| @@ -8,8 +8,23 @@ | ||
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | public function index() |
| 11 | 11 | { |
| 12 | + $this->data['form'] = &$this->form; | |
| 13 | + /* [Table Actions Bulk Form] */ | |
| 14 | + $table_action = $this->input->post_get('table_action'); | |
| 15 | + $action = $this->input->post_get('action'); | |
| 16 | + $posts_selected = $this->input->post_get('post'); | |
| 17 | + | |
| 18 | + if(!empty($table_action)) | |
| 19 | + { | |
| 20 | + switch ($action) { | |
| 21 | + case 'delete': | |
| 22 | + $this->bulk_delete($posts_selected); | |
| 23 | + break; | |
| 24 | + } | |
| 25 | + } | |
| 26 | + | |
| 12 | 27 | $this->load->model('category_m'); |
| 13 | 28 | |
| 14 | 29 | $this->data['categories'] = $this->category_m->get_tree_table(); |
| 15 | 30 | |
| @@ -21,20 +36,40 @@ | ||
| 21 | 36 | { |
| 22 | 37 | $id = (int) $this->input->post_get('id'); |
| 23 | 38 | $paged = (int) $this->input->post_get('paged'); |
| 24 | 39 | |
| 40 | + // Check _wpnonce | |
| 41 | + check_admin_referer( 'wdk-category-delete_'.$id, '_wpnonce' ); | |
| 42 | + | |
| 25 | 43 | $this->load->model('category_m'); |
| 26 | - | |
| 44 | + wdk_access_check('category_m', $id); | |
| 45 | + | |
| 27 | 46 | $this->category_m->delete($id); |
| 28 | 47 | |
| 29 | 48 | wp_redirect(admin_url("admin.php?page=wdk_category&paged=$paged")); |
| 30 | 49 | } |
| 50 | + | |
| 51 | + public function bulk_delete($posts_selected) | |
| 52 | + { | |
| 53 | + // Check _wpnonce | |
| 54 | + check_admin_referer( 'wdk-category-bulk', '_wpnonce'); | |
| 55 | + | |
| 56 | + $this->load->model('category_m'); | |
| 57 | + foreach($posts_selected as $id) | |
| 58 | + { | |
| 59 | + wdk_access_check('category_m', $id); | |
| 60 | + $this->category_m->delete($id); | |
| 61 | + } | |
| 62 | + | |
| 63 | + wp_redirect(admin_url("admin.php?page=wdk_category&is_updated=true&custom_message=".urlencode(esc_html__('Selected Categories removed', 'wpdirectorykit')))); | |
| 64 | + exit(); | |
| 65 | + } | |
| 31 | 66 | |
| 32 | 67 | public function edit() |
| 33 | 68 | { |
| 34 | 69 | $this->load->model('category_m'); |
| 35 | 70 | |
| 36 | - $id = $this->input->post_get('id'); | |
| 71 | + $id = (int) $this->input->post_get('id'); | |
| 37 | 72 | wdk_access_check('category_m', $id); |
| 38 | 73 | $this->data['db_data'] = NULL; |
| 39 | 74 | |
| 40 | 75 | $this->data['form'] = &$this->form; |
| @@ -78,40 +113,65 @@ | ||
| 78 | 113 | 'field' => 'image_id', |
| 79 | 114 | 'label' => __('Parent', 'wpdirectorykit'), |
| 80 | 115 | 'rules' => '' |
| 81 | 116 | ), |
| 117 | + array( | |
| 118 | + 'field' => 'category_color', | |
| 119 | + 'label' => __('Color', 'wpdirectorykit'), | |
| 120 | + 'rules' => '' | |
| 121 | + ), | |
| 122 | + array( | |
| 123 | + 'field' => 'titles_for_search', | |
| 124 | + 'label' => __('Alternative titles for search', 'wpdirectorykit'), | |
| 125 | + 'rules' => '' | |
| 126 | + ), | |
| 82 | 127 | ); |
| 83 | 128 | |
| 84 | 129 | if($this->form->run($rules)) |
| 85 | 130 | { |
| 131 | + // Check _wpnonce | |
| 132 | + check_admin_referer( 'wdk-category-edit_'.$id, '_wpnonce' ); | |
| 133 | + | |
| 86 | 134 | // Save procedure for basic data |
| 87 | - $data = $this->category_m->prepare_data($this->input->post(), $rules); | |
| 135 | + $data = $this->category_m->prepare_data(wdk_get_post(), $rules); | |
| 88 | 136 | |
| 89 | - // Save standard wp post | |
| 137 | + if(empty($id) && strpos($data['category_title'], ',') !== FALSE) { | |
| 138 | + | |
| 139 | + foreach (explode(',', $data['category_title']) as $title) { | |
| 140 | + // Save standard wp post | |
| 141 | + $insert_id = $this->category_m->insert(array_merge($data, array('category_title' => trim($title))), NULL); | |
| 142 | + } | |
| 143 | + wp_redirect(admin_url("admin.php?page=wdk_category&is_updated=true&custom_message=".urlencode(esc_html__('Bulk Categories added', 'wpdirectorykit')))); | |
| 144 | + exit; | |
| 145 | + } else { | |
| 146 | + // Save standard wp post | |
| 147 | + $data['icon_path'] = wdk_generate_path_image($data['icon_id']); | |
| 148 | + $data['image_path'] = wdk_generate_path_image($data['image_id']); | |
| 149 | + $data['marker_image_path'] = wdk_generate_path_image($data['marker_image_id']); | |
| 90 | 150 | |
| 91 | - $insert_id = $this->category_m->insert($data, $id); | |
| 151 | + $insert_id = $this->category_m->insert($data, $id); | |
| 92 | 152 | |
| 93 | - /* indexes by new order and reorder */ | |
| 94 | - $results = $this->category_m->get_tree_table(); | |
| 95 | - $values = array(); | |
| 96 | - $order_index = 1; | |
| 97 | - foreach( $results as $item) | |
| 98 | - { | |
| 99 | - $values[] = array('order_index' => $order_index, 'idcategory' => $item->idcategory); | |
| 100 | - $order_index++; | |
| 101 | - } | |
| 102 | - $this->db->updateBatch( $this->category_m->_table_name, $values, 'idcategory'); | |
| 153 | + /* indexes by new order and reorder */ | |
| 154 | + $results = $this->category_m->get_tree_table(); | |
| 155 | + $values = array(); | |
| 156 | + $order_index = 1; | |
| 157 | + foreach( $results as $item) | |
| 158 | + { | |
| 159 | + $values[] = array('order_index' => $order_index, 'idcategory' => $item->idcategory); | |
| 160 | + $order_index++; | |
| 161 | + } | |
| 162 | + $this->db->updateBatch( $this->category_m->_table_name, $values, 'idcategory'); | |
| 103 | 163 | |
| 104 | - //exit($this->db->last_error()); | |
| 164 | + //exit($this->db->last_error()); | |
| 105 | 165 | |
| 106 | - // redirect | |
| 107 | - | |
| 108 | - if(!empty($insert_id) && empty($id)) | |
| 109 | - { | |
| 110 | - wp_redirect(admin_url("admin.php?page=wdk_category&id=$insert_id&is_updated=true")); | |
| 111 | - exit; | |
| 112 | - } | |
| 166 | + // redirect | |
| 113 | 167 | |
| 168 | + if(!empty($insert_id) && empty($id)) | |
| 169 | + { | |
| 170 | + wp_redirect(admin_url("admin.php?page=wdk_category&id=$insert_id&is_updated=true")); | |
| 171 | + exit; | |
| 172 | + } | |
| 173 | + } | |
| 114 | 174 | } |
| 115 | 175 | |
| 116 | 176 | if(!empty($id)) |
| 117 | 177 | { |