Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if ( ! defined('DIAFAN'))
- {
- $path = __FILE__;
- while(! file_exists($path.'/includes/404.php'))
- {
- $parent = dirname($path);
- if($parent == $path) exit;
- $path = $parent;
- }
- include $path.'/includes/404.php';
- }
- /**
- * Shop_export
- */
- class Feedback_export extends Diafan
- {
- /**
- * @var array конфигурация текущего экспорта
- */
- private $config;
- /**
- * @var array название полей списка
- */
- private $select_values;
- /**
- * @var array поля, заданные для текущего экспорта
- */
- private $fields;
- /**
- * Инициирует экспорт
- *
- * @return void
- */
- public function init()
- {
- if(! $this->diafan->_users->roles("init", "shop/importexport", array(), 'admin'))
- {
- Custom::inc('includes/404.php');
- }
- if (empty($_GET["site_id"]))
- {
- Custom::inc('includes/404.php');
- }
- $feedback = DB::query_fetch_all("SELECT id FROM {feedback} WHERE site_id = %d AND trash='0'",(int)$_GET["site_id"]);
- $params = DB::query_fetch_all("SELECT id,[name],type FROM {feedback_param} WHERE site_id = 32 AND trash='0'",(int)$_GET["site_id"]);
- $text = '';
- $list = array();
- if(!empty($params))
- {
- foreach($params as $field)
- {
- $list[] = $field["name"];
- }
- $text .= $this->putcsv($list);
- $list = array();
- if (!empty($feedback))
- {
- foreach ($feedback as $key => $feed) {
- $list = array();
- foreach ($params as $param) {
- switch ($param["type"]) {
- case 'select':
- $value = DB::query_result("SELECT [name] FROM {feedback_param_select} WHERE id IN (SELECT value FROM {feedback_param_element} WHERE param_id=%d AND element_id=%d)",$param["id"],$feed["id"]);
- break;
- default:
- $value = DB::query_result("SELECT value FROM {feedback_param_element} WHERE param_id=%d AND element_id=%d",$param["id"],$feed["id"]);
- break;
- }
- $list[] = $value;
- }
- $text .= $this->putcsv($list);
- }
- }
- }
- $name = preg_replace('/[^a-z_ ]+/', '', str_replace(array(' ', '-'), '_', substr(strtolower($this->diafan->translit(TIT1)), 0, 50)));
- header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
- header('Cache-Control: max-age=86400');
- header("Content-type: text/plain");
- header("Content-Disposition: attachment; filename=shop_export_".$name.".csv");
- header('Content-transfer-encoding: binary');
- header("Connection: close");
- echo utf::to_windows1251($text);
- exit;
- }
- /**
- * Форматирует строку в виде CSV
- *
- * @param array $list исходные данные
- * @param strign $q символ ограничителя поля
- */
- private function putcsv($list, $q = '"')
- {
- $line = "";
- foreach ($list as $i => $field)
- {
- // remove any windows new lines,
- // as they interfere with the parsing at the other end
- $field = str_replace("\r\n", "\n", $field);
- // if a deliminator char, a double quote char or a newline
- // are in the field, add quotes
- if(preg_match("/[;"."$q\n\r]/", $field))
- {
- $field = $q.str_replace($q, $q.$q, $field).$q;
- }
- $line .= $field;
- if($i != count($list) - 1)
- {
- $line .= ';';
- }
- }
- $line .= "\n";
- return $line;
- }
- }
- $shop_export = new Feedback_export($this->diafan);
- $shop_export->init();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement