42@phan-var-force int<0,1> $diroutput
43@phan-var-force string $defaulttopic
44@phan-var-force string $defaulttopiclang
45@phan-var-force string[] $arrayoffamiliestoexclude
46@phan-var-force string $file
47@phan-var-force CommonObject $object
51if (empty($conf) || !is_object($conf)) {
52 print
"Error, template page can't be called as URL";
59if ($action ==
'presend') {
60 $langs->load(
"mails");
62 $titreform =
'SendMail';
67 if (!in_array(
$object->element, array(
'user',
'member'))) {
70 if (!empty(
$object->last_main_doc) && is_readable(DOL_DATA_ROOT.
'/'.
$object->last_main_doc) && is_file(DOL_DATA_ROOT.
'/'.
$object->last_main_doc)) {
71 $fileparams[
'fullname'] = DOL_DATA_ROOT.
'/'.
$object->last_main_doc;
73 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
75 if (
$object->element ==
'invoice_supplier') {
82 $file = isset($fileparams[
'fullname']) ? $fileparams[
'fullname'] :
null;
86 $outputlangs = $langs;
89 if (is_object(
$object->thirdparty)) {
90 $newlang =
$object->thirdparty->default_lang;
92 if (
GETPOST(
'lang_id',
'aZ09')) {
93 $newlang =
GETPOST(
'lang_id',
'aZ09');
97 if (!empty($newlang)) {
99 $outputlangs->setDefaultLang($newlang);
101 $outputlangs->loadLangs(array(
'commercial',
'bills',
'orders',
'contracts',
'main',
'members',
'propal',
'products',
'supplier_proposal',
'interventions',
'receptions',
'sendings'));
102 if (!empty($defaulttopiclang)) {
103 $outputlangs->loadLangs(array($defaulttopiclang));
108 if (empty(
$object->ref_client)) {
109 $topicmail = $outputlangs->trans($defaulttopic,
'__REF__');
110 } elseif (!empty(
$object->ref_client)) {
111 $topicmail = $outputlangs->trans($defaulttopic,
'__REF__ (__REF_CLIENT__)');
115 $forcebuilddoc =
true;
117 if (in_array(
$object->element, array(
'user',
'member'))) {
118 $forcebuilddoc =
false;
121 $forcebuilddoc =
false;
124 $forcebuilddoc =
false;
127 $forcebuilddoc =
false;
130 $forcebuilddoc =
false;
133 if ($forcebuilddoc) {
134 if ((!$file || !is_readable($file)) && method_exists(
$object,
'generateDocument')) {
135 $hidedetails = $hidedetails?$hidedetails:
'';
136 $hidedesc = $hidedetails?$hidedetails:
'';
137 $hideref = $hidedetails?$hidedetails:
'';
139 $result =
$object->generateDocument(
GETPOST(
'model') ?
GETPOST(
'model') :
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
144 if (
$object->element ==
'invoice_supplier') {
150 $file = isset($fileparams[
'fullname']) ? $fileparams[
'fullname'] :
null;
154 print
'<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
155 print
'<div class="clearboth"></div>';
162 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
165 $formmail->param[
'langsmodels'] = (empty($newlang) ? $langs->defaultlang : $newlang);
168 if ($formmail->fromtype ===
'user') {
169 $formmail->fromid = $user->id;
174 $formmail->fromtype =
'special';
179 $formmail->fromtype =
'special';
184 $formmail->fromtype =
'special';
189 $formmail->fromtype =
'special';
194 $formmail->fromtype =
'special';
196 if (
$object->element ===
'recruitmentcandidature') {
197 $formmail->frommail =
getDolGlobalString(
'RECRUITMENT_EMAIL_SENDER', (!empty($recruitermail) ? $recruitermail :
''));
198 $formmail->fromname =
getDolGlobalString(
'RECRUITMENT_EMAIL_SENDER_NAME', (!empty($recruitername) ? $recruitername :
''));
199 $formmail->fromtype =
'special';
204 if (GETPOSTISSET(
'fromtype')) {
205 $defaultfrom =
GETPOST(
'fromtype');
207 $parameters = array();
208 $reshook = $hookmanager->executeHooks(
'getDefaultFromEmail', $parameters, $formmail);
209 if (empty($reshook)) {
210 $defaultfrom = $formmail->fromtype;
212 if (!empty($hookmanager->resArray[
'defaultfrom'])) {
213 $defaultfrom = $hookmanager->resArray[
'defaultfrom'];
216 $formmail->fromtype = $defaultfrom;
218 $formmail->trackid = empty($trackid) ?
'' : $trackid;
219 $formmail->inreplyto = empty($inreplyto) ?
'' : $inreplyto;
220 $formmail->withfrom = 1;
221 $formmail->withlayout =
'email';
222 $formmail->withaiprompt =
'html';
227 if (
$object->element ==
'expensereport') {
228 '@phan-var-force ExpenseReport $object';
229 $fuser =
new User($db);
230 $fuser->fetch(
$object->fk_user_author);
231 $liste[
'thirdparty'] = $fuser->getFullName($outputlangs).
" <".$fuser->email.
">";
233 '@phan-var-force Partnership $object';
235 $fadherent->fetch(
$object->fk_member);
236 $liste[
'member'] = $fadherent->getFullName($outputlangs).
" <".$fadherent->email.
">";
237 } elseif (
$object->element ==
'societe') {
238 '@phan-var-force Societe $object';
239 foreach (
$object->thirdparty_and_contact_email_array(1) as $key => $value) {
240 $liste[$key] = $value;
242 } elseif (
$object->element ==
'contact') {
243 '@phan-var-force Contact $object';
244 $liste[
'contact'] =
$object->getFullName($outputlangs).
" <".
$object->email.
">";
245 } elseif (
$object->element ==
'user' ||
$object->element ==
'member') {
246 '@phan-var-force User|Adherent $object';
247 $liste[
'thirdparty'] =
$object->getFullName($outputlangs).
" <".
$object->email.
">";
248 } elseif (
$object->element ==
'salary') {
249 '@phan-var-force Salary $object';
250 $fuser =
new User($db);
251 $fuser->fetch(
$object->fk_user);
252 $liste[
'thirdparty'] = $fuser->getFullName($outputlangs).
" <".$fuser->email.
">";
258 if (is_object(
$object->thirdparty)) {
259 foreach (
$object->thirdparty->thirdparty_and_contact_email_array(1) as $key => $value) {
260 $liste[$key] = $value;
266 $listeuser = array();
267 $fuserdest =
new User($db);
268 $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);
269 if ($result > 0 && is_array($fuserdest->users) && count($fuserdest->users) > 0) {
270 foreach ($fuserdest->users as $uuserdest) {
271 $listeuser[$uuserdest->id] = $uuserdest->user_get_property($uuserdest->id,
'email');
273 } elseif ($result < 0) {
276 if (count($listeuser) > 0) {
277 $formmail->withtouser = $listeuser;
278 $formmail->withtoccuser = $listeuser;
283 if (!isset($arrayoffamiliestoexclude)) {
284 $arrayoffamiliestoexclude =
null;
290 $formmail->setSubstitFromObject(
$object, $langs);
292 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, $arrayoffamiliestoexclude,
$object);
294 $emailsendersignature =
null;
296 if ($formmail->fromtype) {
298 if (preg_match(
'/user/', $formmail->fromtype, $reg)) {
299 $emailsendersignature = $user->signature;
300 } elseif (preg_match(
'/company/', $formmail->fromtype, $reg)) {
301 $emailsendersignature =
'';
302 } elseif (preg_match(
'/senderprofile_(\d+)/', $formmail->fromtype, $reg)) {
303 $sql =
"SELECT rowid, label, email, signature FROM ".$db->prefix().
"c_email_senderprofile";
304 $sql .=
" WHERE rowid = ".((int) $reg[1]);
305 $resql = $db->query($sql);
307 $obj = $db->fetch_object($resql);
309 $emailsendersignature = $obj->signature;
314 $substitutionarray[
'__SENDEREMAIL_SIGNATURE__'] = $emailsendersignature;
316 $substitutionarray[
'__CHECK_READ__'] =
"";
318 $checkRead =
'<img src="'.DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-read.php';
320 $checkRead .=
'?tag='.(!empty(
$object->thirdparty->tag) ? urlencode(
$object->thirdparty->tag) :
"");
321 $checkRead .=
'&securitykey='.(getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY') ? urlencode(
getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY')) :
"");
322 $checkRead .=
'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
323 $substitutionarray[
'__CHECK_READ__'] = $checkRead;
325 $substitutionarray[
'__CONTACTCIVNAME__'] =
'';
327 'mode' =>
'formemail'
333 if ((
$object->element ==
'shipping' ||
$object->element ==
'reception')) {
335 $origin_id =
$object->origin_id;
337 if (!empty($origin) && !empty($origin_id)) {
338 $element = $subelement = $origin;
340 if ($element ==
'order_supplier') {
342 $subelement =
'fournisseur.commande';
343 $origin =
'CommandeFournisseur';
347 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
349 $subelement = $regs[2];
352 if ($element ==
'order') {
353 $element = $subelement =
'commande';
355 if ($element ==
'propal') {
356 $element =
'comm/propal';
357 $subelement =
'propal';
359 if ($element ==
'contract') {
360 $element = $subelement =
'contrat';
362 if ($element ==
'inter') {
363 $element = $subelement =
'fichinter';
365 if ($element ==
'shipping') {
366 $element = $subelement =
'expedition';
368 if ($element ==
'project') {
373 $classname = ucfirst($origin);
374 $objectsrc =
new $classname($db);
375 '@phan-var-force Commande|Facture $objectsrc';
376 $objectsrc->fetch($origin_id);
378 $tmpobject = $objectsrc;
382 $contactarr = array();
383 $contactarr = $tmpobject->liste_contact(-1,
'external', 0,
'', 1);
385 if (is_array($contactarr) && count($contactarr) > 0) {
386 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
387 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
388 $contactstatic =
new Contact($db);
389 $tmpcompany =
new Societe($db);
391 foreach ($contactarr as $contact) {
392 $contactstatic->fetch($contact[
'id']);
394 $substitutionarray[
'__CONTACT_NAME_'.$contact[
'code'].
'__'] = $contactstatic->getFullName($outputlangs, 1);
395 $substitutionarray[
'__CONTACT_LASTNAME_'.$contact[
'code'].
'__'] = $contactstatic->lastname;
396 $substitutionarray[
'__CONTACT_FIRSTNAME_'.$contact[
'code'].
'__'] = $contactstatic->firstname;
397 $substitutionarray[
'__CONTACT_TITLE_'.$contact[
'code'].
'__'] = $contactstatic->getCivilityLabel();
400 if (empty($liste[$contact[
'id']])) {
402 if (isset(
$object->thirdparty) && is_object(
$object->thirdparty)) {
403 if ($contactstatic->fk_soc !=
$object->thirdparty->id) {
404 $tmpcompany->fetch($contactstatic->fk_soc);
405 if ($tmpcompany->id > 0) {
406 $contacttoshow .= $tmpcompany->name.
': ';
410 $contacttoshow .= $contactstatic->getFullName($outputlangs, 1);
411 $contacttoshow .=
" <".($contactstatic->email ? $contactstatic->email : $langs->transnoentitiesnoconv(
"NoEMail")) .
">";
412 $liste[$contact[
'id']] = $contacttoshow;
417 $formmail->withto = $liste;
418 $formmail->withtofree = (
GETPOST(
'sendto',
'alphawithlgt') ?
GETPOST(
'sendto',
'alphawithlgt') :
'1');
419 $formmail->withtocc = $liste;
421 $formmail->withtopic = $topicmail;
422 $formmail->withfile = 2;
423 $formmail->withbody = 1;
424 $formmail->withdeliveryreceipt = 1;
425 $formmail->withcancel = 1;
428 $formmail->substit = $substitutionarray;
431 $formmail->param[
'action'] =
'send';
432 $formmail->param[
'models'] = $modelmail;
433 $formmail->param[
'models_id'] =
GETPOSTINT(
'modelmailselected');
434 $formmail->param[
'id'] =
$object->id;
435 $formmail->param[
'returnurl'] = $_SERVER[
"PHP_SELF"].
'?id='.
$object->id;
436 $formmail->param[
'fileinit'] = array($file);
437 $formmail->param[
'object_entity'] =
$object->entity;
440 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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.