47@phan-var-force Societe $mysoc
48@phan-var-force CommonObject $object
56if (
GETPOST(
'addfile',
'alpha')) {
57 $trackid =
GETPOST(
'trackid',
'aZ09');
59 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
62 $vardir =
$conf->user->dir_output.
"/".$user->id;
63 $upload_dir_tmp = $vardir.
'/temp';
73 $trackid =
GETPOST(
'trackid',
'aZ09');
75 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
78 $vardir =
$conf->user->dir_output.
"/".$user->id;
79 $upload_dir_tmp = $vardir.
'/temp';
90if (
GETPOST(
'removAll',
'alpha')) {
91 $trackid =
GETPOST(
'trackid',
'aZ09');
93 $listofpaths = array();
94 $listofnames = array();
95 $listofmimes = array();
96 $keytoavoidconflict = empty($trackid) ?
'' :
'-'.$trackid;
97 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) {
98 $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
100 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) {
101 $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
103 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) {
104 $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
107 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
109 $formmail->trackid = $trackid;
111 foreach ($listofpaths as $key => $value) {
112 $pathtodelete = $value;
113 $filetodelete = $listofnames[$key];
116 $langs->load(
"other");
117 setEventMessages($langs->trans(
"FileWasRemoved", $filetodelete),
null,
'mesgs');
119 $formmail->remove_attached_files($key);
126if (($action ==
'send' || $action ==
'relance') && !
GETPOST(
'addfile') && !
GETPOST(
'removAll') && !
GETPOST(
'removedfile') && !
GETPOST(
'cancel') && !
GETPOST(
'modelselected')) {
127 if (empty($trackid)) {
128 $trackid =
GETPOST(
'trackid',
'aZ09');
132 $vardir =
$conf->user->dir_output.
"/".$user->id;
133 $upload_dir_tmp = $vardir.
'/temp';
139 $langs->load(
'mails');
146 if (method_exists(
$object,
"fetch_thirdparty") && !in_array(
$object->element, array(
'member',
'user',
'expensereport',
'societe',
'contact'))) {
147 $resultthirdparty =
$object->fetch_thirdparty();
148 $thirdparty =
$object->thirdparty;
149 if (is_object($thirdparty)) {
150 $sendtosocid = $thirdparty->id;
152 } elseif (
$object->element ==
'member' ||
$object->element ==
'user') {
157 } elseif (
$object->element ==
'expensereport') {
158 $tmpuser =
new User($db);
159 $tmpuser->fetch(
$object->fk_user_author);
160 $thirdparty = $tmpuser;
164 } elseif (
$object->element ==
'societe') {
166 if (is_object($thirdparty) && $thirdparty->id > 0) {
167 $sendtosocid = $thirdparty->id;
169 } elseif (
$object->element ==
'contact') {
171 if ($contact->id > 0) {
172 $contact->fetch_thirdparty();
173 $thirdparty = $contact->thirdparty;
174 if (is_object($thirdparty) && $thirdparty->id > 0) {
175 $sendtosocid = $thirdparty->id;
179 dol_print_error(
null,
"Use actions_sendmails.in.php for an element/object '".
$object->element.
"' that is not supported");
182 if (is_object($hookmanager)) {
183 $parameters = array();
184 $reshook = $hookmanager->executeHooks(
'initSendToSocid', $parameters,
$object, $action);
187 $thirdparty = $mysoc;
195 $sendtouserid = array();
196 $sendtoccuserid = array();
199 $receiver =
GETPOST(
'receiver',
'alphawithlgt');
200 if (!is_array($receiver)) {
201 if ($receiver ==
'-1') {
204 $receiver = array($receiver);
209 if (trim(
GETPOST(
'sendto',
'alphawithlgt'))) {
211 $tmparray[] = trim(
GETPOST(
'sendto',
'alphawithlgt'));
214 if (trim(
GETPOST(
'tomail',
'alphawithlgt'))) {
216 $tmparray[] = trim(
GETPOST(
'tomail',
'alphawithlgt'));
219 if (count($receiver) > 0) {
221 foreach ($receiver as $key => $val) {
222 if ($val ==
'thirdparty') {
223 $tmparray[] =
dol_string_nospecial($thirdparty->getFullName($langs),
' ', array(
",")).
' <'.$thirdparty->email.
'>';
224 } elseif ($val ==
'contact') {
225 $tmparray[] =
dol_string_nospecial($contact->getFullName($langs),
' ', array(
",")).
' <'.$contact->email.
'>';
226 $sendtoid[] = $contact->id;
227 } elseif ($val &&
$object->element ==
'project' && empty(
$object->socid)) {
229 $ret = $contact->fetch((
int) $val);
230 if ($ret > 0 && !empty($contact->socid)) {
231 $thirdparty =
new Societe($db);
232 $thirdparty->fetch($contact->socid);
233 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
234 $sendtoid[] = ((int) $val);
237 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
238 $sendtoid[] = ((int) $val);
244 $receiveruser =
GETPOST(
'receiveruser',
'alphawithlgt');
245 if (is_array($receiveruser) && count($receiveruser) > 0) {
246 $fuserdest =
new User($db);
247 foreach ($receiveruser as $key => $val) {
248 $tmparray[] = $fuserdest->user_get_property($val,
'email');
249 $sendtouserid[] = $val;
254 $sendto = implode(
',', $tmparray);
257 $receivercc =
GETPOST(
'receivercc',
'alphawithlgt');
258 if (!is_array($receivercc)) {
259 if ($receivercc ==
'-1') {
260 $receivercc = array();
262 $receivercc = array($receivercc);
266 if (trim(
GETPOST(
'sendtocc',
'alphawithlgt'))) {
267 $tmparray[] = trim(
GETPOST(
'sendtocc',
'alphawithlgt'));
269 if (count($receivercc) > 0) {
270 foreach ($receivercc as $key => $val) {
271 if ($val ==
'thirdparty') {
273 $tmparray[] =
dol_string_nospecial($thirdparty->name,
' ', array(
",")).
' <'.$thirdparty->email.
'>';
274 } elseif ($val ==
'contact') {
279 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
285 $receiverccuser =
GETPOST(
'receiverccuser',
'alphawithlgt');
287 if (is_array($receiverccuser) && count($receiverccuser) > 0) {
288 $fuserdest =
new User($db);
289 foreach ($receiverccuser as $key => $val) {
290 $tmparray[] = $fuserdest->user_get_property($val,
'email');
291 $sendtoccuserid[] = $val;
295 $sendtocc = implode(
',', $tmparray);
299 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
300 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
303 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
305 $langs->load(
"commercial");
308 $fromtype =
GETPOST(
'fromtype',
'alpha');
309 if ($fromtype ===
'robot') {
311 } elseif ($fromtype ===
'user') {
312 $from =
dol_string_nospecial($user->getFullName($langs),
' ', array(
",")).
' <'.$user->email.
'>';
313 } elseif ($fromtype ===
'company') {
315 } elseif (preg_match(
'/user_aliases_(\d+)/', $fromtype, $reg)) {
316 $tmp = explode(
',', $user->email_aliases);
317 $from = trim($tmp[((
int) $reg[1] - 1)]);
318 } elseif (preg_match(
'/global_aliases_(\d+)/', $fromtype, $reg)) {
320 $from = trim($tmp[((
int) $reg[1] - 1)]);
321 } elseif (preg_match(
'/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) {
322 $sql =
'SELECT rowid, label, email FROM '.MAIN_DB_PREFIX.
'c_email_senderprofile';
323 $sql .=
' WHERE rowid = '.(int) $reg[1];
324 $resql = $db->query($sql);
325 $obj = $db->fetch_object($resql);
329 } elseif (preg_match(
'/from_template_(\d+)/', $fromtype, $reg)) {
330 $sql =
'SELECT rowid, email_from FROM '.MAIN_DB_PREFIX.
'c_email_templates';
331 $sql .=
' WHERE rowid = '.(int) $reg[1];
332 $resql = $db->query($sql);
333 $obj = $db->fetch_object($resql);
335 $from = $obj->email_from;
343 $message =
GETPOST(
'message',
'restricthtml');
344 $subject =
GETPOST(
'subject',
'restricthtml');
350 $message = preg_replace(
'/(<img.*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^\/]*\/>)/',
'\1'.$urlwithroot.
'/viewimage.php\2modulepart=medias\3file=\4\5', $message);
352 $sendtobcc =
GETPOST(
'sendtoccc',
'alphawithlgt');
355 if (!empty($autocopy)) {
359 $deliveryreceipt =
GETPOSTINT(
'deliveryreceipt') ? 1 : 0;
361 if ($action ==
'send' || $action ==
'relance') {
376 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
378 $formmail->trackid = $trackid;
380 $attachedfiles = $formmail->get_attached_files();
381 $filepath = $attachedfiles[
'paths'];
382 $filename = $attachedfiles[
'names'];
383 $mimetype = $attachedfiles[
'mimes'];
387 $substitutionarray[
'__EMAIL__'] = $sendto;
388 $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"/>' :
'';
390 $parameters = array(
'mode' =>
'formemail');
396 if (is_object(
$object) && method_exists(
$object,
'makeSubstitution')) {
397 $subject =
$object->makeSubstitution($subject);
398 $message =
$object->makeSubstitution($message);
402 if (empty($sendcontext)) {
403 $sendcontext =
'standard';
405 $mailfile =
new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1,
'',
'', $trackid,
'', $sendcontext,
'', $upload_dir_tmp);
407 if (!empty($mailfile->error) || !empty($mailfile->errors)) {
411 $result = $mailfile->sendfile();
415 if (empty($actiontypecode)) {
416 $actiontypecode =
'AC_OTH_AUTO';
421 $object->actiontypecode = $actiontypecode;
423 $object->actionmsg2 = $actionmsg2;
425 $object->actionmsg2 = $subject;
431 if (is_array($attachedfiles) && count($attachedfiles) > 0) {
432 $object->attachedfiles = $attachedfiles;
434 if (is_array($sendtouserid) && count($sendtouserid) > 0 &&
getDolGlobalString(
'MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
435 $object->sendtouserid = $sendtouserid;
438 $object->email_msgid = $mailfile->msgid;
440 $object->email_subject = $subject;
442 $object->email_tocc = $sendtocc;
443 $object->email_tobcc = $sendtobcc;
444 $object->email_subject = $subject;
447 if (!empty($triggersendname) || !empty($trigger_name)) {
449 $result =
$object->call_trigger(empty($triggersendname) ? $trigger_name : $triggersendname, $user);
463 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($sendto, 2));
467 if (isset($paramval2)) {
469 $moreparam .=
'&'.($paramname2 ? $paramname2 :
'mid').
'='.$paramval2;
471 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?'.($paramname ??
'id').
'='.(is_object(
$object) ?
$object->id :
'').$moreparam);
474 $langs->load(
"other");
475 $mesg =
'<div class="error">';
476 if (!empty($mailfile->error) || !empty($mailfile->errors)) {
478 if (!empty($mailfile->error)) {
479 $mesg .=
'<br>'.$mailfile->error;
481 if (!empty($mailfile->errors) && is_array($mailfile->errors)) {
482 $mesg .=
'<br>'.implode(
'<br>', $mailfile->errors);
487 $mesg .=
'<br>Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
489 $mesg .=
'<br>Unknown Error, please refer to your administrator';
499 $langs->load(
"errors");
500 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"MailTo")),
null,
'warnings');
501 dol_syslog(
'Try to send email with no recipient defined', LOG_WARNING);
505 $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 third parties objects (customers, suppliers, prospects...)
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, $forceFullTestIndexation='')
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.