Automatic installer.php lang files by installer_builder (20081224)
[moodle.git] / admin / site.php
blobce06de6b96565bbab28e9d24fbb44404013c6507
1 <?php // $Id$
3 require_once('../config.php');
4 require_once('../course/lib.php');
6 if ($site = get_site()) {
7 require_login();
8 if (!isadmin()) {
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();
49 if ($form->id) {
50 if (update_record("course", $form)) {
51 redirect("$CFG->wwwroot/", get_string("changessaved"));
52 } else {
53 error("Serious Error! Could not update the site record! (id = $form->id)");
55 } else {
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);
68 } else {
69 error("Serious Error! Could not set up a default course category!");
71 } else {
72 error("Serious Error! Could not set up the site!");
75 die;
77 } else {
78 foreach ($err as $key => $value) {
79 $focus = "form.$key";
84 /// Otherwise fill and print the form.
86 if ($site and empty($form)) {
87 $form = $site;
88 $course = $site;
89 $firsttime = false;
90 } else {
91 $form->fullname = "";
92 $form->shortname = "";
93 $form->summary = "";
94 $form->newsitems = 3;
95 $form->numsections = 0;
96 $form->id = "";
97 $form->category = 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");
103 $firsttime = true;
106 if (isset($CFG->frontpage)) {
107 $form->frontpage = $CFG->frontpage;
108 } else {
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;
115 } else {
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");
124 if ($firsttime) {
125 print_header();
126 print_heading($strsitesettings);
127 print_simple_box(get_string("configintrosite", 'admin'), "center", "50%");
128 echo "<br />";
129 } else {
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;
138 $sesskey = '';
139 } else {
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) {
150 use_html_editor();
153 if (!$firsttime) {
154 print_footer();
157 exit;
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");
169 return;