Umfragen
embed.php
Go to the documentation of this file.
1 <?php
2 /*
3  * embed.php
4  *
5  * Copyright 2013 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 function display_poll_form($show_poll,$preview=false){
25 
26  echo '<form method="POST" action="">';
27  $show_poll->display();
28  $has_required = false;
29  foreach( $show_poll->widget_list as $widget ){
30  if( $widget->is_required == true ){
31  $has_required = true;
32  break;
33  }
34  }
35  if( $has_required == true ){
36  echo "<p style='margin-top:0em;margin-bottom:0em'><span class='required_asterisk'>*</span> bedeutet Plichtfeld.</p>";
37  }
38  if($preview==false){
39  echo '<br/><input type="submit" value="Senden" name="poll_submit"/>';
40  }
41  echo "</form>";
42 }
43 
44 
45 
46 // SESSION
47 require_once("inc/user.class.php");
48 if( !(isset($_SESSION)) ){
49  session_start();
50 }
51 
52 session_regenerate_id();
53 
54 
55 require_once("config.php");
56 require_once("inc/tools.php");
57 
58 require_once("inc/db.class.php");
59 require_once("inc/config.class.php");
60 require_once("inc/poll.class.php");
61 require_once("inc/messages.class.php");
62 $db= new db( DB_USER, DB_PASS, DB_DATABASE, DB_HOST );
64 $config->load();
65 
66 $now = time();
67 
68 // LOAD POLLS
69 $ps = $db->get_all_polls_array();
70 $polls = array();
71 foreach($ps as $pps){
72  // check if public poll
73  if( $pps["anonymous"] == "2"){
74  $p = new poll();
75  $p->load_from_id($db,$pps["ID"]);
76  // check timeout and Status
77  if( ($p->status == STATUS_NORMAL) AND
78  ($p->get_timeout_timestamp() >= $now) ){
79  $polls[$p->ID] = $p;
80  }
81  unset($p);
82  }
83 }
84 
85 // default page --> list public polls
86 $page = "index";
87 
88 
89 if( (isset($_GET["h"])) AND (strlen($_GET["h"]) == 32) ){
90  // if poll is public
91  foreach( $polls as &$p ){
92  if( $p->hashID === $_GET["h"] ){
93  $poll = $p;
94  $page = "show poll";
95  }
96  } // end foreach poll
97 } // end if option "h"
98 
99 
100 // submit form
101 if( (isset($_POST["poll_submit"])) AND (isset($poll)) ){
102  $poll->load_from_id($db,$poll->ID); // get old results
103  $page = "handle poll";
104 }
105 
106 
107 // load counters for widgets
108 if( ($page == "show poll") OR ($page == "handle poll") ){
109  $poll->load_widget_result_count($db);
110 }
111 
112 // include polls theme
113 if( ($page == "show poll") OR ($page == "handle poll") OR ($page == "preview") ){
114  $theme_include = '<link href="'.APP_ROOT.'/CSS/Themes/'.$poll->theme.'" rel="stylesheet" type="text/css">';
115 }else{
116  $theme_include ="";
117 }
118 
119 
120 
121 ?>
122 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
123  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
124 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
125 
126 <head>
127  <title>Umfrage</title>
128  <meta http-equiv="content-type" content="text/html;charset=utf-8" />
129  <meta name="generator" content="Geany 0.21" />
130  <style type="text/css">
131  .required_asterisk{
132  color:#C21C1C;
133  }
134 
135 
136  .error .message_ul{
137  list-style:none;
138  padding:0px;
139  margin:0px;
140  }
141  .error .message.ul li{
142  margin:0px;
143  padding:0px;
144  }
145  .error{
146  padding:5px;
147  margin:10px 0px 20px 0px;
148  border-radius:10px;
149  box-shadow:1px 1px 2px #525252;
150  background-color:#F88F94;
151  border:2px solid #8A0000;
152  text-shadow:1px 1px 1px #FFD3D3;
153  }
154  .error hr{
155  color:#FF7B81;
156  background-color:#FF7B81;
157  height:1px;
158  width:10em;
159  margin:2px;
160  }
161  .error .message_text_top_left{
162  background-color:#FFDFE1;
163  border-bottom:2px solid #8A0000;
164  border-right:2px solid #8A0000;
165  padding:2px 10px 2px 2px;
166  margin:0px;
167  position:relative;
168  top:-3px; /*-5px+2px*/
169  left:-5px;
170  border-top-left-radius:10px;
171  border-bottom-right-radius:10px;
172  }
173  .error img{
174  height:2.5em;
175  margin-right:.5em;
176  vertical-align: middle;
177  }
178 
179  </style>
180 
181  <?php echo $theme_include;?>
182 </head>
183 
184 <body>
185 
186 
187 <?php
188 
189 
190 if ($page == "show poll"){
191  // display ... timeout and status check done by loading complete list above
192  display_poll_form($poll);
193 
194 // HANDLE POLL INPUT
195 }else if($page == "handle poll"){
196 
197  $errors = $poll->handle_inpt(); // returns array of errors
198 
199  // if there is an input error reshow the form
200  if(sizeof($errors) != 0){
201  foreach($errors as $e){
202  print_err($e);
203  }
204  display_poll_form($poll);
205 
206  }else{
207  // insert in DB if there is no error
208  $ret = $db->insert_poll_result($poll);
209 
210  $email_stack = array("pollID" => $poll->ID , "type" => $ret["action"] , "fullName" => "Unbekannt", "uname" => "" , "timestamp" => "NOW()" );
211 
212  if ( $ret["value"] !== false ){
213  $notif_events = $poll->get_config("email_notif");
214  if( in_array($ret["action"],$notif_events) ){
215  $db->email_stack_add($email_stack);
216  }
217  // failure
218  }else{
219  $messages->add_message( new errorMessage("Fehler in der Datenbank! Deine Daten wurden <b>nicht</b> gespeichert") );
220  }
221 
222  echo "<p>Vielen Dank, dass du an dieser Umfrage Teilgenommen hast.</p>";
223  echo "<p><a href='embed.php?h={$poll->hashID}'>Zurück</a></p>";
224 
225  // SHOW RESULTS !!!
226 
227 
228  } // end if errors
229 }
230 
231 
232 // send notification emails in a new background process
233 exec("cd backend && php email-bg.php");
234 
235 ?>
236 </body>
237 
238 </html>