2004-10-06 00:08:08 +00:00
|
|
|
<?php // $Id$
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2006-03-06 19:27:25 +00:00
|
|
|
require_once('../config.php');
|
|
|
|
require_once('../course/lib.php');
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-08-08 14:17:55 +00:00
|
|
|
if ($site = get_site()) {
|
2004-07-08 01:19:32 +00:00
|
|
|
require_login();
|
2002-08-06 12:17:40 +00:00
|
|
|
if (!isadmin()) {
|
|
|
|
error("You need to be admin to edit this page");
|
|
|
|
}
|
2003-05-06 15:58:20 +00:00
|
|
|
$site->format = "social"; // override
|
2002-08-06 12:17:40 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2006-03-06 19:27:25 +00:00
|
|
|
$focus = "form.fullname";
|
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
/// If data submitted, then process and store.
|
|
|
|
|
2005-02-24 08:49:32 +00:00
|
|
|
if ($form = data_submitted()) {
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2004-10-06 00:08:08 +00:00
|
|
|
if (!empty($USER->id)) { // Additional identity check
|
2004-10-04 13:50:37 +00:00
|
|
|
if (!confirm_sesskey()) {
|
2005-01-22 16:04:14 +00:00
|
|
|
error(get_string('confirmsesskeybad', 'error'));
|
2004-10-04 13:50:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
validate_form($form, $err);
|
|
|
|
|
|
|
|
if (count($err) == 0) {
|
|
|
|
|
2005-12-14 21:42:44 +00:00
|
|
|
$form->frontpage = array_flip($form->frontpage);
|
|
|
|
unset($form->frontpage[0]);
|
|
|
|
$form->frontpage = array_flip($form->frontpage);
|
|
|
|
asort($form->frontpage);
|
|
|
|
$form->frontpage = implode(',',array_flip($form->frontpage));
|
2003-07-30 13:05:51 +00:00
|
|
|
set_config("frontpage", $form->frontpage);
|
2006-04-21 03:09:58 +00:00
|
|
|
if ($form->frontpage == '') {
|
2005-04-02 09:29:59 +00:00
|
|
|
$form->numsections = 1; // Force the topic display for this format
|
|
|
|
}
|
2003-07-30 13:05:51 +00:00
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
$form->timemodified = time();
|
|
|
|
|
|
|
|
if ($form->id) {
|
|
|
|
if (update_record("course", $form)) {
|
2003-07-30 13:05:51 +00:00
|
|
|
redirect("$CFG->wwwroot/", get_string("changessaved"));
|
2001-11-22 06:23:56 +00:00
|
|
|
} else {
|
2002-08-08 14:17:55 +00:00
|
|
|
error("Serious Error! Could not update the site record! (id = $form->id)");
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
} else {
|
2004-11-08 19:36:07 +00:00
|
|
|
// We are about to create the site "course"
|
2004-08-31 07:29:25 +00:00
|
|
|
require_once($CFG->dirroot.'/lib/blocklib.php');
|
2004-06-01 13:47:55 +00:00
|
|
|
|
2004-11-08 19:36:07 +00:00
|
|
|
if ($newid = insert_record('course', $form)) {
|
|
|
|
|
2004-10-19 21:04:28 +00:00
|
|
|
// Site created, add blocks for it
|
2005-01-31 02:18:15 +00:00
|
|
|
$page = page_create_object(PAGE_COURSE_VIEW, $newid);
|
2004-10-19 21:04:28 +00:00
|
|
|
blocks_repopulate_page($page); // Return value not checked because you can always edit later
|
|
|
|
|
2004-11-08 19:36:07 +00:00
|
|
|
$cat->name = get_string('miscellaneous');
|
|
|
|
if (insert_record('course_categories', $cat)) {
|
2003-08-10 08:17:59 +00:00
|
|
|
redirect("$CFG->wwwroot/$CFG->admin/index.php", get_string("changessaved"), 1);
|
2001-11-22 06:23:56 +00:00
|
|
|
} else {
|
2002-09-09 11:48:11 +00:00
|
|
|
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;
|
2002-08-13 15:40:07 +00:00
|
|
|
|
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)) {
|
2002-08-08 14:17:55 +00:00
|
|
|
$form = $site;
|
2003-10-12 17:21:36 +00:00
|
|
|
$course = $site;
|
2003-05-06 15:58:20 +00:00
|
|
|
$firsttime = false;
|
2001-11-22 06:23:56 +00:00
|
|
|
} else {
|
2003-05-26 14:38:41 +00:00
|
|
|
$form->fullname = "";
|
|
|
|
$form->shortname = "";
|
|
|
|
$form->summary = "";
|
2003-07-30 13:05:51 +00:00
|
|
|
$form->newsitems = 3;
|
2004-07-29 18:01:32 +00:00
|
|
|
$form->numsections = 0;
|
2003-05-26 14:38:41 +00:00
|
|
|
$form->id = "";
|
2001-11-22 06:23:56 +00:00
|
|
|
$form->category = 0;
|
2004-10-08 13:46:06 +00:00
|
|
|
$form->format = 'site'; // Only for this course
|
2003-08-07 16:01:31 +00:00
|
|
|
$form->teacher = get_string("defaultcourseteacher");
|
|
|
|
$form->teachers = get_string("defaultcourseteachers");
|
|
|
|
$form->student = get_string("defaultcoursestudent");
|
|
|
|
$form->students = get_string("defaultcoursestudents");
|
2003-05-06 15:58:20 +00:00
|
|
|
$firsttime = true;
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2003-07-30 13:05:51 +00:00
|
|
|
if (isset($CFG->frontpage)) {
|
|
|
|
$form->frontpage = $CFG->frontpage;
|
|
|
|
|
|
|
|
} else {
|
2005-06-11 19:00:23 +00:00
|
|
|
$form->frontpage = FRONTPAGECOURSELIST; // Show course list by default
|
2003-07-30 13:05:51 +00:00
|
|
|
set_config("frontpage", $form->frontpage);
|
|
|
|
}
|
|
|
|
|
2002-08-08 15:51:23 +00:00
|
|
|
$stradmin = get_string("administration");
|
2003-08-18 16:40:27 +00:00
|
|
|
$strconfiguration = get_string("configuration");
|
2002-08-08 15:51:23 +00:00
|
|
|
$strsitesettings = get_string("sitesettings");
|
|
|
|
|
2003-05-06 15:58:20 +00:00
|
|
|
if ($firsttime) {
|
|
|
|
print_header();
|
|
|
|
print_heading($strsitesettings);
|
2005-02-24 08:49:32 +00:00
|
|
|
print_simple_box(get_string("configintrosite", 'admin'), "center", "50%");
|
2003-05-06 15:58:20 +00:00
|
|
|
echo "<br />";
|
|
|
|
} else {
|
|
|
|
print_header("$site->shortname: $strsitesettings", "$site->fullname",
|
2003-08-18 16:40:27 +00:00
|
|
|
"<a href=\"index.php\">$stradmin</a> -> ".
|
|
|
|
"<a href=\"configure.php\">$strconfiguration</a> -> $strsitesettings", "$focus");
|
2003-05-06 15:58:20 +00:00
|
|
|
print_heading($strsitesettings);
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2004-10-08 05:41:52 +00:00
|
|
|
if (empty($USER->id)) { // New undefined admin user
|
2004-10-04 13:50:37 +00:00
|
|
|
$USER->htmleditor = true;
|
2004-10-08 05:41:52 +00:00
|
|
|
$sesskey = '';
|
|
|
|
} else {
|
|
|
|
$sesskey = $USER->sesskey;
|
2003-08-10 09:26:11 +00:00
|
|
|
}
|
2004-10-04 13:50:37 +00:00
|
|
|
$usehtmleditor = can_use_html_editor();
|
|
|
|
$defaultformat = FORMAT_HTML;
|
|
|
|
|
2005-01-25 17:08:05 +00:00
|
|
|
print_simple_box_start("center", "");
|
2002-12-30 05:13:43 +00:00
|
|
|
include("site.html");
|
2001-11-22 06:23:56 +00:00
|
|
|
print_simple_box_end();
|
2003-05-06 15:58:20 +00:00
|
|
|
|
2004-10-04 13:50:37 +00:00
|
|
|
if ($usehtmleditor) {
|
|
|
|
use_html_editor();
|
|
|
|
}
|
|
|
|
|
2003-05-06 15:58:20 +00:00
|
|
|
if (!$firsttime) {
|
|
|
|
print_footer();
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
exit;
|
|
|
|
|
|
|
|
/// Functions /////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
function validate_form(&$form, &$err) {
|
|
|
|
|
|
|
|
if (empty($form->fullname))
|
2002-08-13 15:40:07 +00:00
|
|
|
$err["fullname"] = get_string("missingsitename");
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
if (empty($form->shortname))
|
2002-08-13 15:40:07 +00:00
|
|
|
$err["shortname"] = get_string("missingshortsitename");
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|