From 021fb83ec60dce561dea94179fcacd23121bbb25 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 3 Feb 2024 17:57:12 +0100 Subject: [PATCH] WIP SMSing --- htdocs/comm/mailing/advtargetemailing.php | 2 +- htdocs/comm/mailing/card.php | 252 ++++++++++++-------- htdocs/comm/mailing/cibles.php | 68 +++--- htdocs/comm/mailing/class/mailing.class.php | 85 +++---- htdocs/comm/mailing/info.php | 2 +- htdocs/comm/mailing/list.php | 65 ++++- htdocs/comm/mailing/note.php | 2 +- htdocs/core/class/CSMSFile.class.php | 18 +- htdocs/langs/en_US/admin.lang | 2 +- htdocs/langs/en_US/mails.lang | 4 +- 10 files changed, 296 insertions(+), 204 deletions(-) diff --git a/htdocs/comm/mailing/advtargetemailing.php b/htdocs/comm/mailing/advtargetemailing.php index fa08d145abf..73fc1826706 100644 --- a/htdocs/comm/mailing/advtargetemailing.php +++ b/htdocs/comm/mailing/advtargetemailing.php @@ -459,7 +459,7 @@ if ($object->fetch($id) >= 0) { print ""; // Show email selectors - if ($object->statut == 0 && $user->hasRight('mailing', 'creer')) { + if ($object->status == 0 && $user->hasRight('mailing', 'creer')) { include DOL_DOCUMENT_ROOT.'/core/tpl/advtarget.tpl.php'; } } diff --git a/htdocs/comm/mailing/card.php b/htdocs/comm/mailing/card.php index 3595296fec3..323cb20e90d 100644 --- a/htdocs/comm/mailing/card.php +++ b/htdocs/comm/mailing/card.php @@ -162,7 +162,7 @@ if (empty($reshook)) { setEventMessages($langs->trans("NotEnoughPermissions"), null, 'warnings'); $action = ''; } else { - if ($object->statut == 0) { + if ($object->status == 0) { dol_print_error(null, 'ErrorMailIsNotValidated'); exit; } @@ -547,6 +547,7 @@ if (empty($reshook)) { if ($action == 'add') { $mesgs = array(); + $object->messtype = (string) GETPOST("messtype"); $object->email_from = (string) GETPOST("from", 'alphawithlgt'); // Must allow 'name ' $object->email_replyto = (string) GETPOST("replyto", 'alphawithlgt'); // Must allow 'name ' $object->email_errorsto = (string) GETPOST("errorsto", 'alphawithlgt'); // Must allow 'name ' @@ -559,7 +560,7 @@ if (empty($reshook)) { if (!$object->title) { $mesgs[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailTitle")); } - if (!$object->sujet) { + if ($object->messtype != 'sms' && !$object->sujet) { $mesgs[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailTopic")); } if (!$object->body) { @@ -645,12 +646,14 @@ if (empty($reshook)) { if (!$isupload) { $mesgs = array(); + + //$object->messtype = (string) GETPOST("messtype"); // We must not be able to change the messtype $object->sujet = (string) GETPOST("sujet"); $object->body = (string) GETPOST("bodyemail", 'restricthtml'); $object->bgcolor = preg_replace('/^#/', '', (string) GETPOST("bgcolor")); $object->bgimage = (string) GETPOST("bgimage"); - if (!$object->sujet) { + if ($object->messtype != 'sms' && !$object->sujet) { $mesgs[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailTopic")); } if (!$object->body) { @@ -777,7 +780,7 @@ if ($action == 'create') { $htmltext .= ''; - $availablelink = $form->textwithpicto(''.$langs->trans("AvailableVariables").'', $htmltext, 1, 'help', '', 0, 2, 'availvar'); + $availablelink = $form->textwithpicto(''.$langs->trans("AvailableVariables").'', $htmltext, 1, 'helpclickable', '', 0, 2, 'availvar'); //print ''.img_picto($langs->trans("ClickToShowDescription"), $imginfo).''; @@ -790,9 +793,40 @@ if ($action == 'create') { print ''.$langs->trans("MailTitle").''; - print ''.$langs->trans("MailFrom").''; + if (getDolGlobalInt('EMAILINGS_SUPPORT_ALSO_SMS')) { + $arrayoftypes = array("email" => "Email", "sms" => "SMS"); + print ''.$langs->trans("Type").''; + print $form->selectarray('messtype', $arrayoftypes, (GETPOSTISSET('messtype') ? GETPOST('messtype') : 'email'), 0, 0); - print ''.$langs->trans("MailErrorsTo").''; + print ''; + + print ''; + } + print ''; + + print '

'; + + print ''; + + print ''; + print ''; + + print ''; // Other attributes $parameters = array(); @@ -806,8 +840,8 @@ if ($action == 'create') { print '

'; print '
'.$langs->trans("MailFrom").'
'.$langs->trans("MailErrorsTo").'
'; - print ''; - print ''; + print ''; @@ -822,7 +856,7 @@ if ($action == 'create') { print dol_get_fiche_end(); - print $form->buttonsSaveCancel("CreateMailing", 'Cancel'); + print $form->buttonsSaveCancel("Create", 'Cancel'); print ''; } else { @@ -845,7 +879,7 @@ if ($action == 'create') { print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id.(!empty($urlfrom) ? '&urlfrom='.urlencode($urlfrom) : ''), $langs->trans("DeleteAMailing"), $langs->trans("ConfirmDeleteMailing"), "confirm_delete", '', '', 1); } - if ($action != 'edit' && $action != 'edithtml') { + if ($action != 'edit' && $action != 'edittxt' &&$action != 'edithtml') { print dol_get_fiche_head($head, 'card', $langs->trans("Mailing"), -1, 'email'); /* @@ -934,7 +968,7 @@ if ($action == 'create') { $morehtmlright = ''; $nbtry = $nbok = 0; - if ($object->statut == 2 || $object->statut == 3) { + if ($object->status == 2 || $object->status == 3) { $nbtry = $object->countNbOfTargets('alreadysent'); $nbko = $object->countNbOfTargets('alreadysentko'); @@ -954,9 +988,9 @@ if ($action == 'create') { // From print ''; // Errors to - print ''; } - print ''; print '
'.$langs->trans("MailTopic").'
'.$langs->trans("BackgroundColorByDefault").''; + print '
'.$langs->trans("MailTopic").'
'.$langs->trans("BackgroundColorByDefault").''; print $htmlother->selectColor(GETPOST('bgcolor'), 'bgcolor', '', 0); print '
'; - print $form->editfieldkey("MailFrom", 'email_from', $object->email_from, $object, $user->hasRight('mailing', 'creer') && $object->statut < 3, 'string'); + print $form->editfieldkey("MailFrom", 'email_from', $object->email_from, $object, $user->hasRight('mailing', 'creer') && $object->status < 3, 'string'); print ''; - print $form->editfieldval("MailFrom", 'email_from', $object->email_from, $object, $user->hasRight('mailing', 'creer') && $object->statut < 3, 'string'); + print $form->editfieldval("MailFrom", 'email_from', $object->email_from, $object, $user->hasRight('mailing', 'creer') && $object->status < 3, 'string'); $email = CMailFile::getValidAddress($object->email_from, 2); if ($email && !isValidEmail($email)) { $langs->load("errors"); @@ -969,19 +1003,21 @@ if ($action == 'create') { print '
'; - print $form->editfieldkey("MailErrorsTo", 'email_errorsto', $object->email_errorsto, $object, $user->hasRight('mailing', 'creer') && $object->statut < 3, 'string'); - print ''; - print $form->editfieldval("MailErrorsTo", 'email_errorsto', $object->email_errorsto, $object, $user->hasRight('mailing', 'creer') && $object->statut < 3, 'string'); - $email = CMailFile::getValidAddress($object->email_errorsto, 2); - if ($email && !isValidEmail($email)) { - $langs->load("errors"); - print img_warning($langs->trans("ErrorBadEMail", $email)); - } elseif ($email && !isValidMailDomain($email)) { - $langs->load("errors"); - print img_warning($langs->trans("ErrorBadMXDomain", $email)); + if ($object->messtype != 'sms') { + print '
'; + print $form->editfieldkey("MailErrorsTo", 'email_errorsto', $object->email_errorsto, $object, $user->hasRight('mailing', 'creer') && $object->status < 3, 'string'); + print ''; + print $form->editfieldval("MailErrorsTo", 'email_errorsto', $object->email_errorsto, $object, $user->hasRight('mailing', 'creer') && $object->status < 3, 'string'); + $email = CMailFile::getValidAddress($object->email_errorsto, 2); + if ($email && !isValidEmail($email)) { + $langs->load("errors"); + print img_warning($langs->trans("ErrorBadEMail", $email)); + } elseif ($email && !isValidMailDomain($email)) { + $langs->load("errors"); + print img_warning($langs->trans("ErrorBadMXDomain", $email)); + } + print '
'; print ''; @@ -992,13 +1028,13 @@ if ($action == 'create') { print ''; // Number of distinct emails - print ''; // Errors to - print ''; } - print ''; print '
'; + print '
'; print $langs->trans("TotalNbOfDistinctRecipients"); print ''; $nbemail = ($object->nbemail ? $object->nbemail : 0); if (is_numeric($nbemail)) { $text = ''; - if ((getDolGlobalString('MAILING_LIMIT_SENDBYWEB') && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->statut == 1 || ($object->statut == 2 && $nbtry < $nbemail))) { + if ((getDolGlobalString('MAILING_LIMIT_SENDBYWEB') && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->status == 1 || ($object->status == 2 && $nbtry < $nbemail))) { if (getDolGlobalInt('MAILING_LIMIT_SENDBYWEB') > 0) { $text .= $langs->trans('LimitSendingEmailing', getDolGlobalString('MAILING_LIMIT_SENDBYWEB')); } else { @@ -1064,19 +1100,21 @@ if ($action == 'create') { if (GETPOST('cancel', 'alpha') || $confirm == 'no' || $action == '' || in_array($action, array('settodraft', 'valid', 'delete', 'sendall', 'clone', 'test', 'editevenunsubscribe'))) { print "\n\n
\n"; - if (($object->statut == 1) && ($user->hasRight('mailing', 'valider') || $object->user_validation_id == $user->id)) { + if (($object->status == 1) && ($user->hasRight('mailing', 'valider') || $object->user_validation_id == $user->id)) { print ''.$langs->trans("SetToDraft").''; } - if (($object->statut == 0 || $object->statut == 1 || $object->statut == 2) && $user->hasRight('mailing', 'creer')) { - if (isModEnabled('fckeditor') && getDolGlobalString('FCKEDITOR_ENABLE_MAILING')) { + if (($object->status == 0 || $object->status == 1 || $object->status == 2) && $user->hasRight('mailing', 'creer')) { + if (isModEnabled('fckeditor') && getDolGlobalString('FCKEDITOR_ENABLE_MAILING') && $object->messtype != 'sms') { print ''.$langs->trans("EditWithEditor").''; } else { - print ''.$langs->trans("EditWithTextEditor").''; + print ''.$langs->trans("EditWithTextEditor").''; } - if (!empty($conf->use_javascript_ajax)) { - print ''.$langs->trans("EditHTMLSource").''; + if (!getDolGlobalInt('EMAILINGS_SUPPORT_ALSO_SMS')) { + if (!empty($conf->use_javascript_ajax)) { + print ''.$langs->trans("EditHTMLSource").''; + } } } @@ -1088,17 +1126,17 @@ if ($action == 'create') { print ''.$langs->trans("TestMailing").''; } - if ($object->statut == 0) { + if ($object->status == 0) { if ($object->nbemail <= 0) { - print ''.$langs->trans("ValidMailing").''; + print ''.$langs->trans("Validate").''; } elseif (!$user->hasRight('mailing', 'valider')) { - print ''.$langs->trans("ValidMailing").''; + print ''.$langs->trans("Validate").''; } else { - print ''.$langs->trans("ValidMailing").''; + print ''.$langs->trans("Validate").''; } } - if (($object->statut == 1 || $object->statut == 2) && $object->nbemail > 0 && $user->hasRight('mailing', 'valider')) { + if (($object->status == 1 || $object->status == 2) && $object->nbemail > 0 && $user->hasRight('mailing', 'valider')) { if (getDolGlobalInt('MAILING_LIMIT_SENDBYWEB') < 0) { print ''.$langs->trans("SendMailing").''; } elseif (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('mailing', 'mailing_advance', 'send')) { @@ -1112,7 +1150,7 @@ if ($action == 'create') { print ''.$langs->trans("ToClone").''; } - if (($object->statut == 2 || $object->statut == 3) && $user->hasRight('mailing', 'valider')) { + if (($object->status == 2 || $object->status == 3) && $user->hasRight('mailing', 'valider')) { if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('mailing', 'mailing_advance', 'send')) { print ''.$langs->trans("ResetMailing").''; } else { @@ -1120,11 +1158,11 @@ if ($action == 'create') { } } - if (($object->statut <= 1 && $user->hasRight('mailing', 'creer')) || $user->hasRight('mailing', 'supprimer')) { - if ($object->statut > 0 && (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('mailing', 'mailing_advance', 'delete'))) { - print ''.$langs->trans("DeleteMailing").''; + if (($object->status <= 1 && $user->hasRight('mailing', 'creer')) || $user->hasRight('mailing', 'supprimer')) { + if ($object->status > 0 && (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('mailing', 'mailing_advance', 'delete'))) { + print ''.$langs->trans("Delete").''; } else { - print ''.$langs->trans("DeleteMailing").''; + print ''.$langs->trans("Delete").''; } } @@ -1187,21 +1225,25 @@ if ($action == 'create') { print ''; // Subject - print ''; + if ($object->messtype != 'sms') { + print ''; + } // Joined files - print ''; } - print ''; // Background color /*print ''; + print ''; // To - print ''; + if ($object->messtype != 'sms') { + print ''; + } print '
'.$langs->trans("MailTopic").''.$object->sujet.'
'.$langs->trans("MailTopic").''.$object->sujet.'
'.$langs->trans("MailFile").''; - // List of files - $listofpaths = dol_dir_list($upload_dir, 'all', 0, '', '', 'name', SORT_ASC, 0); - if (count($listofpaths)) { - foreach ($listofpaths as $key => $val) { - print img_mime($listofpaths[$key]['name']).' '.$listofpaths[$key]['name']; - print '
'; + if ($object->messtype != 'sms') { + print '
'.$langs->trans("MailFile").''; + // List of files + $listofpaths = dol_dir_list($upload_dir, 'all', 0, '', '', 'name', SORT_ASC, 0); + if (count($listofpaths)) { + foreach ($listofpaths as $key => $val) { + print img_mime($listofpaths[$key]['name']).' '.$listofpaths[$key]['name']; + print '
'; + } + } else { + print ''.$langs->trans("NoAttachedFiles").'
'; } - } else { - print ''.$langs->trans("NoAttachedFiles").'
'; + print '
'.$langs->trans("BackgroundColorByDefault").''; @@ -1241,7 +1283,7 @@ if ($action == 'create') { $morehtmlright = ''; $nbtry = $nbok = 0; - if ($object->statut == 2 || $object->statut == 3) { + if ($object->status == 2 || $object->status == 3) { $nbtry = $object->countNbOfTargets('alreadysent'); $nbko = $object->countNbOfTargets('alreadysentko'); @@ -1268,9 +1310,13 @@ if ($action == 'create') { */ // From - print '
'.$langs->trans("MailFrom").''.dol_print_email($object->email_from, 0, 0, 0, 0, 1).'
'; + print $langs->trans("MailFrom"); + print ''.dol_print_email($object->email_from, 0, 0, 0, 0, 1).'
'.$langs->trans("MailErrorsTo").''.dol_print_email($object->email_errorsto, 0, 0, 0, 0, 1).'
'.$langs->trans("MailErrorsTo").''.dol_print_email($object->email_errorsto, 0, 0, 0, 0, 1).'
'; print '
'; @@ -1288,7 +1334,7 @@ if ($action == 'create') { $nbemail = ($object->nbemail ? $object->nbemail : 0); if (is_numeric($nbemail)) { $text = ''; - if ((getDolGlobalString('MAILING_LIMIT_SENDBYWEB') && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->statut == 1 || $object->statut == 2)) { + if ((getDolGlobalString('MAILING_LIMIT_SENDBYWEB') && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->status == 1 || $object->status == 2)) { if (getDolGlobalInt('MAILING_LIMIT_SENDBYWEB') > 0) { $text .= $langs->trans('LimitSendingEmailing', getDolGlobalString('MAILING_LIMIT_SENDBYWEB')); } else { @@ -1365,54 +1411,60 @@ if ($action == 'create') { print ''; // Subject - print ''; + if ($object->messtype != 'sms') { + print ''; + } $trackid = ''; // TODO To avoid conflicts with 2 mass emailing, we should set a trackid here, even if we use another one into email header. dol_init_file_process($upload_dir, $trackid); // Joined files - $addfileaction = 'addfile'; - print ''; - print ''; + print ''; + // Add link to add file + $maxfilesizearray = getMaxFileSizeArray(); + $maxmin = $maxfilesizearray['maxmin']; + if ($maxmin > 0) { + $out .= ''; // MAX_FILE_SIZE must precede the field type=file + } + $out .= ''; + $out .= ' '; + $out .= ''; + print $out; + print ''; - // Background color - print ''; + // Background color + print ''; + } print '
'.$langs->trans("MailTopic").'
'; + print $langs->trans("MailTopic"); + print '
'.$langs->trans("MailFile").''; - // List of files - $listofpaths = dol_dir_list($upload_dir, 'all', 0, '', '', 'name', SORT_ASC, 0); + if ($object->messtype != 'sms') { + $addfileaction = 'addfile'; + print '
'.$langs->trans("MailFile").''; + // List of files + $listofpaths = dol_dir_list($upload_dir, 'all', 0, '', '', 'name', SORT_ASC, 0); - // TODO Trick to have param removedfile containing nb of image to delete. But this does not works without javascript - $out .= ''."\n"; - $out .= ''."\n"; - if (count($listofpaths)) { - foreach ($listofpaths as $key => $val) { - $out .= '
'; - $out .= img_mime($listofpaths[$key]['name']).' '.$listofpaths[$key]['name']; - $out .= ' '; - $out .= '
'; + // TODO Trick to have param removedfile containing nb of image to delete. But this does not works without javascript + $out .= ''."\n"; + $out .= ''."\n"; + if (count($listofpaths)) { + foreach ($listofpaths as $key => $val) { + $out .= '
'; + $out .= img_mime($listofpaths[$key]['name']).' '.$listofpaths[$key]['name']; + $out .= ' '; + $out .= '
'; + } + } else { + //$out .= ''.$langs->trans("NoAttachedFiles").'
'; } - } else { - //$out .= ''.$langs->trans("NoAttachedFiles").'
'; - } - // Add link to add file - $maxfilesizearray = getMaxFileSizeArray(); - $maxmin = $maxfilesizearray['maxmin']; - if ($maxmin > 0) { - $out .= ''; // MAX_FILE_SIZE must precede the field type=file - } - $out .= ''; - $out .= ' '; - $out .= ''; - print $out; - print '
'.$langs->trans("BackgroundColorByDefault").''; - print $htmlother->selectColor($object->bgcolor, 'bgcolor', '', 0); - print '
'.$langs->trans("BackgroundColorByDefault").''; + print $htmlother->selectColor($object->bgcolor, 'bgcolor', '', 0); + print '
'; @@ -1426,6 +1478,12 @@ if ($action == 'create') { $doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', true, true, getDolGlobalInt('FCKEDITOR_ENABLE_MAILING'), 20, '90%'); $doleditor->Create(); } + if ($action == 'edittxt') { + // wysiwyg editor + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; + $doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', true, true, 0, 20, '90%'); + $doleditor->Create(); + } if ($action == 'edithtml') { // HTML source editor require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; diff --git a/htdocs/comm/mailing/cibles.php b/htdocs/comm/mailing/cibles.php index cd7593f8e21..f2c2643c2bc 100644 --- a/htdocs/comm/mailing/cibles.php +++ b/htdocs/comm/mailing/cibles.php @@ -275,7 +275,7 @@ if ($object->fetch($id) >= 0) { $morehtmlright = ''; $nbtry = $nbok = 0; - if ($object->statut == $object::STATUS_SENTPARTIALY || $object->statut == $object::STATUS_SENTCOMPLETELY) { + if ($object->status == $object::STATUS_SENTPARTIALY || $object->status == $object::STATUS_SENTCOMPLETELY) { $nbtry = $object->countNbOfTargets('alreadysent'); $nbko = $object->countNbOfTargets('alreadysentko'); $nbok = ($nbtry - $nbko); @@ -314,21 +314,23 @@ if ($object->fetch($id) >= 0) { print '
'.$langs->trans("MailErrorsTo").''; - $emailarray = CMailFile::getArrayAddress($object->email_errorsto); - foreach ($emailarray as $email => $name) { - if ($name != $email) { - print dol_escape_htmltag($name).' <'.$email; - print '>'; - if (!isValidEmail($email)) { - $langs->load("errors"); - print img_warning($langs->trans("ErrorBadEMail", $email)); + if ($object->messtype != 'sms') { + print '
'.$langs->trans("MailErrorsTo").''; + $emailarray = CMailFile::getArrayAddress($object->email_errorsto); + foreach ($emailarray as $email => $name) { + if ($name != $email) { + print dol_escape_htmltag($name).' <'.$email; + print '>'; + if (!isValidEmail($email)) { + $langs->load("errors"); + print img_warning($langs->trans("ErrorBadEMail", $email)); + } + } else { + print dol_print_email($object->email_errorsto, 0, 0, 0, 0, 1); } - } else { - print dol_print_email($object->email_errorsto, 0, 0, 0, 0, 1); } + print '
'; print ''; @@ -340,13 +342,13 @@ if ($object->fetch($id) >= 0) { print ''; // Number of distinct emails - print ''; @@ -853,12 +863,12 @@ if ($object->fetch($id) >= 0) { if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { print ''; diff --git a/htdocs/comm/mailing/class/mailing.class.php b/htdocs/comm/mailing/class/mailing.class.php index d5160aefd8b..7e18ce5f477 100644 --- a/htdocs/comm/mailing/class/mailing.class.php +++ b/htdocs/comm/mailing/class/mailing.class.php @@ -88,9 +88,15 @@ class Mailing extends CommonObject /** * @var int status + * @deprecated */ public $statut; // Status 0=Draft, 1=Validated, 2=Sent partially, 3=Sent completely + /** + * @var int status + */ + public $status; // Status 0=Draft, 1=Validated, 2=Sent partially, 3=Sent completely + /** * @var string email from */ @@ -131,47 +137,11 @@ class Mailing extends CommonObject */ public $joined_file4; - /** - * @var int id of user create - * @deprecated - */ - public $user_creation; - - /** - * @var int id of user create - * @deprecated - */ - public $user_creat; - - /** - * @var int id of user validate - * @deprecated - */ - public $user_validation; - - /** - * @var int id of user validate - * @deprecated - */ - public $user_valid; - - /** - * @var integer|string date_creation - * @deprecated - */ - public $date_creat; - /** * @var integer|string date_creation */ public $date_creation; - /** - * @var int date validate - * @deprecated - */ - public $date_valid; - /** * @var int date validate */ @@ -220,8 +190,6 @@ class Mailing extends CommonObject */ public function __construct($db) { - global $langs; - $this->db = $db; // List of language codes for status @@ -258,12 +226,13 @@ class Mailing extends CommonObject $this->email_from = trim($this->email_from); if (!$this->email_from) { - $this->error = $langs->trans("ErrorMailFromRequired"); + $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("From")); return -1; } $error = 0; $now = dol_now(); + $this->db->begin(); $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing"; @@ -275,6 +244,7 @@ class Mailing extends CommonObject } dol_syslog(__METHOD__, LOG_DEBUG); + $resql = $this->db->query($sql); if ($resql) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."mailing"); @@ -328,6 +298,7 @@ class Mailing extends CommonObject $sql = "UPDATE ".MAIN_DB_PREFIX."mailing "; $sql .= " SET titre = '".$this->db->escape($this->title)."'"; + $sql .= ", messtype = '".$this->db->escape($this->messtype)."'"; $sql .= ", sujet = '".$this->db->escape($this->sujet)."'"; $sql .= ", body = '".$this->db->escape($this->body)."'"; $sql .= ", email_from = '".$this->db->escape($this->email_from)."'"; @@ -375,11 +346,9 @@ class Mailing extends CommonObject */ public function fetch($rowid, $ref = '') { - global $conf; - - $sql = "SELECT m.rowid, m.titre as title, m.sujet, m.body, m.bgcolor, m.bgimage, m.evenunsubscribe"; + $sql = "SELECT m.rowid, m.messtype, m.titre as title, m.sujet, m.body, m.bgcolor, m.bgimage, m.evenunsubscribe"; $sql .= ", m.email_from, m.email_replyto, m.email_errorsto"; - $sql .= ", m.statut, m.nbemail"; + $sql .= ", m.statut as status, m.nbemail"; $sql .= ", m.fk_user_creat, m.fk_user_valid"; $sql .= ", m.date_creat"; $sql .= ", m.date_valid"; @@ -401,9 +370,13 @@ class Mailing extends CommonObject $this->id = $obj->rowid; $this->ref = $obj->rowid; - $this->statut = $obj->statut; - $this->nbemail = $obj->nbemail; $this->title = $obj->title; + $this->messtype = $obj->messtype; + + $this->statut = $obj->status; // deprecated + $this->status = $obj->status; + + $this->nbemail = $obj->nbemail; $this->sujet = $obj->sujet; if (getDolGlobalString('FCKEDITOR_ENABLE_MAILING') && dol_textishtml(dol_html_entity_decode($obj->body, ENT_COMPAT | ENT_HTML5))) { @@ -423,14 +396,16 @@ class Mailing extends CommonObject $this->user_creation_id = $obj->fk_user_creat; $this->user_validation_id = $obj->fk_user_valid; - $this->date_creat = $this->db->jdate($obj->date_creat); $this->date_creation = $this->db->jdate($obj->date_creat); - $this->date_valid = $this->db->jdate($obj->date_valid); $this->date_validation = $this->db->jdate($obj->date_valid); $this->date_envoi = $this->db->jdate($obj->date_envoi); $this->extraparams = (array) json_decode($obj->extraparams, true); + if ($this->messtype == 'sms') { + $this->picto = 'phone'; + } + return 1; } else { dol_syslog(get_class($this)."::fetch Erreur -1"); @@ -465,6 +440,7 @@ class Mailing extends CommonObject // Load source object $object->fetch($fromid); $object->id = 0; + $object->status = 0; $object->statut = 0; // Clear fields @@ -487,9 +463,7 @@ class Mailing extends CommonObject $object->user_creation_id = $user->id; $object->user_validation_id = ''; - $object->date_creat = ''; - $object->date_valid = ''; - $object->date_envoi = ''; + $object->date_envoi = null; } // Create clone @@ -728,7 +702,8 @@ class Mailing extends CommonObject */ public function refreshNbOfTargets() { - $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."mailing_cibles"; + $sql = "SELECT COUNT(rowid) as nb"; + $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles"; $sql .= " WHERE fk_mailing = ".((int) $this->id); $resql = $this->db->query($sql); @@ -765,14 +740,14 @@ class Mailing extends CommonObject */ public function getTooltipContentArray($params) { - global $conf, $langs; + global $langs; - $nofetch = !empty($params['nofetch']); + //$nofetch = !empty($params['nofetch']); $langs->load('mails'); $datas = array(); $datas['picto'] = img_picto('', $this->picto).' '.$langs->trans("ShowEMailing").''; - if (isset($this->statut)) { + if (isset($this->status)) { $datas['picto'] .= ' '.$this->getLibStatut(5); } $datas['ref'] = '
'.$langs->trans('Ref').': '.$this->ref; @@ -881,7 +856,7 @@ class Mailing extends CommonObject */ public function getLibStatut($mode = 0) { - return $this->LibStatut($this->statut, $mode); + return $this->LibStatut($this->status, $mode); } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps diff --git a/htdocs/comm/mailing/info.php b/htdocs/comm/mailing/info.php index dccea76c39b..12ca330896b 100644 --- a/htdocs/comm/mailing/info.php +++ b/htdocs/comm/mailing/info.php @@ -66,7 +66,7 @@ if ($object->fetch($id) >= 0) { $morehtmlright = ''; $nbtry = $nbok = 0; - if ($object->statut == 2 || $object->statut == 3) { + if ($object->status == 2 || $object->status == 3) { $nbtry = $object->countNbOfTargets('alreadysent'); $nbko = $object->countNbOfTargets('alreadysentko'); diff --git a/htdocs/comm/mailing/list.php b/htdocs/comm/mailing/list.php index 973480ca2e6..e60e2295add 100644 --- a/htdocs/comm/mailing/list.php +++ b/htdocs/comm/mailing/list.php @@ -57,6 +57,7 @@ $pagenext = $page + 1; // Search Fields $search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml')); $search_ref = GETPOST("search_ref", "alpha") ? GETPOST("search_ref", "alpha") : GETPOST("sref", "alpha"); +$search_messtype = GETPOST("search_messtype", "alpha"); $filteremail = GETPOST('filteremail', 'alpha'); // Initialize technical objects @@ -122,6 +123,7 @@ if (empty($reshook)) { $search[$key]=''; }*/ $search_ref = ''; + $search_messtype = ''; $search_all = ''; $toselect = array(); $search_array_options = array(); @@ -155,7 +157,7 @@ $morecss = array(); // Build and execute select // -------------------------------------------------------------------- if ($filteremail) { - $sql = "SELECT m.rowid, m.titre as title, m.nbemail, m.statut, m.date_creat as datec, m.date_envoi as date_envoi,"; + $sql = "SELECT m.rowid, m.messtype, m.titre as title, m.nbemail, m.statut as status, m.date_creat as datec, m.date_envoi as date_envoi,"; $sql .= " mc.statut as sendstatut"; $sqlfields = $sql; // $sql fields to remove for count total @@ -166,8 +168,11 @@ if ($filteremail) { if ($search_ref) { $sql .= " AND m.rowid = '".$db->escape($search_ref)."'"; } + if ($search_messtype) { + $sql .= " AND m.messtype LIKE '".$db->escape($search_messtype)."'"; + } if ($search_all) { - $sql .= " AND (m.titre like '%".$db->escape($search_all)."%' OR m.sujet like '%".$db->escape($search_all)."%' OR m.body like '%".$db->escape($search_all)."%')"; + $sql .= " AND (m.titre LIKE '%".$db->escape($search_all)."%' OR m.sujet LIKE '%".$db->escape($search_all)."%' OR m.body LIKE '%".$db->escape($search_all)."%')"; } if (!$sortorder) { $sortorder = "ASC"; @@ -176,17 +181,20 @@ if ($filteremail) { $sortfield = "m.rowid"; } } else { - $sql = "SELECT m.rowid, m.titre as title, m.nbemail, m.statut, m.date_creat as datec, m.date_envoi as date_envoi"; + $sql = "SELECT m.rowid, m.messtype, m.titre as title, m.nbemail, m.statut as status, m.date_creat as datec, m.date_envoi as date_envoi"; $sqlfields = $sql; // $sql fields to remove for count total $sql .= " FROM ".MAIN_DB_PREFIX."mailing as m"; - $sql .= " WHERE m.entity = ".$conf->entity; + $sql .= " WHERE m.entity = ".((int) $conf->entity); if ($search_ref) { $sql .= " AND m.rowid = '".$db->escape($search_ref)."'"; } + if ($search_messtype) { + $sql .= " AND m.messtype LIKE '".$db->escape($search_messtype)."'"; + } if ($search_all) { - $sql .= " AND (m.titre like '%".$db->escape($search_all)."%' OR m.sujet like '%".$db->escape($search_all)."%' OR m.body like '%".$db->escape($search_all)."%')"; + $sql .= " AND (m.titre LIKE '%".$db->escape($search_all)."%' OR m.sujet LIKE '%".$db->escape($search_all)."%' OR m.body LIKE '%".$db->escape($search_all)."%')"; } if (!$sortorder) { $sortorder = "ASC"; @@ -276,6 +284,16 @@ if ($limit > 0 && $limit != $conf->liste_limit) { if ($optioncss != '') { $param .= '&optioncss='.urlencode($optioncss); } +if ($search_ref != '') { + $param .= '&search_ref='.urlencode($search_ref); +} +if ($search_messtype != '') { + $param .= '&search_type='.urlencode($search_messtype); +} +if ($optioncss != '') { + $param .= '&optioncss='.urlencode($optioncss); +} + if ($filteremail) { $param .= '&filteremail='.urlencode($filteremail); } @@ -378,6 +396,12 @@ if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { print ''; +// Message type +if (getDolGlobalInt('EMAILINGS_SUPPORT_ALSO_SMS')) { + print ''; +} // Title print ''; + // Message type + if (getDolGlobalInt('EMAILINGS_SUPPORT_ALSO_SMS')) { + print ''; + } + // Title print ''; @@ -500,7 +541,7 @@ while ($i < $imaxinloop) { if (!$filteremail) { print ''; + print ''; print ''; // Status @@ -522,7 +563,7 @@ while ($i < $imaxinloop) { if ($filteremail) { print $object::libStatutDest($obj->sendstatut, 2); } else { - print $object->LibStatut($obj->statut, 5); + print $object->LibStatut($obj->status, 5); } print ''; diff --git a/htdocs/comm/mailing/note.php b/htdocs/comm/mailing/note.php index 49cf4b026df..19e623d519b 100644 --- a/htdocs/comm/mailing/note.php +++ b/htdocs/comm/mailing/note.php @@ -29,7 +29,7 @@ require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/mailing.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/emailing.lib.php'; // Load translation files required by the page -$langs->loadLangs(array("mailing", "companies")); +$langs->loadLangs(array("mails", "mailing", "companies")); // Get parameters $id = GETPOST('id', 'int'); diff --git a/htdocs/core/class/CSMSFile.class.php b/htdocs/core/class/CSMSFile.class.php index 9c1f99bbb31..adfb7448c0c 100644 --- a/htdocs/core/class/CSMSFile.class.php +++ b/htdocs/core/class/CSMSFile.class.php @@ -124,8 +124,6 @@ class CSMSFile */ public function sendfile() { - global $conf; - $errorlevel = error_reporting(); error_reporting($errorlevel ^ E_WARNING); // Disable warnings @@ -155,8 +153,12 @@ class CSMSFile dol_include_once('/'.$module.'/class/'.strtolower($classfile).'.class.php'); try { $classname = ucfirst($classfile); + + dol_syslog("CSMSFile::sendfile: try to include class ".$classname); + if (class_exists($classname)) { $sms = new $classname($this->db); + $sms->expe = $this->addr_from; $sms->dest = $this->addr_to; $sms->deferred = $this->deferred; @@ -177,6 +179,10 @@ class CSMSFile $this->errors = $sms->errors; if ($res <= 0) { dol_syslog("CSMSFile::sendfile: sms send error=".$this->error, LOG_ERR); + if (getDolGlobalString('MAIN_SMS_DEBUG')) { + $this->dump_sms_result($res); + } + $res = false; } else { dol_syslog("CSMSFile::sendfile: sms send success with id=".$res, LOG_DEBUG); //var_dump($res); // 1973128 @@ -194,8 +200,8 @@ class CSMSFile } else { // Send sms method not correctly defined // -------------------------------------- - - return 'Bad value for MAIN_SMS_SENDMODE constant'; + $sms->error = 'Bad value for MAIN_SMS_SENDMODE constant'; + $res = false; } } else { $this->error = 'No sms sent. Feature is disabled by option MAIN_DISABLE_ALL_SMS'; @@ -249,13 +255,13 @@ class CSMSFile public function dump_sms_result($result) { // phpcs:enable - global $conf, $dolibarr_main_data_root; + global $dolibarr_main_data_root; if (@is_writeable($dolibarr_main_data_root)) { // Avoid fatal error on fopen with open_basedir $outputfile = $dolibarr_main_data_root."/dolibarr_sms.log"; $fp = fopen($outputfile, "a+"); - fputs($fp, "\nResult id=".$result); + fputs($fp, "\nResult of SmsSend = ".$result); fclose($fp); dolChmod($outputfile); diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 06bcb0712ed..a79dac78826 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -302,7 +302,7 @@ MAIN_DISABLE_ALL_MAILS=Disable all email sending (for test purposes or demos) MAIN_MAIL_FORCE_SENDTO=Send all emails to (instead of real recipients, for test purposes) MAIN_MAIL_ENABLED_USER_DEST_SELECT=Suggest emails of employees (if defined) into the list of predefined recipient when writing a new email MAIN_MAIL_NO_WITH_TO_SELECTED=Do not select a default recipient even if there is only 1 possible choice -MAIN_MAIL_SENDMODE=Email sending method +MAIN_MAIL_SENDMODE=Sending method MAIN_MAIL_SMTPS_ID=SMTP ID (if sending server requires authentication) MAIN_MAIL_SMTPS_PW=SMTP Password (if sending server requires authentication) MAIN_MAIL_EMAIL_TLS=Use TLS (SSL) encryption diff --git a/htdocs/langs/en_US/mails.lang b/htdocs/langs/en_US/mails.lang index 38901ccf3a3..ff6f26f1992 100644 --- a/htdocs/langs/en_US/mails.lang +++ b/htdocs/langs/en_US/mails.lang @@ -9,6 +9,7 @@ MailRecipients=Recipients MailRecipient=Recipient MailTitle=Description MailFrom=From +PhoneFrom=From MailErrorsTo=Errors to MailReply=Reply to MailTo=To @@ -32,7 +33,7 @@ DeleteMailing=Delete emailing DeleteAMailing=Delete an emailing PreviewMailing=Preview emailing CreateMailing=Create emailing -TestMailing=Test email +TestMailing=Test ValidMailing=Valid emailing MailingStatusDraft=Draft MailingStatusValidated=Validated @@ -52,6 +53,7 @@ ConfirmValidMailing=Are you sure you want to validate this emailing? ConfirmResetMailing=Warning, by re-initializing emailing %s, you will allow the re-sending this email in a bulk mailing. Are you sure you want to do this? ConfirmDeleteMailing=Are you sure you want to delete this emailing? NbOfUniqueEMails=No. of unique emails +NbOfUniquePhones=No. of unique phones NbOfEMails=No. of EMails TotalNbOfDistinctRecipients=Number of distinct recipients NoTargetYet=No recipients defined yet (Go on tab 'Recipients')
'; + print '
'; print $langs->trans("TotalNbOfDistinctRecipients"); print ''; $nbemail = ($object->nbemail ? $object->nbemail : 0); if (is_numeric($nbemail)) { $text = ''; - if ((getDolGlobalString('MAILING_LIMIT_SENDBYWEB') && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->statut == 1 || ($object->statut == 2 && $nbtry < $nbemail))) { + if ((getDolGlobalString('MAILING_LIMIT_SENDBYWEB') && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->status == 1 || ($object->status == 2 && $nbtry < $nbemail))) { if (getDolGlobalInt('MAILING_LIMIT_SENDBYWEB') > 0) { $text .= $langs->trans('LimitSendingEmailing', getDolGlobalString('MAILING_LIMIT_SENDBYWEB')); } else { @@ -398,7 +400,7 @@ if ($object->fetch($id) >= 0) { print '
'; - $allowaddtarget = ($object->statut == $object::STATUS_DRAFT); + $allowaddtarget = ($object->status == $object::STATUS_DRAFT); // Show email selectors if ($allowaddtarget && $user->hasRight('mailing', 'creer')) { @@ -410,11 +412,19 @@ if ($object->fetch($id) >= 0) { print '
'; print '
'; print '
'.$langs->trans("RecipientSelectionModules").'
'; - print '
'.$langs->trans("NbOfUniqueEMails").'
'; - print '
'.$langs->trans("Filters").'
'; - print '              
'.$langs->trans("EvenUnsubscribe").' '; - print ajax_object_onoff($object, 'evenunsubscribe', 'evenunsubscribe', 'EvenUnsubscribe:switch_on:warning', 'EvenUnsubscribe', array(), 'small valignmiddle', '', 1); + print '
'; + if ($object->messtype != 'sms') { + print $langs->trans("NbOfUniqueEMails"); + } else { + print $langs->trans("NbOfUniquePhones"); + } print '
'; + print '
'.$langs->trans("Filters").'
'; + if ($object->messtype != 'sms') { + print '              
'.$langs->trans("EvenUnsubscribe").' '; + print ajax_object_onoff($object, 'evenunsubscribe', 'evenunsubscribe', 'EvenUnsubscribe:switch_on:warning', 'EvenUnsubscribe', array(), 'small valignmiddle', '', 1); + print '
'; + } print '
'; print '
 
'; print '
'; // End tr @@ -776,12 +786,12 @@ if ($object->fetch($id) >= 0) { if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { print '
'; print ''; - if ($obj->statut == $object::STATUS_DRAFT) { // Not sent yet + if ($obj->status == $object::STATUS_DRAFT) { // Not sent yet if ($user->hasRight('mailing', 'creer')) { print ''.img_delete($langs->trans("RemoveRecipient")).''; } } - /*if ($obj->statut == -1) // Sent with error + /*if ($obj->status == -1) // Sent with error { print ''.$langs->trans("Retry").''; }*/ @@ -834,7 +844,7 @@ if ($object->fetch($id) >= 0) { // Date sent print ''; - if ($obj->statut != $object::STATUS_DRAFT) { + if ($obj->status != $object::STATUS_DRAFT) { // Date sent print $obj->date_envoi; } @@ -842,10 +852,10 @@ if ($object->fetch($id) >= 0) { // Status of recipient sending email (Warning != status of emailing) print ''; - if ($obj->statut == $object::STATUS_DRAFT) { - print $object::libStatutDest($obj->statut, 2, ''); + if ($obj->status == $object::STATUS_DRAFT) { + print $object::libStatutDest($obj->status, 2, ''); } else { - print $object::libStatutDest($obj->statut, 2, $obj->error_text); + print $object::libStatutDest($obj->status, 2, $obj->error_text); } print ''; print ''; - if ($obj->statut == $object::STATUS_DRAFT) { // Not sent yet + if ($obj->status == $object::STATUS_DRAFT) { // Not sent yet if ($user->hasRight('mailing', 'creer')) { print ''.img_delete($langs->trans("RemoveRecipient")).''; } } - /*if ($obj->statut == -1) // Sent with error + /*if ($obj->status == -1) // Sent with error { print ''.$langs->trans("Retry").''; }*/ @@ -869,7 +879,7 @@ if ($object->fetch($id) >= 0) { $i++; } } else { - if ($object->statut < $object::STATUS_SENTPARTIALY) { + if ($object->status < $object::STATUS_SENTPARTIALY) { print '
'; print ''.$langs->trans("NoTargetYet").''; print '
'; print ''; print ''; + print ''; + print ''; print ''; @@ -415,19 +439,28 @@ if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { } print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "m.rowid", $param, "", "", $sortfield, $sortorder); $totalarray['nbfield']++; +// Message type +if (getDolGlobalInt('EMAILINGS_SUPPORT_ALSO_SMS')) { + print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "m.messtype", $param, "", "", $sortfield, $sortorder); + $totalarray['nbfield']++; +} print_liste_field_titre("Title", $_SERVER["PHP_SELF"], "m.titre", $param, "", "", $sortfield, $sortorder); $totalarray['nbfield']++; -print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "m.date_creat", $param, "", 'align="center"', $sortfield, $sortorder); +print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "m.date_creat", $param, "", '', $sortfield, $sortorder, 'center '); $totalarray['nbfield']++; if (!$filteremail) { - print_liste_field_titre("NbOfEMails", $_SERVER["PHP_SELF"], "m.nbemail", $param, "", 'align="center"', $sortfield, $sortorder); + $title = $langs->trans("NbOfEMails"); + if (getDolGlobalInt('EMAILINGS_SUPPORT_ALSO_SMS')) { + $title .= ' | '.$langs->trans("SMS"); + } + print_liste_field_titre($title, $_SERVER["PHP_SELF"], "m.nbemail", $param, "", '', $sortfield, $sortorder, 'center '); $totalarray['nbfield']++; } if (!$filteremail) { - print_liste_field_titre("DateLastSend", $_SERVER["PHP_SELF"], "m.date_envoi", $param, "", 'align="center"', $sortfield, $sortorder); + print_liste_field_titre("DateLastSend", $_SERVER["PHP_SELF"], "m.date_envoi", $param, "", '', $sortfield, $sortorder, 'center '); $totalarray['nbfield']++; } else { - print_liste_field_titre("DateSending", $_SERVER["PHP_SELF"], "mc.date_envoi", $param, "", 'align="center"', $sortfield, $sortorder); + print_liste_field_titre("DateSending", $_SERVER["PHP_SELF"], "mc.date_envoi", $param, "", '', $sortfield, $sortorder, 'center '); $totalarray['nbfield']++; } // Extra fields @@ -484,10 +517,18 @@ while ($i < $imaxinloop) { } } + // Ref print ''; print $object->getNomUrl(1); print ''; + print dol_escape_htmltag($obj->messtype); + print ''.dol_escape_htmltag($obj->title).''; $nbemail = $obj->nbemail; - /*if ($obj->statut != 3 && !empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) + /*if ($obj->status != 3 && !empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) { $text=$langs->trans('LimitSendingEmailing',$conf->global->MAILING_LIMIT_SENDBYWEB); print $form->textwithpicto($nbemail,$text,1,'warning'); @@ -514,7 +555,7 @@ while ($i < $imaxinloop) { } // Last send - print ''.dol_print_date($db->jdate($obj->date_envoi), 'day').''.dol_print_date($db->jdate($obj->date_envoi), 'day').'