<?php
ini_set("max_execution_time", "3600"); // ожидаем
// // Игнорирует отключение пользователя и позволяет скрипту
// // быть запущенным постоянно
// ignore_user_abort(true);
// ini_set('error_reporting', E_ALL);
// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
//require "auth.php";
//Инклюдим файл подключения с базой данных
include_once($_SERVER["DOCUMENT_ROOT"].'/db.php');
$getsort = $_GET['sort'];
if ($getsort === 'desc'){
$sort = 'desc';
}else{
$sort = 'asc';
}
$getkey = $_GET['key'];
if (!empty($getkey)) {
$key = $getkey;
}else{
$key = 'id';
}
$q=$db->query('SELECT * FROM `news` WHERE `show_in_feed`=1 ORDER BY `'.$key.'` '.$sort.' ');
require('classes/PHPExcel.php');
// Подключаем класс для вывода данных в формате excel
require_once('classes/PHPExcel/Writer/Excel5.php');
// Создаем объект класса PHPExcel
$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp;
$cacheSettings = array( 'memoryCacheSize ' => '256MB');
PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);
$pExcel = new PHPExcel();
$pExcel->setActiveSheetIndex(0);
$aSheet = $pExcel->getActiveSheet();
$aSheet->setTitle('List');
//добавление данных
$aSheet->setCellValue("A1", "Added Date");
$aSheet->setCellValue("B1", "Title");
$aSheet->setCellValue("C1", "Threat Type");
$aSheet->setCellValue("D1", "Domain");
$aSheet->setCellValue("E1", "URL");
$rowCount = 2;
while($n=$q->fetch_assoc()){
$type_ed = explode(",", $n['threat_type']);
$type_edit = '';
foreach ($type_ed as $type_edd)
{
$ttt = $db->query("SELECT * FROM `type` WHERE `id`='".$type_edd."'")->fetch_assoc();
$name_type = $ttt['type'];
$type_edit.= "$name_type,";
}
$threat_type = substr($type_edit, 0, -1);
$aSheet->setCellValue("A".$rowCount, $n["added_date"]);
$aSheet->setCellValue("B".$rowCount, $n["title"]);
$aSheet->setCellValue("C".$rowCount, $threat_type);
$aSheet->setCellValue("D".$rowCount, $n["domain"]);
$aSheet->setCellValue("E".$rowCount, $n["full_url"]);
$rowCount++;
}
//форматирование
$style_wrap = array( 'font' => array( 'bold' => true ) );
$aSheet->getStyle('A1:V1')->applyFromArray($style_wrap);
//отдаем пользователю в браузер
// include("classes/PHPExcel/Writer/Excel2007.php");
// $objWriter = new PHPExcel_Writer_Excel2007($pExcel);
$objWriter = new PHPExcel_Writer_Excel5($pExcel);
ob_clean();
// header('Cache-Control: max-age=0');
header ( "Expires: Mon, 1 Apr 1974 05:00:00 GMT" );
header ( "Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT" );
header ( "Cache-Control: no-cache, must-revalidate" );
header ( "Pragma: no-cache" );
header ( "Content-type: application/vnd.ms-excel" );
header ( "Content-Disposition: attachment; filename=List.xls" );
$objWriter->save('php://output');
?>
type_ed = explode(",", $n['threat_type']);
$type_edit = '';
foreach ($type_ed as $type_edd)
{
$ttt = $db->query("SELECT * FROM `type` WHERE `id`='".$type_edd."'")->fetch_assoc();
$name_type = $ttt['type'];
$type_edit.= "$name_type,";
}
type_ed = explode(",", $n['threat_type']);
$type_edit = '';
foreach ($type_ed as $type_edd)
{
$ttt = $db->query("SELECT * FROM `type` WHERE `id`='".$type_edd."'")->fetch_assoc();
$name_type = $ttt['type'];
$type_edit.= "$name_type,";
}