Updated the HEAD build version to 20100102
[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();
32
33$PAGE->set_url('/blog/external_blogs.php');
34require_capability('moodle/blog:manageexternal', get_context_instance(CONTEXT_SYSTEM));
35
36$delete = optional_param('delete', null, PARAM_INT);
37
38$strexternalblogs = get_string('externalblogs','blog');
39$straddnewexternalblog = get_string('addnewexternalblog','blog');
40$strblogs = get_string('blogs','blog');
41$message = null;
42
43if ($delete && confirm_sesskey()) {
44 $externalbloguserid = $DB->get_field('blog_external', 'userid', array('id' => $delete));
45 if ($externalbloguserid == $USER->id) {
46 $DB->delete_records('blog_external', array('id' => $delete));
47 $message = get_string('externalblogdeleted', 'blog');
6f5e0852 48 }
b57d3959
NC
49}
50
51$blogs = $DB->get_records('blog_external', array('userid' => $USER->id));
52
53$PAGE->navbar->add(fullname($USER), new moodle_url($CFG->wwwroot.'/user/view.php', array('id'=>$USER->id)));
54$PAGE->navbar->add($strblogs, new moodle_url($CFG->wwwroot.'/blog/index.php', array('userid'=>$USER->id)));
55$PAGE->navbar->add($strexternalblogs);
56$PAGE->set_heading("$SITE->shortname: $strblogs: $strexternalblogs", $SITE->fullname);
57$PAGE->set_title("$SITE->shortname: $strblogs: $strexternalblogs");
58
59echo $OUTPUT->header();
60echo $OUTPUT->heading($strexternalblogs, 2);
61
62if (!empty($message)) {
63 echo $OUTPUT->notification($message);
64}
65
66echo $OUTPUT->box_start('generalbox boxaligncenter');
67
68if (!empty($blogs)) {
69 $table = new html_table();
70 $table->cellpadding = 4;
71 $table->add_class('generaltable boxaligncenter');
72 $table->head = array(get_string('name'), get_string('url'), get_string('timefetched', 'blog'), get_string('valid', 'blog'), get_string('actions'));
73
74 foreach ($blogs as $blog) {
b57d3959 75 if ($blog->failedlastsync) {
b5270630 76 $validicon = $OUTPUT->image('i/cross_red_big', array('alt'=>get_string('feedisinvalid', 'blog'), 'title'=>get_string('feedisinvalid', 'blog')));
1ba862ec 77 } else {
b5270630 78 $validicon = $OUTPUT->image('i/tick_green_big', array('alt'=>get_string('feedisvalid', 'blog'), 'title'=>get_string('feedisvalid', 'blog')));
b57d3959
NC
79 }
80
81 $editicon = new moodle_action_icon;
82 $editicon->link->url = new moodle_url($CFG->wwwroot.'/blog/external_blog_edit.php', array('id' => $blog->id));
83 $editicon->link->title = get_string('editexternalblog', 'blog');
b5d0cafc 84 $editicon->image->src = $OUTPUT->pix_url('t/edit');
b57d3959
NC
85 $editicon->image->alt = get_string('editexternalblog', 'blog');
86
87 $deleteicon = new moodle_action_icon;
88 $deleteicon->link->url = new moodle_url($CFG->wwwroot.'/blog/external_blogs.php', array('delete' => $blog->id, 'sesskey' => sesskey()));
89 $deleteicon->link->title = get_string('deleteexternalblog', 'blog');
b5d0cafc 90 $deleteicon->image->src = $OUTPUT->pix_url('t/delete');
b57d3959
NC
91 $deleteicon->image->alt = get_string('deleteexternalblog', 'blog');
92 $deleteicon->add_confirm_action(get_string('externalblogdeleteconfirm', 'blog'));
93 $icons = $OUTPUT->action_icon($editicon) . $OUTPUT->action_icon($deleteicon);
b5270630 94 $table->data[] = html_table_row::make(array($blog->name, $blog->url, userdate($blog->timefetched), $validicon, $icons));
b57d3959
NC
95 }
96 echo $OUTPUT->table($table);
97}
98
99$newexternalurl = new moodle_url($CFG->wwwroot.'/blog/external_blog_edit.php');
100echo $OUTPUT->link(html_link::make($newexternalurl, $straddnewexternalblog));
101echo $OUTPUT->box_end();
102echo $OUTPUT->footer();