PluginProbe
WP Directory Kit / 1.3.0
WP Directory Kit v1.3.0
1.5.9 1.5.7 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 All 37 releases
wpdirectorykit / application / controllers / Wdk_listing.php

Wdk_listing.php in WP Directory Kit 1.3.0, at application/controllers/Wdk_listing.php

641 lines 29.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_listing extends Winter_MVC_Controller {
5
6 public function __construct(){
7 parent::__construct();
8 }
9
10 // Edit listing method
11 public function index()
12 {
13 $this->load->model('field_m');
14 $this->load->model('listing_m');
15 $this->load->model('listingfield_m');
16 $this->load->model('listingusers_m');
17 $this->load->model('category_m');
18 $this->load->model('location_m');
19 $this->load->model('user_m');
20 $this->load->model('categorieslistings_m');
21 $this->load->model('locationslistings_m');
22 $this->load->load_helper('listing');
23
24 $listing_post_id = (int) $this->input->post_get('id');
25
26 wdk_access_check('listing_m', $listing_post_id, NULL, 'edit');
27
28 $this->data['db_data'] = NULL;
29 $this->data['db_data']['listing_agents'] = array();
30 $this->data['db_data']['listing_sub_locations'] = array();
31 $this->data['db_data']['listing_sub_categories'] = array();
32 $this->data['form'] = &$this->form;
33 $this->data['edit_log'] = NULL;
34
35 $this->data['categories'] = $this->category_m->get_parents();
36 $this->data['locations'] = $this->location_m->get_parents();
37
38 $or_like = "(meta_value LIKE '%administrator%'
39 OR meta_value LIKE '%wdk_agency%'
40 OR meta_value LIKE '%wdk_agent%'
41 OR meta_value LIKE '%wdk_owner%')";
42
43 $this->data['agents'] = $this->user_m->get_agents_names(array(), $or_like);
44
45 if(!empty($listing_post_id))
46 {
47 $listing_post = get_post( $listing_post_id );
48
49 $listing_db_data = $this->listing_m->get($listing_post_id, TRUE);
50
51 $listingfield_db_data = $this->listingfield_m->get($listing_post_id, TRUE);
52 $listingusers_db_data = $this->listingusers_m->get($listing_post_id);
53
54 $this->data['db_data'] = array_merge((array) $listing_post,
55 (array) $listing_db_data,
56 (array) $listingfield_db_data);
57
58 $this->data['db_data']['listing_agents'] = array();
59 $this->data['db_data']['listing_sub_locations'] = array();
60 $this->data['db_data']['listing_sub_categories'] = array();
61
62 foreach ($listingusers_db_data as $key => $listinguser) {
63 if(isset($this->data['agents'][$listinguser->user_id]))
64 $this->data['db_data']['listing_agents'] [$listinguser->user_id]= $this->data['agents'][$listinguser->user_id];
65 }
66
67 $this->data['db_data']['listing_sub_locations'] = wdk_generate_other_locations_keys($listing_post_id);
68 $this->data['db_data']['listing_sub_categories'] = wdk_generate_other_categories_keys($listing_post_id);
69 if(function_exists('run_wdk_payments')) {
70 $this->data['packages'] = array();
71
72 global $Winter_MVC_wdk_payments;
73 $Winter_MVC_wdk_payments->model('package_m');
74
75 $packages = $Winter_MVC_wdk_payments->package_m->get_by(array('(date_from IS NULL OR date_from < \''.current_time( 'mysql' ).'\')'=>NULL,
76 '(date_to IS NULL OR date_to > \''.current_time( 'mysql' ).'\')'=>NULL,
77 '(location_id IS NULL OR location_id = '.wdk_show_data('location_id', $listing_db_data, '0', TRUE, TRUE).')'=>NULL,
78 '(category_id IS NULL OR category_id = '.wdk_show_data('category_id', $listing_db_data, '0', TRUE, TRUE).')'=>NULL));
79 if (count($packages) > 0) {
80 foreach($packages as $package) {
81 $this->data['packages'][wdk_show_data('idpackage', $package, TRUE, TRUE)] = wdk_show_data('idpackage', $package,'', TRUE, TRUE)
82 .', '.wdk_show_data('package_name', $package,'', TRUE, TRUE)
83 .'('.wdk_get_date(wdk_show_data('date_to', $package,'', TRUE, TRUE)).')';
84 }
85 }
86 }
87
88 $this->load->model('editlog_m');
89 $this->data['edit_log'] = $this->editlog_m->get_pagination_listing($listing_post_id, 10, NULL);
90 }
91
92 if(isset($_POST['listing_agents'])) {
93 $this->data['db_data']['listing_agents'] = array();
94 foreach ($_POST['listing_agents'] as $user_id) {
95 if(isset($this->data['agents'][intval($user_id)]))
96 $this->data['db_data']['listing_agents'] [intval($user_id)]= $this->data['agents'][intval($user_id)];
97 }
98 }
99
100 if(isset($_POST['listing_sub_locations'])) {
101 $this->data['db_data']['listing_sub_locations'] = $_POST['listing_sub_locations'];
102 }
103 if(isset($_POST['listing_sub_categories'])) {
104 $this->data['db_data']['listing_sub_categories'] = $_POST['listing_sub_categories'];
105 }
106
107 $this->data['subscriptions'] = array();
108 $this->data['subscriptions_data'] = array();
109
110 if(wdk_get_option('wdk_membership_is_enable_subscriptions') && function_exists('run_wdk_membership')){
111 global $Winter_MVC_wdk_membership;
112 $Winter_MVC_wdk_membership->model('subscription_user_m');
113 $Winter_MVC_wdk_membership->model('subscription_m');
114
115 $this->db->select('*');
116 $this->db->join($Winter_MVC_wdk_membership->subscription_m->_table_name.' ON '.$Winter_MVC_wdk_membership->subscription_m->_table_name.'.idsubscription = '.$Winter_MVC_wdk_membership->subscription_user_m->_table_name.'.subscription_id');
117 $this->db->join($this->db->prefix.'wdk_categories ON '.$this->db->prefix.'wdk_categories.idcategory = '.$Winter_MVC_wdk_membership->subscription_m->_table_name.'.category_id', TRUE, 'LEFT');
118 $this->db->join($this->db->prefix.'wdk_locations ON '.$this->db->prefix.'wdk_locations.idlocation = '.$Winter_MVC_wdk_membership->subscription_m->_table_name.'.location_id', TRUE, 'LEFT');
119 $this->db->where(array(
120 '(date_expire > \''.current_time( 'mysql' ).'\')'=>NULL,
121 '(user_id = \''.wmvc_show_data('user_id_editor', $this->data['db_data'], false).'\')'=>NULL,
122 '(status = \'ACTIVE\')'=>NULL,
123 )
124 );
125
126 $subscriptions = $Winter_MVC_wdk_membership->subscription_user_m->get();
127 if (count($subscriptions) > 0) {
128 foreach($subscriptions as $subscription) {
129 $this->data['subscriptions'][wdk_show_data('subscription_id',$subscription,'', TRUE, TRUE)] = wdk_show_data('subscription_id', $subscription,'', TRUE, TRUE)
130 .', '.wdk_show_data('subscription_name', $subscription,'', TRUE, TRUE)
131 .', '.wdk_show_data('location_title',$subscription, esc_html__('Any', 'wpdirectorykit'), TRUE, TRUE).' '. esc_html__('Location', 'wpdirectorykit')
132 .', '.wdk_show_data('category_title',$subscription, esc_html__('Any', 'wpdirectorykit'), TRUE, TRUE).' '. esc_html__('Category', 'wpdirectorykit')
133 .'('.wdk_get_date(wdk_show_data('date_expire', $subscription,'', TRUE, TRUE)).')';
134 }
135 }
136 }
137
138
139 $this->db->where(array('field_type !='=> 'SECTION'));
140 $this->data['listing_fields'] = $this->field_m->get();
141
142 $this->data['fields'] = $this->field_m->get();
143
144 $rules = array(
145 array(
146 'field' => 'post_title',
147 'label' => __('Title', 'wpdirectorykit'),
148 'rules' => 'required'
149 ),
150 array(
151 'field' => 'post_content',
152 'label' => __('Content', 'wpdirectorykit'),
153 'rules' => (wdk_get_option('wdk_is_post_content_enable', FALSE)) ? 'required' : ''
154 ),
155 array(
156 'field' => 'category_id',
157 'label' => __('Category', 'wpdirectorykit'),
158 'rules' => (wdk_get_option('wdk_listing_category_required')) ? 'required':''
159 ),
160 array(
161 'field' => 'location_id',
162 'label' => __('Location', 'wpdirectorykit'),
163 'rules' => (wdk_get_option('wdk_listing_location_required')) ? 'required':''
164 ),
165 array(
166 'field' => 'address',
167 'label' => __('Address', 'wpdirectorykit'),
168 'rules' => ''
169 ),
170 array(
171 'field' => 'lat',
172 'label' => __('lat', 'wpdirectorykit'),
173 'rules' => (wdk_get_option('wdk_is_address_enabled')) ? 'wdk_gps_single':''
174 ),
175 array(
176 'field' => 'lng',
177 'label' => __('lng', 'wpdirectorykit'),
178 'rules' => (wdk_get_option('wdk_is_address_enabled')) ? 'wdk_gps_single':''
179 ),
180 array(
181 'field' => 'listing_images',
182 'label' => __('Listing images', 'wpdirectorykit'),
183 'rules' => (wdk_get_option('wdk_listings_images_required_enable')) ? 'required' : ''
184 ),
185 array(
186 'field' => 'listing_plans_documents',
187 'label' => __('Listing plans and documents', 'wpdirectorykit'),
188 'rules' => ''
189 ),
190 array(
191 'field' => 'is_featured',
192 'label' => __('Is Featured', 'wpdirectorykit'),
193 'rules' => ''
194 ),
195 array(
196 'field' => 'is_activated',
197 'label' => __('Is Activated', 'wpdirectorykit'),
198 'rules' => ''
199 ),
200 array(
201 'field' => 'is_approved',
202 'label' => __('Is Approved', 'wpdirectorykit'),
203 'rules' => ''
204 ),
205 array(
206 'field' => 'user_id_editor',
207 'label' => __('Agents', 'wpdirectorykit'),
208 'rules' => ''
209 ),
210 array(
211 'field' => 'listing_agents',
212 'label' => __('Agents', 'wpdirectorykit'),
213 'rules' => ''
214 ),
215 array(
216 'field' => 'listing_sub_locations',
217 'label' => __('Locations', 'wpdirectorykit'),
218 'rules' => ''
219 ),
220 array(
221 'field' => 'listing_sub_categories',
222 'label' => __('Categories', 'wpdirectorykit'),
223 'rules' => ''
224 ),
225 array(
226 'field' => 'package_id',
227 'label' => __('Package', 'wpdirectorykit'),
228 'rules' => ''
229 ),
230 array(
231 'field' => 'subscription_id',
232 'label' => __('Subscription id', 'wpdirectorykit'),
233 'rules' => ''
234 ),
235 array(
236 'field' => 'listing_parent_post_id',
237 'label' => __('Listing parent id', 'wpdirectorykit'),
238 'rules' => ''
239 ),
240 array(
241 'field' => 'listing_related_ids',
242 'label' => __('Listing childs', 'wpdirectorykit'),
243 'rules' => ''
244 ),
245 );
246
247 $rules[] = array(
248 'field' => 'rank',
249 'label' => __('Rank', 'wpdirectorykit'),
250 'rules' => 'numeric'
251 );
252
253
254 foreach($this->data['fields'] as $key => $field)
255 {
256 if($field->field_type == 'SECTION'){
257 $this->data['fields'][$key]->is_required = '';
258 continue;
259 }
260
261 $rule_required = (wmvc_show_data('is_required', $field) == 1) ? 'required' : '';
262
263 if(wmvc_show_data('validation', $field)) {
264 if(!empty($rule_required)) {
265 $rule_required .= '|';
266 }
267 $rule_required .= wmvc_show_data('validation', $field);
268 }
269
270 if(!empty(wmvc_show_data('min_length', $field))) {
271 if(!empty($rule_required)) {
272 $rule_required .= '|';
273 }
274
275 if(wmvc_show_data('field_type', $field) == "NUMBER") {
276 $rule_required .= "min_number";
277 } else {
278 $rule_required .= "min_length";
279 }
280 $rule_required .= "[".wmvc_show_data('min_length', $field)."]";
281
282 }
283
284 if(!empty(wmvc_show_data('max_length', $field))) {
285 if(!empty($rule_required)) {
286 $rule_required .= '|';
287 }
288 if(wmvc_show_data('field_type', $field) == "NUMBER") {
289 $rule_required .= "max_number";
290 } else {
291 $rule_required .= "max_length";
292 }
293 $rule_required .= "[".wmvc_show_data('max_length', $field)."]";
294 }
295
296 /* clear rules, because hidden field */
297 if(isset($_POST['category_id']) && !empty($_POST['category_id'])) {
298 if(wdk_depend_is_hidden_field($field->idfield, intval($_POST['category_id']))) {
299 $rule_required = '';
300 }
301 }
302
303 $rules[] =
304 array(
305 'field' => 'field_'.$field->idfield,
306 'label' => $field->field_label,
307 'rules' => $rule_required
308 );
309
310 if(isset($this->data['db_data']['field_'.$field->idfield.'_'.$field->field_type]))
311 $this->data['db_data']['field_'.$field->idfield] =
312 $this->data['db_data']['field_'.$field->idfield.'_'.$field->field_type];
313 }
314
315 $this->form->add_error_message('wdk_gps_single', __('Gps field is not valid, should be like xx.xxxxxx (between -180 and 180)', 'wpdirectorykit'));
316 if($this->form->run($rules))
317 {
318 // Check _wpnonce
319 check_admin_referer( 'wdk-listing-edit_'.$listing_post_id, '_wpnonce' );
320
321 $data = $this->listing_m->prepare_data(wdk_get_post(), $rules, FALSE);
322 // Save standard wp post
323
324 if(!isset($data['post_content'])) {
325 $data['post_content'] = '';
326 }
327
328 // Create post object
329 $listing_post = array(
330 'ID' => $listing_post_id,
331 'post_type' => 'wdk-listing',
332 'post_title' => wp_strip_all_tags( $data['post_title'] ),
333 'post_content' => $data['post_content'],
334 'post_status' => 'publish',
335 'post_author' => get_current_user_id()
336 );
337
338 // Insert the post into the database
339 $id = wp_insert_post( $listing_post );
340
341 // Save our main listing data
342
343 $listing_data = array('post_id' => $id);
344
345 $listing_data_fields = array('category_id', 'location_id', 'address', 'lat', 'lng', 'listing_images','listing_plans_documents', 'is_featured', 'is_activated','is_approved', 'package_id','rank','subscription_id',
346 'user_id_editor', 'listing_parent_post_id','listing_related_ids');
347 foreach($listing_data_fields as $field_name)
348 {
349 $listing_data[$field_name] = $data[$field_name];
350 }
351
352 $image_ids = explode(',', $data['listing_images']);
353
354 $listing_data['listing_images_path'] = '';
355 $listing_data['listing_images_path_medium'] = '';
356
357 if(is_array($image_ids)) {
358 foreach ($image_ids as $image_id) {
359 if(is_numeric($image_id))
360 {
361 $image_path = wp_get_original_image_path( $image_id);
362 if($image_path) {
363 /* path of image */
364 $next_path = str_replace(WP_CONTENT_DIR . '/uploads/','', $image_path);
365
366 if(!empty($listing_data['listing_images_path']))
367 $listing_data['listing_images_path'] .= ',';
368
369 $listing_data['listing_images_path'] .= $next_path;
370 }
371
372 $image_url = wp_get_attachment_image_url($image_id, 'large');
373 if($image_url) {
374 $parsed = parse_url($image_url);
375 $next_path = substr($parsed['path'], strpos($parsed['path'], 'uploads/')+8);
376
377 if(!empty($listing_data['listing_images_path_medium']))
378 $listing_data['listing_images_path_medium'] .= ',';
379
380 $listing_data['listing_images_path_medium'] .= $next_path;
381 }
382 }
383 }
384 }
385
386 if((wmvc_user_in_role('administrator') || current_user_can('wdk_listings_manage')) && $this->input->post('slug')) {
387 // update the post slug
388 wp_update_post( array(
389 'ID' => $id,
390 'post_name' => sanitize_text_field($this->input->post('slug'))
391 ));
392
393 }
394
395 if(!function_exists('run_wdk_membership')) {
396 if($listing_data['is_activated'] == 1) {
397 $listing_data['is_approved'] = 1;
398 } else {
399 $listing_data['is_approved'] = 0;
400 }
401 }
402
403 if(!wmvc_user_in_role('administrator') && !current_user_can('wdk_listings_manage')) {
404 unset($listing_data['rank']);
405 }
406
407 if(function_exists('run_wdk_payments') && wmvc_show_data('package_id', $listing_data_field, false)) {
408
409 global $Winter_MVC_wdk_payments;
410 $Winter_MVC_wdk_payments->model('package_m');
411 $package = $Winter_MVC_wdk_payments->package_m->get(wmvc_show_data('package_id', $listing_data_field, false), TRUE);
412 if ($packages) {
413 if(!isset($listing_data['rank']) || empty($listing_data['rank']))
414 $listing_data['rank'] = wdk_show_data('featured_rank',$package, 0, TRUE, TRUE);
415 $listing_data['date_package_expire'] = date('Y-m-d H:i:s', strtotime('+'.wdk_show_data('days_limit',$package, 0, TRUE, TRUE).'days'));
416 }
417 }
418
419 /* dates set */
420 if(isset($this->data['db_data']['date']))
421 $listing_data['date'] = $this->data['db_data']['date'];
422
423 $listing_data['date_modified'] = date('Y-m-d H:i:s');
424
425 if(empty($listing_db_data))
426 {
427 $id_ret = $this->listing_m->insert($listing_data, NULL);
428 }
429 else
430 {
431 $id_ret = $this->listing_m->insert($listing_data, $id);
432 }
433
434 if($this->db->last_error() != '')
435 exit('DB Error: '.$this->db->last_error());
436
437 //var_dump($id_ret);
438
439 // insert users/agents
440
441 if(function_exists('run_wdk_membership')){
442 $this->listingusers_m->delete_where(array('post_id' => $id));
443 if(is_array($data['listing_agents']))
444 foreach($data['listing_agents'] as $val)
445 {
446 $this->listingusers_m->insert(array('post_id' => $id, 'user_id' => $val), NULL);
447 }
448 }
449
450 $data_other_categories = array();
451 if(isset($data['listing_sub_categories']) || is_null($data['listing_sub_categories'])) {
452 $this->categorieslistings_m->delete_where(array('post_id' => $id));
453 if(is_array($data['listing_sub_categories']))
454 foreach($data['listing_sub_categories'] as $val)
455 {
456 $this->categorieslistings_m->insert(array('post_id' => $id, 'category_id' => $val), NULL);
457
458 $data_other_categories []= $val;
459 }
460 }
461
462 $data_other_locations = array();
463 if(isset($data['listing_sub_locations']) || is_null($data['listing_sub_locations'])) {
464 $this->locationslistings_m->delete_where(array('post_id' => $id));
465 if(is_array($data['listing_sub_locations']))
466 foreach($data['listing_sub_locations'] as $val)
467 {
468 $this->locationslistings_m->insert(array('post_id' => $id, 'location_id' => $val), NULL);
469 $data_other_locations []= $val;
470 }
471 }
472
473 $data_update = array(
474 'categories_list'=> '',
475 'locations_list'=>''
476 );
477
478 if(!empty($data_other_categories)) {
479 $data_update['categories_list'] = ','.join(',',$data_other_categories).',';
480 }
481
482 if(!empty($data_other_locations)) {
483 $data_update['locations_list'] = ','.join(',',$data_other_locations).',';
484 }
485
486
487 if(!empty($data_update))
488 $this->listing_m->insert($data_update, $id);
489
490 //exit($this->db->last_query());
491
492 // Save dynamic fields data
493
494 $data['post_id'] = $id;
495
496 global $wpdb;
497 foreach($this->data['fields'] as $key => $field)
498 {
499 if($field->field_type == 'TEXTAREA'){
500 $data[ 'field_'.$field->idfield ] = wp_encode_emoji( $data['field_'.$field->idfield] );
501 }
502 }
503
504 if(empty($listingfield_db_data))
505 {
506 $this->listingfield_m->insert_custom_fields($this->data['listing_fields'], $data, NULL);
507 }
508 else
509 {
510 $this->listingfield_m->insert_custom_fields($this->data['listing_fields'], $data, $id);
511 }
512
513 $this->load->model('editlog_m');
514 $this->editlog_m->insert(array(
515 'user_id' => get_current_user_id(),
516 'post_id' => $id,
517 'date' => date('Y-m-d H:i:s'),
518 'ip' => $_SERVER['REMOTE_ADDR']
519 ));
520
521
522 do_action('wpdirectorykit/listing/saved', $id, $this->data['db_data']);
523
524 if(wdk_get_option('wdk_sub_listings_enable')) {
525 /* generate fast childs ids for parents */
526
527 if(isset($listing_data['listing_parent_post_id']) && !empty($listing_data['listing_parent_post_id'])) {
528
529 $this->db->select('post_id');
530 $this->db->order_by('sublisting_order,idlisting');
531 $this->db->from($this->listing_m->_table_name);
532 $this->db->where(array('listing_parent_post_id' => intval($listing_data['listing_parent_post_id'])));
533 $query = $this->db->get();
534
535 $listings_childs = '';
536 if ($this->db->num_rows() > 0)
537 foreach ($this->db->results() as $listing) {
538 $listings_childs .= $listing->post_id.',';
539 }
540
541 if(!empty($listings_childs))
542 $listings_childs = substr($listings_childs,0, -1);
543
544 $this->listing_m->insert(array('listing_related_ids' => $listings_childs), intval($listing_data['listing_parent_post_id']));
545 }
546
547 if(isset($listing_data['listing_related_ids']) && !empty($listing_data['listing_related_ids'])) {
548
549 $old_childs_ids = wmvc_show_data('listing_related_ids', $this->data['db_data'],'',TRUE, TRUE);
550 $order_index = 0;
551 $listings_childs = '';
552
553 $old_childs_ids = explode(',', $old_childs_ids);
554 $old_childs_ids = array_flip($old_childs_ids);
555 foreach (explode(',', $listing_data['listing_related_ids']) as $idlisting) {
556 $this->listing_m->insert(array('listing_parent_post_id' => $listing_post_id, 'sublisting_order'=>$order_index++), intval($idlisting));
557
558 if(isset($old_childs_ids[$idlisting])) {
559 unset($old_childs_ids[$idlisting]);
560 }
561 }
562
563 /* clear old related listings */
564 if(!empty($old_childs_ids)) {
565 foreach ($old_childs_ids as $idlisting => $v) {
566 $this->listing_m->insert(array('listing_parent_post_id' => NULL), intval($idlisting));
567 }
568 }
569 }
570 }
571
572 // redirect
573 if(empty($listing_post_id) && !empty($id))
574 {
575 wp_redirect(admin_url("admin.php?page=wdk_listing&id=$id&is_updated=true"));
576 exit;
577 }
578
579 /* fix checkbox after submit */
580 if(!empty($id))
581 {
582 $is_approved_before_save = (isset($this->data['db_data']['is_approved'])) ? $this->data['db_data']['is_approved'] : 0;
583
584 $listing_post = get_post( $id );
585 $listing_db_data = $this->listing_m->get($id, TRUE);
586 $listingfield_db_data = $this->listingfield_m->get($id, TRUE);
587 $listingusers_db_data = $this->listingusers_m->get($id);
588 $this->data['db_data'] = array_merge((array) $listing_post,
589 (array) $listing_db_data,
590 (array) $listingfield_db_data);
591
592 $this->data['db_data']['listing_agents'] = array();
593 $this->data['db_data']['listing_sub_locations'] = array();
594 $this->data['db_data']['listing_sub_categories'] = array();
595
596 foreach ($listingusers_db_data as $key => $listinguser) {
597 if(isset($this->data['agents'][$listinguser->user_id]))
598 $this->data['db_data']['listing_agents'] [$listinguser->user_id]= $this->data['agents'][$listinguser->user_id];
599 }
600
601 if(isset($_POST['listing_sub_locations'])) {
602 $this->data['db_data']['listing_sub_locations'] = $_POST['listing_sub_locations'];
603 unset($_POST['listing_sub_locations']);
604 }
605 if(isset($_POST['listing_sub_categories'])) {
606 $this->data['db_data']['listing_sub_categories'] = $_POST['listing_sub_categories'];
607 unset($_POST['listing_sub_categories']);
608 }
609
610 /* if approved message */
611 if (!empty($listing_post_id) && wmvc_show_data('user_id', $data, false)) {
612 if( $is_approved_before_save != 1 && wmvc_show_data('is_approved', $data) == 1 && wmvc_show_data('is_activated', $data) == 1) {
613
614 $user = get_userdata( wmvc_show_data('user_id', $data) );
615
616 $data_message = array();
617 $data_message['user'] = $user;
618 $data_message['post_id'] = $id;
619 $data_message['post'] = $this->data['db_data'];
620 $ret = wdk_mail($user->user_email, __('Your Listing Approved', 'wpdirectorykit'), $data_message, 'new_listing_approved');
621 }
622 }
623 }
624
625 }
626
627 $this->data['calendar_id'] = NULL;
628 if(!empty($listing_post_id) && function_exists('run_wdk_bookings')) {
629 global $Winter_MVC_wdk_bookings;
630 $Winter_MVC_wdk_bookings->model('calendar_m');
631 $calendar = $Winter_MVC_wdk_bookings->calendar_m->get_by(array('post_id'=>$listing_post_id), TRUE);
632 if($calendar) {
633 $this->data['calendar_id'] = $calendar->idcalendar;
634 }
635 }
636
637 $this->load->view('wdk_listing/index', $this->data);
638 }
639
640 }
641