Export in excel tickets y catogories

Helpdesk for my helpdesk software

Moderator: mkoch227

Post Reply
Juan Lema
Posts: 5
Joined: Fri Jun 07, 2013 1:33 pm

Export in excel tickets y catogories

Post by Juan Lema »

Script URL:
Version of script: 2.4.2
Hosting company:
URL of phpinfo.php:
URL of session_test.php:
What terms did you try when SEARCHING for a solution:

Write your message below:

hello, helps to export database tickets and the database categories in excel I added the option to export in repors.php and created export.php whet exporting, export 0 kb.

Code: Select all

<?php
define('IN_SCRIPT',1);
define('HESK_PATH','../');

/* Get all the required files and functions */
require(HESK_PATH . 'hesk_settings.inc.php');
require(HESK_PATH . 'inc/common.inc.php');
require(HESK_PATH . 'inc/database.inc.php');
   
   function echocsv($fields)
   {
      $separator = '';
      foreach ($fields as $field) {
         if (preg_match('/\\r|\\n|,|"/', $field)) {
            $field = '"' . str_replace('"', '""', $field) . '"';
         }
         $field = strip_tags($field);
         $field = iconv('utf-8','gbk',$field);
         echo $separator . $field;
         $separator = ',';
      }
      echo "\r\n";
   }
   
$export_type = $_GET['export_type'];
$date_from = $_GET['date_from'];
$date_to = $_GET['date_to'];
hesk_dbConnect();
switch ($export_type)
{
   case 2:
       export_articles();
        break;
        default:
       export_tickets();
      break;
}

function export_tickets()
{
   global $hesk_settings, $hesklang, $date_from, $date_to;

   $query = 'SELECT `a`.`id` AS `ID`, 
concat(CASE WHEN ISNULL(`f`.`name`) THEN "" ELSE concat(`f`.`name`,":") END,CASE WHEN ISNULL(`e`.`name`) THEN "" ELSE concat(`e`.`name`,":") END,CASE WHEN ISNULL(`d`.`name`) THEN "" ELSE concat(`d`.`name`,":") END,CASE WHEN ISNULL(`c`.`name`) THEN "" ELSE concat(`c`.`name`,":") END,CASE WHEN ISNULL(`b`.`name`) THEN "" ELSE `b`.`name` END) AS `Category`, `name` AS `author`,  `a`.`views` AS `views`, `t`.`name` AS `type``a`.`custom1` AS `Problemas con`, `a`.`custom2` AS `Estacion de Servicio `, `a`, `a`.`custom4` AS `Impacto.`, `a`.`custom5` AS `Urgencia`

    FROM hesk_tickets as a
   LEFT JOIN hesk_categories as b ON a.category = b.id
   LEFT JOIN hesk_users as u ON a.owner = u.id
   LEFT JOIN hesk_users as r ON a.replierid = r.id
   LEFT JOIN hesk_status as s ON a.status = s.id
   LEFT JOIN hesk_priority as p ON a. priority = p.id

    WHERE (DATE(`dt`) BETWEEN \'' . $date_from . '\' AND \'' . $date_to . '\'' .$hesk_settings . ') order by dt asc';
   
   $result = mysql_query($query);
   header('Content-Type: text/csv');
   header('Content-Disposition: attachment;filename=soporte_.csv');
   $row = mysql_fetch_assoc($result);
   if ($row) {
      echocsv(array_keys($row));
   }
   while ($row) {
      echocsv($row);
      $row = mysql_fetch_assoc($result);
   }
}

function export_articles()
{
   global $date_from, $date_to;
  $query = 'SELECT `hesk_tickets`.`id` AS "ID", 
`hesk_tickets`.`trackid` AS "TRAKID",
`hesk_tickets`.`name` AS "NAME",
`hesk_tickets`.`content` AS "Content",
`hesk_tickets`.`dt` AS "Date Created", 
`hesk_tickets`.`subject` AS "TITULO", 
`hesk_tickets`.`custom2` AS "Estacion de Servicio",
`hesk_users`.`name` AS "author"

FROM hesk_kb_articles, hesk_kb_categories, hesk_users, hesk_kb_type,hesk_pseries
WHERE ( (DATE(`dt`) BETWEEN \'' . $date_from . '\' AND \'' . $date_to . '\') 
and hesk_kb_categories.id = hesk_tickets.catid
AND hesk_users.id = hesk_tickets.author
AND hesk_kb_type.id = hesk_tickets.type
) order by id asc


    WHERE (DATE(`dt`) BETWEEN \'' . $date_from . '\' AND \'' . $date_to . '\')  order by id asc';
   
   $result = mysql_query($query);
   header('Content-Type: text/csv');
   header('Content-Disposition: attachment;filename=hesk_kb_articles.csv');
   $row = mysql_fetch_assoc($result);
   if ($row) {
      echocsv(array_keys($row));
   }
   while ($row) {
      echocsv($row);
      $row = mysql_fetch_assoc($result);
   }
}

?>
Klemen
Site Admin
Posts: 10162
Joined: Fri Feb 11, 2005 4:04 pm

Re: Export in excel tickets y catogories

Post by Klemen »

Thanks for sharing.

Actually, exporting tickets has been included in 2.5, which will be released this weekend (beta/test version at first).
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Post Reply