Proyectos de Subversion Moodle

Rev

| 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
 * Display the file type updating page.
19
 *
20
 * @package tool_filetypes
21
 * @copyright 2014 The Open University
22
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
require(__DIR__ . '/../../../config.php');
25
require_once($CFG->libdir . '/adminlib.php');
26
require_once('edit_form.php');
27
 
28
admin_externalpage_setup('tool_filetypes');
29
 
30
$oldextension = optional_param('oldextension', '', PARAM_ALPHANUMEXT);
31
$mform = new tool_filetypes_form('edit.php', array('oldextension' => $oldextension));
32
$title = get_string('addfiletypes', 'tool_filetypes');
33
 
34
if ($oldextension) {
35
    // This is editing an existing filetype, load data to the form.
36
    $mimetypes = get_mimetypes_array();
37
    if (!array_key_exists($oldextension, $mimetypes)) {
38
        throw new moodle_exception('error_notfound', 'tool_filetypes');
39
    }
40
    $typeinfo = $mimetypes[$oldextension];
41
    $formdata = array(
42
        'extension' => $oldextension,
43
        'mimetype' => $typeinfo['type'],
44
        'icon' => $typeinfo['icon'],
45
        'oldextension' => $oldextension,
46
        'description' => '',
47
        'groups' => '',
48
        'corestring' => '',
49
        'defaulticon' => 0
50
    );
51
    if (!empty($typeinfo['customdescription'])) {
52
        $formdata['description'] = $typeinfo['customdescription'];
53
    }
54
    if (!empty($typeinfo['groups'])) {
55
        $formdata['groups'] = implode(', ', $typeinfo['groups']);
56
    }
57
    if (!empty($typeinfo['string'])) {
58
        $formdata['corestring'] = $typeinfo['string'];
59
    }
60
    if (!empty($typeinfo['defaulticon'])) {
61
        $formdata['defaulticon'] = 1;
62
    }
63
 
64
    $mform->set_data($formdata);
65
    $title = get_string('editfiletypes', 'tool_filetypes');
66
}
67
 
68
$backurl = new \moodle_url('/admin/tool/filetypes/index.php');
69
if ($mform->is_cancelled()) {
70
    redirect($backurl);
71
} else if ($data = $mform->get_data()) {
72
    // Convert the groups value back into an array.
73
    $data->groups = trim($data->groups);
74
    if ($data->groups) {
75
        $data->groups = preg_split('~,\s*~', $data->groups);
76
    } else {
77
        $data->groups = array();
78
    }
79
    if (empty($data->defaulticon)) {
80
        $data->defaulticon = 0;
81
    }
82
    if (empty($data->corestring)) {
83
        $data->corestring = '';
84
    }
85
    if (empty($data->description)) {
86
        $data->description = '';
87
    }
88
    if ($data->oldextension) {
89
        // Update an existing file type.
90
        core_filetypes::update_type($data->oldextension, $data->extension, $data->mimetype, $data->icon,
91
            $data->groups, $data->corestring, $data->description, (bool)$data->defaulticon);
92
    } else {
93
        // Add a new file type entry.
94
        core_filetypes::add_type($data->extension, $data->mimetype, $data->icon,
95
            $data->groups, $data->corestring, $data->description, (bool)$data->defaulticon);
96
    }
97
    redirect($backurl);
98
}
99
 
100
// Page settings.
101
$context = context_system::instance();
102
$PAGE->set_url(new \moodle_url('/admin/tool/filetypes/edit.php', array('oldextension' => $oldextension)));
103
 
104
$PAGE->set_primary_active_tab('siteadminnode');
105
$PAGE->set_secondary_active_tab('server');
106
 
107
$PAGE->navbar->add($oldextension ? s($oldextension) : $title);
108
$PAGE->set_context($context);
109
$PAGE->set_pagelayout('admin');
110
$PAGE->set_title($title);
111
 
112
// Display the page.
113
echo $OUTPUT->header();
114
$mform->display();
115
echo $OUTPUT->footer();