dolibarr  19.0.0-dev
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 <https://www.gnu.org/licenses/>.
18  * or see https://www.gnu.org/
19  */
20 
21 // Following var must be set:
22 // $action
23 // $arrayofselected = array of id selected
24 // $objecttmp = new MyObject($db);
25 // $topicmail="SendSupplierProposalRef";
26 // $modelmail="supplier_proposal_send";
27 // $trackid='ord'.$objecttmp->id;
28 //
29 // Following var can be set
30 // $object = Object fetched;
31 // $sendto
32 // $withmaindocfilemail
33 
34 
35 if ($massaction == 'predeletedraft') {
36  print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassDraftDeletion"), $langs->trans("ConfirmMassDeletionQuestion", count($toselect)), "delete", null, '', 0, 200, 500, 1);
37 }
38 
39 if ($massaction == 'predelete') {
40  print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassDeletion"), $langs->trans("ConfirmMassDeletionQuestion", count($toselect)), "delete", null, '', 0, 200, 500, 1);
41 }
42 
43 if ($massaction == 'preclonetasks') {
44  $selected = '';
45  foreach (GETPOST('toselect') as $tmpselected) {
46  $selected .= '&selected[]=' . $tmpselected;
47  }
48 
49  $formquestion = array(
50  array('type' => 'other', 'name' => 'projectid', 'label' => $langs->trans('Project') .': ', 'value' => $form->selectProjects('', 'projectid', '', '', '', '', '', '', '', 1, 1)),
51  );
52  print $form->formconfirm($_SERVER['PHP_SELF'] . '?id=' . $object->id . $selected, $langs->trans('ConfirmMassClone'), '', 'clonetasks', $formquestion, '', 1, 300, 590);
53 }
54 
55 if ($massaction == 'preaffecttag' && isModEnabled('category')) {
56  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
57  $categ = new Categorie($db);
58  $categ_types = array();
59  $categ_type_array = $categ->getMapList();
60  foreach ($categ_type_array as $categdef) {
61  // Test on $object (should be useless, we already check on $objecttmp just after)
62  if (isset($object) && $categdef['obj_table'] == $object->table_element) {
63  if (!array_key_exists($categdef['code'], $categ_types)) {
64  $categ_types[$categdef['code']] = array('code'=>$categdef['code'], 'label'=>$langs->trans($categdef['obj_class']));
65  }
66  }
67  if (isset($objecttmp) && $categdef['obj_table'] == $objecttmp->table_element) {
68  if (!array_key_exists($categdef['code'], $categ_types)) {
69  $categ_types[$categdef['code']] = array('code'=>$categdef['code'], 'label'=>$langs->trans($categdef['obj_class']));
70  }
71  }
72  }
73 
74  $formquestion = array();
75  if (!empty($categ_types)) {
76  foreach ($categ_types as $categ_type) {
77  $categ_arbo_tmp = $form->select_all_categories($categ_type['code'], null, 'parent', null, null, 2);
78  $formquestion[] = array(
79  'type' => 'other',
80  'name' => 'affecttag_'.$categ_type['code'],
81  'label' => '',
82  'value' => $form->multiselectarray('contcats_'.$categ_type['code'], $categ_arbo_tmp, GETPOST('contcats_'.$categ_type['code'], 'array'), null, null, '', 0, '60%', '', '', $langs->trans("SelectTheTagsToAssign"))
83  );
84  }
85  $formquestion[] = array(
86  'type' => 'other',
87  'name' => 'affecttag_type',
88  'label' => '',
89  'value' => '<input type="hidden" name="affecttag_type" id="affecttag_type" value="'.implode(",", array_keys($categ_types)).'"/>'
90  );
91  print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmAffectTag"), $langs->trans("ConfirmAffectTagQuestion", count($toselect)), "affecttag", $formquestion, 1, 0, 200, 500, 1);
92  } else {
93  setEventMessage('CategTypeNotFound');
94  }
95 }
96 
97 if ($massaction == 'preupdateprice' && isModEnabled('category')) {
98  $formquestion = array();
99 
100  $valuefield = '<div style="display: flex; align-items: center; justify-content: flex-end; padding-right: 150px">';
101  $valuefield .= '<input type="number" name="pricerate" id="pricerate" min="-100" value="0" style="width: 100px; text-align: right; margin-right: 10px" />%';
102  $valuefield .= '</div>';
103 
104  $formquestion[] = array(
105  'type' => 'other',
106  'name' => 'pricerate',
107  'label' => $langs->trans("Rate"),
108  'value' => $valuefield
109  );
110 
111  print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmUpdatePrice"), $langs->trans("ConfirmUpdatePriceQuestion", count($toselect)), "updateprice", $formquestion, 1, 0, 200, 500, 1);
112 }
113 
114 if ($massaction == 'presetsupervisor') {
115  $formquestion = array();
116 
117  $valuefield = '<div style="display: flex; align-items: center; justify-content: flex-end; padding-right: 150px">';
118  $valuefield .= img_picto('', 'user').' ';
119  $valuefield .= $form->select_dolusers('', 'supervisortoset', 1, $arrayofselected, 0, '', 0, $object->entity, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
120  $valuefield .= '</div>';
121 
122  $formquestion[] = array(
123  'type' => 'other',
124  'name' => 'supervisortoset',
125  'label' => $langs->trans("Supervisor"),
126  'value' => $valuefield
127  );
128 
129  print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmSetSupervisor"), $langs->trans("ConfirmSetSupervisorQuestion", count($toselect)), "setsupervisor", $formquestion, 1, 0, 200, 500, 1);
130 }
131 
132 if ($massaction == 'preaffectuser') {
133  $formquestion = array();
134 
135  $valuefielduser = '<div style="display: flex; align-items: center; justify-content: flex-end; padding-right: 165px; padding-bottom: 6px; gap: 5px">';
136  $valuefielduser .= img_picto('', 'user').' ';
137  $valuefielduser .= $form->select_dolusers('', 'usertoaffect', 1, $arrayofselected, 0, '', 0, $object->entity, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
138  $valuefielduser .= '</div>';
139 
140  $valuefieldprojrole = '<div style="display: flex; align-items: center; justify-content: flex-end; padding-right: 150px; padding-bottom: 6px">';
141  $valuefieldprojrole .= $formcompany->selectTypeContact($object, '', 'projectrole', 'internal', 'position', 0, 'widthcentpercentminusx maxwidth300', 0);
142  $valuefieldprojrole .= '</div>';
143 
144  $valuefieldtasksrole = '<div style="display: flex; align-items: center; justify-content: flex-end; padding-right: 150px">';
145  $valuefieldtasksrole .= $formcompany->selectTypeContact($taskstatic, '', 'tasksrole', 'internal', 'position', 0, 'widthcentpercentminusx maxwidth300', 0);
146  $valuefieldtasksrole .= '</div>';
147 
148  $formquestion[] = array(
149  'type' => 'other',
150  'name' => 'usertoaffect',
151  'label' => $langs->trans("User"),
152  'value' => $valuefielduser
153  );
154  $formquestion[] = array(
155  'type' => 'other',
156  'name' => 'projectrole',
157  'label' => $langs->trans("ProjectRole"),
158  'value' => $valuefieldprojrole
159  );
160 
161  $formquestion[] = array(
162  'type' => 'other',
163  'name' => 'tasksrole',
164  'label' => $langs->trans("TasksRole"),
165  'value' => $valuefieldtasksrole
166  );
167 
168  print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmAffectUser"), $langs->trans("ConfirmAffectUserQuestion", count($toselect)), "affectuser", $formquestion, 1, 0, 200, 500, 1);
169 }
170 
171 if ($massaction == 'presend') {
172  $langs->load("mails");
173 
174  $listofselectedid = array();
175  $listofselectedrecipientobjid = array();
176  $listofselectedref = array();
177 
178  if (!GETPOST('cancel', 'alpha')) {
179  foreach ($arrayofselected as $toselectid) {
180  $result = $objecttmp->fetch($toselectid);
181  if ($result > 0) {
182  $listofselectedid[$toselectid] = $toselectid;
183  $thirdpartyid = ($objecttmp->fk_soc ? $objecttmp->fk_soc : $objecttmp->socid); // For proposal, order, invoice, conferenceorbooth, ...
184  if (in_array($objecttmp->element, array('societe', 'conferenceorboothattendee'))) {
185  $thirdpartyid = $objecttmp->id;
186  } elseif ($objecttmp->element == 'contact') {
187  $thirdpartyid = $objecttmp->id;
188  } elseif ($objecttmp->element == 'expensereport') {
189  $thirdpartyid = $objecttmp->fk_user_author;
190  }
191  if (empty($thirdpartyid)) {
192  $thirdpartyid = 0;
193  }
194  if ($thirdpartyid) {
195  $listofselectedrecipientobjid[$thirdpartyid] = $thirdpartyid;
196  }
197  $listofselectedref[$thirdpartyid][$toselectid] = $objecttmp->ref;
198  }
199  }
200  }
201 
202  print '<input type="hidden" name="massaction" value="confirm_presend">';
203 
204  print dol_get_fiche_head(null, '', '');
205 
206  // Create mail form
207  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
208  $formmail = new FormMail($db);
209  $formmail->withform = -1;
210  $formmail->fromtype = (GETPOST('fromtype') ? GETPOST('fromtype') : (!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE) ? $conf->global->MAIN_MAIL_DEFAULT_FROMTYPE : 'user'));
211 
212  if ($formmail->fromtype === 'user') {
213  $formmail->fromid = $user->id;
214  }
215  $formmail->trackid = $trackid;
216  $formmail->withfrom = 1;
217  $liste = $langs->trans("AllRecipientSelected", count($arrayofselected));
218  if (count($listofselectedrecipientobjid) == 1) { // Only 1 different recipient selected, we can suggest contacts
219  $liste = array();
220  $thirdpartyid = array_shift($listofselectedrecipientobjid);
221  if ($objecttmp->element == 'expensereport') {
222  $fuser = new User($db);
223  $fuser->fetch($thirdpartyid);
224  $liste['thirdparty'] = $fuser->getFullName($langs)." &lt;".$fuser->email."&gt;";
225  } elseif ($objecttmp->element == 'contact') {
226  $fcontact = new Contact($db);
227  $fcontact->fetch($thirdpartyid);
228  $liste['contact'] = $fcontact->getFullName($langs)." &lt;".$fcontact->email."&gt;";
229  } elseif ($objecttmp->element == 'partnership' && getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR') == 'member') {
230  $fadherent = new Adherent($db);
231  $fadherent->fetch($objecttmp->fk_member);
232  $liste['member'] = $fadherent->getFullName($langs)." &lt;".$fadherent->email."&gt;";
233  } else {
234  $soc = new Societe($db);
235  $soc->fetch($thirdpartyid);
236  foreach ($soc->thirdparty_and_contact_email_array(1) as $key => $value) {
237  $liste[$key] = $value;
238  }
239  }
240  $formmail->withtoreadonly = 0;
241  } else {
242  $formmail->withtoreadonly = 1;
243  }
244 
245 
246  $formmail->withoptiononeemailperrecipient = ((count($listofselectedref) == 1 && count(reset($listofselectedref)) == 1) || empty($liste)) ? 0 : (GETPOST('oneemailperrecipient', 'int') ? 1 : -1);
247  if (in_array($objecttmp->element, array('conferenceorboothattendee'))) {
248  $formmail->withoptiononeemailperrecipient = 0;
249  }
250 
251  $formmail->withto = empty($liste) ? (GETPOST('sendto', 'alpha') ?GETPOST('sendto', 'alpha') : array()) : $liste;
252  $formmail->withtofree = empty($liste) ? 1 : 0;
253  $formmail->withtocc = 1;
254  $formmail->withtoccc = $conf->global->MAIN_EMAIL_USECCC;
255  if (!empty($topicmail)) {
256  $formmail->withtopic = $langs->transnoentities($topicmail, '__REF__', '__REF_CLIENT__');
257  } else {
258  $formmail->withtopic = 1;
259  }
260  if ($objecttmp->element == 'contact') {
261  $formmail->withfile = 0;
262  $formmail->withmaindocfile = 0; // Add a checkbox "Attach also main document"
263  } else {
264  $formmail->withfile = 1; // $formmail->withfile = 2 to allow to upload files is not yet supported in mass action
265  // Add a checkbox "Attach also main document"
266  if (isset($withmaindocfilemail)) {
267  $formmail->withmaindocfile = $withmaindocfilemail;
268  } else { // Do an automatic definition of $formmail->withmaindocfile
269  $formmail->withmaindocfile = 1;
270  if ($objecttmp->element != 'societe') {
271  $formmail->withfile = '<span class="hideonsmartphone opacitymedium">' . $langs->trans("OnlyPDFattachmentSupported") . '</span>';
272  $formmail->withmaindocfile = -1; // Add a checkbox "Attach also main document" but not checked by default
273  }
274  }
275  }
276 
277  $formmail->withbody = 1;
278  $formmail->withdeliveryreceipt = 1;
279  $formmail->withcancel = 1;
280 
281  // Make substitution in email content
282  $substitutionarray = getCommonSubstitutionArray($langs, 0, null, $object);
283 
284  $substitutionarray['__EMAIL__'] = $sendto;
285  $substitutionarray['__CHECK_READ__'] = '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag=undefined&securitykey='.dol_hash(getDolGlobalString('MAILING_EMAIL_UNSUBSCRIBE_KEY')."-undefined", 'md5').'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
286  $substitutionarray['__PERSONALIZED__'] = ''; // deprecated
287  $substitutionarray['__CONTACTCIVNAME__'] = '';
288 
289  $parameters = array(
290  'mode' => 'formemail'
291  );
292  complete_substitutions_array($substitutionarray, $langs, $object, $parameters);
293 
294  // Array of substitutions
295  $formmail->substit = $substitutionarray;
296 
297  // Tableau des parametres complementaires du post
298  $formmail->param['action'] = $action;
299  $formmail->param['models'] = $modelmail; // the filter to know which kind of template emails to show. 'none' means no template suggested.
300  $formmail->param['models_id'] = GETPOST('modelmailselected', 'int') ? GETPOST('modelmailselected', 'int') : '-1';
301  $formmail->param['id'] = join(',', $arrayofselected);
302  // $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id;
303  if (!empty($conf->global->MAILING_LIMIT_SENDBYWEB) && count($listofselectedrecipientobjid) > $conf->global->MAILING_LIMIT_SENDBYWEB) {
304  // Note: MAILING_LIMIT_SENDBYWEB may be forced by conf.php file and variable $dolibarr_mailing_limit_sendbyweb
305  $langs->load("errors");
306  print img_warning().' '.$langs->trans('WarningNumberOfRecipientIsRestrictedInMassAction', $conf->global->MAILING_LIMIT_SENDBYWEB);
307  print ' - <a href="javascript: window.history.go(-1)">'.$langs->trans("GoBack").'</a>';
308  $arrayofmassactions = array();
309  } else {
310  print $formmail->get_form();
311  }
312 
313  print dol_get_fiche_end();
314 }
315 
316 if ($massaction == 'edit_extrafields') {
317  require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
318  $elementtype = $objecttmp->element;
320  $extrafields = new ExtraFields($db);
321  $keysuffix = '';
322  $extrafields->fetch_name_optionals_label($elementtype);
323  $extrafields_list = $extrafields->attributes[$elementtype]['label'];
324 
325  $formquestion = array();
326  if (!empty($extrafields_list)) {
327  $myParamExtra = $object->showOptionals($extrafields, 'create');
328 
329  foreach ($extrafields_list as $extraKey => $extraLabel) {
330  $extrafields_list[$extraKey] = $langs->trans($extraLabel);
331  }
332 
333  $formquestion[] = array(
334  'type' => 'other',
335  'value' => $form->selectarray('extrafield-key-to-update', $extrafields_list, GETPOST('extrafield-key-to-update'), 1)
336  );
337 
338 
339  $outputShowOutputFields = '<div class="extrafields-inputs">';
340 
341  foreach ($extrafields_list as $extraKey => $extraLabel) {
342  $outputShowOutputFields.= '<div class="mass-action-extrafield" data-extrafield="'.$extraKey.'" style="display:none;" >';
343  $outputShowOutputFields.= '<br><span>'. $langs->trans('NewValue').'</span>';
344  $outputShowOutputFields.= $extrafields->showInputField($extraKey, '', '', $keysuffix, '', 0, $objecttmp->id, $objecttmp->table_element);
345  $outputShowOutputFields.= '</div>';
346  }
347  $outputShowOutputFields.= '<script>
348  jQuery(function($) {
349  $("#extrafield-key-to-update").on(\'change\',function(){
350  let selectedExtrtafield = $(this).val();
351  if($(".extrafields-inputs .product_extras_"+selectedExtrtafield) != undefined){
352  $(".mass-action-extrafield").hide();
353  $(".mass-action-extrafield[data-extrafield=" + selectedExtrtafield + "]").show();
354  }
355  });
356  });
357  </script>';
358  $outputShowOutputFields.= '</div>';
359 
360 
361 
362  $formquestion[] = array(
363  'type' => 'other',
364  'value' => $outputShowOutputFields
365  );
366 
367  print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmEditExtrafield"), $langs->trans("ConfirmEditExtrafieldQuestion", count($toselect)), "confirm_edit_value_extrafields", $formquestion, 1, 0, 200, 500, 1);
368  } else {
369  setEventMessage($langs->trans("noExtrafields"));
370  }
371 }
372 
373 if ($massaction == 'preenable') {
374  print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassEnabling"), $langs->trans("ConfirmMassEnablingQuestion", count($toselect)), "enable", null, 'yes', 0, 200, 500, 1);
375 }
376 if ($massaction == 'predisable') {
377  print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassDisabling"), $langs->trans("ConfirmMassDisablingQuestion", count($toselect)), "disable", null, '', 0, 200, 500, 1);
378 }
379 if ($massaction == 'presetcommercial') {
380  $formquestion = array();
381  $userlist = $form->select_dolusers('', '', 0, null, 0, '', '', 0, 0, 0, 'AND u.statut = 1', 0, '', '', 0, 1);
382  $formquestion[] = array('type' => 'other',
383  'name' => 'affectedcommercial',
384  'label' => $form->editfieldkey('AllocateCommercial', 'commercial_id', '', $object, 0),
385  'value' => $form->multiselectarray('commercial', $userlist, null, 0, 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0, '', '', '', 1));
386  print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmAllocateCommercial"), $langs->trans("ConfirmAllocateCommercialQuestion", count($toselect)), "affectcommercial", $formquestion, 1, 0, 200, 500, 1);
387 }
388 if ($massaction == 'preapproveleave') {
389  print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassLeaveApproval"), $langs->trans("ConfirmMassLeaveApprovalQuestion", count($toselect)), "approveleave", null, 'yes', 0, 200, 500, 1);
390 }
391 
392 // Allow Pre-Mass-Action hook (eg for confirmation dialog)
393 $parameters = array(
394  'toselect' => isset($toselect) ? $toselect : array(),
395  'uploaddir' => isset($uploaddir) ? $uploaddir : null,
396  'massaction' => $massaction
397 );
398 
399 $reshook = $hookmanager->executeHooks('doPreMassActions', $parameters, $object, $action);
400 if ($reshook < 0) {
401  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
402 } else {
403  print $hookmanager->resPrint;
404 }
Class to manage members of a foundation.
Class to manage categories.
Class to manage contact/addresses.
Class to manage standard extra fields.
Classe permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new For...
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
Definition: user.class.php:48
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0)
Set event message in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null, $include=null)
Return array of possible common substitutions.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_hash($chain, $type='0')
Returns a hash (non reversible encryption) of a string.