load->model('category_m'); $this->data['categories'] = $this->category_m->get_tree_table(); // Load view $this->load->view('wdk_category/index', $this->data); } public function delete() { $id = (int) $this->input->post_get('id'); $paged = (int) $this->input->post_get('paged'); $this->load->model('category_m'); $this->category_m->delete($id); wp_redirect(admin_url("admin.php?page=wdk_category&paged=$paged")); } public function edit() { $this->load->model('category_m'); $id = $this->input->post_get('id'); wdk_access_check('category_m', $id); $this->data['db_data'] = NULL; $this->data['form'] = &$this->form; $this->data['parents'] = $this->category_m->get_parents($id); //exit($this->db->last_query()); $rules = array( array( 'field' => 'category_title', 'label' => __('Title', 'wpdirectorykit'), 'rules' => 'required' ), array( 'field' => 'order_index', 'label' => __('Order Index', 'wpdirectorykit'), 'rules' => '' ), array( 'field' => 'font_icon_code', 'label' => __('Font icon code', 'wpdirectorykit'), 'rules' => '' ), array( 'field' => 'marker_image_id', 'label' => __('Custom Map Marker Image', 'wpdirectorykit'), 'rules' => '' ), array( 'field' => 'parent_id', 'label' => __('Parent', 'wpdirectorykit'), 'rules' => '' ), array( 'field' => 'icon_id', 'label' => __('Parent', 'wpdirectorykit'), 'rules' => '' ), array( 'field' => 'image_id', 'label' => __('Parent', 'wpdirectorykit'), 'rules' => '' ), ); if($this->form->run($rules)) { // Save procedure for basic data $data = $this->category_m->prepare_data($this->input->post(), $rules); // Save standard wp post $insert_id = $this->category_m->insert($data, $id); /* indexes by new order and reorder */ $results = $this->category_m->get_tree_table(); $values = array(); $order_index = 1; foreach( $results as $item) { $values[] = array('order_index' => $order_index, 'idcategory' => $item->idcategory); $order_index++; } $this->db->updateBatch( $this->category_m->_table_name, $values, 'idcategory'); //exit($this->db->last_error()); // redirect if(!empty($insert_id) && empty($id)) { wp_redirect(admin_url("admin.php?page=wdk_category&id=$insert_id&is_updated=true")); exit; } } if(!empty($id)) { $this->data['db_data'] = $this->category_m->get($id, TRUE); } $this->load->view('wdk_category/category_edit', $this->data); } }