weekly release 3.6dev
[moodle.git] / admin / tool / dataprivacy / editcategory.php
CommitLineData
5efc1f9e
DM
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 * This page lets users manage categories.
19 *
20 * @package tool_dataprivacy
21 * @copyright 2018 David Monllao
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25require_once(__DIR__ . '/../../../config.php');
26
27$id = optional_param('id', 0, PARAM_INT);
28
29$url = new \moodle_url('/admin/tool/dataprivacy/editcategory.php', array('id' => $id));
30if ($id) {
31 $title = get_string('editcategory', 'tool_dataprivacy');
32} else {
33 $title = get_string('addcategory', 'tool_dataprivacy');
34}
35\tool_dataprivacy\page_helper::setup($url, $title, 'dataregistry');
36
37$category = new \tool_dataprivacy\category($id);
38$form = new \tool_dataprivacy\form\category($PAGE->url->out(false),
39 array('persistent' => $category, 'showbuttons' => true));
40
41$returnurl = new \moodle_url('/admin/tool/dataprivacy/categories.php');
42if ($form->is_cancelled()) {
43 redirect($returnurl);
44} else if ($data = $form->get_data()) {
45 if (empty($data->id)) {
46 \tool_dataprivacy\api::create_category($data);
47 $messagesuccess = get_string('categorycreated', 'tool_dataprivacy');
48 } else {
49 \tool_dataprivacy\api::update_category($data);
50 $messagesuccess = get_string('categoryupdated', 'tool_dataprivacy');
51 }
52 redirect($returnurl, $messagesuccess, 0, \core\output\notification::NOTIFY_SUCCESS);
53}
54
55$output = $PAGE->get_renderer('tool_dataprivacy');
56echo $output->header();
57$form->display();
58echo $output->footer();