forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsite.php
162 lines (129 loc) · 4.91 KB
/
site.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php // $Id$
require_once("../config.php");
require_once("../course/lib.php");
if ($site = get_site()) {
require_login();
if (!isadmin()) {
error("You need to be admin to edit this page");
}
$site->format = "social"; // override
}
/// If data submitted, then process and store.
if ($form = data_submitted()) {
if (!empty($USER->id)) { // Additional identity check
if (!confirm_sesskey()) {
error(get_string('confirmsesskeybad', 'error'));
}
}
validate_form($form, $err);
if (count($err) == 0) {
$form->frontpage = array_flip($form->frontpage);
unset($form->frontpage[0]);
$form->frontpage = array_flip($form->frontpage);
asort($form->frontpage);
$form->frontpage = implode(',',array_flip($form->frontpage));
set_config("frontpage", $form->frontpage);
if (!$form->frontpage) {
$form->numsections = 1; // Force the topic display for this format
}
$form->timemodified = time();
if ($form->id) {
if (update_record("course", $form)) {
redirect("$CFG->wwwroot/", get_string("changessaved"));
} else {
error("Serious Error! Could not update the site record! (id = $form->id)");
}
} else {
// We are about to create the site "course"
require_once($CFG->dirroot.'/lib/blocklib.php');
if ($newid = insert_record('course', $form)) {
// Site created, add blocks for it
$page = page_create_object(PAGE_COURSE_VIEW, $newid);
blocks_repopulate_page($page); // Return value not checked because you can always edit later
$cat->name = get_string('miscellaneous');
if (insert_record('course_categories', $cat)) {
redirect("$CFG->wwwroot/$CFG->admin/index.php", get_string("changessaved"), 1);
} else {
error("Serious Error! Could not set up a default course category!");
}
} else {
error("Serious Error! Could not set up the site!");
}
}
die;
} else {
foreach ($err as $key => $value) {
$focus = "form.$key";
}
}
}
/// Otherwise fill and print the form.
if ($site and empty($form)) {
$form = $site;
$course = $site;
$firsttime = false;
} else {
$form->fullname = "";
$form->shortname = "";
$form->summary = "";
$form->newsitems = 3;
$form->numsections = 0;
$form->id = "";
$form->category = 0;
$form->format = 'site'; // Only for this course
$form->teacher = get_string("defaultcourseteacher");
$form->teachers = get_string("defaultcourseteachers");
$form->student = get_string("defaultcoursestudent");
$form->students = get_string("defaultcoursestudents");
$firsttime = true;
}
if (isset($CFG->frontpage)) {
$form->frontpage = $CFG->frontpage;
} else {
$form->frontpage = FRONTPAGECOURSELIST; // Show course list by default
set_config("frontpage", $form->frontpage);
}
if (empty($focus)) {
$focus = "form.fullname";
}
$stradmin = get_string("administration");
$strconfiguration = get_string("configuration");
$strsitesettings = get_string("sitesettings");
if ($firsttime) {
print_header();
print_heading($strsitesettings);
print_simple_box(get_string("configintrosite", 'admin'), "center", "50%");
echo "<br />";
} else {
print_header("$site->shortname: $strsitesettings", "$site->fullname",
"<a href=\"index.php\">$stradmin</a> -> ".
"<a href=\"configure.php\">$strconfiguration</a> -> $strsitesettings", "$focus");
print_heading($strsitesettings);
}
if (empty($USER->id)) { // New undefined admin user
$USER->htmleditor = true;
$sesskey = '';
} else {
$sesskey = $USER->sesskey;
}
$usehtmleditor = can_use_html_editor();
$defaultformat = FORMAT_HTML;
print_simple_box_start("center", "");
include("site.html");
print_simple_box_end();
if ($usehtmleditor) {
use_html_editor();
}
if (!$firsttime) {
print_footer();
}
exit;
/// Functions /////////////////////////////////////////////////////////////////
function validate_form(&$form, &$err) {
if (empty($form->fullname))
$err["fullname"] = get_string("missingsitename");
if (empty($form->shortname))
$err["shortname"] = get_string("missingshortsitename");
return;
}
?>