36if (empty($conf) || !is_object($conf)) {
37 print
"Error, template page can't be called as URL";
43if ($action ==
'presend') {
44 $langs->load(
"mails");
46 $titreform =
'SendMail';
53 if (!in_array(
$object->element, array(
'user',
'member'))) {
56 if (!empty(
$object->last_main_doc) && is_readable(DOL_DATA_ROOT.
'/'.
$object->last_main_doc) && is_file(DOL_DATA_ROOT.
'/'.
$object->last_main_doc)) {
57 $fileparams[
'fullname'] = DOL_DATA_ROOT.
'/'.
$object->last_main_doc;
59 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
61 if (
$object->element ==
'invoice_supplier') {
68 $file = isset($fileparams[
'fullname']) ? $fileparams[
'fullname'] :
null;
72 $outputlangs = $langs;
75 if (is_object(
$object->thirdparty)) {
76 $newlang =
$object->thirdparty->default_lang;
78 if (
GETPOST(
'lang_id',
'aZ09')) {
79 $newlang =
GETPOST(
'lang_id',
'aZ09');
83 if (!empty($newlang)) {
85 $outputlangs->setDefaultLang($newlang);
87 $outputlangs->loadLangs(array(
'commercial',
'bills',
'orders',
'contracts',
'main',
'members',
'propal',
'products',
'supplier_proposal',
'interventions',
'receptions',
'sendings'));
88 if (!empty($defaulttopiclang)) {
89 $outputlangs->loadLangs(array($defaulttopiclang));
94 if (empty(
$object->ref_client)) {
95 $topicmail = $outputlangs->trans($defaulttopic,
'__REF__');
96 } elseif (!empty(
$object->ref_client)) {
97 $topicmail = $outputlangs->trans($defaulttopic,
'__REF__ (__REF_CLIENT__)');
101 $forcebuilddoc =
true;
102 if (in_array(
$object->element, array(
'user',
'member'))) {
103 $forcebuilddoc =
false;
106 $forcebuilddoc =
false;
109 $forcebuilddoc =
false;
111 if ($forcebuilddoc) {
112 if ((!$file || !is_readable($file)) && method_exists(
$object,
'generateDocument')) {
113 $result =
$object->generateDocument(
GETPOST(
'model') ?
GETPOST(
'model') :
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
118 if (
$object->element ==
'invoice_supplier') {
124 $file = isset($fileparams[
'fullname']) ? $fileparams[
'fullname'] :
null;
128 print
'<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
129 print
'<div class="clearboth"></div>';
136 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
139 $formmail->param[
'langsmodels'] = (empty($newlang) ? $langs->defaultlang : $newlang);
142 if ($formmail->fromtype ===
'user') {
143 $formmail->fromid = $user->id;
148 $formmail->fromtype =
'special';
153 $formmail->fromtype =
'special';
158 $formmail->fromtype =
'special';
163 $formmail->fromtype =
'special';
168 $formmail->fromtype =
'special';
170 if (
$object->element ===
'recruitmentcandidature') {
171 $formmail->frommail =
getDolGlobalString(
'RECRUITMENT_EMAIL_SENDER', (!empty($recruitermail) ? $recruitermail :
''));
172 $formmail->fromname =
getDolGlobalString(
'RECRUITMENT_EMAIL_SENDER_NAME', (!empty($recruitername) ? $recruitername :
''));
173 $formmail->fromtype =
'special';
178 if (GETPOSTISSET(
'fromtype')) {
179 $defaultfrom =
GETPOST(
'fromtype');
181 $parameters = array();
182 $reshook = $hookmanager->executeHooks(
'getDefaultFromEmail', $parameters, $formmail);
183 if (empty($reshook)) {
184 $defaultfrom = $formmail->fromtype;
186 if (!empty($hookmanager->resArray[
'defaultfrom'])) {
187 $defaultfrom = $hookmanager->resArray[
'defaultfrom'];
190 $formmail->fromtype = $defaultfrom;
192 $formmail->trackid = empty($trackid) ?
'' : $trackid;
193 $formmail->inreplyto = empty($inreplyto) ?
'' : $inreplyto;
194 $formmail->withfrom = 1;
195 $formmail->withlayout = 1;
196 $formmail->withaiprompt =
'html';
200 if (
$object->element ==
'expensereport') {
201 $fuser =
new User($db);
202 $fuser->fetch(
$object->fk_user_author);
203 $liste[
'thirdparty'] = $fuser->getFullName($outputlangs).
" <".$fuser->email.
">";
206 $fadherent->fetch(
$object->fk_member);
207 $liste[
'member'] = $fadherent->getFullName($outputlangs).
" <".$fadherent->email.
">";
208 } elseif (
$object->element ==
'societe') {
209 foreach (
$object->thirdparty_and_contact_email_array(1) as $key => $value) {
210 $liste[$key] = $value;
212 } elseif (
$object->element ==
'contact') {
213 $liste[
'contact'] =
$object->getFullName($outputlangs).
" <".
$object->email.
">";
214 } elseif (
$object->element ==
'user' ||
$object->element ==
'member') {
215 $liste[
'thirdparty'] =
$object->getFullName($outputlangs).
" <".
$object->email.
">";
216 } elseif (
$object->element ==
'salary') {
217 $fuser =
new User($db);
218 $fuser->fetch(
$object->fk_user);
219 $liste[
'thirdparty'] = $fuser->getFullName($outputlangs).
" <".$fuser->email.
">";
225 if (is_object(
$object->thirdparty)) {
226 foreach (
$object->thirdparty->thirdparty_and_contact_email_array(1) as $key => $value) {
227 $liste[$key] = $value;
233 $listeuser = array();
234 $fuserdest =
new User($db);
235 $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);
236 if ($result > 0 && is_array($fuserdest->users) && count($fuserdest->users) > 0) {
237 foreach ($fuserdest->users as $uuserdest) {
238 $listeuser[$uuserdest->id] = $uuserdest->user_get_property($uuserdest->id,
'email');
240 } elseif ($result < 0) {
243 if (count($listeuser) > 0) {
244 $formmail->withtouser = $listeuser;
245 $formmail->withtoccuser = $listeuser;
250 if (!isset($arrayoffamiliestoexclude)) {
251 $arrayoffamiliestoexclude =
null;
257 $formmail->setSubstitFromObject(
$object, $langs);
262 if ($formmail->fromtype) {
264 if (preg_match(
'/user/', $formmail->fromtype, $reg)) {
265 $emailsendersignature = $user->signature;
266 } elseif (preg_match(
'/company/', $formmail->fromtype, $reg)) {
267 $emailsendersignature =
'';
268 } elseif (preg_match(
'/senderprofile_(\d+)/', $formmail->fromtype, $reg)) {
269 $sql =
"SELECT rowid, label, email, signature FROM ".$db->prefix().
"c_email_senderprofile";
270 $sql .=
" WHERE rowid = ".((int) $reg[1]);
271 $resql = $db->query($sql);
273 $obj = $db->fetch_object($resql);
275 $emailsendersignature = $obj->signature;
280 $substitutionarray[
'__SENDEREMAIL_SIGNATURE__'] = $emailsendersignature;
282 $substitutionarray[
'__CHECK_READ__'] =
"";
284 $checkRead =
'<img src="'.DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-read.php';
285 $checkRead .=
'?tag='.(!empty(
$object->thirdparty->tag) ? urlencode(
$object->thirdparty->tag) :
"");
286 $checkRead .=
'&securitykey='.(getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY') ? urlencode(
getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY')) :
"");
287 $checkRead .=
'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
288 $substitutionarray[
'__CHECK_READ__'] = $checkRead;
290 $substitutionarray[
'__CONTACTCIVNAME__'] =
'';
292 'mode' =>
'formemail'
298 if ((
$object->element ==
'shipping' ||
$object->element ==
'reception')) {
300 $origin_id =
$object->origin_id;
302 if (!empty($origin) && !empty($origin_id)) {
303 $element = $subelement = $origin;
305 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
307 $subelement = $regs[2];
310 if ($element ==
'order') {
311 $element = $subelement =
'commande';
313 if ($element ==
'propal') {
314 $element =
'comm/propal';
315 $subelement =
'propal';
317 if ($element ==
'contract') {
318 $element = $subelement =
'contrat';
320 if ($element ==
'inter') {
321 $element = $subelement =
'fichinter';
323 if ($element ==
'shipping') {
324 $element = $subelement =
'expedition';
326 if ($element ==
'order_supplier') {
328 $subelement =
'fournisseur.commande';
330 if ($element ==
'project') {
335 $classname = ucfirst($origin);
336 $objectsrc =
new $classname($db);
337 $objectsrc->fetch($origin_id);
339 $tmpobject = $objectsrc;
343 $contactarr = array();
344 $contactarr = $tmpobject->liste_contact(-1,
'external', 0,
'', 1);
346 if (is_array($contactarr) && count($contactarr) > 0) {
347 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
348 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
349 $contactstatic =
new Contact($db);
350 $tmpcompany =
new Societe($db);
352 foreach ($contactarr as $contact) {
353 $contactstatic->fetch($contact[
'id']);
355 $substitutionarray[
'__CONTACT_NAME_'.$contact[
'code'].
'__'] = $contactstatic->getFullName($outputlangs, 1);
356 $substitutionarray[
'__CONTACT_LASTNAME_'.$contact[
'code'].
'__'] = $contactstatic->lastname;
357 $substitutionarray[
'__CONTACT_FIRSTNAME_'.$contact[
'code'].
'__'] = $contactstatic->firstname;
358 $substitutionarray[
'__CONTACT_TITLE_'.$contact[
'code'].
'__'] = $contactstatic->getCivilityLabel();
361 if (empty($liste[$contact[
'id']])) {
363 if (isset(
$object->thirdparty) && is_object(
$object->thirdparty)) {
364 if ($contactstatic->fk_soc !=
$object->thirdparty->id) {
365 $tmpcompany->fetch($contactstatic->fk_soc);
366 if ($tmpcompany->id > 0) {
367 $contacttoshow .= $tmpcompany->name.
': ';
371 $contacttoshow .= $contactstatic->getFullName($outputlangs, 1);
372 $contacttoshow .=
" <".($contactstatic->email ? $contactstatic->email : $langs->transnoentitiesnoconv(
"NoEMail")) .
">";
373 $liste[$contact[
'id']] = $contacttoshow;
378 $formmail->withto = $liste;
379 $formmail->withtofree = (
GETPOST(
'sendto',
'alphawithlgt') ?
GETPOST(
'sendto',
'alphawithlgt') :
'1');
380 $formmail->withtocc = $liste;
382 $formmail->withtopic = $topicmail;
383 $formmail->withfile = 2;
384 $formmail->withbody = 1;
385 $formmail->withdeliveryreceipt = 1;
386 $formmail->withcancel = 1;
389 $formmail->substit = $substitutionarray;
392 $formmail->param[
'action'] =
'send';
393 $formmail->param[
'models'] = $modelmail;
394 $formmail->param[
'models_id'] =
GETPOSTINT(
'modelmailselected');
395 $formmail->param[
'id'] =
$object->id;
396 $formmail->param[
'returnurl'] = $_SERVER[
"PHP_SELF"].
'?id='.
$object->id;
397 $formmail->param[
'fileinit'] = array($file);
398 $formmail->param[
'object_entity'] =
$object->entity;
401 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.