mirror of https://github.com/acanas/swad-core.git
Version 18.8.9
This commit is contained in:
parent
ddb0259495
commit
187ac31346
11
swad_ID.c
11
swad_ID.c
|
@ -844,14 +844,11 @@ static void ID_RemoveUsrID (const struct UsrData *UsrDat,bool ItsMe)
|
|||
|
||||
static bool ID_CheckIfConfirmed (long UsrCod,const char *UsrID)
|
||||
{
|
||||
char *Query;
|
||||
|
||||
/***** Get if ID is confirmed from database *****/
|
||||
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_IDs"
|
||||
" WHERE UsrCod=%ld AND UsrID='%s' AND Confirmed='Y'",
|
||||
UsrCod,UsrID) < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
return (DB_QueryCOUNT_free (Query,"can not check if ID is confirmed") != 0);
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM usr_IDs"
|
||||
" WHERE UsrCod=%ld AND UsrID='%s' AND Confirmed='Y'",
|
||||
UsrCod,UsrID);
|
||||
return (DB_QueryCOUNT_new ("can not check if ID is confirmed") != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -355,10 +355,11 @@ En OpenSWAD:
|
|||
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 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.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)
|
||||
|
|
|
@ -3228,6 +3228,23 @@ unsigned long DB_QueryCOUNT (const char *Query,const char *MsgError)
|
|||
/******************** 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)
|
||||
{
|
||||
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 ***/
|
||||
/*****************************************************************************/
|
||||
|
||||
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)
|
||||
{
|
||||
int Result;
|
||||
|
@ -3278,6 +3315,23 @@ long DB_QueryINSERTandReturnCode (const char *Query,const char *MsgError)
|
|||
/******************** 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)
|
||||
{
|
||||
int Result;
|
||||
|
@ -3300,6 +3354,26 @@ void DB_QueryREPLACE (const char *Query,const char *MsgError)
|
|||
/******************** 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)
|
||||
{
|
||||
int Result;
|
||||
|
@ -3328,6 +3402,23 @@ void DB_QueryUPDATE (const char *Query,const char *MsgError)
|
|||
/******************** 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)
|
||||
{
|
||||
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 (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 (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 (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 (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 (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 (const char *Query,const char *MsgError);
|
||||
|
||||
|
|
24
swad_group.c
24
swad_group.c
|
@ -3797,15 +3797,12 @@ void Grp_RecFormNewGrp (void)
|
|||
|
||||
static bool Grp_CheckIfGroupTypeNameExists (const char *GrpTypName,long GrpTypCod)
|
||||
{
|
||||
char *Query;
|
||||
|
||||
/***** Get number of group types with a name from database *****/
|
||||
if (asprintf (&Query,"SELECT COUNT(*) FROM crs_grp_types"
|
||||
" WHERE CrsCod=%ld AND GrpTypName='%s'"
|
||||
" AND GrpTypCod<>%ld",
|
||||
Gbl.CurrentCrs.Crs.CrsCod,GrpTypName,GrpTypCod) < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
return (DB_QueryCOUNT_free (Query,"can not check if the name of type of group already existed") != 0);
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM crs_grp_types"
|
||||
" WHERE CrsCod=%ld AND GrpTypName='%s'"
|
||||
" AND GrpTypCod<>%ld",
|
||||
Gbl.CurrentCrs.Crs.CrsCod,GrpTypName,GrpTypCod);
|
||||
return (DB_QueryCOUNT_new ("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)
|
||||
{
|
||||
char *Query;
|
||||
|
||||
/***** Get number of groups with a type and a name from database *****/
|
||||
if (asprintf (&Query,"SELECT COUNT(*) FROM crs_grp"
|
||||
" WHERE GrpTypCod=%ld AND GrpName='%s' AND GrpCod<>%ld",
|
||||
GrpTypCod,GrpName,GrpCod) < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
return (DB_QueryCOUNT_free (Query,"can not check if the name of group already existed") != 0);
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM crs_grp"
|
||||
" WHERE GrpTypCod=%ld AND GrpName='%s' AND GrpCod<>%ld",
|
||||
GrpTypCod,GrpName,GrpCod);
|
||||
return (DB_QueryCOUNT_new ("can not check if the name of group already existed") != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
15
swad_info.c
15
swad_info.c
|
@ -522,16 +522,13 @@ static void Inf_PutCheckboxConfirmIHaveReadInfo (void)
|
|||
|
||||
static bool Inf_CheckIfIHaveReadInfo (void)
|
||||
{
|
||||
char *Query;
|
||||
|
||||
/***** Get if info source is already stored in database *****/
|
||||
if (asprintf (&Query,"SELECT COUNT(*) FROM crs_info_read"
|
||||
" WHERE UsrCod=%ld AND CrsCod=%ld AND InfoType='%s'",
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
Gbl.CurrentCrs.Crs.CrsCod,
|
||||
Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type]) < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
return (DB_QueryCOUNT_free (Query,"can not get if I have read course info") != 0);
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM crs_info_read"
|
||||
" WHERE UsrCod=%ld AND CrsCod=%ld AND InfoType='%s'",
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
Gbl.CurrentCrs.Crs.CrsCod,
|
||||
Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type]);
|
||||
return (DB_QueryCOUNT_new ("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)
|
||||
{
|
||||
char *Query;
|
||||
|
||||
/***** Get number of institutions in current country with a name from database *****/
|
||||
if (asprintf (&Query,"SELECT COUNT(*) FROM institutions"
|
||||
" WHERE CtyCod=%ld AND %s='%s' AND InsCod<>%ld",
|
||||
CtyCod,FieldName,Name,InsCod) < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
return (DB_QueryCOUNT_free (Query,"can not check if the name of an institution already existed") != 0);
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM institutions"
|
||||
" WHERE CtyCod=%ld AND %s='%s' AND InsCod<>%ld",
|
||||
CtyCod,FieldName,Name,InsCod);
|
||||
return (DB_QueryCOUNT_new ("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)
|
||||
{
|
||||
char *Query;
|
||||
|
||||
/***** Get total number of degrees from database *****/
|
||||
if (asprintf (&Query,"SELECT COUNT(*) FROM institutions") < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
return (unsigned) DB_QueryCOUNT_free (Query,"can not get the total number of institutions");
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM institutions");
|
||||
return (unsigned) DB_QueryCOUNT_new ("can not get the total number of institutions");
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -2461,13 +2455,9 @@ unsigned Ins_GetNumInssTotal (void)
|
|||
|
||||
unsigned Ins_GetNumInssInCty (long CtyCod)
|
||||
{
|
||||
char *Query;
|
||||
|
||||
/***** Get number of degrees of a place from database *****/
|
||||
if (asprintf (&Query,"SELECT COUNT(*) FROM institutions WHERE CtyCod=%ld",
|
||||
CtyCod) < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
return (unsigned) DB_QueryCOUNT_free (Query,"can not get the number of institutions in a country");
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM institutions WHERE CtyCod=%ld",CtyCod);
|
||||
return (unsigned) DB_QueryCOUNT_new ("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)
|
||||
{
|
||||
char *Query;
|
||||
|
||||
/***** Get number of institutions with centres from database *****/
|
||||
if (asprintf (&Query,"SELECT COUNT(DISTINCT institutions.InsCod)"
|
||||
" FROM institutions,centres"
|
||||
" WHERE %sinstitutions.InsCod=centres.InsCod",
|
||||
SubQuery) < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
return (unsigned) DB_QueryCOUNT_free (Query,"can not get number of institutions with centres");
|
||||
DB_BuildQuery ("SELECT COUNT(DISTINCT institutions.InsCod)"
|
||||
" FROM institutions,centres"
|
||||
" WHERE %sinstitutions.InsCod=centres.InsCod",
|
||||
SubQuery);
|
||||
return (unsigned) DB_QueryCOUNT_new ("can not get number of institutions with centres");
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -2493,16 +2480,13 @@ unsigned Ins_GetNumInssWithCtrs (const char *SubQuery)
|
|||
|
||||
unsigned Ins_GetNumInssWithDegs (const char *SubQuery)
|
||||
{
|
||||
char *Query;
|
||||
|
||||
/***** Get number of institutions with degrees from database *****/
|
||||
if (asprintf (&Query,"SELECT COUNT(DISTINCT institutions.InsCod)"
|
||||
" FROM institutions,centres,degrees"
|
||||
" WHERE %sinstitutions.InsCod=centres.InsCod"
|
||||
" AND centres.CtrCod=degrees.CtrCod",
|
||||
SubQuery) < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
return (unsigned) DB_QueryCOUNT_free (Query,"can not get number of institutions with degrees");
|
||||
DB_BuildQuery ("SELECT COUNT(DISTINCT institutions.InsCod)"
|
||||
" FROM institutions,centres,degrees"
|
||||
" WHERE %sinstitutions.InsCod=centres.InsCod"
|
||||
" AND centres.CtrCod=degrees.CtrCod",
|
||||
SubQuery);
|
||||
return (unsigned) DB_QueryCOUNT_new ("can not get number of institutions with degrees");
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -2511,17 +2495,14 @@ unsigned Ins_GetNumInssWithDegs (const char *SubQuery)
|
|||
|
||||
unsigned Ins_GetNumInssWithCrss (const char *SubQuery)
|
||||
{
|
||||
char *Query;
|
||||
|
||||
/***** Get number of institutions with courses from database *****/
|
||||
if (asprintf (&Query,"SELECT COUNT(DISTINCT institutions.InsCod)"
|
||||
" FROM institutions,centres,degrees,courses"
|
||||
" WHERE %sinstitutions.InsCod=centres.InsCod"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod",
|
||||
SubQuery) < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
return (unsigned) DB_QueryCOUNT_free (Query,"can not get number of institutions with courses");
|
||||
DB_BuildQuery ("SELECT COUNT(DISTINCT institutions.InsCod)"
|
||||
" FROM institutions,centres,degrees,courses"
|
||||
" WHERE %sinstitutions.InsCod=centres.InsCod"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod",
|
||||
SubQuery);
|
||||
return (unsigned) DB_QueryCOUNT_new ("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)
|
||||
{
|
||||
char *Query;
|
||||
|
||||
/***** Get number of institutions with users from database *****/
|
||||
if (asprintf (&Query,"SELECT COUNT(DISTINCT institutions.InsCod)"
|
||||
" FROM institutions,centres,degrees,courses,crs_usr"
|
||||
" WHERE %sinstitutions.InsCod=centres.InsCod"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=crs_usr.CrsCod"
|
||||
" AND crs_usr.Role=%u",
|
||||
SubQuery,(unsigned) Role) < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
return (unsigned) DB_QueryCOUNT_free (Query,"can not get number of institutions with users");
|
||||
DB_BuildQuery ("SELECT COUNT(DISTINCT institutions.InsCod)"
|
||||
" FROM institutions,centres,degrees,courses,crs_usr"
|
||||
" WHERE %sinstitutions.InsCod=centres.InsCod"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=crs_usr.CrsCod"
|
||||
" AND crs_usr.Role=%u",
|
||||
SubQuery,(unsigned) Role);
|
||||
return (unsigned) DB_QueryCOUNT_new ("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)
|
||||
{
|
||||
char *Query;
|
||||
|
||||
/***** Get number of links with a name from database *****/
|
||||
if (asprintf (&Query,"SELECT COUNT(*) FROM links WHERE %s='%s' AND LnkCod<>%ld",
|
||||
FieldName,Name,LnkCod) < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
return (DB_QueryCOUNT_free (Query,"can not check if the name of an institutional link already existed") != 0);
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM links WHERE %s='%s' AND LnkCod<>%ld",
|
||||
FieldName,Name,LnkCod);
|
||||
return (DB_QueryCOUNT_new ("can not check if the name of an institutional link already existed") != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
31
swad_mail.c
31
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])
|
||||
{
|
||||
char *Query;
|
||||
|
||||
/***** Get number of mail_domains with a name from database *****/
|
||||
if (asprintf (&Query,"SELECT COUNT(*) FROM mail_domains WHERE Domain='%s'",
|
||||
MailDomain) < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
return (DB_QueryCOUNT_free (Query,"can not check if a mail domain is allowed for notifications") != 0);
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM mail_domains WHERE Domain='%s'",
|
||||
MailDomain);
|
||||
return (DB_QueryCOUNT_new ("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)
|
||||
{
|
||||
char *Query;
|
||||
|
||||
/***** Get number of mail_domains with a name from database *****/
|
||||
if (asprintf (&Query,"SELECT COUNT(*) FROM mail_domains"
|
||||
" WHERE %s='%s' AND MaiCod<>%ld",
|
||||
FieldName,Name,MaiCod) < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
return (DB_QueryCOUNT_free (Query,"can not check if the name of a mail domain already existed") != 0);
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM mail_domains"
|
||||
" WHERE %s='%s' AND MaiCod<>%ld",
|
||||
FieldName,Name,MaiCod);
|
||||
return (DB_QueryCOUNT_new ("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;
|
||||
|
||||
/***** Check if the new email matches any of the confirmed emails of other users *****/
|
||||
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_emails"
|
||||
" WHERE E_mail='%s' AND Confirmed='Y'"
|
||||
" AND UsrCod<>%ld",
|
||||
NewEmail,UsrDat->UsrCod) < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
if (DB_QueryCOUNT_free (Query,"can not check if email already existed")) // An email of another user is the same that my email
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM usr_emails"
|
||||
" WHERE E_mail='%s' AND Confirmed='Y'"
|
||||
" AND UsrCod<>%ld",
|
||||
NewEmail,UsrDat->UsrCod);
|
||||
if (DB_QueryCOUNT_new ("can not check if email already existed")) // An email of another user is the same that my email
|
||||
return false; // Don't update
|
||||
|
||||
/***** Delete email (not confirmed) for other users *****/
|
||||
|
|
764
swad_message.c
764
swad_message.c
File diff suppressed because it is too large
Load Diff
|
@ -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_has_been_registered_successfully;
|
||||
extern const char *Txt_The_nickname_entered_X_is_not_valid_;
|
||||
char *Query;
|
||||
char NewNicknameWithArroba[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
|
||||
{
|
||||
/***** Check if the new nickname matches any of my old nicknames *****/
|
||||
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_nicknames"
|
||||
" WHERE UsrCod=%ld AND Nickname='%s'",
|
||||
UsrDat->UsrCod,NewNicknameWithoutArroba) < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
if (!DB_QueryCOUNT_free (Query,"can not check if nickname already existed")) // No matches
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM usr_nicknames"
|
||||
" WHERE UsrCod=%ld AND Nickname='%s'",
|
||||
UsrDat->UsrCod,NewNicknameWithoutArroba);
|
||||
if (!DB_QueryCOUNT_new ("can not check if nickname already existed")) // No matches
|
||||
{
|
||||
/***** Check if the new nickname matches any of the nicknames of other users *****/
|
||||
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_nicknames"
|
||||
" WHERE Nickname='%s' AND UsrCod<>%ld",
|
||||
NewNicknameWithoutArroba,UsrDat->UsrCod) < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
if (DB_QueryCOUNT_free (Query,"can not check if nickname already existed")) // A nickname of another user is the same that user's nickname
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM usr_nicknames"
|
||||
" WHERE Nickname='%s' AND UsrCod<>%ld",
|
||||
NewNicknameWithoutArroba,UsrDat->UsrCod);
|
||||
if (DB_QueryCOUNT_new ("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.Section = Nck_NICKNAME_SECTION_ID;
|
||||
|
|
|
@ -2120,15 +2120,12 @@ void Ntf_WriteNumberOfNewNtfs (void)
|
|||
|
||||
static unsigned Ntf_GetNumberOfAllMyUnseenNtfs (void)
|
||||
{
|
||||
char *Query;
|
||||
|
||||
/***** Get number of places with a name from database *****/
|
||||
if (asprintf (&Query,"SELECT COUNT(*) FROM notif"
|
||||
" WHERE ToUsrCod=%ld AND (Status & %u)=0",
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED)) < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
return DB_QueryCOUNT_free (Query,"can not get number of unseen notifications");
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM notif"
|
||||
" WHERE ToUsrCod=%ld AND (Status & %u)=0",
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED));
|
||||
return DB_QueryCOUNT_new ("can not get number of unseen notifications");
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -2137,17 +2134,14 @@ static unsigned Ntf_GetNumberOfAllMyUnseenNtfs (void)
|
|||
|
||||
static unsigned Ntf_GetNumberOfMyNewUnseenNtfs (void)
|
||||
{
|
||||
char *Query;
|
||||
|
||||
/***** Get number of places with a name from database *****/
|
||||
if (asprintf (&Query,"SELECT COUNT(*) FROM notif"
|
||||
" WHERE ToUsrCod=%ld AND (Status & %u)=0"
|
||||
" AND TimeNotif>FROM_UNIXTIME(%ld)",
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED),
|
||||
Gbl.Usrs.Me.UsrLast.LastAccNotif) < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
return DB_QueryCOUNT_free (Query,"can not get number of unseen notifications");
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM notif"
|
||||
" WHERE ToUsrCod=%ld AND (Status & %u)=0"
|
||||
" AND TimeNotif>FROM_UNIXTIME(%ld)",
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED),
|
||||
Gbl.Usrs.Me.UsrLast.LastAccNotif);
|
||||
return DB_QueryCOUNT_new ("can not get number of unseen notifications");
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -578,23 +578,20 @@ bool Pwd_SlowCheckIfPasswordIsGood (const char *PlainPassword,
|
|||
|
||||
static bool Pwd_CheckIfPasswdIsUsrIDorName (const char *PlainPassword)
|
||||
{
|
||||
char *Query;
|
||||
bool Found;
|
||||
|
||||
/***** Get if password is found in user's ID from database *****/
|
||||
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_IDs WHERE UsrID='%s'",
|
||||
PlainPassword) < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
Found = (DB_QueryCOUNT_free (Query,"can not check if a password matches a user's ID") != 0);
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM usr_IDs WHERE UsrID='%s'",
|
||||
PlainPassword);
|
||||
Found = (DB_QueryCOUNT_new ("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 *****/
|
||||
if (!Found)
|
||||
{
|
||||
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_data"
|
||||
" WHERE FirstName='%s' OR Surname1='%s' OR Surname2='%s'",
|
||||
PlainPassword,PlainPassword,PlainPassword) < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
Found = (DB_QueryCOUNT_free (Query,"can not check if a password matches a first name or a surname") != 0);
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM usr_data"
|
||||
" WHERE FirstName='%s' OR Surname1='%s' OR Surname2='%s'",
|
||||
PlainPassword,PlainPassword,PlainPassword);
|
||||
Found = (DB_QueryCOUNT_new ("can not check if a password matches a first name or a surname") != 0);
|
||||
}
|
||||
|
||||
return Found;
|
||||
|
@ -606,25 +603,17 @@ static bool Pwd_CheckIfPasswdIsUsrIDorName (const char *PlainPassword)
|
|||
|
||||
static unsigned Pwd_GetNumOtherUsrsWhoUseThisPassword (const char *EncryptedPassword,long UsrCod)
|
||||
{
|
||||
char *Query;
|
||||
|
||||
/***** Get number of other users who use a password from database *****/
|
||||
/* Query database */
|
||||
if (UsrCod > 0)
|
||||
{
|
||||
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_data"
|
||||
" WHERE Password='%s' AND UsrCod<>%ld",
|
||||
EncryptedPassword,UsrCod) < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
}
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM usr_data"
|
||||
" WHERE Password='%s' AND UsrCod<>%ld",
|
||||
EncryptedPassword,UsrCod);
|
||||
else
|
||||
{
|
||||
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_data"
|
||||
" WHERE Password='%s'",
|
||||
EncryptedPassword) < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
}
|
||||
return (unsigned) DB_QueryCOUNT_free (Query,"can not check if a password is trivial");
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM usr_data"
|
||||
" WHERE Password='%s'",
|
||||
EncryptedPassword);
|
||||
return (unsigned) DB_QueryCOUNT_new ("can not check if a password is trivial");
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
11
swad_place.c
11
swad_place.c
|
@ -705,14 +705,11 @@ static void Plc_RenamePlace (Cns_ShrtOrFullName_t ShrtOrFullName)
|
|||
|
||||
static bool Plc_CheckIfPlaceNameExists (const char *FieldName,const char *Name,long PlcCod)
|
||||
{
|
||||
char *Query;
|
||||
|
||||
/***** Get number of places with a name from database *****/
|
||||
if (asprintf (&Query,"SELECT COUNT(*) FROM places"
|
||||
" WHERE InsCod=%ld AND %s='%s' AND PlcCod<>%ld",
|
||||
Gbl.CurrentIns.Ins.InsCod,FieldName,Name,PlcCod) < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
return (DB_QueryCOUNT_free (Query,"can not check if the name of a place already existed") != 0);
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM places"
|
||||
" WHERE InsCod=%ld AND %s='%s' AND PlcCod<>%ld",
|
||||
Gbl.CurrentIns.Ins.InsCod,FieldName,Name,PlcCod);
|
||||
return (DB_QueryCOUNT_new ("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)
|
||||
{
|
||||
char *Query;
|
||||
|
||||
/***** Get number of plugins with a name from database *****/
|
||||
if (asprintf (&Query,"SELECT COUNT(*) FROM plugins"
|
||||
" WHERE Name='%s' AND PlgCod<>%ld",
|
||||
Name,PlgCod) < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
return (DB_QueryCOUNT_free (Query,"can not check if the name of a plugin already existed") != 0);
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM plugins"
|
||||
" WHERE Name='%s' AND PlgCod<>%ld",
|
||||
Name,PlgCod);
|
||||
return (DB_QueryCOUNT_new ("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)
|
||||
{
|
||||
char *Query;
|
||||
|
||||
/***** Select number of rows with figure
|
||||
greater than the figure of this user *****/
|
||||
if (asprintf (&Query,"SELECT COUNT(*)+1 FROM usr_figures"
|
||||
" WHERE UsrCod<>%ld" // Really not necessary here
|
||||
" AND %s>"
|
||||
"(SELECT %s FROM usr_figures WHERE UsrCod=%ld)",
|
||||
UsrCod,FieldName,FieldName,UsrCod) < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
return DB_QueryCOUNT_free (Query,"can not get ranking using a figure");
|
||||
DB_BuildQuery ("SELECT COUNT(*)+1 FROM usr_figures"
|
||||
" WHERE UsrCod<>%ld" // Really not necessary here
|
||||
" AND %s>"
|
||||
"(SELECT %s FROM usr_figures WHERE UsrCod=%ld)",
|
||||
UsrCod,FieldName,FieldName,UsrCod);
|
||||
return DB_QueryCOUNT_new ("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)
|
||||
{
|
||||
char *Query;
|
||||
|
||||
/***** Select number of rows with values already calculated *****/
|
||||
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_figures WHERE %s>=0",
|
||||
FieldName) < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
return DB_QueryCOUNT_free (Query,"can not get number of users with a figure");
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM usr_figures WHERE %s>=0",FieldName);
|
||||
return DB_QueryCOUNT_new ("can not get number of users with a figure");
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -713,27 +706,24 @@ static unsigned long Prf_GetNumUsrsWithFigure (const char *FieldName)
|
|||
|
||||
static unsigned long Prf_GetRankingNumClicksPerDay (long UsrCod)
|
||||
{
|
||||
char *Query;
|
||||
|
||||
/***** Select number of rows with number of clicks per day
|
||||
greater than the clicks per day of this user *****/
|
||||
if (asprintf (&Query,"SELECT COUNT(*)+1 FROM"
|
||||
" (SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1)"
|
||||
" AS NumClicksPerDay"
|
||||
" FROM usr_figures"
|
||||
" WHERE UsrCod<>%ld" // Necessary because the following comparison is not exact in floating point
|
||||
" AND NumClicks>0"
|
||||
" AND UNIX_TIMESTAMP(FirstClickTime)>0)"
|
||||
" AS TableNumClicksPerDay"
|
||||
" WHERE NumClicksPerDay>"
|
||||
"(SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1)"
|
||||
" FROM usr_figures"
|
||||
" WHERE UsrCod=%ld"
|
||||
" AND NumClicks>0"
|
||||
" AND UNIX_TIMESTAMP(FirstClickTime)>0)",
|
||||
UsrCod,UsrCod) < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
return DB_QueryCOUNT_free (Query,"can not get ranking using number of clicks per day");
|
||||
DB_BuildQuery ("SELECT COUNT(*)+1 FROM"
|
||||
" (SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1)"
|
||||
" AS NumClicksPerDay"
|
||||
" FROM usr_figures"
|
||||
" WHERE UsrCod<>%ld" // Necessary because the following comparison is not exact in floating point
|
||||
" AND NumClicks>0"
|
||||
" AND UNIX_TIMESTAMP(FirstClickTime)>0)"
|
||||
" AS TableNumClicksPerDay"
|
||||
" WHERE NumClicksPerDay>"
|
||||
"(SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1)"
|
||||
" FROM usr_figures"
|
||||
" WHERE UsrCod=%ld"
|
||||
" AND NumClicks>0"
|
||||
" AND UNIX_TIMESTAMP(FirstClickTime)>0)",
|
||||
UsrCod,UsrCod);
|
||||
return DB_QueryCOUNT_new ("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)
|
||||
{
|
||||
char *Query;
|
||||
|
||||
/***** Select number of rows with values already calculated *****/
|
||||
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_figures"
|
||||
" WHERE NumClicks>0"
|
||||
" AND UNIX_TIMESTAMP(FirstClickTime)>0") < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
return DB_QueryCOUNT_free (Query,"can not get number of users with number of clicks per day");
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM usr_figures"
|
||||
" WHERE NumClicks>0"
|
||||
" AND UNIX_TIMESTAMP(FirstClickTime)>0");
|
||||
return DB_QueryCOUNT_new ("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);
|
||||
|
||||
/***** Get number of clicks from database *****/
|
||||
if (asprintf (&Query,"SELECT COUNT(*) FROM log_full WHERE UsrCod=%ld",
|
||||
UsrCod) < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
UsrFigures.NumClicks = (long) DB_QueryCOUNT_free (Query,"can not get number of clicks");
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM log_full WHERE UsrCod=%ld",UsrCod);
|
||||
UsrFigures.NumClicks = (long) DB_QueryCOUNT_new ("can not get number of clicks");
|
||||
|
||||
/***** Update number of clicks in user's figures *****/
|
||||
if (Prf_CheckIfUsrFiguresExists (UsrCod))
|
||||
|
@ -1101,12 +1086,8 @@ void Prf_RemoveUsrFigures (long UsrCod)
|
|||
|
||||
static bool Prf_CheckIfUsrFiguresExists (long UsrCod)
|
||||
{
|
||||
char *Query;
|
||||
|
||||
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);
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM usr_figures WHERE UsrCod=%ld",UsrCod);
|
||||
return (DB_QueryCOUNT_new ("can not get user's first click") != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -629,15 +629,12 @@ long Rec_GetFieldCod (void)
|
|||
|
||||
unsigned Rec_CountNumRecordsInCurrCrsWithField (long FieldCod)
|
||||
{
|
||||
char *Query;
|
||||
|
||||
/***** Get number of cards with a given field in a course from database *****/
|
||||
if (asprintf (&Query,"SELECT COUNT(*) FROM crs_records WHERE FieldCod=%ld",
|
||||
FieldCod) < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
return (unsigned) DB_QueryCOUNT_free (Query,"can not get number of cards"
|
||||
" with a given field not empty"
|
||||
" in a course");
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM crs_records WHERE FieldCod=%ld",
|
||||
FieldCod);
|
||||
return (unsigned) DB_QueryCOUNT_new ("can not get number of cards"
|
||||
" with a given field not empty"
|
||||
" in a course");
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
Loading…
Reference in New Issue