From cd04ddb7eac832c249f055f56660ccaa623f72db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Mon, 1 Apr 2019 13:15:15 +0200 Subject: [PATCH] Version18.92.3 --- sql/swad.sql | 2 ++ swad_changelog.h | 7 ++++++- swad_database.c | 6 +++++- swad_layout.c | 7 +++++++ swad_user.c | 45 ++++++++++++++++++++++++++++++--------------- swad_user.h | 2 ++ 6 files changed, 52 insertions(+), 17 deletions(-) diff --git a/sql/swad.sql b/sql/swad.sql index 4a56b13d..328373ed 100644 --- a/sql/swad.sql +++ b/sql/swad.sql @@ -1414,6 +1414,8 @@ CREATE TABLE IF NOT EXISTS usr_last ( WhatToSearch TINYINT NOT NULL DEFAULT 0, LastCrs INT NOT NULL DEFAULT -1, LastTab TINYINT NOT NULL, + LastAct INT NOT NULL DEFAULT -1, + LastRole TINYINT NOT NULL DEFAULT 0, LastTime DATETIME NOT NULL, LastAccNotif DATETIME NOT NULL, TimelineUsrs TINYINT NOT NULL DEFAULT 0, diff --git a/swad_changelog.h b/swad_changelog.h index e328244e..885f48a8 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -464,10 +464,15 @@ En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 18.92.2 (2019-04-01)" +#define Log_PLATFORM_VERSION "SWAD 18.92.3 (2019-04-01)" #define CSS_FILE "swad18.92.css" #define JS_FILE "swad18.92.js" /* + Version 18.92.3: Apr 01, 2019 Last action and role are saved in database. (241410 lines) + 2 changes necessary in database: +ALTER TABLE usr_last ADD COLUMN LastAct INT NOT NULL DEFAULT -1 AFTER LastTab; +ALTER TABLE usr_last ADD COLUMN LastRole TINYINT NOT NULL DEFAULT 0 AFTER LastAct; + Version 18.92.2: Apr 01, 2019 Code refactoring related to user login and actions. (241379 lines) Version 18.92.1: Apr 01, 2019 Fixed bug in tests, reported by Javier Fernández Baldomero. (241371 lines) Version 18.92: Mar 29, 2019 Changes in timeline layout. (241367 lines) diff --git a/swad_database.c b/swad_database.c index 550a8ecb..c67c8dbb 100644 --- a/swad_database.c +++ b/swad_database.c @@ -2977,17 +2977,21 @@ mysql> DESCRIBE usr_last; | WhatToSearch | tinyint(4) | NO | | 0 | | | LastCrs | int(11) | NO | | -1 | | | LastTab | tinyint(4) | NO | | NULL | | +| LastAct | int(11) | NO | | -1 | | +| LastRole | tinyint(4) | NO | | 0 | | | LastTime | datetime | NO | MUL | NULL | | | LastAccNotif | datetime | NO | | NULL | | | TimelineUsrs | tinyint(4) | NO | | 0 | | +--------------+------------+------+-----+---------+-------+ -7 rows in set (0.00 sec) +9 rows in set (0.00 sec) */ DB_CreateTable ("CREATE TABLE IF NOT EXISTS usr_last (" "UsrCod INT NOT NULL," "WhatToSearch TINYINT NOT NULL DEFAULT 0," "LastCrs INT NOT NULL DEFAULT -1," "LastTab TINYINT NOT NULL," + "LastAct INT NOT NULL DEFAULT -1," + "LastRole TINYINT NOT NULL DEFAULT 0," "LastTime DATETIME NOT NULL," "LastAccNotif DATETIME NOT NULL," "TimelineUsrs TINYINT NOT NULL DEFAULT 0," diff --git a/swad_layout.c b/swad_layout.c index f25bec52..e8306208 100644 --- a/swad_layout.c +++ b/swad_layout.c @@ -1343,6 +1343,13 @@ void Lay_ShowErrorAndExit (const char *Txt) /***** Log access *****/ Sta_LogAccess (Txt); + /***** Update last data for next time *****/ + if (Gbl.Usrs.Me.Logged) + { + Usr_UpdateMyLastData (); + Crs_UpdateCrsLast (); + } + /***** End the output *****/ if (!Gbl.Layout.HTMLEndWritten) { diff --git a/swad_user.c b/swad_user.c index 87b3b083..09287b74 100644 --- a/swad_user.c +++ b/swad_user.c @@ -755,13 +755,16 @@ static void Usr_GetMyLastData (void) MYSQL_ROW row; unsigned long NumRows; unsigned UnsignedNum; + long ActCod; /***** Get user's last data from database *****/ NumRows = DB_QuerySELECT (&mysql_res,"can not get user's last data", "SELECT WhatToSearch," // row[0] "LastCrs," // row[1] "LastTab," // row[2] - "UNIX_TIMESTAMP(LastAccNotif)" // row[3] + "LastAct," // row[3] + "LastRole," // row[4] + "UNIX_TIMESTAMP(LastAccNotif)" // row[5] " FROM usr_last WHERE UsrCod=%ld", Gbl.Usrs.Me.UsrDat.UsrCod); if (NumRows == 0) @@ -777,7 +780,7 @@ static void Usr_GetMyLastData (void) { row = mysql_fetch_row (mysql_res); - /* Get last type of search */ + /* Get last type of search (row[0]) */ Gbl.Usrs.Me.UsrLast.WhatToSearch = Sch_SEARCH_UNKNOWN; if (sscanf (row[0],"%u",&UnsignedNum) == 1) if (UnsignedNum < Sch_NUM_WHAT_TO_SEARCH) @@ -785,20 +788,27 @@ static void Usr_GetMyLastData (void) if (Gbl.Usrs.Me.UsrLast.WhatToSearch == Sch_SEARCH_UNKNOWN) Gbl.Usrs.Me.UsrLast.WhatToSearch = Sch_WHAT_TO_SEARCH_DEFAULT; - /* Get last course */ + /* Get last course (row[1]) */ Gbl.Usrs.Me.UsrLast.LastCrs = Str_ConvertStrCodToLongCod (row[1]); - /* Get last tab */ + /* Get last tab (row[2]) */ Gbl.Usrs.Me.UsrLast.LastTab = TabStr; // By default, set last tab to the start tab if (sscanf (row[2],"%u",&UnsignedNum) == 1) if (UnsignedNum >= 1 || UnsignedNum <= Tab_NUM_TABS) Gbl.Usrs.Me.UsrLast.LastTab = (Tab_Tab_t) UnsignedNum; - /* Get last access to notifications */ + /* Get last action (row[3]) */ + ActCod = Str_ConvertStrCodToLongCod (row[3]); + Gbl.Usrs.Me.UsrLast.LastAct = Act_GetActionFromActCod (ActCod); + + /* Get last rolw (row[4]) */ + Gbl.Usrs.Me.UsrLast.LastRole = Rol_ConvertUnsignedStrToRole (row[4]); + + /* Get last access to notifications (row[5]) */ Gbl.Usrs.Me.UsrLast.LastAccNotif = 0L; - if (row[3]) - sscanf (row[3],"%ld",&(Gbl.Usrs.Me.UsrLast.LastAccNotif)); + if (row[5]) + sscanf (row[5],"%ld",&(Gbl.Usrs.Me.UsrLast.LastAccNotif)); /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); @@ -3117,11 +3127,11 @@ void Usr_ChkUsrAndGetUsrData (void) } /***** Update last data for next time *****/ - if (Gbl.Usrs.Me.Logged) - { - Usr_UpdateMyLastData (); - Crs_UpdateCrsLast (); - } + // if (Gbl.Usrs.Me.Logged) + // { + // Usr_UpdateMyLastData (); + // Crs_UpdateCrsLast (); + // } } } @@ -3483,10 +3493,13 @@ void Usr_UpdateMyLastData (void) /***** Update my last accessed course, tab and time of click in database *****/ // WhatToSearch, LastAccNotif remain unchanged DB_QueryUPDATE ("can not update last user's data", - "UPDATE usr_last SET LastCrs=%ld,LastTab=%u,LastTime=NOW()" + "UPDATE usr_last" + " SET LastCrs=%ld,LastTab=%u,LastAct=%ld,LastRole=%u,LastTime=NOW()" " WHERE UsrCod=%ld", Gbl.CurrentCrs.Crs.CrsCod, (unsigned) Gbl.Action.Tab, + Act_GetActCod (Gbl.Action.Act), + (unsigned) Gbl.Usrs.Me.Role.Logged, Gbl.Usrs.Me.UsrDat.UsrCod); else Usr_InsertMyLastData (); @@ -3501,13 +3514,15 @@ static void Usr_InsertMyLastData (void) /***** Insert my last accessed course, tab and time of click in database *****/ DB_QueryINSERT ("can not insert last user's data", "INSERT INTO usr_last" - " (UsrCod,WhatToSearch,LastCrs,LastTab,LastTime,LastAccNotif)" + " (UsrCod,WhatToSearch,LastCrs,LastTab,LastAct,LastRole,LastTime,LastAccNotif)" " VALUES" - " (%ld,%u,%ld,%u,NOW(),FROM_UNIXTIME(%ld))", + " (%ld,%u,%ld,%u,%ld,%u,NOW(),FROM_UNIXTIME(%ld))", Gbl.Usrs.Me.UsrDat.UsrCod, (unsigned) Sch_SEARCH_ALL, Gbl.CurrentCrs.Crs.CrsCod, (unsigned) Gbl.Action.Tab, + Act_GetActCod (Gbl.Action.Act), + (unsigned) Gbl.Usrs.Me.Role.Logged, (long) (time_t) 0); // The user never accessed to notifications } diff --git a/swad_user.h b/swad_user.h index 8668745c..6ede6d36 100644 --- a/swad_user.h +++ b/swad_user.h @@ -214,6 +214,8 @@ struct UsrLast Sch_WhatToSearch_t WhatToSearch; // Search courses, teachers, documents...? long LastCrs; Tab_Tab_t LastTab; + Act_Action_t LastAct; + Rol_Role_t LastRole; long LastAccNotif; };