Umfragen
poll.class.php
Go to the documentation of this file.
1 <?php
2 /*
3  * poll.class.php
4  *
5  * Copyright 2012 Johannes <jojo@jojo-42>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20  * MA 02110-1301, USA.
21  *
22  *
23  */
24 
25 class poll {
26 
27  public $widget_list;
28  public $ID;
29  public $hashID;
30  public $name;
31  public $timeout;
32  public $active_since;
33  public $groups = array();
34  public $status;
35  public $owner = 0;
36  public $owner_fn = "";
37  public $type = 0;
38  public $anonymous = false;
39  public $is_public = false;
40  public $noDisplay = false;
41  public $theme = "";
42 
43  public $local_monthNames = array( 0 => "Januar", 1 => "Februar", 2 => "März",
44  3 => "April", 4 => "Mai", 5 => "Juni",
45  6 => "Juli", 7 => "August", 8 => "September",
46  9 => "Oktober", 10 => "November", 11 => "Dezember" );
47 
48  private $config = array();
49 
50  /*---------------------------------
51  *
52  * SETTERS
53  *
54  --------------------------------*/
61  function set_status($db,$status){
62  $r = $db->update_poll_field($this->ID,"status",$status);
63  if ($r == true){
64  $this->status = $status;
65  return true;
66  }
67  return false;
68  }
69 
80  function set_anonymous($db,$au,$val){
81  $err= "";
82  $ok = $db->is_results_empty($this->ID);
83  // set not anonymous
84  if( ($val == true) AND (($this->anonymous === false) OR ($this->is_public === true)) ){
85  if( $ok === false ){
86  $err = "Die Umfrage konnte nicht anonymisiert werden, da bereits Daten vorhanden sind. Bitte diese auswerten und löschen.";
87  }else{
88  $this->anonymous = true;
89  $db->delete_all_result($this->ID);
90  $db->update_poll_field($this->ID,"anonymous","1");
91  }
92  // set anonymous
93  }else if( ($val == false) AND ($this->anonymous === true) ){
94  if( $ok === false ){
95  $err = "Die Anonymisierung der Umfrage konnte nicht zurück gezogen werden, da bereits Daten vorhanden sind. Bitte diese auswerten und löschen.";
96  }else{
97  $this->anonymous = false;
98  $db->update_poll_field($this->ID,"anonymous","0");
99  if( in_array($_SESSION["user"]->group,explode(",",TEACHER_GROUP)) ){
100  //$au = new LDAPauth(LDAP_HOST , LDAP_PORT , LDAP_ROOTDN);
101  $au = make_auth_object();
102  $db->klassenliste($au,$this);
103  } // end if teacher
104  } // end if ok
105  }
106  return $err;
107  }
108 
119  public function set_is_public($db,$au,$val){
120  $err = "";
121  $ok = $db->is_results_empty($this->ID);
122  if( ($val === true) AND ($this->is_public === false) ){
123  // need to be anonymous
124  if( $this->anonymous === true ){
125  if( $ok === false ){
126  $err = "Die Umfrage konnte nicht für externe Benutzer freigegeben werden, da dies eine anonyme Umfrage vorausetzt. Möglicherweise sind noch Daten in den Ergebnissen vorhanden.";
127  }else{
128  $this->is_public = true;
129  $db->update_poll_field($this->ID,"anonymous","2");
130  }
131  }else{
132  $err = "Um die Umfrage für externe Nutzer freizugeben, muss die Umfrage anonym erfolgen. Bitte dies einstellen.";
133  }
134  // unpublish
135  }else if( ($val === false) AND ($this->is_public === true) AND ($this->anonymous === true) ){
136  $this->is_public = false;
137  $db->update_poll_field($this->ID,"anonymous","1");
138  }
139  return $err;
140  }
141 
149  public function set_name($name){
150  $name = htmlspecialchars($name , ENT_QUOTES , "UTF-8",true);
151  if( strlen($name) <= 256){
152  $this->name = $name;
153  return true;
154  }
155  return false;
156  }
157 
162  public function make_id_hash(){
163  $random = substr(md5(mt_rand()),0,7);
164  $str="{$this->ID}-{$this->owner}-{$this->name}-{$random}";
165  if( $str != "" ){
166  return md5($str);
167  }else{
168  return "";
169  }
170  }
171 
176  public function delete($db){
177  $this->set_status($db,3);
178  }
179 
185  public function set_config($name , $value){
186  if( $name == "email_notif" ){
187  if( is_array($value) ){
188  $this->config[$name] = $value;
189  }
190  }
191  }
192 
198  public function get_config($name){
199  if( $name == "email_notif" ){
200  if( isset($this->config[$name]) ){
201  return $this->config[$name];
202  }else{
203  return array();
204  }
205  }
206 
207  }
208 
213  public function serialize_config(){
214  return serialize($this->config);
215  }
216 
217 
218 
219  /*---------------------------------
220  *
221  * GETTERS
222  *
223  --------------------------------*/
229  public function get_widget_by_id($ID){
230  if (isset($this->widget_list)){
231  foreach($this->widget_list as &$w){
232  if ($w->ID == $ID){
233  return $w;
234  }
235  if( $w instanceof container ){
236  foreach( $w->widget_list as $question ){
237  if ($question->ID == $ID){
238  return $question;
239  }
240  } // end foreach matrix question
241  } // end if matrix
242  } // end foreach widget
243  } // end if there is a widget list
244  }
245 
251  public function get_widget_by_name($name){
252  foreach( $this->widget_list as $widget ){
253  if ($widget->name == $name){
254  return $widget;
255  }
256  if( $widget instanceof container ){
257  foreach( $widget->widget_list as $child ){
258  if ($child->name == $name){
259  return $child;
260  }
261  } //end foreach
262  } // end container widgets
263  } // end foreach widget
264  }
265 
273  public function is_group_in_groups($group){
274  foreach($this->groups as $gr){
275  if( ($group == $gr) OR ($gr == "*") ){
276  return true;
277  }
278  }
279  return false;
280  }
281 
286  public function get_active_since_timestammp(){
287  $timeout = strptime($this->active_since,"%Y-%m-%d %H:%M:%S");
288  if($timeout !== false){
289  $y = 1900+$timeout["tm_year"]; // years since 1900
290  $timeout["tm_mon"] = 1+$timeout["tm_mon"]; // 0=>januar 1=>feb ...
291  $ts = mktime($timeout["tm_hour"],$timeout["tm_min"],$timeout["tm_sec"],$timeout["tm_mon"],$timeout["tm_mday"],$y);
292  return $ts;
293  }else{
294  return 0;
295  }
296  }
297 
302  public function get_timeout_timestamp(){
303  $timeout = strptime($this->timeout,"%Y-%m-%d %H:%M:%S");
304  if($timeout !== false){
305  $y = 1900+$timeout["tm_year"]; // years since 1900
306  $timeout["tm_mon"] = 1+$timeout["tm_mon"]; // 0=>januar 1=>feb ...
307  $ts = mktime($timeout["tm_hour"],$timeout["tm_min"],$timeout["tm_sec"],$timeout["tm_mon"],$timeout["tm_mday"],$y);
308  return $ts;
309  }else{
310  return 0;
311  }
312  }
313 
318  public function get_timeout_string(){
319  $timeout = strptime($this->timeout,"%Y-%m-%d %H:%M:%S");
320  if($timeout !== false){
321  $y = 1900+$timeout["tm_year"];
322  $m = $this->local_monthNames[$timeout["tm_mon"]];
323  $time = "";
324  if( ($timeout["tm_min"] == 0) AND ($timeout["tm_hour"] == 0) ){
325  $time = "";
326  }else{
327  if($timeout["tm_min"] == 0){
328  $time = " ".$timeout["tm_hour"]."Uhr";
329  }else{
330  $time = " ".$timeout["tm_hour"].":".$timeout["tm_min"];
331  }
332  }
333  return "{$timeout["tm_mday"]}. {$m} $y {$time}";
334  }else{
335  return "";
336  }
337  }
338 
344  public function get_widget_default_font_config($conf){
345  if( ($conf == "font-family") OR ($conf == "font-size") OR ($conf == "font-bold") ){
346  $conf_name = $conf;
347  }else{
348  return ;
349  }
350 
351  $count = array();
352  foreach( $this->widget_list as $widget ){
353  $f = $widget->get_config($conf_name);
354  if(!isset($count[ $f ])){$count[ $f ]=0;}
355  ++$count[ $f ];
356  }
357  $winner = "";
358  if( sizeof($count) != 0 ){
359  asort($count,SORT_NUMERIC);
360  $winner = array_slice( $count , -1,1,true); // arr, offset,len,preserve_num_key
361  $winner = array_keys($winner);
362  $winner = $winner[0];
363  }
364  return $winner;
365  }
366 
367 
368 
376  public function check_setup_complete($r=false){
377  $complete = true;
378  $reason = array();
379  if( !((isset($this->name)) AND ($this->name != "")) ){
380  $complete = false;
381  $reason[] = "name";
382  }
383  if( $this->is_public === false ){
384  if( !isset($this->groups) ){
385  $complete = false;
386  $reason[] = "groups";
387  }else{
388  if( (sizeof($this->groups) == 0) OR ((sizeof($this->groups) > 0) AND ($this->groups[0] == "") ) ){
389  $complete = false;
390  $reason[] = "groups";
391  }
392  }
393 
394  }
395 
396  if( !( (isset($this->timeout)) AND ($this->timeout != "") ) ){
397  $complete = false;
398  $reason[] = "timeout";
399  }
400  if( !( (isset($this->widget_list)) AND (sizeof($this->widget_list) > 0) ) ){
401  $complete = false;
402  $reason[] = "widget_list";
403  }
404  if($r){
405  return $reason;
406  }
407  return $complete;
408  }
409 
410  /*---------------------------------
411  *
412  * LOAD
413  *
414  --------------------------------*/
419  public function load($db){
420  $this->widget_list = $db->load_poll($this->ID);
421  }
422 
429  public function load_from_id($db,$pollID){
430  $poll_infos = $db->get_poll_infoArray( $pollID ) ;
431  if( ($poll_infos !== false) AND(sizeof($poll_infos) > 0) ){
432  $this->ID = intval($pollID);
433  $this->hashID = $poll_infos["hashID"];
434  $this->groups = explode(",",$poll_infos["groups"]);
435  $this->timeout = $poll_infos["timeout"];
436  $this->active_since = $poll_infos["active_since"];
437  $this->name = $poll_infos["name"];
438  $this->owner = intval($poll_infos["owner"]);
439  $this->owner_fn = $poll_infos["owner_fn"];
440  $this->status = intval($poll_infos["status"]);
441  $this->type = intval($poll_infos["type"]);
442  $this->anonymous = (bool) $poll_infos["anonymous"] ;
443  $this->theme = $poll_infos["theme"] ;
444  if( (int) $poll_infos["anonymous"] > 1 ){
445  $this->is_public = true;
446  }
447  $this->noDisplay = (bool) $poll_infos["noDisplay"];
448  $this->load($db);
449 
450  if( isset($poll_infos["config"]) AND ($poll_infos["config"] != "") ){
451  $this->config = unserialize($poll_infos["config"]);
452  }
453  if( !is_array($this->config) ){
454  $this->config = array();
455  }
456 
457  return true;
458  }else{
459  return false;
460  }
461  }
462 
469  public function load_values_from_id($db,$username){
470  $res = $db->get_poll_result_for_user($this->ID,$username);
471  if( $res !== false ){
472  $keys = array_keys($res);
473  foreach($this->widget_list as &$widget){
474  if( (in_array($widget->name, $keys)) AND ($widget instanceof input_widget) ){
475  $widget->value = $res[$widget->name];
476  }
477  if( $widget instanceof container ){
478  foreach( $widget->widget_list as $child ){
479  if( (in_array($child->name, $keys)) ){
480  $child->value = $res[$child->name];
481  }
482  }
483  }
484  }
485  return true;
486  }
487  return false;
488  }
489 
494  public function load_widget_result_count($db){
495  foreach($this->widget_list as $w){
496  if( $w instanceof schedule ){
497  $w->set_data("users", $db->get_schedule_widget_data($w) );
498  }
499  if( $w instanceof countable_widget ){
500  $w->count($db);
501  }
502  }
503 
504  }
505 
506 
507 
508  /*---------------------------------
509  *
510  * WIDGETS
511  *
512  --------------------------------*/
518  public function insert_widget($index=-1,$w){
519  // insert into list at any position
520  if ( ($index >= 0) AND ($index < sizeof($this->widget_list)) ){
521  // use temp array
522  $temp = array();
523  for( $i=0 ; $i<sizeof($this->widget_list) ; ++$i){
524  // just copy the other widgets
525  $temp[] = $this->widget_list[$i];
526  // once incerted the index is shifted by one
527  if($i > $index){
528  $temp[sizeof($temp)-1]->index = $temp[sizeof($temp)-1]->index+1;
529  }
530 
531  // insert widget if reached the index
532  if($i == $index){
533  $w->index = $i+1;
534  $w->pollID = $this->ID;
535  $temp[] = $w;
536  }
537 
538  }
539  // write back data
540  $this->widget_list = $temp;
541 
542  // insert at the end of list
543  }else if ($index == -1){
544  $this->widget_list[] = $w;
545  $i = sizeof($this->widget_list)-1 ;
546  $this->widget_list[ $i ]->index = $i;
547  $this->widget_list[ $i ]->pollID = $this->ID;
548  }
549  }
550 
556  public function delete_widget($db,$id){
557  $temp = array();
558  $del_w_passed = false;
559  $wid = $this->get_widget_by_id($id);
560 
561  for( $i=0 ; $i<sizeof($this->widget_list) ; ++$i){
562  if( $this->widget_list[$i]->ID != $id ){
563  // index verschiebt sich
564  if($del_w_passed == true){
565  $this->widget_list[$i]->index = $this->widget_list[$i]->index-1;
566  }
567  $temp[] = $this->widget_list[$i];
568  }else{
569  // das zu löschende widget
570  $del_w_passed = true;
571  }
572  }
573  $this->widget_list = $temp;
574 
575  // delete options and childs from containers
576  if( !($wid instanceof container) ){
577  $db->delete_widget($this->ID,$id);
578  }else{
579  $childs = $wid->get_all_childs();
580  foreach( $childs as $child ){
581  $db->delete_widget($this->ID,$child->ID);
582  }
583  $db->delete_widget($this->ID,$id);
584  }
585  $db->mass_update_widget($this->widget_list);
586  }
587 
588 
596  function move_widget($db,$index1,$index2){
597  if( (isset($this->widget_list[$index1])) AND (isset($this->widget_list[$index2])) ){
598 
599  $temp = array();
600  // MOVE UP
601  if( $index1 > $index2 ){
602  for( $i=0 ; $i<sizeof($this->widget_list) ; ++$i){
603  // insert "new" oject BEFORE the index given
604  if( $i == $index2 ){
605  $this->widget_list[$index1]->index = $i;
606  $temp[] = $this->widget_list[$index1];
607  }
608  // shift index by one after insertion and before deletion (after del -1+1 = 0 )
609  // /!\ shift index2 too because we insert after it
610  if( ($i >= $index2) AND ($i < $index1) ){
611  ++$this->widget_list[$i]->index;
612  }
613  // copy widgets exept the one which is moved
614  if( $i != $index1){
615  $temp[] = $this->widget_list[$i];
616  }
617  }
618 
619  // MOVE DOWN
620  }else if($index1 < $index2){
621  for( $i=0 ; $i<sizeof($this->widget_list) ; ++$i){
622  // shift index by one after deletion and before insertion (after ins -1+1 = 0 )
623  // /!\ shift index2 too because we insert after it
624  if( ($i <= $index2) AND ($i > $index1) ){
625  --$this->widget_list[$i]->index;
626  }
627  // copy widgets exept the one which is moved
628  if( $i != $index1){
629  $temp[] = $this->widget_list[$i];
630  }
631  // insert "new" oject AFTER the index given
632  if( $i == $index2 ){
633  $this->widget_list[$index1]->index = $i;
634  $temp[] = $this->widget_list[$index1];
635  }
636 
637  }
638  }
639  if( sizeof($temp) > 0){
640  $this->widget_list = $temp;
641  $db->mass_update_widget($this->widget_list);
642  return true;
643  }
644  }
645  return false;
646 
647  }
648 
649 
650 
651  /*---------------------------------
652  *
653  * SAVE
654  *
655  --------------------------------*/
661  public function save_name($db){
662  return $db->update_poll_field($this->ID , "name" , $this->name);
663  }
664 
670  public function save_groups($db){
671  if( (sizeof($this->groups) > 0) OR ($this->groups === "*") ){;
672  $data = "";
673 
674  if($this->groups === "*"){ // all wildcard overrides all selection
675  $data = "*";
676  }else{
677  foreach($this->groups as $group){
678  $data = $data.",$group";
679  }
680  $data = trim($data,",");
681  }
682 
683  return $db->update_poll_field($this->ID , "groups" , $data);
684  }
685  return false;
686  }
687 
693  public function save_timeout($db){
694  return $db->update_poll_field($this->ID , "timeout" , $this->timeout);
695  }
696 
702  public function save_noDisplay($db){
703  return $db->update_poll_field($this->ID , "noDisplay" , $this->noDisplay);
704  }
705 
711  public function save_theme($db){
712  return $db->update_poll_field($this->ID , "theme" , $this->theme);
713  }
714 
720  public function save_config($db){
721  $val = serialize($this->config);
722  return $db->update_poll_field($this->ID , "config" , $val);
723  }
724 
725  /*---------------------------------
726  *
727  * EDIT USER INTERFACE
728  *
729  --------------------------------*/
730 
734  public function display(){
735  foreach($this->widget_list as &$wid){
736  if( $wid instanceof output_widget ){
737  $wid->display();
738  }
739  }
740  }
741 
746  public function handle_inpt(){
747  $errors = array();
748  foreach($this->widget_list as $w){
749  if( $w instanceof input_widget ){
750  $e = $w->handle_inpt();
751  if ($e !== true){
752  if( is_array($e) ){
753  $errors = array_merge($errors,$e);
754  }else{
755  $errors[] = $e;
756  }
757  }
758  }// end if inpt wid
759  }// end foreach widget
760  return $errors;
761  }
762 
767  public function display_name_edit(){
768  echo "<input type='text' name='poll_name' id='poll_name' value='{$this->name}' placeholder='Umfragetitel' size='30'/>";
769  }
770 
776  public function handle_name_edit(){
777  $err_reason = "";
778  if( isset($_POST["poll_name"]) AND ($_POST["poll_name"] != "")){
779  if( !$this->set_name($_POST["poll_name"])){
780  $err_reason = "Name zu lang";
781  }
782  }else{
783  $err_reason = "Bitte in den Umfrageeigenschaften den Namen der Umfrage angeben.";
784  }
785  // return
786  if($err_reason == ""){
787  return true;
788  }else{
789  return $err_reason;
790  }
791  }
792 
793 
800  public function display_groups_edit($auth,$whitelist=array()){
801  $groups = $auth->get_all_groups($whitelist);
802  if( sizeof($groups) > 0){
803  $deactivated = "";
804  if( $this->is_public === true ){
805  $deactivated = "disabled='disabled'";
806  }
807  echo "<select multiple='multiple' size='5' name='poll_group_select[]' $deactivated>";
808  // all groups have access
809  if( in_array("*",$this->groups) ){
810  echo "<option value='*' selected='selected'>Alle</option>";
811  }else{
812  echo "<option value='*'>Alle</option>";
813  }
814  // list groups
815  foreach($groups as $g){
816  if( in_array($g[1],$this->groups) ){
817  echo "<option value='{$g[1]}' selected='selected'>{$g[0]}</option>";
818  }else{
819  echo "<option value='{$g[1]}'>{$g[0]}</option>";
820  }
821  }
822  echo"</select>";
823  }else{
824  echo "<p>Keine Gruppen verfügbar.</p>";
825  }
826  }
827 
834  public function handle_groups_edit($auth,$whitelist=array()){
835  $err_reason = "";
836  $groups_all = $auth->get_all_groups($whitelist);
837  $groups_selected = array(); // filtered group ID list
838  $groups_all_wildcard = false;
839  if( sizeof($groups_all) > 0){
840  // get list of IDs of all groups
841  $groups_IDs = array();
842  foreach($groups_all as $gr){
843  $groups_IDs[] = intval($gr[1]); // 0=>group_name , 1=>gid
844  }
845  // filter input
846  if( $this->is_public === false ){
847  if( (isset($_POST["poll_group_select"])) AND (sizeof($_POST["poll_group_select"])>0) ){
848  foreach( $_POST["poll_group_select"] as $gid_in){
849  // check if selected group exists
850  if( in_array( intval($gid_in), $groups_IDs) ){
851  $groups_selected[] = intval($gid_in);
852  // wildcard seleced ?
853  }else if($gid_in == "*"){
854  $groups_all_wildcard = true;
855  }
856  }
857  }else{
858  $err_reason = "Bitte in den Umfrageeigenschaften die Klassenbeschränkung der Umfrage angeben.";
859  }
860  }else{
861  $groups_all_wildcard = true;
862  } // end if public
863  }else{
864  $err_reason = "Fehler bei der Verarbeitung. Keine Gruppen gefunden.";
865  }
866 
867  // set group list
868  if ( ( sizeof($groups_selected) != 0) OR ($groups_all_wildcard == true) ){
869  if ($groups_all_wildcard == true){
870  $this->groups = array("*");
871  }else{
872  $this->groups = $groups_selected;
873  }
874  }else{
875  $err_reason = "Bitte in den Umfrageeigenschaften die Klassenbeschränkung der Umfrage angeben.";
876  }
877 
878  // return
879  if($err_reason == ""){
880  return true;
881  }else{
882  return $err_reason;
883  }
884  }
885 
891  private function display_timeout_option($i,$seleced){
892  if ( $i == $seleced ){
893  echo "<option value='$i' selected='selected'>$i</option>";
894  }else{
895  echo "<option value='$i'>$i</option>";
896  }
897 
898  }
899 
904  public function display_timeout_edit(){
905  $timeout_str = $this->timeout;
906  $timeout = strptime($this->timeout,"%Y-%m-%d %H:%M:%S"); // can be false!
907  if( $timeout === false ){
908  $timeout = array();
909  }
910 
911  if(isset($timeout["tm_year"])){
912  $y = 1900+$timeout["tm_year"]; // years since 1900
913  }else{ $y = 0;}
914 
915  if(isset($timeout["tm_mon"])){
916  $timeout["tm_mon"] = 1+$timeout["tm_mon"]; // 0=>januar 1=>feb ...
917  }else{ $timeout["tm_mon"] = 1;}
918 
919  if(!isset($timeout["tm_mday"])){
920  $timeout["tm_mday"] = 1;
921  }
922  if(!isset($timeout["tm_hour"])){
923  $timeout["tm_hour"] = 0;
924  }
925  if(!isset($timeout["tm_min"])){
926  $timeout["tm_min"] = 0;
927  }
928 
929  if($this->timeout != "0000-00-00 00:00:00"){
930  $val = $timeout["tm_mday"]."-".$timeout["tm_mon"]."-".$y;
931  }else{
932  $val ="";
933  }
934 
935  echo "<script type='text/javascript'>";
936  echo "document.write(\"<input type='text' id='poll_timeout_datepicker' name='poll_timeout_datepicker' placeholder='TT-MM-JJJJ' value='$val'/>\");";
937  echo "$( \"#poll_timeout_datepicker\" ).datepicker({dateFormat: \"dd-mm-yy\" });";
938  echo "</script>";
939 
940  echo "<noscript>";
941  echo "<label for='poll_timeout_day'>Tag:</label>";
942  echo "<select name='poll_timeout_day' id='poll_timeout_day'>";
943  for($i=1 ; $i<=31 ; ++$i){
944  $this->display_timeout_option($i,$timeout["tm_mday"]);
945  }
946  echo "</select>";
947 
948  echo "<label for='poll_timeout_month'>Monat:</label>";
949  echo "<select name='poll_timeout_month' id='poll_timeout_month'>";
950  for($i=1 ; $i<=12 ; ++$i){
951  $this->display_timeout_option($i,$timeout["tm_mon"]);
952  }
953  echo "</select>";
954 
955  echo "<label for='poll_timeout_year'>Jahr:</label>";
956  echo "<input type='text' value='$y' name='poll_timeout_year' id='poll_timeout_year' size='4'/>";
957 
958  echo "</noscript>";
959  echo "<br/>";
960 
961  echo "<div style='margin:0px;padding:0px;margin-top:.3em;'>";
962  echo "<label for='poll_timeout_hour'>Stunde:</label>";
963  echo "<select name='poll_timeout_hour' id='poll_timeout_hour'>";
964  for($i=0 ; $i<24 ; ++$i){
965  $this->display_timeout_option($i,$timeout["tm_hour"]);
966  }
967  echo "</select>";
968 
969  echo "<label for='poll_timeout_min'>Minute:</label>";
970  echo "<select name='poll_timeout_min' id='poll_timeout_min'>";
971  for($i=0 ; $i<60 ; ++$i){
972  $this->display_timeout_option($i,$timeout["tm_min"]);
973  }
974  echo "</select>";
975  echo "</div>";
976  }
977 
983  private function format_int_2digit($i){
984  if( $i < 10){
985  return "0$i";
986  }else{
987  return "$i";
988  }
989  }
990 
996  public function handle_timeout_edit(){
997  $err_reason = "";
998  $datetime = "";
999  // VAR FILTER
1000  if( (isset($_POST["poll_timeout_datepicker"])) AND ($_POST["poll_timeout_datepicker"] != "" ) AND
1001  (is_numeric($_POST["poll_timeout_min"])) AND (is_numeric($_POST["poll_timeout_hour"])) ){
1002  //dd-mm-yy
1003  $d = explode("-",$_POST["poll_timeout_datepicker"]);
1004  if( (sizeof($d)==3) ){
1005  $day = intval($d[0]);
1006  $month = intval($d[1]);
1007  $year = intval($d[2]);
1008  $hour = intval($_POST["poll_timeout_hour"]);
1009  $min = intval($_POST["poll_timeout_min"]);
1010  // format ints to 2-char strings
1011  $day_s = $this->format_int_2digit($day);
1012  $month_s = $this->format_int_2digit($month);
1013  $hour_s = $this->format_int_2digit($hour);
1014  $min_s = $this->format_int_2digit($min);
1015  }else{
1016  $err_reason = "Das Datumsformat der automatischen Deaktivierung der Umfrage ist ungültig.";
1017  }
1018  }else if ( (!is_numeric($_POST["poll_timeout_day"])) OR (!is_numeric($_POST["poll_timeout_month"])) OR
1019  (!is_numeric($_POST["poll_timeout_year"])) OR (!is_numeric($_POST["poll_timeout_hour"])) OR
1020  (!is_numeric($_POST["poll_timeout_min"])) ){
1021  $err_reason = "Das Datum der automatischen deaktivierung der Umfrage ist entweder nicht gültig oder nicht eingestellt.";
1022  }else{
1023  $day = intval($_POST["poll_timeout_day"]);
1024  $month = intval($_POST["poll_timeout_month"]);
1025  $year = intval($_POST["poll_timeout_year"]);
1026  $hour = intval($_POST["poll_timeout_hour"]);
1027  $min = intval($_POST["poll_timeout_min"]);
1028  // format ints to 2-char strings
1029  $day_s = $this->format_int_2digit($day);
1030  $month_s = $this->format_int_2digit($month);
1031  $hour_s = $this->format_int_2digit($hour);
1032  $min_s = $this->format_int_2digit($min);
1033 
1034  }
1035  // CHECK DATE
1036  if($err_reason == ""){
1037  if (checkdate($month,$day,$year)){
1038  if( ($hour>=0) AND ($hour<24) AND ($min>=0) AND ($min<60)){
1039  $datetime = "$year-$month_s-$day_s $hour_s:$min_s:00"; //YYYY-MM-DD HH:MM:SS
1040  }else{
1041  $err_reason = "Das Datumsformat der automatischen Deaktivierung ist ungültig!";
1042  }
1043  }else{
1044  $err_reason = "Das Datumsformat der automatischen Deaktivierung ist ungültig!";
1045  }
1046  }
1047  // update value
1048  if( $datetime != "" ){;
1049  $this->timeout = $datetime;
1050  return true;
1051  }
1052  return $err_reason;
1053  }
1054 
1059  public function display_status_edit(){
1061  $stati_names = array( "Aktiv", "Unvollständig" , "Deaktiviert" ,"Vorlage" , "Archiv");
1062  $stati_colors = array( "#BCF6A9" , "#F6E7A9" , "#FF9792" , "#C1DEE2" , "#C6C1E2");
1063  $options_status = "<option value='' style='padding:2px'></option>";
1064  $i=0;
1065  foreach( $stati as $st ){
1066  $sel = "";
1067  if( $this->status == $st ){
1068  $sel = "selected='selected'";
1069  }
1070  $options_status .= "<option value='$st' $sel style='background-color:{$stati_colors[$i]};padding:2px'>{$stati_names[$i]}</option>";
1071  ++$i;
1072  }
1073 
1074  echo "<label for='poll_status'>Status:</label>";
1075  echo "<select size='1' name='poll_status' id='poll_status'>
1076  $options_status
1077  </select>";
1078  if( $this->status == STATUS_SHARED_TEMPLATE ){
1079  echo "Diese Vorlage wird geteilt.";
1080  }
1081  }
1082 
1088  public function handle_status_edit($db){
1089  if( (isset($_POST["poll_status"])) AND ($_POST["poll_status"] != "") ){
1090  if(intval($_POST["poll_status"]) == STATUS_NORMAL){
1092  }else if (intval($_POST["poll_status"]) == STATUS_USER_DEACTIVATED){
1094  }else if (intval($_POST["poll_status"]) == STATUS_TEMPLATE){
1096  }
1097 
1098  if($status == STATUS_NORMAL){
1099  // versuche aktivierung
1100  $r = $this->check_setup_complete();
1101  if($r == true){
1102  $this->set_status($db,$status);
1103  $db->update_poll_field($this->ID , "active_since", date("Y-m-d H:i:s") );
1104  }else{
1105  return "Die Umfrage konnte nicht aktiviert werden, da noch einige Elemente in der Einstellung fehlen.";
1106  }
1107  }else{
1108  // andere stati
1109  $this->set_status($db,$status);
1110  $db->update_poll_field($this->ID , "active_since", "0000-00-00 0:0:0" );
1111  }
1112  return true;
1113  }else{
1114  return "Umfragestatus nicht ausgewählt";
1115  }
1116  }
1117 
1122  public function display_export_edit(){
1123  echo "Spaltentrennung durch: ";
1124  echo "<select name='delimiter' size='1'>";
1125  echo "<option value=';' selected='selected'>Semicolon (;)</option>";
1126  echo "<option value=','>Kommata (,)</option>";
1127  echo "</select>";
1128  echo "<br/>Textbegrenzung durch: &nbsp;";
1129  echo "<select name='enc' size='1'>";
1130  echo "<option value='single'>einfaches Hochkomma (')</option>";
1131  echo "<option value='double' selected='selected'>doppeltes Hochkomma (\")</option>";
1132  echo "</select>";
1133  }
1134 
1142  public function handle_export_edit(db $db,$dl){
1143  $d = ",";
1144  $enc = '"';
1145  if( (isset($_GET["delimiter"])) ){
1146  if($_GET["delimiter"] == ";"){
1147  $d = ";";
1148  }else if($_GET["delimiter"] == ","){
1149  $d = ",";
1150  }
1151  }
1152  if( isset($_GET["enc"]) ){
1153  if( $_GET["enc"] == "single" ){
1154  $enc = "'";
1155  }else if( $_GET["enc"] == "double" ){
1156  $enc = '"';
1157  }
1158  }
1159  if($dl === true){
1160  $db->export_to_csv($this,$d,$enc,$dl);
1161  }else if($dl === false){
1162  $db->export_to_csv($this,$d,$enc,$dl);
1163  }
1164  return true;
1165  }
1166 
1171  public function display_font_family_edit(){
1172  $fonts = array(
1173  "Andale Mono" => "andale mono,times", "Arial" => "arial,helvetica,sans-serif",
1174  "Arial Black" => "arial black,avant garde", "Book Antiqua" => "book antiqua,palatino",
1175  "Comic Sans MS" => "comic sans ms,sans-serif", "Courier New" => "courier new,courier",
1176  "Georgia" => "georgia,palatino", "Helvetica" => "helvetica",
1177  "Impact" => "impact,chicago", "Symbol" => "symbol",
1178  "Tahoma" => "tahoma,arial,helvetica,sans-serif", "Terminal" => "terminal,monaco",
1179  "Times New Roman" => "times new roman,times", "Trebuchet MS" => "trebuchet ms,geneva",
1180  "Verdana" => "verdana,geneva", "Webdings" => "webdings",
1181  "Wingdings" => "wingdings,zapf dingbats"
1182  );
1183 
1184  $font = $this->get_widget_default_font_config("font-family");
1185 
1186  echo "<select name='poll_font_family_select'>";
1187  $names = array_keys($fonts);
1188  $conf = "";
1189  echo "<option value=''>Standard</option>";
1190  foreach( $names as $name ){
1191  if( $fonts[$name] == $font ){
1192  $sel = "selected='selected'";
1193  }else{$sel = "";}
1194  echo "<option value='$name' style='font-family:{$fonts[$name]}' $sel> $name </option>";
1195  }
1196  echo "</select>";
1197  }
1198 
1203  public function handle_font_family_edit(){
1204  $fonts = array(
1205  "Andale Mono" => "andale mono,times", "Arial" => "arial,helvetica,sans-serif",
1206  "Arial Black" => "arial black,avant garde", "Book Antiqua" => "book antiqua,palatino",
1207  "Comic Sans MS" => "comic sans ms,sans-serif", "Courier New" => "courier new,courier",
1208  "Georgia" => "georgia,palatino", "Helvetica" => "helvetica",
1209  "Impact" => "impact,chicago", "Symbol" => "symbol",
1210  "Tahoma" => "tahoma,arial,helvetica,sans-serif", "Terminal" => "terminal,monaco",
1211  "Times New Roman" => "times new roman,times", "Trebuchet MS" => "trebuchet ms,geneva",
1212  "Verdana" => "verdana,geneva", "Webdings" => "webdings",
1213  "Wingdings" => "wingdings,zapf dingbats"
1214  );
1215  $value = "";
1216  if ( (isset($_POST["poll_font_family_select"])) AND ($_POST["poll_font_family_select"] != "") ){
1217  if( isset( $fonts[ $_POST["poll_font_family_select"] ] ) ){
1218  $value= $fonts[ $_POST["poll_font_family_select"] ];
1219  }
1220  }
1221  foreach($this->widget_list as $widget){
1222  $widget->set_config("font-family",$value);
1223  }
1224  }
1225 
1230  public function display_font_size_edit(){
1231  $sizes = array(
1232  "1 (8pt)" => "xx-small", "2 (10pt)" => "x-small", "3 (12pt)" => "small",
1233  "4 (14pt)" => "medium", "5 (18pt)" => "large" , "6 (24pt)" => "x-large"
1234  );
1235  $size = $this->get_widget_default_font_config("font-size");
1236 
1237  $names = array_keys($sizes);
1238  $conf = "";
1239  echo "<select name='poll_font_size_select' style='height:2em'>";
1240 
1241  echo "<option value=''>Standard</option>";
1242  foreach( $names as $name ){
1243  if( $sizes[$name] == $size ){
1244  $sel = "selected='selected'";
1245  }else{$sel = "";}
1246  echo "<option value='{$sizes[$name]}' style='font-size:{$sizes[$name]}' $sel> $name </option>";
1247  }
1248  echo "</select>";
1249  }
1250 
1255  public function handle_font_size_edit(){
1256  $sizes = array(
1257  "xx-small" => "xx-small", "x-small" => "x-small", "small" => "small",
1258  "medium" => "medium", "large" => "large" , "x-large" => "x-large"
1259  );
1260  $value = "";
1261  if ( (isset($_POST["poll_font_size_select"])) AND ($_POST["poll_font_size_select"] != "") ){
1262  if( isset( $sizes[ $_POST["poll_font_size_select"] ] ) ){
1263  $value= $sizes[ $_POST["poll_font_size_select"] ];
1264  }
1265  }
1266  foreach($this->widget_list as $widget){
1267  $widget->set_config("font-size",$value);
1268  }
1269  }
1270 
1275  public function display_questions_bold_edit(){
1276  $bold = $this->get_widget_default_font_config("font-bold");
1277  if( $bold == true ){
1278  $sel = "checked='checked'";
1279  }else{$sel="";}
1280 
1281  echo "<input type='checkbox' name='poll_font_bold_checkbox' value='bold' $sel/> Fragen fett darstellen";
1282  }
1283 
1288  public function handle_questions_bold_edit(){
1289  $value=false;
1290  if( (isset($_POST["poll_font_bold_checkbox"])) AND ($_POST["poll_font_bold_checkbox"] == "bold") ){
1291  $value = true;
1292  }
1293  foreach($this->widget_list as $widget){
1294  $widget->set_config("font-bold",$value);
1295  }
1296  }
1297 
1302  public function display_noDisplay_edit(){
1303  if( $this->noDisplay == true ){
1304  $sel = "checked='checked'";
1305  }else{$sel="";}
1306 
1307  echo "<input type='checkbox' name='poll_noDisplay_checkbox' value='noDisplay' $sel/> <u>nicht</u> auf der Hauptseite anzeigen.";
1308  }
1309 
1314  public function handle_noDisplay_edit(){
1315  $value=false;
1316  if( (isset($_POST["poll_noDisplay_checkbox"])) AND ($_POST["poll_noDisplay_checkbox"] == "noDisplay") ){
1317  $value = true;
1318  }
1319  $this->noDisplay = $value;
1320  }
1321 
1326  public function display_anonymous2_edit(){
1327  $names = array("Nicht anonym","Anonym","Anonym und öffentlich");
1328  $vals = array("1","2","3");
1329  $s = "1";
1330  if( $this->anonymous == true ){
1331  $s = "2";
1332  if( $this->is_public == true ){
1333  $s = "3";
1334  }
1335  }
1336  echo "<select name='poll_anonymous_public'>";
1337  for($i=0 ; $i<sizeof($names) ; ++$i){
1338  $sel = "";
1339  if( $s == $vals[$i] ){
1340  $sel = "selected='selected'";
1341  }
1342  echo "<option value='{$vals[$i]}' {$sel}>{$names[$i]}</option>";
1343  }
1344  echo "</select>";
1345  }
1346 
1354  public function handle_anonymous2_edit($db,$au){
1355  $err = ""; $err2="";
1356  if( isset($_POST["poll_anonymous_public"]) ){
1357  // not anonymous
1358  if( $_POST["poll_anonymous_public"] == "1" ){
1359  $err = $this->set_anonymous($db,$au,false);
1360  // anonymous
1361  }elseif( $_POST["poll_anonymous_public"] == "2" ){
1362  $err = $this->set_anonymous($db,$au,true);
1363  // anonymous & public
1364  }elseif( $_POST["poll_anonymous_public"] == "3" ){
1365  if( $this->anonymous == false ){
1366  $err2 = $this->set_anonymous($db,$au,true);
1367  }
1368  $err = $this->set_is_public($db,$au,true);
1369  }
1370  }
1371  if( ($err != "") OR ($err2 != "") ){
1372  return array($err, $err2);
1373  }
1374  return true;
1375  }
1376 
1381  public function handle_anonymous_edit(){
1382  if ( (isset($_POST["poll_anonymous"])) ){
1383  $this->anonymous = true;
1384  }else{
1385  $this->anonymous = false;
1386  }
1387  if( (isset($_POST["poll_public"]) ) ){
1388  $this->is_public = true;
1389  }else{
1390  $this->is_public = false;
1391  }
1392  return true;
1393  }
1394 
1399  public function display_theme_edit(){
1400  $dir = opendir(DOCUMENT_ROOT."/CSS/Themes");
1401  $themeList = array();
1402  $themeListDisp = array();
1403  while( ($ent = readdir($dir)) !== false ){
1404  // no "." and "..", no folder and only css files
1405  if( (is_dir($ent) === false) AND ( substr($ent,-4,4) == ".css" ) ){
1406  $themeListDisp[] = substr($ent,0,-4);
1407  $themeList[] = $ent;
1408  }
1409  }
1410  closedir($dir);
1411  unset($dir);
1412 
1413  echo "<select name='poll_theme'> ";
1414  echo "<option value=''>Standard</option>";
1415  for( $i=0 ; $i<sizeof($themeList) ; ++$i ){
1416  $theme = $themeList[$i];
1417  $themeDisp = $themeListDisp[$i];
1418 
1419  if( $theme == $this->theme){
1420  echo "<option value='$theme' selected='selected'>$themeDisp</option>";
1421  }else{
1422  echo "<option value='$theme'>$themeDisp</option>";
1423  }
1424 
1425  }
1426  echo "</select>";
1427 
1428  }
1429 
1434  public function handle_theme_edit(){
1435  if( (isset($_POST["poll_theme"])) AND ($_POST["poll_theme"] != "") ){
1436  $dir = opendir(DOCUMENT_ROOT."/CSS/Themes");
1437  $themeList = array();
1438  while( ($ent = readdir($dir)) !== false ){
1439  $themeList[] = $ent;
1440  }
1441  closedir($dir);
1442  unset($dir);
1443 
1444  $themeList = array_diff($themeList , array(".","..") );
1445 
1446  if( in_array($_POST["poll_theme"],$themeList) ){
1447  $this->theme = $_POST["poll_theme"];
1448  }else{
1449  $this->theme = "";
1450  }
1451  }else{
1452  $this->theme = "";
1453  }
1454  return true;
1455  }
1456 
1461  public function display_notification_edit(){
1462  $cnf = $this->get_config("email_notif");
1463  echo "Mich per E-mail benachichtigen wenn:<br/>";
1464  $checked = "";
1465  if( in_array("insert",$cnf) ){
1466  $checked = "checked='checked'";
1467  }
1468  echo "<input type='checkbox' name='poll_notification_insert' id='poll_notification_insert' value='true' $checked/> <label for='poll_notification_insert'>Neuer Datensatz</label><br/>";
1469  $checked = "";
1470  if( in_array("update",$cnf) ){
1471  $checked = "checked='checked'";
1472  }
1473  echo "<input type='checkbox' name='poll_notification_update' id='poll_notification_update' value='true' $checked/> <label for='poll_notification_update'>Datensatz aktualisiert</label><br/>";
1474  }
1475 
1480  public function handle_notification_edit(){
1481  $new = array();
1482  if( (isset($_POST["poll_notification_insert"])) AND ($_POST["poll_notification_insert"] == "true") ){
1483  $new[] = "insert";
1484  }
1485  if( (isset($_POST["poll_notification_update"])) AND ($_POST["poll_notification_update"] == "true") ){
1486  $new[] = "update";
1487  }
1488  $cnf = $this->get_config("email_notif");
1489  $cnf = array_merge($cnf,$new);
1490  $this->set_config("email_notif",$cnf);
1491  return true;
1492  }
1493 
1494 
1495 
1496 }
1497 // ! no ending newLine
1498 ?>