From: moodler Date: Mon, 23 Dec 2002 09:39:26 +0000 (+0000) Subject: Changes throughout Moodle to remove any reserved words from the X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=ebc3bd2b2489a19f4b88bd331c366c596d9df6cd;p=moodle.git Changes throughout Moodle to remove any reserved words from the Moodle tables. ie user -> userid in many tables, plus in user_students start -> starttime and end -> endtime I've just done all this as carefully as I could ... I don't think I missed anything but it's pretty intensive work and I'd be fooling myself if I didn't think I'd missed a couple. Note that this version should pretty much be able to bootstrap itself using PostgreSQL now ... but this is untested --- diff --git a/admin/admin.php b/admin/admin.php index 84c2c5aab5..106ff89f9f 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 e8f1fbe384..4749cd64f5 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 6611986f59..c6c1035661 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 "".userdate($log->time, "%A").""; echo "".userdate($log->time, "%d %B %Y, %I:%M %p").""; echo ""; - link_to_popup_window("$CFG->wwwroot/lib/ipatlas/plot.php?address=$log->ip&user=$log->user", "ipatlas","$log->ip", 400, 700); + link_to_popup_window("$CFG->wwwroot/lib/ipatlas/plot.php?address=$log->ip&user=$log->userid", "ipatlas","$log->ip", 400, 700); echo ""; - echo "user&course=$log->course\">$log->firstname $log->lastname"; + echo "userid&course=$log->course\">$log->firstname $log->lastname"; echo ""; link_to_popup_window( make_log_url($log->module,$log->url), "fromloglive","$log->module $log->action", 400, 600); echo ""; diff --git a/course/teacher.php b/course/teacher.php index 4764e965e5..bfd220a551 100644 --- a/course/teacher.php +++ b/course/teacher.php @@ -79,7 +79,7 @@ } } - $teacher->user = $user->id; + $teacher->userid = $user->id; $teacher->course = $course->id; if ($teachers) { $teacher->authority = 2; diff --git a/course/teachers.php b/course/teachers.php index fcf6275ba8..b16b55d88c 100644 --- a/course/teachers.php +++ b/course/teachers.php @@ -33,7 +33,7 @@ } foreach ($rank as $num => $vals) { - if (! $teacher = get_record("user_teachers", "course", "$course->id", "user", "$num")) { + if (! $teacher = get_record("user_teachers", "course", "$course->id", "userid", "$num")) { error("No such teacher in course $course->shortname with user id $num"); } $teacher->role = $vals[r]; diff --git a/lib/datalib.php b/lib/datalib.php index aed6ec1480..c92ea328d9 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -433,6 +433,8 @@ function insert_record($table, $dataobject, $returnid=true) { function update_record($table, $dataobject) { /// Update a record in a table /// $dataobject is an object containing needed data +/// Relies on $dataobject having a variable "id" to +/// specify the record to update global $db, $CFG; @@ -505,21 +507,21 @@ function get_user_info_from_db($field, $value) { if ( $result->RecordCount() == 1 ) { $user = (object)$result->fields; - $rs = $db->Execute("SELECT course FROM {$CFG->prefix}user_students WHERE user = '$user->id' "); + $rs = $db->Execute("SELECT course FROM {$CFG->prefix}user_students WHERE userid = '$user->id' "); while (!$rs->EOF) { $course = $rs->fields["course"]; $user->student["$course"] = true; $rs->MoveNext(); } - $rs = $db->Execute("SELECT course FROM {$CFG->prefix}user_teachers WHERE user = '$user->id' "); + $rs = $db->Execute("SELECT course FROM {$CFG->prefix}user_teachers WHERE userid = '$user->id' "); while (!$rs->EOF) { $course = $rs->fields["course"]; $user->teacher["$course"] = true; $rs->MoveNext(); } - $rs = $db->Execute("SELECT * FROM {$CFG->prefix}user_admins WHERE user = '$user->id' "); + $rs = $db->Execute("SELECT * FROM {$CFG->prefix}user_admins WHERE userid = '$user->id' "); while (!$rs->EOF) { $user->admin = true; $rs->MoveNext(); @@ -563,7 +565,7 @@ function adminlogin($username, $md5password) { return record_exists_sql("SELECT u.id FROM {$CFG->prefix}user u, {$CFG->prefix}user_admins a - WHERE u.id = a.user + WHERE u.id = a.userid AND u.username = '$username' AND u.password = '$md5password'"); } @@ -623,9 +625,11 @@ function get_admins() { global $CFG; - return get_records_sql("SELECT u.* FROM {$CFG->prefix}user u, {$CFG->prefix}user_admins a - WHERE a.user = u.id - ORDER BY u.id ASC"); + return get_records_sql("SELECT u.* + FROM {$CFG->prefix}user u, + {$CFG->prefix}user_admins a + WHERE a.userid = u.id + ORDER BY u.id ASC"); } @@ -651,7 +655,7 @@ function get_course_students($courseid, $sort="u.lastaccess DESC") { global $CFG; return get_records_sql("SELECT u.* FROM {$CFG->prefix}user u, {$CFG->prefix}user_students s - WHERE s.course = '$courseid' AND s.user = u.id AND u.deleted = '0' + WHERE s.course = '$courseid' AND s.userid = u.id AND u.deleted = '0' ORDER BY $sort"); } @@ -661,7 +665,7 @@ function get_course_teachers($courseid, $sort="t.authority ASC") { global $CFG; return get_records_sql("SELECT u.*,t.authority,t.role FROM {$CFG->prefix}user u, {$CFG->prefix}user_teachers t - WHERE t.course = '$courseid' AND t.user = u.id AND u.deleted = '0' + WHERE t.course = '$courseid' AND t.userid = u.id AND u.deleted = '0' ORDER BY $sort"); } @@ -680,8 +684,8 @@ function get_course_users($courseid, $sort="u.lastaccess DESC") { } /// return get_records_sql("SELECT u.* FROM user u, user_students s, user_teachers t -/// WHERE (s.course = '$courseid' AND s.user = u.id) OR -/// (t.course = '$courseid' AND t.user = u.id) +/// WHERE (s.course = '$courseid' AND s.userid = u.id) OR +/// (t.course = '$courseid' AND t.userid = u.id) /// ORDER BY $sort"); } @@ -743,7 +747,7 @@ function get_users_longtimenosee($cutofftime) { {$CFG->prefix}user_students s WHERE lastaccess > '0' AND lastaccess < '$cutofftime' - AND u.id = s.user + AND u.id = s.userid GROUP BY u.id"); } @@ -821,15 +825,23 @@ function add_to_log($course, $module, $action, $url="", $info="") { $timenow = time(); $info = addslashes($info); - $result = $db->Execute("INSERT INTO log - SET time = '$timenow', - user = '$USER->id', - course = '$course', - ip = '$REMOTE_ADDR', - module = '$module', - action = '$action', - url = '$url', - info = '$info'"); + $result = $db->Execute("INSERT INTO log (time, + userid, + course, + ip, + module, + action, + url, + info) + VALUES ('$timenow', + '$USER->id', + '$course', + '$REMOTE_ADDR', + '$module', + '$action', + '$url', + '$info')"); + if (!$result) { 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 edfa29e814..da38bbf414 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 f2e134fd5d..77cca11f5d 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 ccf458feb1..39eb39fde0 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 462b694eb9..ac56f575f3 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 5a5a6bda55..222764950a 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 3c6f06f2fb..c4f431cf61 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 710caa7183..1348a7fe7d 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 4aac51e094..ce18062780 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 faabd55505..42f0be30e8 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 "
\n"; foreach ($submissions as $submission) { - $user = $users[$submission->user]; + $user = $users[$submission->userid]; assignment_print_submission($assignment, $user, $submission, $teachers, $grades); } diff --git a/mod/assignment/upload.php b/mod/assignment/upload.php index b1dbc04a72..9b48d8e241 100644 --- a/mod/assignment/upload.php +++ b/mod/assignment/upload.php @@ -59,7 +59,7 @@ } } else { $newsubmission->assignment = $assignment->id; - $newsubmission->user = $USER->id; + $newsubmission->userid = $USER->id; $newsubmission->timecreated = time(); $newsubmission->timemodified = time(); $newsubmission->numfiles = 1; diff --git a/mod/assignment/version.php b/mod/assignment/version.php index 114d6377a8..303c372616 100644 --- a/mod/assignment/version.php +++ b/mod/assignment/version.php @@ -5,7 +5,7 @@ // This fragment is called by /admin/index.php //////////////////////////////////////////////////////////////////////////////// -$module->version = 2002111500; +$module->version = 2002122300; $module->cron = 60; ?> diff --git a/mod/choice/db/mysql.php b/mod/choice/db/mysql.php index 47c741f552..28c490b6c3 100644 --- a/mod/choice/db/mysql.php +++ b/mod/choice/db/mysql.php @@ -14,6 +14,9 @@ function choice_upgrade($oldversion) { execute_sql(" ALTER TABLE `choice` ADD `answer5` varchar(255) NOT NULL AFTER `answer4`"); execute_sql(" ALTER TABLE `choice` ADD `answer6` varchar(255) NOT NULL AFTER `answer5`"); } + if ($oldversion < 2002122300) { + execute_sql("ALTER TABLE `choice_answers` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL "); + } return true; } diff --git a/mod/choice/db/mysql.sql b/mod/choice/db/mysql.sql index aad4042c01..8184886ee7 100755 --- a/mod/choice/db/mysql.sql +++ b/mod/choice/db/mysql.sql @@ -40,7 +40,7 @@ CREATE TABLE prefix_choice ( CREATE TABLE prefix_choice_answers ( id int(10) unsigned NOT NULL auto_increment, choice int(10) unsigned NOT NULL default '0', - user int(10) unsigned NOT NULL default '0', + userid int(10) unsigned NOT NULL default '0', answer tinyint(4) NOT NULL default '0', timemodified int(10) NOT NULL default '0', PRIMARY KEY (id), diff --git a/mod/choice/db/postgres7.php b/mod/choice/db/postgres7.php index 47c741f552..830a3b20a8 100644 --- a/mod/choice/db/postgres7.php +++ b/mod/choice/db/postgres7.php @@ -4,16 +4,6 @@ function choice_upgrade($oldversion) { // This function does anything necessary to upgrade // older versions to match current functionality - if ($oldversion < 2002090800) { - execute_sql(" ALTER TABLE `choice` CHANGE `answer1` `answer1` VARCHAR( 255 )"); - execute_sql(" ALTER TABLE `choice` CHANGE `answer2` `answer2` VARCHAR( 255 )"); - } - if ($oldversion < 2002102400) { - execute_sql(" ALTER TABLE `choice` ADD `answer3` varchar(255) NOT NULL AFTER `answer2`"); - execute_sql(" ALTER TABLE `choice` ADD `answer4` varchar(255) NOT NULL AFTER `answer3`"); - execute_sql(" ALTER TABLE `choice` ADD `answer5` varchar(255) NOT NULL AFTER `answer4`"); - execute_sql(" ALTER TABLE `choice` ADD `answer6` varchar(255) NOT NULL AFTER `answer5`"); - } return true; } diff --git a/mod/choice/db/postgres7.sql b/mod/choice/db/postgres7.sql index e93c1e36e1..e1dbe97ea1 100755 --- a/mod/choice/db/postgres7.sql +++ b/mod/choice/db/postgres7.sql @@ -38,7 +38,7 @@ CREATE TABLE choice ( CREATE TABLE choice_answers ( id SERIAL PRIMARY KEY, choice integer NOT NULL default '0', - "user" integer NOT NULL default '0', + userid integer NOT NULL default '0', answer integer NOT NULL default '0', timemodified integer NOT NULL default '0' ); diff --git a/mod/choice/index.php b/mod/choice/index.php index cd80379622..c28fe4709b 100644 --- a/mod/choice/index.php +++ b/mod/choice/index.php @@ -28,7 +28,7 @@ notice("There are no choices", "../../course/view.php?id=$course->id"); } - if ( $allanswers = get_records("choice_answers", "user", $USER->id)) { + if ( $allanswers = get_records("choice_answers", "userid", $USER->id)) { foreach ($allanswers as $aa) { $answers[$aa->choice] = $aa; } diff --git a/mod/choice/lib.php b/mod/choice/lib.php index f0c35817ac..eb8ce90e1f 100644 --- a/mod/choice/lib.php +++ b/mod/choice/lib.php @@ -3,7 +3,7 @@ $CHOICE_MAX_NUMBER = 6; function choice_user_outline($course, $user, $mod, $choice) { - if ($current = get_record("choice_answers", "choice", $choice->id, "user", $user->id)) { + if ($current = get_record("choice_answers", "choice", $choice->id, "userid", $user->id)) { $result->info = "'".choice_get_answer($choice, $current->answer)."'"; $result->time = $current->timemodified; return $result; @@ -13,7 +13,7 @@ function choice_user_outline($course, $user, $mod, $choice) { function choice_user_complete($course, $user, $mod, $choice) { - if ($current = get_record("choice_answers", "choice", $choice->id, "user", $user->id)) { + if ($current = get_record("choice_answers", "choice", $choice->id, "userid", $user->id)) { $result->info = "'".choice_get_answer($choice, $current->answer)."'"; $result->time = $current->timemodified; echo get_string("answered", "choice").": $result->info , last updated ".userdate($result->time); diff --git a/mod/choice/report.php b/mod/choice/report.php index 39c4b7aa23..df27b580c6 100644 --- a/mod/choice/report.php +++ b/mod/choice/report.php @@ -41,7 +41,7 @@ if ( $allanswers = get_records("choice_answers", "choice", $choice->id)) { foreach ($allanswers as $aa) { - $answers[$aa->user] = $aa; + $answers[$aa->userid] = $aa; } } else { $answers = array () ; diff --git a/mod/choice/version.php b/mod/choice/version.php index 1254eb5efc..a843367188 100644 --- a/mod/choice/version.php +++ b/mod/choice/version.php @@ -5,7 +5,7 @@ // This fragment is called by /admin/index.php //////////////////////////////////////////////////////////////////////////////// -$module->version = 2002102400; +$module->version = 2002122300; $module->cron = 0; ?> diff --git a/mod/choice/view.php b/mod/choice/view.php index cb4fdb6700..22f7190dad 100644 --- a/mod/choice/view.php +++ b/mod/choice/view.php @@ -19,7 +19,7 @@ error("Course module is incorrect"); } - if ($current = get_record("choice_answers", "choice", $choice->id, "user", $USER->id)) { + if ($current = get_record("choice_answers", "choice", $choice->id, "userid", $USER->id)) { $answerchecked[$current->answer] = "CHECKED"; } @@ -36,7 +36,7 @@ add_to_log($course->id, "choice", "update", "view.php?id=$cm->id", "$choice->id"); } else { $newanswer->choice = $choice->id; - $newanswer->user = $USER->id; + $newanswer->userid = $USER->id; $newanswer->answer = $form->answer; $newanswer->timemodified = $timenow; if (! insert_record("choice_answers", $newanswer)) { diff --git a/mod/forum/db/mysql.php b/mod/forum/db/mysql.php index 58f758db21..4381eff1d6 100644 --- a/mod/forum/db/mysql.php +++ b/mod/forum/db/mysql.php @@ -50,6 +50,12 @@ function forum_upgrade($oldversion) { execute_sql(" ALTER TABLE `forum_posts` ADD `format` TINYINT(2) UNSIGNED DEFAULT '0' NOT NULL AFTER `message` "); } + if ($oldversion < 2002122300) { + execute_sql("ALTER TABLE `forum_posts` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL "); + execute_sql("ALTER TABLE `forum_ratings` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL "); + execute_sql("ALTER TABLE `forum_subscriptions` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL "); + } + return true; } diff --git a/mod/forum/db/mysql.sql b/mod/forum/db/mysql.sql index 04e4121a98..9131f4e813 100644 --- a/mod/forum/db/mysql.sql +++ b/mod/forum/db/mysql.sql @@ -41,7 +41,7 @@ CREATE TABLE prefix_forum_posts ( id int(10) unsigned NOT NULL auto_increment, discussion int(10) unsigned NOT NULL default '0', parent int(10) unsigned NOT NULL default '0', - user int(10) unsigned NOT NULL default '0', + userid int(10) unsigned NOT NULL default '0', created int(10) unsigned NOT NULL default '0', modified int(10) unsigned NOT NULL default '0', mailed tinyint(1) unsigned NOT NULL default '0', @@ -60,7 +60,7 @@ CREATE TABLE prefix_forum_posts ( CREATE TABLE prefix_forum_ratings ( id int(10) unsigned NOT NULL auto_increment, - user int(10) unsigned NOT NULL default '0', + userid int(10) unsigned NOT NULL default '0', post int(10) unsigned NOT NULL default '0', time int(10) unsigned NOT NULL default '0', rating tinyint(4) NOT NULL default '0', @@ -74,7 +74,7 @@ CREATE TABLE prefix_forum_ratings ( CREATE TABLE prefix_forum_subscriptions ( id int(10) unsigned NOT NULL auto_increment, - user int(10) unsigned NOT NULL default '0', + userid int(10) unsigned NOT NULL default '0', forum int(10) unsigned NOT NULL default '0', PRIMARY KEY (id), UNIQUE KEY id (id) diff --git a/mod/forum/db/postgres7.php b/mod/forum/db/postgres7.php index a5593235c6..eb40f2fa0e 100644 --- a/mod/forum/db/postgres7.php +++ b/mod/forum/db/postgres7.php @@ -4,51 +4,7 @@ function forum_upgrade($oldversion) { // This function does anything necessary to upgrade // older versions to match current functionality - if ($oldversion < 2002073008) { - execute_sql("DELETE FROM modules WHERE name = 'discuss' "); - execute_sql("ALTER TABLE `discuss` RENAME `forum_discussions` "); - execute_sql("ALTER TABLE `discuss_posts` RENAME `forum_posts` "); - execute_sql("ALTER TABLE `discuss_ratings` RENAME `forum_ratings` "); - execute_sql("ALTER TABLE `forum` CHANGE `intro` `intro` TEXT NOT NULL "); - execute_sql("ALTER TABLE `forum` ADD `forcesubscribe` INTEGER DEFAULT '0' NOT NULL AFTER `assessed`"); - execute_sql("ALTER TABLE `forum` CHANGE `type` `type` ENUM( 'single', 'news', 'social', 'general', - 'eachuser', 'teacher' ) DEFAULT 'general' NOT NULL "); - execute_sql("ALTER TABLE `forum_posts` CHANGE `discuss` `discussion` INT( 10 ) UNSIGNED DEFAULT '0' NOT NULL "); - execute_sql("INSERT INTO log_display VALUES ('forum', 'add', 'forum', 'name') "); - execute_sql("INSERT INTO log_display VALUES ('forum', 'add discussion', 'forum_discussions', 'name') "); - execute_sql("INSERT INTO log_display VALUES ('forum', 'add post', 'forum_posts', 'subject') "); - execute_sql("INSERT INTO log_display VALUES ('forum', 'update post', 'forum_posts', 'subject') "); - execute_sql("INSERT INTO log_display VALUES ('forum', 'view discussion', 'forum_discussions', 'name') "); - execute_sql("DELETE FROM log_display WHERE module = 'discuss' "); - execute_sql("UPDATE log SET action = 'view discussion' WHERE module = 'discuss' AND action = 'view' "); - execute_sql("UPDATE log SET action = 'add discussion' WHERE module = 'discuss' AND action = 'add' "); - execute_sql("UPDATE log SET module = 'forum' WHERE module = 'discuss' "); - notify("Renamed all the old discuss tables (now part of forum) and created new forum_types"); - } - - if ($oldversion < 2002080100) { - execute_sql("INSERT INTO log_display VALUES ('forum', 'view subscribers', 'forum', 'name') "); - execute_sql("INSERT INTO log_display VALUES ('forum', 'update', 'forum', 'name') "); - } - - if ($oldversion < 2002082900) { - execute_sql(" ALTER TABLE `forum_posts` ADD `attachment` VARCHAR(100) NOT NULL AFTER `message` "); - } - - if ($oldversion < 2002091000) { - if (! execute_sql(" ALTER TABLE `forum_posts` ADD `attachment` VARCHAR(100) NOT NULL AFTER `message` ")) { - echo "

Don't worry about this error - your server already had this upgrade applied"; - } - } - - if ($oldversion < 2002100300) { - execute_sql(" ALTER TABLE `forum` CHANGE `open` `open` INTEGER DEFAULT '2' NOT NULL "); - execute_sql(" UPDATE `forum` SET `open` = 2 WHERE `open` = 1 "); - execute_sql(" UPDATE `forum` SET `open` = 1 WHERE `open` = 0 "); - } - if ($oldversion < 2002101001) { - execute_sql(" ALTER TABLE `forum_posts` ADD `format` INTEGER DEFAULT '0' NOT NULL AFTER `message` "); - } + global $CFG; return true; diff --git a/mod/forum/db/postgres7.sql b/mod/forum/db/postgres7.sql index 92d85fc690..44031854cb 100644 --- a/mod/forum/db/postgres7.sql +++ b/mod/forum/db/postgres7.sql @@ -38,7 +38,7 @@ CREATE TABLE forum_posts ( id SERIAL PRIMARY KEY, discussion integer NOT NULL default '0', parent integer NOT NULL default '0', - "user" integer NOT NULL default '0', + userid integer NOT NULL default '0', created integer NOT NULL default '0', modified integer NOT NULL default '0', mailed integer NOT NULL default '0', @@ -56,7 +56,7 @@ CREATE TABLE forum_posts ( CREATE TABLE forum_ratings ( id SERIAL PRIMARY KEY, - "user" integer NOT NULL default '0', + userid integer NOT NULL default '0', post integer NOT NULL default '0', time integer NOT NULL default '0', rating integer NOT NULL default '0' @@ -69,7 +69,7 @@ CREATE TABLE forum_ratings ( CREATE TABLE forum_subscriptions ( id SERIAL PRIMARY KEY, - "user" integer NOT NULL default '0', + userid integer NOT NULL default '0', forum integer NOT NULL default '0' ); # -------------------------------------------------------- diff --git a/mod/forum/lib.php b/mod/forum/lib.php index dc9bf022c5..40271e4449 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -159,8 +159,8 @@ function forum_cron () { print_string("processingpost", "forum", $post->id); echo " ... "; - if (! $userfrom = get_record("user", "id", "$post->user")) { - echo "Could not find user $post->user\n"; + if (! $userfrom = get_record("user", "id", "$post->userid")) { + echo "Could not find user $post->userid\n"; continue; } @@ -349,7 +349,7 @@ function forum_grades($forumid) { } if ($ratings = forum_get_user_grades($forumid)) { foreach ($ratings as $rating) { - $u = $rating->user; + $u = $rating->userid; $r = $rating->rating; if (!isset($sumrating[$u])) { $sumrating[$u][1] = 0; @@ -376,34 +376,34 @@ function forum_get_post_full($postid) { /// Gets a post with all info ready for forum_print_post global $CFG; - return get_record_sql("SELECT p.*, u.firstname, u.lastname, u.email, u.picture, u.id as userid + return get_record_sql("SELECT p.*, u.firstname, u.lastname, u.email, u.picture FROM {$CFG->prefix}forum_posts p, {$CFG->prefix}user u WHERE p.id = '$postid' - AND p.user = u.id"); + AND p.userid = u.id"); } function forum_get_discussion_posts($discussion, $sort) { /// Gets posts with all info ready for forum_print_post global $CFG; - return get_records_sql("SELECT p.*, u.id as userid, u.firstname, u.lastname, u.email, u.picture + return get_records_sql("SELECT p.*, u.firstname, u.lastname, u.email, u.picture FROM {$CFG->prefix}forum_posts p, {$CFG->prefix}user u WHERE p.discussion = $discussion AND p.parent > 0 - AND p.user = u.id $sort"); + AND p.userid = u.id $sort"); } function forum_get_child_posts($parent) { /// Gets posts with all info ready for forum_print_post global $CFG; - return get_records_sql("SELECT p.*, u.id as userid, u.firstname, u.lastname, u.email, u.picture + return get_records_sql("SELECT p.*, u.firstname, u.lastname, u.email, u.picture FROM {$CFG->prefix}forum_posts p, {$CFG->prefix}user u WHERE p.parent = '$parent' - AND p.user = u.id + AND p.userid = u.id ORDER BY p.created ASC"); } @@ -418,13 +418,13 @@ function forum_search_posts($search, $courseid) { $notteacherforum = ""; } - return get_records_sql("SELECT p.*,u.firstname,u.lastname,u.email,u.picture,u.id as userid + return get_records_sql("SELECT p.*,u.firstname,u.lastname,u.email,u.picture FROM {$CFG->prefix}forum_posts p, {$CFG->prefix}forum_discussions d, {$CFG->prefix}user u, {$CFG->prefix}forum f WHERE (p.message LIKE '%$search%' OR p.subject LIKE '%$search%') - AND p.user = u.id + AND p.userid = u.id AND p.discussion = d.id AND d.course = '$courseid' AND d.forum = f.id @@ -439,7 +439,7 @@ function forum_get_ratings($postid, $sort="u.firstname ASC") { FROM {$CFG->prefix}forum_ratings r, {$CFG->prefix}user u WHERE r.post = '$postid' - AND r.user = u.id + AND r.userid = u.id ORDER BY $sort"); } @@ -458,7 +458,7 @@ function forum_get_user_posts($forumid, $userid) { /// Get all the posts for a user in a forum suitable for forum_print_post global $CFG; - return get_records_sql("SELECT p.*, u.id as userid, u.firstname, u.lastname, u.email, u.picture + return get_records_sql("SELECT p.*, u.firstname, u.lastname, u.email, u.picture FROM {$CFG->prefix}forum f, {$CFG->prefix}forum_discussions d, {$CFG->prefix}forum_posts p, @@ -466,8 +466,8 @@ function forum_get_user_posts($forumid, $userid) { WHERE f.id = '$forumid' AND d.forum = f.id AND p.discussion = d.id - AND p.user = '$userid' - AND p.user = u.id + AND p.userid = '$userid' + AND p.userid = u.id ORDER BY p.modified ASC"); } @@ -477,25 +477,25 @@ function forum_get_post_from_log($log) { if ($log->action == "add post") { - return get_record_sql("SELECT p.*, d.forum, u.firstname, u.lastname, u.email, u.picture, u.id as userid + return get_record_sql("SELECT p.*, d.forum, u.firstname, u.lastname, u.email, u.picture FROM {$CFG->prefix}forum_discussions d, {$CFG->prefix}forum_posts p, {$CFG->prefix}user u WHERE p.id = '$log->info' AND d.id = p.discussion - AND p.user = u.id + AND p.userid = u.id AND u.deleted <> '1'"); } else if ($log->action == "add discussion") { - return get_record_sql("SELECT p.*, d.forum, u.firstname, u.lastname, u.email, u.picture, u.id as userid + return get_record_sql("SELECT p.*, d.forum, u.firstname, u.lastname, u.email, u.picture FROM {$CFG->prefix}forum_discussions d, {$CFG->prefix}forum_posts p, {$CFG->prefix}user u WHERE d.id = '$log->info' AND d.firstpost = p.id - AND p.user = u.id + AND p.userid = u.id AND u.deleted <> '1'"); } return NULL; @@ -506,7 +506,7 @@ function forum_get_user_grades($forumid) { /// Get all user grades for a forum global $CFG; - return get_records_sql("SELECT r.id, p.user, r.rating + return get_records_sql("SELECT r.id, p.userid, r.rating FROM {$CFG->prefix}forum_discussions d, {$CFG->prefix}forum_posts p, {$CFG->prefix}forum_ratings r @@ -538,14 +538,14 @@ function forum_count_unrated_posts($discussionid, $userid) { FROM {$CFG->prefix}forum_posts WHERE parent > 0 AND discussion = '$discussionid' - AND user <> '$userid' ")) { + AND userid <> '$userid' ")) { if ($rated = get_record_sql("SELECT count(*) as num FROM {$CFG->prefix}forum_posts p, {$CFG->prefix}forum_ratings r WHERE p.discussion = '$discussionid' AND p.id = r.post - AND r.user = '$userid'")) { + AND r.userid = '$userid'")) { $difference = $posts->num - $rated->num; if ($difference > 0) { return $difference; @@ -569,14 +569,14 @@ function forum_get_discussions($forum="0", $forum_sort="DESC", $user=0) { } else { $userselect = ""; } - return get_records_sql("SELECT p.*, u.firstname, u.lastname, u.email, u.picture, u.id as userid + return get_records_sql("SELECT p.*, u.firstname, u.lastname, u.email, u.picture FROM {$CFG->prefix}forum_discussions d, {$CFG->prefix}forum_posts p, {$CFG->prefix}user u WHERE d.forum = '$forum' AND p.discussion = d.id AND p.parent= 0 - AND p.user = u.id $userselect + AND p.userid = u.id $userselect ORDER BY p.created $forum_sort"); } @@ -587,7 +587,7 @@ function forum_get_user_discussions($courseid, $userid) { global $CFG; return get_records_sql("SELECT p.*, u.firstname, u.lastname, u.email, u.picture, - u.id as userid, f.type as forumtype, f.name as forumname, f.id as forumid + f.type as forumtype, f.name as forumname, f.id as forumid FROM {$CFG->prefix}forum_discussions d, {$CFG->prefix}forum_posts p, {$CFG->prefix}user u, @@ -595,7 +595,7 @@ function forum_get_user_discussions($courseid, $userid) { WHERE d.course = '$courseid' AND p.discussion = d.id AND p.parent = 0 - AND p.user = u.id + AND p.userid = u.id AND u.id = '$userid' AND d.forum = f.id ORDER BY p.created ASC"); @@ -615,7 +615,7 @@ function forum_subscribed_users($course, $forum) { FROM {$CFG->prefix}user u, {$CFG->prefix}forum_subscriptions s WHERE s.forum = '$forum->id' - AND s.user = u.id + AND s.userid = u.id AND u.deleted <> 1"); } @@ -997,7 +997,7 @@ function forum_print_ratings($post) { function forum_print_rating($post, $user) { global $FORUM_POST_RATINGS; - if ($rating = get_record("forum_ratings", "user", $user, "post", $post)) { + if ($rating = get_record("forum_ratings", "userid", $user, "post", $post)) { if ($FORUM_POST_RATINGS[$rating->rating]) { echo "".get_string("youratedthis", "forum").": "; echo $FORUM_POST_RATINGS[$rating->rating]; @@ -1214,7 +1214,7 @@ function forum_add_discussion($discussion) { $post->discussion = 0; $post->parent = 0; - $post->user = $USER->id; + $post->userid = $USER->id; $post->created = $timenow; $post->modified = $timenow; $post->mailed = 0; @@ -1333,13 +1333,13 @@ function forum_is_subscribed($userid, $forumid) { if (forum_is_forcesubscribed($forumid)) { return true; } - return record_exists("forum_subscriptions", "user", $userid, "forum", $forumid); + return record_exists("forum_subscriptions", "userid", $userid, "forum", $forumid); } function forum_subscribe($userid, $forumid) { /// Adds user to the subscriber list - $sub->user = $userid; + $sub->userid = $userid; $sub->forum = $forumid; return insert_record("forum_subscriptions", $sub); @@ -1347,7 +1347,7 @@ function forum_subscribe($userid, $forumid) { function forum_unsubscribe($userid, $forumid) { /// Removes user from the subscriber list - return delete_records("forum_subscriptions", "user", $userid, "forum", $forumid); + return delete_records("forum_subscriptions", "userid", $userid, "forum", $forumid); } @@ -1482,7 +1482,7 @@ function forum_print_discussion($course, $forum, $discussion, $post, $mode) { global $USER; - $ownpost = ($USER->id == $post->user); + $ownpost = ($USER->id == $post->userid); $reply = forum_user_can_post($forum); forum_print_post($post, $course->id, $ownpost, $reply, $link=false, $rate=false); @@ -1541,7 +1541,7 @@ function forum_print_posts_flat($discussion, $course, $direction, $assessed, $re if ($posts = forum_get_discussion_posts($discussion, $sort)) { foreach ($posts as $post) { - $ownpost = ($USER->id == $post->user); + $ownpost = ($USER->id == $post->userid); forum_print_post($post, $course, $ownpost, $reply, $link, $assessed); } } else { @@ -1559,7 +1559,7 @@ function forum_print_posts_threaded($parent, $course, $depth, $assessed, $reply) echo "