FIX Closing ticket from public interface

This commit is contained in:
Laurent Destailleur 2019-07-19 23:43:49 +02:00
parent ec34ce1e64
commit feee437471
5 changed files with 93 additions and 84 deletions

View File

@ -237,37 +237,37 @@ if ($action == "view_ticketlist")
}
if (!empty($search_subject)) {
$filter['t.subject'] = $search_subject;
$param .= '&search_subject=' . $search_subject;
$param .= '&search_subject=' .urlencode($search_subject);
}
if (!empty($search_type)) {
$filter['t.type_code'] = $search_type;
$param .= '&search_type=' . $search_type;
$param .= '&search_type=' . urlencode($search_type);
}
if (!empty($search_category)) {
$filter['t.category_code'] = $search_category;
$param .= '&search_category=' . $search_category;
$param .= '&search_category=' . urlencode($search_category);
}
if (!empty($search_severity)) {
$filter['t.severity_code'] = $search_severity;
$param .= '&search_severity=' . $search_severity;
$param .= '&search_severity=' . urlencode($search_severity);
}
if (!empty($search_fk_user_assign)) {
// -1 value = all so no filter
if ($search_fk_user_assign > 0) {
$filter['t.fk_user_assign'] = $search_fk_user_assign;
$param .= '&search_fk_user_assign=' . $search_fk_user_assign;
$param .= '&search_fk_user_assign=' . urlencode($search_fk_user_assign);
}
}
if (!empty($search_fk_user_create)) {
// -1 value = all so no filter
if ($search_fk_user_create > 0) {
$filter['t.fk_user_create'] = $search_fk_user_create;
$param .= '&search_fk_user_create=' . $search_fk_user_create;
$param .= '&search_fk_user_create=' . urlencode($search_fk_user_create);
}
}
if ((isset($search_fk_status) && $search_fk_status != '') && $search_fk_status != '-1' && $search_fk_status != 'non_closed') {
$filter['t.fk_statut'] = $search_fk_status;
$param .= '&search_fk_status=' . $search_fk_status;
$param .= '&search_fk_status=' . urlencode($search_fk_status);
}
if (isset($search_fk_status) && $search_fk_status == 'non_closed') {
$filter['t.fk_statut'] = array(0, 1, 3, 4, 5, 6);
@ -388,62 +388,7 @@ if ($action == "view_ticketlist")
print '<table class="liste ' . ($moreforfilter ? "listwithfilterbefore" : "") . '">';
print '<tr class="liste_titre">';
if (!empty($arrayfields['t.datec']['checked'])) {
print_liste_field_titre($arrayfields['t.datec']['label'], $url_page_current, 't.datec', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['t.date_read']['checked'])) {
print_liste_field_titre($arrayfields['t.date_read']['label'], $url_page_current, 't.date_read', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['t.date_close']['checked'])) {
print_liste_field_titre($arrayfields['t.date_close']['label'], $url_page_current, 't.date_close', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['t.ref']['checked'])) {
print_liste_field_titre($arrayfields['t.ref']['label'], $url_page_current, 't.ref', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['t.subject']['checked'])) {
print_liste_field_titre($arrayfields['t.subject']['label']);
}
if (!empty($arrayfields['type.code']['checked'])) {
print_liste_field_titre($arrayfields['type.code']['label'], $url_page_current, 'type.code', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['category.code']['checked'])) {
print_liste_field_titre($arrayfields['category.code']['label'], $url_page_current, 'category.code', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['severity.code']['checked'])) {
print_liste_field_titre($arrayfields['severity.code']['label'], $url_page_current, 'severity.code', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['t.progress']['checked'])) {
print_liste_field_titre($arrayfields['t.progress']['label'], $url_page_current, 't.progress', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['t.fk_user_create']['checked'])) {
print_liste_field_titre($arrayfields['t.fk_user_create']['label'], $url_page_current, 't.fk_user_create', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['t.fk_user_assign']['checked'])) {
print_liste_field_titre($arrayfields['t.fk_user_assign']['label'], $url_page_current, 't.fk_user_assign', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['t.tms']['checked'])) {
print_liste_field_titre($arrayfields['t.tms']['label'], $url_page_current, 't.tms', '', $param, '', $sortfield, $sortorder);
}
// Extra fields
if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
if (!empty($arrayfields["ef." . $key]['checked'])) {
$align = $extrafields->getAlignFlag($key);
print_liste_field_titre($extralabels[$key], $url_page_current, "ef." . $key, "", $param, ($align ? 'align="' . $align . '"' : ''), $sortfield, $sortorder);
}
}
}
if (!empty($arrayfields['t.fk_statut']['checked'])) {
print_liste_field_titre($arrayfields['t.fk_statut']['label'], $url_page_current, 't.fk_statut', '', $param, '', $sortfield, $sortorder);
}
print_liste_field_titre($selectedfields, $url_page_current, "", '', '', 'align="right"', $sortfield, $sortorder, 'maxwidthsearch ');
print '</tr>';
/*
* Filter bar
*/
// Filter bar
print '<tr class="liste_titre">';
if (!empty($arrayfields['t.datec']['checked'])) {
@ -463,13 +408,13 @@ if ($action == "view_ticketlist")
if (!empty($arrayfields['t.subject']['checked'])) {
print '<td class="liste_titre">';
print '<input type="text" class="flat" name="search_subject" value="' . $search_subject . '" size="20">';
print '<input type="text" class="flat maxwidth100" name="search_subject" value="' . $search_subject . '">';
print '</td>';
}
if (!empty($arrayfields['type.code']['checked'])) {
print '<td class="liste_titre">';
$formTicket->selectTypesTickets($search_type, 'search_type', '', 2, 1, 1);
$formTicket->selectTypesTickets($search_type, 'search_type', '', 2, 1, 1, 0, 'maxwidth150');
print '</td>';
}
@ -524,6 +469,59 @@ if ($action == "view_ticketlist")
print '</td>';
print '</tr>';
// Field title
print '<tr class="liste_titre">';
if (!empty($arrayfields['t.datec']['checked'])) {
print_liste_field_titre($arrayfields['t.datec']['label'], $url_page_current, 't.datec', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['t.date_read']['checked'])) {
print_liste_field_titre($arrayfields['t.date_read']['label'], $url_page_current, 't.date_read', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['t.date_close']['checked'])) {
print_liste_field_titre($arrayfields['t.date_close']['label'], $url_page_current, 't.date_close', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['t.ref']['checked'])) {
print_liste_field_titre($arrayfields['t.ref']['label'], $url_page_current, 't.ref', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['t.subject']['checked'])) {
print_liste_field_titre($arrayfields['t.subject']['label']);
}
if (!empty($arrayfields['type.code']['checked'])) {
print_liste_field_titre($arrayfields['type.code']['label'], $url_page_current, 'type.code', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['category.code']['checked'])) {
print_liste_field_titre($arrayfields['category.code']['label'], $url_page_current, 'category.code', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['severity.code']['checked'])) {
print_liste_field_titre($arrayfields['severity.code']['label'], $url_page_current, 'severity.code', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['t.progress']['checked'])) {
print_liste_field_titre($arrayfields['t.progress']['label'], $url_page_current, 't.progress', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['t.fk_user_create']['checked'])) {
print_liste_field_titre($arrayfields['t.fk_user_create']['label'], $url_page_current, 't.fk_user_create', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['t.fk_user_assign']['checked'])) {
print_liste_field_titre($arrayfields['t.fk_user_assign']['label'], $url_page_current, 't.fk_user_assign', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['t.tms']['checked'])) {
print_liste_field_titre($arrayfields['t.tms']['label'], $url_page_current, 't.tms', '', $param, '', $sortfield, $sortorder);
}
// Extra fields
if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
if (!empty($arrayfields["ef." . $key]['checked'])) {
$align = $extrafields->getAlignFlag($key);
print_liste_field_titre($extralabels[$key], $url_page_current, "ef." . $key, "", $param, ($align ? 'align="' . $align . '"' : ''), $sortfield, $sortorder);
}
}
}
if (!empty($arrayfields['t.fk_statut']['checked'])) {
print_liste_field_titre($arrayfields['t.fk_statut']['label'], $url_page_current, 't.fk_statut', '', $param, '', $sortfield, $sortorder);
}
print_liste_field_titre($selectedfields, $url_page_current, "", '', '', 'align="right"', $sortfield, $sortorder, 'maxwidthsearch ');
print '</tr>';
while ($obj = $db->fetch_object($resql))
{
print '<tr class="oddeven">';
@ -551,7 +549,7 @@ if ($action == "view_ticketlist")
// Ref
if (!empty($arrayfields['t.ref']['checked'])) {
print '<td>';
print '<td class="nowraponall">';
print $obj->ref;
print '</td>';
}

View File

@ -84,7 +84,6 @@ if ($action == "view_ticket" || $action == "presend" || $action == "close" || $a
array_push($object->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("TicketTrackId")));
$action = '';
}
if (!strlen($email)) {
$error++;
array_push($object->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("Email")));
@ -154,6 +153,19 @@ if ($action == "view_ticket" || $action == "presend" || $action == "close" || $a
}
}
if (! $error && $action == 'confirm_public_close' && $display_ticket)
{
if ($object->dao->close($user)) {
setEventMessages($langs->trans('TicketMarkedAsClosed'), null, 'mesgs');
$url = 'view.php?action=view_ticket&track_id=' . GETPOST('track_id', 'alpha');
header("Location: " . $url);
} else {
$action = '';
setEventMessages($object->error, $object->errors, 'errors');
}
}
if (! $error && $action == "add_message" && $display_ticket)
{
// TODO Add message...
@ -290,8 +302,6 @@ if ($action == "view_ticket" || $action == "presend" || $action == "close" || $a
$fuser = new User($db);
$fuser->fetch($object->dao->fk_user_assign);
print $fuser->getFullName($langs, 1);
} else {
print $langs->trans('None');
}
print '</td></tr>';
@ -336,12 +346,12 @@ if ($action == "view_ticket" || $action == "presend" || $action == "close" || $a
// List ticket
print '<div class="inline-block divButAction"><a class="butAction" href="javascript:$(\'#form_view_ticket_list\').submit();">' . $langs->trans('ViewMyTicketList') . '</a></div>';
if ($object->dao->fk_statut < 8) {
if ($object->dao->fk_statut < Ticket::STATUS_CLOSED) {
// New message
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?action=presend&mode=init&track_id=' . $object->dao->track_id . '">' . $langs->trans('AddMessage') . '</a></div>';
// Close ticket
if ($object->dao->fk_statut > 0 && $object->dao->fk_statut < 8) {
if ($object->dao->fk_statut >= Ticket::STATUS_NOT_READ && $object->dao->fk_statut < Ticket::STATUS_CLOSED) {
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?action=close&track_id=' . $object->dao->track_id . '">' . $langs->trans('CloseTicket') . '</a></div>';
}
}

View File

@ -394,9 +394,6 @@ if ($action == "confirm_close" && GETPOST('confirm', 'alpha') == 'yes' && $user-
$object->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha'));
if ($object->close($user)) {
// Log action in ticket logs table
$log_action = $langs->trans('TicketLogClosedBy', $user->getFullName($langs));
setEventMessages($langs->trans('TicketMarkedAsClosed'), null, 'mesgs');
$url = 'card.php?action=view&track_id=' . GETPOST('track_id', 'alpha');
@ -409,13 +406,15 @@ if ($action == "confirm_close" && GETPOST('confirm', 'alpha') == 'yes' && $user-
if ($action == "confirm_public_close" && GETPOST('confirm', 'alpha') == 'yes') {
$object->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha'));
if (($_SESSION['email_customer'] == $object->origin_email || $_SESSION['email_customer'] == $object->thirdparty->email) && $object->close()) {
if ($_SESSION['email_customer'] == $object->origin_email || $_SESSION['email_customer'] == $object->thirdparty->email) {
$object->close($user);
// Log action in ticket logs table
$log_action = $langs->trans('TicketLogClosedBy', $_SESSION['email_customer']);
setEventMessages('<div class="confirm">' . $langs->trans('TicketMarkedAsClosed') . '</div>', null, 'mesgs');
$url = 'view.php?action=view_ticket&track_id=' . GETPOST('track_id', 'alpha');
$url = 'card.php?action=view_ticket&track_id=' . GETPOST('track_id', 'alpha');
header("Location: " . $url);
} else {
setEventMessages($object->error, $object->errors, 'errors');

View File

@ -183,7 +183,7 @@ class Ticket extends CommonObject
'track_id' => array('type'=>'varchar(255)', 'label'=>'TicketTrackId', 'visible'=>-2, 'enabled'=>1, 'position'=>11, 'notnull'=>-1, 'searchall'=>1, 'help'=>"Help text"),
'fk_user_create' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'Author', 'visible'=>1, 'enabled'=>1, 'position'=>15, 'notnull'=>1, 'css'=>'nowraponall'),
'origin_email' => array('type'=>'mail', 'label'=>'OriginEmail', 'visible'=>-2, 'enabled'=>1, 'position'=>16, 'notnull'=>1, 'index'=>1, 'searchall'=>1, 'comment'=>"Reference of object"),
'subject' => array('type'=>'varchar(255)', 'label'=>'Subject', 'visible'=>1, 'enabled'=>1, 'position'=>18, 'notnull'=>-1, 'searchall'=>1, 'help'=>""),
'subject' => array('type'=>'varchar(255)', 'label'=>'Subject', 'visible'=>1, 'enabled'=>1, 'position'=>18, 'notnull'=>-1, 'searchall'=>1, 'help'=>"", 'css'=>'maxwidth75'),
'type_code' => array('type'=>'varchar(32)', 'label'=>'Type', 'visible'=>1, 'enabled'=>1, 'position'=>20, 'notnull'=>-1, 'searchall'=>1, 'help'=>"", 'css'=>'maxwidth100'),
'category_code' => array('type'=>'varchar(32)', 'label'=>'TicketGroup', 'visible'=>-1, 'enabled'=>1, 'position'=>21, 'notnull'=>-1, 'help'=>"", 'css'=>'maxwidth100'),
'severity_code' => array('type'=>'varchar(32)', 'label'=>'Severity', 'visible'=>1, 'enabled'=>1, 'position'=>22, 'notnull'=>-1, 'help'=>"", 'css'=>'maxwidth100'),

View File

@ -499,10 +499,11 @@ print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"")
print '<tr class="liste_titre">';
foreach($object->fields as $key => $val)
{
$cssforfield='';
if (in_array($val['type'], array('date','datetime','timestamp'))) $cssforfield.=($cssforfield?' ':'').'center';
if (in_array($val['type'], array('timestamp'))) $cssforfield.=($cssforfield?' ':'').'nowrap';
if ($key == 'status') $cssforfield.=($cssforfield?' ':'').'center';
$cssforfield=(empty($val['css'])?'':$val['css']);
if ($key == 'fk_statut') $cssforfield.=($cssforfield?' ':'').'center';
elseif (in_array($val['type'], array('date','datetime','timestamp'))) $cssforfield.=($cssforfield?' ':'').'center';
elseif (in_array($val['type'], array('timestamp'))) $cssforfield.=($cssforfield?' ':'').'nowrap';
elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price'))) $cssforfield.=($cssforfield?' ':'').'right';
if (! empty($arrayfields['t.'.$key]['checked'])) {
if ($key == 'type_code') {
print '<td class="liste_titre'.($cssforfield?' '.$cssforfield:'').'">';
@ -562,10 +563,11 @@ print '</tr>'."\n";
print '<tr class="liste_titre">';
foreach($object->fields as $key => $val)
{
$cssforfield='';
if (in_array($val['type'], array('date','datetime','timestamp'))) $cssforfield.=($cssforfield?' ':'').'center';
if (in_array($val['type'], array('timestamp'))) $cssforfield.=($cssforfield?' ':'').'nowrap';
$cssforfield=(empty($val['css'])?'':$val['css']);
if ($key == 'fk_statut') $cssforfield.=($cssforfield?' ':'').'center';
elseif (in_array($val['type'], array('date','datetime','timestamp'))) $cssforfield.=($cssforfield?' ':'').'center';
elseif (in_array($val['type'], array('timestamp'))) $cssforfield.=($cssforfield?' ':'').'nowrap';
elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price'))) $cssforfield.=($cssforfield?' ':'').'right';
if (! empty($arrayfields['t.'.$key]['checked']))
{
print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, '', $sortfield, $sortorder, ($cssforfield?$cssforfield.' ':''))."\n";