dolibarr  7.0.0-beta
html.formmail.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
4  * Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
5  * Copyright (C) 2015 Marcos GarcĂ­a <marcosgdf@gmail.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
26 require_once DOL_DOCUMENT_ROOT .'/core/class/html.form.class.php';
27 
28 
35 class FormMail extends Form
36 {
37  var $db;
38 
39  var $withform; // 1=Include HTML form tag and show submit button, 0=Do not include form tag and submit button, -1=Do not include form tag but include submit button
40 
41  var $fromname;
42  var $frommail;
43  var $replytoname;
44  var $replytomail;
45  var $toname;
46  var $tomail;
47  var $trackid;
48 
49  var $withsubstit; // Show substitution array
50  var $withfrom;
56  public $withtosocid;
60  public $withto; // Show recipient emails
61  var $withtofree; // Show free text for recipient emails
62  var $withtocc;
63  var $withtoccc;
64  var $withtopic;
65  var $withfile; // 0=No attaches files, 1=Show attached files, 2=Can add new attached files
66  var $withmaindocfile; // 1=Add a checkbox "Attach also main document" for mass actions (checked by default), -1=Add checkbox (not checked by default)
67  var $withbody;
68 
69  var $withfromreadonly;
70  var $withreplytoreadonly;
71  var $withtoreadonly;
72  var $withtoccreadonly;
73  var $withtocccreadonly;
74  var $withtopicreadonly;
75  var $withfilereadonly;
76  var $withdeliveryreceipt;
77  var $withcancel;
78  var $withfckeditor;
79 
80  var $substit=array();
81  var $substit_lines=array();
82  var $param=array();
83 
84  var $error;
85 
86  public $lines_model;
87 
88 
94  function __construct($db)
95  {
96  $this->db = $db;
97 
98  $this->withform=1;
99 
100  $this->withfrom=1;
101  $this->withto=1;
102  $this->withtofree=1;
103  $this->withtocc=1;
104  $this->withtoccc=0;
105  $this->witherrorsto=0;
106  $this->withtopic=1;
107  $this->withfile=0; // 1=Add section "Attached files". 2=Can add files.
108  $this->withmaindocfile=0; // 1=Add a checkbox "Attach also main document" for mass actions (checked by default), -1=Add checkbox (not checked by default)
109  $this->withbody=1;
110 
111  $this->withfromreadonly=1;
112  $this->withreplytoreadonly=1;
113  $this->withtoreadonly=0;
114  $this->withtoccreadonly=0;
115  $this->withtocccreadonly=0;
116  $this->witherrorstoreadonly=0;
117  $this->withtopicreadonly=0;
118  $this->withfilereadonly=0;
119  $this->withbodyreadonly=0;
120  $this->withdeliveryreceiptreadonly=0;
121  $this->withfckeditor=-1; // -1 = Auto
122 
123  return 1;
124  }
125 
132  {
133  global $conf,$user;
134  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
135 
136  // Set tmp user directory
137  $vardir=$conf->user->dir_output."/".$user->id;
138  $upload_dir = $vardir.'/temp/'; // TODO Add $keytoavoidconflict in upload_dir path
139  if (is_dir($upload_dir)) dol_delete_dir_recursive($upload_dir);
140 
141  $keytoavoidconflict = empty($this->trackid)?'':'-'.$this->trackid; // this->trackid must be defined
142  unset($_SESSION["listofpaths".$keytoavoidconflict]);
143  unset($_SESSION["listofnames".$keytoavoidconflict]);
144  unset($_SESSION["listofmimes".$keytoavoidconflict]);
145  }
146 
155  function add_attached_files($path,$file,$type)
156  {
157  $listofpaths=array();
158  $listofnames=array();
159  $listofmimes=array();
160 
161  $keytoavoidconflict = empty($this->trackid)?'':'-'.$this->trackid; // this->trackid must be defined
162  if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]);
163  if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]);
164  if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]);
165  if (! in_array($file,$listofnames))
166  {
167  $listofpaths[]=$path;
168  $listofnames[]=$file;
169  $listofmimes[]=$type;
170  $_SESSION["listofpaths".$keytoavoidconflict]=join(';',$listofpaths);
171  $_SESSION["listofnames".$keytoavoidconflict]=join(';',$listofnames);
172  $_SESSION["listofmimes".$keytoavoidconflict]=join(';',$listofmimes);
173  }
174  }
175 
182  function remove_attached_files($keytodelete)
183  {
184  $listofpaths=array();
185  $listofnames=array();
186  $listofmimes=array();
187 
188  $keytoavoidconflict = empty($this->trackid)?'':'-'.$this->trackid; // this->trackid must be defined
189  if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]);
190  if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]);
191  if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]);
192  if ($keytodelete >= 0)
193  {
194  unset ($listofpaths[$keytodelete]);
195  unset ($listofnames[$keytodelete]);
196  unset ($listofmimes[$keytodelete]);
197  $_SESSION["listofpaths".$keytoavoidconflict]=join(';',$listofpaths);
198  $_SESSION["listofnames".$keytoavoidconflict]=join(';',$listofnames);
199  $_SESSION["listofmimes".$keytoavoidconflict]=join(';',$listofmimes);
200  //var_dump($_SESSION['listofpaths']);
201  }
202  }
203 
210  {
211  $listofpaths=array();
212  $listofnames=array();
213  $listofmimes=array();
214 
215  $keytoavoidconflict = empty($this->trackid)?'':'-'.$this->trackid; // this->trackid must be defined
216  if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]);
217  if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]);
218  if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]);
219  return array('paths'=>$listofpaths, 'names'=>$listofnames, 'mimes'=>$listofmimes);
220  }
221 
231  function show_form($addfileaction='addfile',$removefileaction='removefile')
232  {
233  print $this->get_form($addfileaction,$removefileaction);
234  }
235 
246  function get_form($addfileaction='addfile',$removefileaction='removefile')
247  {
248  global $conf, $langs, $user, $hookmanager, $form;
249 
250  if (! is_object($form)) $form=new Form($this->db);
251 
252  $langs->load("other");
253  $langs->load("mails");
254 
255  $hookmanager->initHooks(array('formmail'));
256 
257  $parameters=array(
258  'addfileaction' => $addfileaction,
259  'removefileaction'=> $removefileaction,
260  'trackid'=> $this->trackid
261  );
262  $reshook=$hookmanager->executeHooks('getFormMail', $parameters, $this);
263 
264  if (!empty($reshook))
265  {
266  return $hookmanager->resPrint;
267  }
268  else
269  {
270  $out='';
271 
272  $disablebademails=1;
273 
274  // Define output language
275  $outputlangs = $langs;
276  $newlang = '';
277  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $this->param['langsmodels'];
278  if (! empty($newlang))
279  {
280  $outputlangs = new Translate("", $conf);
281  $outputlangs->setDefaultLang($newlang);
282  $outputlangs->load('other');
283  }
284 
285  // Get message template for $this->param["models"] into c_email_templates
286  $arraydefaultmessage=array();
287  if ($this->param['models'] != 'none')
288  {
289  $model_id=0;
290  if (array_key_exists('models_id',$this->param))
291  {
292  $model_id=$this->param["models_id"];
293  }
294  $arraydefaultmessage=$this->getEMailTemplate($this->db, $this->param["models"], $user, $outputlangs, ($model_id ? $model_id : -1)); // we set -1 if model_id empty
295  }
296  //var_dump($this->param["models"]);
297  //var_dump($model_id);
298  //var_dump($arraydefaultmessage);
299 
300 
301  // Define list of attached files
302  $listofpaths=array();
303  $listofnames=array();
304  $listofmimes=array();
305  $keytoavoidconflict = empty($this->trackid)?'':'-'.$this->trackid; // this->trackid must be defined
306 
307  if (GETPOST('mode','alpha') == 'init' || (GETPOST('modelmailselected','alpha') && GETPOST('modelmailselected','alpha') != '-1'))
308  {
309  $this->clear_attached_files();
310  if (! empty($arraydefaultmessage['joinfiles']) && is_array($this->param['fileinit']))
311  {
312  foreach($this->param['fileinit'] as $file)
313  {
314  $this->add_attached_files($file, basename($file), dol_mimetype($file));
315  }
316  }
317  }
318 
319  if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]);
320  if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]);
321  if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]);
322 
323 
324  $out.= "\n".'<!-- Begin form mail type='.$this->param["models"].' --><div id="mailformdiv"></div>'."\n";
325  if ($this->withform == 1)
326  {
327  $out.= '<form method="POST" name="mailform" id="mailform" enctype="multipart/form-data" action="'.$this->param["returnurl"].'#formmail">'."\n";
328 
329  $out.= '<a id="formmail" name="formmail"></a>';
330  $out.= '<input style="display:none" type="submit" id="sendmail" name="sendmail">';
331  $out.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'" />';
332  $out.= '<input type="hidden" name="trackid" value="'.$this->trackid.'" />';
333  }
334  if (! empty($this->withfrom))
335  {
336  if (! empty($this->withfromreadonly))
337  {
338  $out.= '<input type="hidden" id="fromname" name="fromname" value="'.$this->fromname.'" />';
339  $out.= '<input type="hidden" id="frommail" name="frommail" value="'.$this->frommail.'" />';
340  }
341  }
342  foreach ($this->param as $key=>$value)
343  {
344  $out.= '<input type="hidden" id="'.$key.'" name="'.$key.'" value="'.$value.'" />'."\n";
345  }
346 
347  $modelmail_array=array();
348  if ($this->param['models'] != 'none')
349  {
350  $result = $this->fetchAllEMailTemplate($this->param["models"], $user, $outputlangs);
351  if ($result < 0)
352  {
353  setEventMessages($this->error, $this->errors, 'errors');
354  }
355  foreach($this->lines_model as $line)
356  {
357  $langs->trans("members");
358  if (preg_match('/\((.*)\)/', $line->label, $reg))
359  {
360  $modelmail_array[$line->id]=$langs->trans($reg[1]); // langs->trans when label is __(xxx)__
361  }
362  else
363  {
364  $modelmail_array[$line->id]=$line->label;
365  }
366  if ($line->lang) $modelmail_array[$line->id].=' ('.$line->lang.')';
367  if ($line->private) $modelmail_array[$line->id].=' - '.$langs->trans("Private");
368  //if ($line->fk_user != $user->id) $modelmail_array[$line->id].=' - '.$langs->trans("By").' ';
369  }
370  }
371 
372  // Zone to select email template
373  if (count($modelmail_array)>0)
374  {
375  // If list of template is filled
376  $out.= '<div class="center" style="padding: 0px 0 12px 0">'."\n";
377  $out.= '<span class="opacitymedium">'.$langs->trans('SelectMailModel').':</span> '.$this->selectarray('modelmailselected', $modelmail_array, 0, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100');
378  if ($user->admin) $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv('Setup').' - '.$langs->transnoentitiesnoconv('EMails')),1);
379  $out.= ' &nbsp; ';
380  $out.= '<input class="button" type="submit" value="'.$langs->trans('Apply').'" name="modelselected" id="modelselected">';
381  $out.= ' &nbsp; ';
382  $out.= '</div>';
383  }
384  elseif (! empty($this->param['models']) && in_array($this->param['models'], array(
385  'propal_send','order_send','facture_send',
386  'shipping_send','fichinter_send','supplier_proposal_send','order_supplier_send',
387  'invoice_supplier_send','thirdparty','contract','user','all'
388  )))
389  {
390  // If list of template is empty
391  $out.= '<div class="center" style="padding: 0px 0 12px 0">'."\n";
392  $out.= $langs->trans('SelectMailModel').': <select name="modelmailselected" disabled="disabled"><option value="none">'.$langs->trans("NoTemplateDefined").'</option></select>'; // Do not put 'disabled' on 'option' tag, it is already on 'select' and it makes chrome crazy.
393  if ($user->admin) $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv('Setup').' - '.$langs->transnoentitiesnoconv('EMails')),1);
394  $out.= ' &nbsp; ';
395  $out.= '<input class="button" type="submit" value="'.$langs->trans('Apply').'" name="modelselected" disabled="disabled" id="modelselected">';
396  $out.= ' &nbsp; ';
397  $out.= '</div>';
398  }
399 
400 
401 
402  $out.= '<table class="border" width="100%">'."\n";
403 
404  // Substitution array
405  if (! empty($this->withsubstit)) // Unset or set ->withsubstit=0 to disable this.
406  {
407  $out.= '<tr><td colspan="2" align="right">';
408  //$out.='<div class="floatright">';
409  $help="";
410  foreach($this->substit as $key => $val)
411  {
412  $help.=$key.' -> '.$langs->trans(dol_string_nohtmltag($val)).'<br>';
413  }
414  if (is_numeric($this->withsubstit)) $out.= $form->textwithpicto($langs->trans("EMailTestSubstitutionReplacedByGenericValues"), $help, 1, 'help', '', 0, 2, 'substittooltip'); // Old usage
415  else $out.= $form->textwithpicto($langs->trans('AvailableVariables'), $help, 1, 'help', '', 0, 2, 'substittooltip'); // New usage
416  $out.= "</td></tr>\n";
417  //$out.='</div>';
418  }
419 
420  /*var_dump(! empty($this->withfromreadonly));
421  var_dump($this->withfrom);
422  var_dump($this->fromtype);
423  var_dump($this->fromname);*/
424 
425  // From
426  if (! empty($this->withfrom))
427  {
428  if (! empty($this->withfromreadonly))
429  {
430  $out.= '<tr><td class="fieldrequired minwidth200">'.$langs->trans("MailFrom").'</td><td>';
431 
432  // $this->fromtype is the default value to use to select sender
433  if (! ($this->fromtype === 'user' && $this->fromid > 0)
434  && ! ($this->fromtype === 'company')
435  && ! ($this->fromtype === 'robot')
436  && ! preg_match('/user_aliases/', $this->fromtype)
437  && ! preg_match('/global_aliases/', $this->fromtype)
438  && ! preg_match('/senderprofile/', $this->fromtype)
439  )
440  {
441  // Use this->fromname and this->frommail or error if not defined
442  $out.= $this->fromname;
443  if ($this->frommail)
444  {
445  $out.= ' &lt;'.$this->frommail.'&gt;';
446  }
447  else
448  {
449  if ($this->fromtype)
450  {
451  $langs->load('errors');
452  $out.= '<span class="warning"> &lt;'.$langs->trans('ErrorNoMailDefinedForThisUser').'&gt; </span>';
453  }
454  }
455  } else {
456  $liste = array();
457 
458  // Add user email
459  if (empty($user->email))
460  {
461  $langs->load('errors');
462  $liste['user'] = $user->getFullName($langs) . ' &lt;'.$langs->trans('ErrorNoMailDefinedForThisUser').'&gt;';
463  }
464  else
465  {
466  $liste['user'] = $user->getFullName($langs) .' &lt;'.$user->email.'&gt;';
467  }
468 
469  // Add also company main email
470  $liste['company'] = $conf->global->MAIN_INFO_SOCIETE_NOM .' &lt;'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'&gt;';
471 
472  // Add also email aliases if there is some
473  $listaliases=array('user_aliases'=>$user->email_aliases, 'global_aliases'=>$conf->global->MAIN_INFO_SOCIETE_MAIL_ALIASES);
474 
475  // Also add robot email
476  if (! empty($this->fromalsorobot))
477  {
478  if (! empty($conf->global->MAIN_MAIL_EMAIL_FROM) && $conf->global->MAIN_MAIL_EMAIL_FROM != $conf->global->MAIN_INFO_SOCIETE_MAIL)
479  {
480  $liste['robot'] = $conf->global->MAIN_MAIL_EMAIL_FROM;
481  if ($this->frommail)
482  {
483  $liste['robot'] .= ' &lt;'.$conf->global->MAIN_MAIL_EMAIL_FROM.'&gt;';
484  }
485  }
486  }
487 
488  // Add also email aliases from the c_email_senderprofile table
489  $sql='SELECT rowid, label, email FROM '.MAIN_DB_PREFIX.'c_email_senderprofile WHERE active = 1 ORDER BY position';
490  $resql = $this->db->query($sql);
491  if ($resql)
492  {
493  $num = $this->db->num_rows($resql);
494  $i=0;
495  while($i < $num)
496  {
497  $obj = $this->db->fetch_object($resql);
498  if ($obj)
499  {
500  $listaliases['senderprofile_'.$obj->rowid] = $obj->label.' <'.$obj->email.'>';
501  }
502  $i++;
503  }
504  }
505  else dol_print_error($this->db);
506 
507  foreach($listaliases as $typealias => $listalias)
508  {
509  $posalias=0;
510  $listaliasarray=explode(',', $listalias);
511  foreach ($listaliasarray as $listaliasval)
512  {
513  $posalias++;
514  $listaliasval=trim($listaliasval);
515  if ($listaliasval)
516  {
517  $listaliasval=preg_replace('/</', '&lt;', $listaliasval);
518  $listaliasval=preg_replace('/>/', '&gt;', $listaliasval);
519  if (! preg_match('/&lt;/', $listaliasval)) $listaliasval='&lt;'.$listaliasval.'&gt;';
520  $liste[$typealias.'_'.$posalias]=$listaliasval;
521  }
522  }
523  }
524 
525  // Set the default "From"
526  $defaultfrom='';
527  $reshook=$hookmanager->executeHooks('getDefaultFromEmail', $parameters, $this);
528  if (empty($reshook))
529  {
530  $defaultfrom = $this->fromtype;
531  }
532  if (! empty($hookmanager->resArray['defaultfrom'])) $defaultfrom=$hookmanager->resArray['defaultfrom'];
533 
534  // Using combo here make the '<email>' no more visible on list.
535  //$out.= ' '.$form->selectarray('fromtype', $liste, $this->fromtype, 0, 0, 0, '', 0, 0, 0, '', 'fromforsendingprofile maxwidth200onsmartphone', 1, '', $disablebademails);
536  $out.= ' '.$form->selectarray('fromtype', $liste, $defaultfrom, 0, 0, 0, '', 0, 0, 0, '', 'fromforsendingprofile maxwidth200onsmartphone', 0, '', $disablebademails);
537  }
538 
539  $out.= "</td></tr>\n";
540  }
541  else
542  {
543  $out.= '<tr><td class="fieldrequired width200">'.$langs->trans("MailFrom")."</td><td>";
544  $out.= $langs->trans("Name").':<input type="text" id="fromname" name="fromname" class="maxwidth200onsmartphone" value="'.$this->fromname.'" />';
545  $out.= '&nbsp; &nbsp; ';
546  $out.= $langs->trans("EMail").':&lt;<input type="text" id="frommail" name="frommail" class="maxwidth200onsmartphone" value="'.$this->frommail.'" />&gt;';
547  $out.= "</td></tr>\n";
548  }
549  }
550 
551  // To
552  if (! empty($this->withto) || is_array($this->withto))
553  {
554  $out.= '<tr><td class="fieldrequired">';
555  if ($this->withtofree) $out.= $form->textwithpicto($langs->trans("MailTo"),$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"));
556  else $out.= $langs->trans("MailTo");
557  $out.= '</td><td>';
558  if ($this->withtoreadonly)
559  {
560  if (! empty($this->toname) && ! empty($this->tomail))
561  {
562  $out.= '<input type="hidden" id="toname" name="toname" value="'.$this->toname.'" />';
563  $out.= '<input type="hidden" id="tomail" name="tomail" value="'.$this->tomail.'" />';
564  if ($this->totype == 'thirdparty')
565  {
566  $soc=new Societe($this->db);
567  $soc->fetch($this->toid);
568  $out.= $soc->getNomUrl(1);
569  }
570  else if ($this->totype == 'contact')
571  {
572  $contact=new Contact($this->db);
573  $contact->fetch($this->toid);
574  $out.= $contact->getNomUrl(1);
575  }
576  else
577  {
578  $out.= $this->toname;
579  }
580  $out.= ' &lt;'.$this->tomail.'&gt;';
581  if ($this->withtofree)
582  {
583  $out.= '<br>'.$langs->trans("and").' <input class="minwidth200" id="sendto" name="sendto" value="'.(! is_array($this->withto) && ! is_numeric($this->withto)? (isset($_REQUEST["sendto"])?$_REQUEST["sendto"]:$this->withto) :"").'" />';
584  }
585  }
586  else
587  {
588  // Note withto may be a text like 'AllRecipientSelected'
589  $out.= (! is_array($this->withto) && ! is_numeric($this->withto))?$this->withto:"";
590  }
591  }
592  else
593  {
594  if (! empty($this->withtofree))
595  {
596  $out.= '<input class="minwidth200" id="sendto" name="sendto" value="'.(! is_array($this->withto) && ! is_numeric($this->withto)? (isset($_REQUEST["sendto"])?$_REQUEST["sendto"]:$this->withto) :"").'" />';
597  }
598  if (! empty($this->withto) && is_array($this->withto))
599  {
600  if (! empty($this->withtofree)) $out.= " ".$langs->trans("and")."/".$langs->trans("or")." ";
601  // multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time
602  $tmparray = $this->withto;
603  foreach($tmparray as $key => $val)
604  {
605  $tmparray[$key]=dol_htmlentities($tmparray[$key], null, 'UTF-8', true);
606  }
607  $withtoselected=GETPOST("receiver",'none'); // Array of selected value
608  if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action','aZ09') == 'presend')
609  {
610  $withtoselected = array_keys($tmparray);
611  }
612  $out.= $form->multiselectarray("receiver", $tmparray, $withtoselected, null, null, 'inline-block minwidth500', null, "");
613  }
614  }
615  $out.= "</td></tr>\n";
616  }
617 
618  // withoptiononeemailperrecipient
619  if (! empty($this->withoptiononeemailperrecipient))
620  {
621  $out.= '<tr><td class="minwidth200">';
622  $out.= $langs->trans("GroupEmails");
623  $out.= '</td><td>';
624  $out.=' <input type="checkbox" name="oneemailperrecipient"'.($this->withoptiononeemailperrecipient > 0?' checked="checked"':'').'> ';
625  $out.= $langs->trans("OneEmailPerRecipient");
626  $out.='<span class="hideonsmartphone">';
627  $out.=' - ';
628  $out.= $langs->trans("WarningIfYouCheckOneRecipientPerEmail");
629  $out.='</span>';
630  $out.= '</td></tr>';
631  }
632 
633  // CC
634  if (! empty($this->withtocc) || is_array($this->withtocc))
635  {
636  $out.= '<tr><td>';
637  $out.= $form->textwithpicto($langs->trans("MailCC"),$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"));
638  $out.= '</td><td>';
639  if ($this->withtoccreadonly)
640  {
641  $out.= (! is_array($this->withtocc) && ! is_numeric($this->withtocc))?$this->withtocc:"";
642  }
643  else
644  {
645  $out.= '<input class="minwidth200" id="sendtocc" name="sendtocc" value="'.((! is_array($this->withtocc) && ! is_numeric($this->withtocc))? (isset($_POST["sendtocc"])?$_POST["sendtocc"]:$this->withtocc) : (isset($_POST["sendtocc"])?$_POST["sendtocc"]:"") ).'" />';
646  if (! empty($this->withtocc) && is_array($this->withtocc))
647  {
648  $out.= " ".$langs->trans("and")."/".$langs->trans("or")." ";
649  // multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time
650  $tmparray = $this->withtocc;
651  foreach($tmparray as $key => $val)
652  {
653  $tmparray[$key]=dol_htmlentities($tmparray[$key], null, 'UTF-8', true);
654  }
655  $withtoccselected=GETPOST("receivercc"); // Array of selected value
656  $out.= $form->multiselectarray("receivercc", $tmparray, $withtoccselected, null, null, 'inline-block minwidth500',null, "");
657  }
658  }
659  $out.= "</td></tr>\n";
660  }
661 
662  // CCC
663  if (! empty($this->withtoccc) || is_array($this->withtoccc))
664  {
665  $out.= '<tr><td>';
666  $out.= $form->textwithpicto($langs->trans("MailCCC"),$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"));
667  $out.= '</td><td>';
668  if (! empty($this->withtocccreadonly))
669  {
670  $out.= (! is_array($this->withtoccc) && ! is_numeric($this->withtoccc))?$this->withtoccc:"";
671  }
672  else
673  {
674  $out.= '<input class="minwidth200" id="sendtoccc" name="sendtoccc" value="'.((! is_array($this->withtoccc) && ! is_numeric($this->withtoccc))? (isset($_POST["sendtoccc"])?$_POST["sendtoccc"]:$this->withtoccc) : (isset($_POST["sendtoccc"])?$_POST["sendtoccc"]:"") ).'" />';
675  if (! empty($this->withtoccc) && is_array($this->withtoccc))
676  {
677  $out.= " ".$langs->trans("and")."/".$langs->trans("or")." ";
678  // multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time
679  $tmparray = $this->withtoccc;
680  foreach($tmparray as $key => $val)
681  {
682  $tmparray[$key]=dol_htmlentities($tmparray[$key], null, 'UTF-8', true);
683  }
684  $withtocccselected=GETPOST("receiverccc"); // Array of selected value
685  $out.= $form->multiselectarray("receiverccc", $tmparray, $withtocccselected, null, null, null,null, "90%");
686  }
687  }
688 
689  $showinfobcc='';
690  if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO) && ! empty($this->param['models']) && $this->param['models'] == 'propal_send') $showinfobcc=$conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO;
691  if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO) && ! empty($this->param['models']) && $this->param['models'] == 'supplier_proposal_send') $showinfobcc=$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO;
692  if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO) && ! empty($this->param['models']) && $this->param['models'] == 'order_send') $showinfobcc=$conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO;
693  if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO) && ! empty($this->param['models']) && $this->param['models'] == 'facture_send') $showinfobcc=$conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO;
694  if ($showinfobcc) $out.=' + '.$showinfobcc;
695  $out.= "</td></tr>\n";
696  }
697 
698  // Replyto
699  if (! empty($this->withreplyto))
700  {
701  if ($this->withreplytoreadonly)
702  {
703  $out.= '<input type="hidden" id="replyname" name="replyname" value="'.$this->replytoname.'" />';
704  $out.= '<input type="hidden" id="replymail" name="replymail" value="'.$this->replytomail.'" />';
705  $out.= "<tr><td>".$langs->trans("MailReply")."</td><td>".$this->replytoname.($this->replytomail?(" &lt;".$this->replytomail."&gt;"):"");
706  $out.= "</td></tr>\n";
707  }
708  }
709 
710  // Errorsto
711  if (! empty($this->witherrorsto))
712  {
713  //if (! $this->errorstomail) $this->errorstomail=$this->frommail;
714  $errorstomail = (! empty($conf->global->MAIN_MAIL_ERRORS_TO) ? $conf->global->MAIN_MAIL_ERRORS_TO : $this->errorstomail);
715  if ($this->witherrorstoreadonly)
716  {
717  $out.= '<input type="hidden" id="errorstomail" name="errorstomail" value="'.$errorstomail.'" />';
718  $out.= '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td>';
719  $out.= $errorstomail;
720  $out.= "</td></tr>\n";
721  }
722  else
723  {
724  $out.= '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td>';
725  $out.= '<input size="30" id="errorstomail" name="errorstomail" value="'.$errorstomail.'" />';
726  $out.= "</td></tr>\n";
727  }
728  }
729 
730  // Ask delivery receipt
731  if (! empty($this->withdeliveryreceipt))
732  {
733  $out.= '<tr><td>'.$langs->trans("DeliveryReceipt").'</td><td>';
734 
735  if (! empty($this->withdeliveryreceiptreadonly))
736  {
737  $out.= yn($this->withdeliveryreceipt);
738  }
739  else
740  {
741  $defaultvaluefordeliveryreceipt=0;
742  if (! empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_PROPAL) && ! empty($this->param['models']) && $this->param['models'] == 'propal_send') $defaultvaluefordeliveryreceipt=1;
743  if (! empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_SUPPLIER_PROPOSAL) && ! empty($this->param['models']) && $this->param['models'] == 'supplier_proposal_send') $defaultvaluefordeliveryreceipt=1;
744  if (! empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_ORDER) && ! empty($this->param['models']) && $this->param['models'] == 'order_send') $defaultvaluefordeliveryreceipt=1;
745  if (! empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_INVOICE) && ! empty($this->param['models']) && $this->param['models'] == 'facture_send') $defaultvaluefordeliveryreceipt=1;
746  $out.= $form->selectyesno('deliveryreceipt', (isset($_POST["deliveryreceipt"])?$_POST["deliveryreceipt"]:$defaultvaluefordeliveryreceipt), 1);
747  }
748 
749  $out.= "</td></tr>\n";
750  }
751 
752  // Topic
753  if (! empty($this->withtopic))
754  {
755  $defaulttopic=GETPOST('subject','none');
756  if (! GETPOST('modelselected','alpha') || GETPOST('modelmailselected') != '-1')
757  {
758  if (is_array($arraydefaultmessage) && count($arraydefaultmessage) > 0 && $arraydefaultmessage['topic']) $defaulttopic=$arraydefaultmessage['topic'];
759  elseif (! is_numeric($this->withtopic)) $defaulttopic=$this->withtopic;
760  }
761 
762  $defaulttopic=make_substitutions($defaulttopic,$this->substit);
763 
764  $out.= '<tr>';
765  $out.= '<td class="fieldrequired">'.$langs->trans("MailTopic").'</td>';
766  $out.= '<td>';
767  if ($this->withtopicreadonly)
768  {
769  $out.= $defaulttopic;
770  $out.= '<input type="hidden" class="quatrevingtpercent" id="subject" name="subject" value="'.$defaulttopic.'" />';
771  }
772  else
773  {
774  $out.= '<input type="text" class="quatrevingtpercent" id="subject" name="subject" value="'. ((isset($_POST["subject"]) && ! $_POST['modelselected'])?$_POST["subject"]:($defaulttopic?$defaulttopic:'')) .'" />';
775  }
776  $out.= "</td></tr>\n";
777  }
778 
779  // Attached files
780  if (! empty($this->withfile))
781  {
782  $out.= '<tr>';
783  $out.= '<td>'.$langs->trans("MailFile").'</td>';
784 
785  $out.= '<td>';
786  if (! empty($this->withmaindocfile))
787  {
788  if ($this->withmaindocfile == 1)
789  {
790  $out.='<input type="checkbox" name="addmaindocfile" value="1" />';
791  }
792  if ($this->withmaindocfile == -1)
793  {
794  $out.='<input type="checkbox" name="addmaindocfile" checked="checked" />';
795  }
796  $out.=' '.$langs->trans("JoinMainDoc").'.<br>';
797  }
798 
799  if (is_numeric($this->withfile))
800  {
801  // TODO Trick to have param removedfile containing nb of file to delete. But this does not works without javascript
802  $out.= '<input type="hidden" class="removedfilehidden" name="removedfile" value="">'."\n";
803  $out.= '<script type="text/javascript" language="javascript">';
804  $out.= 'jQuery(document).ready(function () {';
805  $out.= ' jQuery(".removedfile").click(function() {';
806  $out.= ' jQuery(".removedfilehidden").val(jQuery(this).val());';
807  $out.= ' });';
808  $out.= '})';
809  $out.= '</script>'."\n";
810  if (count($listofpaths))
811  {
812  foreach($listofpaths as $key => $val)
813  {
814  $out.= '<div id="attachfile_'.$key.'">';
815  $out.= img_mime($listofnames[$key]).' '.$listofnames[$key];
816  if (! $this->withfilereadonly)
817  {
818  $out.= ' <input type="image" style="border: 0px;" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/delete.png" value="'.($key+1).'" class="removedfile" id="removedfile_'.$key.'" name="removedfile_'.$key.'" />';
819  //$out.= ' <a href="'.$_SERVER["PHP_SELF"].'?removedfile='.($key+1).' id="removedfile_'.$key.'">'.img_delete($langs->trans("Delete").'</a>';
820  }
821  $out.= '<br></div>';
822  }
823  }
824  else if (empty($this->withmaindocfile)) // Do not show message if we asked to show the checkbox
825  {
826  $out.= $langs->trans("NoAttachedFiles").'<br>';
827  }
828  if ($this->withfile == 2) // Can add other files
829  {
830  if (!empty($conf->global->FROM_MAIL_USE_INPUT_FILE_MULTIPLE)) $out.= '<input type="file" class="flat" id="addedfile" name="addedfile[]" value="'.$langs->trans("Upload").'" multiple />';
831  else $out.= '<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans("Upload").'" />';
832  $out.= ' ';
833  $out.= '<input class="button" type="submit" id="'.$addfileaction.'" name="'.$addfileaction.'" value="'.$langs->trans("MailingAddFile").'" />';
834  }
835  }
836  else
837  {
838  $out.=$this->withfile;
839  }
840 
841  $out.= "</td></tr>\n";
842  }
843 
844  // Message
845  if (! empty($this->withbody))
846  {
847  $defaultmessage=GETPOST('message','none');
848  if (! GETPOST('modelselected','alpha') || GETPOST('modelmailselected') != '-1')
849  {
850  if (count($arraydefaultmessage) > 0 && $arraydefaultmessage['content']) $defaultmessage=$arraydefaultmessage['content'];
851  elseif (! is_numeric($this->withbody)) $defaultmessage=$this->withbody;
852  }
853 
854  // Complete substitution array
855  $paymenturl='';
856  if (empty($this->substit['__REF__']))
857  {
858  $paymenturl='';
859  }
860  else
861  {
862  // Set the online payment url link into __ONLINE_PAYMENT_URL__ key
863  require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
864  $langs->load('paypal');
865  $typeforonlinepayment='free';
866  if ($this->param["models"]=='order_send') $typeforonlinepayment='order'; // TODO use detection on something else than template
867  if ($this->param["models"]=='facture_send') $typeforonlinepayment='invoice'; // TODO use detection on something else than template
868  if ($this->param["models"]=='member_send') $typeforonlinepayment='member'; // TODO use detection on something else than template
869  $url=getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit['__REF__']);
870  $paymenturl=$url;
871  }
872 
873  $this->substit['__ONLINE_PAYMENT_URL__']=$paymenturl;
874 
875  //Add lines substitution key from each line
876  $lines = '';
877  $defaultlines = $arraydefaultmessage['content_lines'];
878  if (isset($defaultlines))
879  {
880  foreach ($this->substit_lines as $substit_line)
881  {
882  $lines .= make_substitutions($defaultlines,$substit_line)."\n";
883  }
884  }
885  $this->substit['__LINES__']=$lines;
886 
887  $defaultmessage=str_replace('\n',"\n",$defaultmessage);
888 
889  // Deal with format differences between message and signature (text / HTML)
890  if(dol_textishtml($defaultmessage) && !dol_textishtml($this->substit['__USER_SIGNATURE__'])) {
891  $this->substit['__USER_SIGNATURE__'] = dol_nl2br($this->substit['__USER_SIGNATURE__']);
892  } else if(!dol_textishtml($defaultmessage) && dol_textishtml($this->substit['__USER_SIGNATURE__'])) {
893  $defaultmessage = dol_nl2br($defaultmessage);
894  }
895 
896  if (isset($_POST["message"]) && ! $_POST['modelselected']) $defaultmessage=$_POST["message"];
897  else
898  {
899  $defaultmessage=make_substitutions($defaultmessage,$this->substit);
900  // Clean first \n and br (to avoid empty line when CONTACTCIVNAME is empty)
901  $defaultmessage=preg_replace("/^(<br>)+/","",$defaultmessage);
902  $defaultmessage=preg_replace("/^\n+/","",$defaultmessage);
903  }
904 
905  $out.= '<tr>';
906  $out.= '<td valign="top">'.$langs->trans("MailText").'</td>';
907  $out.= '<td>';
908  if ($this->withbodyreadonly)
909  {
910  $out.= nl2br($defaultmessage);
911  $out.= '<input type="hidden" id="message" name="message" value="'.$defaultmessage.'" />';
912  }
913  else
914  {
915  if (! isset($this->ckeditortoolbar)) $this->ckeditortoolbar = 'dolibarr_notes';
916 
917  // Editor wysiwyg
918  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
919  if ($this->withfckeditor == -1)
920  {
921  if (! empty($conf->global->FCKEDITOR_ENABLE_MAIL)) $this->withfckeditor=1;
922  else $this->withfckeditor=0;
923  }
924 
925  $doleditor=new DolEditor('message',$defaultmessage,'',280,$this->ckeditortoolbar,'In',true,true,$this->withfckeditor,8,'95%');
926  $out.= $doleditor->Create(1);
927  }
928  $out.= "</td></tr>\n";
929  }
930 
931  $out.= '</table>'."\n";
932 
933  if ($this->withform == 1 || $this->withform == -1)
934  {
935  $out.= '<br><div class="center">';
936  $out.= '<input class="button" type="submit" id="sendmail" name="sendmail" value="'.$langs->trans("SendMail").'"';
937  // Add a javascript test to avoid to forget to submit file before sending email
938  if ($this->withfile == 2 && $conf->use_javascript_ajax)
939  {
940  $out.= ' onClick="if (document.mailform.addedfile.value != \'\') { alert(\''.dol_escape_js($langs->trans("FileWasNotUploaded")).'\'); return false; } else { return true; }"';
941  }
942  $out.= ' />';
943  if ($this->withcancel)
944  {
945  $out.= ' &nbsp; &nbsp; ';
946  $out.= '<input class="button" type="submit" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'" />';
947  }
948  $out.= '</div>'."\n";
949  }
950 
951  if ($this->withform == 1) $out.= '</form>'."\n";
952 
953  // Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set
954  if (! empty($conf->global->MAIN_MAILFORM_DISABLE_ENTERKEY))
955  {
956  $out.= '<script type="text/javascript" language="javascript">';
957  $out.= 'jQuery(document).ready(function () {';
958  $out.= ' $(document).on("keypress", \'#mailform\', function (e) { /* Note this is called at every key pressed ! */
959  var code = e.keyCode || e.which;
960  if (code == 13) {
961  e.preventDefault();
962  return false;
963  }
964  });';
965  $out.=' })';
966  $out.= '</script>';
967  }
968 
969  $out.= "<!-- End form mail -->\n";
970 
971  return $out;
972  }
973  }
974 
975 
976 
989  public function getEMailTemplate($db, $type_template, $user, $outputlangs, $id=0, $active=1)
990  {
991  $ret=array();
992 
993  $sql = "SELECT label, topic, joinfiles, content, content_lines, lang";
994  $sql.= " FROM ".MAIN_DB_PREFIX.'c_email_templates';
995  $sql.= " WHERE (type_template='".$db->escape($type_template)."' OR type_template='all')";
996  $sql.= " AND entity IN (".getEntity('c_email_templates', 0).")";
997  $sql.= " AND (private = 0 OR fk_user = ".$user->id.")"; // Get all public or private owned
998  if ($active >= 0) $sql.=" AND active = ".$active;
999  if (is_object($outputlangs)) $sql.= " AND (lang = '".$outputlangs->defaultlang."' OR lang IS NULL OR lang = '')";
1000  if ($id > 0) $sql.= " AND rowid=".$id;
1001  if ($id == -1) $sql.= " AND position=0";
1002  $sql.= $db->order("position,lang,label","ASC");
1003  if ($id == -1) $sql.= $db->plimit(1);
1004  //print $sql;
1005 
1006  $resql = $db->query($sql);
1007  if ($resql)
1008  {
1009  $obj = $db->fetch_object($resql); // Get first found
1010  if ($obj)
1011  {
1012  $ret['label']=$obj->label;
1013  $ret['lang']=$obj->lang;
1014  $ret['topic']=$obj->topic;
1015  $ret['joinfiles']=$obj->joinfiles;
1016  $ret['content']=$obj->content;
1017  $ret['content_lines']=$obj->content_lines;
1018  }
1019  else // If there is no template at all
1020  {
1021  $defaultmessage='';
1022  if ($type_template=='facture_send') { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendInvoice"); }
1023  elseif ($type_template=='facture_relance') { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendInvoiceReminder"); }
1024  elseif ($type_template=='propal_send') { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendProposal"); }
1025  elseif ($type_template=='supplier_proposal_send') { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendSupplierProposal"); }
1026  elseif ($type_template=='order_send') { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendOrder"); }
1027  elseif ($type_template=='order_supplier_send') { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendSupplierOrder"); }
1028  elseif ($type_template=='invoice_supplier_send') { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendSupplierInvoice"); }
1029  elseif ($type_template=='shipping_send') { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendShipping"); }
1030  elseif ($type_template=='fichinter_send') { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendFichInter"); }
1031  elseif ($type_template=='thirdparty') { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentThirdparty"); }
1032  elseif ($type_template=='user') { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentUser"); }
1033 
1034  $ret['label']='default';
1035  $ret['lang']=$outputlangs->defaultlang;
1036  $ret['topic']='';
1037  $ret['joinfiles']=1;
1038  $ret['content']=$defaultmessage;
1039  $ret['content_lines']='';
1040  }
1041 
1042  $db->free($resql);
1043  return $ret;
1044  }
1045  else
1046  {
1047  dol_print_error($db);
1048  return -1;
1049  }
1050  }
1051 
1061  public function isEMailTemplate($type_template, $user, $outputlangs)
1062  {
1063  $ret=array();
1064 
1065  $sql = "SELECT label, topic, content, lang";
1066  $sql.= " FROM ".MAIN_DB_PREFIX.'c_email_templates';
1067  $sql.= " WHERE type_template='".$this->db->escape($type_template)."'";
1068  $sql.= " AND entity IN (".getEntity('c_email_templates', 0).")";
1069  $sql.= " AND (fk_user is NULL or fk_user = 0 or fk_user = ".$user->id.")";
1070  if (is_object($outputlangs)) $sql.= " AND (lang = '".$outputlangs->defaultlang."' OR lang IS NULL OR lang = '')";
1071  $sql.= $this->db->order("lang,label","ASC");
1072  //print $sql;
1073 
1074  $resql = $this->db->query($sql);
1075  if ($resql)
1076  {
1077  $num= $this->db->num_rows($resql);
1078  $this->db->free($resql);
1079  return $num;
1080  }
1081  else
1082  {
1083  $this->error=get_class($this).' '.__METHOD__.' ERROR:'.$this->db->lasterror();
1084  return -1;
1085  }
1086  }
1087 
1098  public function fetchAllEMailTemplate($type_template, $user, $outputlangs, $active=1)
1099  {
1100  $ret=array();
1101 
1102  $sql = "SELECT rowid, label, topic, content, content_lines, lang, fk_user, private, position";
1103  $sql.= " FROM ".MAIN_DB_PREFIX.'c_email_templates';
1104  $sql.= " WHERE type_template IN ('".$this->db->escape($type_template)."', 'all')";
1105  $sql.= " AND entity IN (".getEntity('c_email_templates', 1).")";
1106  $sql.= " AND (private = 0 OR fk_user = ".$user->id.")"; // See all public templates or templates I own.
1107  if ($active >= 0) $sql.=" AND active = ".$active;
1108  //if (is_object($outputlangs)) $sql.= " AND (lang = '".$outputlangs->defaultlang."' OR lang IS NULL OR lang = '')"; // Return all languages
1109  $sql.= $this->db->order("position,lang,label","ASC");
1110  //print $sql;
1111 
1112  $resql = $this->db->query($sql);
1113  if ($resql)
1114  {
1115  $num=$this->db->num_rows($resql);
1116  $this->lines_model=array();
1117  while ($obj = $this->db->fetch_object($resql))
1118  {
1119  $line = new ModelMail();
1120  $line->id=$obj->rowid;
1121  $line->label=$obj->label;
1122  $line->lang=$obj->lang;
1123  $line->fk_user=$obj->fk_user;
1124  $line->private=$obj->private;
1125  $line->position=$obj->position;
1126  $line->topic=$obj->topic;
1127  $line->content=$obj->content;
1128  $line->content_lines=$obj->content_lines;
1129  $this->lines_model[]=$line;
1130  }
1131  $this->db->free($resql);
1132  return $num;
1133  }
1134  else
1135  {
1136  $this->error=get_class($this).' '.__METHOD__.' ERROR:'.$this->db->lasterror();
1137  return -1;
1138  }
1139  }
1140 
1141 
1142 
1151  function setSubstitFromObject($object, $outputlangs)
1152  {
1153  global $conf, $user;
1154 
1155  $parameters=array();
1156  $tmparray=getCommonSubstitutionArray($outputlangs, 0, null, $object);
1157  complete_substitutions_array($tmparray, $outputlangs, null, $parameters);
1158 
1159  $this->substit=$tmparray;
1160 
1161  // Fill substit_lines with each object lines content
1162  if (is_array($object->lines))
1163  {
1164  foreach ($object->lines as $line)
1165  {
1166  $substit_line = array(
1167  '__PRODUCT_REF__' => isset($line->product_ref) ? $line->product_ref : '',
1168  '__PRODUCT_LABEL__' => isset($line->product_label) ? $line->product_label : '',
1169  '__PRODUCT_DESCRIPTION__' => isset($line->product_desc) ? $line->product_desc : '',
1170  '__LABEL__' => isset($line->label) ? $line->label : '',
1171  '__DESCRIPTION__' => isset($line->desc) ? $line->desc : '',
1172  '__DATE_START_YMD__' => dol_print_date($line->date_start, 'day', 0, $outputlangs),
1173  '__DATE_END_YMD__' => dol_print_date($line->date_end, 'day', 0, $outputlangs),
1174  '__QUANTITY__' => $line->qty,
1175  '__SUBPRICE__' => price($line->subprice),
1176  '__AMOUNT__' => price($line->total_ttc),
1177  '__AMOUNT_EXCL_TAX__' => price($line->total_ht),
1178  //'__PRODUCT_EXTRAFIELD_FIELD__' Done dinamically just after
1179  );
1180 
1181  // Create dynamic tags for __PRODUCT_EXTRAFIELD_FIELD__
1182  if (!empty($line->fk_product))
1183  {
1184  $extrafields = new ExtraFields($this->db);
1185  $extralabels = $extrafields->fetch_name_optionals_label('product', true);
1186  $product = new Product($this->db);
1187  $product->fetch($line->fk_product, '', '', 1);
1188  $product->fetch_optionals($product->id, $extralabels);
1189  foreach ($extrafields->attribute_label as $key => $label) {
1190  $substit_line['__PRODUCT_EXTRAFIELD_' . strtoupper($key) . '__'] = $product->array_options['options_' . $key];
1191  }
1192  }
1193  $this->substit_lines[] = $substit_line;
1194  }
1195  }
1196  }
1197 
1206  static function getAvailableSubstitKey($mode='formemail', $object=null)
1207  {
1208  global $conf, $langs;
1209 
1210  $tmparray=array();
1211  if ($mode == 'formemail' || $mode == 'formemailwithlines' || $mode == 'formemailforlines')
1212  {
1213  $parameters=array('mode'=>$mode);
1214  $tmparray=getCommonSubstitutionArray($langs, 2, null, $object); // Note: On email templated edition, this is null because it is related to all type of objects
1215  complete_substitutions_array($tmparray, $langs, null, $parameters);
1216 
1217  if ($mode == 'formwithlines')
1218  {
1219  $tmparray['__LINES__'] = '__LINES__'; // Will be set by the get_form function
1220  }
1221  if ($mode == 'formforlines')
1222  {
1223  $tmparray['__QUANTITY__'] = '__QUANTITY__'; // Will be set by the get_form function
1224  }
1225  }
1226 
1227  if ($mode == 'emailing')
1228  {
1229  $parameters=array('mode'=>$mode);
1230  $tmparray=getCommonSubstitutionArray($langs, 2, array('object','objectamount'), $object); // Note: On email templated edition, this is null because it is related to all type of objects
1231  complete_substitutions_array($tmparray, $langs, null, $parameters);
1232 
1233  // For mass emailing, we have different keys
1234  $tmparray['__ID__'] = 'IdRecord';
1235  $tmparray['__EMAIL__'] = 'EMailRecipient';
1236  $tmparray['__LASTNAME__'] = 'Lastname';
1237  $tmparray['__FIRSTNAME__'] = 'Firstname';
1238  $tmparray['__MAILTOEMAIL__'] = 'TagMailtoEmail';
1239  $tmparray['__OTHER1__'] = 'Other1';
1240  $tmparray['__OTHER2__'] = 'Other2';
1241  $tmparray['__OTHER3__'] = 'Other3';
1242  $tmparray['__OTHER4__'] = 'Other4';
1243  $tmparray['__OTHER5__'] = 'Other5';
1244  $tmparray['__USER_SIGNATURE__'] = 'TagSignature';
1245  $tmparray['__CHECK_READ__'] = 'TagCheckMail';
1246  $tmparray['__UNSUBSCRIBE__'] = 'TagUnsubscribe';
1247  //,'__PERSONALIZED__' => 'Personalized' // Hidden because not used yet in mass emailing
1248 
1249  $onlinepaymentenabled = 0;
1250  if (! empty($conf->paypal->enabled)) $onlinepaymentenabled++;
1251  if (! empty($conf->paybox->enabled)) $onlinepaymentenabled++;
1252  if (! empty($conf->stripe->enabled)) $onlinepaymentenabled++;
1253  if ($onlinepaymentenabled && ! empty($conf->global->PAYMENT_SECURITY_TOKEN))
1254  {
1255  $tmparray['__SECUREKEYPAYMENT__']=$conf->global->PAYMENT_SECURITY_TOKEN;
1256  if (! empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE))
1257  {
1258  if ($conf->adherent->enabled) $tmparray['__SECUREKEYPAYMENT_MEMBER__']='SecureKeyPAYMENTUniquePerMember';
1259  if ($conf->facture->enabled) $tmparray['__SECUREKEYPAYMENT_INVOICE__']='SecureKeyPAYMENTUniquePerInvoice';
1260  if ($conf->commande->enabled) $tmparray['__SECUREKEYPAYMENT_ORDER__']='SecureKeyPAYMENTUniquePerOrder';
1261  if ($conf->contrat->enabled) $tmparray['__SECUREKEYPAYMENT_CONTRACTLINE__']='SecureKeyPAYMENTUniquePerContractLine';
1262  }
1263  }
1264  else
1265  {
1266  /* No need to show into tooltip help, option is not enabled
1267  $vars['__SECUREKEYPAYMENT__']='';
1268  $vars['__SECUREKEYPAYMENT_MEMBER__']='';
1269  $vars['__SECUREKEYPAYMENT_INVOICE__']='';
1270  $vars['__SECUREKEYPAYMENT_ORDER__']='';
1271  $vars['__SECUREKEYPAYMENT_CONTRACTLINE__']='';
1272  */
1273  }
1274  }
1275 
1276  $tmparray['__(AnyTranslationKey)__']="Translation";
1277 
1278  foreach($tmparray as $key => $val)
1279  {
1280  if (empty($val)) $tmparray[$key]=$key;
1281  }
1282 
1283  return $tmparray;
1284  }
1285 
1286 }
1287 
1288 
1292 class ModelMail
1293 {
1294  public $id;
1295  public $label;
1296  public $topic;
1297  public $content;
1298  public $content_lines;
1299  public $lang;
1300 }
Classe permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new For...
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
__construct($db)
Constructor.
img_mime($file, $titlealt= '', $morecss='')
Show MIME img of a file.
get_form($addfileaction='addfile', $removefileaction='removefile')
Get the form to input an email this->withfile: 0=No attaches files, 1=Show attached files...
Class to manage contact/addresses.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return mime type of a file.
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
background position
Definition: style.css.php:368
show_form($addfileaction='addfile', $removefileaction='removefile')
Show the form to input an email this->withfile: 0=No attaches files, 1=Show attached files...
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
static selectarray($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $moreparam='', $translate=0, $maxlen=0, $disabled=0, $sort='', $morecss='', $addjscombo=0, $moreparamonempty='', $disablebademail=0, $nohtmlescape=0)
Return a HTML select string, built from an array of key+value.
Class to manage generation of HTML components Only common components must be here.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1')
Show information for admin users or standard users.
Class to manage third parties objects (customers, suppliers, prospects...)
getEMailTemplate($db, $type_template, $user, $outputlangs, $id=0, $active=1)
Return templates of email with type = $type_template or type = 'all'.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories) ...
Definition: files.lib.php:1234
fetchAllEMailTemplate($type_template, $user, $outputlangs, $active=1)
Find if template exists and are available for current user, then set them into $this->lines_module.
Class to manage translations.
remove_attached_files($keytodelete)
Remove a file from the list of attached files (stored in SECTION array)
get_attached_files()
Return list of attached files (stored in SECTION array)
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8')
Clean a string from all HTML tags and entities.
print
Draft customers invoices.
Definition: index.php:91
clear_attached_files()
Clear list of attached files in send mail form (also stored in session)
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
Class to manage a WYSIWYG editor.
make_substitutions($text, $substitutionarray, $outputlangs=null)
Make substition into a text string, replacing keys with vals from $substitutionarray (oldval=>newval)...
dol_htmlentities($string, $flags=null, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
add_attached_files($path, $file, $type)
Add a file into the list of attached files (stored in SECTION array)
dol_textishtml($msg, $option=0)
Return if a text is a html content.