Umfragen
ajax.php
Go to the documentation of this file.
1 <?php
2 /*
3  * backend/ajax.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 require_once("../config.php");
26 require_once("../inc/user.class.php");
27 require_once("../inc/tools.php");
28 require_once("../inc/check_login.php");
29 
30 require_once("../inc/db.class.php");
31 require_once("../inc/config.class.php");
32 require_once("../inc/auth.class.php");
33 
34 require_once("../inc/poll.class.php");
35 require_once("../inc/messages.class.php");
36 require_once("../inc/html.class.php");
37 
38 $db= new db( DB_USER, DB_PASS, DB_DATABASE, DB_HOST );
40 $config->load();
41 
43 // SESSION
44 make_session();
45 
46 $edit = "";
47 // SET VARS
48 if ( (isset($_GET["pollID"])) AND
49  (is_numeric($_GET["pollID"])) AND
50  ($_GET["pollID"] != "")
51  )
52 {
53  $poll = new poll();
54  if (!$poll->load_from_id($db, intval($_GET["pollID"]) ) ){
55  die("");
56  }
57 
58  if ( (isset($_GET["widgetID"])) AND ($_GET["widgetID"] != "") AND (is_numeric($_GET["widgetID"])) ){
59  $widget = $poll->get_widget_by_id( intval($_GET["widgetID"]) );
60  if (isset($widget)){
61  $edit = "widget";
62  }
63  }else{
64  $edit = "poll";
65  }
66 
67 }else{
68  exit();
69 }
70 
71 
72 check_login();
73 
74 // edit needs ownership or admin rights
75 if( (intval($_SESSION["user"]->ID) !== intval($poll->owner) ) AND
76  ( !in_array("{$_SESSION["user"]->ID}",explode(",",SUPER_ADMIN) )) ){
77  die("");
78 }
79 
80 
81 if( isset($_GET["action"]) ){
82 
83  if( ($_GET["action"] == "mvwid") AND (isset($widget)) ){
84  if( (isset($_GET["pos"])) ){
85  $indexes = explode( ",",$_GET["pos"] );
86  if( (isset($indexes)) AND (sizeof($indexes) == 2) ){
87  $poll->move_widget($db,$indexes[0],$indexes[1]);
88  }
89  }
90  }else if( $_GET["action"] == "setStatus" AND (isset($poll)) ){
91  $status_mapping = array(
92  STATUS_NORMAL => array("name"=>"aktiv" , "css"=>"status_active"),
93  STATUS_INCOMPLETE => array("name"=>"inaktiv" , "css"=>"status_inactive"),
94  STATUS_USER_DEACTIVATED => array("name"=>"deaktiviert" , "css"=>"status_deactivated") );
95 
96  if( isset($_GET["status"]) ){
97  $old_status = $poll->status;
98  $new_status = $old_status;
99  $status = intval($_GET["status"]);
100 
101  if($status == STATUS_NORMAL){
102  // versuche aktivierung
103  $r = $poll->check_setup_complete();
104  if($r == true){
105  $rr = $poll->set_status($db,$status);
106  $db->update_poll_field($poll->ID , "active_since", date("Y-m-d H:i:s") );
107  if( $rr === true){
108  $new_status = $status;
109  }
110  }else{
111  //return "Die Umfrage konnte nicht aktiviert werden, da noch einige Elemente in der Einstellung fehlen.";
112  }
113  }else if($status == STATUS_USER_DEACTIVATED){
114  // andere stati
115  $r = $poll->set_status($db,$status);
116  $db->update_poll_field($poll->ID , "active_since", "0000-00-00 0:0:0" );
117  if( $r === true){
118  $new_status = $status;
119  }
120  }
121  // if status set send some data to client
122  if( $new_status !== $old_status ){
123  $data = array("pollID"=>$poll->ID, "statusCSS" =>$status_mapping[$new_status]["css"] , "statusTXT" =>$status_mapping[$new_status]["name"]);
124  $ts = $poll->get_timeout_timestamp();
125  if( ($ts < time()) AND ($new_status == STATUS_NORMAL) ){
126  $data["statusTXT"] = "abgelaufen";
127  $data["statusCSS"] = "status_timeout";
128  }
129  print json_encode($data);
130  }
131  }
132  }
133 
134 
135 /*
136  // WIDGET move up
137  if( ($_GET["action"] == "mvup") AND (isset($widget)) ){
138  $poll->move_widget($db,$widget->index,$widget->index-1);
139  $_SESSION["last_widget_edit"] = $widget->ID;
140  header("location: edit.php?pollID={$poll->ID}#widget{$widget->ID}");
141  exit();
142  // WIDGET move down
143  }else if( ($_GET["action"] == "mvdwn") AND (isset($widget) ) ){
144  $poll->move_widget($db,$widget->index,$widget->index+1);
145  $_SESSION["last_widget_edit"] = $widget->ID;
146  header("location: edit.php?pollID={$poll->ID}#widget{$widget->ID}");
147  exit();
148  *//*
149  // WIDGET delete
150  }else if( ($_GET["action"] == "rmwid") AND (isset($widget) ) AND (isset($_POST["rmwid_confirm"])) ){
151  $poll->delete_widget($db,$widget->ID);
152  $db->garbage_collect_result_table($poll);
153  header("location: edit.php?pollID={$poll->ID}");
154  exit();
155  }else if( ($_GET["action"] == "rmwid") AND (isset($_POST["cancel_action"])) AND (isset($widget)) ){
156  header("location: edit.php?pollID={$poll->ID}");
157  exit();
158  }else if( ($_GET["action"] == "rmwid") AND (isset($widget) ) ){
159  $edit="confirm widget remove";
160 
161  // WIDGET duplicate
162  }else if( ($_GET["action"] == "duplicate_widget") AND (isset($widget)) ){
163  $new_id = $db->duplicate_widget($poll->ID,$widget->ID);
164  $_SESSION["last_widget_edit"] = $new_id;
165  header("location: edit.php?pollID={$poll->ID}#widget{$new_id}");
166  exit();
167  */
168 }
169 
170 ?>