diff --git a/swad_changelog.h b/swad_changelog.h index 7e581109..7d99b3f6 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -214,13 +214,14 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 16.181.1 (2017-04-17)" +#define Log_PLATFORM_VERSION "SWAD 16.181.2 (2017-04-18)" #define CSS_FILE "swad16.181.css" #define JS_FILE "swad16.181.js" // Number of lines (includes comments but not blank lines) has been got with the following command: // nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*?.h sql/swad*.sql | tail -1 /* + Version 16.181.2: Apr 18, 2017 Code refactoring in forums. (217590 lines) Version 16.181.1: Apr 17, 2017 Code refactoring in forums. (217538 lines) Version 16.181: Apr 17, 2017 Changes in layout of messages. Changes in layout of some tables. diff --git a/swad_forum.c b/swad_forum.c index 63175bd9..ca00cd5d 100644 --- a/swad_forum.c +++ b/swad_forum.c @@ -272,7 +272,7 @@ static long For_InsertForumThread (struct Forum *WichForum,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]); -static void For_GetForumTypeAndLocationFromQuery (const char *Query,struct Forum *WhichForum); +static void For_GetForumTypeAndLocationFromQuery (const char *Query,struct Forum *ForumSelected); static void For_UpdateThrFirstAndLastPst (long ThrCod,long FirstPstCod,long LastPstCod); static void For_UpdateThrLastPst (long ThrCod,long LastPstCod); static long For_GetLastPstCod (long ThrCod); @@ -287,24 +287,26 @@ static void For_DeleteThrFromReadThrs (long ThrCod); static void For_ShowThreadPosts (void); static void For_PutIconNewPost (void); -static void For_ShowAForumPost (struct Forum *WhichForum,struct ForumThread *Thr,unsigned PstNum,long PstCod, +static void For_ShowAForumPost (struct Forum *ForumSelected, + 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 Image *Image); -static void For_WriteNumberOfPosts (struct Forum *WhichForum,long UsrCod); +static void For_WriteNumberOfPosts (struct Forum *ForumSelected,long UsrCod); -static void For_PutParamForumSet (void); -static void For_PutParamForumOrder (void); - -static void For_PutIconsForums (void); - -static void For_PutFormWhichForums (void); -static void For_PutParamForumInsCtrDegCrs (void); +static void For_PutAllHiddenParamsSelectedForum (void); +static void For_PutParamForumSet (For_ForumSet_t ForumSet); +static void For_PutParamForumOrder (For_Order_t Order); +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_PutIconsForums (void); +static void For_PutFormWhichForums (void); static void For_WriteLinksToGblForums (bool IsLastItemInLevel[1 + For_FORUM_MAX_LEVELS]); static void For_WriteLinksToPlatformForums (bool IsLastForum, @@ -317,18 +319,18 @@ static long For_WriteLinksToDegForums (long DegCod,bool IsLastDeg, bool IsLastItemInLevel[1 + For_FORUM_MAX_LEVELS]); static long For_WriteLinksToCrsForums (long CrsCod,bool IsLastCrs, bool IsLastItemInLevel[1 + For_FORUM_MAX_LEVELS]); -static void For_WriteLinkToAForum (struct Forum *WhichForum, +static void For_WriteLinkToAForum (struct Forum *Forum, bool Highlight,bool ShowNumOfPosts, unsigned Level, bool IsLastItemInLevel[1 + For_FORUM_MAX_LEVELS]); -static void For_WriteLinkToForum (struct Forum *WhichForum, +static void For_WriteLinkToForum (struct Forum *Forum, Act_Action_t NextAct, const char *Icon,const char *ForumName, bool Highlight,bool ShowNumOfPosts, unsigned Level,bool IsLastItemInLevel[1 + For_FORUM_MAX_LEVELS]); -static unsigned For_GetNumThrsWithNewPstsInForum (struct Forum *WhichForum, +static unsigned For_GetNumThrsWithNewPstsInForum (struct Forum *ForumSelected, unsigned NumThreads); -static unsigned For_GetNumOfThreadsInForumNewerThan (struct Forum *WhichForum, +static unsigned For_GetNumOfThreadsInForumNewerThan (struct Forum *ForumSelected, const char *Time); static unsigned For_GetNumOfUnreadPostsInThr (long ThrCod,unsigned NumPostsInThr); static unsigned For_GetNumOfPostsInThrNewerThan (long ThrCod,const char *Time); @@ -337,8 +339,8 @@ static void For_WriteNumThrsAndPsts (unsigned NumThrs,unsigned NumThrsWithNewPos static void For_WriteNumberOfThrs (unsigned NumThrs,unsigned NumThrsWithNewPosts); static void For_ShowForumThreadsHighlightingOneThread (long ThrCodHighlighted); static void For_PutIconNewThread (void); -static unsigned For_GetNumThrsInForum (struct Forum *WhichForum); -static unsigned For_GetNumPstsInForum (struct Forum *WhichForum); +static unsigned For_GetNumThrsInForum (struct Forum *ForumSelected); +static unsigned For_GetNumPstsInForum (struct Forum *ForumSelected); static void For_ListForumThrs (long ThrCods[Pag_ITEMS_PER_PAGE], long ThrCodHighlighted, struct Pagination *PaginationThrs); @@ -347,15 +349,13 @@ 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_PutHiddenParamPstCod (long PstCod); -static long For_GetParamPstCod (void); -static void For_WriteFormForumPst (bool IsReply,long ThrCod,const char *Subject); +static void For_WriteFormForumPst (bool IsReply,const char *Subject); static void For_UpdateNumUsrsNotifiedByEMailAboutPost (long PstCod,unsigned NumUsrsToBeNotifiedByEMail); static long For_GetThrInMyClipboard (void); -static bool For_CheckIfThrBelongsToForum (long ThrCod,struct Forum *WhichForum); +static bool For_CheckIfThrBelongsToForum (long ThrCod,struct Forum *ForumSelected); static void For_MoveThrToCurrentForum (long ThrCod); static void For_InsertThrInClipboard (long ThrCod); static void For_RemoveExpiredThrsClipboards (void); @@ -368,16 +368,12 @@ static void For_RemoveThrCodFromThrClipboard (long ThrCod); void For_EnbPst (void) { extern const char *Txt_Post_unbanned; - long PstCod; /***** Get parameters related to forum *****/ For_GetParamsForum (); - /***** Get the post code to unban *****/ - PstCod = For_GetParamPstCod (); - /***** Delete post from table of disabled posts *****/ - For_DeletePstFromDisabledPstTable (PstCod); + For_DeletePstFromDisabledPstTable (Gbl.Forum.ForumSelected.PstCod); Lay_ShowAlert (Lay_SUCCESS,Txt_Post_unbanned); /***** Show the posts again *****/ @@ -391,19 +387,15 @@ void For_EnbPst (void) void For_DisPst (void) { extern const char *Txt_Post_banned; - long PstCod; /***** Get parameters related to forum *****/ For_GetParamsForum (); - /***** Get the post code to ban *****/ - PstCod = For_GetParamPstCod (); - /***** Check if post really exists, if it has not been removed *****/ - if (For_GetIfForumPstExists (PstCod)) + if (For_GetIfForumPstExists (Gbl.Forum.ForumSelected.PstCod)) { /***** Insert post into table of banned posts *****/ - For_InsertPstIntoBannedPstTable (PstCod); + For_InsertPstIntoBannedPstTable (Gbl.Forum.ForumSelected.PstCod); Lay_ShowAlert (Lay_SUCCESS,Txt_Post_banned); } else @@ -683,7 +675,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 *WhichForum) +void For_GetForumTypeAndLocationOfAPost (long PstCod,struct Forum *ForumSelected) { char Query[512]; @@ -693,14 +685,14 @@ void For_GetForumTypeAndLocationOfAPost (long PstCod,struct Forum *WhichForum) " WHERE forum_post.PstCod=%ld" " AND forum_post.ThrCod=forum_thread.ThrCod", PstCod); - For_GetForumTypeAndLocationFromQuery (Query,WhichForum); + For_GetForumTypeAndLocationFromQuery (Query,ForumSelected); } /*****************************************************************************/ /*********** Get the forum type and location of a thread or post *************/ /*****************************************************************************/ -static void For_GetForumTypeAndLocationFromQuery (const char *Query,struct Forum *WhichForum) +static void For_GetForumTypeAndLocationFromQuery (const char *Query,struct Forum *ForumSelected) { MYSQL_RES *mysql_res; MYSQL_ROW row; @@ -716,10 +708,10 @@ static void For_GetForumTypeAndLocationFromQuery (const char *Query,struct Forum Lay_ShowErrorAndExit ("Wrong forum type."); if (UnsignedNum >= For_NUM_TYPES_FORUM) Lay_ShowErrorAndExit ("Wrong forum type."); - WhichForum->Type = (For_ForumType_t) UnsignedNum; + ForumSelected->Type = (For_ForumType_t) UnsignedNum; /* Get forum location (row[1]) */ - if (sscanf (row[1],"%ld",&(WhichForum->Location)) != 1) + if (sscanf (row[1],"%ld",&(ForumSelected->Location)) != 1) Lay_ShowErrorAndExit ("Wrong forum location."); } else @@ -977,10 +969,10 @@ static void For_ShowThreadPosts (void) bool ICanMoveThreads = (Gbl.Usrs.Me.LoggedRole == Rol_SYS_ADM); // If I have permission to move threads... /***** Show threads *****/ - For_ShowForumThreadsHighlightingOneThread (Gbl.Forum.WhichForum.ThrCod); + For_ShowForumThreadsHighlightingOneThread (Gbl.Forum.ForumSelected.ThrCod); /***** Get data of the thread *****/ - Thr.ThrCod = Gbl.Forum.WhichForum.ThrCod; + Thr.ThrCod = Gbl.Forum.ForumSelected.ThrCod; For_GetThrData (&Thr); /***** Get the page number *****/ @@ -992,7 +984,7 @@ static void For_ShowThreadPosts (void) Gbl.Forum.ThreadToMove = For_GetThrInMyClipboard (); /* Get thread read time for the current user */ - ReadTimeUTC = For_GetThrReadTime (Gbl.Forum.WhichForum.ThrCod); + ReadTimeUTC = For_GetThrReadTime (Gbl.Forum.ForumSelected.ThrCod); /***** Start frame *****/ fprintf (Gbl.F.Out,"
",For_ID_FORUM_POSTS_SECTION); @@ -1004,14 +996,14 @@ static void For_ShowThreadPosts (void) sprintf (Query,"SELECT PstCod,UNIX_TIMESTAMP(CreatTime)" " FROM forum_post" " WHERE ThrCod=%ld ORDER BY PstCod", - Gbl.Forum.WhichForum.ThrCod); + Gbl.Forum.ForumSelected.ThrCod); NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get posts of a thread"); NumPsts = (unsigned) NumRows; LastSubject[0] = '\0'; if (NumPsts) // If there are posts... { /***** Check if I can moderate posts in forum *****/ - switch (Gbl.Forum.WhichForum.Type) + switch (Gbl.Forum.ForumSelected.Type) { case For_FORUM_SWAD_USRS: case For_FORUM_SWAD_TCHS: @@ -1048,7 +1040,7 @@ static void For_ShowThreadPosts (void) /***** Write links to pages *****/ if (PaginationPsts.MoreThanOnePage) Pag_WriteLinksToPagesCentered (Pag_POSTS_FORUM, - Gbl.Forum.WhichForum.ThrCod, + Gbl.Forum.ForumSelected.ThrCod, &PaginationPsts); /***** Start table *****/ @@ -1074,15 +1066,16 @@ static void For_ShowThreadPosts (void) /* Update forum_thr_read table indicating that this thread page and previous ones have been read and have no new posts for the current user (even if any previous pages have been no read actually) */ - For_UpdateThrReadTime (Gbl.Forum.WhichForum.ThrCod,CreatTimeUTC); + For_UpdateThrReadTime (Gbl.Forum.ForumSelected.ThrCod,CreatTimeUTC); /* Show post */ - For_ShowAForumPost (&Gbl.Forum.WhichForum,&Thr,NumPst,PstCod, + For_ShowAForumPost (&Gbl.Forum.ForumSelected, + NumPst,PstCod, (NumRow == NumRows),LastSubject, NewPst,ICanModerateForum); /* Mark possible notification as seen */ - switch (Gbl.Forum.WhichForum.Type) + switch (Gbl.Forum.ForumSelected.Type) { case For_FORUM_COURSE_TCHS: case For_FORUM_COURSE_USRS: @@ -1105,7 +1098,7 @@ static void For_ShowThreadPosts (void) /***** Write again links to pages *****/ if (PaginationPsts.MoreThanOnePage) Pag_WriteLinksToPagesCentered (Pag_POSTS_FORUM, - Gbl.Forum.WhichForum.ThrCod, + Gbl.Forum.ForumSelected.ThrCod, &PaginationPsts); } @@ -1114,7 +1107,7 @@ static void For_ShowThreadPosts (void) /***** Form to write a new post in the thread *****/ fprintf (Gbl.F.Out,"
",For_ID_NEW_POST_SECTION); - For_WriteFormForumPst (true,Gbl.Forum.WhichForum.ThrCod,LastSubject); + For_WriteFormForumPst (true,LastSubject); fprintf (Gbl.F.Out,"
"); /***** End frame *****/ @@ -1130,8 +1123,8 @@ static void For_PutIconNewPost (void) { extern const char *Txt_New_post; - Lay_PutContextualLink (For_ActionsSeePstFor[Gbl.Forum.WhichForum.Type], - For_ID_NEW_POST_SECTION,For_PutAllHiddenParamsForum, + Lay_PutContextualLink (For_ActionsSeePstFor[Gbl.Forum.ForumSelected.Type], + For_ID_NEW_POST_SECTION,For_PutAllHiddenParamsSelectedForum, "plus64x64.png", Txt_New_post,NULL, NULL); @@ -1141,7 +1134,8 @@ static void For_PutIconNewPost (void) /**************************** Show a post from forum *************************/ /*****************************************************************************/ -static void For_ShowAForumPost (struct Forum *WhichForum,struct ForumThread *Thr,unsigned PstNum,long PstCod, +static void For_ShowAForumPost (struct Forum *ForumSelected, + unsigned PstNum,long PstCod, bool LastPst,char LastSubject[Cns_MAX_BYTES_SUBJECT + 1], bool NewPst,bool ICanModerateForum) { @@ -1226,11 +1220,13 @@ static void For_ShowAForumPost (struct Forum *WhichForum,struct ForumThread *Thr if (LastPst && Gbl.Usrs.Me.UsrDat.UsrCod == UsrDat.UsrCod) // Post can be removed if post is the last (without answers) and it's mine { - Act_FormStart (For_ActionsDelPstFor[WhichForum->Type]); + Act_FormStart (For_ActionsDelPstFor[ForumSelected->Type]); Pag_PutHiddenParamPagNum (Pag_POSTS_FORUM,Gbl.Forum.CurrentPagePsts); - For_PutHiddenParamPstCod (PstCod); - For_PutAllHiddenParamsForum (); - For_PutHiddenParamThrCod (Thr->ThrCod); + For_PutAllHiddenParamsForum (Gbl.Forum.ForumSet, + Gbl.Forum.SelectedOrder, + Gbl.Forum.ForumSelected.Location, + Gbl.Forum.ForumSelected.ThrCod, + PstCod); Lay_PutIconRemove (); Act_FormEnd (); } @@ -1240,12 +1236,14 @@ static void For_ShowAForumPost (struct Forum *WhichForum,struct ForumThread *Thr { if (ICanModerateForum) { - Act_FormStart (Enabled ? For_ActionsDisPstFor[WhichForum->Type] : - For_ActionsEnbPstFor[WhichForum->Type]); + Act_FormStart (Enabled ? For_ActionsDisPstFor[ForumSelected->Type] : + For_ActionsEnbPstFor[ForumSelected->Type]); Pag_PutHiddenParamPagNum (Pag_POSTS_FORUM,Gbl.Forum.CurrentPagePsts); - For_PutHiddenParamPstCod (PstCod); - For_PutAllHiddenParamsForum (); - For_PutHiddenParamThrCod (Thr->ThrCod); + For_PutAllHiddenParamsForum (Gbl.Forum.ForumSet, + Gbl.Forum.SelectedOrder, + Gbl.Forum.ForumSelected.Location, + Gbl.Forum.ForumSelected.ThrCod, + PstCod); sprintf (Gbl.Title,Enabled ? Txt_Post_X_allowed_Click_to_ban_it : Txt_Post_X_banned_Click_to_unban_it, @@ -1294,7 +1292,7 @@ static void For_ShowAForumPost (struct Forum *WhichForum,struct ForumThread *Thr { /* Write number of posts from this user */ fprintf (Gbl.F.Out,""); - For_WriteNumberOfPosts (WhichForum,UsrDat.UsrCod); + For_WriteNumberOfPosts (ForumSelected,UsrDat.UsrCod); fprintf (Gbl.F.Out,""); } @@ -1435,7 +1433,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 (struct Forum *WhichForum,long UsrCod) +static void For_WriteNumberOfPosts (struct Forum *ForumSelected,long UsrCod) { extern const char *Txt_post; extern const char *Txt_posts; @@ -1448,15 +1446,15 @@ static void For_WriteNumberOfPosts (struct Forum *WhichForum,long UsrCod) " style=\"width:150px;\">"); /***** Get number of posts from database *****/ - if (WhichForum->Location > 0) - sprintf (SubQuery," AND forum_thread.Location=%ld",WhichForum->Location); + if (ForumSelected->Location > 0) + sprintf (SubQuery," AND forum_thread.Location=%ld",ForumSelected->Location); else SubQuery[0] = '\0'; sprintf (Query,"SELECT COUNT(*) FROM forum_post,forum_thread" " WHERE forum_post.UsrCod=%ld" " AND forum_post.ThrCod=forum_thread.ThrCod" " AND forum_thread.ForumType=%u%s", - UsrCod,(unsigned) WhichForum->Type,SubQuery); + UsrCod,(unsigned) ForumSelected->Type,SubQuery); NumPsts = (unsigned) DB_QueryCOUNT (Query,"can not get the number of posts of a user in a forum"); /***** Write number of threads and number of posts *****/ @@ -1473,31 +1471,44 @@ static void For_WriteNumberOfPosts (struct Forum *WhichForum,long UsrCod) /************ Put all the hidden parameters related to forums ****************/ /*****************************************************************************/ -void For_PutAllHiddenParamsForum (void) +static void For_PutAllHiddenParamsSelectedForum (void) { - For_PutParamForumSet (); - For_PutParamForumOrder (); - For_PutParamForumInsCtrDegCrs (); - if (Gbl.Forum.WhichForum.ThrCod > 0) // A thread is selected - For_PutHiddenParamThrCod (Gbl.Forum.WhichForum.ThrCod); + For_PutAllHiddenParamsForum (Gbl.Forum.ForumSet, + Gbl.Forum.SelectedOrder, + Gbl.Forum.ForumSelected.Location, + Gbl.Forum.ForumSelected.ThrCod, + -1L); + } + +void For_PutAllHiddenParamsForum (For_ForumSet_t ForumSet, + For_Order_t Order, + long Location, + long ThrCod, + long PstCod) + { + For_PutParamForumSet (ForumSet); + For_PutParamForumOrder (Order); + For_PutParamForumLocation (Location); + For_PutHiddenParamThrCod (ThrCod); + For_PutHiddenParamPstCod (PstCod); } /*****************************************************************************/ /********* Put a hidden parameter with set of forums I want to see ***********/ /*****************************************************************************/ -static void For_PutParamForumSet (void) +static void For_PutParamForumSet (For_ForumSet_t ForumSet) { - Par_PutHiddenParamUnsigned ("ForumSet",(unsigned) Gbl.Forum.ForumSet); + Par_PutHiddenParamUnsigned ("ForumSet",(unsigned) ForumSet); } /*****************************************************************************/ /******** Put a hidden parameter with the order criterium for forums *********/ /*****************************************************************************/ -static void For_PutParamForumOrder (void) +static void For_PutParamForumOrder (For_Order_t Order) { - Par_PutHiddenParamUnsigned ("Order",(unsigned) Gbl.Forum.SelectedOrder); + Par_PutHiddenParamUnsigned ("Order",(unsigned) Order); } /*****************************************************************************/ @@ -1505,11 +1516,32 @@ static void For_PutParamForumOrder (void) /************** forum institution, centre, degree and course *****************/ /*****************************************************************************/ -static void For_PutParamForumInsCtrDegCrs (void) +static void For_PutParamForumLocation (long Location) { - if (Gbl.Forum.WhichForum.Location > 0) - /***** Put a hidden parameter with the institution, centre, degree or course of the forum *****/ - Par_PutHiddenParamLong ("Location",Gbl.Forum.WhichForum.Location); + if (Location > 0) + /***** Put a hidden parameter with the + institution, centre, degree or course of the forum *****/ + Par_PutHiddenParamLong ("Location",Location); + } + +/*****************************************************************************/ +/************ Write a form parameter to specify a thread code ****************/ +/*****************************************************************************/ + +static void For_PutHiddenParamThrCod (long ThrCod) + { + if (ThrCod > 0) + Par_PutHiddenParamLong ("ThrCod",ThrCod); + } + +/*****************************************************************************/ +/************* Write a form parameter to specify a post code *****************/ +/*****************************************************************************/ + +static void For_PutHiddenParamPstCod (long PstCod) + { + if (PstCod > 0) + Par_PutHiddenParamLong ("PstCod",PstCod); } /*****************************************************************************/ @@ -1520,7 +1552,7 @@ static void For_ShowForumList (void) { extern const char *Hlp_SOCIAL_Forums; extern const char *Txt_Forums; - bool ICanMoveThreads = (Gbl.Usrs.Me.LoggedRole == Rol_SYS_ADM); // If I have permission to move threads... + bool ICanMoveThreads = (Gbl.Usrs.Me.LoggedRole == Rol_SYS_ADM); bool IsLastItemInLevel[1 + For_FORUM_MAX_LEVELS]; MYSQL_RES *mysql_resCtr; MYSQL_RES *mysql_resDeg; @@ -1542,7 +1574,7 @@ static void For_ShowForumList (void) bool ICanSeeDegForum; /***** Get if there is a thread ready to be moved *****/ - if (ICanMoveThreads) + if (ICanMoveThreads) // If I have permission to move threads... Gbl.Forum.ThreadToMove = For_GetThrInMyClipboard (); /***** Fill the list with the institutions I belong to *****/ @@ -1729,7 +1761,7 @@ static void For_PutFormWhichForums (void) - all my forums - only the forums of current institution/degree/course *****/ Act_FormStart (ActSeeFor); - For_PutParamForumOrder (); + For_PutParamForumOrder (Gbl.Forum.SelectedOrder); fprintf (Gbl.F.Out,"
" "