noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
iselect.class.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS 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 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS 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 NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21
22/*!
23 * \file
24 * \brief Html Input , create a tag <SELECT> ... </SELECT>
25 * if readonly == true then display the label corresponding to the selected value
26 * You can use also $this->rowsize to specify the number of lines to display
27 *
28 * @see Database::make_array
29 */
30
31/*!
32 * \class ISelect
33 * \brief Html Input , create a tag <SELECT> ... </SELECT>
34 * if readonly == true then display the label corresponding to the selected value
35 * You can use also $this->rowsize to specify the number of lines to display
36 *
37 * @see Database::make_array
38 */
39class ISelect extends HtmlInput
40{
41 /**
42 * Constructor , $p_value is supposed to be an array
43 * @param string $p_name name of the element
44 * @param array $p_value
45 * @param DOMID $p_id
46 */
47 function __construct($p_name="", $p_value="", $p_id="")
48 {
49 parent::__construct($p_name, $p_value, $p_id);
50 if ( $p_value =="" )
51 {
52 $this->value=[];
53 } else {
54 $this->value=$p_value;
55 }
56 }
57 /*!
58 * \brief show the html input of the widget
59 * \note to use a OPTGROUP, the key "value" must be null , it is important
60 * to note that it is needed to use for opening and closing the element
61 * \code
62 $select->value=array(
63 array ("value"=>null,"label"=>"Groupe 1"),
64 array ("value"=>1,"label"=>"Element 1"),
65 array ("value"=>2,"label"=>"Element 2"),
66 array ("value"=>null,"label"=>"END Groupe 1"), // not displaid
67 array ("value"=>null,"label"=>"Groupe 2"),
68 array ("value"=>1,"label"=>"Element 1"),
69 array ("value"=>2,"label"=>"Element 2"),
70 array ("value"=>null,"label"=>"END group Groupe 1")// not displaid
71 );
72 *
73 * \endcode
74
75 *
76 * */
77 public function input($p_name=null,$p_value=null)
78 {
79 $this->name=($p_name==null)?$this->name:$p_name;
80 $this->value=($p_value==null)?$this->value:$p_value;
81 if ( $this->readOnly==true) return $this->display();
82 $style=(isset($this->style))?$this->style:"";
83 $this->id=($this->id=="")?$this->name:$this->id;
84
85 $disabled=($this->disabled==true)?"disabled":"";
86 $rowsize = (isset ($this->rowsize)) ? ' size = "'.$this->rowsize.'"':"";
87
88 $r="";
89
90 $a="<SELECT id=\"$this->id\" NAME=\"$this->name\" $style $this->javascript $disabled $rowsize>";
91 if (empty($this->value)) return '';
92 // var $start_group boolean , true the element OPTGROUP starts, false, it ends
93 $start_group=false;
94 for ( $i=0;$i<sizeof($this->value);$i++)
95 {
96 // open the element optgroup
97 if ($this->value[$i]['value']===null && !$start_group) {
98 $start_group=true;
99 $a.=sprintf('<optgroup label="%s">', htmlspecialchars($this->value[$i]['label']));
100 continue;
101 }
102 // close the element optgroup
103 if ($this->value[$i]['value']==null && $start_group) {
104 $start_group=false;
105 $a.='</optgroup >';
106 continue;
107 }
108 $checked=($this->selected==$this->value[$i]['value'])?"SELECTED":"";
109
110 $a.='<OPTION VALUE="'.$this->value[$i]['value'].'" '.$checked.'>';
111 $a.=strip_tags($this->value[$i]['label']);
112 }
113 $a.="</SELECT>";
114 if ( $this->table == 1 ) $a='<td>'.$a.'</td>';
115
116 return $r.$a;
117 }
118 /*!\brief print in html the readonly value of the widget*/
119 public function display()
120 {
121 $r="";
122 if ($this->value == null) {
123 $this->value=array();
124 }
125 for ( $i=0;$i<sizeof($this->value);$i++)
126 {
127 if ($this->selected==$this->value[$i]['value'] )
128 {
129 $r=htmlentities($this->value[$i]['label'],ENT_QUOTES|ENT_HTML5,'UTF-8',true);
130
131 }
132 }
133 // $r='<span class="input_text_ro">'.$r.'</span>';
134 if ( $this->table == 1 ) $r='<td>'.$r.'</td>';
135 return $r;
136 }
137 /*!\brief print in html the readonly value of the widget*/
138 public function get_value()
139 {
140 $r="";
141 for ( $i=0;$i<sizeof($this->value);$i++)
142 {
143 if ($this->selected==$this->value[$i]['value'] )
144 {
145 $r=$this->value[$i]['label'];
146
147 }
148 }
149 return $r;
150 }
151 /**
152 * @brief set the value of an ISelect with the array , this array
153 * is bidimensional , the first dimension is the code to store and the second
154 * is the label to display.
155 * Example
156 * @code
157 * array(array('M'=>'Mister'),array('Ms'=>'Miss'));
158 * // will be turned into
159 * array( array("value"=>'M,"label"=>"Mister")...)
160 * @endcode
161 * @param array $p_array
162 */
163 public function transform($p_array) {
164 if (! is_array($p_array) || count($p_array)==0) return ;
165 $a_ret=array();
166 foreach ($p_array as $key=>$value) {
167 $a_ret['value']=$key;
168 $a_ret['label']=$value;
169 $this->value[]=$a_ret;
170 }
171 }
172 function set_value($p_string) {
173 $this->selected=$p_string;
174 }
175 static public function test_me()
176 {
177 }
178}
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$select selected
$opd_description style
$from_poste name
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
input($p_name=null, $p_value=null)
show the html input of the widget
get_value()
print in html the readonly value of the widget
set_value($p_string)
Set the value of input (IText, INum,...)
display()
print in html the readonly value of the widget
transform($p_array)
set the value of an ISelect with the array , this array is bidimensional , the first dimension is the...
__construct($p_name="", $p_value="", $p_id="")
Constructor , $p_value is supposed to be an array.
static test_me()
$all table
$icard readOnly
$action rowsize
$all disabled