diff --git a/swad_banner.c b/swad_banner.c index 3b2accf9c..ed5db31ec 100644 --- a/swad_banner.c +++ b/swad_banner.c @@ -397,7 +397,7 @@ static void Ban_ListBannersForEdition (struct Ban_Banners *Banners) unsigned NumBan; struct Ban_Banner *Ban; char *Anchor = NULL; - const char *Name[Cns_NUM_SHRT_FULL_NAMES]; + const char *Names[Cns_NUM_SHRT_FULL_NAMES]; /***** Begin table *****/ HTM_TABLE_BeginWidePadding (2); @@ -444,12 +444,12 @@ static void Ban_ListBannersForEdition (struct Ban_Banners *Banners) HTM_TD_End (); /* Banner short name and full name */ - Name[Cns_SHRT_NAME] = Ban->ShrtName; - Name[Cns_FULL_NAME] = Ban->FullName; - Frm_PutShortAndFullNames (ActionRename, - ParCod_Ban,Banners->BanCodToEdit, - Name, - true); // Put form + Names[Cns_SHRT_NAME] = Ban->ShrtName; + Names[Cns_FULL_NAME] = Ban->FullName; + Frm_ExistingShortAndFullNames (ActionRename, + ParCod_Ban,Banners->BanCodToEdit, + Names, + true); // Put form /* Banner image */ HTM_TD_Begin ("class=\"CM\""); @@ -641,8 +641,7 @@ static void Ban_RenameBanner (struct Ban_Banner *Ban, if (Ban_DB_CheckIfBannerNameExists (Cns_ParShrtOrFullName[ShrtOrFullName], NewName,Ban->BanCod)) Ale_CreateAlert (Ale_WARNING,NULL, - Txt_The_banner_X_already_exists, - NewName); + Txt_The_banner_X_already_exists,NewName); else { /* Update the table changing old name by new name */ @@ -657,7 +656,8 @@ static void Ban_RenameBanner (struct Ban_Banner *Ban, else // The same name /* Write warning message */ Ale_CreateAlert (Ale_INFO,NULL, - Txt_The_name_X_has_not_changed,CurrentName[ShrtOrFullName]); + Txt_The_name_X_has_not_changed, + CurrentName[ShrtOrFullName]); } /***** Update name *****/ @@ -774,15 +774,11 @@ void Ban_ContEditAfterChgBan (void) static void Ban_PutFormToCreateBanner (const struct Ban_Banner *Ban) { - extern const char *Cns_ParShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; - extern unsigned Cns_MaxCharsShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; - extern const char *Cns_ClassShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; - const char *Name[Cns_NUM_SHRT_FULL_NAMES] = + const char *Names[Cns_NUM_SHRT_FULL_NAMES] = { [Cns_SHRT_NAME] = Ban->ShrtName, [Cns_FULL_NAME] = Ban->FullName, }; - Cns_ShrtOrFullName_t ShrtOrFullName; /***** Begin form to create *****/ Frm_BeginFormTable (ActNewBan,NULL,NULL,NULL); @@ -804,21 +800,7 @@ static void Ban_PutFormToCreateBanner (const struct Ban_Banner *Ban) HTM_TD_Empty (1); /* Banner short name and full name */ - for (ShrtOrFullName = Cns_SHRT_NAME; - ShrtOrFullName <= Cns_FULL_NAME; - ShrtOrFullName++) - { - HTM_TD_Begin ("class=\"CM\""); - HTM_INPUT_TEXT (Cns_ParShrtOrFullName[ShrtOrFullName], - Cns_MaxCharsShrtOrFullName[ShrtOrFullName], - Name[ShrtOrFullName], - HTM_DONT_SUBMIT_ON_CHANGE, - "class=\"%s INPUT_%s\"" - " required=\"required\"", - Cns_ClassShrtOrFullName[ShrtOrFullName], - The_GetSuffix ()); - HTM_TD_End (); - } + Frm_NewShortAndFullNames (Names); /* Banner image */ HTM_TD_Begin ("class=\"CM\""); diff --git a/swad_building.c b/swad_building.c index 6247ea45a..d71cef270 100644 --- a/swad_building.c +++ b/swad_building.c @@ -390,9 +390,6 @@ void Bld_FreeListBuildings (struct Bld_Buildings *Buildings) static void Bld_ListBuildingsForEdition (const struct Bld_Buildings *Buildings) { - extern const char *Cns_ParShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; - extern unsigned Cns_MaxCharsShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; - extern const char *Cns_ClassShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; static Act_Action_t ActionRename[Cns_NUM_SHRT_FULL_NAMES] = { [Cns_SHRT_NAME] = ActRenBldSho, @@ -401,8 +398,7 @@ static void Bld_ListBuildingsForEdition (const struct Bld_Buildings *Buildings) unsigned NumBld; struct Bld_Building *Building; char *Anchor = NULL; - Cns_ShrtOrFullName_t ShrtOrFullName; - char *Name[Cns_NUM_SHRT_FULL_NAMES]; + const char *Names[Cns_NUM_SHRT_FULL_NAMES]; /***** Begin table *****/ HTM_TABLE_BeginWidePadding (2); @@ -436,25 +432,12 @@ static void Bld_ListBuildingsForEdition (const struct Bld_Buildings *Buildings) HTM_TD_End (); /* Building short name and full name */ - Name[Cns_SHRT_NAME] = Building->ShrtName; - Name[Cns_FULL_NAME] = Building->FullName; - for (ShrtOrFullName = Cns_SHRT_NAME; - ShrtOrFullName <= Cns_FULL_NAME; - ShrtOrFullName++) - { - HTM_TD_Begin ("class=\"LM\""); - Frm_BeginFormAnchor (ActionRename[ShrtOrFullName],Anchor); - ParCod_PutPar (ParCod_Bld,Building->BldCod); - HTM_INPUT_TEXT (Cns_ParShrtOrFullName[ShrtOrFullName], - Cns_MaxCharsShrtOrFullName[ShrtOrFullName], - Name[ShrtOrFullName], - HTM_SUBMIT_ON_CHANGE, - "size=\"10\" class=\"%s INPUT_%s\"", - Cns_ClassShrtOrFullName[ShrtOrFullName], - The_GetSuffix ()); - Frm_EndForm (); - HTM_TD_End (); - } + Names[Cns_SHRT_NAME] = Building->ShrtName; + Names[Cns_FULL_NAME] = Building->FullName; + Frm_ExistingShortAndFullNames (ActionRename, + ParCod_Bld,Building->BldCod, + Names, + true); // Put form /* Building location */ HTM_TD_Begin ("class=\"LM\""); @@ -672,11 +655,7 @@ void Bld_ContEditAfterChgBuilding (void) static void Bld_PutFormToCreateBuilding (void) { - extern const char *Cns_ParShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; - extern unsigned Cns_MaxCharsShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; - extern const char *Cns_ClassShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; - Cns_ShrtOrFullName_t ShrtOrFullName; - char *Name[Cns_NUM_SHRT_FULL_NAMES] = + const char *Names[Cns_NUM_SHRT_FULL_NAMES] = { [Cns_SHRT_NAME] = Bld_EditingBuilding->ShrtName, [Cns_FULL_NAME] = Bld_EditingBuilding->FullName, @@ -699,21 +678,7 @@ static void Bld_PutFormToCreateBuilding (void) HTM_TD_End (); /***** Building short name and full name *****/ - for (ShrtOrFullName = Cns_SHRT_NAME; - ShrtOrFullName <= Cns_FULL_NAME; - ShrtOrFullName++) - { - HTM_TD_Begin ("class=\"LM\""); - HTM_INPUT_TEXT (Cns_ParShrtOrFullName[ShrtOrFullName], - Cns_MaxCharsShrtOrFullName[ShrtOrFullName], - Name[ShrtOrFullName], - HTM_DONT_SUBMIT_ON_CHANGE, - "size=\"10\" class=\"%s INPUT_%s\"" - " required=\"required\"", - Cns_ClassShrtOrFullName[ShrtOrFullName], - The_GetSuffix ()); - HTM_TD_End (); - } + Frm_NewShortAndFullNames (Names); /***** Building location *****/ HTM_TD_Begin ("class=\"LM\""); diff --git a/swad_center.c b/swad_center.c index 6862aca11..aa6374cb4 100644 --- a/swad_center.c +++ b/swad_center.c @@ -747,7 +747,7 @@ static void Ctr_ListCentersForEdition (const struct Plc_Places *Places) unsigned NumDegs; unsigned NumUsrsCtr; unsigned NumUsrsInCrssOfCtr; - const char *Name[Cns_NUM_SHRT_FULL_NAMES]; + const char *Names[Cns_NUM_SHRT_FULL_NAMES]; /***** Initialize structure with user's data *****/ Usr_UsrDataConstructor (&UsrDat); @@ -840,12 +840,12 @@ static void Ctr_ListCentersForEdition (const struct Plc_Places *Places) HTM_TD_End (); /* Center short name and full name */ - Name[Cns_SHRT_NAME] = Ctr->ShrtName; - Name[Cns_FULL_NAME] = Ctr->FullName; - Frm_PutShortAndFullNames (ActionRename, - ParCod_OthHie,Ctr->HieCod, - Name, - ICanEdit); // Put form? + Names[Cns_SHRT_NAME] = Ctr->ShrtName; + Names[Cns_FULL_NAME] = Ctr->FullName; + Frm_ExistingShortAndFullNames (ActionRename, + ParCod_OthHie,Ctr->HieCod, + Names, + ICanEdit); // Put form? /* Center WWW */ HTM_TD_Begin ("class=\"LM DAT_%s\"",The_GetSuffix ()); @@ -1236,15 +1236,11 @@ static void Ctr_ShowAlertAndButtonToGoToCtr (void) static void Ctr_PutFormToCreateCenter (const struct Plc_Places *Places) { - extern const char *Cns_ParShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; - extern unsigned Cns_MaxCharsShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; - extern const char *Cns_ClassShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; extern const char *Txt_Another_place; Act_Action_t NextAction = ActUnk; unsigned NumPlc; const struct Plc_Place *Plc; - Cns_ShrtOrFullName_t ShrtOrFullName; - char *Name[Cns_NUM_SHRT_FULL_NAMES] = + const char *Names[Cns_NUM_SHRT_FULL_NAMES] = { [Cns_SHRT_NAME] = Ctr_EditingCtr->ShrtName, [Cns_FULL_NAME] = Ctr_EditingCtr->FullName, @@ -1307,21 +1303,7 @@ static void Ctr_PutFormToCreateCenter (const struct Plc_Places *Places) HTM_TD_End (); /***** Center short name and full name *****/ - for (ShrtOrFullName = Cns_SHRT_NAME; - ShrtOrFullName <= Cns_FULL_NAME; - ShrtOrFullName++) - { - HTM_TD_Begin ("class=\"LM\""); - HTM_INPUT_TEXT (Cns_ParShrtOrFullName[ShrtOrFullName], - Cns_MaxCharsShrtOrFullName[ShrtOrFullName], - Name[ShrtOrFullName], - HTM_DONT_SUBMIT_ON_CHANGE, - "class=\"%s INPUT_%s\"" - " required=\"required\"", - Cns_ClassShrtOrFullName[ShrtOrFullName], - The_GetSuffix ()); - HTM_TD_End (); - } + Frm_NewShortAndFullNames (Names); /***** Center WWW *****/ HTM_TD_Begin ("class=\"LM\""); diff --git a/swad_changelog.h b/swad_changelog.h index 330987c9b..89f10d63c 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -632,10 +632,11 @@ TODO: Francisco Javier Fern Me sale este error, no sé si por no recordar yo la sintaxis apropiada para mandar a varios destinatarios. ¿No era así? "can npt create received message (duplicated entry '243218-2160773' for key 'UsrCod_MsgCod') */ -#define Log_PLATFORM_VERSION "SWAD 23.32 (2023-10-10)" +#define Log_PLATFORM_VERSION "SWAD 23.33 (2023-10-10)" #define CSS_FILE "swad23.25.2.css" #define JS_FILE "swad22.49.js" /* + Version 23.33: Oct 10, 2023 Code refactoring in short and full names. (335919 lines) Version 23.32: Oct 10, 2023 Code refactoring in short and full names. (336110 lines) Version 23.31: Oct 10, 2023 Code refactoring in short and full names. (336169 lines) Version 23.30: Oct 09, 2023 Code refactoring in short and full names. (336293 lines) diff --git a/swad_course.c b/swad_course.c index 37f4103d0..132f47e9a 100644 --- a/swad_course.c +++ b/swad_course.c @@ -929,7 +929,7 @@ static void Crs_ListCoursesOfAYearForEdition (unsigned Year) struct Usr_Data UsrDat; bool ICanEdit; unsigned NumUsrs[Rol_NUM_ROLES]; - const char *Name[Cns_NUM_SHRT_FULL_NAMES]; + const char *Names[Cns_NUM_SHRT_FULL_NAMES]; /***** Initialize structure with user's data *****/ Usr_UsrDataConstructor (&UsrDat); @@ -1014,12 +1014,12 @@ static void Crs_ListCoursesOfAYearForEdition (unsigned Year) HTM_TD_End (); /* Course short name and full name */ - Name[Cns_SHRT_NAME] = Crs->ShrtName; - Name[Cns_FULL_NAME] = Crs->FullName; - Frm_PutShortAndFullNames (ActionRename, - ParCod_OthHie,Crs->HieCod, - Name, - ICanEdit); // Put form? + Names[Cns_SHRT_NAME] = Crs->ShrtName; + Names[Cns_FULL_NAME] = Crs->FullName; + Frm_ExistingShortAndFullNames (ActionRename, + ParCod_OthHie,Crs->HieCod, + Names, + ICanEdit); // Put form? /* Current number of teachers in this course */ HTM_TD_Begin ("class=\"RM DAT_%s\"",The_GetSuffix ()); @@ -1072,21 +1072,15 @@ static bool Crs_CheckIfICanEdit (struct Hie_Node *Crs) static void Crs_PutFormToCreateCourse (void) { - extern const char *Cns_ParShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; - extern unsigned Cns_MaxCharsShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; - extern const char *Cns_ClassShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; extern const char *Txt_YEAR_OF_DEGREE[1 + Deg_MAX_YEARS_PER_DEGREE]; Act_Action_t NextAction = ActUnk; unsigned Year; - Cns_ShrtOrFullName_t ShrtOrFullName; - char *Name[Cns_NUM_SHRT_FULL_NAMES] = + const char *Names[Cns_NUM_SHRT_FULL_NAMES] = { [Cns_SHRT_NAME] = Crs_EditingCrs->ShrtName, [Cns_FULL_NAME] = Crs_EditingCrs->FullName, }; - /***** Set action depending on role *****/ - /***** Begin form *****/ if (Gbl.Usrs.Me.Role.Logged >= Rol_DEG_ADM) NextAction = ActNewCrs; @@ -1138,21 +1132,7 @@ static void Crs_PutFormToCreateCourse (void) HTM_TD_End (); /***** Course short name and full name *****/ - for (ShrtOrFullName = Cns_SHRT_NAME; - ShrtOrFullName <= Cns_FULL_NAME; - ShrtOrFullName++) - { - HTM_TD_Begin ("class=\"LM\""); - HTM_INPUT_TEXT (Cns_ParShrtOrFullName[ShrtOrFullName], - Cns_MaxCharsShrtOrFullName[ShrtOrFullName], - Name[ShrtOrFullName], - HTM_DONT_SUBMIT_ON_CHANGE, - "class=\"%s INPUT_%s\"" - " required=\"required\"", - Cns_ClassShrtOrFullName[ShrtOrFullName], - The_GetSuffix ()); - HTM_TD_End (); - } + Frm_NewShortAndFullNames (Names); /***** Current number of teachers in this course *****/ HTM_TD_Begin ("class=\"RM DAT_%s\"",The_GetSuffix ()); diff --git a/swad_degree.c b/swad_degree.c index 53ce9826e..5a2d7a005 100644 --- a/swad_degree.c +++ b/swad_degree.c @@ -331,7 +331,7 @@ static void Deg_ListDegreesForEdition (const struct DegTyp_DegTypes *DegTypes) bool ICanEdit; unsigned NumCrss; unsigned NumUsrsInCrssOfDeg; - const char *Name[Cns_NUM_SHRT_FULL_NAMES]; + const char *Names[Cns_NUM_SHRT_FULL_NAMES]; /***** Initialize structure with user's data *****/ Usr_UsrDataConstructor (&UsrDat); @@ -385,12 +385,12 @@ static void Deg_ListDegreesForEdition (const struct DegTyp_DegTypes *DegTypes) HTM_TD_End (); /* Degree short name and full name */ - Name[Cns_SHRT_NAME] = Deg->ShrtName; - Name[Cns_FULL_NAME] = Deg->FullName; - Frm_PutShortAndFullNames (ActionRename, - ParCod_OthHie,Deg->HieCod, - Name, - ICanEdit); // Put form? + Names[Cns_SHRT_NAME] = Deg->ShrtName; + Names[Cns_FULL_NAME] = Deg->FullName; + Frm_ExistingShortAndFullNames (ActionRename, + ParCod_OthHie,Deg->HieCod, + Names, + ICanEdit); // Put form? /* Degree type */ HTM_TD_Begin ("class=\"LM DAT_%s\"",The_GetSuffix ()); @@ -506,14 +506,10 @@ static bool Deg_CheckIfICanEditADegree (struct Hie_Node *Deg) static void Deg_PutFormToCreateDegree (const struct DegTyp_DegTypes *DegTypes) { - extern const char *Cns_ParShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; - extern unsigned Cns_MaxCharsShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; - extern const char *Cns_ClassShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; Act_Action_t NextAction = ActUnk; unsigned NumDegTyp; struct DegTyp_DegreeType *DegTyp; - Cns_ShrtOrFullName_t ShrtOrFullName; - char *Name[Cns_NUM_SHRT_FULL_NAMES] = + const char *Names[Cns_NUM_SHRT_FULL_NAMES] = { [Cns_SHRT_NAME] = Deg_EditingDeg->ShrtName, [Cns_FULL_NAME] = Deg_EditingDeg->FullName, @@ -552,21 +548,7 @@ static void Deg_PutFormToCreateDegree (const struct DegTyp_DegTypes *DegTypes) HTM_TD_End (); /***** Degree short name and full name *****/ - for (ShrtOrFullName = Cns_SHRT_NAME; - ShrtOrFullName <= Cns_FULL_NAME; - ShrtOrFullName++) - { - HTM_TD_Begin ("class=\"LM\""); - HTM_INPUT_TEXT (Cns_ParShrtOrFullName[ShrtOrFullName], - Cns_MaxCharsShrtOrFullName[ShrtOrFullName], - Name[ShrtOrFullName], - HTM_DONT_SUBMIT_ON_CHANGE, - "class=\"%s INPUT_%s\"" - " required=\"required\"", - Cns_ClassShrtOrFullName[ShrtOrFullName], - The_GetSuffix ()); - HTM_TD_End (); - } + Frm_NewShortAndFullNames (Names); /***** Degree type *****/ HTM_TD_Begin ("class=\"LM\""); diff --git a/swad_department.c b/swad_department.c index e52177c77..5f8ee95e5 100644 --- a/swad_department.c +++ b/swad_department.c @@ -474,7 +474,7 @@ static void Dpt_ListDepartmentsForEdition (const struct Dpt_Departments *Departm struct Dpt_Department *Dpt; unsigned NumIns; struct Hie_Node *Ins; - const char *Name[Cns_NUM_SHRT_FULL_NAMES]; + const char *Names[Cns_NUM_SHRT_FULL_NAMES]; /***** Begin table *****/ HTM_TABLE_BeginPadding (2); @@ -534,12 +534,12 @@ static void Dpt_ListDepartmentsForEdition (const struct Dpt_Departments *Departm HTM_TD_End (); /* Department short name and full name */ - Name[Cns_SHRT_NAME] = Dpt->ShrtName; - Name[Cns_FULL_NAME] = Dpt->FullName; - Frm_PutShortAndFullNames (ActionRename, - ParCod_Dpt,Dpt->DptCod, - Name, - true); // Put form + Names[Cns_SHRT_NAME] = Dpt->ShrtName; + Names[Cns_FULL_NAME] = Dpt->FullName; + Frm_ExistingShortAndFullNames (ActionRename, + ParCod_Dpt,Dpt->DptCod, + Names, + true); // Put form /* Department WWW */ HTM_TD_Begin ("class=\"LM\""); @@ -793,14 +793,10 @@ void Dpt_ContEditAfterChgDpt (void) static void Dpt_PutFormToCreateDepartment (void) { - extern const char *Cns_ParShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; - extern unsigned Cns_MaxCharsShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; - extern const char *Cns_ClassShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; extern const char *Txt_Another_institution; unsigned NumIns; const struct Hie_Node *Ins; - Cns_ShrtOrFullName_t ShrtOrFullName; - char *Name[Cns_NUM_SHRT_FULL_NAMES] = + const char *Names[Cns_NUM_SHRT_FULL_NAMES] = { [Cns_SHRT_NAME] = Dpt_EditingDpt->ShrtName, [Cns_FULL_NAME] = Dpt_EditingDpt->FullName, @@ -848,21 +844,7 @@ static void Dpt_PutFormToCreateDepartment (void) HTM_TD_End (); /***** Department short name and full name *****/ - for (ShrtOrFullName = Cns_SHRT_NAME; - ShrtOrFullName <= Cns_FULL_NAME; - ShrtOrFullName++) - { - HTM_TD_Begin ("class=\"LM\""); - HTM_INPUT_TEXT (Cns_ParShrtOrFullName[ShrtOrFullName], - Cns_MaxCharsShrtOrFullName[ShrtOrFullName], - Name[ShrtOrFullName], - HTM_DONT_SUBMIT_ON_CHANGE, - "class=\"%s INPUT_%s\"" - " required=\"required\"", - Cns_ClassShrtOrFullName[ShrtOrFullName], - The_GetSuffix ()); - HTM_TD_End (); - } + Frm_NewShortAndFullNames (Names); /***** Department WWW *****/ HTM_TD_Begin ("class=\"LM\""); diff --git a/swad_form.c b/swad_form.c index 8e90e4693..6c5adde6c 100644 --- a/swad_form.c +++ b/swad_form.c @@ -357,10 +357,34 @@ void Frm_LabelColumn (const char *TDClass,const char *Id,const char *Label) /************************ Write short and full names *************************/ /*****************************************************************************/ -void Frm_PutShortAndFullNames (Act_Action_t ActionRename[Cns_NUM_SHRT_FULL_NAMES], - ParCod_Param_t ParCod,long Cod, - const char *Name[Cns_NUM_SHRT_FULL_NAMES], - bool PutForm) +void Frm_NewShortAndFullNames (const char *Names[Cns_NUM_SHRT_FULL_NAMES]) + { + extern const char *Cns_ParShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; + extern unsigned Cns_MaxCharsShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; + extern const char *Cns_ClassShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; + Cns_ShrtOrFullName_t ShrtOrFullName; + + for (ShrtOrFullName = Cns_SHRT_NAME; + ShrtOrFullName <= Cns_FULL_NAME; + ShrtOrFullName++) + { + HTM_TD_Begin ("class=\"CM\""); + HTM_INPUT_TEXT (Cns_ParShrtOrFullName[ShrtOrFullName], + Cns_MaxCharsShrtOrFullName[ShrtOrFullName], + Names[ShrtOrFullName], + HTM_DONT_SUBMIT_ON_CHANGE, + "class=\"%s INPUT_%s\"" + " required=\"required\"", + Cns_ClassShrtOrFullName[ShrtOrFullName], + The_GetSuffix ()); + HTM_TD_End (); + } + } + +void Frm_ExistingShortAndFullNames (Act_Action_t ActionRename[Cns_NUM_SHRT_FULL_NAMES], + ParCod_Param_t ParCod,long Cod, + const char *Names[Cns_NUM_SHRT_FULL_NAMES], + bool PutForm) { extern const char *Cns_ParShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; extern unsigned Cns_MaxCharsShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; @@ -378,15 +402,16 @@ void Frm_PutShortAndFullNames (Act_Action_t ActionRename[Cns_NUM_SHRT_FULL_NAMES ParCod_PutPar (ParCod,Cod); HTM_INPUT_TEXT (Cns_ParShrtOrFullName[ShrtOrFullName], Cns_MaxCharsShrtOrFullName[ShrtOrFullName], - Name[ShrtOrFullName], + Names[ShrtOrFullName], HTM_SUBMIT_ON_CHANGE, - "class=\"%s INPUT_%s\"", + "class=\"%s INPUT_%s\"" + " required=\"required\"", Cns_ClassShrtOrFullName[ShrtOrFullName], The_GetSuffix ()); Frm_EndForm (); } else - HTM_Txt (Name[ShrtOrFullName]); + HTM_Txt (Names[ShrtOrFullName]); HTM_TD_End (); } } diff --git a/swad_form.h b/swad_form.h index 91480af9e..6c64fb778 100644 --- a/swad_form.h +++ b/swad_form.h @@ -79,9 +79,10 @@ void Frm_FreeAnchorStr (char **Anchor); void Frm_LabelColumn (const char *TDClass,const char *Id,const char *Label); -void Frm_PutShortAndFullNames (Act_Action_t ActionRename[Cns_NUM_SHRT_FULL_NAMES], - ParCod_Param_t ParCod,long Cod, - const char *Name[Cns_NUM_SHRT_FULL_NAMES], - bool PutForm); +void Frm_NewShortAndFullNames (const char *Names[Cns_NUM_SHRT_FULL_NAMES]); +void Frm_ExistingShortAndFullNames (Act_Action_t ActionRename[Cns_NUM_SHRT_FULL_NAMES], + ParCod_Param_t ParCod,long Cod, + const char *Names[Cns_NUM_SHRT_FULL_NAMES], + bool PutForm); #endif diff --git a/swad_institution.c b/swad_institution.c index 8be7605ab..94535a112 100644 --- a/swad_institution.c +++ b/swad_institution.c @@ -890,7 +890,7 @@ static void Ins_ListInstitutionsForEdition (void) unsigned NumCtrs; unsigned NumUsrsIns; unsigned NumUsrsInCrssOfIns; - const char *Name[Cns_NUM_SHRT_FULL_NAMES]; + const char *Names[Cns_NUM_SHRT_FULL_NAMES]; /***** Initialize structure with user's data *****/ Usr_UsrDataConstructor (&UsrDat); @@ -947,12 +947,12 @@ static void Ins_ListInstitutionsForEdition (void) HTM_TD_End (); /* Institution short name and full name */ - Name[Cns_SHRT_NAME] = Ins->ShrtName; - Name[Cns_FULL_NAME] = Ins->FullName; - Frm_PutShortAndFullNames (ActionRename, - ParCod_OthHie,Ins->HieCod, - Name, - ICanEdit); // Put form? + Names[Cns_SHRT_NAME] = Ins->ShrtName; + Names[Cns_FULL_NAME] = Ins->FullName; + Frm_ExistingShortAndFullNames (ActionRename, + ParCod_OthHie,Ins->HieCod, + Names, + ICanEdit); // Put form? /* Institution WWW */ HTM_TD_Begin ("class=\"LM DAT_%s\"",The_GetSuffix ()); @@ -1330,12 +1330,8 @@ static void Ins_ShowAlertAndButtonToGoToIns (void) static void Ins_PutFormToCreateInstitution (void) { - extern const char *Cns_ParShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; - extern unsigned Cns_MaxCharsShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; - extern const char *Cns_ClassShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; Act_Action_t NextAction = ActUnk; - Cns_ShrtOrFullName_t ShrtOrFullName; - char *Name[Cns_NUM_SHRT_FULL_NAMES] = + const char *Names[Cns_NUM_SHRT_FULL_NAMES] = { [Cns_SHRT_NAME] = Ins_EditingIns->ShrtName, [Cns_FULL_NAME] = Ins_EditingIns->FullName, @@ -1374,21 +1370,7 @@ static void Ins_PutFormToCreateInstitution (void) HTM_TD_End (); /***** Institution short name and full name *****/ - for (ShrtOrFullName = Cns_SHRT_NAME; - ShrtOrFullName <= Cns_FULL_NAME; - ShrtOrFullName++) - { - HTM_TD_Begin ("class=\"LM\""); - HTM_INPUT_TEXT (Cns_ParShrtOrFullName[ShrtOrFullName], - Cns_MaxCharsShrtOrFullName[ShrtOrFullName], - Name[ShrtOrFullName], - HTM_DONT_SUBMIT_ON_CHANGE, - "class=\"%s INPUT_%s\"" - " required=\"required\"", - Cns_ClassShrtOrFullName[ShrtOrFullName], - The_GetSuffix ()); - HTM_TD_End (); - } + Frm_NewShortAndFullNames (Names); /***** Institution WWW *****/ HTM_TD_Begin ("class=\"LM\""); diff --git a/swad_link.c b/swad_link.c index 974b63b02..927259164 100644 --- a/swad_link.c +++ b/swad_link.c @@ -404,7 +404,7 @@ static void Lnk_ListLinksForEdition (const struct Lnk_Links *Links) }; unsigned NumLnk; struct Lnk_Link *Lnk; - const char *Name[Cns_NUM_SHRT_FULL_NAMES]; + const char *Names[Cns_NUM_SHRT_FULL_NAMES]; /***** Begin table *****/ HTM_TABLE_BeginWidePadding (2); @@ -433,12 +433,12 @@ static void Lnk_ListLinksForEdition (const struct Lnk_Links *Links) HTM_TD_End (); /* Link short name and full name */ - Name[Cns_SHRT_NAME] = Lnk->ShrtName; - Name[Cns_FULL_NAME] = Lnk->FullName; - Frm_PutShortAndFullNames (ActionRename, - ParCod_Lnk,Lnk->LnkCod, - Name, - true); // Put form + Names[Cns_SHRT_NAME] = Lnk->ShrtName; + Names[Cns_FULL_NAME] = Lnk->FullName; + Frm_ExistingShortAndFullNames (ActionRename, + ParCod_Lnk,Lnk->LnkCod, + Names, + true); // Put form /* Link WWW */ HTM_TD_Begin ("class=\"CM\""); @@ -649,11 +649,7 @@ void Lnk_ContEditAfterChgLnk (void) static void Lnk_PutFormToCreateLink (void) { - extern const char *Cns_ParShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; - extern unsigned Cns_MaxCharsShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; - extern const char *Cns_ClassShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; - Cns_ShrtOrFullName_t ShrtOrFullName; - char *Name[Cns_NUM_SHRT_FULL_NAMES] = + const char *Names[Cns_NUM_SHRT_FULL_NAMES] = { [Cns_SHRT_NAME] = Lnk_EditingLnk->ShrtName, [Cns_FULL_NAME] = Lnk_EditingLnk->FullName, @@ -676,21 +672,7 @@ static void Lnk_PutFormToCreateLink (void) HTM_TD_End (); /***** Link short name and full name *****/ - for (ShrtOrFullName = Cns_SHRT_NAME; - ShrtOrFullName <= Cns_FULL_NAME; - ShrtOrFullName++) - { - HTM_TD_Begin ("class=\"CM\""); - HTM_INPUT_TEXT (Cns_ParShrtOrFullName[ShrtOrFullName], - Cns_MaxCharsShrtOrFullName[ShrtOrFullName], - Name[ShrtOrFullName], - HTM_DONT_SUBMIT_ON_CHANGE, - "class=\"%s INPUT_%s\"" - " required=\"required\"", - Cns_ClassShrtOrFullName[ShrtOrFullName], - The_GetSuffix ()); - HTM_TD_End (); - } + Frm_NewShortAndFullNames (Names); /***** Link WWW *****/ HTM_TD_Begin ("class=\"CM\""); diff --git a/swad_place.c b/swad_place.c index be6e4bcfb..9384e575c 100644 --- a/swad_place.c +++ b/swad_place.c @@ -452,7 +452,7 @@ static void Plc_ListPlacesForEdition (const struct Plc_Places *Places) }; unsigned NumPlc; struct Plc_Place *Plc; - const char *Name[Cns_NUM_SHRT_FULL_NAMES]; + const char *Names[Cns_NUM_SHRT_FULL_NAMES]; /***** Begin table *****/ HTM_TABLE_BeginWidePadding (2); @@ -484,12 +484,12 @@ static void Plc_ListPlacesForEdition (const struct Plc_Places *Places) HTM_TD_End (); /* Place short name and full name */ - Name[Cns_SHRT_NAME] = Plc->ShrtName; - Name[Cns_FULL_NAME] = Plc->FullName; - Frm_PutShortAndFullNames (ActionRename, - ParCod_Plc,Plc->PlcCod, - Name, - true); // Put form + Names[Cns_SHRT_NAME] = Plc->ShrtName; + Names[Cns_FULL_NAME] = Plc->FullName; + Frm_ExistingShortAndFullNames (ActionRename, + ParCod_Plc,Plc->PlcCod, + Names, + true); // Put form /* Number of centers */ HTM_TD_Begin ("class=\"RM DAT_%s\"",The_GetSuffix ()); @@ -662,11 +662,7 @@ void Plc_ContEditAfterChgPlc (void) static void Plc_PutFormToCreatePlace (void) { - extern const char *Cns_ParShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; - extern unsigned Cns_MaxCharsShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; - extern const char *Cns_ClassShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; - Cns_ShrtOrFullName_t ShrtOrFullName; - char *Name[Cns_NUM_SHRT_FULL_NAMES] = + const char *Names[Cns_NUM_SHRT_FULL_NAMES] = { [Cns_SHRT_NAME] = Plc_EditingPlc->ShrtName, [Cns_FULL_NAME] = Plc_EditingPlc->FullName, @@ -689,21 +685,7 @@ static void Plc_PutFormToCreatePlace (void) HTM_TD_End (); /***** Place short name and full name *****/ - for (ShrtOrFullName = Cns_SHRT_NAME; - ShrtOrFullName <= Cns_FULL_NAME; - ShrtOrFullName++) - { - HTM_TD_Begin ("class=\"CM\""); - HTM_INPUT_TEXT (Cns_ParShrtOrFullName[ShrtOrFullName], - Cns_MaxCharsShrtOrFullName[ShrtOrFullName], - Name[ShrtOrFullName], - HTM_DONT_SUBMIT_ON_CHANGE, - "class=\"%s INPUT_%s\"" - " required=\"required\"", - Cns_ClassShrtOrFullName[ShrtOrFullName], - The_GetSuffix ()); - HTM_TD_End (); - } + Frm_NewShortAndFullNames (Names); /***** Number of centers *****/ HTM_TD_Begin ("class=\"RM DAT_%s\"",The_GetSuffix ()); diff --git a/swad_room.c b/swad_room.c index c624f15b6..baf40a724 100644 --- a/swad_room.c +++ b/swad_room.c @@ -628,9 +628,6 @@ void Roo_FreeListRooms (struct Roo_Rooms *Rooms) static void Roo_ListRoomsForEdition (const struct Bld_Buildings *Buildings, const struct Roo_Rooms *Rooms) { - extern const char *Cns_ParShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; - extern unsigned Cns_MaxCharsShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; - extern const char *Cns_ClassShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; static Act_Action_t ActionRename[Cns_NUM_SHRT_FULL_NAMES] = { [Cns_SHRT_NAME] = ActRenRooSho, @@ -640,8 +637,7 @@ static void Roo_ListRoomsForEdition (const struct Bld_Buildings *Buildings, struct Roo_Room *Room; char *Anchor = NULL; char StrCapacity[Cns_MAX_DECIMAL_DIGITS_UINT + 1]; - Cns_ShrtOrFullName_t ShrtOrFullName; - char *Name[Cns_NUM_SHRT_FULL_NAMES]; + const char *Names[Cns_NUM_SHRT_FULL_NAMES]; HTM_TABLE_BeginWidePadding (2); @@ -703,26 +699,12 @@ static void Roo_ListRoomsForEdition (const struct Bld_Buildings *Buildings, HTM_TD_End (); /* Room short name and full name */ - Name[Cns_SHRT_NAME] = Room->ShrtName; - Name[Cns_FULL_NAME] = Room->FullName; - for (ShrtOrFullName = Cns_SHRT_NAME; - ShrtOrFullName <= Cns_FULL_NAME; - ShrtOrFullName++) - { - HTM_TD_Begin ("class=\"LT\""); - Frm_BeginFormAnchor (ActionRename[ShrtOrFullName],Anchor); - ParCod_PutPar (ParCod_Roo,Room->RooCod); - HTM_INPUT_TEXT (Cns_ParShrtOrFullName[ShrtOrFullName], - Cns_MaxCharsShrtOrFullName[ShrtOrFullName], - Name[ShrtOrFullName], - HTM_SUBMIT_ON_CHANGE, - "size=\"10\"" - " class=\"%s INPUT_%s\"", - Cns_ClassShrtOrFullName[ShrtOrFullName], - The_GetSuffix ()); - Frm_EndForm (); - HTM_TD_End (); - } + Names[Cns_SHRT_NAME] = Room->ShrtName; + Names[Cns_FULL_NAME] = Room->FullName; + Frm_ExistingShortAndFullNames (ActionRename, + ParCod_Roo,Room->RooCod, + Names, + true); // Put form /* Seating capacity */ HTM_TD_Begin ("class=\"LT\""); @@ -1214,13 +1196,9 @@ void Roo_ContEditAfterChgRoom (void) static void Roo_PutFormToCreateRoom (const struct Bld_Buildings *Buildings) { - extern const char *Cns_ParShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; - extern unsigned Cns_MaxCharsShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; - extern const char *Cns_ClassShrtOrFullName[Cns_NUM_SHRT_FULL_NAMES]; char StrCapacity[Cns_MAX_DECIMAL_DIGITS_UINT + 1]; char MACstr[MAC_LENGTH_MAC_ADDRESS + 1]; // MAC address in xx:xx:xx:xx:xx:xx format - Cns_ShrtOrFullName_t ShrtOrFullName; - char *Name[Cns_NUM_SHRT_FULL_NAMES] = + const char *Names[Cns_NUM_SHRT_FULL_NAMES] = { [Cns_SHRT_NAME] = Roo_EditingRoom->ShrtName, [Cns_FULL_NAME] = Roo_EditingRoom->FullName, @@ -1263,21 +1241,7 @@ static void Roo_PutFormToCreateRoom (const struct Bld_Buildings *Buildings) HTM_TD_End (); /***** Room short name and full name *****/ - for (ShrtOrFullName = Cns_SHRT_NAME; - ShrtOrFullName <= Cns_FULL_NAME; - ShrtOrFullName++) - { - HTM_TD_Begin ("class=\"LM\""); - HTM_INPUT_TEXT (Cns_ParShrtOrFullName[ShrtOrFullName], - Cns_MaxCharsShrtOrFullName[ShrtOrFullName], - Name[ShrtOrFullName], - HTM_DONT_SUBMIT_ON_CHANGE, - "size=\"10\" class=\"%s INPUT_%s\"" - " required=\"required\"", - Cns_ClassShrtOrFullName[ShrtOrFullName], - The_GetSuffix ()); - HTM_TD_End (); - } + Frm_NewShortAndFullNames (Names); /***** Seating capacity *****/ HTM_TD_Begin ("class=\"LM\""); @@ -1363,9 +1327,9 @@ void Roo_ReceiveFormNewRoom (void) /* Get seating capacity */ Roo_EditingRoom->Capacity = (unsigned) Par_GetParUnsignedLong ("Capacity", - 0, - Roo_MAX_CAPACITY, - Roo_UNLIMITED_CAPACITY); + 0, + Roo_MAX_CAPACITY, + Roo_UNLIMITED_CAPACITY); /* Get MAC address */ Roo_EditingRoom->MACnum = MAC_GetMACnumFromForm ("MAC");