Merge branch 'MDL-74500' of https://github.com/paulholden/moodle
[moodle.git] / mod / data / css.php
blobe8f416723919cb62d1a9d39e2935e0358dc57d6f
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.
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/>.
17 /**
18 * This file is part of the Database module for Moodle
20 * @copyright 2005 Martin Dougiamas http://dougiamas.com
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22 * @package mod_data
24 use mod_data\manager;
25 use mod_data\preset;
27 define('NO_MOODLE_COOKIES', true); // Session not used here.
29 require_once('../../config.php');
31 $id = optional_param('id', 0, PARAM_INT); // Course module id.
32 $d = optional_param('d', 0, PARAM_INT); // Database id.
33 $presetfullname = optional_param('preset', '', PARAM_PATH); // The directory the preset is in.
35 $lifetime = 600; // Seconds to cache this stylesheet.
36 $url = new moodle_url('/mod/data/css.php');
38 $manager = null;
39 if ($id) {
40 list($course, $cm) = get_course_and_cm_from_cmid($id, manager::MODULE);
41 $manager = manager::create_from_coursemodule($cm);
42 $instance = $manager->get_instance();
43 } else {
44 // We must have the database activity id.
45 $d = required_param('d', PARAM_INT);
46 $instance = $DB->get_record('data', ['id' => $d], '*', MUST_EXIST);
47 $manager = manager::create_from_instance($instance);
49 $url->param('d', $instance->id);
51 // Get the content.
52 if ($presetfullname) {
53 $url->param('preset', $presetfullname);
54 $preset = preset::create_from_fullname($manager, $presetfullname);
55 $content = $preset->get_template_content('csstemplate');
56 $lifetime = 60; // Preset preview does not need a long cache.
57 } else {
58 $content = $instance->csstemplate;
61 $PAGE->set_url($url);
63 header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
64 header('Expires: ' . gmdate("D, d M Y H:i:s", time() + $lifetime) . ' GMT');
65 header('Cache-control: max_age = '. $lifetime);
66 header('Pragma: ');
67 header('Content-type: text/css; charset=utf-8'); // Correct MIME type.
69 echo $content;