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