From 0cdae0dcaaa61c11b340cef04f179915ec386cb9 Mon Sep 17 00:00:00 2001 From: skodak Date: Tue, 11 Apr 2006 21:41:21 +0000 Subject: [PATCH] general cleanup of xxx_parameter() functions + fixed several register globals problems --- course/format/lams/format.php | 7 +++++-- course/format/topics/format.php | 6 ++++-- course/format/weeks/format.php | 6 ++++-- course/format/weekscss/format.php | 6 ++++-- course/mod.php | 30 ++++++++++++++++-------------- course/view.php | 29 +++++++++++++++-------------- 6 files changed, 48 insertions(+), 36 deletions(-) diff --git a/course/format/lams/format.php b/course/format/lams/format.php index d5bc25d2b7..c0b74a2488 100644 --- a/course/format/lams/format.php +++ b/course/format/lams/format.php @@ -6,6 +6,9 @@ require_once($CFG->dirroot.'/mod/forum/lib.php'); require_once($CFG->dirroot.'/mod/lams/constants.php'); require_once($CFG->dirroot.'/lib/weblib.php'); + +$topic = optional_param('topic', -1, PARAM_INT); + // Bounds for block widths define('BLOCK_L_MIN_WIDTH', 100); define('BLOCK_L_MAX_WIDTH', 210); @@ -17,7 +20,7 @@ $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_widt $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), BLOCK_R_MAX_WIDTH); -if (isset($topic)) { +if ($topic != -1) { $displaysection = course_set_display($course->id, $topic); } else { if (isset($USER->display[$course->id])) { // for admins, mostly @@ -269,7 +272,7 @@ while ($section <= $course->numsections) { echo ''; if ($displaysection == $section) { // Show the zoom boxes - echo ''. + echo ''. '
'; } else { $strshowonlytopic = get_string('showonlytopic', '', $section); diff --git a/course/format/topics/format.php b/course/format/topics/format.php index 8f76d1d75e..1beb7c08e7 100644 --- a/course/format/topics/format.php +++ b/course/format/topics/format.php @@ -8,6 +8,8 @@ require_once($CFG->dirroot.'/mod/forum/lib.php'); + $topic = optional_param('topic', -1, PARAM_INT); + // Bounds for block widths define('BLOCK_L_MIN_WIDTH', 100); define('BLOCK_L_MAX_WIDTH', 210); @@ -19,7 +21,7 @@ $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), BLOCK_R_MAX_WIDTH); - if (isset($topic)) { + if ($topic != -1) { $displaysection = course_set_display($course->id, $topic); } else { if (isset($USER->display[$course->id])) { // for admins, mostly @@ -198,7 +200,7 @@ echo ''; if ($displaysection == $section) { // Show the zoom boxes - echo ''. + echo ''. ''.$strshowalltopics.'
'; } else { $strshowonlytopic = get_string('showonlytopic', '', $section); diff --git a/course/format/weeks/format.php b/course/format/weeks/format.php index 2c1be8c1a3..b20ea63b81 100644 --- a/course/format/weeks/format.php +++ b/course/format/weeks/format.php @@ -4,6 +4,8 @@ require_once("$CFG->dirroot/mod/forum/lib.php"); + $week = optional_param('week', -1, PARAM_INT); + // Bounds for block widths define('BLOCK_L_MIN_WIDTH', 100); define('BLOCK_L_MAX_WIDTH', 210); @@ -15,7 +17,7 @@ $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), BLOCK_R_MAX_WIDTH); - if (isset($week)) { + if ($week != -1) { $displaysection = course_set_display($course->id, $week); } else { if (isset($USER->display[$course->id])) { @@ -198,7 +200,7 @@ echo ''; if ($displaysection == $section) { - echo ''. + echo ''. ''.$strshowallweeks.'
'; } else { $strshowonlyweek = get_string("showonlyweek", "", $section); diff --git a/course/format/weekscss/format.php b/course/format/weekscss/format.php index 0fad3ca162..12d44ba492 100644 --- a/course/format/weekscss/format.php +++ b/course/format/weekscss/format.php @@ -27,6 +27,8 @@ require_once("$CFG->dirroot/mod/forum/lib.php"); + $week = optional_param('week', -1, PARAM_INT); + // Bounds for block widths; in PIXELS. define('BLOCK_L_MIN_WIDTH', 100); define('BLOCK_L_MAX_WIDTH', 210); @@ -47,7 +49,7 @@ $min_max_block= 'min-width:100px; max-width:210px; '; $min_max_main = 'min-width:25em; max-width:37em; '; //33em - if (isset($week)) { + if ($week != -1) { $displaysection = course_set_display($course->id, $week); } else { if (isset($USER->display[$course->id])) { @@ -226,7 +228,7 @@ echo '
'; if ($displaysection == $section) { - echo ''. + echo ''. ''.$strshowallweeks.'
'; } else { $strshowonlyweek = get_string("showonlyweek", "", $section); diff --git a/course/mod.php b/course/mod.php index 4e6330a160..d5f7b5376b 100644 --- a/course/mod.php +++ b/course/mod.php @@ -8,19 +8,21 @@ require_login(); $sectionreturn = optional_param('sr', '', PARAM_INT); - $add = optional_param( 'add','',PARAM_ALPHA ); - $type = optional_param( 'type','',PARAM_ALPHA ); - $indent = optional_param( 'indent',0,PARAM_INT ); - $update = optional_param( 'update',0,PARAM_INT ); - $hide = optional_param( 'hide',0,PARAM_INT ); - $show = optional_param( 'show',0,PARAM_INT ); - $copy = optional_param( 'copy',0,PARAM_INT ); - $moveto = optional_param( 'moveto',0,PARAM_INT ); - $movetosection = optional_param( 'movetosection',0,PARAM_INT ); - $delete = optional_param( 'delete',0,PARAM_INT ); - $course = optional_param( 'course',0,PARAM_INT ); - $groupmode = optional_param( 'groupmode',-1,PARAM_INT ); - $duplicate = optional_param( 'duplicate',0,PARAM_INT ); + $add = optional_param('add','', PARAM_ALPHA); + $type = optional_param('type', '', PARAM_ALPHA); + $indent = optional_param('indent', 0, PARAM_INT); + $update = optional_param('update', 0, PARAM_INT); + $hide = optional_param('hide', 0, PARAM_INT); + $show = optional_param('show', 0, PARAM_INT); + $copy = optional_param('copy', 0, PARAM_INT); + $moveto = optional_param('moveto', 0, PARAM_INT); + $movetosection = optional_param('movetosection', 0, PARAM_INT); + $delete = optional_param('delete', 0, PARAM_INT); + $course = optional_param('course', 0, PARAM_INT); + $groupmode = optional_param('groupmode', -1, PARAM_INT); + $duplicate = optional_param('duplicate', 0, PARAM_INT); + $cancel = optional_param('cancel', 0, PARAM_BOOL); + $cancelcopy = optional_param('cancelcopy', 0, PARAM_BOOL); if (isset($SESSION->modform)) { // Variables are stored in the session $mod = $SESSION->modform; @@ -29,7 +31,7 @@ $mod = (object)$_POST; } - if (isset($cancel)) { + if ($cancel) { if (!empty($SESSION->returnpage)) { $return = $SESSION->returnpage; unset($SESSION->returnpage); diff --git a/course/view.php b/course/view.php index 3235ee6d17..f58e65218b 100644 --- a/course/view.php +++ b/course/view.php @@ -7,14 +7,15 @@ require_once($CFG->libdir.'/blocklib.php'); $id = optional_param('id', 0, PARAM_INT); - $name = optional_param('name'); - $edit = optional_param('edit','',PARAM_ALPHA); - $idnumber = optional_param('idnumber'); - $topic = optional_param('topic',0,PARAM_INT); - $studentview = optional_param('studentview','',PARAM_ALPHA); - $section = optional_param('section',0,PARAM_INT); - $move = optional_param('move',0,PARAM_INT); - $marker = optional_param('marker',0,PARAM_INT); + $name = optional_param('name', '', PARAM_RAW); + $edit = optional_param('edit', -1, PARAM_BOOL); + $hide = optional_param('hide', 0, PARAM_INT); + $show = optional_param('show', 0, PARAM_INT); + $idnumber = optional_param('idnumber', '', PARAM_RAW); + $studentview = optional_param('studentview', -1, PARAM_BOOL); + $section = optional_param('section', 0, PARAM_INT); + $move = optional_param('move', 0, PARAM_INT); + $marker = optional_param('marker',0 , PARAM_INT); if (empty($id) && empty($name) && empty($idnumber)) { @@ -69,14 +70,14 @@ } // need to check this here, as studentview=on disables edit allowed (where 'on' is checked) - if (($studentview == 'off') and confirm_sesskey()) { + if (($studentview == 0) and confirm_sesskey()) { $USER->studentview = false; } if ($PAGE->user_allowed_editing()) { - if (($edit == 'on') and confirm_sesskey()) { + if (($edit == 1) and confirm_sesskey()) { $USER->editing = true; - } else if (($edit == 'off') and confirm_sesskey()) { + } else if (($edit == 0) and confirm_sesskey()) { $USER->editing = false; if(!empty($USER->activitycopy) && $USER->activitycopycourse == $course->id) { $USER->activitycopy = false; @@ -84,16 +85,16 @@ } } - if (($studentview == 'on') and confirm_sesskey()) { + if (($studentview == 1) and confirm_sesskey()) { $USER->studentview = true; $USER->editing = false; } - if (isset($hide) && confirm_sesskey()) { + if ($hide && confirm_sesskey()) { set_section_visible($course->id, $hide, '0'); } - if (isset($show) && confirm_sesskey()) { + if ($show && confirm_sesskey()) { set_section_visible($course->id, $show, '1'); } -- 2.39.5