MDL-19806 Converted print_box* to $OUTPUT->box*
[moodle.git] / mod / feedback / edit.php
CommitLineData
c70ad9f7 1<?php // $Id$
2/**
3* prints the form to edit the feedback items such moving, deleting and so on
4*
5* @version $Id$
6* @author Andreas Grabs
7* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8* @package feedback
9*/
10
11 require_once("../../config.php");
12 require_once("lib.php");
13 require_once('edit_form.php');
14
15 $id = required_param('id', PARAM_INT);
16
294ce987 17 if(($formdata = data_submitted()) AND !confirm_sesskey()) {
5d2edd1c 18 print_error('invalidsesskey');
c70ad9f7 19 }
20
21 $do_show = optional_param('do_show', 'edit', PARAM_ALPHA);
22 $moveupitem = optional_param('moveupitem', false, PARAM_INT);
23 $movedownitem = optional_param('movedownitem', false, PARAM_INT);
24 $moveitem = optional_param('moveitem', false, PARAM_INT);
25 $movehere = optional_param('movehere', false, PARAM_INT);
26 $switchitemrequired = optional_param('switchitemrequired', false, PARAM_INT);
b7a47958 27
28 $ME = strip_querystring($FULLME);//sometimes it is not correct set
c70ad9f7 29
30 // $SESSION->feedback->current_tab = $do_show;
31 $current_tab = $do_show;
32
33 if ($id) {
34 if (! $cm = get_coursemodule_from_id('feedback', $id)) {
5d2edd1c 35 print_error('invalidcoursemodule');
c70ad9f7 36 }
37
0085fff8 38 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
5d2edd1c 39 print_error('coursemisconf');
c70ad9f7 40 }
41
0085fff8 42 if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
5d2edd1c 43 print_error('invalidcoursemodule');
c70ad9f7 44 }
45 }
46 $capabilities = feedback_load_capabilities($cm->id);
47
6178c62a 48 require_login($course->id, true, $cm);
c70ad9f7 49
50 if(!$capabilities->edititems){
5d2edd1c 51 print_error('error');
c70ad9f7 52 }
53
54 //move up/down items
55 if($moveupitem){
0085fff8 56 $item = $DB->get_record('feedback_item', array('id'=>$moveupitem));
c70ad9f7 57 feedback_moveup_item($item);
58 }
59 if($movedownitem){
0085fff8 60 $item = $DB->get_record('feedback_item', array('id'=>$movedownitem));
c70ad9f7 61 feedback_movedown_item($item);
62 }
63
64 //moving of items
65 if($movehere && isset($SESSION->feedback->moving->movingitem)){
0085fff8 66 $item = $DB->get_record('feedback_item', array('id'=>$SESSION->feedback->moving->movingitem));
c70ad9f7 67 feedback_move_item($item, intval($movehere));
b7a47958 68 $moveitem = false;
c70ad9f7 69 }
70 if($moveitem){
0085fff8 71 $item = $DB->get_record('feedback_item', array('id'=>$moveitem));
c70ad9f7 72 $SESSION->feedback->moving->shouldmoving = 1;
73 $SESSION->feedback->moving->movingitem = $moveitem;
74 } else {
75 unset($SESSION->feedback->moving);
76 }
77
78 if($switchitemrequired) {
0085fff8 79 $item = $DB->get_record('feedback_item', array('id'=>$switchitemrequired));
c70ad9f7 80 @feedback_switch_item_required($item);
81 redirect($ME.'?'.feedback_edit_get_default_query($id, $do_show));
82 exit;
83 }
84
85 //the create_template-form
86 $create_template_form = new feedback_edit_create_template_form();
87 $create_template_form->set_feedbackdata(array('capabilities' => $capabilities));
88 $create_template_form->set_form_elements();
89 $create_template_form->set_data(array('id'=>$id, 'do_show'=>'templates'));
90 $create_template_formdata = $create_template_form->get_data();
91 if(isset($create_template_formdata->savetemplate) && $create_template_formdata->savetemplate == 1) {
92 //check the capabilities to create templates
93 if(!$capabilities->createprivatetemplate AND !$capabilities->createpublictemplate) {
5d2edd1c 94 print_error('cannotsavetempl', 'feedback');
c70ad9f7 95 }
96 if(trim($create_template_formdata->templatename) == '')
97 {
98 $savereturn = 'notsaved_name';
99 }else {
100 if($capabilities->createpublictemplate) {
101 $create_template_formdata->ispublic = isset($create_template_formdata->ispublic) ? 1 : 0;
102 }else {
103 $create_template_formdata->ispublic = 0;
104 }
105 if(!feedback_save_as_template($feedback, $create_template_formdata->templatename, $create_template_formdata->ispublic))
106 {
107 $savereturn = 'failed';
108 }else {
109 $savereturn = 'saved';
110 }
111 }
112 }
113
114 //get the feedbackitems
115 $lastposition = 0;
0085fff8 116 $feedbackitems = $DB->get_records('feedback_item', array('feedback'=>$feedback->id), 'position');
c70ad9f7 117 if(is_array($feedbackitems)){
118 $feedbackitems = array_values($feedbackitems);
b9fb72f7 119 if(count($feedbackitems) > 0) {
120 $lastitem = $feedbackitems[count($feedbackitems)-1];
121 $lastposition = $lastitem->position;
122 }else {
123 $lastposition = 0;
124 }
c70ad9f7 125 }
126 $lastposition++;
127
128
129 //the add_item-form
130 $add_item_form = new feedback_edit_add_question_form('edit_item.php');
131 $add_item_form->set_data(array('id'=>$id, 'position'=>$lastposition));
132
133 //the use_template-form
134 $use_template_form = new feedback_edit_use_template_form('use_templ.php');
135 $use_template_form->set_feedbackdata(array('course' => $course));
136 $use_template_form->set_form_elements();
137 $use_template_form->set_data(array('id'=>$id));
138
139 //the create_template-form
140 //$create_template_form = new feedback_edit_create_template_form('use_templ.php');
141
142 /// Print the page header
143 $strfeedbacks = get_string("modulenameplural", "feedback");
144 $strfeedback = get_string("modulename", "feedback");
145 $buttontext = update_module_button($cm->id, $course->id, $strfeedback);
146
147 $navlinks = array();
148 $navlinks[] = array('name' => $strfeedbacks, 'link' => "index.php?id=$course->id", 'type' => 'activity');
149 $navlinks[] = array('name' => format_string($feedback->name), 'link' => "", 'type' => 'activityinstance');
150
151 $navigation = build_navigation($navlinks);
152
153 print_header_simple(format_string($feedback->name), "",
154 $navigation, "", "", true, $buttontext, navmenu($course, $cm));
155
156 /// print the tabs
157 include('tabs.php');
158
159 /// Print the main part of the page
160 ///////////////////////////////////////////////////////////////////////////
161 ///////////////////////////////////////////////////////////////////////////
162 ///////////////////////////////////////////////////////////////////////////
163
164 $savereturn=isset($savereturn)?$savereturn:'';
165
166 //print the messages
167 if($savereturn == 'notsaved_name') {
168 echo '<p align="center"><b><font color="red">'.get_string('name_required','feedback').'</font></b></p>';
169 }
170
171 if($savereturn == 'saved') {
172 echo '<p align="center"><b><font color="green">'.get_string('template_saved','feedback').'</font></b></p>';
173 }
174
175 if($savereturn == 'failed') {
176 echo '<p align="center"><b><font color="red">'.get_string('saving_failed','feedback').'</font></b></p>';
177 }
178
179 feedback_print_errors();
180
181 ///////////////////////////////////////////////////////////////////////////
182 ///print the template-section
183 ///////////////////////////////////////////////////////////////////////////
184 if($do_show == 'templates') {
185 // print_simple_box_start("center", '80%');
186 print_box_start('generalbox boxaligncenter boxwidthwide');
187 $use_template_form->display();
188
189 if($capabilities->createprivatetemplate OR $capabilities->createpublictemplate) {
190 $create_template_form->display();
191 echo '<p><a href="'.htmlspecialchars('delete_template.php?id='.$id).'">'.get_string('delete_templates', 'feedback').'</a></p>';
192 }else {
193 echo '&nbsp;';
194 }
195
196 if($capabilities->edititems) {
197 echo '<p>
198 <a href="'.htmlspecialchars('export.php?action=exportfile&id='.$id).'">'.get_string('export_questions', 'feedback').'</a>/
199 <a href="'.htmlspecialchars('import.php?id='.$id).'">'.get_string('import_questions', 'feedback').'</a>
200 </p>';
201 }
202 // print_simple_box_end();
203 print_box_end();
204 }
205 ///////////////////////////////////////////////////////////////////////////
206 ///print the Item-Edit-section
207 ///////////////////////////////////////////////////////////////////////////
208 if($do_show == 'edit') {
209
210 $add_item_form->display();
211
212 if(is_array($feedbackitems)){
213 $itemnr = 0;
214
215 $helpbutton = helpbutton('preview', get_string('preview','feedback'), 'feedback',true,false,'',true);
216
53b1f5da 217 echo $OUTPUT->heading($helpbutton . get_string('preview', 'feedback'));
c70ad9f7 218 if(isset($SESSION->feedback->moving) AND $SESSION->feedback->moving->shouldmoving == 1) {
53b1f5da 219 echo $OUTPUT->heading('<a href="'.htmlspecialchars($ME.'?id='.$id).'">'.get_string('cancel_moving', 'feedback').'</a>');
c70ad9f7 220 }
221 // print_simple_box_start('center', '80%');
222 print_box_start('generalbox boxaligncenter boxwidthwide');
223
224 //check, if there exists required-elements
7e29e800 225 $countreq = $DB->count_records('feedback_item', array('feedback'=>$feedback->id, 'required'=> 1));
c70ad9f7 226 if($countreq > 0) {
227 // echo '<font color="red">(*)' . get_string('items_are_required', 'feedback') . '</font>';
228 echo '<span class="feedback_required_mark">(*)' . get_string('items_are_required', 'feedback') . '</span>';
229 }
230
231 echo '<table>';
232 if(isset($SESSION->feedback->moving) AND $SESSION->feedback->moving->shouldmoving == 1) {
233 $moveposition = 1;
234 echo '<tr>'; //only shown if shouldmoving = 1
235 echo '<td>';
236 $buttonlink = $ME.'?'.htmlspecialchars(feedback_edit_get_default_query($id, $do_show).'&movehere='.$moveposition);
237 echo '<a title="'.get_string('move_here','feedback').'" href="'.$buttonlink.'">
e63f88c9 238 <img class="movetarget" alt="'.get_string('move_here','feedback').'" src="'.$OUTPUT->old_icon_url('movehere') . '" />
c70ad9f7 239 </a>';
240
241 // echo '<form action="'.$ME.'" method="post"><fieldset>';
e63f88c9 242 // echo '<input title="'.get_string('move_here','feedback').'" type="image" src="'.$OUTPUT->old_icon_url('movehere') . '" hspace="1" height="16" width="80" border="0" />';
c70ad9f7 243 // echo '<input type="hidden" name="movehere" value="'.$moveposition.'" />';
244 // feedback_edit_print_default_form_values($id, $do_show);
245 // echo '</fieldset></form>';
246 echo '</td>';
247 echo '</tr>';
248 }
249 //print the inserted items
250 $itempos = 0;
251 foreach($feedbackitems as $feedbackitem){
252 $itempos++;
253 if(isset($SESSION->feedback->moving) AND $SESSION->feedback->moving->movingitem == $feedbackitem->id){ //hiding the item to move
254 continue;
255 }
256 echo '<tr>';
257 //items without value only are labels
efc59167 258 if($feedbackitem->hasvalue == 1 AND $feedback->autonumbering) {
c70ad9f7 259 $itemnr++;
efc59167 260 echo '<td valign="top">' . $itemnr . '.&nbsp;</td>';
c70ad9f7 261 } else {
262 echo '<td>&nbsp;</td>';
263 }
264 if($feedbackitem->typ != 'pagebreak') {
265 feedback_print_item($feedbackitem, false, false, true);
266 }else {
267 echo '<td class="feedback_pagebreak"><b>'.get_string('pagebreak', 'feedback').'</b></td><td><hr width="100%" size="8px" noshade="noshade" /></td>';
268 }
269 echo '<td>('.get_string('position', 'feedback').':'.$itempos .')</td>';
270 echo '<td>';
271 if($feedbackitem->position > 1){
272 $buttonlink = $ME.'?'.htmlspecialchars(feedback_edit_get_default_query($id, $do_show).'&moveupitem='.$feedbackitem->id);
273 echo '<a class="icon up" title="'.get_string('moveup_item','feedback').'" href="'.$buttonlink.'">
f2a1963c 274 <img alt="'.get_string('moveup_item','feedback').'" src="'.$OUTPUT->old_icon_url('t/up') . '" />
c70ad9f7 275 </a>';
276 //print the button to move-up the item
277 // echo '<form action="'.$ME.'" method="post"><fieldset>';
f2a1963c 278 // ///////echo '<input title="'.get_string('moveup_item','feedback').'" type="image" src="'.$OUTPUT->old_icon_url('t/up') . '" hspace="1" height="11" width="11" border="0" />';
279 // echo '<input class="feedback_moveup_button" title="'.get_string('moveup_item','feedback').'" type="image" src="'.$OUTPUT->old_icon_url('t/up') . '" />';
c70ad9f7 280 // echo '<input type="hidden" name="moveupitem" value="'.$feedbackitem->id.'" />';
281 // feedback_edit_print_default_form_values($id, $do_show);
282 // echo '</fieldset></form>';
283 }else{
284 echo '&nbsp;';
285 }
286 echo '</td>';
287 echo '<td>';
288 if($feedbackitem->position < $lastposition - 1){
289 $buttonlink = $ME.'?'.htmlspecialchars(feedback_edit_get_default_query($id, $do_show).'&movedownitem='.$feedbackitem->id);
290 echo '<a class="icon down" title="'.get_string('movedown_item','feedback').'" href="'.$buttonlink.'">
f2a1963c 291 <img alt="'.get_string('movedown_item','feedback').'" src="'.$OUTPUT->old_icon_url('t/down') . '" />
c70ad9f7 292 </a>';
293 //print the button to move-down the item
294 // echo '<form action="'.$ME.'" method="post"><fieldset>';
f2a1963c 295 // echo '<input title="'.get_string('movedown_item','feedback').'" type="image" src="'.$OUTPUT->old_icon_url('t/down') . '" hspace="1" height="11" width="11" border="0" />';
296 // echo '<input class="feedback_movedown_button" title="'.get_string('movedown_item','feedback').'" type="image" src="'.$OUTPUT->old_icon_url('t/down') . '" />';
c70ad9f7 297 // echo '<input type="hidden" name="movedownitem" value="'.$feedbackitem->id.'" />';
298 // feedback_edit_print_default_form_values($id, $do_show);
299 // echo '</fieldset></form>';
300 }else{
301 echo '&nbsp;';
302 }
303 echo '</td>';
304 echo '<td>';
305 $buttonlink = $ME.'?'.htmlspecialchars(feedback_edit_get_default_query($id, $do_show).'&moveitem='.$feedbackitem->id);
306 echo '<a class="editing_move" title="'.get_string('move_item','feedback').'" href="'.$buttonlink.'">
f2a1963c 307 <img alt="'.get_string('move_item','feedback').'" src="'.$OUTPUT->old_icon_url('t/move') . '" />
c70ad9f7 308 </a>';
309 // echo '<form action="'.$ME.'" method="post"><fieldset>';
f2a1963c 310 // echo '<input title="'.get_string('move_item','feedback').'" type="image" src="'.$OUTPUT->old_icon_url('t/move') . '" hspace="1" height="11" width="11" border="0" />';
311 // echo '<input class="feedback_move_button" title="'.get_string('move_item','feedback').'" type="image" src="'.$OUTPUT->old_icon_url('t/move') . '" />';
c70ad9f7 312 // echo '<input type="hidden" name="moveitem" value="'.$feedbackitem->id.'" />';
313 // feedback_edit_print_default_form_values($id, $do_show);
314 // echo '</fieldset></form>';
315 echo '</td>';
316 echo '<td>';
317 //print the button to edit the item
318 if($feedbackitem->typ != 'pagebreak') {
319 $buttonlink = 'edit_item.php?'.htmlspecialchars(feedback_edit_get_default_query($id, $do_show).'&itemid='.$feedbackitem->id.'&typ='.$feedbackitem->typ);
320 echo '<a class="editing_update" title="'.get_string('edit_item','feedback').'" href="'.$buttonlink.'">
f2a1963c 321 <img alt="'.get_string('edit_item','feedback').'" src="'.$OUTPUT->old_icon_url('t/edit') . '" />
c70ad9f7 322 </a>';
323 // echo '<form action="edit_item.php" method="post"><fieldset>';
f2a1963c 324 // echo '<input title="'.get_string('edit_item','feedback').'" type="image" src="'.$OUTPUT->old_icon_url('t/edit') . '" hspace="1" height="11" width="11" border="0" />';
325 // echo '<input class="feedback_edit_button" title="'.get_string('edit_item','feedback').'" type="image" src="'.$OUTPUT->old_icon_url('t/edit') . '" />';
c70ad9f7 326 // echo '<input type="hidden" name="itemid" value="'.$feedbackitem->id.'" />';
327 // echo '<input type="hidden" name="typ" value="'.$feedbackitem->typ.'" />';
328 // feedback_edit_print_default_form_values($id, $do_show);
329 // echo '</fieldset></form>';
330 }else {
331 echo '&nbsp;';
332 }
333 echo '</td>';
334 echo '<td>';
335
336 //print the toggle-button to switch required yes/no
337 if($feedbackitem->hasvalue == 1) {
338 // echo '<form action="'.$ME.'" method="post"><fieldset>';
339 if($feedbackitem->required == 1) {
340 // echo '<input title="'.get_string('switch_item_to_not_required','feedback').'" type="image" src="pics/required.gif" hspace="1" height="11" width="11" border="0" />';
341 // echo '<input class="feedback_required_button" title="'.get_string('switch_item_to_not_required','feedback').'" type="image" src="pics/required.gif" />';
342 $buttontitle = get_string('switch_item_to_not_required','feedback');
343 $buttonimg = 'pics/required.gif';
344 } else {
345 // echo '<input title="'.get_string('switch_item_to_required','feedback').'" type="image" src="pics/notrequired.gif" hspace="1" height="11" width="11" border="0" />';
346 // echo '<input class="feedback_required_button" title="'.get_string('switch_item_to_required','feedback').'" type="image" src="pics/notrequired.gif" />';
347 $buttontitle = get_string('switch_item_to_required','feedback');
348 $buttonimg = 'pics/notrequired.gif';
349 }
350 $buttonlink = $ME.'?'.htmlspecialchars(feedback_edit_get_default_query($id, $do_show).'&switchitemrequired='.$feedbackitem->id);
351 echo '<a class="icon feedback_switchrequired" title="'.$buttontitle.'" href="'.$buttonlink.'">
352 <img alt="'.$buttontitle.'" src="'.$buttonimg.'" />
353 </a>';
354 // echo '<input type="hidden" name="switchitemrequired" value="'.$feedbackitem->id.'" />';
355 // feedback_edit_print_default_form_values($id, $do_show);
356 // echo '</fieldset></form>';
357 }else {
358 echo '&nbsp;';
359 }
360 echo '</td>';
361 echo '<td>';
362 $buttonlink = 'delete_item.php?'.htmlspecialchars(feedback_edit_get_default_query($id, $do_show).'&deleteitem='.$feedbackitem->id);
363 echo '<a class="icon delete" title="'.get_string('delete_item','feedback').'" href="'.$buttonlink.'">
f2a1963c 364 <img alt="'.get_string('delete_item','feedback').'" src="'.$OUTPUT->old_icon_url('t/delete') . '" />
c70ad9f7 365 </a>';
366 //print the button to drop the item
367 // echo '<form action="delete_item.php" method="post"><fieldset>';
f2a1963c 368 // echo '<input class="feedback_delete_button" title="'.get_string('delete_item','feedback').'" type="image" src="'.$OUTPUT->old_icon_url('t/delete') . '" />';
c70ad9f7 369 // echo '<input type="hidden" name="deleteitem" value="'.$feedbackitem->id.'" />';
370 // feedback_edit_print_default_form_values($id, $do_show);
371 // echo '</fieldset></form>';
372 echo '</td>';
373 echo '</tr>';
374 if(isset($SESSION->feedback->moving) AND $SESSION->feedback->moving->shouldmoving == 1) {
375 $moveposition++;
376 echo '<tr>'; //only shown if shouldmoving = 1
377 echo '<td>';
378 $buttonlink = $ME.'?'.htmlspecialchars(feedback_edit_get_default_query($id, $do_show).'&movehere='.$moveposition);
379 echo '<a title="'.get_string('move_here','feedback').'" href="'.$buttonlink.'">
e63f88c9 380 <img class="movetarget" alt="'.get_string('move_here','feedback').'" src="'.$OUTPUT->old_icon_url('movehere') . '" />
c70ad9f7 381 </a>';
382 // echo '<form action="'.$ME.'" method="post"><fieldset>';
e63f88c9 383 // echo '<input class="feedback_movehere_button" title="'.get_string('move_here','feedback').'" type="image" src="'.$OUTPUT->old_icon_url('movehere') . '" />';
c70ad9f7 384 // echo '<input type="hidden" name="movehere" value="'.$moveposition.'" />';
385 // feedback_edit_print_default_form_values($id, $do_show);
386 // echo '</fieldset></form>';
387 echo '</td>';
388 echo '</tr>';
389 }else {
390 echo '<tr><td>&nbsp;</td></tr>';
391 }
392
393 }
394 echo '</table>';
395 // print_simple_box_end();
396 print_box_end();
397 }else{
398 // print_simple_box(get_string('no_items_available_yet','feedback'),"center");
399 print_box(get_string('no_items_available_yet','feedback'),'generalbox boxaligncenter');
400 }
401 }
402 /// Finish the page
403 ///////////////////////////////////////////////////////////////////////////
404 ///////////////////////////////////////////////////////////////////////////
405 ///////////////////////////////////////////////////////////////////////////
406
c6ea0876 407 echo $OUTPUT->footer();
c70ad9f7 408
409 function feedback_edit_get_default_query($id, $tab) {
410 global $USER;
411
412 $query = 'id='.$id;
413 $query .= '&do_show='.$tab;
973d2660 414 //$query .= '&sesskey='.sesskey();
c70ad9f7 415
416 return $query;
417 }
418
419 function feedback_edit_print_default_form_values($id, $tab) {
420 global $USER;
421
973d2660 422 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
c70ad9f7 423 echo '<input type="hidden" name="id" value="'.$id.'" />';
424 echo '<input type="hidden" name="do_show" value="'.$tab.'" />';
425 }
426?>