diff --git a/Makefile b/Makefile index 599c8bdf..aa47c3e4 100644 --- a/Makefile +++ b/Makefile @@ -53,6 +53,7 @@ OBJS = swad_account.o swad_account_database.o swad_action.o swad_admin.o \ swad_file_database.o swad_file_extension.o swad_file_MIME.o \ swad_firewall.o swad_firewall_database.o swad_follow.o \ swad_follow_database.o swad_form.o swad_forum.o swad_forum_database.o \ + swad_forum_resource.o \ swad_game.o swad_game_database.o swad_game_resource.o swad_global.o \ swad_group.o swad_group_database.o \ swad_help.o swad_hierarchy.o swad_hierarchy_config.o \ diff --git a/swad_action.c b/swad_action.c index c6c763f1..0f2829d1 100644 --- a/swad_action.c +++ b/swad_action.c @@ -62,6 +62,7 @@ #include "swad_figure.h" #include "swad_follow.h" #include "swad_forum.h" +#include "swad_forum_resource.h" #include "swad_game.h" #include "swad_game_resource.h" #include "swad_global.h" @@ -1728,7 +1729,7 @@ const struct Act_Actions Act_Actions[Act_NUM_ACTIONS] = [ActDisPstForSWAUsr ] = { 625,-1,TabUnk,ActSeeFor ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,For_DisablePost ,NULL}, [ActDisPstForSWATch ] = { 635,-1,TabUnk,ActSeeFor ,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,0x3C0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,For_DisablePost ,NULL}, - [ActReqLnkForCrsUsr ] = {1941,-1,TabUnk,ActSeeFor ,0x220,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,For_GetLinkToThread ,NULL}, + [ActReqLnkForCrsUsr ] = {1941,-1,TabUnk,ActSeeFor ,0x220,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,ForRsc_GetLinkToThread ,NULL}, // [ActCht ] = { 52,-1,TabUnk,ActSeeChtRms ,0x3F8,0x3C4,0x3C4,0x3C4,0x3C4,0x3C4,0x3C4,Act_CONT_NORM,Act_BRW_NEW_TAB,Cht_OpenChatWindow ,NULL ,NULL}, [ActCht ] = { 52,-1,TabUnk,ActSeeChtRms ,0x200,0x200,0x200,0x200,0x200,0x200,0x200,Act_CONT_NORM,Act_BRW_NEW_TAB,Cht_OpenChatWindow ,NULL ,NULL}, diff --git a/swad_attendance_resource.c b/swad_attendance_resource.c index 4dac951b..fb0ef015 100644 --- a/swad_attendance_resource.c +++ b/swad_attendance_resource.c @@ -24,40 +24,12 @@ /********************************** Headers **********************************/ /*****************************************************************************/ -// #define _GNU_SOURCE // For asprintf -// #include // For PATH_MAX -// #include // To access MySQL databases -// #include // For NULL -// #include // For asprintf -// #include // For calloc -// #include // For string functions - #include "swad_alert.h" #include "swad_attendance.h" #include "swad_attendance_database.h" -// #include "swad_autolink.h" -// #include "swad_box.h" -// #include "swad_database.h" #include "swad_error.h" #include "swad_form.h" -// #include "swad_global.h" -// #include "swad_group.h" -// #include "swad_group_database.h" -// #include "swad_hierarchy_level.h" -// #include "swad_HTML.h" -// #include "swad_ID.h" -// #include "swad_pagination.h" -// #include "swad_parameter.h" -// #include "swad_photo.h" #include "swad_program_database.h" -// #include "swad_QR.h" -// #include "swad_setting.h" - -/*****************************************************************************/ -/*************** External global variables from others modules ***************/ -/*****************************************************************************/ - -extern struct Globals Gbl; /*****************************************************************************/ /************************ Get link to attendance event ***********************/ diff --git a/swad_attendance_resource.h b/swad_attendance_resource.h index 29cd4de7..78a87eac 100644 --- a/swad_attendance_resource.h +++ b/swad_attendance_resource.h @@ -27,6 +27,8 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ +#include // For size_t + /*****************************************************************************/ /***************************** Public prototypes *****************************/ /*****************************************************************************/ diff --git a/swad_changelog.h b/swad_changelog.h index 97729565..9ce49e94 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -606,10 +606,11 @@ TODO: Fix bug: error al enviar un mensaje a dos recipientes, error on duplicate TODO: Attach pdf files in multimedia. */ -#define Log_PLATFORM_VERSION "SWAD 22.28 (2022-09-24)" +#define Log_PLATFORM_VERSION "SWAD 22.29 (2022-09-24)" #define CSS_FILE "swad22.22.1.css" #define JS_FILE "swad21.100.js" /* + Version 22.29: Sep 24, 2022 New module swad_forum_resource. (? lines) Version 22.28: Sep 24, 2022 New module swad_attendance_resource. (332236 lines) Version 22.27: Sep 24, 2022 New module swad_browser_resource. (332157 lines) Version 22.26: Sep 23, 2022 New module swad_survey_resource. (332095 lines) diff --git a/swad_forum.c b/swad_forum.c index 044662ba..a6856952 100644 --- a/swad_forum.c +++ b/swad_forum.c @@ -282,13 +282,6 @@ static const unsigned PermissionThreadDeletion[For_NUM_TYPES_FORUM] = [For_FORUM_UNKNOWN ] = 0x000, }; -// Links to go to
-#define For_REMOVE_THREAD_SECTION_ID "remove_thread" -#define For_FORUM_THREADS_SECTION_ID "forum_threads" -#define For_NEW_THREAD_SECTION_ID "new_thread" -#define For_FORUM_POSTS_SECTION_ID "thread_posts" -#define For_NEW_POST_SECTION_ID "new_post" - // Forum images will be saved with: // - maximum width of For_IMAGE_SAVED_MAX_HEIGHT // - maximum height of For_IMAGE_SAVED_MAX_HEIGHT @@ -319,10 +312,8 @@ static void For_RemoveThreadOnly (long ThrCod); static void For_RemoveThreadAndItsPsts (long ThrCod); static time_t For_GetThrReadTime (long ThrCod); -static void For_ShowPostsOfAThread (struct For_Forums *Forums, - Ale_AlertType_t AlertType,const char *Message); + static void For_PutIconsOneThread (void *Forums); -static void For_PutAllHiddenParamsNewPost (void *Forums); static void For_ShowAForumPost (struct For_Forums *Forums, unsigned PstNum, @@ -341,7 +332,6 @@ static void For_PutParamForumLocation (long Location); static void For_PutHiddenParamThrCod (long ThrCod); static void For_PutHiddenParamPstCod (long PstCod); -static void For_ShowForumList (struct For_Forums *Forums); static void For_PutIconsForums (__attribute__((unused)) void *Args); static void For_PutFormWhichForums (const struct For_Forums *Forums); @@ -372,8 +362,7 @@ static unsigned For_GetNumThrsWithNewPstsInForum (const struct For_Forum *Forum, static unsigned For_GetNumOfUnreadPostsInThr (long ThrCod,unsigned NumPostsInThr); static void For_WriteNumberOfThrs (unsigned NumThrs); -static void For_ShowForumThreadsHighlightingOneThread (struct For_Forums *Forums, - Ale_AlertType_t AlertType,const char *Message); + static void For_PutIconNewThread (void *Forums); static void For_PutAllHiddenParamsNewThread (void *Forums); static void For_ListForumThrs (struct For_Forums *Forums, @@ -382,7 +371,6 @@ static void For_ListForumThrs (struct For_Forums *Forums, struct Pagination *PaginationThrs); static void For_GetThreadData (struct For_Thread *Thr); -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); @@ -665,8 +653,8 @@ static time_t For_GetThrReadTime (long ThrCod) /************************ Show posts in a thread *****************************/ /*****************************************************************************/ -static void For_ShowPostsOfAThread (struct For_Forums *Forums, - Ale_AlertType_t AlertType,const char *Message) +void For_ShowPostsOfAThread (struct For_Forums *Forums, + Ale_AlertType_t AlertType,const char *Message) { extern const char *Hlp_COMMUNICATION_Forums_posts; extern const char *Txt_Thread; @@ -850,7 +838,7 @@ static void For_PutIconsOneThread (void *Forums) } } -static void For_PutAllHiddenParamsNewPost (void *Forums) +void For_PutAllHiddenParamsNewPost (void *Forums) { if (Forums) For_PutAllHiddenParamsForum (((struct For_Forums *) Forums)->CurrentPageThrs, // Page of threads = current @@ -1205,7 +1193,7 @@ static void For_PutHiddenParamPstCod (long PstCod) /************************** Show list of available forums ********************/ /*****************************************************************************/ -static void For_ShowForumList (struct For_Forums *Forums) +void For_ShowForumList (struct For_Forums *Forums) { extern const char *Hlp_COMMUNICATION_Forums; extern const char *Txt_Forums; @@ -1997,8 +1985,8 @@ void For_ShowForumTheads (void) /********** Show available threads of a forum highlighting a thread **********/ /*****************************************************************************/ -static void For_ShowForumThreadsHighlightingOneThread (struct For_Forums *Forums, - Ale_AlertType_t AlertType,const char *Message) +void For_ShowForumThreadsHighlightingOneThread (struct For_Forums *Forums, + Ale_AlertType_t AlertType,const char *Message) { extern const char *Hlp_COMMUNICATION_Forums_threads; extern const char *Txt_Forum; @@ -2440,7 +2428,7 @@ void For_ShowThreadPosts (void) /********************* Get parameters related to a forum *********************/ /*****************************************************************************/ -static void For_GetParamsForums (struct For_Forums *Forums) +void For_GetParamsForums (struct For_Forums *Forums) { /***** Set forum type *****/ For_SetForumType (Forums); @@ -3514,105 +3502,3 @@ static void For_WriteForumTotalStats (struct For_FiguresForum *FiguresForum) HTM_TR_End (); } - -/*****************************************************************************/ -/**************************** Get link to thread *****************************/ -/*****************************************************************************/ - -void For_GetLinkToThread (void) - { - extern const char *Txt_Link_to_resource_X_copied_into_clipboard; - struct For_Forums Forums; - char Subject[Cns_MAX_BYTES_SUBJECT + 1]; - - /***** Reset forum *****/ - For_ResetForums (&Forums); - - /***** Get parameters related to forums *****/ - For_GetParamsForums (&Forums); - - /***** Get thread subject *****/ - For_DB_GetThreadSubject (Forums.Thread.Current,Subject); - - /***** Copy link to thread into resource clipboard *****/ - Prg_DB_CopyToClipboard (PrgRsc_FORUM_THREAD,Forums.Thread.Current); - - /***** Write sucess message *****/ - Ale_ShowAlert (Ale_SUCCESS,Txt_Link_to_resource_X_copied_into_clipboard, - Subject); - - /***** Show forum list again *****/ - For_ShowForumList (&Forums); - - /***** Show threads again *****/ - For_ShowForumThreadsHighlightingOneThread (&Forums,Ale_SUCCESS,NULL); - - /***** Show the posts of that thread *****/ - For_ShowPostsOfAThread (&Forums,Ale_SUCCESS,NULL); - } - -/*****************************************************************************/ -/***************** Write thread subject in course program ********************/ -/*****************************************************************************/ - -void ForRsc_WriteThreadInCrsProgram (long ThrCod,bool PutFormToGo, - const char *Icon,const char *IconTitle) - { - extern const char *Txt_Actions[Act_NUM_ACTIONS]; - struct For_Forums Forums; - char Subject[Cns_MAX_BYTES_SUBJECT + 1]; - - /***** Get thread subject *****/ - For_DB_GetThreadSubject (ThrCod,Subject); - - /***** Begin form to go to survey *****/ - if (PutFormToGo) - { - /***** Set forum and thread *****/ - For_ResetForums (&Forums); - Forums.Forum.Type = For_FORUM_COURSE_USRS; - Forums.Forum.Location = Gbl.Hierarchy.Crs.CrsCod; - Forums.Thread.Current = - Forums.Thread.Selected = ThrCod; - // TODO: In the listing of threads, the page is always the first. - // The page should be that corresponding to the selected thread. - - Frm_BeginFormAnchor (ActSeePstForCrsUsr,For_FORUM_POSTS_SECTION_ID); - For_PutAllHiddenParamsNewPost (&Forums); - HTM_BUTTON_Submit_Begin (Txt_Actions[ActSeePstForCrsUsr], - "class=\"LM BT_LINK PRG_LNK_%s\"", - The_GetSuffix ()); - } - - /***** Icon depending on type ******/ - if (PutFormToGo) - Ico_PutIconLink (Icon,Ico_BLACK,ActSeePstForCrsUsr); - else - Ico_PutIconOn (Icon,Ico_BLACK,IconTitle); - - /***** Write Name of the course and date of exam *****/ - HTM_Txt (Subject); - - /***** End form to download file *****/ - if (PutFormToGo) - { - /* End form */ - HTM_BUTTON_End (); - - Frm_EndForm (); - } - } - -/*****************************************************************************/ -/********************* Get survey title from survey code *********************/ -/*****************************************************************************/ - -void ForRsc_GetTitleFromThrCod (long ThrCod,char *Title,size_t TitleSize) - { - char Subject[Cns_MAX_BYTES_SUBJECT + 1]; - - /***** Get thread subject *****/ - For_DB_GetThreadSubject (ThrCod,Subject); - - Str_Copy (Title,Subject,TitleSize); - } diff --git a/swad_forum.h b/swad_forum.h index ac947c5d..6f9fed0e 100644 --- a/swad_forum.h +++ b/swad_forum.h @@ -27,6 +27,7 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ +#include "swad_alert.h" #include "swad_center.h" #include "swad_degree.h" #include "swad_institution.h" @@ -110,6 +111,13 @@ struct For_Forums #define For_MAX_BYTES_FORUM_NAME (512 - 1) +// Links to go to
+#define For_REMOVE_THREAD_SECTION_ID "remove_thread" +#define For_FORUM_THREADS_SECTION_ID "forum_threads" +#define For_NEW_THREAD_SECTION_ID "new_thread" +#define For_FORUM_POSTS_SECTION_ID "thread_posts" +#define For_NEW_POST_SECTION_ID "new_post" + /*****************************************************************************/ /***************************** Public prototypes *****************************/ /*****************************************************************************/ @@ -121,6 +129,11 @@ void For_DisablePost (void); void For_GetForumTypeAndLocationOfAPost (long PstCod,struct For_Forum *Forum); +void For_ShowPostsOfAThread (struct For_Forums *Forums, + Ale_AlertType_t AlertType,const char *Message); + +void For_PutAllHiddenParamsNewPost (void *Forums); + void For_GetSummaryAndContentForumPst (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1], char **ContentStr, long PstCod,bool GetContent); @@ -133,13 +146,20 @@ void For_PutAllHiddenParamsForum (unsigned NumPageThreads, long ThrCod, long PstCod); +void For_ShowForumList (struct For_Forums *Forums); + void For_SetForumName (const struct For_Forum *Forum, char ForumName[For_MAX_BYTES_FORUM_NAME + 1], Lan_Language_t Language,bool UseHTMLEntities); void For_ShowForumTheads (void); +void For_ShowForumThreadsHighlightingOneThread (struct For_Forums *Forums, + Ale_AlertType_t AlertType,const char *Message); void For_ShowThreadPosts (void); + +void For_GetParamsForums (struct For_Forums *Forums); + void For_ReceiveForumPost (void); void For_RemovePost (void); void For_RequestRemoveThread (void); @@ -150,10 +170,4 @@ void For_PasteThread (void); //-------------------------------- Figures ------------------------------------ void For_GetAndShowForumStats (void); -//--------------------------- Program resources ------------------------------- -void For_GetLinkToThread (void); -void ForRsc_WriteThreadInCrsProgram (long ThrCod,bool PutFormToGo, - const char *Icon,const char *IconTitle); -void ForRsc_GetTitleFromThrCod (long ThrCod,char *Title,size_t TitleSize); - #endif diff --git a/swad_forum_resource.c b/swad_forum_resource.c new file mode 100644 index 00000000..9a55eba9 --- /dev/null +++ b/swad_forum_resource.c @@ -0,0 +1,140 @@ +// swad_forum_resource.c: links to course forum threads as program resources +/* + SWAD (Shared Workspace At a Distance), + is a web platform developed at the University of Granada (Spain), + and used to support university teaching. + + This file is part of SWAD core. + Copyright (C) 1999-2022 Antonio Caņas Vargas + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ +/*****************************************************************************/ +/********************************* Headers ***********************************/ +/*****************************************************************************/ + +#include "swad_alert.h" +#include "swad_form.h" +#include "swad_forum.h" +#include "swad_forum_database.h" +#include "swad_global.h" +#include "swad_program_database.h" + +/*****************************************************************************/ +/************** External global variables from others modules ****************/ +/*****************************************************************************/ + +extern struct Globals Gbl; + +/*****************************************************************************/ +/**************************** Get link to thread *****************************/ +/*****************************************************************************/ + +void ForRsc_GetLinkToThread (void) + { + extern const char *Txt_Link_to_resource_X_copied_into_clipboard; + struct For_Forums Forums; + char Subject[Cns_MAX_BYTES_SUBJECT + 1]; + + /***** Reset forum *****/ + For_ResetForums (&Forums); + + /***** Get parameters related to forums *****/ + For_GetParamsForums (&Forums); + + /***** Get thread subject *****/ + For_DB_GetThreadSubject (Forums.Thread.Current,Subject); + + /***** Copy link to thread into resource clipboard *****/ + Prg_DB_CopyToClipboard (PrgRsc_FORUM_THREAD,Forums.Thread.Current); + + /***** Write sucess message *****/ + Ale_ShowAlert (Ale_SUCCESS,Txt_Link_to_resource_X_copied_into_clipboard, + Subject); + + /***** Show forum list again *****/ + For_ShowForumList (&Forums); + + /***** Show threads again *****/ + For_ShowForumThreadsHighlightingOneThread (&Forums,Ale_SUCCESS,NULL); + + /***** Show the posts of that thread *****/ + For_ShowPostsOfAThread (&Forums,Ale_SUCCESS,NULL); + } + +/*****************************************************************************/ +/***************** Write thread subject in course program ********************/ +/*****************************************************************************/ + +void ForRsc_WriteThreadInCrsProgram (long ThrCod,bool PutFormToGo, + const char *Icon,const char *IconTitle) + { + extern const char *Txt_Actions[Act_NUM_ACTIONS]; + struct For_Forums Forums; + char Subject[Cns_MAX_BYTES_SUBJECT + 1]; + + /***** Get thread subject *****/ + For_DB_GetThreadSubject (ThrCod,Subject); + + /***** Begin form to go to survey *****/ + if (PutFormToGo) + { + /***** Set forum and thread *****/ + For_ResetForums (&Forums); + Forums.Forum.Type = For_FORUM_COURSE_USRS; + Forums.Forum.Location = Gbl.Hierarchy.Crs.CrsCod; + Forums.Thread.Current = + Forums.Thread.Selected = ThrCod; + // TODO: In the listing of threads, the page is always the first. + // The page should be that corresponding to the selected thread. + + Frm_BeginFormAnchor (ActSeePstForCrsUsr,For_FORUM_POSTS_SECTION_ID); + For_PutAllHiddenParamsNewPost (&Forums); + HTM_BUTTON_Submit_Begin (Txt_Actions[ActSeePstForCrsUsr], + "class=\"LM BT_LINK PRG_LNK_%s\"", + The_GetSuffix ()); + } + + /***** Icon depending on type ******/ + if (PutFormToGo) + Ico_PutIconLink (Icon,Ico_BLACK,ActSeePstForCrsUsr); + else + Ico_PutIconOn (Icon,Ico_BLACK,IconTitle); + + /***** Write Name of the course and date of exam *****/ + HTM_Txt (Subject); + + /***** End form to download file *****/ + if (PutFormToGo) + { + /* End form */ + HTM_BUTTON_End (); + + Frm_EndForm (); + } + } + +/*****************************************************************************/ +/********************* Get survey title from survey code *********************/ +/*****************************************************************************/ + +void ForRsc_GetTitleFromThrCod (long ThrCod,char *Title,size_t TitleSize) + { + char Subject[Cns_MAX_BYTES_SUBJECT + 1]; + + /***** Get thread subject *****/ + For_DB_GetThreadSubject (ThrCod,Subject); + + Str_Copy (Title,Subject,TitleSize); + } diff --git a/swad_forum_resource.h b/swad_forum_resource.h new file mode 100644 index 00000000..9c83ae4c --- /dev/null +++ b/swad_forum_resource.h @@ -0,0 +1,41 @@ +// swad_forum_resource.h: links to course forum threads as program resources + +#ifndef _SWAD_FOR_RSC +#define _SWAD_FOR_RSC +/* + SWAD (Shared Workspace At a Distance in Spanish), + is a web platform developed at the University of Granada (Spain), + and used to support university teaching. + + This file is part of SWAD core. + Copyright (C) 1999-2022 Antonio Caņas Vargas + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ +/*****************************************************************************/ +/********************************* Headers ***********************************/ +/*****************************************************************************/ + +#include // For size_t + +/*****************************************************************************/ +/***************************** Public prototypes *****************************/ +/*****************************************************************************/ + +void ForRsc_GetLinkToThread (void); +void ForRsc_WriteThreadInCrsProgram (long ThrCod,bool PutFormToGo, + const char *Icon,const char *IconTitle); +void ForRsc_GetTitleFromThrCod (long ThrCod,char *Title,size_t TitleSize); + +#endif diff --git a/swad_program_resource.c b/swad_program_resource.c index eb6ac049..f0537f91 100644 --- a/swad_program_resource.c +++ b/swad_program_resource.c @@ -37,6 +37,7 @@ #include "swad_error.h" #include "swad_exam_resource.h" #include "swad_form.h" +#include "swad_forum_resource.h" #include "swad_game_resource.h" #include "swad_global.h" #include "swad_program.h"