コード例 #1
0
ファイル: category.php プロジェクト: trk/ionize
 /**
  * Saves one category
  *
  */
 public function save()
 {
     if ($this->input->post('name') != '') {
         // If no ID (means new one) and this item name already exists in DB : No save
         if ($this->input->post('id_category') == '' && $this->category_model->exists(array('name' => url_title($this->input->post('name'))))) {
             $this->error(lang('ionize_message_category_name_exists'));
         } else {
             $this->_prepare_data();
             // Event
             $event_data = array('base' => $this->data, 'lang' => $this->lang_data);
             $event_received = Event::fire('Category.save.before', $event_data);
             $event_received = array_pop($event_received);
             if (!empty($event_received['base']) && !empty($event_received['lang'])) {
                 $this->data = $event_received['base'];
                 $this->lang_data = $event_received['lang'];
             }
             // Save data
             $this->id = $this->category_model->save($this->data, $this->lang_data);
             // Event
             $event_data = array('base' => $this->data, 'lang' => $this->lang_data);
             Event::fire('Category.save.success', $event_data);
             // JSON Update array : If parent is defined in form, the categories selectbox of the parent will be updated
             if ($this->input->post('parent') != '') {
                 $this->update[] = array('element' => 'categories', 'url' => 'category/get_select/' . $this->input->post('parent') . '/' . $this->input->post('id_parent'));
             } else {
                 $this->callback = array(array('fn' => 'ION.HTML', 'args' => array('category/get_list', '', array('update' => 'categoriesContainer'))), array('fn' => 'ION.clearFormInput', 'args' => array('form' => 'newCategoryForm')));
             }
             $this->success(lang('ionize_message_category_saved'));
         }
     } else {
         Event::fire('Category.save.error');
         $this->error(lang('ionize_message_category_not_saved'));
     }
 }
コード例 #2
0
 /**
  * Register Edit / New Category form data
  *
  * @access	private
  * @param   integer $id item ID (if 0 then is a new item)
  * @param   array 	$_post _POST array
  * @return  void
  */
 private function editing($id, $_post)
 {
     $msg = null;
     // check permission
     $msg = $id ? AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'categories', $_post['id'], 3) : AdmUtils_helper::chk_priv_level($_SESSION['xuid'], '_category_creation', 0, 4);
     if (is_null($msg)) {
         // handle _post
         $post = array('id_area' => $_post['id_area'], 'lang' => $_post['lang'], 'title' => $_post['title'], 'name' => X4Utils_helper::unspace($_post['title']), 'tag' => X4Utils_helper::unspace($_post['tag']));
         $mod = new Category_model();
         // check if category already exists
         $check = $mod->exists($post, $id);
         if ($check) {
             $msg = AdmUtils_helper::set_msg(false, '', $this->dict->get_word('_CATEGORY_ALREADY_EXISTS', 'msg'));
         } else {
             // update or insert
             if ($id) {
                 $result = $mod->update($_post['id'], $post);
             } else {
                 $result = $mod->insert($post);
                 // create permissions
                 if ($result[1]) {
                     $perm = new Permission_model();
                     $array[] = array('action' => 'insert', 'id_what' => $result[0], 'id_user' => $_SESSION['xuid'], 'level' => 4);
                     $res = $perm->pexec('categories', $array, $_post['id_area']);
                 }
             }
             // set message
             $msg = AdmUtils_helper::set_msg($result);
             // set what update
             if ($result[1]) {
                 $msg->update[] = array('element' => 'topic', 'url' => BASE_URL . 'categories/index/' . $post['id_area'] . '/' . $post['lang'] . '/' . $post['tag'], 'title' => null);
             }
         }
     }
     $this->response($msg);
 }