dolibarr  13.0.2
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  '-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  } else {
151  print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat" value="'.($selected >= 0 ? $selected : '').'" size="2"'.($canedit ? '' : ' disabled').'>%';
152  }
153  }
154 
155 
169  public function showactions($object, $typeelement, $socid = 0, $forceshowtitle = 0, $morecss = 'listactions', $max = 0, $moreparambacktopage = '', $morehtmlcenter = '')
170  {
171  global $langs, $conf, $user;
172 
173  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
174 
175  $sortfield = 'a.datep,a.id';
176  $sortorder = 'DESC,DESC';
177 
178  $listofactions = ActionComm::getActions($this->db, $socid, $object->id, $typeelement, '', $sortfield, $sortorder, ($max ? ($max + 1) : 0));
179  if (!is_array($listofactions)) dol_print_error($this->db, 'FailedToGetActions');
180 
181  $num = count($listofactions);
182  if ($num || $forceshowtitle)
183  {
184  if ($typeelement == 'invoice') $title = $langs->trans('ActionsOnBill');
185  elseif ($typeelement == 'invoice_supplier' || $typeelement == 'supplier_invoice') $title = $langs->trans('ActionsOnBill');
186  elseif ($typeelement == 'propal') $title = $langs->trans('ActionsOnPropal');
187  elseif ($typeelement == 'supplier_proposal') $title = $langs->trans('ActionsOnSupplierProposal');
188  elseif ($typeelement == 'order') $title = $langs->trans('ActionsOnOrder');
189  elseif ($typeelement == 'order_supplier' || $typeelement == 'supplier_order') $title = $langs->trans('ActionsOnOrder');
190  elseif ($typeelement == 'shipping') $title = $langs->trans('ActionsOnShipping');
191  elseif ($typeelement == 'fichinter') $title = $langs->trans('ActionsOnFicheInter');
192  elseif ($typeelement == 'project') $title = $langs->trans('LatestLinkedEvents', $max ? $max : '');
193  elseif ($typeelement == 'task') $title = $langs->trans('LatestLinkedEvents', $max ? $max : '');
194  elseif ($typeelement == 'member') $title = $langs->trans('LatestLinkedEvents', $max ? $max : '');
195  else $title = $langs->trans("LatestLinkedEvents", $max ? $max : '');
196 
197  $urlbacktopage = $_SERVER['PHP_SELF'].'?id='.$object->id.($moreparambacktopage ? '&'.$moreparambacktopage : '');
198 
199  $projectid = $object->fk_project;
200  if ($typeelement == 'project') $projectid = $object->id;
201 
202  $newcardbutton = '';
203  if (!empty($conf->agenda->enabled) && !empty($user->rights->agenda->myactions->create))
204  {
205  $newcardbutton .= dolGetButtonTitle($langs->trans("AddEvent"), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create&amp;datep='.urlencode(dol_print_date(dol_now(), 'dayhourlog', 'tzuser')).'&amp;origin='.urlencode($typeelement).'&amp;originid='.$object->id.($object->socid > 0 ? '&amp;socid='.$object->socid : ($socid > 0 ? '&amp;socid='.$socid : '')).($projectid > 0 ? '&amp;projectid='.$projectid : '').'&amp;backtopage='.urlencode($urlbacktopage));
206  }
207 
208 
209  print '<!-- formactions->showactions -->'."\n";
210  print load_fiche_titre($title, $newcardbutton, '', 0, 0, '', $morehtmlcenter);
211 
212  $page = 0; $param = '';
213 
214  print '<div class="div-table-responsive-no-min">';
215  print '<table class="centpercent noborder'.($morecss ? ' '.$morecss : '').'">';
216  print '<tr class="liste_titre">';
217  print getTitleFieldOfList('Ref', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
218  print getTitleFieldOfList('By', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
219  print getTitleFieldOfList('Type', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
220  print getTitleFieldOfList('Title', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
221  print getTitleFieldOfList('Date', 0, $_SERVER["PHP_SELF"], 'a.datep', $page, $param, '', $sortfield, $sortorder, 'center ', 1);
222  print getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, 'right ', 1);
223  print '</tr>';
224  print "\n";
225 
226  if (is_array($listofactions) && count($listofactions))
227  {
228  $cacheusers = array();
229 
230  $cursorevent = 0;
231  foreach ($listofactions as $actioncomm)
232  {
233  if ($max && $cursorevent >= $max) break;
234 
235  $ref = $actioncomm->getNomUrl(1, -1);
236  $label = $actioncomm->getNomUrl(0, 36);
237 
238  print '<tr class="oddeven">';
239 
240  // Ref
241  print '<td class="nowraponall">'.$ref.'</td>';
242 
243  // Onwer
244  print '<td class="nowraponall tdoverflowmax125">';
245  if (!empty($actioncomm->userownerid))
246  {
247  if (is_object($cacheusers[$actioncomm->userownerid]))
248  {
249  $tmpuser = $cacheusers[$actioncomm->userownerid];
250  } else {
251  $tmpuser = new User($this->db);
252  $tmpuser->fetch($actioncomm->userownerid);
253  $cacheusers[$actioncomm->userownerid] = $tmpuser;
254  }
255  if ($tmpuser->id > 0)
256  {
257  print $tmpuser->getNomUrl(-1, '', 0, 0, 16, 0, 'firstelselast', '');
258  }
259  }
260  print '</td>';
261 
262  // Type
263  print '<td>';
264  // TODO Code common with code into comm/action/list.php
265  $imgpicto = '';
266  if (!empty($conf->global->AGENDA_USE_EVENT_TYPE))
267  {
268  if ($actioncomm->type_picto) {
269  $imgpicto = img_picto('', $actioncomm->type_picto);
270  } else {
271  if ($actioncomm->type_code == 'AC_RDV') $imgpicto = img_picto('', 'object_group', '', false, 0, 0, '', 'paddingright');
272  elseif ($actioncomm->type_code == 'AC_TEL') $imgpicto = img_picto('', 'object_phoning', '', false, 0, 0, '', 'paddingright');
273  elseif ($actioncomm->type_code == 'AC_FAX') $imgpicto = img_picto('', 'object_phoning_fax', '', false, 0, 0, '', 'paddingright');
274  elseif ($actioncomm->type_code == 'AC_EMAIL') $imgpicto = img_picto('', 'object_email', '', false, 0, 0, '', 'paddingright');
275  elseif ($actioncomm->type_code == 'AC_INT') $imgpicto = img_picto('', 'object_intervention', '', false, 0, 0, '', 'paddingright');
276  elseif ($actioncomm->type_code == 'AC_OTH' && $actioncomm->code == 'TICKET_MSG') $imgpicto = img_picto('', 'object_conversation', '', false, 0, 0, '', 'paddingright');
277  elseif (!preg_match('/_AUTO/', $actioncomm->type_code)) $imgpicto = img_picto('', 'object_action', '', false, 0, 0, '', 'paddingright');
278  }
279  }
280  print $imgpicto;
281  if ($actioncomm->type_code == 'AC_OTH' && $actioncomm->code == 'TICKET_MSG') {
282  print $langs->trans("Message");
283  } else {
284  print $actioncomm->type_short ? $actioncomm->type_short : $actioncomm->type;
285  }
286  print '</td>';
287 
288  // Label
289  print '<td>'.$label.'</td>';
290 
291  // Date
292  print '<td class="center">'.dol_print_date($actioncomm->datep, 'dayhour', 'tzuserrel');
293  if ($actioncomm->datef)
294  {
295  $tmpa = dol_getdate($actioncomm->datep);
296  $tmpb = dol_getdate($actioncomm->datef);
297  if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year'])
298  {
299  if ($tmpa['hours'] != $tmpb['hours'] || $tmpa['minutes'] != $tmpb['minutes'] && $tmpa['seconds'] != $tmpb['seconds']) print '-'.dol_print_date($actioncomm->datef, 'hour', 'tzuserrel');
300  } else print '-'.dol_print_date($actioncomm->datef, 'dayhour', 'tzuserrel');
301  }
302  print '</td>';
303  print '<td class="right">';
304  print $actioncomm->getLibStatut(3);
305  print '</td>';
306  print '</tr>';
307 
308  $cursorevent++;
309  }
310  } else {
311  print '<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
312  }
313 
314  if ($max && $num > $max)
315  {
316  print '<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans("More").'...</td></tr>';
317  }
318 
319  print '</table>';
320  print '</div>';
321  }
322 
323  return $num;
324  }
325 
326 
327  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
341  public function select_type_actions($selected = '', $htmlname = 'actioncode', $excludetype = '', $onlyautoornot = 0, $hideinfohelp = 0, $multiselect = 0, $nooutput = 0, $morecss = '')
342  {
343  // phpcs:enable
344  global $langs, $user, $form, $conf;
345 
346  if (!is_object($form)) $form = new Form($this->db);
347 
348  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
349  require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
350  $caction = new CActionComm($this->db);
351 
352  // Suggest a list with manual events or all auto events
353  $arraylist = $caction->liste_array(1, 'code', $excludetype, $onlyautoornot);
354  if (empty($multiselect)) {
355  // Add empty line at start only if no multiselect
356  array_unshift($arraylist, '&nbsp;');
357  }
358  //asort($arraylist);
359 
360  if ($selected == 'manual') $selected = 'AC_OTH';
361  if ($selected == 'auto') $selected = 'AC_OTH_AUTO';
362 
363  if (!empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO)) unset($arraylist['AC_OTH_AUTO']);
364 
365  $out = '';
366 
367  if (!empty($multiselect))
368  {
369  if (!is_array($selected) && !empty($selected)) $selected = explode(',', $selected);
370  $out .= $form->multiselectarray($htmlname, $arraylist, $selected, 0, 0, 'centpercent', 0, 0);
371  } else {
372  $out .= $form->selectarray($htmlname, $arraylist, $selected, 0, 0, 0, '', 0, 0, 0, '', 'minwidth200'.($morecss ? ' '.$morecss : ''), 1);
373  }
374 
375  if ($user->admin && empty($onlyautoornot) && $hideinfohelp <= 0)
376  {
377  $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup").($hideinfohelp == -1 ? ". ".$langs->trans("YouCanSetDefaultValueInModuleSetup") : ''), 1);
378  }
379 
380  if ($nooutput) return $out;
381  else print $out;
382  return '';
383  }
384 }
Class to manage different types of events.
Class to manage building of HTML components.
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.
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.
$conf db
API class for accounts.
Definition: inc.php:54
Class to manage generation of HTML components Only common components must be here.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
__construct($db)
Constructor.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
select_type_actions($selected= '', $htmlname= 'actioncode', $excludetype= '', $onlyautoornot=0, $hideinfohelp=0, $multiselect=0, $nooutput=0, $morecss= '')
Output html select list of type of event.
dol_getdate($timestamp, $fast=false, $forcetimezone= '')
Return an array with locale date info.
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $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_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
showactions($object, $typeelement, $socid=0, $forceshowtitle=0, $morecss= 'listactions', $max=0, $moreparambacktopage= '', $morehtmlcenter= '')
Show list of actions for element.
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= '', $textfordropdown= '')
Show information for admin users or standard users.