Umfragen
results.show.php
Go to the documentation of this file.
1 <?php
2 /*
3  * backend.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 require_once("../config.php");
25 require_once("../inc/user.class.php");
26 require_once("../inc/tools.php");
27 require_once("../inc/check_login.php");
28 check_login();
29 
30 require_once("../inc/db.class.php");
31 require_once("../inc/config.class.php");
32 
33 require_once("../inc/poll.class.php");
34 require_once("../inc/messages.class.php");
35 require_once("../inc/html.class.php");
36 require_once("../inc/chart.class.php");
37 $db= new db( DB_USER, DB_PASS, DB_DATABASE, DB_HOST );
39 $config->load();
40 make_session();
41 
42 
43 function make_url($sort,$order){
44  $qarr = explode("&",$_SERVER['QUERY_STRING']);
45  $qarr_n = array();
46  $sort_passed = false;
47  $order_passed = false;
48  // go through query string
49  foreach( $qarr as $q ){
50  if( (substr($q,0,5) == "sort=") ){
51  if( ($sort_passed === false) ){
52  $qarr_n[] = "sort=$sort";
53  $sort_passed = true;
54  }else{
55  // ignore duplicates
56  }
57 
58  }else if( ($q == "asc") OR ($q == "desc") ){
59  if( ($order_passed === false) ){
60  $qarr_n[] = "$order";
61  $order_passed = true;
62  }else{
63  // ignore duplicates
64  }
65  }else{
66  // copy other
67  $qarr_n[] = "$q";
68  }
69  }
70 
71  $url = $_SERVER[ 'SCRIPT_NAME' ]."?";
72  $url .= implode("&",$qarr_n);
73  // if missing
74  if( strpos($url,"sort") === false ){
75  $url .= "&sort=$sort";
76  }
77  if( (strpos($url,"asc") === false) AND (strpos($url,"desc") === false) ){
78  $url .= "&$order";
79  }
80 
81  return $url;
82 }
83 
84 
85 function make_table($db,$poll,$editable=false){
86  if( isset($_GET["sort"]) ){
87  $sort = $_GET["sort"];
88  }else{
89  $sort = "";
90  }
91  if( isset($_GET["asc"]) ){
92  $order = "asc";
93  }else if( isset($_GET["desc"]) ){
94  $order = "desc";
95  }else{
96  $order = "asc";
97  }
98 
99  $order2 = "";
100  if( $order == "desc" ){
101  $order2 = "asc";
102  }else if( $order == "asc" ){
103  $order2="desc";
104  }
105  //$order_icons = array( "asc" => "" , "desc" => "" , "ascdesc" => "");
106  $order_icons = array(
107  "asc" => "<img src='".APP_ROOT."/icons/16/sort-down.png' alt='' style='vertical-align:middle'/>" ,
108  "desc" => "<img src='".APP_ROOT."/icons/16/sort-up.png' alt='' style='vertical-align:middle'/>" ,
109  "ascdesc" => "");
110 
111  $res = $db->export_result($poll->ID,$sort,$order);
112  if( sizeof($res) > 0 ){
113  echo "<table class='result_table'>";
114  echo "<tr>";
115  if($editable){
116  echo "<th></th>";
117  }
118 
119  foreach( array_keys($res[0]) as $name ){
120  if( ($sort == $name) ){
121  $url = make_url($name,$order2);
122  $icon = $order_icons[$order2];
123  $css = "sorted";
124  }else{
125  $url = make_url($name,"asc");
126  $icon = "";//$order_icons["asc"];
127  $css = "";
128  }
129 
130  if( ! in_array($name, array("user","name","group","Datum") ) ){
131  $wid = $poll->get_widget_by_name($name);
132  if( isset($wid) ){
133  echo "<th class='$css'> <a href='$url'>$icon {$wid->dispName}";
134  if( $poll->type == POLLTYPE_ADVANCED ){
135  echo "<br/> <span style='font-size:80%;font-variant:italic'>({$name})</span>";
136  }
137  echo "</a> </th>";
138  }else{
139  echo "<th class='$css'> <a href='$url'>$icon {$name}</a> </th>";
140  }
141  }else{
142  // other columns
143  echo "<th class='$css'> <a href='$url'>$icon {$name}</a> </th>";
144  }
145  }
146  echo "</tr>";
147 
148  $c = 0;
149  // go through all results
150  foreach( $res as $row ){
151  $evenodd = $c %2;
152  echo "<tr class='line$evenodd'>";
153  if($editable){
154  echo "<td> <input type='checkbox' name='selection[{$row["user"]}]'/> </td>";
155  }
156  // make collums per row
157  foreach( array_keys($row) as $name){
158  $hh = htmlspecialchars($row[$name],ENT_QUOTES,"UTF-8",true);
159  echo "<td>{$hh}</td>";
160  }
161  echo "</tr>";
162  ++$c;
163  }
164  echo "</table>";
165  }
166 
167 }
168 
169 $edit = "";
170 // SET VARS
171 if ( (isset($_GET["pollID"])) AND
172  (is_numeric($_GET["pollID"])) AND
173  ($_GET["pollID"] != "")
174  )
175 {
176  $poll = new poll();
177  if (!$poll->load_from_id($db, intval($_GET["pollID"]) ) ){
178  die("Umfrage existiert nicht.");
179  }
180 
181 }else{
182  header("Location: index.php");
183  exit();
184 }
185 
186 
187 if( (intval($_SESSION["user"]->ID) !== intval($poll->owner) ) AND
188  ( !in_array("{$_SESSION["user"]->ID}",explode(",",SUPER_ADMIN) )) ){
189  die("Umfrage Bearbeiten nicht erlaubt.");
190 }
191 
192 
193 
194 
195 // CSV export
196 $db->garbage_collect_result_table($poll);
197 if( isset($_GET["view_csv"]) ){
198  $poll->handle_export_edit($db,false);
199  exit();
200 }else if (isset($_GET["dl_csv"])){
201  $poll->handle_export_edit($db,true);
202  exit();
203 // HTML
204 }else if(isset($_GET["view_html"]) ){
205  $edit = "show html results";
206 }else if(isset($_GET["edit_html"]) ){
207  $edit = "edit html results";
208 // STATS
209 }else if( isset($_GET["view_count"]) ){
210  $edit = "show count";
211 }else if( isset($_GET["view_charts"]) ){
212  $edit = "show charts";
213 }
214 
215 $status_human_readable = array( STATUS_INCOMPLETE=>"Unfollständig konfiguriert",
216  STATUS_NORMAL=>"Normal",
217  STATUS_USER_DEACTIVATED=>"Deaktiviert",
218  STATUS_DELETED=>"Gelöscht",
219  STATUS_TEMPLATE=>"Vorlage",
220  STATUS_SHARED_TEMPLATE=>"Vorlage geteilt");
221 $polltype_human_readable = array(POLLTYPE_SIMPLE=>"Einfache Konfiguration",POLLTYPE_ADVANCED=>"Erweiterte Konfiguration");
222 
223 HTML::doctype();
224 if( ($edit == "show html results") OR ($edit == "edit html results") ){
225  echo '
226  <head>
227  <title>Umfrage</title>
228  <meta http-equiv="content-type" content="text/html;charset=utf-8" />
229  <meta name="generator" content="Geany 0.21" />
230  <link rel="icon" type="image/png" href="../icons/32/dialog-apply.png">
231  <link href="../JS/jquery/css/smoothness/jquery-ui-1.10.0.custom" rel="stylesheet">
232  <script src="../JS/jquery/jquery-1.9.0.js"></script>
233  <script src="../JS/jquery/jquery-ui-1.10.0.custom.js"></script>
234  <link href="'.APP_ROOT.'/CSS/style.css" rel="stylesheet" type="text/css">
235  <link href="'.APP_ROOT.'/CSS/menu_nav.css" rel="stylesheet" type="text/css">
236  <link href="'.APP_ROOT.'/CSS/backend.css" rel="stylesheet" type="text/css">
237  <link href="'.APP_ROOT.'/CSS/messages.css" rel="stylesheet" type="text/css">
238  </head>
239  <body>
240  <div class="content" style="width:80% !important" >
241  ';
242 }else{
243  HTML::head("",1);
244 }
245 
246 HTML::menu();
247 if( ($edit == "show html results") OR ($edit == "edit html results") ){
248  $timeout = $poll->get_timeout_string();
249  if($poll->anonymous == true){
250  $anon = "Anonym";
251  }else{
252  $anon = "Nicht anonym";
253  }
254  if( $poll->is_public === true){
255  $anon = "Öffentlich";
256  }
257  echo "<table class='table_2' style='width:500px'>";
258  echo "<tr> <th>Eigenschaft</th> <th>Wert</th></tr>";
259  echo "<tr> <td>Name</td> <td>{$poll->name}</td></tr>";
260  echo "<tr> <td>Typ</td> <td>{$polltype_human_readable[$poll->type]}</td></tr>";
261  echo "<tr> <td>aktueller Status</td> <td>{$status_human_readable[$poll->status]}</td></tr>";
262  echo "<tr> <td>Endet am</td> <td>$timeout</td></tr>";
263  echo "<tr> <td>Anonymität</td> <td>$anon</td></tr>";
264  echo "</table>";
265  echo "<p><a href='edit.php?pollID={$poll->ID}'>zurück</a> zu den Umfrageeinstellungen</p>";
266 }
267 
268 // HTML
269 if($edit == "show html results"){
270  echo "<div style='width:100%;height:600px;overflow:scroll'>";
271  make_table($db,$poll,false);
272  echo "</div>";
273 
274 }else if($edit == "edit html results"){
275 
276  echo "<form action='results.show.handle.php' method='POST'>";
277  echo "<div style='width:100%;height:600px;overflow:scroll'>";
278  make_table($db,$poll,true);
279  echo "</div>";
280  echo "<input type='hidden' name='pollID' value='{$poll->ID}'/>";
281 
282  echo "<br/>";
283  if($poll->anonymous == false){
284  echo "<span style='margin-left:2em'>&nbsp;</span>ausgewählte Elemente <input type='submit' name='save_results' value='Löschen'/>";
285  echo "<span style='margin-left:2em'>&nbsp;</span>Auswahl <input type='reset' value='Zurücksetzen'/>";
286  }
287  echo "<span style='margin-left:2em'>&nbsp;</span><b>alles</b> <input type='submit' name='rm_all' value='Löschen'/>";
288  echo "</form>";
289 
290 // COUNT
291 }else if ($edit == "show count"){
292  $poll->load_widget_result_count($db);
293  echo "<ul>";
294  foreach($poll->widget_list as $widget){
295  if( $widget instanceof container ){
296  echo "<li>{$widget->dispName} <span style='color:red'>{$widget->get_data("count")}</span>";
297  echo "<ul>";
298  if( $widget instanceof matrix ){
299  foreach($widget->widget_list as $question){
300  echo "<li>{$question->dispName}";
301  echo "<ul>";
302  foreach( $widget->option_list as $opt){
303  echo "<li>{$opt->value} <span style='color:red'>{$question->get_data('count_'.$opt->ID)}</span></li>";
304  }
305  echo "</ul></li>";
306  }
307 
308  }else{
309  foreach($widget->option_list as $option){
310  echo "<li>{$option->dispName} <span style='color:red'>{$option->get_data("count")}</span></li>";
311  }
312  }
313  echo "</ul></li>";
314  }else if($widget instanceof checkBoxSingle){
315  $true = $widget->get_config("true"); $false = $widget->get_config("false");
316  echo "<li>{$widget->dispName} - $true <span style='color:red'>{$widget->get_data("count_true")}</span></li>";
317  echo "<li>{$widget->dispName} - $false <span style='color:red'>{$widget->get_data("count_false")}</span></li>";
318  }else{
319  echo "<li>{$widget->dispName} <span style='color:red'>{$widget->get_data("count")}</span></li>";
320  }
321  }
322  echo "</ul>";
323 
324 // CHARTS
325 }else if ($edit == "show charts"){
326  echo "<p><a href='edit.php?pollID={$poll->ID}'>zurück</a> zu den Umfrageeinstellungen</p>";
327  $poll->load_widget_result_count($db);
328  echo '<script src="../JS/Chart.js"></script>';
329  foreach( $poll->widget_list as $widget ){
330  if( $widget instanceof chartable_widget ){
331  $widget->chart_display();
332  }
333  }
334 }
335 
336 echo "<p><a href='edit.php?pollID={$poll->ID}'>zurück</a> zu den Umfrageeinstellungen</p>";
337 
338 HTML::foot();
339 
340 ?>