34@phan-var-force Societe $mysoc
35@phan-var-force CommonObject $object
41if (
GETPOST(
'addfile',
'alpha')) {
42 $trackid =
GETPOST(
'trackid',
'aZ09');
44 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
47 $vardir = $conf->user->dir_output.
"/".$user->id;
48 $upload_dir_tmp = $vardir.
'/temp';
58 $trackid =
GETPOST(
'trackid',
'aZ09');
60 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
63 $vardir = $conf->user->dir_output.
"/".$user->id;
64 $upload_dir_tmp = $vardir.
'/temp';
75if (
GETPOST(
'removAll',
'alpha')) {
76 $trackid =
GETPOST(
'trackid',
'aZ09');
78 $listofpaths = array();
79 $listofnames = array();
80 $listofmimes = array();
81 $keytoavoidconflict = empty($trackid) ?
'' :
'-'.$trackid;
82 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) {
83 $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
85 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) {
86 $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
88 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) {
89 $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
92 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
94 $formmail->trackid = $trackid;
96 foreach ($listofpaths as $key => $value) {
97 $pathtodelete = $value;
98 $filetodelete = $listofnames[$key];
101 $langs->load(
"other");
102 setEventMessages($langs->trans(
"FileWasRemoved", $filetodelete),
null,
'mesgs');
104 $formmail->remove_attached_files($key);
111if (($action ==
'send' || $action ==
'relance') && !
GETPOST(
'addfile') && !
GETPOST(
'removAll') && !
GETPOST(
'removedfile') && !
GETPOST(
'cancel') && !
GETPOST(
'modelselected')) {
112 if (empty($trackid)) {
113 $trackid =
GETPOST(
'trackid',
'aZ09');
117 $vardir = $conf->user->dir_output.
"/".$user->id;
118 $upload_dir_tmp = $vardir.
'/temp';
124 $langs->load(
'mails');
130 if (method_exists(
$object,
"fetch_thirdparty") && !in_array(
$object->element, array(
'member',
'user',
'expensereport',
'societe',
'contact'))) {
131 $resultthirdparty =
$object->fetch_thirdparty();
132 $thirdparty =
$object->thirdparty;
133 if (is_object($thirdparty)) {
134 $sendtosocid = $thirdparty->id;
136 } elseif (
$object->element ==
'member' ||
$object->element ==
'user') {
141 } elseif (
$object->element ==
'expensereport') {
142 $tmpuser =
new User($db);
143 $tmpuser->fetch(
$object->fk_user_author);
144 $thirdparty = $tmpuser;
148 } elseif (
$object->element ==
'societe') {
150 if (is_object($thirdparty) && $thirdparty->id > 0) {
151 $sendtosocid = $thirdparty->id;
153 } elseif (
$object->element ==
'contact') {
155 if ($contact->id > 0) {
156 $contact->fetch_thirdparty();
157 $thirdparty = $contact->thirdparty;
158 if (is_object($thirdparty) && $thirdparty->id > 0) {
159 $sendtosocid = $thirdparty->id;
163 dol_print_error(
null,
"Use actions_sendmails.in.php for an element/object '".
$object->element.
"' that is not supported");
166 if (is_object($hookmanager)) {
167 $parameters = array();
168 $reshook = $hookmanager->executeHooks(
'initSendToSocid', $parameters,
$object, $action);
171 $thirdparty = $mysoc;
179 $sendtouserid = array();
180 $sendtoccuserid = array();
183 $receiver =
GETPOST(
'receiver',
'alphawithlgt');
184 if (!is_array($receiver)) {
185 if ($receiver ==
'-1') {
188 $receiver = array($receiver);
193 if (trim(
GETPOST(
'sendto',
'alphawithlgt'))) {
195 $tmparray[] = trim(
GETPOST(
'sendto',
'alphawithlgt'));
198 if (trim(
GETPOST(
'tomail',
'alphawithlgt'))) {
200 $tmparray[] = trim(
GETPOST(
'tomail',
'alphawithlgt'));
203 if (count($receiver) > 0) {
205 foreach ($receiver as $key => $val) {
206 if ($val ==
'thirdparty') {
207 $tmparray[] =
dol_string_nospecial($thirdparty->getFullName($langs),
' ', array(
",")).
' <'.$thirdparty->email.
'>';
208 } elseif ($val ==
'contact') {
209 $tmparray[] =
dol_string_nospecial($contact->getFullName($langs),
' ', array(
",")).
' <'.$contact->email.
'>';
210 $sendtoid[] = $contact->id;
212 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
213 $sendtoid[] = ((int) $val);
219 $receiveruser =
GETPOST(
'receiveruser',
'alphawithlgt');
220 if (is_array($receiveruser) && count($receiveruser) > 0) {
221 $fuserdest =
new User($db);
222 foreach ($receiveruser as $key => $val) {
223 $tmparray[] = $fuserdest->user_get_property($val,
'email');
224 $sendtouserid[] = $val;
229 $sendto = implode(
',', $tmparray);
232 $receivercc =
GETPOST(
'receivercc',
'alphawithlgt');
233 if (!is_array($receivercc)) {
234 if ($receivercc ==
'-1') {
235 $receivercc = array();
237 $receivercc = array($receivercc);
241 if (trim(
GETPOST(
'sendtocc',
'alphawithlgt'))) {
242 $tmparray[] = trim(
GETPOST(
'sendtocc',
'alphawithlgt'));
244 if (count($receivercc) > 0) {
245 foreach ($receivercc as $key => $val) {
246 if ($val ==
'thirdparty') {
248 $tmparray[] =
dol_string_nospecial($thirdparty->name,
' ', array(
",")).
' <'.$thirdparty->email.
'>';
249 } elseif ($val ==
'contact') {
254 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
260 $receiverccuser =
GETPOST(
'receiverccuser',
'alphawithlgt');
262 if (is_array($receiverccuser) && count($receiverccuser) > 0) {
263 $fuserdest =
new User($db);
264 foreach ($receiverccuser as $key => $val) {
265 $tmparray[] = $fuserdest->user_get_property($val,
'email');
266 $sendtoccuserid[] = $val;
270 $sendtocc = implode(
',', $tmparray);
274 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
275 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
278 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
280 $langs->load(
"commercial");
283 $fromtype =
GETPOST(
'fromtype',
'alpha');
284 if ($fromtype ===
'robot') {
286 } elseif ($fromtype ===
'user') {
287 $from =
dol_string_nospecial($user->getFullName($langs),
' ', array(
",")).
' <'.$user->email.
'>';
288 } elseif ($fromtype ===
'company') {
290 } elseif (preg_match(
'/user_aliases_(\d+)/', $fromtype, $reg)) {
291 $tmp = explode(
',', $user->email_aliases);
292 $from = trim($tmp[((
int) $reg[1] - 1)]);
293 } elseif (preg_match(
'/global_aliases_(\d+)/', $fromtype, $reg)) {
295 $from = trim($tmp[((
int) $reg[1] - 1)]);
296 } elseif (preg_match(
'/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) {
297 $sql =
'SELECT rowid, label, email FROM '.MAIN_DB_PREFIX.
'c_email_senderprofile';
298 $sql .=
' WHERE rowid = '.(int) $reg[1];
299 $resql = $db->query($sql);
300 $obj = $db->fetch_object($resql);
304 } elseif (preg_match(
'/from_template_(\d+)/', $fromtype, $reg)) {
305 $sql =
'SELECT rowid, email_from FROM '.MAIN_DB_PREFIX.
'c_email_templates';
306 $sql .=
' WHERE rowid = '.(int) $reg[1];
307 $resql = $db->query($sql);
308 $obj = $db->fetch_object($resql);
310 $from = $obj->email_from;
318 $message =
GETPOST(
'message',
'restricthtml');
319 $subject =
GETPOST(
'subject',
'restricthtml');
325 $message = preg_replace(
'/(<img.*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^\/]*\/>)/',
'\1'.$urlwithroot.
'/viewimage.php\2modulepart=medias\3file=\4\5', $message);
327 $sendtobcc =
GETPOST(
'sendtoccc');
330 if (!empty($autocopy)) {
334 $deliveryreceipt =
GETPOSTINT(
'deliveryreceipt') ? 1 : 0;
336 if ($action ==
'send' || $action ==
'relance') {
351 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
353 $formmail->trackid = $trackid;
355 $attachedfiles = $formmail->get_attached_files();
356 $filepath = $attachedfiles[
'paths'];
357 $filename = $attachedfiles[
'names'];
358 $mimetype = $attachedfiles[
'mimes'];
362 $substitutionarray[
'__EMAIL__'] = $sendto;
363 $substitutionarray[
'__CHECK_READ__'] = (is_object(
$object) && is_object(
$object->thirdparty)) ?
'<img src="'.DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-read.php?tag=undefined&securitykey='.
dol_hash(
getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY').
"-undefined",
'md5').
'" width="1" height="1" style="width:1px;height:1px" border="0"/>' :
'';
365 $parameters = array(
'mode' =>
'formemail');
371 if (is_object(
$object) && method_exists(
$object,
'makeSubstitution')) {
372 $subject =
$object->makeSubstitution($subject);
373 $message =
$object->makeSubstitution($message);
377 if (empty($sendcontext)) {
378 $sendcontext =
'standard';
380 $mailfile =
new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1,
'',
'', $trackid,
'', $sendcontext,
'', $upload_dir_tmp);
382 if (!empty($mailfile->error) || !empty($mailfile->errors)) {
386 $result = $mailfile->sendfile();
390 if (empty($actiontypecode)) {
391 $actiontypecode =
'AC_OTH_AUTO';
396 $object->actiontypecode = $actiontypecode;
398 $object->actionmsg2 = $actionmsg2;
400 $object->actionmsg2 = $subject;
406 if (is_array($attachedfiles) && count($attachedfiles) > 0) {
407 $object->attachedfiles = $attachedfiles;
409 if (is_array($sendtouserid) && count($sendtouserid) > 0 &&
getDolGlobalString(
'MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
410 $object->sendtouserid = $sendtouserid;
413 $object->email_msgid = $mailfile->msgid;
415 $object->email_subject = $subject;
417 $object->email_tocc = $sendtocc;
418 $object->email_tobcc = $sendtobcc;
419 $object->email_subject = $subject;
422 if (!empty($triggersendname) || !empty($trigger_name)) {
424 $result =
$object->call_trigger(empty($triggersendname) ? $trigger_name : $triggersendname, $user);
438 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($sendto, 2));
442 if (isset($paramval2)) {
443 $moreparam .=
'&'.($paramname2 ? $paramname2 :
'mid').
'='.$paramval2;
445 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?'.($paramname ??
'id').
'='.(is_object(
$object) ?
$object->id :
'').$moreparam);
448 $langs->load(
"other");
449 $mesg =
'<div class="error">';
450 if (!empty($mailfile->error) || !empty($mailfile->errors)) {
452 if (!empty($mailfile->error)) {
453 $mesg .=
'<br>'.$mailfile->error;
455 if (!empty($mailfile->errors) && is_array($mailfile->errors)) {
456 $mesg .=
'<br>'.implode(
'<br>', $mailfile->errors);
461 $mesg .=
'<br>Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
463 $mesg .=
'<br>Unknown Error, please refer to your administrator';
473 $langs->load(
"errors");
474 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"MailTo")),
null,
'warnings');
475 dol_syslog(
'Try to send email with no recipient defined', LOG_WARNING);
479 $langs->load(
"errors");
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
static getValidAddress($address, $format, $encode=0, $maxnumberofemail=0)
Return a formatted address string for SMTP protocol.
Class to manage Dolibarr users.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_add_file_process($upload_dir, $allowoverwrite=0, $updatesessionordb=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).
dol_remove_file_process($filenb, $donotupdatesession=0, $donotdeletefile=1, $trackid='')
Remove an uploaded file (for example after submitting a new file a mail form).
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='', $keepspaces=0)
Clean a string from all punctuation characters to use it as a ref or login.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
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...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null, $include=null)
Return array of possible common substitutions.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
dol_hash($chain, $type='0', $nosalt=0)
Returns a hash (non reversible encryption) of a string.