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