From 1b502431a8202218b5ea7c8b9788e6947a0a1ac0 Mon Sep 17 00:00:00 2001 From: stronk7 Date: Sun, 4 May 2003 01:10:20 +0000 Subject: [PATCH] Commented the "needed users" option (too complex for this initial release). Check all and course users. --- backup/backup.html | 4 +-- backup/check.html | 73 ++++++++++++++++++++------------------ backup/db/backup_mysql.php | 2 +- backup/lib.php | 47 ++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 38 deletions(-) diff --git a/backup/backup.html b/backup/backup.html index d525891971..7996fdb00a 100644 --- a/backup/backup.html +++ b/backup/backup.html @@ -34,7 +34,7 @@ //Check other parameters if (!isset($backup_users)) { - $backup_users = 2; + $backup_users = 1; } if (!isset($backup_logs)) { @@ -91,7 +91,7 @@ echo ""; $user_options[0] = get_string("all"); $user_options[1] = get_string("course"); - $user_options[2] = get_string("needed"); + //$user_options[2] = get_string("needed");-->NOT IMPLEMENTED choose_from_menu($user_options, "backup_users", $backup_users, ""); echo ""; diff --git a/backup/check.html b/backup/check.html index 3789623263..f1e4ea9ea6 100644 --- a/backup/check.html +++ b/backup/check.html @@ -34,7 +34,7 @@ //Check other parameters if (!isset($backup_users)) { - $backup_users = 2; + $backup_users = 1; } if (!isset($backup_logs)) { @@ -136,44 +136,47 @@ //Now print the Users tr echo ""; - echo "

"; - echo get_string("users").":"; - echo ""; - $user_options[0] = get_string("all"); - $user_options[1] = get_string("course"); - $user_options[2] = get_string("needed"); - choose_from_menu($user_options, "backup_users", $backup_users, ""); + echo "

"; + $user_options[0] = get_string("includeallusers"); + $user_options[1] = get_string("includecourseusers"); + ///$user_options[2] = get_string("includeneededusers");--->NOT IMPLEMENTED + echo "

  • ".$user_options[$backup_users]."

    "; + //Add as hidden name + echo ""; + //Print info + $table->data = user_check_backup($id,$backup_unique_code,$backup_users); + print_table($table); echo ""; - //Now print the Logs tr - echo ""; - echo "

    "; - echo get_string("logs").":"; - echo ""; - $log_options[0] = get_string("no"); - $log_options[1] = get_string("yes"); - choose_from_menu($log_options, "backup_logs", $backup_logs, ""); - echo ""; + //Now print the Logs tr conditionally + if ($backup_logs) { + echo ""; + echo "

    "; + echo "

  • ".get_string("includelogentries");; + echo ""; + } + //Add as hidden name + echo ""; - //Now print the User Files tr - echo ""; - echo "

    "; - echo get_string ("userfiles").":"; - echo ""; - $user_file_options[0] = get_string("no"); - $user_file_options[1] = get_string("yes"); - choose_from_menu($user_file_options, "backup_user_files", $backup_user_files, ""); - echo ""; + //Now print the User Files tr conditionally + if ($backup_user_files) { + echo ""; + echo "

    "; + echo "

  • ".get_string("includeuserfiles");; + echo ""; + } + //Add as hidden name + echo ""; - //Now print the Course Files tr - echo ""; - echo "

    "; - echo get_string ("coursefiles").":"; - echo ""; - $course_file_options[0] = get_string("no"); - $course_file_options[1] = get_string("yes"); - choose_from_menu($course_file_options, "backup_course_files", $backup_course_files, ""); - echo ""; + //Now print the Course Files tr conditionally + if ($backup_course_files) { + echo ""; + echo "

    "; + echo "

  • ".get_string("includecoursefiles");; + echo ""; + } + //Add as hidden name + echo ""; } ?> diff --git a/backup/db/backup_mysql.php b/backup/db/backup_mysql.php index 1b332cbf54..69d29b1dbf 100644 --- a/backup/db/backup_mysql.php +++ b/backup/db/backup_mysql.php @@ -37,7 +37,7 @@ function backup_upgrade($oldversion=0) { if ($oldversion < 2003050301 and $result) { $result = execute_sql("ALTER TABLE `{$CFG->prefix}backup_ids` - ADD `time` INT(10) UNSIGNED"); + ADD `info` VARCHAR(30)"); } diff --git a/backup/lib.php b/backup/lib.php index f07ac6db9b..22250ce42a 100644 --- a/backup/lib.php +++ b/backup/lib.php @@ -27,5 +27,52 @@ WHERE backup_code = '$backup_unique_code'",false); return $status; } + + //Calculate the number of users to backup and put their ids in backup_ids + //Return an array of info (name,value) + function user_check_backup($course,$backup_unique_code,$backup_users) { + //$backup_users=0-->all + // 1-->course + // 2-->needed-->NOT IMPLEMEMTED + + global $CFG; + + if ($backup_users == 0) { + //Insert all users (from user) + $sql_insert = "INSERT INTO {$CFG->prefix}backup_ids + (backup_code, table_name, old_id) + SELECT DISTINCT '$backup_unique_code','user',u.id + FROM {$CFG->prefix}user u"; + } else { + //Insert only course users (from user_students and user_teachers) + $sql_insert = "INSERT INTO {$CFG->prefix}backup_ids + (backup_code, table_name, old_id) + SELECT DISTINCT '$backup_unique_code','user',u.id + FROM {$CFG->prefix}user u, + {$CFG->prefix}user_students s, + {$CFG->prefix}user_teachers t + WHERE s.course = '$course' AND + t.course = s.course AND + (s.userid = u.id OR t.userid = u.id)"; + } + //Execute the insert + $status = execute_sql($sql_insert,false); + + //Now execute the select + $ids = get_records_sql("SELECT DISTINCT u.old_id,u.table_name + FROM {$CFG->prefix}backup_ids u + WHERE backup_code = '$backup_unique_code' AND + table_name ='user'"); + + //Gets the user data + $info[0][0] = get_string("users"); + if ($ids) { + $info[0][1] = count($ids); + } else { + $info[0][1] = 0; + } + + return $info; + } ?> -- 2.39.5