33 if (empty($conf) || !is_object($conf)) {
34 print
"Error, template page can't be called as URL";
39 if ($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'));
83 if (empty($object->ref_client)) {
84 $topicmail = $outputlangs->trans($defaulttopic,
'__REF__');
85 } elseif (!empty($object->ref_client)) {
86 $topicmail = $outputlangs->trans($defaulttopic,
'__REF__ (__REF_CLIENT__)');
90 $forcebuilddoc =
true;
91 if (in_array($object->element, array(
'user',
'member'))) {
92 $forcebuilddoc =
false;
94 if ($object->element ==
'invoice_supplier' && empty($conf->global->INVOICE_SUPPLIER_ADDON_PDF)) {
95 $forcebuilddoc =
false;
97 if ($object->element ==
'societe' && empty($conf->global->COMPANY_ADDON_PDF)) {
98 $forcebuilddoc =
false;
100 if ($forcebuilddoc) {
101 if ((!$file || !is_readable($file)) && method_exists($object,
'generateDocument')) {
102 $result = $object->generateDocument(
GETPOST(
'model') ?
GETPOST(
'model') : $object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
107 if ($object->element ==
'invoice_supplier') {
108 $fileparams =
dol_most_recent_file($diroutput.
'/'.
get_exdir($object->id, 2, 0, 0, $object, $object->element).$ref, preg_quote($ref,
'/').
'([^\-])+');
113 $file = isset($fileparams[
'fullname'])?$fileparams[
'fullname']:
null;
117 print
'<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
118 print
'<div class="clearboth"></div>';
125 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
128 $formmail->param[
'langsmodels'] = (empty($newlang) ? $langs->defaultlang : $newlang);
129 $formmail->fromtype = (
GETPOST(
'fromtype') ?
GETPOST(
'fromtype') : (!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE) ? $conf->global->MAIN_MAIL_DEFAULT_FROMTYPE :
'user'));
131 if ($formmail->fromtype ===
'user') {
132 $formmail->fromid = $user->id;
134 if ($object->element ==
'salary' && !empty($conf->global->INVOICE_EMAIL_SENDER)) {
135 $formmail->frommail = $conf->global->SINVOICE_EMAIL_SENDER;
136 $formmail->fromname = (!empty($conf->global->INVOICE_EMAIL_SENDER_NAME) ? $conf->global->INVOICE_EMAIL_SENDER_NAME :
'');
137 $formmail->fromtype =
'special';
139 if ($object->element ===
'facture' && !empty($conf->global->INVOICE_EMAIL_SENDER)) {
140 $formmail->frommail = $conf->global->INVOICE_EMAIL_SENDER;
141 $formmail->fromname = (!empty($conf->global->INVOICE_EMAIL_SENDER_NAME) ? $conf->global->INVOICE_EMAIL_SENDER_NAME :
'');
142 $formmail->fromtype =
'special';
144 if ($object->element ===
'shipping' && !empty($conf->global->SHIPPING_EMAIL_SENDER)) {
145 $formmail->frommail = $conf->global->SHIPPING_EMAIL_SENDER;
146 $formmail->fromname = (!empty($conf->global->SHIPPING_EMAIL_SENDER_NAME) ? $conf->global->SHIPPING_EMAIL_SENDER_NAME :
'');
147 $formmail->fromtype =
'special';
149 if ($object->element ===
'commande' && !empty($conf->global->COMMANDE_EMAIL_SENDER)) {
150 $formmail->frommail = $conf->global->COMMANDE_EMAIL_SENDER;
151 $formmail->fromname = (!empty($conf->global->COMMANDE_EMAIL_SENDER_NAME) ? $conf->global->COMMANDE_EMAIL_SENDER_NAME :
'');
152 $formmail->fromtype =
'special';
154 if ($object->element ===
'order_supplier' && !empty($conf->global->ORDER_SUPPLIER_EMAIL_SENDER)) {
155 $formmail->frommail = $conf->global->ORDER_SUPPLIER_EMAIL_SENDER;
156 $formmail->fromname = (!empty($conf->global->ORDER_SUPPLIER_EMAIL_SENDER_NAME) ? $conf->global->ORDER_SUPPLIER_EMAIL_SENDER_NAME :
'');
157 $formmail->fromtype =
'special';
159 if ($object->element ===
'recruitmentcandidature' ) {
160 $formmail->frommail = (!empty($conf->global->RECRUITMENT_EMAIL_SENDER) ? $conf->global->RECRUITMENT_EMAIL_SENDER : $recruitermail);
161 $formmail->fromname = (!empty($conf->global->RECRUITMENT_EMAIL_SENDER_NAME) ? $conf->global->RECRUITMENT_EMAIL_SENDER_NAME : (!empty($recruitername) ? $recruitername :
''));
162 $formmail->fromtype =
'special';
168 $defaultfrom =
GETPOST(
'fromtype');
170 $parameters = array();
171 $reshook = $hookmanager->executeHooks(
'getDefaultFromEmail', $parameters, $formmail);
172 if (empty($reshook)) {
173 $defaultfrom = $formmail->fromtype;
175 if (!empty($hookmanager->resArray[
'defaultfrom'])) {
176 $defaultfrom = $hookmanager->resArray[
'defaultfrom'];
179 $formmail->fromtype = $defaultfrom;
181 $formmail->trackid = empty($trackid) ?
'' : $trackid;
182 $formmail->inreplyto = empty($inreplyto) ?
'' : $inreplyto;
183 $formmail->withfrom = 1;
187 if ($object->element ==
'expensereport') {
188 $fuser =
new User($db);
189 $fuser->fetch($object->fk_user_author);
190 $liste[
'thirdparty'] = $fuser->getFullName($outputlangs).
" <".$fuser->email.
">";
191 } elseif ($object->element ==
'partnership' &&
getDolGlobalString(
'PARTNERSHIP_IS_MANAGED_FOR') ==
'member') {
193 $fadherent->fetch($object->fk_member);
194 $liste[
'member'] = $fadherent->getFullName($outputlangs).
" <".$fadherent->email.
">";
195 } elseif ($object->element ==
'societe') {
196 foreach ($object->thirdparty_and_contact_email_array(1) as $key => $value) {
197 $liste[$key] = $value;
199 } elseif ($object->element ==
'contact') {
200 $liste[
'contact'] = $object->getFullName($outputlangs).
" <".$object->email.
">";
201 } elseif ($object->element ==
'user' || $object->element ==
'member') {
202 $liste[
'thirdparty'] = $object->getFullName($outputlangs).
" <".$object->email.
">";
203 } elseif ($object->element ==
'salary') {
204 $fuser =
new User($db);
205 $fuser->fetch($object->fk_user);
206 $liste[
'thirdparty'] = $fuser->getFullName($outputlangs).
" <".$fuser->email.
">";
208 if (!empty($object->socid) && $object->socid > 0 && !is_object($object->thirdparty) && method_exists($object,
'fetch_thirdparty')) {
209 $object->fetch_thirdparty();
211 if (is_object($object->thirdparty)) {
212 foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key => $value) {
213 $liste[$key] = $value;
217 if (!empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) {
218 $listeuser = array();
219 $fuserdest =
new User($db);
221 $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);
222 if ($result > 0 && is_array($fuserdest->users) && count($fuserdest->users) > 0) {
223 foreach ($fuserdest->users as $uuserdest) {
224 $listeuser[$uuserdest->id] = $uuserdest->user_get_property($uuserdest->id,
'email');
226 } elseif ($result < 0) {
229 if (count($listeuser) > 0) {
230 $formmail->withtouser = $listeuser;
231 $formmail->withtoccuser = $listeuser;
236 if (!isset($arrayoffamiliestoexclude)) {
237 $arrayoffamiliestoexclude =
null;
241 if (!empty($object)) {
243 $formmail->setSubstitFromObject($object, $langs);
248 if ($formmail->fromtype) {
250 if (preg_match(
'/user/', $formmail->fromtype, $reg)) {
251 $emailsendersignature = $user->signature;
252 } elseif (preg_match(
'/company/', $formmail->fromtype, $reg)) {
253 $emailsendersignature =
'';
254 } elseif (preg_match(
'/senderprofile_(\d+)/', $formmail->fromtype, $reg)) {
255 $sql =
"SELECT rowid, label, email, signature FROM ".$db->prefix().
"c_email_senderprofile";
256 $sql .=
" WHERE rowid = ".((int) $reg[1]);
257 $resql = $db->query(
$sql);
259 $obj = $db->fetch_object($resql);
261 $emailsendersignature = $obj->signature;
266 $substitutionarray[
'__SENDEREMAIL_SIGNATURE__'] = $emailsendersignature;
268 $substitutionarray[
'__CHECK_READ__'] =
"";
269 if (is_object($object) && is_object($object->thirdparty)) {
270 $checkRead=
'<img src="'.DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-read.php';
271 $checkRead.=
'?tag='.(!empty($object->thirdparty->tag)?urlencode($object->thirdparty->tag):
"");
273 $checkRead.=
'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
274 $substitutionarray[
'__CHECK_READ__'] = $checkRead;
276 $substitutionarray[
'__PERSONALIZED__'] =
'';
277 $substitutionarray[
'__CONTACTCIVNAME__'] =
'';
279 'mode' =>
'formemail'
284 $tmpobject = $object;
285 if (($object->element ==
'shipping' || $object->element ==
'reception')) {
286 $origin = $object->origin;
287 $origin_id = $object->origin_id;
289 if (!empty($origin) && !empty($origin_id)) {
290 $element = $subelement = $origin;
292 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
294 $subelement = $regs[2];
297 if ($element ==
'order') {
298 $element = $subelement =
'commande';
300 if ($element ==
'propal') {
301 $element =
'comm/propal';
302 $subelement =
'propal';
304 if ($element ==
'contract') {
305 $element = $subelement =
'contrat';
307 if ($element ==
'inter') {
308 $element = $subelement =
'ficheinter';
310 if ($element ==
'shipping') {
311 $element = $subelement =
'expedition';
313 if ($element ==
'order_supplier') {
315 $subelement =
'fournisseur.commande';
317 if ($element ==
'project') {
322 $classname = ucfirst($origin);
323 $objectsrc =
new $classname($db);
324 $objectsrc->fetch($origin_id);
326 $tmpobject = $objectsrc;
330 $contactarr = array();
331 $contactarr = $tmpobject->liste_contact(-1,
'external', 0,
'', 1);
333 if (is_array($contactarr) && count($contactarr) > 0) {
334 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
335 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
336 $contactstatic =
new Contact($db);
337 $tmpcompany =
new Societe($db);
339 foreach ($contactarr as $contact) {
340 $contactstatic->fetch($contact[
'id']);
342 $substitutionarray[
'__CONTACT_NAME_'.$contact[
'code'].
'__'] = $contactstatic->getFullName($outputlangs, 1);
343 $substitutionarray[
'__CONTACT_LASTNAME_'.$contact[
'code'].
'__'] = $contactstatic->lastname;
344 $substitutionarray[
'__CONTACT_FIRSTNAME_'.$contact[
'code'].
'__'] = $contactstatic->firstname;
345 $substitutionarray[
'__CONTACT_TITLE_'.$contact[
'code'].
'__'] = $contactstatic->getCivilityLabel();
348 if (empty($liste[$contact[
'id']])) {
350 if (isset($object->thirdparty) && is_object($object->thirdparty)) {
351 if ($contactstatic->fk_soc != $object->thirdparty->id) {
352 $tmpcompany->fetch($contactstatic->fk_soc);
353 if ($tmpcompany->id > 0) {
354 $contacttoshow .= $tmpcompany->name.
': ';
358 $contacttoshow .= $contactstatic->getFullName($outputlangs, 1);
359 $contacttoshow .=
" <".($contactstatic->email ? $contactstatic->email : $langs->transnoentitiesnoconv(
"NoEMail")) .
">";
360 $liste[$contact[
'id']] = $contacttoshow;
365 $formmail->withto = $liste;
366 $formmail->withtofree = (
GETPOST(
'sendto',
'alphawithlgt') ?
GETPOST(
'sendto',
'alphawithlgt') :
'1');
367 $formmail->withtocc = $liste;
369 $formmail->withtopic = $topicmail;
370 $formmail->withfile = 2;
371 $formmail->withbody = 1;
372 $formmail->withdeliveryreceipt = 1;
373 $formmail->withcancel = 1;
376 $formmail->substit = $substitutionarray;
379 $formmail->param[
'action'] =
'send';
380 $formmail->param[
'models'] = $modelmail;
381 $formmail->param[
'models_id'] =
GETPOST(
'modelmailselected',
'int');
382 $formmail->param[
'id'] = $object->id;
383 $formmail->param[
'returnurl'] = $_SERVER[
"PHP_SELF"].
'?id='.$object->id;
384 $formmail->param[
'fileinit'] = array($file);
387 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') && $user->hasRight('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') && $user->hasRight('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)) $sql
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='', $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.
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.
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
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.