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