From ba2e5d7347c1150576c1fd91f3f5cfee2b088c8f Mon Sep 17 00:00:00 2001 From: martin Date: Mon, 9 Sep 2002 11:48:11 +0000 Subject: [PATCH] Categories upgrade. Admin can now create/edit/delete categories, and these are diesplayed wherever courses are listed --- CHANGES | 180 ++++++++++++++++++++++++++++++++++++++++++ admin/index.php | 3 +- admin/site.php | 8 +- course/categories.php | 122 ++++++++++++++++++++++++++++ course/index.php | 44 ++++++++--- course/lib.php | 30 ++++++- index.php | 13 ++- lang/en/moodle.php | 7 +- version.php | 4 +- 9 files changed, 389 insertions(+), 22 deletions(-) create mode 100644 course/categories.php diff --git a/CHANGES b/CHANGES index 016af2fe9b..3ce57a2336 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,183 @@ +2002-09-09 Monday 00:13 martin + + * lib/weblib.php: + + Added height and width to smiley icons, to make emails look better + in circumstances where external images are blocked (eg some webmail + programs like squirrelmail). + +2002-09-09 Monday 00:04 martin + + * mod/forum/lib.php: + + Added an "unsubscribe" link to emails + +2002-09-08 Sunday 23:39 martin + + * mod/forum/lib.php: + + Fixed a bug. When replying to an email copy, you would be + forwarded to the login screen to login first. However, this was + being saved as the place to go back to after replying. + + I added a check for this so now it behaves as you'd expect. + +2002-09-08 Sunday 17:47 martin + + * mod/choice/mod.html: + + Text window a bit bigger + +2002-09-08 Sunday 17:42 martin + + * lang/en/choice.php, mod/choice/lib.php, mod/choice/mod.html, + mod/choice/report.php, mod/choice/version.php, + mod/choice/view.html, mod/choice/view.php: + + Choices now support up to 6 choices. Backward compatible to + 2-choice format. + +2002-09-08 Sunday 17:41 martin + + * course/: social.php, topics.php, weeks.php: + + Tip over 'Edit profile' is the user's name + +2002-09-08 Sunday 17:22 martin + + * lang/en/help/choice/options.html: + + Help for choices + +2002-09-08 Sunday 13:29 martin + + * course/: social.php, topics.php, weeks.php: + + Clarified the "participants" link ... + +2002-09-08 Sunday 13:23 martin + + * course/view.php: + + Link at bottom now goes to site home, not this page + +2002-09-08 Sunday 13:15 martin + + * course/teachers.php, lang/en/help/teachers.html: + + Added documentation to the teachers page. + +2002-09-08 Sunday 13:15 martin + + * lib/moodlelib.php: + + Improved print_table() a bit (can now specify column widths) + +2002-09-08 Sunday 11:34 martin + + * course/teachers.php: + + Need this file to go with the previous changes! + +2002-09-08 Sunday 11:34 martin + + * lang/en/moodle.php, user/index.php, user/lib.php: + + Changes to improve display of teachers + +2002-09-08 Sunday 11:24 martin + + * version.php, course/edit.html, course/edit.php, course/lib.php, + course/social.php, course/topics.php, course/weeks.php, + lang/en/moodle.php, lib/moodlelib.php, lib/db/mysql.sql, + user/index.php: + + Changes to allow much better control over what "teachers" are + called in a course. Firstly, the course settings page now allows + the teachers to specify the word they want to use in place of + "teachers" and "students" as well as "teacher" and "student". + Secondly, a new teacher admin tool allows any teacher to modify the + order and displayed role of teachers in that course. This affects + the display on the course listings, the participants page and so + on. + +2002-09-07 Saturday 22:57 martin + + * admin/lang.php, lang/en/moodle.php, lib/moodlelib.php: + + Improvements to the language checker. As well as checking for + missing strings, you can now see the current language compared + side-by-side with English. + +2002-09-07 Saturday 22:56 martin + + * admin/index.php: + + Add a link if a "manage database" directory exists + +2002-09-07 Saturday 13:01 martin + + * mod/newmodule_template.zip: + + Slight update to README + +2002-09-07 Saturday 11:54 martin + + * mod/newmodule_template.zip: + + Added a README that explains the process + +2002-09-07 Saturday 11:31 martin + + * mod/: README, newmodule_template.zip: + + Added a template for new modules that contains the bare + necessities. + +2002-09-06 Friday 23:17 martin + + * version.php: + + Checking in the current release number for CVS users + +2002-09-06 Friday 23:10 martin + + * user/view.php: + + Don't try and print the last access date if it doesn't exist + +2002-09-06 Friday 22:06 martin + + * version.php, admin/index.php, lib/moodlelib.php: + + Added a new $release variable that shows the user-friendly version + number + +2002-09-06 Friday 22:05 martin + + * lib/setup.php: + + Cleaned up a bit + +2002-09-06 Friday 01:31 martin + + * user/edit.php: + + Fixed bug in password checking for new admin user ... + +2002-09-05 Thursday 20:29 martin + + * UPGRADING.txt: + + Updated the info to mention that the upgrading only works if you + are logged in as the *administrator* and visit the site home page. + +2002-09-05 Thursday 20:25 martin + + * CHANGES: + + CHANGES UP TO 1.0.3.1 + 2002-09-05 Thursday 20:24 martin * version.php: diff --git a/admin/index.php b/admin/index.php index 8c5b0d9c6f..ba1d561b4a 100644 --- a/admin/index.php +++ b/admin/index.php @@ -207,7 +207,8 @@ } $table->data[0][1] = "

".get_string("addnewcourse")."

". "

".get_string("assignteachers")."

". - "

".get_string("deletecourse")."

"; + "

".get_string("deletecourse")."

". + "

".get_string("categories")."

"; $table->data[0][2] = "

".get_string("addnewuser")."

". "

".get_string("edituser")."

"; diff --git a/admin/site.php b/admin/site.php index 057565453d..b0f774798c 100644 --- a/admin/site.php +++ b/admin/site.php @@ -23,17 +23,17 @@ if ($form->id) { if (update_record("course", $form)) { - redirect("$CFG->wwwroot/admin/index.php", "Changes saved"); + redirect("$CFG->wwwroot/admin/index.php", get_string("changessaved")); } else { error("Serious Error! Could not update the site record! (id = $form->id)"); } } else { if ($newid = insert_record("course", $form)) { - $cat->name = "General"; + $cat->name = get_string("miscellaneous"); if (insert_record("course_categories", $cat)) { - redirect("$CFG->wwwroot/admin/index.php", "Changes saved", "1"); + redirect("$CFG->wwwroot/admin/index.php", get_string("changessaved"), "1"); } else { - error("Serious Error! Could not set up the default categories!"); + error("Serious Error! Could not set up a default course category!"); } } else { error("Serious Error! Could not set up the site!"); diff --git a/course/categories.php b/course/categories.php new file mode 100644 index 0000000000..53018d14b2 --- /dev/null +++ b/course/categories.php @@ -0,0 +1,122 @@ +fullname: $strcategories", "$site->fullname", + "wwwroot/admin\">$stradministration -> $strcategories"); + + print_heading($strcategories); + +/// If data submitted, then process and store. + + if (match_referer() && isset($HTTP_POST_VARS)) { + + $categories = array(); + + // Peel out all the data from variable names. + foreach ($HTTP_POST_VARS as $key => $val) { + if ($key == "new" and $val != "") { + $cat->name = $val; + if (!insert_record("course_categories", $cat)) { + error("Could not insert the new category '$val'"); + } else { + notify(get_string("categoryadded", "", $val)); + } + + } else { + $cat->id = substr($key,1); + $cat->name = $val; + if (!update_record("course_categories", $cat)) { + error("Could not update the category '$val'"); + } + } + } + } + + +/// Get the existing categories + if (!$categories = get_all_categories()) { + // Try and make one + $cat->name = get_string("miscellaneous"); + if ($cat->id = insert_record("course_categories", $cat)) { + $categories[$cat->id] = $cat; + } else { + 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"); + } + } + +/// Find lowest ID category - this is the default category + $default = 99999; + foreach ($categories as $category) { + if ($category->id < $default) { + $default = $category->id; + } + } + +/// Find any orphan courses that don't yet have a valid category and set to default + if ($courses = get_records_sql("SELECT * FROM course WHERE category > 0")) { + foreach ($courses as $course) { + if (!isset( $categories[$course->category] )) { + set_field("course", "category", $default, "id", $course->id); + } + } + } + + +/// Print the table of all categories + $table->head = array ($strcategory, $strcourses, $strdelete); + $table->align = array ("LEFT", "CENTER", "CENTER"); + $table->size = array ("50", "20", "20"); + $table->width = 100; + + echo "
"; + foreach ($categories as $category) { + $count = count_records("course", "category", $category->id); + if ($category->id == $default) { + $delete = ""; // Can't delete default category + } else { + $delete = "id\">$strdelete"; + } + $table->data[] = array ("id\" VALUE=\"$category->name\" SIZE=30>", + "$count", $delete); + } + $table->data[] = array ("", "", "$stradd"); + print_table($table); + echo "

"; + echo "
"; + echo "
"; + + print_footer(); + +?> diff --git a/course/index.php b/course/index.php index 5b3cdb3bd2..76675a7c37 100644 --- a/course/index.php +++ b/course/index.php @@ -4,15 +4,41 @@ require("../config.php"); require("lib.php"); - $title = get_string("courses"); - - print_header($title, $title, $title, ""); - - optional_variable($cat, 1); - - echo "
"; - - print_all_courses($cat); + optional_variable($category, 0); + + $strcourses = get_string("courses"); + + if (!$categories = get_all_categories()) { + error("Could not find any course categories!"); + } + + if (isset($categories[$category])) { + $thiscatname = $categories[$category]->name; + $navigation = "$strcourses -> $thiscatname"; + } else { + $navigation = $strcourses; + } + print_header($strcourses, $strcourses, $navigation); + + $showcategories = (count($categories) > 1); + if ($showcategories) { + echo ""; + echo "
"; + print_simple_box(get_string("categories"), "CENTER", 180, $THEME->cellheading); + print_course_categories($categories, $category, 180); + echo ""; + } else { + echo "
"; + $category="all"; + } + + if ($category) { + if ($category != "all") { + print_simple_box($categories[$category]->name, "CENTER", "100%", $THEME->cellheading); + echo "
"; + } + print_all_courses($category); + } echo "
"; diff --git a/course/lib.php b/course/lib.php index 148e01c7a9..9b31878cf2 100644 --- a/course/lib.php +++ b/course/lib.php @@ -172,10 +172,16 @@ function print_log($course, $user=0, $date=0, $order="ORDER BY l.time ASC") { } -function print_all_courses($cat=1, $style="full", $maxcount=999) { +function print_all_courses($category="all", $style="full", $maxcount=999) { global $CFG; - if ($courses = get_records("course", "category", $cat, "fullname ASC")) { + if ($category == "all") { + $courses = get_records_sql("SELECT * FROM course WHERE category > 0 ORDER BY fullname ASC"); + } else { + $courses = get_records("course", "category", $category, "fullname ASC"); + } + + if ($courses) { if ($style == "minimal") { $count = 0; $icon = "\"".get_string("course")."\""; @@ -459,6 +465,10 @@ function get_all_sections($courseid) { ORDER BY section"); } +function get_all_categories() { + return get_records_sql("SELECT * FROM course_categories ORDER by name"); +} + function print_section($courseid, $section, $mods, $modnamesused, $absolute=false, $width="100%") { global $CFG; @@ -521,6 +531,8 @@ function print_admin_links ($siteid, $width=180) { $modicon[]=$icon; $moddata[]="wwwroot/course/edit.php\">".get_string("addnewcourse").""; $modicon[]=$icon; + $moddata[]="wwwroot/course/categories.php\">".get_string("categories").""; + $modicon[]=$icon; $moddata[]="wwwroot/course/teacher.php\">".get_string("assignteachers").""; $modicon[]=$icon; $moddata[]="wwwroot/course/delete.php\">".get_string("deletecourse").""; @@ -570,6 +582,20 @@ function print_course_admin_links($course, $width=180) { print_side_block("", $admindata, "", $adminicon, $width); } +function print_course_categories($categories, $selected="none", $width=180) { + global $CFG, $THEME; + + foreach ($categories as $cat) { + $caticon[]="wwwroot/pix/i/course.gif\" HEIGHT=16 WIDTH=16>"; + if ($cat->id == $selected) { + $catdata[]="$cat->name"; + } else { + $catdata[]="wwwroot/course/index.php?category=$cat->id\">$cat->name"; + } + } + $showall = "

wwwroot/course/index.php?category=all\">".get_string("fulllistofcourses")."..."; + print_side_block("", $catdata, $showall, $caticon, $width); +} function print_log_graph($course, $userid=0, $type="course.png", $date=0) { global $CFG; diff --git a/index.php b/index.php index 9b9b54e5dc..0303e12b99 100644 --- a/index.php +++ b/index.php @@ -57,8 +57,15 @@ } if ($site->newsitems > 0 ) { - print_simple_box(get_string("courses"), "CENTER", $side, "$THEME->cellheading"); - print_all_courses($cat=1, "minimal", 10); + $categories = get_all_categories(); + if (count($categories) > 1) { + print_simple_box(get_string("categories"), "CENTER", $side, "$THEME->cellheading"); + print_course_categories($categories, "none", $side); + } else { + print_simple_box(get_string("courses"), "CENTER", $side, "$THEME->cellheading"); + $category = array_shift($categories); + print_all_courses($category->id, "minimal", 10); + } } print_spacer(1,$side); } @@ -78,7 +85,7 @@ if ($site->newsitems == 0 ) { print_simple_box(get_string("availablecourses"), "CENTER", "100%", "$THEME->cellheading"); print_spacer(8,1); - print_all_courses(); + print_all_courses("all"); } else { if (! $newsforum = forum_get_course_forum($site->id, "news")) { diff --git a/lang/en/moodle.php b/lang/en/moodle.php index ae9defebc6..3f8e07a7a4 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -28,7 +28,10 @@ $string[answer] = "Answer"; $string[assignteachers] = "Assign teachers"; $string[availablecourses] = "Available Courses"; $string[cancel] = "Cancel"; +$string[categories] = "Course categories"; $string[category] = "Category"; +$string[categoryadded] = "The category '\$a' was added"; +$string[categorydeleted] = "The category '\$a' was deleted"; $string[changepassword] = "Change password"; $string[changedpassword] = "Changed password"; $string[changessaved] = "Changes saved"; @@ -140,7 +143,7 @@ $string[formattopics] = "Topics format"; $string[formatweeks] = "Weekly format"; $string[frontpagedescription] = "Front page description"; $string[frontpageformat] = "Front page format"; -$string[fulllistofcourses] = "Full list of courses"; +$string[fulllistofcourses] = "Show all courses"; $string[fullprofile] = "Full profile"; $string[fullname] = "Full name"; $string[fullsitename] = "Full site name"; @@ -220,6 +223,7 @@ $string[markthistopic] = "Mark this topic as the current topic"; $string[maximumchars] = "Maximum of \$a characters"; $string[maximumgrade] = "Maximum grade"; $string[maxsize] = "Max size: \$a"; +$string[miscellaneous] = "Miscellaneous"; // Default course category $string[missingcategory] = "You need to choose a category"; $string[missingcity] = "Missing city/town"; $string[missingcountry] = "Missing country"; @@ -350,6 +354,7 @@ $string[showonlytopic] = "Show only topic \$a"; $string[showonlyweek] = "Show only week \$a"; $string[showtheselogs] = "Show these logs"; $string[socialheadline] = "Social forum - latest topics"; +$string[showallcourses] = "Show all courses"; $string[site] = "Site"; $string[sites] = "Sites"; $string[sitelogs] = "Site logs"; diff --git a/version.php b/version.php index ecde90fb67..809b48dbdb 100644 --- a/version.php +++ b/version.php @@ -18,10 +18,10 @@ // If there's something it cannot do itself, it // will tell you what you need to do. -$version = 2002090800; // The current version is a date (YYYYMMDDXX) where +$version = 2002090900; // The current version is a date (YYYYMMDDXX) where // XX is a number that increments during the day -$release = "1.0.4 beta"; // For humans only, not used for the upgrade process +$release = "1.0.4"; // For humans only, not used for the upgrade process function upgrade_moodle($oldversion=0) { -- 2.39.5