function open_csa_wp_delete_product() { if (isset($_POST['product_id'])) { $product_id = intval(open_csa_wp_clean_input($_POST['product_id'])); if (!empty($product_id)) { // Updating the information global $wpdb; $product_is_used = $wpdb->get_var($wpdb->prepare("\n\t\t\t\t\t\t\t\t\tSELECT COUNT(product_id)\n\t\t\t\t\t\t\t\t\tFROM " . OPEN_CSA_WP_TABLE_PRODUCT_ORDERS . " \n\t\t\t\t\t\t\t\t\tWHERE product_id=%d", $product_id)); if ($product_is_used > 0) { echo 'skipped, used in orders'; } else { if ($wpdb->delete(OPEN_CSA_WP_TABLE_PRODUCTS, array('id' => $product_id), array('%d')) === FALSE) { echo 'error, sql request failed.'; } else { echo 'success'; } } } else { echo 'error,Empty values.'; } } else { echo 'error,Bad request.'; } wp_die(); // this is required to terminate immediately and return a proper response }
function open_csa_wp_delete_spot() { if (isset($_POST['spot_id'])) { $spot_id = intval(open_csa_wp_clean_input($_POST['spot_id'])); if (!empty($spot_id)) { global $wpdb; $spot_is_used_in_deliveries = $wpdb->get_var($wpdb->prepare("\n\t\t\t\t\t\t\t\t\t\t\t\t\tSELECT COUNT(spot_id)\n\t\t\t\t\t\t\t\t\t\t\t\t\tFROM " . OPEN_CSA_WP_TABLE_DELIVERIES . " \n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE spot_id=%d", $spot_id)); $spot_is_used_in_spots_to_users = $wpdb->get_var($wpdb->prepare("\n\t\t\t\t\t\t\t\t\t\t\t\t\tSELECT COUNT(spot_id)\n\t\t\t\t\t\t\t\t\t\t\t\t\tFROM " . OPEN_CSA_WP_TABLE_SPOTS_TO_USERS . " \n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE spot_id=%d", $spot_id)); if ($spot_is_used_in_deliveries > 0) { echo 'skipped, used in deliveries'; } else { // deleting entries in spot to user array if ($wpdb->delete(OPEN_CSA_WP_TABLE_SPOTS_TO_USERS, array('spot_id' => $spot_id), array('%d')) === FALSE) { echo 'error, sql request failed.'; } else { // deleting spot if ($wpdb->delete(OPEN_CSA_WP_TABLE_SPOTS, array('id' => $spot_id), array('%d')) === FALSE) { echo 'error, sql request failed.'; } else { echo 'success'; } echo 'success'; } } } else { echo 'error,Empty values.'; } } else { echo 'error,Bad request.'; } wp_die(); // this is required to terminate immediately and return a proper response }
function open_csa_wp_become_responsible() { if (isset($_POST['delivery_id']) && isset($_POST['user_id'])) { $delivery_id = intval(open_csa_wp_clean_input($_POST['delivery_id'])); $user_id = intval(open_csa_wp_clean_input($_POST['user_id'])); if (!empty($delivery_id) && !empty($user_id)) { global $wpdb; $user_in_charge = $wpdb->get_var($wpdb->prepare("SELECT user_in_charge FROM " . OPEN_CSA_WP_TABLE_DELIVERIES . " WHERE id=%d", $delivery_id)); if ($user_in_charge != null) { echo 'skipped, responsible user already exists'; } else { // Updating the information if ($wpdb->update(OPEN_CSA_WP_TABLE_DELIVERIES, array('user_in_charge' => $user_id), array('id' => $delivery_id)) === FALSE) { echo 'error, sql request failed'; } else { echo 'success'; } } } else { echo 'error,Empty values: '; } } else { echo 'error,Bad request.'; } wp_die(); // this is required to terminate immediately and return a proper response }
function CsaWpPluginDeleteDelivery() { if (isset($_POST['delivery_id'])) { $delivery_id = intval(open_csa_wp_clean_input($_POST['delivery_id'])); if (!empty($delivery_id)) { // Updating the information global $wpdb; if ($wpdb->delete(OPEN_CSA_WP_TABLE_DELIVERIES, array('id' => $delivery_id), array('%d')) === FALSE) { echo 'error, sql request failed.'; } else { echo 'success'; } } else { echo 'error,Empty values.'; } } else { echo 'error,Bad request.'; } wp_die(); // this is required to terminate immediately and return a proper response }