Location: PHPKode > projects > QuickTicket > quickticket/qti_find_csv.php
<?php

/**
* PHP versions 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to hide@address.com so we can mail you a copy immediately.
*
* @package    QuickTicket
* @author     Philippe Vandenberghe <hide@address.com>
* @copyright  2008-2012 The PHP Group
* @version    2.5.1 build:20110304
*/

session_start();
require_once('bin/qti_init.php');
if ( !$oVIP->CanView('V5') ) HtmlPage(11);

if ( !isset($_GET['a']) ) die('Missing parameter a');
$a = strip_tags($_GET['a']);

// INITIALISE

$strCSV = '';
$oVIP->selfname = $L['Search_result'];

include('qti_find_inc.php');

// Read report arguments

$size = strip_tags($_GET['size']);
$intCount = intval($_GET['n']);
$intLen = intval($_SESSION[QT]['topics_per_page']);

// Check report arguments

if ( empty($size) || $intCount <= $_SESSION[QT]['topics_per_page'] ) $size='all';
if ( strlen($size)>6 || strlen($size)<2 ) die('Invalid argument');
if ( substr($size,0,1)!='p' && substr($size,0,1)!='m' && $size!='all') die('Invalid argument');
if ( substr($size,0,1)=='p' )
{
  $i = intval(substr($size,1));
  if ( empty($i) ) die('Invalid argument');
  if ( ($i-1) > $intCount/$_SESSION[QT]['topics_per_page'] ) die('Invalid argument');
}
if ( substr($size,0,1)=='m' )
{
  if ( $size!='m1' && $size!='m2' && $size!='m5' && $size!='m10' ) die('Invalid argument');
}
if ( $intCount>1000 && $size=='all' ) die('Invalid argument');
if ( $intCount<=1000 && substr($size,0,1)=='m' ) die('Invalid argument');
if ( $intCount>1000 && substr($size,0,1)=='p' ) die('Invalid argument');

// Apply report argument (page)

if ( substr($size,0,1)=='p' ) $_GET['page'] = substr($size,1);

if ( isset($_GET['page']) ) $intLimit = (intval($_GET['page'])-1)*$intLen;

// apply argument

if ( $size=='all') { $intLimit=0; $intLen=$intCount; }
if ( $size=='m1' ) { $intLimit=0; $intLen=999; }
if ( $size=='m2' ) { $intLimit=1000; $intLen=1000; }
if ( $size=='m5' ) { $intLimit=0; $intLen=4999; }
if ( $size=='m10') { $intLimit=5000; $intLen=5000; }

// End

$oVIP->selfurl = 'qti_find.php';
$oVIP->exiturl = 'qti_search.php?'.QTargimplode(QTargexplode());
$oVIP->exitname = $L['Search'];

include('bin/qti_fn_sql.php');

// --------
// HTML START
// --------

$strFullOrder = 't.'.$strOrder.' '.$strDir; // first order
if ( $strOrder=='title' ) $strFullOrder = 'p.title'.' '.$strDir;
if ( $strOrder=='sectiontitle' ) $strFullOrder = 'f.title'.' '.$strDir;
if ( $strOrder!='lastpostdate' ) $strFullOrder .= ',t.lastpostdate DESC'; //second order
$oDB->Query( LimitSQL($strField.$strFrom.$strWhere,$strFullOrder,$intLimit,$intLen,$intCount) );

// ========
$arrFLD = array();
$oFLD = new cFLD('csvdate',$L['Date']); $arrFLD['csvdate']=$oFLD;
$oFLD = new cFLD('csvtime',$L['Time']); $arrFLD['csvtime']=$oFLD;
$oFLD = new cFLD('status','Status'); $arrFLD['status']=$oFLD;
if ( $bAddRef ) { $oFLD = new cFLD('numid',$L['Ref']); $arrFLD['numid']=$oFLD; }
$oFLD = new cFLD('smile','Ico'); $arrFLD['smile']=$oFLD;
$oFLD = new cFLD('title',$L['Topics']); $arrFLD['title']=$oFLD;
$oFLD = new cFLD('text','Text'); $arrFLD['text']=$oFLD;
$oFLD = new cFLD('sectiontitle',$L['Section']); $arrFLD['sectiontitle']=$oFLD;
$oFLD = new cFLD('firstpostname',$L['Author']); $arrFLD['firstpostname']=$oFLD;
$oFLD = new cFLD('lastpostdate',$L['Last_message']); $arrFLD['lastpostdate']=$oFLD;
if ( $a=='tst' && !empty($k3) )
{
$oFLD = new cFLD('tags',$L['Tags']); $arrFLD['tags']=$oFLD;
}
else
{
$oFLD = new cFLD('replies',$L['Replys']); $arrFLD['replies']=$oFLD;
}
$oFLD = new cFLD('uid','UID'); $arrFLD['uid']=$oFLD;
// ========
foreach($arrFLD as $strKey=>$oFLD) $strCSV .= ToCsv($oFLD->name);
$strCSV = substr($strCSV,0,-1)."\r\n";
// ========
$intWhile=0;
while($row=$oDB->Getrow())
{
  $str = implode('',TableRowFormat($arrFLD,$row,true,null,false,true));
  if ( substr($str,-1,1)==';' ) $str = substr($str,0,-1);
  $strCSV .= $str."\r\n";

  $intWhile++; 
  //odbcbreak
  if ( $intWhile>=$intCount ) break;  
}
// ========

// OUPUT

if ( isset($_GET['debug']) ) { echo $strCSV; exit; }

if ( !headers_sent() )
{
  header('Content-Type: text/csv; charset='.QTI_HTML_CHAR);
  header('Content-Disposition: attachment; filename="qti_'.date('YmdHi').'.csv"');
}
echo $strCSV;
Return current item: QuickTicket