PluginProbe
WP Directory Kit / 1.2.9
WP Directory Kit v1.2.9
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.2.9, at application/controllers/Wdk_listing.php

637 lines 29.4 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' => '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 // Create post object
325 $listing_post = array(
326 'ID' => $listing_post_id,
327 'post_type' => 'wdk-listing',
328 'post_title' => wp_strip_all_tags( $data['post_title'] ),
329 'post_content' => $data['post_content'],
330 'post_status' => 'publish',
331 'post_author' => get_current_user_id()
332 );
333
334 // Insert the post into the database
335 $id = wp_insert_post( $listing_post );
336
337 // Save our main listing data
338
339 $listing_data = array('post_id' => $id);
340
341 $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',
342 'user_id_editor', 'listing_parent_post_id','listing_related_ids');
343 foreach($listing_data_fields as $field_name)
344 {
345 $listing_data[$field_name] = $data[$field_name];
346 }
347
348 $image_ids = explode(',', $data['listing_images']);
349
350 $listing_data['listing_images_path'] = '';
351 $listing_data['listing_images_path_medium'] = '';
352
353 if(is_array($image_ids)) {
354 foreach ($image_ids as $image_id) {
355 if(is_numeric($image_id))
356 {
357 $image_path = wp_get_original_image_path( $image_id);
358 if($image_path) {
359 /* path of image */
360 $next_path = str_replace(WP_CONTENT_DIR . '/uploads/','', $image_path);
361
362 if(!empty($listing_data['listing_images_path']))
363 $listing_data['listing_images_path'] .= ',';
364
365 $listing_data['listing_images_path'] .= $next_path;
366 }
367
368 $image_url = wp_get_attachment_image_url($image_id, 'large');
369 if($image_url) {
370 $parsed = parse_url($image_url);
371 $next_path = substr($parsed['path'], strpos($parsed['path'], 'uploads/')+8);
372
373 if(!empty($listing_data['listing_images_path_medium']))
374 $listing_data['listing_images_path_medium'] .= ',';
375
376 $listing_data['listing_images_path_medium'] .= $next_path;
377 }
378 }
379 }
380 }
381
382 if((wmvc_user_in_role('administrator') || current_user_can('wdk_listings_manage')) && $this->input->post('slug')) {
383 // update the post slug
384 wp_update_post( array(
385 'ID' => $id,
386 'post_name' => sanitize_text_field($this->input->post('slug'))
387 ));
388
389 }
390
391 if(!function_exists('run_wdk_membership')) {
392 if($listing_data['is_activated'] == 1) {
393 $listing_data['is_approved'] = 1;
394 } else {
395 $listing_data['is_approved'] = 0;
396 }
397 }
398
399 if(!wmvc_user_in_role('administrator') && !current_user_can('wdk_listings_manage')) {
400 unset($listing_data['rank']);
401 }
402
403 if(function_exists('run_wdk_payments') && wmvc_show_data('package_id', $listing_data_field, false)) {
404
405 global $Winter_MVC_wdk_payments;
406 $Winter_MVC_wdk_payments->model('package_m');
407 $package = $Winter_MVC_wdk_payments->package_m->get(wmvc_show_data('package_id', $listing_data_field, false), TRUE);
408 if ($packages) {
409 if(!isset($listing_data['rank']) || empty($listing_data['rank']))
410 $listing_data['rank'] = wdk_show_data('featured_rank',$package, 0, TRUE, TRUE);
411 $listing_data['date_package_expire'] = date('Y-m-d H:i:s', strtotime('+'.wdk_show_data('days_limit',$package, 0, TRUE, TRUE).'days'));
412 }
413 }
414
415 /* dates set */
416 if(isset($this->data['db_data']['date']))
417 $listing_data['date'] = $this->data['db_data']['date'];
418
419 $listing_data['date_modified'] = date('Y-m-d H:i:s');
420
421 if(empty($listing_db_data))
422 {
423 $id_ret = $this->listing_m->insert($listing_data, NULL);
424 }
425 else
426 {
427 $id_ret = $this->listing_m->insert($listing_data, $id);
428 }
429
430 if($this->db->last_error() != '')
431 exit('DB Error: '.$this->db->last_error());
432
433 //var_dump($id_ret);
434
435 // insert users/agents
436
437 if(function_exists('run_wdk_membership')){
438 $this->listingusers_m->delete_where(array('post_id' => $id));
439 if(is_array($data['listing_agents']))
440 foreach($data['listing_agents'] as $val)
441 {
442 $this->listingusers_m->insert(array('post_id' => $id, 'user_id' => $val), NULL);
443 }
444 }
445
446 $data_other_categories = array();
447 if(isset($data['listing_sub_categories']) || is_null($data['listing_sub_categories'])) {
448 $this->categorieslistings_m->delete_where(array('post_id' => $id));
449 if(is_array($data['listing_sub_categories']))
450 foreach($data['listing_sub_categories'] as $val)
451 {
452 $this->categorieslistings_m->insert(array('post_id' => $id, 'category_id' => $val), NULL);
453
454 $data_other_categories []= $val;
455 }
456 }
457
458 $data_other_locations = array();
459 if(isset($data['listing_sub_locations']) || is_null($data['listing_sub_locations'])) {
460 $this->locationslistings_m->delete_where(array('post_id' => $id));
461 if(is_array($data['listing_sub_locations']))
462 foreach($data['listing_sub_locations'] as $val)
463 {
464 $this->locationslistings_m->insert(array('post_id' => $id, 'location_id' => $val), NULL);
465 $data_other_locations []= $val;
466 }
467 }
468
469 $data_update = array(
470 'categories_list'=> '',
471 'locations_list'=>''
472 );
473
474 if(!empty($data_other_categories)) {
475 $data_update['categories_list'] = ','.join(',',$data_other_categories).',';
476 }
477
478 if(!empty($data_other_locations)) {
479 $data_update['locations_list'] = ','.join(',',$data_other_locations).',';
480 }
481
482
483 if(!empty($data_update))
484 $this->listing_m->insert($data_update, $id);
485
486 //exit($this->db->last_query());
487
488 // Save dynamic fields data
489
490 $data['post_id'] = $id;
491
492 global $wpdb;
493 foreach($this->data['fields'] as $key => $field)
494 {
495 if($field->field_type == 'TEXTAREA'){
496 $data[ 'field_'.$field->idfield ] = wp_encode_emoji( $data['field_'.$field->idfield] );
497 }
498 }
499
500 if(empty($listingfield_db_data))
501 {
502 $this->listingfield_m->insert_custom_fields($this->data['listing_fields'], $data, NULL);
503 }
504 else
505 {
506 $this->listingfield_m->insert_custom_fields($this->data['listing_fields'], $data, $id);
507 }
508
509 $this->load->model('editlog_m');
510 $this->editlog_m->insert(array(
511 'user_id' => get_current_user_id(),
512 'post_id' => $id,
513 'date' => date('Y-m-d H:i:s'),
514 'ip' => $_SERVER['REMOTE_ADDR']
515 ));
516
517
518 do_action('wpdirectorykit/listing/saved', $id, $this->data['db_data']);
519
520 if(wdk_get_option('wdk_sub_listings_enable')) {
521 /* generate fast childs ids for parents */
522
523 if(isset($listing_data['listing_parent_post_id']) && !empty($listing_data['listing_parent_post_id'])) {
524
525 $this->db->select('post_id');
526 $this->db->order_by('sublisting_order,idlisting');
527 $this->db->from($this->listing_m->_table_name);
528 $this->db->where(array('listing_parent_post_id' => intval($listing_data['listing_parent_post_id'])));
529 $query = $this->db->get();
530
531 $listings_childs = '';
532 if ($this->db->num_rows() > 0)
533 foreach ($this->db->results() as $listing) {
534 $listings_childs .= $listing->post_id.',';
535 }
536
537 if(!empty($listings_childs))
538 $listings_childs = substr($listings_childs,0, -1);
539
540 $this->listing_m->insert(array('listing_related_ids' => $listings_childs), intval($listing_data['listing_parent_post_id']));
541 }
542
543 if(isset($listing_data['listing_related_ids']) && !empty($listing_data['listing_related_ids'])) {
544
545 $old_childs_ids = wmvc_show_data('listing_related_ids', $this->data['db_data'],'',TRUE, TRUE);
546 $order_index = 0;
547 $listings_childs = '';
548
549 $old_childs_ids = explode(',', $old_childs_ids);
550 $old_childs_ids = array_flip($old_childs_ids);
551 foreach (explode(',', $listing_data['listing_related_ids']) as $idlisting) {
552 $this->listing_m->insert(array('listing_parent_post_id' => $listing_post_id, 'sublisting_order'=>$order_index++), intval($idlisting));
553
554 if(isset($old_childs_ids[$idlisting])) {
555 unset($old_childs_ids[$idlisting]);
556 }
557 }
558
559 /* clear old related listings */
560 if(!empty($old_childs_ids)) {
561 foreach ($old_childs_ids as $idlisting => $v) {
562 $this->listing_m->insert(array('listing_parent_post_id' => NULL), intval($idlisting));
563 }
564 }
565 }
566 }
567
568 // redirect
569 if(empty($listing_post_id) && !empty($id))
570 {
571 wp_redirect(admin_url("admin.php?page=wdk_listing&id=$id&is_updated=true"));
572 exit;
573 }
574
575 /* fix checkbox after submit */
576 if(!empty($id))
577 {
578 $is_approved_before_save = (isset($this->data['db_data']['is_approved'])) ? $this->data['db_data']['is_approved'] : 0;
579
580 $listing_post = get_post( $id );
581 $listing_db_data = $this->listing_m->get($id, TRUE);
582 $listingfield_db_data = $this->listingfield_m->get($id, TRUE);
583 $listingusers_db_data = $this->listingusers_m->get($id);
584 $this->data['db_data'] = array_merge((array) $listing_post,
585 (array) $listing_db_data,
586 (array) $listingfield_db_data);
587
588 $this->data['db_data']['listing_agents'] = array();
589 $this->data['db_data']['listing_sub_locations'] = array();
590 $this->data['db_data']['listing_sub_categories'] = array();
591
592 foreach ($listingusers_db_data as $key => $listinguser) {
593 if(isset($this->data['agents'][$listinguser->user_id]))
594 $this->data['db_data']['listing_agents'] [$listinguser->user_id]= $this->data['agents'][$listinguser->user_id];
595 }
596
597 if(isset($_POST['listing_sub_locations'])) {
598 $this->data['db_data']['listing_sub_locations'] = $_POST['listing_sub_locations'];
599 unset($_POST['listing_sub_locations']);
600 }
601 if(isset($_POST['listing_sub_categories'])) {
602 $this->data['db_data']['listing_sub_categories'] = $_POST['listing_sub_categories'];
603 unset($_POST['listing_sub_categories']);
604 }
605
606 /* if approved message */
607 if (!empty($listing_post_id) && wmvc_show_data('user_id', $data, false)) {
608 if( $is_approved_before_save != 1 && wmvc_show_data('is_approved', $data) == 1 && wmvc_show_data('is_activated', $data) == 1) {
609
610 $user = get_userdata( wmvc_show_data('user_id', $data) );
611
612 $data_message = array();
613 $data_message['user'] = $user;
614 $data_message['post_id'] = $id;
615 $data_message['post'] = $this->data['db_data'];
616 $ret = wdk_mail($user->user_email, __('Your Listing Approved', 'wpdirectorykit'), $data_message, 'new_listing_approved');
617 }
618 }
619 }
620
621 }
622
623 $this->data['calendar_id'] = NULL;
624 if(!empty($listing_post_id) && function_exists('run_wdk_bookings')) {
625 global $Winter_MVC_wdk_bookings;
626 $Winter_MVC_wdk_bookings->model('calendar_m');
627 $calendar = $Winter_MVC_wdk_bookings->calendar_m->get_by(array('post_id'=>$listing_post_id), TRUE);
628 if($calendar) {
629 $this->data['calendar_id'] = $calendar->idcalendar;
630 }
631 }
632
633 $this->load->view('wdk_listing/index', $this->data);
634 }
635
636 }
637