From b0934f7c4c2df8bc3f863d638b55cbade95e3088 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Wed, 16 May 2018 18:55:16 -0400 Subject: [PATCH] Update export_functions --- admin/export.php | 340 ---------------- inc/export_functions.inc.php | 372 ++++++++++++++++++ ...nt_template.php => print_template.inc.php} | 0 3 files changed, 372 insertions(+), 340 deletions(-) create mode 100644 inc/export_functions.inc.php rename inc/{print_template.php => print_template.inc.php} (100%) diff --git a/admin/export.php b/admin/export.php index c4c1e699..ec67a22c 100644 --- a/admin/export.php +++ b/admin/export.php @@ -298,346 +298,6 @@ while ($row = hesk_dbFetchAssoc($res2)) { // Generate export file if (isset($_GET['w'])) { - /* - * // We'll need HH:MM:SS format for hesk_date() here - $hesk_settings['timeformat'] = 'H:i:s'; - - // Get staff names - $admins = array(); - $result = hesk_dbQuery("SELECT `id`,`name` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` ORDER BY `name` ASC"); - while ($row = hesk_dbFetchAssoc($result)) { - $admins[$row['id']] = $row['name']; - } - - // This will be the export directory - $export_dir = HESK_PATH.$hesk_settings['cache_dir'].'/'; - - // This will be the name of the export and the XML file - $export_name = 'hesk_export_' . date('Y-m-d_H-i-s') . '_' . mt_rand(10000, 99999); - $save_to = $export_dir . $export_name . '.xml'; - - // Do we have the export directory? - if (is_dir($export_dir) || (@mkdir($export_dir, 0777) && is_writable($export_dir))) { - // Is there an index.htm file? - if (!file_exists($export_dir.'index.htm')) { - @file_put_contents($export_dir.'index.htm', ''); - } - - // Cleanup old files - hesk_purge_cache('export', 86400); - } else { - hesk_error($hesklang['ede']); - } - - // Make sure the file can be saved and written to - @file_put_contents($save_to, ''); - if (!file_exists($save_to)) { - hesk_error($hesklang['eef']); - } - - // Start generating the report message and generating the export - $success_msg = ''; - $flush_me = '

'; - $flush_me .= hesk_date() . " | {$hesklang['inite']} "; - - if ($date_from == $date_to) { - $flush_me .= "(" . hesk_dateToString($date_from, 0) . ")
\n"; - } else { - $flush_me .= "(" . hesk_dateToString($date_from, 0) . " - " . hesk_dateToString($date_to, 0) . ")
\n"; - } - - // Start generating file contents - $tmp = ' - - - - - - - 8250 - 16275 - 360 - 90 - False - False - - - - - - - - - -'; - - // Define column width - $tmp .= ' - - - - - - - - - - - - - - '; - - foreach ($hesk_settings['custom_fields'] as $k => $v) { - if ($v['use']) { - $tmp .= '' . "\n"; - } - } - - // Define first row (header) - $tmp .= ' - - # - ' . $hesklang['trackID'] . ' - ' . $hesklang['date'] . ' - ' . $hesklang['last_update'] . ' - ' . $hesklang['name'] . ' - ' . $hesklang['email'] . ' - ' . $hesklang['category'] . ' - ' . $hesklang['priority'] . ' - ' . $hesklang['status'] . ' - ' . $hesklang['subject'] . ' - ' . $hesklang['message'] . ' - ' . $hesklang['owner'] . ' - ' . $hesklang['ts'] . ' - '; - - foreach ($hesk_settings['custom_fields'] as $k => $v) { - if ($v['use']) { - $tmp .= '' . $v['name'] . '' . "\n"; - } - } - - $tmp .= "\n"; - - // Write what we have by now into the XML file - file_put_contents($save_to, $tmp, FILE_APPEND); - $flush_me .= hesk_date() . " | {$hesklang['gXML']}
\n"; - - // OK, now start dumping data and writing it into the file - $tickets_exported = 0; - $save_after = 100; - $this_round = 0; - $tmp = ''; - - $result = hesk_dbQuery($sql); - while ($ticket = hesk_dbFetchAssoc($result)) { - $ticket['status'] = mfh_getDisplayTextForStatusId($ticket['status']); - - switch ($ticket['priority']) { - case 0: - $ticket['priority'] = $hesklang['critical']; - break; - case 1: - $ticket['priority'] = $hesklang['high']; - break; - case 2: - $ticket['priority'] = $hesklang['medium']; - break; - default: - $ticket['priority'] = $hesklang['low']; - } - - $ticket['archive'] = !($ticket['archive']) ? $hesklang['no'] : $hesklang['yes']; - $ticket['message'] = hesk_msgToPlain($ticket['message'], 1, 0); - $ticket['subject'] = hesk_msgToPlain($ticket['subject'], 1, 0); - $ticket['owner'] = isset($admins[$ticket['owner']]) ? $admins[$ticket['owner']] : ''; - $ticket['category'] = isset($my_cat[$ticket['category']]) ? $my_cat[$ticket['category']] : ''; - - // Format for export dates - $hesk_settings['timeformat'] = "Y-m-d\TH:i:s\.000"; - - // Create row for the XML file - $tmp .= ' - -' . $ticket['id'] . ' - -' . hesk_date($ticket['dt'], true) . ' -' . hesk_date($ticket['lastchange'], true) . ' - - - - - - - - - -'; - - // Add custom fields - foreach ($hesk_settings['custom_fields'] as $k=>$v) { - if ($v['use']) { - switch ($v['type']) { - case 'date': - $tmp_dt = hesk_custom_date_display_format($ticket[$k], 'Y-m-d\T00:00:00.000'); - $tmp .= strlen($tmp_dt) ? ''.$tmp_dt : ''; - $tmp .= " \n"; - break; - default: - $tmp .= ' ' . "\n"; - } - } - } - - $tmp .= "\n"; - - // Write every 100 rows into the file - if ($this_round >= $save_after) { - file_put_contents($save_to, $tmp, FILE_APPEND); - $this_round = 0; - $tmp = ''; - usleep(1); - } - - $tickets_exported++; - $this_round++; - } // End of while loop - - // Go back to the HH:MM:SS format for hesk_date() - $hesk_settings['timeformat'] = 'H:i:s'; - - // Append any remaining rows into the file - if ($this_round > 0) { - file_put_contents($save_to, $tmp, FILE_APPEND); - } - - // If any tickets were exported, continue, otherwise cleanup - if ($tickets_exported > 0) { - // Finish the XML file - $tmp = ' -
- - -
-