From 7fcf9f48ed8aa1875bd7c17ba34bb90065d71c60 Mon Sep 17 00:00:00 2001 From: acanas Date: Sun, 29 Oct 2023 22:20:07 +0100 Subject: [PATCH] Version 23.42: Oct 29, 2023 Code refactoring in view/edit/print. --- swad_API.c | 2 +- swad_announcement.c | 79 +++++--- swad_attendance.c | 2 +- swad_browser.c | 16 +- swad_call_for_exam.c | 2 +- swad_changelog.h | 3 +- swad_enrolment.c | 3 +- swad_layout.h | 2 +- swad_password.c | 3 +- swad_profile.c | 12 +- swad_program_resource.c | 2 +- swad_question.c | 5 +- swad_record.c | 340 +++++++++++++++++++------------- swad_survey.c | 6 +- swad_syllabus.h | 2 +- swad_test_print.c | 2 +- swad_view_edit.h => swad_view.h | 0 17 files changed, 288 insertions(+), 193 deletions(-) rename swad_view_edit.h => swad_view.h (100%) diff --git a/swad_API.c b/swad_API.c index 9876bb69..cafd609c 100644 --- a/swad_API.c +++ b/swad_API.c @@ -3952,7 +3952,7 @@ int swad__getTrivialQuestion (struct soap *soap, { /***** Get answer from database *****/ NumAnss = Qst_DB_GetAnswersData (&mysql_res,QstCod, - false); // Don't shuffle + false); // Don't shuffle getTrivialQuestionOut->answersArray.__size = (int) NumAnss; diff --git a/swad_announcement.c b/swad_announcement.c index 944e2c50..fd543779 100644 --- a/swad_announcement.c +++ b/swad_announcement.c @@ -41,6 +41,22 @@ #include "swad_parameter_code.h" #include "swad_role.h" +/*****************************************************************************/ +/******************************* Private types *******************************/ +/*****************************************************************************/ + +typedef enum + { + Ann_DONT_SHOW_ALL = 0, + Ann_SHOW_ALL = 1, + } Ann_ShowAll_t; + +typedef enum + { + Ann_I_CAN_NOT_EDIT = 0, + Ann_I_CAN_EDIT = 1, + } Ann_ICanEdit_t; + /*****************************************************************************/ /************** External global variables from others modules ****************/ /*****************************************************************************/ @@ -57,8 +73,8 @@ static void Ann_GetAnnouncementDataFromRow (MYSQL_RES *mysql_res, struct Ann_Announcement *Announcement); static void Ann_DrawAnAnnouncement (struct Ann_Announcement *Announcement, - bool ShowAllAnnouncements, - bool ICanEdit); + Ann_ShowAll_t ShowAll, + Ann_ICanEdit_t ICanEdit); static void Ann_PutParAnnCod (void *AnnCod); static void Ann_PutSubjectMessage (const char *Field,const char *Label, unsigned Rows); @@ -76,7 +92,8 @@ void Ann_ShowAllAnnouncements (void) struct Ann_Announcement Announcement; unsigned NumAnnouncements; unsigned NumAnn; - bool ICanEdit = (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM); + Ann_ICanEdit_t ICanEdit = (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM) ? Ann_I_CAN_EDIT : + Ann_I_CAN_NOT_EDIT; /***** Get announcements from database *****/ if (ICanEdit) @@ -108,7 +125,7 @@ void Ann_ShowAllAnnouncements (void) /* Show the announcement */ Ann_DrawAnAnnouncement (&Announcement, - true, // Show all announcements + Ann_SHOW_ALL, // Show all announcements ICanEdit); } @@ -157,8 +174,8 @@ void Ann_ShowMyAnnouncementsNotMarkedAsSeen (void) /* Show the announcement */ Ann_DrawAnAnnouncement (&Announcement, - false, // Don't show all announcements - false); // I can not edit + Ann_DONT_SHOW_ALL, // Don't show all announcements + Ann_I_CAN_NOT_EDIT); // I can not edit } HTM_DIV_End (); @@ -206,8 +223,8 @@ static void Ann_GetAnnouncementDataFromRow (MYSQL_RES *mysql_res, /*****************************************************************************/ static void Ann_DrawAnAnnouncement (struct Ann_Announcement *Announcement, - bool ShowAllAnnouncements, - bool ICanEdit) + Ann_ShowAll_t ShowAll, + Ann_ICanEdit_t ICanEdit) { extern const char *Txt_Users; extern const char *Txt_ROLES_PLURAL_abc[Rol_NUM_ROLES][Usr_NUM_SEXS]; @@ -228,7 +245,7 @@ static void Ann_DrawAnAnnouncement (struct Ann_Announcement *Announcement, /***** Begin yellow note *****/ HTM_DIV_Begin ("class=\"%s\"",ContainerClass[Announcement->Status]); - if (ICanEdit) + if (ICanEdit == Ann_I_CAN_EDIT) { /***** Icon to remove announcement *****/ Ico_PutContextualIconToRemove (ActRemAnn,NULL, @@ -257,27 +274,30 @@ static void Ann_DrawAnAnnouncement (struct Ann_Announcement *Announcement, /* Begin container for foot */ HTM_DIV_Begin ("class=\"NOTICE_USERS\""); - if (ShowAllAnnouncements) + switch (ShowAll) { - /* Users' roles who can view this announcement */ - HTM_TxtColon (Txt_Users); - for (Role = Rol_UNK, SomeRolesAreSelected = false; - Role <= Rol_TCH; - Role++) - if (Announcement->Roles & (1 << Role)) - { - if (SomeRolesAreSelected) - HTM_Comma (); - SomeRolesAreSelected = true; - HTM_TxtF (" %s",Txt_ROLES_PLURAL_abc[Role][Usr_SEX_UNKNOWN]); - } + case Ann_DONT_SHOW_ALL: + /***** Put form to mark announcement as seen *****/ + Lay_PutContextualLinkIconText (ActAnnSee,NULL, + Ann_PutParAnnCod,&Announcement->AnnCod, + "times.svg",Ico_BLACK, + Txt_Do_not_show_again,NULL); + break; + case Ann_SHOW_ALL: + /* Users' roles who can view this announcement */ + HTM_TxtColon (Txt_Users); + for (Role = Rol_UNK, SomeRolesAreSelected = false; + Role <= Rol_TCH; + Role++) + if (Announcement->Roles & (1 << Role)) + { + if (SomeRolesAreSelected) + HTM_Comma (); + SomeRolesAreSelected = true; + HTM_TxtF (" %s",Txt_ROLES_PLURAL_abc[Role][Usr_SEX_UNKNOWN]); + } + break; } - else - /***** Put form to mark announcement as seen *****/ - Lay_PutContextualLinkIconText (ActAnnSee,NULL, - Ann_PutParAnnCod,&Announcement->AnnCod, - "times.svg",Ico_BLACK, - Txt_Do_not_show_again,NULL); /* End container for foot */ HTM_DIV_End (); @@ -335,7 +355,8 @@ void Ann_ShowFormAnnouncement (void) 1 << Rol_STD | 1 << Rol_NET | 1 << Rol_TCH, - false,false); + false, + HTM_DONT_SUBMIT_ON_CHANGE); HTM_TD_End (); HTM_TR_End (); diff --git a/swad_attendance.c b/swad_attendance.c index 132d3af7..23f1c6fd 100644 --- a/swad_attendance.c +++ b/swad_attendance.c @@ -1432,7 +1432,7 @@ static void Att_ShowEvent (struct Att_Events *Events) Att_PutIconsOneEvent,Events, Hlp_USERS_Attendance,Box_NOT_CLOSABLE,2); Att_ShowOneEventRow (Events, - true); // Show only this event + true); // Show only this event Box_BoxTableEnd (); switch (Gbl.Usrs.Me.Role.Logged) diff --git a/swad_browser.c b/swad_browser.c index a7b367e5..9a9dde22 100644 --- a/swad_browser.c +++ b/swad_browser.c @@ -4548,25 +4548,25 @@ static void Brw_PutIconFolder (unsigned Level, { /***** Visible icon with folder closed *****/ Brw_PutIconFolderWithPlus (FileBrowserId,RowId, - false, // Closed - false); // Visible + false, // Closed + HidVis_VISIBLE); // Visible /***** Hidden icon with folder open *****/ Brw_PutIconFolderWithPlus (FileBrowserId,RowId, - true, // Open - true); // Hidden + true, // Open + HidVis_HIDDEN); // Hidden } else { /***** Hidden icon with folder closed *****/ Brw_PutIconFolderWithPlus (FileBrowserId,RowId, - false, // Closed - true); // Hidden + false, // Closed + HidVis_HIDDEN); // Hidden /***** Visible icon with folder open *****/ Brw_PutIconFolderWithPlus (FileBrowserId,RowId, - true, // Open - false); // Visible + true, // Open + HidVis_VISIBLE); // Visible } } else // I can't create a new file or folder diff --git a/swad_call_for_exam.c b/swad_call_for_exam.c index cba23dfb..d1ce705d 100644 --- a/swad_call_for_exam.c +++ b/swad_call_for_exam.c @@ -154,7 +154,7 @@ void Cfe_PutFrmEditACallForExam (void) /***** Show call for exam *****/ Cfe_ShowCallForExam (&CallsForExams,ExaCod,Cfe_FORM_VIEW, - false); // Don't highlight + false); // Don't highlight /***** Free memory of the call for exam *****/ Cfe_FreeMemCallForExam (&CallsForExams); diff --git a/swad_changelog.h b/swad_changelog.h index ed4ac3c2..be700fd9 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -633,10 +633,11 @@ Me sale este error, no s "can npt create received message (duplicated entry '243218-2160773' for key 'UsrCod_MsgCod') */ -#define Log_PLATFORM_VERSION "SWAD 23.41.2 (2023-10-29)" +#define Log_PLATFORM_VERSION "SWAD 23.42 (2023-10-29)" #define CSS_FILE "swad23.35.1.css" #define JS_FILE "swad22.49.js" /* + Version 23.42: Oct 29, 2023 Code refactoring in view/edit/print. (335453 lines) Version 23.41.2: Oct 29, 2023 Code refactoring in class photo. (335361 lines) Version 23.41.1: Oct 29, 2023 Code refactoring in view/edit/print. (335361 lines) Version 23.41: Oct 29, 2023 Code refactoring in view/edit/print. (335359 lines) diff --git a/swad_enrolment.c b/swad_enrolment.c index 35c52b08..50fc4c4b 100644 --- a/swad_enrolment.c +++ b/swad_enrolment.c @@ -2170,7 +2170,8 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected) 1 << Rol_NET | 1 << Rol_TCH, RolesSelected, - false,true); + false, + HTM_SUBMIT_ON_CHANGE); HTM_TD_End (); HTM_TR_End (); diff --git a/swad_layout.h b/swad_layout.h index e1c09b47..db7190fb 100644 --- a/swad_layout.h +++ b/swad_layout.h @@ -29,7 +29,7 @@ #include "swad_action.h" #include "swad_icon.h" -#include "swad_view_edit.h" +#include "swad_view.h" /*****************************************************************************/ /****************************** Public constants *****************************/ diff --git a/swad_password.c b/swad_password.c index c8dc105a..2104102d 100644 --- a/swad_password.c +++ b/swad_password.c @@ -106,7 +106,8 @@ void Pwd_GetParUsrPwdLogin (void) bool Pwd_CheckCurrentPassword (void) { return (Gbl.Usrs.Me.UsrDat.Password[0] ? - !strcmp (Gbl.Usrs.Me.LoginEncryptedPassword,Gbl.Usrs.Me.UsrDat.Password) : true); + !strcmp (Gbl.Usrs.Me.LoginEncryptedPassword,Gbl.Usrs.Me.UsrDat.Password) : + true); } /*****************************************************************************/ diff --git a/swad_profile.c b/swad_profile.c index 22f72791..9b4e91de 100644 --- a/swad_profile.c +++ b/swad_profile.c @@ -974,7 +974,7 @@ static void Prf_GetFirstClickFromLogAndStoreAsUsrFigure (long UsrCod) if (Prf_DB_CheckIfUsrFiguresExists (UsrCod)) Prf_DB_UpdateFirstClickTimeUsr (UsrCod,UsrFigures.FirstClickTimeUTC); else // User entry does not exist - Prf_DB_CreateUsrFigures (UsrCod,&UsrFigures,false); + Prf_DB_CreateUsrFigures (UsrCod,&UsrFigures,Usr_OTHER); } } @@ -998,7 +998,7 @@ static void Prf_GetNumClicksAndStoreAsUsrFigure (long UsrCod) if (Prf_DB_CheckIfUsrFiguresExists (UsrCod)) Prf_DB_UpdateNumClicksUsr (UsrCod,UsrFigures.NumClicks); else // User entry does not exist - Prf_DB_CreateUsrFigures (UsrCod,&UsrFigures,false); + Prf_DB_CreateUsrFigures (UsrCod,&UsrFigures,Usr_OTHER); } } @@ -1022,7 +1022,7 @@ static void Prf_GetNumTimelinePubsAndStoreAsUsrFigure (long UsrCod) if (Prf_DB_CheckIfUsrFiguresExists (UsrCod)) Prf_DB_UpdateNumTimelinePubsUsr (UsrCod,UsrFigures.NumTimelinePubs); else // User entry does not exist - Prf_DB_CreateUsrFigures (UsrCod,&UsrFigures,false); + Prf_DB_CreateUsrFigures (UsrCod,&UsrFigures,Usr_OTHER); } } @@ -1046,7 +1046,7 @@ static void Prf_GetNumFileViewsAndStoreAsUsrFigure (long UsrCod) if (Prf_DB_CheckIfUsrFiguresExists (UsrCod)) Prf_DB_UpdateNumFileViewsUsr (UsrCod,UsrFigures.NumFileViews); else // User entry does not exist - Prf_DB_CreateUsrFigures (UsrCod,&UsrFigures,false); + Prf_DB_CreateUsrFigures (UsrCod,&UsrFigures,Usr_OTHER); } } @@ -1070,7 +1070,7 @@ static void Prf_GetNumForumPostsAndStoreAsUsrFigure (long UsrCod) if (Prf_DB_CheckIfUsrFiguresExists (UsrCod)) Prf_DB_UpdateNumForumPostsUsr (UsrCod,UsrFigures.NumForumPosts); else // User entry does not exist - Prf_DB_CreateUsrFigures (UsrCod,&UsrFigures,false); + Prf_DB_CreateUsrFigures (UsrCod,&UsrFigures,Usr_OTHER); } } @@ -1094,7 +1094,7 @@ static void Prf_GetNumMessagesSentAndStoreAsUsrFigure (long UsrCod) if (Prf_DB_CheckIfUsrFiguresExists (UsrCod)) Prf_DB_UpdateNumMessagesSentUsr (UsrCod,UsrFigures.NumMessagesSent); else // User entry does not exist - Prf_DB_CreateUsrFigures (UsrCod,&UsrFigures,false); + Prf_DB_CreateUsrFigures (UsrCod,&UsrFigures,Usr_OTHER); } } diff --git a/swad_program_resource.c b/swad_program_resource.c index bfd97162..94f8db6b 100644 --- a/swad_program_resource.c +++ b/swad_program_resource.c @@ -43,7 +43,7 @@ #include "swad_program.h" #include "swad_program_database.h" #include "swad_resource_database.h" -#include "swad_view_edit.h" +#include "swad_view.h" /*****************************************************************************/ /************** External global variables from others modules ****************/ diff --git a/swad_question.c b/swad_question.c index dc7e706c..68801476 100644 --- a/swad_question.c +++ b/swad_question.c @@ -574,7 +574,8 @@ void Qst_WriteQstStem (const char *Stem,const char *ClassStem,bool Visible) Str_Copy (StemRigorousHTML,Stem,StemLength); Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, - StemRigorousHTML,StemLength,false); + StemRigorousHTML,StemLength, + Str_DONT_REMOVE_SPACES); /* Write stem text */ HTM_Txt (StemRigorousHTML); @@ -2496,7 +2497,7 @@ bool Qst_GetQstDataByCod (struct Qst_Question *Question) /***** Get the answers from the database *****/ Question->Answer.NumOptions = Qst_DB_GetAnswersData (&mysql_res,Question->QstCod, - false); // Don't shuffle + false); // Don't shuffle /* row[0] AnsInd row[1] Answer diff --git a/swad_record.c b/swad_record.c index c68e4991..1847665e 100644 --- a/swad_record.c +++ b/swad_record.c @@ -147,14 +147,16 @@ static void Rec_ShowEmail (struct Usr_Data *UsrDat); static void Rec_ShowUsrIDs (struct Usr_Data *UsrDat,const char *Anchor); static void Rec_ShowRole (struct Usr_Data *UsrDat, Rec_SharedRecordViewType_t TypeOfView); -static void Rec_ShowSurname1 (struct Usr_Data *UsrDat,bool PutForm); -static void Rec_ShowSurname2 (struct Usr_Data *UsrDat,bool PutForm); -static void Rec_ShowFirstName (struct Usr_Data *UsrDat,bool PutForm); -static void Rec_ShowCountry (struct Usr_Data *UsrDat,bool PutForm); -static void Rec_ShowDateOfBirth (struct Usr_Data *UsrDat,bool ShowData,bool PutForm); -static void Rec_ShowPhone (struct Usr_Data *UsrDat,bool ShowData,bool PutForm, - unsigned NumPhone); -static void Rec_ShowComments (struct Usr_Data *UsrDat,bool ShowData,bool PutForm); +static void Rec_ShowSurname1 (struct Usr_Data *UsrDat,Vie_ViewType_t ViewType); +static void Rec_ShowSurname2 (struct Usr_Data *UsrDat,Vie_ViewType_t ViewType); +static void Rec_ShowFirstName (struct Usr_Data *UsrDat,Vie_ViewType_t ViewType); +static void Rec_ShowCountry (struct Usr_Data *UsrDat,Vie_ViewType_t ViewType); +static void Rec_ShowDateOfBirth (struct Usr_Data *UsrDat,bool ShowData, + Vie_ViewType_t ViewType); +static void Rec_ShowPhone (struct Usr_Data *UsrDat,bool ShowData, + Vie_ViewType_t ViewType,unsigned NumPhone); +static void Rec_ShowComments (struct Usr_Data *UsrDat,bool ShowData, + Vie_ViewType_t ViewType); static void Rec_ShowTeacherRows (struct Usr_Data *UsrDat,struct Hie_Node *Ins, bool ShowData); static void Rec_ShowInstitution (struct Hie_Node *Ins,bool ShowData); @@ -2028,7 +2030,7 @@ void Rec_ShowSharedUsrRecord (Rec_SharedRecordViewType_t TypeOfView, Usr_MeOrOther_t MeOrOther; bool IAmLoggedAsTeacherOrSysAdm; bool CountryForm; - bool ICanEdit; + Vie_ViewType_t ViewType; bool PutFormLinks; // Put links (forms) inside record card bool ShowData; bool ShowIDRows; @@ -2069,13 +2071,14 @@ void Rec_ShowSharedUsrRecord (Rec_SharedRecordViewType_t TypeOfView, { case Rec_SHA_MY_RECORD_FORM: case Rec_SHA_OTHER_NEW_USR_FORM: - ICanEdit = true; + ViewType = Vie_EDIT; break; case Rec_SHA_OTHER_EXISTING_USR_FORM: - ICanEdit = Usr_ICanChangeOtherUsrData (UsrDat); + ViewType = Usr_ICanChangeOtherUsrData (UsrDat) ? Vie_EDIT : + Vie_VIEW; break; default: // In other options, I can not edit user's data - ICanEdit = false; + ViewType = Vie_VIEW; break; } @@ -2200,27 +2203,27 @@ void Rec_ShowSharedUsrRecord (Rec_SharedRecordViewType_t TypeOfView, Rec_ShowRole (UsrDat,TypeOfView); /***** Name *****/ - Rec_ShowSurname1 (UsrDat,ICanEdit); - Rec_ShowSurname2 (UsrDat,ICanEdit); - Rec_ShowFirstName (UsrDat,ICanEdit); + Rec_ShowSurname1 (UsrDat,ViewType); + Rec_ShowSurname2 (UsrDat,ViewType); + Rec_ShowFirstName (UsrDat,ViewType); /***** Country *****/ if (CountryForm) - Rec_ShowCountry (UsrDat,ICanEdit); + Rec_ShowCountry (UsrDat,ViewType); } /***** Address rows *****/ if (ShowAddressRows) { /***** Date of birth *****/ - Rec_ShowDateOfBirth (UsrDat,ShowData,ICanEdit); + Rec_ShowDateOfBirth (UsrDat,ShowData,ViewType); /***** Phones *****/ - Rec_ShowPhone (UsrDat,ShowData,ICanEdit,0); - Rec_ShowPhone (UsrDat,ShowData,ICanEdit,1); + Rec_ShowPhone (UsrDat,ShowData,ViewType,0); + Rec_ShowPhone (UsrDat,ShowData,ViewType,1); /***** User's comments *****/ - Rec_ShowComments (UsrDat,ShowData,ICanEdit); + Rec_ShowComments (UsrDat,ShowData,ViewType); } /***** Teacher's rows *****/ @@ -3028,7 +3031,7 @@ static void Rec_ShowRole (struct Usr_Data *UsrDat, /*************************** Show user's surname 1 ***************************/ /*****************************************************************************/ -static void Rec_ShowSurname1 (struct Usr_Data *UsrDat,bool PutForm) +static void Rec_ShowSurname1 (struct Usr_Data *UsrDat,Vie_ViewType_t ViewType) { extern const char *Txt_Surname_1; char *Label; @@ -3036,31 +3039,46 @@ static void Rec_ShowSurname1 (struct Usr_Data *UsrDat,bool PutForm) HTM_TR_Begin (NULL); /* Label */ - if (PutForm) - { - if (asprintf (&Label,"%s*",Txt_Surname_1) < 0) - Err_NotEnoughMemoryExit (); - Frm_LabelColumn ("REC_C1_BOT RM","Surname1",Label); - free (Label); - } - else - Frm_LabelColumn ("REC_C1_BOT RM",NULL,Txt_Surname_1); + switch (ViewType) + { + case Vie_VIEW: + Frm_LabelColumn ("REC_C1_BOT RM",NULL,Txt_Surname_1); + break; + case Vie_EDIT: + if (asprintf (&Label,"%s*",Txt_Surname_1) < 0) + Err_NotEnoughMemoryExit (); + Frm_LabelColumn ("REC_C1_BOT RM","Surname1",Label); + free (Label); + break; + default: + Err_WrongTypeExit (); + break; + } /* Data */ HTM_TD_Begin ("class=\"REC_C2_BOT LM DAT_STRONG_%s\"", The_GetSuffix ()); - if (PutForm) - HTM_INPUT_TEXT ("Surname1",Usr_MAX_CHARS_FIRSTNAME_OR_SURNAME,UsrDat->Surname1, - HTM_DONT_SUBMIT_ON_CHANGE, - "id=\"Surname1\" class=\"REC_C2_BOT_INPUT INPUT_%s\"" - " required=\"required\"", - The_GetSuffix ()); - else if (UsrDat->Surname1[0]) + switch (ViewType) { - HTM_STRONG_Begin (); - HTM_Txt (UsrDat->Surname1); - HTM_STRONG_End (); - } + case Vie_VIEW: + if (UsrDat->Surname1[0]) + { + HTM_STRONG_Begin (); + HTM_Txt (UsrDat->Surname1); + HTM_STRONG_End (); + } + break; + case Vie_EDIT: + HTM_INPUT_TEXT ("Surname1",Usr_MAX_CHARS_FIRSTNAME_OR_SURNAME,UsrDat->Surname1, + HTM_DONT_SUBMIT_ON_CHANGE, + "id=\"Surname1\" class=\"REC_C2_BOT_INPUT INPUT_%s\"" + " required=\"required\"", + The_GetSuffix ()); + break; + default: + Err_WrongTypeExit (); + break; + } HTM_TD_End (); HTM_TR_End (); @@ -3070,33 +3088,42 @@ static void Rec_ShowSurname1 (struct Usr_Data *UsrDat,bool PutForm) /*************************** Show user's surname 2 ***************************/ /*****************************************************************************/ -static void Rec_ShowSurname2 (struct Usr_Data *UsrDat,bool PutForm) +static void Rec_ShowSurname2 (struct Usr_Data *UsrDat,Vie_ViewType_t ViewType) { extern const char *Txt_Surname_2; HTM_TR_Begin (NULL); /* Label */ - Frm_LabelColumn ("REC_C1_BOT RM",PutForm ? "Surname2" : - NULL, + Frm_LabelColumn ("REC_C1_BOT RM",ViewType == Vie_EDIT ? "Surname2" : + NULL, Txt_Surname_2); /* Data */ HTM_TD_Begin ("class=\"REC_C2_BOT LM DAT_STRONG_%s\"", The_GetSuffix ()); - if (PutForm) - HTM_INPUT_TEXT ("Surname2",Usr_MAX_CHARS_FIRSTNAME_OR_SURNAME, - UsrDat->Surname2, - HTM_DONT_SUBMIT_ON_CHANGE, - "id=\"Surname2\"" - " class=\"REC_C2_BOT_INPUT INPUT_%s\"", - The_GetSuffix ()); - else if (UsrDat->Surname2[0]) + switch (ViewType) { - HTM_STRONG_Begin (); - HTM_Txt (UsrDat->Surname2); - HTM_STRONG_End (); - } + case Vie_VIEW: + if (UsrDat->Surname2[0]) + { + HTM_STRONG_Begin (); + HTM_Txt (UsrDat->Surname2); + HTM_STRONG_End (); + } + break; + case Vie_EDIT: + HTM_INPUT_TEXT ("Surname2",Usr_MAX_CHARS_FIRSTNAME_OR_SURNAME, + UsrDat->Surname2, + HTM_DONT_SUBMIT_ON_CHANGE, + "id=\"Surname2\"" + " class=\"REC_C2_BOT_INPUT INPUT_%s\"", + The_GetSuffix ()); + break; + default: + Err_WrongTypeExit (); + break; + } HTM_TD_End (); HTM_TR_End (); @@ -3106,7 +3133,7 @@ static void Rec_ShowSurname2 (struct Usr_Data *UsrDat,bool PutForm) /************************** Show user's first name ***************************/ /*****************************************************************************/ -static void Rec_ShowFirstName (struct Usr_Data *UsrDat,bool PutForm) +static void Rec_ShowFirstName (struct Usr_Data *UsrDat,Vie_ViewType_t ViewType) { extern const char *Txt_First_name; char *Label; @@ -3114,32 +3141,47 @@ static void Rec_ShowFirstName (struct Usr_Data *UsrDat,bool PutForm) HTM_TR_Begin (NULL); /* Label */ - if (PutForm) + switch (ViewType) { - if (asprintf (&Label,"%s*",Txt_First_name) < 0) - Err_NotEnoughMemoryExit (); - Frm_LabelColumn ("REC_C1_BOT RM","FirstName",Label); - free (Label); + case Vie_VIEW: + Frm_LabelColumn ("REC_C1_BOT RM",NULL,Txt_First_name); + break; + case Vie_EDIT: + if (asprintf (&Label,"%s*",Txt_First_name) < 0) + Err_NotEnoughMemoryExit (); + Frm_LabelColumn ("REC_C1_BOT RM","FirstName",Label); + free (Label); + break; + default: + Err_WrongTypeExit (); + break; } - else - Frm_LabelColumn ("REC_C1_BOT RM",NULL,Txt_First_name); /* Data */ HTM_TD_Begin ("colspan=\"2\" class=\"REC_C2_BOT LM DAT_STRONG_%s\"", The_GetSuffix ()); - if (PutForm) - HTM_INPUT_TEXT ("FirstName",Usr_MAX_CHARS_FIRSTNAME_OR_SURNAME, - UsrDat->FrstName, - HTM_DONT_SUBMIT_ON_CHANGE, - "id=\"FirstName\"" - " class=\"REC_C2_BOT_INPUT INPUT_%s\"" - " required=\"required\"", - The_GetSuffix ()); - else if (UsrDat->FrstName[0]) + switch (ViewType) { - HTM_STRONG_Begin (); - HTM_Txt (UsrDat->FrstName); - HTM_STRONG_End (); + case Vie_VIEW: + if (UsrDat->FrstName[0]) + { + HTM_STRONG_Begin (); + HTM_Txt (UsrDat->FrstName); + HTM_STRONG_End (); + } + break; + case Vie_EDIT: + HTM_INPUT_TEXT ("FirstName",Usr_MAX_CHARS_FIRSTNAME_OR_SURNAME, + UsrDat->FrstName, + HTM_DONT_SUBMIT_ON_CHANGE, + "id=\"FirstName\"" + " class=\"REC_C2_BOT_INPUT INPUT_%s\"" + " required=\"required\"", + The_GetSuffix ()); + break; + default: + Err_WrongTypeExit (); + break; } HTM_TD_End (); @@ -3150,7 +3192,7 @@ static void Rec_ShowFirstName (struct Usr_Data *UsrDat,bool PutForm) /**************************** Show user's country ****************************/ /*****************************************************************************/ -static void Rec_ShowCountry (struct Usr_Data *UsrDat,bool PutForm) +static void Rec_ShowCountry (struct Usr_Data *UsrDat,Vie_ViewType_t ViewType) { extern const char *Par_CodeStr[]; extern const char *Txt_Country; @@ -3166,15 +3208,21 @@ static void Rec_ShowCountry (struct Usr_Data *UsrDat,bool PutForm) HTM_TR_Begin (NULL); /* Label */ - if (PutForm) + switch (ViewType) { - if (asprintf (&Label,"%s*",Txt_Country) < 0) - Err_NotEnoughMemoryExit (); - Frm_LabelColumn ("REC_C1_BOT RM",Par_CodeStr[ParCod_OthCty],Label); - free (Label); + case Vie_VIEW: + Frm_LabelColumn ("REC_C1_BOT RM",NULL,Txt_Country); + break; + case Vie_EDIT: + if (asprintf (&Label,"%s*",Txt_Country) < 0) + Err_NotEnoughMemoryExit (); + Frm_LabelColumn ("REC_C1_BOT RM",Par_CodeStr[ParCod_OthCty],Label); + free (Label); + break; + default: + Err_WrongTypeExit (); + break; } - else - Frm_LabelColumn ("REC_C1_BOT RM",NULL,Txt_Country); /* Data */ HTM_TD_Begin ("colspan=\"2\" class=\"REC_C2_BOT LM\""); @@ -3215,7 +3263,8 @@ static void Rec_ShowCountry (struct Usr_Data *UsrDat,bool PutForm) /************************ Show user's date of birth **************************/ /*****************************************************************************/ -static void Rec_ShowDateOfBirth (struct Usr_Data *UsrDat,bool ShowData,bool PutForm) +static void Rec_ShowDateOfBirth (struct Usr_Data *UsrDat,bool ShowData, + Vie_ViewType_t ViewType) { extern const char *Txt_Date_of_birth; unsigned CurrentYear = Dat_GetCurrentYear (); @@ -3224,25 +3273,31 @@ static void Rec_ShowDateOfBirth (struct Usr_Data *UsrDat,bool ShowData,bool PutF HTM_TR_Begin (NULL); /* Label */ - Frm_LabelColumn ("REC_C1_BOT RM",PutForm ? "" : - NULL, + Frm_LabelColumn ("REC_C1_BOT RM",ViewType == Vie_EDIT ? "" : + NULL, Txt_Date_of_birth); /* Data */ - HTM_TD_Begin ("class=\"REC_C2_BOT LM DAT_STRONG_%s\"", - The_GetSuffix ()); + HTM_TD_Begin ("class=\"REC_C2_BOT LM DAT_STRONG_%s\"",The_GetSuffix ()); if (ShowData) - { - if (PutForm) - Dat_WriteFormDate (CurrentYear - Rec_USR_MAX_AGE, - CurrentYear - Rec_USR_MIN_AGE, - "Birth", - &(UsrDat->Birthday), - HTM_DONT_SUBMIT_ON_CHANGE, - false); - else if (UsrDat->StrBirthday[0]) - HTM_Txt (UsrDat->StrBirthday); - } + switch (ViewType) + { + case Vie_VIEW: + if (UsrDat->StrBirthday[0]) + HTM_Txt (UsrDat->StrBirthday); + break; + case Vie_EDIT: + Dat_WriteFormDate (CurrentYear - Rec_USR_MAX_AGE, + CurrentYear - Rec_USR_MIN_AGE, + "Birth", + &(UsrDat->Birthday), + HTM_DONT_SUBMIT_ON_CHANGE, + false); + break; + default: + Err_WrongTypeExit (); + break; + } HTM_TD_End (); HTM_TR_End (); @@ -3253,8 +3308,8 @@ static void Rec_ShowDateOfBirth (struct Usr_Data *UsrDat,bool ShowData,bool PutF /*****************************************************************************/ // NumPhone can be 0 or 1 -static void Rec_ShowPhone (struct Usr_Data *UsrDat,bool ShowData,bool PutForm, - unsigned NumPhone) +static void Rec_ShowPhone (struct Usr_Data *UsrDat,bool ShowData, + Vie_ViewType_t ViewType,unsigned NumPhone) { extern const char *Txt_Phone; char *Name; @@ -3272,29 +3327,36 @@ static void Rec_ShowPhone (struct Usr_Data *UsrDat,bool ShowData,bool PutForm, HTM_TR_Begin (NULL); /* Label */ - Frm_LabelColumn ("REC_C1_BOT RM",PutForm ? Name : - NULL, + Frm_LabelColumn ("REC_C1_BOT RM",ViewType == Vie_EDIT ? Name : + NULL, Label); /* Data */ HTM_TD_Begin ("class=\"REC_C2_BOT LM DAT_STRONG_%s\"", The_GetSuffix ()); if (ShowData) - { - if (PutForm) - HTM_INPUT_TEL (Name,UsrDat->Phone[NumPhone], - HTM_DONT_SUBMIT_ON_CHANGE, - "id=\"%s\" class=\"REC_C2_BOT_INPUT INPUT_%s\"", - Name, - The_GetSuffix ()); - else if (UsrDat->Phone[NumPhone][0]) + switch (ViewType) { - HTM_A_Begin ("href=\"tel:%s\" class=\"DAT_STRONG_%s\"", - UsrDat->Phone[NumPhone],The_GetSuffix ()); - HTM_Txt (UsrDat->Phone[NumPhone]); - HTM_A_End (); + case Vie_VIEW: + if (UsrDat->Phone[NumPhone][0]) + { + HTM_A_Begin ("href=\"tel:%s\" class=\"DAT_STRONG_%s\"", + UsrDat->Phone[NumPhone],The_GetSuffix ()); + HTM_Txt (UsrDat->Phone[NumPhone]); + HTM_A_End (); + } + break; + case Vie_EDIT: + HTM_INPUT_TEL (Name,UsrDat->Phone[NumPhone], + HTM_DONT_SUBMIT_ON_CHANGE, + "id=\"%s\" class=\"REC_C2_BOT_INPUT INPUT_%s\"", + Name, + The_GetSuffix ()); + break; + default: + Err_WrongTypeExit (); + break; } - } HTM_TD_End (); HTM_TR_End (); @@ -3310,7 +3372,8 @@ static void Rec_ShowPhone (struct Usr_Data *UsrDat,bool ShowData,bool PutForm, /************************** Show user's comments *****************************/ /*****************************************************************************/ -static void Rec_ShowComments (struct Usr_Data *UsrDat,bool ShowData,bool PutForm) +static void Rec_ShowComments (struct Usr_Data *UsrDat,bool ShowData, + Vie_ViewType_t ViewType) { extern const char *Txt_USER_comments; @@ -3318,32 +3381,37 @@ static void Rec_ShowComments (struct Usr_Data *UsrDat,bool ShowData,bool PutForm HTM_TR_Begin (NULL); /* Label */ - Frm_LabelColumn ("REC_C1_BOT RT",PutForm ? "Comments" : - NULL, + Frm_LabelColumn ("REC_C1_BOT RT",ViewType == Vie_EDIT ? "Comments" : + NULL, Txt_USER_comments); /* Data */ HTM_TD_Begin ("class=\"REC_C2_BOT LT DAT_STRONG_%s\"", The_GetSuffix ()); if (ShowData) - { - if (PutForm) + switch (ViewType) { - HTM_TEXTAREA_Begin ("id=\"Comments\" name=\"Comments\"" - " rows=\"4\"" - " class=\"REC_C2_BOT_INPUT INPUT_%s\"", - The_GetSuffix ()); - HTM_Txt (UsrDat->Comments); - HTM_TEXTAREA_End (); + case Vie_VIEW: + if (UsrDat->Comments[0]) + { + Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, + UsrDat->Comments,Cns_MAX_BYTES_TEXT, + Str_DONT_REMOVE_SPACES); + HTM_Txt (UsrDat->Comments); + } + break; + case Vie_EDIT: + HTM_TEXTAREA_Begin ("id=\"Comments\" name=\"Comments\"" + " rows=\"4\"" + " class=\"REC_C2_BOT_INPUT INPUT_%s\"", + The_GetSuffix ()); + HTM_Txt (UsrDat->Comments); + HTM_TEXTAREA_End (); + break; + default: + Err_WrongTypeExit (); + break; } - else if (UsrDat->Comments[0]) - { - Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, - UsrDat->Comments,Cns_MAX_BYTES_TEXT, - Str_DONT_REMOVE_SPACES); - HTM_Txt (UsrDat->Comments); - } - } HTM_TD_End (); HTM_TR_End (); diff --git a/swad_survey.c b/swad_survey.c index 61997b0e..ac7f11d8 100644 --- a/swad_survey.c +++ b/swad_survey.c @@ -608,7 +608,8 @@ static void Svy_ShowOneSurvey (struct Svy_Surveys *Surveys, 1 << Rol_NET | 1 << Rol_TCH, Surveys->Svy.Roles, - true,false); + true, + HTM_DONT_SUBMIT_ON_CHANGE); HTM_DIV_End (); /* Groups whose users can answer this survey */ @@ -1704,7 +1705,8 @@ void Svy_ReqCreatOrEditSvy (void) 1 << Rol_NET | 1 << Rol_TCH, Surveys.Svy.Roles, - false,false); + false, + HTM_DONT_SUBMIT_ON_CHANGE); HTM_TD_End (); HTM_TR_End (); diff --git a/swad_syllabus.h b/swad_syllabus.h index 952c7fcb..db3e99c5 100644 --- a/swad_syllabus.h +++ b/swad_syllabus.h @@ -27,7 +27,7 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -#include "swad_view_edit.h" +#include "swad_view.h" /*****************************************************************************/ /************************ Public constants and types *************************/ diff --git a/swad_test_print.c b/swad_test_print.c index 35ddb5ad..6251cb67 100644 --- a/swad_test_print.c +++ b/swad_test_print.c @@ -1426,7 +1426,7 @@ static void TstPrn_WriteChoAnsPrint (struct Usr_Data *UsrDat, HTM_TR_Begin (NULL); /* Draw icon depending on user's answer */ - if (UsrAnswers[Indexes[NumOpt]] == true) // This answer has been selected by the user + if (UsrAnswers[Indexes[NumOpt]]) // This answer has been selected by the user { if (ICanView[TstVis_VISIBLE_CORRECT_ANSWER]) { diff --git a/swad_view_edit.h b/swad_view.h similarity index 100% rename from swad_view_edit.h rename to swad_view.h