25 require_once(
"Exceptions.class.php");
26 require_once(
"widget.class.php");
28 if( !isset($config_included) ){
29 die(
"config not loaded");
47 $this->dbh =
new PDO(
"mysql:dbname=".$dbname.
";host=".$dbhost, $dbuser, $dbpass,
48 array(PDO::MYSQL_ATTR_INIT_COMMAND =>
"SET NAMES 'utf8'"));
49 }
catch (PDOException $e) {
50 die(
'Connection failed: ' . $e->getMessage());
67 $sqh = $this->dbh->query($sql);
69 return $sqh->fetchAll(PDO::FETCH_ASSOC);
82 $sqh = $this->dbh->prepare(
"SELECT ID,name from `umfragen` WHERE `ID` = :id AND `status` != ".
STATUS_DELETED);
83 foreach(
$polls as $pollID){
84 $sqh->execute(array(
":id" => $pollID));
85 $res =
$sqh->fetchAll(PDO::FETCH_ASSOC);
86 if(
sizeof($res) == 1){
87 $name_list[ $res[0][
"ID"] ] = $res[0][
"name"];
98 $sqh = $this->dbh->query(
"SELECT * from `umfragen` WHERE `umfragen`.`status` != ".
STATUS_DELETED);
100 return $sqh->fetchAll(PDO::FETCH_ASSOC);
108 $sqh = $this->dbh->query(
"SELECT * from `umfragen` WHERE `umfragen`.`status` = $stat");
109 return $sqh->fetchAll(PDO::FETCH_ASSOC);
118 $sqh = $this->dbh->query(
"SELECT * from `umfragen` WHERE `ID` = $pollID AND `status` != ".
STATUS_DELETED);
119 return $sqh->fetch(PDO::FETCH_ASSOC);
129 $sqh = $this->dbh->query(
"SELECT * from `{$pollID}_results` WHERE `user` = '$username'");
131 return $sqh->fetch(PDO::FETCH_ASSOC);
142 $sqh = $this->dbh->query(
"SELECT name,ID from `{$pollID}`");
144 $res =
$sqh->fetchAll(PDO::FETCH_ASSOC);
155 $sqh = $this->dbh->query(
"SELECT * FROM `config`");
156 if(
$sqh !==
false ){
157 $res =
$sqh->fetchALL(PDO::FETCH_ASSOC);
169 $sqh = $this->dbh->query(
"SELECT COUNT(*) FROM `{$pollID}_results`");
171 $r=
$sqh->fetch(PDO::FETCH_ASSOC);
172 return $r[
"COUNT(*)"];
320 foreach(
$widget->widget_list as $child ){
321 $data[$child->ID] = array();
322 $names_str .=
",`".$child->name.
"`";
327 $names_str = trim($names_str,
",");
329 $sqh = $this->dbh->query(
"SELECT $names_str from `{$widget->pollID}_results`");
331 if( (
$sqh !==
false) AND (isset($name_wid)) ){
332 $res =
$sqh->fetchAll(PDO::FETCH_ASSOC);
333 if( is_array($res) ){
334 foreach( $res as $row ){
335 if( (is_array($row)) AND (isset($row[$name_wid->ID])) AND ($row[$name_wid->ID] !=
"") ){
336 foreach(
$widget->widget_list as $child ){
337 if( isset($row[ $child->name ]) ){
338 $data[ $child->ID ][] = $row[ $child->name ];
358 $sqh = $this->dbh->query(
"SELECT * from `{$poll->ID}_results`");
362 header(
'Content-Type: text/csv' );
363 header(
'Content-Disposition: attachment;filename=export.csv');
365 $fp = fopen(
'php://output',
'w');
369 while($row =
$sqh->fetch(PDO::FETCH_ASSOC) ) {
374 $names = array_keys($row);
376 foreach($names as $name){
377 if( is_numeric($name) ){
380 $header[] = $w->dispName;
386 fputcsv($fp, $header,$delimiter,$enclosure);
388 $header = array_keys($row);
389 fputcsv($fp, $header,$delimiter,$enclosure);
393 fputcsv($fp, $row,$delimiter,$enclosure);
410 if( ! in_array($order,array(
"asc",
"desc")) ){
417 $sqh = $this->dbh->query(
"SHOW COLUMNS FROM `{$pollID}_results`");
418 if(
$sqh !==
false ){
419 $r =
$sqh->fetchAll(PDO::FETCH_ASSOC);
421 if( $row[
"Field"] == $sort){
432 $sqh = $this->dbh->query(
"SELECT * from `{$pollID}_results`");
434 $sqh = $this->dbh->query(
"SELECT * from `{$pollID}_results` ORDER BY `$sort` $order");
438 return $sqh->fetchAll(PDO::FETCH_ASSOC);
459 if( empty($whitelist) ){
462 }
else if( in_array(
"*",$whitelist)){
463 $sqh = $this->dbh->query(
"SELECT `typ` , `ID`,`name`,`index`,`dispName`,`value`,`config`,`is_child`,`parent`,`is_required` FROM `$pollID` WHERE `parent` = $ID AND `is_child`=1 ORDER BY `index` ASC");
467 foreach( $whitelist as $typ){
468 $wlist = $wlist.
" OR `typ` = '$typ'";
470 $wlist = trim($wlist,
" OR ");
471 $sqh = $this->dbh->query(
"SELECT `typ` , `ID`,`name`,`index`,`dispName`,`value`,`config`,`is_child`,`parent`,`is_required`
476 ORDER BY `index` ASC");
479 $r =
$sqh->fetchAll( PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE );
490 $sqh = $this->dbh->query(
"SELECT `typ` , `ID`,`name`,`index`,`dispName`,`value`,`is_required`,`config`,`is_child` FROM `$pollID` WHERE ID = $ID AND `is_child`=0");
494 $r =
$sqh->fetch( PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE );
496 $r->pollID = $pollID;
497 if(
$r->is_child ==
"1"){
$r->is_child =
true;}
else{
$r->is_child =
false;}
498 if(
$r->is_required ==
"1"){
$r->is_required =
true;}
else{
$r->is_required =
false;}
508 if( (
$l !==
false) AND ($l2 !==
false) ){
510 $r->set_widgets($l2);
524 $sqh = $this->dbh->query(
"SELECT `ID` FROM `$pollID` WHERE `is_child`=0 ORDER BY `index` ASC");
525 $list =
$sqh->fetchAll(PDO::FETCH_ASSOC);
527 $widget_list = array();
528 foreach($list as $w){
531 $widget_list[] = $wo;
551 if( !(isset($w->typ)) ){
553 }
else if( $w->typ ==
"" ){
556 if( !(isset($w->index)) ){
559 if( !(isset($w->pollID)) ){
561 }
else if( $w->pollID ==
"" ){
575 $childs = $w->get_all_childs();
576 foreach( $childs as $child ){
583 if( (!isset($w->name)) OR ($w->name ==
"") ){
590 if( !isset($w->value) ){
592 }
else {$val = $w->value;}
594 if( !isset($w->config) ){
597 $w->serialize_config();
607 ":dn" => $w->dispName,
608 ":req" => $w->is_required,
611 ":chil" => $w->is_child,
614 $sqh = $this->dbh->prepare(
"INSERT INTO `{$w->pollID}` (`typ`,`name`,`index`,`dispName`,`is_required`,`value`,`config`,`is_child`,`parent`) VALUES (:t,:n,:i,:dn,:req,:v,:c,:chil,:par)");
617 $w->ID = $this->dbh->lastInsertId();
620 if( ($w->is_child ===
false) ){
621 if( ($w->name ==
"-") OR ($w->name ==
"") ){
622 $w->name =
"{$w->ID}";
627 if ($w instanceof container){
628 $childs = $w->get_all_childs();
629 foreach( $childs as $child ){
636 if( ($w instanceof
input_widget) AND ($w->direct_result ===
true) ){
637 if( ($w->is_child ===
true) ){
638 if( ($w->name ==
"-") OR ($w->name ==
"") ){
639 $w->name =
"{$w->ID}";
660 if ( !(isset($p->name)) ){
663 if( ($p->name ==
"") ){
667 $anon = $p->anonymous;
672 $cnf = $p->serialize_config();
677 ":ofn" => $p->owner_fn,
679 ":i" => $p->noDisplay,
684 $sqh = $this->dbh->prepare(
"INSERT INTO `umfragen` (`name`,`owner`,`owner_fn`,`type`,`anonymous`,`noDisplay`,`theme`,`config`) VALUES (:n,:o,:ofn,:t,:a,:i,:th,:cnf)");
687 $this->last_poll_insert_id = $this->dbh->lastInsertId();
688 $p->ID = intval($this->last_poll_insert_id);
689 $hash = $p->make_id_hash();
691 $this->dbh->exec(
"UPDATE `umfragen` SET `hashID` = '$hash' WHERE `ID`={$p->ID}");
693 $sql =
"CREATE TABLE `umfragen`.`{$p->ID}` (
694 `ID` int( 11 ) NOT NULL AUTO_INCREMENT ,
695 `typ` varchar( 15 ) COLLATE utf8_unicode_ci NOT NULL ,
696 `name` varchar( 256 ) COLLATE utf8_unicode_ci NOT NULL ,
697 `index` int( 11 ) NOT NULL ,
698 `dispName` varchar( 256 ) COLLATE utf8_unicode_ci NOT NULL ,
699 `value` longtext COLLATE utf8_unicode_ci NOT NULL ,
700 `is_required` tinyint( 1 ) NOT NULL DEFAULT '0',
701 `is_child` tinyint( 1 ) NOT NULL DEFAULT '0',
702 `parent` int( 11 ) NOT NULL DEFAULT '-1',
703 `config` longtext COLLATE utf8_unicode_ci,
705 ) ENGINE = InnoDB DEFAULT CHARSET = utf8 COLLATE = utf8_unicode_ci;";
706 $this->dbh->exec($sql);
719 CREATE TABLE IF NOT EXISTS `umfragen` (
720 `ID` int(11) NOT NULL AUTO_INCREMENT,
721 `hashID` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
722 `name` varchar(256) COLLATE utf8_unicode_ci NOT NULL,
723 `groups` tinytext COLLATE utf8_unicode_ci NOT NULL,
724 `owner` int(11) NOT NULL DEFAULT '0',
725 `owner_fn` varchar(256) COLLATE utf8_unicode_ci NOT NULL,
726 `timeout` datetime NOT NULL,
727 `active_since` datetime NOT NULL,
728 `status` int(11) NOT NULL DEFAULT '0',
729 `noDisplay` tinyint(1) NOT NULL DEFAULT '0',
730 `type` int(11) NOT NULL,
731 `anonymous` tinyint(1) NOT NULL DEFAULT '0',
732 `theme` varchar(256) COLLATE utf8_unicode_ci NOT NULL,
733 `config` longtext COLLATE utf8_unicode_ci NOT NULL,
735 UNIQUE KEY `ID` (`ID`)
736 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;";
737 $this->dbh->exec($sql);
747 "CREATE TABLE IF NOT EXISTS `user_config` (
748 `user` varchar(256) COLLATE utf8_unicode_ci NOT NULL,
749 `polls_visited` longtext COLLATE utf8_unicode_ci NOT NULL,
750 `email` varchar(256) COLLATE utf8_unicode_ci NOT NULL,
751 `config` longtext COLLATE utf8_unicode_ci NOT NULL
752 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
753 $this->dbh->exec($sql);
763 "CREATE TABLE IF NOT EXISTS `config` (
764 `name` varchar(256) COLLATE utf8_unicode_ci NOT NULL,
765 `value` longtext COLLATE utf8_unicode_ci NOT NULL
766 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
767 $this->dbh->exec($sql);
777 "CREATE TABLE IF NOT EXISTS `email_stack` (
778 `ID` INT UNSIGNED AUTO_INCREMENT,
779 `pollID` int(11) NOT NULL,
780 `type` VARCHAR(256) NOT NULL,
781 `fullName` VARCHAR(256) NOT NULL,
782 `uname` VARCHAR(256) NOT NULL,
783 `timestamp` DATETIME NOT NULL,
785 UNIQUE KEY `ID` (`ID`)
786 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
787 $this->dbh->exec($sql);
797 $sqh = $this->dbh->query(
"SHOW TABLES FROM `umfragen`");
798 $rows =
$sqh->fetchAll(PDO::FETCH_ASSOC);
801 $tables[] = $r[
"Tables_in_umfragen"];
803 if( in_array(
"umfragen",
$tables) ){
804 $ok[
"umfragen"] =
true;
806 $ok[
"umfragen"] =
false;
808 if( in_array(
"user_config",
$tables) ){
809 $ok[
"user_config"] =
true;
811 $ok[
"user_config"] =
false;
813 if( in_array(
"config",
$tables) ){
814 $ok[
"config"] =
true;
816 $ok[
"config"] =
false;
818 if( in_array(
"email_stack",
$tables) ){
819 $ok[
"email_stack"] =
true;
821 $ok[
"email_stack"] =
false;
838 $r = $p->load_from_id($this,$pID);
840 if( (isset($_SESSION[
"user"]->ID)) AND (isset($_SESSION[
"user"]->fullName)) ){
841 $p->owner = $_SESSION[
"user"]->ID;
842 $p->owner_fn = $_SESSION[
"user"]->fullName;
846 $p->save_name($this);
847 $p->save_groups($this);
848 $p->save_timeout($this);
849 foreach($p->widget_list as $wid){
851 if( $wid->name == $wid->ID){
854 $wid->pollID = $p->ID;
857 foreach( $wid->option_list as $option ){
858 $option->pollID = $p->ID;
860 foreach( $wid->widget_list as $child ){
861 if( $child->name == $child->ID){
864 $child->pollID = $p->ID;
871 foreach( $p->widget_list as
$widget ){
872 if( is_numeric($widget->name) ){
893 $r = $poll->load_from_id($this,$pID);
897 $widget = clone $poll->get_widget_by_id($wID);
903 foreach(
$widget->option_list as $option){
906 foreach(
$widget->widget_list as $child ){
907 $child->name = $child->name.
"-copy";
912 $childs =
$widget->get_all_childs();
913 foreach( $childs as $child ){
919 foreach(
$widget->widget_list as $child){
927 $childs =
$widget->get_all_childs();
928 foreach( $childs as $child ){
930 $option->name = $child->ID;
951 foreach($poll->widget_list as $wid){
976 if( $long_result ===
true ){
977 $sql =
"ALTER TABLE `{$pollID}_results` CHANGE `{$old_name}` `$new_name` LONGTEXT";
979 $sql =
"ALTER TABLE `{$pollID}_results` CHANGE `{$old_name}` `$new_name` VARCHAR( 256 )";
981 $sqh = $this->dbh->prepare($sql);
982 $sqh->execute(array());
991 if( (isset(
$widget->long_result)) AND (
$widget->long_result ===
true) ){
992 $sql =
"ALTER TABLE `{$widget->pollID}_results` ADD `{$widget->name}` LONGTEXT";
994 $sql =
"ALTER TABLE `{$widget->pollID}_results` ADD `{$widget->name}` VARCHAR( 256 )";
996 return $this->dbh->exec($sql);
1011 $sql =
"CREATE TABLE `umfragen`.`{$poll->ID}_results` (
1012 `user` varchar( 256 ) COLLATE utf8_unicode_ci NOT NULL,
1013 `name` varchar( 256 ) COLLATE utf8_unicode_ci NOT NULL,
1014 `Vorname` varchar( 256 ) COLLATE utf8_unicode_ci NOT NULL,
1015 `Nachname` varchar( 256 ) COLLATE utf8_unicode_ci NOT NULL,
1016 `group` varchar( 256 ) COLLATE utf8_unicode_ci NOT NULL,
1017 `Datum` DATETIME COLLATE utf8_unicode_ci NOT NULL
1018 ) ENGINE = InnoDB DEFAULT CHARSET = utf8 COLLATE = utf8_unicode_ci;";
1019 return $this->dbh->exec($sql);
1029 foreach($poll->widget_list as
$widget){
1031 if( (isset($widget->long_result)) AND ($widget->long_result ===
true) ){
1032 $sql_widgets = $sql_widgets.
"`{$widget->name}` LONGTEXT COLLATE utf8_unicode_ci NOT NULL ,";
1034 $sql_widgets = $sql_widgets.
"`{$widget->name}` varchar( 256 ) COLLATE utf8_unicode_ci NOT NULL ,";
1038 $sql =
"CREATE TABLE `umfragen`.`{$poll->ID}_results` (".$sql_widgets.
"
1039 `user` varchar( 256 ) COLLATE utf8_unicode_ci NOT NULL
1040 `name` varchar( 256 ) COLLATE utf8_unicode_ci NOT NULL,
1041 `Vorname` varchar( 256 ) COLLATE utf8_unicode_ci NOT NULL,
1042 `Nachname` varchar( 256 ) COLLATE utf8_unicode_ci NOT NULL,
1043 `group` varchar( 256 ) COLLATE utf8_unicode_ci NOT NULL,
1044 `Datum` DATETIME COLLATE utf8_unicode_ci NOT NULL
1045 ) ENGINE = InnoDB DEFAULT CHARSET = utf8 COLLATE = utf8_unicode_ci;";
1046 return $this->dbh->exec($sql);
1056 foreach($poll->widget_list as
$widget){
1057 if( (isset($widget->long_result)) AND ($widget->long_result ===
true) ){
1058 $sql_widgets = $sql_widgets.
"`{$widget->name}` LONGTEXT COLLATE utf8_unicode_ci NOT NULL ,";
1060 $sql_widgets = $sql_widgets.
"`{$widget->name}` varchar( 256 ) COLLATE utf8_unicode_ci NOT NULL ,";
1063 return $this->dbh->exec($sql_widgets);
1074 $return = array(
"value",
"action");
1075 $poll = clone $poll2;
1076 foreach( $poll->widget_list as
$widget ){
1078 foreach( $widget->widget_list as $child ){
1079 $poll->insert_widget(-1,$child);
1085 if( !isset( $_SESSION[
"user"]->
name) ){
1088 $user = $_SESSION[
"user"]->name;
1091 if( !isset( $_SESSION[
"user"]->fullName) ){
1094 $fullName = $_SESSION[
"user"]->fullName;
1096 if( !isset( $_SESSION[
"user"]->givenName) ){
1099 $givenName = $_SESSION[
"user"]->givenName;
1101 if( !isset( $_SESSION[
"user"]->surName) ){
1104 $surName = $_SESSION[
"user"]->surName;
1107 if( !isset( $_SESSION[
"user"]->group) ){
1110 $group = $_SESSION[
"user"]->group;
1113 if( !isset( $_SESSION[
"user"]->groupName) ){
1116 $groupName = $_SESSION[
"user"]->groupName;
1120 if( $poll->anonymous ===
true ){
1121 $data = array(); $fields =
""; $vals =
"";
1122 for(
$i=0 ;
$i <
sizeof($poll->widget_list) ; ++
$i){
1123 $add_container =
true;
1124 if( ($poll->widget_list[
$i] instanceof
container) AND ($poll->widget_list[
$i]->direct_result ===
false) ){
1125 $add_container =
false;
1128 if( ($poll->widget_list[
$i] instanceof
input_widget) AND ( $add_container ===
true ) ){
1129 $data[
":$i"] = $poll->widget_list[
$i]->value;
1130 $fields = $fields.
"`{$poll->widget_list[$i]->name}`,";
1131 $vals = $vals.
":$i,";
1134 $fields = trim($fields,
",");
1135 $vals = trim($vals,
",");
1136 $sqh = $this->dbh->prepare(
"INSERT INTO `{$poll->ID}_results` ($fields,`Datum`) VALUES ($vals,NOW())");
1138 if(
$err !==
false ){
1139 $return[
"action"] =
"insert";
1141 $return[
"value"] =
$err;
1147 $sqrh = $this->dbh->query(
"SELECT * FROM `{$poll->ID}_results` WHERE `user` = '$user'");
1148 if ($sqrh !==
false){
1149 $rec = $sqrh->fetchAll(PDO::FETCH_ASSOC);
1152 if(
sizeof($rec) == 0 ){
1153 $data = array(
":user"=>
$user,
":FN"=>$fullName,
":G"=>$groupName,
":givenName"=>$givenName,
":sn"=>$surName); $fields =
"`user`,`name`,`group`,`Vorname`,`Nachname`,"; $vals =
":user,:FN,:G,:givenName,:sn,";
1154 for(
$i=0 ;
$i <
sizeof($poll->widget_list) ; ++
$i){
1155 $add_container =
true;
1156 if( ($poll->widget_list[
$i] instanceof
container) AND ($poll->widget_list[
$i]->direct_result ===
false) ){
1157 $add_container =
false;
1160 if( ($poll->widget_list[
$i] instanceof
input_widget) AND ( $add_container ===
true ) ){
1161 $data[
":$i"] = $poll->widget_list[
$i]->value;
1162 $fields = $fields.
"`{$poll->widget_list[$i]->name}`,";
1163 $vals = $vals.
":$i,";
1166 $fields = trim($fields,
",");
1167 $vals = trim($vals,
",");
1169 $sqh = $this->dbh->prepare(
"INSERT INTO `{$poll->ID}_results` ($fields,`Datum`) VALUES ($vals,NOW())");
1172 if(
$err !==
false ){
1173 $return[
"action"] =
"insert";
1175 $return[
"value"] =
$err;
1179 }
else if(
sizeof($rec) == 1){
1180 $data = array(
":FN"=>$fullName,
":G"=>$groupName,
":sn"=>$surName,
":givenName"=>$givenName);
1181 $fields =
"`Datum`= NOW(),`name`=:FN,`group`=:G, `Vorname` = :givenName , `Nachname` = :sn,";
1182 for(
$i=0 ;
$i <
sizeof($poll->widget_list) ; ++
$i){
1183 $add_container =
true;
1184 if( ($poll->widget_list[
$i] instanceof
container) AND ($poll->widget_list[
$i]->direct_result ===
false) ){
1185 $add_container =
false;
1188 if( ($poll->widget_list[
$i] instanceof
input_widget) AND ( $add_container ===
true ) ){
1189 $data[
":$i"] = $poll->widget_list[
$i]->value;
1190 $fields = $fields.
"`{$poll->widget_list[$i]->name}` = :$i,";
1193 $fields = trim($fields,
",");
1194 $sqh = $this->dbh->prepare(
"UPDATE `{$poll->ID}_results` SET $fields WHERE `user` = '$user'");
1198 if(
$err !==
false ){
1199 $return[
"action"] =
"update";
1201 if( (isset($rec[0])) AND (isset($rec[0][
"Datum"])) ){
1202 if( $rec[0][
"Datum"] ===
"0000-00-00 00:00:00" ){
1203 $return[
"action"] =
"insert";
1207 $return[
"value"] =
$err;
1222 if($poll->anonymous ===
false){
1224 global $groups_whitelist;
1225 $group_mapping =
$au->get_gid_to_name_mapping($groups_whitelist);
1227 $sqrh = $this->dbh->query(
"SELECT `user`,`Datum` FROM `{$poll->ID}_results`");
1228 if ($sqrh ===
false){
1231 $rec = $sqrh->fetchAll(PDO::FETCH_ASSOC);
1232 $username_list_old = array();
1233 $username_list_old_for_remove = array();
1234 foreach($rec as $ent){
1236 if($ent[
"Datum"] ==
"0000-00-00 00:00:00"){
1237 $username_list_old_for_remove[] = $ent[
"user"];
1240 $username_list_old[] = $ent[
"user"];
1243 if(in_array(
"*",$poll->groups)){
1245 $gg = array_keys($group_mapping);
1256 $user_list_new =
$au->get_all_users_from_grouplist(
$groups);
1257 if(
sizeof($user_list_new) != 0){
1258 $username_list_new = array();
1259 foreach($user_list_new as $tmp_user){
1260 $username_list_new[] = $tmp_user[
"userName"];
1264 foreach($user_list_new as
$user){
1265 if( !in_array($user[
"userName"],$username_list_old) ){
1266 $sql =
"INSERT INTO `{$poll->ID}_results` (`user`,`Datum`,`name`,`group`,`Vorname`,`Nachname`) VALUES ('{$user["userName
"]}','0000-00-00 00:00:00','{$user["fullName
"]}','{$group_mapping[$user["groupID
"]]}','{$user["givenName
"]}','{$user["surName
"]}')";
1267 $this->dbh->exec($sql);
1272 foreach($username_list_old_for_remove as $user_old){
1273 if( !in_array($user_old,$username_list_new) ){
1274 $sql =
"DELETE FROM `{$poll->ID}_results` WHERE `{$poll->ID}_results`.`user` = '$user_old'";
1275 $this->dbh->exec($sql);
1289 $blacklist = array(
"Datum",
"user",
"group",
"name",
"Vorname",
"Nachname");
1290 $widget_list = array();
1291 $results_complete = array();
1295 $sqh = $this->dbh->query(
"SHOW COLUMNS FROM `{$poll->ID}_results`");
1297 $rows =
$sqh->fetchAll(PDO::FETCH_ASSOC);
1299 if(!in_array($r[
"Field"],$blacklist) ){
1300 $cols[] = $r[
"Field"];
1308 $sqh = $this->dbh->query(
"SELECT * FROM `{$poll->ID}_results`");
1309 $results_complete =
$sqh->fetchAll(PDO::FETCH_ASSOC);
1312 foreach($poll->widget_list as
$widget){
1315 foreach( $widget->widget_list as $child ){
1316 $widget_list[] = $child->name;
1318 if( $widget->direct_result ===
true ){
1320 $widget_list[] = $widget->name;
1323 $widget_list[] = $widget->name;
1330 foreach($cols as $col){
1332 if( ! in_array($col,$widget_list) ){
1334 $complete_void =
true;
1335 foreach($results_complete as $row){
1336 $value = $row[$col];
1338 $complete_void =
false;
1342 if($complete_void ===
true){
1343 $sql =
"ALTER TABLE `{$poll->ID}_results` DROP COLUMN `$col`";
1344 $this->dbh->exec($sql);
1358 $sqh = $this->dbh->query(
"SELECT polls_visited FROM `user_config` WHERE `user` = '$user'");
1359 if(
$sqh !==
false ){
1360 $res =
$sqh->fetch(PDO::FETCH_ASSOC);
1361 if( $res !==
false ){
1362 return explode(
",",$res[
"polls_visited"]);
1378 $sqh = $this->dbh->query(
"SELECT ID FROM `umfragen`");
1379 if(
$sqh !==
false ){
1380 $res =
$sqh->fetchAll(PDO::FETCH_ASSOC);
1381 if( $res !==
false ){
1382 foreach( $res as $row ){
1383 $exist[] = $row[
"ID"];
1385 foreach( $visited as $p ){
1386 if( !in_array($p,$exist) ){
1393 return array_diff($visited,$defunct);
1404 $sqh = $this->dbh->query(
"SELECT polls_visited FROM `user_config` WHERE `user` = '$user'");
1406 if(
$sqh !==
false ){
1407 $res =
$sqh->fetch(PDO::FETCH_ASSOC);
1408 if( $res ===
false ){
1415 $visstr = implode(
",",$visited);
1417 $sqh = $this->dbh->exec(
"INSERT INTO `user_config` (`polls_visited`,`user`) VALUES ('$visstr','$user')");
1419 $sqh = $this->dbh->exec(
"UPDATE `user_config` SET `polls_visited` = '$visstr' WHERE `user` = '$user'");
1421 if(
$sqh !==
false ){
1435 $visited = array_diff($visited,array($pollID));
1436 $visstr = implode(
",",$visited);
1437 $sqh = $this->dbh->exec(
"UPDATE `user_config` SET `polls_visited` = '$visstr' WHERE `user` = '$user'");
1452 if (
sizeof($wlist)==0){
1455 foreach($wlist as $w){
1456 $w->check_vital_vars();
1457 if( !isset($w->value) ){
1459 }
else {$val = $w->value;}
1462 if( isset($w->config) ){
1463 if( is_array($w->config)){
1464 $w->serialize_config();
1466 if(is_string($w->config)){
1477 ":dn" => $w->dispName,
1478 ":req" => (
int) $w->is_required,
1485 #$pollID = mysql_real_escape_string($wlist[0]->pollID);
1486 $pollID = $wlist[0]->pollID;
1487 $sqh = $this->dbh->prepare(
"UPDATE `$pollID` SET `typ` = :t , `name` = :n ,`index` = :i ,`dispName` = :dn, `value` = :v, `config` = :c, `is_required` = :req WHERE `ID` = :ID");
1488 foreach(
$data as $d){
1503 if ( !(isset($w->typ)) OR !(isset($w->name)) OR !(isset($w->index)) OR !(isset($w->pollID)) ){
1506 if( ($w->typ ==
"") OR ($w->name ==
"") ){
1510 $sqh = $this->dbh->prepare(
"UPDATE `{$w->pollID}` SET `$field` = :data WHERE `ID` = '{$w->ID}'");
1511 return $sqh->execute( array(
":data" =>
$data) );
1523 $sqh = $this->dbh->prepare(
"UPDATE umfragen SET `$field` = :data WHERE `ID` = $ID");
1524 return $sqh->execute( array(
":data" =>
$data) );
1536 $sqh = $this->dbh->query(
"SELECT polls_visited FROM `user_config` WHERE `user` = '$user'");
1538 if(
$sqh !==
false ){
1539 $res =
$sqh->fetch(PDO::FETCH_ASSOC);
1540 if( $res ===
false ){
1547 $sqh = $this->dbh->prepare(
"INSERT INTO user_config (`user`,`$field`) VALUES ('$user',:data)");
1549 $sqh = $this->dbh->prepare(
"UPDATE user_config SET `$field` = :data WHERE `user` = '$user'");
1551 return $sqh->execute( array(
":data" =>
$data) );
1562 if( (isset(
$data[
"pollID"])) AND (isset(
$data[
"type"])) AND (isset(
$data[
"fullName"])) AND (isset(
$data[
"uname"])) ){
1563 $sqh = $this->dbh->prepare(
"INSERT INTO `email_stack` (`pollID`,`type`,`fullName`,`uname`,`timestamp`) VALUES (:pollID,:type,:fullName,:uname,NOW())" );
1565 ":pollID" =>
$data[
"pollID"],
1566 ":type" =>
$data[
"type"],
1567 ":fullName" =>
$data[
"fullName"],
1568 ":uname" =>
$data[
"uname"]
1572 throw new exception(
"invalid data");
1581 $sqh = $this->dbh->query(
"SELECT * FROM `email_stack` ORDER BY `ID` DESC LIMIT 1");
1582 $res =
$sqh->fetch(PDO::FETCH_ASSOC);
1583 if( (is_array($res)) AND (
sizeof($res) == 0) ){
1594 $sqh = $this->dbh->query(
"SELECT * FROM `email_stack` ORDER BY `ID` DESC");
1595 $res =
$sqh->fetchAll(PDO::FETCH_ASSOC);
1605 $this->dbh->exec(
"DELETE FROM `email_stack` WHERE `ID` = $ID");
1618 $sqh = $this->dbh->query(
"SELECT * FROM `config` WHERE `name` = '$name'");
1620 $res =
$sqh->fetch(PDO::FETCH_ASSOC);
1621 if( (
sizeof($res) == 0) OR ($res ===
false) ){
1629 if( $create ===
false ){
1630 $sqh = $this->dbh->prepare(
"UPDATE `config` SET `value` = :data WHERE `name` = '$name'");
1631 return $sqh->execute( array(
":data" => $value) );
1633 $sqh = $this->dbh->prepare(
"INSERT INTO `config` (`name`,`value`) VALUES (:name,:data)");
1634 return $sqh->execute( array(
":name" => $name,
":data" => $value) );
1646 if( is_array($field) ){
1648 foreach( $field as $f){
1649 $fieldstr = $fieldstr.
",".$f;
1651 $fieldstr = trim($fieldstr,
",");
1652 $sqh = $this->dbh->query(
"SELECT $fieldstr FROM `user_config` WHERE `user`='$user'");
1654 $sqh = $this->dbh->query(
"SELECT $field FROM `user_config` WHERE `user`='$user'");
1656 if(
$sqh !==
false ){
1657 $res =
$sqh->fetch(PDO::FETCH_ASSOC);
1658 if( (is_array($res)) AND (
sizeof($res) == 1) ){
1659 return $res[$field];
1675 if( (isset(
$widget->long_result)) AND (
$widget->long_result ===
true) ){
1690 foreach( $poll->widget_list as
$widget ){
1694 foreach( $widget->widget_list as $child ){
1711 foreach( $poll->widget_list as
$widget ){
1715 foreach( $widget->widget_list as $child ){
1731 $blacklist = array(
"Datum",
"user",
"group",
"name");
1733 $sql =
"SELECT * FROM `{$pid}_results`";
1734 $sqh = $this->dbh->query($sql);
1735 if(
$sqh !==
false ){
1736 $res =
$sqh->fetchAll(PDO::FETCH_ASSOC);
1739 if(
sizeof($res) == 0 ){
1742 foreach( $res as
$r ){
1743 $keys = array_keys($r);
1744 for(
$i=0 ;
$i<
sizeof(
$r) ; ++
$i ){
1745 if( !in_array(
$keys[
$i],$blacklist) ){
1746 if( (!isset($r[
$keys[$i] ])) OR ($r[
$keys[$i] ] ==
"") OR ($r[
$keys[$i] ] ==
"NULL") OR ($r[
$keys[$i] ] ==
"null") ){
1752 if(
sizeof(
$data) != 0 ){
1758 if(
sizeof(
$data) == 0 ){
1774 $sql =
"UPDATE `{$pollID}_results` SET `user` = NULL , group = NULL , name = NULL, `Vorname` = NULL, `Nachname` = NULL";
1788 $sql =
"DROP TABLE `$id`";
1789 $this->dbh->exec($sql);
1799 $sql =
"DROP TABLE `{$id}_results`";
1800 $this->dbh->exec($sql);
1810 $sql =
"DELETE FROM `umfragen`.`umfragen` WHERE `umfragen`.`ID` = $id";
1811 $this->dbh->exec($sql);
1825 $sql =
"DELETE FROM `umfragen`.`$pollID` WHERE `ID` = $wID";
1826 $this->dbh->exec($sql);
1837 if(is_array($username_list)){
1841 foreach($username_list as
$user){
1847 $list = trim($list,
",");
1848 $sqh = $this->dbh->prepare(
"DELETE FROM `umfragen`.`{$pollID}_results` WHERE user IN ($list)");
1862 $sqh = $this->dbh->query(
"SELECT `user` FROM `umfragen`.`{$pollID}_results`");
1863 $old_usernames =
$sqh->fetchAll();
1864 if( $old_usernames !==
false ){
1865 foreach( $old_usernames as $row){
1869 $sql =
"DELETE FROM `umfragen`.`{$pollID}_results`";
1870 $this->dbh->exec($sql);