Fix error management

This commit is contained in:
Laurent Destailleur
2018-03-12 13:19:09 +01:00
parent 97c93e35fc
commit 0d1e26b02c
3 changed files with 58 additions and 55 deletions

View File

@@ -155,12 +155,12 @@ class FormTicketsup
if ($this->withref) { if ($this->withref) {
// Ref // Ref
$defaultref = $ticketstat->getDefaultRef(); $defaultref = $ticketstat->getDefaultRef();
print '<tr><td><span class="fieldrequired">' . $langs->trans("Ref") . '</span></td><td><input size="18" type="text" name="ref" value="' . (GETPOST("ref", 'alpha') ? GETPOST("ref", 'alpha') : $defaultref) . '"></td></tr>'; print '<tr><td class="titlefield"><span class="fieldrequired">' . $langs->trans("Ref") . '</span></td><td><input size="18" type="text" name="ref" value="' . (GETPOST("ref", 'alpha') ? GETPOST("ref", 'alpha') : $defaultref) . '"></td></tr>';
} }
// FK_USER_CREATE // FK_USER_CREATE
if ($this->withusercreate > 0 && $this->fk_user_create) { if ($this->withusercreate > 0 && $this->fk_user_create) {
print '<tr><td width="35%">' . $langs->trans("CreatedBy") . '</td><td>'; print '<tr><td class="titlefield">' . $langs->trans("CreatedBy") . '</td><td>';
$langs->load("users"); $langs->load("users");
$fuser = new User($this->db); $fuser = new User($this->db);
@@ -178,7 +178,7 @@ class FormTicketsup
// altairis: force company and contact id for external user // altairis: force company and contact id for external user
if (empty($user->socid)) { if (empty($user->socid)) {
// Company // Company
print '<tr><td>' . $langs->trans("Customer") . '</td><td>'; print '<tr><td class="titlefield">' . $langs->trans("Customer") . '</td><td>';
$events = array(); $events = array();
$events[] = array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php', 1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled')); $events[] = array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php', 1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled'));
print $form->select_company($this->withfromsocid, 'socid', '', 1, 1, '', $events); print $form->select_company($this->withfromsocid, 'socid', '', 1, 1, '', $events);
@@ -245,7 +245,7 @@ class FormTicketsup
$formcompany->selectTypeContact($ticketstatic, '', 'type', 'external'); $formcompany->selectTypeContact($ticketstatic, '', 'type', 'external');
print '</td></tr>'; print '</td></tr>';
} else { } else {
print '<tr><td><input type="hidden" name="socid" value="' . $user->socid . '"/></td>'; print '<tr><td class="titlefield"><input type="hidden" name="socid" value="' . $user->socid . '"/></td>';
print '<td><input type="hidden" name="contactid" value="' . $user->contactid . '"/></td>'; print '<td><input type="hidden" name="contactid" value="' . $user->contactid . '"/></td>';
print '<td><input type="hidden" name="type" value="Z"/></td></tr>'; print '<td><input type="hidden" name="type" value="Z"/></td></tr>';
} }
@@ -253,8 +253,8 @@ class FormTicketsup
// TITLE // TITLE
if ($this->withemail) { if ($this->withemail) {
print '<tr><td width="35%"><label for="email"><span class="fieldrequired">' . $langs->trans("Email") . '</span></label></td><td>'; print '<tr><td class="titlefield"><label for="email"><span class="fieldrequired">' . $langs->trans("Email") . '</span></label></td><td>';
print '<input class="text" size="40" id="email" name="email" value="' . (GETPOST('email', 'alpha') ? GETPOST('email', 'alpha') : $subject) . '" />'; print '<input class="text minwidth200" id="email" name="email" value="' . (GETPOST('email', 'alpha') ? GETPOST('email', 'alpha') : $subject) . '" />';
print '</td></tr>'; print '</td></tr>';
} }
@@ -282,7 +282,7 @@ class FormTicketsup
} }
// Type // Type
print '<tr><td><span class="fieldrequired"><label for="selecttype_code">' . $langs->trans("TicketTypeRequest") . '</span></label></td><td>'; print '<tr><td class="titlefield"><span class="fieldrequired"><label for="selecttype_code">' . $langs->trans("TicketTypeRequest") . '</span></label></td><td>';
print $this->selectTypesTickets((GETPOST('type_code') ? GETPOST('type_code') : $this->type_code), 'type_code', '', '2'); print $this->selectTypesTickets((GETPOST('type_code') ? GETPOST('type_code') : $this->type_code), 'type_code', '', '2');
print '</td></tr>'; print '</td></tr>';

View File

@@ -6149,6 +6149,12 @@ function setEventMessage($mesgs, $style='mesgs')
*/ */
function setEventMessages($mesg, $mesgs, $style='mesgs') function setEventMessages($mesg, $mesgs, $style='mesgs')
{ {
if (empty($mesg) && empty($mesgs))
{
dol_syslog("Try to add a message in stack with empty message", LOG_WARNING);
}
else
{
if (! in_array((string) $style, array('mesgs','warnings','errors'))) dol_print_error('','Bad parameter style='.$style.' for setEventMessages'); if (! in_array((string) $style, array('mesgs','warnings','errors'))) dol_print_error('','Bad parameter style='.$style.' for setEventMessages');
if (empty($mesgs)) setEventMessage($mesg, $style); if (empty($mesgs)) setEventMessage($mesg, $style);
else else
@@ -6156,6 +6162,7 @@ function setEventMessages($mesg, $mesgs, $style='mesgs')
if (! empty($mesg) && ! in_array($mesg, $mesgs)) setEventMessage($mesg, $style); // Add message string if not already into array if (! empty($mesg) && ! in_array($mesg, $mesgs)) setEventMessage($mesg, $style); // Add message string if not already into array
setEventMessage($mesgs, $style); setEventMessage($mesgs, $style);
} }
}
} }
/** /**

View File

@@ -93,7 +93,7 @@ class ActionsTicketsup
if (GETPOST('addfile')) { if (GETPOST('addfile')) {
// altairis : allow files from public interface // altairis : allow files from public interface
if (GETPOST('track_id')) { if (GETPOST('track_id')) {
$res = $this->dao->fetch('', GETPOST('track_id')); $res = $this->dao->fetch('', GETPOST('track_id','alpha'));
} }
////if($res > 0) ////if($res > 0)
@@ -139,11 +139,11 @@ class ActionsTicketsup
if (!GETPOST("subject")) { if (!GETPOST("subject")) {
$error++; $error++;
array_push($this->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("Subject"))); $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Subject"));
$action = 'create_ticket'; $action = 'create_ticket';
} elseif (!GETPOST("message")) { } elseif (!GETPOST("message")) {
$error++; $error++;
array_push($this->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("message"))); $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("message"));
$action = 'create_ticket'; $action = 'create_ticket';
} }
@@ -170,8 +170,8 @@ class ActionsTicketsup
$id = $this->dao->create($user); $id = $this->dao->create($user);
if ($id <= 0) { if ($id <= 0) {
$error++; $error++;
$errors = ($this->dao->error ? array($this->dao->error) : $this->dao->errors); $this->errors = $this->dao->error;
array_push($this->errors, $this->dao->error ? array($this->dao->error) : $this->dao->errors); $this->errors = $this->dao->errors;
$action = 'create_ticket'; $action = 'create_ticket';
} }
@@ -235,7 +235,7 @@ class ActionsTicketsup
$id = $fichinter->create($user); $id = $fichinter->create($user);
if ($id <= 0) { if ($id <= 0) {
setEventMessage($fichinter->error, 'errors'); setEventMessages($fichinter->error, null, 'errors');
} }
} }
@@ -249,10 +249,10 @@ class ActionsTicketsup
exit; exit;
} else { } else {
$this->db->rollback(); $this->db->rollback();
setEventMessage($this->errors, 'errors'); setEventMessages($this->error, $this->errors, 'errors');
} }
} else { } else {
setEventMessage($this->errors, 'errors'); setEventMessages($this->error, $this->errors, 'errors');
} }
} }
@@ -294,7 +294,8 @@ class ActionsTicketsup
$ret = $this->dao->update(GETPOST('id'), $user); $ret = $this->dao->update(GETPOST('id'), $user);
if ($ret <= 0) { if ($ret <= 0) {
$error++; $error++;
$errors = ($this->dao->error ? array($this->dao->error) : $this->dao->errors); $this->errors = $this->dao->error;
$this->errors = $this->dao->errors;
$action = 'edit'; $action = 'edit';
} }
@@ -314,9 +315,9 @@ class ActionsTicketsup
$log_action = $langs->trans('TicketLogMesgReadBy', $user->getFullName($langs)); $log_action = $langs->trans('TicketLogMesgReadBy', $user->getFullName($langs));
$ret = $this->dao->createTicketLog($user, $log_action); $ret = $this->dao->createTicketLog($user, $log_action);
if ($ret > 0) { if ($ret > 0) {
setEventMessage($langs->trans('TicketMarkedAsRead')); setEventMessages($langs->trans('TicketMarkedAsRead'), null, 'mesgs');
} else { } else {
setEventMessage($langs->trans('TicketMarkedAsReadButLogActionNotSaved'), 'errors'); setEventMessages($langs->trans('TicketMarkedAsReadButLogActionNotSaved'), null, 'errors');
} }
header("Location: card.php?track_id=" . $this->dao->track_id . "&action=view"); header("Location: card.php?track_id=" . $this->dao->track_id . "&action=view");
exit; exit;
@@ -362,9 +363,9 @@ class ActionsTicketsup
$log_action = $langs->trans('TicketLogAssignedTo', $this->dao->user->getFullName($langs)); $log_action = $langs->trans('TicketLogAssignedTo', $this->dao->user->getFullName($langs));
$ret = $this->dao->createTicketLog($user, $log_action); $ret = $this->dao->createTicketLog($user, $log_action);
if ($ret > 0) { if ($ret > 0) {
setEventMessage($langs->trans('TicketAssigned')); setEventMessages($langs->trans('TicketAssigned'), null, 'mesgs');
} else { } else {
setEventMessage($langs->trans('TicketAssignedButLogActionNotSaved'), 'errors'); setEventMessages($langs->trans('TicketAssignedButLogActionNotSaved'), null, 'errors');
} }
header("Location: card.php?track_id=" . $this->dao->track_id . "&action=view"); header("Location: card.php?track_id=" . $this->dao->track_id . "&action=view");
exit; exit;
@@ -393,7 +394,7 @@ class ActionsTicketsup
$log_action = $langs->trans('TicketLogPropertyChanged', $oldvalue_label, $newvalue_label); $log_action = $langs->trans('TicketLogPropertyChanged', $oldvalue_label, $newvalue_label);
$ret = $this->dao->createTicketLog($user, $log_action); $ret = $this->dao->createTicketLog($user, $log_action);
if ($ret > 0) { if ($ret > 0) {
setEventMessage($langs->trans('TicketUpdated')); setEventMessages($langs->trans('TicketUpdated'), null, 'mesgs');
} }
} }
$action = 'view'; $action = 'view';
@@ -411,7 +412,7 @@ class ActionsTicketsup
header("Location: " . $url); header("Location: " . $url);
exit; exit;
} else { } else {
setEventMessage($this->dao->error, 'errors'); setEventMessages($this->dao->error, null, 'errors');
$action = 'add_message'; $action = 'add_message';
} }
} }
@@ -427,15 +428,15 @@ class ActionsTicketsup
$log_action = $langs->trans('TicketLogClosedBy', $user->getFullName($langs)); $log_action = $langs->trans('TicketLogClosedBy', $user->getFullName($langs));
$ret = $this->dao->createTicketLog($user, $log_action); $ret = $this->dao->createTicketLog($user, $log_action);
if ($ret > 0) { if ($ret > 0) {
setEventMessage('<div class="confirm">' . $langs->trans('TicketMarkedAsClosed') . '</div>'); setEventMessages('<div class="confirm">' . $langs->trans('TicketMarkedAsClosed') . '</div>');
} else { } else {
setEventMessage($langs->trans('TicketMarkedAsClosedButLogActionNotSaved'), 'warnings'); setEventMessages($langs->trans('TicketMarkedAsClosedButLogActionNotSaved'), null, 'warnings');
} }
$url = 'card.php?action=view&track_id=' . GETPOST('track_id', 'alpha'); $url = 'card.php?action=view&track_id=' . GETPOST('track_id', 'alpha');
header("Location: " . $url); header("Location: " . $url);
} else { } else {
$action = ''; $action = '';
setEventMessage($this->error, 'errors'); setEventMessages($this->error, $this->errors, 'errors');
} }
} }
@@ -446,14 +447,14 @@ class ActionsTicketsup
$log_action = $langs->trans('TicketLogClosedBy', $_SESSION['email_customer']); $log_action = $langs->trans('TicketLogClosedBy', $_SESSION['email_customer']);
$ret = $this->dao->createTicketLog($user, $log_action); $ret = $this->dao->createTicketLog($user, $log_action);
if ($ret > 0) { if ($ret > 0) {
setEventMessage('<div class="confirm">' . $langs->trans('TicketMarkedAsClosed') . '</div>'); setEventMessages('<div class="confirm">' . $langs->trans('TicketMarkedAsClosed') . '</div>', null, 'mesgs');
} else { } else {
setEventMessage($langs->trans('TicketMarkedAsClosedButLogActionNotSaved'), 'warnings'); setEventMessages($langs->trans('TicketMarkedAsClosedButLogActionNotSaved'), null, 'warnings');
} }
$url = 'view.php?action=view_ticket&track_id=' . GETPOST('track_id', 'alpha'); $url = 'view.php?action=view_ticket&track_id=' . GETPOST('track_id', 'alpha');
header("Location: " . $url); header("Location: " . $url);
} else { } else {
setEventMessage($this->error, 'errors'); setEventMessages($this->error, $this->errors, 'errors');
$action = ''; $action = '';
} }
} }
@@ -461,7 +462,7 @@ class ActionsTicketsup
if ($action == 'confirm_delete_ticket' && GETPOST('confirm', 'alpha') == "yes" && $user->rights->ticketsup->delete) { if ($action == 'confirm_delete_ticket' && GETPOST('confirm', 'alpha') == "yes" && $user->rights->ticketsup->delete) {
if ($this->fetch(GETPOST('id', 'int'), GETPOST('track_id', 'alpha')) >= 0) { if ($this->fetch(GETPOST('id', 'int'), GETPOST('track_id', 'alpha')) >= 0) {
if ($this->dao->delete($user) > 0) { if ($this->dao->delete($user) > 0) {
setEventMessage('<div class="confirm">' . $langs->trans('TicketDeletedSuccess') . '</div>'); setEventMessages('<div class="confirm">' . $langs->trans('TicketDeletedSuccess') . '</div>', null, 'mesgs');
Header("Location: index.php"); Header("Location: index.php");
exit; exit;
} else { } else {
@@ -523,7 +524,7 @@ class ActionsTicketsup
$ret = $this->dao->update($user); $ret = $this->dao->update($user);
if ($ret > 0) { if ($ret > 0) {
setEventMessage($langs->trans('TicketUpdated')); setEventMessages($langs->trans('TicketUpdated'), null, 'mesgs');
$url = 'card.php?action=view&track_id=' . $this->dao->track_id; $url = 'card.php?action=view&track_id=' . $this->dao->track_id;
header("Location: " . $url); header("Location: " . $url);
exit(); exit();
@@ -580,7 +581,7 @@ class ActionsTicketsup
$ret = $this->dao->createTicketLog($user, $log_action); $ret = $this->dao->createTicketLog($user, $log_action);
if ($ret > 0) { if ($ret > 0) {
setEventMessage($langs->trans('TicketMessageSuccesfullyUpdated')); setEventMessages($langs->trans('TicketMessageSuccesfullyUpdated'), null, 'mesgs');
} }
} }
} }
@@ -646,13 +647,13 @@ class ActionsTicketsup
$id = $this->dao->createTicketMessage($user); $id = $this->dao->createTicketMessage($user);
if ($id <= 0) { if ($id <= 0) {
$error++; $error++;
$errors = ($this->dao->error ? array($this->dao->error) : $this->dao->errors); $this->errors = $this->dao->error;
array_push($this->errors, $this->dao->error ? array($this->dao->error) : $this->dao->errors); $this->errors = $this->dao->errors;
$action = 'add_message'; $action = 'add_message';
} }
if (!$error && $id > 0) { if (!$error && $id > 0) {
setEventMessage($langs->trans('TicketMessageSuccessfullyAdded')); setEventMessages($langs->trans('TicketMessageSuccessfullyAdded'), null, 'mesgs');
/* /*
* Send email to linked contacts * Send email to linked contacts
@@ -809,11 +810,11 @@ class ActionsTicketsup
return 1; return 1;
} else { } else {
return -1; return -1;
setEventMessage($this->dao->error, 'errors'); setEventMessages($this->dao->error, $this->dao->errors, 'errors');
} }
} else { } else {
return -1; return -1;
setEventMessage($this->errors, 'errors'); setEventMessages($this->error, $this->errors, 'errors');
} }
} }
@@ -849,13 +850,13 @@ class ActionsTicketsup
$id = $this->dao->createTicketMessage($user); $id = $this->dao->createTicketMessage($user);
if ($id <= 0) { if ($id <= 0) {
$error++; $error++;
$errors = ($this->dao->error ? array($this->dao->error) : $this->dao->errors); $this->errors = $this->dao->error;
array_push($this->errors, $this->dao->error ? array($this->dao->error) : $this->dao->errors); $this->errors = $this->dao->errors;
$action = 'add_message'; $action = 'add_message';
} }
if (!$error && $id > 0) { if (!$error && $id > 0) {
setEventMessage($langs->trans('TicketMessageSuccessfullyAdded')); setEventMessages($langs->trans('TicketMessageSuccessfullyAdded'), null, 'mesgs');
// Retrieve internal contact datas // Retrieve internal contact datas
$internal_contacts = $this->dao->getInfosTicketInternalContact(); $internal_contacts = $this->dao->getInfosTicketInternalContact();
@@ -954,10 +955,10 @@ class ActionsTicketsup
header("Location: " . $url); header("Location: " . $url);
exit; exit;
} else { } else {
setEventMessage($this->dao->error, 'errors'); setEventMessages($this->dao->error, $this->dao->errors, 'errors');
} }
} else { } else {
setEventMessage($this->errors, 'errors'); setEventMessages($this->error, $this->errors, 'errors');
} }
} }
@@ -1385,18 +1386,18 @@ class ActionsTicketsup
include_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php'; include_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php';
$mailfile = new CMailFile($subject, $receiver, $from, $message_to_send, $filepath, $mimetype, $filename, $sendtocc, '', $deliveryreceipt, -1); $mailfile = new CMailFile($subject, $receiver, $from, $message_to_send, $filepath, $mimetype, $filename, $sendtocc, '', $deliveryreceipt, -1);
if ($mailfile->error) { if ($mailfile->error) {
setEventMessage($mailfile->error, 'errors'); setEventMessages($mailfile->error, null, 'errors');
} else { } else {
$result = $mailfile->sendfile(); $result = $mailfile->sendfile();
if ($result) { if ($result) {
setEventMessage($langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($receiver, 2)), 'mesgs'); setEventMessages($langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($receiver, 2)), null, 'mesgs');
} else { } else {
$langs->load("other"); $langs->load("other");
if ($mailfile->error) { if ($mailfile->error) {
setEventMessage($langs->trans('ErrorFailedToSendMail', $from, $receiver), 'errors'); setEventMessages($langs->trans('ErrorFailedToSendMail', $from, $receiver), null, 'errors');
dol_syslog($langs->trans('ErrorFailedToSendMail', $from, $receiver) . ' : ' . $mailfile->error); dol_syslog($langs->trans('ErrorFailedToSendMail', $from, $receiver) . ' : ' . $mailfile->error);
} else { } else {
setEventMessage('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', 'errors'); setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'errors');
} }
} }
} }
@@ -1406,23 +1407,18 @@ class ActionsTicketsup
} }
} else { } else {
$langs->load("other"); $langs->load("other");
setEventMessage($langs->trans('ErrorMailRecipientIsEmptyForSendTicketMessage') . '!', 'warnings'); setEventMessages($langs->trans('ErrorMailRecipientIsEmptyForSendTicketMessage'), null, 'warnings');
} }
} }
/** /**
* Copy files into ticket directory * Copy files into ticket directory
*
* Used for files linked into messages * Used for files linked into messages
<<<<<<< HEAD
* *
* @return void * @return void
=======
>>>>>>> branch 'develop' of git@github.com:Dolibarr/dolibarr.git
*/ */
public function copyFilesForTicket() public function copyFilesForTicket()
{ {
global $conf; global $conf;
// Create form object // Create form object