function populate() { $tickets = new TicketCollection(new Ticket()); $pl = new PageList('current_tickets'); $ticket_sh = new SearchHandler($tickets, false); $ticket_sh->setLimit(10); $ticket_sh->setOrderBy('created', 'ASC'); $user = new User(); $user->loadBy('username', EGS_USERNAME); $ticket_sh->addConstraint(new Constraint('originator_person_id', '=', $user->username)); $ticket_sh->addConstraint(new Constraint('usercompanyid', '=', EGS_COMPANY_ID)); // Find open statuses $statuses = new TicketStatusCollection(new TicketStatus()); $status_sh = new SearchHandler($statuses); $status_sh->addConstraint(new Constraint('usercompanyid', '=', EGS_COMPANY_ID)); $status_sh->addConstraint(new Constraint('status_code', '=', 'NEW'), 'OR'); $status_sh->addConstraint(new Constraint('status_code', '=', 'OPEN'), 'OR'); $statuses->load($status_sh); foreach ($statuses->getContents() as $status) { $ticket_sh->addConstraint(new Constraint('client_ticket_status_id', '=', $status->id), 'OR'); } $tickets->load($ticket_sh); $pl->addFromCollection($tickets, array('module' => 'ticketing', 'controller' => 'tickets', 'action' => 'view'), array('id'), 'ticket', 'summary'); $this->contents = $pl->getPages()->toArray(); }
public static function mytickets() { $search = new TicketsSearch(); $search->setHidden(); $field = new SelectSearchField('originator_person_id'); $user = new User(); $user->loadBy('username', EGS_USERNAME); $field->setValue($user->username); $search->addField('originator_person_id', $field); return $search; }
function getDefaultAssignedTo($field) { if (isset($_GET['project_id'])) { $resource = new Resource(); $cc = new ConstraintChain(); $cc->add(new Constraint('project_id', '=', $_GET['project_id'])); $cc->add(new Constraint('project_manager', '=', 'true')); $res = $resource->loadBy($cc); if ($res !== false) { $user = new User(); $user->loadBy('person_id', $resource->person_id); return $user->username; } } return EGS_USERNAME; }
public function changePassword($data) { $current_password = $data['current_password']; $new_password = $data['new_password']; $confirm_password = $data['confirm_password']; $user = new User(); $cc = new ConstraintChain(); $cc->add(new Constraint('username', '=', EGS_USERNAME)); $result = $user->loadBy($cc); $current_match = password_verify($current_password, $result->password); if ($result !== FALSE && $current_match === TRUE && $new_password === $confirm_password && strlen($new_password) >= 10) { User::updatePassword($new_password, EGS_USERNAME); } else { $flash = Flash::Instance(); $flash->addError('Please check your current password is correct, and that you have typed your new password correctly both times'); $flash->addError('Passwords must be at least 10 characters long'); return FALSE; } }
public function save() { // Set some defaults $errors = array(); $flash = Flash::Instance(); if (isset($this->_data['Ticket']['id']) && $this->_data['Ticket']['id'] != '') { $originalTicket = new Ticket(); $originalTicket->load($this->_data['Ticket']['id']); // Check for Client Status/Priority/Severity/Queue change $changes = array(array('param' => 'client_ticket_status_id', 'friendly' => 'Status', 'object' => 'TicketStatus'), array('param' => 'client_ticket_priority_id', 'friendly' => 'Priority', 'object' => 'TicketPriority'), array('param' => 'client_ticket_severity_id', 'friendly' => 'Severity', 'object' => 'TicketSeverity'), array('param' => 'ticket_queue_id', 'friendly' => 'Queue', 'object' => 'TicketQueue')); $changeText = array(); foreach ($changes as $change) { if ($this->_data['Ticket'][$change['param']] != $originalTicket->{$change}['param']) { $was = new $change['object'](); $now = new $change['object'](); $was->load($originalTicket->{$change}['param']); $now->load($this->_data['Ticket'][$change['param']]); $changeText[] = $change['friendly'] . ': was ' . $was->name . ' now ' . $now->name . '.'; } } if (count($changeText) > 0) { $ticketResponse = TicketResponse::Factory(array('ticket_id' => $this->_data['Ticket']['id'], 'internal' => 'false', 'body' => implode("\n", $changeText), 'type' => 'status', 'owner' => EGS_USERNAME), $errors, 'TicketResponse'); $ticketResponse->save(); if (!empty($this->_data['TicketResponse']['body']) && !isset($this->_data['TicketResponse']['internal'])) { $changeText[] = $this->_data['TicketResponse']['body']; } // Send mail $headers = array('From' => TicketingUtils::getReplyAddress($originalTicket)); $header_string = ""; foreach ($headers as $header => $value) { $header_string .= $header . ': ' . $value . "\r\n"; } $body = TicketingUtils::StatusPlate($originalTicket) . implode("\n", $changeText); $recipients = TicketingUtils::GetRecipients($originalTicket); foreach ($recipients as $recipient) { mail($recipient, 're: [' . $originalTicket->ticket_queue_id . '-' . $originalTicket->id . '] ' . $originalTicket->summary, $body, $header_string); } } // Check for Internal Status/Priority/Severity/Assigned to/Originator Person/Company change $changes = array(array('param' => 'internal_ticket_status_id', 'friendly' => 'Internal Status', 'object' => 'TicketStatus'), array('param' => 'internal_ticket_priority_id', 'friendly' => 'Internal Priority', 'object' => 'TicketPriority'), array('param' => 'internal_ticket_severity_id', 'friendly' => 'Internal Severity', 'object' => 'TicketSeverity'), array('param' => 'assigned_to', 'friendly' => 'Assigned To', 'object' => 'User', 'fields' => array('username')), array('param' => 'originator_person_id', 'friendly' => 'Person', 'object' => 'Person'), array('param' => 'originator_company_id', 'friendly' => 'Company', 'object' => 'Company')); $changeText = array(); foreach ($changes as $change) { if ($this->_data['Ticket'][$change['param']] != $originalTicket->{$change}['param']) { $was = new $change['object'](); $now = new $change['object'](); $was->load($originalTicket->{$change}['param']); $now->load($this->_data['Ticket'][$change['param']]); if (!isset($change['fields'])) { $was_value = $was->name; } else { $t = ''; foreach ($change['fields'] as $field) { $t .= $was->{$field} . ' '; } $t = rtrim($t); $was_value = $t; } if (!isset($change['fields'])) { $now_value = $now->name; } else { $t = ''; foreach ($change['fields'] as $field) { $t .= $now->{$field} . ' '; } $t = rtrim($t); $now_value = $t; } $changeText[] = $change['friendly'] . ': was ' . $was_value . ' now ' . $now_value . '.'; } } if (count($changeText) > 0) { $ticketResponse = TicketResponse::Factory(array('ticket_id' => $this->_data['Ticket']['id'], 'internal' => 'true', 'body' => implode("\n", $changeText), 'type' => 'status', 'owner' => EGS_USERNAME), $errors, 'TicketResponse'); $ticketResponse->save(); } // Assignation changed? if ($this->_data['Ticket']['assigned_to'] != $originalTicket->assigned_to and $this->_data['Ticket']['assigned_to'] != '') { // Find email address for user $user = new User(); $user->loadBy('username', $this->_data['Ticket']['assigned_to']); if (!is_null($user->person_id)) { $person = new Person(); $person->load($user->person_id); $to = $person->email->contactmethod; } else { $to = ''; } if (empty($to)) { $to = $user->email; } if ($to != '') { $body = "The following ticket has been assigned to you:\n"; $body .= '[' . $this->_data['Ticket']['ticket_queue_id'] . '-' . $this->_data['Ticket']['id'] . '] ' . $this->_data['Ticket']['summary'] . "\n"; $header_string = 'From: ' . TicketingUtils::getReplyAddress($originalTicket); mail($to, 'You\'ve been assigned: [' . $this->_data['Ticket']['ticket_queue_id'] . '-' . $this->_data['Ticket']['id'] . '] ' . $this->_data['Ticket']['summary'], $body, $header_string); } } } if (isset($this->_data['TicketResponse']) && empty($this->_data['TicketResponse']['body'])) { unset($this->_data['TicketResponse']); } if (parent::save('Ticket', '', $errors)) { sendTo('Tickets', 'view', array('ticketing'), array('id' => $this->saved_model->id)); } $errors[] = 'Error saving ticket'; $flash->addErrors($errors); $this->refresh(); }
private function notifyQueueOwner($ticket, $data) { // Needs to be Assigned To if present // otherwise Queue Owner $plateout = TicketingUtils::StatusPlate($ticket); $to = ''; if (!is_null($ticket->assigned_to)) { $user = new User(); $user->loadBy('username', $ticket->assigned_to); if (!is_null($user->person_id)) { $person = new Person(); $person->load($user->person_id); $to = $person->email->contactmethod; } if (empty($to)) { $to = $user->email; } } if (empty($to)) { $queue = new TicketQueue(); $queue->load($ticket->ticket_queue_id); if ($queue->isLoaded() && !is_null($queue->email_address)) { $to = $queue->email_address; } } if (!empty($to)) { $headers = array('From' => TicketingUtils::getReplyAddress($ticket), 'Reply-To' => $data['reply_address']); $header_string = ""; foreach ($headers as $header => $value) { $header_string .= $header . ': ' . $value . "\r\n"; } $body = $plateout . "\n" . $data['message'] . "\n"; mail($to, 're: [' . $ticket->ticket_queue_id . '-' . $ticket->id . '] ' . $ticket->summary, $body, $header_string, '-r ' . $to); } }