. /** * prints the form to edit the feedback items such moving, deleting and so on * * @author Andreas Grabs * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @package mod_feedback */ require_once('../../config.php'); require_once('lib.php'); require_once('edit_form.php'); feedback_init_feedback_session(); $id = required_param('id', PARAM_INT); if (($formdata = data_submitted()) AND !confirm_sesskey()) { print_error('invalidsesskey'); } $do_show = optional_param('do_show', 'edit', PARAM_ALPHA); $moveupitem = optional_param('moveupitem', false, PARAM_INT); $movedownitem = optional_param('movedownitem', false, PARAM_INT); $moveitem = optional_param('moveitem', false, PARAM_INT); $movehere = optional_param('movehere', false, PARAM_INT); $switchitemrequired = optional_param('switchitemrequired', false, PARAM_INT); $current_tab = $do_show; $url = new moodle_url('/mod/feedback/edit.php', array('id'=>$id, 'do_show'=>$do_show)); if (! $cm = get_coursemodule_from_id('feedback', $id)) { print_error('invalidcoursemodule'); } if (! $course = $DB->get_record('course', array('id'=>$cm->course))) { print_error('coursemisconf'); } if (! $feedback = $DB->get_record('feedback', array('id'=>$cm->instance))) { print_error('invalidcoursemodule'); } $context = context_module::instance($cm->id); require_login($course, true, $cm); require_capability('mod/feedback:edititems', $context); //Move up/down items if ($moveupitem) { $item = $DB->get_record('feedback_item', array('id'=>$moveupitem)); feedback_moveup_item($item); } if ($movedownitem) { $item = $DB->get_record('feedback_item', array('id'=>$movedownitem)); feedback_movedown_item($item); } //Moving of items if ($movehere && isset($SESSION->feedback->moving->movingitem)) { $item = $DB->get_record('feedback_item', array('id'=>$SESSION->feedback->moving->movingitem)); feedback_move_item($item, intval($movehere)); $moveitem = false; } if ($moveitem) { $item = $DB->get_record('feedback_item', array('id'=>$moveitem)); $SESSION->feedback->moving->shouldmoving = 1; $SESSION->feedback->moving->movingitem = $moveitem; } else { unset($SESSION->feedback->moving); } if ($switchitemrequired) { $item = $DB->get_record('feedback_item', array('id'=>$switchitemrequired)); @feedback_switch_item_required($item); redirect($url->out(false)); exit; } //The create_template-form $create_template_form = new feedback_edit_create_template_form(); $create_template_form->set_feedbackdata(array('context'=>$context, 'course'=>$course)); $create_template_form->set_form_elements(); $create_template_form->set_data(array('id'=>$id, 'do_show'=>'templates')); $create_template_formdata = $create_template_form->get_data(); if (isset($create_template_formdata->savetemplate) && $create_template_formdata->savetemplate == 1) { //Check the capabilities to create templates. if (!has_capability('mod/feedback:createprivatetemplate', $context) AND !has_capability('mod/feedback:createpublictemplate', $context)) { print_error('cannotsavetempl', 'feedback'); } if (trim($create_template_formdata->templatename) == '') { $savereturn = 'notsaved_name'; } else { //If the feedback is located on the frontpage then templates can be public. if (has_capability('mod/feedback:createpublictemplate', context_system::instance())) { $create_template_formdata->ispublic = isset($create_template_formdata->ispublic) ? 1 : 0; } else { $create_template_formdata->ispublic = 0; } if (!feedback_save_as_template($feedback, $create_template_formdata->templatename, $create_template_formdata->ispublic)) { $savereturn = 'failed'; } else { $savereturn = 'saved'; } } } //Get the feedbackitems $lastposition = 0; $feedbackitems = $DB->get_records('feedback_item', array('feedback'=>$feedback->id), 'position'); if (is_array($feedbackitems)) { $feedbackitems = array_values($feedbackitems); if (count($feedbackitems) > 0) { $lastitem = $feedbackitems[count($feedbackitems)-1]; $lastposition = $lastitem->position; } else { $lastposition = 0; } } $lastposition++; //The add_item-form $add_item_form = new feedback_edit_add_question_form('edit_item.php'); $add_item_form->set_data(array('cmid'=>$id, 'position'=>$lastposition)); //The use_template-form $use_template_form = new feedback_edit_use_template_form('use_templ.php'); $use_template_form->set_feedbackdata(array('course' => $course)); $use_template_form->set_form_elements(); $use_template_form->set_data(array('id'=>$id)); //Print the page header. $strfeedbacks = get_string('modulenameplural', 'feedback'); $strfeedback = get_string('modulename', 'feedback'); $PAGE->set_url('/mod/feedback/edit.php', array('id'=>$cm->id, 'do_show'=>$do_show)); $PAGE->set_heading($course->fullname); $PAGE->set_title($feedback->name); //Adding the javascript module for the items dragdrop. if (count($feedbackitems) > 1) { if ($do_show == 'edit') { $PAGE->requires->strings_for_js(array( 'pluginname', 'move_item', 'position', ), 'feedback'); $PAGE->requires->yui_module('moodle-mod_feedback-dragdrop', 'M.mod_feedback.init_dragdrop', array(array('cmid' => $cm->id))); } } echo $OUTPUT->header(); echo $OUTPUT->heading(format_string($feedback->name)); /// print the tabs require('tabs.php'); /// Print the main part of the page. /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// $savereturn=isset($savereturn)?$savereturn:''; //Print the messages. if ($savereturn == 'notsaved_name') { echo '
'. get_string('name_required', 'feedback'). '
'; } if ($savereturn == 'saved') { echo ''. get_string('template_saved', 'feedback'). '
'; } if ($savereturn == 'failed') { echo ''. get_string('saving_failed', 'feedback'). '
'; } /////////////////////////////////////////////////////////////////////////// ///Print the template-section. /////////////////////////////////////////////////////////////////////////// if ($do_show == 'templates') { echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide'); $use_template_form->display(); if (has_capability('mod/feedback:createprivatetemplate', $context) OR has_capability('mod/feedback:createpublictemplate', $context)) { $deleteurl = new moodle_url('/mod/feedback/delete_template.php', array('id' => $id)); $create_template_form->display(); echo ''. get_string('delete_templates', 'feedback'). '
'; } else { echo ' '; } if (has_capability('mod/feedback:edititems', $context)) { $urlparams = array('action'=>'exportfile', 'id'=>$id); $exporturl = new moodle_url('/mod/feedback/export.php', $urlparams); $importurl = new moodle_url('/mod/feedback/import.php', array('id'=>$id)); echo ''.get_string('export_questions', 'feedback').'/ '.get_string('import_questions', 'feedback').'
'; } echo $OUTPUT->box_end(); } /////////////////////////////////////////////////////////////////////////// ///Print the Item-Edit-section. /////////////////////////////////////////////////////////////////////////// if ($do_show == 'edit') { $add_item_form->display(); if (is_array($feedbackitems)) { $itemnr = 0; $align = right_to_left() ? 'right' : 'left'; $helpbutton = $OUTPUT->help_icon('preview', 'feedback'); echo $OUTPUT->heading(get_string('preview', 'feedback').$helpbutton, 3); if (isset($SESSION->feedback->moving) AND $SESSION->feedback->moving->shouldmoving == 1) { $anker = ''; $anker .= get_string('cancel_moving', 'feedback'); $anker .= ''; echo $OUTPUT->heading($anker); } //Check, if there exists required-elements. $params = array('feedback' => $feedback->id, 'required' => 1); $countreq = $DB->count_records('feedback_item', $params); if ($countreq > 0) { echo '