UsersController::add_template PHP Method

add_template() public method

public add_template ( $templateuniqid = null )
    function add_template($templateuniqid = null)
    {
        if (isset($this->params['pass'][0]) && $this->params['pass'][0]) {
            $this->loadModel("CaseTemplate");
            $res = $this->CaseTemplate->find('first', array('conditions' => array('CaseTemplate.id' => $this->params['pass'][0])));
            $this->set('TempalteArray', $res);
        } else {
            if (!empty($this->request->data) && $this->Auth->User('id')) {
                $this->request->data['CaseTemplate'] = $this->request->data['User'];
                $this->request->data['CaseTemplate']['name'] = $this->request->data['CaseTemplate']['title'];
                $this->request->data['CaseTemplate']['description'] = $this->request->data['CaseTemplate']['desc'];
                $this->request->data['CaseTemplate']['user_id'] = $this->Auth->User('id');
                $this->request->data['CaseTemplate']['company_id'] = SES_COMP;
                $this->loadModel("CaseTemplate");
                if ($this->request->data['CaseTemplate']['update_temp'] == 1) {
                    if (isset($this->request->data['User']['id'])) {
                        $this->CaseTemplate->id = $this->request->data['User']['id'];
                        if ($this->CaseTemplate->save($this->request->data)) {
                            $this->Session->write("SUCCESS", "Template updated successfully");
                            $this->redirect(HTTP_ROOT . "users/manage_template");
                        } else {
                            $this->Session->write("ERROR", "Template can't be updated");
                            $this->redirect(HTTP_ROOT . "users/add_template/" . $this->request->data['User']['id']);
                        }
                    } else {
                        if ($this->CaseTemplate->save($this->request->data)) {
                            $this->Session->write("SUCCESS", "Template added successfully");
                            $this->redirect(HTTP_ROOT . "users/manage_template");
                        } else {
                            $this->Session->write("ERROR", "Template can't be added");
                            $this->redirect(HTTP_ROOT . "users/add_template");
                        }
                    }
                }
            }
        }
    }