示例#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);
 }
 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>';
 }