PluginProbe
WP Directory Kit / 1.3.3
WP Directory Kit v1.3.3
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_listing.php

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

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