dolibarr 21.0.0-beta
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 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
69 public function form_select_status_action($formname, $selected, $canedit = 1, $htmlname = 'complete', $showempty = 0, $onlyselect = 0, $morecss = 'maxwidth100')
70 {
71 // phpcs:enable
72 global $langs, $conf;
73
74 $listofstatus = array(
75 'na' => $langs->trans("ActionNotApplicable"),
76 '0' => $langs->trans("ActionsToDoShort"),
77 '50' => $langs->trans("ActionRunningShort"),
78 '100' => $langs->trans("ActionDoneShort")
79 );
80 // +ActionUncomplete
81
82 if (!empty($conf->use_javascript_ajax) || $onlyselect) {
83 //var_dump($selected);
84 if ($selected == 'done') {
85 $selected = '100';
86 }
87 print '<select '.($canedit ? '' : 'disabled ').'name="'.$htmlname.'" id="select'.$htmlname.'" class="flat'.($morecss ? ' '.$morecss : '').'">';
88 if ($showempty) {
89 print '<option value="-1"'.($selected == '' ? ' selected' : '').'>&nbsp;</option>';
90 }
91 foreach ($listofstatus as $key => $val) {
92 print '<option value="'.$key.'"'.(($selected == $key && strlen($selected) == strlen($key)) || (($selected > 0 && $selected < 100) && $key == '50') ? ' selected' : '').'>'.$val.'</option>';
93 if ($key == '50' && $onlyselect == 2) {
94 print '<option value="todo"'.($selected == 'todo' ? ' selected' : '').'>'.$langs->trans("ActionUncomplete").' ('.$langs->trans("ActionsToDoShort")."+".$langs->trans("ActionRunningShort").')</option>';
95 }
96 }
97 print '</select>';
98 if ($selected == 0 || $selected == 100) {
99 $canedit = 0;
100 }
101
102 print ajax_combobox('select'.$htmlname, array(), 0, 0, 'resolve', '-1', $morecss);
103
104 if (empty($onlyselect)) {
105 print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat hideifna" value="'.($selected >= 0 ? $selected : '').'" size="2"'.($canedit && ($selected >= 0) ? '' : ' disabled').'>';
106 print '<span class="hideonsmartphone hideifna">%</span>';
107 }
108 } else {
109 print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat" value="'.($selected >= 0 ? $selected : '').'" size="2"'.($canedit ? '' : ' disabled').'>%';
110 }
111
112 if (!empty($conf->use_javascript_ajax)) {
113 print "\n";
114 print '<script nonce="'.getNonce().'" type="text/javascript">';
115 print "
116 var htmlname = '".dol_escape_js($htmlname)."';
117
118 $(document).ready(function () {
119 select_status();
120
121 $('#select' + htmlname).change(function() {
122 console.log('We change field select '+htmlname);
123 select_status();
124 });
125 });
126
127 function select_status() {
128 var defaultvalue = $('#select' + htmlname).val();
129 console.log('val='+defaultvalue);
130 var percentage = $('input[name=percentage]');
131 var selected = '".(isset($selected) ? dol_escape_js($selected) : '')."';
132 var value = (selected>0?selected:(defaultvalue>=0?defaultvalue:''));
133
134 percentage.val(value);
135
136 if (defaultvalue == 'na' || defaultvalue == -1) {
137 percentage.prop('disabled', true);
138 $('.hideifna').hide();
139 }
140 else if (defaultvalue == 0) {
141 percentage.val(0);
142 percentage.removeAttr('disabled'); /* Not disabled, we want to change it to higher value */
143 $('.hideifna').show();
144 }
145 else if (defaultvalue == 100) {
146 percentage.val(100);
147 percentage.prop('disabled', true);
148 $('.hideifna').show();
149 }
150 else {
151 if (defaultvalue == 50 && (percentage.val() == 0 || percentage.val() == 100)) { percentage.val(50); }
152 percentage.removeAttr('disabled');
153 $('.hideifna').show();
154 }
155 }
156 </script>\n";
157 }
158 }
159
160
175 public function showactions($object, $typeelement, $socid = 0, $forceshowtitle = 0, $morecss = 'listactions', $max = 0, $moreparambacktopage = '', $morehtmlcenter = '', $assignedtouser = 0)
176 {
177 global $langs, $user, $hookmanager;
178
179 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
180
181 $sortfield = 'a.datep,a.id';
182 $sortorder = 'DESC,DESC';
183
184 $actioncomm = new ActionComm($this->db);
185 $listofactions = $actioncomm->getActions($socid, $object->id, $typeelement, '', $sortfield, $sortorder, ($max ? ($max + 1) : 0));
186 if (!is_array($listofactions)) {
187 dol_print_error($this->db, 'FailedToGetActions');
188 }
189
190 $num = count($listofactions);
191 if ($num || $forceshowtitle) {
192 $title = $langs->trans("LatestLinkedEvents", $max ? $max : '');
193
194 $urlbacktopage = $_SERVER['PHP_SELF'].'?id='.$object->id.($moreparambacktopage ? '&'.$moreparambacktopage : '');
195
196 $projectid = $object->fk_project;
197 if ($typeelement == 'project') {
198 $projectid = $object->id;
199 }
200 $taskid = 0;
201 if ($typeelement == 'task') {
202 $taskid = $object->id;
203 }
204
205 $usercanaddaction = 0;
206 if (empty($assignedtouser) || $assignedtouser == $user->id) {
207 $usercanaddaction = $user->hasRight('agenda', 'myactions', 'create');
208 $assignedtouser = 0;
209 } else {
210 $usercanaddaction = $user->hasRight('agenda', 'allactions', 'create');
211 }
212
213 $url = '';
214 $morehtmlright = '';
215 if (isModEnabled('agenda') && $usercanaddaction) {
216 $url = DOL_URL_ROOT.'/comm/action/card.php?action=create&token='.newToken().'&datep='.urlencode(dol_print_date(dol_now(), 'dayhourlog', 'tzuser'));
217 $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) : ''));
218 $url .= ($projectid > 0 ? '&projectid='.((int) $projectid) : '').($taskid > 0 ? '&taskid='.((int) $taskid) : '');
219 $url .= ($assignedtouser > 0 ? '&assignedtouser='.((int) $assignedtouser) : '');
220 $url .= '&backtopage='.urlencode($urlbacktopage);
221
222 if ($typeelement == 'invoice_supplier') {
223 $messagingUrl = DOL_URL_ROOT.'/fourn/facture/messaging.php?id='.$object->id;
224 $morehtmlright .= dolGetButtonTitle($langs->trans('ShowAsConversation'), '', 'fa fa-comments imgforviewmode', $messagingUrl, '', 1);
225 $messagingUrl = DOL_URL_ROOT.'/fourn/facture/agenda.php?id='.$object->id;
226 $morehtmlright .= dolGetButtonTitle($langs->trans('MessageListViewType'), '', 'fa fa-bars imgforviewmode', $messagingUrl, '', 2);
227 }
228
229 $morehtmlright .= dolGetButtonTitle($langs->trans("AddEvent"), '', 'fa fa-plus-circle', $url);
230 }
231
232 $parameters = array(
233 'title' => &$title,
234 'morehtmlright' => &$morehtmlright,
235 'morehtmlcenter' => &$morehtmlcenter,
236 'usercanaddaction' => $usercanaddaction,
237 'url' => &$url,
238 'typeelement' => $typeelement,
239 'projectid' => $projectid,
240 'assignedtouser' => $assignedtouser,
241 'taskid' => $taskid,
242 'urlbacktopage' => $urlbacktopage
243 );
244
245 $reshook = $hookmanager->executeHooks('showActionsLoadFicheTitre', $parameters, $object);
246
247 if ($reshook < 0) {
248 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
249 }
250
251 $error = 0;
252 if (empty($reshook)) {
253 print '<!-- formactions->showactions -->' . "\n";
254 print load_fiche_titre($title, $morehtmlright, '', 0, '', '', $morehtmlcenter);
255 }
256
257 $page = 0;
258 $param = '';
259
260 print '<div class="div-table-responsive-no-min">';
261 print '<table class="centpercent noborder'.($morecss ? ' '.$morecss : '').'">';
262 print '<tr class="liste_titre">';
263 print getTitleFieldOfList('Ref', 0, $_SERVER["PHP_SELF"], '', (string) $page, $param, '', $sortfield, $sortorder, '', 1);
264 print getTitleFieldOfList('Date', 0, $_SERVER["PHP_SELF"], 'a.datep', (string) $page, $param, '', $sortfield, $sortorder, 'center ', 1);
265 print getTitleFieldOfList('By', 0, $_SERVER["PHP_SELF"], '', (string) $page, $param, '', $sortfield, $sortorder, '', 1);
266 print getTitleFieldOfList('Type', 0, $_SERVER["PHP_SELF"], '', (string) $page, $param, '', $sortfield, $sortorder, '', 1);
267 print getTitleFieldOfList('Title', 0, $_SERVER["PHP_SELF"], '', (string) $page, $param, '', $sortfield, $sortorder, '', 1);
268 print getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', (string) $page, $param, '', $sortfield, $sortorder, 'right ', 1);
269 print '</tr>';
270 print "\n";
271
272 if (is_array($listofactions) && count($listofactions)) {
273 $cacheusers = array();
274
275 $cursorevent = 0;
276 foreach ($listofactions as $actioncomm) {
277 if ($max && $cursorevent >= $max) {
278 break;
279 }
280
281 print '<tr class="oddeven">';
282
283 // Ref
284 print '<td class="nowraponall nopaddingrightimp">'.$actioncomm->getNomUrl(1, -1).'</td>';
285
286 // Date
287 print '<td class="center nowraponall">'.dol_print_date($actioncomm->datep, 'dayhourreduceformat', 'tzuserrel');
288 if ($actioncomm->datef) {
289 $tmpa = dol_getdate($actioncomm->datep);
290 $tmpb = dol_getdate($actioncomm->datef);
291 if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
292 if ($tmpa['hours'] != $tmpb['hours'] || $tmpa['minutes'] != $tmpb['minutes']) {
293 print '-'.dol_print_date($actioncomm->datef, 'hour', 'tzuserrel');
294 }
295 } else {
296 print '-'.dol_print_date($actioncomm->datef, 'dayhourreduceformat', 'tzuserrel');
297 }
298 }
299 print '</td>';
300
301 // Owner
302 print '<td class="nowraponall tdoverflowmax100">';
303 if (!empty($actioncomm->userownerid)) {
304 if (isset($cacheusers[$actioncomm->userownerid]) && is_object($cacheusers[$actioncomm->userownerid])) {
305 $tmpuser = $cacheusers[$actioncomm->userownerid];
306 } else {
307 $tmpuser = new User($this->db);
308 $tmpuser->fetch($actioncomm->userownerid);
309 $cacheusers[$actioncomm->userownerid] = $tmpuser;
310 }
311 if ($tmpuser->id > 0) {
312 print $tmpuser->getNomUrl(-1, '', 0, 0, 16, 0, 'firstelselast', '');
313 }
314 }
315 print '</td>';
316
317 // Example: Email sent from invoice card
318 //$actionstatic->code = 'AC_BILL_SENTBYMAIL
319 //$actionstatic->type_code = 'AC_OTHER_AUTO'
320
321 // Type
322 $labeltype = $actioncomm->getTypeLabel(0);
323 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($labeltype).'">';
324 print $actioncomm->getTypePicto();
325 print $labeltype;
326 print '</td>';
327
328 // Label
329 print '<td class="tdoverflowmax250">';
330 print $actioncomm->getNomUrl(0);
331 print '</td>';
332
333 // Status
334 print '<td class="right">';
335 print $actioncomm->getLibStatut(3);
336 print '</td>';
337 print '</tr>';
338
339 $cursorevent++;
340 }
341 } else {
342 print '<tr class="oddeven"><td colspan="6"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
343 }
344
345 if ($max && $num > $max) {
346 print '<tr class="oddeven"><td colspan="6"><span class="opacitymedium">'.$langs->trans("More").'...</span></td></tr>';
347 }
348
349 print '</table>';
350 print '</div>';
351 }
352
353 return $num;
354 }
355
356
357 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
372 public function select_type_actions($selected = '', $htmlname = 'actioncode', $excludetype = '', $onlyautoornot = 0, $hideinfohelp = 0, $multiselect = 0, $nooutput = 0, $morecss = 'minwidth300', $showempty = 0)
373 {
374 // phpcs:enable
375 global $langs, $user, $form;
376
377 if (!is_object($form)) {
378 $form = new Form($this->db);
379 }
380
381 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
382 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
383 $caction = new CActionComm($this->db);
384
385 // Suggest a list with manual events or all auto events
386 $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.
387
388 if ($selected == 'manual') {
389 $selected = 'AC_OTH';
390 }
391 if ($selected == 'auto') {
392 $selected = 'AC_OTH_AUTO';
393 }
394
395 if (array_key_exists('AC_OTH_AUTO', $arraylist) && getDolGlobalString('AGENDA_ALWAYS_HIDE_AUTO')) {
396 unset($arraylist['AC_OTH_AUTO']);
397 }
398
399 $out = '';
400
401 // Reformat the array
402 $newarraylist = array();
403 foreach ($arraylist as $key => $value) {
404 $disabled = '';
405 if (strpos($key, 'AC_ALL_') !== false && strpos($key, 'AC_ALL_AUTO') === false) {
406 $disabled = 'disabled';
407 }
408
409 $newarraylist[$key] = array('id' => $key, 'label' => $value, 'disabled' => $disabled);
410 }
411
412 if (!empty($multiselect)) {
413 if (!is_array($selected) && !empty($selected)) {
414 $selected = explode(',', $selected);
415 }
416 $out .= $form->multiselectarray($htmlname, $newarraylist, $selected, 0, 0, 'centpercent', 0, 0, '', '', (is_numeric($showempty) ? '' : $showempty));
417 } else {
418 $out .= $form->selectarray($htmlname, $newarraylist, $selected, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1);
419 }
420
421 if ($user->admin && empty($onlyautoornot) && $hideinfohelp <= 0) {
422 $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup").($hideinfohelp == -1 ? ". ".$langs->trans("YouCanSetDefaultValueInModuleSetup") : ''), 1);
423 }
424
425 if ($nooutput) {
426 return $out;
427 } else {
428 print $out;
429 }
430 return '';
431 }
432}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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:459
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.
form_select_status_action($formname, $selected, $canedit=1, $htmlname='complete', $showempty=0, $onlyselect=0, $morecss='maxwidth100')
Show list of action status.
showactions($object, $typeelement, $socid=0, $forceshowtitle=0, $morecss='listactions', $max=0, $moreparambacktopage='', $morehtmlcenter='', $assignedtouser=0)
Show list of actions for element.
__construct($db)
Constructor.
Class to manage generation of HTML components Only common components must be here.
Class to manage Dolibarr users.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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_now($mode='auto')
Return date for now.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79