From 9455534308b00fd86285c8d32772ec69440a27ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Thu, 4 Apr 2019 11:22:08 +0200 Subject: [PATCH] Version18.95.1 --- swad_changelog.h | 3 +- swad_country.c | 73 +++++++++++++++++++++++++++++++++++++++++------- swad_global.c | 6 ---- swad_global.h | 22 ++++++--------- swad_system.h | 1 - 5 files changed, 74 insertions(+), 31 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index d9e73378..404eb123 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.95 (2019-04-03)" +#define Log_PLATFORM_VERSION "SWAD 18.95.1 (2019-04-03)" #define CSS_FILE "swad18.92.css" #define JS_FILE "swad18.92.js" /* + Version 18.95.1: Apr 03, 2019 Code refactoring in edition of countries. (241607 lines) Version 18.95: Apr 03, 2019 Code refactoring related to hierarchy. (241575 lines) Version 18.94.2: Apr 03, 2019 Remember last role even if last access is old. (241531 lines) Version 18.94.1: Apr 03, 2019 Remember last action and role after login only if last access is recent. (241526 lines) diff --git a/swad_country.c b/swad_country.c index dd528261..144308fc 100644 --- a/swad_country.c +++ b/swad_country.c @@ -100,6 +100,9 @@ static void Cty_PutFormToCreateCountry (void); static void Cty_PutHeadCountriesForEdition (void); static void Cty_CreateCountry (struct Country *Cty); +static void Cty_CountryConstructor (struct Country **Cty); +static void Cty_CountryDestructor (struct Country **Cty); + /*****************************************************************************/ /***************** List countries with pending institutions ******************/ /*****************************************************************************/ @@ -1528,7 +1531,7 @@ static void Cty_GetMapAttribution (long CtyCod,char **MapAttribution) if (row[0][0]) { Length = strlen (row[0]); - if (((*MapAttribution) = (char *) malloc (Length + 1)) == NULL) + if ((*MapAttribution = (char *) malloc (Length + 1)) == NULL) Lay_ShowErrorAndExit ("Error allocating memory for map attribution."); Str_Copy (*MapAttribution,row[0], Length); @@ -1774,12 +1777,13 @@ void Cty_RenameCountry (void) extern const char *Txt_The_country_X_has_been_renamed_as_Y; extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES]; extern const char *Txt_The_name_of_the_country_X_has_not_changed; - struct Country *Cty; + struct Country *Cty = NULL; char NewCtyName[Cty_MAX_BYTES_NAME + 1]; Lan_Language_t Language; char FieldName[4 + 1 + 2 + 1]; // Example: "Name_en" - Cty = &Gbl.Ctys.EditingCty; + /***** Country constructor *****/ + Cty_CountryConstructor (&Cty); /***** Get the code of the country *****/ Cty->CtyCod = Cty_GetAndCheckParamOtherCtyCod (0); @@ -1829,6 +1833,9 @@ void Cty_RenameCountry (void) Cty->Name[Language]); } + /***** Country destructor *****/ + Cty_CountryDestructor (&Cty); + /***** Show the form again *****/ Cty_EditCountries (); } @@ -1900,11 +1907,12 @@ void Cty_ChangeCtyWWW (void) { extern const char *Txt_The_new_web_address_is_X; extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES]; - struct Country *Cty; + struct Country *Cty = NULL; char NewWWW[Cns_MAX_BYTES_WWW + 1]; Lan_Language_t Language; - Cty = &Gbl.Ctys.EditingCty; + /***** Country constructor *****/ + Cty_CountryConstructor (&Cty); /***** Get the code of the country *****/ Cty->CtyCod = Cty_GetAndCheckParamOtherCtyCod (0); @@ -1930,6 +1938,9 @@ void Cty_ChangeCtyWWW (void) Ale_ShowAlert (Ale_SUCCESS,Txt_The_new_web_address_is_X, NewWWW); + /***** Country destructor *****/ + Cty_CountryDestructor (&Cty); + /***** Show the form again *****/ Cty_EditCountries (); } @@ -1966,11 +1977,11 @@ static void Cty_PutFormToCreateCountry (void) extern const char *Txt_STR_LANG_NAME[1 + Lan_NUM_LANGUAGES]; extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES]; extern const char *Txt_Create_country; - struct Country *Cty; + struct Country *Cty = NULL; Lan_Language_t Lan; - /***** Country data *****/ - Cty = &Gbl.Ctys.EditingCty; + /***** Country constructoor *****/ + Cty_CountryConstructor (&Cty); /***** Start form *****/ Frm_StartForm (ActNewCty); @@ -2061,6 +2072,9 @@ static void Cty_PutFormToCreateCountry (void) /***** End form *****/ Frm_EndForm (); + + /***** Country destructor *****/ + Cty_CountryDestructor (&Cty); } /*****************************************************************************/ @@ -2120,12 +2134,13 @@ void Cty_RecFormNewCountry (void) extern const char *Txt_The_country_X_already_exists; extern const char *Txt_You_must_specify_the_name_of_the_new_country_in_all_languages; char ParamName[32]; - struct Country *Cty; + struct Country *Cty = NULL; bool CreateCountry = true; Lan_Language_t Lan; unsigned i; - Cty = &Gbl.Ctys.EditingCty; + /***** Country constructoor *****/ + Cty_CountryConstructor (&Cty); /***** Get parameters from form *****/ /* Get numeric country code */ @@ -2205,6 +2220,9 @@ void Cty_RecFormNewCountry (void) if (CreateCountry) Cty_CreateCountry (Cty); // Add new country to database + /***** Country destructor *****/ + Cty_CountryDestructor (&Cty); + /***** Show the form again *****/ Cty_EditCountries (); } @@ -2424,3 +2442,38 @@ void Cty_ListCtysFound (MYSQL_RES **mysql_res,unsigned NumCtys) /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (mysql_res); } + +/*****************************************************************************/ +/*********************** Country constructor/destructor **********************/ +/*****************************************************************************/ +// *Cty must be null + +static void Cty_CountryConstructor (struct Country **Cty) + { + Lan_Language_t Lan; + + /***** *Cty must be NULL *****/ + if (*Cty == NULL) + Lay_ShowErrorAndExit ("Error trying to initialyze country."); + + /***** Allocate memory for country *****/ + if ((*Cty = (struct Country *) malloc (sizeof (struct Country))) == NULL) + Lay_ShowErrorAndExit ("Error allocating memory for country."); + + /***** Reset country *****/ + (*Cty)->CtyCod = -1L; + for (Lan = (Lan_Language_t) 1; + Lan <= Lan_NUM_LANGUAGES; + Lan++) + (*Cty)->Name[Lan][0] = '\0'; + } + +static void Cty_CountryDestructor (struct Country **Cty) + { + /***** Free memory used for country *****/ + if (*Cty != NULL) + { + free ((void *) *Cty); + *Cty = NULL; + } + } diff --git a/swad_global.c b/swad_global.c index 057f36bb..870aa0e5 100644 --- a/swad_global.c +++ b/swad_global.c @@ -85,7 +85,6 @@ void Gbl_InitializeGlobals (void) extern const char *Ico_IconSetId[Ico_NUM_ICON_SETS]; extern const unsigned Txt_Current_CGI_SWAD_Language; Rol_Role_t Role; - Lan_Language_t Lan; Gbl.Layout.WritingHTMLStart = Gbl.Layout.HTMLStartWritten = @@ -248,11 +247,6 @@ void Gbl_InitializeGlobals (void) Gbl.Hierarchy.Sys.Ctys.Num = 0; Gbl.Hierarchy.Sys.Ctys.Lst = NULL; Gbl.Hierarchy.Sys.Ctys.SelectedOrder = Cty_ORDER_DEFAULT; - Gbl.Ctys.EditingCty.CtyCod = -1L; - for (Lan = (Lan_Language_t) 1; - Lan <= Lan_NUM_LANGUAGES; - Lan++) - Gbl.Ctys.EditingCty.Name[Lan][0] = '\0'; Gbl.Hierarchy.Ins.Ctrs.Num = 0; Gbl.Hierarchy.Ins.Ctrs.Lst = NULL; diff --git a/swad_global.h b/swad_global.h index 45aa97f2..ea4ee682 100644 --- a/swad_global.h +++ b/swad_global.h @@ -205,8 +205,15 @@ struct Globals } HTMLOutput; struct { - struct Country EditingCty; - } Ctys; + Hie_Level_t Level; // Current level in the hierarchy: system, country, institution, centre, degree or course + long Cod; // Code of the current country, institution, centre, degree or course + struct System Sys; // Top level of the hierarchy (system or platform) + struct Country Cty; // Current country + struct Instit Ins; // Current institution + struct Centre Ctr; // Current centre + struct Degree Deg; // Current degree + struct Course Crs; // Current course. Aditional info about course is stored in Gbl.Crs. + } Hierarchy; struct { struct Instit EditingIns; @@ -445,17 +452,6 @@ struct Globals Hie_Level_t Default; unsigned Allowed; } Scope; - struct - { - Hie_Level_t Level; // Current level in the hierarchy: system, country, institution, centre, degree or course - long Cod; // Code of the current country, institution, centre, degree or course - struct System Sys; // Top level of the hierarchy (system or platform) - struct Country Cty; // Current country - struct Instit Ins; // Current institution - struct Centre Ctr; // Current centre - struct Degree Deg; // Current degree - struct Course Crs; // Current course. Aditional info about course is stored in Gbl.Crs. - } Hierarchy; struct { char PathPriv[PATH_MAX + 1]; // Absolute path to the private directory of the course diff --git a/swad_system.h b/swad_system.h index 69e3adb3..c1d376bd 100644 --- a/swad_system.h +++ b/swad_system.h @@ -38,7 +38,6 @@ struct System unsigned Num; // Number of countries struct Country *Lst; // List of countries Cty_Order_t SelectedOrder; - // struct Country EditingCty; } Ctys; };