3 require_once('../config.php');
4 require_once('../course/lib.php');
6 if ($site = get_site()) {
9 error("You need to be admin to edit this page");
11 $site->format
= "social"; // override
14 $focus = "form.fullname";
16 /// If data submitted, then process and store.
18 if ($form = data_submitted()) {
20 if (!empty($USER->id
)) { // Additional identity check
21 if (!confirm_sesskey()) {
22 error(get_string('confirmsesskeybad', 'error'));
26 validate_form($form, $err);
28 if (count($err) == 0) {
30 $form->frontpage
= array_flip($form->frontpage
);
31 unset($form->frontpage
[0]);
32 $form->frontpage
= array_flip($form->frontpage
);
33 asort($form->frontpage
);
34 $form->frontpage
= implode(',',array_flip($form->frontpage
));
35 set_config("frontpage", $form->frontpage
);
36 if ($form->frontpage
== '') {
37 $form->numsections
= 1; // Force the topic display for this format
40 $form->frontpageloggedin
= array_flip($form->frontpageloggedin
);
41 unset($form->frontpageloggedin
[0]);
42 $form->frontpageloggedin
= array_flip($form->frontpageloggedin
);
43 asort($form->frontpageloggedin
);
44 $form->frontpageloggedin
= implode(',',array_flip($form->frontpageloggedin
));
45 set_config("frontpageloggedin", $form->frontpageloggedin
);
47 $form->timemodified
= time();
50 if (update_record("course", $form)) {
51 redirect("$CFG->wwwroot/", get_string("changessaved"));
53 error("Serious Error! Could not update the site record! (id = $form->id)");
56 // We are about to create the site "course"
57 require_once($CFG->dirroot
.'/lib/blocklib.php');
59 if ($newid = insert_record('course', $form)) {
61 // Site created, add blocks for it
62 $page = page_create_object(PAGE_COURSE_VIEW
, $newid);
63 blocks_repopulate_page($page); // Return value not checked because you can always edit later
65 $cat->name
= get_string('miscellaneous');
66 if (insert_record('course_categories', $cat)) {
67 redirect("$CFG->wwwroot/$CFG->admin/index.php", get_string("changessaved"), 1);
69 error("Serious Error! Could not set up a default course category!");
72 error("Serious Error! Could not set up the site!");
78 foreach ($err as $key => $value) {
84 /// Otherwise fill and print the form.
86 if ($site and empty($form)) {
92 $form->shortname
= "";
95 $form->numsections
= 0;
98 $form->format
= 'site'; // Only for this course
99 $form->teacher
= get_string("defaultcourseteacher");
100 $form->teachers
= get_string("defaultcourseteachers");
101 $form->student
= get_string("defaultcoursestudent");
102 $form->students
= get_string("defaultcoursestudents");
106 if (isset($CFG->frontpage
)) {
107 $form->frontpage
= $CFG->frontpage
;
109 $form->frontpage
= FRONTPAGECOURSELIST
; // Show course list by default
110 set_config("frontpage", $form->frontpage
);
113 if (isset($CFG->frontpageloggedin
)) {
114 $form->frontpageloggedin
= $CFG->frontpageloggedin
;
116 $form->frontpageloggedin
= $form->frontpage
;
117 set_config("frontpageloggedin", $form->frontpageloggedin
);
120 $stradmin = get_string("administration");
121 $strconfiguration = get_string("configuration");
122 $strsitesettings = get_string("sitesettings");
126 print_heading($strsitesettings);
127 print_simple_box(get_string("configintrosite", 'admin'), "center", "50%");
130 print_header("$site->shortname: $strsitesettings", "$site->fullname",
131 "<a href=\"index.php\">$stradmin</a> -> ".
132 "<a href=\"configure.php\">$strconfiguration</a> -> $strsitesettings", "$focus");
133 print_heading($strsitesettings);
136 if (empty($USER->id
)) { // New undefined admin user
137 $USER->htmleditor
= true;
140 $sesskey = $USER->sesskey
;
142 $usehtmleditor = can_use_html_editor();
143 $defaultformat = FORMAT_HTML
;
145 print_simple_box_start("center", "");
146 include("site.html");
147 print_simple_box_end();
149 if ($usehtmleditor) {
159 /// Functions /////////////////////////////////////////////////////////////////
161 function validate_form(&$form, &$err) {
163 if (empty($form->fullname
))
164 $err["fullname"] = get_string("missingsitename");
166 if (empty($form->shortname
))
167 $err["shortname"] = get_string("missingshortsitename");