FIX Follow rule to create a new page

This commit is contained in:
Laurent Destailleur 2019-05-01 17:15:42 +02:00
parent 61bf731d17
commit a75c6a81d1
4 changed files with 22 additions and 170 deletions

View File

@ -834,7 +834,7 @@ class FormTicket
if ($user->rights->ticket->write && !$user->socid)
{
print '<tr><td width="30%"></td><td colspan="2">';
$checkbox_selected = ( GETPOST('send_email') == "1" ? ' checked' : '');
$checkbox_selected = (GETPOST('send_email') == "1" ? ' checked' : '');
print '<input type="checkbox" name="send_email" value="1" id="send_msg_email" '.$checkbox_selected.'/> ';
print '<label for="send_msg_email">' . $langs->trans('SendMessageByEmail') . '</label>';
print '</td></tr>';
@ -863,18 +863,19 @@ class FormTicket
print "</td></tr>";
}
// Private message or not. TODO What does this means ?
/*
if (! $user->socid) {
print '<tr><td width="30%"></td><td>';
$checkbox_selected = ( GETPOST('private_message') == "1" ? ' checked' : '');
$checkbox_selected = (GETPOST('private_message', 'alpha') == "1" ? ' checked' : '');
print '<input type="checkbox" name="private_message" value="1" id="private_message" '.$checkbox_selected.'/> ';
print '<label for="private_message">' . $langs->trans('MarkMessageAsPrivate') . '</label>';
print '</td><td align="center">';
print $form->textwithpicto('', $langs->trans("TicketMessagePrivateHelp"), 1, 'help');
print '</td></tr>';
}
}*/
print '<tr class="email_line"><td width=20%">' . $langs->trans('Subject') . '</td>';
print '<tr class="email_line"><td class="titlefieldcreate">' . $langs->trans('Subject') . '</td>';
$label_title = empty($conf->global->MAIN_APPLICATION_TITLE) ? $mysoc->name : $conf->global->MAIN_APPLICATION_TITLE;
print '<td colspan="2"><input type="text" class="text" size="80" name="subject" value="[' . $label_title . ' - ticket #' . $this->track_id . '] ' . $langs->trans('TicketNewMessage') . '" />';
print '</td></tr>';

View File

@ -307,7 +307,7 @@ function GETPOST($paramname, $check = 'none', $method = 0, $filter = null, $opti
}
if (! empty($conf->global->MAIN_ENABLE_DEFAULT_VALUES))
{
if (! empty($_GET['action']) && $_GET['action'] == 'create' && ! isset($_GET[$paramname]) && ! isset($_POST[$paramname]))
if (! empty($_GET['action']) && preg_match('/^create/', $_GET['action']) && ! isset($_GET[$paramname]) && ! isset($_POST[$paramname]))
{
// Now search in setup to overwrite default values
if (! empty($user->default_values)) // $user->default_values defined from menu 'Setup - Default values'

View File

@ -75,7 +75,7 @@ if (empty($action) && empty($id) && empty($ref)) $action='view';
//Select mail models is same action as add_message
if (GETPOST('modelselected', 'alpha')) {
$action = 'add_message';
$action = 'create_message';
}
// Load object
@ -369,9 +369,9 @@ if ($action == "assign_user" && GETPOST('btn_assign_user', 'aplha') && $user->ri
$action = 'view';
}
if ($action == "new_message" && GETPOST('btn_add_message') && $user->rights->ticket->read) {
$ret = $object->newMessage($user, $action);
if ($ret) {
if ($action == "add_message" && GETPOST('btn_create_message') && $user->rights->ticket->read) {
$ret = $object->newMessage($user, $action, (GETPOST('private_message', 'alpha') == "on" ? 1 : 0));
if ($ret > 0) {
if (!empty($backtopage)) {
$url = $backtopage;
} else {
@ -382,14 +382,10 @@ if ($action == "new_message" && GETPOST('btn_add_message') && $user->rights->tic
exit;
} else {
setEventMessages($object->error, null, 'errors');
$action = 'add_message';
$action = 'create_message';
}
}
if ($action == "new_public_message" && GETPOST('btn_add_message')) {
$object->newMessagePublic($user, $action);
}
if ($action == "confirm_close" && GETPOST('confirm', 'alpha') == 'yes' && $user->rights->ticket->write)
{
$object->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha'));
@ -641,7 +637,7 @@ if ($action == 'create' || $action == 'presend')
$formticket->showForm(1);
}
if (empty($action) || $action == 'view' || $action == 'addlink' || $action == 'dellink' || $action == 'add_message' || $action == 'close' || $action == 'delete' || $action == 'editcustomer' || $action == 'progression' || $action == 'reopen'
if (empty($action) || $action == 'view' || $action == 'addlink' || $action == 'dellink' || $action == 'create_message' || $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)
@ -1173,8 +1169,8 @@ if (empty($action) || $action == 'view' || $action == 'addlink' || $action == 'd
if (empty($reshook))
{
// Show link to add a message (if read and not closed)
if ($object->fk_statut < Ticket::STATUS_CLOSED && $action != "add_message") {
print '<div class="inline-block divButAction"><a class="butAction" href="card.php?track_id=' . $object->track_id . '&action=add_message">' . $langs->trans('TicketAddMessage') . '</a></div>';
if ($object->fk_statut < Ticket::STATUS_CLOSED && $action != "create_message") {
print '<div class="inline-block divButAction"><a class="butAction" href="card.php?track_id=' . $object->track_id . '&action=create_message">' . $langs->trans('TicketAddMessage') . '</a></div>';
}
// Link to create an intervention
@ -1210,7 +1206,7 @@ if (empty($action) || $action == 'view' || $action == 'addlink' || $action == 'd
$action = 'presend';
}
if ($action != 'add_message')
if ($action != 'create_message')
{
print '<div class="fichecenter"><div class="fichehalfleft">';
print '<a name="builddoc"></a>'; // ancre
@ -1232,7 +1228,7 @@ if (empty($action) || $action == 'view' || $action == 'addlink' || $action == 'd
}
else
{
$action='new_message';
$action='add_message';
$modelmail='ticket_send';
print '<div>';

View File

@ -2486,11 +2486,12 @@ class Ticket extends CommonObject
/**
* Add new message on a ticket (private area)
*
* @param User $user User for action
* @param string $action Action string
* @return int
* @param User $user User for action
* @param string $action Action string
* @param int $private 1=Message is private. TODO Implement this. What does this means ?
* @return int
*/
public function newMessage($user, &$action)
public function newMessage($user, &$action, $private = 1)
{
global $mysoc, $conf, $langs;
@ -2777,152 +2778,6 @@ class Ticket extends CommonObject
setEventMessages($langs->trans('ErrorMailRecipientIsEmptyForSendTicketMessage'), null, 'warnings');
}
}
/**
* Add new message on a ticket (public area)
*
* @param User $user User for action
* @param string $action Action string
* @return void
*/
public function newMessagePublic($user, &$action)
{
global $mysoc, $conf, $langs;
$object = new Ticket($this->db);
$error = 0;
$ret = $object->fetch('', '', GETPOST('track_id', 'alpha'));
$object->socid = $object->fk_soc;
$object->fetch_thirdparty();
if ($ret < 0) {
$error++;
array_push($this->errors, $langs->trans("ErrorTicketIsNotValid"));
$action = '';
}
if (!GETPOST("message")) {
$error++;
array_push($this->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("message")));
$action = 'add_message';
}
if (!$error) {
$object->message = (string) GETPOST("message");
$id = $object->createTicketMessage($user);
if ($id <= 0) {
$error++;
$this->error = $object->error;
$this->errors = $object->errors;
$action = 'add_message';
}
if (!$error && $id > 0) {
setEventMessages($langs->trans('TicketMessageSuccessfullyAdded'), null, 'mesgs');
// Retrieve internal contact datas
$internal_contacts = $object->getInfosTicketInternalContact();
$sendto = array();
if (is_array($internal_contacts) && count($internal_contacts) > 0) {
$subject = '[' . $mysoc->name . '- ticket #' . $object->track_id . '] ' . $langs->trans('TicketNewMessage');
$message = $langs->trans('TicketMessageMailIntroAutoNewPublicMessage', $object->subject);
$message .= "\n";
$message .= GETPOST('message');
$message .= "\n";
// Coordonnées client
if ($object->thirdparty->id > 0) {
$message .= "\n\n";
$message .= "==============================================\n";
$message .= $langs->trans('Thirparty') . " : " . $object->thirdparty->name;
$message .= !empty($object->thirdparty->town) ? $langs->trans('Town') . " : " . $object->thirdparty->town : '';
$message .= "\n";
$message .= !empty($object->thirdparty->phone) ? $langs->trans('Phone') . " : " . $object->thirdparty->phone : '';
$message .= "\n";
}
// Build array to display recipient list
foreach ($internal_contacts as $key => $info_sendto) {
if ($info_sendto['email'] != '') {
$sendto[] = trim($info_sendto['firstname'] . " " . $info_sendto['lastname']) . " <" . $info_sendto['email'] . ">";
}
// Contact type
$recipient = dolGetFirstLastname($info_sendto['firstname'], $info_sendto['lastname'], '-1') . ' (' . strtolower($info_sendto['libelle']) . ')';
$message .= (!empty($recipient) ? $langs->trans('TicketNotificationRecipient') . ' : ' . $recipient . "\n" : '');
$message .= "\n";
}
// URL ticket
$url_internal_ticket = dol_buildpath('/ticket/card.php', 2) . '?track_id=' . $object->track_id;
$message .= "\n" . $langs->trans('TicketNotificationEmailBodyInfosTrackUrlinternal') . ' : ' . $url_internal_ticket . "\n";
$message .= "\n\n";
$message_signature = GETPOST('mail_signature') ? GETPOST('mail_signature') : $conf->global->TICKET_MESSAGE_MAIL_SIGNATURE;
// Add global email address reciepient
if ($conf->global->TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS && !in_array($conf->global->TICKET_NOTIFICATION_EMAIL_FROM, $sendto)) {
$sendto[] = $conf->global->TICKET_NOTIFICATION_EMAIL_FROM;
}
$this->sendTicketMessageByEmail($subject, $message, '', $sendto);
}
/*
* Email for externals users if not private
*/
// Retrieve email of all contacts external
$external_contacts = $object->getInfosTicketExternalContact();
$sendto = array();
if (is_array($external_contacts) && count($external_contacts) > 0) {
$subject = '[' . $mysoc->name . '- ticket #' . $object->track_id . '] ' . $langs->trans('TicketNewMessage');
$message = $langs->trans('TicketMessageMailIntroAutoNewPublicMessage', $object->subject);
$message .= "\n";
$message .= GETPOST('message');
$message .= "\n\n";
$message_signature = GETPOST('mail_signature') ? GETPOST('mail_signature') : $conf->global->TICKET_MESSAGE_MAIL_SIGNATURE;
foreach ($external_contacts as $key => $info_sendto) {
if ($info_sendto['email'] != '') {
$sendto[] = trim($info_sendto['firstname'] . " " . $info_sendto['lastname']) . " <" . $info_sendto['email'] . ">";
}
$recipient = '';
$recipient = dolGetFirstLastname($info_sendto['firstname'], $info_sendto['lastname'], '-1') . ' (' . strtolower($info_sendto['libelle']) . ')';
$message .= (!empty($recipient) ? $langs->trans('TicketNotificationRecipient') . ' : ' . $recipient . "\n" : '');
}
$url_public_ticket = ($conf->global->TICKET_URL_PUBLIC_INTERFACE ? $conf->global->TICKET_URL_PUBLIC_INTERFACE . '/view.php' : dol_buildpath('/public/ticket/view.php', 2)) . '?track_id=' . $object->track_id;
$message .= "\n\n" . $langs->trans('TicketNewEmailBodyInfosTrackUrlCustomer') . ' : ' . $url_public_ticket . "\n";
// Add signature
$message .= '\n\n' . $message_signature;
if (!empty($object->origin_email) && !in_array($object->origin_email, $sendto)) {
$sendto[] = $object->origin_email;
}
if ($object->fk_soc > 0 && !in_array($object->origin_email, $sendto)) {
$sendto[] = $object->thirdparty->email;
}
$this->sendTicketMessageByEmail($subject, $message, '', $sendto);
}
$object->copyFilesForTicket();
$url = 'view.php?action=view_ticket&track_id=' . $object->track_id;
header("Location: " . $url);
exit;
} else {
setEventMessages($object->error, $object->errors, 'errors');
}
} else {
setEventMessages($this->error, $this->errors, 'errors');
}
}
}