Version 22.48: Oct 15, 2022 Code optimization related to nick links.

This commit is contained in:
acanas 2022-10-15 15:12:40 +02:00
parent 3263490ff1
commit 62fc35435e
13 changed files with 98 additions and 66 deletions

View File

@ -113,6 +113,40 @@ a:hover /* Default ==> underlined */
text-decoration:underline; opacity:1;
}
.NICK_WHITE,
.NICK_GREY,
.NICK_PURPLE,
.NICK_BLUE,
.NICK_YELLOW,
.NICK_PINK
{
background:transparent;
border:none;
padding:0;
font:inherit;
color:#4d88a1;
text-decoration:none;
}
.NICK_DARK
{
background:transparent;
border:none;
padding:0;
font:inherit;
color:#afc4cc;
}
.NICK_WHITE:hover,
.NICK_GREY:hover,
.NICK_PURPLE:hover,
.NICK_BLUE:hover,
.NICK_YELLOW:hover,
.NICK_PINK:hover,
.NICK_DARK:hover
{
cursor:pointer;
text-decoration:underline;
}
/****************** Layout (the whole page with a background) ****************/
#whole_page
{

View File

@ -1486,10 +1486,6 @@ void HTM_BUTTON_Submit_Begin (const char *Title,const char *fmt,...)
free (Attr);
}
}
/*
if (OnSubmit) // JavaScript function to be called before submitting the form
if (OnSubmit[0])
HTM_TxtF (" onsubmit=\"%s;\"",OnSubmit); */
HTM_Txt (">");
HTM_BUTTON_NestingLevel++;

View File

@ -137,11 +137,10 @@ The web site of <a href="https://openswad.org/?usr=@rms">@rms</a> is <a href="ht
/*
<form id="form_z7FY4oFr-yot9R9xRVwDhIntnod3geLj36nyQ6jlJJs_53"
action="https://localhost/swad/es" method="post">
<form action="https://localhost/swad/es" method="post">
<input type="hidden" name="ses" value="2jb9CGhIJ81_qhDyeQ6MWDFKQ5ZaA_F68tq22ZAjYww">
<input type="hidden" name="usr" value="@acanas">
<a href="" onclick="document.getElementById('form_z7FY4oFr-yot9R9xRVwDhIntnod3geLj36nyQ6jlJJs_53').submit();return false;">
<a href="" onclick="this.closest('form').submit();return false;">
@acanas
</a>
</form>
@ -554,8 +553,8 @@ static ALn_LinkType_t ALn_CheckNickname (char **PtrSrc,char PrevCh,
/***** Store second part of anchor *****/
if (asprintf (&(*Link)->NickAnchor[1].Str,
"\">"
"<a href=\"\""
" onclick=\"this.closest('form').submit();return false;\">") < 0)
"<button type=\"submit\" class=\"NICK_%s\">",
The_GetSuffix ()) < 0)
Err_NotEnoughMemoryExit ();
(*Link)->NickAnchor[1].Len = strlen ((*Link)->NickAnchor[1].Str);
@ -567,7 +566,10 @@ static ALn_LinkType_t ALn_CheckNickname (char **PtrSrc,char PrevCh,
&CaptionStr,
&ImgStr);
if (asprintf (&(*Link)->NickAnchor[2].Str,
"</a></form>%s%s",
"</button>"
"</form>"
"%s"
"%s",
CaptionStr,
ImgStr) < 0)
Err_NotEnoughMemoryExit ();

View File

@ -6890,7 +6890,6 @@ static void Brw_PutFormToUploadFilesUsingDropzone (const char *FileNameToShow)
/***** Form to upload files using the library Dropzone.js *****/
// Use min-height:125px; or other number to stablish the height?
Gbl.Form.Num++;
HTM_TxtF ("<form method=\"post\" action=\"%s/%s\""
" class=\"dropzone\""
" enctype=\"multipart/form-data\""

View File

@ -606,10 +606,12 @@ 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.47.1 (2022-10-15)"
#define CSS_FILE "swad22.46.css"
#define Log_PLATFORM_VERSION "SWAD 22.48 (2022-10-15)"
#define CSS_FILE "swad22.48.css"
#define JS_FILE "swad21.100.js"
/*
Version 22.48: Oct 15, 2022 Code optimization related to nick links. (333157 lines)
Version 22.47.2: Oct 15, 2022 Code optimization related to forms. (333124 lines)
Version 22.47.1: Oct 15, 2022 Removed unused code. (333126 lines)
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)

View File

@ -676,7 +676,7 @@ static void ExaPrn_ShowTableWithQstsToFill (struct Exa_Exams *Exams,
HTM_TABLE_End ();
/***** Form to end/close this exam print *****/
Frm_BeginFormId (ActEndExaPrn,"finished");
Frm_BeginForm (ActEndExaPrn);
ExaSes_PutParamsEdit (Exams);
Btn_PutCreateButton (Txt_I_have_finished);
Frm_EndForm ();

View File

@ -54,9 +54,7 @@ static void Frm_BeginFormInternal (Act_Action_t NextAction,bool PutParameterLoca
void Frm_BeginFormGoTo (Act_Action_t NextAction)
{
Gbl.Form.Num++; // Initialized to -1. The first time it is incremented, it will be equal to 0
snprintf (Gbl.Form.Id,sizeof (Gbl.Form.Id),"form_%d",Gbl.Form.Num);
Frm_BeginFormInternal (NextAction,false,Gbl.Form.Id,NULL,NULL); // Do not put now parameter location
Frm_BeginFormInternal (NextAction,false,NULL,NULL,NULL); // Do not put now parameter location
}
void Frm_BeginForm (Act_Action_t NextAction)
@ -76,18 +74,14 @@ void Frm_BeginFormOnSubmit (Act_Action_t NextAction,const char *OnSubmit)
void Frm_BeginFormAnchorOnSubmit (Act_Action_t NextAction,const char *Anchor,const char *OnSubmit)
{
Gbl.Form.Num++; // Initialized to -1. The first time it is incremented, it will be equal to 0
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)
Frm_BeginFormInternal (NextAction,true,NULL,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
Frm_BeginFormInternal (NextAction,true,Id,NULL,NULL); // Do put now parameter location (if no open session)
}
// Id can not be NULL
static void Frm_BeginFormInternal (Act_Action_t NextAction,bool PutParameterLocationIfNoSesion,
const char *Id,const char *Anchor,const char *OnSubmit)
{
@ -103,7 +97,15 @@ static void Frm_BeginFormInternal (Act_Action_t NextAction,bool PutParameterLoca
if (Anchor)
if (Anchor[0])
HTM_TxtF ("#%s",Anchor);
HTM_TxtF ("\" id=\"%s\"",Id);
if (Id)
{
if (Id[0])
HTM_TxtF ("\" id=\"%s\"",Id);
else
HTM_Txt ("\"");
}
else
HTM_Txt ("\"");
if (OnSubmit)
if (OnSubmit[0])
HTM_TxtF (" onsubmit=\"%s\"",OnSubmit);

View File

@ -50,8 +50,8 @@ 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_BeginFormAnchor (Act_Action_t NextAction,const char *Anchor);
void Frm_BeginFormId (Act_Action_t NextAction,const char *Id);
void Frm_BeginFormAnchor (Act_Action_t NextAction,const char *Anchor);
void Frm_BeginFormNoAction (void);
void Frm_SetParamsForm (char ParamsStr[Frm_MAX_BYTES_PARAMS_STR],Act_Action_t NextAction,
bool PutParameterLocationIfNoSession);

View File

@ -106,7 +106,6 @@ void Gbl_InitializeGlobals (void)
Gbl.F.XML = NULL;
Gbl.F.Rep = NULL; // Report
Gbl.Form.Num = -1; // Number of form. It's increased by 1 at the begin of each form
Gbl.Form.Inside = false; // Set to true inside a form to avoid nested forms
Gbl.Box.Nested = -1; // -1 means no box open

View File

@ -77,8 +77,6 @@ struct Globals
pid_t PID; // PID of current process
struct
{
int Num; // Number of form, used in form submit links
char Id[32]; // Identifier string used in forms
bool Inside; // Set to true inside a form to avoid nested forms
} Form;
struct

View File

@ -202,7 +202,7 @@ static const char *Mch_GetClassBorder (unsigned NumRow);
static void Mch_PutParamNumOpt (unsigned NumOpt);
static unsigned Mch_GetParamNumOpt (void);
static void Mch_PutBigButton (Act_Action_t NextAction,const char *Id,
static void Mch_PutBigButton (Act_Action_t NextAction,
long MchCod,const char *Icon,const char *Txt);
static void Mch_PutBigButtonHidden (const char *Icon);
static void Mch_PutBigButtonClose (void);
@ -2536,7 +2536,7 @@ static void Mch_PutMatchControlButtons (const struct Mch_Match *Match)
break;
default:
/* Put button to go back */
Mch_PutBigButton (ActBckMch,"backward",Match->MchCod,
Mch_PutBigButton (ActBckMch,Match->MchCod,
Mch_ICON_PREVIOUS,Txt_Go_back);
break;
}
@ -2546,7 +2546,7 @@ static void Mch_PutMatchControlButtons (const struct Mch_Match *Match)
HTM_DIV_Begin ("class=\"MCH_BUTTON_CENTER_CONT\"");
if (Match->Status.Playing) // Match is being played
/* Put button to pause match */
Mch_PutBigButton (ActPlyPauMch,"play_pause",Match->MchCod,
Mch_PutBigButton (ActPlyPauMch,Match->MchCod,
Mch_ICON_PAUSE,Txt_Pause);
else // Match is paused, not being played
{
@ -2554,7 +2554,7 @@ static void Mch_PutMatchControlButtons (const struct Mch_Match *Match)
{
case Mch_START: // Match just started, before first question
/* Put button to start playing match */
Mch_PutBigButton (ActPlyPauMch,"play_pause",Match->MchCod,
Mch_PutBigButton (ActPlyPauMch,Match->MchCod,
Mch_ICON_PLAY,Txt_Start);
break;
case Mch_END: // Match over
@ -2563,7 +2563,7 @@ static void Mch_PutMatchControlButtons (const struct Mch_Match *Match)
break;
default:
/* Put button to resume match */
Mch_PutBigButton (ActPlyPauMch,"play_pause",Match->MchCod,
Mch_PutBigButton (ActPlyPauMch,Match->MchCod,
Mch_ICON_PLAY,Txt_Resume);
}
}
@ -2576,7 +2576,7 @@ static void Mch_PutMatchControlButtons (const struct Mch_Match *Match)
Mch_PutBigButtonClose ();
else // Match not over
/* Put button to show answers */
Mch_PutBigButton (ActFwdMch,"forward",Match->MchCod,
Mch_PutBigButton (ActFwdMch,Match->MchCod,
Mch_ICON_NEXT,Txt_Go_forward);
HTM_DIV_End ();
@ -3261,11 +3261,11 @@ static unsigned Mch_GetParamNumOpt (void)
/*********************** Put a big button to do action ***********************/
/*****************************************************************************/
static void Mch_PutBigButton (Act_Action_t NextAction,const char *Id,
static void Mch_PutBigButton (Act_Action_t NextAction,
long MchCod,const char *Icon,const char *Txt)
{
/***** Begin form *****/
Frm_BeginFormId (NextAction,Id);
Frm_BeginForm (NextAction);
Mch_PutParamMchCod (MchCod);
/***** Put icon with link *****/

View File

@ -1682,7 +1682,7 @@ void Ntf_WriteNumberOfNewNtfs (void)
NumNewNtfs = Ntf_DB_GetNumMyNewUnseenNtfs ();
/***** Begin form *****/
Frm_BeginFormId (ActSeeNewNtf,"form_ntf");
Frm_BeginForm (ActSeeNewNtf);
/***** Begin link *****/
HTM_BUTTON_Submit_Begin (Txt_See_notifications,"class=\"BT_LINK\"");

View File

@ -577,12 +577,13 @@ static bool Pho_ReceivePhotoAndDetectFaces (bool ItsMe,const struct Usr_Data *Us
bool WrongType = false;
char Command[256 + PATH_MAX]; // Command to call the program of preprocessing of photos
int ReturnCode;
int NumLastForm = 0; // Initialized to avoid warning
char FormId[32];
unsigned NumFacesTotal = 0;
unsigned NumFacesGreen = 0;
unsigned NumFacesRed = 0;
unsigned NumFace;
struct
{
unsigned Green;
unsigned Red;
unsigned Total;
} NumFaces;
unsigned X;
unsigned Y;
unsigned Radius;
@ -661,6 +662,7 @@ static bool Pho_ReceivePhotoAndDetectFaces (bool ItsMe,const struct Usr_Data *Us
/***** Write message depending on return code *****/
ReturnCode = WEXITSTATUS(ReturnCode);
NumFaces.Green = NumFaces.Red = 0;
switch (ReturnCode)
{
case 0: // Faces detected
@ -671,32 +673,29 @@ static bool Pho_ReceivePhotoAndDetectFaces (bool ItsMe,const struct Usr_Data *Us
Err_ShowErrorAndExit ("Can not read text file with coordinates of detected faces.");
/***** Read file with coordinates for image map and compute the number of faces *****/
NumLastForm = Gbl.Form.Num;
while (!feof (FileTxtMap))
while (!feof (FileTxtMap))
{
if (fscanf (FileTxtMap,"%u %u %u %u %s\n",&X,&Y,&Radius,&BackgroundCode,StrFileName) != 5) // Example of StrFileName = "4924a838630e_016"
break;
if (BackgroundCode == 1)
{
NumFacesGreen++;
snprintf (FormId,sizeof (FormId),"photo_%u",++NumFaces.Green);
if (ItsMe)
Frm_BeginForm (ActUpdMyPho);
Frm_BeginFormId (ActUpdMyPho,FormId);
else
{
Frm_BeginForm (NextAction[Gbl.Usrs.Other.UsrDat.Roles.InCurrentCrs]);
Frm_BeginFormId (NextAction[Gbl.Usrs.Other.UsrDat.Roles.InCurrentCrs],FormId);
Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
}
Par_PutHiddenParamString (NULL,"FileName",StrFileName);
Frm_EndForm ();
}
else
NumFacesRed++;
NumFaces.Red++;
}
NumFacesTotal = NumFacesGreen + NumFacesRed;
break;
case 1: // No faces detected
NumFacesTotal = NumFacesGreen = NumFacesRed = 0;
break;
default: // Error
snprintf (ErrorTxt,sizeof (ErrorTxt),
@ -706,53 +705,54 @@ static bool Pho_ReceivePhotoAndDetectFaces (bool ItsMe,const struct Usr_Data *Us
Err_ShowErrorAndExit (ErrorTxt);
break;
}
NumFaces.Total = NumFaces.Green + NumFaces.Red;
/***** Begin alert to the user about the number of faces detected in the image*****/
if (NumFacesTotal == 0)
if (NumFaces.Total == 0)
Ale_ShowAlertAndButton1 (Ale_WARNING,Txt_Could_not_detect_any_face_in_front_position_);
else if (NumFacesTotal == 1)
else if (NumFaces.Total == 1)
{
if (NumFacesGreen == 1)
if (NumFaces.Green == 1)
Ale_ShowAlertAndButton1 (Ale_SUCCESS,Txt_A_face_marked_in_green_has_been_detected_);
else
Ale_ShowAlertAndButton1 (Ale_WARNING,Txt_A_face_marked_in_red_has_been_detected_);
}
else // NumFacesTotal > 1
{
if (NumFacesRed == 0)
if (NumFaces.Red == 0)
Ale_ShowAlertAndButton1 (Ale_SUCCESS,Txt_X_faces_marked_in_green_have_been_detected_,
NumFacesGreen);
else if (NumFacesGreen == 0)
NumFaces.Green);
else if (NumFaces.Green == 0)
Ale_ShowAlertAndButton1 (Ale_WARNING,Txt_X_faces_marked_in_red_have_been_detected_,
NumFacesRed);
else // NumFacesGreen > 0
NumFaces.Red);
else // NumFaces.Green > 0
{
if (NumFacesGreen == 1)
if (NumFaces.Green == 1)
Ale_ShowAlertAndButton1 (Ale_SUCCESS,Txt_X_faces_have_been_detected_in_front_position_1_Z_,
NumFacesTotal,NumFacesRed);
NumFaces.Total,NumFaces.Red);
else
Ale_ShowAlertAndButton1 (Ale_SUCCESS,Txt_X_faces_have_been_detected_in_front_position_Y_Z_,
NumFacesTotal,NumFacesGreen,NumFacesRed);
NumFaces.Total,NumFaces.Green,NumFaces.Red);
}
}
/***** Create map *****/
HTM_Txt ("<map name=\"faces_map\">\n");
if (NumFacesTotal)
if (NumFaces.Total)
{
/***** Read again the file with coordinates and create area shapes *****/
rewind (FileTxtMap);
for (NumFace = 0; !feof (FileTxtMap);)
NumFaces.Green = 0;
while (!feof (FileTxtMap))
{
if (fscanf (FileTxtMap,"%u %u %u %u %s\n",&X,&Y,&Radius,&BackgroundCode,StrFileName) != 5)
break;
if (BackgroundCode == 1)
{
NumFace++;
snprintf (FormId,sizeof (FormId),"form_%d",NumLastForm + NumFace);
snprintf (FormId,sizeof (FormId),"photo_%u",++NumFaces.Green);
HTM_TxtF ("<area shape=\"circle\""
" href=\"\""
" onclick=\"javascript:document.getElementById('%s').submit();return false;\""
" onclick=\"document.getElementById('%s').submit();return false;\""
" coords=\"%u,%u,%u\">\n",
FormId,X,Y,Radius);
}
@ -778,7 +778,7 @@ static bool Pho_ReceivePhotoAndDetectFaces (bool ItsMe,const struct Usr_Data *Us
Btn_NO_BUTTON,NULL);
/***** Button to send another photo *****/
return (NumFacesGreen != 0);
return (NumFaces.Green != 0);
}
/*****************************************************************************/