dolibarr  7.0.0-beta
card_presend.tpl.php
1 <?php
2 /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  * or see http://www.gnu.org/
17  */
18 
19 /*
20  * Code to ouput content when action is presend
21  *
22  * $trackid must be defined
23  * $modelmail
24  * $defaulttopic
25  * $diroutput
26  */
27 
28 // Protection to avoid direct call of template
29 if (empty($conf) || ! is_object($conf))
30 {
31  print "Error, template page can't be called as URL";
32  exit;
33 }
34 
35 
36 if ($action == 'presend')
37 {
38  $langs->load("mails");
39 
40  $titreform='SendMail';
41 
42  $object->fetch_projet();
43 
44  if (! in_array($object->element, array('societe', 'user', 'member')))
45  {
46  // TODO get also the main_lastdoc field of $object. If not found, try to guess with following code
47 
48  $ref = dol_sanitizeFileName($object->ref);
49  include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
50  $fileparams = dol_most_recent_file($diroutput . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
51  //
52  if ($object->element == 'invoice_supplier')
53  {
54  $fileparams = dol_most_recent_file($diroutput . '/' . get_exdir($object->id,2,0,0,$object,$object->element).$ref, preg_quote($ref,'/').'([^\-])+');
55  }
56 
57  $file = $fileparams['fullname'];
58  }
59 
60  // Define output language
61  $outputlangs = $langs;
62  $newlang = '';
63  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id']))
64  {
65  $newlang = $_REQUEST['lang_id'];
66  }
67  if ($conf->global->MAIN_MULTILANGS && empty($newlang))
68  {
69  $newlang = $object->thirdparty->default_lang;
70  }
71 
72  if (!empty($newlang))
73  {
74  $outputlangs = new Translate('', $conf);
75  $outputlangs->setDefaultLang($newlang);
76  $outputlangs->loadLangs(array('commercial','bills','orders','contracts','members','propal','supplier_proposal','interventions'));
77  }
78 
79  $topicmail='';
80  if (empty($object->ref_client)) {
81  $topicmail = $outputlangs->trans($defaulttopic, '__REF__');
82  } else if (! empty($object->ref_client)) {
83  $topicmail = $outputlangs->trans($defaulttopic, '__REF__ (__REFCLIENT__)');
84  }
85 
86  // Build document if it not exists
87  if (! in_array($object->element, array('societe', 'user', 'member')))
88  {
89  if ((! $file || ! is_readable($file)) && method_exists($object, 'generateDocument'))
90  {
91  $result = $object->generateDocument(GETPOST('model') ? GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
92  if ($result <= 0) {
93  dol_print_error($db, $object->error, $object->errors);
94  exit();
95  }
96  $fileparams = dol_most_recent_file($diroutput . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
97  $file = $fileparams['fullname'];
98  }
99  }
100 
101  print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
102  print '<div class="clearboth"></div>';
103  print '<br>';
104  print load_fiche_titre($langs->trans($titreform));
105 
106  dol_fiche_head('');
107 
108  // Create form for email
109  include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
110  $formmail = new FormMail($db);
111  $formmail->param['langsmodels']=(empty($newlang)?$langs->defaultlang:$newlang);
112  $formmail->fromtype = (GETPOST('fromtype')?GETPOST('fromtype'):(!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE)?$conf->global->MAIN_MAIL_DEFAULT_FROMTYPE:'user'));
113 
114  if ($formmail->fromtype === 'user')
115  {
116  $formmail->fromid = $user->id;
117  }
118  $formmail->trackid=$trackid;
119  if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2)) // If bit 2 is set
120  {
121  include DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
122  $formmail->frommail=dolAddEmailTrackId($formmail->frommail, $trackid);
123  }
124  $formmail->withfrom = 1;
125 
126  // Fill list of recipient with email inside <>.
127  $liste = array();
128  if ($object->element == 'expensereport')
129  {
130  $fuser = new User($db);
131  $fuser->fetch($object->fk_user_author);
132  $liste['thirdparty'] = $fuser->getFullName($langs)." <".$fuser->email.">";
133  }
134  elseif ($object->element == 'societe')
135  {
136  foreach ($object->thirdparty_and_contact_email_array(1) as $key => $value) {
137  $liste[$key] = $value;
138  }
139  }
140  elseif ($object->element == 'user' || $object->element == 'member')
141  {
142  $liste['thirdparty'] = $object->getFullName($langs)." <".$object->email.">";
143  }
144  else
145  {
146  foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key => $value) {
147  $liste[$key] = $value;
148  }
149  }
150 
151  $formmail->withto = GETPOST('sendto') ? GETPOST('sendto') : $liste;
152  $formmail->withtocc = $liste;
153  $formmail->withtoccc = $conf->global->MAIN_EMAIL_USECCC;
154  $formmail->withtopic = $topicmail;
155  $formmail->withfile = 2;
156  $formmail->withbody = 1;
157  $formmail->withdeliveryreceipt = 1;
158  $formmail->withcancel = 1;
159 
160  // Make substitution in email content
161  $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
162  $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"/>' : '';
163  $substitutionarray['__PERSONALIZED__'] = ''; // deprecated
164  $substitutionarray['__CONTACTCIVNAME__'] = '';
165  $parameters = array(
166  'mode' => 'formemail'
167  );
168  complete_substitutions_array($substitutionarray, $outputlangs, $object, $parameters);
169 
170  // Tableau des substitutions
171  $formmail->substit = $substitutionarray;
172 
173  // Tableau des parametres complementaires
174  $formmail->param['action'] = 'send';
175  $formmail->param['models'] = $modelmail;
176  $formmail->param['models_id']=GETPOST('modelmailselected','int');
177  $formmail->param['id'] = $object->id;
178  $formmail->param['returnurl'] = $_SERVER["PHP_SELF"] . '?id=' . $object->id;
179  $formmail->param['fileinit'] = array($file);
180 
181  // Init list of files
182  /*if (GETPOST('mode','alpha') == 'init')
183  {
184  $formmail->clear_attached_files();
185 
186  $formmail->add_attached_files($file, basename($file), dol_mimetype($file));
187  }*/
188 
189  // Show form
190  print $formmail->get_form();
191 
192  dol_fiche_end();
193 }
194 
Classe permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new For...
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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 Dolibarr users.
Definition: user.class.php:39
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
dol_fiche_end($notab=0)
Show tab footer of a card.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_most_recent_file($dir, $regexfilter='', $excludefilter=array('(\.meta|_preview.*\.png)$','^\.'), $nohook=false, $mode='')
Return file(s) into a directory (by default most recent)
Definition: files.lib.php:1952
Class to manage translations.
print
Draft customers invoices.
Definition: index.php:91
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...