MDL-48934 navigation: Update the default entries in the user menu.
[moodle.git] / blog / external_blogs.php
CommitLineData
b57d3959 1<?php
b57d3959
NC
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/>.
16
17
18/**
19 * List of external blogs for current user.
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 */
26
27require_once('../config.php');
28require_once('lib.php');
29
30require_login();
41b38360 31$context = context_system::instance();
2713c6bd
SH
32$PAGE->set_context($context);
33$PAGE->set_url(new moodle_url('/blog/external_blogs.php'));
34require_capability('moodle/blog:manageexternal', $context);
b57d3959
NC
35
36$delete = optional_param('delete', null, PARAM_INT);
37
2b6e53e8
AD
38$strexternalblogs = get_string('externalblogs', 'blog');
39$straddnewexternalblog = get_string('addnewexternalblog', 'blog');
40$strblogs = get_string('blogs', 'blog');
b57d3959
NC
41$message = null;
42
43if ($delete && confirm_sesskey()) {
44 $externalbloguserid = $DB->get_field('blog_external', 'userid', array('id' => $delete));
45 if ($externalbloguserid == $USER->id) {
2b6e53e8 46 // Delete the external blog.
b57d3959 47 $DB->delete_records('blog_external', array('id' => $delete));
4db11a24 48
2b6e53e8 49 // Delete the external blog's posts.
4db11a24
AD
50 $deletewhere = 'module = :module
51 AND userid = :userid
52 AND ' . $DB->sql_isnotempty('post', 'uniquehash', false, false) . '
53 AND ' . $DB->sql_compare_text('content') . ' = ' . $DB->sql_compare_text(':delete');
2b6e53e8
AD
54 $DB->delete_records_select('post', $deletewhere, array('module' => 'blog_external',
55 'userid' => $USER->id,
56 'delete' => $delete));
4db11a24 57
b57d3959 58 $message = get_string('externalblogdeleted', 'blog');
6f5e0852 59 }
b57d3959
NC
60}
61
62$blogs = $DB->get_records('blog_external', array('userid' => $USER->id));
63
b57d3959
NC
64$PAGE->set_heading("$SITE->shortname: $strblogs: $strexternalblogs", $SITE->fullname);
65$PAGE->set_title("$SITE->shortname: $strblogs: $strexternalblogs");
897aa80c 66$PAGE->set_pagelayout('standard');
b57d3959
NC
67
68echo $OUTPUT->header();
69echo $OUTPUT->heading($strexternalblogs, 2);
70
71if (!empty($message)) {
72 echo $OUTPUT->notification($message);
73}
74
75echo $OUTPUT->box_start('generalbox boxaligncenter');
76
77if (!empty($blogs)) {
78 $table = new html_table();
79 $table->cellpadding = 4;
16be8974 80 $table->attributes['class'] = 'generaltable boxaligncenter';
2b6e53e8
AD
81 $table->head = array(get_string('name'),
82 get_string('url', 'blog'),
83 get_string('timefetched', 'blog'),
84 get_string('valid', 'blog'),
85 get_string('actions'));
b57d3959
NC
86
87 foreach ($blogs as $blog) {
b57d3959 88 if ($blog->failedlastsync) {
c3847443 89 $validicon = $OUTPUT->pix_icon('i/invalid', get_string('feedisinvalid', 'blog'));
1ba862ec 90 } else {
c3847443 91 $validicon = $OUTPUT->pix_icon('i/valid', get_string('feedisvalid', 'blog'));
b57d3959
NC
92 }
93
a6855934 94 $editurl = new moodle_url('/blog/external_blog_edit.php', array('id' => $blog->id));
c63923bd 95 $editicon = $OUTPUT->action_icon($editurl, new pix_icon('t/edit', get_string('editexternalblog', 'blog')));
8ae8bf8a 96
91663dc3
MD
97 $deletelink = new moodle_url('/blog/external_blogs.php', array('delete' => $blog->id, 'sesskey'=>sesskey()));
98 $deleteicon = $OUTPUT->action_icon($deletelink, new pix_icon('t/delete', get_string('deleteexternalblog', 'blog')));
8ae8bf8a 99
2b6e53e8
AD
100 $table->data[] = new html_table_row(array($blog->name,
101 $blog->url,
102 userdate($blog->timefetched),
103 $validicon,
104 $editicon . '&nbsp'. $deleteicon));
b57d3959 105 }
16be8974 106 echo html_writer::table($table);
b57d3959
NC
107}
108
a6855934 109$newexternalurl = new moodle_url('/blog/external_blog_edit.php');
75015e5f 110echo html_writer::link($newexternalurl, $straddnewexternalblog);
b57d3959
NC
111echo $OUTPUT->box_end();
112echo $OUTPUT->footer();