Permalink
Browse files

Use of 'register_global' type functionality removed and replaced with

required_param() and optional_param().
  • Loading branch information...
1 parent d3753d4 commit 2fbfbcdd7ba72a5b6d8093174083b4cf43b8d022 thepurpleblob committed Jun 9, 2005
Showing with 51 additions and 76 deletions.
  1. +4 −4 backup/backup.php
  2. +16 −37 backup/backup_execute.html
  3. +4 −4 backup/backup_form.html
  4. +5 −5 backup/restore.php
  5. +14 −18 backup/restore_check.html
  6. +8 −8 backup/restore_form.html
View
8 backup/backup.php
@@ -8,10 +8,10 @@
require_once ("backuplib.php");
require_once ("$CFG->libdir/blocklib.php");
- optional_variable($id); // course id
- optional_variable($to); // id of course to import into afterwards.
- optional_variable($cancel);
- optional_variable($launch);
+ $id = optional_param( 'id' ); // course id
+ $to = optional_param( 'to' ); // id of course to import into afterwards.
+ $cancel = optional_param( 'cancel' );
+ $launch = optional_param( 'launch' );
require_login();
View
53 backup/backup_execute.html
@@ -43,21 +43,19 @@
$count++;
}
}
+
//Check data
//Check module info
$var = "backup_".$modname;
- if (!isset($$var)) {
- //Every undefined backup_XXXX isn't exported
- $$var = 0;
- }
+ $$var = optional_param( $var,0,PARAM_INT );
+
//Now stores all the mods preferences into an array into preferences
$preferences->mods[$modname]->backup = $$var;
//Check include user info
$var = "backup_user_info_".$modname;
- if (!isset($$var)) {
- $$var = 1;
- }
+ $$var = optional_param( $var,0,PARAM_INT );
+
//Now stores all the mods preferences into an array into preferences
$preferences->mods[$modname]->userinfo = $$var;
//And the name of the mod
@@ -66,50 +64,31 @@
}
//Check other parameters
- if (!isset($backup_metacourse)) {
- $backup_metacourse = 1;
- }
+ $backup_metacourse = optional_param( 'backup_metacourse',1,PARAM_INT );
$preferences->backup_metacourse = $backup_metacourse;
-
- if (!isset($backup_users)) {
- $backup_users = 1;
- }
+
+ $backup_users = optional_param( 'backup_users',1,PARAM_INT );
$preferences->backup_users = $backup_users;
- if (!isset($backup_logs)) {
- $backup_logs = 0;
- }
+ $backup_logs = optional_param( 'backup_logs',0,PARAM_INT );
$preferences->backup_logs = $backup_logs;
- if (!isset($backup_user_files)) {
- $backup_user_files = 1;
- }
+ $backup_user_files = optional_param( 'backup_user_files',1,PARAM_INT );
$preferences->backup_user_files = $backup_user_files;
- if (!isset($backup_course_files)) {
- $backup_course_files = 2;
- }
+ $backup_course_files = optional_param( 'backup_course_files',2,PARAM_INT );
$preferences->backup_course_files = $backup_course_files;
- if (!isset($backup_messages)) {
- $backup_messages = 1;
- }
+ $backup_messages = optional_param( 'backup_messages',1,PARAM_INT );
$preferences->backup_messages = $backup_messages;
- if (!isset($id)) {
- error ("Course not specified");
- }
+ $id = required_param('id');
$preferences->backup_course = $id;
- if (!isset($backup_name)) {
- error ("Backup name not specified");
- }
- //We clean it again (to prevent diacritics entered manually)
- $preferences->backup_name = clean_filename($backup_name);
+ $backup_name = required_param('backup_name',PARAM_FILE );
+ $preferences->backup_name = $backup_name;
- if (!isset($backup_unique_code)) {
- error ("Backup unique code not specified");
- }
+ $backup_unique_code = required_param('backup_unique_code');
$preferences->backup_unique_code = $backup_unique_code;
//Another Info
View
8 backup/backup_form.html
@@ -99,9 +99,9 @@
if (isset($$var) && $$var) {
//Print the full tr
echo "<tr>";
- echo "<td align=\"right\"><b>";
+ echo " <td align=\"right\"><b>";
echo get_string("include")." ". get_string("modulenameplural",$modname).":";
- echo "</b></td><td>";
+ echo "</b></td><td>\n";
$backup_options[0] = get_string("no");
$backup_options[1] = get_string("yes");
$var = "backup_".$modname;
@@ -115,11 +115,11 @@
else {
echo '<input type="hidden" name="'.$var.'" value="0" />';
}
- echo "</td></tr>";
+ echo "</td></tr>\n";
}
}
//Line
- echo "<tr><td colspan=\"2\"><hr /></td></tr>";
+ echo "<tr><td colspan=\"2\"><hr /></td></tr>\n";
if (empty($to)) {
//Now print the Metacourse tr
View
10 backup/restore.php
@@ -14,11 +14,11 @@
require_once("$CFG->libdir/wiki_to_markdown.php" );
//Optional
- optional_variable($id);
- optional_variable($file);
- optional_variable($cancel);
- optional_variable($launch);
- optional_variable($to);
+ $id = optional_param( 'id' );
+ $file = optional_param( 'file' );;
+ $cancel = optional_param( 'cancel' );
+ $launch = optional_param( 'launch' );
+ $to = optional_param( 'to' );
//Check login
require_login();
View
32 backup/restore_check.html
@@ -20,47 +20,43 @@
unset($restore);
}
- //Check required objects from session
-
- //info
- require_variable($info);
-
- //course_header
- require_variable($course_header);
+ // check for session objects
+ assert_var_set( $info, 'info' );
+ assert_var_set( $course_header, 'course_header' );
//If the restore object doesn't exist, we are going
//to check every variable individually and create it
if (!isset($restore)) {
//Check that we have all we need
//backup_unique_code
- require_variable($backup_unique_code);
+ $backup_unique_code = required_param( 'backup_unique_code' );
//file
- require_variable($file);
+ $file = required_param( 'file');
//Checks for the required restoremod parameters
if ($allmods = get_records("modules")) {
foreach ($allmods as $mod) {
$modname = $mod->name;
$var = "restore_".$modname;
- require_variable($$var);
+ $$var = required_param( $var);
$var = "restore_user_info_".$modname;
- require_variable($$var);
+ $$var = required_param( $var);
}
}
//restoreto
- require_variable($restore_restoreto);
+ $restore_restoreto = required_param('restore_restoreto');
//restore_metacourse
- require_variable($restore_metacourse);
+ $restore_metacourse = required_param('restore_metacourse');
//restore_users
- require_variable($restore_users);
+ $restore_users = required_param('restore_users');
//restore_logs
- require_variable($restore_logs);
+ $restore_logs = required_param('restore_logs');
//restore_user_files
- require_variable($restore_user_files);
+ $restore_user_files = required_param('restore_user_files');
//restore_course_files
- require_variable($restore_course_files);
+ $restore_course_files = required_param('restore_course_files');
//restore_messages
- require_variable($restore_messages);
+ $restore_messages = required_param('restore_messages');
//Check we've selected a course
if (!isset($course_id)) {
View
16 backup/restore_form.html
@@ -5,18 +5,18 @@
//capabilities.
//Get objects from session
- $info = $SESSION->info;
- $course_header = $SESSION->course_header;
+ if (!($info = $SESSION->info)) {
+ error( 'info object missing from session' );
+ }
+ if (!($course_header = $SESSION->course_header)) {
+ error( 'course_header object missing from session' );
+ }
//Check that we have all we need
//backup_unique_code
- require_variable($backup_unique_code);
+ $backup_unique_code = required_param( 'backup_unique_code' );
//file
- require_variable($file);
- //info
- require_variable($info);
- //course_header
- require_variable($course_header);
+ $file = required_param( 'file' );
//Check login
require_login();

0 comments on commit 2fbfbcd

Please sign in to comment.