35@phan-var-force int<0,1> $diroutput
36@phan-var-force string $defaulttopic
37@phan-var-force string $defaulttopiclang
38@phan-var-force string[] $arrayoffamiliestoexclude
39@phan-var-force string $file
40@phan-var-force CommonObject $object
45 print
"Error, template page can't be called as URL";
51if ($action ==
'presend') {
52 $langs->load(
"mails");
54 $titreform =
'SendMail';
58 if (!in_array(
$object->element, array(
'user',
'member'))) {
61 if (!empty(
$object->last_main_doc) && is_readable(DOL_DATA_ROOT.
'/'.
$object->last_main_doc) && is_file(DOL_DATA_ROOT.
'/'.
$object->last_main_doc)) {
62 $fileparams[
'fullname'] = DOL_DATA_ROOT.
'/'.
$object->last_main_doc;
64 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
66 if (
$object->element ==
'invoice_supplier') {
73 $file = isset($fileparams[
'fullname']) ? $fileparams[
'fullname'] :
null;
77 $outputlangs = $langs;
80 if (is_object(
$object->thirdparty)) {
81 $newlang =
$object->thirdparty->default_lang;
83 if (
GETPOST(
'lang_id',
'aZ09')) {
84 $newlang =
GETPOST(
'lang_id',
'aZ09');
88 if (!empty($newlang)) {
90 $outputlangs->setDefaultLang($newlang);
92 $outputlangs->loadLangs(array(
'commercial',
'bills',
'orders',
'contracts',
'main',
'members',
'propal',
'products',
'supplier_proposal',
'interventions',
'receptions',
'sendings'));
93 if (!empty($defaulttopiclang)) {
94 $outputlangs->loadLangs(array($defaulttopiclang));
99 if (empty(
$object->ref_client)) {
100 $topicmail = $outputlangs->trans($defaulttopic,
'__REF__');
101 } elseif (!empty(
$object->ref_client)) {
102 $topicmail = $outputlangs->trans($defaulttopic,
'__REF__ (__REF_CLIENT__)');
106 $forcebuilddoc =
true;
107 if (in_array(
$object->element, array(
'user',
'member'))) {
108 $forcebuilddoc =
false;
111 $forcebuilddoc =
false;
114 $forcebuilddoc =
false;
116 if ($forcebuilddoc) {
117 if ((!$file || !is_readable($file)) && method_exists(
$object,
'generateDocument')) {
118 $result =
$object->generateDocument(
GETPOST(
'model') ?
GETPOST(
'model') :
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
123 if (
$object->element ==
'invoice_supplier') {
129 $file = isset($fileparams[
'fullname']) ? $fileparams[
'fullname'] :
null;
133 print
'<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
134 print
'<div class="clearboth"></div>';
141 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
144 $formmail->param[
'langsmodels'] = (empty($newlang) ? $langs->defaultlang : $newlang);
147 if ($formmail->fromtype ===
'user') {
148 $formmail->fromid = $user->id;
153 $formmail->fromtype =
'special';
158 $formmail->fromtype =
'special';
163 $formmail->fromtype =
'special';
168 $formmail->fromtype =
'special';
173 $formmail->fromtype =
'special';
175 if (
$object->element ===
'recruitmentcandidature') {
176 $formmail->frommail =
getDolGlobalString(
'RECRUITMENT_EMAIL_SENDER', (!empty($recruitermail) ? $recruitermail :
''));
177 $formmail->fromname =
getDolGlobalString(
'RECRUITMENT_EMAIL_SENDER_NAME', (!empty($recruitername) ? $recruitername :
''));
178 $formmail->fromtype =
'special';
183 if (GETPOSTISSET(
'fromtype')) {
184 $defaultfrom =
GETPOST(
'fromtype');
186 $parameters = array();
187 $reshook = $hookmanager->executeHooks(
'getDefaultFromEmail', $parameters, $formmail);
188 if (empty($reshook)) {
189 $defaultfrom = $formmail->fromtype;
191 if (!empty($hookmanager->resArray[
'defaultfrom'])) {
192 $defaultfrom = $hookmanager->resArray[
'defaultfrom'];
195 $formmail->fromtype = $defaultfrom;
197 $formmail->trackid = empty($trackid) ?
'' : $trackid;
198 $formmail->inreplyto = empty($inreplyto) ?
'' : $inreplyto;
199 $formmail->withfrom = 1;
200 $formmail->withlayout =
'email';
201 $formmail->withaiprompt =
'html';
205 if (
$object->element ==
'expensereport') {
206 '@phan-var-force ExpenseReport $object';
207 $fuser =
new User($db);
208 $fuser->fetch(
$object->fk_user_author);
209 $liste[
'thirdparty'] = $fuser->getFullName($outputlangs).
" <".$fuser->email.
">";
211 '@phan-var-force Partnership $object';
213 $fadherent->fetch(
$object->fk_member);
214 $liste[
'member'] = $fadherent->getFullName($outputlangs).
" <".$fadherent->email.
">";
215 } elseif (
$object->element ==
'societe') {
216 '@phan-var-force Societe $object';
217 foreach (
$object->thirdparty_and_contact_email_array(1) as $key => $value) {
218 $liste[$key] = $value;
220 } elseif (
$object->element ==
'contact') {
221 '@phan-var-force Contact $object';
222 $liste[
'contact'] =
$object->getFullName($outputlangs).
" <".
$object->email.
">";
223 } elseif (
$object->element ==
'user' ||
$object->element ==
'member') {
224 '@phan-var-force User|Adherent $object';
225 $liste[
'thirdparty'] =
$object->getFullName($outputlangs).
" <".
$object->email.
">";
226 } elseif (
$object->element ==
'salary') {
227 '@phan-var-force Salary $object';
228 $fuser =
new User($db);
229 $fuser->fetch(
$object->fk_user);
230 $liste[
'thirdparty'] = $fuser->getFullName($outputlangs).
" <".$fuser->email.
">";
236 if (is_object(
$object->thirdparty)) {
237 foreach (
$object->thirdparty->thirdparty_and_contact_email_array(1) as $key => $value) {
238 $liste[$key] = $value;
244 $listeuser = array();
245 $fuserdest =
new User($db);
246 $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);
247 if ($result > 0 && is_array($fuserdest->users) && count($fuserdest->users) > 0) {
248 foreach ($fuserdest->users as $uuserdest) {
249 $listeuser[$uuserdest->id] = $uuserdest->user_get_property($uuserdest->id,
'email');
251 } elseif ($result < 0) {
254 if (count($listeuser) > 0) {
255 $formmail->withtouser = $listeuser;
256 $formmail->withtoccuser = $listeuser;
261 if (!isset($arrayoffamiliestoexclude)) {
262 $arrayoffamiliestoexclude =
null;
268 $formmail->setSubstitFromObject(
$object, $langs);
272 $emailsendersignature =
null;
274 if ($formmail->fromtype) {
276 if (preg_match(
'/user/', $formmail->fromtype, $reg)) {
277 $emailsendersignature = $user->signature;
278 } elseif (preg_match(
'/company/', $formmail->fromtype, $reg)) {
279 $emailsendersignature =
'';
280 } elseif (preg_match(
'/senderprofile_(\d+)/', $formmail->fromtype, $reg)) {
281 $sql =
"SELECT rowid, label, email, signature FROM ".$db->prefix().
"c_email_senderprofile";
282 $sql .=
" WHERE rowid = ".((int) $reg[1]);
283 $resql = $db->query($sql);
285 $obj = $db->fetch_object($resql);
287 $emailsendersignature = $obj->signature;
292 $substitutionarray[
'__SENDEREMAIL_SIGNATURE__'] = $emailsendersignature;
294 $substitutionarray[
'__CHECK_READ__'] =
"";
296 $checkRead =
'<img src="'.DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-read.php';
298 $checkRead .=
'?tag='.(!empty(
$object->thirdparty->tag) ? urlencode(
$object->thirdparty->tag) :
"");
299 $checkRead .=
'&securitykey='.(getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY') ? urlencode(
getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY')) :
"");
300 $checkRead .=
'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
301 $substitutionarray[
'__CHECK_READ__'] = $checkRead;
303 $substitutionarray[
'__CONTACTCIVNAME__'] =
'';
305 'mode' =>
'formemail'
311 if ((
$object->element ==
'shipping' ||
$object->element ==
'reception')) {
313 $origin_id =
$object->origin_id;
315 if (!empty($origin) && !empty($origin_id)) {
316 $element = $subelement = $origin;
318 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
320 $subelement = $regs[2];
323 if ($element ==
'order') {
324 $element = $subelement =
'commande';
326 if ($element ==
'propal') {
327 $element =
'comm/propal';
328 $subelement =
'propal';
330 if ($element ==
'contract') {
331 $element = $subelement =
'contrat';
333 if ($element ==
'inter') {
334 $element = $subelement =
'fichinter';
336 if ($element ==
'shipping') {
337 $element = $subelement =
'expedition';
339 if ($element ==
'order_supplier') {
341 $subelement =
'fournisseur.commande';
343 if ($element ==
'project') {
348 $classname = ucfirst($origin);
349 $objectsrc =
new $classname($db);
350 '@phan-var-force Commande|Facture $objectsrc';
351 $objectsrc->fetch($origin_id);
353 $tmpobject = $objectsrc;
357 $contactarr = array();
358 $contactarr = $tmpobject->liste_contact(-1,
'external', 0,
'', 1);
360 if (is_array($contactarr) && count($contactarr) > 0) {
361 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
362 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
363 $contactstatic =
new Contact($db);
364 $tmpcompany =
new Societe($db);
366 foreach ($contactarr as $contact) {
367 $contactstatic->fetch($contact[
'id']);
369 $substitutionarray[
'__CONTACT_NAME_'.$contact[
'code'].
'__'] = $contactstatic->getFullName($outputlangs, 1);
370 $substitutionarray[
'__CONTACT_LASTNAME_'.$contact[
'code'].
'__'] = $contactstatic->lastname;
371 $substitutionarray[
'__CONTACT_FIRSTNAME_'.$contact[
'code'].
'__'] = $contactstatic->firstname;
372 $substitutionarray[
'__CONTACT_TITLE_'.$contact[
'code'].
'__'] = $contactstatic->getCivilityLabel();
375 if (empty($liste[$contact[
'id']])) {
377 if (isset(
$object->thirdparty) && is_object(
$object->thirdparty)) {
378 if ($contactstatic->fk_soc !=
$object->thirdparty->id) {
379 $tmpcompany->fetch($contactstatic->fk_soc);
380 if ($tmpcompany->id > 0) {
381 $contacttoshow .= $tmpcompany->name.
': ';
385 $contacttoshow .= $contactstatic->getFullName($outputlangs, 1);
386 $contacttoshow .=
" <".($contactstatic->email ? $contactstatic->email : $langs->transnoentitiesnoconv(
"NoEMail")) .
">";
387 $liste[$contact[
'id']] = $contacttoshow;
392 $formmail->withto = $liste;
393 $formmail->withtofree = (
GETPOST(
'sendto',
'alphawithlgt') ?
GETPOST(
'sendto',
'alphawithlgt') :
'1');
394 $formmail->withtocc = $liste;
396 $formmail->withtopic = $topicmail;
397 $formmail->withfile = 2;
398 $formmail->withbody = 1;
399 $formmail->withdeliveryreceipt = 1;
400 $formmail->withcancel = 1;
403 $formmail->substit = $substitutionarray;
406 $formmail->param[
'action'] =
'send';
407 $formmail->param[
'models'] = $modelmail;
408 $formmail->param[
'models_id'] =
GETPOSTINT(
'modelmailselected');
409 $formmail->param[
'id'] =
$object->id;
410 $formmail->param[
'returnurl'] = $_SERVER[
"PHP_SELF"].
'?id='.
$object->id;
411 $formmail->param[
'fileinit'] = array($file);
412 $formmail->param[
'object_entity'] =
$object->entity;
415 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)
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_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null, $include=null)
Return array of possible common substitutions.
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...