Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * prints the form to edit a dedicated item
19
 *
20
 * @author Andreas Grabs
21
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
22
 * @package mod_feedback
23
 */
24
 
25
require_once("../../config.php");
26
require_once("lib.php");
27
 
28
feedback_init_feedback_session();
29
 
30
$itemid = optional_param('id', false, PARAM_INT);
31
if (!$itemid) {
32
    $cmid = required_param('cmid', PARAM_INT);
33
    $typ = required_param('typ', PARAM_ALPHA);
34
}
35
 
36
if ($itemid) {
37
    $item = $DB->get_record('feedback_item', array('id' => $itemid), '*', MUST_EXIST);
38
    list($course, $cm) = get_course_and_cm_from_instance($item->feedback, 'feedback');
39
    $url = new moodle_url('/mod/feedback/edit_item.php', array('id' => $itemid));
40
    $typ = $item->typ;
41
} else {
42
    $item = null;
43
    list($course, $cm) = get_course_and_cm_from_cmid($cmid, 'feedback');
44
    $url = new moodle_url('/mod/feedback/edit_item.php', array('cmid' => $cm->id, 'typ' => $typ));
45
    $item = (object)['id' => null, 'position' => -1, 'typ' => $typ, 'options' => ''];
46
}
47
 
48
require_login($course, true, $cm);
49
$context = context_module::instance($cm->id);
50
require_capability('mod/feedback:edititems', $context);
51
$feedback = $PAGE->activityrecord;
52
 
53
$editurl = new moodle_url('/mod/feedback/edit.php', array('id' => $cm->id));
54
 
55
$PAGE->set_url($url);
56
 
57
// If the typ is pagebreak so the item will be saved directly.
58
if (!$item->id && $typ === 'pagebreak') {
59
    require_sesskey();
1441 ariadna 60
 
61
    $redirectmessage = '';
62
    if (!feedback_create_pagebreak($feedback->id)) {
63
        $redirectmessage = get_string('cannotcreatepagebreak', 'mod_feedback');
64
    }
65
 
66
    redirect($editurl, $redirectmessage, null, \core\output\notification::NOTIFY_WARNING);
1 efrain 67
}
68
 
69
//get the existing item or create it
70
if (!$typ) {
71
    throw new \moodle_exception('typemissing', 'feedback', $editurl->out(false));
72
}
73
 
74
$itemobj = feedback_get_item_class($typ);
75
$itemobj->build_editform($item, $feedback, $cm);
76
 
77
if ($itemobj->is_cancelled()) {
78
    redirect($editurl);
79
    exit;
80
}
81
if ($itemobj->get_data()) {
82
    if ($item = $itemobj->save_item()) {
83
        feedback_move_item($item, $item->position);
84
        redirect($editurl);
85
    }
86
}
87
 
88
////////////////////////////////////////////////////////////////////////////////////
89
/// Print the page header
90
$strfeedbacks = get_string("modulenameplural", "feedback");
91
$strfeedback  = get_string("modulename", "feedback");
92
 
93
navigation_node::override_active_url(new moodle_url('/mod/feedback/edit.php',
94
        array('id' => $cm->id, 'do_show' => 'edit')));
95
if ($item->id) {
96
    $PAGE->navbar->add(get_string('edit_item', 'feedback'));
97
} else {
98
    $PAGE->navbar->add(get_string('add_item', 'feedback'));
99
}
100
$PAGE->set_heading($course->fullname);
1441 ariadna 101
 
102
$renderer = $PAGE->get_renderer('mod_feedback');
103
$pagetitle = ($itemid) ? get_string('edit_item', 'feedback') : get_string('add_item', 'feedback');
104
$renderer->set_title(
105
    [format_string($feedback->name), format_string($course->fullname)],
106
    $pagetitle
107
);
108
 
1 efrain 109
$PAGE->activityheader->set_attrs([
110
    "hidecompletion" => true,
111
    "description" => ''
112
]);
1441 ariadna 113
$PAGE->add_body_class('limitedwidth');
1 efrain 114
echo $OUTPUT->header();
115
 
116
//print errormsg
117
if (isset($error)) {
118
    echo $error;
119
}
120
$itemobj->show_editform();
121
 
122
/// Finish the page
123
///////////////////////////////////////////////////////////////////////////
124
///////////////////////////////////////////////////////////////////////////
125
///////////////////////////////////////////////////////////////////////////
126
 
127
echo $OUTPUT->footer();