33if (empty($conf) || !is_object($conf)) {
34 print
"Error, template page can't be called as URL";
39if ($action ==
'presend') {
40 $langs->load(
"mails");
42 $titreform =
'SendMail';
44 $object->fetch_projet();
45 if (!isset($file)) $file =
null;
47 if (!in_array($object->element, array(
'user',
'member'))) {
50 if (!empty($object->last_main_doc) && is_readable(DOL_DATA_ROOT.
'/'.$object->last_main_doc) && is_file(DOL_DATA_ROOT.
'/'.$object->last_main_doc)) {
51 $fileparams[
'fullname'] = DOL_DATA_ROOT.
'/'.$object->last_main_doc;
53 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
55 if ($object->element ==
'invoice_supplier') {
56 $fileparams =
dol_most_recent_file($diroutput.
'/'.
get_exdir($object->id, 2, 0, 0, $object, $object->element).$ref, preg_quote($ref,
'/').
'([^\-])+');
62 $file = isset($fileparams[
'fullname'])?$fileparams[
'fullname']:
null;
66 $outputlangs = $langs;
69 $newlang = $object->thirdparty->default_lang;
70 if (
GETPOST(
'lang_id',
'aZ09')) {
71 $newlang =
GETPOST(
'lang_id',
'aZ09');
75 if (!empty($newlang)) {
77 $outputlangs->setDefaultLang($newlang);
79 $outputlangs->loadLangs(array(
'commercial',
'bills',
'orders',
'contracts',
'members',
'propal',
'products',
'supplier_proposal',
'interventions',
'receptions',
'sendings'));
80 if (!empty($defaulttopiclang)) {
81 $outputlangs->loadLangs(array($defaulttopiclang));
86 if (empty($object->ref_client)) {
87 $topicmail = $outputlangs->trans($defaulttopic,
'__REF__');
88 } elseif (!empty($object->ref_client)) {
89 $topicmail = $outputlangs->trans($defaulttopic,
'__REF__ (__REF_CLIENT__)');
93 $forcebuilddoc =
true;
94 if (in_array($object->element, array(
'user',
'member'))) {
95 $forcebuilddoc =
false;
97 if ($object->element ==
'invoice_supplier' && empty($conf->global->INVOICE_SUPPLIER_ADDON_PDF)) {
98 $forcebuilddoc =
false;
100 if ($object->element ==
'societe' && empty($conf->global->COMPANY_ADDON_PDF)) {
101 $forcebuilddoc =
false;
103 if ($forcebuilddoc) {
104 if ((!$file || !is_readable($file)) && method_exists($object,
'generateDocument')) {
105 $result = $object->generateDocument(
GETPOST(
'model') ?
GETPOST(
'model') : $object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
110 if ($object->element ==
'invoice_supplier') {
111 $fileparams =
dol_most_recent_file($diroutput.
'/'.
get_exdir($object->id, 2, 0, 0, $object, $object->element).$ref, preg_quote($ref,
'/').
'([^\-])+');
116 $file = isset($fileparams[
'fullname'])?$fileparams[
'fullname']:
null;
120 print
'<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
121 print
'<div class="clearboth"></div>';
128 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
131 $formmail->param[
'langsmodels'] = (empty($newlang) ? $langs->defaultlang : $newlang);
132 $formmail->fromtype = (
GETPOST(
'fromtype') ?
GETPOST(
'fromtype') : (!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE) ? $conf->global->MAIN_MAIL_DEFAULT_FROMTYPE :
'user'));
134 if ($formmail->fromtype ===
'user') {
135 $formmail->fromid = $user->id;
137 if ($object->element ==
'salary' && !empty($conf->global->INVOICE_EMAIL_SENDER)) {
138 $formmail->frommail = $conf->global->SINVOICE_EMAIL_SENDER;
139 $formmail->fromname = (!empty($conf->global->INVOICE_EMAIL_SENDER_NAME) ? $conf->global->INVOICE_EMAIL_SENDER_NAME :
'');
140 $formmail->fromtype =
'special';
142 if ($object->element ===
'facture' && !empty($conf->global->INVOICE_EMAIL_SENDER)) {
143 $formmail->frommail = $conf->global->INVOICE_EMAIL_SENDER;
144 $formmail->fromname = (!empty($conf->global->INVOICE_EMAIL_SENDER_NAME) ? $conf->global->INVOICE_EMAIL_SENDER_NAME :
'');
145 $formmail->fromtype =
'special';
147 if ($object->element ===
'shipping' && !empty($conf->global->SHIPPING_EMAIL_SENDER)) {
148 $formmail->frommail = $conf->global->SHIPPING_EMAIL_SENDER;
149 $formmail->fromname = (!empty($conf->global->SHIPPING_EMAIL_SENDER_NAME) ? $conf->global->SHIPPING_EMAIL_SENDER_NAME :
'');
150 $formmail->fromtype =
'special';
152 if ($object->element ===
'commande' && !empty($conf->global->COMMANDE_EMAIL_SENDER)) {
153 $formmail->frommail = $conf->global->COMMANDE_EMAIL_SENDER;
154 $formmail->fromname = (!empty($conf->global->COMMANDE_EMAIL_SENDER_NAME) ? $conf->global->COMMANDE_EMAIL_SENDER_NAME :
'');
155 $formmail->fromtype =
'special';
157 if ($object->element ===
'order_supplier' && !empty($conf->global->ORDER_SUPPLIER_EMAIL_SENDER)) {
158 $formmail->frommail = $conf->global->ORDER_SUPPLIER_EMAIL_SENDER;
159 $formmail->fromname = (!empty($conf->global->ORDER_SUPPLIER_EMAIL_SENDER_NAME) ? $conf->global->ORDER_SUPPLIER_EMAIL_SENDER_NAME :
'');
160 $formmail->fromtype =
'special';
162 if ($object->element ===
'recruitmentcandidature' ) {
163 $formmail->frommail = (!empty($conf->global->RECRUITMENT_EMAIL_SENDER) ? $conf->global->RECRUITMENT_EMAIL_SENDER : $recruitermail);
164 $formmail->fromname = (!empty($conf->global->RECRUITMENT_EMAIL_SENDER_NAME) ? $conf->global->RECRUITMENT_EMAIL_SENDER_NAME : (!empty($recruitername) ? $recruitername :
''));
165 $formmail->fromtype =
'special';
170 if (GETPOSTISSET(
'fromtype')) {
171 $defaultfrom =
GETPOST(
'fromtype');
173 $parameters = array();
174 $reshook = $hookmanager->executeHooks(
'getDefaultFromEmail', $parameters, $formmail);
175 if (empty($reshook)) {
176 $defaultfrom = $formmail->fromtype;
178 if (!empty($hookmanager->resArray[
'defaultfrom'])) {
179 $defaultfrom = $hookmanager->resArray[
'defaultfrom'];
182 $formmail->fromtype = $defaultfrom;
184 $formmail->trackid = empty($trackid) ?
'' : $trackid;
185 $formmail->inreplyto = empty($inreplyto) ?
'' : $inreplyto;
186 $formmail->withfrom = 1;
190 if ($object->element ==
'expensereport') {
191 $fuser =
new User($db);
192 $fuser->fetch($object->fk_user_author);
193 $liste[
'thirdparty'] = $fuser->getFullName($outputlangs).
" <".$fuser->email.
">";
194 } elseif ($object->element ==
'partnership' &&
getDolGlobalString(
'PARTNERSHIP_IS_MANAGED_FOR') ==
'member') {
196 $fadherent->fetch($object->fk_member);
197 $liste[
'member'] = $fadherent->getFullName($outputlangs).
" <".$fadherent->email.
">";
198 } elseif ($object->element ==
'societe') {
199 foreach ($object->thirdparty_and_contact_email_array(1) as $key => $value) {
200 $liste[$key] = $value;
202 } elseif ($object->element ==
'contact') {
203 $liste[
'contact'] = $object->getFullName($outputlangs).
" <".$object->email.
">";
204 } elseif ($object->element ==
'user' || $object->element ==
'member') {
205 $liste[
'thirdparty'] = $object->getFullName($outputlangs).
" <".$object->email.
">";
206 } elseif ($object->element ==
'salary') {
207 $fuser =
new User($db);
208 $fuser->fetch($object->fk_user);
209 $liste[
'thirdparty'] = $fuser->getFullName($outputlangs).
" <".$fuser->email.
">";
211 if (!empty($object->socid) && $object->socid > 0 && !is_object($object->thirdparty) && method_exists($object,
'fetch_thirdparty')) {
212 $object->fetch_thirdparty();
214 if (is_object($object->thirdparty)) {
215 foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key => $value) {
216 $liste[$key] = $value;
220 if (!empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) {
221 $listeuser = array();
222 $fuserdest =
new User($db);
224 $result = $fuserdest->fetchAll(
'ASC',
't.lastname', 0, 0, array(
'customsql'=>
"t.statut=1 AND t.employee=1 AND t.email IS NOT NULL AND t.email <> ''"),
'AND',
true);
225 if ($result > 0 && is_array($fuserdest->users) && count($fuserdest->users) > 0) {
226 foreach ($fuserdest->users as $uuserdest) {
227 $listeuser[$uuserdest->id] = $uuserdest->user_get_property($uuserdest->id,
'email');
229 } elseif ($result < 0) {
232 if (count($listeuser) > 0) {
233 $formmail->withtouser = $listeuser;
234 $formmail->withtoccuser = $listeuser;
239 if (!isset($arrayoffamiliestoexclude)) {
240 $arrayoffamiliestoexclude =
null;
244 if (!empty($object)) {
246 $formmail->setSubstitFromObject($object, $langs);
251 if ($formmail->fromtype) {
253 if (preg_match(
'/user/', $formmail->fromtype, $reg)) {
254 $emailsendersignature = $user->signature;
255 } elseif (preg_match(
'/company/', $formmail->fromtype, $reg)) {
256 $emailsendersignature =
'';
257 } elseif (preg_match(
'/senderprofile_(\d+)/', $formmail->fromtype, $reg)) {
258 $sql =
"SELECT rowid, label, email, signature FROM ".$db->prefix().
"c_email_senderprofile";
259 $sql .=
" WHERE rowid = ".((int) $reg[1]);
260 $resql = $db->query($sql);
262 $obj = $db->fetch_object($resql);
264 $emailsendersignature = $obj->signature;
269 $substitutionarray[
'__SENDEREMAIL_SIGNATURE__'] = $emailsendersignature;
271 $substitutionarray[
'__CHECK_READ__'] =
"";
272 if (is_object($object) && is_object($object->thirdparty)) {
273 $checkRead=
'<img src="'.DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-read.php';
274 $checkRead.=
'?tag='.(!empty($object->thirdparty->tag)?urlencode($object->thirdparty->tag):
"");
275 $checkRead.=
'&securitykey='.(getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY') ? urlencode(
getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY')) :
"");
276 $checkRead.=
'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
277 $substitutionarray[
'__CHECK_READ__'] = $checkRead;
279 $substitutionarray[
'__PERSONALIZED__'] =
'';
280 $substitutionarray[
'__CONTACTCIVNAME__'] =
'';
282 'mode' =>
'formemail'
287 $tmpobject = $object;
288 if (($object->element ==
'shipping' || $object->element ==
'reception')) {
289 $origin = $object->origin;
290 $origin_id = $object->origin_id;
292 if (!empty($origin) && !empty($origin_id)) {
293 $element = $subelement = $origin;
295 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
297 $subelement = $regs[2];
300 if ($element ==
'order') {
301 $element = $subelement =
'commande';
303 if ($element ==
'propal') {
304 $element =
'comm/propal';
305 $subelement =
'propal';
307 if ($element ==
'contract') {
308 $element = $subelement =
'contrat';
310 if ($element ==
'inter') {
311 $element = $subelement =
'ficheinter';
313 if ($element ==
'shipping') {
314 $element = $subelement =
'expedition';
316 if ($element ==
'order_supplier') {
318 $subelement =
'fournisseur.commande';
320 if ($element ==
'project') {
325 $classname = ucfirst($origin);
326 $objectsrc =
new $classname($db);
327 $objectsrc->fetch($origin_id);
329 $tmpobject = $objectsrc;
333 $contactarr = array();
334 $contactarr = $tmpobject->liste_contact(-1,
'external', 0,
'', 1);
336 if (is_array($contactarr) && count($contactarr) > 0) {
337 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
338 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
339 $contactstatic =
new Contact($db);
340 $tmpcompany =
new Societe($db);
342 foreach ($contactarr as $contact) {
343 $contactstatic->fetch($contact[
'id']);
345 $substitutionarray[
'__CONTACT_NAME_'.$contact[
'code'].
'__'] = $contactstatic->getFullName($outputlangs, 1);
346 $substitutionarray[
'__CONTACT_LASTNAME_'.$contact[
'code'].
'__'] = $contactstatic->lastname;
347 $substitutionarray[
'__CONTACT_FIRSTNAME_'.$contact[
'code'].
'__'] = $contactstatic->firstname;
348 $substitutionarray[
'__CONTACT_TITLE_'.$contact[
'code'].
'__'] = $contactstatic->getCivilityLabel();
351 if (empty($liste[$contact[
'id']])) {
353 if (isset($object->thirdparty) && is_object($object->thirdparty)) {
354 if ($contactstatic->fk_soc != $object->thirdparty->id) {
355 $tmpcompany->fetch($contactstatic->fk_soc);
356 if ($tmpcompany->id > 0) {
357 $contacttoshow .= $tmpcompany->name.
': ';
361 $contacttoshow .= $contactstatic->getFullName($outputlangs, 1);
362 $contacttoshow .=
" <".($contactstatic->email ? $contactstatic->email : $langs->transnoentitiesnoconv(
"NoEMail")) .
">";
363 $liste[$contact[
'id']] = $contacttoshow;
368 $formmail->withto = $liste;
369 $formmail->withtofree = (
GETPOST(
'sendto',
'alphawithlgt') ?
GETPOST(
'sendto',
'alphawithlgt') :
'1');
370 $formmail->withtocc = $liste;
372 $formmail->withtopic = $topicmail;
373 $formmail->withfile = 2;
374 $formmail->withbody = 1;
375 $formmail->withdeliveryreceipt = 1;
376 $formmail->withcancel = 1;
379 $formmail->substit = $substitutionarray;
382 $formmail->param[
'action'] =
'send';
383 $formmail->param[
'models'] = $modelmail;
384 $formmail->param[
'models_id'] =
GETPOST(
'modelmailselected',
'int');
385 $formmail->param[
'id'] = $object->id;
386 $formmail->param[
'returnurl'] = $_SERVER[
"PHP_SELF"].
'?id='.$object->id;
387 $formmail->param[
'fileinit'] = array($file);
390 print $formmail->get_form();
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=false, $mode='')
Return file(s) into a directory (by default most recent)
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
getDolGlobalInt($key, $default=0)
Return 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.
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.