31 if (empty($conf) || !is_object($conf)) {
32 print
"Error, template page can't be called as URL";
37 if ($action ==
'presend') {
38 $langs->load(
"mails");
40 $titreform =
'SendMail';
42 $object->fetch_projet();
45 if (!in_array($object->element, array(
'user',
'member'))) {
48 if (!empty($object->last_main_doc) && is_readable(DOL_DATA_ROOT.
'/'.$object->last_main_doc) && is_file(DOL_DATA_ROOT.
'/'.$object->last_main_doc)) {
49 $fileparams[
'fullname'] = DOL_DATA_ROOT.
'/'.$object->last_main_doc;
51 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
53 if ($object->element ==
'invoice_supplier') {
54 $fileparams =
dol_most_recent_file($diroutput.
'/'.
get_exdir($object->id, 2, 0, 0, $object, $object->element).$ref, preg_quote($ref,
'/').
'([^\-])+');
60 $file = $fileparams[
'fullname'];
64 $outputlangs = $langs;
67 $newlang = $object->thirdparty->default_lang;
68 if (
GETPOST(
'lang_id',
'aZ09')) {
69 $newlang =
GETPOST(
'lang_id',
'aZ09');
73 if (!empty($newlang)) {
75 $outputlangs->setDefaultLang($newlang);
77 $outputlangs->loadLangs(array(
'commercial',
'bills',
'orders',
'contracts',
'members',
'propal',
'products',
'supplier_proposal',
'interventions',
'receptions',
'sendings'));
81 if (empty($object->ref_client)) {
82 $topicmail = $outputlangs->trans($defaulttopic,
'__REF__');
83 } elseif (!empty($object->ref_client)) {
84 $topicmail = $outputlangs->trans($defaulttopic,
'__REF__ (__REF_CLIENT__)');
88 $forcebuilddoc =
true;
89 if (in_array($object->element, array(
'user',
'member'))) {
90 $forcebuilddoc =
false;
92 if ($object->element ==
'invoice_supplier' && empty($conf->global->INVOICE_SUPPLIER_ADDON_PDF)) {
93 $forcebuilddoc =
false;
95 if ($object->element ==
'societe' && empty($conf->global->COMPANY_ADDON_PDF)) {
96 $forcebuilddoc =
false;
99 if ((!$file || !is_readable($file)) && method_exists($object,
'generateDocument')) {
100 $result = $object->generateDocument(
GETPOST(
'model') ?
GETPOST(
'model') : $object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
105 if ($object->element ==
'invoice_supplier') {
106 $fileparams =
dol_most_recent_file($diroutput.
'/'.
get_exdir($object->id, 2, 0, 0, $object, $object->element).$ref, preg_quote($ref,
'/').
'([^\-])+');
111 $file = $fileparams[
'fullname'];
115 print
'<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
116 print
'<div class="clearboth"></div>';
123 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
126 $formmail->param[
'langsmodels'] = (empty($newlang) ? $langs->defaultlang : $newlang);
127 $formmail->fromtype = (
GETPOST(
'fromtype') ?
GETPOST(
'fromtype') : (!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE) ? $conf->global->MAIN_MAIL_DEFAULT_FROMTYPE :
'user'));
129 if ($formmail->fromtype ===
'user') {
130 $formmail->fromid = $user->id;
133 if ($object->element ===
'facture' && !empty($conf->global->INVOICE_EMAIL_SENDER)) {
134 $formmail->frommail = $conf->global->INVOICE_EMAIL_SENDER;
135 $formmail->fromname = (!empty($conf->global->INVOICE_EMAIL_SENDER_NAME) ? $conf->global->INVOICE_EMAIL_SENDER_NAME :
'');
136 $formmail->fromtype =
'special';
138 if ($object->element ===
'shipping' && !empty($conf->global->SHIPPING_EMAIL_SENDER)) {
139 $formmail->frommail = $conf->global->SHIPPING_EMAIL_SENDER;
140 $formmail->fromname = (!empty($conf->global->SHIPPING_EMAIL_SENDER_NAME) ? $conf->global->SHIPPING_EMAIL_SENDER_NAME :
'');
141 $formmail->fromtype =
'special';
143 if ($object->element ===
'commande' && !empty($conf->global->COMMANDE_EMAIL_SENDER)) {
144 $formmail->frommail = $conf->global->COMMANDE_EMAIL_SENDER;
145 $formmail->fromname = (!empty($conf->global->COMMANDE_EMAIL_SENDER_NAME) ? $conf->global->COMMANDE_EMAIL_SENDER_NAME :
'');
146 $formmail->fromtype =
'special';
148 if ($object->element ===
'order_supplier' && !empty($conf->global->ORDER_SUPPLIER_EMAIL_SENDER)) {
149 $formmail->frommail = $conf->global->ORDER_SUPPLIER_EMAIL_SENDER;
150 $formmail->fromname = (!empty($conf->global->ORDER_SUPPLIER_EMAIL_SENDER_NAME) ? $conf->global->ORDER_SUPPLIER_EMAIL_SENDER_NAME :
'');
151 $formmail->fromtype =
'special';
153 if ($object->element ===
'recruitmentcandidature' ) {
154 $formmail->frommail = (!empty($conf->global->RECRUITMENT_EMAIL_SENDER) ? $conf->global->RECRUITMENT_EMAIL_SENDER : $recruitermail);
155 $formmail->fromname = (!empty($conf->global->RECRUITMENT_EMAIL_SENDER_NAME) ? $conf->global->RECRUITMENT_EMAIL_SENDER_NAME : (!empty($recruitername) ? $recruitername :
''));
156 $formmail->fromtype =
'special';
162 $defaultfrom =
GETPOST(
'fromtype');
164 $parameters = array();
165 $reshook = $hookmanager->executeHooks(
'getDefaultFromEmail', $parameters, $formmail);
166 if (empty($reshook)) {
167 $defaultfrom = $formmail->fromtype;
169 if (!empty($hookmanager->resArray[
'defaultfrom'])) {
170 $defaultfrom = $hookmanager->resArray[
'defaultfrom'];
173 $formmail->fromtype = $defaultfrom;
175 $formmail->trackid = empty($trackid) ?
'' : $trackid;
176 $formmail->inreplyto = empty($inreplyto) ?
'' : $inreplyto;
177 $formmail->withfrom = 1;
181 if ($object->element ==
'expensereport') {
182 $fuser =
new User($db);
183 $fuser->fetch($object->fk_user_author);
184 $liste[
'thirdparty'] = $fuser->getFullName($outputlangs).
" <".$fuser->email.
">";
185 } elseif ($object->element ==
'partnership' &&
getDolGlobalString(
'PARTNERSHIP_IS_MANAGED_FOR') ==
'member') {
187 $fadherent->fetch($object->fk_member);
188 $liste[
'member'] = $fadherent->getFullName($outputlangs).
" <".$fadherent->email.
">";
189 } elseif ($object->element ==
'societe') {
190 foreach ($object->thirdparty_and_contact_email_array(1) as $key => $value) {
191 $liste[$key] = $value;
193 } elseif ($object->element ==
'contact') {
194 $liste[
'contact'] = $object->getFullName($outputlangs).
" <".$object->email.
">";
195 } elseif ($object->element ==
'user' || $object->element ==
'member') {
196 $liste[
'thirdparty'] = $object->getFullName($outputlangs).
" <".$object->email.
">";
198 if (!empty($object->socid) && $object->socid > 0 && !is_object($object->thirdparty) && method_exists($object,
'fetch_thirdparty')) {
199 $object->fetch_thirdparty();
201 if (is_object($object->thirdparty)) {
202 foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key => $value) {
203 $liste[$key] = $value;
207 if (!empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) {
208 $listeuser = array();
209 $fuserdest =
new User($db);
211 $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);
212 if ($result > 0 && is_array($fuserdest->users) && count($fuserdest->users) > 0) {
213 foreach ($fuserdest->users as $uuserdest) {
214 $listeuser[$uuserdest->id] = $uuserdest->user_get_property($uuserdest->id,
'email');
216 } elseif ($result < 0) {
219 if (count($listeuser) > 0) {
220 $formmail->withtouser = $listeuser;
221 $formmail->withtoccuser = $listeuser;
226 if (!isset($arrayoffamiliestoexclude)) {
227 $arrayoffamiliestoexclude =
null;
231 if (!empty($object)) {
233 $formmail->setSubstitFromObject($object, $langs);
238 if ($formmail->fromtype) {
240 if (preg_match(
'/user/', $formmail->fromtype, $reg)) {
241 $emailsendersignature = $user->signature;
242 } elseif (preg_match(
'/company/', $formmail->fromtype, $reg)) {
243 $emailsendersignature =
'';
244 } elseif (preg_match(
'/senderprofile_(\d+)/', $formmail->fromtype, $reg)) {
245 $sql =
"SELECT rowid, label, email, signature FROM ".$db->prefix().
"c_email_senderprofile";
246 $sql .=
" WHERE rowid = ".((int) $reg[1]);
247 $resql = $db->query($sql);
249 $obj = $db->fetch_object(
$resql);
251 $emailsendersignature = $obj->signature;
256 $substitutionarray[
'__SENDEREMAIL_SIGNATURE__'] = $emailsendersignature;
258 $substitutionarray[
'__CHECK_READ__'] =
"";
259 if (is_object($object) && is_object($object->thirdparty)) {
260 $checkRead=
'<img src="'.DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-read.php';
261 $checkRead.=
'?tag='.(!empty($object->thirdparty->tag)?urlencode($object->thirdparty->tag):
"");
262 $checkRead.=
'&securitykey='.(!empty($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY)?urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY):
"");
263 $checkRead.=
'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
264 $substitutionarray[
'__CHECK_READ__'] = $checkRead;
266 $substitutionarray[
'__PERSONALIZED__'] =
'';
267 $substitutionarray[
'__CONTACTCIVNAME__'] =
'';
269 'mode' =>
'formemail'
274 $tmpobject = $object;
275 if (($object->element ==
'shipping' || $object->element ==
'reception')) {
276 $origin = $object->origin;
277 $origin_id = $object->origin_id;
279 if (!empty($origin) && !empty($origin_id)) {
280 $element = $subelement = $origin;
282 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
284 $subelement = $regs[2];
287 if ($element ==
'order') {
288 $element = $subelement =
'commande';
290 if ($element ==
'propal') {
291 $element =
'comm/propal';
292 $subelement =
'propal';
294 if ($element ==
'contract') {
295 $element = $subelement =
'contrat';
297 if ($element ==
'inter') {
298 $element = $subelement =
'ficheinter';
300 if ($element ==
'shipping') {
301 $element = $subelement =
'expedition';
303 if ($element ==
'order_supplier') {
305 $subelement =
'fournisseur.commande';
307 if ($element ==
'project') {
312 $classname = ucfirst($origin);
313 $objectsrc =
new $classname($db);
314 $objectsrc->fetch($origin_id);
316 $tmpobject = $objectsrc;
320 $contactarr = array();
321 $contactarr = $tmpobject->liste_contact(-1,
'external');
323 if (is_array($contactarr) && count($contactarr) > 0) {
324 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
325 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
326 $contactstatic =
new Contact($db);
327 $tmpcompany =
new Societe($db);
329 foreach ($contactarr as $contact) {
330 $contactstatic->fetch($contact[
'id']);
332 $substitutionarray[
'__CONTACT_NAME_'.$contact[
'code'].
'__'] = $contactstatic->getFullName($outputlangs, 1);
333 $substitutionarray[
'__CONTACT_LASTNAME_'.$contact[
'code'].
'__'] = $contactstatic->lastname;
334 $substitutionarray[
'__CONTACT_FIRSTNAME_'.$contact[
'code'].
'__'] = $contactstatic->firstname;
335 $substitutionarray[
'__CONTACT_TITLE_'.$contact[
'code'].
'__'] = $contactstatic->getCivilityLabel();
338 if (empty($liste[$contact[
'id']])) {
340 if (isset($object->thirdparty) && is_object($object->thirdparty)) {
341 if ($contactstatic->fk_soc != $object->thirdparty->id) {
342 $tmpcompany->fetch($contactstatic->fk_soc);
343 if ($tmpcompany->id > 0) {
344 $contacttoshow .= $tmpcompany->name.
': ';
348 $contacttoshow .= $contactstatic->getFullName($outputlangs, 1);
349 $contacttoshow .=
" <".($contactstatic->email ? $contactstatic->email : $langs->transnoentitiesnoconv(
"NoEMail")) .
">";
350 $liste[$contact[
'id']] = $contacttoshow;
355 $formmail->withto = $liste;
356 $formmail->withtofree = (
GETPOST(
'sendto',
'alphawithlgt') ?
GETPOST(
'sendto',
'alphawithlgt') :
'1');
357 $formmail->withtocc = $liste;
359 $formmail->withtopic = $topicmail;
360 $formmail->withfile = 2;
361 $formmail->withbody = 1;
362 $formmail->withdeliveryreceipt = 1;
363 $formmail->withcancel = 1;
366 $formmail->substit = $substitutionarray;
369 $formmail->param[
'action'] =
'send';
370 $formmail->param[
'models'] = $modelmail;
371 $formmail->param[
'models_id'] =
GETPOST(
'modelmailselected',
'int');
372 $formmail->param[
'id'] = $object->id;
373 $formmail->param[
'returnurl'] = $_SERVER[
"PHP_SELF"].
'?id='.$object->id;
374 $formmail->param[
'fileinit'] = array($file);
377 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.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
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='')
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
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.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.