48@phan-var-force Societe $mysoc
49@phan-var-force CommonObject $object
57if (
GETPOST(
'addfile',
'alpha')) {
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';
74 $trackid =
GETPOST(
'trackid',
'aZ09');
76 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
79 $vardir =
$conf->user->dir_output.
"/".$user->id;
80 $upload_dir_tmp = $vardir.
'/temp';
91if (
GETPOST(
'removeAll',
'alpha')) {
92 $trackid =
GETPOST(
'trackid',
'aZ09');
94 $listofpaths = array();
95 $listofnames = array();
96 $listofmimes = array();
97 $keytoavoidconflict = empty($trackid) ?
'' :
'-'.$trackid;
98 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) {
99 $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
101 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) {
102 $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
104 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) {
105 $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
108 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
110 $formmail->trackid = $trackid;
112 foreach ($listofpaths as $key => $value) {
113 $pathtodelete = $value;
114 $filetodelete = $listofnames[$key];
117 $langs->load(
"other");
118 setEventMessages($langs->trans(
"FileWasRemoved", $filetodelete),
null,
'mesgs');
120 $formmail->remove_attached_files($key);
127if (($action ==
'send' || $action ==
'relance') && !
GETPOST(
'addfile') && !
GETPOST(
'removeAll') && !
GETPOST(
'removedfile') && !
GETPOST(
'cancel') && !
GETPOST(
'modelselected')) {
128 if (empty($trackid)) {
129 $trackid =
GETPOST(
'trackid',
'aZ09');
133 $vardir =
$conf->user->dir_output.
"/".$user->id;
134 $upload_dir_tmp = $vardir.
'/temp';
140 $langs->load(
'mails');
147 if (method_exists(
$object,
"fetch_thirdparty") && !in_array(
$object->element, array(
'member',
'user',
'expensereport',
'societe',
'contact'))) {
149 $thirdparty =
$object->thirdparty;
150 if (is_object($thirdparty)) {
151 $sendtosocid = $thirdparty->id;
153 } elseif (
$object->element ==
'member' ||
$object->element ==
'user') {
158 } elseif (
$object->element ==
'expensereport') {
159 $tmpuser =
new User($db);
160 $tmpuser->fetch(
$object->fk_user_author);
161 $thirdparty = $tmpuser;
165 } elseif (
$object->element ==
'societe') {
167 if (is_object($thirdparty) && $thirdparty->id > 0) {
168 $sendtosocid = $thirdparty->id;
170 } elseif (
$object->element ==
'contact') {
172 if ($contact->id > 0) {
173 $contact->fetch_thirdparty();
174 $thirdparty = $contact->thirdparty;
175 if (is_object($thirdparty) && $thirdparty->id > 0) {
176 $sendtosocid = $thirdparty->id;
180 dol_print_error(
null,
"Use actions_sendmails.in.php for an element/object '".
$object->element.
"' that is not supported");
183 if (is_object($hookmanager)) {
184 $parameters = array();
185 $reshook = $hookmanager->executeHooks(
'initSendToSocid', $parameters,
$object, $action);
188 $thirdparty = $mysoc;
196 $sendtouserid = array();
197 $sendtoccuserid = array();
200 $receiver =
GETPOST(
'receiver',
'alphawithlgt');
201 if (!is_array($receiver)) {
202 if ($receiver ==
'-1') {
205 $receiver = array($receiver);
210 if (trim(
GETPOST(
'sendto',
'alphawithlgt'))) {
212 $tmparray[] = trim(
GETPOST(
'sendto',
'alphawithlgt'));
215 if (trim(
GETPOST(
'tomail',
'alphawithlgt'))) {
217 $tmparray[] = trim(
GETPOST(
'tomail',
'alphawithlgt'));
220 if (count($receiver) > 0) {
222 foreach ($receiver as $key => $val) {
223 if ($val ==
'thirdparty') {
224 $tmparray[] =
dol_string_nospecial($thirdparty->getFullName($langs),
' ', array(
",")).
' <'.$thirdparty->email.
'>';
225 } elseif ($val ==
'contact') {
226 $tmparray[] =
dol_string_nospecial($contact->getFullName($langs),
' ', array(
",")).
' <'.$contact->email.
'>';
227 $sendtoid[] = $contact->id;
228 } elseif ($val &&
$object->element ==
'project' && empty(
$object->socid)) {
230 $ret = $contact->fetch((
int) $val);
231 if ($ret > 0 && !empty($contact->socid)) {
232 $thirdparty =
new Societe($db);
233 $thirdparty->fetch($contact->socid);
234 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
235 $sendtoid[] = ((int) $val);
238 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
239 $sendtoid[] = ((int) $val);
245 $receiveruser =
GETPOST(
'receiveruser',
'alphawithlgt');
246 if (is_array($receiveruser) && count($receiveruser) > 0) {
247 $fuserdest =
new User($db);
248 foreach ($receiveruser as $key => $val) {
249 $tmparray[] = $fuserdest->user_get_property($val,
'email');
250 $sendtouserid[] = $val;
255 $sendto = implode(
',', $tmparray);
258 $receivercc =
GETPOST(
'receivercc',
'alphawithlgt');
259 if (!is_array($receivercc)) {
260 if ($receivercc ==
'-1') {
261 $receivercc = array();
263 $receivercc = array($receivercc);
267 if (trim(
GETPOST(
'sendtocc',
'alphawithlgt'))) {
268 $tmparray[] = trim(
GETPOST(
'sendtocc',
'alphawithlgt'));
270 if (count($receivercc) > 0) {
271 foreach ($receivercc as $key => $val) {
272 if ($val ==
'thirdparty') {
274 $tmparray[] =
dol_string_nospecial($thirdparty->name,
' ', array(
",")).
' <'.$thirdparty->email.
'>';
275 } elseif ($val ==
'contact') {
280 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
286 $receiverccuser =
GETPOST(
'receiverccuser',
'alphawithlgt');
288 if (is_array($receiverccuser) && count($receiverccuser) > 0) {
289 $fuserdest =
new User($db);
290 foreach ($receiverccuser as $key => $val) {
291 $tmparray[] = $fuserdest->user_get_property($val,
'email');
292 $sendtoccuserid[] = $val;
296 $sendtocc = implode(
',', $tmparray);
301 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
304 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
306 $langs->load(
"commercial");
309 $fromtype =
GETPOST(
'fromtype',
'alpha');
310 $emailsendersignature =
'';
311 if ($fromtype ===
'robot') {
313 } elseif ($fromtype ===
'user') {
314 $from =
dol_string_nospecial($user->getFullName($langs),
' ', array(
",")).
' <'.$user->email.
'>';
315 } elseif ($fromtype ===
'company') {
317 } elseif (preg_match(
'/user_aliases_(\d+)/', $fromtype, $reg)) {
318 $tmp = explode(
',', $user->email_aliases);
319 $from = trim($tmp[((
int) $reg[1] - 1)]);
320 } elseif (preg_match(
'/global_aliases_(\d+)/', $fromtype, $reg)) {
322 $from = trim($tmp[((
int) $reg[1] - 1)]);
323 } elseif (preg_match(
'/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) {
324 $sql =
'SELECT rowid, label, email, signature FROM '.MAIN_DB_PREFIX.
'c_email_senderprofile';
325 $sql .=
' WHERE rowid = '.(int) $reg[1];
326 $resql = $db->query($sql);
327 $obj = $db->fetch_object($resql);
330 $emailsendersignature = $obj->signature;
332 } elseif (preg_match(
'/from_template_(\d+)/', $fromtype, $reg)) {
333 $sql =
'SELECT rowid, email_from FROM '.MAIN_DB_PREFIX.
'c_email_templates';
334 $sql .=
' WHERE rowid = '.(int) $reg[1];
335 $resql = $db->query($sql);
336 $obj = $db->fetch_object($resql);
338 $from = $obj->email_from;
346 $message =
GETPOST(
'message',
'restricthtml');
347 $subject =
GETPOST(
'subject',
'restricthtml');
353 $message = preg_replace(
'/(<img.*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^\/]*\/>)/',
'\1'.$urlwithroot.
'/viewimage.php\2modulepart=medias\3file=\4\5', $message);
355 $sendtobcc =
GETPOST(
'sendtoccc',
'alphawithlgt');
358 if (!empty($autocopy)) {
362 $deliveryreceipt =
GETPOSTINT(
'deliveryreceipt') ? 1 : 0;
364 if ($action ==
'send' || $action ==
'relance') {
379 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
381 $formmail->trackid = $trackid;
383 $attachedfiles = $formmail->get_attached_files();
384 $filepath = $attachedfiles[
'paths'];
385 $filename = $attachedfiles[
'names'];
386 $mimetype = $attachedfiles[
'mimes'];
389 $substitutionarray = getCommonSubstitutionArray($langs, 0,
null,
$object);
391 $substitutionarray[
'__SENDEREMAIL_SIGNATURE__'] = (empty($emailsendersignature) ? $user->signature : $emailsendersignature);
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=undefined&securitykey='.
dol_hash(
getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY').
"-undefined",
'md5').
'" width="1" height="1" style="width:1px;height:1px" border="0"/>' :
'';
395 $parameters = array(
'mode' =>
'formemail');
401 if (is_object(
$object) && method_exists(
$object,
'makeSubstitution')) {
402 $subject =
$object->makeSubstitution($subject);
403 $message =
$object->makeSubstitution($message);
407 if (empty($sendcontext)) {
408 $sendcontext =
'standard';
410 $mailfile =
new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1,
'',
'', $trackid,
'', $sendcontext,
'', $upload_dir_tmp);
412 if (!empty($mailfile->error) || !empty($mailfile->errors)) {
416 $result = $mailfile->sendfile();
420 if (empty($actiontypecode)) {
421 $actiontypecode =
'AC_OTH_AUTO';
426 $object->actiontypecode = $actiontypecode;
428 $object->actionmsg2 = $actionmsg2;
430 $object->actionmsg2 = $subject;
436 if (is_array($attachedfiles) && count($attachedfiles) > 0) {
437 $object->attachedfiles = $attachedfiles;
439 if (is_array($sendtouserid) && count($sendtouserid) > 0 &&
getDolGlobalString(
'MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
440 $object->sendtouserid = $sendtouserid;
443 $object->email_msgid = $mailfile->msgid;
445 $object->email_subject = $subject;
447 $object->email_tocc = $sendtocc;
448 $object->email_tobcc = $sendtobcc;
451 if (!empty($triggersendname)) {
452 $result =
$object->call_trigger($triggersendname, $user);
465 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($sendto, 2));
468 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?'.($paramname ??
'id').
'='.(is_object(
$object) ?
$object->id :
''));
471 $langs->load(
"other");
472 $mesg =
'<div class="error">';
473 if (!empty($mailfile->error) || !empty($mailfile->errors)) {
475 if (!empty($mailfile->error)) {
476 $mesg .=
'<br>'.$mailfile->error;
478 if (!empty($mailfile->errors) && is_array($mailfile->errors)) {
479 $mesg .=
'<br>'.implode(
'<br>', $mailfile->errors);
484 $mesg .=
'<br>Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
486 $mesg .=
'<br>Unknown Error, please refer to your administrator';
496 $langs->load(
"errors");
497 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"MailTo")),
null,
'warnings');
498 dol_syslog(
'Try to send email with no recipient defined', LOG_WARNING);
502 $langs->load(
"errors");
$id
Support class for third parties, contacts, members, users or resources.
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
global $dolibarr_main_url_root
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_add_file_process($upload_dir, $allowoverwrite=0, $updatesessionordb=0, $keyforsourcefile='addedfile', $savingdocmask='', $link=null, $trackid='', $generatethumbs=1, $object=null, $forceFullTextIndexation='', $mode=0)
Get and save an upload file (for example after submitting a new file in a mail form).
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_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...
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.