From de4074523ecd5829c58240055c33510a3b764979 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Mon, 8 Apr 2019 23:34:58 +0200 Subject: [PATCH] Version18.102 --- swad_action.c | 12 +- swad_alert.h | 2 +- swad_centre.c | 2 +- swad_changelog.h | 3 +- swad_country.c | 4 +- swad_course.c | 4 +- swad_degree.c | 2 +- swad_degree_type.c | 2 +- swad_department.c | 284 ++++++++++++++++++++++++++++++--------------- swad_department.h | 2 + swad_global.c | 4 - swad_global.h | 2 +- swad_hierarchy.c | 3 - swad_institution.c | 4 +- swad_text.c | 21 ++++ 15 files changed, 231 insertions(+), 120 deletions(-) diff --git a/swad_action.c b/swad_action.c index 2563608a..c96ebf35 100644 --- a/swad_action.c +++ b/swad_action.c @@ -1785,12 +1785,12 @@ struct Act_Actions Act_Actions[Act_NUM_ACTIONS] = /* ActRenPlcFul */{ 895,-1,TabUnk,ActSeePlc , 0, 0, 0, 0,0x200, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Plc_RenamePlaceFull ,NULL}, /* ActEdiDpt */{ 677,-1,TabUnk,ActSeeDpt , 0, 0, 0, 0,0x200, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Dpt_EditDepartments ,NULL}, - /* ActNewDpt */{ 687,-1,TabUnk,ActSeeDpt , 0, 0, 0, 0,0x200, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Dpt_RecFormNewDpt ,NULL}, - /* ActRemDpt */{ 690,-1,TabUnk,ActSeeDpt , 0, 0, 0, 0,0x200, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Dpt_RemoveDepartment ,NULL}, - /* ActChgDptIns */{ 721,-1,TabUnk,ActSeeDpt , 0, 0, 0, 0,0x200, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Dpt_ChangeDepartIns ,NULL}, - /* ActRenDptSho */{ 688,-1,TabUnk,ActSeeDpt , 0, 0, 0, 0,0x200, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Dpt_RenameDepartShort ,NULL}, - /* ActRenDptFul */{ 689,-1,TabUnk,ActSeeDpt , 0, 0, 0, 0,0x200, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Dpt_RenameDepartFull ,NULL}, - /* ActChgDptWWW */{ 691,-1,TabUnk,ActSeeDpt , 0, 0, 0, 0,0x200, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Dpt_ChangeDptWWW ,NULL}, + /* ActNewDpt */{ 687,-1,TabUnk,ActSeeDpt , 0, 0, 0, 0,0x200, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,Dpt_RecFormNewDpt ,Dpt_ContEditAfterChgDpt ,NULL}, + /* ActRemDpt */{ 690,-1,TabUnk,ActSeeDpt , 0, 0, 0, 0,0x200, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,Dpt_RemoveDepartment ,Dpt_ContEditAfterChgDpt ,NULL}, + /* ActChgDptIns */{ 721,-1,TabUnk,ActSeeDpt , 0, 0, 0, 0,0x200, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,Dpt_ChangeDepartIns ,Dpt_ContEditAfterChgDpt ,NULL}, + /* ActRenDptSho */{ 688,-1,TabUnk,ActSeeDpt , 0, 0, 0, 0,0x200, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,Dpt_RenameDepartShort ,Dpt_ContEditAfterChgDpt ,NULL}, + /* ActRenDptFul */{ 689,-1,TabUnk,ActSeeDpt , 0, 0, 0, 0,0x200, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,Dpt_RenameDepartFull ,Dpt_ContEditAfterChgDpt ,NULL}, + /* ActChgDptWWW */{ 691,-1,TabUnk,ActSeeDpt , 0, 0, 0, 0,0x200, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,Dpt_ChangeDptWWW ,Dpt_ContEditAfterChgDpt ,NULL}, /* ActEdiHld */{ 713,-1,TabUnk,ActSeeHld , 0, 0, 0, 0,0x300, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Hld_EditHolidays ,NULL}, /* ActNewHld */{ 714,-1,TabUnk,ActSeeHld , 0, 0, 0, 0,0x300, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,Hld_RecFormNewHoliday1 ,Hld_RecFormNewHoliday2 ,NULL}, diff --git a/swad_alert.h b/swad_alert.h index 4d451725..6156f144 100644 --- a/swad_alert.h +++ b/swad_alert.h @@ -35,7 +35,7 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Ale_MAX_ALERTS 10 // Max. number of alerts stored before of beeing shown +#define Ale_MAX_ALERTS 10 // Max. number of alerts stored before of being shown /*****************************************************************************/ /********************************* Public types ******************************/ diff --git a/swad_centre.c b/swad_centre.c index a201124c..e3b97562 100644 --- a/swad_centre.c +++ b/swad_centre.c @@ -75,7 +75,7 @@ extern struct Globals Gbl; /***************************** Private variables *****************************/ /*****************************************************************************/ -static struct Centre *Ctr_EditingCtr = NULL; // Static variable to keep the centre beeing edited +static struct Centre *Ctr_EditingCtr = NULL; // Static variable to keep the centre being edited /*****************************************************************************/ /***************************** Private prototypes ****************************/ diff --git a/swad_changelog.h b/swad_changelog.h index 2a3adf68..068901aa 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.101.6 (2019-04-08)" +#define Log_PLATFORM_VERSION "SWAD 18.102 (2019-04-08)" #define CSS_FILE "swad18.92.css" #define JS_FILE "swad18.92.js" /* + 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) Version 18.101.5: Apr 08, 2019 Code refactoring in edition of institutions. (241898 lines) Version 18.101.4: Apr 08, 2019 Code refactoring in edition of centres. (241908 lines) diff --git a/swad_country.c b/swad_country.c index 8ab6ec3e..c2614e2e 100644 --- a/swad_country.c +++ b/swad_country.c @@ -63,7 +63,7 @@ extern struct Globals Gbl; /***************************** Private variables *****************************/ /*****************************************************************************/ -static struct Country *Cty_EditingCty = NULL; // Static variable to keep the country beeing edited +static struct Country *Cty_EditingCty = NULL; // Static variable to keep the country being edited /*****************************************************************************/ /***************************** Private prototypes ****************************/ @@ -2001,7 +2001,7 @@ void Cty_ContEditAfterChgCty (void) static void Cty_ShowAlertAndButtonToGoToCty (void) { - // If the country beeing edited is different to the current one... + // If the country being edited is different to the current one... if (Cty_EditingCty->CtyCod != Gbl.Hierarchy.Cty.CtyCod) { /***** Alert with button to go to couuntry *****/ diff --git a/swad_course.c b/swad_course.c index bf94afb0..0abeba43 100644 --- a/swad_course.c +++ b/swad_course.c @@ -73,7 +73,7 @@ extern struct Globals Gbl; /**************************** Private variables ******************************/ /*****************************************************************************/ -static struct Course *Crs_EditingCrs = NULL; // Static variable to keep the course beeing edited +static struct Course *Crs_EditingCrs = NULL; // Static variable to keep the course being edited /*****************************************************************************/ /**************************** Private prototypes *****************************/ @@ -2910,7 +2910,7 @@ static void Crs_PutButtonToRegisterInCrs (void) extern const char *Txt_Register_me_in_X; Frm_StartForm (ActReqSignUp); - // If the course beeing edited is different to the current one... + // If the course being edited is different to the current one... if (Crs_EditingCrs->CrsCod != Gbl.Hierarchy.Crs.CrsCod) Crs_PutParamCrsCod (Crs_EditingCrs->CrsCod); snprintf (Gbl.Title,sizeof (Gbl.Title), diff --git a/swad_degree.c b/swad_degree.c index 1466cdc2..14458dee 100644 --- a/swad_degree.c +++ b/swad_degree.c @@ -81,7 +81,7 @@ typedef enum /**************************** Private variables ******************************/ /*****************************************************************************/ -static struct Degree *Deg_EditingDeg = NULL; // Static variable to keep the degree beeing edited +static struct Degree *Deg_EditingDeg = NULL; // Static variable to keep the degree being edited /*****************************************************************************/ /**************************** Private prototypes *****************************/ diff --git a/swad_degree_type.c b/swad_degree_type.c index 25b9d3a5..fc6a7dca 100644 --- a/swad_degree_type.c +++ b/swad_degree_type.c @@ -61,7 +61,7 @@ extern struct Globals Gbl; /**************************** Private variables ******************************/ /*****************************************************************************/ -static struct DegreeType *DT_EditingDegTyp = NULL; // Static variable to keep the degree type beeing edited +static struct DegreeType *DT_EditingDegTyp = NULL; // Static variable to keep the degree type being edited /*****************************************************************************/ /*************************** Private prototypes ******************************/ diff --git a/swad_department.c b/swad_department.c index c2fc0c48..e31b89bf 100644 --- a/swad_department.c +++ b/swad_department.c @@ -40,6 +40,7 @@ #include "swad_language.h" #include "swad_parameter.h" #include "swad_string.h" +#include "swad_table.h" /*****************************************************************************/ /************** External global variables from others modules ****************/ @@ -59,12 +60,15 @@ extern struct Globals Gbl; /***************************** Private variables *****************************/ /*****************************************************************************/ +static struct Department *Dpt_EditingDpt = NULL; // Static variable to keep the department being edited + /*****************************************************************************/ /***************************** Private prototypes ****************************/ /*****************************************************************************/ static void Dpt_GetParamDptOrder (void); static void Dpt_PutIconToEditDpts (void); +static void Dpt_EditDepartmentsInternal (void); static void Dpt_ListDepartmentsForEdition (void); static void Dpt_PutParamDptCod (long DptCod); @@ -76,6 +80,9 @@ static void Dpt_PutFormToCreateDepartment (void); static void Dpt_PutHeadDepartments (void); static void Dpt_CreateDepartment (struct Department *Dpt); +static void Dpt_EditingDepartmentConstructor (void); +static void Dpt_EditingDepartmentDestructor (void); + /*****************************************************************************/ /************************* List all the departments **************************/ /*****************************************************************************/ @@ -83,7 +90,7 @@ static void Dpt_CreateDepartment (struct Department *Dpt); void Dpt_SeeDepts (void) { extern const char *Hlp_INSTITUTION_Departments; - extern const char *Txt_Departments; + extern const char *Txt_Departments_of_INSTITUTION_X; extern const char *Txt_DEPARTMENTS_HELP_ORDER[2]; extern const char *Txt_DEPARTMENTS_ORDER[2]; extern const char *Txt_Other_departments; @@ -104,7 +111,10 @@ void Dpt_SeeDepts (void) Dpt_GetListDepartments (Gbl.Hierarchy.Ins.InsCod); /***** Start box and table *****/ - Box_StartBoxTable (NULL,Txt_Departments, + snprintf (Gbl.Title,sizeof (Gbl.Title), + Txt_Departments_of_INSTITUTION_X, + Gbl.Hierarchy.Ins.FullName); + Box_StartBoxTable (NULL,Gbl.Title, Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM ? Dpt_PutIconToEditDpts : NULL, Hlp_INSTITUTION_Departments,Box_NOT_CLOSABLE,2); @@ -222,12 +232,26 @@ static void Dpt_PutIconToEditDpts (void) /*****************************************************************************/ /******* Put forms to edit the departments of the current institution ********/ /*****************************************************************************/ -// An institution must be selected void Dpt_EditDepartments (void) { + /***** Department constructor *****/ + Dpt_EditingDepartmentConstructor (); + + /***** Edit departments *****/ + Dpt_EditDepartmentsInternal (); + + /***** Department destructor *****/ + Dpt_EditingDepartmentDestructor (); + } + +static void Dpt_EditDepartmentsInternal (void) + { + extern const char *Hlp_INSTITUTION_Departments_edit; + extern const char *Txt_Departments_of_INSTITUTION_X; + /***** Trivial check *****/ - if (Gbl.Hierarchy.Ins.InsCod <= 0) + if (Gbl.Hierarchy.Ins.InsCod <= 0) // An institution must be selected return; /***** Get list of institutions *****/ @@ -236,6 +260,13 @@ void Dpt_EditDepartments (void) /***** Get list of departments *****/ Dpt_GetListDepartments (Gbl.Hierarchy.Ins.InsCod); + /***** Start box *****/ + snprintf (Gbl.Title,sizeof (Gbl.Title), + Txt_Departments_of_INSTITUTION_X, + Gbl.Hierarchy.Ins.FullName); + Box_StartBox (NULL,Gbl.Title,NULL, + Hlp_INSTITUTION_Departments_edit,Box_NOT_CLOSABLE); + /***** Put a form to create a new department *****/ Dpt_PutFormToCreateDepartment (); @@ -243,6 +274,9 @@ void Dpt_EditDepartments (void) if (Gbl.Dpts.Num) Dpt_ListDepartmentsForEdition (); + /***** End box *****/ + Box_EndBox (); + /***** Free list of departments *****/ Dpt_FreeListDepartments (); @@ -451,17 +485,14 @@ unsigned Dpt_GetNumDepartmentsInInstitution (long InsCod) static void Dpt_ListDepartmentsForEdition (void) { - extern const char *Hlp_INSTITUTION_Departments_edit; - extern const char *Txt_Departments; extern const char *Txt_Another_institution; unsigned NumDpt; struct Department *Dpt; struct Instit Ins; unsigned NumIns; - /***** Start box and table *****/ - Box_StartBoxTable (NULL,Txt_Departments,NULL, - Hlp_INSTITUTION_Departments_edit,Box_NOT_CLOSABLE,2); + /***** Start table *****/ + Tbl_StartTable (2); /***** Write heading *****/ Dpt_PutHeadDepartments (); @@ -564,8 +595,8 @@ static void Dpt_ListDepartmentsForEdition (void) Dpt->NumTchs); } - /***** End table and box *****/ - Box_EndBoxTable (); + /***** End table *****/ + Tbl_EndTable (); } /*****************************************************************************/ @@ -600,31 +631,32 @@ void Dpt_RemoveDepartment (void) { extern const char *Txt_To_remove_a_department_you_must_first_remove_all_teachers_in_the_department; extern const char *Txt_Department_X_removed; - struct Department Dpt; + + /***** Department constructor *****/ + Dpt_EditingDepartmentConstructor (); /***** Get department code *****/ - Dpt.DptCod = Dpt_GetAndCheckParamDptCod (1); + Dpt_EditingDpt->DptCod = Dpt_GetAndCheckParamDptCod (1); /***** Get data of the department from database *****/ - Dpt_GetDataOfDepartmentByCod (&Dpt); + Dpt_GetDataOfDepartmentByCod (Dpt_EditingDpt); /***** Check if this department has teachers *****/ - if (Dpt.NumTchs) // Department has teachers ==> don't remove - Ale_ShowAlert (Ale_WARNING,Txt_To_remove_a_department_you_must_first_remove_all_teachers_in_the_department); + if (Dpt_EditingDpt->NumTchs) // Department has teachers ==> don't remove + Ale_CreateAlert (Ale_WARNING,NULL, + Txt_To_remove_a_department_you_must_first_remove_all_teachers_in_the_department); else // Department has no teachers ==> remove it { /***** Remove department *****/ DB_QueryDELETE ("can not remove a department", "DELETE FROM departments WHERE DptCod=%ld", - Dpt.DptCod); + Dpt_EditingDpt->DptCod); /***** Write message to show the change made *****/ - Ale_ShowAlert (Ale_SUCCESS,Txt_Department_X_removed, - Dpt.FullName); + Ale_CreateAlert (Ale_SUCCESS,NULL, + Txt_Department_X_removed, + Dpt_EditingDpt->FullName); } - - /***** Show the form again *****/ - Dpt_EditDepartments (); } /*****************************************************************************/ @@ -634,27 +666,29 @@ void Dpt_RemoveDepartment (void) void Dpt_ChangeDepartIns (void) { extern const char *Txt_The_institution_of_the_department_has_changed; - struct Department *Dpt; + long NewInsCod; - Dpt = &Gbl.Dpts.EditingDpt; + /***** Department constructor *****/ + Dpt_EditingDepartmentConstructor (); /***** Get parameters from form *****/ /* Get the code of the department */ - Dpt->DptCod = Dpt_GetAndCheckParamDptCod (1); + Dpt_EditingDpt->DptCod = Dpt_GetAndCheckParamDptCod (1); /* Get parameter with institution code */ - Dpt->InsCod = Ins_GetAndCheckParamOtherInsCod (1); + NewInsCod = Ins_GetAndCheckParamOtherInsCod (1); + + /***** Get data of the department from database *****/ + Dpt_GetDataOfDepartmentByCod (Dpt_EditingDpt); /***** Update institution in table of departments *****/ DB_QueryUPDATE ("can not update the institution of a department", "UPDATE departments SET InsCod=%ld WHERE DptCod=%ld", - Dpt->InsCod,Dpt->DptCod); + NewInsCod,Dpt_EditingDpt->DptCod); /***** Write message to show the change made *****/ - Ale_ShowAlert (Ale_SUCCESS,Txt_The_institution_of_the_department_has_changed); - - /***** Show the form again *****/ - Dpt_EditDepartments (); + Ale_CreateAlert (Ale_SUCCESS,NULL, + Txt_The_institution_of_the_department_has_changed); } /*****************************************************************************/ @@ -663,6 +697,10 @@ void Dpt_ChangeDepartIns (void) void Dpt_RenameDepartShort (void) { + /***** Department constructor *****/ + Dpt_EditingDepartmentConstructor (); + + /***** Rename department *****/ Dpt_RenameDepartment (Cns_SHRT_NAME); } @@ -672,6 +710,10 @@ void Dpt_RenameDepartShort (void) void Dpt_RenameDepartFull (void) { + /***** Department constructor *****/ + Dpt_EditingDepartmentConstructor (); + + /***** Rename department *****/ Dpt_RenameDepartment (Cns_FULL_NAME); } @@ -685,44 +727,43 @@ static void Dpt_RenameDepartment (Cns_ShrtOrFullName_t ShrtOrFullName) extern const char *Txt_The_department_X_already_exists; extern const char *Txt_The_department_X_has_been_renamed_as_Y; extern const char *Txt_The_name_of_the_department_X_has_not_changed; - struct Department *Dpt; const char *ParamName = NULL; // Initialized to avoid warning const char *FieldName = NULL; // Initialized to avoid warning size_t MaxBytes = 0; // Initialized to avoid warning char *CurrentDptName = NULL; // Initialized to avoid warning char NewDptName[Hie_MAX_BYTES_FULL_NAME + 1]; - Dpt = &Gbl.Dpts.EditingDpt; switch (ShrtOrFullName) { case Cns_SHRT_NAME: ParamName = "ShortName"; FieldName = "ShortName"; MaxBytes = Hie_MAX_BYTES_SHRT_NAME; - CurrentDptName = Dpt->ShrtName; + CurrentDptName = Dpt_EditingDpt->ShrtName; break; case Cns_FULL_NAME: ParamName = "FullName"; FieldName = "FullName"; MaxBytes = Hie_MAX_BYTES_FULL_NAME; - CurrentDptName = Dpt->FullName; + CurrentDptName = Dpt_EditingDpt->FullName; break; } /***** Get parameters from form *****/ /* Get the code of the department */ - Dpt->DptCod = Dpt_GetAndCheckParamDptCod (1); + Dpt_EditingDpt->DptCod = Dpt_GetAndCheckParamDptCod (1); /* Get the new name for the department */ Par_GetParToText (ParamName,NewDptName,MaxBytes); /***** Get from the database the old names of the department *****/ - Dpt_GetDataOfDepartmentByCod (Dpt); + Dpt_GetDataOfDepartmentByCod (Dpt_EditingDpt); /***** Check if new name is empty *****/ if (!NewDptName[0]) - Ale_ShowAlert (Ale_WARNING,Txt_You_can_not_leave_the_name_of_the_department_X_empty, - CurrentDptName); + Ale_CreateAlert (Ale_WARNING,NULL, + Txt_You_can_not_leave_the_name_of_the_department_X_empty, + CurrentDptName); else { /***** Check if old and new names are the same @@ -730,28 +771,30 @@ static void Dpt_RenameDepartment (Cns_ShrtOrFullName_t ShrtOrFullName) if (strcmp (CurrentDptName,NewDptName)) // Different names { /***** If degree was in database... *****/ - if (Dpt_CheckIfDepartmentNameExists (ParamName,NewDptName,Dpt->DptCod)) - Ale_ShowAlert (Ale_WARNING,Txt_The_department_X_already_exists, - NewDptName); + if (Dpt_CheckIfDepartmentNameExists (ParamName,NewDptName,Dpt_EditingDpt->DptCod)) + Ale_CreateAlert (Ale_WARNING,NULL, + Txt_The_department_X_already_exists, + NewDptName); else { /* Update the table changing old name by new name */ - Dpt_UpdateDegNameDB (Dpt->DptCod,FieldName,NewDptName); + Dpt_UpdateDegNameDB (Dpt_EditingDpt->DptCod,FieldName,NewDptName); /* Write message to show the change made */ - Ale_ShowAlert (Ale_SUCCESS,Txt_The_department_X_has_been_renamed_as_Y, - CurrentDptName,NewDptName); + Ale_CreateAlert (Ale_SUCCESS,NULL, + Txt_The_department_X_has_been_renamed_as_Y, + CurrentDptName,NewDptName); } } else // The same name - Ale_ShowAlert (Ale_INFO,Txt_The_name_of_the_department_X_has_not_changed, - CurrentDptName); + Ale_CreateAlert (Ale_INFO,NULL, + Txt_The_name_of_the_department_X_has_not_changed, + CurrentDptName); } - /***** Show the form again *****/ + /***** Update name *****/ Str_Copy (CurrentDptName,NewDptName, MaxBytes); - Dpt_EditDepartments (); } /*****************************************************************************/ @@ -788,37 +831,57 @@ void Dpt_ChangeDptWWW (void) { extern const char *Txt_The_new_web_address_is_X; extern const char *Txt_You_can_not_leave_the_web_address_empty; - struct Department *Dpt; char NewWWW[Cns_MAX_BYTES_WWW + 1]; - Dpt = &Gbl.Dpts.EditingDpt; + /***** Department constructor *****/ + Dpt_EditingDepartmentConstructor (); /***** Get parameters from form *****/ /* Get the code of the department */ - Dpt->DptCod = Dpt_GetAndCheckParamDptCod (1); + Dpt_EditingDpt->DptCod = Dpt_GetAndCheckParamDptCod (1); /* Get the new WWW for the department */ Par_GetParToText ("WWW",NewWWW,Cns_MAX_BYTES_WWW); + /***** Get data of the department from database *****/ + Dpt_GetDataOfDepartmentByCod (Dpt_EditingDpt); + /***** Check if new WWW is empty *****/ if (NewWWW[0]) { /* Update the table changing old WWW by new WWW */ DB_QueryUPDATE ("can not update the web of a department", "UPDATE departments SET WWW='%s' WHERE DptCod=%ld", - NewWWW,Dpt->DptCod); + NewWWW,Dpt_EditingDpt->DptCod); /***** Write message to show the change made *****/ - Ale_ShowAlert (Ale_SUCCESS,Txt_The_new_web_address_is_X, - NewWWW); + Ale_CreateAlert (Ale_SUCCESS,NULL, + Txt_The_new_web_address_is_X, + NewWWW); } else - Ale_ShowAlert (Ale_WARNING,Txt_You_can_not_leave_the_web_address_empty); + Ale_CreateAlert (Ale_WARNING,NULL, + Txt_You_can_not_leave_the_web_address_empty); + + /***** Update web *****/ + Str_Copy (Dpt_EditingDpt->WWW,NewWWW, + Cns_MAX_BYTES_WWW); + } + +/*****************************************************************************/ +/******* Show alerts after changing a department and continue editing ********/ +/*****************************************************************************/ + +void Dpt_ContEditAfterChgDpt (void) + { + /***** Write message to show the change made *****/ + Ale_ShowAlerts (NULL); /***** Show the form again *****/ - Str_Copy (Dpt->WWW,NewWWW, - Cns_MAX_BYTES_WWW); - Dpt_EditDepartments (); + Dpt_EditDepartmentsInternal (); + + /***** Department destructor *****/ + Dpt_EditingDepartmentDestructor (); } /*****************************************************************************/ @@ -827,7 +890,6 @@ void Dpt_ChangeDptWWW (void) static void Dpt_PutFormToCreateDepartment (void) { - extern const char *Hlp_INSTITUTION_Departments_edit; extern const char *Txt_New_department; extern const char *Txt_Institution; extern const char *Txt_Short_name; @@ -835,17 +897,14 @@ static void Dpt_PutFormToCreateDepartment (void) extern const char *Txt_WWW; extern const char *Txt_Another_institution; extern const char *Txt_Create_department; - struct Department *Dpt; unsigned NumIns; - Dpt = &Gbl.Dpts.EditingDpt; - /***** Start form *****/ Frm_StartForm (ActNewDpt); /***** Start box and table *****/ Box_StartBoxTable (NULL,Txt_New_department,NULL, - Hlp_INSTITUTION_Departments_edit,Box_NOT_CLOSABLE,2); + NULL,Box_NOT_CLOSABLE,2); /***** Write heading *****/ fprintf (Gbl.F.Out,"" @@ -872,7 +931,7 @@ static void Dpt_PutFormToCreateDepartment (void) "" "" @@ -893,7 +952,7 @@ static void Dpt_PutFormToCreateDepartment (void) " class=\"INPUT_SHORT_NAME\"" " required=\"required\" />" "", - Hie_MAX_CHARS_SHRT_NAME,Dpt->ShrtName); + Hie_MAX_CHARS_SHRT_NAME,Dpt_EditingDpt->ShrtName); /***** Department full name *****/ fprintf (Gbl.F.Out,"" @@ -902,7 +961,7 @@ static void Dpt_PutFormToCreateDepartment (void) " class=\"INPUT_FULL_NAME\"" " required=\"required\" />" "", - Hie_MAX_CHARS_FULL_NAME,Dpt->FullName); + Hie_MAX_CHARS_FULL_NAME,Dpt_EditingDpt->FullName); /***** Department WWW *****/ fprintf (Gbl.F.Out,"" @@ -912,7 +971,7 @@ static void Dpt_PutFormToCreateDepartment (void) " required=\"required\" />" "" "", - Cns_MAX_CHARS_WWW,Dpt->WWW); + Cns_MAX_CHARS_WWW,Dpt_EditingDpt->WWW); /***** End table, send button and end box *****/ Box_EndBoxTableWithButton (Btn_CREATE_BUTTON,Txt_Create_department); @@ -971,47 +1030,54 @@ static void Dpt_PutHeadDepartments (void) void Dpt_RecFormNewDpt (void) { extern const char *Txt_The_department_X_already_exists; + extern const char *Txt_Created_new_department_X; extern const char *Txt_You_must_specify_the_web_address_of_the_new_department; extern const char *Txt_You_must_specify_the_short_name_and_the_full_name_of_the_new_department; - struct Department *Dpt; - Dpt = &Gbl.Dpts.EditingDpt; + /***** Department constructor *****/ + Dpt_EditingDepartmentConstructor (); /***** Get parameters from form *****/ /* Get institution */ - Dpt->InsCod = Ins_GetAndCheckParamOtherInsCod (1); + Dpt_EditingDpt->InsCod = Ins_GetAndCheckParamOtherInsCod (1); /* Get department short name */ - Par_GetParToText ("ShortName",Dpt->ShrtName,Hie_MAX_BYTES_SHRT_NAME); + Par_GetParToText ("ShortName",Dpt_EditingDpt->ShrtName,Hie_MAX_BYTES_SHRT_NAME); /* Get department full name */ - Par_GetParToText ("FullName",Dpt->FullName,Hie_MAX_BYTES_FULL_NAME); + Par_GetParToText ("FullName",Dpt_EditingDpt->FullName,Hie_MAX_BYTES_FULL_NAME); /* Get department WWW */ - Par_GetParToText ("WWW",Dpt->WWW,Cns_MAX_BYTES_WWW); + Par_GetParToText ("WWW",Dpt_EditingDpt->WWW,Cns_MAX_BYTES_WWW); - if (Dpt->ShrtName[0] && Dpt->FullName[0]) // If there's a department name + if (Dpt_EditingDpt->ShrtName[0] && + Dpt_EditingDpt->FullName[0]) // If there's a department name { - if (Dpt->WWW[0]) + if (Dpt_EditingDpt->WWW[0]) { /***** If name of department was in database... *****/ - if (Dpt_CheckIfDepartmentNameExists ("ShortName",Dpt->ShrtName,-1L)) - Ale_ShowAlert (Ale_WARNING,Txt_The_department_X_already_exists, - Dpt->ShrtName); - else if (Dpt_CheckIfDepartmentNameExists ("FullName",Dpt->FullName,-1L)) - Ale_ShowAlert (Ale_WARNING,Txt_The_department_X_already_exists, - Dpt->FullName); + if (Dpt_CheckIfDepartmentNameExists ("ShortName",Dpt_EditingDpt->ShrtName,-1L)) + Ale_CreateAlert (Ale_WARNING,NULL, + Txt_The_department_X_already_exists, + Dpt_EditingDpt->ShrtName); + else if (Dpt_CheckIfDepartmentNameExists ("FullName",Dpt_EditingDpt->FullName,-1L)) + Ale_CreateAlert (Ale_WARNING,NULL, + Txt_The_department_X_already_exists, + Dpt_EditingDpt->FullName); else // Add new department to database - Dpt_CreateDepartment (Dpt); + { + Dpt_CreateDepartment (Dpt_EditingDpt); + Ale_ShowAlert (Ale_SUCCESS,Txt_Created_new_department_X, + Dpt_EditingDpt->FullName); + } } else // If there is not a web - Ale_ShowAlert (Ale_WARNING,Txt_You_must_specify_the_web_address_of_the_new_department); + Ale_CreateAlert (Ale_WARNING,NULL, + Txt_You_must_specify_the_web_address_of_the_new_department); } else // If there is not a department name - Ale_ShowAlert (Ale_WARNING,Txt_You_must_specify_the_short_name_and_the_full_name_of_the_new_department); - - /***** Show the form again *****/ - Dpt_EditDepartments (); + Ale_CreateAlert (Ale_WARNING,NULL, + Txt_You_must_specify_the_short_name_and_the_full_name_of_the_new_department); } /*****************************************************************************/ @@ -1020,8 +1086,6 @@ void Dpt_RecFormNewDpt (void) static void Dpt_CreateDepartment (struct Department *Dpt) { - extern const char *Txt_Created_new_department_X; - /***** Create a new department *****/ DB_QueryINSERT ("can not create a new department", "INSERT INTO departments" @@ -1029,10 +1093,6 @@ static void Dpt_CreateDepartment (struct Department *Dpt) " VALUES" " (%ld,'%s','%s','%s')", Dpt->InsCod,Dpt->ShrtName,Dpt->FullName,Dpt->WWW); - - /***** Write success message *****/ - Ale_ShowAlert (Ale_SUCCESS,Txt_Created_new_department_X, - Dpt->FullName); } /*****************************************************************************/ @@ -1131,3 +1191,37 @@ void Dpt_WriteSelectorDepartment (long InsCod,long DptCod, /***** Free list of departments *****/ Dpt_FreeListDepartments (); } + +/*****************************************************************************/ +/********************** Department constructor/destructor ********************/ +/*****************************************************************************/ + +static void Dpt_EditingDepartmentConstructor (void) + { + /***** Pointer must be NULL *****/ + if (Dpt_EditingDpt != NULL) + Lay_ShowErrorAndExit ("Error initializing department."); + + /***** Allocate memory for department *****/ + if ((Dpt_EditingDpt = (struct Department *) malloc (sizeof (struct Department))) == NULL) + Lay_ShowErrorAndExit ("Error allocating memory for department."); + + /***** Reset department *****/ + Dpt_EditingDpt->DptCod = -1L; + Dpt_EditingDpt->InsCod = -1L; + Dpt_EditingDpt->ShrtName[0] = '\0'; + Dpt_EditingDpt->FullName[0] = '\0'; + Dpt_EditingDpt->WWW[0] = '\0'; + Dpt_EditingDpt->NumTchs = 0; + } + +static void Dpt_EditingDepartmentDestructor (void) + { + /***** Free memory used for degree *****/ + if (Dpt_EditingDpt != NULL) + { + free ((void *) Dpt_EditingDpt); + Dpt_EditingDpt = NULL; + } + } + diff --git a/swad_department.h b/swad_department.h index d2bb8374..81500a64 100644 --- a/swad_department.h +++ b/swad_department.h @@ -69,6 +69,8 @@ void Dpt_ChangeDepartIns (void); void Dpt_RenameDepartShort (void); void Dpt_RenameDepartFull (void); void Dpt_ChangeDptWWW (void); +void Dpt_ContEditAfterChgDpt (void); + void Dpt_RecFormNewDpt (void); unsigned Dpt_GetTotalNumberOfDepartments (void); unsigned Dpt_GetNumDptsInIns (long InsCod); diff --git a/swad_global.c b/swad_global.c index 87386c7b..32ea7046 100644 --- a/swad_global.c +++ b/swad_global.c @@ -248,10 +248,6 @@ void Gbl_InitializeGlobals (void) Gbl.Dpts.Num = 0; Gbl.Dpts.Lst = NULL; Gbl.Dpts.SelectedOrder = Dpt_ORDER_DEFAULT; - Gbl.Dpts.EditingDpt.DptCod = -1L; - Gbl.Dpts.EditingDpt.ShrtName[0] = '\0'; - Gbl.Dpts.EditingDpt.FullName[0] = '\0'; - Gbl.Dpts.EditingDpt.WWW[0] = '\0'; Gbl.Plcs.Num = 0; Gbl.Plcs.Lst = NULL; diff --git a/swad_global.h b/swad_global.h index 544a1368..3c67b501 100644 --- a/swad_global.h +++ b/swad_global.h @@ -475,7 +475,7 @@ struct Globals struct { char PathDir[PATH_MAX + 1]; - unsigned NumItem; // Item beeing edited + unsigned NumItem; // Item being edited unsigned ParamNumItem; // Used as parameter in forms bool EditionIsActive; Syl_WhichSyllabus_t WhichSyllabus; diff --git a/swad_hierarchy.c b/swad_hierarchy.c index 6bd6cffc..d35e4a6e 100644 --- a/swad_hierarchy.c +++ b/swad_hierarchy.c @@ -578,9 +578,6 @@ void Hie_InitHierarchy (void) Gbl.Hierarchy.Cod = -1L; } - /***** Initialize default fields for edition to current values *****/ - Gbl.Dpts.EditingDpt.InsCod = Gbl.Hierarchy.Ins.InsCod; - /***** Initialize paths *****/ if (Gbl.Hierarchy.Level == Hie_CRS) // Course selected { diff --git a/swad_institution.c b/swad_institution.c index 7f21843a..867d99d5 100644 --- a/swad_institution.c +++ b/swad_institution.c @@ -63,7 +63,7 @@ extern struct Globals Gbl; /***************************** Private variables *****************************/ /*****************************************************************************/ -static struct Instit *Ins_EditingIns = NULL; // Static variable to keep the institution beeing edited +static struct Instit *Ins_EditingIns = NULL; // Static variable to keep the institution being edited /*****************************************************************************/ /***************************** Private prototypes ****************************/ @@ -2181,7 +2181,7 @@ void Ins_ContEditAfterChgIns (void) static void Ins_ShowAlertAndButtonToGoToIns (void) { - // If the institution beeing edited is different to the current one... + // If the institution being edited is different to the current one... if (Ins_EditingIns->InsCod != Gbl.Hierarchy.Ins.InsCod) { /***** Alert with button to go to institution *****/ diff --git a/swad_text.c b/swad_text.c index 72ed8c3e..3030d824 100644 --- a/swad_text.c +++ b/swad_text.c @@ -7750,6 +7750,27 @@ const char *Txt_Departments = "Departamentos"; #endif +const char *Txt_Departments_of_INSTITUTION_X = // Warning: it is very important to include %s in the following sentences +#if L==1 // ca + "Departaments de %s"; +#elif L==2 // de + "Abteilungen von %s"; +#elif L==3 // en + "Departments of %s"; +#elif L==4 // es + "Departamentos de %s"; +#elif L==5 // fr + "Départements de %s"; +#elif L==6 // gn + "Pehẽ de %s"; // Okoteve traducción +#elif L==7 // it + "Dipartimenti di %s"; +#elif L==8 // pl + "Wydziały %s"; +#elif L==9 // pt + "Departamentos de %s"; +#endif + const char *Txt_Departments_ABBREVIATION = #if L==1 // ca "Depar.";