diff --git a/swad_action.c b/swad_action.c index 8d06deb6..a1d4f671 100644 --- a/swad_action.c +++ b/swad_action.c @@ -1838,12 +1838,12 @@ struct Act_Actions Act_Actions[Act_NUM_ACTIONS] = /* ActChgDegSta */{1207,-1,TabUnk,ActSeeDeg , 0, 0, 0,0x380, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,Deg_ChangeDegStatus ,Deg_ContEditAfterChgDeg ,NULL}, /* ActEdiCla */{1745,-1,TabUnk,ActSeeCla , 0, 0, 0,0x3C6, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Cla_EditClassrooms ,NULL}, - /* ActNewCla */{1746,-1,TabUnk,ActSeeCla , 0, 0, 0,0x3C6, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Cla_RecFormNewClassroom ,NULL}, - /* ActRemCla */{1747,-1,TabUnk,ActSeeCla , 0, 0, 0,0x3C6, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Cla_RemoveClassroom ,NULL}, - /* ActRenClaSho */{1748,-1,TabUnk,ActSeeCla , 0, 0, 0,0x3C6, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Cla_RenameClassroomShort ,NULL}, - /* ActRenClaFul */{1749,-1,TabUnk,ActSeeCla , 0, 0, 0,0x3C6, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Cla_RenameClassroomFull ,NULL}, - /* ActChgClaMaxStd */{1750,-1,TabUnk,ActSeeCla , 0, 0, 0,0x3C6, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Cla_ChangeCapacity ,NULL}, - /* ActRenClaLoc */{1751,-1,TabUnk,ActSeeCla , 0, 0, 0,0x3C6, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Cla_ChangeClassroomLocation ,NULL}, + /* ActNewCla */{1746,-1,TabUnk,ActSeeCla , 0, 0, 0,0x3C6, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,Cla_RecFormNewClassroom ,Cla_ContEditAfterChgCla ,NULL}, + /* ActRemCla */{1747,-1,TabUnk,ActSeeCla , 0, 0, 0,0x3C6, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,Cla_RemoveClassroom ,Cla_ContEditAfterChgCla ,NULL}, + /* ActRenClaSho */{1748,-1,TabUnk,ActSeeCla , 0, 0, 0,0x3C6, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,Cla_RenameClassroomShort ,Cla_ContEditAfterChgCla ,NULL}, + /* ActRenClaFul */{1749,-1,TabUnk,ActSeeCla , 0, 0, 0,0x3C6, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,Cla_RenameClassroomFull ,Cla_ContEditAfterChgCla ,NULL}, + /* ActChgClaMaxStd */{1750,-1,TabUnk,ActSeeCla , 0, 0, 0,0x3C6, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,Cla_ChangeCapacity ,Cla_ContEditAfterChgCla ,NULL}, + /* ActRenClaLoc */{1751,-1,TabUnk,ActSeeCla , 0, 0, 0,0x3C6, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,Cla_ChangeClassroomLocation ,Cla_ContEditAfterChgCla ,NULL}, // TabDeg ****************************************************************** // Actions in menu: diff --git a/swad_changelog.h b/swad_changelog.h index 6bbfe6f2..700a9a09 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -464,10 +464,11 @@ En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 18.103 (2019-04-09)" +#define Log_PLATFORM_VERSION "SWAD 18.104 (2019-04-09)" #define CSS_FILE "swad18.92.css" #define JS_FILE "swad18.92.js" /* + Version 18.104: Apr 09, 2019 Code refactoring in edition of classrooms. (242151 lines) Version 18.103: Apr 09, 2019 Code refactoring in edition of places. (242091 lines) Version 18.102: Apr 08, 2019 Code refactoring in edition of departments. (242033 lines) Version 18.101.6: Apr 08, 2019 Code refactoring in edition of countries. (241940 lines) diff --git a/swad_classroom.c b/swad_classroom.c index 55d5cf26..dde3d503 100644 --- a/swad_classroom.c +++ b/swad_classroom.c @@ -54,6 +54,8 @@ extern struct Globals Gbl; /***************************** Private variables *****************************/ /*****************************************************************************/ +static struct Classroom *Cla_EditingCla = NULL; // Static variable to keep the classroom being edited + /*****************************************************************************/ /***************************** Private prototypes ****************************/ /*****************************************************************************/ @@ -64,6 +66,8 @@ static void Cla_PutIconsListingClassrooms (void); static void Cla_PutIconToEditClassrooms (void); static void Cla_PutIconsEditingClassrooms (void); +static void Cla_EditClassroomsInternal (void); + static void Cla_ListClassroomsForEdition (void); static void Cla_PutParamClaCod (long ClaCod); @@ -77,6 +81,9 @@ static void Cla_PutFormToCreateClassroom (void); static void Cla_PutHeadClassrooms (void); static void Cla_CreateClassroom (struct Classroom *Cla); +static void Cla_EditingClassroomConstructor (void); +static void Cla_EditingClassroomDestructor (void); + /*****************************************************************************/ /************************* List all the classrooms ***************************/ /*****************************************************************************/ @@ -228,6 +235,18 @@ static void Cla_PutIconToEditClassrooms (void) /*****************************************************************************/ void Cla_EditClassrooms (void) + { + /***** Classroom constructor *****/ + Cla_EditingClassroomConstructor (); + + /***** Edit classrooms *****/ + Cla_EditClassroomsInternal (); + + /***** Classroom destructor *****/ + Cla_EditingClassroomDestructor (); + } + +static void Cla_EditClassroomsInternal (void) { extern const char *Hlp_CENTRE_Classrooms_edit; extern const char *Txt_Classrooms; @@ -253,7 +272,6 @@ void Cla_EditClassrooms (void) Cla_FreeListClassrooms (); } - /*****************************************************************************/ /*************** Put contextual icons in edition of classrooms ***************/ /*****************************************************************************/ @@ -561,34 +579,32 @@ long Cla_GetParamClaCod (void) void Cla_RemoveClassroom (void) { extern const char *Txt_Classroom_X_removed; - struct Classroom *Cla; - Cla = &Gbl.Classrooms.EditingCla; + /***** Classroom constructor *****/ + Cla_EditingClassroomConstructor (); /***** Get classroom code *****/ - if ((Cla->ClaCod = Cla_GetParamClaCod ()) == -1L) + if ((Cla_EditingCla->ClaCod = Cla_GetParamClaCod ()) == -1L) Lay_ShowErrorAndExit ("Code of classroom is missing."); /***** Get data of the classroom from database *****/ - Cla_GetDataOfClassroomByCod (Cla); + Cla_GetDataOfClassroomByCod (Cla_EditingCla); /***** Update groups assigned to this classroom *****/ DB_QueryUPDATE ("can not update classroom in groups", "UPDATE crs_grp SET ClaCod=0" // 0 means another classroom " WHERE ClaCod=%ld", - Cla->ClaCod); + Cla_EditingCla->ClaCod); /***** Remove classroom *****/ DB_QueryDELETE ("can not remove a classroom", "DELETE FROM classrooms WHERE ClaCod=%ld", - Cla->ClaCod); + Cla_EditingCla->ClaCod); - /***** Write message to show the change made *****/ - Ale_ShowAlert (Ale_SUCCESS,Txt_Classroom_X_removed, - Cla->FullName); - - /***** Show the form again *****/ - Cla_EditClassrooms (); + /***** Create message to show the change made *****/ + Ale_CreateAlert (Ale_SUCCESS,NULL, + Txt_Classroom_X_removed, + Cla_EditingCla->FullName); } /*****************************************************************************/ @@ -610,6 +626,10 @@ void Cla_RemoveAllClassroomsInCtr (long CtrCod) void Cla_RenameClassroomShort (void) { + /***** Classroom constructor *****/ + Cla_EditingClassroomConstructor (); + + /***** Rename classroom *****/ Cla_RenameClassroom (Cns_SHRT_NAME); } @@ -619,6 +639,10 @@ void Cla_RenameClassroomShort (void) void Cla_RenameClassroomFull (void) { + /***** Classroom constructor *****/ + Cla_EditingClassroomConstructor (); + + /***** Rename classroom *****/ Cla_RenameClassroom (Cns_FULL_NAME); } @@ -632,45 +656,44 @@ static void Cla_RenameClassroom (Cns_ShrtOrFullName_t ShrtOrFullName) extern const char *Txt_The_classroom_X_already_exists; extern const char *Txt_The_classroom_X_has_been_renamed_as_Y; extern const char *Txt_The_name_of_the_classroom_X_has_not_changed; - struct Classroom *Cla; const char *ParamName = NULL; // Initialized to avoid warning const char *FieldName = NULL; // Initialized to avoid warning unsigned MaxBytes = 0; // Initialized to avoid warning char *CurrentClaName = NULL; // Initialized to avoid warning char NewClaName[Cla_MAX_BYTES_FULL_NAME + 1]; - Cla = &Gbl.Classrooms.EditingCla; switch (ShrtOrFullName) { case Cns_SHRT_NAME: ParamName = "ShortName"; FieldName = "ShortName"; MaxBytes = Cla_MAX_BYTES_SHRT_NAME; - CurrentClaName = Cla->ShrtName; + CurrentClaName = Cla_EditingCla->ShrtName; break; case Cns_FULL_NAME: ParamName = "FullName"; FieldName = "FullName"; MaxBytes = Cla_MAX_BYTES_FULL_NAME; - CurrentClaName = Cla->FullName; + CurrentClaName = Cla_EditingCla->FullName; break; } /***** Get parameters from form *****/ /* Get the code of the classroom */ - if ((Cla->ClaCod = Cla_GetParamClaCod ()) == -1L) + if ((Cla_EditingCla->ClaCod = Cla_GetParamClaCod ()) == -1L) Lay_ShowErrorAndExit ("Code of classroom is missing."); /* Get the new name for the classroom */ Par_GetParToText (ParamName,NewClaName,MaxBytes); /***** Get from the database the old names of the classroom *****/ - Cla_GetDataOfClassroomByCod (Cla); + Cla_GetDataOfClassroomByCod (Cla_EditingCla); /***** Check if new name is empty *****/ if (!NewClaName[0]) - Ale_ShowAlert (Ale_WARNING,Txt_You_can_not_leave_the_name_of_the_classroom_X_empty, - CurrentClaName); + Ale_CreateAlert (Ale_WARNING,NULL, + Txt_You_can_not_leave_the_name_of_the_classroom_X_empty, + CurrentClaName); else { /***** Check if old and new names are the same @@ -678,28 +701,30 @@ static void Cla_RenameClassroom (Cns_ShrtOrFullName_t ShrtOrFullName) if (strcmp (CurrentClaName,NewClaName)) // Different names { /***** If classroom was in database... *****/ - if (Cla_CheckIfClassroomNameExists (ParamName,NewClaName,Cla->ClaCod)) - Ale_ShowAlert (Ale_WARNING,Txt_The_classroom_X_already_exists, - NewClaName); + if (Cla_CheckIfClassroomNameExists (ParamName,NewClaName,Cla_EditingCla->ClaCod)) + Ale_CreateAlert (Ale_WARNING,NULL, + Txt_The_classroom_X_already_exists, + NewClaName); else { /* Update the table changing old name by new name */ - Cla_UpdateClaNameDB (Cla->ClaCod,FieldName,NewClaName); + Cla_UpdateClaNameDB (Cla_EditingCla->ClaCod,FieldName,NewClaName); /* Write message to show the change made */ - Ale_ShowAlert (Ale_SUCCESS,Txt_The_classroom_X_has_been_renamed_as_Y, - CurrentClaName,NewClaName); + Ale_CreateAlert (Ale_SUCCESS,NULL, + Txt_The_classroom_X_has_been_renamed_as_Y, + CurrentClaName,NewClaName); } } else // The same name - Ale_ShowAlert (Ale_INFO,Txt_The_name_of_the_classroom_X_has_not_changed, - CurrentClaName); + Ale_CreateAlert (Ale_INFO,NULL, + Txt_The_name_of_the_classroom_X_has_not_changed, + CurrentClaName); } - /***** Show the form again *****/ + /***** Update classroom name *****/ Str_Copy (CurrentClaName,NewClaName, MaxBytes); - Cla_EditClassrooms (); } /*****************************************************************************/ @@ -739,52 +764,51 @@ void Cla_ChangeCapacity (void) extern const char *Txt_The_capacity_of_classroom_X_has_not_changed; extern const char *Txt_The_classroom_X_does_not_have_a_limited_capacity_now; extern const char *Txt_The_capacity_of_classroom_X_is_now_Y; - struct Classroom *Cla; unsigned NewCapacity; - /***** Use current editing classroom *****/ - Cla = &Gbl.Classrooms.EditingCla; + /***** Classroom constructor *****/ + Cla_EditingClassroomConstructor (); /***** Get parameters from form *****/ /* Get the code of the classroom */ - if ((Cla->ClaCod = Cla_GetParamClaCod ()) == -1L) + if ((Cla_EditingCla->ClaCod = Cla_GetParamClaCod ()) == -1L) Lay_ShowErrorAndExit ("Code of classroom is missing."); /* Get the seating capacity of the classroom */ NewCapacity = (unsigned) - Par_GetParToUnsignedLong ("Capacity", - 0, - Cla_MAX_CAPACITY, - Cla_UNLIMITED_CAPACITY); + Par_GetParToUnsignedLong ("Capacity", + 0, + Cla_MAX_CAPACITY, + Cla_UNLIMITED_CAPACITY); /***** Get data of the classroom from database *****/ - Cla_GetDataOfClassroomByCod (Cla); + Cla_GetDataOfClassroomByCod (Cla_EditingCla); /***** Check if the old capacity equals the new one (this happens when return is pressed without changes) *****/ - if (Cla->Capacity == NewCapacity) + if (Cla_EditingCla->Capacity == NewCapacity) /***** Message to show no changes made *****/ - Ale_ShowAlert (Ale_INFO,Txt_The_capacity_of_classroom_X_has_not_changed, - Cla->FullName); + Ale_CreateAlert (Ale_INFO,NULL, + Txt_The_capacity_of_classroom_X_has_not_changed, + Cla_EditingCla->FullName); else { /***** Update the table of groups changing the old capacity to the new *****/ DB_QueryUPDATE ("can not update the capacity of a classroom", "UPDATE classrooms SET Capacity=%u WHERE ClaCod=%ld", - NewCapacity,Cla->ClaCod); - Cla->Capacity = NewCapacity; + NewCapacity,Cla_EditingCla->ClaCod); + Cla_EditingCla->Capacity = NewCapacity; /***** Message to show the change made *****/ if (NewCapacity > Grp_MAX_STUDENTS_IN_A_GROUP) - Ale_ShowAlert (Ale_SUCCESS,Txt_The_classroom_X_does_not_have_a_limited_capacity_now, - Cla->FullName); + Ale_CreateAlert (Ale_SUCCESS,NULL, + Txt_The_classroom_X_does_not_have_a_limited_capacity_now, + Cla_EditingCla->FullName); else - Ale_ShowAlert (Ale_SUCCESS,Txt_The_capacity_of_classroom_X_is_now_Y, - Cla->FullName,NewCapacity); + Ale_CreateAlert (Ale_SUCCESS,NULL, + Txt_The_capacity_of_classroom_X_is_now_Y, + Cla_EditingCla->FullName,NewCapacity); } - - /***** Show the form again *****/ - Cla_EditClassrooms (); } /*****************************************************************************/ @@ -805,41 +829,56 @@ void Cla_ChangeClassroomLocation (void) { extern const char *Txt_The_location_of_the_classroom_X_has_changed_to_Y; extern const char *Txt_The_location_of_the_classroom_X_has_not_changed; - struct Classroom *Cla; char NewLocation[Cla_MAX_BYTES_FULL_NAME + 1]; - Cla = &Gbl.Classrooms.EditingCla; + /***** Classroom constructor *****/ + Cla_EditingClassroomConstructor (); /***** Get parameters from form *****/ /* Get the code of the classroom */ - if ((Cla->ClaCod = Cla_GetParamClaCod ()) == -1L) + if ((Cla_EditingCla->ClaCod = Cla_GetParamClaCod ()) == -1L) Lay_ShowErrorAndExit ("Code of classroom is missing."); /* Get the new location for the classroom */ Par_GetParToText ("Location",NewLocation,Cla_MAX_BYTES_LOCATION); /***** Get from the database the old location of the classroom *****/ - Cla_GetDataOfClassroomByCod (Cla); + Cla_GetDataOfClassroomByCod (Cla_EditingCla); /***** Check if old and new locations are the same (this happens when return is pressed without changes) *****/ - if (strcmp (Cla->Location,NewLocation)) // Different locations + if (strcmp (Cla_EditingCla->Location,NewLocation)) // Different locations { /* Update the table changing old name by new name */ - Cla_UpdateClaNameDB (Cla->ClaCod,"Location",NewLocation); - Str_Copy (Cla->Location,NewLocation, + Cla_UpdateClaNameDB (Cla_EditingCla->ClaCod,"Location",NewLocation); + Str_Copy (Cla_EditingCla->Location,NewLocation, Cla_MAX_BYTES_LOCATION); /* Write message to show the change made */ - Ale_ShowAlert (Ale_SUCCESS,Txt_The_location_of_the_classroom_X_has_changed_to_Y, - Cla->FullName,NewLocation); + Ale_CreateAlert (Ale_SUCCESS,NULL, + Txt_The_location_of_the_classroom_X_has_changed_to_Y, + Cla_EditingCla->FullName,NewLocation); } else // The same location - Ale_ShowAlert (Ale_INFO,Txt_The_location_of_the_classroom_X_has_not_changed, - Cla->FullName); + Ale_CreateAlert (Ale_INFO,NULL, + Txt_The_location_of_the_classroom_X_has_not_changed, + Cla_EditingCla->FullName); + } + +/*****************************************************************************/ +/******* Show alerts after changing a classroom and continue editing *********/ +/*****************************************************************************/ + +void Cla_ContEditAfterChgCla (void) + { + /***** Write message to show the change made *****/ + Ale_ShowAlerts (NULL); /***** Show the form again *****/ - Cla_EditClassrooms (); + Cla_EditClassroomsInternal (); + + /***** Classroom destructor *****/ + Cla_EditingClassroomDestructor (); } /*****************************************************************************/ @@ -850,10 +889,6 @@ static void Cla_PutFormToCreateClassroom (void) { extern const char *Txt_New_classroom; extern const char *Txt_Create_classroom; - struct Classroom *Cla; - - /***** Classroom data *****/ - Cla = &Gbl.Classrooms.EditingCla; /***** Start form *****/ Frm_StartForm (ActNewCla); @@ -879,7 +914,7 @@ static void Cla_PutFormToCreateClassroom (void) " class=\"INPUT_SHORT_NAME\"" " required=\"required\" />" "", - Cla_MAX_CHARS_SHRT_NAME,Cla->ShrtName); + Cla_MAX_CHARS_SHRT_NAME,Cla_EditingCla->ShrtName); /***** Classroom full name *****/ fprintf (Gbl.F.Out,"