1 | <?php |
||
2 | /* Copyright (c) 2002-2007 Rodolphe Quiedeville <[email protected]> |
||
3 | * Copyright (C) 2004-2012 Laurent Destailleur <[email protected]> |
||
4 | * Copyright (C) 2004 Benoit Mortier <[email protected]> |
||
5 | * Copyright (C) 2004 Sebastien Di Cintio <[email protected]> |
||
6 | * Copyright (C) 2004 Eric Seigne <[email protected]> |
||
7 | * Copyright (C) 2005-2012 Regis Houssin <[email protected]> |
||
8 | * Copyright (C) 2006 Andre Cianfarani <[email protected]> |
||
9 | * Copyright (C) 2006 Marc Barilley/Ocebo <[email protected]> |
||
10 | * Copyright (C) 2007 Franky Van Liedekerke <[email protected]> |
||
11 | * Copyright (C) 2007 Patrick Raguin <[email protected]> |
||
12 | * |
||
13 | * This program is free software; you can redistribute it and/or modify |
||
14 | * it under the terms of the GNU General Public License as published by |
||
15 | * the Free Software Foundation; either version 3 of the License, or |
||
16 | * (at your option) any later version. |
||
17 | * |
||
18 | * This program is distributed in the hope that it will be useful, |
||
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
21 | * GNU General Public License for more details. |
||
22 | * |
||
23 | * You should have received a copy of the GNU General Public License |
||
24 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
25 | */ |
||
26 | namespace Alixar\Base; |
||
27 | |||
28 | /** |
||
29 | * \file htdocs/core/class/html.formother.class.php |
||
30 | * \ingroup core |
||
31 | * \brief Fichier de la classe des fonctions predefinie de composants html autre |
||
32 | */ |
||
33 | |||
34 | |||
35 | /** |
||
36 | * Classe permettant la generation de composants html autre |
||
37 | * Only common components are here. |
||
38 | */ |
||
39 | class AlFormOther |
||
40 | { |
||
41 | // private $db; |
||
42 | |||
43 | /** |
||
44 | * @var string Error code (or message) |
||
45 | */ |
||
46 | public $error; |
||
47 | |||
48 | |||
49 | /** |
||
50 | * Constructor |
||
51 | * |
||
52 | * @param DoliDB $db Database handler |
||
53 | */ |
||
54 | function __construct() |
||
55 | { |
||
56 | // $this->db = $db; |
||
57 | } |
||
58 | |||
59 | |||
60 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
||
61 | /** |
||
62 | * Return HTML select list of export models |
||
63 | * |
||
64 | * @param string $selected Id modele pre-selectionne |
||
65 | * @param string $htmlname Nom de la zone select |
||
66 | * @param string $type Type des modeles recherches |
||
67 | * @param int $useempty Affiche valeur vide dans liste |
||
68 | * @param int $fk_user Utilisateur créant le modèle |
||
69 | * @return void |
||
70 | */ |
||
71 | function select_export_model($selected='', $htmlname='exportmodelid', $type='', $useempty=0, $fk_user=null) |
||
72 | { |
||
73 | // phpcs:enable |
||
74 | $sql = "SELECT rowid, label"; |
||
75 | $sql.= " FROM ".MAIN_DB_PREFIX."export_model"; |
||
76 | $sql.= " WHERE type = '".$type."'"; |
||
77 | if (!empty($fk_user)) $sql.=" AND fk_user=".$fk_user; |
||
78 | $sql.= " ORDER BY rowid"; |
||
79 | $result = $this->db->query($sql); |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
80 | if ($result) |
||
81 | { |
||
82 | print '<select class="flat minwidth200" name="'.$htmlname.'">'; |
||
83 | if ($useempty) |
||
84 | { |
||
85 | print '<option value="-1"> </option>'; |
||
86 | } |
||
87 | |||
88 | $num = $this->db->num_rows($result); |
||
89 | $i = 0; |
||
90 | while ($i < $num) |
||
91 | { |
||
92 | $obj = $this->db->fetch_object($result); |
||
93 | if ($selected == $obj->rowid) |
||
94 | { |
||
95 | print '<option value="'.$obj->rowid.'" selected>'; |
||
96 | } |
||
97 | else |
||
98 | { |
||
99 | print '<option value="'.$obj->rowid.'">'; |
||
100 | } |
||
101 | print $obj->label; |
||
102 | print '</option>'; |
||
103 | $i++; |
||
104 | } |
||
105 | print "</select>"; |
||
106 | } |
||
107 | else { |
||
108 | dol_print_error($this->db); |
||
109 | } |
||
110 | } |
||
111 | |||
112 | |||
113 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
||
114 | /** |
||
115 | * Return list of export models |
||
116 | * |
||
117 | * @param string $selected Id modele pre-selectionne |
||
118 | * @param string $htmlname Nom de la zone select |
||
119 | * @param string $type Type des modeles recherches |
||
120 | * @param int $useempty Affiche valeur vide dans liste |
||
121 | * @return void |
||
122 | */ |
||
123 | function select_import_model($selected='', $htmlname='importmodelid', $type='', $useempty=0) |
||
124 | { |
||
125 | // phpcs:enable |
||
126 | $sql = "SELECT rowid, label"; |
||
127 | $sql.= " FROM ".MAIN_DB_PREFIX."import_model"; |
||
128 | $sql.= " WHERE type = '".$type."'"; |
||
129 | $sql.= " ORDER BY rowid"; |
||
130 | $result = $this->db->query($sql); |
||
0 ignored issues
–
show
|
|||
131 | if ($result) |
||
132 | { |
||
133 | print '<select class="flat minwidth200" name="'.$htmlname.'">'; |
||
134 | if ($useempty) |
||
135 | { |
||
136 | print '<option value="-1"> </option>'; |
||
137 | } |
||
138 | |||
139 | $num = $this->db->num_rows($result); |
||
140 | $i = 0; |
||
141 | while ($i < $num) |
||
142 | { |
||
143 | $obj = $this->db->fetch_object($result); |
||
144 | if ($selected == $obj->rowid) |
||
145 | { |
||
146 | print '<option value="'.$obj->rowid.'" selected>'; |
||
147 | } |
||
148 | else |
||
149 | { |
||
150 | print '<option value="'.$obj->rowid.'">'; |
||
151 | } |
||
152 | print $obj->label; |
||
153 | print '</option>'; |
||
154 | $i++; |
||
155 | } |
||
156 | print "</select>"; |
||
157 | } |
||
158 | else { |
||
159 | dol_print_error($this->db); |
||
160 | } |
||
161 | } |
||
162 | |||
163 | |||
164 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
||
165 | /** |
||
166 | * Return list of ecotaxes with label |
||
167 | * |
||
168 | * @param string $selected Preselected ecotaxes |
||
169 | * @param string $htmlname Name of combo list |
||
170 | * @return integer |
||
171 | */ |
||
172 | function select_ecotaxes($selected='', $htmlname='ecotaxe_id') |
||
173 | { |
||
174 | // phpcs:enable |
||
175 | global $langs; |
||
176 | |||
177 | $sql = "SELECT e.rowid, e.code, e.label, e.price, e.organization,"; |
||
178 | $sql.= " c.label as country"; |
||
179 | $sql.= " FROM ".MAIN_DB_PREFIX."c_ecotaxe as e,".MAIN_DB_PREFIX."c_country as c"; |
||
180 | $sql.= " WHERE e.active = 1 AND e.fk_pays = c.rowid"; |
||
181 | $sql.= " ORDER BY country, e.organization ASC, e.code ASC"; |
||
182 | |||
183 | dol_syslog(get_class($this).'::select_ecotaxes', LOG_DEBUG); |
||
184 | $resql=$this->db->query($sql); |
||
0 ignored issues
–
show
|
|||
185 | if ($resql) |
||
186 | { |
||
187 | print '<select class="flat" name="'.$htmlname.'">'; |
||
188 | $num = $this->db->num_rows($resql); |
||
189 | $i = 0; |
||
190 | print '<option value="-1"> </option>'."\n"; |
||
191 | if ($num) |
||
192 | { |
||
193 | while ($i < $num) |
||
194 | { |
||
195 | $obj = $this->db->fetch_object($resql); |
||
196 | if ($selected && $selected == $obj->rowid) |
||
197 | { |
||
198 | print '<option value="'.$obj->rowid.'" selected>'; |
||
199 | } |
||
200 | else |
||
201 | { |
||
202 | print '<option value="'.$obj->rowid.'">'; |
||
203 | //print '<option onmouseover="showtip(\''.$obj->label.'\')" onMouseout="hidetip()" value="'.$obj->rowid.'">'; |
||
204 | } |
||
205 | $selectOptionValue = $obj->code.' - '.$obj->label.' : '.price($obj->price).' '.$langs->trans("HT").' ('.$obj->organization.')'; |
||
206 | print $selectOptionValue; |
||
207 | print '</option>'; |
||
208 | $i++; |
||
209 | } |
||
210 | } |
||
211 | print '</select>'; |
||
212 | return 0; |
||
213 | } |
||
214 | else |
||
215 | { |
||
216 | dol_print_error($this->db); |
||
217 | return 1; |
||
218 | } |
||
219 | } |
||
220 | |||
221 | |||
222 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
||
223 | /** |
||
224 | * Return list of revenue stamp for country |
||
225 | * |
||
226 | * @param string $selected Value of preselected revenue stamp |
||
227 | * @param string $htmlname Name of combo list |
||
228 | * @param string $country_code Country Code |
||
229 | * @return string HTML select list |
||
230 | */ |
||
231 | function select_revenue_stamp($selected='', $htmlname='revenuestamp', $country_code='') |
||
232 | { |
||
233 | // phpcs:enable |
||
234 | global $langs; |
||
235 | |||
236 | $out=''; |
||
237 | |||
238 | $sql = "SELECT r.taux, r.revenuestamp_type"; |
||
239 | $sql.= " FROM ".MAIN_DB_PREFIX."c_revenuestamp as r,".MAIN_DB_PREFIX."c_country as c"; |
||
240 | $sql.= " WHERE r.active = 1 AND r.fk_pays = c.rowid"; |
||
241 | $sql.= " AND c.code = '".$country_code."'"; |
||
242 | |||
243 | dol_syslog(get_class($this).'::select_revenue_stamp', LOG_DEBUG); |
||
244 | $resql=$this->db->query($sql); |
||
0 ignored issues
–
show
|
|||
245 | if ($resql) |
||
246 | { |
||
247 | $out.='<select class="flat" name="'.$htmlname.'">'; |
||
248 | $num = $this->db->num_rows($resql); |
||
249 | $i = 0; |
||
250 | $out.='<option value="0"> </option>'."\n"; |
||
251 | if ($num) |
||
252 | { |
||
253 | while ($i < $num) |
||
254 | { |
||
255 | $obj = $this->db->fetch_object($resql); |
||
256 | if (($selected && $selected == $obj->taux) || $num == 1) |
||
257 | { |
||
258 | $out.='<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').' selected>'; |
||
259 | } |
||
260 | else |
||
261 | { |
||
262 | $out.='<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').'>'; |
||
263 | //print '<option onmouseover="showtip(\''.$obj->libelle.'\')" onMouseout="hidetip()" value="'.$obj->rowid.'">'; |
||
264 | } |
||
265 | $out.=$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : ''); |
||
266 | $out.='</option>'; |
||
267 | $i++; |
||
268 | } |
||
269 | } |
||
270 | $out.='</select>'; |
||
271 | return $out; |
||
272 | } |
||
273 | else |
||
274 | { |
||
275 | dol_print_error($this->db); |
||
276 | return ''; |
||
277 | } |
||
278 | } |
||
279 | |||
280 | |||
281 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
||
282 | /** |
||
283 | * Return a HTML select list to select a percent |
||
284 | * |
||
285 | * @param integer $selected pourcentage pre-selectionne |
||
286 | * @param string $htmlname nom de la liste deroulante |
||
287 | * @param int $disabled Disabled or not |
||
288 | * @param int $increment increment value |
||
289 | * @param int $start start value |
||
290 | * @param int $end end value |
||
291 | * @param int $showempty Add also an empty line |
||
292 | * @return string HTML select string |
||
293 | */ |
||
294 | function select_percent($selected=0,$htmlname='percent',$disabled=0,$increment=5,$start=0,$end=100,$showempty=0) |
||
295 | { |
||
296 | // phpcs:enable |
||
297 | $return = '<select class="flat" name="'.$htmlname.'" '.($disabled?'disabled':'').'>'; |
||
298 | if ($showempty) $return.='<option value="-1"'.(($selected == -1 || $selected == '')?' selected':'').'> </option>'; |
||
299 | |||
300 | for ($i = $start ; $i <= $end ; $i += $increment) |
||
301 | { |
||
302 | if ($selected != '' && (int) $selected == $i) |
||
303 | { |
||
304 | $return.= '<option value="'.$i.'" selected>'; |
||
305 | } |
||
306 | else |
||
307 | { |
||
308 | $return.= '<option value="'.$i.'">'; |
||
309 | } |
||
310 | $return.= $i.' % '; |
||
311 | $return.= '</option>'; |
||
312 | } |
||
313 | |||
314 | $return.= '</select>'; |
||
315 | |||
316 | return $return; |
||
317 | } |
||
318 | |||
319 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
||
320 | /** |
||
321 | * Return select list for categories (to use in form search selectors) |
||
322 | * |
||
323 | * @param int $type Type of category ('customer', 'supplier', 'contact', 'product', 'member'). Old mode (0, 1, 2, ...) is deprecated. |
||
324 | * @param integer $selected Preselected value |
||
325 | * @param string $htmlname Name of combo list |
||
326 | * @param int $nocateg Show also an entry "Not categorized" |
||
327 | * @param int $showempty Add also an empty line |
||
328 | * @param string $morecss More CSS |
||
329 | * @return string Html combo list code |
||
330 | * @see select_all_categories |
||
331 | */ |
||
332 | function select_categories($type, $selected=0, $htmlname='search_categ', $nocateg=0, $showempty=1, $morecss='') |
||
333 | { |
||
334 | // phpcs:enable |
||
335 | global $conf, $langs; |
||
336 | require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; |
||
337 | |||
338 | // For backward compatibility |
||
339 | if (is_numeric($type)) |
||
340 | { |
||
341 | dol_syslog(__METHOD__ . ': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING); |
||
342 | } |
||
343 | |||
344 | // Load list of "categories" |
||
345 | $static_categs = new Categorie($this->db); |
||
0 ignored issues
–
show
|
|||
346 | $tab_categs = $static_categs->get_full_arbo($type); |
||
347 | |||
348 | $moreforfilter = ''; |
||
349 | // Enhance with select2 |
||
350 | if (Globals::$conf->use_javascript_ajax) { |
||
351 | include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
||
352 | $comboenhancement = ajax_combobox('select_categ_'.$htmlname); |
||
353 | $moreforfilter.=$comboenhancement; |
||
354 | } |
||
355 | |||
356 | // Print a select with each of them |
||
357 | $moreforfilter.='<select class="flat minwidth100'.($morecss?' '.$morecss:'').'" id="select_categ_'.$htmlname.'" name="'.$htmlname.'">'; |
||
358 | if ($showempty) $moreforfilter.='<option value="0"> </option>'; // Should use -1 to say nothing |
||
359 | |||
360 | if (is_array($tab_categs)) |
||
361 | { |
||
362 | foreach ($tab_categs as $categ) |
||
363 | { |
||
364 | $moreforfilter.='<option value="'.$categ['id'].'"'; |
||
365 | if ($categ['id'] == $selected) $moreforfilter.=' selected'; |
||
366 | $moreforfilter.='>'.dol_trunc($categ['fulllabel'],50,'middle').'</option>'; |
||
367 | } |
||
368 | } |
||
369 | if ($nocateg) |
||
370 | { |
||
371 | $langs->load("categories"); |
||
372 | $moreforfilter.='<option value="-2"'.($selected == -2 ? ' selected':'').'>- '.$langs->trans("NotCategorized").' -</option>'; |
||
373 | } |
||
374 | $moreforfilter.='</select>'; |
||
375 | |||
376 | return $moreforfilter; |
||
377 | } |
||
378 | |||
379 | |||
380 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
||
381 | /** |
||
382 | * Return select list for categories (to use in form search selectors) |
||
383 | * |
||
384 | * @param string $selected Preselected value |
||
385 | * @param string $htmlname Name of combo list (example: 'search_sale') |
||
386 | * @param User $user Object user |
||
387 | * @param int $showstatus 0=show user status only if status is disabled, 1=always show user status into label, -1=never show user status |
||
388 | * @param int $showempty 1=show also an empty value |
||
389 | * @param string $morecss More CSS |
||
390 | * @return string Html combo list code |
||
391 | */ |
||
392 | function select_salesrepresentatives($selected,$htmlname,$user,$showstatus=0,$showempty=1,$morecss='') |
||
393 | { |
||
394 | // phpcs:enable |
||
395 | global $conf,$langs; |
||
396 | $langs->load('users'); |
||
397 | |||
398 | $out = ''; |
||
399 | // Enhance with select2 |
||
400 | if (Globals::$conf->use_javascript_ajax) { |
||
401 | include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
||
402 | |||
403 | $comboenhancement = ajax_combobox($htmlname); |
||
404 | if ($comboenhancement) |
||
405 | { |
||
406 | $out.=$comboenhancement; |
||
407 | } |
||
408 | } |
||
409 | // Select each sales and print them in a select input |
||
410 | $out.='<select class="flat'.($morecss?' '.$morecss:'').'" id="'.$htmlname.'" name="'.$htmlname.'">'; |
||
411 | if ($showempty) $out.='<option value="0"> </option>'; |
||
412 | |||
413 | // Get list of users allowed to be viewed |
||
414 | $sql_usr = "SELECT u.rowid, u.lastname, u.firstname, u.statut, u.login"; |
||
415 | $sql_usr.= " FROM ".MAIN_DB_PREFIX."user as u"; |
||
416 | $sql_usr .= " WHERE u.entity IN (0," . Globals::$conf->entity . ")"; |
||
417 | if (empty($user->rights->user->user->lire)) $sql_usr.=" AND u.rowid = ".$user->id; |
||
418 | if (! empty($user->societe_id)) $sql_usr.=" AND u.fk_soc = ".$user->societe_id; |
||
419 | // Add existing sales representatives of thirdparty of external user |
||
420 | if (empty($user->rights->user->user->lire) && $user->societe_id) |
||
421 | { |
||
422 | $sql_usr.=" UNION "; |
||
423 | $sql_usr.= "SELECT u2.rowid, u2.lastname, u2.firstname, u2.statut, u2.login"; |
||
424 | $sql_usr.= " FROM ".MAIN_DB_PREFIX."user as u2, ".MAIN_DB_PREFIX."societe_commerciaux as sc"; |
||
425 | $sql_usr .= " WHERE u2.entity IN (0," . Globals::$conf->entity . ")"; |
||
426 | $sql_usr.= " AND u2.rowid = sc.fk_user AND sc.fk_soc=".$user->societe_id; |
||
427 | } |
||
428 | $sql_usr.= " ORDER BY statut DESC, lastname ASC"; // Do not use 'ORDER BY u.statut' here, not compatible with the UNION. |
||
429 | //print $sql_usr;exit; |
||
430 | |||
431 | $resql_usr = $this->db->query($sql_usr); |
||
0 ignored issues
–
show
|
|||
432 | if ($resql_usr) |
||
433 | { |
||
434 | while ($obj_usr = $this->db->fetch_object($resql_usr)) |
||
435 | { |
||
436 | |||
437 | $out.='<option value="'.$obj_usr->rowid.'"'; |
||
438 | |||
439 | if ($obj_usr->rowid == $selected) $out.=' selected'; |
||
440 | |||
441 | $out.='>'; |
||
442 | $out.=dolGetFirstLastname($obj_usr->firstname,$obj_usr->lastname); |
||
443 | // Complete name with more info |
||
444 | $moreinfo=0; |
||
445 | if (!empty(Globals::$conf->global->MAIN_SHOW_LOGIN)) { |
||
446 | $out.=($moreinfo?' - ':' (').$obj_usr->login; |
||
447 | $moreinfo++; |
||
448 | } |
||
449 | if ($showstatus >= 0) |
||
450 | { |
||
451 | if ($obj_usr->statut == 1 && $showstatus == 1) |
||
452 | { |
||
453 | $out.=($moreinfo?' - ':' (').$langs->trans('Enabled'); |
||
454 | $moreinfo++; |
||
455 | } |
||
456 | if ($obj_usr->statut == 0) |
||
457 | { |
||
458 | $out.=($moreinfo?' - ':' (').$langs->trans('Disabled'); |
||
459 | $moreinfo++; |
||
460 | } |
||
461 | } |
||
462 | $out.=($moreinfo?')':''); |
||
463 | $out.='</option>'; |
||
464 | } |
||
465 | $this->db->free($resql_usr); |
||
466 | } |
||
467 | else |
||
468 | { |
||
469 | dol_print_error($this->db); |
||
470 | } |
||
471 | $out.='</select>'; |
||
472 | |||
473 | return $out; |
||
474 | } |
||
475 | |||
476 | /** |
||
477 | * Return list of project and tasks |
||
478 | * |
||
479 | * @param int $selectedtask Pre-selected task |
||
480 | * @param int $projectid Project id |
||
481 | * @param string $htmlname Name of html select |
||
482 | * @param int $modeproject 1 to restrict on projects owned by user |
||
483 | * @param int $modetask 1 to restrict on tasks associated to user |
||
484 | * @param int $mode 0=Return list of tasks and their projects, 1=Return projects and tasks if exists |
||
485 | * @param int $useempty 0=Allow empty values |
||
486 | * @param int $disablechildoftaskid 1=Disable task that are child of the provided task id |
||
487 | * @param string $filteronprojstatus Filter on project status ('-1'=no filter, '0,1'=Draft+Validated status) |
||
488 | * @param string $morecss More css |
||
489 | * @return void |
||
490 | */ |
||
491 | function selectProjectTasks($selectedtask='', $projectid=0, $htmlname='task_parent', $modeproject=0, $modetask=0, $mode=0, $useempty=0, $disablechildoftaskid=0, $filteronprojstatus='', $morecss='') |
||
492 | { |
||
493 | global $user, $langs; |
||
494 | |||
495 | require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php'; |
||
496 | |||
497 | //print $modeproject.'-'.$modetask; |
||
498 | $task=new Task($this->db); |
||
0 ignored issues
–
show
|
|||
499 | $tasksarray=$task->getTasksArray($modetask?$user:0, $modeproject?$user:0, $projectid, 0, $mode, '', $filteronprojstatus); |
||
500 | if ($tasksarray) |
||
501 | { |
||
502 | print '<select class="flat'.($morecss?' '.$morecss:'').'" name="'.$htmlname.'" id="'.$htmlname.'">'; |
||
503 | if ($useempty) print '<option value="0"> </option>'; |
||
504 | $j=0; |
||
505 | $level=0; |
||
506 | $this->_pLineSelect($j, 0, $tasksarray, $level, $selectedtask, $projectid, $disablechildoftaskid); |
||
507 | print '</select>'; |
||
508 | |||
509 | print ajax_combobox($htmlname); |
||
510 | } |
||
511 | else |
||
512 | { |
||
513 | print '<div class="warning">'.$langs->trans("NoProject").'</div>'; |
||
514 | } |
||
515 | } |
||
516 | |||
517 | /** |
||
518 | * Write lines of a project (all lines of a project if parent = 0) |
||
519 | * |
||
520 | * @param int $inc Cursor counter |
||
521 | * @param int $parent Id of parent task we want to see |
||
522 | * @param array $lines Array of task lines |
||
523 | * @param int $level Level |
||
524 | * @param int $selectedtask Id selected task |
||
525 | * @param int $selectedproject Id selected project |
||
526 | * @param int $disablechildoftaskid 1=Disable task that are child of the provided task id |
||
527 | * @return void |
||
528 | */ |
||
529 | private function _pLineSelect(&$inc, $parent, $lines, $level=0, $selectedtask=0, $selectedproject=0, $disablechildoftaskid=0) |
||
530 | { |
||
531 | global $langs, $user, $conf; |
||
532 | |||
533 | $lastprojectid=0; |
||
534 | |||
535 | $numlines=count($lines); |
||
536 | for ($i = 0 ; $i < $numlines ; $i++) |
||
537 | { |
||
538 | if ($lines[$i]->fk_parent == $parent) |
||
539 | { |
||
540 | $var = !$var; |
||
541 | |||
542 | //var_dump($selectedproject."--".$selectedtask."--".$lines[$i]->fk_project."_".$lines[$i]->id); // $lines[$i]->id may be empty if project has no lines |
||
543 | |||
544 | // Break on a new project |
||
545 | if ($parent == 0) // We are on a task at first level |
||
546 | { |
||
547 | if ($lines[$i]->fk_project != $lastprojectid) // Break found on project |
||
548 | { |
||
549 | if ($i > 0) print '<option value="0" disabled>----------</option>'; |
||
550 | print '<option value="'.$lines[$i]->fk_project.'_0"'; |
||
551 | if ($selectedproject == $lines[$i]->fk_project) print ' selected'; |
||
552 | print '>'; // Project -> Task |
||
553 | print $langs->trans("Project").' '.$lines[$i]->projectref; |
||
554 | if (empty($lines[$i]->public)) |
||
555 | { |
||
556 | print ' ('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')'; |
||
557 | } |
||
558 | else |
||
559 | { |
||
560 | print ' ('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')'; |
||
561 | } |
||
562 | //print '-'.$parent.'-'.$lines[$i]->fk_project.'-'.$lastprojectid; |
||
563 | print "</option>\n"; |
||
564 | |||
565 | $lastprojectid=$lines[$i]->fk_project; |
||
566 | $inc++; |
||
567 | } |
||
568 | } |
||
569 | |||
570 | $newdisablechildoftaskid=$disablechildoftaskid; |
||
571 | |||
572 | // Print task |
||
573 | if (isset($lines[$i]->id)) // We use isset because $lines[$i]->id may be null if project has no task and are on root project (tasks may be caught by a left join). We enter here only if '0' or >0 |
||
574 | { |
||
575 | // Check if we must disable entry |
||
576 | $disabled=0; |
||
577 | if ($disablechildoftaskid && (($lines[$i]->id == $disablechildoftaskid || $lines[$i]->fk_parent == $disablechildoftaskid))) |
||
578 | { |
||
579 | $disabled++; |
||
580 | if ($lines[$i]->fk_parent == $disablechildoftaskid) $newdisablechildoftaskid=$lines[$i]->id; // If task is child of a disabled parent, we will propagate id to disable next child too |
||
581 | } |
||
582 | |||
583 | print '<option value="'.$lines[$i]->fk_project.'_'.$lines[$i]->id.'"'; |
||
584 | if (($lines[$i]->id == $selectedtask) || ($lines[$i]->fk_project.'_'.$lines[$i]->id == $selectedtask)) print ' selected'; |
||
585 | if ($disabled) print ' disabled'; |
||
586 | print '>'; |
||
587 | print $langs->trans("Project").' '.$lines[$i]->projectref; |
||
588 | print ' '.$lines[$i]->projectlabel; |
||
589 | if (empty($lines[$i]->public)) |
||
590 | { |
||
591 | print ' ('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')'; |
||
592 | } |
||
593 | else |
||
594 | { |
||
595 | print ' ('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')'; |
||
596 | } |
||
597 | if ($lines[$i]->id) print ' > '; |
||
598 | for ($k = 0 ; $k < $level ; $k++) |
||
599 | { |
||
600 | print " "; |
||
601 | } |
||
602 | print $lines[$i]->ref.' '.$lines[$i]->label."</option>\n"; |
||
603 | $inc++; |
||
604 | } |
||
605 | |||
606 | $level++; |
||
607 | if ($lines[$i]->id) $this->_pLineSelect($inc, $lines[$i]->id, $lines, $level, $selectedtask, $selectedproject, $newdisablechildoftaskid); |
||
608 | $level--; |
||
609 | } |
||
610 | } |
||
611 | } |
||
612 | |||
613 | |||
614 | /** |
||
615 | * Output a HTML thumb of color or a text if not defined. |
||
616 | * |
||
617 | * @param string $color String with hex (FFFFFF) or comma RGB ('255,255,255') |
||
618 | * @param string $textifnotdefined Text to show if color not defined |
||
619 | * @return string HTML code for color thumb |
||
620 | * @see selectColor |
||
621 | */ |
||
622 | static function showColor($color, $textifnotdefined='') |
||
623 | { |
||
624 | $textcolor='FFF'; |
||
625 | include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; |
||
626 | if(colorIsLight($color)) $textcolor='000'; |
||
627 | |||
628 | $color = colorArrayToHex(colorStringToArray($color,array()),''); |
||
629 | |||
630 | if ($color) print '<input type="text" class="colorthumb" disabled style="padding: 1px; margin-top: 0; margin-bottom: 0; color: #'.$textcolor.'; background-color: #'.$color.'" value="'.$color.'">'; |
||
631 | else print $textifnotdefined; |
||
632 | } |
||
633 | |||
634 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
||
635 | /** |
||
636 | * Output a HTML code to select a color |
||
637 | * |
||
638 | * @param string $set_color Pre-selected color |
||
639 | * @param string $prefix Name of HTML field |
||
640 | * @param string $form_name Deprecated. Not used. |
||
641 | * @param int $showcolorbox 1=Show color code and color box, 0=Show only color code |
||
642 | * @param array $arrayofcolors Array of colors. Example: array('29527A','5229A3','A32929','7A367A','B1365F','0D7813') |
||
643 | * @return void |
||
644 | * @deprecated Use instead selectColor |
||
645 | * @see selectColor() |
||
646 | */ |
||
647 | function select_color($set_color='', $prefix='f_color', $form_name='', $showcolorbox=1, $arrayofcolors='') |
||
648 | { |
||
649 | // phpcs:enable |
||
650 | print $this->selectColor($set_color, $prefix, $form_name, $showcolorbox, $arrayofcolors); |
||
651 | } |
||
652 | |||
653 | /** |
||
654 | * Output a HTML code to select a color. Field will return an hexa color like '334455'. |
||
655 | * |
||
656 | * @param string $set_color Pre-selected color |
||
657 | * @param string $prefix Name of HTML field |
||
658 | * @param string $form_name Deprecated. Not used. |
||
659 | * @param int $showcolorbox 1=Show color code and color box, 0=Show only color code |
||
660 | * @param array $arrayofcolors Array of colors. Example: array('29527A','5229A3','A32929','7A367A','B1365F','0D7813') |
||
661 | * @param string $morecss Add css style into input field |
||
662 | * @return string |
||
663 | * @see showColor |
||
664 | */ |
||
665 | static function selectColor($set_color='', $prefix='f_color', $form_name='', $showcolorbox=1, $arrayofcolors='', $morecss='') |
||
666 | { |
||
667 | // Deprecation warning |
||
668 | if ($form_name) { |
||
669 | dol_syslog(__METHOD__ . ": form_name parameter is deprecated", LOG_WARNING); |
||
670 | } |
||
671 | |||
672 | global $langs,$conf; |
||
673 | |||
674 | $out=''; |
||
675 | |||
676 | if (! is_array($arrayofcolors) || count($arrayofcolors) < 1) |
||
677 | { |
||
678 | $langs->load("other"); |
||
679 | if (empty(Globals::$conf->dol_use_jmobile)) { |
||
680 | $out.= '<link rel="stylesheet" media="screen" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/css/jPicker-1.1.6.css" />'; |
||
681 | $out.= '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/jpicker-1.1.6.js"></script>'; |
||
682 | $out.= '<script type="text/javascript"> |
||
683 | jQuery(document).ready(function(){ |
||
684 | $(\'#colorpicker'.$prefix.'\').jPicker( { |
||
685 | window: { |
||
686 | title: \''.dol_escape_js($langs->trans("SelectAColor")).'\', /* any title for the jPicker window itself - displays "Drag Markers To Pick A Color" if left null */ |
||
687 | effects: |
||
688 | { |
||
689 | type: \'show\', /* effect used to show/hide an expandable picker. Acceptable values "slide", "show", "fade" */ |
||
690 | speed: |
||
691 | { |
||
692 | show: \'fast\', /* duration of "show" effect. Acceptable values are "fast", "slow", or time in ms */ |
||
693 | hide: \'fast\' /* duration of "hide" effect. Acceptable values are "fast", "slow", or time in ms */ |
||
694 | } |
||
695 | }, |
||
696 | position: |
||
697 | { |
||
698 | x: \'screenCenter\', /* acceptable values "left", "center", "right", "screenCenter", or relative px value */ |
||
699 | y: \'center\' /* acceptable values "top", "bottom", "center", or relative px value */ |
||
700 | }, |
||
701 | }, |
||
702 | images: { |
||
703 | clientPath: \''.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/images/\', |
||
704 | picker: { file: \'../../../../../theme/common/colorpicker.png\', width: 14, height: 14 } |
||
705 | }, |
||
706 | localization: // alter these to change the text presented by the picker (e.g. different language) |
||
707 | { |
||
708 | text: |
||
709 | { |
||
710 | title: \''.dol_escape_js($langs->trans("SelectAColor")).'\', |
||
711 | newColor: \''.dol_escape_js($langs->trans("New")).'\', |
||
712 | currentColor: \''.dol_escape_js($langs->trans("Current")).'\', |
||
713 | ok: \''.dol_escape_js($langs->trans("Save")).'\', |
||
714 | cancel: \''.dol_escape_js($langs->trans("Cancel")).'\' |
||
715 | } |
||
716 | } |
||
717 | } ); }); |
||
718 | </script>'; |
||
719 | } |
||
720 | $out.= '<input id="colorpicker'.$prefix.'" name="'.$prefix.'" size="6" maxlength="7" class="flat'.($morecss?' '.$morecss:'').'" type="text" value="'.$set_color.'" />'; |
||
721 | } |
||
722 | else // In most cases, this is not used. We used instead function with no specific list of colors |
||
723 | { |
||
724 | if (empty(Globals::$conf->dol_use_jmobile)) { |
||
725 | $out.= '<link rel="stylesheet" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.css" type="text/css" media="screen" />'; |
||
726 | $out.= '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.js" type="text/javascript"></script>'; |
||
727 | $out.= '<script type="text/javascript"> |
||
728 | jQuery(document).ready(function(){ |
||
729 | jQuery(\'#colorpicker'.$prefix.'\').colorpicker({ |
||
730 | size: 14, |
||
731 | label: \'\', |
||
732 | hide: true |
||
733 | }); |
||
734 | }); |
||
735 | </script>'; |
||
736 | } |
||
737 | $out.= '<select id="colorpicker'.$prefix.'" class="flat'.($morecss?' '.$morecss:'').'" name="'.$prefix.'">'; |
||
738 | //print '<option value="-1"> </option>'; |
||
739 | foreach ($arrayofcolors as $val) |
||
740 | { |
||
741 | $out.= '<option value="'.$val.'"'; |
||
742 | if ($set_color == $val) $out.= ' selected'; |
||
743 | $out.= '>'.$val.'</option>'; |
||
744 | } |
||
745 | $out.= '</select>'; |
||
746 | } |
||
747 | |||
748 | return $out; |
||
749 | } |
||
750 | |||
751 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
||
752 | /** |
||
753 | * Creation d'un icone de couleur |
||
754 | * |
||
755 | * @param string $color Couleur de l'image |
||
756 | * @param string $module Nom du module |
||
757 | * @param string $name Nom de l'image |
||
758 | * @param int $x Largeur de l'image en pixels |
||
759 | * @param int $y Hauteur de l'image en pixels |
||
760 | * @return void |
||
761 | */ |
||
762 | function CreateColorIcon($color,$module,$name,$x='12',$y='12') |
||
763 | { |
||
764 | // phpcs:enable |
||
765 | global $conf; |
||
766 | |||
767 | $file = Globals::$conf->$module->dir_temp . '/' . $name . '.png'; |
||
768 | |||
769 | // On cree le repertoire contenant les icones |
||
770 | if (!file_exists(Globals::$conf->$module->dir_temp)) { |
||
771 | dol_mkdir(Globals::$conf->$module->dir_temp); |
||
772 | } |
||
773 | |||
774 | // On cree l'image en vraies couleurs |
||
775 | $image = imagecreatetruecolor($x,$y); |
||
776 | |||
777 | $color = substr($color,1,6); |
||
778 | |||
779 | $rouge = hexdec(substr($color,0,2)); //conversion du canal rouge |
||
780 | $vert = hexdec(substr($color,2,2)); //conversion du canal vert |
||
781 | $bleu = hexdec(substr($color,4,2)); //conversion du canal bleu |
||
782 | |||
783 | $couleur = imagecolorallocate($image,$rouge,$vert,$bleu); |
||
784 | //print $rouge.$vert.$bleu; |
||
785 | imagefill($image,0,0,$couleur); //on remplit l'image |
||
786 | // On cree la couleur et on l'attribue a une variable pour ne pas la perdre |
||
787 | ImagePng($image,$file); //renvoie une image sous format png |
||
788 | ImageDestroy($image); |
||
789 | } |
||
790 | |||
791 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
||
792 | /** |
||
793 | * Return HTML combo list of week |
||
794 | * |
||
795 | * @param string $selected Preselected value |
||
796 | * @param string $htmlname Nom de la zone select |
||
797 | * @param int $useempty Affiche valeur vide dans liste |
||
798 | * @return string |
||
799 | */ |
||
800 | function select_dayofweek($selected='',$htmlname='weekid',$useempty=0) |
||
801 | { |
||
802 | // phpcs:enable |
||
803 | global $langs; |
||
804 | |||
805 | $week = array( |
||
806 | 0=>$langs->trans("Day0"), |
||
807 | 1=>$langs->trans("Day1"), |
||
808 | 2=>$langs->trans("Day2"), |
||
809 | 3=>$langs->trans("Day3"), |
||
810 | 4=>$langs->trans("Day4"), |
||
811 | 5=>$langs->trans("Day5"), |
||
812 | 6=>$langs->trans("Day6") |
||
813 | ); |
||
814 | |||
815 | $select_week = '<select class="flat" name="'.$htmlname.'">'; |
||
816 | if ($useempty) |
||
817 | { |
||
818 | $select_week .= '<option value="-1"> </option>'; |
||
819 | } |
||
820 | foreach ($week as $key => $val) |
||
821 | { |
||
822 | if ($selected == $key) |
||
823 | { |
||
824 | $select_week .= '<option value="'.$key.'" selected>'; |
||
825 | } |
||
826 | else |
||
827 | { |
||
828 | $select_week .= '<option value="'.$key.'">'; |
||
829 | } |
||
830 | $select_week .= $val; |
||
831 | $select_week .= '</option>'; |
||
832 | } |
||
833 | $select_week .= '</select>'; |
||
834 | return $select_week; |
||
835 | } |
||
836 | |||
837 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
||
838 | /** |
||
839 | * Return HTML combo list of month |
||
840 | * |
||
841 | * @param string $selected Preselected value |
||
842 | * @param string $htmlname Name of HTML select object |
||
843 | * @param int $useempty Show empty in list |
||
844 | * @param int $longlabel Show long label |
||
845 | * @param string $morecss More Css |
||
846 | * @return string |
||
847 | */ |
||
848 | function select_month($selected='', $htmlname='monthid', $useempty=0, $longlabel=0, $morecss='') |
||
849 | { |
||
850 | // phpcs:enable |
||
851 | global $langs; |
||
852 | |||
853 | require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; |
||
854 | |||
855 | if ($longlabel) $montharray = monthArray($langs, 0); // Get array |
||
856 | else $montharray = monthArray($langs, 1); |
||
857 | |||
858 | $select_month = '<select class="flat'.($morecss?' '.$morecss:'').'" name="'.$htmlname.'" id="'.$htmlname.'">'; |
||
859 | if ($useempty) |
||
860 | { |
||
861 | $select_month .= '<option value="0"> </option>'; |
||
862 | } |
||
863 | foreach ($montharray as $key => $val) |
||
864 | { |
||
865 | if ($selected == $key) |
||
866 | { |
||
867 | $select_month .= '<option value="'.$key.'" selected>'; |
||
868 | } |
||
869 | else |
||
870 | { |
||
871 | $select_month .= '<option value="'.$key.'">'; |
||
872 | } |
||
873 | $select_month .= $val; |
||
874 | $select_month .= '</option>'; |
||
875 | } |
||
876 | $select_month .= '</select>'; |
||
877 | return $select_month; |
||
878 | } |
||
879 | |||
880 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
||
881 | /** |
||
882 | * Return HTML combo list of years |
||
883 | * |
||
884 | * @param string $selected Preselected value (''=current year, -1=none, year otherwise) |
||
885 | * @param string $htmlname Name of HTML select object |
||
886 | * @param int $useempty Affiche valeur vide dans liste |
||
887 | * @param int $min_year Offset of minimum year into list (by default current year -10) |
||
888 | * @param int $max_year Offset of maximum year into list (by default current year + 5) |
||
889 | * @param int $offset Offset |
||
890 | * @param int $invert Invert |
||
891 | * @param string $option Option |
||
892 | * @param string $morecss More CSS |
||
893 | * @return string |
||
894 | */ |
||
895 | function select_year($selected='',$htmlname='yearid',$useempty=0, $min_year=10, $max_year=5, $offset=0, $invert=0, $option='', $morecss='valignmiddle widthauto') |
||
896 | { |
||
897 | // phpcs:enable |
||
898 | print $this->selectyear($selected,$htmlname,$useempty,$min_year,$max_year,$offset,$invert,$option,$morecss); |
||
899 | } |
||
900 | |||
901 | /** |
||
902 | * Return HTML combo list of years |
||
903 | * |
||
904 | * @param string $selected Preselected value (''=current year, -1=none, year otherwise) |
||
905 | * @param string $htmlname Name of HTML select object |
||
906 | * @param int $useempty Affiche valeur vide dans liste |
||
907 | * @param int $min_year Offset of minimum year into list (by default current year -10) |
||
908 | * @param int $max_year Offset of maximum year into list (by default current year + 5) |
||
909 | * @param int $offset Offset |
||
910 | * @param int $invert Invert |
||
911 | * @param string $option Option |
||
912 | * @param string $morecss More css |
||
913 | * @return string |
||
914 | */ |
||
915 | function selectyear($selected='',$htmlname='yearid',$useempty=0, $min_year=10, $max_year=5, $offset=0, $invert=0, $option='', $morecss='valignmiddle widthauto') |
||
916 | { |
||
917 | $out=''; |
||
918 | |||
919 | $currentyear = date("Y")+$offset; |
||
920 | $max_year = $currentyear+$max_year; |
||
921 | $min_year = $currentyear-$min_year; |
||
922 | if(empty($selected) && empty($useempty)) $selected = $currentyear; |
||
923 | |||
924 | $out.= '<select class="flat'.($morecss?' '.$morecss:'').'" id="' . $htmlname . '" name="' . $htmlname . '"'.$option.' >'; |
||
925 | if($useempty) |
||
926 | { |
||
927 | $selected_html=''; |
||
928 | if ($selected == '') $selected_html = ' selected'; |
||
929 | $out.= '<option value=""' . $selected_html . '> </option>'; |
||
930 | } |
||
931 | if (! $invert) |
||
932 | { |
||
933 | for ($y = $max_year; $y >= $min_year; $y--) |
||
934 | { |
||
935 | $selected_html=''; |
||
936 | if ($selected > 0 && $y == $selected) $selected_html = ' selected'; |
||
937 | $out.= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>'; |
||
938 | } |
||
939 | } |
||
940 | else |
||
941 | { |
||
942 | for ($y = $min_year; $y <= $max_year; $y++) |
||
943 | { |
||
944 | $selected_html=''; |
||
945 | if ($selected > 0 && $y == $selected) $selected_html = ' selected'; |
||
946 | $out.= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>'; |
||
947 | } |
||
948 | } |
||
949 | $out.= "</select>\n"; |
||
950 | |||
951 | return $out; |
||
952 | } |
||
953 | |||
954 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
||
955 | /** |
||
956 | * Show form to select address |
||
957 | * |
||
958 | * @param int $page Page |
||
959 | * @param string $selected Id condition pre-selectionne |
||
960 | * @param int $socid Id of third party |
||
961 | * @param string $htmlname Nom du formulaire select |
||
962 | * @param string $origin Origine de l'appel pour pouvoir creer un retour |
||
963 | * @param int $originid Id de l'origine |
||
964 | * @return void |
||
965 | */ |
||
966 | function form_address($page, $selected, $socid, $htmlname='address_id', $origin='', $originid='') |
||
967 | { |
||
968 | // phpcs:enable |
||
969 | global $langs,$conf; |
||
970 | global $form; |
||
971 | |||
972 | if ($htmlname != "none") |
||
973 | { |
||
974 | print '<form method="post" action="'.$page.'">'; |
||
975 | print '<input type="hidden" name="action" value="setaddress">'; |
||
976 | print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
||
977 | $form->select_address($selected, $socid, $htmlname, 1); |
||
978 | print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">'; |
||
979 | $langs->load("companies"); |
||
980 | print ' <a href='.DOL_URL_ROOT.'/comm/address.php?socid='.$socid.'&action=create&origin='.$origin.'&originid='.$originid.'>'.$langs->trans("AddAddress").'</a>'; |
||
981 | print '</form>'; |
||
982 | } |
||
983 | else |
||
984 | { |
||
985 | if ($selected) |
||
986 | { |
||
987 | require_once DOL_DOCUMENT_ROOT .'/societe/class/address.class.php'; |
||
988 | $address=new Address($this->db); |
||
0 ignored issues
–
show
|
|||
989 | $result=$address->fetch_address($selected); |
||
990 | print '<a href='.DOL_URL_ROOT.'/comm/address.php?socid='.$address->socid.'&id='.$address->id.'&action=edit&origin='.$origin.'&originid='.$originid.'>'.$address->label.'</a>'; |
||
991 | } |
||
992 | else |
||
993 | { |
||
994 | print " "; |
||
995 | } |
||
996 | } |
||
997 | } |
||
998 | |||
999 | |||
1000 | |||
1001 | /** |
||
1002 | * Get array with HTML tabs with boxes of a particular area including personalized choices of user. |
||
1003 | * Class 'Form' must be known. |
||
1004 | * |
||
1005 | * @param User $user Object User |
||
1006 | * @param String $areacode Code of area for pages ('0'=value for Home page) |
||
1007 | * @return array array('selectboxlist'=>, 'boxactivated'=>, 'boxlista'=>, 'boxlistb'=>) |
||
1008 | */ |
||
1009 | static function getBoxesArea($user,$areacode) |
||
1010 | { |
||
1011 | global $conf,$langs,$db; |
||
1012 | |||
1013 | include_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php'; |
||
1014 | |||
1015 | $confuserzone='MAIN_BOXES_'.$areacode; |
||
1016 | |||
1017 | // $boxactivated will be array of boxes enabled into global setup |
||
1018 | // $boxidactivatedforuser will be array of boxes choosed by user |
||
1019 | |||
1020 | $selectboxlist=''; |
||
1021 | $boxactivated=InfoBox::listBoxes($db, 'activated', $areacode, (empty($user->conf->$confuserzone)?null:$user), array(), 0); // Search boxes of common+user (or common only if user has no specific setup) |
||
1022 | |||
1023 | $boxidactivatedforuser=array(); |
||
1024 | foreach($boxactivated as $box) |
||
1025 | { |
||
1026 | if (empty($user->conf->$confuserzone) || $box->fk_user == $user->id) $boxidactivatedforuser[$box->id]=$box->id; // We keep only boxes to show for user |
||
1027 | } |
||
1028 | |||
1029 | // Define selectboxlist |
||
1030 | $arrayboxtoactivatelabel=array(); |
||
1031 | if (! empty($user->conf->$confuserzone)) |
||
1032 | { |
||
1033 | $boxorder=''; |
||
1034 | $langs->load("boxes"); // Load label of boxes |
||
1035 | foreach($boxactivated as $box) |
||
1036 | { |
||
1037 | if (! empty($boxidactivatedforuser[$box->id])) continue; // Already visible for user |
||
1038 | $label=$langs->transnoentitiesnoconv($box->boxlabel); |
||
1039 | //if (preg_match('/graph/',$box->class)) $label.=' ('.$langs->trans("Graph").')'; |
||
1040 | if (preg_match('/graph/', $box->class) && Globals::$conf->browser->layout != 'phone') { |
||
1041 | $label=$label.' <span class="fa fa-bar-chart"></span>'; |
||
1042 | } |
||
1043 | $arrayboxtoactivatelabel[$box->id]=$label; // We keep only boxes not shown for user, to show into combo list |
||
1044 | } |
||
1045 | foreach($boxidactivatedforuser as $boxid) |
||
1046 | { |
||
1047 | if (empty($boxorder)) $boxorder.='A:'; |
||
1048 | $boxorder.=$boxid.','; |
||
1049 | } |
||
1050 | |||
1051 | //var_dump($boxidactivatedforuser); |
||
1052 | |||
1053 | // Class Form must have been already loaded |
||
1054 | $selectboxlist.='<!-- Form with select box list -->'."\n"; |
||
1055 | $selectboxlist.='<form id="addbox" name="addbox" method="POST" action="'.$_SERVER["PHP_SELF"].'">'; |
||
1056 | $selectboxlist.='<input type="hidden" name="addbox" value="addbox">'; |
||
1057 | $selectboxlist.='<input type="hidden" name="userid" value="'.$user->id.'">'; |
||
1058 | $selectboxlist.='<input type="hidden" name="areacode" value="'.$areacode.'">'; |
||
1059 | $selectboxlist.='<input type="hidden" name="boxorder" value="'.$boxorder.'">'; |
||
1060 | $selectboxlist.=Form::selectarray('boxcombo', $arrayboxtoactivatelabel, -1, $langs->trans("ChooseBoxToAdd").'...', 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth150onsmartphone', 0, 'hidden selected', 0, 1); |
||
0 ignored issues
–
show
|
|||
1061 | if (empty(Globals::$conf->use_javascript_ajax)) |
||
1062 | $selectboxlist .= ' <input type="submit" class="button" value="' . $langs->trans("AddBox") . '">'; |
||
1063 | $selectboxlist.='</form>'; |
||
1064 | if (!empty(Globals::$conf->use_javascript_ajax)) { |
||
1065 | include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
||
1066 | $selectboxlist.=ajax_combobox("boxcombo"); |
||
1067 | } |
||
1068 | } |
||
1069 | |||
1070 | // Javascript code for dynamic actions |
||
1071 | if (!empty(Globals::$conf->use_javascript_ajax)) { |
||
1072 | $selectboxlist.='<script type="text/javascript" language="javascript"> |
||
1073 | |||
1074 | // To update list of activated boxes |
||
1075 | function updateBoxOrder(closing) { |
||
1076 | var left_list = cleanSerialize(jQuery("#boxhalfleft").sortable("serialize")); |
||
1077 | var right_list = cleanSerialize(jQuery("#boxhalfright").sortable("serialize")); |
||
1078 | var boxorder = \'A:\' + left_list + \'-B:\' + right_list; |
||
1079 | if (boxorder==\'A:A-B:B\' && closing == 1) // There is no more boxes on screen, and we are after a delete of a box so we must hide title |
||
1080 | { |
||
1081 | jQuery.ajax({ |
||
1082 | url: \''.DOL_URL_ROOT.'/core/ajax/box.php?closing=0&boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.', |
||
1083 | async: false |
||
1084 | }); |
||
1085 | // We force reload to be sure to get all boxes into list |
||
1086 | window.location.search=\'mainmenu='.GETPOST("mainmenu","aZ09").'&leftmenu='.GETPOST('leftmenu',"aZ09").'&action=delbox\'; |
||
1087 | } |
||
1088 | else |
||
1089 | { |
||
1090 | jQuery.ajax({ |
||
1091 | url: \''.DOL_URL_ROOT.'/core/ajax/box.php?closing=\'+closing+\'&boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.', |
||
1092 | async: true |
||
1093 | }); |
||
1094 | } |
||
1095 | } |
||
1096 | |||
1097 | jQuery(document).ready(function() { |
||
1098 | jQuery("#boxcombo").change(function() { |
||
1099 | var boxid=jQuery("#boxcombo").val(); |
||
1100 | if (boxid > 0) { |
||
1101 | var left_list = cleanSerialize(jQuery("#boxhalfleft").sortable("serialize")); |
||
1102 | var right_list = cleanSerialize(jQuery("#boxhalfright").sortable("serialize")); |
||
1103 | var boxorder = \'A:\' + left_list + \'-B:\' + right_list; |
||
1104 | jQuery.ajax({ |
||
1105 | url: \''.DOL_URL_ROOT.'/core/ajax/box.php?boxorder=\'+boxorder+\'&boxid=\'+boxid+\'&zone='.$areacode.'&userid='.$user->id.'\', |
||
1106 | async: false |
||
1107 | }); |
||
1108 | window.location.search=\'mainmenu='.GETPOST("mainmenu","aZ09").'&leftmenu='.GETPOST('leftmenu',"aZ09").'&action=addbox&boxid=\'+boxid; |
||
1109 | } |
||
1110 | });'; |
||
1111 | if (! count($arrayboxtoactivatelabel)) $selectboxlist.='jQuery("#boxcombo").hide();'; |
||
1112 | $selectboxlist.=' |
||
1113 | |||
1114 | jQuery("#boxhalfleft, #boxhalfright").sortable({ |
||
1115 | handle: \'.boxhandle\', |
||
1116 | revert: \'invalid\', |
||
1117 | items: \'.boxdraggable\', |
||
1118 | containment: \'document\', |
||
1119 | connectWith: \'#boxhalfleft, #boxhalfright\', |
||
1120 | stop: function(event, ui) { |
||
1121 | updateBoxOrder(1); /* 1 to avoid message after a move */ |
||
1122 | } |
||
1123 | }); |
||
1124 | |||
1125 | jQuery(".boxclose").click(function() { |
||
1126 | var self = this; // because JQuery can modify this |
||
1127 | var boxid=self.id.substring(8); |
||
1128 | var label=jQuery(\'#boxlabelentry\'+boxid).val(); |
||
1129 | console.log("We close box "+boxid); |
||
1130 | jQuery(\'#boxto_\'+boxid).remove(); |
||
1131 | if (boxid > 0) jQuery(\'#boxcombo\').append(new Option(label, boxid)); |
||
1132 | updateBoxOrder(1); /* 1 to avoid message after a remove */ |
||
1133 | }); |
||
1134 | |||
1135 | });'."\n"; |
||
1136 | |||
1137 | $selectboxlist.='</script>'."\n"; |
||
1138 | } |
||
1139 | |||
1140 | // Define boxlista and boxlistb |
||
1141 | $nbboxactivated=count($boxidactivatedforuser); |
||
1142 | |||
1143 | if ($nbboxactivated) |
||
1144 | { |
||
1145 | // Load translation files required by the page |
||
1146 | $langs->loadLangs(array("boxes","projects")); |
||
1147 | |||
1148 | $emptybox=new ModeleBoxes($db); |
||
1149 | |||
1150 | $boxlista.="\n<!-- Box left container -->\n"; |
||
1151 | |||
1152 | // Define $box_max_lines |
||
1153 | $box_max_lines=5; |
||
1154 | if (!empty(Globals::$conf->global->MAIN_BOXES_MAXLINES)) |
||
1155 | $box_max_lines = Globals::$conf->global->MAIN_BOXES_MAXLINES; |
||
1156 | |||
1157 | $ii=0; |
||
1158 | foreach ($boxactivated as $key => $box) |
||
1159 | { |
||
1160 | if ((! empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) continue; |
||
1161 | if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) $box->box_order='A'.sprintf("%02d",($ii+1)); // When box_order was not yet set to Axx or Bxx and is still 0 |
||
1162 | if (preg_match('/^A/i',$box->box_order)) // column A |
||
1163 | { |
||
1164 | $ii++; |
||
1165 | //print 'box_id '.$boxactivated[$ii]->box_id.' '; |
||
1166 | //print 'box_order '.$boxactivated[$ii]->box_order.'<br>'; |
||
1167 | // Show box |
||
1168 | $box->loadBox($box_max_lines); |
||
1169 | $boxlista.= $box->outputBox(); |
||
1170 | } |
||
1171 | } |
||
1172 | |||
1173 | if (Globals::$conf->browser->layout != 'phone') { |
||
1174 | $emptybox->box_id='A'; |
||
1175 | $emptybox->info_box_head=array(); |
||
1176 | $emptybox->info_box_contents=array(); |
||
1177 | $boxlista.= $emptybox->outputBox(array(),array()); |
||
1178 | } |
||
1179 | $boxlista.= "<!-- End box left container -->\n"; |
||
1180 | |||
1181 | $boxlistb.= "\n<!-- Box right container -->\n"; |
||
1182 | |||
1183 | $ii=0; |
||
1184 | foreach ($boxactivated as $key => $box) |
||
1185 | { |
||
1186 | if ((! empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) continue; |
||
1187 | if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) $box->box_order='B'.sprintf("%02d",($ii+1)); // When box_order was not yet set to Axx or Bxx and is still 0 |
||
1188 | if (preg_match('/^B/i',$box->box_order)) // colonne B |
||
1189 | { |
||
1190 | $ii++; |
||
1191 | //print 'box_id '.$boxactivated[$ii]->box_id.' '; |
||
1192 | //print 'box_order '.$boxactivated[$ii]->box_order.'<br>'; |
||
1193 | // Show box |
||
1194 | $box->loadBox($box_max_lines); |
||
1195 | $boxlistb.= $box->outputBox(); |
||
1196 | } |
||
1197 | } |
||
1198 | |||
1199 | if (Globals::$conf->browser->layout != 'phone') { |
||
1200 | $emptybox->box_id='B'; |
||
1201 | $emptybox->info_box_head=array(); |
||
1202 | $emptybox->info_box_contents=array(); |
||
1203 | $boxlistb.= $emptybox->outputBox(array(),array()); |
||
1204 | } |
||
1205 | |||
1206 | $boxlistb.= "<!-- End box right container -->\n"; |
||
1207 | } |
||
1208 | |||
1209 | return array('selectboxlist'=>count($boxactivated)?$selectboxlist:'', 'boxactivated'=>$boxactivated, 'boxlista'=>$boxlista, 'boxlistb'=>$boxlistb); |
||
1210 | } |
||
1211 | |||
1212 | |||
1213 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
||
1214 | /** |
||
1215 | * Return a HTML select list of a dictionary |
||
1216 | * |
||
1217 | * @param string $htmlname Name of select zone |
||
1218 | * @param string $dictionarytable Dictionary table |
||
1219 | * @param string $keyfield Field for key |
||
1220 | * @param string $labelfield Label field |
||
1221 | * @param string $selected Selected value |
||
1222 | * @param int $useempty 1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries. |
||
1223 | * @param string $moreattrib More attributes on HTML select tag |
||
1224 | * @return void |
||
1225 | */ |
||
1226 | function select_dictionary($htmlname,$dictionarytable,$keyfield='code',$labelfield='label',$selected='',$useempty=0,$moreattrib='') |
||
1227 | { |
||
1228 | // phpcs:enable |
||
1229 | global $langs, $conf; |
||
1230 | |||
1231 | $langs->load("admin"); |
||
1232 | |||
1233 | $sql = "SELECT rowid, ".$keyfield.", ".$labelfield; |
||
1234 | $sql.= " FROM ".MAIN_DB_PREFIX.$dictionarytable; |
||
1235 | $sql.= " ORDER BY ".$labelfield; |
||
1236 | |||
1237 | dol_syslog(get_class($this)."::select_dictionary", LOG_DEBUG); |
||
1238 | $result = $this->db->query($sql); |
||
0 ignored issues
–
show
|
|||
1239 | if ($result) |
||
1240 | { |
||
1241 | $num = $this->db->num_rows($result); |
||
1242 | $i = 0; |
||
1243 | if ($num) |
||
1244 | { |
||
1245 | print '<select id="select'.$htmlname.'" class="flat selectdictionary" name="'.$htmlname.'"'.($moreattrib?' '.$moreattrib:'').'>'; |
||
1246 | if ($useempty == 1 || ($useempty == 2 && $num > 1)) |
||
1247 | { |
||
1248 | print '<option value="-1"> </option>'; |
||
1249 | } |
||
1250 | |||
1251 | while ($i < $num) |
||
1252 | { |
||
1253 | $obj = $this->db->fetch_object($result); |
||
1254 | if ($selected == $obj->rowid || $selected == $obj->$keyfield) |
||
1255 | { |
||
1256 | print '<option value="'.$obj->$keyfield.'" selected>'; |
||
1257 | } |
||
1258 | else |
||
1259 | { |
||
1260 | print '<option value="'.$obj->$keyfield.'">'; |
||
1261 | } |
||
1262 | print $obj->$labelfield; |
||
1263 | print '</option>'; |
||
1264 | $i++; |
||
1265 | } |
||
1266 | print "</select>"; |
||
1267 | } |
||
1268 | else |
||
1269 | { |
||
1270 | print $langs->trans("DictionaryEmpty"); |
||
1271 | } |
||
1272 | } |
||
1273 | else { |
||
1274 | dol_print_error($this->db); |
||
1275 | } |
||
1276 | } |
||
1277 | } |
||
1278 |