mirror of
https://github.com/acanas/swad-core.git
synced 2024-06-10 10:45:23 +02:00
Version 21.35.1: Oct 18, 2021 Queries moved to module swad_file_database.
This commit is contained in:
parent
0f8f8fc396
commit
aa77769927
|
@ -602,13 +602,14 @@ TODO: FIX BUG, URGENT! En las fechas como par
|
|||
|
||||
TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo.
|
||||
*/
|
||||
#define Log_PLATFORM_VERSION "SWAD 21.35 (2021-10-18)"
|
||||
#define Log_PLATFORM_VERSION "SWAD 21.35.1 (2021-10-18)"
|
||||
#define CSS_FILE "swad20.45.css"
|
||||
#define JS_FILE "swad20.69.1.js"
|
||||
/*
|
||||
TODO: Rename CENTRE to CENTER in help wiki.
|
||||
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
|
||||
|
||||
Version 21.35.1: Oct 18, 2021 Queries moved to module swad_file_database. (320175 lines)
|
||||
Version 21.35: Oct 18, 2021 New module swad_file_database for database queries related to files. (320171 lines)
|
||||
Version 21.34: Oct 15, 2021 New module swad_session_database for database queries related to sessions. (320081 lines)
|
||||
Version 21.33.2: Oct 15, 2021 Fixed bug getting name of degree. (319950 lines)
|
||||
|
|
|
@ -51,6 +51,7 @@
|
|||
#include "swad_project.h"
|
||||
#include "swad_role.h"
|
||||
#include "swad_room.h"
|
||||
#include "swad_session_database.h"
|
||||
#include "swad_setting.h"
|
||||
#include "swad_statistic.h"
|
||||
#include "swad_theme.h"
|
||||
|
@ -357,7 +358,7 @@ void Gbl_Cleanup (void)
|
|||
if (!Gbl.Action.UsesAJAX &&
|
||||
!Gbl.WebService.IsWebService &&
|
||||
Act_GetBrowserTab (Gbl.Action.Act) == Act_BRW_1ST_TAB)
|
||||
Ses_RemoveParamFromThisSession ();
|
||||
Ses_DB_RemoveParam ();
|
||||
Usr_FreeMyCourses ();
|
||||
Usr_FreeMyDegrees ();
|
||||
Usr_FreeMyCenters ();
|
||||
|
|
|
@ -56,8 +56,6 @@ extern struct Globals Gbl;
|
|||
|
||||
static void Ses_RemoveSessionFromDB (void);
|
||||
|
||||
static bool Ses_CheckIfParamIsAlreadyInDB (const char *ParamName);
|
||||
|
||||
/*****************************************************************************/
|
||||
/************************** Get number of open sessions **********************/
|
||||
/*****************************************************************************/
|
||||
|
@ -119,7 +117,7 @@ void Ses_CloseSession (void)
|
|||
Con_DB_RemoveOldConnected ();
|
||||
|
||||
/***** Remove unused data associated to expired sessions *****/
|
||||
Ses_RemoveParamsFromExpiredSessions ();
|
||||
Ses_DB_RemoveParamsFromExpiredSessions ();
|
||||
Fil_DB_RemovePublicDirsFromExpiredSessions ();
|
||||
|
||||
/***** Now, user is not logged in *****/
|
||||
|
@ -222,81 +220,16 @@ void Ses_InsertParamInDB (const char *ParamName,const char *ParamValue)
|
|||
{
|
||||
/***** Before of inserting the first session parameter passed to the next action,
|
||||
delete all the parameters coming from the previous action *****/
|
||||
Ses_RemoveParamFromThisSession ();
|
||||
Ses_DB_RemoveParam ();
|
||||
|
||||
/***** For a unique session-parameter,
|
||||
don't insert a parameter more than one time *****/
|
||||
if (ParamName)
|
||||
if (ParamName[0])
|
||||
if (!Ses_CheckIfParamIsAlreadyInDB (ParamName))
|
||||
if (!Ses_DB_CheckIfParamIsAlreadyStored (ParamName))
|
||||
{
|
||||
/***** Insert session parameter in the database *****/
|
||||
Ses_DB_InsertParam (ParamName,ParamValue);
|
||||
Gbl.Session.ParamsInsertedIntoDB = true;
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************ Remove session parameters of a session from database ***********/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Ses_RemoveParamFromThisSession (void)
|
||||
{
|
||||
if (Gbl.Session.IsOpen && // There is an open session
|
||||
!Gbl.Session.ParamsInsertedIntoDB) // No params just inserted
|
||||
/***** Remove session parameters of this session *****/
|
||||
DB_QueryDELETE ("can not remove session parameters of current session",
|
||||
"DELETE FROM ses_params"
|
||||
" WHERE SessionId='%s'",
|
||||
Gbl.Session.Id);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********* Remove expired hidden parameters (from expired sessions) **********/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Ses_RemoveParamsFromExpiredSessions (void)
|
||||
{
|
||||
/***** Remove session parameters from expired sessions *****/
|
||||
DB_QueryDELETE ("can not remove session parameters of expired sessions",
|
||||
"DELETE FROM ses_params"
|
||||
" WHERE SessionId NOT IN"
|
||||
" (SELECT SessionId"
|
||||
" FROM ses_sessions)");
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************** Check if a session parameter existed in database *************/
|
||||
/*****************************************************************************/
|
||||
// Return true if the parameter already existed in database
|
||||
|
||||
static bool Ses_CheckIfParamIsAlreadyInDB (const char *ParamName)
|
||||
{
|
||||
return (DB_QueryCOUNT ("can not check if a session parameter"
|
||||
" is already in database",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM ses_params"
|
||||
" WHERE SessionId='%s'"
|
||||
" AND ParamName='%s'",
|
||||
Gbl.Session.Id,
|
||||
ParamName) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************** Get session parameter from the database *******************/
|
||||
/*****************************************************************************/
|
||||
// StrSize is the size of the parameter value, not including the ending '\0'
|
||||
|
||||
void Ses_GetParamFromDB (const char *ParamName,char *ParamValue,size_t StrSize)
|
||||
{
|
||||
ParamValue[0] = '\0';
|
||||
if (Gbl.Session.IsOpen) // If the session is open, get parameter from DB
|
||||
/***** Get a session parameter from database *****/
|
||||
DB_QuerySELECTString (ParamValue,StrSize,"can not get a session parameter",
|
||||
"SELECT ParamValue" // row[0]
|
||||
" FROM ses_params"
|
||||
" WHERE SessionId='%s'"
|
||||
" AND ParamName='%s'",
|
||||
Gbl.Session.Id,
|
||||
ParamName);
|
||||
}
|
||||
|
|
|
@ -44,9 +44,7 @@ void Ses_CloseSession (void);
|
|||
|
||||
bool Ses_GetSessionData (void);
|
||||
|
||||
//---------------------------- Session parameters -----------------------------
|
||||
void Ses_InsertParamInDB (const char *ParamName,const char *ParamValue);
|
||||
void Ses_RemoveParamFromThisSession (void);
|
||||
void Ses_RemoveParamsFromExpiredSessions (void);
|
||||
void Ses_GetParamFromDB (const char *ParamName,char *ParamValue,size_t StrSize);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -279,3 +279,68 @@ void Ses_DB_InsertParam (const char *ParamName,const char *ParamValue)
|
|||
ParamValue ? ParamValue :
|
||||
"");
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************** Check if a session parameter existed in database *************/
|
||||
/*****************************************************************************/
|
||||
// Return true if the parameter already existed in database
|
||||
|
||||
bool Ses_DB_CheckIfParamIsAlreadyStored (const char *ParamName)
|
||||
{
|
||||
return (DB_QueryCOUNT ("can not check if a session parameter"
|
||||
" is already in database",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM ses_params"
|
||||
" WHERE SessionId='%s'"
|
||||
" AND ParamName='%s'",
|
||||
Gbl.Session.Id,
|
||||
ParamName) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************** Get session parameter from the database *******************/
|
||||
/*****************************************************************************/
|
||||
// StrSize is the size of the parameter value, not including the ending '\0'
|
||||
|
||||
void Ses_DB_GetParam (const char *ParamName,char *ParamValue,size_t StrSize)
|
||||
{
|
||||
ParamValue[0] = '\0';
|
||||
if (Gbl.Session.IsOpen) // If the session is open, get parameter from DB
|
||||
/***** Get a session parameter from database *****/
|
||||
DB_QuerySELECTString (ParamValue,StrSize,"can not get a session parameter",
|
||||
"SELECT ParamValue" // row[0]
|
||||
" FROM ses_params"
|
||||
" WHERE SessionId='%s'"
|
||||
" AND ParamName='%s'",
|
||||
Gbl.Session.Id,
|
||||
ParamName);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************ Remove session parameters of a session from database ***********/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Ses_DB_RemoveParam (void)
|
||||
{
|
||||
if (Gbl.Session.IsOpen && // There is an open session
|
||||
!Gbl.Session.ParamsInsertedIntoDB) // No params just inserted
|
||||
/***** Remove session parameters of this session *****/
|
||||
DB_QueryDELETE ("can not remove session parameters of current session",
|
||||
"DELETE FROM ses_params"
|
||||
" WHERE SessionId='%s'",
|
||||
Gbl.Session.Id);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********* Remove expired hidden parameters (from expired sessions) **********/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Ses_DB_RemoveParamsFromExpiredSessions (void)
|
||||
{
|
||||
/***** Remove session parameters from expired sessions *****/
|
||||
DB_QueryDELETE ("can not remove session parameters of expired sessions",
|
||||
"DELETE FROM ses_params"
|
||||
" WHERE SessionId NOT IN"
|
||||
" (SELECT SessionId"
|
||||
" FROM ses_sessions)");
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
/*****************************************************************************/
|
||||
/***************************** Public prototypes *****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
//---------------------------------- Sessions ---------------------------------
|
||||
void Ses_DB_InsertSession (void);
|
||||
void Ses_DB_UpdateSession (void);
|
||||
void Ses_DB_SaveLastSearchIntoSession (void);
|
||||
|
@ -53,7 +53,12 @@ void Ses_DB_RemoveUsrSessions (long UsrCod);
|
|||
void Ses_SB_RemoveCurrentSession (void);
|
||||
|
||||
//---------------------------- Session parameters -----------------------------
|
||||
|
||||
void Ses_DB_InsertParam (const char *ParamName,const char *ParamValue);
|
||||
|
||||
bool Ses_DB_CheckIfParamIsAlreadyStored (const char *ParamName);
|
||||
void Ses_DB_GetParam (const char *ParamName,char *ParamValue,size_t StrSize);
|
||||
|
||||
void Ses_DB_RemoveParam (void);
|
||||
void Ses_DB_RemoveParamsFromExpiredSessions (void);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -5923,7 +5923,7 @@ void Usr_GetListsSelectedEncryptedUsrsCods (struct SelectedUsrs *SelectedUsrs)
|
|||
Usr_AllocateListSelectedEncryptedUsrCods (SelectedUsrs,Rol_UNK);
|
||||
if (Gbl.Session.IsOpen) // If the session is open, get parameter from DB
|
||||
{
|
||||
Ses_GetParamFromDB (ParamName,SelectedUsrs->List[Rol_UNK],
|
||||
Ses_DB_GetParam (ParamName,SelectedUsrs->List[Rol_UNK],
|
||||
Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS);
|
||||
Str_ChangeFormat (Str_FROM_FORM,Str_TO_TEXT,SelectedUsrs->List[Rol_UNK],
|
||||
Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS,true);
|
||||
|
|
Loading…
Reference in New Issue
Block a user