Umfragen
textExt.class.php
Go to the documentation of this file.
1 <?php
2 
3 
5  public $typ = "textExt";
6  public $direct_result = false;
7 
8  public $child_widgets_whitelist = array("text","labelTiny");
9  public $child_options_whitelist = array();
10 
11 
12  public function set_default_values($db){
13  $this->set_dispName("Bitte Fragestellung eingeben");
14  if( (isset($this->pollID)) AND (isset($this->ID)) AND (!empty($this->pollID)) AND (!empty($this->ID)) AND ($this->pollID != -1) AND ($this->ID != -1) ){
15  $this->widget_list = new object_list($this->pollID,$this->ID);
16  $this->option_list = new object_list($this->pollID,$this->ID);
17  $w1 = new labelTiny();
18  $w2 = new text();
19  $w1->set_default_values($db);
20  $w2->set_default_values($db);
21  $this->widget_list[] = $w1;
22  $this->widget_list[] = $w2;
23  $db->insert_widget($w1,POLLTYPE_SIMPLE);
24  $db->insert_widget($w2,POLLTYPE_SIMPLE);
25  }
26  }
27 
28 
29  /*
30  * DISPLAY
31  * */
32 
33  public function display_add_widget_edit(){
34  $widgets = array( array("name"=>"Text abfragen" , "type"=>"text") , array("name"=>"Text anzeigen","type"=>"labelTiny") );
35  echo "Element <select name='add_widget_type' style='margin-right:.4em'>";
36  foreach( $widgets as $widget ){
37  echo "<option value='{$widget["type"]}'>{$widget["name"]}</option>";
38  }
39  echo "</select>";
40 
41  echo "<input type='hidden' name='pollID' value='{$this->pollID}'/>";
42  echo "<input type='hidden' name='wID' value='{$this->ID}'/>";
43  echo "<input type='submit' name='addq_option_ID{$this->ID}' value='Hinzufügen' />";
44  }
45 
46  public function handle_add_widget_edit(){
47  $widgets = array( array("name"=>"Textabfrage" , "type"=>"text") , array("name"=>"Text anzeigen","type"=>"labelTiny") );
48  if( isset( $_POST["add_widget_type"])){
49  foreach( $widgets as $widget ){
50  if( $widget["type"] === $_POST["add_widget_type"]){
51  return $_POST["add_widget_type"];
52  }
53  }
54  }
55  return "";
56  }
57 
58  public function display_widget_list_edit($polltype){
59  echo "<table class='table_1' > ";
60  if($polltype == POLLTYPE_ADVANCED){
61  echo "<tr> <th>ID</th> <th style='width:8em'>Typ</th> <th>Fragestellung/Text</th> <th>Datenbank Name</th> <th></th> <th>Breite , Abstand</th> <th>Rechts</th> <th style='width:100px'></th> </tr>";
62  }else{
63  echo "<tr> <th>ID</th> <th style='width:8em'>Typ</th> <th>Fragestellung/Text</th> <th></th> <th>Breite , Abstand</th> <th>Rechts</th> <th style='width:100px'></th> </tr>";
64  }
65  $passed_float = false;
66  if( sizeof($this->widget_list) != 0 ){
67  foreach($this->widget_list as $widget){
68  $width= $widget->get_config("width");
69  $margin_left= $widget->get_config("margin-left");
70  $margin_right= $widget->get_config("margin-right");
71  $float = $widget->get_config("float");
72 
73  $edited = "";
74  if( (isset($_SESSION["last_option_edit"])) AND ( $_SESSION["last_option_edit"] == $widget->ID ) ){
75  $edited = "option_last_edit";
76  unset($_SESSION["last_option_edit"] );
77  }
78  echo "<tr class='$edited'>";
79  echo "<td>{$widget->ID}</td>";
80 
81 
82  if( $widget instanceof text ){
83  echo "<td><img src='".APP_ROOT."/icons/22/go-first.png' alt='' style='vertical-align:middle;margin-right:5px'/>Abfragen</td>";
84  echo "<td style='text-align:center'>
85  <input type='text' value='{$widget->dispName}' name='option_ID{$widget->ID}_name' placeholder='Fragestellung' style='width:90%' size='20'/>
86  </td>";
87  }else if( $widget instanceof labelTiny){
88  echo "<td><img src='".APP_ROOT."/icons/22/go-last.png' alt='' style='vertical-align:middle;margin-right:5px'/>Anzeigen</td>";
89  echo "<td style='text-align:center'>
90  <input type='text' value='{$widget->value}' name='option_ID{$widget->ID}_value' placeholder='Angezeigter Text' style='width:90%' size='20'/>
91  </td>";
92  }
93 
94  if( ($polltype == POLLTYPE_ADVANCED) ){
95  if( $widget instanceof input_widget ){
96  echo "<td style='text-align:center'>
97  <input type='text' value='{$widget->name}' name='option_ID{$widget->ID}_name2' placeholder='Name in der Datenbank' style='width:90%' size='10'/>
98  </td>";
99  }else{
100  echo "<td></td>";
101  }
102  }
103 
104 
105  if( $widget instanceof text ){
106  $conf = $widget->get_config("regexp");
107  echo "<td>";
108  echo "<select name='option_ID{$widget->ID}_regexp'>";
109  echo "<option value=''></option>";
110  foreach( $widget->regexp as $reg){
111  if( (isset($conf)) AND ($conf->exp == $reg->exp) ){
112  echo "<option value='{$reg->name}' selected='selected'> {$reg->desc_tiny} </option>";
113  }else{
114  echo "<option value='{$reg->name}'> {$reg->desc_tiny} </option>";
115  }
116  }
117  echo "</select>";
118  echo "</td>";
119  }else{
120  echo "<td></td>";
121  }
122 
123 
124  echo "<td style='text-align:center'>";
125  echo "<input type='text' value='$width' size='2' name='option_ID{$widget->ID}_width'/>,";
126  echo "&nbsp;l:<input type='text' value='$margin_left' size='2' name='option_ID{$widget->ID}_marginleft'/>";
127  echo "&nbsp;r:<input type='text' value='$margin_right' size='2' name='option_ID{$widget->ID}_marginright'/>";
128  echo "</td>";
129 
130  if(($float == "right") AND ($passed_float == false) ){$float_sel = "checked='checked'";}else{$float_sel = "";}
131  echo "<td style='text-align:center'><input type='radio' value='{$widget->ID}' name='option_alignright' $float_sel/></td>";
132  if($float == "right" ){$passed_float = true;}else{$passed_float=false;}
133 
134  echo "
135  <td>
136  <input type='submit' name='rmq_option_ID{$widget->ID}' title='Option Löschen' tabindex='-1' value='' 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;' />
137  <input type='submit' name='mvupq_option_ID{$widget->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;' />
138  <input type='submit' name='mvdwnq_option_ID{$widget->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' />
139  </td>";
140  echo "</tr>";
141  }
142  if( ($passed_float == false) ){$float_sel = "checked='checked'";}else{$float_sel = "";}
143  if($polltype == POLLTYPE_ADVANCED){
144  echo "<tr> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td>
145  <td style='text-align:center'><input type='radio' value='-1' name='option_alignright' $float_sel/></td>
146  <td></td> </tr>";
147  }else{
148  echo "<tr> <td></td> <td></td> <td></td> <td></td> <td></td>
149  <td style='text-align:center'><input type='radio' value='-1' name='option_alignright' $float_sel/></td>
150  <td></td> </tr>";
151  }
152  }else{
153 
154  }
155  echo "</table>";
156  }
157 
158  private function handle_widget_edit($ID){
159  $all_err = array();
160  $widget = $this->get_widget_by_id($ID);
161  if($widget instanceof text ){
162  $err = $widget->set_dispName( $_POST["option_ID{$widget->ID}_name"] );
163  }else if($widget instanceof labelTiny ){
164  $err = $widget->set_value( $_POST["option_ID{$widget->ID}_value"] );
165  }
166  if($err !== true){
167  $all_err[] = $err;
168  }
169 
170  if( (isset($_POST["option_ID{$widget->ID}_name2"])) AND ($_POST["option_ID{$widget->ID}_name2"] != "") AND ($widget instanceof input_widget) ) {
171  $err = $widget->set_name( $_POST["option_ID{$widget->ID}_name2"] );
172  if($err !== true){
173  $all_err[] = $err;
174  }
175  }else{
176  $widget->set_name( $widget->ID );
177  }
178 
179  if( (isset($_POST["option_ID{$widget->ID}_width"])) AND ($_POST["option_ID{$widget->ID}_width"] != "-1") ){
180  $err = $widget->set_config("width",$_POST["option_ID{$widget->ID}_width"]);
181  }else{
182  $err = $widget->set_config("width","-1");
183  }
184  if($err !== true){
185  $all_err[] = $err;
186  }
187 
188  if( (isset($_POST["option_ID{$widget->ID}_marginleft"])) ){
189  $err = $widget->set_config("margin-left",$_POST["option_ID{$widget->ID}_marginleft"]);
190  }else{
191  $err = $widget->set_config("margin-left","0");
192  }
193  if($err !== true){
194  $all_err[] = $err;
195  }
196 
197  if( (isset($_POST["option_ID{$widget->ID}_marginright"])) ){
198  $err = $widget->set_config("margin-right",$_POST["option_ID{$widget->ID}_marginright"]);
199  }else{
200  $err = $widget->set_config("margin-right","0");
201  }
202  if($err !== true){
203  $all_err[] = $err;
204  }
205 
206  if( (isset($_POST["option_ID{$widget->ID}_regexp"])) AND ($_POST["option_ID{$widget->ID}_regexp"] != "") ){
207  foreach( $widget->regexp as $exp ){
208  if( $exp->name === $_POST["option_ID{$widget->ID}_regexp"] ){
209  $widget->set_config("regexp",$exp->exp);
210  } // end if found
211  } // end foreach expression
212  }else{
213  $this->set_config("regexp","");
214  }
215  return $all_err;
216  }
217 
218  public function handle_widget_list_edit(){
219  // format: option_IDxx_name option_IDxx_value etc
220  $all_errs = "";
221  $options_seen = array();
222  // loop POST variable
223  $post_keys = array_keys($_POST);
224  foreach($post_keys as $post){
225  // if post array index beginns with "option_ID"
226  if( substr($post,0,strlen("option_ID")) == "option_ID"){
227  // get properety
228  if( substr($post,-1*strlen("name")) == "name"){
229  $prop = "name";
230  }else if( substr($post,-1*strlen("value")) == "value" ){
231  $prop = "value";
232  }else if( substr($post,-1*strlen("marginleft")) == "marginleft" ){
233  $prop = "marginleft";
234  }else if( substr($post,-1*strlen("marginright")) == "marginright" ){
235  $prop = "marginright";
236  }else if( substr($post,-1*strlen("width")) == "width" ){
237  $prop = "width";
238  }else if( substr($post,-1*strlen("name2")) == "name2" ){
239  $prop = "name2";
240  }else if( substr($post,-1*strlen("regexp")) == "regexp" ){
241  $prop = "regexp";
242  }
243  /*else if( substr($post,-1*strlen("linebr")) == "linebr" ){
244  $prop = "linebr";
245  }else if( substr($post,-1*strlen("max")) == "max" ){
246  $prop = "max";
247  }*/
248  }
249  if (isset($prop)){
250  // get id
251  $id = substr( $post , strlen("option_ID") , strlen($post)-strlen("option_ID")-strlen("_".$prop) );
252  // handle option edit only once .. here we have 3 times this Id
253  if( ($id != false) AND (is_numeric($id)) AND (!in_array(intval($id),$options_seen) ) ){
254  //$widget = $this->get_widget_by_id( intval($id) );
255  $err_reason = $this->handle_widget_edit(intval($id));
256  if( sizeof($err_reason) !== 0){
257  foreach( $err_reason as $err ){
258  $all_errs = $all_errs."<br/>".$err;
259  }
260  }
261  $options_seen[] = $id;
262  }
263  }
264  }
265  if( $_POST["option_alignright"] == "-1" ){
266  $float_right = -1;
267  }else{
268  $float_right = $this->get_widget_by_id($_POST["option_alignright"]);
269  }
270  if( (isset($_POST["option_alignright"])) AND ( isset($float_right) ) ){
271  $passed = false;
272  foreach( $this->widget_list as $child){
273  if( ($child->ID == $_POST["option_alignright"]) OR ($passed == true) ){
274  $passed = true;
275  $child->set_config("float","right");
276  }else{
277  $child->set_config("float","left");
278  }
279  }
280  }
281  if($all_errs !== ""){
282  return $all_errs;
283  }else{
284  return true;
285  }
286  }
287 
288 
289  public function display_dispName_edit(){
290  if( $this->dispName == "-" ){
291  $value = "";
292  }else{
294  }
295  echo "<label for='widget_dispname'>Gemeinsame Beschreibung der Antworten</label> <br/>
296  <input type='text' name='widget_dispname' id='widget_dispname' value='{$value}' placeholder='Optionaler Beschribungstext für alle Antworten' size='40' style='margin-left:1.5em' />";
297  }
298 
299  public function handle_dispName_edit(){
300  if( (isset($_POST["widget_dispname"])) AND ($_POST["widget_dispname"] != "") ){
301  $r = $this->set_dispName($_POST["widget_dispname"]);
302  if($r !== true){
303  return $r;
304  }else{
305  return true;
306  }
307  }else{
308  $this->set_dispName("-");
309  return true;
310  }
311  }
312 
313 
314 
315  public function display_edit(){
316  $font_bold= $this->get_config("font-bold");
317  if( $font_bold == true){ $font_bold = "font-weight:bold"; }else{ $font_bold=""; }
318 
319  $this->display_edit_begin();
320  echo "<table><tr>";
321  $float_passed = false;
322  foreach( $this->widget_list as $widget){
323  $float = $widget->get_config("float");
324  if( ($float == "right") AND ($float_passed == false) ){
325  echo "<td style='width:100%;'>&nbsp;</td>";
326  $float_passed = true;
327  }
328  echo "<td style='text-align:{$float};'>";
329  if( $widget instanceof text ){
330  $widget->display_child();
331  }else{
332  $widget->display();
333  }
334  echo "</td>";
335  }
336  echo "</tr></table>";
337  echo "</div>";
338  }
339 
340 
341  public function display(){
342  $font_family= $this->get_config("font-family");
343  $font_size= $this->get_config("font-size");
344  $font_bold= $this->get_config("font-bold");
345 
346  if( $font_family != ""){ $font_family = "font-family:".$font_family; }
347  if( $font_size != ""){ $font_size = "font-size:".$font_size; }
348  if( $font_bold == true){ $font_bold = "font-weight:bold"; }else{ $font_bold=""; }
349 
350  echo "<div class='widget_container textExt_widget' style='$font_family;$font_size;'>";
351 
352  echo "<table><tr>";
353  $float_passed = false;
354  foreach( $this->widget_list as $widget){
355  $float = $widget->get_config("float");
356  if( ($float == "right") AND ($float_passed == false) ){
357  echo "<td style='width:100%;'>&nbsp;</td>";
358  $float_passed = true;
359  }
360  echo "<td style='text-align:{$float};'>";
361  if( $widget instanceof text ){
362  $widget->display_child();
363  }else{
364  $widget->display();
365  }
366  echo "</td>";
367  }
368  echo "</tr></table>";
369 
370  echo "</div>";
371  }
372 
373  public function handle_inpt(){
374  $all_errs = array();
375  foreach( $this->widget_list as $widget ){
376  $err = $widget->handle_inpt();
377  if( $err !== true){
378  $all_errs[] = $err;
379  }
380  }
381  if( sizeof($all_errs) > 0 ){
382  return implode("<br/>",$all_errs);
383  }else{
384  return true;
385  }
386  }
387 
388 }
389 // ! no ending newLine
390 ?>