diff --git a/admin/admin.php b/admin/admin.php index 84c2c5aab5d..106ff89f9ff 100644 --- a/admin/admin.php +++ b/admin/admin.php @@ -67,7 +67,7 @@ } } - $admin->user = $user->id; + $admin->userid = $user->id; $admin->id = insert_record("user_admins", $admin); $admins[] = $user; } diff --git a/admin/user.php b/admin/user.php index e8f1fbe384f..4749cd64f59 100644 --- a/admin/user.php +++ b/admin/user.php @@ -28,7 +28,7 @@ error("SERIOUS ERROR: Could not create admin user record !!!"); } - $admin->user = $user->id; + $admin->userid = $user->id; if (! insert_record("user_admins", $admin)) { error("Could not make user $user->id an admin !!!"); @@ -42,7 +42,7 @@ error("Could not find site-level course"); } - $teacher->user = $user->id; + $teacher->userid = $user->id; $teacher->course = $site->id; $teacher->authority = 1; if (! insert_record("user_teachers", $teacher)) { diff --git a/course/lib.php b/course/lib.php index 6611986f596..c6c10356610 100644 --- a/course/lib.php +++ b/course/lib.php @@ -106,10 +106,10 @@ function print_log($course, $user=0, $date=0, $order="ORDER BY l.time ASC") { // and so the next 86400 seconds worth of logs are printed. if ($course->category) { - $selector = "WHERE l.course='$course->id' AND l.user = u.id"; + $selector = "WHERE l.course='$course->id' AND l.userid = u.id"; } else { - $selector = "WHERE l.user = u.id"; // Show all courses + $selector = "WHERE l.userid = u.id"; // Show all courses if ($ccc = get_courses(-1)) { foreach ($ccc as $cc) { $courses[$cc->id] = "$cc->shortname"; @@ -118,7 +118,7 @@ function print_log($course, $user=0, $date=0, $order="ORDER BY l.time ASC") { } if ($user) { - $selector .= " AND l.user = '$user'"; + $selector .= " AND l.userid = '$user'"; } if ($date) { @@ -152,9 +152,9 @@ function print_log($course, $user=0, $date=0, $order="ORDER BY l.time ASC") { echo "
Error: Could not insert a new entry to the Moodle log
"; // Don't throw an error } @@ -850,7 +862,7 @@ function get_logs_usercourse($userid, $courseid, $coursestart) { return get_records_sql("SELECT floor((`time` - $coursestart)/86400) as day, count(*) as num FROM {$CFG->prefix}log - WHERE user = '$userid' + WHERE userid = '$userid' AND course = '$courseid' AND `time` > '$coursestart' GROUP BY day "); @@ -861,7 +873,7 @@ function get_logs_userday($userid, $courseid, $daystart) { return get_records_sql("SELECT floor((`time` - $daystart)/3600) as hour, count(*) as num FROM {$CFG->prefix}log - WHERE user = '$userid' + WHERE userid = '$userid' AND course = '$courseid' AND `time` > '$daystart' GROUP BY hour "); diff --git a/lib/db/mysql.php b/lib/db/mysql.php index edfa29e8146..da38bbf4144 100644 --- a/lib/db/mysql.php +++ b/lib/db/mysql.php @@ -216,6 +216,15 @@ function main_upgrade($oldversion=0) { set_config("guestloginbutton", 1); } + if ($oldversion < 2002122300) { + execute_sql("ALTER TABLE `log` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL "); + execute_sql("ALTER TABLE `user_admins` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL "); + execute_sql("ALTER TABLE `user_students` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL "); + execute_sql("ALTER TABLE `user_teachers` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL "); + execute_sql("ALTER TABLE `user_students` CHANGE `start` `timestart` INT(10) UNSIGNED DEFAULT '0' NOT NULL "); + execute_sql("ALTER TABLE `user_students` CHANGE `end` `timeend` INT(10) UNSIGNED DEFAULT '0' NOT NULL "); + } + return true; } diff --git a/lib/db/mysql.sql b/lib/db/mysql.sql index f2e134fd5d6..77cca11f5d0 100644 --- a/lib/db/mysql.sql +++ b/lib/db/mysql.sql @@ -103,7 +103,7 @@ CREATE TABLE `prefix_course_sections` ( CREATE TABLE `prefix_log` ( `id` int(10) unsigned NOT NULL auto_increment, `time` int(10) unsigned NOT NULL default '0', - `user` int(10) unsigned NOT NULL default '0', + `userid` int(10) unsigned NOT NULL default '0', `ip` varchar(15) NOT NULL default '', `course` int(10) unsigned NOT NULL default '0', `module` varchar(10) NOT NULL default '', @@ -191,7 +191,7 @@ CREATE TABLE `prefix_user` ( CREATE TABLE `prefix_user_admins` ( `id` int(10) unsigned NOT NULL auto_increment, - `user` int(10) unsigned NOT NULL default '0', + `userid` int(10) unsigned NOT NULL default '0', PRIMARY KEY (`id`), UNIQUE KEY `id` (`id`) ) TYPE=MyISAM COMMENT='One record per administrator user'; @@ -203,10 +203,10 @@ CREATE TABLE `prefix_user_admins` ( CREATE TABLE `prefix_user_students` ( `id` int(10) unsigned NOT NULL auto_increment, - `user` int(10) unsigned NOT NULL default '0', + `userid` int(10) unsigned NOT NULL default '0', `course` int(10) unsigned NOT NULL default '0', - `start` int(10) unsigned NOT NULL default '0', - `end` int(10) unsigned NOT NULL default '0', + `timestart` int(10) unsigned NOT NULL default '0', + `timeend` int(10) unsigned NOT NULL default '0', `time` int(10) unsigned NOT NULL default '0', PRIMARY KEY (`id`), UNIQUE KEY `id` (`id`) @@ -219,7 +219,7 @@ CREATE TABLE `prefix_user_students` ( CREATE TABLE `prefix_user_teachers` ( `id` int(10) unsigned NOT NULL auto_increment, - `user` int(10) unsigned NOT NULL default '0', + `userid` int(10) unsigned NOT NULL default '0', `course` int(10) unsigned NOT NULL default '0', `authority` int(10) NOT NULL default '3', `role` varchar(40) NOT NULL default '', diff --git a/lib/db/postgres7.sql b/lib/db/postgres7.sql index ccf458feb1b..39eb39fde0b 100644 --- a/lib/db/postgres7.sql +++ b/lib/db/postgres7.sql @@ -54,7 +54,7 @@ CREATE TABLE course_sections ( CREATE TABLE log ( id SERIAL PRIMARY KEY, time integer NOT NULL default '0', - "user" integer NOT NULL default '0', + userid integer NOT NULL default '0', ip varchar(15) NOT NULL default '', course integer NOT NULL default '0', module varchar(10) NOT NULL default '', @@ -115,21 +115,21 @@ CREATE TABLE "user" ( CREATE TABLE user_admins ( id SERIAL PRIMARY KEY, - "user" integer NOT NULL default '0' + userid integer NOT NULL default '0' ); CREATE TABLE user_students ( id SERIAL PRIMARY KEY, - "user" integer NOT NULL default '0', + userid integer NOT NULL default '0', course integer NOT NULL default '0', - "start" integer NOT NULL default '0', - "end" integer NOT NULL default '0', + timestart integer NOT NULL default '0', + timeend integer NOT NULL default '0', time integer NOT NULL default '0' ); CREATE TABLE user_teachers ( id SERIAL PRIMARY KEY, - "user" integer NOT NULL default '0', + userid integer NOT NULL default '0', course integer NOT NULL default '0', authority integer NOT NULL default '3', role varchar(40) NOT NULL default '' diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 462b694eb9f..ac56f575f37 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -358,10 +358,10 @@ function isadmin($userid=0) { global $USER; if (!$userid) { - return record_exists("user_admins", "user", $USER->id); + return record_exists("user_admins", "userid", $USER->id); } - return record_exists("user_admins", "user", $userid); + return record_exists("user_admins", "userid", $userid); } @@ -377,7 +377,7 @@ function isteacher($courseid, $userid=0) { return $USER->teacher[$courseid]; } - return record_exists("user_teachers", "user", $userid, "course", $courseid); + return record_exists("user_teachers", "userid", $userid, "course", $courseid); } @@ -389,9 +389,9 @@ function isstudent($courseid, $userid=0) { return $USER->student[$courseid]; } - $timenow = time(); // todo: add time check below + // $timenow = time(); // todo: add time check below - return record_exists("user_students", "user", $userid, "course", $courseid); + return record_exists("user_students", "userid", $userid, "course", $courseid); } function isguest($userid=0) { @@ -519,13 +519,13 @@ function enrol_student($user, $course) { /// Enrols a student in a given course global $db; - $record->user = $user; + $record->userid = $user; $record->course = $course; $record->start = 0; $record->end = 0; $record->time = time(); - return insert_record("user", $record); + return insert_record("user_students", $record); } function unenrol_student($user, $course=0) { @@ -536,14 +536,14 @@ function unenrol_student($user, $course=0) { /// First delete any crucial stuff that might still send mail if ($forums = get_records("forum", "course", $course)) { foreach ($forums as $forum) { - delete_records("forum_subscriptions", "forum", $forum->id, "user", $user); + delete_records("forum_subscriptions", "forum", $forum->id, "userid", $user); } } - return delete_records("user_students", "user", $user, "course", $course); + return delete_records("user_students", "userid", $user, "course", $course); } else { - delete_records("forum_subscriptions", "user", $user); - return delete_records("user_students", "user", $user); + delete_records("forum_subscriptions", "userid", $user); + return delete_records("user_students", "userid", $user); } } @@ -556,13 +556,13 @@ function remove_teacher($user, $course=0) { /// First delete any crucial stuff that might still send mail if ($forums = get_records("forum", "course", $course)) { foreach ($forums as $forum) { - delete_records("forum_subscriptions", "forum", $forum->id, "user", $user); + delete_records("forum_subscriptions", "forum", $forum->id, "userid", $user); } } - return delete_records("user_teachers", "user", $user, "course", $course); + return delete_records("user_teachers", "userid", $user, "course", $course); } else { - delete_records("forum_subscriptions", "user", $user); - return delete_records("user_teachers", "user", $user); + delete_records("forum_subscriptions", "userid", $user); + return delete_records("user_teachers", "userid", $user); } } @@ -570,7 +570,7 @@ function remove_admin($user) { /// Removes an admin from a site global $db; - return delete_records("user_admins", "user", $user); + return delete_records("user_admins", "userid", $user); } diff --git a/mod/assignment/db/mysql.php b/mod/assignment/db/mysql.php index 5a5a6bda556..222764950a5 100644 --- a/mod/assignment/db/mysql.php +++ b/mod/assignment/db/mysql.php @@ -88,6 +88,9 @@ function assignment_upgrade($oldversion) { if ($oldversion < 2002111500) { execute_sql(" ALTER TABLE `assignment` ADD `resubmit` TINYINT(2) UNSIGNED DEFAULT '0' NOT NULL AFTER `format` "); } + if ($oldversion < 2002122300) { + execute_sql("ALTER TABLE `assignment_submissions` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL "); + } return true; } diff --git a/mod/assignment/db/mysql.sql b/mod/assignment/db/mysql.sql index 3c6f06f2fb4..c4f431cf613 100644 --- a/mod/assignment/db/mysql.sql +++ b/mod/assignment/db/mysql.sql @@ -25,7 +25,7 @@ CREATE TABLE `prefix_assignment` ( CREATE TABLE `prefix_assignment_submissions` ( `id` int(10) unsigned NOT NULL auto_increment, `assignment` int(10) unsigned NOT NULL default '0', - `user` int(10) unsigned NOT NULL default '0', + `userid` int(10) unsigned NOT NULL default '0', `timecreated` int(10) unsigned NOT NULL default '0', `timemodified` int(10) unsigned NOT NULL default '0', `numfiles` int(10) unsigned NOT NULL default '0', diff --git a/mod/assignment/db/postgres7.sql b/mod/assignment/db/postgres7.sql index 710caa71830..1348a7fe7db 100644 --- a/mod/assignment/db/postgres7.sql +++ b/mod/assignment/db/postgres7.sql @@ -23,7 +23,7 @@ CREATE TABLE assignment ( CREATE TABLE assignment_submissions ( id SERIAL PRIMARY KEY, assignment integer NOT NULL default '0', - "user" integer NOT NULL default '0', + userid integer NOT NULL default '0', timecreated integer NOT NULL default '0', timemodified integer NOT NULL default '0', numfiles integer NOT NULL default '0', diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php index 4aac51e0949..ce180627801 100644 --- a/mod/assignment/lib.php +++ b/mod/assignment/lib.php @@ -119,8 +119,8 @@ function assignment_cron () { echo "Processing assignment submission $submission->id\n"; - if (! $user = get_record("user", "id", "$submission->user")) { - echo "Could not find user $post->user\n"; + if (! $user = get_record("user", "id", "$submission->userid")) { + echo "Could not find user $post->userid\n"; continue; } @@ -215,7 +215,7 @@ function assignment_grades($assignmentid) { /// Must return an array of grades, indexed by user, and a max grade. $return->grades = get_records_menu("assignment_submissions", "assignment", - $assignmentid, "", "user,grade"); + $assignmentid, "", "userid,grade"); $return->maxgrade = get_field("assignment", "grade", "id", "$assignmentid"); return $return; } @@ -228,7 +228,7 @@ function assignment_log_info($log) { FROM {$CFG->prefix}assignment a, {$CFG->prefix}user u WHERE a.id = '$log->info' - AND u.id = '$log->user'"); + AND u.id = '$log->userid'"); } function assignment_get_all_submissions($assignment) { @@ -237,7 +237,7 @@ function assignment_get_all_submissions($assignment) { return get_records_sql("SELECT a.* FROM {$CFG->prefix}assignment_submissions a, {$CFG->prefix}user_students s - WHERE a.user = s.user + WHERE a.userid = s.userid AND s.course = '$assignment->course' AND a.assignment = '$assignment->id' ORDER BY a.timemodified DESC"); @@ -251,8 +251,8 @@ function assignment_get_users_done($assignment) { {$CFG->prefix}user_students s, {$CFG->prefix}assignment_submissions a WHERE s.course = '$assignment->course' - AND s.user = u.id - AND u.id = a.user + AND s.userid = u.id + AND u.id = a.userid AND a.assignment = '$assignment->id' ORDER BY a.timemodified DESC"); } @@ -284,7 +284,7 @@ function assignment_file_area($assignment, $user) { } function assignment_get_submission($assignment, $user) { - return get_record("assignment_submissions", "assignment", $assignment->id, "user", $user->id); + return get_record("assignment_submissions", "assignment", $assignment->id, "userid", $user->id); } function assignment_print_difference($time) { diff --git a/mod/assignment/submissions.php b/mod/assignment/submissions.php index faabd55505e..42f0be30e8e 100644 --- a/mod/assignment/submissions.php +++ b/mod/assignment/submissions.php @@ -48,7 +48,7 @@ /// Make some easy ways to reference submissions if ($submissions = assignment_get_all_submissions($assignment)) { foreach ($submissions as $submission) { - $submissionbyuser[$submission->user] = $submission; + $submissionbyuser[$submission->userid] = $submission; } } @@ -56,7 +56,7 @@ foreach($users as $user) { if (!isset($submissionbyuser[$user->id])) { // Need to create empty entry $newsubmission->assignment = $assignment->id; - $newsubmission->user = $user->id; + $newsubmission->userid = $user->id; $newsubmission->timecreated = time(); if (!insert_record("assignment_submissions", $newsubmission)) { error("Could not insert a new empty submission"); @@ -97,7 +97,7 @@ $newsubmission->mailed = 0; // Make sure mail goes out (again, even) $newsubmission->id = $num; if (! update_record("assignment_submissions", $newsubmission)) { - notify(get_string("failedupdatefeedback", "assignment", $submission->user)); + notify(get_string("failedupdatefeedback", "assignment", $submission->userid)); } else { $count++; } @@ -117,7 +117,7 @@ echo "