2009-09-24 06:11:39 +00:00
|
|
|
<?php
|
|
|
|
|
2008-04-23 09:33:54 +00:00
|
|
|
/**
|
2009-09-24 06:11:39 +00:00
|
|
|
* prints the form to edit a dedicated item
|
|
|
|
*
|
|
|
|
* @author Andreas Grabs
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
|
|
|
* @package feedback
|
|
|
|
*/
|
2008-04-23 09:33:54 +00:00
|
|
|
|
2009-09-24 06:11:39 +00:00
|
|
|
require_once("../../config.php");
|
|
|
|
require_once("lib.php");
|
2008-04-23 09:33:54 +00:00
|
|
|
|
2009-09-24 06:11:39 +00:00
|
|
|
feedback_init_feedback_session();
|
2009-09-16 12:21:47 +00:00
|
|
|
|
2010-04-02 21:26:17 +00:00
|
|
|
// $cmid = optional_param('cmid', NULL, PARAM_INT);
|
|
|
|
$cmid = required_param('cmid', PARAM_INT);
|
2009-09-24 06:11:39 +00:00
|
|
|
$typ = optional_param('typ', false, PARAM_ALPHA);
|
2010-02-28 18:56:20 +00:00
|
|
|
$id = optional_param('id', false, PARAM_INT);
|
2010-04-23 21:25:27 +00:00
|
|
|
$action = optional_param('action', false, PARAM_ALPHA);
|
2009-08-10 04:59:26 +00:00
|
|
|
|
2010-03-28 15:29:49 +00:00
|
|
|
$editurl = new moodle_url('/mod/feedback/edit.php', array('id'=>$cmid));
|
|
|
|
|
|
|
|
if(!$typ)redirect($editurl->out(false));
|
2008-04-23 09:33:54 +00:00
|
|
|
|
2010-02-28 18:56:20 +00:00
|
|
|
$url = new moodle_url('/mod/feedback/edit_item.php', array('cmid'=>$cmid));
|
2009-11-25 01:46:12 +00:00
|
|
|
if ($typ !== false) {
|
2009-09-24 06:11:39 +00:00
|
|
|
$url->param('typ', $typ);
|
|
|
|
}
|
2010-02-28 18:56:20 +00:00
|
|
|
if ($id !== false) {
|
|
|
|
$url->param('id', $id);
|
2009-09-24 06:11:39 +00:00
|
|
|
}
|
|
|
|
$PAGE->set_url($url);
|
2008-04-23 09:33:54 +00:00
|
|
|
|
2009-09-24 06:11:39 +00:00
|
|
|
// set up some general variables
|
|
|
|
$usehtmleditor = can_use_html_editor();
|
2008-04-28 09:58:09 +00:00
|
|
|
|
|
|
|
|
2009-09-24 06:11:39 +00:00
|
|
|
if(($formdata = data_submitted()) AND !confirm_sesskey()) {
|
|
|
|
print_error('invalidsesskey');
|
|
|
|
}
|
2009-08-10 04:59:26 +00:00
|
|
|
|
2010-04-02 21:26:17 +00:00
|
|
|
if (! $cm = get_coursemodule_from_id('feedback', $cmid)) {
|
|
|
|
print_error('invalidcoursemodule');
|
|
|
|
}
|
2008-04-23 09:33:54 +00:00
|
|
|
|
2010-04-02 21:26:17 +00:00
|
|
|
if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
|
|
|
|
print_error('coursemisconf');
|
|
|
|
}
|
2008-04-23 09:33:54 +00:00
|
|
|
|
2010-04-02 21:26:17 +00:00
|
|
|
if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
|
|
|
|
print_error('invalidcoursemodule');
|
2009-09-24 06:11:39 +00:00
|
|
|
}
|
2010-04-02 11:34:28 +00:00
|
|
|
|
|
|
|
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
|
|
|
|
print_error('badcontext');
|
|
|
|
}
|
2009-09-24 06:11:39 +00:00
|
|
|
|
|
|
|
require_login($course->id, true, $cm);
|
|
|
|
|
2010-04-02 20:38:17 +00:00
|
|
|
require_capability('mod/feedback:edititems', $context);
|
2009-09-24 06:11:39 +00:00
|
|
|
|
|
|
|
//if the typ is pagebreak so the item will be saved directly
|
|
|
|
if($typ == 'pagebreak') {
|
|
|
|
feedback_create_pagebreak($feedback->id);
|
2010-03-28 15:29:49 +00:00
|
|
|
redirect($editurl->out(false));
|
2009-09-24 06:11:39 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
//get the existing item or create it
|
|
|
|
// $formdata->itemid = isset($formdata->itemid) ? $formdata->itemid : NULL;
|
2010-02-28 18:56:20 +00:00
|
|
|
if($id and $item = $DB->get_record('feedback_item', array('id'=>$id))) {
|
2009-09-24 06:11:39 +00:00
|
|
|
$typ = $item->typ;
|
|
|
|
}else {
|
|
|
|
$item = new stdClass();
|
2010-04-23 21:25:27 +00:00
|
|
|
$item->id = null;
|
|
|
|
$item->position = -1;
|
2009-09-24 06:11:39 +00:00
|
|
|
if (!$typ) {
|
2010-03-28 15:29:49 +00:00
|
|
|
print_error('typemissing', 'feedback', $editurl->out(false));
|
2009-09-24 06:11:39 +00:00
|
|
|
}
|
2010-04-23 21:25:27 +00:00
|
|
|
$item->typ = $typ;
|
2010-05-16 08:17:09 +00:00
|
|
|
$item->options = '';
|
2009-09-24 06:11:39 +00:00
|
|
|
}
|
2008-04-23 09:33:54 +00:00
|
|
|
|
2009-09-24 06:11:39 +00:00
|
|
|
require_once($CFG->dirroot.'/mod/feedback/item/'.$typ.'/lib.php');
|
2009-09-11 02:04:38 +00:00
|
|
|
|
2010-06-04 20:21:08 +00:00
|
|
|
$itemobj = feedback_get_item_class($typ);
|
2009-09-24 06:11:39 +00:00
|
|
|
|
2010-04-23 21:25:27 +00:00
|
|
|
$itemobj->build_editform($item, $feedback, $cm);
|
2010-04-08 19:32:43 +00:00
|
|
|
|
2010-04-23 21:25:27 +00:00
|
|
|
if($itemobj->is_cancelled()) {
|
|
|
|
redirect($editurl->out(false));
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
if($itemobj->get_data()) {
|
|
|
|
if($item = $itemobj->save_item()) {
|
|
|
|
feedback_move_item($item, $item->position);
|
2010-03-28 15:29:49 +00:00
|
|
|
redirect($editurl->out(false));
|
2009-12-21 03:57:36 +00:00
|
|
|
}
|
|
|
|
}
|
2010-04-23 21:25:27 +00:00
|
|
|
|
2009-12-21 03:57:36 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/// Print the page header
|
|
|
|
$strfeedbacks = get_string("modulenameplural", "feedback");
|
|
|
|
$strfeedback = get_string("modulename", "feedback");
|
|
|
|
|
2010-05-28 03:38:41 +00:00
|
|
|
if ($item->id) {
|
|
|
|
$PAGE->navbar->add(get_string('edit_item', 'feedback'));
|
|
|
|
} else {
|
|
|
|
$PAGE->navbar->add(get_string('add_item', 'feedback'));
|
|
|
|
}
|
2010-05-09 21:37:48 +00:00
|
|
|
$PAGE->set_heading(format_string($course->fullname));
|
2009-12-21 03:57:36 +00:00
|
|
|
$PAGE->set_title(format_string($feedback->name));
|
|
|
|
echo $OUTPUT->header();
|
|
|
|
/// print the tabs
|
|
|
|
include('tabs.php');
|
|
|
|
/// Print the main part of the page
|
|
|
|
echo $OUTPUT->heading(format_text($feedback->name));
|
|
|
|
//print errormsg
|
|
|
|
if(isset($error)) {
|
|
|
|
echo $error;
|
|
|
|
}
|
|
|
|
feedback_print_errors();
|
2010-04-23 21:25:27 +00:00
|
|
|
$itemobj->show_editform();
|
2009-08-10 04:59:26 +00:00
|
|
|
|
2009-09-24 06:11:39 +00:00
|
|
|
// echo $OUTPUT->box_end();
|
2009-08-10 04:59:26 +00:00
|
|
|
|
2009-09-24 06:11:39 +00:00
|
|
|
if ($typ!='label') {
|
2010-01-18 20:57:32 +00:00
|
|
|
$PAGE->requires->js('/mod/feedback/feedback.js');
|
2009-09-24 06:11:39 +00:00
|
|
|
$PAGE->requires->js_function_call('set_item_focus', Array('id_itemname'));
|
|
|
|
}
|
2008-04-23 09:33:54 +00:00
|
|
|
|
2009-09-24 06:11:39 +00:00
|
|
|
/// Finish the page
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2008-04-23 09:33:54 +00:00
|
|
|
|
2009-09-24 06:11:39 +00:00
|
|
|
echo $OUTPUT->footer();
|
2008-04-23 09:33:54 +00:00
|
|
|
|