private function get_existing_regions_of_type($type, $hierarchy) { $parent_type = $this->get_parent_region_type($type); $parent = awpcp_array_data($parent_type, null, $hierarchy); $api = awpcp_basic_regions_api(); if (!is_null($parent)) { $regions = $api->find_by_parent_name($parent, $parent_type, $type); } else { $regions = $api->find_by_type($type); } return $regions; }
public function save_details_step($transaction, $errors = array()) { global $wpdb, $hasextrafieldsmodule; $data = $this->get_posted_details($_POST, $transaction); $characters = $this->get_characters_allowed($data['ad_id'], $transaction); $errors = array(); $payment_term = awpcp_payments_api()->get_transaction_payment_term($transaction); if (!$this->validate_details($data, false, $payment_term, $errors)) { return $this->details_step_form($transaction, $data, $errors); } $now = current_time('mysql'); if ($transaction->get('ad-id')) { $ad = AWPCP_Ad::find_by_id($transaction->get('ad-id')); } else { $ad = new AWPCP_Ad(); $totals = $transaction->get_totals(); $ad->adterm_id = $transaction->get('payment-term-id'); $ad->payment_term_type = $transaction->get('payment-term-type'); $ad->ad_transaction_id = $transaction->id; $ad->ad_fee_paid = $totals['money']; $ad->ad_key = AWPCP_Ad::generate_key(); $timestamp = awpcp_datetime('timestamp', $now); $payment_term = $ad->get_payment_term(); $ad->set_start_date($now); $ad->set_end_date($payment_term->calculate_end_date($timestamp)); $ad->ad_postdate = $now; $ad->disabled = true; $ad->payment_status = 'Unpaid'; } if (!$transaction->get('ad-id') || $this->verify_preview_hash($ad)) { $ad->user_id = $data['user_id']; $ad->ad_category_id = $data['ad_category']; $ad->ad_category_parent_id = get_cat_parent_ID($data['ad_category']); $ad->ad_title = $this->prepare_ad_title($data['ad_title'], $characters['characters_allowed_in_title']); $ad->ad_details = $this->prepare_ad_details($data['ad_details'], $characters['characters_allowed']); $ad->ad_contact_name = $data['ad_contact_name']; $ad->ad_contact_phone = $data['ad_contact_phone']; $ad->ad_contact_email = $data['ad_contact_email']; $ad->websiteurl = $data['websiteurl']; $ad->ad_item_price = $data['ad_item_price'] * 100; $ad->is_featured_ad = $data['is_featured_ad']; $ad->ad_last_updated = $now; $ad->posterip = awpcp_getip(); if (!$ad->save()) { $errors[] = __('There was an unexpected error trying to save your Ad details. Please try again or contact an administrator.', 'AWPCP'); return $this->details_step_form($transaction, $data, $errors); } $regions_allowed = $this->get_regions_allowed($ad->ad_id, $transaction); awpcp_basic_regions_api()->update_ad_regions($ad, $data['regions'], $regions_allowed); $transaction->set('ad-id', $ad->ad_id); do_action('awpcp-save-ad-details', $ad, $transaction); $transaction->save(); } if (awpcp_post_param('preview-hash', false)) { return $this->preview_step(); } else { if ($this->should_show_upload_files_step($ad)) { return $this->upload_images_step(); } else { if ((bool) get_awpcp_option('pay-before-place-ad')) { return $this->finish_step(); } else { if ((bool) get_awpcp_option('show-ad-preview-before-payment')) { return $this->preview_step(); } else { return $this->checkout_step(); } } } } }
/** * Handler for AJAX request from the Multiple Region Selector to get new options * for a given field. * * @since 3.0.2 */ public function get_regions_options() { $type = awpcp_request_param('type', '', $_GET); $parent_type = awpcp_request_param('parent_type', '', $_GET); $parent = awpcp_request_param('parent', '', $_GET); $context = awpcp_request_param('context', '', $_GET); $options = apply_filters('awpcp-get-regions-options', false, $type, $parent_type, $parent, $context); if ($options === false) { $options = array(); if ($context === 'search' && get_awpcp_option('buildsearchdropdownlists')) { $regions = awpcp_basic_regions_api()->find_by_parent_name($parent, $parent_type, $type); } else { $regions = array(); } $regions = array_filter($regions, 'strlen'); foreach ($regions as $key => $option) { $options[] = array('id' => $option, 'name' => $option); } } $response = array('status' => 'ok', 'options' => $options); header("Content-Type: application/json"); echo json_encode($response); die; }
private static function _get_ad_regions($ad_id) { $results = awpcp_basic_regions_api()->find_by_ad_id($ad_id); $regions = array(); foreach ($results as $region) { $regions[] = array('country' => $region->country, 'county' => $region->county, 'state' => $region->state, 'city' => $region->city); } return $regions; }
public function ajax_migrate_regions_information() { global $wpdb; if (awpcp_column_exists(AWPCP_TABLE_ADS, 'ad_country')) { $cursor = get_option('awpcp-migrate-regions-info-cursor', 0); $total = $this->count_ads_pending_region_information_migration($cursor); $sql = 'SELECT ad_id, ad_country, ad_state, ad_city, ad_county_village '; $sql .= 'FROM ' . AWPCP_TABLE_ADS . ' '; $sql .= 'WHERE ad_id > %d ORDER BY ad_id LIMIT 0, 100'; $results = $wpdb->get_results($wpdb->prepare($sql, $cursor)); $regions = awpcp_basic_regions_api(); foreach ($results as $ad) { $region = array(); if (!empty($ad->ad_country)) { $region['country'] = $ad->ad_country; } if (!empty($ad->ad_county_village)) { $region['county'] = $ad->ad_county_village; } if (!empty($ad->ad_state)) { $region['state'] = $ad->ad_state; } if (!empty($ad->ad_city)) { $region['city'] = $ad->ad_city; } if (!empty($region)) { // remove old data first $regions->delete_by_ad_id($ad->ad_id); $regions->save(array_merge(array('ad_id' => $ad->ad_id), $region)); } $cursor = $ad->ad_id; } update_option('awpcp-migrate-regions-info-cursor', $cursor); $remaining = $this->count_ads_pending_region_information_migration($cursor); if (0 === $remaining) { // TODO: do this in the next version // $columns = array( 'ad_country, ad_state, ad_city, ad_county_village' ); // foreach ( $columns as $column ) { // $wpdb->query( sprintf( 'ALTER TABLE %s DROP COLUMN', AWPCP_TABLE_ADS, $column ) ); // } // TODO: delete region_id column in a future upgrade and remove // all rows from ad_regions table that have no data in the country, county, state // and city columns. delete_option('awpcp-migrate-regions-information'); $this->update_pending_upgrades_status(); } } else { $total = 0; $remaining = 0; } return $this->ajax_response($total, $remaining); }
/** * @param transaction unused but required to match method * signature in parent class. */ public function save_details_step($transaction = null, $errors = array()) { global $wpdb, $hasextrafieldsmodule; $ad = $this->get_ad(); if (is_null($ad)) { $message = __('The specified Ad doesn\'t exists.', 'AWPCP'); return $this->render('content', awpcp_print_error($message)); } $data = $this->get_posted_details($_POST); $characters = $this->get_characters_allowed($ad->ad_id); $errors = array(); $payment_term = awpcp_payments_api()->get_ad_payment_term($ad); if (!$this->validate_details($data, true, $payment_term, $errors)) { return $this->details_step_form($ad, $data, $errors); } do_action('awpcp_before_edit_ad', $ad); // only admins can change the owner of an Ad if (!awpcp_current_user_is_moderator() || empty($data['user_id'])) { $data['user_id'] = $ad->user_id; } $ad->user_id = $data['user_id']; $ad->ad_title = $this->prepare_ad_title($data['ad_title'], $characters['characters_allowed_in_title']); $ad->ad_details = $this->prepare_ad_details($data['ad_details'], $characters['characters_allowed']); $ad->ad_contact_name = $data['ad_contact_name']; $ad->ad_contact_phone = $data['ad_contact_phone']; $ad->ad_contact_email = $data['ad_contact_email']; $ad->websiteurl = $data['websiteurl']; $ad->ad_item_price = $data['ad_item_price'] * 100; $ad->ad_last_updated = current_time('mysql'); if (awpcp_current_user_is_moderator()) { $ad->ad_startdate = awpcp_set_datetime_date($ad->ad_startdate, $data['start_date']); $ad->ad_enddate = awpcp_set_datetime_date($ad->ad_enddate, $data['end_date']); } if (awpcp_current_user_is_moderator() && !empty($data['ad_category'])) { $category = AWPCP_Category::find_by_id($data['ad_category']); if (!is_null($category)) { $ad->ad_category_id = $category->id; $ad->ad_category_parent_id = $category->parent; } } if (!$ad->save()) { $errors[] = __('There was an unexpected error trying to save your Ad details. Please try again or contact an administrator.', 'AWPCP'); return $this->details_step_form($ad, $data, $errors); } if (awpcp_current_user_is_moderator() || get_awpcp_option('allow-regions-modification')) { $regions_allowed = $this->get_regions_allowed($ad->ad_id); awpcp_basic_regions_api()->update_ad_regions($ad, $data['regions'], $regions_allowed); } do_action('awpcp_edit_ad', $ad); if (is_admin() || !awpcp_are_images_allowed()) { return $this->finish_step(); } else { return $this->upload_images_step(); } }
private function save_regions($region, $ad_id, $row, &$errors) { if (!$this->options['test-import']) { $ad = AWPCP_Ad::find_by_id($ad_id); awpcp_basic_regions_api()->update_ad_regions($ad, array($region), 1); } }