diff --git a/swad_action.c b/swad_action.c index 021674d5..2563608a 100644 --- a/swad_action.c +++ b/swad_action.c @@ -1695,10 +1695,10 @@ struct Act_Actions Act_Actions[Act_NUM_ACTIONS] = // Actions not in menu: /* ActEdiCty */{ 863,-1,TabUnk,ActSeeCty , 0, 0, 0, 0, 0, 0,0x200,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Cty_EditCountries ,NULL}, - /* ActNewCty */{ 864,-1,TabUnk,ActSeeCty , 0, 0, 0, 0, 0, 0,0x200,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Cty_RecFormNewCountry ,NULL}, - /* ActRemCty */{ 893,-1,TabUnk,ActSeeCty , 0, 0, 0, 0, 0, 0,0x200,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Cty_RemoveCountry ,NULL}, - /* ActRenCty */{ 866,-1,TabUnk,ActSeeCty , 0, 0, 0, 0, 0, 0,0x200,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Cty_RenameCountry ,NULL}, - /* ActChgCtyWWW */{1157,-1,TabUnk,ActSeeCty , 0, 0, 0, 0, 0, 0,0x200,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Cty_ChangeCtyWWW ,NULL}, + /* ActNewCty */{ 864,-1,TabUnk,ActSeeCty , 0, 0, 0, 0, 0, 0,0x200,Act_CONT_NORM,Act_BRW_1ST_TAB,Cty_RecFormNewCountry ,Cty_ContEditAfterChgCty ,NULL}, + /* ActRemCty */{ 893,-1,TabUnk,ActSeeCty , 0, 0, 0, 0, 0, 0,0x200,Act_CONT_NORM,Act_BRW_1ST_TAB,Cty_RemoveCountry ,Cty_ContEditAfterChgCty ,NULL}, + /* ActRenCty */{ 866,-1,TabUnk,ActSeeCty , 0, 0, 0, 0, 0, 0,0x200,Act_CONT_NORM,Act_BRW_1ST_TAB,Cty_RenameCountry ,Cty_ContEditAfterChgCty ,NULL}, + /* ActChgCtyWWW */{1157,-1,TabUnk,ActSeeCty , 0, 0, 0, 0, 0, 0,0x200,Act_CONT_NORM,Act_BRW_1ST_TAB,Cty_ChangeCtyWWW ,Cty_ContEditAfterChgCty ,NULL}, /* ActReqRemOldCrs */{1109,-1,TabUnk,ActSeePen , 0, 0, 0, 0, 0, 0,0x200,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Crs_AskRemoveOldCrss ,NULL}, /* ActRemOldCrs */{1110,-1,TabUnk,ActSeePen , 0, 0, 0, 0, 0, 0,0x200,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Crs_RemoveOldCrss ,NULL}, diff --git a/swad_changelog.h b/swad_changelog.h index bc878451..2a3adf68 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -464,11 +464,11 @@ En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 18.101.5 (2019-04-08)" +#define Log_PLATFORM_VERSION "SWAD 18.101.6 (2019-04-08)" #define CSS_FILE "swad18.92.css" #define JS_FILE "swad18.92.js" /* -En country, hacer más funciones a priori al estilo de como está hecha la edición de course + 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) Version 18.101.3: Apr 08, 2019 Code refactoring in edition of degrees. (241924 lines) diff --git a/swad_country.c b/swad_country.c index a4b655ad..8ab6ec3e 100644 --- a/swad_country.c +++ b/swad_country.c @@ -63,6 +63,8 @@ extern struct Globals Gbl; /***************************** Private variables *****************************/ /*****************************************************************************/ +static struct Country *Cty_EditingCty = NULL; // Static variable to keep the country beeing edited + /*****************************************************************************/ /***************************** Private prototypes ****************************/ /*****************************************************************************/ @@ -82,6 +84,7 @@ static void Cty_PutIconToEditCountries (void); static unsigned Cty_GetNumUsrsWhoClaimToBelongToCty (long CtyCod); static void Cty_GetParamCtyOrder (void); +static void Cty_EditCountriesInternal (void); static void Cty_PutIconsEditingCountries (void); static void Cty_PutIconToViewCountries (void); @@ -96,12 +99,15 @@ static bool Cty_CheckIfAlpha2CountryCodeExists (const char Alpha2[2 + 1]); static bool Cty_CheckIfCountryNameExists (Lan_Language_t Language,const char *Name,long CtyCod); static void Cty_UpdateCtyNameDB (long CtyCod,const char *FieldName,const char *NewCtyName); +static void Cty_ShowAlertAndButtonToGoToCty (void); +static void Cty_PutParamGoToCty (void); + static void Cty_PutFormToCreateCountry (void); static void Cty_PutHeadCountriesForEdition (void); -static void Cty_CreateCountry (struct Country *Cty); +static void Cty_CreateCountry (void); -static void Cty_CountryConstructor (struct Country **Cty); -static void Cty_CountryDestructor (struct Country **Cty); +static void Cty_EditingCountryConstructor (void); +static void Cty_EditingCountryDestructor (void); /*****************************************************************************/ /***************** List countries with pending institutions ******************/ @@ -953,6 +959,18 @@ static void Cty_GetParamCtyOrder (void) /*****************************************************************************/ void Cty_EditCountries (void) + { + /***** Country constructor *****/ + Cty_EditingCountryConstructor (); + + /***** Edit countries *****/ + Cty_EditCountriesInternal (); + + /***** Country destructor *****/ + Cty_EditingCountryDestructor (); + } + +static void Cty_EditCountriesInternal (void) { extern const char *Hlp_SYSTEM_Countries; extern const char *Txt_Countries; @@ -1731,39 +1749,40 @@ void Cty_RemoveCountry (void) { extern const char *Txt_You_can_not_remove_a_country_with_institutions_or_users; extern const char *Txt_Country_X_removed; - struct Country Cty; + + /***** Country constructor *****/ + Cty_EditingCountryConstructor (); /***** Get country code *****/ - Cty.CtyCod = Cty_GetAndCheckParamOtherCtyCod (0); + Cty_EditingCty->CtyCod = Cty_GetAndCheckParamOtherCtyCod (0); /***** Get data of the country from database *****/ - Cty_GetDataOfCountryByCod (&Cty,Cty_GET_EXTRA_DATA); + Cty_GetDataOfCountryByCod (Cty_EditingCty,Cty_GET_EXTRA_DATA); /***** Check if this country has users *****/ - if (Cty.Inss.Num || - Cty.NumUsrsWhoClaimToBelongToCty || - Cty.NumUsrs) // Country has institutions or users ==> don't remove - Ale_ShowAlert (Ale_WARNING,Txt_You_can_not_remove_a_country_with_institutions_or_users); + if (Cty_EditingCty->Inss.Num || + Cty_EditingCty->NumUsrsWhoClaimToBelongToCty || + Cty_EditingCty->NumUsrs) // Country has institutions or users ==> don't remove + Ale_CreateAlert (Ale_WARNING,NULL, + Txt_You_can_not_remove_a_country_with_institutions_or_users); else // Country has no users ==> remove it { /***** Remove surveys of the country *****/ - Svy_RemoveSurveys (Hie_CTY,Cty.CtyCod); + Svy_RemoveSurveys (Hie_CTY,Cty_EditingCty->CtyCod); /***** Remove country *****/ DB_QueryDELETE ("can not remove a country", "DELETE FROM countries WHERE CtyCod='%03ld'", - Cty.CtyCod); + Cty_EditingCty->CtyCod); /***** Flush cache *****/ Cty_FlushCacheCountryName (); /***** Write message to show the change made *****/ - Ale_ShowAlert (Ale_SUCCESS,Txt_Country_X_removed, - Cty.Name[Gbl.Prefs.Language]); + Ale_CreateAlert (Ale_SUCCESS,NULL, + Txt_Country_X_removed, + Cty_EditingCty->Name[Gbl.Prefs.Language]); } - - /***** Show the form again *****/ - Cty_EditCountries (); } /*****************************************************************************/ @@ -1777,16 +1796,15 @@ 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 = NULL; char NewCtyName[Cty_MAX_BYTES_NAME + 1]; Lan_Language_t Language; char FieldName[4 + 1 + 2 + 1]; // Example: "Name_en" /***** Country constructor *****/ - Cty_CountryConstructor (&Cty); + Cty_EditingCountryConstructor (); /***** Get the code of the country *****/ - Cty->CtyCod = Cty_GetAndCheckParamOtherCtyCod (0); + Cty_EditingCty->CtyCod = Cty_GetAndCheckParamOtherCtyCod (0); /***** Get the lenguage *****/ Language = Lan_GetParamLanguage (); @@ -1795,49 +1813,47 @@ void Cty_RenameCountry (void) Par_GetParToText ("Name",NewCtyName,Cty_MAX_BYTES_NAME); /***** Get from the database the data of the country *****/ - Cty_GetDataOfCountryByCod (Cty,Cty_GET_EXTRA_DATA); + Cty_GetDataOfCountryByCod (Cty_EditingCty,Cty_GET_EXTRA_DATA); /***** Check if new name is empty *****/ if (!NewCtyName[0]) - Ale_ShowAlert (Ale_WARNING,Txt_You_can_not_leave_the_name_of_the_country_X_empty, - Cty->Name[Language]); + Ale_CreateAlert (Ale_WARNING,NULL, + Txt_You_can_not_leave_the_name_of_the_country_X_empty, + Cty_EditingCty->Name[Language]); else { /***** Check if old and new names are the same (this happens when return is pressed without changes) *****/ - if (strcmp (Cty->Name[Language],NewCtyName)) // Different names + if (strcmp (Cty_EditingCty->Name[Language],NewCtyName)) // Different names { /***** If country was in database... *****/ - if (Cty_CheckIfCountryNameExists (Language,NewCtyName,Cty->CtyCod)) - Ale_ShowAlert (Ale_WARNING,Txt_The_country_X_already_exists, - NewCtyName); + if (Cty_CheckIfCountryNameExists (Language,NewCtyName,Cty_EditingCty->CtyCod)) + Ale_CreateAlert (Ale_WARNING,NULL, + Txt_The_country_X_already_exists, + NewCtyName); else { /* Update the table changing old name by new name */ snprintf (FieldName,sizeof (FieldName), "Name_%s", Lan_STR_LANG_ID[Language]); - Cty_UpdateCtyNameDB (Cty->CtyCod,FieldName,NewCtyName); + Cty_UpdateCtyNameDB (Cty_EditingCty->CtyCod,FieldName,NewCtyName); /* Write message to show the change made */ - Ale_ShowAlert (Ale_SUCCESS,Txt_The_country_X_has_been_renamed_as_Y, - Cty->Name[Language],NewCtyName); + Ale_CreateAlert (Ale_SUCCESS,NULL, + Txt_The_country_X_has_been_renamed_as_Y, + Cty_EditingCty->Name[Language],NewCtyName); /* Update country name */ - Str_Copy (Cty->Name[Language],NewCtyName, + Str_Copy (Cty_EditingCty->Name[Language],NewCtyName, Cty_MAX_BYTES_NAME); } } else // The same name - Ale_ShowAlert (Ale_INFO,Txt_The_name_of_the_country_X_has_not_changed, - Cty->Name[Language]); + Ale_CreateAlert (Ale_INFO,NULL, + Txt_The_name_of_the_country_X_has_not_changed, + Cty_EditingCty->Name[Language]); } - - /***** Country destructor *****/ - Cty_CountryDestructor (&Cty); - - /***** Show the form again *****/ - Cty_EditCountries (); } /*****************************************************************************/ @@ -1907,15 +1923,14 @@ 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 = NULL; char NewWWW[Cns_MAX_BYTES_WWW + 1]; Lan_Language_t Language; /***** Country constructor *****/ - Cty_CountryConstructor (&Cty); + Cty_EditingCountryConstructor (); /***** Get the code of the country *****/ - Cty->CtyCod = Cty_GetAndCheckParamOtherCtyCod (0); + Cty_EditingCty->CtyCod = Cty_GetAndCheckParamOtherCtyCod (0); /***** Get the lenguage *****/ Language = Lan_GetParamLanguage (); @@ -1924,25 +1939,20 @@ void Cty_ChangeCtyWWW (void) Par_GetParToText ("WWW",NewWWW,Cns_MAX_BYTES_WWW); /***** Get from the database the data of the country *****/ - Cty_GetDataOfCountryByCod (Cty,Cty_GET_EXTRA_DATA); + Cty_GetDataOfCountryByCod (Cty_EditingCty,Cty_GET_EXTRA_DATA); /***** Update the table changing old WWW by new WWW *****/ DB_QueryUPDATE ("can not update the web of a country", "UPDATE countries SET WWW_%s='%s'" " WHERE CtyCod='%03ld'", - Lan_STR_LANG_ID[Language],NewWWW,Cty->CtyCod); - Str_Copy (Cty->WWW[Language],NewWWW, + Lan_STR_LANG_ID[Language],NewWWW,Cty_EditingCty->CtyCod); + Str_Copy (Cty_EditingCty->WWW[Language],NewWWW, Cns_MAX_BYTES_WWW); /***** Write message to show the change made *****/ - Ale_ShowAlert (Ale_SUCCESS,Txt_The_new_web_address_is_X, - NewWWW); - - /***** Country destructor *****/ - Cty_CountryDestructor (&Cty); - - /***** Show the form again *****/ - Cty_EditCountries (); + Ale_CreateAlert (Ale_SUCCESS,NULL, + Txt_The_new_web_address_is_X, + NewWWW); } /*****************************************************************************/ @@ -1967,6 +1977,48 @@ void Cty_ChangeCtyMapAttribution (void) Cty_ShowConfiguration (); } +/*****************************************************************************/ +/********* Show alerts after changing a country and continue editing *********/ +/*****************************************************************************/ + +void Cty_ContEditAfterChgCty (void) + { + /***** Write message to show the change made + and put button to go to country changed *****/ + Cty_ShowAlertAndButtonToGoToCty (); + + /***** Show the form again *****/ + Cty_EditCountriesInternal (); + + /***** Country destructor *****/ + Cty_EditingCountryDestructor (); + } + +/*****************************************************************************/ +/***************** Write message to show the change made *******************/ +/***************** and put button to go to country changed *******************/ +/*****************************************************************************/ + +static void Cty_ShowAlertAndButtonToGoToCty (void) + { + // If the country beeing edited is different to the current one... + if (Cty_EditingCty->CtyCod != Gbl.Hierarchy.Cty.CtyCod) + { + /***** Alert with button to go to couuntry *****/ + Ale_ShowLastAlertAndButton (ActSeeIns,NULL,NULL,Cty_PutParamGoToCty, + Btn_CONFIRM_BUTTON,Gbl.Title); + } + else + /***** Alert *****/ + Ale_ShowAlerts (NULL); + } + +static void Cty_PutParamGoToCty (void) + { + /***** Put parameter *****/ + Cty_PutParamCtyCod (Cty_EditingCty->CtyCod); + } + /*****************************************************************************/ /********************* Put a form to create a new country ********************/ /*****************************************************************************/ @@ -1977,12 +2029,8 @@ 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 = NULL; Lan_Language_t Lan; - /***** Country constructoor *****/ - Cty_CountryConstructor (&Cty); - /***** Start form *****/ Frm_StartForm (ActNewCty); @@ -2003,8 +2051,8 @@ static void Cty_PutFormToCreateCountry (void) "CtyCod > 0) - fprintf (Gbl.F.Out,"%03ld",Cty->CtyCod); + if (Cty_EditingCty->CtyCod > 0) + fprintf (Gbl.F.Out,"%03ld",Cty_EditingCty->CtyCod); fprintf (Gbl.F.Out,"\" required=\"required\" />" ""); @@ -2014,7 +2062,7 @@ static void Cty_PutFormToCreateCountry (void) " size=\"2\" maxlength=\"2\" value=\"%s\"" " required=\"required\" />" "", - 1 + Lan_NUM_LANGUAGES,Cty->Alpha2); + 1 + Lan_NUM_LANGUAGES,Cty_EditingCty->Alpha2); fprintf (Gbl.F.Out,"