PluginProbe
WP Directory Kit / 1.2.4
WP Directory Kit v1.2.4
1.5.6 1.5.5 1.5.4 1.5.3 trunk 1.1.0 1.1.6 1.1.8 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.8 1.4.0 1.4.1 All 35 releases
wpdirectorykit / application / controllers / Wdk_fields.php

Wdk_fields.php in WP Directory Kit 1.2.4, at application/controllers/Wdk_fields.php

275 lines 9.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly;
3
4 class Wdk_fields extends Winter_MVC_Controller {
5
6 public function __construct(){
7 parent::__construct();
8 }
9
10 public function index()
11 {
12 $this->load->model('field_m');
13
14 $this->data['fields'] = $this->field_m->get();
15
16 //wmvc_dump($this->data['fields']);
17
18
19 $this->load->view('wdk_fields/index', $this->data);
20 }
21
22 public function field_edit()
23 {
24
25 $this->load->model('field_m');
26 $this->load->model('listingfield_m');
27
28 $field_id = (int) $this->input->post_get('id');
29 wdk_access_check('category_m', $field_id);
30 $this->data['field_types'] = array(
31 'INPUTBOX' => __('INPUTBOX', 'wpdirectorykit'),
32 'SECTION' => __('SECTION', 'wpdirectorykit'),
33 'TEXTAREA' => __('TEXTAREA', 'wpdirectorykit'),
34 'TEXTAREA_WYSIWYG' => __('TEXTAREA WYSIWYG', 'wpdirectorykit'),
35 'NUMBER' => __('NUMBER', 'wpdirectorykit'),
36 'DATE' => __('DATE', 'wpdirectorykit'),
37 'DROPDOWN' => __('DROPDOWN', 'wpdirectorykit'),
38 'DROPDOWNMULTIPLE' => __('DROPDOWN MULTIPLE', 'wpdirectorykit'),
39 'CHECKBOX' => __('CHECKBOX', 'wpdirectorykit'),
40 );
41 $this->data['section_list'] = array(
42 '' => __('Not Selected', 'wpdirectorykit'),
43 );
44
45 $fields_list = $this->field_m->get();
46 $this->data['fields_tree'] = array();
47 $this->data['fields_categories'] = array();
48 $section = '';
49 foreach ($fields_list as $key => $field) {
50 if($field->field_type == "SECTION") {
51 $section = $field->idfield;
52 $this->data['fields_tree'][$section] = array();
53 } else {
54 $this->data['fields_tree'][$section][$field->idfield] =$field->field_label;
55 $this->data['fields_categories'][$field->idfield] = $section;
56 }
57 }
58
59 $this->db->where(array('field_type'=> 'SECTION'));
60 $section_list = $this->field_m->get();
61 foreach($section_list as $section) {
62 $this->data['section_list'][$section->idfield] = $section->field_label;
63 }
64
65 $this->data['db_data'] = NULL;
66
67 $this->data['form'] = &$this->form;
68
69 /* default data */
70 if(empty($field_id) && empty($_POST)) {
71 $this->data['db_data']['is_visible_frontend'] = 1;
72 $this->data['db_data']['is_visible_dashboard'] = 1;
73 }
74
75 $rules = array(
76 array(
77 'field' => 'field_type',
78 'label' => __('Field Type', 'wpdirectorykit'),
79 'rules' => 'required'
80 ),
81 array(
82 'field' => 'field_label',
83 'label' => __('Field Label', 'wpdirectorykit'),
84 'rules' => 'required'
85 ),
86 array(
87 'field' => 'hint',
88 'label' => __('Hint', 'wpdirectorykit'),
89 'rules' => ''
90 ),
91 array(
92 'field' => 'placeholder',
93 'label' => __('Placeholder', 'wpdirectorykit'),
94 'rules' => ''
95 ),
96 array(
97 'field' => 'columns_number',
98 'label' => __('Columns number/Width', 'wpdirectorykit'),
99 'rules' => ''
100 ),
101 array(
102 'field' => 'is_visible_frontend',
103 'label' => __('Visible on Frontend', 'wpdirectorykit'),
104 'rules' => ''
105 ),
106 array(
107 'field' => 'is_required',
108 'label' => __('Field is Required', 'wpdirectorykit'),
109 'rules' => ''
110 ),
111 array(
112 'field' => 'is_price_format',
113 'label' => __('Field is Price Format', 'wpdirectorykit'),
114 'rules' => ''
115 ),
116 array(
117 'field' => 'is_visible_dashboard',
118 'label' => __('Visible in Dashboard', 'wpdirectorykit'),
119 'rules' => ''
120 ),
121 array(
122 'field' => 'prefix',
123 'label' => __('Prefix', 'wpdirectorykit'),
124 'rules' => ''
125 ),
126 array(
127 'field' => 'suffix',
128 'label' => __('Suffix', 'wpdirectorykit'),
129 'rules' => ''
130 ),
131 array(
132 'field' => 'values_list',
133 'label' => __('Values', 'wpdirectorykit'),
134 'rules' => ''
135 ),
136 array(
137 'field' => 'icon_id',
138 'label' => __('Parent', 'wpdirectorykit'),
139 'rules' => ''
140 ),
141 array(
142 'field' => 'validation',
143 'label' => __('Validation', 'wpdirectorykit'),
144 'rules' => ''
145 ),
146 array(
147 'field' => 'min_length',
148 'label' => __('Min Length', 'wpdirectorykit'),
149 'rules' => 'is_numerical'
150 ),
151 array(
152 'field' => 'max_length',
153 'label' => __('Max Length', 'wpdirectorykit'),
154 'rules' => 'is_numerical'
155 ),
156 );
157
158 if($this->form->run($rules))
159 {
160 // Check _wpnonce
161 check_admin_referer( 'wdk-fields-edit_'.$field_id, '_wpnonce' );
162
163 // Save procedure for basic data
164
165 $data = $this->field_m->prepare_data(wdk_get_post(), $rules);
166
167
168 $insert_id = $this->field_m->insert($data, $field_id);
169
170 // check if column exists, add if not exists
171
172 if(!empty($insert_id))
173 $this->listingfield_m->create_table_column($data, $insert_id);
174
175 //exit($this->db->last_error());
176
177 /* Change section */
178 if($this->input->post('section'))
179 if(empty($field_id) || ($field_id && $this->data['fields_categories'][$field_id] != $this->input->post('section'))) {
180 /* add section in new category */
181 $this->data['fields_tree'][$this->input->post('section')][$insert_id] = true;
182
183 /* remove section from old category */
184 if(isset($this->data['fields_categories'][$field_id]))
185 unset($this->data['fields_tree'][$this->data['fields_categories'][$field_id]][$field_id]);
186
187 /* indexes by new order and reorder */
188 $values = array();
189 $order_index = 1;
190 foreach( $this->data['fields_tree'] as $key_section => $section)
191 {
192 if(empty($key_section)) continue;
193
194 $values[] = array('order_index' => $order_index, 'idfield' => $key_section);
195 $order_index++;
196 if(is_array($section))
197 foreach($section as $key_field => $field)
198 {
199 $values[] = array('order_index' => $order_index, 'idfield' => $key_field);
200 $order_index++;
201 }
202 }
203 $this->db->updateBatch( $this->field_m->_table_name, $values, 'idfield');
204
205 }
206
207
208 // redirect
209
210 if(!empty($insert_id) && empty($field_id))
211 {
212 wp_redirect(admin_url("admin.php?page=wdk_fields&function=field_edit&id=$insert_id&is_updated=true"));
213 exit;
214 } else {
215 $fields_list = $this->field_m->get();
216 $this->data['fields_categories'] = array();
217 $section = '';
218 foreach ($fields_list as $key => $field) {
219 if($field->field_type == "SECTION") {
220 $section = $field->idfield;
221 } else {
222 $this->data['fields_categories'][$field->idfield] = $section;
223 }
224 }
225 }
226 }
227
228 if(!empty($field_id))
229 $this->data['db_data'] = $this->field_m->get($field_id, TRUE);
230
231 $this->load->view('wdk_fields/field_edit', $this->data);
232 }
233
234 public function ajax_save_order()
235 {
236 $this->load->model('field_m');
237
238 $data_fields_list = $this->input->post_get('data_fields_list');
239
240
241 $splitted = explode(';', $data_fields_list);
242
243 $values = array();
244 $order_index = 1;
245
246 foreach($splitted as $field_id)
247 {
248 if(!empty($field_id))
249 $values[] = array('order_index' => $order_index, 'idfield' => $field_id);
250
251 $order_index++;
252 }
253
254 echo esc_html($this->db->updateBatch( $this->field_m->_table_name, $values, 'idfield'));
255
256 //wmvc_dump($_POST);
257 exit();
258 }
259
260 public function delete()
261 {
262 $field_id = (int) $this->input->post_get('id');
263 wdk_access_check('field_m', $field_id);
264 // Check _wpnonce
265 check_admin_referer( 'wdk-fields-delete_'.$field_id, '_wpnonce' );
266
267 $this->load->model('field_m');
268
269 $this->field_m->delete($field_id);
270
271 wp_redirect(admin_url("admin.php?page=wdk_fields"));
272 }
273
274 }
275