MDL-40266 improve emulate_bound_params() for mysqli
[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();
2713c6bd
SH
32$context = get_context_instance(CONTEXT_SYSTEM);
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) {
fb1b0bc0 47 // Delete the external blog
b57d3959 48 $DB->delete_records('blog_external', array('id' => $delete));
fb1b0bc0
AD
49
50 // Delete the external blog's posts
51 $deletewhere = 'module = :module
52 AND userid = :userid
53 AND ' . $DB->sql_isnotempty('post', 'uniquehash', false, false) . '
54 AND ' . $DB->sql_compare_text('content') . ' = ' . $DB->sql_compare_text(':delete');
55 $DB->delete_records_select('post', $deletewhere, array('module' => 'blog_external', 'userid' => $USER->id, 'delete' => $delete));
56
b57d3959 57 $message = get_string('externalblogdeleted', 'blog');
6f5e0852 58 }
b57d3959
NC
59}
60
61$blogs = $DB->get_records('blog_external', array('userid' => $USER->id));
62
b57d3959
NC
63$PAGE->set_heading("$SITE->shortname: $strblogs: $strexternalblogs", $SITE->fullname);
64$PAGE->set_title("$SITE->shortname: $strblogs: $strexternalblogs");
897aa80c 65$PAGE->set_pagelayout('standard');
b57d3959
NC
66
67echo $OUTPUT->header();
68echo $OUTPUT->heading($strexternalblogs, 2);
69
70if (!empty($message)) {
71 echo $OUTPUT->notification($message);
72}
73
74echo $OUTPUT->box_start('generalbox boxaligncenter');
75
76if (!empty($blogs)) {
77 $table = new html_table();
78 $table->cellpadding = 4;
16be8974 79 $table->attributes['class'] = 'generaltable boxaligncenter';
06aad19c 80 $table->head = array(get_string('name'), get_string('url', 'blog'), get_string('timefetched', 'blog'), get_string('valid', 'blog'), get_string('actions'));
b57d3959
NC
81
82 foreach ($blogs as $blog) {
b57d3959 83 if ($blog->failedlastsync) {
000c278c 84 $validicon = $OUTPUT->pix_icon('i/cross_red_big', get_string('feedisinvalid', 'blog'));
1ba862ec 85 } else {
000c278c 86 $validicon = $OUTPUT->pix_icon('i/tick_green_big', get_string('feedisvalid', 'blog'));
b57d3959
NC
87 }
88
a6855934 89 $editurl = new moodle_url('/blog/external_blog_edit.php', array('id' => $blog->id));
c63923bd 90 $editicon = $OUTPUT->action_icon($editurl, new pix_icon('t/edit', get_string('editexternalblog', 'blog')));
8ae8bf8a 91
91663dc3
MD
92 $deletelink = new moodle_url('/blog/external_blogs.php', array('delete' => $blog->id, 'sesskey'=>sesskey()));
93 $deleteicon = $OUTPUT->action_icon($deletelink, new pix_icon('t/delete', get_string('deleteexternalblog', 'blog')));
8ae8bf8a 94
91663dc3 95 $table->data[] = new html_table_row(array($blog->name, $blog->url, userdate($blog->timefetched), $validicon, $editicon . '&nbsp'. $deleteicon));
b57d3959 96 }
16be8974 97 echo html_writer::table($table);
b57d3959
NC
98}
99
a6855934 100$newexternalurl = new moodle_url('/blog/external_blog_edit.php');
75015e5f 101echo html_writer::link($newexternalurl, $straddnewexternalblog);
b57d3959
NC
102echo $OUTPUT->box_end();
103echo $OUTPUT->footer();