dolibarr  7.0.0-beta
massactions_pre.tpl.php
1 <?php
2 /* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
3  * Copyright (C) 2013-2014 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  * or see http://www.gnu.org/
19  */
20 
21 // Following var must be set:
22 // $arrayofselected = array of id selected
23 // $object
24 // $objecttmp=new Propal($db);
25 // $topicmail="SendSupplierProposalRef";
26 // $modelmail="supplier_proposal_send";
27 // $trackid='ord'.$object->id;
28 
29 
30 if ($massaction == 'predelete')
31 {
32  print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassDeletion"), $langs->trans("ConfirmMassDeletionQuestion", count($toselect)), "delete", null, '', 0, 200, 500, 1);
33 }
34 
35 if ($massaction == 'presend')
36 {
37  $langs->load("mails");
38 
39  if (! GETPOST('cancel', 'alpha'))
40  {
41  $listofselectedid = array();
42  $listofselectedthirdparties = array();
43  $listofselectedref = array();
44  foreach ($arrayofselected as $toselectid)
45  {
46  $result = $objecttmp->fetch($toselectid);
47  if ($result > 0)
48  {
49  $listofselectedid[$toselectid] = $toselectid;
50  $thirdpartyid = ($objecttmp->fk_soc ? $objecttmp->fk_soc : $objecttmp->socid);
51  if ($objecttmp->element == 'societe')
52  $thirdpartyid = $objecttmp->id;
53  if ($objecttmp->element == 'expensereport')
54  $thirdpartyid = $objecttmp->fk_user_author;
55  $listofselectedthirdparties[$thirdpartyid] = $thirdpartyid;
56  $listofselectedref[$thirdpartyid][$toselectid] = $objecttmp->ref;
57  }
58  }
59  }
60 
61  print '<input type="hidden" name="massaction" value="confirm_presend">';
62 
63  include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
64  $formmail = new FormMail($db);
65 
66  dol_fiche_head(null, '', '');
67 
68  // Cree l'objet formulaire mail
69  include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
70  $formmail = new FormMail($db);
71  $formmail->withform = -1;
72  $formmail->fromtype = (GETPOST('fromtype') ? GETPOST('fromtype') : (! empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE) ? $conf->global->MAIN_MAIL_DEFAULT_FROMTYPE : 'user'));
73 
74  if ($formmail->fromtype === 'user')
75  {
76  $formmail->fromid = $user->id;
77  }
78  $formmail->trackid = $trackid;
79  if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2)) // If bit 2 is set
80  {
81  include DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
82  $formmail->frommail = dolAddEmailTrackId($formmail->frommail, $trackid);
83  }
84  $formmail->withfrom = 1;
85  $liste = $langs->trans("AllRecipientSelected", count($arrayofselected));
86  if (count($listofselectedthirdparties) == 1) // Only 1 different recipient selected, we can suggest contacts
87  {
88  $liste = array();
89  $thirdpartyid = array_shift($listofselectedthirdparties);
90  if ($objecttmp->element == 'expensereport')
91  {
92  $fuser = new User($db);
93  $fuser->fetch($thirdpartyid);
94  $liste['thirdparty'] = $fuser->getFullName($langs)." &lt;".$fuser->email."&gt;";
95  }
96  else
97  {
98  $soc = new Societe($db);
99  $soc->fetch($thirdpartyid);
100  foreach ($soc->thirdparty_and_contact_email_array(1) as $key => $value) {
101  $liste[$key] = $value;
102  }
103  }
104  $formmail->withtoreadonly = 0;
105  } else {
106  $formmail->withtoreadonly = 1;
107  }
108 
109  $formmail->withoptiononeemailperrecipient = empty($liste)?0:((GETPOST('oneemailperrecipient')=='on')?1:-1);
110  $formmail->withto = empty($liste)?(GETPOST('sendto','alpha')?GETPOST('sendto','alpha'):array()):$liste;
111  $formmail->withtofree = empty($liste)?1:0;
112  $formmail->withtocc = 1;
113  $formmail->withtoccc = $conf->global->MAIN_EMAIL_USECCC;
114  $formmail->withtopic = $langs->transnoentities($topicmail, '__REF__', '__REFCLIENT__');
115  $formmail->withfile = 1;
116  // $formmail->withfile = 2; Not yet supported in mass action
117  $formmail->withmaindocfile = 1; // Add a checkbox "Attach also main document"
118  if ($objecttmp->element != 'societe') {
119  $formmail->withfile = '<span class="hideonsmartphone">'.$langs->trans("OnlyPDFattachmentSupported").'</span>';
120  $formmail->withmaindocfile = - 1; // Add a checkbox "Attach also main document" but not checked by default
121  }
122  $formmail->withbody = 1;
123  $formmail->withdeliveryreceipt = 1;
124  $formmail->withcancel = 1;
125 
126  // Make substitution in email content
127  $substitutionarray = getCommonSubstitutionArray($langs, 0, null, $object);
128  $substitutionarray['__EMAIL__'] = $sendto;
129  $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"/>' : '';
130  $substitutionarray['__PERSONALIZED__'] = ''; // deprecated
131  $substitutionarray['__CONTACTCIVNAME__'] = '';
132 
133  $parameters = array(
134  'mode' => 'formemail'
135  );
136  complete_substitutions_array($substitutionarray, $langs, $object, $parameters);
137 
138  // Tableau des substitutions
139  $formmail->substit = $substitutionarray;
140 
141  // Tableau des parametres complementaires du post
142  $formmail->param['action'] = $action;
143  $formmail->param['models'] = $modelmail;
144  $formmail->param['models_id'] = GETPOST('modelmailselected', 'int');
145  $formmail->param['id'] = join(',', $arrayofselected);
146  // $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id;
147  if (! empty($conf->global->MAILING_LIMIT_SENDBYWEB) && count($listofselectedthirdparties) > $conf->global->MAILING_LIMIT_SENDBYWEB)
148  {
149  $langs->load("errors");
150  print img_warning() . ' ' . $langs->trans('WarningNumberOfRecipientIsRestrictedInMassAction', $conf->global->MAILING_LIMIT_SENDBYWEB);
151  print ' - <a href="javascript: window.history.go(-1)">' . $langs->trans("GoBack") . '</a>';
152  $arrayofmassactions = array();
153  }
154  else
155  {
156  print $formmail->get_form();
157  }
158 
159  dol_fiche_end();
160 }
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.
Class to manage Dolibarr users.
Definition: user.class.php:39
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.
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.
Class to manage third parties objects (customers, suppliers, prospects...)
img_warning($titlealt= 'default', $moreatt= '')
Show warning logo.
dol_fiche_end($notab=0)
Show tab footer of a card.
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...