public function export($id_shop = null, $header_colums)
    {
        $o_netreviews = new NetReviews();
        $duree = Tools::getValue('duree');
        $order_statut_list = array_map('intval', Tools::getValue('orderstates'));
        $order_statut_list = !empty($order_statut_list) ? implode(',', $order_statut_list) : null;
        if (!empty($id_shop)) {
            $file_name = Configuration::get('AV_CSVFILENAME', null, null, $id_shop);
            $delay = Configuration::get('AV_DELAY', null, null, $id_shop) ? Configuration::get('AV_DELAY', null, null, $id_shop) : 0;
        } else {
            $file_name = Configuration::get('AV_CSVFILENAME');
            $delay = Configuration::get('AV_DELAY') ? Configuration::get('AV_DELAY') : 0;
        }
        $avis_produit = Tools::getValue('productreviews');
        if (!empty($file_name)) {
            $file_path = _PS_MODULE_DIR_ . 'netreviews/Export_NetReviews_' . str_replace('/', '', Tools::stripslashes($file_name));
            if (file_exists($file_path)) {
                if (is_writable($file_path)) {
                    unlink($file_path);
                } else {
                    throw new Exception($o_netreviews->l('Writing on our server is not allowed. Please assign write permissions to the folder netreviews'));
                }
            } else {
                foreach (glob(_PS_MODULE_DIR_ . 'netreviews/Export_NetReviews_*') as $filename_to_delete) {
                    if (is_writable($filename_to_delete)) {
                        unlink($filename_to_delete);
                    }
                }
            }
        }
        $file_name = date('d-m-Y') . '-' . Tools::substr(md5(rand(0, 10000)), 1, 10) . '.csv';
        $file_path = _PS_MODULE_DIR_ . 'netreviews/Export_NetReviews_' . $file_name;
        $duree_sql = '';
        switch ($duree) {
            case '1w':
                $duree_sql = 'INTERVAL 1 WEEK';
                break;
            case '2w':
                $duree_sql = 'INTERVAL 2 WEEK';
                break;
            case '1m':
                $duree_sql = 'INTERVAL 1 MONTH';
                break;
            case '2m':
                $duree_sql = 'INTERVAL 2 MONTH';
                break;
            case '3m':
                $duree_sql = 'INTERVAL 3 MONTH';
                break;
            case '4m':
                $duree_sql = 'INTERVAL 4 MONTH';
                break;
            case '5m':
                $duree_sql = 'INTERVAL 5 MONTH';
                break;
            case '6m':
                $duree_sql = 'INTERVAL 6 MONTH';
                break;
            case '7m':
                $duree_sql = 'INTERVAL 7 MONTH';
                break;
            case '8m':
                $duree_sql = 'INTERVAL 8 MONTH';
                break;
            case '9m':
                $duree_sql = 'INTERVAL 9 MONTH';
                break;
            case '10m':
                $duree_sql = 'INTERVAL 10 MONTH';
                break;
            case '11m':
                $duree_sql = 'INTERVAL 11 MONTH';
                break;
            case '12m':
                $duree_sql = 'INTERVAL 12 MONTH';
                break;
            default:
                $duree_sql = 'INTERVAL 1 WEEK';
                break;
        }
        $all_orders = array();
        // Get orders with choosen date interval
        $where_id_shop = !empty($id_shop) ? 'AND o.id_shop = ' . (int) $id_shop : '';
        $select_id_shop = !empty($id_shop) ? ', o.id_shop' : '';
        $where_id_state = !empty($order_statut_list) ? ' AND o.current_state IN (' . $order_statut_list . ')' : '';
        $select_id_state = !empty($order_statut_list) ? ', o.current_state' : '';
        $qry_sql = '	SELECT lg.iso_code, o.id_order, o.total_paid, o.id_customer, o.date_add, c.firstname, c.lastname, c.email ' . $select_id_shop . $select_id_state . '
						FROM ' . _DB_PREFIX_ . 'orders o
						LEFT JOIN ' . _DB_PREFIX_ . 'customer c ON o.id_customer = c.id_customer
						LEFT JOIN ' . _DB_PREFIX_ . 'lang lg ON o.id_lang = lg.id_lang
						WHERE (TO_DAYS(DATE_ADD(o.date_add,' . $duree_sql . ')) - TO_DAYS(NOW())) >= 0
						' . $where_id_shop . $where_id_state;
        $item_list = Db::getInstance()->ExecuteS($qry_sql);
        foreach ($item_list as $item) {
            $all_orders[$item['id_order']] = array('ID_ORDER' => $item['id_order'], 'MONTANT_COMMANDE' => $item['total_paid'], 'DATE_ORDER' => date('d/m/Y', strtotime($item['date_add'])), 'ID_CUSTOMER' => array('ID_CUSTOMER' => $item['id_customer'], 'FIRST_NAME' => $item['firstname'], 'LAST_NAME' => $item['lastname'], 'EMAIL' => $item['email']), 'EMAIL_CLIENT' => '', 'NOM_CLIENT' => '', 'ORDER_STATE' => $item['current_state'], 'ISO_LANG' => $item['iso_code'], 'PRODUCTS' => array());
            $qry_sql = 'SELECT id_order, product_id, product_name FROM ' . _DB_PREFIX_ . 'order_detail WHERE id_order = ' . (int) $item['id_order'];
            $product_list = Db::getInstance()->ExecuteS($qry_sql);
            foreach ($product_list as $product) {
                $array_url = NetReviewsModel::getUrlsProduct($product['product_id']);
                $all_orders[$product['id_order']]['PRODUCTS'][] = array('ID_PRODUCT' => $product['product_id'], 'NOM_PRODUCT' => $product['product_name'], 'URL_PRODUCT' => $array_url['url_product'], 'URL_IMAGE_PRODUCT' => $array_url['url_image_product']);
            }
        }
        if (count($all_orders) > 0) {
            if ($csv = @fopen($file_path, 'w')) {
                fwrite($csv, $header_colums);
                foreach ($all_orders as $order) {
                    $count_products = count($order['PRODUCTS']);
                    if ($avis_produit == 1 && $count_products > 0) {
                        for ($i = 0; $i < $count_products; $i++) {
                            $line = '';
                            //reset the line
                            $line[] = $order['ID_ORDER'];
                            $line[] = $order['MONTANT_COMMANDE'];
                            $line[] = $order['ID_CUSTOMER']['EMAIL'];
                            $line[] = utf8_decode($order['ID_CUSTOMER']['LAST_NAME']);
                            $line[] = utf8_decode($order['ID_CUSTOMER']['FIRST_NAME']);
                            $line[] = $order['DATE_ORDER'];
                            $line[] = $delay;
                            $line[] = $order['PRODUCTS'][$i]['ID_PRODUCT'];
                            $line[] = '';
                            // Categorie du produit
                            $line[] = utf8_decode($order['PRODUCTS'][$i]['NOM_PRODUCT']);
                            $line[] = utf8_decode($order['PRODUCTS'][$i]['URL_PRODUCT']);
                            //Url fiche product
                            $line[] = utf8_decode($order['PRODUCTS'][$i]['URL_IMAGE_PRODUCT']);
                            //Url image fiche product
                            $line[] = $order['ORDER_STATE'];
                            //Etat de la commande
                            $line[] = $order['ISO_LANG'];
                            //Order lang
                            if (!empty($id_shop)) {
                                $line[] = $id_shop;
                            }
                            fwrite($csv, self::generateCsvLine($line));
                        }
                    } else {
                        $line = '';
                        //reset the line
                        $line[] = $order['ID_ORDER'];
                        $line[] = $order['ID_CUSTOMER']['EMAIL'];
                        $line[] = utf8_decode($order['ID_CUSTOMER']['LAST_NAME']);
                        $line[] = utf8_decode($order['ID_CUSTOMER']['FIRST_NAME']);
                        $line[] = $order['DATE_ORDER'];
                        $line[] = $delay;
                        $line[] = '';
                        $line[] = '';
                        // Product category
                        $line[] = '';
                        $line[] = '';
                        // URL
                        $line[] = '';
                        //Url image fiche product
                        $line[] = $order['ORDER_STATE'];
                        //Order state
                        $line[] = $order['ISO_LANG'];
                        //Order lang
                        if (!empty($id_shop)) {
                            $line[] = $id_shop;
                        }
                        fwrite($csv, self::generateCsvLine($line));
                    }
                }
                fclose($csv);
                if (file_exists($file_path)) {
                    Configuration::updateValue('AV_CSVFILENAME', $file_name);
                    return array($file_name, count($all_orders), $file_path);
                } else {
                    throw new Exception($o_netreviews->l('Unable to read/write export file'));
                }
            } else {
                throw new Exception($o_netreviews->l('Unable to read/write export file'));
            }
        } else {
            throw new Exception($o_netreviews->l('No order to export'));
        }
    }
예제 #2
0
/**
 * Return day count orders
 *
 * @param $post_data : sent parameters
 * @return array with info data
 */
function getCountOrder(&$post_data)
{
    $reponse = array();
    $post_message = Tools::jsonDecode(NetReviewsModel::acDecodeBase64($post_data['message']), true);
    $sql_id_shop = '';
    $sql_iso_lang = '';
    $ids_lang = array();
    if (!empty($post_message['id_shop'])) {
        if (Configuration::get('AV_MULTILINGUE', null, null, $post_message['id_shop']) == 'checked') {
            $sql_id_shop .= ' and id_shop = ' . (int) $post_message['id_shop'];
            $sql = 'SELECT name
                    FROM ' . _DB_PREFIX_ . "configuration\n                    where value = '" . pSQL($post_message['idWebsite']) . "'\n                    and name like 'AV_IDWEBSITE_%'\n                    and id_shop = " . (int) $post_message['id_shop'];
            if ($row = Db::getInstance()->getRow($sql)) {
                $group_name = '_' . Tools::substr($row['name'], 13);
            }
            $av_group_conf = unserialize(Configuration::get('AV_GROUP_CONF' . $group_name, null, null, $post_message['id_shop']));
            $o_lang = new Language();
            foreach ($av_group_conf as $isolang) {
                $ids_lang[] = $o_lang->getIdByIso(Tools::strtolower($isolang));
            }
            $sql_iso_lang .= ' and id_lang in ("' . implode('","', $ids_lang) . '")';
        } else {
            $sql_id_shop .= ' and id_shop = ' . (int) $post_message['id_shop'];
        }
    } else {
        if (Configuration::get('AV_MULTILINGUE') == 'checked') {
            $sql = 'SELECT name
                    FROM ' . _DB_PREFIX_ . "configuration\n                    where value = '" . pSQL($post_message['idWebsite']) . "'\n                    and name like 'AV_IDWEBSITE_%'\n                    and id_shop is null ";
            if ($row = Db::getInstance()->getRow($sql)) {
                $group_name = '_' . Tools::substr($row['name'], 13);
            }
            $av_group_conf = unserialize(Configuration::get('AV_GROUP_CONF' . $group_name));
            $o_lang = new Language();
            foreach ($av_group_conf as $isolang) {
                $ids_lang[] = $o_lang->getIdByIso(Tools::strtolower($isolang));
            }
            $sql_iso_lang .= ' and id_lang in ("' . implode('","', $ids_lang) . '")';
        }
    }
    $sql = 'SELECT COUNT( * )
            FROM ' . _DB_PREFIX_ . 'orders
            WHERE (
            date_add
            BETWEEN DATE_SUB( NOW( ) , INTERVAL 1 DAY )
            AND NOW( )
            )' . $sql_iso_lang . $sql_id_shop;
    $reponse['message']['count_orders_day'] = Db::getInstance()->getValue($sql);
    $reponse['return'] = 1;
    if (!empty($post_message['id_shop'])) {
        if (Configuration::get('AV_MULTILINGUE', null, null, $post_message['id_shop']) == 'checked') {
            $sql = 'SELECT name
                    FROM ' . _DB_PREFIX_ . "configuration\n                    where value = '" . pSQL($post_message['idWebsite']) . "'\n                    and name like 'AV_IDWEBSITE_%'\n                    and id_shop = " . (int) $post_message['id_shop'];
            if ($row = Db::getInstance()->getRow($sql)) {
                $group_name = '_' . Tools::substr($row['name'], 13);
            }
            $reponse['sign'] = SHA1($post_message['query'] . Configuration::get('AV_IDWEBSITE' . $group_name, null, null, $post_message['id_shop']) . Configuration::get('AV_CLESECRETE' . $group_name, null, null, $post_message['id_shop']));
        } else {
            $reponse['sign'] = SHA1($post_data['query'] . Configuration::get('AV_IDWEBSITE', null, null, $post_message['id_shop']) . Configuration::get('AV_CLESECRETE', null, null, $post_message['id_shop']));
        }
    } else {
        if (Configuration::get('AV_MULTILINGUE') == 'checked') {
            $sql = 'SELECT name
                    FROM ' . _DB_PREFIX_ . "configuration\n                    where value = '" . pSQL($post_message['idWebsite']) . "'\n                    and name like 'AV_IDWEBSITE_%'\n                    and id_shop is null ";
            if ($row = Db::getInstance()->getRow($sql)) {
                $group_name = '_' . Tools::substr($row['name'], 13);
            }
            $reponse['sign'] = SHA1($post_data['query'] . Configuration::get('AV_IDWEBSITE' . $group_name) . Configuration::get('AV_CLESECRETE' . $group_name));
        } else {
            $reponse['sign'] = SHA1($post_data['query'] . Configuration::get('AV_IDWEBSITE') . Configuration::get('AV_CLESECRETE'));
        }
    }
    return $reponse;
}
예제 #3
0
 public function hookExtraRight()
 {
     if (Configuration::get('AV_MULTILINGUE') == 'checked') {
         $this->id_lang = $this->context->language->id;
         $this->iso_lang = pSQL(Language::getIsoById($this->id_lang));
         $this->group_name = $this->getIdConfigurationGroup($this->iso_lang);
     }
     if (version_compare(_PS_VERSION_, '1.5', '<')) {
         $display_prod_reviews = configuration::get('AV_DISPLAYPRODREVIEWS' . $this->group_name);
     } else {
         $display_prod_reviews = configuration::get('AV_DISPLAYPRODREVIEWS' . $this->group_name, null, null, $this->context->shop->getContextShopID());
     }
     $id_product = (int) Tools::getValue('id_product');
     $o = new NetReviewsModel();
     $reviews = $o->getStatsProduct($id_product, $this->group_name, $this->context->shop->getContextShopID());
     if ($reviews['nb_reviews'] < 1 || $display_prod_reviews != 'yes') {
         return '';
     }
     //Si Aucun avis, on retourne vide
     $percent = round($reviews['rate']) * 20;
     $this->context->smarty->assign(array('av_nb_reviews' => $reviews['nb_reviews'], 'av_rate' => $reviews['rate'], 'av_rate_percent' => $percent ? $percent : 100));
     if (Configuration::get('AV_LIGHTWIDGET') == 'checked') {
         $tpl = 'avisverifies-extraright-light.tpl';
     } else {
         $tpl = 'avisverifies-extraright.tpl';
     }
     if (version_compare(_PS_VERSION_, '1.5', '<')) {
         return $this->display(__FILE__, "/views/templates/hook/{$tpl}");
     } else {
         return $this->display(__FILE__, $tpl);
     }
 }
예제 #4
0
*  International Registered Trademark & Property of NetReviews SAS
*/
require dirname(__FILE__) . '/../../config/config.inc.php';
include dirname(__FILE__) . '/../../init.php';
require_once dirname(__FILE__) . '/models/NetReviewsModel.php';
$nom_group = null;
$id_shop = null;
/*
# Ajax file to pagination enfine
# This file contains the same code as hook productTabContent but use a template dedicated to the ajax data loaded
*/
$id_product = Tools::getValue('id_product');
if (empty($id_product)) {
    exit;
}
$o_av = new NetReviewsModel();
$nb_comments = (int) Tools::getValue('count_reviews');
$nom_group = Tools::getValue('nom_group');
$id_shop = (int) Tools::getValue('id_shop');
$p = abs((int) Tools::getValue('p', 1));
$range = 2;
if ($p > $nb_comments / $o_av->reviews_by_page + 1) {
    Tools::redirect(preg_replace('/[&?]p=\\d+/', '', $_SERVER['REQUEST_URI']));
}
$pages_nb = ceil($nb_comments / (int) $o_av->reviews_by_page);
$start = (int) $p - $range;
if ($start < 1) {
    $start = 1;
}
$stop = (int) $p + $range;
if ($stop > $pages_nb) {
예제 #5
0
 public function exportApi($duree, $statut)
 {
     $o_netreviews = new NetReviews();
     $order_statut_list = array_map('intval', $statut);
     $order_statut_list = !empty($order_statut_list) ? implode(',', $order_statut_list) : null;
     $duree_sql = '';
     switch ($duree) {
         case '1w':
             $duree_sql = 'INTERVAL 1 WEEK';
             break;
         case '2w':
             $duree_sql = 'INTERVAL 2 WEEK';
             break;
         case '1m':
             $duree_sql = 'INTERVAL 1 MONTH';
             break;
         case '2m':
             $duree_sql = 'INTERVAL 2 MONTH';
             break;
         case '3m':
             $duree_sql = 'INTERVAL 3 MONTH';
             break;
         case '4m':
             $duree_sql = 'INTERVAL 4 MONTH';
             break;
         case '5m':
             $duree_sql = 'INTERVAL 5 MONTH';
             break;
         case '6m':
             $duree_sql = 'INTERVAL 6 MONTH';
             break;
         case '7m':
             $duree_sql = 'INTERVAL 7 MONTH';
             break;
         case '8m':
             $duree_sql = 'INTERVAL 8 MONTH';
             break;
         case '9m':
             $duree_sql = 'INTERVAL 9 MONTH';
             break;
         case '10m':
             $duree_sql = 'INTERVAL 10 MONTH';
             break;
         case '11m':
             $duree_sql = 'INTERVAL 11 MONTH';
             break;
         case '12m':
             $duree_sql = 'INTERVAL 12 MONTH';
             break;
         default:
             $duree_sql = 'INTERVAL 1 WEEK';
             break;
     }
     $all_orders = array();
     // Get orders with choosen date interval
     $where_id_state = !empty($order_statut_list) ? ' AND o.current_state IN (' . $order_statut_list . ')' : '';
     $select_id_state = !empty($order_statut_list) ? ', o.current_state' : '';
     $qry_sql = '    SELECT lg.iso_code, o.id_order, o.total_paid, o.id_customer, o.date_add, c.firstname, c.lastname, c.email ' . $select_id_state . '
                     FROM ' . _DB_PREFIX_ . 'orders o
                     LEFT JOIN ' . _DB_PREFIX_ . 'customer c ON o.id_customer = c.id_customer
                     LEFT JOIN ' . _DB_PREFIX_ . 'lang lg ON o.id_lang = lg.id_lang
                     WHERE (TO_DAYS(DATE_ADD(o.date_add,' . $duree_sql . ')) - TO_DAYS(NOW())) >= 0 ' . $where_id_state;
     $item_list = Db::getInstance()->ExecuteS($qry_sql);
     foreach ($item_list as $item) {
         $all_orders[$item['id_order']] = array('ID_ORDER' => $item['id_order'], 'MONTANT_COMMANDE' => $item['total_paid'], 'DATE_ORDER' => date('d/m/Y', strtotime($item['date_add'])), 'ID_CUSTOMER' => array('ID_CUSTOMER' => $item['id_customer'], 'FIRST_NAME' => $item['firstname'], 'LAST_NAME' => $item['lastname'], 'EMAIL' => $item['email']), 'EMAIL_CLIENT' => '', 'NOM_CLIENT' => '', 'ORDER_STATE' => $item['current_state'], 'ISO_LANG' => $item['iso_code'], 'PRODUCTS' => array());
         $qry_sql = 'SELECT id_order, product_id, product_name FROM ' . _DB_PREFIX_ . 'order_detail WHERE id_order = ' . (int) $item['id_order'];
         $product_list = Db::getInstance()->ExecuteS($qry_sql);
         foreach ($product_list as $product) {
             $array_url = NetReviewsModel::getUrlsProduct($product['product_id']);
             $all_orders[$product['id_order']]['PRODUCTS'][] = array('ID_PRODUCT' => $product['product_id'], 'NOM_PRODUCT' => $product['product_name'], 'URL_PRODUCT' => $array_url['url_product'], 'URL_IMAGE_PRODUCT' => $array_url['url_image_product']);
         }
     }
     if (count($all_orders) > 0) {
         return $all_orders;
     }
 }