/**
  * Редактирует категорию
  * @param $args array mixed
  * @return void
  */
 function edit(array $args = array())
 {
     $errors = array();
     $categorys = Core::getInstance()->user->getUserCategory();
     $category = null;
     if (array_key_exists(0, $args) && array_key_exists($args[0], $categorys)) {
         $category = array('id' => (int) $args[0], 'name' => $categorys[$args[0]]['cat_name'], 'parent' => $categorys[$args[0]]['cat_parent'], 'system' => $categorys[$args[0]]['system_category_id'], 'type' => $categorys[$args[0]]['type']);
     }
     if ($this->request->method == 'POST') {
         $category = array('id' => isset($this->request->post['id']) ? $this->request->post['id'] : $category['id'], 'name' => $this->request->post['name'], 'parent' => (int) $this->request->post['parent'], 'system' => (int) $this->request->post['system'], 'type' => (int) $this->request->post['type']);
         if (!strlen($category['name'])) {
             $errors[] = 'Название не может быть пустым!';
         }
         if (!$category['parent'] && !$category['system']) {
             $errors[] = 'Вы должны указать системную или родительскую категорию.';
         }
         if (!sizeof($errors)) {
             $this->model->edit($category['id'], $category['name'], $category['parent'], $category['system'], $category['type']);
             $this->tpl->assign('result', array('text' => "Категория успешно изменена."));
         } else {
             $this->tpl->assign('error', array('text' => implode(" \n", $errors)));
         }
     }
     $this->tpl->assign('category', $category);
     $this->tpl->assign('name_page', 'category/edit');
 }
Exemplo n.º 2
0
 /**
  * 更新联系人分组名
  * @param int $id 分组ID
  */
 public function update($id = NULL)
 {
     if ($this->get_method() != 'POST') {
         $this->send_response(405, NULL, Kohana::lang('contact.method_not_exist'));
     }
     $data = $this->get_data();
     $name = isset($data['name']) ? $data['name'] : '';
     $id = (int) $id;
     if (empty($id)) {
         $this->send_response(400, NULL, Kohana::lang('contact.group_id_empty'));
     } elseif (empty($name)) {
         $this->send_response(400, NULL, Kohana::lang('contact.group_name_empty'));
     } elseif (mb_strlen($name, 'utf8') > 32) {
         $this->send_response(400, NULL, Kohana::lang('contact.group_name_too_long'));
     } elseif ($this->model->check_name($this->user_id, $name, $id)) {
         $this->send_response(400, NULL, Kohana::lang('contact.group_name_exist'));
     } else {
         $status = $this->model->edit($this->user_id, $name, $id);
         if ($status == FALSE) {
             $this->send_response(404, NULL, Kohana::lang('contact.group_not_exist'));
         } else {
             $this->send_response(200, array('id' => (int) $id, 'name' => $name), '', FALSE);
         }
     }
 }