49@phan-var-force int<0,1> $diroutput
50@phan-var-force string $defaulttopic
51@phan-var-force string $defaulttopiclang
52@phan-var-force string[] $arrayoffamiliestoexclude
53@phan-var-force string $file
54@phan-var-force string $modelmail
55@phan-var-force CommonObject $object
60 print
"Error, template page can't be called as URL";
66if (!isset($modelmail)) {
70if ($action ==
'presend') {
71 $langs->load(
"mails");
73 $titreform =
'SendMail';
78 if (!in_array(
$object->element, array(
'user',
'member'))) {
81 if (!empty(
$object->last_main_doc) && is_readable(DOL_DATA_ROOT.
'/'.
$object->last_main_doc) && is_file(DOL_DATA_ROOT.
'/'.
$object->last_main_doc)) {
82 $fileparams[
'fullname'] = DOL_DATA_ROOT.
'/'.
$object->last_main_doc;
84 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
86 if (
$object->element ==
'invoice_supplier') {
93 $file = isset($fileparams[
'fullname']) ? $fileparams[
'fullname'] :
null;
97 $outputlangs = $langs;
100 if (!is_object(
$object->thirdparty) && method_exists(
$object,
'fetch_thirdparty')) {
103 if (is_object(
$object->thirdparty)) {
104 $newlang =
$object->thirdparty->default_lang;
106 if (
GETPOST(
'lang_id',
'aZ09')) {
107 $newlang =
GETPOST(
'lang_id',
'aZ09');
111 if (empty($newlang) &&
GETPOST(
'langsmodels',
'aZ09')) {
112 $newlang =
GETPOST(
'langsmodels',
'aZ09');
116 if (!empty($newlang)) {
118 $outputlangs->setDefaultLang($newlang);
120 $outputlangs->loadLangs(array(
'commercial',
'bills',
'orders',
'contracts',
'main',
'members',
'propal',
'products',
'supplier_proposal',
'interventions',
'receptions',
'sendings'));
121 if (!empty($defaulttopiclang)) {
122 $outputlangs->loadLangs(array($defaulttopiclang));
127 if (empty(
$object->ref_client)) {
128 $topicmail = $outputlangs->trans($defaulttopic,
'__REF__');
129 } elseif (!empty(
$object->ref_client)) {
130 $topicmail = $outputlangs->trans($defaulttopic,
'__REF__ (__REF_CLIENT__)');
134 $forcebuilddoc =
true;
136 if (in_array(
$object->element, array(
'user',
'member'))) {
137 $forcebuilddoc =
false;
140 $forcebuilddoc =
false;
143 $forcebuilddoc =
false;
146 $forcebuilddoc =
false;
149 $forcebuilddoc =
false;
152 if ($forcebuilddoc) {
153 if ((!$file || !is_readable($file)) && method_exists(
$object,
'generateDocument')) {
154 $hidedetails = empty($hidedetails) ?
'' : $hidedetails;
155 $hidedesc = empty($hidedesc) ?
'' : $hidedesc;
156 $hideref = empty($hideref) ?
'' : $hideref;
158 $result =
$object->generateDocument(
GETPOST(
'model') ?
GETPOST(
'model') :
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
164 if (
$object->element ==
'invoice_supplier') {
170 $file = isset($fileparams[
'fullname']) ? $fileparams[
'fullname'] :
null;
175 print
'<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
176 print
'<div class="clearboth"></div>';
183 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
186 $formmail->param[
'langsmodels'] = (empty($newlang) ? $langs->defaultlang : $newlang);
189 if ($formmail->fromtype ===
'user') {
190 $formmail->fromid = $user->id;
195 $formmail->fromtype =
'special';
200 $formmail->fromtype =
'special';
205 $formmail->fromtype =
'special';
210 $formmail->fromtype =
'special';
215 $formmail->fromtype =
'special';
217 if (
$object->element ===
'recruitmentcandidature') {
218 $formmail->frommail =
getDolGlobalString(
'RECRUITMENT_EMAIL_SENDER', (!empty($recruitermail) ? $recruitermail :
''));
219 $formmail->fromname =
getDolGlobalString(
'RECRUITMENT_EMAIL_SENDER_NAME', (!empty($recruitername) ? $recruitername :
''));
220 $formmail->fromtype =
'special';
226 $defaultfrom =
GETPOST(
'fromtype');
228 $parameters = array();
229 $reshook = $hookmanager->executeHooks(
'getDefaultFromEmail', $parameters, $formmail);
230 if (empty($reshook)) {
231 $defaultfrom = $formmail->fromtype;
233 if (!empty($hookmanager->resArray[
'defaultfrom'])) {
234 $defaultfrom = $hookmanager->resArray[
'defaultfrom'];
237 $formmail->fromtype = $defaultfrom;
239 $formmail->trackid = empty($trackid) ?
'' : $trackid;
240 $formmail->inreplyto = empty($inreplyto) ?
'' : $inreplyto;
241 $formmail->withfrom = 1;
242 $formmail->withlayout =
'email';
243 $formmail->withaiprompt =
'html';
248 if (
$object->element ==
'expensereport') {
249 '@phan-var-force ExpenseReport $object';
250 $fuser =
new User($db);
251 $fuser->fetch(
$object->fk_user_author);
252 $liste[
'thirdparty'] = $fuser->getFullName($outputlangs).
" <".$fuser->email.
">";
254 '@phan-var-force Partnership $object';
256 $fadherent->fetch(
$object->fk_member);
257 $liste[
'member'] = $fadherent->getFullName($outputlangs).
" <".$fadherent->email.
">";
258 } elseif (
$object->element ==
'societe') {
259 '@phan-var-force Societe $object';
260 foreach (
$object->thirdparty_and_contact_email_array(1) as $key => $value) {
261 $liste[$key] = $value;
263 } elseif (
$object->element ==
'contact') {
264 '@phan-var-force Contact $object';
265 $liste[
'contact'] =
$object->getFullName($outputlangs).
" <".
$object->email.
">";
266 } elseif (
$object->element ==
'user' ||
$object->element ==
'member') {
267 '@phan-var-force User|Adherent $object';
268 $liste[
'thirdparty'] =
$object->getFullName($outputlangs).
" <".
$object->email.
">";
269 } elseif (
$object->element ==
'salary') {
270 '@phan-var-force Salary $object';
271 $fuser =
new User($db);
272 $fuser->fetch(
$object->fk_user);
273 $liste[
'thirdparty'] = $fuser->getFullName($outputlangs).
" <".$fuser->email.
">";
280 if (is_object(
$object->thirdparty)) {
281 foreach (
$object->thirdparty->thirdparty_and_contact_email_array(1) as $key => $value) {
282 $liste[$key] = $value;
288 $listeuser = array();
289 $fuserdest =
new User($db);
290 $result = $fuserdest->fetchAll(
'ASC',
't.lastname', 0, 0,
"(t.statut:=:1) AND (t.employee:=:1) AND (t.email:isnot:NULL) AND (t.email:!=:'')",
'AND',
true);
291 if ($result > 0 && is_array($fuserdest->users) && count($fuserdest->users) > 0) {
292 foreach ($fuserdest->users as $uuserdest) {
293 $listeuser[$uuserdest->id] = $uuserdest->user_get_property($uuserdest->id,
'email');
295 } elseif ($result < 0) {
296 setEventMessages(
null, $fuserdest->errors,
'errors');
298 if (count($listeuser) > 0) {
299 $formmail->withtouser = $listeuser;
300 $formmail->withtoccuser = $listeuser;
305 if (!isset($arrayoffamiliestoexclude)) {
306 $arrayoffamiliestoexclude =
null;
312 $formmail->setSubstitFromObject(
$object, $outputlangs);
314 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, $arrayoffamiliestoexclude,
$object);
316 $emailsendersignature =
null;
318 if ($formmail->fromtype) {
320 if (preg_match(
'/user/', $formmail->fromtype, $reg)) {
321 $emailsendersignature = $user->signature;
322 } elseif (preg_match(
'/company/', $formmail->fromtype, $reg)) {
323 $emailsendersignature =
'';
324 } elseif (preg_match(
'/senderprofile_(\d+)/', $formmail->fromtype, $reg)) {
325 $sql =
"SELECT rowid, label, email, signature FROM ".$db->prefix().
"c_email_senderprofile";
326 $sql .=
" WHERE rowid = ".((int) $reg[1]);
327 $resql = $db->query($sql);
329 $obj = $db->fetch_object($resql);
331 $emailsendersignature = $obj->signature;
336 $substitutionarray[
'__SENDEREMAIL_SIGNATURE__'] = $emailsendersignature;
338 $substitutionarray[
'__CHECK_READ__'] =
"";
340 $checkRead =
'<img src="'.DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-read.php';
342 $checkRead .=
'?tag='.(!empty(
$object->thirdparty->tag) ? urlencode(
$object->thirdparty->tag) :
"");
343 $checkRead .=
'&securitykey='.(getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY') ? urlencode(
getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY')) :
"");
344 $checkRead .=
'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
345 $substitutionarray[
'__CHECK_READ__'] = $checkRead;
347 $substitutionarray[
'__CONTACTCIVNAME__'] =
'';
349 'mode' =>
'formemail'
355 if ((
$object->element ==
'shipping' ||
$object->element ==
'reception')) {
357 $origin_id =
$object->origin_id;
359 if (!empty($origin) && !empty($origin_id)) {
360 $element = $subelement = $origin;
362 if ($element ==
'order_supplier') {
364 $subelement =
'fournisseur.commande';
365 $origin =
'CommandeFournisseur';
369 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
371 $subelement = $regs[2];
374 if ($element ==
'order') {
375 $element = $subelement =
'commande';
377 if ($element ==
'propal') {
378 $element =
'comm/propal';
379 $subelement =
'propal';
381 if ($element ==
'contract') {
382 $element = $subelement =
'contrat';
384 if ($element ==
'inter') {
385 $element = $subelement =
'fichinter';
387 if ($element ==
'shipping') {
388 $element = $subelement =
'expedition';
390 if ($element ==
'project') {
395 $classname = ucfirst($origin);
396 $objectsrc =
new $classname($db);
397 '@phan-var-force Commande|Facture $objectsrc';
398 $objectsrc->fetch($origin_id);
400 $tmpobject = $objectsrc;
404 $contactarr = array();
405 $contactarr = $tmpobject->liste_contact(-1,
'external', 0,
'', 1);
407 if (is_array($contactarr) && count($contactarr) > 0) {
408 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
409 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
410 $contactstatic =
new Contact($db);
411 $tmpcompany =
new Societe($db);
413 foreach ($contactarr as $contact) {
414 $contactstatic->fetch($contact[
'id']);
416 $substitutionarray[
'__CONTACT_NAME_'.$contact[
'code'].
'__'] = $contactstatic->getFullName($outputlangs, 1);
417 $substitutionarray[
'__CONTACT_LASTNAME_'.$contact[
'code'].
'__'] = $contactstatic->lastname;
418 $substitutionarray[
'__CONTACT_FIRSTNAME_'.$contact[
'code'].
'__'] = $contactstatic->firstname;
419 $substitutionarray[
'__CONTACT_TITLE_'.$contact[
'code'].
'__'] = $contactstatic->getCivilityLabel();
422 if (empty($liste[$contact[
'id']])) {
424 if (isset(
$object->thirdparty) && is_object(
$object->thirdparty)) {
425 if ($contactstatic->fk_soc !=
$object->thirdparty->id) {
426 $tmpcompany->fetch($contactstatic->fk_soc);
427 if ($tmpcompany->id > 0) {
428 $contacttoshow .= $tmpcompany->name.
': ';
432 $contacttoshow .= $contactstatic->getFullName($outputlangs, 1);
433 $contacttoshow .=
" <".($contactstatic->email ? $contactstatic->email : $langs->transnoentitiesnoconv(
"NoEMail")) .
">";
434 $liste[$contact[
'id']] = $contacttoshow;
439 $formmail->withto = $liste;
440 $formmail->withtofree = (
GETPOST(
'sendto',
'alphawithlgt') ?
GETPOST(
'sendto',
'alphawithlgt') :
'1');
441 $formmail->withtocc = $liste;
443 $formmail->withtopic = $topicmail;
444 $formmail->withfile = 2;
445 $formmail->withbody = 1;
446 $formmail->withdeliveryreceipt = 1;
447 $formmail->withcancel = 1;
450 $formmail->substit = $substitutionarray;
453 $nbmostrecentfiles = 0;
454 if (
$object->element ==
'facture' &&
getDolGlobalInt(
'MAIN_FACTURE_EMAIL_ATTACH_MOST_RECENT_FILES') > 0) {
455 $nbmostrecentfiles =
getDolGlobalInt(
'MAIN_FACTURE_EMAIL_ATTACH_MOST_RECENT_FILES');
456 } elseif (
getDolGlobalInt(
'MAIN_EMAIL_ATTACH_MOST_RECENT_FILES') > 0) {
457 $nbmostrecentfiles =
getDolGlobalInt(
'MAIN_EMAIL_ATTACH_MOST_RECENT_FILES');
460 if ($nbmostrecentfiles > 0) {
461 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
462 if (
$object->element ==
'invoice_supplier') {
465 $dir = $diroutput.
'/'.$ref;
467 $recentfiles =
dol_most_recent_file($dir,
'', array(
'(\.meta|_preview.*\.png)$',
'^\.'), 0, 0, $nbmostrecentfiles);
468 if (is_array($recentfiles) && count($recentfiles) > 0) {
469 if (isset($recentfiles[
'fullname'])) {
470 $recentfiles = array($recentfiles);
472 foreach ($recentfiles as $fileentry) {
473 if (!empty($fileentry[
'fullname']) && is_readable($fileentry[
'fullname'])) {
474 $fileinit[] = $fileentry[
'fullname'];
480 if (empty($fileinit) && !empty($file)) {
481 $fileinit = array($file);
485 $formmail->param[
'action'] =
'send';
486 $formmail->param[
'models'] = $modelmail;
487 $formmail->param[
'models_id'] =
GETPOSTINT(
'modelmailselected');
488 $formmail->param[
'id'] =
$object->id;
489 $formmail->param[
'returnurl'] = $_SERVER[
"PHP_SELF"].
'?id='.
$object->id;
490 $formmail->param[
'fileinit'] = $fileinit;
491 $formmail->param[
'object_entity'] =
$object->entity;
494 print $formmail->get_form();
if(! $sortfield) if(! $sortorder) $object
Class to manage members of a foundation.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
dol_most_recent_file($dir, $regexfilter='', $excludefilter=array('(\.meta|_preview.*\.png) $', '^\.'), $nohook=0, $mode=0, $limit=0)
Return file(s) into a directory (by default most recent)
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
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...
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.