/**
  *	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
     break;
 case 'add_attribute_unit_group':
 case 'edit_attribute_unit_group':
     $atribute_unit_group = '';
     if ($action == 'edit_attribute_unit_group') {
         $atribute_unit_group = wpshop_tools::varSanitizer($_REQUEST['elementIdentifier']);
     }
     echo wpshop_attributes_unit::unit_group_edition($atribute_unit_group);
     break;
 case 'save_new_attribute_unit_group':
     $save_output = '';
     $attribute_unit_informations['id'] = '';
     $attribute_unit_informations['status'] = wpshop_tools::varSanitizer($_POST[WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP]['status']);
     $attribute_unit_informations['creation_date'] = date('Y-m-d H:i:s');
     $attribute_unit_informations['name'] = wpshop_tools::varSanitizer($_POST[WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP]['name']);
     $save_unit_result = wpshop_database::save($attribute_unit_informations, WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP);
     if ($save_unit_result == 'done') {
         $save_output = wpshop_attributes_unit::unit_group_list();
         $save_message = '<img class="wpshopPageMessage_Icon" alt="action successful" src="' . WPSHOP_SUCCES_ICON . '" />' . __('The new unit group has been saved succesfully', 'wpshop');
     } else {
         $save_output = wpshop_attributes_unit::unit_group_edition();
         $save_message = '<img class="wpshopPageMessage_Icon" alt="action error" src="' . WPSHOP_ERROR_ICON . '" />' . __('An error occured during new unit group saving', 'wpshop');
     }
     echo '<script type="text/javascript" >wpshop(document).ready(function(){setTimeout(function(){ wpshop("#wpshopMessage_unit").removeClass("wpshopPageMessage_Updated"); wpshop("#wpshopMessage_unit").html(""); }, 5000);});</script><div class="fade below-h2 wpshopPageMessage wpshopPageMessage_Updated" id="wpshopMessage_unit">' . $save_message . '</div>' . $save_output;
     break;
 case 'update_attribute_unit_group':
     $save_output = '';
     $attributeUnitId = wpshop_tools::varSanitizer($_POST[WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP]['id']);
     $attribute_unit_informations['status'] = wpshop_tools::varSanitizer($_POST[WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP]['status']);
     $attribute_unit_informations['last_update_date'] = date('Y-m-d H:i:s');
     $attribute_unit_informations['name'] = wpshop_tools::varSanitizer($_POST[WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP]['name']);
 /**
  *	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);
 }
 /**
  *	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);
 }