From 7d99d6959ea26a03cfe0df361f3141b1f94fdff9 Mon Sep 17 00:00:00 2001 From: moodler Date: Sun, 4 May 2003 07:59:46 +0000 Subject: [PATCH] New feature: hide/show topics! --- course/lib.php | 18 ++++++- course/topics.php | 110 +++++++++++++++++++++++++++---------------- course/view.php | 9 ++++ lib/db/mysql.php | 4 ++ lib/db/mysql.sql | 1 + lib/db/postgres7.php | 4 ++ lib/db/postgres7.sql | 3 +- version.php | 2 +- 8 files changed, 106 insertions(+), 45 deletions(-) diff --git a/course/lib.php b/course/lib.php index 6ec9a6d2bb..17e211ad17 100644 --- a/course/lib.php +++ b/course/lib.php @@ -504,7 +504,7 @@ function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modname function get_all_sections($courseid) { return get_records("course_sections", "course", "$courseid", "section", - "section, id, course, summary, sequence"); + "section, id, course, summary, sequence, visible"); } function course_set_display($courseid, $display=0) { @@ -546,6 +546,20 @@ function course_section_visible($courseid, $section) { return $USER->display[$courseid] == $section; } +function set_section_visible($courseid, $sectionnumber, $visibility) { +/// For a given course section, markes it visible or hidden, +/// and does the same for every activity in that section + + if ($section = get_record("course_sections", "course", $courseid, "section", $sectionnumber)) { + set_field("course_sections", "visible", "$visibility", "id", $section->id); + if (!empty($section->sequence)) { + $modules = explode(",", $section->sequence); + foreach ($modules as $moduleid) { + set_field("course_modules", "visible", "$visibility", "id", $moduleid); + } + } + } +} function print_section_block($heading, $course, $section, $mods, $modnames, $modnamesused, $absolute=true, $width="100%", $isediting=false) { @@ -688,7 +702,7 @@ function print_side_block_start($heading="", $width=180, $class="sideblockmain") function print_side_block_end() { echo ""; - echo "
"; + echo "
"; } diff --git a/course/topics.php b/course/topics.php index 77fd7e8477..558058c075 100644 --- a/course/topics.php +++ b/course/topics.php @@ -32,6 +32,9 @@ $streditsummary = get_string("editsummary"); $stradd = get_string("add"); $stractivities = get_string("activities"); + $strshowalltopics = get_string("showalltopics"); + $strtopichide = get_string("topichide"); + $strtopicshow = get_string("topicshow"); /// Layout the whole page as three big columns. @@ -110,6 +113,7 @@ echo ""; echo "cellheading\" class=\"topicsoutlineside\" valign=top align=center width=10> "; + echo "id&topic=all\" title=\"$strshowalltopics\">

"; echo ""; echo ""; echo ""; @@ -129,9 +133,26 @@ continue; } + if (!empty($sections[$section])) { + $thissection = $sections[$section]; + + } else { + unset($thissection); + $thissection->course = $course->id; // Create a new section structure + $thissection->section = $section; + $thissection->summary = ""; + $thissection->visible = 1; + if (!$thissection->id = insert_record("course_sections", $thissection)) { + notify("Error inserting new topic!"); + } + } + $currenttopic = ($course->marker == $section); - if ($currenttopic) { + if (!$thissection->visible) { + $colorsides = "bgcolor=\"$THEME->hidden\" class=\"topicsoutlinesidehidden\""; + $colormain = "bgcolor=\"$THEME->cellcontent\" class=\"topicsoutlinecontenthidden\""; + } else if ($currenttopic) { $colorsides = "bgcolor=\"$THEME->cellheading2\" class=\"topicsoutlinesidehighlight\""; $colormain = "bgcolor=\"$THEME->cellcontent\" class=\"topicsoutlinecontenthighlight\""; } else { @@ -143,53 +164,60 @@ echo ""; echo "

$section

"; echo ""; - - echo ""; - - if (!empty($sections[$section])) { - $thissection = $sections[$section]; + + if (!isteacher($course->id) and !$thissection->visible) { // Hidden for students + echo ""; + echo get_string("notavailable"); + echo ""; + echo " "; + echo ""; } else { - unset($thissection); - $thissection->course = $course->id; // Create a new section structure - $thissection->section = $section; - $thissection->summary = ""; - if (!$thissection->id = insert_record("course_sections", $thissection)) { - notify("Error inserting new topic!"); - } - } - - if (isediting($course->id)) { - $thissection->summary .= " id>\"$streditsummary\""; - } + echo ""; - echo text_to_html($thissection->summary); + if (isediting($course->id)) { + $thissection->summary .= " id>\"$streditsummary\""; + } + + echo text_to_html($thissection->summary); + + print_section($course, $thissection, $mods, $modnamesused); + + if (isediting($course->id)) { + echo "
"; + popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&section=$section&add=", + $modnames, "section$section", "", "$stradd...", "mods", $stractivities); + echo "
"; + } + + echo ""; + echo ""; + echo ""; + + if ($displaysection == $section) { // Show the zoom box + echo "id&topic=all\" title=\"$strshowalltopics\">

"; + } else { + $strshowonlytopic = get_string("showonlytopic", "", $section); + echo "id&topic=$section\" title=\"$strshowonlytopic\">

"; + } - print_section($course, $thissection, $mods, $modnamesused); + if (isediting($course->id) and $course->marker != $section) { // Show the "tick" + $strmarkthistopic = get_string("markthistopic"); + echo "id&marker=$section\" title=\"$strmarkthistopic\">

"; + } - if (isediting($course->id)) { - echo "
"; - popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&section=$section&add=", - $modnames, "section$section", "", "$stradd...", "mods", $stractivities); - echo "
"; - } + if (isediting($course->id)) { // Show the hide/show eye + if ($thissection->visible) { + echo "id&hide=$section\" title=\"$strtopichide\">

"; + + } else { + echo "id&show=$section\" title=\"$strtopicshow\">

"; + } + } - echo ""; - echo ""; - echo ""; - if ($displaysection == $section) { - $strshowalltopics = get_string("showalltopics"); - echo "id&topic=all\" title=\"$strshowalltopics\">

"; - } else { - $strshowonlytopic = get_string("showonlytopic", "", $section); - echo "id&topic=$section\" title=\"$strshowonlytopic\">

"; - } - if (isediting($course->id) and $course->marker != $section) { - $strmarkthistopic = get_string("markthistopic"); - echo "id&marker=$section\" title=\"$strmarkthistopic\">

"; + echo ""; + echo ""; } - echo ""; - echo ""; echo ""; $section++; diff --git a/course/view.php b/course/view.php index 75808f865e..f8f6cfcf10 100644 --- a/course/view.php +++ b/course/view.php @@ -44,6 +44,14 @@ } } + if (isset($hide)) { + set_section_visible($course->id, $hide, "0"); + } + + if (isset($show)) { + set_section_visible($course->id, $show, "1"); + } + $SESSION->fromdiscussion = "$CFG->wwwroot/course/view.php?id=$course->id"; if (! $course->category) { // This course is not a real course. @@ -76,6 +84,7 @@ } } + switch ($course->format) { case "weeks": include("weeks.php"); diff --git a/lib/db/mysql.php b/lib/db/mysql.php index c317b6011f..97e8be11f1 100644 --- a/lib/db/mysql.php +++ b/lib/db/mysql.php @@ -375,6 +375,10 @@ function main_upgrade($oldversion=0) { ) TYPE=MyISAM COMMENT='Stores info about how to display the course'"); } + if ($oldversion < 2003050400) { + table_column("course_sections", "", "visible", "integer", "1", "unsigned", "1", "", ""); + } + return $result; } diff --git a/lib/db/mysql.sql b/lib/db/mysql.sql index 748b0ce29f..d32571f2ed 100644 --- a/lib/db/mysql.sql +++ b/lib/db/mysql.sql @@ -110,6 +110,7 @@ CREATE TABLE `prefix_course_sections` ( `section` int(10) unsigned NOT NULL default '0', `summary` text NOT NULL, `sequence` varchar(255) NOT NULL default '', + `visible` tinyint(1) NOT NULL default '1', PRIMARY KEY (`id`) ) TYPE=MyISAM; # -------------------------------------------------------- diff --git a/lib/db/postgres7.php b/lib/db/postgres7.php index 11c5630e92..6227030062 100644 --- a/lib/db/postgres7.php +++ b/lib/db/postgres7.php @@ -137,6 +137,10 @@ function main_upgrade($oldversion=0) { execute_sql("CREATE INDEX {$CFG->prefix}course_display_courseuserid_idx ON {$CFG->prefix}course_display (course,userid)"); } + + if ($oldversion < 2003050400) { + table_column("course_sections", "", "visible", "integer", "1", "unsigned", "1", "", ""); + } return $result; } diff --git a/lib/db/postgres7.sql b/lib/db/postgres7.sql index e62662975c..8513496f4b 100644 --- a/lib/db/postgres7.sql +++ b/lib/db/postgres7.sql @@ -58,7 +58,8 @@ CREATE TABLE prefix_course_sections ( course integer NOT NULL default '0', section integer NOT NULL default '0', summary text NOT NULL default '', - sequence varchar(255) NOT NULL default '' + sequence varchar(255) NOT NULL default '', + visible integer NOT NULL default '1' ); CREATE TABLE prefix_log ( diff --git a/version.php b/version.php index 4c7e7893e2..06054e584a 100644 --- a/version.php +++ b/version.php @@ -5,7 +5,7 @@ // database to determine whether upgrades should // be performed (see lib/db/*.php) -$version = 2003042801; // The current version is a date (YYYYMMDDXX) +$version = 2003050400; // The current version is a date (YYYYMMDDXX) $release = "1.0.9 development"; // User-friendly version number -- 2.39.5