Merge branch 'MDL-54833-master-workshopuserplan' of git://github.com/mudrd8mz/moodle
[moodle.git] / blog / preferences.php
blob18711612945afbb8284643ec27fdce12e75cbb18
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/>.
18 /**
19 * Form page for blog preferences
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
27 require_once('../config.php');
28 require_once($CFG->dirroot.'/blog/lib.php');
29 require_once('preferences_form.php');
31 $courseid = optional_param('courseid', SITEID, PARAM_INT);
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);
37 $url = new moodle_url('/blog/preferences.php');
38 if ($courseid !== SITEID) {
39 $url->param('courseid', $courseid);
41 if ($modid !== null) {
42 $url->param('modid', $modid);
44 if ($userid !== null) {
45 $url->param('userid', $userid);
47 if ($tagid !== null) {
48 $url->param('tagid', $tagid);
50 if ($groupid !== null) {
51 $url->param('groupid', $groupid);
54 $PAGE->set_url($url);
55 $PAGE->set_pagelayout('admin');
57 $sitecontext = context_system::instance();
58 $usercontext = context_user::instance($USER->id);
59 $PAGE->set_context($usercontext);
60 require_login($courseid);
62 if (empty($CFG->enableblogs)) {
63 print_error('blogdisable', 'blog');
66 if (isguestuser()) {
67 print_error('noguest');
70 // The preference is site wide not blog specific. Hence user should have permissions in site level.
71 require_capability('moodle/blog:view', $sitecontext);
73 // If data submitted, then process and store.
75 $mform = new blog_preferences_form('preferences.php');
76 $mform->set_data(array('pagesize' => get_user_preferences('blogpagesize')));
78 if (!$mform->is_cancelled() && $data = $mform->get_data()) {
79 $pagesize = $data->pagesize;
81 if ($pagesize < 1) {
82 print_error('invalidpagesize');
84 set_user_preference('blogpagesize', $pagesize);
87 if ($mform->is_cancelled()) {
88 redirect($CFG->wwwroot . '/user/preferences.php');
91 $site = get_site();
93 $strpreferences = get_string('preferences');
94 $strblogs = get_string('blogs', 'blog');
96 $title = "$site->shortname: $strblogs : $strpreferences";
97 $PAGE->set_title($title);
98 $PAGE->set_heading(fullname($USER));
100 echo $OUTPUT->header();
102 echo $OUTPUT->heading("$strblogs : $strpreferences", 2);
104 $mform->display();
106 echo $OUTPUT->footer();