Umfragen
action.option.php
Go to the documentation of this file.
1 <?php
2 /*
3  * backend/action.option.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 
42 require_once("../config.php");
43 require_once("../inc/user.class.php");
44 require_once("../inc/tools.php");
45 
46 require_once("../inc/check_login.php");
47 require_once("../inc/db.class.php");
48 require_once("../inc/config.class.php");
49 require_once("../inc/html.class.php");
50 require_once("../inc/poll.class.php");
51 require_once("../inc/messages.class.php");
52 $db= new db( DB_USER, DB_PASS, DB_DATABASE, DB_HOST );
54 $config->load();
55 
57 
58 // SESSION
59 make_session();
60 
61 // LOAD POLL
63 // check if poll loaded
64 if( !$r instanceof poll ){
65  die($r);
66 }else{
67  $poll = $r;
68 }
69 unset($r);
70 
71 // load widget
72 $r = load_widget_from_http_request($poll,"GET");
73 if( !$r instanceof widget ){
74  die($r);
75 }else{
76  $widget = $r;
77 }
78 unset($r);
79 
80 // load option
81 if( (isset($_GET["optionID"])) AND ($_GET["optionID"] != "") AND ( is_numeric($_GET["optionID"]) ) AND (isset($widget) ) ){
82  $optionID = intval($_GET["optionID"]);
83  // when adding a option the ID given is the widget ID
84  if( ($optionID == $widget->ID) AND ( isset($_GET["action"]) ) AND ($_GET["action"] == "add") ){
85  $option = $widget;
86  }else if ( ($optionID == $widget->ID) AND ( isset($_GET["action"]) ) AND ($_GET["action"] == "addq") ){
87  $option = $widget;
88  }else{
89  $option = $widget->get_option_by_id($optionID);
90  if( !isset($option) ){
91  $option = $widget->get_widget_by_id($optionID);
92  }
93  }
94  if( !isset($option) ){
95  $messages->add_message( new errorMessage("Option $optionID der Frage {$widget->ID} der Umfrage {$poll->ID} existiert leider nicht ... ") );
96  }
97 }
98 
99 
100 
101 
102 /*****************
103  * PERMISSIONS
104  *****************/
105 check_login();
106 // edit needs ownership or admin rights
107 if( (intval($_SESSION["user"]->ID) !== intval($poll->owner) ) AND
108  ( !in_array("{$_SESSION["user"]->ID}",explode(",",SUPER_ADMIN) )) ){
109  die("Umfrage Bearbeiten nicht erlaubt.");
110 }
111 
112 
113 
115 
116 if( ($messages->iserr()) === false){
117 
118  if( isset($_GET["action"]) ){
119  /*----------------
120  * OPTIONS
121  *---------------*/
122  // add option
123  if( $_GET["action"] == "add"){
124  if( $widget instanceof radioButtonList ){
125  $new_option = new radioButton();
126  }else if( $widget instanceof checkBoxList ){
127  $new_option = new checkBox();
128  }else if( $widget instanceof matrix ){
129  $new_option = new matrixOption();
130  }else{
131  $err_reason = "Ungültiger Widgettyp";
132  }
133 
134  if( ($err_reason == "") AND ($option->ID != $widget->ID) ){
135  $widget->insert_option($option->index,$new_option);
136  if( !($widget instanceof matrix) ){
137  $new_option->set_dispName("Option{$new_option->index}");
138  }else{
139  $new_option->set_dispName("");
140  }
141  $new_option->set_value("Option{$new_option->index}");
142  $db->insert_widget($new_option,$poll->type);
143  $widget->save_option_list($db);
144  $_SESSION["last_option_edit"] = $new_option->ID;
145  }else if( ($err_reason == "") AND ($option->ID == $widget->ID) ){
146  $widget->insert_option(-1,$new_option);
147  if( !($widget instanceof matrix) ){
148  $new_option->set_dispName("Option{$new_option->index}");
149  }else{
150  $new_option->set_dispName("");
151  }
152  $new_option->set_value("Option{$new_option->index}");
153  $db->insert_widget($new_option,$poll->type);
154  $widget->save_option_list($db);
155  $_SESSION["last_option_edit"] = $new_option->ID;
156  }
157 
158  // delete option
159  }else if( $_GET["action"] == "rm" ){
160  $widget->delete_option($db,$option->ID);
161  // move up option
162  }else if( $_GET["action"] == "mvup" ){
163  $widget->move_option($db,$option->index,$option->index-1);
164  $_SESSION["last_option_edit"] = $option->ID;
165  // move down option
166  }else if( $_GET["action"] == "mvdwn" ){
167  $widget->move_option($db,$option->index,$option->index+1);
168  $_SESSION["last_option_edit"] = $option->ID;
169 
170  /*----------------
171  * WIDGET
172  *---------------*/
173  // add widget
174  }else if( $_GET["action"] == "addq"){
175  if( $widget instanceof matrix ){
176  $new_option = new matrixQuestion();
177 
178  }else if ($widget instanceof textExt){
179  if( (isset($_GET["type"])) AND ($_GET["type"] == "text") ){
180  $new_option = new text();
181  }else if( (isset($_GET["type"])) AND ($_GET["type"] == "labelTiny") ){
182  $new_option = new labelTiny();
183  }else{
184  $err_reason = "Ungültiger Widgettyp";
185  }
186  }else if( $widget instanceof label){
187  $new_option = new label();
188  }else if( $widget instanceof schedule){
189  $new_option = new scheduleDate();
190  }else{
191  $err_reason = "Ungültiger Widgettyp";
192  }
193 
194  if($err_reason == ""){
195  if($option->ID != $widget->ID){
196  $widget->insert_widget($option->index,$new_option);
197  }else{
198  $widget->insert_widget(-1,$new_option);
199  }/*
200  if( $widget instanceof textExt ){
201  $new_option->set_default_values($db);
202  }else{
203  $new_option->set_dispName("Option{$new_option->index}");
204  }*/
205  $new_option->set_default_values($db);
206  $db->insert_widget($new_option,$poll->type);
207  $widget->save_widget_list($db);
208  // clean up result table
209  $db->garbage_collect_result_table($poll);
210  $_SESSION["last_option_edit"] = $new_option->ID;
211  }
212 
213  // remove widget
214  }else if( $_GET["action"] == "rmq" ){
215  $widget->delete_widget($db,$option->ID);
216  // clean up result table
217  $db->garbage_collect_result_table($poll);
218  // move widget up
219  }else if( $_GET["action"] == "mvupq" ){
220  $widget->move_widget($db,$option->index,$option->index-1);
221  $_SESSION["last_option_edit"] = $option->ID;
222  // move widget down
223  }else if( $_GET["action"] == "mvdwnq" ){
224  $widget->move_widget($db,$option->index,$option->index+1);
225  $_SESSION["last_option_edit"] = $option->ID;
226  }
227 
228  } // end action
229 
230 } // end if err_reason
231 
232 
233 if($err_reason != ""){
234  $messages->add_message( new errorMessage($err_reason) );
235 }
236 
237 header("Location: edit.php?pollID={$poll->ID}&widgetID={$widget->ID}");
238 
239 ?>
240