mirror of https://github.com/acanas/swad-core.git
Version 20.56.1: Apr 04, 2021 Optimizations in database selects.
This commit is contained in:
parent
3c20280f3a
commit
444bf9c76b
|
@ -600,13 +600,14 @@ TODO: Salvador Romero Cort
|
||||||
|
|
||||||
TODO: FIX BUG, URGENT! En las fechas como parámetro Dat_WriteParamsIniEndDates(), por ejemplo al cambiar el color de la gráfica de accesos por día y hora, no se respeta la zona horaria.
|
TODO: FIX BUG, URGENT! En las fechas como parámetro Dat_WriteParamsIniEndDates(), por ejemplo al cambiar el color de la gráfica de accesos por día y hora, no se respeta la zona horaria.
|
||||||
*/
|
*/
|
||||||
#define Log_PLATFORM_VERSION "SWAD 20.56 (2021-04-04)"
|
#define Log_PLATFORM_VERSION "SWAD 20.56.1 (2021-04-04)"
|
||||||
#define CSS_FILE "swad20.45.css"
|
#define CSS_FILE "swad20.45.css"
|
||||||
#define JS_FILE "swad20.6.2.js"
|
#define JS_FILE "swad20.6.2.js"
|
||||||
/*
|
/*
|
||||||
TODO: Rename CENTRE to CENTER in help wiki.
|
TODO: Rename CENTRE to CENTER in help wiki.
|
||||||
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
|
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
|
||||||
|
|
||||||
|
Version 20.56.1: Apr 04, 2021 Optimizations in database selects. (309252 lines)
|
||||||
Version 20.56: Apr 04, 2021 Optimizations in database selects. (309296 lines)
|
Version 20.56: Apr 04, 2021 Optimizations in database selects. (309296 lines)
|
||||||
Version 20.55: Apr 04, 2021 Optimizations in database selects. (309500 lines)
|
Version 20.55: Apr 04, 2021 Optimizations in database selects. (309500 lines)
|
||||||
Version 20.54: Mar 30, 2021 Statistics about agendas. (309539 lines)
|
Version 20.54: Mar 30, 2021 Statistics about agendas. (309539 lines)
|
||||||
|
|
87
swad_game.c
87
swad_game.c
|
@ -1138,7 +1138,7 @@ static void Gam_GetGameTxtFromDB (long GamCod,char Txt[Cns_MAX_BYTES_TEXT + 1])
|
||||||
|
|
||||||
/***** Get text of game from database *****/
|
/***** Get text of game from database *****/
|
||||||
NumRows = DB_QuerySELECT (&mysql_res,"can not get game text",
|
NumRows = DB_QuerySELECT (&mysql_res,"can not get game text",
|
||||||
"SELECT Txt"
|
"SELECT Txt" // row[0]
|
||||||
" FROM gam_games"
|
" FROM gam_games"
|
||||||
" WHERE GamCod=%ld",
|
" WHERE GamCod=%ld",
|
||||||
GamCod);
|
GamCod);
|
||||||
|
@ -1878,27 +1878,19 @@ static unsigned Gam_GetQstIndFromQstCod (long GamCod,long QstCod)
|
||||||
|
|
||||||
long Gam_GetQstCodFromQstInd (long GamCod,unsigned QstInd)
|
long Gam_GetQstCodFromQstInd (long GamCod,unsigned QstInd)
|
||||||
{
|
{
|
||||||
MYSQL_RES *mysql_res;
|
|
||||||
MYSQL_ROW row;
|
|
||||||
long QstCod;
|
long QstCod;
|
||||||
|
|
||||||
/***** Get question code of the question to be moved up *****/
|
/***** Get question code of the question to be moved up *****/
|
||||||
if (!DB_QuerySELECT (&mysql_res,"can not get question code",
|
QstCod = DB_QuerySELECTCode ("can not get question code",
|
||||||
"SELECT QstCod"
|
"SELECT QstCod"
|
||||||
" FROM gam_questions"
|
" FROM gam_questions"
|
||||||
" WHERE GamCod=%ld"
|
" WHERE GamCod=%ld"
|
||||||
" AND QstInd=%u",
|
" AND QstInd=%u",
|
||||||
GamCod,QstInd))
|
GamCod,
|
||||||
|
QstInd);
|
||||||
|
if (QstCod <= 0)
|
||||||
Lay_ShowErrorAndExit ("Error: wrong question index.");
|
Lay_ShowErrorAndExit ("Error: wrong question index.");
|
||||||
|
|
||||||
/***** Get question code (row[0]) *****/
|
|
||||||
row = mysql_fetch_row (mysql_res);
|
|
||||||
if ((QstCod = Str_ConvertStrCodToLongCod (row[0])) <= 0)
|
|
||||||
Lay_ShowErrorAndExit ("Error: wrong question code.");
|
|
||||||
|
|
||||||
/***** Free structure that stores the query result *****/
|
|
||||||
DB_FreeMySQLResult (&mysql_res);
|
|
||||||
|
|
||||||
return QstCod;
|
return QstCod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1916,7 +1908,7 @@ static unsigned Gam_GetMaxQuestionIndexInGame (long GamCod)
|
||||||
|
|
||||||
/***** Get maximum question index in a game from database *****/
|
/***** Get maximum question index in a game from database *****/
|
||||||
DB_QuerySELECT (&mysql_res,"can not get last question index",
|
DB_QuerySELECT (&mysql_res,"can not get last question index",
|
||||||
"SELECT MAX(QstInd)"
|
"SELECT MAX(QstInd)" // row[0]
|
||||||
" FROM gam_questions"
|
" FROM gam_questions"
|
||||||
" WHERE GamCod=%ld",
|
" WHERE GamCod=%ld",
|
||||||
GamCod);
|
GamCod);
|
||||||
|
@ -1984,7 +1976,7 @@ unsigned Gam_GetNextQuestionIndexInGame (long GamCod,unsigned QstInd)
|
||||||
// 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
|
||||||
if (!DB_QuerySELECT (&mysql_res,"can not get next question index",
|
if (!DB_QuerySELECT (&mysql_res,"can not get next question index",
|
||||||
"SELECT MIN(QstInd)"
|
"SELECT MIN(QstInd)" // row[0]
|
||||||
" FROM gam_questions"
|
" FROM gam_questions"
|
||||||
" WHERE GamCod=%ld"
|
" WHERE GamCod=%ld"
|
||||||
" AND QstInd>%u",
|
" AND QstInd>%u",
|
||||||
|
@ -2834,7 +2826,7 @@ double Gam_GetNumQstsPerCrsGame (Hie_Lvl_Level_t Scope)
|
||||||
{
|
{
|
||||||
case Hie_Lvl_SYS:
|
case Hie_Lvl_SYS:
|
||||||
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
|
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
|
||||||
"SELECT AVG(NumQsts)"
|
"SELECT AVG(NumQsts)" // row[0]
|
||||||
" FROM (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
|
" FROM (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
|
||||||
" FROM gam_games,"
|
" FROM gam_games,"
|
||||||
"gam_questions"
|
"gam_questions"
|
||||||
|
@ -2843,7 +2835,7 @@ double Gam_GetNumQstsPerCrsGame (Hie_Lvl_Level_t Scope)
|
||||||
break;
|
break;
|
||||||
case Hie_Lvl_CTY:
|
case Hie_Lvl_CTY:
|
||||||
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
|
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
|
||||||
"SELECT AVG(NumQsts)"
|
"SELECT AVG(NumQsts)" // row[0]
|
||||||
" FROM (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
|
" FROM (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
|
||||||
" FROM ins_instits,"
|
" FROM ins_instits,"
|
||||||
"ctr_centers,"
|
"ctr_centers,"
|
||||||
|
@ -2862,7 +2854,7 @@ double Gam_GetNumQstsPerCrsGame (Hie_Lvl_Level_t Scope)
|
||||||
break;
|
break;
|
||||||
case Hie_Lvl_INS:
|
case Hie_Lvl_INS:
|
||||||
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
|
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
|
||||||
"SELECT AVG(NumQsts)"
|
"SELECT AVG(NumQsts)" // row[0]
|
||||||
" FROM (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
|
" FROM (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
|
||||||
" FROM ctr_centers,"
|
" FROM ctr_centers,"
|
||||||
"deg_degrees,"
|
"deg_degrees,"
|
||||||
|
@ -2879,7 +2871,7 @@ double Gam_GetNumQstsPerCrsGame (Hie_Lvl_Level_t Scope)
|
||||||
break;
|
break;
|
||||||
case Hie_Lvl_CTR:
|
case Hie_Lvl_CTR:
|
||||||
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
|
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
|
||||||
"SELECT AVG(NumQsts)"
|
"SELECT AVG(NumQsts)" // row[0]
|
||||||
" FROM (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
|
" FROM (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
|
||||||
" FROM deg_degrees,"
|
" FROM deg_degrees,"
|
||||||
"crs_courses,"
|
"crs_courses,"
|
||||||
|
@ -2894,7 +2886,7 @@ double Gam_GetNumQstsPerCrsGame (Hie_Lvl_Level_t Scope)
|
||||||
break;
|
break;
|
||||||
case Hie_Lvl_DEG:
|
case Hie_Lvl_DEG:
|
||||||
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
|
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
|
||||||
"SELECT AVG(NumQsts)"
|
"SELECT AVG(NumQsts)" // row[0]
|
||||||
" FROM (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
|
" FROM (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
|
||||||
" FROM crs_courses,"
|
" FROM crs_courses,"
|
||||||
"gam_games,"
|
"gam_games,"
|
||||||
|
@ -2907,7 +2899,7 @@ double Gam_GetNumQstsPerCrsGame (Hie_Lvl_Level_t Scope)
|
||||||
break;
|
break;
|
||||||
case Hie_Lvl_CRS:
|
case Hie_Lvl_CRS:
|
||||||
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
|
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
|
||||||
"SELECT AVG(NumQsts)"
|
"SELECT AVG(NumQsts)" // row[0]
|
||||||
" FROM (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
|
" FROM (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
|
||||||
" FROM gam_games,"
|
" FROM gam_games,"
|
||||||
"gam_questions"
|
"gam_questions"
|
||||||
|
@ -2964,39 +2956,22 @@ void Gam_ShowTstTagsPresentInAGame (long GamCod)
|
||||||
|
|
||||||
void Gam_GetScoreRange (long GamCod,double *MinScore,double *MaxScore)
|
void Gam_GetScoreRange (long GamCod,double *MinScore,double *MaxScore)
|
||||||
{
|
{
|
||||||
MYSQL_RES *mysql_res;
|
|
||||||
MYSQL_ROW row;
|
|
||||||
unsigned NumRows;
|
|
||||||
unsigned NumRow;
|
|
||||||
unsigned NumAnswers;
|
unsigned NumAnswers;
|
||||||
|
|
||||||
/***** Get maximum score of a game from database *****/
|
/***** Get maximum score of a game from database *****/
|
||||||
NumRows = (unsigned)
|
NumAnswers = DB_QueryCOUNT ("can not number of answers of a question",
|
||||||
DB_QuerySELECT (&mysql_res,"can not get data of a question",
|
"SELECT COUNT(tst_answers.AnsInd)"
|
||||||
"SELECT COUNT(tst_answers.AnsInd) AS N"
|
" FROM tst_answers,"
|
||||||
" FROM tst_answers,"
|
"gam_questions"
|
||||||
"gam_questions"
|
" WHERE gam_questions.GamCod=%ld"
|
||||||
" WHERE gam_questions.GamCod=%ld"
|
" AND gam_questions.QstCod=tst_answers.QstCod"
|
||||||
" AND gam_questions.QstCod=tst_answers.QstCod"
|
" GROUP BY tst_answers.QstCod",
|
||||||
" GROUP BY tst_answers.QstCod",
|
GamCod);
|
||||||
GamCod);
|
if (NumAnswers < 2)
|
||||||
for (NumRow = 0, *MinScore = *MaxScore = 0.0;
|
Lay_ShowErrorAndExit ("Wrong number of answers.");
|
||||||
NumRow < NumRows;
|
|
||||||
NumRow++)
|
|
||||||
{
|
|
||||||
row = mysql_fetch_row (mysql_res);
|
|
||||||
|
|
||||||
/* Get min answers (row[0]) */
|
/***** Set minimum and maximum scores *****/
|
||||||
if (sscanf (row[0],"%u",&NumAnswers) != 1)
|
*MinScore = *MaxScore = 0.0;
|
||||||
NumAnswers = 0;
|
*MinScore += -1.0 / (double) (NumAnswers - 1);
|
||||||
|
*MaxScore += 1.0;
|
||||||
/* Accumulate minimum and maximum score */
|
|
||||||
if (NumAnswers < 2)
|
|
||||||
Lay_ShowErrorAndExit ("Wrong number of answers.");
|
|
||||||
*MinScore += -1.0 / (double) (NumAnswers - 1);
|
|
||||||
*MaxScore += 1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/***** Free structure that stores the query result *****/
|
|
||||||
DB_FreeMySQLResult (&mysql_res);
|
|
||||||
}
|
}
|
||||||
|
|
285
swad_group.c
285
swad_group.c
|
@ -2768,56 +2768,54 @@ 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:
|
||||||
Gbl.Crs.Grps.GrpTypes.Num =
|
Gbl.Crs.Grps.GrpTypes.Num = (unsigned)
|
||||||
(unsigned) DB_QuerySELECT (&mysql_res,"can not get types of group"
|
DB_QuerySELECT (&mysql_res,"can not get types of group of a course",
|
||||||
" of a course",
|
"SELECT grp_types.GrpTypCod," // row[0]
|
||||||
"SELECT grp_types.GrpTypCod,"
|
"grp_types.GrpTypName," // row[1]
|
||||||
"grp_types.GrpTypName,"
|
"grp_types.Mandatory," // row[2]
|
||||||
"grp_types.Mandatory,"
|
"grp_types.Multiple," // row[3]
|
||||||
"grp_types.Multiple,"
|
"grp_types.MustBeOpened," // row[4]
|
||||||
"grp_types.MustBeOpened,"
|
"UNIX_TIMESTAMP(grp_types.OpenTime)," // row[5]
|
||||||
"UNIX_TIMESTAMP(grp_types.OpenTime),"
|
"COUNT(grp_groups.GrpCod)" // row[6]
|
||||||
"COUNT(grp_groups.GrpCod)"
|
" FROM grp_types,"
|
||||||
" FROM grp_types,"
|
"grp_groups"
|
||||||
"grp_groups"
|
" WHERE grp_types.CrsCod=%ld"
|
||||||
" WHERE grp_types.CrsCod=%ld"
|
" AND grp_types.GrpTypCod=grp_groups.GrpTypCod"
|
||||||
" AND grp_types.GrpTypCod=grp_groups.GrpTypCod"
|
" GROUP BY grp_types.GrpTypCod"
|
||||||
" GROUP BY grp_types.GrpTypCod"
|
" ORDER BY grp_types.GrpTypName",
|
||||||
" ORDER BY grp_types.GrpTypName",
|
Gbl.Hierarchy.Crs.CrsCod);
|
||||||
Gbl.Hierarchy.Crs.CrsCod);
|
|
||||||
break;
|
break;
|
||||||
case Grp_ALL_GROUP_TYPES:
|
case Grp_ALL_GROUP_TYPES:
|
||||||
Gbl.Crs.Grps.GrpTypes.Num =
|
Gbl.Crs.Grps.GrpTypes.Num = (unsigned)
|
||||||
(unsigned) DB_QuerySELECT (&mysql_res,"can not get types of group"
|
DB_QuerySELECT (&mysql_res,"can not get types of group of a course",
|
||||||
" of a course",
|
"(SELECT grp_types.GrpTypCod," // row[0]
|
||||||
"(SELECT grp_types.GrpTypCod,"
|
"grp_types.GrpTypName AS GrpTypName," // row[1]
|
||||||
"grp_types.GrpTypName AS GrpTypName,"
|
"grp_types.Mandatory," // row[2]
|
||||||
"grp_types.Mandatory,"
|
"grp_types.Multiple," // row[3]
|
||||||
"grp_types.Multiple,"
|
"grp_types.MustBeOpened," // row[4]
|
||||||
"grp_types.MustBeOpened,"
|
"UNIX_TIMESTAMP(grp_types.OpenTime)," // row[5]
|
||||||
"UNIX_TIMESTAMP(grp_types.OpenTime),"
|
"COUNT(grp_groups.GrpCod)" // row[6]
|
||||||
"COUNT(grp_groups.GrpCod)"
|
" FROM grp_types,"
|
||||||
" FROM grp_types,"
|
"grp_groups"
|
||||||
"grp_groups"
|
" WHERE grp_types.CrsCod=%ld"
|
||||||
" WHERE grp_types.CrsCod=%ld"
|
" AND grp_types.GrpTypCod=grp_groups.GrpTypCod"
|
||||||
" AND grp_types.GrpTypCod=grp_groups.GrpTypCod"
|
" GROUP BY grp_types.GrpTypCod)"
|
||||||
" GROUP BY grp_types.GrpTypCod)"
|
" UNION "
|
||||||
" UNION "
|
"(SELECT GrpTypCod," // row[0]
|
||||||
"(SELECT GrpTypCod,"
|
"GrpTypName," // row[1]
|
||||||
"GrpTypName,"
|
"Mandatory," // row[2]
|
||||||
"Mandatory,"
|
"Multiple," // row[3]
|
||||||
"Multiple,"
|
"MustBeOpened," // row[4]
|
||||||
"MustBeOpened,"
|
"UNIX_TIMESTAMP(OpenTime)," // row[5]
|
||||||
"UNIX_TIMESTAMP(OpenTime),"
|
"0"
|
||||||
"0"
|
" FROM grp_types"
|
||||||
" FROM grp_types"
|
" WHERE CrsCod=%ld"
|
||||||
" WHERE CrsCod=%ld"
|
" AND GrpTypCod NOT IN"
|
||||||
" AND GrpTypCod NOT IN"
|
" (SELECT GrpTypCod"
|
||||||
" (SELECT GrpTypCod"
|
" FROM grp_groups))"
|
||||||
" FROM grp_groups))"
|
" ORDER BY GrpTypName",
|
||||||
" ORDER BY GrpTypName",
|
Gbl.Hierarchy.Crs.CrsCod,
|
||||||
Gbl.Hierarchy.Crs.CrsCod,
|
Gbl.Hierarchy.Crs.CrsCod);
|
||||||
Gbl.Hierarchy.Crs.CrsCod);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2884,30 +2882,26 @@ void Grp_GetListGrpTypesInThisCrs (Grp_WhichGroupTypes_t WhichGroupTypes)
|
||||||
void Grp_OpenGroupsAutomatically (void)
|
void Grp_OpenGroupsAutomatically (void)
|
||||||
{
|
{
|
||||||
MYSQL_RES *mysql_res;
|
MYSQL_RES *mysql_res;
|
||||||
MYSQL_ROW row;
|
|
||||||
unsigned NumGrpTypes;
|
unsigned NumGrpTypes;
|
||||||
unsigned NumGrpTyp;
|
unsigned NumGrpTyp;
|
||||||
long GrpTypCod;
|
long GrpTypCod;
|
||||||
|
|
||||||
/***** Find group types to be opened *****/
|
/***** Find group types to be opened *****/
|
||||||
NumGrpTypes =
|
NumGrpTypes = (unsigned)
|
||||||
(unsigned) DB_QuerySELECT (&mysql_res,"can not get the types of group"
|
DB_QuerySELECT (&mysql_res,"can not get the types of group to be opened",
|
||||||
" to be opened",
|
"SELECT GrpTypCod"
|
||||||
"SELECT GrpTypCod"
|
" FROM grp_types"
|
||||||
" FROM grp_types"
|
" WHERE CrsCod=%ld"
|
||||||
" WHERE CrsCod=%ld"
|
" AND MustBeOpened='Y'"
|
||||||
" AND MustBeOpened='Y'"
|
" AND OpenTime<=NOW()",
|
||||||
" AND OpenTime<=NOW()",
|
Gbl.Hierarchy.Crs.CrsCod);
|
||||||
Gbl.Hierarchy.Crs.CrsCod);
|
|
||||||
|
|
||||||
for (NumGrpTyp = 0;
|
for (NumGrpTyp = 0;
|
||||||
NumGrpTyp < NumGrpTypes;
|
NumGrpTyp < NumGrpTypes;
|
||||||
NumGrpTyp++)
|
NumGrpTyp++)
|
||||||
{
|
{
|
||||||
/* Get next group TYPE */
|
/* Get next group TYPE */
|
||||||
row = mysql_fetch_row (mysql_res);
|
if ((GrpTypCod = DB_GetNextCode (mysql_res)) > 0)
|
||||||
|
|
||||||
if ((GrpTypCod = Str_ConvertStrCodToLongCod (row[0])) > 0)
|
|
||||||
{
|
{
|
||||||
/***** Open all the closed groups in this course the must be opened
|
/***** Open all the closed groups in this course the must be opened
|
||||||
and with open time in the past ****/
|
and with open time in the past ****/
|
||||||
|
@ -3123,15 +3117,15 @@ static void Grp_GetDataOfGroupTypeByCod (struct GroupType *GrpTyp)
|
||||||
|
|
||||||
/***** Get data of a type of group from database *****/
|
/***** Get data of a type of group from database *****/
|
||||||
if (DB_QuerySELECT (&mysql_res,"can not get type of group",
|
if (DB_QuerySELECT (&mysql_res,"can not get type of group",
|
||||||
"SELECT GrpTypName," // row[0]
|
"SELECT GrpTypName," // row[0]
|
||||||
"Mandatory," // row[1]
|
"Mandatory," // row[1]
|
||||||
"Multiple," // row[2]
|
"Multiple," // row[2]
|
||||||
"MustBeOpened," // row[3]
|
"MustBeOpened," // row[3]
|
||||||
"UNIX_TIMESTAMP(OpenTime)" // row[4]
|
"UNIX_TIMESTAMP(OpenTime)" // row[4]
|
||||||
" FROM grp_types"
|
" FROM grp_types"
|
||||||
" WHERE CrsCod=%ld"
|
" WHERE CrsCod=%ld"
|
||||||
" AND GrpTypCod=%ld",
|
" AND GrpTypCod=%ld",
|
||||||
Gbl.Hierarchy.Crs.CrsCod,GrpTyp->GrpTypCod) != 1)
|
Gbl.Hierarchy.Crs.CrsCod,GrpTyp->GrpTypCod) != 1)
|
||||||
Lay_ShowErrorAndExit ("Error when getting type of group.");
|
Lay_ShowErrorAndExit ("Error when getting type of group.");
|
||||||
|
|
||||||
/***** Get some data of group type *****/
|
/***** Get some data of group type *****/
|
||||||
|
@ -3159,7 +3153,7 @@ static bool Grp_GetMultipleEnrolmentOfAGroupType (long GrpTypCod)
|
||||||
/***** Get data of a type of group from database *****/
|
/***** Get data of a type of group from database *****/
|
||||||
if (DB_QuerySELECT (&mysql_res,"can not get if type of group"
|
if (DB_QuerySELECT (&mysql_res,"can not get if type of group"
|
||||||
" has multiple enrolment",
|
" has multiple enrolment",
|
||||||
"SELECT Multiple"
|
"SELECT Multiple" // row[0]
|
||||||
" FROM grp_types"
|
" FROM grp_types"
|
||||||
" WHERE GrpTypCod=%ld",
|
" WHERE GrpTypCod=%ld",
|
||||||
GrpTypCod) != 1)
|
GrpTypCod) != 1)
|
||||||
|
@ -3204,8 +3198,8 @@ void Grp_GetDataOfGroupByCod (struct GroupData *GrpDat)
|
||||||
NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a group",
|
NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a group",
|
||||||
"SELECT grp_groups.GrpTypCod," // row[0]
|
"SELECT grp_groups.GrpTypCod," // row[0]
|
||||||
"grp_types.CrsCod," // row[1]
|
"grp_types.CrsCod," // row[1]
|
||||||
"grp_types.GrpTypName," // row[2]
|
"grp_types.GrpTypName," // row[2]
|
||||||
"grp_types.Multiple," // row[3]
|
"grp_types.Multiple," // row[3]
|
||||||
"grp_groups.GrpName," // row[4]
|
"grp_groups.GrpName," // row[4]
|
||||||
"grp_groups.RooCod," // row[5]
|
"grp_groups.RooCod," // row[5]
|
||||||
"roo_rooms.ShortName," // row[6]
|
"roo_rooms.ShortName," // row[6]
|
||||||
|
@ -3273,27 +3267,17 @@ void Grp_GetDataOfGroupByCod (struct GroupData *GrpDat)
|
||||||
|
|
||||||
static long Grp_GetTypeOfGroupOfAGroup (long GrpCod)
|
static long Grp_GetTypeOfGroupOfAGroup (long GrpCod)
|
||||||
{
|
{
|
||||||
MYSQL_RES *mysql_res;
|
|
||||||
MYSQL_ROW row;
|
|
||||||
long GrpTypCod;
|
long GrpTypCod;
|
||||||
|
|
||||||
/***** Get data of a group from database *****/
|
/***** Get group type of a group from database *****/
|
||||||
if (DB_QuerySELECT (&mysql_res,"can not get the type of a group",
|
GrpTypCod = DB_QuerySELECTCode ("can not get the type of a group",
|
||||||
"SELECT GrpTypCod"
|
"SELECT GrpTypCod"
|
||||||
" FROM grp_groups"
|
" FROM grp_groups"
|
||||||
" WHERE GrpCod=%ld",
|
" WHERE GrpCod=%ld",
|
||||||
GrpCod) != 1)
|
GrpCod);
|
||||||
|
if (GrpTypCod <= 0)
|
||||||
Lay_ShowErrorAndExit ("Error when getting group.");
|
Lay_ShowErrorAndExit ("Error when getting group.");
|
||||||
|
|
||||||
/***** Get data of group *****/
|
|
||||||
row = mysql_fetch_row (mysql_res);
|
|
||||||
/* Get the code of the group type (row[0]) */
|
|
||||||
if ((GrpTypCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
|
|
||||||
Lay_ShowErrorAndExit ("Wrong code of type of group.");
|
|
||||||
|
|
||||||
/***** Free structure that stores the query result *****/
|
|
||||||
DB_FreeMySQLResult (&mysql_res);
|
|
||||||
|
|
||||||
return GrpTypCod;
|
return GrpTypCod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3621,51 +3605,47 @@ static void Grp_GetLstCodGrpsUsrBelongs (long CrsCod,long GrpTypCod,
|
||||||
long UsrCod,struct ListCodGrps *LstGrps)
|
long UsrCod,struct ListCodGrps *LstGrps)
|
||||||
{
|
{
|
||||||
MYSQL_RES *mysql_res;
|
MYSQL_RES *mysql_res;
|
||||||
MYSQL_ROW row;
|
|
||||||
unsigned NumGrp;
|
unsigned NumGrp;
|
||||||
|
|
||||||
/***** 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
|
||||||
LstGrps->NumGrps =
|
LstGrps->NumGrps = (unsigned)
|
||||||
(unsigned) DB_QuerySELECT (&mysql_res,"can not get the groups"
|
DB_QuerySELECT (&mysql_res,"can not get the groups which a user belongs to",
|
||||||
" which a user belongs to",
|
"SELECT GrpCod" // row[0]
|
||||||
"SELECT GrpCod"
|
" FROM grp_users"
|
||||||
" FROM grp_users"
|
" WHERE UsrCod=%ld", // Groups will be unordered
|
||||||
" WHERE UsrCod=%ld", // Groups will be unordered
|
UsrCod);
|
||||||
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
|
||||||
LstGrps->NumGrps =
|
LstGrps->NumGrps = (unsigned)
|
||||||
(unsigned) DB_QuerySELECT (&mysql_res,"can not get the groups"
|
DB_QuerySELECT (&mysql_res,"can not get the groups which a user belongs to",
|
||||||
" which a user belongs to",
|
"SELECT grp_groups.GrpCod" // row[0]
|
||||||
"SELECT grp_groups.GrpCod"
|
" FROM grp_types,"
|
||||||
" FROM grp_types,"
|
"grp_groups,"
|
||||||
"grp_groups,"
|
"grp_users"
|
||||||
"grp_users"
|
" WHERE grp_types.CrsCod=%ld"
|
||||||
" WHERE grp_types.CrsCod=%ld"
|
" AND grp_types.GrpTypCod=grp_groups.GrpTypCod"
|
||||||
" AND grp_types.GrpTypCod=grp_groups.GrpTypCod"
|
" AND grp_groups.GrpCod=grp_users.GrpCod"
|
||||||
" AND grp_groups.GrpCod=grp_users.GrpCod"
|
" AND grp_users.UsrCod=%ld"
|
||||||
" AND grp_users.UsrCod=%ld"
|
" ORDER BY grp_types.GrpTypName,"
|
||||||
" ORDER BY grp_types.GrpTypName,"
|
"grp_groups.GrpName",
|
||||||
"grp_groups.GrpName",
|
Gbl.Hierarchy.Crs.CrsCod,
|
||||||
Gbl.Hierarchy.Crs.CrsCod,
|
UsrCod);
|
||||||
UsrCod);
|
|
||||||
else // Query only the groups of specified type in the course
|
else // Query only the groups of specified type in the course
|
||||||
LstGrps->NumGrps =
|
LstGrps->NumGrps = (unsigned)
|
||||||
(unsigned) DB_QuerySELECT (&mysql_res,"can not get the groups"
|
DB_QuerySELECT (&mysql_res,"can not get the groups which a user belongs to",
|
||||||
" which a user belongs to",
|
"SELECT grp_groups.GrpCod" // row[0]
|
||||||
"SELECT grp_groups.GrpCod"
|
" FROM grp_types,"
|
||||||
" FROM grp_types,"
|
"grp_groups,"
|
||||||
"grp_groups,"
|
"grp_users"
|
||||||
"grp_users"
|
" WHERE grp_types.CrsCod=%ld"
|
||||||
" WHERE grp_types.CrsCod=%ld"
|
" AND grp_types.GrpTypCod=%ld"
|
||||||
" AND grp_types.GrpTypCod=%ld"
|
" AND grp_types.GrpTypCod=grp_groups.GrpTypCod"
|
||||||
" AND grp_types.GrpTypCod=grp_groups.GrpTypCod"
|
" AND grp_groups.GrpCod=grp_users.GrpCod"
|
||||||
" AND grp_groups.GrpCod=grp_users.GrpCod"
|
" AND grp_users.UsrCod=%ld"
|
||||||
" AND grp_users.UsrCod=%ld"
|
" ORDER BY grp_groups.GrpName",
|
||||||
" ORDER BY grp_groups.GrpName",
|
Gbl.Hierarchy.Crs.CrsCod,
|
||||||
Gbl.Hierarchy.Crs.CrsCod,
|
GrpTypCod,
|
||||||
GrpTypCod,
|
UsrCod);
|
||||||
UsrCod);
|
|
||||||
|
|
||||||
/***** Get the groups *****/
|
/***** Get the groups *****/
|
||||||
if (LstGrps->NumGrps)
|
if (LstGrps->NumGrps)
|
||||||
|
@ -3677,13 +3657,9 @@ static void Grp_GetLstCodGrpsUsrBelongs (long CrsCod,long GrpTypCod,
|
||||||
for (NumGrp = 0;
|
for (NumGrp = 0;
|
||||||
NumGrp < LstGrps->NumGrps;
|
NumGrp < LstGrps->NumGrps;
|
||||||
NumGrp++)
|
NumGrp++)
|
||||||
{
|
|
||||||
row = mysql_fetch_row (mysql_res);
|
|
||||||
|
|
||||||
/* Get the code of group (row[0]) */
|
/* Get the code of group (row[0]) */
|
||||||
if ((LstGrps->GrpCods[NumGrp] = Str_ConvertStrCodToLongCod (row[0])) < 0)
|
if ((LstGrps->GrpCods[NumGrp] = DB_GetNextCode (mysql_res)) < 0)
|
||||||
Lay_ShowErrorAndExit ("Wrong code of group.");
|
Lay_ShowErrorAndExit ("Wrong code of group.");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/***** Free structure that stores the query result *****/
|
/***** Free structure that stores the query result *****/
|
||||||
|
@ -3697,25 +3673,24 @@ static void Grp_GetLstCodGrpsUsrBelongs (long CrsCod,long GrpTypCod,
|
||||||
void Grp_GetLstCodGrpsWithFileZonesIBelong (struct ListCodGrps *LstGrps)
|
void Grp_GetLstCodGrpsWithFileZonesIBelong (struct ListCodGrps *LstGrps)
|
||||||
{
|
{
|
||||||
MYSQL_RES *mysql_res;
|
MYSQL_RES *mysql_res;
|
||||||
MYSQL_ROW row;
|
|
||||||
unsigned NumGrp;
|
unsigned NumGrp;
|
||||||
|
|
||||||
/***** Get groups which I belong to from database *****/
|
/***** Get groups which I belong to from database *****/
|
||||||
LstGrps->NumGrps =
|
LstGrps->NumGrps = (unsigned)
|
||||||
(unsigned) DB_QuerySELECT (&mysql_res,"can not get the groups"
|
DB_QuerySELECT (&mysql_res,"can not get the groups which you belong to",
|
||||||
" which you belong to",
|
"SELECT grp_groups.GrpCod" // row[0]
|
||||||
"SELECT grp_groups.GrpCod"
|
" FROM grp_types,"
|
||||||
" FROM grp_types,"
|
"grp_groups,"
|
||||||
"grp_groups,"
|
"grp_users"
|
||||||
"grp_users"
|
" WHERE grp_types.CrsCod=%ld"
|
||||||
" WHERE grp_types.CrsCod=%ld"
|
" AND grp_types.GrpTypCod=grp_groups.GrpTypCod"
|
||||||
" AND grp_types.GrpTypCod=grp_groups.GrpTypCod"
|
" AND grp_groups.FileZones='Y'"
|
||||||
" AND grp_groups.FileZones='Y'"
|
" AND grp_groups.GrpCod=grp_users.GrpCod"
|
||||||
" AND grp_groups.GrpCod=grp_users.GrpCod"
|
" AND grp_users.UsrCod=%ld"
|
||||||
" AND grp_users.UsrCod=%ld"
|
" ORDER BY grp_types.GrpTypName,"
|
||||||
" ORDER BY grp_types.GrpTypName,"
|
"grp_groups.GrpName",
|
||||||
"grp_groups.GrpName",
|
Gbl.Hierarchy.Crs.CrsCod,
|
||||||
Gbl.Hierarchy.Crs.CrsCod,Gbl.Usrs.Me.UsrDat.UsrCod);
|
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||||
|
|
||||||
/***** Get the groups *****/
|
/***** Get the groups *****/
|
||||||
if (LstGrps->NumGrps)
|
if (LstGrps->NumGrps)
|
||||||
|
@ -3727,13 +3702,9 @@ void Grp_GetLstCodGrpsWithFileZonesIBelong (struct ListCodGrps *LstGrps)
|
||||||
for (NumGrp = 0;
|
for (NumGrp = 0;
|
||||||
NumGrp < LstGrps->NumGrps;
|
NumGrp < LstGrps->NumGrps;
|
||||||
NumGrp++)
|
NumGrp++)
|
||||||
{
|
/* Get the code of group */
|
||||||
row = mysql_fetch_row (mysql_res);
|
if ((LstGrps->GrpCods[NumGrp] = DB_GetNextCode (mysql_res)) < 0)
|
||||||
|
|
||||||
/* Get the code of group (row[0]) */
|
|
||||||
if ((LstGrps->GrpCods[NumGrp] = Str_ConvertStrCodToLongCod (row[0])) < 0)
|
|
||||||
Lay_ShowErrorAndExit ("Wrong code of group.");
|
Lay_ShowErrorAndExit ("Wrong code of group.");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/***** Free structure that stores the query result *****/
|
/***** Free structure that stores the query result *****/
|
||||||
|
@ -3772,7 +3743,7 @@ void Grp_GetNamesGrpsStdBelongsTo (long GrpTypCod,long UsrCod,char *GroupNames)
|
||||||
/***** Get the names of groups which a user belongs to, from database *****/
|
/***** Get the names of groups which a user belongs to, from database *****/
|
||||||
NumRows = DB_QuerySELECT (&mysql_res,"can not get the names of groups"
|
NumRows = DB_QuerySELECT (&mysql_res,"can not get the names of groups"
|
||||||
" a user belongs to",
|
" a user belongs to",
|
||||||
"SELECT grp_groups.GrpName"
|
"SELECT grp_groups.GrpName" // row[0]
|
||||||
" FROM grp_groups,"
|
" FROM grp_groups,"
|
||||||
"grp_users"
|
"grp_users"
|
||||||
" WHERE grp_groups.GrpTypCod=%ld"
|
" WHERE grp_groups.GrpTypCod=%ld"
|
||||||
|
|
Loading…
Reference in New Issue