Skip to content
Snippets Groups Projects
Commit 50c02ff2 authored by Jared Hancock's avatar Jared Hancock
Browse files

Implement help topic forms for all new tickets

(regardless of the source)
parent 37b657bd
Branches
Tags
No related merge requests found
...@@ -122,14 +122,6 @@ class TicketApiController extends ApiController { ...@@ -122,14 +122,6 @@ class TicketApiController extends ApiController {
# Create the ticket with the data (attempt to anyway) # Create the ticket with the data (attempt to anyway)
$errors = array(); $errors = array();
if ($topic=Topic::lookup($data['topicId'])) {
if ($form=DynamicForm::lookup($topic->ht['form_id'])) {
$form = $form->instanciate();
if (!$form->isValid())
$errors += $form->errors();
}
}
$ticket = Ticket::create($data, $errors, $data['source'], $autorespond, $alert); $ticket = Ticket::create($data, $errors, $data['source'], $autorespond, $alert);
# Return errors (?) # Return errors (?)
if (count($errors)) { if (count($errors)) {
...@@ -145,12 +137,6 @@ class TicketApiController extends ApiController { ...@@ -145,12 +137,6 @@ class TicketApiController extends ApiController {
return $this->exerr(500, "Unable to create new ticket: unknown error"); return $this->exerr(500, "Unable to create new ticket: unknown error");
} }
# Save dynamic form
if (isset($form)) {
$form->setTicketId($ticket->getId());
$form->save();
}
return $ticket; return $ticket;
} }
......
...@@ -2230,6 +2230,14 @@ class Ticket { ...@@ -2230,6 +2230,14 @@ class Ticket {
$vars['email'], $filter->getName())); $vars['email'], $filter->getName()));
} }
if ($vars['topicId'] && ($topic=Topic::lookup($vars['topicId']))) {
if ($topic_form = DynamicForm::lookup($topic->ht['form_id'])) {
$topic_form = $topic_form->instanciate();
if (!$topic_form->getForm()->isValid($field_filter('topic')))
$errors = array_merge($errors, $topic_form->getForm()->errors());
}
}
$id=0; $id=0;
$fields=array(); $fields=array();
$fields['message'] = array('type'=>'*', 'required'=>1, 'error'=>'Message required'); $fields['message'] = array('type'=>'*', 'required'=>1, 'error'=>'Message required');
...@@ -2293,24 +2301,26 @@ class Ticket { ...@@ -2293,24 +2301,26 @@ class Ticket {
# Some things will need to be unpacked back into the scope of this # Some things will need to be unpacked back into the scope of this
# function # function
if (isset($vars['autorespond'])) $autorespond=$vars['autorespond']; if (isset($vars['autorespond']))
$autorespond = $vars['autorespond'];
# Apply filter-specific priority # Apply filter-specific priority
if ($vars['priorityId']) if ($vars['priorityId'])
$form->setAnswer('priority', null, $vars['priorityId']); $form->setAnswer('priority', null, $vars['priorityId']);
// OK...just do it. // OK...just do it.
$deptId=$vars['deptId']; //pre-selected Dept if any. $deptId = $vars['deptId']; //pre-selected Dept if any.
$source=ucfirst($vars['source']); $source = ucfirst($vars['source']);
$topic=NULL;
// Intenal mapping magic...see if we need to override anything // Intenal mapping magic...see if we need to override anything
if(isset($vars['topicId']) && ($topic=Topic::lookup($vars['topicId']))) { //Ticket created via web by user/or staff if (isset($topic)) {
$deptId=$deptId?$deptId:$topic->getDeptId(); $deptId = $deptId ?: $topic->getDeptId();
$priority = $form->getAnswer('priority'); $priority = $form->getAnswer('priority');
if (!$priority || !$priority->getIdValue()) if (!$priority || !$priority->getIdValue())
$form->setAnswer('priority', null, $topic->getPriorityId()); $form->setAnswer('priority', null, $topic->getPriorityId());
if($autorespond) $autorespond=$topic->autoRespond(); if ($autorespond)
$source=$vars['source']?$vars['source']:'Web'; $autorespond = $topic->autoRespond();
$source = $vars['source'] ?: 'Web';
//Auto assignment. //Auto assignment.
if (!isset($vars['staffId']) && $topic->getStaffId()) if (!isset($vars['staffId']) && $topic->getStaffId())
...@@ -2319,27 +2329,30 @@ class Ticket { ...@@ -2319,27 +2329,30 @@ class Ticket {
$vars['teamId'] = $topic->getTeamId(); $vars['teamId'] = $topic->getTeamId();
//set default sla. //set default sla.
if(isset($vars['slaId'])) if (isset($vars['slaId']))
$vars['slaId'] = $vars['slaId']?$vars['slaId']:$cfg->getDefaultSLAId(); $vars['slaId'] = $vars['slaId'] ?: $cfg->getDefaultSLAId();
elseif($topic && $topic->getSLAId()) elseif ($topic && $topic->getSLAId())
$vars['slaId'] = $topic->getSLAId(); $vars['slaId'] = $topic->getSLAId();
}
}elseif($vars['emailId'] && !$vars['deptId'] && ($email=Email::lookup($vars['emailId']))) { //Emailed Tickets // Apply email settings for emailed tickets
$deptId=$email->getDeptId(); if ($vars['emailId'] && ($email=Email::lookup($vars['emailId']))) {
$deptId = $deptId ?: $email->getDeptId();
$priority = $form->getAnswer('priority'); $priority = $form->getAnswer('priority');
if (!$priority || !$priority->getIdValue()) if (!$priority || !$priority->getIdValue())
$form->setAnswer('priority', null, $email->getPriorityId()); $form->setAnswer('priority', null, $email->getPriorityId());
if($autorespond) $autorespond=$email->autoRespond(); if ($autorespond)
$email=null; $autorespond = $email->autoRespond();
$source='Email'; $email = null;
$source = 'Email';
} }
//Last minute checks //Last minute checks
$priority = $form->getAnswer('priority'); $priority = $form->getAnswer('priority');
if (!$priority || !$priority->getIdValue()) if (!$priority || !$priority->getIdValue())
$form->setAnswer('priority', null, $cfg->getDefaultPriorityId()); $form->setAnswer('priority', null, $cfg->getDefaultPriorityId());
$deptId=$deptId?$deptId:$cfg->getDefaultDeptId(); $deptId = $deptId ?: $cfg->getDefaultDeptId();
$topicId=$vars['topicId']?$vars['topicId']:0; $topicId = $vars['topicId'] ?: 0;
$ipaddress=$vars['ip']?$vars['ip']:$_SERVER['REMOTE_ADDR']; $ipaddress = $vars['ip'] ?: $_SERVER['REMOTE_ADDR'];
//We are ready son...hold on to the rails. //We are ready son...hold on to the rails.
$number = Ticket::genRandTicketNumber(); $number = Ticket::genRandTicketNumber();
...@@ -2375,6 +2388,13 @@ class Ticket { ...@@ -2375,6 +2388,13 @@ class Ticket {
// Save the (common) dynamic form // Save the (common) dynamic form
$form->setTicketId($id); $form->setTicketId($id);
$form->save(); $form->save();
// Save the form data from the help-topic form, if any
if ($topic_form) {
$topic_form->setTicketId($id);
$topic_form->save();
}
$ticket->loadDynamicData(); $ticket->loadDynamicData();
$dept = $ticket->getDept(); $dept = $ticket->getDept();
......
...@@ -29,16 +29,6 @@ if ($_POST) { ...@@ -29,16 +29,6 @@ if ($_POST) {
$errors['captcha']='Invalid - try again!'; $errors['captcha']='Invalid - try again!';
} }
$form = false;
if ($topic = Topic::lookup($vars['topicId'])) {
if ($form = DynamicForm::lookup($topic->ht['form_id'])) {
$form = $form->instanciate();
// Don't require internal fields (they're not shown)
if (!$form->isValid(function($f) { return !$f->get('private'); }))
$errors += $form->errors();
}
}
if (!$errors && $cfg->allowOnlineAttachments() && $_FILES['attachments']) if (!$errors && $cfg->allowOnlineAttachments() && $_FILES['attachments'])
$vars['files'] = AttachmentFile::format($_FILES['attachments'], true); $vars['files'] = AttachmentFile::format($_FILES['attachments'], true);
...@@ -46,11 +36,6 @@ if ($_POST) { ...@@ -46,11 +36,6 @@ if ($_POST) {
if(($ticket=Ticket::create($vars, $errors, SOURCE))){ if(($ticket=Ticket::create($vars, $errors, SOURCE))){
$msg='Support ticket request created'; $msg='Support ticket request created';
Draft::deleteForNamespace('ticket.client.'.substr(session_id(), -12)); Draft::deleteForNamespace('ticket.client.'.substr(session_id(), -12));
// Save the form data from the help-topic form, if any
if ($form) {
$form->setTicketId($ticket->getId());
$form->save();
}
//Logged in...simply view the newly created ticket. //Logged in...simply view the newly created ticket.
if($thisclient && $thisclient->isValid()) { if($thisclient && $thisclient->isValid()) {
session_write_close(); session_write_close();
......
...@@ -485,13 +485,6 @@ if($_POST && !$errors): ...@@ -485,13 +485,6 @@ if($_POST && !$errors):
break; break;
case 'open': case 'open':
$ticket=null; $ticket=null;
if ($topic=Topic::lookup($_POST['topicId'])) {
if ($form = DynamicForm::lookup($topic->ht['form_id'])) {
$form = $form->instanciate();
if (!$form->getForm()->isValid())
$errors = array_merge($errors, $form->getForm()->errors());
}
}
if(!$thisstaff || !$thisstaff->canCreateTickets()) { if(!$thisstaff || !$thisstaff->canCreateTickets()) {
$errors['err']='You do not have permission to create tickets. Contact admin for such access'; $errors['err']='You do not have permission to create tickets. Contact admin for such access';
} else { } else {
...@@ -501,11 +494,6 @@ if($_POST && !$errors): ...@@ -501,11 +494,6 @@ if($_POST && !$errors):
if(($ticket=Ticket::open($vars, $errors))) { if(($ticket=Ticket::open($vars, $errors))) {
$msg='Ticket created successfully'; $msg='Ticket created successfully';
$_REQUEST['a']=null; $_REQUEST['a']=null;
# Save extra dynamic form(s)
if (isset($form)) {
$form->setTicketId($ticket->getId());
$form->save();
}
if (!$ticket->checkStaffAccess($thisstaff) || $ticket->isClosed()) if (!$ticket->checkStaffAccess($thisstaff) || $ticket->isClosed())
$ticket=null; $ticket=null;
Draft::deleteForNamespace('ticket.staff%', $thisstaff->getId()); Draft::deleteForNamespace('ticket.staff%', $thisstaff->getId());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment