From aac94fd0ccfe0f3f09a225fb260ecfbccc90a478 Mon Sep 17 00:00:00 2001 From: moodler Date: Sun, 14 Sep 2003 16:31:33 +0000 Subject: [PATCH] New field on course_modules called "indent" ... this is an integer that tells us how far to indent the activity when it is displayed. This gives us some more flexibility on the course outline to arrange things as we might like them, into subtopics etc Backup/restore is updated as well. There is also a bit more robustness in course/mod.php --- backup/backuplib.php | 1 + backup/restorelib.php | 6 ++++ course/lib.php | 28 ++++++++++++++++-- course/mod.php | 68 ++++++++++++++++++++++++++++++------------- lib/db/mysql.php | 4 +++ lib/db/mysql.sql | 1 + lib/db/postgres7.php | 5 ++++ lib/db/postgres7.sql | 1 + version.php | 2 +- 9 files changed, 91 insertions(+), 25 deletions(-) diff --git a/backup/backuplib.php b/backup/backuplib.php index ba6ce1bbf8..aa80ff6f48 100644 --- a/backup/backuplib.php +++ b/backup/backuplib.php @@ -530,6 +530,7 @@ fwrite ($bf,full_tag("ADDED",6,false,$course_module[$tok]->added)); fwrite ($bf,full_tag("DELETED",6,false,$course_module[$tok]->deleted)); fwrite ($bf,full_tag("SCORE",6,false,$course_module[$tok]->score)); + fwrite ($bf,full_tag("INDENT",6,false,$course_module[$tok]->indent)); fwrite ($bf,full_tag("VISIBLE",6,false,$course_module[$tok]->visible)); fwrite ($bf,end_tag("MOD",5,true)); } diff --git a/backup/restorelib.php b/backup/restorelib.php index 1d20d2b481..bcd6c973ac 100644 --- a/backup/restorelib.php +++ b/backup/restorelib.php @@ -394,6 +394,7 @@ $course_module->added = $mod->added; $course_module->deleted = $mod->deleted; $course_module->score = $mod->score; + $course_module->indent = $mod->indent; $course_module->visible = $mod->visible; $course_module->instance = null; //NOTE: The instance (new) is calculated and updated in db in the @@ -1320,6 +1321,8 @@ $this->info->tempmod->deleted; $this->info->tempsection->mods[$this->info->tempmod->id]->score = $this->info->tempmod->score; + $this->info->tempsection->mods[$this->info->tempmod->id]->indent = + $this->info->tempmod->indent; $this->info->tempsection->mods[$this->info->tempmod->id]->visible = $this->info->tempmod->visible; unset($this->info->tempmod); @@ -1345,6 +1348,9 @@ case "SCORE": $this->info->tempmod->score = $this->getContents(); break; + case "INDENT": + $this->info->tempmod->indent = $this->getContents(); + break; case "VISIBLE": $this->info->tempmod->visible = $this->getContents(); break; diff --git a/course/lib.php b/course/lib.php index d476ace061..3af0aa7bdf 100644 --- a/course/lib.php +++ b/course/lib.php @@ -637,8 +637,18 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false, $extra = ""; } + if ($mod->indent) { + print_spacer(12, 20 * $mod->indent, false); + } + if ($mod->modname == "label") { + if (!$mod->visible) { + echo ""; + } echo format_text($extra, FORMAT_HTML); + if (!$mod->visible) { + echo ""; + } } else { // Normal activity $linkcss = $mod->visible ? "" : " class=\"dimmed\" "; @@ -650,7 +660,7 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false, echo ""; if ($isediting) { echo ""; - echo make_editing_buttons($mod->id, $absolute, $mod->visible); + echo make_editing_buttons($mod->id, $absolute, $mod->visible, true, $mod->indent); echo " "; } echo ""; @@ -1508,7 +1518,7 @@ function move_module($cm, $move) { } } -function make_editing_buttons($moduleid, $absolute=false, $visible=true, $moveselect=true) { +function make_editing_buttons($moduleid, $absolute=false, $visible=true, $moveselect=true, $indent=-1) { global $CFG, $THEME; static $str = ''; @@ -1517,6 +1527,8 @@ function make_editing_buttons($moduleid, $absolute=false, $visible=true, $movese $str->move = get_string("move"); $str->moveup = get_string("moveup"); $str->movedown = get_string("movedown"); + $str->moveright = get_string("moveright"); + $str->moveleft = get_string("moveleft"); $str->update = get_string("update"); $str->hide = get_string("hide"); $str->show = get_string("show"); @@ -1552,7 +1564,17 @@ function make_editing_buttons($moduleid, $absolute=false, $visible=true, $movese " src=\"$pixpath/t/down.gif\" height=11 width=11 border=0> "; } - return "delete\" href=\"$path/mod.php?delete=$moduleid\"> 0) { + $leftright .= "moveleft\" href=\"$path/mod.php?id=$moduleid&indent=-1\"> "; + } + if ($indent >= 0) { + $leftright .= "moveright\" href=\"$path/mod.php?id=$moduleid&indent=1\"> "; + } + + return "$leftrightdelete\" href=\"$path/mod.php?delete=$moduleid\"> $move". "update\" href=\"$path/mod.php?update=$moduleid\"> $hideshow"; diff --git a/course/mod.php b/course/mod.php index 73d4a331d5..86a0da9528 100644 --- a/course/mod.php +++ b/course/mod.php @@ -103,7 +103,7 @@ } - if (isset($move)) { + if (isset($_GET['move'])) { require_variable($id); @@ -115,7 +115,7 @@ error("You can't modify this course!"); } - move_module($cm, $move); + move_module($cm, $_GET['move']); rebuild_course_cache($cm->course); @@ -127,20 +127,20 @@ } exit; - } else if (isset($movetosection) or isset($moveto)) { + } else if (isset($_GET['movetosection']) or isset($_GET['moveto'])) { if (! $cm = get_record("course_modules", "id", $USER->activitycopy)) { error("The copied course module doesn't exist!"); } - if (isset($movetosection)) { - if (! $section = get_record("course_sections", "id", $movetosection)) { + if (isset($_GET['movetosection'])) { + if (! $section = get_record("course_sections", "id", $_GET['movetosection'])) { error("This section doesn't exist"); } $beforecm = NULL; } else { // normal moveto - if (! $beforecm = get_record("course_modules", "id", $moveto)) { + if (! $beforecm = get_record("course_modules", "id", $_GET['moveto'])) { error("The destination course module doesn't exist"); } if (! $section = get_record("course_sections", "id", $beforecm->section)) { @@ -171,9 +171,35 @@ redirect("view.php?id=$section->course"); } - } else if (isset($hide)) { + } else if (isset($_GET['indent'])) { - if (! $cm = get_record("course_modules", "id", $hide)) { + require_variable($id); + + if (! $cm = get_record("course_modules", "id", $id)) { + error("This course module doesn't exist"); + } + + $cm->indent += $_GET['indent']; + + if ($cm->indent < 0) { + $cm->indent = 0; + } + + if (!set_field("course_modules", "indent", $cm->indent, "id", $cm->id)) { + error("Could not update the indent level on that course module"); + } + + $site = get_site(); + if ($site->id == $cm->course) { + redirect($CFG->wwwroot); + } else { + redirect("view.php?id=$cm->course"); + } + exit; + + } else if (isset($_GET['hide'])) { + + if (! $cm = get_record("course_modules", "id", $_GET['hide'])) { error("This course module doesn't exist"); } @@ -193,9 +219,9 @@ } exit; - } else if (isset($show)) { + } else if (isset($_GET['show'])) { - if (! $cm = get_record("course_modules", "id", $show)) { + if (! $cm = get_record("course_modules", "id", $_GET['show'])) { error("This course module doesn't exist"); } @@ -225,9 +251,9 @@ } exit; - } else if (isset($copy)) { // value = course module + } else if (isset($_GET['copy'])) { // value = course module - if (! $cm = get_record("course_modules", "id", $copy)) { + if (! $cm = get_record("course_modules", "id", $_GET['copy'])) { error("This course module doesn't exist"); } @@ -253,7 +279,7 @@ redirect("view.php?id=$cm->course"); - } else if (isset($cancelcopy)) { // value = course module + } else if (isset($_GET['cancelcopy'])) { // value = course module $courseid = $USER->activitycopycourse; @@ -263,9 +289,9 @@ redirect("view.php?id=$courseid"); - } else if (isset($delete)) { // value = course module + } else if (isset($_GET['delete'])) { // value = course module - if (! $cm = get_record("course_modules", "id", $delete)) { + if (! $cm = get_record("course_modules", "id", $_GET['delete'])) { error("This course module doesn't exist"); } @@ -293,7 +319,7 @@ "$CFG->wwwroot/course/view.php?id=$course->id"); } - $fullmodulename = strtolower(get_string("modulename", $module->name)); + $fullmodulename = get_string("modulename", $module->name); $form->coursemodule = $cm->id; $form->section = $cm->section; @@ -319,9 +345,9 @@ exit; - } else if (isset($update)) { // value = course module + } else if (isset($_GET['update'])) { // value = course module - if (! $cm = get_record("course_modules", "id", $update)) { + if (! $cm = get_record("course_modules", "id", $_GET['update'])) { error("This course module doesn't exist"); } @@ -369,9 +395,9 @@ } - } else if (isset($add)) { + } else if (isset($_GET['add'])) { - if (!$add) { + if (empty($_GET['add'])) { redirect($_SERVER["HTTP_REFERER"]); die; } @@ -383,7 +409,7 @@ error("This course doesn't exist"); } - if (! $module = get_record("modules", "name", $add)) { + if (! $module = get_record("modules", "name", $_GET['add'])) { error("This module type doesn't exist"); } diff --git a/lib/db/mysql.php b/lib/db/mysql.php index 71a209820c..d5b6ef0918 100644 --- a/lib/db/mysql.php +++ b/lib/db/mysql.php @@ -501,6 +501,10 @@ function main_upgrade($oldversion=0) { execute_sql(" INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('course', 'user report', 'user', 'CONCAT(firstname,\" \",lastname)') "); } + if ($oldversion < 2003091400) { + table_column("course_modules", "", "indent", "integer", "5", "unsigned", "0", "", "score"); + } + return $result; } diff --git a/lib/db/mysql.sql b/lib/db/mysql.sql index dd3e025eb7..9b8b2a9b3b 100644 --- a/lib/db/mysql.sql +++ b/lib/db/mysql.sql @@ -104,6 +104,7 @@ CREATE TABLE `prefix_course_modules` ( `added` int(10) unsigned NOT NULL default '0', `deleted` tinyint(1) unsigned NOT NULL default '0', `score` tinyint(4) NOT NULL default '0', + `indent` int(5) unsigned NOT NULL default '0', `visible` tinyint(1) NOT NULL default '1', PRIMARY KEY (`id`), UNIQUE KEY `id` (`id`) diff --git a/lib/db/postgres7.php b/lib/db/postgres7.php index e4ce836925..89e6a89a03 100644 --- a/lib/db/postgres7.php +++ b/lib/db/postgres7.php @@ -250,6 +250,11 @@ function main_upgrade($oldversion=0) { table_column("course", "", "showrecent", "integer", "10", "unsigned", "1", "", "numsections"); } + if ($oldversion < 2003091400) { + table_column("course_modules", "", "indent", "integer", "5", "unsigned", "0", "", "score"); + } + + return $result; } ?> diff --git a/lib/db/postgres7.sql b/lib/db/postgres7.sql index dee9e0793a..5e4fe2d321 100644 --- a/lib/db/postgres7.sql +++ b/lib/db/postgres7.sql @@ -62,6 +62,7 @@ CREATE TABLE prefix_course_modules ( added integer NOT NULL default '0', deleted integer NOT NULL default '0', score integer NOT NULL default '0', + indent integer NOT NULL default '0', visible integer NOT NULL default '1' ); diff --git a/version.php b/version.php index d5c1f71c14..3049095b82 100644 --- a/version.php +++ b/version.php @@ -5,7 +5,7 @@ // database to determine whether upgrades should // be performed (see lib/db/*.php) -$version = 2003091111; // The current version is a date (YYYYMMDDXX) +$version = 2003091400; // The current version is a date (YYYYMMDDXX) $release = "1.2 development"; // User-friendly version number -- 2.39.5