Commit | Line | Data |
---|---|---|
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 | 27 | require_once('../config.php'); |
28 | require_once($CFG->dirroot.'/blog/lib.php'); | |
29 | require_once('preferences_form.php'); | |
6e65554e | 30 | require_once($CFG->dirroot.'/user/editlib.php'); |
cae83708 | 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'); |
39 | if ($courseid !== SITEID) { | |
40 | $url->param('courseid', $courseid); | |
41 | } | |
42 | if ($modid !== null) { | |
43 | $url->param('modid', $modid); | |
44 | } | |
45 | if ($userid !== null) { | |
46 | $url->param('userid', $userid); | |
47 | } | |
48 | if ($tagid !== null) { | |
49 | $url->param('tagid', $tagid); | |
50 | } | |
51 | if ($groupid !== null) { | |
52 | $url->param('groupid', $groupid); | |
53 | } | |
54 | ||
55 | $PAGE->set_url($url); | |
566889aa | 56 | $PAGE->set_pagelayout('admin'); |
cae83708 | 57 | |
68fc1cc2 | 58 | $sitecontext = context_system::instance(); |
880c5073 AG |
59 | $usercontext = context_user::instance($USER->id); |
60 | $PAGE->set_context($usercontext); | |
68fc1cc2 | 61 | require_login($courseid); |
ab2f17b0 | 62 | |
850d2db8 | 63 | if (empty($CFG->enableblogs)) { |
cae83708 | 64 | print_error('blogdisable', 'blog'); |
65 | } | |
66 | ||
67a1f639 SB |
67 | if (isguestuser()) { |
68 | print_error('noguest'); | |
69 | } | |
70 | ||
68fc1cc2 AA |
71 | // The preference is site wide not blog specific. Hence user should have permissions in site level. |
72 | require_capability('moodle/blog:view', $sitecontext); | |
4a173181 | 73 | |
2b6e53e8 | 74 | // If data submitted, then process and store. |
4a173181 | 75 | |
cae83708 | 76 | $mform = new blog_preferences_form('preferences.php'); |
92681489 | 77 | $mform->set_data(array('pagesize' => get_user_preferences('blogpagesize'))); |
4a173181 | 78 | |
cae83708 | 79 | if (!$mform->is_cancelled() && $data = $mform->get_data()) { |
80 | $pagesize = $data->pagesize; | |
e96f2a77 | 81 | |
cae83708 | 82 | if ($pagesize < 1) { |
83 | print_error('invalidpagesize'); | |
4a173181 | 84 | } |
6e65554e MG |
85 | useredit_update_user_preference(['id' => $USER->id, |
86 | 'preference_blogpagesize' => $pagesize]); | |
cae83708 | 87 | } |
88 | ||
2b6e53e8 | 89 | if ($mform->is_cancelled()) { |
4e1f6047 | 90 | redirect($CFG->wwwroot . '/user/preferences.php'); |
cae83708 | 91 | } |
92 | ||
93 | $site = get_site(); | |
94 | ||
95 | $strpreferences = get_string('preferences'); | |
96 | $strblogs = get_string('blogs', 'blog'); | |
db837673 | 97 | |
cae83708 | 98 | $title = "$site->shortname: $strblogs : $strpreferences"; |
99 | $PAGE->set_title($title); | |
880c5073 | 100 | $PAGE->set_heading(fullname($USER)); |
4a173181 | 101 | |
e640790e | 102 | echo $OUTPUT->header(); |
4a173181 | 103 | |
cae83708 | 104 | echo $OUTPUT->heading("$strblogs : $strpreferences", 2); |
4a173181 | 105 | |
cae83708 | 106 | $mform->display(); |
4a173181 | 107 | |
cae83708 | 108 | echo $OUTPUT->footer(); |