dolibarr  9.0.0
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 <http://www.gnu.org/licenses/>.
18  */
19 
31 {
35  public $db;
36 
40  public $error='';
41 
42 
48  function __construct($db)
49  {
50  $this->db = $db;
51  }
52 
53 
54  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
67  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  '-1' => $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  {
82  print "\n";
83  print "<script type=\"text/javascript\">
84  var htmlname = '".$htmlname."';
85 
86  $(document).ready(function () {
87  select_status();
88 
89  $('#select' + htmlname).change(function() {
90  select_status();
91  });
92  // FIXME use another method for update combobox
93  //$('#val' + htmlname).change(function() {
94  //select_status();
95  //});
96  });
97 
98  function select_status() {
99  var defaultvalue = $('#select' + htmlname).val();
100  var percentage = $('input[name=percentage]');
101  var selected = '".(isset($selected)?$selected:'')."';
102  var value = (selected>0?selected:(defaultvalue>=0?defaultvalue:''));
103 
104  percentage.val(value);
105 
106  if (defaultvalue == -1) {
107  percentage.prop('disabled', true);
108  $('.hideifna').hide();
109  }
110  else if (defaultvalue == 0) {
111  percentage.val(0);
112  percentage.removeAttr('disabled'); /* Not disabled, we want to change it to higher value */
113  $('.hideifna').show();
114  }
115  else if (defaultvalue == 100) {
116  percentage.val(100);
117  percentage.prop('disabled', true);
118  $('.hideifna').show();
119  }
120  else {
121  if (defaultvalue == 50 && (percentage.val() == 0 || percentage.val() == 100)) { percentage.val(50) };
122  percentage.removeAttr('disabled');
123  $('.hideifna').show();
124  }
125  }
126  </script>\n";
127  }
128  if (! empty($conf->use_javascript_ajax) || $onlyselect)
129  {
130  //var_dump($selected);
131  if ($selected == 'done') $selected='100';
132  print '<select '.($canedit?'':'disabled ').'name="'.$htmlname.'" id="select'.$htmlname.'" class="flat'.($morecss?' '.$morecss:'').'">';
133  if ($showempty) print '<option value=""'.($selected == ''?' selected':'').'></option>';
134  foreach($listofstatus as $key => $val)
135  {
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  {
139  print '<option value="todo"'.($selected == 'todo' ? ' selected' : '').'>'.$langs->trans("ActionUncomplete").' ('.$langs->trans("ActionsToDoShort")."+".$langs->trans("ActionRunningShort").')</option>';
140  }
141  }
142  print '</select>';
143  if ($selected == 0 || $selected == 100) $canedit=0;
144 
145  if (empty($onlyselect))
146  {
147  print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat hideifna" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit&&($selected>=0)?'':' disabled').'>';
148  print '<span class="hideonsmartphone hideifna">%</span>';
149  }
150  }
151  else
152  {
153  print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit?'':' disabled').'>%';
154  }
155  }
156 
157 
171  function showactions($object, $typeelement, $socid=0, $forceshowtitle=0, $morecss='listactions', $max=0, $moreparambacktopage='', $morehtmlright='')
172  {
173  global $langs,$conf,$user;
174  global $bc;
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  $listofactions=ActionComm::getActions($this->db, $socid, $object->id, $typeelement, '', $sortfield, $sortorder, ($max?($max+1):0));
182  if (! is_array($listofactions)) dol_print_error($this->db,'FailedToGetActions');
183 
184  $num = count($listofactions);
185  if ($num || $forceshowtitle)
186  {
187  if ($typeelement == 'invoice') $title=$langs->trans('ActionsOnBill');
188  elseif ($typeelement == 'invoice_supplier' || $typeelement == 'supplier_invoice') $title=$langs->trans('ActionsOnBill');
189  elseif ($typeelement == 'propal') $title=$langs->trans('ActionsOnPropal');
190  elseif ($typeelement == 'supplier_proposal') $title=$langs->trans('ActionsOnSupplierProposal');
191  elseif ($typeelement == 'order') $title=$langs->trans('ActionsOnOrder');
192  elseif ($typeelement == 'order_supplier' || $typeelement == 'supplier_order') $title=$langs->trans('ActionsOnOrder');
193  elseif ($typeelement == 'shipping') $title=$langs->trans('ActionsOnShipping');
194  elseif ($typeelement == 'fichinter') $title=$langs->trans('ActionsOnFicheInter');
195  elseif ($typeelement == 'project') $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
196  elseif ($typeelement == 'task') $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
197  elseif ($typeelement == 'member') $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
198  else $title=$langs->trans("LatestLinkedEvents", $max?$max:'');
199 
200  $urlbacktopage=$_SERVER['PHP_SELF'].'?id='.$object->id.($moreparambacktopage?'&'.$moreparambacktopage:'');
201 
202  $projectid = $object->fk_project;
203  if ($typeelement == 'project') $projectid = $object->id;
204 
205  $newcardbutton='';
206  if (! empty($conf->agenda->enabled))
207  {
208  $newcardbutton = '<a class="butActionNew" href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&datep='.dol_print_date(dol_now(),'dayhourlog').'&origin='.$typeelement.'&originid='.$object->id.($object->socid>0?'&socid='.$object->socid:($socid>0?'&socid='.$socid:'')).($projectid>0?'&projectid='.$projectid:'').'&backtopage='.urlencode($urlbacktopage).'"><span class="valignmiddle">'.$langs->trans("AddEvent").'</span>';
209  $newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
210  $newcardbutton.= '</a>';
211  }
212 
213  print '<!-- formactions->showactions -->'."\n";
214  print load_fiche_titre($title, $newcardbutton, '', 0, 0, '', $morehtmlright);
215 
216  $page=0; $param='';
217 
218  $total = 0;
219 
220  print '<div class="div-table-responsive-no-min">';
221  print '<table class="noborder'.($morecss?' '.$morecss:'').'" width="100%">';
222  print '<tr class="liste_titre">';
223  print getTitleFieldOfList('Ref', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
224  print getTitleFieldOfList('By', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
225  print getTitleFieldOfList('Type', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
226  print getTitleFieldOfList('Title', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
227  print getTitleFieldOfList('Date', 0, $_SERVER["PHP_SELF"], 'a.datep', $page, $param, 'align="center"', $sortfield, $sortorder, '', 1);
228  print getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', $page, $param, 'align="right"', $sortfield, $sortorder, '', 1);
229  print '</tr>';
230  print "\n";
231 
232  $userstatic = new User($this->db);
233 
234  if (count($listofactions))
235  {
236  $cursorevent = 0;
237  foreach($listofactions as $action)
238  {
239  if ($max && $cursorevent >= $max) break;
240 
241  $ref=$action->getNomUrl(1,-1);
242  $label=$action->getNomUrl(0,38);
243 
244  print '<tr class="oddeven">';
245  // Ref
246  print '<td class="nowraponall">'.$ref.'</td>';
247  // Onwer
248  print '<td>';
249  if (! empty($action->userownerid))
250  {
251  $userstatic->fetch($action->userownerid); // TODO Introduce a cache on users fetched
252  print $userstatic->getNomUrl(-1, '', 0, 0, 16, 0, '', '');
253  }
254  print '</td>';
255  // Type
256  print '<td>';
257  $imgpicto='';
258  if (! empty($conf->global->AGENDA_USE_EVENT_TYPE))
259  {
260  if ($action->type_picto) $imgpicto=img_picto('', $action->type_picto);
261  else {
262  if ($action->type_code == 'AC_RDV') $imgpicto=img_picto('', 'object_group', '', false, 0, 0, '', 'paddingright').' ';
263  elseif ($action->type_code == 'AC_TEL') $imgpicto=img_picto('', 'object_phoning', '', false, 0, 0, '', 'paddingright').' ';
264  elseif ($action->type_code == 'AC_FAX') $imgpicto=img_picto('', 'object_phoning_fax', '', false, 0, 0, '', 'paddingright').' ';
265  elseif ($action->type_code == 'AC_EMAIL') $imgpicto=img_picto('', 'object_email', '', false, 0, 0, '', 'paddingright').' ';
266  elseif ($action->type_code == 'AC_INT') $imgpicto=img_picto('', 'object_intervention', '', false, 0, 0, '', 'paddingright').' ';
267  elseif (! preg_match('/_AUTO/', $action->type_code)) $imgpicto=img_picto('', 'object_action', '', false, 0, 0, '', 'paddingright').' ';
268  }
269  }
270  print $imgpicto;
271  print $action->type_short ? $action->type_short : $action->type;
272  print '</td>';
273  // Label
274  print '<td>'.$label.'</td>';
275  // Date
276  print '<td align="center">'.dol_print_date($action->datep, 'dayhour', 'tzuserrel');
277  if ($action->datef)
278  {
279  $tmpa=dol_getdate($action->datep);
280  $tmpb=dol_getdate($action->datef);
281  if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year'])
282  {
283  if ($tmpa['hours'] != $tmpb['hours'] || $tmpa['minutes'] != $tmpb['minutes'] && $tmpa['seconds'] != $tmpb['seconds']) print '-'.dol_print_date($action->datef, 'hour', 'tzuserrel');
284  }
285  else print '-'.dol_print_date($action->datef, 'dayhour', 'tzuserrel');
286  }
287  print '</td>';
288  print '<td align="right">';
289  if (! empty($action->author->id))
290  {
291  print $action->getLibStatut(3);
292  }
293  print '</td>';
294  print '</tr>';
295 
296  $cursorevent++;
297  }
298  }
299  else
300  {
301  print '<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
302  }
303 
304  if ($max && $num > $max)
305  {
306  print '<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans("More").'...</td></tr>';
307  }
308 
309  print '</table>';
310  print '</div>';
311  }
312 
313  return $num;
314  }
315 
316 
317  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
330  function select_type_actions($selected='', $htmlname='actioncode', $excludetype='', $onlyautoornot=0, $hideinfohelp=0, $multiselect=0, $nooutput=0)
331  {
332  // phpcs:enable
333  global $langs,$user,$form,$conf;
334 
335  if (! is_object($form)) $form=new Form($this->db);
336 
337  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
338  require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
339  $caction=new CActionComm($this->db);
340 
341  // Suggest a list with manual events or all auto events
342  $arraylist=$caction->liste_array(1, 'code', $excludetype, $onlyautoornot);
343  array_unshift($arraylist,'&nbsp;'); // Add empty line at start
344  //asort($arraylist);
345 
346  if ($selected == 'manual') $selected='AC_OTH';
347  if ($selected == 'auto') $selected='AC_OTH_AUTO';
348 
349  if (! empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO)) unset($arraylist['AC_OTH_AUTO']);
350 
351  $out='';
352 
353  if (! empty($multiselect))
354  {
355  if (!is_array($selected) && !empty($selected)) $selected = explode(',', $selected);
356  $out.=$form->multiselectarray($htmlname, $arraylist, $selected, 0, 0, 'centpercent', 0, 0);
357  }
358  else
359  {
360  $out.=$form->selectarray($htmlname, $arraylist, $selected, 0, 0, 0, '', 0, 0, 0, '', 'minwidth200', 1);
361  }
362 
363  if ($user->admin && empty($onlyautoornot) && $hideinfohelp <= 0)
364  {
365  $out.=info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup").($hideinfohelp == -1 ? ". ".$langs->trans("YouCanSetDefaultValueInModuleSetup") : ''),1);
366  }
367 
368  if ($nooutput) return $out;
369  else print $out;
370  return '';
371  }
372 }
Class to manage different types of events.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
print
Draft customers invoices.
Definition: index.php:91
Class to manage building of HTML components.
Class to manage Dolibarr users.
Definition: user.class.php:41
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
Class to manage generation of HTML components Only common components must be here.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='')
Get title line of an array.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='')
Show information for admin users or standard users.
__construct($db)
Constructor.
select_type_actions($selected='', $htmlname='actioncode', $excludetype='', $onlyautoornot=0, $hideinfohelp=0, $multiselect=0, $nooutput=0)
Output html select list of type of event.
dol_now($mode='gmt')
Return date for now.
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
static getActions($db, $socid=0, $fk_element=0, $elementtype='', $filter='', $sortfield='a.datep', $sortorder='DESC', $limit=0)
Load all objects with filters.
dol_getdate($timestamp, $fast=false)
Return an array with locale date info.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it&#39;s its name (generic function)
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='', $morehtmlright='')
Show list of actions for element.