48@phan-var-force int<0,1> $diroutput
49@phan-var-force string $defaulttopic
50@phan-var-force string $defaulttopiclang
51@phan-var-force string[] $arrayoffamiliestoexclude
52@phan-var-force string $file
53@phan-var-force string $modelmail
54@phan-var-force CommonObject $object
59 print
"Error, template page can't be called as URL";
65if (!isset($modelmail)) {
69if ($action ==
'presend') {
70 $langs->load(
"mails");
72 $titreform =
'SendMail';
77 if (!in_array(
$object->element, array(
'user',
'member'))) {
80 if (!empty(
$object->last_main_doc) && is_readable(DOL_DATA_ROOT.
'/'.
$object->last_main_doc) && is_file(DOL_DATA_ROOT.
'/'.
$object->last_main_doc)) {
81 $fileparams[
'fullname'] = DOL_DATA_ROOT.
'/'.
$object->last_main_doc;
83 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
85 if (
$object->element ==
'invoice_supplier') {
92 $file = isset($fileparams[
'fullname']) ? $fileparams[
'fullname'] :
null;
96 $outputlangs = $langs;
99 if (!is_object(
$object->thirdparty) && method_exists(
$object,
'fetch_thirdparty')) {
102 if (is_object(
$object->thirdparty)) {
103 $newlang =
$object->thirdparty->default_lang;
105 if (
GETPOST(
'lang_id',
'aZ09')) {
106 $newlang =
GETPOST(
'lang_id',
'aZ09');
110 if (empty($newlang) &&
GETPOST(
'langsmodels',
'aZ09')) {
111 $newlang =
GETPOST(
'langsmodels',
'aZ09');
115 if (!empty($newlang)) {
117 $outputlangs->setDefaultLang($newlang);
119 $outputlangs->loadLangs(array(
'commercial',
'bills',
'orders',
'contracts',
'main',
'members',
'propal',
'products',
'supplier_proposal',
'interventions',
'receptions',
'sendings'));
120 if (!empty($defaulttopiclang)) {
121 $outputlangs->loadLangs(array($defaulttopiclang));
126 if (empty(
$object->ref_client)) {
127 $topicmail = $outputlangs->trans($defaulttopic,
'__REF__');
128 } elseif (!empty(
$object->ref_client)) {
129 $topicmail = $outputlangs->trans($defaulttopic,
'__REF__ (__REF_CLIENT__)');
133 $forcebuilddoc =
true;
135 if (in_array(
$object->element, array(
'user',
'member'))) {
136 $forcebuilddoc =
false;
139 $forcebuilddoc =
false;
142 $forcebuilddoc =
false;
145 $forcebuilddoc =
false;
148 $forcebuilddoc =
false;
151 if ($forcebuilddoc) {
152 if ((!$file || !is_readable($file)) && method_exists(
$object,
'generateDocument')) {
153 $hidedetails = empty($hidedetails) ?
'' : $hidedetails;
154 $hidedesc = empty($hidedesc) ?
'' : $hidedesc;
155 $hideref = empty($hideref) ?
'' : $hideref;
157 $result =
$object->generateDocument(
GETPOST(
'model') ?
GETPOST(
'model') :
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
163 if (
$object->element ==
'invoice_supplier') {
169 $file = isset($fileparams[
'fullname']) ? $fileparams[
'fullname'] :
null;
174 print
'<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
175 print
'<div class="clearboth"></div>';
182 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
185 $formmail->param[
'langsmodels'] = (empty($newlang) ? $langs->defaultlang : $newlang);
188 if ($formmail->fromtype ===
'user') {
189 $formmail->fromid = $user->id;
194 $formmail->fromtype =
'special';
199 $formmail->fromtype =
'special';
204 $formmail->fromtype =
'special';
209 $formmail->fromtype =
'special';
214 $formmail->fromtype =
'special';
216 if (
$object->element ===
'recruitmentcandidature') {
217 $formmail->frommail =
getDolGlobalString(
'RECRUITMENT_EMAIL_SENDER', (!empty($recruitermail) ? $recruitermail :
''));
218 $formmail->fromname =
getDolGlobalString(
'RECRUITMENT_EMAIL_SENDER_NAME', (!empty($recruitername) ? $recruitername :
''));
219 $formmail->fromtype =
'special';
224 if (GETPOSTISSET(
'fromtype')) {
225 $defaultfrom =
GETPOST(
'fromtype');
227 $parameters = array();
228 $reshook = $hookmanager->executeHooks(
'getDefaultFromEmail', $parameters, $formmail);
229 if (empty($reshook)) {
230 $defaultfrom = $formmail->fromtype;
232 if (!empty($hookmanager->resArray[
'defaultfrom'])) {
233 $defaultfrom = $hookmanager->resArray[
'defaultfrom'];
236 $formmail->fromtype = $defaultfrom;
238 $formmail->trackid = empty($trackid) ?
'' : $trackid;
239 $formmail->inreplyto = empty($inreplyto) ?
'' : $inreplyto;
240 $formmail->withfrom = 1;
241 $formmail->withlayout =
'email';
242 $formmail->withaiprompt =
'html';
247 if (
$object->element ==
'expensereport') {
248 '@phan-var-force ExpenseReport $object';
250 $fuser->fetch(
$object->fk_user_author);
251 $liste[
'thirdparty'] = $fuser->getFullName($outputlangs).
" <".$fuser->email.
">";
253 '@phan-var-force Partnership $object';
255 $fadherent->fetch(
$object->fk_member);
256 $liste[
'member'] = $fadherent->getFullName($outputlangs).
" <".$fadherent->email.
">";
257 } elseif (
$object->element ==
'societe') {
258 '@phan-var-force Societe $object';
259 foreach (
$object->thirdparty_and_contact_email_array(1) as $key => $value) {
260 $liste[$key] = $value;
262 } elseif (
$object->element ==
'contact') {
263 '@phan-var-force Contact $object';
264 $liste[
'contact'] =
$object->getFullName($outputlangs).
" <".
$object->email.
">";
265 } elseif (
$object->element ==
'user' ||
$object->element ==
'member') {
266 '@phan-var-force User|Adherent $object';
267 $liste[
'thirdparty'] =
$object->getFullName($outputlangs).
" <".
$object->email.
">";
268 } elseif (
$object->element ==
'salary') {
269 '@phan-var-force Salary $object';
271 $fuser->fetch(
$object->fk_user);
272 $liste[
'thirdparty'] = $fuser->getFullName($outputlangs).
" <".$fuser->email.
">";
279 if (is_object(
$object->thirdparty)) {
280 foreach (
$object->thirdparty->thirdparty_and_contact_email_array(1) as $key => $value) {
281 $liste[$key] = $value;
287 $listeuser = array();
289 $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);
290 if ($result > 0 && is_array($fuserdest->users) && count($fuserdest->users) > 0) {
291 foreach ($fuserdest->users as $uuserdest) {
292 $listeuser[$uuserdest->id] = $uuserdest->user_get_property($uuserdest->id,
'email');
294 } elseif ($result < 0) {
297 if (count($listeuser) > 0) {
298 $formmail->withtouser = $listeuser;
299 $formmail->withtoccuser = $listeuser;
304 if (!isset($arrayoffamiliestoexclude)) {
305 $arrayoffamiliestoexclude =
null;
311 $formmail->setSubstitFromObject(
$object, $outputlangs);
313 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, $arrayoffamiliestoexclude,
$object);
315 $emailsendersignature =
null;
317 if ($formmail->fromtype) {
319 if (preg_match(
'/user/', $formmail->fromtype, $reg)) {
320 $emailsendersignature = $user->signature;
321 } elseif (preg_match(
'/company/', $formmail->fromtype, $reg)) {
322 $emailsendersignature =
'';
323 } elseif (preg_match(
'/senderprofile_(\d+)/', $formmail->fromtype, $reg)) {
324 $sql =
"SELECT rowid, label, email, signature FROM ".$db->prefix().
"c_email_senderprofile";
325 $sql .=
" WHERE rowid = ".((int) $reg[1]);
326 $resql =
$db->query($sql);
328 $obj =
$db->fetch_object($resql);
330 $emailsendersignature = $obj->signature;
335 $substitutionarray[
'__SENDEREMAIL_SIGNATURE__'] = $emailsendersignature;
337 $substitutionarray[
'__CHECK_READ__'] =
"";
339 $checkRead =
'<img src="'.DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-read.php';
341 $checkRead .=
'?tag='.(!empty(
$object->thirdparty->tag) ? urlencode(
$object->thirdparty->tag) :
"");
342 $checkRead .=
'&securitykey='.(getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY') ? urlencode(
getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY')) :
"");
343 $checkRead .=
'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
344 $substitutionarray[
'__CHECK_READ__'] = $checkRead;
346 $substitutionarray[
'__CONTACTCIVNAME__'] =
'';
348 'mode' =>
'formemail'
354 if ((
$object->element ==
'shipping' ||
$object->element ==
'reception')) {
356 $origin_id =
$object->origin_id;
358 if (!empty($origin) && !empty($origin_id)) {
359 $element = $subelement = $origin;
361 if ($element ==
'order_supplier') {
363 $subelement =
'fournisseur.commande';
364 $origin =
'CommandeFournisseur';
368 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
370 $subelement = $regs[2];
373 if ($element ==
'order') {
374 $element = $subelement =
'commande';
376 if ($element ==
'propal') {
377 $element =
'comm/propal';
378 $subelement =
'propal';
380 if ($element ==
'contract') {
381 $element = $subelement =
'contrat';
383 if ($element ==
'inter') {
384 $element = $subelement =
'fichinter';
386 if ($element ==
'shipping') {
387 $element = $subelement =
'expedition';
389 if ($element ==
'project') {
394 $classname = ucfirst($origin);
395 $objectsrc =
new $classname(
$db);
396 '@phan-var-force Commande|Facture $objectsrc';
397 $objectsrc->fetch($origin_id);
399 $tmpobject = $objectsrc;
403 $contactarr = array();
404 $contactarr = $tmpobject->liste_contact(-1,
'external', 0,
'', 1);
406 if (is_array($contactarr) && count($contactarr) > 0) {
407 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
408 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
412 foreach ($contactarr as $contact) {
413 $contactstatic->fetch($contact[
'id']);
415 $substitutionarray[
'__CONTACT_NAME_'.$contact[
'code'].
'__'] = $contactstatic->getFullName($outputlangs, 1);
416 $substitutionarray[
'__CONTACT_LASTNAME_'.$contact[
'code'].
'__'] = $contactstatic->lastname;
417 $substitutionarray[
'__CONTACT_FIRSTNAME_'.$contact[
'code'].
'__'] = $contactstatic->firstname;
418 $substitutionarray[
'__CONTACT_TITLE_'.$contact[
'code'].
'__'] = $contactstatic->getCivilityLabel();
421 if (empty($liste[$contact[
'id']])) {
423 if (isset(
$object->thirdparty) && is_object(
$object->thirdparty)) {
424 if ($contactstatic->fk_soc !=
$object->thirdparty->id) {
425 $tmpcompany->fetch($contactstatic->fk_soc);
426 if ($tmpcompany->id > 0) {
427 $contacttoshow .= $tmpcompany->name.
': ';
431 $contacttoshow .= $contactstatic->getFullName($outputlangs, 1);
432 $contacttoshow .=
" <".($contactstatic->email ? $contactstatic->email : $langs->transnoentitiesnoconv(
"NoEMail")) .
">";
433 $liste[$contact[
'id']] = $contacttoshow;
438 $formmail->withto = $liste;
439 $formmail->withtofree = (
GETPOST(
'sendto',
'alphawithlgt') ?
GETPOST(
'sendto',
'alphawithlgt') :
'1');
440 $formmail->withtocc = $liste;
442 $formmail->withtopic = $topicmail;
443 $formmail->withfile = 2;
444 $formmail->withbody = 1;
445 $formmail->withdeliveryreceipt = 1;
446 $formmail->withcancel = 1;
449 $formmail->substit = $substitutionarray;
452 $formmail->param[
'action'] =
'send';
453 $formmail->param[
'models'] = $modelmail;
454 $formmail->param[
'models_id'] =
GETPOSTINT(
'modelmailselected');
455 $formmail->param[
'id'] =
$object->id;
456 $formmail->param[
'returnurl'] = $_SERVER[
"PHP_SELF"].
'?id='.
$object->id;
457 $formmail->param[
'fileinit'] = array($file);
458 $formmail->param[
'object_entity'] =
$object->entity;
461 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)
Return file(s) into a directory (by default most recent)
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_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.
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.
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...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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.