Umfragen
edit.handle.php
Go to the documentation of this file.
1 <?php
2 /*
3  * backend/edit.handle.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  */
56 // SESSION
57 require_once("../config.php");
58 require_once("../inc/user.class.php");
59 require_once("../inc/tools.php");
60 make_session();
61 
62 require_once("../inc/check_login.php");
63 check_login();
64 
65 require_once("../inc/db.class.php");
66 require_once("../inc/config.class.php");
67 
68 require_once("../inc/html.class.php");
69 require_once("../inc/poll.class.php");
70 require_once("../inc/messages.class.php");
71 
72 $db= new db( DB_USER, DB_PASS, DB_DATABASE, DB_HOST );
74 $config->load();
75 
77 
78 $err_reason = array();
79 
80 
81 // LOAD POLL
82 if( (isset($_POST["pollID"])) AND ($_POST["pollID"] != "") AND ( is_numeric($_POST["pollID"]) ) ){
83  $pollID = intval($_POST["pollID"]);
84  $poll = new poll();
85  if( !$poll->load_from_id($db,$pollID) ){
86  $messages->add_message( new errorMessage("Die angeforderte Umfrage existiert leider nicht...") );
87  }
88 }
89 
90 // LOAD WIDGET
91 if( (isset($_POST["wID"])) AND ($_POST["wID"] != "") AND ( is_numeric($_POST["wID"]) ) AND (isset($poll) ) ){
92  $wID = intval($_POST["wID"]);
93  $widget = $poll->get_widget_by_id($wID);
94  if( !isset($widget) ){
95  $messages->add_message( new errorMessage("Die angeforderte Frage in dieser Umfrage existiert leider nicht ... ") );
96  }
97 }
98 // LOAD option
99 if( (isset($_POST["oID"])) AND ($_POST["oID"] != "") AND ( is_numeric($_POST["oID"]) ) AND (isset($widget) ) ){
100  $oID = intval($_POST["oID"]);
101  $option = $widget->get_widget_by_id($oID);
102  if( !isset($option) ){
103  $messages->add_message( new errorMessage("Die angeforderte Option in dieser Frage, dieser Umfrage existiert leider nicht ... ") );
104  }
105 }
106 
107 
108 // PERMISSIONS !! IMPORTANT
109 if( (intval($_SESSION["user"]->ID) !== intval($poll->owner) ) AND
110  ( !in_array("{$_SESSION["user"]->ID}",explode(",",SUPER_ADMIN) )) ){
111  die("Umfrage Bearbeiten nicht erlaubt.");
112 }
113 
114 // detect option edit
115 $keys = array_keys($_POST);
116 foreach($keys as $key){
117  $actions = array("add","rm","mvup","mvdwn","addq","rmq","mvupq","mvdwnq","editq");
118  foreach($actions as $act){
119  if(
120  (substr($key, 0, strlen("{$act}_option_ID") ) == "{$act}_option_ID" )
121  AND ( is_numeric(substr($key,strlen("{$act}_option_ID"))) )
122  AND ( !isset($add_option) )
123  ){
124  $tmp = intval( substr($key,strlen("{$act}_option_ID")) );
125  // check if provided ID is an option !!!!!!!
126  if( ($widget instanceof container) ){
127  if( ($widget->get_widget_by_id($tmp)!= NULL)
128  OR (($tmp == $widget->ID) AND ($act == "addq") )
129  OR ($widget->get_option_by_id( $tmp ) != NULL)
130  OR (($tmp == $widget->ID) AND ($act == "add") ) ){
131  $option_action_ID = $tmp;
132  $option_action = $act;
133  } // end if option
134  }// end if container
135  }// end if opton_ID
136  }
137 }
138 unset($keys);
139 
140 // IF POLL AND WIDGET LOADED
141 if( ($messages->iserr()) === false){
142  $err_reason = array();
143  // options & widgets
144  if ( ((isset($_POST["save"])) AND ($_POST["save"] != "")) OR ((isset($_POST["apply"])) AND ($_POST["apply"] != "")) ){
145  if( (isset($option)) AND (isset($widget)) AND (isset($poll)) ){
146  if( $option instanceof label ){
147  include(INCLUDE_DIR."/backend/handle/edit.label.child.handle.php");
149  }
150 
151  }else if( (isset($widget)) AND (isset($poll)) ){
152  include(INCLUDE_DIR."/backend/handle/edit.".$widget->typ.".handle.php");
154 
155  }
156 
157  // polls
158  }else if( (isset($_POST["save_poll"])) OR (isset($_POST["apply_poll"])) ){
159  include(INCLUDE_DIR."/backend/handle/edit.poll.handle.php");
161  // option action
162  }else if( (isset($option_action_ID)) AND (isset($option_action)) AND (isset($poll)) AND (isset($widget)) ){
163  if($widget->typ == "radioButtonList" ){
164  include(INCLUDE_DIR."/backend/handle/edit.radioButtonList.handle.php");
165  $add_type = "radioButton";
166  }else if($widget->typ == "checkBoxList" ){
167  include(INCLUDE_DIR."/backend/handle/edit.checkBoxList.handle.php");
168  $add_type = "checkBox";
169  }else if($widget->typ == "matrix" ){
170  include(INCLUDE_DIR."/backend/handle/edit.matrix.handle.php");
171  $add_type = "matrixOption";
172  if( $add_action == "addq"){
173  $add_type = "matrixQuestion";
174  }
175  }else if($widget->typ == "textExt" ){
176  include(INCLUDE_DIR."/backend/handle/edit.textExt.handle.php");
177  $add_type = $widget->handle_add_widget_edit();
178  }else if($widget->typ == "label" ){
179  include(INCLUDE_DIR."/backend/handle/edit.label.handle.php");
180  $add_type = "label";
181  }else if($widget->typ == "schedule" ){
182  include(INCLUDE_DIR."/backend/handle/edit.schedule.handle.php");
183  $add_type = "scheduleDate";
184  }
185 
186  if( sizeof($all_err_reason) ==0 ){
187  if( ($widget instanceof label) AND ($option_action == "editq") ){
188  header("Location: edit.php?pollID={$poll->ID}&widgetID={$widget->ID}&optionID={$option_action_ID}");
189  exit();
190  }
191  header("Location: action.option.php?pollID={$poll->ID}&widgetID={$widget->ID}&optionID={$option_action_ID}&action=$option_action&type=$add_type");
192  exit();
193  }else{
194  foreach($all_err_reason as $err){
195  $messages->add_message( new errorMessage($err) );
196  }
197  header("Location: edit.php?pollID={$poll->ID}&widgetID={$widget->ID}");
198  }
199  exit();
200  }
201 }
202 
203 
204 // HANDLE ERRORS
205 if( sizeof($err_reason) > 0 ){
206  foreach( $err_reason as $er){
207  $messages->add_message( new errorMessage($er) );
208  }
209 }
210 
211 // on success
212 if( (sizeof($err_reason) == 0) ){
213  //options
214  if( (isset($_POST["apply"])) AND (isset($option)) ){
215  header("Location: edit.php?pollID=$pollID&widgetID=$wID&optionID={$option->ID}");
216  }else if( (isset($_POST["save"])) AND (isset($option)) ){
217  header("Location: edit.php?pollID=$pollID&widgetID=$wID");
218  // widgets
219  }else if( isset($_POST["apply"]) ){
220  header("Location: edit.php?pollID=$pollID&widgetID=$wID");
221  }else if( (!isset($_POST["save_poll"])) AND (!isset($_POST["apply_poll"])) ){
222  $_SESSION["last_widget_edit"] = $widget->ID;
223  header("Location: edit.php?pollID=$pollID#widget{$widget->ID}");
224  }
225  // polls
226  if( isset($_POST["save_poll"]) ){
227  $_SESSION["last_poll_edit"] = $poll->ID;
228  header("Location: index.php");
229  }else if( isset($_POST["apply_poll"]) ){
230  header("Location: edit.php?pollID=$pollID#poll_settings");
231  }
232 // on error
233 }else{
234  //widgets
235  if( isset($option) ){
236  header("Location: edit.php?pollID=$pollID&widgetID=$wID&optionID={$option->ID}");
237  }else if( (!isset($_POST["save_poll"])) AND (!isset($_POST["apply_poll"])) ){
238  header("Location: edit.php?pollID=$pollID&widgetID=$wID");
239  // polls
240  }else{
241  header("Location: edit.php?pollID=$pollID");
242  }
243 }
244 
245 ?>