PluginProbe
WP Directory Kit / 1.4.8
WP Directory Kit v1.4.8
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.4.8, at application/controllers/Wdk_fields.php

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