diff --git a/swad_changelog.h b/swad_changelog.h index 2045a3d3..47215c99 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -553,7 +553,7 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - * En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 20.36.17 (2021-02-27)" +#define Log_PLATFORM_VERSION "SWAD 20.36.18 (2021-02-27)" #define CSS_FILE "swad20.33.9.css" #define JS_FILE "swad20.6.2.js" /* @@ -601,6 +601,7 @@ TODO: DNI de un estudiante sale err TODO: BUG: Cuando un tipo de grupo sólo tiene un grupo, inscribirse es voluntario, el estudiante sólo puede pertenecer a un grupo, y se inscribe en él, debería poder desapuntarse. Ahora no puede. TODO: Salvador Romero Cortés: @acanas opción para editar posts + Version 20.36.18: Feb 27, 2021 Function moved to module swad_timeline_database. (305334 lines) Version 20.36.17: Feb 27, 2021 Query moved to module swad_timeline_database. (305328 lines) Version 20.36.16: Feb 27, 2021 Query moved to module swad_timeline_database. (305317 lines) Version 20.36.15: Feb 27, 2021 Functions moved to module swad_timeline_database. (305305 lines) diff --git a/swad_timeline_database.c b/swad_timeline_database.c index e3a15461..c284f4e5 100644 --- a/swad_timeline_database.c +++ b/swad_timeline_database.c @@ -589,3 +589,37 @@ static long TL_DB_GetMedCodFromPub (long PubCod,const char *DBTable) return MedCod; } + +/*****************************************************************************/ +/************* Get last/first publication code stored in session *************/ +/*****************************************************************************/ +// FieldName can be: +// "LastPubCod" +// "FirstPubCod" + +long TL_DB_GetPubCodFromSession (const char *FieldName, + const char SessionId[Cns_BYTES_SESSION_ID + 1]) + { + MYSQL_RES *mysql_res; + MYSQL_ROW row; + long PubCod; + + /***** Get last publication code from database *****/ + if (DB_QuerySELECT (&mysql_res,"can not get publication code from session", + "SELECT %s FROM sessions" + " WHERE SessionId='%s'", + FieldName,SessionId) == 1) + { + /***** Get last publication code *****/ + row = mysql_fetch_row (mysql_res); + if (sscanf (row[0],"%ld",&PubCod) != 1) + PubCod = 0; + } + else + PubCod = 0; + + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); + + return PubCod; + } diff --git a/swad_timeline_database.h b/swad_timeline_database.h index 94507597..1e9b474a 100644 --- a/swad_timeline_database.h +++ b/swad_timeline_database.h @@ -90,4 +90,8 @@ void TL_DB_RemoveCommentFavs (long PubCod); void TL_DB_RemoveCommentContent (long PubCod); void TL_DB_RemoveCommentPub (long PubCod,long PublisherCod); +/* Publications */ +long TL_DB_GetPubCodFromSession (const char *FieldName, + const char SessionId[Cns_BYTES_SESSION_ID + 1]); + #endif diff --git a/swad_timeline_publication.c b/swad_timeline_publication.c index 8bf01fc0..2813a7aa 100644 --- a/swad_timeline_publication.c +++ b/swad_timeline_publication.c @@ -88,7 +88,6 @@ static void TL_Pub_CreateSubQueryRangeBottom (const struct TL_Pub_RangePubsToGet static void TL_Pub_CreateSubQueryRangeTop (const struct TL_Pub_RangePubsToGet *RangePubsToGet, struct TL_Pub_SubQueries *SubQueries); -static long TL_Pub_GetPubCodFromSession (const char *FieldName); static void TL_Pub_UpdateFirstLastPubCodesIntoSession (const struct TL_Timeline *Timeline); static struct TL_Pub_Publication *TL_Pub_SelectTheMostRecentPub (const struct TL_Pub_SubQueries *SubQueries); @@ -150,13 +149,13 @@ void TL_Pub_GetListPubsToShowInTimeline (struct TL_Timeline *Timeline) // newer than LastPubCod /* This query is made via AJAX automatically from time to time */ RangePubsToGet.Top = 0; // +Infinite - RangePubsToGet.Bottom = TL_Pub_GetPubCodFromSession ("LastPubCod"); + RangePubsToGet.Bottom = TL_DB_GetPubCodFromSession ("LastPubCod",Gbl.Session.Id); break; case TL_GET_ONLY_OLD_PUBS: // Get some limited publications // older than FirstPubCod /* This query is made via AJAX when I click in link to get old publications */ - RangePubsToGet.Top = TL_Pub_GetPubCodFromSession ("FirstPubCod"); + RangePubsToGet.Top = TL_DB_GetPubCodFromSession ("FirstPubCod",Gbl.Session.Id); RangePubsToGet.Bottom = 0; // -Infinite break; case TL_GET_RECENT_TIMELINE: // Get some limited recent publications @@ -363,38 +362,6 @@ static void TL_Pub_CreateSubQueryRangeTop (const struct TL_Pub_RangePubsToGet *R SubQueries->RangeTop[0] = '\0'; } -/*****************************************************************************/ -/************* Get last/first publication code stored in session *************/ -/*****************************************************************************/ -// FieldName can be: -// "LastPubCod" -// "FirstPubCod" - -static long TL_Pub_GetPubCodFromSession (const char *FieldName) - { - extern const char *Txt_The_session_has_expired; - MYSQL_RES *mysql_res; - MYSQL_ROW row; - long PubCod; - - /***** Get last publication code from database *****/ - if (DB_QuerySELECT (&mysql_res,"can not get publication code from session", - "SELECT %s FROM sessions" - " WHERE SessionId='%s'", - FieldName,Gbl.Session.Id) != 1) - Lay_ShowErrorAndExit (Txt_The_session_has_expired); - - /***** Get last publication code *****/ - row = mysql_fetch_row (mysql_res); - if (sscanf (row[0],"%ld",&PubCod) != 1) - PubCod = 0; - - /***** Free structure that stores the query result *****/ - DB_FreeMySQLResult (&mysql_res); - - return PubCod; - } - /*****************************************************************************/ /************* Update first (oldest) and last (more recent) ***************/ /************* publication codes into session for next refresh ***************/