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