diff --git a/htdocs/ticket/card.php b/htdocs/ticket/card.php index 6c7a1278c99..0cb1673fa81 100644 --- a/htdocs/ticket/card.php +++ b/htdocs/ticket/card.php @@ -268,53 +268,55 @@ if (empty($reshook)) { } } - if ($action == 'edit' && $user->rights->ticket->write) { + if ($action == 'update' && $user->rights->ticket->write && $object->fk_statut < Ticket::STATUS_CLOSED) { $error = 0; - if ($object->fetch(GETPOST('id', 'int')) < 0) { - $error++; - array_push($object->errors, $langs->trans("ErrorTicketIsNotValid")); - $_GET["action"] = $_POST["action"] = ''; - } - } - - if (GETPOST('update', 'alpha') && GETPOST('id', 'int') && $user->rights->ticket->write) { - $error = 0; - - $ret = $object->fetch(GETPOST('id', 'int')); + $ret = $object->fetch(GETPOST('id', 'int'), GETPOST('ref', 'alpha'), GETPOST('track_id', 'alpha')); if ($ret < 0) { $error++; - array_push($object->errors, $langs->trans("ErrorTicketIsNotValid")); - $action = ''; - } elseif (!GETPOST("label")) { - $error++; - array_push($object->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label"))); - $action = 'edit'; - } elseif (!GETPOST("subject", 'alphanohtml')) { - $error++; - array_push($object->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("Subject"))); - $action = 'edit'; + array_push($object->errors, $langs->trans('ErrorTicketIsNotValid')); + } + + // check fields + if (!$error) { + if (!GETPOST('subject' , 'alpha')) { + $error++; + array_push($object->errors, $langs->trans('ErrorFieldRequired', $langs->transnoentities('Subject'))); + } + $ret = $extrafields->setOptionalsFromPost(null, $object); + if ($ret < 0) $error++; } if (!$error) { $db->begin(); - $object->label = GETPOST("label", 'alphanohtml'); - $object->description = GETPOST("description", 'restricthtml'); + $object->subject = GETPOST('subject', 'alpha'); + $object->type_code = GETPOST('type_code', 'alpha'); + $object->category_code = GETPOST('category_code', 'alpha'); + $object->severity_code = GETPOST('severity_code', 'alpha'); - //... $ret = $object->update($user); - if ($ret <= 0) { - $error++; - setEventMessages($object->error, $object->errors, 'errors'); - $action = 'edit'; + if ($ret <= 0) $error++; + + if ($error) { + $db->rollback(); + } else { + $db->commit(); + } + } + + if ($error) { + setEventMessages($object->error, $object->errors, 'errors'); + $action = 'edit'; + } else { + if (!empty($backtopage)) { + $url = $backtopage; + } else { + $url = 'card.php?track_id=' . $object->track_id; } - if (!$error && $ret > 0) { - $db->commit(); - } else { - $db->rollback(); - } + header('Location: ' . $url); + exit(); } } @@ -650,9 +652,63 @@ if ($action == 'create' || $action == 'presend') } $formticket->showForm(1, 'create'); -} +} elseif ($action == 'edit' && $user->rights->ticket->write && $object->fk_statut < Ticket::STATUS_CLOSED) { + $formticket = new FormTicket($db); -if (empty($action) || $action == 'view' || $action == 'addlink' || $action == 'dellink' || $action == 'presend' || $action == 'presend_addmessage' || $action == 'close' || $action == 'delete' || $action == 'editcustomer' || $action == 'progression' || $action == 'reopen' + $head = ticket_prepare_head($object); + + print '
'; +} +elseif (empty($action) || $action == 'view' || $action == 'addlink' || $action == 'dellink' || $action == 'presend' || $action == 'presend_addmessage' || $action == 'close' || $action == 'delete' || $action == 'editcustomer' || $action == 'progression' || $action == 'reopen' || $action == 'editsubject' || $action == 'edit_extras' || $action == 'update_extras' || $action == 'edit_extrafields' || $action == 'set_extrafields' || $action == 'classify' || $action == 'sel_contract' || $action == 'edit_message_init' || $action == 'set_status' || $action == 'dellink') { if ($res > 0) @@ -1193,6 +1249,10 @@ if (empty($action) || $action == 'view' || $action == 'addlink' || $action == 'd print ''; } + if ($user->rights->ticket->write && $object->fk_statut < Ticket::STATUS_CLOSED) { + print ''; + } + // Close ticket if statut is read if ($object->fk_statut > 0 && $object->fk_statut < Ticket::STATUS_CLOSED && $user->rights->ticket->write) { print '';