Umfragen
radioButton.class.php
Go to the documentation of this file.
1 <?php
2 
4 
5  public $typ = "radioButton";
6  public $id;
7  public $direct_result = false;
8 
9  function __construct(){
10  }
11 
12  public function set_default_values($db){
13  $this->set_dispName("Option {$this->index}");
14  $this->set_value("Option {$this->index}");
15  }
16 
17 
18  public function get_config($name){
19  $this->init_config();
20 
21  if( is_array($this->config) ){
22  if($name == "br"){
23  if( isset($this->config["br"]) ){
24  return $this->config["br"];
25  }else{
26  return false;
27  }
28 
29  }else{
30  return parent::get_config($name);
31  }
32  }
33  }
34 
35 
36  public function set_config($name,$val){
37  if( (!isset($this->config)) OR ($this->config == "") ){
38  $this->config = array();
39  }
40  $this->init_config();
41 
42  if($name == "br"){
43  if ( is_bool($val) ){
44  $this->config["br"] = $val;
45  }
46 
47  }else{
48  return parent::set_config($name,$val);
49  }
50  return true;
51  }
52 
59  public function set_data($name,$val){
60  if( $name == "br" ){
61  if( $val === true ){
62  $this->data["br"] = true;
63  }else{
64  $this->data["br"] = false;
65  }
66  }else{
67  parent::set_data($name,$val);
68  }
69  }
70 
76  public function get_data($name){
77  if( $name == "br" ){
78  if( isset($this->data["br"]) ){
79  return $this->data["br"];
80  }else{
81  return false;
82  }
83  }else{
84  return parent::get_data($name);
85  }
86  }
87 
88 
89  public function set_value($val){
90  $val = htmlspecialchars($val , ENT_QUOTES , "UTF-8",true);
91 
92  $err_reason = "";
93  if( (strlen($val) > 256) ){
94  $err_reason = "Wert der Option mit der ID {$this->ID} enthält mehr als 256 Zeichen.";
95  }
96  if( (strlen($val) == 0) ){
97  $err_reason = "Bitte Wert für die Wert Option mit der ID {$this->ID} angeben.";
98  }
99 
100  if($err_reason == ""){
101  $this->value = $val;
102  return true;
103  }else{
104  return $err_reason;
105  }
106 
107  }
108 
109 
110  public function display_option_edit($polltype){
111  $break = $this->get_config( "br" );
112  if( $break ){
113  $checked = "checked='checked'";
114  }else{
115  $checked = "";
116  }
117  $max = $this->get_config("max");
118  $edited ="";
119  if( (isset($_SESSION["last_option_edit"])) AND ( $_SESSION["last_option_edit"] == $this->ID ) ){
120  $edited = "option_last_edit";
121  unset($_SESSION["last_option_edit"] );
122  }
123 
124  echo "<tr class='$edited'>";
125  echo "<td>{$this->ID}</td>";
126  echo "<td style='text-align:center'>
127  <input type='text' value='{$this->dispName}' name='option_ID{$this->ID}_name' placeholder='Antwortmöglichkeit' style='width:90%'/>
128  </td>";
129  if($polltype == POLLTYPE_ADVANCED){
130  echo "<td style='text-align:center'>
131  <input type='text' value='{$this->value}' name='option_ID{$this->ID}_value' placeholder='Wert in der Datenbank' style='width:90%'/>
132  </td>";
133  }
134  echo "
135  <td>
136  <input type='submit' name='add_option_ID{$this->ID}' title='Option Einfügen' value='' style='padding:0px;margin:0px;background-color:transparent;background-image:url( ".APP_ROOT."/icons/22/list-add.png );background-repeat:no-repeat;width:26px;height:26px;' />
137  <input type='submit' name='rm_option_ID{$this->ID}' title='Option Löschen' value='' tabindex='-1' style='padding:0px;margin:0px;background-color:transparent;background-image:url( ".APP_ROOT."/icons/22/edit-delete.png );background-repeat:no-repeat;width:26px;height:26px;' />
138  <input type='submit' name='mvup_option_ID{$this->ID}' title='Option nach Oben schieben' tabindex='-1' value='' style='padding:0px;margin:0px;background-color:transparent;background-image:url( ".APP_ROOT."/icons/22/go-up.png );background-repeat:no-repeat;width:26px;height:26px;' />
139  <input type='submit' name='mvdwn_option_ID{$this->ID}' title='Option nach Unten schieben' tabindex='-1' value='' style='padding:0px;margin:0px;background-color:transparent;background-image:url( ".APP_ROOT."/icons/22/go-down.png );background-repeat:no-repeat;width:26px;height:26px' />
140  <input type='checkbox' value='br' name='option_ID{$this->ID}_linebr' tabindex='-1' style='margin-left:1em' $checked/> Umbruch
141  <span style='margin-left:1em'>Limit:</span><input type='text' name='option_ID{$this->ID}_max' size='3' tabindex='-1' value='$max'/>
142  </td>";
143  echo "</tr>";
144  }
145 
146 
147 
148  public function handle_option_edit(){
149  if( (isset($_POST["option_ID{$this->ID}_name"])) AND ($_POST["option_ID{$this->ID}_name"] != "") ){
150  $dispName = htmlspecialchars($_POST["option_ID{$this->ID}_name"] , ENT_QUOTES , "UTF-8",true);
151  if(strlen($dispName) < 256){
152  $this->dispName = $dispName;
153  }else{
154  return "Name der Option mit ID {$this->ID} enthält mehr als 256 Zeichen!";
155  }
156  }else{
157  return "Name der Option mit ID {$this->ID} nicht angegeben!";
158  }
159 
160  if( (isset($_POST["option_ID{$this->ID}_linebr"])) AND ($_POST["option_ID{$this->ID}_linebr"] == "br") ){
161  $this->set_config( "br" ,true );
162  }else{
163  $this->set_config( "br" ,false );
164  }
165  if( isset($_POST["option_ID{$this->ID}_max"]) ){
166  if( $_POST["option_ID{$this->ID}_max"] != "" ){
167  $this->set_config( "max" , intval($_POST["option_ID{$this->ID}_max"]) );
168  }else{
169  $this->set_config( "max" , -1 );
170  }
171  }
172 
173 
174  // dispName gültig, sonst return vorher schon.
175  if( isset($_POST["option_ID{$this->ID}_value"]) ){
176  if( ($_POST["option_ID{$this->ID}_value"] != "") ){
177  return $this->set_value( $_POST["option_ID{$this->ID}_value"] );
178  }else{
179  return $this->set_value( $this->dispName);
180  }
181  }else{
182  return $this->set_value( $this->dispName);
183  }
184 
185  return true;
186  }
187 
188 
189 
190  function display($sel=false,$columns="columns",$name=""){
191  if( !(isset($this->name)) OR !(isset($this->value)) OR ($this->value == "") OR ($this->name == "") ){
192  throw new exception("name or value not set");
193  }else{
194  if($sel === true){
195  $s = "checked='checked'";
196  }else{$s="";}
197 
198  $max = $this->get_config("max");
199  if( ($this->get_data("count") >= $max) AND ($max != -1) ){
200  // reset maximum deactivation if i already selected the option in the past
201  if( $sel === true ){
202  $active = "";
203  }else{
204  $active = "disabled='disabled'";
205  }
206  $active_style = "disabled_widget_text";
207  }else{$active="";$active_style="";}
208 
209  echo "<td><input type='radio' value='{$this->value}' name='{$name}' id='{$this->ID}' $s $active/> </td>".PHP_EOL;
210  echo "<td><label class='widget_answer $active_style' style='margin-right:2em' for='{$this->ID}' >{$this->dispName}</label></td>".PHP_EOL;
211  if( $columns == "rows" ){
212  if($this->get_config("br")){
213  echo "</tr><tr>";
214  }
215  }else if($columns == "columns"){
216  if($this->get_data("br")){
217  echo "</tr><tr>";
218  }
219  }
220 
221  }
222  }
223 
224 
225  function display2($sel=false){
226  if( !(isset($this->name)) OR !(isset($this->value)) OR ($this->value == "") OR ($this->name == "") ){
227  throw new exception("name or value not set");
228  }else{
229  if($sel == true){
230  $s = "selected='selected'";
231  }else{$s="";}
232 
233  $max = $this->get_config("max");
234  if( ($this->get_data("count") >= $max) AND ($max != -1) ){
235  // reset maximum deactivation if i already selected the option in the past
236  if( $sel === true ){
237  $active = "";
238  }else{
239  $active = "disabled='disabled'";
240  }
241  $active_style = "disabled_widget_text";
242  }else{$active="";$active_style="";}
243 
244  echo "<option value='{$this->value}' $s $active class='$active_style' style='min-width:15em'>{$this->dispName}</option>";
245  }
246 
247  }
248 
249  public function handle_inpt(){
250  return true;
251  }
252  public function display_edit(){
253 
254  }
255 
256 
257 }
258 
259 
261  function display($sel=false,$columns="columns",$name=""){
262  echo "<td></td><td></td>";
263  if( $columns == "rows" ){
264  if($this->get_config("br")){
265  echo "</tr><tr>";
266  }
267  }else if($columns == "columns"){
268  if($this->get_data("br")){
269  echo "</tr><tr>";
270  }
271  }
272  }
273 }
274 // ! no ending newLine
275 ?>