function GetCSVFile() { // имя файла для сохранения $from_date = get('from_date', '', 'g'); $to_date = get('to_date', '', 'g'); $filename = $this->name . '_' . $from_date . ' - ' . $to_date . '.csv'; $data = $this->GetCSVData(); $GLOBALS['gzip'] = false; ob_end_clean(); $zip = new ss_zip('', 6); $zip->add_data($filename, $data); $zip->save($filename . ".zip", 'd'); exit; }
$size = convert_string($r['sizedesc']); $difficulty = sprintf('%01.1f', $r['difficulty'] / 2); $terrain = sprintf('%01.1f', $r['terrain'] / 2); $cacheid = convert_string($r['wp_oc']); $line = "{$name} by {$username}, {$type}, {$size}, {$cacheid}"; $record = pack("CLllA*x", 2, 1 + 4 + 4 + 4 + strlen($line) + 1, (int) $lon, (int) $lat, $line); append_output($record); } mysql_free_result($rs); if ($sqldebug == true) { sqldbg_end(); } // phpzip versenden if ($bUseZip == true) { $phpzip->add_data($sFilebasename . '.ov2', $content); echo $phpzip->save($sFilebasename . '.zip', 'b'); } exit; function convert_string($str) { $newstr = iconv("UTF-8", "ISO-8859-1", $str); if ($newstr == false) { return "--- charset error ---"; } else { return $newstr; } } function append_output($str) { global $content, $bUseZip, $sqldebug; if ($sqldebug == true) {
set_time_limit(3000); $fichier_liste="options_eleves_gepi_".suppr_accents(preg_replace("/'/","'",preg_replace('/[" ]/','',$projet)))."_".date("Ymd_Hi"); if(file_exists("../lib/ss_zip.class.php")){ //require_once("ss_zip.class.php"); require_once("../lib/ss_zip.class.php"); $zip= new ss_zip('',6); $zip->add_file("../temp/".$user_temp_directory."/content.xml",'content.xml'); $zip->add_file('liste_options_ods/meta.xml','meta.xml'); $zip->add_file('liste_options_ods/mimetype','mimetype'); $zip->add_file('liste_options_ods/settings.xml','settings.xml'); $zip->add_file('liste_options_ods/styles.xml','styles.xml'); $zip->add_file('liste_options_ods/META-INF/manifest.xml','META-INF/manifest.xml'); $zip->save("../temp/".$user_temp_directory."/$fichier_liste.zip"); rename("../temp/".$user_temp_directory."/$fichier_liste.zip","../temp/".$user_temp_directory."/".$fichier_liste.".ods"); } else { $path = path_niveau(); $chemin_temp = $path."temp/".get_user_temp_directory()."/"; if (!defined('PCLZIP_TEMPORARY_DIR') || constant('PCLZIP_TEMPORARY_DIR')!=$chemin_temp) { @define( 'PCLZIP_TEMPORARY_DIR', $chemin_temp); } $nom_fic=$fichier_liste.".ods"; $chemin_stockage = $chemin_temp."/".$nom_fic; $chemin_modele_ods='liste_options_ods';
function EditCSV() { $period = get('period', 'all'); $date_state = ""; if ($period != 'all') { $from = get('from_date', ''); $to = get('to_date', ''); if ($from && $to) { $from = explode('-', $from); $to = explode('-', $to); if (count($to) > 2 && count($from) > 2) { $from_date = mktime(0, 0, 0, $from[1], $from[2], $from[0]); $to_date = mktime(23, 59, 59, $to[1], $to[2], $to[0]); } } $date_state = " AND (o.order_date BETWEEN '" . $from_date . "' AND '" . $to_date . "')"; } $filename = $this->name . '_' . date('Y-m-d') . '.csv'; $data = $this->str('art') . ';' . $this->str('art2') . ';' . $this->str('name') . ';' . $this->str('manufacturer') . ';' . $this->str('catalog') . ';' . $this->str('order_id') . ';' . $this->str('order_date') . ';' . $this->str('quantity') . ';' . $this->str('price') . ';' . $this->str('customer_price') . "\n"; $client_id = get('client_id', NULL); if (isset($client_id)) { $rows = $this->getRows("SELECT p.art, p.art2, p.name, m.name as manufacturer, t.name as catalog, o.id as order_id, DATE_FORMAT(FROM_UNIXTIME(o.order_date),'%Y-%m-%d') as order_date, c.quantity, c.price, c.customer_price\n FROM orders AS o, cart AS c, elem_product AS ep\n LEFT JOIN products AS p ON c.product_id = p.id\n LEFT JOIN manufacturers AS m ON m.id = p.manufacturer_id\n LEFT JOIN tree AS t ON ep.pid = t.id\n LEFT JOIN auth_users AS c1 ON o.client_id=c1.id\n WHERE c.order_id=o.id AND ep.id=p.id AND o.status IN ('Delivered', 'ReadyPaid') " . $date_state . " AND o.client_id=" . $client_id . " ORDER BY o.order_date"); } else { $sql = "SELECT p.art, p.art2, p.name, m.name as manufacturer, t.name as catalog, o.id as order_id, DATE_FORMAT(FROM_UNIXTIME(o.order_date),'%Y-%m-%d') as order_date, c.quantity, c.price, c.customer_price\n FROM orders AS o, cart AS c, elem_product AS ep\n LEFT JOIN products AS p ON c.product_id = p.id\n LEFT JOIN manufacturers AS m ON m.id = p.manufacturer_id\n LEFT JOIN tree AS t ON ep.pid = t.id\n WHERE c.order_id = o.id AND ep.id=p.id AND o.status IN ('Delivered', 'ReadyPaid') " . $date_state . " ORDER BY o.order_date"; $rows = $this->getRows($sql); } if ($rows) { foreach ($rows as $i => $row) { $data .= $row['art'] . ';' . $row['art2'] . ';' . $row['name'] . ';' . $row['manufacturer'] . ';' . $row['catalog'] . ';' . $row['order_id'] . ';' . $row['order_date'] . ';' . $row['quantity'] . ';' . $row['price'] . ';' . $row['customer_price'] . "\n"; } } $zip = new ss_zip('', 6); $zip->add_data($filename, $data); $zip->save($filename . ".zip", 'd'); }
function download() { $config = $this->get_config(); if (!$config) { return "<SCRIPT>alert('" . $this->str('err_no_config') . "')</SCRIPT>"; } $rows = sql_query('SELECT ' . implode(',', $config['fields_request']) . ' FROM ' . $config['table_base']); if (!$rows) { return "<SCRIPT>alert(\"Error: " . mysql_error() . "\")</SCRIPT>"; } require 'modules/csv_tools/Bs_CsvUtil.class.php'; $Bs_CsvUtil =& new Bs_CsvUtil(); // первой строкой выдаем заголовки таблицы $data = $Bs_CsvUtil->arrayToCsvString($config['fields_request'], ';', 'none', TRUE) . "\n"; // теперь собственно данные построчно: while ($row = mysql_fetch_assoc($rows)) { $csv_row = $Bs_CsvUtil->arrayToCsvString($row, ';', $trim = 'none', TRUE); /* $comma = '';$csv_row = ''; foreach($row AS $val){ $csv_row .= $comma.'"'.$val.'"'; $comma = '; '; }*/ //добавляем возможность скачивания zip архива //(strtr($csv_row, array("\r" => '\r', "\n" => '\n'))."\n"); $data .= strtr($csv_row, array("\r" => '\\r', "\n" => '\\n')) . "\n"; } // new empty archive with compression level 6 $zip = new ss_zip('', 6); $zip->add_data($config['table_base'] . '.csv', $data); $zip->save('modules/csv_tools/' . $config['table_base'] . ".zip", 'd'); }
require_once "../lib/ss_zip.class.php"; $zip = new ss_zip('', 6); $zip->add_file("{$tmp_fich}", 'content.xml'); // On n'ajoute pas les dossiers, ni les fichiers vides... ss_zip ne le supporte pas... // ... et OpenOffice a l'air de supporter l'absence de ces dossiers/fichiers. $zip->add_file($chemin_modele_ods . '/Basic/script-lc.xml', 'Basic/script-lc.xml'); $zip->add_file($chemin_modele_ods . '/Basic/Standard/script-lb.xml', 'Basic/Standard/script-lb.xml'); $zip->add_file($chemin_modele_ods . '/Basic/Standard/Module1.xml', 'Basic/Standard/Module1.xml'); // On ne met pas ce fichier parce que sa longueur vide fait une blague pour ss_zip. $zip->add_file($chemin_modele_ods . '/META-INF/manifest.xml', 'META-INF/manifest.xml'); $zip->add_file($chemin_modele_ods . '/settings.xml', 'settings.xml'); $zip->add_file($chemin_modele_ods . '/meta.xml', 'meta.xml'); $zip->add_file($chemin_modele_ods . '/Thumbnails/thumbnail.png', 'Thumbnails/thumbnail.png'); $zip->add_file($chemin_modele_ods . '/mimetype', 'mimetype'); $zip->add_file($chemin_modele_ods . '/styles.xml', 'styles.xml'); $zip->save("{$tmp_fich}.zip"); if (file_exists("{$chemin_temp}/{$nom_fic}")) { unlink("{$chemin_temp}/{$nom_fic}"); } rename("{$tmp_fich}.zip", "{$chemin_temp}/{$nom_fic}"); // Suppression du fichier content...xml unlink($tmp_fich); } else { $path = path_niveau(); $chemin_temp = $path . "temp/" . get_user_temp_directory() . "/"; if (!defined('PCLZIP_TEMPORARY_DIR') || constant('PCLZIP_TEMPORARY_DIR') != $chemin_temp) { @define('PCLZIP_TEMPORARY_DIR', $chemin_temp); } $chemin_stockage = $chemin_temp . "/" . $nom_fic; $dossier_a_traiter = $chemin_temp . "export_cn_" . strftime("%Y%m%d%H%M%S"); @mkdir($dossier_a_traiter);
$zip->add_file($chemin_modele_ods.'/Basic/script-lc.xml', 'Basic/script-lc.xml'); $zip->add_file($chemin_modele_ods.'/Basic/Standard/script-lb.xml', 'Basic/Standard/script-lb.xml'); $zip->add_file($chemin_modele_ods.'/Basic/Standard/Export_CSV.xml', 'Basic/Standard/Export_CSV.xml'); // On ne met pas ce fichier parce que sa longueur vide fait une blague pour ss_zip. //$zip->add_file($chemin_modele_ods.'/Configurations2/accelerator/current.xml', 'Configurations2/accelerator/current.xml'); $zip->add_file($chemin_modele_ods.'/META-INF/manifest.xml', 'META-INF/manifest.xml'); $zip->add_file($chemin_modele_ods.'/settings.xml', 'settings.xml'); $zip->add_file($chemin_modele_ods.'/meta.xml', 'meta.xml'); //$zip->add_file($chemin_modele_ods.'/modele_ods/Thumbnails', 'Thumbnails'); $zip->add_file($chemin_modele_ods.'/Thumbnails/thumbnail.png', 'Thumbnails/thumbnail.png'); $zip->add_file($chemin_modele_ods.'/mimetype', 'mimetype'); $zip->add_file($chemin_modele_ods.'/styles.xml', 'styles.xml'); $zip->save("$tmp_fich.zip"); if(file_exists("$chemin_temp/$nom_fic")){unlink("$chemin_temp/$nom_fic");} //rename("$tmp_fich.zip","$chemin_modele_ods/$chaine_tmp.$nom_fic"); rename("$tmp_fich.zip","$chemin_temp/$nom_fic"); // Suppression du fichier content...xml unlink($tmp_fich); } else { $path = path_niveau(); $chemin_temp = $path."temp/".get_user_temp_directory()."/"; if (!defined('PCLZIP_TEMPORARY_DIR') || constant('PCLZIP_TEMPORARY_DIR')!=$chemin_temp) {
$thisline = str_replace('{difficulty}', $difficulty, $thisline); $terrain = sprintf('%01.1f', $r['terrain'] / 2); $thisline = str_replace('{terrain}', $terrain, $thisline); $time = date($kmlTimeFormat, strtotime($r['date_hidden'])); $thisline = str_replace('{{time}}', $time, $thisline); $thisline = str_replace('{username}', xmlentities(PlConvert("UTF-8", "POLSKAWY", $r['username'])), $thisline); $thisline = str_replace('{cacheid}', xmlentities($r['cacheid']), $thisline); echo $thisline; // ob_flush(); } echo $kmlFoot; // phpzip versenden if ($bUseZip == true) { $content = ob_get_clean(); $phpzip->add_data($sFilebasename . '.kml', $content); $out = $phpzip->save($sFilebasename . '.kmz', 'r'); header('Content-Type: application/vnd.google-earth.kmz; charset=utf8'); header('Content-Disposition: attachment; filename="' . $sFilebasename . '.kmz"'); header('Pragma: no-cache'); header('Cache-Control: no-store,no-cache,must-revalidate,post-check=0,pre-check=0,private'); // header('Content-Transfer-Encoding: binary'); echo $out; ob_end_flush(); } else { header('Content-Type: application/vnd.google-earth.kml; charset=utf8'); header('Content-Disposition: attachment; filename="' . $sFilebasename . '.kml"'); ob_end_flush(); } } exit; function xmlentities($str)