diff --git a/course/categories.php b/course/categories.php index 762130ed35c..668466dc8bd 100644 --- a/course/categories.php +++ b/course/categories.php @@ -7,7 +7,7 @@ require_login(); if (!isadmin()) { - error("Only administrators can use this course!"); + error("Only administrators can use this page!"); } if (!$site = get_site()) { @@ -24,80 +24,146 @@ $stredit = get_string("edit"); $strdelete = get_string("delete"); $straction = get_string("action"); - $stradd = get_string("add"); + $straddnewcategory = get_string("addnewcategory"); print_header("$site->shortname: $strcategories", "$site->fullname", - "admin/index.php\">$stradministration -> $strcategories"); + "admin/index.php\">$stradministration -> $strcategories", + "addform.addcategory"); - print_heading($strcategories); -/// If data submitted, then process and store. - - if ($form = data_submitted()) { - - $categories = array(); - - // Peel out all the data from variable names. - foreach ($form as $key => $val) { - if ($key == "new") { - if (!empty($val)) { - if (get_records("course_categories", "name", $val)) { - notify(get_string("categoryduplicate", "", $val)); - } else { - $cat->name = $val; - if (!insert_record("course_categories", $cat)) { - error("Could not insert the new category '$val'"); - } else { - notify(get_string("categoryadded", "", $val)); - } - } - } - +/// If data for a new category was submitted, then add it + if ($form = data_submitted()) { + if (!empty($form->addcategory)) { + unset($newcategory); + $newcategory->name = $form->addcategory; + $newcategory->sortorder = 999; + if (!insert_record("course_categories", $newcategory)) { + notify("Could not insert the new category '$newcategory->name'"); } else { - $cat->id = substr($key,1); - $cat->name = $val; + notify(get_string("categoryadded", "", $newcategory->name)); + } + } + } - if ($existingcats = get_records("course_categories", "name", $val)) { - foreach($existingcats as $existingcat) { - if ($existingcat->id != $cat->id) { - notify(get_string("categoryduplicate", "", $val)); - continue 2; - } + +/// Delete a category if necessary + + if (isset($delete)) { + if ($tempcat = get_record("course_categories", "id", $delete)) { + if (delete_records("course_categories", "id", $tempcat->id)) { + notify(get_string("categorydeleted", "", $tempcat->name)); + } + if ($children = get_records("course_categories", "parent", $tempcat->id)) { + foreach ($children as $childcat) { + if (! set_field("course_categories", "parent", $tempcat->parent, "id", $childcat->id)) { + notify("Could not update a child category!"); } } - - if (!update_record("course_categories", $cat)) { - error("Could not update the category '$val'"); - } } } - } + } -/// Get the existing categories - if (!$categories = get_categories()) { +/// Create a default category if necessary + if (!$categories = get_categories()) { /// No category yet! // Try and make one - $cat->name = get_string("miscellaneous"); - if ($cat->id = insert_record("course_categories", $cat)) { - $categories[$cat->id] = $cat; - } else { + unset($tempcat); + $tempcat->name = get_string("miscellaneous"); + if (!$tempcat->id = insert_record("course_categories", $tempcat)) { error("Serious error: Could not create a default category!"); } } -/// Delete category if the user wants to delete it - if (isset($delete)) { - if (delete_records("course_categories", "id", $delete)) { - notify(get_string("categorydeleted", "", $categories[$delete]->name)); - unset($categories[$delete]); - } else { - error("An error occurred while trying to delete a category"); + +/// Move a category to a new parent if required + + if (isset($move) and isset($moveto)) { + if ($tempcat = get_record("course_categories", "id", $move)) { + if ($tempcat->parent != $moveto) { + if (! set_field("course_categories", "parent", $moveto, "id", $tempcat->id)) { + notify("Could not update that category!"); + } + } } } -/// Find lowest ID category - this is the default category + +/// Hide or show a category + if (isset($hide) or isset($show)) { + if (isset($hide)) { + $tempcat = get_record("course_categories", "id", $hide); + $visible = 0; + } else { + $tempcat = get_record("course_categories", "id", $show); + $visible = 1; + } + if ($tempcat) { + if (! set_field("course_categories", "visible", $visible, "id", $tempcat->id)) { + notify("Could not update that category!"); + } + if (! set_field("course", "visible", $visible, "category", $tempcat->id)) { + notify("Could not hide/show any courses in this category !"); + } + } + } + + +/// Move a category up or down + + if (isset($moveup) or isset($movedown)) { + + $swapcategory = NULL; + $movecategory = NULL; + + if (isset($moveup)) { + if ($movecategory = get_record("course_categories", "id", $moveup)) { + $categories = get_categories("$movecategory->parent"); + + foreach ($categories as $category) { + if ($category->id == $movecategory->id) { + break; + } + $swapcategory = $category; + } + } + } + if (isset($movedown)) { + if ($movecategory = get_record("course_categories", "id", $movedown)) { + $categories = get_categories("$movecategory->parent"); + + $choosenext = false; + foreach ($categories as $category) { + if ($choosenext) { + $swapcategory = $category; + break; + } + if ($category->id == $movecategory->id) { + $choosenext = true; + } + } + } + } + if ($swapcategory and $movecategory) { // Renumber everything for robustness + $count=0; + foreach ($categories as $category) { + $count++; + if ($category->id == $swapcategory->id) { + $category = $movecategory; + } else if ($category->id == $movecategory->id) { + $category = $swapcategory; + } + if (! set_field("course_categories", "sortorder", $count, "id", $category->id)) { + notify("Could not update that category!"); + } + } + } + } + +/// Find the default category (the one with the lowest ID) + $categories = get_categories(); $default = 99999; foreach ($categories as $category) { + fix_category_courses($category->id); if ($category->id < $default) { $default = $category->id; } @@ -112,30 +178,141 @@ } } +/// Print form for creating new categories -/// Print the table of all categories - $table->head = array ($strcategory, $strcourses, $straction); - $table->align = array ("LEFT", "CENTER", "CENTER"); - $table->size = array ("80", "50", "50"); - $table->width = 100; + print_simple_box_start("center"); + echo "
| $strcategories | "; + echo "$stredit | "; + echo "$strmovecategoryto | "; + + print_category_edit(NULL, $displaylist, $parentlist); + + echo "
|---|
"; + for ($i=0; $i<$depth;$i++) { + echo " "; + } + $linkcss = $category->visible ? "" : " class=\"dimmed\" "; + echo "edit\" href=\"category.php?id=$category->id\">$category->name"; + echo "
"; + echo "| "; + popup_form("category.php?id=", $displaylist, "switchcategory", "$category->id", "", "", "", false); + echo " |
| $strcourses | "; + echo "$stredit | "; + echo "$strmovecourseto |
|---|---|---|
| id\">$course->fullname | "; + echo "";
+ if (!empty($course->visible)) {
+ echo "id&hide=$course->id\"> | ";
+ echo ""; + popup_form ("category.php?id=$category->id&move=$course->id&moveto=", $displaylist, + "moveform$course->id", "$course->category", "", "", "", false); + echo " | "; + echo "
print_string("category") ?>:
| "; - print_course_categories($categories, $category, 200); - echo " | ";
+/// Print the category selector
+
+ $categories = get_categories();
+ $multicategories = count($categories) > 1;
+
+ if (count($categories) > 1) {
+ $parentlist = array();
+ $displaylist = array();
+ $displaylist["0"] = $strfulllistofcourses;
+ make_categories_list($displaylist, $parentlist, "");
+
+ echo "
"; + } + + if (empty($category->id)) { + print_courses(0, "80%"); } else { - echo "
wwwroot/course/\">".get_string("fulllistofcourses")."...";
- } else {
- $moddata = array();
- $modicon = array();
- $fulllist = get_string("nocoursesyet");
- }
- print_side_block(get_string("courses"), "", $moddata, $modicon, $fulllist, $width);
-
- } else if ($courses) {
- foreach ($courses as $course) {
- print_course($course);
- echo " ".get_string("nocoursesyet")." "; + echo "
$editbuttons"; } @@ -670,10 +575,10 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false, } else { $extra = ""; } - $link_css = $mod->visible ? "" : " class=\"dimmed\" "; + $linkcss = $mod->visible ? "" : " class=\"dimmed\" "; echo "
"; - $some = true; - } - } - if (!$some) { - print_string("nocoursesyet"); - } - echo "
"; - $some = true; - } - } - if (!$some) { - print_string("nocoursesyet"); - } - echo "
wwwroot/course/\">".get_string("fulllistofcourses")."..."; + } else { + $moddata = array(); + $modicon = array(); + $fulllist = get_string("nocoursesyet"); + } + } + + print_side_block(get_string("courses"), "", $moddata, $modicon, $fulllist, $width); +} + + +function print_courses($category, $width="100%") { +/// Category is 0 (for all courses) or an object + + global $CFG, $THEME; + + if (empty($category)) { + $categories = NULL; + $courses = get_courses(0); + } else { + $categories = get_categories($category->id); // sub categories + $courses = get_courses($category); + } + + if ($categories) { + print_simple_box_start("center"); + print_heading(get_string("subcategories")); + foreach ($categories as $category) { + $linkcss = $category->visible ? "" : " class=\"dimmed\" "; + echo " wwwroot/course/index.php?category=$category->id\">$category->name "; + } + print_simple_box_end(); + } + + if ($courses) { + foreach ($courses as $course) { + print_course($course, $width); + echo "\n"; + } + } else { + print_heading(get_string("nocoursesyet")); + } + +} + + +function print_course($course, $width="100%") { + + global $CFG, $THEME; + + if (! $site = get_site()) { + error("Could not find a site!"); + } + + if (empty($THEME->custompix)) { + $pixpath = "$CFG->wwwroot/pix"; + } else { + $pixpath = "$CFG->wwwroot/theme/$CFG->theme/pix"; + } + + print_simple_box_start("center", "$width"); + + echo "
\n"; + } + } + echo " wwwroot/course/\">".get_string("fulllistofcourses")."... "; } diff --git a/course/unenrol.php b/course/unenrol.php index 3c32377dd47..d9eb241244a 100644 --- a/course/unenrol.php +++ b/course/unenrol.php @@ -34,7 +34,7 @@ if ($user->id == $USER->id) { unset($USER->student["$id"]); - redirect("$CFG->wwwroot"); + redirect("$CFG->wwwroot/"); } redirect("$CFG->wwwroot/user/index.php?id=$course->id"); diff --git a/index.php b/index.php index ed7a34dc509..f48298d1476 100644 --- a/index.php +++ b/index.php @@ -61,14 +61,23 @@ echo ""; } - if ($site->newsitems > 0 ) { - $categories = get_categories(); - if (count($categories) > 1) { - print_course_categories($categories, "none", $side); - } else { - $category = array_shift($categories); - print_all_courses($category->id, "minimal", 10, $side); - } + switch ($CFG->frontpage) { + case FRONTPAGENEWS: // print news links on the side + print_courses_sideblock(0, "$side"); + break; + + case FRONTPAGECOURSELIST: + case FRONTPAGECATEGORYNAMES: + if ($site->newsitems) { + if ($news = forum_get_course_forum($site->id, "news")) { + print_side_block_start(get_string("latestnews"), $side, "sideblocklatestnews"); + echo ""; + forum_print_latest_discussions($news->id, $site->newsitems, "minimal", "", false); + echo ""; + print_side_block_end(); + } + } + break; } print_spacer(1,$side); } @@ -86,38 +95,49 @@ } echo " | ";
- if ($site->newsitems == 0 ) {
- print_heading_block(get_string("availablecourses"));
- print_spacer(8,1);
- $categories = get_categories();
- if (count($categories) > 1) {
- print_course_categories($categories, "index");
- } else {
- print_all_courses("all");
- }
-
- } else {
- if (! $newsforum = forum_get_course_forum($site->id, "news")) {
- error("Could not find or create a main news forum for the site");
- }
-
- if (isset($USER->id)) {
- $SESSION->fromdiscussion = "$CFG->wwwroot";
- if (forum_is_subscribed($USER->id, $newsforum->id)) {
- $subtext = get_string("unsubscribe", "forum");
- } else {
- $subtext = get_string("subscribe", "forum");
+ switch ($CFG->frontpage) { /// Display the main part of the front page.
+ case FRONTPAGENEWS:
+ if (! $newsforum = forum_get_course_forum($site->id, "news")) {
+ error("Could not find or create a main news forum for the site");
}
- $headertext = "
| ";
diff --git a/lang/en/moodle.php b/lang/en/moodle.php
index 4b2ca830ff6..04c5f045ec1 100644
--- a/lang/en/moodle.php
+++ b/lang/en/moodle.php
@@ -16,6 +16,7 @@ $string['add'] = "Add";
$string['added'] = "Added \$a";
$string['addinganew'] = "Adding a new \$a";
$string['addinganewto'] = "Adding a new \$a->what to \$a->to";
+$string['addnewcategory'] = "Add new category";
$string['addnewcourse'] = "Add a new course";
$string['addnewuser'] = "Add a new user";
$string['address'] = "Address";
@@ -186,6 +187,7 @@ $string['editinga'] = "Editing a \$a";
$string['editmyprofile'] = "Edit profile";
$string['editsummary'] = "Edit summary";
$string['editthisactivity'] = "Edit this activity";
+$string['editthiscategory'] = "Edit this category";
$string['edituser'] = "Edit user accounts";
$string['email'] = "Email address";
$string['emailformat'] = "Email format";
@@ -276,8 +278,11 @@ $string['formattopics'] = "Topics format";
$string['formatweeks'] = "Weekly format";
$string['formatwiki'] = "Wiki format";
$string['from'] = "From";
+$string['frontpagecategorynames'] = "Show a list of categories";
+$string['frontpagecourselist'] = "Show a list of courses";
$string['frontpagedescription'] = "Front page description";
$string['frontpageformat'] = "Front page format";
+$string['frontpagenews'] = "Show news items";
$string['fulllistofcourses'] = "All courses";
$string['fullprofile'] = "Full profile";
$string['fullname'] = "Full name";
@@ -441,6 +446,8 @@ $string['modulesuccess'] = "\$a tables have been set up correctly";
$string['moodleversion'] = "Moodle Version";
$string['mostrecently'] = "most recently";
$string['move'] = "Move";
+$string['movecategoryto'] = "Move category to:";
+$string['movecourseto'] = "Move course to:";
$string['movedown'] = "Move down";
$string['movefull'] = "Move \$a to this location";
$string['movehere'] = "Move to here";
@@ -609,7 +616,6 @@ $string['showonlytopic'] = "Show only topic \$a";
$string['showonlyweek'] = "Show only week \$a";
$string['showrecent'] = "Show recent activity";
$string['showtheselogs'] = "Show these logs";
-$string['socialheadline'] = "Social forum - latest topics";
$string['showallcourses'] = "Show all courses";
$string['site'] = "Site";
$string['sites'] = "Sites";
@@ -617,6 +623,7 @@ $string['sitelogs'] = "Site logs";
$string['sitenews'] = "Site news";
$string['sitesettings'] = "Site settings";
$string['size'] = "Size";
+$string['socialheadline'] = "Social forum - latest topics";
$string['someallowguest'] = "Some courses may allow guest access";
$string['someerrorswerefound'] = "Some information was missing or incorrect. Look below for details.";
$string['startdate'] = "Course start date";
@@ -635,6 +642,7 @@ $string['strftimerecentfull'] = "%%a, %%d %%b %%Y, %%I:%%M %%p";
$string['strftimetime'] = "%%I:%%M %%p";
$string['stringsnotset'] = "The following strings are not defined in \$a";
$string['studentnotallowed'] = "Sorry, but you can not enter this course as '\$a'";
+$string['subcategories'] = "Sub-categories";
$string['success'] = "Success";
$string['summary'] = "Summary";
$string['summaryof'] = "Summary of \$a";
@@ -652,13 +660,14 @@ $string['to'] = "To";
$string['today'] = "Today";
$string['todaylogs'] = "Today's logs";
$string['toomanytoshow'] = "There are too many users to show";
+$string['top'] = "Top";
$string['topic'] = "Topic";
$string['topichide'] = "Hide this topic from \$a";
$string['topicoutline'] = "Topic outline";
$string['topicshow'] = "Show this topic to \$a";
+$string['total'] = "Total";
$string['turneditingoff'] = "Turn editing off";
$string['turneditingon'] = "Turn editing on";
-$string['total'] = "Total";
$string['undecided'] = "Undecided";
$string['unenrol'] = "Unenrol";
$string['unenrolme'] = "Unenrol me from \$a";
diff --git a/lib/datalib.php b/lib/datalib.php
index 25546877641..06e5d169276 100644
--- a/lib/datalib.php
+++ b/lib/datalib.php
@@ -83,6 +83,9 @@ function table_column($table, $oldfield, $field, $type="integer", $size="10",
case "mysqlt":
switch (strtolower($type)) {
+ case "text":
+ $type = "TEXT";
+ break;
case "integer":
$type = "INTEGER($size)";
break;
@@ -821,16 +824,24 @@ function get_site () {
function get_courses($category=0, $sort="fullname ASC") {
-/// Returns list of courses
+/// Returns list of courses, for whole site, or category
- if ($category > 0) { // Return all courses in one category
- $courses = get_records("course", "category", $category, $sort);
+ if ($category === 0) { // Return all courses, except site
+ $courses = get_records_select("course", "category > 0", $sort);
- } else if ($category < 0) { // Return all courses, even the site
+ } else if ($category === -1) { // Return all courses, even the site
$courses = get_records("course", "", "", $sort);
- } else { // Return all courses, except site
- $courses = get_records_select("course", "category > 0", $sort);
+ } else { // $category is an object
+ $courses = get_records("course", "category", $category->id);
+ if ($courses) { // Reorder them
+ $courselist = explode(',', $category->courseorder);
+ $outcourses = array();
+ foreach ($courselist as $courseid) {
+ $outcourses[] = $courses[$courseid];
+ }
+ $courses = $outcourses;
+ }
}
if ($courses) { /// Remove unavailable courses from the list
@@ -845,8 +856,37 @@ function get_courses($category=0, $sort="fullname ASC") {
return $courses;
}
-function get_categories() {
- return get_records("course_categories", "", "", "name");
+function get_my_courses($userid, $sort="c.fullname ASC") {
+ global $CFG;
+
+ return get_records_sql("SELECT c.*
+ FROM {$CFG->prefix}course c,
+ {$CFG->prefix}user_students s,
+ {$CFG->prefix}user_teachers t
+ WHERE (s.userid = '$userid' AND s.course = c.id)
+ OR (t.userid = '$userid' AND t.course = c.id)
+ GROUP BY c.id
+ ORDER BY $sort");
+}
+
+
+function get_categories($parent="none", $sort="sortorder ASC") {
+ if ($parent == "none") {
+ $categories = get_records("course_categories", "", "", $sort);
+ } else {
+ $categories = get_records("course_categories", "parent", $parent, $sort);
+ }
+ if ($categories) { /// Remove unavailable categories from the list
+ $admin = isadmin();
+ foreach ($categories as $key => $category) {
+ if (!$category->visible) {
+ if (!$admin) {
+ unset($categories[$key]);
+ }
+ }
+ }
+ }
+ return $categories;
}
diff --git a/lib/db/mysql.php b/lib/db/mysql.php
index 33ea8caaf53..a2058df9b6c 100644
--- a/lib/db/mysql.php
+++ b/lib/db/mysql.php
@@ -413,6 +413,15 @@ function main_upgrade($oldversion=0) {
execute_sql(" ALTER TABLE `{$CFG->prefix}user_teachers` ADD INDEX courseuserid (course,userid) ");
}
+ if ($oldversion < 2003072803) {
+ table_column("course_categories", "", "description", "text", "", "", "");
+ table_column("course_categories", "", "parent", "integer", "10", "unsigned");
+ table_column("course_categories", "", "sortorder", "integer", "10", "unsigned");
+ table_column("course_categories", "", "courseorder", "text", "", "", "");
+ table_column("course_categories", "", "visible", "integer", "1", "unsigned", "1");
+ table_column("course_categories", "", "timemodified", "integer", "10", "unsigned");
+ }
+
return $result;
}
diff --git a/lib/db/mysql.sql b/lib/db/mysql.sql
index ece942f6f2b..66c0a33bd81 100644
--- a/lib/db/mysql.sql
+++ b/lib/db/mysql.sql
@@ -60,6 +60,12 @@ CREATE TABLE `prefix_course` (
CREATE TABLE `prefix_course_categories` (
`id` int(10) unsigned NOT NULL auto_increment,
`name` varchar(255) NOT NULL default '',
+ `description` text NOT NULL,
+ `parent` int(10) unsigned NOT NULL default '0',
+ `sortorder` int(10) unsigned NOT NULL default '0',
+ `courseorder` text NOT NULL,
+ `visible` tinyint(1) NOT NULL default '1',
+ `timemodified` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
) TYPE=MyISAM COMMENT='Course categories';
diff --git a/lib/db/postgres7.php b/lib/db/postgres7.php
index 653423fef67..8e3c95986c5 100644
--- a/lib/db/postgres7.php
+++ b/lib/db/postgres7.php
@@ -184,6 +184,15 @@ function main_upgrade($oldversion=0) {
execute_sql(" CREATE INDEX {$CFG->prefix}user_teachers_courseuserid_idx ON {$CFG->prefix}user_teachers (course,userid) ");
}
+ if ($oldversion < 2003072802) {
+ table_column("course_categories", "", "description", "text", "", "", "");
+ table_column("course_categories", "", "parent", "integer", "10", "unsigned");
+ table_column("course_categories", "", "sortorder", "integer", "10", "unsigned");
+ table_column("course_categories", "", "courseorder", "text", "", "", "");
+ table_column("course_categories", "", "visible", "integer", "1", "unsigned", "1");
+ table_column("course_categories", "", "timemodified", "integer", "10", "unsigned");
+ }
+
return $result;
}
?>
diff --git a/lib/db/postgres7.sql b/lib/db/postgres7.sql
index 4f689cd567b..3a8630f108d 100644
--- a/lib/db/postgres7.sql
+++ b/lib/db/postgres7.sql
@@ -31,6 +31,12 @@ CREATE TABLE prefix_course (
CREATE TABLE prefix_course_categories (
id SERIAL PRIMARY KEY,
name varchar(255) NOT NULL default ''
+ description text NOT NULL default '',
+ parent integer NOT NULL default '0',
+ sortorder integer NOT NULL default '0',
+ courseorder text NOT NULL default '',
+ visible integer NOT NULL default '1',
+ timemodified` integer NOT NULL default '0'
);
CREATE TABLE prefix_course_display (
diff --git a/lib/weblib.php b/lib/weblib.php
index f00c7e86fe5..0121cd3dbbb 100644
--- a/lib/weblib.php
+++ b/lib/weblib.php
@@ -725,7 +725,7 @@ function print_footer ($course=NULL) {
$homelink = "framename}\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname";
}
} else {
- $homelink = "framename}\" href=\"$CFG->wwwroot\">".get_string("home")."";
+ $homelink = "framename}\" href=\"$CFG->wwwroot/\">".get_string("home")."";
$course = get_site();
}
@@ -1079,6 +1079,17 @@ function update_module_button($moduleid, $courseid, $string) {
}
}
+function update_category_button($categoryid) {
+// Prints the editing button on a module "view" page
+ global $CFG;
+
+ if (isadmin()) {
+ $string = get_string("editthiscategory");
+ return "";
+ }
+}
function navmenu($course, $cm=NULL) {
// Given a course and a (current) coursemodule
@@ -1184,7 +1195,7 @@ function error ($message, $link="") {
$link = "$SESSION->fromurl";
unset($SESSION->fromurl);
} else {
- $link = "$CFG->wwwroot";
+ $link = "$CFG->wwwroot/";
}
}
print_continue($link);
@@ -1245,7 +1256,7 @@ function notice ($message, $link="") {
if (!empty($_SERVER["HTTP_REFERER"])) {
$link = $_SERVER["HTTP_REFERER"];
} else {
- $link = $CFG->wwwroot;
+ $link = "$CFG->wwwroot/";
}
}
diff --git a/version.php b/version.php
index abe5209d524..87c589dcff9 100644
--- a/version.php
+++ b/version.php
@@ -5,7 +5,7 @@
// database to determine whether upgrades should
// be performed (see lib/db/*.php)
-$version = 2003072800; // The current version is a date (YYYYMMDDXX)
+$version = 2003072803; // The current version is a date (YYYYMMDDXX)
$release = "1.1 development"; // User-friendly version number