2009-09-24 06:11:39 +00:00
|
|
|
<?php
|
2011-10-28 00:30:42 +02:00
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
2009-09-24 06:11:39 +00:00
|
|
|
|
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
|
2014-02-14 17:01:49 +13:00
|
|
|
* @package mod_feedback
|
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("../../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
|
|
|
|
2016-03-11 20:45:41 +08:00
|
|
|
$itemid = optional_param('id', false, PARAM_INT);
|
|
|
|
if (!$itemid) {
|
|
|
|
$cmid = required_param('cmid', PARAM_INT);
|
|
|
|
$typ = required_param('typ', PARAM_ALPHA);
|
2010-04-02 21:26:17 +00:00
|
|
|
}
|
2008-04-23 09:33:54 +00:00
|
|
|
|
2016-03-11 20:45:41 +08:00
|
|
|
if ($itemid) {
|
|
|
|
$item = $DB->get_record('feedback_item', array('id' => $itemid), '*', MUST_EXIST);
|
|
|
|
list($course, $cm) = get_course_and_cm_from_instance($item->feedback, 'feedback');
|
|
|
|
$url = new moodle_url('/mod/feedback/edit_item.php', array('id' => $itemid));
|
|
|
|
$typ = $item->typ;
|
|
|
|
} else {
|
|
|
|
$item = null;
|
|
|
|
list($course, $cm) = get_course_and_cm_from_cmid($cmid, 'feedback');
|
|
|
|
$url = new moodle_url('/mod/feedback/edit_item.php', array('cmid' => $cm->id, 'typ' => $typ));
|
|
|
|
$item = (object)['id' => null, 'position' => -1, 'typ' => $typ, 'options' => ''];
|
2009-09-24 06:11:39 +00:00
|
|
|
}
|
2010-04-02 11:34:28 +00:00
|
|
|
|
2016-03-11 20:45:41 +08:00
|
|
|
require_login($course, true, $cm);
|
2012-07-26 13:59:09 +08:00
|
|
|
$context = context_module::instance($cm->id);
|
2016-03-11 20:45:41 +08:00
|
|
|
require_capability('mod/feedback:edititems', $context);
|
|
|
|
$feedback = $PAGE->activityrecord;
|
2009-09-24 06:11:39 +00:00
|
|
|
|
2016-03-11 20:45:41 +08:00
|
|
|
$editurl = new moodle_url('/mod/feedback/edit.php', array('id' => $cm->id));
|
2009-09-24 06:11:39 +00:00
|
|
|
|
2016-03-11 20:45:41 +08:00
|
|
|
$PAGE->set_url($url);
|
2009-09-24 06:11:39 +00:00
|
|
|
|
2016-03-11 20:45:41 +08:00
|
|
|
// If the typ is pagebreak so the item will be saved directly.
|
|
|
|
if (!$item->id && $typ === 'pagebreak') {
|
|
|
|
require_sesskey();
|
2024-07-31 11:41:43 +01:00
|
|
|
|
|
|
|
$redirectmessage = '';
|
|
|
|
if (!feedback_create_pagebreak($feedback->id)) {
|
|
|
|
$redirectmessage = get_string('cannotcreatepagebreak', 'mod_feedback');
|
|
|
|
}
|
|
|
|
|
|
|
|
redirect($editurl, $redirectmessage, null, \core\output\notification::NOTIFY_WARNING);
|
2009-09-24 06:11:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//get the existing item or create it
|
2024-03-06 21:24:45 +00:00
|
|
|
if (!$typ) {
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('typemissing', 'feedback', $editurl->out(false));
|
2009-09-24 06:11:39 +00:00
|
|
|
}
|
2008-04-23 09:33:54 +00:00
|
|
|
|
2010-06-04 20:21:08 +00:00
|
|
|
$itemobj = feedback_get_item_class($typ);
|
2010-04-23 21:25:27 +00:00
|
|
|
$itemobj->build_editform($item, $feedback, $cm);
|
2010-04-08 19:32:43 +00:00
|
|
|
|
2011-10-28 00:30:42 +02:00
|
|
|
if ($itemobj->is_cancelled()) {
|
2016-03-11 20:45:41 +08:00
|
|
|
redirect($editurl);
|
2010-04-23 21:25:27 +00:00
|
|
|
exit;
|
|
|
|
}
|
2011-10-28 00:30:42 +02:00
|
|
|
if ($itemobj->get_data()) {
|
|
|
|
if ($item = $itemobj->save_item()) {
|
2010-04-23 21:25:27 +00:00
|
|
|
feedback_move_item($item, $item->position);
|
2016-03-11 20:45:41 +08:00
|
|
|
redirect($editurl);
|
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");
|
|
|
|
|
2016-03-11 20:45:41 +08:00
|
|
|
navigation_node::override_active_url(new moodle_url('/mod/feedback/edit.php',
|
|
|
|
array('id' => $cm->id, 'do_show' => 'edit')));
|
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'));
|
|
|
|
}
|
2014-02-05 14:47:23 +08:00
|
|
|
$PAGE->set_heading($course->fullname);
|
|
|
|
$PAGE->set_title($feedback->name);
|
2021-09-21 12:49:15 +08:00
|
|
|
$PAGE->activityheader->set_attrs([
|
|
|
|
"hidecompletion" => true,
|
|
|
|
"description" => ''
|
|
|
|
]);
|
2024-04-23 13:40:12 +02:00
|
|
|
$PAGE->add_body_class('limitedwidth');
|
2009-12-21 03:57:36 +00:00
|
|
|
echo $OUTPUT->header();
|
2013-09-02 16:07:27 +08:00
|
|
|
|
2009-12-21 03:57:36 +00:00
|
|
|
/// print the tabs
|
2016-03-11 20:45:41 +08:00
|
|
|
$current_tab = 'edit';
|
|
|
|
$id = $cm->id;
|
2013-09-02 16:07:27 +08:00
|
|
|
|
2009-12-21 03:57:36 +00:00
|
|
|
//print errormsg
|
2011-10-28 00:30:42 +02:00
|
|
|
if (isset($error)) {
|
2009-12-21 03:57:36 +00:00
|
|
|
echo $error;
|
|
|
|
}
|
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
|
|
|
/// Finish the page
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2008-04-23 09:33:54 +00:00
|
|
|
|
2009-09-24 06:11:39 +00:00
|
|
|
echo $OUTPUT->footer();
|