Merge pull request #15855 from frederic34/cleancode

remove unused code
This commit is contained in:
Laurent Destailleur 2021-01-02 15:56:45 +01:00 committed by GitHub
commit 342fed350c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 181 additions and 211 deletions

View File

@ -33,8 +33,7 @@
/* /*
* Add file in email form * Add file in email form
*/ */
if (GETPOST('addfile', 'alpha')) if (GETPOST('addfile', 'alpha')) {
{
$trackid = GETPOST('trackid', 'aZ09'); $trackid = GETPOST('trackid', 'aZ09');
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
@ -50,8 +49,7 @@ if (GETPOST('addfile', 'alpha'))
/* /*
* Remove file in email form * Remove file in email form
*/ */
if (!empty($_POST['removedfile']) && empty($_POST['removAll'])) if (!empty($_POST['removedfile']) && empty($_POST['removAll'])) {
{
$trackid = GETPOST('trackid', 'aZ09'); $trackid = GETPOST('trackid', 'aZ09');
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; 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 * Remove all files in email form
*/ */
if (GETPOST('removAll', 'alpha')) if (GETPOST('removAll', 'alpha')) {
{
$trackid = GETPOST('trackid', 'aZ09'); $trackid = GETPOST('trackid', 'aZ09');
$listofpaths = array(); $listofpaths = array();
$listofnames = array(); $listofnames = array();
$listofmimes = array(); $listofmimes = array();
$keytoavoidconflict = empty($trackid) ? '' : '-'.$trackid; $keytoavoidconflict = empty($trackid) ? '' : '-'.$trackid;
if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]); if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) {
if (!empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]); $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]);
if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes = explode(';', $_SESSION["listofmimes".$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'; include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
$formmail = new FormMail($db); $formmail = new FormMail($db);
$formmail->trackid = $trackid; $formmail->trackid = $trackid;
foreach ($listofpaths as $key => $value) foreach ($listofpaths as $key => $value) {
{
$pathtodelete = $value; $pathtodelete = $value;
$filetodelete = $listofnames[$key]; $filetodelete = $listofnames[$key];
$result = dol_delete_file($pathtodelete, 1); // Delete uploded Files $result = dol_delete_file($pathtodelete, 1); // Delete uploded Files
@ -101,50 +103,56 @@ if (GETPOST('removAll', 'alpha'))
/* /*
* Send mail * Send mail
*/ */
if (($action == 'send' || $action == 'relance') && !$_POST['addfile'] && !$_POST['removAll'] && !$_POST['removedfile'] && !$_POST['cancel'] && !$_POST['modelselected']) if (($action == 'send' || $action == 'relance') && !$_POST['addfile'] && !$_POST['removAll'] && !$_POST['removedfile'] && !$_POST['cancel'] && !$_POST['modelselected']) {
{ if (empty($trackid)) {
if (empty($trackid)) $trackid = GETPOST('trackid', 'aZ09'); $trackid = GETPOST('trackid', 'aZ09');
}
$subject = ''; $actionmsg = ''; $actionmsg2 = ''; $subject = ''; $actionmsg = ''; $actionmsg2 = '';
$langs->load('mails'); $langs->load('mails');
if (is_object($object)) if (is_object($object)) {
{
$result = $object->fetch($id); $result = $object->fetch($id);
$sendtosocid = 0; // Id of related thirdparty $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(); $resultthirdparty = $object->fetch_thirdparty();
$thirdparty = $object->thirdparty; $thirdparty = $object->thirdparty;
if (is_object($thirdparty)) $sendtosocid = $thirdparty->id; if (is_object($thirdparty)) {
} elseif ($object->element == 'member' || $object->element == 'user') $sendtosocid = $thirdparty->id;
{ }
} elseif ($object->element == 'member' || $object->element == 'user') {
$thirdparty = $object; $thirdparty = $object;
if ($object->socid > 0) $sendtosocid = $object->socid; if ($object->socid > 0) {
} elseif ($object->element == 'expensereport') $sendtosocid = $object->socid;
{ }
} elseif ($object->element == 'expensereport') {
$tmpuser = new User($db); $tmpuser = new User($db);
$tmpuser->fetch($object->fk_user_author); $tmpuser->fetch($object->fk_user_author);
$thirdparty = $tmpuser; $thirdparty = $tmpuser;
if ($object->socid > 0) $sendtosocid = $object->socid; if ($object->socid > 0) {
} elseif ($object->element == 'societe') $sendtosocid = $object->socid;
{ }
} elseif ($object->element == 'societe') {
$thirdparty = $object; $thirdparty = $object;
if (is_object($thirdparty) && $thirdparty->id > 0) $sendtosocid = $thirdparty->id; if (is_object($thirdparty) && $thirdparty->id > 0) {
} elseif ($object->element == 'contact') $sendtosocid = $thirdparty->id;
{ }
} elseif ($object->element == 'contact') {
$contact = $object; $contact = $object;
if ($contact->id > 0) { if ($contact->id > 0) {
$contact->fetch_thirdparty(); $contact->fetch_thirdparty();
$thirdparty = $contact->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(); $parameters = array();
$reshook = $hookmanager->executeHooks('initSendToSocid', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks $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; $thirdparty = $mysoc;
} }
if ($result > 0) if ($result > 0) {
{
$sendto = ''; $sendto = '';
$sendtocc = ''; $sendtocc = '';
$sendtobcc = ''; $sendtobcc = '';
@ -163,48 +170,40 @@ if (($action == 'send' || $action == 'relance') && !$_POST['addfile'] && !$_POST
// Define $sendto // Define $sendto
$receiver = $_POST['receiver']; $receiver = $_POST['receiver'];
if (!is_array($receiver)) if (!is_array($receiver)) {
{ if ($receiver == '-1') {
if ($receiver == '-1') $receiver = array(); $receiver = array();
else $receiver = array($receiver); } else {
$receiver = array($receiver);
}
} }
$tmparray = array(); $tmparray = array();
if (trim($_POST['sendto'])) if (trim($_POST['sendto'])) {
{
// Recipients are provided into free text // Recipients are provided into free text
$tmparray[] = trim($_POST['sendto']); $tmparray[] = trim($_POST['sendto']);
} }
if (count($receiver) > 0) if (count($receiver) > 0) {
{
// Recipient was provided from combo list // Recipient was provided from combo list
foreach ($receiver as $key=>$val) 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)
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.'>'; $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.'>'; $tmparray[] = dol_string_nospecial($contact->getFullName($langs), ' ', array(",")).' <'.$contact->email.'>';
$sendtoid[] = $contact->id; $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'); $tmparray[] = $thirdparty->contact_get_property((int) $val, 'email');
$sendtoid[] = ((int) $val); $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']; $receiveruser = $_POST['receiveruser'];
if (is_array($receiveruser) && count($receiveruser) > 0) if (is_array($receiveruser) && count($receiveruser) > 0) {
{
$fuserdest = new User($db); $fuserdest = new User($db);
foreach ($receiveruser as $key=>$val) foreach ($receiveruser as $key => $val) {
{
$tmparray[] = $fuserdest->user_get_property($val, 'email'); $tmparray[] = $fuserdest->user_get_property($val, 'email');
$sendtouserid[] = $val; $sendtouserid[] = $val;
} }
@ -215,32 +214,27 @@ if (($action == 'send' || $action == 'relance') && !$_POST['addfile'] && !$_POST
// Define $sendtocc // Define $sendtocc
$receivercc = $_POST['receivercc']; $receivercc = $_POST['receivercc'];
if (!is_array($receivercc)) if (!is_array($receivercc)) {
{ if ($receivercc == '-1') {
if ($receivercc == '-1') $receivercc = array(); $receivercc = array();
else $receivercc = array($receivercc); } else {
$receivercc = array($receivercc);
}
} }
$tmparray = array(); $tmparray = array();
if (trim($_POST['sendtocc'])) if (trim($_POST['sendtocc'])) {
{
$tmparray[] = trim($_POST['sendtocc']); $tmparray[] = trim($_POST['sendtocc']);
} }
if (count($receivercc) > 0) if (count($receivercc) > 0) {
{ foreach ($receivercc as $key => $val) {
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 // Recipient was provided from combo list
if ($val == 'thirdparty') // Key selected means currentthird party (may be usd for current member or current user too)
{
$tmparray[] = dol_string_nospecial($thirdparty->name, ' ', array(",")).' <'.$thirdparty->email.'>'; $tmparray[] = dol_string_nospecial($thirdparty->name, ' ', array(",")).' <'.$thirdparty->email.'>';
} } elseif ($val == 'contact') { // Key selected means current contact
// Recipient was provided from combo list // Recipient was provided from combo list
elseif ($val == 'contact') // Key selected means current contact
{
$tmparray[] = dol_string_nospecial($contact->name, ' ', array(",")).' <'.$contact->email.'>'; $tmparray[] = dol_string_nospecial($contact->name, ' ', array(",")).' <'.$contact->email.'>';
//$sendtoid[] = $contact->id; TODO Add also id of contact in CC ? //$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'); $tmparray[] = $thirdparty->contact_get_property((int) $val, 'email');
//$sendtoid[] = ((int) $val); TODO Add also id of contact in CC ? //$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)) { if (!empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) {
$receiverccuser = $_POST['receiverccuser']; $receiverccuser = $_POST['receiverccuser'];
if (is_array($receiverccuser) && count($receiverccuser) > 0) if (is_array($receiverccuser) && count($receiverccuser) > 0) {
{
$fuserdest = new User($db); $fuserdest = new User($db);
foreach ($receiverccuser as $key=>$val) foreach ($receiverccuser as $key => $val) {
{
$tmparray[] = $fuserdest->user_get_property($val, 'email'); $tmparray[] = $fuserdest->user_get_property($val, 'email');
$sendtoccuserid[] = $val; $sendtoccuserid[] = $val;
} }
@ -261,8 +253,7 @@ if (($action == 'send' || $action == 'relance') && !$_POST['addfile'] && !$_POST
} }
$sendtocc = implode(',', $tmparray); $sendtocc = implode(',', $tmparray);
if (dol_strlen($sendto)) if (dol_strlen($sendto)) {
{
// Define $urlwithroot // Define $urlwithroot
$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); $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 $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]; $sql .= ' WHERE rowid = '.(int) $reg[1];
$resql = $db->query($sql); $resql = $db->query($sql);
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
if ($obj) if ($obj) {
{
$from = dol_string_nospecial($obj->label, ' ', array(",")).' <'.$obj->email.'>'; $from = dol_string_nospecial($obj->label, ' ', array(",")).' <'.$obj->email.'>';
} }
} else { } else {
@ -312,21 +302,20 @@ if (($action == 'send' || $action == 'relance') && !$_POST['addfile'] && !$_POST
$sendtobcc = GETPOST('sendtoccc'); $sendtobcc = GETPOST('sendtoccc');
// Autocomplete the $sendtobcc // 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... // $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)); $sendtobcc .= (empty($conf->global->$autocopy) ? '' : (($sendtobcc ? ", " : "").$conf->global->$autocopy));
} }
$deliveryreceipt = $_POST['deliveryreceipt']; $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); $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 = $langs->transnoentities('MailFrom').': '.dol_escape_htmltag($from);
$actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTo').': '.dol_escape_htmltag($sendto)); $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('MailTopic').": ".$subject);
$actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody').":"); $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody').":");
$actionmsg = dol_concatdesc($actionmsg, $message); $actionmsg = dol_concatdesc($actionmsg, $message);
@ -343,50 +332,6 @@ if (($action == 'send' || $action == 'relance') && !$_POST['addfile'] && !$_POST
$filename = $attachedfiles['names']; $filename = $attachedfiles['names'];
$mimetype = $attachedfiles['mimes']; $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# <aaa@aaa.com>' // 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 // Make substitution in email content
$substitutionarray = getCommonSubstitutionArray($langs, 0, null, $object); $substitutionarray = getCommonSubstitutionArray($langs, 0, null, $object);
$substitutionarray['__EMAIL__'] = $sendto; $substitutionarray['__EMAIL__'] = $sendto;
@ -398,28 +343,28 @@ if (($action == 'send' || $action == 'relance') && !$_POST['addfile'] && !$_POST
$subject = make_substitutions($subject, $substitutionarray); $subject = make_substitutions($subject, $substitutionarray);
$message = make_substitutions($message, $substitutionarray); $message = make_substitutions($message, $substitutionarray);
if (method_exists($object, 'makeSubstitution')) if (method_exists($object, 'makeSubstitution')) {
{
$subject = $object->makeSubstitution($subject); $subject = $object->makeSubstitution($subject);
$message = $object->makeSubstitution($message); $message = $object->makeSubstitution($message);
} }
// Send mail (substitutionarray must be done just before this) // 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); $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'); setEventMessages($mailfile->error, $mailfile->errors, 'errors');
$action = 'presend'; $action = 'presend';
} else { } else {
$result = $mailfile->sendfile(); $result = $mailfile->sendfile();
if ($result) if ($result) {
{
// Initialisation of datas of object to call trigger // Initialisation of datas of object to call trigger
if (is_object($object)) if (is_object($object)) {
{ if (empty($actiontypecode)) {
if (empty($actiontypecode)) $actiontypecode = 'AC_OTH_AUTO'; // Event insert into agenda automatically $actiontypecode = 'AC_OTH_AUTO'; // Event insert into agenda automatically
}
$object->socid = $sendtosocid; // To link to a company $object->socid = $sendtosocid; // To link to a company
$object->sendtoid = $sendtoid; // To link to contact-addresses. This is an array. $object->sendtoid = $sendtoid; // To link to contact-addresses. This is an array.
@ -447,11 +392,12 @@ if (($action == 'send' || $action == 'relance') && !$_POST['addfile'] && !$_POST
$object->email_msgid = $mailfile->msgid; $object->email_msgid = $mailfile->msgid;
// Call of triggers (you should have set $triggersendname to execute trigger. $trigger_name is deprecated) // 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 // Call trigger
$result = $object->call_trigger(empty($triggersendname) ? $trigger_name : $triggersendname, $user); $result = $object->call_trigger(empty($triggersendname) ? $trigger_name : $triggersendname, $user);
if ($result < 0) $error++; if ($result < 0) {
$error++;
}
// End call triggers // End call triggers
if ($error) { if ($error) {
@ -467,7 +413,9 @@ if (($action == 'send' || $action == 'relance') && !$_POST['addfile'] && !$_POST
setEventMessages($mesg, null, 'mesgs'); setEventMessages($mesg, null, 'mesgs');
$moreparam = ''; $moreparam = '';
if (isset($paramname2) || isset($paramval2)) $moreparam .= '&'.($paramname2 ? $paramname2 : 'mid').'='.$paramval2; if (isset($paramname2) || isset($paramval2)) {
$moreparam .= '&'.($paramname2 ? $paramname2 : 'mid').'='.$paramval2;
}
header('Location: '.$_SERVER["PHP_SELF"].'?'.($paramname ? $paramname : 'id').'='.(is_object($object) ? $object->id : '').$moreparam); header('Location: '.$_SERVER["PHP_SELF"].'?'.($paramname ? $paramname : 'id').'='.(is_object($object) ? $object->id : '').$moreparam);
exit; exit;
} else { } else {

View File

@ -6668,8 +6668,7 @@ class Form
}); });
</script>'; </script>';
if ($acceptdelayedhtml) if ($acceptdelayedhtml) {
{
$delayedhtmlcontent .= $outdelayed; $delayedhtmlcontent .= $outdelayed;
} else { } else {
$out .= $outdelayed; $out .= $outdelayed;
@ -6707,24 +6706,20 @@ class Form
} }
// Add code for jquery to use multiselect // 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".'<!-- JS CODE TO ENABLE select for id '.$htmlname.' --> $out .= "\n".'<!-- JS CODE TO ENABLE select for id '.$htmlname.' -->
<script>'."\n"; <script>'."\n";
if ($addjscombo == 1) if ($addjscombo == 1) {
{
$tmpplugin = empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) ?constant('REQUIRE_JQUERY_MULTISELECT') : $conf->global->MAIN_USE_JQUERY_MULTISELECT; $tmpplugin = empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) ?constant('REQUIRE_JQUERY_MULTISELECT') : $conf->global->MAIN_USE_JQUERY_MULTISELECT;
$out .= 'function formatResult(record) {'."\n"; $out .= 'function formatResult(record) {'."\n";
if ($elemtype == 'category') if ($elemtype == 'category') {
{
$out .= 'return \'<span><img src="'.DOL_URL_ROOT.'/theme/eldy/img/object_category.png"> \'+record.text+\'</span>\';'; $out .= 'return \'<span><img src="'.DOL_URL_ROOT.'/theme/eldy/img/object_category.png"> \'+record.text+\'</span>\';';
} else { } else {
$out .= 'return record.text;'; $out .= 'return record.text;';
} }
$out .= '};'."\n"; $out .= '};'."\n";
$out .= 'function formatSelection(record) {'."\n"; $out .= 'function formatSelection(record) {'."\n";
if ($elemtype == 'category') if ($elemtype == 'category') {
{
$out .= 'return \'<span><img src="'.DOL_URL_ROOT.'/theme/eldy/img/object_category.png"> \'+record.text+\'</span>\';'; $out .= 'return \'<span><img src="'.DOL_URL_ROOT.'/theme/eldy/img/object_category.png"> \'+record.text+\'</span>\';';
} else { } else {
$out .= 'return record.text;'; $out .= 'return record.text;';
@ -6741,8 +6736,7 @@ class Form
templateSelection: formatSelection /* For 4.0 */ templateSelection: formatSelection /* For 4.0 */
}); });
});'."\n"; });'."\n";
} elseif ($addjscombo == 2 && !defined('DISABLE_MULTISELECT')) } elseif ($addjscombo == 2 && !defined('DISABLE_MULTISELECT')) {
{
// Add other js lib // Add other js lib
// TODO external lib multiselect/jquery.multi-select.js must have been loaded to use this multiselect plugin // TODO external lib multiselect/jquery.multi-select.js must have been loaded to use this multiselect plugin
// ... // ...
@ -6763,20 +6757,18 @@ class Form
// Try also magic suggest // Try also magic suggest
$out .= '<select id="'.$htmlname.'" class="multiselect'.($morecss ? ' '.$morecss : '').'" multiple name="'.$htmlname.'[]"'.($moreattrib ? ' '.$moreattrib : '').($width ? ' style="width: '.(preg_match('/%/', $width) ? $width : $width.'px').'"' : '').'>'."\n"; $out .= '<select id="'.$htmlname.'" class="multiselect'.($morecss ? ' '.$morecss : '').'" multiple name="'.$htmlname.'[]"'.($moreattrib ? ' '.$moreattrib : '').($width ? ' style="width: '.(preg_match('/%/', $width) ? $width : $width.'px').'"' : '').'>'."\n";
if (is_array($array) && !empty($array)) if (is_array($array) && !empty($array)) {
{ if ($value_as_key) {
if ($value_as_key) $array = array_combine($array, $array); $array = array_combine($array, $array);
}
if (!empty($array)) if (!empty($array)) {
{ foreach ($array as $key => $value) {
foreach ($array as $key => $value)
{
$newval = ($translate ? $langs->trans($value) : $value); $newval = ($translate ? $langs->trans($value) : $value);
$newval = ($key_in_label ? $key.' - '.$newval : $newval); $newval = ($key_in_label ? $key.' - '.$newval : $newval);
$out .= '<option value="'.$key.'"'; $out .= '<option value="'.$key.'"';
if (is_array($selected) && !empty($selected) && in_array((string) $key, $selected) && ((string) $key != '')) if (is_array($selected) && !empty($selected) && in_array((string) $key, $selected) && ((string) $key != '')) {
{
$out .= ' selected'; $out .= ' selected';
} }
$out .= ' data-html="'.dol_escape_htmltag($newval).'"'; $out .= ' data-html="'.dol_escape_htmltag($newval).'"';
@ -6805,36 +6797,36 @@ class Form
{ {
global $conf, $langs, $user, $extrafields; global $conf, $langs, $user, $extrafields;
if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) return ''; if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
return '';
}
$tmpvar = "MAIN_SELECTEDFIELDS_".$varpage; // To get list of saved seleteced properties $tmpvar = "MAIN_SELECTEDFIELDS_".$varpage; // To get list of saved seleteced properties
if (!empty($user->conf->$tmpvar)) if (!empty($user->conf->$tmpvar)) {
{
$tmparray = explode(',', $user->conf->$tmpvar); $tmparray = explode(',', $user->conf->$tmpvar);
foreach ($array as $key => $val) foreach ($array as $key => $val) {
{
//var_dump($key); //var_dump($key);
//var_dump($tmparray); //var_dump($tmparray);
if (in_array($key, $tmparray)) $array[$key]['checked'] = 1; if (in_array($key, $tmparray)) {
else $array[$key]['checked'] = 0; $array[$key]['checked'] = 1;
} else {
$array[$key]['checked'] = 0;
}
} }
} }
$lis = ''; $lis = '';
$listcheckedstring = ''; $listcheckedstring = '';
foreach ($array as $key => $val) foreach ($array as $key => $val) {
{
/* var_dump($val); /* var_dump($val);
var_dump(array_key_exists('enabled', $val)); var_dump(array_key_exists('enabled', $val));
var_dump(!$val['enabled']);*/ var_dump(!$val['enabled']);*/
if (array_key_exists('enabled', $val) && isset($val['enabled']) && !$val['enabled']) if (array_key_exists('enabled', $val) && isset($val['enabled']) && !$val['enabled']) {
{
unset($array[$key]); // We don't want this field unset($array[$key]); // We don't want this field
continue; continue;
} }
if ($val['label']) if ($val['label']) {
{
if (!empty($val['langfile']) && is_object($langs)) { if (!empty($val['langfile']) && is_object($langs)) {
$langs->load($val['langfile']); $langs->load($val['langfile']);
} }

View File

@ -120,8 +120,16 @@ class FormMail extends Form
public $withtocc; public $withtocc;
public $withtoccc; public $withtoccc;
public $withtopic; public $withtopic;
public $withfile; // 0=No attaches files, 1=Show attached files, 2=Can add new attached files
public $withmaindocfile; // 1=Add a checkbox "Attach also main document" for mass actions (checked by default), -1=Add checkbox (not checked by default) /**
* @var int 0=No attaches files, 1=Show attached files, 2=Can add new attached files
*/
public $withfile;
/**
* @var int 1=Add a checkbox "Attach also main document" for mass actions (checked by default), -1=Add checkbox (not checked by default)
*/
public $withmaindocfile;
public $withbody; public $withbody;
public $withfromreadonly; public $withfromreadonly;
@ -195,7 +203,9 @@ class FormMail extends Form
// Set tmp user directory // Set tmp user directory
$vardir = $conf->user->dir_output."/".$user->id; $vardir = $conf->user->dir_output."/".$user->id;
$upload_dir = $vardir.'/temp/'; // TODO Add $keytoavoidconflict in upload_dir path $upload_dir = $vardir.'/temp/'; // TODO Add $keytoavoidconflict in upload_dir path
if (is_dir($upload_dir)) dol_delete_dir_recursive($upload_dir); if (is_dir($upload_dir)) {
dol_delete_dir_recursive($upload_dir);
}
$keytoavoidconflict = empty($this->trackid) ? '' : '-'.$this->trackid; // this->trackid must be defined $keytoavoidconflict = empty($this->trackid) ? '' : '-'.$this->trackid; // this->trackid must be defined
unset($_SESSION["listofpaths".$keytoavoidconflict]); unset($_SESSION["listofpaths".$keytoavoidconflict]);
@ -219,15 +229,24 @@ class FormMail extends Form
$listofnames = array(); $listofnames = array();
$listofmimes = array(); $listofmimes = array();
if (empty($file)) $file = basename($path); if (empty($file)) {
if (empty($type)) $type = dol_mimetype($file); $file = basename($path);
}
if (empty($type)) {
$type = dol_mimetype($file);
}
$keytoavoidconflict = empty($this->trackid) ? '' : '-'.$this->trackid; // this->trackid must be defined $keytoavoidconflict = empty($this->trackid) ? '' : '-'.$this->trackid; // this->trackid must be defined
if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]); if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) {
if (!empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]); $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]);
if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]); }
if (!in_array($file, $listofnames)) if (!empty($_SESSION["listofnames".$keytoavoidconflict])) {
{ $listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]);
}
if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) {
$listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]);
}
if (!in_array($file, $listofnames)) {
$listofpaths[] = $path; $listofpaths[] = $path;
$listofnames[] = $file; $listofnames[] = $file;
$listofmimes[] = $type; $listofmimes[] = $type;
@ -252,11 +271,16 @@ class FormMail extends Form
$listofmimes = array(); $listofmimes = array();
$keytoavoidconflict = empty($this->trackid) ? '' : '-'.$this->trackid; // this->trackid must be defined $keytoavoidconflict = empty($this->trackid) ? '' : '-'.$this->trackid; // this->trackid must be defined
if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]); if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) {
if (!empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]); $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]);
if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]); }
if ($keytodelete >= 0) if (!empty($_SESSION["listofnames".$keytoavoidconflict])) {
{ $listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]);
}
if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) {
$listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]);
}
if ($keytodelete >= 0) {
unset($listofpaths[$keytodelete]); unset($listofpaths[$keytodelete]);
unset($listofnames[$keytodelete]); unset($listofnames[$keytodelete]);
unset($listofmimes[$keytodelete]); unset($listofmimes[$keytodelete]);
@ -281,9 +305,15 @@ class FormMail extends Form
$listofmimes = array(); $listofmimes = array();
$keytoavoidconflict = empty($this->trackid) ? '' : '-'.$this->trackid; // this->trackid must be defined $keytoavoidconflict = empty($this->trackid) ? '' : '-'.$this->trackid; // this->trackid must be defined
if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]); if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) {
if (!empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]); $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]);
if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]); }
if (!empty($_SESSION["listofnames".$keytoavoidconflict])) {
$listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]);
}
if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) {
$listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]);
}
return array('paths'=>$listofpaths, 'names'=>$listofnames, 'mimes'=>$listofmimes); return array('paths'=>$listofpaths, 'names'=>$listofnames, 'mimes'=>$listofmimes);
} }