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