Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur 2020-05-28 18:30:32 +02:00
commit 1e76101c41
10 changed files with 275 additions and 106 deletions

View File

@ -106,6 +106,12 @@ if ($action == 'setvar') {
if (!$res > 0) {
$error++;
}
$param_public_notification_new_message_default_email = GETPOST('TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL', 'alpha');
$res = dolibarr_set_const($db, 'TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL', $param_public_notification_new_message_default_email, 'chaine', 0, '', $conf->entity);
if (!$res > 0) {
$error++;
}
}
if ($action == 'setvarother') {
@ -377,7 +383,31 @@ if (!empty($conf->global->TICKET_ENABLE_PUBLIC_INTERFACE))
print $form->textwithpicto('', $langs->trans("TicketUrlPublicInterfaceHelpAdmin"), 1, 'help');
print '</td></tr>';
print '</table>';
// Activate email notification when a new message is added
print '<tr class="pair"><td>' . $langs->trans("TicketsPublicNotificationNewMessage") . '</td>';
print '<td class="left">';
if ($conf->use_javascript_ajax) {
print ajax_constantonoff('TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_ENABLED');
} else {
$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
print $form->selectarray("TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_ENABLED", $arrval, $conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_ENABLED);
}
print '</td>';
print '<td align="center">';
print $form->textwithpicto('', $langs->trans("TicketsPublicNotificationNewMessageHelp"), 1, 'help');
print '</td>';
print '</tr>';
// Send notification when a new message is added to a email if a user is not assigned to the ticket
print '<tr><td>' . $langs->trans("TicketPublicNotificationNewMessageDefaultEmail") . '</label>';
print '</td><td>';
print '<input type="text" name="TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL" value="' . $conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL . '" size="40" ></td>';
print '</td>';
print '<td align="center">';
print $form->textwithpicto('', $langs->trans("TicketPublicNotificationNewMessageDefaultEmailHelp"), 1, 'help');
print '</td></tr>';
print '</table>';
print '</div>';
print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Save").'"></div>';

View File

@ -90,6 +90,15 @@ $status = GETPOST("search_status", 'aZ09') ?GETPOST("search_status", 'aZ09') : G
$type = GETPOST("search_type", 'aZ09') ?GETPOST("search_type", 'aZ09') : GETPOST("type", 'aZ09');
$maxprint = (isset($_GET["maxprint"]) ?GETPOST("maxprint") : $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW);
$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
$dateselect=dol_mktime(0, 0, 0, GETPOST('dateselectmonth', 'int'), GETPOST('dateselectday', 'int'), GETPOST('dateselectyear', 'int'));
if ($dateselect > 0)
{
$day=GETPOST('dateselectday', 'int');
$month=GETPOST('dateselectmonth', 'int');
$year=GETPOST('dateselectyear', 'int');
}
// Set actioncode (this code must be same for setting actioncode into peruser, listacton and index)
if (GETPOST('search_actioncode', 'array'))
{
@ -371,6 +380,9 @@ if ($action == 'show_day')
$picto = 'calendarday';
}
$nav .= $form->selectDate($dateselect, 'dateselect', 0, 0, 1, '', 1, 0);
$nav .= ' <input type="submit" name="submitdateselect" class="button" value="'.$langs->trans("Refresh").'">';
// Must be after the nav definition
$param .= '&year='.$year.'&month='.$month.($day ? '&day='.$day : '');
//print 'x'.$param;

View File

@ -52,6 +52,7 @@ $year = GETPOST("year", 'int');
$month = GETPOST("month", 'int');
$day = GETPOST("day", 'int');
$toselect = GETPOST('toselect', 'array');
$confirm = GETPOST('confirm', 'alpha');
// Set actioncode (this code must be same for setting actioncode into peruser, listacton and index)
if (GETPOST('search_actioncode', 'array'))
@ -156,6 +157,11 @@ $arrayfields = dol_sort_array($arrayfields, 'position');
* Actions
*/
if (GETPOST('cancel', 'alpha'))
{
$action='list'; $massaction='';
}
if (GETPOST("viewcal") || GETPOST("viewweek") || GETPOST("viewday"))
{
$param = '';
@ -224,6 +230,17 @@ if (empty($reshook) && !empty($massaction))
}
}
// As mass deletion happens with a confirm step, $massaction is not use for the final step (deletion).
if (empty($reshook))
{
$objectclass = 'ActionComm';
$objectlabel = 'Events';
$uploaddir = true;
// Only users that can delete any event can remove records.
$permissiontodelete = $user->rights->agenda->allactions->delete;
include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
}
/*
* View
*/
@ -280,6 +297,10 @@ $arrayofmassactions = array(
'set_all_events_to_in_progress' => $langs->trans("SetAllEventsToInProgress"),
'set_all_events_to_finished' => $langs->trans("SetAllEventsToFinished"),
);
if ($user->rights->agenda->allactions->delete)
{
$arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
}
$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
@ -477,6 +498,8 @@ if ($resql)
print_barre_liste($s, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, -1 * $nbtotalofrecords, '', 0, $nav.$newcardbutton, '', $limit, 0, 0, 1);
include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
$moreforfilter = '';
$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;

View File

@ -46,7 +46,7 @@ if (empty($objectclass) || empty($uploaddir))
// For backward compatibility
if (!empty($permtoread) && empty($permissiontoread)) $permissiontoread = $permtoread;
if (!empty($permtocreate) && empty($permissiontoadd)) $permissiontoadd = $permtocreate;
if (!empty($permtodelete) && empty($permissiontodelete)) $permissiontoread = $permtodelete;
if (!empty($permtodelete) && empty($permissiontodelete)) $permissiontodelete = $permtodelete;
// Mass actions. Controls on number of lines checked.

View File

@ -262,6 +262,7 @@ ALTER TABLE llx_commande_fournisseur_dispatch MODIFY COLUMN batch varchar(128);
ALTER TABLE llx_stock_mouvement MODIFY COLUMN batch varchar(128);
ALTER TABLE llx_mrp_production MODIFY COLUMN batch varchar(128);
ALTER TABLE llx_mrp_production MODIFY qty real NOT NULL DEFAULT 1;
ALTER TABLE llx_expeditiondet_batch MODIFY COLUMN batch varchar(128);
create table llx_categorie_website_page
(

View File

@ -130,6 +130,10 @@ TicketNumberingModules=Tickets numbering module
TicketNotifyTiersAtCreation=Notify third party at creation
TicketGroup=Group
TicketsDisableCustomerEmail=Always disable emails when a ticket is created from public interface
TicketsPublicNotificationNewMessage=Send email(s) when a new message is added
TicketsPublicNotificationNewMessageHelp=Send email(s) when a new message is added from public interface (to assigned user or the notifications email to (update) and/or the notifications email to)
TicketPublicNotificationNewMessageDefaultEmail=Notifications email to (update)
TicketPublicNotificationNewMessageDefaultEmailHelp=Send email new message notifications to this address if the ticket don't have a user assigned or the user don't have a email.
#
# Index & list page
#

View File

@ -130,6 +130,10 @@ TicketNumberingModules=Module de numérotation des tickets
TicketNotifyTiersAtCreation=Notifier le tiers à la création
TicketGroup=Groupe
TicketsDisableCustomerEmail=Toujours désactiver les courriels lorsqu'un ticket est créé depuis l'interface publique
TicketsPublicNotificationNewMessage=Envoi d'e-mails lorsqu'un nouveau message est ajouté
TicketsPublicNotificationNewMessageHelp=Envoi d'e-mails lorsqu'un nouveau message est ajouté depuis l'interface public (à l'utilisateur assigné ou à l'e-mail de notification à (nouveaux message) et/ou l'e-mail de notification à)
TicketPublicNotificationNewMessageDefaultEmail=E-mail de notification à (nouveaux message)
TicketPublicNotificationNewMessageDefaultEmailHelp=Envoyer des notifications de nouveaux message par e-mail à cette adresse si aucun utilisateur n'a été affecté au ticket ou qu'il n'a pas d'e-mail.
#
# Index & list page
#

View File

@ -39,8 +39,10 @@ $hookmanager->initHooks(array('projectsindex'));
// Load translation files required by the page
$langs->loadLangs(array('projects', 'companies'));
$action = GETPOST('action', 'alpha');
$search_project_user = GETPOST('search_project_user', 'int');
$mine = GETPOST('mode', 'aZ09') == 'mine' ? 1 : 0;
if ($mine == 0 && $search_project_user === '') $search_project_user = $user->conf->MAIN_SEARCH_PROJECT_USER_PROJECTSINDEX;
if ($search_project_user == $user->id) $mine = 1;
// Security check
@ -54,6 +56,24 @@ $sortorder = GETPOST("sortorder", 'alpha');
$max = 3;
/*
* Actions
*/
$parameters = array();
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if (empty($reshook)) {
if ($action == 'refresh_search_project_user') {
$search_project_user = GETPOST('search_project_user', 'int');
$tabparam = array("MAIN_SEARCH_PROJECT_USER_PROJECTSINDEX" => $search_project_user);
include_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
$result = dol_set_user_param($db, $conf, $user, $tabparam);
}
}
/*
* View
*/
@ -81,6 +101,7 @@ else $titleall = $langs->trans("AllAllowedProjects").'<br><br>';
$morehtml = '';
$morehtml .= '<form name="projectform" method="POST">';
$morehtml .= '<input type="hidden" name="token" value="'.newToken().'">';
$morehtml .= '<input type="hidden" name="action" value="refresh_search_project_user">';
$morehtml .= '<SELECT name="search_project_user">';
$morehtml .= '<option name="all" value="0"'.($mine ? '' : ' selected').'>'.$titleall.'</option>';
$morehtml .= '<option name="mine" value="'.$user->id.'"'.(($search_project_user == $user->id) ? ' selected' : '').'>'.$langs->trans("ProjectsImContactFor").'</option>';

View File

@ -171,7 +171,7 @@ if ($action == "view_ticket" || $action == "presend" || $action == "close" || $a
if (!$error && $action == "add_message" && $display_ticket && GETPOSTISSET('btn_add_message'))
{
// TODO Add message...
$ret = $object->dao->newMessage($user, $action, 0);
$ret = $object->dao->newMessage($user, $action, 0, 1);

View File

@ -2391,14 +2391,15 @@ class Ticket extends CommonObject
/**
* Add new message on a ticket (private area). Can also send it be email if GETPOST('send_email', 'int') is set.
* Add new message on a ticket (private/public area). Can also send it be email if GETPOST('send_email', 'int') is set.
*
* @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 ?
* @param int $public_area 1=Is the public area
* @return int
*/
public function newMessage($user, &$action, $private = 1)
public function newMessage($user, &$action, $private = 1, $public_area = 0)
{
global $mysoc, $conf, $langs;
@ -2451,142 +2452,215 @@ class Ticket extends CommonObject
//var_dump($_SESSION); var_dump($listofpaths);exit;
/*
* Send emails to internal users (linked contacts)
*/
if ($send_email > 0) {
// Retrieve internal contact datas
$internal_contacts = $object->getInfosTicketInternalContact();
$sendto = array();
if (is_array($internal_contacts) && count($internal_contacts) > 0) {
// altairis: set default subject
$label_title = empty($conf->global->MAIN_APPLICATION_TITLE) ? $mysoc->name : $conf->global->MAIN_APPLICATION_TITLE;
$subject = GETPOST('subject', 'nohtml') ? GETPOST('subject', 'nohtml') : '['.$label_title.'- ticket #'.$object->track_id.'] '.$langs->trans('TicketNewMessage');
$message_intro = $langs->trans('TicketNotificationEmailBody', "#".$object->id);
$message_signature = GETPOST('mail_signature') ? GETPOST('mail_signature') : $conf->global->TICKET_MESSAGE_MAIL_SIGNATURE;
$message = $langs->trans('TicketMessageMailIntroText');
$message .= "\n\n";
$message .= GETPOST('message', 'restricthtml');
// Coordonnées client
$message .= "\n\n";
$message .= "==============================================\n";
$message .= !empty($object->thirdparty->name) ? $langs->trans('Thirdparty')." : ".$object->thirdparty->name : '';
$message .= !empty($object->thirdparty->town) ? "\n".$langs->trans('Town')." : ".$object->thirdparty->town : '';
$message .= !empty($object->thirdparty->phone) ? "\n".$langs->trans('Phone')." : ".$object->thirdparty->phone : '';
// Build array to display recipient list
foreach ($internal_contacts as $key => $info_sendto) {
// altairis: avoid duplicate notifications
if ($info_sendto['id'] == $user->id) {
continue;
}
if ($info_sendto['email'] != '') {
if (!empty($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" : '');
* Public area
*/
if (!empty($public_area)) {
/*
* Send emails to assigned users (public area notification)
*/
if (!empty($conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_ENABLED)) {
$assigned_user_dont_have_email = '';
$sendto = array();
if ($this->fk_user_assign > 0) {
$assigned_user = new User($this->db);
$assigned_user->fetch($this->fk_user_assign);
if (!empty($assigned_user->email)) {
$sendto[] = $assigned_user->getFullName($langs) . " <" . $assigned_user->email . ">";
} else {
$assigned_user_dont_have_email = $assigned_user->getFullName($langs);
}
}
if (empty($sendto)) {
if (!empty($conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL)) {
$sendto[] = $conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL;
} elseif (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO)) {
$sendto[] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
}
}
$message .= "\n";
// URL ticket
$url_internal_ticket = dol_buildpath('/ticket/card.php', 2).'?track_id='.$object->track_id;
// altairis: make html link on url
$message .= "\n".$langs->trans('TicketNotificationEmailBodyInfosTrackUrlinternal').' : <a href="'.$url_internal_ticket.'">'.$object->track_id.'</a>'."\n";
// Add global email address recipient
if ($conf->global->TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS && !in_array($conf->global->TICKET_NOTIFICATION_EMAIL_TO, $sendto)) {
if (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO)) $sendto[] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
if (!empty($conf->global->TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS) &&
!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) && !in_array($conf->global->TICKET_NOTIFICATION_EMAIL_TO, $sendto)
) {
$sendto[] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
}
// altairis: dont try to send email if no recipient
if (!empty($sendto)) {
$label_title = empty($conf->global->MAIN_APPLICATION_TITLE) ? $mysoc->name : $conf->global->MAIN_APPLICATION_TITLE;
$subject = '[' . $label_title . '- ticket #' . $object->track_id . '] ' . $langs->trans('TicketNewMessage');
// Message send
$message = $langs->trans('TicketMessageMailIntroText');
$message .= "\n\n";
$message .= GETPOST('message', 'restricthtml');
// Customer company infos
$message .= "\n\n";
$message .= "==============================================";
$message .= !empty($object->thirdparty->name) ? "\n" . $langs->trans('Thirdparty') . " : " . $object->thirdparty->name : '';
$message .= !empty($object->thirdparty->town) ? "\n" . $langs->trans('Town') . " : " . $object->thirdparty->town : '';
$message .= !empty($object->thirdparty->phone) ? "\n" . $langs->trans('Phone') . " : " . $object->thirdparty->phone : '';
// Email send to
$message .= "\n\n";
if (!empty($assigned_user_dont_have_email)) {
$message .= "\n" . $langs->trans('NoEMail') . ' : ' . $assigned_user_dont_have_email;
}
foreach ($sendto as $val) {
$message .= "\n" . $langs->trans('TicketNotificationRecipient') . ' : ' . $val;
}
// URL ticket
$url_internal_ticket = dol_buildpath('/ticket/card.php', 2) . '?track_id=' . $object->track_id;
$message .= "\n\n";
$message .= $langs->trans('TicketNotificationEmailBodyInfosTrackUrlinternal') . ' : <a href="' . $url_internal_ticket . '">' . $object->track_id . '</a>';
$this->sendTicketMessageByEmail($subject, $message, '', $sendto, $listofpaths, $listofmimes, $listofnames);
}
}
}
/*
* Private area
*/
else {
/*
* Send emails for externals users if not private (linked contacts)
*/
if (empty($object->private)) {
// Retrieve email of all contacts (external)
$external_contacts = $object->getInfosTicketExternalContact();
// If no contact, get email from thirdparty
if (is_array($external_contacts) && count($external_contacts) === 0) {
if (!empty($object->fk_soc)) {
$object->fetch_thirdparty($object->fk_soc);
$array_company = array(array('firstname' => '', 'lastname' => $object->thirdparty->name, 'email' => $object->thirdparty->email, 'libelle' => $langs->transnoentities('Customer'), 'socid' => $object->thirdparty->id));
$external_contacts = array_merge($external_contacts, $array_company);
} elseif (empty($object->fk_soc) && !empty($object->origin_email)) {
$array_external = array(array('firstname' => '', 'lastname' => $object->origin_email, 'email' => $object->thirdparty->email, 'libelle' => $langs->transnoentities('Customer'), 'socid' => $object->thirdparty->id));
$external_contacts = array_merge($external_contacts, $array_external);
}
}
* Send emails to internal users (linked contacts)
*/
if ($send_email > 0) {
// Retrieve internal contact datas
$internal_contacts = $object->getInfosTicketInternalContact();
$sendto = array();
if (is_array($external_contacts) && count($external_contacts) > 0) {
// altairis: get default subject for email to external contacts
if (is_array($internal_contacts) && count($internal_contacts) > 0) {
// altairis: set default subject
$label_title = empty($conf->global->MAIN_APPLICATION_TITLE) ? $mysoc->name : $conf->global->MAIN_APPLICATION_TITLE;
$subject = GETPOST('subject') ? GETPOST('subject') : '['.$label_title.'- ticket #'.$object->track_id.'] '.$langs->trans('TicketNewMessage');
$subject = GETPOST('subject', 'nohtml') ? GETPOST('subject', 'nohtml') : '[' . $label_title . '- ticket #' . $object->track_id . '] ' . $langs->trans('TicketNewMessage');
$message_intro = GETPOST('mail_intro') ? GETPOST('mail_intro') : $conf->global->TICKET_MESSAGE_MAIL_INTRO;
$message_intro = $langs->trans('TicketNotificationEmailBody', "#" . $object->id);
$message_signature = GETPOST('mail_signature') ? GETPOST('mail_signature') : $conf->global->TICKET_MESSAGE_MAIL_SIGNATURE;
// We put intro after
$message = GETPOST('message');
$message = $langs->trans('TicketMessageMailIntroText');
$message .= "\n\n";
$message .= GETPOST('message', 'restricthtml');
foreach ($external_contacts as $key => $info_sendto) {
// altairis: avoid duplicate emails to external contacts
if ($info_sendto['id'] == $user->contactid) {
// Coordonnées client
$message .= "\n\n";
$message .= "==============================================\n";
$message .= !empty($object->thirdparty->name) ? $langs->trans('Thirdparty') . " : " . $object->thirdparty->name : '';
$message .= !empty($object->thirdparty->town) ? "\n" . $langs->trans('Town') . " : " . $object->thirdparty->town : '';
$message .= !empty($object->thirdparty->phone) ? "\n" . $langs->trans('Phone') . " : " . $object->thirdparty->phone : '';
// Build array to display recipient list
foreach ($internal_contacts as $key => $info_sendto) {
// altairis: avoid duplicate notifications
if ($info_sendto['id'] == $user->id) {
continue;
}
if ($info_sendto['email'] != '' && $info_sendto['email'] != $object->origin_email) {
if (!empty($info_sendto['email'])) $sendto[] = trim($info_sendto['firstname']." ".$info_sendto['lastname'])." <".$info_sendto['email'].">";
if ($info_sendto['email'] != '') {
if (!empty($info_sendto['email'])) $sendto[] = trim($info_sendto['firstname'] . " " . $info_sendto['lastname']) . " <" . $info_sendto['email'] . ">";
$recipient = dolGetFirstLastname($info_sendto['firstname'], $info_sendto['lastname'], '-1').' ('.strtolower($info_sendto['libelle']).')';
$message .= (!empty($recipient) ? $langs->trans('TicketNotificationRecipient').' : '.$recipient."\n" : '');
//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;
// If public interface is not enable, use link to internal page into mail
$url_public_ticket = (!empty($conf->global->TICKET_ENABLE_PUBLIC_INTERFACE) ?
(!empty($conf->global->TICKET_URL_PUBLIC_INTERFACE) ? $conf->global->TICKET_URL_PUBLIC_INTERFACE.'/view.php' : dol_buildpath('/public/ticket/view.php', 2)) : dol_buildpath('/ticket/card.php', 2)).'?track_id='.$object->track_id;
$message .= "\n".$langs->trans('TicketNewEmailBodyInfosTrackUrlCustomer').' : <a href="'.$url_public_ticket.'">'.$object->track_id.'</a>'."\n";
// altairis: make html link on url
$message .= "\n" . $langs->trans('TicketNotificationEmailBodyInfosTrackUrlinternal') . ' : <a href="' . $url_internal_ticket . '">' . $object->track_id . '</a>' . "\n";
// Build final message
$message = $message_intro.$message;
// Add signature
$message .= '<br>'.$message_signature;
if (!empty($object->origin_email)) {
$sendto[] = $object->origin_email;
}
if ($object->fk_soc > 0 && !in_array($object->origin_email, $sendto)) {
$object->socid = $object->fk_soc;
$object->fetch_thirdparty();
if (!empty($object->thirdparty->email)) $sendto[] = $object->thirdparty->email;
}
// altairis: Add global email address reciepient
// Add global email address recipient
if ($conf->global->TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS && !in_array($conf->global->TICKET_NOTIFICATION_EMAIL_TO, $sendto)) {
if (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO)) $sendto[] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
}
// altairis: dont try to send email when no recipient
// altairis: dont try to send email if no recipient
if (!empty($sendto)) {
$this->sendTicketMessageByEmail($subject, $message, '', $sendto, $listofpaths, $listofmimes, $listofnames);
}
}
/*
* Send emails for externals users if not private (linked contacts)
*/
if (empty($object->private)) {
// Retrieve email of all contacts (external)
$external_contacts = $object->getInfosTicketExternalContact();
// If no contact, get email from thirdparty
if (is_array($external_contacts) && count($external_contacts) === 0) {
if (!empty($object->fk_soc)) {
$object->fetch_thirdparty($object->fk_soc);
$array_company = array(array('firstname' => '', 'lastname' => $object->thirdparty->name, 'email' => $object->thirdparty->email, 'libelle' => $langs->transnoentities('Customer'), 'socid' => $object->thirdparty->id));
$external_contacts = array_merge($external_contacts, $array_company);
} elseif (empty($object->fk_soc) && !empty($object->origin_email)) {
$array_external = array(array('firstname' => '', 'lastname' => $object->origin_email, 'email' => $object->thirdparty->email, 'libelle' => $langs->transnoentities('Customer'), 'socid' => $object->thirdparty->id));
$external_contacts = array_merge($external_contacts, $array_external);
}
}
$sendto = array();
if (is_array($external_contacts) && count($external_contacts) > 0) {
// altairis: get default subject for email to external contacts
$label_title = empty($conf->global->MAIN_APPLICATION_TITLE) ? $mysoc->name : $conf->global->MAIN_APPLICATION_TITLE;
$subject = GETPOST('subject') ? GETPOST('subject') : '[' . $label_title . '- ticket #' . $object->track_id . '] ' . $langs->trans('TicketNewMessage');
$message_intro = GETPOST('mail_intro') ? GETPOST('mail_intro') : $conf->global->TICKET_MESSAGE_MAIL_INTRO;
$message_signature = GETPOST('mail_signature') ? GETPOST('mail_signature') : $conf->global->TICKET_MESSAGE_MAIL_SIGNATURE;
// We put intro after
$message = GETPOST('message');
$message .= "\n\n";
foreach ($external_contacts as $key => $info_sendto) {
// altairis: avoid duplicate emails to external contacts
if ($info_sendto['id'] == $user->contactid) {
continue;
}
if ($info_sendto['email'] != '' && $info_sendto['email'] != $object->origin_email) {
if (!empty($info_sendto['email'])) $sendto[] = trim($info_sendto['firstname'] . " " . $info_sendto['lastname']) . " <" . $info_sendto['email'] . ">";
$recipient = dolGetFirstLastname($info_sendto['firstname'], $info_sendto['lastname'], '-1') . ' (' . strtolower($info_sendto['libelle']) . ')';
$message .= (!empty($recipient) ? $langs->trans('TicketNotificationRecipient') . ' : ' . $recipient . "\n" : '');
}
}
// If public interface is not enable, use link to internal page into mail
$url_public_ticket = (!empty($conf->global->TICKET_ENABLE_PUBLIC_INTERFACE) ?
(!empty($conf->global->TICKET_URL_PUBLIC_INTERFACE) ? $conf->global->TICKET_URL_PUBLIC_INTERFACE . '/view.php' : dol_buildpath('/public/ticket/view.php', 2)) : dol_buildpath('/ticket/card.php', 2)) . '?track_id=' . $object->track_id;
$message .= "\n" . $langs->trans('TicketNewEmailBodyInfosTrackUrlCustomer') . ' : <a href="' . $url_public_ticket . '">' . $object->track_id . '</a>' . "\n";
// Build final message
$message = $message_intro . $message;
// Add signature
$message .= '<br>' . $message_signature;
if (!empty($object->origin_email)) {
$sendto[] = $object->origin_email;
}
if ($object->fk_soc > 0 && !in_array($object->origin_email, $sendto)) {
$object->socid = $object->fk_soc;
$object->fetch_thirdparty();
if (!empty($object->thirdparty->email)) $sendto[] = $object->thirdparty->email;
}
// altairis: Add global email address reciepient
if ($conf->global->TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS && !in_array($conf->global->TICKET_NOTIFICATION_EMAIL_TO, $sendto)) {
if (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO)) $sendto[] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
}
// altairis: dont try to send email when no recipient
if (!empty($sendto)) {
$this->sendTicketMessageByEmail($subject, $message, '', $sendto, $listofpaths, $listofmimes, $listofnames);
}
}
}
}
}