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

285 lines 9.8 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' => 'empty_value',
138 'label' => __('Empty Value', 'wpdirectorykit'),
139 'rules' => ''
140 ),
141 array(
142 'field' => 'icon_id',
143 'label' => __('Parent', 'wpdirectorykit'),
144 'rules' => ''
145 ),
146 array(
147 'field' => 'validation',
148 'label' => __('Validation', 'wpdirectorykit'),
149 'rules' => ''
150 ),
151 array(
152 'field' => 'min_length',
153 'label' => __('Min Length', 'wpdirectorykit'),
154 'rules' => 'is_numerical'
155 ),
156 array(
157 'field' => 'max_length',
158 'label' => __('Max Length', 'wpdirectorykit'),
159 'rules' => 'is_numerical'
160 ),
161 array(
162 'field' => 'date_format',
163 'label' => __('Вate Аormat', 'wpdirectorykit'),
164 'rules' => ''
165 ),
166 );
167
168 if($this->form->run($rules))
169 {
170 // Check _wpnonce
171 check_admin_referer( 'wdk-fields-edit_'.$field_id, '_wpnonce' );
172
173 // Save procedure for basic data
174
175 $data = $this->field_m->prepare_data(wdk_get_post(), $rules);
176
177
178 $insert_id = $this->field_m->insert($data, $field_id);
179
180 // check if column exists, add if not exists
181
182 if(!empty($insert_id))
183 $this->listingfield_m->create_table_column($data, $insert_id);
184
185 //exit($this->db->last_error());
186
187 /* Change section */
188 if($this->input->post('section'))
189 if(empty($field_id) || ($field_id && $this->data['fields_categories'][$field_id] != $this->input->post('section'))) {
190 /* add section in new category */
191 $this->data['fields_tree'][$this->input->post('section')][$insert_id] = true;
192
193 /* remove section from old category */
194 if(isset($this->data['fields_categories'][$field_id]))
195 unset($this->data['fields_tree'][$this->data['fields_categories'][$field_id]][$field_id]);
196
197 /* indexes by new order and reorder */
198 $values = array();
199 $order_index = 1;
200 foreach( $this->data['fields_tree'] as $key_section => $section)
201 {
202 if(empty($key_section)) continue;
203
204 $values[] = array('order_index' => $order_index, 'idfield' => $key_section);
205 $order_index++;
206 if(is_array($section))
207 foreach($section as $key_field => $field)
208 {
209 $values[] = array('order_index' => $order_index, 'idfield' => $key_field);
210 $order_index++;
211 }
212 }
213 $this->db->updateBatch( $this->field_m->_table_name, $values, 'idfield');
214
215 }
216
217
218 // redirect
219
220 if(!empty($insert_id) && empty($field_id))
221 {
222 wp_redirect(admin_url("admin.php?page=wdk_fields&function=field_edit&id=$insert_id&is_updated=true"));
223 exit;
224 } else {
225 $fields_list = $this->field_m->get();
226 $this->data['fields_categories'] = array();
227 $section = '';
228 foreach ($fields_list as $key => $field) {
229 if($field->field_type == "SECTION") {
230 $section = $field->idfield;
231 } else {
232 $this->data['fields_categories'][$field->idfield] = $section;
233 }
234 }
235 }
236 }
237
238 if(!empty($field_id))
239 $this->data['db_data'] = $this->field_m->get($field_id, TRUE);
240
241 $this->load->view('wdk_fields/field_edit', $this->data);
242 }
243
244 public function ajax_save_order()
245 {
246 $this->load->model('field_m');
247
248 $data_fields_list = $this->input->post_get('data_fields_list');
249
250
251 $splitted = explode(';', $data_fields_list);
252
253 $values = array();
254 $order_index = 1;
255
256 foreach($splitted as $field_id)
257 {
258 if(!empty($field_id))
259 $values[] = array('order_index' => $order_index, 'idfield' => $field_id);
260
261 $order_index++;
262 }
263
264 echo esc_html($this->db->updateBatch( $this->field_m->_table_name, $values, 'idfield'));
265
266 //wmvc_dump($_POST);
267 exit();
268 }
269
270 public function delete()
271 {
272 $field_id = (int) $this->input->post_get('id');
273 wdk_access_check('field_m', $field_id);
274 // Check _wpnonce
275 check_admin_referer( 'wdk-fields-delete_'.$field_id, '_wpnonce' );
276
277 $this->load->model('field_m');
278
279 $this->field_m->delete($field_id);
280
281 wp_redirect(admin_url("admin.php?page=wdk_fields"));
282 }
283
284 }
285