30 if (empty($conf) || !is_object($conf)) {
31 print "Error, template page can't be called as URL";
36 if ($action ==
'presend')
38 $langs->load(
"mails");
40 $titreform =
'SendMail';
42 $object->fetch_projet();
44 if (!in_array($object->element, array(
'societe',
'user',
'member')))
49 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
51 if ($object->element ==
'invoice_supplier')
53 $fileparams =
dol_most_recent_file($diroutput.
'/'.
get_exdir($object->id, 2, 0, 0, $object, $object->element).$ref, preg_quote($ref,
'/').
'([^\-])+');
58 $file = $fileparams[
'fullname'];
62 $outputlangs = $langs;
64 if ($conf->global->MAIN_MULTILANGS && empty($newlang) && !empty($_REQUEST[
'lang_id']))
66 $newlang = $_REQUEST[
'lang_id'];
68 if ($conf->global->MAIN_MULTILANGS && empty($newlang))
70 $newlang = $object->thirdparty->default_lang;
76 $outputlangs->setDefaultLang($newlang);
78 $outputlangs->loadLangs(array(
'commercial',
'bills',
'orders',
'contracts',
'members',
'propal',
'products',
'supplier_proposal',
'interventions',
'receptions'));
82 if (empty($object->ref_client)) {
83 $topicmail = $outputlangs->trans($defaulttopic,
'__REF__');
84 } elseif (!empty($object->ref_client)) {
85 $topicmail = $outputlangs->trans($defaulttopic,
'__REF__ (__REFCLIENT__)');
89 $forcebuilddoc =
true;
90 if (in_array($object->element, array(
'societe',
'user',
'member'))) $forcebuilddoc =
false;
91 if ($object->element ==
'invoice_supplier' && empty($conf->global->INVOICE_SUPPLIER_ADDON_PDF)) $forcebuilddoc =
false;
94 if ((!$file || !is_readable($file)) && method_exists($object,
'generateDocument'))
96 $result = $object->generateDocument(
GETPOST(
'model') ?
GETPOST(
'model') : $object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
101 if ($object->element ==
'invoice_supplier')
103 $fileparams =
dol_most_recent_file($diroutput.
'/'.
get_exdir($object->id, 2, 0, 0, $object, $object->element).$ref, preg_quote($ref,
'/').
'([^\-])+');
108 $file = $fileparams[
'fullname'];
112 print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
113 print '<div class="clearboth"></div>';
120 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
123 $formmail->param[
'langsmodels'] = (empty($newlang) ? $langs->defaultlang : $newlang);
124 $formmail->fromtype = (
GETPOST(
'fromtype') ?
GETPOST(
'fromtype') : (!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE) ? $conf->global->MAIN_MAIL_DEFAULT_FROMTYPE :
'user'));
126 if ($formmail->fromtype ===
'user')
128 $formmail->fromid = $user->id;
131 if ($object->element ===
'facture' && !empty($conf->global->INVOICE_EMAIL_SENDER)) {
132 $formmail->frommail = $conf->global->INVOICE_EMAIL_SENDER;
133 $formmail->fromname =
'';
134 $formmail->fromtype =
'special';
136 if ($object->element ===
'shipping' && !empty($conf->global->SHIPPING_EMAIL_SENDER)) {
137 $formmail->frommail = $conf->global->SHIPPING_EMAIL_SENDER;
138 $formmail->fromname =
'';
139 $formmail->fromtype =
'special';
141 if ($object->element ===
'commande' && !empty($conf->global->COMMANDE_EMAIL_SENDER)) {
142 $formmail->frommail = $conf->global->COMMANDE_EMAIL_SENDER;
143 $formmail->fromname =
'';
144 $formmail->fromtype =
'special';
147 $formmail->trackid = $trackid;
148 if (!empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2))
150 include DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
153 $formmail->withfrom = 1;
157 if ($object->element ==
'expensereport') {
158 $fuser =
new User($db);
159 $fuser->fetch($object->fk_user_author);
160 $liste[
'thirdparty'] = $fuser->getFullName($outputlangs).
" <".$fuser->email.
">";
161 } elseif ($object->element ==
'societe') {
162 foreach ($object->thirdparty_and_contact_email_array(1) as $key => $value) {
163 $liste[$key] = $value;
165 } elseif ($object->element ==
'contact') {
166 $liste[
'contact'] = $object->getFullName($outputlangs).
" <".$object->email.
">";
167 } elseif ($object->element ==
'user' || $object->element ==
'member') {
168 $liste[
'thirdparty'] = $object->getFullName($outputlangs).
" <".$object->email.
">";
170 if (!empty($object->socid) && $object->socid > 0 && !is_object($object->thirdparty) && method_exists($object,
'fetch_thirdparty')) {
171 $object->fetch_thirdparty();
173 if (is_object($object->thirdparty))
175 foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key => $value) {
176 $liste[$key] = $value;
180 if (!empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) {
181 $listeuser = array();
182 $fuserdest =
new User($db);
184 $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);
185 if ($result > 0 && is_array($fuserdest->users) && count($fuserdest->users) > 0) {
186 foreach ($fuserdest->users as $uuserdest) {
187 $listeuser[$uuserdest->id] = $uuserdest->user_get_property($uuserdest->id,
'email');
189 } elseif ($result < 0) {
192 if (count($listeuser) > 0) {
193 $formmail->withtouser = $listeuser;
194 $formmail->withtoccuser = $listeuser;
198 $formmail->withto = $liste;
199 $formmail->withtofree = (
GETPOSTISSET(
'sendto') ? (
GETPOST(
'sendto',
'alphawithlgt') ?
GETPOST(
'sendto',
'alphawithlgt') :
'1') :
'1');
200 $formmail->withtocc = $liste;
201 $formmail->withtoccc = $conf->global->MAIN_EMAIL_USECCC;
202 $formmail->withtopic = $topicmail;
203 $formmail->withfile = 2;
204 $formmail->withbody = 1;
205 $formmail->withdeliveryreceipt = 1;
206 $formmail->withcancel = 1;
209 if (!isset($arrayoffamiliestoexclude)) $arrayoffamiliestoexclude = null;
213 $substitutionarray[
'__CHECK_READ__'] = (is_object($object) && is_object($object->thirdparty)) ?
'<img src="'.DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-read.php?tag='.$object->thirdparty->tag.
'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).
'" width="1" height="1" style="width:1px;height:1px" border="0"/>' :
'';
214 $substitutionarray[
'__PERSONALIZED__'] =
'';
215 $substitutionarray[
'__CONTACTCIVNAME__'] =
'';
217 'mode' =>
'formemail'
222 $tmpobject = $object;
223 if (($object->element ==
'shipping' || $object->element ==
'reception')) {
224 $origin = $object->origin;
225 $origin_id = $object->origin_id;
227 if (!empty($origin) && !empty($origin_id)) {
228 $element = $subelement = $origin;
230 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
232 $subelement = $regs[2];
235 if ($element ==
'order') {
236 $element = $subelement =
'commande';
238 if ($element ==
'propal') {
239 $element =
'comm/propal';
240 $subelement =
'propal';
242 if ($element ==
'contract') {
243 $element = $subelement =
'contrat';
245 if ($element ==
'inter') {
246 $element = $subelement =
'ficheinter';
248 if ($element ==
'shipping') {
249 $element = $subelement =
'expedition';
251 if ($element ==
'order_supplier') {
253 $subelement =
'fournisseur.commande';
255 if ($element ==
'project') {
260 $classname = ucfirst($origin);
261 $objectsrc =
new $classname($db);
262 $objectsrc->fetch($origin_id);
264 $tmpobject = $objectsrc;
268 $contactarr = array();
269 $contactarr = $tmpobject->liste_contact(-1,
'external');
271 if (is_array($contactarr) && count($contactarr) > 0) {
272 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
273 $contactstatic =
new Contact($db);
275 foreach ($contactarr as $contact) {
276 $contactstatic->fetch($contact[
'id']);
277 $substitutionarray[
'__CONTACT_NAME_'.$contact[
'code'].
'__'] = $contactstatic->getFullName($outputlangs, 1);
282 $formmail->substit = $substitutionarray;
285 $formmail->param[
'action'] =
'send';
286 $formmail->param[
'models'] = $modelmail;
287 $formmail->param[
'models_id'] =
GETPOST(
'modelmailselected',
'int');
288 $formmail->param[
'id'] = $object->id;
289 $formmail->param[
'returnurl'] =
$_SERVER[
"PHP_SELF"].
'?id='.$object->id;
290 $formmail->param[
'fileinit'] = array($file);
293 print $formmail->get_form();
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname= '')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage Dolibarr users.
dolAddEmailTrackId($email, $trackingid)
Return an email formatted to include a tracking id For example myemail@example.com becom myemail+trac...
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart= '')
Return a path to have a the directory according to object where files are stored. ...
Class to manage translations.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
dol_most_recent_file($dir, $regexfilter= '', $excludefilter=array('(\.meta|_preview.*\.png)$', '^\.'), $nohook=false, $mode= '')
Return file(s) into a directory (by default most recent)
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.
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...