diff --git a/swad_changelog.h b/swad_changelog.h index 741d983c9..79c848eef 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -629,10 +629,11 @@ TODO: Emilce Barrera Mesa: Podr TODO: Emilce Barrera Mesa: Mis estudiantes presentan muchas dificultades a la hora de poner la foto porque la plataforma es muy exigente respecto al fondo de la imagen. */ -#define Log_PLATFORM_VERSION "SWAD 22.107.5 (2023-05-06)" +#define Log_PLATFORM_VERSION "SWAD 22.107.6 (2023-05-06)" #define CSS_FILE "swad22.107.css" #define JS_FILE "swad22.49.js" /* + Version 22.107.6: May 06, 2023 Code refactoring in edition of exam. (338023 lines) Version 22.107.5: May 06, 2023 Changes in edition of rubric. (338027 lines) Version 22.107.4: May 06, 2023 Changes in edition of exam. (338040 lines) Version 22.107.3: May 06, 2023 Changes in edition of exam. (338045 lines) diff --git a/swad_exam.c b/swad_exam.c index 36415da50..8bbfb97ec 100644 --- a/swad_exam.c +++ b/swad_exam.c @@ -1227,7 +1227,7 @@ void Exa_ReqCreatOrEditExam (void) { struct Exa_Exams Exams; struct ExaSet_Set Set; - bool ItsANewExam; + Exa_ExistingNewExam_t ExistingNewExam; /***** Check if I can edit exams *****/ if (!Exa_CheckIfICanEditExams ()) @@ -1240,18 +1240,22 @@ void Exa_ReqCreatOrEditExam (void) /***** Get parameters *****/ Exa_GetPars (&Exams,Exa_DONT_CHECK_EXA_COD); - ItsANewExam = (Exams.Exam.ExaCod <= 0); + ExistingNewExam = (Exams.Exam.ExaCod > 0) ? Exa_EXISTING_EXAM : + Exa_NEW_EXAM; /***** Get exam data *****/ - if (ItsANewExam) - /* Initialize to empty exam */ - Exa_ResetExam (&Exams.Exam); - else - /* Get exam data from database */ - Exa_GetExamDataByCod (&Exams.Exam); + switch (ExistingNewExam) + { + case Exa_EXISTING_EXAM: + /* Get exam data from database */ + Exa_GetExamDataByCod (&Exams.Exam); + break; + case Exa_NEW_EXAM: + break; + } /***** Put form to create/edit an exam and show sets *****/ - Exa_PutFormsOneExam (&Exams,&Set,ItsANewExam); + Exa_PutFormsOneExam (&Exams,&Set,ExistingNewExam); } /*****************************************************************************/ @@ -1430,7 +1434,7 @@ void Exa_ReceiveFormExam (void) { struct Exa_Exams Exams; struct ExaSet_Set Set; - bool ItsANewExam; + Exa_ExistingNewExam_t ExistingNewExam; char Txt[Cns_MAX_BYTES_TEXT + 1]; /***** Check if I can edit exams *****/ @@ -1444,31 +1448,41 @@ void Exa_ReceiveFormExam (void) /***** Get parameters *****/ Exa_GetPars (&Exams,Exa_DONT_CHECK_EXA_COD); - ItsANewExam = (Exams.Exam.ExaCod <= 0); + ExistingNewExam = (Exams.Exam.ExaCod > 0) ? Exa_EXISTING_EXAM : + Exa_NEW_EXAM; /***** Get all current exam data from database *****/ // Some data, not received from form, // are necessary to show exam and sets of questions again - if (!ItsANewExam) - Exa_GetExamDataByCod (&Exams.Exam); + switch (ExistingNewExam) + { + case Exa_EXISTING_EXAM: + Exa_GetExamDataByCod (&Exams.Exam); + break; + case Exa_NEW_EXAM: + break; + } /***** Overwrite some exam data with the data received from form *****/ Exa_ReceiveExamFieldsFromForm (&Exams.Exam,Txt); if (Exa_CheckExamFieldsReceivedFromForm (&Exams.Exam)) - { /***** Create a new exam or update an existing one *****/ - if (ItsANewExam) + switch (ExistingNewExam) { - Exa_CreateExam (&Exams.Exam,Txt); // Add new exam to database - ItsANewExam = false; + case Exa_EXISTING_EXAM: + Exa_UpdateExam (&Exams.Exam,Txt); // Update exam data in database + break; + case Exa_NEW_EXAM: + Exa_CreateExam (&Exams.Exam,Txt); // Add new exam to database + ExistingNewExam = Exa_EXISTING_EXAM; + break; } - else - Exa_UpdateExam (&Exams.Exam,Txt); // Update exam data in database - } + + /***** Show pending alerts */ + Ale_ShowAlerts (NULL); /***** Show current exam and its sets *****/ - Exa_PutFormsOneExam (&Exams,&Set, - ItsANewExam); + Exa_PutFormsOneExam (&Exams,&Set,ExistingNewExam); } static void Exa_ReceiveExamFieldsFromForm (struct Exa_Exam *Exam, @@ -1506,8 +1520,9 @@ static bool Exa_CheckExamFieldsReceivedFromForm (const struct Exa_Exam *Exam) Exam->ExaCod,Exam->Title)) { NewExamIsCorrect = false; - Ale_ShowAlert (Ale_WARNING,Txt_Already_existed_an_exam_with_the_title_X, - Exam->Title); + Ale_CreateAlert (Ale_WARNING,NULL, + Txt_Already_existed_an_exam_with_the_title_X, + Exam->Title); } } else // If there is not an exam title diff --git a/swad_exam_set.c b/swad_exam_set.c index bceefa821..6f316adb1 100644 --- a/swad_exam_set.c +++ b/swad_exam_set.c @@ -269,8 +269,7 @@ void ExaSet_ReceiveFormSet (void) ExaSet_CreateSet (&Set); // Add new set to database /***** Show current exam and its sets *****/ - Exa_PutFormsOneExam (&Exams,&Set, - false); // It's not a new exam + Exa_PutFormsOneExam (&Exams,&Set,Exa_EXISTING_EXAM); } static void ExaSet_ReceiveSetFieldsFromForm (struct ExaSet_Set *Set) @@ -357,8 +356,7 @@ void ExaSet_ChangeSetTitle (void) } /***** Show current exam and its sets *****/ - Exa_PutFormsOneExam (&Exams,&Set, - false); // It's not a new exam + Exa_PutFormsOneExam (&Exams,&Set,Exa_EXISTING_EXAM); } /*****************************************************************************/ @@ -404,8 +402,7 @@ void ExaSet_ChangeNumQstsToExam (void) } /***** Show current exam and its sets *****/ - Exa_PutFormsOneExam (&Exams,&Set, - false); // It's not a new exam + Exa_PutFormsOneExam (&Exams,&Set,Exa_EXISTING_EXAM); } /*****************************************************************************/ @@ -450,8 +447,7 @@ void ExaSet_ReqSelectQstsToAddToSet (void) Qst_RequestSelectQstsForExamSet (&Exams); /***** Show current exam and its sets *****/ - Exa_PutFormsOneExam (&Exams,&Set, - false); // It's not a new exam + Exa_PutFormsOneExam (&Exams,&Set,Exa_EXISTING_EXAM); } /*****************************************************************************/ @@ -479,8 +475,7 @@ void ExaSet_ListQstsToAddToSet (void) Qst_ListQuestionsToSelectForExamSet (&Exams); /***** Show current exam and its sets *****/ - Exa_PutFormsOneExam (&Exams,&Set, - false); // It's not a new exam + Exa_PutFormsOneExam (&Exams,&Set,Exa_EXISTING_EXAM); } /*****************************************************************************/ @@ -1144,8 +1139,7 @@ void ExaSet_AddQstsToSet (void) ExaSet_FreeListsSelectedQuestions (&Exams); /***** Show current exam and its sets *****/ - Exa_PutFormsOneExam (&Exams,&Set, - false); // It's not a new exam + Exa_PutFormsOneExam (&Exams,&Set,Exa_EXISTING_EXAM); } /*****************************************************************************/ @@ -1275,8 +1269,7 @@ void ExaSet_ReqRemSet (void) Set.Title); /***** Show current exam and its sets *****/ - Exa_PutFormsOneExam (&Exams,&Set, - false); // It's not a new exam + Exa_PutFormsOneExam (&Exams,&Set,Exa_EXISTING_EXAM); } /*****************************************************************************/ @@ -1315,8 +1308,7 @@ void ExaSet_RemoveSet (void) Ale_ShowAlert (Ale_SUCCESS,Txt_Set_of_questions_removed); /***** Show current exam and its sets *****/ - Exa_PutFormsOneExam (&Exams,&Set, - false); // It's not a new exam + Exa_PutFormsOneExam (&Exams,&Set,Exa_EXISTING_EXAM); } /*****************************************************************************/ @@ -1361,8 +1353,7 @@ void ExaSet_MoveUpSet (void) Ale_ShowAlert (Ale_WARNING,Txt_Movement_not_allowed); /***** Show current exam and its sets *****/ - Exa_PutFormsOneExam (&Exams,&Set, - false); // It's not a new exam + Exa_PutFormsOneExam (&Exams,&Set,Exa_EXISTING_EXAM); } /*****************************************************************************/ @@ -1411,8 +1402,7 @@ void ExaSet_MoveDownSet (void) Ale_ShowAlert (Ale_WARNING,Txt_Movement_not_allowed); /***** Show current exam and its sets *****/ - Exa_PutFormsOneExam (&Exams,&Set, - false); // It's not a new exam + Exa_PutFormsOneExam (&Exams,&Set,Exa_EXISTING_EXAM); } /*****************************************************************************/ @@ -1452,8 +1442,7 @@ void ExaSet_ReqRemQstFromSet (void) Frm_FreeAnchorStr (&Anchor); /***** Show current exam and its sets *****/ - Exa_PutFormsOneExam (&Exams,&Set, - false); // It's not a new exam + Exa_PutFormsOneExam (&Exams,&Set,Exa_EXISTING_EXAM); } /*****************************************************************************/ @@ -1489,8 +1478,7 @@ void ExaSet_RemoveQstFromSet (void) Ale_ShowAlert (Ale_SUCCESS,Txt_Question_removed); /***** Show current exam and its sets *****/ - Exa_PutFormsOneExam (&Exams,&Set, - false); // It's not a new exam + Exa_PutFormsOneExam (&Exams,&Set,Exa_EXISTING_EXAM); } /*****************************************************************************/ @@ -1564,8 +1552,7 @@ static void ExaSet_ChangeValidityQst (Qst_Validity_t Validity) Validity); /***** Show current exam and its sets *****/ - Exa_PutFormsOneExam (&Exams,&Set, - false); // It's not a new exam + Exa_PutFormsOneExam (&Exams,&Set,Exa_EXISTING_EXAM); } /*****************************************************************************/ diff --git a/swad_game.c b/swad_game.c index ab83b8187..6adfc5d25 100644 --- a/swad_game.c +++ b/swad_game.c @@ -144,9 +144,9 @@ static Gam_Order_t Gam_GetParOrder (void); static void Gam_RemoveGameFromAllTables (long GamCod); -static void Gam_PutFormsEditionGame (struct Gam_Games *Games, - char Txt[Cns_MAX_BYTES_TEXT + 1], - Gam_ExistingNewGame_t ExistingNewGame); +static void Gam_PutFormEditionGame (struct Gam_Games *Games, + char Txt[Cns_MAX_BYTES_TEXT + 1], + Gam_ExistingNewGame_t ExistingNewGame); static void Gam_ReceiveGameFieldsFromForm (struct Gam_Game *Game, char Txt[Cns_MAX_BYTES_TEXT + 1]); static bool Gam_CheckGameFieldsReceivedFromForm (const struct Gam_Game *Game); @@ -1268,7 +1268,7 @@ void Gam_ReqCreatOrEditGame (void) } /***** Put forms to create/edit a game *****/ - Gam_PutFormsEditionGame (&Games,Txt,ExistingNewGame); + Gam_PutFormEditionGame (&Games,Txt,ExistingNewGame); /***** Show games or questions *****/ switch (ExistingNewGame) @@ -1288,9 +1288,9 @@ void Gam_ReqCreatOrEditGame (void) /********************* Put a form to create/edit a game **********************/ /*****************************************************************************/ -static void Gam_PutFormsEditionGame (struct Gam_Games *Games, - char Txt[Cns_MAX_BYTES_TEXT + 1], - Gam_ExistingNewGame_t ExistingNewGame) +static void Gam_PutFormEditionGame (struct Gam_Games *Games, + char Txt[Cns_MAX_BYTES_TEXT + 1], + Gam_ExistingNewGame_t ExistingNewGame) { extern const char *Hlp_ASSESSMENT_Games_edit_game; extern const char *Hlp_ASSESSMENT_Games_new_game; @@ -1447,7 +1447,6 @@ void Gam_ReceiveFormGame (void) /***** Receive game from form *****/ Gam_ReceiveGameFieldsFromForm (&Games.Game,Txt); if (Gam_CheckGameFieldsReceivedFromForm (&Games.Game)) - { /***** Create a new game or update an existing one *****/ switch (ExistingNewGame) { @@ -1456,34 +1455,28 @@ void Gam_ReceiveFormGame (void) break; case Gam_NEW_GAME: Gam_CreateGame (&Games.Game,Txt); // Add new game to database + ExistingNewGame = Gam_EXISTING_GAME; break; } - /***** Put forms to edit the game created or updated *****/ - Gam_PutFormsEditionGame (&Games,Txt,Gam_EXISTING_GAME); + /***** Show pending alerts */ + Ale_ShowAlerts (NULL); - /***** Show questions of the game ready to be edited ******/ - Gam_ListGameQuestions (&Games); - } - else + /***** Put forms to create/edit the game *****/ + Gam_PutFormEditionGame (&Games,Txt,ExistingNewGame); + + /***** Show games or questions *****/ + switch (ExistingNewGame) { - /***** Put forms to create/edit the game *****/ - Gam_PutFormsEditionGame (&Games,Txt,ExistingNewGame); - - /***** Show games or questions *****/ - switch (ExistingNewGame) - { - case Gam_EXISTING_GAME: - /* Show questions of the game ready to be edited */ - Gam_ListGameQuestions (&Games); - break; - case Gam_NEW_GAME: - /* Show games again */ - Gam_ListAllGames (&Games); - break; - } + case Gam_EXISTING_GAME: + /* Show questions of the game ready to be edited */ + Gam_ListGameQuestions (&Games); + break; + case Gam_NEW_GAME: + /* Show games again */ + Gam_ListAllGames (&Games); + break; } - } static void Gam_ReceiveGameFieldsFromForm (struct Gam_Game *Game, @@ -1520,8 +1513,9 @@ static bool Gam_CheckGameFieldsReceivedFromForm (const struct Gam_Game *Game) if (Gam_DB_CheckIfSimilarGameExists (Game)) { NewGameIsCorrect = false; - Ale_ShowAlert (Ale_WARNING,Txt_Already_existed_a_game_with_the_title_X, - Game->Title); + Ale_CreateAlert (Ale_WARNING,NULL, + Txt_Already_existed_a_game_with_the_title_X, + Game->Title); } } else // If there is not a game title diff --git a/swad_rubric.c b/swad_rubric.c index 37ef9f32d..8f0282ac6 100644 --- a/swad_rubric.c +++ b/swad_rubric.c @@ -976,7 +976,6 @@ void Rub_ReceiveFormRubric (void) /***** Overwrite some rubric data with the data received from form *****/ Rub_ReceiveRubricFieldsFromForm (&Rubrics.Rubric); if (Rub_CheckRubricFieldsReceivedFromForm (&Rubrics.Rubric)) - { /***** Create a new rubric or update an existing one *****/ switch (ExistingNewRubric) { @@ -988,7 +987,6 @@ void Rub_ReceiveFormRubric (void) ExistingNewRubric = Rub_EXISTING_RUBRIC; break; } - } /***** Show pending alerts */ Ale_ShowAlerts (NULL); @@ -1022,8 +1020,9 @@ static bool Rub_CheckRubricFieldsReceivedFromForm (const struct Rub_Rubric *Rubr if (Rub_DB_CheckIfSimilarRubricExists (Rubric)) { NewRubricIsCorrect = false; - Ale_ShowAlert (Ale_WARNING,Txt_Already_existed_a_game_with_the_title_X, - Rubric->Title); + Ale_CreateAlert (Ale_WARNING,NULL, + Txt_Already_existed_a_game_with_the_title_X, + Rubric->Title); } } else // If there is not a rubric title