dolibarr 23.0.3
html.formactions.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 2008-2012 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2010-2018 Juanjo Menent <jmenent@2byte.es>
5 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
33{
37 public $db;
38
42 public $error = '';
43
44
50 public function __construct($db)
51 {
52 $this->db = $db;
53 }
54
55
56 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
71 public function form_select_status_action($formname, $selected, $canedit = 1, $htmlname = 'complete', $showempty = 0, $onlyselect = 0, $morecss = 'maxwidth100', $nooutput = 0)
72 {
73 // phpcs:enable
74 global $langs, $conf;
75
76 $listofstatus = [
77 'na' => $langs->trans("ActionNotApplicable"),
78 '0' => $langs->trans("ActionsToDoShort"),
79 '50' => $langs->trans("ActionRunningShort"),
80 '100' => $langs->trans("ActionDoneShort")
81 ];
82 // +ActionUncomplete
83
84 $out = '';
85
86 if (!empty($conf->use_javascript_ajax) || $onlyselect) {
87 //var_dump($selected);
88 if ($selected == 'done') {
89 $selected = '100';
90 }
91 $out .= '<select '.($canedit ? '' : 'disabled ').'name="'.$htmlname.'" id="select'.$htmlname.'" class="flat'.($morecss ? ' '.$morecss : '').'">';
92 if ($showempty) {
93 $out .= '<option value="-1"'.($selected == '' ? ' selected' : '').'>&nbsp;</option>';
94 }
95 foreach ($listofstatus as $key => $val) {
96 $out .= '<option value="'.$key.'"'.(($selected == $key && strlen($selected) == strlen($key)) || (($selected > 0 && $selected < 100) && $key == '50') ? ' selected' : '').'>';
97 $out .= $val;
98 $out .= '</option>';
99 // Add a choice "Incomplete" at second position
100 if ($key === 'na' && $onlyselect == 2) {
101 $out .= '<option value="todo"'.($selected == 'todo' ? ' selected' : '').'>'.$langs->trans("ActionUncomplete").' ('.$langs->trans("ActionsToDoShort")." + ".$langs->trans("ActionRunningShort").')</option>';
102 }
103 }
104 $out .= '</select>';
105 if ($selected == 0 || $selected == 100) {
106 $canedit = 0;
107 }
108
109 $out .= ajax_combobox('select'.$htmlname, array(), 0, 0, 'resolve', '-1', $morecss);
110
111 if (empty($onlyselect)) {
112 $out .= ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat hideifna heightofcombo" value="'.($selected >= 0 ? $selected : '').'" size="2"'.($canedit && ($selected >= 0) ? '' : ' disabled').'>';
113 $out .= '<span class="hideonsmartphone hideifna">%</span>';
114 }
115 } else {
116 $out .= ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat" value="'.($selected >= 0 ? $selected : '').'" size="2"'.($canedit ? '' : ' disabled').'>%';
117 }
118
119 if (!empty($conf->use_javascript_ajax)) {
120 $out .= "\n";
121 $out .= '<script nonce="'.getNonce().'" type="text/javascript">';
122 $out .= "
123 var htmlname = '".dol_escape_js($htmlname)."';
124
125 $(document).ready(function () {
126 select_status();
127
128 $('#select' + htmlname).change(function() {
129 console.log('We change field select '+htmlname);
130 select_status();
131 });
132 });
133
134 function select_status() {
135 var defaultvalue = $('#select' + htmlname).val();
136 console.log('val='+defaultvalue);
137 var percentage = $('input[name=percentage]');
138 var selected = '".(isset($selected) ? dol_escape_js($selected) : '')."';
139 var value = (selected>0?selected:(defaultvalue>=0?defaultvalue:''));
140
141 percentage.val(value);
142
143 if (defaultvalue == 'na' || defaultvalue == -1) {
144 percentage.prop('disabled', true);
145 $('.hideifna').hide();
146 }
147 else if (defaultvalue == 0) {
148 percentage.val(0);
149 percentage.removeAttr('disabled'); /* Not disabled, we want to change it to higher value */
150 $('.hideifna').show();
151 }
152 else if (defaultvalue == 100) {
153 percentage.val(100);
154 percentage.prop('disabled', true);
155 $('.hideifna').show();
156 }
157 else {
158 if (defaultvalue == 50 && (percentage.val() == 0 || percentage.val() == 100)) { percentage.val(50); }
159 percentage.removeAttr('disabled');
160 $('.hideifna').show();
161 }
162 }
163 </script>\n";
164 }
165
166 if ($nooutput) {
167 return $out;
168 } else {
169 print $out;
170 }
171 }
172
173
188 public function showactions($object, $typeelement, $socid = 0, $forceshowtitle = 0, $morecss = 'listactions', $max = 0, $moreparambacktopage = '', $morehtmlcenter = '', $assignedtouser = 0)
189 {
190 global $langs, $user, $hookmanager;
191
192 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
193
194 $sortfield = 'a.datep,a.id';
195 $sortorder = 'DESC,DESC';
196
197 $actioncomm = new ActionComm($this->db);
198 $listofactions = $actioncomm->getActions($socid, $object->id, $typeelement, '', $sortfield, $sortorder, ($max ? ($max + 1) : 0));
199 if (!is_array($listofactions)) {
200 dol_print_error($this->db, 'FailedToGetActions');
201 }
202
203 $num = count($listofactions);
204 if ($num || $forceshowtitle) {
205 $title = $langs->trans("LatestLinkedEvents", $max ? $max : '');
206
207 $urlbacktopage = $_SERVER['PHP_SELF'].'?id='.$object->id.($moreparambacktopage ? '&'.$moreparambacktopage : '');
208
209 $projectid = $object->fk_project;
210 if ($typeelement == 'project') {
211 $projectid = $object->id;
212 }
213 $taskid = 0;
214 if ($typeelement == 'project_task') {
215 $taskid = $object->id;
216 }
217
218 $usercanaddaction = 0;
219 if (empty($assignedtouser) || $assignedtouser == $user->id) {
220 $usercanaddaction = $user->hasRight('agenda', 'myactions', 'create');
221 $assignedtouser = 0;
222 } else {
223 $usercanaddaction = $user->hasRight('agenda', 'allactions', 'create');
224 }
225
226 $url = '';
227 $morehtmlright = '';
228 if (isModEnabled('agenda') && $usercanaddaction) {
229 $url = DOL_URL_ROOT.'/comm/action/card.php?action=create&token='.newToken().'&datep='.urlencode(dol_print_date(dol_now(), 'dayhourlog', 'tzuser'));
230 $url .= '&origin='.urlencode($typeelement).'&originid='.((int) $object->id).((!empty($object->socid) && $object->socid > 0) ? '&socid='.((int) $object->socid) : ((!empty($socid) && $socid > 0) ? '&socid='.((int) $socid) : ''));
231 $url .= ($projectid > 0 ? '&projectid='.((int) $projectid) : '').($taskid > 0 ? '&taskid='.((int) $taskid) : '');
232 $url .= ($assignedtouser > 0 ? '&assignedtouser='.((int) $assignedtouser) : '');
233 $url .= '&backtopage='.urlencode($urlbacktopage);
234
235 if ($typeelement == 'invoice_supplier') {
236 $messagingUrl = DOL_URL_ROOT.'/fourn/facture/messaging.php?id='.$object->id;
237 $morehtmlright .= dolGetButtonTitle($langs->trans('ShowAsConversation'), '', 'fa fa-comments imgforviewmode', $messagingUrl, '', 1);
238 $messagingUrl = DOL_URL_ROOT.'/fourn/facture/agenda.php?id='.$object->id;
239 $morehtmlright .= dolGetButtonTitle($langs->trans('MessageListViewType'), '', 'fa fa-bars imgforviewmode', $messagingUrl, '', 2);
240 }
241
242 $morehtmlright .= dolGetButtonTitle($langs->trans("AddEvent"), '', 'fa fa-plus-circle', $url);
243 }
244
245 $parameters = array(
246 'title' => &$title,
247 'morehtmlright' => &$morehtmlright,
248 'morehtmlcenter' => &$morehtmlcenter,
249 'usercanaddaction' => $usercanaddaction,
250 'url' => &$url,
251 'typeelement' => $typeelement,
252 'projectid' => $projectid,
253 'assignedtouser' => $assignedtouser,
254 'taskid' => $taskid,
255 'urlbacktopage' => $urlbacktopage
256 );
257
258 $reshook = $hookmanager->executeHooks('showActionsLoadFicheTitre', $parameters, $object);
259
260 if ($reshook < 0) {
261 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
262 }
263
264 $error = 0;
265 if (empty($reshook)) {
266 print '<!-- formactions->showactions -->' . "\n";
267 print load_fiche_titre($title, $morehtmlright, '', 0, '', '', $morehtmlcenter);
268 }
269
270 $page = 0;
271 $param = '';
272
273 print '<div class="div-table-responsive-no-min">';
274 print '<table class="centpercent noborder'.($morecss ? ' '.$morecss : '').'">';
275 print '<tr class="liste_titre">';
276 print getTitleFieldOfList('Ref', 0, $_SERVER["PHP_SELF"], '', (string) $page, $param, '', $sortfield, $sortorder, '', 1);
277 print getTitleFieldOfList('Date', 0, $_SERVER["PHP_SELF"], 'a.datep', (string) $page, $param, '', $sortfield, $sortorder, 'center ', 1);
278 print getTitleFieldOfList('By', 0, $_SERVER["PHP_SELF"], '', (string) $page, $param, '', $sortfield, $sortorder, '', 1);
279 print getTitleFieldOfList('Type', 0, $_SERVER["PHP_SELF"], '', (string) $page, $param, '', $sortfield, $sortorder, 'center ', 1);
280 print getTitleFieldOfList('Title', 0, $_SERVER["PHP_SELF"], '', (string) $page, $param, '', $sortfield, $sortorder, '', 1);
281 print getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', (string) $page, $param, '', $sortfield, $sortorder, 'right ', 1);
282 print '</tr>';
283 print "\n";
284
285 if (is_array($listofactions) && count($listofactions)) {
286 $cacheusers = array();
287
288 $cursorevent = 0;
289 foreach ($listofactions as $actioncomm) {
290 if ($max && $cursorevent >= $max) {
291 break;
292 }
293
294 print '<tr class="oddeven">';
295
296 // Ref
297 print '<td class="nowraponall nopaddingrightimp">'.$actioncomm->getNomUrl(1, -1).'</td>';
298
299 // Date
300 print '<td class="center nowraponall nopaddingtopimp nopaddingbottomimp">';
301 $tmpa = dol_getdate($actioncomm->datep);
302 if ($actioncomm->datef) { // There is also a end date
303 $tmpb = dol_getdate($actioncomm->datef);
304 } else {
305 $tmpb = $tmpa;
306 }
307 if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
308 // The same day
309 print '<div class="center inline-block dateheight">';
310 if ($tmpa['hours'] != $tmpb['hours'] || $tmpa['minutes'] != $tmpb['minutes']) {
311 print dol_print_date($actioncomm->datep, 'dayreduceformat', 'tzuserrel');
312 print '<br><span class="small opacitymedium">';
313 print dol_print_date($actioncomm->datep, 'hourreduceformat', 'tzuserrel');
314 print '-'.dol_print_date($actioncomm->datef, 'hourreduceformat', 'tzuserrel');
315 print '</span>';
316 } else {
317 print dol_print_date($actioncomm->datep, 'dayreduceformat', 'tzuserrel');
318 print '<br><span class="small opacitymedium">';
319 print dol_print_date($actioncomm->datep, 'hourreduceformat', 'tzuserrel');
320 print '</span>';
321 }
322 print '</div>';
323 } else {
324 // Not the same day
325 print '<div class="center inline-block">';
326 print dol_print_date($actioncomm->datep, 'dayreduceformat', 'tzuserrel');
327 print '<br><span class="small opacitymedium">';
328 print dol_print_date($actioncomm->datep, 'hourreduceformat', 'tzuserrel');
329 print '</span>';
330 print '</div>';
331 print ' ';
332 print '<div class="center inline-block">';
333 print dol_print_date($actioncomm->datef, 'dayreduceformat', 'tzuserrel');
334 print '<br><span class="small opacitymedium">';
335 print dol_print_date($actioncomm->datef, 'hourreduceformat', 'tzuserrel');
336 print '</span>';
337 print '</div>';
338 }
339 print '</td>';
340
341 // Owner
342 print '<td class="nowraponall tdoverflowmax100">';
343 if (!empty($actioncomm->userownerid)) {
344 if (isset($cacheusers[$actioncomm->userownerid]) && is_object($cacheusers[$actioncomm->userownerid])) {
345 $tmpuser = $cacheusers[$actioncomm->userownerid];
346 } else {
347 $tmpuser = new User($this->db);
348 $tmpuser->fetch($actioncomm->userownerid);
349 $cacheusers[$actioncomm->userownerid] = $tmpuser;
350 }
351 if ($tmpuser->id > 0) {
352 print $tmpuser->getNomUrl(-1, '', 0, 0, 16, 0, 'firstelselast', '');
353 }
354 }
355 print '</td>';
356
357 // Example: Email sent from invoice card
358 //$actionstatic->code = 'AC_BILL_SENTBYMAIL
359 //$actionstatic->type_code = 'AC_OTHER_AUTO'
360
361 // Type
362 $labeltypelong = $actioncomm->getTypeLabel(2);
363 print '<td class="tdoverflowmax100 center" title="'.dolPrintHTML($labeltypelong).'">';
364 print $actioncomm->getTypePicto('valignmiddle');
365 //$labeltype = $actioncomm->getTypeLabel(0);
366 //print $labeltype;
367 print '</td>';
368
369 // Label / Title
370 print '<td class="tdoverflowmax250">';
371 print $actioncomm->getNomUrl(0);
372 print '</td>';
373
374 // Status
375 print '<td class="right">';
376 print $actioncomm->getLibStatut(3);
377 print '</td>';
378 print '</tr>';
379
380 $cursorevent++;
381 }
382 } else {
383 print '<tr class="oddeven"><td colspan="6"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
384 }
385
386 if ($max && $num > $max) {
387 print '<tr class="oddeven"><td colspan="6"><span class="opacitymedium">'.$langs->trans("More").'...</span></td></tr>';
388 }
389
390 print '</table>';
391 print '</div>';
392 }
393
394 return $num;
395 }
396
397
398 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
413 public function select_type_actions($selected = '', $htmlname = 'actioncode', $excludetype = '', $onlyautoornot = 0, $hideinfohelp = 0, $multiselect = 0, $nooutput = 0, $morecss = 'minwidth300', $showempty = 0)
414 {
415 // phpcs:enable
416 global $langs, $user, $form;
417
418 if (!is_object($form)) {
419 $form = new Form($this->db);
420 }
421
422 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
423 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
424 $caction = new CActionComm($this->db);
425
426 // Suggest a list with manual events or all auto events
427 $arraylist = $caction->liste_array(1, 'code', $excludetype, $onlyautoornot, '', 0); // If we use param 'all' instead of 'code', there is no group by include in answer but the key 'type' of answer array contains the key for the group by.
428
429 if ($selected == 'manual') {
430 $selected = 'AC_OTH';
431 }
432 if ($selected == 'auto') {
433 $selected = 'AC_OTH_AUTO';
434 }
435
436 if (array_key_exists('AC_OTH_AUTO', $arraylist) && getDolGlobalString('AGENDA_ALWAYS_HIDE_AUTO')) {
437 unset($arraylist['AC_OTH_AUTO']);
438 }
439
440 $out = '';
441
442 // Reformat the array
443 $newarraylist = array();
444 foreach ($arraylist as $key => $value) {
445 $disabled = '';
446 if (strpos($key, 'AC_ALL_') !== false && strpos($key, 'AC_ALL_AUTO') === false) {
447 $disabled = 'disabled';
448 }
449
450 $newarraylist[$key] = array('id' => $key, 'label' => $value, 'disabled' => $disabled);
451 }
452
453 if (!empty($multiselect)) {
454 if (!is_array($selected) && !empty($selected)) {
455 $selected = explode(',', $selected);
456 }
457 $out .= $form->multiselectarray($htmlname, $newarraylist, $selected, 0, 0, 'centpercent', 0, 0, '', '', (is_numeric($showempty) ? '' : $showempty));
458 } else {
459 $out .= $form->selectarray($htmlname, $newarraylist, $selected, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1);
460 }
461
462 if ($user->admin && empty($onlyautoornot) && $hideinfohelp <= 0) {
463 $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup").($hideinfohelp == -1 ? ". ".$langs->trans("YouCanSetDefaultValueInModuleSetup") : ''), 1);
464 }
465
466 if ($nooutput) {
467 return $out;
468 } else {
469 print $out;
470 }
471 return '';
472 }
473}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Definition ajax.lib.php:475
Class to manage agenda events (actions)
Class to manage different types of events.
Class to manage building of HTML components.
select_type_actions($selected='', $htmlname='actioncode', $excludetype='', $onlyautoornot=0, $hideinfohelp=0, $multiselect=0, $nooutput=0, $morecss='minwidth300', $showempty=0)
Output html select list of type of event.
showactions($object, $typeelement, $socid=0, $forceshowtitle=0, $morecss='listactions', $max=0, $moreparambacktopage='', $morehtmlcenter='', $assignedtouser=0)
Show list of actions for element.
__construct($db)
Constructor.
form_select_status_action($formname, $selected, $canedit=1, $htmlname='complete', $showempty=0, $onlyselect=0, $morecss='maxwidth100', $nooutput=0)
Show list of action status.
Class to manage generation of HTML components Only common components must be here.
Class to manage Dolibarr users.
$cacheusers
Definition index.php:1595
dol_now($mode='gmt')
Return date for now.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.