Version 18.11.7

This commit is contained in:
Antonio Cañas Vargas 2018-10-31 10:19:01 +01:00
parent ad7ec2156c
commit 7bfe4197e8
5 changed files with 488 additions and 436 deletions

View File

@ -355,10 +355,11 @@ En OpenSWAD:
ps2pdf source.ps destination.pdf
*/
#define Log_PLATFORM_VERSION "SWAD 18.11.6 (2018-10-31)"
#define Log_PLATFORM_VERSION "SWAD 18.11.7 (2018-10-31)"
#define CSS_FILE "swad18.4.css"
#define JS_FILE "swad17.17.1.js"
/*
Version 18.11.7: Oct 31, 2018 Joining building and performing query into one function. (235741 lines)
Version 18.11.6: Oct 31, 2018 Joining building and performing query into one function. (235687 lines)
Version 18.11.5: Oct 31, 2018 Joining building and performing query into one function. (235619 lines)
Version 18.11.4: Oct 30, 2018 Joining building and performing query into one function. (235593 lines)

View File

@ -3175,6 +3175,25 @@ unsigned long DB_QuerySELECT_old (char **Query,MYSQL_RES **mysql_res,const char
/**************** Make a SELECT COUNT query from database ********************/
/*****************************************************************************/
unsigned long DB_QueryCOUNT (const char *MsgError,
const char *fmt,...)
{
int NumBytesPrinted;
va_list ap;
char *Query = NULL;
va_start (ap,fmt);
NumBytesPrinted = vasprintf (&Query,fmt,ap);
va_end (ap);
if (NumBytesPrinted < 0) // If memory allocation wasn't possible,
// or some other error occurs,
// vasprintf will return -1
Lay_NotEnoughMemoryExit ();
return DB_QueryCOUNT_old (&Query,MsgError);
}
unsigned long DB_QueryCOUNT_new (const char *MsgError)
{
return DB_QueryCOUNT_old (&Gbl.DB.QueryPtr,MsgError);

View File

@ -45,6 +45,8 @@ unsigned long DB_QuerySELECT (MYSQL_RES **mysql_res,const char *MsgError,
unsigned long DB_QuerySELECT_new (MYSQL_RES **mysql_res,const char *MsgError);
unsigned long DB_QuerySELECT_old (char **Query,MYSQL_RES **mysql_res,const char *MsgError);
unsigned long DB_QueryCOUNT (const char *MsgError,
const char *fmt,...);
unsigned long DB_QueryCOUNT_new (const char *MsgError);
unsigned long DB_QueryCOUNT_old (char **Query,const char *MsgError);

View File

@ -888,7 +888,7 @@ void Gam_GetListGames (void)
char OrderBySubQuery[256];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
unsigned long NumRows = 0; // Initialized to avoid warning
unsigned NumGame;
unsigned ScopesAllowed = 0;
unsigned HiddenAllowed = 0;
@ -975,7 +975,9 @@ void Gam_GetListGames (void)
break;
}
DB_BuildQuery ("SELECT GamCod FROM games"
/* Make query */
NumRows = DB_QuerySELECT (&mysql_res,"can not get games",
"SELECT GamCod FROM games"
" WHERE %s%s%s%s%s%s"
" ORDER BY %s",
SubQuery[Sco_SCOPE_SYS],
@ -989,9 +991,6 @@ void Gam_GetListGames (void)
else
Lay_ShowErrorAndExit ("Can not get list of games.");
/* Make query */
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get games");
if (NumRows) // Games found...
{
Gbl.Games.Num = (unsigned) NumRows;
@ -1197,8 +1196,9 @@ void Gam_GetDataOfGameByCod (struct Game *Game)
MYSQL_ROW row;
unsigned long NumRows;
/***** Build query *****/
DB_BuildQuery ("SELECT GamCod,Scope,Cod,Hidden,Roles,UsrCod,"
/***** Get data of game from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get game data",
"SELECT GamCod,Scope,Cod,Hidden,Roles,UsrCod,"
"UNIX_TIMESTAMP(StartTime),"
"UNIX_TIMESTAMP(EndTime),"
"NOW() BETWEEN StartTime AND EndTime,"
@ -1206,10 +1206,6 @@ void Gam_GetDataOfGameByCod (struct Game *Game)
" FROM games"
" WHERE GamCod=%ld",
Game->GamCod);
/***** Get data of game from database *****/
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get game data");
if (NumRows) // Game found...
{
/* Get row */
@ -1428,8 +1424,9 @@ static void Gam_GetGameTxtFromDB (long GamCod,char Txt[Cns_MAX_BYTES_TEXT + 1])
unsigned long NumRows;
/***** Get text of game from database *****/
DB_BuildQuery ("SELECT Txt FROM games WHERE GamCod=%ld",GamCod);
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get game text");
NumRows = DB_QuerySELECT (&mysql_res,"can not get game text",
"SELECT Txt FROM games WHERE GamCod=%ld",
GamCod);
/***** The result of the query must have one row or none *****/
if (NumRows == 1)
@ -2343,14 +2340,14 @@ static void Gam_GetAndWriteNamesOfGrpsAssociatedToGame (struct Game *Game)
unsigned long NumRows;
/***** Get groups associated to a game from database *****/
DB_BuildQuery ("SELECT crs_grp_types.GrpTypName,crs_grp.GrpName"
NumRows = DB_QuerySELECT (&mysql_res,"can not get groups of a game",
"SELECT crs_grp_types.GrpTypName,crs_grp.GrpName"
" FROM gam_grp,crs_grp,crs_grp_types"
" WHERE gam_grp.GamCod=%ld"
" AND gam_grp.GrpCod=crs_grp.GrpCod"
" AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod"
" ORDER BY crs_grp_types.GrpTypName,crs_grp.GrpName",
Game->GamCod);
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get groups of a game");
/***** Write heading *****/
fprintf (Gbl.F.Out,"<div class=\"%s\">%s: ",
@ -2564,10 +2561,10 @@ static int Gam_GetQstIndFromQstCod (long GamCod,long QstCod)
int QstInd = -1;
/***** Get number of games with a field value from database *****/
DB_BuildQuery ("SELECT QstInd FROM gam_questions"
if (!DB_QuerySELECT (&mysql_res,"can not get question index",
"SELECT QstInd FROM gam_questions"
" WHERE GamCod=%ld AND QstCod=%ld",
GamCod,QstCod);
if (!DB_QuerySELECT_new (&mysql_res,"can not get question index"))
GamCod,QstCod))
Lay_ShowErrorAndExit ("Error when getting question index.");
/***** Get question index (row[0]) *****/
@ -2593,10 +2590,10 @@ static long Gam_GetQstCodFromQstInd (long GamCod,unsigned QstInd)
long QstCod;
/***** Get question code of thw question to be moved up *****/
DB_BuildQuery ("SELECT QstCod FROM gam_questions"
if (!DB_QuerySELECT (&mysql_res,"can not get question code",
"SELECT QstCod FROM gam_questions"
" WHERE GamCod=%ld AND QstInd=%u",
GamCod,QstInd);
if (!DB_QuerySELECT_new (&mysql_res,"can not get question code"))
GamCod,QstInd))
Lay_ShowErrorAndExit ("Error: wrong question code.");
/***** Get question code (row[0]) *****/
@ -2623,9 +2620,9 @@ static int Gam_GetMaxQuestionIndexInGame (long GamCod)
int QstInd = -1;
/***** Get maximum question index in a game from database *****/
DB_BuildQuery ("SELECT MAX(QstInd) FROM gam_questions WHERE GamCod=%ld",
DB_QuerySELECT (&mysql_res,"can not get last question index",
"SELECT MAX(QstInd) FROM gam_questions WHERE GamCod=%ld",
GamCod);
DB_QuerySELECT_new (&mysql_res,"can not get last question index");
row = mysql_fetch_row (mysql_res);
if (row[0]) // There are questions
if (sscanf (row[0],"%d",&QstInd) != 1)
@ -2652,10 +2649,10 @@ static int Gam_GetPrevQuestionIndexInGame (long GamCod,unsigned QstInd)
/***** Get previous question index in a game from database *****/
// Although indexes are always continuous...
// ...this implementation works even with non continuous indexes
DB_BuildQuery ("SELECT MAX(QstInd) FROM gam_questions"
if (!DB_QuerySELECT (&mysql_res,"can not get previous question index",
"SELECT MAX(QstInd) FROM gam_questions"
" WHERE GamCod=%ld AND QstInd<%u",
GamCod,QstInd);
if (!DB_QuerySELECT_new (&mysql_res,"can not get previous question index"))
GamCod,QstInd))
Lay_ShowErrorAndExit ("Error: previous question index not found.");
/***** Get previous question index (row[0]) *****/
@ -2685,10 +2682,10 @@ static int Gam_GetNextQuestionIndexInGame (long GamCod,unsigned QstInd)
/***** Get next question index in a game from database *****/
// Although indexes are always continuous...
// ...this implementation works even with non continuous indexes
DB_BuildQuery ("SELECT MIN(QstInd) FROM gam_questions"
if (!DB_QuerySELECT (&mysql_res,"can not get next question index",
"SELECT MIN(QstInd) FROM gam_questions"
" WHERE GamCod=%ld AND QstInd>%u",
GamCod,QstInd);
if (!DB_QuerySELECT_new (&mysql_res,"can not get next question index"))
GamCod,QstInd))
Lay_ShowErrorAndExit ("Error: next question index not found.");
/***** Get next question index (row[0]) *****/
@ -2735,7 +2732,8 @@ static void Gam_ListGameQuestions (struct Game *Game)
row[5] ImageTitle
row[6] ImageURL
*/
DB_BuildQuery ("SELECT tst_questions.QstCod,"
NumQsts = (unsigned) DB_QuerySELECT (&mysql_res,"can not get data of a question",
"SELECT tst_questions.QstCod,"
"tst_questions.AnsType,"
"tst_questions.Stem,"
"tst_questions.Feedback,"
@ -2747,7 +2745,6 @@ static void Gam_ListGameQuestions (struct Game *Game)
" AND gam_questions.QstCod=tst_questions.QstCod"
" ORDER BY gam_questions.QstInd",
Game->GamCod);
NumQsts = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get data of a question");
/***** Start box *****/
Gbl.Games.CurrentGamCod = Game->GamCod;
@ -3129,10 +3126,10 @@ static unsigned Gam_GetNumUsrsWhoAnswered (long GamCod,long QstCod,unsigned AnsI
unsigned NumUsrs = 0; // Default returned value
/***** Get answers of a question from database *****/
DB_BuildQuery ("SELECT NumUsrs FROM gam_answers"
if (DB_QuerySELECT (&mysql_res,"can not get number of users who answered",
"SELECT NumUsrs FROM gam_answers"
" WHERE GamCod=%ld AND QstCod=%ld AND AnsInd=%u",
GamCod,QstCod,AnsInd);
if (DB_QuerySELECT_new (&mysql_res,"can not get number of users who answered"))
GamCod,QstCod,AnsInd))
{
row = mysql_fetch_row (mysql_res);
if (row[0]) // There are users who selected this answer
@ -3543,7 +3540,8 @@ static void Gam_PlayGameShowQuestionAndAnswers (bool ShowAnswers)
row[4] ImageTitle
row[5] ImageURL
*/
DB_BuildQuery ("SELECT "
if (!DB_QuerySELECT (&mysql_res,"can not get data of a question",
"SELECT "
"tst_questions.QstCod,"
"tst_questions.AnsType,"
"tst_questions.Stem,"
@ -3554,8 +3552,7 @@ static void Gam_PlayGameShowQuestionAndAnswers (bool ShowAnswers)
" WHERE gam_questions.GamCod=%ld"
" AND gam_questions.QstInd=%u"
" AND gam_questions.QstCod=tst_questions.QstCod",
Game.GamCod,QstInd);
if (!DB_QuerySELECT_new (&mysql_res,"can not get data of a question"))
Game.GamCod,QstInd))
Ale_ShowAlert (Ale_WARNING,"Questions doesn't exist.");
row = mysql_fetch_row (mysql_res);
@ -3700,10 +3697,11 @@ static void Gam_ReceiveAndStoreUserAnswersToAGame (long GamCod)
unsigned AnsInd;
/***** Get questions of this game from database *****/
DB_BuildQuery ("SELECT QstCod FROM gam_questions"
NumQsts = (unsigned) DB_QuerySELECT (&mysql_res,"can not get questions of a game",
"SELECT QstCod FROM gam_questions"
" WHERE GamCod=%ld ORDER BY QstCod",
GamCod);
if ((NumQsts = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get questions of a game"))) // The game has questions
if (NumQsts) // The game has questions
{
/***** Get questions *****/
for (NumQst = 0;
@ -3812,13 +3810,15 @@ unsigned Gam_GetNumCoursesWithGames (Sco_Scope_t Scope)
switch (Scope)
{
case Sco_SCOPE_SYS:
DB_BuildQuery ("SELECT COUNT(DISTINCT Cod)"
DB_QuerySELECT (&mysql_res,"can not get number of courses with games",
"SELECT COUNT(DISTINCT Cod)"
" FROM games"
" WHERE Scope='%s'",
Sco_ScopeDB[Sco_SCOPE_CRS]);
break;
case Sco_SCOPE_CTY:
DB_BuildQuery ("SELECT COUNT(DISTINCT games.Cod)"
DB_QuerySELECT (&mysql_res,"can not get number of courses with games",
"SELECT COUNT(DISTINCT games.Cod)"
" FROM institutions,centres,degrees,courses,games"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
@ -3830,7 +3830,8 @@ unsigned Gam_GetNumCoursesWithGames (Sco_Scope_t Scope)
Sco_ScopeDB[Sco_SCOPE_CRS]);
break;
case Sco_SCOPE_INS:
DB_BuildQuery ("SELECT COUNT(DISTINCT games.Cod)"
DB_QuerySELECT (&mysql_res,"can not get number of courses with games",
"SELECT COUNT(DISTINCT games.Cod)"
" FROM centres,degrees,courses,games"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
@ -3841,7 +3842,7 @@ unsigned Gam_GetNumCoursesWithGames (Sco_Scope_t Scope)
Sco_ScopeDB[Sco_SCOPE_CRS]);
break;
case Sco_SCOPE_CTR:
DB_BuildQuery ("SELECT COUNT(DISTINCT games.Cod)"
DB_QuerySELECT (&mysql_res,"can not get number of courses with games",
" FROM degrees,courses,games"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
@ -3851,7 +3852,8 @@ unsigned Gam_GetNumCoursesWithGames (Sco_Scope_t Scope)
Sco_ScopeDB[Sco_SCOPE_CRS]);
break;
case Sco_SCOPE_DEG:
DB_BuildQuery ("SELECT COUNT(DISTINCT games.Cod)"
DB_QuerySELECT (&mysql_res,"can not get number of courses with games",
"SELECT COUNT(DISTINCT games.Cod)"
" FROM courses,games"
" WHERE courses.DegCod=%ld"
" AND courses.CrsCod=games.Cod"
@ -3860,7 +3862,8 @@ unsigned Gam_GetNumCoursesWithGames (Sco_Scope_t Scope)
Sco_ScopeDB[Sco_SCOPE_CRS]);
break;
case Sco_SCOPE_CRS:
DB_BuildQuery ("SELECT COUNT(DISTINCT Cod)"
DB_QuerySELECT (&mysql_res,"can not get number of courses with games",
"SELECT COUNT(DISTINCT Cod)"
" FROM games"
" WHERE Scope='%s' AND Cod=%ld",
Sco_ScopeDB[Sco_SCOPE_CRS],
@ -3870,7 +3873,6 @@ unsigned Gam_GetNumCoursesWithGames (Sco_Scope_t Scope)
Lay_WrongScopeExit ();
break;
}
DB_QuerySELECT_new (&mysql_res,"can not get number of courses with games");
/***** Get number of games *****/
row = mysql_fetch_row (mysql_res);
@ -3899,13 +3901,15 @@ unsigned Gam_GetNumGames (Sco_Scope_t Scope)
switch (Scope)
{
case Sco_SCOPE_SYS:
DB_BuildQuery ("SELECT COUNT(*)"
DB_QuerySELECT (&mysql_res,"can not get number of games",
"SELECT COUNT(*)"
" FROM games"
" WHERE Scope='%s'",
Sco_ScopeDB[Sco_SCOPE_CRS]);
break;
case Sco_SCOPE_CTY:
DB_BuildQuery ("SELECT COUNT(*)"
DB_QuerySELECT (&mysql_res,"can not get number of games",
"SELECT COUNT(*)"
" FROM institutions,centres,degrees,courses,games"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
@ -3917,7 +3921,8 @@ unsigned Gam_GetNumGames (Sco_Scope_t Scope)
Sco_ScopeDB[Sco_SCOPE_CRS]);
break;
case Sco_SCOPE_INS:
DB_BuildQuery ("SELECT COUNT(*)"
DB_QuerySELECT (&mysql_res,"can not get number of games",
"SELECT COUNT(*)"
" FROM centres,degrees,courses,games"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
@ -3928,7 +3933,8 @@ unsigned Gam_GetNumGames (Sco_Scope_t Scope)
Sco_ScopeDB[Sco_SCOPE_CRS]);
break;
case Sco_SCOPE_CTR:
DB_BuildQuery ("SELECT COUNT(*)"
DB_QuerySELECT (&mysql_res,"can not get number of games",
"SELECT COUNT(*)"
" FROM degrees,courses,games"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
@ -3938,7 +3944,8 @@ unsigned Gam_GetNumGames (Sco_Scope_t Scope)
Sco_ScopeDB[Sco_SCOPE_CRS]);
break;
case Sco_SCOPE_DEG:
DB_BuildQuery ("SELECT COUNT(*)"
DB_QuerySELECT (&mysql_res,"can not get number of games",
"SELECT COUNT(*)"
" FROM courses,games"
" WHERE courses.DegCod=%ld"
" AND courses.CrsCod=games.Cod"
@ -3947,7 +3954,8 @@ unsigned Gam_GetNumGames (Sco_Scope_t Scope)
Sco_ScopeDB[Sco_SCOPE_CRS]);
break;
case Sco_SCOPE_CRS:
DB_BuildQuery ("SELECT COUNT(*)"
DB_QuerySELECT (&mysql_res,"can not get number of games",
"SELECT COUNT(*)"
" FROM games"
" WHERE games.Scope='%s'"
" AND CrsCod=%ld",
@ -3958,7 +3966,6 @@ unsigned Gam_GetNumGames (Sco_Scope_t Scope)
Lay_WrongScopeExit ();
break;
}
DB_QuerySELECT_new (&mysql_res,"can not get number of games");
/***** Get number of games *****/
row = mysql_fetch_row (mysql_res);
@ -3986,7 +3993,8 @@ float Gam_GetNumQstsPerCrsGame (Sco_Scope_t Scope)
switch (Scope)
{
case Sco_SCOPE_SYS:
DB_BuildQuery ("SELECT AVG(NumQsts) FROM"
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
" FROM games,gam_questions"
" WHERE games.Scope='%s'"
@ -3995,7 +4003,8 @@ float Gam_GetNumQstsPerCrsGame (Sco_Scope_t Scope)
Sco_ScopeDB[Sco_SCOPE_CRS]);
break;
case Sco_SCOPE_CTY:
DB_BuildQuery ("SELECT AVG(NumQsts) FROM"
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
" FROM institutions,centres,degrees,courses,games,gam_questions"
" WHERE institutions.CtyCod=%ld"
@ -4010,7 +4019,8 @@ float Gam_GetNumQstsPerCrsGame (Sco_Scope_t Scope)
Sco_ScopeDB[Sco_SCOPE_CRS]);
break;
case Sco_SCOPE_INS:
DB_BuildQuery ("SELECT AVG(NumQsts) FROM"
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
" FROM centres,degrees,courses,games,gam_questions"
" WHERE centres.InsCod=%ld"
@ -4024,7 +4034,8 @@ float Gam_GetNumQstsPerCrsGame (Sco_Scope_t Scope)
Sco_ScopeDB[Sco_SCOPE_CRS]);
break;
case Sco_SCOPE_CTR:
DB_BuildQuery ("SELECT AVG(NumQsts) FROM"
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
" FROM degrees,courses,games,gam_questions"
" WHERE degrees.CtrCod=%ld"
@ -4037,7 +4048,8 @@ float Gam_GetNumQstsPerCrsGame (Sco_Scope_t Scope)
Sco_ScopeDB[Sco_SCOPE_CRS]);
break;
case Sco_SCOPE_DEG:
DB_BuildQuery ("SELECT AVG(NumQsts) FROM"
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
" FROM courses,games,gam_questions"
" WHERE courses.DegCod=%ld"
@ -4049,7 +4061,8 @@ float Gam_GetNumQstsPerCrsGame (Sco_Scope_t Scope)
Sco_ScopeDB[Sco_SCOPE_CRS]);
break;
case Sco_SCOPE_CRS:
DB_BuildQuery ("SELECT AVG(NumQsts) FROM"
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
" FROM games,gam_questions"
" WHERE games.Scope='%s' AND games.Cod=%ld"
@ -4061,7 +4074,6 @@ float Gam_GetNumQstsPerCrsGame (Sco_Scope_t Scope)
Lay_WrongScopeExit ();
break;
}
DB_QuerySELECT_new (&mysql_res,"can not get number of questions per game");
/***** Get number of courses *****/
row = mysql_fetch_row (mysql_res);

View File

@ -128,7 +128,7 @@ static unsigned Grp_CountNumGrpsInThisCrsOfType (long GrpTypCod);
static void Grp_GetDataOfGroupTypeByCod (struct GroupType *GrpTyp);
static bool Grp_GetMultipleEnrolmentOfAGroupType (long GrpTypCod);
static long Grp_GetTypeOfGroupOfAGroup (long GrpCod);
static unsigned Grp_CountNumUsrsInNoGrpsOfType (Rol_Role_t Role,long GrpTypCod);
static unsigned long Grp_CountNumUsrsInNoGrpsOfType (Rol_Role_t Role,long GrpTypCod);
static long Grp_GetFirstCodGrpIBelongTo (long GrpTypCod);
static bool Grp_GetIfGrpIsAvailable (long GrpTypCod);
static void Grp_GetLstCodGrpsUsrBelongs (long CrsCod,long GrpTypCod,long UsrCod,
@ -2305,7 +2305,7 @@ static void Grp_ListGrpsForMultipleSelection (struct GroupType *GrpTyp,
Role >= Rol_STD;
Role--)
fprintf (Gbl.F.Out,"<td class=\"DAT CENTER_MIDDLE\">"
"%u"
"%lu"
"</td>",
Grp_CountNumUsrsInNoGrpsOfType (Role,GrpTyp->GrpTypCod));
@ -2674,7 +2674,7 @@ void Grp_GetListGrpTypesInThisCrs (Grp_WhichGroupTypes_t WhichGroupTypes)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRow;
unsigned long NumGrpTyp;
if (++Gbl.CurrentCrs.Grps.GrpTypes.NestedCalls > 1) // If list is created yet, there's nothing to do
return;
@ -2688,7 +2688,10 @@ void Grp_GetListGrpTypesInThisCrs (Grp_WhichGroupTypes_t WhichGroupTypes)
switch (WhichGroupTypes)
{
case Grp_ONLY_GROUP_TYPES_WITH_GROUPS:
DB_BuildQuery ("SELECT crs_grp_types.GrpTypCod,crs_grp_types.GrpTypName,"
Gbl.CurrentCrs.Grps.GrpTypes.Num =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get types of group"
" of a course",
"SELECT crs_grp_types.GrpTypCod,crs_grp_types.GrpTypName,"
"crs_grp_types.Mandatory,crs_grp_types.Multiple,"
"crs_grp_types.MustBeOpened,"
"UNIX_TIMESTAMP(crs_grp_types.OpenTime),"
@ -2701,7 +2704,10 @@ void Grp_GetListGrpTypesInThisCrs (Grp_WhichGroupTypes_t WhichGroupTypes)
Gbl.CurrentCrs.Crs.CrsCod);
break;
case Grp_ALL_GROUP_TYPES:
DB_BuildQuery ("(SELECT crs_grp_types.GrpTypCod,crs_grp_types.GrpTypName AS GrpTypName,"
Gbl.CurrentCrs.Grps.GrpTypes.Num =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get types of group"
" of a course",
"(SELECT crs_grp_types.GrpTypCod,crs_grp_types.GrpTypName AS GrpTypName,"
"crs_grp_types.Mandatory,crs_grp_types.Multiple,"
"crs_grp_types.MustBeOpened,"
"UNIX_TIMESTAMP(crs_grp_types.OpenTime),"
@ -2723,7 +2729,6 @@ void Grp_GetListGrpTypesInThisCrs (Grp_WhichGroupTypes_t WhichGroupTypes)
Gbl.CurrentCrs.Crs.CrsCod);
break;
}
Gbl.CurrentCrs.Grps.GrpTypes.Num = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get types of group of a course");
/***** Get group types *****/
Gbl.CurrentCrs.Grps.GrpTypes.NumGrpsTotal = 0;
@ -2735,43 +2740,43 @@ void Grp_GetListGrpTypesInThisCrs (Grp_WhichGroupTypes_t WhichGroupTypes)
Lay_NotEnoughMemoryExit ();
/***** Get group types *****/
for (NumRow = 0;
NumRow < Gbl.CurrentCrs.Grps.GrpTypes.Num;
NumRow++)
for (NumGrpTyp = 0;
NumGrpTyp < Gbl.CurrentCrs.Grps.GrpTypes.Num;
NumGrpTyp++)
{
/* Get next group type */
row = mysql_fetch_row (mysql_res);
/* Get group type code (row[0]) */
if ((Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumRow].GrpTypCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
if ((Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].GrpTypCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong type of group.");
/* Get group type name (row[1]) */
Str_Copy (Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumRow].GrpTypName,row[1],
Str_Copy (Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].GrpTypName,row[1],
Grp_MAX_BYTES_GROUP_TYPE_NAME);
/* Is it mandatory to register in any groups of this type? (row[2]) */
Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumRow].MandatoryEnrolment = (row[2][0] == 'Y');
Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].MandatoryEnrolment = (row[2][0] == 'Y');
/* Is it possible to register in multiple groups of this type? (row[3]) */
Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumRow].MultipleEnrolment = (row[3][0] == 'Y');
Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].MultipleEnrolment = (row[3][0] == 'Y');
/* Groups of this type must be opened? (row[4]) */
Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumRow].MustBeOpened = (row[4][0] == 'Y');
Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].MustBeOpened = (row[4][0] == 'Y');
/* Get open time (row[5] holds the open time UTC) */
Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumRow].OpenTimeUTC = Dat_GetUNIXTimeFromStr (row[5]);
Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumRow].MustBeOpened &= Grp_CheckIfOpenTimeInTheFuture (Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumRow].OpenTimeUTC);
Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].OpenTimeUTC = Dat_GetUNIXTimeFromStr (row[5]);
Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].MustBeOpened &= Grp_CheckIfOpenTimeInTheFuture (Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].OpenTimeUTC);
/* Number of groups of this type (row[6]) */
if (sscanf (row[6],"%u",&Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumRow].NumGrps) != 1)
if (sscanf (row[6],"%u",&Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].NumGrps) != 1)
Lay_ShowErrorAndExit ("Wrong number of groups of a type.");
/* Add number of groups to total number of groups */
Gbl.CurrentCrs.Grps.GrpTypes.NumGrpsTotal += Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumRow].NumGrps;
Gbl.CurrentCrs.Grps.GrpTypes.NumGrpsTotal += Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].NumGrps;
/* Initialize pointer to the list of groups of this type */
Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumRow].LstGrps = NULL;
Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].LstGrps = NULL;
}
}
@ -2793,12 +2798,14 @@ void Grp_OpenGroupsAutomatically (void)
long GrpTypCod;
/***** Find group types to be opened *****/
DB_BuildQuery ("SELECT GrpTypCod FROM crs_grp_types"
NumGrpTypes =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get the types of group"
" to be opened",
"SELECT GrpTypCod FROM crs_grp_types"
" WHERE CrsCod=%ld AND MustBeOpened='Y'"
" AND OpenTime<=NOW()",
Gbl.CurrentCrs.Crs.CrsCod);
NumGrpTypes = (unsigned) DB_QuerySELECT_new (&mysql_res,
"can not get the types of group to be opened");
for (NumGrpTyp = 0;
NumGrpTyp < NumGrpTypes;
NumGrpTyp++)
@ -2973,12 +2980,12 @@ static unsigned Grp_CountNumGrpsInThisCrsOfType (long GrpTypCod)
unsigned long Grp_GetGrpsOfType (long GrpTypCod,MYSQL_RES **mysql_res)
{
/***** Get groups of a type from database *****/
DB_BuildQuery ("SELECT GrpCod,GrpName,MaxStudents,Open,FileZones"
return DB_QuerySELECT (mysql_res,"can not get groups of a type",
"SELECT GrpCod,GrpName,MaxStudents,Open,FileZones"
" FROM crs_grp"
" WHERE GrpTypCod=%ld"
" ORDER BY GrpName",
GrpTypCod);
return DB_QuerySELECT_new (mysql_res,"can not get groups of a type");
}
/*****************************************************************************/
@ -2993,11 +3000,15 @@ static void Grp_GetDataOfGroupTypeByCod (struct GroupType *GrpTyp)
unsigned long NumRows;
/***** Get data of a type of group from database *****/
DB_BuildQuery ("SELECT GrpTypName,Mandatory,Multiple,MustBeOpened,UNIX_TIMESTAMP(OpenTime)"
NumRows = DB_QuerySELECT (&mysql_res,"can not get type of group",
"SELECT GrpTypName,"
"Mandatory,"
"Multiple,"
"MustBeOpened,"
"UNIX_TIMESTAMP(OpenTime)"
" FROM crs_grp_types"
" WHERE CrsCod=%ld AND GrpTypCod=%ld",
Gbl.CurrentCrs.Crs.CrsCod,GrpTyp->GrpTypCod);
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get type of group");
/***** Count number of rows in result *****/
if (NumRows != 1)
@ -3027,9 +3038,11 @@ static bool Grp_GetMultipleEnrolmentOfAGroupType (long GrpTypCod)
bool MultipleEnrolment;
/***** Get data of a type of group from database *****/
DB_BuildQuery ("SELECT Multiple FROM crs_grp_types WHERE GrpTypCod=%ld",
GrpTypCod);
if (DB_QuerySELECT_new (&mysql_res,"can not get if type of group has multiple enrolment") != 1)
if (DB_QuerySELECT (&mysql_res,"can not get if type of group"
" has multiple enrolment",
"SELECT Multiple FROM crs_grp_types"
" WHERE GrpTypCod=%ld",
GrpTypCod) != 1)
Lay_ShowErrorAndExit ("Error when getting type of group.");
/***** Get multiple enrolment *****/
@ -3066,15 +3079,19 @@ void Grp_GetDataOfGroupByCod (struct GroupData *GrpDat)
if (GrpDat->GrpCod > 0)
{
/***** Get data of a group from database *****/
DB_BuildQuery ("SELECT crs_grp_types.GrpTypCod,crs_grp_types.CrsCod,"
"crs_grp_types.GrpTypName,crs_grp_types.Multiple,"
"crs_grp.GrpName,crs_grp.MaxStudents,"
"crs_grp.Open,crs_grp.FileZones"
NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a group",
"SELECT crs_grp_types.GrpTypCod,"
"crs_grp_types.CrsCod,"
"crs_grp_types.GrpTypName,"
"crs_grp_types.Multiple,"
"crs_grp.GrpName,"
"crs_grp.MaxStudents,"
"crs_grp.Open,"
"crs_grp.FileZones"
" FROM crs_grp,crs_grp_types"
" WHERE crs_grp.GrpCod=%ld"
" AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod",
GrpDat->GrpCod);
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get data of a group");
if (NumRows == 1)
{
@ -3126,8 +3143,11 @@ static long Grp_GetTypeOfGroupOfAGroup (long GrpCod)
long GrpTypCod;
/***** Get data of a group from database *****/
DB_BuildQuery ("SELECT GrpTypCod FROM crs_grp WHERE GrpCod=%ld",GrpCod);
if (DB_QuerySELECT_new (&mysql_res,"can not get the type of a group") != 1)
if (DB_QuerySELECT (&mysql_res,"can not get the type of a group",
"SELECT GrpTypCod"
" FROM crs_grp"
" WHERE GrpCod=%ld",
GrpCod) != 1)
Lay_ShowErrorAndExit ("Error when getting group.");
/***** Get data of group *****/
@ -3191,34 +3211,20 @@ unsigned Grp_CountNumUsrsInGrp (Rol_Role_t Role,long GrpCod)
/*** Count # of users of current course not belonging to groups of a type ****/
/*****************************************************************************/
static unsigned Grp_CountNumUsrsInNoGrpsOfType (Rol_Role_t Role,long GrpTypCod)
static unsigned long Grp_CountNumUsrsInNoGrpsOfType (Rol_Role_t Role,long GrpTypCod)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumUsrs;
/***** Get number of users not belonging to groups of a type ******/
DB_BuildQuery ("SELECT COUNT(UsrCod) FROM crs_usr"
return DB_QueryCOUNT ("can not get the number of users"
" not belonging to groups of a type",
"SELECT COUNT(UsrCod) FROM crs_usr"
" WHERE CrsCod=%ld AND Role=%u"
" AND UsrCod NOT IN"
" (SELECT DISTINCT crs_grp_usr.UsrCod"
" FROM crs_grp,crs_grp_usr"
" WHERE crs_grp.GrpTypCod=%ld"
" AND crs_grp.GrpCod=crs_grp_usr.GrpCod)",
Gbl.CurrentCrs.Crs.CrsCod,(unsigned) Role,GrpTypCod);
DB_QuerySELECT_new (&mysql_res,"can not get the number of users"
" not belonging to groups of a type");
/***** Get the number of users (row[0]) *****/
row = mysql_fetch_row (mysql_res);
if (sscanf (row[0],"%u",&NumUsrs) != 1)
Lay_ShowErrorAndExit ("Error when getting the number of users"
" not belonging to groups of a type.");
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NumUsrs;
Gbl.CurrentCrs.Crs.CrsCod,
(unsigned) Role,GrpTypCod);
}
/*****************************************************************************/
@ -3234,12 +3240,12 @@ static long Grp_GetFirstCodGrpIBelongTo (long GrpTypCod)
long CodGrpIBelong;
/***** Get a group which I belong to from database *****/
DB_BuildQuery ("SELECT crs_grp.GrpCod FROM crs_grp,crs_grp_usr"
NumRows = DB_QuerySELECT (&mysql_res,"can not check if you belong to a group",
"SELECT crs_grp.GrpCod FROM crs_grp,crs_grp_usr"
" WHERE crs_grp.GrpTypCod=%ld"
" AND crs_grp.GrpCod=crs_grp_usr.GrpCod"
" AND crs_grp_usr.UsrCod=%ld",
GrpTypCod,Gbl.Usrs.Me.UsrDat.UsrCod);
NumRows = DB_QuerySELECT_new (&mysql_res,"can not check if you belong to a group");
/***** Get the group *****/
if (NumRows == 0)
@ -3485,12 +3491,18 @@ static void Grp_GetLstCodGrpsUsrBelongs (long CrsCod,long GrpTypCod,
/***** Get groups which a user belong to from database *****/
if (CrsCod < 0) // Query the groups from all the user's courses
DB_BuildQuery ("SELECT GrpCod"
LstGrps->NumGrps =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get the groups"
" which a user belongs to",
"SELECT GrpCod"
" FROM crs_grp_usr"
" WHERE UsrCod=%ld", // Groups will be unordered
UsrCod);
else if (GrpTypCod < 0) // Query the groups of any type in the course
DB_BuildQuery ("SELECT crs_grp.GrpCod"
LstGrps->NumGrps =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get the groups"
" which a user belongs to",
"SELECT crs_grp.GrpCod"
" FROM crs_grp_types,crs_grp,crs_grp_usr"
" WHERE crs_grp_types.CrsCod=%ld"
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
@ -3499,7 +3511,10 @@ static void Grp_GetLstCodGrpsUsrBelongs (long CrsCod,long GrpTypCod,
" ORDER BY crs_grp_types.GrpTypName,crs_grp.GrpName",
Gbl.CurrentCrs.Crs.CrsCod,UsrCod);
else // Query only the groups of specified type in the course
DB_BuildQuery ("SELECT crs_grp.GrpCod"
LstGrps->NumGrps =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get the groups"
" which a user belongs to",
"SELECT crs_grp.GrpCod"
" FROM crs_grp_types,crs_grp,crs_grp_usr"
" WHERE crs_grp_types.CrsCod=%ld"
" AND crs_grp_types.GrpTypCod=%ld"
@ -3508,8 +3523,6 @@ static void Grp_GetLstCodGrpsUsrBelongs (long CrsCod,long GrpTypCod,
" AND crs_grp_usr.UsrCod=%ld"
" ORDER BY crs_grp.GrpName",
Gbl.CurrentCrs.Crs.CrsCod,GrpTypCod,UsrCod);
LstGrps->NumGrps = (unsigned) DB_QuerySELECT_new (&mysql_res,
"can not get the groups which a user belongs to");
/***** Get the groups *****/
if (LstGrps->NumGrps)
@ -3544,7 +3557,10 @@ void Grp_GetLstCodGrpsWithFileZonesIBelong (struct ListCodGrps *LstGrps)
unsigned NumGrp;
/***** Get groups which I belong to from database *****/
DB_BuildQuery ("SELECT crs_grp.GrpCod"
LstGrps->NumGrps =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get the groups"
" which you belong to",
"SELECT crs_grp.GrpCod"
" FROM crs_grp_types,crs_grp,crs_grp_usr"
" WHERE crs_grp_types.CrsCod=%ld"
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
@ -3553,7 +3569,6 @@ void Grp_GetLstCodGrpsWithFileZonesIBelong (struct ListCodGrps *LstGrps)
" AND crs_grp_usr.UsrCod=%ld"
" ORDER BY crs_grp_types.GrpTypName,crs_grp.GrpName",
Gbl.CurrentCrs.Crs.CrsCod,Gbl.Usrs.Me.UsrDat.UsrCod);
LstGrps->NumGrps = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get the groups which I belong to");
/***** Get the groups *****/
if (LstGrps->NumGrps)
@ -3603,16 +3618,19 @@ void Grp_GetNamesGrpsStdBelongsTo (long GrpTypCod,long UsrCod,char *GroupNames)
MYSQL_ROW row;
unsigned long NumRow;
unsigned long NumRows;
size_t MaxLength = (Grp_MAX_BYTES_GROUP_NAME + 2) * Gbl.CurrentCrs.Grps.GrpTypes.NumGrpsTotal;
size_t MaxLength = (Grp_MAX_BYTES_GROUP_NAME + 2) *
Gbl.CurrentCrs.Grps.GrpTypes.NumGrpsTotal;
/***** Get the names of groups which a user belongs to, from database *****/
DB_BuildQuery ("SELECT crs_grp.GrpName FROM crs_grp,crs_grp_usr"
NumRows = DB_QuerySELECT (&mysql_res,"can not get the names of groups"
" a user belongs to",
"SELECT crs_grp.GrpName"
" FROM crs_grp,crs_grp_usr"
" WHERE crs_grp.GrpTypCod=%ld"
" AND crs_grp.GrpCod=crs_grp_usr.GrpCod"
" AND crs_grp_usr.UsrCod=%ld"
" ORDER BY crs_grp.GrpName",
GrpTypCod,UsrCod);
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get the names of groups a user belongs to");
/***** Get the groups *****/
GroupNames[0] = '\0';