Hi there,
I just thought i could share this, im not quite sure that it is a breakthrough but i've had some really hard time to find the info over the internet.
Anyways, i'm running osticket as logistics follow up support tool for clients and they really have been buggin' me out for a real time export button on their interface so i did this:
1) create a file in the osticket folder called "exportcsv.php"
<?php/* * PHP code to export MySQL data to CSV * http://salman-w.blogspot.com/2009/07/export-mysql-data-to-csv-using-php.html * * Sends the result of a MySQL query as a CSV file for download *//* * establish database connection */ include('client.inc.php'); //make sure u add thisif(!defined('OSTCLIENTINC') || !is_object($thisclient) || !$thisclient->isValid()) die('Kwaheri'); //... and this$conn = mysql_connect('localhost', 'dbuser', 'dbpass') or die(mysql_error());mysql_select_db('dbname', $conn) or die(mysql_error($conn));/* * execute sql query I totally copy/past this part from the tickets.inc.php, i've added the tables i needed tho' */$qwhere =' WHERE email='.db_input($thisclient->getEmail()); // STRICT TO THE USER$qfrom=' FROM '.TICKET_TABLE.' ticket LEFT JOIN '.DEPT_TABLE.' dept ON ticket.dept_id=dept.dept_id ';//Pagenation stuff....wish MYSQL could auto pagenate (something better than limit)$result=mysql_query('SELECT ticket.ticketID , ville , subject,name,email,status,ticket.created,paiement,numcmdmar,nomcli,closed'.$qfrom.' '.$qwhere);//$result1 = mysql_query($qselect,$qfrom,$qwhere, $conn) or die(mysql_error($conn));/* * send response headers to the browser * following headers instruct the browser to treat the data as a csv file called export.csv */header('Content-Type: text/csv');header('Content-Disposition: attachment;filename=export.csv');/* * output header row (if atleast one row exists) */$row = mysql_fetch_assoc($result);if ($row) { echocsv(array_keys($row));}/* * output data rows (if atleast one row exists) */while ($row) { echocsv($row); $row = mysql_fetch_assoc($result);}/* * echo the input array as csv data maintaining consistency with most CSV implementations * - uses double-quotes as enclosure when necessary * - uses double double-quotes to escape double-quotes * - uses CRLF as a line separator */function echocsv($fields){ $separator = ''; foreach ($fields as $field) { if (preg_match('/\\r|\\n|,|"/', $field)) { $field = '"' . str_replace('"', '""', $field) . '"'; } echo $separator . $field; $separator = ','; } echo "\r\n";}?>
Afterwards, all i needed is a button to trigger the download... easy
Open the header.inc.php and add this line next to Home.
Export CSV
And you're done.
Special shout outs to salman-w for his script.
Cheers all,
Mouad