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 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 CSS_FILE "swad18.4.css"
#define JS_FILE "swad17.17.1.js" #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.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.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) 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 ********************/ /**************** 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) unsigned long DB_QueryCOUNT_new (const char *MsgError)
{ {
return DB_QueryCOUNT_old (&Gbl.DB.QueryPtr,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_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_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_new (const char *MsgError);
unsigned long DB_QueryCOUNT_old (char **Query,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]; char OrderBySubQuery[256];
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows; unsigned long NumRows = 0; // Initialized to avoid warning
unsigned NumGame; unsigned NumGame;
unsigned ScopesAllowed = 0; unsigned ScopesAllowed = 0;
unsigned HiddenAllowed = 0; unsigned HiddenAllowed = 0;
@ -975,23 +975,22 @@ void Gam_GetListGames (void)
break; break;
} }
DB_BuildQuery ("SELECT GamCod FROM games" /* Make query */
" WHERE %s%s%s%s%s%s" NumRows = DB_QuerySELECT (&mysql_res,"can not get games",
" ORDER BY %s", "SELECT GamCod FROM games"
SubQuery[Sco_SCOPE_SYS], " WHERE %s%s%s%s%s%s"
SubQuery[Sco_SCOPE_CTY], " ORDER BY %s",
SubQuery[Sco_SCOPE_INS], SubQuery[Sco_SCOPE_SYS],
SubQuery[Sco_SCOPE_CTR], SubQuery[Sco_SCOPE_CTY],
SubQuery[Sco_SCOPE_DEG], SubQuery[Sco_SCOPE_INS],
SubQuery[Sco_SCOPE_CRS], SubQuery[Sco_SCOPE_CTR],
OrderBySubQuery); SubQuery[Sco_SCOPE_DEG],
SubQuery[Sco_SCOPE_CRS],
OrderBySubQuery);
} }
else else
Lay_ShowErrorAndExit ("Can not get list of games."); Lay_ShowErrorAndExit ("Can not get list of games.");
/* Make query */
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get games");
if (NumRows) // Games found... if (NumRows) // Games found...
{ {
Gbl.Games.Num = (unsigned) NumRows; Gbl.Games.Num = (unsigned) NumRows;
@ -1197,19 +1196,16 @@ void Gam_GetDataOfGameByCod (struct Game *Game)
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows; unsigned long NumRows;
/***** Build query *****/
DB_BuildQuery ("SELECT GamCod,Scope,Cod,Hidden,Roles,UsrCod,"
"UNIX_TIMESTAMP(StartTime),"
"UNIX_TIMESTAMP(EndTime),"
"NOW() BETWEEN StartTime AND EndTime,"
"Title"
" FROM games"
" WHERE GamCod=%ld",
Game->GamCod);
/***** Get data of game from database *****/ /***** Get data of game from database *****/
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get game data"); 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,"
"Title"
" FROM games"
" WHERE GamCod=%ld",
Game->GamCod);
if (NumRows) // Game found... if (NumRows) // Game found...
{ {
/* Get row */ /* Get row */
@ -1299,71 +1295,71 @@ void Gam_GetDataOfGameByCod (struct Game *Game)
{ {
case Rol_STD: case Rol_STD:
Game->Status.ICanViewResults = (Game->Scope == Sco_SCOPE_CRS || Game->Status.ICanViewResults = (Game->Scope == Sco_SCOPE_CRS ||
Game->Scope == Sco_SCOPE_DEG || Game->Scope == Sco_SCOPE_DEG ||
Game->Scope == Sco_SCOPE_CTR || Game->Scope == Sco_SCOPE_CTR ||
Game->Scope == Sco_SCOPE_INS || Game->Scope == Sco_SCOPE_INS ||
Game->Scope == Sco_SCOPE_CTY || Game->Scope == Sco_SCOPE_CTY ||
Game->Scope == Sco_SCOPE_SYS) && Game->Scope == Sco_SCOPE_SYS) &&
(Game->NumQsts != 0) && (Game->NumQsts != 0) &&
Game->Status.Visible && Game->Status.Visible &&
Game->Status.Open && Game->Status.Open &&
Game->Status.IAmLoggedWithAValidRoleToAnswer && Game->Status.IAmLoggedWithAValidRoleToAnswer &&
Game->Status.IBelongToScope && Game->Status.IBelongToScope &&
Game->Status.IHaveAnswered; Game->Status.IHaveAnswered;
Game->Status.ICanEdit = false; Game->Status.ICanEdit = false;
break; break;
case Rol_NET: case Rol_NET:
Game->Status.ICanViewResults = (Game->Scope == Sco_SCOPE_CRS || Game->Status.ICanViewResults = (Game->Scope == Sco_SCOPE_CRS ||
Game->Scope == Sco_SCOPE_DEG || Game->Scope == Sco_SCOPE_DEG ||
Game->Scope == Sco_SCOPE_CTR || Game->Scope == Sco_SCOPE_CTR ||
Game->Scope == Sco_SCOPE_INS || Game->Scope == Sco_SCOPE_INS ||
Game->Scope == Sco_SCOPE_CTY || Game->Scope == Sco_SCOPE_CTY ||
Game->Scope == Sco_SCOPE_SYS) && Game->Scope == Sco_SCOPE_SYS) &&
Game->NumQsts != 0 && Game->NumQsts != 0 &&
!Game->Status.ICanAnswer; !Game->Status.ICanAnswer;
Game->Status.ICanEdit = false; Game->Status.ICanEdit = false;
break; break;
case Rol_TCH: case Rol_TCH:
Game->Status.ICanViewResults = (Game->Scope == Sco_SCOPE_CRS || Game->Status.ICanViewResults = (Game->Scope == Sco_SCOPE_CRS ||
Game->Scope == Sco_SCOPE_DEG || Game->Scope == Sco_SCOPE_DEG ||
Game->Scope == Sco_SCOPE_CTR || Game->Scope == Sco_SCOPE_CTR ||
Game->Scope == Sco_SCOPE_INS || Game->Scope == Sco_SCOPE_INS ||
Game->Scope == Sco_SCOPE_CTY || Game->Scope == Sco_SCOPE_CTY ||
Game->Scope == Sco_SCOPE_SYS) && Game->Scope == Sco_SCOPE_SYS) &&
Game->NumQsts != 0 && Game->NumQsts != 0 &&
!Game->Status.ICanAnswer; !Game->Status.ICanAnswer;
Game->Status.ICanEdit = Game->Scope == Sco_SCOPE_CRS && Game->Status.ICanEdit = Game->Scope == Sco_SCOPE_CRS &&
Game->Status.IBelongToScope; Game->Status.IBelongToScope;
break; break;
case Rol_DEG_ADM: case Rol_DEG_ADM:
Game->Status.ICanViewResults = (Game->Scope == Sco_SCOPE_DEG || Game->Status.ICanViewResults = (Game->Scope == Sco_SCOPE_DEG ||
Game->Scope == Sco_SCOPE_CTR || Game->Scope == Sco_SCOPE_CTR ||
Game->Scope == Sco_SCOPE_INS || Game->Scope == Sco_SCOPE_INS ||
Game->Scope == Sco_SCOPE_CTY || Game->Scope == Sco_SCOPE_CTY ||
Game->Scope == Sco_SCOPE_SYS) && Game->Scope == Sco_SCOPE_SYS) &&
(Game->NumQsts != 0) && (Game->NumQsts != 0) &&
!Game->Status.ICanAnswer; !Game->Status.ICanAnswer;
Game->Status.ICanEdit = Game->Scope == Sco_SCOPE_DEG && Game->Status.ICanEdit = Game->Scope == Sco_SCOPE_DEG &&
Game->Status.IBelongToScope; Game->Status.IBelongToScope;
break; break;
case Rol_CTR_ADM: case Rol_CTR_ADM:
Game->Status.ICanViewResults = (Game->Scope == Sco_SCOPE_CTR || Game->Status.ICanViewResults = (Game->Scope == Sco_SCOPE_CTR ||
Game->Scope == Sco_SCOPE_INS || Game->Scope == Sco_SCOPE_INS ||
Game->Scope == Sco_SCOPE_CTY || Game->Scope == Sco_SCOPE_CTY ||
Game->Scope == Sco_SCOPE_SYS) && Game->Scope == Sco_SCOPE_SYS) &&
(Game->NumQsts != 0) && (Game->NumQsts != 0) &&
!Game->Status.ICanAnswer; !Game->Status.ICanAnswer;
Game->Status.ICanEdit = Game->Scope == Sco_SCOPE_CTR && Game->Status.ICanEdit = Game->Scope == Sco_SCOPE_CTR &&
Game->Status.IBelongToScope; Game->Status.IBelongToScope;
break; break;
case Rol_INS_ADM: case Rol_INS_ADM:
Game->Status.ICanViewResults = (Game->Scope == Sco_SCOPE_INS || Game->Status.ICanViewResults = (Game->Scope == Sco_SCOPE_INS ||
Game->Scope == Sco_SCOPE_CTY || Game->Scope == Sco_SCOPE_CTY ||
Game->Scope == Sco_SCOPE_SYS) && Game->Scope == Sco_SCOPE_SYS) &&
(Game->NumQsts != 0) && (Game->NumQsts != 0) &&
!Game->Status.ICanAnswer; !Game->Status.ICanAnswer;
Game->Status.ICanEdit = Game->Scope == Sco_SCOPE_INS && Game->Status.ICanEdit = Game->Scope == Sco_SCOPE_INS &&
Game->Status.IBelongToScope; Game->Status.IBelongToScope;
break; break;
case Rol_SYS_ADM: case Rol_SYS_ADM:
Game->Status.ICanViewResults = (Game->NumQsts != 0); Game->Status.ICanViewResults = (Game->NumQsts != 0);
@ -1428,8 +1424,9 @@ static void Gam_GetGameTxtFromDB (long GamCod,char Txt[Cns_MAX_BYTES_TEXT + 1])
unsigned long NumRows; unsigned long NumRows;
/***** Get text of game from database *****/ /***** Get text of game from database *****/
DB_BuildQuery ("SELECT Txt FROM games WHERE GamCod=%ld",GamCod); NumRows = DB_QuerySELECT (&mysql_res,"can not get game text",
NumRows = DB_QuerySELECT_new (&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 *****/ /***** The result of the query must have one row or none *****/
if (NumRows == 1) if (NumRows == 1)
@ -2343,14 +2340,14 @@ static void Gam_GetAndWriteNamesOfGrpsAssociatedToGame (struct Game *Game)
unsigned long NumRows; unsigned long NumRows;
/***** Get groups associated to a game from database *****/ /***** 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",
" FROM gam_grp,crs_grp,crs_grp_types" "SELECT crs_grp_types.GrpTypName,crs_grp.GrpName"
" WHERE gam_grp.GamCod=%ld" " FROM gam_grp,crs_grp,crs_grp_types"
" AND gam_grp.GrpCod=crs_grp.GrpCod" " WHERE gam_grp.GamCod=%ld"
" AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod" " AND gam_grp.GrpCod=crs_grp.GrpCod"
" ORDER BY crs_grp_types.GrpTypName,crs_grp.GrpName", " AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod"
Game->GamCod); " ORDER BY crs_grp_types.GrpTypName,crs_grp.GrpName",
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get groups of a game"); Game->GamCod);
/***** Write heading *****/ /***** Write heading *****/
fprintf (Gbl.F.Out,"<div class=\"%s\">%s: ", fprintf (Gbl.F.Out,"<div class=\"%s\">%s: ",
@ -2564,10 +2561,10 @@ static int Gam_GetQstIndFromQstCod (long GamCod,long QstCod)
int QstInd = -1; int QstInd = -1;
/***** Get number of games with a field value from database *****/ /***** 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",
" WHERE GamCod=%ld AND QstCod=%ld", "SELECT QstInd FROM gam_questions"
GamCod,QstCod); " WHERE GamCod=%ld AND QstCod=%ld",
if (!DB_QuerySELECT_new (&mysql_res,"can not get question index")) GamCod,QstCod))
Lay_ShowErrorAndExit ("Error when getting question index."); Lay_ShowErrorAndExit ("Error when getting question index.");
/***** Get question index (row[0]) *****/ /***** Get question index (row[0]) *****/
@ -2593,10 +2590,10 @@ static long Gam_GetQstCodFromQstInd (long GamCod,unsigned QstInd)
long QstCod; long QstCod;
/***** Get question code of thw question to be moved up *****/ /***** 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",
" WHERE GamCod=%ld AND QstInd=%u", "SELECT QstCod FROM gam_questions"
GamCod,QstInd); " WHERE GamCod=%ld AND QstInd=%u",
if (!DB_QuerySELECT_new (&mysql_res,"can not get question code")) GamCod,QstInd))
Lay_ShowErrorAndExit ("Error: wrong question code."); Lay_ShowErrorAndExit ("Error: wrong question code.");
/***** Get question code (row[0]) *****/ /***** Get question code (row[0]) *****/
@ -2623,9 +2620,9 @@ static int Gam_GetMaxQuestionIndexInGame (long GamCod)
int QstInd = -1; int QstInd = -1;
/***** Get maximum question index in a game from database *****/ /***** 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",
GamCod); "SELECT MAX(QstInd) FROM gam_questions WHERE GamCod=%ld",
DB_QuerySELECT_new (&mysql_res,"can not get last question index"); GamCod);
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
if (row[0]) // There are questions if (row[0]) // There are questions
if (sscanf (row[0],"%d",&QstInd) != 1) 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 *****/ /***** Get previous question index in a game from database *****/
// Although indexes are always continuous... // Although indexes are always continuous...
// ...this implementation works even with non continuous indexes // ...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",
" WHERE GamCod=%ld AND QstInd<%u", "SELECT MAX(QstInd) FROM gam_questions"
GamCod,QstInd); " WHERE GamCod=%ld AND QstInd<%u",
if (!DB_QuerySELECT_new (&mysql_res,"can not get previous question index")) GamCod,QstInd))
Lay_ShowErrorAndExit ("Error: previous question index not found."); Lay_ShowErrorAndExit ("Error: previous question index not found.");
/***** Get previous question index (row[0]) *****/ /***** 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 *****/ /***** Get next question index in a game from database *****/
// Although indexes are always continuous... // Although indexes are always continuous...
// ...this implementation works even with non continuous indexes // ...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",
" WHERE GamCod=%ld AND QstInd>%u", "SELECT MIN(QstInd) FROM gam_questions"
GamCod,QstInd); " WHERE GamCod=%ld AND QstInd>%u",
if (!DB_QuerySELECT_new (&mysql_res,"can not get next question index")) GamCod,QstInd))
Lay_ShowErrorAndExit ("Error: next question index not found."); Lay_ShowErrorAndExit ("Error: next question index not found.");
/***** Get next question index (row[0]) *****/ /***** Get next question index (row[0]) *****/
@ -2735,19 +2732,19 @@ static void Gam_ListGameQuestions (struct Game *Game)
row[5] ImageTitle row[5] ImageTitle
row[6] ImageURL row[6] ImageURL
*/ */
DB_BuildQuery ("SELECT tst_questions.QstCod," NumQsts = (unsigned) DB_QuerySELECT (&mysql_res,"can not get data of a question",
"tst_questions.AnsType," "SELECT tst_questions.QstCod,"
"tst_questions.Stem," "tst_questions.AnsType,"
"tst_questions.Feedback," "tst_questions.Stem,"
"tst_questions.ImageName," "tst_questions.Feedback,"
"tst_questions.ImageTitle," "tst_questions.ImageName,"
"tst_questions.ImageURL" "tst_questions.ImageTitle,"
" FROM gam_questions,tst_questions" "tst_questions.ImageURL"
" WHERE gam_questions.GamCod=%ld" " FROM gam_questions,tst_questions"
" AND gam_questions.QstCod=tst_questions.QstCod" " WHERE gam_questions.GamCod=%ld"
" ORDER BY gam_questions.QstInd", " AND gam_questions.QstCod=tst_questions.QstCod"
Game->GamCod); " ORDER BY gam_questions.QstInd",
NumQsts = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get data of a question"); Game->GamCod);
/***** Start box *****/ /***** Start box *****/
Gbl.Games.CurrentGamCod = Game->GamCod; 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 unsigned NumUsrs = 0; // Default returned value
/***** Get answers of a question from database *****/ /***** 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",
" WHERE GamCod=%ld AND QstCod=%ld AND AnsInd=%u", "SELECT NumUsrs FROM gam_answers"
GamCod,QstCod,AnsInd); " WHERE GamCod=%ld AND QstCod=%ld AND AnsInd=%u",
if (DB_QuerySELECT_new (&mysql_res,"can not get number of users who answered")) GamCod,QstCod,AnsInd))
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
if (row[0]) // There are users who selected this answer if (row[0]) // There are users who selected this answer
@ -3543,19 +3540,19 @@ static void Gam_PlayGameShowQuestionAndAnswers (bool ShowAnswers)
row[4] ImageTitle row[4] ImageTitle
row[5] ImageURL row[5] ImageURL
*/ */
DB_BuildQuery ("SELECT " if (!DB_QuerySELECT (&mysql_res,"can not get data of a question",
"tst_questions.QstCod," "SELECT "
"tst_questions.AnsType," "tst_questions.QstCod,"
"tst_questions.Stem," "tst_questions.AnsType,"
"tst_questions.ImageName," "tst_questions.Stem,"
"tst_questions.ImageTitle," "tst_questions.ImageName,"
"tst_questions.ImageURL" "tst_questions.ImageTitle,"
" FROM gam_questions,tst_questions" "tst_questions.ImageURL"
" WHERE gam_questions.GamCod=%ld" " FROM gam_questions,tst_questions"
" AND gam_questions.QstInd=%u" " WHERE gam_questions.GamCod=%ld"
" AND gam_questions.QstCod=tst_questions.QstCod", " AND gam_questions.QstInd=%u"
Game.GamCod,QstInd); " AND gam_questions.QstCod=tst_questions.QstCod",
if (!DB_QuerySELECT_new (&mysql_res,"can not get data of a question")) Game.GamCod,QstInd))
Ale_ShowAlert (Ale_WARNING,"Questions doesn't exist."); Ale_ShowAlert (Ale_WARNING,"Questions doesn't exist.");
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -3700,10 +3697,11 @@ static void Gam_ReceiveAndStoreUserAnswersToAGame (long GamCod)
unsigned AnsInd; unsigned AnsInd;
/***** Get questions of this game from database *****/ /***** 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",
" WHERE GamCod=%ld ORDER BY QstCod", "SELECT QstCod FROM gam_questions"
GamCod); " WHERE GamCod=%ld ORDER BY QstCod",
if ((NumQsts = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get questions of a game"))) // The game has questions GamCod);
if (NumQsts) // The game has questions
{ {
/***** Get questions *****/ /***** Get questions *****/
for (NumQst = 0; for (NumQst = 0;
@ -3812,65 +3810,69 @@ unsigned Gam_GetNumCoursesWithGames (Sco_Scope_t Scope)
switch (Scope) switch (Scope)
{ {
case Sco_SCOPE_SYS: case Sco_SCOPE_SYS:
DB_BuildQuery ("SELECT COUNT(DISTINCT Cod)" DB_QuerySELECT (&mysql_res,"can not get number of courses with games",
" FROM games" "SELECT COUNT(DISTINCT Cod)"
" WHERE Scope='%s'", " FROM games"
Sco_ScopeDB[Sco_SCOPE_CRS]); " WHERE Scope='%s'",
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CTY: case Sco_SCOPE_CTY:
DB_BuildQuery ("SELECT COUNT(DISTINCT games.Cod)" DB_QuerySELECT (&mysql_res,"can not get number of courses with games",
" FROM institutions,centres,degrees,courses,games" "SELECT COUNT(DISTINCT games.Cod)"
" WHERE institutions.CtyCod=%ld" " FROM institutions,centres,degrees,courses,games"
" AND institutions.InsCod=centres.InsCod" " WHERE institutions.CtyCod=%ld"
" AND centres.CtrCod=degrees.CtrCod" " AND institutions.InsCod=centres.InsCod"
" AND degrees.DegCod=courses.DegCod" " AND centres.CtrCod=degrees.CtrCod"
" AND courses.CrsCod=games.Cod" " AND degrees.DegCod=courses.DegCod"
" AND games.Scope='%s'", " AND courses.CrsCod=games.Cod"
Gbl.CurrentIns.Ins.InsCod, " AND games.Scope='%s'",
Sco_ScopeDB[Sco_SCOPE_CRS]); Gbl.CurrentIns.Ins.InsCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
DB_BuildQuery ("SELECT COUNT(DISTINCT games.Cod)" DB_QuerySELECT (&mysql_res,"can not get number of courses with games",
" FROM centres,degrees,courses,games" "SELECT COUNT(DISTINCT games.Cod)"
" WHERE centres.InsCod=%ld" " FROM centres,degrees,courses,games"
" AND centres.CtrCod=degrees.CtrCod" " WHERE centres.InsCod=%ld"
" AND degrees.DegCod=courses.DegCod" " AND centres.CtrCod=degrees.CtrCod"
" AND courses.CrsCod=games.Cod" " AND degrees.DegCod=courses.DegCod"
" AND games.Scope='%s'", " AND courses.CrsCod=games.Cod"
Gbl.CurrentIns.Ins.InsCod, " AND games.Scope='%s'",
Sco_ScopeDB[Sco_SCOPE_CRS]); Gbl.CurrentIns.Ins.InsCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CTR: 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" " FROM degrees,courses,games"
" WHERE degrees.CtrCod=%ld" " WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod" " AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=games.Cod" " AND courses.CrsCod=games.Cod"
" AND games.Scope='%s'", " AND games.Scope='%s'",
Gbl.CurrentCtr.Ctr.CtrCod, Gbl.CurrentCtr.Ctr.CtrCod,
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
DB_BuildQuery ("SELECT COUNT(DISTINCT games.Cod)" DB_QuerySELECT (&mysql_res,"can not get number of courses with games",
" FROM courses,games" "SELECT COUNT(DISTINCT games.Cod)"
" WHERE courses.DegCod=%ld" " FROM courses,games"
" AND courses.CrsCod=games.Cod" " WHERE courses.DegCod=%ld"
" AND games.Scope='%s'", " AND courses.CrsCod=games.Cod"
Gbl.CurrentDeg.Deg.DegCod, " AND games.Scope='%s'",
Sco_ScopeDB[Sco_SCOPE_CRS]); Gbl.CurrentDeg.Deg.DegCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
DB_BuildQuery ("SELECT COUNT(DISTINCT Cod)" DB_QuerySELECT (&mysql_res,"can not get number of courses with games",
" FROM games" "SELECT COUNT(DISTINCT Cod)"
" WHERE Scope='%s' AND Cod=%ld", " FROM games"
Sco_ScopeDB[Sco_SCOPE_CRS], " WHERE Scope='%s' AND Cod=%ld",
Gbl.CurrentCrs.Crs.CrsCod); Sco_ScopeDB[Sco_SCOPE_CRS],
Gbl.CurrentCrs.Crs.CrsCod);
break; break;
default: default:
Lay_WrongScopeExit (); Lay_WrongScopeExit ();
break; break;
} }
DB_QuerySELECT_new (&mysql_res,"can not get number of courses with games");
/***** Get number of games *****/ /***** Get number of games *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -3899,66 +3901,71 @@ unsigned Gam_GetNumGames (Sco_Scope_t Scope)
switch (Scope) switch (Scope)
{ {
case Sco_SCOPE_SYS: case Sco_SCOPE_SYS:
DB_BuildQuery ("SELECT COUNT(*)" DB_QuerySELECT (&mysql_res,"can not get number of games",
" FROM games" "SELECT COUNT(*)"
" WHERE Scope='%s'", " FROM games"
Sco_ScopeDB[Sco_SCOPE_CRS]); " WHERE Scope='%s'",
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CTY: case Sco_SCOPE_CTY:
DB_BuildQuery ("SELECT COUNT(*)" DB_QuerySELECT (&mysql_res,"can not get number of games",
" FROM institutions,centres,degrees,courses,games" "SELECT COUNT(*)"
" WHERE institutions.CtyCod=%ld" " FROM institutions,centres,degrees,courses,games"
" AND institutions.InsCod=centres.InsCod" " WHERE institutions.CtyCod=%ld"
" AND centres.CtrCod=degrees.CtrCod" " AND institutions.InsCod=centres.InsCod"
" AND degrees.DegCod=courses.DegCod" " AND centres.CtrCod=degrees.CtrCod"
" AND courses.CrsCod=games.Cod" " AND degrees.DegCod=courses.DegCod"
" AND games.Scope='%s'", " AND courses.CrsCod=games.Cod"
Gbl.CurrentCty.Cty.CtyCod, " AND games.Scope='%s'",
Sco_ScopeDB[Sco_SCOPE_CRS]); Gbl.CurrentCty.Cty.CtyCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
DB_BuildQuery ("SELECT COUNT(*)" DB_QuerySELECT (&mysql_res,"can not get number of games",
" FROM centres,degrees,courses,games" "SELECT COUNT(*)"
" WHERE centres.InsCod=%ld" " FROM centres,degrees,courses,games"
" AND centres.CtrCod=degrees.CtrCod" " WHERE centres.InsCod=%ld"
" AND degrees.DegCod=courses.DegCod" " AND centres.CtrCod=degrees.CtrCod"
" AND courses.CrsCod=games.Cod" " AND degrees.DegCod=courses.DegCod"
" AND games.Scope='%s'", " AND courses.CrsCod=games.Cod"
Gbl.CurrentIns.Ins.InsCod, " AND games.Scope='%s'",
Sco_ScopeDB[Sco_SCOPE_CRS]); Gbl.CurrentIns.Ins.InsCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CTR: case Sco_SCOPE_CTR:
DB_BuildQuery ("SELECT COUNT(*)" DB_QuerySELECT (&mysql_res,"can not get number of games",
" FROM degrees,courses,games" "SELECT COUNT(*)"
" WHERE degrees.CtrCod=%ld" " FROM degrees,courses,games"
" AND degrees.DegCod=courses.DegCod" " WHERE degrees.CtrCod=%ld"
" AND courses.CrsCod=games.Cod" " AND degrees.DegCod=courses.DegCod"
" AND games.Scope='%s'", " AND courses.CrsCod=games.Cod"
Gbl.CurrentCtr.Ctr.CtrCod, " AND games.Scope='%s'",
Sco_ScopeDB[Sco_SCOPE_CRS]); Gbl.CurrentCtr.Ctr.CtrCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
DB_BuildQuery ("SELECT COUNT(*)" DB_QuerySELECT (&mysql_res,"can not get number of games",
" FROM courses,games" "SELECT COUNT(*)"
" WHERE courses.DegCod=%ld" " FROM courses,games"
" AND courses.CrsCod=games.Cod" " WHERE courses.DegCod=%ld"
" AND games.Scope='%s'", " AND courses.CrsCod=games.Cod"
Gbl.CurrentDeg.Deg.DegCod, " AND games.Scope='%s'",
Sco_ScopeDB[Sco_SCOPE_CRS]); Gbl.CurrentDeg.Deg.DegCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
DB_BuildQuery ("SELECT COUNT(*)" DB_QuerySELECT (&mysql_res,"can not get number of games",
" FROM games" "SELECT COUNT(*)"
" WHERE games.Scope='%s'" " FROM games"
" AND CrsCod=%ld", " WHERE games.Scope='%s'"
Sco_ScopeDB[Sco_SCOPE_CRS], " AND CrsCod=%ld",
Gbl.CurrentCrs.Crs.CrsCod); Sco_ScopeDB[Sco_SCOPE_CRS],
Gbl.CurrentCrs.Crs.CrsCod);
break; break;
default: default:
Lay_WrongScopeExit (); Lay_WrongScopeExit ();
break; break;
} }
DB_QuerySELECT_new (&mysql_res,"can not get number of games");
/***** Get number of games *****/ /***** Get number of games *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -3986,82 +3993,87 @@ float Gam_GetNumQstsPerCrsGame (Sco_Scope_t Scope)
switch (Scope) switch (Scope)
{ {
case Sco_SCOPE_SYS: case Sco_SCOPE_SYS:
DB_BuildQuery ("SELECT AVG(NumQsts) FROM" DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts" "SELECT AVG(NumQsts) FROM"
" FROM games,gam_questions" " (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
" WHERE games.Scope='%s'" " FROM games,gam_questions"
" AND games.GamCod=gam_questions.GamCod" " WHERE games.Scope='%s'"
" GROUP BY gam_questions.GamCod) AS NumQstsTable", " AND games.GamCod=gam_questions.GamCod"
Sco_ScopeDB[Sco_SCOPE_CRS]); " GROUP BY gam_questions.GamCod) AS NumQstsTable",
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CTY: case Sco_SCOPE_CTY:
DB_BuildQuery ("SELECT AVG(NumQsts) FROM" DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts" "SELECT AVG(NumQsts) FROM"
" FROM institutions,centres,degrees,courses,games,gam_questions" " (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
" WHERE institutions.CtyCod=%ld" " FROM institutions,centres,degrees,courses,games,gam_questions"
" AND institutions.InsCod=centres.InsCod" " WHERE institutions.CtyCod=%ld"
" AND centres.CtrCod=degrees.CtrCod" " AND institutions.InsCod=centres.InsCod"
" AND degrees.DegCod=courses.DegCod" " AND centres.CtrCod=degrees.CtrCod"
" AND courses.CrsCod=games.Cod" " AND degrees.DegCod=courses.DegCod"
" AND games.Scope='%s'" " AND courses.CrsCod=games.Cod"
" AND games.GamCod=gam_questions.GamCod" " AND games.Scope='%s'"
" GROUP BY gam_questions.GamCod) AS NumQstsTable", " AND games.GamCod=gam_questions.GamCod"
Gbl.CurrentCty.Cty.CtyCod, " GROUP BY gam_questions.GamCod) AS NumQstsTable",
Sco_ScopeDB[Sco_SCOPE_CRS]); Gbl.CurrentCty.Cty.CtyCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
DB_BuildQuery ("SELECT AVG(NumQsts) FROM" DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts" "SELECT AVG(NumQsts) FROM"
" FROM centres,degrees,courses,games,gam_questions" " (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
" WHERE centres.InsCod=%ld" " FROM centres,degrees,courses,games,gam_questions"
" AND centres.CtrCod=degrees.CtrCod" " WHERE centres.InsCod=%ld"
" AND degrees.DegCod=courses.DegCod" " AND centres.CtrCod=degrees.CtrCod"
" AND courses.CrsCod=games.Cod" " AND degrees.DegCod=courses.DegCod"
" AND games.Scope='%s'" " AND courses.CrsCod=games.Cod"
" AND games.GamCod=gam_questions.GamCod" " AND games.Scope='%s'"
" GROUP BY gam_questions.GamCod) AS NumQstsTable", " AND games.GamCod=gam_questions.GamCod"
Gbl.CurrentIns.Ins.InsCod, " GROUP BY gam_questions.GamCod) AS NumQstsTable",
Sco_ScopeDB[Sco_SCOPE_CRS]); Gbl.CurrentIns.Ins.InsCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CTR: case Sco_SCOPE_CTR:
DB_BuildQuery ("SELECT AVG(NumQsts) FROM" DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts" "SELECT AVG(NumQsts) FROM"
" FROM degrees,courses,games,gam_questions" " (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
" WHERE degrees.CtrCod=%ld" " FROM degrees,courses,games,gam_questions"
" AND degrees.DegCod=courses.DegCod" " WHERE degrees.CtrCod=%ld"
" AND courses.CrsCod=games.Cod" " AND degrees.DegCod=courses.DegCod"
" AND games.Scope='%s'" " AND courses.CrsCod=games.Cod"
" AND games.GamCod=gam_questions.GamCod" " AND games.Scope='%s'"
" GROUP BY gam_questions.GamCod) AS NumQstsTable", " AND games.GamCod=gam_questions.GamCod"
Gbl.CurrentCtr.Ctr.CtrCod, " GROUP BY gam_questions.GamCod) AS NumQstsTable",
Sco_ScopeDB[Sco_SCOPE_CRS]); Gbl.CurrentCtr.Ctr.CtrCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
DB_BuildQuery ("SELECT AVG(NumQsts) FROM" DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts" "SELECT AVG(NumQsts) FROM"
" FROM courses,games,gam_questions" " (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
" WHERE courses.DegCod=%ld" " FROM courses,games,gam_questions"
" AND courses.CrsCod=games.Cod" " WHERE courses.DegCod=%ld"
" AND games.Scope='%s'" " AND courses.CrsCod=games.Cod"
" AND games.GamCod=gam_questions.GamCod" " AND games.Scope='%s'"
" GROUP BY gam_questions.GamCod) AS NumQstsTable", " AND games.GamCod=gam_questions.GamCod"
Gbl.CurrentDeg.Deg.DegCod, " GROUP BY gam_questions.GamCod) AS NumQstsTable",
Sco_ScopeDB[Sco_SCOPE_CRS]); Gbl.CurrentDeg.Deg.DegCod,
Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
DB_BuildQuery ("SELECT AVG(NumQsts) FROM" DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts" "SELECT AVG(NumQsts) FROM"
" FROM games,gam_questions" " (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
" WHERE games.Scope='%s' AND games.Cod=%ld" " FROM games,gam_questions"
" AND games.GamCod=gam_questions.GamCod" " WHERE games.Scope='%s' AND games.Cod=%ld"
" GROUP BY gam_questions.GamCod) AS NumQstsTable", " AND games.GamCod=gam_questions.GamCod"
Sco_ScopeDB[Sco_SCOPE_CRS],Gbl.CurrentCrs.Crs.CrsCod); " GROUP BY gam_questions.GamCod) AS NumQstsTable",
Sco_ScopeDB[Sco_SCOPE_CRS],Gbl.CurrentCrs.Crs.CrsCod);
break; break;
default: default:
Lay_WrongScopeExit (); Lay_WrongScopeExit ();
break; break;
} }
DB_QuerySELECT_new (&mysql_res,"can not get number of questions per game");
/***** Get number of courses *****/ /***** Get number of courses *****/
row = mysql_fetch_row (mysql_res); 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 void Grp_GetDataOfGroupTypeByCod (struct GroupType *GrpTyp);
static bool Grp_GetMultipleEnrolmentOfAGroupType (long GrpTypCod); static bool Grp_GetMultipleEnrolmentOfAGroupType (long GrpTypCod);
static long Grp_GetTypeOfGroupOfAGroup (long GrpCod); 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 long Grp_GetFirstCodGrpIBelongTo (long GrpTypCod);
static bool Grp_GetIfGrpIsAvailable (long GrpTypCod); static bool Grp_GetIfGrpIsAvailable (long GrpTypCod);
static void Grp_GetLstCodGrpsUsrBelongs (long CrsCod,long GrpTypCod,long UsrCod, 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 >= Rol_STD;
Role--) Role--)
fprintf (Gbl.F.Out,"<td class=\"DAT CENTER_MIDDLE\">" fprintf (Gbl.F.Out,"<td class=\"DAT CENTER_MIDDLE\">"
"%u" "%lu"
"</td>", "</td>",
Grp_CountNumUsrsInNoGrpsOfType (Role,GrpTyp->GrpTypCod)); Grp_CountNumUsrsInNoGrpsOfType (Role,GrpTyp->GrpTypCod));
@ -2674,7 +2674,7 @@ void Grp_GetListGrpTypesInThisCrs (Grp_WhichGroupTypes_t WhichGroupTypes)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; 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 if (++Gbl.CurrentCrs.Grps.GrpTypes.NestedCalls > 1) // If list is created yet, there's nothing to do
return; return;
@ -2688,42 +2688,47 @@ void Grp_GetListGrpTypesInThisCrs (Grp_WhichGroupTypes_t WhichGroupTypes)
switch (WhichGroupTypes) switch (WhichGroupTypes)
{ {
case Grp_ONLY_GROUP_TYPES_WITH_GROUPS: case Grp_ONLY_GROUP_TYPES_WITH_GROUPS:
DB_BuildQuery ("SELECT crs_grp_types.GrpTypCod,crs_grp_types.GrpTypName," Gbl.CurrentCrs.Grps.GrpTypes.Num =
"crs_grp_types.Mandatory,crs_grp_types.Multiple," (unsigned) DB_QuerySELECT (&mysql_res,"can not get types of group"
"crs_grp_types.MustBeOpened," " of a course",
"UNIX_TIMESTAMP(crs_grp_types.OpenTime)," "SELECT crs_grp_types.GrpTypCod,crs_grp_types.GrpTypName,"
"COUNT(crs_grp.GrpCod)" "crs_grp_types.Mandatory,crs_grp_types.Multiple,"
" FROM crs_grp_types,crs_grp" "crs_grp_types.MustBeOpened,"
" WHERE crs_grp_types.CrsCod=%ld" "UNIX_TIMESTAMP(crs_grp_types.OpenTime),"
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod" "COUNT(crs_grp.GrpCod)"
" GROUP BY crs_grp_types.GrpTypCod" " FROM crs_grp_types,crs_grp"
" ORDER BY crs_grp_types.GrpTypName", " WHERE crs_grp_types.CrsCod=%ld"
Gbl.CurrentCrs.Crs.CrsCod); " AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
" GROUP BY crs_grp_types.GrpTypCod"
" ORDER BY crs_grp_types.GrpTypName",
Gbl.CurrentCrs.Crs.CrsCod);
break; break;
case Grp_ALL_GROUP_TYPES: case Grp_ALL_GROUP_TYPES:
DB_BuildQuery ("(SELECT crs_grp_types.GrpTypCod,crs_grp_types.GrpTypName AS GrpTypName," Gbl.CurrentCrs.Grps.GrpTypes.Num =
"crs_grp_types.Mandatory,crs_grp_types.Multiple," (unsigned) DB_QuerySELECT (&mysql_res,"can not get types of group"
"crs_grp_types.MustBeOpened," " of a course",
"UNIX_TIMESTAMP(crs_grp_types.OpenTime)," "(SELECT crs_grp_types.GrpTypCod,crs_grp_types.GrpTypName AS GrpTypName,"
"COUNT(crs_grp.GrpCod)" "crs_grp_types.Mandatory,crs_grp_types.Multiple,"
" FROM crs_grp_types,crs_grp" "crs_grp_types.MustBeOpened,"
" WHERE crs_grp_types.CrsCod=%ld" "UNIX_TIMESTAMP(crs_grp_types.OpenTime),"
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod" "COUNT(crs_grp.GrpCod)"
" GROUP BY crs_grp_types.GrpTypCod)" " FROM crs_grp_types,crs_grp"
" UNION " " WHERE crs_grp_types.CrsCod=%ld"
"(SELECT GrpTypCod,GrpTypName," " AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
"Mandatory,Multiple," " GROUP BY crs_grp_types.GrpTypCod)"
"MustBeOpened," " UNION "
"UNIX_TIMESTAMP(OpenTime)," "(SELECT GrpTypCod,GrpTypName,"
"0" "Mandatory,Multiple,"
" FROM crs_grp_types WHERE CrsCod=%ld" "MustBeOpened,"
" AND GrpTypCod NOT IN (SELECT GrpTypCod FROM crs_grp))" "UNIX_TIMESTAMP(OpenTime),"
" ORDER BY GrpTypName", "0"
Gbl.CurrentCrs.Crs.CrsCod, " FROM crs_grp_types WHERE CrsCod=%ld"
Gbl.CurrentCrs.Crs.CrsCod); " AND GrpTypCod NOT IN (SELECT GrpTypCod FROM crs_grp))"
" ORDER BY GrpTypName",
Gbl.CurrentCrs.Crs.CrsCod,
Gbl.CurrentCrs.Crs.CrsCod);
break; break;
} }
Gbl.CurrentCrs.Grps.GrpTypes.Num = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get types of group of a course");
/***** Get group types *****/ /***** Get group types *****/
Gbl.CurrentCrs.Grps.GrpTypes.NumGrpsTotal = 0; Gbl.CurrentCrs.Grps.GrpTypes.NumGrpsTotal = 0;
@ -2735,43 +2740,43 @@ void Grp_GetListGrpTypesInThisCrs (Grp_WhichGroupTypes_t WhichGroupTypes)
Lay_NotEnoughMemoryExit (); Lay_NotEnoughMemoryExit ();
/***** Get group types *****/ /***** Get group types *****/
for (NumRow = 0; for (NumGrpTyp = 0;
NumRow < Gbl.CurrentCrs.Grps.GrpTypes.Num; NumGrpTyp < Gbl.CurrentCrs.Grps.GrpTypes.Num;
NumRow++) NumGrpTyp++)
{ {
/* Get next group type */ /* Get next group type */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
/* Get group type code (row[0]) */ /* 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."); Lay_ShowErrorAndExit ("Wrong type of group.");
/* Get group type name (row[1]) */ /* 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); Grp_MAX_BYTES_GROUP_TYPE_NAME);
/* Is it mandatory to register in any groups of this type? (row[2]) */ /* 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]) */ /* 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]) */ /* 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) */ /* 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[NumGrpTyp].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].MustBeOpened &= Grp_CheckIfOpenTimeInTheFuture (Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].OpenTimeUTC);
/* Number of groups of this type (row[6]) */ /* 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."); Lay_ShowErrorAndExit ("Wrong number of groups of a type.");
/* Add number of groups to total number of groups */ /* 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 */ /* 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; long GrpTypCod;
/***** Find group types to be opened *****/ /***** Find group types to be opened *****/
DB_BuildQuery ("SELECT GrpTypCod FROM crs_grp_types" NumGrpTypes =
" WHERE CrsCod=%ld AND MustBeOpened='Y'" (unsigned) DB_QuerySELECT (&mysql_res,"can not get the types of group"
" AND OpenTime<=NOW()", " to be opened",
Gbl.CurrentCrs.Crs.CrsCod); "SELECT GrpTypCod FROM crs_grp_types"
NumGrpTypes = (unsigned) DB_QuerySELECT_new (&mysql_res, " WHERE CrsCod=%ld AND MustBeOpened='Y'"
"can not get the types of group to be opened"); " AND OpenTime<=NOW()",
Gbl.CurrentCrs.Crs.CrsCod);
for (NumGrpTyp = 0; for (NumGrpTyp = 0;
NumGrpTyp < NumGrpTypes; NumGrpTyp < NumGrpTypes;
NumGrpTyp++) NumGrpTyp++)
@ -2973,12 +2980,12 @@ static unsigned Grp_CountNumGrpsInThisCrsOfType (long GrpTypCod)
unsigned long Grp_GetGrpsOfType (long GrpTypCod,MYSQL_RES **mysql_res) unsigned long Grp_GetGrpsOfType (long GrpTypCod,MYSQL_RES **mysql_res)
{ {
/***** Get groups of a type from database *****/ /***** 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",
" FROM crs_grp" "SELECT GrpCod,GrpName,MaxStudents,Open,FileZones"
" WHERE GrpTypCod=%ld" " FROM crs_grp"
" ORDER BY GrpName", " WHERE GrpTypCod=%ld"
GrpTypCod); " ORDER BY GrpName",
return DB_QuerySELECT_new (mysql_res,"can not get groups of a type"); GrpTypCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2993,11 +3000,15 @@ static void Grp_GetDataOfGroupTypeByCod (struct GroupType *GrpTyp)
unsigned long NumRows; unsigned long NumRows;
/***** Get data of a type of group from database *****/ /***** 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",
" FROM crs_grp_types" "SELECT GrpTypName,"
" WHERE CrsCod=%ld AND GrpTypCod=%ld", "Mandatory,"
Gbl.CurrentCrs.Crs.CrsCod,GrpTyp->GrpTypCod); "Multiple,"
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get type of group"); "MustBeOpened,"
"UNIX_TIMESTAMP(OpenTime)"
" FROM crs_grp_types"
" WHERE CrsCod=%ld AND GrpTypCod=%ld",
Gbl.CurrentCrs.Crs.CrsCod,GrpTyp->GrpTypCod);
/***** Count number of rows in result *****/ /***** Count number of rows in result *****/
if (NumRows != 1) if (NumRows != 1)
@ -3027,9 +3038,11 @@ static bool Grp_GetMultipleEnrolmentOfAGroupType (long GrpTypCod)
bool MultipleEnrolment; bool MultipleEnrolment;
/***** Get data of a type of group from database *****/ /***** Get data of a type of group from database *****/
DB_BuildQuery ("SELECT Multiple FROM crs_grp_types WHERE GrpTypCod=%ld", if (DB_QuerySELECT (&mysql_res,"can not get if type of group"
GrpTypCod); " has multiple enrolment",
if (DB_QuerySELECT_new (&mysql_res,"can not get if type of group has multiple enrolment") != 1) "SELECT Multiple FROM crs_grp_types"
" WHERE GrpTypCod=%ld",
GrpTypCod) != 1)
Lay_ShowErrorAndExit ("Error when getting type of group."); Lay_ShowErrorAndExit ("Error when getting type of group.");
/***** Get multiple enrolment *****/ /***** Get multiple enrolment *****/
@ -3066,15 +3079,19 @@ void Grp_GetDataOfGroupByCod (struct GroupData *GrpDat)
if (GrpDat->GrpCod > 0) if (GrpDat->GrpCod > 0)
{ {
/***** Get data of a group from database *****/ /***** Get data of a group from database *****/
DB_BuildQuery ("SELECT crs_grp_types.GrpTypCod,crs_grp_types.CrsCod," NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a group",
"crs_grp_types.GrpTypName,crs_grp_types.Multiple," "SELECT crs_grp_types.GrpTypCod,"
"crs_grp.GrpName,crs_grp.MaxStudents," "crs_grp_types.CrsCod,"
"crs_grp.Open,crs_grp.FileZones" "crs_grp_types.GrpTypName,"
" FROM crs_grp,crs_grp_types" "crs_grp_types.Multiple,"
" WHERE crs_grp.GrpCod=%ld" "crs_grp.GrpName,"
" AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod", "crs_grp.MaxStudents,"
GrpDat->GrpCod); "crs_grp.Open,"
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get data of a group"); "crs_grp.FileZones"
" FROM crs_grp,crs_grp_types"
" WHERE crs_grp.GrpCod=%ld"
" AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod",
GrpDat->GrpCod);
if (NumRows == 1) if (NumRows == 1)
{ {
@ -3126,8 +3143,11 @@ static long Grp_GetTypeOfGroupOfAGroup (long GrpCod)
long GrpTypCod; long GrpTypCod;
/***** Get data of a group from database *****/ /***** Get data of a group from database *****/
DB_BuildQuery ("SELECT GrpTypCod FROM crs_grp WHERE GrpCod=%ld",GrpCod); if (DB_QuerySELECT (&mysql_res,"can not get the type of a group",
if (DB_QuerySELECT_new (&mysql_res,"can not get the type of a group") != 1) "SELECT GrpTypCod"
" FROM crs_grp"
" WHERE GrpCod=%ld",
GrpCod) != 1)
Lay_ShowErrorAndExit ("Error when getting group."); Lay_ShowErrorAndExit ("Error when getting group.");
/***** Get data of 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 ****/ /*** 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 ******/ /***** 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"
" WHERE CrsCod=%ld AND Role=%u" " not belonging to groups of a type",
" AND UsrCod NOT IN" "SELECT COUNT(UsrCod) FROM crs_usr"
" (SELECT DISTINCT crs_grp_usr.UsrCod" " WHERE CrsCod=%ld AND Role=%u"
" FROM crs_grp,crs_grp_usr" " AND UsrCod NOT IN"
" WHERE crs_grp.GrpTypCod=%ld" " (SELECT DISTINCT crs_grp_usr.UsrCod"
" AND crs_grp.GrpCod=crs_grp_usr.GrpCod)", " FROM crs_grp,crs_grp_usr"
Gbl.CurrentCrs.Crs.CrsCod,(unsigned) Role,GrpTypCod); " WHERE crs_grp.GrpTypCod=%ld"
DB_QuerySELECT_new (&mysql_res,"can not get the number of users" " AND crs_grp.GrpCod=crs_grp_usr.GrpCod)",
" not belonging to groups of a type"); Gbl.CurrentCrs.Crs.CrsCod,
(unsigned) Role,GrpTypCod);
/***** 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;
} }
/*****************************************************************************/ /*****************************************************************************/
@ -3234,12 +3240,12 @@ static long Grp_GetFirstCodGrpIBelongTo (long GrpTypCod)
long CodGrpIBelong; long CodGrpIBelong;
/***** Get a group which I belong to from database *****/ /***** 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",
" WHERE crs_grp.GrpTypCod=%ld" "SELECT crs_grp.GrpCod FROM crs_grp,crs_grp_usr"
" AND crs_grp.GrpCod=crs_grp_usr.GrpCod" " WHERE crs_grp.GrpTypCod=%ld"
" AND crs_grp_usr.UsrCod=%ld", " AND crs_grp.GrpCod=crs_grp_usr.GrpCod"
GrpTypCod,Gbl.Usrs.Me.UsrDat.UsrCod); " AND crs_grp_usr.UsrCod=%ld",
NumRows = DB_QuerySELECT_new (&mysql_res,"can not check if you belong to a group"); GrpTypCod,Gbl.Usrs.Me.UsrDat.UsrCod);
/***** Get the group *****/ /***** Get the group *****/
if (NumRows == 0) if (NumRows == 0)
@ -3485,31 +3491,38 @@ static void Grp_GetLstCodGrpsUsrBelongs (long CrsCod,long GrpTypCod,
/***** Get groups which a user belong to from database *****/ /***** Get groups which a user belong to from database *****/
if (CrsCod < 0) // Query the groups from all the user's courses if (CrsCod < 0) // Query the groups from all the user's courses
DB_BuildQuery ("SELECT GrpCod" LstGrps->NumGrps =
" FROM crs_grp_usr" (unsigned) DB_QuerySELECT (&mysql_res,"can not get the groups"
" WHERE UsrCod=%ld", // Groups will be unordered " which a user belongs to",
UsrCod); "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 else if (GrpTypCod < 0) // Query the groups of any type in the course
DB_BuildQuery ("SELECT crs_grp.GrpCod" LstGrps->NumGrps =
" FROM crs_grp_types,crs_grp,crs_grp_usr" (unsigned) DB_QuerySELECT (&mysql_res,"can not get the groups"
" WHERE crs_grp_types.CrsCod=%ld" " which a user belongs to",
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod" "SELECT crs_grp.GrpCod"
" AND crs_grp.GrpCod=crs_grp_usr.GrpCod" " FROM crs_grp_types,crs_grp,crs_grp_usr"
" AND crs_grp_usr.UsrCod=%ld" " WHERE crs_grp_types.CrsCod=%ld"
" ORDER BY crs_grp_types.GrpTypName,crs_grp.GrpName", " AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
Gbl.CurrentCrs.Crs.CrsCod,UsrCod); " AND crs_grp.GrpCod=crs_grp_usr.GrpCod"
" AND crs_grp_usr.UsrCod=%ld"
" 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 else // Query only the groups of specified type in the course
DB_BuildQuery ("SELECT crs_grp.GrpCod" LstGrps->NumGrps =
" FROM crs_grp_types,crs_grp,crs_grp_usr" (unsigned) DB_QuerySELECT (&mysql_res,"can not get the groups"
" WHERE crs_grp_types.CrsCod=%ld" " which a user belongs to",
" AND crs_grp_types.GrpTypCod=%ld" "SELECT crs_grp.GrpCod"
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod" " FROM crs_grp_types,crs_grp,crs_grp_usr"
" AND crs_grp.GrpCod=crs_grp_usr.GrpCod" " WHERE crs_grp_types.CrsCod=%ld"
" AND crs_grp_usr.UsrCod=%ld" " AND crs_grp_types.GrpTypCod=%ld"
" ORDER BY crs_grp.GrpName", " AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
Gbl.CurrentCrs.Crs.CrsCod,GrpTypCod,UsrCod); " AND crs_grp.GrpCod=crs_grp_usr.GrpCod"
LstGrps->NumGrps = (unsigned) DB_QuerySELECT_new (&mysql_res, " AND crs_grp_usr.UsrCod=%ld"
"can not get the groups which a user belongs to"); " ORDER BY crs_grp.GrpName",
Gbl.CurrentCrs.Crs.CrsCod,GrpTypCod,UsrCod);
/***** Get the groups *****/ /***** Get the groups *****/
if (LstGrps->NumGrps) if (LstGrps->NumGrps)
@ -3544,16 +3557,18 @@ void Grp_GetLstCodGrpsWithFileZonesIBelong (struct ListCodGrps *LstGrps)
unsigned NumGrp; unsigned NumGrp;
/***** Get groups which I belong to from database *****/ /***** Get groups which I belong to from database *****/
DB_BuildQuery ("SELECT crs_grp.GrpCod" LstGrps->NumGrps =
" FROM crs_grp_types,crs_grp,crs_grp_usr" (unsigned) DB_QuerySELECT (&mysql_res,"can not get the groups"
" WHERE crs_grp_types.CrsCod=%ld" " which you belong to",
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod" "SELECT crs_grp.GrpCod"
" AND crs_grp.FileZones='Y'" " FROM crs_grp_types,crs_grp,crs_grp_usr"
" AND crs_grp.GrpCod=crs_grp_usr.GrpCod" " WHERE crs_grp_types.CrsCod=%ld"
" AND crs_grp_usr.UsrCod=%ld" " AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
" ORDER BY crs_grp_types.GrpTypName,crs_grp.GrpName", " AND crs_grp.FileZones='Y'"
Gbl.CurrentCrs.Crs.CrsCod,Gbl.Usrs.Me.UsrDat.UsrCod); " AND crs_grp.GrpCod=crs_grp_usr.GrpCod"
LstGrps->NumGrps = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get the groups which I belong to"); " AND crs_grp_usr.UsrCod=%ld"
" ORDER BY crs_grp_types.GrpTypName,crs_grp.GrpName",
Gbl.CurrentCrs.Crs.CrsCod,Gbl.Usrs.Me.UsrDat.UsrCod);
/***** Get the groups *****/ /***** Get the groups *****/
if (LstGrps->NumGrps) if (LstGrps->NumGrps)
@ -3603,16 +3618,19 @@ void Grp_GetNamesGrpsStdBelongsTo (long GrpTypCod,long UsrCod,char *GroupNames)
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRow; unsigned long NumRow;
unsigned long NumRows; 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 *****/ /***** 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"
" WHERE crs_grp.GrpTypCod=%ld" " a user belongs to",
" AND crs_grp.GrpCod=crs_grp_usr.GrpCod" "SELECT crs_grp.GrpName"
" AND crs_grp_usr.UsrCod=%ld" " FROM crs_grp,crs_grp_usr"
" ORDER BY crs_grp.GrpName", " WHERE crs_grp.GrpTypCod=%ld"
GrpTypCod,UsrCod); " AND crs_grp.GrpCod=crs_grp_usr.GrpCod"
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get the names of groups a user belongs to"); " AND crs_grp_usr.UsrCod=%ld"
" ORDER BY crs_grp.GrpName",
GrpTypCod,UsrCod);
/***** Get the groups *****/ /***** Get the groups *****/
GroupNames[0] = '\0'; GroupNames[0] = '\0';