Merge branch 'install_21_STABLE' of git://git.moodle.cz/moodle-install into MOODLE_21...
[moodle.git] / blog / external_blogs.php
blob988a046605998ad1d730b30cea8e6914cf2cdfff
1 <?php
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.
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/>.
19 /**
20 * List of external blogs for current user.
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
28 require_once('../config.php');
29 require_once('lib.php');
31 require_login();
32 $context = get_context_instance(CONTEXT_SYSTEM);
33 $PAGE->set_context($context);
34 $PAGE->set_url(new moodle_url('/blog/external_blogs.php'));
35 require_capability('moodle/blog:manageexternal', $context);
37 $delete = optional_param('delete', null, PARAM_INT);
39 $strexternalblogs = get_string('externalblogs','blog');
40 $straddnewexternalblog = get_string('addnewexternalblog','blog');
41 $strblogs = get_string('blogs','blog');
42 $message = null;
44 if ($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');
52 $blogs = $DB->get_records('blog_external', array('userid' => $USER->id));
54 $PAGE->set_heading("$SITE->shortname: $strblogs: $strexternalblogs", $SITE->fullname);
55 $PAGE->set_title("$SITE->shortname: $strblogs: $strexternalblogs");
56 $PAGE->set_pagelayout('standard');
58 echo $OUTPUT->header();
59 echo $OUTPUT->heading($strexternalblogs, 2);
61 if (!empty($message)) {
62 echo $OUTPUT->notification($message);
65 echo $OUTPUT->box_start('generalbox boxaligncenter');
67 if (!empty($blogs)) {
68 $table = new html_table();
69 $table->cellpadding = 4;
70 $table->attributes['class'] = 'generaltable boxaligncenter';
71 $table->head = array(get_string('name'), get_string('url'), get_string('timefetched', 'blog'), get_string('valid', 'blog'), get_string('actions'));
73 foreach ($blogs as $blog) {
74 if ($blog->failedlastsync) {
75 $validicon = $OUTPUT->pix_icon('i/cross_red_big', get_string('feedisinvalid', 'blog'));
76 } else {
77 $validicon = $OUTPUT->pix_icon('i/tick_green_big', get_string('feedisvalid', 'blog'));
80 $editurl = new moodle_url('/blog/external_blog_edit.php', array('id' => $blog->id));
81 $editicon = $OUTPUT->action_icon($editurl, new pix_icon('t/edit', get_string('editexternalblog', 'blog')));
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')));
86 $table->data[] = new html_table_row(array($blog->name, $blog->url, userdate($blog->timefetched), $validicon, $editicon . '&nbsp'. $deleteicon));
88 echo html_writer::table($table);
91 $newexternalurl = new moodle_url('/blog/external_blog_edit.php');
92 echo html_writer::link($newexternalurl, $straddnewexternalblog);
93 echo $OUTPUT->box_end();
94 echo $OUTPUT->footer();