-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_global_action.php
145 lines (117 loc) · 5.16 KB
/
config_global_action.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This block generates a simple list of links based on the users profile.
*
* @package block_links
* @copyright 2010 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('../../config.php');
require_once($CFG->libdir . '/tablelib.php');
global $DB;
$delete = optional_param('delete', 0, PARAM_INT);
require_login();
$context = context_system::instance();
if ((!has_capability('moodle/site:manageblocks', $context)) || (!has_capability('block/links:managelinks', $context))) {
throw new moodle_exception('accessdenied', 'block_links');
}
$strmanagelinks = get_string('managelinks', 'block_links');
// Print the header.
$urlparams = array();
$baseurl = new moodle_url('/blocks/links/config_global_action.php', $urlparams);
$PAGE->set_url($baseurl);
$PAGE->set_context($context);
$PAGE->navbar->add(get_string('blocks'));
$PAGE->navbar->add(get_string('pluginname', 'block_links'), $baseurl);
$PAGE->navbar->add($strmanagelinks);
$PAGE->set_title($strmanagelinks);
$PAGE->set_heading(format_string($strmanagelinks));
$PAGE->set_pagelayout('standard');
if (($delete > 0) && confirm_sesskey()) {
// Trigger event about deleting the link.
$params = array('context' => $context, 'objectid' => $delete);
$event = \block_links\event\link_deleted::create($params);
$event->trigger();
$DB->delete_records('block_links', array('id' => $delete));
}
$rs = $DB->get_records('block_links', null, 'linktext');
if (!is_array($rs)) {
$rs = array();
}
// Check to see if we have any records.
if (count($rs) == 0) {
$add = 1;
}
echo $OUTPUT->header();
echo html_writer::start_tag('div', array('class' => 'content'));
echo html_writer::tag('h2', $strmanagelinks, array('class' => 'main'));
// Generate the table.
echo html_writer::start_tag('form', array('method' => 'post', 'action' => $baseurl));
$table = new flexible_table('links-administration');
$table->define_columns(array('linktext', 'url', 'notes', 'defaultshow', 'category', 'actions'));
$table->define_headers(array(get_string('linktext', 'block_links'),
get_string('url', 'block_links'),
get_string('notes', 'block_links'),
get_string('defaultshow', 'block_links'),
get_string('category', 'block_links'),
get_string('actions', 'moodle')));
$table->define_baseurl($baseurl);
$table->set_attribute('cellspacing', '0');
$table->set_attribute('id', 'links');
$table->set_attribute('class', 'generaltable generalbox');
$table->column_class('linktext', 'linktext');
$table->column_class('url', 'url');
$table->column_class('notes', 'notes');
$table->column_class('defaultshow', 'defaultshow');
$table->column_class('category', 'category');
$table->column_class('actions', 'actions');
$table->setup();
foreach ($rs as $index => $link) {
if ($link->defaultshow == '1') {
$show = get_string('yes');
} else {
$show = get_string('no');
}
// Default Key 'All' is stored in the DB, Allow it to be translated.
if ($link->department === 'All') {
$department = get_string('all', 'block_links');
} else {
$department = $link->department;
}
$editurl = new moodle_url('/blocks/links/edit.php', array('id' => $link->id));
$editaction = $OUTPUT->action_icon($editurl, new pix_icon('t/edit', get_string('edit')));
$deleteurl = new moodle_url('/blocks/links/config_global_action.php', array('delete' => $link->id, 'sesskey' => sesskey()));
$deleteicon = new pix_icon('t/delete', get_string('delete'));
$deleteaction = $OUTPUT->action_icon($deleteurl, $deleteicon,
new confirm_action(get_string('deletelinkconfirm', 'block_links')));
$icons = $editaction . ' ' . $deleteaction;
$table->add_data(array($link->linktext,
html_writer::link($link->url, $link->url, array('target' => '_blank')),
$link->notes,
$show,
$department,
$icons));
}
$table->print_html();
echo html_writer::end_tag('form');
echo html_writer::start_tag('div', array('class' => 'actionbuttons'));
echo html_writer::empty_tag('hr', array());
$addurl = new moodle_url('/blocks/links/edit.php', array());
echo $OUTPUT->single_button($addurl, get_string('addlink', 'block_links'), 'get');
echo html_writer::end_tag('div');
echo html_writer::end_tag('div');
echo $OUTPUT->footer();