/**
  * Log informations for setted type when post is saved
  */
 function content_logger($content)
 {
     remove_filter('content_save_pre', array(&$this, 'content_logger'));
     if (!empty($_POST) && !empty($_POST['post_type']) && !empty($this->wpeologs_settings['my_services']) && !empty($this->wpeologs_settings['my_services'][$_POST['post_type']]) && $this->wpeologs_settings['my_services'][$_POST['post_type']]['service_active']) {
         $previous_element = get_post($_POST['post_ID']);
         $previous_element_metas = get_post_meta($_POST['post_ID']);
         if (!empty($previous_element)) {
             wpeologs_ctr::log_datas_in_files($_POST['post_type'], array('object_id' => $_POST['post_ID'], 'previous_element' => $previous_element, 'previous_element_metas' => $previous_element_metas), $_POST['post_type'], WPEO_CRITICALITY_INFORMATIONS);
         }
     }
     return $content;
 }
 /**
  * OPTIONS -
  *
  * @param array $input
  *
  * @return array
  */
 function validate_options($settings)
 {
     if (is_array($settings)) {
         $module_option = get_option('wpshop_modules');
         $log_error = array();
         foreach ($settings as $module => $module_state) {
             if (!array_key_exists('activated', $module_state) && 'on' == $module_state['old_activated']) {
                 $module_option[$module]['activated'] = 'off';
                 $module_option[$module]['date_off'] = gmdate("Y-m-d H:i:s", time());
                 $module_option[$module]['author_off'] = get_current_user_id();
                 $settings[$module] = $module_option[$module];
                 /**	Log module activation	*/
                 $user = get_userdata($module_option[$folder]['author_on']);
                 $author = $user->display_name;
                 $log_error['message'] = sprintf(__('Activation made on %1$s by %2$s', 'eo-modmanager-i18n'), mysql2date(get_option('date_format') . ' ' . get_option('time_format'), $settings[$module]['date_on'], true), $author);
             } else {
                 if (array_key_exists('activated', $module_state) && 'off' == $module_state['old_activated']) {
                     $module_option[$module]['activated'] = 'on';
                     $module_option[$module]['date_on'] = gmdate("Y-m-d H:i:s", time());
                     $module_option[$module]['author_on'] = get_current_user_id();
                     $settings[$module] = $module_option[$module];
                     /**	Log module activation	*/
                     $user = get_userdata($module_option[$folder]['author_off']);
                     $author = $user->display_name;
                     $log_error['message'] = sprintf(__('Deactivation made on %1$s by %2$s', 'eo-modmanager-i18n'), mysql2date(get_option('date_format') . ' ' . get_option('time_format'), $settings[$module]['date_off'], true), $author);
                 } else {
                     $settings[$module] = $module_option[$module];
                 }
             }
             unset($settings[$module]['old_activated']);
             $log_error['object_id'] = $module;
         }
         wpeologs_ctr::log_datas_in_files('wps_addon', $log_error, 0);
     }
     return $settings;
 }
 /**
  * Récupère le taux de TVA du produit. Si il n'est pas trouvé retourne le taux 
  * par défaut. Si ces deux cas sont vides log et arrêtes le script. / Get the 
  * Product VAT rate. If it is not found return the default rate. If these 
  * two cases are empty, log and stop the script.
  * 
  * @param integer $product_id L'id du produit / The product ID
  * @return stdClass ( value, id ) L'id de l'attribut et le taux de TVA /
  * Attribute ID and the VAT rate
  */
 public static function get_rate_vat($product_id)
 {
     global $wpdb;
     /** 
      * Cette requête récupère la valeur du taux de TVA / This query retrieves 
      * the value of the VAT rate
      */
     $query = "\n\t\t\t\t\tSELECT ATTR_VAL_OPTIONS.value, ATTR_VAL_OPTIONS.id\n\t\t\t\t\tFROM " . WPSHOP_DBT_ATTRIBUTE . " as ATTR\n\t\t\t\t\t\tINNER JOIN " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " as ATTR_VAL_OPTIONS ON ATTR_VAL_OPTIONS.attribute_id = ATTR.id\n\t\t\t\t\t\tINNER JOIN " . WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER . " as ATTR_VAL_INT ON ( ATTR_VAL_INT.attribute_id = ATTR.id AND ATTR_VAL_OPTIONS.id=ATTR_VAL_INT.value )\t\t\t\t\t\t\n\t\t\t\t\tWHERE ATTR.code=%s AND ATTR_VAL_INT.entity_id=%d";
     $request = $wpdb->prepare($query, array('tx_tva', $product_id));
     $rate_vat = $wpdb->get_row($request);
     /** 
      * Vérifie ensuite si elle est vide, si elle est vide met la valeur par 
      * défaut / Then checks if it is empty , if empty the value put the 
      * default value
      */
     if (empty($rate_vat)) {
         wpeologs_ctr::log_datas_in_files('wps_product', array('object_id' => $product_id, 'message' => __('Use the default VAT rate', 'wpshop')), 0);
         $query = "\n\t\t\t\t\t\tSELECT ATTR_VAL_OPTIONS.value, ATTR_VAL_OPTIONS.id\n\t\t\t\t\t\tFROM " . WPSHOP_DBT_ATTRIBUTE . " as ATTR\n\t\t\t\t\t\t\tINNER JOIN " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " as ATTR_VAL_OPTIONS ON ATTR_VAL_OPTIONS.attribute_id = ATTR.id\n\t\t\t\t\t\tWHERE ATTR.code=%s AND ATTR_VAL_OPTIONS.id=ATTR.default_value";
         $request = $wpdb->prepare($query, array('tx_tva'));
         $rate_vat = $wpdb->get_row($request);
     }
     /**
      * Si c'est toujours vide, cela signifie qu'aucun taux de tva à été trouvé
      * dans ce cas la on utilise le log / If it is still empty , it means that no 
      * VAT rate found in this case the log is used
      */
     if (empty($rate_vat)) {
         wpeologs_ctr::log_datas_in_files('wps_product', array('object_id' => $product_id, 'message' => __('No VAT rate in the product and no default VAT rate found', 'wpshop')), 2);
     }
     return $rate_vat;
 }
 * Description: This plugins allows to log informations and display them later / Plugin de gestion de logs
 * Version: 1.0
 * Author: Eoxia dev team <*****@*****.**>
 * Author URI: http://www.eoxia.com/
 * License: GPL2
 */
/**
 * Bootstrap file for plugin. Do main includes and create new instance for plugin components
 *
 * @author Eoxia <*****@*****.**>
 * @version 1.0
 */
global $wpeologs;
if (!isset($wpeologs)) {
    DEFINE('WPEO_LOGS_VERSION', '1.0');
    DEFINE('WPEO_LOGS_DIR', basename(dirname(__FILE__)));
    DEFINE('WPEO_LOGS_PATH', dirname(__FILE__));
    DEFINE('WPEO_LOGS_URL', str_replace(str_replace("\\", "/", ABSPATH), site_url() . '/', str_replace("\\", "/", WPEO_LOGS_PATH)));
    /**	Load plugin translation	*/
    load_plugin_textdomain('wpeologs-i18n', false, dirname(plugin_basename(__FILE__)) . '/languages/');
    /**	Define the templates directories	*/
    DEFINE('WPEO_LOGS_TEMPLATES_MAIN_DIR', WPEO_LOGS_PATH . '/templates/');
    require_once WPEO_LOGS_PATH . '/controller/wpeologs_ctr.php';
    require_once WPEO_LOGS_PATH . '/controller/wpeologs_settings_ctr.php';
    require_once WPEO_LOGS_PATH . '/controller/wpeologs_display_log_ctr.php';
    $wpeologs = new wpeologs_ctr();
    $wpeologs->get_settings();
    $wpeologs_settings = new wpeologs_settings_ctr();
    new wpeologs_display_log_ctr();
    register_activation_hook(__FILE__, array($wpeologs, 'install_service'));
}
 private function wps_generate_barcode($array)
 {
     include_once 'wps_barcodegen.ctr.php';
     $code = '';
     $ref = '';
     $barcode = new wps_barcodegen();
     $conf = get_option('wps_barcode');
     if (array_key_exists('normal', $array)) {
         $code .= $array['normal']['country'];
         $code .= $array['normal']['enterprise'];
         $code .= $array['normal']['ID'];
         $id = $array['normal']['ID'];
     } else {
         if (array_key_exists('internal', $array)) {
             $code .= $array['internal']['type'];
             $code .= $array['internal']['date'];
             $code .= $array['internal']['ID'];
             $id = $array['internal']['ID'];
         }
     }
     $gencode = $barcode->checksum($code);
     $barcode->writeLog(sprintf(__("Checksum generate: %s from %s <br />", 'wps_barcode'), '<b>' . $gencode . '</b>', '<b>' . $code . '</b>'));
     $message = sprintf(__("Log generated by wps_barcodegen for add/update product: <br /> %s", 'wps_barcode'), $barcode->getLog());
     if (class_exists('wpeologs_ctr')) {
         wpeologs_ctr::log_datas_in_files('wps_barcode', array('object_id' => $id, 'message' => $message), 0);
     }
     return $gencode;
 }
 /**
  *	Save the different value for attribute of a given entity type and entity
  *
  *	@param array $attributeToSet The list of attribute with each value to set like this : ['integer']['tx_tva'] = 10
  *	@param integer $entityTypeId The entity type identifier (products/categories/...)
  *	@param integer $entityId The entity identifier we want to save attribute for (The specific product/category/...)
  *	@param string $language The language to set the value for into database
  *
  */
 public static function saveAttributeForEntity($attributeToSet, $entityTypeId, $entityId, $language = WPSHOP_CURRENT_LOCALE, $from = '')
 {
     global $wpdb;
     /* Recuperation de l'identifiant de l'utilisateur connecte */
     $user_id = function_exists('is_user_logged_in') && is_user_logged_in() ? get_current_user_id() : '0';
     $sent_attribute_list = array();
     if (!empty($attributeToSet)) {
         foreach ($attributeToSet as $attributeType => $attributeTypeDetails) {
             /** Preparation des parametres permettant de supprimer les bonnes valeurs des attributs suivant la configuration de la boutique et de la methode de mise a jour */
             $delete_current_attribute_values_params = array('entity_id' => $entityId, 'entity_type_id' => $entityTypeId);
             if (WPSHOP_ATTRIBUTE_VALUE_PER_USER) {
                 $delete_current_attribute_values_params['user_id'] = $user_id;
             }
             if (!empty($attributeTypeDetails) && is_array($attributeTypeDetails)) {
                 foreach ($attributeTypeDetails as $attribute_code => $attributeValue) {
                     if ($attributeType == 'decimal') {
                         $attributeValue = str_replace(',', '.', $attributeValue);
                     }
                     if ($attributeType == 'integer' && !is_array($attributeValue)) {
                         $attributeValue = (int) $attributeValue;
                     }
                     $more_query_params_values = array();
                     if ($attribute_code != 'unit') {
                         $unit_id = 0;
                         if (isset($attributeTypeDetails['unit'][$attribute_code])) {
                             $unit_id = $attributeTypeDetails['unit'][$attribute_code];
                         }
                         $currentAttribute = self::getElement($attribute_code, "'valid'", 'code');
                         if (!empty($currentAttribute)) {
                             $sent_attribute_list[] = $currentAttribute->id;
                             /*	Enregistrement de la valeur actuelle de l'attribut dans la table d'historique si l'option historique est activee sur l'attribut courant	*/
                             if ($currentAttribute->is_historisable == 'yes') {
                                 $query = $wpdb->prepare("SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . $attributeType . " WHERE entity_type_id = %d AND attribute_id = %d AND entity_id = %d", $entityTypeId, $currentAttribute->id, $entityId);
                                 $attribute_histo = $wpdb->get_results($query);
                                 if (!empty($attribute_histo)) {
                                     $attribute_histo_content['status'] = 'valid';
                                     $attribute_histo_content['creation_date'] = current_time('mysql', 0);
                                     $attribute_histo_content['creation_date_value'] = $attribute_histo[0]->creation_date_value;
                                     $attribute_histo_content['original_value_id'] = $attribute_histo[0]->value_id;
                                     $attribute_histo_content['entity_type_id'] = $attribute_histo[0]->entity_type_id;
                                     $attribute_histo_content['attribute_id'] = $attribute_histo[0]->attribute_id;
                                     $attribute_histo_content['entity_id'] = $attribute_histo[0]->entity_id;
                                     $attribute_histo_content['unit_id'] = $attribute_histo[0]->unit_id;
                                     $attribute_histo_content['language'] = $attribute_histo[0]->language;
                                     $attribute_histo_content['value'] = $attribute_histo[0]->value;
                                     $attribute_histo_content['value_type'] = WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . $attributeType;
                                     $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO, $attribute_histo_content);
                                 }
                             }
                             $attributeValue = str_replace("\\", "", $attributeValue);
                             if (empty($from) || !empty($attributeValue)) {
                                 $wpdb->delete(WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . $attributeType, array_merge($delete_current_attribute_values_params, array('attribute_id' => $currentAttribute->id)));
                                 /**	Insertion de la nouvelle valeur de l'attribut dans la base	*/
                                 $query_params = array('value_id' => '', 'entity_type_id' => $entityTypeId, 'attribute_id' => $currentAttribute->id, 'entity_id' => $entityId, 'unit_id' => $unit_id, 'language' => $language, 'user_id' => $user_id, 'creation_date_value' => current_time('mysql', 0));
                                 /**	Si l'attribut courant est contenu dans un tableau (exemple: select multiple) on lit tout le tableau et on enregistre chaque valeur separement	*/
                                 if (is_array($attributeValue)) {
                                     foreach ($attributeValue as $a) {
                                         $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . $attributeType, array_merge($query_params, array('value' => $a)));
                                     }
                                 } else {
                                     $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . $attributeType, array_merge($query_params, array('value' => $attributeValue)));
                                     wpeologs_ctr::log_datas_in_files('wpshop_attributes', array('object_id' => $entityId, 'message' => __('Add the attribute : ' . $currentAttribute->code . ' with value : ' . $attributeValue, 'wpshop')), 0);
                                 }
                                 /**	Dans le cas ou l'attribut courant est utilise dans l'interface permettant de trier les produits (option de l'attribut) on defini une meta specifique	*/
                                 if ($currentAttribute->is_used_for_sort_by == 'yes' || $currentAttribute->is_searchable == 'yes' || $currentAttribute->is_filterable == 'yes' && !empty($attributeValue)) {
                                     update_post_meta($entityId, '_' . $attribute_code, $attributeValue);
                                 }
                                 /**	Enregistrement de toutes les valeurs des attributs dans une meta du produit	*/
                                 if (!empty($_POST['attribute_option'][$attribute_code])) {
                                     $value = self::get_attribute_type_select_option_info($attributeTypeDetails[$attribute_code], 'value');
                                     if (strtolower($value) == 'yes') {
                                         update_post_meta($entityId, 'attribute_option_' . $attribute_code, $_POST['attribute_option'][$attribute_code]);
                                     } else {
                                         delete_post_meta($entityId, 'attribute_option_' . $attribute_code);
                                     }
                                 }
                             }
                         }
                     }
                 }
                 if (empty($from)) {
                     $query = $wpdb->prepare("SELECT value_id FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . $attributeType . " WHERE attribute_id NOT IN ('" . implode("', '", $sent_attribute_list) . "') AND entity_id = %d AND entity_type_id = %d", $entityId, $entityTypeId);
                     $attr_to_delete = $wpdb->get_results($query);
                     if (!empty($attr_to_delete)) {
                         foreach ($attr_to_delete as $value) {
                             $wpdb->delete(WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . $attributeType, array_merge($delete_current_attribute_values_params, array('value_id' => $value->value_id)));
                             wpeologs_ctr::log_datas_in_files('wpshop_attributes', array('object_id' => $entityId, 'message' => __('Remove the attribute : ' . $value->value_id, 'wpshop')), 0);
                         }
                     }
                 }
             }
         }
     }
 }