-
Notifications
You must be signed in to change notification settings - Fork 1
/
edit_issuers.php
124 lines (106 loc) · 4.77 KB
/
edit_issuers.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
<?php
// This file is part of Moodle - http:https://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:https://www.gnu.org/licenses/>.
/**
* Interface for adding, editing and removing certification authorities.
*
* @package mod_ilddigitalcert
* @copyright 2020 ILD TH Lübeck <[email protected]>
* @license http:https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__.'/../../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_login();
$context = context_system::instance();
if (has_capability('moodle/site:config', $context)) {
$PAGE->set_context($context);
$PAGE->set_url('/mod/ilddigitalcert/edit_issuers.php');
$PAGE->set_title(get_string('edit_issuers', 'mod_ilddigitalcert'));
$PAGE->set_heading(get_string('edit_issuers', 'mod_ilddigitalcert'));
// Inform moodle which menu entry currently is active!
admin_externalpage_setup('ilddigitalcert_edit_issuers');
$id = optional_param('id', 0, PARAM_INT);
$action = optional_param('action', '', PARAM_RAW);
// Projekte.
$url = new moodle_url('/mod/ilddigitalcert/edit_issuers.php');
$mform = new mod_ilddigitalcert\output\form\edit_issuers_form($url.'?id='.$id, array('issuerid' => $id));
if ($mform->is_cancelled()) {
redirect($url);
} else if ($fromform = $mform->get_data()) {
require_once('locallib.php');
$issuer = new stdClass();
$issuer->name = $fromform->issuername_label;
$issuer->description = $fromform->issuerdescription;
$issuer->email = $fromform->issueremail;
$issuer->url = $fromform->issuerurl;
$issuer->location = $fromform->issuerlocation;
$issuer->zip = $fromform->issuerzip;
$issuer->street = $fromform->issuerstreet;
$issuer->pob = $fromform->issuerpob;
$issuer->address = $fromform->issueraddress;
if (isset($fromform->issuerid) and $fromform->issuerid > 0) {
$issuer->id = $fromform->issuerid;
$DB->update_record('ilddigitalcert_issuer', $issuer);
} else {
$issuer->id = $DB->insert_record('ilddigitalcert_issuer', $issuer);
}
if (isset($issuer->id) and $issuer->id > 0) {
file_save_draft_area_files($fromform->issuerimage,
$context->id,
'mod_ilddigitalcert',
'issuer',
$issuer->id,
array('maxfiles' => 1));
}
redirect($url);
}
echo $OUTPUT->header();
echo html_writer::tag('h1', get_string('overview', 'mod_ilddigitalcert'));
$issuers = $DB->get_records('ilddigitalcert_issuer');
if (count($issuers) > 0) {
echo '<ul>';
foreach ($issuers as $issuer) {
echo '<li>'.$issuer->name.' '.
html_writer::link(
new moodle_url('/mod/ilddigitalcert/edit_issuers.php?id='.$issuer->id.'&action=edit'),
get_string('edit')).' | '.html_writer::link(
new moodle_url('/mod/ilddigitalcert/edit_issuers.php?id='.$issuer->id.'&action=delete'),
get_string('delete')).
'</li>';
}
echo '</ul>';
}
if ($action == 'edit' and $id != 0) {
$result = $DB->get_record('ilddigitalcert_issuer', array('id' => $id));
$toform = new stdClass();
$toform->issuername_label = $result->name;
$toform->issuerdescription = $result->description;
$toform->issueremail = $result->email;
$toform->issuerurl = $result->url;
$toform->issuerlocation = $result->location;
$toform->issuerzip = $result->zip;
$toform->issuerstreet = $result->street;
$toform->issuerpob = $result->pob;
$toform->issueraddress = $result->address;
$draftitemid = file_get_submitted_draft_itemid('issuerimage');
file_prepare_draft_area($draftitemid, $context->id, 'mod_ilddigitalcert', 'issuer', $id, array('maxfiles' => 1));
$toform->issuerimage = $draftitemid;
$mform->set_data($toform);
}
$mform->display();
echo $OUTPUT->footer();
} else {
redirect($CFG->wwwroot);
}