mirror of https://github.com/acanas/swad-core.git
Version 21.47.2: Oct 29, 2021 Queries moved to module swad_questions_database.
This commit is contained in:
parent
b5ff64cb8d
commit
0179af96e0
|
@ -3145,7 +3145,7 @@ int swad__sendAttendanceUsers (struct soap *soap,
|
|||
/* Find next string in text until comma (leading and trailing spaces are removed) */
|
||||
Str_GetNextStringUntilComma (&Ptr,LongStr,Cns_MAX_DECIMAL_DIGITS_LONG);
|
||||
if ((UsrDat.UsrCod = Str_ConvertStrCodToLongCod (LongStr)) > 0)
|
||||
if (Usr_ChkIfUsrCodExists (UsrDat.UsrCod))
|
||||
if (Usr_DB_ChkIfUsrCodExists (UsrDat.UsrCod))
|
||||
// The user must belong to course,
|
||||
// but it's not necessary he/she belongs to groups associated to the event
|
||||
if (Usr_CheckIfUsrBelongsToCurrentCrs (&UsrDat))
|
||||
|
|
|
@ -786,7 +786,7 @@ static void Acc_CreateNewEncryptedUsrCod (struct UsrData *UsrDat)
|
|||
{
|
||||
Str_CreateRandomAlphanumStr (RandomStr,LENGTH_RANDOM_STR);
|
||||
Cry_EncryptSHA256Base64 (RandomStr,UsrDat->EnUsrCod);
|
||||
if (!Usr_ChkIfEncryptedUsrCodExists (UsrDat->EnUsrCod))
|
||||
if (!Usr_DB_ChkIfEncryptedUsrCodExists (UsrDat->EnUsrCod))
|
||||
break;
|
||||
}
|
||||
if (NumTry == MAX_TRY)
|
||||
|
@ -923,7 +923,7 @@ static void Acc_AskIfRemoveOtherUsrAccount (void)
|
|||
extern const char *Txt_Do_you_really_want_to_completely_eliminate_the_following_user;
|
||||
extern const char *Txt_Eliminate_user_account;
|
||||
|
||||
if (Usr_ChkIfUsrCodExists (Gbl.Usrs.Other.UsrDat.UsrCod))
|
||||
if (Usr_DB_ChkIfUsrCodExists (Gbl.Usrs.Other.UsrDat.UsrCod))
|
||||
{
|
||||
/***** Show question and button to remove user account *****/
|
||||
/* Begin alert */
|
||||
|
|
10
swad_admin.c
10
swad_admin.c
|
@ -149,7 +149,7 @@ static void Adm_ReqAddAdm (HieLvl_Level_t Scope,long Cod,
|
|||
(Scope == HieLvl_INS && Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM));
|
||||
if (ICanRegister)
|
||||
{
|
||||
if (Usr_CheckIfUsrIsAdm (Gbl.Usrs.Other.UsrDat.UsrCod,Scope,Cod)) // User is already an administrator of current institution/center/degree
|
||||
if (Usr_DB_CheckIfUsrIsAdm (Gbl.Usrs.Other.UsrDat.UsrCod,Scope,Cod)) // User is already an administrator of current institution/center/degree
|
||||
{
|
||||
Ale_ShowAlert (Ale_INFO,Txt_THE_USER_X_is_already_an_administrator_of_Y,
|
||||
Gbl.Usrs.Other.UsrDat.FullName,InsCtrDegName);
|
||||
|
@ -253,7 +253,7 @@ static void Adm_RegisterAdmin (struct UsrData *UsrDat,
|
|||
extern const char *Txt_THE_USER_X_has_been_enroled_as_administrator_of_Y;
|
||||
|
||||
/***** Check if user was and administrator of current institution/center/degree *****/
|
||||
if (Usr_CheckIfUsrIsAdm (UsrDat->UsrCod,Scope,Cod))
|
||||
if (Usr_DB_CheckIfUsrIsAdm (UsrDat->UsrCod,Scope,Cod))
|
||||
Ale_ShowAlert (Ale_SUCCESS,Txt_THE_USER_X_is_already_an_administrator_of_Y,
|
||||
UsrDat->FullName,InsCtrDegName);
|
||||
else // User was not administrator of current institution/center/degree
|
||||
|
@ -352,7 +352,7 @@ static void Adm_ReqRemOrRemAdm (Enr_ReqDelOrDelUsr_t ReqDelOrDelUsr,
|
|||
if (ICanRemove)
|
||||
{
|
||||
/* Check if the other user is an admin of the current institution/center/degree */
|
||||
if (Usr_CheckIfUsrIsAdm (Gbl.Usrs.Other.UsrDat.UsrCod,Scope,Cod))
|
||||
if (Usr_DB_CheckIfUsrIsAdm (Gbl.Usrs.Other.UsrDat.UsrCod,Scope,Cod))
|
||||
{ // The other user is an administrator of current institution/center/degree ==> ask for removing or remove her/him
|
||||
switch (ReqDelOrDelUsr)
|
||||
{
|
||||
|
@ -399,7 +399,7 @@ static void Adm_AskIfRemAdm (bool ItsMe,HieLvl_Level_t Scope,
|
|||
[HieLvl_CRS] = ActUnk,
|
||||
};
|
||||
|
||||
if (Usr_ChkIfUsrCodExists (Gbl.Usrs.Other.UsrDat.UsrCod))
|
||||
if (Usr_DB_ChkIfUsrCodExists (Gbl.Usrs.Other.UsrDat.UsrCod))
|
||||
{
|
||||
/***** Show question and button to remove user as administrator *****/
|
||||
/* Begin alert */
|
||||
|
@ -432,7 +432,7 @@ static void Adm_EffectivelyRemAdm (struct UsrData *UsrDat,
|
|||
extern const char *Txt_THE_USER_X_has_been_removed_as_administrator_of_Y;
|
||||
extern const char *Txt_THE_USER_X_is_not_an_administrator_of_Y;
|
||||
|
||||
if (Usr_CheckIfUsrIsAdm (UsrDat->UsrCod,Scope,Cod)) // User is administrator of current institution/center/degree
|
||||
if (Usr_DB_CheckIfUsrIsAdm (UsrDat->UsrCod,Scope,Cod)) // User is administrator of current institution/center/degree
|
||||
{
|
||||
/***** Remove user as administrator of institution, center or degree *****/
|
||||
Adm_DB_RemAdmin (UsrDat->UsrCod,Scope,Cod);
|
||||
|
|
|
@ -6407,7 +6407,7 @@ static void Brw_PasteClipboard (void)
|
|||
if (Crs_GetDataOfCourseByCod (&Hie.Crs))
|
||||
{
|
||||
Usr_UsrDataConstructor (&UsrDat);
|
||||
if (Usr_ChkIfUsrCodExists (Gbl.FileBrowser.Clipboard.WorksUsrCod))
|
||||
if (Usr_DB_ChkIfUsrCodExists (Gbl.FileBrowser.Clipboard.WorksUsrCod))
|
||||
|
||||
UsrDat.UsrCod = Gbl.FileBrowser.Clipboard.WorksUsrCod;
|
||||
Usr_GetAllUsrDataFromUsrCod (&UsrDat,
|
||||
|
|
|
@ -602,13 +602,14 @@ TODO: FIX BUG, URGENT! En las fechas como par
|
|||
|
||||
TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo.
|
||||
*/
|
||||
#define Log_PLATFORM_VERSION "SWAD 21.47.1 (2021-10-28)"
|
||||
#define Log_PLATFORM_VERSION "SWAD 21.47.2 (2021-10-29)"
|
||||
#define CSS_FILE "swad20.45.css"
|
||||
#define JS_FILE "swad20.69.1.js"
|
||||
/*
|
||||
TODO: Rename CENTRE to CENTER in help wiki.
|
||||
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
|
||||
|
||||
Version 21.47.2: Oct 29, 2021 Queries moved to module swad_questions_database. (321259 lines)
|
||||
Version 21.47.1: Oct 28, 2021 Queries moved to module swad_questions_database. (321231 lines)
|
||||
Version 21.47: Oct 27, 2021 New module swad_questions_database for database queries related to test/exam/game questions. (321236 lines)
|
||||
Version 21.46.5: Oct 27, 2021 Queries moved to module swad_test_database. (321140 lines)
|
||||
|
|
|
@ -213,7 +213,7 @@ static void Crs_WriteListMyCoursesToSelectOne (void)
|
|||
HTM_LI_End ();
|
||||
|
||||
/***** Get my countries *****/
|
||||
NumCtys = Usr_GetCtysFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,&mysql_resCty);
|
||||
NumCtys = Usr_DB_GetCtysFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,&mysql_resCty);
|
||||
for (NumCty = 0;
|
||||
NumCty < NumCtys;
|
||||
NumCty++)
|
||||
|
|
|
@ -196,7 +196,7 @@ void Dpt_SeeDepts (void)
|
|||
HTM_TR_End ();
|
||||
|
||||
/***** Write teachers of this institution with other department *****/
|
||||
NumTchsInsInOtherDpts = Usr_GetNumTchsCurrentInsInDepartment (0);
|
||||
NumTchsInsInOtherDpts = Usr_DB_GetNumTchsCurrentInsInDepartment (0);
|
||||
|
||||
HTM_TR_Begin (NULL);
|
||||
|
||||
|
@ -211,7 +211,7 @@ void Dpt_SeeDepts (void)
|
|||
HTM_TR_End ();
|
||||
|
||||
/***** Write teachers with no department *****/
|
||||
NumTchsInsWithNoDpt = Usr_GetNumTchsCurrentInsInDepartment (-1L);
|
||||
NumTchsInsWithNoDpt = Usr_DB_GetNumTchsCurrentInsInDepartment (-1L);
|
||||
|
||||
HTM_TR_Begin (NULL);
|
||||
|
||||
|
|
|
@ -166,8 +166,8 @@ void Dup_ListDuplicateUsrs (void)
|
|||
Usr_DONT_GET_ROLE_IN_CURRENT_CRS))
|
||||
{
|
||||
/* Get if user has accepted all his/her courses */
|
||||
if (Usr_GetNumCrssOfUsr (UsrDat.UsrCod) != 0)
|
||||
UsrDat.Accepted = (Usr_GetNumCrssOfUsrNotAccepted (UsrDat.UsrCod) == 0);
|
||||
if (Usr_DB_GetNumCrssOfUsr (UsrDat.UsrCod) != 0)
|
||||
UsrDat.Accepted = (Usr_DB_GetNumCrssOfUsrNotAccepted (UsrDat.UsrCod) == 0);
|
||||
else
|
||||
UsrDat.Accepted = false;
|
||||
|
||||
|
@ -283,8 +283,8 @@ static void Dup_ListSimilarUsrs (void)
|
|||
Usr_DONT_GET_ROLE_IN_CURRENT_CRS))
|
||||
{
|
||||
/* Get if user has accepted all his/her courses */
|
||||
if (Usr_GetNumCrssOfUsr (UsrDat.UsrCod) != 0)
|
||||
UsrDat.Accepted = (Usr_GetNumCrssOfUsrNotAccepted (UsrDat.UsrCod) == 0);
|
||||
if (Usr_DB_GetNumCrssOfUsr (UsrDat.UsrCod) != 0)
|
||||
UsrDat.Accepted = (Usr_DB_GetNumCrssOfUsrNotAccepted (UsrDat.UsrCod) == 0);
|
||||
else
|
||||
UsrDat.Accepted = false;
|
||||
|
||||
|
|
|
@ -1368,20 +1368,20 @@ bool Enr_PutActionsRegRemOneUsr (bool ItsMe)
|
|||
if (Gbl.Hierarchy.Ins.InsCod > 0)
|
||||
{
|
||||
/***** Check if the other user is administrator of the current institution *****/
|
||||
UsrIsInsAdmin = Usr_CheckIfUsrIsAdm (Gbl.Usrs.Other.UsrDat.UsrCod,
|
||||
UsrIsInsAdmin = Usr_DB_CheckIfUsrIsAdm (Gbl.Usrs.Other.UsrDat.UsrCod,
|
||||
HieLvl_INS,
|
||||
Gbl.Hierarchy.Ins.InsCod);
|
||||
|
||||
if (Gbl.Hierarchy.Ctr.CtrCod > 0)
|
||||
{
|
||||
/***** Check if the other user is administrator of the current center *****/
|
||||
UsrIsCtrAdmin = Usr_CheckIfUsrIsAdm (Gbl.Usrs.Other.UsrDat.UsrCod,
|
||||
UsrIsCtrAdmin = Usr_DB_CheckIfUsrIsAdm (Gbl.Usrs.Other.UsrDat.UsrCod,
|
||||
HieLvl_CTR,
|
||||
Gbl.Hierarchy.Ctr.CtrCod);
|
||||
|
||||
if (Gbl.Hierarchy.Deg.DegCod > 0)
|
||||
/***** Check if the other user is administrator of the current degree *****/
|
||||
UsrIsDegAdmin = Usr_CheckIfUsrIsAdm (Gbl.Usrs.Other.UsrDat.UsrCod,
|
||||
UsrIsDegAdmin = Usr_DB_CheckIfUsrIsAdm (Gbl.Usrs.Other.UsrDat.UsrCod,
|
||||
HieLvl_DEG,
|
||||
Gbl.Hierarchy.Deg.DegCod);
|
||||
}
|
||||
|
@ -2651,7 +2651,7 @@ static void Enr_ShowFormToEditOtherUsr (void)
|
|||
extern const char *Txt_THE_USER_X_already_exists_in_Y;
|
||||
|
||||
/***** If user exists... *****/
|
||||
if (Usr_ChkIfUsrCodExists (Gbl.Usrs.Other.UsrDat.UsrCod))
|
||||
if (Usr_DB_ChkIfUsrCodExists (Gbl.Usrs.Other.UsrDat.UsrCod))
|
||||
{
|
||||
/***** Show form to edit user *****/
|
||||
if (Gbl.Hierarchy.Level == HieLvl_CRS) // Course selected
|
||||
|
|
|
@ -561,7 +561,7 @@ void Mrk_ShowMyMarks (void)
|
|||
{
|
||||
if (Grp_DB_CountNumUsrsInGrp (Rol_STD,Gbl.Crs.Grps.GrpCod)) // If there are students in this group
|
||||
{
|
||||
Gbl.Usrs.Other.UsrDat.UsrCod = Usr_GetRamdomStdFromGrp (Gbl.Crs.Grps.GrpCod);
|
||||
Gbl.Usrs.Other.UsrDat.UsrCod = Usr_DB_GetRamdomStdFromGrp (Gbl.Crs.Grps.GrpCod);
|
||||
UsrDat = &Gbl.Usrs.Other.UsrDat;
|
||||
}
|
||||
else
|
||||
|
@ -572,7 +572,7 @@ void Mrk_ShowMyMarks (void)
|
|||
if (Usr_GetNumUsrsInCrss (HieLvl_CRS,Gbl.Hierarchy.Crs.CrsCod,
|
||||
1 << Rol_STD)) // If there are students in this course
|
||||
{
|
||||
Gbl.Usrs.Other.UsrDat.UsrCod = Usr_GetRamdomStdFromCrs (Gbl.Hierarchy.Crs.CrsCod);
|
||||
Gbl.Usrs.Other.UsrDat.UsrCod = Usr_DB_GetRamdomStdFromCrs (Gbl.Hierarchy.Crs.CrsCod);
|
||||
UsrDat = &Gbl.Usrs.Other.UsrDat;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -526,7 +526,7 @@ static void Prf_ShowNumCrssWithRole (const struct UsrData *UsrDat,
|
|||
unsigned NumCrss;
|
||||
|
||||
/***** Number of courses in which the user has a given role *****/
|
||||
NumCrss = Usr_GetNumCrssOfUsrWithARole (UsrDat->UsrCod,Role);
|
||||
NumCrss = Usr_DB_GetNumCrssOfUsrWithARole (UsrDat->UsrCod,Role);
|
||||
|
||||
Prf_BeginListItem (Txt_ROLES_SINGUL_Abc[Role][UsrDat->Sex],Rol_Icons[Role]);
|
||||
|
||||
|
@ -955,7 +955,7 @@ static void Prf_GetFirstClickFromLogAndStoreAsUsrFigure (long UsrCod)
|
|||
MYSQL_ROW row;
|
||||
struct Prf_UsrFigures UsrFigures;
|
||||
|
||||
if (Usr_ChkIfUsrCodExists (UsrCod))
|
||||
if (Usr_DB_ChkIfUsrCodExists (UsrCod))
|
||||
{
|
||||
/***** Reset user's figures *****/
|
||||
Prf_ResetUsrFigures (&UsrFigures);
|
||||
|
@ -989,7 +989,7 @@ static void Prf_GetNumClicksAndStoreAsUsrFigure (long UsrCod)
|
|||
{
|
||||
struct Prf_UsrFigures UsrFigures;
|
||||
|
||||
if (Usr_ChkIfUsrCodExists (UsrCod))
|
||||
if (Usr_DB_ChkIfUsrCodExists (UsrCod))
|
||||
{
|
||||
/***** Reset user's figures *****/
|
||||
Prf_ResetUsrFigures (&UsrFigures);
|
||||
|
@ -1013,7 +1013,7 @@ static void Prf_GetNumTimelinePubsAndStoreAsUsrFigure (long UsrCod)
|
|||
{
|
||||
struct Prf_UsrFigures UsrFigures;
|
||||
|
||||
if (Usr_ChkIfUsrCodExists (UsrCod))
|
||||
if (Usr_DB_ChkIfUsrCodExists (UsrCod))
|
||||
{
|
||||
/***** Reset user's figures *****/
|
||||
Prf_ResetUsrFigures (&UsrFigures);
|
||||
|
@ -1037,7 +1037,7 @@ static void Prf_GetNumFileViewsAndStoreAsUsrFigure (long UsrCod)
|
|||
{
|
||||
struct Prf_UsrFigures UsrFigures;
|
||||
|
||||
if (Usr_ChkIfUsrCodExists (UsrCod))
|
||||
if (Usr_DB_ChkIfUsrCodExists (UsrCod))
|
||||
{
|
||||
/***** Reset user's figures *****/
|
||||
Prf_ResetUsrFigures (&UsrFigures);
|
||||
|
@ -1061,7 +1061,7 @@ static void Prf_GetNumForumPostsAndStoreAsUsrFigure (long UsrCod)
|
|||
{
|
||||
struct Prf_UsrFigures UsrFigures;
|
||||
|
||||
if (Usr_ChkIfUsrCodExists (UsrCod))
|
||||
if (Usr_DB_ChkIfUsrCodExists (UsrCod))
|
||||
{
|
||||
/***** Reset user's figures *****/
|
||||
Prf_ResetUsrFigures (&UsrFigures);
|
||||
|
@ -1085,7 +1085,7 @@ static void Prf_GetNumMessagesSentAndStoreAsUsrFigure (long UsrCod)
|
|||
{
|
||||
struct Prf_UsrFigures UsrFigures;
|
||||
|
||||
if (Usr_ChkIfUsrCodExists (UsrCod))
|
||||
if (Usr_DB_ChkIfUsrCodExists (UsrCod))
|
||||
{
|
||||
/***** Reset user's figures *****/
|
||||
Prf_ResetUsrFigures (&UsrFigures);
|
||||
|
|
269
swad_question.c
269
swad_question.c
|
@ -753,8 +753,7 @@ void Qst_ListQuestionsToEdit (void)
|
|||
if (Tst_GetParamsTst (&Questions,Tst_EDIT_QUESTIONS)) // Get parameters from the form
|
||||
{
|
||||
/***** Get question codes from database *****/
|
||||
Qst_GetQuestions (&Questions,&mysql_res); // Query database
|
||||
if (Questions.NumQsts)
|
||||
if ((Questions.NumQsts = Qst_DB_GetQsts (&mysql_res,&Questions)))
|
||||
{
|
||||
/* Contextual menu */
|
||||
if (QstImp_GetCreateXMLParamFromForm ())
|
||||
|
@ -795,8 +794,7 @@ void Qst_ListQuestionsToSelectForExamSet (struct Exa_Exams *Exams)
|
|||
/***** Get parameters, query the database and list the questions *****/
|
||||
if (Tst_GetParamsTst (&Questions,Tst_SELECT_QUESTIONS_FOR_EXAM)) // Get parameters from the form
|
||||
{
|
||||
Qst_GetQuestions (&Questions,&mysql_res); // Query database
|
||||
if (Questions.NumQsts)
|
||||
if ((Questions.NumQsts = Qst_DB_GetQsts (&mysql_res,&Questions)))
|
||||
/* Show the table with the questions */
|
||||
Qst_ListOneOrMoreQstsForSelectionForExamSet (Exams,Questions.NumQsts,mysql_res);
|
||||
|
||||
|
@ -826,8 +824,7 @@ void Qst_ListQuestionsToSelectForGame (struct Gam_Games *Games)
|
|||
/***** Get parameters, query the database and list the questions *****/
|
||||
if (Tst_GetParamsTst (&Questions,Tst_SELECT_QUESTIONS_FOR_GAME)) // Get parameters from the form
|
||||
{
|
||||
Qst_GetQuestions (&Questions,&mysql_res); // Query database
|
||||
if (Questions.NumQsts)
|
||||
if ((Questions.NumQsts = Qst_DB_GetQsts (&mysql_res,&Questions)))
|
||||
/* Show the table with the questions */
|
||||
Qst_ListOneOrMoreQstsForSelectionForGame (Games,Questions.NumQsts,mysql_res);
|
||||
|
||||
|
@ -1720,149 +1717,6 @@ void Qst_CheckIfNumberOfAnswersIsOne (const struct Qst_Question *Question)
|
|||
Err_WrongAnswerExit ();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********** Get from the database several test questions for listing *********/
|
||||
/*****************************************************************************/
|
||||
|
||||
#define Qst_MAX_BYTES_QUERY_QUESTIONS (16 * 1024 - 1)
|
||||
|
||||
void Qst_GetQuestions (struct Qst_Questions *Questions,MYSQL_RES **mysql_res)
|
||||
{
|
||||
extern const char *Qst_DB_StrAnswerTypes[Qst_NUM_ANS_TYPES];
|
||||
extern const char *Txt_No_questions_found_matching_your_search_criteria;
|
||||
char *Query = NULL;
|
||||
long LengthQuery;
|
||||
unsigned NumItemInList;
|
||||
const char *Ptr;
|
||||
char TagText[Tag_MAX_BYTES_TAG + 1];
|
||||
char LongStr[Cns_MAX_DECIMAL_DIGITS_LONG + 1];
|
||||
char UnsignedStr[Cns_MAX_DECIMAL_DIGITS_UINT + 1];
|
||||
Qst_AnswerType_t AnsType;
|
||||
char CrsCodStr[Cns_MAX_DECIMAL_DIGITS_LONG + 1];
|
||||
|
||||
/***** Allocate space for query *****/
|
||||
if ((Query = malloc (Qst_MAX_BYTES_QUERY_QUESTIONS + 1)) == NULL)
|
||||
Err_NotEnoughMemoryExit ();
|
||||
|
||||
/***** Select questions *****/
|
||||
/* Begin query */
|
||||
Str_Copy (Query,"SELECT tst_questions.QstCod" // row[0]
|
||||
" FROM tst_questions",Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
if (!Questions->Tags.All)
|
||||
Str_Concat (Query,","
|
||||
"tst_question_tags,"
|
||||
"tst_tags",
|
||||
Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
|
||||
Str_Concat (Query," WHERE tst_questions.CrsCod='",Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
snprintf (CrsCodStr,sizeof (CrsCodStr),"%ld",Gbl.Hierarchy.Crs.CrsCod);
|
||||
Str_Concat (Query,CrsCodStr,Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
Str_Concat (Query,"' AND tst_questions.EditTime>=FROM_UNIXTIME('",
|
||||
Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
snprintf (LongStr,sizeof (LongStr),"%ld",
|
||||
(long) Gbl.DateRange.TimeUTC[Dat_STR_TIME]);
|
||||
Str_Concat (Query,LongStr,Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
Str_Concat (Query,"') AND tst_questions.EditTime<=FROM_UNIXTIME('",
|
||||
Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
snprintf (LongStr,sizeof (LongStr),"%ld",
|
||||
(long) Gbl.DateRange.TimeUTC[Dat_END_TIME]);
|
||||
Str_Concat (Query,LongStr,Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
Str_Concat (Query,"')",Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
|
||||
/* Add the tags selected */
|
||||
if (!Questions->Tags.All)
|
||||
{
|
||||
Str_Concat (Query," AND tst_questions.QstCod=tst_question_tags.QstCod"
|
||||
" AND tst_question_tags.TagCod=tst_tags.TagCod"
|
||||
" AND tst_tags.CrsCod='",
|
||||
Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
Str_Concat (Query,CrsCodStr,Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
Str_Concat (Query,"'",Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
LengthQuery = strlen (Query);
|
||||
NumItemInList = 0;
|
||||
Ptr = Questions->Tags.List;
|
||||
while (*Ptr)
|
||||
{
|
||||
Par_GetNextStrUntilSeparParamMult (&Ptr,TagText,Tag_MAX_BYTES_TAG);
|
||||
LengthQuery = LengthQuery + 35 + strlen (TagText) + 1;
|
||||
if (LengthQuery > Qst_MAX_BYTES_QUERY_QUESTIONS - 256)
|
||||
Err_QuerySizeExceededExit ();
|
||||
Str_Concat (Query,
|
||||
NumItemInList ? " OR tst_tags.TagTxt='" :
|
||||
" AND (tst_tags.TagTxt='",
|
||||
Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
Str_Concat (Query,TagText,Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
Str_Concat (Query,"'",Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
NumItemInList++;
|
||||
}
|
||||
Str_Concat (Query,")",Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
}
|
||||
|
||||
/* Add the types of answer selected */
|
||||
if (!Questions->AnswerTypes.All)
|
||||
{
|
||||
LengthQuery = strlen (Query);
|
||||
NumItemInList = 0;
|
||||
Ptr = Questions->AnswerTypes.List;
|
||||
while (*Ptr)
|
||||
{
|
||||
Par_GetNextStrUntilSeparParamMult (&Ptr,UnsignedStr,Tag_MAX_BYTES_TAG);
|
||||
AnsType = Qst_ConvertFromUnsignedStrToAnsTyp (UnsignedStr);
|
||||
LengthQuery = LengthQuery + 35 + strlen (Qst_DB_StrAnswerTypes[AnsType]) + 1;
|
||||
if (LengthQuery > Qst_MAX_BYTES_QUERY_QUESTIONS - 256)
|
||||
Err_QuerySizeExceededExit ();
|
||||
Str_Concat (Query,
|
||||
NumItemInList ? " OR tst_questions.AnsType='" :
|
||||
" AND (tst_questions.AnsType='",
|
||||
Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
Str_Concat (Query,Qst_DB_StrAnswerTypes[AnsType],Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
Str_Concat (Query,"'",Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
NumItemInList++;
|
||||
}
|
||||
Str_Concat (Query,")",Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
}
|
||||
|
||||
/* End the query */
|
||||
Str_Concat (Query," GROUP BY tst_questions.QstCod",Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
|
||||
switch (Questions->SelectedOrder)
|
||||
{
|
||||
case Qst_ORDER_STEM:
|
||||
Str_Concat (Query," ORDER BY tst_questions.Stem",
|
||||
Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
break;
|
||||
case Qst_ORDER_NUM_HITS:
|
||||
Str_Concat (Query," ORDER BY tst_questions.NumHits DESC,"
|
||||
"tst_questions.Stem",
|
||||
Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
break;
|
||||
case Qst_ORDER_AVERAGE_SCORE:
|
||||
Str_Concat (Query," ORDER BY tst_questions.Score/tst_questions.NumHits DESC,"
|
||||
"tst_questions.NumHits DESC,"
|
||||
"tst_questions.Stem",
|
||||
Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
break;
|
||||
case Qst_ORDER_NUM_HITS_NOT_BLANK:
|
||||
Str_Concat (Query," ORDER BY tst_questions.NumHitsNotBlank DESC,"
|
||||
"tst_questions.Stem",
|
||||
Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
break;
|
||||
case Qst_ORDER_AVERAGE_SCORE_NOT_BLANK:
|
||||
Str_Concat (Query," ORDER BY tst_questions.Score/tst_questions.NumHitsNotBlank DESC,"
|
||||
"tst_questions.NumHitsNotBlank DESC,"
|
||||
"tst_questions.Stem",
|
||||
Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Make the query */
|
||||
Questions->NumQsts = (unsigned) DB_QuerySELECT (mysql_res,"can not get questions",
|
||||
"%s",
|
||||
Query);
|
||||
if (Questions->NumQsts == 0)
|
||||
Ale_ShowAlert (Ale_INFO,Txt_No_questions_found_matching_your_search_criteria);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************** Change format of answers text / feedback ******************/
|
||||
/*****************************************************************************/
|
||||
|
@ -2590,24 +2444,6 @@ void Qst_FreeMediaOfQuestion (struct Qst_Question *Question)
|
|||
Med_MediaDestructor (&Question->Answer.Options[NumOpt].Media);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*************** Get answer type of a question from database *****************/
|
||||
/*****************************************************************************/
|
||||
|
||||
Qst_AnswerType_t Qst_GetQstAnswerTypeFromDB (long QstCod)
|
||||
{
|
||||
char StrAnsTypeDB[256];
|
||||
|
||||
/***** Get type of answer from database *****/
|
||||
DB_QuerySELECTString (StrAnsTypeDB,sizeof (StrAnsTypeDB) - 1,
|
||||
"can not get the type of a question",
|
||||
"SELECT AnsType"
|
||||
" FROM tst_questions"
|
||||
" WHERE QstCod=%ld",
|
||||
QstCod);
|
||||
return Qst_ConvertFromStrAnsTypDBToAnsTyp (StrAnsTypeDB);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/****************** Get data of a question from database *********************/
|
||||
/*****************************************************************************/
|
||||
|
@ -2622,23 +2458,7 @@ bool Qst_GetQstDataFromDB (struct Qst_Question *Question)
|
|||
unsigned NumOpt;
|
||||
|
||||
/***** Get question data from database *****/
|
||||
QuestionExists = (DB_QuerySELECT (&mysql_res,"can not get a question",
|
||||
"SELECT UNIX_TIMESTAMP(EditTime)," // row[0]
|
||||
"AnsType," // row[1]
|
||||
"Shuffle," // row[2]
|
||||
"Stem," // row[3]
|
||||
"Feedback," // row[4]
|
||||
"MedCod," // row[5]
|
||||
"NumHits," // row[6]
|
||||
"NumHitsNotBlank," // row[7]
|
||||
"Score" // row[8]
|
||||
" FROM tst_questions"
|
||||
" WHERE QstCod=%ld"
|
||||
" AND CrsCod=%ld", // Extra check
|
||||
Question->QstCod,
|
||||
Gbl.Hierarchy.Crs.CrsCod) != 0);
|
||||
|
||||
if (QuestionExists)
|
||||
if ((QuestionExists = (Qst_DB_GetQstData (&mysql_res,Question->QstCod) != 0)))
|
||||
{
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
|
||||
|
@ -2653,10 +2473,10 @@ bool Qst_GetQstDataFromDB (struct Qst_Question *Question)
|
|||
|
||||
/* Get the stem (row[3]) and the feedback (row[4]) */
|
||||
Question->Stem [0] = '\0';
|
||||
Question->Feedback[0] = '\0';
|
||||
if (row[3])
|
||||
if (row[3][0])
|
||||
Str_Copy (Question->Stem ,row[3],Cns_MAX_BYTES_TEXT);
|
||||
Question->Feedback[0] = '\0';
|
||||
if (row[4])
|
||||
if (row[4][0])
|
||||
Str_Copy (Question->Feedback,row[4],Cns_MAX_BYTES_TEXT);
|
||||
|
@ -2667,13 +2487,12 @@ bool Qst_GetQstDataFromDB (struct Qst_Question *Question)
|
|||
|
||||
/* Get number of hits
|
||||
(number of times that the question has been answered,
|
||||
including blank answers) (row[6]) */
|
||||
if (sscanf (row[6],"%lu",&Question->NumHits) != 1)
|
||||
Question->NumHits = 0;
|
||||
|
||||
/* Get number of hits not blank
|
||||
including blank answers) (row[6])
|
||||
and number of hits not blank
|
||||
(number of times that the question has been answered
|
||||
with a not blank answer) (row[7]) */
|
||||
if (sscanf (row[6],"%lu",&Question->NumHits ) != 1)
|
||||
Question->NumHits = 0;
|
||||
if (sscanf (row[7],"%lu",&Question->NumHitsNotBlank) != 1)
|
||||
Question->NumHitsNotBlank = 0;
|
||||
|
||||
|
@ -2788,20 +2607,10 @@ long Qst_GetMedCodFromDB (long CrsCod,long QstCod,int NumOpt)
|
|||
/***** Query depending on NumOpt *****/
|
||||
if (NumOpt < 0)
|
||||
// Get media associated to stem
|
||||
return DB_QuerySELECTCode ("can not get media",
|
||||
"SELECT MedCod"
|
||||
" FROM tst_questions"
|
||||
" WHERE QstCod=%ld"
|
||||
" AND CrsCod=%ld",
|
||||
QstCod,CrsCod);
|
||||
return Qst_DB_GetQstMedCod (CrsCod,QstCod);
|
||||
else
|
||||
// Get media associated to answer
|
||||
return DB_QuerySELECTCode ("can not get media",
|
||||
"SELECT MedCod"
|
||||
" FROM tst_answers"
|
||||
" WHERE QstCod=%ld"
|
||||
" AND AnsInd=%u",
|
||||
QstCod,(unsigned) NumOpt);
|
||||
return Qst_DB_GetAnswerMedCod (QstCod,(unsigned) NumOpt);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -3254,8 +3063,7 @@ bool Qst_CheckIfQuestionExistsInDB (struct Qst_Question *Question)
|
|||
|
||||
/***** Check if stem exists *****/
|
||||
NumQstsWithThisStem =
|
||||
(unsigned) DB_QuerySELECT (&mysql_res_qst,"can not check"
|
||||
" if a question exists",
|
||||
(unsigned) DB_QuerySELECT (&mysql_res_qst,"can not check if a question exists",
|
||||
"SELECT QstCod"
|
||||
" FROM tst_questions"
|
||||
" WHERE CrsCod=%ld"
|
||||
|
@ -3278,14 +3086,7 @@ bool Qst_CheckIfQuestionExistsInDB (struct Qst_Question *Question)
|
|||
Err_WrongQuestionExit ();
|
||||
|
||||
/* Get answers from this question */
|
||||
NumOptsExistingQstInDB =
|
||||
(unsigned) DB_QuerySELECT (&mysql_res_ans,"can not get the answer"
|
||||
" of a question",
|
||||
"SELECT Answer" // row[0]
|
||||
" FROM tst_answers"
|
||||
" WHERE QstCod=%ld"
|
||||
" ORDER BY AnsInd",
|
||||
Question->QstCod);
|
||||
NumOptsExistingQstInDB = Qst_DB_GetTextOfAnswers (&mysql_res_ans,Question->QstCod);
|
||||
|
||||
switch (Question->Answer.Type)
|
||||
{
|
||||
|
@ -3354,7 +3155,7 @@ void Qst_MoveMediaToDefinitiveDirectories (struct Qst_Question *Question)
|
|||
|
||||
/***** Media associated to question stem *****/
|
||||
CurrentMedCodInDB = Qst_GetMedCodFromDB (Gbl.Hierarchy.Crs.CrsCod,Question->QstCod,
|
||||
-1L); // Get current media code associated to stem
|
||||
-1); // Get current media code associated to stem
|
||||
Med_RemoveKeepOrStoreMedia (CurrentMedCodInDB,&Question->Media);
|
||||
|
||||
/****** Move media associated to answers *****/
|
||||
|
@ -3367,7 +3168,7 @@ void Qst_MoveMediaToDefinitiveDirectories (struct Qst_Question *Question)
|
|||
NumOpt++)
|
||||
{
|
||||
CurrentMedCodInDB = Qst_GetMedCodFromDB (Gbl.Hierarchy.Crs.CrsCod,Question->QstCod,
|
||||
NumOpt); // Get current media code associated to this option
|
||||
(int) NumOpt); // Get current media code associated to this option
|
||||
Med_RemoveKeepOrStoreMedia (CurrentMedCodInDB,&Question->Answer.Options[NumOpt].Media);
|
||||
}
|
||||
break;
|
||||
|
@ -3449,7 +3250,7 @@ void Qst_RemoveSelectedQsts (void)
|
|||
if (Tst_GetParamsTst (&Questions,Tst_EDIT_QUESTIONS)) // Get parameters
|
||||
{
|
||||
/***** Get question codes *****/
|
||||
Qst_GetQuestions (&Questions,&mysql_res); // Query database
|
||||
Questions.NumQsts = Qst_DB_GetQsts (&mysql_res,&Questions);
|
||||
|
||||
/***** Remove questions one by one *****/
|
||||
for (NumQst = 0;
|
||||
|
@ -3599,12 +3400,7 @@ void Qst_RemoveOneQstFromDB (long CrsCod,long QstCod)
|
|||
Tag_DB_RemoveUnusedTagsFromCrs (CrsCod);
|
||||
|
||||
/* Remove the question itself */
|
||||
DB_QueryDELETE ("can not remove a question",
|
||||
"DELETE FROM tst_questions"
|
||||
" WHERE QstCod=%ld"
|
||||
" AND CrsCod=%ld",
|
||||
QstCod,
|
||||
CrsCod);
|
||||
Qst_DB_RemoveQst (CrsCod,QstCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -3939,19 +3735,6 @@ void Qst_RemoveCrsQsts (long CrsCod)
|
|||
CrsCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************** Remove answers from a test question ********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Qst_DB_RemAnsFromQst (long QstCod)
|
||||
{
|
||||
/***** Remove answers *****/
|
||||
DB_QueryDELETE ("can not remove the answers of a question",
|
||||
"DELETE FROM tst_answers"
|
||||
" WHERE QstCod=%ld",
|
||||
QstCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************ Remove media associated to stem of a test question *************/
|
||||
/*****************************************************************************/
|
||||
|
@ -4058,24 +3841,6 @@ void Qst_RemoveAllMedFilesFromAnsOfAllQstsInCrs (long CrsCod)
|
|||
DB_FreeMySQLResult (&mysql_res);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*********** Get suffled/not-shuffled answers indexes of question ************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Qst_DB_GetShuffledAnswersIndexes (MYSQL_RES **mysql_res,
|
||||
const struct Qst_Question *Question)
|
||||
{
|
||||
return (unsigned)
|
||||
DB_QuerySELECT (mysql_res,"can not get questions of a game",
|
||||
"SELECT AnsInd" // row[0]
|
||||
" FROM tst_answers"
|
||||
" WHERE QstCod=%ld"
|
||||
" ORDER BY %s",
|
||||
Question->QstCod,
|
||||
Question->Answer.Shuffle ? "RAND()" : // Use RAND() because is really random; RAND(NOW()) repeats order
|
||||
"AnsInd");
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*********************** Get number of test questions ************************/
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -213,8 +213,6 @@ void Qst_WriteParamQstCod (unsigned NumQst,long QstCod);
|
|||
|
||||
void Qst_CheckIfNumberOfAnswersIsOne (const struct Qst_Question *Question);
|
||||
|
||||
void Qst_GetQuestions (struct Qst_Questions *Questions,MYSQL_RES **mysql_res);
|
||||
|
||||
void Qst_ChangeFormatAnswersText (struct Qst_Question *Question);
|
||||
void Qst_ChangeFormatAnswersFeedback (struct Qst_Question *Question);
|
||||
|
||||
|
@ -239,7 +237,6 @@ void Qst_FreeTextChoiceAnswer (struct Qst_Question *Question,unsigned NumOpt);
|
|||
void Qst_ResetMediaOfQuestion (struct Qst_Question *Question);
|
||||
void Qst_FreeMediaOfQuestion (struct Qst_Question *Question);
|
||||
|
||||
Qst_AnswerType_t Qst_GetQstAnswerTypeFromDB (long QstCod);
|
||||
bool Qst_GetQstDataFromDB (struct Qst_Question *Question);
|
||||
long Qst_GetMedCodFromDB (long CrsCod,long QstCod,int NumOpt);
|
||||
void Qst_GetMediaFromDB (long CrsCod,long QstCod,int NumOpt,
|
||||
|
@ -275,15 +272,11 @@ unsigned Qst_CountNumAnswerTypesInList (const struct Qst_AnswerTypes *AnswerType
|
|||
unsigned Qst_CountNumQuestionsInList (const char *ListQuestions);
|
||||
|
||||
void Qst_RemoveCrsQsts (long CrsCod);
|
||||
void Qst_DB_RemAnsFromQst (long QstCod);
|
||||
void Qst_RemoveMediaFromStemOfQst (long CrsCod,long QstCod);
|
||||
void Qst_RemoveMediaFromAllAnsOfQst (long CrsCod,long QstCod);
|
||||
void Qst_RemoveAllMedFilesFromStemOfAllQstsInCrs (long CrsCod);
|
||||
void Qst_RemoveAllMedFilesFromAnsOfAllQstsInCrs (long CrsCod);
|
||||
|
||||
unsigned Qst_DB_GetShuffledAnswersIndexes (MYSQL_RES **mysql_res,
|
||||
const struct Qst_Question *Question);
|
||||
|
||||
unsigned Qst_GetNumQuestions (HieLvl_Level_t Scope,Qst_AnswerType_t AnsType,
|
||||
struct Qst_Stats *Stats);
|
||||
|
||||
|
|
|
@ -59,6 +59,8 @@ const char *Qst_DB_StrAnswerTypes[Qst_NUM_ANS_TYPES] =
|
|||
/**************************** Private constants ******************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
#define Qst_MAX_BYTES_QUERY_QUESTIONS (16 * 1024 - 1)
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************************* Private types *******************************/
|
||||
/*****************************************************************************/
|
||||
|
@ -103,13 +105,157 @@ void Qst_DB_UpdateQstScore (long QstCod,bool AnswerIsNotBlank,double Score)
|
|||
Str_SetDecimalPointToLocal (); // Return to local system
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************** Get several test questions from database ******************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Qst_DB_GetQsts (MYSQL_RES **mysql_res,
|
||||
const struct Qst_Questions *Questions)
|
||||
{
|
||||
extern const char *Qst_DB_StrAnswerTypes[Qst_NUM_ANS_TYPES];
|
||||
extern const char *Txt_No_questions_found_matching_your_search_criteria;
|
||||
char *Query = NULL;
|
||||
long LengthQuery;
|
||||
unsigned NumItemInList;
|
||||
const char *Ptr;
|
||||
char TagText[Tag_MAX_BYTES_TAG + 1];
|
||||
char LongStr[Cns_MAX_DECIMAL_DIGITS_LONG + 1];
|
||||
char UnsignedStr[Cns_MAX_DECIMAL_DIGITS_UINT + 1];
|
||||
Qst_AnswerType_t AnsType;
|
||||
char CrsCodStr[Cns_MAX_DECIMAL_DIGITS_LONG + 1];
|
||||
unsigned NumQsts;
|
||||
|
||||
/***** Allocate space for query *****/
|
||||
if ((Query = malloc (Qst_MAX_BYTES_QUERY_QUESTIONS + 1)) == NULL)
|
||||
Err_NotEnoughMemoryExit ();
|
||||
|
||||
/***** Select questions *****/
|
||||
/* Begin query */
|
||||
Str_Copy (Query,"SELECT tst_questions.QstCod" // row[0]
|
||||
" FROM tst_questions",Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
if (!Questions->Tags.All)
|
||||
Str_Concat (Query,","
|
||||
"tst_question_tags,"
|
||||
"tst_tags",
|
||||
Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
|
||||
Str_Concat (Query," WHERE tst_questions.CrsCod='",
|
||||
Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
snprintf (CrsCodStr,sizeof (CrsCodStr),"%ld",Gbl.Hierarchy.Crs.CrsCod);
|
||||
Str_Concat (Query,CrsCodStr,Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
Str_Concat (Query,"' AND tst_questions.EditTime>=FROM_UNIXTIME('",
|
||||
Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
snprintf (LongStr,sizeof (LongStr),"%ld",
|
||||
(long) Gbl.DateRange.TimeUTC[Dat_STR_TIME]);
|
||||
Str_Concat (Query,LongStr,Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
Str_Concat (Query,"') AND tst_questions.EditTime<=FROM_UNIXTIME('",
|
||||
Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
snprintf (LongStr,sizeof (LongStr),"%ld",
|
||||
(long) Gbl.DateRange.TimeUTC[Dat_END_TIME]);
|
||||
Str_Concat (Query,LongStr,Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
Str_Concat (Query,"')",Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
|
||||
/* Add the tags selected */
|
||||
if (!Questions->Tags.All)
|
||||
{
|
||||
Str_Concat (Query," AND tst_questions.QstCod=tst_question_tags.QstCod"
|
||||
" AND tst_question_tags.TagCod=tst_tags.TagCod"
|
||||
" AND tst_tags.CrsCod='",
|
||||
Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
Str_Concat (Query,CrsCodStr,Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
Str_Concat (Query,"'",Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
LengthQuery = strlen (Query);
|
||||
NumItemInList = 0;
|
||||
Ptr = Questions->Tags.List;
|
||||
while (*Ptr)
|
||||
{
|
||||
Par_GetNextStrUntilSeparParamMult (&Ptr,TagText,Tag_MAX_BYTES_TAG);
|
||||
LengthQuery = LengthQuery + 35 + strlen (TagText) + 1;
|
||||
if (LengthQuery > Qst_MAX_BYTES_QUERY_QUESTIONS - 256)
|
||||
Err_QuerySizeExceededExit ();
|
||||
Str_Concat (Query,
|
||||
NumItemInList ? " OR tst_tags.TagTxt='" :
|
||||
" AND (tst_tags.TagTxt='",
|
||||
Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
Str_Concat (Query,TagText,Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
Str_Concat (Query,"'",Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
NumItemInList++;
|
||||
}
|
||||
Str_Concat (Query,")",Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
}
|
||||
|
||||
/* Add the types of answer selected */
|
||||
if (!Questions->AnswerTypes.All)
|
||||
{
|
||||
LengthQuery = strlen (Query);
|
||||
NumItemInList = 0;
|
||||
Ptr = Questions->AnswerTypes.List;
|
||||
while (*Ptr)
|
||||
{
|
||||
Par_GetNextStrUntilSeparParamMult (&Ptr,UnsignedStr,Tag_MAX_BYTES_TAG);
|
||||
AnsType = Qst_ConvertFromUnsignedStrToAnsTyp (UnsignedStr);
|
||||
LengthQuery = LengthQuery + 35 + strlen (Qst_DB_StrAnswerTypes[AnsType]) + 1;
|
||||
if (LengthQuery > Qst_MAX_BYTES_QUERY_QUESTIONS - 256)
|
||||
Err_QuerySizeExceededExit ();
|
||||
Str_Concat (Query,
|
||||
NumItemInList ? " OR tst_questions.AnsType='" :
|
||||
" AND (tst_questions.AnsType='",
|
||||
Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
Str_Concat (Query,Qst_DB_StrAnswerTypes[AnsType],Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
Str_Concat (Query,"'",Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
NumItemInList++;
|
||||
}
|
||||
Str_Concat (Query,")",Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
}
|
||||
|
||||
/* End the query */
|
||||
Str_Concat (Query," GROUP BY tst_questions.QstCod",Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
|
||||
switch (Questions->SelectedOrder)
|
||||
{
|
||||
case Qst_ORDER_STEM:
|
||||
Str_Concat (Query," ORDER BY tst_questions.Stem",
|
||||
Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
break;
|
||||
case Qst_ORDER_NUM_HITS:
|
||||
Str_Concat (Query," ORDER BY tst_questions.NumHits DESC,"
|
||||
"tst_questions.Stem",
|
||||
Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
break;
|
||||
case Qst_ORDER_AVERAGE_SCORE:
|
||||
Str_Concat (Query," ORDER BY tst_questions.Score/tst_questions.NumHits DESC,"
|
||||
"tst_questions.NumHits DESC,"
|
||||
"tst_questions.Stem",
|
||||
Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
break;
|
||||
case Qst_ORDER_NUM_HITS_NOT_BLANK:
|
||||
Str_Concat (Query," ORDER BY tst_questions.NumHitsNotBlank DESC,"
|
||||
"tst_questions.Stem",
|
||||
Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
break;
|
||||
case Qst_ORDER_AVERAGE_SCORE_NOT_BLANK:
|
||||
Str_Concat (Query," ORDER BY tst_questions.Score/tst_questions.NumHitsNotBlank DESC,"
|
||||
"tst_questions.NumHitsNotBlank DESC,"
|
||||
"tst_questions.Stem",
|
||||
Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Make the query */
|
||||
if ((NumQsts = (unsigned)
|
||||
DB_QuerySELECT (mysql_res,"can not get questions",
|
||||
"%s",
|
||||
Query)) == 0)
|
||||
Ale_ShowAlert (Ale_INFO,Txt_No_questions_found_matching_your_search_criteria);
|
||||
|
||||
return NumQsts;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************* Get questions for a new test print **********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
#define Tst_MAX_BYTES_QUERY_QUESTIONS (16 * 1024 - 1)
|
||||
|
||||
unsigned Qst_DB_GetQuestionsForNewTestPrint (MYSQL_RES **mysql_res,
|
||||
unsigned Qst_DB_GetQstsForNewTestPrint (MYSQL_RES **mysql_res,
|
||||
const struct Qst_Questions *Questions)
|
||||
{
|
||||
extern const char *Qst_DB_StrAnswerTypes[Qst_NUM_ANS_TYPES];
|
||||
|
@ -123,7 +269,7 @@ unsigned Qst_DB_GetQuestionsForNewTestPrint (MYSQL_RES **mysql_res,
|
|||
char StrNumQsts[Cns_MAX_DECIMAL_DIGITS_UINT + 1];
|
||||
|
||||
/***** Allocate space for query *****/
|
||||
if ((Query = malloc (Tst_MAX_BYTES_QUERY_QUESTIONS + 1)) == NULL)
|
||||
if ((Query = malloc (Qst_MAX_BYTES_QUERY_QUESTIONS + 1)) == NULL)
|
||||
Err_NotEnoughMemoryExit ();
|
||||
|
||||
/***** Select questions without hidden tags *****/
|
||||
|
@ -131,7 +277,7 @@ unsigned Qst_DB_GetQuestionsForNewTestPrint (MYSQL_RES **mysql_res,
|
|||
// Reject questions with any tag hidden
|
||||
// Select only questions with tags
|
||||
// DISTINCTROW is necessary to not repeat questions
|
||||
snprintf (Query,Tst_MAX_BYTES_QUERY_QUESTIONS + 1,
|
||||
snprintf (Query,Qst_MAX_BYTES_QUERY_QUESTIONS + 1,
|
||||
"SELECT DISTINCTROW tst_questions.QstCod," // row[0]
|
||||
"tst_questions.AnsType," // row[1]
|
||||
"tst_questions.Shuffle" // row[2]
|
||||
|
@ -160,17 +306,17 @@ unsigned Qst_DB_GetQuestionsForNewTestPrint (MYSQL_RES **mysql_res,
|
|||
{
|
||||
Par_GetNextStrUntilSeparParamMult (&Ptr,TagText,Tag_MAX_BYTES_TAG);
|
||||
LengthQuery = LengthQuery + 35 + strlen (TagText) + 1;
|
||||
if (LengthQuery > Tst_MAX_BYTES_QUERY_QUESTIONS - 128)
|
||||
if (LengthQuery > Qst_MAX_BYTES_QUERY_QUESTIONS - 128)
|
||||
Err_QuerySizeExceededExit ();
|
||||
Str_Concat (Query,
|
||||
NumItemInList ? " OR tst_tags.TagTxt='" :
|
||||
" AND (tst_tags.TagTxt='",
|
||||
Tst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
Str_Concat (Query,TagText,Tst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
Str_Concat (Query,"'",Tst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
Str_Concat (Query,TagText,Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
Str_Concat (Query,"'",Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
NumItemInList++;
|
||||
}
|
||||
Str_Concat (Query,")",Tst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
Str_Concat (Query,")",Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
}
|
||||
|
||||
/* Add answer types selected */
|
||||
|
@ -184,23 +330,23 @@ unsigned Qst_DB_GetQuestionsForNewTestPrint (MYSQL_RES **mysql_res,
|
|||
Par_GetNextStrUntilSeparParamMult (&Ptr,UnsignedStr,Tag_MAX_BYTES_TAG);
|
||||
AnswerType = Qst_ConvertFromUnsignedStrToAnsTyp (UnsignedStr);
|
||||
LengthQuery = LengthQuery + 35 + strlen (Qst_DB_StrAnswerTypes[AnswerType]) + 1;
|
||||
if (LengthQuery > Tst_MAX_BYTES_QUERY_QUESTIONS - 128)
|
||||
if (LengthQuery > Qst_MAX_BYTES_QUERY_QUESTIONS - 128)
|
||||
Err_QuerySizeExceededExit ();
|
||||
Str_Concat (Query,
|
||||
NumItemInList ? " OR tst_questions.AnsType='" :
|
||||
" AND (tst_questions.AnsType='",
|
||||
Tst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
Str_Concat (Query,Qst_DB_StrAnswerTypes[AnswerType],Tst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
Str_Concat (Query,"'",Tst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
Str_Concat (Query,Qst_DB_StrAnswerTypes[AnswerType],Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
Str_Concat (Query,"'",Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
NumItemInList++;
|
||||
}
|
||||
Str_Concat (Query,")",Tst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
Str_Concat (Query,")",Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
}
|
||||
|
||||
/* End query */
|
||||
Str_Concat (Query," ORDER BY RAND() LIMIT ",Tst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
Str_Concat (Query," ORDER BY RAND() LIMIT ",Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
snprintf (StrNumQsts,sizeof (StrNumQsts),"%u",Questions->NumQsts);
|
||||
Str_Concat (Query,StrNumQsts,Tst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
Str_Concat (Query,StrNumQsts,Qst_MAX_BYTES_QUERY_QUESTIONS);
|
||||
/*
|
||||
if (Gbl.Usrs.Me.Roles.LoggedRole == Rol_SYS_ADM)
|
||||
Lay_ShowAlert (Lay_INFO,Query);
|
||||
|
@ -756,6 +902,63 @@ unsigned Qst_DB_GetNumCrssWithPluggableQsts (HieLvl_Level_t Scope,
|
|||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/****************** Get data of a question from database *********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Qst_DB_GetQstData (MYSQL_RES **mysql_res,long QstCod)
|
||||
{
|
||||
return (unsigned)
|
||||
DB_QuerySELECT (mysql_res,"can not get a question",
|
||||
"SELECT UNIX_TIMESTAMP(EditTime)," // row[0]
|
||||
"AnsType," // row[1]
|
||||
"Shuffle," // row[2]
|
||||
"Stem," // row[3]
|
||||
"Feedback," // row[4]
|
||||
"MedCod," // row[5]
|
||||
"NumHits," // row[6]
|
||||
"NumHitsNotBlank," // row[7]
|
||||
"Score" // row[8]
|
||||
" FROM tst_questions"
|
||||
" WHERE QstCod=%ld"
|
||||
" AND CrsCod=%ld", // Extra check
|
||||
QstCod,
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*************** Get answer type of a question from database *****************/
|
||||
/*****************************************************************************/
|
||||
|
||||
Qst_AnswerType_t Qst_DB_GetQstAnswerType (long QstCod)
|
||||
{
|
||||
char StrAnsTypeDB[256];
|
||||
|
||||
/***** Get type of answer from database *****/
|
||||
DB_QuerySELECTString (StrAnsTypeDB,sizeof (StrAnsTypeDB) - 1,
|
||||
"can not get the type of a question",
|
||||
"SELECT AnsType"
|
||||
" FROM tst_questions"
|
||||
" WHERE QstCod=%ld",
|
||||
QstCod);
|
||||
return Qst_ConvertFromStrAnsTypDBToAnsTyp (StrAnsTypeDB);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/******** Get media code associated with the stem of a test question *********/
|
||||
/*****************************************************************************/
|
||||
|
||||
long Qst_DB_GetQstMedCod (long CrsCod,long QstCod)
|
||||
{
|
||||
return DB_QuerySELECTCode ("can not get media",
|
||||
"SELECT MedCod"
|
||||
" FROM tst_questions"
|
||||
" WHERE QstCod=%ld"
|
||||
" AND CrsCod=%ld", // Extra check
|
||||
QstCod,
|
||||
CrsCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************ Get number of answers of a question from database **************/
|
||||
/*****************************************************************************/
|
||||
|
@ -815,3 +1018,63 @@ unsigned Qst_DB_GetTextOfAnswers (MYSQL_RES **mysql_res,long QstCod)
|
|||
|
||||
return NumOptions;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*********** Get suffled/not-shuffled answers indexes of question ************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Qst_DB_GetShuffledAnswersIndexes (MYSQL_RES **mysql_res,
|
||||
const struct Qst_Question *Question)
|
||||
{
|
||||
return (unsigned)
|
||||
DB_QuerySELECT (mysql_res,"can not get questions of a game",
|
||||
"SELECT AnsInd" // row[0]
|
||||
" FROM tst_answers"
|
||||
" WHERE QstCod=%ld"
|
||||
" ORDER BY %s",
|
||||
Question->QstCod,
|
||||
Question->Answer.Shuffle ? "RAND()" : // Use RAND() because is really random; RAND(NOW()) repeats order
|
||||
"AnsInd");
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********* Get media code associated to an answer of a test question *********/
|
||||
/*****************************************************************************/
|
||||
|
||||
long Qst_DB_GetAnswerMedCod (long QstCod,unsigned AnsInd)
|
||||
{
|
||||
return DB_QuerySELECTCode ("can not get media",
|
||||
"SELECT MedCod"
|
||||
" FROM tst_answers"
|
||||
" WHERE QstCod=%ld"
|
||||
" AND AnsInd=%u",
|
||||
QstCod,
|
||||
AnsInd);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********************** Remove a question from database **********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Qst_DB_RemoveQst (long CrsCod,long QstCod)
|
||||
{
|
||||
DB_QueryDELETE ("can not remove a question",
|
||||
"DELETE FROM tst_questions"
|
||||
" WHERE QstCod=%ld"
|
||||
" AND CrsCod=%ld",
|
||||
QstCod,
|
||||
CrsCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************** Remove answers from a test question ********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Qst_DB_RemAnsFromQst (long QstCod)
|
||||
{
|
||||
/***** Remove answers *****/
|
||||
DB_QueryDELETE ("can not remove the answers of a question",
|
||||
"DELETE FROM tst_answers"
|
||||
" WHERE QstCod=%ld",
|
||||
QstCod);
|
||||
}
|
||||
|
|
|
@ -51,7 +51,9 @@
|
|||
|
||||
void Qst_DB_UpdateQstScore (long QstCod,bool AnswerIsNotBlank,double Score);
|
||||
|
||||
unsigned Qst_DB_GetQuestionsForNewTestPrint (MYSQL_RES **mysql_res,
|
||||
unsigned Qst_DB_GetQsts (MYSQL_RES **mysql_res,
|
||||
const struct Qst_Questions *Questions);
|
||||
unsigned Qst_DB_GetQstsForNewTestPrint (MYSQL_RES **mysql_res,
|
||||
const struct Qst_Questions *Questions);
|
||||
unsigned Qst_DB_GetNumQsts (MYSQL_RES **mysql_res,
|
||||
HieLvl_Level_t Scope,Qst_AnswerType_t AnsType);
|
||||
|
@ -60,8 +62,18 @@ unsigned Qst_DB_GetNumCrssWithQsts (HieLvl_Level_t Scope,
|
|||
unsigned Qst_DB_GetNumCrssWithPluggableQsts (HieLvl_Level_t Scope,
|
||||
Qst_AnswerType_t AnsType);
|
||||
|
||||
unsigned Qst_DB_GetQstData (MYSQL_RES **mysql_res,long QstCod);
|
||||
Qst_AnswerType_t Qst_DB_GetQstAnswerType (long QstCod);
|
||||
long Qst_DB_GetQstMedCod (long CrsCod,long QstCod);
|
||||
|
||||
unsigned Qst_DB_GetNumAnswersQst (long QstCod);
|
||||
unsigned Qst_DB_GetDataOfAnswers (MYSQL_RES **mysql_res,long QstCod,bool Shuffle);
|
||||
unsigned Qst_DB_GetTextOfAnswers (MYSQL_RES **mysql_res,long QstCod);
|
||||
unsigned Qst_DB_GetShuffledAnswersIndexes (MYSQL_RES **mysql_res,
|
||||
const struct Qst_Question *Question);
|
||||
long Qst_DB_GetAnswerMedCod (long QstCod,unsigned AnsInd);
|
||||
|
||||
void Qst_DB_RemoveQst (long CrsCod,long QstCod);
|
||||
void Qst_DB_RemAnsFromQst (long QstCod);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -896,7 +896,7 @@ static void Rep_GetAndWriteMyCurrentCrss (Rol_Role_t Role,
|
|||
unsigned NumCrs;
|
||||
long CrsCod;
|
||||
|
||||
NumCrss = Usr_GetNumCrssOfUsrWithARole (Gbl.Usrs.Me.UsrDat.UsrCod,Role);
|
||||
NumCrss = Usr_DB_GetNumCrssOfUsrWithARole (Gbl.Usrs.Me.UsrDat.UsrCod,Role);
|
||||
fprintf (Gbl.F.Rep,"<li>");
|
||||
fprintf (Gbl.F.Rep,Txt_USER_in_COURSE,
|
||||
Txt_ROLES_SINGUL_Abc[Role][Gbl.Usrs.Me.UsrDat.Sex]);
|
||||
|
|
|
@ -119,18 +119,18 @@ void Rol_SetMyRoles (void)
|
|||
if (Gbl.Hierarchy.Ins.InsCod > 0)
|
||||
{
|
||||
/* Check if I am and administrator of current institution */
|
||||
ICanBeInsAdm = Usr_CheckIfUsrIsAdm (Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
ICanBeInsAdm = Usr_DB_CheckIfUsrIsAdm (Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
HieLvl_INS,
|
||||
Gbl.Hierarchy.Ins.InsCod);
|
||||
if (Gbl.Hierarchy.Ctr.CtrCod > 0)
|
||||
{
|
||||
/* Check if I am and administrator of current center */
|
||||
ICanBeCtrAdm = Usr_CheckIfUsrIsAdm (Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
ICanBeCtrAdm = Usr_DB_CheckIfUsrIsAdm (Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
HieLvl_CTR,
|
||||
Gbl.Hierarchy.Ctr.CtrCod);
|
||||
if (Gbl.Hierarchy.Deg.DegCod > 0)
|
||||
/* Check if I am and administrator of current degree */
|
||||
ICanBeDegAdm = Usr_CheckIfUsrIsAdm (Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
ICanBeDegAdm = Usr_DB_CheckIfUsrIsAdm (Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
HieLvl_DEG,
|
||||
Gbl.Hierarchy.Deg.DegCod);
|
||||
}
|
||||
|
|
|
@ -491,7 +491,7 @@ void Tst_PutIconsTests (__attribute__((unused)) void *Args)
|
|||
/************** Get questions for a new test from the database ***************/
|
||||
/*****************************************************************************/
|
||||
|
||||
#define Tst_MAX_BYTES_QUERY_QUESTIONS (16 * 1024 - 1)
|
||||
#define Qst_MAX_BYTES_QUERY_QUESTIONS (16 * 1024 - 1)
|
||||
|
||||
static void Tst_GetQuestionsForNewTest (struct Qst_Questions *Questions,
|
||||
struct TstPrn_Print *Print)
|
||||
|
@ -509,7 +509,7 @@ static void Tst_GetQuestionsForNewTest (struct Qst_Questions *Questions,
|
|||
|
||||
/***** Get questions and answers from database *****/
|
||||
Print->NumQsts.All =
|
||||
Questions->NumQsts = Qst_DB_GetQuestionsForNewTestPrint (&mysql_res,Questions);
|
||||
Questions->NumQsts = Qst_DB_GetQstsForNewTestPrint (&mysql_res,Questions);
|
||||
|
||||
for (QstInd = 0;
|
||||
QstInd < Print->NumQsts.All;
|
||||
|
|
|
@ -746,7 +746,7 @@ void TstPrn_ComputeScoresAndStoreQuestionsOfPrint (struct TstPrn_Print *Print,
|
|||
/* Compute question score */
|
||||
Qst_QstConstructor (&Question);
|
||||
Question.QstCod = Print->PrintedQuestions[QstInd].QstCod;
|
||||
Question.Answer.Type = Qst_GetQstAnswerTypeFromDB (Question.QstCod);
|
||||
Question.Answer.Type = Qst_DB_GetQstAnswerType (Question.QstCod);
|
||||
TstPrn_ComputeAnswerScore (&Print->PrintedQuestions[QstInd],&Question);
|
||||
Qst_QstDestructor (&Question);
|
||||
|
||||
|
|
69
swad_user.c
69
swad_user.c
|
@ -166,7 +166,7 @@ static void Usr_GetMyLastData (void);
|
|||
static void Usr_GetUsrCommentsFromString (char *Str,struct UsrData *UsrDat);
|
||||
static Usr_Sex_t Usr_GetSexFromStr (const char *Str);
|
||||
|
||||
static bool Usr_CheckIfMyBirthdayHasNotBeenCongratulated (void);
|
||||
static bool Usr_DB_CheckIfMyBirthdayHasNotBeenCongratulated (void);
|
||||
static void Usr_InsertMyBirthday (void);
|
||||
|
||||
static void Usr_RemoveTemporaryTableMyCourses (void);
|
||||
|
@ -182,7 +182,7 @@ static void Usr_SetMyPrefsAndRoles (void);
|
|||
|
||||
static void Usr_PutLinkToLogOut (__attribute__((unused)) void *Args);
|
||||
|
||||
static void Usr_InsertMyLastData (void);
|
||||
static void Usr_DB_InsertMyLastData (void);
|
||||
|
||||
static void Usr_WriteRowGstAllData (struct UsrData *UsrDat);
|
||||
static void Usr_WriteRowStdAllData (struct UsrData *UsrDat,char *GroupNames);
|
||||
|
@ -238,15 +238,15 @@ static void Usr_ListRowsAllDataTchs (Rol_Role_t Role,
|
|||
static void Usr_GetAndUpdateUsrListType (void);
|
||||
static void Usr_GetUsrListTypeFromForm (void);
|
||||
static void Usr_GetMyUsrListTypeFromDB (void);
|
||||
static void Usr_UpdateMyUsrListTypeInDB (void);
|
||||
static void Usr_DB_UpdateMyUsrListType (void);
|
||||
|
||||
static void Usr_GetParamColsClassPhotoFromForm (void);
|
||||
static void Usr_GetMyColsClassPhotoFromDB (void);
|
||||
static void Usr_UpdateMyColsClassPhotoInDB (void);
|
||||
static void Usr_DB_UpdateMyColsClassPhoto (void);
|
||||
|
||||
static void Usr_GetAndUpdatePrefAboutListWithPhotos (void);
|
||||
static bool Usr_GetParamListWithPhotosFromForm (void);
|
||||
static void Usr_UpdateMyPrefAboutListWithPhotosPhotoInDB (void);
|
||||
static void Usr_DB_UpdateMyPrefAboutListWithPhotosPhoto (void);
|
||||
|
||||
static void Usr_PutLinkToSeeAdmins (void);
|
||||
static void Usr_PutLinkToSeeGuests (void);
|
||||
|
@ -783,7 +783,7 @@ static void Usr_GetMyLastData (void)
|
|||
|
||||
/***** Create entry for me in table of user's last data *****/
|
||||
Usr_ResetMyLastData ();
|
||||
Usr_InsertMyLastData ();
|
||||
Usr_DB_InsertMyLastData ();
|
||||
}
|
||||
else if (NumRows == 1)
|
||||
{
|
||||
|
@ -922,7 +922,7 @@ void Usr_FlushCachesUsr (void)
|
|||
/***** Check if a user is an administrator of a degree/center/institution ****/
|
||||
/*****************************************************************************/
|
||||
|
||||
bool Usr_CheckIfUsrIsAdm (long UsrCod,HieLvl_Level_t Scope,long Cod)
|
||||
bool Usr_DB_CheckIfUsrIsAdm (long UsrCod,HieLvl_Level_t Scope,long Cod)
|
||||
{
|
||||
/***** Get if a user is administrator of a degree from database *****/
|
||||
return (DB_QueryCOUNT ("can not check if a user is administrator",
|
||||
|
@ -1051,7 +1051,7 @@ bool Usr_ICanEditOtherUsr (const struct UsrData *UsrDat)
|
|||
/********************* Get number of courses of a user ***********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Usr_GetNumCrssOfUsr (long UsrCod)
|
||||
unsigned Usr_DB_GetNumCrssOfUsr (long UsrCod)
|
||||
{
|
||||
/***** Get the number of courses of a user from database ******/
|
||||
return (unsigned)
|
||||
|
@ -1066,7 +1066,7 @@ unsigned Usr_GetNumCrssOfUsr (long UsrCod)
|
|||
/*************** Get number of courses of a user not accepted ****************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Usr_GetNumCrssOfUsrNotAccepted (long UsrCod)
|
||||
unsigned Usr_DB_GetNumCrssOfUsrNotAccepted (long UsrCod)
|
||||
{
|
||||
/***** Get the number of courses of a user not accepted from database ******/
|
||||
return (unsigned)
|
||||
|
@ -1082,7 +1082,7 @@ unsigned Usr_GetNumCrssOfUsrNotAccepted (long UsrCod)
|
|||
/********* Get number of courses in with a user have a given role ************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Usr_GetNumCrssOfUsrWithARole (long UsrCod,Rol_Role_t Role)
|
||||
unsigned Usr_DB_GetNumCrssOfUsrWithARole (long UsrCod,Rol_Role_t Role)
|
||||
{
|
||||
/***** Get the number of courses of a user with a role from database ******/
|
||||
return (unsigned)
|
||||
|
@ -1099,7 +1099,7 @@ unsigned Usr_GetNumCrssOfUsrWithARole (long UsrCod,Rol_Role_t Role)
|
|||
/********* Get number of courses in with a user have a given role ************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Usr_GetNumCrssOfUsrWithARoleNotAccepted (long UsrCod,Rol_Role_t Role)
|
||||
unsigned Usr_DB_GetNumCrssOfUsrWithARoleNotAccepted (long UsrCod,Rol_Role_t Role)
|
||||
{
|
||||
/***** Get the number of courses of a user with a role from database ******/
|
||||
return (unsigned)
|
||||
|
@ -1568,7 +1568,7 @@ void Usr_GetMyCountrs (void)
|
|||
Gbl.Usrs.Me.MyCtys.Num = 0;
|
||||
|
||||
/***** Get my institutions from database *****/
|
||||
NumCtys = Usr_GetCtysFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,&mysql_res);
|
||||
NumCtys = Usr_DB_GetCtysFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,&mysql_res);
|
||||
for (NumCty = 0;
|
||||
NumCty < NumCtys;
|
||||
NumCty++)
|
||||
|
@ -2247,7 +2247,7 @@ bool Usr_CheckIfIBelongToCrs (long CrsCod)
|
|||
/*****************************************************************************/
|
||||
// Returns the number of rows of the result
|
||||
|
||||
unsigned Usr_GetCtysFromUsr (long UsrCod,MYSQL_RES **mysql_res)
|
||||
unsigned Usr_DB_GetCtysFromUsr (long UsrCod,MYSQL_RES **mysql_res)
|
||||
{
|
||||
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
|
||||
|
||||
|
@ -2500,7 +2500,7 @@ void Usr_GetMainDeg (long UsrCod,
|
|||
/******** Check if a user exists with a given encrypted user's code **********/
|
||||
/*****************************************************************************/
|
||||
|
||||
bool Usr_ChkIfEncryptedUsrCodExists (const char EncryptedUsrCod[Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64])
|
||||
bool Usr_DB_ChkIfEncryptedUsrCodExists (const char EncryptedUsrCod[Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64])
|
||||
{
|
||||
/***** Get if an encrypted user's code already existed in database *****/
|
||||
return (DB_QueryCOUNT ("can not check if an encrypted user's code"
|
||||
|
@ -2659,7 +2659,7 @@ void Usr_WelcomeUsr (void)
|
|||
/***** Birthday congratulation *****/
|
||||
if (Gbl.Usrs.Me.UsrDat.Birthday.Day == Gbl.Now.Date.Day &&
|
||||
Gbl.Usrs.Me.UsrDat.Birthday.Month == Gbl.Now.Date.Month)
|
||||
if (Usr_CheckIfMyBirthdayHasNotBeenCongratulated ())
|
||||
if (Usr_DB_CheckIfMyBirthdayHasNotBeenCongratulated ())
|
||||
{
|
||||
/* Mark my birthday as already congratulated */
|
||||
Usr_InsertMyBirthday ();
|
||||
|
@ -2753,7 +2753,7 @@ void Usr_CreateBirthdayStrDB (const struct UsrData *UsrDat,
|
|||
/*************** Check if my birthday is already congratulated ***************/
|
||||
/*****************************************************************************/
|
||||
|
||||
static bool Usr_CheckIfMyBirthdayHasNotBeenCongratulated (void)
|
||||
static bool Usr_DB_CheckIfMyBirthdayHasNotBeenCongratulated (void)
|
||||
{
|
||||
/***** Delete old birthdays *****/
|
||||
return (DB_QueryCOUNT ("can not check if my birthday has been congratulated",
|
||||
|
@ -3574,7 +3574,7 @@ bool Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (struct UsrData *UsrDat,
|
|||
Usr_GetRoleInCurrentCrs_t GetRoleInCurrentCrs)
|
||||
{
|
||||
/***** Check if a user exists having this user's code *****/
|
||||
if (Usr_ChkIfUsrCodExists (UsrDat->UsrCod))
|
||||
if (Usr_DB_ChkIfUsrCodExists (UsrDat->UsrCod))
|
||||
{
|
||||
/* Get user's data */
|
||||
Usr_GetAllUsrDataFromUsrCod (UsrDat,GetPrefs,GetRoleInCurrentCrs);
|
||||
|
@ -3615,7 +3615,7 @@ void Usr_UpdateMyLastData (void)
|
|||
(unsigned) Gbl.Usrs.Me.Role.Logged,
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||
else
|
||||
Usr_InsertMyLastData ();
|
||||
Usr_DB_InsertMyLastData ();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -3638,7 +3638,7 @@ void Usr_DB_UpdateMyLastWhatToSearch (void)
|
|||
/*************** Create new entry for my last data in database ***************/
|
||||
/*****************************************************************************/
|
||||
|
||||
static void Usr_InsertMyLastData (void)
|
||||
static void Usr_DB_InsertMyLastData (void)
|
||||
{
|
||||
/***** Insert my last accessed course, tab and time of click in database *****/
|
||||
DB_QueryINSERT ("can not insert last user's data",
|
||||
|
@ -4170,7 +4170,7 @@ static void Usr_WriteUsrData (const char *BgColor,
|
|||
/*****************************************************************************/
|
||||
// Returns user's code or -1 if no user found
|
||||
|
||||
long Usr_GetRamdomStdFromCrs (long CrsCod)
|
||||
long Usr_DB_GetRamdomStdFromCrs (long CrsCod)
|
||||
{
|
||||
/***** Get a random student from current course from database *****/
|
||||
return DB_QuerySELECTCode ("can not get a random student from a course",
|
||||
|
@ -4189,7 +4189,7 @@ long Usr_GetRamdomStdFromCrs (long CrsCod)
|
|||
/*****************************************************************************/
|
||||
// Returns user's code or -1 if no user found
|
||||
|
||||
long Usr_GetRamdomStdFromGrp (long GrpCod)
|
||||
long Usr_DB_GetRamdomStdFromGrp (long GrpCod)
|
||||
{
|
||||
/***** Get a random student from a group from database *****/
|
||||
return DB_QuerySELECTCode ("can not get a random student from a group",
|
||||
|
@ -4209,7 +4209,7 @@ long Usr_GetRamdomStdFromGrp (long GrpCod)
|
|||
/* Get number of teachers in courses of the current instit. in a department **/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Usr_GetNumTchsCurrentInsInDepartment (long DptCod)
|
||||
unsigned Usr_DB_GetNumTchsCurrentInsInDepartment (long DptCod)
|
||||
{
|
||||
/***** Get the number of teachers
|
||||
from the current institution in a department *****/
|
||||
|
@ -5670,8 +5670,8 @@ static void Usr_GetListUsrsFromQuery (char *Query,Rol_Role_t Role,HieLvl_Level_t
|
|||
case HieLvl_SYS: // System
|
||||
// Query result has not a column with the acceptation
|
||||
UsrInList->RoleInCurrentCrsDB = Rol_UNK;
|
||||
if (Usr_GetNumCrssOfUsr (UsrInList->UsrCod))
|
||||
UsrInList->Accepted = (Usr_GetNumCrssOfUsrNotAccepted (UsrInList->UsrCod) == 0);
|
||||
if (Usr_DB_GetNumCrssOfUsr (UsrInList->UsrCod))
|
||||
UsrInList->Accepted = (Usr_DB_GetNumCrssOfUsrNotAccepted (UsrInList->UsrCod) == 0);
|
||||
else
|
||||
UsrInList->Accepted = false;
|
||||
break;
|
||||
|
@ -5681,7 +5681,7 @@ static void Usr_GetListUsrsFromQuery (char *Query,Rol_Role_t Role,HieLvl_Level_t
|
|||
case HieLvl_DEG: // Degree
|
||||
// Query result has not a column with the acceptation
|
||||
UsrInList->RoleInCurrentCrsDB = Rol_UNK;
|
||||
UsrInList->Accepted = (Usr_GetNumCrssOfUsrNotAccepted (UsrInList->UsrCod) == 0);
|
||||
UsrInList->Accepted = (Usr_DB_GetNumCrssOfUsrNotAccepted (UsrInList->UsrCod) == 0);
|
||||
break;
|
||||
case HieLvl_CRS: // Course
|
||||
// Query result has a column with the acceptation
|
||||
|
@ -5712,7 +5712,7 @@ static void Usr_GetListUsrsFromQuery (char *Query,Rol_Role_t Role,HieLvl_Level_t
|
|||
case HieLvl_DEG: // Degree
|
||||
// Query result has not a column with the acceptation
|
||||
UsrInList->RoleInCurrentCrsDB = Rol_UNK;
|
||||
UsrInList->Accepted = (Usr_GetNumCrssOfUsrWithARoleNotAccepted (UsrInList->UsrCod,Role) == 0);
|
||||
UsrInList->Accepted = (Usr_DB_GetNumCrssOfUsrWithARoleNotAccepted (UsrInList->UsrCod,Role) == 0);
|
||||
break;
|
||||
case HieLvl_CRS: // Course
|
||||
// Query result has a column with the acceptation
|
||||
|
@ -7228,6 +7228,7 @@ void Usr_ListAllDataStds (void)
|
|||
|
||||
/***** Begin table with list of students *****/
|
||||
HTM_TABLE_BeginWide ();
|
||||
|
||||
if (!Gbl.Usrs.ClassPhoto.AllGroups)
|
||||
{
|
||||
HTM_TR_Begin (NULL);
|
||||
|
@ -7274,7 +7275,9 @@ void Usr_ListAllDataStds (void)
|
|||
|
||||
/* 4. Visibility type for the record fields that depend on the course, in other row */
|
||||
HTM_TR_End ();
|
||||
|
||||
HTM_TR_Begin (NULL);
|
||||
|
||||
for (NumCol = 0;
|
||||
NumCol < NumColumnsCardAndGroups;
|
||||
NumCol++)
|
||||
|
@ -7825,7 +7828,7 @@ static void Usr_GetAndUpdateUsrListType (void)
|
|||
|
||||
if (Gbl.Usrs.Me.ListType != Usr_LIST_UNKNOWN)
|
||||
/* Save in the database the type of list preferred by me */
|
||||
Usr_UpdateMyUsrListTypeInDB ();
|
||||
Usr_DB_UpdateMyUsrListType ();
|
||||
else
|
||||
/* If parameter can't be retrieved from,
|
||||
get my preference from database */
|
||||
|
@ -7905,7 +7908,7 @@ static void Usr_GetMyUsrListTypeFromDB (void)
|
|||
/***************** Save my preference about type of users' list **************/
|
||||
/*****************************************************************************/
|
||||
|
||||
static void Usr_UpdateMyUsrListTypeInDB (void)
|
||||
static void Usr_DB_UpdateMyUsrListType (void)
|
||||
{
|
||||
/***** Update type of users listing *****/
|
||||
DB_QueryUPDATE ("can not update type of listing",
|
||||
|
@ -7929,7 +7932,7 @@ void Usr_GetAndUpdateColsClassPhoto (void)
|
|||
|
||||
if (Gbl.Usrs.ClassPhoto.Cols)
|
||||
/* Save the number of columns into the database */
|
||||
Usr_UpdateMyColsClassPhotoInDB ();
|
||||
Usr_DB_UpdateMyColsClassPhoto ();
|
||||
else
|
||||
/* If parameter can't be retrieved from form,
|
||||
get my preference from database */
|
||||
|
@ -8007,7 +8010,7 @@ static void Usr_GetMyColsClassPhotoFromDB (void)
|
|||
/** Save my prefs. about number of colums in class photo for current course **/
|
||||
/*****************************************************************************/
|
||||
|
||||
static void Usr_UpdateMyColsClassPhotoInDB (void)
|
||||
static void Usr_DB_UpdateMyColsClassPhoto (void)
|
||||
{
|
||||
if (Gbl.Usrs.Me.Logged &&
|
||||
Gbl.Hierarchy.Level == HieLvl_CRS) // Course selected
|
||||
|
@ -8031,7 +8034,7 @@ static void Usr_GetAndUpdatePrefAboutListWithPhotos (void)
|
|||
/***** Get my preference about photos in users' list from form *****/
|
||||
if (Usr_GetParamListWithPhotosFromForm ())
|
||||
/* Save preference about photos in users' list into the database */
|
||||
Usr_UpdateMyPrefAboutListWithPhotosPhotoInDB ();
|
||||
Usr_DB_UpdateMyPrefAboutListWithPhotosPhoto ();
|
||||
else
|
||||
/* If parameter can't be retrieved from form,
|
||||
get my preference from database */
|
||||
|
@ -8114,7 +8117,7 @@ void Usr_GetMyPrefAboutListWithPhotosFromDB (void)
|
|||
/**** Save my preference about photos in users' list for current course ******/
|
||||
/*****************************************************************************/
|
||||
|
||||
static void Usr_UpdateMyPrefAboutListWithPhotosPhotoInDB (void)
|
||||
static void Usr_DB_UpdateMyPrefAboutListWithPhotosPhoto (void)
|
||||
{
|
||||
if (Gbl.Usrs.Me.Logged &&
|
||||
Gbl.Hierarchy.Level == HieLvl_CRS) // Course selected
|
||||
|
@ -9423,7 +9426,7 @@ void Usr_ConstructPathUsr (long UsrCod,char PathUsr[PATH_MAX + 1 + Cns_MAX_DECIM
|
|||
/************** Check if a user exists with a given user's code **************/
|
||||
/*****************************************************************************/
|
||||
|
||||
bool Usr_ChkIfUsrCodExists (long UsrCod)
|
||||
bool Usr_DB_ChkIfUsrCodExists (long UsrCod)
|
||||
{
|
||||
/***** Trivial check: user's code should be > 0 *****/
|
||||
if (UsrCod <= 0) // Wrong user's code
|
||||
|
|
22
swad_user.h
22
swad_user.h
|
@ -305,17 +305,17 @@ void Usr_WriteFirstNameBRSurnames (const struct UsrData *UsrDat);
|
|||
|
||||
void Usr_FlushCachesUsr (void);
|
||||
|
||||
bool Usr_CheckIfUsrIsAdm (long UsrCod,HieLvl_Level_t Scope,long Cod);
|
||||
bool Usr_DB_CheckIfUsrIsAdm (long UsrCod,HieLvl_Level_t Scope,long Cod);
|
||||
void Usr_FlushCacheUsrIsSuperuser (void);
|
||||
bool Usr_CheckIfUsrIsSuperuser (long UsrCod);
|
||||
|
||||
bool Usr_ICanChangeOtherUsrData (const struct UsrData *UsrDat);
|
||||
bool Usr_ICanEditOtherUsr (const struct UsrData *UsrDat);
|
||||
|
||||
unsigned Usr_GetNumCrssOfUsr (long UsrCod);
|
||||
unsigned Usr_GetNumCrssOfUsrNotAccepted (long UsrCod);
|
||||
unsigned Usr_GetNumCrssOfUsrWithARole (long UsrCod,Rol_Role_t Role);
|
||||
unsigned Usr_GetNumCrssOfUsrWithARoleNotAccepted (long UsrCod,Rol_Role_t Role);
|
||||
unsigned Usr_DB_GetNumCrssOfUsr (long UsrCod);
|
||||
unsigned Usr_DB_GetNumCrssOfUsrNotAccepted (long UsrCod);
|
||||
unsigned Usr_DB_GetNumCrssOfUsrWithARole (long UsrCod,Rol_Role_t Role);
|
||||
unsigned Usr_DB_GetNumCrssOfUsrWithARoleNotAccepted (long UsrCod,Rol_Role_t Role);
|
||||
|
||||
unsigned Usr_GetNumUsrsInCrssOfAUsr (long UsrCod,Rol_Role_t UsrRole,
|
||||
unsigned OthersRoles);
|
||||
|
@ -364,7 +364,7 @@ bool Usr_CheckIfIBelongToCtr (long CtrCod);
|
|||
bool Usr_CheckIfIBelongToDeg (long DegCod);
|
||||
bool Usr_CheckIfIBelongToCrs (long CrsCod);
|
||||
|
||||
unsigned Usr_GetCtysFromUsr (long UsrCod,MYSQL_RES **mysql_res);
|
||||
unsigned Usr_DB_GetCtysFromUsr (long UsrCod,MYSQL_RES **mysql_res);
|
||||
unsigned Usr_GetInssFromUsr (long UsrCod,long CtyCod,MYSQL_RES **mysql_res);
|
||||
unsigned Usr_GetCtrsFromUsr (long UsrCod,long InsCod,MYSQL_RES **mysql_res);
|
||||
unsigned Usr_GetDegsFromUsr (long UsrCod,long CtrCod,MYSQL_RES **mysql_res);
|
||||
|
@ -373,7 +373,7 @@ void Usr_GetMainDeg (long UsrCod,
|
|||
char ShrtName[Cns_HIERARCHY_MAX_BYTES_SHRT_NAME + 1],
|
||||
Rol_Role_t *MaxRole);
|
||||
|
||||
bool Usr_ChkIfEncryptedUsrCodExists (const char EncryptedUsrCod[Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64]);
|
||||
bool Usr_DB_ChkIfEncryptedUsrCodExists (const char EncryptedUsrCod[Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64]);
|
||||
|
||||
void Usr_WriteLandingPage (void);
|
||||
void Usr_WriteFormLogout (void);
|
||||
|
@ -417,10 +417,10 @@ void Usr_WriteRowUsrMainData (unsigned NumUsr,struct UsrData *UsrDat,
|
|||
bool PutCheckBoxToSelectUsr,Rol_Role_t Role,
|
||||
struct SelectedUsrs *SelectedUsrs);
|
||||
|
||||
long Usr_GetRamdomStdFromCrs (long CrsCod);
|
||||
long Usr_GetRamdomStdFromGrp (long GrpCod);
|
||||
long Usr_DB_GetRamdomStdFromCrs (long CrsCod);
|
||||
long Usr_DB_GetRamdomStdFromGrp (long GrpCod);
|
||||
|
||||
unsigned Usr_GetNumTchsCurrentInsInDepartment (long DptCod);
|
||||
unsigned Usr_DB_GetNumTchsCurrentInsInDepartment (long DptCod);
|
||||
|
||||
void Usr_FlushCacheNumUsrsWhoDontClaimToBelongToAnyCty (void);
|
||||
unsigned Usr_GetNumUsrsWhoDontClaimToBelongToAnyCty (void);
|
||||
|
@ -527,7 +527,7 @@ void Usr_SeeTchClassPhotoPrn (void);
|
|||
void Usr_PutSelectorNumColsClassPhoto (void);
|
||||
|
||||
void Usr_ConstructPathUsr (long UsrCod,char PathUsr[PATH_MAX + 1 + Cns_MAX_DECIMAL_DIGITS_LONG + 1]);
|
||||
bool Usr_ChkIfUsrCodExists (long UsrCod);
|
||||
bool Usr_DB_ChkIfUsrCodExists (long UsrCod);
|
||||
|
||||
void Usr_ShowWarningNoUsersFound (Rol_Role_t Role);
|
||||
|
||||
|
|
Loading…
Reference in New Issue