diff --git a/Makefile b/Makefile index 5088ec55..078f850b 100644 --- a/Makefile +++ b/Makefile @@ -50,7 +50,7 @@ OBJS = swad_account.o swad_account_database.o swad_action.o swad_admin.o \ swad_figure.o swad_figure_cache.o swad_figure_database.o swad_file.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_form.o swad_forum.o swad_forum_database.o \ swad_game.o swad_global.o swad_group.o swad_group_database.o \ swad_help.o swad_hierarchy.o swad_hierarchy_config.o swad_holiday.o \ swad_HTML.o \ diff --git a/swad_admin.h b/swad_admin.h index 95e26f6f..4e4a787d 100644 --- a/swad_admin.h +++ b/swad_admin.h @@ -28,11 +28,8 @@ /*****************************************************************************/ #include "swad_admin.h" -// #include "swad_course.h" #include "swad_enrolment.h" #include "swad_hierarchy.h" -// #include "swad_notification.h" -// #include "swad_user.h" /*****************************************************************************/ /****************************** Public constants *****************************/ diff --git a/swad_admin_database.c b/swad_admin_database.c index f89313c1..777c823c 100644 --- a/swad_admin_database.c +++ b/swad_admin_database.c @@ -28,8 +28,6 @@ #include "swad_database.h" #include "swad_admin.h" #include "swad_admin_database.h" -// #include "swad_error.h" -// #include "swad_global.h" /*****************************************************************************/ /****************************** Public constants *****************************/ diff --git a/swad_browser_database.c b/swad_browser_database.c index 84f1a917..c6506a97 100644 --- a/swad_browser_database.c +++ b/swad_browser_database.c @@ -25,49 +25,15 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -// #define _GNU_SOURCE // For asprintf -// #include // For scandir, etc. -// #include // For errno -// #include // For PATH_MAX #include // To access MySQL databases -// #include // For NULL -// #include // For asprintf -// #include // For exit, system, free, etc #include // For string functions -// #include // For lstat, time_t -// #include // For lstat -// #include // For time -// #include // For access, lstat, getpid, chdir, symlink -// #include "swad_box.h" #include "swad_browser.h" #include "swad_browser_database.h" -// #include "swad_config.h" #include "swad_database.h" #include "swad_error.h" -// #include "swad_figure.h" -// #include "swad_file_extension.h" -// #include "swad_file_MIME.h" -// #include "swad_form.h" #include "swad_global.h" -// #include "swad_group_database.h" -// #include "swad_hierarchy.h" -// #include "swad_hierarchy_level.h" -// #include "swad_HTML.h" -// #include "swad_ID.h" -// #include "swad_logo.h" -// #include "swad_mark.h" -// #include "swad_notification.h" -// #include "swad_parameter.h" -// #include "swad_photo.h" -// #include "swad_profile.h" #include "swad_project.h" -// #include "swad_role.h" -// #include "swad_setting.h" -// #include "swad_string.h" -// #include "swad_timeline.h" -// #include "swad_timeline_note.h" -// #include "swad_zip.h" /*****************************************************************************/ /******************** Global variables from other modules ********************/ diff --git a/swad_browser_database.h b/swad_browser_database.h index 9d3cad70..58c0674d 100644 --- a/swad_browser_database.h +++ b/swad_browser_database.h @@ -27,13 +27,9 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -// #include // For PATH_MAX #include // To access MySQL databases #include "swad_browser.h" -// #include "swad_course.h" -// #include "swad_group.h" -// #include "swad_notification.h" /*****************************************************************************/ /************************ Public types and constants *************************/ diff --git a/swad_changelog.h b/swad_changelog.h index 6ae81d37..93387637 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -602,13 +602,14 @@ TODO: FIX BUG, URGENT! En las fechas como par TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo. */ -#define Log_PLATFORM_VERSION "SWAD 21.4 (2021-09-15)" +#define Log_PLATFORM_VERSION "SWAD 21.5 (2021-09-15)" #define CSS_FILE "swad20.45.css" #define JS_FILE "swad20.69.1.js" /* TODO: Rename CENTRE to CENTER in help wiki. TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams + Version 21.5: Sep 15, 2021 New module swad_forum_database for database queries related to forums. (315354 lines) Version 21.4: Sep 15, 2021 New module swad_firewall_database for database queries related to firewall. (315286 lines) Version 21.3.1: Sep 15, 2021 Queries moved to module swad_browser_database. (315201 lines) Version 21.3: Sep 15, 2021 New module swad_notification_database for database queries related to notifications. (315211 lines) diff --git a/swad_figure_database.c b/swad_figure_database.c index 8c46070a..74cba85a 100644 --- a/swad_figure_database.c +++ b/swad_figure_database.c @@ -25,13 +25,8 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -// #include // For sscanf - #include "swad_database.h" -// #include "swad_figure_cache.h" #include "swad_figure_database.h" -// #include "swad_scope.h" -// #include "swad_string.h" /*****************************************************************************/ /************** External global variables from others modules ****************/ diff --git a/swad_forum.c b/swad_forum.c index cd5beec7..4bebd8d3 100644 --- a/swad_forum.c +++ b/swad_forum.c @@ -41,6 +41,7 @@ #include "swad_figure.h" #include "swad_form.h" #include "swad_forum.h" +#include "swad_forum_database.h" #include "swad_global.h" #include "swad_hierarchy.h" #include "swad_HTML.h" @@ -298,23 +299,14 @@ static const unsigned PermissionThreadDeletion[For_NUM_TYPES_FORUM] = /***************************** Private prototypes ***************************/ /*****************************************************************************/ -static bool For_DB_GetIfForumPstExists (long PstCod); - -static bool For_DB_GetIfPstIsEnabled (long PstCod); -static void For_DB_RemovePstFromDisabledPstTable (long PstCod); -static void For_DB_InsertPstIntoBannedPstTable (long PstCod); - static long For_InsertForumPst (long ThrCod,long UsrCod, const char *Subject,const char *Content, struct Med_Media *Media); static bool For_RemoveForumPst (long PstCod,long MedCod); static unsigned For_NumPstsInThrWithPstCod (long PstCod,long *ThrCod); -static long For_DB_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]); static void For_DB_UpdateThrFirstAndLastPst (long ThrCod,long FirstPstCod,long LastPstCod); static void For_DB_UpdateThrLastPst (long ThrCod,long LastPstCod); @@ -452,7 +444,7 @@ void For_EnablePost (void) For_GetParamsForums (&Forums); /***** Delete post from table of disabled posts *****/ - For_DB_RemovePstFromDisabledPstTable (Forums.PstCod); + For_DB_RemovePstFromDisabled (Forums.PstCod); /***** Show forum list again *****/ For_ShowForumList (&Forums); @@ -480,7 +472,7 @@ void For_DisablePost (void) if (For_DB_GetIfForumPstExists (Forums.PstCod)) { /***** Insert post into table of banned posts *****/ - For_DB_InsertPstIntoBannedPstTable (Forums.PstCod); + For_DB_InsertPstIntoDisabled (Forums.PstCod); /***** Show forum list again *****/ For_ShowForumList (&Forums); @@ -495,67 +487,6 @@ void For_DisablePost (void) Err_WrongPostExit (); } -/*****************************************************************************/ -/******************** Get if a forum post exists in database *****************/ -/*****************************************************************************/ - -static bool For_DB_GetIfForumPstExists (long PstCod) - { - /***** Get if a forum post exists from database *****/ - return (DB_QueryCOUNT ("can not check if a post of a forum already existed", - "SELECT COUNT(*)" - " FROM for_posts" - " WHERE PstCod=%ld", - PstCod) != 0); // Post exists if it appears in table of forum posts - } - -/*****************************************************************************/ -/*********************** Get if a forum post is enabled **********************/ -/*****************************************************************************/ - -static bool For_DB_GetIfPstIsEnabled (long PstCod) - { - /***** Trivial check: post code should be > 0 *****/ - if (PstCod <= 0) - return false; - - /***** Get if post is disabled from database *****/ - return (DB_QueryCOUNT ("can not check if a post of a forum is disabled", - "SELECT COUNT(*)" - " FROM for_disabled" - " WHERE PstCod=%ld", - PstCod) == 0); // Post is enabled if it does not appear in table of disabled posts - } - -/*****************************************************************************/ -/****************** Remove post from table of disabled posts *****************/ -/*****************************************************************************/ - -static void For_DB_RemovePstFromDisabledPstTable (long PstCod) - { - /***** Remove post from disabled posts table *****/ - DB_QueryDELETE ("can not unban a post of a forum", - "DELETE FROM for_disabled" - " WHERE PstCod=%ld", - PstCod); - } - -/*****************************************************************************/ -/****************** Insert post into table of banned posts *******************/ -/*****************************************************************************/ - -static void For_DB_InsertPstIntoBannedPstTable (long PstCod) - { - /***** Remove post from banned posts table *****/ - DB_QueryREPLACE ("can not ban a post of a forum", - "REPLACE INTO for_disabled" - " (PstCod,UsrCod,DisableTime)" - " VALUES" - " (%ld,%ld,NOW())", - PstCod, - Gbl.Usrs.Me.UsrDat.UsrCod); - } - /*****************************************************************************/ /************** Insert a post new in the table of posts of forums ************/ /*****************************************************************************/ @@ -564,26 +495,11 @@ static long For_InsertForumPst (long ThrCod,long UsrCod, const char *Subject,const char *Content, struct Med_Media *Media) { - long PstCod; - /***** Store media in filesystem and database *****/ Med_RemoveKeepOrStoreMedia (-1L,Media); /***** Insert forum post in the database *****/ - PstCod = - DB_QueryINSERTandReturnCode ("can not create a new post in a forum", - "INSERT INTO for_posts" - " (ThrCod,UsrCod,CreatTime,ModifTime,NumNotif," - "Subject,Content,MedCod)" - " VALUES" - " (%ld,%ld,NOW(),NOW(),0," - "'%s','%s',%ld)", - ThrCod, - UsrCod, - Subject, - Content,Media->MedCod); - - return PstCod; + return For_DB_InsertForumPst (ThrCod,UsrCod,Subject,Content,Media->MedCod); } /*****************************************************************************/ @@ -606,14 +522,11 @@ static bool For_RemoveForumPst (long PstCod,long MedCod) ThreadDeleted = true; } - /***** Delete post from forum post table *****/ - DB_QueryDELETE ("can not remove a post from a forum", - "DELETE FROM for_posts" - " WHERE PstCod=%ld", - PstCod); - /***** Delete the post from the table of disabled forum posts *****/ - For_DB_RemovePstFromDisabledPstTable (PstCod); + For_DB_RemovePstFromDisabled (PstCod); + + /***** Delete post from forum post table *****/ + For_DB_RemovePst (PstCod); /***** Update the last post of the thread *****/ if (!ThreadDeleted) @@ -641,21 +554,16 @@ static unsigned For_NumPstsInThrWithPstCod (long PstCod,long *ThrCod) return NumPsts; /***** Get number of posts in the thread that holds a post from database *****/ - if (DB_QuerySELECT (&mysql_res,"can not get number of posts in a thread", - "SELECT COUNT(PstCod)," // row[0] - "ThrCod" // row[1] - " FROM for_posts" - " WHERE ThrCod IN" - " (SELECT ThrCod" - " FROM for_posts" - " WHERE PstCod=%ld)" - " GROUP BY ThrCod;", - PstCod) == 1) // Result should have one row + if (For_DB_GetThreadAndNumPostsGivenPstCod (&mysql_res,PstCod) == 1) // Result should have one row { row = mysql_fetch_row (mysql_res); - if (sscanf (row[0],"%u",&NumPsts) != 1) + /* + row[0]: ThrCod + row[1]: COUNT(PstCod) + */ + if (sscanf (row[0],"%ld",ThrCod) != 1) Err_ShowErrorAndExit ("Error when getting number of posts in a thread."); - if (sscanf (row[1],"%ld",ThrCod) != 1) + if (sscanf (row[1],"%u",&NumPsts) != 1) Err_ShowErrorAndExit ("Error when getting number of posts in a thread."); } DB_FreeMySQLResult (&mysql_res); @@ -663,27 +571,6 @@ static unsigned For_NumPstsInThrWithPstCod (long PstCod,long *ThrCod) return NumPsts; } -/*****************************************************************************/ -/*************** Insert a new thread in table of forum threads ***************/ -/*****************************************************************************/ -// Returns the code of the new inserted thread - -static long For_DB_InsertForumThread (const struct For_Forums *Forums, - long FirstPstCod) - { - /***** Insert new thread in the database *****/ - return - DB_QueryINSERTandReturnCode ("can not create a new thread in a forum", - "INSERT INTO for_threads" - " (ForumType,Location,FirstPstCod,LastPstCod)" - " VALUES" - " (%u,%ld,%ld,%ld)", - (unsigned) Forums->Forum.Type, - Forums->Forum.Location, - FirstPstCod, - FirstPstCod); - } - /*****************************************************************************/ /*************** Delete a thread from the forum thread table *****************/ /*****************************************************************************/ @@ -697,10 +584,7 @@ static void For_RemoveThreadOnly (long ThrCod) For_DB_RemoveThrCodFromThrClipboard (ThrCod); /***** Delete thread from forum thread table *****/ - DB_QueryDELETE ("can not remove a thread from a forum", - "DELETE FROM for_threads" - " WHERE ThrCod=%ld", - ThrCod); + For_DB_RemoveThread (ThrCod); } /*****************************************************************************/ @@ -709,51 +593,16 @@ static void For_RemoveThreadOnly (long ThrCod) static void For_RemoveThreadAndItsPsts (long ThrCod) { - /***** Delete banned posts in thread *****/ - DB_QueryDELETE ("can not unban the posts of a thread of a forum", - "DELETE FROM for_disabled" - "USING for_posts," - "for_disabled" - " WHERE for_posts.ThrCod=%ld" - " AND for_posts.PstCod=for_disabled.PstCod", - ThrCod); + /***** Delete disabled posts in thread *****/ + For_DB_RemoveDisabledPstsInThread (ThrCod); /***** Delete thread posts *****/ - DB_QueryDELETE ("can not remove the posts of a thread of a forum", - "DELETE FROM for_posts" - " WHERE ThrCod=%ld", - ThrCod); + For_DB_RemoveThreadPsts (ThrCod); /***** Delete thread from forum thread table *****/ For_RemoveThreadOnly (ThrCod); } -/*****************************************************************************/ -/********************* Get the thread subject from a thread ******************/ -/*****************************************************************************/ - -static void For_GetThrSubject (long ThrCod,char Subject[Cns_MAX_BYTES_SUBJECT + 1]) - { - MYSQL_RES *mysql_res; - MYSQL_ROW row; - - /***** Get subject of a thread from database *****/ - DB_QuerySELECT (&mysql_res,"can not get the subject of a thread of a forum", - "SELECT for_posts.Subject" // row[0] - " FROM for_threads," - "for_posts" - " WHERE for_threads.ThrCod=%ld" - " AND for_threads.FirstPstCod=for_posts.PstCod", - ThrCod); - - /***** Write the subject of the thread *****/ - row = mysql_fetch_row (mysql_res); - Str_Copy (Subject,row[0],Cns_MAX_BYTES_SUBJECT); - - /***** Free structure that stores the query result *****/ - DB_FreeMySQLResult (&mysql_res); - } - /*****************************************************************************/ /*************** Get the forum type and location of a post *******************/ /*****************************************************************************/ @@ -4352,7 +4201,7 @@ void For_RequestRemoveThread (void) For_GetParamsForums (&Forums); /***** Get subject of the thread to delete *****/ - For_GetThrSubject (Forums.Thread.Current,Subject); + For_DB_GetThrSubject (Forums.Thread.Current,Subject); /***** Show forum list again *****/ For_ShowForumList (&Forums); @@ -4412,7 +4261,7 @@ void For_RemoveThread (void) (1 << Gbl.Usrs.Me.Role.Logged)) // If I have permission to remove thread in this forum... { /***** Get subject of thread to delete *****/ - For_GetThrSubject (Forums.Thread.Current,Subject); + For_DB_GetThrSubject (Forums.Thread.Current,Subject); /***** Remove the thread and all its posts *****/ For_RemoveThreadAndItsPsts (Forums.Thread.Current); @@ -4453,7 +4302,7 @@ void For_CutThread (void) For_GetParamsForums (&Forums); /***** Get subject of thread to cut *****/ - For_GetThrSubject (Forums.Thread.Current,Subject); + For_DB_GetThrSubject (Forums.Thread.Current,Subject); /***** Mark the thread as cut *****/ For_InsertThrInClipboard (Forums.Thread.Current); @@ -4494,7 +4343,7 @@ void For_PasteThread (void) For_GetParamsForums (&Forums); /***** Get subject of thread to paste *****/ - For_GetThrSubject (Forums.Thread.Current,Subject); + For_DB_GetThrSubject (Forums.Thread.Current,Subject); /***** Check if paste (move) the thread to current forum has sense *****/ if (For_DB_CheckIfThrBelongsToForum (Forums.Thread.Current,&Forums.Forum)) diff --git a/swad_forum.h b/swad_forum.h index a8cd4e6b..134d73e4 100644 --- a/swad_forum.h +++ b/swad_forum.h @@ -31,7 +31,6 @@ #include "swad_degree.h" #include "swad_institution.h" #include "swad_notification.h" -// #include "swad_pagination.h" #include "swad_scope.h" #include "swad_string.h" diff --git a/swad_forum_database.c b/swad_forum_database.c new file mode 100644 index 00000000..3644aaef --- /dev/null +++ b/swad_forum_database.c @@ -0,0 +1,263 @@ +// swad_forum_database.c: forums operations with database + +/* + 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-2021 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 ***********************************/ +/*****************************************************************************/ + +// #define _GNU_SOURCE // For asprintf +#include // For boolean type +// #include // For malloc +// #include // To access MySQL databases +// #include // For NULL +// #include // For asprintf +// #include +// #include // For time_t + +// #include "swad_action.h" +// #include "swad_box.h" +// #include "swad_config.h" +#include "swad_database.h" +// #include "swad_error.h" +// #include "swad_figure.h" +// #include "swad_form.h" +#include "swad_forum.h" +#include "swad_forum_database.h" +#include "swad_global.h" +// #include "swad_hierarchy.h" +// #include "swad_HTML.h" +// #include "swad_layout.h" +// #include "swad_logo.h" +// #include "swad_message.h" +// #include "swad_notification.h" +// #include "swad_pagination.h" +// #include "swad_parameter.h" +// #include "swad_profile.h" +// #include "swad_role.h" +// #include "swad_timeline.h" +// #include "swad_timeline_database.h" + +/*****************************************************************************/ +/************** External global variables from others modules ****************/ +/*****************************************************************************/ + +extern struct Globals Gbl; + +/*****************************************************************************/ +/************************ Public constants and types *************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/*********************** Private constants and types *************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/***************************** Private prototypes ****************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/**************** Insert new post in the table of forum posts ****************/ +/*****************************************************************************/ + +long For_DB_InsertForumPst (long ThrCod,long UsrCod, + const char *Subject,const char *Content, + long MedCod) + { + return + DB_QueryINSERTandReturnCode ("can not create a new post in a forum", + "INSERT INTO for_posts" + " (ThrCod,UsrCod,CreatTime,ModifTime,NumNotif," + "Subject,Content,MedCod)" + " VALUES" + " (%ld,%ld,NOW(),NOW(),0," + "'%s','%s',%ld)", + ThrCod, + UsrCod, + Subject, + Content, + MedCod); + } + +/*****************************************************************************/ +/******************** Get if a forum post exists in database *****************/ +/*****************************************************************************/ + +bool For_DB_GetIfForumPstExists (long PstCod) + { + return (DB_QueryCOUNT ("can not check if a post of a forum already existed", + "SELECT COUNT(*)" + " FROM for_posts" + " WHERE PstCod=%ld", + PstCod) != 0); // Post exists if it appears in table of forum posts + } + +/*****************************************************************************/ +/*********** Get the number of posts in the thread than holds a post *********/ +/*****************************************************************************/ + +unsigned For_DB_GetThreadAndNumPostsGivenPstCod (MYSQL_RES **mysql_res,long PstCod) + { + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get number of posts in a thread", + "SELECT ThrCod," // row[1] + " COUNT(PstCod)" // row[0] + " FROM for_posts" + " WHERE ThrCod IN" + " (SELECT ThrCod" + " FROM for_posts" + " WHERE PstCod=%ld)" + " GROUP BY ThrCod;", + PstCod); + } + +/*****************************************************************************/ +/********************* Remove post from forum posts table ********************/ +/*****************************************************************************/ + +void For_DB_RemovePst (long PstCod) + { + DB_QueryDELETE ("can not remove a post from a forum", + "DELETE FROM for_posts" + " WHERE PstCod=%ld", + PstCod); + } + +/*****************************************************************************/ +/************************ Remove all posts in a thread ***********************/ +/*****************************************************************************/ + +void For_DB_RemoveThreadPsts (long ThrCod) + { + DB_QueryDELETE ("can not remove the posts of a thread of a forum", + "DELETE FROM for_posts" + " WHERE ThrCod=%ld", + ThrCod); + } + +/*****************************************************************************/ +/*************** Insert a new thread in table of forum threads ***************/ +/*****************************************************************************/ +// Returns the code of the new inserted thread + +long For_DB_InsertForumThread (const struct For_Forums *Forums, + long FirstPstCod) + { + return + DB_QueryINSERTandReturnCode ("can not create a new thread in a forum", + "INSERT INTO for_threads" + " (ForumType,Location,FirstPstCod,LastPstCod)" + " VALUES" + " (%u,%ld,%ld,%ld)", + (unsigned) Forums->Forum.Type, + Forums->Forum.Location, + FirstPstCod, + FirstPstCod); + } + +/*****************************************************************************/ +/********************* Get the thread subject from a thread ******************/ +/*****************************************************************************/ + +void For_DB_GetThrSubject (long ThrCod,char Subject[Cns_MAX_BYTES_SUBJECT + 1]) + { + DB_QuerySELECTString (Subject,Cns_MAX_BYTES_SUBJECT, + "can not get the subject of a thread of a forum", + "SELECT for_posts.Subject" // row[0] + " FROM for_threads," + "for_posts" + " WHERE for_threads.ThrCod=%ld" + " AND for_threads.FirstPstCod=for_posts.PstCod", + ThrCod); + } + +/*****************************************************************************/ +/*************** Delete a thread from the forum thread table *****************/ +/*****************************************************************************/ + +void For_DB_RemoveThread (long ThrCod) + { + DB_QueryDELETE ("can not remove a thread from a forum", + "DELETE FROM for_threads" + " WHERE ThrCod=%ld", + ThrCod); + } + +/*****************************************************************************/ +/****************** Insert post into table of banned posts *******************/ +/*****************************************************************************/ + +void For_DB_InsertPstIntoDisabled (long PstCod) + { + DB_QueryREPLACE ("can not ban a post of a forum", + "REPLACE INTO for_disabled" + " (PstCod,UsrCod,DisableTime)" + " VALUES" + " (%ld,%ld,NOW())", + PstCod, + Gbl.Usrs.Me.UsrDat.UsrCod); + } + +/*****************************************************************************/ +/*********************** Get if a forum post is enabled **********************/ +/*****************************************************************************/ + +bool For_DB_GetIfPstIsEnabled (long PstCod) + { + /***** Trivial check: post code should be > 0 *****/ + if (PstCod <= 0) + return false; + + /***** Get if post is disabled from database *****/ + return (DB_QueryCOUNT ("can not check if a post of a forum is disabled", + "SELECT COUNT(*)" + " FROM for_disabled" + " WHERE PstCod=%ld", + PstCod) == 0); // Post is enabled if it does not appear in table of disabled posts + } + +/*****************************************************************************/ +/****************** Remove post from table of disabled posts *****************/ +/*****************************************************************************/ + +void For_DB_RemovePstFromDisabled (long PstCod) + { + DB_QueryDELETE ("can not unban a post of a forum", + "DELETE FROM for_disabled" + " WHERE PstCod=%ld", + PstCod); + } + +/*****************************************************************************/ +/*********************** Delete disabled posts in thread *********************/ +/*****************************************************************************/ + +void For_DB_RemoveDisabledPstsInThread (long ThrCod) + { + DB_QueryDELETE ("can not unban the posts of a thread of a forum", + "DELETE FROM for_disabled" + "USING for_posts," + "for_disabled" + " WHERE for_posts.ThrCod=%ld" + " AND for_posts.PstCod=for_disabled.PstCod", + ThrCod); + } diff --git a/swad_forum_database.h b/swad_forum_database.h new file mode 100644 index 00000000..6ae69b7b --- /dev/null +++ b/swad_forum_database.h @@ -0,0 +1,67 @@ +// swad_forum_database.h: forums operations with database + +#ifndef _SWAD_FOR_DB +#define _SWAD_FOR_DB +/* + 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-2021 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_center.h" +// #include "swad_degree.h" +// #include "swad_institution.h" +// #include "swad_notification.h" +// #include "swad_pagination.h" +// #include "swad_scope.h" +// #include "swad_string.h" + +/*****************************************************************************/ +/************************ Public constants and types *************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/***************************** Public prototypes *****************************/ +/*****************************************************************************/ + +//------------------------------- Posts --------------------------------------- +long For_DB_InsertForumPst (long ThrCod,long UsrCod, + const char *Subject,const char *Content, + long MedCod); +bool For_DB_GetIfForumPstExists (long PstCod); +unsigned For_DB_GetThreadAndNumPostsGivenPstCod (MYSQL_RES **mysql_res,long PstCod); +void For_DB_RemovePst (long PstCod); +void For_DB_RemoveThreadPsts (long ThrCod); + +//------------------------------ Threads -------------------------------------- +long For_DB_InsertForumThread (const struct For_Forums *Forums, + long FirstPstCod); +void For_DB_GetThrSubject (long ThrCod,char Subject[Cns_MAX_BYTES_SUBJECT + 1]); +void For_DB_RemoveThread (long ThrCod); + +//--------------------------- Disabled posts ---------------------------------- +void For_DB_InsertPstIntoDisabled (long PstCod); +bool For_DB_GetIfPstIsEnabled (long PstCod); +void For_DB_RemovePstFromDisabled (long PstCod); +void For_DB_RemoveDisabledPstsInThread (long ThrCod); + +#endif diff --git a/swad_media_database.h b/swad_media_database.h index 661ee794..31984254 100644 --- a/swad_media_database.h +++ b/swad_media_database.h @@ -27,10 +27,6 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -// #include // To access MySQL databases - -// #include "swad_cryptography.h" - /*****************************************************************************/ /***************************** Public constants ******************************/ /*****************************************************************************/ diff --git a/swad_notification.h b/swad_notification.h index 9480a816..2c753f8e 100644 --- a/swad_notification.h +++ b/swad_notification.h @@ -27,7 +27,6 @@ /********************************** Headers **********************************/ /*****************************************************************************/ -// #include "swad_browser.h" #include "swad_user.h" /*****************************************************************************/ diff --git a/swad_notification_database.c b/swad_notification_database.c index e0d0361b..67811386 100644 --- a/swad_notification_database.c +++ b/swad_notification_database.c @@ -25,38 +25,8 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -// #include // For NULL -// #include // For system -// #include -// #include // For the macro WEXITSTATUS -// #include // For unlink - -// #include "swad_action.h" -// #include "swad_box.h" -// #include "swad_call_for_exam.h" -// #include "swad_config.h" -// #include "swad_config.h" #include "swad_database.h" -// #include "swad_enrolment.h" -// #include "swad_error.h" -// #include "swad_figure.h" -// #include "swad_follow.h" -// #include "swad_form.h" -// #include "swad_forum.h" -// #include "swad_global.h" -// #include "swad_hierarchy.h" -// #include "swad_hierarchy_level.h" -// #include "swad_HTML.h" -// #include "swad_mark.h" -// #include "swad_message.h" -// #include "swad_notice.h" -// #include "swad_notification.h" #include "swad_notification_database.h" -// #include "swad_parameter.h" -// #include "swad_survey.h" -// #include "swad_timeline.h" -// #include "swad_timeline_notification.h" -// #include "swad_timeline_publication.h" /*****************************************************************************/ /************** External global variables from others modules ****************/ diff --git a/swad_notification_database.h b/swad_notification_database.h index d26dfcf6..07f69ecf 100644 --- a/swad_notification_database.h +++ b/swad_notification_database.h @@ -29,7 +29,6 @@ #include "swad_browser.h" #include "swad_notification.h" -// #include "swad_user.h" /*****************************************************************************/ /****************************** Public constants *****************************/ diff --git a/swad_zip.h b/swad_zip.h index 77688d44..3abf363b 100644 --- a/swad_zip.h +++ b/swad_zip.h @@ -27,10 +27,6 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -// #include // For PATH_MAX - -// #include "swad_group.h" - /*****************************************************************************/ /******************************* Public types ********************************/ /*****************************************************************************/