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 = '
-
-
-
-
-
-
-
-
-
-
- 3
- 4
-
-
- False
- False
-
-
-
-
-
-
-
-
-
-
- False
- False
-
-
-
-
-
-
-
-
-
-
- False
- False
-
-
-
-';
- file_put_contents($save_to, $tmp, FILE_APPEND);
-
- // Log how many rows we exported
- $flush_me .= hesk_date() . " | " . sprintf($hesklang['nrow'], $tickets_exported) . "
\n";
-
- // We will convert XML to Zip to save a lot of space
- $save_to_zip = $export_dir . $export_name . '.zip';
-
- // Log start of Zip creation
- $flush_me .= hesk_date() . " | {$hesklang['cZIP']}
\n";
-
- // Preferrably use the zip extension
- if (extension_loaded('zip')) {
- $save_to_zip = $export_dir . $export_name . '.zip';
-
- $zip = new ZipArchive;
- $res = $zip->open($save_to_zip, ZipArchive::CREATE);
- if ($res === TRUE) {
- $zip->addFile($save_to, "{$export_name}.xml");
- $zip->close();
- } else {
- die("{$hesklang['eZIP']} <$save_to_zip>\n");
- }
-
- } // Some servers have ZipArchive class enabled anyway - can we use it?
- elseif (class_exists('ZipArchive')) {
- require(HESK_PATH . 'inc/zip/Zip.php');
- $zip = new Zip();
- $zip->addLargeFile($save_to, "{$export_name}.xml");
- $zip->finalize();
- $zip->setZipFile($save_to_zip);
- } // If not available, use a 3rd party Zip class included with HESK
- else {
- require(HESK_PATH . 'inc/zip/pclzip.lib.php');
- $zip = new PclZip($save_to_zip);
- $zip->add($save_to, PCLZIP_OPT_REMOVE_ALL_PATH);
- }
-
- // Delete XML, just leave the Zip archive
- hesk_unlink($save_to);
-
- // Echo memory peak usage
- $flush_me .= hesk_date() . " | " . sprintf($hesklang['pmem'], (@memory_get_peak_usage(true) / 1048576)) . "
\r\n";
-
- // We're done!
- $flush_me .= hesk_date() . " | {$hesklang['fZIP']}
";
-
- // Success message
- $success_msg .= $hesk_settings['debug_mode'] ? $flush_me : '
';
- $success_msg .= $hesklang['step1'] . ': ' . $hesklang['ch2d'] . '
' . $hesklang['step2'] . ': ' . $hesklang['dffs'] . '';
- } // No tickets exported, cleanup
- else {
- hesk_unlink($save_to);
- }
- */
-
require_once(HESK_PATH . 'inc/export_functions.inc.php');
list($success_msg, $tickets_exported) = hesk_export_to_XML($sql);
}
diff --git a/inc/export_functions.inc.php b/inc/export_functions.inc.php
new file mode 100644
index 00000000..9021d0b6
--- /dev/null
+++ b/inc/export_functions.inc.php
@@ -0,0 +1,372 @@
+
';
+ $flush_me .= hesk_date() . " | {$hesklang['inite']} ";
+
+ // Is this export of a date or date range?
+ if ($export_selected === false)
+ {
+ global $date_from, $date_to;
+
+ if ($date_from == $date_to)
+ {
+ $flush_me .= "(" . hesk_dateToString($date_from,0) . ")";
+ }
+ else
+ {
+ $flush_me .= "(" . hesk_dateToString($date_from,0) . " - " . hesk_dateToString($date_to,0) . ")";
+ }
+ }
+
+ // 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 = '
+
+
+
+
+
+
+
+
+
+
+ 3
+ 4
+
+
+ False
+ False
+
+
+
+
+
+
+
+
+
+
+ False
+ False
+
+
+
+
+
+
+
+
+
+
+ False
+ False
+
+
+
+';
+ file_put_contents($save_to, $tmp, FILE_APPEND);
+
+ // Log how many rows we exported
+ $flush_me .= hesk_date() . " | " . sprintf($hesklang['nrow'], $tickets_exported) . "
\n";
+
+ // We will convert XML to Zip to save a lot of space
+ $save_to_zip = $export_dir . $export_name . '.zip';
+
+ // Log start of Zip creation
+ $flush_me .= hesk_date() . " | {$hesklang['cZIP']}
\n";
+
+ // Preferrably use the zip extension
+ if (extension_loaded('zip')) {
+ $save_to_zip = $export_dir . $export_name . '.zip';
+
+ $zip = new ZipArchive;
+ $res = $zip->open($save_to_zip, ZipArchive::CREATE);
+ if ($res === TRUE) {
+ $zip->addFile($save_to, "{$export_name}.xml");
+ $zip->close();
+ } else {
+ die("{$hesklang['eZIP']} <$save_to_zip>\n");
+ }
+
+ } // Some servers have ZipArchive class enabled anyway - can we use it?
+ elseif (class_exists('ZipArchive')) {
+ require(HESK_PATH . 'inc/zip/Zip.php');
+ $zip = new Zip();
+ $zip->addLargeFile($save_to, "{$export_name}.xml");
+ $zip->finalize();
+ $zip->setZipFile($save_to_zip);
+ } // If not available, use a 3rd party Zip class included with HESK
+ else {
+ require(HESK_PATH . 'inc/zip/pclzip.lib.php');
+ $zip = new PclZip($save_to_zip);
+ $zip->add($save_to, PCLZIP_OPT_REMOVE_ALL_PATH);
+ }
+
+ // Delete XML, just leave the Zip archive
+ hesk_unlink($save_to);
+
+ // Echo memory peak usage
+ $flush_me .= hesk_date() . " | " . sprintf($hesklang['pmem'], (@memory_get_peak_usage(true) / 1048576)) . "
\r\n";
+
+ // We're done!
+ $flush_me .= hesk_date() . " | {$hesklang['fZIP']}
";
+
+ // Success message
+ $success_msg .= $hesk_settings['debug_mode'] ? $flush_me : '
';
+ $success_msg .= $hesklang['step1'] . ': ' . $hesklang['ch2d'] . '
' . $hesklang['step2'] . ': ' . $hesklang['dffs'] . '';
+ } // No tickets exported, cleanup
+ else {
+ hesk_unlink($save_to);
+ }
+
+ return array($success_msg, $tickets_exported);
+
+} // END hesk_export_to_XML()
\ No newline at end of file
diff --git a/inc/print_template.php b/inc/print_template.inc.php
similarity index 100%
rename from inc/print_template.php
rename to inc/print_template.inc.php