diff --git a/swad_ID.c b/swad_ID.c index 6d8d29c8..86b41f42 100644 --- a/swad_ID.c +++ b/swad_ID.c @@ -312,7 +312,7 @@ void ID_WriteUsrIDs (struct Usr_Data *UsrDat,const char *Anchor) ICanSeeUsrID = ID_ICanSeeOtherUsrIDs (UsrDat); ICanConfirmUsrID = ICanSeeUsrID && (UsrDat->UsrCod != Gbl.Usrs.Me.UsrDat.UsrCod) && // Not me - !Gbl.Form.Inside && // Not inside another form + !Frm_CheckIfInside () && // Not inside another form Act_GetBrowserTab (Gbl.Action.Act) == Act_BRW_1ST_TAB; // Only in main browser tab for (NumID = 0; diff --git a/swad_changelog.h b/swad_changelog.h index 6a2bde57..358c0d09 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -606,10 +606,11 @@ TODO: Fix bug: error al enviar un mensaje a dos recipientes, error on duplicate TODO: Attach pdf files in multimedia. */ -#define Log_PLATFORM_VERSION "SWAD 22.49.1 (2022-10-17)" +#define Log_PLATFORM_VERSION "SWAD 22.49.2 (2022-10-18)" #define CSS_FILE "swad22.49.css" #define JS_FILE "swad22.49.js" /* + Version 22.49.2: Oct 18, 2022 Code refactoring related to forms. (333189 lines) Version 22.49.1: Oct 17, 2022 Fixed bug filtering projects. (333176 lines) Version 22.49: Oct 16, 2022 Changes in project review form. (333161 lines) Version 22.48: Oct 15, 2022 Code optimization related to nick links. (333157 lines) diff --git a/swad_country.c b/swad_country.c index 0664be2b..6943de5d 100644 --- a/swad_country.c +++ b/swad_country.c @@ -905,7 +905,7 @@ void Cty_WriteSelectorOfCountry (void) void Cty_WriteCountryName (long CtyCod) { char CtyName[Cty_MAX_BYTES_NAME + 1]; - bool PutForm = !Gbl.Form.Inside && // Only if not inside another form + bool PutForm = !Frm_CheckIfInside () && // Only if not inside another form Act_GetBrowserTab (Gbl.Action.Act) == Act_BRW_1ST_TAB; // Only in main browser tab /***** Get country name *****/ diff --git a/swad_form.c b/swad_form.c index 299dee82..3cb569c3 100644 --- a/swad_form.c +++ b/swad_form.c @@ -41,6 +41,12 @@ extern struct Globals Gbl; +/*****************************************************************************/ +/************************* Private global variables **************************/ +/*****************************************************************************/ + +static bool Frm_Inside = false; + /*****************************************************************************/ /**************************** Private prototypes *****************************/ /*****************************************************************************/ @@ -48,6 +54,8 @@ extern struct Globals Gbl; static void Frm_BeginFormInternal (Act_Action_t NextAction,bool PutParameterLocationIfNoSesion, const char *Id,const char *Anchor,const char *OnSubmit); +static inline void Frm_SetInside (bool Inside); + /*****************************************************************************/ /******************************** Begin a form *******************************/ /*****************************************************************************/ @@ -88,7 +96,7 @@ static void Frm_BeginFormInternal (Act_Action_t NextAction,bool PutParameterLoca extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES]; char ParamsStr[Frm_MAX_BYTES_PARAMS_STR + 1]; - if (!Gbl.Form.Inside) + if (!Frm_CheckIfInside ()) { /* Begin form */ HTM_TxtF ("
"); // Form that can not be submitted, to avoid enter key to send it - Gbl.Form.Inside = true; + Frm_SetInside (true); } } @@ -215,10 +223,10 @@ void Frm_SetParamsForm (char ParamsStr[Frm_MAX_BYTES_PARAMS_STR + 1],Act_Action_ void Frm_EndForm (void) { - if (Gbl.Form.Inside) + if (Frm_CheckIfInside ()) { HTM_Txt ("
"); - Gbl.Form.Inside = false; + Frm_SetInside (false); } } @@ -299,3 +307,17 @@ void Frm_LabelColumn (const char *TDClass,const char *Id,const char *Label) /***** Column/cell end *****/ HTM_TD_End (); } + +/*****************************************************************************/ +/************** Set to true inside a form to avoid nested forms **************/ +/*****************************************************************************/ + +static inline void Frm_SetInside (bool Inside) + { + Frm_Inside = Inside; + } + +bool Frm_CheckIfInside (void) + { + return Frm_Inside; + } diff --git a/swad_form.h b/swad_form.h index 3e396f7c..8a6b6b85 100644 --- a/swad_form.h +++ b/swad_form.h @@ -64,4 +64,6 @@ void Frm_FreeAnchorStr (char *Anchor); void Frm_LabelColumn (const char *TDClass,const char *Id,const char *Label); +bool Frm_CheckIfInside (void); + #endif diff --git a/swad_global.c b/swad_global.c index ec9c950e..f8a7fa1a 100644 --- a/swad_global.c +++ b/swad_global.c @@ -106,8 +106,6 @@ void Gbl_InitializeGlobals (void) Gbl.F.XML = NULL; Gbl.F.Rep = NULL; // Report - Gbl.Form.Inside = false; // Set to true inside a form to avoid nested forms - Gbl.Box.Nested = -1; // -1 means no box open Gbl.Alerts.Num = 0; // No pending alerts to be shown diff --git a/swad_global.h b/swad_global.h index 2a2b5b9d..49a173b3 100644 --- a/swad_global.h +++ b/swad_global.h @@ -75,10 +75,6 @@ struct Globals struct Files F; MYSQL mysql; pid_t PID; // PID of current process - struct - { - bool Inside; // Set to true inside a form to avoid nested forms - } Form; struct { int Nested; // Index of top open box diff --git a/swad_group.c b/swad_group.c index 8c26ed9a..b9144d82 100644 --- a/swad_group.c +++ b/swad_group.c @@ -362,7 +362,7 @@ void Grp_ShowFormToSelectSeveralGroups (void (*FuncParams) (void *Args),void *Ar return; /***** Begin box *****/ - ICanEdit = !Gbl.Form.Inside && + ICanEdit = !Frm_CheckIfInside () && (Gbl.Usrs.Me.Role.Logged == Rol_TCH || Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM); if (ICanEdit) @@ -1706,8 +1706,8 @@ void Grp_ShowLstGrpsToChgMyGrps (void) unsigned NumGrpTyp; unsigned NumGrpsThisTypeIBelong; unsigned NumGrpsIBelong = 0; - bool PutFormToChangeGrps = !Gbl.Form.Inside; // Not inside another form (record card) - bool ICanEdit = !Gbl.Form.Inside && + bool PutFormToChangeGrps = !Frm_CheckIfInside (); // Not inside another form (record card) + bool ICanEdit = !Frm_CheckIfInside () && (Gbl.Usrs.Me.Role.Logged == Rol_TCH || Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM); bool ICanChangeMyGrps = false; diff --git a/swad_institution.c b/swad_institution.c index 475b45a7..f6b73866 100644 --- a/swad_institution.c +++ b/swad_institution.c @@ -205,7 +205,7 @@ void Ins_SeeInsWithPendingCtrs (void) void Ins_DrawInstitutionLogoWithLink (struct Ins_Instit *Ins,unsigned Size) { - bool PutLink = !Gbl.Form.Inside; // Don't put link to institution if already inside a form + bool PutLink = !Frm_CheckIfInside (); // Don't put link to institution if already inside a form if (PutLink) { diff --git a/swad_media.c b/swad_media.c index 637ea15d..d7140a53 100644 --- a/swad_media.c +++ b/swad_media.c @@ -1831,7 +1831,7 @@ static void Med_AlertThirdPartyCookies (void) Ale_ShowAlertAndButton1 (Ale_INFO,Txt_To_watch_multimedia_content_from_another_website_you_have_to_accept_third_party_cookies_in_your_personal_settings); /* Put form to change cookies preferences */ - if (!Gbl.Form.Inside) + if (!Frm_CheckIfInside ()) Lay_PutContextualLinkIconText (ActReqEdiSet,Coo_COOKIES_ID, NULL,NULL, "cog.svg",Ico_BLACK, diff --git a/swad_notification.c b/swad_notification.c index d6ae9bc7..f83245e8 100644 --- a/swad_notification.c +++ b/swad_notification.c @@ -486,7 +486,7 @@ void Ntf_ShowMyNotifications (void) if (PutLink) { Action = Ntf_StartFormGoToAction (NotifyEvent,Hie.Crs.CrsCod,&UsrDat,Cod,&Forums); - PutLink = Gbl.Form.Inside; + PutLink = Frm_CheckIfInside (); } if (PutLink) @@ -504,7 +504,7 @@ void Ntf_ShowMyNotifications (void) if (PutLink) { Action = Ntf_StartFormGoToAction (NotifyEvent,Hie.Crs.CrsCod,&UsrDat,Cod,&Forums); - PutLink = Gbl.Form.Inside; + PutLink = Frm_CheckIfInside (); HTM_BUTTON_Submit_Begin (Txt_NOTIFY_EVENTS_SINGULAR[NotifyEvent], "class=\"LT %s_%s\"", @@ -537,7 +537,7 @@ void Ntf_ShowMyNotifications (void) if (PutLink) { Action = Ntf_StartFormGoToAction (NotifyEvent,Hie.Crs.CrsCod,&UsrDat,Cod,&Forums); - PutLink = Gbl.Form.Inside; + PutLink = Frm_CheckIfInside (); } if (PutLink) @@ -561,7 +561,7 @@ void Ntf_ShowMyNotifications (void) if (PutLink) { Action = Ntf_StartFormGoToAction (NotifyEvent,Hie.Crs.CrsCod,&UsrDat,Cod,&Forums); - PutLink = Gbl.Form.Inside; + PutLink = Frm_CheckIfInside (); } if (PutLink) @@ -815,7 +815,7 @@ static Act_Action_t Ntf_StartFormGoToAction (Ntf_NotifyEvent_t NotifyEvent, } /***** Parameter to go to another course/degree/center/institution *****/ - if (Gbl.Form.Inside) + if (Frm_CheckIfInside ()) { if (CrsCod > 0) // Course specified { diff --git a/swad_photo.c b/swad_photo.c index f3233f01..f7d49d61 100644 --- a/swad_photo.c +++ b/swad_photo.c @@ -1250,8 +1250,8 @@ void Pho_ShowUsrPhoto (const struct Usr_Data *UsrDat,const char *PhotoURL, bool BrowserTabIs1stTab = (BrowserTab == Act_BRW_1ST_TAB || BrowserTab == Act_AJAX_NORMAL || BrowserTab == Act_AJAX_RFRESH); - bool PutLinkToPublicProfile = !Gbl.Form.Inside && // Only if not inside another form - BrowserTabIs1stTab; // Only in main browser tab (or AJAX) + bool PutLinkToPublicProfile = !Frm_CheckIfInside () && // Only if not inside another form + BrowserTabIs1stTab; // Only in main browser tab (or AJAX) char *CaptionStr; char *ImgStr; diff --git a/swad_record.c b/swad_record.c index 8db0478b..a916c094 100644 --- a/swad_record.c +++ b/swad_record.c @@ -2099,7 +2099,7 @@ void Rec_ShowSharedUsrRecord (Rec_SharedRecordViewType_t TypeOfView, Rec_RecordHelp[Rec_SHA_RECORD_LIST] = Rec_RecordListHelp[UsrDat->Roles.InCurrentCrs]; - PutFormLinks = !Gbl.Form.Inside && // Only if not inside another form + PutFormLinks = !Frm_CheckIfInside () && // Only if not inside another form Act_GetBrowserTab (Gbl.Action.Act) == Act_BRW_1ST_TAB; // Only in main browser tab Ins.InsCod = UsrDat->InsCod; @@ -2323,7 +2323,7 @@ static void Rec_PutIconsCommands (__attribute__((unused)) void *Args) [Rol_SYS_ADM] = ActReqMdfOth, }; - if (!Gbl.Form.Inside && // Only if not inside another form + if (!Frm_CheckIfInside () && // Only if not inside another form Act_GetBrowserTab (Gbl.Action.Act) == Act_BRW_1ST_TAB && // Only in main browser tab Gbl.Usrs.Me.Logged) // Only if I am logged { diff --git a/swad_timeline_note.c b/swad_timeline_note.c index 19e306b3..edec755a 100644 --- a/swad_timeline_note.c +++ b/swad_timeline_note.c @@ -598,7 +598,7 @@ static void TmlNot_PutFormGoToAction (const struct TmlNot_Note *Not, }; if (Not->Unavailable || // File/notice... pointed by this note is unavailable - Gbl.Form.Inside) // Inside another form + Frm_CheckIfInside ()) // Inside another form { /***** Do not put form *****/ /* Begin container */