d9e76d33d034e094673d421e33abb4aadff67242
[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     }
54     print_header("Admin: Setting up site", "Administration: Setting up site",
55                   "<A HREF=\"$CFG->wwwroot/admin/\">Admin</A> -> Setting up site", "$focus");
57     print_simple_box_start("center", "", "$THEME->cellheading");
58     print_heading("Editing site settings");
59         include("site.html");
60     print_simple_box_end();
61     print_footer();
63     exit;
65 /// Functions /////////////////////////////////////////////////////////////////
67 function validate_form(&$form, &$err) {
69     if (empty($form->fullname))
70         $err["fullname"] = "Missing site name";
72     if (empty($form->shortname))
73         $err["shortname"] = "Missing short site name";
75     if (empty($form->summary))
76         $err["summary"] = "Missing site description";
78     return;
79 }
82 ?>