mirror of
https://github.com/acanas/swad-core.git
synced 2024-06-16 13:44:06 +02:00
Version 18.8.9
This commit is contained in:
parent
ddb0259495
commit
187ac31346
|
@ -844,14 +844,11 @@ static void ID_RemoveUsrID (const struct UsrData *UsrDat,bool ItsMe)
|
||||||
|
|
||||||
static bool ID_CheckIfConfirmed (long UsrCod,const char *UsrID)
|
static bool ID_CheckIfConfirmed (long UsrCod,const char *UsrID)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Get if ID is confirmed from database *****/
|
/***** Get if ID is confirmed from database *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_IDs"
|
DB_BuildQuery ("SELECT COUNT(*) FROM usr_IDs"
|
||||||
" WHERE UsrCod=%ld AND UsrID='%s' AND Confirmed='Y'",
|
" WHERE UsrCod=%ld AND UsrID='%s' AND Confirmed='Y'",
|
||||||
UsrCod,UsrID) < 0)
|
UsrCod,UsrID);
|
||||||
Lay_NotEnoughMemoryExit ();
|
return (DB_QueryCOUNT_new ("can not check if ID is confirmed") != 0);
|
||||||
return (DB_QueryCOUNT_free (Query,"can not check if ID is confirmed") != 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
|
@ -355,10 +355,11 @@ En OpenSWAD:
|
||||||
ps2pdf source.ps destination.pdf
|
ps2pdf source.ps destination.pdf
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define Log_PLATFORM_VERSION "SWAD 18.8.8 (2018-10-26)"
|
#define Log_PLATFORM_VERSION "SWAD 18.8.9 (2018-10-26)"
|
||||||
#define CSS_FILE "swad18.4.css"
|
#define CSS_FILE "swad18.4.css"
|
||||||
#define JS_FILE "swad17.17.1.js"
|
#define JS_FILE "swad17.17.1.js"
|
||||||
/*
|
/*
|
||||||
|
Version 18.8.9: Oct 26, 2018 Some asprintf for database queries changed by internal function. (237082 lines)
|
||||||
Version 18.8.8: Oct 26, 2018 Some asprintf for database queries changed by internal function. (237154 lines)
|
Version 18.8.8: Oct 26, 2018 Some asprintf for database queries changed by internal function. (237154 lines)
|
||||||
Version 18.8.7: Oct 26, 2018 Some asprintf for database queries changed by internal function. (237172 lines)
|
Version 18.8.7: Oct 26, 2018 Some asprintf for database queries changed by internal function. (237172 lines)
|
||||||
Version 18.8.6: Oct 26, 2018 Some asprintf for database queries changed by internal function. (237407 lines)
|
Version 18.8.6: Oct 26, 2018 Some asprintf for database queries changed by internal function. (237407 lines)
|
||||||
|
|
|
@ -3228,6 +3228,23 @@ unsigned long DB_QueryCOUNT (const char *Query,const char *MsgError)
|
||||||
/******************** Make an INSERT query in database ***********************/
|
/******************** Make an INSERT query in database ***********************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void DB_QueryINSERT_new (const char *MsgError)
|
||||||
|
{
|
||||||
|
int Result;
|
||||||
|
|
||||||
|
/***** Check that query string pointer
|
||||||
|
does not point to an allocated string *****/
|
||||||
|
if (Gbl.DB.QueryPtr == NULL)
|
||||||
|
Lay_ShowErrorAndExit ("Wrong query string.");
|
||||||
|
|
||||||
|
/***** Query database and free query string pointer *****/
|
||||||
|
Result = mysql_query (&Gbl.mysql,Gbl.DB.QueryPtr); // Returns 0 on success
|
||||||
|
free ((void *) Gbl.DB.QueryPtr);
|
||||||
|
Gbl.DB.QueryPtr = NULL;
|
||||||
|
if (Result)
|
||||||
|
DB_ExitOnMySQLError (MsgError);
|
||||||
|
}
|
||||||
|
|
||||||
void DB_QueryINSERT_free (const char *Query,const char *MsgError)
|
void DB_QueryINSERT_free (const char *Query,const char *MsgError)
|
||||||
{
|
{
|
||||||
int Result;
|
int Result;
|
||||||
|
@ -3250,6 +3267,26 @@ void DB_QueryINSERT (const char *Query,const char *MsgError)
|
||||||
/** Make an INSERT query in database and return code of last inserted item ***/
|
/** Make an INSERT query in database and return code of last inserted item ***/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
long DB_QueryINSERTandReturnCode_new (const char *MsgError)
|
||||||
|
{
|
||||||
|
int Result;
|
||||||
|
|
||||||
|
/***** Check that query string pointer
|
||||||
|
does not point to an allocated string *****/
|
||||||
|
if (Gbl.DB.QueryPtr == NULL)
|
||||||
|
Lay_ShowErrorAndExit ("Wrong query string.");
|
||||||
|
|
||||||
|
/***** Query database and free query string pointer *****/
|
||||||
|
Result = mysql_query (&Gbl.mysql,Gbl.DB.QueryPtr); // Returns 0 on success
|
||||||
|
free ((void *) Gbl.DB.QueryPtr);
|
||||||
|
Gbl.DB.QueryPtr = NULL;
|
||||||
|
if (Result)
|
||||||
|
DB_ExitOnMySQLError (MsgError);
|
||||||
|
|
||||||
|
/***** Return the code of the inserted item *****/
|
||||||
|
return (long) mysql_insert_id (&Gbl.mysql);
|
||||||
|
}
|
||||||
|
|
||||||
long DB_QueryINSERTandReturnCode_free (const char *Query,const char *MsgError)
|
long DB_QueryINSERTandReturnCode_free (const char *Query,const char *MsgError)
|
||||||
{
|
{
|
||||||
int Result;
|
int Result;
|
||||||
|
@ -3278,6 +3315,23 @@ long DB_QueryINSERTandReturnCode (const char *Query,const char *MsgError)
|
||||||
/******************** Make an REPLACE query in database **********************/
|
/******************** Make an REPLACE query in database **********************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void DB_QueryREPLACE_new (const char *MsgError)
|
||||||
|
{
|
||||||
|
int Result;
|
||||||
|
|
||||||
|
/***** Check that query string pointer
|
||||||
|
does not point to an allocated string *****/
|
||||||
|
if (Gbl.DB.QueryPtr == NULL)
|
||||||
|
Lay_ShowErrorAndExit ("Wrong query string.");
|
||||||
|
|
||||||
|
/***** Query database and free query string pointer *****/
|
||||||
|
Result = mysql_query (&Gbl.mysql,Gbl.DB.QueryPtr); // Returns 0 on success
|
||||||
|
free ((void *) Gbl.DB.QueryPtr);
|
||||||
|
Gbl.DB.QueryPtr = NULL;
|
||||||
|
if (Result)
|
||||||
|
DB_ExitOnMySQLError (MsgError);
|
||||||
|
}
|
||||||
|
|
||||||
void DB_QueryREPLACE_free (const char *Query,const char *MsgError)
|
void DB_QueryREPLACE_free (const char *Query,const char *MsgError)
|
||||||
{
|
{
|
||||||
int Result;
|
int Result;
|
||||||
|
@ -3300,6 +3354,26 @@ void DB_QueryREPLACE (const char *Query,const char *MsgError)
|
||||||
/******************** Make a UPDATE query from database **********************/
|
/******************** Make a UPDATE query from database **********************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void DB_QueryUPDATE_new (const char *MsgError)
|
||||||
|
{
|
||||||
|
int Result;
|
||||||
|
|
||||||
|
/***** Check that query string pointer
|
||||||
|
does not point to an allocated string *****/
|
||||||
|
if (Gbl.DB.QueryPtr == NULL)
|
||||||
|
Lay_ShowErrorAndExit ("Wrong query string.");
|
||||||
|
|
||||||
|
/***** Query database and free query string pointer *****/
|
||||||
|
Result = mysql_query (&Gbl.mysql,Gbl.DB.QueryPtr); // Returns 0 on success
|
||||||
|
free ((void *) Gbl.DB.QueryPtr);
|
||||||
|
Gbl.DB.QueryPtr = NULL;
|
||||||
|
if (Result)
|
||||||
|
DB_ExitOnMySQLError (MsgError);
|
||||||
|
|
||||||
|
/***** Return number of rows updated *****/
|
||||||
|
//return (unsigned long) mysql_affected_rows (&Gbl.mysql);
|
||||||
|
}
|
||||||
|
|
||||||
void DB_QueryUPDATE_free (const char *Query,const char *MsgError)
|
void DB_QueryUPDATE_free (const char *Query,const char *MsgError)
|
||||||
{
|
{
|
||||||
int Result;
|
int Result;
|
||||||
|
@ -3328,6 +3402,23 @@ void DB_QueryUPDATE (const char *Query,const char *MsgError)
|
||||||
/******************** Make a DELETE query from database **********************/
|
/******************** Make a DELETE query from database **********************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void DB_QueryDELETE_new (const char *MsgError)
|
||||||
|
{
|
||||||
|
int Result;
|
||||||
|
|
||||||
|
/***** Check that query string pointer
|
||||||
|
does not point to an allocated string *****/
|
||||||
|
if (Gbl.DB.QueryPtr == NULL)
|
||||||
|
Lay_ShowErrorAndExit ("Wrong query string.");
|
||||||
|
|
||||||
|
/***** Query database and free query string pointer *****/
|
||||||
|
Result = mysql_query (&Gbl.mysql,Gbl.DB.QueryPtr); // Returns 0 on success
|
||||||
|
free ((void *) Gbl.DB.QueryPtr);
|
||||||
|
Gbl.DB.QueryPtr = NULL;
|
||||||
|
if (Result)
|
||||||
|
DB_ExitOnMySQLError (MsgError);
|
||||||
|
}
|
||||||
|
|
||||||
void DB_QueryDELETE_free (const char *Query,const char *MsgError)
|
void DB_QueryDELETE_free (const char *Query,const char *MsgError)
|
||||||
{
|
{
|
||||||
int Result;
|
int Result;
|
||||||
|
|
|
@ -47,18 +47,23 @@ unsigned long DB_QueryCOUNT_new (const char *MsgError);
|
||||||
unsigned long DB_QueryCOUNT_free (const char *Query,const char *MsgError);
|
unsigned long DB_QueryCOUNT_free (const char *Query,const char *MsgError);
|
||||||
unsigned long DB_QueryCOUNT (const char *Query,const char *MsgError);
|
unsigned long DB_QueryCOUNT (const char *Query,const char *MsgError);
|
||||||
|
|
||||||
|
void DB_QueryINSERT_new (const char *MsgError);
|
||||||
void DB_QueryINSERT_free (const char *Query,const char *MsgError);
|
void DB_QueryINSERT_free (const char *Query,const char *MsgError);
|
||||||
void DB_QueryINSERT (const char *Query,const char *MsgError);
|
void DB_QueryINSERT (const char *Query,const char *MsgError);
|
||||||
|
|
||||||
|
long DB_QueryINSERTandReturnCode_new (const char *MsgError);
|
||||||
long DB_QueryINSERTandReturnCode_free (const char *Query,const char *MsgError);
|
long DB_QueryINSERTandReturnCode_free (const char *Query,const char *MsgError);
|
||||||
long DB_QueryINSERTandReturnCode (const char *Query,const char *MsgError);
|
long DB_QueryINSERTandReturnCode (const char *Query,const char *MsgError);
|
||||||
|
|
||||||
|
void DB_QueryREPLACE_new (const char *MsgError);
|
||||||
void DB_QueryREPLACE_free (const char *Query,const char *MsgError);
|
void DB_QueryREPLACE_free (const char *Query,const char *MsgError);
|
||||||
void DB_QueryREPLACE (const char *Query,const char *MsgError);
|
void DB_QueryREPLACE (const char *Query,const char *MsgError);
|
||||||
|
|
||||||
|
void DB_QueryUPDATE_new (const char *MsgError);
|
||||||
void DB_QueryUPDATE_free (const char *Query,const char *MsgError);
|
void DB_QueryUPDATE_free (const char *Query,const char *MsgError);
|
||||||
void DB_QueryUPDATE (const char *Query,const char *MsgError);
|
void DB_QueryUPDATE (const char *Query,const char *MsgError);
|
||||||
|
|
||||||
|
void DB_QueryDELETE_new (const char *MsgError);
|
||||||
void DB_QueryDELETE_free (const char *Query,const char *MsgError);
|
void DB_QueryDELETE_free (const char *Query,const char *MsgError);
|
||||||
void DB_QueryDELETE (const char *Query,const char *MsgError);
|
void DB_QueryDELETE (const char *Query,const char *MsgError);
|
||||||
|
|
||||||
|
|
18
swad_group.c
18
swad_group.c
|
@ -3797,15 +3797,12 @@ void Grp_RecFormNewGrp (void)
|
||||||
|
|
||||||
static bool Grp_CheckIfGroupTypeNameExists (const char *GrpTypName,long GrpTypCod)
|
static bool Grp_CheckIfGroupTypeNameExists (const char *GrpTypName,long GrpTypCod)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Get number of group types with a name from database *****/
|
/***** Get number of group types with a name from database *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM crs_grp_types"
|
DB_BuildQuery ("SELECT COUNT(*) FROM crs_grp_types"
|
||||||
" WHERE CrsCod=%ld AND GrpTypName='%s'"
|
" WHERE CrsCod=%ld AND GrpTypName='%s'"
|
||||||
" AND GrpTypCod<>%ld",
|
" AND GrpTypCod<>%ld",
|
||||||
Gbl.CurrentCrs.Crs.CrsCod,GrpTypName,GrpTypCod) < 0)
|
Gbl.CurrentCrs.Crs.CrsCod,GrpTypName,GrpTypCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
return (DB_QueryCOUNT_new ("can not check if the name of type of group already existed") != 0);
|
||||||
return (DB_QueryCOUNT_free (Query,"can not check if the name of type of group already existed") != 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -3814,14 +3811,11 @@ static bool Grp_CheckIfGroupTypeNameExists (const char *GrpTypName,long GrpTypCo
|
||||||
|
|
||||||
static bool Grp_CheckIfGroupNameExists (long GrpTypCod,const char *GrpName,long GrpCod)
|
static bool Grp_CheckIfGroupNameExists (long GrpTypCod,const char *GrpName,long GrpCod)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Get number of groups with a type and a name from database *****/
|
/***** Get number of groups with a type and a name from database *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM crs_grp"
|
DB_BuildQuery ("SELECT COUNT(*) FROM crs_grp"
|
||||||
" WHERE GrpTypCod=%ld AND GrpName='%s' AND GrpCod<>%ld",
|
" WHERE GrpTypCod=%ld AND GrpName='%s' AND GrpCod<>%ld",
|
||||||
GrpTypCod,GrpName,GrpCod) < 0)
|
GrpTypCod,GrpName,GrpCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
return (DB_QueryCOUNT_new ("can not check if the name of group already existed") != 0);
|
||||||
return (DB_QueryCOUNT_free (Query,"can not check if the name of group already existed") != 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
|
@ -522,16 +522,13 @@ static void Inf_PutCheckboxConfirmIHaveReadInfo (void)
|
||||||
|
|
||||||
static bool Inf_CheckIfIHaveReadInfo (void)
|
static bool Inf_CheckIfIHaveReadInfo (void)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Get if info source is already stored in database *****/
|
/***** Get if info source is already stored in database *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM crs_info_read"
|
DB_BuildQuery ("SELECT COUNT(*) FROM crs_info_read"
|
||||||
" WHERE UsrCod=%ld AND CrsCod=%ld AND InfoType='%s'",
|
" WHERE UsrCod=%ld AND CrsCod=%ld AND InfoType='%s'",
|
||||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||||
Gbl.CurrentCrs.Crs.CrsCod,
|
Gbl.CurrentCrs.Crs.CrsCod,
|
||||||
Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type]) < 0)
|
Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type]);
|
||||||
Lay_NotEnoughMemoryExit ();
|
return (DB_QueryCOUNT_new ("can not get if I have read course info") != 0);
|
||||||
return (DB_QueryCOUNT_free (Query,"can not get if I have read course info") != 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
|
@ -1863,14 +1863,11 @@ static void Ins_RenameInstitution (struct Instit *Ins,Cns_ShrtOrFullName_t ShrtO
|
||||||
|
|
||||||
static bool Ins_CheckIfInsNameExistsInCty (const char *FieldName,const char *Name,long InsCod,long CtyCod)
|
static bool Ins_CheckIfInsNameExistsInCty (const char *FieldName,const char *Name,long InsCod,long CtyCod)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Get number of institutions in current country with a name from database *****/
|
/***** Get number of institutions in current country with a name from database *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM institutions"
|
DB_BuildQuery ("SELECT COUNT(*) FROM institutions"
|
||||||
" WHERE CtyCod=%ld AND %s='%s' AND InsCod<>%ld",
|
" WHERE CtyCod=%ld AND %s='%s' AND InsCod<>%ld",
|
||||||
CtyCod,FieldName,Name,InsCod) < 0)
|
CtyCod,FieldName,Name,InsCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
return (DB_QueryCOUNT_new ("can not check if the name of an institution already existed") != 0);
|
||||||
return (DB_QueryCOUNT_free (Query,"can not check if the name of an institution already existed") != 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -2447,12 +2444,9 @@ static void Ins_CreateInstitution (unsigned Status)
|
||||||
|
|
||||||
unsigned Ins_GetNumInssTotal (void)
|
unsigned Ins_GetNumInssTotal (void)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Get total number of degrees from database *****/
|
/***** Get total number of degrees from database *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM institutions") < 0)
|
DB_BuildQuery ("SELECT COUNT(*) FROM institutions");
|
||||||
Lay_NotEnoughMemoryExit ();
|
return (unsigned) DB_QueryCOUNT_new ("can not get the total number of institutions");
|
||||||
return (unsigned) DB_QueryCOUNT_free (Query,"can not get the total number of institutions");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -2461,13 +2455,9 @@ unsigned Ins_GetNumInssTotal (void)
|
||||||
|
|
||||||
unsigned Ins_GetNumInssInCty (long CtyCod)
|
unsigned Ins_GetNumInssInCty (long CtyCod)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Get number of degrees of a place from database *****/
|
/***** Get number of degrees of a place from database *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM institutions WHERE CtyCod=%ld",
|
DB_BuildQuery ("SELECT COUNT(*) FROM institutions WHERE CtyCod=%ld",CtyCod);
|
||||||
CtyCod) < 0)
|
return (unsigned) DB_QueryCOUNT_new ("can not get the number of institutions in a country");
|
||||||
Lay_NotEnoughMemoryExit ();
|
|
||||||
return (unsigned) DB_QueryCOUNT_free (Query,"can not get the number of institutions in a country");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -2476,15 +2466,12 @@ unsigned Ins_GetNumInssInCty (long CtyCod)
|
||||||
|
|
||||||
unsigned Ins_GetNumInssWithCtrs (const char *SubQuery)
|
unsigned Ins_GetNumInssWithCtrs (const char *SubQuery)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Get number of institutions with centres from database *****/
|
/***** Get number of institutions with centres from database *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(DISTINCT institutions.InsCod)"
|
DB_BuildQuery ("SELECT COUNT(DISTINCT institutions.InsCod)"
|
||||||
" FROM institutions,centres"
|
" FROM institutions,centres"
|
||||||
" WHERE %sinstitutions.InsCod=centres.InsCod",
|
" WHERE %sinstitutions.InsCod=centres.InsCod",
|
||||||
SubQuery) < 0)
|
SubQuery);
|
||||||
Lay_NotEnoughMemoryExit ();
|
return (unsigned) DB_QueryCOUNT_new ("can not get number of institutions with centres");
|
||||||
return (unsigned) DB_QueryCOUNT_free (Query,"can not get number of institutions with centres");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -2493,16 +2480,13 @@ unsigned Ins_GetNumInssWithCtrs (const char *SubQuery)
|
||||||
|
|
||||||
unsigned Ins_GetNumInssWithDegs (const char *SubQuery)
|
unsigned Ins_GetNumInssWithDegs (const char *SubQuery)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Get number of institutions with degrees from database *****/
|
/***** Get number of institutions with degrees from database *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(DISTINCT institutions.InsCod)"
|
DB_BuildQuery ("SELECT COUNT(DISTINCT institutions.InsCod)"
|
||||||
" FROM institutions,centres,degrees"
|
" FROM institutions,centres,degrees"
|
||||||
" WHERE %sinstitutions.InsCod=centres.InsCod"
|
" WHERE %sinstitutions.InsCod=centres.InsCod"
|
||||||
" AND centres.CtrCod=degrees.CtrCod",
|
" AND centres.CtrCod=degrees.CtrCod",
|
||||||
SubQuery) < 0)
|
SubQuery);
|
||||||
Lay_NotEnoughMemoryExit ();
|
return (unsigned) DB_QueryCOUNT_new ("can not get number of institutions with degrees");
|
||||||
return (unsigned) DB_QueryCOUNT_free (Query,"can not get number of institutions with degrees");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -2511,17 +2495,14 @@ unsigned Ins_GetNumInssWithDegs (const char *SubQuery)
|
||||||
|
|
||||||
unsigned Ins_GetNumInssWithCrss (const char *SubQuery)
|
unsigned Ins_GetNumInssWithCrss (const char *SubQuery)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Get number of institutions with courses from database *****/
|
/***** Get number of institutions with courses from database *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(DISTINCT institutions.InsCod)"
|
DB_BuildQuery ("SELECT COUNT(DISTINCT institutions.InsCod)"
|
||||||
" FROM institutions,centres,degrees,courses"
|
" FROM institutions,centres,degrees,courses"
|
||||||
" WHERE %sinstitutions.InsCod=centres.InsCod"
|
" WHERE %sinstitutions.InsCod=centres.InsCod"
|
||||||
" AND centres.CtrCod=degrees.CtrCod"
|
" AND centres.CtrCod=degrees.CtrCod"
|
||||||
" AND degrees.DegCod=courses.DegCod",
|
" AND degrees.DegCod=courses.DegCod",
|
||||||
SubQuery) < 0)
|
SubQuery);
|
||||||
Lay_NotEnoughMemoryExit ();
|
return (unsigned) DB_QueryCOUNT_new ("can not get number of institutions with courses");
|
||||||
return (unsigned) DB_QueryCOUNT_free (Query,"can not get number of institutions with courses");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -2530,19 +2511,16 @@ unsigned Ins_GetNumInssWithCrss (const char *SubQuery)
|
||||||
|
|
||||||
unsigned Ins_GetNumInssWithUsrs (Rol_Role_t Role,const char *SubQuery)
|
unsigned Ins_GetNumInssWithUsrs (Rol_Role_t Role,const char *SubQuery)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Get number of institutions with users from database *****/
|
/***** Get number of institutions with users from database *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(DISTINCT institutions.InsCod)"
|
DB_BuildQuery ("SELECT COUNT(DISTINCT institutions.InsCod)"
|
||||||
" FROM institutions,centres,degrees,courses,crs_usr"
|
" FROM institutions,centres,degrees,courses,crs_usr"
|
||||||
" WHERE %sinstitutions.InsCod=centres.InsCod"
|
" WHERE %sinstitutions.InsCod=centres.InsCod"
|
||||||
" AND centres.CtrCod=degrees.CtrCod"
|
" AND centres.CtrCod=degrees.CtrCod"
|
||||||
" AND degrees.DegCod=courses.DegCod"
|
" AND degrees.DegCod=courses.DegCod"
|
||||||
" AND courses.CrsCod=crs_usr.CrsCod"
|
" AND courses.CrsCod=crs_usr.CrsCod"
|
||||||
" AND crs_usr.Role=%u",
|
" AND crs_usr.Role=%u",
|
||||||
SubQuery,(unsigned) Role) < 0)
|
SubQuery,(unsigned) Role);
|
||||||
Lay_NotEnoughMemoryExit ();
|
return (unsigned) DB_QueryCOUNT_new ("can not get number of institutions with users");
|
||||||
return (unsigned) DB_QueryCOUNT_free (Query,"can not get number of institutions with users");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
|
@ -630,13 +630,10 @@ static void Lnk_RenameLink (Cns_ShrtOrFullName_t ShrtOrFullName)
|
||||||
|
|
||||||
static bool Lnk_CheckIfLinkNameExists (const char *FieldName,const char *Name,long LnkCod)
|
static bool Lnk_CheckIfLinkNameExists (const char *FieldName,const char *Name,long LnkCod)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Get number of links with a name from database *****/
|
/***** Get number of links with a name from database *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM links WHERE %s='%s' AND LnkCod<>%ld",
|
DB_BuildQuery ("SELECT COUNT(*) FROM links WHERE %s='%s' AND LnkCod<>%ld",
|
||||||
FieldName,Name,LnkCod) < 0)
|
FieldName,Name,LnkCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
return (DB_QueryCOUNT_new ("can not check if the name of an institutional link already existed") != 0);
|
||||||
return (DB_QueryCOUNT_free (Query,"can not check if the name of an institutional link already existed") != 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
25
swad_mail.c
25
swad_mail.c
|
@ -357,13 +357,10 @@ static void Mai_GetMailDomain (const char *Email,char MailDomain[Cns_MAX_BYTES_E
|
||||||
|
|
||||||
static bool Mai_CheckIfMailDomainIsAllowedForNotif (const char MailDomain[Cns_MAX_BYTES_EMAIL_ADDRESS + 1])
|
static bool Mai_CheckIfMailDomainIsAllowedForNotif (const char MailDomain[Cns_MAX_BYTES_EMAIL_ADDRESS + 1])
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Get number of mail_domains with a name from database *****/
|
/***** Get number of mail_domains with a name from database *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM mail_domains WHERE Domain='%s'",
|
DB_BuildQuery ("SELECT COUNT(*) FROM mail_domains WHERE Domain='%s'",
|
||||||
MailDomain) < 0)
|
MailDomain);
|
||||||
Lay_NotEnoughMemoryExit ();
|
return (DB_QueryCOUNT_new ("can not check if a mail domain is allowed for notifications") != 0);
|
||||||
return (DB_QueryCOUNT_free (Query,"can not check if a mail domain is allowed for notifications") != 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -693,14 +690,11 @@ static void Mai_RenameMailDomain (Cns_ShrtOrFullName_t ShrtOrFullName)
|
||||||
|
|
||||||
static bool Mai_CheckIfMailDomainNameExists (const char *FieldName,const char *Name,long MaiCod)
|
static bool Mai_CheckIfMailDomainNameExists (const char *FieldName,const char *Name,long MaiCod)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Get number of mail_domains with a name from database *****/
|
/***** Get number of mail_domains with a name from database *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM mail_domains"
|
DB_BuildQuery ("SELECT COUNT(*) FROM mail_domains"
|
||||||
" WHERE %s='%s' AND MaiCod<>%ld",
|
" WHERE %s='%s' AND MaiCod<>%ld",
|
||||||
FieldName,Name,MaiCod) < 0)
|
FieldName,Name,MaiCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
return (DB_QueryCOUNT_new ("can not check if the name of a mail domain already existed") != 0);
|
||||||
return (DB_QueryCOUNT_free (Query,"can not check if the name of a mail domain already existed") != 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -1639,12 +1633,11 @@ bool Mai_UpdateEmailInDB (const struct UsrData *UsrDat,const char NewEmail[Cns_M
|
||||||
char *Query;
|
char *Query;
|
||||||
|
|
||||||
/***** Check if the new email matches any of the confirmed emails of other users *****/
|
/***** Check if the new email matches any of the confirmed emails of other users *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_emails"
|
DB_BuildQuery ("SELECT COUNT(*) FROM usr_emails"
|
||||||
" WHERE E_mail='%s' AND Confirmed='Y'"
|
" WHERE E_mail='%s' AND Confirmed='Y'"
|
||||||
" AND UsrCod<>%ld",
|
" AND UsrCod<>%ld",
|
||||||
NewEmail,UsrDat->UsrCod) < 0)
|
NewEmail,UsrDat->UsrCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
if (DB_QueryCOUNT_new ("can not check if email already existed")) // An email of another user is the same that my email
|
||||||
if (DB_QueryCOUNT_free (Query,"can not check if email already existed")) // An email of another user is the same that my email
|
|
||||||
return false; // Don't update
|
return false; // Don't update
|
||||||
|
|
||||||
/***** Delete email (not confirmed) for other users *****/
|
/***** Delete email (not confirmed) for other users *****/
|
||||||
|
|
380
swad_message.c
380
swad_message.c
|
@ -25,10 +25,8 @@
|
||||||
/********************************* Headers ***********************************/
|
/********************************* Headers ***********************************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
#define _GNU_SOURCE // For asprintf
|
|
||||||
#include <linux/limits.h> // For PATH_MAX
|
#include <linux/limits.h> // For PATH_MAX
|
||||||
#include <linux/stddef.h> // For NULL
|
#include <linux/stddef.h> // For NULL
|
||||||
#include <stdio.h> // For asprintf
|
|
||||||
#include <stdlib.h> // For free
|
#include <stdlib.h> // For free
|
||||||
#include <string.h> // For string functions
|
#include <string.h> // For string functions
|
||||||
#include <time.h> // For time
|
#include <time.h> // For time
|
||||||
|
@ -1225,21 +1223,17 @@ void Msg_ConRecMsg (void)
|
||||||
|
|
||||||
static void Msg_ExpandSentMsg (long MsgCod)
|
static void Msg_ExpandSentMsg (long MsgCod)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Expand message in sent message table *****/
|
/***** Expand message in sent message table *****/
|
||||||
if (asprintf (&Query,"UPDATE msg_snt SET Expanded='Y'"
|
DB_BuildQuery ("UPDATE msg_snt SET Expanded='Y'"
|
||||||
" WHERE MsgCod=%ld AND UsrCod=%ld",
|
" WHERE MsgCod=%ld AND UsrCod=%ld",
|
||||||
MsgCod,Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
|
MsgCod,Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
DB_QueryUPDATE_new ("can not expand a sent message");
|
||||||
DB_QueryUPDATE_free (Query,"can not expand a sent message");
|
|
||||||
|
|
||||||
/***** Contract all my other messages in sent message table *****/
|
/***** Contract all my other messages in sent message table *****/
|
||||||
if (asprintf (&Query,"UPDATE msg_snt SET Expanded='N'"
|
DB_BuildQuery ("UPDATE msg_snt SET Expanded='N'"
|
||||||
" WHERE UsrCod=%ld AND MsgCod<>%ld",
|
" WHERE UsrCod=%ld AND MsgCod<>%ld",
|
||||||
Gbl.Usrs.Me.UsrDat.UsrCod,MsgCod) < 0)
|
Gbl.Usrs.Me.UsrDat.UsrCod,MsgCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
DB_QueryUPDATE_new ("can not contract a sent message");
|
||||||
DB_QueryUPDATE (Query,"can not contract a sent message");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -1248,21 +1242,17 @@ static void Msg_ExpandSentMsg (long MsgCod)
|
||||||
|
|
||||||
static void Msg_ExpandReceivedMsg (long MsgCod)
|
static void Msg_ExpandReceivedMsg (long MsgCod)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Expand message in received message table and mark it as read by me *****/
|
/***** Expand message in received message table and mark it as read by me *****/
|
||||||
if (asprintf (&Query,"UPDATE msg_rcv SET Open='Y',Expanded='Y'"
|
DB_BuildQuery ("UPDATE msg_rcv SET Open='Y',Expanded='Y'"
|
||||||
" WHERE MsgCod=%ld AND UsrCod=%ld",
|
" WHERE MsgCod=%ld AND UsrCod=%ld",
|
||||||
MsgCod,Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
|
MsgCod,Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
DB_QueryUPDATE_new ("can not expand a received message");
|
||||||
DB_QueryUPDATE_free (Query,"can not expand a received message");
|
|
||||||
|
|
||||||
/***** Contract all my other messages in received message table *****/
|
/***** Contract all my other messages in received message table *****/
|
||||||
if (asprintf (&Query,"UPDATE msg_rcv SET Expanded='N'"
|
DB_BuildQuery ("UPDATE msg_rcv SET Expanded='N'"
|
||||||
" WHERE UsrCod=%ld AND MsgCod<>%ld",
|
" WHERE UsrCod=%ld AND MsgCod<>%ld",
|
||||||
Gbl.Usrs.Me.UsrDat.UsrCod,MsgCod) < 0)
|
Gbl.Usrs.Me.UsrDat.UsrCod,MsgCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
DB_QueryUPDATE_new ("can not contract a received message");
|
||||||
DB_QueryUPDATE_free (Query,"can not contract a received message");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -1271,14 +1261,11 @@ static void Msg_ExpandReceivedMsg (long MsgCod)
|
||||||
|
|
||||||
static void Msg_ContractSentMsg (long MsgCod)
|
static void Msg_ContractSentMsg (long MsgCod)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Contract message in sent message table *****/
|
/***** Contract message in sent message table *****/
|
||||||
if (asprintf (&Query,"UPDATE msg_snt SET Expanded='N'"
|
DB_BuildQuery ("UPDATE msg_snt SET Expanded='N'"
|
||||||
" WHERE MsgCod=%ld AND UsrCod=%ld",
|
" WHERE MsgCod=%ld AND UsrCod=%ld",
|
||||||
MsgCod,Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
|
MsgCod,Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
DB_QueryUPDATE_new ("can not contract a sent message");
|
||||||
DB_QueryUPDATE_free (Query,"can not contract a sent message");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -1287,14 +1274,11 @@ static void Msg_ContractSentMsg (long MsgCod)
|
||||||
|
|
||||||
static void Msg_ContractReceivedMsg (long MsgCod)
|
static void Msg_ContractReceivedMsg (long MsgCod)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Contract message in received message table *****/
|
/***** Contract message in received message table *****/
|
||||||
if (asprintf (&Query,"UPDATE msg_rcv SET Expanded='N'"
|
DB_BuildQuery ("UPDATE msg_rcv SET Expanded='N'"
|
||||||
" WHERE MsgCod=%ld AND UsrCod=%ld",
|
" WHERE MsgCod=%ld AND UsrCod=%ld",
|
||||||
MsgCod,Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
|
MsgCod,Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
DB_QueryUPDATE_new ("can not contract a received message");
|
||||||
DB_QueryUPDATE_free (Query,"can not contract a received message");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -1303,14 +1287,11 @@ static void Msg_ContractReceivedMsg (long MsgCod)
|
||||||
|
|
||||||
void Msg_SetReceivedMsgAsOpen (long MsgCod,long UsrCod)
|
void Msg_SetReceivedMsgAsOpen (long MsgCod,long UsrCod)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Mark message as read by user *****/
|
/***** Mark message as read by user *****/
|
||||||
if (asprintf (&Query,"UPDATE msg_rcv SET Open='Y'"
|
DB_BuildQuery ("UPDATE msg_rcv SET Open='Y'"
|
||||||
" WHERE MsgCod=%ld AND UsrCod=%ld",
|
" WHERE MsgCod=%ld AND UsrCod=%ld",
|
||||||
MsgCod,UsrCod) < 0)
|
MsgCod,UsrCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
DB_QueryUPDATE_new ("can not mark a received message as open");
|
||||||
DB_QueryUPDATE_free (Query,"can not mark a received message as open");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -1321,7 +1302,6 @@ void Msg_SetReceivedMsgAsOpen (long MsgCod,long UsrCod)
|
||||||
static long Msg_InsertNewMsg (const char *Subject,const char *Content,
|
static long Msg_InsertNewMsg (const char *Subject,const char *Content,
|
||||||
struct Image *Image)
|
struct Image *Image)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
long MsgCod;
|
long MsgCod;
|
||||||
|
|
||||||
/***** Check if image is received and processed *****/
|
/***** Check if image is received and processed *****/
|
||||||
|
@ -1331,27 +1311,25 @@ static long Msg_InsertNewMsg (const char *Subject,const char *Content,
|
||||||
Img_MoveImageToDefinitiveDirectory (Image);
|
Img_MoveImageToDefinitiveDirectory (Image);
|
||||||
|
|
||||||
/***** Insert message subject and content in the database *****/
|
/***** Insert message subject and content in the database *****/
|
||||||
if (asprintf (&Query,"INSERT INTO msg_content"
|
DB_BuildQuery ("INSERT INTO msg_content"
|
||||||
" (Subject,Content,ImageName,ImageTitle,ImageURL)"
|
" (Subject,Content,ImageName,ImageTitle,ImageURL)"
|
||||||
" VALUES"
|
" VALUES"
|
||||||
" ('%s','%s','%s','%s','%s')",
|
" ('%s','%s','%s','%s','%s')",
|
||||||
Subject,Content,
|
Subject,Content,
|
||||||
Image->Name,
|
Image->Name,
|
||||||
Image->Title ? Image->Title : "",
|
Image->Title ? Image->Title : "",
|
||||||
Image->URL ? Image->URL : "") < 0)
|
Image->URL ? Image->URL : "");
|
||||||
Lay_NotEnoughMemoryExit ();
|
MsgCod = DB_QueryINSERTandReturnCode_new ("can not create message");
|
||||||
MsgCod = DB_QueryINSERTandReturnCode_free (Query,"can not create message");
|
|
||||||
|
|
||||||
/***** Insert message in sent messages *****/
|
/***** Insert message in sent messages *****/
|
||||||
if (asprintf (&Query,"INSERT INTO msg_snt"
|
DB_BuildQuery ("INSERT INTO msg_snt"
|
||||||
" (MsgCod,CrsCod,UsrCod,Expanded,CreatTime)"
|
" (MsgCod,CrsCod,UsrCod,Expanded,CreatTime)"
|
||||||
" VALUES"
|
" VALUES"
|
||||||
" (%ld,%ld,%ld,'N',NOW())",
|
" (%ld,%ld,%ld,'N',NOW())",
|
||||||
MsgCod,
|
MsgCod,
|
||||||
Gbl.CurrentCrs.Crs.CrsCod,
|
Gbl.CurrentCrs.Crs.CrsCod,
|
||||||
Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
|
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
DB_QueryINSERT_new ("can not create message");
|
||||||
DB_QueryINSERT_free (Query,"can not create message");
|
|
||||||
|
|
||||||
/***** Increment number of messages sent by me *****/
|
/***** Increment number of messages sent by me *****/
|
||||||
Prf_IncrementNumMsgSntUsr (Gbl.Usrs.Me.UsrDat.UsrCod);
|
Prf_IncrementNumMsgSntUsr (Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||||
|
@ -1410,36 +1388,30 @@ static unsigned long Msg_DelSomeRecOrSntMsgsUsr (Msg_TypeOfMessages_t TypeOfMess
|
||||||
|
|
||||||
void Msg_DelAllRecAndSntMsgsUsr (long UsrCod)
|
void Msg_DelAllRecAndSntMsgsUsr (long UsrCod)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Move messages from msg_rcv to msg_rcv_deleted *****/
|
/***** Move messages from msg_rcv to msg_rcv_deleted *****/
|
||||||
/* Insert messages into msg_rcv_deleted */
|
/* Insert messages into msg_rcv_deleted */
|
||||||
if (asprintf (&Query,"INSERT IGNORE INTO msg_rcv_deleted"
|
DB_BuildQuery ("INSERT IGNORE INTO msg_rcv_deleted"
|
||||||
" (MsgCod,UsrCod,Notified,Open,Replied)"
|
" (MsgCod,UsrCod,Notified,Open,Replied)"
|
||||||
" SELECT MsgCod,UsrCod,Notified,Open,Replied FROM msg_rcv WHERE UsrCod=%ld",
|
" SELECT MsgCod,UsrCod,Notified,Open,Replied FROM msg_rcv WHERE UsrCod=%ld",
|
||||||
UsrCod) < 0)
|
UsrCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
DB_QueryINSERT_new ("can not remove received messages");
|
||||||
DB_QueryINSERT_free (Query,"can not remove received messages");
|
|
||||||
|
|
||||||
/* Delete messages from msg_rcv *****/
|
/* Delete messages from msg_rcv *****/
|
||||||
if (asprintf (&Query,"DELETE FROM msg_rcv WHERE UsrCod=%ld",UsrCod) < 0)
|
DB_BuildQuery ("DELETE FROM msg_rcv WHERE UsrCod=%ld",UsrCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
DB_QueryDELETE_new ("can not remove received messages");
|
||||||
DB_QueryDELETE_free (Query,"can not remove received messages");
|
|
||||||
|
|
||||||
/***** Move message from msg_snt to msg_snt_deleted *****/
|
/***** Move message from msg_snt to msg_snt_deleted *****/
|
||||||
/* Insert message into msg_snt_deleted */
|
/* Insert message into msg_snt_deleted */
|
||||||
if (asprintf (&Query,"INSERT IGNORE INTO msg_snt_deleted"
|
DB_BuildQuery ("INSERT IGNORE INTO msg_snt_deleted"
|
||||||
" (MsgCod,CrsCod,UsrCod,CreatTime)"
|
" (MsgCod,CrsCod,UsrCod,CreatTime)"
|
||||||
" SELECT MsgCod,CrsCod,UsrCod,CreatTime"
|
" SELECT MsgCod,CrsCod,UsrCod,CreatTime"
|
||||||
" FROM msg_snt WHERE UsrCod=%ld",
|
" FROM msg_snt WHERE UsrCod=%ld",
|
||||||
UsrCod) < 0)
|
UsrCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
DB_QueryINSERT_new ("can not remove sent messages");
|
||||||
DB_QueryINSERT_free (Query,"can not remove sent messages");
|
|
||||||
|
|
||||||
/* Delete message from msg_snt *****/
|
/* Delete message from msg_snt *****/
|
||||||
if (asprintf (&Query,"DELETE FROM msg_snt WHERE UsrCod=%ld",UsrCod) < 0)
|
DB_BuildQuery ("DELETE FROM msg_snt WHERE UsrCod=%ld",UsrCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
DB_QueryDELETE_new ("can not remove sent messages");
|
||||||
DB_QueryDELETE_free (Query,"can not remove sent messages");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -1448,18 +1420,15 @@ void Msg_DelAllRecAndSntMsgsUsr (long UsrCod)
|
||||||
|
|
||||||
static void Msg_InsertReceivedMsgIntoDB (long MsgCod,long UsrCod,bool NotifyByEmail)
|
static void Msg_InsertReceivedMsgIntoDB (long MsgCod,long UsrCod,bool NotifyByEmail)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Insert message received in the database *****/
|
/***** Insert message received in the database *****/
|
||||||
if (asprintf (&Query,"INSERT INTO msg_rcv"
|
DB_BuildQuery ("INSERT INTO msg_rcv"
|
||||||
" (MsgCod,UsrCod,Notified,Open,Replied,Expanded)"
|
" (MsgCod,UsrCod,Notified,Open,Replied,Expanded)"
|
||||||
" VALUES"
|
" VALUES"
|
||||||
" (%ld,%ld,'%c','N','N','N')",
|
" (%ld,%ld,'%c','N','N','N')",
|
||||||
MsgCod,UsrCod,
|
MsgCod,UsrCod,
|
||||||
NotifyByEmail ? 'Y' :
|
NotifyByEmail ? 'Y' :
|
||||||
'N') < 0)
|
'N');
|
||||||
Lay_NotEnoughMemoryExit ();
|
DB_QueryINSERT_new ("can not create received message");
|
||||||
DB_QueryINSERT_free (Query,"can not create received message");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -1468,14 +1437,11 @@ static void Msg_InsertReceivedMsgIntoDB (long MsgCod,long UsrCod,bool NotifyByEm
|
||||||
|
|
||||||
static void Msg_SetReceivedMsgAsReplied (long MsgCod)
|
static void Msg_SetReceivedMsgAsReplied (long MsgCod)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Update received message by setting Replied field to true *****/
|
/***** Update received message by setting Replied field to true *****/
|
||||||
if (asprintf (&Query,"UPDATE msg_rcv SET Replied='Y'"
|
DB_BuildQuery ("UPDATE msg_rcv SET Replied='Y'"
|
||||||
" WHERE MsgCod=%ld AND UsrCod=%ld",
|
" WHERE MsgCod=%ld AND UsrCod=%ld",
|
||||||
MsgCod,Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
|
MsgCod,Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
DB_QueryUPDATE_new ("can not update a received message");
|
||||||
DB_QueryUPDATE_free (Query,"can not update a received message");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -1484,23 +1450,19 @@ static void Msg_SetReceivedMsgAsReplied (long MsgCod)
|
||||||
|
|
||||||
static void Msg_MoveReceivedMsgToDeleted (long MsgCod,long UsrCod)
|
static void Msg_MoveReceivedMsgToDeleted (long MsgCod,long UsrCod)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Move message from msg_rcv to msg_rcv_deleted *****/
|
/***** Move message from msg_rcv to msg_rcv_deleted *****/
|
||||||
/* Insert message into msg_rcv_deleted */
|
/* Insert message into msg_rcv_deleted */
|
||||||
if (asprintf (&Query,"INSERT IGNORE INTO msg_rcv_deleted"
|
DB_BuildQuery ("INSERT IGNORE INTO msg_rcv_deleted"
|
||||||
" (MsgCod,UsrCod,Notified,Open,Replied)"
|
" (MsgCod,UsrCod,Notified,Open,Replied)"
|
||||||
" SELECT MsgCod,UsrCod,Notified,Open,Replied"
|
" SELECT MsgCod,UsrCod,Notified,Open,Replied"
|
||||||
" FROM msg_rcv WHERE MsgCod=%ld AND UsrCod=%ld",
|
" FROM msg_rcv WHERE MsgCod=%ld AND UsrCod=%ld",
|
||||||
MsgCod,UsrCod) < 0)
|
MsgCod,UsrCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
DB_QueryINSERT_new ("can not remove a received message");
|
||||||
DB_QueryINSERT_free (Query,"can not remove a received message");
|
|
||||||
|
|
||||||
/* Delete message from msg_rcv *****/
|
/* Delete message from msg_rcv *****/
|
||||||
if (asprintf (&Query,"DELETE FROM msg_rcv WHERE MsgCod=%ld AND UsrCod=%ld",
|
DB_BuildQuery ("DELETE FROM msg_rcv WHERE MsgCod=%ld AND UsrCod=%ld",
|
||||||
MsgCod,UsrCod) < 0)
|
MsgCod,UsrCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
DB_QueryDELETE_new ("can not remove a received message");
|
||||||
DB_QueryDELETE_free (Query,"can not remove a received message");
|
|
||||||
|
|
||||||
/***** If message content is not longer necessary, move it to msg_content_deleted *****/
|
/***** If message content is not longer necessary, move it to msg_content_deleted *****/
|
||||||
if (Msg_CheckIfSentMsgIsDeleted (MsgCod))
|
if (Msg_CheckIfSentMsgIsDeleted (MsgCod))
|
||||||
|
@ -1517,22 +1479,18 @@ static void Msg_MoveReceivedMsgToDeleted (long MsgCod,long UsrCod)
|
||||||
|
|
||||||
static void Msg_MoveSentMsgToDeleted (long MsgCod)
|
static void Msg_MoveSentMsgToDeleted (long MsgCod)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Move message from msg_snt to msg_snt_deleted *****/
|
/***** Move message from msg_snt to msg_snt_deleted *****/
|
||||||
/* Insert message into msg_snt_deleted */
|
/* Insert message into msg_snt_deleted */
|
||||||
if (asprintf (&Query,"INSERT IGNORE INTO msg_snt_deleted"
|
DB_BuildQuery ("INSERT IGNORE INTO msg_snt_deleted"
|
||||||
" (MsgCod,CrsCod,UsrCod,CreatTime)"
|
" (MsgCod,CrsCod,UsrCod,CreatTime)"
|
||||||
" SELECT MsgCod,CrsCod,UsrCod,CreatTime"
|
" SELECT MsgCod,CrsCod,UsrCod,CreatTime"
|
||||||
" FROM msg_snt WHERE MsgCod=%ld",
|
" FROM msg_snt WHERE MsgCod=%ld",
|
||||||
MsgCod) < 0)
|
MsgCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
DB_QueryINSERT_new ("can not remove a sent message");
|
||||||
DB_QueryINSERT_free (Query,"can not remove a sent message");
|
|
||||||
|
|
||||||
/* Delete message from msg_snt *****/
|
/* Delete message from msg_snt *****/
|
||||||
if (asprintf (&Query,"DELETE FROM msg_snt WHERE MsgCod=%ld",MsgCod) < 0)
|
DB_BuildQuery ("DELETE FROM msg_snt WHERE MsgCod=%ld",MsgCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
DB_QueryDELETE_new ("can not remove a sent message");
|
||||||
DB_QueryDELETE_free (Query,"can not remove a sent message");
|
|
||||||
|
|
||||||
/***** If message content is not longer necessary, move it to msg_content_deleted *****/
|
/***** If message content is not longer necessary, move it to msg_content_deleted *****/
|
||||||
if (Msg_CheckIfReceivedMsgIsDeletedForAllItsRecipients (MsgCod))
|
if (Msg_CheckIfReceivedMsgIsDeletedForAllItsRecipients (MsgCod))
|
||||||
|
@ -1545,25 +1503,21 @@ static void Msg_MoveSentMsgToDeleted (long MsgCod)
|
||||||
|
|
||||||
static void Msg_MoveMsgContentToDeleted (long MsgCod)
|
static void Msg_MoveMsgContentToDeleted (long MsgCod)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Move message from msg_content to msg_content_deleted *****/
|
/***** Move message from msg_content to msg_content_deleted *****/
|
||||||
/* Insert message content into msg_content_deleted */
|
/* Insert message content into msg_content_deleted */
|
||||||
if (asprintf (&Query,"INSERT IGNORE INTO msg_content_deleted"
|
DB_BuildQuery ("INSERT IGNORE INTO msg_content_deleted"
|
||||||
" (MsgCod,Subject,Content,ImageName,ImageTitle,ImageURL)"
|
" (MsgCod,Subject,Content,ImageName,ImageTitle,ImageURL)"
|
||||||
" SELECT MsgCod,Subject,Content,ImageName,ImageTitle,ImageURL"
|
" SELECT MsgCod,Subject,Content,ImageName,ImageTitle,ImageURL"
|
||||||
" FROM msg_content WHERE MsgCod=%ld",
|
" FROM msg_content WHERE MsgCod=%ld",
|
||||||
MsgCod) < 0)
|
MsgCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
DB_QueryINSERT_new ("can not remove the content of a message");
|
||||||
DB_QueryINSERT_free (Query,"can not remove the content of a message");
|
|
||||||
|
|
||||||
/* TODO: Messages in msg_content_deleted older than a certain time
|
/* TODO: Messages in msg_content_deleted older than a certain time
|
||||||
should be deleted to ensure the protection of personal data */
|
should be deleted to ensure the protection of personal data */
|
||||||
|
|
||||||
/* Delete message from msg_content *****/
|
/* Delete message from msg_content *****/
|
||||||
if (asprintf (&Query,"DELETE FROM msg_content WHERE MsgCod=%ld",MsgCod) < 0)
|
DB_BuildQuery ("DELETE FROM msg_content WHERE MsgCod=%ld",MsgCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
DB_QueryUPDATE_new ("can not remove the content of a message");
|
||||||
DB_QueryUPDATE_free (Query,"can not remove the content of a message");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -1572,27 +1526,23 @@ static void Msg_MoveMsgContentToDeleted (long MsgCod)
|
||||||
|
|
||||||
void Msg_MoveUnusedMsgsContentToDeleted (void)
|
void Msg_MoveUnusedMsgsContentToDeleted (void)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Move messages from msg_content to msg_content_deleted *****/
|
/***** Move messages from msg_content to msg_content_deleted *****/
|
||||||
/* Insert message content into msg_content_deleted */
|
/* Insert message content into msg_content_deleted */
|
||||||
if (asprintf (&Query,"INSERT IGNORE INTO msg_content_deleted"
|
DB_BuildQuery ("INSERT IGNORE INTO msg_content_deleted"
|
||||||
" (MsgCod,Subject,Content)"
|
" (MsgCod,Subject,Content)"
|
||||||
" SELECT MsgCod,Subject,Content FROM msg_content"
|
" SELECT MsgCod,Subject,Content FROM msg_content"
|
||||||
" WHERE MsgCod NOT IN (SELECT MsgCod FROM msg_snt)"
|
" WHERE MsgCod NOT IN (SELECT MsgCod FROM msg_snt)"
|
||||||
" AND MsgCod NOT IN (SELECT DISTINCT MsgCod FROM msg_rcv)") < 0)
|
" AND MsgCod NOT IN (SELECT DISTINCT MsgCod FROM msg_rcv)");
|
||||||
Lay_NotEnoughMemoryExit ();
|
DB_QueryINSERT_new ("can not remove the content of some messages");
|
||||||
DB_QueryINSERT_free (Query,"can not remove the content of some messages");
|
|
||||||
|
|
||||||
/* Messages in msg_content_deleted older than a certain time
|
/* Messages in msg_content_deleted older than a certain time
|
||||||
should be deleted to ensure the protection of personal data */
|
should be deleted to ensure the protection of personal data */
|
||||||
|
|
||||||
/* Delete message from msg_content *****/
|
/* Delete message from msg_content *****/
|
||||||
if (asprintf (&Query,"DELETE FROM msg_content"
|
DB_BuildQuery ("DELETE FROM msg_content"
|
||||||
" WHERE MsgCod NOT IN (SELECT MsgCod FROM msg_snt)"
|
" WHERE MsgCod NOT IN (SELECT MsgCod FROM msg_snt)"
|
||||||
" AND MsgCod NOT IN (SELECT DISTINCT MsgCod FROM msg_rcv)") < 0)
|
" AND MsgCod NOT IN (SELECT DISTINCT MsgCod FROM msg_rcv)");
|
||||||
Lay_NotEnoughMemoryExit ();
|
DB_QueryUPDATE_new ("can not remove the content of some messages");
|
||||||
DB_QueryUPDATE_free (Query,"can not remove the content of some messages");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -1601,13 +1551,10 @@ void Msg_MoveUnusedMsgsContentToDeleted (void)
|
||||||
|
|
||||||
static bool Msg_CheckIfSentMsgIsDeleted (long MsgCod)
|
static bool Msg_CheckIfSentMsgIsDeleted (long MsgCod)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Get if the message code is in table of sent messages not deleted *****/
|
/***** Get if the message code is in table of sent messages not deleted *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM msg_snt"
|
DB_BuildQuery ("SELECT COUNT(*) FROM msg_snt"
|
||||||
" WHERE MsgCod=%ld",MsgCod) < 0)
|
" WHERE MsgCod=%ld",MsgCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
return (DB_QueryCOUNT_new ("can not check if a sent message is deleted") == 0); // The message has been deleted by its author when it is not present in table of sent messages undeleted
|
||||||
return (DB_QueryCOUNT_free (Query,"can not check if a sent message is deleted") == 0); // The message has been deleted by its author when it is not present in table of sent messages undeleted
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -1616,13 +1563,10 @@ static bool Msg_CheckIfSentMsgIsDeleted (long MsgCod)
|
||||||
|
|
||||||
static bool Msg_CheckIfReceivedMsgIsDeletedForAllItsRecipients (long MsgCod)
|
static bool Msg_CheckIfReceivedMsgIsDeletedForAllItsRecipients (long MsgCod)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Get if the message code is in table of received messages not deleted *****/
|
/***** Get if the message code is in table of received messages not deleted *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM msg_rcv"
|
DB_BuildQuery ("SELECT COUNT(*) FROM msg_rcv"
|
||||||
" WHERE MsgCod=%ld",MsgCod) < 0)
|
" WHERE MsgCod=%ld",MsgCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
return (DB_QueryCOUNT_new ("can not check if a received message is deleted by all recipients") == 0); // The message has been deleted by all its recipients when it is not present in table of received messages undeleted
|
||||||
return (DB_QueryCOUNT_free (Query,"can not check if a received message is deleted by all recipients") == 0); // The message has been deleted by all its recipients when it is not present in table of received messages undeleted
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -1632,7 +1576,6 @@ static bool Msg_CheckIfReceivedMsgIsDeletedForAllItsRecipients (long MsgCod)
|
||||||
static unsigned Msg_GetNumUnreadMsgs (long FilterCrsCod,const char *FilterFromToSubquery)
|
static unsigned Msg_GetNumUnreadMsgs (long FilterCrsCod,const char *FilterFromToSubquery)
|
||||||
{
|
{
|
||||||
char SubQuery[Msg_MAX_BYTES_MESSAGES_QUERY + 1];
|
char SubQuery[Msg_MAX_BYTES_MESSAGES_QUERY + 1];
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Get number of unread messages from database *****/
|
/***** Get number of unread messages from database *****/
|
||||||
if (FilterCrsCod >= 0) // If origin course selected
|
if (FilterCrsCod >= 0) // If origin course selected
|
||||||
|
@ -1670,21 +1613,15 @@ static unsigned Msg_GetNumUnreadMsgs (long FilterCrsCod,const char *FilterFromTo
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Gbl.Msg.FilterContent[0])
|
if (Gbl.Msg.FilterContent[0])
|
||||||
{
|
DB_BuildQuery ("SELECT COUNT(*) FROM msg_content"
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM msg_content"
|
|
||||||
" WHERE MsgCod IN (%s)"
|
" WHERE MsgCod IN (%s)"
|
||||||
" AND MATCH (Subject,Content) AGAINST ('%s')",
|
" AND MATCH (Subject,Content) AGAINST ('%s')",
|
||||||
SubQuery,
|
SubQuery,
|
||||||
Gbl.Msg.FilterContent) < 0)
|
Gbl.Msg.FilterContent);
|
||||||
Lay_NotEnoughMemoryExit ();
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
DB_BuildQuery ("SELECT COUNT(*) FROM (%s) AS T",
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM (%s) AS T",
|
SubQuery);
|
||||||
SubQuery) < 0)
|
return (unsigned) DB_QueryCOUNT_new ("can not get number of unread messages");
|
||||||
Lay_NotEnoughMemoryExit ();
|
|
||||||
}
|
|
||||||
return (unsigned) DB_QueryCOUNT_free (Query,"can not get number of unread messages");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -1897,13 +1834,10 @@ static void Msg_ShowSentOrReceivedMessages (void)
|
||||||
|
|
||||||
static unsigned long Msg_GetNumUsrsBannedByMe (void)
|
static unsigned long Msg_GetNumUsrsBannedByMe (void)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Get number of users I have banned *****/
|
/***** Get number of users I have banned *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM msg_banned WHERE ToUsrCod=%ld",
|
DB_BuildQuery ("SELECT COUNT(*) FROM msg_banned WHERE ToUsrCod=%ld",
|
||||||
Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
|
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
return DB_QueryCOUNT_new ("can not get number of users you have banned");
|
||||||
return DB_QueryCOUNT_free (Query,"can not get number of users you have banned");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -2074,15 +2008,12 @@ static void Msg_ConstructQueryToSelectSentOrReceivedMsgs (char Query[Msg_MAX_BYT
|
||||||
|
|
||||||
unsigned Msg_GetNumMsgsSentByTchsCrs (long CrsCod)
|
unsigned Msg_GetNumMsgsSentByTchsCrs (long CrsCod)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Get the number of unique messages sent by any teacher from this course *****/
|
/***** Get the number of unique messages sent by any teacher from this course *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM msg_snt,crs_usr"
|
DB_BuildQuery ("SELECT COUNT(*) FROM msg_snt,crs_usr"
|
||||||
" WHERE msg_snt.CrsCod=%ld AND crs_usr.CrsCod=%ld AND crs_usr.Role=%u"
|
" WHERE msg_snt.CrsCod=%ld AND crs_usr.CrsCod=%ld AND crs_usr.Role=%u"
|
||||||
" AND msg_snt.UsrCod=crs_usr.UsrCod",
|
" AND msg_snt.UsrCod=crs_usr.UsrCod",
|
||||||
CrsCod,CrsCod,(unsigned) Rol_TCH) < 0)
|
CrsCod,CrsCod,(unsigned) Rol_TCH);
|
||||||
Lay_NotEnoughMemoryExit ();
|
return (unsigned) DB_QueryCOUNT_new ("can not get the number of messages sent by teachers");
|
||||||
return (unsigned) DB_QueryCOUNT_free (Query,"can not get the number of messages sent by teachers");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -2091,17 +2022,14 @@ unsigned Msg_GetNumMsgsSentByTchsCrs (long CrsCod)
|
||||||
|
|
||||||
unsigned long Msg_GetNumMsgsSentByUsr (long UsrCod)
|
unsigned long Msg_GetNumMsgsSentByUsr (long UsrCod)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Get the number of unique messages sent by any teacher from this course *****/
|
/***** Get the number of unique messages sent by any teacher from this course *****/
|
||||||
if (asprintf (&Query,"SELECT"
|
DB_BuildQuery ("SELECT"
|
||||||
" (SELECT COUNT(*) FROM msg_snt WHERE UsrCod=%ld)"
|
" (SELECT COUNT(*) FROM msg_snt WHERE UsrCod=%ld)"
|
||||||
" +"
|
" +"
|
||||||
" (SELECT COUNT(*) FROM msg_snt_deleted WHERE UsrCod=%ld)",
|
" (SELECT COUNT(*) FROM msg_snt_deleted WHERE UsrCod=%ld)",
|
||||||
UsrCod,
|
UsrCod,
|
||||||
UsrCod) < 0)
|
UsrCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
return DB_QueryCOUNT_new ("can not get the number of messages sent by a user");
|
||||||
return DB_QueryCOUNT_free (Query,"can not get the number of messages sent by a user");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -2112,7 +2040,6 @@ unsigned long Msg_GetNumMsgsSentByUsr (long UsrCod)
|
||||||
unsigned Msg_GetNumMsgsSent (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
|
unsigned Msg_GetNumMsgsSent (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
|
||||||
{
|
{
|
||||||
const char *Table = "msg_snt";
|
const char *Table = "msg_snt";
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Get the number of messages sent from this location
|
/***** Get the number of messages sent from this location
|
||||||
(all the platform, current degree or current course) from database *****/
|
(all the platform, current degree or current course) from database *****/
|
||||||
|
@ -2129,12 +2056,11 @@ unsigned Msg_GetNumMsgsSent (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
|
||||||
switch (Scope)
|
switch (Scope)
|
||||||
{
|
{
|
||||||
case Sco_SCOPE_SYS:
|
case Sco_SCOPE_SYS:
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM %s",
|
DB_BuildQuery ("SELECT COUNT(*) FROM %s",
|
||||||
Table) < 0)
|
Table);
|
||||||
Lay_NotEnoughMemoryExit ();
|
|
||||||
break;
|
break;
|
||||||
case Sco_SCOPE_CTY:
|
case Sco_SCOPE_CTY:
|
||||||
if (asprintf (&Query,"SELECT COUNT(*)"
|
DB_BuildQuery ("SELECT COUNT(*)"
|
||||||
" FROM institutions,centres,degrees,courses,%s"
|
" FROM institutions,centres,degrees,courses,%s"
|
||||||
" WHERE institutions.CtyCod=%ld"
|
" WHERE institutions.CtyCod=%ld"
|
||||||
" AND institutions.InsCod=centres.InsCod"
|
" AND institutions.InsCod=centres.InsCod"
|
||||||
|
@ -2143,11 +2069,10 @@ unsigned Msg_GetNumMsgsSent (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
|
||||||
" AND courses.CrsCod=%s.CrsCod",
|
" AND courses.CrsCod=%s.CrsCod",
|
||||||
Table,
|
Table,
|
||||||
Gbl.CurrentCty.Cty.CtyCod,
|
Gbl.CurrentCty.Cty.CtyCod,
|
||||||
Table) < 0)
|
Table);
|
||||||
Lay_NotEnoughMemoryExit ();
|
|
||||||
break;
|
break;
|
||||||
case Sco_SCOPE_INS:
|
case Sco_SCOPE_INS:
|
||||||
if (asprintf (&Query,"SELECT COUNT(*)"
|
DB_BuildQuery ("SELECT COUNT(*)"
|
||||||
" FROM centres,degrees,courses,%s"
|
" FROM centres,degrees,courses,%s"
|
||||||
" WHERE centres.InsCod=%ld"
|
" WHERE centres.InsCod=%ld"
|
||||||
" AND centres.CtrCod=degrees.CtrCod"
|
" AND centres.CtrCod=degrees.CtrCod"
|
||||||
|
@ -2155,43 +2080,39 @@ unsigned Msg_GetNumMsgsSent (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
|
||||||
" AND courses.CrsCod=%s.CrsCod",
|
" AND courses.CrsCod=%s.CrsCod",
|
||||||
Table,
|
Table,
|
||||||
Gbl.CurrentIns.Ins.InsCod,
|
Gbl.CurrentIns.Ins.InsCod,
|
||||||
Table) < 0)
|
Table);
|
||||||
Lay_NotEnoughMemoryExit ();
|
|
||||||
break;
|
break;
|
||||||
case Sco_SCOPE_CTR:
|
case Sco_SCOPE_CTR:
|
||||||
if (asprintf (&Query,"SELECT COUNT(*)"
|
DB_BuildQuery ("SELECT COUNT(*)"
|
||||||
" FROM degrees,courses,%s"
|
" FROM degrees,courses,%s"
|
||||||
" WHERE degrees.CtrCod=%ld"
|
" WHERE degrees.CtrCod=%ld"
|
||||||
" AND degrees.DegCod=courses.DegCod"
|
" AND degrees.DegCod=courses.DegCod"
|
||||||
" AND courses.CrsCod=%s.CrsCod",
|
" AND courses.CrsCod=%s.CrsCod",
|
||||||
Table,
|
Table,
|
||||||
Gbl.CurrentCtr.Ctr.CtrCod,
|
Gbl.CurrentCtr.Ctr.CtrCod,
|
||||||
Table) < 0)
|
Table);
|
||||||
Lay_NotEnoughMemoryExit ();
|
|
||||||
break;
|
break;
|
||||||
case Sco_SCOPE_DEG:
|
case Sco_SCOPE_DEG:
|
||||||
if (asprintf (&Query,"SELECT COUNT(*)"
|
DB_BuildQuery ("SELECT COUNT(*)"
|
||||||
" FROM courses,%s"
|
" FROM courses,%s"
|
||||||
" WHERE courses.DegCod=%ld"
|
" WHERE courses.DegCod=%ld"
|
||||||
" AND courses.CrsCod=%s.CrsCod",
|
" AND courses.CrsCod=%s.CrsCod",
|
||||||
Table,
|
Table,
|
||||||
Gbl.CurrentDeg.Deg.DegCod,
|
Gbl.CurrentDeg.Deg.DegCod,
|
||||||
Table) < 0)
|
Table);
|
||||||
Lay_NotEnoughMemoryExit ();
|
|
||||||
break;
|
break;
|
||||||
case Sco_SCOPE_CRS:
|
case Sco_SCOPE_CRS:
|
||||||
if (asprintf (&Query,"SELECT COUNT(*)"
|
DB_BuildQuery ("SELECT COUNT(*)"
|
||||||
" FROM %s"
|
" FROM %s"
|
||||||
" WHERE CrsCod=%ld",
|
" WHERE CrsCod=%ld",
|
||||||
Table,
|
Table,
|
||||||
Gbl.CurrentCrs.Crs.CrsCod) < 0)
|
Gbl.CurrentCrs.Crs.CrsCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Lay_WrongScopeExit ();
|
Lay_WrongScopeExit ();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return (unsigned) DB_QueryCOUNT_free (Query,"can not get number of sent messages");
|
return (unsigned) DB_QueryCOUNT_new ("can not get number of sent messages");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -2202,7 +2123,6 @@ unsigned Msg_GetNumMsgsSent (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
|
||||||
unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
|
unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
|
||||||
{
|
{
|
||||||
char *Table;
|
char *Table;
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Get the number of unique messages sent from this location
|
/***** Get the number of unique messages sent from this location
|
||||||
(all the platform, current degree or current course) from database *****/
|
(all the platform, current degree or current course) from database *****/
|
||||||
|
@ -2215,12 +2135,11 @@ unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
|
||||||
switch (Scope)
|
switch (Scope)
|
||||||
{
|
{
|
||||||
case Sco_SCOPE_SYS:
|
case Sco_SCOPE_SYS:
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM %s",
|
DB_BuildQuery ("SELECT COUNT(*) FROM %s",
|
||||||
Table) < 0)
|
Table);
|
||||||
Lay_NotEnoughMemoryExit ();
|
|
||||||
break;
|
break;
|
||||||
case Sco_SCOPE_CTY:
|
case Sco_SCOPE_CTY:
|
||||||
if (asprintf (&Query,"SELECT COUNT(*)"
|
DB_BuildQuery ("SELECT COUNT(*)"
|
||||||
" FROM institutions,centres,degrees,courses,%s,msg_snt"
|
" FROM institutions,centres,degrees,courses,%s,msg_snt"
|
||||||
" WHERE institutions.CtyCod=%ld"
|
" WHERE institutions.CtyCod=%ld"
|
||||||
" AND institutions.InsCod=centres.InsCod"
|
" AND institutions.InsCod=centres.InsCod"
|
||||||
|
@ -2230,11 +2149,10 @@ unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
|
||||||
" AND msg_snt.MsgCod=%s.MsgCod",
|
" AND msg_snt.MsgCod=%s.MsgCod",
|
||||||
Table,
|
Table,
|
||||||
Gbl.CurrentCty.Cty.CtyCod,
|
Gbl.CurrentCty.Cty.CtyCod,
|
||||||
Table) < 0)
|
Table);
|
||||||
Lay_NotEnoughMemoryExit ();
|
|
||||||
break;
|
break;
|
||||||
case Sco_SCOPE_INS:
|
case Sco_SCOPE_INS:
|
||||||
if (asprintf (&Query,"SELECT COUNT(*)"
|
DB_BuildQuery ("SELECT COUNT(*)"
|
||||||
" FROM centres,degrees,courses,%s,msg_snt"
|
" FROM centres,degrees,courses,%s,msg_snt"
|
||||||
" WHERE centres.InsCod=%ld"
|
" WHERE centres.InsCod=%ld"
|
||||||
" AND centres.CtrCod=degrees.CtrCod"
|
" AND centres.CtrCod=degrees.CtrCod"
|
||||||
|
@ -2243,11 +2161,10 @@ unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
|
||||||
" AND msg_snt.MsgCod=%s.MsgCod",
|
" AND msg_snt.MsgCod=%s.MsgCod",
|
||||||
Table,
|
Table,
|
||||||
Gbl.CurrentIns.Ins.InsCod,
|
Gbl.CurrentIns.Ins.InsCod,
|
||||||
Table) < 0)
|
Table);
|
||||||
Lay_NotEnoughMemoryExit ();
|
|
||||||
break;
|
break;
|
||||||
case Sco_SCOPE_CTR:
|
case Sco_SCOPE_CTR:
|
||||||
if (asprintf (&Query,"SELECT COUNT(*)"
|
DB_BuildQuery ("SELECT COUNT(*)"
|
||||||
" FROM degrees,courses,%s,msg_snt"
|
" FROM degrees,courses,%s,msg_snt"
|
||||||
" WHERE degrees.CtrCod=%ld"
|
" WHERE degrees.CtrCod=%ld"
|
||||||
" AND degrees.DegCod=courses.DegCod"
|
" AND degrees.DegCod=courses.DegCod"
|
||||||
|
@ -2255,29 +2172,26 @@ unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
|
||||||
" AND msg_snt.MsgCod=%s.MsgCod",
|
" AND msg_snt.MsgCod=%s.MsgCod",
|
||||||
Table,
|
Table,
|
||||||
Gbl.CurrentCtr.Ctr.CtrCod,
|
Gbl.CurrentCtr.Ctr.CtrCod,
|
||||||
Table) < 0)
|
Table);
|
||||||
Lay_NotEnoughMemoryExit ();
|
|
||||||
break;
|
break;
|
||||||
case Sco_SCOPE_DEG:
|
case Sco_SCOPE_DEG:
|
||||||
if (asprintf (&Query,"SELECT COUNT(*)"
|
DB_BuildQuery ("SELECT COUNT(*)"
|
||||||
" FROM courses,%s,msg_snt"
|
" FROM courses,%s,msg_snt"
|
||||||
" WHERE courses.DegCod=%ld"
|
" WHERE courses.DegCod=%ld"
|
||||||
" AND courses.CrsCod=msg_snt.CrsCod"
|
" AND courses.CrsCod=msg_snt.CrsCod"
|
||||||
" AND msg_snt.MsgCod=%s.MsgCod",
|
" AND msg_snt.MsgCod=%s.MsgCod",
|
||||||
Table,
|
Table,
|
||||||
Gbl.CurrentDeg.Deg.DegCod,
|
Gbl.CurrentDeg.Deg.DegCod,
|
||||||
Table) < 0)
|
Table);
|
||||||
Lay_NotEnoughMemoryExit ();
|
|
||||||
break;
|
break;
|
||||||
case Sco_SCOPE_CRS:
|
case Sco_SCOPE_CRS:
|
||||||
if (asprintf (&Query,"SELECT COUNT(*)"
|
DB_BuildQuery ("SELECT COUNT(*)"
|
||||||
" FROM msg_snt,%s"
|
" FROM msg_snt,%s"
|
||||||
" WHERE msg_snt.CrsCod=%ld"
|
" WHERE msg_snt.CrsCod=%ld"
|
||||||
" AND msg_snt.MsgCod=%s.MsgCod",
|
" AND msg_snt.MsgCod=%s.MsgCod",
|
||||||
Table,
|
Table,
|
||||||
Gbl.CurrentCrs.Crs.CrsCod,
|
Gbl.CurrentCrs.Crs.CrsCod,
|
||||||
Table) < 0)
|
Table);
|
||||||
Lay_NotEnoughMemoryExit ();
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Lay_WrongScopeExit ();
|
Lay_WrongScopeExit ();
|
||||||
|
@ -2288,18 +2202,17 @@ unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
|
||||||
switch (Scope)
|
switch (Scope)
|
||||||
{
|
{
|
||||||
case Sco_SCOPE_SYS:
|
case Sco_SCOPE_SYS:
|
||||||
if (asprintf (&Query,"SELECT "
|
DB_BuildQuery ("SELECT "
|
||||||
"(SELECT COUNT(*)"
|
"(SELECT COUNT(*)"
|
||||||
" FROM msg_rcv"
|
" FROM msg_rcv"
|
||||||
" WHERE Notified='Y')"
|
" WHERE Notified='Y')"
|
||||||
" + "
|
" + "
|
||||||
"(SELECT COUNT(*)"
|
"(SELECT COUNT(*)"
|
||||||
" FROM msg_rcv_deleted"
|
" FROM msg_rcv_deleted"
|
||||||
" WHERE Notified='Y')") < 0)
|
" WHERE Notified='Y')");
|
||||||
Lay_NotEnoughMemoryExit ();
|
|
||||||
break;
|
break;
|
||||||
case Sco_SCOPE_CTY:
|
case Sco_SCOPE_CTY:
|
||||||
if (asprintf (&Query,"SELECT "
|
DB_BuildQuery ("SELECT "
|
||||||
"(SELECT COUNT(*)"
|
"(SELECT COUNT(*)"
|
||||||
" FROM institutions,centres,degrees,courses,msg_snt,msg_rcv"
|
" FROM institutions,centres,degrees,courses,msg_snt,msg_rcv"
|
||||||
" WHERE institutions.CtyCod=%ld"
|
" WHERE institutions.CtyCod=%ld"
|
||||||
|
@ -2320,11 +2233,10 @@ unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
|
||||||
" AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod"
|
" AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod"
|
||||||
" AND msg_rcv_deleted.Notified='Y')",
|
" AND msg_rcv_deleted.Notified='Y')",
|
||||||
Gbl.CurrentCty.Cty.CtyCod,
|
Gbl.CurrentCty.Cty.CtyCod,
|
||||||
Gbl.CurrentCty.Cty.CtyCod) < 0)
|
Gbl.CurrentCty.Cty.CtyCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
|
||||||
break;
|
break;
|
||||||
case Sco_SCOPE_INS:
|
case Sco_SCOPE_INS:
|
||||||
if (asprintf (&Query,"SELECT "
|
DB_BuildQuery ("SELECT "
|
||||||
"(SELECT COUNT(*)"
|
"(SELECT COUNT(*)"
|
||||||
" FROM centres,degrees,courses,msg_snt,msg_rcv"
|
" FROM centres,degrees,courses,msg_snt,msg_rcv"
|
||||||
" WHERE centres.InsCod=%ld"
|
" WHERE centres.InsCod=%ld"
|
||||||
|
@ -2343,11 +2255,10 @@ unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
|
||||||
" AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod"
|
" AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod"
|
||||||
" AND msg_rcv_deleted.Notified='Y')",
|
" AND msg_rcv_deleted.Notified='Y')",
|
||||||
Gbl.CurrentIns.Ins.InsCod,
|
Gbl.CurrentIns.Ins.InsCod,
|
||||||
Gbl.CurrentIns.Ins.InsCod) < 0)
|
Gbl.CurrentIns.Ins.InsCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
|
||||||
break;
|
break;
|
||||||
case Sco_SCOPE_CTR:
|
case Sco_SCOPE_CTR:
|
||||||
if (asprintf (&Query,"SELECT "
|
DB_BuildQuery ("SELECT "
|
||||||
"(SELECT COUNT(*)"
|
"(SELECT COUNT(*)"
|
||||||
" FROM degrees,courses,msg_snt,msg_rcv"
|
" FROM degrees,courses,msg_snt,msg_rcv"
|
||||||
" WHERE degrees.CtrCod=%ld"
|
" WHERE degrees.CtrCod=%ld"
|
||||||
|
@ -2364,11 +2275,10 @@ unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
|
||||||
" AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod"
|
" AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod"
|
||||||
" AND msg_rcv_deleted.Notified='Y')",
|
" AND msg_rcv_deleted.Notified='Y')",
|
||||||
Gbl.CurrentCtr.Ctr.CtrCod,
|
Gbl.CurrentCtr.Ctr.CtrCod,
|
||||||
Gbl.CurrentCtr.Ctr.CtrCod) < 0)
|
Gbl.CurrentCtr.Ctr.CtrCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
|
||||||
break;
|
break;
|
||||||
case Sco_SCOPE_DEG:
|
case Sco_SCOPE_DEG:
|
||||||
if (asprintf (&Query,"SELECT "
|
DB_BuildQuery ("SELECT "
|
||||||
"(SELECT COUNT(*)"
|
"(SELECT COUNT(*)"
|
||||||
" FROM courses,msg_snt,msg_rcv"
|
" FROM courses,msg_snt,msg_rcv"
|
||||||
" WHERE courses.DegCod=%ld"
|
" WHERE courses.DegCod=%ld"
|
||||||
|
@ -2383,11 +2293,10 @@ unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
|
||||||
" AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod"
|
" AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod"
|
||||||
" AND msg_rcv_deleted.Notified='Y')",
|
" AND msg_rcv_deleted.Notified='Y')",
|
||||||
Gbl.CurrentDeg.Deg.DegCod,
|
Gbl.CurrentDeg.Deg.DegCod,
|
||||||
Gbl.CurrentDeg.Deg.DegCod) < 0)
|
Gbl.CurrentDeg.Deg.DegCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
|
||||||
break;
|
break;
|
||||||
case Sco_SCOPE_CRS:
|
case Sco_SCOPE_CRS:
|
||||||
if (asprintf (&Query,"SELECT "
|
DB_BuildQuery ("SELECT "
|
||||||
"(SELECT COUNT(*)"
|
"(SELECT COUNT(*)"
|
||||||
" FROM msg_snt,msg_rcv"
|
" FROM msg_snt,msg_rcv"
|
||||||
" WHERE msg_snt.CrsCod=%ld"
|
" WHERE msg_snt.CrsCod=%ld"
|
||||||
|
@ -2400,8 +2309,7 @@ unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
|
||||||
" AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod"
|
" AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod"
|
||||||
" AND msg_rcv_deleted.Notified='Y')",
|
" AND msg_rcv_deleted.Notified='Y')",
|
||||||
Gbl.CurrentCrs.Crs.CrsCod,
|
Gbl.CurrentCrs.Crs.CrsCod,
|
||||||
Gbl.CurrentCrs.Crs.CrsCod) < 0)
|
Gbl.CurrentCrs.Crs.CrsCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Lay_WrongScopeExit ();
|
Lay_WrongScopeExit ();
|
||||||
|
@ -2409,7 +2317,7 @@ unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return (unsigned) DB_QueryCOUNT_free (Query,"can not get number of received messages");
|
return (unsigned) DB_QueryCOUNT_new ("can not get number of received messages");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -3408,7 +3316,6 @@ static void Msg_WriteMsgTo (long MsgCod)
|
||||||
extern const char *Txt_and_X_other_recipients;
|
extern const char *Txt_and_X_other_recipients;
|
||||||
extern const char *Txt_unknown_recipient;
|
extern const char *Txt_unknown_recipient;
|
||||||
extern const char *Txt_unknown_recipients;
|
extern const char *Txt_unknown_recipients;
|
||||||
char *Query;
|
|
||||||
MYSQL_RES *mysql_res;
|
MYSQL_RES *mysql_res;
|
||||||
MYSQL_ROW row;
|
MYSQL_ROW row;
|
||||||
unsigned NumRcp;
|
unsigned NumRcp;
|
||||||
|
@ -3430,13 +3337,12 @@ static void Msg_WriteMsgTo (long MsgCod)
|
||||||
};
|
};
|
||||||
|
|
||||||
/***** Get number of recipients of a message from database *****/
|
/***** Get number of recipients of a message from database *****/
|
||||||
if (asprintf (&Query,"SELECT "
|
DB_BuildQuery ("SELECT "
|
||||||
"(SELECT COUNT(*) FROM msg_rcv WHERE MsgCod=%ld)"
|
"(SELECT COUNT(*) FROM msg_rcv WHERE MsgCod=%ld)"
|
||||||
" + "
|
" + "
|
||||||
"(SELECT COUNT(*) FROM msg_rcv_deleted WHERE MsgCod=%ld)",
|
"(SELECT COUNT(*) FROM msg_rcv_deleted WHERE MsgCod=%ld)",
|
||||||
MsgCod,MsgCod) < 0)
|
MsgCod,MsgCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
NumRecipientsTotal = (unsigned) DB_QueryCOUNT_new ("can not get number of recipients");
|
||||||
NumRecipientsTotal = (unsigned) DB_QueryCOUNT_free (Query,"can not get number of recipients");
|
|
||||||
|
|
||||||
/***** Get recipients of a message from database *****/
|
/***** Get recipients of a message from database *****/
|
||||||
DB_BuildQuery ("(SELECT msg_rcv.UsrCod,'N',msg_rcv.Open,"
|
DB_BuildQuery ("(SELECT msg_rcv.UsrCod,'N',msg_rcv.Open,"
|
||||||
|
@ -3685,7 +3591,6 @@ static void Msg_PutFormToUnbanSender (struct UsrData *UsrDat)
|
||||||
void Msg_BanSenderWhenShowingMsgs (void)
|
void Msg_BanSenderWhenShowingMsgs (void)
|
||||||
{
|
{
|
||||||
extern const char *Txt_From_this_time_you_will_not_receive_messages_from_X;
|
extern const char *Txt_From_this_time_you_will_not_receive_messages_from_X;
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Get user's code from form *****/
|
/***** Get user's code from form *****/
|
||||||
Usr_GetParamOtherUsrCodEncryptedAndGetListIDs ();
|
Usr_GetParamOtherUsrCodEncryptedAndGetListIDs ();
|
||||||
|
@ -3695,13 +3600,12 @@ void Msg_BanSenderWhenShowingMsgs (void)
|
||||||
Lay_ShowErrorAndExit ("Sender does not exist.");
|
Lay_ShowErrorAndExit ("Sender does not exist.");
|
||||||
|
|
||||||
/***** Insert pair (sender's code - my code) in table of banned senders if not inserted *****/
|
/***** Insert pair (sender's code - my code) in table of banned senders if not inserted *****/
|
||||||
if (asprintf (&Query,"REPLACE INTO msg_banned"
|
DB_BuildQuery ("REPLACE INTO msg_banned"
|
||||||
" (FromUsrCod,ToUsrCod)"
|
" (FromUsrCod,ToUsrCod)"
|
||||||
" VALUES"
|
" VALUES"
|
||||||
" (%ld,%ld)",
|
" (%ld,%ld)",
|
||||||
Gbl.Usrs.Other.UsrDat.UsrCod,Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
|
Gbl.Usrs.Other.UsrDat.UsrCod,Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
DB_QueryREPLACE_new ("can not ban sender");
|
||||||
DB_QueryREPLACE_free (Query,"can not ban sender");
|
|
||||||
|
|
||||||
/***** Show alert with the change made *****/
|
/***** Show alert with the change made *****/
|
||||||
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
|
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
|
||||||
|
@ -3746,7 +3650,6 @@ void Msg_UnbanSenderWhenListingUsrs (void)
|
||||||
static void Msg_UnbanSender (void)
|
static void Msg_UnbanSender (void)
|
||||||
{
|
{
|
||||||
extern const char *Txt_From_this_time_you_can_receive_messages_from_X;
|
extern const char *Txt_From_this_time_you_can_receive_messages_from_X;
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Get user's code from form *****/
|
/***** Get user's code from form *****/
|
||||||
Usr_GetParamOtherUsrCodEncryptedAndGetListIDs ();
|
Usr_GetParamOtherUsrCodEncryptedAndGetListIDs ();
|
||||||
|
@ -3756,11 +3659,10 @@ static void Msg_UnbanSender (void)
|
||||||
Lay_ShowErrorAndExit ("Sender does not exist.");
|
Lay_ShowErrorAndExit ("Sender does not exist.");
|
||||||
|
|
||||||
/***** Remove pair (sender's code - my code) from table of banned senders *****/
|
/***** Remove pair (sender's code - my code) from table of banned senders *****/
|
||||||
if (asprintf (&Query,"DELETE FROM msg_banned"
|
DB_BuildQuery ("DELETE FROM msg_banned"
|
||||||
" WHERE FromUsrCod=%ld AND ToUsrCod=%ld",
|
" WHERE FromUsrCod=%ld AND ToUsrCod=%ld",
|
||||||
Gbl.Usrs.Other.UsrDat.UsrCod,Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
|
Gbl.Usrs.Other.UsrDat.UsrCod,Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
DB_QueryDELETE_new ("can not ban sender");
|
||||||
DB_QueryDELETE_free (Query,"can not ban sender");
|
|
||||||
|
|
||||||
/***** Show alert with the change made *****/
|
/***** Show alert with the change made *****/
|
||||||
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
|
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
|
||||||
|
@ -3775,14 +3677,11 @@ static void Msg_UnbanSender (void)
|
||||||
|
|
||||||
static bool Msg_CheckIfUsrIsBanned (long FromUsrCod,long ToUsrCod)
|
static bool Msg_CheckIfUsrIsBanned (long FromUsrCod,long ToUsrCod)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Get if FromUsrCod is banned by ToUsrCod *****/
|
/***** Get if FromUsrCod is banned by ToUsrCod *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM msg_banned"
|
DB_BuildQuery ("SELECT COUNT(*) FROM msg_banned"
|
||||||
" WHERE FromUsrCod=%ld AND ToUsrCod=%ld",
|
" WHERE FromUsrCod=%ld AND ToUsrCod=%ld",
|
||||||
FromUsrCod,ToUsrCod) < 0)
|
FromUsrCod,ToUsrCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
return (DB_QueryCOUNT_new ("can not check if a user is banned") != 0);
|
||||||
return (DB_QueryCOUNT_free (Query,"can not check if a user is banned") != 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -3791,15 +3690,12 @@ static bool Msg_CheckIfUsrIsBanned (long FromUsrCod,long ToUsrCod)
|
||||||
|
|
||||||
void Msg_RemoveUsrFromBanned (long UsrCod)
|
void Msg_RemoveUsrFromBanned (long UsrCod)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Remove pair (sender's code - my code)
|
/***** Remove pair (sender's code - my code)
|
||||||
from table of banned senders *****/
|
from table of banned senders *****/
|
||||||
if (asprintf (&Query,"DELETE FROM msg_banned"
|
DB_BuildQuery ("DELETE FROM msg_banned"
|
||||||
" WHERE FromUsrCod=%ld OR ToUsrCod=%ld",
|
" WHERE FromUsrCod=%ld OR ToUsrCod=%ld",
|
||||||
UsrCod,UsrCod) < 0)
|
UsrCod,UsrCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
DB_QueryDELETE_new ("can not remove user from table of banned users");
|
||||||
DB_QueryDELETE_free (Query,"can not remove user from table of banned users");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
|
@ -557,7 +557,6 @@ static void Nck_UpdateUsrNick (struct UsrData *UsrDat)
|
||||||
extern const char *Txt_The_nickname_X_had_been_registered_by_another_user;
|
extern const char *Txt_The_nickname_X_had_been_registered_by_another_user;
|
||||||
extern const char *Txt_The_nickname_X_has_been_registered_successfully;
|
extern const char *Txt_The_nickname_X_has_been_registered_successfully;
|
||||||
extern const char *Txt_The_nickname_entered_X_is_not_valid_;
|
extern const char *Txt_The_nickname_entered_X_is_not_valid_;
|
||||||
char *Query;
|
|
||||||
char NewNicknameWithArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1];
|
char NewNicknameWithArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1];
|
||||||
char NewNicknameWithoutArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1];
|
char NewNicknameWithoutArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1];
|
||||||
|
|
||||||
|
@ -583,18 +582,16 @@ static void Nck_UpdateUsrNick (struct UsrData *UsrDat)
|
||||||
else if (strcasecmp (UsrDat->Nickname,NewNicknameWithoutArroba)) // User's nickname does not match, not even case insensitive, the new nickname
|
else if (strcasecmp (UsrDat->Nickname,NewNicknameWithoutArroba)) // User's nickname does not match, not even case insensitive, the new nickname
|
||||||
{
|
{
|
||||||
/***** Check if the new nickname matches any of my old nicknames *****/
|
/***** Check if the new nickname matches any of my old nicknames *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_nicknames"
|
DB_BuildQuery ("SELECT COUNT(*) FROM usr_nicknames"
|
||||||
" WHERE UsrCod=%ld AND Nickname='%s'",
|
" WHERE UsrCod=%ld AND Nickname='%s'",
|
||||||
UsrDat->UsrCod,NewNicknameWithoutArroba) < 0)
|
UsrDat->UsrCod,NewNicknameWithoutArroba);
|
||||||
Lay_NotEnoughMemoryExit ();
|
if (!DB_QueryCOUNT_new ("can not check if nickname already existed")) // No matches
|
||||||
if (!DB_QueryCOUNT_free (Query,"can not check if nickname already existed")) // No matches
|
|
||||||
{
|
{
|
||||||
/***** Check if the new nickname matches any of the nicknames of other users *****/
|
/***** Check if the new nickname matches any of the nicknames of other users *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_nicknames"
|
DB_BuildQuery ("SELECT COUNT(*) FROM usr_nicknames"
|
||||||
" WHERE Nickname='%s' AND UsrCod<>%ld",
|
" WHERE Nickname='%s' AND UsrCod<>%ld",
|
||||||
NewNicknameWithoutArroba,UsrDat->UsrCod) < 0)
|
NewNicknameWithoutArroba,UsrDat->UsrCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
if (DB_QueryCOUNT_new ("can not check if nickname already existed")) // A nickname of another user is the same that user's nickname
|
||||||
if (DB_QueryCOUNT_free (Query,"can not check if nickname already existed")) // A nickname of another user is the same that user's nickname
|
|
||||||
{
|
{
|
||||||
Gbl.Alert.Type = Ale_WARNING;
|
Gbl.Alert.Type = Ale_WARNING;
|
||||||
Gbl.Alert.Section = Nck_NICKNAME_SECTION_ID;
|
Gbl.Alert.Section = Nck_NICKNAME_SECTION_ID;
|
||||||
|
|
|
@ -2120,15 +2120,12 @@ void Ntf_WriteNumberOfNewNtfs (void)
|
||||||
|
|
||||||
static unsigned Ntf_GetNumberOfAllMyUnseenNtfs (void)
|
static unsigned Ntf_GetNumberOfAllMyUnseenNtfs (void)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Get number of places with a name from database *****/
|
/***** Get number of places with a name from database *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM notif"
|
DB_BuildQuery ("SELECT COUNT(*) FROM notif"
|
||||||
" WHERE ToUsrCod=%ld AND (Status & %u)=0",
|
" WHERE ToUsrCod=%ld AND (Status & %u)=0",
|
||||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||||
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED)) < 0)
|
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED));
|
||||||
Lay_NotEnoughMemoryExit ();
|
return DB_QueryCOUNT_new ("can not get number of unseen notifications");
|
||||||
return DB_QueryCOUNT_free (Query,"can not get number of unseen notifications");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -2137,17 +2134,14 @@ static unsigned Ntf_GetNumberOfAllMyUnseenNtfs (void)
|
||||||
|
|
||||||
static unsigned Ntf_GetNumberOfMyNewUnseenNtfs (void)
|
static unsigned Ntf_GetNumberOfMyNewUnseenNtfs (void)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Get number of places with a name from database *****/
|
/***** Get number of places with a name from database *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM notif"
|
DB_BuildQuery ("SELECT COUNT(*) FROM notif"
|
||||||
" WHERE ToUsrCod=%ld AND (Status & %u)=0"
|
" WHERE ToUsrCod=%ld AND (Status & %u)=0"
|
||||||
" AND TimeNotif>FROM_UNIXTIME(%ld)",
|
" AND TimeNotif>FROM_UNIXTIME(%ld)",
|
||||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||||
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED),
|
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED),
|
||||||
Gbl.Usrs.Me.UsrLast.LastAccNotif) < 0)
|
Gbl.Usrs.Me.UsrLast.LastAccNotif);
|
||||||
Lay_NotEnoughMemoryExit ();
|
return DB_QueryCOUNT_new ("can not get number of unseen notifications");
|
||||||
return DB_QueryCOUNT_free (Query,"can not get number of unseen notifications");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
|
@ -578,23 +578,20 @@ bool Pwd_SlowCheckIfPasswordIsGood (const char *PlainPassword,
|
||||||
|
|
||||||
static bool Pwd_CheckIfPasswdIsUsrIDorName (const char *PlainPassword)
|
static bool Pwd_CheckIfPasswdIsUsrIDorName (const char *PlainPassword)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
bool Found;
|
bool Found;
|
||||||
|
|
||||||
/***** Get if password is found in user's ID from database *****/
|
/***** Get if password is found in user's ID from database *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_IDs WHERE UsrID='%s'",
|
DB_BuildQuery ("SELECT COUNT(*) FROM usr_IDs WHERE UsrID='%s'",
|
||||||
PlainPassword) < 0)
|
PlainPassword);
|
||||||
Lay_NotEnoughMemoryExit ();
|
Found = (DB_QueryCOUNT_new ("can not check if a password matches a user's ID") != 0);
|
||||||
Found = (DB_QueryCOUNT_free (Query,"can not check if a password matches a user's ID") != 0);
|
|
||||||
|
|
||||||
/***** Get if password is found in first name or surnames of anybody, from database *****/
|
/***** Get if password is found in first name or surnames of anybody, from database *****/
|
||||||
if (!Found)
|
if (!Found)
|
||||||
{
|
{
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_data"
|
DB_BuildQuery ("SELECT COUNT(*) FROM usr_data"
|
||||||
" WHERE FirstName='%s' OR Surname1='%s' OR Surname2='%s'",
|
" WHERE FirstName='%s' OR Surname1='%s' OR Surname2='%s'",
|
||||||
PlainPassword,PlainPassword,PlainPassword) < 0)
|
PlainPassword,PlainPassword,PlainPassword);
|
||||||
Lay_NotEnoughMemoryExit ();
|
Found = (DB_QueryCOUNT_new ("can not check if a password matches a first name or a surname") != 0);
|
||||||
Found = (DB_QueryCOUNT_free (Query,"can not check if a password matches a first name or a surname") != 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Found;
|
return Found;
|
||||||
|
@ -606,25 +603,17 @@ static bool Pwd_CheckIfPasswdIsUsrIDorName (const char *PlainPassword)
|
||||||
|
|
||||||
static unsigned Pwd_GetNumOtherUsrsWhoUseThisPassword (const char *EncryptedPassword,long UsrCod)
|
static unsigned Pwd_GetNumOtherUsrsWhoUseThisPassword (const char *EncryptedPassword,long UsrCod)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Get number of other users who use a password from database *****/
|
/***** Get number of other users who use a password from database *****/
|
||||||
/* Query database */
|
/* Query database */
|
||||||
if (UsrCod > 0)
|
if (UsrCod > 0)
|
||||||
{
|
DB_BuildQuery ("SELECT COUNT(*) FROM usr_data"
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_data"
|
|
||||||
" WHERE Password='%s' AND UsrCod<>%ld",
|
" WHERE Password='%s' AND UsrCod<>%ld",
|
||||||
EncryptedPassword,UsrCod) < 0)
|
EncryptedPassword,UsrCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
DB_BuildQuery ("SELECT COUNT(*) FROM usr_data"
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_data"
|
|
||||||
" WHERE Password='%s'",
|
" WHERE Password='%s'",
|
||||||
EncryptedPassword) < 0)
|
EncryptedPassword);
|
||||||
Lay_NotEnoughMemoryExit ();
|
return (unsigned) DB_QueryCOUNT_new ("can not check if a password is trivial");
|
||||||
}
|
|
||||||
return (unsigned) DB_QueryCOUNT_free (Query,"can not check if a password is trivial");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
|
@ -705,14 +705,11 @@ static void Plc_RenamePlace (Cns_ShrtOrFullName_t ShrtOrFullName)
|
||||||
|
|
||||||
static bool Plc_CheckIfPlaceNameExists (const char *FieldName,const char *Name,long PlcCod)
|
static bool Plc_CheckIfPlaceNameExists (const char *FieldName,const char *Name,long PlcCod)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Get number of places with a name from database *****/
|
/***** Get number of places with a name from database *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM places"
|
DB_BuildQuery ("SELECT COUNT(*) FROM places"
|
||||||
" WHERE InsCod=%ld AND %s='%s' AND PlcCod<>%ld",
|
" WHERE InsCod=%ld AND %s='%s' AND PlcCod<>%ld",
|
||||||
Gbl.CurrentIns.Ins.InsCod,FieldName,Name,PlcCod) < 0)
|
Gbl.CurrentIns.Ins.InsCod,FieldName,Name,PlcCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
return (DB_QueryCOUNT_new ("can not check if the name of a place already existed") != 0);
|
||||||
return (DB_QueryCOUNT_free (Query,"can not check if the name of a place already existed") != 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
|
@ -596,14 +596,11 @@ void Plg_RenamePlugin (void)
|
||||||
|
|
||||||
static bool Plg_CheckIfPluginNameExists (const char *Name,long PlgCod)
|
static bool Plg_CheckIfPluginNameExists (const char *Name,long PlgCod)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Get number of plugins with a name from database *****/
|
/***** Get number of plugins with a name from database *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM plugins"
|
DB_BuildQuery ("SELECT COUNT(*) FROM plugins"
|
||||||
" WHERE Name='%s' AND PlgCod<>%ld",
|
" WHERE Name='%s' AND PlgCod<>%ld",
|
||||||
Name,PlgCod) < 0)
|
Name,PlgCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
return (DB_QueryCOUNT_new ("can not check if the name of a plugin already existed") != 0);
|
||||||
return (DB_QueryCOUNT_free (Query,"can not check if the name of a plugin already existed") != 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
|
@ -679,17 +679,14 @@ void Prf_GetUsrFigures (long UsrCod,struct UsrFigures *UsrFigures)
|
||||||
|
|
||||||
static unsigned long Prf_GetRankingFigure (long UsrCod,const char *FieldName)
|
static unsigned long Prf_GetRankingFigure (long UsrCod,const char *FieldName)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Select number of rows with figure
|
/***** Select number of rows with figure
|
||||||
greater than the figure of this user *****/
|
greater than the figure of this user *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(*)+1 FROM usr_figures"
|
DB_BuildQuery ("SELECT COUNT(*)+1 FROM usr_figures"
|
||||||
" WHERE UsrCod<>%ld" // Really not necessary here
|
" WHERE UsrCod<>%ld" // Really not necessary here
|
||||||
" AND %s>"
|
" AND %s>"
|
||||||
"(SELECT %s FROM usr_figures WHERE UsrCod=%ld)",
|
"(SELECT %s FROM usr_figures WHERE UsrCod=%ld)",
|
||||||
UsrCod,FieldName,FieldName,UsrCod) < 0)
|
UsrCod,FieldName,FieldName,UsrCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
return DB_QueryCOUNT_new ("can not get ranking using a figure");
|
||||||
return DB_QueryCOUNT_free (Query,"can not get ranking using a figure");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -698,13 +695,9 @@ static unsigned long Prf_GetRankingFigure (long UsrCod,const char *FieldName)
|
||||||
|
|
||||||
static unsigned long Prf_GetNumUsrsWithFigure (const char *FieldName)
|
static unsigned long Prf_GetNumUsrsWithFigure (const char *FieldName)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Select number of rows with values already calculated *****/
|
/***** Select number of rows with values already calculated *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_figures WHERE %s>=0",
|
DB_BuildQuery ("SELECT COUNT(*) FROM usr_figures WHERE %s>=0",FieldName);
|
||||||
FieldName) < 0)
|
return DB_QueryCOUNT_new ("can not get number of users with a figure");
|
||||||
Lay_NotEnoughMemoryExit ();
|
|
||||||
return DB_QueryCOUNT_free (Query,"can not get number of users with a figure");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -713,11 +706,9 @@ static unsigned long Prf_GetNumUsrsWithFigure (const char *FieldName)
|
||||||
|
|
||||||
static unsigned long Prf_GetRankingNumClicksPerDay (long UsrCod)
|
static unsigned long Prf_GetRankingNumClicksPerDay (long UsrCod)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Select number of rows with number of clicks per day
|
/***** Select number of rows with number of clicks per day
|
||||||
greater than the clicks per day of this user *****/
|
greater than the clicks per day of this user *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(*)+1 FROM"
|
DB_BuildQuery ("SELECT COUNT(*)+1 FROM"
|
||||||
" (SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1)"
|
" (SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1)"
|
||||||
" AS NumClicksPerDay"
|
" AS NumClicksPerDay"
|
||||||
" FROM usr_figures"
|
" FROM usr_figures"
|
||||||
|
@ -731,9 +722,8 @@ static unsigned long Prf_GetRankingNumClicksPerDay (long UsrCod)
|
||||||
" WHERE UsrCod=%ld"
|
" WHERE UsrCod=%ld"
|
||||||
" AND NumClicks>0"
|
" AND NumClicks>0"
|
||||||
" AND UNIX_TIMESTAMP(FirstClickTime)>0)",
|
" AND UNIX_TIMESTAMP(FirstClickTime)>0)",
|
||||||
UsrCod,UsrCod) < 0)
|
UsrCod,UsrCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
return DB_QueryCOUNT_new ("can not get ranking using number of clicks per day");
|
||||||
return DB_QueryCOUNT_free (Query,"can not get ranking using number of clicks per day");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -742,14 +732,11 @@ static unsigned long Prf_GetRankingNumClicksPerDay (long UsrCod)
|
||||||
|
|
||||||
static unsigned long Prf_GetNumUsrsWithNumClicksPerDay (void)
|
static unsigned long Prf_GetNumUsrsWithNumClicksPerDay (void)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Select number of rows with values already calculated *****/
|
/***** Select number of rows with values already calculated *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_figures"
|
DB_BuildQuery ("SELECT COUNT(*) FROM usr_figures"
|
||||||
" WHERE NumClicks>0"
|
" WHERE NumClicks>0"
|
||||||
" AND UNIX_TIMESTAMP(FirstClickTime)>0") < 0)
|
" AND UNIX_TIMESTAMP(FirstClickTime)>0");
|
||||||
Lay_NotEnoughMemoryExit ();
|
return DB_QueryCOUNT_new ("can not get number of users with number of clicks per day");
|
||||||
return DB_QueryCOUNT_free (Query,"can not get number of users with number of clicks per day");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -900,10 +887,8 @@ static void Prf_GetNumClicksAndStoreAsUsrFigure (long UsrCod)
|
||||||
Prf_ResetUsrFigures (&UsrFigures);
|
Prf_ResetUsrFigures (&UsrFigures);
|
||||||
|
|
||||||
/***** Get number of clicks from database *****/
|
/***** Get number of clicks from database *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM log_full WHERE UsrCod=%ld",
|
DB_BuildQuery ("SELECT COUNT(*) FROM log_full WHERE UsrCod=%ld",UsrCod);
|
||||||
UsrCod) < 0)
|
UsrFigures.NumClicks = (long) DB_QueryCOUNT_new ("can not get number of clicks");
|
||||||
Lay_NotEnoughMemoryExit ();
|
|
||||||
UsrFigures.NumClicks = (long) DB_QueryCOUNT_free (Query,"can not get number of clicks");
|
|
||||||
|
|
||||||
/***** Update number of clicks in user's figures *****/
|
/***** Update number of clicks in user's figures *****/
|
||||||
if (Prf_CheckIfUsrFiguresExists (UsrCod))
|
if (Prf_CheckIfUsrFiguresExists (UsrCod))
|
||||||
|
@ -1101,12 +1086,8 @@ void Prf_RemoveUsrFigures (long UsrCod)
|
||||||
|
|
||||||
static bool Prf_CheckIfUsrFiguresExists (long UsrCod)
|
static bool Prf_CheckIfUsrFiguresExists (long UsrCod)
|
||||||
{
|
{
|
||||||
char *Query;
|
DB_BuildQuery ("SELECT COUNT(*) FROM usr_figures WHERE UsrCod=%ld",UsrCod);
|
||||||
|
return (DB_QueryCOUNT_new ("can not get user's first click") != 0);
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_figures WHERE UsrCod=%ld",
|
|
||||||
UsrCod) < 0)
|
|
||||||
Lay_NotEnoughMemoryExit ();
|
|
||||||
return (DB_QueryCOUNT_free (Query,"can not get user's first click") != 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
|
@ -629,13 +629,10 @@ long Rec_GetFieldCod (void)
|
||||||
|
|
||||||
unsigned Rec_CountNumRecordsInCurrCrsWithField (long FieldCod)
|
unsigned Rec_CountNumRecordsInCurrCrsWithField (long FieldCod)
|
||||||
{
|
{
|
||||||
char *Query;
|
|
||||||
|
|
||||||
/***** Get number of cards with a given field in a course from database *****/
|
/***** Get number of cards with a given field in a course from database *****/
|
||||||
if (asprintf (&Query,"SELECT COUNT(*) FROM crs_records WHERE FieldCod=%ld",
|
DB_BuildQuery ("SELECT COUNT(*) FROM crs_records WHERE FieldCod=%ld",
|
||||||
FieldCod) < 0)
|
FieldCod);
|
||||||
Lay_NotEnoughMemoryExit ();
|
return (unsigned) DB_QueryCOUNT_new ("can not get number of cards"
|
||||||
return (unsigned) DB_QueryCOUNT_free (Query,"can not get number of cards"
|
|
||||||
" with a given field not empty"
|
" with a given field not empty"
|
||||||
" in a course");
|
" in a course");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user