From 19c764abf75dfdc2d97d1585dfb2c4ec90809074 Mon Sep 17 00:00:00 2001 From: acanas Date: Tue, 7 Apr 2020 03:01:41 +0200 Subject: [PATCH] Version19.168 --- swad_API.c | 2 +- swad_agenda.c | 4 +- swad_assignment.c | 4 +- swad_attendance.c | 4 +- swad_changelog.h | 3 +- swad_enrolment.c | 6 +- swad_follow.c | 6 +- swad_forum.c | 804 ++++++++++++++++++++++++-------------------- swad_forum.h | 20 +- swad_game.c | 4 +- swad_global.c | 9 - swad_global.h | 9 - swad_message.c | 11 +- swad_notification.c | 122 +++---- swad_notification.h | 3 +- swad_pagination.c | 91 ++--- swad_pagination.h | 6 +- swad_project.c | 4 +- swad_survey.c | 4 +- swad_timeline.c | 39 ++- 20 files changed, 633 insertions(+), 522 deletions(-) diff --git a/swad_API.c b/swad_API.c index 69bee5cac..10af55aef 100644 --- a/swad_API.c +++ b/swad_API.c @@ -3250,7 +3250,7 @@ int swad__getNotifications (struct soap *soap, struct Degree Deg; struct Course Crs; long Cod; - struct Forum ForumSelected; + struct For_Forum ForumSelected; char ForumName[For_MAX_BYTES_FORUM_NAME + 1]; char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1]; char *ContentStr; diff --git a/swad_agenda.c b/swad_agenda.c index e8a8ce157..eab29385b 100644 --- a/swad_agenda.c +++ b/swad_agenda.c @@ -473,7 +473,7 @@ static void Agd_ShowEvents (Agd_AgendaType_t AgendaType) Pag_WriteLinksToPagesCentered (WhatPaginate[AgendaType], &Pagination, (unsigned) Gbl.Agenda.SelectedOrder, - 0); + NULL,0); if (Gbl.Agenda.Num) { @@ -499,7 +499,7 @@ static void Agd_ShowEvents (Agd_AgendaType_t AgendaType) Pag_WriteLinksToPagesCentered (WhatPaginate[AgendaType], &Pagination, (unsigned) Gbl.Agenda.SelectedOrder, - 0); + NULL,0); /***** Button to create a new event *****/ if (AgendaType == Agd_MY_AGENDA) diff --git a/swad_assignment.c b/swad_assignment.c index a3cc57976..17c758a65 100644 --- a/swad_assignment.c +++ b/swad_assignment.c @@ -187,7 +187,7 @@ static void Asg_ShowAllAssignments (struct Asg_Assignments *Assignments) Pag_WriteLinksToPagesCentered (Pag_ASSIGNMENTS, &Pagination, (unsigned) Assignments->SelectedOrder, - 0); + NULL,0); if (Assignments->Num) { @@ -212,7 +212,7 @@ static void Asg_ShowAllAssignments (struct Asg_Assignments *Assignments) Pag_WriteLinksToPagesCentered (Pag_ASSIGNMENTS, &Pagination, (unsigned) Assignments->SelectedOrder, - 0); + NULL,0); /***** Button to create a new assignment *****/ if (Asg_CheckIfICanCreateAssignments ()) diff --git a/swad_attendance.c b/swad_attendance.c index 7a01491c2..ec6aa9973 100644 --- a/swad_attendance.c +++ b/swad_attendance.c @@ -270,7 +270,7 @@ static void Att_ShowAllAttEvents (struct Att_Events *Events) Pag_WriteLinksToPagesCentered (Pag_ATT_EVENTS, &Pagination, (unsigned) Events->SelectedOrder, - 0); + NULL,0); if (Events->Num) { @@ -324,7 +324,7 @@ static void Att_ShowAllAttEvents (struct Att_Events *Events) Pag_WriteLinksToPagesCentered (Pag_ATT_EVENTS, &Pagination, (unsigned) Events->SelectedOrder, - 0); + NULL,0); /***** Button to create a new attendance event *****/ if (ICanEdit) diff --git a/swad_changelog.h b/swad_changelog.h index b5325e304..0c6ac2015 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -497,7 +497,7 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - * En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 19.167 (2020-04-06)" +#define Log_PLATFORM_VERSION "SWAD 19.168 (2020-04-07)" #define CSS_FILE "swad19.146.css" #define JS_FILE "swad19.153.js" /* @@ -550,6 +550,7 @@ Funci // TODO: Bug en SWADroid: loginByUserPasswordKey falla cuando se le pasa como parámetro un DNI + Version 19.168: Apr 07, 2020 Code refactoring in forums. (284866 lines) Version 19.167: Apr 06, 2020 Code refactoring in figures. (284772 lines) Version 19.166.1: Apr 06, 2020 Fixed bug in API function loginByUserPasswordKey, reported by Javier Bueno López. (? lines) Version 19.166: Apr 06, 2020 Code refactoring in banners. (284805 lines) diff --git a/swad_enrolment.c b/swad_enrolment.c index f5a914e60..17d3aa920 100644 --- a/swad_enrolment.c +++ b/swad_enrolment.c @@ -363,7 +363,11 @@ static void Enr_NotifyAfterEnrolment (struct UsrData *UsrDat,Rol_Role_t NewRole) if (CreateNotif) Ntf_StoreNotifyEventToOneUser (NotifyEvent,UsrDat,-1L, (Ntf_Status_t) (NotifyByEmail ? Ntf_STATUS_BIT_EMAIL : - 0)); + 0), + Gbl.Hierarchy.Ins.InsCod, + Gbl.Hierarchy.Ctr.CtrCod, + Gbl.Hierarchy.Deg.DegCod, + Gbl.Hierarchy.Crs.CrsCod); } /*****************************************************************************/ diff --git a/swad_follow.c b/swad_follow.c index bc1e6bf3c..2ae5e6c17 100644 --- a/swad_follow.c +++ b/swad_follow.c @@ -1332,7 +1332,11 @@ static void Fol_FollowUsr (struct UsrData *UsrDat) if (CreateNotif) Ntf_StoreNotifyEventToOneUser (Ntf_EVENT_FOLLOWER,UsrDat,Gbl.Usrs.Me.UsrDat.UsrCod, (Ntf_Status_t) (NotifyByEmail ? Ntf_STATUS_BIT_EMAIL : - 0)); + 0), + Gbl.Hierarchy.Ins.InsCod, + Gbl.Hierarchy.Ctr.CtrCod, + Gbl.Hierarchy.Deg.DegCod, + Gbl.Hierarchy.Crs.CrsCod); } /*****************************************************************************/ diff --git a/swad_forum.c b/swad_forum.c index dfa45e9ec..0972618d1 100644 --- a/swad_forum.c +++ b/swad_forum.c @@ -44,6 +44,7 @@ #include "swad_layout.h" #include "swad_logo.h" #include "swad_notification.h" +#include "swad_pagination.h" #include "swad_parameter.h" #include "swad_profile.h" #include "swad_role.h" @@ -284,6 +285,10 @@ static const unsigned PermissionThreadDeletion[For_NUM_TYPES_FORUM] = #define For_IMAGE_SAVED_MAX_HEIGHT 768 #define For_IMAGE_SAVED_QUALITY 90 // 1 to 100 +/*****************************************************************************/ +/***************************** Private types ***************************/ +/*****************************************************************************/ + /*****************************************************************************/ /***************************** Private prototypes ***************************/ /*****************************************************************************/ @@ -300,7 +305,8 @@ static long For_InsertForumPst (long ThrCod,long UsrCod, static bool For_RemoveForumPst (long PstCod,long MedCod); static unsigned For_NumPstsInThrWithPstCod (long PstCod,long *ThrCod); -static long For_InsertForumThread (long FirstPstCod); +static long For_InsertForumThread (const struct For_Forums *Forums, + long FirstPstCod); static void For_RemoveThreadOnly (long ThrCod); static void For_RemoveThreadAndItsPsts (long ThrCod); static void For_GetThrSubject (long ThrCod,char Subject[Cns_MAX_BYTES_SUBJECT + 1]); @@ -317,79 +323,107 @@ static unsigned For_GetNumPstsInThr (long ThrCod); static unsigned For_GetNumMyPstInThr (long ThrCod); static time_t For_GetThrReadTime (long ThrCod); static void For_DeleteThrFromReadThrs (long ThrCod); -static void For_ShowPostsOfAThread (Ale_AlertType_t AlertType,const char *Message); -static void For_PutIconNewPost (void *Args); -static void For_PutAllHiddenParamsNewPost (void *Args); +static void For_ShowPostsOfAThread (struct For_Forums *Forums, + Ale_AlertType_t AlertType,const char *Message); +static void For_PutIconNewPost (void *Forums); +static void For_PutAllHiddenParamsNewPost (void *Forums); -static void For_ShowAForumPost (unsigned PstNum,long PstCod, +static void For_ShowAForumPost (const struct For_Forums *Forums, + unsigned PstNum,long PstCod, bool LastPst,char LastSubject[Cns_MAX_BYTES_SUBJECT + 1], bool NewPst,bool ICanModerateForum); static void For_GetPstData (long PstCod,long *UsrCod,time_t *CreatTimeUTC, char Subject[Cns_MAX_BYTES_SUBJECT + 1], char Content[Cns_MAX_BYTES_LONG_TEXT + 1], struct Media *Media); -static void For_WriteNumberOfPosts (long UsrCod); +static void For_WriteNumberOfPosts (const struct For_Forums *Forums,long UsrCod); static void For_PutParamForumSet (For_ForumSet_t ForumSet); static void For_PutParamForumLocation (long Location); static void For_PutHiddenParamThrCod (long ThrCod); static void For_PutHiddenParamPstCod (long PstCod); -static void For_ShowForumList (void); +static void For_ShowForumList (struct For_Forums *Forums); static void For_PutIconsForums (void *Args); -static void For_PutFormWhichForums (void); +static void For_PutFormWhichForums (const struct For_Forums *Forums); -static void For_WriteLinksToGblForums (bool IsLastItemInLevel[1 + For_FORUM_MAX_LEVELS]); -static void For_WriteLinksToPlatformForums (bool IsLastForum, +static void For_WriteLinksToGblForums (const struct For_Forums *Forums, + bool IsLastItemInLevel[1 + For_FORUM_MAX_LEVELS]); +static void For_WriteLinksToPlatformForums (const struct For_Forums *Forums, + bool IsLastForum, bool IsLastItemInLevel[1 + For_FORUM_MAX_LEVELS]); -static long For_WriteLinksToInsForums (long InsCod,bool IsLastIns, +static long For_WriteLinksToInsForums (const struct For_Forums *Forums, + long InsCod,bool IsLastIns, bool IsLastItemInLevel[1 + For_FORUM_MAX_LEVELS]); -static long For_WriteLinksToCtrForums (long CtrCod,bool IsLastCtr, +static long For_WriteLinksToCtrForums (const struct For_Forums *Forums, + long CtrCod,bool IsLastCtr, bool IsLastItemInLevel[1 + For_FORUM_MAX_LEVELS]); -static long For_WriteLinksToDegForums (long DegCod,bool IsLastDeg, +static long For_WriteLinksToDegForums (const struct For_Forums *Forums, + long DegCod,bool IsLastDeg, bool IsLastItemInLevel[1 + For_FORUM_MAX_LEVELS]); -static long For_WriteLinksToCrsForums (long CrsCod,bool IsLastCrs, +static long For_WriteLinksToCrsForums (const struct For_Forums *Forums, + long CrsCod,bool IsLastCrs, bool IsLastItemInLevel[1 + For_FORUM_MAX_LEVELS]); -static void For_WriteLinkToForum (struct Forum *Forum, +static void For_WriteLinkToForum (const struct For_Forums *Forums, + struct For_Forum *Forum, bool Highlight, unsigned Level, bool IsLastItemInLevel[1 + For_FORUM_MAX_LEVELS]); -static unsigned For_GetNumThrsWithNewPstsInForum (struct Forum *Forum, +static unsigned For_GetNumThrsWithNewPstsInForum (struct For_Forum *Forum, unsigned NumThreads); -static unsigned For_GetNumOfThreadsInForumNewerThan (struct Forum *Forum, +static unsigned For_GetNumOfThreadsInForumNewerThan (struct For_Forum *Forum, const char *Time); static unsigned For_GetNumOfUnreadPostsInThr (long ThrCod,unsigned NumPostsInThr); static unsigned For_GetNumOfPostsInThrNewerThan (long ThrCod,const char *Time); static void For_WriteNumberOfThrs (unsigned NumThrs); -static void For_ShowForumThreadsHighlightingOneThread (long ThrCodHighlighted, +static void For_ShowForumThreadsHighlightingOneThread (struct For_Forums *Forums, Ale_AlertType_t AlertType,const char *Message); -static void For_PutIconNewThread (void *Args); -static void For_PutAllHiddenParamsNewThread (void *Args); -static unsigned For_GetNumThrsInForum (struct Forum *Forum); -static void For_ListForumThrs (long ThrCods[Pag_ITEMS_PER_PAGE], +static void For_PutIconNewThread (void *Forums); +static void For_PutAllHiddenParamsNewThread (void *Forums); +static unsigned For_GetNumThrsInForum (struct For_Forum *Forum); +static void For_ListForumThrs (const struct For_Forums *Forums, + long ThrCods[Pag_ITEMS_PER_PAGE], long ThrCodHighlighted, struct Pagination *PaginationThrs); static void For_GetThrData (struct ForumThread *Thr); -static void For_GetParamsForum (void); -static void For_SetForumType (void); -static void For_RestrictAccess (void); +static void For_GetParamsForums (struct For_Forums *Forums); +static void For_SetForumType (struct For_Forums *Forums); +static void For_RestrictAccess (const struct For_Forums *Forums); -static void For_WriteFormForumPst (bool IsReply,const char *Subject); +static void For_WriteFormForumPst (const struct For_Forums *Forums, + bool IsReply,const char *Subject); static void For_UpdateNumUsrsNotifiedByEMailAboutPost (long PstCod,unsigned NumUsrsToBeNotifiedByEMail); -static void For_PutAllHiddenParamsRemThread (void *Args); +static void For_PutAllHiddenParamsRemThread (void *Forums); static bool For_CheckIfICanMoveThreads (void); static long For_GetThrInMyClipboard (void); -static bool For_CheckIfThrBelongsToForum (long ThrCod,struct Forum *Forum); -static void For_MoveThrToCurrentForum (long ThrCod); +static bool For_CheckIfThrBelongsToForum (long ThrCod,struct For_Forum *Forum); +static void For_MoveThrToCurrentForum (const struct For_Forums *Forums); static void For_InsertThrInClipboard (long ThrCod); static void For_RemoveExpiredThrsClipboards (void); static void For_RemoveThrCodFromThrClipboard (long ThrCod); +/*****************************************************************************/ +/********************************** Reset forum ******************************/ +/*****************************************************************************/ + +void For_ResetForums (struct For_Forums *Forums) + { + Forums->ForumSet = For_DEFAULT_FORUM_SET; + Forums->ThreadsOrder = For_DEFAULT_ORDER; + Forums->CurrentPageThrs = 0; + Forums->CurrentPagePsts = 0; + Forums->ForumSelected.Type = For_FORUM_UNKNOWN; + Forums->ForumSelected.Location = -1L; + Forums->ForumSelected.ThrCod = -1L; + Forums->ForumSelected.PstCod = -1L; + Forums->ThreadToMove = -1L; + } + /*****************************************************************************/ /****************************** Enable a forum post **************************/ /*****************************************************************************/ @@ -397,22 +431,25 @@ static void For_RemoveThrCodFromThrClipboard (long ThrCod); void For_EnablePost (void) { extern const char *Txt_FORUM_Post_unbanned; + struct For_Forums Forums; + + /***** Reset forum *****/ + For_ResetForums (&Forums); /***** Get parameters related to forum *****/ - For_GetParamsForum (); + For_GetParamsForums (&Forums); /***** Delete post from table of disabled posts *****/ - For_DeletePstFromDisabledPstTable (Gbl.Forum.ForumSelected.PstCod); + For_DeletePstFromDisabledPstTable (Forums.ForumSelected.PstCod); /***** Show forum list again *****/ - For_ShowForumList (); + For_ShowForumList (&Forums); /***** Show threads again *****/ - For_ShowForumThreadsHighlightingOneThread (Gbl.Forum.ForumSelected.ThrCod, - Ale_SUCCESS,NULL); + For_ShowForumThreadsHighlightingOneThread (&Forums,Ale_SUCCESS,NULL); /***** Show the posts again *****/ - For_ShowPostsOfAThread (Ale_SUCCESS,Txt_FORUM_Post_unbanned); + For_ShowPostsOfAThread (&Forums,Ale_SUCCESS,Txt_FORUM_Post_unbanned); } /*****************************************************************************/ @@ -422,25 +459,25 @@ void For_EnablePost (void) void For_DisablePost (void) { extern const char *Txt_FORUM_Post_banned; + struct For_Forums Forums; - /***** Get parameters related to forum *****/ - For_GetParamsForum (); + /***** Get parameters related to forums *****/ + For_GetParamsForums (&Forums); /***** Check if post really exists, if it has not been removed *****/ - if (For_GetIfForumPstExists (Gbl.Forum.ForumSelected.PstCod)) + if (For_GetIfForumPstExists (Forums.ForumSelected.PstCod)) { /***** Insert post into table of banned posts *****/ - For_InsertPstIntoBannedPstTable (Gbl.Forum.ForumSelected.PstCod); + For_InsertPstIntoBannedPstTable (Forums.ForumSelected.PstCod); /***** Show forum list again *****/ - For_ShowForumList (); + For_ShowForumList (&Forums); /***** Show threads again *****/ - For_ShowForumThreadsHighlightingOneThread (Gbl.Forum.ForumSelected.ThrCod, - Ale_SUCCESS,NULL); + For_ShowForumThreadsHighlightingOneThread (&Forums,Ale_SUCCESS,NULL); /***** Show the posts again *****/ - For_ShowPostsOfAThread (Ale_SUCCESS,Txt_FORUM_Post_banned); + For_ShowPostsOfAThread (&Forums,Ale_SUCCESS,Txt_FORUM_Post_banned); } else Lay_ShowErrorAndExit ("The post to be banned no longer exists."); @@ -598,7 +635,8 @@ static unsigned For_NumPstsInThrWithPstCod (long PstCod,long *ThrCod) /*****************************************************************************/ // Returns the code of the new inserted thread -static long For_InsertForumThread (long FirstPstCod) +static long For_InsertForumThread (const struct For_Forums *Forums, + long FirstPstCod) { /***** Insert new thread in the database *****/ return @@ -607,8 +645,8 @@ static long For_InsertForumThread (long FirstPstCod) " (ForumType,Location,FirstPstCod,LastPstCod)" " VALUES" " (%u,%ld,%ld,%ld)", - (unsigned) Gbl.Forum.ForumSelected.Type, - Gbl.Forum.ForumSelected.Location, + (unsigned) Forums->ForumSelected.Type, + Forums->ForumSelected.Location, FirstPstCod,FirstPstCod); } @@ -683,7 +721,7 @@ static void For_GetThrSubject (long ThrCod,char Subject[Cns_MAX_BYTES_SUBJECT + /*************** Get the forum type and location of a post *******************/ /*****************************************************************************/ -void For_GetForumTypeAndLocationOfAPost (long PstCod,struct Forum *Forum) +void For_GetForumTypeAndLocationOfAPost (long PstCod,struct For_Forum *Forum) { MYSQL_RES *mysql_res; MYSQL_ROW row; @@ -942,7 +980,8 @@ void For_RemoveUsrFromReadThrs (long UsrCod) /************************ Show posts in a thread *****************************/ /*****************************************************************************/ -static void For_ShowPostsOfAThread (Ale_AlertType_t AlertType,const char *Message) +static void For_ShowPostsOfAThread (struct For_Forums *Forums, + Ale_AlertType_t AlertType,const char *Message) { extern const char *Hlp_MESSAGES_Forums_posts; extern const char *Txt_Thread; @@ -963,15 +1002,15 @@ static void For_ShowPostsOfAThread (Ale_AlertType_t AlertType,const char *Messag bool ICanModerateForum = false; /***** Get data of the thread *****/ - Thr.ThrCod = Gbl.Forum.ForumSelected.ThrCod; + Thr.ThrCod = Forums->ForumSelected.ThrCod; For_GetThrData (&Thr); /***** Get if there is a thread ready to be moved *****/ if (For_CheckIfICanMoveThreads ()) - Gbl.Forum.ThreadToMove = For_GetThrInMyClipboard (); + Forums->ThreadToMove = For_GetThrInMyClipboard (); /***** Get thread read time for the current user *****/ - ReadTimeUTC = For_GetThrReadTime (Gbl.Forum.ForumSelected.ThrCod); + ReadTimeUTC = For_GetThrReadTime (Forums->ForumSelected.ThrCod); /***** Show alert after action *****/ HTM_SECTION_Begin (For_FORUM_POSTS_SECTION_ID); @@ -993,14 +1032,14 @@ static void For_ShowPostsOfAThread (Ale_AlertType_t AlertType,const char *Messag "SELECT PstCod,UNIX_TIMESTAMP(CreatTime)" " FROM forum_post" " WHERE ThrCod=%ld ORDER BY PstCod", - Gbl.Forum.ForumSelected.ThrCod); + Forums->ForumSelected.ThrCod); NumPsts = (unsigned) NumRows; LastSubject[0] = '\0'; if (NumPsts) // If there are posts... { /***** Check if I can moderate posts in forum *****/ - switch (Gbl.Forum.ForumSelected.Type) + switch (Forums->ForumSelected.Type) { case For_FORUM_GLOBAL_USRS: case For_FORUM_GLOBAL_TCHS: @@ -1031,16 +1070,16 @@ static void For_ShowPostsOfAThread (Ale_AlertType_t AlertType,const char *Messag /***** Compute variables related to pagination *****/ PaginationPsts.NumItems = NumPsts; - PaginationPsts.CurrentPage = (int) Gbl.Forum.CurrentPagePsts; + PaginationPsts.CurrentPage = (int) Forums->CurrentPagePsts; Pag_CalculatePagination (&PaginationPsts); PaginationPsts.Anchor = For_FORUM_POSTS_SECTION_ID; - Gbl.Forum.CurrentPagePsts = (unsigned) PaginationPsts.CurrentPage; + Forums->CurrentPagePsts = (unsigned) PaginationPsts.CurrentPage; /***** Write links to pages *****/ Pag_WriteLinksToPagesCentered (Pag_POSTS_FORUM, &PaginationPsts, - (unsigned) Gbl.Forum.ThreadsOrder, - Gbl.Forum.ForumSelected.ThrCod); + (unsigned) Forums->ThreadsOrder, + Forums,Forums->ForumSelected.ThrCod); /***** Begin table *****/ HTM_TABLE_BeginWidePadding (2); @@ -1068,16 +1107,16 @@ static void For_ShowPostsOfAThread (Ale_AlertType_t AlertType,const char *Messag Note that database is not updated with the current time, but with the creation time of the most recent post in this page of threads. */ - For_UpdateThrReadTime (Gbl.Forum.ForumSelected.ThrCod, + For_UpdateThrReadTime (Forums->ForumSelected.ThrCod, CreatTimeUTC); /* Show post */ - For_ShowAForumPost (NumPst,PstCod, + For_ShowAForumPost (Forums,NumPst,PstCod, (NumRow == NumRows),LastSubject, NewPst,ICanModerateForum); /* Mark possible notification as seen */ - switch (Gbl.Forum.ForumSelected.Type) + switch (Forums->ForumSelected.Type) { case For_FORUM_COURSE_TCHS: case For_FORUM_COURSE_USRS: @@ -1100,8 +1139,8 @@ static void For_ShowPostsOfAThread (Ale_AlertType_t AlertType,const char *Messag /***** Write again links to pages *****/ Pag_WriteLinksToPagesCentered (Pag_POSTS_FORUM, &PaginationPsts, - (unsigned) Gbl.Forum.ThreadsOrder, - Gbl.Forum.ForumSelected.ThrCod); + (unsigned) Forums->ThreadsOrder, + Forums,Forums->ForumSelected.ThrCod); } /***** Free structure that stores the query result *****/ @@ -1109,7 +1148,7 @@ static void For_ShowPostsOfAThread (Ale_AlertType_t AlertType,const char *Messag /***** Form to write a new post in the thread *****/ HTM_SECTION_Begin (For_NEW_POST_SECTION_ID); - For_WriteFormForumPst (true,LastSubject); + For_WriteFormForumPst (Forums,true,LastSubject); HTM_SECTION_End (); /***** End box *****/ @@ -1121,26 +1160,26 @@ static void For_ShowPostsOfAThread (Ale_AlertType_t AlertType,const char *Messag /*********************** Put icon to write a new post ************************/ /*****************************************************************************/ -static void For_PutIconNewPost (void *Args) +static void For_PutIconNewPost (void *Forums) { extern const char *Txt_New_post; - if (Args) - Ico_PutContextualIconToAdd (For_ActionsSeePstFor[Gbl.Forum.ForumSelected.Type], + if (Forums) + Ico_PutContextualIconToAdd (For_ActionsSeePstFor[((struct For_Forums *) Forums)->ForumSelected.Type], For_NEW_POST_SECTION_ID, For_PutAllHiddenParamsNewPost,&Gbl, Txt_New_post); } -static void For_PutAllHiddenParamsNewPost (void *Args) +static void For_PutAllHiddenParamsNewPost (void *Forums) { - if (Args) - For_PutAllHiddenParamsForum (Gbl.Forum.CurrentPageThrs, // Page of threads = current - UINT_MAX, // Page of posts = last - Gbl.Forum.ForumSet, - Gbl.Forum.ThreadsOrder, - Gbl.Forum.ForumSelected.Location, - Gbl.Forum.ForumSelected.ThrCod, + if (Forums) + For_PutAllHiddenParamsForum (((struct For_Forums *) Forums)->CurrentPageThrs, // Page of threads = current + UINT_MAX, // Page of posts = last + ((struct For_Forums *) Forums)->ForumSet, + ((struct For_Forums *) Forums)->ThreadsOrder, + ((struct For_Forums *) Forums)->ForumSelected.Location, + ((struct For_Forums *) Forums)->ForumSelected.ThrCod, -1L); } @@ -1148,7 +1187,8 @@ static void For_PutAllHiddenParamsNewPost (void *Args) /**************************** Show a post from forum *************************/ /*****************************************************************************/ -static void For_ShowAForumPost (unsigned PstNum,long PstCod, +static void For_ShowAForumPost (const struct For_Forums *Forums, + unsigned PstNum,long PstCod, bool LastPst,char LastSubject[Cns_MAX_BYTES_SUBJECT + 1], bool NewPst,bool ICanModerateForum) { @@ -1228,15 +1268,15 @@ static void For_ShowAForumPost (unsigned PstNum,long PstCod, HTM_TD_Begin ("class=\"CONTEXT_COL\""); if (ICanModerateForum) { - Frm_StartFormAnchor (Enabled ? For_ActionsDisPstFor[Gbl.Forum.ForumSelected.Type] : - For_ActionsEnbPstFor[Gbl.Forum.ForumSelected.Type], + Frm_StartFormAnchor (Enabled ? For_ActionsDisPstFor[Forums->ForumSelected.Type] : + For_ActionsEnbPstFor[Forums->ForumSelected.Type], For_FORUM_POSTS_SECTION_ID); - For_PutAllHiddenParamsForum (Gbl.Forum.CurrentPageThrs, // Page of threads = current - Gbl.Forum.CurrentPagePsts, // Page of posts = current - Gbl.Forum.ForumSet, - Gbl.Forum.ThreadsOrder, - Gbl.Forum.ForumSelected.Location, - Gbl.Forum.ForumSelected.ThrCod, + For_PutAllHiddenParamsForum (Forums->CurrentPageThrs, // Page of threads = current + Forums->CurrentPagePsts, // Page of posts = current + Forums->ForumSet, + Forums->ThreadsOrder, + Forums->ForumSelected.Location, + Forums->ForumSelected.ThrCod, PstCod); Ico_PutIconLink (Enabled ? "eye-green.svg" : "eye-slash-red.svg", @@ -1265,17 +1305,17 @@ static void For_ShowAForumPost (unsigned PstNum,long PstCod, { // Post can be removed if post is the last (without answers) and it's mine if (PstNum == 1) // First and unique post in thread - Frm_StartFormAnchor (For_ActionsDelPstFor[Gbl.Forum.ForumSelected.Type], + Frm_StartFormAnchor (For_ActionsDelPstFor[Forums->ForumSelected.Type], For_FORUM_THREADS_SECTION_ID); else // Last of several posts in thread - Frm_StartFormAnchor (For_ActionsDelPstFor[Gbl.Forum.ForumSelected.Type], + Frm_StartFormAnchor (For_ActionsDelPstFor[Forums->ForumSelected.Type], For_FORUM_POSTS_SECTION_ID); - For_PutAllHiddenParamsForum (Gbl.Forum.CurrentPageThrs, // Page of threads = current - Gbl.Forum.CurrentPagePsts, // Page of posts = current - Gbl.Forum.ForumSet, - Gbl.Forum.ThreadsOrder, - Gbl.Forum.ForumSelected.Location, - Gbl.Forum.ForumSelected.ThrCod, + For_PutAllHiddenParamsForum (Forums->CurrentPageThrs, // Page of threads = current + Forums->CurrentPagePsts, // Page of posts = current + Forums->ForumSet, + Forums->ThreadsOrder, + Forums->ForumSelected.Location, + Forums->ForumSelected.ThrCod, PstCod); Ico_PutIconRemove (); Frm_EndForm (); @@ -1289,7 +1329,7 @@ static void For_ShowAForumPost (unsigned PstNum,long PstCod, Msg_WriteMsgAuthor (&UsrDat,Enabled,NULL); if (Enabled) /* Write number of posts from this user */ - For_WriteNumberOfPosts (UsrDat.UsrCod); + For_WriteNumberOfPosts (Forums,UsrDat.UsrCod); HTM_TD_End (); /***** Write post content *****/ @@ -1419,7 +1459,7 @@ void For_GetSummaryAndContentForumPst (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1 /*************** Write number of posts in a forum of an user *****************/ /*****************************************************************************/ -static void For_WriteNumberOfPosts (long UsrCod) +static void For_WriteNumberOfPosts (const struct For_Forums *Forums,long UsrCod) { extern const char *Txt_FORUM_post; extern const char *Txt_FORUM_posts; @@ -1430,9 +1470,9 @@ static void For_WriteNumberOfPosts (long UsrCod) HTM_DIV_Begin ("class=\"AUTHOR_TXT LT\""); /***** Get number of posts from database *****/ - if (Gbl.Forum.ForumSelected.Location > 0) + if (Forums->ForumSelected.Location > 0) sprintf (SubQuery," AND forum_thread.Location=%ld", - Gbl.Forum.ForumSelected.Location); + Forums->ForumSelected.Location); else SubQuery[0] = '\0'; NumPsts = @@ -1443,7 +1483,7 @@ static void For_WriteNumberOfPosts (long UsrCod) " AND forum_post.ThrCod=forum_thread.ThrCod" " AND forum_thread.ForumType=%u%s", UsrCod, - (unsigned) Gbl.Forum.ForumSelected.Type,SubQuery); + (unsigned) Forums->ForumSelected.Type,SubQuery); /***** Write number of threads and number of posts *****/ HTM_TxtF ("[%u %s]",NumPsts,NumPsts == 1 ? Txt_FORUM_post : @@ -1520,7 +1560,7 @@ static void For_PutHiddenParamPstCod (long PstCod) /************************** Show list of available forums ********************/ /*****************************************************************************/ -static void For_ShowForumList (void) +static void For_ShowForumList (struct For_Forums *Forums) { extern const char *Hlp_MESSAGES_Forums; extern const char *Txt_Forums; @@ -1546,7 +1586,7 @@ static void For_ShowForumList (void) /***** Get if there is a thread ready to be moved *****/ if (For_CheckIfICanMoveThreads ()) - Gbl.Forum.ThreadToMove = For_GetThrInMyClipboard (); + Forums->ThreadToMove = For_GetThrInMyClipboard (); /***** Fill the list with the institutions I belong to *****/ Usr_GetMyInstits (); @@ -1557,14 +1597,14 @@ static void For_ShowForumList (void) Hlp_MESSAGES_Forums,Box_NOT_CLOSABLE); /***** Put a form to select which forums *****/ - For_PutFormWhichForums (); + For_PutFormWhichForums (Forums); /***** Start list *****/ HTM_UL_Begin ("class=\"LIST_TREE\""); /***** Links to global forums *****/ - For_WriteLinksToGblForums (IsLastItemInLevel); - switch (Gbl.Forum.ForumSet) + For_WriteLinksToGblForums (Forums,IsLastItemInLevel); + switch (Forums->ForumSet) { case For_ONLY_CURRENT_FORUMS: if (Gbl.Hierarchy.Ins.InsCod > 0) @@ -1578,7 +1618,7 @@ static void For_ShowForumList (void) ICanSeeInsForum = false; /***** Links to forums about the platform *****/ - For_WriteLinksToPlatformForums (!ICanSeeInsForum,IsLastItemInLevel); + For_WriteLinksToPlatformForums (Forums,!ICanSeeInsForum,IsLastItemInLevel); if (ICanSeeInsForum) { @@ -1588,7 +1628,7 @@ static void For_ShowForumList (void) ICanSeeCtrForum = Usr_CheckIfIBelongToCtr (Gbl.Hierarchy.Ctr.CtrCod); /***** Links to forums of current institution *****/ - if (For_WriteLinksToInsForums (Gbl.Hierarchy.Ins.InsCod, + if (For_WriteLinksToInsForums (Forums,Gbl.Hierarchy.Ins.InsCod, true, IsLastItemInLevel) > 0) if (ICanSeeCtrForum) @@ -1599,18 +1639,21 @@ static void For_ShowForumList (void) ICanSeeDegForum = Usr_CheckIfIBelongToDeg (Gbl.Hierarchy.Deg.DegCod); /***** Links to forums of current centre *****/ - if (For_WriteLinksToCtrForums (Gbl.Hierarchy.Ctr.CtrCod, + if (For_WriteLinksToCtrForums (Forums, + Gbl.Hierarchy.Ctr.CtrCod, true, IsLastItemInLevel) > 0) if (ICanSeeDegForum) /***** Links to forums of current degree *****/ - if (For_WriteLinksToDegForums (Gbl.Hierarchy.Deg.DegCod, + if (For_WriteLinksToDegForums (Forums, + Gbl.Hierarchy.Deg.DegCod, true, IsLastItemInLevel) > 0) if (Gbl.Usrs.Me.IBelongToCurrentCrs || Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM) /***** Links to forums of current degree *****/ - For_WriteLinksToCrsForums (Gbl.Hierarchy.Crs.CrsCod, + For_WriteLinksToCrsForums (Forums, + Gbl.Hierarchy.Crs.CrsCod, true, IsLastItemInLevel); } @@ -1618,7 +1661,7 @@ static void For_ShowForumList (void) break; case For_ALL_MY_FORUMS: /***** Links to forums about the platform *****/ - For_WriteLinksToPlatformForums ((Gbl.Usrs.Me.MyInss.Num == 0),IsLastItemInLevel); + For_WriteLinksToPlatformForums (Forums,(Gbl.Usrs.Me.MyInss.Num == 0),IsLastItemInLevel); /***** Links to forums of users from my institutions, the degrees in each institution and the courses in each degree *****/ for (NumMyIns = 0; @@ -1628,7 +1671,8 @@ static void For_ShowForumList (void) InsCod = Gbl.Usrs.Me.MyInss.Inss[NumMyIns].InsCod; /* Links to forums of this institution */ - For_WriteLinksToInsForums (InsCod, + For_WriteLinksToInsForums (Forums, + InsCod, (NumMyIns == Gbl.Usrs.Me.MyInss.Num - 1), IsLastItemInLevel); @@ -1645,7 +1689,8 @@ static void For_ShowForumList (void) CtrCod = Str_ConvertStrCodToLongCod (row[0]); /* Links to forums of this centre */ - if (For_WriteLinksToCtrForums (CtrCod, + if (For_WriteLinksToCtrForums (Forums, + CtrCod, (NumCtr == NumCtrs - 1), IsLastItemInLevel) > 0) { @@ -1662,7 +1707,8 @@ static void For_ShowForumList (void) DegCod = Str_ConvertStrCodToLongCod (row[0]); /* Links to forums of this degree */ - if (For_WriteLinksToDegForums (DegCod, + if (For_WriteLinksToDegForums (Forums, + DegCod, (NumDeg == NumDegs - 1), IsLastItemInLevel) > 0) { @@ -1679,7 +1725,8 @@ static void For_ShowForumList (void) CrsCod = Str_ConvertStrCodToLongCod (row[0]); /* Links to forums of this course */ - For_WriteLinksToCrsForums (CrsCod, + For_WriteLinksToCrsForums (Forums, + CrsCod, (NumCrs == NumCrss - 1), IsLastItemInLevel); } @@ -1724,7 +1771,7 @@ static void For_PutIconsForums (void *Args) /*************** Put form to select which forums I want to see ***************/ /*****************************************************************************/ -static void For_PutFormWhichForums (void) +static void For_PutFormWhichForums (const struct For_Forums *Forums) { extern const char *Txt_FORUM_WHICH_FORUM[For_NUM_FORUM_SETS]; For_ForumSet_t ForumSet; @@ -1733,7 +1780,7 @@ static void For_PutFormWhichForums (void) - all my forums - only the forums of current institution/degree/course *****/ Frm_StartForm (ActSeeFor); - Dat_PutHiddenParamOrder (Gbl.Forum.ThreadsOrder); + Dat_PutHiddenParamOrder (Forums->ThreadsOrder); HTM_DIV_Begin ("class=\"SEL_BELOW_TITLE\""); HTM_UL_Begin (NULL); @@ -1746,7 +1793,8 @@ static void For_PutFormWhichForums (void) HTM_INPUT_RADIO ("ForumSet",true, "value=\"%u\"%s", (unsigned) ForumSet, - (ForumSet == Gbl.Forum.ForumSet) ? " checked=\"checked\"" : ""); + (ForumSet == Forums->ForumSet) ? " checked=\"checked\"" : + ""); HTM_Txt (Txt_FORUM_WHICH_FORUM[ForumSet]); HTM_LABEL_End (); HTM_LI_End (); @@ -1760,11 +1808,12 @@ static void For_PutFormWhichForums (void) /************************* Write links to global forums **********************/ /*****************************************************************************/ -static void For_WriteLinksToGblForums (bool IsLastItemInLevel[1 + For_FORUM_MAX_LEVELS]) +static void For_WriteLinksToGblForums (const struct For_Forums *Forums, + bool IsLastItemInLevel[1 + For_FORUM_MAX_LEVELS]) { bool Highlight; bool ICanSeeTeacherForum; - struct Forum Forum; + struct For_Forum Forum; /***** Can I see teachers's forums? *****/ Rol_GetRolesInAllCrssIfNotYetGot (&Gbl.Usrs.Me.UsrDat); @@ -1775,9 +1824,9 @@ static void For_WriteLinksToGblForums (bool IsLastItemInLevel[1 + For_FORUM_MAX_ /***** Link to forum global *****/ Forum.Type = For_FORUM_GLOBAL_USRS; Forum.Location = -1L; - Highlight = (Gbl.Forum.ForumSelected.Type == For_FORUM_GLOBAL_USRS); + Highlight = (Forums->ForumSelected.Type == For_FORUM_GLOBAL_USRS); IsLastItemInLevel[1] = false; - For_WriteLinkToForum (&Forum,Highlight,0,IsLastItemInLevel); + For_WriteLinkToForum (Forums,&Forum,Highlight,0,IsLastItemInLevel); /***** Link to forum of teachers global *****/ Rol_GetRolesInAllCrssIfNotYetGot (&Gbl.Usrs.Me.UsrDat); @@ -1785,9 +1834,9 @@ static void For_WriteLinksToGblForums (bool IsLastItemInLevel[1 + For_FORUM_MAX_ { Forum.Type = For_FORUM_GLOBAL_TCHS; Forum.Location = -1L; - Highlight = (Gbl.Forum.ForumSelected.Type == For_FORUM_GLOBAL_TCHS); + Highlight = (Forums->ForumSelected.Type == For_FORUM_GLOBAL_TCHS); IsLastItemInLevel[1] = false; - For_WriteLinkToForum (&Forum,Highlight,0,IsLastItemInLevel); + For_WriteLinkToForum (Forums,&Forum,Highlight,0,IsLastItemInLevel); } } @@ -1795,12 +1844,13 @@ static void For_WriteLinksToGblForums (bool IsLastItemInLevel[1 + For_FORUM_MAX_ /****************** Write links to forums about the platform *****************/ /*****************************************************************************/ -static void For_WriteLinksToPlatformForums (bool IsLastForum, +static void For_WriteLinksToPlatformForums (const struct For_Forums *Forums, + bool IsLastForum, bool IsLastItemInLevel[1 + For_FORUM_MAX_LEVELS]) { bool Highlight; bool ICanSeeTeacherForum; - struct Forum Forum; + struct For_Forum Forum; /***** Can I see teachers's forums? *****/ Rol_GetRolesInAllCrssIfNotYetGot (&Gbl.Usrs.Me.UsrDat); @@ -1811,18 +1861,18 @@ static void For_WriteLinksToPlatformForums (bool IsLastForum, /***** Link to forum of users about the platform *****/ Forum.Type = For_FORUM__SWAD__USRS; Forum.Location = -1L; - Highlight = (Gbl.Forum.ForumSelected.Type == For_FORUM__SWAD__USRS); + Highlight = (Forums->ForumSelected.Type == For_FORUM__SWAD__USRS); IsLastItemInLevel[1] = (IsLastForum && !ICanSeeTeacherForum); - For_WriteLinkToForum (&Forum,Highlight,0,IsLastItemInLevel); + For_WriteLinkToForum (Forums,&Forum,Highlight,0,IsLastItemInLevel); /***** Link to forum of teachers about the platform *****/ if (ICanSeeTeacherForum) { Forum.Type = For_FORUM__SWAD__TCHS; Forum.Location = -1L; - Highlight = (Gbl.Forum.ForumSelected.Type == For_FORUM__SWAD__TCHS); + Highlight = (Forums->ForumSelected.Type == For_FORUM__SWAD__TCHS); IsLastItemInLevel[1] = IsLastForum; - For_WriteLinkToForum (&Forum,Highlight,0,IsLastItemInLevel); + For_WriteLinkToForum (Forums,&Forum,Highlight,0,IsLastItemInLevel); } } @@ -1831,13 +1881,14 @@ static void For_WriteLinksToPlatformForums (bool IsLastForum, /*****************************************************************************/ // Returns institution code -static long For_WriteLinksToInsForums (long InsCod,bool IsLastIns, +static long For_WriteLinksToInsForums (const struct For_Forums *Forums, + long InsCod,bool IsLastIns, bool IsLastItemInLevel[1 + For_FORUM_MAX_LEVELS]) { bool Highlight; Rol_Role_t MaxRoleInIns; bool ICanSeeTeacherForum; - struct Forum Forum; + struct For_Forum Forum; if (InsCod > 0) { @@ -1849,20 +1900,20 @@ static long For_WriteLinksToInsForums (long InsCod,bool IsLastIns, /***** Link to the forum of users from this institution *****/ Forum.Type = For_FORUM_INSTIT_USRS; Forum.Location = InsCod; - Highlight = (Gbl.Forum.ForumSelected.Type == For_FORUM_INSTIT_USRS && - Gbl.Forum.ForumSelected.Location == InsCod); + Highlight = (Forums->ForumSelected.Type == For_FORUM_INSTIT_USRS && + Forums->ForumSelected.Location == InsCod); IsLastItemInLevel[1] = (IsLastIns && !ICanSeeTeacherForum); - For_WriteLinkToForum (&Forum,Highlight,1,IsLastItemInLevel); + For_WriteLinkToForum (Forums,&Forum,Highlight,1,IsLastItemInLevel); /***** Link to forum of teachers from this institution *****/ if (ICanSeeTeacherForum) { Forum.Type = For_FORUM_INSTIT_TCHS; Forum.Location = InsCod; - Highlight = (Gbl.Forum.ForumSelected.Type == For_FORUM_INSTIT_TCHS && - Gbl.Forum.ForumSelected.Location == InsCod); + Highlight = (Forums->ForumSelected.Type == For_FORUM_INSTIT_TCHS && + Forums->ForumSelected.Location == InsCod); IsLastItemInLevel[1] = IsLastIns; - For_WriteLinkToForum (&Forum,Highlight,1,IsLastItemInLevel); + For_WriteLinkToForum (Forums,&Forum,Highlight,1,IsLastItemInLevel); } } return InsCod; @@ -1873,13 +1924,14 @@ static long For_WriteLinksToInsForums (long InsCod,bool IsLastIns, /*****************************************************************************/ // Returns centre code -static long For_WriteLinksToCtrForums (long CtrCod,bool IsLastCtr, +static long For_WriteLinksToCtrForums (const struct For_Forums *Forums, + long CtrCod,bool IsLastCtr, bool IsLastItemInLevel[1 + For_FORUM_MAX_LEVELS]) { bool Highlight; Rol_Role_t MaxRoleInCtr; bool ICanSeeTeacherForum; - struct Forum Forum; + struct For_Forum Forum; if (CtrCod > 0) { @@ -1891,20 +1943,20 @@ static long For_WriteLinksToCtrForums (long CtrCod,bool IsLastCtr, /***** Link to the forum of users from this centre *****/ Forum.Type = For_FORUM_CENTRE_USRS; Forum.Location = CtrCod; - Highlight = (Gbl.Forum.ForumSelected.Type == For_FORUM_CENTRE_USRS && - Gbl.Forum.ForumSelected.Location == CtrCod); + Highlight = (Forums->ForumSelected.Type == For_FORUM_CENTRE_USRS && + Forums->ForumSelected.Location == CtrCod); IsLastItemInLevel[2] = (IsLastCtr && !ICanSeeTeacherForum); - For_WriteLinkToForum (&Forum,Highlight,2,IsLastItemInLevel); + For_WriteLinkToForum (Forums,&Forum,Highlight,2,IsLastItemInLevel); /***** Link to forum of teachers from this centre *****/ if (ICanSeeTeacherForum) { Forum.Type = For_FORUM_CENTRE_TCHS; Forum.Location = CtrCod; - Highlight = (Gbl.Forum.ForumSelected.Type == For_FORUM_CENTRE_TCHS && - Gbl.Forum.ForumSelected.Location == CtrCod); + Highlight = (Forums->ForumSelected.Type == For_FORUM_CENTRE_TCHS && + Forums->ForumSelected.Location == CtrCod); IsLastItemInLevel[2] = IsLastCtr; - For_WriteLinkToForum (&Forum,Highlight,2,IsLastItemInLevel); + For_WriteLinkToForum (Forums,&Forum,Highlight,2,IsLastItemInLevel); } } return CtrCod; @@ -1915,13 +1967,14 @@ static long For_WriteLinksToCtrForums (long CtrCod,bool IsLastCtr, /*****************************************************************************/ // Returns degree code -static long For_WriteLinksToDegForums (long DegCod,bool IsLastDeg, +static long For_WriteLinksToDegForums (const struct For_Forums *Forums, + long DegCod,bool IsLastDeg, bool IsLastItemInLevel[1 + For_FORUM_MAX_LEVELS]) { bool Highlight; Rol_Role_t MaxRoleInDeg; bool ICanSeeTeacherForum; - struct Forum Forum; + struct For_Forum Forum; if (DegCod > 0) { @@ -1933,20 +1986,20 @@ static long For_WriteLinksToDegForums (long DegCod,bool IsLastDeg, /***** Link to the forum of users from this degree *****/ Forum.Type = For_FORUM_DEGREE_USRS; Forum.Location = DegCod; - Highlight = (Gbl.Forum.ForumSelected.Type == For_FORUM_DEGREE_USRS && - Gbl.Forum.ForumSelected.Location == DegCod); + Highlight = (Forums->ForumSelected.Type == For_FORUM_DEGREE_USRS && + Forums->ForumSelected.Location == DegCod); IsLastItemInLevel[3] = (IsLastDeg && !ICanSeeTeacherForum); - For_WriteLinkToForum (&Forum,Highlight,3,IsLastItemInLevel); + For_WriteLinkToForum (Forums,&Forum,Highlight,3,IsLastItemInLevel); /***** Link to forum of teachers from this degree *****/ if (ICanSeeTeacherForum) { Forum.Type = For_FORUM_DEGREE_TCHS; Forum.Location = DegCod; - Highlight = (Gbl.Forum.ForumSelected.Type == For_FORUM_DEGREE_TCHS && - Gbl.Forum.ForumSelected.Location == DegCod); + Highlight = (Forums->ForumSelected.Type == For_FORUM_DEGREE_TCHS && + Forums->ForumSelected.Location == DegCod); IsLastItemInLevel[3] = IsLastDeg; - For_WriteLinkToForum (&Forum,Highlight,3,IsLastItemInLevel); + For_WriteLinkToForum (Forums,&Forum,Highlight,3,IsLastItemInLevel); } } return DegCod; @@ -1957,13 +2010,14 @@ static long For_WriteLinksToDegForums (long DegCod,bool IsLastDeg, /*****************************************************************************/ // Returns course code -static long For_WriteLinksToCrsForums (long CrsCod,bool IsLastCrs, +static long For_WriteLinksToCrsForums (const struct For_Forums *Forums, + long CrsCod,bool IsLastCrs, bool IsLastItemInLevel[1 + For_FORUM_MAX_LEVELS]) { bool Highlight; Rol_Role_t MyRoleInCrs; bool ICanSeeTeacherForum; - struct Forum Forum; + struct For_Forum Forum; if (CrsCod > 0) { @@ -1975,20 +2029,20 @@ static long For_WriteLinksToCrsForums (long CrsCod,bool IsLastCrs, /***** Link to the forum of users from this course *****/ Forum.Type = For_FORUM_COURSE_USRS; Forum.Location = CrsCod; - Highlight = (Gbl.Forum.ForumSelected.Type == For_FORUM_COURSE_USRS && - Gbl.Forum.ForumSelected.Location == CrsCod); + Highlight = (Forums->ForumSelected.Type == For_FORUM_COURSE_USRS && + Forums->ForumSelected.Location == CrsCod); IsLastItemInLevel[4] = (IsLastCrs && !ICanSeeTeacherForum); - For_WriteLinkToForum (&Forum,Highlight,4,IsLastItemInLevel); + For_WriteLinkToForum (Forums,&Forum,Highlight,4,IsLastItemInLevel); /***** Link to forum of teachers from this course *****/ if (ICanSeeTeacherForum) { Forum.Type = For_FORUM_COURSE_TCHS; Forum.Location = CrsCod; - Highlight = (Gbl.Forum.ForumSelected.Type == For_FORUM_COURSE_TCHS && - Gbl.Forum.ForumSelected.Location == CrsCod); + Highlight = (Forums->ForumSelected.Type == For_FORUM_COURSE_TCHS && + Forums->ForumSelected.Location == CrsCod); IsLastItemInLevel[4] = IsLastCrs; - For_WriteLinkToForum (&Forum,Highlight,4,IsLastItemInLevel); + For_WriteLinkToForum (Forums,&Forum,Highlight,4,IsLastItemInLevel); } } return CrsCod; @@ -1998,7 +2052,8 @@ static long For_WriteLinksToCrsForums (long CrsCod,bool IsLastCrs, /********************** Write title and link to a forum **********************/ /*****************************************************************************/ -static void For_WriteLinkToForum (struct Forum *Forum, +static void For_WriteLinkToForum (const struct For_Forums *Forums, + struct For_Forum *Forum, bool Highlight, unsigned Level, bool IsLastItemInLevel[1 + For_FORUM_MAX_LEVELS]) @@ -2025,10 +2080,10 @@ static void For_WriteLinkToForum (struct Forum *Forum, Lay_IndentDependingOnLevel (Level,IsLastItemInLevel); /***** Write paste button used to move a thread in clipboard to this forum *****/ - if (Gbl.Forum.ThreadToMove >= 0) // If I have permission to paste threads and there is a thread ready to be pasted... + if (Forums->ThreadToMove >= 0) // If I have permission to paste threads and there is a thread ready to be pasted... { /* Check if thread to move is yet in current forum */ - if (For_CheckIfThrBelongsToForum (Gbl.Forum.ThreadToMove,Forum)) + if (For_CheckIfThrBelongsToForum (Forums->ThreadToMove,Forum)) Ico_PutIcon ("paste.svg",Txt_Copy_not_allowed,"CONTEXT_OPT ICO_HIDDEN ICO16x16"); else { @@ -2036,10 +2091,10 @@ static void For_WriteLinkToForum (struct Forum *Forum, For_FORUM_THREADS_SECTION_ID); For_PutAllHiddenParamsForum (1, // Page of threads = first 1, // Page of posts = first - Gbl.Forum.ForumSet, - Gbl.Forum.ThreadsOrder, + Forums->ForumSet, + Forums->ThreadsOrder, Forum->Location, - Gbl.Forum.ThreadToMove, + Forums->ThreadToMove, -1L); Ico_PutIconPaste (); Frm_EndForm (); @@ -2051,8 +2106,8 @@ static void For_WriteLinkToForum (struct Forum *Forum, For_FORUM_THREADS_SECTION_ID); For_PutAllHiddenParamsForum (1, // Page of threads = first 1, // Page of posts = first - Gbl.Forum.ForumSet, - Gbl.Forum.ThreadsOrder, + Forums->ForumSet, + Forums->ThreadsOrder, Forum->Location, -1L, -1L); @@ -2110,7 +2165,7 @@ static void For_WriteLinkToForum (struct Forum *Forum, /************************** Set the name of a forum **************************/ /*****************************************************************************/ -void For_SetForumName (struct Forum *Forum, +void For_SetForumName (const struct For_Forum *Forum, char ForumName[For_MAX_BYTES_FORUM_NAME + 1], Lan_Language_t Language,bool UseHTMLEntities) { @@ -2223,7 +2278,7 @@ void For_SetForumName (struct Forum *Forum, /***** Get number of threads with new posts since my last read of a forum ****/ /*****************************************************************************/ -static unsigned For_GetNumThrsWithNewPstsInForum (struct Forum *Forum, +static unsigned For_GetNumThrsWithNewPstsInForum (struct For_Forum *Forum, unsigned NumThreads) { char SubQuery[256]; @@ -2263,7 +2318,7 @@ static unsigned For_GetNumThrsWithNewPstsInForum (struct Forum *Forum, /**** Get number of threads in forum with a modify time > a specified time ***/ /*****************************************************************************/ -static unsigned For_GetNumOfThreadsInForumNewerThan (struct Forum *Forum, +static unsigned For_GetNumOfThreadsInForumNewerThan (struct For_Forum *Forum, const char *Time) { char SubQuery[256]; @@ -2350,21 +2405,26 @@ static void For_WriteNumberOfThrs (unsigned NumThrs) void For_ShowForumTheads (void) { - /***** Get parameters related to forum *****/ - For_GetParamsForum (); + struct For_Forums Forums; + + /***** Reset forum *****/ + For_ResetForums (&Forums); + + /***** Get parameters related to forums *****/ + For_GetParamsForums (&Forums); /***** Show forum list again *****/ - For_ShowForumList (); + For_ShowForumList (&Forums); /***** Show forum threads with no one highlighted *****/ - For_ShowForumThreadsHighlightingOneThread (-1L,Ale_SUCCESS,NULL); + For_ShowForumThreadsHighlightingOneThread (&Forums,Ale_SUCCESS,NULL); } /*****************************************************************************/ /********** Show available threads of a forum highlighting a thread **********/ /*****************************************************************************/ -static void For_ShowForumThreadsHighlightingOneThread (long ThrCodHighlighted, +static void For_ShowForumThreadsHighlightingOneThread (struct For_Forums *Forums, Ale_AlertType_t AlertType,const char *Message) { extern const char *Hlp_MESSAGES_Forums_threads; @@ -2389,16 +2449,16 @@ static void For_ShowForumThreadsHighlightingOneThread (long ThrCodHighlighted, struct Pagination PaginationThrs; /***** Set forum name *****/ - For_SetForumName (&Gbl.Forum.ForumSelected, + For_SetForumName (&Forums->ForumSelected, ForumName,Gbl.Prefs.Language,true); /***** Get threads of a forum from database *****/ - if (Gbl.Forum.ForumSelected.Location > 0) + if (Forums->ForumSelected.Location > 0) sprintf (SubQuery," AND forum_thread.Location=%ld", - Gbl.Forum.ForumSelected.Location); + Forums->ForumSelected.Location); else SubQuery[0] = '\0'; - switch (Gbl.Forum.ThreadsOrder) + switch (Forums->ThreadsOrder) { case Dat_START_TIME: // First post time NumThrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get thread of a forum", @@ -2407,7 +2467,7 @@ static void For_ShowForumThreadsHighlightingOneThread (long ThrCodHighlighted, " WHERE forum_thread.ForumType=%u%s" " AND forum_thread.FirstPstCod=forum_post.PstCod" " ORDER BY forum_post.CreatTime DESC", - (unsigned) Gbl.Forum.ForumSelected.Type,SubQuery); + (unsigned) Forums->ForumSelected.Type,SubQuery); break; case Dat_END_TIME: // Last post time NumThrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get thread of a forum", @@ -2416,7 +2476,7 @@ static void For_ShowForumThreadsHighlightingOneThread (long ThrCodHighlighted, " WHERE forum_thread.ForumType=%u%s" " AND forum_thread.LastPstCod=forum_post.PstCod" " ORDER BY forum_post.CreatTime DESC", - (unsigned) Gbl.Forum.ForumSelected.Type,SubQuery); + (unsigned) Forums->ForumSelected.Type,SubQuery); break; default: // Impossible return; @@ -2424,10 +2484,10 @@ static void For_ShowForumThreadsHighlightingOneThread (long ThrCodHighlighted, /***** Compute variables related to pagination of threads *****/ PaginationThrs.NumItems = NumThrs; - PaginationThrs.CurrentPage = (int) Gbl.Forum.CurrentPageThrs; + PaginationThrs.CurrentPage = (int) Forums->CurrentPageThrs; Pag_CalculatePagination (&PaginationThrs); PaginationThrs.Anchor = For_FORUM_THREADS_SECTION_ID; - Gbl.Forum.CurrentPageThrs = (unsigned) PaginationThrs.CurrentPage; + Forums->CurrentPageThrs = (unsigned) PaginationThrs.CurrentPage; /***** Fill the list of threads for current page *****/ mysql_data_seek (mysql_res,(my_ulonglong) (PaginationThrs.FirstItemVisible - 1)); @@ -2456,7 +2516,7 @@ static void For_ShowForumThreadsHighlightingOneThread (long ThrCodHighlighted, "%s: %s", Txt_Forum,ForumName); Box_BoxBegin (NULL,FrameTitle, - For_PutIconNewThread,&Gbl, + For_PutIconNewThread,Forums, Hlp_MESSAGES_Forums_threads,Box_NOT_CLOSABLE); /***** List the threads *****/ @@ -2465,8 +2525,8 @@ static void For_ShowForumThreadsHighlightingOneThread (long ThrCodHighlighted, /***** Write links to all the pages in the listing of threads *****/ Pag_WriteLinksToPagesCentered (Pag_THREADS_FORUM, &PaginationThrs, - (unsigned) Gbl.Forum.ThreadsOrder, - 0); + (unsigned) Forums->ThreadsOrder, + Forums,0); /***** Heading row *****/ HTM_TABLE_BeginWideMarginPadding (2); @@ -2482,20 +2542,20 @@ static void For_ShowForumThreadsHighlightingOneThread (long ThrCodHighlighted, { HTM_TH_Begin (1,2,"CM"); - Frm_StartFormAnchor (For_ActionsSeeFor[Gbl.Forum.ForumSelected.Type], + Frm_StartFormAnchor (For_ActionsSeeFor[Forums->ForumSelected.Type], For_FORUM_THREADS_SECTION_ID); - For_PutAllHiddenParamsForum (Gbl.Forum.CurrentPageThrs, // Page of threads = current + For_PutAllHiddenParamsForum (Forums->CurrentPageThrs, // Page of threads = current 1, // Page of posts = first - Gbl.Forum.ForumSet, + Forums->ForumSet, Order, - Gbl.Forum.ForumSelected.Location, + Forums->ForumSelected.Location, -1L, -1L); HTM_BUTTON_SUBMIT_Begin (Txt_FORUM_THREAD_HELP_ORDER[Order],"BT_LINK TIT_TBL",NULL); - if (Order == Gbl.Forum.ThreadsOrder) + if (Order == Forums->ThreadsOrder) HTM_U_Begin (); HTM_Txt (Txt_FORUM_THREAD_ORDER[Order]); - if (Order == Gbl.Forum.ThreadsOrder) + if (Order == Forums->ThreadsOrder) HTM_U_End (); HTM_BUTTON_End (); Frm_EndForm (); @@ -2511,7 +2571,7 @@ static void For_ShowForumThreadsHighlightingOneThread (long ThrCodHighlighted, HTM_TR_End (); /***** List the threads *****/ - For_ListForumThrs (ThrCods,ThrCodHighlighted,&PaginationThrs); + For_ListForumThrs (Forums,ThrCods,Forums->ForumSelected.ThrCod,&PaginationThrs); /***** End table *****/ HTM_TABLE_End (); @@ -2519,13 +2579,13 @@ static void For_ShowForumThreadsHighlightingOneThread (long ThrCodHighlighted, /***** Write links to all the pages in the listing of threads *****/ Pag_WriteLinksToPagesCentered (Pag_THREADS_FORUM, &PaginationThrs, - (unsigned) Gbl.Forum.ThreadsOrder, - 0); + (unsigned) Forums->ThreadsOrder, + Forums,0); } /***** Put a form to write the first post of a new thread *****/ HTM_SECTION_Begin (For_NEW_THREAD_SECTION_ID); - For_WriteFormForumPst (false,NULL); + For_WriteFormForumPst (Forums,false,NULL); HTM_SECTION_End (); /***** End box with threads of this forum ****/ @@ -2537,25 +2597,25 @@ static void For_ShowForumThreadsHighlightingOneThread (long ThrCodHighlighted, /********************** Put icon to write a new thread ***********************/ /*****************************************************************************/ -static void For_PutIconNewThread (void *Args) +static void For_PutIconNewThread (void *Forums) { extern const char *Txt_New_thread; - if (Args) - Ico_PutContextualIconToAdd (For_ActionsSeeFor[Gbl.Forum.ForumSelected.Type], + if (Forums) + Ico_PutContextualIconToAdd (For_ActionsSeeFor[((struct For_Forums *) Forums)->ForumSelected.Type], For_NEW_THREAD_SECTION_ID, - For_PutAllHiddenParamsNewThread,&Gbl, + For_PutAllHiddenParamsNewThread,Forums, Txt_New_thread); } -static void For_PutAllHiddenParamsNewThread (void *Args) +static void For_PutAllHiddenParamsNewThread (void *Forums) { - if (Args) + if (Forums) For_PutAllHiddenParamsForum (1, // Page of threads = first 1, // Page of posts = first - Gbl.Forum.ForumSet, - Gbl.Forum.ThreadsOrder, - Gbl.Forum.ForumSelected.Location, + ((struct For_Forums *)Forums)->ForumSet, + ((struct For_Forums *)Forums)->ThreadsOrder, + ((struct For_Forums *)Forums)->ForumSelected.Location, -1L, -1L); } @@ -2977,7 +3037,7 @@ unsigned For_GetNumTotalThrsInForumsOfType (For_ForumType_t ForumType, /******************* Get number of threads in a forum ************************/ /*****************************************************************************/ -static unsigned For_GetNumThrsInForum (struct Forum *Forum) +static unsigned For_GetNumThrsInForum (struct For_Forum *Forum) { char SubQuery[256]; @@ -3240,7 +3300,8 @@ unsigned For_GetNumTotalPstsInForumsOfType (For_ForumType_t ForumType, /************************ List the threads of a forum ************************/ /*****************************************************************************/ -static void For_ListForumThrs (long ThrCods[Pag_ITEMS_PER_PAGE], +static void For_ListForumThrs (const struct For_Forums *Forums, + long ThrCods[Pag_ITEMS_PER_PAGE], long ThrCodHighlighted, struct Pagination *PaginationThrs) { @@ -3306,17 +3367,17 @@ static void For_ListForumThrs (long ThrCods[Pag_ITEMS_PER_PAGE], "ICO16x16"); /***** Put button to remove the thread *****/ - if (PermissionThreadDeletion[Gbl.Forum.ForumSelected.Type] & + if (PermissionThreadDeletion[Forums->ForumSelected.Type] & (1 << Gbl.Usrs.Me.Role.Logged)) // If I have permission to remove thread in this forum... { HTM_BR (); - Frm_StartFormAnchor (For_ActionsReqDelThr[Gbl.Forum.ForumSelected.Type], + Frm_StartFormAnchor (For_ActionsReqDelThr[Forums->ForumSelected.Type], For_REMOVE_THREAD_SECTION_ID); - For_PutAllHiddenParamsForum (Gbl.Forum.CurrentPageThrs, // Page of threads = current + For_PutAllHiddenParamsForum (Forums->CurrentPageThrs, // Page of threads = current 1, // Page of posts = first - Gbl.Forum.ForumSet, - Gbl.Forum.ThreadsOrder, - Gbl.Forum.ForumSelected.Location, + Forums->ForumSet, + Forums->ThreadsOrder, + Forums->ForumSelected.Location, Thr.ThrCod, -1L); Ico_PutIconRemove (); @@ -3327,13 +3388,13 @@ static void For_ListForumThrs (long ThrCods[Pag_ITEMS_PER_PAGE], if (ICanMoveThreads) { HTM_BR (); - Frm_StartFormAnchor (For_ActionsCutThrFor[Gbl.Forum.ForumSelected.Type], + Frm_StartFormAnchor (For_ActionsCutThrFor[Forums->ForumSelected.Type], For_FORUM_THREADS_SECTION_ID); - For_PutAllHiddenParamsForum (Gbl.Forum.CurrentPageThrs, // Page of threads = current + For_PutAllHiddenParamsForum (Forums->CurrentPageThrs, // Page of threads = current 1, // Page of posts = first - Gbl.Forum.ForumSet, - Gbl.Forum.ThreadsOrder, - Gbl.Forum.ForumSelected.Location, + Forums->ForumSet, + Forums->ThreadsOrder, + Forums->ForumSelected.Location, Thr.ThrCod, -1L); Ico_PutIconCut (); @@ -3350,8 +3411,8 @@ static void For_ListForumThrs (long ThrCods[Pag_ITEMS_PER_PAGE], PaginationPsts.Anchor = For_FORUM_POSTS_SECTION_ID; Pag_WriteLinksToPages (Pag_POSTS_FORUM, &PaginationPsts, - (unsigned) Gbl.Forum.ThreadsOrder, - Thr.ThrCod, + (unsigned) Forums->ThreadsOrder, + Forums,Thr.ThrCod, Thr.Enabled[Dat_START_TIME], Thr.Subject, Thr.NumUnreadPosts ? The_ClassFormInBoxBold[Gbl.Prefs.Theme] : @@ -3518,31 +3579,35 @@ static void For_GetThrData (struct ForumThread *Thr) void For_ShowThreadPosts (void) { - /***** Get parameters related to forum *****/ - For_GetParamsForum (); + struct For_Forums Forums; + + /***** Reset forum *****/ + For_ResetForums (&Forums); + + /***** Get parameters related to forums *****/ + For_GetParamsForums (&Forums); /***** Show forum list again *****/ - For_ShowForumList (); + For_ShowForumList (&Forums); /***** Show threads again *****/ - For_ShowForumThreadsHighlightingOneThread (Gbl.Forum.ForumSelected.ThrCod, - Ale_SUCCESS,NULL); + For_ShowForumThreadsHighlightingOneThread (&Forums,Ale_SUCCESS,NULL); /***** Show the posts of that thread *****/ - For_ShowPostsOfAThread (Ale_SUCCESS,NULL); + For_ShowPostsOfAThread (&Forums,Ale_SUCCESS,NULL); } /*****************************************************************************/ /********************* Get parameters related to a forum *********************/ /*****************************************************************************/ -static void For_GetParamsForum (void) +static void For_GetParamsForums (struct For_Forums *Forums) { /***** Set forum type *****/ - For_SetForumType (); + For_SetForumType (Forums); /***** Get parameter with code of course, degree, centre or institution *****/ - switch (Gbl.Forum.ForumSelected.Type) + switch (Forums->ForumSelected.Type) { case For_FORUM_INSTIT_USRS: case For_FORUM_INSTIT_TCHS: @@ -3552,46 +3617,46 @@ static void For_GetParamsForum (void) case For_FORUM_DEGREE_TCHS: case For_FORUM_COURSE_USRS: case For_FORUM_COURSE_TCHS: - Gbl.Forum.ForumSelected.Location = Par_GetParToLong ("Location"); + Forums->ForumSelected.Location = Par_GetParToLong ("Location"); break; default: - Gbl.Forum.ForumSelected.Location = -1L; + Forums->ForumSelected.Location = -1L; break; } /***** Get optional parameter with code of a selected thread *****/ - Gbl.Forum.ForumSelected.ThrCod = Par_GetParToLong ("ThrCod"); + Forums->ForumSelected.ThrCod = Par_GetParToLong ("ThrCod"); /***** Get optional parameter with code of a selected post *****/ - Gbl.Forum.ForumSelected.PstCod = Par_GetParToLong ("PstCod"); + Forums->ForumSelected.PstCod = Par_GetParToLong ("PstCod"); /***** Get which forums I want to see *****/ - Gbl.Forum.ForumSet = (For_ForumSet_t) - Par_GetParToUnsignedLong ("ForumSet", - 0, - For_NUM_FORUM_SETS - 1, - (unsigned long) For_DEFAULT_FORUM_SET); + Forums->ForumSet = (For_ForumSet_t) + Par_GetParToUnsignedLong ("ForumSet", + 0, + For_NUM_FORUM_SETS - 1, + (unsigned long) For_DEFAULT_FORUM_SET); /***** Get order type *****/ - Gbl.Forum.ThreadsOrder = (Dat_StartEndTime_t) - Par_GetParToUnsignedLong ("Order", - 0, - Dat_NUM_START_END_TIME - 1, - (unsigned long) For_DEFAULT_ORDER); + Forums->ThreadsOrder = (Dat_StartEndTime_t) + Par_GetParToUnsignedLong ("Order", + 0, + Dat_NUM_START_END_TIME - 1, + (unsigned long) For_DEFAULT_ORDER); /***** Get optional page numbers for threads and posts *****/ - Gbl.Forum.CurrentPageThrs = Pag_GetParamPagNum (Pag_THREADS_FORUM); - Gbl.Forum.CurrentPagePsts = Pag_GetParamPagNum (Pag_POSTS_FORUM); + Forums->CurrentPageThrs = Pag_GetParamPagNum (Pag_THREADS_FORUM); + Forums->CurrentPagePsts = Pag_GetParamPagNum (Pag_POSTS_FORUM); /***** Restrict access to forum *****/ - For_RestrictAccess (); + For_RestrictAccess (Forums); } /*****************************************************************************/ /***************************** Set the type of forum *************************/ /*****************************************************************************/ -static void For_SetForumType (void) +static void For_SetForumType (struct For_Forums *Forums) { switch (Gbl.Action.Act) { @@ -3602,7 +3667,7 @@ static void For_SetForumType (void) case ActCutThrForGenUsr: case ActPasThrForGenUsr: case ActDelPstForGenUsr: case ActEnbPstForGenUsr: case ActDisPstForGenUsr: - Gbl.Forum.ForumSelected.Type = For_FORUM_GLOBAL_USRS; + Forums->ForumSelected.Type = For_FORUM_GLOBAL_USRS; break; case ActSeeForGenTch: case ActSeePstForGenTch: case ActRcvThrForGenTch: case ActRcvRepForGenTch: @@ -3610,7 +3675,7 @@ static void For_SetForumType (void) case ActCutThrForGenTch: case ActPasThrForGenTch: case ActDelPstForGenTch: case ActEnbPstForGenTch: case ActDisPstForGenTch: - Gbl.Forum.ForumSelected.Type = For_FORUM_GLOBAL_TCHS; + Forums->ForumSelected.Type = For_FORUM_GLOBAL_TCHS; break; case ActSeeForSWAUsr: case ActSeePstForSWAUsr: case ActRcvThrForSWAUsr: case ActRcvRepForSWAUsr: @@ -3618,7 +3683,7 @@ static void For_SetForumType (void) case ActCutThrForSWAUsr: case ActPasThrForSWAUsr: case ActDelPstForSWAUsr: case ActEnbPstForSWAUsr: case ActDisPstForSWAUsr: - Gbl.Forum.ForumSelected.Type = For_FORUM__SWAD__USRS; + Forums->ForumSelected.Type = For_FORUM__SWAD__USRS; break; case ActSeeForSWATch: case ActSeePstForSWATch: case ActRcvThrForSWATch: case ActRcvRepForSWATch: @@ -3626,7 +3691,7 @@ static void For_SetForumType (void) case ActCutThrForSWATch: case ActPasThrForSWATch: case ActDelPstForSWATch: case ActEnbPstForSWATch: case ActDisPstForSWATch: - Gbl.Forum.ForumSelected.Type = For_FORUM__SWAD__TCHS; + Forums->ForumSelected.Type = For_FORUM__SWAD__TCHS; break; case ActSeeForInsUsr: case ActSeePstForInsUsr: case ActRcvThrForInsUsr: case ActRcvRepForInsUsr: @@ -3634,7 +3699,7 @@ static void For_SetForumType (void) case ActCutThrForInsUsr: case ActPasThrForInsUsr: case ActDelPstForInsUsr: case ActEnbPstForInsUsr: case ActDisPstForInsUsr: - Gbl.Forum.ForumSelected.Type = For_FORUM_INSTIT_USRS; + Forums->ForumSelected.Type = For_FORUM_INSTIT_USRS; break; case ActSeeForInsTch: case ActSeePstForInsTch: case ActRcvThrForInsTch: case ActRcvRepForInsTch: @@ -3642,7 +3707,7 @@ static void For_SetForumType (void) case ActCutThrForInsTch: case ActPasThrForInsTch: case ActDelPstForInsTch: case ActEnbPstForInsTch: case ActDisPstForInsTch: - Gbl.Forum.ForumSelected.Type = For_FORUM_INSTIT_TCHS; + Forums->ForumSelected.Type = For_FORUM_INSTIT_TCHS; break; case ActSeeForCtrUsr: case ActSeePstForCtrUsr: case ActRcvThrForCtrUsr: case ActRcvRepForCtrUsr: @@ -3650,7 +3715,7 @@ static void For_SetForumType (void) case ActCutThrForCtrUsr: case ActPasThrForCtrUsr: case ActDelPstForCtrUsr: case ActEnbPstForCtrUsr: case ActDisPstForCtrUsr: - Gbl.Forum.ForumSelected.Type = For_FORUM_CENTRE_USRS; + Forums->ForumSelected.Type = For_FORUM_CENTRE_USRS; break; case ActSeeForCtrTch: case ActSeePstForCtrTch: case ActRcvThrForCtrTch: case ActRcvRepForCtrTch: @@ -3658,7 +3723,7 @@ static void For_SetForumType (void) case ActCutThrForCtrTch: case ActPasThrForCtrTch: case ActDelPstForCtrTch: case ActEnbPstForCtrTch: case ActDisPstForCtrTch: - Gbl.Forum.ForumSelected.Type = For_FORUM_CENTRE_TCHS; + Forums->ForumSelected.Type = For_FORUM_CENTRE_TCHS; break; case ActSeeForDegUsr: case ActSeePstForDegUsr: case ActRcvThrForDegUsr: case ActRcvRepForDegUsr: @@ -3666,7 +3731,7 @@ static void For_SetForumType (void) case ActCutThrForDegUsr: case ActPasThrForDegUsr: case ActDelPstForDegUsr: case ActEnbPstForDegUsr: case ActDisPstForDegUsr: - Gbl.Forum.ForumSelected.Type = For_FORUM_DEGREE_USRS; + Forums->ForumSelected.Type = For_FORUM_DEGREE_USRS; break; case ActSeeForDegTch: case ActSeePstForDegTch: case ActRcvThrForDegTch: case ActRcvRepForDegTch: @@ -3674,7 +3739,7 @@ static void For_SetForumType (void) case ActCutThrForDegTch: case ActPasThrForDegTch: case ActDelPstForDegTch: case ActEnbPstForDegTch: case ActDisPstForDegTch: - Gbl.Forum.ForumSelected.Type = For_FORUM_DEGREE_TCHS; + Forums->ForumSelected.Type = For_FORUM_DEGREE_TCHS; break; case ActSeeForCrsUsr: case ActSeePstForCrsUsr: case ActRcvThrForCrsUsr: case ActRcvRepForCrsUsr: @@ -3682,7 +3747,7 @@ static void For_SetForumType (void) case ActCutThrForCrsUsr: case ActPasThrForCrsUsr: case ActDelPstForCrsUsr: case ActEnbPstForCrsUsr: case ActDisPstForCrsUsr: - Gbl.Forum.ForumSelected.Type = For_FORUM_COURSE_USRS; + Forums->ForumSelected.Type = For_FORUM_COURSE_USRS; break; case ActSeeForCrsTch: case ActSeePstForCrsTch: case ActRcvThrForCrsTch: case ActRcvRepForCrsTch: @@ -3690,10 +3755,10 @@ static void For_SetForumType (void) case ActCutThrForCrsTch: case ActPasThrForCrsTch: case ActDelPstForCrsTch: case ActEnbPstForCrsTch: case ActDisPstForCrsTch: - Gbl.Forum.ForumSelected.Type = For_FORUM_COURSE_TCHS; + Forums->ForumSelected.Type = For_FORUM_COURSE_TCHS; break; default: - Gbl.Forum.ForumSelected.Type = For_FORUM_UNKNOWN; + Forums->ForumSelected.Type = For_FORUM_UNKNOWN; } } @@ -3701,13 +3766,13 @@ static void For_SetForumType (void) /************************** Restrict access to forum *************************/ /*****************************************************************************/ -static void For_RestrictAccess (void) +static void For_RestrictAccess (const struct For_Forums *Forums) { Rol_Role_t MaxRole; bool ICanSeeForum; /***** Restrict access *****/ - switch (Gbl.Forum.ForumSelected.Type) + switch (Forums->ForumSelected.Type) { case For_FORUM_GLOBAL_USRS: case For_FORUM__SWAD__USRS: @@ -3720,53 +3785,53 @@ static void For_RestrictAccess (void) (1 << Rol_TCH))); break; case For_FORUM_INSTIT_USRS: - MaxRole = Rol_GetMyMaxRoleInIns (Gbl.Forum.ForumSelected.Location); + MaxRole = Rol_GetMyMaxRoleInIns (Forums->ForumSelected.Location); ICanSeeForum = (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM || MaxRole == Rol_STD || MaxRole == Rol_NET || MaxRole == Rol_TCH); break; case For_FORUM_INSTIT_TCHS: - MaxRole = Rol_GetMyMaxRoleInIns (Gbl.Forum.ForumSelected.Location); + MaxRole = Rol_GetMyMaxRoleInIns (Forums->ForumSelected.Location); ICanSeeForum = (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM || MaxRole == Rol_NET || MaxRole == Rol_TCH); break; case For_FORUM_CENTRE_USRS: - MaxRole = Rol_GetMyMaxRoleInCtr (Gbl.Forum.ForumSelected.Location); + MaxRole = Rol_GetMyMaxRoleInCtr (Forums->ForumSelected.Location); ICanSeeForum = (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM || MaxRole >= Rol_STD || MaxRole == Rol_NET || MaxRole == Rol_TCH); break; case For_FORUM_CENTRE_TCHS: - MaxRole = Rol_GetMyMaxRoleInCtr (Gbl.Forum.ForumSelected.Location); + MaxRole = Rol_GetMyMaxRoleInCtr (Forums->ForumSelected.Location); ICanSeeForum = (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM || MaxRole == Rol_NET || MaxRole == Rol_TCH); break; case For_FORUM_DEGREE_USRS: - MaxRole = Rol_GetMyMaxRoleInDeg (Gbl.Forum.ForumSelected.Location); + MaxRole = Rol_GetMyMaxRoleInDeg (Forums->ForumSelected.Location); ICanSeeForum = (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM || MaxRole >= Rol_STD || MaxRole == Rol_NET || MaxRole == Rol_TCH); break; case For_FORUM_DEGREE_TCHS: - MaxRole = Rol_GetMyMaxRoleInDeg (Gbl.Forum.ForumSelected.Location); + MaxRole = Rol_GetMyMaxRoleInDeg (Forums->ForumSelected.Location); ICanSeeForum = (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM || MaxRole == Rol_NET || MaxRole == Rol_TCH); break; case For_FORUM_COURSE_USRS: - MaxRole = Rol_GetMyRoleInCrs (Gbl.Forum.ForumSelected.Location); + MaxRole = Rol_GetMyRoleInCrs (Forums->ForumSelected.Location); ICanSeeForum = (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM || MaxRole >= Rol_STD || MaxRole == Rol_NET || MaxRole == Rol_TCH); break; case For_FORUM_COURSE_TCHS: - MaxRole = Rol_GetMyRoleInCrs (Gbl.Forum.ForumSelected.Location); + MaxRole = Rol_GetMyRoleInCrs (Forums->ForumSelected.Location); ICanSeeForum = (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM || MaxRole == Rol_NET || MaxRole == Rol_TCH); @@ -3783,7 +3848,8 @@ static void For_RestrictAccess (void) /********************** Show an area to write a message **********************/ /*****************************************************************************/ -static void For_WriteFormForumPst (bool IsReply,const char *Subject) +static void For_WriteFormForumPst (const struct For_Forums *Forums, + bool IsReply,const char *Subject) { extern const char *Hlp_MESSAGES_Forums_new_post; extern const char *Hlp_MESSAGES_Forums_new_thread; @@ -3807,13 +3873,13 @@ static void For_WriteFormForumPst (bool IsReply,const char *Subject) /***** Begin form *****/ if (IsReply) // Form to write a reply to a post of an existing thread { - Frm_StartFormAnchor (For_ActionsRecRepFor[Gbl.Forum.ForumSelected.Type], + Frm_StartFormAnchor (For_ActionsRecRepFor[Forums->ForumSelected.Type], For_FORUM_POSTS_SECTION_ID); For_PutAllHiddenParamsNewPost (&Gbl); } else // Form to write the first post of a new thread { - Frm_StartFormAnchor (For_ActionsRecThrFor[Gbl.Forum.ForumSelected.Type], + Frm_StartFormAnchor (For_ActionsRecThrFor[Forums->ForumSelected.Type], For_FORUM_POSTS_SECTION_ID); For_PutAllHiddenParamsNewThread (&Gbl); } @@ -3877,6 +3943,7 @@ static void For_WriteFormForumPst (bool IsReply,const char *Subject) void For_ReceiveForumPost (void) { extern const char *Txt_FORUM_Post_sent; + struct For_Forums Forums; bool IsReply = false; long PstCod = 0; unsigned NumUsrsToBeNotifiedByEMail; @@ -3884,8 +3951,11 @@ void For_ReceiveForumPost (void) char Content[Cns_MAX_BYTES_LONG_TEXT + 1]; struct Media Media; + /***** Reset forum *****/ + For_ResetForums (&Forums); + /***** Get parameters related to forum *****/ - For_GetParamsForum (); + For_GetParamsForums (&Forums); /***** Get the code of the thread y the número of page *****/ if (Gbl.Action.Act == ActRcvRepForCrsUsr || Gbl.Action.Act == ActRcvRepForCrsTch || @@ -3916,26 +3986,26 @@ void For_ReceiveForumPost (void) /***** Create a new message *****/ if (IsReply) // This post is a reply to another posts in the thread { - // Gbl.Forum.ForumSelected.ThrCod has been received from form + // For_Forum.ForumSelected.ThrCod has been received from form /***** Create last message of the thread *****/ - PstCod = For_InsertForumPst (Gbl.Forum.ForumSelected.ThrCod,Gbl.Usrs.Me.UsrDat.UsrCod, + PstCod = For_InsertForumPst (Forums.ForumSelected.ThrCod,Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Msg.Subject,Content,&Media); /***** Modify last message of the thread *****/ - For_UpdateThrLastPst (Gbl.Forum.ForumSelected.ThrCod,PstCod); + For_UpdateThrLastPst (Forums.ForumSelected.ThrCod,PstCod); } else // This post is the first of a new thread { /***** Create new thread with unknown first and last message codes *****/ - Gbl.Forum.ForumSelected.ThrCod = For_InsertForumThread (-1L); + Forums.ForumSelected.ThrCod = For_InsertForumThread (&Forums,-1L); /***** Create first (and last) message of the thread *****/ - PstCod = For_InsertForumPst (Gbl.Forum.ForumSelected.ThrCod,Gbl.Usrs.Me.UsrDat.UsrCod, + PstCod = For_InsertForumPst (Forums.ForumSelected.ThrCod,Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Msg.Subject,Content,&Media); /***** Update first and last posts of new thread *****/ - For_UpdateThrFirstAndLastPst (Gbl.Forum.ForumSelected.ThrCod,PstCod,PstCod); + For_UpdateThrFirstAndLastPst (Forums.ForumSelected.ThrCod,PstCod,PstCod); } /***** Free media *****/ @@ -3945,7 +4015,7 @@ void For_ReceiveForumPost (void) Prf_IncrementNumForPstUsr (Gbl.Usrs.Me.UsrDat.UsrCod); /***** Notify the new post to users in course *****/ - switch (Gbl.Forum.ForumSelected.Type) + switch (Forums.ForumSelected.Type) { case For_FORUM_COURSE_USRS: case For_FORUM_COURSE_TCHS: @@ -3962,7 +4032,7 @@ void For_ReceiveForumPost (void) For_UpdateNumUsrsNotifiedByEMailAboutPost (PstCod,NumUsrsToBeNotifiedByEMail); /***** Insert forum post into public social activity *****/ - switch (Gbl.Forum.ForumSelected.Type) // Only if forum is public for any logged user + switch (Forums.ForumSelected.Type) // Only if forum is public for any logged user { case For_FORUM_GLOBAL_USRS: case For_FORUM__SWAD__USRS: @@ -3973,14 +4043,13 @@ void For_ReceiveForumPost (void) } /***** Show forum list again *****/ - For_ShowForumList (); + For_ShowForumList (&Forums); /***** Show threads again *****/ - For_ShowForumThreadsHighlightingOneThread (Gbl.Forum.ForumSelected.ThrCod, - Ale_SUCCESS,NULL); + For_ShowForumThreadsHighlightingOneThread (&Forums,Ale_SUCCESS,NULL); /***** Show again the posts of this thread of the forum *****/ - For_ShowPostsOfAThread (Ale_SUCCESS,Txt_FORUM_Post_sent); + For_ShowPostsOfAThread (&Forums,Ale_SUCCESS,Txt_FORUM_Post_sent); } /*****************************************************************************/ @@ -4004,6 +4073,7 @@ void For_RemovePost (void) { extern const char *Txt_FORUM_Post_and_thread_removed; extern const char *Txt_FORUM_Post_removed; + struct For_Forums Forums; struct UsrData UsrDat; time_t CreatTimeUTC; // Creation time of a message char Subject[Cns_MAX_BYTES_SUBJECT + 1]; @@ -4012,19 +4082,22 @@ void For_RemovePost (void) bool ItsMe; bool ThreadDeleted = false; + /***** Reset forum *****/ + For_ResetForums (&Forums); + /***** Get parameters related to forum *****/ - For_GetParamsForum (); + For_GetParamsForums (&Forums); /***** Initialize image *****/ Med_MediaConstructor (&Media); /***** Get forum post data *****/ - For_GetPstData (Gbl.Forum.ForumSelected.PstCod,&UsrDat.UsrCod,&CreatTimeUTC, + For_GetPstData (Forums.ForumSelected.PstCod,&UsrDat.UsrCod,&CreatTimeUTC, Subject,OriginalContent,&Media); /***** Check if I can remove the post *****/ /* Check if the message really exists, if it has not been removed */ - if (!For_GetIfForumPstExists (Gbl.Forum.ForumSelected.PstCod)) + if (!For_GetIfForumPstExists (Forums.ForumSelected.PstCod)) Lay_ShowErrorAndExit ("The post to remove no longer exists."); /* Check if I am the author of the message */ @@ -4033,44 +4106,42 @@ void For_RemovePost (void) Lay_NoPermissionExit (); /* Check if the message is the last message in the thread */ - if (Gbl.Forum.ForumSelected.PstCod != For_GetLastPstCod (Gbl.Forum.ForumSelected.ThrCod)) + if (Forums.ForumSelected.PstCod != For_GetLastPstCod (Forums.ForumSelected.ThrCod)) Lay_NoPermissionExit (); /***** Remove the post *****/ - ThreadDeleted = For_RemoveForumPst (Gbl.Forum.ForumSelected.PstCod,Media.MedCod); + ThreadDeleted = For_RemoveForumPst (Forums.ForumSelected.PstCod,Media.MedCod); /***** Free image *****/ Med_MediaDestructor (&Media); /***** Mark possible notifications as removed *****/ - Ntf_MarkNotifAsRemoved (Ntf_EVENT_FORUM_POST_COURSE,Gbl.Forum.ForumSelected.PstCod); - Ntf_MarkNotifAsRemoved (Ntf_EVENT_FORUM_REPLY,Gbl.Forum.ForumSelected.PstCod); + Ntf_MarkNotifAsRemoved (Ntf_EVENT_FORUM_POST_COURSE,Forums.ForumSelected.PstCod); + Ntf_MarkNotifAsRemoved (Ntf_EVENT_FORUM_REPLY,Forums.ForumSelected.PstCod); /***** Mark possible social note as unavailable *****/ - switch (Gbl.Forum.ForumSelected.Type) // Only if forum is public for any logged user + switch (Forums.ForumSelected.Type) // Only if forum is public for any logged user { case For_FORUM_GLOBAL_USRS: case For_FORUM__SWAD__USRS: - TL_MarkNoteAsUnavailableUsingNoteTypeAndCod (TL_NOTE_FORUM_POST,Gbl.Forum.ForumSelected.PstCod); + TL_MarkNoteAsUnavailableUsingNoteTypeAndCod (TL_NOTE_FORUM_POST,Forums.ForumSelected.PstCod); break; default: break; } /***** Show forum list again *****/ - For_ShowForumList (); + For_ShowForumList (&Forums); if (ThreadDeleted) /***** Show the remaining threads *****/ - For_ShowForumThreadsHighlightingOneThread (Gbl.Forum.ForumSelected.ThrCod, - Ale_SUCCESS,Txt_FORUM_Post_and_thread_removed); + For_ShowForumThreadsHighlightingOneThread (&Forums,Ale_SUCCESS,Txt_FORUM_Post_and_thread_removed); else { /***** Show threads again *****/ - For_ShowForumThreadsHighlightingOneThread (Gbl.Forum.ForumSelected.ThrCod, - Ale_SUCCESS,NULL); + For_ShowForumThreadsHighlightingOneThread (&Forums,Ale_SUCCESS,NULL); /***** Show the remaining posts *****/ - For_ShowPostsOfAThread (Ale_SUCCESS,Txt_FORUM_Post_removed); + For_ShowPostsOfAThread (&Forums,Ale_SUCCESS,Txt_FORUM_Post_removed); } } @@ -4083,28 +4154,32 @@ void For_RequestRemoveThread (void) extern const char *Txt_Do_you_really_want_to_remove_the_entire_thread_X; extern const char *Txt_Do_you_really_want_to_remove_the_entire_thread; extern const char *Txt_Remove_thread; + struct For_Forums Forums; char Subject[Cns_MAX_BYTES_SUBJECT + 1]; + /***** Reset forum *****/ + For_ResetForums (&Forums); + /***** Get parameters related to forum *****/ - For_GetParamsForum (); + For_GetParamsForums (&Forums); /***** Get subject of the thread to delete *****/ - For_GetThrSubject (Gbl.Forum.ForumSelected.ThrCod,Subject); + For_GetThrSubject (Forums.ForumSelected.ThrCod,Subject); /***** Show forum list again *****/ - For_ShowForumList (); + For_ShowForumList (&Forums); /***** Show question and button to remove the thread *****/ HTM_SECTION_Begin (For_REMOVE_THREAD_SECTION_ID); if (Subject[0]) - Ale_ShowAlertAndButton (For_ActionsDelThrFor[Gbl.Forum.ForumSelected.Type], + Ale_ShowAlertAndButton (For_ActionsDelThrFor[Forums.ForumSelected.Type], For_FORUM_THREADS_SECTION_ID,NULL, For_PutAllHiddenParamsRemThread,&Gbl, Btn_REMOVE_BUTTON,Txt_Remove_thread, Ale_QUESTION,Txt_Do_you_really_want_to_remove_the_entire_thread_X, Subject); else - Ale_ShowAlertAndButton (For_ActionsDelThrFor[Gbl.Forum.ForumSelected.Type], + Ale_ShowAlertAndButton (For_ActionsDelThrFor[Forums.ForumSelected.Type], For_FORUM_THREADS_SECTION_ID,NULL, For_PutAllHiddenParamsRemThread,&Gbl, Btn_REMOVE_BUTTON,Txt_Remove_thread, @@ -4112,19 +4187,18 @@ void For_RequestRemoveThread (void) HTM_SECTION_End (); /***** Show the threads again *****/ - For_ShowForumThreadsHighlightingOneThread (Gbl.Forum.ForumSelected.ThrCod, - Ale_SUCCESS,NULL); + For_ShowForumThreadsHighlightingOneThread (&Forums,Ale_SUCCESS,NULL); } -static void For_PutAllHiddenParamsRemThread (void *Args) +static void For_PutAllHiddenParamsRemThread (void *Forums) { - if (Args) - For_PutAllHiddenParamsForum (Gbl.Forum.CurrentPageThrs, // Page of threads = current + if (Forums) + For_PutAllHiddenParamsForum (((struct For_Forums *) Forums)->CurrentPageThrs, // Page of threads = current 1, // Page of posts = first - Gbl.Forum.ForumSet, - Gbl.Forum.ThreadsOrder, - Gbl.Forum.ForumSelected.Location, - Gbl.Forum.ForumSelected.ThrCod, + ((struct For_Forums *) Forums)->ForumSet, + ((struct For_Forums *) Forums)->ThreadsOrder, + ((struct For_Forums *) Forums)->ForumSelected.Location, + ((struct For_Forums *) Forums)->ForumSelected.ThrCod, -1L); } @@ -4136,35 +4210,37 @@ void For_RemoveThread (void) { extern const char *Txt_Thread_X_removed; extern const char *Txt_Thread_removed; + struct For_Forums Forums; char Subject[Cns_MAX_BYTES_SUBJECT + 1]; char Message[256 + Cns_MAX_BYTES_SUBJECT + 1]; - /***** Get parameters related to forum *****/ - For_GetParamsForum (); + /***** Reset forum *****/ + For_ResetForums (&Forums); - if (PermissionThreadDeletion[Gbl.Forum.ForumSelected.Type] & + /***** Get parameters related to forum *****/ + For_GetParamsForums (&Forums); + + if (PermissionThreadDeletion[Forums.ForumSelected.Type] & (1 << Gbl.Usrs.Me.Role.Logged)) // If I have permission to remove thread in this forum... { /***** Get subject of thread to delete *****/ - For_GetThrSubject (Gbl.Forum.ForumSelected.ThrCod,Subject); + For_GetThrSubject (Forums.ForumSelected.ThrCod,Subject); /***** Remove the thread and all its posts *****/ - For_RemoveThreadAndItsPsts (Gbl.Forum.ForumSelected.ThrCod); + For_RemoveThreadAndItsPsts (Forums.ForumSelected.ThrCod); /***** Show forum list again *****/ - For_ShowForumList (); + For_ShowForumList (&Forums); /***** Show the threads again *****/ if (Subject[0]) { snprintf (Message,sizeof (Message), Txt_Thread_X_removed,Subject); - For_ShowForumThreadsHighlightingOneThread (Gbl.Forum.ForumSelected.ThrCod, - Ale_SUCCESS,Message); + For_ShowForumThreadsHighlightingOneThread (&Forums,Ale_SUCCESS,Message); } else - For_ShowForumThreadsHighlightingOneThread (Gbl.Forum.ForumSelected.ThrCod, - Ale_SUCCESS,Txt_Thread_removed); + For_ShowForumThreadsHighlightingOneThread (&Forums,Ale_SUCCESS,Txt_Thread_removed); } else Lay_NoPermissionExit (); @@ -4178,32 +4254,34 @@ void For_CutThread (void) { extern const char *Txt_Thread_X_marked_to_be_moved; extern const char *Txt_Thread_marked_to_be_moved; + struct For_Forums Forums; char Subject[Cns_MAX_BYTES_SUBJECT + 1]; char Message[256 + Cns_MAX_BYTES_SUBJECT + 1]; + /***** Reset forum *****/ + For_ResetForums (&Forums); + /***** Get parameters related to forum *****/ - For_GetParamsForum (); + For_GetParamsForums (&Forums); /***** Get subject of thread to cut *****/ - For_GetThrSubject (Gbl.Forum.ForumSelected.ThrCod,Subject); + For_GetThrSubject (Forums.ForumSelected.ThrCod,Subject); /***** Mark the thread as cut *****/ - For_InsertThrInClipboard (Gbl.Forum.ForumSelected.ThrCod); + For_InsertThrInClipboard (Forums.ForumSelected.ThrCod); /***** Show forum list again *****/ - For_ShowForumList (); + For_ShowForumList (&Forums); /***** Show the threads again *****/ if (Subject[0]) { snprintf (Message,sizeof (Message), Txt_Thread_X_marked_to_be_moved,Subject); - For_ShowForumThreadsHighlightingOneThread (Gbl.Forum.ForumSelected.ThrCod, - Ale_SUCCESS,Message); + For_ShowForumThreadsHighlightingOneThread (&Forums,Ale_SUCCESS,Message); } else - For_ShowForumThreadsHighlightingOneThread (Gbl.Forum.ForumSelected.ThrCod, - Ale_SUCCESS,Txt_Thread_marked_to_be_moved); + For_ShowForumThreadsHighlightingOneThread (&Forums,Ale_SUCCESS,Txt_Thread_marked_to_be_moved); } @@ -4217,20 +4295,24 @@ void For_PasteThread (void) extern const char *Txt_The_thread_is_already_in_this_forum; extern const char *Txt_Thread_X_moved_to_this_forum; extern const char *Txt_Thread_moved_to_this_forum; + struct For_Forums Forums; char Subject[Cns_MAX_BYTES_SUBJECT + 1]; char Message[256 + Cns_MAX_BYTES_SUBJECT + 1]; + /***** Reset forum *****/ + For_ResetForums (&Forums); + /***** Get parameters related to forum *****/ - For_GetParamsForum (); + For_GetParamsForums (&Forums); /***** Get subject of thread to paste *****/ - For_GetThrSubject (Gbl.Forum.ForumSelected.ThrCod,Subject); + For_GetThrSubject (Forums.ForumSelected.ThrCod,Subject); /***** Check if paste (move) the thread to current forum has sense *****/ - if (For_CheckIfThrBelongsToForum (Gbl.Forum.ForumSelected.ThrCod,&Gbl.Forum.ForumSelected)) + if (For_CheckIfThrBelongsToForum (Forums.ForumSelected.ThrCod,&Forums.ForumSelected)) { /***** Show forum list again *****/ - For_ShowForumList (); + For_ShowForumList (&Forums); /***** Show the threads again *****/ if (Subject[0]) @@ -4238,20 +4320,18 @@ void For_PasteThread (void) snprintf (Message,sizeof (Message), Txt_The_thread_X_is_already_in_this_forum, Subject); - For_ShowForumThreadsHighlightingOneThread (Gbl.Forum.ForumSelected.ThrCod, - Ale_WARNING,Message); + For_ShowForumThreadsHighlightingOneThread (&Forums,Ale_WARNING,Message); } else - For_ShowForumThreadsHighlightingOneThread (Gbl.Forum.ForumSelected.ThrCod, - Ale_WARNING,Txt_The_thread_is_already_in_this_forum); + For_ShowForumThreadsHighlightingOneThread (&Forums,Ale_WARNING,Txt_The_thread_is_already_in_this_forum); } else { /***** Paste (move) the thread to current forum *****/ - For_MoveThrToCurrentForum (Gbl.Forum.ForumSelected.ThrCod); + For_MoveThrToCurrentForum (&Forums); /***** Show forum list again *****/ - For_ShowForumList (); + For_ShowForumList (&Forums); /***** Show the threads again *****/ if (Subject[0]) @@ -4259,12 +4339,10 @@ void For_PasteThread (void) snprintf (Message,sizeof (Message), Txt_Thread_X_moved_to_this_forum, Subject); - For_ShowForumThreadsHighlightingOneThread (Gbl.Forum.ForumSelected.ThrCod, - Ale_SUCCESS,Message); + For_ShowForumThreadsHighlightingOneThread (&Forums,Ale_SUCCESS,Message); } else - For_ShowForumThreadsHighlightingOneThread (Gbl.Forum.ForumSelected.ThrCod, - Ale_SUCCESS,Txt_Thread_moved_to_this_forum); + For_ShowForumThreadsHighlightingOneThread (&Forums,Ale_SUCCESS,Txt_Thread_moved_to_this_forum); } } @@ -4313,7 +4391,7 @@ static long For_GetThrInMyClipboard (void) /***************** Get if a thread belongs to current forum ******************/ /*****************************************************************************/ -static bool For_CheckIfThrBelongsToForum (long ThrCod,struct Forum *Forum) +static bool For_CheckIfThrBelongsToForum (long ThrCod,struct For_Forum *Forum) { char SubQuery[256]; @@ -4332,10 +4410,10 @@ static bool For_CheckIfThrBelongsToForum (long ThrCod,struct Forum *Forum) /************************ Move a thread to current forum *********************/ /*****************************************************************************/ -static void For_MoveThrToCurrentForum (long ThrCod) +static void For_MoveThrToCurrentForum (const struct For_Forums *Forums) { /***** Move a thread to current forum *****/ - switch (Gbl.Forum.ForumSelected.Type) + switch (Forums->ForumSelected.Type) { case For_FORUM_GLOBAL_USRS: case For_FORUM_GLOBAL_TCHS: @@ -4345,8 +4423,8 @@ static void For_MoveThrToCurrentForum (long ThrCod) "UPDATE forum_thread" " SET ForumType=%u,Location=-1" " WHERE ThrCod=%ld", - (unsigned) Gbl.Forum.ForumSelected.Type, - ThrCod); + (unsigned) Forums->ForumSelected.Type, + Forums->ForumSelected.ThrCod); break; case For_FORUM_INSTIT_USRS: case For_FORUM_INSTIT_TCHS: @@ -4354,9 +4432,9 @@ static void For_MoveThrToCurrentForum (long ThrCod) "UPDATE forum_thread" " SET ForumType=%u,Location=%ld" " WHERE ThrCod=%ld", - (unsigned) Gbl.Forum.ForumSelected.Type, - Gbl.Forum.ForumSelected.Location, - ThrCod); + (unsigned) Forums->ForumSelected.Type, + Forums->ForumSelected.Location, + Forums->ForumSelected.ThrCod); break; case For_FORUM_CENTRE_USRS: case For_FORUM_CENTRE_TCHS: @@ -4364,9 +4442,9 @@ static void For_MoveThrToCurrentForum (long ThrCod) "UPDATE forum_thread" " SET ForumType=%u,Location=%ld" " WHERE ThrCod=%ld", - (unsigned) Gbl.Forum.ForumSelected.Type, - Gbl.Forum.ForumSelected.Location, - ThrCod); + (unsigned) Forums->ForumSelected.Type, + Forums->ForumSelected.Location, + Forums->ForumSelected.ThrCod); break; case For_FORUM_DEGREE_USRS: case For_FORUM_DEGREE_TCHS: @@ -4374,9 +4452,9 @@ static void For_MoveThrToCurrentForum (long ThrCod) "UPDATE forum_thread" " SET ForumType=%u,Location=%ld" " WHERE ThrCod=%ld", - (unsigned) Gbl.Forum.ForumSelected.Type, - Gbl.Forum.ForumSelected.Location, - ThrCod); + (unsigned) Forums->ForumSelected.Type, + Forums->ForumSelected.Location, + Forums->ForumSelected.ThrCod); break; case For_FORUM_COURSE_USRS: case For_FORUM_COURSE_TCHS: @@ -4384,9 +4462,9 @@ static void For_MoveThrToCurrentForum (long ThrCod) "UPDATE forum_thread" " SET ForumType=%u,Location=%ld" " WHERE ThrCod=%ld", - (unsigned) Gbl.Forum.ForumSelected.Type, - Gbl.Forum.ForumSelected.Location, - ThrCod); + (unsigned) Forums->ForumSelected.Type, + Forums->ForumSelected.Location, + Forums->ForumSelected.ThrCod); break; default: Lay_ShowErrorAndExit ("Wrong forum."); diff --git a/swad_forum.h b/swad_forum.h index 0a8dca1a7..98bea2c0d 100644 --- a/swad_forum.h +++ b/swad_forum.h @@ -31,7 +31,7 @@ #include "swad_degree.h" #include "swad_institution.h" #include "swad_notification.h" -#include "swad_pagination.h" +// #include "swad_pagination.h" #include "swad_scope.h" #include "swad_string.h" @@ -65,7 +65,7 @@ typedef enum For_FORUM_UNKNOWN = 12, // TODO: Change to 0 (also in database) } For_ForumType_t; // Don't change numbers (used in database) -struct Forum +struct For_Forum { For_ForumType_t Type; // Type of forum long Location; // Code of institution, centre, degree or course @@ -73,6 +73,16 @@ struct Forum long PstCod; // Optional post code }; +struct For_Forums + { + For_ForumSet_t ForumSet; + Dat_StartEndTime_t ThreadsOrder; + unsigned CurrentPageThrs; + unsigned CurrentPagePsts; + struct For_Forum ForumSelected; // Forum type, location, thread and post + long ThreadToMove; + }; + struct ForumThread { long ThrCod; @@ -96,10 +106,12 @@ struct ForumThread /***************************** Public prototypes *****************************/ /*****************************************************************************/ +void For_ResetForums (struct For_Forums *Forums); + void For_EnablePost (void); void For_DisablePost (void); -void For_GetForumTypeAndLocationOfAPost (long PstCod,struct Forum *Forum); +void For_GetForumTypeAndLocationOfAPost (long PstCod,struct For_Forum *Forum); unsigned long For_GetNumPostsUsr (long UsrCod); void For_RemoveUsrFromReadThrs (long UsrCod); @@ -116,7 +128,7 @@ void For_PutAllHiddenParamsForum (unsigned NumPageThreads, long ThrCod, long PstCod); -void For_SetForumName (struct Forum *Forum, +void For_SetForumName (const struct For_Forum *Forum, char ForumName[For_MAX_BYTES_FORUM_NAME + 1], Lan_Language_t Language,bool UseHTMLEntities); diff --git a/swad_game.c b/swad_game.c index afb45d4d5..6d4ad1c4f 100644 --- a/swad_game.c +++ b/swad_game.c @@ -222,7 +222,7 @@ static void Gam_ListAllGames (void) Pag_WriteLinksToPagesCentered (Pag_GAMES, &Pagination, (unsigned) Gbl.Games.SelectedOrder, - 0); + NULL,0); if (Gbl.Games.Num) { @@ -282,7 +282,7 @@ static void Gam_ListAllGames (void) Pag_WriteLinksToPagesCentered (Pag_GAMES, &Pagination, (unsigned) Gbl.Games.SelectedOrder, - 0); + NULL,0); /***** Button to create a new game *****/ if (Gam_CheckIfICanEditGames ()) diff --git a/swad_global.c b/swad_global.c index 4ca2d385a..1e5a6d4d3 100644 --- a/swad_global.c +++ b/swad_global.c @@ -343,15 +343,6 @@ void Gbl_InitializeGlobals (void) /* Public activity */ Gbl.Timeline.Who = TL_DEFAULT_WHO; - /* Forums */ - Gbl.Forum.ForumSet = For_DEFAULT_FORUM_SET; - Gbl.Forum.ForumSelected.Type = For_FORUM_UNKNOWN; - Gbl.Forum.ForumSelected.Location = -1L; - Gbl.Forum.ForumSelected.ThrCod = -1L; - Gbl.Forum.ForumSelected.PstCod = -1L; - Gbl.Forum.ThreadsOrder = For_DEFAULT_ORDER; - Gbl.Forum.ThreadToMove = -1L; - /* User nickname */ Gbl.Usrs.Me.UsrDat.Nickname[0] = '\0'; diff --git a/swad_global.h b/swad_global.h index d8e326d17..0b898fdc9 100644 --- a/swad_global.h +++ b/swad_global.h @@ -540,15 +540,6 @@ struct Globals long NotCod; // Used as parameter about social note to be edited, removed... long PubCod; // Used as parameter about social publishing to be edited, removed... } Timeline; - struct - { - For_ForumSet_t ForumSet; - Dat_StartEndTime_t ThreadsOrder; - unsigned CurrentPageThrs; - unsigned CurrentPagePsts; - struct Forum ForumSelected; // Forum type, location, thread and post - long ThreadToMove; - } Forum; struct { Msg_TypeOfMessages_t TypeOfMessages; diff --git a/swad_message.c b/swad_message.c index c2267f979..76cdb1f24 100644 --- a/swad_message.c +++ b/swad_message.c @@ -46,6 +46,7 @@ #include "swad_ID.h" #include "swad_message.h" #include "swad_notification.h" +#include "swad_pagination.h" #include "swad_parameter.h" #include "swad_photo.h" #include "swad_profile.h" @@ -814,7 +815,11 @@ void Msg_RecMsgFromUsr (void) if (CreateNotif) Ntf_StoreNotifyEventToOneUser (Ntf_EVENT_MESSAGE,&UsrDstData,NewMsgCod, (Ntf_Status_t) (NotifyByEmail ? Ntf_STATUS_BIT_EMAIL : - 0)); + 0), + Gbl.Hierarchy.Ins.InsCod, + Gbl.Hierarchy.Ctr.CtrCod, + Gbl.Hierarchy.Deg.DegCod, + Gbl.Hierarchy.Crs.CrsCod); /***** Show an alert indicating that the message has been sent successfully *****/ Ale_ShowAlert (Ale_SUCCESS,NotifyByEmail ? Txt_message_sent_to_X_notified_by_email : @@ -1835,7 +1840,7 @@ static void Msg_ShowSentOrReceivedMessages (void) Pag_WriteLinksToPagesCentered (WhatPaginate[Gbl.Msg.TypeOfMessages], &Pagination, (unsigned) Dat_START_TIME, // Not used - 0); + NULL,0); /***** Show received / sent messages in this page *****/ HTM_TABLE_BeginWidePadding (2); @@ -1859,7 +1864,7 @@ static void Msg_ShowSentOrReceivedMessages (void) Pag_WriteLinksToPagesCentered (WhatPaginate[Gbl.Msg.TypeOfMessages], &Pagination, (unsigned) Dat_START_TIME, // Not used - 0); + NULL,0); } /***** End box *****/ diff --git a/swad_notification.c b/swad_notification.c index a4c2e0472..33a750a1f 100644 --- a/swad_notification.c +++ b/swad_notification.c @@ -40,6 +40,7 @@ #include "swad_exam.h" #include "swad_follow.h" #include "swad_form.h" +#include "swad_forum.h" #include "swad_global.h" #include "swad_HTML.h" #include "swad_mark.h" @@ -267,7 +268,8 @@ static void Ntf_WriteFormAllNotifications (bool AllNotifications); static bool Ntf_GetAllNotificationsFromForm (void); static bool Ntf_StartFormGoToAction (Ntf_NotifyEvent_t NotifyEvent, - long CrsCod,struct UsrData *UsrDat,long Cod); + long CrsCod,struct UsrData *UsrDat,long Cod, + const struct For_Forums *Forums); static void Ntf_PutHiddenParamNotifyEvent (Ntf_NotifyEvent_t NotifyEvent); static void Ntf_UpdateMyLastAccessToNotifications (void); @@ -321,6 +323,7 @@ void Ntf_ShowMyNotifications (void) struct Degree Deg; struct Course Crs; long Cod; + struct For_Forums Forums; char ForumName[For_MAX_BYTES_FORUM_NAME + 1]; time_t DateTimeUTC; // Date-time of the event Ntf_Status_t Status; @@ -428,8 +431,9 @@ void Ntf_ShowMyNotifications (void) if (NotifyEvent == Ntf_EVENT_FORUM_POST_COURSE || NotifyEvent == Ntf_EVENT_FORUM_REPLY) { - For_GetForumTypeAndLocationOfAPost (Cod,&Gbl.Forum.ForumSelected); - For_SetForumName (&Gbl.Forum.ForumSelected, + For_ResetForums (&Forums); + For_GetForumTypeAndLocationOfAPost (Cod,&Forums.ForumSelected); + For_SetForumName (&Forums.ForumSelected, ForumName,Gbl.Prefs.Language,false); // Set forum name in recipient's language } @@ -472,7 +476,7 @@ void Ntf_ShowMyNotifications (void) HTM_TD_Begin ("class=\"%s LT\" style=\"width:25px;\"",ClassBackground); if (PutLink) - PutLink = Ntf_StartFormGoToAction (NotifyEvent,Crs.CrsCod,&UsrDat,Cod); + PutLink = Ntf_StartFormGoToAction (NotifyEvent,Crs.CrsCod,&UsrDat,Cod,&Forums); if (PutLink) { @@ -489,7 +493,7 @@ void Ntf_ShowMyNotifications (void) HTM_TD_Begin ("class=\"%s LT\"",ClassBackground); if (PutLink) { - PutLink = Ntf_StartFormGoToAction (NotifyEvent,Crs.CrsCod,&UsrDat,Cod); + PutLink = Ntf_StartFormGoToAction (NotifyEvent,Crs.CrsCod,&UsrDat,Cod,&Forums); HTM_BUTTON_SUBMIT_Begin (Txt_NOTIFY_EVENTS_SINGULAR[NotifyEvent],ClassLink,NULL); HTM_Txt (Txt_NOTIFY_EVENTS_SINGULAR[NotifyEvent]); HTM_BUTTON_End (); @@ -514,7 +518,7 @@ void Ntf_ShowMyNotifications (void) NotifyEvent == Ntf_EVENT_FORUM_REPLY) { if (PutLink) - PutLink = Ntf_StartFormGoToAction (NotifyEvent,Crs.CrsCod,&UsrDat,Cod); + PutLink = Ntf_StartFormGoToAction (NotifyEvent,Crs.CrsCod,&UsrDat,Cod,&Forums); if (PutLink) HTM_BUTTON_SUBMIT_Begin (Txt_NOTIFY_EVENTS_SINGULAR[NotifyEvent],ClassLink,NULL); @@ -532,7 +536,7 @@ void Ntf_ShowMyNotifications (void) else { if (PutLink) - PutLink = Ntf_StartFormGoToAction (NotifyEvent,Crs.CrsCod,&UsrDat,Cod); + PutLink = Ntf_StartFormGoToAction (NotifyEvent,Crs.CrsCod,&UsrDat,Cod,&Forums); if (PutLink) HTM_BUTTON_SUBMIT_Begin (Txt_NOTIFY_EVENTS_SINGULAR[NotifyEvent],ClassLink,NULL); @@ -653,7 +657,8 @@ static bool Ntf_GetAllNotificationsFromForm (void) // Return the value of Gbl.Form.Inside (true if form is started) static bool Ntf_StartFormGoToAction (Ntf_NotifyEvent_t NotifyEvent, - long CrsCod,struct UsrData *UsrDat,long Cod) + long CrsCod,struct UsrData *UsrDat,long Cod, + const struct For_Forums *Forums) { extern const Act_Action_t For_ActionsSeeFor[For_NUM_TYPES_FORUM]; struct FileMetadata FileMetadata; @@ -734,13 +739,13 @@ static bool Ntf_StartFormGoToAction (Ntf_NotifyEvent_t NotifyEvent, break; case Ntf_EVENT_FORUM_POST_COURSE: case Ntf_EVENT_FORUM_REPLY: - Frm_StartForm (For_ActionsSeeFor[Gbl.Forum.ForumSelected.Type]); + Frm_StartForm (For_ActionsSeeFor[Forums->ForumSelected.Type]); For_PutAllHiddenParamsForum (1, // Page of threads = first 1, // Page of posts = first - Gbl.Forum.ForumSet, - Gbl.Forum.ThreadsOrder, - Gbl.Forum.ForumSelected.Location, - Gbl.Forum.ForumSelected.ThrCod, + Forums->ForumSet, + Forums->ThreadsOrder, + Forums->ForumSelected.Location, + Forums->ForumSelected.ThrCod, -1L); break; case Ntf_EVENT_NOTICE: @@ -1145,7 +1150,11 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod) unsigned long NumRow; unsigned long NumRows = 0; // Initialized to avoid warning struct UsrData UsrDat; - struct Forum ForumSelected; + struct For_Forum ForumSelected; + long InsCod; + long CtrCod; + long DegCod; + long CrsCod; unsigned NumUsrsToBeNotifiedByEMail = 0; unsigned NotifyEventMask = (1 << NotifyEvent); @@ -1299,6 +1308,7 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod) case Ntf_EVENT_FORUM_POST_COURSE: // Check if forum is for users or for all users in the course For_GetForumTypeAndLocationOfAPost (Cod,&ForumSelected); + switch (ForumSelected.Type) { case For_FORUM_COURSE_USRS: @@ -1367,6 +1377,40 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod) break; } + if (NotifyEvent == Ntf_EVENT_FORUM_POST_COURSE || + NotifyEvent == Ntf_EVENT_FORUM_REPLY) + { + InsCod = CtrCod = DegCod = CrsCod = -1L; + switch (ForumSelected.Type) + { + case For_FORUM_INSTIT_USRS: + case For_FORUM_INSTIT_TCHS: + InsCod = ForumSelected.Location; + break; + case For_FORUM_CENTRE_USRS: + case For_FORUM_CENTRE_TCHS: + CtrCod = ForumSelected.Location; + break; + case For_FORUM_DEGREE_USRS: + case For_FORUM_DEGREE_TCHS: + DegCod = ForumSelected.Location; + break; + case For_FORUM_COURSE_USRS: + case For_FORUM_COURSE_TCHS: + CrsCod = ForumSelected.Location; + break; + default: + break; + } + } + else + { + InsCod = Gbl.Hierarchy.Ins.InsCod; + CtrCod = Gbl.Hierarchy.Ctr.CtrCod; + DegCod = Gbl.Hierarchy.Deg.DegCod; + CrsCod = Gbl.Hierarchy.Crs.CrsCod; + } + if (NumRows) // Users found { /***** Initialize structure with user's data *****/ @@ -1389,11 +1433,13 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod) if ((UsrDat.NtfEvents.SendEmail & NotifyEventMask)) // Send notification by email { Ntf_StoreNotifyEventToOneUser (NotifyEvent,&UsrDat,Cod, - (Ntf_Status_t) Ntf_STATUS_BIT_EMAIL); + (Ntf_Status_t) Ntf_STATUS_BIT_EMAIL, + InsCod,CtrCod,DegCod,CrsCod); NumUsrsToBeNotifiedByEMail++; } else // Don't send notification by email - Ntf_StoreNotifyEventToOneUser (NotifyEvent,&UsrDat,Cod,(Ntf_Status_t) 0); + Ntf_StoreNotifyEventToOneUser (NotifyEvent,&UsrDat,Cod,(Ntf_Status_t) 0, + InsCod,CtrCod,DegCod,CrsCod); } } @@ -1413,47 +1459,9 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod) void Ntf_StoreNotifyEventToOneUser (Ntf_NotifyEvent_t NotifyEvent, struct UsrData *UsrDat, - long Cod,Ntf_Status_t Status) + long Cod,Ntf_Status_t Status, + long InsCod,long CtrCod,long DegCod,long CrsCod) { - long InsCod; - long CtrCod; - long DegCod; - long CrsCod; - - if (NotifyEvent == Ntf_EVENT_FORUM_POST_COURSE || - NotifyEvent == Ntf_EVENT_FORUM_REPLY) - { - InsCod = CtrCod = DegCod = CrsCod = -1L; - switch (Gbl.Forum.ForumSelected.Type) - { - case For_FORUM_INSTIT_USRS: - case For_FORUM_INSTIT_TCHS: - InsCod = Gbl.Forum.ForumSelected.Location; - break; - case For_FORUM_CENTRE_USRS: - case For_FORUM_CENTRE_TCHS: - CtrCod = Gbl.Forum.ForumSelected.Location; - break; - case For_FORUM_DEGREE_USRS: - case For_FORUM_DEGREE_TCHS: - DegCod = Gbl.Forum.ForumSelected.Location; - break; - case For_FORUM_COURSE_USRS: - case For_FORUM_COURSE_TCHS: - CrsCod = Gbl.Forum.ForumSelected.Location; - break; - default: - break; - } - } - else - { - InsCod = Gbl.Hierarchy.Ins.InsCod; - CtrCod = Gbl.Hierarchy.Ctr.CtrCod; - DegCod = Gbl.Hierarchy.Deg.DegCod; - CrsCod = Gbl.Hierarchy.Crs.CrsCod; - } - /***** Store notify event *****/ DB_QueryINSERT ("can not create new notification event", "INSERT INTO notif" @@ -1578,7 +1586,7 @@ static void Ntf_SendPendingNotifByEMailToOneUsr (struct UsrData *ToUsrDat,unsign struct Degree Deg; struct Course Crs; long Cod; - struct Forum ForumSelected; + struct For_Forum ForumSelected; char ForumName[For_MAX_BYTES_FORUM_NAME + 1]; char Command[2048 + Cfg_MAX_BYTES_SMTP_PASSWORD + diff --git a/swad_notification.h b/swad_notification.h index 79db4fe87..173fd3395 100644 --- a/swad_notification.h +++ b/swad_notification.h @@ -131,7 +131,8 @@ void Ntf_MarkNotifFilesInGroupAsRemoved (long GrpCod); unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod); void Ntf_StoreNotifyEventToOneUser (Ntf_NotifyEvent_t NotifyEvent, struct UsrData *UsrDat, - long Cod,Ntf_Status_t Status); + long Cod,Ntf_Status_t Status, + long InsCod,long CtrCod,long DegCod,long CrsCod); void Ntf_SendPendingNotifByEMailToAllUsrs (void); Ntf_NotifyEvent_t Ntf_GetNotifyEventFromStr (const char *Str); void Ntf_MarkAllNotifAsSeen (void); diff --git a/swad_pagination.c b/swad_pagination.c index 172ad22a6..50b626c5a 100644 --- a/swad_pagination.c +++ b/swad_pagination.c @@ -36,6 +36,7 @@ #include "swad_forum.h" #include "swad_global.h" #include "swad_HTML.h" +#include "swad_pagination.h" #include "swad_parameter.h" #include "swad_program.h" #include "swad_project.h" @@ -131,12 +132,12 @@ void Pag_CalculatePagination (struct Pagination *Pagination) void Pag_WriteLinksToPagesCentered (Pag_WhatPaginate_t WhatPaginate, struct Pagination *Pagination, unsigned SelectedOrder, - long ThrCod) + const struct For_Forums *Forums,long ThrCod) { if (Pagination->MoreThanOnePage) { HTM_DIV_Begin ("class=\"CM\""); - Pag_WriteLinksToPages (WhatPaginate,Pagination,SelectedOrder,ThrCod, + Pag_WriteLinksToPages (WhatPaginate,Pagination,SelectedOrder,Forums,ThrCod, true,NULL,"PAG_TXT",false); HTM_DIV_End (); } @@ -149,7 +150,7 @@ void Pag_WriteLinksToPagesCentered (Pag_WhatPaginate_t WhatPaginate, void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate, struct Pagination *Pagination, unsigned SelectedOrder, - long ThrCod, + const struct For_Forums *Forums,long ThrCod, bool FirstMsgEnabled, const char *Subject,const char *ClassTxt, bool LinkToPagCurrent) @@ -205,24 +206,24 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate, Grp_PutParamWhichGroups (&WhichGroups); break; case Pag_THREADS_FORUM: - Frm_StartFormAnchor (For_ActionsSeeFor[Gbl.Forum.ForumSelected.Type], + Frm_StartFormAnchor (For_ActionsSeeFor[Forums->ForumSelected.Type], Pagination->Anchor); For_PutAllHiddenParamsForum (1, // Page of threads = first 1, // Page of posts = first - Gbl.Forum.ForumSet, + Forums->ForumSet, (Dat_StartEndTime_t) SelectedOrder, - Gbl.Forum.ForumSelected.Location, + Forums->ForumSelected.Location, -1L, -1L); break; case Pag_POSTS_FORUM: - Frm_StartFormAnchor (For_ActionsSeePstFor[Gbl.Forum.ForumSelected.Type], + Frm_StartFormAnchor (For_ActionsSeePstFor[Forums->ForumSelected.Type], Pagination->Anchor); - For_PutAllHiddenParamsForum (Gbl.Forum.CurrentPageThrs, // Page of threads = current + For_PutAllHiddenParamsForum (Forums->CurrentPageThrs, // Page of threads = current 1, // Page of posts = first - Gbl.Forum.ForumSet, + Forums->ForumSet, (Dat_StartEndTime_t) SelectedOrder, - Gbl.Forum.ForumSelected.Location, + Forums->ForumSelected.Location, ThrCod, -1L); break; @@ -323,24 +324,24 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate, Grp_PutParamWhichGroups (&WhichGroups); break; case Pag_THREADS_FORUM: - Frm_StartFormAnchor (For_ActionsSeeFor[Gbl.Forum.ForumSelected.Type], + Frm_StartFormAnchor (For_ActionsSeeFor[Forums->ForumSelected.Type], Pagination->Anchor); For_PutAllHiddenParamsForum (1, // Page of threads = first 1, // Page of posts = first - Gbl.Forum.ForumSet, + Forums->ForumSet, (Dat_StartEndTime_t) SelectedOrder, - Gbl.Forum.ForumSelected.Location, + Forums->ForumSelected.Location, -1L, -1L); break; case Pag_POSTS_FORUM: - Frm_StartFormAnchor (For_ActionsSeePstFor[Gbl.Forum.ForumSelected.Type], + Frm_StartFormAnchor (For_ActionsSeePstFor[Forums->ForumSelected.Type], Pagination->Anchor); - For_PutAllHiddenParamsForum (Gbl.Forum.CurrentPageThrs, // Page of threads = current + For_PutAllHiddenParamsForum (Forums->CurrentPageThrs, // Page of threads = current 1, // Page of posts = first - Gbl.Forum.ForumSet, + Forums->ForumSet, (Dat_StartEndTime_t) SelectedOrder, - Gbl.Forum.ForumSelected.Location, + Forums->ForumSelected.Location, ThrCod, -1L); break; @@ -427,24 +428,24 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate, Grp_PutParamWhichGroups (&WhichGroups); break; case Pag_THREADS_FORUM: - Frm_StartFormAnchor (For_ActionsSeeFor[Gbl.Forum.ForumSelected.Type], + Frm_StartFormAnchor (For_ActionsSeeFor[Forums->ForumSelected.Type], Pagination->Anchor); For_PutAllHiddenParamsForum (Pagination->LeftPage, // Page of threads = left 1, // Page of posts = first - Gbl.Forum.ForumSet, + Forums->ForumSet, (Dat_StartEndTime_t) SelectedOrder, - Gbl.Forum.ForumSelected.Location, + Forums->ForumSelected.Location, -1L, -1L); break; case Pag_POSTS_FORUM: - Frm_StartFormAnchor (For_ActionsSeePstFor[Gbl.Forum.ForumSelected.Type], + Frm_StartFormAnchor (For_ActionsSeePstFor[Forums->ForumSelected.Type], Pagination->Anchor); - For_PutAllHiddenParamsForum (Gbl.Forum.CurrentPageThrs, // Page of threads = current + For_PutAllHiddenParamsForum (Forums->CurrentPageThrs, // Page of threads = current Pagination->LeftPage, // Page of posts = left - Gbl.Forum.ForumSet, + Forums->ForumSet, (Dat_StartEndTime_t) SelectedOrder, - Gbl.Forum.ForumSelected.Location, + Forums->ForumSelected.Location, ThrCod, -1L); break; @@ -543,24 +544,24 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate, Grp_PutParamWhichGroups (&WhichGroups); break; case Pag_THREADS_FORUM: - Frm_StartFormAnchor (For_ActionsSeeFor[Gbl.Forum.ForumSelected.Type], + Frm_StartFormAnchor (For_ActionsSeeFor[Forums->ForumSelected.Type], Pagination->Anchor); For_PutAllHiddenParamsForum (NumPage, // Page of threads = number of page 1, // Page of posts = first - Gbl.Forum.ForumSet, + Forums->ForumSet, (Dat_StartEndTime_t) SelectedOrder, - Gbl.Forum.ForumSelected.Location, + Forums->ForumSelected.Location, -1L, -1L); break; case Pag_POSTS_FORUM: - Frm_StartFormAnchor (For_ActionsSeePstFor[Gbl.Forum.ForumSelected.Type], + Frm_StartFormAnchor (For_ActionsSeePstFor[Forums->ForumSelected.Type], Pagination->Anchor); - For_PutAllHiddenParamsForum (Gbl.Forum.CurrentPageThrs, // Page of threads = current + For_PutAllHiddenParamsForum (Forums->CurrentPageThrs, // Page of threads = current NumPage, // Page of posts = number of page - Gbl.Forum.ForumSet, + Forums->ForumSet, (Dat_StartEndTime_t) SelectedOrder, - Gbl.Forum.ForumSelected.Location, + Forums->ForumSelected.Location, ThrCod, -1L); break; @@ -646,24 +647,24 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate, Grp_PutParamWhichGroups (&WhichGroups); break; case Pag_THREADS_FORUM: - Frm_StartFormAnchor (For_ActionsSeeFor[Gbl.Forum.ForumSelected.Type], + Frm_StartFormAnchor (For_ActionsSeeFor[Forums->ForumSelected.Type], Pagination->Anchor); For_PutAllHiddenParamsForum (Pagination->RightPage, // Page of threads = right 1, // Page of posts = first - Gbl.Forum.ForumSet, + Forums->ForumSet, (Dat_StartEndTime_t) SelectedOrder, - Gbl.Forum.ForumSelected.Location, + Forums->ForumSelected.Location, -1L, -1L); break; case Pag_POSTS_FORUM: - Frm_StartFormAnchor (For_ActionsSeePstFor[Gbl.Forum.ForumSelected.Type], + Frm_StartFormAnchor (For_ActionsSeePstFor[Forums->ForumSelected.Type], Pagination->Anchor); - For_PutAllHiddenParamsForum (Gbl.Forum.CurrentPageThrs, // Page of threads = current + For_PutAllHiddenParamsForum (Forums->CurrentPageThrs, // Page of threads = current Pagination->RightPage, // Page of posts = right - Gbl.Forum.ForumSet, + Forums->ForumSet, (Dat_StartEndTime_t) SelectedOrder, - Gbl.Forum.ForumSelected.Location, + Forums->ForumSelected.Location, ThrCod, -1L); break; @@ -750,24 +751,24 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate, Grp_PutParamWhichGroups (&WhichGroups); break; case Pag_THREADS_FORUM: - Frm_StartFormAnchor (For_ActionsSeeFor[Gbl.Forum.ForumSelected.Type], + Frm_StartFormAnchor (For_ActionsSeeFor[Forums->ForumSelected.Type], Pagination->Anchor); For_PutAllHiddenParamsForum (Pagination->NumPags, // Page of threads = last 1, // Page of posts = first - Gbl.Forum.ForumSet, + Forums->ForumSet, (Dat_StartEndTime_t) SelectedOrder, - Gbl.Forum.ForumSelected.Location, + Forums->ForumSelected.Location, -1L, -1L); break; case Pag_POSTS_FORUM: - Frm_StartFormAnchor (For_ActionsSeePstFor[Gbl.Forum.ForumSelected.Type], + Frm_StartFormAnchor (For_ActionsSeePstFor[Forums->ForumSelected.Type], Pagination->Anchor); - For_PutAllHiddenParamsForum (Gbl.Forum.CurrentPageThrs, // Page of threads = current + For_PutAllHiddenParamsForum (Forums->CurrentPageThrs, // Page of threads = current Pagination->NumPags, // Page of posts = last - Gbl.Forum.ForumSet, + Forums->ForumSet, (Dat_StartEndTime_t) SelectedOrder, - Gbl.Forum.ForumSelected.Location, + Forums->ForumSelected.Location, ThrCod, -1L); break; diff --git a/swad_pagination.h b/swad_pagination.h index 96d55a363..3b603a452 100644 --- a/swad_pagination.h +++ b/swad_pagination.h @@ -27,6 +27,8 @@ /********************************** Headers **********************************/ /*****************************************************************************/ +#include "swad_forum.h" + /*****************************************************************************/ /****************************** Public constants *****************************/ /*****************************************************************************/ @@ -76,11 +78,11 @@ void Pag_CalculatePagination (struct Pagination *Pagination); void Pag_WriteLinksToPagesCentered (Pag_WhatPaginate_t WhatPaginate, struct Pagination *Pagination, unsigned SelectedOrder, - long ThrCod); + const struct For_Forums *Forums,long ThrCod); void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate, struct Pagination *Pagination, unsigned SelectedOrder, - long ThrCod, + const struct For_Forums *Forums,long ThrCod, bool FirstMsgEnabled, const char *Subject,const char *ClassTxt, bool LinkToPagCurrent); diff --git a/swad_project.c b/swad_project.c index 96c2ac2f4..90d2d2992 100644 --- a/swad_project.c +++ b/swad_project.c @@ -434,7 +434,7 @@ static void Prj_ShowPrjsInCurrentPage (void *Args) Pag_WriteLinksToPagesCentered (Pag_PROJECTS, &Pagination, (unsigned) Gbl.Prjs.SelectedOrder, - 0); + NULL,0); /***** Allocate memory for the project *****/ Prj_AllocMemProject (&Prj); @@ -480,7 +480,7 @@ static void Prj_ShowPrjsInCurrentPage (void *Args) Pag_WriteLinksToPagesCentered (Pag_PROJECTS, &Pagination, (unsigned) Gbl.Prjs.SelectedOrder, - 0); + NULL,0); } else // No projects created Ale_ShowAlert (Ale_INFO,Txt_No_projects); diff --git a/swad_survey.c b/swad_survey.c index ea726a90e..b81d974f3 100644 --- a/swad_survey.c +++ b/swad_survey.c @@ -235,7 +235,7 @@ static void Svy_ListAllSurveys (void) Pag_WriteLinksToPagesCentered (Pag_SURVEYS, &Pagination, (unsigned) Gbl.Svys.SelectedOrder, - 0); + NULL,0); if (Gbl.Svys.Num) { @@ -291,7 +291,7 @@ static void Svy_ListAllSurveys (void) Pag_WriteLinksToPagesCentered (Pag_SURVEYS, &Pagination, (unsigned) Gbl.Svys.SelectedOrder, - 0); + NULL,0); /***** Button to create a new survey *****/ if (Svy_CheckIfICanCreateSvy ()) diff --git a/swad_timeline.c b/swad_timeline.c index 05905a418..e7d933d02 100644 --- a/swad_timeline.c +++ b/swad_timeline.c @@ -250,7 +250,8 @@ static void TL_WriteTopMessage (TL_TopMessage_t TopMessage,long UsrCod); static void TL_WriteAuthorNote (const struct UsrData *UsrDat); static void TL_WriteDateTime (time_t TimeUTC); static void TL_GetAndWritePost (long PstCod); -static void TL_PutFormGoToAction (const struct TL_Note *SocNot); +static void TL_PutFormGoToAction (const struct TL_Note *SocNot, + const struct For_Forums *Forums); static void TL_GetNoteSummary (const struct TL_Note *SocNot, char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1]); static void TL_PublishNoteInTimeline (struct TL_Publication *SocPub); @@ -1536,6 +1537,7 @@ static void TL_WriteNote (const struct TL_Note *SocNot, struct Course Crs; bool ShowPhoto = false; char PhotoURL[PATH_MAX + 1]; + struct For_Forums Forums; char ForumName[For_MAX_BYTES_FORUM_NAME + 1]; char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1]; unsigned NumComments; @@ -1605,6 +1607,9 @@ static void TL_WriteNote (const struct TL_Note *SocNot, TL_GetAndWritePost (SocNot->Cod); else { + /* Reset forums */ + For_ResetForums (&Forums); + /* Get location in hierarchy */ if (!SocNot->Unavailable) switch (SocNot->NoteType) @@ -1637,16 +1642,15 @@ static void TL_WriteNote (const struct TL_Note *SocNot, break; case TL_NOTE_FORUM_POST: /* Get forum type of the post */ - For_GetForumTypeAndLocationOfAPost (SocNot->Cod,&Gbl.Forum.ForumSelected); - For_SetForumName (&Gbl.Forum.ForumSelected, - ForumName,Gbl.Prefs.Language,false); // Set forum name in recipient's language + For_GetForumTypeAndLocationOfAPost (SocNot->Cod,&Forums.ForumSelected); + For_SetForumName (&Forums.ForumSelected,ForumName,Gbl.Prefs.Language,false); // Set forum name in recipient's language break; default: break; } /* Write note type */ - TL_PutFormGoToAction (SocNot); + TL_PutFormGoToAction (SocNot,&Forums); /* Write location in hierarchy */ if (!SocNot->Unavailable) @@ -1921,7 +1925,8 @@ static void TL_GetAndWritePost (long PstCod) /************* Put form to go to an action depending on the note *************/ /*****************************************************************************/ -static void TL_PutFormGoToAction (const struct TL_Note *SocNot) +static void TL_PutFormGoToAction (const struct TL_Note *SocNot, + const struct For_Forums *Forums) { extern const Act_Action_t For_ActionsSeeFor[For_NUM_TYPES_FORUM]; extern const char *The_ClassFormInBoxBold[The_NUM_THEMES]; @@ -2038,13 +2043,13 @@ static void TL_PutFormGoToAction (const struct TL_Note *SocNot) case TL_NOTE_POST: // Not applicable return; case TL_NOTE_FORUM_POST: - Frm_StartFormUnique (For_ActionsSeeFor[Gbl.Forum.ForumSelected.Type]); + Frm_StartFormUnique (For_ActionsSeeFor[Forums->ForumSelected.Type]); For_PutAllHiddenParamsForum (1, // Page of threads = first 1, // Page of posts = first - Gbl.Forum.ForumSet, - Gbl.Forum.ThreadsOrder, - Gbl.Forum.ForumSelected.Location, - Gbl.Forum.ForumSelected.ThrCod, + Forums->ForumSet, + Forums->ThreadsOrder, + Forums->ForumSelected.Location, + Forums->ForumSelected.ThrCod, -1L); if (SocNot->HieCod != Gbl.Hierarchy.Crs.CrsCod) // Not the current course Crs_PutParamCrsCod (SocNot->HieCod); // Go to another course @@ -3929,7 +3934,11 @@ static void TL_CreateNotifToAuthor (long AuthorCod,long PubCod, if (CreateNotif) Ntf_StoreNotifyEventToOneUser (NotifyEvent,&UsrDat,PubCod, (Ntf_Status_t) (NotifyByEmail ? Ntf_STATUS_BIT_EMAIL : - 0)); + 0), + Gbl.Hierarchy.Ins.InsCod, + Gbl.Hierarchy.Ctr.CtrCod, + Gbl.Hierarchy.Deg.DegCod, + Gbl.Hierarchy.Crs.CrsCod); } /***** Free memory used for user's data *****/ @@ -5409,7 +5418,11 @@ static void Str_AnalyzeTxtAndStoreNotifyEventToMentionedUsrs (long PubCod,const NotifyByEmail = (UsrDat.NtfEvents.SendEmail & (1 << Ntf_EVENT_TIMELINE_MENTION)); Ntf_StoreNotifyEventToOneUser (Ntf_EVENT_TIMELINE_MENTION,&UsrDat,PubCod, (Ntf_Status_t) (NotifyByEmail ? Ntf_STATUS_BIT_EMAIL : - 0)); + 0), + Gbl.Hierarchy.Ins.InsCod, + Gbl.Hierarchy.Ctr.CtrCod, + Gbl.Hierarchy.Deg.DegCod, + Gbl.Hierarchy.Crs.CrsCod); } } }