public static function direct_payment_link($token, $order_id, $login) { global $wpdb; if (!empty($token) && !empty($order_id) && !empty($login)) { /** Verify informations **/ $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->users . ' WHERE user_login = %s AND user_activation_key = %s', $login, $token); $user_infos = $wpdb->get_row($query); if (!empty($user_infos)) { /** Connect the user **/ $secure_cookie = is_ssl() ? true : false; wp_set_auth_cookie($user_infos->ID, true, $secure_cookie); /** Add order to SESSION **/ $order_meta = get_post_meta($order_id, '_order_postmeta', true); $_SESSION['cart'] = array(); $_SESSION['cart']['order_items'] = array(); if (!empty($order_meta) && !empty($order_meta['order_items'])) { $wpshop_cart_type = 'cart'; foreach ($order_meta['order_items'] as $item) { $_SESSION['cart']['order_items'][$item['item_id']] = $item; } $wps_cart_ctr = new wps_cart(); $order = $wps_cart_ctr->calcul_cart_information(array()); $wps_cart_ctr->store_cart_in_session($order); } $_SESSION['order_id'] = $order_id; $wpdb->update($wpdb->users, array('user_activation_key' => ''), array('user_login' => $login)); wpshop_tools::wpshop_safe_redirect(get_permalink(wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')))); } else { wpshop_tools::wpshop_safe_redirect(get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id')))); } } }
/** * Define the different message and action after an action is send through the element interface */ function elementAction() { global $wpdb, $initialEavData; $pageMessage = $actionResult = ''; $attribute_undeletable = unserialize(WPSHOP_ATTRIBUTE_UNDELETABLE); /* Start definition of output message when action is doing on another page */ /************ CHANGE THE FIELD NAME TO TAKE TO DISPLAY *************/ /****************************************************************************/ $action = isset($_REQUEST['action']) ? wpshop_tools::varSanitizer($_REQUEST['action']) : 'add'; $saveditem = isset($_REQUEST['saveditem']) ? wpshop_tools::varSanitizer($_REQUEST['saveditem']) : ''; $set_section = !empty($_REQUEST[self::getDbTable()]['set_section']) ? wpshop_tools::varSanitizer($_REQUEST[self::getDbTable()]['set_section']) : ''; if (!empty($_REQUEST[self::getDbTable()]['set_section'])) { unset($_REQUEST[self::getDbTable()]['set_section']); } if (!empty($action) && $action == 'activate' && !empty($_REQUEST['id'])) { $query = $wpdb->update(self::getDbTable(), array('status' => 'moderated'), array('id' => $_REQUEST['id'])); wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . self::getListingSlug() . "&action=edit&id=" . $_REQUEST['id'])); } if ($action != '' && $action == 'saveok' && $saveditem > 0) { $editedElement = self::getElement($saveditem); $pageMessage = '<img src="' . WPSHOP_SUCCES_ICON . '" alt="action success" class="wpshopPageMessage_Icon" />' . sprintf(__('%s succesfully saved', 'wpshop'), '<span class="bold" >' . $editedElement->code . '</span>'); } elseif ($action != '' && $action == 'deleteok' && $saveditem > 0) { $editedElement = self::getElement($saveditem, "'deleted'"); $pageMessage = '<img src="' . WPSHOP_SUCCES_ICON . '" alt="action success" class="wpshopPageMessage_Icon" />' . sprintf(__('%s succesfully deleted', 'wpshop'), '<span class="bold" >' . $editedElement->code . '</span>'); } $wpshop_attribute_combo_values_list_order_def = !empty($_REQUEST[self::getDbTable()]['wpshop_attribute_combo_values_list_order_def']) ? $_REQUEST[self::getDbTable()]['wpshop_attribute_combo_values_list_order_def'] : array(); unset($_REQUEST[self::getDbTable()]['wpshop_attribute_combo_values_list_order_def']); if (!isset($_REQUEST[self::getDbTable()]['status'])) { $_REQUEST[self::getDbTable()]['status'] = 'moderated'; } if (!isset($_REQUEST[self::getDbTable()]['is_historisable'])) { $_REQUEST[self::getDbTable()]['is_historisable'] = 'no'; } if (!isset($_REQUEST[self::getDbTable()]['is_required'])) { $_REQUEST[self::getDbTable()]['is_required'] = 'no'; } if (!isset($_REQUEST[self::getDbTable()]['is_used_in_admin_listing_column'])) { $_REQUEST[self::getDbTable()]['is_used_in_admin_listing_column'] = 'no'; } if (!isset($_REQUEST[self::getDbTable()]['is_used_in_quick_add_form'])) { $_REQUEST[self::getDbTable()]['is_used_in_quick_add_form'] = 'no'; } if (!isset($_REQUEST[self::getDbTable()]['is_intrinsic'])) { $_REQUEST[self::getDbTable()]['is_intrinsic'] = 'no'; } if (!isset($_REQUEST[self::getDbTable()]['is_requiring_unit'])) { $_REQUEST[self::getDbTable()]['is_requiring_unit'] = 'no'; } if (!isset($_REQUEST[self::getDbTable()]['is_visible_in_front'])) { $_REQUEST[self::getDbTable()]['is_visible_in_front'] = 'no'; } if (!isset($_REQUEST[self::getDbTable()]['is_visible_in_front_listing'])) { $_REQUEST[self::getDbTable()]['is_visible_in_front_listing'] = 'no'; } if (!isset($_REQUEST[self::getDbTable()]['is_used_for_sort_by'])) { $_REQUEST[self::getDbTable()]['is_used_for_sort_by'] = 'no'; } if (!isset($_REQUEST[self::getDbTable()]['is_visible_in_advanced_search'])) { $_REQUEST[self::getDbTable()]['is_visible_in_advanced_search'] = 'no'; } if (!isset($_REQUEST[self::getDbTable()]['is_searchable'])) { $_REQUEST[self::getDbTable()]['is_searchable'] = 'no'; } if (!isset($_REQUEST[self::getDbTable()]['is_used_for_variation'])) { $_REQUEST[self::getDbTable()]['is_used_for_variation'] = 'no'; } if (!isset($_REQUEST[self::getDbTable()]['is_used_in_variation'])) { $_REQUEST[self::getDbTable()]['is_used_in_variation'] = 'no'; } if (!isset($_REQUEST[self::getDbTable()]['is_user_defined'])) { $_REQUEST[self::getDbTable()]['is_user_defined'] = 'no'; } if (!isset($_REQUEST[self::getDbTable()]['_display_informations_about_value'])) { $_REQUEST[self::getDbTable()]['_display_informations_about_value'] = 'no'; } /* Check frontend input and data type */ if (!empty($_REQUEST[self::getDbTable()]['frontend_input'])) { switch ($_REQUEST[self::getDbTable()]['frontend_input']) { case 'short_text': $_REQUEST[self::getDbTable()]['frontend_input'] = 'text'; if (empty($_REQUEST[self::getDbTable()]['backend_input'])) { $_REQUEST[self::getDbTable()]['backend_input'] = 'text'; } $_REQUEST[self::getDbTable()]['data_type'] = 'varchar'; break; case 'date_field': $_REQUEST[self::getDbTable()]['frontend_input'] = 'text'; if (empty($_REQUEST[self::getDbTable()]['backend_input'])) { $_REQUEST[self::getDbTable()]['backend_input'] = 'text'; } $_REQUEST[self::getDbTable()]['data_type'] = 'datetime'; break; case 'float_field': $_REQUEST[self::getDbTable()]['frontend_input'] = 'text'; if (empty($_REQUEST[self::getDbTable()]['backend_input'])) { $_REQUEST[self::getDbTable()]['backend_input'] = 'text'; } $_REQUEST[self::getDbTable()]['data_type'] = 'decimal'; break; case 'hidden_field': $_REQUEST[self::getDbTable()]['frontend_input'] = 'hidden'; if (empty($_REQUEST[self::getDbTable()]['backend_input'])) { $_REQUEST[self::getDbTable()]['backend_input'] = 'text'; } $_REQUEST[self::getDbTable()]['data_type'] = 'varchar'; break; case 'pass_field': $_REQUEST[self::getDbTable()]['frontend_input'] = 'password'; if (empty($_REQUEST[self::getDbTable()]['backend_input'])) { $_REQUEST[self::getDbTable()]['backend_input'] = 'text'; } $_REQUEST[self::getDbTable()]['data_type'] = 'varchar'; break; case 'select': $_REQUEST[self::getDbTable()]['frontend_input'] = 'select'; if (empty($_REQUEST[self::getDbTable()]['backend_input']) || empty($_REQUEST['id'])) { $_REQUEST[self::getDbTable()]['backend_input'] = 'multiple-select'; } $_REQUEST[self::getDbTable()]['data_type'] = 'integer'; break; case 'multiple-select': $_REQUEST[self::getDbTable()]['frontend_input'] = 'multiple-select'; if (empty($_REQUEST[self::getDbTable()]['backend_input']) || empty($_REQUEST['id'])) { $_REQUEST[self::getDbTable()]['backend_input'] = 'multiple-select'; } $_REQUEST[self::getDbTable()]['data_type'] = 'integer'; break; case 'radio': $_REQUEST[self::getDbTable()]['frontend_input'] = 'radio'; if (empty($_REQUEST[self::getDbTable()]['backend_input']) || empty($_REQUEST['id'])) { $_REQUEST[self::getDbTable()]['backend_input'] = 'multiple-select'; } $_REQUEST[self::getDbTable()]['data_type'] = 'integer'; break; case 'checkbox': $_REQUEST[self::getDbTable()]['frontend_input'] = 'checkbox'; if (empty($_REQUEST[self::getDbTable()]['backend_input']) || empty($_REQUEST['id'])) { $_REQUEST[self::getDbTable()]['backend_input'] = 'multiple-select'; } $_REQUEST[self::getDbTable()]['data_type'] = 'integer'; break; case 'textarea': $_REQUEST[self::getDbTable()]['frontend_input'] = 'textarea'; if (empty($_REQUEST[self::getDbTable()]['backend_input']) || empty($_REQUEST['id'])) { $_REQUEST[self::getDbTable()]['backend_input'] = 'textarea'; } $_REQUEST[self::getDbTable()]['data_type'] = 'text'; break; } } else { $_REQUEST[self::getDbTable()]['frontend_input'] = 'text'; if (empty($_REQUEST[self::getDbTable()]['backend_input'])) { $_REQUEST[self::getDbTable()]['backend_input'] = 'text'; } $_REQUEST[self::getDbTable()]['data_type'] = 'varchar'; } /* Check if the checkbox for ajax activation is checked for data update */ // if(!isset($_REQUEST[self::getDbTable()]['use_ajax_for_filling_field']) || empty($_REQUEST[self::getDbTable()]['use_ajax_for_filling_field'])){ // $_REQUEST[self::getDbTable()]['use_ajax_for_filling_field']='no'; // } $_REQUEST[self::getDbTable()]['use_ajax_for_filling_field'] = 'yes'; /* Define the database operation type from action launched by the user */ $_REQUEST[self::getDbTable()]['default_value'] = !empty($_REQUEST[self::getDbTable()]['default_value']) && is_array($_REQUEST[self::getDbTable()]['default_value']) ? serialize($_REQUEST[self::getDbTable()]['default_value']) : (isset($_REQUEST[self::getDbTable()]['default_value']) ? str_replace('"', "'", $_REQUEST[self::getDbTable()]['default_value']) : ''); if ($_REQUEST[self::getDbTable()]['data_type'] == 'datetime') { $date_default_value_trasform_into_config = array('default_value' => $_REQUEST[self::getDbTable()]['default_value'], 'field_options' => !empty($_POST[self::getDbTable() . '_options']) ? $_POST[self::getDbTable() . '_options'] : null); $_REQUEST[self::getDbTable()]['default_value'] = serialize($date_default_value_trasform_into_config); } /***************************** GENERIC **************************/ /*************************************************************************/ $pageAction = !empty($_REQUEST[self::getDbTable()]['frontend_label']) && isset($_REQUEST[self::getDbTable() . '_action']) ? wpshop_tools::varSanitizer($_REQUEST[self::getDbTable() . '_action']) : (!empty($_GET['action']) && $_GET['action'] == 'delete' ? $_GET['action'] : ''); $id = isset($_REQUEST[self::getDbTable()]['id']) ? wpshop_tools::varSanitizer($_REQUEST[self::getDbTable()]['id']) : (!empty($_GET['id']) ? $_GET['id'] : ''); if ($pageAction != '' && ($pageAction == 'edit' || $pageAction == 'editandcontinue')) { if (current_user_can('wpshop_edit_attributes')) { $_REQUEST[self::getDbTable()]['last_update_date'] = date('Y-m-d H:i:s'); if ($pageAction == 'delete') { $attribute_code = $_REQUEST[self::getDbTable()]['code']; if (!isset($_REQUEST[self::getDbTable()]['code']) || $_REQUEST[self::getDbTable()]['code'] == '') { $attribute = self::getElement($id, "'valid', 'moderated', 'notused'", 'id'); $attribute_code = $attribute->code; } if (!in_array($attribute_code, $attribute_undeletable)) { if (current_user_can('wpshop_delete_attributes')) { $_REQUEST[self::getDbTable()]['status'] = 'deleted'; } else { $actionResult = 'userNotAllowedForActionDelete'; } } else { $actionResult = 'unDeletableAtribute'; } } $actionResult = wpshop_database::update($_REQUEST[self::getDbTable()], $id, self::getDbTable()); } else { $actionResult = 'userNotAllowedForActionEdit'; } } elseif ($pageAction != '' && $pageAction == 'delete') { $attribute_code = ''; if (empty($_REQUEST[self::getDbTable()]['code'])) { $attribute = self::getElement($id, "'valid', 'moderated', 'notused', 'deleted'", 'id'); $attribute_code = $attribute->code; } if (!in_array($attribute_code, $attribute_undeletable)) { if (current_user_can('wpshop_delete_attributes')) { $_REQUEST[self::getDbTable()]['last_update_date'] = current_time('mysql', 0); $_REQUEST[self::getDbTable()]['status'] = 'deleted'; $actionResult = wpshop_database::update($_REQUEST[self::getDbTable()], $id, self::getDbTable()); } else { $actionResult = 'userNotAllowedForActionDelete'; } } else { $actionResult = 'unDeletableAtribute'; } } elseif ($pageAction != '' && ($pageAction == 'save' || $pageAction == 'saveandcontinue' || $pageAction == 'add')) { if (current_user_can('wpshop_add_attributes')) { $_REQUEST[self::getDbTable()]['creation_date'] = current_time('mysql', 0); if (trim($_REQUEST[self::getDbTable()]['code']) == '') { $_REQUEST[self::getDbTable()]['code'] = $_REQUEST[self::getDbTable()]['frontend_label']; } $_REQUEST[self::getDbTable()]['code'] = wpshop_tools::slugify(str_replace("\\'", "_", str_replace('\\"', "_", $_REQUEST[self::getDbTable()]['code'])), array('noAccent', 'noSpaces', 'lowerCase', 'noPunctuation')); $code_exists = self::getElement($_REQUEST[self::getDbTable()]['code'], "'valid', 'moderated', 'deleted'", 'code'); if ((is_object($code_exists) || is_array($code_exists)) && count($code_exists) > 0) { $_REQUEST[self::getDbTable()]['code'] = $_REQUEST[self::getDbTable()]['code'] . '_' . (count($code_exists) + rand()); } $actionResult = wpshop_database::save($_REQUEST[self::getDbTable()], self::getDbTable()); $id = $wpdb->insert_id; } else { $actionResult = 'userNotAllowedForActionAdd'; } } /* When an action is launched and there is a result message */ /************ CHANGE THE FIELD NAME TO TAKE TO DISPLAY *************/ /************ CHANGE ERROR MESSAGE FOR SPECIFIC CASE *************/ /****************************************************************************/ if ($actionResult != '') { $elementIdentifierForMessage = __('the attribute', 'wpshop'); if (!empty($_REQUEST[self::getDbTable()]['name'])) { $elementIdentifierForMessage = '<span class="bold" >' . $_REQUEST[self::getDbTable()]['frontend_label'] . '</span>'; } if ($actionResult == 'error') { /* CHANGE HERE FOR SPECIFIC CASE */ $pageMessage .= '<img src="' . WPSHOP_ERROR_ICON . '" alt="action error" class="wpshopPageMessage_Icon" />' . sprintf(__('An error occured while saving %s', 'wpshop'), $elementIdentifierForMessage, ' -> ' . $wpdb->last_error); } else { if ($actionResult == 'done' || $actionResult == 'nothingToUpdate') { /* CHANGE HERE FOR SPECIFIC CASE */ /*****************************************************************************************************************/ /************************* CHANGE FOR SPECIFIC ACTION FOR CURRENT ELEMENT ****************************/ /*****************************************************************************************************************/ /* Add the different option for the attribute that are set to combo box for frontend input */ $done_options_value = array(); $default_value = $_REQUEST[self::getDbTable()]['default_value']; $i = 1; if (!empty($_REQUEST['optionsUpdate'])) { /** * Check if there is an attribute code into sended request or if we have to get the code from database (Bug fix) */ if (empty($_REQUEST[self::getDbTable()]['code'])) { $attribute = self::getElement($id, "'valid', 'moderated', 'notused'", 'id'); $attribute_code = $attribute->code; } else { $attribute_code = $_REQUEST[self::getDbTable()]['code']; } foreach ($_REQUEST['optionsUpdate'] as $option_key => $option_label) { $option_value = !empty($_REQUEST['optionsUpdateValue'][$option_key]) ? str_replace(",", ".", $_REQUEST['optionsUpdateValue'][$option_key]) : ''; if (empty($option_value) || !in_array($option_value, $done_options_value)) { /* Update an existing value only if the value does not exist into existing list */ $label = $option_label != '' ? $option_label : str_replace(",", ".", $option_value); $value = str_replace(",", ".", $option_value); if (!WPSHOP_DISPLAY_VALUE_FOR_ATTRIBUTE_SELECT) { $label = $option_label; $value = str_replace(",", ".", $label); } $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('last_update_date' => current_time('mysql', 0), 'position' => $i, 'label' => stripslashes($label), 'value' => stripslashes($value)), array('id' => $option_key)); $done_options_value[] = str_replace(",", ".", $option_value); /* Check if this value is used for price calculation and make update on the different product using this value */ if ($attribute_code == WPSHOP_PRODUCT_PRICE_TAX) { $action = wpshop_prices::mass_update_prices(); } } if ($default_value == $option_key) { /* Update an existing a only if the value does not exist into existing list */ $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('last_update_date' => current_time('mysql', 0), 'default_value' => $option_key), array('id' => $id)); $done_options_value[] = str_replace(",", ".", $option_value); } $i++; } } if (!empty($_REQUEST['options'])) { foreach ($_REQUEST['options'] as $option_key => $option_label) { $option_value = !empty($_REQUEST['optionsValue'][$option_key]) ? str_replace(",", ".", $_REQUEST['optionsValue'][$option_key]) : sanitize_title($option_label); /* Check what value to use for the new values */ $label = !empty($option_label) ? $option_label : str_replace(",", ".", $option_value); if (!WPSHOP_DISPLAY_VALUE_FOR_ATTRIBUTE_SELECT && empty($option_value)) { $label = $option_label; $option_value = sanitize_title($label); } // If the optionsUpdateValue is empty, set it a empty array to avoid error calling the in_array() function $_REQUEST['optionsUpdateValue'] = !empty($_REQUEST['optionsUpdateValue']) ? $_REQUEST['optionsUpdateValue'] : array(); if (!in_array($option_value, $done_options_value) && !in_array($option_value, $_REQUEST['optionsUpdateValue'])) { $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('creation_date' => current_time('mysql', 0), 'status' => 'valid', 'attribute_id' => $id, 'position' => $i, 'label' => stripslashes($label), 'value' => stripslashes($option_value))); $done_options_value[] = str_replace(",", ".", $option_value); $last_insert_id = $wpdb->insert_id; if (empty($default_value)) { /* Update an existing a only if the value does not exist into existing list */ $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('last_update_date' => current_time('mysql', 0), 'default_value' => $last_insert_id), array('id' => $id)); $done_options_value[] = str_replace(",", ".", $option_value); } } $i++; } } // If the is_used_for_sort_by is mark as yes, we have to get out some attributes and save it separately if (!empty($_REQUEST[self::getDbTable()]['is_used_for_sort_by']) && $_REQUEST[self::getDbTable()]['is_used_for_sort_by'] == 'yes' || !empty($_REQUEST[self::getDbTable()]['is_filterable']) && $_REQUEST[self::getDbTable()]['is_filterable'] == 'yes' || !empty($_REQUEST[self::getDbTable()]['is_searchable']) && $_REQUEST[self::getDbTable()]['is_searchable'] == 'yes') { $attribute_code = $_REQUEST[self::getDbTable()]['code']; if (!isset($_REQUEST[self::getDbTable()]['code']) || $_REQUEST[self::getDbTable()]['code'] == '') { $attribute = self::getElement($id, "'valid', 'moderated', 'notused'", 'id'); $attribute_code = $attribute->code; } $count_products = wp_count_posts(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); for ($i = 0; $i <= $count_products->publish; $i += 20) { $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_status = %s ORDER BY ID DESC LIMIT ' . $i . ', 20', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'publish'); $products = $wpdb->get_results($query); if (!empty($products)) { foreach ($products as $product) { $query = $wpdb->prepare("SELECT value FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . $_REQUEST[self::getDbTable()]['data_type'] . " WHERE attribute_id = %d AND entity_type_id = %d AND entity_id = %d AND value != '' ORDER BY creation_date_value DESC", $id, $_REQUEST[self::getDbTable()]['entity_id'], $product->ID); $value = $wpdb->get_var($query); update_post_meta($product->ID, '_' . $attribute_code, $value); } } } wp_reset_query(); } if ($pageAction != 'delete') { /* Add the new attribute in the additionnal informations attribute group */ if (!empty($set_section)) { $choosen_set_section = explode('_', $set_section); $set_id = $choosen_set_section[0]; $group_id = $choosen_set_section[1]; } else { $attribute_current_attribute_set = 0; $query = $wpdb->prepare("\r\n\t\t\t\t\t\t\t\tSELECT id\r\n\t\t\t\t\t\t\t\tFROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " AS ATTRIBUTE_SET_DETAILS\r\n\t\t\t\t\t\t\t\tWHERE ATTRIBUTE_SET_DETAILS.status = 'valid'\r\n\t\t\t\t\t\t\t\t\tAND ATTRIBUTE_SET_DETAILS.attribute_id = %d\r\n\t\t\t\t\t\t\t\t\tAND ATTRIBUTE_SET_DETAILS.entity_type_id = %d", $id, $_REQUEST[self::getDbTable()]['entity_id']); $attribute_current_attribute_set = $wpdb->get_results($query); if (empty($attribute_current_attribute_set)) { $query = $wpdb->prepare("\r\n\t\t\t\t\t\t\t\tSELECT\r\n\t\t\t\t\t\t\t\t\t(\r\n\t\t\t\t\t\t\t\t\t\tSELECT ATTRIBUTE_SET.id\r\n\t\t\t\t\t\t\t\t\t\tFROM " . WPSHOP_DBT_ATTRIBUTE_SET . " AS ATTRIBUTE_SET\r\n\t\t\t\t\t\t\t\t\t\tWHERE ATTRIBUTE_SET.entity_id = %d\r\n\t\t\t\t\t\t\t\t\t\t\tAND ATTRIBUTE_SET.default_set = 'yes'\r\n\t\t\t\t\t\t\t\t\t) AS attribute_set_id,\r\n\t\t\t\t\t\t\t\t\t(\r\n\t\t\t\t\t\t\t\t\t\tSELECT ATTRIBUTE_GROUP.id\r\n\t\t\t\t\t\t\t\t\t\tFROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " AS ATTRIBUTE_GROUP\r\n\t\t\t\t\t\t\t\t\t\tINNER JOIN " . WPSHOP_DBT_ATTRIBUTE_SET . " AS ATTRIBUTE_SET ON ((ATTRIBUTE_SET.id = ATTRIBUTE_GROUP.attribute_set_id) AND (ATTRIBUTE_SET.entity_id = %d))\r\n\t\t\t\t\t\t\t\t\t\tWHERE ATTRIBUTE_GROUP.default_group = 'yes'\r\n\t\t\t\t\t\t\t\t\t\t\tAND ATTRIBUTE_GROUP.status = 'valid'\r\n\t\t\t\t\t\t\t\t\t) AS attribute_group_id", $_REQUEST[self::getDbTable()]['entity_id'], $_REQUEST[self::getDbTable()]['entity_id'], $_REQUEST[self::getDbTable()]['entity_id'], $_REQUEST[self::getDbTable()]['entity_id']); $wpshop_default_group = $wpdb->get_row($query); $set_id = $wpshop_default_group->attribute_set_id; $default_group_id = !empty($wpshop_default_group->default_attribute_group_id) ? $wpshop_default_group->default_attribute_group_id : ''; $group_id = !empty($default_group_id) ? $default_group_id : $wpshop_default_group->attribute_group_id; } } if (!empty($set_id) && !empty($group_id)) { $query = $wpdb->prepare("SELECT (MAX(position) + 1) AS position\r\n\t\t\t\t\t\t\t\tFROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . "\r\n\t\t\t\t\t\t\t\tWHERE attribute_set_id = %s\r\n\t\t\t\t\t\t\t\tAND attribute_group_id = %s\r\n\t\t\t\t\t\t\t\tAND entity_type_id = %s ", $set_id, $group_id, $_REQUEST[self::getDbTable()]['entity_id']); $wpshopAttributePosition = $wpdb->get_var($query); if ($wpshopAttributePosition == 0) { $wpshopAttributePosition = 1; } $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $_REQUEST[self::getDbTable()]['entity_id'], 'attribute_set_id' => $set_id, 'attribute_group_id' => $group_id, 'attribute_id' => $id, 'position' => $wpshopAttributePosition)); } } if (!empty($wpshop_attribute_combo_values_list_order_def)) { $post_order = explode(',', $wpshop_attribute_combo_values_list_order_def); $position = 1; foreach ($post_order as $post_id) { $wpdb->update($wpdb->posts, array('menu_order' => $position), array('ID' => str_replace('post_', '', $post_id))); $position++; } } /************************* GENERIC ****************************/ /*************************************************************************/ $pageMessage .= '<img src="' . WPSHOP_SUCCES_ICON . '" alt="action success" class="wpshopPageMessage_Icon" />' . sprintf(__('%s succesfully saved', 'wpshop'), $elementIdentifierForMessage); /* if(($pageAction == 'edit') || ($pageAction == 'save')){ wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . self::getListingSlug() . "&action=saveok&saveditem=" . $id)); } else */ if ($pageAction == 'add') { wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . self::getListingSlug() . "&action=edit&id=" . $id)); } elseif ($pageAction == 'delete') { wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . self::getListingSlug() . "&action=deleteok&saveditem=" . $id)); } } elseif ($actionResult == 'userNotAllowedForActionEdit' || $actionResult == 'userNotAllowedForActionAdd' || $actionResult == 'userNotAllowedForActionDelete') { $pageMessage .= '<img src="' . WPSHOP_ERROR_ICON . '" alt="action error" class="wpshopPageMessage_Icon" />' . __('You are not allowed to do this action', 'wpshop'); } elseif ($actionResult == 'unDeletableAtribute') { $pageMessage .= '<img src="' . WPSHOP_ERROR_ICON . '" alt="action error" class="wpshopPageMessage_Icon" />' . __('This attribute could not be deleted due to configuration', 'wpshop'); } } if (empty($_REQUEST[self::getDbTable()]['frontend_label']) && $pageAction != 'delete') { $pageMessage .= __('Please enter an label for the attribut', 'wpshop'); } } self::setMessage($pageMessage); }
/** * Affiche la page des groupes */ public static function display_page() { self::manage_post(); ob_start(); wpshop_display::displayPageHeader(__('Groups', 'wpshop'), '', __('Groups', 'wpshop'), __('Groups', 'wpshop'), true, 'admin.php?page=' . WPSHOP_NEWTYPE_IDENTIFIER_GROUP . '&action=add', ''); $content = ob_get_contents(); ob_end_clean(); $wps_customer_mdl = new wps_customer_mdl(); // Si on re�oit une action if (!empty($_GET['action'])) { $readonly_name_field = ''; switch ($_GET['action']) { case 'delete': if (!empty($_GET['code'])) { $roles = get_option('wp_user_roles', array()); if (isset($roles[$_GET['code']]) && $_GET['code'] != 'customer' && $_GET['code'] != 'wpshop_customer') { unset($roles[$_GET['code']]); $this->unaffectUsersToGroup($_GET['code']); update_option('wp_user_roles', $roles); } } wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . WPSHOP_NEWTYPE_IDENTIFIER_GROUP)); break; case 'edit': $readonly_name_field = 'readonly'; if (!empty($_GET['code'])) { $role = $this->getRole($_GET['code']); if (!empty($role)) { $group_name = $role['name']; $group_description = $role['description']; $group_parent = $role['parent']; $submit_button_value = __('Edit the group', 'wpshop'); $submit_button_name = 'editrole'; // ROLES $roles = get_option('wp_user_roles', array()); $select_parent = '<option value="">--</option>'; foreach ($roles as $code => $role) { if ($code != $_GET['code']) { $selected = $group_parent == $code ? 'selected' : ''; $select_parent .= '<option value="' . $code . '" ' . $selected . '>' . $role['name'] . '</option>'; } } // USERS $users = $wps_customer_mdl->getUserList(); if (!empty($users)) { $select_users = ''; foreach ($users as $user) { if ($user->ID != 1) { $u = new WP_User($user->ID); $selected = isset($u->roles[0]) && $u->roles[0] == $_GET['code'] ? 'selected' : ''; $select_users .= '<option value="' . $user->ID . '" ' . $selected . '>' . $user->user_login . '</option>'; } } } } else { wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . WPSHOP_NEWTYPE_IDENTIFIER_GROUP)); exit; } } else { wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . WPSHOP_NEWTYPE_IDENTIFIER_GROUP)); exit; } break; case 'add': $group_name = $group_description = ''; $submit_button_value = __('Create the group', 'wpshop'); $submit_button_name = 'addrole'; // ROLES $roles = get_option('wp_user_roles', array()); $select_parent = '<option value="">--</option>'; foreach ($roles as $code => $role) { $select_parent .= '<option value="' . $code . '">' . $role['name'] . '</option>'; } // USERS $users = $wps_customer_mdl->getUserList(); $select_users = ''; if (!empty($users)) { foreach ($users as $user) { if ($user->ID != 1) { $select_users .= '<option value="' . $user->ID . '">' . $user->user_login . '</option>'; } } } break; } $content .= ' <form method="post"> <label>' . __('Name', 'wpshop') . '</label><br /><input type="text" name="group-name" style="width:500px;" value="' . $group_name . '" ' . $readonly_name_field . ' /><br /><br /> <label>' . __('Parent', 'wpshop') . '</label><br /> <select name="group-parent" class="chosen_select" style="width:500px;"> ' . $select_parent . ' </select><br /><br /> <label>' . __('Users', 'wpshop') . '</label><br /> <select name="group-users[]" class="chosen_select" multiple style="width:500px;"> ' . $select_users . ' </select><br /><br /> <label>' . __('Description', 'wpshop') . '</label><br /><textarea name="group-description" style="width:500px;">' . $group_description . '</textarea><br /><br /> <input type="submit" class="button-primary" name="' . $submit_button_name . '" value="' . $submit_button_value . '" /> <a href="admin.php?page=' . WPSHOP_NEWTYPE_IDENTIFIER_GROUP . '">' . __('Cancel', 'wpshop') . '</a> </form> '; } else { $wpshop_list_table = new wpshop_groups_custom_List_table(); //Fetch, prepare, sort, and filter our data... $status = "'valid'"; if (!empty($_REQUEST['attribute_status'])) { switch ($_REQUEST['attribute_status']) { case 'unactive': $status = "'moderated', 'notused'"; if (empty($_REQUEST['orderby']) && empty($_REQUEST['order'])) { $_REQUEST['orderby'] = 'status'; $_REQUEST['order'] = 'asc'; } break; default: $status = "'" . $_REQUEST['attribute_status'] . "'"; break; } } $roles = get_option('wp_user_roles', array()); $i = 0; $attribute_set_list = array(); $group_not_to_display = array('administrator', 'editor', 'author', 'contributor', 'subscriber'); $wpshop_groups_meta = get_option('wpshop_groups_meta', array()); foreach ($roles as $code => $role) { if (!in_array($code, $group_not_to_display)) { $description = !empty($wpshop_groups_meta[$code]['description']) ? $wpshop_groups_meta[$code]['description'] : '--'; $attribute_set_list[$i]['name'] = $role['name']; $attribute_set_list[$i]['description'] = $description; $attribute_set_list[$i]['code'] = $code; $i++; } } $wpshop_list_table->prepare_items($attribute_set_list); ob_start(); $wpshop_list_table->display(); $element_output = ob_get_contents(); ob_end_clean(); $content .= $element_output; } $content .= '</div>'; echo $content; }
/** Force le t�l�chargement d'un fichier */ function forceDownload($nom, $path, $poids) { /*header('Content-Type: application/pdf'); header('Content-Length: '. $poids); header('Content-disposition: attachment; filename='. $nom); header('Pragma: no-cache'); header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0'); header('Expires: 0'); ob_clean(); flush();*/ wpshop_tools::wpshop_safe_redirect(str_replace(WP_CONTENT_DIR, WP_CONTENT_URL, $path)); //readfile($path); exit; }
/** * Define the different message and action after an action is send through the element interface */ function elementAction() { global $wpdb, $initialEavData; $pageMessage = $actionResult = ''; /* Start definition of output message when action is doing on another page */ /************ CHANGE THE FIELD NAME TO TAKE TO DISPLAY *************/ /****************************************************************************/ $action = isset($_REQUEST['action']) ? wpshop_tools::varSanitizer($_REQUEST['action']) : 'add'; $saveditem = isset($_REQUEST['saveditem']) ? wpshop_tools::varSanitizer($_REQUEST['saveditem']) : ''; if ($action != '' && $action == 'saveok' && $saveditem > 0) { $editedElement = self::getElement($saveditem); $pageMessage = '<img src="' . WPSHOP_SUCCES_ICON . '" alt="action success" class="wpshopPageMessage_Icon" />' . sprintf(__('%s succesfully saved', 'wpshop'), '<span class="bold" >' . $editedElement->code . '</span>'); } elseif ($action != '' && $action == 'deleteok' && $saveditem > 0) { $editedElement = self::getElement($saveditem, "'deleted'"); $pageMessage = '<img src="' . WPSHOP_SUCCES_ICON . '" alt="action success" class="wpshopPageMessage_Icon" />' . sprintf(__('%s succesfully deleted', 'wpshop'), '<span class="bold" >' . $editedElement->code . '</span>'); } /* Define the database operation type from action launched by the user */ $_REQUEST[self::getDbTable()]['default_value'] = str_replace('"', "'", $_REQUEST[self::getDbTable()]['default_value']); /************************* GENERIC **************************/ /*************************************************************************/ $pageAction = isset($_REQUEST[self::getDbTable() . '_action']) ? wpshop_tools::varSanitizer($_REQUEST[self::getDbTable() . '_action']) : ''; $id = isset($_REQUEST[self::getDbTable()]['id']) ? wpshop_tools::varSanitizer($_REQUEST[self::getDbTable()]['id']) : ''; if ($pageAction != '' && ($pageAction == 'edit' || $pageAction == 'editandcontinue')) { if (current_user_can('wpshop_edit_attributes')) { $_REQUEST[self::getDbTable()]['last_update_date'] = date('Y-m-d H:i:s'); if ($pageAction == 'delete') { if (current_user_can('wpshop_delete_attributes')) { $_REQUEST[self::getDbTable()]['status'] = 'deleted'; } else { $actionResult = 'userNotAllowedForActionDelete'; } } $actionResult = wpshop_database::update($_REQUEST[self::getDbTable()], $id, self::getDbTable()); } else { $actionResult = 'userNotAllowedForActionEdit'; } } elseif ($pageAction != '' && $pageAction == 'delete') { if (current_user_can('wpshop_delete_attributes')) { $_REQUEST[self::getDbTable()]['last_update_date'] = date('Y-m-d H:i:s'); $_REQUEST[self::getDbTable()]['status'] = 'deleted'; $actionResult = wpshop_database::update($_REQUEST[self::getDbTable()], $id, self::getDbTable()); } else { $actionResult = 'userNotAllowedForActionDelete'; } } elseif ($pageAction != '' && ($pageAction == 'save' || $pageAction == 'saveandcontinue' || $pageAction == 'add')) { if (current_user_can('wpshop_add_attributes')) { $_REQUEST[self::getDbTable()]['creation_date'] = date('Y-m-d H:i:s'); if (trim($_REQUEST[self::getDbTable()]['code']) == '') { $_REQUEST[self::getDbTable()]['code'] = $_REQUEST[self::getDbTable()]['frontend_label']; } $_REQUEST[self::getDbTable()]['code'] = wpshop_tools::slugify(str_replace("\\'", "_", str_replace('\\"', "_", $_REQUEST[self::getDbTable()]['code'])), array('noAccent', 'noSpaces', 'lowerCase', 'noPunctuation')); $code_exists = self::getElement($_REQUEST[self::getDbTable()]['code'], "'valid', 'moderated', 'deleted'", 'code'); if ((is_object($code_exists) || is_array($code_exists)) && count($code_exists) > 0) { $_REQUEST[self::getDbTable()]['code'] = $_REQUEST[self::getDbTable()]['code'] . '_' . (count($code_exists) + 1); } $actionResult = wpshop_database::save($_REQUEST[self::getDbTable()], self::getDbTable()); $id = $wpdb->insert_id; } else { $actionResult = 'userNotAllowedForActionAdd'; } } /* When an action is launched and there is a result message */ /************ CHANGE THE FIELD NAME TO TAKE TO DISPLAY *************/ /************ CHANGE ERROR MESSAGE FOR SPECIFIC CASE *************/ /****************************************************************************/ if ($actionResult != '') { $elementIdentifierForMessage = '<span class="bold" >' . $_REQUEST[self::getDbTable()]['frontend_label'] . '</span>'; if ($actionResult == 'error') { $pageMessage .= '<img src="' . WPSHOP_ERROR_ICON . '" alt="action error" class="wpshopPageMessage_Icon" />' . sprintf(__('An error occured while saving %s', 'wpshop'), $elementIdentifierForMessage); if (WPSHOP_DEBUG_MODE) { $pageMessage .= '<br/>' . $wpdb->last_error; } } elseif ($actionResult == 'done' || $actionResult == 'nothingToUpdate') { /* CHANGE HERE FOR SPECIFIC CASE */ /*****************************************************************************************************************/ /************************* CHANGE FOR SPECIFIC ACTION FOR CURRENT ELEMENT ******************/ /*****************************************************************************************************************/ /***********************************************************************************/ /************************* GENERIC ****************************/ /***********************************************************************************/ $pageMessage .= '<img src="' . WPSHOP_SUCCES_ICON . '" alt="action success" class="wpshopPageMessage_Icon" />' . sprintf(__('%s succesfully saved', 'wpshop'), $elementIdentifierForMessage); if ($pageAction == 'edit' || $pageAction == 'save') { wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . self::getListingSlug() . "&action=saveok&saveditem=" . $id)); } elseif ($pageAction == 'add') { wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . self::getListingSlug() . "&action=edit&id=" . $id)); } elseif ($pageAction == 'delete') { wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . self::getListingSlug() . "&action=deleteok&saveditem=" . $id)); } } elseif ($actionResult == 'userNotAllowedForActionEdit' || $actionResult == 'userNotAllowedForActionAdd' || $actionResult == 'userNotAllowedForActionDelete') { $pageMessage .= '<img src="' . WPSHOP_ERROR_ICON . '" alt="action error" class="wpshopPageMessage_Icon" />' . __('You are not allowed to do this action', 'wpshop'); } } self::setMessage($pageMessage); }
/** * Display Classic Checkout */ function show_classic_checkout() { if (!empty($_GET['action']) && $_GET['action'] == 'direct_payment_link') { wpshop_checkout::direct_payment_link($_GET['token'], $_GET['order_id'], $_GET['login']); } $checkout_step_indicator = do_shortcode('[wps_checkout_step_indicator]'); $checkout_content = ''; if (!empty($_GET['order_step'])) { switch ($_GET['order_step']) { case 1: ob_start(); require wpshop_tools::get_template_part(WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir, "frontend", "classic-checkout", "step-one"); $checkout_content .= ob_get_contents(); ob_end_clean(); break; case 2: if (get_current_user_id() != 0) { $permalink_option = get_option('permalink_structure'); $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); $url = get_permalink($checkout_page_id) . (!empty($permalink_option) ? '?' : '&') . 'order_step=3'; wpshop_tools::wpshop_safe_redirect($url); } else { ob_start(); require wpshop_tools::get_template_part(WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir, "frontend", "classic-checkout", "step-two"); $checkout_content .= ob_get_contents(); ob_end_clean(); } break; case 3: if (get_current_user_id() == 0) { $permalink_option = get_option('permalink_structure'); $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); $url = get_permalink($checkout_page_id) . (!empty($permalink_option) ? '?' : '&') . 'order_step=2'; wpshop_tools::wpshop_safe_redirect($url); } else { if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) { ob_start(); require wpshop_tools::get_template_part(WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir, "frontend", "classic-checkout", "step-three"); $checkout_content .= ob_get_contents(); ob_end_clean(); $url = apply_filters('wps_extra_signup_actions', isset($url) ? $url : ''); if (!empty($url)) { wpshop_tools::wpshop_safe_redirect($url); } } else { $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); $url = get_permalink($checkout_page_id); wpshop_tools::wpshop_safe_redirect($url); } } break; case 4: if (get_current_user_id() == 0) { $permalink_option = get_option('permalink_structure'); $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); $url = get_permalink($checkout_page_id) . (!empty($permalink_option) ? '?' : '&') . 'order_step=2'; wpshop_tools::wpshop_safe_redirect($url); } else { if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) { ob_start(); require wpshop_tools::get_template_part(WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir, "frontend", "classic-checkout", "step-four"); $checkout_content .= ob_get_contents(); ob_end_clean(); } else { $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); $url = get_permalink($checkout_page_id); wpshop_tools::wpshop_safe_redirect($url); } } break; case 5: if (get_current_user_id() == 0) { $permalink_option = get_option('permalink_structure'); $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); $url = get_permalink($checkout_page_id) . (!empty($permalink_option) ? '?' : '&') . 'order_step=2'; wpshop_tools::wpshop_safe_redirect($url); } else { $wps_cart = new wps_cart(); $order = $wps_cart->calcul_cart_information(array()); $wps_cart->store_cart_in_session($order); $shipping_option = get_option('wpshop_shipping_address_choice'); if (!empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) && (!empty($shipping_option) && !empty($shipping_option['activate']) && !empty($_SESSION['shipping_method']) || !empty($shipping_option) && empty($shipping_option['activate']))) { $order_id = !empty($_SESSION['cart']['order_id']) ? wpshop_tools::varSanitizer($_SESSION['cart']['order_id']) : 0; ob_start(); require wpshop_tools::get_template_part(WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir, "frontend", "classic-checkout", "step-five"); $checkout_content .= ob_get_contents(); ob_end_clean(); } else { $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); $url = get_permalink($checkout_page_id); wpshop_tools::wpshop_safe_redirect($url); } } break; case 6: if (!empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) { $wps_marketing_tools_ctr = new wps_marketing_tools_ctr(); $checkout_content .= $wps_marketing_tools_ctr->display_ecommerce_ga_tracker($_SESSION['order_id']); $checkout_content .= $this->wps_classic_confirmation_message(); } else { $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); $url = get_permalink($checkout_page_id); wpshop_tools::wpshop_safe_redirect($url); } break; default: ob_start(); require wpshop_tools::get_template_part(WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir, "frontend", "classic-checkout", "step-one"); $checkout_content .= ob_get_contents(); ob_end_clean(); break; } } else { $checkout_content = do_shortcode('[wps_cart]'); } require_once wpshop_tools::get_template_part(WPS_CLASSIC_CHECKOUT_DIR, $this->template_dir, "frontend", "classic_checkout"); }
/** * Define the different message and action after an action is send through the element interface */ function elementAction() { global $wpdb, $initialEavData; $pageMessage = $actionResult = ''; /* Start definition of output message when action is doing on another page */ /************ CHANGE THE FIELD NAME TO TAKE TO DISPLAY *************/ /****************************************************************************/ $saveditem = isset($_REQUEST['saveditem']) ? wpshop_tools::varSanitizer($_REQUEST['saveditem']) : ''; $action = isset($_REQUEST['action']) ? wpshop_tools::varSanitizer($_REQUEST['action']) : 'add'; if (!empty($action) && $action == 'activate' && !empty($_REQUEST['id'])) { $query = $wpdb->update(self::getDbTable(), array('status' => 'moderated'), array('id' => $_REQUEST['id'])); wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . self::getListingSlug() . "&action=edit&id=" . $_REQUEST['id'])); } if ($action != '' && $action == 'saveok' && $saveditem > 0) { $editedElement = self::getElement($saveditem); $pageMessage = '<img src="' . WPSHOP_SUCCES_ICON . '" alt="action success" class="wpshopPageMessage_Icon" />' . sprintf(__('%s succesfully saved', 'wpshop'), '<span class="bold" >' . $editedElement->name . '</span>'); } elseif ($action != '' && $action == 'deleteok' && $saveditem > 0) { $editedElement = self::getElement($saveditem, "'deleted'"); $pageMessage = '<img src="' . WPSHOP_SUCCES_ICON . '" alt="action success" class="wpshopPageMessage_Icon" />' . sprintf(__('%s succesfully deleted', 'wpshop'), '<span class="bold" >' . $editedElement->name . '</span>'); } /* Define the database operation type from action launched by the user */ /************************* GENERIC ****************************/ /*************************************************************************/ $pageAction = isset($_REQUEST[self::getDbTable() . '_action']) ? wpshop_tools::varSanitizer($_REQUEST[self::getDbTable() . '_action']) : (!empty($_GET['action']) && $_GET['action'] == 'delete' ? $_GET['action'] : ''); $id = isset($_REQUEST[self::getDbTable()]['id']) ? wpshop_tools::varSanitizer($_REQUEST[self::getDbTable()]['id']) : (!empty($_GET['id']) ? $_GET['id'] : ''); $set_section = !empty($_REQUEST[self::getDbTable()]['set_section']) ? wpshop_tools::varSanitizer($_REQUEST[self::getDbTable()]['set_section']) : ''; unset($_REQUEST[self::getDbTable()]['set_section']); /* Specific case for the attribute groups */ if (!isset($_REQUEST[self::getDbTable()]['status'])) { $_REQUEST[self::getDbTable()]['status'] = 'moderated'; } if (!isset($_REQUEST[self::getDbTable()]['default_set'])) { $_REQUEST[self::getDbTable()]['default_set'] = 'no'; } if ($pageAction != '' && ($pageAction == 'edit' || $pageAction == 'editandcontinue' || $pageAction == 'delete')) { if (current_user_can('wpshop_edit_attribute_set')) { $_REQUEST[self::getDbTable()]['last_update_date'] = date('Y-m-d H:i:s'); if ($pageAction == 'delete') { if (current_user_can('wpshop_delete_attribute_set')) { $_REQUEST[self::getDbTable()]['status'] = 'deleted'; } else { $actionResult = 'userNotAllowedForActionDelete'; } } $actionResult = wpshop_database::update($_REQUEST[self::getDbTable()], $id, self::getDbTable()); } else { $actionResult = 'userNotAllowedForActionEdit'; } /** Address display managment **/ if (!empty($_REQUEST['id'])) { $is_billing = $is_shipping = false; /** Get billing option **/ $billing_option = get_option('wpshop_billing_address'); $shipping_option = get_option('wpshop_shipping_address_choice'); if (!empty($billing_option) && !empty($billing_option['choice']) && $billing_option['choice'] == $_REQUEST['id']) { $is_billing = true; } if (!empty($shipping_option) && !empty($shipping_option['choice']) && $shipping_option['choice'] == $_REQUEST['id']) { $is_shipping = true; } $attribute_display = array(); if (!empty($_REQUEST['attribute_group_order'])) { foreach ($_REQUEST['attribute_group_order'] as $group_id => $group_def) { $end_line_element_id = 0; if ($group_id != 'newOrderNotAffectedAttribute') { $attribute_display[str_replace('newOrder', '', $group_id)] = explode(',', $group_def); foreach ($attribute_display[str_replace('newOrder', '', $group_id)] as $att_id => $att) { if ($att == 'wps-attribute-end-line') { $attribute_display[str_replace('newOrder', '', $group_id)][$att_id] = 'wps-attribute-end-line-' . $end_line_element_id; $end_line_element_id++; } } } } } if ($is_billing && !$is_shipping) { $billing_option['display_model'] = $attribute_display; update_option('wpshop_billing_address', $billing_option); } if (!$is_billing && $is_shipping) { $shipping_option['display_model'] = $attribute_display; update_option('wpshop_shipping_address_choice', $shipping_option); } } } elseif ($pageAction != '' && $pageAction == 'delete') { if (current_user_can('wpshop_delete_attribute_set')) { $_REQUEST[self::getDbTable()]['last_update_date'] = date('Y-m-d H:i:s'); $_REQUEST[self::getDbTable()]['status'] = 'deleted'; $actionResult = wpshop_database::update($_REQUEST[self::getDbTable()], $id, self::getDbTable()); } else { $actionResult = 'userNotAllowedForActionDelete'; } } elseif ($pageAction != '' && ($pageAction == 'save' || $pageAction == 'saveandcontinue' || $pageAction == 'add')) { if (current_user_can('wpshop_add_attribute_set')) { $_REQUEST[self::getDbTable()]['creation_date'] = date('Y-m-d H:i:s'); $actionResult = wpshop_database::save($_REQUEST[self::getDbTable()], self::getDbTable()); $id = $wpdb->insert_id; if (empty($set_section)) { $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_GROUP, array('status' => 'valid', 'attribute_set_id' => $id, 'position' => 1, 'creation_date' => current_time('mysql', 0), 'code' => 'general', 'default_group' => 'yes', 'name' => __('Main information', 'wpshop'))); $selected_entity_query = $wpdb->prepare("SELECT post_name FROM " . $wpdb->posts . " WHERE ID = %d", $_REQUEST[self::getDbTable()]['entity_id']); if (WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT == $wpdb->get_var($selected_entity_query)) { $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_GROUP, array('status' => 'valid', 'attribute_set_id' => $id, 'position' => 1, 'creation_date' => current_time('mysql', 0), 'code' => 'prices', 'default_group' => 'no', 'name' => __('Prices', 'wpshop'))); $price_attribute_set_id = $wpdb->insert_id; $price_tab = unserialize(WPSHOP_ATTRIBUTE_PRICES); unset($price_tab[array_search(WPSHOP_COST_OF_POSTAGE, $price_tab)]); foreach ($price_tab as $price_code) { $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s", $price_code); $attribute_id = $wpdb->get_var($query); switch ($price_code) { case WPSHOP_PRODUCT_PRICE_HT: $position = WPSHOP_PRODUCT_PRICE_PILOT == 'HT' ? 1 : 3; break; case WPSHOP_PRODUCT_PRICE_TAX: $position = 2; break; case WPSHOP_PRODUCT_PRICE_TTC: $position = WPSHOP_PRODUCT_PRICE_PILOT == 'HT' ? 3 : 1; break; case WPSHOP_PRODUCT_PRICE_TAX_AMOUNT: $position = 4; break; } $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $_REQUEST[self::getDbTable()]['entity_id'], 'attribute_set_id' => $id, 'attribute_group_id' => $price_attribute_set_id, 'attribute_id' => $attribute_id, 'position' => $position)); } } } } else { $actionResult = 'userNotAllowedForActionAdd'; } } /* When an action is launched and there is a result message */ /************ CHANGE THE FIELD NAME TO TAKE TO DISPLAY *************/ /************ CHANGE ERROR MESSAGE FOR SPECIFIC CASE *************/ /****************************************************************************/ if ($actionResult != '') { $elementIdentifierForMessage = __('the attribute group', 'wpshop'); if (!empty($_REQUEST[self::getDbTable()]['name'])) { $elementIdentifierForMessage = '<span class="bold" >' . $_REQUEST[self::getDbTable()]['name'] . '</span>'; } if ($actionResult == 'error') { /* CHANGE HERE FOR SPECIFIC CASE */ $pageMessage .= '<img src="' . WPSHOP_ERROR_ICON . '" alt="action error" class="wpshopPageMessage_Icon" />' . sprintf(__('An error occured while saving %s', 'wpshop'), $elementIdentifierForMessage); } elseif ($actionResult == 'done' || $actionResult == 'nothingToUpdate') { /*****************************************************************************************************************/ /************************* CHANGE FOR SPECIFIC ACTION FOR CURRENT ELEMENT ******************/ /*****************************************************************************************************************/ if (!empty($_REQUEST['wpshop_attribute_set_section_order'])) { $newOrder = str_replace('attribute_group_', '', $_REQUEST['wpshop_attribute_set_section_order']); $order = explode(',', $newOrder); foreach ($order as $position => $set_section_id) { $_REQUEST['wpshop_attribute_set_section'][$set_section_id]['position'] = $position; } } if (isset($_REQUEST['attribute_group_order']) && $_REQUEST['attribute_group_order'] != '') { foreach ($_REQUEST['attribute_group_order'] as $groupIdentifier => $newOrder) { $newOrder = str_replace('attribute_', '', $newOrder); $order = explode(',', $newOrder); $groupId = str_replace('newOrder', '', $groupIdentifier); $i = 1; foreach ($order as $element) { if ($element != '') { if ((int) $groupId > 0) { $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE attribute_id = %d AND status = %s AND attribute_set_id = %d", $element, 'valid', $id); $validElement = $wpdb->get_var($query); if (!empty($validElement)) { $query = $wpdb->prepare("UPDATE " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " SET position = %d, attribute_group_id = %d, last_update_date = NOW() WHERE attribute_id = %d AND status = %s AND attribute_set_id = %d", $i, $groupId, $element, 'valid', $id); } else { $query = $wpdb->prepare("INSERT INTO " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " (id, status, creation_date, entity_type_id, attribute_set_id, attribute_group_id, attribute_id, position) VALUES ('', 'valid', NOW(), %d, %d, %d, %d, %d)", $_REQUEST[self::getDbTable()]['entity_id'], $id, $groupId, $element, $i); } $wpdb->query($query); } else { $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'deleted', 'last_update_date' => current_time('mysql', 0), 'position' => 0), array('attribute_id' => $element, 'status' => 'valid', 'attribute_set_id' => $id)); } $i++; } } } } if (!empty($_REQUEST['wpshop_attribute_set_section'])) { foreach ($_REQUEST['wpshop_attribute_set_section'] as $set_section_id => $set_section_options) { if (!empty($set_section_options) && is_array($set_section_options)) { $set_section_options['default_group'] = !empty($_REQUEST['wpshop_attribute_set_section_is_default_of_set']) && $_REQUEST['wpshop_attribute_set_section_is_default_of_set'] == $set_section_id ? 'yes' : 'no'; $set_section_options['last_update_date'] = current_time('mysql', 0); $set_section_options['display_on_frontend'] = !empty($set_section_options['display_on_frontend']) && $set_section_options['display_on_frontend'] == 'yes' ? 'yes' : 'no'; $wpdb->update(WPSHOP_DBT_ATTRIBUTE_GROUP, $set_section_options, array('id' => $set_section_id), array('%s'), array('%d')); } } } if (!empty($set_section)) { $parent_attribute_set_detail = self::getAttributeSetDetails($set_section, "'valid'"); if (!empty($parent_attribute_set_detail)) { foreach ($parent_attribute_set_detail as $section => $section_detail) { $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_GROUP, array('status' => 'valid', 'attribute_set_id' => $id, 'creation_date' => current_time('mysql', 0), 'code' => $section_detail['code'], 'name' => $section_detail['name'], 'default_group' => $section_detail['is_default_group'], 'backend_display_type' => $section_detail['backend_display_type'], 'used_in_shop_type' => $section_detail['used_in_shop_type'], 'display_on_frontend' => $section_detail['display_on_frontend'])); $last_group_id = $wpdb->insert_id; foreach ($section_detail['attribut'] as $attribute) { $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $attribute->entity_id, 'attribute_set_id' => $id, 'attribute_group_id' => $last_group_id, 'attribute_id' => $attribute->id, 'position' => $attribute->attr_position_in_group)); } } } } /* If the current group is selected as default group set all others for current entity at no */ if ($_REQUEST[self::getDbTable()]['default_set'] == 'yes') { $entity_to_take = 0; if (isset($_REQUEST['attribute_set_group_id']) && $_REQUEST['attribute_set_group_id'] != '') { $entity_to_take = $_REQUEST['attribute_set_group_id']; } if (isset($_REQUEST[self::getDbTable()]['entity_id']) && $_REQUEST[self::getDbTable()]['entity_id'] != '') { $entity_to_take = $_REQUEST[self::getDbTable()]['entity_id']; } if ($entity_to_take > 0) { $query = $wpdb->prepare("UPDATE " . self::getDbTable() . " SET default_set = 'no' WHERE id != %d AND entity_id = %d", $id, $entity_to_take); $wpdb->query($query); } } /************************* GENERIC ****************************/ /*************************************************************************/ $pageMessage .= '<img src="' . WPSHOP_SUCCES_ICON . '" alt="action success" class="wpshopPageMessage_Icon" />' . sprintf(__('%s succesfully saved', 'wpshop'), $elementIdentifierForMessage); /* if(($pageAction == 'edit') || ($pageAction == 'save')) wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . self::getListingSlug() . "&action=saveok&saveditem=" . $id)); else */ if ($pageAction == 'add') { wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . self::getListingSlug() . "&action=edit&id=" . $id)); } elseif ($pageAction == 'delete') { wpshop_tools::wpshop_safe_redirect(admin_url('admin.php?page=' . self::getListingSlug() . "&action=deleteok&saveditem=" . $id)); } } elseif ($actionResult == 'userNotAllowedForActionEdit' || $actionResult == 'userNotAllowedForActionAdd' || $actionResult == 'userNotAllowedForActionDelete') { $pageMessage .= '<img src="' . WPSHOP_ERROR_ICON . '" alt="action error" class="wpshopPageMessage_Icon" />' . __('You are not allowed to do this action', 'wpshop'); } } self::setMessage($pageMessage); }