| @@ -5,8 +5,87 @@ | ||
| 5 | 5 | |
| 6 | 6 | public function __construct(){ |
| 7 | 7 | parent::__construct(); |
| 8 | 8 | } |
| 9 | + | |
| 10 | + public function copy() | |
| 11 | + { | |
| 12 | + $this->load->model('field_m'); | |
| 13 | + $this->load->model('listing_m'); | |
| 14 | + $this->load->model('listingfield_m'); | |
| 15 | + $this->load->model('listingusers_m'); | |
| 16 | + $this->load->model('category_m'); | |
| 17 | + $this->load->model('location_m'); | |
| 18 | + $this->load->model('user_m'); | |
| 19 | + $this->load->model('categorieslistings_m'); | |
| 20 | + $this->load->model('locationslistings_m'); | |
| 21 | + | |
| 22 | + $from_id = intval($_GET['from_id']); | |
| 23 | + $to_lang = sanitize_text_field(wp_unslash($_GET['to_lang'])); | |
| 24 | + | |
| 25 | + // fetch data | |
| 26 | + $listing_post = get_post( $from_id ); | |
| 27 | + | |
| 28 | + $listing_db_data = $this->listing_m->get($from_id, TRUE); | |
| 29 | + | |
| 30 | + $listingfield_db_data = $this->listingfield_m->get($from_id, TRUE); | |
| 31 | + $listingusers_db_data = $this->listingusers_m->get($from_id); | |
| 32 | + | |
| 33 | + $lang_from_code = pll_get_post_language($from_id); | |
| 34 | + | |
| 35 | + $post_data = array( | |
| 36 | + 'post_title' => wp_strip_all_tags($listing_post->post_title).' '.$to_lang, | |
| 37 | + 'post_content' => $listing_post->post_content, | |
| 38 | + 'post_status' => 'publish', | |
| 39 | + 'post_type' => 'wdk-listing', | |
| 40 | + 'post_author' => get_current_user_id() | |
| 41 | + // Other fields as needed | |
| 42 | + ); | |
| 43 | + | |
| 44 | + // Insert the custom post into the database | |
| 45 | + $post_id = wp_insert_post($post_data); | |
| 46 | + | |
| 47 | + pll_set_post_language($post_id, $to_lang); | |
| 48 | + | |
| 49 | + // Link the translations together | |
| 50 | + pll_save_post_translations(array( | |
| 51 | + $lang_from_code => $from_id, | |
| 52 | + $to_lang => $post_id, | |
| 53 | + )); | |
| 54 | + | |
| 55 | + $listing_data = array('post_id' => $post_id); | |
| 56 | + | |
| 57 | + | |
| 58 | + $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', | |
| 59 | + 'user_id_editor', 'listing_parent_post_id','listing_related_ids'); | |
| 60 | + foreach($listing_data_fields as $field_name) | |
| 61 | + { | |
| 62 | + if(isset($listing_db_data->$field_name)) | |
| 63 | + $listing_data[$field_name] = $listing_db_data->$field_name; | |
| 64 | + } | |
| 65 | + | |
| 66 | + $listing_data['date_modified'] = gmdate('Y-m-d H:i:s'); | |
| 67 | + | |
| 68 | + // copy listing data | |
| 69 | + $this->listing_m->insert($listing_data, NULL); | |
| 70 | + | |
| 71 | + if($this->db->last_error() != '') | |
| 72 | + exit('DB Error: '.esc_html($this->db->last_error())); | |
| 73 | + | |
| 74 | + $this->data['listing_fields'] = $this->field_m->get(); | |
| 75 | + | |
| 76 | + foreach($this->data['listing_fields'] as $field_data) | |
| 77 | + { | |
| 78 | + if(isset($listing_db_data->{'field_'.$field_data->idfield.'_'.$field_data->field_type})) | |
| 79 | + $listing_data['field_'.$field_data->idfield] = $listing_db_data->{'field_'.$field_data->idfield.'_'.$field_data->field_type}; | |
| 80 | + } | |
| 81 | + | |
| 82 | + $this->listingfield_m->insert_custom_fields($this->data['listing_fields'], $listing_data, NULL); | |
| 83 | + | |
| 84 | + //exit($this->db->last_query()); | |
| 85 | + | |
| 86 | + wp_redirect(get_admin_url() . "admin.php?page=wdk_listing&id=".$post_id); | |
| 87 | + } | |
| 9 | 88 | |
| 10 | 89 | // Edit listing method |
| 11 | 90 | public function index() |
| 12 | 91 | { |
| @@ -20,9 +99,9 @@ | ||
| 20 | 99 | $this->load->model('categorieslistings_m'); |
| 21 | 100 | $this->load->model('locationslistings_m'); |
| 22 | 101 | $this->load->load_helper('listing'); |
| 23 | 102 | |
| 24 | - $listing_post_id = $this->input->post_get('id'); | |
| 103 | + $listing_post_id = (int) $this->input->post_get('id'); | |
| 25 | 104 | |
| 26 | 105 | wdk_access_check('listing_m', $listing_post_id, NULL, 'edit'); |
| 27 | 106 | |
| 28 | 107 | $this->data['db_data'] = NULL; |
| @@ -29,8 +108,9 @@ | ||
| 29 | 108 | $this->data['db_data']['listing_agents'] = array(); |
| 30 | 109 | $this->data['db_data']['listing_sub_locations'] = array(); |
| 31 | 110 | $this->data['db_data']['listing_sub_categories'] = array(); |
| 32 | 111 | $this->data['form'] = &$this->form; |
| 112 | + $this->data['edit_log'] = NULL; | |
| 33 | 113 | |
| 34 | 114 | $this->data['categories'] = $this->category_m->get_parents(); |
| 35 | 115 | $this->data['locations'] = $this->location_m->get_parents(); |
| 36 | 116 | |
| @@ -82,8 +162,11 @@ | ||
| 82 | 162 | .'('.wdk_get_date(wdk_show_data('date_to', $package,'', TRUE, TRUE)).')'; |
| 83 | 163 | } |
| 84 | 164 | } |
| 85 | 165 | } |
| 166 | + | |
| 167 | + $this->load->model('editlog_m'); | |
| 168 | + $this->data['edit_log'] = $this->editlog_m->get_pagination_listing($listing_post_id, 10, NULL); | |
| 86 | 169 | } |
| 87 | 170 | |
| 88 | 171 | if(isset($_POST['listing_agents'])) { |
| 89 | 172 | $this->data['db_data']['listing_agents'] = array(); |
| @@ -108,26 +191,17 @@ | ||
| 108 | 191 | $Winter_MVC_wdk_membership->model('subscription_user_m'); |
| 109 | 192 | $Winter_MVC_wdk_membership->model('subscription_m'); |
| 110 | 193 | |
| 111 | 194 | $this->db->select('*'); |
| 112 | - $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'); | |
| 113 | 195 | $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'); |
| 114 | 196 | $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'); |
| 115 | - $this->db->where(array( | |
| 116 | - '(date_expire > \''.current_time( 'mysql' ).'\')'=>NULL, | |
| 117 | - '(user_id = \''.wmvc_show_data('user_id_editor', $this->data['db_data'], false).'\')'=>NULL, | |
| 118 | - '(status = \'ACTIVE\')'=>NULL, | |
| 119 | - ) | |
| 120 | - ); | |
| 121 | - | |
| 122 | - $subscriptions = $Winter_MVC_wdk_membership->subscription_user_m->get(); | |
| 197 | + $subscriptions = $Winter_MVC_wdk_membership->subscription_m->get(); | |
| 123 | 198 | if (count($subscriptions) > 0) { |
| 124 | 199 | foreach($subscriptions as $subscription) { |
| 125 | - $this->data['subscriptions'][wdk_show_data('subscription_id',$subscription,'', TRUE, TRUE)] = wdk_show_data('subscription_id', $subscription,'', TRUE, TRUE) | |
| 200 | + $this->data['subscriptions'][wdk_show_data('idsubscription', $subscription,'', TRUE, TRUE)] = wdk_show_data('idsubscription', $subscription,'', TRUE, TRUE) | |
| 126 | 201 | .', '.wdk_show_data('subscription_name', $subscription,'', TRUE, TRUE) |
| 127 | 202 | .', '.wdk_show_data('location_title',$subscription, esc_html__('Any', 'wpdirectorykit'), TRUE, TRUE).' '. esc_html__('Location', 'wpdirectorykit') |
| 128 | - .', '.wdk_show_data('category_title',$subscription, esc_html__('Any', 'wpdirectorykit'), TRUE, TRUE).' '. esc_html__('Category', 'wpdirectorykit') | |
| 129 | - .'('.wdk_get_date(wdk_show_data('date_expire', $subscription,'', TRUE, TRUE)).')'; | |
| 203 | + .', '.wdk_show_data('category_title',$subscription, esc_html__('Any', 'wpdirectorykit'), TRUE, TRUE).' '. esc_html__('Category', 'wpdirectorykit'); | |
| 130 | 204 | } |
| 131 | 205 | } |
| 132 | 206 | } |
| 133 | 207 | |
| @@ -145,9 +219,9 @@ | ||
| 145 | 219 | ), |
| 146 | 220 | array( |
| 147 | 221 | 'field' => 'post_content', |
| 148 | 222 | 'label' => __('Content', 'wpdirectorykit'), |
| 149 | - 'rules' => 'required' | |
| 223 | + 'rules' => (wdk_get_option('wdk_is_post_content_enable', FALSE)) ? 'required' : '' | |
| 150 | 224 | ), |
| 151 | 225 | array( |
| 152 | 226 | 'field' => 'category_id', |
| 153 | 227 | 'label' => __('Category', 'wpdirectorykit'), |
| @@ -165,19 +239,19 @@ | ||
| 165 | 239 | ), |
| 166 | 240 | array( |
| 167 | 241 | 'field' => 'lat', |
| 168 | 242 | 'label' => __('lat', 'wpdirectorykit'), |
| 169 | - 'rules' => '' | |
| 243 | + 'rules' => (wdk_get_option('wdk_is_address_enabled')) ? 'wdk_gps_single':'' | |
| 170 | 244 | ), |
| 171 | 245 | array( |
| 172 | 246 | 'field' => 'lng', |
| 173 | 247 | 'label' => __('lng', 'wpdirectorykit'), |
| 174 | - 'rules' => '' | |
| 248 | + 'rules' => (wdk_get_option('wdk_is_address_enabled')) ? 'wdk_gps_single':'' | |
| 175 | 249 | ), |
| 176 | 250 | array( |
| 177 | 251 | 'field' => 'listing_images', |
| 178 | 252 | 'label' => __('Listing images', 'wpdirectorykit'), |
| 179 | - 'rules' => '' | |
| 253 | + 'rules' => (wdk_get_option('wdk_listings_images_required_enable')) ? 'required' : '' | |
| 180 | 254 | ), |
| 181 | 255 | array( |
| 182 | 256 | 'field' => 'listing_plans_documents', |
| 183 | 257 | 'label' => __('Listing plans and documents', 'wpdirectorykit'), |
| @@ -227,8 +301,14 @@ | ||
| 227 | 301 | 'field' => 'subscription_id', |
| 228 | 302 | 'label' => __('Subscription id', 'wpdirectorykit'), |
| 229 | 303 | 'rules' => '' |
| 230 | 304 | ), |
| 305 | + array( | |
| 306 | + 'field' => 'listing_parent_post_id', | |
| 307 | + 'label' => __('Listing parent id', 'wpdirectorykit'), | |
| 308 | + 'rules' => '' | |
| 309 | + ), | |
| 310 | + | |
| 231 | 311 | ); |
| 232 | 312 | |
| 233 | 313 | $rules[] = array( |
| 234 | 314 | 'field' => 'rank', |
| @@ -236,8 +316,16 @@ | ||
| 236 | 316 | 'rules' => 'numeric' |
| 237 | 317 | ); |
| 238 | 318 | |
| 239 | 319 | |
| 320 | + if(wdk_get_option('wdk_sub_listings_enable')) { | |
| 321 | + $rules[] = array( | |
| 322 | + 'field' => 'listing_related_ids', | |
| 323 | + 'label' => __('Listing childs', 'wpdirectorykit'), | |
| 324 | + 'rules' => 'wdk_related_validation' | |
| 325 | + ); | |
| 326 | + } | |
| 327 | + | |
| 240 | 328 | foreach($this->data['fields'] as $key => $field) |
| 241 | 329 | { |
| 242 | 330 | if($field->field_type == 'SECTION'){ |
| 243 | 331 | $this->data['fields'][$key]->is_required = ''; |
| @@ -297,15 +385,22 @@ | ||
| 297 | 385 | $this->data['db_data']['field_'.$field->idfield] = |
| 298 | 386 | $this->data['db_data']['field_'.$field->idfield.'_'.$field->field_type]; |
| 299 | 387 | } |
| 300 | 388 | |
| 389 | + $this->form->add_error_message('wdk_gps_single', __('Gps field is not valid, should be like xx.xxxxxx (between -180 and 180)', 'wpdirectorykit')); | |
| 390 | + $this->form->add_error_message('wdk_related_validation', __('Related listings must not contain child listings and cannot be child listings themselves.', 'wpdirectorykit')); | |
| 301 | 391 | if($this->form->run($rules)) |
| 302 | 392 | { |
| 303 | - // Save procedure for basic data | |
| 304 | - | |
| 393 | + // Check _wpnonce | |
| 394 | + check_admin_referer( 'wdk-listing-edit_'.$listing_post_id, '_wpnonce' ); | |
| 395 | + | |
| 305 | 396 | $data = $this->listing_m->prepare_data(wdk_get_post(), $rules, FALSE); |
| 306 | 397 | // Save standard wp post |
| 307 | 398 | |
| 399 | + if(!isset($data['post_content'])) { | |
| 400 | + $data['post_content'] = ''; | |
| 401 | + } | |
| 402 | + | |
| 308 | 403 | // Create post object |
| 309 | 404 | $listing_post = array( |
| 310 | 405 | 'ID' => $listing_post_id, |
| 311 | 406 | 'post_type' => 'wdk-listing', |
| @@ -321,15 +416,22 @@ | ||
| 321 | 416 | // Save our main listing data |
| 322 | 417 | |
| 323 | 418 | $listing_data = array('post_id' => $id); |
| 324 | 419 | |
| 325 | - $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','user_id_editor'); | |
| 420 | + $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', | |
| 421 | + 'user_id_editor', 'listing_parent_post_id','listing_related_ids'); | |
| 422 | + | |
| 326 | 423 | foreach($listing_data_fields as $field_name) |
| 327 | 424 | { |
| 328 | - $listing_data[$field_name] = $data[$field_name]; | |
| 425 | + $listing_data[$field_name] = $data[$field_name] ?? ''; | |
| 329 | 426 | } |
| 330 | 427 | |
| 331 | - $image_ids = explode(',', $data['listing_images']); | |
| 428 | + if(empty($listing_data['user_id_editor'])) | |
| 429 | + $listing_data['user_id_editor'] = $this->data['db_data']['user_id_editor'] = get_current_user_id(); | |
| 430 | + | |
| 431 | + $image_ids = array(); | |
| 432 | + if(!empty($data['listing_images'])) | |
| 433 | + $image_ids = explode(',', $data['listing_images']); | |
| 332 | 434 | |
| 333 | 435 | $listing_data['listing_images_path'] = ''; |
| 334 | 436 | $listing_data['listing_images_path_medium'] = ''; |
| 335 | 437 | |
| @@ -349,9 +451,9 @@ | ||
| 349 | 451 | } |
| 350 | 452 | |
| 351 | 453 | $image_url = wp_get_attachment_image_url($image_id, 'large'); |
| 352 | 454 | if($image_url) { |
| 353 | - $parsed = parse_url($image_url); | |
| 455 | + $parsed = wp_parse_url($image_url); | |
| 354 | 456 | $next_path = substr($parsed['path'], strpos($parsed['path'], 'uploads/')+8); |
| 355 | 457 | |
| 356 | 458 | if(!empty($listing_data['listing_images_path_medium'])) |
| 357 | 459 | $listing_data['listing_images_path_medium'] .= ','; |
| @@ -359,11 +461,14 @@ | ||
| 359 | 461 | $listing_data['listing_images_path_medium'] .= $next_path; |
| 360 | 462 | } |
| 361 | 463 | } |
| 362 | 464 | } |
| 465 | + | |
| 466 | + /* add featured images */ | |
| 467 | + set_post_thumbnail($id, reset($image_ids)); | |
| 363 | 468 | } |
| 364 | 469 | |
| 365 | - if(wmvc_user_in_role('administrator') && $this->input->post('slug')) { | |
| 470 | + if((wmvc_user_in_role('administrator') || current_user_can('wdk_listings_manage')) && $this->input->post('slug')) { | |
| 366 | 471 | // update the post slug |
| 367 | 472 | wp_update_post( array( |
| 368 | 473 | 'ID' => $id, |
| 369 | 474 | 'post_name' => sanitize_text_field($this->input->post('slug')) |
| @@ -378,9 +483,9 @@ | ||
| 378 | 483 | $listing_data['is_approved'] = 0; |
| 379 | 484 | } |
| 380 | 485 | } |
| 381 | 486 | |
| 382 | - if(!wmvc_user_in_role('administrator')) { | |
| 487 | + if(!wmvc_user_in_role('administrator') && !current_user_can('wdk_listings_manage')) { | |
| 383 | 488 | unset($listing_data['rank']); |
| 384 | 489 | } |
| 385 | 490 | |
| 386 | 491 | if(function_exists('run_wdk_payments') && wmvc_show_data('package_id', $listing_data_field, false)) { |
| @@ -390,9 +495,9 @@ | ||
| 390 | 495 | $package = $Winter_MVC_wdk_payments->package_m->get(wmvc_show_data('package_id', $listing_data_field, false), TRUE); |
| 391 | 496 | if ($packages) { |
| 392 | 497 | if(!isset($listing_data['rank']) || empty($listing_data['rank'])) |
| 393 | 498 | $listing_data['rank'] = wdk_show_data('featured_rank',$package, 0, TRUE, TRUE); |
| 394 | - $listing_data['date_package_expire'] = date('Y-m-d H:i:s', strtotime('+'.wdk_show_data('days_limit',$package, 0, TRUE, TRUE).'days')); | |
| 499 | + $listing_data['date_package_expire'] = gmdate('Y-m-d H:i:s', strtotime('+'.wdk_show_data('days_limit',$package, 0, TRUE, TRUE).'days')); | |
| 395 | 500 | } |
| 396 | 501 | } |
| 397 | 502 | |
| 398 | 503 | /* dates set */ |
| @@ -398,19 +503,24 @@ | ||
| 398 | 503 | /* dates set */ |
| 399 | 504 | if(isset($this->data['db_data']['date'])) |
| 400 | 505 | $listing_data['date'] = $this->data['db_data']['date']; |
| 401 | 506 | |
| 402 | - $listing_data['date_modified'] = date('Y-m-d H:i:s'); | |
| 507 | + $listing_data['date_modified'] = gmdate('Y-m-d H:i:s'); | |
| 403 | 508 | |
| 404 | 509 | if(empty($listing_db_data)) |
| 405 | 510 | { |
| 406 | - $this->listing_m->insert($listing_data, NULL); | |
| 511 | + $id_ret = $this->listing_m->insert($listing_data, NULL); | |
| 407 | 512 | } |
| 408 | 513 | else |
| 409 | 514 | { |
| 410 | - $this->listing_m->insert($listing_data, $id); | |
| 515 | + $id_ret = $this->listing_m->insert($listing_data, $id); | |
| 411 | 516 | } |
| 412 | 517 | |
| 518 | + if($this->db->last_error() != '') | |
| 519 | + exit('DB Error: '.esc_html($this->db->last_error())); | |
| 520 | + | |
| 521 | + //var_dump($id_ret); | |
| 522 | + | |
| 413 | 523 | // insert users/agents |
| 414 | 524 | |
| 415 | 525 | if(function_exists('run_wdk_membership')){ |
| 416 | 526 | $this->listingusers_m->delete_where(array('post_id' => $id)); |
| @@ -466,8 +576,16 @@ | ||
| 466 | 576 | // Save dynamic fields data |
| 467 | 577 | |
| 468 | 578 | $data['post_id'] = $id; |
| 469 | 579 | |
| 580 | + global $wpdb; | |
| 581 | + foreach($this->data['fields'] as $key => $field) | |
| 582 | + { | |
| 583 | + if($field->field_type == 'TEXTAREA' && !empty($data['field_'.$field->idfield])){ | |
| 584 | + $data[ 'field_'.$field->idfield ] = wp_encode_emoji( $data['field_'.$field->idfield] ); | |
| 585 | + } | |
| 586 | + } | |
| 587 | + | |
| 470 | 588 | if(empty($listingfield_db_data)) |
| 471 | 589 | { |
| 472 | 590 | $this->listingfield_m->insert_custom_fields($this->data['listing_fields'], $data, NULL); |
| 473 | 591 | } |
| @@ -475,12 +593,70 @@ | ||
| 475 | 593 | { |
| 476 | 594 | $this->listingfield_m->insert_custom_fields($this->data['listing_fields'], $data, $id); |
| 477 | 595 | } |
| 478 | 596 | |
| 479 | - //exit($this->db->last_query()); | |
| 597 | + if($this->db->last_error() != '') | |
| 598 | + exit('DB Error: '.esc_html($this->db->last_error())); | |
| 480 | 599 | |
| 481 | - //exit($this->db->last_error()); | |
| 600 | + $this->load->model('editlog_m'); | |
| 601 | + $this->editlog_m->insert(array( | |
| 602 | + 'user_id' => get_current_user_id(), | |
| 603 | + 'post_id' => $id, | |
| 604 | + 'date' => gmdate('Y-m-d H:i:s'), | |
| 605 | + 'ip' => $_SERVER['REMOTE_ADDR'] | |
| 606 | + )); | |
| 482 | 607 | |
| 608 | + | |
| 609 | + do_action('wpdirectorykit/listing/saved', $id, $this->data['db_data']); | |
| 610 | + | |
| 611 | + if(wdk_get_option('wdk_sub_listings_enable')) { | |
| 612 | + /* generate fast childs ids for parents */ | |
| 613 | + | |
| 614 | + if(isset($listing_data['listing_parent_post_id']) && !empty($listing_data['listing_parent_post_id'])) { | |
| 615 | + | |
| 616 | + $this->db->select('post_id'); | |
| 617 | + $this->db->order_by('sublisting_order,idlisting'); | |
| 618 | + $this->db->from($this->listing_m->_table_name); | |
| 619 | + $this->db->where(array('listing_parent_post_id' => intval($listing_data['listing_parent_post_id']))); | |
| 620 | + $query = $this->db->get(); | |
| 621 | + | |
| 622 | + $listings_childs = ''; | |
| 623 | + if ($this->db->num_rows() > 0) | |
| 624 | + foreach ($this->db->results() as $listing) { | |
| 625 | + $listings_childs .= $listing->post_id.','; | |
| 626 | + } | |
| 627 | + | |
| 628 | + if(!empty($listings_childs)) | |
| 629 | + $listings_childs = substr($listings_childs,0, -1); | |
| 630 | + | |
| 631 | + $this->listing_m->insert(array('listing_related_ids' => $listings_childs), intval($listing_data['listing_parent_post_id'])); | |
| 632 | + } | |
| 633 | + | |
| 634 | + if(isset($listing_data['listing_related_ids']) && !empty($listing_data['listing_related_ids'])) { | |
| 635 | + | |
| 636 | + $old_childs_ids = wmvc_show_data('listing_related_ids', $this->data['db_data'],'',TRUE, TRUE); | |
| 637 | + $order_index = 0; | |
| 638 | + $listings_childs = ''; | |
| 639 | + | |
| 640 | + $old_childs_ids = explode(',', $old_childs_ids); | |
| 641 | + $old_childs_ids = array_flip($old_childs_ids); | |
| 642 | + foreach (explode(',', $listing_data['listing_related_ids']) as $idlisting) { | |
| 643 | + $this->listing_m->insert(array('listing_parent_post_id' => $listing_post_id, 'sublisting_order'=>$order_index++), intval($idlisting)); | |
| 644 | + | |
| 645 | + if(isset($old_childs_ids[$idlisting])) { | |
| 646 | + unset($old_childs_ids[$idlisting]); | |
| 647 | + } | |
| 648 | + } | |
| 649 | + | |
| 650 | + /* clear old related listings */ | |
| 651 | + if(!empty($old_childs_ids)) { | |
| 652 | + foreach ($old_childs_ids as $idlisting => $v) { | |
| 653 | + $this->listing_m->insert(array('listing_parent_post_id' => NULL), intval($idlisting)); | |
| 654 | + } | |
| 655 | + } | |
| 656 | + } | |
| 657 | + } | |
| 658 | + | |
| 483 | 659 | // redirect |
| 484 | 660 | if(empty($listing_post_id) && !empty($id)) |
| 485 | 661 | { |
| 486 | 662 | wp_redirect(admin_url("admin.php?page=wdk_listing&id=$id&is_updated=true")); |
| @@ -489,9 +665,9 @@ | ||
| 489 | 665 | |
| 490 | 666 | /* fix checkbox after submit */ |
| 491 | 667 | if(!empty($id)) |
| 492 | 668 | { |
| 493 | - $is_approved_before_save = $this->data['db_data']['is_approved']; | |
| 669 | + $is_approved_before_save = (isset($this->data['db_data']['is_approved'])) ? $this->data['db_data']['is_approved'] : 0; | |
| 494 | 670 | |
| 495 | 671 | $listing_post = get_post( $id ); |
| 496 | 672 | $listing_db_data = $this->listing_m->get($id, TRUE); |
| 497 | 673 | $listingfield_db_data = $this->listingfield_m->get($id, TRUE); |