mirror of https://github.com/acanas/swad-core.git
Version 18.11.7
This commit is contained in:
parent
ad7ec2156c
commit
7bfe4197e8
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
578
swad_game.c
578
swad_game.c
|
@ -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,23 +975,22 @@ void Gam_GetListGames (void)
|
|||
break;
|
||||
}
|
||||
|
||||
DB_BuildQuery ("SELECT GamCod FROM games"
|
||||
" WHERE %s%s%s%s%s%s"
|
||||
" ORDER BY %s",
|
||||
SubQuery[Sco_SCOPE_SYS],
|
||||
SubQuery[Sco_SCOPE_CTY],
|
||||
SubQuery[Sco_SCOPE_INS],
|
||||
SubQuery[Sco_SCOPE_CTR],
|
||||
SubQuery[Sco_SCOPE_DEG],
|
||||
SubQuery[Sco_SCOPE_CRS],
|
||||
OrderBySubQuery);
|
||||
/* 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],
|
||||
SubQuery[Sco_SCOPE_CTY],
|
||||
SubQuery[Sco_SCOPE_INS],
|
||||
SubQuery[Sco_SCOPE_CTR],
|
||||
SubQuery[Sco_SCOPE_DEG],
|
||||
SubQuery[Sco_SCOPE_CRS],
|
||||
OrderBySubQuery);
|
||||
}
|
||||
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,19 +1196,16 @@ void Gam_GetDataOfGameByCod (struct Game *Game)
|
|||
MYSQL_ROW row;
|
||||
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 *****/
|
||||
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...
|
||||
{
|
||||
/* Get row */
|
||||
|
@ -1299,71 +1295,71 @@ void Gam_GetDataOfGameByCod (struct Game *Game)
|
|||
{
|
||||
case Rol_STD:
|
||||
Game->Status.ICanViewResults = (Game->Scope == Sco_SCOPE_CRS ||
|
||||
Game->Scope == Sco_SCOPE_DEG ||
|
||||
Game->Scope == Sco_SCOPE_CTR ||
|
||||
Game->Scope == Sco_SCOPE_INS ||
|
||||
Game->Scope == Sco_SCOPE_CTY ||
|
||||
Game->Scope == Sco_SCOPE_SYS) &&
|
||||
(Game->NumQsts != 0) &&
|
||||
Game->Status.Visible &&
|
||||
Game->Status.Open &&
|
||||
Game->Status.IAmLoggedWithAValidRoleToAnswer &&
|
||||
Game->Status.IBelongToScope &&
|
||||
Game->Status.IHaveAnswered;
|
||||
Game->Scope == Sco_SCOPE_DEG ||
|
||||
Game->Scope == Sco_SCOPE_CTR ||
|
||||
Game->Scope == Sco_SCOPE_INS ||
|
||||
Game->Scope == Sco_SCOPE_CTY ||
|
||||
Game->Scope == Sco_SCOPE_SYS) &&
|
||||
(Game->NumQsts != 0) &&
|
||||
Game->Status.Visible &&
|
||||
Game->Status.Open &&
|
||||
Game->Status.IAmLoggedWithAValidRoleToAnswer &&
|
||||
Game->Status.IBelongToScope &&
|
||||
Game->Status.IHaveAnswered;
|
||||
Game->Status.ICanEdit = false;
|
||||
break;
|
||||
case Rol_NET:
|
||||
Game->Status.ICanViewResults = (Game->Scope == Sco_SCOPE_CRS ||
|
||||
Game->Scope == Sco_SCOPE_DEG ||
|
||||
Game->Scope == Sco_SCOPE_CTR ||
|
||||
Game->Scope == Sco_SCOPE_INS ||
|
||||
Game->Scope == Sco_SCOPE_CTY ||
|
||||
Game->Scope == Sco_SCOPE_SYS) &&
|
||||
Game->NumQsts != 0 &&
|
||||
!Game->Status.ICanAnswer;
|
||||
Game->Scope == Sco_SCOPE_DEG ||
|
||||
Game->Scope == Sco_SCOPE_CTR ||
|
||||
Game->Scope == Sco_SCOPE_INS ||
|
||||
Game->Scope == Sco_SCOPE_CTY ||
|
||||
Game->Scope == Sco_SCOPE_SYS) &&
|
||||
Game->NumQsts != 0 &&
|
||||
!Game->Status.ICanAnswer;
|
||||
Game->Status.ICanEdit = false;
|
||||
break;
|
||||
case Rol_TCH:
|
||||
Game->Status.ICanViewResults = (Game->Scope == Sco_SCOPE_CRS ||
|
||||
Game->Scope == Sco_SCOPE_DEG ||
|
||||
Game->Scope == Sco_SCOPE_CTR ||
|
||||
Game->Scope == Sco_SCOPE_INS ||
|
||||
Game->Scope == Sco_SCOPE_CTY ||
|
||||
Game->Scope == Sco_SCOPE_SYS) &&
|
||||
Game->NumQsts != 0 &&
|
||||
!Game->Status.ICanAnswer;
|
||||
Game->Scope == Sco_SCOPE_DEG ||
|
||||
Game->Scope == Sco_SCOPE_CTR ||
|
||||
Game->Scope == Sco_SCOPE_INS ||
|
||||
Game->Scope == Sco_SCOPE_CTY ||
|
||||
Game->Scope == Sco_SCOPE_SYS) &&
|
||||
Game->NumQsts != 0 &&
|
||||
!Game->Status.ICanAnswer;
|
||||
Game->Status.ICanEdit = Game->Scope == Sco_SCOPE_CRS &&
|
||||
Game->Status.IBelongToScope;
|
||||
Game->Status.IBelongToScope;
|
||||
break;
|
||||
case Rol_DEG_ADM:
|
||||
Game->Status.ICanViewResults = (Game->Scope == Sco_SCOPE_DEG ||
|
||||
Game->Scope == Sco_SCOPE_CTR ||
|
||||
Game->Scope == Sco_SCOPE_INS ||
|
||||
Game->Scope == Sco_SCOPE_CTY ||
|
||||
Game->Scope == Sco_SCOPE_SYS) &&
|
||||
(Game->NumQsts != 0) &&
|
||||
!Game->Status.ICanAnswer;
|
||||
Game->Scope == Sco_SCOPE_CTR ||
|
||||
Game->Scope == Sco_SCOPE_INS ||
|
||||
Game->Scope == Sco_SCOPE_CTY ||
|
||||
Game->Scope == Sco_SCOPE_SYS) &&
|
||||
(Game->NumQsts != 0) &&
|
||||
!Game->Status.ICanAnswer;
|
||||
Game->Status.ICanEdit = Game->Scope == Sco_SCOPE_DEG &&
|
||||
Game->Status.IBelongToScope;
|
||||
Game->Status.IBelongToScope;
|
||||
break;
|
||||
case Rol_CTR_ADM:
|
||||
Game->Status.ICanViewResults = (Game->Scope == Sco_SCOPE_CTR ||
|
||||
Game->Scope == Sco_SCOPE_INS ||
|
||||
Game->Scope == Sco_SCOPE_CTY ||
|
||||
Game->Scope == Sco_SCOPE_SYS) &&
|
||||
(Game->NumQsts != 0) &&
|
||||
!Game->Status.ICanAnswer;
|
||||
Game->Scope == Sco_SCOPE_INS ||
|
||||
Game->Scope == Sco_SCOPE_CTY ||
|
||||
Game->Scope == Sco_SCOPE_SYS) &&
|
||||
(Game->NumQsts != 0) &&
|
||||
!Game->Status.ICanAnswer;
|
||||
Game->Status.ICanEdit = Game->Scope == Sco_SCOPE_CTR &&
|
||||
Game->Status.IBelongToScope;
|
||||
Game->Status.IBelongToScope;
|
||||
break;
|
||||
case Rol_INS_ADM:
|
||||
Game->Status.ICanViewResults = (Game->Scope == Sco_SCOPE_INS ||
|
||||
Game->Scope == Sco_SCOPE_CTY ||
|
||||
Game->Scope == Sco_SCOPE_SYS) &&
|
||||
(Game->NumQsts != 0) &&
|
||||
!Game->Status.ICanAnswer;
|
||||
Game->Scope == Sco_SCOPE_CTY ||
|
||||
Game->Scope == Sco_SCOPE_SYS) &&
|
||||
(Game->NumQsts != 0) &&
|
||||
!Game->Status.ICanAnswer;
|
||||
Game->Status.ICanEdit = Game->Scope == Sco_SCOPE_INS &&
|
||||
Game->Status.IBelongToScope;
|
||||
Game->Status.IBelongToScope;
|
||||
break;
|
||||
case Rol_SYS_ADM:
|
||||
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;
|
||||
|
||||
/***** 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"
|
||||
" 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");
|
||||
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);
|
||||
|
||||
/***** 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"
|
||||
" WHERE GamCod=%ld AND QstCod=%ld",
|
||||
GamCod,QstCod);
|
||||
if (!DB_QuerySELECT_new (&mysql_res,"can not get question index"))
|
||||
if (!DB_QuerySELECT (&mysql_res,"can not get question index",
|
||||
"SELECT QstInd FROM gam_questions"
|
||||
" WHERE GamCod=%ld AND QstCod=%ld",
|
||||
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"
|
||||
" WHERE GamCod=%ld AND QstInd=%u",
|
||||
GamCod,QstInd);
|
||||
if (!DB_QuerySELECT_new (&mysql_res,"can not get question code"))
|
||||
if (!DB_QuerySELECT (&mysql_res,"can not get question code",
|
||||
"SELECT QstCod FROM gam_questions"
|
||||
" WHERE GamCod=%ld AND QstInd=%u",
|
||||
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",
|
||||
GamCod);
|
||||
DB_QuerySELECT_new (&mysql_res,"can not get last question index");
|
||||
DB_QuerySELECT (&mysql_res,"can not get last question index",
|
||||
"SELECT MAX(QstInd) FROM gam_questions WHERE GamCod=%ld",
|
||||
GamCod);
|
||||
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"
|
||||
" WHERE GamCod=%ld AND QstInd<%u",
|
||||
GamCod,QstInd);
|
||||
if (!DB_QuerySELECT_new (&mysql_res,"can not get previous question index"))
|
||||
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))
|
||||
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"
|
||||
" WHERE GamCod=%ld AND QstInd>%u",
|
||||
GamCod,QstInd);
|
||||
if (!DB_QuerySELECT_new (&mysql_res,"can not get next question index"))
|
||||
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))
|
||||
Lay_ShowErrorAndExit ("Error: next question index not found.");
|
||||
|
||||
/***** Get next question index (row[0]) *****/
|
||||
|
@ -2735,19 +2732,19 @@ static void Gam_ListGameQuestions (struct Game *Game)
|
|||
row[5] ImageTitle
|
||||
row[6] ImageURL
|
||||
*/
|
||||
DB_BuildQuery ("SELECT tst_questions.QstCod,"
|
||||
"tst_questions.AnsType,"
|
||||
"tst_questions.Stem,"
|
||||
"tst_questions.Feedback,"
|
||||
"tst_questions.ImageName,"
|
||||
"tst_questions.ImageTitle,"
|
||||
"tst_questions.ImageURL"
|
||||
" FROM gam_questions,tst_questions"
|
||||
" WHERE gam_questions.GamCod=%ld"
|
||||
" 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");
|
||||
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,"
|
||||
"tst_questions.ImageName,"
|
||||
"tst_questions.ImageTitle,"
|
||||
"tst_questions.ImageURL"
|
||||
" FROM gam_questions,tst_questions"
|
||||
" WHERE gam_questions.GamCod=%ld"
|
||||
" AND gam_questions.QstCod=tst_questions.QstCod"
|
||||
" ORDER BY gam_questions.QstInd",
|
||||
Game->GamCod);
|
||||
|
||||
/***** 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"
|
||||
" 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"))
|
||||
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))
|
||||
{
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
if (row[0]) // There are users who selected this answer
|
||||
|
@ -3543,19 +3540,19 @@ static void Gam_PlayGameShowQuestionAndAnswers (bool ShowAnswers)
|
|||
row[4] ImageTitle
|
||||
row[5] ImageURL
|
||||
*/
|
||||
DB_BuildQuery ("SELECT "
|
||||
"tst_questions.QstCod,"
|
||||
"tst_questions.AnsType,"
|
||||
"tst_questions.Stem,"
|
||||
"tst_questions.ImageName,"
|
||||
"tst_questions.ImageTitle,"
|
||||
"tst_questions.ImageURL"
|
||||
" FROM gam_questions,tst_questions"
|
||||
" 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"))
|
||||
if (!DB_QuerySELECT (&mysql_res,"can not get data of a question",
|
||||
"SELECT "
|
||||
"tst_questions.QstCod,"
|
||||
"tst_questions.AnsType,"
|
||||
"tst_questions.Stem,"
|
||||
"tst_questions.ImageName,"
|
||||
"tst_questions.ImageTitle,"
|
||||
"tst_questions.ImageURL"
|
||||
" FROM gam_questions,tst_questions"
|
||||
" WHERE gam_questions.GamCod=%ld"
|
||||
" AND gam_questions.QstInd=%u"
|
||||
" AND gam_questions.QstCod=tst_questions.QstCod",
|
||||
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"
|
||||
" 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
|
||||
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) // The game has questions
|
||||
{
|
||||
/***** Get questions *****/
|
||||
for (NumQst = 0;
|
||||
|
@ -3812,65 +3810,69 @@ unsigned Gam_GetNumCoursesWithGames (Sco_Scope_t Scope)
|
|||
switch (Scope)
|
||||
{
|
||||
case Sco_SCOPE_SYS:
|
||||
DB_BuildQuery ("SELECT COUNT(DISTINCT Cod)"
|
||||
" FROM games"
|
||||
" WHERE Scope='%s'",
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS]);
|
||||
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)"
|
||||
" FROM institutions,centres,degrees,courses,games"
|
||||
" WHERE institutions.CtyCod=%ld"
|
||||
" AND institutions.InsCod=centres.InsCod"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=games.Cod"
|
||||
" AND games.Scope='%s'",
|
||||
Gbl.CurrentIns.Ins.InsCod,
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS]);
|
||||
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"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=games.Cod"
|
||||
" AND games.Scope='%s'",
|
||||
Gbl.CurrentIns.Ins.InsCod,
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS]);
|
||||
break;
|
||||
case Sco_SCOPE_INS:
|
||||
DB_BuildQuery ("SELECT COUNT(DISTINCT games.Cod)"
|
||||
" FROM centres,degrees,courses,games"
|
||||
" WHERE centres.InsCod=%ld"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=games.Cod"
|
||||
" AND games.Scope='%s'",
|
||||
Gbl.CurrentIns.Ins.InsCod,
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS]);
|
||||
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"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=games.Cod"
|
||||
" AND games.Scope='%s'",
|
||||
Gbl.CurrentIns.Ins.InsCod,
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS]);
|
||||
break;
|
||||
case Sco_SCOPE_CTR:
|
||||
DB_BuildQuery ("SELECT COUNT(DISTINCT games.Cod)"
|
||||
" FROM degrees,courses,games"
|
||||
" WHERE degrees.CtrCod=%ld"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=games.Cod"
|
||||
" AND games.Scope='%s'",
|
||||
Gbl.CurrentCtr.Ctr.CtrCod,
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS]);
|
||||
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"
|
||||
" AND courses.CrsCod=games.Cod"
|
||||
" AND games.Scope='%s'",
|
||||
Gbl.CurrentCtr.Ctr.CtrCod,
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS]);
|
||||
break;
|
||||
case Sco_SCOPE_DEG:
|
||||
DB_BuildQuery ("SELECT COUNT(DISTINCT games.Cod)"
|
||||
" FROM courses,games"
|
||||
" WHERE courses.DegCod=%ld"
|
||||
" AND courses.CrsCod=games.Cod"
|
||||
" AND games.Scope='%s'",
|
||||
Gbl.CurrentDeg.Deg.DegCod,
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS]);
|
||||
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"
|
||||
" AND games.Scope='%s'",
|
||||
Gbl.CurrentDeg.Deg.DegCod,
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS]);
|
||||
break;
|
||||
case Sco_SCOPE_CRS:
|
||||
DB_BuildQuery ("SELECT COUNT(DISTINCT Cod)"
|
||||
" FROM games"
|
||||
" WHERE Scope='%s' AND Cod=%ld",
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS],
|
||||
Gbl.CurrentCrs.Crs.CrsCod);
|
||||
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],
|
||||
Gbl.CurrentCrs.Crs.CrsCod);
|
||||
break;
|
||||
default:
|
||||
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,66 +3901,71 @@ unsigned Gam_GetNumGames (Sco_Scope_t Scope)
|
|||
switch (Scope)
|
||||
{
|
||||
case Sco_SCOPE_SYS:
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM games"
|
||||
" WHERE Scope='%s'",
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS]);
|
||||
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(*)"
|
||||
" FROM institutions,centres,degrees,courses,games"
|
||||
" WHERE institutions.CtyCod=%ld"
|
||||
" AND institutions.InsCod=centres.InsCod"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=games.Cod"
|
||||
" AND games.Scope='%s'",
|
||||
Gbl.CurrentCty.Cty.CtyCod,
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS]);
|
||||
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"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=games.Cod"
|
||||
" AND games.Scope='%s'",
|
||||
Gbl.CurrentCty.Cty.CtyCod,
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS]);
|
||||
break;
|
||||
case Sco_SCOPE_INS:
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM centres,degrees,courses,games"
|
||||
" WHERE centres.InsCod=%ld"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=games.Cod"
|
||||
" AND games.Scope='%s'",
|
||||
Gbl.CurrentIns.Ins.InsCod,
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS]);
|
||||
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"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=games.Cod"
|
||||
" AND games.Scope='%s'",
|
||||
Gbl.CurrentIns.Ins.InsCod,
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS]);
|
||||
break;
|
||||
case Sco_SCOPE_CTR:
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM degrees,courses,games"
|
||||
" WHERE degrees.CtrCod=%ld"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=games.Cod"
|
||||
" AND games.Scope='%s'",
|
||||
Gbl.CurrentCtr.Ctr.CtrCod,
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS]);
|
||||
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"
|
||||
" AND courses.CrsCod=games.Cod"
|
||||
" AND games.Scope='%s'",
|
||||
Gbl.CurrentCtr.Ctr.CtrCod,
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS]);
|
||||
break;
|
||||
case Sco_SCOPE_DEG:
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM courses,games"
|
||||
" WHERE courses.DegCod=%ld"
|
||||
" AND courses.CrsCod=games.Cod"
|
||||
" AND games.Scope='%s'",
|
||||
Gbl.CurrentDeg.Deg.DegCod,
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS]);
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of games",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM courses,games"
|
||||
" WHERE courses.DegCod=%ld"
|
||||
" AND courses.CrsCod=games.Cod"
|
||||
" AND games.Scope='%s'",
|
||||
Gbl.CurrentDeg.Deg.DegCod,
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS]);
|
||||
break;
|
||||
case Sco_SCOPE_CRS:
|
||||
DB_BuildQuery ("SELECT COUNT(*)"
|
||||
" FROM games"
|
||||
" WHERE games.Scope='%s'"
|
||||
" AND CrsCod=%ld",
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS],
|
||||
Gbl.CurrentCrs.Crs.CrsCod);
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of games",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM games"
|
||||
" WHERE games.Scope='%s'"
|
||||
" AND CrsCod=%ld",
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS],
|
||||
Gbl.CurrentCrs.Crs.CrsCod);
|
||||
break;
|
||||
default:
|
||||
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,82 +3993,87 @@ float Gam_GetNumQstsPerCrsGame (Sco_Scope_t Scope)
|
|||
switch (Scope)
|
||||
{
|
||||
case Sco_SCOPE_SYS:
|
||||
DB_BuildQuery ("SELECT AVG(NumQsts) FROM"
|
||||
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
|
||||
" FROM games,gam_questions"
|
||||
" WHERE games.Scope='%s'"
|
||||
" AND games.GamCod=gam_questions.GamCod"
|
||||
" GROUP BY gam_questions.GamCod) AS NumQstsTable",
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS]);
|
||||
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.GamCod=gam_questions.GamCod"
|
||||
" GROUP BY gam_questions.GamCod) AS NumQstsTable",
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS]);
|
||||
break;
|
||||
case Sco_SCOPE_CTY:
|
||||
DB_BuildQuery ("SELECT AVG(NumQsts) FROM"
|
||||
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
|
||||
" FROM institutions,centres,degrees,courses,games,gam_questions"
|
||||
" WHERE institutions.CtyCod=%ld"
|
||||
" AND institutions.InsCod=centres.InsCod"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=games.Cod"
|
||||
" AND games.Scope='%s'"
|
||||
" AND games.GamCod=gam_questions.GamCod"
|
||||
" GROUP BY gam_questions.GamCod) AS NumQstsTable",
|
||||
Gbl.CurrentCty.Cty.CtyCod,
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS]);
|
||||
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"
|
||||
" AND institutions.InsCod=centres.InsCod"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=games.Cod"
|
||||
" AND games.Scope='%s'"
|
||||
" AND games.GamCod=gam_questions.GamCod"
|
||||
" GROUP BY gam_questions.GamCod) AS NumQstsTable",
|
||||
Gbl.CurrentCty.Cty.CtyCod,
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS]);
|
||||
break;
|
||||
case Sco_SCOPE_INS:
|
||||
DB_BuildQuery ("SELECT AVG(NumQsts) FROM"
|
||||
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
|
||||
" FROM centres,degrees,courses,games,gam_questions"
|
||||
" WHERE centres.InsCod=%ld"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=games.Cod"
|
||||
" AND games.Scope='%s'"
|
||||
" AND games.GamCod=gam_questions.GamCod"
|
||||
" GROUP BY gam_questions.GamCod) AS NumQstsTable",
|
||||
Gbl.CurrentIns.Ins.InsCod,
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS]);
|
||||
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"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=games.Cod"
|
||||
" AND games.Scope='%s'"
|
||||
" AND games.GamCod=gam_questions.GamCod"
|
||||
" GROUP BY gam_questions.GamCod) AS NumQstsTable",
|
||||
Gbl.CurrentIns.Ins.InsCod,
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS]);
|
||||
break;
|
||||
case Sco_SCOPE_CTR:
|
||||
DB_BuildQuery ("SELECT AVG(NumQsts) FROM"
|
||||
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
|
||||
" FROM degrees,courses,games,gam_questions"
|
||||
" WHERE degrees.CtrCod=%ld"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=games.Cod"
|
||||
" AND games.Scope='%s'"
|
||||
" AND games.GamCod=gam_questions.GamCod"
|
||||
" GROUP BY gam_questions.GamCod) AS NumQstsTable",
|
||||
Gbl.CurrentCtr.Ctr.CtrCod,
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS]);
|
||||
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"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=games.Cod"
|
||||
" AND games.Scope='%s'"
|
||||
" AND games.GamCod=gam_questions.GamCod"
|
||||
" GROUP BY gam_questions.GamCod) AS NumQstsTable",
|
||||
Gbl.CurrentCtr.Ctr.CtrCod,
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS]);
|
||||
break;
|
||||
case Sco_SCOPE_DEG:
|
||||
DB_BuildQuery ("SELECT AVG(NumQsts) FROM"
|
||||
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
|
||||
" FROM courses,games,gam_questions"
|
||||
" WHERE courses.DegCod=%ld"
|
||||
" AND courses.CrsCod=games.Cod"
|
||||
" AND games.Scope='%s'"
|
||||
" AND games.GamCod=gam_questions.GamCod"
|
||||
" GROUP BY gam_questions.GamCod) AS NumQstsTable",
|
||||
Gbl.CurrentDeg.Deg.DegCod,
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS]);
|
||||
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"
|
||||
" AND courses.CrsCod=games.Cod"
|
||||
" AND games.Scope='%s'"
|
||||
" AND games.GamCod=gam_questions.GamCod"
|
||||
" GROUP BY gam_questions.GamCod) AS NumQstsTable",
|
||||
Gbl.CurrentDeg.Deg.DegCod,
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS]);
|
||||
break;
|
||||
case Sco_SCOPE_CRS:
|
||||
DB_BuildQuery ("SELECT AVG(NumQsts) FROM"
|
||||
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
|
||||
" FROM games,gam_questions"
|
||||
" WHERE games.Scope='%s' AND games.Cod=%ld"
|
||||
" AND games.GamCod=gam_questions.GamCod"
|
||||
" GROUP BY gam_questions.GamCod) AS NumQstsTable",
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS],Gbl.CurrentCrs.Crs.CrsCod);
|
||||
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"
|
||||
" AND games.GamCod=gam_questions.GamCod"
|
||||
" GROUP BY gam_questions.GamCod) AS NumQstsTable",
|
||||
Sco_ScopeDB[Sco_SCOPE_CRS],Gbl.CurrentCrs.Crs.CrsCod);
|
||||
break;
|
||||
default:
|
||||
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);
|
||||
|
|
322
swad_group.c
322
swad_group.c
|
@ -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,42 +2688,47 @@ 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,"
|
||||
"crs_grp_types.Mandatory,crs_grp_types.Multiple,"
|
||||
"crs_grp_types.MustBeOpened,"
|
||||
"UNIX_TIMESTAMP(crs_grp_types.OpenTime),"
|
||||
"COUNT(crs_grp.GrpCod)"
|
||||
" FROM crs_grp_types,crs_grp"
|
||||
" WHERE crs_grp_types.CrsCod=%ld"
|
||||
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
|
||||
" GROUP BY crs_grp_types.GrpTypCod"
|
||||
" ORDER BY crs_grp_types.GrpTypName",
|
||||
Gbl.CurrentCrs.Crs.CrsCod);
|
||||
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),"
|
||||
"COUNT(crs_grp.GrpCod)"
|
||||
" FROM crs_grp_types,crs_grp"
|
||||
" WHERE crs_grp_types.CrsCod=%ld"
|
||||
" 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;
|
||||
case Grp_ALL_GROUP_TYPES:
|
||||
DB_BuildQuery ("(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),"
|
||||
"COUNT(crs_grp.GrpCod)"
|
||||
" FROM crs_grp_types,crs_grp"
|
||||
" WHERE crs_grp_types.CrsCod=%ld"
|
||||
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
|
||||
" GROUP BY crs_grp_types.GrpTypCod)"
|
||||
" UNION "
|
||||
"(SELECT GrpTypCod,GrpTypName,"
|
||||
"Mandatory,Multiple,"
|
||||
"MustBeOpened,"
|
||||
"UNIX_TIMESTAMP(OpenTime),"
|
||||
"0"
|
||||
" FROM crs_grp_types WHERE CrsCod=%ld"
|
||||
" AND GrpTypCod NOT IN (SELECT GrpTypCod FROM crs_grp))"
|
||||
" ORDER BY GrpTypName",
|
||||
Gbl.CurrentCrs.Crs.CrsCod,
|
||||
Gbl.CurrentCrs.Crs.CrsCod);
|
||||
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),"
|
||||
"COUNT(crs_grp.GrpCod)"
|
||||
" FROM crs_grp_types,crs_grp"
|
||||
" WHERE crs_grp_types.CrsCod=%ld"
|
||||
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
|
||||
" GROUP BY crs_grp_types.GrpTypCod)"
|
||||
" UNION "
|
||||
"(SELECT GrpTypCod,GrpTypName,"
|
||||
"Mandatory,Multiple,"
|
||||
"MustBeOpened,"
|
||||
"UNIX_TIMESTAMP(OpenTime),"
|
||||
"0"
|
||||
" FROM crs_grp_types WHERE CrsCod=%ld"
|
||||
" AND GrpTypCod NOT IN (SELECT GrpTypCod FROM crs_grp))"
|
||||
" ORDER BY GrpTypName",
|
||||
Gbl.CurrentCrs.Crs.CrsCod,
|
||||
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"
|
||||
" 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");
|
||||
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);
|
||||
|
||||
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"
|
||||
" FROM crs_grp"
|
||||
" WHERE GrpTypCod=%ld"
|
||||
" ORDER BY GrpName",
|
||||
GrpTypCod);
|
||||
return DB_QuerySELECT_new (mysql_res,"can not get groups of a type");
|
||||
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);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -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)"
|
||||
" 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");
|
||||
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);
|
||||
|
||||
/***** 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"
|
||||
" 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");
|
||||
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);
|
||||
|
||||
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"
|
||||
" 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;
|
||||
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);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -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"
|
||||
" 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");
|
||||
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);
|
||||
|
||||
/***** Get the group *****/
|
||||
if (NumRows == 0)
|
||||
|
@ -3485,31 +3491,38 @@ 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"
|
||||
" FROM crs_grp_usr"
|
||||
" WHERE UsrCod=%ld", // Groups will be unordered
|
||||
UsrCod);
|
||||
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"
|
||||
" FROM crs_grp_types,crs_grp,crs_grp_usr"
|
||||
" WHERE crs_grp_types.CrsCod=%ld"
|
||||
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
|
||||
" 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);
|
||||
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"
|
||||
" 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
|
||||
DB_BuildQuery ("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"
|
||||
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
|
||||
" AND crs_grp.GrpCod=crs_grp_usr.GrpCod"
|
||||
" 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");
|
||||
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"
|
||||
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
|
||||
" AND crs_grp.GrpCod=crs_grp_usr.GrpCod"
|
||||
" AND crs_grp_usr.UsrCod=%ld"
|
||||
" ORDER BY crs_grp.GrpName",
|
||||
Gbl.CurrentCrs.Crs.CrsCod,GrpTypCod,UsrCod);
|
||||
|
||||
/***** Get the groups *****/
|
||||
if (LstGrps->NumGrps)
|
||||
|
@ -3544,16 +3557,18 @@ void Grp_GetLstCodGrpsWithFileZonesIBelong (struct ListCodGrps *LstGrps)
|
|||
unsigned NumGrp;
|
||||
|
||||
/***** Get groups which I belong to from database *****/
|
||||
DB_BuildQuery ("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"
|
||||
" AND crs_grp.FileZones='Y'"
|
||||
" 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,Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||
LstGrps->NumGrps = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get the groups which I belong to");
|
||||
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"
|
||||
" AND crs_grp.FileZones='Y'"
|
||||
" 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,Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||
|
||||
/***** 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"
|
||||
" 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");
|
||||
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);
|
||||
|
||||
/***** Get the groups *****/
|
||||
GroupNames[0] = '\0';
|
||||
|
|
Loading…
Reference in New Issue