Umfragen
checkBox.class.php
Go to the documentation of this file.
1 <?php
3 class checkBox extends widget implements iWidget, input_widget, output_widget{
4 
5  public $typ = "checkBox";
6  public $direct_result = false;
7 
8 
9  function __construct(){
10  }
11 
12  public function set_value($val){
13  $val = htmlspecialchars($val , ENT_QUOTES , "UTF-8",true);
14 
15  $err_reason = "";
16  if( (strlen($val) > 256) ){
17  $err_reason = "Wert der Option mit der ID {$this->ID} enthält mehr als 256 Zeichen.";
18  }
19  if( (strlen($val) == 0) ){
20  $err_reason = "Bitte Wert für die Wert Option mit der ID {$this->ID} angeben.";
21  }
22 
23  if($err_reason == ""){
24  $this->value = $val;
25  return true;
26  }else{
27  return $err_reason;
28  }
29 
30  }
31 
32  public function set_default_values($db){
33  $this->set_dispName("Option {$this->index}");
34  $this->set_value("Option {$this->index}");
35  }
36 
37 
38  public function get_config($name){
39  $this->init_config();
40 
41  if( is_array($this->config) ){
42  if($name == "br"){
43  if( isset($this->config["br"]) ){
44  return $this->config["br"];
45  }else{
46  return false;
47  }
48 
49  }else{
50  return parent::get_config($name);
51  }
52  }
53  }
54 
55 
56  public function set_config($name,$val){
57  if( (!isset($this->config)) OR ($this->config == "") ){
58  $this->config = array();
59  }
60  $this->init_config();
61 
62  if($name == "br"){
63  if ( is_bool($val) ){
64  $this->config["br"] = $val;
65  }
66 
67  }else{
68  return parent::set_config($name,$val);
69  }
70  return true;
71  }
72 
79  public function set_data($name,$val){
80  if( $name == "br" ){
81  if( $val === true ){
82  $this->data["br"] = true;
83  }else{
84  $this->data["br"] = false;
85  }
86  }else{
87  parent::set_data($name,$val);
88  }
89  }
90 
96  public function get_data($name){
97  if( $name == "br" ){
98  if( isset($this->data["br"]) ){
99  return $this->data["br"];
100  }else{
101  return false;
102  }
103  }else{
104  return parent::get_data($name);
105  }
106  }
107 
108 
109  public function display_option_edit($polltype){
110  $break = $this->get_config( "br" );
111  if( $break ){
112  $checked = "checked='checked'";
113  }else{
114  $checked = "";
115  }
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  public function handle_option_edit(){
147  if( (isset($_POST["option_ID{$this->ID}_name"])) AND ($_POST["option_ID{$this->ID}_name"] != "") ){
148  $dispName = htmlspecialchars($_POST["option_ID{$this->ID}_name"] , ENT_QUOTES , "UTF-8",true);
149  if(strlen($dispName) < 256){
150  $this->dispName = $dispName;
151  }else{
152  return "Name der Option mit ID {$this->ID} enthält mehr als 256 Zeichen!";
153  }
154  }else{
155  return "Name der Option mit ID {$this->ID} nicht angegeben!";
156  }
157 
158  if( (isset($_POST["option_ID{$this->ID}_linebr"])) AND ($_POST["option_ID{$this->ID}_linebr"] == "br") ){
159  $this->set_config( "br" ,true );
160  }else{
161  $this->set_config( "br" ,false );
162  }
163  if( isset($_POST["option_ID{$this->ID}_max"]) ){
164  if( $_POST["option_ID{$this->ID}_max"] != "" ){
165  $this->set_config( "max" , intval($_POST["option_ID{$this->ID}_max"]) );
166  }else{
167  $this->set_config( "max" , -1 );
168  }
169  }
170 
171  // dispName gültig, sonst return vorher schon.
172  if( isset($_POST["option_ID{$this->ID}_value"]) ){
173  if( ($_POST["option_ID{$this->ID}_value"] != "") ){
174  return $this->set_value( $_POST["option_ID{$this->ID}_value"] );
175  }else{
176  return $this->set_value( $this->dispName);
177  }
178  }else{
179  return $this->set_value( $this->dispName);
180  }
181 
182  return true;
183  }
184 
185 
186  function display($sel=false,$columns="columns"){
187  if( !(isset($this->name)) OR !(isset($this->value)) OR ($this->value == "") OR ($this->name == "") ){
188  throw new exception("name or value not set");
189  }else{
190  if($sel == true){
191  $s = "checked='checked'";
192  }else{$s="";}
193 
194  // disable on limit reached
195  $max = $this->get_config("max");
196  if( ($this->get_data("count") >= $max) AND ($max != -1) ){
197  $active_style = "disabled_widget_text";
198  // allow deselecting when limit reached and selected
199  if( $sel === false ){
200  $active="disabled='disabled'";
201  }else{
202  $active= "";
203  }
204  }else{$active_style = $active = "";}
205 
206  echo "<td><input type='checkbox' value='{$this->value}' name='{$this->ID}' id='{$this->ID}' $s $active/> </td>".PHP_EOL;
207  echo "<td><label class='widget_answer $active_style' style='margin-right:2em' for='{$this->ID}' >{$this->dispName}</label></td>".PHP_EOL;
208  // handle line break if activated
209 
210  if( $columns == "rows" ){
211  if($this->get_config("br")){
212  echo "</tr><tr>";
213  }
214  }else if($columns == "columns"){
215  if($this->get_data("br")){
216  echo "</tr><tr>";
217  }
218  }
219 
220  }
221  }
222 
223  public function handle_inpt(){
224  return true;
225  }
226  public function display_edit(){
227 
228  }
229 
230 
231 }
232 
233 
234 // ! no ending newLine
235 ?>