mirror of https://github.com/acanas/swad-core.git
Version 20.56: Apr 04, 2021 Optimizations in database selects.
This commit is contained in:
parent
9dba8e5314
commit
3c20280f3a
126
swad_API.c
126
swad_API.c
|
@ -358,11 +358,11 @@ static int API_GetPlgCodFromAppKey (struct soap *soap,
|
|||
const char *appKey)
|
||||
{
|
||||
/***** Get number of plugins with a IP address *****/
|
||||
Gbl.WebService.PlgCod = DB_QuerySELECTCod ("can not check application key",
|
||||
"SELECT PlgCod"
|
||||
" FROM plg_plugins"
|
||||
" WHERE AppKey='%s'",
|
||||
appKey); // Session found in table of sessions
|
||||
Gbl.WebService.PlgCod = DB_QuerySELECTCode ("can not check application key",
|
||||
"SELECT PlgCod"
|
||||
" FROM plg_plugins"
|
||||
" WHERE AppKey='%s'",
|
||||
appKey); // Session found in table of sessions
|
||||
if (Gbl.WebService.PlgCod < 0)
|
||||
return soap_sender_fault (soap,
|
||||
"Unknown application key",
|
||||
|
@ -578,11 +578,11 @@ static int API_RemoveOldWSKeys (struct soap *soap)
|
|||
static int API_GetCurrentDegCodFromCurrentCrsCod (void)
|
||||
{
|
||||
/***** Check that key does not exist in database *****/
|
||||
Gbl.Hierarchy.Deg.DegCod = DB_QuerySELECTCod ("can not get the degree of a course",
|
||||
"SELECT DegCod"
|
||||
" FROM crs_courses"
|
||||
" WHERE CrsCod=%ld",
|
||||
Gbl.Hierarchy.Crs.CrsCod); // Course found in table of courses
|
||||
Gbl.Hierarchy.Deg.DegCod = DB_QuerySELECTCode ("can not get the degree of a course",
|
||||
"SELECT DegCod"
|
||||
" FROM crs_courses"
|
||||
" WHERE CrsCod=%ld",
|
||||
Gbl.Hierarchy.Crs.CrsCod); // Course found in table of courses
|
||||
|
||||
return SOAP_OK;
|
||||
}
|
||||
|
@ -895,28 +895,28 @@ int swad__loginByUserPasswordKey (struct soap *soap,
|
|||
Str_RemoveLeadingArrobas (UsrIDNickOrEmail);
|
||||
|
||||
/* User has typed a nickname */
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod = DB_QuerySELECTCod ("can not get user's data",
|
||||
"SELECT usr_nicknames.UsrCod"
|
||||
" FROM usr_nicknames,"
|
||||
"usr_data"
|
||||
" WHERE usr_nicknames.Nickname='%s'"
|
||||
" AND usr_nicknames.UsrCod=usr_data.UsrCod"
|
||||
" AND usr_data.Password='%s'",
|
||||
UsrIDNickOrEmail,
|
||||
userPassword);
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod = DB_QuerySELECTCode ("can not get user's data",
|
||||
"SELECT usr_nicknames.UsrCod"
|
||||
" FROM usr_nicknames,"
|
||||
"usr_data"
|
||||
" WHERE usr_nicknames.Nickname='%s'"
|
||||
" AND usr_nicknames.UsrCod=usr_data.UsrCod"
|
||||
" AND usr_data.Password='%s'",
|
||||
UsrIDNickOrEmail,
|
||||
userPassword);
|
||||
}
|
||||
else if (Mai_CheckIfEmailIsValid (UsrIDNickOrEmail)) // 2: It's an email
|
||||
{
|
||||
/* User has typed an email */
|
||||
// TODO: Get only if email confirmed?
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod = DB_QuerySELECTCod ("can not get user's data",
|
||||
"SELECT usr_emails.UsrCod"
|
||||
" FROM usr_emails,usr_data"
|
||||
" WHERE usr_emails.E_mail='%s'"
|
||||
" AND usr_emails.UsrCod=usr_data.UsrCod"
|
||||
" AND usr_data.Password='%s'",
|
||||
UsrIDNickOrEmail,
|
||||
userPassword);
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod = DB_QuerySELECTCode ("can not get user's data",
|
||||
"SELECT usr_emails.UsrCod"
|
||||
" FROM usr_emails,usr_data"
|
||||
" WHERE usr_emails.E_mail='%s'"
|
||||
" AND usr_emails.UsrCod=usr_data.UsrCod"
|
||||
" AND usr_data.Password='%s'",
|
||||
UsrIDNickOrEmail,
|
||||
userPassword);
|
||||
}
|
||||
else // 3: It's not a nickname nor email
|
||||
{
|
||||
|
@ -927,15 +927,15 @@ int swad__loginByUserPasswordKey (struct soap *soap,
|
|||
{
|
||||
/* User has typed a valid user's ID (existing or not) */
|
||||
// TODO: Get only if ID confirmed?
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod = DB_QuerySELECTCod ("can not get user's data",
|
||||
"SELECT usr_ids.UsrCod"
|
||||
" FROM usr_ids,"
|
||||
"usr_data"
|
||||
" WHERE usr_ids.UsrID='%s'"
|
||||
" AND usr_ids.UsrCod=usr_data.UsrCod"
|
||||
" AND usr_data.Password='%s'",
|
||||
UsrIDNickOrEmail,
|
||||
userPassword);
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod = DB_QuerySELECTCode ("can not get user's data",
|
||||
"SELECT usr_ids.UsrCod"
|
||||
" FROM usr_ids,"
|
||||
"usr_data"
|
||||
" WHERE usr_ids.UsrID='%s'"
|
||||
" AND usr_ids.UsrCod=usr_data.UsrCod"
|
||||
" AND usr_data.Password='%s'",
|
||||
UsrIDNickOrEmail,
|
||||
userPassword);
|
||||
}
|
||||
else // String is not a valid user's nickname, email or ID
|
||||
return soap_receiver_fault (soap,
|
||||
|
@ -1245,20 +1245,20 @@ int swad__getNewPassword (struct soap *soap,
|
|||
Str_RemoveLeadingArrobas (UsrIDNickOrEmail);
|
||||
|
||||
/* User has typed a nickname */
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod = DB_QuerySELECTCod ("can not get user's data",
|
||||
"SELECT UsrCod"
|
||||
" FROM usr_nicknames"
|
||||
" WHERE Nickname='%s'",
|
||||
UsrIDNickOrEmail);
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod = DB_QuerySELECTCode ("can not get user's data",
|
||||
"SELECT UsrCod"
|
||||
" FROM usr_nicknames"
|
||||
" WHERE Nickname='%s'",
|
||||
UsrIDNickOrEmail);
|
||||
}
|
||||
else if (Mai_CheckIfEmailIsValid (Gbl.Usrs.Me.UsrIdLogin)) // 2: It's an email
|
||||
/* User has typed an email */
|
||||
// TODO: Get only if email confirmed?
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod = DB_QuerySELECTCod ("can not get user's data",
|
||||
"SELECT UsrCod"
|
||||
" FROM usr_emails"
|
||||
" WHERE E_mail='%s'",
|
||||
UsrIDNickOrEmail);
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod = DB_QuerySELECTCode ("can not get user's data",
|
||||
"SELECT UsrCod"
|
||||
" FROM usr_emails"
|
||||
" WHERE E_mail='%s'",
|
||||
UsrIDNickOrEmail);
|
||||
else // 3: It's not a nickname nor email
|
||||
{
|
||||
// Users' IDs are always stored internally in capitals and without leading zeros
|
||||
|
@ -1267,11 +1267,11 @@ int swad__getNewPassword (struct soap *soap,
|
|||
if (ID_CheckIfUsrIDIsValid (UsrIDNickOrEmail))
|
||||
/* User has typed a valid user's ID (existing or not) */
|
||||
// TODO: Get only if ID confirmed?
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod = DB_QuerySELECTCod ("can not get user's data",
|
||||
"SELECT UsrCod"
|
||||
" FROM usr_ids"
|
||||
" WHERE UsrID='%s'",
|
||||
UsrIDNickOrEmail);
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod = DB_QuerySELECTCode ("can not get user's data",
|
||||
"SELECT UsrCod"
|
||||
" FROM usr_ids"
|
||||
" WHERE UsrID='%s'",
|
||||
UsrIDNickOrEmail);
|
||||
else // String is not a valid user's nickname, email or ID
|
||||
return soap_receiver_fault (soap,
|
||||
"Bad log in",
|
||||
|
@ -2697,7 +2697,7 @@ static void API_GetListGrpsInAttendanceEventFromDB (struct soap *soap,
|
|||
NumGrp++)
|
||||
{
|
||||
/* Get next group */
|
||||
GrpCod = DB_GetNextCod (mysql_res);
|
||||
GrpCod = DB_GetNextCode (mysql_res);
|
||||
snprintf (GrpCodStr,sizeof (GrpCodStr),NumGrp ? ",%ld" :
|
||||
"%ld",
|
||||
GrpCod);
|
||||
|
@ -3704,16 +3704,16 @@ int swad__sendMessage (struct soap *soap,
|
|||
"Original message does not exist");
|
||||
|
||||
/***** Get the recipient of the message *****/
|
||||
ReplyUsrCod = DB_QuerySELECTCod ("can not check original message",
|
||||
"SELECT UsrCod"
|
||||
" FROM msg_snt"
|
||||
" WHERE MsgCod=%ld"
|
||||
" UNION "
|
||||
"SELECT UsrCod"
|
||||
" FROM msg_snt_deleted"
|
||||
" WHERE MsgCod=%ld",
|
||||
(long) messageCode,
|
||||
(long) messageCode);
|
||||
ReplyUsrCod = DB_QuerySELECTCode ("can not check original message",
|
||||
"SELECT UsrCod"
|
||||
" FROM msg_snt"
|
||||
" WHERE MsgCod=%ld"
|
||||
" UNION "
|
||||
"SELECT UsrCod"
|
||||
" FROM msg_snt_deleted"
|
||||
" WHERE MsgCod=%ld",
|
||||
(long) messageCode,
|
||||
(long) messageCode);
|
||||
if (ReplyUsrCod <= 0)
|
||||
return soap_sender_fault (soap,
|
||||
"Can not send reply message",
|
||||
|
@ -5418,7 +5418,7 @@ static void API_GetListGrpsInGameFromDB (struct soap *soap,
|
|||
NumGrp++)
|
||||
{
|
||||
/* Get next group */
|
||||
GrpCod = DB_GetNextCod (mysql_res);
|
||||
GrpCod = DB_GetNextCode (mysql_res);
|
||||
snprintf (GrpCodStr,sizeof (GrpCodStr),NumGrp ? ",%ld" :
|
||||
"%ld",
|
||||
GrpCod);
|
||||
|
|
|
@ -238,7 +238,7 @@ void Acc_CheckIfEmptyAccountExists (void)
|
|||
{
|
||||
/***** Get user's data from query result *****/
|
||||
/* Get user's code */
|
||||
UsrDat.UsrCod = DB_GetNextCod (mysql_res);
|
||||
UsrDat.UsrCod = DB_GetNextCode (mysql_res);
|
||||
|
||||
/* Get user's data */
|
||||
Usr_GetAllUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS);
|
||||
|
|
|
@ -1175,7 +1175,7 @@ static void Agd_GetListEvents (struct Agd_Agenda *Agenda,
|
|||
NumEvent < Agenda->Num;
|
||||
NumEvent++)
|
||||
/* Get next event code */
|
||||
if ((Agenda->LstAgdCods[NumEvent] = DB_GetNextCod (mysql_res)) < 0)
|
||||
if ((Agenda->LstAgdCods[NumEvent] = DB_GetNextCode (mysql_res)) < 0)
|
||||
Lay_ShowErrorAndExit ("Error: wrong event code.");
|
||||
}
|
||||
|
||||
|
|
|
@ -740,7 +740,7 @@ static void Asg_GetListAssignments (struct Asg_Assignments *Assignments)
|
|||
NumAsg++)
|
||||
{
|
||||
/* Get next assignment code */
|
||||
if ((Assignments->LstAsgCods[NumAsg] = DB_GetNextCod (mysql_res)) < 0)
|
||||
if ((Assignments->LstAsgCods[NumAsg] = DB_GetNextCode (mysql_res)) < 0)
|
||||
Lay_ShowErrorAndExit ("Error: wrong assignment code.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -720,7 +720,7 @@ static void Att_GetListAttEvents (struct Att_Events *Events,
|
|||
NumAttEvent++)
|
||||
{
|
||||
/* Get next attendance event code */
|
||||
if ((Events->Lst[NumAttEvent].AttCod = DB_GetNextCod (mysql_res)) < 0)
|
||||
if ((Events->Lst[NumAttEvent].AttCod = DB_GetNextCode (mysql_res)) < 0)
|
||||
Lay_ShowErrorAndExit ("Error: wrong attendance event code.");
|
||||
}
|
||||
}
|
||||
|
@ -3069,7 +3069,7 @@ static void Att_GetListSelectedAttCods (struct Att_Events *Events)
|
|||
NumGrpInThisEvent++)
|
||||
{
|
||||
/* Get next group associated to this event */
|
||||
if ((GrpCodInThisEvent = DB_GetNextCod (mysql_res)) > 0)
|
||||
if ((GrpCodInThisEvent = DB_GetNextCode (mysql_res)) > 0)
|
||||
/* Check if this group is selected */
|
||||
for (NumGrpSel = 0;
|
||||
NumGrpSel < Gbl.Crs.Grps.LstGrpsSel.NumGrps &&
|
||||
|
|
|
@ -423,7 +423,7 @@ void Cfe_PrintCallForExam (void)
|
|||
|
||||
/***** Get the code of the call for exam *****/
|
||||
if ((ExaCod = Cfe_GetParamExaCod ()) <= 0)
|
||||
Lay_ShowErrorAndExit ("Code of call for exam is missing.");
|
||||
Lay_WrongCallForExamExit ();
|
||||
|
||||
/***** Read call for exam from the database *****/
|
||||
Cfe_GetDataCallForExamFromDB (&CallsForExams,ExaCod);
|
||||
|
@ -452,7 +452,7 @@ void Cfe_ReqRemoveCallForExam (void)
|
|||
|
||||
/***** Get the code of the call for exam *****/
|
||||
if ((ExaCod = Cfe_GetParamExaCod ()) <= 0)
|
||||
Lay_ShowErrorAndExit ("Code of call for exam is missing.");
|
||||
Lay_WrongCallForExamExit ();
|
||||
|
||||
/***** Show question and button to remove call for exam *****/
|
||||
/* Begin alert */
|
||||
|
@ -488,7 +488,7 @@ void Cfe_RemoveCallForExam1 (void)
|
|||
|
||||
/***** Get the code of the call for exam *****/
|
||||
if ((ExaCod = Cfe_GetParamExaCod ()) <= 0)
|
||||
Lay_ShowErrorAndExit ("Code of call for exam is missing.");
|
||||
Lay_WrongCallForExamExit ();
|
||||
|
||||
/***** Mark the call for exam as deleted in the database *****/
|
||||
DB_QueryUPDATE ("can not remove call for exam",
|
||||
|
@ -536,7 +536,7 @@ void Cfe_HideCallForExam (void)
|
|||
|
||||
/***** Get the code of the call for exam *****/
|
||||
if ((ExaCod = Cfe_GetParamExaCod ()) <= 0)
|
||||
Lay_ShowErrorAndExit ("Code of call for exam is missing.");
|
||||
Lay_WrongCallForExamExit ();
|
||||
|
||||
/***** Mark the call for exam as hidden in the database *****/
|
||||
DB_QueryUPDATE ("can not hide call for exam",
|
||||
|
@ -567,7 +567,7 @@ void Cfe_UnhideCallForExam (void)
|
|||
|
||||
/***** Get the code of the call for exam *****/
|
||||
if ((ExaCod = Cfe_GetParamExaCod ()) <= 0)
|
||||
Lay_ShowErrorAndExit ("Code of call for exam is missing.");
|
||||
Lay_WrongCallForExamExit ();
|
||||
|
||||
/***** Mark the call for exam as visible in the database *****/
|
||||
DB_QueryUPDATE ("can not unhide call for exam",
|
||||
|
@ -683,7 +683,6 @@ static void Cfe_ListCallsForExams (struct Cfe_CallsForExams *CallsForExams,
|
|||
extern const char *Txt_No_calls_for_exams_of_X;
|
||||
char SubQueryStatus[64];
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
unsigned long NumExaAnn;
|
||||
unsigned long NumExaAnns;
|
||||
long ExaCod;
|
||||
|
@ -731,10 +730,8 @@ static void Cfe_ListCallsForExams (struct Cfe_CallsForExams *CallsForExams,
|
|||
NumExaAnn++)
|
||||
{
|
||||
/***** Get the code of the call for exam (row[0]) *****/
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
|
||||
if (sscanf (row[0],"%ld",&ExaCod) != 1)
|
||||
Lay_ShowErrorAndExit ("Wrong code of call for exam.");
|
||||
if ((ExaCod = DB_GetNextCode (mysql_res)) <= 0)
|
||||
Lay_WrongCallForExamExit ();
|
||||
|
||||
/***** Allocate memory for the call for exam *****/
|
||||
Cfe_AllocMemCallForExam (CallsForExams);
|
||||
|
@ -934,7 +931,7 @@ void Cfe_CreateListCallsForExams (struct Cfe_CallsForExams *CallsForExams)
|
|||
&CallsForExams->Lst[CallsForExams->NumCallsForExams].ExamDate.Year,
|
||||
&CallsForExams->Lst[CallsForExams->NumCallsForExams].ExamDate.Month,
|
||||
&CallsForExams->Lst[CallsForExams->NumCallsForExams].ExamDate.Day) != 3)
|
||||
Lay_ShowErrorAndExit ("Wrong date of exam.");
|
||||
Lay_WrongCallForExamExit ();
|
||||
|
||||
/***** Increment number of elements in list *****/
|
||||
CallsForExams->NumCallsForExams++;
|
||||
|
@ -999,7 +996,7 @@ static void Cfe_GetDataCallForExamFromDB (struct Cfe_CallsForExams *CallsForExam
|
|||
|
||||
/***** The result of the query must have one row *****/
|
||||
if (NumExaAnns != 1)
|
||||
Lay_ShowErrorAndExit ("Error when getting data of a call for exam.");
|
||||
Lay_WrongCallForExamExit ();
|
||||
|
||||
/***** Get the data of the call for exam *****/
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
|
@ -1009,9 +1006,9 @@ static void Cfe_GetDataCallForExamFromDB (struct Cfe_CallsForExams *CallsForExam
|
|||
|
||||
/* Status of the call for exam (row[1]) */
|
||||
if (sscanf (row[1],"%u",&UnsignedNum) != 1)
|
||||
Lay_ShowErrorAndExit ("Wrong status.");
|
||||
Lay_WrongCallForExamExit ();
|
||||
if (UnsignedNum >= Cfe_NUM_STATUS)
|
||||
Lay_ShowErrorAndExit ("Wrong status.");
|
||||
Lay_WrongCallForExamExit ();
|
||||
CallsForExams->CallForExam.Status = (Cfe_Status_t) UnsignedNum;
|
||||
|
||||
/* Name of the course (row[2]) */
|
||||
|
@ -1020,7 +1017,7 @@ static void Cfe_GetDataCallForExamFromDB (struct Cfe_CallsForExams *CallsForExam
|
|||
|
||||
/* Year (row[3]) */
|
||||
if (sscanf (row[3],"%u",&CallsForExams->CallForExam.Year) != 1)
|
||||
Lay_ShowErrorAndExit ("Wrong year.");
|
||||
Lay_WrongCallForExamExit ();
|
||||
|
||||
/* Exam session (row[4]) */
|
||||
Str_Copy (CallsForExams->CallForExam.Session,row[4],
|
||||
|
@ -1034,7 +1031,7 @@ static void Cfe_GetDataCallForExamFromDB (struct Cfe_CallsForExams *CallsForExam
|
|||
&Hour,
|
||||
&Minute,
|
||||
&Second) != 6)
|
||||
Lay_ShowErrorAndExit ("Wrong date of call for exam.");
|
||||
Lay_WrongCallForExamExit ();
|
||||
|
||||
/* Date of exam (row[6]) */
|
||||
if (sscanf (row[6],"%04u-%02u-%02u %02u:%02u:%02u",
|
||||
|
@ -1044,7 +1041,7 @@ static void Cfe_GetDataCallForExamFromDB (struct Cfe_CallsForExams *CallsForExam
|
|||
&CallsForExams->CallForExam.StartTime.Hour,
|
||||
&CallsForExams->CallForExam.StartTime.Minute,
|
||||
&Second) != 6)
|
||||
Lay_ShowErrorAndExit ("Wrong date of exam.");
|
||||
Lay_WrongCallForExamExit ();
|
||||
snprintf (CallsForExams->CallForExam.ExamDate.YYYYMMDD,
|
||||
sizeof (CallsForExams->CallForExam.ExamDate.YYYYMMDD),"%04u%02u%02u",
|
||||
CallsForExams->CallForExam.ExamDate.Year,
|
||||
|
@ -1056,7 +1053,7 @@ static void Cfe_GetDataCallForExamFromDB (struct Cfe_CallsForExams *CallsForExam
|
|||
&CallsForExams->CallForExam.Duration.Hour,
|
||||
&CallsForExams->CallForExam.Duration.Minute,
|
||||
&Second) != 3)
|
||||
Lay_ShowErrorAndExit ("Wrong duration of exam.");
|
||||
Lay_WrongCallForExamExit ();
|
||||
|
||||
/* Place (row[8]), exam mode (row[9]), structure (row[10]),
|
||||
documentation required (row[11]), material required (row[12]),
|
||||
|
|
|
@ -147,8 +147,8 @@ void Ctr_SeeCtrWithPendingDegs (void)
|
|||
case Rol_SYS_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_centers"
|
||||
" WHERE (deg_degrees.Status & %u)<>0"
|
||||
|
@ -795,29 +795,16 @@ static void Ctr_GetDataOfCenterFromRow (struct Ctr_Center *Ctr,MYSQL_ROW row)
|
|||
|
||||
long Ctr_GetInsCodOfCenterByCod (long CtrCod)
|
||||
{
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
long InsCod = -1L;
|
||||
/***** Trivial check: center code should be > 0 *****/
|
||||
if (CtrCod <= 0)
|
||||
return -1L;
|
||||
|
||||
if (CtrCod > 0)
|
||||
{
|
||||
/***** 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",
|
||||
CtrCod) == 1)
|
||||
{
|
||||
/***** Get the institution code of this center *****/
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
InsCod = Str_ConvertStrCodToLongCod (row[0]);
|
||||
}
|
||||
|
||||
/***** Free structure that stores the query result *****/
|
||||
DB_FreeMySQLResult (&mysql_res);
|
||||
}
|
||||
|
||||
return InsCod;
|
||||
/***** Get the institution code of a center from database *****/
|
||||
return DB_QuerySELECTCode ("can not get the institution of a center",
|
||||
"SELECT InsCod"
|
||||
" FROM ctr_centers"
|
||||
" WHERE CtrCod=%ld",
|
||||
CtrCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -834,7 +821,7 @@ 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"
|
||||
"SELECT ShortName" // row[0]
|
||||
" FROM ctr_centers"
|
||||
" WHERE CtrCod=%ld",
|
||||
Ctr->CtrCod) == 1)
|
||||
|
@ -896,8 +883,8 @@ void Ctr_WriteSelectorOfCenter (void)
|
|||
/***** Get centers from database *****/
|
||||
NumCtrs = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get centers",
|
||||
"SELECT DISTINCT CtrCod,"
|
||||
"ShortName"
|
||||
"SELECT DISTINCT CtrCod," // row[0]
|
||||
"ShortName" // row[1]
|
||||
" FROM ctr_centers"
|
||||
" WHERE InsCod=%ld"
|
||||
" ORDER BY ShortName",
|
||||
|
|
|
@ -517,7 +517,7 @@ 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"
|
||||
"SELECT PhotoAttribution" // row[0]
|
||||
" 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.55 (2021-04-04)"
|
||||
#define Log_PLATFORM_VERSION "SWAD 20.56 (2021-04-04)"
|
||||
#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.56: Apr 04, 2021 Optimizations in database selects. (309296 lines)
|
||||
Version 20.55: Apr 04, 2021 Optimizations in database selects. (309500 lines)
|
||||
Version 20.54: Mar 30, 2021 Statistics about agendas. (309539 lines)
|
||||
Version 20.53.1: Mar 30, 2021 Optimizations in database selects. (309459 lines)
|
||||
|
|
|
@ -637,8 +637,8 @@ static void Con_GetNumConnectedUsrsWithARoleBelongingCurrentLocation (Rol_Role_t
|
|||
break;
|
||||
case Hie_Lvl_CTY: // Show connected users in the current country
|
||||
DB_QuerySELECT (&mysql_res,"can not get number"
|
||||
" of connected users"
|
||||
" who belong to this location",
|
||||
" of connected users"
|
||||
" who belong to this location",
|
||||
"SELECT COUNT(DISTINCT usr_connected.UsrCod)," // row[0]
|
||||
"COUNT(DISTINCT usr_data.Sex)," // row[1]
|
||||
"MIN(usr_data.Sex)" // row[2]
|
||||
|
|
|
@ -271,7 +271,6 @@ static void CtyCfg_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom)
|
|||
static void CtyCfg_Map (void)
|
||||
{
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
struct Coordinates CtyAvgCoord;
|
||||
unsigned Zoom;
|
||||
unsigned NumCtrs;
|
||||
|
@ -317,10 +316,7 @@ static void CtyCfg_Map (void)
|
|||
NumCtr++)
|
||||
{
|
||||
/* Get next center */
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
|
||||
/* Get center code (row[0]) */
|
||||
Ctr.CtrCod = Str_ConvertStrCodToLongCod (row[0]);
|
||||
Ctr.CtrCod = DB_GetNextCode (mysql_res);
|
||||
|
||||
/* Get data of center */
|
||||
Ctr_GetDataOfCenterByCod (&Ctr);
|
||||
|
@ -583,7 +579,7 @@ static void CtyCfg_GetMapAttr (long CtyCod,char **MapAttribution)
|
|||
|
||||
/***** Get photo attribution from database *****/
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get photo attribution",
|
||||
"SELECT MapAttribution"
|
||||
"SELECT MapAttribution" // row[0]
|
||||
" FROM cty_countrs"
|
||||
" WHERE CtyCod=%ld",
|
||||
CtyCod))
|
||||
|
|
|
@ -2992,7 +2992,6 @@ void Crs_RemoveOldCrss (void)
|
|||
unsigned MonthsWithoutAccess;
|
||||
unsigned long SecondsWithoutAccess;
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
unsigned long NumCrs;
|
||||
unsigned long NumCrss;
|
||||
unsigned NumCrssRemoved = 0;
|
||||
|
@ -3029,8 +3028,7 @@ void Crs_RemoveOldCrss (void)
|
|||
NumCrs < NumCrss;
|
||||
NumCrs++)
|
||||
{
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
CrsCod = Str_ConvertStrCodToLongCod (row[0]);
|
||||
CrsCod = DB_GetNextCode (mysql_res);
|
||||
Crs_RemoveCourseCompletely (CrsCod);
|
||||
NumCrssRemoved++;
|
||||
}
|
||||
|
|
|
@ -3808,8 +3808,8 @@ unsigned long DB_QuerySELECT (MYSQL_RES **mysql_res,const char *MsgError,
|
|||
/*** Make a SELECT query for a unique row with one long code from database ***/
|
||||
/*****************************************************************************/
|
||||
|
||||
long DB_QuerySELECTCod (const char *MsgError,
|
||||
const char *fmt,...)
|
||||
long DB_QuerySELECTCode (const char *MsgError,
|
||||
const char *fmt,...)
|
||||
{
|
||||
MYSQL_RES *mysql_res;
|
||||
va_list ap;
|
||||
|
@ -3826,7 +3826,7 @@ long DB_QuerySELECTCod (const char *MsgError,
|
|||
|
||||
/***** Do SELECT query *****/
|
||||
if (DB_QuerySELECTusingQueryStr (Query,&mysql_res,MsgError)) // Row found
|
||||
Cod = DB_GetNextCod (mysql_res);
|
||||
Cod = DB_GetNextCode (mysql_res);
|
||||
else
|
||||
Cod = -1L;
|
||||
|
||||
|
@ -3870,7 +3870,7 @@ static unsigned long DB_QuerySELECTusingQueryStr (char *Query,
|
|||
/*****************************************************************************/
|
||||
/* Each row of the result should hold a code (long) */
|
||||
|
||||
long DB_GetNextCod (MYSQL_RES *mysql_res)
|
||||
long DB_GetNextCode (MYSQL_RES *mysql_res)
|
||||
{
|
||||
MYSQL_ROW row;
|
||||
|
||||
|
|
|
@ -41,9 +41,9 @@ void DB_BuildQuery (char **Query,const char *fmt,...);
|
|||
|
||||
unsigned long DB_QuerySELECT (MYSQL_RES **mysql_res,const char *MsgError,
|
||||
const char *fmt,...);
|
||||
long DB_QuerySELECTCod (const char *MsgError,
|
||||
const char *fmt,...);
|
||||
long DB_GetNextCod (MYSQL_RES *mysql_res);
|
||||
long DB_QuerySELECTCode (const char *MsgError,
|
||||
const char *fmt,...);
|
||||
long DB_GetNextCode (MYSQL_RES *mysql_res);
|
||||
unsigned long DB_GetNumRowsTable (const char *Table);
|
||||
unsigned long DB_QueryCOUNT (const char *MsgError,const char *fmt,...);
|
||||
|
||||
|
|
|
@ -802,7 +802,7 @@ void Dat_GetBrowserTimeZone (char BrowserTimeZone[Dat_MAX_BYTES_TIME_ZONE + 1])
|
|||
/* Try to convert a date from server time zone to browser time zone */
|
||||
if (DB_QuerySELECT (&mysql_res,"can not check if time zone name"
|
||||
" is usable",
|
||||
"SELECT CONVERT_TZ(NOW(),@@session.time_zone,'%s')",
|
||||
"SELECT CONVERT_TZ(NOW(),@@session.time_zone,'%s')", // row[0]
|
||||
BrowserTimeZone))
|
||||
{
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
|
|
|
@ -1438,7 +1438,7 @@ 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"
|
||||
"SELECT ShortName" // row[0]
|
||||
" FROM deg_degrees"
|
||||
" WHERE DegCod=%ld",
|
||||
Deg->DegCod) == 1)
|
||||
|
@ -1459,29 +1459,16 @@ void Deg_GetShortNameOfDegreeByCod (struct Deg_Degree *Deg)
|
|||
|
||||
long Deg_GetCtrCodOfDegreeByCod (long DegCod)
|
||||
{
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
long CtrCod = -1L;
|
||||
/***** Trivial check: degree code should be > 0 *****/
|
||||
if (DegCod <= 0)
|
||||
return -1L;
|
||||
|
||||
if (DegCod > 0)
|
||||
{
|
||||
/***** 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",
|
||||
DegCod) == 1)
|
||||
{
|
||||
/***** Get the center code of this degree *****/
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
CtrCod = Str_ConvertStrCodToLongCod (row[0]);
|
||||
}
|
||||
|
||||
/***** Free structure that stores the query result *****/
|
||||
DB_FreeMySQLResult (&mysql_res);
|
||||
}
|
||||
|
||||
return CtrCod;
|
||||
/***** Get the center code of a degree from database *****/
|
||||
return DB_QuerySELECTCode ("can not get the center of a degree",
|
||||
"SELECT CtrCod"
|
||||
" FROM deg_degrees"
|
||||
" WHERE DegCod=%ld",
|
||||
DegCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -1490,31 +1477,18 @@ long Deg_GetCtrCodOfDegreeByCod (long DegCod)
|
|||
|
||||
long Deg_GetInsCodOfDegreeByCod (long DegCod)
|
||||
{
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
long InsCod = -1L;
|
||||
/***** Trivial check: degree code should be > 0 *****/
|
||||
if (DegCod <= 0)
|
||||
return -1L;
|
||||
|
||||
if (DegCod > 0)
|
||||
{
|
||||
/***** Get the institution code of a degree from database *****/
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get the institution of a degree",
|
||||
"SELECT ctr_centers.InsCod"
|
||||
" FROM deg_degrees,"
|
||||
"ctr_centers"
|
||||
" WHERE deg_degrees.DegCod=%ld"
|
||||
" AND deg_degrees.CtrCod=ctr_centers.CtrCod",
|
||||
DegCod) == 1)
|
||||
{
|
||||
/***** Get the institution code of this degree *****/
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
InsCod = Str_ConvertStrCodToLongCod (row[0]);
|
||||
}
|
||||
|
||||
/***** Free structure that stores the query result *****/
|
||||
DB_FreeMySQLResult (&mysql_res);
|
||||
}
|
||||
|
||||
return InsCod;
|
||||
/***** Get the institution code of a degree from database *****/
|
||||
return DB_QuerySELECTCode ("can not get the institution of a degree",
|
||||
"SELECT ctr_centers.InsCod"
|
||||
" FROM deg_degrees,"
|
||||
"ctr_centers"
|
||||
" WHERE deg_degrees.DegCod=%ld"
|
||||
" AND deg_degrees.CtrCod=ctr_centers.CtrCod",
|
||||
DegCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -1524,7 +1498,6 @@ long Deg_GetInsCodOfDegreeByCod (long DegCod)
|
|||
void Deg_RemoveDegreeCompletely (long DegCod)
|
||||
{
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
unsigned long NumRows;
|
||||
unsigned long NumRow;
|
||||
long CrsCod;
|
||||
|
@ -1532,7 +1505,7 @@ void Deg_RemoveDegreeCompletely (long DegCod)
|
|||
|
||||
/***** Get courses of a degree from database *****/
|
||||
NumRows = DB_QuerySELECT (&mysql_res,"can not get courses of a degree",
|
||||
"SELECT CrsCod"
|
||||
"SELECT CrsCod" // row[0]
|
||||
" FROM crs_courses"
|
||||
" WHERE DegCod=%ld",
|
||||
DegCod);
|
||||
|
@ -1543,10 +1516,7 @@ void Deg_RemoveDegreeCompletely (long DegCod)
|
|||
NumRow++)
|
||||
{
|
||||
/* Get next course */
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
|
||||
/* Get course code (row[0]) */
|
||||
if ((CrsCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
|
||||
if ((CrsCod = DB_GetNextCode (mysql_res)) < 0)
|
||||
Lay_ShowErrorAndExit ("Wrong code of course.");
|
||||
|
||||
/* Remove course */
|
||||
|
|
|
@ -882,7 +882,7 @@ 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"
|
||||
"SELECT DegTypName" // row[0]
|
||||
" FROM deg_types"
|
||||
" WHERE DegTypCod=%ld",
|
||||
DegTyp->DegTypCod);
|
||||
|
@ -923,14 +923,13 @@ bool DT_GetDataOfDegreeTypeByCod (struct DegreeType *DegTyp)
|
|||
static void DT_RemoveDegreeTypeCompletely (long DegTypCod)
|
||||
{
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
unsigned long NumRows;
|
||||
unsigned long NumRow;
|
||||
long DegCod;
|
||||
|
||||
/***** Get degrees of a type from database *****/
|
||||
NumRows = DB_QuerySELECT (&mysql_res,"can not get degrees of a type",
|
||||
"SELECT DegCod"
|
||||
"SELECT DegCod" // row[0]
|
||||
" FROM deg_degrees"
|
||||
" WHERE DegTypCod=%ld",
|
||||
DegTypCod);
|
||||
|
@ -941,10 +940,7 @@ static void DT_RemoveDegreeTypeCompletely (long DegTypCod)
|
|||
NumRow++)
|
||||
{
|
||||
/* Get next degree */
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
|
||||
/* Get degree code (row[0]) */
|
||||
if ((DegCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
|
||||
if ((DegCod = DB_GetNextCode (mysql_res)) < 0)
|
||||
Lay_ShowErrorAndExit ("Wrong code of degree.");
|
||||
|
||||
/* Remove degree */
|
||||
|
@ -956,7 +952,8 @@ static void DT_RemoveDegreeTypeCompletely (long DegTypCod)
|
|||
|
||||
/***** Remove the degree type *****/
|
||||
DB_QueryDELETE ("can not remove a type of degree",
|
||||
"DELETE FROM deg_types WHERE DegTypCod=%ld",
|
||||
"DELETE FROM deg_types"
|
||||
" WHERE DegTypCod=%ld",
|
||||
DegTypCod);
|
||||
}
|
||||
|
||||
|
|
|
@ -146,9 +146,9 @@ void Dup_ListDuplicateUsrs (void)
|
|||
/***** 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"
|
||||
"SELECT UsrCod," // row[0]
|
||||
"COUNT(*) AS N," // row[1]
|
||||
"UNIX_TIMESTAMP(MIN(InformTime)) AS T" // row[2]
|
||||
" FROM usr_duplicated"
|
||||
" GROUP BY UsrCod"
|
||||
" ORDER BY N DESC,"
|
||||
|
@ -263,7 +263,6 @@ static void Dup_ListSimilarUsrs (void)
|
|||
extern const char *Txt_Similar_users;
|
||||
struct UsrData UsrDat;
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
unsigned NumUsrs;
|
||||
unsigned NumUsr;
|
||||
|
||||
|
@ -325,10 +324,8 @@ static void Dup_ListSimilarUsrs (void)
|
|||
NumUsr < NumUsrs;
|
||||
NumUsr++)
|
||||
{
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
|
||||
/* Get user code (row[0]) */
|
||||
UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0]);
|
||||
/* Get user code */
|
||||
UsrDat.UsrCod = DB_GetNextCode (mysql_res);
|
||||
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS))
|
||||
{
|
||||
/* Get if user has accepted all his/her courses */
|
||||
|
|
|
@ -515,9 +515,8 @@ void Enr_GetNotifEnrolment (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
|
|||
SummaryStr[0] = '\0'; // Return nothing on error
|
||||
|
||||
/***** Get user's role in course from database *****/
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get user's role"
|
||||
" in course",
|
||||
"SELECT Role"
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get user's role in course",
|
||||
"SELECT Role" // row[0]
|
||||
" FROM crs_users"
|
||||
" WHERE CrsCod=%ld"
|
||||
" AND UsrCod=%ld",
|
||||
|
@ -866,7 +865,6 @@ void Enr_RemoveOldUsrs (void)
|
|||
unsigned MonthsWithoutAccess;
|
||||
time_t SecondsWithoutAccess;
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
unsigned long NumUsr;
|
||||
unsigned long NumUsrs;
|
||||
unsigned NumUsrsEliminated = 0;
|
||||
|
@ -884,14 +882,17 @@ void Enr_RemoveOldUsrs (void)
|
|||
|
||||
/***** Get old users from database *****/
|
||||
NumUsrs = DB_QuerySELECT (&mysql_res,"can not get old users",
|
||||
"SELECT UsrCod FROM"
|
||||
"("
|
||||
"SELECT UsrCod FROM usr_last WHERE"
|
||||
" LastTime<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)"
|
||||
" UNION "
|
||||
"SELECT UsrCod FROM usr_data WHERE"
|
||||
" UsrCod NOT IN (SELECT UsrCod FROM usr_last)"
|
||||
") AS candidate_usrs"
|
||||
"SELECT UsrCod"
|
||||
" FROM (SELECT UsrCod"
|
||||
" FROM usr_last"
|
||||
" WHERE LastTime<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)"
|
||||
" UNION "
|
||||
"SELECT UsrCod"
|
||||
" FROM usr_data"
|
||||
" WHERE UsrCod NOT IN"
|
||||
" (SELECT UsrCod"
|
||||
" FROM usr_last)"
|
||||
") AS candidate_usrs"
|
||||
" WHERE UsrCod NOT IN"
|
||||
" (SELECT DISTINCT UsrCod"
|
||||
" FROM crs_users)",
|
||||
|
@ -911,8 +912,7 @@ void Enr_RemoveOldUsrs (void)
|
|||
NumUsr < NumUsrs;
|
||||
NumUsr++)
|
||||
{
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0]);
|
||||
UsrDat.UsrCod = DB_GetNextCode (mysql_res);
|
||||
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS)) // If user's data exist...
|
||||
{
|
||||
Acc_CompletelyEliminateAccount (&UsrDat,Cns_QUIET);
|
||||
|
@ -1973,8 +1973,6 @@ void Enr_SignUpInCrs (void)
|
|||
extern const char *Txt_You_were_already_enroled_as_X_in_the_course_Y;
|
||||
extern const char *Txt_ROLES_SINGUL_abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
|
||||
extern const char *Txt_Your_request_for_enrolment_as_X_in_the_course_Y_has_been_accepted_for_processing;
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
Rol_Role_t RoleFromForm;
|
||||
bool Notify;
|
||||
long ReqCod = -1L;
|
||||
|
@ -2000,20 +1998,13 @@ void Enr_SignUpInCrs (void)
|
|||
Rol_WrongRoleExit ();
|
||||
|
||||
/***** Try to get and old request of the same user in the same course from database *****/
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get enrolment request",
|
||||
"SELECT ReqCod"
|
||||
" FROM crs_requests"
|
||||
" WHERE CrsCod=%ld"
|
||||
" AND UsrCod=%ld",
|
||||
Gbl.Hierarchy.Crs.CrsCod,
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod))
|
||||
{
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
/* Get request code (row[0]) */
|
||||
ReqCod = Str_ConvertStrCodToLongCod (row[0]);
|
||||
}
|
||||
/* Free structure that stores the query result */
|
||||
DB_FreeMySQLResult (&mysql_res);
|
||||
ReqCod = DB_QuerySELECTCode ("can not get enrolment request",
|
||||
"SELECT ReqCod"
|
||||
" FROM crs_requests"
|
||||
" WHERE CrsCod=%ld"
|
||||
" AND UsrCod=%ld",
|
||||
Gbl.Hierarchy.Crs.CrsCod,
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||
|
||||
/***** Request user in current course in database *****/
|
||||
if (ReqCod > 0) // Old request exists in database
|
||||
|
@ -3049,29 +3040,21 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
|
|||
|
||||
static void Enr_RemoveEnrolmentRequest (long CrsCod,long UsrCod)
|
||||
{
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
long ReqCod;
|
||||
|
||||
/***** Mark possible notifications as removed
|
||||
Important: do this before removing the request *****/
|
||||
/* Request request code (returns 0 or 1 rows) */
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get request code",
|
||||
"SELECT ReqCod"
|
||||
" FROM crs_requests"
|
||||
" WHERE CrsCod=%ld"
|
||||
" AND UsrCod=%ld",
|
||||
CrsCod,UsrCod)) // Request exists
|
||||
{
|
||||
/* Get request code */
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
ReqCod = Str_ConvertStrCodToLongCod (row[0]);
|
||||
ReqCod = DB_QuerySELECTCode ("can not get request code",
|
||||
"SELECT ReqCod"
|
||||
" FROM crs_requests"
|
||||
" WHERE CrsCod=%ld"
|
||||
" AND UsrCod=%ld",
|
||||
CrsCod,
|
||||
UsrCod);
|
||||
|
||||
/* Mark possible notifications as removed */
|
||||
Ntf_MarkNotifAsRemoved (Ntf_EVENT_ENROLMENT_REQUEST,ReqCod);
|
||||
}
|
||||
/* Free structure that stores the query result */
|
||||
DB_FreeMySQLResult (&mysql_res);
|
||||
/* Mark possible notifications as removed */
|
||||
Ntf_MarkNotifAsRemoved (Ntf_EVENT_ENROLMENT_REQUEST,ReqCod);
|
||||
|
||||
/***** Remove enrolment request *****/
|
||||
DB_QueryDELETE ("can not remove a request for enrolment",
|
||||
|
|
313
swad_exam.c
313
swad_exam.c
|
@ -1774,12 +1774,14 @@ long Exa_GetQstCodFromQstInd (long ExaCod,unsigned QstInd)
|
|||
long QstCod;
|
||||
|
||||
/***** 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",
|
||||
ExaCod,QstInd))
|
||||
QstCod = DB_QuerySELECTCode ("can not get question code",
|
||||
"SELECT QstCod"
|
||||
" FROM exa_set_questions"
|
||||
" WHERE ExaCod=%ld"
|
||||
" AND QstInd=%u",
|
||||
ExaCod,
|
||||
QstInd);
|
||||
if (QstCod <= 0)
|
||||
Lay_ShowErrorAndExit ("Error: wrong question index.");
|
||||
|
||||
/***** Get question code (row[0]) *****/
|
||||
|
@ -1809,7 +1811,7 @@ 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)"
|
||||
"SELECT MAX(QstInd)" // row[0]
|
||||
" FROM exa_set_questions"
|
||||
" WHERE ExaCod=%ld"
|
||||
" AND QstInd<%u",
|
||||
|
@ -1846,7 +1848,7 @@ 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)"
|
||||
"SELECT MIN(QstInd)" // row[0]
|
||||
" FROM exa_set_questions"
|
||||
" WHERE ExaCod=%ld"
|
||||
" AND QstInd>%u",
|
||||
|
@ -1899,87 +1901,67 @@ bool Exa_CheckIfEditable (const struct Exa_Exam *Exam)
|
|||
|
||||
unsigned Exa_GetNumCoursesWithExams (Hie_Lvl_Level_t Scope)
|
||||
{
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
unsigned NumCourses;
|
||||
|
||||
/***** Get number of courses with exams from database *****/
|
||||
switch (Scope)
|
||||
{
|
||||
case Hie_Lvl_SYS:
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of courses with exams",
|
||||
"SELECT COUNT(DISTINCT CrsCod)"
|
||||
" FROM exa_exams");
|
||||
break;
|
||||
return DB_QueryCOUNT ("can not get number of courses with exams",
|
||||
"SELECT COUNT(DISTINCT CrsCod)"
|
||||
" FROM exa_exams");
|
||||
case Hie_Lvl_CTY:
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of courses with exams",
|
||||
"SELECT COUNT(DISTINCT exa_exams.CrsCod)"
|
||||
" FROM ins_instits,"
|
||||
"ctr_centers,"
|
||||
"deg_degrees,"
|
||||
"crs_courses,"
|
||||
"exa_exams"
|
||||
" WHERE ins_instits.CtyCod=%ld"
|
||||
" AND ins_instits.InsCod=ctr_centers.InsCod"
|
||||
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
|
||||
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
||||
" AND crs_courses.CrsCod=exa_exams.CrsCod",
|
||||
Gbl.Hierarchy.Ins.InsCod);
|
||||
break;
|
||||
return DB_QueryCOUNT ("can not get number of courses with exams",
|
||||
"SELECT COUNT(DISTINCT exa_exams.CrsCod)"
|
||||
" FROM ins_instits,"
|
||||
"ctr_centers,"
|
||||
"deg_degrees,"
|
||||
"crs_courses,"
|
||||
"exa_exams"
|
||||
" WHERE ins_instits.CtyCod=%ld"
|
||||
" AND ins_instits.InsCod=ctr_centers.InsCod"
|
||||
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
|
||||
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
||||
" AND crs_courses.CrsCod=exa_exams.CrsCod",
|
||||
Gbl.Hierarchy.Ins.InsCod);
|
||||
case Hie_Lvl_INS:
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of courses with exams",
|
||||
"SELECT COUNT(DISTINCT exa_exams.CrsCod)"
|
||||
" FROM ctr_centers,"
|
||||
"deg_degrees,"
|
||||
"crs_courses,"
|
||||
"exa_exams"
|
||||
" WHERE ctr_centers.InsCod=%ld"
|
||||
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
|
||||
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
||||
" AND crs_courses.CrsCod=exa_exams.CrsCod",
|
||||
Gbl.Hierarchy.Ins.InsCod);
|
||||
break;
|
||||
return DB_QueryCOUNT ("can not get number of courses with exams",
|
||||
"SELECT COUNT(DISTINCT exa_exams.CrsCod)"
|
||||
" FROM ctr_centers,"
|
||||
"deg_degrees,"
|
||||
"crs_courses,"
|
||||
"exa_exams"
|
||||
" WHERE ctr_centers.InsCod=%ld"
|
||||
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
|
||||
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
||||
" AND crs_courses.CrsCod=exa_exams.CrsCod",
|
||||
Gbl.Hierarchy.Ins.InsCod);
|
||||
case Hie_Lvl_CTR:
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of courses with exams",
|
||||
"SELECT COUNT(DISTINCT exa_exams.CrsCod)"
|
||||
" FROM deg_degrees,"
|
||||
"crs_courses,"
|
||||
"exa_exams"
|
||||
" WHERE deg_degrees.CtrCod=%ld"
|
||||
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
||||
" AND crs_courses.CrsCod=exa_exams.CrsCod",
|
||||
Gbl.Hierarchy.Ctr.CtrCod);
|
||||
break;
|
||||
return DB_QueryCOUNT ("can not get number of courses with exams",
|
||||
"SELECT COUNT(DISTINCT exa_exams.CrsCod)"
|
||||
" FROM deg_degrees,"
|
||||
"crs_courses,"
|
||||
"exa_exams"
|
||||
" WHERE deg_degrees.CtrCod=%ld"
|
||||
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
||||
" AND crs_courses.CrsCod=exa_exams.CrsCod",
|
||||
Gbl.Hierarchy.Ctr.CtrCod);
|
||||
case Hie_Lvl_DEG:
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of courses with exams",
|
||||
"SELECT COUNT(DISTINCT exa_exams.CrsCod)"
|
||||
" FROM crs_courses,"
|
||||
"exa_exams"
|
||||
" WHERE crs_courses.DegCod=%ld"
|
||||
" AND crs_courses.CrsCod=exa_exams.CrsCod",
|
||||
Gbl.Hierarchy.Deg.DegCod);
|
||||
break;
|
||||
return DB_QueryCOUNT ("can not get number of courses with exams",
|
||||
"SELECT COUNT(DISTINCT exa_exams.CrsCod)"
|
||||
" FROM crs_courses,"
|
||||
"exa_exams"
|
||||
" WHERE crs_courses.DegCod=%ld"
|
||||
" AND crs_courses.CrsCod=exa_exams.CrsCod",
|
||||
Gbl.Hierarchy.Deg.DegCod);
|
||||
case Hie_Lvl_CRS:
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of courses with exams",
|
||||
"SELECT COUNT(DISTINCT CrsCod)"
|
||||
" FROM exa_exams"
|
||||
" WHERE CrsCod=%ld",
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
break;
|
||||
return DB_QueryCOUNT ("can not get number of courses with exams",
|
||||
"SELECT COUNT(DISTINCT CrsCod)"
|
||||
" FROM exa_exams"
|
||||
" WHERE CrsCod=%ld",
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
default:
|
||||
Lay_WrongScopeExit ();
|
||||
break;
|
||||
return 0; // Not reached
|
||||
}
|
||||
|
||||
/***** Get number of exams *****/
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
if (sscanf (row[0],"%u",&NumCourses) != 1)
|
||||
Lay_ShowErrorAndExit ("Error when getting number of courses with exams.");
|
||||
|
||||
/***** Free structure that stores the query result *****/
|
||||
DB_FreeMySQLResult (&mysql_res);
|
||||
|
||||
return NumCourses;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -1989,87 +1971,67 @@ unsigned Exa_GetNumCoursesWithExams (Hie_Lvl_Level_t Scope)
|
|||
|
||||
unsigned Exa_GetNumExams (Hie_Lvl_Level_t Scope)
|
||||
{
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
unsigned NumExams;
|
||||
|
||||
/***** Get number of exams from database *****/
|
||||
switch (Scope)
|
||||
{
|
||||
case Hie_Lvl_SYS:
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of exams",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM exa_exams");
|
||||
break;
|
||||
return DB_QueryCOUNT ("can not get number of exams",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM exa_exams");
|
||||
case Hie_Lvl_CTY:
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of exams",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM ins_instits,"
|
||||
"ctr_centers,"
|
||||
"deg_degrees,"
|
||||
"crs_courses,"
|
||||
"exa_exams"
|
||||
" WHERE ins_instits.CtyCod=%ld"
|
||||
" AND ins_instits.InsCod=ctr_centers.InsCod"
|
||||
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
|
||||
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
||||
" AND crs_courses.CrsCod=exa_exams.CrsCod",
|
||||
Gbl.Hierarchy.Cty.CtyCod);
|
||||
break;
|
||||
return DB_QueryCOUNT ("can not get number of exams",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM ins_instits,"
|
||||
"ctr_centers,"
|
||||
"deg_degrees,"
|
||||
"crs_courses,"
|
||||
"exa_exams"
|
||||
" WHERE ins_instits.CtyCod=%ld"
|
||||
" AND ins_instits.InsCod=ctr_centers.InsCod"
|
||||
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
|
||||
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
||||
" AND crs_courses.CrsCod=exa_exams.CrsCod",
|
||||
Gbl.Hierarchy.Cty.CtyCod);
|
||||
case Hie_Lvl_INS:
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of exams",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM ctr_centers,"
|
||||
"deg_degrees,"
|
||||
"crs_courses,"
|
||||
"exa_exams"
|
||||
" WHERE ctr_centers.InsCod=%ld"
|
||||
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
|
||||
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
||||
" AND crs_courses.CrsCod=exa_exams.CrsCod",
|
||||
Gbl.Hierarchy.Ins.InsCod);
|
||||
break;
|
||||
return DB_QueryCOUNT ("can not get number of exams",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM ctr_centers,"
|
||||
"deg_degrees,"
|
||||
"crs_courses,"
|
||||
"exa_exams"
|
||||
" WHERE ctr_centers.InsCod=%ld"
|
||||
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
|
||||
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
||||
" AND crs_courses.CrsCod=exa_exams.CrsCod",
|
||||
Gbl.Hierarchy.Ins.InsCod);
|
||||
case Hie_Lvl_CTR:
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of exams",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM deg_degrees,"
|
||||
"crs_courses,"
|
||||
"exa_exams"
|
||||
" WHERE deg_degrees.CtrCod=%ld"
|
||||
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
||||
" AND crs_courses.CrsCod=exa_exams.CrsCod",
|
||||
Gbl.Hierarchy.Ctr.CtrCod);
|
||||
break;
|
||||
return DB_QueryCOUNT ("can not get number of exams",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM deg_degrees,"
|
||||
"crs_courses,"
|
||||
"exa_exams"
|
||||
" WHERE deg_degrees.CtrCod=%ld"
|
||||
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
||||
" AND crs_courses.CrsCod=exa_exams.CrsCod",
|
||||
Gbl.Hierarchy.Ctr.CtrCod);
|
||||
case Hie_Lvl_DEG:
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of exams",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM crs_courses,"
|
||||
"exa_exams"
|
||||
" WHERE crs_courses.DegCod=%ld"
|
||||
" AND crs_courses.CrsCod=exa_exams.CrsCod",
|
||||
Gbl.Hierarchy.Deg.DegCod);
|
||||
break;
|
||||
return DB_QueryCOUNT ("can not get number of exams",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM crs_courses,"
|
||||
"exa_exams"
|
||||
" WHERE crs_courses.DegCod=%ld"
|
||||
" AND crs_courses.CrsCod=exa_exams.CrsCod",
|
||||
Gbl.Hierarchy.Deg.DegCod);
|
||||
case Hie_Lvl_CRS:
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of exams",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM exa_exams"
|
||||
" WHERE CrsCod=%ld",
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
break;
|
||||
return DB_QueryCOUNT ("can not get number of exams",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM exa_exams"
|
||||
" WHERE CrsCod=%ld",
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
default:
|
||||
Lay_WrongScopeExit ();
|
||||
break;
|
||||
return 0; // Not reached
|
||||
}
|
||||
|
||||
/***** Get number of exams *****/
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
if (sscanf (row[0],"%u",&NumExams) != 1)
|
||||
Lay_ShowErrorAndExit ("Error when getting number of exams.");
|
||||
|
||||
/***** Free structure that stores the query result *****/
|
||||
DB_FreeMySQLResult (&mysql_res);
|
||||
|
||||
return NumExams;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -2087,7 +2049,7 @@ 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)"
|
||||
"SELECT AVG(NumQsts)" // row[0]
|
||||
" FROM (SELECT COUNT(exa_set_questions.QstCod) AS NumQsts"
|
||||
" FROM exa_exams,"
|
||||
"exa_set_questions"
|
||||
|
@ -2096,7 +2058,7 @@ double Exa_GetNumQstsPerCrsExam (Hie_Lvl_Level_t Scope)
|
|||
break;
|
||||
case Hie_Lvl_CTY:
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of questions per exam",
|
||||
"SELECT AVG(NumQsts)"
|
||||
"SELECT AVG(NumQsts)" // row[0]
|
||||
" FROM (SELECT COUNT(exa_set_questions.QstCod) AS NumQsts"
|
||||
" FROM ins_instits,"
|
||||
"ctr_centers,"
|
||||
|
@ -2115,7 +2077,7 @@ 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)"
|
||||
"SELECT AVG(NumQsts)" // row[0]
|
||||
" FROM (SELECT COUNT(exa_set_questions.QstCod) AS NumQsts"
|
||||
" FROM ctr_centers,"
|
||||
"deg_degrees,"
|
||||
|
@ -2132,7 +2094,7 @@ 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)"
|
||||
"SELECT AVG(NumQsts)" // row[0]
|
||||
" FROM (SELECT COUNT(exa_set_questions.QstCod) AS NumQsts"
|
||||
" FROM deg_degrees,"
|
||||
"crs_courses,"
|
||||
|
@ -2147,7 +2109,7 @@ 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)"
|
||||
"SELECT AVG(NumQsts)" // row[0]
|
||||
" FROM (SELECT COUNT(exa_set_questions.QstCod) AS NumQsts"
|
||||
" FROM crs_courses,"
|
||||
"exa_exams,"
|
||||
|
@ -2160,7 +2122,7 @@ 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)"
|
||||
"SELECT AVG(NumQsts)" // row[0]
|
||||
" FROM (SELECT COUNT(exa_set_questions.QstCod) AS NumQsts"
|
||||
" FROM exa_exams,"
|
||||
"exa_set_questions"
|
||||
|
@ -2190,39 +2152,22 @@ double Exa_GetNumQstsPerCrsExam (Hie_Lvl_Level_t Scope)
|
|||
|
||||
void Exa_GetScoreRange (long ExaCod,double *MinScore,double *MaxScore)
|
||||
{
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
unsigned NumRows;
|
||||
unsigned NumRow;
|
||||
unsigned NumAnswers;
|
||||
|
||||
/***** Get maximum score of an exam from database *****/
|
||||
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"
|
||||
" WHERE exa_set_questions.ExaCod=%ld"
|
||||
" AND exa_set_questions.QstCod=tst_answers.QstCod"
|
||||
" GROUP BY tst_answers.QstCod",
|
||||
ExaCod);
|
||||
for (NumRow = 0, *MinScore = *MaxScore = 0.0;
|
||||
NumRow < NumRows;
|
||||
NumRow++)
|
||||
{
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
/***** Get number of answers of exam from database *****/
|
||||
NumAnswers = DB_QueryCOUNT ("can not get data of a question",
|
||||
"SELECT COUNT(tst_answers.AnsInd)"
|
||||
" 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",
|
||||
ExaCod);
|
||||
if (NumAnswers < 2)
|
||||
Lay_ShowErrorAndExit ("Wrong number of answers.");
|
||||
|
||||
/* Get min answers (row[0]) */
|
||||
if (sscanf (row[0],"%u",&NumAnswers) != 1)
|
||||
NumAnswers = 0;
|
||||
|
||||
/* Accumulate minimum and maximum score */
|
||||
if (NumAnswers < 2)
|
||||
Lay_ShowErrorAndExit ("Wrong number of answers.");
|
||||
*MinScore += -1.0 / (double) (NumAnswers - 1);
|
||||
*MaxScore += 1.0;
|
||||
}
|
||||
|
||||
/***** Free structure that stores the query result *****/
|
||||
DB_FreeMySQLResult (&mysql_res);
|
||||
/***** Set minimum and maximum scores *****/
|
||||
*MinScore = *MaxScore = 0.0;
|
||||
*MinScore += -1.0 / (double) (NumAnswers - 1);
|
||||
*MaxScore += 1.0;
|
||||
}
|
||||
|
|
|
@ -307,22 +307,22 @@ void ExaLog_ShowExamLog (const struct ExaPrn_Print *Print)
|
|||
|
||||
/***** Get print log from database *****/
|
||||
NumClicks = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get exam print log",
|
||||
"SELECT exa_log.ActCod," // row[0]
|
||||
"exa_log.QstInd," // row[1]
|
||||
"exa_log.CanAnswer," // row[2]
|
||||
"UNIX_TIMESTAMP(exa_log.ClickTime)," // row[3]
|
||||
"exa_log.IP," // row[4]
|
||||
"exa_log_sessions.SessionId," // row[5]
|
||||
"exa_log_user_agents.UserAgent" // row[6]
|
||||
" FROM exa_log"
|
||||
" LEFT JOIN exa_log_sessions"
|
||||
" ON exa_log.LogCod=exa_log_sessions.LogCod"
|
||||
" LEFT JOIN exa_log_user_agents"
|
||||
" ON exa_log.LogCod=exa_log_user_agents.LogCod"
|
||||
" WHERE exa_log.PrnCod=%ld"
|
||||
" ORDER BY exa_log.LogCod",
|
||||
Print->PrnCod);
|
||||
DB_QuerySELECT (&mysql_res,"can not get exam print log",
|
||||
"SELECT exa_log.ActCod," // row[0]
|
||||
"exa_log.QstInd," // row[1]
|
||||
"exa_log.CanAnswer," // row[2]
|
||||
"UNIX_TIMESTAMP(exa_log.ClickTime)," // row[3]
|
||||
"exa_log.IP," // row[4]
|
||||
"exa_log_sessions.SessionId," // row[5]
|
||||
"exa_log_user_agents.UserAgent" // row[6]
|
||||
" FROM exa_log"
|
||||
" LEFT JOIN exa_log_sessions"
|
||||
" ON exa_log.LogCod=exa_log_sessions.LogCod"
|
||||
" LEFT JOIN exa_log_user_agents"
|
||||
" ON exa_log.LogCod=exa_log_user_agents.LogCod"
|
||||
" WHERE exa_log.PrnCod=%ld"
|
||||
" ORDER BY exa_log.LogCod",
|
||||
Print->PrnCod);
|
||||
|
||||
if (NumClicks)
|
||||
{
|
||||
|
|
|
@ -370,14 +370,14 @@ static void ExaPrn_GetQuestionsForNewPrintFromDB (struct ExaPrn_Print *Print,lon
|
|||
|
||||
/***** Get data of set of questions from database *****/
|
||||
NumSets = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get sets of questions",
|
||||
"SELECT SetCod," // row[0]
|
||||
"NumQstsToPrint," // row[1]
|
||||
"Title" // row[2]
|
||||
" FROM exa_sets"
|
||||
" WHERE ExaCod=%ld"
|
||||
" ORDER BY SetInd",
|
||||
ExaCod);
|
||||
DB_QuerySELECT (&mysql_res,"can not get sets of questions",
|
||||
"SELECT SetCod," // row[0]
|
||||
"NumQstsToPrint," // row[1]
|
||||
"Title" // row[2]
|
||||
" FROM exa_sets"
|
||||
" WHERE ExaCod=%ld"
|
||||
" ORDER BY SetInd",
|
||||
ExaCod);
|
||||
|
||||
/***** Get questions from all sets *****/
|
||||
Print->NumQsts.All = 0;
|
||||
|
@ -436,16 +436,16 @@ static unsigned ExaPrn_GetSomeQstsFromSetToPrint (struct ExaPrn_Print *Print,
|
|||
|
||||
/***** Get questions from database *****/
|
||||
NumQstsInSet = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get questions from set",
|
||||
"SELECT QstCod," // row[0]
|
||||
"AnsType," // row[1]
|
||||
"Shuffle" // row[2]
|
||||
" FROM exa_set_questions"
|
||||
" WHERE SetCod=%ld"
|
||||
" ORDER BY RAND()" // Don't use RAND(NOW()) because the same ordering will be repeated across sets
|
||||
" LIMIT %u",
|
||||
Set->SetCod,
|
||||
Set->NumQstsToPrint);
|
||||
DB_QuerySELECT (&mysql_res,"can not get questions from set",
|
||||
"SELECT QstCod," // row[0]
|
||||
"AnsType," // row[1]
|
||||
"Shuffle" // row[2]
|
||||
" FROM exa_set_questions"
|
||||
" WHERE SetCod=%ld"
|
||||
" ORDER BY RAND()" // Don't use RAND(NOW()) because the same ordering will be repeated across sets
|
||||
" LIMIT %u",
|
||||
Set->SetCod,
|
||||
Set->NumQstsToPrint);
|
||||
|
||||
/***** Questions in this set *****/
|
||||
for (NumQstInSet = 0;
|
||||
|
@ -609,18 +609,17 @@ void ExaPrn_GetPrintQuestionsFromDB (struct ExaPrn_Print *Print)
|
|||
unsigned NumQst;
|
||||
|
||||
/***** Get questions of an exam print from database *****/
|
||||
Print->NumQsts.All =
|
||||
(unsigned) DB_QuerySELECT (&mysql_res,"can not get questions"
|
||||
" of an exam print",
|
||||
"SELECT QstCod," // row[0]
|
||||
"SetCod," // row[1]
|
||||
"Score," // row[2]
|
||||
"Indexes," // row[3]
|
||||
"Answers" // row[4]
|
||||
" FROM exa_print_questions"
|
||||
" WHERE PrnCod=%ld"
|
||||
" ORDER BY QstInd",
|
||||
Print->PrnCod);
|
||||
Print->NumQsts.All = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get questions of an exam print",
|
||||
"SELECT QstCod," // row[0]
|
||||
"SetCod," // row[1]
|
||||
"Score," // row[2]
|
||||
"Indexes," // row[3]
|
||||
"Answers" // row[4]
|
||||
" FROM exa_print_questions"
|
||||
" WHERE PrnCod=%ld"
|
||||
" ORDER BY QstInd",
|
||||
Print->PrnCod);
|
||||
|
||||
/***** Get questions *****/
|
||||
if (Print->NumQsts.All <= ExaPrn_MAX_QUESTIONS_PER_EXAM_PRINT)
|
||||
|
@ -1273,12 +1272,12 @@ static void ExaPrn_GetCorrectIntAnswerFromDB (struct Tst_Question *Question)
|
|||
MYSQL_ROW row;
|
||||
|
||||
/***** Query database *****/
|
||||
Question->Answer.NumOptions =
|
||||
(unsigned) DB_QuerySELECT (&mysql_res,"can not get answers of a question",
|
||||
"SELECT Answer" // row[0]
|
||||
" FROM exa_set_answers"
|
||||
" WHERE QstCod=%ld",
|
||||
Question->QstCod);
|
||||
Question->Answer.NumOptions = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get answers of a question",
|
||||
"SELECT Answer" // row[0]
|
||||
" FROM exa_set_answers"
|
||||
" WHERE QstCod=%ld",
|
||||
Question->QstCod);
|
||||
|
||||
/***** Check if number of rows is correct *****/
|
||||
Tst_CheckIfNumberOfAnswersIsOne (Question);
|
||||
|
@ -1300,12 +1299,12 @@ static void ExaPrn_GetCorrectFltAnswerFromDB (struct Tst_Question *Question)
|
|||
double Tmp;
|
||||
|
||||
/***** Query database *****/
|
||||
Question->Answer.NumOptions =
|
||||
(unsigned) DB_QuerySELECT (&mysql_res,"can not get answers of a question",
|
||||
"SELECT Answer" // row[0]
|
||||
" FROM exa_set_answers"
|
||||
" WHERE QstCod=%ld",
|
||||
Question->QstCod);
|
||||
Question->Answer.NumOptions = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get answers of a question",
|
||||
"SELECT Answer" // row[0]
|
||||
" FROM exa_set_answers"
|
||||
" WHERE QstCod=%ld",
|
||||
Question->QstCod);
|
||||
|
||||
/***** Check if number of rows is correct *****/
|
||||
if (Question->Answer.NumOptions != 2)
|
||||
|
@ -1338,12 +1337,12 @@ static void ExaPrn_GetCorrectTF_AnswerFromDB (struct Tst_Question *Question)
|
|||
MYSQL_ROW row;
|
||||
|
||||
/***** Query database *****/
|
||||
Question->Answer.NumOptions =
|
||||
(unsigned) DB_QuerySELECT (&mysql_res,"can not get answers of a question",
|
||||
"SELECT Answer" // row[0]
|
||||
" FROM exa_set_answers"
|
||||
" WHERE QstCod=%ld",
|
||||
Question->QstCod);
|
||||
Question->Answer.NumOptions = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get answers of a question",
|
||||
"SELECT Answer" // row[0]
|
||||
" FROM exa_set_answers"
|
||||
" WHERE QstCod=%ld",
|
||||
Question->QstCod);
|
||||
|
||||
/***** Check if number of rows is correct *****/
|
||||
Tst_CheckIfNumberOfAnswersIsOne (Question);
|
||||
|
@ -1363,13 +1362,13 @@ static void ExaPrn_GetCorrectChoAnswerFromDB (struct Tst_Question *Question)
|
|||
unsigned NumOpt;
|
||||
|
||||
/***** Query database *****/
|
||||
Question->Answer.NumOptions =
|
||||
(unsigned) DB_QuerySELECT (&mysql_res,"can not get answers of a question",
|
||||
"SELECT Correct" // row[0]
|
||||
" FROM exa_set_answers"
|
||||
" WHERE QstCod=%ld"
|
||||
" ORDER BY AnsInd",
|
||||
Question->QstCod);
|
||||
Question->Answer.NumOptions = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get answers of a question",
|
||||
"SELECT Correct" // row[0]
|
||||
" FROM exa_set_answers"
|
||||
" WHERE QstCod=%ld"
|
||||
" ORDER BY AnsInd",
|
||||
Question->QstCod);
|
||||
for (NumOpt = 0;
|
||||
NumOpt < Question->Answer.NumOptions;
|
||||
NumOpt++)
|
||||
|
@ -1392,12 +1391,12 @@ static void ExaPrn_GetCorrectTxtAnswerFromDB (struct Tst_Question *Question)
|
|||
unsigned NumOpt;
|
||||
|
||||
/***** Query database *****/
|
||||
Question->Answer.NumOptions =
|
||||
(unsigned) DB_QuerySELECT (&mysql_res,"can not get answers of a question",
|
||||
"SELECT Answer" // row[0]
|
||||
" FROM exa_set_answers"
|
||||
" WHERE QstCod=%ld",
|
||||
Question->QstCod);
|
||||
Question->Answer.NumOptions = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get answers of a question",
|
||||
"SELECT Answer" // row[0]
|
||||
" FROM exa_set_answers"
|
||||
" WHERE QstCod=%ld",
|
||||
Question->QstCod);
|
||||
|
||||
/***** Get text and correctness of answers for this question from database (one row per answer) *****/
|
||||
for (NumOpt = 0;
|
||||
|
@ -1436,7 +1435,7 @@ static void ExaPrn_GetAnswerFromDB (struct ExaPrn_Print *Print,long QstCod,
|
|||
|
||||
/***** Get questions of an exam print from database *****/
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get answer in an exam print",
|
||||
"SELECT Answers"
|
||||
"SELECT Answers" // row[0]
|
||||
" FROM exa_print_questions"
|
||||
" WHERE PrnCod=%ld"
|
||||
" AND QstCod=%ld",
|
||||
|
@ -1507,7 +1506,7 @@ static void ExaPrn_ComputeTotalScoreOfPrint (struct ExaPrn_Print *Print)
|
|||
|
||||
/***** Compute total score of exam print *****/
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get score of exam print",
|
||||
"SELECT SUM(Score)"
|
||||
"SELECT SUM(Score)" // row[0]
|
||||
" FROM exa_print_questions"
|
||||
" WHERE PrnCod=%ld",
|
||||
Print->PrnCod))
|
||||
|
|
|
@ -427,7 +427,6 @@ void ExaRes_ShowAllResultsInExa (void)
|
|||
static void ExaRes_ListAllResultsInExa (struct Exa_Exams *Exams,long ExaCod)
|
||||
{
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
unsigned long NumUsrs;
|
||||
unsigned long NumUsr;
|
||||
|
||||
|
@ -450,26 +449,20 @@ static void ExaRes_ListAllResultsInExa (struct Exa_Exams *Exams,long ExaCod)
|
|||
"usr_data.FirstName",
|
||||
ExaCod,
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
if (NumUsrs)
|
||||
{
|
||||
/***** List sessions results for each user *****/
|
||||
for (NumUsr = 0;
|
||||
NumUsr < NumUsrs;
|
||||
NumUsr++)
|
||||
{
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
|
||||
/* Get session code (row[0]) */
|
||||
if ((Gbl.Usrs.Other.UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0])) > 0)
|
||||
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat,Usr_DONT_GET_PREFS))
|
||||
if (Usr_CheckIfICanViewTstExaMchResult (&Gbl.Usrs.Other.UsrDat))
|
||||
{
|
||||
/***** Show sessions results *****/
|
||||
Gbl.Usrs.Other.UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&Gbl.Usrs.Other.UsrDat);
|
||||
ExaRes_ShowResults (Exams,Usr_OTHER,-1L,ExaCod,NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
/***** List sessions results for each user *****/
|
||||
for (NumUsr = 0;
|
||||
NumUsr < NumUsrs;
|
||||
NumUsr++)
|
||||
/* Get session code */
|
||||
if ((Gbl.Usrs.Other.UsrDat.UsrCod = DB_GetNextCode (mysql_res)) > 0)
|
||||
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat,Usr_DONT_GET_PREFS))
|
||||
if (Usr_CheckIfICanViewTstExaMchResult (&Gbl.Usrs.Other.UsrDat))
|
||||
{
|
||||
/***** Show sessions results *****/
|
||||
Gbl.Usrs.Other.UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&Gbl.Usrs.Other.UsrDat);
|
||||
ExaRes_ShowResults (Exams,Usr_OTHER,-1L,ExaCod,NULL);
|
||||
}
|
||||
|
||||
/***** Free structure that stores the query result *****/
|
||||
DB_FreeMySQLResult (&mysql_res);
|
||||
|
@ -523,7 +516,6 @@ void ExaRes_ShowAllResultsInSes (void)
|
|||
static void ExaRes_ListAllResultsInSes (struct Exa_Exams *Exams,long SesCod)
|
||||
{
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
unsigned long NumUsrs;
|
||||
unsigned long NumUsr;
|
||||
|
||||
|
@ -532,7 +524,7 @@ 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"
|
||||
"SELECT users.UsrCod" // row[0]
|
||||
" FROM (SELECT exa_prints.UsrCod AS UsrCod" // row[0]
|
||||
" FROM exa_prints,exa_sessions,exa_exams"
|
||||
" WHERE exa_prints.SesCod=%ld"
|
||||
|
@ -546,26 +538,20 @@ static void ExaRes_ListAllResultsInSes (struct Exa_Exams *Exams,long SesCod)
|
|||
"usr_data.FirstName",
|
||||
SesCod,
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
if (NumUsrs)
|
||||
{
|
||||
/***** List sessions results for each user *****/
|
||||
for (NumUsr = 0;
|
||||
NumUsr < NumUsrs;
|
||||
NumUsr++)
|
||||
{
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
|
||||
/* Get session code (row[0]) */
|
||||
if ((Gbl.Usrs.Other.UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0])) > 0)
|
||||
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat,Usr_DONT_GET_PREFS))
|
||||
if (Usr_CheckIfICanViewTstExaMchResult (&Gbl.Usrs.Other.UsrDat))
|
||||
{
|
||||
/***** Show sessions results *****/
|
||||
Gbl.Usrs.Other.UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&Gbl.Usrs.Other.UsrDat);
|
||||
ExaRes_ShowResults (Exams,Usr_OTHER,SesCod,-1L,NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
/***** List sessions results for each user *****/
|
||||
for (NumUsr = 0;
|
||||
NumUsr < NumUsrs;
|
||||
NumUsr++)
|
||||
/* Get session code (row[0]) */
|
||||
if ((Gbl.Usrs.Other.UsrDat.UsrCod = DB_GetNextCode (mysql_res)) > 0)
|
||||
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat,Usr_DONT_GET_PREFS))
|
||||
if (Usr_CheckIfICanViewTstExaMchResult (&Gbl.Usrs.Other.UsrDat))
|
||||
{
|
||||
/***** Show sessions results *****/
|
||||
Gbl.Usrs.Other.UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&Gbl.Usrs.Other.UsrDat);
|
||||
ExaRes_ShowResults (Exams,Usr_OTHER,SesCod,-1L,NULL);
|
||||
}
|
||||
|
||||
/***** Free structure that stores the query result *****/
|
||||
DB_FreeMySQLResult (&mysql_res);
|
||||
|
@ -814,7 +800,6 @@ static void ExaRes_ShowResults (struct Exa_Exams *Exams,
|
|||
char *HidExaSubQuery;
|
||||
char *ExaSubQuery;
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
struct UsrData *UsrDat;
|
||||
unsigned NumResults;
|
||||
unsigned NumResult;
|
||||
|
@ -955,10 +940,8 @@ static void ExaRes_ShowResults (struct Exa_Exams *Exams,
|
|||
NumResult < NumResults;
|
||||
NumResult++)
|
||||
{
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
|
||||
/* Get print code (row[0]) */
|
||||
if ((Print.PrnCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
|
||||
if ((Print.PrnCod = DB_GetNextCode (mysql_res)) < 0)
|
||||
Lay_ShowErrorAndExit ("Wrong code of exam print.");
|
||||
|
||||
/* Get print data */
|
||||
|
|
|
@ -200,20 +200,20 @@ void ExaSes_ListSessions (struct Exa_Exams *Exams,
|
|||
|
||||
/***** Get data of sessions from database *****/
|
||||
NumSessions = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get sessions",
|
||||
"SELECT SesCod," // row[0]
|
||||
"ExaCod," // 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]
|
||||
"Title," // row[7]
|
||||
"ShowUsrResults" // row[8]
|
||||
" FROM exa_sessions"
|
||||
" WHERE ExaCod=%ld%s%s"
|
||||
" ORDER BY SesCod",
|
||||
Exam->ExaCod,HiddenSubQuery,GroupsSubQuery);
|
||||
DB_QuerySELECT (&mysql_res,"can not get sessions",
|
||||
"SELECT SesCod," // row[0]
|
||||
"ExaCod," // 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]
|
||||
"Title," // row[7]
|
||||
"ShowUsrResults" // row[8]
|
||||
" FROM exa_sessions"
|
||||
" WHERE ExaCod=%ld%s%s"
|
||||
" ORDER BY SesCod",
|
||||
Exam->ExaCod,HiddenSubQuery,GroupsSubQuery);
|
||||
|
||||
/***** Free allocated memory for subqueries *****/
|
||||
free (GroupsSubQuery);
|
||||
|
@ -303,24 +303,24 @@ void ExaSes_GetDataOfSessionByCod (struct ExaSes_Session *Session)
|
|||
|
||||
/***** Get exam data session from database *****/
|
||||
NumRows = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get sessions",
|
||||
"SELECT SesCod," // row[0]
|
||||
"ExaCod," // 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]
|
||||
"Title," // row[7]
|
||||
"ShowUsrResults" // row[8]
|
||||
" FROM exa_sessions"
|
||||
" WHERE SesCod=%ld"
|
||||
" AND ExaCod IN" // Extra check
|
||||
" (SELECT ExaCod"
|
||||
" FROM exa_exams"
|
||||
" WHERE CrsCod='%ld')",
|
||||
Session->SesCod,
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
DB_QuerySELECT (&mysql_res,"can not get sessions",
|
||||
"SELECT SesCod," // row[0]
|
||||
"ExaCod," // 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]
|
||||
"Title," // row[7]
|
||||
"ShowUsrResults" // row[8]
|
||||
" FROM exa_sessions"
|
||||
" WHERE SesCod=%ld"
|
||||
" AND ExaCod IN" // Extra check
|
||||
" (SELECT ExaCod"
|
||||
" FROM exa_exams"
|
||||
" WHERE CrsCod='%ld')",
|
||||
Session->SesCod,
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
if (NumRows) // Session found...
|
||||
/* Get exam session data from row */
|
||||
ExaSes_GetSessionDataFromRow (mysql_res,Session);
|
||||
|
|
|
@ -646,7 +646,7 @@ 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)"
|
||||
"SELECT SUM(NumQstsToPrint)" // row[0]
|
||||
" FROM exa_sets"
|
||||
" WHERE ExaCod=%ld",
|
||||
ExaCod))
|
||||
|
@ -790,7 +790,7 @@ 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"
|
||||
"SELECT SetInd" // row[0]
|
||||
" FROM exa_sets"
|
||||
" WHERE SetCod=%u"
|
||||
" AND ExaCod=%ld", // Extra check
|
||||
|
@ -813,27 +813,19 @@ static unsigned ExaSet_GetSetIndFromSetCod (long ExaCod,long SetCod)
|
|||
|
||||
static long ExaSet_GetSetCodFromSetInd (long ExaCod,unsigned SetInd)
|
||||
{
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
long SetCod;
|
||||
|
||||
/***** 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",
|
||||
ExaCod,SetInd))
|
||||
SetCod = DB_QuerySELECTCode ("can not get set code",
|
||||
"SELECT SetCod"
|
||||
" FROM exa_sets"
|
||||
" WHERE ExaCod=%ld"
|
||||
" AND SetInd=%u",
|
||||
ExaCod,
|
||||
SetInd);
|
||||
if (SetCod <= 0)
|
||||
Lay_ShowErrorAndExit ("Error: wrong set index.");
|
||||
|
||||
/***** Get set code (row[0]) *****/
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
if ((SetCod = Str_ConvertStrCodToLongCod (row[0])) <= 0)
|
||||
Lay_ShowErrorAndExit ("Error: wrong set code.");
|
||||
|
||||
/***** Free structure that stores the query result *****/
|
||||
DB_FreeMySQLResult (&mysql_res);
|
||||
|
||||
return SetCod;
|
||||
}
|
||||
|
||||
|
@ -851,7 +843,7 @@ static unsigned ExaSet_GetMaxSetIndexInExam (long ExaCod)
|
|||
|
||||
/***** Get maximum set index in an exam from database *****/
|
||||
DB_QuerySELECT (&mysql_res,"can not get max set index",
|
||||
"SELECT MAX(SetInd)"
|
||||
"SELECT MAX(SetInd)" // row[0]
|
||||
" FROM exa_sets"
|
||||
" WHERE ExaCod=%ld",
|
||||
ExaCod);
|
||||
|
@ -882,7 +874,7 @@ 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)"
|
||||
"SELECT MAX(SetInd)" // row[0]
|
||||
" FROM exa_sets"
|
||||
" WHERE ExaCod=%ld"
|
||||
" AND SetInd<%u",
|
||||
|
@ -918,7 +910,7 @@ 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)"
|
||||
"SELECT MIN(SetInd)" // row[0]
|
||||
" FROM exa_sets"
|
||||
" WHERE ExaCod=%ld"
|
||||
" AND SetInd>%u",
|
||||
|
@ -958,15 +950,15 @@ void ExaSet_ListExamSets (struct Exa_Exams *Exams,
|
|||
|
||||
/***** Get data of set of questions from database *****/
|
||||
NumSets = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get sets of questions",
|
||||
"SELECT SetCod," // row[0]
|
||||
"SetInd," // row[1]
|
||||
"NumQstsToPrint," // row[2]
|
||||
"Title" // row[3]
|
||||
" FROM exa_sets"
|
||||
" WHERE ExaCod=%ld"
|
||||
" ORDER BY SetInd",
|
||||
Exam->ExaCod);
|
||||
DB_QuerySELECT (&mysql_res,"can not get sets of questions",
|
||||
"SELECT SetCod," // row[0]
|
||||
"SetInd," // row[1]
|
||||
"NumQstsToPrint," // row[2]
|
||||
"Title" // row[3]
|
||||
" FROM exa_sets"
|
||||
" WHERE ExaCod=%ld"
|
||||
" ORDER BY SetInd",
|
||||
Exam->ExaCod);
|
||||
|
||||
/***** Begin box *****/
|
||||
Exams->ExaCod = Exam->ExaCod;
|
||||
|
@ -1008,12 +1000,12 @@ static void ExaSet_ListSetQuestions (struct Exa_Exams *Exams,
|
|||
|
||||
/***** Get data of questions from database *****/
|
||||
NumQsts = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get exam questions",
|
||||
"SELECT QstCod" // row[0]
|
||||
" FROM exa_set_questions"
|
||||
" WHERE SetCod=%ld"
|
||||
" ORDER BY Stem",
|
||||
Set->SetCod);
|
||||
DB_QuerySELECT (&mysql_res,"can not get exam questions",
|
||||
"SELECT QstCod" // row[0]
|
||||
" FROM exa_set_questions"
|
||||
" WHERE SetCod=%ld"
|
||||
" ORDER BY Stem",
|
||||
Set->SetCod);
|
||||
|
||||
/***** Begin box *****/
|
||||
if (ICanEditQuestions)
|
||||
|
@ -1280,7 +1272,6 @@ static void ExaSet_ListOneOrMoreQuestionsForEdition (struct Exa_Exams *Exams,
|
|||
extern const char *Txt_No_INDEX;
|
||||
extern const char *Txt_Question;
|
||||
unsigned NumQst;
|
||||
MYSQL_ROW row;
|
||||
struct Tst_Question Question;
|
||||
char *Anchor;
|
||||
static Act_Action_t NextAction[Tst_NUM_VALIDITIES] =
|
||||
|
@ -1321,12 +1312,8 @@ static void ExaSet_ListOneOrMoreQuestionsForEdition (struct Exa_Exams *Exams,
|
|||
Tst_QstConstructor (&Question);
|
||||
|
||||
/***** Get question data *****/
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
/*
|
||||
row[0] QstCod
|
||||
*/
|
||||
/* Get question code (row[0]) */
|
||||
Exams->QstCod = Question.QstCod = Str_ConvertStrCodToLongCod (row[0]);
|
||||
/* Get question code */
|
||||
Exams->QstCod = Question.QstCod = DB_GetNextCode (mysql_res);
|
||||
ExaSet_GetQstDataFromDB (&Question);
|
||||
|
||||
/***** Build anchor string *****/
|
||||
|
|
|
@ -1079,8 +1079,8 @@ static void Fig_GetAndShowInssOrderedByNumCtrs (void)
|
|||
case Hie_Lvl_SYS:
|
||||
NumInss = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get institutions",
|
||||
"SELECT InsCod,"
|
||||
"COUNT(*) AS N"
|
||||
"SELECT InsCod," // row[0]
|
||||
"COUNT(*) AS N" // row[1]
|
||||
" FROM ctr_centers"
|
||||
" GROUP BY InsCod"
|
||||
" ORDER BY N DESC");
|
||||
|
@ -1088,8 +1088,8 @@ static void Fig_GetAndShowInssOrderedByNumCtrs (void)
|
|||
case Hie_Lvl_CTY:
|
||||
NumInss = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get institutions",
|
||||
"SELECT ctr_centers.InsCod,"
|
||||
"COUNT(*) AS N"
|
||||
"SELECT ctr_centers.InsCod," // row[0]
|
||||
"COUNT(*) AS N" // row[1]
|
||||
" FROM ins_instits,"
|
||||
"ctr_centers"
|
||||
" WHERE ins_instits.CtyCod=%ld"
|
||||
|
@ -1104,8 +1104,8 @@ static void Fig_GetAndShowInssOrderedByNumCtrs (void)
|
|||
case Hie_Lvl_CRS:
|
||||
NumInss = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get institutions",
|
||||
"SELECT InsCod,"
|
||||
"COUNT(*) AS N"
|
||||
"SELECT InsCod," // row[0]
|
||||
"COUNT(*) AS N" // row[1]
|
||||
" FROM ctr_centers"
|
||||
" WHERE InsCod=%ld"
|
||||
" GROUP BY InsCod"
|
||||
|
@ -1149,8 +1149,8 @@ static void Fig_GetAndShowInssOrderedByNumDegs (void)
|
|||
case Hie_Lvl_SYS:
|
||||
NumInss = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get institutions",
|
||||
"SELECT ctr_centers.InsCod,"
|
||||
"COUNT(*) AS N"
|
||||
"SELECT ctr_centers.InsCod," // row[0]
|
||||
"COUNT(*) AS N" // row[1]
|
||||
" FROM ctr_centers,"
|
||||
"deg_degrees"
|
||||
" WHERE ctr_centers.CtrCod=deg_degrees.CtrCod"
|
||||
|
@ -1160,8 +1160,8 @@ static void Fig_GetAndShowInssOrderedByNumDegs (void)
|
|||
case Hie_Lvl_CTY:
|
||||
NumInss = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get institutions",
|
||||
"SELECT ctr_centers.InsCod,"
|
||||
"COUNT(*) AS N"
|
||||
"SELECT ctr_centers.InsCod," // row[0]
|
||||
"COUNT(*) AS N" // row[1]
|
||||
" FROM ins_instits,"
|
||||
"ctr_centers,"
|
||||
"deg_degrees"
|
||||
|
@ -1178,8 +1178,8 @@ static void Fig_GetAndShowInssOrderedByNumDegs (void)
|
|||
case Hie_Lvl_CRS:
|
||||
NumInss = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get institutions",
|
||||
"SELECT ctr_centers.InsCod,"
|
||||
"COUNT(*) AS N"
|
||||
"SELECT ctr_centers.InsCod," // row[0]
|
||||
"COUNT(*) AS N" // row[1]
|
||||
" FROM ctr_centers,"
|
||||
"deg_degrees"
|
||||
" WHERE ctr_centers.InsCod=%ld"
|
||||
|
@ -1225,8 +1225,8 @@ static void Fig_GetAndShowInssOrderedByNumCrss (void)
|
|||
case Hie_Lvl_SYS:
|
||||
NumInss = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get institutions",
|
||||
"SELECT ctr_centers.InsCod,"
|
||||
"COUNT(*) AS N"
|
||||
"SELECT ctr_centers.InsCod," // row[0]
|
||||
"COUNT(*) AS N" // row[1]
|
||||
" FROM ctr_centers,"
|
||||
"deg_degrees,"
|
||||
"crs_courses"
|
||||
|
@ -1238,8 +1238,8 @@ static void Fig_GetAndShowInssOrderedByNumCrss (void)
|
|||
case Hie_Lvl_CTY:
|
||||
NumInss = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get institutions",
|
||||
"SELECT ctr_centers.InsCod,"
|
||||
"COUNT(*) AS N"
|
||||
"SELECT ctr_centers.InsCod," // row[0]
|
||||
"COUNT(*) AS N" // row[1]
|
||||
" FROM ins_instits,"
|
||||
"ctr_centers,"
|
||||
"deg_degrees,"
|
||||
|
@ -1258,8 +1258,8 @@ static void Fig_GetAndShowInssOrderedByNumCrss (void)
|
|||
case Hie_Lvl_CRS:
|
||||
NumInss = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get institutions",
|
||||
"SELECT ctr_centers.InsCod,"
|
||||
"COUNT(*) AS N"
|
||||
"SELECT ctr_centers.InsCod," // row[0]
|
||||
"COUNT(*) AS N" // row[1]
|
||||
" FROM ctr_centers,"
|
||||
"deg_degrees,"
|
||||
"crs_courses"
|
||||
|
@ -1307,8 +1307,8 @@ static void Fig_GetAndShowInssOrderedByNumUsrsInCrss (void)
|
|||
case Hie_Lvl_SYS:
|
||||
NumInss = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get institutions",
|
||||
"SELECT ctr_centers.InsCod,"
|
||||
"COUNT(DISTINCT crs_users.UsrCod) AS N"
|
||||
"SELECT ctr_centers.InsCod," // row[0]
|
||||
"COUNT(DISTINCT crs_users.UsrCod) AS N" // row[1]
|
||||
" FROM ctr_centers,"
|
||||
"deg_degrees,"
|
||||
"crs_courses,"
|
||||
|
@ -1322,8 +1322,8 @@ static void Fig_GetAndShowInssOrderedByNumUsrsInCrss (void)
|
|||
case Hie_Lvl_CTY:
|
||||
NumInss = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get institutions",
|
||||
"SELECT ctr_centers.InsCod,"
|
||||
"COUNT(DISTINCT crs_users.UsrCod) AS N"
|
||||
"SELECT ctr_centers.InsCod," // row[0]
|
||||
"COUNT(DISTINCT crs_users.UsrCod) AS N" // row[1]
|
||||
" FROM ins_instits,"
|
||||
"ctr_centers,"
|
||||
"deg_degrees,"
|
||||
|
@ -1344,8 +1344,8 @@ static void Fig_GetAndShowInssOrderedByNumUsrsInCrss (void)
|
|||
case Hie_Lvl_CRS:
|
||||
NumInss = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get institutions",
|
||||
"SELECT ctr_centers.InsCod,"
|
||||
"COUNT(DISTINCT crs_users.UsrCod) AS N"
|
||||
"SELECT ctr_centers.InsCod," // row[0]
|
||||
"COUNT(DISTINCT crs_users.UsrCod) AS N" // row[1]
|
||||
" FROM ctr_centers,"
|
||||
"deg_degrees,"
|
||||
"crs_courses,"
|
||||
|
@ -1396,7 +1396,8 @@ static void Fig_GetAndShowInssOrderedByNumUsrsWhoClaimToBelongToThem (void)
|
|||
case Hie_Lvl_SYS:
|
||||
NumInss =
|
||||
(unsigned) DB_QuerySELECT (&mysql_res,"can not get institutions",
|
||||
"SELECT InsCod,COUNT(*) AS N"
|
||||
"SELECT InsCod," // row[0]
|
||||
"COUNT(*) AS N" // row[1]
|
||||
" FROM usr_data"
|
||||
" WHERE InsCod>0"
|
||||
" GROUP BY InsCod"
|
||||
|
@ -1405,7 +1406,8 @@ static void Fig_GetAndShowInssOrderedByNumUsrsWhoClaimToBelongToThem (void)
|
|||
case Hie_Lvl_CTY:
|
||||
NumInss =
|
||||
(unsigned) DB_QuerySELECT (&mysql_res,"can not get institutions",
|
||||
"SELECT usr_data.InsCod,COUNT(*) AS N"
|
||||
"SELECT usr_data.InsCod," // row[0]
|
||||
"COUNT(*) AS N" // row[1]
|
||||
" FROM ins_instits,usr_data"
|
||||
" WHERE ins_instits.CtyCod=%ld"
|
||||
" AND ins_instits.InsCod=usr_data.InsCod"
|
||||
|
@ -1419,7 +1421,8 @@ static void Fig_GetAndShowInssOrderedByNumUsrsWhoClaimToBelongToThem (void)
|
|||
case Hie_Lvl_CRS:
|
||||
NumInss =
|
||||
(unsigned) DB_QuerySELECT (&mysql_res,"can not get institutions",
|
||||
"SELECT InsCod,COUNT(*) AS N"
|
||||
"SELECT InsCod," // row[0]
|
||||
"COUNT(*) AS N" // row[1]
|
||||
" FROM usr_data"
|
||||
" WHERE InsCod=%ld"
|
||||
" GROUP BY InsCod"
|
||||
|
@ -3583,8 +3586,8 @@ static void Fig_GetAndShowTimelineActivityStats (void)
|
|||
case Hie_Lvl_SYS:
|
||||
NumRows =
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of social notes",
|
||||
"SELECT COUNT(*),"
|
||||
"COUNT(DISTINCT UsrCod)"
|
||||
"SELECT COUNT(*)," // row[0]
|
||||
"COUNT(DISTINCT UsrCod)" // row[1]
|
||||
" FROM tml_notes WHERE NoteType=%u",
|
||||
NoteType);
|
||||
break;
|
||||
|
@ -3735,8 +3738,8 @@ static void Fig_GetAndShowTimelineActivityStats (void)
|
|||
case Hie_Lvl_SYS:
|
||||
NumRows =
|
||||
DB_QuerySELECT (&mysql_res,"can not get number of social notes",
|
||||
"SELECT COUNT(*),"
|
||||
"COUNT(DISTINCT UsrCod)"
|
||||
"SELECT COUNT(*)," // row[0]
|
||||
"COUNT(DISTINCT UsrCod)" // row[1]
|
||||
" FROM tml_notes");
|
||||
break;
|
||||
case Hie_Lvl_CTY:
|
||||
|
|
|
@ -2671,7 +2671,6 @@ static void Brw_SetPathFileBrowser (void)
|
|||
bool Brw_CheckIfExistsFolderAssigmentForAnyUsr (const char *FolderName)
|
||||
{
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
unsigned NumUsrs;
|
||||
unsigned NumUsr;
|
||||
long UsrCod;
|
||||
|
@ -2692,8 +2691,7 @@ bool Brw_CheckIfExistsFolderAssigmentForAnyUsr (const char *FolderName)
|
|||
NumUsr++)
|
||||
{
|
||||
/* Get next user */
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
UsrCod = Str_ConvertStrCodToLongCod (row[0]);
|
||||
UsrCod = DB_GetNextCode (mysql_res);
|
||||
|
||||
/* Check if folder exists */
|
||||
snprintf (PathFolder,sizeof (PathFolder),"%s/usr/%02u/%ld/%s/%s",
|
||||
|
@ -2782,7 +2780,6 @@ bool Brw_UpdateFoldersAssigmentsIfExistForAllUsrs (const char *OldFolderName,con
|
|||
extern const char *Txt_Folders_renamed;
|
||||
extern const char *Txt_Folders_not_renamed;
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
unsigned NumUsrs;
|
||||
unsigned NumUsr;
|
||||
long UsrCod;
|
||||
|
@ -2795,12 +2792,12 @@ bool Brw_UpdateFoldersAssigmentsIfExistForAllUsrs (const char *OldFolderName,con
|
|||
unsigned NumUsrsSuccess = 0;
|
||||
|
||||
/***** Get all the users belonging to current course from database *****/
|
||||
NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get users"
|
||||
" from current course",
|
||||
"SELECT UsrCod" // row[0]
|
||||
" FROM crs_users"
|
||||
" WHERE CrsCod=%ld",
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
NumUsrs = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get users from current course",
|
||||
"SELECT UsrCod" // row[0]
|
||||
" FROM crs_users"
|
||||
" WHERE CrsCod=%ld",
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
|
||||
/***** Check if there exist folders with the new name *****/
|
||||
for (NumUsr = 0;
|
||||
|
@ -2808,8 +2805,7 @@ bool Brw_UpdateFoldersAssigmentsIfExistForAllUsrs (const char *OldFolderName,con
|
|||
NumUsr++)
|
||||
{
|
||||
/* Get next user */
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
UsrCod = Str_ConvertStrCodToLongCod (row[0]);
|
||||
UsrCod = DB_GetNextCode (mysql_res);
|
||||
|
||||
/* Rename folder if exists */
|
||||
snprintf (PathOldFolder,sizeof (PathOldFolder),"%s/usr/%02u/%ld/%s/%s",
|
||||
|
@ -2838,8 +2834,7 @@ bool Brw_UpdateFoldersAssigmentsIfExistForAllUsrs (const char *OldFolderName,con
|
|||
NumUsr++)
|
||||
{
|
||||
/* Get next user */
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
UsrCod = Str_ConvertStrCodToLongCod (row[0]);
|
||||
UsrCod = DB_GetNextCode (mysql_res);
|
||||
|
||||
/* Rename folder if exists */
|
||||
snprintf (PathOldFolder,sizeof (PathOldFolder),"%s/usr/%02u/%ld/%s/%s",
|
||||
|
@ -2908,19 +2903,18 @@ bool Brw_UpdateFoldersAssigmentsIfExistForAllUsrs (const char *OldFolderName,con
|
|||
void Brw_RemoveFoldersAssignmentsIfExistForAllUsrs (const char *FolderName)
|
||||
{
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
unsigned NumUsrs;
|
||||
unsigned NumUsr;
|
||||
long UsrCod;
|
||||
char PathFolder[PATH_MAX * 2 + 128];
|
||||
|
||||
/***** Get all the users belonging to current course from database *****/
|
||||
NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get users"
|
||||
" from current course",
|
||||
"SELECT UsrCod" // row[0]
|
||||
" FROM crs_users"
|
||||
" WHERE CrsCod=%ld",
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
NumUsrs = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get users from current course",
|
||||
"SELECT UsrCod" // row[0]
|
||||
" FROM crs_users"
|
||||
" WHERE CrsCod=%ld",
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
|
||||
/***** Remove folders *****/
|
||||
for (NumUsr = 0;
|
||||
|
@ -2928,8 +2922,7 @@ void Brw_RemoveFoldersAssignmentsIfExistForAllUsrs (const char *FolderName)
|
|||
NumUsr++)
|
||||
{
|
||||
/* Get next user */
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
UsrCod = Str_ConvertStrCodToLongCod (row[0]);
|
||||
UsrCod = DB_GetNextCode (mysql_res);
|
||||
|
||||
/* Remove tree if exists */
|
||||
snprintf (PathFolder,sizeof (PathFolder),"%s/usr/%02u/%ld/%s/%s",
|
||||
|
@ -9381,7 +9374,7 @@ bool Brw_CheckIfFileOrFolderIsSetAsHiddenInDB (Brw_FileType_t FileType,const cha
|
|||
/***** Get if a file or folder is hidden from database *****/
|
||||
if (DB_QuerySELECT (&mysql_res,"can not check if a file is hidden",
|
||||
"SELECT Hidden" // row[0]
|
||||
" FROM brw_files" // row[1]
|
||||
" FROM brw_files"
|
||||
" WHERE FileBrowser=%u"
|
||||
" AND Cod=%ld"
|
||||
" AND ZoneUsrCod=%ld"
|
||||
|
@ -10374,38 +10367,22 @@ long Brw_GetFilCodByPath (const char *Path,bool OnlyIfPublic)
|
|||
{
|
||||
long Cod = Brw_GetCodForFiles ();
|
||||
long ZoneUsrCod = Brw_GetZoneUsrCodForFiles ();
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
long FilCod;
|
||||
|
||||
/***** Get code of a file from database *****/
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get file code",
|
||||
"SELECT FilCod"
|
||||
" FROM brw_files"
|
||||
" WHERE FileBrowser=%u"
|
||||
" AND Cod=%ld"
|
||||
" AND ZoneUsrCod=%ld"
|
||||
" AND Path='%s'"
|
||||
"%s",
|
||||
(unsigned) Brw_FileBrowserForDB_files[Gbl.FileBrowser.Type],
|
||||
Cod,ZoneUsrCod,
|
||||
Path,
|
||||
OnlyIfPublic ? " AND Public='Y'" :
|
||||
""))
|
||||
{
|
||||
/* Get row */
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
|
||||
/* Get file code (row[0]) */
|
||||
FilCod = Str_ConvertStrCodToLongCod (row[0]);
|
||||
}
|
||||
else
|
||||
FilCod = -1L;
|
||||
|
||||
/***** Free structure that stores the query result *****/
|
||||
DB_FreeMySQLResult (&mysql_res);
|
||||
|
||||
return FilCod;
|
||||
return DB_QuerySELECTCode ("can not get file code",
|
||||
"SELECT FilCod"
|
||||
" FROM brw_files"
|
||||
" WHERE FileBrowser=%u"
|
||||
" AND Cod=%ld"
|
||||
" AND ZoneUsrCod=%ld"
|
||||
" AND Path='%s'"
|
||||
"%s",
|
||||
(unsigned) Brw_FileBrowserForDB_files[Gbl.FileBrowser.Type],
|
||||
Cod,
|
||||
ZoneUsrCod,
|
||||
Path,
|
||||
OnlyIfPublic ? " AND Public='Y'" :
|
||||
"");
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -11749,41 +11726,22 @@ static bool Brw_CheckIfICanModifyPrjAssFileOrFolder (void)
|
|||
|
||||
static long Brw_GetPublisherOfSubtree (void)
|
||||
{
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
unsigned long NumRows;
|
||||
long PublisherUsrCod;
|
||||
long Cod = Brw_GetCodForFiles ();
|
||||
|
||||
/***** Get all common files that are equal to full path (including filename)
|
||||
or that are under that full path from database *****/
|
||||
NumRows = DB_QuerySELECT (&mysql_res,"can not get publishers of files",
|
||||
"SELECT DISTINCT(PublisherUsrCod)"
|
||||
" FROM brw_files"
|
||||
" WHERE FileBrowser=%u"
|
||||
" AND Cod=%ld"
|
||||
" AND (Path='%s'"
|
||||
" OR"
|
||||
" Path LIKE '%s/%%')",
|
||||
(unsigned) Brw_FileBrowserForDB_files[Gbl.FileBrowser.Type],
|
||||
Cod,
|
||||
Gbl.FileBrowser.FilFolLnk.Full,
|
||||
Gbl.FileBrowser.FilFolLnk.Full);
|
||||
|
||||
/***** Check all common files that are equal to full path (including filename)
|
||||
or that are under that full path *****/
|
||||
if (NumRows == 1) // Get the publisher of the file(s)
|
||||
{
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
PublisherUsrCod = Str_ConvertStrCodToLongCod (row[0]);
|
||||
}
|
||||
else
|
||||
PublisherUsrCod = -1L;
|
||||
|
||||
/***** Free structure that stores the query result *****/
|
||||
DB_FreeMySQLResult (&mysql_res);
|
||||
|
||||
return PublisherUsrCod;
|
||||
return DB_QuerySELECTCode ("can not get publishers of files",
|
||||
"SELECT DISTINCT(PublisherUsrCod)"
|
||||
" FROM brw_files"
|
||||
" WHERE FileBrowser=%u"
|
||||
" AND Cod=%ld"
|
||||
" AND (Path='%s'"
|
||||
" OR"
|
||||
" Path LIKE '%s/%%')",
|
||||
(unsigned) Brw_FileBrowserForDB_files[Gbl.FileBrowser.Type],
|
||||
Cod,
|
||||
Gbl.FileBrowser.FilFolLnk.Full,
|
||||
Gbl.FileBrowser.FilFolLnk.Full);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -675,7 +675,6 @@ static void Fol_ListFollowingUsr (struct UsrData *UsrDat)
|
|||
{
|
||||
extern const char *Txt_Following;
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
unsigned long NumUsrs;
|
||||
unsigned long NumUsr;
|
||||
struct UsrData FollowingUsrDat;
|
||||
|
@ -685,7 +684,7 @@ 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"
|
||||
"SELECT FollowedCod" // row[0]
|
||||
" FROM usr_follow"
|
||||
" WHERE FollowerCod=%ld"
|
||||
" ORDER BY FollowTime DESC",
|
||||
|
@ -705,11 +704,8 @@ static void Fol_ListFollowingUsr (struct UsrData *UsrDat)
|
|||
NumUsr < NumUsrs;
|
||||
NumUsr++)
|
||||
{
|
||||
/***** Get user *****/
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
|
||||
/* Get user's code (row[0]) */
|
||||
FollowingUsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0]);
|
||||
/***** Get user's code *****/
|
||||
FollowingUsrDat.UsrCod = DB_GetNextCode (mysql_res);
|
||||
|
||||
/***** Show user *****/
|
||||
if ((NumUsr % Fol_NUM_COLUMNS_FOLLOW) == 0)
|
||||
|
@ -759,7 +755,6 @@ static void Fol_ListFollowersUsr (struct UsrData *UsrDat)
|
|||
{
|
||||
extern const char *Txt_Followers;
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
unsigned long NumUsrs;
|
||||
unsigned long NumUsr;
|
||||
struct UsrData FollowerUsrDat;
|
||||
|
@ -790,11 +785,8 @@ static void Fol_ListFollowersUsr (struct UsrData *UsrDat)
|
|||
NumUsr < NumUsrs;
|
||||
NumUsr++)
|
||||
{
|
||||
/***** Get user and number of clicks *****/
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
|
||||
/* Get user's code (row[0]) */
|
||||
FollowerUsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0]);
|
||||
/***** Get user's code *****/
|
||||
FollowerUsrDat.UsrCod = DB_GetNextCode (mysql_res);
|
||||
|
||||
/***** Show user *****/
|
||||
if ((NumUsr % Fol_NUM_COLUMNS_FOLLOW) == 0)
|
||||
|
@ -1378,8 +1370,8 @@ void Fol_GetAndShowRankingFollowers (void)
|
|||
case Hie_Lvl_SYS:
|
||||
NumUsrs = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get ranking",
|
||||
"SELECT FollowedCod," // row[0]
|
||||
"COUNT(FollowerCod) AS N" // row[1]
|
||||
"SELECT FollowedCod," // row[0]
|
||||
"COUNT(FollowerCod) AS N" // row[1]
|
||||
" FROM usr_follow"
|
||||
" GROUP BY FollowedCod"
|
||||
" ORDER BY N DESC,"
|
||||
|
|
104
swad_forum.c
104
swad_forum.c
|
@ -731,9 +731,8 @@ static void For_GetThrSubject (long ThrCod,char Subject[Cns_MAX_BYTES_SUBJECT +
|
|||
MYSQL_ROW row;
|
||||
|
||||
/***** Get subject of a thread from database *****/
|
||||
DB_QuerySELECT (&mysql_res,"can not get the subject"
|
||||
" of a thread of a forum",
|
||||
"SELECT for_posts.Subject"
|
||||
DB_QuerySELECT (&mysql_res,"can not get the subject of a thread of a forum",
|
||||
"SELECT for_posts.Subject" // row[0]
|
||||
" FROM for_threads,"
|
||||
"for_posts"
|
||||
" WHERE for_threads.ThrCod=%ld"
|
||||
|
@ -827,23 +826,18 @@ static void For_UpdateThrLastPst (long ThrCod,long LastPstCod)
|
|||
|
||||
static long For_GetLastPstCod (long ThrCod)
|
||||
{
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
long LastPstCod;
|
||||
|
||||
/***** Get the code of the last post of a thread from database *****/
|
||||
DB_QuerySELECT (&mysql_res,"can not get the most recent post"
|
||||
" of a thread of a forum",
|
||||
"SELECT PstCod"
|
||||
" FROM for_posts"
|
||||
" WHERE ThrCod=%ld"
|
||||
" ORDER BY CreatTime DESC"
|
||||
" LIMIT 1",
|
||||
ThrCod);
|
||||
|
||||
/***** Write the subject of the thread *****/
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
if (sscanf (row[0],"%ld",&LastPstCod) != 1)
|
||||
LastPstCod = DB_QuerySELECTCode ("can not get the most recent post"
|
||||
" of a thread of a forum",
|
||||
"SELECT PstCod"
|
||||
" FROM for_posts"
|
||||
" WHERE ThrCod=%ld"
|
||||
" ORDER BY CreatTime DESC"
|
||||
" LIMIT 1",
|
||||
ThrCod);
|
||||
if (LastPstCod <= 0)
|
||||
Lay_ShowErrorAndExit ("Error when getting the most recent post of a thread of a forum.");
|
||||
|
||||
return LastPstCod;
|
||||
|
@ -894,29 +888,12 @@ static unsigned For_GetNumOfReadersOfThr (long ThrCod)
|
|||
|
||||
static unsigned For_GetNumOfWritersInThr (long ThrCod)
|
||||
{
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
unsigned NumWriters;
|
||||
|
||||
/***** Get number of distinct writers in a thread from database *****/
|
||||
DB_QuerySELECT (&mysql_res,"can not get the number of writers"
|
||||
" in a thread of a forum",
|
||||
"SELECT COUNT(DISTINCT UsrCod)"
|
||||
" FROM for_posts"
|
||||
" WHERE ThrCod=%ld",
|
||||
ThrCod);
|
||||
|
||||
/* Get row with number of writers */
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
|
||||
/* Get number of writers (row[0]) */
|
||||
if (sscanf (row[0],"%u",&NumWriters) != 1)
|
||||
Lay_ShowErrorAndExit ("Error when getting the number of writers in a thread of a forum.");
|
||||
|
||||
/***** Free structure that stores the query result *****/
|
||||
DB_FreeMySQLResult (&mysql_res);
|
||||
|
||||
return NumWriters;
|
||||
return DB_QueryCOUNT ("can not get the number of writers in a thread of a forum",
|
||||
"SELECT COUNT(DISTINCT UsrCod)"
|
||||
" FROM for_posts"
|
||||
" WHERE ThrCod=%ld",
|
||||
ThrCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -2473,7 +2450,6 @@ static void For_ShowForumThreadsHighlightingOneThread (struct For_Forums *Forums
|
|||
extern const char *Txt_ReaBRders;
|
||||
char SubQuery[256];
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
char FrameTitle[128 + For_MAX_BYTES_FORUM_NAME];
|
||||
char ForumName[For_MAX_BYTES_FORUM_NAME + 1];
|
||||
unsigned NumThr;
|
||||
|
@ -2531,13 +2507,9 @@ static void For_ShowForumThreadsHighlightingOneThread (struct For_Forums *Forums
|
|||
for (NumThr = PaginationThrs.FirstItemVisible, NumThrInScreen = 0;
|
||||
NumThr <= PaginationThrs.LastItemVisible;
|
||||
NumThr++, NumThrInScreen++)
|
||||
{
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
|
||||
/* Get thread code(row[0]) */
|
||||
if ((ThrCods[NumThrInScreen] = Str_ConvertStrCodToLongCod (row[0])) < 0)
|
||||
if ((ThrCods[NumThrInScreen] = DB_GetNextCode (mysql_res)) < 0)
|
||||
Lay_ShowErrorAndExit ("Error when getting thread of a forum.");
|
||||
}
|
||||
|
||||
/***** Free structure that stores the query result *****/
|
||||
DB_FreeMySQLResult (&mysql_res);
|
||||
|
@ -3688,12 +3660,12 @@ static void For_GetThreadData (struct For_Thread *Thr)
|
|||
/***** Get data of a thread from database *****/
|
||||
NumRows = DB_QuerySELECT (&mysql_res,"can not get data"
|
||||
" of a thread of a forum",
|
||||
"SELECT m0.PstCod,"
|
||||
"m1.PstCod,"
|
||||
"m0.UsrCod,"
|
||||
"m1.UsrCod,"
|
||||
"UNIX_TIMESTAMP(m0.CreatTime),"
|
||||
"UNIX_TIMESTAMP(m1.CreatTime),"
|
||||
"SELECT m0.PstCod," // row[0]
|
||||
"m1.PstCod," // row[1]
|
||||
"m0.UsrCod," // row[2]
|
||||
"m1.UsrCod," // row[3]
|
||||
"UNIX_TIMESTAMP(m0.CreatTime)," // row[4]
|
||||
"UNIX_TIMESTAMP(m1.CreatTime)," // row[5]
|
||||
"m0.Subject"
|
||||
" FROM for_threads,"
|
||||
"for_posts AS m0,"
|
||||
|
@ -4555,31 +4527,13 @@ static bool For_CheckIfICanMoveThreads (void)
|
|||
|
||||
static long For_GetThrInMyClipboard (void)
|
||||
{
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
unsigned long NumRows;
|
||||
long ThrCod = -1L;
|
||||
|
||||
/***** Get if there is a thread ready to move in my clipboard from database *****/
|
||||
NumRows = DB_QuerySELECT (&mysql_res,"can not check if there is"
|
||||
" any thread ready to be moved",
|
||||
"SELECT ThrCod"
|
||||
" FROM for_clipboards"
|
||||
" WHERE UsrCod=%ld",
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||
|
||||
if (NumRows == 1)
|
||||
{
|
||||
/* Get thread code */
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
if (sscanf (row[0],"%ld",&ThrCod) != 1)
|
||||
Lay_ShowErrorAndExit ("Error when checking if there is any thread ready to be moved.");
|
||||
}
|
||||
|
||||
/***** Free structure that stores the query result *****/
|
||||
DB_FreeMySQLResult (&mysql_res);
|
||||
|
||||
return ThrCod;
|
||||
return DB_QuerySELECTCode ("can not check if there is"
|
||||
" any thread ready to be moved",
|
||||
"SELECT ThrCod"
|
||||
" FROM for_clipboards"
|
||||
" WHERE UsrCod=%ld",
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -1429,6 +1429,15 @@ void Lay_WrongProjectExit (void)
|
|||
Lay_ShowErrorAndExit ("Wrong project.");
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********** Write error message and exit when wrong call for exam ************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Lay_WrongCallForExamExit (void)
|
||||
{
|
||||
Lay_ShowErrorAndExit ("Wrong call for exam.");
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************** Write error message and exit when wrong exam *****************/
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -74,6 +74,7 @@ void Lay_WrongScopeExit (void);
|
|||
void Lay_WrongOrderExit (void);
|
||||
void Lay_WrongTypeOfViewExit (void);
|
||||
void Lay_WrongProjectExit (void);
|
||||
void Lay_WrongCallForExamExit (void);
|
||||
void Lay_WrongExamExit (void);
|
||||
void Lay_WrongSetExit (void);
|
||||
void Lay_WrongExamSessionExit (void);
|
||||
|
|
|
@ -1929,7 +1929,6 @@ long Med_CloneMedia (const struct Med_Media *MediaSrc)
|
|||
|
||||
void Med_RemoveMediaFromAllRows (unsigned NumMedia,MYSQL_RES *mysql_res)
|
||||
{
|
||||
MYSQL_ROW row;
|
||||
unsigned NumMed;
|
||||
long MedCod;
|
||||
|
||||
|
@ -1938,9 +1937,8 @@ void Med_RemoveMediaFromAllRows (unsigned NumMedia,MYSQL_RES *mysql_res)
|
|||
NumMed < NumMedia;
|
||||
NumMed++)
|
||||
{
|
||||
/***** Get media code (row[0]) *****/
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
MedCod = Str_ConvertStrCodToLongCod (row[0]);
|
||||
/***** Get media code *****/
|
||||
MedCod = DB_GetNextCode (mysql_res);
|
||||
|
||||
/***** Remove media files *****/
|
||||
Med_RemoveMedia (MedCod);
|
||||
|
|
Loading…
Reference in New Issue