From fe8168dcf8663c8e0f400abf7d0114265b361f94 Mon Sep 17 00:00:00 2001 From: acanas Date: Wed, 10 Nov 2021 00:39:09 +0100 Subject: [PATCH] Version 21.55.2: Nov 10, 2021 Code refactoring in switch statements (until swad_button.c). --- swad_account.c | 34 ++++++++--------- swad_agenda_database.c | 2 +- swad_assignment_database.c | 2 +- swad_attendance.c | 4 +- swad_browser.c | 70 ++++++++++++++--------------------- swad_button.c | 72 ++++++++++++++++-------------------- swad_button.h | 1 + swad_changelog.h | 3 +- swad_figure.c | 6 +-- swad_timeline.c | 2 +- swad_timeline_comment.c | 2 +- swad_timeline_database.c | 12 +++--- swad_timeline_database.h | 8 ++-- swad_timeline_note.c | 58 ++++++++++++++--------------- swad_timeline_note.h | 30 +++++++++------ swad_timeline_notification.c | 6 +-- swad_timeline_publication.c | 14 +++---- swad_timeline_publication.h | 12 +++--- swad_timeline_share.c | 2 +- 19 files changed, 160 insertions(+), 180 deletions(-) diff --git a/swad_account.c b/swad_account.c index 3d3c168d..79c47164 100644 --- a/swad_account.c +++ b/swad_account.c @@ -1108,34 +1108,30 @@ static void Acc_RemoveUsrBriefcase (struct UsrData *UsrDat) void Acc_PutIconToChangeUsrAccount (void) { extern const char *Txt_Change_account; - Act_Action_t NextAction; - bool ItsMe = Usr_ItsMe (Gbl.Record.UsrDat->UsrCod); + static const Act_Action_t NextAction[Rol_NUM_ROLES] = + { + [Rol_UNK ] = ActFrmAccOth, + [Rol_GST ] = ActFrmAccOth, + [Rol_USR ] = ActFrmAccOth, + [Rol_STD ] = ActFrmAccStd, + [Rol_NET ] = ActFrmAccTch, + [Rol_TCH ] = ActFrmAccTch, + [Rol_DEG_ADM] = ActFrmAccOth, + [Rol_CTR_ADM] = ActFrmAccOth, + [Rol_INS_ADM] = ActFrmAccOth, + [Rol_SYS_ADM] = ActFrmAccOth, + }; /***** Link for changing the account *****/ - if (ItsMe) + if (Usr_ItsMe (Gbl.Record.UsrDat->UsrCod)) Lay_PutContextualLinkOnlyIcon (ActFrmMyAcc,NULL, NULL,NULL, "at.svg", Txt_Change_account); else // Not me if (Usr_ICanEditOtherUsr (Gbl.Record.UsrDat)) - { - switch (Gbl.Record.UsrDat->Roles.InCurrentCrs) - { - case Rol_STD: - NextAction = ActFrmAccStd; - break; - case Rol_NET: - case Rol_TCH: - NextAction = ActFrmAccTch; - break; - default: // Guest, user or admin - NextAction = ActFrmAccOth; - break; - } - Lay_PutContextualLinkOnlyIcon (NextAction,NULL, + Lay_PutContextualLinkOnlyIcon (NextAction[Gbl.Record.UsrDat->Roles.InCurrentCrs],NULL, Rec_PutParamUsrCodEncrypted,NULL, "at.svg", Txt_Change_account); - } } diff --git a/swad_agenda_database.c b/swad_agenda_database.c index 9bd0d8ea..fe3f167a 100644 --- a/swad_agenda_database.c +++ b/swad_agenda_database.c @@ -357,7 +357,7 @@ unsigned Agd_DB_GetNumUsrsWithEvents (HieLvl_Level_t Scope) "SELECT COUNT(DISTINCT UsrCod)" " FROM agd_agendas" " WHERE UsrCod>0"); - case HieLvl_CTY: + case HieLvl_CTY: return (unsigned) DB_QueryCOUNT ("can not get number of users with events", "SELECT COUNT(DISTINCT agd_agendas.UsrCod)" diff --git a/swad_assignment_database.c b/swad_assignment_database.c index 12749e6f..fa72c095 100644 --- a/swad_assignment_database.c +++ b/swad_assignment_database.c @@ -515,7 +515,7 @@ unsigned Asg_DB_GetNumCoursesWithAssignments (HieLvl_Level_t Scope) "SELECT COUNT(DISTINCT CrsCod)" " FROM asg_assignments" " WHERE CrsCod>0"); - case HieLvl_CTY: + case HieLvl_CTY: return (unsigned) DB_QueryCOUNT ("can not get number of courses with assignments", "SELECT COUNT(DISTINCT asg_assignments.CrsCod)" diff --git a/swad_attendance.c b/swad_attendance.c index ae017542..246be6bc 100644 --- a/swad_attendance.c +++ b/swad_attendance.c @@ -1682,7 +1682,6 @@ static void Att_WriteRowUsrToCallTheRoll (unsigned NumUsr, bool Present; char CommentStd[Cns_MAX_BYTES_TEXT + 1]; char CommentTch[Cns_MAX_BYTES_TEXT + 1]; - bool ItsMe; bool ICanChangeStdAttendance; bool ICanEditStdComment; bool ICanEditTchComment; @@ -1692,8 +1691,7 @@ static void Att_WriteRowUsrToCallTheRoll (unsigned NumUsr, { case Rol_STD: // A student can see only her/his attendance - ItsMe = Usr_ItsMe (UsrDat->UsrCod); - if (!ItsMe) + if (!Usr_ItsMe (UsrDat->UsrCod)) Err_ShowErrorAndExit ("Wrong call."); ICanChangeStdAttendance = false; ICanEditStdComment = Event->Open; // Attendance event is open diff --git a/swad_browser.c b/swad_browser.c index 1fad652b..1aee38ac 100644 --- a/swad_browser.c +++ b/swad_browser.c @@ -3223,7 +3223,19 @@ static void Brw_GetSelectedGroupData (struct GroupData *GrpDat,bool AbortOnError static void Brw_ShowDataOwnerAsgWrk (struct UsrData *UsrDat) { extern const char *Txt_View_record_for_this_course; - Act_Action_t NextAction; + static const Act_Action_t NextAction[Rol_NUM_ROLES] = + { + [Rol_UNK ] = ActUnk, + [Rol_GST ] = ActUnk, + [Rol_USR ] = ActUnk, + [Rol_STD ] = ActSeeRecOneStd, + [Rol_NET ] = ActSeeRecOneTch, + [Rol_TCH ] = ActSeeRecOneTch, + [Rol_DEG_ADM] = ActUnk, + [Rol_CTR_ADM] = ActUnk, + [Rol_INS_ADM] = ActUnk, + [Rol_SYS_ADM] = ActUnk, + }; /***** Show user's photo *****/ HTM_TD_Begin ("class=\"OWNER_WORKS_PHOTO\""); @@ -3235,21 +3247,10 @@ static void Brw_ShowDataOwnerAsgWrk (struct UsrData *UsrDat) HTM_DIV_Begin ("class=\"OWNER_WORKS_DATA AUTHOR_TXT\""); - switch (UsrDat->Roles.InCurrentCrs) - { - case Rol_STD: - NextAction = ActSeeRecOneStd; - break; - case Rol_NET: - case Rol_TCH: - NextAction = ActSeeRecOneTch; - break; - default: - NextAction = ActUnk; - Err_WrongRoleExit (); - break; - } - Frm_BeginForm (NextAction); + if (NextAction[UsrDat->Roles.InCurrentCrs] == ActUnk) + Err_WrongRoleExit (); + + Frm_BeginForm (NextAction[UsrDat->Roles.InCurrentCrs]); Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod); /***** Show user's ID *****/ @@ -8356,24 +8357,24 @@ void Brw_DownloadFile (void) case Brw_ADMI_DOC_CRS: case Brw_ADMI_DOC_GRP: Ntf_DB_MarkNotifAsRemoved (Ntf_EVENT_DOCUMENT_FILE, - FileMetadata.FilCod); + FileMetadata.FilCod); break; case Brw_ADMI_TCH_CRS: case Brw_ADMI_TCH_GRP: Ntf_DB_MarkNotifAsRemoved (Ntf_EVENT_TEACHERS_FILE, - FileMetadata.FilCod); + FileMetadata.FilCod); break; case Brw_ADMI_SHR_CRS: case Brw_ADMI_SHR_GRP: Ntf_DB_MarkNotifAsRemoved (Ntf_EVENT_SHARED_FILE, - FileMetadata.FilCod); + FileMetadata.FilCod); break; case Brw_SHOW_MRK_CRS: case Brw_SHOW_MRK_GRP: case Brw_ADMI_MRK_CRS: case Brw_ADMI_MRK_GRP: Ntf_DB_MarkNotifAsRemoved (Ntf_EVENT_MARKS_FILE, - FileMetadata.FilCod); + FileMetadata.FilCod); break; default: break; @@ -9485,14 +9486,11 @@ static bool Brw_CheckIfICanModifyPrivateFileOrFolder (void) bool Brw_CheckIfICanViewProjectFiles (long PrjCod) { - unsigned MyRolesInProject; - switch (Gbl.Usrs.Me.Role.Logged) { case Rol_STD: case Rol_NET: - MyRolesInProject = Prj_GetMyRolesInProject (PrjCod); - return (MyRolesInProject != 0); // Am I a member? + return (Prj_GetMyRolesInProject (PrjCod) != 0); // Am I a member? case Rol_TCH: // Editing teachers in a course can access to all files case Rol_SYS_ADM: return true; @@ -9507,14 +9505,11 @@ bool Brw_CheckIfICanViewProjectFiles (long PrjCod) static bool Brw_CheckIfICanViewProjectDocuments (long PrjCod) { - unsigned MyRolesInProject; - switch (Gbl.Usrs.Me.Role.Logged) { case Rol_STD: case Rol_NET: - MyRolesInProject = Prj_GetMyRolesInProject (PrjCod); - return (MyRolesInProject != 0); // Am I a member? + return (Prj_GetMyRolesInProject (PrjCod) != 0); // Am I a member? case Rol_TCH: // Editing teachers in a course can access to all files case Rol_SYS_ADM: return true; @@ -9530,15 +9525,12 @@ static bool Brw_CheckIfICanViewProjectDocuments (long PrjCod) static bool Brw_CheckIfICanViewProjectAssessment (long PrjCod) { - unsigned MyRolesInProject; - switch (Gbl.Usrs.Me.Role.Logged) { case Rol_STD: case Rol_NET: - MyRolesInProject = Prj_GetMyRolesInProject (PrjCod); - return ((MyRolesInProject & (1 << Prj_ROLE_TUT | // Tutor... - 1 << Prj_ROLE_EVL)) != 0); // ...or evaluator + return ((Prj_GetMyRolesInProject (PrjCod) & (1 << Prj_ROLE_TUT | // Tutor... + 1 << Prj_ROLE_EVL)) != 0); // ...or evaluator case Rol_TCH: // Editing teachers in a course can access to all files case Rol_SYS_ADM: return true; @@ -9558,14 +9550,11 @@ static bool Brw_CheckIfICanViewProjectAssessment (long PrjCod) static bool Brw_CheckIfICanModifyPrjDocFileOrFolder (void) { - unsigned MyRolesInProject; - switch (Gbl.Usrs.Me.Role.Logged) { case Rol_STD: case Rol_NET: - MyRolesInProject = Prj_GetMyRolesInProject (Prj_GetPrjCod ()); - if (MyRolesInProject) // I am a member + if (Prj_GetMyRolesInProject (Prj_GetPrjCod ())) // I am a member return (Gbl.Usrs.Me.UsrDat.UsrCod == Brw_DB_GetPublisherOfSubtree (Gbl.FileBrowser.FilFolLnk.Full)); // Am I the publisher of subtree? return false; case Rol_TCH: // Editing teachers in a course can access to all files @@ -9587,15 +9576,12 @@ static bool Brw_CheckIfICanModifyPrjDocFileOrFolder (void) static bool Brw_CheckIfICanModifyPrjAssFileOrFolder (void) { - unsigned MyRolesInProject; - switch (Gbl.Usrs.Me.Role.Logged) { case Rol_STD: case Rol_NET: - MyRolesInProject = Prj_GetMyRolesInProject (Prj_GetPrjCod ()); - if ((MyRolesInProject & (1 << Prj_ROLE_TUT | // Tutor... - 1 << Prj_ROLE_EVL))) // ...or evaluator + if ((Prj_GetMyRolesInProject (Prj_GetPrjCod ()) & (1 << Prj_ROLE_TUT | // Tutor... + 1 << Prj_ROLE_EVL))) // ...or evaluator return (Gbl.Usrs.Me.UsrDat.UsrCod == Brw_DB_GetPublisherOfSubtree (Gbl.FileBrowser.FilFolLnk.Full)); // Am I the publisher of subtree? return false; case Rol_TCH: // Editing teachers in a course can access to all files diff --git a/swad_button.c b/swad_button.c index df116a7a..07316a14 100644 --- a/swad_button.c +++ b/swad_button.c @@ -35,88 +35,80 @@ void Btn_PutButton (Btn_Button_t Button,const char *TxtButton) { + static void (*Function[Btn_NUM_BUTTON_TYPES]) (const char *TxtButton) = + { + [Btn_NO_BUTTON ] = NULL, + [Btn_CREATE_BUTTON ] = Btn_PutCreateButton, + [Btn_CONFIRM_BUTTON] = Btn_PutConfirmButton, + [Btn_REMOVE_BUTTON ] = Btn_PutRemoveButton, + }; + if (TxtButton) if (TxtButton[0]) - switch (Button) - { - case Btn_NO_BUTTON: - break; - case Btn_CREATE_BUTTON: - Btn_PutCreateButton (TxtButton); - break; - case Btn_CONFIRM_BUTTON: - Btn_PutConfirmButton (TxtButton); - break; - case Btn_REMOVE_BUTTON: - Btn_PutRemoveButton (TxtButton); - break; - } + if (Function[Button]) + Function[Button] (TxtButton); } void Btn_PutButtonInline (Btn_Button_t Button,const char *TxtButton) { + static void (*Function[Btn_NUM_BUTTON_TYPES]) (const char *TxtButton) = + { + [Btn_NO_BUTTON ] = NULL, + [Btn_CREATE_BUTTON ] = Btn_PutCreateButtonInline, + [Btn_CONFIRM_BUTTON] = Btn_PutConfirmButtonInline, + [Btn_REMOVE_BUTTON ] = Btn_PutRemoveButtonInline, + }; + if (TxtButton) if (TxtButton[0]) - switch (Button) - { - case Btn_NO_BUTTON: - break; - case Btn_CREATE_BUTTON: - Btn_PutCreateButtonInline (TxtButton); - break; - case Btn_CONFIRM_BUTTON: - Btn_PutConfirmButtonInline (TxtButton); - break; - case Btn_REMOVE_BUTTON: - Btn_PutRemoveButtonInline (TxtButton); - break; - } + if (Function[Button]) + Function[Button] (TxtButton); } void Btn_PutCreateButton (const char *TxtButton) { HTM_DIV_Begin ("class=\"CM\""); - HTM_BUTTON_SUBMIT_Begin (NULL,"BT_SUBMIT BT_CREATE",NULL); - HTM_Txt (TxtButton); - HTM_BUTTON_End (); + HTM_BUTTON_SUBMIT_Begin (NULL,"BT_SUBMIT BT_CREATE",NULL); + HTM_Txt (TxtButton); + HTM_BUTTON_End (); HTM_DIV_End (); } void Btn_PutCreateButtonInline (const char *TxtButton) { HTM_BUTTON_SUBMIT_Begin (NULL,"BT_SUBMIT_INLINE BT_CREATE",NULL); - HTM_Txt (TxtButton); + HTM_Txt (TxtButton); HTM_BUTTON_End (); } void Btn_PutConfirmButton (const char *TxtButton) { HTM_DIV_Begin ("class=\"CM\""); - HTM_BUTTON_SUBMIT_Begin (NULL,"BT_SUBMIT BT_CONFIRM",NULL); - HTM_Txt (TxtButton); - HTM_BUTTON_End (); + HTM_BUTTON_SUBMIT_Begin (NULL,"BT_SUBMIT BT_CONFIRM",NULL); + HTM_Txt (TxtButton); + HTM_BUTTON_End (); HTM_DIV_End (); } void Btn_PutConfirmButtonInline (const char *TxtButton) { HTM_BUTTON_SUBMIT_Begin (NULL,"BT_SUBMIT_INLINE BT_CONFIRM",NULL); - HTM_Txt (TxtButton); + HTM_Txt (TxtButton); HTM_BUTTON_End (); } void Btn_PutRemoveButton (const char *TxtButton) { HTM_DIV_Begin ("class=\"CM\""); - HTM_BUTTON_SUBMIT_Begin (NULL,"BT_SUBMIT BT_REMOVE",NULL); - HTM_Txt (TxtButton); - HTM_BUTTON_End (); + HTM_BUTTON_SUBMIT_Begin (NULL,"BT_SUBMIT BT_REMOVE",NULL); + HTM_Txt (TxtButton); + HTM_BUTTON_End (); HTM_DIV_End (); } void Btn_PutRemoveButtonInline (const char *TxtButton) { HTM_BUTTON_SUBMIT_Begin (NULL,"BT_SUBMIT_INLINE BT_REMOVE",NULL); - HTM_Txt (TxtButton); + HTM_Txt (TxtButton); HTM_BUTTON_End (); } diff --git a/swad_button.h b/swad_button.h index 2024a6ff..dd9a64cd 100644 --- a/swad_button.h +++ b/swad_button.h @@ -27,6 +27,7 @@ /********************************* Public types ******************************/ /*****************************************************************************/ +#define Btn_NUM_BUTTON_TYPES 4 typedef enum { Btn_NO_BUTTON, diff --git a/swad_changelog.h b/swad_changelog.h index ed96d6d5..3dc661e3 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -602,13 +602,14 @@ TODO: FIX BUG, URGENT! En las fechas como par TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo. */ -#define Log_PLATFORM_VERSION "SWAD 21.55.1 (2021-11-09)" +#define Log_PLATFORM_VERSION "SWAD 21.55.2 (2021-11-10)" #define CSS_FILE "swad20.45.css" #define JS_FILE "swad20.69.1.js" /* TODO: Rename CENTRE to CENTER in help wiki. TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams + Version 21.55.2: Nov 10, 2021 Code refactoring in switch statements (until swad_button.c). (? lines) Version 21.55.1: Nov 09, 2021 Removed unused comments. (319893 lines) Version 21.55: Nov 09, 2021 New module swad_template. Removed unused comments. (320885 lines) Version 21.54.8: Nov 09, 2021 Queries moved from API module to database modules. (322179 lines) diff --git a/swad_figure.c b/swad_figure.c index d236cabe..30adb629 100644 --- a/swad_figure.c +++ b/swad_figure.c @@ -2234,7 +2234,7 @@ static void Fig_GetAndShowTimelineActivityStats (void) extern const char *Txt_Total; MYSQL_RES *mysql_res; MYSQL_ROW row; - Tml_Not_NoteType_t NoteType; + Tml_Not_Type_t NoteType; unsigned NumNotes; unsigned NumUsrs; unsigned NumUsrsTotal; @@ -2257,8 +2257,8 @@ static void Fig_GetAndShowTimelineActivityStats (void) NumUsrsTotal = Usr_GetTotalNumberOfUsers (); /***** Get total number of timeline notes and users for each note type *****/ - for (NoteType = (Tml_Not_NoteType_t) 0; - NoteType <= (Tml_Not_NoteType_t) (TL_NOT_NUM_NOTE_TYPES - 1); + for (NoteType = (Tml_Not_Type_t) 0; + NoteType <= (Tml_Not_Type_t) (TL_NOT_NUM_NOTE_TYPES - 1); NoteType++) { /***** Get number of timeline notes and users for this type *****/ diff --git a/swad_timeline.c b/swad_timeline.c index c0545d83..cc157e48 100644 --- a/swad_timeline.c +++ b/swad_timeline.c @@ -495,7 +495,7 @@ static unsigned Tml_ListRecentPubs (struct Tml_Timeline *Timeline, Not.NotCod == NotCodToHighlight ? "TL_WIDTH TL_SEP TL_NEW_PUB" : "TL_WIDTH TL_SEP"); Tml_Not_CheckAndWriteNoteWithTopMsg (Timeline,&Not, - Tml_Pub_GetTopMessage (Pub->PubType), + Tml_Pub_GetTopMessage (Pub->Type), Pub->PublisherCod); HTM_LI_End (); } diff --git a/swad_timeline_comment.c b/swad_timeline_comment.c index 7c4f0756..e6b3cde4 100644 --- a/swad_timeline_comment.c +++ b/swad_timeline_comment.c @@ -774,7 +774,7 @@ static long Tml_Com_ReceiveComm (void) /* Insert into publications */ Pub.NotCod = Not.NotCod; Pub.PublisherCod = Gbl.Usrs.Me.UsrDat.UsrCod; - Pub.PubType = Tml_Pub_COMMENT_TO_NOTE; + Pub.Type = Tml_Pub_COMMENT_TO_NOTE; Tml_Pub_PublishPubInTimeline (&Pub); // Set Pub.PubCod /* Insert comment content in the database */ diff --git a/swad_timeline_database.c b/swad_timeline_database.c index 52546bf6..7f99eef5 100644 --- a/swad_timeline_database.c +++ b/swad_timeline_database.c @@ -50,7 +50,7 @@ static const char *Tml_DB_FieldFav[Tml_Usr_NUM_FAV_SHA] = [Tml_Usr_FAV_UNF_COMM] = "PubCod", [Tml_Usr_SHA_UNS_NOTE] = NULL, // Not used }; -static Tml_Pub_PubType_t Tml_DB_PubTypeFav[Tml_Usr_NUM_FAV_SHA] = +static Tml_Pub_Type_t Tml_DB_PubTypeFav[Tml_Usr_NUM_FAV_SHA] = { [Tml_Usr_FAV_UNF_NOTE] = Tml_Pub_ORIGINAL_NOTE, [Tml_Usr_FAV_UNF_COMM] = Tml_Pub_COMMENT_TO_NOTE, @@ -144,7 +144,7 @@ long Tml_DB_GetPubCodOfOriginalNote (long NotCod) /*****************************************************************************/ // Returns code of note just created -long Tml_DB_CreateNewNote (Tml_Not_NoteType_t NoteType,long Cod, +long Tml_DB_CreateNewNote (Tml_Not_Type_t NoteType,long Cod, long PublisherCod,long HieCod) { return @@ -165,7 +165,7 @@ long Tml_DB_CreateNewNote (Tml_Not_NoteType_t NoteType,long Cod, /************************* Mark a note as unavailable ************************/ /*****************************************************************************/ -void Tml_DB_MarkNoteAsUnavailable (Tml_Not_NoteType_t NoteType,long Cod) +void Tml_DB_MarkNoteAsUnavailable (Tml_Not_Type_t NoteType,long Cod) { DB_QueryUPDATE ("can not mark note as unavailable", "UPDATE tml_notes" @@ -180,7 +180,7 @@ void Tml_DB_MarkNoteAsUnavailable (Tml_Not_NoteType_t NoteType,long Cod) /***** Mark possible notes involving children of a folder as unavailable *****/ /*****************************************************************************/ -void Tml_DB_MarkNotesChildrenOfFolderAsUnavailable (Tml_Not_NoteType_t NoteType, +void Tml_DB_MarkNotesChildrenOfFolderAsUnavailable (Tml_Not_Type_t NoteType, Brw_FileBrowser_t FileBrowser, long Cod,const char *Path) { @@ -205,7 +205,7 @@ void Tml_DB_MarkNotesChildrenOfFolderAsUnavailable (Tml_Not_NoteType_t NoteType, /*****************************************************************************/ unsigned Tml_DB_GetNumNotesAndUsrsByType (MYSQL_RES **mysql_res, - Tml_Not_NoteType_t NoteType) + Tml_Not_Type_t NoteType) { switch (Gbl.Scope.Current) { @@ -1097,7 +1097,7 @@ long Tml_DB_CreateNewPub (const struct Tml_Pub_Publication *Pub) " (%ld,%ld,%u,NOW())", Pub->NotCod, Pub->PublisherCod, - (unsigned) Pub->PubType); + (unsigned) Pub->Type); } /*****************************************************************************/ diff --git a/swad_timeline_database.h b/swad_timeline_database.h index 166c7b1e..7e1997c4 100644 --- a/swad_timeline_database.h +++ b/swad_timeline_database.h @@ -46,15 +46,15 @@ void Tml_DB_UpdateWho (Usr_Who_t Who); /*********************************** Notes ***********************************/ unsigned Tml_DB_GetDataOfNoteByCod (long NotCod,MYSQL_RES **mysql_res); long Tml_DB_GetPubCodOfOriginalNote (long NotCod); -long Tml_DB_CreateNewNote (Tml_Not_NoteType_t NoteType,long Cod, +long Tml_DB_CreateNewNote (Tml_Not_Type_t NoteType,long Cod, long PublisherCod,long HieCod); -void Tml_DB_MarkNoteAsUnavailable (Tml_Not_NoteType_t NoteType,long Cod); -void Tml_DB_MarkNotesChildrenOfFolderAsUnavailable (Tml_Not_NoteType_t NoteType, +void Tml_DB_MarkNoteAsUnavailable (Tml_Not_Type_t NoteType,long Cod); +void Tml_DB_MarkNotesChildrenOfFolderAsUnavailable (Tml_Not_Type_t NoteType, Brw_FileBrowser_t FileBrowser, long Cod,const char *Path); unsigned Tml_DB_GetNumNotesAndUsrsByType (MYSQL_RES **mysql_res, - Tml_Not_NoteType_t NoteType); + Tml_Not_Type_t NoteType); unsigned Tml_DB_GetNumNotesAndUsrsTotal (MYSQL_RES **mysql_res); void Tml_DB_CreateTmpTableJustRetrievedNotes (void); diff --git a/swad_timeline_note.c b/swad_timeline_note.c index ddfc589e..f60782db 100644 --- a/swad_timeline_note.c +++ b/swad_timeline_note.c @@ -98,7 +98,7 @@ static void Tml_Not_RemoveNoteMediaAndDBEntries (struct Tml_Not_Note *Not); static void Tml_Not_GetDataOfNoteFromRow (MYSQL_ROW row,struct Tml_Not_Note *Not); -static Tml_Not_NoteType_t Tml_Not_GetNoteTypeFromStr (const char *Str); +static Tml_Not_Type_t Tml_Not_GetNoteTypeFromStr (const char *Str); static void Tml_Not_ResetNote (struct Tml_Not_Note *Not); @@ -218,7 +218,7 @@ void Tml_Not_CheckAndWriteNoteWithTopMsg (const struct Tml_Timeline *Timeline, /***** Trivial check: codes *****/ if (Not->NotCod <= 0 || Not->UsrCod <= 0 || - Not->NoteType == TL_NOTE_UNKNOWN) + Not->Type == TL_NOTE_UNKNOWN) { Ale_ShowAlert (Ale_ERROR,"Error in note."); return; @@ -370,7 +370,7 @@ void Tml_Not_WriteAuthorName (const struct UsrData *UsrDat, static void Tml_Not_WriteContent (const struct Tml_Not_Note *Not) { - if (Not->NoteType == TL_NOTE_POST) // It's a post + if (Not->Type == TL_NOTE_POST) // It's a post Tml_Pst_GetAndWritePost (Not->Cod); else // Not a post Tml_Not_GetAndWriteNoPost (Not); @@ -428,7 +428,7 @@ static void Tml_Not_GetLocationInHierarchy (const struct Tml_Not_Note *Not, Hie->Crs.CrsCod = -1L; /***** Get location in hierarchy *****/ - switch (Not->NoteType) + switch (Not->Type) { case TL_NOTE_INS_DOC_PUB_FILE: case TL_NOTE_INS_SHA_PUB_FILE: @@ -486,7 +486,7 @@ static void Tml_Not_WriteLocationInHierarchy (const struct Tml_Not_Note *Not, HTM_DIV_Begin ("class=\"TL_LOC\""); /***** Write location *****/ - switch (Not->NoteType) + switch (Not->Type) { case TL_NOTE_INS_DOC_PUB_FILE: case TL_NOTE_INS_SHA_PUB_FILE: @@ -605,7 +605,7 @@ static void Tml_Not_PutFormGoToAction (const struct Tml_Not_Note *Not, HTM_DIV_Begin ("class=\"TL_FORM_OFF\""); /* Text ("not available") */ - HTM_Txt (Txt_TIMELINE_NOTE[Not->NoteType]); + HTM_Txt (Txt_TIMELINE_NOTE[Not->Type]); if (Not->Unavailable) HTM_TxtF (" (%s)",Txt_not_available); @@ -618,39 +618,39 @@ static void Tml_Not_PutFormGoToAction (const struct Tml_Not_Note *Not, HTM_DIV_Begin ("class=\"TL_FORM\""); /***** Begin form with parameters depending on the type of note *****/ - switch (Not->NoteType) + switch (Not->Type) { case TL_NOTE_INS_DOC_PUB_FILE: case TL_NOTE_INS_SHA_PUB_FILE: - Frm_BeginFormUnique (TL_DefaultActions[Not->NoteType]); + Frm_BeginFormUnique (TL_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 TL_NOTE_CTR_DOC_PUB_FILE: case TL_NOTE_CTR_SHA_PUB_FILE: - Frm_BeginFormUnique (TL_DefaultActions[Not->NoteType]); + Frm_BeginFormUnique (TL_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 TL_NOTE_DEG_DOC_PUB_FILE: case TL_NOTE_DEG_SHA_PUB_FILE: - Frm_BeginFormUnique (TL_DefaultActions[Not->NoteType]); + Frm_BeginFormUnique (TL_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 TL_NOTE_CRS_DOC_PUB_FILE: case TL_NOTE_CRS_SHA_PUB_FILE: - Frm_BeginFormUnique (TL_DefaultActions[Not->NoteType]); + Frm_BeginFormUnique (TL_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 TL_NOTE_CALL_FOR_EXAM: Frm_SetAnchorStr (Not->Cod,&Anchor); - Frm_BeginFormUniqueAnchor (TL_DefaultActions[Not->NoteType], + Frm_BeginFormUniqueAnchor (TL_DefaultActions[Not->Type], Anchor); // Locate on this specific exam Frm_FreeAnchorStr (Anchor); Cfe_PutHiddenParamExaCod (Not->Cod); @@ -673,7 +673,7 @@ static void Tml_Not_PutFormGoToAction (const struct Tml_Not_Note *Not, break; case TL_NOTE_NOTICE: Frm_SetAnchorStr (Not->Cod,&Anchor); - Frm_BeginFormUniqueAnchor (TL_DefaultActions[Not->NoteType], + Frm_BeginFormUniqueAnchor (TL_DefaultActions[Not->Type], Anchor); Frm_FreeAnchorStr (Anchor); Not_PutHiddenParamNotCod (Not->Cod); @@ -686,16 +686,16 @@ static void Tml_Not_PutFormGoToAction (const struct Tml_Not_Note *Not, /***** Icon and link to go to action *****/ /* Begin button */ - HTM_BUTTON_SUBMIT_Begin (Txt_TIMELINE_NOTE[Not->NoteType], + HTM_BUTTON_SUBMIT_Begin (Txt_TIMELINE_NOTE[Not->Type], Str_BuildStringStr ("BT_LINK %s ICO_HIGHLIGHT", The_ClassFormInBoxBold[Gbl.Prefs.Theme]), NULL); Str_FreeString (); /* Icon and text */ - Ico_PutIcon (TL_Icons[Not->NoteType], - Txt_TIMELINE_NOTE[Not->NoteType],"CONTEXT_ICO_x16"); - HTM_TxtF (" %s",Txt_TIMELINE_NOTE[Not->NoteType]); + Ico_PutIcon (TL_Icons[Not->Type], + Txt_TIMELINE_NOTE[Not->Type],"CONTEXT_ICO_x16"); + HTM_TxtF (" %s",Txt_TIMELINE_NOTE[Not->Type]); /* End button */ HTM_BUTTON_End (); @@ -717,7 +717,7 @@ void Tml_Not_GetNoteSummary (const struct Tml_Not_Note *Not, { SummaryStr[0] = '\0'; - switch (Not->NoteType) + switch (Not->Type) { case TL_NOTE_UNKNOWN: break; @@ -878,14 +878,14 @@ static void Tml_Not_PutFormToRemoveNote (const struct Tml_Timeline *Timeline, /***************** Store and publish a note into database ********************/ /*****************************************************************************/ -void Tml_Not_StoreAndPublishNote (Tml_Not_NoteType_t NoteType,long Cod) +void Tml_Not_StoreAndPublishNote (Tml_Not_Type_t NoteType,long Cod) { struct Tml_Pub_Publication Pub; Tml_Not_StoreAndPublishNoteInternal (NoteType,Cod,&Pub); } -void Tml_Not_StoreAndPublishNoteInternal (Tml_Not_NoteType_t NoteType,long Cod, +void Tml_Not_StoreAndPublishNoteInternal (Tml_Not_Type_t NoteType,long Cod, struct Tml_Pub_Publication *Pub) { long HieCod; // Hierarchy code (institution/center/degree/course) @@ -918,7 +918,7 @@ void Tml_Not_StoreAndPublishNoteInternal (Tml_Not_NoteType_t NoteType,long Cod, /***** Publish note in timeline *****/ Pub->PublisherCod = Gbl.Usrs.Me.UsrDat.UsrCod; Pub->NotCod = Tml_DB_CreateNewNote (NoteType,Cod,Pub->PublisherCod,HieCod); - Pub->PubType = Tml_Pub_ORIGINAL_NOTE; + Pub->Type = Tml_Pub_ORIGINAL_NOTE; Tml_Pub_PublishPubInTimeline (Pub); } @@ -931,7 +931,7 @@ void Tml_Not_MarkNoteOneFileAsUnavailable (const char *Path) extern const Brw_FileBrowser_t Brw_DB_FileBrowserForDB_files[Brw_NUM_TYPES_FILE_BROWSER]; Brw_FileBrowser_t FileBrowser = Brw_DB_FileBrowserForDB_files[Gbl.FileBrowser.Type]; long FilCod; - Tml_Not_NoteType_t NoteType; + Tml_Not_Type_t NoteType; switch (FileBrowser) { @@ -993,7 +993,7 @@ void Tml_Not_MarkNotesChildrenOfFolderAsUnavailable (const char *Path) { extern const Brw_FileBrowser_t Brw_DB_FileBrowserForDB_files[Brw_NUM_TYPES_FILE_BROWSER]; Brw_FileBrowser_t FileBrowser = Brw_DB_FileBrowserForDB_files[Gbl.FileBrowser.Type]; - Tml_Not_NoteType_t NoteType; + Tml_Not_Type_t NoteType; switch (FileBrowser) { @@ -1268,7 +1268,7 @@ static void Tml_Not_RemoveNoteMediaAndDBEntries (struct Tml_Not_Note *Not) DB_FreeMySQLResult (&mysql_res); /***** Remove media associated to post *****/ - if (Not->NoteType == TL_NOTE_POST) + if (Not->Type == TL_NOTE_POST) if ((MedCod = Tml_DB_GetMedCodFromPost (Not->Cod)) > 0) Med_RemoveMedia (MedCod); @@ -1291,7 +1291,7 @@ static void Tml_Not_RemoveNoteMediaAndDBEntries (struct Tml_Not_Note *Not) /***** Remove note *****/ Tml_DB_RemoveNote (Not->NotCod); - if (Not->NoteType == TL_NOTE_POST) + if (Not->Type == TL_NOTE_POST) /***** Remove post *****/ Tml_DB_RemovePost (Not->Cod); } @@ -1315,7 +1315,7 @@ static void Tml_Not_GetDataOfNoteFromRow (MYSQL_ROW row,struct Tml_Not_Note *Not Not->NotCod = Str_ConvertStrCodToLongCod (row[0]); /***** Get note type (row[1]) *****/ - Not->NoteType = Tml_Not_GetNoteTypeFromStr (row[1]); + Not->Type = Tml_Not_GetNoteTypeFromStr (row[1]); /***** Get file/post... code (row[2]) *****/ Not->Cod = Str_ConvertStrCodToLongCod (row[2]); @@ -1344,13 +1344,13 @@ static void Tml_Not_GetDataOfNoteFromRow (MYSQL_ROW row,struct Tml_Not_Note *Not /********* Get note type from string number coming from database *************/ /*****************************************************************************/ -static Tml_Not_NoteType_t Tml_Not_GetNoteTypeFromStr (const char *Str) +static Tml_Not_Type_t Tml_Not_GetNoteTypeFromStr (const char *Str) { unsigned UnsignedNum; if (sscanf (Str,"%u",&UnsignedNum) == 1) if (UnsignedNum < TL_NOT_NUM_NOTE_TYPES) - return (Tml_Not_NoteType_t) UnsignedNum; + return (Tml_Not_Type_t) UnsignedNum; return TL_NOTE_UNKNOWN; } @@ -1362,7 +1362,7 @@ static Tml_Not_NoteType_t Tml_Not_GetNoteTypeFromStr (const char *Str) static void Tml_Not_ResetNote (struct Tml_Not_Note *Not) { Not->NotCod = -1L; - Not->NoteType = TL_NOTE_UNKNOWN; + Not->Type = TL_NOTE_UNKNOWN; Not->UsrCod = -1L; Not->HieCod = -1L; Not->Cod = -1L; diff --git a/swad_timeline_note.h b/swad_timeline_note.h index 8c3c1e23..7b3ee096 100644 --- a/swad_timeline_note.h +++ b/swad_timeline_note.h @@ -61,19 +61,25 @@ typedef enum TL_NOTE_FORUM_POST = 11, // Post in global/swad forums /* Analytics tab */ /* Profile tab */ - } Tml_Not_NoteType_t; + } Tml_Not_Type_t; struct Tml_Not_Note { - long NotCod; // Unique code/identifier for each note - Tml_Not_NoteType_t NoteType; // Timeline post, public file, exam announcement, notice, forum post... - long UsrCod; // Publisher - long HieCod; // Hierarchy code (institution/center/degree/course) - long Cod; // Code of file, forum post, notice, timeline post... - bool Unavailable; // File, forum post, notice,... unavailable (removed) - time_t DateTimeUTC; // Date-time of publication in UTC time - unsigned NumShared; // Number of times (users) this note has been shared - unsigned NumFavs; // Number of times (users) this note has been favourited + long NotCod; // Unique code/identifier for each note + Tml_Not_Type_t Type; // Timeline post, public file, + // call for exam, notice, forum post... + long UsrCod; // Publisher + long HieCod; // Hierarchy code + // (institution/center/degree/course) + long Cod; // Code of file, forum post, + // notice, timeline post... + bool Unavailable; // File, forum post, notice,... + // unavailable (removed) + time_t DateTimeUTC; // Date-time of publication in UTC time + unsigned NumShared; // Number of times (users) + // this note has been shared + unsigned NumFavs; // Number of times (users) + // this note has been favourited }; /*****************************************************************************/ @@ -94,8 +100,8 @@ void Tml_Not_WriteAuthorName (const struct UsrData *UsrDat, void Tml_Not_GetNoteSummary (const struct Tml_Not_Note *Not, char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1]); -void Tml_Not_StoreAndPublishNote (Tml_Not_NoteType_t NoteType,long Cod); -void Tml_Not_StoreAndPublishNoteInternal (Tml_Not_NoteType_t NoteType,long Cod, +void Tml_Not_StoreAndPublishNote (Tml_Not_Type_t NoteType,long Cod); +void Tml_Not_StoreAndPublishNoteInternal (Tml_Not_Type_t NoteType,long Cod, struct Tml_Pub_Publication *Pub); void Tml_Not_MarkNoteOneFileAsUnavailable (const char *Path); void Tml_Not_MarkNotesChildrenOfFolderAsUnavailable (const char *Path); diff --git a/swad_timeline_notification.c b/swad_timeline_notification.c index 6b23cfcd..ba858ef8 100644 --- a/swad_timeline_notification.c +++ b/swad_timeline_notification.c @@ -101,7 +101,7 @@ void Tml_Ntf_GetNotifPublication (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1], bool ContentCopied = false; /***** Return nothing on error *****/ - Pub.PubType = Tml_Pub_UNKNOWN; + Pub.Type = Tml_Pub_UNKNOWN; SummaryStr[0] = '\0'; // Return nothing on error Content.Txt[0] = '\0'; @@ -114,7 +114,7 @@ void Tml_Ntf_GetNotifPublication (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1], DB_FreeMySQLResult (&mysql_res); /***** Get summary and content *****/ - switch (Pub.PubType) + switch (Pub.Type) { case Tml_Pub_UNKNOWN: break; @@ -124,7 +124,7 @@ void Tml_Ntf_GetNotifPublication (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1], Not.NotCod = Pub.NotCod; Tml_Not_GetDataOfNoteByCod (&Not); - if (Not.NoteType == TL_NOTE_POST) + if (Not.Type == TL_NOTE_POST) { /***** Get post from database *****/ if (Tml_DB_GetPostByCod (Not.Cod,&mysql_res) == 1) // Result should have a unique row diff --git a/swad_timeline_publication.c b/swad_timeline_publication.c index eedfb511..28e9ac01 100644 --- a/swad_timeline_publication.c +++ b/swad_timeline_publication.c @@ -58,7 +58,7 @@ static void Tml_Pub_UpdateFirstLastPubCodesIntoSession (const struct Tml_Timelin static struct Tml_Pub_Publication *Tml_Pub_SelectTheMostRecentPub (const struct Tml_Pub_SubQueries *SubQueries); -static Tml_Pub_PubType_t Tml_Pub_GetPubTypeFromStr (const char *Str); +static Tml_Pub_Type_t Tml_Pub_GetPubTypeFromStr (const char *Str); /*****************************************************************************/ /*************** Get list of pubications to show in timeline *****************/ @@ -358,7 +358,7 @@ void Tml_Pub_InsertNewPubsInTimeline (struct Tml_Timeline *Timeline) Not.NotCod); // ...from JavaScript... // ...to avoid repeating notes Tml_Not_CheckAndWriteNoteWithTopMsg (Timeline,&Not, - Tml_Pub_GetTopMessage (Pub->PubType), + Tml_Pub_GetTopMessage (Pub->Type), Pub->PublisherCod); HTM_LI_End (); } @@ -386,7 +386,7 @@ void Tml_Pub_ShowOldPubsInTimeline (struct Tml_Timeline *Timeline) /* Write note */ HTM_LI_Begin ("class=\"TL_WIDTH TL_SEP\""); Tml_Not_CheckAndWriteNoteWithTopMsg (Timeline,&Not, - Tml_Pub_GetTopMessage (Pub->PubType), + Tml_Pub_GetTopMessage (Pub->Type), Pub->PublisherCod); HTM_LI_End (); } @@ -396,7 +396,7 @@ void Tml_Pub_ShowOldPubsInTimeline (struct Tml_Timeline *Timeline) /************* Get a top message given the type of publication ***************/ /*****************************************************************************/ -Tml_TopMessage_t Tml_Pub_GetTopMessage (Tml_Pub_PubType_t PubType) +Tml_TopMessage_t Tml_Pub_GetTopMessage (Tml_Pub_Type_t PubType) { static const Tml_TopMessage_t TopMessages[Tml_Pub_NUM_PUB_TYPES] = { @@ -523,21 +523,21 @@ void Tml_Pub_GetDataOfPubFromNextRow (MYSQL_RES *mysql_res, Pub->PubCod = Str_ConvertStrCodToLongCod (row[0]); Pub->NotCod = Str_ConvertStrCodToLongCod (row[1]); Pub->PublisherCod = Str_ConvertStrCodToLongCod (row[2]); - Pub->PubType = Tml_Pub_GetPubTypeFromStr (row[3]); + Pub->Type = Tml_Pub_GetPubTypeFromStr (row[3]); } /*****************************************************************************/ /******* Get publication type from string number coming from database ********/ /*****************************************************************************/ -static Tml_Pub_PubType_t Tml_Pub_GetPubTypeFromStr (const char *Str) +static Tml_Pub_Type_t Tml_Pub_GetPubTypeFromStr (const char *Str) { unsigned UnsignedNum; /***** Get publication type from string *****/ if (sscanf (Str,"%u",&UnsignedNum) == 1) if (UnsignedNum < Tml_Pub_NUM_PUB_TYPES) - return (Tml_Pub_PubType_t) UnsignedNum; + return (Tml_Pub_Type_t) UnsignedNum; return Tml_Pub_UNKNOWN; } diff --git a/swad_timeline_publication.h b/swad_timeline_publication.h index 6c7d45b0..a638ce92 100644 --- a/swad_timeline_publication.h +++ b/swad_timeline_publication.h @@ -51,17 +51,17 @@ typedef enum { Tml_Pub_UNKNOWN = 0, - Tml_Pub_ORIGINAL_NOTE = 1, + Tml_Pub_ORIGINAL_NOTE = 1, Tml_Pub_SHARED_NOTE = 2, Tml_Pub_COMMENT_TO_NOTE = 3, - } Tml_Pub_PubType_t; + } Tml_Pub_Type_t; struct Tml_Pub_Publication { - long PubCod; - long NotCod; + long PubCod; // Publication code + long NotCod; // Note code long PublisherCod; // Sharer or writer of the publication - Tml_Pub_PubType_t PubType; + Tml_Pub_Type_t Type; // Original note, shared note, comment struct Tml_Pub_Publication *Next; // Used for chained list }; @@ -91,7 +91,7 @@ void Tml_Pub_FreeListPubs (struct Tml_Timeline *Timeline); void Tml_Pub_InsertNewPubsInTimeline (struct Tml_Timeline *Timeline); void Tml_Pub_ShowOldPubsInTimeline (struct Tml_Timeline *Timeline); -Tml_TopMessage_t Tml_Pub_GetTopMessage (Tml_Pub_PubType_t PubType); +Tml_TopMessage_t Tml_Pub_GetTopMessage (Tml_Pub_Type_t PubType); void Tml_Pub_PutLinkToViewNewPubs (void); void Tml_Pub_PutLinkToViewOldPubs (void); diff --git a/swad_timeline_share.c b/swad_timeline_share.c index 80058b44..c845b816 100644 --- a/swad_timeline_share.c +++ b/swad_timeline_share.c @@ -121,7 +121,7 @@ static void Tml_Sha_ShaNote (struct Tml_Not_Note *Not) /***** Share (publish note in timeline) *****/ Pub.NotCod = Not->NotCod; Pub.PublisherCod = Gbl.Usrs.Me.UsrDat.UsrCod; - Pub.PubType = Tml_Pub_SHARED_NOTE; + Pub.Type = Tml_Pub_SHARED_NOTE; Tml_Pub_PublishPubInTimeline (&Pub); // Set Pub.PubCod /***** Update number of times this note is shared *****/