dolibarr  21.0.0-alpha
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) || $onlyselect) {
81  //var_dump($selected);
82  if ($selected == 'done') {
83  $selected = '100';
84  }
85  print '<select '.($canedit ? '' : 'disabled ').'name="'.$htmlname.'" id="select'.$htmlname.'" class="flat'.($morecss ? ' '.$morecss : '').'">';
86  if ($showempty) {
87  print '<option value="-1"'.($selected == '' ? ' selected' : '').'>&nbsp;</option>';
88  }
89  foreach ($listofstatus as $key => $val) {
90  print '<option value="'.$key.'"'.(($selected == $key && strlen($selected) == strlen($key)) || (($selected > 0 && $selected < 100) && $key == '50') ? ' selected' : '').'>'.$val.'</option>';
91  if ($key == '50' && $onlyselect == 2) {
92  print '<option value="todo"'.($selected == 'todo' ? ' selected' : '').'>'.$langs->trans("ActionUncomplete").' ('.$langs->trans("ActionsToDoShort")."+".$langs->trans("ActionRunningShort").')</option>';
93  }
94  }
95  print '</select>';
96  if ($selected == 0 || $selected == 100) {
97  $canedit = 0;
98  }
99 
100  print ajax_combobox('select'.$htmlname, array(), 0, 0, 'resolve', '-1', $morecss);
101 
102  if (empty($onlyselect)) {
103  print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat hideifna" value="'.($selected >= 0 ? $selected : '').'" size="2"'.($canedit && ($selected >= 0) ? '' : ' disabled').'>';
104  print '<span class="hideonsmartphone hideifna">%</span>';
105  }
106  } else {
107  print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat" value="'.($selected >= 0 ? $selected : '').'" size="2"'.($canedit ? '' : ' disabled').'>%';
108  }
109 
110  if (!empty($conf->use_javascript_ajax)) {
111  print "\n";
112  print '<script nonce="'.getNonce().'" type="text/javascript">';
113  print "
114  var htmlname = '".dol_escape_js($htmlname)."';
115 
116  $(document).ready(function () {
117  select_status();
118 
119  $('#select' + htmlname).change(function() {
120  console.log('We change field select '+htmlname);
121  select_status();
122  });
123  });
124 
125  function select_status() {
126  var defaultvalue = $('#select' + htmlname).val();
127  console.log('val='+defaultvalue);
128  var percentage = $('input[name=percentage]');
129  var selected = '".(isset($selected) ? dol_escape_js($selected) : '')."';
130  var value = (selected>0?selected:(defaultvalue>=0?defaultvalue:''));
131 
132  percentage.val(value);
133 
134  if (defaultvalue == 'na' || defaultvalue == -1) {
135  percentage.prop('disabled', true);
136  $('.hideifna').hide();
137  }
138  else if (defaultvalue == 0) {
139  percentage.val(0);
140  percentage.removeAttr('disabled'); /* Not disabled, we want to change it to higher value */
141  $('.hideifna').show();
142  }
143  else if (defaultvalue == 100) {
144  percentage.val(100);
145  percentage.prop('disabled', true);
146  $('.hideifna').show();
147  }
148  else {
149  if (defaultvalue == 50 && (percentage.val() == 0 || percentage.val() == 100)) { percentage.val(50); }
150  percentage.removeAttr('disabled');
151  $('.hideifna').show();
152  }
153  }
154  </script>\n";
155  }
156  }
157 
158 
173  public function showactions($object, $typeelement, $socid = 0, $forceshowtitle = 0, $morecss = 'listactions', $max = 0, $moreparambacktopage = '', $morehtmlcenter = '', $assignedtouser = 0)
174  {
175  global $langs, $conf, $user, $hookmanager;
176 
177  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
178 
179  $sortfield = 'a.datep,a.id';
180  $sortorder = 'DESC,DESC';
181 
182  $actioncomm = new ActionComm($this->db);
183  $listofactions = $actioncomm->getActions($socid, $object->id, $typeelement, '', $sortfield, $sortorder, ($max ? ($max + 1) : 0));
184  if (!is_array($listofactions)) {
185  dol_print_error($this->db, 'FailedToGetActions');
186  }
187 
188  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
189  $caction = new CActionComm($this->db);
190  $arraylist = $caction->liste_array(1, 'code', '', (!getDolGlobalString('AGENDA_USE_EVENT_TYPE') ? 1 : 0), '', 1);
191 
192  $num = count($listofactions);
193  if ($num || $forceshowtitle) {
194  $title = $langs->trans("LatestLinkedEvents", $max ? $max : '');
195 
196  $urlbacktopage = $_SERVER['PHP_SELF'].'?id='.$object->id.($moreparambacktopage ? '&'.$moreparambacktopage : '');
197 
198  $projectid = $object->fk_project;
199  if ($typeelement == 'project') {
200  $projectid = $object->id;
201  }
202  $taskid = 0;
203  if ($typeelement == 'task') {
204  $taskid = $object->id;
205  }
206 
207  $usercanaddaction = 0;
208  if (empty($assignedtouser) || $assignedtouser == $user->id) {
209  $usercanaddaction = $user->hasRight('agenda', 'myactions', 'create');
210  $assignedtouser = 0;
211  } else {
212  $usercanaddaction = $user->hasRight('agenda', 'allactions', 'create');
213  }
214 
215  $url = '';
216  $morehtmlright = '';
217  if (isModEnabled('agenda') && $usercanaddaction) {
218  $url = DOL_URL_ROOT.'/comm/action/card.php?action=create&token='.newToken().'&datep='.urlencode(dol_print_date(dol_now(), 'dayhourlog', 'tzuser'));
219  $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) : ''));
220  $url .= ($projectid > 0 ? '&projectid='.((int) $projectid) : '').($taskid > 0 ? '&taskid='.((int) $taskid) : '');
221  $url .= ($assignedtouser > 0 ? '&assignedtouser='.$assignedtouser : '');
222  $url .= '&backtopage='.urlencode($urlbacktopage);
223  $morehtmlright .= dolGetButtonTitle($langs->trans("AddEvent"), '', 'fa fa-plus-circle', $url);
224  }
225 
226  $parameters = array(
227  'title' => &$title,
228  'morehtmlright' => &$morehtmlright,
229  'morehtmlcenter' => &$morehtmlcenter,
230  'usercanaddaction' => $usercanaddaction,
231  'url' => &$url,
232  'typeelement' => $typeelement,
233  'projectid' => $projectid,
234  'assignedtouser' => $assignedtouser,
235  'taskid' => $taskid,
236  'urlbacktopage' => $urlbacktopage
237  );
238 
239  $reshook = $hookmanager->executeHooks('showActionsLoadFicheTitre', $parameters, $object);
240 
241  if ($reshook < 0) {
242  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
243  }
244 
245  $error = 0;
246  if (empty($reshook)) {
247  print '<!-- formactions->showactions -->' . "\n";
248  print load_fiche_titre($title, $morehtmlright, '', 0, 0, '', $morehtmlcenter);
249  }
250 
251  $page = 0;
252  $param = '';
253 
254  print '<div class="div-table-responsive-no-min">';
255  print '<table class="centpercent noborder'.($morecss ? ' '.$morecss : '').'">';
256  print '<tr class="liste_titre">';
257  print getTitleFieldOfList('Ref', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
258  print getTitleFieldOfList('Date', 0, $_SERVER["PHP_SELF"], 'a.datep', $page, $param, '', $sortfield, $sortorder, 'center ', 1);
259  print getTitleFieldOfList('By', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
260  print getTitleFieldOfList('Type', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
261  print getTitleFieldOfList('Title', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
262  print getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, 'right ', 1);
263  print '</tr>';
264  print "\n";
265 
266  if (is_array($listofactions) && count($listofactions)) {
267  $cacheusers = array();
268 
269  $cursorevent = 0;
270  foreach ($listofactions as $actioncomm) {
271  if ($max && $cursorevent >= $max) {
272  break;
273  }
274 
275  print '<tr class="oddeven">';
276 
277  // Ref
278  print '<td class="nowraponall">'.$actioncomm->getNomUrl(1, -1).'</td>';
279 
280  // Date
281  print '<td class="center nowraponall">'.dol_print_date($actioncomm->datep, 'dayhour', 'tzuserrel');
282  if ($actioncomm->datef) {
283  $tmpa = dol_getdate($actioncomm->datep);
284  $tmpb = dol_getdate($actioncomm->datef);
285  if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
286  if ($tmpa['hours'] != $tmpb['hours'] || $tmpa['minutes'] != $tmpb['minutes']) {
287  print '-'.dol_print_date($actioncomm->datef, 'hour', 'tzuserrel');
288  }
289  } else {
290  print '-'.dol_print_date($actioncomm->datef, 'dayhour', 'tzuserrel');
291  }
292  }
293  print '</td>';
294 
295  // Owner
296  print '<td class="nowraponall tdoverflowmax125">';
297  if (!empty($actioncomm->userownerid)) {
298  if (isset($cacheusers[$actioncomm->userownerid]) && is_object($cacheusers[$actioncomm->userownerid])) {
299  $tmpuser = $cacheusers[$actioncomm->userownerid];
300  } else {
301  $tmpuser = new User($this->db);
302  $tmpuser->fetch($actioncomm->userownerid);
303  $cacheusers[$actioncomm->userownerid] = $tmpuser;
304  }
305  if ($tmpuser->id > 0) {
306  print $tmpuser->getNomUrl(-1, '', 0, 0, 16, 0, 'firstelselast', '');
307  }
308  }
309  print '</td>';
310 
311  $actionstatic = $actioncomm;
312 
313  // Example: Email sent from invoice card
314  //$actionstatic->code = 'AC_BILL_SENTBYMAIL
315  //$actionstatic->type_code = 'AC_OTHER_AUTO'
316 
317  // Type
318  $labeltype = $actionstatic->type_code;
319  if (!getDolGlobalString('AGENDA_USE_EVENT_TYPE') && empty($arraylist[$labeltype])) {
320  $labeltype = 'AC_OTH';
321  }
322  if (preg_match('/^TICKET_MSG/', $actionstatic->code)) {
323  $labeltype = $langs->trans("Message");
324  } else {
325  if (!empty($arraylist[$labeltype])) {
326  $labeltype = $arraylist[$labeltype];
327  }
328  if ($actionstatic->type_code == 'AC_OTH_AUTO' && ($actionstatic->type_code != $actionstatic->code) && $labeltype && !empty($arraylist[$actionstatic->code])) {
329  $labeltype .= ' - '.$arraylist[$actionstatic->code]; // Use code in priority on type_code
330  }
331  }
332  print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($labeltype).'">';
333  print $actioncomm->getTypePicto();
334  print $labeltype;
335  print '</td>';
336 
337  // Label
338  print '<td class="tdoverflowmax200">';
339  print $actioncomm->getNomUrl(0);
340  print '</td>';
341 
342  // Status
343  print '<td class="right">';
344  print $actioncomm->getLibStatut(3);
345  print '</td>';
346  print '</tr>';
347 
348  $cursorevent++;
349  }
350  } else {
351  print '<tr class="oddeven"><td colspan="6"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
352  }
353 
354  if ($max && $num > $max) {
355  print '<tr class="oddeven"><td colspan="6"><span class="opacitymedium">'.$langs->trans("More").'...</span></td></tr>';
356  }
357 
358  print '</table>';
359  print '</div>';
360  }
361 
362  return $num;
363  }
364 
365 
366  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
380  public function select_type_actions($selected = '', $htmlname = 'actioncode', $excludetype = '', $onlyautoornot = 0, $hideinfohelp = 0, $multiselect = 0, $nooutput = 0, $morecss = 'minwidth300')
381  {
382  // phpcs:enable
383  global $langs, $user, $form;
384 
385  if (!is_object($form)) {
386  $form = new Form($this->db);
387  }
388 
389  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
390  require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
391  $caction = new CActionComm($this->db);
392 
393  // Suggest a list with manual events or all auto events
394  $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.
395  if (empty($multiselect)) {
396  // Add empty line at start only if no multiselect
397  array_unshift($arraylist, '&nbsp;');
398  }
399  //asort($arraylist);
400 
401  if ($selected == 'manual') {
402  $selected = 'AC_OTH';
403  }
404  if ($selected == 'auto') {
405  $selected = 'AC_OTH_AUTO';
406  }
407 
408  if (getDolGlobalString('AGENDA_ALWAYS_HIDE_AUTO')) {
409  unset($arraylist['AC_OTH_AUTO']);
410  }
411 
412  $out = '';
413 
414  // Reformat the array
415  $newarraylist = array();
416  foreach ($arraylist as $key => $value) {
417  $disabled = '';
418  if (strpos($key, 'AC_ALL_') !== false && strpos($key, 'AC_ALL_AUTO') === false) {
419  $disabled = 'disabled';
420  }
421  $newarraylist[$key] = array('id' => $key, 'label' => $value, 'disabled' => $disabled);
422  }
423 
424  if (!empty($multiselect)) {
425  if (!is_array($selected) && !empty($selected)) {
426  $selected = explode(',', $selected);
427  }
428  $out .= $form->multiselectarray($htmlname, $newarraylist, $selected, 0, 0, 'centpercent', 0, 0);
429  } else {
430  $out .= $form->selectarray($htmlname, $newarraylist, $selected, 0, 0, 0, '', 0, 0, 0, '', $morecss, 1);
431  }
432 
433  if ($user->admin && empty($onlyautoornot) && $hideinfohelp <= 0) {
434  $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup").($hideinfohelp == -1 ? ". ".$langs->trans("YouCanSetDefaultValueInModuleSetup") : ''), 1);
435  }
436 
437  if ($nooutput) {
438  return $out;
439  } else {
440  print $out;
441  }
442  return '';
443  }
444 }
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
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:456
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.
Definition: user.class.php:50
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information in HTML for admin users or standard users.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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 dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.