Changes to allow choice of format on home page of site
[moodle.git] / admin / site.php
CommitLineData
f9903ed0 1<?PHP // $Id$
2
3 require("../config.php");
4
5 $course = get_record("course", "category", 0);
6
7/// If data submitted, then process and store.
8
9 if (match_referer() && isset($HTTP_POST_VARS)) {
10
11 $form = (object)$HTTP_POST_VARS;
12
13 validate_form($form, $err);
14
15 if (count($err) == 0) {
16
17 $form->timemodified = time();
18
19 if ($form->id) {
20 if (update_record("course", $form)) {
f9903ed0 21 redirect("$CFG->wwwroot/admin/", "Changes saved");
22 } else {
23 error("Serious Error! Could not update the course record! (id = $form->id)");
24 }
25 } else {
26 if ($newid = insert_record("course", $form)) {
27 $cat->name = "General";
28 if (insert_record("course_categories", $cat)) {
f9903ed0 29 redirect("$CFG->wwwroot/admin/", "Changes saved", "1");
30 } else {
31 error("Serious Error! Could not set up the default categories!");
32 }
33 } else {
34 error("Serious Error! Could not set up the site!");
35 }
36 }
37 die;
38 } else {
39 foreach ($err as $key => $value) {
40 $focus = "form.$key";
41 }
42
43 }
44 }
45
46/// Otherwise fill and print the form.
47
48 if ($course && !$form) {
49 $form = $course;
50 } else {
51 $form->category = 0;
d887b5a7 52 $form->format = 1;
f9903ed0 53 }
54
55 print_header("Admin: Setting up site", "Administration: Setting up site",
56 "<A HREF=\"$CFG->wwwroot/admin/\">Admin</A> -> Setting up site", "$focus");
57
58 print_simple_box_start("center", "", "$THEME->cellheading");
59 print_heading("Editing site settings");
60 include("site.html");
61 print_simple_box_end();
62 print_footer();
63
64 exit;
65
66/// Functions /////////////////////////////////////////////////////////////////
67
68function validate_form(&$form, &$err) {
69
70 if (empty($form->fullname))
71 $err["fullname"] = "Missing site name";
72
73 if (empty($form->shortname))
74 $err["shortname"] = "Missing short site name";
75
76 if (empty($form->summary))
77 $err["summary"] = "Missing site description";
78
79 return;
80}
81
82
83?>