diff --git a/swad_changelog.h b/swad_changelog.h index 0a5013a32..5bba0100d 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -464,12 +464,11 @@ En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 18.96 (2019-04-03)" +#define Log_PLATFORM_VERSION "SWAD 18.97 (2019-04-06)" #define CSS_FILE "swad18.92.css" #define JS_FILE "swad18.92.js" /* -TODO: Fix: Campos tienen que aparecer rellenos en formulario de creación tras editar una institución existente - + Version 18.97: Apr 06, 2019 Code refactoring in edition of institutions. (241699 lines) Version 18.96: Apr 03, 2019 Code refactoring in edition of institutions. Fixed bug in creation of country. (241724 lines) Version 18.95.1: Apr 03, 2019 Code refactoring in edition of countries. (241607 lines) diff --git a/swad_institution.c b/swad_institution.c index 41811a345..96e6dad34 100644 --- a/swad_institution.c +++ b/swad_institution.c @@ -63,6 +63,8 @@ extern struct Globals Gbl; /***************************** Private variables *****************************/ /*****************************************************************************/ +static struct Instit *Ins_EditingIns = NULL; // Static variable to keep institution beeing edited + /*****************************************************************************/ /***************************** Private prototypes ****************************/ /*****************************************************************************/ @@ -79,13 +81,15 @@ static void Ins_ListOneInstitutionForSeeing (struct Instit *Ins,unsigned NumIns) static void Ins_PutHeadInstitutionsForSeeing (bool OrderSelectable); static void Ins_GetParamInsOrder (void); +static void Ins_EditInstitutionsInternal (void); + static void Ins_PutIconsEditingInstitutions (void); static void Ins_PutIconToViewInstitutions (void); static void Ins_GetShrtNameAndCtyOfInstitution (struct Instit *Ins, char CtyName[Hie_MAX_BYTES_FULL_NAME + 1]); -static void Ins_ListInstitutionsForEdition (struct Instit *Ins); +static void Ins_ListInstitutionsForEdition (void); static bool Ins_CheckIfICanEdit (struct Instit *Ins); static Ins_StatusTxt_t Ins_GetStatusTxtFromStatusBits (Ins_Status_t Status); static Ins_Status_t Ins_GetStatusBitsFromStatusTxt (Ins_StatusTxt_t StatusTxt); @@ -102,20 +106,16 @@ static void Ins_UpdateInsNameDB (long InsCod,const char *FieldName,const char *N static void Ins_UpdateInsCtyDB (long InsCod,long CtyCod); static void Ins_UpdateInsWWWDB (long InsCod,const char NewWWW[Cns_MAX_BYTES_WWW + 1]); -static void Ins_ShowAlertAndButtonToGoToIns (long InsCod); +static void Ins_ShowAlertAndButtonToGoToIns (void); static void Ins_PutParamGoToIns (void); -static void Ins_PutFormToCreateInstitution (struct Instit *Ins); +static void Ins_PutFormToCreateInstitution (void); static void Ins_PutHeadInstitutionsForEdition (void); -static void Ins_RecFormRequestOrCreateIns (struct Instit *Ins,unsigned Status); -static void Ins_CreateInstitution (struct Instit *Ins,unsigned Status); +static void Ins_RecFormRequestOrCreateIns (unsigned Status); +static void Ins_CreateInstitution (unsigned Status); -static void Ins_InstitutionConstructor (struct Instit **Ins); -static void Ins_InstitutionDestructor (struct Instit **Ins); - -static void Ins_SetEditingInsCod (long InsCod); -static long Ins_GetEditingInsCod (void); -static long *Ins_GetPtrToEditingInsCod (void); +static void Ins_EditingInstitutionConstructor (); +static void Ins_EditingInstitutionDestructor (); /*****************************************************************************/ /***************** List institutions with pending centres ********************/ @@ -939,10 +939,21 @@ static void Ins_GetParamInsOrder (void) /*****************************************************************************/ void Ins_EditInstitutions (void) + { + /***** Institution constructor *****/ + Ins_EditingInstitutionConstructor (); + + /***** Edit institutions *****/ + Ins_EditInstitutionsInternal (); + + /***** Institution destructor *****/ + Ins_EditingInstitutionDestructor (); + } + +static void Ins_EditInstitutionsInternal (void) { extern const char *Hlp_COUNTRY_Institutions; extern const char *Txt_Institutions_of_COUNTRY_X; - struct Instit *Ins = NULL; /***** Get list of institutions *****/ Ins_GetListInstitutions (Gbl.Hierarchy.Cty.CtyCod,Ins_GET_EXTRA_DATA); @@ -957,18 +968,12 @@ void Ins_EditInstitutions (void) Box_StartBox (NULL,Gbl.Title,Ins_PutIconsEditingInstitutions, Hlp_COUNTRY_Institutions,Box_NOT_CLOSABLE); - /***** Institution constructor *****/ - Ins_InstitutionConstructor (&Ins); - /***** Put a form to create a new institution *****/ - Ins_PutFormToCreateInstitution (Ins); + Ins_PutFormToCreateInstitution (); /***** Forms to edit current institutions *****/ if (Gbl.Hierarchy.Cty.Inss.Num) - Ins_ListInstitutionsForEdition (Ins); - - /***** Institution destructor *****/ - Ins_InstitutionDestructor (&Ins); + Ins_ListInstitutionsForEdition (); /***** End box *****/ Box_EndBox (); @@ -1452,10 +1457,11 @@ void Ins_WriteSelectorOfInstitution (void) /************************* List all the institutions *************************/ /*****************************************************************************/ -static void Ins_ListInstitutionsForEdition (struct Instit *Ins) +static void Ins_ListInstitutionsForEdition (void) { extern const char *Txt_INSTITUTION_STATUS[Ins_NUM_STATUS_TXT]; unsigned NumIns; + struct Instit *Ins; char WWW[Cns_MAX_BYTES_WWW + 1]; struct UsrData UsrDat; bool ICanEdit; @@ -1732,45 +1738,47 @@ void Ins_RemoveInstitution (void) { extern const char *Txt_To_remove_an_institution_you_must_first_remove_all_centres_and_users_in_the_institution; extern const char *Txt_Institution_X_removed; - struct Instit Ins; char PathIns[PATH_MAX + 1]; + /***** Institution constructor *****/ + Ins_EditingInstitutionConstructor (); + /***** Get institution code *****/ - Ins.InsCod = Ins_GetAndCheckParamOtherInsCod (1); + Ins_EditingIns->InsCod = Ins_GetAndCheckParamOtherInsCod (1); /***** Get data of the institution from database *****/ - Ins_GetDataOfInstitutionByCod (&Ins,Ins_GET_EXTRA_DATA); + Ins_GetDataOfInstitutionByCod (Ins_EditingIns,Ins_GET_EXTRA_DATA); /***** Check if this institution has users *****/ - if (!Ins_CheckIfICanEdit (&Ins)) + if (!Ins_CheckIfICanEdit (Ins_EditingIns)) Lay_NoPermissionExit (); - else if (Ins.Ctrs.Num || - Ins.NumUsrsWhoClaimToBelongToIns || - Ins.NumUsrs) // Institution has centres or users ==> don't remove + else if (Ins_EditingIns->Ctrs.Num || + Ins_EditingIns->NumUsrsWhoClaimToBelongToIns || + Ins_EditingIns->NumUsrs) // Institution has centres or users ==> don't remove Ale_ShowAlert (Ale_WARNING,Txt_To_remove_an_institution_you_must_first_remove_all_centres_and_users_in_the_institution); else // Institution has no users ==> remove it { /***** Remove all the threads and posts in forums of the institution *****/ - For_RemoveForums (Hie_INS,Ins.InsCod); + For_RemoveForums (Hie_INS,Ins_EditingIns->InsCod); /***** Remove surveys of the institution *****/ - Svy_RemoveSurveys (Hie_INS,Ins.InsCod); + Svy_RemoveSurveys (Hie_INS,Ins_EditingIns->InsCod); /***** Remove information related to files in institution *****/ - Brw_RemoveInsFilesFromDB (Ins.InsCod); + Brw_RemoveInsFilesFromDB (Ins_EditingIns->InsCod); /***** Remove directories of the institution *****/ snprintf (PathIns,sizeof (PathIns), "%s/%02u/%u", Cfg_PATH_INS_PUBLIC, - (unsigned) (Ins.InsCod % 100), - (unsigned) Ins.InsCod); + (unsigned) (Ins_EditingIns->InsCod % 100), + (unsigned) Ins_EditingIns->InsCod); Fil_RemoveTree (PathIns); /***** Remove institution *****/ DB_QueryDELETE ("can not remove an institution", "DELETE FROM institutions WHERE InsCod=%ld", - Ins.InsCod); + Ins_EditingIns->InsCod); /***** Flush caches *****/ Ins_FlushCacheShortNameOfInstitution (); @@ -1778,66 +1786,70 @@ void Ins_RemoveInstitution (void) /***** Write message to show the change made *****/ Ale_ShowAlert (Ale_SUCCESS,Txt_Institution_X_removed, - Ins.FullName); + Ins_EditingIns->FullName); } /***** Show the form again *****/ - Ins_EditInstitutions (); + Ins_EditInstitutionsInternal (); + + /***** Institution destructor *****/ + Ins_EditingInstitutionDestructor (); } /*****************************************************************************/ -/***************** Change the short name of an institution *******************/ +/***************** Change the name of an institution *******************/ /*****************************************************************************/ void Ins_RenameInsShort (void) { - struct Instit *Ins = NULL; - /***** Institution constructor *****/ - Ins_InstitutionConstructor (&Ins); + Ins_EditingInstitutionConstructor (); /***** Rename institution *****/ - Ins->InsCod = Ins_GetAndCheckParamOtherInsCod (1); - Ins_SetEditingInsCod (Ins->InsCod); // It will be used later - Ins_RenameInstitution (Ins,Cns_SHRT_NAME); + Ins_EditingIns->InsCod = Ins_GetAndCheckParamOtherInsCod (1); + Ins_RenameInstitution (Ins_EditingIns,Cns_SHRT_NAME); + } + +void Ins_RenameInsFull (void) + { + /***** Institution constructor *****/ + Ins_EditingInstitutionConstructor (); + + /***** Rename institution *****/ + Ins_EditingIns->InsCod = Ins_GetAndCheckParamOtherInsCod (1); + Ins_RenameInstitution (Ins_EditingIns,Cns_FULL_NAME); + } + +void Ins_ContEditAfterChgIns (void) + { + /***** Write message to show the change made + and put button to go to institution changed *****/ + Ins_ShowAlertAndButtonToGoToIns (); + + /***** Show the form again *****/ + Ins_EditInstitutionsInternal (); /***** Institution destructor *****/ - Ins_InstitutionDestructor (&Ins); + Ins_EditingInstitutionDestructor (); } +/*****************************************************************************/ +/************ Change the name of an institution in configuration *************/ +/*****************************************************************************/ + void Ins_RenameInsShortInConfig (void) { struct Instit *Ins = NULL; /***** Institution constructor *****/ - Ins_InstitutionConstructor (&Ins); + Ins_EditingInstitutionConstructor (&Ins); /***** Rename institution *****/ Ins->InsCod = Gbl.Hierarchy.Ins.InsCod; Ins_RenameInstitution (Ins,Cns_SHRT_NAME); /***** Institution destructor *****/ - Ins_InstitutionDestructor (&Ins); - } - -/*****************************************************************************/ -/***************** Change the full name of an institution ********************/ -/*****************************************************************************/ - -void Ins_RenameInsFull (void) - { - struct Instit *Ins = NULL; - - /***** Institution constructor *****/ - Ins_InstitutionConstructor (&Ins); - - /***** Rename institution *****/ - Ins->InsCod = Ins_GetAndCheckParamOtherInsCod (1); - Ins_SetEditingInsCod (Ins->InsCod); // It will be used later - Ins_RenameInstitution (Ins,Cns_FULL_NAME); - - /***** Institution destructor *****/ - Ins_InstitutionDestructor (&Ins); + Ins_EditingInstitutionDestructor (&Ins); } void Ins_RenameInsFullInConfig (void) @@ -1845,14 +1857,14 @@ void Ins_RenameInsFullInConfig (void) struct Instit *Ins = NULL; /***** Institution constructor *****/ - Ins_InstitutionConstructor (&Ins); + Ins_EditingInstitutionConstructor (&Ins); /***** Rename institution *****/ Ins->InsCod = Gbl.Hierarchy.Ins.InsCod; Ins_RenameInstitution (Ins,Cns_FULL_NAME); /***** Institution destructor *****/ - Ins_InstitutionDestructor (&Ins); + Ins_EditingInstitutionDestructor (&Ins); } /*****************************************************************************/ @@ -2044,28 +2056,27 @@ void Ins_ChangeInsWWW (void) { extern const char *Txt_The_new_web_address_is_X; extern const char *Txt_You_can_not_leave_the_web_address_empty; - struct Instit *Ins = NULL; char NewWWW[Cns_MAX_BYTES_WWW + 1]; /***** Institution constructor *****/ - Ins_InstitutionConstructor (&Ins); + Ins_EditingInstitutionConstructor (); /***** Get parameters from form *****/ /* Get the code of the institution */ - Ins->InsCod = Ins_GetAndCheckParamOtherInsCod (1); + Ins_EditingIns->InsCod = Ins_GetAndCheckParamOtherInsCod (1); /* Get the new WWW for the institution */ Par_GetParToText ("WWW",NewWWW,Cns_MAX_BYTES_WWW); /***** Get data of institution *****/ - Ins_GetDataOfInstitutionByCod (Ins,Ins_GET_BASIC_DATA); + Ins_GetDataOfInstitutionByCod (Ins_EditingIns,Ins_GET_BASIC_DATA); /***** Check if new WWW is empty *****/ if (NewWWW[0]) { /***** Update database changing old WWW by new WWW *****/ - Ins_UpdateInsWWWDB (Ins->InsCod,NewWWW); - Str_Copy (Ins->WWW,NewWWW, + Ins_UpdateInsWWWDB (Ins_EditingIns->InsCod,NewWWW); + Str_Copy (Ins_EditingIns->WWW,NewWWW, Cns_MAX_BYTES_WWW); /***** Write message to show the change made @@ -2073,16 +2084,16 @@ void Ins_ChangeInsWWW (void) Ale_CreateAlert (Ale_SUCCESS,NULL, Txt_The_new_web_address_is_X, NewWWW); - Ins_ShowAlertAndButtonToGoToIns (Ins->InsCod); + Ins_ShowAlertAndButtonToGoToIns (); } else Ale_ShowAlert (Ale_WARNING,Txt_You_can_not_leave_the_web_address_empty); - /***** Institution destructor *****/ - Ins_InstitutionDestructor (&Ins); - /***** Show the form again *****/ - Ins_EditInstitutions (); + Ins_EditInstitutionsInternal (); + + /***** Institution destructor *****/ + Ins_EditingInstitutionDestructor (); } void Ins_ChangeInsWWWInConfig (void) @@ -2133,16 +2144,15 @@ static void Ins_UpdateInsWWWDB (long InsCod,const char NewWWW[Cns_MAX_BYTES_WWW void Ins_ChangeInsStatus (void) { extern const char *Txt_The_status_of_the_institution_X_has_changed; - struct Instit *Ins = NULL; Ins_Status_t Status; Ins_StatusTxt_t StatusTxt; /***** Institution constructor *****/ - Ins_InstitutionConstructor (&Ins); + Ins_EditingInstitutionConstructor (); /***** Get parameters from form *****/ /* Get institution code */ - Ins->InsCod = Ins_GetAndCheckParamOtherInsCod (1); + Ins_EditingIns->InsCod = Ins_GetAndCheckParamOtherInsCod (1); /* Get parameter with status */ Status = (Ins_Status_t) @@ -2156,40 +2166,26 @@ void Ins_ChangeInsStatus (void) Status = Ins_GetStatusBitsFromStatusTxt (StatusTxt); // New status /***** Get data of institution *****/ - Ins_GetDataOfInstitutionByCod (Ins,Ins_GET_BASIC_DATA); + Ins_GetDataOfInstitutionByCod (Ins_EditingIns,Ins_GET_BASIC_DATA); /***** Update status in table of institutions *****/ DB_QueryUPDATE ("can not update the status of an institution", "UPDATE institutions SET Status=%u WHERE InsCod=%ld", - (unsigned) Status,Ins->InsCod); - Ins->Status = Status; + (unsigned) Status,Ins_EditingIns->InsCod); + Ins_EditingIns->Status = Status; /***** Write message to show the change made and put button to go to institution changed *****/ Ale_CreateAlert (Ale_SUCCESS,NULL, Txt_The_status_of_the_institution_X_has_changed, - Ins->ShrtName); - Ins_ShowAlertAndButtonToGoToIns (Ins->InsCod); + Ins_EditingIns->ShrtName); + Ins_ShowAlertAndButtonToGoToIns (); + + /***** Show the form again *****/ + Ins_EditInstitutionsInternal (); /***** Institution destructor *****/ - Ins_InstitutionDestructor (&Ins); - - /***** Show the form again *****/ - Ins_EditInstitutions (); - } - -/*****************************************************************************/ -/*********** Show message of success after changing an institution ***********/ -/*****************************************************************************/ - -void Ins_ContEditAfterChgIns (void) - { - /***** Write message to show the change made - and put button to go to institution changed *****/ - Ins_ShowAlertAndButtonToGoToIns (Ins_GetEditingInsCod ()); - - /***** Show the form again *****/ - Ins_EditInstitutions (); + Ins_EditingInstitutionDestructor (); } /*****************************************************************************/ @@ -2198,13 +2194,12 @@ void Ins_ContEditAfterChgIns (void) /*****************************************************************************/ // Gbl.Hierarchy.Deg is the current degree -static void Ins_ShowAlertAndButtonToGoToIns (long InsCod) +static void Ins_ShowAlertAndButtonToGoToIns (void) { // If the institution beeing edited is different to the current one... - if (InsCod != Gbl.Hierarchy.Ins.InsCod) + if (Ins_EditingIns->InsCod != Gbl.Hierarchy.Ins.InsCod) { /***** Alert with button to go to degree *****/ - Ins_SetEditingInsCod (InsCod); // Parameter to function Ale_ShowLastAlertAndButton (ActSeeCtr,NULL,NULL,Ins_PutParamGoToIns, Btn_CONFIRM_BUTTON,Gbl.Title); } @@ -2215,7 +2210,8 @@ static void Ins_ShowAlertAndButtonToGoToIns (long InsCod) static void Ins_PutParamGoToIns (void) { - Ins_PutParamInsCod (Ins_GetEditingInsCod ()); + /***** Put parameter *****/ + Ins_PutParamInsCod (Ins_EditingIns->InsCod); } /*****************************************************************************/ @@ -2249,7 +2245,7 @@ void Ins_RemoveLogo (void) /****************** Put a form to create a new institution *******************/ /*****************************************************************************/ -static void Ins_PutFormToCreateInstitution (struct Instit *Ins) +static void Ins_PutFormToCreateInstitution (void) { extern const char *Txt_New_institution; extern const char *Txt_Create_institution; @@ -2288,7 +2284,7 @@ static void Ins_PutFormToCreateInstitution (struct Instit *Ins) " class=\"INPUT_SHORT_NAME\"" " required=\"required\" />" "", - Hie_MAX_CHARS_SHRT_NAME,Ins->ShrtName); + Hie_MAX_CHARS_SHRT_NAME,Ins_EditingIns->ShrtName); /***** Institution full name *****/ fprintf (Gbl.F.Out,"