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

227 lines 7.6 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 $this->load->model('field_m');
25 $this->load->model('listingfield_m');
26
27 $field_id = (int) $this->input->post_get('id');
28 wdk_access_check('category_m', $field_id);
29 $this->data['field_types'] = array(
30 'INPUTBOX' => __('INPUTBOX', 'wpdirectorykit'),
31 'SECTION' => __('SECTION', 'wpdirectorykit'),
32 'TEXTAREA' => __('TEXTAREA', 'wpdirectorykit'),
33 'TEXTAREA_WYSIWYG' => __('TEXTAREA WYSIWYG', 'wpdirectorykit'),
34 'NUMBER' => __('NUMBER', 'wpdirectorykit'),
35 'DATE' => __('DATE', 'wpdirectorykit'),
36 'DROPDOWN' => __('DROPDOWN', 'wpdirectorykit'),
37 'CHECKBOX' => __('CHECKBOX', 'wpdirectorykit'),
38 );
39 $this->data['section_list'] = array(
40 '' => __('Not Selected', 'wpdirectorykit'),
41 );
42
43 $fields_list = $this->field_m->get();
44 $this->data['fields_tree'] = array();
45 $this->data['fields_categories'] = array();
46 $section = '';
47 foreach ($fields_list as $key => $field) {
48 if($field->field_type == "SECTION") {
49 $section = $field->idfield;
50 $this->data['fields_tree'][$section] = array();
51 } else {
52 $this->data['fields_tree'][$section][$field->idfield] =$field->field_label;
53 $this->data['fields_categories'][$field->idfield] = $section;
54 }
55 }
56
57 $this->db->where(array('field_type'=> 'SECTION'));
58 $section_list = $this->field_m->get();
59 foreach($section_list as $section) {
60 $this->data['section_list'][$section->idfield] = $section->field_label;
61 }
62
63 $this->data['db_data'] = NULL;
64
65 $this->data['form'] = &$this->form;
66
67 $rules = array(
68 array(
69 'field' => 'field_type',
70 'label' => __('Field Type', 'wpdirectorykit'),
71 'rules' => 'required'
72 ),
73 array(
74 'field' => 'field_label',
75 'label' => __('Field Label', 'wpdirectorykit'),
76 'rules' => 'required'
77 ),
78 array(
79 'field' => 'hint',
80 'label' => __('Hint', 'wpdirectorykit'),
81 'rules' => ''
82 ),
83 array(
84 'field' => 'columns_number',
85 'label' => __('Columns number/Width', 'wpdirectorykit'),
86 'rules' => ''
87 ),
88 array(
89 'field' => 'is_visible_frontend',
90 'label' => __('Visible on Frontend', 'wpdirectorykit'),
91 'rules' => ''
92 ),
93 array(
94 'field' => 'is_required',
95 'label' => __('Field is Required', 'wpdirectorykit'),
96 'rules' => ''
97 ),
98 array(
99 'field' => 'is_price_format',
100 'label' => __('Field is Price Format', 'wpdirectorykit'),
101 'rules' => ''
102 ),
103 array(
104 'field' => 'is_visible_dashboard',
105 'label' => __('Visible in Dashboard', 'wpdirectorykit'),
106 'rules' => ''
107 ),
108 array(
109 'field' => 'prefix',
110 'label' => __('Prefix', 'wpdirectorykit'),
111 'rules' => ''
112 ),
113 array(
114 'field' => 'suffix',
115 'label' => __('Suffix', 'wpdirectorykit'),
116 'rules' => ''
117 ),
118 array(
119 'field' => 'values_list',
120 'label' => __('Values', 'wpdirectorykit'),
121 'rules' => ''
122 ),
123 array(
124 'field' => 'icon_id',
125 'label' => __('Parent', 'wpdirectorykit'),
126 'rules' => ''
127 ),
128 );
129
130 if($this->form->run($rules))
131 {
132 // Save procedure for basic data
133
134 $data = $this->field_m->prepare_data($this->input->post(), $rules);
135
136
137 $insert_id = $this->field_m->insert($data, $field_id);
138
139 // check if column exists, add if nto exists
140
141 if(!empty($insert_id))
142 $this->listingfield_m->create_table_column($data, $insert_id);
143
144 //exit($this->db->last_error());
145
146 /* Change section */
147 if($this->input->post('section'))
148 if(empty($field_id) || ($field_id && $this->data['fields_categories'][$field_id] != $this->input->post('section'))) {
149 /* add section in new category */
150 $this->data['fields_tree'][$this->input->post('section')][$insert_id] = true;
151
152 /* remove section from old category */
153 if(isset($this->data['fields_categories'][$field_id]))
154 unset($this->data['fields_tree'][$this->data['fields_categories'][$field_id]][$field_id]);
155
156 /* indexes by new order and reorder */
157 $values = array();
158 $order_index = 1;
159 foreach( $this->data['fields_tree'] as $key_section => $section)
160 {
161 $values[] = array('order_index' => $order_index, 'idfield' => $key_section);
162 $order_index++;
163 if(is_array($section))
164 foreach($section as $key_field => $field)
165 {
166 $values[] = array('order_index' => $order_index, 'idfield' => $key_field);
167 $order_index++;
168 }
169 }
170 $this->db->updateBatch( $this->field_m->_table_name, $values, 'idfield');
171 }
172
173
174 // redirect
175
176 if(!empty($insert_id) && empty($field_id))
177 {
178 wp_redirect(admin_url("admin.php?page=wdk_fields&function=field_edit&id=$insert_id&is_updated=true"));
179 exit;
180 }
181 }
182
183 if(!empty($field_id))
184 $this->data['db_data'] = $this->field_m->get($field_id, TRUE);
185
186 $this->load->view('wdk_fields/field_edit', $this->data);
187 }
188
189 public function ajax_save_order()
190 {
191 $this->load->model('field_m');
192
193 $data_fields_list = $this->input->post_get('data_fields_list');
194
195
196 $splitted = explode(';', $data_fields_list);
197
198 $values = array();
199 $order_index = 1;
200
201 foreach($splitted as $field_id)
202 {
203 if(!empty($field_id))
204 $values[] = array('order_index' => $order_index, 'idfield' => $field_id);
205
206 $order_index++;
207 }
208
209 echo esc_html($this->db->updateBatch( $this->field_m->_table_name, $values, 'idfield'));
210
211 //wmvc_dump($_POST);
212 exit();
213 }
214
215 public function delete()
216 {
217 $field_id = (int) $this->input->post_get('id');
218
219 $this->load->model('field_m');
220
221 $this->field_m->delete($field_id);
222
223 wp_redirect(admin_url("admin.php?page=wdk_fields"));
224 }
225
226 }
227