mirror of https://github.com/acanas/swad-core.git
Version 20.52: Mar 28, 2021 Code refactoring in database selects.
This commit is contained in:
parent
bad9767bd1
commit
9af1bbaa51
244
swad_API.c
244
swad_API.c
|
@ -497,7 +497,8 @@ static int API_CheckCourseAndGroupCodes (struct soap *soap,
|
|||
|
||||
/***** Query if course code already exists in database *****/
|
||||
if (DB_QueryCOUNT ("can not get course",
|
||||
"SELECT COUNT(*) FROM crs_courses"
|
||||
"SELECT COUNT(*)"
|
||||
" FROM crs_courses"
|
||||
" WHERE CrsCod=%ld",
|
||||
CrsCod) != 1)
|
||||
return soap_sender_fault (soap,
|
||||
|
@ -598,7 +599,9 @@ static int API_GetCurrentDegCodFromCurrentCrsCod (void)
|
|||
|
||||
/***** Check that key does not exist in database *****/
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get the degree of a course",
|
||||
"SELECT DegCod FROM crs_courses WHERE CrsCod=%ld",
|
||||
"SELECT DegCod"
|
||||
" FROM crs_courses"
|
||||
" WHERE CrsCod=%ld",
|
||||
Gbl.Hierarchy.Crs.CrsCod)) // Course found in table of courses
|
||||
{
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
|
@ -633,7 +636,8 @@ static bool API_GetSomeUsrDataFromUsrCod (struct UsrData *UsrDat,long CrsCod)
|
|||
"FirstName," // row[2]
|
||||
"Photo," // row[3]
|
||||
"DATE_FORMAT(Birthday,'%%Y%%m%%d')" // row[4]
|
||||
" FROM usr_data WHERE UsrCod=%ld",
|
||||
" FROM usr_data"
|
||||
" WHERE UsrCod=%ld",
|
||||
UsrDat->UsrCod) != 1)
|
||||
return false;
|
||||
|
||||
|
@ -837,7 +841,8 @@ static int API_CheckParamsNewAccount (char *NewNickWithArr, // Input
|
|||
|
||||
/***** Check if the new nickname matches any of the nicknames of other users *****/
|
||||
if (DB_QueryCOUNT ("can not check if nickname already existed",
|
||||
"SELECT COUNT(*) FROM usr_nicknames"
|
||||
"SELECT COUNT(*)"
|
||||
" FROM usr_nicknames"
|
||||
" WHERE Nickname='%s'",
|
||||
NewNickWithoutArr)) // A nickname of another user is the same that this nickname
|
||||
return API_CHECK_NEW_ACCOUNT_NICKNAME_REGISTERED_BY_ANOTHER_USER;
|
||||
|
@ -850,8 +855,10 @@ static int API_CheckParamsNewAccount (char *NewNickWithArr, // Input
|
|||
{
|
||||
/***** Check if the new email matches any of the confirmed emails of other users *****/
|
||||
if (DB_QueryCOUNT ("can not check if email already existed",
|
||||
"SELECT COUNT(*) FROM usr_emails"
|
||||
" WHERE E_mail='%s' AND Confirmed='Y'",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM usr_emails"
|
||||
" WHERE E_mail='%s'"
|
||||
" AND Confirmed='Y'",
|
||||
NewEmail)) // An email of another user is the same that my email
|
||||
return API_CHECK_NEW_ACCOUNT_EMAIL_REGISTERED_BY_ANOTHER_USER;
|
||||
}
|
||||
|
@ -922,11 +929,13 @@ int swad__loginByUserPasswordKey (struct soap *soap,
|
|||
NumRows =
|
||||
(unsigned) DB_QuerySELECT (&mysql_res,"can not get user's data",
|
||||
"SELECT usr_nicknames.UsrCod"
|
||||
" FROM usr_nicknames,usr_data"
|
||||
" FROM usr_nicknames,"
|
||||
"usr_data"
|
||||
" WHERE usr_nicknames.Nickname='%s'"
|
||||
" AND usr_nicknames.UsrCod=usr_data.UsrCod"
|
||||
" AND usr_data.Password='%s'",
|
||||
UsrIDNickOrEmail,userPassword);
|
||||
UsrIDNickOrEmail,
|
||||
userPassword);
|
||||
}
|
||||
else if (Mai_CheckIfEmailIsValid (UsrIDNickOrEmail)) // 2: It's an email
|
||||
{
|
||||
|
@ -939,7 +948,8 @@ int swad__loginByUserPasswordKey (struct soap *soap,
|
|||
" WHERE usr_emails.E_mail='%s'"
|
||||
" AND usr_emails.UsrCod=usr_data.UsrCod"
|
||||
" AND usr_data.Password='%s'",
|
||||
UsrIDNickOrEmail,userPassword);
|
||||
UsrIDNickOrEmail,
|
||||
userPassword);
|
||||
}
|
||||
else // 3: It's not a nickname nor email
|
||||
{
|
||||
|
@ -1284,7 +1294,8 @@ int swad__getNewPassword (struct soap *soap,
|
|||
/* User has typed a nickname */
|
||||
NumRows =
|
||||
(unsigned) DB_QuerySELECT (&mysql_res,"can not get user's data",
|
||||
"SELECT UsrCod FROM usr_nicknames"
|
||||
"SELECT UsrCod"
|
||||
" FROM usr_nicknames"
|
||||
" WHERE Nickname='%s'",
|
||||
UsrIDNickOrEmail);
|
||||
}
|
||||
|
@ -1294,7 +1305,8 @@ int swad__getNewPassword (struct soap *soap,
|
|||
// TODO: Get only if email confirmed?
|
||||
NumRows =
|
||||
(unsigned) DB_QuerySELECT (&mysql_res,"can not get user's data",
|
||||
"SELECT UsrCod FROM usr_emails"
|
||||
"SELECT UsrCod"
|
||||
" FROM usr_emails"
|
||||
" WHERE E_mail='%s'",
|
||||
UsrIDNickOrEmail);
|
||||
}
|
||||
|
@ -2591,13 +2603,19 @@ int swad__getAttendanceEvents (struct soap *soap,
|
|||
/***** Query list of attendance events *****/
|
||||
NumRows =
|
||||
(unsigned) DB_QuerySELECT (&mysql_res,"can not get attendance events",
|
||||
"SELECT AttCod,Hidden,UsrCod,"
|
||||
"SELECT AttCod,"
|
||||
"Hidden,"
|
||||
"UsrCod,"
|
||||
"UNIX_TIMESTAMP(StartTime) AS ST,"
|
||||
"UNIX_TIMESTAMP(EndTime) AS ET,"
|
||||
"CommentTchVisible,Title,Txt"
|
||||
"CommentTchVisible,"
|
||||
"Title,"
|
||||
"Txt"
|
||||
" FROM att_events"
|
||||
" WHERE CrsCod=%d"
|
||||
" ORDER BY ST DESC,ET DESC,Title DESC",
|
||||
" ORDER BY ST DESC,"
|
||||
"ET DESC,"
|
||||
"Title DESC",
|
||||
courseCode);
|
||||
|
||||
getAttendanceEventsOut->eventsArray.__size =
|
||||
|
@ -3068,9 +3086,12 @@ int swad__getAttendanceUsers (struct soap *soap,
|
|||
NumRows =
|
||||
(unsigned) DB_QuerySELECT (&mysql_res,"can not get users"
|
||||
" in an attendance event",
|
||||
"SELECT u.UsrCod,u.Present"
|
||||
" FROM (SELECT UsrCod,Present"
|
||||
" FROM att_users WHERE AttCod=%ld"
|
||||
"SELECT u.UsrCod,"
|
||||
"u.Present"
|
||||
" FROM (SELECT UsrCod,"
|
||||
"Present"
|
||||
" FROM att_users"
|
||||
" WHERE AttCod=%ld"
|
||||
" UNION %s) AS u,"
|
||||
"usr_data"
|
||||
" WHERE u.UsrCod=usr_data.UsrCod"
|
||||
|
@ -3572,7 +3593,8 @@ static int API_GetMyLanguage (struct soap *soap)
|
|||
|
||||
/***** Get user's language *****/
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get user's language",
|
||||
"SELECT Language FROM usr_data"
|
||||
"SELECT Language"
|
||||
" FROM usr_data"
|
||||
" WHERE UsrCod=%ld",
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod) != 1)
|
||||
return soap_receiver_fault (soap,
|
||||
|
@ -3716,12 +3738,16 @@ int swad__sendMessage (struct soap *soap,
|
|||
{
|
||||
/***** Check if the original message was really received by me *****/
|
||||
if (!DB_QuerySELECT (&mysql_res,"can not check original message",
|
||||
"SELECT SUM(N) FROM"
|
||||
" (SELECT COUNT(*) AS N FROM msg_rcv"
|
||||
" WHERE UsrCod=%ld AND MsgCod=%ld"
|
||||
"SELECT SUM(N)"
|
||||
" FROM (SELECT COUNT(*) AS N"
|
||||
" FROM msg_rcv"
|
||||
" WHERE UsrCod=%ld"
|
||||
" AND MsgCod=%ld"
|
||||
" UNION"
|
||||
" SELECT COUNT(*) AS N FROM msg_rcv_deleted"
|
||||
" WHERE UsrCod=%ld AND MsgCod=%ld) AS T",
|
||||
" SELECT COUNT(*) AS N"
|
||||
" FROM msg_rcv_deleted"
|
||||
" WHERE UsrCod=%ld"
|
||||
" AND MsgCod=%ld) AS T",
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod,(long) messageCode,
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod,(long) messageCode))
|
||||
return soap_sender_fault (soap,
|
||||
|
@ -3746,12 +3772,15 @@ int swad__sendMessage (struct soap *soap,
|
|||
/***** Get the recipient of the message *****/
|
||||
NumRows =
|
||||
(unsigned) DB_QuerySELECT (&mysql_res,"can not check original message",
|
||||
"SELECT UsrCod FROM msg_snt"
|
||||
"SELECT UsrCod"
|
||||
" FROM msg_snt"
|
||||
" WHERE MsgCod=%ld"
|
||||
" UNION "
|
||||
"SELECT UsrCod FROM msg_snt_deleted"
|
||||
"SELECT UsrCod"
|
||||
" FROM msg_snt_deleted"
|
||||
" WHERE MsgCod=%ld",
|
||||
(long) messageCode,(long) messageCode);
|
||||
(long) messageCode,
|
||||
(long) messageCode);
|
||||
if (NumRows) // Message found in any of the two tables of sent messages
|
||||
{
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
|
@ -3774,7 +3803,10 @@ int swad__sendMessage (struct soap *soap,
|
|||
/***** Build query for recipients from database *****/
|
||||
if (ReplyUsrCod > 0)
|
||||
snprintf (Query,API_MAX_BYTES_QUERY_RECIPIENTS + 1,
|
||||
"SELECT UsrCod FROM usr_data WHERE UsrCod=%ld",ReplyUsrCod);
|
||||
"SELECT UsrCod"
|
||||
" FROM usr_data"
|
||||
" WHERE UsrCod=%ld",
|
||||
ReplyUsrCod);
|
||||
else
|
||||
Query[0] = '\0';
|
||||
|
||||
|
@ -3802,7 +3834,8 @@ int swad__sendMessage (struct soap *soap,
|
|||
{
|
||||
if (ReplyUsrCod > 0)
|
||||
Str_Concat (Query," UNION ",API_MAX_BYTES_QUERY_RECIPIENTS);
|
||||
Str_Concat (Query,"SELECT UsrCod FROM usr_nicknames"
|
||||
Str_Concat (Query,"SELECT UsrCod"
|
||||
" FROM usr_nicknames"
|
||||
" WHERE Nickname IN ('",
|
||||
API_MAX_BYTES_QUERY_RECIPIENTS);
|
||||
FirstNickname = false;
|
||||
|
@ -4131,8 +4164,14 @@ static int API_GetTstConfig (long CrsCod)
|
|||
|
||||
/***** Query database *****/
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get test configuration",
|
||||
"SELECT Pluggable,Min,Def,Max,MinTimeNxtTstPerQst,Visibility"
|
||||
" FROM tst_config WHERE CrsCod=%ld",
|
||||
"SELECT Pluggable," // row[0]
|
||||
"Min," // row[1]
|
||||
"Def," // row[2]
|
||||
"Max," // row[3]
|
||||
"MinTimeNxtTstPerQst," // row[4]
|
||||
"Visibility" // row[5]
|
||||
" FROM tst_config"
|
||||
" WHERE CrsCod=%ld",
|
||||
CrsCod))
|
||||
{
|
||||
/***** Get minimun, default and maximum *****/
|
||||
|
@ -4166,20 +4205,23 @@ static int API_GetNumTestQuestionsInCrs (long CrsCod)
|
|||
return
|
||||
(int) DB_QueryCOUNT ("can not get number of test questions",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM tst_questions,tst_question_tags,tst_tags"
|
||||
" FROM tst_questions,"
|
||||
"tst_question_tags,"
|
||||
"tst_tags"
|
||||
" WHERE tst_questions.CrsCod=%ld"
|
||||
" AND tst_questions.QstCod NOT IN"
|
||||
|
||||
" (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'"
|
||||
" AND tst_tags.TagCod=tst_question_tags.TagCod)"
|
||||
|
||||
" AND tst_questions.QstCod=tst_question_tags.QstCod"
|
||||
" AND tst_question_tags.TagCod=tst_tags.TagCod"
|
||||
" AND tst_tags.CrsCod=%ld",
|
||||
CrsCod,CrsCod,CrsCod);
|
||||
CrsCod,
|
||||
CrsCod,
|
||||
CrsCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -4286,9 +4328,11 @@ static int API_GetTstTags (struct soap *soap,
|
|||
|
||||
/***** Get available tags from database *****/
|
||||
NumRows = DB_QuerySELECT (&mysql_res,"can not get test tags",
|
||||
"SELECT TagCod,TagTxt"
|
||||
"SELECT TagCod," // row[0]
|
||||
"TagTxt" // row[1]
|
||||
" FROM tst_tags"
|
||||
" WHERE CrsCod=%ld AND TagHidden='N'"
|
||||
" WHERE CrsCod=%ld"
|
||||
" AND TagHidden='N'"
|
||||
" ORDER BY TagTxt",
|
||||
CrsCod);
|
||||
|
||||
|
@ -4345,24 +4389,28 @@ static int API_GetTstQuestions (struct soap *soap,
|
|||
// DISTINCTROW is necessary to not repeat questions
|
||||
NumRows =
|
||||
(unsigned) DB_QuerySELECT (&mysql_res,"can not get test questions",
|
||||
"SELECT DISTINCTROW tst_questions.QstCod,"
|
||||
"tst_questions.AnsType,tst_questions.Shuffle,"
|
||||
"tst_questions.Stem,tst_questions.Feedback"
|
||||
" FROM tst_questions,tst_question_tags,tst_tags"
|
||||
"SELECT DISTINCTROW tst_questions.QstCod," // row[0]
|
||||
"tst_questions.AnsType," // row[1]
|
||||
"tst_questions.Shuffle," // row[2]
|
||||
"tst_questions.Stem," // row[3]
|
||||
"tst_questions.Feedback" // row[4]
|
||||
" FROM tst_questions,"
|
||||
"tst_question_tags,"
|
||||
"tst_tags"
|
||||
" WHERE tst_questions.CrsCod=%ld"
|
||||
" AND tst_questions.QstCod NOT IN"
|
||||
" (SELECT tst_question_tags.QstCod FROM tst_tags,tst_question_tags"
|
||||
" WHERE tst_tags.CrsCod=%ld AND tst_tags.TagHidden='Y'"
|
||||
" (SELECT tst_question_tags.QstCod"
|
||||
" FROM tst_tags,"
|
||||
"tst_question_tags"
|
||||
" WHERE tst_tags.CrsCod=%ld"
|
||||
" AND tst_tags.TagHidden='Y'"
|
||||
" AND tst_tags.TagCod=tst_question_tags.TagCod)"
|
||||
" AND tst_questions.QstCod=tst_question_tags.QstCod"
|
||||
" AND tst_question_tags.TagCod=tst_tags.TagCod"
|
||||
" AND tst_tags.CrsCod=%ld"
|
||||
" AND "
|
||||
"("
|
||||
"tst_questions.EditTime>=FROM_UNIXTIME(%ld)"
|
||||
" AND (tst_questions.EditTime>=FROM_UNIXTIME(%ld)"
|
||||
" OR "
|
||||
"tst_tags.ChangeTime>=FROM_UNIXTIME(%ld)"
|
||||
")"
|
||||
"tst_tags.ChangeTime>=FROM_UNIXTIME(%ld))"
|
||||
" ORDER BY QstCod",
|
||||
CrsCod,CrsCod,CrsCod,
|
||||
BeginTime,
|
||||
|
@ -4437,26 +4485,33 @@ static int API_GetTstAnswers (struct soap *soap,
|
|||
/***** Get recent test questions from database *****/
|
||||
NumRows =
|
||||
(unsigned) DB_QuerySELECT (&mysql_res,"can not get test answers",
|
||||
"SELECT QstCod,AnsInd,Correct,Answer,Feedback"
|
||||
" FROM tst_answers WHERE QstCod IN "
|
||||
"SELECT QstCod,"
|
||||
"AnsInd,"
|
||||
"Correct,"
|
||||
"Answer,"
|
||||
"Feedback"
|
||||
" FROM tst_answers"
|
||||
" WHERE QstCod IN "
|
||||
"(SELECT tst_questions.QstCod"
|
||||
" FROM tst_questions,tst_question_tags,tst_tags"
|
||||
" FROM tst_questions,"
|
||||
"tst_question_tags,"
|
||||
"tst_tags"
|
||||
" WHERE tst_questions.CrsCod=%ld"
|
||||
" AND tst_questions.QstCod NOT IN"
|
||||
" (SELECT tst_question_tags.QstCod FROM tst_tags,tst_question_tags"
|
||||
" WHERE tst_tags.CrsCod=%ld AND tst_tags.TagHidden='Y'"
|
||||
" (SELECT tst_question_tags.QstCod"
|
||||
" FROM tst_tags,"
|
||||
"tst_question_tags"
|
||||
" WHERE tst_tags.CrsCod=%ld"
|
||||
" AND tst_tags.TagHidden='Y'"
|
||||
" AND tst_tags.TagCod=tst_question_tags.TagCod)"
|
||||
" AND tst_questions.QstCod=tst_question_tags.QstCod"
|
||||
" AND tst_question_tags.TagCod=tst_tags.TagCod"
|
||||
" AND tst_tags.CrsCod=%ld"
|
||||
" AND "
|
||||
"("
|
||||
"tst_questions.EditTime>=FROM_UNIXTIME(%ld)"
|
||||
" AND (tst_questions.EditTime>=FROM_UNIXTIME(%ld)"
|
||||
" OR "
|
||||
"tst_tags.ChangeTime>=FROM_UNIXTIME(%ld)"
|
||||
")"
|
||||
")"
|
||||
" ORDER BY QstCod,AnsInd",
|
||||
"tst_tags.ChangeTime>=FROM_UNIXTIME(%ld)))"
|
||||
" ORDER BY QstCod,"
|
||||
"AnsInd",
|
||||
CrsCod,CrsCod,CrsCod,
|
||||
BeginTime,
|
||||
BeginTime);
|
||||
|
@ -4528,26 +4583,31 @@ static int API_GetTstQuestionTags (struct soap *soap,
|
|||
/***** Get recent test questions from database *****/
|
||||
NumRows =
|
||||
(unsigned) DB_QuerySELECT (&mysql_res,"can not get test question tags",
|
||||
"SELECT QstCod,TagCod,TagInd"
|
||||
" FROM tst_question_tags WHERE QstCod IN "
|
||||
"SELECT QstCod,"
|
||||
"TagCod,"
|
||||
"TagInd"
|
||||
" FROM tst_question_tags"
|
||||
" WHERE QstCod IN "
|
||||
"(SELECT tst_questions.QstCod"
|
||||
" FROM tst_questions,tst_question_tags,tst_tags"
|
||||
" FROM tst_questions,"
|
||||
"tst_question_tags,"
|
||||
"tst_tags"
|
||||
" WHERE tst_questions.CrsCod=%ld"
|
||||
" AND tst_questions.QstCod NOT IN"
|
||||
" (SELECT tst_question_tags.QstCod FROM tst_tags,tst_question_tags"
|
||||
" WHERE tst_tags.CrsCod=%ld AND tst_tags.TagHidden='Y'"
|
||||
" (SELECT tst_question_tags.QstCod"
|
||||
" FROM tst_tags,"
|
||||
"tst_question_tags"
|
||||
" WHERE tst_tags.CrsCod=%ld"
|
||||
" AND tst_tags.TagHidden='Y'"
|
||||
" AND tst_tags.TagCod=tst_question_tags.TagCod)"
|
||||
" AND tst_questions.QstCod=tst_question_tags.QstCod"
|
||||
" AND tst_question_tags.TagCod=tst_tags.TagCod"
|
||||
" AND tst_tags.CrsCod=%ld"
|
||||
" AND "
|
||||
"("
|
||||
"tst_questions.EditTime>=FROM_UNIXTIME(%ld)"
|
||||
" AND (tst_questions.EditTime>=FROM_UNIXTIME(%ld)"
|
||||
" OR "
|
||||
"tst_tags.ChangeTime>=FROM_UNIXTIME(%ld)"
|
||||
")"
|
||||
")"
|
||||
" ORDER BY QstCod,TagInd",
|
||||
"tst_tags.ChangeTime>=FROM_UNIXTIME(%ld)))"
|
||||
" ORDER BY QstCod,"
|
||||
"TagInd",
|
||||
CrsCod,CrsCod,CrsCod,
|
||||
BeginTime,
|
||||
BeginTime);
|
||||
|
@ -4680,12 +4740,13 @@ int swad__getTrivialQuestion (struct soap *soap,
|
|||
NumRows =
|
||||
(unsigned) DB_QuerySELECT (&mysql_res,"can not get test questions",
|
||||
"SELECT DISTINCTROW "
|
||||
"tst_questions.QstCod,"
|
||||
"tst_questions.AnsType,"
|
||||
"tst_questions.Shuffle,"
|
||||
"tst_questions.Stem,"
|
||||
"tst_questions.Feedback,"
|
||||
"tst_questions.Score/tst_questions.NumHits AS S"
|
||||
"tst_questions.QstCod," // row[0]
|
||||
"tst_questions.AnsType," // row[1]
|
||||
"tst_questions.Shuffle," // row[2]
|
||||
"tst_questions.Stem," // row[3]
|
||||
"tst_questions.Feedback," // row[4]
|
||||
"tst_questions.Score/"
|
||||
"tst_questions.NumHits AS S" // row[5]
|
||||
" FROM crs_courses,"
|
||||
"tst_questions"
|
||||
" WHERE crs_courses.DegCod IN (%s)"
|
||||
|
@ -4701,8 +4762,10 @@ int swad__getTrivialQuestion (struct soap *soap,
|
|||
" AND crs_courses.CrsCod=tst_tags.CrsCod"
|
||||
" AND tst_tags.TagHidden='Y'"
|
||||
" AND tst_tags.TagCod=tst_question_tags.TagCod)"
|
||||
" HAVING S>='%f' AND S<='%f'"
|
||||
" ORDER BY RAND() LIMIT 1",
|
||||
" HAVING S>='%f'"
|
||||
" AND S<='%f'"
|
||||
" ORDER BY RAND()"
|
||||
" LIMIT 1",
|
||||
DegreesStr,DegreesStr,
|
||||
lowerScore,upperScore);
|
||||
Str_SetDecimalPointToLocal (); // Return to local system
|
||||
|
@ -4765,10 +4828,15 @@ int swad__getTrivialQuestion (struct soap *soap,
|
|||
if (QstCod > 0)
|
||||
{
|
||||
/***** Get answer from database *****/
|
||||
NumRows =
|
||||
(unsigned) DB_QuerySELECT (&mysql_res,"can not get test answers",
|
||||
"SELECT QstCod,AnsInd,Correct,Answer,Feedback"
|
||||
" FROM tst_answers WHERE QstCod=%ld"
|
||||
NumRows = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get test answers",
|
||||
"SELECT QstCod," // row[0]
|
||||
"AnsInd," // row[1]
|
||||
"Correct," // row[2]
|
||||
"Answer," // row[3]
|
||||
"Feedback" // row[4]
|
||||
" FROM tst_answers"
|
||||
" WHERE QstCod=%ld"
|
||||
" ORDER BY AnsInd",
|
||||
QstCod);
|
||||
|
||||
|
@ -5401,9 +5469,11 @@ static void API_GetListGrpsInGameFromDB (struct soap *soap,
|
|||
size_t Length;
|
||||
|
||||
/***** Get list of groups *****/
|
||||
NumGrps =
|
||||
(unsigned) DB_QuerySELECT (&mysql_res,"can not get groups of a match",
|
||||
"SELECT GrpCod FROM mch_groups WHERE MchCod=%ld",
|
||||
NumGrps = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get groups of a match",
|
||||
"SELECT GrpCod"
|
||||
" FROM mch_groups"
|
||||
" WHERE MchCod=%ld",
|
||||
MchCod);
|
||||
if (NumGrps == 0)
|
||||
*ListGroups = NULL;
|
||||
|
|
|
@ -659,8 +659,10 @@ static bool Acc_GetParamsNewAccount (char NewNickWithoutArr[Nck_MAX_BYTES_NICK_F
|
|||
/* Check if the new nickname
|
||||
matches any of the nicknames of other users */
|
||||
if (DB_QueryCOUNT ("can not check if nickname already existed",
|
||||
"SELECT COUNT(*) FROM usr_nicknames"
|
||||
" WHERE Nickname='%s' AND UsrCod<>%ld",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM usr_nicknames"
|
||||
" WHERE Nickname='%s'"
|
||||
" AND UsrCod<>%ld",
|
||||
NewNickWithoutArr,
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod)) // A nickname of another user is the same that this nickname
|
||||
{
|
||||
|
@ -686,8 +688,10 @@ static bool Acc_GetParamsNewAccount (char NewNickWithoutArr[Nck_MAX_BYTES_NICK_F
|
|||
/* Check if the new email matches
|
||||
any of the confirmed emails of other users */
|
||||
if (DB_QueryCOUNT ("can not check if email already existed",
|
||||
"SELECT COUNT(*) FROM usr_emails"
|
||||
" WHERE E_mail='%s' AND Confirmed='Y'",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM usr_emails"
|
||||
" WHERE E_mail='%s'"
|
||||
" AND Confirmed='Y'",
|
||||
NewEmail)) // An email of another user is the same that my email
|
||||
{
|
||||
Error = true;
|
||||
|
|
|
@ -1151,7 +1151,8 @@ static void Agd_GetListEvents (struct Agd_Agenda *Agenda,
|
|||
{
|
||||
/* Make query */
|
||||
NumRows = DB_QuerySELECT (&mysql_res,"can not get agenda events",
|
||||
"SELECT AgdCod FROM agd_agendas"
|
||||
"SELECT AgdCod"
|
||||
" FROM agd_agendas"
|
||||
" WHERE %s%s%s%s"
|
||||
" ORDER BY %s",
|
||||
UsrSubQuery,
|
||||
|
|
|
@ -132,7 +132,8 @@ void Ann_ShowAllAnnouncements (void)
|
|||
"Subject," // row[3]
|
||||
"Content" // row[4]
|
||||
" FROM ann_announcements"
|
||||
" WHERE Status=%u AND (Roles&%u)<>0 "
|
||||
" WHERE Status=%u"
|
||||
" AND (Roles&%u)<>0 "
|
||||
" ORDER BY AnnCod DESC",
|
||||
(unsigned) Ann_ACTIVE_ANNOUNCEMENT,
|
||||
(unsigned) (1 << Rol_UNK));
|
||||
|
|
|
@ -1204,7 +1204,8 @@ static bool Asg_CheckIfSimilarAssignmentExists (const char *Field,const char *Va
|
|||
"SELECT COUNT(*)"
|
||||
" FROM asg_assignments"
|
||||
" WHERE CrsCod=%ld"
|
||||
" AND %s='%s' AND AsgCod<>%ld",
|
||||
" AND %s='%s'"
|
||||
" AND AsgCod<>%ld",
|
||||
Gbl.Hierarchy.Crs.CrsCod,
|
||||
Field,Value,AsgCod) != 0);
|
||||
}
|
||||
|
|
|
@ -770,12 +770,15 @@ bool Att_GetDataOfAttEventByCod (struct Att_Event *Event)
|
|||
{
|
||||
/***** Build query *****/
|
||||
NumRows = DB_QuerySELECT (&mysql_res,"can not get attendance event data",
|
||||
"SELECT AttCod,CrsCod,Hidden,UsrCod,"
|
||||
"UNIX_TIMESTAMP(StartTime),"
|
||||
"UNIX_TIMESTAMP(EndTime),"
|
||||
"NOW() BETWEEN StartTime AND EndTime,"
|
||||
"CommentTchVisible,"
|
||||
"Title"
|
||||
"SELECT AttCod," // row[0]
|
||||
"CrsCod," // row[1]
|
||||
"Hidden," // row[2]
|
||||
"UsrCod," // row[3]
|
||||
"UNIX_TIMESTAMP(StartTime)," // row[4]
|
||||
"UNIX_TIMESTAMP(EndTime)," // row[5]
|
||||
"NOW() BETWEEN StartTime AND EndTime," // row[6]
|
||||
"CommentTchVisible," // row[7]
|
||||
"Title" // row[8]
|
||||
" FROM att_events"
|
||||
" WHERE AttCod=%ld",
|
||||
Event->AttCod);
|
||||
|
@ -870,8 +873,10 @@ static void Att_GetAttEventDescriptionFromDB (long AttCod,char Description[Cns_M
|
|||
|
||||
/***** Get text of attendance event from database *****/
|
||||
NumRows = DB_QuerySELECT (&mysql_res,"can not get attendance event text",
|
||||
"SELECT Txt FROM att_events"
|
||||
" WHERE AttCod=%ld AND CrsCod=%ld",
|
||||
"SELECT Txt"
|
||||
" FROM att_events"
|
||||
" WHERE AttCod=%ld"
|
||||
" AND CrsCod=%ld",
|
||||
AttCod,Gbl.Hierarchy.Crs.CrsCod);
|
||||
|
||||
/***** The result of the query must have one row or none *****/
|
||||
|
@ -1067,9 +1072,11 @@ static bool Att_CheckIfSimilarAttEventExists (const char *Field,const char *Valu
|
|||
/***** Get number of attendance events
|
||||
with a field value from database *****/
|
||||
return (DB_QueryCOUNT ("can not get similar attendance events",
|
||||
"SELECT COUNT(*) FROM att_events"
|
||||
"SELECT COUNT(*)"
|
||||
" FROM att_events"
|
||||
" WHERE CrsCod=%ld"
|
||||
" AND %s='%s' AND AttCod<>%ld",
|
||||
" AND %s='%s'"
|
||||
" AND AttCod<>%ld",
|
||||
Gbl.Hierarchy.Crs.CrsCod,
|
||||
Field,Value,AttCod) != 0);
|
||||
}
|
||||
|
@ -1697,10 +1704,10 @@ void Att_RemoveCrsAttEvents (long CrsCod)
|
|||
unsigned Att_GetNumAttEventsInCrs (long CrsCod)
|
||||
{
|
||||
/***** Get number of attendance events in a course from database *****/
|
||||
return
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of attendance events"
|
||||
" in course",
|
||||
"SELECT COUNT(*) FROM att_events"
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of attendance events in course",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM att_events"
|
||||
" WHERE CrsCod=%ld",
|
||||
CrsCod);
|
||||
}
|
||||
|
@ -1802,7 +1809,8 @@ unsigned Att_GetNumAttEvents (Hie_Lvl_Level_t Scope,unsigned *NumNotif)
|
|||
{
|
||||
case Hie_Lvl_SYS:
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of attendance events",
|
||||
"SELECT COUNT(*),SUM(NumNotif)"
|
||||
"SELECT COUNT(*),"
|
||||
"SUM(NumNotif)"
|
||||
" FROM att_events"
|
||||
" WHERE CrsCod>0");
|
||||
break;
|
||||
|
@ -3071,8 +3079,8 @@ static void Att_GetListSelectedAttCods (struct Att_Events *Events)
|
|||
else // No students attended to this event
|
||||
{
|
||||
/***** Get groups associated to an attendance event from database *****/
|
||||
NumGrpsInThisEvent = (unsigned) DB_QuerySELECT (&mysql_res,"can not get groups"
|
||||
" of an attendance event",
|
||||
NumGrpsInThisEvent = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get groups of an attendance event",
|
||||
"SELECT GrpCod" // row[0]
|
||||
" FROM att_groups"
|
||||
" WHERE att_groups.AttCod=%ld",
|
||||
|
|
|
@ -903,7 +903,8 @@ void Cfe_CreateListCallsForExams (struct Cfe_CallsForExams *CallsForExams)
|
|||
"SELECT ExaCod," // row[0]
|
||||
"DATE(ExamDate)" // row[1]
|
||||
" FROM cfe_exams"
|
||||
" WHERE CrsCod=%ld AND Status=%u"
|
||||
" WHERE CrsCod=%ld"
|
||||
" AND Status=%u"
|
||||
" ORDER BY ExamDate DESC",
|
||||
Gbl.Hierarchy.Crs.CrsCod,
|
||||
(unsigned) Cfe_VISIBLE_CALL_FOR_EXAM);
|
||||
|
|
|
@ -130,8 +130,8 @@ void Ctr_SeeCtrWithPendingDegs (void)
|
|||
case Rol_CTR_ADM:
|
||||
NumCtrs = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get centers with pending degrees",
|
||||
"SELECT deg_degrees.CtrCod,"
|
||||
"COUNT(*)"
|
||||
"SELECT deg_degrees.CtrCod," // row[0]
|
||||
"COUNT(*)" // row[1]
|
||||
" FROM deg_degrees,"
|
||||
"ctr_admin,"
|
||||
"ctr_centers"
|
||||
|
@ -656,9 +656,11 @@ void Ctr_GetFullListOfCenters (long InsCod)
|
|||
" FROM ctr_centers"
|
||||
" WHERE InsCod=%ld"
|
||||
" AND CtrCod NOT IN"
|
||||
" (SELECT DISTINCT CtrCod FROM usr_data))"
|
||||
" (SELECT DISTINCT CtrCod"
|
||||
" FROM usr_data))"
|
||||
" ORDER BY %s",
|
||||
InsCod,InsCod,
|
||||
InsCod,
|
||||
InsCod,
|
||||
OrderBySubQuery[Gbl.Hierarchy.Ctrs.SelectedOrder]);
|
||||
|
||||
if (NumRows) // Centers found...
|
||||
|
@ -801,7 +803,9 @@ long Ctr_GetInsCodOfCenterByCod (long CtrCod)
|
|||
{
|
||||
/***** Get the institution code of a center from database *****/
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get the institution of a center",
|
||||
"SELECT InsCod FROM ctr_centers WHERE CtrCod=%ld",
|
||||
"SELECT InsCod"
|
||||
" FROM ctr_centers"
|
||||
" WHERE CtrCod=%ld",
|
||||
CtrCod) == 1)
|
||||
{
|
||||
/***** Get the institution code of this center *****/
|
||||
|
@ -830,7 +834,9 @@ void Ctr_GetShortNameOfCenterByCod (struct Ctr_Center *Ctr)
|
|||
{
|
||||
/***** Get the short name of a center from database *****/
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get the short name of a center",
|
||||
"SELECT ShortName FROM ctr_centers WHERE CtrCod=%ld",
|
||||
"SELECT ShortName"
|
||||
" FROM ctr_centers"
|
||||
" WHERE CtrCod=%ld",
|
||||
Ctr->CtrCod) == 1)
|
||||
{
|
||||
/***** Get the short name of this center *****/
|
||||
|
@ -1435,9 +1441,15 @@ bool Ctr_CheckIfCtrNameExistsInIns (const char *FieldName,const char *Name,
|
|||
/***** Get number of centers with a name from database *****/
|
||||
return (DB_QueryCOUNT ("can not check if the name of a center"
|
||||
" already existed",
|
||||
"SELECT COUNT(*) FROM ctr_centers"
|
||||
" WHERE InsCod=%ld AND %s='%s' AND CtrCod<>%ld",
|
||||
InsCod,FieldName,Name,CtrCod) != 0);
|
||||
"SELECT COUNT(*)"
|
||||
" FROM ctr_centers"
|
||||
" WHERE InsCod=%ld"
|
||||
" AND %s='%s'"
|
||||
" AND CtrCod<>%ld",
|
||||
InsCod,
|
||||
FieldName,
|
||||
Name,
|
||||
CtrCod) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -2000,7 +2012,9 @@ unsigned Ctr_GetNumCtrsInIns (long InsCod)
|
|||
Gbl.Cache.NumCtrsInIns.InsCod = InsCod;
|
||||
Gbl.Cache.NumCtrsInIns.NumCtrs = (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of centers in an institution",
|
||||
"SELECT COUNT(*) FROM ctr_centers WHERE InsCod=%ld",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM ctr_centers"
|
||||
" WHERE InsCod=%ld",
|
||||
InsCod);
|
||||
FigCch_UpdateFigureIntoCache (FigCch_NUM_CTRS,Hie_Lvl_INS,Gbl.Cache.NumCtrsInIns.InsCod,
|
||||
FigCch_UNSIGNED,&Gbl.Cache.NumCtrsInIns.NumCtrs);
|
||||
|
@ -2036,8 +2050,10 @@ unsigned Ctr_GetCachedNumCtrsWithMapInSys (void)
|
|||
/* Ccoordinates 0, 0 means not set ==> don't show map */
|
||||
NumCtrsWithMap = (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of centers with map",
|
||||
"SELECT COUNT(*) FROM ctr_centers"
|
||||
" WHERE Latitude<>0 OR Longitude<>0");
|
||||
"SELECT COUNT(*)"
|
||||
" FROM ctr_centers"
|
||||
" WHERE Latitude<>0"
|
||||
" OR Longitude<>0");
|
||||
FigCch_UpdateFigureIntoCache (FigCch_NUM_CTRS_WITH_MAP,Hie_Lvl_SYS,-1L,
|
||||
FigCch_UNSIGNED,&NumCtrsWithMap);
|
||||
}
|
||||
|
@ -2092,9 +2108,11 @@ unsigned Ctr_GetCachedNumCtrsWithMapInIns (long InsCod)
|
|||
/* Ccoordinates 0, 0 means not set ==> don't show map */
|
||||
NumCtrsWithMap = (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of centers with map",
|
||||
"SELECT COUNT(*) FROM ctr_centers"
|
||||
"SELECT COUNT(*)"
|
||||
" FROM ctr_centers"
|
||||
" WHERE InsCod=%ld"
|
||||
" AND (Latitude<>0 OR Longitude<>0)",
|
||||
" AND (Latitude<>0"
|
||||
" OR Longitude<>0)",
|
||||
InsCod);
|
||||
FigCch_UpdateFigureIntoCache (FigCch_NUM_CTRS_WITH_MAP,Hie_Lvl_INS,InsCod,
|
||||
FigCch_UNSIGNED,&NumCtrsWithMap);
|
||||
|
@ -2112,9 +2130,12 @@ unsigned Ctr_GetNumCtrsInPlc (long PlcCod)
|
|||
/***** Get number of centers (of the current institution) in a place *****/
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get the number of centers in a place",
|
||||
"SELECT COUNT(*) FROM ctr_centers"
|
||||
" WHERE InsCod=%ld AND PlcCod=%ld",
|
||||
Gbl.Hierarchy.Ins.InsCod,PlcCod);
|
||||
"SELECT COUNT(*)"
|
||||
" FROM ctr_centers"
|
||||
" WHERE InsCod=%ld"
|
||||
" AND PlcCod=%ld",
|
||||
Gbl.Hierarchy.Ins.InsCod,
|
||||
PlcCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -517,7 +517,8 @@ static void CtrCfg_GetPhotoAttr (long CtrCod,char **PhotoAttribution)
|
|||
|
||||
/***** Get photo attribution from database *****/
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get photo attribution",
|
||||
"SELECT PhotoAttribution FROM ctr_centers"
|
||||
"SELECT PhotoAttribution"
|
||||
" FROM ctr_centers"
|
||||
" WHERE CtrCod=%ld",
|
||||
CtrCod))
|
||||
{
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
#define Log_PLATFORM_VERSION "SWAD 20.51.49 (2021-03-26)"
|
||||
#define Log_PLATFORM_VERSION "SWAD 20.52 (2021-03-28)"
|
||||
#define CSS_FILE "swad20.45.css"
|
||||
#define JS_FILE "swad20.6.2.js"
|
||||
/*
|
||||
TODO: Rename CENTRE to CENTER in help wiki.
|
||||
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
|
||||
|
||||
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)
|
||||
1 change necessary in database:
|
||||
RENAME TABLE usr_IDs TO usr_ids;
|
||||
|
|
|
@ -356,7 +356,7 @@ static unsigned Cht_GetNumUsrsInChatRoom (const char *RoomCode)
|
|||
/***** Get number of users connected to chat rooms from database *****/
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get number of users"
|
||||
" connected to a chat room",
|
||||
"SELECT NumUsrs"
|
||||
"SELECT NumUsrs" // row[0]
|
||||
" FROM cht_rooms"
|
||||
" WHERE RoomCode='%s'",
|
||||
RoomCode))
|
||||
|
|
|
@ -126,8 +126,8 @@ void Cty_SeeCtyWithPendingInss (void)
|
|||
NumCtys = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get countries"
|
||||
" with pending institutions",
|
||||
"SELECT ins_instits.CtyCod,"
|
||||
"COUNT(*)"
|
||||
"SELECT ins_instits.CtyCod," // row[0]
|
||||
"COUNT(*)" // row[1]
|
||||
" FROM ins_instits,"
|
||||
"cty_countrs"
|
||||
" WHERE (ins_instits.Status & %u)<>0"
|
||||
|
@ -888,7 +888,8 @@ void Cty_GetFullListOfCountries (void)
|
|||
"0 AS NumUsrs" // row[...]
|
||||
" FROM cty_countrs"
|
||||
" WHERE CtyCod NOT IN"
|
||||
" (SELECT DISTINCT CtyCod FROM usr_data))"
|
||||
" (SELECT DISTINCT CtyCod"
|
||||
" FROM usr_data))"
|
||||
" ORDER BY %s",
|
||||
SubQueryNam1,SubQueryWWW1,
|
||||
SubQueryNam2,SubQueryWWW2,OrderBySubQuery);
|
||||
|
@ -2066,7 +2067,8 @@ unsigned Cty_GetCachedNumCtysWithUsrs (Rol_Role_t Role,const char *SubQuery,
|
|||
"deg_degrees,"
|
||||
"crs_courses,"
|
||||
"crs_users"
|
||||
" WHERE %scty_countrs.CtyCod=ins_instits.CtyCod"
|
||||
" WHERE %s"
|
||||
"cty_countrs.CtyCod=ins_instits.CtyCod"
|
||||
" AND ins_instits.InsCod=ctr_centers.InsCod"
|
||||
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
|
||||
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
||||
|
|
|
@ -300,8 +300,8 @@ static void CtyCfg_Map (void)
|
|||
Map_AddTileLayer ();
|
||||
|
||||
/* Get centers with coordinates */
|
||||
NumCtrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get centers"
|
||||
" with coordinates",
|
||||
NumCtrs = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get centers with coordinates",
|
||||
"SELECT ctr_centers.CtrCod" // row[0]
|
||||
" FROM ins_instits,"
|
||||
"ctr_centers"
|
||||
|
|
|
@ -599,7 +599,9 @@ unsigned Crs_GetNumCrssInDeg (long DegCod)
|
|||
Gbl.Cache.NumCrssInDeg.DegCod = DegCod;
|
||||
Gbl.Cache.NumCrssInDeg.NumCrss = (unsigned)
|
||||
DB_QueryCOUNT ("can not get the number of courses in a degree",
|
||||
"SELECT COUNT(*) FROM crs_courses WHERE DegCod=%ld",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM crs_courses"
|
||||
" WHERE DegCod=%ld",
|
||||
DegCod);
|
||||
FigCch_UpdateFigureIntoCache (FigCch_NUM_CRSS,Hie_Lvl_DEG,Gbl.Cache.NumCrssInDeg.DegCod,
|
||||
FigCch_UNSIGNED,&Gbl.Cache.NumCrssInDeg.NumCrss);
|
||||
|
@ -692,8 +694,8 @@ void Crs_WriteSelectorOfCourse (void)
|
|||
/***** Get courses belonging to the current degree from database *****/
|
||||
NumCrss = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get courses of a degree",
|
||||
"SELECT CrsCod,"
|
||||
"ShortName"
|
||||
"SELECT CrsCod," // row[0]
|
||||
"ShortName" // row[1]
|
||||
" FROM crs_courses"
|
||||
" WHERE DegCod=%ld"
|
||||
" ORDER BY ShortName",
|
||||
|
@ -768,33 +770,37 @@ static void Crs_GetListCrssInCurrentDeg (Crs_WhatCourses_t WhatCourses)
|
|||
case Crs_ACTIVE_COURSES:
|
||||
NumCrss = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get courses of a degree",
|
||||
"SELECT CrsCod,"
|
||||
"DegCod,"
|
||||
"Year,"
|
||||
"InsCrsCod,"
|
||||
"Status,"
|
||||
"RequesterUsrCod,"
|
||||
"ShortName,"
|
||||
"FullName"
|
||||
"SELECT CrsCod," // row[0]
|
||||
"DegCod," // row[1]
|
||||
"Year," // row[2]
|
||||
"InsCrsCod," // row[3]
|
||||
"Status," // row[4]
|
||||
"RequesterUsrCod," // row[5]
|
||||
"ShortName," // row[6]
|
||||
"FullName" // row[7]
|
||||
" FROM crs_courses"
|
||||
" WHERE DegCod=%ld AND Status=0"
|
||||
" ORDER BY Year,ShortName",
|
||||
" WHERE DegCod=%ld"
|
||||
" AND Status=0"
|
||||
" ORDER BY Year,"
|
||||
"ShortName",
|
||||
Gbl.Hierarchy.Deg.DegCod);
|
||||
break;
|
||||
case Crs_ALL_COURSES_EXCEPT_REMOVED:
|
||||
NumCrss = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get courses of a degree",
|
||||
"SELECT CrsCod,"
|
||||
"DegCod,"
|
||||
"Year,"
|
||||
"InsCrsCod,"
|
||||
"Status,"
|
||||
"RequesterUsrCod,"
|
||||
"ShortName,"
|
||||
"FullName"
|
||||
"SELECT CrsCod," // row[0]
|
||||
"DegCod," // row[1]
|
||||
"Year," // row[2]
|
||||
"InsCrsCod," // row[3]
|
||||
"Status," // row[4]
|
||||
"RequesterUsrCod," // row[5]
|
||||
"ShortName," // row[6]
|
||||
"FullName" // row[7]
|
||||
" FROM crs_courses"
|
||||
" WHERE DegCod=%ld AND (Status & %u)=0"
|
||||
" ORDER BY Year,ShortName",
|
||||
" WHERE DegCod=%ld"
|
||||
" AND (Status & %u)=0"
|
||||
" ORDER BY Year,"
|
||||
"ShortName",
|
||||
Gbl.Hierarchy.Deg.DegCod,
|
||||
(unsigned) Crs_STATUS_BIT_REMOVED);
|
||||
break;
|
||||
|
@ -1864,8 +1870,8 @@ static void Crs_GetShortNamesByCod (long CrsCod,
|
|||
{
|
||||
/***** Get the short name of a degree from database *****/
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get the short name of a course",
|
||||
"SELECT crs_courses.ShortName,"
|
||||
"deg_degrees.ShortName"
|
||||
"SELECT crs_courses.ShortName," // row[0]
|
||||
"deg_degrees.ShortName" // row[1]
|
||||
" FROM crs_courses,"
|
||||
"deg_degrees"
|
||||
" WHERE crs_courses.CrsCod=%ld"
|
||||
|
@ -2327,10 +2333,17 @@ bool Crs_CheckIfCrsNameExistsInYearOfDeg (const char *FieldName,const char *Name
|
|||
/***** Get number of courses in a year of a degree and with a name from database *****/
|
||||
return (DB_QueryCOUNT ("can not check if the name"
|
||||
" of a course already existed",
|
||||
"SELECT COUNT(*) FROM crs_courses"
|
||||
" WHERE DegCod=%ld AND Year=%u"
|
||||
" AND %s='%s' AND CrsCod<>%ld",
|
||||
DegCod,Year,FieldName,Name,CrsCod) != 0);
|
||||
"SELECT COUNT(*)"
|
||||
" FROM crs_courses"
|
||||
" WHERE DegCod=%ld"
|
||||
" AND Year=%u"
|
||||
" AND %s='%s'"
|
||||
" AND CrsCod<>%ld",
|
||||
DegCod,
|
||||
Year,
|
||||
FieldName,
|
||||
Name,
|
||||
CrsCod) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -3835,7 +3835,8 @@ unsigned long DB_GetNumRowsTable (const char *Table)
|
|||
{
|
||||
/***** Get total number of rows from database *****/
|
||||
return DB_QueryCOUNT ("can not get number of rows in table",
|
||||
"SELECT COUNT(*) FROM %s",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM %s",
|
||||
Table);
|
||||
}
|
||||
|
||||
|
|
|
@ -129,8 +129,8 @@ void Deg_SeeDegWithPendingCrss (void)
|
|||
case Rol_DEG_ADM:
|
||||
NumDegs = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get degrees with pending courses",
|
||||
"SELECT crs_courses.DegCod,"
|
||||
"COUNT(*)"
|
||||
"SELECT crs_courses.DegCod," // row[0]
|
||||
"COUNT(*)" // row[1]
|
||||
" FROM usr_admins,"
|
||||
"crs_courses,"
|
||||
"deg_degrees"
|
||||
|
@ -148,8 +148,8 @@ void Deg_SeeDegWithPendingCrss (void)
|
|||
case Rol_SYS_ADM:
|
||||
NumDegs = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get degrees with pending courses",
|
||||
"SELECT crs_courses.DegCod,"
|
||||
"COUNT(*)"
|
||||
"SELECT crs_courses.DegCod," // row[0]
|
||||
"COUNT(*)" // row[1]
|
||||
" FROM crs_courses,"
|
||||
"deg_degrees"
|
||||
" WHERE (crs_courses.Status & %u)<>0"
|
||||
|
@ -277,9 +277,10 @@ void Deg_WriteSelectorOfDegree (void)
|
|||
if (Gbl.Hierarchy.Ctr.CtrCod > 0)
|
||||
{
|
||||
/***** Get degrees belonging to the current center from database *****/
|
||||
NumDegs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get degrees"
|
||||
" of a center",
|
||||
"SELECT DegCod,ShortName"
|
||||
NumDegs = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get degrees of a center",
|
||||
"SELECT DegCod," // row[0]
|
||||
"ShortName" // row[1]
|
||||
" FROM deg_degrees"
|
||||
" WHERE CtrCod=%ld"
|
||||
" ORDER BY ShortName",
|
||||
|
@ -1375,7 +1376,8 @@ bool Deg_GetDataOfDegreeByCod (struct Deg_Degree *Deg)
|
|||
"ShortName," // row[5]
|
||||
"FullName," // row[6]
|
||||
"WWW" // row[7]
|
||||
" FROM deg_degrees WHERE DegCod=%ld",
|
||||
" FROM deg_degrees"
|
||||
" WHERE DegCod=%ld",
|
||||
Deg->DegCod)) // Degree found...
|
||||
{
|
||||
/***** Get data of degree *****/
|
||||
|
@ -1436,7 +1438,9 @@ void Deg_GetShortNameOfDegreeByCod (struct Deg_Degree *Deg)
|
|||
{
|
||||
/***** Get the short name of a degree from database *****/
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get the short name of a degree",
|
||||
"SELECT ShortName FROM deg_degrees WHERE DegCod=%ld",
|
||||
"SELECT ShortName"
|
||||
" FROM deg_degrees"
|
||||
" WHERE DegCod=%ld",
|
||||
Deg->DegCod) == 1)
|
||||
{
|
||||
/***** Get the short name of this degree *****/
|
||||
|
@ -1463,7 +1467,9 @@ long Deg_GetCtrCodOfDegreeByCod (long DegCod)
|
|||
{
|
||||
/***** Get the center code of a degree from database *****/
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get the center of a degree",
|
||||
"SELECT CtrCod FROM deg_degrees WHERE DegCod=%ld",
|
||||
"SELECT CtrCod"
|
||||
" FROM deg_degrees"
|
||||
" WHERE DegCod=%ld",
|
||||
DegCod) == 1)
|
||||
{
|
||||
/***** Get the center code of this degree *****/
|
||||
|
@ -1690,9 +1696,14 @@ bool Deg_CheckIfDegNameExistsInCtr (const char *FieldName,const char *Name,
|
|||
/***** Get number of degrees with a type and a name from database *****/
|
||||
return (DB_QueryCOUNT ("can not check if the name of a degree"
|
||||
" already existed",
|
||||
"SELECT COUNT(*) FROM deg_degrees"
|
||||
" WHERE CtrCod=%ld AND %s='%s' AND DegCod<>%ld",
|
||||
CtrCod,FieldName,Name,DegCod) != 0);
|
||||
"SELECT COUNT(*)"
|
||||
" FROM deg_degrees"
|
||||
" WHERE CtrCod=%ld"
|
||||
" AND %s='%s'"
|
||||
" AND DegCod<>%ld",
|
||||
CtrCod,
|
||||
FieldName,Name,
|
||||
DegCod) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -2052,7 +2063,8 @@ unsigned Deg_GetNumDegsInCtr (long CtrCod)
|
|||
Gbl.Cache.NumDegsInCtr.CtrCod = CtrCod;
|
||||
Gbl.Cache.NumDegsInCtr.NumDegs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get the number of degrees in a center",
|
||||
"SELECT COUNT(*) FROM deg_degrees"
|
||||
"SELECT COUNT(*)"
|
||||
" FROM deg_degrees"
|
||||
" WHERE CtrCod=%ld",
|
||||
CtrCod);
|
||||
FigCch_UpdateFigureIntoCache (FigCch_NUM_DEGS,Hie_Lvl_CTR,Gbl.Cache.NumDegsInCtr.CtrCod,
|
||||
|
|
|
@ -606,7 +606,8 @@ void DT_GetListDegreeTypes (Hie_Lvl_Level_t Scope,DT_Order_t Order)
|
|||
"(SELECT deg_types.DegTypCod," // row[0]
|
||||
"deg_types.DegTypName," // row[1]
|
||||
"COUNT(deg_degrees.DegCod) AS NumDegs" // row[2]
|
||||
" FROM deg_degrees,deg_types"
|
||||
" FROM deg_degrees,"
|
||||
"deg_types"
|
||||
" WHERE deg_degrees.DegTypCod=deg_types.DegTypCod"
|
||||
" GROUP BY deg_degrees.DegTypCod)"
|
||||
" UNION "
|
||||
|
@ -618,7 +619,8 @@ void DT_GetListDegreeTypes (Hie_Lvl_Level_t Scope,DT_Order_t Order)
|
|||
// and order will be wrong
|
||||
" FROM deg_types"
|
||||
" WHERE DegTypCod NOT IN"
|
||||
" (SELECT DegTypCod FROM deg_degrees))"
|
||||
" (SELECT DegTypCod"
|
||||
" FROM deg_degrees))"
|
||||
" ORDER BY %s",
|
||||
OrderBySubQuery[Order]);
|
||||
break;
|
||||
|
@ -667,7 +669,8 @@ void DT_GetListDegreeTypes (Hie_Lvl_Level_t Scope,DT_Order_t Order)
|
|||
"SELECT deg_types.DegTypCod," // row[0]
|
||||
"deg_types.DegTypName," // row[1]
|
||||
"COUNT(deg_degrees.DegCod) AS NumDegs" // row[2]
|
||||
" FROM deg_degrees,deg_types"
|
||||
" FROM deg_degrees,"
|
||||
"deg_types"
|
||||
" WHERE deg_degrees.CtrCod=%ld"
|
||||
" AND deg_degrees.DegTypCod=deg_types.DegTypCod"
|
||||
" GROUP BY deg_degrees.DegTypCod"
|
||||
|
@ -683,7 +686,8 @@ void DT_GetListDegreeTypes (Hie_Lvl_Level_t Scope,DT_Order_t Order)
|
|||
"SELECT deg_types.DegTypCod," // row[0]
|
||||
"deg_types.DegTypName," // row[1]
|
||||
"COUNT(deg_degrees.DegCod) AS NumDegs" // row[2]
|
||||
" FROM deg_degrees,deg_types"
|
||||
" FROM deg_degrees,"
|
||||
"deg_types"
|
||||
" WHERE deg_degrees.DegCod=%ld"
|
||||
" AND deg_degrees.DegTypCod=deg_types.DegTypCod"
|
||||
" GROUP BY deg_degrees.DegTypCod"
|
||||
|
@ -851,7 +855,8 @@ static unsigned DT_CountNumDegsOfType (long DegTypCod)
|
|||
/***** Get number of degrees of a type from database *****/
|
||||
return
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of degrees of a type",
|
||||
"SELECT COUNT(*) FROM deg_degrees"
|
||||
"SELECT COUNT(*)"
|
||||
" FROM deg_degrees"
|
||||
" WHERE DegTypCod=%ld",
|
||||
DegTypCod);
|
||||
}
|
||||
|
@ -877,7 +882,9 @@ bool DT_GetDataOfDegreeTypeByCod (struct DegreeType *DegTyp)
|
|||
|
||||
/***** Get the name of a type of degree from database *****/
|
||||
NumRows = DB_QuerySELECT (&mysql_res,"can not get the name of a type of degree",
|
||||
"SELECT DegTypName FROM deg_types WHERE DegTypCod=%ld",
|
||||
"SELECT DegTypName"
|
||||
" FROM deg_types"
|
||||
" WHERE DegTypCod=%ld",
|
||||
DegTyp->DegTypCod);
|
||||
if (NumRows == 1)
|
||||
{
|
||||
|
@ -923,7 +930,8 @@ static void DT_RemoveDegreeTypeCompletely (long DegTypCod)
|
|||
|
||||
/***** Get degrees of a type from database *****/
|
||||
NumRows = DB_QuerySELECT (&mysql_res,"can not get degrees of a type",
|
||||
"SELECT DegCod FROM deg_degrees"
|
||||
"SELECT DegCod"
|
||||
" FROM deg_degrees"
|
||||
" WHERE DegTypCod=%ld",
|
||||
DegTypCod);
|
||||
|
||||
|
@ -1027,8 +1035,10 @@ static bool DT_CheckIfDegreeTypeNameExists (const char *DegTypName,long DegTypCo
|
|||
/***** Get number of degree types with a name from database *****/
|
||||
return (DB_QueryCOUNT ("can not check if the name of a type of degree"
|
||||
" already existed",
|
||||
"SELECT COUNT(*) FROM deg_types"
|
||||
" WHERE DegTypName='%s' AND DegTypCod<>%ld",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM deg_types"
|
||||
" WHERE DegTypName='%s'"
|
||||
" AND DegTypCod<>%ld",
|
||||
DegTypName,DegTypCod) != 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -517,7 +517,8 @@ unsigned Dpt_GetNumDepartmentsInInstitution (long InsCod)
|
|||
/***** Get number of departments in an institution from database *****/
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of departments in an institution",
|
||||
"SELECT COUNT(*) FROM dpt_departments"
|
||||
"SELECT COUNT(*)"
|
||||
" FROM dpt_departments"
|
||||
" WHERE InsCod=%ld",
|
||||
InsCod);
|
||||
}
|
||||
|
@ -833,7 +834,8 @@ static bool Dpt_CheckIfDepartmentNameExists (const char *FieldName,const char *N
|
|||
{
|
||||
/***** Get number of departments with a name from database *****/
|
||||
return (DB_QueryCOUNT ("can not check if the department name already existed",
|
||||
"SELECT COUNT(*) FROM dpt_departments"
|
||||
"SELECT COUNT(*)"
|
||||
" FROM dpt_departments"
|
||||
" WHERE %s='%s'"
|
||||
" AND DptCod<>%ld",
|
||||
FieldName,Name,
|
||||
|
@ -1131,7 +1133,8 @@ unsigned Dpt_GetNumDptsInIns (long InsCod)
|
|||
Gbl.Cache.NumDptsInIns.InsCod = InsCod;
|
||||
Gbl.Cache.NumDptsInIns.NumDpts = (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of departments in an institution",
|
||||
"SELECT COUNT(*) FROM departments"
|
||||
"SELECT COUNT(*)"
|
||||
" FROM departments"
|
||||
" WHERE InsCod=%ld",
|
||||
InsCod);
|
||||
return Gbl.Cache.NumDptsInIns.NumDpts;
|
||||
|
|
|
@ -144,12 +144,15 @@ void Dup_ListDuplicateUsrs (void)
|
|||
Hlp_USERS_Duplicates_possibly_duplicate_users,Box_NOT_CLOSABLE);
|
||||
|
||||
/***** Make query *****/
|
||||
NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get possibly"
|
||||
" duplicate users",
|
||||
"SELECT UsrCod,COUNT(*) AS N,UNIX_TIMESTAMP(MIN(InformTime)) AS T"
|
||||
NumUsrs = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get possibly duplicate users",
|
||||
"SELECT UsrCod,"
|
||||
"COUNT(*) AS N,"
|
||||
"UNIX_TIMESTAMP(MIN(InformTime)) AS T"
|
||||
" FROM usr_duplicated"
|
||||
" GROUP BY UsrCod"
|
||||
" ORDER BY N DESC,T DESC");
|
||||
" ORDER BY N DESC,"
|
||||
"T DESC");
|
||||
|
||||
/***** List possible duplicated users *****/
|
||||
if (NumUsrs)
|
||||
|
@ -293,8 +296,12 @@ static void Dup_ListSimilarUsrs (void)
|
|||
Gbl.Usrs.Other.UsrDat.FrstName);
|
||||
else
|
||||
NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get similar users",
|
||||
"SELECT DISTINCT UsrCod FROM usr_ids"
|
||||
" WHERE UsrID IN (SELECT UsrID FROM usr_ids WHERE UsrCod=%ld)",
|
||||
"SELECT DISTINCT UsrCod"
|
||||
" FROM usr_ids"
|
||||
" WHERE UsrID IN"
|
||||
" (SELECT UsrID"
|
||||
" FROM usr_ids"
|
||||
" WHERE UsrCod=%ld)",
|
||||
Gbl.Usrs.Other.UsrDat.UsrCod);
|
||||
|
||||
/***** List possible similar users *****/
|
||||
|
@ -401,7 +408,8 @@ static bool Dup_CheckIfUsrIsDup (long UsrCod)
|
|||
{
|
||||
return (DB_QueryCOUNT ("can not if user is in list"
|
||||
" of possible duplicate users",
|
||||
"SELECT COUNT(*) FROM usr_duplicated"
|
||||
"SELECT COUNT(*)"
|
||||
" FROM usr_duplicated"
|
||||
" WHERE UsrCod=%ld",
|
||||
UsrCod) != 0);
|
||||
}
|
||||
|
|
64
swad_exam.c
64
swad_exam.c
|
@ -1073,7 +1073,9 @@ void Exa_GetExamTxtFromDB (long ExaCod,char Txt[Cns_MAX_BYTES_TEXT + 1])
|
|||
|
||||
/***** Get text of exam from database *****/
|
||||
NumRows = DB_QuerySELECT (&mysql_res,"can not get exam text",
|
||||
"SELECT Txt FROM exa_exams WHERE ExaCod=%ld",
|
||||
"SELECT Txt" // row[0]
|
||||
" FROM exa_exams"
|
||||
" WHERE ExaCod=%ld",
|
||||
ExaCod);
|
||||
|
||||
/***** The result of the query must have one row or none *****/
|
||||
|
@ -1388,10 +1390,13 @@ static bool Exa_CheckIfSimilarExamExists (const struct Exa_Exam *Exam)
|
|||
{
|
||||
/***** Get number of exams with a field value from database *****/
|
||||
return (DB_QueryCOUNT ("can not get similar exams",
|
||||
"SELECT COUNT(*) FROM exa_exams"
|
||||
" WHERE CrsCod=%ld AND Title='%s'"
|
||||
"SELECT COUNT(*)"
|
||||
" FROM exa_exams"
|
||||
" WHERE CrsCod=%ld"
|
||||
" AND Title='%s'"
|
||||
" AND ExaCod<>%ld",
|
||||
Gbl.Hierarchy.Crs.CrsCod,Exam->Title,
|
||||
Gbl.Hierarchy.Crs.CrsCod,
|
||||
Exam->Title,
|
||||
Exam->ExaCod) != 0);
|
||||
}
|
||||
|
||||
|
@ -1770,8 +1775,10 @@ long Exa_GetQstCodFromQstInd (long ExaCod,unsigned QstInd)
|
|||
|
||||
/***** Get question code of the question to be moved up *****/
|
||||
if (!DB_QuerySELECT (&mysql_res,"can not get question code",
|
||||
"SELECT QstCod FROM exa_set_questions"
|
||||
" WHERE ExaCod=%ld AND QstInd=%u",
|
||||
"SELECT QstCod"
|
||||
" FROM exa_set_questions"
|
||||
" WHERE ExaCod=%ld"
|
||||
" AND QstInd=%u",
|
||||
ExaCod,QstInd))
|
||||
Lay_ShowErrorAndExit ("Error: wrong question index.");
|
||||
|
||||
|
@ -1802,9 +1809,12 @@ unsigned Exa_GetPrevQuestionIndexInExam (long ExaCod,unsigned QstInd)
|
|||
// Although indexes are always continuous...
|
||||
// ...this implementation works even with non continuous indexes
|
||||
if (!DB_QuerySELECT (&mysql_res,"can not get previous question index",
|
||||
"SELECT MAX(QstInd) FROM exa_set_questions"
|
||||
" WHERE ExaCod=%ld AND QstInd<%u",
|
||||
ExaCod,QstInd))
|
||||
"SELECT MAX(QstInd)"
|
||||
" FROM exa_set_questions"
|
||||
" WHERE ExaCod=%ld"
|
||||
" AND QstInd<%u",
|
||||
ExaCod,
|
||||
QstInd))
|
||||
Lay_ShowErrorAndExit ("Error: previous question index not found.");
|
||||
|
||||
/***** Get previous question index (row[0]) *****/
|
||||
|
@ -1836,8 +1846,10 @@ unsigned Exa_GetNextQuestionIndexInExam (long ExaCod,unsigned QstInd)
|
|||
// Although indexes are always continuous...
|
||||
// ...this implementation works even with non continuous indexes
|
||||
if (!DB_QuerySELECT (&mysql_res,"can not get next question index",
|
||||
"SELECT MIN(QstInd) FROM exa_set_questions"
|
||||
" WHERE ExaCod=%ld AND QstInd>%u",
|
||||
"SELECT MIN(QstInd)"
|
||||
" FROM exa_set_questions"
|
||||
" WHERE ExaCod=%ld"
|
||||
" AND QstInd>%u",
|
||||
ExaCod,QstInd))
|
||||
Lay_ShowErrorAndExit ("Error: next question index not found.");
|
||||
|
||||
|
@ -2075,16 +2087,17 @@ double Exa_GetNumQstsPerCrsExam (Hie_Lvl_Level_t Scope)
|
|||
{
|
||||
case Hie_Lvl_SYS:
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of questions per exam",
|
||||
"SELECT AVG(NumQsts) FROM"
|
||||
" (SELECT COUNT(exa_set_questions.QstCod) AS NumQsts"
|
||||
" FROM exa_exams,exa_set_questions"
|
||||
"SELECT AVG(NumQsts)"
|
||||
" FROM (SELECT COUNT(exa_set_questions.QstCod) AS NumQsts"
|
||||
" FROM exa_exams,"
|
||||
"exa_set_questions"
|
||||
" WHERE exa_exams.ExaCod=exa_set_questions.ExaCod"
|
||||
" GROUP BY exa_set_questions.ExaCod) AS NumQstsTable");
|
||||
break;
|
||||
case Hie_Lvl_CTY:
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of questions per exam",
|
||||
"SELECT AVG(NumQsts) FROM"
|
||||
" (SELECT COUNT(exa_set_questions.QstCod) AS NumQsts"
|
||||
"SELECT AVG(NumQsts)"
|
||||
" FROM (SELECT COUNT(exa_set_questions.QstCod) AS NumQsts"
|
||||
" FROM ins_instits,"
|
||||
"ctr_centers,"
|
||||
"deg_degrees,"
|
||||
|
@ -2102,8 +2115,8 @@ double Exa_GetNumQstsPerCrsExam (Hie_Lvl_Level_t Scope)
|
|||
break;
|
||||
case Hie_Lvl_INS:
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of questions per exam",
|
||||
"SELECT AVG(NumQsts) FROM"
|
||||
" (SELECT COUNT(exa_set_questions.QstCod) AS NumQsts"
|
||||
"SELECT AVG(NumQsts)"
|
||||
" FROM (SELECT COUNT(exa_set_questions.QstCod) AS NumQsts"
|
||||
" FROM ctr_centers,"
|
||||
"deg_degrees,"
|
||||
"crs_courses,"
|
||||
|
@ -2119,8 +2132,8 @@ double Exa_GetNumQstsPerCrsExam (Hie_Lvl_Level_t Scope)
|
|||
break;
|
||||
case Hie_Lvl_CTR:
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of questions per exam",
|
||||
"SELECT AVG(NumQsts) FROM"
|
||||
" (SELECT COUNT(exa_set_questions.QstCod) AS NumQsts"
|
||||
"SELECT AVG(NumQsts)"
|
||||
" FROM (SELECT COUNT(exa_set_questions.QstCod) AS NumQsts"
|
||||
" FROM deg_degrees,"
|
||||
"crs_courses,"
|
||||
"exa_exams,"
|
||||
|
@ -2134,8 +2147,8 @@ double Exa_GetNumQstsPerCrsExam (Hie_Lvl_Level_t Scope)
|
|||
break;
|
||||
case Hie_Lvl_DEG:
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of questions per exam",
|
||||
"SELECT AVG(NumQsts) FROM"
|
||||
" (SELECT COUNT(exa_set_questions.QstCod) AS NumQsts"
|
||||
"SELECT AVG(NumQsts)"
|
||||
" FROM (SELECT COUNT(exa_set_questions.QstCod) AS NumQsts"
|
||||
" FROM crs_courses,"
|
||||
"exa_exams,"
|
||||
"exa_set_questions"
|
||||
|
@ -2147,8 +2160,8 @@ double Exa_GetNumQstsPerCrsExam (Hie_Lvl_Level_t Scope)
|
|||
break;
|
||||
case Hie_Lvl_CRS:
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of questions per exam",
|
||||
"SELECT AVG(NumQsts) FROM"
|
||||
" (SELECT COUNT(exa_set_questions.QstCod) AS NumQsts"
|
||||
"SELECT AVG(NumQsts)"
|
||||
" FROM (SELECT COUNT(exa_set_questions.QstCod) AS NumQsts"
|
||||
" FROM exa_exams,"
|
||||
"exa_set_questions"
|
||||
" WHERE exa_exams.Cod=%ld"
|
||||
|
@ -2187,7 +2200,8 @@ void Exa_GetScoreRange (long ExaCod,double *MinScore,double *MaxScore)
|
|||
NumRows = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get data of a question",
|
||||
"SELECT COUNT(tst_answers.AnsInd) AS N"
|
||||
" FROM tst_answers,exa_set_questions"
|
||||
" FROM tst_answers,"
|
||||
"exa_set_questions"
|
||||
" WHERE exa_set_questions.ExaCod=%ld"
|
||||
" AND exa_set_questions.QstCod=tst_answers.QstCod"
|
||||
" GROUP BY tst_answers.QstCod",
|
||||
|
|
|
@ -1438,7 +1438,8 @@ static void ExaPrn_GetAnswerFromDB (struct ExaPrn_Print *Print,long QstCod,
|
|||
if (DB_QuerySELECT (&mysql_res,"can not get answer in an exam print",
|
||||
"SELECT Answers"
|
||||
" FROM exa_print_questions"
|
||||
" WHERE PrnCod=%ld AND QstCod=%ld",
|
||||
" WHERE PrnCod=%ld"
|
||||
" AND QstCod=%ld",
|
||||
Print->PrnCod,QstCod))
|
||||
{
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
|
@ -1487,7 +1488,8 @@ static void ExaPrn_GetNumQstsNotBlank (struct ExaPrn_Print *Print)
|
|||
DB_QueryCOUNT ("can not get number of questions not blank",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM exa_print_questions"
|
||||
" WHERE PrnCod=%ld AND Answers<>''",
|
||||
" WHERE PrnCod=%ld"
|
||||
" AND Answers<>''",
|
||||
Print->PrnCod);
|
||||
}
|
||||
|
||||
|
|
|
@ -436,14 +436,14 @@ static void ExaRes_ListAllResultsInExa (struct Exa_Exams *Exams,long ExaCod)
|
|||
|
||||
/***** Get all users who have answered any session question in this exam *****/
|
||||
NumUsrs = DB_QuerySELECT (&mysql_res,"can not get users in exam",
|
||||
"SELECT users.UsrCod FROM"
|
||||
" (SELECT DISTINCT exa_prints.UsrCod AS UsrCod" // row[0]
|
||||
"SELECT users.UsrCod" // row[0]
|
||||
" FROM (SELECT DISTINCT exa_prints.UsrCod AS UsrCod"
|
||||
" FROM exa_prints,exa_sessions,exa_exams"
|
||||
" WHERE exa_sessions.ExaCod=%ld"
|
||||
" AND exa_sessions.SesCod=exa_prints.SesCod"
|
||||
" AND exa_sessions.ExaCod=exa_exams.ExaCod"
|
||||
" AND exa_exams.CrsCod=%ld)" // Extra check
|
||||
" AS users,usr_data"
|
||||
" AND exa_exams.CrsCod=%ld) AS users," // Extra check
|
||||
"usr_data"
|
||||
" WHERE users.UsrCod=usr_data.UsrCod"
|
||||
" ORDER BY usr_data.Surname1,"
|
||||
"usr_data.Surname2,"
|
||||
|
@ -532,14 +532,14 @@ static void ExaRes_ListAllResultsInSes (struct Exa_Exams *Exams,long SesCod)
|
|||
|
||||
/***** Get all users who have answered any session question in this exam *****/
|
||||
NumUsrs = DB_QuerySELECT (&mysql_res,"can not get users in session",
|
||||
"SELECT users.UsrCod FROM"
|
||||
" (SELECT exa_prints.UsrCod AS UsrCod" // row[0]
|
||||
"SELECT users.UsrCod"
|
||||
" FROM (SELECT exa_prints.UsrCod AS UsrCod" // row[0]
|
||||
" FROM exa_prints,exa_sessions,exa_exams"
|
||||
" WHERE exa_prints.SesCod=%ld"
|
||||
" AND exa_prints.SesCod=exa_sessions.SesCod"
|
||||
" AND exa_sessions.ExaCod=exa_exams.ExaCod"
|
||||
" AND exa_exams.CrsCod=%ld)" // Extra check
|
||||
" AS users,usr_data"
|
||||
" AND exa_exams.CrsCod=%ld) AS users," // Extra check
|
||||
"usr_data"
|
||||
" WHERE users.UsrCod=usr_data.UsrCod"
|
||||
" ORDER BY usr_data.Surname1,"
|
||||
"usr_data.Surname2,"
|
||||
|
|
|
@ -316,7 +316,8 @@ void ExaSes_GetDataOfSessionByCod (struct ExaSes_Session *Session)
|
|||
" FROM exa_sessions"
|
||||
" WHERE SesCod=%ld"
|
||||
" AND ExaCod IN" // Extra check
|
||||
" (SELECT ExaCod FROM exa_exams"
|
||||
" (SELECT ExaCod"
|
||||
" FROM exa_exams"
|
||||
" WHERE CrsCod='%ld')",
|
||||
Session->SesCod,
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
|
@ -1685,7 +1686,8 @@ unsigned ExaSes_GetNumSessionsInExam (long ExaCod)
|
|||
/***** Get number of sessions in an exam from database *****/
|
||||
return
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of sessions of an exam",
|
||||
"SELECT COUNT(*) FROM exa_sessions"
|
||||
"SELECT COUNT(*)"
|
||||
" FROM exa_sessions"
|
||||
" WHERE ExaCod=%ld",
|
||||
ExaCod);
|
||||
}
|
||||
|
@ -1703,7 +1705,8 @@ unsigned ExaSes_GetNumOpenSessionsInExam (long ExaCod)
|
|||
/***** Get number of open sessions in an exam from database *****/
|
||||
return
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of open sessions of an exam",
|
||||
"SELECT COUNT(*) FROM exa_sessions"
|
||||
"SELECT COUNT(*)"
|
||||
" FROM exa_sessions"
|
||||
" WHERE ExaCod=%ld"
|
||||
" AND NOW() BETWEEN StartTime AND EndTime",
|
||||
ExaCod);
|
||||
|
@ -1718,7 +1721,9 @@ bool ExaSes_CheckIfICanAnswerThisSession (const struct Exa_Exam *Exam,
|
|||
{
|
||||
/***** 1. Sessions in hidden exams are not accesible
|
||||
2. Hidden or closed sessions are not accesible *****/
|
||||
if (Exam->Hidden || Session->Hidden || !Session->Open)
|
||||
if (Exam->Hidden ||
|
||||
Session->Hidden ||
|
||||
!Session->Open)
|
||||
return false;
|
||||
|
||||
/***** Exam is visible, session is visible and open ==>
|
||||
|
|
|
@ -190,7 +190,8 @@ static unsigned ExaSet_GetNumQstsInSet (long SetCod)
|
|||
/***** Get number of questions in set from database *****/
|
||||
return
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of questions in a set",
|
||||
"SELECT COUNT(*) FROM exa_set_questions"
|
||||
"SELECT COUNT(*)"
|
||||
" FROM exa_set_questions"
|
||||
" WHERE SetCod=%ld",
|
||||
SetCod);
|
||||
}
|
||||
|
@ -266,8 +267,11 @@ static bool ExaSet_CheckIfSimilarSetExists (const struct ExaSet_Set *Set,
|
|||
{
|
||||
/***** Get number of set of questions with a field value from database *****/
|
||||
return (DB_QueryCOUNT ("can not get similar sets of questions",
|
||||
"SELECT COUNT(*) FROM exa_sets,exa_exams"
|
||||
" WHERE exa_sets.ExaCod=%ld AND exa_sets.Title='%s'"
|
||||
"SELECT COUNT(*)"
|
||||
" FROM exa_sets,"
|
||||
"exa_exams"
|
||||
" WHERE exa_sets.ExaCod=%ld"
|
||||
" AND exa_sets.Title='%s'"
|
||||
" AND exa_sets.SetCod<>%ld"
|
||||
" AND exa_sets.ExaCod=exa_exams.ExaCod"
|
||||
" AND exa_exams.CrsCod=%ld", // Extra check
|
||||
|
@ -624,7 +628,8 @@ unsigned ExaSet_GetNumSetsExam (long ExaCod)
|
|||
/***** Get number of sets in an exam from database *****/
|
||||
return
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of sets in an exam",
|
||||
"SELECT COUNT(*) FROM exa_sets"
|
||||
"SELECT COUNT(*)"
|
||||
" FROM exa_sets"
|
||||
" WHERE ExaCod=%ld",
|
||||
ExaCod);
|
||||
}
|
||||
|
@ -641,7 +646,8 @@ unsigned ExaSet_GetNumQstsExam (long ExaCod)
|
|||
|
||||
/***** Get total number of questions to appear in exam print *****/
|
||||
if (!DB_QuerySELECT (&mysql_res,"can not get number of questions in an exam print",
|
||||
"SELECT SUM(NumQstsToPrint) FROM exa_sets"
|
||||
"SELECT SUM(NumQstsToPrint)"
|
||||
" FROM exa_sets"
|
||||
" WHERE ExaCod=%ld",
|
||||
ExaCod))
|
||||
Lay_ShowErrorAndExit ("Error: wrong question index.");
|
||||
|
@ -784,7 +790,8 @@ static unsigned ExaSet_GetSetIndFromSetCod (long ExaCod,long SetCod)
|
|||
|
||||
/***** Get set index from set code *****/
|
||||
if (!DB_QuerySELECT (&mysql_res,"can not get set index",
|
||||
"SELECT SetInd FROM exa_sets"
|
||||
"SELECT SetInd"
|
||||
" FROM exa_sets"
|
||||
" WHERE SetCod=%u"
|
||||
" AND ExaCod=%ld", // Extra check
|
||||
SetCod,ExaCod))
|
||||
|
@ -812,8 +819,10 @@ static long ExaSet_GetSetCodFromSetInd (long ExaCod,unsigned SetInd)
|
|||
|
||||
/***** Get set code from set index *****/
|
||||
if (!DB_QuerySELECT (&mysql_res,"can not get set code",
|
||||
"SELECT SetCod FROM exa_sets"
|
||||
" WHERE ExaCod=%ld AND SetInd=%u",
|
||||
"SELECT SetCod"
|
||||
" FROM exa_sets"
|
||||
" WHERE ExaCod=%ld"
|
||||
" AND SetInd=%u",
|
||||
ExaCod,SetInd))
|
||||
Lay_ShowErrorAndExit ("Error: wrong set index.");
|
||||
|
||||
|
@ -873,8 +882,10 @@ static unsigned ExaSet_GetPrevSetIndexInExam (long ExaCod,unsigned SetInd)
|
|||
// Although indexes are always continuous...
|
||||
// ...this implementation works even with non continuous indexes
|
||||
if (!DB_QuerySELECT (&mysql_res,"can not get previous set index",
|
||||
"SELECT MAX(SetInd) FROM exa_sets"
|
||||
" WHERE ExaCod=%ld AND SetInd<%u",
|
||||
"SELECT MAX(SetInd)"
|
||||
" FROM exa_sets"
|
||||
" WHERE ExaCod=%ld"
|
||||
" AND SetInd<%u",
|
||||
ExaCod,SetInd))
|
||||
Lay_ShowErrorAndExit ("Error: previous set index not found.");
|
||||
|
||||
|
@ -907,8 +918,10 @@ static unsigned ExaSet_GetNextSetIndexInExam (long ExaCod,unsigned SetInd)
|
|||
// Although indexes are always continuous...
|
||||
// ...this implementation works even with non continuous indexes
|
||||
if (!DB_QuerySELECT (&mysql_res,"can not get next set index",
|
||||
"SELECT MIN(SetInd) FROM exa_sets"
|
||||
" WHERE ExaCod=%ld AND SetInd>%u",
|
||||
"SELECT MIN(SetInd)"
|
||||
" FROM exa_sets"
|
||||
" WHERE ExaCod=%ld"
|
||||
" AND SetInd>%u",
|
||||
ExaCod,SetInd))
|
||||
Lay_ShowErrorAndExit ("Error: next set index not found.");
|
||||
|
||||
|
|
|
@ -4065,8 +4065,8 @@ static void Fig_GetAndShowFollowStats (void)
|
|||
case Hie_Lvl_SYS:
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of questions"
|
||||
" per survey",
|
||||
"SELECT AVG(N) FROM " // row[0]
|
||||
"(SELECT COUNT(%s) AS N"
|
||||
"SELECT AVG(N)" // row[0]
|
||||
" FROM (SELECT COUNT(%s) AS N"
|
||||
" FROM usr_follow"
|
||||
" GROUP BY %s) AS F",
|
||||
FieldDB[Fol],
|
||||
|
@ -4075,8 +4075,8 @@ static void Fig_GetAndShowFollowStats (void)
|
|||
case Hie_Lvl_CTY:
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of questions"
|
||||
" per survey",
|
||||
"SELECT AVG(N) FROM " // row[0]
|
||||
"(SELECT COUNT(DISTINCT usr_follow.%s) AS N"
|
||||
"SELECT AVG(N)" // row[0]
|
||||
" FROM (SELECT COUNT(DISTINCT usr_follow.%s) AS N"
|
||||
" FROM ins_instits,"
|
||||
"ctr_centers,"
|
||||
"deg_degrees,"
|
||||
|
@ -4098,8 +4098,8 @@ static void Fig_GetAndShowFollowStats (void)
|
|||
case Hie_Lvl_INS:
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of questions"
|
||||
" per survey",
|
||||
"SELECT AVG(N) FROM " // row[0]
|
||||
"(SELECT COUNT(DISTINCT usr_follow.%s) AS N"
|
||||
"SELECT AVG(N)" // row[0]
|
||||
" FROM (SELECT COUNT(DISTINCT usr_follow.%s) AS N"
|
||||
" FROM ctr_centers,"
|
||||
"deg_degrees,"
|
||||
"crs_courses,"
|
||||
|
@ -4119,8 +4119,8 @@ static void Fig_GetAndShowFollowStats (void)
|
|||
case Hie_Lvl_CTR:
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of questions"
|
||||
" per survey",
|
||||
"SELECT AVG(N) FROM " // row[0]
|
||||
"(SELECT COUNT(DISTINCT usr_follow.%s) AS N"
|
||||
"SELECT AVG(N)" // row[0]
|
||||
" FROM (SELECT COUNT(DISTINCT usr_follow.%s) AS N"
|
||||
" FROM deg_degrees,"
|
||||
"crs_courses,"
|
||||
"crs_users,"
|
||||
|
@ -4138,8 +4138,8 @@ static void Fig_GetAndShowFollowStats (void)
|
|||
case Hie_Lvl_DEG:
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of questions"
|
||||
" per survey",
|
||||
"SELECT AVG(N) FROM " // row[0]
|
||||
"(SELECT COUNT(DISTINCT usr_follow.%s) AS N"
|
||||
"SELECT AVG(N)" // row[0]
|
||||
" FROM (SELECT COUNT(DISTINCT usr_follow.%s) AS N"
|
||||
" FROM crs_courses,"
|
||||
"crs_users,"
|
||||
"usr_follow"
|
||||
|
@ -4155,8 +4155,8 @@ static void Fig_GetAndShowFollowStats (void)
|
|||
case Hie_Lvl_CRS:
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of questions"
|
||||
" per survey",
|
||||
"SELECT AVG(N) FROM " // row[0]
|
||||
"(SELECT COUNT(DISTINCT usr_follow.%s) AS N"
|
||||
"SELECT AVG(N)" // row[0]
|
||||
" FROM (SELECT COUNT(DISTINCT usr_follow.%s) AS N"
|
||||
" FROM crs_users,"
|
||||
"usr_follow"
|
||||
" WHERE crs_users.CrsCod=%ld"
|
||||
|
|
|
@ -9420,12 +9420,15 @@ bool Brw_CheckIfFileOrFolderIsHidden (struct FileMetadata *FileMetadata)
|
|||
2) the argument Path begins by 'x/', where x is a path stored in database
|
||||
*/
|
||||
return (DB_QueryCOUNT ("can not check if a file or folder is hidden",
|
||||
"SELECT COUNT(*) FROM brw_files"
|
||||
"SELECT COUNT(*)"
|
||||
" FROM brw_files"
|
||||
" WHERE FileBrowser=%u"
|
||||
" AND Cod=%ld"
|
||||
" AND ZoneUsrCod=%ld"
|
||||
" AND Hidden='Y'"
|
||||
" AND (Path='%s' OR LOCATE(CONCAT(Path,'/'),'%s')=1)",
|
||||
" AND (Path='%s'"
|
||||
" OR"
|
||||
" LOCATE(CONCAT(Path,'/'),'%s')=1)",
|
||||
FileMetadata->FileBrowser,
|
||||
FileMetadata->Cod,
|
||||
FileMetadata->ZoneUsrCod,
|
||||
|
@ -10382,7 +10385,8 @@ long Brw_GetFilCodByPath (const char *Path,bool OnlyIfPublic)
|
|||
" WHERE FileBrowser=%u"
|
||||
" AND Cod=%ld"
|
||||
" AND ZoneUsrCod=%ld"
|
||||
" AND Path='%s'%s",
|
||||
" AND Path='%s'"
|
||||
"%s",
|
||||
(unsigned) Brw_FileBrowserForDB_files[Gbl.FileBrowser.Type],
|
||||
Cod,ZoneUsrCod,
|
||||
Path,
|
||||
|
@ -11758,7 +11762,9 @@ static long Brw_GetPublisherOfSubtree (void)
|
|||
" FROM brw_files"
|
||||
" WHERE FileBrowser=%u"
|
||||
" AND Cod=%ld"
|
||||
" AND (Path='%s' OR Path LIKE '%s/%%')",
|
||||
" AND (Path='%s'"
|
||||
" OR"
|
||||
" Path LIKE '%s/%%')",
|
||||
(unsigned) Brw_FileBrowserForDB_files[Gbl.FileBrowser.Type],
|
||||
Cod,
|
||||
Gbl.FileBrowser.FilFolLnk.Full,
|
||||
|
|
|
@ -461,8 +461,10 @@ bool Fol_CheckUsrIsFollowerOf (long FollowerCod,long FollowedCod)
|
|||
|
||||
/***** Check if a user is a follower of another user *****/
|
||||
return (DB_QueryCOUNT ("can not get if a user is a follower of another one",
|
||||
"SELECT COUNT(*) FROM usr_follow"
|
||||
" WHERE FollowerCod=%ld AND FollowedCod=%ld",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM usr_follow"
|
||||
" WHERE FollowerCod=%ld"
|
||||
" AND FollowedCod=%ld",
|
||||
FollowerCod,FollowedCod) != 0);
|
||||
}
|
||||
|
||||
|
@ -499,12 +501,14 @@ void Fol_GetNumFollow (long UsrCod,
|
|||
Gbl.Cache.Follow.UsrCod = UsrCod;
|
||||
*NumFollowing = Gbl.Cache.Follow.NumFollowing =
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of followed",
|
||||
"SELECT COUNT(*) FROM usr_follow"
|
||||
"SELECT COUNT(*)"
|
||||
" FROM usr_follow"
|
||||
" WHERE FollowerCod=%ld",
|
||||
UsrCod);
|
||||
*NumFollowers = Gbl.Cache.Follow.NumFollowers =
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of followers",
|
||||
"SELECT COUNT(*) FROM usr_follow"
|
||||
"SELECT COUNT(*)"
|
||||
" FROM usr_follow"
|
||||
" WHERE FollowedCod=%ld",
|
||||
UsrCod);
|
||||
}
|
||||
|
@ -681,7 +685,8 @@ static void Fol_ListFollowingUsr (struct UsrData *UsrDat)
|
|||
{
|
||||
/***** Check if a user is a follower of another user *****/
|
||||
NumUsrs = DB_QuerySELECT (&mysql_res,"can not get followed users",
|
||||
"SELECT FollowedCod FROM usr_follow"
|
||||
"SELECT FollowedCod"
|
||||
" FROM usr_follow"
|
||||
" WHERE FollowerCod=%ld"
|
||||
" ORDER BY FollowTime DESC",
|
||||
UsrDat->UsrCod);
|
||||
|
@ -765,7 +770,8 @@ static void Fol_ListFollowersUsr (struct UsrData *UsrDat)
|
|||
{
|
||||
/***** Check if a user is a follower of another user *****/
|
||||
NumUsrs = DB_QuerySELECT (&mysql_res,"can not get followers",
|
||||
"SELECT FollowerCod FROM usr_follow"
|
||||
"SELECT FollowerCod"
|
||||
" FROM usr_follow"
|
||||
" WHERE FollowedCod=%ld"
|
||||
" ORDER BY FollowTime DESC",
|
||||
UsrDat->UsrCod);
|
||||
|
@ -1372,8 +1378,8 @@ void Fol_GetAndShowRankingFollowers (void)
|
|||
case Hie_Lvl_SYS:
|
||||
NumUsrs = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get ranking",
|
||||
"SELECT FollowedCod,"
|
||||
"COUNT(FollowerCod) AS N"
|
||||
"SELECT FollowedCod," // row[0]
|
||||
"COUNT(FollowerCod) AS N" // row[1]
|
||||
" FROM usr_follow"
|
||||
" GROUP BY FollowedCod"
|
||||
" ORDER BY N DESC,"
|
||||
|
|
90
swad_game.c
90
swad_game.c
|
@ -1138,7 +1138,9 @@ static void Gam_GetGameTxtFromDB (long GamCod,char Txt[Cns_MAX_BYTES_TEXT + 1])
|
|||
|
||||
/***** Get text of game from database *****/
|
||||
NumRows = DB_QuerySELECT (&mysql_res,"can not get game text",
|
||||
"SELECT Txt FROM gam_games WHERE GamCod=%ld",
|
||||
"SELECT Txt"
|
||||
" FROM gam_games"
|
||||
" WHERE GamCod=%ld",
|
||||
GamCod);
|
||||
|
||||
/***** The result of the query must have one row or none *****/
|
||||
|
@ -1350,10 +1352,13 @@ static bool Gam_CheckIfSimilarGameExists (const struct Gam_Game *Game)
|
|||
{
|
||||
/***** Get number of games with a field value from database *****/
|
||||
return (DB_QueryCOUNT ("can not get similar games",
|
||||
"SELECT COUNT(*) FROM gam_games"
|
||||
" WHERE CrsCod=%ld AND Title='%s'"
|
||||
"SELECT COUNT(*)"
|
||||
" FROM gam_games"
|
||||
" WHERE CrsCod=%ld"
|
||||
" AND Title='%s'"
|
||||
" AND GamCod<>%ld",
|
||||
Gbl.Hierarchy.Crs.CrsCod,Game->Title,
|
||||
Gbl.Hierarchy.Crs.CrsCod,
|
||||
Game->Title,
|
||||
Game->GamCod) != 0);
|
||||
}
|
||||
|
||||
|
@ -1724,9 +1729,10 @@ static void Gam_UpdateGame (struct Gam_Game *Game,const char *Txt)
|
|||
unsigned Gam_GetNumQstsGame (long GamCod)
|
||||
{
|
||||
/***** Get nuumber of questions in a game from database *****/
|
||||
return
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of questions of a game",
|
||||
"SELECT COUNT(*) FROM gam_questions"
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of questions of a game",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM gam_questions"
|
||||
" WHERE GamCod=%ld",
|
||||
GamCod);
|
||||
}
|
||||
|
@ -1846,9 +1852,12 @@ static unsigned Gam_GetQstIndFromQstCod (long GamCod,long QstCod)
|
|||
|
||||
/***** Get question index in a game given the question code *****/
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get question index",
|
||||
"SELECT QstInd FROM gam_questions"
|
||||
" WHERE GamCod=%ld AND QstCod=%ld",
|
||||
GamCod,QstCod))
|
||||
"SELECT QstInd" // row[0]
|
||||
" FROM gam_questions"
|
||||
" WHERE GamCod=%ld"
|
||||
" AND QstCod=%ld",
|
||||
GamCod,
|
||||
QstCod))
|
||||
{
|
||||
/***** Get question code (row[0]) *****/
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
|
@ -1875,8 +1884,10 @@ long Gam_GetQstCodFromQstInd (long GamCod,unsigned QstInd)
|
|||
|
||||
/***** Get question code of the question to be moved up *****/
|
||||
if (!DB_QuerySELECT (&mysql_res,"can not get question code",
|
||||
"SELECT QstCod FROM gam_questions"
|
||||
" WHERE GamCod=%ld AND QstInd=%u",
|
||||
"SELECT QstCod"
|
||||
" FROM gam_questions"
|
||||
" WHERE GamCod=%ld"
|
||||
" AND QstInd=%u",
|
||||
GamCod,QstInd))
|
||||
Lay_ShowErrorAndExit ("Error: wrong question index.");
|
||||
|
||||
|
@ -1936,9 +1947,12 @@ unsigned Gam_GetPrevQuestionIndexInGame (long GamCod,unsigned QstInd)
|
|||
// Although indexes are always continuous...
|
||||
// ...this implementation works even with non continuous indexes
|
||||
if (!DB_QuerySELECT (&mysql_res,"can not get previous question index",
|
||||
"SELECT MAX(QstInd) FROM gam_questions"
|
||||
" WHERE GamCod=%ld AND QstInd<%u",
|
||||
GamCod,QstInd))
|
||||
"SELECT MAX(QstInd)" // row[0]
|
||||
" FROM gam_questions"
|
||||
" WHERE GamCod=%ld"
|
||||
" AND QstInd<%u",
|
||||
GamCod,
|
||||
QstInd))
|
||||
Lay_ShowErrorAndExit ("Error: previous question index not found.");
|
||||
|
||||
/***** Get previous question index (row[0]) *****/
|
||||
|
@ -1970,9 +1984,12 @@ unsigned Gam_GetNextQuestionIndexInGame (long GamCod,unsigned QstInd)
|
|||
// Although indexes are always continuous...
|
||||
// ...this implementation works even with non continuous indexes
|
||||
if (!DB_QuerySELECT (&mysql_res,"can not get next question index",
|
||||
"SELECT MIN(QstInd) FROM gam_questions"
|
||||
" WHERE GamCod=%ld AND QstInd>%u",
|
||||
GamCod,QstInd))
|
||||
"SELECT MIN(QstInd)"
|
||||
" FROM gam_questions"
|
||||
" WHERE GamCod=%ld"
|
||||
" AND QstInd>%u",
|
||||
GamCod,
|
||||
QstInd))
|
||||
Lay_ShowErrorAndExit ("Error: next question index not found.");
|
||||
|
||||
/***** Get next question index (row[0]) *****/
|
||||
|
@ -2817,8 +2834,8 @@ double Gam_GetNumQstsPerCrsGame (Hie_Lvl_Level_t Scope)
|
|||
{
|
||||
case Hie_Lvl_SYS:
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
|
||||
"SELECT AVG(NumQsts) FROM"
|
||||
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
|
||||
"SELECT AVG(NumQsts)"
|
||||
" FROM (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
|
||||
" FROM gam_games,"
|
||||
"gam_questions"
|
||||
" WHERE gam_games.GamCod=gam_questions.GamCod"
|
||||
|
@ -2826,8 +2843,8 @@ double Gam_GetNumQstsPerCrsGame (Hie_Lvl_Level_t Scope)
|
|||
break;
|
||||
case Hie_Lvl_CTY:
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
|
||||
"SELECT AVG(NumQsts) FROM"
|
||||
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
|
||||
"SELECT AVG(NumQsts)"
|
||||
" FROM (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
|
||||
" FROM ins_instits,"
|
||||
"ctr_centers,"
|
||||
"deg_degrees,"
|
||||
|
@ -2845,8 +2862,8 @@ double Gam_GetNumQstsPerCrsGame (Hie_Lvl_Level_t Scope)
|
|||
break;
|
||||
case Hie_Lvl_INS:
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
|
||||
"SELECT AVG(NumQsts) FROM"
|
||||
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
|
||||
"SELECT AVG(NumQsts)"
|
||||
" FROM (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
|
||||
" FROM ctr_centers,"
|
||||
"deg_degrees,"
|
||||
"crs_courses,"
|
||||
|
@ -2862,8 +2879,8 @@ double Gam_GetNumQstsPerCrsGame (Hie_Lvl_Level_t Scope)
|
|||
break;
|
||||
case Hie_Lvl_CTR:
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
|
||||
"SELECT AVG(NumQsts) FROM"
|
||||
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
|
||||
"SELECT AVG(NumQsts)"
|
||||
" FROM (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
|
||||
" FROM deg_degrees,"
|
||||
"crs_courses,"
|
||||
"gam_games,"
|
||||
|
@ -2877,8 +2894,8 @@ double Gam_GetNumQstsPerCrsGame (Hie_Lvl_Level_t Scope)
|
|||
break;
|
||||
case Hie_Lvl_DEG:
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
|
||||
"SELECT AVG(NumQsts) FROM"
|
||||
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
|
||||
"SELECT AVG(NumQsts)"
|
||||
" FROM (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
|
||||
" FROM crs_courses,"
|
||||
"gam_games,"
|
||||
"gam_questions"
|
||||
|
@ -2890,8 +2907,8 @@ double Gam_GetNumQstsPerCrsGame (Hie_Lvl_Level_t Scope)
|
|||
break;
|
||||
case Hie_Lvl_CRS:
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
|
||||
"SELECT AVG(NumQsts) FROM"
|
||||
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
|
||||
"SELECT AVG(NumQsts)"
|
||||
" FROM (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
|
||||
" FROM gam_games,"
|
||||
"gam_questions"
|
||||
" WHERE gam_games.Cod=%ld"
|
||||
|
@ -2925,15 +2942,13 @@ void Gam_ShowTstTagsPresentInAGame (long GamCod)
|
|||
|
||||
/***** Get all tags of questions in this game *****/
|
||||
NumTags = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get tags"
|
||||
" present in a match result",
|
||||
DB_QuerySELECT (&mysql_res,"can not get tags present in a match result",
|
||||
"SELECT tst_tags.TagTxt" // row[0]
|
||||
" FROM"
|
||||
" (SELECT DISTINCT(tst_question_tags.TagCod)"
|
||||
" FROM (SELECT DISTINCT(tst_question_tags.TagCod)"
|
||||
" FROM tst_question_tags,gam_questions"
|
||||
" WHERE gam_questions.GamCod=%ld"
|
||||
" AND gam_questions.QstCod=tst_question_tags.QstCod)"
|
||||
" AS TagsCods,tst_tags"
|
||||
" AND gam_questions.QstCod=tst_question_tags.QstCod) AS TagsCods,"
|
||||
"tst_tags"
|
||||
" WHERE TagsCods.TagCod=tst_tags.TagCod"
|
||||
" ORDER BY tst_tags.TagTxt",
|
||||
GamCod);
|
||||
|
@ -2959,7 +2974,8 @@ void Gam_GetScoreRange (long GamCod,double *MinScore,double *MaxScore)
|
|||
NumRows = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get data of a question",
|
||||
"SELECT COUNT(tst_answers.AnsInd) AS N"
|
||||
" FROM tst_answers,gam_questions"
|
||||
" FROM tst_answers,"
|
||||
"gam_questions"
|
||||
" WHERE gam_questions.GamCod=%ld"
|
||||
" AND gam_questions.QstCod=tst_answers.QstCod"
|
||||
" GROUP BY tst_answers.QstCod",
|
||||
|
|
30
swad_group.c
30
swad_group.c
|
@ -1770,9 +1770,13 @@ static bool Grp_CheckIfAssociatedToGrp (const char *Table,const char *Field,
|
|||
/***** Get if an assignment, attendance event, survey, exam event or match
|
||||
is associated to a given group from database *****/
|
||||
return (DB_QueryCOUNT ("can not check if associated to a group",
|
||||
"SELECT COUNT(*) FROM %s"
|
||||
" WHERE %s=%ld AND GrpCod=%ld",
|
||||
Table,Field,Cod,GrpCod) != 0);
|
||||
"SELECT COUNT(*)"
|
||||
" FROM %s"
|
||||
" WHERE %s=%ld"
|
||||
" AND GrpCod=%ld",
|
||||
Table,
|
||||
Field,Cod,
|
||||
GrpCod) != 0);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1790,9 +1794,11 @@ bool Grp_CheckIfAssociatedToGrps (const char *Table,const char *Field,long Cod)
|
|||
/***** Get if an assignment, attendance event, survey, exam event or match
|
||||
is associated to any group from database *****/
|
||||
return (DB_QueryCOUNT ("can not check if associated to groups",
|
||||
"SELECT COUNT(*) FROM %s"
|
||||
"SELECT COUNT(*)"
|
||||
" FROM %s"
|
||||
" WHERE %s=%ld",
|
||||
Table,Field,Cod) != 0);
|
||||
Table,
|
||||
Field,Cod) != 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -3090,13 +3096,13 @@ unsigned long Grp_GetGrpsOfType (long GrpTypCod,MYSQL_RES **mysql_res)
|
|||
/***** Get groups of a type from database *****/
|
||||
// Don't use INNER JOIN because there are groups without assigned room
|
||||
return DB_QuerySELECT (mysql_res,"can not get groups of a type",
|
||||
"SELECT grp_groups.GrpCod,"
|
||||
"grp_groups.GrpName,"
|
||||
"grp_groups.RooCod,"
|
||||
"roo_rooms.ShortName,"
|
||||
"grp_groups.MaxStudents,"
|
||||
"grp_groups.Open,"
|
||||
"grp_groups.FileZones"
|
||||
"SELECT grp_groups.GrpCod," // row[0]
|
||||
"grp_groups.GrpName," // row[1]
|
||||
"grp_groups.RooCod," // row[2]
|
||||
"roo_rooms.ShortName," // row[3]
|
||||
"grp_groups.MaxStudents," // row[4]
|
||||
"grp_groups.Open," // row[5]
|
||||
"grp_groups.FileZones" // row[6]
|
||||
" FROM grp_groups"
|
||||
" LEFT JOIN roo_rooms"
|
||||
" ON grp_groups.RooCod=roo_rooms.RooCod"
|
||||
|
|
|
@ -660,40 +660,44 @@ void Hie_GetAndWriteInsCtrDegAdminBy (long UsrCod,unsigned ColSpan)
|
|||
struct Hie_Hierarchy Hie;
|
||||
|
||||
/***** Get institutions, centers, degrees admin by user from database *****/
|
||||
NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get institutions,"
|
||||
" centers, degrees"
|
||||
NumRows = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get institutions, centers, degrees"
|
||||
" admin by a user",
|
||||
"(SELECT %u AS S,-1 AS Cod,'' AS FullName"
|
||||
"(SELECT %u AS S," // row[0]
|
||||
"-1 AS Cod," // row[1]
|
||||
"'' AS FullName" // row[2]
|
||||
" FROM usr_admins"
|
||||
" WHERE UsrCod=%ld"
|
||||
" AND Scope='%s')"
|
||||
" UNION "
|
||||
"(SELECT %u AS S,"
|
||||
"usr_admins.Cod,"
|
||||
"ins_instits.FullName"
|
||||
"(SELECT %u AS S," // row[0]
|
||||
"usr_admins.Cod," // row[1]
|
||||
"ins_instits.FullName" // row[2]
|
||||
" FROM usr_admins,"
|
||||
"ins_instits"
|
||||
" WHERE usr_admins.UsrCod=%ld"
|
||||
" AND usr_admins.Scope='%s'"
|
||||
" AND usr_admins.Cod=ins_instits.InsCod)"
|
||||
" UNION "
|
||||
"(SELECT %u AS S,"
|
||||
"usr_admins.Cod,"
|
||||
"ctr_centers.FullName"
|
||||
"(SELECT %u AS S," // row[0]
|
||||
"usr_admins.Cod," // row[1]
|
||||
"ctr_centers.FullName" // row[2]
|
||||
" FROM usr_admins,"
|
||||
"ctr_centers"
|
||||
" WHERE usr_admins.UsrCod=%ld"
|
||||
" AND usr_admins.Scope='%s'"
|
||||
" AND usr_admins.Cod=ctr_centers.CtrCod)"
|
||||
" UNION "
|
||||
"(SELECT %u AS S,"
|
||||
"usr_admins.Cod,"
|
||||
"deg_degrees.FullName"
|
||||
" FROM usr_admins,deg_degrees"
|
||||
"(SELECT %u AS S," // row[0]
|
||||
"usr_admins.Cod," // row[1]
|
||||
"deg_degrees.FullName" // row[2]
|
||||
" FROM usr_admins,"
|
||||
"deg_degrees"
|
||||
" WHERE usr_admins.UsrCod=%ld"
|
||||
" AND usr_admins.Scope='%s'"
|
||||
" AND usr_admins.Cod=deg_degrees.DegCod)"
|
||||
" ORDER BY S,FullName",
|
||||
" ORDER BY S,"
|
||||
"FullName",
|
||||
(unsigned) Hie_Lvl_SYS,UsrCod,Sco_GetDBStrFromScope (Hie_Lvl_SYS),
|
||||
(unsigned) Hie_Lvl_INS,UsrCod,Sco_GetDBStrFromScope (Hie_Lvl_INS),
|
||||
(unsigned) Hie_Lvl_CTR,UsrCod,Sco_GetDBStrFromScope (Hie_Lvl_CTR),
|
||||
|
|
|
@ -1375,7 +1375,9 @@ int Ind_GetNumIndicatorsCrsFromDB (long CrsCod)
|
|||
|
||||
/***** Get number of indicators of a course from database *****/
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get number of indicators",
|
||||
"SELECT NumIndicators FROM crs_courses WHERE CrsCod=%ld",
|
||||
"SELECT NumIndicators"
|
||||
" FROM crs_courses"
|
||||
" WHERE CrsCod=%ld",
|
||||
CrsCod))
|
||||
{
|
||||
/***** Get row *****/
|
||||
|
|
67
swad_info.c
67
swad_info.c
|
@ -506,8 +506,11 @@ static bool Inf_CheckIfIHaveReadInfo (void)
|
|||
{
|
||||
/***** Get if info source is already stored in database *****/
|
||||
return (DB_QueryCOUNT ("can not get if I have read course info",
|
||||
"SELECT COUNT(*) FROM crs_info_read"
|
||||
" WHERE UsrCod=%ld AND CrsCod=%ld AND InfoType='%s'",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM crs_info_read"
|
||||
" WHERE UsrCod=%ld"
|
||||
" AND CrsCod=%ld"
|
||||
" AND InfoType='%s'",
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
Gbl.Hierarchy.Crs.CrsCod,
|
||||
Inf_NamesInDBForInfoType[Gbl.Crs.Info.Type]) != 0);
|
||||
|
@ -534,11 +537,15 @@ bool Inf_GetIfIMustReadAnyCrsInfoInThisCrs (void)
|
|||
/***** Get info types where students must read info *****/
|
||||
NumRows = DB_QuerySELECT (&mysql_res,"can not get if you must read"
|
||||
" any course info",
|
||||
"SELECT InfoType FROM crs_info_src"
|
||||
" WHERE CrsCod=%ld AND MustBeRead='Y'"
|
||||
"SELECT InfoType"
|
||||
" FROM crs_info_src"
|
||||
" WHERE CrsCod=%ld"
|
||||
" AND MustBeRead='Y'"
|
||||
" AND InfoType NOT IN"
|
||||
" (SELECT InfoType FROM crs_info_read"
|
||||
" WHERE UsrCod=%ld AND CrsCod=%ld)",
|
||||
" (SELECT InfoType"
|
||||
" FROM crs_info_read"
|
||||
" WHERE UsrCod=%ld"
|
||||
" AND CrsCod=%ld)",
|
||||
Gbl.Hierarchy.Crs.CrsCod,
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
|
@ -1408,23 +1415,30 @@ void Inf_SetInfoSrcIntoDB (Inf_InfoSrc_t InfoSrc)
|
|||
{
|
||||
/***** Get if info source is already stored in database *****/
|
||||
if (DB_QueryCOUNT ("can not get if info source is already stored in database",
|
||||
"SELECT COUNT(*) FROM crs_info_src"
|
||||
" WHERE CrsCod=%ld AND InfoType='%s'",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM crs_info_src"
|
||||
" WHERE CrsCod=%ld"
|
||||
" AND InfoType='%s'",
|
||||
Gbl.Hierarchy.Crs.CrsCod,
|
||||
Inf_NamesInDBForInfoType[Gbl.Crs.Info.Type]))
|
||||
// Info is already stored in database, so update it
|
||||
{ // Update info source
|
||||
if (InfoSrc == Inf_INFO_SRC_NONE)
|
||||
DB_QueryUPDATE ("can not update info source",
|
||||
"UPDATE crs_info_src SET InfoSrc='%s',MustBeRead='N'"
|
||||
" WHERE CrsCod=%ld AND InfoType='%s'",
|
||||
"UPDATE crs_info_src"
|
||||
" SET InfoSrc='%s',"
|
||||
"MustBeRead='N'"
|
||||
" WHERE CrsCod=%ld"
|
||||
" AND InfoType='%s'",
|
||||
Inf_NamesInDBForInfoSrc[Inf_INFO_SRC_NONE],
|
||||
Gbl.Hierarchy.Crs.CrsCod,
|
||||
Inf_NamesInDBForInfoType[Gbl.Crs.Info.Type]);
|
||||
else // MustBeRead remains unchanged
|
||||
DB_QueryUPDATE ("can not update info source",
|
||||
"UPDATE crs_info_src SET InfoSrc='%s'"
|
||||
" WHERE CrsCod=%ld AND InfoType='%s'",
|
||||
"UPDATE crs_info_src"
|
||||
" SET InfoSrc='%s'"
|
||||
" WHERE CrsCod=%ld"
|
||||
" AND InfoType='%s'",
|
||||
Inf_NamesInDBForInfoSrc[InfoSrc],
|
||||
Gbl.Hierarchy.Crs.CrsCod,
|
||||
Inf_NamesInDBForInfoType[Gbl.Crs.Info.Type]);
|
||||
|
@ -1453,9 +1467,12 @@ Inf_InfoSrc_t Inf_GetInfoSrcFromDB (long CrsCod,Inf_InfoType_t InfoType)
|
|||
|
||||
/***** Get info source for a specific type of info from database *****/
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get info source",
|
||||
"SELECT InfoSrc FROM crs_info_src"
|
||||
" WHERE CrsCod=%ld AND InfoType='%s'",
|
||||
CrsCod,Inf_NamesInDBForInfoType[InfoType]))
|
||||
"SELECT InfoSrc"
|
||||
" FROM crs_info_src"
|
||||
" WHERE CrsCod=%ld"
|
||||
" AND InfoType='%s'",
|
||||
CrsCod,
|
||||
Inf_NamesInDBForInfoType[InfoType]))
|
||||
{
|
||||
/* Get row */
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
|
@ -1491,9 +1508,13 @@ void Inf_GetAndCheckInfoSrcFromDB (struct Syl_Syllabus *Syllabus,
|
|||
|
||||
/***** Get info source for a specific type of info from database *****/
|
||||
NumRows = DB_QuerySELECT (&mysql_res,"can not get info source",
|
||||
"SELECT InfoSrc,MustBeRead FROM crs_info_src"
|
||||
" WHERE CrsCod=%ld AND InfoType='%s'",
|
||||
CrsCod,Inf_NamesInDBForInfoType[InfoType]);
|
||||
"SELECT InfoSrc,"
|
||||
"MustBeRead"
|
||||
" FROM crs_info_src"
|
||||
" WHERE CrsCod=%ld"
|
||||
" AND InfoType='%s'",
|
||||
CrsCod,
|
||||
Inf_NamesInDBForInfoType[InfoType]);
|
||||
|
||||
/***** The result of the query must have one row or none *****/
|
||||
if (NumRows == 1)
|
||||
|
@ -1647,9 +1668,13 @@ void Inf_GetInfoTxtFromDB (long CrsCod,Inf_InfoType_t InfoType,
|
|||
/***** Get info source for a specific type of course information
|
||||
(bibliography, FAQ, links or evaluation) from database *****/
|
||||
NumRows = DB_QuerySELECT (&mysql_res,"can not get info text",
|
||||
"SELECT InfoTxtHTML,InfoTxtMD FROM crs_info_txt"
|
||||
" WHERE CrsCod=%ld AND InfoType='%s'",
|
||||
CrsCod,Inf_NamesInDBForInfoType[InfoType]);
|
||||
"SELECT InfoTxtHTML,"
|
||||
"InfoTxtMD"
|
||||
" FROM crs_info_txt"
|
||||
" WHERE CrsCod=%ld"
|
||||
" AND InfoType='%s'",
|
||||
CrsCod,
|
||||
Inf_NamesInDBForInfoType[InfoType]);
|
||||
|
||||
/***** The result of the query must have one row or none *****/
|
||||
if (NumRows == 1)
|
||||
|
|
|
@ -131,9 +131,8 @@ void Ins_SeeInsWithPendingCtrs (void)
|
|||
switch (Gbl.Usrs.Me.Role.Logged)
|
||||
{
|
||||
case Rol_INS_ADM:
|
||||
NumInss =
|
||||
(unsigned) DB_QuerySELECT (&mysql_res,"can not get institutions"
|
||||
" with pending centers",
|
||||
NumInss = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get institutions with pending centers",
|
||||
"SELECT ctr_centers.InsCod,"
|
||||
"COUNT(*)"
|
||||
" FROM ctr_centers,"
|
||||
|
@ -149,9 +148,8 @@ void Ins_SeeInsWithPendingCtrs (void)
|
|||
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||
break;
|
||||
case Rol_SYS_ADM:
|
||||
NumInss =
|
||||
(unsigned) DB_QuerySELECT (&mysql_res,"can not get institutions"
|
||||
" with pending centers",
|
||||
NumInss = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get institutions with pending centers",
|
||||
"SELECT ctr_centers.InsCod,"
|
||||
"COUNT(*)"
|
||||
" FROM ctr_centers,"
|
||||
|
@ -712,7 +710,8 @@ void Ins_GetFullListOfInstitutions (long CtyCod)
|
|||
"ins_instits.FullName," // row[5]
|
||||
"ins_instits.WWW," // row[6]
|
||||
"COUNT(*) AS NumUsrs" // row[7]
|
||||
" FROM ins_instits,usr_data"
|
||||
" FROM ins_instits,"
|
||||
"usr_data"
|
||||
" WHERE ins_instits.CtyCod=%ld"
|
||||
" AND ins_instits.InsCod=usr_data.InsCod"
|
||||
" GROUP BY ins_instits.InsCod)"
|
||||
|
@ -728,9 +727,12 @@ void Ins_GetFullListOfInstitutions (long CtyCod)
|
|||
" FROM ins_instits"
|
||||
" WHERE CtyCod=%ld"
|
||||
" AND InsCod NOT IN"
|
||||
" (SELECT DISTINCT InsCod FROM usr_data))"
|
||||
" (SELECT DISTINCT InsCod"
|
||||
" FROM usr_data))"
|
||||
" ORDER BY %s",
|
||||
CtyCod,CtyCod,OrderBySubQuery[Gbl.Hierarchy.Inss.SelectedOrder]);
|
||||
CtyCod,
|
||||
CtyCod,
|
||||
OrderBySubQuery[Gbl.Hierarchy.Inss.SelectedOrder]);
|
||||
|
||||
if (NumRows) // Institutions found...
|
||||
{
|
||||
|
@ -818,7 +820,8 @@ bool Ins_GetDataOfInstitutionByCod (struct Ins_Instit *Ins)
|
|||
"ShortName," // row[4]
|
||||
"FullName," // row[5]
|
||||
"WWW" // row[6]
|
||||
" FROM ins_instits WHERE InsCod=%ld",
|
||||
" FROM ins_instits"
|
||||
" WHERE InsCod=%ld",
|
||||
Ins->InsCod)) // Institution found...
|
||||
{
|
||||
/* Get institution data */
|
||||
|
@ -898,7 +901,8 @@ void Ins_GetShortNameOfInstitution (struct Ins_Instit *Ins)
|
|||
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get the short name"
|
||||
" of an institution",
|
||||
"SELECT ShortName FROM ins_instits"
|
||||
"SELECT ShortName"
|
||||
" FROM ins_instits"
|
||||
" WHERE InsCod=%ld",
|
||||
Ins->InsCod) == 1)
|
||||
{
|
||||
|
@ -1533,8 +1537,11 @@ bool Ins_CheckIfInsNameExistsInCty (const char *FieldName,
|
|||
/***** Get number of institutions in current country with a name from database *****/
|
||||
return (DB_QueryCOUNT ("can not check if the name of an institution"
|
||||
" already existed",
|
||||
"SELECT COUNT(*) FROM ins_instits"
|
||||
" WHERE CtyCod=%ld AND %s='%s' AND InsCod<>%ld",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM ins_instits"
|
||||
" WHERE CtyCod=%ld"
|
||||
" AND %s='%s'"
|
||||
" AND InsCod<>%ld",
|
||||
CtyCod,FieldName,Name,InsCod) != 0);
|
||||
}
|
||||
|
||||
|
@ -1970,7 +1977,8 @@ unsigned Ins_GetNumInssInCty (long CtyCod)
|
|||
Gbl.Cache.NumInssInCty.NumInss =
|
||||
(unsigned) DB_QueryCOUNT ("can not get the number of institutions"
|
||||
" in a country",
|
||||
"SELECT COUNT(*) FROM ins_instits"
|
||||
"SELECT COUNT(*)"
|
||||
" FROM ins_instits"
|
||||
" WHERE CtyCod=%ld",
|
||||
CtyCod);
|
||||
Gbl.Cache.NumInssInCty.Valid = true;
|
||||
|
@ -2240,9 +2248,12 @@ bool Ins_GetIfMapIsAvailable (long InsCod)
|
|||
(coordinates 0, 0 means not set ==> don't show map) *****/
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get if map is available",
|
||||
"SELECT EXISTS"
|
||||
"(SELECT * FROM ctr_centers"
|
||||
"(SELECT *"
|
||||
" FROM ctr_centers"
|
||||
" WHERE InsCod=%ld"
|
||||
" AND (Latitude<>0 OR Longitude<>0))",
|
||||
" AND (Latitude<>0"
|
||||
" OR"
|
||||
" Longitude<>0))",
|
||||
InsCod))
|
||||
{
|
||||
/* Get if map is available */
|
||||
|
|
|
@ -306,8 +306,8 @@ static void InsCfg_Map (void)
|
|||
Map_AddTileLayer ();
|
||||
|
||||
/* Get centers with coordinates */
|
||||
NumCtrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get centers"
|
||||
" with coordinates",
|
||||
NumCtrs = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get centers with coordinates",
|
||||
"SELECT CtrCod" // row[0]
|
||||
" FROM ctr_centers"
|
||||
" WHERE InsCod=%ld"
|
||||
|
|
|
@ -276,7 +276,8 @@ void Log_GetAndShowLastClicks (void)
|
|||
"CtrCod," // row[6]
|
||||
"DegCod" // row[7]
|
||||
" FROM log_recent"
|
||||
" ORDER BY LogCod DESC LIMIT 20");
|
||||
" ORDER BY LogCod DESC"
|
||||
" LIMIT 20");
|
||||
|
||||
/***** Write list of connected users *****/
|
||||
HTM_TABLE_BeginCenterPadding (1);
|
||||
|
|
52
swad_mail.c
52
swad_mail.c
|
@ -273,10 +273,13 @@ static void Mai_GetListMailDomainsAllowedForNotif (void)
|
|||
DB_Query ("can not create temporary table",
|
||||
"CREATE TEMPORARY TABLE T1 ENGINE=MEMORY"
|
||||
" SELECT SUBSTRING_INDEX(E_mail,'@',-1) AS Domain,COUNT(*) as N"
|
||||
" FROM usr_emails GROUP BY Domain");
|
||||
" FROM usr_emails"
|
||||
" GROUP BY Domain");
|
||||
|
||||
DB_Query ("can not create temporary table",
|
||||
"CREATE TEMPORARY TABLE T2 ENGINE=MEMORY SELECT * FROM T1");
|
||||
"CREATE TEMPORARY TABLE T2 ENGINE=MEMORY"
|
||||
" SELECT *"
|
||||
" FROM T1");
|
||||
|
||||
/***** Get mail domains from database *****/
|
||||
NumRows = DB_QuerySELECT (&mysql_res,"can not get mail domains",
|
||||
|
@ -293,7 +296,8 @@ static void Mai_GetListMailDomainsAllowedForNotif (void)
|
|||
"0 AS N" // row[3]
|
||||
" FROM ntf_mail_domains"
|
||||
" WHERE Domain NOT IN"
|
||||
" (SELECT Domain COLLATE 'latin1_bin' FROM T2))"
|
||||
" (SELECT Domain COLLATE 'latin1_bin'"
|
||||
" FROM T2))"
|
||||
" ORDER BY %s", // COLLATE necessary to avoid error in comparisons
|
||||
OrderBySubQuery[Gbl.Mails.SelectedOrder]);
|
||||
|
||||
|
@ -1083,9 +1087,12 @@ bool Mai_GetEmailFromUsrCod (struct UsrData *UsrDat)
|
|||
|
||||
/***** Get current (last updated) user's nickname from database *****/
|
||||
NumRows = DB_QuerySELECT (&mysql_res,"can not get email address",
|
||||
"SELECT E_mail,Confirmed FROM usr_emails"
|
||||
"SELECT E_mail,"
|
||||
"Confirmed"
|
||||
" FROM usr_emails"
|
||||
" WHERE UsrCod=%ld"
|
||||
" ORDER BY CreatTime DESC LIMIT 1",
|
||||
" ORDER BY CreatTime DESC"
|
||||
" LIMIT 1",
|
||||
UsrDat->UsrCod);
|
||||
|
||||
if (NumRows == 0)
|
||||
|
@ -1126,9 +1133,11 @@ long Mai_GetUsrCodFromEmail (const char Email[Cns_MAX_BYTES_EMAIL_ADDRESS + 1])
|
|||
{
|
||||
/***** Get user's code from database *****/
|
||||
/* Check if user code from table usr_emails is also in table usr_data */
|
||||
NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get user's code",
|
||||
NumUsrs = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get user's code",
|
||||
"SELECT usr_emails.UsrCod"
|
||||
" FROM usr_emails,usr_data"
|
||||
" FROM usr_emails,"
|
||||
"usr_data"
|
||||
" WHERE usr_emails.E_mail='%s'"
|
||||
" AND usr_emails.UsrCod=usr_data.UsrCod",
|
||||
Email);
|
||||
|
@ -1253,10 +1262,10 @@ static void Mai_ShowFormChangeUsrEmail (bool ItsMe,
|
|||
Ale_ShowAlert (Ale_WARNING,Txt_Please_confirm_your_email_address);
|
||||
|
||||
/***** Get my emails *****/
|
||||
NumEmails = (unsigned) DB_QuerySELECT (&mysql_res,"can not get"
|
||||
" old email addresses"
|
||||
" of a user",
|
||||
"SELECT E_mail,Confirmed"
|
||||
NumEmails = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get old email addresses of a user",
|
||||
"SELECT E_mail," // row[0]
|
||||
"Confirmed" // row[1]
|
||||
" FROM usr_emails"
|
||||
" WHERE UsrCod=%ld"
|
||||
" ORDER BY CreatTime DESC",
|
||||
|
@ -1617,23 +1626,30 @@ bool Mai_UpdateEmailInDB (const struct UsrData *UsrDat,const char NewEmail[Cns_M
|
|||
{
|
||||
/***** Check if the new email matches any of the confirmed emails of other users *****/
|
||||
if (DB_QueryCOUNT ("can not check if email already existed",
|
||||
"SELECT COUNT(*) FROM usr_emails"
|
||||
" WHERE E_mail='%s' AND Confirmed='Y'"
|
||||
"SELECT COUNT(*)"
|
||||
" FROM usr_emails"
|
||||
" WHERE E_mail='%s'"
|
||||
" AND Confirmed='Y'"
|
||||
" AND UsrCod<>%ld",
|
||||
NewEmail,UsrDat->UsrCod)) // An email of another user is the same that my email
|
||||
NewEmail,
|
||||
UsrDat->UsrCod)) // An email of another user is the same that my email
|
||||
return false; // Don't update
|
||||
|
||||
/***** Delete email (not confirmed) for other users *****/
|
||||
DB_QueryDELETE ("can not remove pending email for other users",
|
||||
"DELETE FROM usr_pending_emails"
|
||||
" WHERE E_mail='%s' AND UsrCod<>%ld",
|
||||
NewEmail,UsrDat->UsrCod);
|
||||
" WHERE E_mail='%s'"
|
||||
" AND UsrCod<>%ld",
|
||||
NewEmail,
|
||||
UsrDat->UsrCod);
|
||||
|
||||
DB_QueryDELETE ("can not remove not confirmed email for other users",
|
||||
"DELETE FROM usr_emails"
|
||||
" WHERE E_mail='%s' AND Confirmed='N'"
|
||||
" WHERE E_mail='%s'"
|
||||
" AND Confirmed='N'"
|
||||
" AND UsrCod<>%ld",
|
||||
NewEmail,UsrDat->UsrCod);
|
||||
NewEmail,
|
||||
UsrDat->UsrCod);
|
||||
|
||||
/***** Update email in database *****/
|
||||
DB_QueryREPLACE ("can not update email",
|
||||
|
|
10
swad_mark.c
10
swad_mark.c
|
@ -729,11 +729,11 @@ void Mrk_GetNotifMyMarks (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
|
|||
/***** Get subject of message from database *****/
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get the number of rows"
|
||||
" in header and footer",
|
||||
"SELECT brw_files.FileBrowser,"
|
||||
"brw_files.Cod,"
|
||||
"brw_files.Path,"
|
||||
"mrk_marks.Header,"
|
||||
"mrk_marks.Footer"
|
||||
"SELECT brw_files.FileBrowser," // row[0]
|
||||
"brw_files.Cod," // row[1]
|
||||
"brw_files.Path," // row[2]
|
||||
"mrk_marks.Header," // row[3]
|
||||
"mrk_marks.Footer" // row[4]
|
||||
" FROM brw_files,"
|
||||
"mrk_marks"
|
||||
" WHERE brw_files.FilCod=%ld"
|
||||
|
|
Loading…
Reference in New Issue