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