コード例 #1
0
 /**
  *	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);
 }
コード例 #2
0
function wps_update_products_prices()
{
    $action = wpshop_prices::mass_update_prices();
    $response = array('status' => $action[0], 'response' => $action[1]);
    echo json_encode($response);
    die;
}