-
Notifications
You must be signed in to change notification settings - Fork 3
/
managelinks.php
88 lines (72 loc) · 3.53 KB
/
managelinks.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
<?php
require_once(dirname(__FILE__) . '/../../config.php');
require_once(dirname(__FILE__) . '/link_edit_form.php');
require_once($CFG->libdir . '/formslib.php');
require_once($CFG->libdir . '/tablelib.php');
$courseid = required_param('courseid', PARAM_INT);
$action = optional_param('action', '', PARAM_ALPHA);
$linkid = optional_param('linkid', '', PARAM_INT);
$baseurl = new moodle_url('/blocks/equella_links/managelinks.php', array('courseid'=>$courseid, 'sesskey' => sesskey()));
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
$context = context_course::instance($courseid);
$PAGE->set_course($course);
$PAGE->set_url($baseurl);
$PAGE->set_pagelayout('standard');
$PAGE->set_heading(get_string('linksaddedit', 'block_equella_links'));
require_capability('block/equella_links:manageanylinks', $context);
require_sesskey();
if (!empty($action)) {
$link = $DB->get_record('block_equella_links', array('id' => $linkid, 'contextid'=>$context->id), '*', MUST_EXIST);
if ($action == 'edit') {
$mform = new equella_links_edit_form($PAGE->url, false);
$mform->set_data(array('title'=>$link->title, 'url'=>$link->url, 'linkid'=>$link->id, 'contextid'=>$context->id));
} else if ($action == 'delete') {
$DB->delete_records('block_equella_links', array('id' => $linkid));
// we are done here
redirect($baseurl);
}
} else {
$mform = new equella_links_edit_form($PAGE->url, true);
}
if ($mform->is_cancelled()) {
redirect($baseurl);
}
if ($formdata = $mform->get_data()) {
if (!empty($formdata->linkid)) {
$editinglink = new stdClass;
$editinglink->id = $formdata->linkid;
$editinglink->title = $formdata->title;
$editinglink->url = $formdata->url;
$editinglink->contextid = $context->id;
$DB->update_record('block_equella_links', $editinglink);
} else {
$addinglink = new stdClass;
$addinglink->title = $formdata->title;
$addinglink->url = $formdata->url;
$addinglink->created = time();
$addinglink->contextid = $context->id;
$DB->insert_record('block_equella_links', $addinglink);
}
redirect($baseurl);
}
echo $OUTPUT->header();
$table = new flexible_table('equella-links-display');
$table->define_columns(array('link', 'title', 'actions'));
$table->define_headers(array(get_string('equellaurl', 'block_equella_links'), get_string('linktitle', 'block_equella_links'), get_string('actions', 'moodle')));
$table->define_baseurl($baseurl);
$table->set_attribute('cellspacing', '0');
$table->set_attribute('class', 'generaltable generalbox');
$table->setup();
$links = $DB->get_records('block_equella_links', array('contextid'=>$context->id));
foreach ($links as $link) {
$editurl = new moodle_url('/blocks/equella_links/managelinks.php', array('linkid'=>$link->id, 'action'=>'edit', 'courseid'=>$courseid, 'sesskey' => sesskey()));
$editaction = $OUTPUT->action_icon($editurl, new pix_icon('t/edit', get_string('edit')));
$deleteurl = new moodle_url('/blocks/equella_links/managelinks.php', array('linkid'=>$link->id, 'action'=>'delete', 'courseid'=>$courseid, 'sesskey' => sesskey()));
$deleteicon = new pix_icon('t/delete', get_string('delete'));
$deleteaction = $OUTPUT->action_icon($deleteurl, $deleteicon, new confirm_action(get_string('deletelinkconfirm', 'block_equella_links')));
$action = $editaction . ' ' . $deleteaction;
$table->add_data(array($link->url, $link->title, $action));
}
$table->print_html();
$mform->display();
echo $OUTPUT->footer();