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(); } } } } }
/** * A function created to wrap code intended to handle * Admin Panel requests. * * The body of this function was in the content of awpcp.php * being executed every time the plugin file was read. * * The part of this function that handles Fees is @deprecated since 2.1.4. * The part of this function that handles Ads is @deprecated since 2.1.4. * The part of this function that handles Categories is still being used. */ function awpcp_handle_admin_requests() { global $wpdb; global $message; if (isset($_REQUEST['createeditadcategory']) && !empty($_REQUEST['createeditadcategory'])) { $tbl_ad_categories = $wpdb->prefix . "awpcp_categories"; $tbl_ads = $wpdb->prefix . "awpcp_ads"; $category_id = clean_field($_REQUEST['category_id']); if (isset($_REQUEST['$movetocat']) && !empty($_REQUEST['$movetocat'])) { $movetocat = clean_field($_REQUEST['movetocat']); } if (isset($_REQUEST['$deletetheads']) && !empty($_REQUEST['$deletetheads'])) { $deletetheads = $_REQUEST['deletetheads']; } $aeaction = clean_field($_REQUEST['aeaction']); if ($aeaction == 'newcategory') { $name = stripslashes_deep(awpcp_request_param('category_name')); $parent = intval(awpcp_request_param('category_parent_id')); $order = intval(awpcp_request_param('category_order')); $category = new AWPCP_Category(null, $name, null, $order, $parent); try { awpcp_categories_collection()->save($category); $themessagetoprint = __('The new category was successfully added.', 'AWPCP'); } catch (AWPCP_Exception $e) { $themessagetoprint = $e->getMessage(); } } elseif ($aeaction == 'delete') { if (isset($_REQUEST['category_name']) && !empty($_REQUEST['category_name'])) { $category_name = clean_field($_REQUEST['category_name']); } if (isset($_REQUEST['category_parent_id']) && !empty($_REQUEST['category_parent_id'])) { $category_parent_id = clean_field($_REQUEST['category_parent_id']); } // Make sure this is not the default category. If it is the default category alert that the default category can only be renamed not deleted if ($category_id == 1) { $themessagetoprint = __("Sorry but you cannot delete the default category. The default category can only be renamed", "AWPCP"); } else { //Proceed with the delete instructions // Move any ads that the category contains if move-to category value is set and does not equal zero if (isset($movetocat) && !empty($movetocat) && $movetocat != 0) { $movetocatparent = get_cat_parent_ID($movetocat); $query = 'UPDATE ' . AWPCP_TABLE_ADS . ' SET ad_category_id = %d ad_category_parent_id=%d '; $query .= 'WHERE ad_category_id = %d'; $query = $wpdb->prepare($query, $movetocat, $movetocatparent, $category_id); $wpdb->query($query); // Must also relocate ads where the main category was a child of the category being deleted $query = 'UPDATE ' . AWPCP_TABLE_ADS . ' SET ad_category_parent_id = %d WHERE ad_category_parent_id = %d'; $query = $wpdb->prepare($query, $movetocat, $category_id); $wpdb->query($query); // Must also relocate any children categories to the the move-to-cat $query = 'UPDATE ' . AWPCP_TABLE_CATEGORIES . ' SET category_parent_id = %d WHERE category_parent_id = %d'; $wpdb->prepare($query, $movetocat, $category_id); $wpdb->query($query); } elseif (!isset($movetocat) || empty($movetocat) || $movetocat == 0) { // If the category has a parent move the ads to the parent otherwise move the ads to the default if (category_is_child($category_id)) { $movetocat = get_cat_parent_ID($category_id); } else { $movetocat = 1; } $movetocatparent = get_cat_parent_ID($movetocat); // Adjust any ads transferred from the main category $query = "UPDATE " . $tbl_ads . " SET ad_category_id='{$movetocat}', ad_category_parent_id='{$movetocatparent}' WHERE ad_category_id='{$category_id}'"; $wpdb->query($query); // Must also relocate any children categories to the the move-to-cat $query = "UPDATE " . $tbl_ad_categories . " SET category_parent_id='{$movetocat}' WHERE category_parent_id='{$category_id}'"; $wpdb->query($query); // Adjust any ads transferred from children categories $query = "UPDATE " . $tbl_ads . " SET ad_category_parent_id='{$movetocat}' WHERE ad_category_parent_id='{$category_id}'"; $wpdb->query($query); } $query = "DELETE FROM " . AWPCP_TABLE_CATEGORIES . " WHERE category_id='{$category_id}'"; $wpdb->query($query); do_action('awpcp-category-deleted', $category_id); $themessagetoprint = __("The category has been deleted", "AWPCP"); } } elseif ($aeaction == 'edit') { $category = AWPCP_Category::find_by_id($category_id); $category->name = clean_field(awpcp_request_param('category_name')); $category->parent = intval(clean_field(awpcp_request_param('category_parent_id'))); $category->order = intval(awpcp_request_param('category_order', 0)); try { awpcp_categories_collection()->save($category); $themessagetoprint = __('Your category changes have been saved.', 'AWPCP'); } catch (AWPCP_Exception $e) { $themessagetoprint = $e->getMessage(); } } else { $themessagetoprint = __("No changes made to categories.", "AWPCP"); } $message = "<div style=\"background-color: rgb(255, 251, 204);\" id=\"message\" class=\"awpcp-updated updated fade\">{$themessagetoprint}</div>"; $clearform = 1; } // Move multiple categories if (isset($_REQUEST['movemultiplecategories']) && !empty($_REQUEST['movemultiplecategories'])) { $tbl_ad_categories = $wpdb->prefix . "awpcp_categories"; $tbl_ads = $wpdb->prefix . "awpcp_ads"; // First get the array of categories to be deleted $categoriestomove = clean_field($_REQUEST['category_to_delete_or_move']); // Next get the value for where the admin wants to move the ads if (isset($_REQUEST['moveadstocategory']) && !empty($_REQUEST['moveadstocategory']) && $_REQUEST['moveadstocategory'] != 0) { $moveadstocategory = clean_field($_REQUEST['moveadstocategory']); // Next loop through the categories and move them to the new category foreach ($categoriestomove as $cattomove) { if ($cattomove != $moveadstocategory) { // First update all the ads in the category to take on the new parent ID $query = "UPDATE " . AWPCP_TABLE_ADS . " SET ad_category_parent_id='{$moveadstocategory}' WHERE ad_category_id='{$cattomove}'"; $wpdb->query($query); $query = "UPDATE " . AWPCP_TABLE_CATEGORIES . " SET category_parent_id='{$moveadstocategory}' WHERE category_id='{$cattomove}'"; $wpdb->query($query); } } $themessagetoprint = __("With the exception of any category that was being moved to itself, the categories have been moved", "AWPCP"); } else { $themessagetoprint = __("The categories have not been moved because you did not indicate where you want the categories to be moved to", "AWPCP"); } $message = "<div style=\"background-color: rgb(255, 251, 204);\" id=\"message\" class=\"awpcp-updated updated fade\">{$themessagetoprint}</div>"; } // Delete multiple categories if (isset($_REQUEST['deletemultiplecategories']) && !empty($_REQUEST['deletemultiplecategories'])) { $tbl_ad_categories = $wpdb->prefix . "awpcp_categories"; $tbl_ads = $wpdb->prefix . "awpcp_ads"; // First get the array of categories to be deleted $categoriestodelete = (array) clean_field($_REQUEST['category_to_delete_or_move']); // Next get the value of move/delete ads if (isset($_REQUEST['movedeleteads']) && !empty($_REQUEST['movedeleteads'])) { $movedeleteads = clean_field($_REQUEST['movedeleteads']); } else { $movedeleteads = 1; } // Next get the value for where the admin wants to move the ads if (isset($_REQUEST['moveadstocategory']) && !empty($_REQUEST['moveadstocategory']) && $_REQUEST['moveadstocategory'] != 0) { $moveadstocategory = clean_field($_REQUEST['moveadstocategory']); } else { $moveadstocategory = 1; } // Next make sure there is a default category with an ID of 1 because any ads that exist in the // categories will need to be moved to a default category if admin has checked move ads but // has not selected a move to category if ($moveadstocategory == 1 && !defaultcatexists($defid = 1)) { createdefaultcategory($idtomake = 1, $titletocallit = 'Untitled'); } // Next loop through the categories and move all their ads foreach ($categoriestodelete as $cattodel) { // Make sure this is not the default category which cannot be deleted if ($cattodel != 1) { // If admin has instructed moving ads move the ads if ($movedeleteads == 1) { // Now move the ads if any $movetocat = $moveadstocategory; $movetocatparent = get_cat_parent_ID($movetocat); // Move the ads in the category main $query = "UPDATE " . AWPCP_TABLE_ADS . " SET ad_category_id='{$movetocat}',ad_category_parent_id='{$movetocatparent}' WHERE ad_category_id='{$cattodel}'"; $wpdb->query($query); // Must also relocate ads where the main category was a child of the category being deleted $query = "UPDATE " . AWPCP_TABLE_ADS . " SET ad_category_parent_id='{$movetocat}' WHERE ad_category_parent_id='{$cattodel}'"; $wpdb->query($query); // Must also relocate any children categories that do not exist in the categories to delete loop to the the move-to-cat $query = "UPDATE " . AWPCP_TABLE_CATEGORIES . " SET category_parent_id='{$movetocat}' WHERE category_parent_id='{$cattodel}' AND category_id NOT IN (" . implode(',', $categoriestodelete) . ")"; $wpdb->query($query); } elseif ($movedeleteads == 2) { $movetocat = $moveadstocategory; // If the category has children move the ads in the child categories to the default category if (category_has_children($cattodel)) { // Relocate the ads ads in any children categories of the category being deleted $query = "UPDATE " . AWPCP_TABLE_ADS . " SET ad_category_parent_id='{$movetocat}' WHERE ad_category_parent_id='{$cattodel}'"; $wpdb->query($query); // Relocate any children categories that exist under the category being deleted $query = "UPDATE " . AWPCP_TABLE_CATEGORIES . " SET category_parent_id='{$movetocat}' WHERE category_parent_id='{$cattodel}'"; $wpdb->query($query); } // Now delete the ads because the admin has checked Delete ads if any massdeleteadsfromcategory($cattodel); } // Now delete the categories $query = "DELETE FROM " . AWPCP_TABLE_CATEGORIES . " WHERE category_id='{$cattodel}'"; $wpdb->query($query); $themessagetoprint = __("The categories have been deleted", "AWPCP"); } } if (isset($themessagetoprint)) { $message = "<div style=\"background-color: rgb(255, 251, 204);\" id=\"message\" class=\"awpcp-updated updated fade\">{$themessagetoprint}</div>"; } } }