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; }
$type = convert_string($r['typedesc']); $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;
} } } // *** run output module *** // // Modules will use these variables from search.php: // // $phpzip // $bUseZip $content = ''; search_output(); sql_drop_temp_table_slave('searchtmp'); // output zip file if ($bUseZip && !$db['debug']) { if ($add_to_zipfile) { $phpzip->add_data($sFilebasename . '.' . $output_module, $content); } echo $phpzip->save($sFilebasename . '.zip', 'r'); } } else { //=================================================================== // X8b. run other output module (XML, HTML) // // The following variables from search.php are used by output modules: // // $called_by_search // $called_by_profile_query // $distance_unit // $lat_rad, $lon_rad // $startat // $count
$thislog = mb_ereg_replace('{username}', $rLog['username'], $thislog); $logtype = $rLog['type']; $thislog = mb_ereg_replace('{type}', $logtype, $thislog); if ($rLog['text_html'] == 0) { $thislog = mb_ereg_replace('{text}', $rLog['text'], $thislog); } else { $thislog = mb_ereg_replace('{text}', html2txt($rLog['text']), $thislog); } $logentries .= $thislog . "\n"; } $thisline = mb_ereg_replace('{logs}', $logentries, $thisline); $thisline = lf2crlf($thisline); if ($rCount['count'] == 1 && $bUseZip == false) { echo $thisline; } else { $phpzip->add_data($r['waypoint'] . '.txt', $thisline); } } mysql_free_result($rs); if ($sqldebug == true) { sqldbg_end(); } // phpzip versenden if ($bUseZip == true) { echo $phpzip->save($sFilebasename . '.zip', 'b'); } exit; function html2txt($html) { $str = mb_ereg_replace("\r\n", '', $html); $str = mb_ereg_replace("\n", '', $str);
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'); }