From e27f8ea601f5ce04d66224b2134c9c0b7ab0b40a Mon Sep 17 00:00:00 2001 From: Ivan Tcholakov Date: Fri, 28 Aug 2009 13:18:33 +0300 Subject: [PATCH] Bug #1370 - Before going further, cleaning code first. Clarification of using constants for selecting database tables. Replacing everywhere hardcoded database names with the corresponding constants. --- main/announcements/announcements.inc.php | 4 +- main/announcements/announcements.php | 4 +- main/auth/my_progress.php | 10 +- main/exercice/answer.class.php | 2 +- main/forum/forumfunction.inc.php | 8 +- .../lib/be/forumthreadlink.class.php | 2 +- main/inc/lib/database.lib.php | 22 ++-- main/inc/lib/surveymanager.lib.php | 48 ++++---- main/metadata/importmanifest.php | 2 +- main/metadata/md_funcs.php | 2 +- main/metadata/md_scorm.php | 2 +- main/mySpace/myStudents.php | 6 +- main/newscorm/aicc.class.php | 16 +-- main/newscorm/learnpath.class.php | 114 +++++++++--------- main/newscorm/learnpathItem.class.php | 36 +++--- main/newscorm/learnpathList.class.php | 2 +- main/newscorm/learnpath_functions.inc.php | 10 +- main/newscorm/lp_add.php | 6 +- main/newscorm/lp_add_item.php | 6 +- main/newscorm/lp_admin_view.php | 10 +- main/newscorm/lp_build.php | 6 +- main/newscorm/lp_controller.php | 2 +- main/newscorm/lp_edit_item.php | 6 +- main/newscorm/lp_edit_item_prereq.php | 6 +- main/newscorm/lp_move_item.php | 6 +- main/newscorm/lp_stats.php | 8 +- main/newscorm/lp_view.php | 4 +- main/newscorm/lp_view_item.php | 6 +- main/newscorm/resourcelinker.inc.php | 8 +- main/newscorm/resourcelinker.php | 4 +- main/newscorm/scorm.class.php | 18 +-- main/survey/reporting.php | 2 +- main/survey/survey.php | 2 +- main/survey/survey_invite.php | 2 +- main/tracking/courseLog.php | 2 +- main/tracking/courseLogCSV.php | 10 +- main/tracking/userLog.php | 10 +- main/tracking/userlogCSV.php | 10 +- 38 files changed, 215 insertions(+), 209 deletions(-) diff --git a/main/announcements/announcements.inc.php b/main/announcements/announcements.inc.php index 1ddef5df3a..dc4bb2b517 100644 --- a/main/announcements/announcements.inc.php +++ b/main/announcements/announcements.inc.php @@ -44,8 +44,8 @@ function display_announcement($announcement_id) if ($announcement_id != strval(intval($announcement_id))) { return false; } // potencial sql injection - $tbl_announcement = Database::get_course_table('announcement'); - $tbl_item_property = Database::get_course_table('item_property'); + $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT); + $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY); if ($_user['user_id']) { diff --git a/main/announcements/announcements.php b/main/announcements/announcements.php index 650829f2f2..87ba3ca9e0 100644 --- a/main/announcements/announcements.php +++ b/main/announcements/announcements.php @@ -590,7 +590,7 @@ if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_ed $res_date=api_sql_query($sql_date, __FILE__, __LINE__); $obj_date=Database::fetch_object($res_date); $end_date=$obj_date->avail_till; - $table_reminder = Database :: get_main_table(TABLE_MAIN_SURVEY_REMINDER); + $table_reminder = Database :: get_main_table(TABLE_MAIN_SURVEY_REMINDER); // TODO: To be checked. TABLE_MAIN_SURVEY_REMINDER has not been defined. if ($_REQUEST['reminder']=="1") { $time=getdate(); $time = $time['yday']; @@ -737,7 +737,7 @@ if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_ed $res_date=api_sql_query($sql_date, __FILE__, __LINE__); $obj_date=Database::fetch_object($res_date); $end_date=$obj_date->avail_till; - $table_reminder = Database :: get_main_table(TABLE_MAIN_SURVEY_REMINDER); + $table_reminder = Database :: get_main_table(TABLE_MAIN_SURVEY_REMINDER); // TODO: To be checked. TABLE_MAIN_SURVEY_REMINDER has not been defined. if ($_REQUEST['reminder']=="1") { $time=getdate(); diff --git a/main/auth/my_progress.php b/main/auth/my_progress.php index e0edcb283b..f90da930cb 100644 --- a/main/auth/my_progress.php +++ b/main/auth/my_progress.php @@ -27,11 +27,11 @@ $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE); $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER); $tbl_stats_lastaccess = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS); $tbl_stats_exercices = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); -$tbl_course_lp_view = Database :: get_course_table('lp_view'); -$tbl_course_lp_view_item = Database :: get_course_table('lp_item_view'); -$tbl_course_lp = Database :: get_course_table('lp'); -$tbl_course_lp_item = Database :: get_course_table('lp_item'); -$tbl_course_quiz = Database :: get_course_table('quiz'); +$tbl_course_lp_view = Database :: get_course_table(TABLE_LP_VIEW); +$tbl_course_lp_view_item = Database :: get_course_table(TABLE_LP_ITEM_VIEW); +$tbl_course_lp = Database :: get_course_table(TABLE_LP_MAIN); +$tbl_course_lp_item = Database :: get_course_table(TABLE_LP_ITEM); +$tbl_course_quiz = Database :: get_course_table(TABLE_QUIZ_TEST); // get course list diff --git a/main/exercice/answer.class.php b/main/exercice/answer.class.php index 8fa2d13012..ed415b199b 100644 --- a/main/exercice/answer.class.php +++ b/main/exercice/answer.class.php @@ -156,7 +156,7 @@ class Answer { $order = 'ASC'; } - $TBL_ANSWER = Database::get_course_table('quiz_answer'); + $TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER); $questionId=$this->questionId; //$answerType=$this->selectType(); diff --git a/main/forum/forumfunction.inc.php b/main/forum/forumfunction.inc.php index 6d6ea1cc12..f1b652df3a 100644 --- a/main/forum/forumfunction.inc.php +++ b/main/forum/forumfunction.inc.php @@ -2828,7 +2828,7 @@ function send_notification_mails($thread_id, $reply_info) { $sql="SELECT * FROM $table_posts WHERE thread_id='".Database::escape_string($thread_id)."' AND post_notification='1'"; $result=api_sql_query($sql, __LINE__, __FILE__); */ - $table_notification = Database::get_course_table('forum_notification'); + $table_notification = Database::get_course_table(TABLE_FORUM_NOTIFICATION); $sql = "SELECT * FROM $table_notification WHERE forum_id = '".Database::escape_string($current_forum['forum_id'])."' OR thread_id = '".Database::escape_string($thread_id)."'"; $result=api_sql_query($sql, __FILE__, __LINE__); while ($row=Database::fetch_array($result)) { @@ -3595,7 +3595,7 @@ function set_notification($content,$id, $add_only = false) { } // database table definition - $table_notification = Database::get_course_table('forum_notification'); + $table_notification = Database::get_course_table(TABLE_FORUM_NOTIFICATION); // first we check if the notification is already set for this $sql = "SELECT * FROM $table_notification WHERE $database_field = '".Database::escape_string($id)."' AND user_id = '".Database::escape_string($_user['user_id'])."'"; @@ -3642,7 +3642,7 @@ function get_notifications($content,$id) { $database_field = 'thread_id'; } // database table definition - $table_notification = Database::get_course_table('forum_notification'); + $table_notification = Database::get_course_table(TABLE_FORUM_NOTIFICATION); $sql = "SELECT user.user_id, user.firstname, user.lastname, user.email, user.user_id user FROM $table_users user, $table_notification notification WHERE user.user_id = notification.user_id AND notification.$database_field= '".Database::escape_string($id)."'"; @@ -3737,7 +3737,7 @@ function get_notifications_of_user($user_id = 0, $force = false) { } // database table definition - $table_notification = Database::get_course_table('forum_notification'); + $table_notification = Database::get_course_table(TABLE_FORUM_NOTIFICATION); $my_code = isset($_course['code']) ? $_course['code'] : ''; if (!isset($_SESSION['forum_notification']) OR $_SESSION['forum_notification']['course'] <> $my_code OR $force=true) { $_SESSION['forum_notification']['course'] = $my_code; diff --git a/main/gradebook/lib/be/forumthreadlink.class.php b/main/gradebook/lib/be/forumthreadlink.class.php index 387dc8e730..b0b40157d3 100755 --- a/main/gradebook/lib/be/forumthreadlink.class.php +++ b/main/gradebook/lib/be/forumthreadlink.class.php @@ -125,7 +125,7 @@ class ForumThreadLink extends AbstractLink $course_info = Database :: get_course_info($this->get_course_code()); $database_name = (empty($course_info['db_name']))?$course_info['dbName']:$course_info['db_name']; if ($database_name!="") { - $thread_qualify = Database :: get_course_table('forum_thread_qualify', $database_name); + $thread_qualify = Database :: get_course_table(TABLE_FORUM_THREAD_QUALIFY, $database_name); $sql = 'SELECT thread_qualify_max FROM '.Database :: get_course_table(TABLE_FORUM_THREAD, $database_name)." WHERE thread_id = '".$this->get_ref_id()."'"; $query = api_sql_query($sql,__FILE__,__LINE__); diff --git a/main/inc/lib/database.lib.php b/main/inc/lib/database.lib.php index de4cf55dca..769a0b4c85 100644 --- a/main/inc/lib/database.lib.php +++ b/main/inc/lib/database.lib.php @@ -83,21 +83,21 @@ define('TABLE_MAIN_RESERVATION_CATEGORY', 'reservation_category'); define('TABLE_MAIN_RESERVATION_ITEM_RIGHTS', 'reservation_item_rights'); // Social networking -define('TABLE_MAIN_USER_FRIEND','user_friend'); +define('TABLE_MAIN_USER_FRIEND', 'user_friend'); define('TABLE_MAIN_USER_FRIEND_RELATION_TYPE', 'user_friend_relation_type'); // Web services -define('TABLE_MAIN_USER_API_KEY','user_api_key'); +define('TABLE_MAIN_USER_API_KEY', 'user_api_key'); define('TABLE_MAIN_COURSE_FIELD', 'course_field'); define('TABLE_MAIN_COURSE_FIELD_VALUES', 'course_field_values'); define('TABLE_MAIN_SESSION_FIELD', 'session_field'); define('TABLE_MAIN_SESSION_FIELD_VALUES', 'session_field_values'); // Message -define('TABLE_MAIN_MESSAGE','message'); +define('TABLE_MAIN_MESSAGE', 'message'); // Term and conditions -define('TABLE_MAIN_LEGAL','legal'); +define('TABLE_MAIN_LEGAL', 'legal'); // Statistic database tables define('TABLE_STATISTIC_TRACK_E_LASTACCESS', 'track_e_lastaccess'); @@ -123,7 +123,7 @@ define('TABLE_SCORM_SCO_DATA', 'scorm_sco_data'); define('TABLE_AGENDA', 'calendar_event'); define('TABLE_AGENDA_REPEAT', 'calendar_event_repeat'); define('TABLE_AGENDA_REPEAT_NOT', 'calendar_event_repeat_not'); -define('TABLE_AGENDA_ATTACHMENT','calendar_event_attachment'); +define('TABLE_AGENDA_ATTACHMENT', 'calendar_event_attachment'); define('TABLE_ANNOUNCEMENT', 'announcement'); define('TABLE_CHAT_CONNECTED', 'chat_connected'); // @todo: probably no longer in use !!! define('TABLE_COURSE_DESCRIPTION', 'course_description'); @@ -219,17 +219,20 @@ define('TABLE_PERSONAL_AGENDA_REPEAT_NOT', 'personal_agenda_repeat_not'); define('TABLE_USER_COURSE_CATEGORY', 'user_course_category'); // Survey -// @todo: are these MAIN tables or course tables ? +// @TODO: Are these MAIN tables or course tables? +// @TODO: Probably these constants are obsolete. define('TABLE_MAIN_SURVEY', 'survey'); define('TABLE_MAIN_GROUP', 'survey_group'); define('TABLE_MAIN_SURVEYQUESTION', 'questions'); + // Survey define('TABLE_SURVEY', 'survey'); define('TABLE_SURVEY_QUESTION', 'survey_question'); define('TABLE_SURVEY_QUESTION_OPTION', 'survey_question_option'); define('TABLE_SURVEY_INVITATION', 'survey_invitation'); define('TABLE_SURVEY_ANSWER', 'survey_answer'); -define('TABLE_SURVEY_QUESTION_GROUP','survey_group'); +define('TABLE_SURVEY_QUESTION_GROUP', 'survey_group'); +define('TABLE_SURVEY_REPORT', 'survey_report'); // Wiki tables define('TABLE_WIKI', 'wiki'); @@ -244,7 +247,10 @@ define('TABLE_GLOSSARY', 'glossary'); define('TABLE_NOTEBOOK', 'notebook'); // Message -define('TABLE_MESSAGE', 'message'); +define('TABLE_MESSAGE', 'message'); + +// Metadata +define('TABLE_METADATA', 'metadata'); /* diff --git a/main/inc/lib/surveymanager.lib.php b/main/inc/lib/surveymanager.lib.php index bf304bfccf..9ecbae7400 100644 --- a/main/inc/lib/surveymanager.lib.php +++ b/main/inc/lib/surveymanager.lib.php @@ -39,7 +39,7 @@ class SurveyManager { * Possible deprecated method */ public static function select_survey_list ($seleced_surveyid='', $extra_script='') { - $survey_table = Database :: get_course_table('survey'); + $survey_table = Database :: get_course_table(TABLE_SURVEY); $sql = "SELECT * FROM $survey_table";// WHERE is_shared='1'"; $sql_result = api_sql_query($sql,__FILE__,__LINE__); if(mysql_num_rows($sql_result)>0) @@ -123,7 +123,7 @@ class SurveyManager { */ function get_author($db_name,$survey_id) { - //$table_survey = Database :: get_course_table('survey'); + //$table_survey = Database :: get_course_table(TABLE_SURVEY); $survey_id = Database::escape_string($survey_id); $sql = "SELECT author FROM $db_name.survey WHERE survey_id='$survey_id'"; $res = api_sql_query($sql, __FILE__, __LINE__); @@ -135,7 +135,7 @@ class SurveyManager { */ function get_surveyid($db_name,$group_id) { - //$group_table = Database :: get_course_table('survey_group'); + //$group_table = Database :: get_course_table(TABLE_SURVEY_QUESTION_GROUP); $group_id = Database::escape_string($group_id); $sql = "SELECT survey_id FROM $db_name.survey_group WHERE group_id='$group_id'"; $res = api_sql_query($sql, __FILE__, __LINE__); @@ -144,7 +144,7 @@ class SurveyManager { } public static function get_groupname ($db_name,$gid) { - //$grouptable = Database :: get_course_table('survey_group'); + //$grouptable = Database :: get_course_table(TABLE_SURVEY_QUESTION_GROUP); $gid = Database::escape_string($gid); $sql = "SELECT * FROM $db_name.survey_group WHERE group_id='$gid'"; $res=api_sql_query($sql); @@ -183,7 +183,7 @@ class SurveyManager { */ function get_survey_list() { - $survey_table = Database :: get_course_table('survey'); + $survey_table = Database :: get_course_table(TABLE_SURVEY); $sql_query = "SELECT survey_id,title FROM $survey_table where title!='' "; $sql_result = api_sql_query($sql_query,__FILE__,__LINE__); echo "