-
Notifications
You must be signed in to change notification settings - Fork 3
/
edit.php
92 lines (72 loc) · 2.57 KB
/
edit.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
<?php
/**
* Edit institution settings
* @copyright 2013 Bruno Sampaio
*/
require_once('../../config.php');
require_once('lib.php');
require_once('edit_form.php');
require_login();
$id = optional_param('id', 0, PARAM_INT); // institution id
$site = get_site();
$strinstitution = get_string('institution', 'local_institutions');
$strinstitutions = get_string('institutions', 'local_institutions');
$straddinstitution = get_string('add-institution', 'local_institutions');
$streditinstitution = get_string('edit-institution', 'local_institutions');
$stradministration = get_string("administration");
$PAGE->set_pagelayout('admin');
$PAGE->set_url('/local/institutions/edit.php');
$PAGE->set_context(context_system::instance());
$sitecontext = get_context_instance(CONTEXT_SYSTEM);
if(has_capability('moodle/site:config', $sitecontext)) {
if(!local_institutions_table_exists()) { //Table not exists
redirect(new moodle_url($CFG->wwwroot.'/local/institutions/error.php'));
}
else {
// basic access control checks
if($id) { // editing institution
$institution = $DB->get_record(INSTITUTIONS_TABLE, array('id'=>$id), '*', MUST_EXIST);
$PAGE->url->param('id',$id);
}
else {
$institution = array();
}
// first create the form
$editform = new institution_edit_form(NULL, array('institution'=>$institution));
if($editform->is_cancelled()) {
redirect(new moodle_url($CFG->wwwroot.'/local/institutions/'));
}
else if($data = $editform->get_data()) {
// process data if submitted
if(empty($institution->id)) {
// Create the institution
$institution = local_institutions_create($data);
} else {
// Update the institution
local_institutions_update($data);
}
redirect(new moodle_url($CFG->wwwroot.'/local/institutions/view.php?id='.$institution->id));
}
$PAGE->navbar->add($stradministration, new moodle_url('/admin/index.php'));
$PAGE->navbar->add($straddinstitution, new moodle_url('/local/institutions/index.php'));
if (!empty($institution->id)) {
$PAGE->navbar->add($streditinstitution);
$title = "$site->shortname: $streditinstitution";
$fullname = $institution->fullname;
} else {
$PAGE->navbar->add($straddinstitution);
$title = "$site->shortname: $straddinstitution";
$fullname = $site->fullname;
}
$PAGE->set_title($title);
$PAGE->set_heading($fullname);
echo $OUTPUT->header();
echo $OUTPUT->heading($streditinstitution);
// Print the form
$editform->display();
echo $OUTPUT->footer();
}
}
else {
redirect(new moodle_url($CFG->wwwroot));
}