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 CommonObject $object
58 print
"Error, template page can't be called as URL";
64if ($action ==
'presend') {
65 $langs->load(
"mails");
67 $titreform =
'SendMail';
72 if (!in_array(
$object->element, array(
'user',
'member'))) {
75 if (!empty(
$object->last_main_doc) && is_readable(DOL_DATA_ROOT.
'/'.
$object->last_main_doc) && is_file(DOL_DATA_ROOT.
'/'.
$object->last_main_doc)) {
76 $fileparams[
'fullname'] = DOL_DATA_ROOT.
'/'.
$object->last_main_doc;
78 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
80 if (
$object->element ==
'invoice_supplier') {
87 $file = isset($fileparams[
'fullname']) ? $fileparams[
'fullname'] :
null;
91 $outputlangs = $langs;
94 if (is_object(
$object->thirdparty)) {
95 $newlang =
$object->thirdparty->default_lang;
97 if (
GETPOST(
'lang_id',
'aZ09')) {
98 $newlang =
GETPOST(
'lang_id',
'aZ09');
102 if (!empty($newlang)) {
104 $outputlangs->setDefaultLang($newlang);
106 $outputlangs->loadLangs(array(
'commercial',
'bills',
'orders',
'contracts',
'main',
'members',
'propal',
'products',
'supplier_proposal',
'interventions',
'receptions',
'sendings'));
107 if (!empty($defaulttopiclang)) {
108 $outputlangs->loadLangs(array($defaulttopiclang));
113 if (empty(
$object->ref_client)) {
114 $topicmail = $outputlangs->trans($defaulttopic,
'__REF__');
115 } elseif (!empty(
$object->ref_client)) {
116 $topicmail = $outputlangs->trans($defaulttopic,
'__REF__ (__REF_CLIENT__)');
120 $forcebuilddoc =
true;
122 if (in_array(
$object->element, array(
'user',
'member'))) {
123 $forcebuilddoc =
false;
126 $forcebuilddoc =
false;
129 $forcebuilddoc =
false;
132 $forcebuilddoc =
false;
135 $forcebuilddoc =
false;
138 if ($forcebuilddoc) {
139 if ((!$file || !is_readable($file)) && method_exists(
$object,
'generateDocument')) {
140 $result =
$object->generateDocument(
GETPOST(
'model') ?
GETPOST(
'model') :
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
145 if (
$object->element ==
'invoice_supplier') {
151 $file = isset($fileparams[
'fullname']) ? $fileparams[
'fullname'] :
null;
155 print
'<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
156 print
'<div class="clearboth"></div>';
163 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
166 $formmail->param[
'langsmodels'] = (empty($newlang) ? $langs->defaultlang : $newlang);
169 if ($formmail->fromtype ===
'user') {
170 $formmail->fromid = $user->id;
175 $formmail->fromtype =
'special';
180 $formmail->fromtype =
'special';
185 $formmail->fromtype =
'special';
190 $formmail->fromtype =
'special';
195 $formmail->fromtype =
'special';
197 if (
$object->element ===
'recruitmentcandidature') {
198 $formmail->frommail =
getDolGlobalString(
'RECRUITMENT_EMAIL_SENDER', (!empty($recruitermail) ? $recruitermail :
''));
199 $formmail->fromname =
getDolGlobalString(
'RECRUITMENT_EMAIL_SENDER_NAME', (!empty($recruitername) ? $recruitername :
''));
200 $formmail->fromtype =
'special';
205 if (GETPOSTISSET(
'fromtype')) {
206 $defaultfrom =
GETPOST(
'fromtype');
208 $parameters = array();
209 $reshook = $hookmanager->executeHooks(
'getDefaultFromEmail', $parameters, $formmail);
210 if (empty($reshook)) {
211 $defaultfrom = $formmail->fromtype;
213 if (!empty($hookmanager->resArray[
'defaultfrom'])) {
214 $defaultfrom = $hookmanager->resArray[
'defaultfrom'];
217 $formmail->fromtype = $defaultfrom;
219 $formmail->trackid = empty($trackid) ?
'' : $trackid;
220 $formmail->inreplyto = empty($inreplyto) ?
'' : $inreplyto;
221 $formmail->withfrom = 1;
222 $formmail->withlayout =
'email';
223 $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);
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 (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
342 $subelement = $regs[2];
345 if ($element ==
'order') {
346 $element = $subelement =
'commande';
348 if ($element ==
'propal') {
349 $element =
'comm/propal';
350 $subelement =
'propal';
352 if ($element ==
'contract') {
353 $element = $subelement =
'contrat';
355 if ($element ==
'inter') {
356 $element = $subelement =
'fichinter';
358 if ($element ==
'shipping') {
359 $element = $subelement =
'expedition';
361 if ($element ==
'order_supplier') {
363 $subelement =
'fournisseur.commande';
365 if ($element ==
'project') {
370 $classname = ucfirst($origin);
371 $objectsrc =
new $classname($db);
372 '@phan-var-force Commande|Facture $objectsrc';
373 $objectsrc->fetch($origin_id);
375 $tmpobject = $objectsrc;
379 $contactarr = array();
380 $contactarr = $tmpobject->liste_contact(-1,
'external', 0,
'', 1);
382 if (is_array($contactarr) && count($contactarr) > 0) {
383 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
384 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
385 $contactstatic =
new Contact($db);
386 $tmpcompany =
new Societe($db);
388 foreach ($contactarr as $contact) {
389 $contactstatic->fetch($contact[
'id']);
391 $substitutionarray[
'__CONTACT_NAME_'.$contact[
'code'].
'__'] = $contactstatic->getFullName($outputlangs, 1);
392 $substitutionarray[
'__CONTACT_LASTNAME_'.$contact[
'code'].
'__'] = $contactstatic->lastname;
393 $substitutionarray[
'__CONTACT_FIRSTNAME_'.$contact[
'code'].
'__'] = $contactstatic->firstname;
394 $substitutionarray[
'__CONTACT_TITLE_'.$contact[
'code'].
'__'] = $contactstatic->getCivilityLabel();
397 if (empty($liste[$contact[
'id']])) {
399 if (isset(
$object->thirdparty) && is_object(
$object->thirdparty)) {
400 if ($contactstatic->fk_soc !=
$object->thirdparty->id) {
401 $tmpcompany->fetch($contactstatic->fk_soc);
402 if ($tmpcompany->id > 0) {
403 $contacttoshow .= $tmpcompany->name.
': ';
407 $contacttoshow .= $contactstatic->getFullName($outputlangs, 1);
408 $contacttoshow .=
" <".($contactstatic->email ? $contactstatic->email : $langs->transnoentitiesnoconv(
"NoEMail")) .
">";
409 $liste[$contact[
'id']] = $contacttoshow;
414 $formmail->withto = $liste;
415 $formmail->withtofree = (
GETPOST(
'sendto',
'alphawithlgt') ?
GETPOST(
'sendto',
'alphawithlgt') :
'1');
416 $formmail->withtocc = $liste;
418 $formmail->withtopic = $topicmail;
419 $formmail->withfile = 2;
420 $formmail->withbody = 1;
421 $formmail->withdeliveryreceipt = 1;
422 $formmail->withcancel = 1;
425 $formmail->substit = $substitutionarray;
428 $formmail->param[
'action'] =
'send';
429 $formmail->param[
'models'] = $modelmail;
430 $formmail->param[
'models_id'] =
GETPOSTINT(
'modelmailselected');
431 $formmail->param[
'id'] =
$object->id;
432 $formmail->param[
'returnurl'] = $_SERVER[
"PHP_SELF"].
'?id='.
$object->id;
433 $formmail->param[
'fileinit'] = array($file);
434 $formmail->param[
'object_entity'] =
$object->entity;
437 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_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.
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...