source: moodle/trunk/fuentes/admin/tool/messageinbound/index.php @ 136

Last change on this file since 136 was 136, checked in by mabarracus, 4 years ago

Ported code to xenial

File size: 2.9 KB
Line 
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 * Inbound Message Settings pages.
19 *
20 * @package    tool_messageinbound
21 * @copyright  2014 Andrew NIcols
22 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25require_once(dirname(__FILE__) . '/../../../config.php');
26require_once($CFG->libdir.'/adminlib.php');
27require_once($CFG->libdir.'/tablelib.php');
28
29admin_externalpage_setup('messageinbound_handlers');
30
31$classname = optional_param('classname', '', PARAM_RAW);
32
33$pageurl = new moodle_url('/admin/tool/messageinbound/index.php');
34
35if (empty($classname)) {
36    $renderer = $PAGE->get_renderer('tool_messageinbound');
37
38    $records = $DB->get_recordset('messageinbound_handlers', null, 'enabled desc', 'classname');
39    $instances = array();
40    foreach ($records as $record) {
41        $instances[] = \core\message\inbound\manager::get_handler($record->classname);
42    }
43
44    echo $OUTPUT->header();
45    echo $renderer->messageinbound_handlers_table($instances);
46    echo $OUTPUT->footer();
47
48} else {
49    // Retrieve the handler and its record.
50    $handler = \core\message\inbound\manager::get_handler($classname);
51    $record = \core\message\inbound\manager::record_from_handler($handler);
52
53    $formurl = new moodle_url($PAGE->url, array('classname' => $classname));
54    $mform = new tool_messageinbound_edit_handler_form($formurl, array(
55            'handler' => $handler,
56    ));
57
58    if ($mform->is_cancelled()) {
59        redirect($PAGE->url);
60    } else if ($data = $mform->get_data()) {
61        // Update the record from the form.
62        $record->defaultexpiration = (int) $data->defaultexpiration;
63
64        if ($handler->can_change_validateaddress()) {
65            $record->validateaddress = !empty($data->validateaddress);
66        }
67
68        if ($handler->can_change_enabled()) {
69            $record->enabled = !empty($data->enabled);
70        }
71        $DB->update_record('messageinbound_handlers', $record);
72        redirect($PAGE->url);
73    }
74
75    // Add the breadcrumb.
76    $pageurl->param('classname', $handler->classname);
77    $PAGE->navbar->add($handler->name, $pageurl);
78    echo $OUTPUT->header();
79    echo $OUTPUT->heading(get_string('editinghandler', 'tool_messageinbound', $handler->name));
80    $mform->set_data($record);
81    $mform->display();
82    echo $OUTPUT->footer();
83
84}
Note: See TracBrowser for help on using the repository browser.