40@phan-var-force int<0,1> $diroutput
41@phan-var-force string $defaulttopic
42@phan-var-force string $defaulttopiclang
43@phan-var-force string[] $arrayoffamiliestoexclude
44@phan-var-force string $file
45@phan-var-force CommonObject $object
50 print
"Error, template page can't be called as URL";
57if ($action ==
'presend') {
58 $langs->load(
"mails");
60 $titreform =
'SendMail';
65 if (!in_array(
$object->element, array(
'user',
'member'))) {
68 if (!empty(
$object->last_main_doc) && is_readable(DOL_DATA_ROOT.
'/'.
$object->last_main_doc) && is_file(DOL_DATA_ROOT.
'/'.
$object->last_main_doc)) {
69 $fileparams[
'fullname'] = DOL_DATA_ROOT.
'/'.
$object->last_main_doc;
71 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
73 if (
$object->element ==
'invoice_supplier') {
80 $file = isset($fileparams[
'fullname']) ? $fileparams[
'fullname'] :
null;
84 $outputlangs = $langs;
87 if (is_object(
$object->thirdparty)) {
88 $newlang =
$object->thirdparty->default_lang;
90 if (
GETPOST(
'lang_id',
'aZ09')) {
91 $newlang =
GETPOST(
'lang_id',
'aZ09');
95 if (!empty($newlang)) {
97 $outputlangs->setDefaultLang($newlang);
99 $outputlangs->loadLangs(array(
'commercial',
'bills',
'orders',
'contracts',
'main',
'members',
'propal',
'products',
'supplier_proposal',
'interventions',
'receptions',
'sendings'));
100 if (!empty($defaulttopiclang)) {
101 $outputlangs->loadLangs(array($defaulttopiclang));
106 if (empty(
$object->ref_client)) {
107 $topicmail = $outputlangs->trans($defaulttopic,
'__REF__');
108 } elseif (!empty(
$object->ref_client)) {
109 $topicmail = $outputlangs->trans($defaulttopic,
'__REF__ (__REF_CLIENT__)');
113 $forcebuilddoc =
true;
115 if (in_array(
$object->element, array(
'user',
'member'))) {
116 $forcebuilddoc =
false;
119 $forcebuilddoc =
false;
122 $forcebuilddoc =
false;
125 $forcebuilddoc =
false;
128 $forcebuilddoc =
false;
131 if ($forcebuilddoc) {
132 if ((!$file || !is_readable($file)) && method_exists(
$object,
'generateDocument')) {
133 $hidedetails = $hidedetails?$hidedetails:
'';
134 $hidedesc = $hidedetails?$hidedetails:
'';
135 $hideref = $hidedetails?$hidedetails:
'';
137 $result =
$object->generateDocument(
GETPOST(
'model') ?
GETPOST(
'model') :
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
142 if (
$object->element ==
'invoice_supplier') {
148 $file = isset($fileparams[
'fullname']) ? $fileparams[
'fullname'] :
null;
152 print
'<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
153 print
'<div class="clearboth"></div>';
160 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
163 $formmail->param[
'langsmodels'] = (empty($newlang) ? $langs->defaultlang : $newlang);
166 if ($formmail->fromtype ===
'user') {
167 $formmail->fromid = $user->id;
172 $formmail->fromtype =
'special';
177 $formmail->fromtype =
'special';
182 $formmail->fromtype =
'special';
187 $formmail->fromtype =
'special';
192 $formmail->fromtype =
'special';
194 if (
$object->element ===
'recruitmentcandidature') {
195 $formmail->frommail =
getDolGlobalString(
'RECRUITMENT_EMAIL_SENDER', (!empty($recruitermail) ? $recruitermail :
''));
196 $formmail->fromname =
getDolGlobalString(
'RECRUITMENT_EMAIL_SENDER_NAME', (!empty($recruitername) ? $recruitername :
''));
197 $formmail->fromtype =
'special';
202 if (GETPOSTISSET(
'fromtype')) {
203 $defaultfrom =
GETPOST(
'fromtype');
205 $parameters = array();
206 $reshook = $hookmanager->executeHooks(
'getDefaultFromEmail', $parameters, $formmail);
207 if (empty($reshook)) {
208 $defaultfrom = $formmail->fromtype;
210 if (!empty($hookmanager->resArray[
'defaultfrom'])) {
211 $defaultfrom = $hookmanager->resArray[
'defaultfrom'];
214 $formmail->fromtype = $defaultfrom;
216 $formmail->trackid = empty($trackid) ?
'' : $trackid;
217 $formmail->inreplyto = empty($inreplyto) ?
'' : $inreplyto;
218 $formmail->withfrom = 1;
219 $formmail->withlayout =
'email';
220 $formmail->withaiprompt =
'html';
224 if (
$object->element ==
'expensereport') {
225 '@phan-var-force ExpenseReport $object';
226 $fuser =
new User($db);
227 $fuser->fetch(
$object->fk_user_author);
228 $liste[
'thirdparty'] = $fuser->getFullName($outputlangs).
" <".$fuser->email.
">";
230 '@phan-var-force Partnership $object';
232 $fadherent->fetch(
$object->fk_member);
233 $liste[
'member'] = $fadherent->getFullName($outputlangs).
" <".$fadherent->email.
">";
234 } elseif (
$object->element ==
'societe') {
235 '@phan-var-force Societe $object';
236 foreach (
$object->thirdparty_and_contact_email_array(1) as $key => $value) {
237 $liste[$key] = $value;
239 } elseif (
$object->element ==
'contact') {
240 '@phan-var-force Contact $object';
241 $liste[
'contact'] =
$object->getFullName($outputlangs).
" <".
$object->email.
">";
242 } elseif (
$object->element ==
'user' ||
$object->element ==
'member') {
243 '@phan-var-force User|Adherent $object';
244 $liste[
'thirdparty'] =
$object->getFullName($outputlangs).
" <".
$object->email.
">";
245 } elseif (
$object->element ==
'salary') {
246 '@phan-var-force Salary $object';
247 $fuser =
new User($db);
248 $fuser->fetch(
$object->fk_user);
249 $liste[
'thirdparty'] = $fuser->getFullName($outputlangs).
" <".$fuser->email.
">";
255 if (is_object(
$object->thirdparty)) {
256 foreach (
$object->thirdparty->thirdparty_and_contact_email_array(1) as $key => $value) {
257 $liste[$key] = $value;
263 $listeuser = array();
264 $fuserdest =
new User($db);
265 $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);
266 if ($result > 0 && is_array($fuserdest->users) && count($fuserdest->users) > 0) {
267 foreach ($fuserdest->users as $uuserdest) {
268 $listeuser[$uuserdest->id] = $uuserdest->user_get_property($uuserdest->id,
'email');
270 } elseif ($result < 0) {
273 if (count($listeuser) > 0) {
274 $formmail->withtouser = $listeuser;
275 $formmail->withtoccuser = $listeuser;
280 if (!isset($arrayoffamiliestoexclude)) {
281 $arrayoffamiliestoexclude =
null;
287 $formmail->setSubstitFromObject(
$object, $langs);
289 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, $arrayoffamiliestoexclude,
$object);
291 $emailsendersignature =
null;
293 if ($formmail->fromtype) {
295 if (preg_match(
'/user/', $formmail->fromtype, $reg)) {
296 $emailsendersignature = $user->signature;
297 } elseif (preg_match(
'/company/', $formmail->fromtype, $reg)) {
298 $emailsendersignature =
'';
299 } elseif (preg_match(
'/senderprofile_(\d+)/', $formmail->fromtype, $reg)) {
300 $sql =
"SELECT rowid, label, email, signature FROM ".$db->prefix().
"c_email_senderprofile";
301 $sql .=
" WHERE rowid = ".((int) $reg[1]);
302 $resql = $db->query($sql);
304 $obj = $db->fetch_object($resql);
306 $emailsendersignature = $obj->signature;
311 $substitutionarray[
'__SENDEREMAIL_SIGNATURE__'] = $emailsendersignature;
313 $substitutionarray[
'__CHECK_READ__'] =
"";
315 $checkRead =
'<img src="'.DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-read.php';
317 $checkRead .=
'?tag='.(!empty(
$object->thirdparty->tag) ? urlencode(
$object->thirdparty->tag) :
"");
318 $checkRead .=
'&securitykey='.(getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY') ? urlencode(
getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY')) :
"");
319 $checkRead .=
'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
320 $substitutionarray[
'__CHECK_READ__'] = $checkRead;
322 $substitutionarray[
'__CONTACTCIVNAME__'] =
'';
324 'mode' =>
'formemail'
330 if ((
$object->element ==
'shipping' ||
$object->element ==
'reception')) {
332 $origin_id =
$object->origin_id;
334 if (!empty($origin) && !empty($origin_id)) {
335 $element = $subelement = $origin;
337 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
339 $subelement = $regs[2];
342 if ($element ==
'order') {
343 $element = $subelement =
'commande';
345 if ($element ==
'propal') {
346 $element =
'comm/propal';
347 $subelement =
'propal';
349 if ($element ==
'contract') {
350 $element = $subelement =
'contrat';
352 if ($element ==
'inter') {
353 $element = $subelement =
'fichinter';
355 if ($element ==
'shipping') {
356 $element = $subelement =
'expedition';
358 if ($element ==
'order_supplier') {
360 $subelement =
'fournisseur.commande';
362 if ($element ==
'project') {
367 $classname = ucfirst($origin);
368 $objectsrc =
new $classname($db);
369 '@phan-var-force Commande|Facture $objectsrc';
370 $objectsrc->fetch($origin_id);
372 $tmpobject = $objectsrc;
376 $contactarr = array();
377 $contactarr = $tmpobject->liste_contact(-1,
'external', 0,
'', 1);
379 if (is_array($contactarr) && count($contactarr) > 0) {
380 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
381 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
382 $contactstatic =
new Contact($db);
383 $tmpcompany =
new Societe($db);
385 foreach ($contactarr as $contact) {
386 $contactstatic->fetch($contact[
'id']);
388 $substitutionarray[
'__CONTACT_NAME_'.$contact[
'code'].
'__'] = $contactstatic->getFullName($outputlangs, 1);
389 $substitutionarray[
'__CONTACT_LASTNAME_'.$contact[
'code'].
'__'] = $contactstatic->lastname;
390 $substitutionarray[
'__CONTACT_FIRSTNAME_'.$contact[
'code'].
'__'] = $contactstatic->firstname;
391 $substitutionarray[
'__CONTACT_TITLE_'.$contact[
'code'].
'__'] = $contactstatic->getCivilityLabel();
394 if (empty($liste[$contact[
'id']])) {
396 if (isset(
$object->thirdparty) && is_object(
$object->thirdparty)) {
397 if ($contactstatic->fk_soc !=
$object->thirdparty->id) {
398 $tmpcompany->fetch($contactstatic->fk_soc);
399 if ($tmpcompany->id > 0) {
400 $contacttoshow .= $tmpcompany->name.
': ';
404 $contacttoshow .= $contactstatic->getFullName($outputlangs, 1);
405 $contacttoshow .=
" <".($contactstatic->email ? $contactstatic->email : $langs->transnoentitiesnoconv(
"NoEMail")) .
">";
406 $liste[$contact[
'id']] = $contacttoshow;
411 $formmail->withto = $liste;
412 $formmail->withtofree = (
GETPOST(
'sendto',
'alphawithlgt') ?
GETPOST(
'sendto',
'alphawithlgt') :
'1');
413 $formmail->withtocc = $liste;
415 $formmail->withtopic = $topicmail;
416 $formmail->withfile = 2;
417 $formmail->withbody = 1;
418 $formmail->withdeliveryreceipt = 1;
419 $formmail->withcancel = 1;
422 $formmail->substit = $substitutionarray;
425 $formmail->param[
'action'] =
'send';
426 $formmail->param[
'models'] = $modelmail;
427 $formmail->param[
'models_id'] =
GETPOSTINT(
'modelmailselected');
428 $formmail->param[
'id'] =
$object->id;
429 $formmail->param[
'returnurl'] = $_SERVER[
"PHP_SELF"].
'?id='.
$object->id;
430 $formmail->param[
'fileinit'] = array($file);
431 $formmail->param[
'object_entity'] =
$object->entity;
434 print $formmail->get_form();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $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)
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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.
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...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...