Version 20.53: Mar 29, 2021 Code refactoring in database selects.

This commit is contained in:
acanas 2021-03-29 16:38:56 +02:00
parent 9af1bbaa51
commit b889e97639
29 changed files with 1751 additions and 1381 deletions

View File

@ -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.52 (2021-03-28)" #define Log_PLATFORM_VERSION "SWAD 20.53 (2021-03-29)"
#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.53: Mar 29, 2021 Code refactoring in database selects. (309473 lines)
Version 20.52: Mar 28, 2021 Code refactoring in database selects. (309103 lines) Version 20.52: Mar 28, 2021 Code refactoring in database selects. (309103 lines)
Version 20.51.49: Mar 26, 2021 User IDs database table renamed. (308816 lines) Version 20.51.49: Mar 26, 2021 User IDs database table renamed. (308816 lines)
1 change necessary in database: 1 change necessary in database:

View File

@ -306,14 +306,15 @@ void Mch_ListMatches (struct Gam_Games *Games,
{ {
if (asprintf (&SubQuery," AND" if (asprintf (&SubQuery," AND"
" (MchCod NOT IN" " (MchCod NOT IN"
" (SELECT MchCod FROM mch_groups)" " (SELECT MchCod"
" OR" " FROM mch_groups)"
" MchCod IN" " OR"
" (SELECT mch_groups.MchCod" " MchCod IN"
" FROM grp_users," " (SELECT mch_groups.MchCod"
"mch_groups" " FROM grp_users,"
" WHERE grp_users.UsrCod=%ld" "mch_groups"
" AND grp_users.GrpCod=mch_groups.GrpCod))", " WHERE grp_users.UsrCod=%ld"
" AND grp_users.GrpCod=mch_groups.GrpCod))",
Gbl.Usrs.Me.UsrDat.UsrCod) < 0) Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit (); Lay_NotEnoughMemoryExit ();
} }
@ -322,25 +323,26 @@ void Mch_ListMatches (struct Gam_Games *Games,
Lay_NotEnoughMemoryExit (); Lay_NotEnoughMemoryExit ();
/* Make query */ /* Make query */
NumMatches = (unsigned) DB_QuerySELECT (&mysql_res,"can not get matches", NumMatches = (unsigned)
"SELECT MchCod," // row[ 0] DB_QuerySELECT (&mysql_res,"can not get matches",
"GamCod," // row[ 1] "SELECT MchCod," // row[ 0]
"UsrCod," // row[ 2] "GamCod," // row[ 1]
"UNIX_TIMESTAMP(StartTime)," // row[ 3] "UsrCod," // row[ 2]
"UNIX_TIMESTAMP(EndTime)," // row[ 4] "UNIX_TIMESTAMP(StartTime)," // row[ 3]
"Title," // row[ 5] "UNIX_TIMESTAMP(EndTime)," // row[ 4]
"QstInd," // row[ 6] "Title," // row[ 5]
"QstCod," // row[ 7] "QstInd," // row[ 6]
"Showing," // row[ 8] "QstCod," // row[ 7]
"Countdown," // row[ 9] "Showing," // row[ 8]
"NumCols," // row[10] "Countdown," // row[ 9]
"ShowQstResults," // row[11] "NumCols," // row[10]
"ShowUsrResults" // row[12] "ShowQstResults," // row[11]
" FROM mch_matches" "ShowUsrResults" // row[12]
" WHERE GamCod=%ld%s" " FROM mch_matches"
" ORDER BY MchCod", " WHERE GamCod=%ld%s"
Game->GamCod, " ORDER BY MchCod",
SubQuery); Game->GamCod,
SubQuery);
/* Free allocated memory for subquery */ /* Free allocated memory for subquery */
free (SubQuery); free (SubQuery);
@ -406,27 +408,28 @@ void Mch_GetDataOfMatchByCod (struct Mch_Match *Match)
/***** Get data of match from database *****/ /***** Get data of match from database *****/
NumRows = (unsigned) NumRows = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get matches", DB_QuerySELECT (&mysql_res,"can not get matches",
"SELECT MchCod," // row[ 0] "SELECT MchCod," // row[ 0]
"GamCod," // row[ 1] "GamCod," // row[ 1]
"UsrCod," // row[ 2] "UsrCod," // row[ 2]
"UNIX_TIMESTAMP(StartTime),"// row[ 3] "UNIX_TIMESTAMP(StartTime)," // row[ 3]
"UNIX_TIMESTAMP(EndTime)," // row[ 4] "UNIX_TIMESTAMP(EndTime)," // row[ 4]
"Title," // row[ 5] "Title," // row[ 5]
"QstInd," // row[ 6] "QstInd," // row[ 6]
"QstCod," // row[ 7] "QstCod," // row[ 7]
"Showing," // row[ 8] "Showing," // row[ 8]
"Countdown," // row[ 9] "Countdown," // row[ 9]
"NumCols," // row[10] "NumCols," // row[10]
"ShowQstResults," // row[11] "ShowQstResults," // row[11]
"ShowUsrResults" // row[12] "ShowUsrResults" // row[12]
" FROM mch_matches" " FROM mch_matches"
" WHERE MchCod=%ld" " WHERE MchCod=%ld"
" AND GamCod IN" // Extra check " AND GamCod IN" // Extra check
" (SELECT GamCod FROM gam_games" " (SELECT GamCod"
" WHERE CrsCod='%ld')", " FROM gam_games"
Match->MchCod, " WHERE CrsCod='%ld')",
Gbl.Hierarchy.Crs.CrsCod); Match->MchCod,
Gbl.Hierarchy.Crs.CrsCod);
if (NumRows) // Match found... if (NumRows) // Match found...
/* Get match data from row */ /* Get match data from row */
Mch_GetMatchDataFromRow (mysql_res,Match); Mch_GetMatchDataFromRow (mysql_res,Match);
@ -1789,9 +1792,9 @@ static void Mch_CreateIndexes (long GamCod,long MchCod)
"gam_questions.QstInd," // row[1] "gam_questions.QstInd," // row[1]
"tst_questions.AnsType," // row[2] "tst_questions.AnsType," // row[2]
"tst_questions.Shuffle" // row[3] "tst_questions.Shuffle" // row[3]
" FROM gam_questions,tst_questions" " FROM gam_questions,tst_questions"
" WHERE gam_questions.GamCod=%ld" " WHERE gam_questions.GamCod=%ld"
" AND gam_questions.QstCod=tst_questions.QstCod" " AND gam_questions.QstCod=tst_questions.QstCod"
" ORDER BY gam_questions.QstInd", " ORDER BY gam_questions.QstInd",
GamCod); GamCod);
@ -1861,14 +1864,14 @@ static void Mch_ReorderAnswer (long MchCod,unsigned QstInd,
/***** Get questions of the game *****/ /***** Get questions of the game *****/
NumAnss = (unsigned) NumAnss = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get questions of a game", DB_QuerySELECT (&mysql_res,"can not get questions of a game",
"SELECT AnsInd" // row[0] "SELECT AnsInd" // row[0]
" FROM tst_answers" " FROM tst_answers"
" WHERE QstCod=%ld" " WHERE QstCod=%ld"
" ORDER BY %s", " ORDER BY %s",
Question->QstCod, Question->QstCod,
Question->Answer.Shuffle ? "RAND()" : // Use RAND() because is really random; RAND(NOW()) repeats order Question->Answer.Shuffle ? "RAND()" : // Use RAND() because is really random; RAND(NOW()) repeats order
"AnsInd"); "AnsInd");
/***** For each answer in question... *****/ /***** For each answer in question... *****/
for (NumAns = 0; for (NumAns = 0;
@ -1915,9 +1918,11 @@ void Mch_GetIndexes (long MchCod,unsigned QstInd,
/***** Get indexes for a question from database *****/ /***** Get indexes for a question from database *****/
if (!DB_QuerySELECT (&mysql_res,"can not get data of a question", if (!DB_QuerySELECT (&mysql_res,"can not get data of a question",
"SELECT Indexes" // row[0] "SELECT Indexes" // row[0]
" FROM mch_indexes" " FROM mch_indexes"
" WHERE MchCod=%ld AND QstInd=%u", " WHERE MchCod=%ld"
MchCod,QstInd)) " AND QstInd=%u",
MchCod,
QstInd))
Lay_ShowErrorAndExit ("No indexes found for a question."); Lay_ShowErrorAndExit ("No indexes found for a question.");
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -2067,11 +2072,14 @@ static void Mch_GetElapsedTimeInQuestion (const struct Mch_Match *Match,
unsigned NumRows; unsigned NumRows;
/***** Query database *****/ /***** Query database *****/
NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get elapsed time", NumRows = (unsigned)
"SELECT ElapsedTime" DB_QuerySELECT (&mysql_res,"can not get elapsed time",
" FROM mch_times" "SELECT ElapsedTime"
" WHERE MchCod=%ld AND QstInd=%u", " FROM mch_times"
Match->MchCod,Match->Status.QstInd); " WHERE MchCod=%ld"
" AND QstInd=%u",
Match->MchCod,
Match->Status.QstInd);
/***** Get elapsed time from query result *****/ /***** Get elapsed time from query result *****/
Mch_GetElapsedTime (NumRows,mysql_res,Time); Mch_GetElapsedTime (NumRows,mysql_res,Time);
@ -2091,10 +2099,12 @@ static void Mch_GetElapsedTimeInMatch (const struct Mch_Match *Match,
unsigned NumRows; unsigned NumRows;
/***** Query database *****/ /***** Query database *****/
NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get elapsed time", NumRows = (unsigned)
"SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(ElapsedTime)))" DB_QuerySELECT (&mysql_res,"can not get elapsed time",
" FROM mch_times WHERE MchCod=%ld", "SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(ElapsedTime)))"
Match->MchCod); " FROM mch_times"
" WHERE MchCod=%ld",
Match->MchCod);
/***** Get elapsed time from query result *****/ /***** Get elapsed time from query result *****/
Mch_GetElapsedTime (NumRows,mysql_res,Time); Mch_GetElapsedTime (NumRows,mysql_res,Time);
@ -2480,11 +2490,12 @@ unsigned Mch_GetNumMchsInGame (long GamCod)
return 0; // ...has no matches return 0; // ...has no matches
/***** Get number of matches in a game from database *****/ /***** Get number of matches in a game from database *****/
return return (unsigned)
(unsigned) DB_QueryCOUNT ("can not get number of matches of a game", DB_QueryCOUNT ("can not get number of matches of a game",
"SELECT COUNT(*) FROM mch_matches" "SELECT COUNT(*)"
" WHERE GamCod=%ld", " FROM mch_matches"
GamCod); " WHERE GamCod=%ld",
GamCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2498,11 +2509,14 @@ unsigned Mch_GetNumUnfinishedMchsInGame (long GamCod)
return 0; // ...has no matches return 0; // ...has no matches
/***** Get number of matches in a game from database *****/ /***** Get number of matches in a game from database *****/
return return (unsigned)
(unsigned) DB_QueryCOUNT ("can not get number of unfinished matches of a game", DB_QueryCOUNT ("can not get number of unfinished matches of a game",
"SELECT COUNT(*) FROM mch_matches" "SELECT COUNT(*)"
" WHERE GamCod=%ld AND Showing<>'%s'", " FROM mch_matches"
GamCod,Mch_ShowingStringsDB[Mch_END]); " WHERE GamCod=%ld"
" AND Showing<>'%s'",
GamCod,
Mch_ShowingStringsDB[Mch_END]);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2517,19 +2531,21 @@ bool Mch_CheckIfICanPlayThisMatchBasedOnGrps (const struct Mch_Match *Match)
/***** Check if I belong to any of the groups /***** Check if I belong to any of the groups
associated to the match *****/ associated to the match *****/
return (DB_QueryCOUNT ("can not check if I can play a match", return (DB_QueryCOUNT ("can not check if I can play a match",
"SELECT COUNT(*) FROM mch_matches" "SELECT COUNT(*)"
" FROM mch_matches"
" WHERE MchCod=%ld" " WHERE MchCod=%ld"
" AND" " AND (MchCod NOT IN"
"(MchCod NOT IN" " (SELECT MchCod"
" (SELECT MchCod FROM mch_groups)" " FROM mch_groups)"
" OR" " OR"
" MchCod IN" " MchCod IN"
" (SELECT mch_groups.MchCod" " (SELECT mch_groups.MchCod"
" FROM grp_users," " FROM grp_users,"
"mch_groups" "mch_groups"
" WHERE grp_users.UsrCod=%ld" " WHERE grp_users.UsrCod=%ld"
" AND grp_users.GrpCod=mch_groups.GrpCod))", " AND grp_users.GrpCod=mch_groups.GrpCod))",
Match->MchCod,Gbl.Usrs.Me.UsrDat.UsrCod) != 0); Match->MchCod,
Gbl.Usrs.Me.UsrDat.UsrCod) != 0);
break; break;
case Rol_NET: case Rol_NET:
/***** Only if I am the creator *****/ /***** Only if I am the creator *****/
@ -3489,13 +3505,12 @@ static void Mch_ShowMatchScore (const struct Mch_Match *Match)
/***** Get maximum number of users *****/ /***** Get maximum number of users *****/
if (DB_QuerySELECT (&mysql_res,"can not get max users", if (DB_QuerySELECT (&mysql_res,"can not get max users",
"SELECT MAX(NumUsrs)" "SELECT MAX(NumUsrs)" // row[1]
" FROM " " FROM (SELECT COUNT(*) AS NumUsrs"
"(SELECT COUNT(*) AS NumUsrs" // row[1] " FROM mch_results"
" FROM mch_results" " WHERE MchCod=%ld"
" WHERE MchCod=%ld" " GROUP BY Score"
" GROUP BY Score" " ORDER BY Score) AS Scores",
" ORDER BY Score) AS Scores",
Match->MchCod)) Match->MchCod))
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -3515,7 +3530,7 @@ static void Mch_ShowMatchScore (const struct Mch_Match *Match)
DB_QuerySELECT (&mysql_res,"can not get scores", DB_QuerySELECT (&mysql_res,"can not get scores",
"SELECT Score," // row[0] "SELECT Score," // row[0]
"COUNT(*) AS NumUsrs" // row[1] "COUNT(*) AS NumUsrs" // row[1]
" FROM mch_results" " FROM mch_results"
" WHERE MchCod=%ld" " WHERE MchCod=%ld"
" GROUP BY Score" " GROUP BY Score"
" ORDER BY Score DESC", " ORDER BY Score DESC",
@ -3832,7 +3847,8 @@ static bool Mch_GetIfMatchIsBeingPlayed (long MchCod)
/***** Get if a match is being played or not *****/ /***** Get if a match is being played or not *****/
return return
(bool) (DB_QueryCOUNT ("can not get if match is being played", (bool) (DB_QueryCOUNT ("can not get if match is being played",
"SELECT COUNT(*) FROM mch_playing" "SELECT COUNT(*)"
" FROM mch_playing"
" WHERE MchCod=%ld", " WHERE MchCod=%ld",
MchCod) != 0); MchCod) != 0);
} }
@ -3846,7 +3862,8 @@ static void Mch_GetNumPlayers (struct Mch_Match *Match)
/***** Get number of players who are playing a match *****/ /***** Get number of players who are playing a match *****/
Match->Status.NumPlayers = Match->Status.NumPlayers =
(unsigned) DB_QueryCOUNT ("can not get number of players", (unsigned) DB_QueryCOUNT ("can not get number of players",
"SELECT COUNT(*) FROM mch_players" "SELECT COUNT(*)"
" FROM mch_players"
" WHERE MchCod=%ld", " WHERE MchCod=%ld",
Match->MchCod); Match->MchCod);
} }
@ -4101,11 +4118,13 @@ void Mch_GetQstAnsFromDB (long MchCod,long UsrCod,unsigned QstInd,
NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get user's answer to a match question", NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get user's answer to a match question",
"SELECT NumOpt," // row[0] "SELECT NumOpt," // row[0]
"AnsInd" // row[1] "AnsInd" // row[1]
" FROM mch_answers" " FROM mch_answers"
" WHERE MchCod=%ld" " WHERE MchCod=%ld"
" AND UsrCod=%ld" " AND UsrCod=%ld"
" AND QstInd=%u", " AND QstInd=%u",
MchCod,UsrCod,QstInd); MchCod,
UsrCod,
QstInd);
if (NumRows) // Answer found... if (NumRows) // Answer found...
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -4255,18 +4274,18 @@ void Mch_GetMatchQuestionsFromDB (struct MchPrn_Print *Print)
/***** Get questions and answers of a match result *****/ /***** Get questions and answers of a match result *****/
Print->NumQsts.All = (unsigned) Print->NumQsts.All = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get questions and answers" DB_QuerySELECT (&mysql_res,"can not get questions and answers"
" of a match result", " of a match result",
"SELECT gam_questions.QstCod," // row[0] "SELECT gam_questions.QstCod," // row[0]
"gam_questions.QstInd," // row[1] "gam_questions.QstInd," // row[1]
"mch_indexes.Indexes" // row[2] "mch_indexes.Indexes" // row[2]
" FROM mch_matches,gam_questions,mch_indexes" " FROM mch_matches,gam_questions,mch_indexes"
" WHERE mch_matches.MchCod=%ld" " WHERE mch_matches.MchCod=%ld"
" AND mch_matches.GamCod=gam_questions.GamCod" " AND mch_matches.GamCod=gam_questions.GamCod"
" AND mch_matches.MchCod=mch_indexes.MchCod" " AND mch_matches.MchCod=mch_indexes.MchCod"
" AND gam_questions.QstInd=mch_indexes.QstInd" " AND gam_questions.QstInd=mch_indexes.QstInd"
" ORDER BY gam_questions.QstInd", " ORDER BY gam_questions.QstInd",
Print->MchCod); Print->MchCod);
for (NumQst = 0, Print->NumQsts.NotBlank = 0; for (NumQst = 0, Print->NumQsts.NotBlank = 0;
NumQst < Print->NumQsts.All; NumQst < Print->NumQsts.All;
NumQst++) NumQst++)
@ -4340,11 +4359,14 @@ unsigned Mch_GetNumUsrsWhoAnsweredQst (long MchCod,unsigned QstInd)
{ {
/***** Get number of users who answered /***** Get number of users who answered
a question in a match from database *****/ a question in a match from database *****/
return return (unsigned)
(unsigned) DB_QueryCOUNT ("can not get number of users who answered a question", DB_QueryCOUNT ("can not get number of users who answered a question",
"SELECT COUNT(*) FROM mch_answers" "SELECT COUNT(*)"
" WHERE MchCod=%ld AND QstInd=%u", " FROM mch_answers"
MchCod,QstInd); " WHERE MchCod=%ld"
" AND QstInd=%u",
MchCod,
QstInd);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -4355,11 +4377,16 @@ unsigned Mch_GetNumUsrsWhoHaveChosenAns (long MchCod,unsigned QstInd,unsigned An
{ {
/***** Get number of users who have chosen /***** Get number of users who have chosen
an answer of a question from database *****/ an answer of a question from database *****/
return return (unsigned)
(unsigned) DB_QueryCOUNT ("can not get number of users who have chosen an answer", DB_QueryCOUNT ("can not get number of users who have chosen an answer",
"SELECT COUNT(*) FROM mch_answers" "SELECT COUNT(*)"
" WHERE MchCod=%ld AND QstInd=%u AND AnsInd=%u", " FROM mch_answers"
MchCod,QstInd,AnsInd); " WHERE MchCod=%ld"
" AND QstInd=%u"
" AND AnsInd=%u",
MchCod,
QstInd,
AnsInd);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -4371,11 +4398,12 @@ static unsigned Mch_GetNumUsrsWhoHavePlayedMch (long MchCod)
/***** Get number of users who have played the match /***** Get number of users who have played the match
(users who have a result for this match, even blank result) (users who have a result for this match, even blank result)
from database *****/ from database *****/
return return (unsigned)
(unsigned) DB_QueryCOUNT ("can not get number of users who have played a match", DB_QueryCOUNT ("can not get number of users who have played a match",
"SELECT COUNT(*) FROM mch_results" "SELECT COUNT(*)"
" WHERE MchCod=%ld", " FROM mch_results"
MchCod); " WHERE MchCod=%ld",
MchCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -101,17 +101,20 @@ static void MchPrn_UpdateMyMatchPrintInDB (struct MchPrn_Print *Print)
{ {
Str_SetDecimalPointToUS (); // To print the floating point as a dot Str_SetDecimalPointToUS (); // To print the floating point as a dot
if (DB_QueryCOUNT ("can not get if match result exists", if (DB_QueryCOUNT ("can not get if match result exists",
"SELECT COUNT(*) FROM mch_results" "SELECT COUNT(*)"
" WHERE MchCod=%ld AND UsrCod=%ld", " FROM mch_results"
" WHERE MchCod=%ld"
" AND UsrCod=%ld",
Print->MchCod,Print->UsrCod)) // Match print exists Print->MchCod,Print->UsrCod)) // Match print exists
/* Update result */ /* Update result */
DB_QueryUPDATE ("can not update match result", DB_QueryUPDATE ("can not update match result",
"UPDATE mch_results" "UPDATE mch_results"
" SET EndTime=NOW()," " SET EndTime=NOW(),"
"NumQsts=%u," "NumQsts=%u,"
"NumQstsNotBlank=%u," "NumQstsNotBlank=%u,"
"Score='%.15lg'" "Score='%.15lg'"
" WHERE MchCod=%ld AND UsrCod=%ld", " WHERE MchCod=%ld"
" AND UsrCod=%ld",
Print->NumQsts.All, Print->NumQsts.All,
Print->NumQsts.NotBlank, Print->NumQsts.NotBlank,
Print->Score, Print->Score,
@ -153,12 +156,14 @@ void MchPrn_GetMatchPrintDataByMchCodAndUsrCod (struct MchPrn_Print *Print)
"mch_results.NumQsts," // row[3] "mch_results.NumQsts," // row[3]
"mch_results.NumQstsNotBlank," // row[4] "mch_results.NumQstsNotBlank," // row[4]
"mch_results.Score" // row[5] "mch_results.Score" // row[5]
" FROM mch_results,mch_matches,gam_games" " FROM mch_results,"
"mch_matches,"
"gam_games"
" WHERE mch_results.MchCod=%ld" " WHERE mch_results.MchCod=%ld"
" AND mch_results.UsrCod=%ld" " AND mch_results.UsrCod=%ld"
" AND mch_results.MchCod=mch_matches.MchCod" " AND mch_results.MchCod=mch_matches.MchCod"
" AND mch_matches.GamCod=gam_games.GamCod" " AND mch_matches.GamCod=gam_games.GamCod"
" AND gam_games.CrsCod=%ld", // Extra check " AND gam_games.CrsCod=%ld", // Extra check
Print->MchCod,Print->UsrCod, Print->MchCod,Print->UsrCod,
Gbl.Hierarchy.Crs.CrsCod) == 1) Gbl.Hierarchy.Crs.CrsCod) == 1)
{ {

View File

@ -402,14 +402,16 @@ static void MchRes_ListAllMchResultsInGam (struct Gam_Games *Games,long GamCod)
/***** Get all users who have answered any match question in this game *****/ /***** Get all users who have answered any match question in this game *****/
NumUsrs = DB_QuerySELECT (&mysql_res,"can not get users in game", NumUsrs = DB_QuerySELECT (&mysql_res,"can not get users in game",
"SELECT users.UsrCod FROM" "SELECT users.UsrCod" // row[0]
" (SELECT DISTINCT mch_results.UsrCod AS UsrCod" // row[0] " FROM (SELECT DISTINCT mch_results.UsrCod AS UsrCod"
" FROM mch_results,mch_matches,gam_games" " FROM mch_results,"
" WHERE mch_matches.GamCod=%ld" "mch_matches,"
" AND mch_matches.MchCod=mch_results.MchCod" "gam_games"
" AND mch_matches.GamCod=gam_games.GamCod" " WHERE mch_matches.GamCod=%ld"
" AND gam_games.CrsCod=%ld)" // Extra check " AND mch_matches.MchCod=mch_results.MchCod"
" AS users,usr_data" " AND mch_matches.GamCod=gam_games.GamCod"
" AND gam_games.CrsCod=%ld) AS users," // Extra check
"usr_data"
" WHERE users.UsrCod=usr_data.UsrCod" " WHERE users.UsrCod=usr_data.UsrCod"
" ORDER BY usr_data.Surname1," " ORDER BY usr_data.Surname1,"
"usr_data.Surname2," "usr_data.Surname2,"
@ -496,14 +498,16 @@ static void MchRes_ListAllMchResultsInMch (struct Gam_Games *Games,long MchCod)
/***** Get all users who have answered any match question in this game *****/ /***** Get all users who have answered any match question in this game *****/
NumUsrs = DB_QuerySELECT (&mysql_res,"can not get users in match", NumUsrs = DB_QuerySELECT (&mysql_res,"can not get users in match",
"SELECT users.UsrCod FROM" "SELECT users.UsrCod"
" (SELECT mch_results.UsrCod AS UsrCod" // row[0] " FROM (SELECT mch_results.UsrCod AS UsrCod" // row[0]
" FROM mch_results,mch_matches,gam_games" " FROM mch_results,"
" WHERE mch_results.MchCod=%ld" "mch_matches,"
" AND mch_results.MchCod=mch_matches.MchCod" "gam_games"
" AND mch_matches.GamCod=gam_games.GamCod" " WHERE mch_results.MchCod=%ld"
" AND gam_games.CrsCod=%ld)" // Extra check " AND mch_results.MchCod=mch_matches.MchCod"
" AS users,usr_data" " AND mch_matches.GamCod=gam_games.GamCod"
" AND gam_games.CrsCod=%ld) AS users," // Extra check
"usr_data"
" WHERE users.UsrCod=usr_data.UsrCod" " WHERE users.UsrCod=usr_data.UsrCod"
" ORDER BY usr_data.Surname1," " ORDER BY usr_data.Surname1,"
"usr_data.Surname2," "usr_data.Surname2,"
@ -850,15 +854,17 @@ static void MchRes_ShowMchResults (struct Gam_Games *Games,
/***** Make database query *****/ /***** Make database query *****/
NumResults = NumResults =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get matches results", (unsigned) DB_QuerySELECT (&mysql_res,"can not get matches results",
"SELECT mch_results.MchCod" // row[0] "SELECT mch_results.MchCod" // row[0]
" FROM mch_results,mch_matches,gam_games" " FROM mch_results,"
"mch_matches,"
"gam_games"
" WHERE mch_results.UsrCod=%ld" " WHERE mch_results.UsrCod=%ld"
"%s" // Match subquery "%s" // Match subquery
" AND mch_results.MchCod=mch_matches.MchCod" " AND mch_results.MchCod=mch_matches.MchCod"
"%s" // Games subquery "%s" // Games subquery
" AND mch_matches.GamCod=gam_games.GamCod" " AND mch_matches.GamCod=gam_games.GamCod"
"%s" // Hidden games subquery "%s" // Hidden games subquery
" AND gam_games.CrsCod=%ld" // Extra check " AND gam_games.CrsCod=%ld" // Extra check
" ORDER BY mch_matches.Title", " ORDER BY mch_matches.Title",
UsrDat->UsrCod, UsrDat->UsrCod,
MchSubQuery, MchSubQuery,

File diff suppressed because it is too large Load Diff

View File

@ -225,9 +225,12 @@ void Net_ShowWebsAndSocialNets (const struct UsrData *UsrDat)
{ {
/***** Check if exists the web / social network for this user *****/ /***** Check if exists the web / social network for this user *****/
if (DB_QuerySELECT (&mysql_res,"can not get user's web / social network", if (DB_QuerySELECT (&mysql_res,"can not get user's web / social network",
"SELECT URL FROM usr_webs" "SELECT URL"
" WHERE UsrCod=%ld AND Web='%s'", " FROM usr_webs"
UsrDat->UsrCod,Net_WebsAndSocialNetworksDB[NumURL])) " WHERE UsrCod=%ld"
" AND Web='%s'",
UsrDat->UsrCod,
Net_WebsAndSocialNetworksDB[NumURL]))
{ {
/* Get URL */ /* Get URL */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -301,8 +304,10 @@ void Net_ShowFormMyWebsAndSocialNets (void)
{ {
/***** Get user's web / social network from database *****/ /***** Get user's web / social network from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get user's web / social network", if (DB_QuerySELECT (&mysql_res,"can not get user's web / social network",
"SELECT URL FROM usr_webs" "SELECT URL"
" WHERE UsrCod=%ld AND Web='%s'", " FROM usr_webs"
" WHERE UsrCod=%ld"
" AND Web='%s'",
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
Net_WebsAndSocialNetworksDB[NumURL])) Net_WebsAndSocialNetworksDB[NumURL]))
{ {
@ -459,9 +464,10 @@ void Net_ShowWebAndSocialNetworksStats (void)
" with webs / social networks", " with webs / social networks",
"SELECT Web," // row[0] "SELECT Web," // row[0]
"COUNT(*) AS N" // row[1] "COUNT(*) AS N" // row[1]
" FROM usr_webs" " FROM usr_webs"
" GROUP BY Web" " GROUP BY Web"
" ORDER BY N DESC,Web"); " ORDER BY N DESC,"
"Web");
break; break;
case Hie_Lvl_CTY: case Hie_Lvl_CTY:
NumRows = (unsigned) NumRows = (unsigned)

View File

@ -121,8 +121,11 @@ bool Nck_GetNicknameFromUsrCod (long UsrCod,
/***** Get current (last updated) user's nickname from database *****/ /***** Get current (last updated) user's nickname from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get nickname", if (DB_QuerySELECT (&mysql_res,"can not get nickname",
"SELECT Nickname FROM usr_nicknames" "SELECT Nickname"
" WHERE UsrCod=%ld ORDER BY CreatTime DESC LIMIT 1", " FROM usr_nicknames"
" WHERE UsrCod=%ld"
" ORDER BY CreatTime DESC"
" LIMIT 1",
UsrCod)) UsrCod))
{ {
/* Get nickname */ /* Get nickname */
@ -166,9 +169,10 @@ long Nck_GetUsrCodFromNickname (const char *Nickname)
/* Check if user code from table usr_nicknames is also in table usr_data */ /* Check if user code from table usr_nicknames is also in table usr_data */
if (DB_QuerySELECT (&mysql_res,"can not get user's code", if (DB_QuerySELECT (&mysql_res,"can not get user's code",
"SELECT usr_nicknames.UsrCod" "SELECT usr_nicknames.UsrCod"
" FROM usr_nicknames,usr_data" " FROM usr_nicknames,"
"usr_data"
" WHERE usr_nicknames.Nickname='%s'" " WHERE usr_nicknames.Nickname='%s'"
" AND usr_nicknames.UsrCod=usr_data.UsrCod", " AND usr_nicknames.UsrCod=usr_data.UsrCod",
NickWithoutArr)) NickWithoutArr))
{ {
/* Get row */ /* Get row */
@ -237,7 +241,8 @@ static void Nck_ShowFormChangeUsrNickname (bool ItsMe,
/***** Get my nicknames *****/ /***** Get my nicknames *****/
NumNicks = NumNicks =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get nicknames of a user", (unsigned) DB_QuerySELECT (&mysql_res,"can not get nicknames of a user",
"SELECT Nickname FROM usr_nicknames" "SELECT Nickname"
" FROM usr_nicknames"
" WHERE UsrCod=%ld" " WHERE UsrCod=%ld"
" ORDER BY CreatTime DESC", " ORDER BY CreatTime DESC",
UsrDat->UsrCod); UsrDat->UsrCod);
@ -577,14 +582,20 @@ static void Nck_UpdateUsrNick (struct UsrData *UsrDat)
{ {
/***** Check if the new nickname matches any of my old nicknames *****/ /***** Check if the new nickname matches any of my old nicknames *****/
if (!DB_QueryCOUNT ("can not check if nickname already existed", if (!DB_QueryCOUNT ("can not check if nickname already existed",
"SELECT COUNT(*) FROM usr_nicknames" "SELECT COUNT(*)"
" WHERE UsrCod=%ld AND Nickname='%s'", " FROM usr_nicknames"
UsrDat->UsrCod,NewNickWithoutArr)) // No matches " WHERE UsrCod=%ld"
" AND Nickname='%s'",
UsrDat->UsrCod,
NewNickWithoutArr)) // No matches
/***** Check if the new nickname matches any of the nicknames of other users *****/ /***** Check if the new nickname matches any of the nicknames of other users *****/
if (DB_QueryCOUNT ("can not check if nickname already existed", if (DB_QueryCOUNT ("can not check if nickname already existed",
"SELECT COUNT(*) FROM usr_nicknames" "SELECT COUNT(*)"
" WHERE Nickname='%s' AND UsrCod<>%ld", " FROM usr_nicknames"
NewNickWithoutArr,UsrDat->UsrCod)) // A nickname of another user is the same that user's nickname " WHERE Nickname='%s'"
" AND UsrCod<>%ld",
NewNickWithoutArr,
UsrDat->UsrCod)) // A nickname of another user is the same that user's nickname
Ale_CreateAlert (Ale_WARNING,Nck_NICKNAME_SECTION_ID, Ale_CreateAlert (Ale_WARNING,Nck_NICKNAME_SECTION_ID,
Txt_The_nickname_X_had_been_registered_by_another_user, Txt_The_nickname_X_had_been_registered_by_another_user,
NewNickWithoutArr); NewNickWithoutArr);

View File

@ -337,17 +337,19 @@ void Not_RemoveNotice (void)
"CreatTime," "CreatTime,"
"Content," "Content,"
"NumNotif" "NumNotif"
" FROM not_notices" " FROM not_notices"
" WHERE NotCod=%ld" " WHERE NotCod=%ld"
" AND CrsCod=%ld", " AND CrsCod=%ld",
NotCod,Gbl.Hierarchy.Crs.CrsCod); NotCod,
Gbl.Hierarchy.Crs.CrsCod);
/* Remove notice */ /* Remove notice */
DB_QueryDELETE ("can not remove notice", DB_QueryDELETE ("can not remove notice",
"DELETE FROM not_notices" "DELETE FROM not_notices"
" WHERE NotCod=%ld" " WHERE NotCod=%ld"
" AND CrsCod=%ld", " AND CrsCod=%ld",
NotCod,Gbl.Hierarchy.Crs.CrsCod); NotCod,
Gbl.Hierarchy.Crs.CrsCod);
/***** Mark possible notifications as removed *****/ /***** Mark possible notifications as removed *****/
Ntf_MarkNotifAsRemoved (Ntf_EVENT_NOTICE,NotCod); Ntf_MarkNotifAsRemoved (Ntf_EVENT_NOTICE,NotCod);
@ -584,8 +586,10 @@ static void Not_GetDataAndShowNotice (long NotCod)
"Content," // row[2] "Content," // row[2]
"Status" // row[3] "Status" // row[3]
" FROM not_notices" " FROM not_notices"
" WHERE NotCod=%ld AND CrsCod=%ld", " WHERE NotCod=%ld"
NotCod,Gbl.Hierarchy.Crs.CrsCod)) " AND CrsCod=%ld",
NotCod,
Gbl.Hierarchy.Crs.CrsCod))
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -958,17 +962,17 @@ unsigned Not_GetNumNoticesDeleted (Hie_Lvl_Level_t Scope,unsigned *NumNotif)
DB_QuerySELECT (&mysql_res,"can not get number of deleted notices", DB_QuerySELECT (&mysql_res,"can not get number of deleted notices",
"SELECT COUNT(*)," // row[0] "SELECT COUNT(*)," // row[0]
"SUM(NumNotif)" // row[1] "SUM(NumNotif)" // row[1]
" FROM not_deleted"); " FROM not_deleted");
break; break;
case Hie_Lvl_CTY: case Hie_Lvl_CTY:
DB_QuerySELECT (&mysql_res,"can not get number of deleted notices", DB_QuerySELECT (&mysql_res,"can not get number of deleted notices",
"SELECT COUNT(*)," // row[0] "SELECT COUNT(*)," // row[0]
"SUM(not_deleted.NumNotif)" // row[1] "SUM(not_deleted.NumNotif)" // row[1]
" FROM ins_instits," " FROM ins_instits,"
"ctr_centers," "ctr_centers,"
"deg_degrees," "deg_degrees,"
"crs_courses," "crs_courses,"
"not_deleted" "not_deleted"
" WHERE ins_instits.CtyCod=%ld" " WHERE ins_instits.CtyCod=%ld"
" AND ins_instits.InsCod=ctr_centers.InsCod" " AND ins_instits.InsCod=ctr_centers.InsCod"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod" " AND ctr_centers.CtrCod=deg_degrees.CtrCod"

View File

@ -1354,12 +1354,12 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod)
" to be notified", " to be notified",
"SELECT DISTINCT(PublisherCod)" // row[0] "SELECT DISTINCT(PublisherCod)" // row[0]
" FROM tml_pubs" " FROM tml_pubs"
" WHERE NotCod=" " WHERE NotCod=(SELECT NotCod"
"(SELECT NotCod" " FROM tml_pubs"
" FROM tml_pubs" " WHERE PubCod=%ld)"
" WHERE PubCod=%ld)" " AND PublisherCod<>%ld",
" AND PublisherCod<>%ld", Cod,
Cod,Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod);
break; break;
case Ntf_EVENT_TL_FAV: // New favourite to one of my social notes or comments case Ntf_EVENT_TL_FAV: // New favourite to one of my social notes or comments
case Ntf_EVENT_TL_SHARE: // New sharing of one of my social notes case Ntf_EVENT_TL_SHARE: // New sharing of one of my social notes
@ -1404,11 +1404,12 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod)
" to be notified", " to be notified",
"SELECT DISTINCT(UsrCod)" // row[0] "SELECT DISTINCT(UsrCod)" // row[0]
" FROM for_posts" " FROM for_posts"
" WHERE ThrCod = (SELECT ThrCod" " WHERE ThrCod=(SELECT ThrCod"
" FROM for_posts" " FROM for_posts"
" WHERE PstCod=%ld)" " WHERE PstCod=%ld)"
" AND UsrCod<>%ld", " AND UsrCod<>%ld",
Cod,Gbl.Usrs.Me.UsrDat.UsrCod); Cod,
Gbl.Usrs.Me.UsrDat.UsrCod);
break; break;
case Ntf_EVENT_MESSAGE: // This function should not be called in this case case Ntf_EVENT_MESSAGE: // This function should not be called in this case
return 0; return 0;

View File

@ -120,7 +120,7 @@ bool Pwd_CheckPendingPassword (void)
/***** Get pending password from database *****/ /***** Get pending password from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get pending password", if (DB_QuerySELECT (&mysql_res,"can not get pending password",
"SELECT PendingPassword" "SELECT PendingPassword" // row[0]
" FROM usr_pending_passwd" " FROM usr_pending_passwd"
" WHERE UsrCod=%ld", " WHERE UsrCod=%ld",
Gbl.Usrs.Me.UsrDat.UsrCod)) Gbl.Usrs.Me.UsrDat.UsrCod))
@ -594,9 +594,12 @@ static unsigned Pwd_GetNumOtherUsrsWhoUseThisPassword (const char *EncryptedPass
/***** Get number of other users who use a password from database *****/ /***** Get number of other users who use a password from database *****/
NumUsrs = NumUsrs =
(unsigned) DB_QueryCOUNT ("can not check if a password is trivial", (unsigned) DB_QueryCOUNT ("can not check if a password is trivial",
"SELECT COUNT(*) FROM usr_data" "SELECT COUNT(*)"
" WHERE Password='%s'%s", " FROM usr_data"
EncryptedPassword,SubQuery); " WHERE Password='%s'"
"%s",
EncryptedPassword,
SubQuery);
/***** Free subquery *****/ /***** Free subquery *****/
if (UsrCod > 0) if (UsrCod > 0)

View File

@ -1502,7 +1502,9 @@ void Pho_RemoveObsoleteStatDegrees (void)
{ {
DB_QueryDELETE ("can not remove old degrees from stats", DB_QueryDELETE ("can not remove old degrees from stats",
"DELETE FROM sta_degrees" "DELETE FROM sta_degrees"
" WHERE DegCod NOT IN (SELECT DegCod FROM deg_degrees)"); " WHERE DegCod NOT IN"
" (SELECT DegCod"
" FROM deg_degrees)");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1520,7 +1522,8 @@ static long Pho_GetTimeAvgPhotoWasComputed (long DegCod)
NumRows = DB_QuerySELECT (&mysql_res,"can not get last time" NumRows = DB_QuerySELECT (&mysql_res,"can not get last time"
" an average photo was computed", " an average photo was computed",
"SELECT MIN(UNIX_TIMESTAMP(TimeAvgPhoto))" "SELECT MIN(UNIX_TIMESTAMP(TimeAvgPhoto))"
" FROM sta_degrees WHERE DegCod=%ld", " FROM sta_degrees"
" WHERE DegCod=%ld",
DegCod); DegCod);
if (NumRows == 1) if (NumRows == 1)
@ -1555,7 +1558,8 @@ static long Pho_GetTimeToComputeAvgPhoto (long DegCod)
/***** Get time to compute average photo from database *****/ /***** Get time to compute average photo from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get time to compute" NumRows = DB_QuerySELECT (&mysql_res,"can not get time to compute"
" average photo", " average photo",
"SELECT TimeToComputeAvgPhoto FROM sta_degrees" "SELECT TimeToComputeAvgPhoto" // row[0]
" FROM sta_degrees"
" WHERE DegCod=%ld", " WHERE DegCod=%ld",
DegCod); DegCod);
@ -2100,10 +2104,12 @@ static void Pho_GetMaxStdsPerDegree (struct Pho_DegPhotos *DegPhotos)
/***** Get maximum number of students in a degree from database *****/ /***** Get maximum number of students in a degree from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get maximum" NumRows = DB_QuerySELECT (&mysql_res,"can not get maximum"
" number of students in a degree", " number of students in a degree",
"SELECT MAX(NumStds),MAX(NumStdsWithPhoto)," "SELECT MAX(NumStds)," // row[0]
"MAX(NumStdsWithPhoto/NumStds)" "MAX(NumStdsWithPhoto)," // row[1]
" FROM sta_degrees" "MAX(NumStdsWithPhoto/NumStds)" // row[2]
" WHERE Sex='all' AND NumStds>0"); " FROM sta_degrees"
" WHERE Sex='all'"
" AND NumStds>0");
/***** Count number of rows in result *****/ /***** Count number of rows in result *****/
if (NumRows == 1) if (NumRows == 1)
@ -2337,10 +2343,10 @@ static unsigned long Pho_BuildQueryOfDegrees (Pho_HowOrderDegrees_t HowOrderDegr
case Pho_NUMBER_OF_STUDENTS: case Pho_NUMBER_OF_STUDENTS:
NumDegs = DB_QuerySELECT (mysql_res,"can not get degrees", NumDegs = DB_QuerySELECT (mysql_res,"can not get degrees",
"SELECT deg_degrees.DegCod" "SELECT deg_degrees.DegCod"
" FROM deg_degrees,sta_degrees" " FROM deg_degrees,sta_degrees"
" WHERE sta_degrees.Sex='all'" " WHERE sta_degrees.Sex='all'"
" AND sta_degrees.NumStds>0" " AND sta_degrees.NumStds>0"
" AND deg_degrees.DegCod=sta_degrees.DegCod" " AND deg_degrees.DegCod=sta_degrees.DegCod"
" ORDER BY sta_degrees.NumStds DESC," " ORDER BY sta_degrees.NumStds DESC,"
"sta_degrees.NumStdsWithPhoto DESC," "sta_degrees.NumStdsWithPhoto DESC,"
"deg_degrees.ShortName"); "deg_degrees.ShortName");
@ -2348,10 +2354,10 @@ static unsigned long Pho_BuildQueryOfDegrees (Pho_HowOrderDegrees_t HowOrderDegr
case Pho_NUMBER_OF_PHOTOS: case Pho_NUMBER_OF_PHOTOS:
NumDegs = DB_QuerySELECT (mysql_res,"can not get degrees", NumDegs = DB_QuerySELECT (mysql_res,"can not get degrees",
"SELECT deg_degrees.DegCod" "SELECT deg_degrees.DegCod"
" FROM deg_degrees,sta_degrees" " FROM deg_degrees,sta_degrees"
" WHERE sta_degrees.Sex='all'" " WHERE sta_degrees.Sex='all'"
" AND sta_degrees.NumStds>0" " AND sta_degrees.NumStds>0"
" AND deg_degrees.DegCod=sta_degrees.DegCod" " AND deg_degrees.DegCod=sta_degrees.DegCod"
" ORDER BY sta_degrees.NumStdsWithPhoto DESC," " ORDER BY sta_degrees.NumStdsWithPhoto DESC,"
"sta_degrees.NumStds DESC," "sta_degrees.NumStds DESC,"
"deg_degrees.ShortName"); "deg_degrees.ShortName");
@ -2359,10 +2365,10 @@ static unsigned long Pho_BuildQueryOfDegrees (Pho_HowOrderDegrees_t HowOrderDegr
case Pho_PERCENT: case Pho_PERCENT:
NumDegs = DB_QuerySELECT (mysql_res,"can not get degrees", NumDegs = DB_QuerySELECT (mysql_res,"can not get degrees",
"SELECT deg_degrees.DegCod" "SELECT deg_degrees.DegCod"
" FROM deg_degrees,sta_degrees" " FROM deg_degrees,sta_degrees"
" WHERE sta_degrees.Sex='all'" " WHERE sta_degrees.Sex='all'"
" AND sta_degrees.NumStds>0" " AND sta_degrees.NumStds>0"
" AND deg_degrees.DegCod=sta_degrees.DegCod" " AND deg_degrees.DegCod=sta_degrees.DegCod"
" ORDER BY sta_degrees.NumStdsWithPhoto/" " ORDER BY sta_degrees.NumStdsWithPhoto/"
"sta_degrees.NumStds DESC," "sta_degrees.NumStds DESC,"
"deg_degrees.ShortName"); "deg_degrees.ShortName");
@ -2370,10 +2376,10 @@ static unsigned long Pho_BuildQueryOfDegrees (Pho_HowOrderDegrees_t HowOrderDegr
case Pho_DEGREE_NAME: case Pho_DEGREE_NAME:
NumDegs = DB_QuerySELECT (mysql_res,"can not get degrees", NumDegs = DB_QuerySELECT (mysql_res,"can not get degrees",
"SELECT deg_degrees.DegCod" "SELECT deg_degrees.DegCod"
" FROM deg_degrees,sta_degrees" " FROM deg_degrees,sta_degrees"
" WHERE sta_degrees.Sex='all'" " WHERE sta_degrees.Sex='all'"
" AND sta_degrees.NumStds>0" " AND sta_degrees.NumStds>0"
" AND deg_degrees.DegCod=sta_degrees.DegCod" " AND deg_degrees.DegCod=sta_degrees.DegCod"
" ORDER BY deg_degrees.ShortName"); " ORDER BY deg_degrees.ShortName");
break; break;
} }
@ -2395,10 +2401,13 @@ static void Pho_GetNumStdsInDegree (long DegCod,Usr_Sex_t Sex,int *NumStds,int *
/***** Get the number of students in a degree from database *****/ /***** Get the number of students in a degree from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get the number of students" NumRows = DB_QuerySELECT (&mysql_res,"can not get the number of students"
" in a degree", " in a degree",
"SELECT NumStds,NumStdsWithPhoto" "SELECT NumStds,"
" FROM sta_degrees" "NumStdsWithPhoto"
" WHERE DegCod=%ld AND Sex='%s'", " FROM sta_degrees"
DegCod,Usr_StringsSexDB[Sex]); " WHERE DegCod=%ld"
" AND Sex='%s'",
DegCod,
Usr_StringsSexDB[Sex]);
if (NumRows == 0) if (NumRows == 0)
*NumStds = *NumStdsWithPhoto = -1; *NumStds = *NumStdsWithPhoto = -1;

View File

@ -464,9 +464,9 @@ void Plc_GetDataOfPlaceByCod (struct Plc_Place *Plc)
{ {
/***** Get data of a place from database *****/ /***** Get data of a place from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a place", NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a place",
"(SELECT plc_places.ShortName," "(SELECT plc_places.ShortName," // row[0]
"plc_places.FullName," "plc_places.FullName," // row[1]
"COUNT(*)" "COUNT(*)" // row[2]
" FROM plc_places," " FROM plc_places,"
"ctr_centers" "ctr_centers"
" WHERE plc_places.PlcCod=%ld" " WHERE plc_places.PlcCod=%ld"
@ -474,9 +474,9 @@ void Plc_GetDataOfPlaceByCod (struct Plc_Place *Plc)
" AND ctr_centers.PlcCod=%ld" " AND ctr_centers.PlcCod=%ld"
" GROUP BY plc_places.PlcCod)" " GROUP BY plc_places.PlcCod)"
" UNION " " UNION "
"(SELECT ShortName," "(SELECT ShortName," // row[0]
"FullName," "FullName," // row[1]
"0" "0" // row[2]
" FROM plc_places" " FROM plc_places"
" WHERE PlcCod=%ld" " WHERE PlcCod=%ld"
" AND PlcCod NOT IN" " AND PlcCod NOT IN"

View File

@ -591,7 +591,8 @@ static bool Plg_CheckIfPluginNameExists (const char *Name,long PlgCod)
/***** Get number of plugins with a name from database *****/ /***** Get number of plugins with a name from database *****/
return (DB_QueryCOUNT ("can not check if the name of a plugin" return (DB_QueryCOUNT ("can not check if the name of a plugin"
" already existed", " already existed",
"SELECT COUNT(*) FROM plg_plugins" "SELECT COUNT(*)"
" FROM plg_plugins"
" WHERE Name='%s'" " WHERE Name='%s'"
" AND PlgCod<>%ld", " AND PlgCod<>%ld",
Name,PlgCod) != 0); Name,PlgCod) != 0);

View File

@ -887,10 +887,12 @@ static unsigned long Prf_GetRankingFigure (long UsrCod,const char *FieldName)
/***** Select number of rows with figure /***** Select number of rows with figure
greater than the figure of this user *****/ greater than the figure of this user *****/
return DB_QueryCOUNT ("can not get ranking using a figure", return DB_QueryCOUNT ("can not get ranking using a figure",
"SELECT COUNT(*)+1 FROM usr_figures" "SELECT COUNT(*)+1"
" FROM usr_figures"
" WHERE UsrCod<>%ld" // Really not necessary here " WHERE UsrCod<>%ld" // Really not necessary here
" AND %s>" " AND %s>(SELECT %s"
"(SELECT %s FROM usr_figures WHERE UsrCod=%ld)", " FROM usr_figures"
" WHERE UsrCod=%ld)",
UsrCod,FieldName,FieldName,UsrCod); UsrCod,FieldName,FieldName,UsrCod);
} }
@ -902,7 +904,8 @@ static unsigned long Prf_GetNumUsrsWithFigure (const char *FieldName)
{ {
/***** Select number of rows with values already calculated *****/ /***** Select number of rows with values already calculated *****/
return DB_QueryCOUNT ("can not get number of users with a figure", return DB_QueryCOUNT ("can not get number of users with a figure",
"SELECT COUNT(*) FROM usr_figures" "SELECT COUNT(*)"
" FROM usr_figures"
" WHERE %s>=0", " WHERE %s>=0",
FieldName); FieldName);
} }
@ -916,20 +919,18 @@ static unsigned long Prf_GetRankingNumClicksPerDay (long UsrCod)
/***** Select number of rows with number of clicks per day /***** Select number of rows with number of clicks per day
greater than the clicks per day of this user *****/ greater than the clicks per day of this user *****/
return DB_QueryCOUNT ("can not get ranking using number of clicks per day", return DB_QueryCOUNT ("can not get ranking using number of clicks per day",
"SELECT COUNT(*)+1 FROM" "SELECT COUNT(*)+1"
" (SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1)" " FROM (SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1) AS NumClicksPerDay"
" AS NumClicksPerDay" " FROM usr_figures"
" FROM usr_figures" " WHERE UsrCod<>%ld" // Necessary because the following comparison is not exact in floating point
" WHERE UsrCod<>%ld" // Necessary because the following comparison is not exact in floating point " AND NumClicks>0"
" AND NumClicks>0" " AND FirstClickTime>FROM_UNIXTIME(0)) AS TableNumClicksPerDay"
" AND FirstClickTime>FROM_UNIXTIME(0))"
" AS TableNumClicksPerDay"
" WHERE NumClicksPerDay>" " WHERE NumClicksPerDay>"
"(SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1)" "(SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1)"
" FROM usr_figures" " FROM usr_figures"
" WHERE UsrCod=%ld" " WHERE UsrCod=%ld"
" AND NumClicks>0" " AND NumClicks>0"
" AND FirstClickTime>FROM_UNIXTIME(0))", " AND FirstClickTime>FROM_UNIXTIME(0))",
UsrCod,UsrCod); UsrCod,UsrCod);
} }
@ -942,9 +943,10 @@ static unsigned long Prf_GetNumUsrsWithNumClicksPerDay (void)
/***** Select number of rows with values already calculated *****/ /***** Select number of rows with values already calculated *****/
return DB_QueryCOUNT ("can not get number of users" return DB_QueryCOUNT ("can not get number of users"
" with number of clicks per day", " with number of clicks per day",
"SELECT COUNT(*) FROM usr_figures" "SELECT COUNT(*)"
" FROM usr_figures"
" WHERE NumClicks>0" " WHERE NumClicks>0"
" AND FirstClickTime>FROM_UNIXTIME(0)"); " AND FirstClickTime>FROM_UNIXTIME(0)");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1056,8 +1058,9 @@ static void Prf_GetFirstClickFromLogAndStoreAsUsrFigure (long UsrCod)
/***** Get first click from log table *****/ /***** Get first click from log table *****/
if (DB_QuerySELECT (&mysql_res,"can not get user's first click", if (DB_QuerySELECT (&mysql_res,"can not get user's first click",
"SELECT UNIX_TIMESTAMP(" "SELECT UNIX_TIMESTAMP("
"(SELECT MIN(ClickTime) FROM log" "(SELECT MIN(ClickTime)"
" WHERE UsrCod=%ld)" " FROM log"
" WHERE UsrCod=%ld)"
")", ")",
UsrCod)) UsrCod))
{ {
@ -1100,7 +1103,8 @@ static void Prf_GetNumClicksAndStoreAsUsrFigure (long UsrCod)
/***** Get number of clicks from database *****/ /***** Get number of clicks from database *****/
UsrFigures.NumClicks = UsrFigures.NumClicks =
(long) DB_QueryCOUNT ("can not get number of clicks", (long) DB_QueryCOUNT ("can not get number of clicks",
"SELECT COUNT(*) FROM log" "SELECT COUNT(*)"
" FROM log"
" WHERE UsrCod=%ld", " WHERE UsrCod=%ld",
UsrCod); UsrCod);
@ -1439,16 +1443,17 @@ static void Prf_GetAndShowRankingFigure (const char *FieldName)
DB_QuerySELECT (&mysql_res,"can not get ranking", DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT UsrCod," // row[0] "SELECT UsrCod," // row[0]
"%s" // row[1] "%s" // row[1]
" FROM usr_figures" " FROM usr_figures"
" WHERE %s>0" " WHERE %s>0"
" AND UsrCod NOT IN" " AND UsrCod NOT IN"
" (SELECT UsrCod" " (SELECT UsrCod"
" FROM usr_banned)" " FROM usr_banned)"
" ORDER BY %s DESC," " ORDER BY %s DESC,"
"UsrCod" "UsrCod"
" LIMIT 100", " LIMIT 100",
FieldName, FieldName,
FieldName,FieldName); FieldName,
FieldName);
break; break;
case Hie_Lvl_CTY: case Hie_Lvl_CTY:
NumUsrs = (unsigned) NumUsrs = (unsigned)
@ -1477,7 +1482,8 @@ static void Prf_GetAndShowRankingFigure (const char *FieldName)
" LIMIT 100", " LIMIT 100",
FieldName, FieldName,
Gbl.Hierarchy.Cty.CtyCod, Gbl.Hierarchy.Cty.CtyCod,
FieldName,FieldName); FieldName,
FieldName);
break; break;
case Hie_Lvl_INS: case Hie_Lvl_INS:
NumUsrs = (unsigned) NumUsrs = (unsigned)
@ -1504,7 +1510,8 @@ static void Prf_GetAndShowRankingFigure (const char *FieldName)
" LIMIT 100", " LIMIT 100",
FieldName, FieldName,
Gbl.Hierarchy.Ins.InsCod, Gbl.Hierarchy.Ins.InsCod,
FieldName,FieldName); FieldName,
FieldName);
break; break;
case Hie_Lvl_CTR: case Hie_Lvl_CTR:
NumUsrs = (unsigned) NumUsrs = (unsigned)
@ -1668,14 +1675,15 @@ void Prf_GetAndShowRankingClicksPerDay (void)
DB_QuerySELECT (&mysql_res,"can not get ranking", DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT UsrCod," // row[0] "SELECT UsrCod," // row[0]
"NumClicks/(DATEDIFF(NOW()," "NumClicks/(DATEDIFF(NOW(),"
"FirstClickTime)+1) AS NumClicksPerDay" // row[1] "FirstClickTime)+1) AS NumClicksPerDay" // row[1]
" FROM usr_figures" " FROM usr_figures"
" WHERE NumClicks>0" " WHERE NumClicks>0"
" AND FirstClickTime>FROM_UNIXTIME(0)" " AND FirstClickTime>FROM_UNIXTIME(0)"
" AND UsrCod NOT IN" " AND UsrCod NOT IN"
" (SELECT UsrCod" " (SELECT UsrCod"
" FROM usr_banned)" " FROM usr_banned)"
" ORDER BY NumClicksPerDay DESC,UsrCod" " ORDER BY NumClicksPerDay DESC,"
"UsrCod"
" LIMIT 100"); " LIMIT 100");
break; break;
case Hie_Lvl_CTY: case Hie_Lvl_CTY:

View File

@ -981,7 +981,7 @@ static void Prg_GetListItems (void)
"ItmInd," // row[1] "ItmInd," // row[1]
"Level," // row[2] "Level," // row[2]
"Hidden" // row[3] "Hidden" // row[3]
" FROM prg_items" " FROM prg_items"
" WHERE CrsCod=%ld%s" " WHERE CrsCod=%ld%s"
" ORDER BY ItmInd", " ORDER BY ItmInd",
Gbl.Hierarchy.Crs.CrsCod, Gbl.Hierarchy.Crs.CrsCod,
@ -1045,9 +1045,9 @@ static void Prg_GetDataOfItemByCod (struct ProgramItem *Item)
"UNIX_TIMESTAMP(EndTime)," // row[6] "UNIX_TIMESTAMP(EndTime)," // row[6]
"NOW() BETWEEN StartTime AND EndTime," // row[7] "NOW() BETWEEN StartTime AND EndTime," // row[7]
"Title" // row[8] "Title" // row[8]
" FROM prg_items" " FROM prg_items"
" WHERE ItmCod=%ld" " WHERE ItmCod=%ld"
" AND CrsCod=%ld", // Extra check " AND CrsCod=%ld", // Extra check
Item->Hierarchy.ItmCod,Gbl.Hierarchy.Crs.CrsCod); Item->Hierarchy.ItmCod,Gbl.Hierarchy.Crs.CrsCod);
/***** Get data of program item *****/ /***** Get data of program item *****/
@ -1165,9 +1165,10 @@ static void Prg_GetItemTxtFromDB (long ItmCod,char Txt[Cns_MAX_BYTES_TEXT + 1])
/***** Get text of program item from database *****/ /***** Get text of program item from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get program item text", NumRows = DB_QuerySELECT (&mysql_res,"can not get program item text",
"SELECT Txt FROM prg_items" "SELECT Txt"
" FROM prg_items"
" WHERE ItmCod=%ld" " WHERE ItmCod=%ld"
" AND CrsCod=%ld", // Extra check " AND CrsCod=%ld", // Extra check
ItmCod,Gbl.Hierarchy.Crs.CrsCod); ItmCod,Gbl.Hierarchy.Crs.CrsCod);
/***** The result of the query must have one row or none *****/ /***** The result of the query must have one row or none *****/
@ -2189,65 +2190,65 @@ unsigned Prg_GetNumCoursesWithItems (Hie_Lvl_Level_t Scope)
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with program items", DB_QueryCOUNT ("can not get number of courses with program items",
"SELECT COUNT(DISTINCT CrsCod)" "SELECT COUNT(DISTINCT CrsCod)"
" FROM prg_items" " FROM prg_items"
" WHERE CrsCod>0"); " WHERE CrsCod>0");
case Hie_Lvl_CTY: case Hie_Lvl_CTY:
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with program items", DB_QueryCOUNT ("can not get number of courses with program items",
"SELECT COUNT(DISTINCT prg_items.CrsCod)" "SELECT COUNT(DISTINCT prg_items.CrsCod)"
" FROM ins_instits," " FROM ins_instits,"
"ctr_centers," "ctr_centers,"
"deg_degrees," "deg_degrees,"
"crs_courses," "crs_courses,"
"prg_items" "prg_items"
" WHERE ins_instits.CtyCod=%ld" " WHERE ins_instits.CtyCod=%ld"
" AND ins_instits.InsCod=ctr_centers.InsCod" " AND ins_instits.InsCod=ctr_centers.InsCod"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod" " AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.Status=0" " AND crs_courses.Status=0"
" AND crs_courses.CrsCod=prg_items.CrsCod", " AND crs_courses.CrsCod=prg_items.CrsCod",
Gbl.Hierarchy.Cty.CtyCod); Gbl.Hierarchy.Cty.CtyCod);
case Hie_Lvl_INS: case Hie_Lvl_INS:
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with program items", DB_QueryCOUNT ("can not get number of courses with program items",
"SELECT COUNT(DISTINCT prg_items.CrsCod)" "SELECT COUNT(DISTINCT prg_items.CrsCod)"
" FROM ctr_centers," " FROM ctr_centers,"
"deg_degrees," "deg_degrees,"
"crs_courses," "crs_courses,"
"prg_items" "prg_items"
" WHERE ctr_centers.InsCod=%ld" " WHERE ctr_centers.InsCod=%ld"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod" " AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.Status=0" " AND crs_courses.Status=0"
" AND crs_courses.CrsCod=prg_items.CrsCod", " AND crs_courses.CrsCod=prg_items.CrsCod",
Gbl.Hierarchy.Ins.InsCod); Gbl.Hierarchy.Ins.InsCod);
case Hie_Lvl_CTR: case Hie_Lvl_CTR:
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with program items", DB_QueryCOUNT ("can not get number of courses with program items",
"SELECT COUNT(DISTINCT prg_items.CrsCod)" "SELECT COUNT(DISTINCT prg_items.CrsCod)"
" FROM deg_degrees," " FROM deg_degrees,"
"crs_courses," "crs_courses,"
"prg_items" "prg_items"
" WHERE deg_degrees.CtrCod=%ld" " WHERE deg_degrees.CtrCod=%ld"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.Status=0" " AND crs_courses.Status=0"
" AND crs_courses.CrsCod=prg_items.CrsCod", " AND crs_courses.CrsCod=prg_items.CrsCod",
Gbl.Hierarchy.Ctr.CtrCod); Gbl.Hierarchy.Ctr.CtrCod);
case Hie_Lvl_DEG: case Hie_Lvl_DEG:
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with program items", DB_QueryCOUNT ("can not get number of courses with program items",
"SELECT COUNT(DISTINCT prg_items.CrsCod)" "SELECT COUNT(DISTINCT prg_items.CrsCod)"
" FROM crs_courses," " FROM crs_courses,"
"prg_items" "prg_items"
" WHERE crs_courses.DegCod=%ld" " WHERE crs_courses.DegCod=%ld"
" AND crs_courses.Status=0" " AND crs_courses.Status=0"
" AND crs_courses.CrsCod=prg_items.CrsCod", " AND crs_courses.CrsCod=prg_items.CrsCod",
Gbl.Hierarchy.Deg.DegCod); Gbl.Hierarchy.Deg.DegCod);
case Hie_Lvl_CRS: case Hie_Lvl_CRS:
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with program items", DB_QueryCOUNT ("can not get number of courses with program items",
"SELECT COUNT(DISTINCT CrsCod)" "SELECT COUNT(DISTINCT CrsCod)"
" FROM prg_items" " FROM prg_items"
" WHERE CrsCod=%ld", " WHERE CrsCod=%ld",
Gbl.Hierarchy.Crs.CrsCod); Gbl.Hierarchy.Crs.CrsCod);
default: default:
@ -2269,66 +2270,66 @@ unsigned Prg_GetNumItems (Hie_Lvl_Level_t Scope)
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of program items", DB_QueryCOUNT ("can not get number of program items",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM prg_items" " FROM prg_items"
" WHERE CrsCod>0"); " WHERE CrsCod>0");
break; break;
case Hie_Lvl_CTY: case Hie_Lvl_CTY:
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of program items", DB_QueryCOUNT ("can not get number of program items",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM ins_instits," " FROM ins_instits,"
"ctr_centers," "ctr_centers,"
"deg_degrees," "deg_degrees,"
"crs_courses," "crs_courses,"
"prg_items" "prg_items"
" WHERE ins_instits.CtyCod=%ld" " WHERE ins_instits.CtyCod=%ld"
" AND ins_instits.InsCod=ctr_centers.InsCod" " AND ins_instits.InsCod=ctr_centers.InsCod"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod" " AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=prg_items.CrsCod", " AND crs_courses.CrsCod=prg_items.CrsCod",
Gbl.Hierarchy.Cty.CtyCod); Gbl.Hierarchy.Cty.CtyCod);
break; break;
case Hie_Lvl_INS: case Hie_Lvl_INS:
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of program items", DB_QueryCOUNT ("can not get number of program items",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM ctr_centers," " FROM ctr_centers,"
"deg_degrees," "deg_degrees,"
"crs_courses," "crs_courses,"
"prg_items" "prg_items"
" WHERE ctr_centers.InsCod=%ld" " WHERE ctr_centers.InsCod=%ld"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod" " AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=prg_items.CrsCod", " AND crs_courses.CrsCod=prg_items.CrsCod",
Gbl.Hierarchy.Ins.InsCod); Gbl.Hierarchy.Ins.InsCod);
break; break;
case Hie_Lvl_CTR: case Hie_Lvl_CTR:
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of program items", DB_QueryCOUNT ("can not get number of program items",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM deg_degrees," " FROM deg_degrees,"
"crs_courses," "crs_courses,"
"prg_items" "prg_items"
" WHERE deg_degrees.CtrCod=%ld" " WHERE deg_degrees.CtrCod=%ld"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=prg_items.CrsCod", " AND crs_courses.CrsCod=prg_items.CrsCod",
Gbl.Hierarchy.Ctr.CtrCod); Gbl.Hierarchy.Ctr.CtrCod);
break; break;
case Hie_Lvl_DEG: case Hie_Lvl_DEG:
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of program items", DB_QueryCOUNT ("can not get number of program items",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM crs_courses," " FROM crs_courses,"
"prg_items" "prg_items"
" WHERE crs_courses.DegCod=%ld" " WHERE crs_courses.DegCod=%ld"
" AND crs_courses.CrsCod=prg_items.CrsCod", " AND crs_courses.CrsCod=prg_items.CrsCod",
Gbl.Hierarchy.Deg.DegCod); Gbl.Hierarchy.Deg.DegCod);
break; break;
case Hie_Lvl_CRS: case Hie_Lvl_CRS:
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of program items", DB_QueryCOUNT ("can not get number of program items",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM prg_items" " FROM prg_items"
" WHERE CrsCod=%ld", " WHERE CrsCod=%ld",
Gbl.Hierarchy.Crs.CrsCod); Gbl.Hierarchy.Crs.CrsCod);
break; break;

View File

@ -2942,7 +2942,7 @@ static void Prj_GetListProjects (struct Prj_Projects *Projects)
" FROM prj_projects," " FROM prj_projects,"
"prj_users" "prj_users"
" WHERE prj_projects.CrsCod=%ld" " WHERE prj_projects.CrsCod=%ld"
"%s%s%s" "%s%s%s"
" AND prj_projects.PrjCod=prj_users.PrjCod" " AND prj_projects.PrjCod=prj_users.PrjCod"
" AND prj_users.UsrCod=%ld" " AND prj_users.UsrCod=%ld"
" GROUP BY prj_projects.PrjCod" // To not repeat projects (DISTINCT can not be used) " GROUP BY prj_projects.PrjCod" // To not repeat projects (DISTINCT can not be used)
@ -2959,7 +2959,7 @@ static void Prj_GetListProjects (struct Prj_Projects *Projects)
"prj_users" "prj_users"
" ON prj_projects.DptCod=dpt_departments.DptCod" " ON prj_projects.DptCod=dpt_departments.DptCod"
" WHERE prj_projects.CrsCod=%ld" " WHERE prj_projects.CrsCod=%ld"
"%s%s%s" "%s%s%s"
" AND prj_projects.PrjCod=prj_users.PrjCod" " AND prj_projects.PrjCod=prj_users.PrjCod"
" AND prj_users.UsrCod=%ld" " AND prj_users.UsrCod=%ld"
" GROUP BY prj_projects.PrjCod" // To not repeat projects (DISTINCT can not be used) " GROUP BY prj_projects.PrjCod" // To not repeat projects (DISTINCT can not be used)
@ -2995,7 +2995,7 @@ static void Prj_GetListProjects (struct Prj_Projects *Projects)
" FROM prj_projects," " FROM prj_projects,"
"prj_users" "prj_users"
" WHERE prj_projects.CrsCod=%ld" " WHERE prj_projects.CrsCod=%ld"
"%s%s%s" "%s%s%s"
" AND prj_projects.PrjCod=prj_users.PrjCod" " AND prj_projects.PrjCod=prj_users.PrjCod"
" AND prj_users.UsrCod IN (%s)" " AND prj_users.UsrCod IN (%s)"
" GROUP BY prj_projects.PrjCod" // To not repeat projects (DISTINCT can not be used) " GROUP BY prj_projects.PrjCod" // To not repeat projects (DISTINCT can not be used)
@ -3012,7 +3012,7 @@ static void Prj_GetListProjects (struct Prj_Projects *Projects)
"prj_users" "prj_users"
" ON prj_projects.DptCod=dpt_departments.DptCod" " ON prj_projects.DptCod=dpt_departments.DptCod"
" WHERE prj_projects.CrsCod=%ld" " WHERE prj_projects.CrsCod=%ld"
"%s%s%s" "%s%s%s"
" AND prj_projects.PrjCod=prj_users.PrjCod" " AND prj_projects.PrjCod=prj_users.PrjCod"
" AND prj_users.UsrCod IN (%s)" " AND prj_users.UsrCod IN (%s)"
" GROUP BY prj_projects.PrjCod" // To not repeat projects (DISTINCT can not be used) " GROUP BY prj_projects.PrjCod" // To not repeat projects (DISTINCT can not be used)
@ -3044,7 +3044,7 @@ static void Prj_GetListProjects (struct Prj_Projects *Projects)
"SELECT prj_projects.PrjCod" "SELECT prj_projects.PrjCod"
" FROM prj_projects" " FROM prj_projects"
" WHERE prj_projects.CrsCod=%ld" " WHERE prj_projects.CrsCod=%ld"
"%s%s%s" "%s%s%s"
" ORDER BY %s", " ORDER BY %s",
Gbl.Hierarchy.Crs.CrsCod, Gbl.Hierarchy.Crs.CrsCod,
PreNonSubQuery,HidVisSubQuery,DptCodSubQuery, PreNonSubQuery,HidVisSubQuery,DptCodSubQuery,
@ -3056,7 +3056,7 @@ static void Prj_GetListProjects (struct Prj_Projects *Projects)
" FROM prj_projects LEFT JOIN dpt_departments" " FROM prj_projects LEFT JOIN dpt_departments"
" ON prj_projects.DptCod=dpt_departments.DptCod" " ON prj_projects.DptCod=dpt_departments.DptCod"
" WHERE prj_projects.CrsCod=%ld" " WHERE prj_projects.CrsCod=%ld"
"%s%s%s" "%s%s%s"
" ORDER BY %s", " ORDER BY %s",
Gbl.Hierarchy.Crs.CrsCod, Gbl.Hierarchy.Crs.CrsCod,
PreNonSubQuery,HidVisSubQuery,DptCodSubQuery, PreNonSubQuery,HidVisSubQuery,DptCodSubQuery,
@ -4153,7 +4153,8 @@ static void Prj_GetConfigPrjFromDB (struct Prj_Projects *Projects)
/***** Get configuration of projects for current course from database *****/ /***** Get configuration of projects for current course from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get configuration of test", NumRows = DB_QuerySELECT (&mysql_res,"can not get configuration of test",
"SELECT Editable" // row[0] "SELECT Editable" // row[0]
" FROM prj_config WHERE CrsCod=%ld", " FROM prj_config"
" WHERE CrsCod=%ld",
Gbl.Hierarchy.Crs.CrsCod); Gbl.Hierarchy.Crs.CrsCod);
if (NumRows == 0) if (NumRows == 0)

View File

@ -200,13 +200,16 @@ void Rec_GetListRecordFieldsInCurrentCrs (void)
return; return;
/***** Get fields of records in a course from database *****/ /***** Get fields of records in a course from database *****/
Gbl.Crs.Records.LstFields.Num = Gbl.Crs.Records.LstFields.Num = (unsigned)
(unsigned) DB_QuerySELECT (&mysql_res,"can not get fields of records" DB_QuerySELECT (&mysql_res,"can not get fields of records in a course",
" in a course", "SELECT FieldCod,"
"SELECT FieldCod,FieldName,NumLines,Visibility" "FieldName,"
" FROM crs_record_fields" "NumLines,"
" WHERE CrsCod=%ld ORDER BY FieldName", "Visibility"
Gbl.Hierarchy.Crs.CrsCod); " FROM crs_record_fields"
" WHERE CrsCod=%ld"
" ORDER BY FieldName",
Gbl.Hierarchy.Crs.CrsCod);
/***** Get the fields of records *****/ /***** Get the fields of records *****/
if (Gbl.Crs.Records.LstFields.Num) if (Gbl.Crs.Records.LstFields.Num)
@ -520,9 +523,12 @@ unsigned long Rec_GetAllFieldsInCurrCrs (MYSQL_RES **mysql_res)
/***** Get fields of records in current course from database *****/ /***** Get fields of records in current course from database *****/
return DB_QuerySELECT (mysql_res,"can not get fields of records" return DB_QuerySELECT (mysql_res,"can not get fields of records"
" in a course", " in a course",
"SELECT FieldCod,FieldName,Visibility" "SELECT FieldCod," // row[0]
" FROM crs_record_fields" "FieldName," // row[1]
" WHERE CrsCod=%ld ORDER BY FieldName", "Visibility" // row[2]
" FROM crs_record_fields"
" WHERE CrsCod=%ld"
" ORDER BY FieldName",
Gbl.Hierarchy.Crs.CrsCod); Gbl.Hierarchy.Crs.CrsCod);
} }
@ -589,7 +595,8 @@ unsigned Rec_CountNumRecordsInCurrCrsWithField (long FieldCod)
return return
(unsigned) DB_QueryCOUNT ("can not get number of records" (unsigned) DB_QueryCOUNT ("can not get number of records"
" with a given field not empty in a course", " with a given field not empty in a course",
"SELECT COUNT(*) FROM crs_records" "SELECT COUNT(*)"
v" FROM crs_records"
" WHERE FieldCod=%ld", " WHERE FieldCod=%ld",
FieldCod); FieldCod);
} }
@ -678,9 +685,12 @@ static void Rec_GetFieldByCod (long FieldCod,char Name[Rec_MAX_BYTES_NAME_FIELD
/***** Get a field of a record in a course from database *****/ /***** Get a field of a record in a course from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get a field of a record" NumRows = DB_QuerySELECT (&mysql_res,"can not get a field of a record"
" in a course", " in a course",
"SELECT FieldName,NumLines,Visibility" "SELECT FieldName," // row[0]
" FROM crs_record_fields" "NumLines," // row[1]
" WHERE CrsCod=%ld AND FieldCod=%ld", "Visibility" // row[2]
" FROM crs_record_fields"
" WHERE CrsCod=%ld"
" AND FieldCod=%ld",
Gbl.Hierarchy.Crs.CrsCod,FieldCod); Gbl.Hierarchy.Crs.CrsCod,FieldCod);
/***** Count number of rows in result *****/ /***** Count number of rows in result *****/
@ -1846,8 +1856,10 @@ unsigned long Rec_GetFieldFromCrsRecord (long UsrCod,long FieldCod,MYSQL_RES **m
/***** Get the text of a field of a record from database *****/ /***** Get the text of a field of a record from database *****/
return DB_QuerySELECT (mysql_res,"can not get the text" return DB_QuerySELECT (mysql_res,"can not get the text"
" of a field of a record", " of a field of a record",
"SELECT Txt FROM crs_records" "SELECT Txt"
" WHERE FieldCod=%ld AND UsrCod=%ld", " FROM crs_records"
" WHERE FieldCod=%ld"
" AND UsrCod=%ld",
FieldCod,UsrCod); FieldCod,UsrCod);
} }
@ -1930,8 +1942,11 @@ void Rec_RemoveFieldsCrsRecordInCrs (long UsrCod,struct Crs_Course *Crs)
/***** Remove text of the field of record course *****/ /***** Remove text of the field of record course *****/
DB_QueryDELETE ("can not remove user's record in a course", DB_QueryDELETE ("can not remove user's record in a course",
"DELETE FROM crs_records" "DELETE FROM crs_records"
" WHERE UsrCod=%ld AND FieldCod IN" " WHERE UsrCod=%ld"
" (SELECT FieldCod FROM crs_record_fields WHERE CrsCod=%ld)", " AND FieldCod IN"
" (SELECT FieldCod"
" FROM crs_record_fields"
" WHERE CrsCod=%ld)",
UsrCod,Crs->CrsCod); UsrCod,Crs->CrsCod);
} }

View File

@ -779,12 +779,14 @@ static void Rep_WriteSectionHitsPerAction (struct Rep_Report *Report)
/***** Make the query *****/ /***** Make the query *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get clicks", NumRows = DB_QuerySELECT (&mysql_res,"can not get clicks",
"SELECT SQL_NO_CACHE ActCod,COUNT(*) AS N" "SELECT SQL_NO_CACHE ActCod," // row[0]
" FROM log" "COUNT(*) AS N" // row[1]
" FROM log"
" WHERE ClickTime>=FROM_UNIXTIME(%ld)" " WHERE ClickTime>=FROM_UNIXTIME(%ld)"
" AND UsrCod=%ld" " AND UsrCod=%ld"
" GROUP BY ActCod" " GROUP BY ActCod"
" ORDER BY N DESC LIMIT %u", " ORDER BY N DESC"
" LIMIT %u",
(long) Report->UsrFigures.FirstClickTimeUTC, (long) Report->UsrFigures.FirstClickTimeUTC,
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
Rep_MAX_ACTIONS); Rep_MAX_ACTIONS);
@ -922,30 +924,28 @@ static void Rep_GetMaxHitsPerYear (struct Rep_Report *Report)
DB_QuerySELECT (&mysql_res,"can not get last question index", DB_QuerySELECT (&mysql_res,"can not get last question index",
"SELECT MAX(N) FROM (" "SELECT MAX(N) FROM ("
// Clicks without course selected -------------------------- // Clicks without course selected --------------------------
"SELECT " "SELECT -1 AS CrsCod,"
"-1 AS CrsCod," "YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year,"
"YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year," "%u AS Role,"
"%u AS Role," "COUNT(*) AS N"
"COUNT(*) AS N" " FROM log"
" FROM log"
" WHERE ClickTime>=FROM_UNIXTIME(%ld)" " WHERE ClickTime>=FROM_UNIXTIME(%ld)"
" AND UsrCod=%ld" " AND UsrCod=%ld"
" AND CrsCod<=0" " AND CrsCod<=0"
" GROUP BY Year" " GROUP BY Year"
// --------------------------------------------------------- // ---------------------------------------------------------
" UNION " " UNION "
// Clicks as student, non-editing teacher or teacher in courses // Clicks as student, non-editing teacher or teacher in courses
"SELECT " "SELECT CrsCod,"
"CrsCod," "YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year,"
"YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year," "Role,"
"Role," "COUNT(*) AS N"
"COUNT(*) AS N" " FROM log"
" FROM log"
" WHERE ClickTime>=FROM_UNIXTIME(%ld)" " WHERE ClickTime>=FROM_UNIXTIME(%ld)"
" AND UsrCod=%ld" " AND UsrCod=%ld"
" AND Role>=%u" // Student " AND Role>=%u" // Student
" AND Role<=%u" // Teacher " AND Role<=%u" // Teacher
" AND CrsCod>0" " AND CrsCod>0"
" GROUP BY CrsCod,Year,Role" " GROUP BY CrsCod,Year,Role"
// --------------------------------------------------------- // ---------------------------------------------------------
") AS hits_per_crs_year", ") AS hits_per_crs_year",
@ -1012,13 +1012,12 @@ static void Rep_GetAndWriteMyCurrentCrss (Rol_Role_t Role,
(unsigned) DB_QuerySELECT (&mysql_res,"can not get courses of a user", (unsigned) DB_QuerySELECT (&mysql_res,"can not get courses of a user",
"SELECT my_courses.CrsCod," // row[0] "SELECT my_courses.CrsCod," // row[0]
"COUNT(*) AS N" // row[1] "COUNT(*) AS N" // row[1]
" FROM" " FROM (SELECT CrsCod"
" (SELECT CrsCod" " FROM crs_users"
" FROM crs_users" " WHERE UsrCod=%ld"
" WHERE UsrCod=%ld" " AND Role=%u) AS my_courses" // It's imperative to use a derived table to not block crs_usr!
" AND Role=%u) AS my_courses" // It's imperative to use a derived table to not block crs_usr! " LEFT JOIN log"
" LEFT JOIN log" " ON (my_courses.CrsCod=log.CrsCod)"
" ON (my_courses.CrsCod=log.CrsCod)"
" WHERE log.UsrCod=%ld" " WHERE log.UsrCod=%ld"
" AND log.Role=%u" " AND log.Role=%u"
" GROUP BY my_courses.CrsCod" " GROUP BY my_courses.CrsCod"
@ -1102,9 +1101,12 @@ static void Rep_GetAndWriteMyHistoricCrss (Rol_Role_t Role,
/***** Get historic courses of a user from log *****/ /***** Get historic courses of a user from log *****/
NumCrss = NumCrss =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get courses of a user", (unsigned) DB_QuerySELECT (&mysql_res,"can not get courses of a user",
"SELECT CrsCod,COUNT(*) AS N" "SELECT CrsCod,"
" FROM log" "COUNT(*) AS N"
" WHERE UsrCod=%ld AND Role=%u AND CrsCod>0" " FROM log"
" WHERE UsrCod=%ld"
" AND Role=%u"
" AND CrsCod>0"
" GROUP BY CrsCod" " GROUP BY CrsCod"
" HAVING N>%u" " HAVING N>%u"
" ORDER BY N DESC", " ORDER BY N DESC",
@ -1240,11 +1242,12 @@ static void Rep_ShowMyHitsPerYear (bool AnyCourse,long CrsCod,Rol_Role_t Role,
sprintf (SubQueryRol," AND Role=%u",(unsigned) Role); sprintf (SubQueryRol," AND Role=%u",(unsigned) Role);
NumRows = DB_QuerySELECT (&mysql_res,"can not get clicks", NumRows = DB_QuerySELECT (&mysql_res,"can not get clicks",
"SELECT SQL_NO_CACHE " "SELECT SQL_NO_CACHE YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year,"
"YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year," "COUNT(*) FROM log"
"COUNT(*) FROM log"
" WHERE ClickTime>=FROM_UNIXTIME(%ld)" " WHERE ClickTime>=FROM_UNIXTIME(%ld)"
" AND UsrCod=%ld%s%s" " AND UsrCod=%ld"
"%s"
"%s"
" GROUP BY Year" " GROUP BY Year"
" ORDER BY Year DESC", " ORDER BY Year DESC",
(long) Report->UsrFigures.FirstClickTimeUTC, (long) Report->UsrFigures.FirstClickTimeUTC,

View File

@ -467,10 +467,12 @@ static unsigned Sch_SearchCountriesInDB (const char *RangeQuery)
NumCtys = (unsigned) NumCtys = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get countries", DB_QuerySELECT (&mysql_res,"can not get countries",
"SELECT CtyCod" // row[0] "SELECT CtyCod" // row[0]
" FROM cty_countrs" " FROM cty_countrs"
" WHERE %s%s" " WHERE %s"
"%s"
" ORDER BY Name_%s", " ORDER BY Name_%s",
SearchQuery,RangeQuery, SearchQuery,
RangeQuery,
Lan_STR_LANG_ID[Gbl.Prefs.Language]); Lan_STR_LANG_ID[Gbl.Prefs.Language]);
Cty_ListCtysFound (&mysql_res,NumCtys); Cty_ListCtysFound (&mysql_res,NumCtys);
return NumCtys; return NumCtys;
@ -505,14 +507,15 @@ static unsigned Sch_SearchInstitutionsInDB (const char *RangeQuery)
NumInss = (unsigned) NumInss = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get institutions", DB_QuerySELECT (&mysql_res,"can not get institutions",
"SELECT ins_instits.InsCod" // row[0] "SELECT ins_instits.InsCod" // row[0]
" FROM ins_instits," " FROM ins_instits,"
"cty_countrs" "cty_countrs"
" WHERE %s" " WHERE %s"
" AND ins_instits.CtyCod=cty_countrs.CtyCod" " AND ins_instits.CtyCod=cty_countrs.CtyCod"
"%s" "%s"
" ORDER BY ins_instits.FullName," " ORDER BY ins_instits.FullName,"
"cty_countrs.Name_%s", "cty_countrs.Name_%s",
SearchQuery,RangeQuery, SearchQuery,
RangeQuery,
Lan_STR_LANG_ID[Gbl.Prefs.Language]); Lan_STR_LANG_ID[Gbl.Prefs.Language]);
Ins_ListInssFound (&mysql_res,NumInss); Ins_ListInssFound (&mysql_res,NumInss);
return NumInss; return NumInss;
@ -544,13 +547,13 @@ static unsigned Sch_SearchCentersInDB (const char *RangeQuery)
NumCtrs = (unsigned) NumCtrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get centers", DB_QuerySELECT (&mysql_res,"can not get centers",
"SELECT ctr_centers.CtrCod" // row[0] "SELECT ctr_centers.CtrCod" // row[0]
" FROM ctr_centers," " FROM ctr_centers,"
"ins_instits," "ins_instits,"
"cty_countrs" "cty_countrs"
" WHERE %s" " WHERE %s"
" AND ctr_centers.InsCod=ins_instits.InsCod" " AND ctr_centers.InsCod=ins_instits.InsCod"
" AND ins_instits.CtyCod=cty_countrs.CtyCod" " AND ins_instits.CtyCod=cty_countrs.CtyCod"
"%s" "%s"
" ORDER BY ctr_centers.FullName," " ORDER BY ctr_centers.FullName,"
"ins_instits.FullName", "ins_instits.FullName",
SearchQuery,RangeQuery); SearchQuery,RangeQuery);
@ -583,15 +586,15 @@ static unsigned Sch_SearchDegreesInDB (const char *RangeQuery)
NumDegs = (unsigned) NumDegs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get degrees", DB_QuerySELECT (&mysql_res,"can not get degrees",
"SELECT deg_degrees.DegCod" // row[0] "SELECT deg_degrees.DegCod" // row[0]
" FROM deg_degrees," " FROM deg_degrees,"
"ctr_centers," "ctr_centers,"
"ins_instits," "ins_instits,"
"cty_countrs" "cty_countrs"
" WHERE %s" " WHERE %s"
" AND deg_degrees.CtrCod=ctr_centers.CtrCod" " AND deg_degrees.CtrCod=ctr_centers.CtrCod"
" AND ctr_centers.InsCod=ins_instits.InsCod" " AND ctr_centers.InsCod=ins_instits.InsCod"
" AND ins_instits.CtyCod=cty_countrs.CtyCod" " AND ins_instits.CtyCod=cty_countrs.CtyCod"
"%s" "%s"
" ORDER BY deg_degrees.FullName," " ORDER BY deg_degrees.FullName,"
"ins_instits.FullName", "ins_instits.FullName",
SearchQuery,RangeQuery); SearchQuery,RangeQuery);
@ -628,17 +631,17 @@ static unsigned Sch_SearchCoursesInDB (const char *RangeQuery)
"crs_courses.Year," // row[4] "crs_courses.Year," // row[4]
"crs_courses.FullName," // row[5] "crs_courses.FullName," // row[5]
"ctr_centers.ShortName" // row[6] "ctr_centers.ShortName" // row[6]
" FROM crs_courses," " FROM crs_courses,"
"deg_degrees," "deg_degrees,"
"ctr_centers," "ctr_centers,"
"ins_instits," "ins_instits,"
"cty_countrs" "cty_countrs"
" WHERE %s" " WHERE %s"
" AND crs_courses.DegCod=deg_degrees.DegCod" " AND crs_courses.DegCod=deg_degrees.DegCod"
" AND deg_degrees.CtrCod=ctr_centers.CtrCod" " AND deg_degrees.CtrCod=ctr_centers.CtrCod"
" AND ctr_centers.InsCod=ins_instits.InsCod" " AND ctr_centers.InsCod=ins_instits.InsCod"
" AND ins_instits.CtyCod=cty_countrs.CtyCod" " AND ins_instits.CtyCod=cty_countrs.CtyCod"
"%s" "%s"
" ORDER BY crs_courses.FullName," " ORDER BY crs_courses.FullName,"
"ins_instits.FullName," "ins_instits.FullName,"
"degrees.FullName," "degrees.FullName,"
@ -912,7 +915,9 @@ static unsigned Sch_SearchDocumentsInMyCoursesInDB (const char *RangeQuery)
"ctr_centers," "ctr_centers,"
"ins_instits," "ins_instits,"
"cty_countrs" "cty_countrs"
" WHERE brw_files.FilCod IN (SELECT FilCod FROM my_files_crs)" " WHERE brw_files.FilCod IN"
" (SELECT FilCod"
" FROM my_files_crs)"
" AND %s" " AND %s"
" AND brw_files.FileBrowser IN (%u,%u,%u,%u)" " AND brw_files.FileBrowser IN (%u,%u,%u,%u)"
" AND brw_files.Cod=crs_courses.CrsCod" " AND brw_files.Cod=crs_courses.CrsCod"
@ -941,7 +946,9 @@ static unsigned Sch_SearchDocumentsInMyCoursesInDB (const char *RangeQuery)
"ctr_centers," "ctr_centers,"
"ins_instits," "ins_instits,"
"cty_countrs" "cty_countrs"
" WHERE brw_files.FilCod IN (SELECT FilCod FROM my_files_grp)" " WHERE brw_files.FilCod IN"
" (SELECT FilCod"
" FROM my_files_grp)"
" AND %s" " AND %s"
" AND brw_files.FileBrowser IN (%u,%u,%u,%u)" " AND brw_files.FileBrowser IN (%u,%u,%u,%u)"
" AND brw_files.Cod=grp_groups.GrpCod" " AND brw_files.Cod=grp_groups.GrpCod"

View File

@ -399,8 +399,8 @@ void Ses_RemoveParamsFromExpiredSessions (void)
DB_QueryDELETE ("can not remove session parameters of expired sessions", DB_QueryDELETE ("can not remove session parameters of expired sessions",
"DELETE FROM ses_params" "DELETE FROM ses_params"
" WHERE SessionId NOT IN" " WHERE SessionId NOT IN"
" (SELECT SessionId" " (SELECT SessionId"
" FROM ses_sessions)"); " FROM ses_sessions)");
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -1789,7 +1789,9 @@ static void Sta_WriteLogComments (long LogCod)
/***** Get log comments from database *****/ /***** Get log comments from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get log comments", if (DB_QuerySELECT (&mysql_res,"can not get log comments",
"SELECT Comments FROM log_comments WHERE LogCod=%ld", "SELECT Comments"
" FROM log_comments"
" WHERE LogCod=%ld",
LogCod)) LogCod))
{ {
/***** Get and write comments *****/ /***** Get and write comments *****/

View File

@ -1031,7 +1031,8 @@ static void Svy_GetListSurveys (struct Svy_Surveys *Surveys)
/* Make query */ /* Make query */
if (SubQueryFilled) if (SubQueryFilled)
NumRows = DB_QuerySELECT (&mysql_res,"can not get surveys", NumRows = DB_QuerySELECT (&mysql_res,"can not get surveys",
"SELECT SvyCod FROM svy_surveys" "SELECT SvyCod"
" FROM svy_surveys"
" WHERE %s%s%s%s%s%s" " WHERE %s%s%s%s%s%s"
" ORDER BY %s", " ORDER BY %s",
SubQuery[Hie_Lvl_SYS], SubQuery[Hie_Lvl_SYS],
@ -1261,12 +1262,17 @@ void Svy_GetDataOfSurveyByCod (struct Svy_Survey *Svy)
/***** Get data of survey from database *****/ /***** Get data of survey from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get survey data", NumRows = DB_QuerySELECT (&mysql_res,"can not get survey data",
"SELECT SvyCod,Scope,Cod,Hidden,Roles,UsrCod," "SELECT SvyCod," // row[0]
"UNIX_TIMESTAMP(StartTime)," "Scope," // row[1]
"UNIX_TIMESTAMP(EndTime)," "Cod," // row[2]
"NOW() BETWEEN StartTime AND EndTime," "Hidden," // row[3]
"Title" "Roles," // row[4]
" FROM svy_surveys" "UsrCod," // row[5]
"UNIX_TIMESTAMP(StartTime)," // row[6]
"UNIX_TIMESTAMP(EndTime)," // row[7]
"NOW() BETWEEN StartTime AND EndTime," // row[8]
"Title"
" FROM svy_surveys"
" WHERE SvyCod=%ld", " WHERE SvyCod=%ld",
Svy->SvyCod); Svy->SvyCod);
@ -1488,7 +1494,9 @@ static void Svy_GetSurveyTxtFromDB (long SvyCod,char Txt[Cns_MAX_BYTES_TEXT + 1]
/***** Get text of survey from database *****/ /***** Get text of survey from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get survey text", NumRows = DB_QuerySELECT (&mysql_res,"can not get survey text",
"SELECT Txt FROM svy_surveys WHERE SvyCod=%ld", "SELECT Txt"
" FROM svy_surveys"
" WHERE SvyCod=%ld",
SvyCod); SvyCod);
/***** The result of the query must have one row or none *****/ /***** The result of the query must have one row or none *****/
@ -1526,7 +1534,7 @@ void Svy_GetNotifSurvey (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
if (DB_QuerySELECT (&mysql_res,"can not get groups of a survey", if (DB_QuerySELECT (&mysql_res,"can not get groups of a survey",
"SELECT Title," // row[0] "SELECT Title," // row[0]
"Txt" // row[1] "Txt" // row[1]
" FROM svy_surveys" " FROM svy_surveys"
" WHERE SvyCod=%ld", " WHERE SvyCod=%ld",
SvyCod) == 1) SvyCod) == 1)
{ {
@ -1851,11 +1859,16 @@ static bool Svy_CheckIfSimilarSurveyExists (struct Svy_Survey *Svy)
{ {
/***** Get number of surveys with a field value from database *****/ /***** Get number of surveys with a field value from database *****/
return (DB_QueryCOUNT ("can not get similar surveys", return (DB_QueryCOUNT ("can not get similar surveys",
"SELECT COUNT(*) FROM svy_surveys" "SELECT COUNT(*)"
" WHERE Scope='%s' AND Cod=%ld" " FROM svy_surveys"
" AND Title='%s' AND SvyCod<>%ld", " WHERE Scope='%s'"
Sco_GetDBStrFromScope (Svy->Scope),Svy->Cod, " AND Cod=%ld"
Svy->Title,Svy->SvyCod) != 0); " AND Title='%s'"
" AND SvyCod<>%ld",
Sco_GetDBStrFromScope (Svy->Scope),
Svy->Cod,
Svy->Title,
Svy->SvyCod) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2613,16 +2626,16 @@ static bool Svy_CheckIfICanDoThisSurveyBasedOnGrps (long SvyCod)
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM svy_surveys" " FROM svy_surveys"
" WHERE SvyCod=%ld" " WHERE SvyCod=%ld"
" AND" " AND (SvyCod NOT IN"
" (SvyCod NOT IN" " (SELECT SvyCod"
" (SELECT SvyCod FROM svy_groups)" " FROM svy_groups)"
" OR" " OR"
" SvyCod IN" " SvyCod IN"
" (SELECT svy_groups.SvyCod" " (SELECT svy_groups.SvyCod"
" FROM grp_users," " FROM grp_users,"
"svy_groups" "svy_groups"
" WHERE grp_users.UsrCod=%ld" " WHERE grp_users.UsrCod=%ld"
" AND grp_users.GrpCod=svy_groups.GrpCod))", " AND grp_users.GrpCod=svy_groups.GrpCod))",
SvyCod,Gbl.Usrs.Me.UsrDat.UsrCod) != 0); SvyCod,Gbl.Usrs.Me.UsrDat.UsrCod) != 0);
} }
@ -2635,7 +2648,8 @@ static unsigned Svy_GetNumQstsSvy (long SvyCod)
/***** Get data of questions from database *****/ /***** Get data of questions from database *****/
return return
(unsigned) DB_QueryCOUNT ("can not get number of questions of a survey", (unsigned) DB_QueryCOUNT ("can not get number of questions of a survey",
"SELECT COUNT(*) FROM svy_questions" "SELECT COUNT(*)"
" FROM svy_questions"
" WHERE SvyCod=%ld", " WHERE SvyCod=%ld",
SvyCod); SvyCod);
} }
@ -2710,9 +2724,14 @@ static void Svy_ShowFormEditOneQst (struct Svy_Surveys *Surveys,
/***** Get the type of answer and the stem from the database *****/ /***** Get the type of answer and the stem from the database *****/
/* Get the question from database */ /* Get the question from database */
DB_QuerySELECT (&mysql_res,"can not get a question", DB_QuerySELECT (&mysql_res,"can not get a question",
"SELECT QstInd,AnsType,Stem FROM svy_questions" "SELECT QstInd," // row[0]
" WHERE QstCod=%ld AND SvyCod=%ld", "AnsType," // row[1]
SvyQst->QstCod,SvyCod); "Stem" // row[2]
" FROM svy_questions"
" WHERE QstCod=%ld"
" AND SvyCod=%ld",
SvyQst->QstCod,
SvyCod);
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -2948,8 +2967,10 @@ static bool Svy_CheckIfAnswerExists (long QstCod,unsigned AnsInd)
{ {
/***** Get answers of a question from database *****/ /***** Get answers of a question from database *****/
return (DB_QueryCOUNT ("can not check if an answer exists", return (DB_QueryCOUNT ("can not check if an answer exists",
"SELECT COUNT(*) FROM svy_answers" "SELECT COUNT(*)"
" WHERE QstCod=%ld AND AnsInd=%u", " FROM svy_answers"
" WHERE QstCod=%ld"
" AND AnsInd=%u",
QstCod,AnsInd) != 0); QstCod,AnsInd) != 0);
} }
@ -2963,8 +2984,12 @@ static unsigned Svy_GetAnswersQst (long QstCod,MYSQL_RES **mysql_res)
/***** Get answers of a question from database *****/ /***** Get answers of a question from database *****/
NumRows = DB_QuerySELECT (mysql_res,"can not get answers of a question", NumRows = DB_QuerySELECT (mysql_res,"can not get answers of a question",
"SELECT AnsInd,NumUsrs,Answer FROM svy_answers" "SELECT AnsInd,"
" WHERE QstCod=%ld ORDER BY AnsInd", "NumUsrs,"
"Answer"
" FROM svy_answers"
" WHERE QstCod=%ld"
" ORDER BY AnsInd",
QstCod); QstCod);
/***** Count number of rows of result *****/ /***** Count number of rows of result *****/
@ -3198,7 +3223,8 @@ static unsigned Svy_GetQstIndFromQstCod (long QstCod)
/***** Get number of surveys with a field value from database *****/ /***** Get number of surveys with a field value from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get question index", NumRows = DB_QuerySELECT (&mysql_res,"can not get question index",
"SELECT QstInd FROM svy_questions" "SELECT QstInd"
" FROM svy_questions"
" WHERE QstCod=%ld", " WHERE QstCod=%ld",
QstCod); QstCod);
@ -3230,7 +3256,9 @@ static unsigned Svy_GetNextQuestionIndexInSvy (long SvyCod)
/***** Get number of surveys with a field value from database *****/ /***** Get number of surveys with a field value 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) FROM svy_questions WHERE SvyCod=%ld", "SELECT MAX(QstInd)"
" FROM svy_questions"
" WHERE SvyCod=%ld",
SvyCod); SvyCod);
/***** Get number of users *****/ /***** Get number of users *****/
@ -3274,11 +3302,16 @@ static void Svy_ListSvyQuestions (struct Svy_Surveys *Surveys,
bool PutFormAnswerSurvey = Svy->Status.ICanAnswer && !Editing; bool PutFormAnswerSurvey = Svy->Status.ICanAnswer && !Editing;
/***** Get data of questions from database *****/ /***** Get data of questions from database *****/
NumQsts = (unsigned) DB_QuerySELECT (&mysql_res,"can not get data of a question", NumQsts = (unsigned)
"SELECT QstCod,QstInd,AnsType,Stem" DB_QuerySELECT (&mysql_res,"can not get data of a question",
" FROM svy_questions" "SELECT QstCod," // row[0]
" WHERE SvyCod=%ld ORDER BY QstInd", "QstInd," // row[1]
Svy->SvyCod); "AnsType," // row[2]
"Stem" // row[3]
" FROM svy_questions"
" WHERE SvyCod=%ld"
" ORDER BY QstInd",
Svy->SvyCod);
/***** Begin box *****/ /***** Begin box *****/
Surveys->SvyCod = Svy->SvyCod; Surveys->SvyCod = Svy->SvyCod;
@ -3789,8 +3822,10 @@ static void Svy_ReceiveAndStoreUserAnswersToASurvey (long SvyCod)
/***** Get questions of this survey from database *****/ /***** Get questions of this survey from database *****/
NumQsts = (unsigned) DB_QuerySELECT (&mysql_res,"can not get questions" NumQsts = (unsigned) DB_QuerySELECT (&mysql_res,"can not get questions"
" of a survey", " of a survey",
"SELECT QstCod FROM svy_questions" "SELECT QstCod"
" WHERE SvyCod=%ld ORDER BY QstCod", " FROM svy_questions"
" WHERE SvyCod=%ld"
" ORDER BY QstCod",
SvyCod); SvyCod);
if (NumQsts) if (NumQsts)
{ {
@ -3868,9 +3903,12 @@ static bool Svy_CheckIfIHaveAnsweredSvy (long SvyCod)
{ {
/***** Get number of surveys with a field value from database *****/ /***** Get number of surveys with a field value from database *****/
return (DB_QueryCOUNT ("can not check if you have answered a survey", return (DB_QueryCOUNT ("can not check if you have answered a survey",
"SELECT COUNT(*) FROM svy_users" "SELECT COUNT(*)"
" WHERE SvyCod=%ld AND UsrCod=%ld", " FROM svy_users"
SvyCod,Gbl.Usrs.Me.UsrDat.UsrCod) != 0); " WHERE SvyCod=%ld"
" AND UsrCod=%ld",
SvyCod,
Gbl.Usrs.Me.UsrDat.UsrCod) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -3883,7 +3921,8 @@ static unsigned Svy_GetNumUsrsWhoHaveAnsweredSvy (long SvyCod)
return return
(unsigned) DB_QueryCOUNT ("can not get number of users" (unsigned) DB_QueryCOUNT ("can not get number of users"
" who have answered a survey", " who have answered a survey",
"SELECT COUNT(*) FROM svy_users" "SELECT COUNT(*)"
" FROM svy_users"
" WHERE SvyCod=%ld", " WHERE SvyCod=%ld",
SvyCod); SvyCod);
} }
@ -3903,52 +3942,52 @@ unsigned Svy_GetNumCoursesWithCrsSurveys (Hie_Lvl_Level_t Scope)
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with surveys", DB_QueryCOUNT ("can not get number of courses with surveys",
"SELECT COUNT(DISTINCT Cod)" "SELECT COUNT(DISTINCT Cod)"
" FROM svy_surveys" " FROM svy_surveys"
" WHERE Scope='%s'", " WHERE Scope='%s'",
Sco_GetDBStrFromScope (Hie_Lvl_CRS)); Sco_GetDBStrFromScope (Hie_Lvl_CRS));
case Hie_Lvl_CTY: case Hie_Lvl_CTY:
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with surveys", DB_QueryCOUNT ("can not get number of courses with surveys",
"SELECT COUNT(DISTINCT svy_surveys.Cod)" "SELECT COUNT(DISTINCT svy_surveys.Cod)"
" FROM ins_instits," " FROM ins_instits,"
"ctr_centers," "ctr_centers,"
"deg_degrees," "deg_degrees,"
"crs_courses," "crs_courses,"
"svy_surveys" "svy_surveys"
" WHERE ins_instits.CtyCod=%ld" " WHERE ins_instits.CtyCod=%ld"
" AND ins_instits.InsCod=ctr_centers.InsCod" " AND ins_instits.InsCod=ctr_centers.InsCod"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod" " AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=svy_surveys.Cod" " AND crs_courses.CrsCod=svy_surveys.Cod"
" AND svy_surveys.Scope='%s'", " AND svy_surveys.Scope='%s'",
Gbl.Hierarchy.Ins.InsCod, Gbl.Hierarchy.Ins.InsCod,
Sco_GetDBStrFromScope (Hie_Lvl_CRS)); Sco_GetDBStrFromScope (Hie_Lvl_CRS));
case Hie_Lvl_INS: case Hie_Lvl_INS:
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with surveys", DB_QueryCOUNT ("can not get number of courses with surveys",
"SELECT COUNT(DISTINCT svy_surveys.Cod)" "SELECT COUNT(DISTINCT svy_surveys.Cod)"
" FROM ctr_centers," " FROM ctr_centers,"
"deg_degrees," "deg_degrees,"
"crs_courses," "crs_courses,"
"svy_surveys" "svy_surveys"
" WHERE ctr_centers.InsCod=%ld" " WHERE ctr_centers.InsCod=%ld"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod" " AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=svy_surveys.Cod" " AND crs_courses.CrsCod=svy_surveys.Cod"
" AND svy_surveys.Scope='%s'", " AND svy_surveys.Scope='%s'",
Gbl.Hierarchy.Ins.InsCod, Gbl.Hierarchy.Ins.InsCod,
Sco_GetDBStrFromScope (Hie_Lvl_CRS)); Sco_GetDBStrFromScope (Hie_Lvl_CRS));
case Hie_Lvl_CTR: case Hie_Lvl_CTR:
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with surveys", DB_QueryCOUNT ("can not get number of courses with surveys",
"SELECT COUNT(DISTINCT svy_surveys.Cod)" "SELECT COUNT(DISTINCT svy_surveys.Cod)"
" FROM deg_degrees," " FROM deg_degrees,"
"crs_courses," "crs_courses,"
"svy_surveys" "svy_surveys"
" WHERE deg_degrees.CtrCod=%ld" " WHERE deg_degrees.CtrCod=%ld"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=svy_surveys.Cod" " AND crs_courses.CrsCod=svy_surveys.Cod"
" AND svy_surveys.Scope='%s'", " AND svy_surveys.Scope='%s'",
Gbl.Hierarchy.Ctr.CtrCod, Gbl.Hierarchy.Ctr.CtrCod,
Sco_GetDBStrFromScope (Hie_Lvl_CRS)); Sco_GetDBStrFromScope (Hie_Lvl_CRS));
case Hie_Lvl_DEG: case Hie_Lvl_DEG:
@ -3966,8 +4005,9 @@ unsigned Svy_GetNumCoursesWithCrsSurveys (Hie_Lvl_Level_t Scope)
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with surveys", DB_QueryCOUNT ("can not get number of courses with surveys",
"SELECT COUNT(DISTINCT Cod)" "SELECT COUNT(DISTINCT Cod)"
" FROM svy_surveys" " FROM svy_surveys"
" WHERE Scope='%s' AND Cod=%ld", " WHERE Scope='%s'"
" AND Cod=%ld",
Sco_GetDBStrFromScope (Hie_Lvl_CRS), Sco_GetDBStrFromScope (Hie_Lvl_CRS),
Gbl.Hierarchy.Crs.CrsCod); Gbl.Hierarchy.Crs.CrsCod);
default: default:
@ -3994,7 +4034,7 @@ unsigned Svy_GetNumCrsSurveys (Hie_Lvl_Level_t Scope,unsigned *NumNotif)
DB_QuerySELECT (&mysql_res,"can not get number of surveys", DB_QuerySELECT (&mysql_res,"can not get number of surveys",
"SELECT COUNT(*)," "SELECT COUNT(*),"
"SUM(NumNotif)" "SUM(NumNotif)"
" FROM svy_surveys" " FROM svy_surveys"
" WHERE Scope='%s'", " WHERE Scope='%s'",
Sco_GetDBStrFromScope (Hie_Lvl_CRS)); Sco_GetDBStrFromScope (Hie_Lvl_CRS));
break; break;
@ -4002,17 +4042,17 @@ unsigned Svy_GetNumCrsSurveys (Hie_Lvl_Level_t Scope,unsigned *NumNotif)
DB_QuerySELECT (&mysql_res,"can not get number of surveys", DB_QuerySELECT (&mysql_res,"can not get number of surveys",
"SELECT COUNT(*)," "SELECT COUNT(*),"
"SUM(svy_surveys.NumNotif)" "SUM(svy_surveys.NumNotif)"
" FROM ins_instits," " FROM ins_instits,"
"ctr_centers," "ctr_centers,"
"deg_degrees," "deg_degrees,"
"crs_courses," "crs_courses,"
"svy_surveys" "svy_surveys"
" WHERE ins_instits.CtyCod=%ld" " WHERE ins_instits.CtyCod=%ld"
" AND ins_instits.InsCod=ctr_centers.InsCod" " AND ins_instits.InsCod=ctr_centers.InsCod"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod" " AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=svy_surveys.Cod" " AND crs_courses.CrsCod=svy_surveys.Cod"
" AND svy_surveys.Scope='%s'", " AND svy_surveys.Scope='%s'",
Gbl.Hierarchy.Cty.CtyCod, Gbl.Hierarchy.Cty.CtyCod,
Sco_GetDBStrFromScope (Hie_Lvl_CRS)); Sco_GetDBStrFromScope (Hie_Lvl_CRS));
break; break;
@ -4020,15 +4060,15 @@ unsigned Svy_GetNumCrsSurveys (Hie_Lvl_Level_t Scope,unsigned *NumNotif)
DB_QuerySELECT (&mysql_res,"can not get number of surveys", DB_QuerySELECT (&mysql_res,"can not get number of surveys",
"SELECT COUNT(*)," "SELECT COUNT(*),"
"SUM(svy_surveys.NumNotif)" "SUM(svy_surveys.NumNotif)"
" FROM ctr_centers," " FROM ctr_centers,"
"deg_degrees," "deg_degrees,"
"crs_courses," "crs_courses,"
"svy_surveys" "svy_surveys"
" WHERE ctr_centers.InsCod=%ld" " WHERE ctr_centers.InsCod=%ld"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod" " AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=svy_surveys.Cod" " AND crs_courses.CrsCod=svy_surveys.Cod"
" AND svy_surveys.Scope='%s'", " AND svy_surveys.Scope='%s'",
Gbl.Hierarchy.Ins.InsCod, Gbl.Hierarchy.Ins.InsCod,
Sco_GetDBStrFromScope (Hie_Lvl_CRS)); Sco_GetDBStrFromScope (Hie_Lvl_CRS));
break; break;
@ -4036,13 +4076,13 @@ unsigned Svy_GetNumCrsSurveys (Hie_Lvl_Level_t Scope,unsigned *NumNotif)
DB_QuerySELECT (&mysql_res,"can not get number of surveys", DB_QuerySELECT (&mysql_res,"can not get number of surveys",
"SELECT COUNT(*)," "SELECT COUNT(*),"
"SUM(svy_surveys.NumNotif)" "SUM(svy_surveys.NumNotif)"
" FROM deg_degrees," " FROM deg_degrees,"
"crs_courses," "crs_courses,"
"svy_surveys" "svy_surveys"
" WHERE deg_degrees.CtrCod=%ld" " WHERE deg_degrees.CtrCod=%ld"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=svy_surveys.Cod" " AND crs_courses.CrsCod=svy_surveys.Cod"
" AND svy_surveys.Scope='%s'", " AND svy_surveys.Scope='%s'",
Gbl.Hierarchy.Ctr.CtrCod, Gbl.Hierarchy.Ctr.CtrCod,
Sco_GetDBStrFromScope (Hie_Lvl_CRS)); Sco_GetDBStrFromScope (Hie_Lvl_CRS));
break; break;
@ -4050,11 +4090,11 @@ unsigned Svy_GetNumCrsSurveys (Hie_Lvl_Level_t Scope,unsigned *NumNotif)
DB_QuerySELECT (&mysql_res,"can not get number of surveys", DB_QuerySELECT (&mysql_res,"can not get number of surveys",
"SELECT COUNT(*)," "SELECT COUNT(*),"
"SUM(svy_surveys.NumNotif)" "SUM(svy_surveys.NumNotif)"
" FROM crs_courses," " FROM crs_courses,"
"svy_surveys" "svy_surveys"
" WHERE crs_courses.DegCod=%ld" " WHERE crs_courses.DegCod=%ld"
" AND crs_courses.CrsCod=svy_surveys.Cod" " AND crs_courses.CrsCod=svy_surveys.Cod"
" AND svy_surveys.Scope='%s'", " AND svy_surveys.Scope='%s'",
Gbl.Hierarchy.Deg.DegCod, Gbl.Hierarchy.Deg.DegCod,
Sco_GetDBStrFromScope (Hie_Lvl_CRS)); Sco_GetDBStrFromScope (Hie_Lvl_CRS));
break; break;
@ -4062,9 +4102,9 @@ unsigned Svy_GetNumCrsSurveys (Hie_Lvl_Level_t Scope,unsigned *NumNotif)
DB_QuerySELECT (&mysql_res,"can not get number of surveys", DB_QuerySELECT (&mysql_res,"can not get number of surveys",
"SELECT COUNT(*)," "SELECT COUNT(*),"
"SUM(NumNotif)" "SUM(NumNotif)"
" FROM svy_surveys" " FROM svy_surveys"
" WHERE svy_surveys.Scope='%s'" " WHERE svy_surveys.Scope='%s'"
" AND CrsCod=%ld", " AND CrsCod=%ld",
Sco_GetDBStrFromScope (Hie_Lvl_CRS), Sco_GetDBStrFromScope (Hie_Lvl_CRS),
Gbl.Hierarchy.Crs.CrsCod); Gbl.Hierarchy.Crs.CrsCod);
break; break;
@ -4109,101 +4149,102 @@ double Svy_GetNumQstsPerCrsSurvey (Hie_Lvl_Level_t Scope)
case Hie_Lvl_SYS: case Hie_Lvl_SYS:
DB_QuerySELECT (&mysql_res,"can not get number of questions" DB_QuerySELECT (&mysql_res,"can not get number of questions"
" per survey", " per survey",
"SELECT AVG(NumQsts) FROM" "SELECT AVG(NumQsts)"
" (SELECT COUNT(svy_questions.QstCod) AS NumQsts" " FROM (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" FROM svy_surveys," " FROM svy_surveys,"
"svy_questions" "svy_questions"
" WHERE svy_surveys.Scope='%s'" " WHERE svy_surveys.Scope='%s'"
" AND svy_surveys.SvyCod=svy_questions.SvyCod" " AND svy_surveys.SvyCod=svy_questions.SvyCod"
" GROUP BY svy_questions.SvyCod) AS NumQstsTable", " GROUP BY svy_questions.SvyCod) AS NumQstsTable",
Sco_GetDBStrFromScope (Hie_Lvl_CRS)); Sco_GetDBStrFromScope (Hie_Lvl_CRS));
break; break;
case Hie_Lvl_CTY: case Hie_Lvl_CTY:
DB_QuerySELECT (&mysql_res,"can not get number of questions" DB_QuerySELECT (&mysql_res,"can not get number of questions"
" per survey", " per survey",
"SELECT AVG(NumQsts) FROM" "SELECT AVG(NumQsts)"
" (SELECT COUNT(svy_questions.QstCod) AS NumQsts" " FROM (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" FROM ins_instits," " FROM ins_instits,"
"ctr_centers," "ctr_centers,"
"deg_degrees," "deg_degrees,"
"crs_courses," "crs_courses,"
"svy_surveys," "svy_surveys,"
"svy_questions" "svy_questions"
" WHERE ins_instits.CtyCod=%ld" " WHERE ins_instits.CtyCod=%ld"
" AND ins_instits.InsCod=ctr_centers.InsCod" " AND ins_instits.InsCod=ctr_centers.InsCod"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod" " AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=svy_surveys.Cod" " AND crs_courses.CrsCod=svy_surveys.Cod"
" AND svy_surveys.Scope='%s'" " AND svy_surveys.Scope='%s'"
" AND svy_surveys.SvyCod=svy_questions.SvyCod" " AND svy_surveys.SvyCod=svy_questions.SvyCod"
" GROUP BY svy_questions.SvyCod) AS NumQstsTable", " GROUP BY svy_questions.SvyCod) AS NumQstsTable",
Gbl.Hierarchy.Cty.CtyCod, Gbl.Hierarchy.Cty.CtyCod,
Sco_GetDBStrFromScope (Hie_Lvl_CRS)); Sco_GetDBStrFromScope (Hie_Lvl_CRS));
break; break;
case Hie_Lvl_INS: case Hie_Lvl_INS:
DB_QuerySELECT (&mysql_res,"can not get number of questions" DB_QuerySELECT (&mysql_res,"can not get number of questions"
" per survey", " per survey",
"SELECT AVG(NumQsts) FROM" "SELECT AVG(NumQsts)"
" (SELECT COUNT(svy_questions.QstCod) AS NumQsts" " FROM (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" FROM ctr_centers," " FROM ctr_centers,"
"deg_degrees," "deg_degrees,"
"crs_courses," "crs_courses,"
"svy_surveys," "svy_surveys,"
"svy_questions" "svy_questions"
" WHERE ctr_centers.InsCod=%ld" " WHERE ctr_centers.InsCod=%ld"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod" " AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=svy_surveys.Cod" " AND crs_courses.CrsCod=svy_surveys.Cod"
" AND svy_surveys.Scope='%s'" " AND svy_surveys.Scope='%s'"
" AND svy_surveys.SvyCod=svy_questions.SvyCod" " AND svy_surveys.SvyCod=svy_questions.SvyCod"
" GROUP BY svy_questions.SvyCod) AS NumQstsTable", " GROUP BY svy_questions.SvyCod) AS NumQstsTable",
Gbl.Hierarchy.Ins.InsCod, Gbl.Hierarchy.Ins.InsCod,
Sco_GetDBStrFromScope (Hie_Lvl_CRS)); Sco_GetDBStrFromScope (Hie_Lvl_CRS));
break; break;
case Hie_Lvl_CTR: case Hie_Lvl_CTR:
DB_QuerySELECT (&mysql_res,"can not get number of questions" DB_QuerySELECT (&mysql_res,"can not get number of questions"
" per survey", " per survey",
"SELECT AVG(NumQsts) FROM" "SELECT AVG(NumQsts)"
" (SELECT COUNT(svy_questions.QstCod) AS NumQsts" " FROM (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" FROM deg_degrees," " FROM deg_degrees,"
"crs_courses," "crs_courses,"
"svy_surveys," "svy_surveys,"
"svy_questions" "svy_questions"
" WHERE deg_degrees.CtrCod=%ld" " WHERE deg_degrees.CtrCod=%ld"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=svy_surveys.Cod" " AND crs_courses.CrsCod=svy_surveys.Cod"
" AND svy_surveys.Scope='%s'" " AND svy_surveys.Scope='%s'"
" AND svy_surveys.SvyCod=svy_questions.SvyCod" " AND svy_surveys.SvyCod=svy_questions.SvyCod"
" GROUP BY svy_questions.SvyCod) AS NumQstsTable", " GROUP BY svy_questions.SvyCod) AS NumQstsTable",
Gbl.Hierarchy.Ctr.CtrCod, Gbl.Hierarchy.Ctr.CtrCod,
Sco_GetDBStrFromScope (Hie_Lvl_CRS)); Sco_GetDBStrFromScope (Hie_Lvl_CRS));
break; break;
case Hie_Lvl_DEG: case Hie_Lvl_DEG:
DB_QuerySELECT (&mysql_res,"can not get number of questions" DB_QuerySELECT (&mysql_res,"can not get number of questions"
" per survey", " per survey",
"SELECT AVG(NumQsts) FROM" "SELECT AVG(NumQsts)"
" (SELECT COUNT(svy_questions.QstCod) AS NumQsts" " FROM (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" FROM crs_courses," " FROM crs_courses,"
"svy_surveys," "svy_surveys,"
"svy_questions" "svy_questions"
" WHERE crs_courses.DegCod=%ld" " WHERE crs_courses.DegCod=%ld"
" AND crs_courses.CrsCod=svy_surveys.Cod" " AND crs_courses.CrsCod=svy_surveys.Cod"
" AND svy_surveys.Scope='%s'" " AND svy_surveys.Scope='%s'"
" AND svy_surveys.SvyCod=svy_questions.SvyCod" " AND svy_surveys.SvyCod=svy_questions.SvyCod"
" GROUP BY svy_questions.SvyCod) AS NumQstsTable", " GROUP BY svy_questions.SvyCod) AS NumQstsTable",
Gbl.Hierarchy.Deg.DegCod, Gbl.Hierarchy.Deg.DegCod,
Sco_GetDBStrFromScope (Hie_Lvl_CRS)); Sco_GetDBStrFromScope (Hie_Lvl_CRS));
break; break;
case Hie_Lvl_CRS: case Hie_Lvl_CRS:
DB_QuerySELECT (&mysql_res,"can not get number of questions" DB_QuerySELECT (&mysql_res,"can not get number of questions"
" per survey", " per survey",
"SELECT AVG(NumQsts) FROM" "SELECT AVG(NumQsts)"
" (SELECT COUNT(svy_questions.QstCod) AS NumQsts" " FROM (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" FROM svy_surveys," " FROM svy_surveys,"
"svy_questions" "svy_questions"
" WHERE svy_surveys.Scope='%s' AND svy_surveys.Cod=%ld" " WHERE svy_surveys.Scope='%s'"
" AND svy_surveys.SvyCod=svy_questions.SvyCod" " AND svy_surveys.Cod=%ld"
" GROUP BY svy_questions.SvyCod) AS NumQstsTable", " AND svy_surveys.SvyCod=svy_questions.SvyCod"
" GROUP BY svy_questions.SvyCod) AS NumQstsTable",
Sco_GetDBStrFromScope (Hie_Lvl_CRS),Gbl.Hierarchy.Crs.CrsCod); Sco_GetDBStrFromScope (Hie_Lvl_CRS),Gbl.Hierarchy.Crs.CrsCod);
break; break;
default: default:

View File

@ -207,9 +207,9 @@ static void SysCfg_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom)
"AVG(Longitude)," // row[1] "AVG(Longitude)," // row[1]
"GREATEST(MAX(Latitude)-MIN(Latitude)," "GREATEST(MAX(Latitude)-MIN(Latitude),"
"MAX(Longitude)-MIN(Longitude))" // row[2] "MAX(Longitude)-MIN(Longitude))" // row[2]
" FROM ctr_centers" " FROM ctr_centers"
" WHERE Latitude<>0" " WHERE Latitude<>0"
" AND Longitude<>0") < 0) " AND Longitude<>0") < 0)
Lay_NotEnoughMemoryExit (); Lay_NotEnoughMemoryExit ();
Map_GetCoordAndZoom (Coord,Zoom,Query); Map_GetCoordAndZoom (Coord,Zoom,Query);
free (Query); free (Query);
@ -256,9 +256,9 @@ static void SysCfg_Map (void)
NumCtrs = (unsigned) NumCtrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get centers with coordinates", DB_QuerySELECT (&mysql_res,"can not get centers with coordinates",
"SELECT CtrCod" // row[0] "SELECT CtrCod" // row[0]
" FROM ctr_centers" " FROM ctr_centers"
" WHERE ctr_centers.Latitude<>0" " WHERE ctr_centers.Latitude<>0"
" AND ctr_centers.Longitude<>0"); " AND ctr_centers.Longitude<>0");
/* Add a marker and a popup for each center */ /* Add a marker and a popup for each center */
for (NumCtr = 0; for (NumCtr = 0;

View File

@ -129,7 +129,8 @@ bool Tag_CheckIfCurrentCrsHasTestTags (void)
{ {
/***** Get available tags from database *****/ /***** Get available tags from database *****/
return (DB_QueryCOUNT ("can not check if course has tags", return (DB_QueryCOUNT ("can not check if course has tags",
"SELECT COUNT(*) FROM tst_tags" "SELECT COUNT(*)"
" FROM tst_tags"
" WHERE CrsCod=%ld", " WHERE CrsCod=%ld",
Gbl.Hierarchy.Crs.CrsCod) != 0); Gbl.Hierarchy.Crs.CrsCod) != 0);
} }
@ -146,7 +147,7 @@ unsigned Tag_GetAllTagsFromCurrentCrs (MYSQL_RES **mysql_res)
"SELECT TagCod," // row[0] "SELECT TagCod," // row[0]
"TagTxt," // row[1] "TagTxt," // row[1]
"TagHidden" // row[2] "TagHidden" // row[2]
" FROM tst_tags" " FROM tst_tags"
" WHERE CrsCod=%ld" " WHERE CrsCod=%ld"
" ORDER BY TagTxt", " ORDER BY TagTxt",
Gbl.Hierarchy.Crs.CrsCod); Gbl.Hierarchy.Crs.CrsCod);
@ -163,8 +164,9 @@ unsigned Tag_GetEnabledTagsFromThisCrs (MYSQL_RES **mysql_res)
return (unsigned) DB_QuerySELECT (mysql_res,"can not get available enabled tags", return (unsigned) DB_QuerySELECT (mysql_res,"can not get available enabled tags",
"SELECT TagCod," // row[0] "SELECT TagCod," // row[0]
"TagTxt" // row[1] "TagTxt" // row[1]
" FROM tst_tags" " FROM tst_tags"
" WHERE CrsCod=%ld AND TagHidden='N'" " WHERE CrsCod=%ld"
" AND TagHidden='N'"
" ORDER BY TagTxt", " ORDER BY TagTxt",
Gbl.Hierarchy.Crs.CrsCod); Gbl.Hierarchy.Crs.CrsCod);
} }
@ -290,8 +292,9 @@ void Tag_RenameTag (void)
DB_Query ("can not create temporary table", DB_Query ("can not create temporary table",
"CREATE TEMPORARY TABLE tst_question_tags_tmp" "CREATE TEMPORARY TABLE tst_question_tags_tmp"
" ENGINE=MEMORY" " ENGINE=MEMORY"
" SELECT QstCod FROM tst_question_tags" " SELECT QstCod"
" WHERE TagCod=%ld", " FROM tst_question_tags"
" WHERE TagCod=%ld",
ExistingTagCod); ExistingTagCod);
/* Remove old tag in questions where it would be repeated */ /* Remove old tag in questions where it would be repeated */
@ -299,18 +302,20 @@ void Tag_RenameTag (void)
DB_QueryDELETE ("can not remove a tag from some questions", DB_QueryDELETE ("can not remove a tag from some questions",
"DELETE FROM tst_question_tags" "DELETE FROM tst_question_tags"
" WHERE TagCod=%ld" " WHERE TagCod=%ld"
" AND QstCod IN" " AND QstCod IN"
" (SELECT QstCod FROM tst_question_tags_tmp)", " (SELECT QstCod"
" FROM tst_question_tags_tmp)",
OldTagCod); OldTagCod);
/* Change old tag to new tag in questions where it would not be repeated */ /* Change old tag to new tag in questions where it would not be repeated */
// New tag did not exist for a question ==> change old tag to new tag // New tag did not exist for a question ==> change old tag to new tag
DB_QueryUPDATE ("can not update a tag in some questions", DB_QueryUPDATE ("can not update a tag in some questions",
"UPDATE tst_question_tags" "UPDATE tst_question_tags"
" SET TagCod=%ld" " SET TagCod=%ld"
" WHERE TagCod=%ld" " WHERE TagCod=%ld"
" AND QstCod NOT IN" " AND QstCod NOT IN"
" (SELECT QstCod FROM tst_question_tags_tmp)", " (SELECT QstCod"
" FROM tst_question_tags_tmp)",
ExistingTagCod, ExistingTagCod,
OldTagCod); OldTagCod);
@ -321,17 +326,22 @@ void Tag_RenameTag (void)
/***** Delete old tag from tst_tags /***** Delete old tag from tst_tags
because it is not longer used *****/ because it is not longer used *****/
DB_QueryDELETE ("can not remove old tag", DB_QueryDELETE ("can not remove old tag",
"DELETE FROM tst_tags WHERE TagCod=%ld", "DELETE FROM tst_tags"
" WHERE TagCod=%ld",
OldTagCod); OldTagCod);
} }
else // Renaming is easy else // Renaming is easy
{ {
/***** Simple update replacing each instance of the old tag by the new tag *****/ /***** Simple update replacing each instance of the old tag by the new tag *****/
DB_QueryUPDATE ("can not update tag", DB_QueryUPDATE ("can not update tag",
"UPDATE tst_tags SET TagTxt='%s',ChangeTime=NOW()" "UPDATE tst_tags"
" SET TagTxt='%s',"
"ChangeTime=NOW()"
" WHERE tst_tags.CrsCod=%ld" " WHERE tst_tags.CrsCod=%ld"
" AND tst_tags.TagTxt='%s'", " AND tst_tags.TagTxt='%s'",
NewTagTxt,Gbl.Hierarchy.Crs.CrsCod,OldTagTxt); NewTagTxt,
Gbl.Hierarchy.Crs.CrsCod,
OldTagTxt);
} }
/***** Write message to show the change made *****/ /***** Write message to show the change made *****/
@ -359,8 +369,10 @@ static long Tag_GetTagCodFromTagTxt (const char *TagTxt)
/***** Get tag code from database *****/ /***** Get tag code from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get tag", NumRows = DB_QuerySELECT (&mysql_res,"can not get tag",
"SELECT TagCod FROM tst_tags" "SELECT TagCod"
" WHERE CrsCod=%ld AND TagTxt='%s'", " FROM tst_tags"
" WHERE CrsCod=%ld"
" AND TagTxt='%s'",
Gbl.Hierarchy.Crs.CrsCod,TagTxt); Gbl.Hierarchy.Crs.CrsCod,TagTxt);
if (NumRows == 1) if (NumRows == 1)
{ {
@ -664,11 +676,13 @@ void Tag_RemoveUnusedTagsFromCrs (long CrsCod)
/***** Remove unused tags from tst_tags *****/ /***** Remove unused tags from tst_tags *****/
DB_QueryDELETE ("can not remove unused tags", DB_QueryDELETE ("can not remove unused tags",
"DELETE FROM tst_tags" "DELETE FROM tst_tags"
" WHERE CrsCod=%ld AND TagCod NOT IN" " WHERE CrsCod=%ld"
" (SELECT DISTINCT tst_question_tags.TagCod" " AND TagCod NOT IN"
" FROM tst_questions,tst_question_tags" " (SELECT DISTINCT tst_question_tags.TagCod"
" WHERE tst_questions.CrsCod=%ld" " FROM tst_questions,"
" AND tst_questions.QstCod=tst_question_tags.QstCod)", "tst_question_tags"
" WHERE tst_questions.CrsCod=%ld"
" AND tst_questions.QstCod=tst_question_tags.QstCod)",
CrsCod, CrsCod,
CrsCod); CrsCod);
} }

View File

@ -1361,7 +1361,7 @@ bool Tst_CheckIfCourseHaveTestsAndPluggableIsUnknown (void)
/***** Get pluggability of tests for current course from database *****/ /***** Get pluggability of tests for current course from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get configuration of test", NumRows = DB_QuerySELECT (&mysql_res,"can not get configuration of test",
"SELECT Pluggable" // row[0] "SELECT Pluggable" // row[0]
" FROM tst_config" " FROM tst_config"
" WHERE CrsCod=%ld", " WHERE CrsCod=%ld",
Gbl.Hierarchy.Crs.CrsCod); Gbl.Hierarchy.Crs.CrsCod);
@ -1757,7 +1757,7 @@ static void Tst_GetQuestions (struct Tst_Test *Test,MYSQL_RES **mysql_res)
/***** Select questions *****/ /***** Select questions *****/
/* Start query */ /* Start query */
Str_Copy (Query,"SELECT tst_questions.QstCod" // row[0] Str_Copy (Query,"SELECT tst_questions.QstCod" // row[0]
" FROM tst_questions",Tst_MAX_BYTES_QUERY_TEST); " FROM tst_questions",Tst_MAX_BYTES_QUERY_TEST);
if (!Test->Tags.All) if (!Test->Tags.All)
Str_Concat (Query,",tst_question_tags,tst_tags",Tst_MAX_BYTES_QUERY_TEST); Str_Concat (Query,",tst_question_tags,tst_tags",Tst_MAX_BYTES_QUERY_TEST);
@ -1908,16 +1908,17 @@ static void Tst_GetQuestionsForNewTestFromDB (struct Tst_Test *Test,
"SELECT DISTINCTROW tst_questions.QstCod," // row[0] "SELECT DISTINCTROW tst_questions.QstCod," // row[0]
"tst_questions.AnsType," // row[1] "tst_questions.AnsType," // row[1]
"tst_questions.Shuffle" // row[2] "tst_questions.Shuffle" // row[2]
" FROM tst_questions,tst_question_tags,tst_tags" " FROM tst_questions,tst_question_tags,tst_tags"
" WHERE tst_questions.CrsCod=%ld" " WHERE tst_questions.CrsCod=%ld"
" AND tst_questions.QstCod NOT IN" " AND tst_questions.QstCod NOT IN"
" (SELECT tst_question_tags.QstCod" " (SELECT tst_question_tags.QstCod"
" FROM tst_tags,tst_question_tags" " FROM tst_tags,tst_question_tags"
" WHERE tst_tags.CrsCod=%ld AND tst_tags.TagHidden='Y'" " WHERE tst_tags.CrsCod=%ld"
" AND tst_tags.TagCod=tst_question_tags.TagCod)" " AND tst_tags.TagHidden='Y'"
" AND tst_questions.QstCod=tst_question_tags.QstCod" " AND tst_tags.TagCod=tst_question_tags.TagCod)"
" AND tst_question_tags.TagCod=tst_tags.TagCod" " AND tst_questions.QstCod=tst_question_tags.QstCod"
" AND tst_tags.CrsCod=%ld", " AND tst_question_tags.TagCod=tst_tags.TagCod"
" AND tst_tags.CrsCod=%ld",
Gbl.Hierarchy.Crs.CrsCod, Gbl.Hierarchy.Crs.CrsCod,
Gbl.Hierarchy.Crs.CrsCod, Gbl.Hierarchy.Crs.CrsCod,
Gbl.Hierarchy.Crs.CrsCod); Gbl.Hierarchy.Crs.CrsCod);
@ -2671,7 +2672,7 @@ unsigned Tst_GetNumAnswersQst (long QstCod)
{ {
return (unsigned) DB_QueryCOUNT ("can not get number of answers of a question", return (unsigned) DB_QueryCOUNT ("can not get number of answers of a question",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM tst_answers" " FROM tst_answers"
" WHERE QstCod=%ld", " WHERE QstCod=%ld",
QstCod); QstCod);
} }
@ -2687,7 +2688,7 @@ void Tst_GetAnswersQst (struct Tst_Question *Question,MYSQL_RES **mysql_res,
"Feedback," // row[2] "Feedback," // row[2]
"MedCod," // row[3] "MedCod," // row[3]
"Correct" // row[4] "Correct" // row[4]
" FROM tst_answers" " FROM tst_answers"
" WHERE QstCod=%ld" " WHERE QstCod=%ld"
" ORDER BY %s", " ORDER BY %s",
Question->QstCod, Question->QstCod,
@ -2912,10 +2913,11 @@ unsigned long Tst_GetTagsQst (long QstCod,MYSQL_RES **mysql_res)
/***** Get the tags of a question from database *****/ /***** Get the tags of a question from database *****/
return DB_QuerySELECT (mysql_res,"can not get the tags of a question", return DB_QuerySELECT (mysql_res,"can not get the tags of a question",
"SELECT tst_tags.TagTxt" // row[0] "SELECT tst_tags.TagTxt" // row[0]
" FROM tst_question_tags,tst_tags" " FROM tst_question_tags,"
"tst_tags"
" WHERE tst_question_tags.QstCod=%ld" " WHERE tst_question_tags.QstCod=%ld"
" AND tst_question_tags.TagCod=tst_tags.TagCod" " AND tst_question_tags.TagCod=tst_tags.TagCod"
" AND tst_tags.CrsCod=%ld" " AND tst_tags.CrsCod=%ld"
" ORDER BY tst_question_tags.TagInd", " ORDER BY tst_question_tags.TagInd",
QstCod,Gbl.Hierarchy.Crs.CrsCod); QstCod,Gbl.Hierarchy.Crs.CrsCod);
} }
@ -3818,7 +3820,7 @@ Tst_AnswerType_t Tst_GetQstAnswerTypeFromDB (long QstCod)
/***** Get type of answer from database *****/ /***** Get type of answer from database *****/
if (!DB_QuerySELECT (&mysql_res,"can not get the type of a question", if (!DB_QuerySELECT (&mysql_res,"can not get the type of a question",
"SELECT AnsType" // row[0] "SELECT AnsType" // row[0]
" FROM tst_questions" " FROM tst_questions"
" WHERE QstCod=%ld", " WHERE QstCod=%ld",
QstCod)) QstCod))
Lay_ShowErrorAndExit ("Question does not exist."); Lay_ShowErrorAndExit ("Question does not exist.");
@ -3857,9 +3859,9 @@ bool Tst_GetQstDataFromDB (struct Tst_Question *Question)
"NumHits," // row[6] "NumHits," // row[6]
"NumHitsNotBlank," // row[7] "NumHitsNotBlank," // row[7]
"Score" // row[8] "Score" // row[8]
" FROM tst_questions" " FROM tst_questions"
" WHERE QstCod=%ld" " WHERE QstCod=%ld"
" AND CrsCod=%ld", // Extra check " AND CrsCod=%ld", // Extra check
Question->QstCod, Question->QstCod,
Gbl.Hierarchy.Crs.CrsCod) != 0); Gbl.Hierarchy.Crs.CrsCod) != 0);
@ -4018,15 +4020,17 @@ static long Tst_GetMedCodFromDB (long CrsCod,long QstCod,int NumOpt)
// Get media associated to stem // Get media associated to stem
NumRows = DB_QuerySELECT (&mysql_res,"can not get media", NumRows = DB_QuerySELECT (&mysql_res,"can not get media",
"SELECT MedCod" // row[0] "SELECT MedCod" // row[0]
" FROM tst_questions" " FROM tst_questions"
" WHERE QstCod=%ld AND CrsCod=%ld", " WHERE QstCod=%ld"
" AND CrsCod=%ld",
QstCod,CrsCod); QstCod,CrsCod);
else else
// Get media associated to answer // Get media associated to answer
NumRows = DB_QuerySELECT (&mysql_res,"can not get media", NumRows = DB_QuerySELECT (&mysql_res,"can not get media",
"SELECT MedCod" // row[0] "SELECT MedCod" // row[0]
" FROM tst_answers" " FROM tst_answers"
" WHERE QstCod=%ld AND AnsInd=%u", " WHERE QstCod=%ld"
" AND AnsInd=%u",
QstCod,(unsigned) NumOpt); QstCod,(unsigned) NumOpt);
if (NumRows) if (NumRows)
@ -4533,8 +4537,11 @@ bool Tst_CheckIfQuestionExistsInDB (struct Tst_Question *Question)
NumQstsWithThisStem = NumQstsWithThisStem =
(unsigned) DB_QuerySELECT (&mysql_res_qst,"can not check" (unsigned) DB_QuerySELECT (&mysql_res_qst,"can not check"
" if a question exists", " if a question exists",
"SELECT QstCod FROM tst_questions" "SELECT QstCod"
" WHERE CrsCod=%ld AND AnsType='%s' AND Stem='%s'", " FROM tst_questions"
" WHERE CrsCod=%ld"
" AND AnsType='%s'"
" AND Stem='%s'",
Gbl.Hierarchy.Crs.CrsCod, Gbl.Hierarchy.Crs.CrsCod,
Tst_StrAnswerTypesDB[Question->Answer.Type], Tst_StrAnswerTypesDB[Question->Answer.Type],
Question->Stem); Question->Stem);
@ -4556,8 +4563,10 @@ bool Tst_CheckIfQuestionExistsInDB (struct Tst_Question *Question)
NumOptsExistingQstInDB = NumOptsExistingQstInDB =
(unsigned) DB_QuerySELECT (&mysql_res_ans,"can not get the answer" (unsigned) DB_QuerySELECT (&mysql_res_ans,"can not get the answer"
" of a question", " of a question",
"SELECT Answer FROM tst_answers" "SELECT Answer"
" WHERE QstCod=%ld ORDER BY AnsInd", " FROM tst_answers"
" WHERE QstCod=%ld"
" ORDER BY AnsInd",
Question->QstCod); Question->QstCod);
switch (Question->Answer.Type) switch (Question->Answer.Type)
@ -5214,9 +5223,9 @@ static void Tst_RemoveMediaFromStemOfQst (long CrsCod,long QstCod)
NumMedia = NumMedia =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get media", (unsigned) DB_QuerySELECT (&mysql_res,"can not get media",
"SELECT MedCod" // row[0] "SELECT MedCod" // row[0]
" FROM tst_questions" " FROM tst_questions"
" WHERE QstCod=%ld" " WHERE QstCod=%ld"
" AND CrsCod=%ld", // Extra check " AND CrsCod=%ld", // Extra check
QstCod,CrsCod); QstCod,CrsCod);
/***** Go over result removing media *****/ /***** Go over result removing media *****/
@ -5239,12 +5248,15 @@ static void Tst_RemoveMediaFromAllAnsOfQst (long CrsCod,long QstCod)
NumMedia = NumMedia =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get media", (unsigned) DB_QuerySELECT (&mysql_res,"can not get media",
"SELECT tst_answers.MedCod" // row[0] "SELECT tst_answers.MedCod" // row[0]
" FROM tst_answers,tst_questions" " FROM tst_answers,"
"tst_questions"
" WHERE tst_answers.QstCod=%ld" " WHERE tst_answers.QstCod=%ld"
" AND tst_answers.QstCod=tst_questions.QstCod" " AND tst_answers.QstCod=tst_questions.QstCod"
" AND tst_questions.CrsCod=%ld" // Extra check " AND tst_questions.CrsCod=%ld" // Extra check
" AND tst_questions.QstCod=%ld", // Extra check " AND tst_questions.QstCod=%ld", // Extra check
QstCod,CrsCod,QstCod); QstCod,
CrsCod,
QstCod);
/***** Go over result removing media *****/ /***** Go over result removing media *****/
Med_RemoveMediaFromAllRows (NumMedia,mysql_res); Med_RemoveMediaFromAllRows (NumMedia,mysql_res);
@ -5266,7 +5278,7 @@ static void Tst_RemoveAllMedFilesFromStemOfAllQstsInCrs (long CrsCod)
NumMedia = NumMedia =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get media", (unsigned) DB_QuerySELECT (&mysql_res,"can not get media",
"SELECT MedCod" // row[0] "SELECT MedCod" // row[0]
" FROM tst_questions" " FROM tst_questions"
" WHERE CrsCod=%ld", " WHERE CrsCod=%ld",
CrsCod); CrsCod);
@ -5290,9 +5302,10 @@ static void Tst_RemoveAllMedFilesFromAnsOfAllQstsInCrs (long CrsCod)
NumMedia = NumMedia =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get media", (unsigned) DB_QuerySELECT (&mysql_res,"can not get media",
"SELECT tst_answers.MedCod" // row[0] "SELECT tst_answers.MedCod" // row[0]
" FROM tst_questions,tst_answers" " FROM tst_questions,"
"tst_answers"
" WHERE tst_questions.CrsCod=%ld" " WHERE tst_questions.CrsCod=%ld"
" AND tst_questions.QstCod=tst_answers.QstCod", " AND tst_questions.QstCod=tst_answers.QstCod",
CrsCod); CrsCod);
/***** Go over result removing media files *****/ /***** Go over result removing media files *****/
@ -5351,13 +5364,13 @@ static unsigned Tst_GetNumTstQuestions (Hie_Lvl_Level_t Scope,Tst_AnswerType_t A
"SELECT COUNT(*)," "SELECT COUNT(*),"
"SUM(NumHits)," "SUM(NumHits),"
"SUM(Score)" "SUM(Score)"
" FROM tst_questions"); " FROM tst_questions");
else else
DB_QuerySELECT (&mysql_res,"can not get number of test questions", DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*)," "SELECT COUNT(*),"
"SUM(NumHits)," "SUM(NumHits),"
"SUM(Score)" "SUM(Score)"
" FROM tst_questions" " FROM tst_questions"
" WHERE AnsType='%s'", " WHERE AnsType='%s'",
Tst_StrAnswerTypesDB[AnsType]); Tst_StrAnswerTypesDB[AnsType]);
break; break;
@ -5367,33 +5380,33 @@ static unsigned Tst_GetNumTstQuestions (Hie_Lvl_Level_t Scope,Tst_AnswerType_t A
"SELECT COUNT(*)," "SELECT COUNT(*),"
"SUM(NumHits)," "SUM(NumHits),"
"SUM(Score)" "SUM(Score)"
" FROM ins_instits," " FROM ins_instits,"
"ctr_centers," "ctr_centers,"
"deg_degrees," "deg_degrees,"
"crs_courses," "crs_courses,"
"tst_questions" "tst_questions"
" WHERE ins_instits.CtyCod=%ld" " WHERE ins_instits.CtyCod=%ld"
" AND ins_instits.InsCod=ctr_centers.InsCod" " AND ins_instits.InsCod=ctr_centers.InsCod"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod" " AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=tst_questions.CrsCod", " AND crs_courses.CrsCod=tst_questions.CrsCod",
Gbl.Hierarchy.Cty.CtyCod); Gbl.Hierarchy.Cty.CtyCod);
else else
DB_QuerySELECT (&mysql_res,"can not get number of test questions", DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*)," "SELECT COUNT(*),"
"SUM(NumHits)," "SUM(NumHits),"
"SUM(Score)" "SUM(Score)"
" FROM ins_instits," " FROM ins_instits,"
"ctr_centers," "ctr_centers,"
"deg_degrees," "deg_degrees,"
"crs_courses," "crs_courses,"
"tst_questions" "tst_questions"
" WHERE ins_instits.CtyCod=%ld" " WHERE ins_instits.CtyCod=%ld"
" AND ins_instits.InsCod=ctr_centers.InsCod" " AND ins_instits.InsCod=ctr_centers.InsCod"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod" " AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=tst_questions.CrsCod" " AND crs_courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.AnsType='%s'", " AND tst_questions.AnsType='%s'",
Gbl.Hierarchy.Cty.CtyCod, Gbl.Hierarchy.Cty.CtyCod,
Tst_StrAnswerTypesDB[AnsType]); Tst_StrAnswerTypesDB[AnsType]);
break; break;
@ -5403,29 +5416,29 @@ static unsigned Tst_GetNumTstQuestions (Hie_Lvl_Level_t Scope,Tst_AnswerType_t A
"SELECT COUNT(*)," "SELECT COUNT(*),"
"SUM(NumHits)," "SUM(NumHits),"
"SUM(Score)" "SUM(Score)"
" FROM ctr_centers," " FROM ctr_centers,"
"deg_degrees," "deg_degrees,"
"crs_courses," "crs_courses,"
"tst_questions" "tst_questions"
" WHERE ctr_centers.InsCod=%ld" " WHERE ctr_centers.InsCod=%ld"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod" " AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=tst_questions.CrsCod", " AND crs_courses.CrsCod=tst_questions.CrsCod",
Gbl.Hierarchy.Ins.InsCod); Gbl.Hierarchy.Ins.InsCod);
else else
DB_QuerySELECT (&mysql_res,"can not get number of test questions", DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*)," "SELECT COUNT(*),"
"SUM(NumHits)," "SUM(NumHits),"
"SUM(Score)" "SUM(Score)"
" FROM ctr_centers," " FROM ctr_centers,"
"deg_degrees," "deg_degrees,"
"crs_courses," "crs_courses,"
"tst_questions" "tst_questions"
" WHERE ctr_centers.InsCod=%ld" " WHERE ctr_centers.InsCod=%ld"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod" " AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=tst_questions.CrsCod" " AND crs_courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.AnsType='%s'", " AND tst_questions.AnsType='%s'",
Gbl.Hierarchy.Ins.InsCod, Gbl.Hierarchy.Ins.InsCod,
Tst_StrAnswerTypesDB[AnsType]); Tst_StrAnswerTypesDB[AnsType]);
break; break;
@ -5435,25 +5448,25 @@ static unsigned Tst_GetNumTstQuestions (Hie_Lvl_Level_t Scope,Tst_AnswerType_t A
"SELECT COUNT(*)," "SELECT COUNT(*),"
"SUM(NumHits)," "SUM(NumHits),"
"SUM(Score)" "SUM(Score)"
" FROM deg_degrees," " FROM deg_degrees,"
"crs_courses," "crs_courses,"
"tst_questions" "tst_questions"
" WHERE deg_degrees.CtrCod=%ld" " WHERE deg_degrees.CtrCod=%ld"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=tst_questions.CrsCod", " AND crs_courses.CrsCod=tst_questions.CrsCod",
Gbl.Hierarchy.Ctr.CtrCod); Gbl.Hierarchy.Ctr.CtrCod);
else else
DB_QuerySELECT (&mysql_res,"can not get number of test questions", DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*)," "SELECT COUNT(*),"
"SUM(NumHits)," "SUM(NumHits),"
"SUM(Score)" "SUM(Score)"
" FROM deg_degrees," " FROM deg_degrees,"
"crs_courses," "crs_courses,"
"tst_questions" "tst_questions"
" WHERE deg_degrees.CtrCod=%ld" " WHERE deg_degrees.CtrCod=%ld"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=tst_questions.CrsCod" " AND crs_courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.AnsType='%s'", " AND tst_questions.AnsType='%s'",
Gbl.Hierarchy.Ctr.CtrCod, Gbl.Hierarchy.Ctr.CtrCod,
Tst_StrAnswerTypesDB[AnsType]); Tst_StrAnswerTypesDB[AnsType]);
break; break;
@ -5463,21 +5476,21 @@ static unsigned Tst_GetNumTstQuestions (Hie_Lvl_Level_t Scope,Tst_AnswerType_t A
"SELECT COUNT(*)," "SELECT COUNT(*),"
"SUM(NumHits)," "SUM(NumHits),"
"SUM(Score)" "SUM(Score)"
" FROM crs_courses," " FROM crs_courses,"
"tst_questions" "tst_questions"
" WHERE crs_courses.DegCod=%ld" " WHERE crs_courses.DegCod=%ld"
" AND crs_courses.CrsCod=tst_questions.CrsCod", " AND crs_courses.CrsCod=tst_questions.CrsCod",
Gbl.Hierarchy.Deg.DegCod); Gbl.Hierarchy.Deg.DegCod);
else else
DB_QuerySELECT (&mysql_res,"can not get number of test questions", DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*)," "SELECT COUNT(*),"
"SUM(NumHits)," "SUM(NumHits),"
"SUM(Score)" "SUM(Score)"
" FROM crs_courses," " FROM crs_courses,"
"tst_questions" "tst_questions"
" WHERE crs_courses.DegCod=%ld" " WHERE crs_courses.DegCod=%ld"
" AND crs_courses.CrsCod=tst_questions.CrsCod" " AND crs_courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.AnsType='%s'", " AND tst_questions.AnsType='%s'",
Gbl.Hierarchy.Deg.DegCod, Gbl.Hierarchy.Deg.DegCod,
Tst_StrAnswerTypesDB[AnsType]); Tst_StrAnswerTypesDB[AnsType]);
break; break;
@ -5487,7 +5500,7 @@ static unsigned Tst_GetNumTstQuestions (Hie_Lvl_Level_t Scope,Tst_AnswerType_t A
"SELECT COUNT(*)," "SELECT COUNT(*),"
"SUM(NumHits)," "SUM(NumHits),"
"SUM(Score)" "SUM(Score)"
" FROM tst_questions" " FROM tst_questions"
" WHERE CrsCod=%ld", " WHERE CrsCod=%ld",
Gbl.Hierarchy.Crs.CrsCod); Gbl.Hierarchy.Crs.CrsCod);
else else
@ -5495,8 +5508,9 @@ static unsigned Tst_GetNumTstQuestions (Hie_Lvl_Level_t Scope,Tst_AnswerType_t A
"SELECT COUNT(*)," "SELECT COUNT(*),"
"SUM(NumHits)," "SUM(NumHits),"
"SUM(Score)" "SUM(Score)"
" FROM tst_questions" " FROM tst_questions"
" WHERE CrsCod=%ld AND AnsType='%s'", " WHERE CrsCod=%ld"
" AND AnsType='%s'",
Gbl.Hierarchy.Crs.CrsCod, Gbl.Hierarchy.Crs.CrsCod,
Tst_StrAnswerTypesDB[AnsType]); Tst_StrAnswerTypesDB[AnsType]);
break; break;
@ -5548,12 +5562,12 @@ static unsigned Tst_GetNumCoursesWithTstQuestions (Hie_Lvl_Level_t Scope,Tst_Ans
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with test questions", DB_QueryCOUNT ("can not get number of courses with test questions",
"SELECT COUNT(DISTINCT CrsCod)" "SELECT COUNT(DISTINCT CrsCod)"
" FROM tst_questions"); " FROM tst_questions");
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with test questions", DB_QueryCOUNT ("can not get number of courses with test questions",
"SELECT COUNT(DISTINCT CrsCod)" "SELECT COUNT(DISTINCT CrsCod)"
" FROM tst_questions" " FROM tst_questions"
" WHERE AnsType='%s'", " WHERE AnsType='%s'",
Tst_StrAnswerTypesDB[AnsType]); Tst_StrAnswerTypesDB[AnsType]);
case Hie_Lvl_CTY: case Hie_Lvl_CTY:
@ -5561,32 +5575,32 @@ static unsigned Tst_GetNumCoursesWithTstQuestions (Hie_Lvl_Level_t Scope,Tst_Ans
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with test questions", DB_QueryCOUNT ("can not get number of courses with test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)" "SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM ins_instits," " FROM ins_instits,"
"ctr_centers," "ctr_centers,"
"deg_degrees," "deg_degrees,"
"crs_courses," "crs_courses,"
"tst_questions" "tst_questions"
" WHERE ins_instits.CtyCod=%ld" " WHERE ins_instits.CtyCod=%ld"
" AND ins_instits.InsCod=ctr_centers.InsCod" " AND ins_instits.InsCod=ctr_centers.InsCod"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod" " AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=tst_questions.CrsCod", " AND crs_courses.CrsCod=tst_questions.CrsCod",
Gbl.Hierarchy.Cty.CtyCod); Gbl.Hierarchy.Cty.CtyCod);
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with test questions", DB_QueryCOUNT ("can not get number of courses with test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)" "SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM ins_instits," " FROM ins_instits,"
"ctr_centers," "ctr_centers,"
"deg_degrees," "deg_degrees,"
"crs_courses," "crs_courses,"
"tst_questions" "tst_questions"
" WHERE ins_instits.CtyCod=%ld" " WHERE ins_instits.CtyCod=%ld"
" AND ins_instits.InsCod=ctr_centers.InsCod" " AND ins_instits.InsCod=ctr_centers.InsCod"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod" " AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=tst_questions.CrsCod" " AND crs_courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.AnsType='%s'", " AND tst_questions.AnsType='%s'",
Gbl.Hierarchy.Cty.CtyCod, Gbl.Hierarchy.Cty.CtyCod,
Tst_StrAnswerTypesDB[AnsType]); Tst_StrAnswerTypesDB[AnsType]);
case Hie_Lvl_INS: case Hie_Lvl_INS:
@ -5594,28 +5608,28 @@ static unsigned Tst_GetNumCoursesWithTstQuestions (Hie_Lvl_Level_t Scope,Tst_Ans
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with test questions", DB_QueryCOUNT ("can not get number of courses with test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)" "SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM ctr_centers," " FROM ctr_centers,"
"deg_degrees," "deg_degrees,"
"crs_courses," "crs_courses,"
"tst_questions" "tst_questions"
" WHERE ctr_centers.InsCod=%ld" " WHERE ctr_centers.InsCod=%ld"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod" " AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=tst_questions.CrsCod", " AND crs_courses.CrsCod=tst_questions.CrsCod",
Gbl.Hierarchy.Ins.InsCod); Gbl.Hierarchy.Ins.InsCod);
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with test questions", DB_QueryCOUNT ("can not get number of courses with test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)" "SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM ctr_centers," " FROM ctr_centers,"
"deg_degrees," "deg_degrees,"
"crs_courses," "crs_courses,"
"tst_questions" "tst_questions"
" WHERE ctr_centers.InsCod=%ld" " WHERE ctr_centers.InsCod=%ld"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod" " AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=tst_questions.CrsCod" " AND crs_courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.AnsType='%s'", " AND tst_questions.AnsType='%s'",
Gbl.Hierarchy.Ins.InsCod, Gbl.Hierarchy.Ins.InsCod,
Tst_StrAnswerTypesDB[AnsType]); Tst_StrAnswerTypesDB[AnsType]);
case Hie_Lvl_CTR: case Hie_Lvl_CTR:
@ -5623,24 +5637,24 @@ static unsigned Tst_GetNumCoursesWithTstQuestions (Hie_Lvl_Level_t Scope,Tst_Ans
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with test questions", DB_QueryCOUNT ("can not get number of courses with test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)" "SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM deg_degrees," " FROM deg_degrees,"
"crs_courses," "crs_courses,"
"tst_questions" "tst_questions"
" WHERE deg_degrees.CtrCod=%ld" " WHERE deg_degrees.CtrCod=%ld"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=tst_questions.CrsCod", " AND crs_courses.CrsCod=tst_questions.CrsCod",
Gbl.Hierarchy.Ctr.CtrCod); Gbl.Hierarchy.Ctr.CtrCod);
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with test questions", DB_QueryCOUNT ("can not get number of courses with test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)" "SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM deg_degrees," " FROM deg_degrees,"
"crs_courses," "crs_courses,"
"tst_questions" "tst_questions"
" WHERE deg_degrees.CtrCod=%ld" " WHERE deg_degrees.CtrCod=%ld"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=tst_questions.CrsCod" " AND crs_courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.AnsType='%s'", " AND tst_questions.AnsType='%s'",
Gbl.Hierarchy.Ctr.CtrCod, Gbl.Hierarchy.Ctr.CtrCod,
Tst_StrAnswerTypesDB[AnsType]); Tst_StrAnswerTypesDB[AnsType]);
case Hie_Lvl_DEG: case Hie_Lvl_DEG:
@ -5648,20 +5662,20 @@ static unsigned Tst_GetNumCoursesWithTstQuestions (Hie_Lvl_Level_t Scope,Tst_Ans
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with test questions", DB_QueryCOUNT ("can not get number of courses with test questions",
"SELECT COUNTDISTINCT (tst_questions.CrsCod)" "SELECT COUNTDISTINCT (tst_questions.CrsCod)"
" FROM crs_courses," " FROM crs_courses,"
"tst_questions" "tst_questions"
" WHERE crs_courses.DegCod=%ld" " WHERE crs_courses.DegCod=%ld"
" AND crs_courses.CrsCod=tst_questions.CrsCod", " AND crs_courses.CrsCod=tst_questions.CrsCod",
Gbl.Hierarchy.Deg.DegCod); Gbl.Hierarchy.Deg.DegCod);
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with test questions", DB_QueryCOUNT ("can not get number of courses with test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)" "SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM crs_courses," " FROM crs_courses,"
"tst_questions" "tst_questions"
" WHERE crs_courses.DegCod=%ld" " WHERE crs_courses.DegCod=%ld"
" AND crs_courses.CrsCod=tst_questions.CrsCod" " AND crs_courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.AnsType='%s'", " AND tst_questions.AnsType='%s'",
Gbl.Hierarchy.Deg.DegCod, Gbl.Hierarchy.Deg.DegCod,
Tst_StrAnswerTypesDB[AnsType]); Tst_StrAnswerTypesDB[AnsType]);
case Hie_Lvl_CRS: case Hie_Lvl_CRS:
@ -5669,16 +5683,16 @@ static unsigned Tst_GetNumCoursesWithTstQuestions (Hie_Lvl_Level_t Scope,Tst_Ans
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with test questions", DB_QueryCOUNT ("can not get number of courses with test questions",
"SELECT COUNT(DISTINCT CrsCod)" "SELECT COUNT(DISTINCT CrsCod)"
" FROM tst_questions" " FROM tst_questions"
" WHERE CrsCod=%ld", " WHERE CrsCod=%ld",
Gbl.Hierarchy.Crs.CrsCod); Gbl.Hierarchy.Crs.CrsCod);
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with test questions", DB_QueryCOUNT ("can not get number of courses with test questions",
"SELECT COUNT(DISTINCT CrsCod)" "SELECT COUNT(DISTINCT CrsCod)"
" FROM tst_questions" " FROM tst_questions"
" WHERE CrsCod=%ld" " WHERE CrsCod=%ld"
" AND AnsType='%s'", " AND AnsType='%s'",
Gbl.Hierarchy.Crs.CrsCod, Gbl.Hierarchy.Crs.CrsCod,
Tst_StrAnswerTypesDB[AnsType]); Tst_StrAnswerTypesDB[AnsType]);
default: default:
@ -5704,20 +5718,20 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Hie_Lvl_Level_t Scop
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with pluggable test questions", DB_QueryCOUNT ("can not get number of courses with pluggable test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)" "SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM tst_questions," " FROM tst_questions,"
"tst_config" "tst_config"
" WHERE tst_questions.CrsCod=tst_config.CrsCod" " WHERE tst_questions.CrsCod=tst_config.CrsCod"
" AND tst_config.pluggable='%s'", " AND tst_config.pluggable='%s'",
TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]); TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]);
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with pluggable test questions", DB_QueryCOUNT ("can not get number of courses with pluggable test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)" "SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM tst_questions," " FROM tst_questions,"
"tst_config" "tst_config"
" WHERE tst_questions.AnsType='%s'" " WHERE tst_questions.AnsType='%s'"
" AND tst_questions.CrsCod=tst_config.CrsCod" " AND tst_questions.CrsCod=tst_config.CrsCod"
" AND tst_config.pluggable='%s'", " AND tst_config.pluggable='%s'",
Tst_StrAnswerTypesDB[AnsType], Tst_StrAnswerTypesDB[AnsType],
TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]); TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]);
case Hie_Lvl_CTY: case Hie_Lvl_CTY:
@ -5725,39 +5739,39 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Hie_Lvl_Level_t Scop
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with pluggable test questions", DB_QueryCOUNT ("can not get number of courses with pluggable test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)" "SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM ins_instits," " FROM ins_instits,"
"ctr_centers," "ctr_centers,"
"deg_degrees," "deg_degrees,"
"crs_courses," "crs_courses,"
"tst_questions," "tst_questions,"
"tst_config" "tst_config"
" WHERE ins_instits.CtyCod=%ld" " WHERE ins_instits.CtyCod=%ld"
" AND ins_instits.InsCod=ctr_centers.InsCod" " AND ins_instits.InsCod=ctr_centers.InsCod"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod" " AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=tst_questions.CrsCod" " AND crs_courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.CrsCod=tst_config.CrsCod" " AND tst_questions.CrsCod=tst_config.CrsCod"
" AND tst_config.pluggable='%s'", " AND tst_config.pluggable='%s'",
Gbl.Hierarchy.Cty.CtyCod, Gbl.Hierarchy.Cty.CtyCod,
TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]); TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]);
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with pluggable test questions", DB_QueryCOUNT ("can not get number of courses with pluggable test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)" "SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM ins_instits," " FROM ins_instits,"
"ctr_centers," "ctr_centers,"
"deg_degrees," "deg_degrees,"
"crs_courses," "crs_courses,"
"tst_questions," "tst_questions,"
"tst_config" "tst_config"
" WHERE ins_instits.CtyCod=%ld" " WHERE ins_instits.CtyCod=%ld"
" AND ins_instits.InsCod=ctr_centers.InsCod" " AND ins_instits.InsCod=ctr_centers.InsCod"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod" " AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=tst_questions.CrsCod" " AND crs_courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.AnsType='%s'" " AND tst_questions.AnsType='%s'"
" AND tst_questions.CrsCod=tst_config.CrsCod" " AND tst_questions.CrsCod=tst_config.CrsCod"
" AND tst_config.pluggable='%s'", " AND tst_config.pluggable='%s'",
Gbl.Hierarchy.Cty.CtyCod, Gbl.Hierarchy.Cty.CtyCod,
Tst_StrAnswerTypesDB[AnsType], Tst_StrAnswerTypesDB[AnsType],
TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]); TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]);
@ -5766,35 +5780,35 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Hie_Lvl_Level_t Scop
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with pluggable test questions", DB_QueryCOUNT ("can not get number of courses with pluggable test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)" "SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM ctr_centers," " FROM ctr_centers,"
"deg_degrees," "deg_degrees,"
"crs_courses," "crs_courses,"
"tst_questions," "tst_questions,"
"tst_config" "tst_config"
" WHERE ctr_centers.InsCod=%ld" " WHERE ctr_centers.InsCod=%ld"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod" " AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=tst_questions.CrsCod" " AND crs_courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.CrsCod=tst_config.CrsCod" " AND tst_questions.CrsCod=tst_config.CrsCod"
" AND tst_config.pluggable='%s'", " AND tst_config.pluggable='%s'",
Gbl.Hierarchy.Ins.InsCod, Gbl.Hierarchy.Ins.InsCod,
TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]); TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]);
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with pluggable test questions", DB_QueryCOUNT ("can not get number of courses with pluggable test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)" "SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM ctr_centers," " FROM ctr_centers,"
"deg_degrees," "deg_degrees,"
"crs_courses," "crs_courses,"
"tst_questions," "tst_questions,"
"tst_config" "tst_config"
" WHERE ctr_centers.InsCod=%ld" " WHERE ctr_centers.InsCod=%ld"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod" " AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=tst_questions.CrsCod" " AND crs_courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.AnsType='%s'" " AND tst_questions.AnsType='%s'"
" AND tst_questions.CrsCod=tst_config.CrsCod" " AND tst_questions.CrsCod=tst_config.CrsCod"
" AND tst_config.pluggable='%s'", " AND tst_config.pluggable='%s'",
Gbl.Hierarchy.Ins.InsCod, Gbl.Hierarchy.Ins.InsCod,
Tst_StrAnswerTypesDB[AnsType], Tst_StrAnswerTypesDB[AnsType],
TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]); TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]);
@ -5803,31 +5817,31 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Hie_Lvl_Level_t Scop
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with pluggable test questions", DB_QueryCOUNT ("can not get number of courses with pluggable test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)" "SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM deg_degrees," " FROM deg_degrees,"
"crs_courses," "crs_courses,"
"tst_questions," "tst_questions,"
"tst_config" "tst_config"
" WHERE deg_degrees.CtrCod=%ld" " WHERE deg_degrees.CtrCod=%ld"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=tst_questions.CrsCod" " AND crs_courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.CrsCod=tst_config.CrsCod" " AND tst_questions.CrsCod=tst_config.CrsCod"
" AND tst_config.pluggable='%s'", " AND tst_config.pluggable='%s'",
Gbl.Hierarchy.Ctr.CtrCod, Gbl.Hierarchy.Ctr.CtrCod,
TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]); TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]);
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with pluggable test questions", DB_QueryCOUNT ("can not get number of courses with pluggable test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)" "SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM deg_degrees," " FROM deg_degrees,"
"crs_courses," "crs_courses,"
"tst_questions," "tst_questions,"
"tst_config" "tst_config"
" WHERE deg_degrees.CtrCod=%ld" " WHERE deg_degrees.CtrCod=%ld"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=tst_questions.CrsCod" " AND crs_courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.AnsType='%s'" " AND tst_questions.AnsType='%s'"
" AND tst_questions.CrsCod=tst_config.CrsCod" " AND tst_questions.CrsCod=tst_config.CrsCod"
" AND tst_config.pluggable='%s'", " AND tst_config.pluggable='%s'",
Gbl.Hierarchy.Ctr.CtrCod, Gbl.Hierarchy.Ctr.CtrCod,
Tst_StrAnswerTypesDB[AnsType], Tst_StrAnswerTypesDB[AnsType],
TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]); TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]);
@ -5836,27 +5850,27 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Hie_Lvl_Level_t Scop
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with pluggable test questions", DB_QueryCOUNT ("can not get number of courses with pluggable test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)" "SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM crs_courses," " FROM crs_courses,"
"tst_questions," "tst_questions,"
"tst_config" "tst_config"
" WHERE crs_courses.DegCod=%ld" " WHERE crs_courses.DegCod=%ld"
" AND crs_courses.CrsCod=tst_questions.CrsCod" " AND crs_courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.CrsCod=tst_config.CrsCod" " AND tst_questions.CrsCod=tst_config.CrsCod"
" AND tst_config.pluggable='%s'", " AND tst_config.pluggable='%s'",
Gbl.Hierarchy.Deg.DegCod, Gbl.Hierarchy.Deg.DegCod,
TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]); TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]);
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with pluggable test questions", DB_QueryCOUNT ("can not get number of courses with pluggable test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)" "SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM crs_courses," " FROM crs_courses,"
"tst_questions," "tst_questions,"
"tst_config" "tst_config"
" WHERE crs_courses.DegCod=%ld" " WHERE crs_courses.DegCod=%ld"
" AND crs_courses.CrsCod=tst_questions.CrsCod" " AND crs_courses.CrsCod=tst_questions.CrsCod"
" AND tst_questions.AnsType='%s'" " AND tst_questions.AnsType='%s'"
" AND tst_questions.CrsCod=tst_config.CrsCod" " AND tst_questions.CrsCod=tst_config.CrsCod"
" AND tst_config.pluggable='%s'", " AND tst_config.pluggable='%s'",
Gbl.Hierarchy.Deg.DegCod, Gbl.Hierarchy.Deg.DegCod,
Tst_StrAnswerTypesDB[AnsType], Tst_StrAnswerTypesDB[AnsType],
TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]); TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]);
@ -5865,23 +5879,23 @@ static unsigned Tst_GetNumCoursesWithPluggableTstQuestions (Hie_Lvl_Level_t Scop
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with pluggable test questions", DB_QueryCOUNT ("can not get number of courses with pluggable test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)" "SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM tst_questions," " FROM tst_questions,"
"tst_config" "tst_config"
" WHERE tst_questions.CrsCod=%ld" " WHERE tst_questions.CrsCod=%ld"
" AND tst_questions.CrsCod=tst_config.CrsCod" " AND tst_questions.CrsCod=tst_config.CrsCod"
" AND tst_config.pluggable='%s'", " AND tst_config.pluggable='%s'",
Gbl.Hierarchy.Crs.CrsCod, Gbl.Hierarchy.Crs.CrsCod,
TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]); TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]);
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of courses with pluggable test questions", DB_QueryCOUNT ("can not get number of courses with pluggable test questions",
"SELECT COUNT(DISTINCT tst_questions.CrsCod)" "SELECT COUNT(DISTINCT tst_questions.CrsCod)"
" FROM tst_questions," " FROM tst_questions,"
"tst_config" "tst_config"
" WHERE tst_questions.CrsCod=%ld" " WHERE tst_questions.CrsCod=%ld"
" AND tst_questions.AnsType='%s'" " AND tst_questions.AnsType='%s'"
" AND tst_questions.CrsCod=tst_config.CrsCod" " AND tst_questions.CrsCod=tst_config.CrsCod"
" AND tst_config.pluggable='%s'", " AND tst_config.pluggable='%s'",
Gbl.Hierarchy.Crs.CrsCod, Gbl.Hierarchy.Crs.CrsCod,
Tst_StrAnswerTypesDB[AnsType], Tst_StrAnswerTypesDB[AnsType],
TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]); TstCfg_PluggableDB[TstCfg_PLUGGABLE_YES]);

View File

@ -99,7 +99,7 @@ void TstCfg_GetConfigFromDB (void)
"Max," // row[3] "Max," // row[3]
"MinTimeNxtTstPerQst," // row[4] "MinTimeNxtTstPerQst," // row[4]
"Visibility" // row[5] "Visibility" // row[5]
" FROM tst_config" " FROM tst_config"
" WHERE CrsCod=%ld", " WHERE CrsCod=%ld",
Gbl.Hierarchy.Crs.CrsCod); Gbl.Hierarchy.Crs.CrsCod);

View File

@ -875,7 +875,7 @@ static void TstPrn_GetCorrectIntAnswerFromDB (struct Tst_Question *Question)
Question->Answer.NumOptions = Question->Answer.NumOptions =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get answers of a question", (unsigned) DB_QuerySELECT (&mysql_res,"can not get answers of a question",
"SELECT Answer" // row[0] "SELECT Answer" // row[0]
" FROM tst_answers" " FROM tst_answers"
" WHERE QstCod=%ld", " WHERE QstCod=%ld",
Question->QstCod); Question->QstCod);
@ -902,7 +902,7 @@ static void TstPrn_GetCorrectFltAnswerFromDB (struct Tst_Question *Question)
Question->Answer.NumOptions = Question->Answer.NumOptions =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get answers of a question", (unsigned) DB_QuerySELECT (&mysql_res,"can not get answers of a question",
"SELECT Answer" // row[0] "SELECT Answer" // row[0]
" FROM tst_answers" " FROM tst_answers"
" WHERE QstCod=%ld", " WHERE QstCod=%ld",
Question->QstCod); Question->QstCod);
@ -940,7 +940,7 @@ static void TstPrn_GetCorrectTF_AnswerFromDB (struct Tst_Question *Question)
Question->Answer.NumOptions = Question->Answer.NumOptions =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get answers of a question", (unsigned) DB_QuerySELECT (&mysql_res,"can not get answers of a question",
"SELECT Answer" // row[0] "SELECT Answer" // row[0]
" FROM tst_answers" " FROM tst_answers"
" WHERE QstCod=%ld", " WHERE QstCod=%ld",
Question->QstCod); Question->QstCod);
@ -965,7 +965,7 @@ static void TstPrn_GetCorrectChoAnswerFromDB (struct Tst_Question *Question)
Question->Answer.NumOptions = Question->Answer.NumOptions =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get answers of a question", (unsigned) DB_QuerySELECT (&mysql_res,"can not get answers of a question",
"SELECT Correct" // row[0] "SELECT Correct" // row[0]
" FROM tst_answers" " FROM tst_answers"
" WHERE QstCod=%ld" " WHERE QstCod=%ld"
" ORDER BY AnsInd", " ORDER BY AnsInd",
Question->QstCod); Question->QstCod);
@ -994,7 +994,7 @@ static void TstPrn_GetCorrectTxtAnswerFromDB (struct Tst_Question *Question)
Question->Answer.NumOptions = Question->Answer.NumOptions =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get answers of a question", (unsigned) DB_QuerySELECT (&mysql_res,"can not get answers of a question",
"SELECT Answer" // row[0] "SELECT Answer" // row[0]
" FROM tst_answers" " FROM tst_answers"
" WHERE QstCod=%ld", " WHERE QstCod=%ld",
Question->QstCod); Question->QstCod);
@ -2070,10 +2070,11 @@ static void TstPrn_ShowUsrPrints (struct UsrData *UsrDat)
NumPrints = NumPrints =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get test exams of a user", (unsigned) DB_QuerySELECT (&mysql_res,"can not get test exams of a user",
"SELECT ExaCod" // row[0] "SELECT ExaCod" // row[0]
" FROM tst_exams" " FROM tst_exams"
" WHERE CrsCod=%ld AND UsrCod=%ld" " WHERE CrsCod=%ld"
" AND EndTime>=FROM_UNIXTIME(%ld)" " AND UsrCod=%ld"
" AND StartTime<=FROM_UNIXTIME(%ld)" " AND EndTime>=FROM_UNIXTIME(%ld)"
" AND StartTime<=FROM_UNIXTIME(%ld)"
" ORDER BY ExaCod", " ORDER BY ExaCod",
Gbl.Hierarchy.Crs.CrsCod, Gbl.Hierarchy.Crs.CrsCod,
UsrDat->UsrCod, UsrDat->UsrCod,
@ -2624,12 +2625,12 @@ static void TstPrn_ShowTagsPresentInAPrint (long ResCod)
DB_QuerySELECT (&mysql_res,"can not get tags" DB_QuerySELECT (&mysql_res,"can not get tags"
" present in a test exam", " present in a test exam",
"SELECT tst_tags.TagTxt" // row[0] "SELECT tst_tags.TagTxt" // row[0]
" FROM" " FROM (SELECT DISTINCT(tst_question_tags.TagCod)"
" (SELECT DISTINCT(tst_question_tags.TagCod)" " FROM tst_question_tags,"
" FROM tst_question_tags,tst_exam_questions" "tst_exam_questions"
" WHERE tst_exam_questions.ExaCod=%ld" " WHERE tst_exam_questions.ExaCod=%ld"
" AND tst_exam_questions.QstCod=tst_question_tags.QstCod)" " AND tst_exam_questions.QstCod=tst_question_tags.QstCod) AS TagsCods,"
" AS TagsCods,tst_tags" "tst_tags"
" WHERE TagsCods.TagCod=tst_tags.TagCod" " WHERE TagsCods.TagCod=tst_tags.TagCod"
" ORDER BY tst_tags.TagTxt", " ORDER BY tst_tags.TagTxt",
ResCod); ResCod);
@ -2697,8 +2698,9 @@ void TstPrn_GetPrintDataByPrnCod (struct TstPrn_Print *Print)
"Sent," // row[5] "Sent," // row[5]
"AllowTeachers," // row[6] "AllowTeachers," // row[6]
"Score" // row[7] "Score" // row[7]
" FROM tst_exams" " FROM tst_exams"
" WHERE ExaCod=%ld AND CrsCod=%ld", " WHERE ExaCod=%ld"
" AND CrsCod=%ld",
Print->PrnCod, Print->PrnCod,
Gbl.Hierarchy.Crs.CrsCod) == 1) Gbl.Hierarchy.Crs.CrsCod) == 1)
{ {
@ -2757,7 +2759,7 @@ void TstPrn_GetPrintQuestionsFromDB (struct TstPrn_Print *Print)
"Score," // row[1] "Score," // row[1]
"Indexes," // row[2] "Indexes," // row[2]
"Answers" // row[3] "Answers" // row[3]
" FROM tst_exam_questions" " FROM tst_exam_questions"
" WHERE ExaCod=%ld" " WHERE ExaCod=%ld"
" ORDER BY QstInd", " ORDER BY QstInd",
Print->PrnCod); Print->PrnCod);

View File

@ -86,7 +86,8 @@ unsigned Tml_DB_GetWho (MYSQL_RES **mysql_res)
return (unsigned) return (unsigned)
DB_QuerySELECT (mysql_res,"can not get which timeline users", DB_QuerySELECT (mysql_res,"can not get which timeline users",
"SELECT TimelineUsrs" // row[0] "SELECT TimelineUsrs" // row[0]
" FROM usr_last WHERE UsrCod=%ld", " FROM usr_last"
" WHERE UsrCod=%ld",
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod);
} }
@ -98,7 +99,8 @@ void Tml_DB_UpdateWho (Usr_Who_t Who)
{ {
/***** Update which users in database *****/ /***** Update which users in database *****/
DB_QueryUPDATE ("can not update which timeline users", DB_QueryUPDATE ("can not update which timeline users",
"UPDATE usr_last SET TimelineUsrs=%u" "UPDATE usr_last"
" SET TimelineUsrs=%u"
" WHERE UsrCod=%ld", " WHERE UsrCod=%ld",
(unsigned) Who, (unsigned) Who,
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod);
@ -125,7 +127,7 @@ unsigned Tml_DB_GetDataOfNoteByCod (long NotCod,MYSQL_RES **mysql_res)
"HieCod," // row[4] "HieCod," // row[4]
"Unavailable," // row[5] "Unavailable," // row[5]
"UNIX_TIMESTAMP(TimeNote)" // row[6] "UNIX_TIMESTAMP(TimeNote)" // row[6]
" FROM tml_notes" " FROM tml_notes"
" WHERE NotCod=%ld", " WHERE NotCod=%ld",
NotCod); NotCod);
} }
@ -142,9 +144,12 @@ long Tml_DB_GetPubCodOfOriginalNote (long NotCod)
/***** Get code of publication of the original note *****/ /***** Get code of publication of the original note *****/
if (DB_QuerySELECT (&mysql_res,"can not get code of publication", if (DB_QuerySELECT (&mysql_res,"can not get code of publication",
"SELECT PubCod FROM tml_pubs" "SELECT PubCod"
" WHERE NotCod=%ld AND PubType=%u", " FROM tml_pubs"
NotCod,(unsigned) Tml_Pub_ORIGINAL_NOTE) == 1) " WHERE NotCod=%ld"
" AND PubType=%u",
NotCod,
(unsigned) Tml_Pub_ORIGINAL_NOTE) == 1)
{ // Result should have a unique row { // Result should have a unique row
/* Get code of publication (row[0]) */ /* Get code of publication (row[0]) */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -235,7 +240,9 @@ void Tml_DB_CreateTmpTableVisibleTimeline (void)
"CREATE TEMPORARY TABLE tml_tmp_visible_timeline " "CREATE TEMPORARY TABLE tml_tmp_visible_timeline "
"(NotCod BIGINT NOT NULL,UNIQUE INDEX(NotCod))" "(NotCod BIGINT NOT NULL,UNIQUE INDEX(NotCod))"
" ENGINE=MEMORY" " ENGINE=MEMORY"
" SELECT NotCod FROM tml_timelines WHERE SessionId='%s'", " SELECT NotCod"
" FROM tml_timelines"
" WHERE SessionId='%s'",
Gbl.Session.Id); Gbl.Session.Id);
} }
@ -290,7 +297,9 @@ mysql> SELECT SessionId,COUNT(*) FROM tml_timelines GROUP BY SessionId;
DB_QueryINSERT ("can not insert notes in timeline", DB_QueryINSERT ("can not insert notes in timeline",
"INSERT IGNORE INTO tml_timelines" "INSERT IGNORE INTO tml_timelines"
" (SessionId,NotCod)" " (SessionId,NotCod)"
" SELECT '%s',NotCod FROM tml_tmp_just_retrieved_notes", " SELECT '%s',"
"NotCod"
" FROM tml_tmp_just_retrieved_notes",
Gbl.Session.Id); Gbl.Session.Id);
} }
@ -409,7 +418,7 @@ unsigned Tml_DB_GetPostByCod (long PstCod,MYSQL_RES **mysql_res)
" of a post", " of a post",
"SELECT Txt," // row[0] "SELECT Txt," // row[0]
"MedCod" // row[1] "MedCod" // row[1]
" FROM tml_posts" " FROM tml_posts"
" WHERE PstCod=%ld", " WHERE PstCod=%ld",
PstCod); PstCod);
} }
@ -464,8 +473,10 @@ void Tml_DB_RemoveAllPostsUsr (long UsrCod)
DB_QueryDELETE ("can not remove posts", DB_QueryDELETE ("can not remove posts",
"DELETE FROM tml_posts" "DELETE FROM tml_posts"
" WHERE PstCod IN" " WHERE PstCod IN"
" (SELECT Cod FROM tml_notes" " (SELECT Cod"
" WHERE UsrCod=%ld AND NoteType=%u)", " FROM tml_notes"
" WHERE UsrCod=%ld"
" AND NoteType=%u)",
UsrCod,(unsigned) TL_NOTE_POST); UsrCod,(unsigned) TL_NOTE_POST);
} }
@ -477,8 +488,10 @@ unsigned Tml_DB_GetNumCommsInNote (long NotCod)
{ {
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of comments in a note", DB_QueryCOUNT ("can not get number of comments in a note",
"SELECT COUNT(*) FROM tml_pubs" "SELECT COUNT(*)"
" WHERE NotCod=%ld AND PubType=%u", " FROM tml_pubs"
" WHERE NotCod=%ld"
" AND PubType=%u",
NotCod,(unsigned) Tml_Pub_COMMENT_TO_NOTE); NotCod,(unsigned) Tml_Pub_COMMENT_TO_NOTE);
} }
@ -492,8 +505,9 @@ unsigned Tml_DB_GetComms (long NotCod,MYSQL_RES **mysql_res)
return (unsigned) return (unsigned)
DB_QuerySELECT (mysql_res,"can not get comments", DB_QuerySELECT (mysql_res,"can not get comments",
"SELECT PubCod" // row[0] "SELECT PubCod" // row[0]
" FROM tml_pubs" " FROM tml_pubs"
" WHERE NotCod=%ld AND PubType=%u", " WHERE NotCod=%ld"
" AND PubType=%u",
NotCod,(unsigned) Tml_Pub_COMMENT_TO_NOTE); NotCod,(unsigned) Tml_Pub_COMMENT_TO_NOTE);
} }
@ -513,10 +527,10 @@ unsigned Tml_DB_GetInitialComms (long NotCod,unsigned NumInitialCommsToGet,
"UNIX_TIMESTAMP(tml_pubs.TimePublish)," // row[3] "UNIX_TIMESTAMP(tml_pubs.TimePublish)," // row[3]
"tml_comments.Txt," // row[4] "tml_comments.Txt," // row[4]
"tml_comments.MedCod" // row[5] "tml_comments.MedCod" // row[5]
" FROM tml_pubs,tml_comments" " FROM tml_pubs,tml_comments"
" WHERE tml_pubs.NotCod=%ld" " WHERE tml_pubs.NotCod=%ld"
" AND tml_pubs.PubType=%u" " AND tml_pubs.PubType=%u"
" AND tml_pubs.PubCod=tml_comments.PubCod" " AND tml_pubs.PubCod=tml_comments.PubCod"
" ORDER BY tml_pubs.PubCod" " ORDER BY tml_pubs.PubCod"
" LIMIT %lu", " LIMIT %lu",
NotCod,(unsigned) Tml_Pub_COMMENT_TO_NOTE, NotCod,(unsigned) Tml_Pub_COMMENT_TO_NOTE,
@ -534,20 +548,19 @@ unsigned Tml_DB_GetFinalComms (long NotCod,unsigned NumFinalCommsToGet,
/***** Get final comments of a note from database *****/ /***** Get final comments of a note from database *****/
return (unsigned) return (unsigned)
DB_QuerySELECT (mysql_res,"can not get comments", DB_QuerySELECT (mysql_res,"can not get comments",
"SELECT * FROM " "SELECT *"
"(" " FROM (SELECT tml_pubs.PubCod," // row[0]
"SELECT tml_pubs.PubCod," // row[0] "tml_pubs.PublisherCod," // row[1]
"tml_pubs.PublisherCod," // row[1] "tml_pubs.NotCod," // row[2]
"tml_pubs.NotCod," // row[2] "UNIX_TIMESTAMP(tml_pubs.TimePublish)," // row[3]
"UNIX_TIMESTAMP(tml_pubs.TimePublish)," // row[3] "tml_comments.Txt," // row[4]
"tml_comments.Txt," // row[4] "tml_comments.MedCod" // row[5]
"tml_comments.MedCod" // row[5] " FROM tml_pubs,tml_comments"
" FROM tml_pubs,tml_comments" " WHERE tml_pubs.NotCod=%ld"
" WHERE tml_pubs.NotCod=%ld" " AND tml_pubs.PubType=%u"
" AND tml_pubs.PubType=%u" " AND tml_pubs.PubCod=tml_comments.PubCod"
" AND tml_pubs.PubCod=tml_comments.PubCod" " ORDER BY tml_pubs.PubCod DESC"
" ORDER BY tml_pubs.PubCod DESC LIMIT %u" " LIMIT %u) AS comments"
") AS comments"
" ORDER BY PubCod", " ORDER BY PubCod",
NotCod,(unsigned) Tml_Pub_COMMENT_TO_NOTE, NotCod,(unsigned) Tml_Pub_COMMENT_TO_NOTE,
NumFinalCommsToGet); NumFinalCommsToGet);
@ -573,10 +586,10 @@ unsigned Tml_DB_GetDataOfCommByCod (long PubCod,MYSQL_RES **mysql_res)
"UNIX_TIMESTAMP(tml_pubs.TimePublish)," // row[3] "UNIX_TIMESTAMP(tml_pubs.TimePublish)," // row[3]
"tml_comments.Txt," // row[4] "tml_comments.Txt," // row[4]
"tml_comments.MedCod" // row[5] "tml_comments.MedCod" // row[5]
" FROM tml_pubs,tml_comments" " FROM tml_pubs,tml_comments"
" WHERE tml_pubs.PubCod=%ld" " WHERE tml_pubs.PubCod=%ld"
" AND tml_pubs.PubType=%u" " AND tml_pubs.PubType=%u"
" AND tml_pubs.PubCod=tml_comments.PubCod", " AND tml_pubs.PubCod=tml_comments.PubCod",
PubCod,(unsigned) Tml_Pub_COMMENT_TO_NOTE); PubCod,(unsigned) Tml_Pub_COMMENT_TO_NOTE);
} }
@ -769,7 +782,9 @@ void Tml_DB_CreateSubQueryAlreadyExists (const struct Tml_Timeline *Timeline,
}; };
snprintf (SubQueries->AlreadyExists,sizeof (SubQueries->AlreadyExists), snprintf (SubQueries->AlreadyExists,sizeof (SubQueries->AlreadyExists),
" tml_pubs.NotCod NOT IN (SELECT NotCod FROM %s)", " tml_pubs.NotCod NOT IN"
" (SELECT NotCod"
" FROM %s)",
Table[Timeline->WhatToGet]); Table[Timeline->WhatToGet]);
} }
@ -807,9 +822,10 @@ unsigned Tml_DB_SelectTheMostRecentPub (const struct Tml_Pub_SubQueries *SubQuer
"tml_pubs.NotCod," // row[1] "tml_pubs.NotCod," // row[1]
"tml_pubs.PublisherCod," // row[2] "tml_pubs.PublisherCod," // row[2]
"tml_pubs.PubType" // row[3] "tml_pubs.PubType" // row[3]
" FROM tml_pubs%s" " FROM tml_pubs%s"
" WHERE %s%s%s%s" " WHERE %s%s%s%s"
" ORDER BY tml_pubs.PubCod DESC LIMIT 1", " ORDER BY tml_pubs.PubCod"
" DESC LIMIT 1",
SubQueries->TablePublishers, SubQueries->TablePublishers,
SubQueries->RangeBottom, SubQueries->RangeBottom,
SubQueries->RangeTop, SubQueries->RangeTop,
@ -835,7 +851,8 @@ unsigned Tml_DB_GetDataOfPubByCod (long PubCod,MYSQL_RES **mysql_res)
"NotCod," // row[1] "NotCod," // row[1]
"PublisherCod," // row[2] "PublisherCod," // row[2]
"PubType" // row[3] "PubType" // row[3]
" FROM tml_pubs WHERE PubCod=%ld", " FROM tml_pubs"
" WHERE PubCod=%ld",
PubCod); PubCod);
} }
@ -851,7 +868,8 @@ long Tml_DB_GetNotCodFromPubCod (long PubCod)
/***** Get code of note from database *****/ /***** Get code of note from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get code of note", if (DB_QuerySELECT (&mysql_res,"can not get code of note",
"SELECT NotCod FROM tml_pubs" "SELECT NotCod"
" FROM tml_pubs"
" WHERE PubCod=%ld", " WHERE PubCod=%ld",
PubCod) == 1) // Result should have a unique row PubCod) == 1) // Result should have a unique row
{ {
@ -908,7 +926,8 @@ unsigned long Tml_DB_GetNumPubsUsr (long UsrCod)
{ {
/***** Get number of posts from a user from database *****/ /***** Get number of posts from a user from database *****/
return DB_QueryCOUNT ("can not get number of publications from a user", return DB_QueryCOUNT ("can not get number of publications from a user",
"SELECT COUNT(*) FROM tml_pubs" "SELECT COUNT(*)"
" FROM tml_pubs"
" WHERE PublisherCod=%ld", " WHERE PublisherCod=%ld",
UsrCod); UsrCod);
} }
@ -956,7 +975,7 @@ void Tml_DB_UpdateLastPubCodInSession (void)
"UPDATE ses_sessions" "UPDATE ses_sessions"
" SET LastPubCod=" " SET LastPubCod="
"(SELECT IFNULL(MAX(PubCod),0)" "(SELECT IFNULL(MAX(PubCod),0)"
" FROM tml_pubs)" // The most recent publication " FROM tml_pubs)" // The most recent publication
" WHERE SessionId='%s'", " WHERE SessionId='%s'",
Gbl.Session.Id); Gbl.Session.Id);
} }
@ -972,7 +991,7 @@ void Tml_DB_UpdateFirstLastPubCodsInSession (long FirstPubCod)
" SET FirstPubCod=%ld," " SET FirstPubCod=%ld,"
"LastPubCod=" "LastPubCod="
"(SELECT IFNULL(MAX(PubCod),0)" "(SELECT IFNULL(MAX(PubCod),0)"
" FROM tml_pubs)" // The most recent publication " FROM tml_pubs)" // The most recent publication
" WHERE SessionId='%s'", " WHERE SessionId='%s'",
FirstPubCod, FirstPubCod,
Gbl.Session.Id); Gbl.Session.Id);
@ -1016,8 +1035,10 @@ bool Tml_DB_CheckIfFavedByUsr (Tml_Usr_FavSha_t FavSha,long Cod,long UsrCod)
{ {
/***** Check if a user has favourited a note/comment from database *****/ /***** Check if a user has favourited a note/comment from database *****/
return (DB_QueryCOUNT ("can not check if a user has favourited", return (DB_QueryCOUNT ("can not check if a user has favourited",
"SELECT COUNT(*) FROM %s" "SELECT COUNT(*)"
" WHERE %s=%ld AND UsrCod=%ld", " FROM %s"
" WHERE %s=%ld"
" AND UsrCod=%ld",
Tml_DB_TableFav[FavSha], Tml_DB_TableFav[FavSha],
Tml_DB_FieldFav[FavSha],Cod,UsrCod) != 0); Tml_DB_FieldFav[FavSha],Cod,UsrCod) != 0);
} }
@ -1031,9 +1052,10 @@ unsigned Tml_DB_GetNumFavers (Tml_Usr_FavSha_t FavSha,long Cod,long UsrCod)
/***** Get number of times (users) a note/comment has been favourited *****/ /***** Get number of times (users) a note/comment has been favourited *****/
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of times has been favourited", DB_QueryCOUNT ("can not get number of times has been favourited",
"SELECT COUNT(*) FROM %s" "SELECT COUNT(*)"
" FROM %s"
" WHERE %s=%ld" " WHERE %s=%ld"
" AND UsrCod<>%ld", // Extra check " AND UsrCod<>%ld", // Extra check
Tml_DB_TableFav[FavSha], Tml_DB_TableFav[FavSha],
Tml_DB_FieldFav[FavSha],Cod, Tml_DB_FieldFav[FavSha],Cod,
UsrCod); // The author UsrCod); // The author
@ -1051,10 +1073,11 @@ unsigned Tml_DB_GetFavers (Tml_Usr_FavSha_t FavSha,
return (unsigned) return (unsigned)
DB_QuerySELECT (mysql_res,"can not get favers", DB_QuerySELECT (mysql_res,"can not get favers",
"SELECT UsrCod" // row[0] "SELECT UsrCod" // row[0]
" FROM %s" " FROM %s"
" WHERE %s=%ld" " WHERE %s=%ld"
" AND UsrCod<>%ld" // Extra check " AND UsrCod<>%ld" // Extra check
" ORDER BY FavCod LIMIT %u", " ORDER BY FavCod"
" LIMIT %u",
Tml_DB_TableFav[FavSha], Tml_DB_TableFav[FavSha],
Tml_DB_FieldFav[FavSha],Cod, Tml_DB_FieldFav[FavSha],Cod,
UsrCod, UsrCod,
@ -1149,10 +1172,11 @@ void Tml_DB_RemoveAllFavsToAllCommsInAllNotesBy (long UsrCod)
bool Tml_DB_CheckIfSharedByUsr (long NotCod,long UsrCod) bool Tml_DB_CheckIfSharedByUsr (long NotCod,long UsrCod)
{ {
return (DB_QueryCOUNT ("can not check if a user has shared a note", return (DB_QueryCOUNT ("can not check if a user has shared a note",
"SELECT COUNT(*) FROM tml_pubs" "SELECT COUNT(*)"
" FROM tml_pubs"
" WHERE NotCod=%ld" " WHERE NotCod=%ld"
" AND PublisherCod=%ld" " AND PublisherCod=%ld"
" AND PubType=%u", " AND PubType=%u",
NotCod, NotCod,
UsrCod, UsrCod,
(unsigned) Tml_Pub_SHARED_NOTE) != 0); (unsigned) Tml_Pub_SHARED_NOTE) != 0);
@ -1167,10 +1191,11 @@ unsigned Tml_DB_GetNumSharers (long NotCod,long UsrCod)
/***** Get number of times (users) this note has been shared *****/ /***** Get number of times (users) this note has been shared *****/
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of times a note has been shared", DB_QueryCOUNT ("can not get number of times a note has been shared",
"SELECT COUNT(*) FROM tml_pubs" "SELECT COUNT(*)"
" FROM tml_pubs"
" WHERE NotCod=%ld" " WHERE NotCod=%ld"
" AND PublisherCod<>%ld" " AND PublisherCod<>%ld"
" AND PubType=%u", " AND PubType=%u",
NotCod, NotCod,
UsrCod, // Author of the note UsrCod, // Author of the note
(unsigned) Tml_Pub_SHARED_NOTE); (unsigned) Tml_Pub_SHARED_NOTE);
@ -1187,11 +1212,12 @@ unsigned Tml_DB_GetSharers (long NotCod,long UsrCod,unsigned MaxUsrs,
return (unsigned) return (unsigned)
DB_QuerySELECT (mysql_res,"can not get users", DB_QuerySELECT (mysql_res,"can not get users",
"SELECT PublisherCod" // row[0] "SELECT PublisherCod" // row[0]
" FROM tml_pubs" " FROM tml_pubs"
" WHERE NotCod=%ld" " WHERE NotCod=%ld"
" AND PublisherCod<>%ld" " AND PublisherCod<>%ld"
" AND PubType=%u" " AND PubType=%u"
" ORDER BY PubCod LIMIT %u", " ORDER BY PubCod"
" LIMIT %u",
NotCod, NotCod,
UsrCod, UsrCod,
(unsigned) Tml_Pub_SHARED_NOTE, (unsigned) Tml_Pub_SHARED_NOTE,

View File

@ -463,7 +463,8 @@ void Usr_GetUsrCodFromEncryptedUsrCod (struct UsrData *UsrDat)
{ {
/***** Get user's code from database *****/ /***** Get user's code from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get user's code", NumRows = DB_QuerySELECT (&mysql_res,"can not get user's code",
"SELECT UsrCod FROM usr_data" "SELECT UsrCod"
" FROM usr_data"
" WHERE EncryptedUsrCod='%s'", " WHERE EncryptedUsrCod='%s'",
UsrDat->EnUsrCod); UsrDat->EnUsrCod);
if (NumRows != 1) if (NumRows != 1)
@ -528,8 +529,8 @@ void Usr_GetUsrDataFromUsrCod (struct UsrData *UsrDat,Usr_GetPrefs_t GetPrefs)
"NotifNtfEvents," // row[21] "NotifNtfEvents," // row[21]
"EmailNtfEvents" // row[22] "EmailNtfEvents" // row[22]
" FROM usr_data" " FROM usr_data"
" WHERE UsrCod=%ld", " WHERE UsrCod=%ld",
UsrDat->UsrCod); UsrDat->UsrCod);
break; break;
case Usr_GET_PREFS: case Usr_GET_PREFS:
default: default:
@ -570,8 +571,8 @@ void Usr_GetUsrDataFromUsrCod (struct UsrData *UsrDat,Usr_GetPrefs_t GetPrefs)
"SideCols," // row[29] "SideCols," // row[29]
"ThirdPartyCookies" // row[30] "ThirdPartyCookies" // row[30]
" FROM usr_data" " FROM usr_data"
" WHERE UsrCod=%ld", " WHERE UsrCod=%ld",
UsrDat->UsrCod); UsrDat->UsrCod);
break; break;
} }
@ -755,7 +756,8 @@ static void Usr_GetMyLastData (void)
"LastRole," // row[4] "LastRole," // row[4]
"UNIX_TIMESTAMP(LastTime)," // row[5] "UNIX_TIMESTAMP(LastTime)," // row[5]
"UNIX_TIMESTAMP(LastAccNotif)" // row[6] "UNIX_TIMESTAMP(LastAccNotif)" // row[6]
" FROM usr_last WHERE UsrCod=%ld", " FROM usr_last"
" WHERE UsrCod=%ld",
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod);
if (NumRows == 0) if (NumRows == 0)
{ {
@ -906,9 +908,14 @@ bool Usr_CheckIfUsrIsAdm (long UsrCod,Hie_Lvl_Level_t Scope,long Cod)
{ {
/***** Get if a user is administrator of a degree from database *****/ /***** Get if a user is administrator of a degree from database *****/
return (DB_QueryCOUNT ("can not check if a user is administrator", return (DB_QueryCOUNT ("can not check if a user is administrator",
"SELECT COUNT(*) FROM usr_admins" "SELECT COUNT(*)"
" WHERE UsrCod=%ld AND Scope='%s' AND Cod=%ld", " FROM usr_admins"
UsrCod,Sco_GetDBStrFromScope (Scope),Cod) != 0); " WHERE UsrCod=%ld"
" AND Scope='%s'"
" AND Cod=%ld",
UsrCod,
Sco_GetDBStrFromScope (Scope),
Cod) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -935,9 +942,12 @@ bool Usr_CheckIfUsrIsSuperuser (long UsrCod)
Gbl.Cache.UsrIsSuperuser.UsrCod = UsrCod; Gbl.Cache.UsrIsSuperuser.UsrCod = UsrCod;
Gbl.Cache.UsrIsSuperuser.IsSuperuser = Gbl.Cache.UsrIsSuperuser.IsSuperuser =
(DB_QueryCOUNT ("can not check if a user is superuser", (DB_QueryCOUNT ("can not check if a user is superuser",
"SELECT COUNT(*) FROM usr_admins" "SELECT COUNT(*)"
" WHERE UsrCod=%ld AND Scope='%s'", " FROM usr_admins"
UsrCod,Sco_GetDBStrFromScope (Hie_Lvl_SYS)) != 0); " WHERE UsrCod=%ld"
" AND Scope='%s'",
UsrCod,
Sco_GetDBStrFromScope (Hie_Lvl_SYS)) != 0);
return Gbl.Cache.UsrIsSuperuser.IsSuperuser; return Gbl.Cache.UsrIsSuperuser.IsSuperuser;
} }
@ -1063,7 +1073,8 @@ unsigned Usr_GetNumCrssOfUsrWithARole (long UsrCod,Rol_Role_t Role)
" FROM crs_users" " FROM crs_users"
" WHERE UsrCod=%ld" " WHERE UsrCod=%ld"
" AND Role=%u", " AND Role=%u",
UsrCod,(unsigned) Role); UsrCod,
(unsigned) Role);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1080,7 +1091,8 @@ unsigned Usr_GetNumCrssOfUsrWithARoleNotAccepted (long UsrCod,Rol_Role_t Role)
" WHERE UsrCod=%ld" " WHERE UsrCod=%ld"
" AND Role=%u" " AND Role=%u"
" AND Accepted='N'", " AND Accepted='N'",
UsrCod,(unsigned) Role); UsrCod,
(unsigned) Role);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1131,7 +1143,7 @@ unsigned Usr_GetNumUsrsInCrssOfAUsr (long UsrCod,Rol_Role_t UsrRole,
" SELECT CrsCod" " SELECT CrsCod"
" FROM crs_users" " FROM crs_users"
" WHERE UsrCod=%ld" " WHERE UsrCod=%ld"
"%s", "%s",
UsrCod,SubQueryRole); UsrCod,SubQueryRole);
/***** Get the number of students/teachers in a course from database ******/ /***** Get the number of students/teachers in a course from database ******/
@ -1149,7 +1161,8 @@ unsigned Usr_GetNumUsrsInCrssOfAUsr (long UsrCod,Rol_Role_t UsrRole,
NumUsrs = NumUsrs =
(unsigned) DB_QueryCOUNT ("can not get number of users", (unsigned) DB_QueryCOUNT ("can not get number of users",
"SELECT COUNT(DISTINCT crs_users.UsrCod)" "SELECT COUNT(DISTINCT crs_users.UsrCod)"
" FROM crs_users,usr_courses_tmp" " FROM crs_users,"
"usr_courses_tmp"
" WHERE crs_users.CrsCod=usr_courses_tmp.CrsCod" " WHERE crs_users.CrsCod=usr_courses_tmp.CrsCod"
" AND crs_users.Role IN (%s)", " AND crs_users.Role IN (%s)",
OthersRolesStr); OthersRolesStr);
@ -1753,7 +1766,9 @@ void Usr_GetMyCourses (void)
NumCrss = NumCrss =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get which courses" (unsigned) DB_QuerySELECT (&mysql_res,"can not get which courses"
" you belong to", " you belong to",
"SELECT CrsCod,Role,DegCod" "SELECT CrsCod,"
"Role,"
"DegCod"
" FROM my_courses_tmp"); " FROM my_courses_tmp");
for (NumCrs = 0; for (NumCrs = 0;
NumCrs < NumCrss; NumCrs < NumCrss;
@ -2470,7 +2485,8 @@ bool Usr_ChkIfEncryptedUsrCodExists (const char EncryptedUsrCod[Cry_BYTES_ENCRYP
/***** Get if an encrypted user's code already existed in database *****/ /***** Get if an encrypted user's code already existed in database *****/
return (DB_QueryCOUNT ("can not check if an encrypted user's code" return (DB_QueryCOUNT ("can not check if an encrypted user's code"
" already existed", " already existed",
"SELECT COUNT(*) FROM usr_data" "SELECT COUNT(*)"
" FROM usr_data"
" WHERE EncryptedUsrCod='%s'", " WHERE EncryptedUsrCod='%s'",
EncryptedUsrCod) != 0); EncryptedUsrCod) != 0);
} }
@ -3536,13 +3552,19 @@ void Usr_UpdateMyLastData (void)
{ {
/***** Check if it exists an entry for me *****/ /***** Check if it exists an entry for me *****/
if (DB_QueryCOUNT ("can not get last user's click", if (DB_QueryCOUNT ("can not get last user's click",
"SELECT COUNT(*) FROM usr_last WHERE UsrCod=%ld", "SELECT COUNT(*)"
" FROM usr_last"
" WHERE UsrCod=%ld",
Gbl.Usrs.Me.UsrDat.UsrCod)) Gbl.Usrs.Me.UsrDat.UsrCod))
/***** Update my last accessed course, tab and time of click in database *****/ /***** Update my last accessed course, tab and time of click in database *****/
// WhatToSearch, LastAccNotif remain unchanged // WhatToSearch, LastAccNotif remain unchanged
DB_QueryUPDATE ("can not update last user's data", DB_QueryUPDATE ("can not update last user's data",
"UPDATE usr_last" "UPDATE usr_last"
" SET LastSco='%s',LastCod=%ld,LastAct=%ld,LastRole=%u,LastTime=NOW()" " SET LastSco='%s',"
"LastCod=%ld,"
"LastAct=%ld,"
"LastRole=%u,"
"LastTime=NOW()"
" WHERE UsrCod=%ld", " WHERE UsrCod=%ld",
Sco_GetDBStrFromScope (Gbl.Hierarchy.Level), Sco_GetDBStrFromScope (Gbl.Hierarchy.Level),
Gbl.Hierarchy.Cod, Gbl.Hierarchy.Cod,
@ -4167,7 +4189,8 @@ unsigned Usr_GetNumUsrsWhoDontClaimToBelongToAnyCty (void)
from database *****/ from database *****/
Gbl.Cache.NumUsrsWhoDontClaimToBelongToAnyCty.NumUsrs = Gbl.Cache.NumUsrsWhoDontClaimToBelongToAnyCty.NumUsrs =
(unsigned) DB_QueryCOUNT ("can not get number of users", (unsigned) DB_QueryCOUNT ("can not get number of users",
"SELECT COUNT(UsrCod) FROM usr_data" "SELECT COUNT(UsrCod)"
" FROM usr_data"
" WHERE CtyCod<0"); " WHERE CtyCod<0");
Gbl.Cache.NumUsrsWhoDontClaimToBelongToAnyCty.Valid = true; Gbl.Cache.NumUsrsWhoDontClaimToBelongToAnyCty.Valid = true;
FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_BELONG_CTY,Hie_Lvl_CTY,-1L, FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_BELONG_CTY,Hie_Lvl_CTY,-1L,
@ -4207,7 +4230,8 @@ unsigned Usr_GetNumUsrsWhoClaimToBelongToAnotherCty (void)
from database *****/ from database *****/
Gbl.Cache.NumUsrsWhoClaimToBelongToAnotherCty.NumUsrs = Gbl.Cache.NumUsrsWhoClaimToBelongToAnotherCty.NumUsrs =
(unsigned) DB_QueryCOUNT ("can not get number of users", (unsigned) DB_QueryCOUNT ("can not get number of users",
"SELECT COUNT(UsrCod) FROM usr_data" "SELECT COUNT(UsrCod)"
" FROM usr_data"
" WHERE CtyCod=0"); " WHERE CtyCod=0");
Gbl.Cache.NumUsrsWhoClaimToBelongToAnotherCty.Valid = true; Gbl.Cache.NumUsrsWhoClaimToBelongToAnotherCty.Valid = true;
FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_BELONG_CTY,Hie_Lvl_CTY,0, FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_BELONG_CTY,Hie_Lvl_CTY,0,
@ -4262,7 +4286,8 @@ unsigned Usr_GetNumUsrsWhoClaimToBelongToCty (struct Cty_Countr *Cty)
Gbl.Cache.NumUsrsWhoClaimToBelongToCty.NumUsrs = Gbl.Cache.NumUsrsWhoClaimToBelongToCty.NumUsrs =
Cty->NumUsrsWhoClaimToBelongToCty.NumUsrs = Cty->NumUsrsWhoClaimToBelongToCty.NumUsrs =
(unsigned) DB_QueryCOUNT ("can not get number of users", (unsigned) DB_QueryCOUNT ("can not get number of users",
"SELECT COUNT(UsrCod) FROM usr_data" "SELECT COUNT(UsrCod)"
" FROM usr_data"
" WHERE CtyCod=%ld", " WHERE CtyCod=%ld",
Cty->CtyCod); Cty->CtyCod);
Cty->NumUsrsWhoClaimToBelongToCty.Valid = true; Cty->NumUsrsWhoClaimToBelongToCty.Valid = true;
@ -4318,7 +4343,8 @@ unsigned Usr_GetNumUsrsWhoClaimToBelongToIns (struct Ins_Instit *Ins)
Gbl.Cache.NumUsrsWhoClaimToBelongToIns.NumUsrs = Gbl.Cache.NumUsrsWhoClaimToBelongToIns.NumUsrs =
Ins->NumUsrsWhoClaimToBelongToIns.NumUsrs = Ins->NumUsrsWhoClaimToBelongToIns.NumUsrs =
(unsigned) DB_QueryCOUNT ("can not get number of users", (unsigned) DB_QueryCOUNT ("can not get number of users",
"SELECT COUNT(UsrCod) FROM usr_data" "SELECT COUNT(UsrCod)"
" FROM usr_data"
" WHERE InsCod=%ld", " WHERE InsCod=%ld",
Ins->InsCod); Ins->InsCod);
Ins->NumUsrsWhoClaimToBelongToIns.Valid = true; Ins->NumUsrsWhoClaimToBelongToIns.Valid = true;
@ -4374,7 +4400,8 @@ unsigned Usr_GetNumUsrsWhoClaimToBelongToCtr (struct Ctr_Center *Ctr)
Gbl.Cache.NumUsrsWhoClaimToBelongToCtr.NumUsrs = Gbl.Cache.NumUsrsWhoClaimToBelongToCtr.NumUsrs =
Ctr->NumUsrsWhoClaimToBelongToCtr.NumUsrs = Ctr->NumUsrsWhoClaimToBelongToCtr.NumUsrs =
(unsigned) DB_QueryCOUNT ("can not get number of users", (unsigned) DB_QueryCOUNT ("can not get number of users",
"SELECT COUNT(UsrCod) FROM usr_data" "SELECT COUNT(UsrCod)"
" FROM usr_data"
" WHERE CtrCod=%ld", " WHERE CtrCod=%ld",
Ctr->CtrCod); Ctr->CtrCod);
FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_BELONG_CTR,Hie_Lvl_CTR,Gbl.Cache.NumUsrsWhoClaimToBelongToCtr.CtrCod, FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_BELONG_CTR,Hie_Lvl_CTR,Gbl.Cache.NumUsrsWhoClaimToBelongToCtr.CtrCod,
@ -5089,7 +5116,9 @@ void Usr_CreateTmpTableAndSearchCandidateUsrs (const char SearchQuery[Sch_MAX_BY
*/ */
sprintf (Query,"CREATE TEMPORARY TABLE candidate_users" sprintf (Query,"CREATE TEMPORARY TABLE candidate_users"
" (UsrCod INT NOT NULL,UNIQUE INDEX(UsrCod)) ENGINE=MEMORY" " (UsrCod INT NOT NULL,UNIQUE INDEX(UsrCod)) ENGINE=MEMORY"
" SELECT UsrCod FROM usr_data WHERE %s", " SELECT UsrCod"
" FROM usr_data"
" WHERE %s",
SearchQuery); SearchQuery);
if (mysql_query (&Gbl.mysql,Query)) if (mysql_query (&Gbl.mysql,Query))
DB_ExitOnMySQLError ("can not create temporary table"); DB_ExitOnMySQLError ("can not create temporary table");
@ -5151,10 +5180,10 @@ static void Usr_GetAdmsLst (Hie_Lvl_Level_t Scope)
case Hie_Lvl_SYS: // All admins case Hie_Lvl_SYS: // All admins
DB_BuildQuery (&Query, DB_BuildQuery (&Query,
"SELECT %s" "SELECT %s"
" FROM usr_data" " FROM usr_data"
" WHERE UsrCod IN " " WHERE UsrCod IN "
"(SELECT DISTINCT UsrCod" "(SELECT DISTINCT UsrCod"
" FROM usr_admins)" " FROM usr_admins)"
" ORDER BY Surname1," " ORDER BY Surname1,"
"Surname2," "Surname2,"
"FirstName," "FirstName,"
@ -5165,37 +5194,38 @@ static void Usr_GetAdmsLst (Hie_Lvl_Level_t Scope)
// and admins of the institutions, centers and degrees in the current country // and admins of the institutions, centers and degrees in the current country
DB_BuildQuery (&Query, DB_BuildQuery (&Query,
"SELECT %s" "SELECT %s"
" FROM usr_data" " FROM usr_data"
" WHERE UsrCod IN " " WHERE UsrCod IN "
"(SELECT UsrCod FROM usr_admins" "(SELECT UsrCod"
" WHERE Scope='%s')" " FROM usr_admins"
" OR UsrCod IN " " WHERE Scope='%s')"
" OR UsrCod IN "
"(SELECT usr_admins.UsrCod"
" FROM usr_admins,"
"ins_instits"
" WHERE usr_admins.Scope='%s'"
" AND usr_admins.Cod=ins_instits.InsCod"
" AND ins_instits.CtyCod=%ld)"
" OR UsrCod IN "
"(SELECT usr_admins.UsrCod" "(SELECT usr_admins.UsrCod"
" FROM usr_admins," " FROM usr_admins,"
"ins_instits" "ctr_centers,"
" WHERE usr_admins.Scope='%s'" "ins_instits"
" AND usr_admins.Cod=ins_instits.InsCod" " WHERE usr_admins.Scope='%s'"
" AND ins_instits.CtyCod=%ld)" " AND usr_admins.Cod=ctr_centers.CtrCod"
" OR UsrCod IN " " AND ctr_centers.InsCod=ins_instits.InsCod"
"(SELECT usr_admins.UsrCod" " AND ins_instits.CtyCod=%ld)"
" FROM usr_admins," " OR UsrCod IN "
"ctr_centers," "(SELECT usr_admins.UsrCod"
"ins_instits" " FROM usr_admins,"
" WHERE usr_admins.Scope='%s'" "deg_degrees,"
" AND usr_admins.Cod=ctr_centers.CtrCod" "ctr_centers,"
" AND ctr_centers.InsCod=ins_instits.InsCod" "ins_instits"
" AND ins_instits.CtyCod=%ld)" " WHERE usr_admins.Scope='%s'"
" OR UsrCod IN " " AND usr_admins.Cod=deg_degrees.DegCod"
"(SELECT usr_admins.UsrCod" " AND deg_degrees.CtrCod=ctr_centers.CtrCod"
" FROM usr_admins," " AND ctr_centers.InsCod=ins_instits.InsCod"
"deg_degrees," " AND ins_instits.CtyCod=%ld)"
"ctr_centers,"
"ins_instits"
" WHERE usr_admins.Scope='%s'"
" AND usr_admins.Cod=deg_degrees.DegCod"
" AND deg_degrees.CtrCod=ctr_centers.CtrCod"
" AND ctr_centers.InsCod=ins_instits.InsCod"
" AND ins_instits.CtyCod=%ld)"
" ORDER BY Surname1," " ORDER BY Surname1,"
"Surname2," "Surname2,"
"FirstName," "FirstName,"
@ -5211,31 +5241,32 @@ static void Usr_GetAdmsLst (Hie_Lvl_Level_t Scope)
// and admins of the centers and degrees in the current institution // and admins of the centers and degrees in the current institution
DB_BuildQuery (&Query, DB_BuildQuery (&Query,
"SELECT %s" "SELECT %s"
" FROM usr_data" " FROM usr_data"
" WHERE UsrCod IN " " WHERE UsrCod IN "
"(SELECT UsrCod" "(SELECT UsrCod"
" FROM usr_admins" " FROM usr_admins"
" WHERE Scope='%s')" " WHERE Scope='%s')"
" OR UsrCod IN " " OR UsrCod IN "
"(SELECT UsrCod" "(SELECT UsrCod"
" FROM usr_admins" " FROM usr_admins"
" WHERE Scope='%s' AND Cod=%ld)" " WHERE Scope='%s'"
" OR UsrCod IN " " AND Cod=%ld)"
"(SELECT usr_admins.UsrCod" " OR UsrCod IN "
" FROM usr_admins," "(SELECT usr_admins.UsrCod"
"ctr_centers" " FROM usr_admins,"
" WHERE usr_admins.Scope='%s'" "ctr_centers"
" AND usr_admins.Cod=ctr_centers.CtrCod" " WHERE usr_admins.Scope='%s'"
" AND ctr_centers.InsCod=%ld)" " AND usr_admins.Cod=ctr_centers.CtrCod"
" OR UsrCod IN " " AND ctr_centers.InsCod=%ld)"
"(SELECT usr_admins.UsrCod" " OR UsrCod IN "
" FROM usr_admins," "(SELECT usr_admins.UsrCod"
"deg_degrees," " FROM usr_admins,"
"ctr_centers" "deg_degrees,"
" WHERE usr_admins.Scope='%s'" "ctr_centers"
" AND usr_admins.Cod=deg_degrees.DegCod" " WHERE usr_admins.Scope='%s'"
" AND deg_degrees.CtrCod=ctr_centers.CtrCod" " AND usr_admins.Cod=deg_degrees.DegCod"
" AND ctr_centers.InsCod=%ld)" " AND deg_degrees.CtrCod=ctr_centers.CtrCod"
" AND ctr_centers.InsCod=%ld)"
" ORDER BY Surname1," " ORDER BY Surname1,"
"Surname2," "Surname2,"
"FirstName," "FirstName,"
@ -5252,26 +5283,28 @@ static void Usr_GetAdmsLst (Hie_Lvl_Level_t Scope)
// and admins of the degrees in the current center // and admins of the degrees in the current center
DB_BuildQuery (&Query, DB_BuildQuery (&Query,
"SELECT %s" "SELECT %s"
" FROM usr_data" " FROM usr_data"
" WHERE UsrCod IN " " WHERE UsrCod IN "
"(SELECT UsrCod" "(SELECT UsrCod"
" FROM usr_admins" " FROM usr_admins"
" WHERE Scope='%s')" " WHERE Scope='%s')"
" OR UsrCod IN " " OR UsrCod IN "
"(SELECT UsrCod" "(SELECT UsrCod"
" FROM usr_admins" " FROM usr_admins"
" WHERE Scope='%s' AND Cod=%ld)" " WHERE Scope='%s'"
" OR UsrCod IN " " AND Cod=%ld)"
"(SELECT UsrCod" " OR UsrCod IN "
" FROM usr_admins" "(SELECT UsrCod"
" WHERE Scope='%s' AND Cod=%ld)" " FROM usr_admins"
" OR UsrCod IN " " WHERE Scope='%s'"
"(SELECT usr_admins.UsrCod" " AND Cod=%ld)"
" FROM usr_admins," " OR UsrCod IN "
"deg_degrees" "(SELECT usr_admins.UsrCod"
" WHERE usr_admins.Scope='%s'" " FROM usr_admins,"
" AND usr_admins.Cod=deg_degrees.DegCod" "deg_degrees"
" AND deg_degrees.CtrCod=%ld)" " WHERE usr_admins.Scope='%s'"
" AND usr_admins.Cod=deg_degrees.DegCod"
" AND deg_degrees.CtrCod=%ld)"
" ORDER BY Surname1," " ORDER BY Surname1,"
"Surname2," "Surname2,"
"FirstName," "FirstName,"
@ -5286,23 +5319,26 @@ static void Usr_GetAdmsLst (Hie_Lvl_Level_t Scope)
// and admins of the current institution, center or degree // and admins of the current institution, center or degree
DB_BuildQuery (&Query, DB_BuildQuery (&Query,
"SELECT %s" "SELECT %s"
" FROM usr_data" " FROM usr_data"
" WHERE UsrCod IN " " WHERE UsrCod IN "
"(SELECT UsrCod" "(SELECT UsrCod"
" FROM usr_admins" " FROM usr_admins"
" WHERE Scope='%s')" " WHERE Scope='%s')"
" OR UsrCod IN " " OR UsrCod IN "
"(SELECT UsrCod" "(SELECT UsrCod"
" FROM usr_admins" " FROM usr_admins"
" WHERE Scope='%s' AND Cod=%ld)" " WHERE Scope='%s'"
" OR UsrCod IN " " AND Cod=%ld)"
"(SELECT UsrCod" " OR UsrCod IN "
" FROM usr_admins" "(SELECT UsrCod"
" WHERE Scope='%s' AND Cod=%ld)" " FROM usr_admins"
" OR UsrCod IN " " WHERE Scope='%s'"
"(SELECT UsrCod" " AND Cod=%ld)"
" FROM usr_admins" " OR UsrCod IN "
" WHERE Scope='%s' AND Cod=%ld)" "(SELECT UsrCod"
" FROM usr_admins"
" WHERE Scope='%s'"
" AND Cod=%ld)"
" ORDER BY Surname1," " ORDER BY Surname1,"
"Surname2," "Surname2,"
"FirstName," "FirstName,"
@ -5375,7 +5411,9 @@ static void Usr_GetGstsLst (Hie_Lvl_Level_t Scope)
DB_BuildQuery (&Query, DB_BuildQuery (&Query,
"SELECT %s" "SELECT %s"
" FROM usr_data" " FROM usr_data"
" WHERE (CtyCod=%ld OR InsCtyCod=%ld)" " WHERE (CtyCod=%ld"
" OR"
" InsCtyCod=%ld)"
" AND UsrCod NOT IN" " AND UsrCod NOT IN"
" (SELECT UsrCod" " (SELECT UsrCod"
" FROM crs_users)" " FROM crs_users)"
@ -9313,7 +9351,8 @@ bool Usr_ChkIfUsrCodExists (long UsrCod)
/***** Get if a user exists in database *****/ /***** Get if a user exists in database *****/
return (DB_QueryCOUNT ("can not check if a user exists", return (DB_QueryCOUNT ("can not check if a user exists",
"SELECT COUNT(*) FROM usr_data" "SELECT COUNT(*)"
" FROM usr_data"
" WHERE UsrCod=%ld", " WHERE UsrCod=%ld",
UsrCod) != 0); UsrCod) != 0);
} }
@ -9361,7 +9400,8 @@ unsigned Usr_GetTotalNumberOfUsersInPlatform (void)
/***** Get number of users from database *****/ /***** Get number of users from database *****/
return return
(unsigned) DB_QueryCOUNT ("can not get number of users", (unsigned) DB_QueryCOUNT ("can not get number of users",
"SELECT COUNT(UsrCod) FROM usr_data"); "SELECT COUNT(UsrCod)"
" FROM usr_data");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -10060,7 +10100,8 @@ double Usr_GetCachedNumUsrsPerCrs (Hie_Lvl_Level_t Scope,long Cod,Rol_Role_t Rol
bool Usr_CheckIfUsrBanned (long UsrCod) bool Usr_CheckIfUsrBanned (long UsrCod)
{ {
return (DB_QueryCOUNT ("can not check if user is banned", return (DB_QueryCOUNT ("can not check if user is banned",
"SELECT COUNT(*) FROM usr_banned" "SELECT COUNT(*)"
" FROM usr_banned"
" WHERE UsrCod=%ld", " WHERE UsrCod=%ld",
UsrCod) != 0); UsrCod) != 0);
} }