dolibarr  13.0.2
html.formresource.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) - 2013-2015 Jean-François FERRY <jfefe@aternatik.fr>
3  * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  * or see https://www.gnu.org/
18  */
19 
25 require_once DOL_DOCUMENT_ROOT."/core/class/html.form.class.php";
26 require_once DOL_DOCUMENT_ROOT."/resource/class/dolresource.class.php";
27 
28 
36 {
40  public $db;
41 
42  public $substit = array();
43 
44  public $param = array();
45 
49  public $error = '';
50 
51 
57  public function __construct($db)
58  {
59  $this->db = $db;
60  }
61 
62 
63  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
80  public function select_resource_list($selected = '', $htmlname = 'fk_resource', $filter = '', $showempty = 0, $showtype = 0, $forcecombo = 0, $event = array(), $filterkey = '', $outputmode = 0, $limit = 20, $morecss = '')
81  {
82  // phpcs:enable
83  global $conf, $user, $langs;
84 
85  $out = '';
86  $outarray = array();
87 
88  $resourcestat = new Dolresource($this->db);
89 
90  $resources_used = $resourcestat->fetch_all('ASC', 't.rowid', $limit, 0, $filter);
91 
92  if ($outputmode != 2)
93  {
94  $out = '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
95  $out .= '<input type="hidden" name="token" value="'.newToken().'">';
96  }
97 
98  if ($resourcestat)
99  {
100  if (!empty($conf->use_javascript_ajax) && !empty($conf->global->RESOURCE_USE_SEARCH_TO_SELECT) && !$forcecombo)
101  {
102  //$minLength = (is_numeric($conf->global->RESOURCE_USE_SEARCH_TO_SELECT)?$conf->global->RESOURCE_USE_SEARCH_TO_SELECT:2);
103  $out .= ajax_combobox($htmlname, $event, $conf->global->RESOURCE_USE_SEARCH_TO_SELECT);
104  } else {
105  $out .= ajax_combobox($htmlname);
106  }
107 
108  // Construct $out and $outarray
109  $out .= '<select id="'.$htmlname.'" class="flat minwidth100'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'">'."\n";
110  if ($showempty) $out .= '<option value="-1">&nbsp;</option>'."\n";
111 
112  $num = 0;
113  if (is_array($resourcestat->lines)) $num = count($resourcestat->lines);
114 
115  //var_dump($resourcestat->lines);
116  $i = 0;
117  if ($num)
118  {
119  while ($i < $num)
120  {
121  $resourceclass = ucfirst($resourcestat->lines[$i]->element);
122 
123  $label = $resourcestat->lines[$i]->ref ? $resourcestat->lines[$i]->ref : ''.$resourcestat->lines[$i]->label;
124  if ($resourceclass != 'Dolresource') $label .= ' ('.$langs->trans($resourceclass).')';
125 
126  if ($selected > 0 && $selected == $resourcestat->lines[$i]->id)
127  {
128  $out .= '<option value="'.$resourcestat->lines[$i]->id.'" selected>'.$label.'</option>';
129  } else {
130  $out .= '<option value="'.$resourcestat->lines[$i]->id.'">'.$label.'</option>';
131  }
132 
133  array_push($outarray, array('key'=>$resourcestat->lines[$i]->id, 'value'=>$resourcestat->lines[$i]->label, 'label'=>$resourcestat->lines[$i]->label));
134 
135  $i++;
136  if (($i % 10) == 0) $out .= "\n";
137  }
138  }
139  $out .= '</select>'."\n";
140 
141  if ($outputmode != 2)
142  {
143  $out .= '<input type="submit" class="button" value="'.$langs->trans("Search").'"> &nbsp; &nbsp; ';
144 
145  $out .= '</form>';
146  }
147  } else {
148  dol_print_error($this->db);
149  }
150 
151  if ($outputmode && $outputmode != 2) return $outarray;
152  return $out;
153  }
154 
155  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
168  public function select_types_resource($selected = '', $htmlname = 'type_resource', $filtertype = '', $format = 0, $empty = 0, $noadmininfo = 0, $maxlength = 0)
169  {
170  // phpcs:enable
171  global $langs, $user;
172 
173  $resourcestat = new Dolresource($this->db);
174 
175  dol_syslog(get_class($this)."::select_types_resource ".$selected.", ".$htmlname.", ".$filtertype.", ".$format, LOG_DEBUG);
176 
177  $filterarray = array();
178 
179  if ($filtertype != '' && $filtertype != '-1') $filterarray = explode(',', $filtertype);
180 
181  $resourcestat->load_cache_code_type_resource();
182  print '<select id="select'.$htmlname.'" class="flat maxwidthonsmartphone select_'.$htmlname.'" name="'.$htmlname.'">';
183  if ($empty) print '<option value="">&nbsp;</option>';
184  if (is_array($resourcestat->cache_code_type_resource) && count($resourcestat->cache_code_type_resource))
185  {
186  foreach ($resourcestat->cache_code_type_resource as $id => $arraytypes)
187  {
188  // We discard empty line if showempty is on because an empty line has already been output.
189  if ($empty && empty($arraytypes['code'])) continue;
190 
191  if ($format == 0) print '<option value="'.$id.'"';
192  elseif ($format == 1) print '<option value="'.$arraytypes['code'].'"';
193  elseif ($format == 2) print '<option value="'.$arraytypes['code'].'"';
194  elseif ($format == 3) print '<option value="'.$id.'"';
195  // Si selected est text, on compare avec code, sinon avec id
196  if (preg_match('/[a-z]/i', $selected) && $selected == $arraytypes['code']) print ' selected';
197  elseif ($selected == $id) print ' selected';
198  print '>';
199  if ($format == 0) $value = ($maxlength ?dol_trunc($arraytypes['label'], $maxlength) : $arraytypes['label']);
200  elseif ($format == 1) $value = $arraytypes['code'];
201  elseif ($format == 2) $value = ($maxlength ?dol_trunc($arraytypes['label'], $maxlength) : $arraytypes['label']);
202  elseif ($format == 3) $value = $arraytypes['code'];
203  print $value ? $value : '&nbsp;';
204  print '</option>';
205  }
206  }
207  print '</select>';
208  if ($user->admin && !$noadmininfo) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
209  }
210 }
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete= 'resolve')
Convert a html select field into an ajax combobox.
Definition: ajax.lib.php:391
$conf db
API class for accounts.
Definition: inc.php:54
Classe permettant la gestion des formulaire du module resource.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
__construct($db)
Constructor.
select_types_resource($selected= '', $htmlname= 'type_resource', $filtertype= '', $format=0, $empty=0, $noadmininfo=0, $maxlength=0)
Return html list of tickets type.
print
Draft customers invoices.
Definition: index.php:89
select_resource_list($selected= '', $htmlname= 'fk_resource', $filter= '', $showempty=0, $showtype=0, $forcecombo=0, $event=array(), $filterkey= '', $outputmode=0, $limit=20, $morecss= '')
Output html form to select a resource.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc= 'right', $stringencoding= 'UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding &#39;...&#39; if string larger than length.
DAO Resource object.
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin= '1', $morecss= '', $textfordropdown= '')
Show information for admin users or standard users.