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();
49 if (!in_array($object->element, array(
'user',
'member'))) {
52 if (!empty($object->last_main_doc) && is_readable(DOL_DATA_ROOT.
'/'.$object->last_main_doc) && is_file(DOL_DATA_ROOT.
'/'.$object->last_main_doc)) {
53 $fileparams[
'fullname'] = DOL_DATA_ROOT.
'/'.$object->last_main_doc;
55 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
57 if ($object->element ==
'invoice_supplier') {
58 $fileparams =
dol_most_recent_file($diroutput.
'/'.
get_exdir($object->id, 2, 0, 0, $object, $object->element).$ref, preg_quote($ref,
'/').
'([^\-])+');
64 $file = isset($fileparams[
'fullname']) ? $fileparams[
'fullname'] :
null;
68 $outputlangs = $langs;
71 $newlang = $object->thirdparty->default_lang;
72 if (
GETPOST(
'lang_id',
'aZ09')) {
73 $newlang =
GETPOST(
'lang_id',
'aZ09');
77 if (!empty($newlang)) {
79 $outputlangs->setDefaultLang($newlang);
81 $outputlangs->loadLangs(array(
'commercial',
'bills',
'orders',
'contracts',
'members',
'propal',
'products',
'supplier_proposal',
'interventions',
'receptions',
'sendings'));
82 if (!empty($defaulttopiclang)) {
83 $outputlangs->loadLangs(array($defaulttopiclang));
88 if (empty($object->ref_client)) {
89 $topicmail = $outputlangs->trans($defaulttopic,
'__REF__');
90 } elseif (!empty($object->ref_client)) {
91 $topicmail = $outputlangs->trans($defaulttopic,
'__REF__ (__REF_CLIENT__)');
95 $forcebuilddoc =
true;
96 if (in_array($object->element, array(
'user',
'member'))) {
97 $forcebuilddoc =
false;
99 if ($object->element ==
'invoice_supplier' && !
getDolGlobalString(
'INVOICE_SUPPLIER_ADDON_PDF')) {
100 $forcebuilddoc =
false;
103 $forcebuilddoc =
false;
105 if ($forcebuilddoc) {
106 if ((!$file || !is_readable($file)) && method_exists($object,
'generateDocument')) {
107 $result = $object->generateDocument(
GETPOST(
'model') ?
GETPOST(
'model') : $object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
112 if ($object->element ==
'invoice_supplier') {
113 $fileparams =
dol_most_recent_file($diroutput.
'/'.
get_exdir($object->id, 2, 0, 0, $object, $object->element).$ref, preg_quote($ref,
'/').
'([^\-])+');
118 $file = isset($fileparams[
'fullname']) ? $fileparams[
'fullname'] :
null;
122 print
'<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
123 print
'<div class="clearboth"></div>';
130 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
133 $formmail->param[
'langsmodels'] = (empty($newlang) ? $langs->defaultlang : $newlang);
134 $formmail->fromtype = (
GETPOST(
'fromtype') ?
GETPOST(
'fromtype') : (
getDolGlobalString(
'MAIN_MAIL_DEFAULT_FROMTYPE') ? $conf->global->MAIN_MAIL_DEFAULT_FROMTYPE :
'user'));
136 if ($formmail->fromtype ===
'user') {
137 $formmail->fromid = $user->id;
140 $formmail->frommail = $conf->global->SINVOICE_EMAIL_SENDER;
142 $formmail->fromtype =
'special';
145 $formmail->frommail = $conf->global->INVOICE_EMAIL_SENDER;
147 $formmail->fromtype =
'special';
150 $formmail->frommail = $conf->global->SHIPPING_EMAIL_SENDER;
152 $formmail->fromtype =
'special';
155 $formmail->frommail = $conf->global->COMMANDE_EMAIL_SENDER;
157 $formmail->fromtype =
'special';
159 if ($object->element ===
'order_supplier' &&
getDolGlobalString(
'ORDER_SUPPLIER_EMAIL_SENDER')) {
160 $formmail->frommail = $conf->global->ORDER_SUPPLIER_EMAIL_SENDER;
162 $formmail->fromtype =
'special';
164 if ($object->element ===
'recruitmentcandidature') {
165 $formmail->frommail =
getDolGlobalString(
'RECRUITMENT_EMAIL_SENDER', (!empty($recruitermail) ? $recruitermail :
''));
166 $formmail->fromname =
getDolGlobalString(
'RECRUITMENT_EMAIL_SENDER_NAME', (!empty($recruitername) ? $recruitername :
''));
167 $formmail->fromtype =
'special';
172 if (GETPOSTISSET(
'fromtype')) {
173 $defaultfrom =
GETPOST(
'fromtype');
175 $parameters = array();
176 $reshook = $hookmanager->executeHooks(
'getDefaultFromEmail', $parameters, $formmail);
177 if (empty($reshook)) {
178 $defaultfrom = $formmail->fromtype;
180 if (!empty($hookmanager->resArray[
'defaultfrom'])) {
181 $defaultfrom = $hookmanager->resArray[
'defaultfrom'];
184 $formmail->fromtype = $defaultfrom;
186 $formmail->trackid = empty($trackid) ?
'' : $trackid;
187 $formmail->inreplyto = empty($inreplyto) ?
'' : $inreplyto;
188 $formmail->withfrom = 1;
192 if ($object->element ==
'expensereport') {
193 $fuser =
new User($db);
194 $fuser->fetch($object->fk_user_author);
195 $liste[
'thirdparty'] = $fuser->getFullName($outputlangs).
" <".$fuser->email.
">";
196 } elseif ($object->element ==
'partnership' &&
getDolGlobalString(
'PARTNERSHIP_IS_MANAGED_FOR') ==
'member') {
198 $fadherent->fetch($object->fk_member);
199 $liste[
'member'] = $fadherent->getFullName($outputlangs).
" <".$fadherent->email.
">";
200 } elseif ($object->element ==
'societe') {
201 foreach ($object->thirdparty_and_contact_email_array(1) as $key => $value) {
202 $liste[$key] = $value;
204 } elseif ($object->element ==
'contact') {
205 $liste[
'contact'] = $object->getFullName($outputlangs).
" <".$object->email.
">";
206 } elseif ($object->element ==
'user' || $object->element ==
'member') {
207 $liste[
'thirdparty'] = $object->getFullName($outputlangs).
" <".$object->email.
">";
208 } elseif ($object->element ==
'salary') {
209 $fuser =
new User($db);
210 $fuser->fetch($object->fk_user);
211 $liste[
'thirdparty'] = $fuser->getFullName($outputlangs).
" <".$fuser->email.
">";
214 if (!empty($object->socid) && $object->socid > 0 && !is_object($object->thirdparty) && method_exists($object,
'fetch_thirdparty')) {
215 $object->fetch_thirdparty();
217 if (is_object($object->thirdparty)) {
218 foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key => $value) {
219 $liste[$key] = $value;
224 $listeuser = array();
225 $fuserdest =
new User($db);
227 $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);
228 if ($result > 0 && is_array($fuserdest->users) && count($fuserdest->users) > 0) {
229 foreach ($fuserdest->users as $uuserdest) {
230 $listeuser[$uuserdest->id] = $uuserdest->user_get_property($uuserdest->id,
'email');
232 } elseif ($result < 0) {
235 if (count($listeuser) > 0) {
236 $formmail->withtouser = $listeuser;
237 $formmail->withtoccuser = $listeuser;
242 if (!isset($arrayoffamiliestoexclude)) {
243 $arrayoffamiliestoexclude =
null;
247 if (!empty($object)) {
249 $formmail->setSubstitFromObject($object, $langs);
254 if ($formmail->fromtype) {
256 if (preg_match(
'/user/', $formmail->fromtype, $reg)) {
257 $emailsendersignature = $user->signature;
258 } elseif (preg_match(
'/company/', $formmail->fromtype, $reg)) {
259 $emailsendersignature =
'';
260 } elseif (preg_match(
'/senderprofile_(\d+)/', $formmail->fromtype, $reg)) {
261 $sql =
"SELECT rowid, label, email, signature FROM ".$db->prefix().
"c_email_senderprofile";
262 $sql .=
" WHERE rowid = ".((int) $reg[1]);
263 $resql = $db->query($sql);
265 $obj = $db->fetch_object($resql);
267 $emailsendersignature = $obj->signature;
272 $substitutionarray[
'__SENDEREMAIL_SIGNATURE__'] = $emailsendersignature;
274 $substitutionarray[
'__CHECK_READ__'] =
"";
275 if (is_object($object) && is_object($object->thirdparty)) {
276 $checkRead=
'<img src="'.DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-read.php';
277 $checkRead.=
'?tag='.(!empty($object->thirdparty->tag) ? urlencode($object->thirdparty->tag) :
"");
278 $checkRead.=
'&securitykey='.(getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY') ? urlencode(
getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY')) :
"");
279 $checkRead.=
'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
280 $substitutionarray[
'__CHECK_READ__'] = $checkRead;
282 $substitutionarray[
'__CONTACTCIVNAME__'] =
'';
284 'mode' =>
'formemail'
289 $tmpobject = $object;
290 if (($object->element ==
'shipping' || $object->element ==
'reception')) {
291 $origin = $object->origin;
292 $origin_id = $object->origin_id;
294 if (!empty($origin) && !empty($origin_id)) {
295 $element = $subelement = $origin;
297 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
299 $subelement = $regs[2];
302 if ($element ==
'order') {
303 $element = $subelement =
'commande';
305 if ($element ==
'propal') {
306 $element =
'comm/propal';
307 $subelement =
'propal';
309 if ($element ==
'contract') {
310 $element = $subelement =
'contrat';
312 if ($element ==
'inter') {
313 $element = $subelement =
'ficheinter';
315 if ($element ==
'shipping') {
316 $element = $subelement =
'expedition';
318 if ($element ==
'order_supplier') {
320 $subelement =
'fournisseur.commande';
322 if ($element ==
'project') {
327 $classname = ucfirst($origin);
328 $objectsrc =
new $classname($db);
329 $objectsrc->fetch($origin_id);
331 $tmpobject = $objectsrc;
335 $contactarr = array();
336 $contactarr = $tmpobject->liste_contact(-1,
'external', 0,
'', 1);
338 if (is_array($contactarr) && count($contactarr) > 0) {
339 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
340 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
341 $contactstatic =
new Contact($db);
342 $tmpcompany =
new Societe($db);
344 foreach ($contactarr as $contact) {
345 $contactstatic->fetch($contact[
'id']);
347 $substitutionarray[
'__CONTACT_NAME_'.$contact[
'code'].
'__'] = $contactstatic->getFullName($outputlangs, 1);
348 $substitutionarray[
'__CONTACT_LASTNAME_'.$contact[
'code'].
'__'] = $contactstatic->lastname;
349 $substitutionarray[
'__CONTACT_FIRSTNAME_'.$contact[
'code'].
'__'] = $contactstatic->firstname;
350 $substitutionarray[
'__CONTACT_TITLE_'.$contact[
'code'].
'__'] = $contactstatic->getCivilityLabel();
353 if (empty($liste[$contact[
'id']])) {
355 if (isset($object->thirdparty) && is_object($object->thirdparty)) {
356 if ($contactstatic->fk_soc != $object->thirdparty->id) {
357 $tmpcompany->fetch($contactstatic->fk_soc);
358 if ($tmpcompany->id > 0) {
359 $contacttoshow .= $tmpcompany->name.
': ';
363 $contacttoshow .= $contactstatic->getFullName($outputlangs, 1);
364 $contacttoshow .=
" <".($contactstatic->email ? $contactstatic->email : $langs->transnoentitiesnoconv(
"NoEMail")) .
">";
365 $liste[$contact[
'id']] = $contacttoshow;
370 $formmail->withto = $liste;
371 $formmail->withtofree = (
GETPOST(
'sendto',
'alphawithlgt') ?
GETPOST(
'sendto',
'alphawithlgt') :
'1');
372 $formmail->withtocc = $liste;
374 $formmail->withtopic = $topicmail;
375 $formmail->withfile = 2;
376 $formmail->withbody = 1;
377 $formmail->withdeliveryreceipt = 1;
378 $formmail->withcancel = 1;
381 $formmail->substit = $substitutionarray;
384 $formmail->param[
'action'] =
'send';
385 $formmail->param[
'models'] = $modelmail;
386 $formmail->param[
'models_id'] =
GETPOST(
'modelmailselected',
'int');
387 $formmail->param[
'id'] = $object->id;
388 $formmail->param[
'returnurl'] = $_SERVER[
"PHP_SELF"].
'?id='.$object->id;
389 $formmail->param[
'fileinit'] = array($file);
390 $formmail->param[
'object_entity'] = $object->entity;
393 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 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.
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.