MDL-21845 user profile: Fixed missing multilang support
[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
84973212 35if ($id) {
36 if (! $cm = get_coursemodule_from_id('feedback', $id)) {
37 print_error('invalidcoursemodule');
c70ad9f7 38 }
d4b1d58c 39
84973212 40 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
41 print_error('coursemisconf');
c70ad9f7 42 }
43
84973212 44 if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
45 print_error('invalidcoursemodule');
c70ad9f7 46 }
84973212 47}
48$capabilities = feedback_load_capabilities($cm->id);
49
50require_login($course->id, true, $cm);
51
52if(!$capabilities->edititems){
53 print_error('error');
54}
55
56//move up/down items
57if($moveupitem){
58 $item = $DB->get_record('feedback_item', array('id'=>$moveupitem));
59 feedback_moveup_item($item);
60}
61if($movedownitem){
62 $item = $DB->get_record('feedback_item', array('id'=>$movedownitem));
63 feedback_movedown_item($item);
64}
65
66//moving of items
67if($movehere && isset($SESSION->feedback->moving->movingitem)){
68 $item = $DB->get_record('feedback_item', array('id'=>$SESSION->feedback->moving->movingitem));
69 feedback_move_item($item, intval($movehere));
70 $moveitem = false;
71}
72if($moveitem){
73 $item = $DB->get_record('feedback_item', array('id'=>$moveitem));
74 $SESSION->feedback->moving->shouldmoving = 1;
75 $SESSION->feedback->moving->movingitem = $moveitem;
76} else {
77 unset($SESSION->feedback->moving);
78}
79
80if($switchitemrequired) {
81 $item = $DB->get_record('feedback_item', array('id'=>$switchitemrequired));
82 @feedback_switch_item_required($item);
5dee2210 83 redirect($url->out(false));
84973212 84 exit;
85}
86
87//the create_template-form
88$create_template_form = new feedback_edit_create_template_form();
89$create_template_form->set_feedbackdata(array('capabilities' => $capabilities));
90$create_template_form->set_form_elements();
91$create_template_form->set_data(array('id'=>$id, 'do_show'=>'templates'));
92$create_template_formdata = $create_template_form->get_data();
93if(isset($create_template_formdata->savetemplate) && $create_template_formdata->savetemplate == 1) {
94 //check the capabilities to create templates
95 if(!$capabilities->createprivatetemplate AND !$capabilities->createpublictemplate) {
96 print_error('cannotsavetempl', 'feedback');
c70ad9f7 97 }
84973212 98 if(trim($create_template_formdata->templatename) == '')
99 {
100 $savereturn = 'notsaved_name';
101 }else {
102 if($capabilities->createpublictemplate) {
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
189 if($capabilities->createprivatetemplate OR $capabilities->createpublictemplate) {
5dee2210 190 $deleteurl = new moodle_url('/mod/feedback/delete_template.php', array('id'=>$id));
84973212 191 $create_template_form->display();
5dee2210 192 echo '<p><a href="'.$deleteurl->out().'">'.get_string('delete_templates', 'feedback').'</a></p>';
84973212 193 }else {
194 echo '&nbsp;';
ab5bd34d 195 }
c70ad9f7 196
84973212 197 if($capabilities->edititems) {
5dee2210
AG
198 $exporturl = new moodle_url('/mod/feedback/export.php', array('action'=>'exportfile', 'id'=>$id));
199 $importurl = new moodle_url('/mod/feedback/import.php', array('id'=>$id));
84973212 200 echo '<p>
5dee2210
AG
201 <a href="'.$exporturl->out().'">'.get_string('export_questions', 'feedback').'</a>/
202 <a href="'.$importurl->out().'">'.get_string('import_questions', 'feedback').'</a>
84973212 203 </p>';
c70ad9f7 204 }
84973212 205 echo $OUTPUT->box_end();
206}
207///////////////////////////////////////////////////////////////////////////
208///print the Item-Edit-section
209///////////////////////////////////////////////////////////////////////////
210if($do_show == 'edit') {
d4b1d58c 211
84973212 212 $add_item_form->display();
c70ad9f7 213
84973212 214 if(is_array($feedbackitems)){
215 $itemnr = 0;
d4b1d58c 216
4bcc5118 217 $helpbutton = $OUTPUT->help_icon('preview', get_string('preview','feedback'), 'feedback',true);
d4b1d58c 218
84973212 219 echo $OUTPUT->heading($helpbutton . get_string('preview', 'feedback'));
220 if(isset($SESSION->feedback->moving) AND $SESSION->feedback->moving->shouldmoving == 1) {
a6855934 221 echo $OUTPUT->heading('<a href="edit.php?id='.$id.'">'.get_string('cancel_moving', 'feedback').'</a>');
c70ad9f7 222 }
84973212 223 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
c70ad9f7 224
84973212 225 //check, if there exists required-elements
226 $countreq = $DB->count_records('feedback_item', array('feedback'=>$feedback->id, 'required'=> 1));
227 if($countreq > 0) {
228 // echo '<font color="red">(*)' . get_string('items_are_required', 'feedback') . '</font>';
229 echo '<span class="feedback_required_mark">(*)' . get_string('items_are_required', 'feedback') . '</span>';
c70ad9f7 230 }
c70ad9f7 231
84973212 232 echo '<table>';
233 if(isset($SESSION->feedback->moving) AND $SESSION->feedback->moving->shouldmoving == 1) {
234 $moveposition = 1;
5dee2210 235 $movehereurl = new moodle_url($url, array('movehere'=>$moveposition));
84973212 236 echo '<tr>'; //only shown if shouldmoving = 1
237 echo '<td>';
5dee2210 238 $buttonlink = $movehereurl->out();
84973212 239 echo '<a title="'.get_string('move_here','feedback').'" href="'.$buttonlink.'">
b5d0cafc 240 <img class="movetarget" alt="'.get_string('move_here','feedback').'" src="'.$OUTPUT->pix_url('movehere') . '" />
84973212 241 </a>';
d4b1d58c 242
a6855934 243 // echo '<form action="edit.php" method="post"><fieldset>';
b5d0cafc 244 // echo '<input title="'.get_string('move_here','feedback').'" type="image" src="'.$OUTPUT->pix_url('movehere') . '" hspace="1" height="16" width="80" border="0" />';
84973212 245 // echo '<input type="hidden" name="movehere" value="'.$moveposition.'" />';
246 // feedback_edit_print_default_form_values($id, $do_show);
247 // echo '</fieldset></form>';
248 echo '</td>';
249 echo '</tr>';
250 }
251 //print the inserted items
252 $itempos = 0;
253 foreach($feedbackitems as $feedbackitem){
254 $itempos++;
255 if(isset($SESSION->feedback->moving) AND $SESSION->feedback->moving->movingitem == $feedbackitem->id){ //hiding the item to move
256 continue;
c70ad9f7 257 }
84973212 258 echo '<tr>';
259 //items without value only are labels
260 if($feedbackitem->hasvalue == 1 AND $feedback->autonumbering) {
261 $itemnr++;
262 echo '<td valign="top">' . $itemnr . '.&nbsp;</td>';
263 } else {
264 echo '<td>&nbsp;</td>';
c70ad9f7 265 }
84973212 266 if($feedbackitem->typ != 'pagebreak') {
267 feedback_print_item($feedbackitem, false, false, true);
268 }else {
269 echo '<td class="feedback_pagebreak"><b>'.get_string('pagebreak', 'feedback').'</b></td><td><hr width="100%" size="8px" noshade="noshade" /></td>';
270 }
271 echo '<td>('.get_string('position', 'feedback').':'.$itempos .')</td>';
272 echo '<td>';
273 if($feedbackitem->position > 1){
5dee2210
AG
274 $moveupurl = new moodle_url($url, array('moveupitem'=>$feedbackitem->id));
275 $buttonlink = $moveupurl->out();
84973212 276 echo '<a class="icon up" title="'.get_string('moveup_item','feedback').'" href="'.$buttonlink.'">
b5d0cafc 277 <img alt="'.get_string('moveup_item','feedback').'" src="'.$OUTPUT->pix_url('t/up') . '" />
84973212 278 </a>';
279 //print the button to move-up the item
a6855934 280 // echo '<form action="edit.php" method="post"><fieldset>';
b5d0cafc
PS
281 // ///////echo '<input title="'.get_string('moveup_item','feedback').'" type="image" src="'.$OUTPUT->pix_url('t/up') . '" hspace="1" height="11" width="11" border="0" />';
282 // echo '<input class="feedback_moveup_button" title="'.get_string('moveup_item','feedback').'" type="image" src="'.$OUTPUT->pix_url('t/up') . '" />';
84973212 283 // echo '<input type="hidden" name="moveupitem" value="'.$feedbackitem->id.'" />';
284 // feedback_edit_print_default_form_values($id, $do_show);
285 // echo '</fieldset></form>';
286 }else{
287 echo '&nbsp;';
288 }
289 echo '</td>';
290 echo '<td>';
291 if($feedbackitem->position < $lastposition - 1){
5dee2210
AG
292 $movedownurl = new moodle_url($url, array('movedownitem'=>$feedbackitem->id));
293 $buttonlink = $movedownurl->out();
84973212 294 echo '<a class="icon down" title="'.get_string('movedown_item','feedback').'" href="'.$buttonlink.'">
b5d0cafc 295 <img alt="'.get_string('movedown_item','feedback').'" src="'.$OUTPUT->pix_url('t/down') . '" />
84973212 296 </a>';
297 //print the button to move-down the item
a6855934 298 // echo '<form action="edit.php" method="post"><fieldset>';
b5d0cafc
PS
299 // echo '<input title="'.get_string('movedown_item','feedback').'" type="image" src="'.$OUTPUT->pix_url('t/down') . '" hspace="1" height="11" width="11" border="0" />';
300 // echo '<input class="feedback_movedown_button" title="'.get_string('movedown_item','feedback').'" type="image" src="'.$OUTPUT->pix_url('t/down') . '" />';
84973212 301 // echo '<input type="hidden" name="movedownitem" value="'.$feedbackitem->id.'" />';
302 // feedback_edit_print_default_form_values($id, $do_show);
303 // echo '</fieldset></form>';
304 }else{
305 echo '&nbsp;';
306 }
307 echo '</td>';
308 echo '<td>';
5dee2210
AG
309 $moveurl = new moodle_url($url, array('moveitem'=>$feedbackitem->id));
310 $buttonlink = $moveurl->out();
84973212 311 echo '<a class="editing_move" title="'.get_string('move_item','feedback').'" href="'.$buttonlink.'">
b5d0cafc 312 <img alt="'.get_string('move_item','feedback').'" src="'.$OUTPUT->pix_url('t/move') . '" />
84973212 313 </a>';
a6855934 314 // echo '<form action="edit.php" method="post"><fieldset>';
b5d0cafc
PS
315 // echo '<input title="'.get_string('move_item','feedback').'" type="image" src="'.$OUTPUT->pix_url('t/move') . '" hspace="1" height="11" width="11" border="0" />';
316 // echo '<input class="feedback_move_button" title="'.get_string('move_item','feedback').'" type="image" src="'.$OUTPUT->pix_url('t/move') . '" />';
84973212 317 // echo '<input type="hidden" name="moveitem" value="'.$feedbackitem->id.'" />';
318 // feedback_edit_print_default_form_values($id, $do_show);
319 // echo '</fieldset></form>';
320 echo '</td>';
321 echo '<td>';
322 //print the button to edit the item
323 if($feedbackitem->typ != 'pagebreak') {
5dee2210
AG
324 $editurl = new moodle_url('/mod/feedback/edit_item.php');
325 $editurl->params(array('do_show'=>$do_show,
326 'cmid'=>$id,
327 'id'=>$feedbackitem->id,
328 'typ'=>$feedbackitem->typ));
329
d5e51c5a 330 // in edit_item.php the param id is used for the itemid and the cmid is the id to get the module
5dee2210 331 $buttonlink = $editurl->out();
84973212 332 echo '<a class="editing_update" title="'.get_string('edit_item','feedback').'" href="'.$buttonlink.'">
b5d0cafc 333 <img alt="'.get_string('edit_item','feedback').'" src="'.$OUTPUT->pix_url('t/edit') . '" />
84973212 334 </a>';
335 // echo '<form action="edit_item.php" method="post"><fieldset>';
b5d0cafc
PS
336 // echo '<input title="'.get_string('edit_item','feedback').'" type="image" src="'.$OUTPUT->pix_url('t/edit') . '" hspace="1" height="11" width="11" border="0" />';
337 // echo '<input class="feedback_edit_button" title="'.get_string('edit_item','feedback').'" type="image" src="'.$OUTPUT->pix_url('t/edit') . '" />';
84973212 338 // echo '<input type="hidden" name="itemid" value="'.$feedbackitem->id.'" />';
339 // echo '<input type="hidden" name="typ" value="'.$feedbackitem->typ.'" />';
340 // feedback_edit_print_default_form_values($id, $do_show);
341 // echo '</fieldset></form>';
342 }else {
343 echo '&nbsp;';
344 }
345 echo '</td>';
346 echo '<td>';
347
348 //print the toggle-button to switch required yes/no
349 if($feedbackitem->hasvalue == 1) {
a6855934 350 // echo '<form action="edit.php" method="post"><fieldset>';
84973212 351 if($feedbackitem->required == 1) {
352 // 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" />';
353 // echo '<input class="feedback_required_button" title="'.get_string('switch_item_to_not_required','feedback').'" type="image" src="pics/required.gif" />';
354 $buttontitle = get_string('switch_item_to_not_required','feedback');
355 $buttonimg = 'pics/required.gif';
356 } else {
357 // echo '<input title="'.get_string('switch_item_to_required','feedback').'" type="image" src="pics/notrequired.gif" hspace="1" height="11" width="11" border="0" />';
358 // echo '<input class="feedback_required_button" title="'.get_string('switch_item_to_required','feedback').'" type="image" src="pics/notrequired.gif" />';
359 $buttontitle = get_string('switch_item_to_required','feedback');
360 $buttonimg = 'pics/notrequired.gif';
361 }
5dee2210
AG
362 $requiredurl = new moodle_url($url, array('switchitemrequired'=>$feedbackitem->id));
363 $buttonlink = $requiredurl->out();
84973212 364 echo '<a class="icon feedback_switchrequired" title="'.$buttontitle.'" href="'.$buttonlink.'">
365 <img alt="'.$buttontitle.'" src="'.$buttonimg.'" />
366 </a>';
367 // echo '<input type="hidden" name="switchitemrequired" value="'.$feedbackitem->id.'" />';
368 // feedback_edit_print_default_form_values($id, $do_show);
369 // echo '</fieldset></form>';
370 }else {
371 echo '&nbsp;';
372 }
373 echo '</td>';
374 echo '<td>';
5dee2210
AG
375 $deleteitemurl = new moodle_url('/mod/feedback/delete_item.php');
376 $deleteitemurl->params(array('id'=>$id,
377 'do_show'=>$do_show,
378 'deleteitem'=>$feedbackitem->id));
379
380 $buttonlink = $deleteitemurl->out();
84973212 381 echo '<a class="icon delete" title="'.get_string('delete_item','feedback').'" href="'.$buttonlink.'">
b5d0cafc 382 <img alt="'.get_string('delete_item','feedback').'" src="'.$OUTPUT->pix_url('t/delete') . '" />
84973212 383 </a>';
384 //print the button to drop the item
385 // echo '<form action="delete_item.php" method="post"><fieldset>';
b5d0cafc 386 // echo '<input class="feedback_delete_button" title="'.get_string('delete_item','feedback').'" type="image" src="'.$OUTPUT->pix_url('t/delete') . '" />';
84973212 387 // echo '<input type="hidden" name="deleteitem" value="'.$feedbackitem->id.'" />';
388 // feedback_edit_print_default_form_values($id, $do_show);
389 // echo '</fieldset></form>';
390 echo '</td>';
391 echo '</tr>';
c70ad9f7 392 if(isset($SESSION->feedback->moving) AND $SESSION->feedback->moving->shouldmoving == 1) {
84973212 393 $moveposition++;
5dee2210 394 $movehereurl->param('movehere', $moveposition);
c70ad9f7 395 echo '<tr>'; //only shown if shouldmoving = 1
396 echo '<td>';
5dee2210 397 $buttonlink = $movehereurl->out();
84973212 398 echo '<a title="'.get_string('move_here','feedback').'" href="'.$buttonlink.'">
b5d0cafc 399 <img class="movetarget" alt="'.get_string('move_here','feedback').'" src="'.$OUTPUT->pix_url('movehere') . '" />
84973212 400 </a>';
a6855934 401 // echo '<form action="edit.php" method="post"><fieldset>';
b5d0cafc 402 // echo '<input class="feedback_movehere_button" title="'.get_string('move_here','feedback').'" type="image" src="'.$OUTPUT->pix_url('movehere') . '" />';
c70ad9f7 403 // echo '<input type="hidden" name="movehere" value="'.$moveposition.'" />';
404 // feedback_edit_print_default_form_values($id, $do_show);
405 // echo '</fieldset></form>';
406 echo '</td>';
407 echo '</tr>';
84973212 408 }else {
409 echo '<tr><td>&nbsp;</td></tr>';
c70ad9f7 410 }
d4b1d58c 411
c70ad9f7 412 }
84973212 413 echo '</table>';
414 echo $OUTPUT->box_end();
415 }else{
416 echo $OUTPUT->box(get_string('no_items_available_yet','feedback'),'generalbox boxaligncenter');
c70ad9f7 417 }
84973212 418}
419/// Finish the page
420///////////////////////////////////////////////////////////////////////////
421///////////////////////////////////////////////////////////////////////////
422///////////////////////////////////////////////////////////////////////////
c70ad9f7 423
84973212 424echo $OUTPUT->footer();