34if (empty($conf) || !is_object($conf)) {
35 print
"Error, template page can't be called as URL";
41if ($action ==
'presend') {
42 $langs->load(
"mails");
44 $titreform =
'SendMail';
51 if (!in_array(
$object->element, array(
'user',
'member'))) {
54 if (!empty(
$object->last_main_doc) && is_readable(DOL_DATA_ROOT.
'/'.
$object->last_main_doc) && is_file(DOL_DATA_ROOT.
'/'.
$object->last_main_doc)) {
55 $fileparams[
'fullname'] = DOL_DATA_ROOT.
'/'.
$object->last_main_doc;
57 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
59 if (
$object->element ==
'invoice_supplier') {
66 $file = isset($fileparams[
'fullname']) ? $fileparams[
'fullname'] :
null;
70 $outputlangs = $langs;
73 if (is_object(
$object->thirdparty)) {
74 $newlang =
$object->thirdparty->default_lang;
76 if (
GETPOST(
'lang_id',
'aZ09')) {
77 $newlang =
GETPOST(
'lang_id',
'aZ09');
81 if (!empty($newlang)) {
83 $outputlangs->setDefaultLang($newlang);
85 $outputlangs->loadLangs(array(
'commercial',
'bills',
'orders',
'contracts',
'main',
'members',
'propal',
'products',
'supplier_proposal',
'interventions',
'receptions',
'sendings'));
86 if (!empty($defaulttopiclang)) {
87 $outputlangs->loadLangs(array($defaulttopiclang));
92 if (empty(
$object->ref_client)) {
93 $topicmail = $outputlangs->trans($defaulttopic,
'__REF__');
94 } elseif (!empty(
$object->ref_client)) {
95 $topicmail = $outputlangs->trans($defaulttopic,
'__REF__ (__REF_CLIENT__)');
99 $forcebuilddoc =
true;
100 if (in_array(
$object->element, array(
'user',
'member'))) {
101 $forcebuilddoc =
false;
104 $forcebuilddoc =
false;
107 $forcebuilddoc =
false;
109 if ($forcebuilddoc) {
110 if ((!$file || !is_readable($file)) && method_exists(
$object,
'generateDocument')) {
111 $result =
$object->generateDocument(
GETPOST(
'model') ?
GETPOST(
'model') :
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
116 if (
$object->element ==
'invoice_supplier') {
122 $file = isset($fileparams[
'fullname']) ? $fileparams[
'fullname'] :
null;
126 print
'<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
127 print
'<div class="clearboth"></div>';
134 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
137 $formmail->param[
'langsmodels'] = (empty($newlang) ? $langs->defaultlang : $newlang);
140 if ($formmail->fromtype ===
'user') {
141 $formmail->fromid = $user->id;
146 $formmail->fromtype =
'special';
151 $formmail->fromtype =
'special';
156 $formmail->fromtype =
'special';
161 $formmail->fromtype =
'special';
166 $formmail->fromtype =
'special';
168 if (
$object->element ===
'recruitmentcandidature') {
169 $formmail->frommail =
getDolGlobalString(
'RECRUITMENT_EMAIL_SENDER', (!empty($recruitermail) ? $recruitermail :
''));
170 $formmail->fromname =
getDolGlobalString(
'RECRUITMENT_EMAIL_SENDER_NAME', (!empty($recruitername) ? $recruitername :
''));
171 $formmail->fromtype =
'special';
176 if (GETPOSTISSET(
'fromtype')) {
177 $defaultfrom =
GETPOST(
'fromtype');
179 $parameters = array();
180 $reshook = $hookmanager->executeHooks(
'getDefaultFromEmail', $parameters, $formmail);
181 if (empty($reshook)) {
182 $defaultfrom = $formmail->fromtype;
184 if (!empty($hookmanager->resArray[
'defaultfrom'])) {
185 $defaultfrom = $hookmanager->resArray[
'defaultfrom'];
188 $formmail->fromtype = $defaultfrom;
190 $formmail->trackid = empty($trackid) ?
'' : $trackid;
191 $formmail->inreplyto = empty($inreplyto) ?
'' : $inreplyto;
192 $formmail->withfrom = 1;
193 $formmail->withlayout = 1;
194 $formmail->withaiprompt =
'html';
198 if (
$object->element ==
'expensereport') {
199 $fuser =
new User($db);
200 $fuser->fetch(
$object->fk_user_author);
201 $liste[
'thirdparty'] = $fuser->getFullName($outputlangs).
" <".$fuser->email.
">";
204 $fadherent->fetch(
$object->fk_member);
205 $liste[
'member'] = $fadherent->getFullName($outputlangs).
" <".$fadherent->email.
">";
206 } elseif (
$object->element ==
'societe') {
207 foreach (
$object->thirdparty_and_contact_email_array(1) as $key => $value) {
208 $liste[$key] = $value;
210 } elseif (
$object->element ==
'contact') {
211 $liste[
'contact'] =
$object->getFullName($outputlangs).
" <".
$object->email.
">";
212 } elseif (
$object->element ==
'user' ||
$object->element ==
'member') {
213 $liste[
'thirdparty'] =
$object->getFullName($outputlangs).
" <".
$object->email.
">";
214 } elseif (
$object->element ==
'salary') {
215 $fuser =
new User($db);
216 $fuser->fetch(
$object->fk_user);
217 $liste[
'thirdparty'] = $fuser->getFullName($outputlangs).
" <".$fuser->email.
">";
223 if (is_object(
$object->thirdparty)) {
224 foreach (
$object->thirdparty->thirdparty_and_contact_email_array(1) as $key => $value) {
225 $liste[$key] = $value;
231 $listeuser = array();
232 $fuserdest =
new User($db);
233 $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);
234 if ($result > 0 && is_array($fuserdest->users) && count($fuserdest->users) > 0) {
235 foreach ($fuserdest->users as $uuserdest) {
236 $listeuser[$uuserdest->id] = $uuserdest->user_get_property($uuserdest->id,
'email');
238 } elseif ($result < 0) {
241 if (count($listeuser) > 0) {
242 $formmail->withtouser = $listeuser;
243 $formmail->withtoccuser = $listeuser;
248 if (!isset($arrayoffamiliestoexclude)) {
249 $arrayoffamiliestoexclude =
null;
255 $formmail->setSubstitFromObject(
$object, $langs);
260 if ($formmail->fromtype) {
262 if (preg_match(
'/user/', $formmail->fromtype, $reg)) {
263 $emailsendersignature = $user->signature;
264 } elseif (preg_match(
'/company/', $formmail->fromtype, $reg)) {
265 $emailsendersignature =
'';
266 } elseif (preg_match(
'/senderprofile_(\d+)/', $formmail->fromtype, $reg)) {
267 $sql =
"SELECT rowid, label, email, signature FROM ".$db->prefix().
"c_email_senderprofile";
268 $sql .=
" WHERE rowid = ".((int) $reg[1]);
269 $resql = $db->query($sql);
271 $obj = $db->fetch_object($resql);
273 $emailsendersignature = $obj->signature;
278 $substitutionarray[
'__SENDEREMAIL_SIGNATURE__'] = $emailsendersignature;
280 $substitutionarray[
'__CHECK_READ__'] =
"";
282 $checkRead =
'<img src="'.DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-read.php';
283 $checkRead .=
'?tag='.(!empty(
$object->thirdparty->tag) ? urlencode(
$object->thirdparty->tag) :
"");
284 $checkRead .=
'&securitykey='.(getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY') ? urlencode(
getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY')) :
"");
285 $checkRead .=
'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
286 $substitutionarray[
'__CHECK_READ__'] = $checkRead;
288 $substitutionarray[
'__CONTACTCIVNAME__'] =
'';
290 'mode' =>
'formemail'
296 if ((
$object->element ==
'shipping' ||
$object->element ==
'reception')) {
298 $origin_id =
$object->origin_id;
300 if (!empty($origin) && !empty($origin_id)) {
301 $element = $subelement = $origin;
303 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
305 $subelement = $regs[2];
308 if ($element ==
'order') {
309 $element = $subelement =
'commande';
311 if ($element ==
'propal') {
312 $element =
'comm/propal';
313 $subelement =
'propal';
315 if ($element ==
'contract') {
316 $element = $subelement =
'contrat';
318 if ($element ==
'inter') {
319 $element = $subelement =
'ficheinter';
321 if ($element ==
'shipping') {
322 $element = $subelement =
'expedition';
324 if ($element ==
'order_supplier') {
326 $subelement =
'fournisseur.commande';
328 if ($element ==
'project') {
333 $classname = ucfirst($origin);
334 $objectsrc =
new $classname($db);
335 $objectsrc->fetch($origin_id);
337 $tmpobject = $objectsrc;
341 $contactarr = array();
342 $contactarr = $tmpobject->liste_contact(-1,
'external', 0,
'', 1);
344 if (is_array($contactarr) && count($contactarr) > 0) {
345 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
346 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
347 $contactstatic =
new Contact($db);
348 $tmpcompany =
new Societe($db);
350 foreach ($contactarr as $contact) {
351 $contactstatic->fetch($contact[
'id']);
353 $substitutionarray[
'__CONTACT_NAME_'.$contact[
'code'].
'__'] = $contactstatic->getFullName($outputlangs, 1);
354 $substitutionarray[
'__CONTACT_LASTNAME_'.$contact[
'code'].
'__'] = $contactstatic->lastname;
355 $substitutionarray[
'__CONTACT_FIRSTNAME_'.$contact[
'code'].
'__'] = $contactstatic->firstname;
356 $substitutionarray[
'__CONTACT_TITLE_'.$contact[
'code'].
'__'] = $contactstatic->getCivilityLabel();
359 if (empty($liste[$contact[
'id']])) {
361 if (isset(
$object->thirdparty) && is_object(
$object->thirdparty)) {
362 if ($contactstatic->fk_soc !=
$object->thirdparty->id) {
363 $tmpcompany->fetch($contactstatic->fk_soc);
364 if ($tmpcompany->id > 0) {
365 $contacttoshow .= $tmpcompany->name.
': ';
369 $contacttoshow .= $contactstatic->getFullName($outputlangs, 1);
370 $contacttoshow .=
" <".($contactstatic->email ? $contactstatic->email : $langs->transnoentitiesnoconv(
"NoEMail")) .
">";
371 $liste[$contact[
'id']] = $contacttoshow;
376 $formmail->withto = $liste;
377 $formmail->withtofree = (
GETPOST(
'sendto',
'alphawithlgt') ?
GETPOST(
'sendto',
'alphawithlgt') :
'1');
378 $formmail->withtocc = $liste;
380 $formmail->withtopic = $topicmail;
381 $formmail->withfile = 2;
382 $formmail->withbody = 1;
383 $formmail->withdeliveryreceipt = 1;
384 $formmail->withcancel = 1;
387 $formmail->substit = $substitutionarray;
390 $formmail->param[
'action'] =
'send';
391 $formmail->param[
'models'] = $modelmail;
392 $formmail->param[
'models_id'] =
GETPOSTINT(
'modelmailselected');
393 $formmail->param[
'id'] =
$object->id;
394 $formmail->param[
'returnurl'] = $_SERVER[
"PHP_SELF"].
'?id='.
$object->id;
395 $formmail->param[
'fileinit'] = array($file);
396 $formmail->param[
'object_entity'] =
$object->entity;
399 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.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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 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.