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

263 lines 8.9 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 $rules = array(
70 array(
71 'field' => 'field_type',
72 'label' => __('Field Type', 'wpdirectorykit'),
73 'rules' => 'required'
74 ),
75 array(
76 'field' => 'field_label',
77 'label' => __('Field Label', 'wpdirectorykit'),
78 'rules' => 'required'
79 ),
80 array(
81 'field' => 'hint',
82 'label' => __('Hint', 'wpdirectorykit'),
83 'rules' => ''
84 ),
85 array(
86 'field' => 'placeholder',
87 'label' => __('Placeholder', 'wpdirectorykit'),
88 'rules' => ''
89 ),
90 array(
91 'field' => 'columns_number',
92 'label' => __('Columns number/Width', 'wpdirectorykit'),
93 'rules' => ''
94 ),
95 array(
96 'field' => 'is_visible_frontend',
97 'label' => __('Visible on Frontend', 'wpdirectorykit'),
98 'rules' => ''
99 ),
100 array(
101 'field' => 'is_required',
102 'label' => __('Field is Required', 'wpdirectorykit'),
103 'rules' => ''
104 ),
105 array(
106 'field' => 'is_price_format',
107 'label' => __('Field is Price Format', 'wpdirectorykit'),
108 'rules' => ''
109 ),
110 array(
111 'field' => 'is_visible_dashboard',
112 'label' => __('Visible in Dashboard', 'wpdirectorykit'),
113 'rules' => ''
114 ),
115 array(
116 'field' => 'prefix',
117 'label' => __('Prefix', 'wpdirectorykit'),
118 'rules' => ''
119 ),
120 array(
121 'field' => 'suffix',
122 'label' => __('Suffix', 'wpdirectorykit'),
123 'rules' => ''
124 ),
125 array(
126 'field' => 'values_list',
127 'label' => __('Values', 'wpdirectorykit'),
128 'rules' => ''
129 ),
130 array(
131 'field' => 'icon_id',
132 'label' => __('Parent', 'wpdirectorykit'),
133 'rules' => ''
134 ),
135 array(
136 'field' => 'validation',
137 'label' => __('Validation', 'wpdirectorykit'),
138 'rules' => ''
139 ),
140 array(
141 'field' => 'min_length',
142 'label' => __('Min Length', 'wpdirectorykit'),
143 'rules' => 'is_numerical'
144 ),
145 array(
146 'field' => 'max_length',
147 'label' => __('Max Length', 'wpdirectorykit'),
148 'rules' => 'is_numerical'
149 ),
150 );
151
152 if($this->form->run($rules))
153 {
154 // Save procedure for basic data
155
156 $data = $this->field_m->prepare_data($this->input->post(), $rules);
157
158
159 $insert_id = $this->field_m->insert($data, $field_id);
160
161 // check if column exists, add if not exists
162
163 if(!empty($insert_id))
164 $this->listingfield_m->create_table_column($data, $insert_id);
165
166 //exit($this->db->last_error());
167
168 /* Change section */
169 if($this->input->post('section'))
170 if(empty($field_id) || ($field_id && $this->data['fields_categories'][$field_id] != $this->input->post('section'))) {
171 /* add section in new category */
172 $this->data['fields_tree'][$this->input->post('section')][$insert_id] = true;
173
174 /* remove section from old category */
175 if(isset($this->data['fields_categories'][$field_id]))
176 unset($this->data['fields_tree'][$this->data['fields_categories'][$field_id]][$field_id]);
177
178 /* indexes by new order and reorder */
179 $values = array();
180 $order_index = 1;
181 foreach( $this->data['fields_tree'] as $key_section => $section)
182 {
183 if(empty($key_section)) continue;
184
185 $values[] = array('order_index' => $order_index, 'idfield' => $key_section);
186 $order_index++;
187 if(is_array($section))
188 foreach($section as $key_field => $field)
189 {
190 $values[] = array('order_index' => $order_index, 'idfield' => $key_field);
191 $order_index++;
192 }
193 }
194 $this->db->updateBatch( $this->field_m->_table_name, $values, 'idfield');
195
196 }
197
198
199 // redirect
200
201 if(!empty($insert_id) && empty($field_id))
202 {
203 wp_redirect(admin_url("admin.php?page=wdk_fields&function=field_edit&id=$insert_id&is_updated=true"));
204 exit;
205 } else {
206 $fields_list = $this->field_m->get();
207 $this->data['fields_categories'] = array();
208 $section = '';
209 foreach ($fields_list as $key => $field) {
210 if($field->field_type == "SECTION") {
211 $section = $field->idfield;
212 } else {
213 $this->data['fields_categories'][$field->idfield] = $section;
214 }
215 }
216 }
217 }
218
219 if(!empty($field_id))
220 $this->data['db_data'] = $this->field_m->get($field_id, TRUE);
221
222 $this->load->view('wdk_fields/field_edit', $this->data);
223 }
224
225 public function ajax_save_order()
226 {
227 $this->load->model('field_m');
228
229 $data_fields_list = $this->input->post_get('data_fields_list');
230
231
232 $splitted = explode(';', $data_fields_list);
233
234 $values = array();
235 $order_index = 1;
236
237 foreach($splitted as $field_id)
238 {
239 if(!empty($field_id))
240 $values[] = array('order_index' => $order_index, 'idfield' => $field_id);
241
242 $order_index++;
243 }
244
245 echo esc_html($this->db->updateBatch( $this->field_m->_table_name, $values, 'idfield'));
246
247 //wmvc_dump($_POST);
248 exit();
249 }
250
251 public function delete()
252 {
253 $field_id = (int) $this->input->post_get('id');
254
255 $this->load->model('field_m');
256
257 $this->field_m->delete($field_id);
258
259 wp_redirect(admin_url("admin.php?page=wdk_fields"));
260 }
261
262 }
263