moodle/admin/site.php

95 lines
2.5 KiB
PHP
Raw Normal View History

2001-11-22 06:23:56 +00:00
<?PHP // $Id$
require_once("../config.php");
2001-11-22 06:23:56 +00:00
if ($site = get_site()) {
if (!isadmin()) {
error("You need to be admin to edit this page");
}
}
$site->format = "social"; // override
2001-11-22 06:23:56 +00:00
/// If data submitted, then process and store.
if ($form = data_submitted()) {
2001-11-22 06:23:56 +00:00
validate_form($form, $err);
if (count($err) == 0) {
$form->timemodified = time();
if ($form->id) {
if (update_record("course", $form)) {
2002-12-30 05:13:43 +00:00
redirect("index.php", get_string("changessaved"));
2001-11-22 06:23:56 +00:00
} else {
error("Serious Error! Could not update the site record! (id = $form->id)");
2001-11-22 06:23:56 +00:00
}
} else {
if ($newid = insert_record("course", $form)) {
$cat->name = get_string("miscellaneous");
2001-11-22 06:23:56 +00:00
if (insert_record("course_categories", $cat)) {
2002-12-30 05:13:43 +00:00
redirect("index.php", get_string("changessaved"), "1");
2001-11-22 06:23:56 +00:00
} else {
error("Serious Error! Could not set up a default course category!");
2001-11-22 06:23:56 +00:00
}
} else {
error("Serious Error! Could not set up the site!");
}
}
2002-12-30 05:13:43 +00:00
die;
2001-11-22 06:23:56 +00:00
} else {
foreach ($err as $key => $value) {
$focus = "form.$key";
}
}
2002-12-30 05:13:43 +00:00
}
2001-11-22 06:23:56 +00:00
/// Otherwise fill and print the form.
2002-12-30 05:13:43 +00:00
if ($site and empty($form)) {
$form = $site;
2001-11-22 06:23:56 +00:00
} else {
$form->category = 0;
$form->format = "social";
$form->newsitems = 0;
2001-11-22 06:23:56 +00:00
}
2002-12-30 05:13:43 +00:00
if (empty($focus)) {
$focus = "form.fullname";
}
$stradmin = get_string("administration");
$strsitesettings = get_string("sitesettings");
print_header("$site->shortname: $strsitesettings", "$site->fullname",
"<A HREF=\"index.php\">$stradmin</A> -> $strsitesettings", "$focus");
2001-11-22 06:23:56 +00:00
print_heading($strsitesettings);
print_simple_box_start("center", "", "$THEME->cellheading");
2002-12-30 05:13:43 +00:00
include("site.html");
2001-11-22 06:23:56 +00:00
print_simple_box_end();
print_footer();
exit;
/// Functions /////////////////////////////////////////////////////////////////
function validate_form(&$form, &$err) {
if (empty($form->fullname))
$err["fullname"] = get_string("missingsitename");
2001-11-22 06:23:56 +00:00
if (empty($form->shortname))
$err["shortname"] = get_string("missingshortsitename");
2001-11-22 06:23:56 +00:00
if (empty($form->summary))
$err["summary"] = get_string("missingsitedescription");
2001-11-22 06:23:56 +00:00
return;
}
?>