mirror of https://github.com/acanas/swad-core.git
Version 18.11.27
This commit is contained in:
parent
408fc80f28
commit
066fac7750
|
@ -842,10 +842,10 @@ static void ID_RemoveUsrID (const struct UsrData *UsrDat,bool ItsMe)
|
|||
static bool ID_CheckIfConfirmed (long UsrCod,const char *UsrID)
|
||||
{
|
||||
/***** Get if ID is confirmed from database *****/
|
||||
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);
|
||||
return (DB_QueryCOUNT ("can not check if ID is confirmed",
|
||||
"SELECT COUNT(*) FROM usr_IDs"
|
||||
" WHERE UsrCod=%ld AND UsrID='%s' AND Confirmed='Y'",
|
||||
UsrCod,UsrID) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -355,10 +355,12 @@ En OpenSWAD:
|
|||
ps2pdf source.ps destination.pdf
|
||||
*/
|
||||
|
||||
#define Log_PLATFORM_VERSION "SWAD 18.11.26 (2018-11-03)"
|
||||
#define Log_PLATFORM_VERSION "SWAD 18.11.27 (2018-11-03)"
|
||||
#define CSS_FILE "swad18.4.css"
|
||||
#define JS_FILE "swad17.17.1.js"
|
||||
/*
|
||||
Version 18.11.27: Nov 03, 2018 Joining building and performing query into one function.
|
||||
Some queries that used UNIX_TIMESTAMP(...)>0 optimized using ...>FROM_UNIXTIME(0). (237185 lines)
|
||||
Version 18.11.26: Nov 03, 2018 Joining building and performing query into one function. (236738 lines)
|
||||
Version 18.11.25: Nov 03, 2018 Joining building and performing query into one function. (236705 lines)
|
||||
Version 18.11.24: Nov 03, 2018 Joining building and performing query into one function. (236636 lines)
|
||||
|
|
|
@ -148,7 +148,7 @@ void Dup_ListDuplicateUsrs (void)
|
|||
/***** Make query *****/
|
||||
NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get possibly"
|
||||
" duplicate users",
|
||||
"SELECT UsrCod,COUNT(*) AS N,MIN(UNIX_TIMESTAMP(InformTime)) AS T"
|
||||
"SELECT UsrCod,COUNT(*) AS N,UNIX_TIMESTAMP(MIN(InformTime)) AS T"
|
||||
" FROM usr_duplicated"
|
||||
" GROUP BY UsrCod"
|
||||
" ORDER BY N DESC,T DESC");
|
||||
|
|
322
swad_forum.c
322
swad_forum.c
|
@ -2382,10 +2382,12 @@ static unsigned For_GetNumOfUnreadPostsInThr (long ThrCod,unsigned NumPostsInThr
|
|||
static unsigned For_GetNumOfPostsInThrNewerThan (long ThrCod,const char *Time)
|
||||
{
|
||||
/***** Get the number of posts in thread with a modify time > a specified time from database *****/
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM forum_post"
|
||||
" WHERE ThrCod=%ld AND ModifTime>'%s'",
|
||||
ThrCod,Time);
|
||||
return (unsigned) DB_QueryCOUNT_new ("can not check if there are new posts in a thread of a forum");
|
||||
return
|
||||
(unsigned) DB_QueryCOUNT ("can not check if there are new posts"
|
||||
" in a thread of a forum",
|
||||
"SELECT COUNT(*) FROM forum_post"
|
||||
" WHERE ThrCod=%ld AND ModifTime>'%s'",
|
||||
ThrCod,Time);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -2862,6 +2864,8 @@ unsigned For_GetNumTotalForumsOfType (For_ForumType_t ForumType,
|
|||
unsigned For_GetNumTotalThrsInForumsOfType (For_ForumType_t ForumType,
|
||||
long CtyCod,long InsCod,long CtrCod,long DegCod,long CrsCod)
|
||||
{
|
||||
unsigned NumThrs;
|
||||
|
||||
/***** Get total number of threads in forums of this type from database *****/
|
||||
switch (ForumType)
|
||||
{
|
||||
|
@ -2870,151 +2874,210 @@ unsigned For_GetNumTotalThrsInForumsOfType (For_ForumType_t ForumType,
|
|||
case For_FORUM__SWAD__USRS:
|
||||
case For_FORUM__SWAD__TCHS:
|
||||
// Total number of threads in forums of this type
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM forum_thread"
|
||||
" WHERE ForumType=%u",
|
||||
(unsigned) ForumType);
|
||||
NumThrs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get the number of threads"
|
||||
" in forums of a type",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM forum_thread"
|
||||
" WHERE ForumType=%u",
|
||||
(unsigned) ForumType);
|
||||
break;
|
||||
case For_FORUM_INSTIT_USRS:
|
||||
case For_FORUM_INSTIT_TCHS:
|
||||
if (InsCod > 0) // InsCod > 0 ==> Number of threads in institution forums for an institution
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM forum_thread"
|
||||
" WHERE ForumType=%u"
|
||||
" AND Location=%ld",
|
||||
(unsigned) ForumType,InsCod);
|
||||
NumThrs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get the number of threads"
|
||||
" in forums of a type",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM forum_thread"
|
||||
" WHERE ForumType=%u"
|
||||
" AND Location=%ld",
|
||||
(unsigned) ForumType,InsCod);
|
||||
else if (CtyCod > 0) // InsCod <= 0 && CtyCod > 0 ==> Number of threads in institution forums for a country
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM forum_thread,institutions"
|
||||
" WHERE forum_thread.ForumType=%u"
|
||||
" AND forum_thread.Location=institutions.InsCod"
|
||||
" AND institutions.CtyCod=%ld",
|
||||
(unsigned) ForumType,CtyCod);
|
||||
NumThrs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get the number of threads"
|
||||
" in forums of a type",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM forum_thread,institutions"
|
||||
" WHERE forum_thread.ForumType=%u"
|
||||
" AND forum_thread.Location=institutions.InsCod"
|
||||
" AND institutions.CtyCod=%ld",
|
||||
(unsigned) ForumType,CtyCod);
|
||||
else // InsCod <= 0 ==> Number of threads in institution forums for the whole platform
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM forum_thread"
|
||||
" WHERE ForumType=%u",
|
||||
(unsigned) ForumType);
|
||||
NumThrs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get the number of threads"
|
||||
" in forums of a type",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM forum_thread"
|
||||
" WHERE ForumType=%u",
|
||||
(unsigned) ForumType);
|
||||
break;
|
||||
case For_FORUM_CENTRE_USRS:
|
||||
case For_FORUM_CENTRE_TCHS:
|
||||
if (CtrCod > 0) // CtrCod > 0 ==> 0 <= Number of threads in centre forums for a centre <= 1
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM forum_thread"
|
||||
" WHERE ForumType=%u"
|
||||
" AND Location=%ld",
|
||||
(unsigned) ForumType,CtrCod);
|
||||
NumThrs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get the number of threads"
|
||||
" in forums of a type",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM forum_thread"
|
||||
" WHERE ForumType=%u"
|
||||
" AND Location=%ld",
|
||||
(unsigned) ForumType,CtrCod);
|
||||
else if (InsCod > 0) // CtrCod <= 0 && InsCod > 0 ==> Number of threads in centre forums for an institution
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM forum_thread,centres"
|
||||
" WHERE forum_thread.ForumType=%u"
|
||||
" AND forum_thread.Location=centres.CtrCod"
|
||||
" AND centres.InsCod=%ld",
|
||||
(unsigned) ForumType,InsCod);
|
||||
NumThrs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get the number of threads"
|
||||
" in forums of a type",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM forum_thread,centres"
|
||||
" WHERE forum_thread.ForumType=%u"
|
||||
" AND forum_thread.Location=centres.CtrCod"
|
||||
" AND centres.InsCod=%ld",
|
||||
(unsigned) ForumType,InsCod);
|
||||
else if (CtyCod > 0) // InsCod <= 0 && CtyCod > 0 ==> Number of threads in centre forums for a country
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM forum_thread,centres,institutions"
|
||||
" WHERE forum_thread.ForumType=%u"
|
||||
" AND forum_thread.Location=centres.CtrCod"
|
||||
" AND centres.InsCod=institutions.InsCod"
|
||||
" AND institutions.CtyCod=%ld",
|
||||
(unsigned) ForumType,CtyCod);
|
||||
NumThrs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get the number of threads"
|
||||
" in forums of a type",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM forum_thread,centres,institutions"
|
||||
" WHERE forum_thread.ForumType=%u"
|
||||
" AND forum_thread.Location=centres.CtrCod"
|
||||
" AND centres.InsCod=institutions.InsCod"
|
||||
" AND institutions.CtyCod=%ld",
|
||||
(unsigned) ForumType,CtyCod);
|
||||
else // InsCod <= 0 ==> Number of threads in centre forums for the whole platform
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM forum_thread"
|
||||
" WHERE ForumType=%u",
|
||||
(unsigned) ForumType);
|
||||
NumThrs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get the number of threads"
|
||||
" in forums of a type",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM forum_thread"
|
||||
" WHERE ForumType=%u",
|
||||
(unsigned) ForumType);
|
||||
break;
|
||||
case For_FORUM_DEGREE_USRS:
|
||||
case For_FORUM_DEGREE_TCHS:
|
||||
if (DegCod > 0) // DegCod > 0 ==> Number of threads in degree forums for a degree
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM forum_thread"
|
||||
" WHERE ForumType=%u"
|
||||
" AND Location=%ld",
|
||||
(unsigned) ForumType,DegCod);
|
||||
NumThrs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get the number of threads"
|
||||
" in forums of a type",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM forum_thread"
|
||||
" WHERE ForumType=%u"
|
||||
" AND Location=%ld",
|
||||
(unsigned) ForumType,DegCod);
|
||||
else if (CtrCod > 0) // DegCod <= 0 && CtrCod > 0 ==> Number of threads in degree forums for a centre
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM forum_thread,degrees"
|
||||
" WHERE forum_thread.ForumType=%u"
|
||||
" AND forum_thread.Location=degrees.DegCod"
|
||||
" AND degrees.CtrCod=%ld",
|
||||
(unsigned) ForumType,CtrCod);
|
||||
NumThrs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get the number of threads"
|
||||
" in forums of a type",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM forum_thread,degrees"
|
||||
" WHERE forum_thread.ForumType=%u"
|
||||
" AND forum_thread.Location=degrees.DegCod"
|
||||
" AND degrees.CtrCod=%ld",
|
||||
(unsigned) ForumType,CtrCod);
|
||||
else if (InsCod > 0) // CtrCod <= 0 && InsCod > 0 ==> Number of threads in degree forums for an institution
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM forum_thread,degrees,centres"
|
||||
" WHERE forum_thread.ForumType=%u"
|
||||
" AND forum_thread.Location=degrees.DegCod"
|
||||
" AND degrees.CtrCod=centres.CtrCod"
|
||||
" AND centres.InsCod=%ld",
|
||||
(unsigned) ForumType,InsCod);
|
||||
NumThrs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get the number of threads"
|
||||
" in forums of a type",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM forum_thread,degrees,centres"
|
||||
" WHERE forum_thread.ForumType=%u"
|
||||
" AND forum_thread.Location=degrees.DegCod"
|
||||
" AND degrees.CtrCod=centres.CtrCod"
|
||||
" AND centres.InsCod=%ld",
|
||||
(unsigned) ForumType,InsCod);
|
||||
else if (CtyCod > 0) // InsCod <= 0 && CtyCod > 0 ==> Number of threads in degree forums for a country
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM forum_thread,degrees,centres,institutions"
|
||||
" WHERE forum_thread.ForumType=%u"
|
||||
" AND forum_thread.Location=degrees.DegCod"
|
||||
" AND degrees.CtrCod=centres.CtrCod"
|
||||
" AND centres.InsCod=institutions.InsCod"
|
||||
" AND institutions.CtyCod=%ld",
|
||||
(unsigned) ForumType,CtyCod);
|
||||
NumThrs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get the number of threads"
|
||||
" in forums of a type",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM forum_thread,degrees,centres,institutions"
|
||||
" WHERE forum_thread.ForumType=%u"
|
||||
" AND forum_thread.Location=degrees.DegCod"
|
||||
" AND degrees.CtrCod=centres.CtrCod"
|
||||
" AND centres.InsCod=institutions.InsCod"
|
||||
" AND institutions.CtyCod=%ld",
|
||||
(unsigned) ForumType,CtyCod);
|
||||
else // InsCod <= 0 ==> Number of threads in degree forums for the whole platform
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM forum_thread"
|
||||
" WHERE ForumType=%u",
|
||||
(unsigned) ForumType);
|
||||
NumThrs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get the number of threads"
|
||||
" in forums of a type",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM forum_thread"
|
||||
" WHERE ForumType=%u",
|
||||
(unsigned) ForumType);
|
||||
break;
|
||||
case For_FORUM_COURSE_USRS:
|
||||
case For_FORUM_COURSE_TCHS:
|
||||
if (CrsCod > 0) // CrsCod > 0 ==> 0 <= Number of threads in course forums for a course
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM forum_thread"
|
||||
" WHERE ForumType=%u"
|
||||
" AND Location=%ld",
|
||||
(unsigned) ForumType,CrsCod);
|
||||
NumThrs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get the number of threads"
|
||||
" in forums of a type",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM forum_thread"
|
||||
" WHERE ForumType=%u"
|
||||
" AND Location=%ld",
|
||||
(unsigned) ForumType,CrsCod);
|
||||
else if (DegCod > 0) // CrsCod <= 0 && DegCod > 0 ==> Number of threads in course forums for a degree
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM forum_thread,courses"
|
||||
" WHERE forum_thread.ForumType=%u"
|
||||
" AND forum_thread.Location=courses.CrsCod"
|
||||
" AND courses.DegCod=%ld",
|
||||
(unsigned) ForumType,DegCod);
|
||||
NumThrs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get the number of threads"
|
||||
" in forums of a type",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM forum_thread,courses"
|
||||
" WHERE forum_thread.ForumType=%u"
|
||||
" AND forum_thread.Location=courses.CrsCod"
|
||||
" AND courses.DegCod=%ld",
|
||||
(unsigned) ForumType,DegCod);
|
||||
else if (CtrCod > 0) // DegCod <= 0 && CtrCod > 0 ==> Number of threads in course forums for a centre
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM forum_thread,courses,degrees"
|
||||
" WHERE forum_thread.ForumType=%u"
|
||||
" AND forum_thread.Location=courses.CrsCod"
|
||||
" AND courses.DegCod=degrees.DegCod"
|
||||
" AND degrees.CtrCod=%ld",
|
||||
(unsigned) ForumType,CtrCod);
|
||||
NumThrs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get the number of threads"
|
||||
" in forums of a type",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM forum_thread,courses,degrees"
|
||||
" WHERE forum_thread.ForumType=%u"
|
||||
" AND forum_thread.Location=courses.CrsCod"
|
||||
" AND courses.DegCod=degrees.DegCod"
|
||||
" AND degrees.CtrCod=%ld",
|
||||
(unsigned) ForumType,CtrCod);
|
||||
else if (InsCod > 0) // CtrCod <= 0 && InsCod > 0 ==> Number of threads in course forums for an institution
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM forum_thread,courses,degrees,centres"
|
||||
" WHERE forum_thread.ForumType=%u"
|
||||
" AND forum_thread.Location=courses.CrsCod"
|
||||
" AND courses.DegCod=degrees.DegCod"
|
||||
" AND degrees.CtrCod=centres.CtrCod"
|
||||
" AND centres.InsCod=%ld",
|
||||
(unsigned) ForumType,InsCod);
|
||||
NumThrs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get the number of threads"
|
||||
" in forums of a type",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM forum_thread,courses,degrees,centres"
|
||||
" WHERE forum_thread.ForumType=%u"
|
||||
" AND forum_thread.Location=courses.CrsCod"
|
||||
" AND courses.DegCod=degrees.DegCod"
|
||||
" AND degrees.CtrCod=centres.CtrCod"
|
||||
" AND centres.InsCod=%ld",
|
||||
(unsigned) ForumType,InsCod);
|
||||
else if (CtyCod > 0) // InsCod <= 0 && CtyCod > 0 ==> Number of threads in course forums for a country
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM forum_thread,courses,degrees,centres,institutions"
|
||||
" WHERE forum_thread.ForumType=%u"
|
||||
" AND forum_thread.Location=courses.CrsCod"
|
||||
" AND courses.DegCod=degrees.DegCod"
|
||||
" AND degrees.CtrCod=centres.CtrCod"
|
||||
" AND centres.InsCod=institutions.InsCod"
|
||||
" AND institutions.CtyCod=%ld",
|
||||
(unsigned) ForumType,CtyCod);
|
||||
NumThrs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get the number of threads"
|
||||
" in forums of a type",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM forum_thread,courses,degrees,centres,institutions"
|
||||
" WHERE forum_thread.ForumType=%u"
|
||||
" AND forum_thread.Location=courses.CrsCod"
|
||||
" AND courses.DegCod=degrees.DegCod"
|
||||
" AND degrees.CtrCod=centres.CtrCod"
|
||||
" AND centres.InsCod=institutions.InsCod"
|
||||
" AND institutions.CtyCod=%ld",
|
||||
(unsigned) ForumType,CtyCod);
|
||||
else // InsCod <= 0 ==> Number of threads in course forums for the whole platform
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM forum_thread"
|
||||
" WHERE ForumType=%u",
|
||||
(unsigned) ForumType);
|
||||
NumThrs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get the number of threads"
|
||||
" in forums of a type",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM forum_thread"
|
||||
" WHERE ForumType=%u",
|
||||
(unsigned) ForumType);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
NumThrs = 0;
|
||||
break;
|
||||
}
|
||||
return (unsigned) DB_QueryCOUNT_new ("can not get the number of threads in forums of a type");
|
||||
|
||||
return NumThrs;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -3030,9 +3093,11 @@ static unsigned For_GetNumThrsInForum (struct Forum *Forum)
|
|||
sprintf (SubQuery," AND Location=%ld",Forum->Location);
|
||||
else
|
||||
SubQuery[0] = '\0';
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM forum_thread WHERE ForumType=%u%s",
|
||||
(unsigned) Forum->Type,SubQuery);
|
||||
return (unsigned) DB_QueryCOUNT_new ("can not get number of threads in a forum");
|
||||
return
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of threads in a forum",
|
||||
"SELECT COUNT(*) FROM forum_thread"
|
||||
" WHERE ForumType=%u%s",
|
||||
(unsigned) Forum->Type,SubQuery);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -3291,11 +3356,12 @@ static unsigned For_GetNumPstsInForum (struct Forum *Forum)
|
|||
sprintf (SubQuery," AND forum_thread.Location=%ld",Forum->Location);
|
||||
else
|
||||
SubQuery[0] = '\0';
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM forum_thread,forum_post "
|
||||
" WHERE forum_thread.ForumType=%u%s"
|
||||
" AND forum_thread.ThrCod=forum_post.ThrCod",
|
||||
(unsigned) Forum->Type,SubQuery);
|
||||
return (unsigned) DB_QueryCOUNT_new ("can not get the number of posts in a forum");
|
||||
return
|
||||
(unsigned) DB_QueryCOUNT ("can not get the number of posts in a forum",
|
||||
"SELECT COUNT(*) FROM forum_thread,forum_post "
|
||||
" WHERE forum_thread.ForumType=%u%s"
|
||||
" AND forum_thread.ThrCod=forum_post.ThrCod",
|
||||
(unsigned) Forum->Type,SubQuery);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -4409,10 +4475,10 @@ static bool For_CheckIfThrBelongsToForum (long ThrCod,struct Forum *Forum)
|
|||
sprintf (SubQuery," AND forum_thread.Location=%ld",Forum->Location);
|
||||
else
|
||||
SubQuery[0] = '\0';
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM forum_thread"
|
||||
" WHERE ThrCod=%ld AND ForumType=%u%s",
|
||||
ThrCod,(unsigned) Forum->Type,SubQuery);
|
||||
return (DB_QueryCOUNT_new ("can not get if a thread belong to current forum") != 0);
|
||||
return (DB_QueryCOUNT ("can not get if a thread belong to current forum",
|
||||
"SELECT COUNT(*) FROM forum_thread"
|
||||
" WHERE ThrCod=%ld AND ForumType=%u%s",
|
||||
ThrCod,(unsigned) Forum->Type,SubQuery) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
64
swad_game.c
64
swad_game.c
|
@ -1715,12 +1715,12 @@ static bool Gam_CheckIfSimilarGameExists (struct Game *Game)
|
|||
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
|
||||
|
||||
/***** Get number of games with a field value from database *****/
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM games"
|
||||
" WHERE Scope='%s' AND Cod=%ld"
|
||||
" AND Title='%s' AND GamCod<>%ld",
|
||||
Sco_ScopeDB[Game->Scope],Game->Cod,
|
||||
Game->Title,Game->GamCod);
|
||||
return (DB_QueryCOUNT_new ("can not get similar games") != 0);
|
||||
return (DB_QueryCOUNT ("can not get similar games",
|
||||
"SELECT COUNT(*) FROM games"
|
||||
" WHERE Scope='%s' AND Cod=%ld"
|
||||
" AND Title='%s' AND GamCod<>%ld",
|
||||
Sco_ScopeDB[Game->Scope],Game->Cod,
|
||||
Game->Title,Game->GamCod) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -2254,8 +2254,9 @@ static void Gam_UpdateGame (struct Game *Game,const char *Txt)
|
|||
static bool Gam_CheckIfGamIsAssociatedToGrps (long GamCod)
|
||||
{
|
||||
/***** Get if a game is associated to a group from database *****/
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM gam_grp WHERE GamCod=%ld",GamCod);
|
||||
return (DB_QueryCOUNT_new ("can not check if a game is associated to groups") != 0);
|
||||
return (DB_QueryCOUNT ("can not check if a game is associated to groups",
|
||||
"SELECT COUNT(*) FROM gam_grp WHERE GamCod=%ld",
|
||||
GamCod) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -2265,10 +2266,10 @@ static bool Gam_CheckIfGamIsAssociatedToGrps (long GamCod)
|
|||
bool Gam_CheckIfGamIsAssociatedToGrp (long GamCod,long GrpCod)
|
||||
{
|
||||
/***** Get if a game is associated to a group from database *****/
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM gam_grp"
|
||||
" WHERE GamCod=%ld AND GrpCod=%ld",
|
||||
GamCod,GrpCod);
|
||||
return (DB_QueryCOUNT_new ("can not check if a game is associated to a group") != 0);
|
||||
return (DB_QueryCOUNT ("can not check if a game is associated to a group",
|
||||
"SELECT COUNT(*) FROM gam_grp"
|
||||
" WHERE GamCod=%ld AND GrpCod=%ld",
|
||||
GamCod,GrpCod) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -2457,14 +2458,14 @@ void Gam_RemoveGames (Sco_Scope_t Scope,long Cod)
|
|||
static bool Gam_CheckIfICanDoThisGameBasedOnGrps (long GamCod)
|
||||
{
|
||||
/***** Get if I can do a game from database *****/
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM games"
|
||||
" WHERE GamCod=%ld"
|
||||
" AND (GamCod NOT IN (SELECT GamCod FROM gam_grp) OR"
|
||||
" GamCod IN (SELECT gam_grp.GamCod FROM gam_grp,crs_grp_usr"
|
||||
" WHERE crs_grp_usr.UsrCod=%ld"
|
||||
" AND gam_grp.GrpCod=crs_grp_usr.GrpCod))",
|
||||
GamCod,Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||
return (DB_QueryCOUNT_new ("can not check if I can do a game") != 0);
|
||||
return (DB_QueryCOUNT ("can not check if I can do a game",
|
||||
"SELECT COUNT(*) FROM games"
|
||||
" WHERE GamCod=%ld"
|
||||
" AND (GamCod NOT IN (SELECT GamCod FROM gam_grp) OR"
|
||||
" GamCod IN (SELECT gam_grp.GamCod FROM gam_grp,crs_grp_usr"
|
||||
" WHERE crs_grp_usr.UsrCod=%ld"
|
||||
" AND gam_grp.GrpCod=crs_grp_usr.GrpCod))",
|
||||
GamCod,Gbl.Usrs.Me.UsrDat.UsrCod) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -2474,8 +2475,11 @@ static bool Gam_CheckIfICanDoThisGameBasedOnGrps (long GamCod)
|
|||
static unsigned Gam_GetNumQstsGame (long GamCod)
|
||||
{
|
||||
/***** Get data of questions from database *****/
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM gam_questions WHERE GamCod=%ld",GamCod);
|
||||
return (unsigned) DB_QueryCOUNT_new ("can not get number of questions of a game");
|
||||
return
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of questions of a game",
|
||||
"SELECT COUNT(*) FROM gam_questions"
|
||||
" WHERE GamCod=%ld",
|
||||
GamCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -3788,10 +3792,10 @@ static void Gam_RegisterIHaveAnsweredGame (long GamCod)
|
|||
static bool Gam_CheckIfIHaveAnsweredGame (long GamCod)
|
||||
{
|
||||
/***** Get number of games with a field value from database *****/
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM gam_users"
|
||||
" WHERE GamCod=%ld AND UsrCod=%ld",
|
||||
GamCod,Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||
return (DB_QueryCOUNT_new ("can not check if you have answered a game") != 0);
|
||||
return (DB_QueryCOUNT ("can not check if you have answered a game",
|
||||
"SELECT COUNT(*) FROM gam_users"
|
||||
" WHERE GamCod=%ld AND UsrCod=%ld",
|
||||
GamCod,Gbl.Usrs.Me.UsrDat.UsrCod) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -3801,8 +3805,12 @@ static bool Gam_CheckIfIHaveAnsweredGame (long GamCod)
|
|||
static unsigned Gam_GetNumUsrsWhoHaveAnsweredGame (long GamCod)
|
||||
{
|
||||
/***** Get number of games with a field value from database *****/
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM gam_users WHERE GamCod=%ld",GamCod);
|
||||
return (unsigned) DB_QueryCOUNT_new ("can not get number of users who have answered a game");
|
||||
return
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of users"
|
||||
" who have answered a game",
|
||||
"SELECT COUNT(*) FROM gam_users"
|
||||
" WHERE GamCod=%ld",
|
||||
GamCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
256
swad_group.c
256
swad_group.c
|
@ -2955,11 +2955,12 @@ void Grp_FreeListGrpTypesAndGrps (void)
|
|||
unsigned Grp_CountNumGrpsInCurrentCrs (void)
|
||||
{
|
||||
/***** Get number of group in current course from database *****/
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM crs_grp_types,crs_grp"
|
||||
" WHERE crs_grp_types.CrsCod=%ld"
|
||||
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod",
|
||||
Gbl.CurrentCrs.Crs.CrsCod);
|
||||
return (unsigned) DB_QueryCOUNT_new ("can not get number of groups in this course");
|
||||
return
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of groups in this course",
|
||||
"SELECT COUNT(*) FROM crs_grp_types,crs_grp"
|
||||
" WHERE crs_grp_types.CrsCod=%ld"
|
||||
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod",
|
||||
Gbl.CurrentCrs.Crs.CrsCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -2969,9 +2970,11 @@ unsigned Grp_CountNumGrpsInCurrentCrs (void)
|
|||
static unsigned Grp_CountNumGrpsInThisCrsOfType (long GrpTypCod)
|
||||
{
|
||||
/***** Get number of groups of a type from database *****/
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM crs_grp WHERE GrpTypCod=%ld",
|
||||
GrpTypCod);
|
||||
return (unsigned) DB_QueryCOUNT_new ("can not get number of groups of a type");
|
||||
return
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of groups of a type",
|
||||
"SELECT COUNT(*) FROM crs_grp"
|
||||
" WHERE GrpTypCod=%ld",
|
||||
GrpTypCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -3170,8 +3173,9 @@ static long Grp_GetTypeOfGroupOfAGroup (long GrpCod)
|
|||
bool Grp_CheckIfGroupExists (long GrpCod)
|
||||
{
|
||||
/***** Get if a group exists from database *****/
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM crs_grp WHERE GrpCod=%ld",GrpCod);
|
||||
return (DB_QueryCOUNT_new ("can not check if a group exists") != 0);
|
||||
return (DB_QueryCOUNT ("can not check if a group exists",
|
||||
"SELECT COUNT(*) FROM crs_grp WHERE GrpCod=%ld",
|
||||
GrpCod) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -3181,12 +3185,12 @@ bool Grp_CheckIfGroupExists (long GrpCod)
|
|||
bool Grp_CheckIfGroupBelongsToCourse (long GrpCod,long CrsCod)
|
||||
{
|
||||
/***** Get if a group exists from database *****/
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM crs_grp,crs_grp_types"
|
||||
" WHERE crs_grp.GrpCod=%ld"
|
||||
" AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod"
|
||||
" AND crs_grp_types.CrsCod=%ld",
|
||||
GrpCod,CrsCod);
|
||||
return (DB_QueryCOUNT_new ("can not check if a group belongs to a course") != 0);
|
||||
return (DB_QueryCOUNT ("can not check if a group belongs to a course",
|
||||
"SELECT COUNT(*) FROM crs_grp,crs_grp_types"
|
||||
" WHERE crs_grp.GrpCod=%ld"
|
||||
" AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod"
|
||||
" AND crs_grp_types.CrsCod=%ld",
|
||||
GrpCod,CrsCod) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -3196,16 +3200,17 @@ bool Grp_CheckIfGroupBelongsToCourse (long GrpCod,long CrsCod)
|
|||
unsigned Grp_CountNumUsrsInGrp (Rol_Role_t Role,long GrpCod)
|
||||
{
|
||||
/***** Get number of students in a group from database *****/
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM crs_grp_usr,crs_grp,crs_grp_types,crs_usr"
|
||||
" WHERE crs_grp_usr.GrpCod=%ld"
|
||||
" AND crs_grp_usr.GrpCod=crs_grp.GrpCod"
|
||||
" AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod"
|
||||
" AND crs_grp_types.CrsCod=crs_usr.CrsCod"
|
||||
" AND crs_grp_usr.UsrCod=crs_usr.UsrCod"
|
||||
" AND crs_usr.Role=%u",
|
||||
GrpCod,(unsigned) Role);
|
||||
return (unsigned) DB_QueryCOUNT_new ("can not get number of users in a group");
|
||||
return
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of users in a group",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM crs_grp_usr,crs_grp,crs_grp_types,crs_usr"
|
||||
" WHERE crs_grp_usr.GrpCod=%ld"
|
||||
" AND crs_grp_usr.GrpCod=crs_grp.GrpCod"
|
||||
" AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod"
|
||||
" AND crs_grp_types.CrsCod=crs_usr.CrsCod"
|
||||
" AND crs_grp_usr.UsrCod=crs_usr.UsrCod"
|
||||
" AND crs_usr.Role=%u",
|
||||
GrpCod,(unsigned) Role);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -3288,12 +3293,12 @@ bool Grp_GetIfIBelongToGrp (long GrpCod)
|
|||
return Gbl.Cache.IBelongToGrp.IBelong;
|
||||
|
||||
/***** 3. Slow check: Get if I belong to a group from database *****/
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM crs_grp_usr"
|
||||
" WHERE GrpCod=%ld AND UsrCod=%ld",
|
||||
GrpCod,Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||
Gbl.Cache.IBelongToGrp.GrpCod = GrpCod;
|
||||
Gbl.Cache.IBelongToGrp.IBelong = (DB_QueryCOUNT_new ("can not check"
|
||||
" if you belong to a group") != 0);
|
||||
Gbl.Cache.IBelongToGrp.IBelong =
|
||||
(DB_QueryCOUNT ("can not check if you belong to a group",
|
||||
"SELECT COUNT(*) FROM crs_grp_usr"
|
||||
" WHERE GrpCod=%ld AND UsrCod=%ld",
|
||||
GrpCod,Gbl.Usrs.Me.UsrDat.UsrCod) != 0);
|
||||
return Gbl.Cache.IBelongToGrp.IBelong;
|
||||
}
|
||||
|
||||
|
@ -3358,21 +3363,21 @@ bool Grp_CheckIfUsrSharesAnyOfMyGrpsInCurrentCrs (const struct UsrData *UsrDat)
|
|||
/***** 9. Slow check: Get if user shares any group in this course with me from database *****/
|
||||
/* Check if user shares any group with me */
|
||||
Gbl.Cache.UsrSharesAnyOfMyGrpsInCurrentCrs.UsrCod = UsrDat->UsrCod;
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM crs_grp_usr"
|
||||
" WHERE UsrCod=%ld"
|
||||
" AND GrpCod IN"
|
||||
" (SELECT crs_grp_usr.GrpCod"
|
||||
" FROM crs_grp_usr,crs_grp,crs_grp_types"
|
||||
" WHERE crs_grp_usr.UsrCod=%ld"
|
||||
" AND crs_grp_usr.GrpCod=crs_grp.GrpCod"
|
||||
" AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod"
|
||||
" AND crs_grp_types.CrsCod=%ld)",
|
||||
UsrDat->UsrCod,
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
Gbl.CurrentCrs.Crs.CrsCod);
|
||||
Gbl.Cache.UsrSharesAnyOfMyGrpsInCurrentCrs.Shares = (DB_QueryCOUNT_new ("can not check"
|
||||
" if a user shares any group"
|
||||
" in the current course with you") != 0);
|
||||
Gbl.Cache.UsrSharesAnyOfMyGrpsInCurrentCrs.Shares =
|
||||
(DB_QueryCOUNT ("can not check if a user shares any group"
|
||||
" in the current course with you",
|
||||
"SELECT COUNT(*) FROM crs_grp_usr"
|
||||
" WHERE UsrCod=%ld"
|
||||
" AND GrpCod IN"
|
||||
" (SELECT crs_grp_usr.GrpCod"
|
||||
" FROM crs_grp_usr,crs_grp,crs_grp_types"
|
||||
" WHERE crs_grp_usr.UsrCod=%ld"
|
||||
" AND crs_grp_usr.GrpCod=crs_grp.GrpCod"
|
||||
" AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod"
|
||||
" AND crs_grp_types.CrsCod=%ld)",
|
||||
UsrDat->UsrCod,
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
Gbl.CurrentCrs.Crs.CrsCod) != 0);
|
||||
return Gbl.Cache.UsrSharesAnyOfMyGrpsInCurrentCrs.Shares;
|
||||
}
|
||||
|
||||
|
@ -3388,36 +3393,37 @@ unsigned Grp_NumGrpTypesMandatIDontBelongAsStd (void)
|
|||
|
||||
/***** Get the number of types of groups with mandatory enrolment
|
||||
which I don't belong to as student, from database *****/
|
||||
DB_BuildQuery ("SELECT COUNT(DISTINCT GrpTypCod) FROM"
|
||||
" (SELECT crs_grp_types.GrpTypCod AS GrpTypCod,"
|
||||
"COUNT(*) AS NumStudents,"
|
||||
"crs_grp.MaxStudents as MaxStudents"
|
||||
" FROM crs_grp_types,crs_grp,crs_grp_usr,crs_usr"
|
||||
" WHERE crs_grp_types.CrsCod=%ld"
|
||||
" AND crs_grp_types.Mandatory='Y'"
|
||||
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
|
||||
" AND crs_grp.Open='Y'"
|
||||
" AND crs_grp_types.CrsCod=crs_usr.CrsCod"
|
||||
" AND crs_grp.GrpCod=crs_grp_usr.GrpCod"
|
||||
" AND crs_grp_usr.UsrCod=crs_usr.UsrCod"
|
||||
" AND crs_usr.Role=%u"
|
||||
" GROUP BY crs_grp.GrpCod"
|
||||
" HAVING NumStudents<MaxStudents) AS grp_types_open_not_full"
|
||||
" WHERE GrpTypCod NOT IN"
|
||||
" (SELECT DISTINCT crs_grp_types.GrpTypCod"
|
||||
" FROM crs_grp_types,crs_grp,crs_grp_usr"
|
||||
" WHERE crs_grp_types.CrsCod=%ld"
|
||||
" AND crs_grp_types.Mandatory='Y'"
|
||||
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
|
||||
" AND crs_grp.GrpCod=crs_grp_usr.GrpCod"
|
||||
" AND crs_grp_usr.UsrCod=%ld)",
|
||||
Gbl.CurrentCrs.Crs.CrsCod,
|
||||
(unsigned) Rol_STD,
|
||||
Gbl.CurrentCrs.Crs.CrsCod,
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||
NumGrpTypes = DB_QueryCOUNT_new ("can not get the number of types of group"
|
||||
" of mandatory registration"
|
||||
" to which you don't belong to");
|
||||
NumGrpTypes =
|
||||
(unsigned) DB_QueryCOUNT ("can not get the number of types of group"
|
||||
" of mandatory registration"
|
||||
" to which you don't belong to",
|
||||
"SELECT COUNT(DISTINCT GrpTypCod) FROM"
|
||||
" (SELECT crs_grp_types.GrpTypCod AS GrpTypCod,"
|
||||
"COUNT(*) AS NumStudents,"
|
||||
"crs_grp.MaxStudents as MaxStudents"
|
||||
" FROM crs_grp_types,crs_grp,crs_grp_usr,crs_usr"
|
||||
" WHERE crs_grp_types.CrsCod=%ld"
|
||||
" AND crs_grp_types.Mandatory='Y'"
|
||||
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
|
||||
" AND crs_grp.Open='Y'"
|
||||
" AND crs_grp_types.CrsCod=crs_usr.CrsCod"
|
||||
" AND crs_grp.GrpCod=crs_grp_usr.GrpCod"
|
||||
" AND crs_grp_usr.UsrCod=crs_usr.UsrCod"
|
||||
" AND crs_usr.Role=%u"
|
||||
" GROUP BY crs_grp.GrpCod"
|
||||
" HAVING NumStudents<MaxStudents) AS grp_types_open_not_full"
|
||||
" WHERE GrpTypCod NOT IN"
|
||||
" (SELECT DISTINCT crs_grp_types.GrpTypCod"
|
||||
" FROM crs_grp_types,crs_grp,crs_grp_usr"
|
||||
" WHERE crs_grp_types.CrsCod=%ld"
|
||||
" AND crs_grp_types.Mandatory='Y'"
|
||||
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
|
||||
" AND crs_grp.GrpCod=crs_grp_usr.GrpCod"
|
||||
" AND crs_grp_usr.UsrCod=%ld)",
|
||||
Gbl.CurrentCrs.Crs.CrsCod,
|
||||
(unsigned) Rol_STD,
|
||||
Gbl.CurrentCrs.Crs.CrsCod,
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||
|
||||
return NumGrpTypes;
|
||||
}
|
||||
|
@ -3432,47 +3438,48 @@ static bool Grp_GetIfGrpIsAvailable (long GrpTypCod)
|
|||
|
||||
/***** Get the number of types of group (0 or 1) of a type
|
||||
with one or more open groups with vacants, from database *****/
|
||||
DB_BuildQuery ("SELECT COUNT(GrpTypCod) FROM "
|
||||
"("
|
||||
// Groups with students
|
||||
"SELECT crs_grp_types.GrpTypCod AS GrpTypCod,"
|
||||
"COUNT(*) AS NumStudents,"
|
||||
"crs_grp.MaxStudents as MaxStudents"
|
||||
" FROM crs_grp_types,crs_grp,crs_grp_usr,crs_usr"
|
||||
" WHERE crs_grp_types.GrpTypCod=%ld"
|
||||
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
|
||||
" AND crs_grp.Open='Y'"
|
||||
" AND crs_grp_types.CrsCod=crs_usr.CrsCod"
|
||||
" AND crs_grp.GrpCod=crs_grp_usr.GrpCod"
|
||||
" AND crs_grp_usr.UsrCod=crs_usr.UsrCod"
|
||||
" AND crs_usr.Role=%u"
|
||||
" GROUP BY crs_grp.GrpCod"
|
||||
" HAVING NumStudents<MaxStudents"
|
||||
NumGrpTypes =
|
||||
(unsigned) DB_QueryCOUNT ("can not check if a type of group has available groups",
|
||||
"SELECT COUNT(GrpTypCod) FROM "
|
||||
"("
|
||||
// Groups with students
|
||||
"SELECT crs_grp_types.GrpTypCod AS GrpTypCod,"
|
||||
"COUNT(*) AS NumStudents,"
|
||||
"crs_grp.MaxStudents as MaxStudents"
|
||||
" FROM crs_grp_types,crs_grp,crs_grp_usr,crs_usr"
|
||||
" WHERE crs_grp_types.GrpTypCod=%ld"
|
||||
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
|
||||
" AND crs_grp.Open='Y'"
|
||||
" AND crs_grp_types.CrsCod=crs_usr.CrsCod"
|
||||
" AND crs_grp.GrpCod=crs_grp_usr.GrpCod"
|
||||
" AND crs_grp_usr.UsrCod=crs_usr.UsrCod"
|
||||
" AND crs_usr.Role=%u"
|
||||
" GROUP BY crs_grp.GrpCod"
|
||||
" HAVING NumStudents<MaxStudents"
|
||||
|
||||
" UNION "
|
||||
" UNION "
|
||||
|
||||
// Groups without students
|
||||
"SELECT crs_grp_types.GrpTypCod AS GrpTypCod,"
|
||||
"0 AS NumStudents,"
|
||||
"crs_grp.MaxStudents as MaxStudents"
|
||||
" FROM crs_grp_types,crs_grp"
|
||||
" WHERE crs_grp_types.GrpTypCod=%ld"
|
||||
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
|
||||
" AND crs_grp.Open='Y'"
|
||||
" AND crs_grp.MaxStudents > 0"
|
||||
" AND crs_grp.GrpCod NOT IN"
|
||||
" (SELECT crs_grp_usr.GrpCod"
|
||||
" FROM crs_grp_types,crs_usr,crs_grp_usr"
|
||||
" WHERE crs_grp_types.GrpTypCod=%ld"
|
||||
" AND crs_grp_types.CrsCod=crs_usr.CrsCod"
|
||||
" AND crs_usr.Role=%u"
|
||||
" AND crs_usr.UsrCod=crs_grp_usr.UsrCod)"
|
||||
// Groups without students
|
||||
"SELECT crs_grp_types.GrpTypCod AS GrpTypCod,"
|
||||
"0 AS NumStudents,"
|
||||
"crs_grp.MaxStudents as MaxStudents"
|
||||
" FROM crs_grp_types,crs_grp"
|
||||
" WHERE crs_grp_types.GrpTypCod=%ld"
|
||||
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
|
||||
" AND crs_grp.Open='Y'"
|
||||
" AND crs_grp.MaxStudents > 0"
|
||||
" AND crs_grp.GrpCod NOT IN"
|
||||
" (SELECT crs_grp_usr.GrpCod"
|
||||
" FROM crs_grp_types,crs_usr,crs_grp_usr"
|
||||
" WHERE crs_grp_types.GrpTypCod=%ld"
|
||||
" AND crs_grp_types.CrsCod=crs_usr.CrsCod"
|
||||
" AND crs_usr.Role=%u"
|
||||
" AND crs_usr.UsrCod=crs_grp_usr.UsrCod)"
|
||||
|
||||
") AS available_grp_types",
|
||||
GrpTypCod,(unsigned) Rol_STD,
|
||||
GrpTypCod,
|
||||
GrpTypCod,(unsigned) Rol_STD);
|
||||
NumGrpTypes = DB_QueryCOUNT_new ("can not check if a type of group has available groups");
|
||||
") AS available_grp_types",
|
||||
GrpTypCod,(unsigned) Rol_STD,
|
||||
GrpTypCod,
|
||||
GrpTypCod,(unsigned) Rol_STD);
|
||||
|
||||
return (NumGrpTypes != 0);
|
||||
}
|
||||
|
@ -3798,11 +3805,12 @@ void Grp_RecFormNewGrp (void)
|
|||
static bool Grp_CheckIfGroupTypeNameExists (const char *GrpTypName,long GrpTypCod)
|
||||
{
|
||||
/***** Get number of group types with a name from database *****/
|
||||
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);
|
||||
return (DB_QueryCOUNT ("can not check if the name of type of group"
|
||||
" already existed",
|
||||
"SELECT COUNT(*) FROM crs_grp_types"
|
||||
" WHERE CrsCod=%ld AND GrpTypName='%s'"
|
||||
" AND GrpTypCod<>%ld",
|
||||
Gbl.CurrentCrs.Crs.CrsCod,GrpTypName,GrpTypCod) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -3812,10 +3820,12 @@ static bool Grp_CheckIfGroupTypeNameExists (const char *GrpTypName,long GrpTypCo
|
|||
static bool Grp_CheckIfGroupNameExists (long GrpTypCod,const char *GrpName,long GrpCod)
|
||||
{
|
||||
/***** Get number of groups with a type and a name from database *****/
|
||||
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);
|
||||
return (DB_QueryCOUNT ("can not check if the name of group already existed",
|
||||
"SELECT COUNT(*) FROM crs_grp"
|
||||
" WHERE GrpTypCod=%ld"
|
||||
" AND GrpName='%s'"
|
||||
" AND GrpCod<>%ld",
|
||||
GrpTypCod,GrpName,GrpCod) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
23
swad_info.c
23
swad_info.c
|
@ -523,12 +523,12 @@ static void Inf_PutCheckboxConfirmIHaveReadInfo (void)
|
|||
static bool Inf_CheckIfIHaveReadInfo (void)
|
||||
{
|
||||
/***** Get if info source is already stored in database *****/
|
||||
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);
|
||||
return (DB_QueryCOUNT ("can not get if I have read course info",
|
||||
"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);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -1477,11 +1477,12 @@ Inf_InfoSrc_t Inf_GetInfoSrcFromForm (void)
|
|||
void Inf_SetInfoSrcIntoDB (Inf_InfoSrc_t InfoSrc)
|
||||
{
|
||||
/***** Get if info source is already stored in database *****/
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM crs_info_src"
|
||||
" WHERE CrsCod=%ld AND InfoType='%s'",
|
||||
Gbl.CurrentCrs.Crs.CrsCod,
|
||||
Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type]);
|
||||
if (DB_QueryCOUNT_new ("can not get if info source is already stored in database")) // Info is already stored in database, so update it
|
||||
if (DB_QueryCOUNT ("can not get if info source is already stored in database",
|
||||
"SELECT COUNT(*) FROM crs_info_src"
|
||||
" WHERE CrsCod=%ld AND InfoType='%s'",
|
||||
Gbl.CurrentCrs.Crs.CrsCod,
|
||||
Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type]))
|
||||
// Info is already stored in database, so update it
|
||||
{ // Update info source
|
||||
if (InfoSrc == Inf_INFO_SRC_NONE)
|
||||
DB_QueryUPDATE ("can not update info source",
|
||||
|
|
|
@ -1872,10 +1872,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)
|
||||
{
|
||||
/***** Get number of institutions in current country with a name from database *****/
|
||||
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);
|
||||
return (DB_QueryCOUNT ("can not check if the name of an institution"
|
||||
" already existed",
|
||||
"SELECT COUNT(*) FROM institutions"
|
||||
" WHERE CtyCod=%ld AND %s='%s' AND InsCod<>%ld",
|
||||
CtyCod,FieldName,Name,InsCod) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -2441,8 +2442,9 @@ static void Ins_CreateInstitution (unsigned Status)
|
|||
unsigned Ins_GetNumInssTotal (void)
|
||||
{
|
||||
/***** Get total number of degrees from database *****/
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM institutions");
|
||||
return (unsigned) DB_QueryCOUNT_new ("can not get the total number of institutions");
|
||||
return
|
||||
(unsigned) DB_QueryCOUNT ("can not get the total number of institutions",
|
||||
"SELECT COUNT(*) FROM institutions");
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -2452,8 +2454,12 @@ unsigned Ins_GetNumInssTotal (void)
|
|||
unsigned Ins_GetNumInssInCty (long CtyCod)
|
||||
{
|
||||
/***** Get number of degrees of a place from database *****/
|
||||
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");
|
||||
return
|
||||
(unsigned) DB_QueryCOUNT ("can not get the number of institutions"
|
||||
" in a country",
|
||||
"SELECT COUNT(*) FROM institutions"
|
||||
" WHERE CtyCod=%ld",
|
||||
CtyCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -2463,11 +2469,12 @@ unsigned Ins_GetNumInssInCty (long CtyCod)
|
|||
unsigned Ins_GetNumInssWithCtrs (const char *SubQuery)
|
||||
{
|
||||
/***** Get number of institutions with centres from database *****/
|
||||
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");
|
||||
return
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of institutions with centres",
|
||||
"SELECT COUNT(DISTINCT institutions.InsCod)"
|
||||
" FROM institutions,centres"
|
||||
" WHERE %sinstitutions.InsCod=centres.InsCod",
|
||||
SubQuery);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -2477,12 +2484,13 @@ unsigned Ins_GetNumInssWithCtrs (const char *SubQuery)
|
|||
unsigned Ins_GetNumInssWithDegs (const char *SubQuery)
|
||||
{
|
||||
/***** Get number of institutions with degrees from database *****/
|
||||
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");
|
||||
return
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of institutions with degrees",
|
||||
"SELECT COUNT(DISTINCT institutions.InsCod)"
|
||||
" FROM institutions,centres,degrees"
|
||||
" WHERE %sinstitutions.InsCod=centres.InsCod"
|
||||
" AND centres.CtrCod=degrees.CtrCod",
|
||||
SubQuery);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -2492,13 +2500,14 @@ unsigned Ins_GetNumInssWithDegs (const char *SubQuery)
|
|||
unsigned Ins_GetNumInssWithCrss (const char *SubQuery)
|
||||
{
|
||||
/***** Get number of institutions with courses from database *****/
|
||||
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");
|
||||
return
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of institutions with courses",
|
||||
"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);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -2508,15 +2517,16 @@ unsigned Ins_GetNumInssWithCrss (const char *SubQuery)
|
|||
unsigned Ins_GetNumInssWithUsrs (Rol_Role_t Role,const char *SubQuery)
|
||||
{
|
||||
/***** Get number of institutions with users from database *****/
|
||||
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");
|
||||
return
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of institutions with users",
|
||||
"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);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -630,9 +630,11 @@ static void Lnk_RenameLink (Cns_ShrtOrFullName_t ShrtOrFullName)
|
|||
static bool Lnk_CheckIfLinkNameExists (const char *FieldName,const char *Name,long LnkCod)
|
||||
{
|
||||
/***** Get number of links with a name from database *****/
|
||||
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);
|
||||
return (DB_QueryCOUNT ("can not check if the name of an institutional link"
|
||||
" already existed",
|
||||
"SELECT COUNT(*) FROM links"
|
||||
" WHERE %s='%s' AND LnkCod<>%ld",
|
||||
FieldName,Name,LnkCod) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
27
swad_mail.c
27
swad_mail.c
|
@ -361,9 +361,11 @@ 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])
|
||||
{
|
||||
/***** Get number of mail_domains with a name from database *****/
|
||||
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);
|
||||
return (DB_QueryCOUNT ("can not check if a mail domain"
|
||||
" is allowed for notifications",
|
||||
"SELECT COUNT(*) FROM mail_domains"
|
||||
" WHERE Domain='%s'",
|
||||
MailDomain) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -694,10 +696,11 @@ static void Mai_RenameMailDomain (Cns_ShrtOrFullName_t ShrtOrFullName)
|
|||
static bool Mai_CheckIfMailDomainNameExists (const char *FieldName,const char *Name,long MaiCod)
|
||||
{
|
||||
/***** Get number of mail_domains with a name from database *****/
|
||||
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);
|
||||
return (DB_QueryCOUNT ("can not check if the name"
|
||||
" of a mail domain already existed",
|
||||
"SELECT COUNT(*) FROM mail_domains"
|
||||
" WHERE %s='%s' AND MaiCod<>%ld",
|
||||
FieldName,Name,MaiCod) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -1631,11 +1634,11 @@ static void Mai_NewUsrEmail (struct UsrData *UsrDat,bool ItsMe)
|
|||
bool Mai_UpdateEmailInDB (const struct UsrData *UsrDat,const char NewEmail[Cns_MAX_BYTES_EMAIL_ADDRESS + 1])
|
||||
{
|
||||
/***** Check if the new email matches any of the confirmed emails of other users *****/
|
||||
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
|
||||
if (DB_QueryCOUNT ("can not check if email already existed",
|
||||
"SELECT COUNT(*) FROM usr_emails"
|
||||
" WHERE E_mail='%s' AND Confirmed='Y'"
|
||||
" AND UsrCod<>%ld",
|
||||
NewEmail,UsrDat->UsrCod)) // An email of another user is the same that my email
|
||||
return false; // Don't update
|
||||
|
||||
/***** Delete email (not confirmed) for other users *****/
|
||||
|
|
524
swad_message.c
524
swad_message.c
|
@ -1561,9 +1561,12 @@ void Msg_MoveUnusedMsgsContentToDeleted (void)
|
|||
static bool Msg_CheckIfSentMsgIsDeleted (long MsgCod)
|
||||
{
|
||||
/***** Get if the message code is in table of sent messages not deleted *****/
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM msg_snt"
|
||||
" WHERE MsgCod=%ld",MsgCod);
|
||||
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 ("can not check if a sent message is deleted",
|
||||
"SELECT COUNT(*) FROM msg_snt"
|
||||
" WHERE MsgCod=%ld",
|
||||
MsgCod) == 0); // The message has been deleted
|
||||
// by its author when it is not present
|
||||
// in table of sent messages undeleted
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -1573,9 +1576,13 @@ static bool Msg_CheckIfSentMsgIsDeleted (long MsgCod)
|
|||
static bool Msg_CheckIfReceivedMsgIsDeletedForAllItsRecipients (long MsgCod)
|
||||
{
|
||||
/***** Get if the message code is in table of received messages not deleted *****/
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM msg_rcv"
|
||||
" WHERE MsgCod=%ld",MsgCod);
|
||||
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 ("can not check if a received message"
|
||||
" is deleted by all recipients",
|
||||
"SELECT COUNT(*) FROM msg_rcv"
|
||||
" WHERE MsgCod=%ld",
|
||||
MsgCod) == 0); // The message has been deleted
|
||||
// by all its recipients when it is not present
|
||||
// in table of received messages undeleted
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -1585,6 +1592,7 @@ static bool Msg_CheckIfReceivedMsgIsDeletedForAllItsRecipients (long MsgCod)
|
|||
static unsigned Msg_GetNumUnreadMsgs (long FilterCrsCod,const char *FilterFromToSubquery)
|
||||
{
|
||||
char SubQuery[Msg_MAX_BYTES_MESSAGES_QUERY + 1];
|
||||
unsigned NumMsgs;
|
||||
|
||||
/***** Get number of unread messages from database *****/
|
||||
if (FilterCrsCod >= 0) // If origin course selected
|
||||
|
@ -1622,15 +1630,20 @@ static unsigned Msg_GetNumUnreadMsgs (long FilterCrsCod,const char *FilterFromTo
|
|||
}
|
||||
|
||||
if (Gbl.Msg.FilterContent[0])
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM msg_content"
|
||||
" WHERE MsgCod IN (%s)"
|
||||
" AND MATCH (Subject,Content) AGAINST ('%s')",
|
||||
SubQuery,
|
||||
Gbl.Msg.FilterContent);
|
||||
NumMsgs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of unread messages",
|
||||
"SELECT COUNT(*) FROM msg_content"
|
||||
" WHERE MsgCod IN (%s)"
|
||||
" AND MATCH (Subject,Content) AGAINST ('%s')",
|
||||
SubQuery,
|
||||
Gbl.Msg.FilterContent);
|
||||
else
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM (%s) AS T",
|
||||
SubQuery);
|
||||
return (unsigned) DB_QueryCOUNT_new ("can not get number of unread messages");
|
||||
NumMsgs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of unread messages",
|
||||
"SELECT COUNT(*) FROM (%s) AS T",
|
||||
SubQuery);
|
||||
|
||||
return NumMsgs;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -1844,9 +1857,10 @@ static void Msg_ShowSentOrReceivedMessages (void)
|
|||
static unsigned long Msg_GetNumUsrsBannedByMe (void)
|
||||
{
|
||||
/***** Get number of users I have banned *****/
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM msg_banned WHERE ToUsrCod=%ld",
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||
return DB_QueryCOUNT_new ("can not get number of users you have banned");
|
||||
return DB_QueryCOUNT ("can not get number of users you have banned",
|
||||
"SELECT COUNT(*) FROM msg_banned"
|
||||
" WHERE ToUsrCod=%ld",
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -2044,11 +2058,14 @@ static unsigned long Msg_GetSentOrReceivedMsgs (long UsrCod,
|
|||
unsigned Msg_GetNumMsgsSentByTchsCrs (long CrsCod)
|
||||
{
|
||||
/***** Get the number of unique messages sent by any teacher from this course *****/
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM msg_snt,crs_usr"
|
||||
" WHERE msg_snt.CrsCod=%ld AND crs_usr.CrsCod=%ld AND crs_usr.Role=%u"
|
||||
" AND msg_snt.UsrCod=crs_usr.UsrCod",
|
||||
CrsCod,CrsCod,(unsigned) Rol_TCH);
|
||||
return (unsigned) DB_QueryCOUNT_new ("can not get the number of messages sent by teachers");
|
||||
return
|
||||
(unsigned) DB_QueryCOUNT ("can not get the number of messages"
|
||||
" sent by teachers",
|
||||
"SELECT COUNT(*) FROM msg_snt,crs_usr"
|
||||
" WHERE msg_snt.CrsCod=%ld"
|
||||
" AND crs_usr.CrsCod=%ld AND crs_usr.Role=%u"
|
||||
" AND msg_snt.UsrCod=crs_usr.UsrCod",
|
||||
CrsCod,CrsCod,(unsigned) Rol_TCH);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -2058,13 +2075,13 @@ unsigned Msg_GetNumMsgsSentByTchsCrs (long CrsCod)
|
|||
unsigned long Msg_GetNumMsgsSentByUsr (long UsrCod)
|
||||
{
|
||||
/***** Get the number of unique messages sent by any teacher from this course *****/
|
||||
DB_BuildQuery ("SELECT"
|
||||
" (SELECT COUNT(*) FROM msg_snt WHERE UsrCod=%ld)"
|
||||
" +"
|
||||
" (SELECT COUNT(*) FROM msg_snt_deleted WHERE UsrCod=%ld)",
|
||||
UsrCod,
|
||||
UsrCod);
|
||||
return DB_QueryCOUNT_new ("can not get the number of messages sent by a user");
|
||||
return DB_QueryCOUNT ("can not get the number of messages sent by a user",
|
||||
"SELECT"
|
||||
" (SELECT COUNT(*) FROM msg_snt WHERE UsrCod=%ld)"
|
||||
" +"
|
||||
" (SELECT COUNT(*) FROM msg_snt_deleted WHERE UsrCod=%ld)",
|
||||
UsrCod,
|
||||
UsrCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -2075,6 +2092,7 @@ unsigned long Msg_GetNumMsgsSentByUsr (long UsrCod)
|
|||
unsigned Msg_GetNumMsgsSent (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
|
||||
{
|
||||
const char *Table = "msg_snt";
|
||||
unsigned NumMsgs = 0; // Initialized to avoid warning
|
||||
|
||||
/***** Get the number of messages sent from this location
|
||||
(all the platform, current degree or current course) from database *****/
|
||||
|
@ -2091,63 +2109,76 @@ unsigned Msg_GetNumMsgsSent (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
|
|||
switch (Scope)
|
||||
{
|
||||
case Sco_SCOPE_SYS:
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM %s",
|
||||
Table);
|
||||
NumMsgs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of sent messages",
|
||||
"SELECT COUNT(*) FROM %s",
|
||||
Table);
|
||||
break;
|
||||
case Sco_SCOPE_CTY:
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM institutions,centres,degrees,courses,%s"
|
||||
" WHERE institutions.CtyCod=%ld"
|
||||
" AND institutions.InsCod=centres.InsCod"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=%s.CrsCod",
|
||||
Table,
|
||||
Gbl.CurrentCty.Cty.CtyCod,
|
||||
Table);
|
||||
NumMsgs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of sent messages",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM institutions,centres,degrees,courses,%s"
|
||||
" WHERE institutions.CtyCod=%ld"
|
||||
" AND institutions.InsCod=centres.InsCod"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=%s.CrsCod",
|
||||
Table,
|
||||
Gbl.CurrentCty.Cty.CtyCod,
|
||||
Table);
|
||||
break;
|
||||
case Sco_SCOPE_INS:
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM centres,degrees,courses,%s"
|
||||
" WHERE centres.InsCod=%ld"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=%s.CrsCod",
|
||||
Table,
|
||||
Gbl.CurrentIns.Ins.InsCod,
|
||||
Table);
|
||||
NumMsgs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of sent messages",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM centres,degrees,courses,%s"
|
||||
" WHERE centres.InsCod=%ld"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=%s.CrsCod",
|
||||
Table,
|
||||
Gbl.CurrentIns.Ins.InsCod,
|
||||
Table);
|
||||
break;
|
||||
case Sco_SCOPE_CTR:
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM degrees,courses,%s"
|
||||
" WHERE degrees.CtrCod=%ld"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=%s.CrsCod",
|
||||
Table,
|
||||
Gbl.CurrentCtr.Ctr.CtrCod,
|
||||
Table);
|
||||
NumMsgs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of sent messages",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM degrees,courses,%s"
|
||||
" WHERE degrees.CtrCod=%ld"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=%s.CrsCod",
|
||||
Table,
|
||||
Gbl.CurrentCtr.Ctr.CtrCod,
|
||||
Table);
|
||||
break;
|
||||
case Sco_SCOPE_DEG:
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM courses,%s"
|
||||
" WHERE courses.DegCod=%ld"
|
||||
" AND courses.CrsCod=%s.CrsCod",
|
||||
Table,
|
||||
Gbl.CurrentDeg.Deg.DegCod,
|
||||
Table);
|
||||
NumMsgs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of sent messages",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM courses,%s"
|
||||
" WHERE courses.DegCod=%ld"
|
||||
" AND courses.CrsCod=%s.CrsCod",
|
||||
Table,
|
||||
Gbl.CurrentDeg.Deg.DegCod,
|
||||
Table);
|
||||
break;
|
||||
case Sco_SCOPE_CRS:
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM %s"
|
||||
" WHERE CrsCod=%ld",
|
||||
Table,
|
||||
Gbl.CurrentCrs.Crs.CrsCod);
|
||||
NumMsgs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of sent messages",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM %s"
|
||||
" WHERE CrsCod=%ld",
|
||||
Table,
|
||||
Gbl.CurrentCrs.Crs.CrsCod);
|
||||
break;
|
||||
default:
|
||||
Lay_WrongScopeExit ();
|
||||
break;
|
||||
}
|
||||
return (unsigned) DB_QueryCOUNT_new ("can not get number of sent messages");
|
||||
|
||||
return NumMsgs;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -2158,6 +2189,7 @@ unsigned Msg_GetNumMsgsSent (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
|
|||
unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
|
||||
{
|
||||
char *Table;
|
||||
unsigned NumMsgs = 0; // Initialized to avoid warning
|
||||
|
||||
/***** Get the number of unique messages sent from this location
|
||||
(all the platform, current degree or current course) from database *****/
|
||||
|
@ -2170,63 +2202,81 @@ unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
|
|||
switch (Scope)
|
||||
{
|
||||
case Sco_SCOPE_SYS:
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM %s",
|
||||
Table);
|
||||
NumMsgs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get number"
|
||||
" of received messages",
|
||||
"SELECT COUNT(*) FROM %s",
|
||||
Table);
|
||||
break;
|
||||
case Sco_SCOPE_CTY:
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM institutions,centres,degrees,courses,%s,msg_snt"
|
||||
" WHERE institutions.CtyCod=%ld"
|
||||
" AND institutions.InsCod=centres.InsCod"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=msg_snt.CrsCod"
|
||||
" AND msg_snt.MsgCod=%s.MsgCod",
|
||||
Table,
|
||||
Gbl.CurrentCty.Cty.CtyCod,
|
||||
Table);
|
||||
NumMsgs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get number"
|
||||
" of received messages",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM institutions,centres,degrees,courses,%s,msg_snt"
|
||||
" WHERE institutions.CtyCod=%ld"
|
||||
" AND institutions.InsCod=centres.InsCod"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=msg_snt.CrsCod"
|
||||
" AND msg_snt.MsgCod=%s.MsgCod",
|
||||
Table,
|
||||
Gbl.CurrentCty.Cty.CtyCod,
|
||||
Table);
|
||||
break;
|
||||
case Sco_SCOPE_INS:
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM centres,degrees,courses,%s,msg_snt"
|
||||
" WHERE centres.InsCod=%ld"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=msg_snt.CrsCod"
|
||||
" AND msg_snt.MsgCod=%s.MsgCod",
|
||||
Table,
|
||||
Gbl.CurrentIns.Ins.InsCod,
|
||||
Table);
|
||||
NumMsgs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get number"
|
||||
" of received messages",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM centres,degrees,courses,%s,msg_snt"
|
||||
" WHERE centres.InsCod=%ld"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=msg_snt.CrsCod"
|
||||
" AND msg_snt.MsgCod=%s.MsgCod",
|
||||
Table,
|
||||
Gbl.CurrentIns.Ins.InsCod,
|
||||
Table);
|
||||
break;
|
||||
case Sco_SCOPE_CTR:
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM degrees,courses,%s,msg_snt"
|
||||
" WHERE degrees.CtrCod=%ld"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=msg_snt.CrsCod"
|
||||
" AND msg_snt.MsgCod=%s.MsgCod",
|
||||
Table,
|
||||
Gbl.CurrentCtr.Ctr.CtrCod,
|
||||
Table);
|
||||
NumMsgs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get number"
|
||||
" of received messages",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM degrees,courses,%s,msg_snt"
|
||||
" WHERE degrees.CtrCod=%ld"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=msg_snt.CrsCod"
|
||||
" AND msg_snt.MsgCod=%s.MsgCod",
|
||||
Table,
|
||||
Gbl.CurrentCtr.Ctr.CtrCod,
|
||||
Table);
|
||||
break;
|
||||
case Sco_SCOPE_DEG:
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM courses,%s,msg_snt"
|
||||
" WHERE courses.DegCod=%ld"
|
||||
" AND courses.CrsCod=msg_snt.CrsCod"
|
||||
" AND msg_snt.MsgCod=%s.MsgCod",
|
||||
Table,
|
||||
Gbl.CurrentDeg.Deg.DegCod,
|
||||
Table);
|
||||
NumMsgs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get number"
|
||||
" of received messages",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM courses,%s,msg_snt"
|
||||
" WHERE courses.DegCod=%ld"
|
||||
" AND courses.CrsCod=msg_snt.CrsCod"
|
||||
" AND msg_snt.MsgCod=%s.MsgCod",
|
||||
Table,
|
||||
Gbl.CurrentDeg.Deg.DegCod,
|
||||
Table);
|
||||
break;
|
||||
case Sco_SCOPE_CRS:
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM msg_snt,%s"
|
||||
" WHERE msg_snt.CrsCod=%ld"
|
||||
" AND msg_snt.MsgCod=%s.MsgCod",
|
||||
Table,
|
||||
Gbl.CurrentCrs.Crs.CrsCod,
|
||||
Table);
|
||||
NumMsgs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get number"
|
||||
" of received messages",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM msg_snt,%s"
|
||||
" WHERE msg_snt.CrsCod=%ld"
|
||||
" AND msg_snt.MsgCod=%s.MsgCod",
|
||||
Table,
|
||||
Gbl.CurrentCrs.Crs.CrsCod,
|
||||
Table);
|
||||
break;
|
||||
default:
|
||||
Lay_WrongScopeExit ();
|
||||
|
@ -2237,114 +2287,132 @@ unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
|
|||
switch (Scope)
|
||||
{
|
||||
case Sco_SCOPE_SYS:
|
||||
DB_BuildQuery ("SELECT "
|
||||
"(SELECT COUNT(*)"
|
||||
" FROM msg_rcv"
|
||||
" WHERE Notified='Y')"
|
||||
" + "
|
||||
"(SELECT COUNT(*)"
|
||||
" FROM msg_rcv_deleted"
|
||||
" WHERE Notified='Y')");
|
||||
NumMsgs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get number"
|
||||
" of received messages",
|
||||
"SELECT "
|
||||
"(SELECT COUNT(*)"
|
||||
" FROM msg_rcv"
|
||||
" WHERE Notified='Y')"
|
||||
" + "
|
||||
"(SELECT COUNT(*)"
|
||||
" FROM msg_rcv_deleted"
|
||||
" WHERE Notified='Y')");
|
||||
break;
|
||||
case Sco_SCOPE_CTY:
|
||||
DB_BuildQuery ("SELECT "
|
||||
"(SELECT COUNT(*)"
|
||||
" FROM institutions,centres,degrees,courses,msg_snt,msg_rcv"
|
||||
" WHERE institutions.CtyCod=%ld"
|
||||
" AND institutions.InsCod=centres.InsCod"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=msg_snt.CrsCod"
|
||||
" AND msg_snt.MsgCod=msg_rcv.MsgCod"
|
||||
" AND msg_rcv.Notified='Y')"
|
||||
" + "
|
||||
"(SELECT COUNT(*)"
|
||||
" FROM institutions,centres,degrees,courses,msg_snt,msg_rcv_deleted"
|
||||
" WHERE institutions.CtyCod=%ld"
|
||||
" AND institutions.InsCod=centres.InsCod"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=msg_snt.CrsCod"
|
||||
" AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod"
|
||||
" AND msg_rcv_deleted.Notified='Y')",
|
||||
Gbl.CurrentCty.Cty.CtyCod,
|
||||
Gbl.CurrentCty.Cty.CtyCod);
|
||||
NumMsgs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get number"
|
||||
" of received messages",
|
||||
"SELECT "
|
||||
"(SELECT COUNT(*)"
|
||||
" FROM institutions,centres,degrees,courses,msg_snt,msg_rcv"
|
||||
" WHERE institutions.CtyCod=%ld"
|
||||
" AND institutions.InsCod=centres.InsCod"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=msg_snt.CrsCod"
|
||||
" AND msg_snt.MsgCod=msg_rcv.MsgCod"
|
||||
" AND msg_rcv.Notified='Y')"
|
||||
" + "
|
||||
"(SELECT COUNT(*)"
|
||||
" FROM institutions,centres,degrees,courses,msg_snt,msg_rcv_deleted"
|
||||
" WHERE institutions.CtyCod=%ld"
|
||||
" AND institutions.InsCod=centres.InsCod"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=msg_snt.CrsCod"
|
||||
" AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod"
|
||||
" AND msg_rcv_deleted.Notified='Y')",
|
||||
Gbl.CurrentCty.Cty.CtyCod,
|
||||
Gbl.CurrentCty.Cty.CtyCod);
|
||||
break;
|
||||
case Sco_SCOPE_INS:
|
||||
DB_BuildQuery ("SELECT "
|
||||
"(SELECT COUNT(*)"
|
||||
" FROM centres,degrees,courses,msg_snt,msg_rcv"
|
||||
" WHERE centres.InsCod=%ld"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=msg_snt.CrsCod"
|
||||
" AND msg_snt.MsgCod=msg_rcv.MsgCod"
|
||||
" AND msg_rcv.Notified='Y')"
|
||||
" + "
|
||||
"(SELECT COUNT(*)"
|
||||
" FROM centres,degrees,courses,msg_snt,msg_rcv_deleted"
|
||||
" WHERE centres.InsCod=%ld"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=msg_snt.CrsCod"
|
||||
" AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod"
|
||||
" AND msg_rcv_deleted.Notified='Y')",
|
||||
Gbl.CurrentIns.Ins.InsCod,
|
||||
Gbl.CurrentIns.Ins.InsCod);
|
||||
NumMsgs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get number"
|
||||
" of received messages",
|
||||
"SELECT "
|
||||
"(SELECT COUNT(*)"
|
||||
" FROM centres,degrees,courses,msg_snt,msg_rcv"
|
||||
" WHERE centres.InsCod=%ld"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=msg_snt.CrsCod"
|
||||
" AND msg_snt.MsgCod=msg_rcv.MsgCod"
|
||||
" AND msg_rcv.Notified='Y')"
|
||||
" + "
|
||||
"(SELECT COUNT(*)"
|
||||
" FROM centres,degrees,courses,msg_snt,msg_rcv_deleted"
|
||||
" WHERE centres.InsCod=%ld"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=msg_snt.CrsCod"
|
||||
" AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod"
|
||||
" AND msg_rcv_deleted.Notified='Y')",
|
||||
Gbl.CurrentIns.Ins.InsCod,
|
||||
Gbl.CurrentIns.Ins.InsCod);
|
||||
break;
|
||||
case Sco_SCOPE_CTR:
|
||||
DB_BuildQuery ("SELECT "
|
||||
"(SELECT COUNT(*)"
|
||||
" FROM degrees,courses,msg_snt,msg_rcv"
|
||||
" WHERE degrees.CtrCod=%ld"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=msg_snt.CrsCod"
|
||||
" AND msg_snt.MsgCod=msg_rcv.MsgCod"
|
||||
" AND msg_rcv.Notified='Y')"
|
||||
" + "
|
||||
"(SELECT COUNT(*)"
|
||||
" FROM degrees,courses,msg_snt,msg_rcv_deleted"
|
||||
" WHERE degrees.CtrCod=%ld"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=msg_snt.CrsCod"
|
||||
" AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod"
|
||||
" AND msg_rcv_deleted.Notified='Y')",
|
||||
Gbl.CurrentCtr.Ctr.CtrCod,
|
||||
Gbl.CurrentCtr.Ctr.CtrCod);
|
||||
NumMsgs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get number"
|
||||
" of received messages",
|
||||
"SELECT "
|
||||
"(SELECT COUNT(*)"
|
||||
" FROM degrees,courses,msg_snt,msg_rcv"
|
||||
" WHERE degrees.CtrCod=%ld"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=msg_snt.CrsCod"
|
||||
" AND msg_snt.MsgCod=msg_rcv.MsgCod"
|
||||
" AND msg_rcv.Notified='Y')"
|
||||
" + "
|
||||
"(SELECT COUNT(*)"
|
||||
" FROM degrees,courses,msg_snt,msg_rcv_deleted"
|
||||
" WHERE degrees.CtrCod=%ld"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=msg_snt.CrsCod"
|
||||
" AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod"
|
||||
" AND msg_rcv_deleted.Notified='Y')",
|
||||
Gbl.CurrentCtr.Ctr.CtrCod,
|
||||
Gbl.CurrentCtr.Ctr.CtrCod);
|
||||
break;
|
||||
case Sco_SCOPE_DEG:
|
||||
DB_BuildQuery ("SELECT "
|
||||
"(SELECT COUNT(*)"
|
||||
" FROM courses,msg_snt,msg_rcv"
|
||||
" WHERE courses.DegCod=%ld"
|
||||
" AND courses.CrsCod=msg_snt.CrsCod"
|
||||
" AND msg_snt.MsgCod=msg_rcv.MsgCod"
|
||||
" AND msg_rcv.Notified='Y')"
|
||||
" + "
|
||||
"(SELECT COUNT(*)"
|
||||
" FROM courses,msg_snt,msg_rcv_deleted"
|
||||
" WHERE courses.DegCod=%ld"
|
||||
" AND courses.CrsCod=msg_snt.CrsCod"
|
||||
" AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod"
|
||||
" AND msg_rcv_deleted.Notified='Y')",
|
||||
Gbl.CurrentDeg.Deg.DegCod,
|
||||
Gbl.CurrentDeg.Deg.DegCod);
|
||||
NumMsgs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get number"
|
||||
" of received messages",
|
||||
"SELECT "
|
||||
"(SELECT COUNT(*)"
|
||||
" FROM courses,msg_snt,msg_rcv"
|
||||
" WHERE courses.DegCod=%ld"
|
||||
" AND courses.CrsCod=msg_snt.CrsCod"
|
||||
" AND msg_snt.MsgCod=msg_rcv.MsgCod"
|
||||
" AND msg_rcv.Notified='Y')"
|
||||
" + "
|
||||
"(SELECT COUNT(*)"
|
||||
" FROM courses,msg_snt,msg_rcv_deleted"
|
||||
" WHERE courses.DegCod=%ld"
|
||||
" AND courses.CrsCod=msg_snt.CrsCod"
|
||||
" AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod"
|
||||
" AND msg_rcv_deleted.Notified='Y')",
|
||||
Gbl.CurrentDeg.Deg.DegCod,
|
||||
Gbl.CurrentDeg.Deg.DegCod);
|
||||
break;
|
||||
case Sco_SCOPE_CRS:
|
||||
DB_BuildQuery ("SELECT "
|
||||
"(SELECT COUNT(*)"
|
||||
" FROM msg_snt,msg_rcv"
|
||||
" WHERE msg_snt.CrsCod=%ld"
|
||||
" AND msg_snt.MsgCod=msg_rcv.MsgCod"
|
||||
" AND msg_rcv.Notified='Y')"
|
||||
" + "
|
||||
"(SELECT COUNT(*)"
|
||||
" FROM msg_snt,msg_rcv_deleted"
|
||||
" WHERE msg_snt.CrsCod=%ld"
|
||||
" AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod"
|
||||
" AND msg_rcv_deleted.Notified='Y')",
|
||||
Gbl.CurrentCrs.Crs.CrsCod,
|
||||
Gbl.CurrentCrs.Crs.CrsCod);
|
||||
NumMsgs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get number"
|
||||
" of received messages",
|
||||
"SELECT "
|
||||
"(SELECT COUNT(*)"
|
||||
" FROM msg_snt,msg_rcv"
|
||||
" WHERE msg_snt.CrsCod=%ld"
|
||||
" AND msg_snt.MsgCod=msg_rcv.MsgCod"
|
||||
" AND msg_rcv.Notified='Y')"
|
||||
" + "
|
||||
"(SELECT COUNT(*)"
|
||||
" FROM msg_snt,msg_rcv_deleted"
|
||||
" WHERE msg_snt.CrsCod=%ld"
|
||||
" AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod"
|
||||
" AND msg_rcv_deleted.Notified='Y')",
|
||||
Gbl.CurrentCrs.Crs.CrsCod,
|
||||
Gbl.CurrentCrs.Crs.CrsCod);
|
||||
break;
|
||||
default:
|
||||
Lay_WrongScopeExit ();
|
||||
|
@ -2352,7 +2420,8 @@ unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
|
|||
}
|
||||
break;
|
||||
}
|
||||
return (unsigned) DB_QueryCOUNT_new ("can not get number of received messages");
|
||||
|
||||
return NumMsgs;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -3378,12 +3447,13 @@ static void Msg_WriteMsgTo (long MsgCod)
|
|||
};
|
||||
|
||||
/***** Get number of recipients of a message from database *****/
|
||||
DB_BuildQuery ("SELECT "
|
||||
"(SELECT COUNT(*) FROM msg_rcv WHERE MsgCod=%ld)"
|
||||
" + "
|
||||
"(SELECT COUNT(*) FROM msg_rcv_deleted WHERE MsgCod=%ld)",
|
||||
MsgCod,MsgCod);
|
||||
NumRecipientsTotal = (unsigned) DB_QueryCOUNT_new ("can not get number of recipients");
|
||||
NumRecipientsTotal =
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of recipients",
|
||||
"SELECT "
|
||||
"(SELECT COUNT(*) FROM msg_rcv WHERE MsgCod=%ld)"
|
||||
" + "
|
||||
"(SELECT COUNT(*) FROM msg_rcv_deleted WHERE MsgCod=%ld)",
|
||||
MsgCod,MsgCod);
|
||||
|
||||
/***** Get recipients of a message from database *****/
|
||||
NumRecipientsKnown =
|
||||
|
@ -3730,10 +3800,10 @@ static void Msg_UnbanSender (void)
|
|||
static bool Msg_CheckIfUsrIsBanned (long FromUsrCod,long ToUsrCod)
|
||||
{
|
||||
/***** Get if FromUsrCod is banned by ToUsrCod *****/
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM msg_banned"
|
||||
" WHERE FromUsrCod=%ld AND ToUsrCod=%ld",
|
||||
FromUsrCod,ToUsrCod);
|
||||
return (DB_QueryCOUNT_new ("can not check if a user is banned") != 0);
|
||||
return (DB_QueryCOUNT ("can not check if a user is banned",
|
||||
"SELECT COUNT(*) FROM msg_banned"
|
||||
" WHERE FromUsrCod=%ld AND ToUsrCod=%ld",
|
||||
FromUsrCod,ToUsrCod) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -580,16 +580,15 @@ 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 *****/
|
||||
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
|
||||
{
|
||||
if (!DB_QueryCOUNT ("can not check if nickname already existed",
|
||||
"SELECT COUNT(*) FROM usr_nicknames"
|
||||
" WHERE UsrCod=%ld AND Nickname='%s'",
|
||||
UsrDat->UsrCod,NewNicknameWithoutArroba)) // No matches
|
||||
/***** Check if the new nickname matches any of the nicknames of other users *****/
|
||||
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
|
||||
if (DB_QueryCOUNT ("can not check if nickname already existed",
|
||||
"SELECT COUNT(*) FROM usr_nicknames"
|
||||
" WHERE Nickname='%s' AND UsrCod<>%ld",
|
||||
NewNicknameWithoutArroba,UsrDat->UsrCod)) // A nickname of another user is the same that user's nickname
|
||||
{
|
||||
Gbl.Alert.Type = Ale_WARNING;
|
||||
Gbl.Alert.Section = Nck_NICKNAME_SECTION_ID;
|
||||
|
@ -597,7 +596,6 @@ static void Nck_UpdateUsrNick (struct UsrData *UsrDat)
|
|||
Txt_The_nickname_X_had_been_registered_by_another_user,
|
||||
NewNicknameWithoutArroba);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Gbl.Alert.Type == Ale_NONE)
|
||||
{
|
||||
|
|
|
@ -2115,11 +2115,11 @@ void Ntf_WriteNumberOfNewNtfs (void)
|
|||
static unsigned Ntf_GetNumberOfAllMyUnseenNtfs (void)
|
||||
{
|
||||
/***** Get number of places with a name from database *****/
|
||||
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");
|
||||
return DB_QueryCOUNT ("can not get number of unseen notifications",
|
||||
"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));
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -2129,13 +2129,13 @@ static unsigned Ntf_GetNumberOfAllMyUnseenNtfs (void)
|
|||
static unsigned Ntf_GetNumberOfMyNewUnseenNtfs (void)
|
||||
{
|
||||
/***** Get number of places with a name from database *****/
|
||||
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");
|
||||
return DB_QueryCOUNT ("can not get number of unseen notifications",
|
||||
"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);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -574,18 +574,17 @@ static bool Pwd_CheckIfPasswdIsUsrIDorName (const char *PlainPassword)
|
|||
bool Found;
|
||||
|
||||
/***** Get if password is found in user's ID from database *****/
|
||||
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);
|
||||
Found = (DB_QueryCOUNT ("can not check if a password matches a user's ID",
|
||||
"SELECT COUNT(*) FROM usr_IDs WHERE UsrID='%s'",
|
||||
PlainPassword) != 0);
|
||||
|
||||
/***** Get if password is found in first name or surnames of anybody, from database *****/
|
||||
if (!Found)
|
||||
{
|
||||
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);
|
||||
}
|
||||
Found = (DB_QueryCOUNT ("can not check if a password matches"
|
||||
" a first name or a surname",
|
||||
"SELECT COUNT(*) FROM usr_data"
|
||||
" WHERE FirstName='%s' OR Surname1='%s' OR Surname2='%s'",
|
||||
PlainPassword,PlainPassword,PlainPassword) != 0);
|
||||
|
||||
return Found;
|
||||
}
|
||||
|
@ -596,17 +595,30 @@ static bool Pwd_CheckIfPasswdIsUsrIDorName (const char *PlainPassword)
|
|||
|
||||
static unsigned Pwd_GetNumOtherUsrsWhoUseThisPassword (const char *EncryptedPassword,long UsrCod)
|
||||
{
|
||||
/***** Get number of other users who use a password from database *****/
|
||||
/* Query database */
|
||||
unsigned NumUsrs;
|
||||
char *SubQuery;
|
||||
|
||||
/***** Build subquery *****/
|
||||
if (UsrCod > 0)
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM usr_data"
|
||||
" WHERE Password='%s' AND UsrCod<>%ld",
|
||||
EncryptedPassword,UsrCod);
|
||||
{
|
||||
if (asprintf (&SubQuery," AND UsrCod<>%ld",UsrCod) < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
}
|
||||
else
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM usr_data"
|
||||
" WHERE Password='%s'",
|
||||
EncryptedPassword);
|
||||
return (unsigned) DB_QueryCOUNT_new ("can not check if a password is trivial");
|
||||
SubQuery = "";
|
||||
|
||||
/***** Get number of other users who use a password from database *****/
|
||||
NumUsrs =
|
||||
(unsigned) DB_QueryCOUNT ("can not check if a password is trivial",
|
||||
"SELECT COUNT(*) FROM usr_data"
|
||||
" WHERE Password='%s'%s",
|
||||
EncryptedPassword,SubQuery);
|
||||
|
||||
/***** Free subquery *****/
|
||||
if (UsrCod > 0)
|
||||
free ((void *) SubQuery);
|
||||
|
||||
return NumUsrs;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
11
swad_place.c
11
swad_place.c
|
@ -715,10 +715,13 @@ static void Plc_RenamePlace (Cns_ShrtOrFullName_t ShrtOrFullName)
|
|||
static bool Plc_CheckIfPlaceNameExists (const char *FieldName,const char *Name,long PlcCod)
|
||||
{
|
||||
/***** Get number of places with a name from database *****/
|
||||
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);
|
||||
return (DB_QueryCOUNT ("can not check if the name of a place"
|
||||
" already existed",
|
||||
"SELECT COUNT(*) FROM places"
|
||||
" WHERE InsCod=%ld"
|
||||
" AND %s='%s' AND PlcCod<>%ld",
|
||||
Gbl.CurrentIns.Ins.InsCod,
|
||||
FieldName,Name,PlcCod) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -593,10 +593,11 @@ void Plg_RenamePlugin (void)
|
|||
static bool Plg_CheckIfPluginNameExists (const char *Name,long PlgCod)
|
||||
{
|
||||
/***** Get number of plugins with a name from database *****/
|
||||
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);
|
||||
return (DB_QueryCOUNT ("can not check if the name of a plugin"
|
||||
" already existed",
|
||||
"SELECT COUNT(*) FROM plugins"
|
||||
" WHERE Name='%s' AND PlgCod<>%ld",
|
||||
Name,PlgCod) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -681,12 +681,12 @@ static unsigned long Prf_GetRankingFigure (long UsrCod,const char *FieldName)
|
|||
{
|
||||
/***** Select number of rows with figure
|
||||
greater than the figure of this user *****/
|
||||
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");
|
||||
return DB_QueryCOUNT ("can not get ranking using a figure",
|
||||
"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);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -696,8 +696,9 @@ static unsigned long Prf_GetRankingFigure (long UsrCod,const char *FieldName)
|
|||
static unsigned long Prf_GetNumUsrsWithFigure (const char *FieldName)
|
||||
{
|
||||
/***** Select number of rows with values already calculated *****/
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM usr_figures WHERE %s>=0",FieldName);
|
||||
return DB_QueryCOUNT_new ("can not get number of users with a figure");
|
||||
return DB_QueryCOUNT ("can not get number of users with a figure",
|
||||
"SELECT COUNT(*) FROM usr_figures WHERE %s>=0",
|
||||
FieldName);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -708,22 +709,22 @@ static unsigned long Prf_GetRankingNumClicksPerDay (long UsrCod)
|
|||
{
|
||||
/***** Select number of rows with number of clicks per day
|
||||
greater than the clicks per day of this user *****/
|
||||
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");
|
||||
return DB_QueryCOUNT ("can not get ranking using number of clicks per day",
|
||||
"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 FirstClickTime>FROM_UNIXTIME(0))"
|
||||
" AS TableNumClicksPerDay"
|
||||
" WHERE NumClicksPerDay>"
|
||||
"(SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1)"
|
||||
" FROM usr_figures"
|
||||
" WHERE UsrCod=%ld"
|
||||
" AND NumClicks>0"
|
||||
" AND FirstClickTime>FROM_UNIXTIME(0))",
|
||||
UsrCod,UsrCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -733,10 +734,11 @@ static unsigned long Prf_GetRankingNumClicksPerDay (long UsrCod)
|
|||
static unsigned long Prf_GetNumUsrsWithNumClicksPerDay (void)
|
||||
{
|
||||
/***** Select number of rows with values already calculated *****/
|
||||
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");
|
||||
return DB_QueryCOUNT ("can not get number of users"
|
||||
" with number of clicks per day",
|
||||
"SELECT COUNT(*) FROM usr_figures"
|
||||
" WHERE NumClicks>0"
|
||||
" AND FirstClickTime>FROM_UNIXTIME(0)");
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -883,8 +885,10 @@ static void Prf_GetNumClicksAndStoreAsUsrFigure (long UsrCod)
|
|||
Prf_ResetUsrFigures (&UsrFigures);
|
||||
|
||||
/***** Get number of clicks from database *****/
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM log_full WHERE UsrCod=%ld",UsrCod);
|
||||
UsrFigures.NumClicks = (long) DB_QueryCOUNT_new ("can not get number of clicks");
|
||||
UsrFigures.NumClicks =
|
||||
(long) DB_QueryCOUNT ("can not get number of clicks",
|
||||
"SELECT COUNT(*) FROM log_full WHERE UsrCod=%ld",
|
||||
UsrCod);
|
||||
|
||||
/***** Update number of clicks in user's figures *****/
|
||||
if (Prf_CheckIfUsrFiguresExists (UsrCod))
|
||||
|
@ -1062,8 +1066,9 @@ void Prf_RemoveUsrFigures (long UsrCod)
|
|||
|
||||
static bool Prf_CheckIfUsrFiguresExists (long UsrCod)
|
||||
{
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM usr_figures WHERE UsrCod=%ld",UsrCod);
|
||||
return (DB_QueryCOUNT_new ("can not get user's first click") != 0);
|
||||
return (DB_QueryCOUNT ("can not get user's first click",
|
||||
"SELECT COUNT(*) FROM usr_figures WHERE UsrCod=%ld",
|
||||
UsrCod) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -1337,7 +1342,7 @@ void Prf_GetAndShowRankingClicksPerDay (void)
|
|||
"NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1) AS NumClicksPerDay"
|
||||
" FROM usr_figures"
|
||||
" WHERE NumClicks>0"
|
||||
" AND UNIX_TIMESTAMP(FirstClickTime)>0"
|
||||
" AND FirstClickTime>FROM_UNIXTIME(0)"
|
||||
" AND UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
|
||||
" ORDER BY NumClicksPerDay DESC,UsrCod LIMIT 100");
|
||||
break;
|
||||
|
@ -1355,7 +1360,7 @@ void Prf_GetAndShowRankingClicksPerDay (void)
|
|||
" AND courses.CrsCod=crs_usr.CrsCod"
|
||||
" AND crs_usr.UsrCod=usr_figures.UsrCod"
|
||||
" AND usr_figures.NumClicks>0"
|
||||
" AND UNIX_TIMESTAMP(usr_figures.FirstClickTime)>0"
|
||||
" AND usr_figures.FirstClickTime>FROM_UNIXTIME(0)"
|
||||
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
|
||||
" ORDER BY NumClicksPerDay DESC,usr_figures.UsrCod LIMIT 100",
|
||||
Gbl.CurrentCty.Cty.CtyCod);
|
||||
|
@ -1373,7 +1378,7 @@ void Prf_GetAndShowRankingClicksPerDay (void)
|
|||
" AND courses.CrsCod=crs_usr.CrsCod"
|
||||
" AND crs_usr.UsrCod=usr_figures.UsrCod"
|
||||
" AND usr_figures.NumClicks>0"
|
||||
" AND UNIX_TIMESTAMP(usr_figures.FirstClickTime)>0"
|
||||
" AND usr_figures.FirstClickTime>FROM_UNIXTIME(0)"
|
||||
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
|
||||
" ORDER BY NumClicksPerDay DESC,usr_figures.UsrCod LIMIT 100",
|
||||
Gbl.CurrentIns.Ins.InsCod);
|
||||
|
@ -1390,7 +1395,7 @@ void Prf_GetAndShowRankingClicksPerDay (void)
|
|||
" AND courses.CrsCod=crs_usr.CrsCod"
|
||||
" AND crs_usr.UsrCod=usr_figures.UsrCod"
|
||||
" AND usr_figures.NumClicks>0"
|
||||
" AND UNIX_TIMESTAMP(usr_figures.FirstClickTime)>0"
|
||||
" AND usr_figures.FirstClickTime>FROM_UNIXTIME(0)"
|
||||
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
|
||||
" ORDER BY NumClicksPerDay DESC,usr_figures.UsrCod LIMIT 100",
|
||||
Gbl.CurrentCtr.Ctr.CtrCod);
|
||||
|
@ -1406,7 +1411,7 @@ void Prf_GetAndShowRankingClicksPerDay (void)
|
|||
" AND courses.CrsCod=crs_usr.CrsCod"
|
||||
" AND crs_usr.UsrCod=usr_figures.UsrCod"
|
||||
" AND usr_figures.NumClicks>0"
|
||||
" AND UNIX_TIMESTAMP(usr_figures.FirstClickTime)>0"
|
||||
" AND usr_figures.FirstClickTime>FROM_UNIXTIME(0)"
|
||||
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
|
||||
" ORDER BY NumClicksPerDay DESC,usr_figures.UsrCod LIMIT 100",
|
||||
Gbl.CurrentDeg.Deg.DegCod);
|
||||
|
@ -1421,7 +1426,7 @@ void Prf_GetAndShowRankingClicksPerDay (void)
|
|||
" WHERE crs_usr.CrsCod=%ld"
|
||||
" AND crs_usr.UsrCod=usr_figures.UsrCod"
|
||||
" AND usr_figures.NumClicks>0"
|
||||
" AND UNIX_TIMESTAMP(usr_figures.FirstClickTime)>0"
|
||||
" AND usr_figures.FirstClickTime>FROM_UNIXTIME(0)"
|
||||
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
|
||||
" ORDER BY NumClicksPerDay DESC,usr_figures.UsrCod LIMIT 100",
|
||||
Gbl.CurrentCrs.Crs.CrsCod);
|
||||
|
|
|
@ -630,11 +630,12 @@ long Rec_GetFieldCod (void)
|
|||
unsigned Rec_CountNumRecordsInCurrCrsWithField (long FieldCod)
|
||||
{
|
||||
/***** Get number of cards with a given field in a course from database *****/
|
||||
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");
|
||||
return
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of records"
|
||||
" with a given field not empty in a course",
|
||||
"SELECT COUNT(*) FROM crs_records"
|
||||
" WHERE FieldCod=%ld",
|
||||
FieldCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -63,8 +63,9 @@ static bool Ses_CheckIfHiddenParIsAlreadyInDB (Act_Action_t NextAction,
|
|||
void Ses_GetNumSessions (void)
|
||||
{
|
||||
/***** Get the number of open sessions from database *****/
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM sessions");
|
||||
Gbl.Session.NumSessions = (unsigned) DB_QueryCOUNT_new ("can not get the number of open sessions");
|
||||
Gbl.Session.NumSessions =
|
||||
(unsigned) DB_QueryCOUNT ("can not get the number of open sessions",
|
||||
"SELECT COUNT(*) FROM sessions");
|
||||
|
||||
Gbl.Usrs.Connected.TimeToRefreshInMs = (unsigned long) (Gbl.Session.NumSessions/Cfg_TIMES_PER_SECOND_REFRESH_CONNECTED) * 1000UL;
|
||||
if (Gbl.Usrs.Connected.TimeToRefreshInMs < Con_MIN_TIME_TO_REFRESH_CONNECTED_IN_MS)
|
||||
|
@ -106,8 +107,10 @@ void Ses_CreateSession (void)
|
|||
bool Ses_CheckIfSessionExists (const char *IdSes)
|
||||
{
|
||||
/***** Get if session already exists in database *****/
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM sessions WHERE SessionId='%s'",IdSes);
|
||||
return (DB_QueryCOUNT_new ("can not check if a session already existed") != 0);
|
||||
return (DB_QueryCOUNT ("can not check if a session already existed",
|
||||
"SELECT COUNT(*) FROM sessions"
|
||||
" WHERE SessionId='%s'",
|
||||
IdSes) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -394,10 +397,13 @@ static bool Ses_CheckIfHiddenParIsAlreadyInDB (Act_Action_t NextAction,
|
|||
const char *ParamName)
|
||||
{
|
||||
/***** Get a hidden parameter from database *****/
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM hidden_params"
|
||||
" WHERE SessionId='%s' AND Action=%ld AND ParamName='%s'",
|
||||
Gbl.Session.Id,Act_GetActCod (NextAction),ParamName);
|
||||
return (DB_QueryCOUNT_new ("can not check if a hidden parameter is already in database") != 0);
|
||||
return (DB_QueryCOUNT ("can not check if a hidden parameter"
|
||||
" is already in database",
|
||||
"SELECT COUNT(*) FROM hidden_params"
|
||||
" WHERE SessionId='%s'"
|
||||
" AND Action=%ld AND ParamName='%s'",
|
||||
Gbl.Session.Id,
|
||||
Act_GetActCod (NextAction),ParamName) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -2426,10 +2426,10 @@ static void Soc_PutHiddenFormToWriteNewCommentToSocialNote (long NotCod,
|
|||
|
||||
static unsigned long Soc_GetNumCommentsInSocialNote (long NotCod)
|
||||
{
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM social_pubs"
|
||||
" WHERE NotCod=%ld AND PubType=%u",
|
||||
NotCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE);
|
||||
return DB_QueryCOUNT_new ("can not get number of comments in a social note");
|
||||
return DB_QueryCOUNT ("can not get number of comments in a social note",
|
||||
"SELECT COUNT(*) FROM social_pubs"
|
||||
" WHERE NotCod=%ld AND PubType=%u",
|
||||
NotCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -4252,10 +4252,14 @@ void Soc_RemoveUsrSocialContent (long UsrCod)
|
|||
|
||||
static bool Soc_CheckIfNoteIsSharedByUsr (long NotCod,long UsrCod)
|
||||
{
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM social_pubs"
|
||||
" WHERE NotCod=%ld AND PublisherCod=%ld AND PubType=%u",
|
||||
NotCod,UsrCod,(unsigned) Soc_PUB_SHARED_NOTE);
|
||||
return (DB_QueryCOUNT_new ("can not check if a user has shared a social note") != 0);
|
||||
return (DB_QueryCOUNT ("can not check if a user has shared a social note",
|
||||
"SELECT COUNT(*) FROM social_pubs"
|
||||
" WHERE NotCod=%ld"
|
||||
" AND PublisherCod=%ld"
|
||||
" AND PubType=%u",
|
||||
NotCod,
|
||||
UsrCod,
|
||||
(unsigned) Soc_PUB_SHARED_NOTE) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -4264,10 +4268,11 @@ static bool Soc_CheckIfNoteIsSharedByUsr (long NotCod,long UsrCod)
|
|||
|
||||
static bool Soc_CheckIfNoteIsFavedByUsr (long NotCod,long UsrCod)
|
||||
{
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM social_notes_fav"
|
||||
" WHERE NotCod=%ld AND UsrCod=%ld",
|
||||
NotCod,UsrCod);
|
||||
return (DB_QueryCOUNT_new ("can not check if a user has favourited a social note") != 0);
|
||||
return (DB_QueryCOUNT ("can not check if a user"
|
||||
" has favourited a social note",
|
||||
"SELECT COUNT(*) FROM social_notes_fav"
|
||||
" WHERE NotCod=%ld AND UsrCod=%ld",
|
||||
NotCod,UsrCod) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -4276,10 +4281,11 @@ static bool Soc_CheckIfNoteIsFavedByUsr (long NotCod,long UsrCod)
|
|||
|
||||
static bool Soc_CheckIfCommIsFavedByUsr (long PubCod,long UsrCod)
|
||||
{
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM social_comments_fav"
|
||||
" WHERE PubCod=%ld AND UsrCod=%ld",
|
||||
PubCod,UsrCod);
|
||||
return (DB_QueryCOUNT_new ("can not check if a user has favourited a social comment") != 0);
|
||||
return (DB_QueryCOUNT ("can not check if a user"
|
||||
" has favourited a social comment",
|
||||
"SELECT COUNT(*) FROM social_comments_fav"
|
||||
" WHERE PubCod=%ld AND UsrCod=%ld",
|
||||
PubCod,UsrCod) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -4289,14 +4295,16 @@ static bool Soc_CheckIfCommIsFavedByUsr (long PubCod,long UsrCod)
|
|||
static unsigned Soc_UpdateNumTimesANoteHasBeenShared (struct SocialNote *SocNot)
|
||||
{
|
||||
/***** Get number of times (users) this note has been shared *****/
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM social_pubs"
|
||||
" WHERE NotCod=%ld"
|
||||
" AND PublisherCod<>%ld"
|
||||
" AND PubType=%u",
|
||||
SocNot->NotCod,
|
||||
SocNot->UsrCod, // The author
|
||||
(unsigned) Soc_PUB_SHARED_NOTE);
|
||||
return (unsigned) DB_QueryCOUNT_new ("can not get number of times a note has been shared");
|
||||
return
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of times"
|
||||
" a note has been shared",
|
||||
"SELECT COUNT(*) FROM social_pubs"
|
||||
" WHERE NotCod=%ld"
|
||||
" AND PublisherCod<>%ld"
|
||||
" AND PubType=%u",
|
||||
SocNot->NotCod,
|
||||
SocNot->UsrCod, // The author
|
||||
(unsigned) Soc_PUB_SHARED_NOTE);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -4306,12 +4314,14 @@ static unsigned Soc_UpdateNumTimesANoteHasBeenShared (struct SocialNote *SocNot)
|
|||
static unsigned Soc_GetNumTimesANoteHasBeenFav (struct SocialNote *SocNot)
|
||||
{
|
||||
/***** Get number of times (users) this note has been favourited *****/
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM social_notes_fav"
|
||||
" WHERE NotCod=%ld"
|
||||
" AND UsrCod<>%ld", // Extra check
|
||||
SocNot->NotCod,
|
||||
SocNot->UsrCod); // The author
|
||||
return (unsigned) DB_QueryCOUNT_new ("can not get number of times a note has been favourited");
|
||||
return
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of times"
|
||||
" a note has been favourited",
|
||||
"SELECT COUNT(*) FROM social_notes_fav"
|
||||
" WHERE NotCod=%ld"
|
||||
" AND UsrCod<>%ld", // Extra check
|
||||
SocNot->NotCod,
|
||||
SocNot->UsrCod); // The author
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -4321,12 +4331,14 @@ static unsigned Soc_GetNumTimesANoteHasBeenFav (struct SocialNote *SocNot)
|
|||
static unsigned Soc_GetNumTimesACommHasBeenFav (struct SocialComment *SocCom)
|
||||
{
|
||||
/***** Get number of times (users) this comment has been favourited *****/
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM social_comments_fav"
|
||||
" WHERE PubCod=%ld"
|
||||
" AND UsrCod<>%ld", // Extra check
|
||||
SocCom->PubCod,
|
||||
SocCom->UsrCod); // The author
|
||||
return (unsigned) DB_QueryCOUNT_new ("can not get number of times a comment has been favourited");
|
||||
return
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of times"
|
||||
" a comment has been favourited",
|
||||
"SELECT COUNT(*) FROM social_comments_fav"
|
||||
" WHERE PubCod=%ld"
|
||||
" AND UsrCod<>%ld", // Extra check
|
||||
SocCom->PubCod,
|
||||
SocCom->UsrCod); // The author
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
1252
swad_statistic.c
1252
swad_statistic.c
File diff suppressed because it is too large
Load Diff
|
@ -1671,9 +1671,9 @@ void Tst_RenameTag (void)
|
|||
static bool Tst_CheckIfCurrentCrsHasTestTags (void)
|
||||
{
|
||||
/***** Get available tags from database *****/
|
||||
DB_BuildQuery ("SELECT COUNT(*) FROM tst_tags WHERE CrsCod=%ld",
|
||||
Gbl.CurrentCrs.Crs.CrsCod);
|
||||
return (DB_QueryCOUNT_new ("can not check if course has tags") != 0);
|
||||
return (DB_QueryCOUNT ("can not check if course has tags",
|
||||
"SELECT COUNT(*) FROM tst_tags WHERE CrsCod=%ld",
|
||||
Gbl.CurrentCrs.Crs.CrsCod) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
Loading…
Reference in New Issue