blocks MDL-20206 Added checking to initialise block weight array outsite of min/max...
[moodle.git] / blog / preferences.php
CommitLineData
cae83708 1<?php
4a173181 2
cae83708 3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
4a173181 17
e96f2a77 18
cae83708 19/**
20 * Form page for blog preferences
21 *
22 * @package moodlecore
23 * @subpackage blog
24 * @copyright 2009 Nicolas Connault
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 */
4a173181 27
cae83708 28require_once('../config.php');
29require_once($CFG->dirroot.'/blog/lib.php');
30require_once('preferences_form.php');
31
32$courseid = optional_param('courseid', SITEID, PARAM_INT);
33$PAGE->set_url('blog/preferences.php', array('courseid' => $courseid));
34
35if ($courseid == SITEID) {
36 require_login();
37 $context = get_context_instance(CONTEXT_SYSTEM);
38} else {
39 require_login($courseid);
40 $context = get_context_instance(CONTEXT_COURSE, $courseid);
41}
ab2f17b0 42
cae83708 43if (empty($CFG->bloglevel)) {
44 print_error('blogdisable', 'blog');
45}
46
47require_capability('moodle/blog:view', $context);
4a173181 48
49/// If data submitted, then process and store.
50
cae83708 51$mform = new blog_preferences_form('preferences.php');
4a173181 52
cae83708 53if (!$mform->is_cancelled() && $data = $mform->get_data()) {
54 $pagesize = $data->pagesize;
e96f2a77 55
cae83708 56 if ($pagesize < 1) {
57 print_error('invalidpagesize');
4a173181 58 }
cae83708 59 set_user_preference('blogpagesize', $pagesize);
60}
61
62if ($mform->is_cancelled()){
63 redirect($CFG->wwwroot . '/blog/index.php');
64}
65
66$site = get_site();
67
68$strpreferences = get_string('preferences');
69$strblogs = get_string('blogs', 'blog');
db837673 70
cae83708 71$title = "$site->shortname: $strblogs : $strpreferences";
72$PAGE->set_title($title);
73$PAGE->set_heading($title);
e640790e 74$PAGE->navbar->add($strblogs, new moodle_url($CFG->wwwroot.'/blog/'));
75$PAGE->navbar->add($strpreferences);
4a173181 76
e640790e 77echo $OUTPUT->header();
4a173181 78
cae83708 79echo $OUTPUT->heading("$strblogs : $strpreferences", 2);
4a173181 80
cae83708 81$mform->display();
4a173181 82
cae83708 83echo $OUTPUT->footer();