diff --git a/mod/feedback/ajax.php b/mod/feedback/ajax.php new file mode 100644 index 00000000000..a562690d194 --- /dev/null +++ b/mod/feedback/ajax.php @@ -0,0 +1,59 @@ +. + +/** + * Process ajax requests + * + * @copyright Andreas Grabs + * @license http://www.gnu.org/copyleft/gpl.html GNU Public License + * @package feedback + */ + +if (!defined('AJAX_SCRIPT')) { + define('AJAX_SCRIPT', true); +} + +require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); +require_once('lib.php'); + +$id = required_param('id', PARAM_INT); +$action = optional_param('action', '', PARAM_ALPHA); +$sesskey = optional_param('sesskey', false, PARAM_TEXT); +$itemorder = optional_param('itemorder', false, PARAM_SEQUENCE); + +$cm = get_coursemodule_from_id('feedback', $id, 0, false, MUST_EXIST); +$course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST); +$feedback = $DB->get_record('feedback', array('id'=>$cm->instance), '*', MUST_EXIST); + +require_sesskey(); + +$context = context_module::instance($cm->id); +require_login($course, true, $cm); +require_capability('mod/feedback:edititems', $context); + +$return = false; + +switch ($action) { + case 'saveitemorder': + $itemlist = explode(',', trim($itemorder, ',')); + if (count($itemlist) > 0) { + $return = feedback_ajax_saveitemorder($itemlist, $feedback); + } + break; +} + +echo json_encode($return); +die; diff --git a/mod/feedback/edit.php b/mod/feedback/edit.php index b928c11e084..6a96292f26b 100644 --- a/mod/feedback/edit.php +++ b/mod/feedback/edit.php @@ -22,8 +22,8 @@ * @package feedback */ -require_once("../../config.php"); -require_once("lib.php"); +require_once('../../config.php'); +require_once('lib.php'); require_once('edit_form.php'); feedback_init_feedback_session(); @@ -49,11 +49,11 @@ if (! $cm = get_coursemodule_from_id('feedback', $id)) { print_error('invalidcoursemodule'); } -if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { +if (! $course = $DB->get_record('course', array('id'=>$cm->course))) { print_error('coursemisconf'); } -if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) { +if (! $feedback = $DB->get_record('feedback', array('id'=>$cm->instance))) { print_error('invalidcoursemodule'); } @@ -63,7 +63,7 @@ require_login($course, true, $cm); require_capability('mod/feedback:edititems', $context); -//move up/down items +//Move up/down items if ($moveupitem) { $item = $DB->get_record('feedback_item', array('id'=>$moveupitem)); feedback_moveup_item($item); @@ -73,7 +73,7 @@ if ($movedownitem) { feedback_movedown_item($item); } -//moving of items +//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)); @@ -94,14 +94,14 @@ if ($switchitemrequired) { exit; } -//the create_template-form +//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 + //Check the capabilities to create templates. if (!has_capability('mod/feedback:createprivatetemplate', $context) AND !has_capability('mod/feedback:createpublictemplate', $context)) { print_error('cannotsavetempl', 'feedback'); @@ -109,7 +109,7 @@ if (isset($create_template_formdata->savetemplate) && $create_template_formdata- if (trim($create_template_formdata->templatename) == '') { $savereturn = 'notsaved_name'; } else { - //if the feedback is located on the frontpage then templates can be public + //If the feedback is located on the frontpage then templates can be public. if (has_capability('mod/feedback:createpublictemplate', get_system_context())) { $create_template_formdata->ispublic = isset($create_template_formdata->ispublic) ? 1 : 0; } else { @@ -125,7 +125,7 @@ if (isset($create_template_formdata->savetemplate) && $create_template_formdata- } } -//get the feedbackitems +//Get the feedbackitems $lastposition = 0; $feedbackitems = $DB->get_records('feedback_item', array('feedback'=>$feedback->id), 'position'); if (is_array($feedbackitems)) { @@ -140,36 +140,48 @@ if (is_array($feedbackitems)) { $lastposition++; -//the add_item-form +//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 +//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"); +//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(format_string($course->fullname)); $PAGE->set_title(format_string($feedback->name)); + +//Adding the javascript module for the items dragdrop. +if ($do_show == 'edit' and $CFG->enableajax) { + $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(); /// print the tabs require('tabs.php'); -/// Print the main part of the page +/// Print the main part of the page. /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// $savereturn=isset($savereturn)?$savereturn:''; -//print the messages +//Print the messages. if ($savereturn == 'notsaved_name') { echo '
'.
get_string('name_required', 'feedback').
@@ -189,7 +201,7 @@ if ($savereturn == 'failed') {
}
///////////////////////////////////////////////////////////////////////////
-///print the template-section
+///Print the template-section.
///////////////////////////////////////////////////////////////////////////
if ($do_show == 'templates') {
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
@@ -218,7 +230,7 @@ if ($do_show == 'templates') {
echo $OUTPUT->box_end();
}
///////////////////////////////////////////////////////////////////////////
-///print the Item-Edit-section
+///Print the Item-Edit-section.
///////////////////////////////////////////////////////////////////////////
if ($do_show == 'edit') {
@@ -239,7 +251,7 @@ if ($do_show == 'edit') {
echo $OUTPUT->heading($anker);
}
- //check, if there exists required-elements
+ //Check, if there exists required-elements.
$params = array('feedback' => $feedback->id, 'required' => 1);
$countreq = $DB->count_records('feedback_item', $params);
if ($countreq > 0) {
@@ -248,12 +260,12 @@ if ($do_show == 'edit') {
echo '';
}
- //use list instead a table
+ //Use list instead a table
echo $OUTPUT->box_start('feedback_items');
if (isset($SESSION->feedback->moving) AND $SESSION->feedback->moving->shouldmoving == 1) {
$moveposition = 1;
$movehereurl = new moodle_url($url, array('movehere'=>$moveposition));
- //only shown if shouldmoving = 1
+ //Only shown if shouldmoving = 1
echo $OUTPUT->box_start('feedback_item_box_'.$align.' clipboard');
$buttonlink = $movehereurl->out();
$strbutton = get_string('move_here', 'feedback');
@@ -263,35 +275,41 @@ if ($do_show == 'edit') {
';
echo $OUTPUT->box_end();
}
- //print the inserted items
+ //Print the inserted items
$itempos = 0;
+ echo ''; //The list what includes the draggable items
foreach ($feedbackitems as $feedbackitem) {
$itempos++;
- //hiding the item to move
+ //Hiding the item to move
if (isset($SESSION->feedback->moving)) {
if ($SESSION->feedback->moving->movingitem == $feedbackitem->id) {
continue;
}
}
+ //Here come the draggable items, each one in a single li-element.
+ echo '
';
+ echo '
';
echo '';
- //print the button to edit the item
+ //Print the button to edit the item
if ($feedbackitem->typ != 'pagebreak') {
echo '';
$editurl = new moodle_url('/mod/feedback/edit_item.php');
@@ -332,8 +350,8 @@ if ($do_show == 'edit') {
'id'=>$feedbackitem->id,
'typ'=>$feedbackitem->typ));
- // in edit_item.php the param id is used for the itemid
- // and the cmid is the id to get the module
+ // In edit_item.php the param id is used for the itemid
+ // and the cmid is the id to get the module.
$buttonlink = $editurl->out();
$strbutton = get_string('edit_item', 'feedback');
echo '
@@ -342,7 +360,7 @@ if ($do_show == 'edit') {
echo '';
}
- //print the toggle-button to switch required yes/no
+ //Print the toggle-button to switch required yes/no
if ($feedbackitem->hasvalue == 1) {
echo '';
if ($feedbackitem->required == 1) {
@@ -364,7 +382,7 @@ if ($do_show == 'edit') {
echo '';
}
- //print the delete-button
+ //Print the delete-button
echo '';
$deleteitemurl = new moodle_url('/mod/feedback/delete_item.php');
$deleteitemurl->params(array('id'=>$id,
@@ -388,10 +406,14 @@ if ($do_show == 'edit') {
}
echo $OUTPUT->box_end();
echo $OUTPUT->box_end();
+ echo '
';
echo $OUTPUT->box_end();
+ echo '