dolibarr  9.0.0
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 == 'predeletedraft')
31 {
32  print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassDraftDeletion"), $langs->trans("ConfirmMassDeletionQuestion", count($toselect)), "delete", null, '', 0, 200, 500, 1);
33 }
34 
35 if ($massaction == 'predelete')
36 {
37  print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassDeletion"), $langs->trans("ConfirmMassDeletionQuestion", count($toselect)), "delete", null, '', 0, 200, 500, 1);
38 }
39 
40 if ($massaction == 'presend')
41 {
42  $langs->load("mails");
43 
44  $listofselectedid = array();
45  $listofselectedthirdparties = array();
46  $listofselectedref = array();
47 
48  if (! GETPOST('cancel', 'alpha'))
49  {
50  foreach ($arrayofselected as $toselectid)
51  {
52  $result = $objecttmp->fetch($toselectid);
53  if ($result > 0)
54  {
55  $listofselectedid[$toselectid] = $toselectid;
56  $thirdpartyid = ($objecttmp->fk_soc ? $objecttmp->fk_soc : $objecttmp->socid);
57  if ($objecttmp->element == 'societe')
58  $thirdpartyid = $objecttmp->id;
59  if ($objecttmp->element == 'expensereport')
60  $thirdpartyid = $objecttmp->fk_user_author;
61  $listofselectedthirdparties[$thirdpartyid] = $thirdpartyid;
62  $listofselectedref[$thirdpartyid][$toselectid] = $objecttmp->ref;
63  }
64  }
65  }
66 
67  print '<input type="hidden" name="massaction" value="confirm_presend">';
68 
69  include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
70  $formmail = new FormMail($db);
71 
72  dol_fiche_head(null, '', '');
73 
74  // Cree l'objet formulaire mail
75  include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
76  $formmail = new FormMail($db);
77  $formmail->withform = -1;
78  $formmail->fromtype = (GETPOST('fromtype') ? GETPOST('fromtype') : (! empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE) ? $conf->global->MAIN_MAIL_DEFAULT_FROMTYPE : 'user'));
79 
80  if ($formmail->fromtype === 'user')
81  {
82  $formmail->fromid = $user->id;
83  }
84  $formmail->trackid = $trackid;
85  if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2)) // If bit 2 is set
86  {
87  include DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
88  $formmail->frommail = dolAddEmailTrackId($formmail->frommail, $trackid);
89  }
90  $formmail->withfrom = 1;
91  $liste = $langs->trans("AllRecipientSelected", count($arrayofselected));
92  if (count($listofselectedthirdparties) == 1) // Only 1 different recipient selected, we can suggest contacts
93  {
94  $liste = array();
95  $thirdpartyid = array_shift($listofselectedthirdparties);
96  if ($objecttmp->element == 'expensereport')
97  {
98  $fuser = new User($db);
99  $fuser->fetch($thirdpartyid);
100  $liste['thirdparty'] = $fuser->getFullName($langs)." &lt;".$fuser->email."&gt;";
101  }
102  else
103  {
104  $soc = new Societe($db);
105  $soc->fetch($thirdpartyid);
106  foreach ($soc->thirdparty_and_contact_email_array(1) as $key => $value) {
107  $liste[$key] = $value;
108  }
109  }
110  $formmail->withtoreadonly = 0;
111  } else {
112  $formmail->withtoreadonly = 1;
113  }
114 
115  $formmail->withoptiononeemailperrecipient = (count($listofselectedref) == 1 || empty($liste))? 0 : ((GETPOST('oneemailperrecipient')=='on')?1:-1);
116  $formmail->withto = empty($liste)?(GETPOST('sendto','alpha')?GETPOST('sendto','alpha'):array()):$liste;
117  $formmail->withtofree = empty($liste)?1:0;
118  $formmail->withtocc = 1;
119  $formmail->withtoccc = $conf->global->MAIN_EMAIL_USECCC;
120  $formmail->withtopic = $langs->transnoentities($topicmail, '__REF__', '__REFCLIENT__');
121  $formmail->withfile = 1;
122  // $formmail->withfile = 2; Not yet supported in mass action
123  $formmail->withmaindocfile = 1; // Add a checkbox "Attach also main document"
124  if ($objecttmp->element != 'societe') {
125  $formmail->withfile = '<span class="hideonsmartphone">'.$langs->trans("OnlyPDFattachmentSupported").'</span>';
126  $formmail->withmaindocfile = - 1; // Add a checkbox "Attach also main document" but not checked by default
127  }
128  $formmail->withbody = 1;
129  $formmail->withdeliveryreceipt = 1;
130  $formmail->withcancel = 1;
131 
132  // Make substitution in email content
133  $substitutionarray = getCommonSubstitutionArray($langs, 0, null, $object);
134 
135  $substitutionarray['__EMAIL__'] = $sendto;
136  $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"/>' : '';
137  $substitutionarray['__PERSONALIZED__'] = ''; // deprecated
138  $substitutionarray['__CONTACTCIVNAME__'] = '';
139 
140  $parameters = array(
141  'mode' => 'formemail'
142  );
143  complete_substitutions_array($substitutionarray, $langs, $object, $parameters);
144 
145  // Tableau des substitutions
146  $formmail->substit = $substitutionarray;
147 
148  // Tableau des parametres complementaires du post
149  $formmail->param['action'] = $action;
150  $formmail->param['models'] = $modelmail;
151  $formmail->param['models_id'] = GETPOST('modelmailselected', 'int');
152  $formmail->param['id'] = join(',', $arrayofselected);
153  // $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id;
154  if (! empty($conf->global->MAILING_LIMIT_SENDBYWEB) && count($listofselectedthirdparties) > $conf->global->MAILING_LIMIT_SENDBYWEB)
155  {
156  $langs->load("errors");
157  print img_warning() . ' ' . $langs->trans('WarningNumberOfRecipientIsRestrictedInMassAction', $conf->global->MAILING_LIMIT_SENDBYWEB);
158  print ' - <a href="javascript: window.history.go(-1)">' . $langs->trans("GoBack") . '</a>';
159  $arrayofmassactions = array();
160  }
161  else
162  {
163  print $formmail->get_form();
164  }
165 
166  dol_fiche_end();
167 }
img_warning($titlealt='default', $moreatt='')
Show warning logo.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Classe permettant la generation du formulaire html d&#39;envoi de mail unitaire Usage: $formail = new For...
print
Draft customers invoices.
Definition: index.php:91
Class to manage Dolibarr users.
Definition: user.class.php:41
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...)
dol_fiche_end($notab=0)
Show tab footer of a card.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header 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...