diff --git a/include/class.export.php b/include/class.export.php index d12dd3bf4762ca9456c56ae31a270bf249264549..a5e950c7fc8c8426584107d6a7be3718c3bd3f03 100644 --- a/include/class.export.php +++ b/include/class.export.php @@ -99,7 +99,7 @@ class Export { ); } - /* static */ function saveTickets($sql, $filename, $how='csv') { + static function saveTickets($sql, $filename, $how='csv') { ob_start(); self::dumpTickets($sql, $how); $stuff = ob_get_contents(); @@ -110,7 +110,64 @@ class Export { return false; } + + static function dumpTasks($sql, $how='csv') { + // Add custom fields to the $sql statement + $cdata = $fields = array(); + foreach (TaskForm::getInstance()->getFields() as $f) { + // Ignore non-data fields + if (!$f->hasData() || $f->isPresentationOnly()) + continue; + + $name = $f->get('name') ?: 'field_'.$f->get('id'); + $key = 'cdata.'.$name; + $fields[$key] = $f; + $cdata[$key] = $f->getLocal('label'); + } + // Reset the $sql query + $tasks = $sql->models() + ->select_related('dept', 'staff', 'team', 'cdata') + ->annotate(array( + 'collab_count' => SqlAggregate::COUNT('thread__collaborators'), + 'attachment_count' => SqlAggregate::COUNT('thread__entries__attachments'), + 'thread_count' => SqlAggregate::COUNT('thread__entries'), + )); + + return self::dumpQuery($tasks, + array( + 'number' => __('Task Number'), + 'created' => __('Date Created'), + 'cdata.title' => __('Title'), + 'dept::getLocalName' => __('Department'), + 'flags' => __('Current Status'), //FIXME: self:getStatus()? + 'duedate' => __('Due Date'), + 'staff::getName' => __('Agent Assigned'), + 'team::getName' => __('Team Assigned'), + 'thread_count' => __('Thread Count'), + 'attachment_count' => __('Attachment Count'), + ) + $cdata, + $how, + array('modify' => function(&$record, $keys) use ($fields) { + foreach ($fields as $k=>$f) { + if (($i = array_search($k, $keys)) !== false) { + $record[$i] = $f->export($f->to_php($record[$i])); + } + } + return $record; + }) + ); + } + + static function saveTasks($sql, $filename, $how='csv') { + + ob_start(); + self::dumpTasks($sql, $how); + $stuff = ob_get_contents(); + ob_end_clean(); + if ($stuff) + Http::download($filename, "text/$how", $stuff); + return false; } diff --git a/include/i18n/en_US/help/tips/tasks.queue.yaml b/include/i18n/en_US/help/tips/tasks.queue.yaml new file mode 100644 index 0000000000000000000000000000000000000000..393447f0b16260e6e1f2166d0453c94091794587 --- /dev/null +++ b/include/i18n/en_US/help/tips/tasks.queue.yaml @@ -0,0 +1,28 @@ +# +# This is popup help messages for the Agents Panel -> Tasks +# +# Fields: +# title - Shown in bold at the top of the popover window +# content - The body of the help popover +# links - List of links shows below the content +# title - Link title +# href - href of link (links starting with / are translated to the +# helpdesk installation path) +# +# The key names such as 'helpdesk_name' should not be translated as they +# must match the HTML #ids put into the page template. +# +--- +advanced: + title: Advanced + content: > + Narrow down your search parameters. Once you have selected your advanced + search criteria and run the search, you can <span class="doc-desc-title">Export + </span> the data at the bottom of the page. + +export: + title: Export + content: > + Export your data currently in view in a CSV file. + CSV files may be opened with any spreadsheet software + (i.e., Microsoft Excel, Apple Pages, OpenOffice, etc.). diff --git a/scp/tasks.php b/scp/tasks.php index 756b9fd577ac27f4c9d5a94745d652c0ecc23558..ced34f872ad4bd73cd9e75af307393f5c31b84ef 100644 --- a/scp/tasks.php +++ b/scp/tasks.php @@ -13,6 +13,7 @@ require('staff.inc.php'); require_once(INCLUDE_DIR.'class.task.php'); +require_once(INCLUDE_DIR.'class.export.php'); $page = ''; $task = null; //clean start.