-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
72 lines (61 loc) · 2.39 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>.
/**
* Index page of helloworld plugin
*
* @package local_helloworld
* @copyright 2020 Jakub Kleban <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../../config.php');
require_login();
// Variables.
$username = optional_param('username', null, PARAM_ALPHA);
$heading = get_string('hellouser', 'local_helloworld', fullname($USER));
$context = context_system::instance();
// Page setup.
$PAGE->set_context($context);
$PAGE->set_pagelayout('standard');
$PAGE->set_heading($heading);
$PAGE->set_title(get_string('pluginname', 'local_helloworld'));
$PAGE->set_url(new moodle_url('/local/helloworld/index.php'));
$output = $PAGE->get_renderer('local_helloworld');
// Save message into database.
if (has_capability('local/helloworld:postmessages', $context)) {
$messagetext = optional_param('message', null, PARAM_TEXT);
if (isset($messagetext) && !empty($messagetext)) {
require_sesskey();
$time = new DateTime("now", core_date::get_server_timezone_object());
$timestamp = $time->getTimestamp();
$message = new stdClass();
$message->message = $messagetext;
$message->timecreated = $timestamp;
$message->userid = $USER->id;
$DB->insert_record('local_helloworld_messages', $message);
}
}
if (has_capability('local/helloworld:deleteanymessage', $context)) {
if ( $deleteid = optional_param('deleteid', null, PARAM_INT) ) {
require_sesskey();
$DB->delete_records('local_helloworld_messages', array(
'id' => $deleteid
));
}
}
// RENDERING HTML.
echo $output->header();
echo $output->display_script($PAGE->url, $context);
echo $output->footer();