MDL-46346 blog: coding style fixes
[moodle.git] / blog / preferences.php
CommitLineData
cae83708 1<?php
cae83708 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/>.
4a173181 16
e96f2a77 17
cae83708 18/**
19 * Form page for blog preferences
20 *
21 * @package moodlecore
22 * @subpackage blog
23 * @copyright 2009 Nicolas Connault
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 */
4a173181 26
cae83708 27require_once('../config.php');
28require_once($CFG->dirroot.'/blog/lib.php');
29require_once('preferences_form.php');
30
31$courseid = optional_param('courseid', SITEID, PARAM_INT);
b0e90a0c 32$modid = optional_param('modid', null, PARAM_INT);
33$userid = optional_param('userid', null, PARAM_INT);
34$tagid = optional_param('tagid', null, PARAM_INT);
35$groupid = optional_param('groupid', null, PARAM_INT);
36
2713c6bd
SH
37$url = new moodle_url('/blog/preferences.php');
38if ($courseid !== SITEID) {
39 $url->param('courseid', $courseid);
40}
41if ($modid !== null) {
42 $url->param('modid', $modid);
43}
44if ($userid !== null) {
45 $url->param('userid', $userid);
46}
47if ($tagid !== null) {
48 $url->param('tagid', $tagid);
49}
50if ($groupid !== null) {
51 $url->param('groupid', $groupid);
52}
53
54$PAGE->set_url($url);
566889aa 55$PAGE->set_pagelayout('admin');
cae83708 56
68fc1cc2
AA
57$sitecontext = context_system::instance();
58$PAGE->set_context($sitecontext);
59require_login($courseid);
ab2f17b0 60
850d2db8 61if (empty($CFG->enableblogs)) {
cae83708 62 print_error('blogdisable', 'blog');
63}
64
68fc1cc2
AA
65// The preference is site wide not blog specific. Hence user should have permissions in site level.
66require_capability('moodle/blog:view', $sitecontext);
4a173181 67
2b6e53e8 68// If data submitted, then process and store.
4a173181 69
cae83708 70$mform = new blog_preferences_form('preferences.php');
92681489 71$mform->set_data(array('pagesize' => get_user_preferences('blogpagesize')));
4a173181 72
cae83708 73if (!$mform->is_cancelled() && $data = $mform->get_data()) {
74 $pagesize = $data->pagesize;
e96f2a77 75
cae83708 76 if ($pagesize < 1) {
77 print_error('invalidpagesize');
4a173181 78 }
cae83708 79 set_user_preference('blogpagesize', $pagesize);
80}
81
2b6e53e8 82if ($mform->is_cancelled()) {
cae83708 83 redirect($CFG->wwwroot . '/blog/index.php');
84}
85
86$site = get_site();
87
88$strpreferences = get_string('preferences');
89$strblogs = get_string('blogs', 'blog');
db837673 90
cae83708 91$title = "$site->shortname: $strblogs : $strpreferences";
92$PAGE->set_title($title);
93$PAGE->set_heading($title);
4a173181 94
e640790e 95echo $OUTPUT->header();
4a173181 96
cae83708 97echo $OUTPUT->heading("$strblogs : $strpreferences", 2);
4a173181 98
cae83708 99$mform->display();
4a173181 100
cae83708 101echo $OUTPUT->footer();