From 5b4a9282265b67ca20992d4f274f10dcccbfeb5a Mon Sep 17 00:00:00 2001 From: acanas Date: Sat, 15 Oct 2022 10:42:32 +0200 Subject: [PATCH] Version 22.47: Oct 15, 2022 Code optimization related to forms. --- swad_autolink.c | 17 ++--------------- swad_changelog.h | 3 ++- swad_connected.c | 21 ++++++++++++++++----- swad_form.c | 4 ++-- swad_form.h | 6 +++--- swad_global.h | 2 +- swad_photo.c | 5 +++-- swad_timeline_comment.c | 3 ++- swad_timeline_form.c | 9 ++++++--- swad_timeline_note.c | 29 +++++++++++++++++++---------- 10 files changed, 56 insertions(+), 43 deletions(-) diff --git a/swad_autolink.c b/swad_autolink.c index 9861b71d..e45cbaaa 100644 --- a/swad_autolink.c +++ b/swad_autolink.c @@ -539,25 +539,14 @@ static ALn_LinkType_t ALn_CheckNickname (char **PtrSrc,char PrevCh, (*Link)->NickAnchor[1].Str = (*Link)->NickAnchor[2].Str = NULL; - /***** Create id for this form *****/ - Gbl.Form.Num++; - if (Gbl.Usrs.Me.Logged) - snprintf (Gbl.Form.UniqueId,sizeof (Gbl.Form.UniqueId), - "form_%s_%d",Gbl.UniqueNameEncrypted,Gbl.Form.Num); - else - snprintf (Gbl.Form.Id,sizeof (Gbl.Form.Id), - "form_%d",Gbl.Form.Num); - /***** Store first part of anchor *****/ Frm_SetParamsForm (ParamsStr,ActSeeOthPubPrf,true); if (asprintf (&(*Link)->NickAnchor[0].Str, - "
" + "" "%s" // Parameters "NickAnchor[0].Len = strlen ((*Link)->NickAnchor[0].Str); @@ -566,9 +555,7 @@ static ALn_LinkType_t ALn_CheckNickname (char **PtrSrc,char PrevCh, if (asprintf (&(*Link)->NickAnchor[1].Str, "\">" "", - Gbl.Usrs.Me.Logged ? Gbl.Form.UniqueId : - Gbl.Form.Id) < 0) + " onclick=\"this.closest('form').submit();return false;\">") < 0) Err_NotEnoughMemoryExit (); (*Link)->NickAnchor[1].Len = strlen ((*Link)->NickAnchor[1].Str); diff --git a/swad_changelog.h b/swad_changelog.h index e1b71733..6166d549 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.46.3 (2022-10-15)" +#define Log_PLATFORM_VERSION "SWAD 22.47 (2022-10-15)" #define CSS_FILE "swad22.46.css" #define JS_FILE "swad21.100.js" /* + Version 22.47: Oct 15, 2022 Code optimization related to forms. (333227 lines) Version 22.46.3: Oct 15, 2022 Code refactoring submiting forms. (333211 lines) Version 22.46.2: Oct 14, 2022 Changes in anchors behavior in project listing. (333228 lines) Version 22.46.1: Oct 14, 2022 Fixed bug filtering projects by department. (333227 lines) diff --git a/swad_connected.c b/swad_connected.c index d82ed004..3e1d5ddb 100644 --- a/swad_connected.c +++ b/swad_connected.c @@ -174,10 +174,13 @@ void Con_ShowGlobalConnectedUsrs (void) /***** Number of sessions *****/ /* Link to view more details about connected users */ + /* Frm_BeginFormUnique (ActLstCon); // Must be unique because // the list of connected users // is dynamically updated via AJAX - HTM_BUTTON_Submit_Begin (Txt_Connected_users,"class=\"BT_LINK\""); + */ + Frm_BeginForm (ActLstCon); + HTM_BUTTON_Submit_Begin (Txt_Connected_users,"class=\"BT_LINK\""); /* Write total number of sessions */ HTM_TxtF ("%u %s",Gbl.Session.NumSessions, @@ -326,9 +329,12 @@ void Con_ShowConnectedUsrsBelongingToCurrentCrs (void) /***** Number of connected users who belong to course *****/ /* Link to view more details about connected users */ + /* Frm_BeginFormUnique (ActLstCon); // Must be unique because // the list of connected users // is dynamically updated via AJAX + */ + Frm_BeginForm (ActLstCon); HTM_BUTTON_Submit_Begin (Txt_Connected_users,"class=\"BT_LINK\""); Str_Copy (CourseName,Gbl.Hierarchy.Crs.ShrtName,sizeof (CourseName) - 1); Con_GetNumConnectedWithARoleBelongingToCurrentScope (Rol_UNK,&Usrs); @@ -414,9 +420,12 @@ static void Con_ShowConnectedUsrsWithARoleBelongingToCurrentCrsOnRightColumn (Ro { HTM_TR_Begin (NULL); HTM_TD_Begin ("colspan=\"3\" class=\"CM\""); + /* Frm_BeginFormUnique (ActLstCon); // Must be unique because // the list of connected users // is dynamically updated via AJAX + */ + Frm_BeginForm (ActLstCon); Sco_PutParamScope ("ScopeCon",HieLvl_CRS); HTM_INPUT_IMAGE (Cfg_URL_ICON_PUBLIC,"ellipsis-h.svg", Txt_Connected_users, @@ -604,12 +613,14 @@ static void Con_WriteRowConnectedUsrOnRightColumn (Rol_Role_t Role) ClassTxt = (Gbl.Usrs.Connected.Lst[Gbl.Usrs.Connected.NumUsr].ThisCrs) ? "CON_NAME_NARROW CON_CRS" : "CON_NAME_NARROW CON_NO_CRS"; HTM_TD_Begin ("class=\"%s %s\"",ClassTxt,The_GetColorRows ()); - // The form must be unique because - // the list of connected users - // is dynamically updated via AJAX if (!NextAction[Role]) Err_WrongRoleExit (); - Frm_BeginFormUnique (NextAction[Role]); + /* + Frm_BeginFormUnique (NextAction[Role]); // The form must be unique because + // the list of connected users + // is dynamically updated via AJAX + */ + Frm_BeginForm (NextAction[Role]); Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod); HTM_DIV_Begin ("class=\"CON_NAME_NARROW\""); // Limited width diff --git a/swad_form.c b/swad_form.c index 3ec47f51..c9c6fee8 100644 --- a/swad_form.c +++ b/swad_form.c @@ -80,7 +80,7 @@ void Frm_BeginFormAnchorOnSubmit (Act_Action_t NextAction,const char *Anchor,con snprintf (Gbl.Form.Id,sizeof (Gbl.Form.Id),"form_%d",Gbl.Form.Num); Frm_BeginFormInternal (NextAction,true,Gbl.Form.Id,Anchor,OnSubmit); // Do put now parameter location (if no open session) } - +/* void Frm_BeginFormUnique (Act_Action_t NextAction) { Frm_BeginFormUniqueAnchor (NextAction,NULL); @@ -101,7 +101,7 @@ void Frm_BeginFormUniqueAnchorOnSubmit (Act_Action_t NextAction,const char *Anch Gbl.UniqueNameEncrypted,Gbl.Form.Num); Frm_BeginFormInternal (NextAction,true,Gbl.Form.UniqueId,Anchor,OnSubmit); // Do put now parameter location (if no open session) } - +*/ void Frm_BeginFormId (Act_Action_t NextAction,const char *Id) { Gbl.Form.Num++; // Initialized to -1. The first time it is incremented, it will be equal to 0 diff --git a/swad_form.h b/swad_form.h index 5577af8a..d9b3b98d 100644 --- a/swad_form.h +++ b/swad_form.h @@ -50,10 +50,10 @@ void Frm_BeginFormGoTo (Act_Action_t NextAction); void Frm_BeginForm (Act_Action_t NextAction); void Frm_BeginFormOnSubmit (Act_Action_t NextAction,const char *OnSubmit); void Frm_BeginFormAnchorOnSubmit (Act_Action_t NextAction,const char *Anchor,const char *OnSubmit); -void Frm_BeginFormUnique (Act_Action_t NextAction); +// void Frm_BeginFormUnique (Act_Action_t NextAction); void Frm_BeginFormAnchor (Act_Action_t NextAction,const char *Anchor); -void Frm_BeginFormUniqueAnchor (Act_Action_t NextAction,const char *Anchor); -void Frm_BeginFormUniqueAnchorOnSubmit (Act_Action_t NextAction,const char *Anchor,const char *OnSubmit); +// void Frm_BeginFormUniqueAnchor (Act_Action_t NextAction,const char *Anchor); +// void Frm_BeginFormUniqueAnchorOnSubmit (Act_Action_t NextAction,const char *Anchor,const char *OnSubmit); void Frm_BeginFormId (Act_Action_t NextAction,const char *Id); void Frm_BeginFormNoAction (void); void Frm_SetParamsForm (char ParamsStr[Frm_MAX_BYTES_PARAMS_STR],Act_Action_t NextAction, diff --git a/swad_global.h b/swad_global.h index 68b5a030..785f5976 100644 --- a/swad_global.h +++ b/swad_global.h @@ -79,7 +79,7 @@ struct Globals { int Num; // Number of form, used in form submit links char Id[32]; // Identifier string used in forms - char UniqueId[32 + Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64 + 10 + 1]; // Unique identifier string used in forms + // char UniqueId[32 + Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64 + 10 + 1]; // Unique identifier string used in forms bool Inside; // Set to true inside a form to avoid nested forms } Form; struct diff --git a/swad_photo.c b/swad_photo.c index 568bf88f..e3250204 100644 --- a/swad_photo.c +++ b/swad_photo.c @@ -1263,8 +1263,9 @@ void Pho_ShowUsrPhoto (const struct Usr_Data *UsrDat,const char *PhotoURL, if (PutLinkToPublicProfile) { if (FormUnique) - Frm_BeginFormUnique (ActSeeOthPubPrf); - else + // Frm_BeginFormUnique (ActSeeOthPubPrf); + Frm_BeginForm (ActSeeOthPubPrf); + else Frm_BeginForm (ActSeeOthPubPrf); Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod); HTM_BUTTON_Submit_Begin (NULL,"class=\"BT_LINK\""); diff --git a/swad_timeline_comment.c b/swad_timeline_comment.c index 4f173ba1..00ac1fc8 100644 --- a/swad_timeline_comment.c +++ b/swad_timeline_comment.c @@ -617,7 +617,8 @@ static void TmlCom_WriteAuthorName (const struct Usr_Data *UsrDat) // Author /***** Show user's name inside form to go to user's public profile *****/ /* Begin form */ - Frm_BeginFormUnique (ActSeeOthPubPrf); + // Frm_BeginFormUnique (ActSeeOthPubPrf); + Frm_BeginForm (ActSeeOthPubPrf); Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod); /* Author's name */ diff --git a/swad_timeline_form.c b/swad_timeline_form.c index 53919dfe..d32ffb50 100644 --- a/swad_timeline_form.c +++ b/swad_timeline_form.c @@ -224,7 +224,8 @@ void TmlFrm_FormFavSha (const struct Tml_Form *Form) ParamStr, Gbl.Usrs.Other.UsrDat.EnUsrCod) < 0) Err_NotEnoughMemoryExit (); - Frm_BeginFormUniqueAnchorOnSubmit (ActUnk,"timeline",OnSubmit); + // Frm_BeginFormUniqueAnchorOnSubmit (ActUnk,"timeline",OnSubmit); + Frm_BeginFormAnchorOnSubmit (ActUnk,"timeline",OnSubmit); free (OnSubmit); Ico_PutIconLink (Form->Icon,Form->Color, TmlFrm_ActionUsr[Form->Action]); @@ -238,7 +239,8 @@ void TmlFrm_FormFavSha (const struct Tml_Form *Form) Gbl.Session.Id, ParamStr) < 0) Err_NotEnoughMemoryExit (); - Frm_BeginFormUniqueAnchorOnSubmit (ActUnk,NULL,OnSubmit); + // Frm_BeginFormUniqueAnchorOnSubmit (ActUnk,NULL,OnSubmit); + Frm_BeginFormAnchorOnSubmit (ActUnk,NULL,OnSubmit); free (OnSubmit); Ico_PutIconLink (Form->Icon,Form->Color, TmlFrm_ActionGbl[Form->Action]); @@ -299,7 +301,8 @@ void TmlFrm_FormToShowHiddenComms (long NotCod, Err_NotEnoughMemoryExit (); Anchor = NULL; } - Frm_BeginFormUniqueAnchorOnSubmit (ActUnk,Anchor,OnSubmit); + // Frm_BeginFormUniqueAnchorOnSubmit (ActUnk,Anchor,OnSubmit); + Frm_BeginFormAnchorOnSubmit (ActUnk,Anchor,OnSubmit); free (OnSubmit); /* Put icon and text with link to show the first hidden comments */ diff --git a/swad_timeline_note.c b/swad_timeline_note.c index d9025d5b..085f4dd0 100644 --- a/swad_timeline_note.c +++ b/swad_timeline_note.c @@ -352,7 +352,8 @@ void TmlNot_WriteAuthorName (const struct Usr_Data *UsrDat, /***** Show user's name inside form to go to user's public profile *****/ /* Begin form */ - Frm_BeginFormUnique (ActSeeOthPubPrf); + // Frm_BeginFormUnique (ActSeeOthPubPrf); + Frm_BeginForm (ActSeeOthPubPrf); Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod); /* Author's name */ @@ -623,36 +624,42 @@ static void TmlNot_PutFormGoToAction (const struct TmlNot_Note *Not, { case TmlNot_INS_DOC_PUB_FILE: case TmlNot_INS_SHA_PUB_FILE: - Frm_BeginFormUnique (Tml_DefaultActions[Not->Type]); + // Frm_BeginFormUnique (Tml_DefaultActions[Not->Type]); + Frm_BeginForm (Tml_DefaultActions[Not->Type]); Brw_PutHiddenParamFilCod (Not->Cod); if (Not->HieCod != Gbl.Hierarchy.Ins.InsCod) // Not the current institution Ins_PutParamInsCod (Not->HieCod); // Go to another institution break; case TmlNot_CTR_DOC_PUB_FILE: case TmlNot_CTR_SHA_PUB_FILE: - Frm_BeginFormUnique (Tml_DefaultActions[Not->Type]); + // Frm_BeginFormUnique (Tml_DefaultActions[Not->Type]); + Frm_BeginForm (Tml_DefaultActions[Not->Type]); Brw_PutHiddenParamFilCod (Not->Cod); if (Not->HieCod != Gbl.Hierarchy.Ctr.CtrCod) // Not the current center Ctr_PutParamCtrCod (Not->HieCod); // Go to another center break; case TmlNot_DEG_DOC_PUB_FILE: case TmlNot_DEG_SHA_PUB_FILE: - Frm_BeginFormUnique (Tml_DefaultActions[Not->Type]); + // Frm_BeginFormUnique (Tml_DefaultActions[Not->Type]); + Frm_BeginForm (Tml_DefaultActions[Not->Type]); Brw_PutHiddenParamFilCod (Not->Cod); if (Not->HieCod != Gbl.Hierarchy.Deg.DegCod) // Not the current degree Deg_PutParamDegCod (Not->HieCod); // Go to another degree break; case TmlNot_CRS_DOC_PUB_FILE: case TmlNot_CRS_SHA_PUB_FILE: - Frm_BeginFormUnique (Tml_DefaultActions[Not->Type]); + // Frm_BeginFormUnique (Tml_DefaultActions[Not->Type]); + Frm_BeginForm (Tml_DefaultActions[Not->Type]); Brw_PutHiddenParamFilCod (Not->Cod); if (Not->HieCod != Gbl.Hierarchy.Crs.CrsCod) // Not the current course Crs_PutParamCrsCod (Not->HieCod); // Go to another course break; case TmlNot_CALL_FOR_EXAM: Frm_SetAnchorStr (Not->Cod,&Anchor); - Frm_BeginFormUniqueAnchor (Tml_DefaultActions[Not->Type], - Anchor); // Locate on this specific exam + // Frm_BeginFormUniqueAnchor (Tml_DefaultActions[Not->Type], + // Anchor); // Locate on this specific exam + Frm_BeginFormAnchor (Tml_DefaultActions[Not->Type], + Anchor); // Locate on this specific exam Frm_FreeAnchorStr (Anchor); Cfe_PutHiddenParamExaCod (Not->Cod); if (Not->HieCod != Gbl.Hierarchy.Crs.CrsCod) // Not the current course @@ -661,7 +668,8 @@ static void TmlNot_PutFormGoToAction (const struct TmlNot_Note *Not, case TmlNot_POST: // Not applicable return; case TmlNot_FORUM_POST: - Frm_BeginFormUnique (For_ActionsSeeFor[Forums->Forum.Type]); + // Frm_BeginFormUnique (For_ActionsSeeFor[Forums->Forum.Type]); + Frm_BeginForm (For_ActionsSeeFor[Forums->Forum.Type]); For_PutAllHiddenParamsForum (1, // Page of threads = first 1, // Page of posts = first Forums->ForumSet, @@ -674,8 +682,9 @@ static void TmlNot_PutFormGoToAction (const struct TmlNot_Note *Not, break; case TmlNot_NOTICE: Frm_SetAnchorStr (Not->Cod,&Anchor); - Frm_BeginFormUniqueAnchor (Tml_DefaultActions[Not->Type], - Anchor); + // Frm_BeginFormUniqueAnchor (Tml_DefaultActions[Not->Type], + // Anchor); + Frm_BeginFormAnchor (Tml_DefaultActions[Not->Type],Anchor); Frm_FreeAnchorStr (Anchor); Not_PutHiddenParamNotCod (Not->Cod); if (Not->HieCod != Gbl.Hierarchy.Crs.CrsCod) // Not the current course