diff --git a/htdocs/core/actions_sendmails.inc.php b/htdocs/core/actions_sendmails.inc.php index 0be919de0dd..929d35d9730 100644 --- a/htdocs/core/actions_sendmails.inc.php +++ b/htdocs/core/actions_sendmails.inc.php @@ -33,8 +33,7 @@ /* * Add file in email form */ -if (GETPOST('addfile', 'alpha')) -{ +if (GETPOST('addfile', 'alpha')) { $trackid = GETPOST('trackid', 'aZ09'); require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -50,8 +49,7 @@ if (GETPOST('addfile', 'alpha')) /* * Remove file in email form */ -if (!empty($_POST['removedfile']) && empty($_POST['removAll'])) -{ +if (!empty($_POST['removedfile']) && empty($_POST['removAll'])) { $trackid = GETPOST('trackid', 'aZ09'); require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -69,24 +67,28 @@ if (!empty($_POST['removedfile']) && empty($_POST['removAll'])) /* * Remove all files in email form */ -if (GETPOST('removAll', 'alpha')) -{ +if (GETPOST('removAll', 'alpha')) { $trackid = GETPOST('trackid', 'aZ09'); $listofpaths = array(); $listofnames = array(); $listofmimes = array(); $keytoavoidconflict = empty($trackid) ? '' : '-'.$trackid; - if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]); - if (!empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]); - if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]); + if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) { + $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]); + } + if (!empty($_SESSION["listofnames".$keytoavoidconflict])) { + $listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]); + } + if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) { + $listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]); + } include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; $formmail = new FormMail($db); $formmail->trackid = $trackid; - foreach ($listofpaths as $key => $value) - { + foreach ($listofpaths as $key => $value) { $pathtodelete = $value; $filetodelete = $listofnames[$key]; $result = dol_delete_file($pathtodelete, 1); // Delete uploded Files @@ -101,50 +103,56 @@ if (GETPOST('removAll', 'alpha')) /* * Send mail */ -if (($action == 'send' || $action == 'relance') && !$_POST['addfile'] && !$_POST['removAll'] && !$_POST['removedfile'] && !$_POST['cancel'] && !$_POST['modelselected']) -{ - if (empty($trackid)) $trackid = GETPOST('trackid', 'aZ09'); +if (($action == 'send' || $action == 'relance') && !$_POST['addfile'] && !$_POST['removAll'] && !$_POST['removedfile'] && !$_POST['cancel'] && !$_POST['modelselected']) { + if (empty($trackid)) { + $trackid = GETPOST('trackid', 'aZ09'); + } $subject = ''; $actionmsg = ''; $actionmsg2 = ''; $langs->load('mails'); - if (is_object($object)) - { + if (is_object($object)) { $result = $object->fetch($id); $sendtosocid = 0; // Id of related thirdparty - if (method_exists($object, "fetch_thirdparty") && !in_array($object->element, array('member', 'user', 'expensereport', 'societe', 'contact'))) - { + if (method_exists($object, "fetch_thirdparty") && !in_array($object->element, array('member', 'user', 'expensereport', 'societe', 'contact'))) { $resultthirdparty = $object->fetch_thirdparty(); $thirdparty = $object->thirdparty; - if (is_object($thirdparty)) $sendtosocid = $thirdparty->id; - } elseif ($object->element == 'member' || $object->element == 'user') - { + if (is_object($thirdparty)) { + $sendtosocid = $thirdparty->id; + } + } elseif ($object->element == 'member' || $object->element == 'user') { $thirdparty = $object; - if ($object->socid > 0) $sendtosocid = $object->socid; - } elseif ($object->element == 'expensereport') - { + if ($object->socid > 0) { + $sendtosocid = $object->socid; + } + } elseif ($object->element == 'expensereport') { $tmpuser = new User($db); $tmpuser->fetch($object->fk_user_author); $thirdparty = $tmpuser; - if ($object->socid > 0) $sendtosocid = $object->socid; - } elseif ($object->element == 'societe') - { + if ($object->socid > 0) { + $sendtosocid = $object->socid; + } + } elseif ($object->element == 'societe') { $thirdparty = $object; - if (is_object($thirdparty) && $thirdparty->id > 0) $sendtosocid = $thirdparty->id; - } elseif ($object->element == 'contact') - { + if (is_object($thirdparty) && $thirdparty->id > 0) { + $sendtosocid = $thirdparty->id; + } + } elseif ($object->element == 'contact') { $contact = $object; if ($contact->id > 0) { $contact->fetch_thirdparty(); $thirdparty = $contact->thirdparty; - if (is_object($thirdparty) && $thirdparty->id > 0) $sendtosocid = $thirdparty->id; + if (is_object($thirdparty) && $thirdparty->id > 0) { + $sendtosocid = $thirdparty->id; + } } - } else dol_print_error('', "Use actions_sendmails.in.php for an element/object '".$object->element."' that is not supported"); + } else { + dol_print_error('', "Use actions_sendmails.in.php for an element/object '".$object->element."' that is not supported"); + } - if (is_object($hookmanager)) - { + if (is_object($hookmanager)) { $parameters = array(); $reshook = $hookmanager->executeHooks('initSendToSocid', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks } @@ -152,8 +160,7 @@ if (($action == 'send' || $action == 'relance') && !$_POST['addfile'] && !$_POST $thirdparty = $mysoc; } - if ($result > 0) - { + if ($result > 0) { $sendto = ''; $sendtocc = ''; $sendtobcc = ''; @@ -163,48 +170,40 @@ if (($action == 'send' || $action == 'relance') && !$_POST['addfile'] && !$_POST // Define $sendto $receiver = $_POST['receiver']; - if (!is_array($receiver)) - { - if ($receiver == '-1') $receiver = array(); - else $receiver = array($receiver); + if (!is_array($receiver)) { + if ($receiver == '-1') { + $receiver = array(); + } else { + $receiver = array($receiver); + } } $tmparray = array(); - if (trim($_POST['sendto'])) - { + if (trim($_POST['sendto'])) { // Recipients are provided into free text $tmparray[] = trim($_POST['sendto']); } - if (count($receiver) > 0) - { + if (count($receiver) > 0) { // Recipient was provided from combo list - foreach ($receiver as $key=>$val) - { - if ($val == 'thirdparty') // Key selected means current third party ('thirdparty' may be used for current member or current user too) - { + foreach ($receiver as $key => $val) { + if ($val == 'thirdparty') { // Key selected means current third party ('thirdparty' may be used for current member or current user too) $tmparray[] = dol_string_nospecial($thirdparty->getFullName($langs), ' ', array(",")).' <'.$thirdparty->email.'>'; - } - elseif ($val == 'contact') // Key selected means current contact - { + } elseif ($val == 'contact') { // Key selected means current contact $tmparray[] = dol_string_nospecial($contact->getFullName($langs), ' ', array(",")).' <'.$contact->email.'>'; $sendtoid[] = $contact->id; - } elseif ($val) // $val is the Id of a contact - { + } elseif ($val) { // $val is the Id of a contact $tmparray[] = $thirdparty->contact_get_property((int) $val, 'email'); $sendtoid[] = ((int) $val); } } } - if (!empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) - { + if (!empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) { $receiveruser = $_POST['receiveruser']; - if (is_array($receiveruser) && count($receiveruser) > 0) - { + if (is_array($receiveruser) && count($receiveruser) > 0) { $fuserdest = new User($db); - foreach ($receiveruser as $key=>$val) - { + foreach ($receiveruser as $key => $val) { $tmparray[] = $fuserdest->user_get_property($val, 'email'); $sendtouserid[] = $val; } @@ -215,32 +214,27 @@ if (($action == 'send' || $action == 'relance') && !$_POST['addfile'] && !$_POST // Define $sendtocc $receivercc = $_POST['receivercc']; - if (!is_array($receivercc)) - { - if ($receivercc == '-1') $receivercc = array(); - else $receivercc = array($receivercc); + if (!is_array($receivercc)) { + if ($receivercc == '-1') { + $receivercc = array(); + } else { + $receivercc = array($receivercc); + } } $tmparray = array(); - if (trim($_POST['sendtocc'])) - { + if (trim($_POST['sendtocc'])) { $tmparray[] = trim($_POST['sendtocc']); } - if (count($receivercc) > 0) - { - foreach ($receivercc as $key=>$val) - { - // Recipient was provided from combo list - if ($val == 'thirdparty') // Key selected means currentthird party (may be usd for current member or current user too) - { + if (count($receivercc) > 0) { + foreach ($receivercc as $key => $val) { + if ($val == 'thirdparty') { // Key selected means currentthird party (may be usd for current member or current user too) + // Recipient was provided from combo list $tmparray[] = dol_string_nospecial($thirdparty->name, ' ', array(",")).' <'.$thirdparty->email.'>'; - } - // Recipient was provided from combo list - elseif ($val == 'contact') // Key selected means current contact - { + } elseif ($val == 'contact') { // Key selected means current contact + // Recipient was provided from combo list $tmparray[] = dol_string_nospecial($contact->name, ' ', array(",")).' <'.$contact->email.'>'; //$sendtoid[] = $contact->id; TODO Add also id of contact in CC ? - } elseif ($val) // $val is the Id of a contact - { + } elseif ($val) { // $val is the Id of a contact $tmparray[] = $thirdparty->contact_get_property((int) $val, 'email'); //$sendtoid[] = ((int) $val); TODO Add also id of contact in CC ? } @@ -249,11 +243,9 @@ if (($action == 'send' || $action == 'relance') && !$_POST['addfile'] && !$_POST if (!empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) { $receiverccuser = $_POST['receiverccuser']; - if (is_array($receiverccuser) && count($receiverccuser) > 0) - { + if (is_array($receiverccuser) && count($receiverccuser) > 0) { $fuserdest = new User($db); - foreach ($receiverccuser as $key=>$val) - { + foreach ($receiverccuser as $key => $val) { $tmparray[] = $fuserdest->user_get_property($val, 'email'); $sendtoccuserid[] = $val; } @@ -261,8 +253,7 @@ if (($action == 'send' || $action == 'relance') && !$_POST['addfile'] && !$_POST } $sendtocc = implode(',', $tmparray); - if (dol_strlen($sendto)) - { + if (dol_strlen($sendto)) { // Define $urlwithroot $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file @@ -291,8 +282,7 @@ if (($action == 'send' || $action == 'relance') && !$_POST['addfile'] && !$_POST $sql .= ' WHERE rowid = '.(int) $reg[1]; $resql = $db->query($sql); $obj = $db->fetch_object($resql); - if ($obj) - { + if ($obj) { $from = dol_string_nospecial($obj->label, ' ', array(",")).' <'.$obj->email.'>'; } } else { @@ -312,21 +302,20 @@ if (($action == 'send' || $action == 'relance') && !$_POST['addfile'] && !$_POST $sendtobcc = GETPOST('sendtoccc'); // Autocomplete the $sendtobcc // $autocopy can be MAIN_MAIL_AUTOCOPY_PROPOSAL_TO, MAIN_MAIL_AUTOCOPY_ORDER_TO, MAIN_MAIL_AUTOCOPY_INVOICE_TO, MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO... - if (!empty($autocopy)) - { + if (!empty($autocopy)) { $sendtobcc .= (empty($conf->global->$autocopy) ? '' : (($sendtobcc ? ", " : "").$conf->global->$autocopy)); } $deliveryreceipt = $_POST['deliveryreceipt']; - if ($action == 'send' || $action == 'relance') - { + if ($action == 'send' || $action == 'relance') { $actionmsg2 = $langs->transnoentities('MailSentBy').' '.CMailFile::getValidAddress($from, 4, 0, 1).' '.$langs->transnoentities('at').' '.CMailFile::getValidAddress($sendto, 4, 0, 1); - if ($message) - { + if ($message) { $actionmsg = $langs->transnoentities('MailFrom').': '.dol_escape_htmltag($from); $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTo').': '.dol_escape_htmltag($sendto)); - if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".dol_escape_htmltag($sendtocc)); + if ($sendtocc) { + $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".dol_escape_htmltag($sendtocc)); + } $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic').": ".$subject); $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody').":"); $actionmsg = dol_concatdesc($actionmsg, $message); @@ -343,50 +332,6 @@ if (($action == 'send' || $action == 'relance') && !$_POST['addfile'] && !$_POST $filename = $attachedfiles['names']; $mimetype = $attachedfiles['mimes']; - // Feature to push mail sent into Sent folder - /* This code must be now included into the hook mail, method sendMailAfter - if (! empty($conf->dolimail->enabled)) - { - $mailfromid = explode("#", $_POST['frommail'],3); // $_POST['frommail'] = 'aaa#Sent# ' // TODO Use a better way to define Sent dir. - if (count($mailfromid)==0) $from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>'; - else - { - $mbid = $mailfromid[1]; - - // IMAP Postbox - $mailboxconfig = new IMAP($db); - $mailboxconfig->fetch($mbid); - if ($mailboxconfig->mailbox_imap_host) $ref=$mailboxconfig->get_ref(); - - $mailboxconfig->folder_id=$mailboxconfig->mailbox_imap_outbox; - $mailboxconfig->userfolder_fetch(); - - if ($mailboxconfig->mailbox_save_sent_mails == 1) - { - - $folder=str_replace($ref, '', $mailboxconfig->folder_cache_key); - if (!$folder) $folder = "Sent"; // Default Sent folder - - $mailboxconfig->mbox = imap_open($mailboxconfig->get_connector_url().$folder, $mailboxconfig->mailbox_imap_login, $mailboxconfig->mailbox_imap_password); - if (false === $mailboxconfig->mbox) - { - $info = false; - $err = $langs->trans('Error3_Imap_Connection_Error'); - setEventMessages($err,$mailboxconfig->element, null, 'errors'); - } - else - { - $mailboxconfig->mailboxid=$_POST['frommail']; - $mailboxconfig->foldername=$folder; - $from = $mailfromid[0] . $mailfromid[2]; - $imap=1; - } - - } - } - } - */ - // Make substitution in email content $substitutionarray = getCommonSubstitutionArray($langs, 0, null, $object); $substitutionarray['__EMAIL__'] = $sendto; @@ -398,38 +343,38 @@ if (($action == 'send' || $action == 'relance') && !$_POST['addfile'] && !$_POST $subject = make_substitutions($subject, $substitutionarray); $message = make_substitutions($message, $substitutionarray); - if (method_exists($object, 'makeSubstitution')) - { + if (method_exists($object, 'makeSubstitution')) { $subject = $object->makeSubstitution($subject); $message = $object->makeSubstitution($message); } // Send mail (substitutionarray must be done just before this) - if (empty($sendcontext)) $sendcontext = 'standard'; + if (empty($sendcontext)) { + $sendcontext = 'standard'; + } $mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1, '', '', $trackid, '', $sendcontext); - if ($mailfile->error) - { + if ($mailfile->error) { setEventMessages($mailfile->error, $mailfile->errors, 'errors'); $action = 'presend'; } else { $result = $mailfile->sendfile(); - if ($result) - { + if ($result) { // Initialisation of datas of object to call trigger - if (is_object($object)) - { - if (empty($actiontypecode)) $actiontypecode = 'AC_OTH_AUTO'; // Event insert into agenda automatically + if (is_object($object)) { + if (empty($actiontypecode)) { + $actiontypecode = 'AC_OTH_AUTO'; // Event insert into agenda automatically + } $object->socid = $sendtosocid; // To link to a company $object->sendtoid = $sendtoid; // To link to contact-addresses. This is an array. $object->actiontypecode = $actiontypecode; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...) $object->actionmsg = $actionmsg; // Long text (@todo Replace this with $message, we already have details of email in dedicated properties) - $object->actionmsg2 = $actionmsg2; // Short text ($langs->transnoentities('MailSentBy')...); + $object->actionmsg2 = $actionmsg2; // Short text ($langs->transnoentities('MailSentBy')...); $object->trackid = $trackid; - $object->fk_element = $object->id; - $object->elementtype = $object->element; + $object->fk_element = $object->id; + $object->elementtype = $object->element; if (is_array($attachedfiles) && count($attachedfiles) > 0) { $object->attachedfiles = $attachedfiles; } @@ -447,11 +392,12 @@ if (($action == 'send' || $action == 'relance') && !$_POST['addfile'] && !$_POST $object->email_msgid = $mailfile->msgid; // Call of triggers (you should have set $triggersendname to execute trigger. $trigger_name is deprecated) - if (!empty($triggersendname) || !empty($trigger_name)) - { + if (!empty($triggersendname) || !empty($trigger_name)) { // Call trigger $result = $object->call_trigger(empty($triggersendname) ? $trigger_name : $triggersendname, $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } // End call triggers if ($error) { @@ -466,10 +412,12 @@ if (($action == 'send' || $action == 'relance') && !$_POST['addfile'] && !$_POST $mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($sendto, 2)); setEventMessages($mesg, null, 'mesgs'); - $moreparam = ''; - if (isset($paramname2) || isset($paramval2)) $moreparam .= '&'.($paramname2 ? $paramname2 : 'mid').'='.$paramval2; - header('Location: '.$_SERVER["PHP_SELF"].'?'.($paramname ? $paramname : 'id').'='.(is_object($object) ? $object->id : '').$moreparam); - exit; + $moreparam = ''; + if (isset($paramname2) || isset($paramval2)) { + $moreparam .= '&'.($paramname2 ? $paramname2 : 'mid').'='.$paramval2; + } + header('Location: '.$_SERVER["PHP_SELF"].'?'.($paramname ? $paramname : 'id').'='.(is_object($object) ? $object->id : '').$moreparam); + exit; } else { $langs->load("other"); $mesg = '
'; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 7be97293938..20721b8ea05 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -6668,8 +6668,7 @@ class Form }); '; - if ($acceptdelayedhtml) - { + if ($acceptdelayedhtml) { $delayedhtmlcontent .= $outdelayed; } else { $out .= $outdelayed; @@ -6707,24 +6706,20 @@ class Form } // Add code for jquery to use multiselect - if (!empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) || defined('REQUIRE_JQUERY_MULTISELECT')) - { + if (!empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) || defined('REQUIRE_JQUERY_MULTISELECT')) { $out .= "\n".'