dolibarr  16.0.1
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 type=\"text/javascript\">
83  var htmlname = '".$htmlname."';
84 
85  $(document).ready(function () {
86  select_status();
87 
88  $('#select' + htmlname).change(function() {
89  console.log('We change field select '+htmlname);
90  select_status();
91  });
92  });
93 
94  function select_status() {
95  var defaultvalue = $('#select' + htmlname).val();
96  console.log('val='+defaultvalue);
97  var percentage = $('input[name=percentage]');
98  var selected = '".(isset($selected) ? dol_escape_js($selected) : '')."';
99  var value = (selected>0?selected:(defaultvalue>=0?defaultvalue:''));
100 
101  percentage.val(value);
102 
103  if (defaultvalue == 'na' || defaultvalue == -1) {
104  percentage.prop('disabled', true);
105  $('.hideifna').hide();
106  }
107  else if (defaultvalue == 0) {
108  percentage.val(0);
109  percentage.removeAttr('disabled'); /* Not disabled, we want to change it to higher value */
110  $('.hideifna').show();
111  }
112  else if (defaultvalue == 100) {
113  percentage.val(100);
114  percentage.prop('disabled', true);
115  $('.hideifna').show();
116  }
117  else {
118  if (defaultvalue == 50 && (percentage.val() == 0 || percentage.val() == 100)) { percentage.val(50) };
119  percentage.removeAttr('disabled');
120  $('.hideifna').show();
121  }
122  }
123  </script>\n";
124  }
125  if (!empty($conf->use_javascript_ajax) || $onlyselect) {
126  //var_dump($selected);
127  if ($selected == 'done') {
128  $selected = '100';
129  }
130  print '<select '.($canedit ? '' : 'disabled ').'name="'.$htmlname.'" id="select'.$htmlname.'" class="flat'.($morecss ? ' '.$morecss : '').'">';
131  if ($showempty) {
132  print '<option value="-1"'.($selected == '' ? ' selected' : '').'>&nbsp;</option>';
133  }
134  foreach ($listofstatus as $key => $val) {
135  print '<option value="'.$key.'"'.(($selected == $key && strlen($selected) == strlen($key)) || (($selected > 0 && $selected < 100) && $key == '50') ? ' selected' : '').'>'.$val.'</option>';
136  if ($key == '50' && $onlyselect == 2) {
137  print '<option value="todo"'.($selected == 'todo' ? ' selected' : '').'>'.$langs->trans("ActionUncomplete").' ('.$langs->trans("ActionsToDoShort")."+".$langs->trans("ActionRunningShort").')</option>';
138  }
139  }
140  print '</select>';
141  if ($selected == 0 || $selected == 100) {
142  $canedit = 0;
143  }
144 
145  print ajax_combobox('select'.$htmlname);
146 
147  if (empty($onlyselect)) {
148  print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat hideifna" value="'.($selected >= 0 ? $selected : '').'" size="2"'.($canedit && ($selected >= 0) ? '' : ' disabled').'>';
149  print '<span class="hideonsmartphone hideifna">%</span>';
150  }
151  } else {
152  print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat" value="'.($selected >= 0 ? $selected : '').'" size="2"'.($canedit ? '' : ' disabled').'>%';
153  }
154  }
155 
156 
170  public function showactions($object, $typeelement, $socid = 0, $forceshowtitle = 0, $morecss = 'listactions', $max = 0, $moreparambacktopage = '', $morehtmlcenter = '')
171  {
172  global $langs, $conf, $user;
173 
174  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
175 
176  $sortfield = 'a.datep,a.id';
177  $sortorder = 'DESC,DESC';
178 
179  $actioncomm = new ActionComm($this->db);
180  $listofactions = $actioncomm->getActions($socid, $object->id, $typeelement, '', $sortfield, $sortorder, ($max ? ($max + 1) : 0));
181  if (!is_array($listofactions)) {
182  dol_print_error($this->db, 'FailedToGetActions');
183  }
184 
185  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
186  $caction = new CActionComm($this->db);
187  $arraylist = $caction->liste_array(1, 'code', '', (empty($conf->global->AGENDA_USE_EVENT_TYPE) ? 1 : 0), '', 1);
188 
189  $num = count($listofactions);
190  if ($num || $forceshowtitle) {
191  if ($typeelement == 'invoice') {
192  $title = $langs->trans('ActionsOnBill');
193  } elseif ($typeelement == 'invoice_supplier' || $typeelement == 'supplier_invoice') {
194  $title = $langs->trans('ActionsOnBill');
195  } elseif ($typeelement == 'propal') {
196  $title = $langs->trans('ActionsOnPropal');
197  } elseif ($typeelement == 'supplier_proposal') {
198  $title = $langs->trans('ActionsOnSupplierProposal');
199  } elseif ($typeelement == 'order') {
200  $title = $langs->trans('ActionsOnOrder');
201  } elseif ($typeelement == 'order_supplier' || $typeelement == 'supplier_order') {
202  $title = $langs->trans('ActionsOnOrder');
203  } elseif ($typeelement == 'shipping') {
204  $title = $langs->trans('ActionsOnShipping');
205  } elseif ($typeelement == 'fichinter') {
206  $title = $langs->trans('ActionsOnFicheInter');
207  } elseif ($typeelement == 'project') {
208  $title = $langs->trans('LatestLinkedEvents', $max ? $max : '');
209  } elseif ($typeelement == 'task') {
210  $title = $langs->trans('LatestLinkedEvents', $max ? $max : '');
211  } elseif ($typeelement == 'member') {
212  $title = $langs->trans('LatestLinkedEvents', $max ? $max : '');
213  } else {
214  $title = $langs->trans("LatestLinkedEvents", $max ? $max : '');
215  }
216 
217  $urlbacktopage = $_SERVER['PHP_SELF'].'?id='.$object->id.($moreparambacktopage ? '&'.$moreparambacktopage : '');
218 
219  $projectid = $object->fk_project;
220  if ($typeelement == 'project') {
221  $projectid = $object->id;
222  }
223  $taskid = 0;
224  if ($typeelement == 'task') {
225  $taskid = $object->id;
226  }
227 
228  $newcardbutton = '';
229  if (isModEnabled('agenda') && !empty($user->rights->agenda->myactions->create)) {
230  $url = DOL_URL_ROOT.'/comm/action/card.php?action=create&token='.newToken().'&datep='.urlencode(dol_print_date(dol_now(), 'dayhourlog', 'tzuser')).'&origin='.urlencode($typeelement).'&originid='.((int) $object->id).((!empty($object->socid) && $object->socid > 0) ? '&socid='.((int) $object->socid) : ((!empty($socid) && $socid > 0) ? '&socid='.((int) $socid) : '')).($projectid > 0 ? '&projectid='.((int) $projectid) : '').($taskid > 0 ? '&taskid='.((int) $taskid) : '').'&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  $ref = $actioncomm->getNomUrl(1, -1);
262 
263  print '<tr class="oddeven">';
264 
265  // Ref
266  print '<td class="nowraponall">'.$ref.'</td>';
267 
268  // Onwer
269  print '<td class="nowraponall tdoverflowmax125">';
270  if (!empty($actioncomm->userownerid)) {
271  if (isset($cacheusers[$actioncomm->userownerid]) && is_object($cacheusers[$actioncomm->userownerid])) {
272  $tmpuser = $cacheusers[$actioncomm->userownerid];
273  } else {
274  $tmpuser = new User($this->db);
275  $tmpuser->fetch($actioncomm->userownerid);
276  $cacheusers[$actioncomm->userownerid] = $tmpuser;
277  }
278  if ($tmpuser->id > 0) {
279  print $tmpuser->getNomUrl(-1, '', 0, 0, 16, 0, 'firstelselast', '');
280  }
281  }
282  print '</td>';
283 
284  $actionstatic = $actioncomm;
285  // Type
286  $labeltype = $actionstatic->type_code;
287  if (empty($conf->global->AGENDA_USE_EVENT_TYPE) && empty($arraylist[$labeltype])) {
288  $labeltype = 'AC_OTH';
289  }
290  if ($actionstatic->type_code == 'AC_OTH' && $actionstatic->code == 'TICKET_MSG') {
291  $labeltype = $langs->trans("Message");
292  } else {
293  if (!empty($arraylist[$labeltype])) {
294  $labeltype = $arraylist[$labeltype];
295  }
296  if ($actionstatic->type_code == 'AC_OTH_AUTO' && ($actionstatic->type_code != $actionstatic->code) && $labeltype && !empty($arraylist[$actionstatic->code])) {
297  $labeltype .= ' - '.$arraylist[$actionstatic->code]; // Use code in priority on type_code
298  }
299  }
300  print '<td class="tdoverflowmax100" title="'.$labeltype.'">';
301  print $actioncomm->getTypePicto();
302  print $labeltype;
303  print '</td>';
304 
305  // Label
306  print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($actioncomm->label).'">'.$actioncomm->getNomUrl(0, 36).'</td>';
307 
308  // Date
309  print '<td class="center nowraponall">'.dol_print_date($actioncomm->datep, 'dayhour', 'tzuserrel');
310  if ($actioncomm->datef) {
311  $tmpa = dol_getdate($actioncomm->datep);
312  $tmpb = dol_getdate($actioncomm->datef);
313  if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
314  if ($tmpa['hours'] != $tmpb['hours'] || $tmpa['minutes'] != $tmpb['minutes']) {
315  print '-'.dol_print_date($actioncomm->datef, 'hour', 'tzuserrel');
316  }
317  } else {
318  print '-'.dol_print_date($actioncomm->datef, 'dayhour', 'tzuserrel');
319  }
320  }
321  print '</td>';
322  print '<td class="right">';
323  print $actioncomm->getLibStatut(3);
324  print '</td>';
325  print '</tr>';
326 
327  $cursorevent++;
328  }
329  } else {
330  print '<tr class="oddeven"><td colspan="6"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
331  }
332 
333  if ($max && $num > $max) {
334  print '<tr class="oddeven"><td colspan="6"><span class="opacitymedium">'.$langs->trans("More").'...</span></td></tr>';
335  }
336 
337  print '</table>';
338  print '</div>';
339  }
340 
341  return $num;
342  }
343 
344 
345  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
359  public function select_type_actions($selected = '', $htmlname = 'actioncode', $excludetype = '', $onlyautoornot = 0, $hideinfohelp = 0, $multiselect = 0, $nooutput = 0, $morecss = 'minwidth300')
360  {
361  // phpcs:enable
362  global $langs, $user, $form, $conf;
363 
364  if (!is_object($form)) {
365  $form = new Form($this->db);
366  }
367 
368  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
369  require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
370  $caction = new CActionComm($this->db);
371 
372  // Suggest a list with manual events or all auto events
373  $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.
374  if (empty($multiselect)) {
375  // Add empty line at start only if no multiselect
376  array_unshift($arraylist, '&nbsp;');
377  }
378  //asort($arraylist);
379 
380  if ($selected == 'manual') {
381  $selected = 'AC_OTH';
382  }
383  if ($selected == 'auto') {
384  $selected = 'AC_OTH_AUTO';
385  }
386 
387  if (!empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO)) {
388  unset($arraylist['AC_OTH_AUTO']);
389  }
390 
391  $out = '';
392 
393  if (!empty($multiselect)) {
394  if (!is_array($selected) && !empty($selected)) {
395  $selected = explode(',', $selected);
396  }
397  $out .= $form->multiselectarray($htmlname, $arraylist, $selected, 0, 0, 'centpercent', 0, 0);
398  } else {
399  $out .= $form->selectarray($htmlname, $arraylist, $selected, 0, 0, 0, '', 0, 0, 0, '', $morecss, 1);
400  }
401 
402  if ($user->admin && empty($onlyautoornot) && $hideinfohelp <= 0) {
403  $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup").($hideinfohelp == -1 ? ". ".$langs->trans("YouCanSetDefaultValueInModuleSetup") : ''), 1);
404  }
405 
406  if ($nooutput) {
407  return $out;
408  } else {
409  print $out;
410  }
411  return '';
412  }
413 }
Class to manage different types of events.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
Definition: card.php:142
Class to manage building of HTML components.
Class to manage agenda events (actions)
$conf db
API class for accounts.
Definition: inc.php:41
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.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
Definition: user.class.php:44
form_select_status_action($formname, $selected, $canedit=1, $htmlname= 'complete', $showempty=0, $onlyselect=0, $morecss= 'maxwidth100')
Show list of action status.
Class to manage generation of HTML components Only common components must be here.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin= '1', $morecss= 'hideonsmartphone', $textfordropdown= '')
Show information for admin users or standard users.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
__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.
dol_getdate($timestamp, $fast=false, $forcetimezone= '')
Return an array with locale date info.
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete= 'resolve', $idforemptyvalue= '-1')
Convert a html select field into an ajax combobox.
Definition: ajax.lib.php:429
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_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
showactions($object, $typeelement, $socid=0, $forceshowtitle=0, $morecss= 'listactions', $max=0, $moreparambacktopage= '', $morehtmlcenter= '')
Show list of actions for element.
isModEnabled($module)
Is Dolibarr module enabled.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip= '', $forcenowrapcolumntitle=0)
Get title line of an array.