Umfragen
results.show.handle.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 $db= new db( DB_USER, DB_PASS, DB_DATABASE, DB_HOST );
38 $config->load();
39 make_session();
40 
41 
42 $edit = "";
43 // SET VARS
44 if ( (isset($_POST["pollID"])) AND
45  (is_numeric($_POST["pollID"])) AND
46  ($_POST["pollID"] != "")
47  )
48 {
49  $poll = new poll();
50  if (!$poll->load_from_id($db, intval($_POST["pollID"]) ) ){
51  die("Umfrage existiert nicht.");
52  }
53 
54 }else{
55  header("Location: index.php");
56  exit();
57 }
58 
59 //Do nothing if not owner and not admin
60 if( (intval($_SESSION["user"]->ID) !== intval($poll->owner) ) AND
61  ( !in_array("{$_SESSION["user"]->ID}",explode(",",SUPER_ADMIN) )) ){
62  die("Umfrage Bearbeiten nicht erlaubt.");
63 }
64 
65 // AFTER CONFIRM DO something
66 if( (!isset($_POST["save_results"])) AND (isset($_POST["confirm_save_result"])) ){
67  $keys = array_keys($_POST["selection"]);
68  $db->delete_result_for_user_list($poll->ID,$keys);
69  header("Location: results.show.php?pollID={$poll->ID}&edit_html");
70  }
71 
72 if( (!isset($_POST["rm_all"])) AND (isset($_POST["confirm_rm_all"])) ){
73  $db->delete_all_result($poll->ID);
74  header("Location: results.show.php?pollID={$poll->ID}&edit_html");
75  }
76 
77 
79 HTML::head("",1);
80 HTML::menu();
81 
82 // CONFIRM
83 if( (isset($_POST["selection"])) AND (is_array($_POST["selection"])) ){
84  if( (isset($_POST["save_results"])) AND (!isset($_POST["confirm_save_result"])) ){
85  echo "<form action='results.show.handle.php' method='POST'>";
86  $w_text = "";
87  $w_text=$w_text."<p>Ergebnisse folgender Personen wirklich löschen?</p><ul>";
88  $keys = array_keys($_POST["selection"]);
89  foreach($keys as $user){
90  $r = $db->get_poll_result_for_user($poll->ID,$user);
91  $w_text =$w_text."<li>{$r["name"]} ($user)</li>";
92  $w_text=$w_text."<input type='hidden' name='selection[$user]' value='on' />";
93  }
94  $w_text=$w_text."</ul>";
95  print_warning($w_text);
96 
97  echo "<input type='hidden' name='pollID' value='{$poll->ID}'/>";
98  echo "<input type='submit' name='confirm_save_result' value='Ja, löschen'/>";
99  echo "</form>";
100  }
101 }
102 
103 if( (isset($_POST["rm_all"])) AND (!isset($_POST["confirm_rm_all"])) ){
104  echo "<form action='results.show.handle.php' method='POST'>";
105  $count = $db->count_results($poll->ID);
106 
107  print_warning("$count Ergebniss einträge unwiederruflich löschen?");
108 
109  echo "<input type='hidden' name='pollID' value='{$poll->ID}'/>";
110  echo "<input type='submit' name='confirm_rm_all' value='Ja, löschen'/>";
111  echo "</form>";
112 
113 }
114 
115 
116 HTML::foot();
117 
118 ?>