MDL-65788 tool_policy: Prevent two modals rendering for guests.
[moodle.git] / blocks / rss_client / managefeeds.php
CommitLineData
f1a34d8f 1<?php
beb56299 2// This file is part of Moodle - http://moodle.org/
3//
f1a34d8f 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.
beb56299 13//
f1a34d8f 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/>.
16
17/**
18 * Script to let a user manage their RSS feeds.
19 *
f25a6839 20 * @package block_rss_client
f1a34d8f 21 * @copyright 2009 Tim Hunt
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
1fcf0ca8 25require_once(__DIR__ . '/../../config.php');
f1a34d8f 26require_once($CFG->libdir . '/tablelib.php');
27
28require_login();
29
30$returnurl = optional_param('returnurl', '', PARAM_LOCALURL);
1e12c120
RT
31$courseid = optional_param('courseid', 0, PARAM_INT);
32$deleterssid = optional_param('deleterssid', 0, PARAM_INT);
f1a34d8f 33
34if ($courseid == SITEID) {
35 $courseid = 0;
36}
37if ($courseid) {
74df2951 38 $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
f1a34d8f 39 $PAGE->set_course($course);
40 $context = $PAGE->context;
41} else {
fe2fdd11 42 $context = context_system::instance();
f1a34d8f 43 $PAGE->set_context($context);
44}
45
46$managesharedfeeds = has_capability('block/rss_client:manageanyfeeds', $context);
47if (!$managesharedfeeds) {
48 require_capability('block/rss_client:manageownfeeds', $context);
49}
50
51$urlparams = array();
52$extraparams = '';
53if ($courseid) {
54 $urlparams['courseid'] = $courseid;
55 $extraparams = '&courseid=' . $courseid;
56}
57if ($returnurl) {
58 $urlparams['returnurl'] = $returnurl;
59 $extraparams = '&returnurl=' . $returnurl;
60}
112c7f05
SH
61$baseurl = new moodle_url('/blocks/rss_client/managefeeds.php', $urlparams);
62$PAGE->set_url($baseurl);
f1a34d8f 63
64// Process any actions
65if ($deleterssid && confirm_sesskey()) {
e760cced 66 $DB->delete_records('block_rss_client', array('id'=>$deleterssid));
f1a34d8f 67
68 redirect($PAGE->url, get_string('feeddeleted', 'block_rss_client'));
69}
70
71// Display the list of feeds.
72if ($managesharedfeeds) {
73 $select = '(userid = ' . $USER->id . ' OR shared = 1)';
74} else {
75 $select = 'userid = ' . $USER->id;
76}
77$feeds = $DB->get_records_select('block_rss_client', $select, null, $DB->sql_order_by_text('title'));
78
79$strmanage = get_string('managefeeds', 'block_rss_client');
80
112c7f05 81$PAGE->set_pagelayout('standard');
f1a34d8f 82$PAGE->set_title($strmanage);
83$PAGE->set_heading($strmanage);
84
a6855934 85$managefeeds = new moodle_url('/blocks/rss_client/managefeeds.php', $urlparams);
7d2a0492 86$PAGE->navbar->add(get_string('blocks'));
cdc018ad 87$PAGE->navbar->add(get_string('pluginname', 'block_rss_client'));
91152a35 88$PAGE->navbar->add(get_string('managefeeds', 'block_rss_client'), $managefeeds);
7d2a0492 89echo $OUTPUT->header();
f1a34d8f 90
91$table = new flexible_table('rss-display-feeds');
92
93$table->define_columns(array('feed', 'actions'));
94$table->define_headers(array(get_string('feed', 'block_rss_client'), get_string('actions', 'moodle')));
112c7f05 95$table->define_baseurl($baseurl);
f1a34d8f 96
97$table->set_attribute('cellspacing', '0');
98$table->set_attribute('id', 'rssfeeds');
99$table->set_attribute('class', 'generaltable generalbox');
100$table->column_class('feed', 'feed');
101$table->column_class('actions', 'actions');
102
103$table->setup();
104
105foreach($feeds as $feed) {
106 if (!empty($feed->preferredtitle)) {
0d4f1ce6 107 $feedtitle = s($feed->preferredtitle);
f1a34d8f 108 } else {
9d10d64e 109 $feedtitle = $feed->title;
f1a34d8f 110 }
111
0f4c64b7 112 $viewlink = html_writer::link($CFG->wwwroot .'/blocks/rss_client/viewfeed.php?rssid=' . $feed->id . $extraparams, $feedtitle);
f1a34d8f 113
0f4c64b7
PS
114 $feedinfo = '<div class="title">' . $viewlink . '</div>' .
115 '<div class="url">' . html_writer::link($feed->url, $feed->url) .'</div>' .
f1a34d8f 116 '<div class="description">' . $feed->description . '</div>';
cd698c8b
DS
117 if ($feed->skipuntil) {
118 $skipuntil = userdate($feed->skipuntil, get_string('strftimedatetime', 'langconfig'));
119 $skipmsg = get_string('failedfeed', 'block_rss_client', $skipuntil);
120 $notification = new \core\output\notification($skipmsg, 'error');
121 $notification->set_show_closebutton(false);
122 $feedinfo .= $OUTPUT->render($notification);
123 }
f1a34d8f 124
c63923bd
PS
125 $editurl = new moodle_url('/blocks/rss_client/editfeed.php?rssid=' . $feed->id . $extraparams);
126 $editaction = $OUTPUT->action_icon($editurl, new pix_icon('t/edit', get_string('edit')));
8ae8bf8a 127
c63923bd
PS
128 $deleteurl = new moodle_url('/blocks/rss_client/managefeeds.php?deleterssid=' . $feed->id . '&sesskey=' . sesskey() . $extraparams);
129 $deleteicon = new pix_icon('t/delete', get_string('delete'));
130 $deleteaction = $OUTPUT->action_icon($deleteurl, $deleteicon, new confirm_action(get_string('deletefeedconfirm', 'block_rss_client')));
8ae8bf8a
PS
131
132 $feedicons = $editaction . ' ' . $deleteaction;
f1a34d8f 133
134 $table->add_data(array($feedinfo, $feedicons));
135}
136
137$table->print_html();
138
5c2ed7e2
PS
139$url = $CFG->wwwroot . '/blocks/rss_client/editfeed.php?' . substr($extraparams, 1);
140echo '<div class="actionbuttons">' . $OUTPUT->single_button($url, get_string('addnewfeed', 'block_rss_client'), 'get') . '</div>';
f1a34d8f 141
142
143if ($returnurl) {
75015e5f 144 echo '<div class="backlink">' . html_writer::link($returnurl, get_string('back')) . '</div>';
f1a34d8f 145}
146
147echo $OUTPUT->footer();