dolibarr 18.0.6
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 *
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 */
19
31{
35 public $db;
36
40 public $error = '';
41
42
48 public function __construct($db)
49 {
50 $this->db = $db;
51 }
52
53
54 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
67 public function form_select_status_action($formname, $selected, $canedit = 1, $htmlname = 'complete', $showempty = 0, $onlyselect = 0, $morecss = 'maxwidth100')
68 {
69 // phpcs:enable
70 global $langs, $conf;
71
72 $listofstatus = array(
73 'na' => $langs->trans("ActionNotApplicable"),
74 '0' => $langs->trans("ActionsToDoShort"),
75 '50' => $langs->trans("ActionRunningShort"),
76 '100' => $langs->trans("ActionDoneShort")
77 );
78 // +ActionUncomplete
79
80 if (!empty($conf->use_javascript_ajax)) {
81 print "\n";
82 print '<script nonce="'.getNonce().'" type="text/javascript">';
83 print "
84 var htmlname = '".$htmlname."';
85
86 $(document).ready(function () {
87 select_status();
88
89 $('#select' + htmlname).change(function() {
90 console.log('We change field select '+htmlname);
91 select_status();
92 });
93 });
94
95 function select_status() {
96 var defaultvalue = $('#select' + htmlname).val();
97 console.log('val='+defaultvalue);
98 var percentage = $('input[name=percentage]');
99 var selected = '".(isset($selected) ? dol_escape_js($selected) : '')."';
100 var value = (selected>0?selected:(defaultvalue>=0?defaultvalue:''));
101
102 percentage.val(value);
103
104 if (defaultvalue == 'na' || defaultvalue == -1) {
105 percentage.prop('disabled', true);
106 $('.hideifna').hide();
107 }
108 else if (defaultvalue == 0) {
109 percentage.val(0);
110 percentage.removeAttr('disabled'); /* Not disabled, we want to change it to higher value */
111 $('.hideifna').show();
112 }
113 else if (defaultvalue == 100) {
114 percentage.val(100);
115 percentage.prop('disabled', true);
116 $('.hideifna').show();
117 }
118 else {
119 if (defaultvalue == 50 && (percentage.val() == 0 || percentage.val() == 100)) { percentage.val(50); }
120 percentage.removeAttr('disabled');
121 $('.hideifna').show();
122 }
123 }
124 </script>\n";
125 }
126 if (!empty($conf->use_javascript_ajax) || $onlyselect) {
127 //var_dump($selected);
128 if ($selected == 'done') {
129 $selected = '100';
130 }
131 print '<select '.($canedit ? '' : 'disabled ').'name="'.$htmlname.'" id="select'.$htmlname.'" class="flat'.($morecss ? ' '.$morecss : '').'">';
132 if ($showempty) {
133 print '<option value="-1"'.($selected == '' ? ' selected' : '').'>&nbsp;</option>';
134 }
135 foreach ($listofstatus as $key => $val) {
136 print '<option value="'.$key.'"'.(($selected == $key && strlen($selected) == strlen($key)) || (($selected > 0 && $selected < 100) && $key == '50') ? ' selected' : '').'>'.$val.'</option>';
137 if ($key == '50' && $onlyselect == 2) {
138 print '<option value="todo"'.($selected == 'todo' ? ' selected' : '').'>'.$langs->trans("ActionUncomplete").' ('.$langs->trans("ActionsToDoShort")."+".$langs->trans("ActionRunningShort").')</option>';
139 }
140 }
141 print '</select>';
142 if ($selected == 0 || $selected == 100) {
143 $canedit = 0;
144 }
145
146 print ajax_combobox('select'.$htmlname, array(), 0, 0, 'resolve', '-1', $morecss);
147
148 if (empty($onlyselect)) {
149 print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat hideifna" value="'.($selected >= 0 ? $selected : '').'" size="2"'.($canedit && ($selected >= 0) ? '' : ' disabled').'>';
150 print '<span class="hideonsmartphone hideifna">%</span>';
151 }
152 } else {
153 print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat" value="'.($selected >= 0 ? $selected : '').'" size="2"'.($canedit ? '' : ' disabled').'>%';
154 }
155 }
156
157
172 public function showactions($object, $typeelement, $socid = 0, $forceshowtitle = 0, $morecss = 'listactions', $max = 0, $moreparambacktopage = '', $morehtmlcenter = '', $assignedtouser = 0)
173 {
174 global $langs, $conf, $user;
175
176 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
177
178 $sortfield = 'a.datep,a.id';
179 $sortorder = 'DESC,DESC';
180
181 $actioncomm = new ActionComm($this->db);
182 $listofactions = $actioncomm->getActions($socid, $object->id, $typeelement, '', $sortfield, $sortorder, ($max ? ($max + 1) : 0));
183 if (!is_array($listofactions)) {
184 dol_print_error($this->db, 'FailedToGetActions');
185 }
186
187 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
188 $caction = new CActionComm($this->db);
189 $arraylist = $caction->liste_array(1, 'code', '', (empty($conf->global->AGENDA_USE_EVENT_TYPE) ? 1 : 0), '', 1);
190
191 $num = count($listofactions);
192 if ($num || $forceshowtitle) {
193 if ($typeelement == 'invoice_supplier' || $typeelement == 'supplier_invoice') {
194 $title = $langs->trans('ActionsOnBill');
195 } elseif ($typeelement == 'supplier_proposal') {
196 $title = $langs->trans('ActionsOnSupplierProposal');
197 } elseif ($typeelement == 'order_supplier' || $typeelement == 'supplier_order') {
198 $title = $langs->trans('ActionsOnOrder');
199 } elseif ($typeelement == 'shipping') {
200 $title = $langs->trans('ActionsOnShipping');
201 } else {
202 $title = $langs->trans("LatestLinkedEvents", $max ? $max : '');
203 }
204
205 $urlbacktopage = $_SERVER['PHP_SELF'].'?id='.$object->id.($moreparambacktopage ? '&'.$moreparambacktopage : '');
206
207 $projectid = $object->fk_project;
208 if ($typeelement == 'project') {
209 $projectid = $object->id;
210 }
211 $taskid = 0;
212 if ($typeelement == 'task') {
213 $taskid = $object->id;
214 }
215
216 $usercanaddaction = 0;
217 if (empty($assignedtouser) || $assignedtouser == $user->id) {
218 $usercanaddaction = $user->hasRight('agenda', 'myactions', 'create');
219 $assignedtouser = 0;
220 } else {
221 $usercanaddaction = $user->hasRight('agenda', 'allactions', 'create');
222 }
223
224 $newcardbutton = '';
225 if (isModEnabled('agenda') && $usercanaddaction) {
226 $url = DOL_URL_ROOT.'/comm/action/card.php?action=create&token='.newToken().'&datep='.urlencode(dol_print_date(dol_now(), 'dayhourlog', 'tzuser'));
227 $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) : ''));
228 $url .= ($projectid > 0 ? '&projectid='.((int) $projectid) : '').($taskid > 0 ? '&taskid='.((int) $taskid) : '');
229 $url .= ($assignedtouser > 0 ? '&assignedtouser='.$assignedtouser : '');
230 $url .= '&backtopage='.urlencode($urlbacktopage);
231 $newcardbutton .= dolGetButtonTitle($langs->trans("AddEvent"), '', 'fa fa-plus-circle', $url);
232 }
233
234 print '<!-- formactions->showactions -->'."\n";
235 print load_fiche_titre($title, $newcardbutton, '', 0, 0, '', $morehtmlcenter);
236
237 $page = 0;
238 $param = '';
239
240 print '<div class="div-table-responsive-no-min">';
241 print '<table class="centpercent noborder'.($morecss ? ' '.$morecss : '').'">';
242 print '<tr class="liste_titre">';
243 print getTitleFieldOfList('Ref', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
244 print getTitleFieldOfList('By', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
245 print getTitleFieldOfList('Type', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
246 print getTitleFieldOfList('Title', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
247 print getTitleFieldOfList('Date', 0, $_SERVER["PHP_SELF"], 'a.datep', $page, $param, '', $sortfield, $sortorder, 'center ', 1);
248 print getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, 'right ', 1);
249 print '</tr>';
250 print "\n";
251
252 if (is_array($listofactions) && count($listofactions)) {
253 $cacheusers = array();
254
255 $cursorevent = 0;
256 foreach ($listofactions as $actioncomm) {
257 if ($max && $cursorevent >= $max) {
258 break;
259 }
260
261 print '<tr class="oddeven">';
262
263 // Ref
264 print '<td class="nowraponall">'.$actioncomm->getNomUrl(1, -1).'</td>';
265
266 // Onwer
267 print '<td class="nowraponall tdoverflowmax125">';
268 if (!empty($actioncomm->userownerid)) {
269 if (isset($cacheusers[$actioncomm->userownerid]) && is_object($cacheusers[$actioncomm->userownerid])) {
270 $tmpuser = $cacheusers[$actioncomm->userownerid];
271 } else {
272 $tmpuser = new User($this->db);
273 $tmpuser->fetch($actioncomm->userownerid);
274 $cacheusers[$actioncomm->userownerid] = $tmpuser;
275 }
276 if ($tmpuser->id > 0) {
277 print $tmpuser->getNomUrl(-1, '', 0, 0, 16, 0, 'firstelselast', '');
278 }
279 }
280 print '</td>';
281
282 $actionstatic = $actioncomm;
283
284 // Example: Email sent from invoice card
285 //$actionstatic->code = 'AC_BILL_SENTBYMAIL
286 //$actionstatic->type_code = 'AC_OTHER_AUTO'
287
288 // Type
289 $labeltype = $actionstatic->type_code;
290 if (empty($conf->global->AGENDA_USE_EVENT_TYPE) && empty($arraylist[$labeltype])) {
291 $labeltype = 'AC_OTH';
292 }
293 if (preg_match('/^TICKET_MSG/', $actionstatic->code)) {
294 $labeltype = $langs->trans("Message");
295 } else {
296 if (!empty($arraylist[$labeltype])) {
297 $labeltype = $arraylist[$labeltype];
298 }
299 if ($actionstatic->type_code == 'AC_OTH_AUTO' && ($actionstatic->type_code != $actionstatic->code) && $labeltype && !empty($arraylist[$actionstatic->code])) {
300 $labeltype .= ' - '.$arraylist[$actionstatic->code]; // Use code in priority on type_code
301 }
302 }
303 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($labeltype).'">';
304 print $actioncomm->getTypePicto();
305 print $labeltype;
306 print '</td>';
307
308 // Label
309 print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($actioncomm->label).'">'.$actioncomm->getNomUrl(0, 36).'</td>';
310
311 // Date
312 print '<td class="center nowraponall">'.dol_print_date($actioncomm->datep, 'dayhour', 'tzuserrel');
313 if ($actioncomm->datef) {
314 $tmpa = dol_getdate($actioncomm->datep);
315 $tmpb = dol_getdate($actioncomm->datef);
316 if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
317 if ($tmpa['hours'] != $tmpb['hours'] || $tmpa['minutes'] != $tmpb['minutes']) {
318 print '-'.dol_print_date($actioncomm->datef, 'hour', 'tzuserrel');
319 }
320 } else {
321 print '-'.dol_print_date($actioncomm->datef, 'dayhour', 'tzuserrel');
322 }
323 }
324 print '</td>';
325 print '<td class="right">';
326 print $actioncomm->getLibStatut(3);
327 print '</td>';
328 print '</tr>';
329
330 $cursorevent++;
331 }
332 } else {
333 print '<tr class="oddeven"><td colspan="6"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
334 }
335
336 if ($max && $num > $max) {
337 print '<tr class="oddeven"><td colspan="6"><span class="opacitymedium">'.$langs->trans("More").'...</span></td></tr>';
338 }
339
340 print '</table>';
341 print '</div>';
342 }
343
344 return $num;
345 }
346
347
348 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
362 public function select_type_actions($selected = '', $htmlname = 'actioncode', $excludetype = '', $onlyautoornot = 0, $hideinfohelp = 0, $multiselect = 0, $nooutput = 0, $morecss = 'minwidth300')
363 {
364 // phpcs:enable
365 global $langs, $user, $form, $conf;
366
367 if (!is_object($form)) {
368 $form = new Form($this->db);
369 }
370
371 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
372 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
373 $caction = new CActionComm($this->db);
374
375 // Suggest a list with manual events or all auto events
376 $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.
377 if (empty($multiselect)) {
378 // Add empty line at start only if no multiselect
379 array_unshift($arraylist, '&nbsp;');
380 }
381 //asort($arraylist);
382
383 if ($selected == 'manual') {
384 $selected = 'AC_OTH';
385 }
386 if ($selected == 'auto') {
387 $selected = 'AC_OTH_AUTO';
388 }
389
390 if (!empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO)) {
391 unset($arraylist['AC_OTH_AUTO']);
392 }
393
394 $out = '';
395
396 if (!empty($multiselect)) {
397 if (!is_array($selected) && !empty($selected)) {
398 $selected = explode(',', $selected);
399 }
400 $out .= $form->multiselectarray($htmlname, $arraylist, $selected, 0, 0, 'centpercent', 0, 0);
401 } else {
402 $out .= $form->selectarray($htmlname, $arraylist, $selected, 0, 0, 0, '', 0, 0, 0, '', $morecss, 1);
403 }
404
405 if ($user->admin && empty($onlyautoornot) && $hideinfohelp <= 0) {
406 $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup").($hideinfohelp == -1 ? ". ".$langs->trans("YouCanSetDefaultValueInModuleSetup") : ''), 1);
407 }
408
409 if ($nooutput) {
410 return $out;
411 } else {
412 print $out;
413 }
414 return '';
415 }
416}
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:464
Class to manage agenda events (actions)
Class to manage different types of events.
Class to manage building of HTML components.
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.
select_type_actions($selected='', $htmlname='actioncode', $excludetype='', $onlyautoornot=0, $hideinfohelp=0, $multiselect=0, $nooutput=0, $morecss='minwidth300')
Output html select list of type of event.
Class to manage generation of HTML components Only common components must be here.
Class to manage Dolibarr users.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.