Esempio n. 1
0
 public function __construct($id_service, $filename = false)
 {
     $this->name = 'CSV';
     $this->extension = 'csv';
     parent::__construct($id_service, $filename);
     self::$_delimiter = trim(self::$_serviceData['delimiter']) == '' ? Configuration::get('EXPORTFREE_DELIMITER') : self::$_serviceData['delimiter'];
     self::$_enclosure = trim(self::$_serviceData['enclosure']) == '' ? Configuration::get('EXPORTFREE_ENCLOSURE') : self::$_serviceData['enclosure'];
     self::$_delimiter = ExportTools::delimiterByKeyWord(self::$_delimiter);
     self::$_enclosure = ExportTools::getEnclosureFromId(self::$_enclosure);
 }
Esempio n. 2
0
 public static function getCsvDefaults($serviceId)
 {
     $sql = '
     SELECT *
     FROM `' . _DB_PREFIX_ . 'moussiqfree_service`
     WHERE `id_moussiqfree_service` = ' . (int) $serviceId;
     if (!($result = Db::getInstance()->getRow($sql))) {
         return false;
     }
     $configuration = Configuration::getMultiple(array('EXPORTFREE_COUNTRY', 'EXPORTFREE_STATE', 'EXPORTFREE_CARRIER', 'EXPORTFREE_STORE', 'EXPORTFREE_SHOP', 'EXPORTFREE_GROUP', 'EXPORTFREE_DELIMITER', 'EXPORTFREE_HEADER', 'EXPORTFREE_INACTIVE', 'EXPORTFREE_LANGUAGE', 'EXPORTFREE_ENCLOSURE'));
     $data = $result;
     $data['id_country'] = (int) self::findCorrectDefault($result['id_country'], $configuration['EXPORTFREE_COUNTRY']);
     $data['id_state'] = (int) self::findCorrectDefault($result['id_state'], $configuration['EXPORTFREE_STATE']);
     $data['id_carrier'] = (int) self::findCorrectDefault($result['id_carrier'], $configuration['EXPORTFREE_CARRIER']);
     $data['id_store'] = (int) self::findCorrectDefault($result['id_store'], $configuration['EXPORTFREE_STORE']);
     $data['id_shop'] = (int) self::findCorrectDefault($result['id_shop'], $configuration['EXPORTFREE_SHOP']);
     $data['id_group'] = (int) self::findCorrectDefault($result['id_group'], $configuration['EXPORTFREE_GROUP']);
     $data['header'] = (int) self::findCorrectDefault($result['header'], $configuration['EXPORTFREE_HEADER']);
     $data['id_lang'] = (int) self::findCorrectDefault($result['id_lang'], $configuration['EXPORTFREE_LANGUAGE']);
     $data['export_inactive'] = self::findCorrectDefault($result['export_inactive'], $configuration['EXPORTFREE_INACTIVE'], true);
     $data['name'] = pSQL($result['name']);
     $data['template'] = ExportTools::jsonDecode(addcslashes(base64_decode($result['template']), "\\"));
     if (!Country::containsStates($data['id_country'])) {
         $data['id_state'] = false;
     }
     return $data;
 }
 public function exporterView($obj)
 {
     $fileName = sha1($obj->name . _COOKIE_KEY_) . '.csv';
     $fileDir = dirname(__FILE__) . '/export/';
     $fileLink = _PS_BASE_URL_ . _MODULE_DIR_ . $this->module . '/export/' . $fileName;
     $delimiter = isset($obj->delimiter) && strlen($obj->delimiter) > 0 ? $obj->delimiter : Configuration::get('EXPORTFREE_DELIMITER');
     $delimiter = ExportTools::delimiterByKeyWord($delimiter);
     $enclosure = isset($obj->enclosure) && strlen($obj->enclosure) > 0 ? $obj->enclosure : Configuration::get('EXPORTFREE_ENCLOSURE');
     $enclosure = ExportTools::getEnclosureFromId($enclosure);
     echo '
     <form method="post">
         <fieldset>
             <legend>
                 ' . $this->l('Service Info') . '
             </legend>
             
             <h2>' . $this->l('Link to CSV File:') . ' </h2>
             <div class="margin-form">';
     if (file_exists($fileDir . $fileName)) {
         echo '<h3><a style="color: blue;" href="' . $fileLink . '">' . $fileLink . '</a></h3>';
         $fileSize = floatval(filesize($fileDir . $fileName)) / pow(1024, 1);
         $fileModified = date("d/m/Y H:i:s", filemtime($fileDir . $fileName));
         echo '<h4>' . $this->l('Size:') . ' <b>' . number_format($fileSize, 2) . ' ' . $this->l('Kb') . '</b></h4>';
         echo '<h4>' . $this->l('Last Modified:') . ' <b>' . $fileModified . '</b></h4>';
     } else {
         echo '<h2>' . $this->l('CSV file have not been generated yet') . '</h2>';
     }
     echo '
             </div>';
     if (file_exists($fileDir . $fileName)) {
         $fileNotTooBig = $fileSize < 1024;
         echo '<h2>' . $this->l('CSV Contents') . '</h2>';
         echo '
         <div style="width: 900px; ' . ($fileNotTooBig ? 'height: 600px; overflow: auto; margin-bottom: 1em;' : '') . '">';
         if ($fileNotTooBig) {
             $index = 0;
             if (($handle = fopen($fileDir . $fileName, "r")) !== false) {
                 $header = intval($obj->header == '' ? Configuration::get('EXPORTFREE_HEADER') : $obj->header);
                 echo '<table class="table csvContents" cellspacing="0" cellpadding="0">';
                 while (($data = fgetcsv($handle, 1000, $delimiter, $enclosure)) !== false) {
                     echo '<tr' . ($index % 2 != 0 ? ' class="alt_row"' : '') . '>';
                     $num = count($data);
                     for ($c = 0; $c < $num; $c++) {
                         if ($index == 0 && $header === 1) {
                             echo '<th>' . $data[$c] . '</th>';
                         } else {
                             echo '<td>' . $data[$c] . '</td>';
                         }
                     }
                     echo '</tr>';
                     $index++;
                 }
                 fclose($handle);
                 echo '</table>';
             }
         } else {
             echo '<h3>' . $this->l('This file is too large to be displayed here, please use the link above to download it and view locally.') . '</h3>';
         }
         echo '
         </div>';
     }
     echo '
             <center><input type="submit" value="' . $this->l('Generate CSV') . '" name="csvGen" class="button" /></center>
         </fieldset>
     </form>';
 }