f9301ac84faf628c6b0605f19ab4eeb506ac0690
[moodle.git] / admin / site.php
1 <?PHP // $Id$
3         require("../config.php");
5     $course = get_record("course", "category", 0);
7 /// If data submitted, then process and store.
9         if (match_referer() && isset($HTTP_POST_VARS)) {
11         $form = (object)$HTTP_POST_VARS;
13         validate_form($form, $err);
15         if (count($err) == 0) {
17             $form->timemodified = time();
19             if ($form->id) {
20                 if (update_record("course", $form)) {
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)) {
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         }
46 /// Otherwise fill and print the form.
48     if ($course && !$form) {
49         $form = $course;
50     } else {
51         $form->category = 0;
52         $form->format = 1;
53     }
55     print_header("Admin: Setting up site", "Administration: Setting up site",
56                   "<A HREF=\"$CFG->wwwroot/admin/\">Admin</A> -> Setting up site", "$focus");
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();
64     exit;
66 /// Functions /////////////////////////////////////////////////////////////////
68 function validate_form(&$form, &$err) {
70     if (empty($form->fullname))
71         $err["fullname"] = "Missing site name";
73     if (empty($form->shortname))
74         $err["shortname"] = "Missing short site name";
76     if (empty($form->summary))
77         $err["summary"] = "Missing site description";
79     return;
80 }
83 ?>