From 7168423c824d0defa49fddeb0744c137fa45b5b3 Mon Sep 17 00:00:00 2001 From: thepurpleblob Date: Tue, 14 Jun 2005 09:21:09 +0000 Subject: [PATCH] Replaced require_variable(), optional_variable() with approproate required_param(), optional_param() etc. --- course/category.php | 32 ++++++++++++++++++++------------ course/delete.php | 4 ++-- course/edit.php | 4 ++-- course/index.php | 26 ++++++++++++++++++-------- 4 files changed, 42 insertions(+), 24 deletions(-) diff --git a/course/category.php b/course/category.php index 1ce016f8b26..897442f45a8 100644 --- a/course/category.php +++ b/course/category.php @@ -6,9 +6,17 @@ require_once("../config.php"); require_once("lib.php"); - require_variable($id); // Category id - optional_variable($page, "0"); // which page to show - optional_variable($perpage, "20"); // how many per page + $id = required_param('id',PARAM_INT); // Category id + $page = optional_param('page', 0, PARAM_INT); // which page to show + $perpage = optional_param('perpage', 20, PARAM_INT); // how many per page + $edit = optional_param('edit','',PARAM_ALPHA); + $hide = optional_param('hide',0,PARAM_INT); + $show = optional_param('show',0,PARAM_INT); + $moveup = optional_param('moveup',0,PARAM_INT); + $movedown = optional_param('movedown',0,PARAM_INT); + $moveto = optional_param('moveto',0,PARAM_INT); + $rename = optional_param('rename',''); + $resort = optional_param('resort',''); if (!$site = get_site()) { error("Site isn't defined!"); @@ -23,7 +31,7 @@ } if (iscreator()) { - if (isset($_GET['edit']) and confirm_sesskey()) { + if (!empty($edit) and confirm_sesskey()) { if ($edit == "on") { $USER->categoryediting = true; } else if ($edit == "off") { @@ -47,8 +55,8 @@ if (isadmin()) { /// Rename the category if requested - if (!empty($_POST['rename']) and confirm_sesskey()) { - $category->name = $_POST['rename']; + if (!empty($rename) and confirm_sesskey()) { + $category->name = $rename; if (! set_field("course_categories", "name", $category->name, "id", $category->id)) { notify("An error occurred while renaming the category"); } @@ -56,7 +64,7 @@ /// Resort the category if requested - if (!empty($_GET['resort']) and confirm_sesskey()) { + if (!empty($resort) and confirm_sesskey()) { if ($courses = get_courses($category->id, "fullname ASC", 'c.id,c.fullname,c.sortorder')) { // move it off the range $count = get_record_sql('SELECT MAX(sortorder) AS max, 1 @@ -118,7 +126,7 @@ /// Move a specified course to a new category - if (isset($moveto) and $data = data_submitted() and confirm_sesskey()) { // Some courses are being moved + if (!empty($moveto) and $data = data_submitted() and confirm_sesskey()) { // Some courses are being moved if (! $destcategory = get_record("course_categories", "id", $data->moveto)) { error("Error finding the category"); @@ -157,8 +165,8 @@ /// Hide or show a course - if ((isset($hide) or isset($show)) and confirm_sesskey()) { - if (isset($hide)) { + if ((!empty($hide) or !empty($show)) and confirm_sesskey()) { + if (!empty($hide)) { $course = get_record("course", "id", $hide); $visible = 0; } else { @@ -175,7 +183,7 @@ /// Move a course up or down - if ((isset($moveup) or isset($movedown)) and confirm_sesskey()) { + if ((!empty($moveup) or !empty($movedown)) and confirm_sesskey()) { $movecourse = NULL; $swapcourse = NULL; @@ -189,7 +197,7 @@ FROM ' . $CFG->prefix . 'course WHERE category=' . $category->id); $max = $max->max + 100; - if (isset($moveup)) { + if (!empty($moveup)) { $movecourse = get_record('course', 'id', $moveup); $swapcourse = get_record('course', 'category', $category->id, diff --git a/course/delete.php b/course/delete.php index 538e0318c68..09df1d2c2b1 100644 --- a/course/delete.php +++ b/course/delete.php @@ -3,8 +3,8 @@ require_once("../config.php"); - require_variable($id); // course id - optional_variable($delete); // delete confirmation + $id = required_param('id',PARAM_INT); // course id + $delete = optional_param('delete'); // delete confirmation require_login(); diff --git a/course/edit.php b/course/edit.php index 37771c940b9..482121403a9 100644 --- a/course/edit.php +++ b/course/edit.php @@ -5,8 +5,8 @@ require_once("lib.php"); require_once("$CFG->libdir/blocklib.php"); - $id = (int)optional_param('id', 0); // course id - $category = (int)optional_param('category', 0); // possible default category + $id = optional_param('id', 0, PARAM_INT); // course id + $category = optional_param('category', 0, PARAM_INT); // possible default category require_login(); diff --git a/course/index.php b/course/index.php index 254bc17ae82..b8d6389795a 100644 --- a/course/index.php +++ b/course/index.php @@ -5,6 +5,16 @@ require_once("../config.php"); require_once("lib.php"); + $edit = optional_param( 'edit','',PARAM_ALPHA ); + $delete = optional_param( 'delete',0,PARAM_INT ); + $hide = optional_param( 'hide',0,PARAM_INT ); + $show = optional_param( 'show',0,PARAM_INT ); + $sure = optional_param( 'sure','',PARAM_CLEAN ); + $move = optional_param( 'move',0,PARAM_INT ); + $moveto = optional_param( 'moveto',-1,PARAM_INT ); + $moveup = optional_param( 'moveup',0,PARAM_INT ); + $movedown = optional_param( 'movedown',0,PARAM_INT ); + if (!$site = get_site()) { error("Site isn't defined!"); } @@ -14,7 +24,7 @@ } if (isadmin()) { - if (isset($_GET['edit']) and confirm_sesskey()) { + if (!empty($edit) and confirm_sesskey()) { if ($edit == "on") { $USER->categoriesediting = true; } else if ($edit == "off") { @@ -101,7 +111,7 @@ /// Delete a category if necessary - if (isset($delete) and confirm_sesskey()) { + if (!empty($delete) and confirm_sesskey()) { if ($deletecat = get_record("course_categories", "id", $delete)) { if (!empty($sure) && $sure == md5($deletecat->timemodified)) { /// Send the children categories to live with their grandparent @@ -154,7 +164,7 @@ /// Move a category to a new parent if required - if (isset($move) and isset($moveto) and confirm_sesskey()) { + if (!empty($move) and ($moveto>=0) and confirm_sesskey()) { if ($tempcat = get_record("course_categories", "id", $move)) { if ($tempcat->parent != $moveto) { if (! set_field("course_categories", "parent", $moveto, "id", $tempcat->id)) { @@ -166,8 +176,8 @@ /// Hide or show a category - if ((isset($hide) or isset($show)) and confirm_sesskey()) { - if (isset($hide)) { + if ((!empty($hide) or !empty($show)) and confirm_sesskey()) { + if (!empty($hide)) { $tempcat = get_record("course_categories", "id", $hide); $visible = 0; } else { @@ -187,12 +197,12 @@ /// Move a category up or down - if ((isset($moveup) or isset($movedown)) and confirm_sesskey()) { + if ((!empty($moveup) or !empty($movedown)) and confirm_sesskey()) { $swapcategory = NULL; $movecategory = NULL; - if (isset($moveup)) { + if (!empty($moveup)) { if ($movecategory = get_record("course_categories", "id", $moveup)) { $categories = get_categories("$movecategory->parent"); @@ -204,7 +214,7 @@ } } } - if (isset($movedown)) { + if (!empty($movedown)) { if ($movecategory = get_record("course_categories", "id", $movedown)) { $categories = get_categories("$movecategory->parent");