Umfragen
schedule.class.php
Go to the documentation of this file.
1 <?php
2 
3 class schedule extends container implements iWidget, input_widget, output_widget{
4  public $typ = "schedule";
5  public $child_widgets_whitelist = array("scheduleDate","scheduleName");
6  public $child_options_whitelist = array("scheduleOption");
7 
8  public $direct_result = false;
9 
10  public function set_default_values($db){
11  $this->set_dispName("-");
12 
13  if( (isset($this->pollID)) AND (isset($this->ID)) AND (!empty($this->pollID)) AND (!empty($this->ID)) AND ($this->pollID != -1) AND ($this->ID != -1) ){
14  $this->widget_list = new object_list($this->pollID,$this->ID);
15  $this->option_list = new object_list($this->pollID,$this->ID);
16 
17  $nick = new scheduleName();
18  $nick->set_dispName("Termin planen Name");
19  $nick->set_name("-");
20  $nick->set_value("");
21  $this->insert_widget(-1,$nick);
22  $db->insert_widget($nick,POLLTYPE_SIMPLE);
23 
24  $date = new scheduleDate();
25  $date->set_default_values($db);
26  $this->insert_widget(-1,$date);
27  $db->insert_widget($date,POLLTYPE_SIMPLE);
28  }
29 
30  }
31 
32 
39  public function set_data($name,$val){
40  if( $name == "users" ){
41  if( is_array($val) ){
42  $this->data["users"] = $val;
43  }
44  }else{
45  parent::set_data($name,$val);
46  }
47  }
48 
54  public function get_data($name){
55  if( $name == "users" ){
56  if( isset($this->data["users"]) ){
57  return $this->data["users"];
58  }else{
59  $tmp = array();
60  foreach( $this->widget_list as $child ){
61  $tmp[ $child->ID ] = array();
62  }
63  return $tmp;
64  }
65  }else{
66  return parent::get_data($name);
67  }
68 
69  }
70 
71  public function get_config($name){
72  if(!is_array($this->config)){
73  $this->unserialize_config();
74  }
75 
76 
77  if( is_array($this->config) ){
78  if( $name == "displayOtherUsers" ){
79  if( isset($this->config["displayOtherUsers"]) ){
80  return $this->config["displayOtherUsers"];
81  }else{
82  return true;
83  }
84 
85  }else if( $name == "displayOtherUsersStatistics" ){
86  if( isset($this->config["displayOtherUsersStatistics"]) ){
87  return $this->config["displayOtherUsersStatistics"];
88  }else{
89  return true;
90  }
91  }else if( $name == "usernameRestriction" ){
92  if( isset($this->config["usernameRestriction"]) ){
93  return $this->config["usernameRestriction"];
94  }else{
95  return "free";
96  }
97  }else if( $name == "yesValue" ){
98  if( isset($this->config["yesValue"]) ){
99  return $this->config["yesValue"];
100  }else{
101  return "Ja";
102  }
103  }else if( $name == "noValue" ){
104  if( isset($this->config["noValue"]) ){
105  return $this->config["noValue"];
106  }else{
107  return "Nein";
108  }
109  }else if( $name == "maybeValue" ){
110  if( isset($this->config["maybeValue"]) ){
111  return $this->config["maybeValue"];
112  }else{
113  return "Vielleicht";
114  }
115  }else{
116  return parent::get_config($name);
117  }
118  }
119  }
120 
121  public function set_config($name,$val){
122  if( (!isset($this->config)) OR ($this->config == "") ){
123  $this->config = array();
124  }
125  if( (isset($this->config)) AND (is_string($this->config)) AND ($this->config != "") ){
126  $this->unserialize_config();
127  }
128 
129  if( $name == "displayOtherUsers" ){
130  if( $val === true ){
131  $this->config["displayOtherUsers"] = true;
132  }else{
133  $this->config["displayOtherUsers"] = false;
134  }
135  }else if( $name == "displayOtherUsersStatistics" ){
136  if( $val === true ){
137  $this->config["displayOtherUsersStatistics"] = true;
138  }else{
139  $this->config["displayOtherUsersStatistics"] = false;
140  }
141  }else if( $name == "usernameRestriction" ){
142  $list = array("free", "force", "none");
143  if( in_array($val,$list) ){
144  $this->config["usernameRestriction"] = $val;
145  }else{
146  return "Wert für usernameRestriction ungültig";
147  }
148  }else if( $name == "yesValue" ){
149  $value_clean = htmlspecialchars($val , ENT_QUOTES , "UTF-8",true);
150  if( (strlen($value_clean) > 25) ){
151  return "Wert für die Antwort \"Ja\" enthält mehr als 25 Zeichen";
152  }else{
153  $this->config["yesValue"] = $value_clean;
154  }
155  }else if( $name == "noValue" ){
156  $value_clean = htmlspecialchars($val , ENT_QUOTES , "UTF-8",true);
157  if( (strlen($value_clean) > 25) ){
158  return "Wert für die Antwort \"Nein\" enthält mehr als 25 Zeichen";
159  }else{
160  $this->config["noValue"] = $value_clean;
161  }
162  }else if( $name == "maybeValue" ){
163  $value_clean = htmlspecialchars($val , ENT_QUOTES , "UTF-8",true);
164  if( (strlen($value_clean) > 25) ){
165  return "Wert für die Antwort \"Vielleicht\" enthält mehr als 25 Zeichen";
166  }else{
167  $this->config["maybeValue"] = $value_clean;
168  }
169  }else{
170  return parent::set_config($name,$val);
171  }
172  return true;
173  }
174 
175 
180  public function get_name_widget(){
181  foreach( $this->widget_list as $child){
182  if($child instanceof scheduleName){
183  return $child;
184  }
185  }
186  }
187 
188 
189 
190  /*
191  * DISPLAY
192  * */
194  $sel = '';
195  if( $this->get_config("displayOtherUsers") ){
196  $sel = "checked='checked'";
197  }
198 
199  echo "<input type='checkbox' name='display_other_participants' id='display_other_participants' value='true' $sel/>";
200  echo "<label for='display_other_participants'>Andere Teilnehmer und ihre Antworten anzeigen</label>";
201  }
202 
204  if( (isset($_POST["display_other_participants"])) AND ($_POST["display_other_participants"] == "true") ){
205  $r = $this->set_config("displayOtherUsers",true);
206  }else{
207  $r = $this->set_config("displayOtherUsers",false);
208  }
209  return $r;
210  }
211 
213  $sel = '';
214  if( $this->get_config("displayOtherUsersStatistics") ){
215  $sel = "checked='checked'";
216  }
217 
218  echo "<input type='checkbox' name='display_other_participants_stats' id='display_other_participants_stats' value='true' $sel/>";
219  echo "<label for='display_other_participants_stats'>Zahlen über die anderen Antworten anzeigen</label>";
220  }
221 
223  if( (isset($_POST["display_other_participants_stats"])) AND ($_POST["display_other_participants_stats"] == "true") ){
224  $r = $this->set_config("displayOtherUsersStatistics",true);
225  }else{
226  $r = $this->set_config("displayOtherUsersStatistics",false);
227  }
228  return $r;
229  }
230 
231 
232  public function display_username_edit(){
233  $sel = '';
234  $config = $this->get_config("usernameRestriction");
235  $val_list = array("free" => "Frei wählbar" , "force" => "Namen erzwingen" , "none" => "Nicht danch fragen");
236 
237  echo "Name: <select name='username_restriction'>";
238  foreach( array_keys($val_list) as $val ){
239  if( $config == $val ){
240  echo "<option value='$val' selected='selected'>{$val_list[$val]}</option>";
241  }else{
242  echo "<option value='$val'>{$val_list[$val]}</option>";
243  }
244  }
245  echo "</select>";
246  }
247 
248  public function handle_username_edit(){
249  $val_list = array("free", "force", "none");
250 
251  if( (isset($_POST["username_restriction"])) AND (in_array($_POST["username_restriction"],$val_list )) ){
252  return $this->set_config("usernameRestriction",$_POST["username_restriction"]);
253  }else{
254  return "Kein gültiger Wert";
255  }
256 
257  }
258 
259  public function display_value_edit(){
260  $yesValue = $this->get_config("yesValue");
261  $noValue = $this->get_config("noValue");
262  $maybeValue = $this->get_config("maybeValue");
263  echo "<table>";
264  echo "<tr>";
265  echo "<td style='text-align:right;color:#9AC74D'><label for='yesValue'>Wert \"Ja\"</label>: </td>";
266  echo "<td><input type='text' name='yesValue' id='yesValue' value='$yesValue'/></td>";
267  echo "<td style='font-size:80%;color:#3C0200;font-style:italic'>Maximal 25 Zeichen</td>";
268  echo "</tr>";
269  echo "<tr>";
270  echo "<td style='text-align:right;color:#C7A24D'><label for='maybeValue'>Wert \"Vielleicht\"</label>: </td>";
271  echo "<td><input type='text' name='maybeValue' id='maybeValue' value='$maybeValue'/></td>";
272  echo "<td style='font-size:80%;color:#3C0200;font-style:italic'>Maximal 25 Zeichen</td>";
273  echo "</tr>";
274  echo "<tr>";
275  echo "<td style='text-align:right;color:#C74D5D'><label for='noValue'>Wert \"Nein\"</label>: </td>";
276  echo "<td><input type='text' name='noValue' id='noValue' value='$noValue'/></td>";
277  echo "<td style='font-size:80%;color:#3C0200;font-style:italic'>Maximal 25 Zeichen</td>";
278  echo "</tr>";
279  echo "</table>";
280  }
281 
282  public function handle_value_edit(){
283  $all_err = "";
284  if( (isset($_POST["yesValue"])) AND ($_POST["yesValue"] != "") ){
285  $err = $this->set_config("yesValue",$_POST["yesValue"]);
286  }
287  if( $err !== true){
288  $all_err .= "<br/>".$err;
289  }
290  if( (isset($_POST["maybeValue"])) AND ($_POST["maybeValue"] != "") ){
291  $err = $this->set_config("maybeValue",$_POST["maybeValue"]);
292  }
293  if( $err !== true){
294  $all_err .= "<br/>".$err;
295  }
296  if( (isset($_POST["noValue"])) AND ($_POST["noValue"] != "") ){
297  $err = $this->set_config("noValue",$_POST["noValue"]);
298  }
299  if( $err !== true){
300  $all_err .= "<br/>".$err;
301  }
302  if( $all_err != "" ){
303  return $all_err;
304  }
305  return true;
306  }
307 
308  public function display_date_list_edit($polltype){
309  echo "<table class='edit_schedule_table' > ";
310  $rows = array("edit","from date","from time","separator","to date","to time");
311  $rows_desc = array( "", "Von / Am",
312  "<span style='font-style:italic;font-size:70%'>Uhrzeit</span><span style='color:#E25C57'> * </span>",
313  "" ,
314  "Bis<span style='color:#E25C57'> * </span>" ,
315  "<span style='font-style:italic;font-size:70%'>Uhrzeit</span><span style='color:#E25C57'> * </span>");
316 
317  if( (sizeof($this->widget_list) > 1) ){
318  $r = 0;
319  foreach( $rows as $code ){
320  $cl = "";
321  if( $code == "separator" ){
322  $cl = "spacer_tr";
323  }
324  echo "<tr class='$cl'>";
325  $code_arr = explode(" ",$code);
326  echo "<th class='{$code_arr[0]}_td'>{$rows_desc[$r]}</th>";
327 
328  foreach($this->widget_list as $child ){
329  if( $child instanceof scheduleDate ){
330  $edited ="";
331  if( (isset($_SESSION["last_option_edit"])) AND ( $_SESSION["last_option_edit"] == $child->ID ) ){
332  $edited = "option_last_edit_schedule";
333  }
334 
335  if( $code == "edit" ){
336  echo "<td class='schedule_edit_td'>
337  <input type='submit' name='rmq_option_ID{$child->ID}' title='Frage 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;' />
338  </td>";
339  }else if($code == "separator"){
340  echo "<td></td>";
341  }else{
342  echo "<td class='{$code_arr[0]}_td $edited'>";
343  $child->display_date_input($code_arr[0],$code_arr[1]);
344  echo "</td>";
345  }
346  }
347  }
348  if( $r == 1 ){
349  $s = sizeof($rows)-1;
350  echo "<td class='schedule_edit_td'><input type='submit' name='addq_option_ID{$child->ID}' title='Frage 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;' /></td>";
351  }else{
352  if($code != "separator"){
353  echo "<td class='schedule_edit_td'></td>";
354  }
355  }
356  echo "</tr>";
357  ++$r;
358  }
359  }else{
360  echo "<tr><td><input type='submit' name='addq_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;' /></td></tr>";
361  }
362  echo "</table>";
363  unset($_SESSION["last_option_edit"] );
364 
365  }
366 
367  public function handle_date_list_edit(){
368  // format: $prefix = "date_{$this->ID}_{$code}";
369  $all_errs = "";
370  $options_seen = array();
371  $code_wl = array("from","to");
372  $type_wl = array("datepicker","time","day","month","year");
373  // loop POST variable
374  $post_keys = array_keys($_POST);
375  foreach($post_keys as $post){
376  $tmp = explode("_",$post);
377  if( sizeof($tmp) == 4 ){
378  if( is_numeric( $tmp[1]) ){
379  $id = intval($tmp[1]);
380  $code = $tmp[2];
381  $type = $tmp[3];
382  // handle only once
383  if( (!in_array(intval($id),$options_seen)) AND (in_array($code,$code_wl)) AND (in_array($type,$type_wl)) ){
384  $child = $this->get_widget_by_id($id);
385  if( $child instanceof scheduleDate ){
386  $err_reason = $child->handle_date_edit();
387  if($err_reason !== true){
388  $all_errs = $all_errs."<br/>".$err_reason;
389  }
390  }
391  $options_seen[] = $id;
392  } // end if whitelisted
393  } // end if ID numeric
394  } // end if _ array
395  } // end foreach post
396 
397  if($all_errs !== ""){
398  return $all_errs;
399  }else{
400  return true;
401  }
402  }
403 
404 
405  private function format_date_array_for_display($date){
406  $month_names = array( "" , "Jan." , "Feb." , "Mrz." ,"Apr." , "Mai" , "Jun." , "Jul." , "Aug" , "Sep." , "Oct.", "Nov." , "Dez.");
407  $fmt = array("year","mon","day","hour","min","time");
408  foreach( array_keys($date) as $key ){
409  if( $key == "tm_year" ){
410  $fmt["year"] = (string) $date[$key];
411  }else if( $key == "tm_mon" ){
412  $fmt["mon"] = $month_names[ $date[$key] ];
413  }else if( $key == "tm_mday" ){
414  if( $date[$key] < 10 ){
415  $fmt["day"] = "0{$date[$key]}.";
416  }else{
417  $fmt["day"] = "{$date[$key]}.";
418  }
419  }else if( $key == "tm_hour" ){
420  if( $date[$key] < 10 ){
421  $fmt["hour"] = "0{$date[$key]}";
422  }else{
423  $fmt["hour"] = "{$date[$key]}";
424  }
425  }else if( $key == "tm_min" ){
426  if( $date[$key] < 10 ){
427  $fmt["min"] = "0{$date[$key]}";
428  }else{
429  $fmt["min"] = "{$date[$key]}";
430  }
431  }
432  }
433  $fmt["time"] = "{$fmt["hour"]}:{$fmt["min"]}";
434  return $fmt;
435  }
436 
437  private function make_table_header_date(){
438  $date_str_common = $date_str_from= $date_str_to = "";
439 
440  foreach( $this->widget_list as $child ){
441  if( $child instanceof scheduleDate ){
442  $from = $child->get_date("from");
443  $to = $child->get_date("to");
444  $from_arr = $child->get_date_array($from);
445  $to_arr = $child->get_date_array($to);
446 
447  if( (!empty($from_arr)) AND (!empty($to_arr)) ){
448  $date_str = "";
449  $year_same = $month_same = $day_same = false;
450  $fromf = $this->format_date_array_for_display($from_arr);
451  $tof = $this->format_date_array_for_display($to_arr);
452 
453  if( $from_arr["tm_year"] === $to_arr["tm_year"] ){
454  $year_same = true;
455  }
456  if( $from_arr["tm_mon"] === $to_arr["tm_mon"] ){
457  $month_same = true;
458  }
459  if( $from_arr["tm_mday"] === $to_arr["tm_mday"] ){
460  $day_same = true;
461  }
462 
463  if( $year_same AND $month_same AND $day_same ){
464  $date_str_common .= "<th class='head_date_th date_common'>{$fromf["day"]} {$fromf["mon"]} {$fromf["year"]} </th>";
465  if( $fromf["time"] != "00:00" ){
466  $date_str_from .= "<th class='head_date_th date_from'>{$fromf["time"]}</th>";
467  }
468  if( $tof["time"] != "00:00" ){
469  $date_str_to .= "<th class='head_date_th date_to'>{$tof["time"]}</th>";
470  }
471  }else if( ($year_same) OR ($year_same AND $month_same) ){
472  $date_str_common .= "<th class='head_date_th date_common'>{$fromf["year"]}</th>";
473  $date_str_from .= "<th class='head_date_th date_from'><span style='display:block;font-weight:bold'>{$fromf["day"]} {$fromf["mon"]}</span>";
474  if( $fromf["time"] != "00:00" ){
475  $date_str_from .= "<span style='display:block'>{$fromf["time"]}</span></th>";
476  }
477  $date_str_to .= "<th class='head_date_th date_to'><span style='display:block;font-weight:bold'>{$tof["day"]} {$tof["mon"]}</span>";
478  if( $tof["time"] != "00:00" ){
479  $date_str_to .= "<span style='display:block'>{$tof["time"]}</span></th>";
480  }
481  }else{
482  $date_str_common .= "<th class='head_date_th date_common'></th>";
483  $date_str_from .= "<th class='head_date_th date_from'><span style='display:block'><span style='font-weight:bold'>{$fromf["day"]} {$fromf["mon"]}</span> {$fromf["year"]}</span>";
484  if( $fromf["time"] != "00:00" ){
485  $date_str_from .= "<span class='head_date_span date_from' style='display:block'>{$fromf["time"]}</span></th>";
486  }
487  if( $to !== "0000-00-00 00:00" ){
488  $date_str_to .= "<th class='head_date_th date_to'><span style='display:block'><span style='display:block'><span style='font-weight:bold'>{$tof["day"]} {$tof["mon"]}</span> {$tof["year"]}</span>";
489  if( $tof["time"] != "00:00" ){
490  $date_str_to .= "<span style='display:block'>{$tof["time"]}</span></th>";
491  }
492  }else{
493  $date_str_to .= "<th class='head_date_th date_to'></th>";
494  }
495 
496  } // end if same
497 
498  } // end if date not empty
499  }// end if date object
500  }// end foreach widget
501  return array( "common" => $date_str_common, "from" => $date_str_from, "to" => $date_str_to );
502  }
503 
504 
505  public function display_edit(){
506  $font_family= $this->get_config("font-family");
507  $font_size= $this->get_config("font-size");
508  $font_bold= $this->get_config("font-bold");
509  if( $font_family != ""){ $font_family = "font-family:".$font_family; }
510  if( $font_size != ""){ $font_size = "font-size:".$font_size; }
511  if( $font_bold == true){ $font_bold = "font-weight:bold"; }else{ $font_bold=""; }
512 
513  $month_names = array( "" , "Jan." , "Feb." , "Mrz." ,"Apr." , "Mai" , "Jun." , "Jul." , "Aug" , "Sep." , "Oct.", "Nov." , "Dez.");
514  $data = $this->get_data("users");
515  $count = array( );
516 
517  //$options_vals = array( "","Ja" , "Vielleicht" ,"Nein" );
518  //$options = array("","yes","maybe","no");
519  $yesValue = $this->get_config("yesValue");
520  $noValue = $this->get_config("noValue");
521  $maybeValue = $this->get_config("maybeValue");
522  $options_map = array( "" => "" , "yes" => $yesValue , "maybe" => $maybeValue , "no" => $noValue );
523 
524  $c_no_to = 0;
525  $c_dates = 0;
526  $no_to = false;
527  foreach( $this->widget_list as $child ){
528  if( ($child instanceof scheduleName) ){
529  $name_wid = $child;
530  }else if( $child instanceof scheduleDate){
531  if( $child->get_date("to") == "0000-00-00 00:00" ){ ++$c_no_to; }
532  ++$c_dates;
533  }
534  $count[ $child->ID] = array("yes"=>0 ,"maybe"=>0 ,"no" =>0);
535  }
536  if( $c_no_to == $c_dates ){
537  $no_to = true;
538  }
539 
540  $this->display_edit_begin();
541  echo "<table class='schedule_table'>";
542  // HEADER FROM TO
543  $tmp = $this->make_table_header_date();
544  $date_str_common = $tmp["common"];
545  $date_str_from = $tmp["from"];
546  $date_str_to = $tmp["to"];
547  echo "<tr><th></th>$date_str_common</tr>";
548  if( $no_to === false){
549  echo "<tr><th style='text-align:right;padding-right:1em''>von/am</th>$date_str_from</tr>";
550  echo "<tr><th style='text-align:right;padding-right:1em'>bis</th>$date_str_to</tr>";
551  }else{
552  echo "<tr><th style='text-align:right;padding-right:1em''>am</th>$date_str_from</tr>";
553  }
554  // PARTICIPATION OTHERS
555  if( $this->get_config("displayOtherUsers") ){
556  $cells = str_repeat("<td></td>",sizeof($this->widget_list));
557  echo "<tr class='spacer_tr'>$cells</tr>";
558  echo "<tr><th style='text-align:right;padding-right:1em;' class='schedule_response_td_name'>Max Muster</th>";
559  foreach( $this->widget_list as $child ){
560  if( !$child instanceof scheduleName ){
561  echo "<td class='schedule_response_td schedule_response_td_yes'>{$yesValue}</td>";
562  } // end if scheduledate
563  } // end foreach widget
564  echo "</tr>";
565  } // end if config
566 
567 
568  // PARTICIPATION COUNT
569  if( $this->get_config("displayOtherUsersStatistics") ){
570  $cells = str_repeat("<td></td>",sizeof($this->widget_list));
571  echo "<tr class='spacer_tr'>$cells</tr>";
572  echo "<tr style='text-align:center' class='schedule_count_tr'><td></td>";
573  foreach( $this->widget_list as $child ){
574  if( !$child instanceof scheduleName ){
575  echo "<td>";
576  foreach( array("yes","maybe","no") as $val){
577  $m = "";
578  echo "<span class='schedule_count_span_$val $m'>{$count[$child->ID][$val]}</span>";
579  }
580  echo "</td>";
581  }
582  }
583  } // end if config
584 
585  // PARTICIPATION SELF
586  $cells = str_repeat("<td></td>",sizeof($this->widget_list));
587  echo "<tr class='spacer_tr'>$cells</tr>";
588  echo "<tr class='participate_tr'>";
589  $name_restriction = $this->get_config("usernameRestriction");
590  if( $name_restriction == "free" ){
591  $name = $_SESSION["user"]->fullName;
592  echo "<td><input type='text' value='{$name}' size='10' name='{$this->name}_name'/></td>";
593  }else if($name_restriction == "force"){
594  $name = $_SESSION["user"]->fullName;
595  echo "<td>{$name}</td>";
596  }else if( $name_restriction == "none" ){
597  echo "<td>Du:</td>";
598  }
599 
600  foreach( $this->widget_list as $child ){
601  if( $child instanceof scheduleDate){
602  echo "<td> <select name='{$child->name}'>";
603  foreach( array_keys($options_map) as $op ){
604  echo "<option value='{$op}'>{$options_map[$op]}</option>";
605  } // end foreach option
606  echo " </select> </td>";
607  } // end if Date
608  } // end foreach child
609  echo "</tr>";
610 
611  echo "</table>";
612  echo "</div>";
613 
614  }
615 
616 
617  public function display(){
618  $font_family= $this->get_config("font-family");
619  $font_size= $this->get_config("font-size");
620  $font_bold= $this->get_config("font-bold");
621  if( $font_family != ""){ $font_family = "font-family:".$font_family; }
622  if( $font_size != ""){ $font_size = "font-size:".$font_size; }
623  if( $font_bold == true){ $font_bold = "font-weight:bold"; }else{ $font_bold=""; }
624 
625  $month_names = array( "" , "Jan." , "Feb." , "Mrz." ,"Apr." , "Mai" , "Jun." , "Jul." , "Aug" , "Sep." , "Oct.", "Nov." , "Dez.");
626  $data = $this->get_data("users");
627  $count = array( );
628 
629  //$options = array( "","Ja" , "Vielleicht" ,"Nein" );
630  //$options_vals = array("","yes","maybe","no");
631  $yesValue = $this->get_config("yesValue");
632  $noValue = $this->get_config("noValue");
633  $maybeValue = $this->get_config("maybeValue");
634  $options_map = array( "" => "" , "yes" => $yesValue , "maybe" => $maybeValue , "no" => $noValue );
635 
636  $c_no_to = 0;
637  $c_dates = 0;
638  $no_to = false;
639  foreach( $this->widget_list as $child ){
640  if( ($child instanceof scheduleName) ){
641  $name_wid = $child;
642  }else if( $child instanceof scheduleDate){
643  if( $child->get_date("to") == "0000-00-00 00:00" ){ ++$c_no_to; }
644  ++$c_dates;
645  }
646  $count[ $child->ID] = array("yes"=>0 ,"maybe"=>0 ,"no" =>0);
647  }
648  if( $c_no_to == $c_dates ){
649  $no_to = true;
650  }
651 
652  echo "<div class='widget_container schedule_widget' style='$font_family;$font_size'>";
653  echo "<table class='schedule_table'>";
654  // HEADER FROM TO
655  $tmp = $this->make_table_header_date();
656  $date_str_common = $tmp["common"];
657  $date_str_from = $tmp["from"];
658  $date_str_to = $tmp["to"];
659  echo "<tr><th></th>$date_str_common</tr>";
660  echo "<tr><th style='text-align:right;padding-right:1em''>von/am</th>$date_str_from</tr>";
661  if( $no_to === false ){
662  echo "<tr><th style='text-align:right;padding-right:1em'>bis</th>$date_str_to</tr>";
663  }
664  // PARTICIPATION OTHERS
665  if( $this->get_config("displayOtherUsers") ){
666  $cells = str_repeat("<td></td>",sizeof($this->widget_list));
667  echo "<tr class='spacer_tr'>$cells</tr>";
668  if( isset($name_wid) ){
669  // data in format of $data[ child widget ID ][ 0-based index ] = value
670  for( $i=0 ; $i<sizeof($data[$name_wid->ID]) ; ++$i ){
671  echo "<tr><th style='text-align:right;padding-right:1em;' class='schedule_response_td_name'>{$data[$name_wid->ID][$i]}</th>";
672  foreach( $this->widget_list as $child ){
673  if( (!$child instanceof scheduleName) ){
674  if( (isset($data[$child->ID])) AND (isset($data[$child->ID][$i])) ){
675  $css ="";
676  if( $data[$child->ID][$i] == $yesValue ){ ++$count[$child->ID]["yes"];$css="yes";}
677  else if( $data[$child->ID][$i] == $maybeValue ){++$count[$child->ID]["maybe"];$css="maybe";}
678  else if( $data[$child->ID][$i] == $noValue ){++$count[$child->ID]["no"];$css="no";}
679  echo "<td class='schedule_response_td schedule_response_td_{$css}'>{$data[$child->ID][$i]}</td>";
680  }else{
681  echo "<td></td>";
682  } // end if data
683  } // end if scheduledate
684  } // end foreach widget
685  echo "</tr>";
686  } // end foreach data row
687  echo "</tr>";
688  } // end if name widget set
689  } // end if config
690 
691 
692  // PARTICIPATION COUNT
693  if( $this->get_config("displayOtherUsersStatistics") ){
694  $cells = str_repeat("<td></td>",sizeof($this->widget_list));
695  echo "<tr class='spacer_tr'>$cells</tr>";
696  echo "<tr style='text-align:center' class='schedule_count_tr'><td></td>";
697  foreach( $this->widget_list as $child ){
698  if( !$child instanceof scheduleName ){
699  echo "<td>";
700  foreach( array("yes","maybe","no") as $val){
701  $m = "";
702  if( max($count[$child->ID]) == $count[$child->ID][$val] ){
703  $m="schedule_count_max";
704  }
705  echo "<span class='schedule_count_span_$val $m'>{$count[$child->ID][$val]}</span>";
706  }
707  echo "</td>";
708  }
709  }
710  } // end if config
711 
712  // PARTICIPATION SELF
713  $cells = str_repeat("<td></td>",sizeof($this->widget_list));
714  echo "<tr class='spacer_tr'>$cells</tr>";
715  echo "<tr class='participate_tr'>";
716  $name_restriction = $this->get_config("usernameRestriction");
717  if( $name_restriction == "free" ){
718  $name = "";
719  if( isset($_SESSION["user"]) ){ // logged in users
720  $name = $_SESSION["user"]->fullName;
721  }
722  if( $name_wid->value != "" ){
723  $name = $name_wid->value;
724  }
725  echo "<td><input type='text' value='{$name}' size='10' name='{$this->name}_name'/></td>";
726  }else if($name_restriction == "force"){
727  $name = "";
728  if( isset($_SESSION["user"]) ){ // logged in users
729  $name = $_SESSION["user"]->fullName;
730  }
731  echo "<td>{$name}</td>";
732  }else if( $name_restriction == "none" ){
733  echo "<td>Du:</td>";
734  }
735 
736  foreach( $this->widget_list as $child ){
737  if( $child instanceof scheduleDate){
738  echo "<td> <select name='{$child->name}'>";
739  //for( $i=0 ; $i<sizeof($options_map) ; ++$i){
740  foreach( array_keys($options_map) as $key ){
741  //if( $child->value === $options_vals[$i] ){
742  if( $child->value === $options_map[$key] ){
743  echo "<option value='{$key}' selected='selected'>{$options_map[$key]}</option>";
744  }else{
745  echo "<option value='{$key}'>{$options_map[$key]}</option>";
746  }
747  } // end foreach option
748  echo " </select> </td>";
749  } // end if Date
750  } // end foreach child
751  echo "</tr>";
752 
753  echo "</table>";
754  echo "</div>";
755  }
756 
757 
758  public function handle_inpt(){
759  $err = array();
760  //$option_list_val = array("yes","maybe","no");
761  //$option_list = array("Ja","Veilleicht","Nein");
762  $yesValue = $this->get_config("yesValue");
763  $noValue = $this->get_config("noValue");
764  $maybeValue = $this->get_config("maybeValue");
765  $options_map = array( "yes" => $yesValue , "maybe" => $maybeValue , "no" => $noValue );
766 
767 
768  // handle each date
769  foreach( $this->widget_list as $child ){
770  if( $child instanceof scheduleDate ){
771  if( (isset($_POST[$child->name])) AND ($_POST[$child->name] != "") ){
772  foreach( array_keys($options_map) as $key ){
773  if( $_POST[$child->name] === $key ){
774  $child->value = $options_map[$key];
775  }
776  } // end foreach option
777  } // end if isset POST
778 
779  $req = $child->check_required();
780  if( ($child->value == "") AND ($req !== true) ){
781  $err[] = $req;
782  }
783 
784  }else if( $child instanceof scheduleName ){
785  $name_widget = $child;
786  }
787  } // end foreach child
788 
789  // handle the nick name
790  $name_restriction = $this->get_config("usernameRestriction");
791  if( $name_restriction == "free" ){
792  if( (isset($name_widget)) AND ($name_widget instanceof scheduleName) ){
793  if( (isset($_POST["{$this->name}_name"])) ){
794  $r = $name_widget->set_value($_POST["{$this->name}_name"]);
795  if($r !== true){
796  $err[] = $r;
797  }
798  }
799  }else{
800  $err[] = "Interner Fehler. Konnte scheduleName nicht in der Widgetliste finden";
801  }
802  }else if($name_restriction == "force"){
803  $r = $name_widget->set_value( $_SESSION["user"]->fullName );
804  }else if($name_restriction == "none"){
805  $name_widget->set_value("");
806  }
807 
808  if( sizeof($err) == 0){
809  return true;
810  }else{
811  return $err;
812  }
813 
814  }
815 
816 }
817 // ! no ending newLine
818 ?>