diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml index 53f6545d..2768e53f 100644 --- a/.settings/language.settings.xml +++ b/.settings/language.settings.xml @@ -9,7 +9,7 @@ - + diff --git a/swad_API.c b/swad_API.c index 893ba800..17c65de0 100644 --- a/swad_API.c +++ b/swad_API.c @@ -4973,6 +4973,9 @@ int swad__getMatches (struct soap *soap, "Bad web service key", "Web service key does not exist in database"); + /***** Reset game *****/ + Gam_ResetGame (&Game); + /***** Get game data from database *****/ Game.GamCod = (long) gameCode; if (Game.GamCod <= 0) @@ -5130,8 +5133,8 @@ int swad__getMatchStatus (struct soap *soap, struct swad__getMatchStatusOutput *getMatchStatusOut) // output { int ReturnCode; - struct Mch_Match Match; struct Gam_Game Game; + struct Mch_Match Match; bool ICanPlayThisMatchBasedOnGrps; unsigned NumOptions; struct Mch_UsrAnswer UsrAnswer; @@ -5148,6 +5151,10 @@ int swad__getMatchStatus (struct soap *soap, "Bad web service key", "Web service key does not exist in database"); + /***** Reset game and match *****/ + Gam_ResetGame (&Game); + Mch_ResetMatch (&Match); + /***** Get match data from database *****/ Match.MchCod = (long) matchCode; if (Match.MchCod <= 0) diff --git a/swad_changelog.h b/swad_changelog.h index 154ed8de..fb80e748 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -544,10 +544,11 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - * En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 19.193.3 (2020-04-23)" +#define Log_PLATFORM_VERSION "SWAD 19.193.4 (2020-04-23)" #define CSS_FILE "swad19.193.1.css" #define JS_FILE "swad19.193.1.js" /* + Version 19.193.4: Apr 23, 2020 Fixed bugs in exams, exam events, games and matches. (297860 lines) Version 19.193.3: Apr 23, 2020 Added new MIME type, reported by Jesús Garrido Manrique. Changed text in test configuration. (297640 lines) 1 change necessary in database: diff --git a/swad_exam.c b/swad_exam.c index 659e4573..96fa3946 100644 --- a/swad_exam.c +++ b/swad_exam.c @@ -134,8 +134,6 @@ static void Exa_PutParamsOneQst (void *Exams); static void Exa_PutHiddenParamOrder (Exa_Order_t SelectedOrder); static Exa_Order_t Exa_GetParamOrder (void); -static void Exa_ResetExam (struct Exa_Exam *Exam); - static void Exa_GetExamTxtFromDB (long ExaCod,char Txt[Cns_MAX_BYTES_TEXT + 1]); static void Exa_RemoveExamFromAllTables (long ExaCod); @@ -194,6 +192,27 @@ void Exa_ResetExams (struct Exa_Exams *Exams) Exams->QstInd = 0; // Current question index } +/*****************************************************************************/ +/*************************** Initialize exam to empty ************************/ +/*****************************************************************************/ + +void Exa_ResetExam (struct Exa_Exam *Exam) + { + /***** Initialize to empty exam *****/ + Exam->ExaCod = -1L; + Exam->CrsCod = -1L; + Exam->UsrCod = -1L; + Exam->MaxGrade = Exa_MAX_GRADE_DEFAULT; + Exam->Visibility = TstVis_VISIBILITY_DEFAULT; + Exam->TimeUTC[Dat_START_TIME] = (time_t) 0; + Exam->TimeUTC[Dat_END_TIME ] = (time_t) 0; + Exam->Title[0] = '\0'; + Exam->NumQsts = 0; + Exam->NumEvts = 0; + Exam->NumUnfinishedEvts = 0; + Exam->Hidden = false; + } + /*****************************************************************************/ /***************************** List all exams ********************************/ /*****************************************************************************/ @@ -202,7 +221,7 @@ void Exa_SeeAllExams (void) { struct Exa_Exams Exams; - /***** Reset exams *****/ + /***** Reset exams context *****/ Exa_ResetExams (&Exams); /***** Get parameters *****/ @@ -421,9 +440,12 @@ void Exa_SeeOneExam (void) struct Exa_Exams Exams; struct Exa_Exam Exam; - /***** Reset exams *****/ + /***** Reset exams context *****/ Exa_ResetExams (&Exams); + /***** Reset exam *****/ + Exa_ResetExam (&Exam); + /***** Get parameters *****/ if ((Exam.ExaCod = Exa_GetParams (&Exams)) <= 0) Lay_ShowErrorAndExit ("Code of exam is missing."); @@ -1053,27 +1075,6 @@ void Exa_GetDataOfExamByCod (struct Exa_Exam *Exam) } } -/*****************************************************************************/ -/*************************** Initialize exam to empty ************************/ -/*****************************************************************************/ - -static void Exa_ResetExam (struct Exa_Exam *Exam) - { - /***** Initialize to empty exam *****/ - Exam->ExaCod = -1L; - Exam->CrsCod = -1L; - Exam->UsrCod = -1L; - Exam->MaxGrade = Exa_MAX_GRADE_DEFAULT; - Exam->Visibility = TstVis_VISIBILITY_DEFAULT; - Exam->TimeUTC[Dat_START_TIME] = (time_t) 0; - Exam->TimeUTC[Dat_END_TIME ] = (time_t) 0; - Exam->Title[0] = '\0'; - Exam->NumQsts = 0; - Exam->NumEvts = 0; - Exam->NumUnfinishedEvts = 0; - Exam->Hidden = false; - } - /*****************************************************************************/ /***************************** Free list of exams ****************************/ /*****************************************************************************/ @@ -1134,9 +1135,12 @@ void Exa_AskRemExam (void) struct Exa_Exams Exams; struct Exa_Exam Exam; - /***** Reset exams *****/ + /***** Reset exams context *****/ Exa_ResetExams (&Exams); + /***** Reset exam *****/ + Exa_ResetExam (&Exam); + /***** Get parameters *****/ if ((Exam.ExaCod = Exa_GetParams (&Exams)) <= 0) Lay_ShowErrorAndExit ("Code of exam is missing."); @@ -1168,9 +1172,12 @@ void Exa_RemoveExam (void) struct Exa_Exams Exams; struct Exa_Exam Exam; - /***** Reset exams *****/ + /***** Reset exams context *****/ Exa_ResetExams (&Exams); + /***** Reset exam *****/ + Exa_ResetExam (&Exam); + /***** Get exam code *****/ if ((Exam.ExaCod = Exa_GetParamExamCod ()) == -1L) Lay_ShowErrorAndExit ("Code of exam is missing."); @@ -1244,9 +1251,12 @@ void Exa_HideExam (void) struct Exa_Exams Exams; struct Exa_Exam Exam; - /***** Reset exams *****/ + /***** Reset exams context *****/ Exa_ResetExams (&Exams); + /***** Reset exam *****/ + Exa_ResetExam (&Exam); + /***** Get parameters *****/ if ((Exam.ExaCod = Exa_GetParams (&Exams)) <= 0) Lay_ShowErrorAndExit ("Code of exam is missing."); @@ -1274,9 +1284,12 @@ void Exa_UnhideExam (void) struct Exa_Exams Exams; struct Exa_Exam Exam; - /***** Reset exams *****/ + /***** Reset exams context *****/ Exa_ResetExams (&Exams); + /***** Reset exam *****/ + Exa_ResetExam (&Exam); + /***** Get parameters *****/ if ((Exam.ExaCod = Exa_GetParams (&Exams)) <= 0) Lay_ShowErrorAndExit ("Code of exam is missing."); @@ -1321,9 +1334,12 @@ void Exa_RequestCreatOrEditExam (void) bool ItsANewExam; char Txt[Cns_MAX_BYTES_TEXT + 1]; - /***** Reset exams *****/ + /***** Reset exams context *****/ Exa_ResetExams (&Exams); + /***** Reset exam *****/ + Exa_ResetExam (&Exam); + /***** Check if I can edit exams *****/ if (!Exa_CheckIfICanEditExams ()) Lay_NoPermissionExit (); @@ -1476,9 +1492,12 @@ void Exa_RecFormExam (void) bool ItsANewExam; char Txt[Cns_MAX_BYTES_TEXT + 1]; - /***** Reset exams *****/ + /***** Reset exams context *****/ Exa_ResetExams (&Exams); + /***** Reset exam *****/ + Exa_ResetExam (&Exam); + /***** Check if I can edit exams *****/ if (!Exa_CheckIfICanEditExams ()) Lay_NoPermissionExit (); @@ -1653,9 +1672,12 @@ void Exa_RequestNewQuestion (void) struct Exa_Exams Exams; struct Exa_Exam Exam; - /***** Reset exams *****/ + /***** Reset exams context *****/ Exa_ResetExams (&Exams); + /***** Reset exam *****/ + Exa_ResetExam (&Exam); + /***** Get parameters *****/ if ((Exam.ExaCod = Exa_GetParams (&Exams)) <= 0) Lay_ShowErrorAndExit ("Code of exam is missing."); @@ -1686,9 +1708,12 @@ void Exa_ListTstQuestionsToSelect (void) struct Exa_Exams Exams; struct Exa_Exam Exam; - /***** Reset exams *****/ + /***** Reset exams context *****/ Exa_ResetExams (&Exams); + /***** Reset exam *****/ + Exa_ResetExam (&Exam); + /***** Get parameters *****/ if ((Exam.ExaCod = Exa_GetParams (&Exams)) <= 0) Lay_ShowErrorAndExit ("Code of exam is missing."); @@ -2153,9 +2178,12 @@ void Exa_AddTstQuestionsToExam (void) long QstCod; unsigned MaxQstInd; - /***** Reset exams *****/ + /***** Reset exams context *****/ Exa_ResetExams (&Exams); + /***** Reset exam *****/ + Exa_ResetExam (&Exam); + /***** Get parameters *****/ if ((Exam.ExaCod = Exa_GetParams (&Exams)) <= 0) Lay_ShowErrorAndExit ("Code of exam is missing."); @@ -2273,9 +2301,12 @@ void Exa_RequestRemoveQst (void) struct Exa_Exam Exam; unsigned QstInd; - /***** Reset exams *****/ + /***** Reset exams context *****/ Exa_ResetExams (&Exams); + /***** Reset exam *****/ + Exa_ResetExam (&Exam); + /***** Get parameters *****/ if ((Exam.ExaCod = Exa_GetParams (&Exams)) <= 0) Lay_ShowErrorAndExit ("Code of exam is missing."); @@ -2316,9 +2347,12 @@ void Exa_RemoveQst (void) struct Exa_Exam Exam; unsigned QstInd; - /***** Reset exams *****/ + /***** Reset exams context *****/ Exa_ResetExams (&Exams); + /***** Reset exam *****/ + Exa_ResetExam (&Exam); + /***** Get parameters *****/ if ((Exam.ExaCod = Exa_GetParams (&Exams)) <= 0) Lay_ShowErrorAndExit ("Code of exam is missing."); @@ -2380,9 +2414,12 @@ void Exa_MoveUpQst (void) unsigned QstIndTop; unsigned QstIndBottom; - /***** Reset exams *****/ + /***** Reset exams context *****/ Exa_ResetExams (&Exams); + /***** Reset exam *****/ + Exa_ResetExam (&Exam); + /***** Get parameters *****/ if ((Exam.ExaCod = Exa_GetParams (&Exams)) <= 0) Lay_ShowErrorAndExit ("Code of exam is missing."); @@ -2435,9 +2472,12 @@ void Exa_MoveDownQst (void) unsigned QstIndBottom; unsigned MaxQstInd; // 0 if no questions - /***** Reset exams *****/ + /***** Reset exams context *****/ Exa_ResetExams (&Exams); + /***** Reset exam *****/ + Exa_ResetExam (&Exam); + /***** Get parameters *****/ if ((Exam.ExaCod = Exa_GetParams (&Exams)) <= 0) Lay_ShowErrorAndExit ("Code of exam is missing."); @@ -2572,9 +2612,12 @@ void Exa_RequestNewEvent (void) struct Exa_Exams Exams; struct Exa_Exam Exam; - /***** Reset exams *****/ + /***** Reset exams context *****/ Exa_ResetExams (&Exams); + /***** Reset exam *****/ + Exa_ResetExam (&Exam); + /***** Get parameters *****/ if ((Exam.ExaCod = Exa_GetParams (&Exams)) <= 0) Lay_ShowErrorAndExit ("Code of exam is missing."); diff --git a/swad_exam.h b/swad_exam.h index 21dd317a..ce9763a7 100644 --- a/swad_exam.h +++ b/swad_exam.h @@ -99,6 +99,7 @@ struct Exa_Exam /*****************************************************************************/ void Exa_ResetExams (struct Exa_Exams *Exams); +void Exa_ResetExam (struct Exa_Exam *Exam); void Exa_SeeAllExams (void); void Exa_SeeOneExam (void); diff --git a/swad_exam_event.c b/swad_exam_event.c index c885f0e8..5db6b401 100644 --- a/swad_exam_event.c +++ b/swad_exam_event.c @@ -247,6 +247,31 @@ long ExaEvt_GetEvtCodBeingPlayed (void) return ExaEvt_EvtCodBeingPlayed; } +/*****************************************************************************/ +/****************************** Reset exam event *****************************/ +/*****************************************************************************/ + +void ExaEvt_ResetEvent (struct ExaEvt_Event *Event) + { + /***** Initialize to empty match *****/ + Event->EvtCod = -1L; + Event->ExaCod = -1L; + Event->UsrCod = -1L; + Event->TimeUTC[Dat_START_TIME] = (time_t) 0; + Event->TimeUTC[Dat_END_TIME ] = (time_t) 0; + Event->Title[0] = '\0'; + Event->Status.QstInd = 0; + Event->Status.QstCod = -1L; + Event->Status.QstStartTimeUTC = (time_t) 0; + Event->Status.Showing = ExaEvt_SHOWING_DEFAULT; + Event->Status.Countdown = 0; + Event->Status.NumCols = 1; + Event->Status.ShowQstResults = false; + Event->Status.ShowUsrResults = false; + Event->Status.Happening = false; + Event->Status.NumParticipants = 0; + }; + /*****************************************************************************/ /************************* List the events of an exam ************************/ /*****************************************************************************/ @@ -453,6 +478,9 @@ static void ExaEvt_ListOneOrMoreEvents (struct Exa_Exams *Exams, struct ExaEvt_Event Event; bool ICanEditEvents = ExaEvt_CheckIfICanEditEvents (); + /***** Reset event *****/ + ExaEvt_ResetEvent (&Event); + /***** Write the heading *****/ HTM_TABLE_BeginWidePadding (2); ExaEvt_ListOneOrMoreEventsHeading (ICanEditEvents); @@ -875,9 +903,13 @@ void ExaEvt_ToggleVisibilResultsEvtUsr (void) struct Exa_Exam Exam; struct ExaEvt_Event Event; - /***** Reset exams *****/ + /***** Reset exams context *****/ Exa_ResetExams (&Exams); + /***** Reset exam and event *****/ + Exa_ResetExam (&Exam); + ExaEvt_ResetEvent (&Event); + /***** Get and check parameters *****/ ExaEvt_GetAndCheckParameters (&Exams,&Exam,&Event); @@ -1017,9 +1049,13 @@ void ExaEvt_RequestRemoveEvent (void) struct Exa_Exam Exam; struct ExaEvt_Event Event; - /***** Reset exams *****/ + /***** Reset exams context *****/ Exa_ResetExams (&Exams); + /***** Reset exam and event *****/ + Exa_ResetExam (&Exam); + ExaEvt_ResetEvent (&Event); + /***** Get and check parameters *****/ ExaEvt_GetAndCheckParameters (&Exams,&Exam,&Event); @@ -1049,9 +1085,13 @@ void ExaEvt_RemoveEvent (void) struct Exa_Exam Exam; struct ExaEvt_Event Event; - /***** Reset exams *****/ + /***** Reset exams context *****/ Exa_ResetExams (&Exams); + /***** Reset exam and event *****/ + Exa_ResetExam (&Exam); + ExaEvt_ResetEvent (&Event); + /***** Get and check parameters *****/ ExaEvt_GetAndCheckParameters (&Exams,&Exam,&Event); @@ -1434,6 +1474,9 @@ void ExaEvt_ResumeEvent (void) { struct ExaEvt_Event Event; + /***** Reset event *****/ + ExaEvt_ResetEvent (&Event); + /***** Remove old participants. This function must be called by a teacher before getting exam event status. *****/ @@ -1874,6 +1917,9 @@ void ExaEvt_PlayPauseEvent (void) { struct ExaEvt_Event Event; + /***** Reset event *****/ + ExaEvt_ResetEvent (&Event); + /***** Remove old participants. This function must be called by a teacher before getting exam event status. *****/ @@ -1908,6 +1954,9 @@ void ExaEvt_ChangeNumColsEvt (void) { struct ExaEvt_Event Event; + /***** Reset event *****/ + ExaEvt_ResetEvent (&Event); + /***** Remove old participants. This function must be called by a teacher before getting exam event status. *****/ @@ -1941,6 +1990,9 @@ void ExaEvt_ToggleVisibilResultsEvtQst (void) { struct ExaEvt_Event Event; + /***** Reset event *****/ + ExaEvt_ResetEvent (&Event); + /***** Remove old participants. This function must be called by a teacher before getting exam event status. *****/ @@ -1973,6 +2025,9 @@ void ExaEvt_BackEvent (void) { struct ExaEvt_Event Event; + /***** Reset event *****/ + ExaEvt_ResetEvent (&Event); + /***** Remove old participants. This function must be called by a teacher before getting exam event status. *****/ @@ -2002,6 +2057,9 @@ void ExaEvt_ForwardEvent (void) { struct ExaEvt_Event Event; + /***** Reset event *****/ + ExaEvt_ResetEvent (&Event); + /***** Remove old participants. This function must be called by a teacher before getting exam event status. *****/ @@ -3624,6 +3682,9 @@ void ExaEvt_JoinEventAsStd (void) { struct ExaEvt_Event Event; + /***** Reset event *****/ + ExaEvt_ResetEvent (&Event); + /***** Get data of the exam event from database *****/ Event.EvtCod = ExaEvt_GetEvtCodBeingPlayed (); ExaEvt_GetDataOfEventByCod (&Event); @@ -3643,6 +3704,9 @@ void ExaEvt_RemoveMyQuestionAnswer (void) struct ExaEvt_Event Event; unsigned QstInd; + /***** Reset event *****/ + ExaEvt_ResetEvent (&Event); + /***** Get data of the exam event from database *****/ Event.EvtCod = ExaEvt_GetEvtCodBeingPlayed (); ExaEvt_GetDataOfEventByCod (&Event); @@ -3673,6 +3737,9 @@ void ExaEvt_StartCountdown (void) struct ExaEvt_Event Event; long NewCountdown; + /***** Reset event *****/ + ExaEvt_ResetEvent (&Event); + /***** Get countdown parameter ****/ NewCountdown = Par_GetParToLong ("Countdown"); @@ -3707,6 +3774,9 @@ void ExaEvt_RefreshEventTch (void) if (!Gbl.Session.IsOpen) // If session has been closed, do not write anything return; + /***** Reset event *****/ + ExaEvt_ResetEvent (&Event); + /***** Remove old participants. This function must be called by a teacher before getting exam event status. *****/ @@ -3764,6 +3834,9 @@ void ExaEvt_RefreshEventStd (void) if (!Gbl.Session.IsOpen) // If session has been closed, do not write anything return; + /***** Reset event *****/ + ExaEvt_ResetEvent (&Event); + /***** Get data of the exam event from database *****/ Event.EvtCod = ExaEvt_GetEvtCodBeingPlayed (); ExaEvt_GetDataOfEventByCod (&Event); @@ -3826,6 +3899,9 @@ void ExaEvt_ReceiveQuestionAnswer (void) struct ExaEvt_UsrAnswer UsrAnswer; struct TstRes_Result Result; + /***** Reset event *****/ + ExaEvt_ResetEvent (&Event); + /***** Get data of the exam event from database *****/ Event.EvtCod = ExaEvt_GetEvtCodBeingPlayed (); ExaEvt_GetDataOfEventByCod (&Event); diff --git a/swad_exam_event.h b/swad_exam_event.h index d630cd74..67c54d83 100644 --- a/swad_exam_event.h +++ b/swad_exam_event.h @@ -85,6 +85,8 @@ struct ExaEvt_UsrAnswer long ExaEvt_GetEvtCodBeingPlayed (void); +void ExaEvt_ResetEvent (struct ExaEvt_Event *Event); + void ExaEvt_ListEvents (struct Exa_Exams *Exams, struct Exa_Exam *Exam, bool PutFormNewEvent); diff --git a/swad_exam_result.c b/swad_exam_result.c index 106aec2b..525cfd54 100644 --- a/swad_exam_result.c +++ b/swad_exam_result.c @@ -116,7 +116,7 @@ void ExaRes_ShowMyExaResultsInCrs (void) extern const char *Txt_Results; struct Exa_Exams Exams; - /***** Reset exams *****/ + /***** Reset exams context *****/ Exa_ResetExams (&Exams); /***** Get list of exams *****/ @@ -157,9 +157,12 @@ void ExaRes_ShowMyExaResultsInExa (void) struct Exa_Exams Exams; struct Exa_Exam Exam; - /***** Reset exams *****/ + /***** Reset exams context *****/ Exa_ResetExams (&Exams); + /***** Reset exam *****/ + Exa_ResetExam (&Exam); + /***** Get parameters *****/ if ((Exam.ExaCod = Exa_GetParams (&Exams)) <= 0) Lay_ShowErrorAndExit ("Code of exam is missing."); @@ -203,9 +206,13 @@ void ExaRes_ShowMyExaResultsInEvt (void) struct Exa_Exam Exam; struct ExaEvt_Event Event; - /***** Reset exams *****/ + /***** Reset exams context *****/ Exa_ResetExams (&Exams); + /***** Reset exam and event *****/ + Exa_ResetExam (&Exam); + ExaEvt_ResetEvent (&Event); + /***** Get parameters *****/ if ((Exam.ExaCod = Exa_GetParams (&Exams)) <= 0) Lay_ShowErrorAndExit ("Code of exam is missing."); @@ -248,7 +255,7 @@ void ExaRes_ShowAllExaResultsInCrs (void) { struct Exa_Exams Exams; - /***** Reset exams *****/ + /***** Reset exams context *****/ Exa_ResetExams (&Exams); /***** Get users and show their events results *****/ @@ -319,7 +326,7 @@ void ExaRes_SelUsrsToViewExaResults (void) { struct Exa_Exams Exams; - /***** Reset exams *****/ + /***** Reset exams context *****/ Exa_ResetExams (&Exams); /***** Put form to select users *****/ @@ -352,9 +359,12 @@ void ExaRes_ShowAllExaResultsInExa (void) struct Exa_Exams Exams; struct Exa_Exam Exam; - /***** Reset exams *****/ + /***** Reset exams context *****/ Exa_ResetExams (&Exams); + /***** Reset exam *****/ + Exa_ResetExam (&Exam); + /***** Get parameters *****/ if ((Exam.ExaCod = Exa_GetParams (&Exams)) <= 0) Lay_ShowErrorAndExit ("Code of exam is missing."); @@ -439,9 +449,13 @@ void ExaRes_ShowAllExaResultsInEvt (void) struct Exa_Exam Exam; struct ExaEvt_Event Event; - /***** Reset exams *****/ + /***** Reset exams context *****/ Exa_ResetExams (&Exams); + /***** Reset exam and event *****/ + Exa_ResetExam (&Exam); + ExaEvt_ResetEvent (&Event); + /***** Get parameters *****/ if ((Exam.ExaCod = Exa_GetParams (&Exams)) <= 0) Lay_ShowErrorAndExit ("Code of exam is missing."); @@ -568,6 +582,9 @@ static void ExaRes_ListExamsToSelect (struct Exa_Exams *Exams) unsigned NumExam; struct Exa_Exam Exam; + /***** Reset exam *****/ + Exa_ResetExam (&Exam); + /***** Begin box *****/ Box_BoxBegin (NULL,Txt_Exams, NULL,NULL, @@ -745,6 +762,9 @@ static void ExaRes_ShowEvtResults (struct Exa_Exams *Exams, unsigned Visibility; time_t TimeUTC[Dat_NUM_START_END_TIME]; + /***** Reset event *****/ + ExaEvt_ResetEvent (&Event); + /***** Set user *****/ UsrDat = (MeOrOther == Usr_ME) ? &Gbl.Usrs.Me.UsrDat : &Gbl.Usrs.Other.UsrDat; @@ -1068,9 +1088,13 @@ void ExaRes_ShowOneExaResult (void) bool ICanViewResult; bool ICanViewScore; - /***** Reset exams *****/ + /***** Reset exams context *****/ Exa_ResetExams (&Exams); + /***** Reset exam and event *****/ + Exa_ResetExam (&Exam); + ExaEvt_ResetEvent (&Event); + /***** Get and check parameters *****/ ExaEvt_GetAndCheckParameters (&Exams,&Exam,&Event); diff --git a/swad_game.c b/swad_game.c index 0be4ff96..fdbd25e9 100644 --- a/swad_game.c +++ b/swad_game.c @@ -131,8 +131,6 @@ static void Gam_PutParamsOneQst (void *Games); static void Gam_PutHiddenParamOrder (Gam_Order_t SelectedOrder); static Gam_Order_t Gam_GetParamOrder (void); -static void Gam_ResetGame (struct Gam_Game *Game); - static void Gam_GetGameTxtFromDB (long GamCod,char Txt[Cns_MAX_BYTES_TEXT + 1]); static void Gam_RemoveGameFromAllTables (long GamCod); @@ -173,7 +171,7 @@ static void Gam_ExchangeQuestions (long GamCod, static bool Gam_CheckIfEditable (const struct Gam_Game *Game); /*****************************************************************************/ -/******************************* Reset games *********************************/ +/*************************** Reset games context *****************************/ /*****************************************************************************/ void Gam_ResetGames (struct Gam_Games *Games) @@ -191,6 +189,27 @@ void Gam_ResetGames (struct Gam_Games *Games) Games->QstInd = 0; // Current question index } +/*****************************************************************************/ +/*************************** Initialize game to empty ************************/ +/*****************************************************************************/ + +void Gam_ResetGame (struct Gam_Game *Game) + { + /***** Initialize to empty game *****/ + Game->GamCod = -1L; + Game->CrsCod = -1L; + Game->UsrCod = -1L; + Game->MaxGrade = Gam_MAX_GRADE_DEFAULT; + Game->Visibility = TstVis_VISIBILITY_DEFAULT; + Game->TimeUTC[Dat_START_TIME] = (time_t) 0; + Game->TimeUTC[Dat_END_TIME ] = (time_t) 0; + Game->Title[0] = '\0'; + Game->NumQsts = 0; + Game->NumMchs = 0; + Game->NumUnfinishedMchs = 0; + Game->Hidden = false; + } + /*****************************************************************************/ /***************************** List all games ********************************/ /*****************************************************************************/ @@ -199,7 +218,7 @@ void Gam_SeeAllGames (void) { struct Gam_Games Games; - /***** Reset games *****/ + /***** Reset games context *****/ Gam_ResetGames (&Games); /***** Get parameters *****/ @@ -226,6 +245,9 @@ static void Gam_ListAllGames (struct Gam_Games *Games) unsigned NumGame; struct Gam_Game Game; + /***** Reset game *****/ + Gam_ResetGame (&Game); + /***** Get number of groups in current course *****/ if (!Gbl.Crs.Grps.NumGrps) Gbl.Crs.Grps.WhichGrps = Grp_ALL_GROUPS; @@ -418,9 +440,12 @@ void Gam_SeeOneGame (void) struct Gam_Games Games; struct Gam_Game Game; - /***** Reset games *****/ + /***** Reset games context *****/ Gam_ResetGames (&Games); + /***** Reset game *****/ + Gam_ResetGame (&Game); + /***** Get parameters *****/ if ((Game.GamCod = Gam_GetParams (&Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); @@ -1050,27 +1075,6 @@ void Gam_GetDataOfGameByCod (struct Gam_Game *Game) } } -/*****************************************************************************/ -/*************************** Initialize game to empty ************************/ -/*****************************************************************************/ - -static void Gam_ResetGame (struct Gam_Game *Game) - { - /***** Initialize to empty game *****/ - Game->GamCod = -1L; - Game->CrsCod = -1L; - Game->UsrCod = -1L; - Game->MaxGrade = Gam_MAX_GRADE_DEFAULT; - Game->Visibility = TstVis_VISIBILITY_DEFAULT; - Game->TimeUTC[Dat_START_TIME] = (time_t) 0; - Game->TimeUTC[Dat_END_TIME ] = (time_t) 0; - Game->Title[0] = '\0'; - Game->NumQsts = 0; - Game->NumMchs = 0; - Game->NumUnfinishedMchs = 0; - Game->Hidden = false; - } - /*****************************************************************************/ /***************************** Free list of games ****************************/ /*****************************************************************************/ @@ -1131,9 +1135,12 @@ void Gam_AskRemGame (void) struct Gam_Games Games; struct Gam_Game Game; - /***** Reset games *****/ + /***** Reset games context *****/ Gam_ResetGames (&Games); + /***** Reset game *****/ + Gam_ResetGame (&Game); + /***** Get parameters *****/ if ((Game.GamCod = Gam_GetParams (&Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); @@ -1165,9 +1172,12 @@ void Gam_RemoveGame (void) struct Gam_Games Games; struct Gam_Game Game; - /***** Reset games *****/ + /***** Reset games context *****/ Gam_ResetGames (&Games); + /***** Reset game *****/ + Gam_ResetGame (&Game); + /***** Get game code *****/ if ((Game.GamCod = Gam_GetParamGameCod ()) == -1L) Lay_ShowErrorAndExit ("Code of game is missing."); @@ -1241,9 +1251,12 @@ void Gam_HideGame (void) struct Gam_Games Games; struct Gam_Game Game; - /***** Reset games *****/ + /***** Reset games context *****/ Gam_ResetGames (&Games); + /***** Reset game *****/ + Gam_ResetGame (&Game); + /***** Get parameters *****/ if ((Game.GamCod = Gam_GetParams (&Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); @@ -1271,9 +1284,12 @@ void Gam_UnhideGame (void) struct Gam_Games Games; struct Gam_Game Game; - /***** Reset games *****/ + /***** Reset games context *****/ Gam_ResetGames (&Games); + /***** Reset game *****/ + Gam_ResetGame (&Game); + /***** Get parameters *****/ if ((Game.GamCod = Gam_GetParams (&Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); @@ -1318,9 +1334,12 @@ void Gam_RequestCreatOrEditGame (void) bool ItsANewGame; char Txt[Cns_MAX_BYTES_TEXT + 1]; - /***** Reset games *****/ + /***** Reset games context *****/ Gam_ResetGames (&Games); + /***** Reset game *****/ + Gam_ResetGame (&Game); + /***** Check if I can edit games *****/ if (!Gam_CheckIfICanEditGames ()) Lay_NoPermissionExit (); @@ -1473,9 +1492,12 @@ void Gam_RecFormGame (void) bool ItsANewGame; char Txt[Cns_MAX_BYTES_TEXT + 1]; - /***** Reset games *****/ + /***** Reset games context *****/ Gam_ResetGames (&Games); + /***** Reset game *****/ + Gam_ResetGame (&Game); + /***** Check if I can edit games *****/ if (!Gam_CheckIfICanEditGames ()) Lay_NoPermissionExit (); @@ -1650,9 +1672,12 @@ void Gam_RequestNewQuestion (void) struct Gam_Games Games; struct Gam_Game Game; - /***** Reset games *****/ + /***** Reset games context *****/ Gam_ResetGames (&Games); + /***** Reset game *****/ + Gam_ResetGame (&Game); + /***** Get parameters *****/ if ((Game.GamCod = Gam_GetParams (&Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); @@ -1683,9 +1708,12 @@ void Gam_ListTstQuestionsToSelect (void) struct Gam_Games Games; struct Gam_Game Game; - /***** Reset games *****/ + /***** Reset games context *****/ Gam_ResetGames (&Games); + /***** Reset game *****/ + Gam_ResetGame (&Game); + /***** Get parameters *****/ if ((Game.GamCod = Gam_GetParams (&Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); @@ -2150,9 +2178,12 @@ void Gam_AddTstQuestionsToGame (void) long QstCod; unsigned MaxQstInd; - /***** Reset games *****/ + /***** Reset games context *****/ Gam_ResetGames (&Games); + /***** Reset game *****/ + Gam_ResetGame (&Game); + /***** Get parameters *****/ if ((Game.GamCod = Gam_GetParams (&Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); @@ -2270,9 +2301,12 @@ void Gam_RequestRemoveQst (void) struct Gam_Game Game; unsigned QstInd; - /***** Reset games *****/ + /***** Reset games context *****/ Gam_ResetGames (&Games); + /***** Reset game *****/ + Gam_ResetGame (&Game); + /***** Get parameters *****/ if ((Game.GamCod = Gam_GetParams (&Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); @@ -2313,9 +2347,12 @@ void Gam_RemoveQst (void) struct Gam_Game Game; unsigned QstInd; - /***** Reset games *****/ + /***** Reset games context *****/ Gam_ResetGames (&Games); + /***** Reset game *****/ + Gam_ResetGame (&Game); + /***** Get parameters *****/ if ((Game.GamCod = Gam_GetParams (&Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); @@ -2377,9 +2414,12 @@ void Gam_MoveUpQst (void) unsigned QstIndTop; unsigned QstIndBottom; - /***** Reset games *****/ + /***** Reset games context *****/ Gam_ResetGames (&Games); + /***** Reset game *****/ + Gam_ResetGame (&Game); + /***** Get parameters *****/ if ((Game.GamCod = Gam_GetParams (&Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); @@ -2432,9 +2472,12 @@ void Gam_MoveDownQst (void) unsigned QstIndBottom; unsigned MaxQstInd; // 0 if no questions - /***** Reset games *****/ + /***** Reset games context *****/ Gam_ResetGames (&Games); + /***** Reset game *****/ + Gam_ResetGame (&Game); + /***** Get parameters *****/ if ((Game.GamCod = Gam_GetParams (&Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); @@ -2569,9 +2612,12 @@ void Gam_RequestNewMatch (void) struct Gam_Games Games; struct Gam_Game Game; - /***** Reset games *****/ + /***** Reset games context *****/ Gam_ResetGames (&Games); + /***** Reset game *****/ + Gam_ResetGame (&Game); + /***** Get parameters *****/ if ((Game.GamCod = Gam_GetParams (&Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); diff --git a/swad_game.h b/swad_game.h index 77af8523..e511f0aa 100644 --- a/swad_game.h +++ b/swad_game.h @@ -98,6 +98,7 @@ struct Gam_Game /*****************************************************************************/ void Gam_ResetGames (struct Gam_Games *Games); +void Gam_ResetGame (struct Gam_Game *Game); void Gam_SeeAllGames (void); void Gam_SeeOneGame (void); diff --git a/swad_match.c b/swad_match.c index ddafabdf..f8295b09 100644 --- a/swad_match.c +++ b/swad_match.c @@ -247,6 +247,31 @@ long Mch_GetMchCodBeingPlayed (void) return Mch_MchCodBeingPlayed; } +/*****************************************************************************/ +/********************************* Reset match *******************************/ +/*****************************************************************************/ + +void Mch_ResetMatch (struct Mch_Match *Match) + { + /***** Initialize to empty match *****/ + Match->MchCod = -1L; + Match->GamCod = -1L; + Match->UsrCod = -1L; + Match->TimeUTC[Dat_START_TIME] = (time_t) 0; + Match->TimeUTC[Dat_END_TIME ] = (time_t) 0; + Match->Title[0] = '\0'; + Match->Status.QstInd = 0; + Match->Status.QstCod = -1L; + Match->Status.QstStartTimeUTC = (time_t) 0; + Match->Status.Showing = Mch_SHOWING_DEFAULT; + Match->Status.Countdown = 0; + Match->Status.NumCols = 1; + Match->Status.ShowQstResults = false; + Match->Status.ShowUsrResults = false; + Match->Status.Playing = false; + Match->Status.NumPlayers = 0; + }; + /*****************************************************************************/ /************************* List the matches of a game ************************/ /*****************************************************************************/ @@ -453,6 +478,9 @@ static void Mch_ListOneOrMoreMatches (struct Gam_Games *Games, struct Mch_Match Match; bool ICanEditMatches = Mch_CheckIfICanEditMatches (); + /***** Reset match *****/ + Mch_ResetMatch (&Match); + /***** Write the heading *****/ HTM_TABLE_BeginWidePadding (2); Mch_ListOneOrMoreMatchesHeading (ICanEditMatches); @@ -875,9 +903,13 @@ void Mch_ToggleVisibilResultsMchUsr (void) struct Gam_Game Game; struct Mch_Match Match; - /***** Reset games *****/ + /***** Reset games context *****/ Gam_ResetGames (&Games); + /***** Reset game and match *****/ + Gam_ResetGame (&Game); + Mch_ResetMatch (&Match); + /***** Get and check parameters *****/ Mch_GetAndCheckParameters (&Games,&Game,&Match); @@ -1017,9 +1049,13 @@ void Mch_RequestRemoveMatch (void) struct Gam_Game Game; struct Mch_Match Match; - /***** Reset games *****/ + /***** Reset games context *****/ Gam_ResetGames (&Games); + /***** Reset game and match *****/ + Gam_ResetGame (&Game); + Mch_ResetMatch (&Match); + /***** Get and check parameters *****/ Mch_GetAndCheckParameters (&Games,&Game,&Match); @@ -1049,9 +1085,13 @@ void Mch_RemoveMatch (void) struct Gam_Game Game; struct Mch_Match Match; - /***** Reset games *****/ + /***** Reset games context *****/ Gam_ResetGames (&Games); + /***** Reset game and match *****/ + Gam_ResetGame (&Game); + Mch_ResetMatch (&Match); + /***** Get and check parameters *****/ Mch_GetAndCheckParameters (&Games,&Game,&Match); @@ -1434,6 +1474,9 @@ void Mch_ResumeMatch (void) { struct Mch_Match Match; + /***** Reset match *****/ + Mch_ResetMatch (&Match); + /***** Remove old players. This function must be called by a teacher before getting match status. *****/ @@ -1874,6 +1917,9 @@ void Mch_PlayPauseMatch (void) { struct Mch_Match Match; + /***** Reset match *****/ + Mch_ResetMatch (&Match); + /***** Remove old players. This function must be called by a teacher before getting match status. *****/ @@ -1908,6 +1954,9 @@ void Mch_ChangeNumColsMch (void) { struct Mch_Match Match; + /***** Reset match *****/ + Mch_ResetMatch (&Match); + /***** Remove old players. This function must be called by a teacher before getting match status. *****/ @@ -1941,6 +1990,9 @@ void Mch_ToggleVisibilResultsMchQst (void) { struct Mch_Match Match; + /***** Reset match *****/ + Mch_ResetMatch (&Match); + /***** Remove old players. This function must be called by a teacher before getting match status. *****/ @@ -1973,6 +2025,9 @@ void Mch_BackMatch (void) { struct Mch_Match Match; + /***** Reset match *****/ + Mch_ResetMatch (&Match); + /***** Remove old players. This function must be called by a teacher before getting match status. *****/ @@ -2002,6 +2057,9 @@ void Mch_ForwardMatch (void) { struct Mch_Match Match; + /***** Reset match *****/ + Mch_ResetMatch (&Match); + /***** Remove old players. This function must be called by a teacher before getting match status. *****/ @@ -3628,6 +3686,9 @@ void Mch_JoinMatchAsStd (void) { struct Mch_Match Match; + /***** Reset match *****/ + Mch_ResetMatch (&Match); + /***** Get data of the match from database *****/ Match.MchCod = Mch_GetMchCodBeingPlayed (); Mch_GetDataOfMatchByCod (&Match); @@ -3647,6 +3708,9 @@ void Mch_RemoveMyQuestionAnswer (void) struct Mch_Match Match; unsigned QstInd; + /***** Reset match *****/ + Mch_ResetMatch (&Match); + /***** Get data of the match from database *****/ Match.MchCod = Mch_GetMchCodBeingPlayed (); Mch_GetDataOfMatchByCod (&Match); @@ -3677,6 +3741,9 @@ void Mch_StartCountdown (void) struct Mch_Match Match; long NewCountdown; + /***** Reset match *****/ + Mch_ResetMatch (&Match); + /***** Get countdown parameter ****/ NewCountdown = Par_GetParToLong ("Countdown"); @@ -3711,6 +3778,9 @@ void Mch_RefreshMatchTch (void) if (!Gbl.Session.IsOpen) // If session has been closed, do not write anything return; + /***** Reset match *****/ + Mch_ResetMatch (&Match); + /***** Remove old players. This function must be called by a teacher before getting match status. *****/ @@ -3768,6 +3838,9 @@ void Mch_RefreshMatchStd (void) if (!Gbl.Session.IsOpen) // If session has been closed, do not write anything return; + /***** Reset match *****/ + Mch_ResetMatch (&Match); + /***** Get data of the match from database *****/ Match.MchCod = Mch_GetMchCodBeingPlayed (); Mch_GetDataOfMatchByCod (&Match); @@ -3830,6 +3903,9 @@ void Mch_ReceiveQuestionAnswer (void) struct Mch_UsrAnswer UsrAnswer; struct TstRes_Result Result; + /***** Reset match *****/ + Mch_ResetMatch (&Match); + /***** Get data of the match from database *****/ Match.MchCod = Mch_GetMchCodBeingPlayed (); Mch_GetDataOfMatchByCod (&Match); diff --git a/swad_match.h b/swad_match.h index 89e7d000..c264716f 100644 --- a/swad_match.h +++ b/swad_match.h @@ -85,6 +85,8 @@ struct Mch_UsrAnswer long Mch_GetMchCodBeingPlayed (void); +void Mch_ResetMatch (struct Mch_Match *Match); + void Mch_ListMatches (struct Gam_Games *Games, struct Gam_Game *Game, bool PutFormNewMatch); diff --git a/swad_match_result.c b/swad_match_result.c index 91e7144d..3762b5e4 100644 --- a/swad_match_result.c +++ b/swad_match_result.c @@ -115,7 +115,7 @@ void MchRes_ShowMyMchResultsInCrs (void) extern const char *Txt_Results; struct Gam_Games Games; - /***** Reset games *****/ + /***** Reset games context *****/ Gam_ResetGames (&Games); /***** Get list of games *****/ @@ -156,9 +156,12 @@ void MchRes_ShowMyMchResultsInGam (void) struct Gam_Games Games; struct Gam_Game Game; - /***** Reset games *****/ + /***** Reset games context *****/ Gam_ResetGames (&Games); + /***** Reset game *****/ + Gam_ResetGame (&Game); + /***** Get parameters *****/ if ((Game.GamCod = Gam_GetParams (&Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); @@ -202,9 +205,13 @@ void MchRes_ShowMyMchResultsInMch (void) struct Gam_Game Game; struct Mch_Match Match; - /***** Reset games *****/ + /***** Reset games context *****/ Gam_ResetGames (&Games); + /***** Reset game and match *****/ + Gam_ResetGame (&Game); + Mch_ResetMatch (&Match); + /***** Get parameters *****/ if ((Game.GamCod = Gam_GetParams (&Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); @@ -247,7 +254,7 @@ void MchRes_ShowAllMchResultsInCrs (void) { struct Gam_Games Games; - /***** Reset games *****/ + /***** Reset games context *****/ Gam_ResetGames (&Games); /***** Get users and show their matches results *****/ @@ -318,7 +325,7 @@ void MchRes_SelUsrsToViewMchResults (void) { struct Gam_Games Games; - /***** Reset games *****/ + /***** Reset games context *****/ Gam_ResetGames (&Games); /***** Put form to select users *****/ @@ -351,9 +358,12 @@ void MchRes_ShowAllMchResultsInGam (void) struct Gam_Games Games; struct Gam_Game Game; - /***** Reset games *****/ + /***** Reset games context *****/ Gam_ResetGames (&Games); + /***** Reset game *****/ + Gam_ResetGame (&Game); + /***** Get parameters *****/ if ((Game.GamCod = Gam_GetParams (&Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); @@ -438,9 +448,13 @@ void MchRes_ShowAllMchResultsInMch (void) struct Gam_Game Game; struct Mch_Match Match; - /***** Reset games *****/ + /***** Reset games context *****/ Gam_ResetGames (&Games); + /***** Reset game and match *****/ + Gam_ResetGame (&Game); + Mch_ResetMatch (&Match); + /***** Get parameters *****/ if ((Game.GamCod = Gam_GetParams (&Games)) <= 0) Lay_ShowErrorAndExit ("Code of game is missing."); @@ -567,6 +581,9 @@ static void MchRes_ListGamesToSelect (struct Gam_Games *Games) unsigned NumGame; struct Gam_Game Game; + /***** Reset game *****/ + Gam_ResetGame (&Game); + /***** Begin box *****/ Box_BoxBegin (NULL,Txt_Games, NULL,NULL, @@ -744,6 +761,9 @@ static void MchRes_ShowMchResults (struct Gam_Games *Games, unsigned Visibility; time_t TimeUTC[Dat_NUM_START_END_TIME]; + /***** Reset match *****/ + Mch_ResetMatch (&Match); + /***** Set user *****/ UsrDat = (MeOrOther == Usr_ME) ? &Gbl.Usrs.Me.UsrDat : &Gbl.Usrs.Other.UsrDat; @@ -1067,9 +1087,13 @@ void MchRes_ShowOneMchResult (void) bool ICanViewResult; bool ICanViewScore; - /***** Reset games *****/ + /***** Reset games context *****/ Gam_ResetGames (&Games); + /***** Reset game and match *****/ + Gam_ResetGame (&Game); + Mch_ResetMatch (&Match); + /***** Get and check parameters *****/ Mch_GetAndCheckParameters (&Games,&Game,&Match);