36 if (
GETPOST(
'addfile',
'alpha'))
38 $trackid =
GETPOST(
'trackid',
'aZ09');
40 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
43 $vardir = $conf->user->dir_output.
"/".$user->id;
44 $upload_dir_tmp = $vardir.
'/temp';
53 if (!empty($_POST[
'removedfile']) && empty($_POST[
'removAll']))
55 $trackid =
GETPOST(
'trackid',
'aZ09');
57 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
60 $vardir = $conf->user->dir_output.
"/".$user->id;
61 $upload_dir_tmp = $vardir.
'/temp';
72 if (
GETPOST(
'removAll',
'alpha'))
74 $trackid =
GETPOST(
'trackid',
'aZ09');
76 $listofpaths = array();
77 $listofnames = array();
78 $listofmimes = array();
79 $keytoavoidconflict = empty($trackid) ?
'' :
'-'.$trackid;
80 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
81 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
82 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
84 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
86 $formmail->trackid = $trackid;
88 foreach ($listofpaths as $key => $value)
90 $pathtodelete = $value;
91 $filetodelete = $listofnames[$key];
94 $langs->load(
"other");
95 setEventMessages($langs->trans(
"FileWasRemoved", $filetodelete), null,
'mesgs');
97 $formmail->remove_attached_files($key);
104 if (($action ==
'send' || $action ==
'relance') && !$_POST[
'addfile'] && !$_POST[
'removAll'] && !$_POST[
'removedfile'] && !$_POST[
'cancel'] && !$_POST[
'modelselected'])
106 if (empty($trackid)) $trackid =
GETPOST(
'trackid',
'aZ09');
108 $subject =
''; $actionmsg =
''; $actionmsg2 =
'';
110 $langs->load(
'mails');
112 if (is_object($object))
114 $result = $object->fetch($id);
117 if (method_exists($object,
"fetch_thirdparty") && !in_array($object->element, array(
'member',
'user',
'expensereport',
'societe',
'contact')))
119 $resultthirdparty = $object->fetch_thirdparty();
120 $thirdparty = $object->thirdparty;
121 if (is_object($thirdparty)) $sendtosocid = $thirdparty->id;
122 } elseif ($object->element ==
'member' || $object->element ==
'user')
124 $thirdparty = $object;
125 if ($object->socid > 0) $sendtosocid = $object->socid;
126 } elseif ($object->element ==
'expensereport')
128 $tmpuser =
new User($db);
129 $tmpuser->fetch($object->fk_user_author);
130 $thirdparty = $tmpuser;
131 if ($object->socid > 0) $sendtosocid = $object->socid;
132 } elseif ($object->element ==
'societe')
134 $thirdparty = $object;
135 if (is_object($thirdparty) && $thirdparty->id > 0) $sendtosocid = $thirdparty->id;
136 } elseif ($object->element ==
'contact')
139 if ($contact->id > 0) {
140 $contact->fetch_thirdparty();
141 $thirdparty = $contact->thirdparty;
142 if (is_object($thirdparty) && $thirdparty->id > 0) $sendtosocid = $thirdparty->id;
144 }
else dol_print_error(
'',
"Use actions_sendmails.in.php for an element/object '".$object->element.
"' that is not supported");
146 if (is_object($hookmanager))
148 $parameters = array();
149 $reshook = $hookmanager->executeHooks(
'initSendToSocid', $parameters, $object, $action);
152 $thirdparty = $mysoc;
161 $sendtouserid = array();
162 $sendtoccuserid = array();
165 $receiver = $_POST[
'receiver'];
166 if (!is_array($receiver))
168 if ($receiver ==
'-1') $receiver = array();
169 else $receiver = array($receiver);
173 if (trim($_POST[
'sendto']))
176 $tmparray[] = trim($_POST[
'sendto']);
179 if (count($receiver) > 0)
182 foreach ($receiver as $key=>$val)
184 if ($val ==
'thirdparty')
186 $tmparray[] =
dol_string_nospecial($thirdparty->getFullName($langs),
' ', array(
",")).
' <'.$thirdparty->email.
'>';
188 elseif ($val ==
'contact')
190 $tmparray[] =
dol_string_nospecial($contact->getFullName($langs),
' ', array(
",")).
' <'.$contact->email.
'>';
191 $sendtoid[] = $contact->id;
194 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
195 $sendtoid[] = ((int) $val);
200 if (!empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT))
202 $receiveruser = $_POST[
'receiveruser'];
203 if (is_array($receiveruser) && count($receiveruser) > 0)
205 $fuserdest =
new User($db);
206 foreach ($receiveruser as $key=>$val)
208 $tmparray[] = $fuserdest->user_get_property($val,
'email');
209 $sendtouserid[] = $val;
214 $sendto = implode(
',', $tmparray);
217 $receivercc = $_POST[
'receivercc'];
218 if (!is_array($receivercc))
220 if ($receivercc ==
'-1') $receivercc = array();
221 else $receivercc = array($receivercc);
224 if (trim($_POST[
'sendtocc']))
226 $tmparray[] = trim($_POST[
'sendtocc']);
228 if (count($receivercc) > 0)
230 foreach ($receivercc as $key=>$val)
233 if ($val ==
'thirdparty')
235 $tmparray[] =
dol_string_nospecial($thirdparty->name,
' ', array(
",")).
' <'.$thirdparty->email.
'>';
238 elseif ($val ==
'contact')
244 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
249 if (!empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) {
250 $receiverccuser = $_POST[
'receiverccuser'];
252 if (is_array($receiverccuser) && count($receiverccuser) > 0)
254 $fuserdest =
new User($db);
255 foreach ($receiverccuser as $key=>$val)
257 $tmparray[] = $fuserdest->user_get_property($val,
'email');
258 $sendtoccuserid[] = $val;
262 $sendtocc = implode(
',', $tmparray);
267 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
268 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
271 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
273 $langs->load(
"commercial");
276 $fromtype =
GETPOST(
'fromtype',
'alpha');
277 if ($fromtype ===
'robot') {
278 $from =
dol_string_nospecial($conf->global->MAIN_MAIL_EMAIL_FROM,
' ', array(
",")).
' <'.$conf->global->MAIN_MAIL_EMAIL_FROM.
'>';
279 } elseif ($fromtype ===
'user') {
280 $from =
dol_string_nospecial($user->getFullName($langs),
' ', array(
",")).
' <'.$user->email.
'>';
281 } elseif ($fromtype ===
'company') {
282 $from =
dol_string_nospecial($conf->global->MAIN_INFO_SOCIETE_NOM,
' ', array(
",")).
' <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.
'>';
283 } elseif (preg_match(
'/user_aliases_(\d+)/', $fromtype, $reg)) {
284 $tmp = explode(
',', $user->email_aliases);
285 $from = trim($tmp[($reg[1] - 1)]);
286 } elseif (preg_match(
'/global_aliases_(\d+)/', $fromtype, $reg)) {
287 $tmp = explode(
',', $conf->global->MAIN_INFO_SOCIETE_MAIL_ALIASES);
288 $from = trim($tmp[($reg[1] - 1)]);
289 } elseif (preg_match(
'/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) {
290 $sql =
'SELECT rowid, label, email FROM '.MAIN_DB_PREFIX.
'c_email_senderprofile';
291 $sql .=
' WHERE rowid = '.(int) $reg[1];
292 $resql = $db->query($sql);
293 $obj = $db->fetch_object(
$resql);
302 $replyto =
dol_string_nospecial($_POST[
'replytoname'],
' ', array(
",")).
' <'.$_POST[
'replytomail'].
'>';
303 $message =
GETPOST(
'message',
'restricthtml');
304 $subject =
GETPOST(
'subject',
'restricthtml');
310 $message = preg_replace(
'/(<img.*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^\/]*\/>)/',
'\1'.$urlwithroot.
'/viewimage.php\2modulepart=medias\3file=\4\5', $message);
312 $sendtobcc =
GETPOST(
'sendtoccc');
315 if (!empty($autocopy))
317 $sendtobcc .= (empty($conf->global->$autocopy) ?
'' : (($sendtobcc ?
", " :
"").$conf->global->$autocopy));
320 $deliveryreceipt = $_POST[
'deliveryreceipt'];
322 if ($action ==
'send' || $action ==
'relance')
330 $actionmsg =
dol_concatdesc($actionmsg, $langs->transnoentities(
'MailTopic').
": ".$subject);
331 $actionmsg =
dol_concatdesc($actionmsg, $langs->transnoentities(
'TextUsedInTheMessageBody').
":");
337 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
339 $formmail->trackid = $trackid;
341 $attachedfiles = $formmail->get_attached_files();
342 $filepath = $attachedfiles[
'paths'];
343 $filename = $attachedfiles[
'names'];
344 $mimetype = $attachedfiles[
'mimes'];
392 $substitutionarray[
'__EMAIL__'] = $sendto;
393 $substitutionarray[
'__CHECK_READ__'] = (is_object($object) && is_object($object->thirdparty)) ?
'<img src="'.DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-read.php?tag='.$object->thirdparty->tag.
'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).
'" width="1" height="1" style="width:1px;height:1px" border="0"/>' :
'';
395 $parameters = array(
'mode'=>
'formemail');
401 if (method_exists($object,
'makeSubstitution'))
403 $subject = $object->makeSubstitution($subject);
404 $message = $object->makeSubstitution($message);
408 if (empty($sendcontext)) $sendcontext =
'standard';
409 $mailfile =
new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1,
'',
'', $trackid,
'', $sendcontext);
411 if ($mailfile->error)
416 $result = $mailfile->sendfile();
420 if (is_object($object))
422 if (empty($actiontypecode)) $actiontypecode =
'AC_OTH_AUTO';
424 $object->socid = $sendtosocid;
425 $object->sendtoid = $sendtoid;
426 $object->actiontypecode = $actiontypecode;
427 $object->actionmsg = $actionmsg;
428 $object->actionmsg2 = $actionmsg2;
430 $object->trackid = $trackid;
431 $object->fk_element = $object->id;
432 $object->elementtype = $object->element;
433 if (is_array($attachedfiles) && count($attachedfiles) > 0) {
434 $object->attachedfiles = $attachedfiles;
436 if (is_array($sendtouserid) && count($sendtouserid) > 0 && !empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) {
437 $object->sendtouserid = $sendtouserid;
440 $object->email_msgid = $mailfile->msgid;
441 $object->email_from = $from;
442 $object->email_subject = $subject;
443 $object->email_to = $sendto;
444 $object->email_tocc = $sendtocc;
445 $object->email_tobcc = $sendtobcc;
446 $object->email_subject = $subject;
447 $object->email_msgid = $mailfile->msgid;
450 if (!empty($triggersendname) || !empty($trigger_name))
453 $result = $object->call_trigger(empty($triggersendname) ? $trigger_name : $triggersendname, $user);
454 if ($result < 0) $error++;
466 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($sendto, 2));
470 if (isset($paramname2) || isset($paramval2)) $moreparam .=
'&'.($paramname2 ? $paramname2 :
'mid').
'='.$paramval2;
471 header(
'Location: '.
$_SERVER[
"PHP_SELF"].
'?'.($paramname ? $paramname :
'id').
'='.(is_object($object) ? $object->id :
'').$moreparam);
474 $langs->load(
"other");
475 $mesg =
'<div class="error">';
476 if ($mailfile->error) {
478 $mesg .=
'<br>'.$mailfile->error;
481 if (!empty($conf->global->MAIN_DISABLE_ALL_MAILS)) {
482 $mesg .=
'<br>Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
484 $mesg .=
'<br>Unkown Error, please refers to your administrator';
494 $langs->load(
"errors");
495 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"MailTo")), null,
'warnings');
496 dol_syslog(
'Try to send email with no recipient defined', LOG_WARNING);
500 $langs->load(
"errors");
501 setEventMessages($langs->trans(
'ErrorFailedToReadObject', $object->element), null,
'errors');
502 dol_syslog(
'Failed to read data of object id='.$object->id.
' element='.$object->element);
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage Dolibarr users.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
dol_string_nospecial($str, $newstr= '_', $badcharstoreplace= '')
Clean a string from all punctuation characters to use it as a ref or login.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
static getValidAddress($address, $format, $encode=0, $maxnumberofemail=0)
Return a formatted address string for SMTP protocol.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to,$css,$trackid,$moreinheader,$sendcontext,$replyto); $mailfile->sendfile();.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1)
Remove a file or several files with a mask.
dol_remove_file_process($filenb, $donotupdatesession=0, $donotdeletefile=1, $trackid= '')
Remove an uploaded file (for example after submitting a new file a mail form).
print $_SERVER["PHP_SELF"]
Edit parameters.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
make_substitutions($text, $substitutionarray, $outputlangs=null)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesession=0, $varfiles= 'addedfile', $savingdocmask= '', $link=null, $trackid= '', $generatethumbs=1, $object=null)
Get and save an upload file (for example after submitting a new file a mail form).
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...