diff --git a/sql/swad.sql b/sql/swad.sql index 481cb25cb..26e8ee942 100644 --- a/sql/swad.sql +++ b/sql/swad.sql @@ -352,6 +352,18 @@ CREATE TABLE IF NOT EXISTS crs_records ( Txt TEXT NOT NULL, UNIQUE INDEX(FieldCod,UsrCod)); -- +-- Table crs_requests: stores requests for enrollment in courses +-- +CREATE TABLE IF NOT EXISTS crs_requests ( + ReqCod INT NOT NULL AUTO_INCREMENT, + CrsCod INT NOT NULL DEFAULT -1, + UsrCod INT NOT NULL, + Role TINYINT NOT NULL DEFAULT 0, + RequestTime DATETIME NOT NULL, + UNIQUE INDEX(ReqCod), + UNIQUE INDEX(CrsCod,UsrCod), + INDEX(UsrCod)); +-- -- Table crs_users: stores who users belong to what courses -- CREATE TABLE IF NOT EXISTS crs_users ( @@ -368,9 +380,9 @@ CREATE TABLE IF NOT EXISTS crs_users ( INDEX(CrsCod,Role), INDEX(UsrCod,Role)); -- --- Table crs_usr_last: stores last prefs of users in courses +-- Table crs_user_settings: stores last settings (preferences) of users in courses -- -CREATE TABLE IF NOT EXISTS crs_usr_last ( +CREATE TABLE IF NOT EXISTS crs_user_settings ( UsrCod INT NOT NULL, CrsCod INT NOT NULL, LastDowGrpCod INT NOT NULL DEFAULT -1, @@ -384,18 +396,6 @@ CREATE TABLE IF NOT EXISTS crs_usr_last ( ListWithPhotos ENUM('N','Y') NOT NULL DEFAULT 'Y', UNIQUE INDEX(UsrCod,CrsCod)); -- --- Table crs_requests: stores requests for enrollment in courses --- -CREATE TABLE IF NOT EXISTS crs_requests ( - ReqCod INT NOT NULL AUTO_INCREMENT, - CrsCod INT NOT NULL DEFAULT -1, - UsrCod INT NOT NULL, - Role TINYINT NOT NULL DEFAULT 0, - RequestTime DATETIME NOT NULL, - UNIQUE INDEX(ReqCod), - UNIQUE INDEX(CrsCod,UsrCod), - INDEX(UsrCod)); --- -- Table ctr_centers: centers (faculties, schools...) -- CREATE TABLE IF NOT EXISTS ctr_centers ( diff --git a/swad_account.c b/swad_account.c index d8065ddd3..4ca6258e1 100644 --- a/swad_account.c +++ b/swad_account.c @@ -1049,7 +1049,7 @@ void Acc_CompletelyEliminateAccount (struct UsrData *UsrDat, /***** Remove user from the tables of courses and users *****/ DB_QueryDELETE ("can not remove a user from all courses", - "DELETE FROM crs_usr_last" + "DELETE FROM crs_user_settings" " WHERE UsrCod=%ld", UsrDat->UsrCod); DB_QueryDELETE ("can not remove a user from all courses", diff --git a/swad_changelog.h b/swad_changelog.h index 256b970a8..481289ce6 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -600,13 +600,17 @@ TODO: Salvador Romero Cort TODO: FIX BUG, URGENT! En las fechas como parámetro Dat_WriteParamsIniEndDates(), por ejemplo al cambiar el color de la gráfica de accesos por día y hora, no se respeta la zona horaria. */ -#define Log_PLATFORM_VERSION "SWAD 20.51.40 (2021-03-24)" +#define Log_PLATFORM_VERSION "SWAD 20.51.41 (2021-03-24)" #define CSS_FILE "swad20.45.css" #define JS_FILE "swad20.6.2.js" /* TODO: Rename CENTRE to CENTER in help wiki. TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams + Version 20.51.41: Mar 24, 2021 Course user settings database table renamed. (? lines) + 1 change necessary in database: +RENAME TABLE crs_usr_last TO crs_user_settings; + Version 20.51.40: Mar 24, 2021 Course requests database table renamed. (308671 lines) 1 change necessary in database: RENAME TABLE crs_usr_requests TO crs_requests; diff --git a/swad_course.c b/swad_course.c index 7ab6538ff..88ed33e04 100644 --- a/swad_course.c +++ b/swad_course.c @@ -2058,7 +2058,7 @@ static void Crs_EmptyCourseCompletely (long CrsCod) /***** Remove possible users remaining in the course (teachers) *****/ DB_QueryDELETE ("can not remove users from a course", - "DELETE FROM crs_usr_last" + "DELETE FROM crs_user_settings" " WHERE CrsCod=%ld", CrsCod); DB_QueryDELETE ("can not remove users from a course", diff --git a/swad_database.c b/swad_database.c index 41fff831b..e48e2be21 100644 --- a/swad_database.c +++ b/swad_database.c @@ -830,6 +830,30 @@ mysql> DESCRIBE crs_records; "Txt TEXT NOT NULL," // Cns_MAX_BYTES_TEXT "UNIQUE INDEX(FieldCod,UsrCod))"); + /***** Table crs_requests *****/ +/* +mysql> DESCRIBE crs_requests; ++-------------+------------+------+-----+---------+----------------+ +| Field | Type | Null | Key | Default | Extra | ++-------------+------------+------+-----+---------+----------------+ +| ReqCod | int(11) | NO | PRI | NULL | auto_increment | +| CrsCod | int(11) | NO | MUL | -1 | | +| UsrCod | int(11) | NO | MUL | NULL | | +| Role | tinyint(4) | NO | | 0 | | +| RequestTime | datetime | NO | | NULL | | ++-------------+------------+------+-----+---------+----------------+ +5 rows in set (0.01 sec) +*/ + DB_CreateTable ("CREATE TABLE IF NOT EXISTS crs_requests (" + "ReqCod INT NOT NULL AUTO_INCREMENT," + "CrsCod INT NOT NULL DEFAULT -1," + "UsrCod INT NOT NULL," + "Role TINYINT NOT NULL DEFAULT 0," + "RequestTime DATETIME NOT NULL," + "UNIQUE INDEX(ReqCod)," + "UNIQUE INDEX(CrsCod,UsrCod)," + "INDEX(UsrCod))"); + /***** Table crs_users *****/ /* mysql> DESCRIBE crs_users; @@ -857,9 +881,9 @@ mysql> DESCRIBE crs_users; "INDEX(CrsCod,Role)," "INDEX(UsrCod,Role))"); - /***** Table crs_usr_last *****/ + /***** Table crs_user_settings *****/ /* -mysql> DESCRIBE crs_usr_last; +mysql> DESCRIBE crs_user_settings; +----------------+---------------------------+------+-----+------------+-------+ | Field | Type | Null | Key | Default | Extra | +----------------+---------------------------+------+-----+------------+-------+ @@ -877,7 +901,7 @@ mysql> DESCRIBE crs_usr_last; +----------------+---------------------------+------+-----+------------+-------+ 11 rows in set (0.00 sec) */ - DB_CreateTable ("CREATE TABLE IF NOT EXISTS crs_usr_last (" + DB_CreateTable ("CREATE TABLE IF NOT EXISTS crs_user_settings (" "UsrCod INT NOT NULL," "CrsCod INT NOT NULL," "LastDowGrpCod INT NOT NULL DEFAULT -1," @@ -891,30 +915,6 @@ mysql> DESCRIBE crs_usr_last; "ListWithPhotos ENUM('N','Y') NOT NULL DEFAULT 'Y'," "UNIQUE INDEX(UsrCod,CrsCod))"); - /***** Table crs_requests *****/ -/* -mysql> DESCRIBE crs_requests; -+-------------+------------+------+-----+---------+----------------+ -| Field | Type | Null | Key | Default | Extra | -+-------------+------------+------+-----+---------+----------------+ -| ReqCod | int(11) | NO | PRI | NULL | auto_increment | -| CrsCod | int(11) | NO | MUL | -1 | | -| UsrCod | int(11) | NO | MUL | NULL | | -| Role | tinyint(4) | NO | | 0 | | -| RequestTime | datetime | NO | | NULL | | -+-------------+------------+------+-----+---------+----------------+ -5 rows in set (0.01 sec) -*/ - DB_CreateTable ("CREATE TABLE IF NOT EXISTS crs_requests (" - "ReqCod INT NOT NULL AUTO_INCREMENT," - "CrsCod INT NOT NULL DEFAULT -1," - "UsrCod INT NOT NULL," - "Role TINYINT NOT NULL DEFAULT 0," - "RequestTime DATETIME NOT NULL," - "UNIQUE INDEX(ReqCod)," - "UNIQUE INDEX(CrsCod,UsrCod)," - "INDEX(UsrCod))"); - /***** Table ctr_centers *****/ /* mysql> DESCRIBE ctr_centers; diff --git a/swad_enrolment.c b/swad_enrolment.c index 8ab32bb3e..989516635 100644 --- a/swad_enrolment.c +++ b/swad_enrolment.c @@ -305,7 +305,7 @@ void Enr_RegisterUsrInCurrentCrs (struct UsrData *UsrDat,Rol_Role_t NewRole, /***** Register last prefs in current course in database *****/ DB_QueryINSERT ("can not register user in course", - "INSERT INTO crs_usr_last" + "INSERT INTO crs_user_settings" " (UsrCod,CrsCod," "LastDowGrpCod,LastComGrpCod,LastAssGrpCod," "NumAccTst,LastAccTst,NumQstsLastTst," @@ -4229,7 +4229,7 @@ static void Enr_EffectivelyRemUsrFromCrs (struct UsrData *UsrDat, /***** Remove user from the tables of courses-users *****/ DB_QueryDELETE ("can not remove a user from a course", - "DELETE FROM crs_usr_last" + "DELETE FROM crs_user_settings" " WHERE UsrCod=%ld" " AND CrsCod=%ld", UsrDat->UsrCod,Crs->CrsCod); diff --git a/swad_file_browser.c b/swad_file_browser.c index 46a891420..ff36e072f 100644 --- a/swad_file_browser.c +++ b/swad_file_browser.c @@ -3902,8 +3902,10 @@ static void Brw_UpdateGrpLastAccZone (const char *FieldNameDB,long GrpCod) { /***** Update the group of my last access to a common zone *****/ DB_QueryUPDATE ("can not update the group of the last access to a file browser", - "UPDATE crs_usr_last SET %s=%ld" - " WHERE UsrCod=%ld AND CrsCod=%ld", + "UPDATE crs_user_settings" + " SET %s=%ld" + " WHERE UsrCod=%ld" + " AND CrsCod=%ld", FieldNameDB,GrpCod, Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Hierarchy.Crs.CrsCod); @@ -5268,8 +5270,10 @@ static long Brw_GetGrpLastAccZone (const char *FieldNameDB) NumRows = DB_QuerySELECT (&mysql_res,"can not get the group" " of your last access" " to a file browser", - "SELECT %s FROM crs_usr_last" - " WHERE UsrCod=%ld AND CrsCod=%ld", + "SELECT %s" // row[0] + " FROM crs_user_settings" + " WHERE UsrCod=%ld" + " AND CrsCod=%ld", FieldNameDB, Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Hierarchy.Crs.CrsCod); diff --git a/swad_group.c b/swad_group.c index 9d1d85166..91b930e24 100644 --- a/swad_group.c +++ b/swad_group.c @@ -981,7 +981,7 @@ static void Grp_LockTables (void) "grp_groups WRITE," "grp_users WRITE," "crs_users READ," - "crs_usr_last READ," + "crs_user_settings READ," "roo_rooms READ"); Gbl.DB.LockedTables = true; } diff --git a/swad_test.c b/swad_test.c index 15687dbe6..f1a48e706 100644 --- a/swad_test.c +++ b/swad_test.c @@ -603,11 +603,13 @@ static bool Tst_CheckIfNextTstAllowed (void) "SELECT UNIX_TIMESTAMP(LastAccTst+INTERVAL (NumQstsLastTst*%lu) SECOND)-" "UNIX_TIMESTAMP()," // row[0] "UNIX_TIMESTAMP(LastAccTst+INTERVAL (NumQstsLastTst*%lu) SECOND)" // row[1] - " FROM crs_usr_last" - " WHERE UsrCod=%ld AND CrsCod=%ld", + " FROM crs_user_settings" + " WHERE UsrCod=%ld" + " AND CrsCod=%ld", TstCfg_GetConfigMinTimeNxtTstPerQst (), TstCfg_GetConfigMinTimeNxtTstPerQst (), - Gbl.Usrs.Me.UsrDat.UsrCod,Gbl.Hierarchy.Crs.CrsCod) == 1) + Gbl.Usrs.Me.UsrDat.UsrCod, + Gbl.Hierarchy.Crs.CrsCod) == 1) { /* Get seconds from now to next access to test */ row = mysql_fetch_row (mysql_res); @@ -657,8 +659,9 @@ static unsigned Tst_GetNumExamsGeneratedByMe (void) /***** Get number of test exams generated by me from database *****/ NumRows = DB_QuerySELECT (&mysql_res,"can not get number of test exams generated", "SELECT NumAccTst" // row[0] - " FROM crs_usr_last" - " WHERE UsrCod=%ld AND CrsCod=%ld", + " FROM crs_user_settings" + " WHERE UsrCod=%ld" + " AND CrsCod=%ld", Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Hierarchy.Crs.CrsCod); @@ -941,8 +944,10 @@ static void Tst_IncreaseMyNumAccessTst (void) /***** Update my number of accesses to test in this course *****/ DB_QueryUPDATE ("can not update the number of accesses to test", - "UPDATE crs_usr_last SET NumAccTst=NumAccTst+1" - " WHERE UsrCod=%ld AND CrsCod=%ld", + "UPDATE crs_user_settings" + " SET NumAccTst=NumAccTst+1" + " WHERE UsrCod=%ld" + " AND CrsCod=%ld", Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Hierarchy.Crs.CrsCod); } @@ -955,8 +960,11 @@ static void Tst_UpdateLastAccTst (unsigned NumQsts) { /***** Update date-time and number of questions of this test *****/ DB_QueryUPDATE ("can not update time and number of questions of this test", - "UPDATE crs_usr_last SET LastAccTst=NOW(),NumQstsLastTst=%u" - " WHERE UsrCod=%ld AND CrsCod=%ld", + "UPDATE crs_user_settings" + " SET LastAccTst=NOW()," + "NumQstsLastTst=%u" + " WHERE UsrCod=%ld" + " AND CrsCod=%ld", NumQsts, Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Hierarchy.Crs.CrsCod); diff --git a/swad_user.c b/swad_user.c index 834742935..fa31a0245 100644 --- a/swad_user.c +++ b/swad_user.c @@ -7752,8 +7752,10 @@ static void Usr_GetMyUsrListTypeFromDB (void) /***** Get type of listing of users from database *****/ NumRows = DB_QuerySELECT (&mysql_res,"can not get type of listing of users", - "SELECT UsrListType FROM crs_usr_last" - " WHERE UsrCod=%ld AND CrsCod=%ld", + "SELECT UsrListType" + " FROM crs_user_settings" + " WHERE UsrCod=%ld" + " AND CrsCod=%ld", Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Hierarchy.Crs.CrsCod); if (NumRows == 1) // Should be one only row @@ -7791,8 +7793,10 @@ static void Usr_UpdateMyUsrListTypeInDB (void) { /***** Update type of users listing *****/ DB_QueryUPDATE ("can not update type of listing", - "UPDATE crs_usr_last SET UsrListType='%s'" - " WHERE UsrCod=%ld AND CrsCod=%ld", + "UPDATE crs_user_settings" + " SET UsrListType='%s'" + " WHERE UsrCod=%ld" + " AND CrsCod=%ld", Usr_StringsUsrListTypeInDB[Gbl.Usrs.Me.ListType], Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Hierarchy.Crs.CrsCod); @@ -7857,8 +7861,10 @@ static void Usr_GetMyColsClassPhotoFromDB (void) /***** Get number of columns in class photo from database *****/ NumRows = DB_QuerySELECT (&mysql_res,"can not get number of columns" " in class photo", - "SELECT ColsClassPhoto FROM crs_usr_last" - " WHERE UsrCod=%ld AND CrsCod=%ld", + "SELECT ColsClassPhoto" + " FROM crs_user_settings" + " WHERE UsrCod=%ld" + " AND CrsCod=%ld", Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Hierarchy.Crs.CrsCod); if (NumRows == 1) // Should be one only row @@ -7891,8 +7897,10 @@ static void Usr_UpdateMyColsClassPhotoInDB (void) Gbl.Hierarchy.Level == Hie_Lvl_CRS) // Course selected /***** Update number of colums in class photo for current course *****/ DB_QueryUPDATE ("can not update number of columns in class photo", - "UPDATE crs_usr_last SET ColsClassPhoto=%u" - " WHERE UsrCod=%ld AND CrsCod=%ld", + "UPDATE crs_user_settings" + " SET ColsClassPhoto=%u" + " WHERE UsrCod=%ld" + " AND CrsCod=%ld", Gbl.Usrs.ClassPhoto.Cols, Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Hierarchy.Crs.CrsCod); @@ -7962,8 +7970,10 @@ void Usr_GetMyPrefAboutListWithPhotosFromDB (void) /***** Get if listing of users must show photos from database *****/ NumRows = DB_QuerySELECT (&mysql_res,"can not check if listing of users" " must show photos", - "SELECT ListWithPhotos FROM crs_usr_last" - " WHERE UsrCod=%ld AND CrsCod=%ld", + "SELECT ListWithPhotos" + " FROM crs_user_settings" + " WHERE UsrCod=%ld" + " AND CrsCod=%ld", Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Hierarchy.Crs.CrsCod); if (NumRows == 1) // Should be one only row @@ -7993,8 +8003,10 @@ static void Usr_UpdateMyPrefAboutListWithPhotosPhotoInDB (void) Gbl.Hierarchy.Level == Hie_Lvl_CRS) // Course selected /***** Update number of colums in class photo for current course *****/ DB_QueryUPDATE ("can not update your preference about photos in listing", - "UPDATE crs_usr_last SET ListWithPhotos='%c'" - " WHERE UsrCod=%ld AND CrsCod=%ld", + "UPDATE crs_user_settings" + " SET ListWithPhotos='%c'" + " WHERE UsrCod=%ld" + " AND CrsCod=%ld", Gbl.Usrs.Listing.WithPhotos ? 'Y' : 'N', Gbl.Usrs.Me.UsrDat.UsrCod,