* @license PHP License * @package WB * @subpackage content */ /** * Load classes */ WBClass::load('WBContent' , 'WBContent_ITS' , 'WBITS'); /** * Content component: ITS_Editor * * @version 1.2.0 * @package WB * @subpackage content */ class WBContent_ITS_Editor extends WBContent_ITS { /** * Parameter list * - action either "edit", "add", "list" * - requiredgroup (tableeditor) * - requiredgroupmanager (tableadmin) * - alloweditmyticket (0) whether to allow editing tickets assigned to me even if not in requiredgroup * - searchfields (array()) list of columns that are allowed to search in using LIKE * - limit * - order optional order by * @var array */ protected $config = array( 'action' => 'list', 'requiredgroup' => 'its-staff', 'requiredgroupmanager' => 'its-master', 'alloweditmyticket' => 0, 'alloweditmyticketedit' => array( 'status', 'title', 'blurb', 'comment' ), 'namespace' => '', 'goto' => 1, 'searchfields' => array('title', 'blurb'), 'limit' => 10, 'order' => '' ); /** * run * * run component * * @return array parameter list */ public function run() { if (!$this->isUserInGroup($this->config['requiredgroup'])) { if (0 < intval($this->config['alloweditmyticket']) && $this->user->isAuthenticated()) { $clause = array(); $clause[] = array( 'field' => 'assigneduid', 'value' => $this->user->getId() ); $this->its->setClause($clause); } else { $this->loadTemplates('anon'); return $this->config; } } $this->runAction(); return $this->config; } /** * Run Ticket Action * * @return array */ protected function runAction() { $this->its->initFilter($this->config['searchfields'], $this->req); switch ($this->config['action']) { // create shipping label for customer case 'downloadshippinglabel': break; // create label to tag box case 'downloadlabel': break; case 'downloadlist': $this->downloadlist(); break; case 'edit': case 'add': if (!$this->editTicket()) { break; } default: case 'list': $this->listTickets(); break; } return $this->config; } /** * Show form to edit ticket * * @return bool true if ticket was saved, false to display form */ private function editTicket() { $save = $this->req->get('save', ''); $this->ticket = $this->its->loadByObscureId($this->req->get('obscureid', '')); // normal edit stuff if ($this->ticket->isPregen()) { $this->tmpl->addGlobalVar('pregen', 'pregen:'); } $this->tmpl->addGlobalVar('obscureid', $this->ticket->getObscureId()); $this->tmpl->addGlobalVar('id', $this->ticket->getId()); $data = $this->ticket->getData(); if (!isset($data['obscureid'])) { $data['obscureid'] = ''; } $this->addGlobalVars($data); $ret = $this->processForm('edit', $data); if (is_bool($ret)) { return $ret; } return false; } /** * Save ticket data * * Update ticket data * * @param patForms $form * @param array $values * @return bool always false */ public function onEditValid($form, $values) { if (!empty($this->config['namespace'])) { $values['namespace'] = $this->config['namespace']; } // handle individual uploads if (isset($values['file'])) { if (!is_array($values['file'])) { $values['file'] = array($values['file']); } if (!isset($values['ticketmedia'])) { $data = $this->ticket->getData(); $values['ticketmedia'] = $data['ticketmedia']; } $values['ticketmedia'] = array_merge($values['ticketmedia'], $values['file']); unset($values['file']); } $this->ticket->save($values); return false; } /** * List tickets * * Get pager and fill template with list */ private function listTickets() { $options = array( 'limit' => $this->config['limit'], 'order' => $this->config['order'] ); $pager = $this->its->getPager(WBITS::PAGER_TYPE_ALL, $options); $this->tmpl->addGlobalVars($pager->browse($this->config['goto']), 'pager_'); $this->loadTemplates('list'); $this->tmpl->addRows('list_entry', $pager->get()); } private function downloadList() { $options = array( 'limit' => 5, 'order' => $this->config['order'] ); $pager = $this->its->getPager(WBITS::PAGER_TYPE_ALL, $options); /** @var WBITS_TicketList_Exporter_Spreadsheet */ $ex = WBClass::create('WBITS_TicketList_Exporter_Spreadsheet'); $config = $ex->useNamespace($this->config['namespace']); $ex->setPager($pager); $ex->export(); $this->downloadFile($ex->realpath(), 'application/vnd.ms-excel', 'tickets-' . gmdate('Y-m-d') . '.xls'); } /** * Fetch List of Form Elements * * @param string name of the xml- and template-filename * @return array $elements */ protected function getFormElementList($name) { $org = parent::getFormElementList($name); // full access user if ($this->isUserInGroup($this->config['requiredgroup'])) { return $org; } $list = array(); foreach ($org as $k => $v) { if (in_array($k, $this->config['alloweditmyticketedit'])) { $list[$k] = $v; } } return $list; } }