blog MDL-23393 - Tidy up preferences form
[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);
b0e90a0c 33$modid = optional_param('modid', null, PARAM_INT);
34$userid = optional_param('userid', null, PARAM_INT);
35$tagid = optional_param('tagid', null, PARAM_INT);
36$groupid = optional_param('groupid', null, PARAM_INT);
37
2713c6bd
SH
38$url = new moodle_url('/blog/preferences.php');
39if ($courseid !== SITEID) {
40 $url->param('courseid', $courseid);
41}
42if ($modid !== null) {
43 $url->param('modid', $modid);
44}
45if ($userid !== null) {
46 $url->param('userid', $userid);
47}
48if ($tagid !== null) {
49 $url->param('tagid', $tagid);
50}
51if ($groupid !== null) {
52 $url->param('groupid', $groupid);
53}
54
55$PAGE->set_url($url);
897aa80c 56$PAGE->set_pagelayout('standard');
cae83708 57
58if ($courseid == SITEID) {
59 require_login();
60 $context = get_context_instance(CONTEXT_SYSTEM);
2713c6bd 61 $PAGE->set_context($context);
cae83708 62} else {
63 require_login($courseid);
64 $context = get_context_instance(CONTEXT_COURSE, $courseid);
65}
ab2f17b0 66
cae83708 67if (empty($CFG->bloglevel)) {
68 print_error('blogdisable', 'blog');
69}
70
71require_capability('moodle/blog:view', $context);
4a173181 72
73/// If data submitted, then process and store.
74
cae83708 75$mform = new blog_preferences_form('preferences.php');
92681489 76$mform->set_data(array('pagesize' => get_user_preferences('blogpagesize')));
4a173181 77
cae83708 78if (!$mform->is_cancelled() && $data = $mform->get_data()) {
79 $pagesize = $data->pagesize;
e96f2a77 80
cae83708 81 if ($pagesize < 1) {
82 print_error('invalidpagesize');
4a173181 83 }
cae83708 84 set_user_preference('blogpagesize', $pagesize);
85}
86
87if ($mform->is_cancelled()){
88 redirect($CFG->wwwroot . '/blog/index.php');
89}
90
91$site = get_site();
92
93$strpreferences = get_string('preferences');
94$strblogs = get_string('blogs', 'blog');
db837673 95
cae83708 96$title = "$site->shortname: $strblogs : $strpreferences";
97$PAGE->set_title($title);
98$PAGE->set_heading($title);
4a173181 99
e640790e 100echo $OUTPUT->header();
4a173181 101
cae83708 102echo $OUTPUT->heading("$strblogs : $strpreferences", 2);
4a173181 103
cae83708 104$mform->display();
4a173181 105
cae83708 106echo $OUTPUT->footer();