dolibarr  7.0.0-beta
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@capnetworks.com>
4  * Copyright (C) 2010 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 {
32  var $db;
33  var $error;
34 
35 
41  function __construct($db)
42  {
43  $this->db = $db;
44  return 1;
45  }
46 
47 
60  function form_select_status_action($formname, $selected, $canedit=1, $htmlname='complete', $showempty=0, $onlyselect=0, $morecss='maxwidth100')
61  {
62  global $langs,$conf;
63 
64  $listofstatus = array(
65  '-1' => $langs->trans("ActionNotApplicable"),
66  '0' => $langs->trans("ActionsToDoShort"),
67  '50' => $langs->trans("ActionRunningShort"),
68  '100' => $langs->trans("ActionDoneShort")
69  );
70  // +ActionUncomplete
71 
72  if (! empty($conf->use_javascript_ajax))
73  {
74  print "\n";
75  print "<script type=\"text/javascript\">
76  var htmlname = '".$htmlname."';
77 
78  $(document).ready(function () {
79  select_status();
80 
81  $('#select' + htmlname).change(function() {
82  select_status();
83  });
84  // FIXME use another method for update combobox
85  //$('#val' + htmlname).change(function() {
86  //select_status();
87  //});
88  });
89 
90  function select_status() {
91  var defaultvalue = $('#select' + htmlname).val();
92  var percentage = $('input[name=percentage]');
93  var selected = '".(isset($selected)?$selected:'')."';
94  var value = (selected>0?selected:(defaultvalue>=0?defaultvalue:''));
95 
96  percentage.val(value);
97 
98  if (defaultvalue == -1) {
99  percentage.prop('disabled', true);
100  $('.hideifna').hide();
101  }
102  else if (defaultvalue == 0) {
103  percentage.val(0);
104  percentage.removeAttr('disabled'); /* Not disabled, we want to change it to higher value */
105  $('.hideifna').show();
106  }
107  else if (defaultvalue == 100) {
108  percentage.val(100);
109  percentage.prop('disabled', true);
110  $('.hideifna').show();
111  }
112  else {
113  if (defaultvalue == 50 && (percentage.val() == 0 || percentage.val() == 100)) { percentage.val(50) };
114  percentage.removeAttr('disabled');
115  $('.hideifna').show();
116  }
117  }
118  </script>\n";
119  }
120  if (! empty($conf->use_javascript_ajax) || $onlyselect)
121  {
122  //var_dump($selected);
123  if ($selected == 'done') $selected='100';
124  print '<select '.($canedit?'':'disabled ').'name="'.$htmlname.'" id="select'.$htmlname.'" class="flat'.($morecss?' '.$morecss:'').'">';
125  if ($showempty) print '<option value=""'.($selected == ''?' selected':'').'></option>';
126  foreach($listofstatus as $key => $val)
127  {
128  print '<option value="'.$key.'"'.(($selected == $key && strlen($selected) == strlen($key)) || (($selected > 0 && $selected < 100) && $key == '50') ? ' selected' : '').'>'.$val.'</option>';
129  if ($key == '50' && $onlyselect == 2)
130  {
131  print '<option value="todo"'.($selected == 'todo' ? ' selected' : '').'>'.$langs->trans("ActionUncomplete").' ('.$langs->trans("ActionsToDoShort")."+".$langs->trans("ActionRunningShort").')</option>';
132  }
133  }
134  print '</select>';
135  if ($selected == 0 || $selected == 100) $canedit=0;
136 
137  if (empty($onlyselect))
138  {
139  print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat hideifna" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit&&($selected>=0)?'':' disabled').'>';
140  print '<span class="hideonsmartphone hideifna">%</span>';
141  }
142  }
143  else
144  {
145  print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit?'':' disabled').'>%';
146  }
147  }
148 
149 
163  function showactions($object, $typeelement, $socid=0, $forceshowtitle=0, $morecss='listactions', $max=0, $moreparambacktopage='', $morehtmlright='')
164  {
165  global $langs,$conf,$user;
166  global $bc;
167 
168  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
169 
170  $sortfield='a.datep,a.id';
171  $sortorder='DESC,DESC';
172 
173  $listofactions=ActionComm::getActions($this->db, $socid, $object->id, $typeelement, '', $sortfield, $sortorder, ($max?($max+1):0));
174  if (! is_array($listofactions)) dol_print_error($this->db,'FailedToGetActions');
175 
176  $num = count($listofactions);
177  if ($num || $forceshowtitle)
178  {
179  if ($typeelement == 'invoice') $title=$langs->trans('ActionsOnBill');
180  elseif ($typeelement == 'invoice_supplier' || $typeelement == 'supplier_invoice') $title=$langs->trans('ActionsOnBill');
181  elseif ($typeelement == 'propal') $title=$langs->trans('ActionsOnPropal');
182  elseif ($typeelement == 'supplier_proposal') $title=$langs->trans('ActionsOnSupplierProposal');
183  elseif ($typeelement == 'order') $title=$langs->trans('ActionsOnOrder');
184  elseif ($typeelement == 'order_supplier' || $typeelement == 'supplier_order') $title=$langs->trans('ActionsOnOrder');
185  elseif ($typeelement == 'shipping') $title=$langs->trans('ActionsOnShipping');
186  elseif ($typeelement == 'fichinter') $title=$langs->trans('ActionsOnFicheInter');
187  elseif ($typeelement == 'project') $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
188  elseif ($typeelement == 'task') $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
189  elseif ($typeelement == 'member') $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
190  else $title=$langs->trans("LatestLinkedEvents", $max?$max:'');
191 
192  $urlbacktopage=$_SERVER['PHP_SELF'].'?id='.$object->id.($moreparambacktopage?'&'.$moreparambacktopage:'');
193 
194  $projectid = $object->fk_project;
195  if ($typeelement == 'project') $projectid = $object->id;
196 
197  $buttontoaddnewevent = '<a 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:'').($projectid>0?'&projectid='.$projectid:'').'&backtopage='.urlencode($urlbacktopage).'">';
198  $buttontoaddnewevent.= $langs->trans("AddEvent");
199  $buttontoaddnewevent.= '</a>';
200 
201  print '<!-- formactions->showactions -->'."\n";
202  print load_fiche_titre($title, $buttontoaddnewevent, '', 0, 0, '', $morehtmlright);
203 
204  $page=0; $param='';
205 
206  $total = 0;
207 
208  print '<div class="div-table-responsive-no-min">';
209  print '<table class="noborder'.($morecss?' '.$morecss:'').'" width="100%">';
210  print '<tr class="liste_titre">';
211  print getTitleFieldOfList('Ref', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
212  print getTitleFieldOfList('By', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
213  print getTitleFieldOfList('Type', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
214  print getTitleFieldOfList('Title', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
215  print getTitleFieldOfList('Date', 0, $_SERVER["PHP_SELF"], 'a.datep', $page, $param, 'align="center"', $sortfield, $sortorder, '', 1);
216  print getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', $page, $param, 'align="right"', $sortfield, $sortorder, '', 1);
217  print '</tr>';
218  print "\n";
219 
220  $userstatic = new User($this->db);
221 
222  if (count($listofactions))
223  {
224  $cursorevent = 0;
225  foreach($listofactions as $action)
226  {
227  if ($max && $cursorevent >= $max) break;
228 
229  $ref=$action->getNomUrl(1,-1);
230  $label=$action->getNomUrl(0,38);
231 
232  print '<tr class="oddeven">';
233  // Ref
234  print '<td>'.$ref.'</td>';
235  // Onwer
236  print '<td>';
237  if (! empty($action->userownerid))
238  {
239  $userstatic->fetch($action->userownerid); // TODO Introduce a cache on users fetched
240  print $userstatic->getNomUrl(-1, '', 0, 0, 16, 0, '', '');
241  }
242  print '</td>';
243  // Type
244  print '<td>';
245  $imgpicto='';
246  if (! empty($conf->global->AGENDA_USE_EVENT_TYPE))
247  {
248  if ($action->type_picto) $imgpicto=img_picto('', $action->type_picto);
249  else {
250  if ($action->type_code == 'AC_RDV') $imgpicto=img_picto('', 'object_group', '', false, 0, 0, '', 'paddingright').' ';
251  elseif ($action->type_code == 'AC_TEL') $imgpicto=img_picto('', 'object_phoning', '', false, 0, 0, '', 'paddingright').' ';
252  elseif ($action->type_code == 'AC_FAX') $imgpicto=img_picto('', 'object_phoning_fax', '', false, 0, 0, '', 'paddingright').' ';
253  elseif ($action->type_code == 'AC_EMAIL') $imgpicto=img_picto('', 'object_email', '', false, 0, 0, '', 'paddingright').' ';
254  elseif ($action->type_code == 'AC_INT') $imgpicto=img_picto('', 'object_intervention', '', false, 0, 0, '', 'paddingright').' ';
255  elseif (! preg_match('/_AUTO/', $action->type_code)) $imgpicto=img_picto('', 'object_action', '', false, 0, 0, '', 'paddingright').' ';
256  }
257  }
258  print $imgpicto;
259  print $action->type_short ? $action->type_short : $action->type;
260  print '</td>';
261  // Label
262  print '<td>'.$label.'</td>';
263  // Date
264  print '<td align="center">'.dol_print_date($action->datep, 'dayhour', 'tzuserrel');
265  if ($action->datef)
266  {
267  $tmpa=dol_getdate($action->datep);
268  $tmpb=dol_getdate($action->datef);
269  if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year'])
270  {
271  if ($tmpa['hours'] != $tmpb['hours'] || $tmpa['minutes'] != $tmpb['minutes'] && $tmpa['seconds'] != $tmpb['seconds']) print '-'.dol_print_date($action->datef, 'hour', 'tzuserrel');
272  }
273  else print '-'.dol_print_date($action->datef, 'dayhour', 'tzuserrel');
274  }
275  print '</td>';
276  print '<td align="right">';
277  if (! empty($action->author->id))
278  {
279  print $action->getLibStatut(3);
280  }
281  print '</td>';
282  print '</tr>';
283 
284  $cursorevent++;
285  }
286  }
287  else
288  {
289  print '<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
290  }
291 
292  if ($max && $num > $max)
293  {
294  print '<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans("More").'...</td></tr>';
295  }
296 
297  print '</table>';
298  print '</div>';
299  }
300 
301  return $num;
302  }
303 
304 
317  function select_type_actions($selected='', $htmlname='actioncode', $excludetype='', $onlyautoornot=0, $hideinfohelp=0, $multiselect=0, $nooutput=0)
318  {
319  global $langs,$user,$form,$conf;
320 
321  if (! is_object($form)) $form=new Form($db);
322 
323  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
324  require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
325  $caction=new CActionComm($this->db);
326 
327  // Suggest a list with manual events or all auto events
328  $arraylist=$caction->liste_array(1, 'code', $excludetype, $onlyautoornot);
329  array_unshift($arraylist,'&nbsp;'); // Add empty line at start
330  //asort($arraylist);
331 
332  if ($selected == 'manual') $selected='AC_OTH';
333  if ($selected == 'auto') $selected='AC_OTH_AUTO';
334 
335  if (! empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO)) unset($arraylist['AC_OTH_AUTO']);
336 
337  $out='';
338 
339  if (! empty($multiselect))
340  {
341  if (!is_array($selected) && !empty($selected)) $selected = explode(',', $selected);
342  $out.=$form->multiselectarray($htmlname, $arraylist, $selected, 0, 0, 'centpercent', 0, 0);
343  }
344  else
345  {
346  $out.=$form->selectarray($htmlname, $arraylist, $selected, 0, 0, 0, '', 0, 0, 0, '', '', 1);
347  }
348 
349  if ($user->admin && empty($onlyautoornot) && $hideinfohelp <= 0)
350  {
351  $out.=info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup").($hideinfohelp == -1 ? ". ".$langs->trans("YouCanSetDefaultValueInModuleSetup") : ''),1);
352  }
353 
354  if ($nooutput) return $out;
355  else print $out;
356  return '';
357  }
358 
359 }
Class to manage different types of events.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it's its name (generic function)
Class to manage building of HTML components.
Class to manage Dolibarr users.
Definition: user.class.php:39
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
if(empty($reshook)) $form
View.
Definition: perms.php:103
Class to manage generation of HTML components Only common components must be here.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1')
Show information for admin users or standard users.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='')
Get title line of an array.
__construct($db)
Constructor.
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
select_type_actions($selected='', $htmlname='actioncode', $excludetype='', $onlyautoornot=0, $hideinfohelp=0, $multiselect=0, $nooutput=0)
Output html select list of type of event.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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).
print
Draft customers invoices.
Definition: index.php:91
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.
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.