2014-12-01 23:55:08 +01:00
// swad_forum.c: forums
/*
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 .
2018-04-24 13:21:53 +02:00
Copyright ( C ) 1999 - 2018 Antonio Ca <EFBFBD> as Vargas
2014-12-01 23:55:08 +01:00
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 < http : //www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/********************************* Headers ***********************************/
/*****************************************************************************/
2018-10-22 00:31:44 +02:00
# define _GNU_SOURCE // For asprintf
2014-12-01 23:55:08 +01:00
# include <linux/stddef.h> // For NULL
# include <malloc.h> // For malloc
# include <mysql/mysql.h> // To access MySQL databases
2018-10-22 00:31:44 +02:00
# include <stdio.h> // For asprintf
2014-12-01 23:55:08 +01:00
# include <string.h>
# include <time.h> // For time_t
# include "swad_action.h"
2017-06-10 21:38:10 +02:00
# include "swad_box.h"
2014-12-01 23:55:08 +01:00
# include "swad_config.h"
# include "swad_database.h"
# include "swad_forum.h"
# include "swad_global.h"
# include "swad_layout.h"
2015-01-17 20:06:25 +01:00
# include "swad_logo.h"
2014-12-01 23:55:08 +01:00
# include "swad_notification.h"
# include "swad_parameter.h"
2015-03-14 17:39:04 +01:00
# include "swad_profile.h"
2016-12-13 13:32:19 +01:00
# include "swad_role.h"
2015-12-28 20:46:48 +01:00
# include "swad_social.h"
2017-06-11 20:09:59 +02:00
# include "swad_table.h"
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl ;
/*****************************************************************************/
/*********************** Private constants and types *************************/
/*****************************************************************************/
# define For_FORUM_MAX_LEVELS 4
const unsigned PermissionThreadDeletion [ For_NUM_TYPES_FORUM ] =
{
2017-06-01 17:53:09 +02:00
0x3F0 , // For_FORUM_COURSE_USRS
0x3F0 , // For_FORUM_COURSE_TCHS
0x3E0 , // For_FORUM_DEGREE_USRS
0x3E0 , // For_FORUM_DEGREE_TCHS
0x3C0 , // For_FORUM_CENTRE_USRS
0x3C0 , // For_FORUM_CENTRE_TCHS
0x380 , // For_FORUM_INSTIT_USRS
0x380 , // For_FORUM_INSTIT_TCHS
0x300 , // For_FORUM_GLOBAL_USRS
0x300 , // For_FORUM_GLOBAL_TCHS
0x300 , // For_FORUM__SWAD__USRS
0x300 , // For_FORUM__SWAD__TCHS
2017-04-18 19:55:56 +02:00
0x000 , // For_FORUM_UNKNOWN
2014-12-01 23:55:08 +01:00
} ;
const Act_Action_t For_ActionsSeeFor [ For_NUM_TYPES_FORUM ] =
{
ActSeeForCrsUsr ,
ActSeeForCrsTch ,
ActSeeForDegUsr ,
ActSeeForDegTch ,
ActSeeForCtrUsr ,
ActSeeForCtrTch ,
ActSeeForInsUsr ,
ActSeeForInsTch ,
ActSeeForGenUsr ,
ActSeeForGenTch ,
ActSeeForSWAUsr ,
ActSeeForSWATch ,
2017-04-18 19:55:56 +02:00
ActSeeFor , // For_FORUM_UNKNOWN
2014-12-01 23:55:08 +01:00
} ;
const Act_Action_t For_ActionsSeePstFor [ For_NUM_TYPES_FORUM ] =
{
ActSeePstForCrsUsr ,
ActSeePstForCrsTch ,
ActSeePstForDegUsr ,
ActSeePstForDegTch ,
ActSeePstForCtrUsr ,
ActSeePstForCtrTch ,
ActSeePstForInsUsr ,
ActSeePstForInsTch ,
ActSeePstForGenUsr ,
ActSeePstForGenTch ,
ActSeePstForSWAUsr ,
ActSeePstForSWATch ,
2017-04-18 19:55:56 +02:00
ActSeeFor , // For_FORUM_UNKNOWN
2014-12-01 23:55:08 +01:00
} ;
const Act_Action_t For_ActionsRecThrFor [ For_NUM_TYPES_FORUM ] =
{
ActRcvThrForCrsUsr ,
ActRcvThrForCrsTch ,
ActRcvThrForDegUsr ,
ActRcvThrForDegTch ,
ActRcvThrForCtrUsr ,
ActRcvThrForCtrTch ,
ActRcvThrForInsUsr ,
ActRcvThrForInsTch ,
ActRcvThrForGenUsr ,
ActRcvThrForGenTch ,
ActRcvThrForSWAUsr ,
ActRcvThrForSWATch ,
2017-04-18 19:55:56 +02:00
ActSeeFor , // For_FORUM_UNKNOWN
2014-12-01 23:55:08 +01:00
} ;
const Act_Action_t For_ActionsRecRepFor [ For_NUM_TYPES_FORUM ] =
{
ActRcvRepForCrsUsr ,
ActRcvRepForCrsTch ,
ActRcvRepForDegUsr ,
ActRcvRepForDegTch ,
ActRcvRepForCtrUsr ,
ActRcvRepForCtrTch ,
ActRcvRepForInsUsr ,
ActRcvRepForInsTch ,
ActRcvRepForGenUsr ,
ActRcvRepForGenTch ,
ActRcvRepForSWAUsr ,
ActRcvRepForSWATch ,
2017-04-18 19:55:56 +02:00
ActSeeFor , // For_FORUM_UNKNOWN
2014-12-01 23:55:08 +01:00
} ;
const Act_Action_t For_ActionsReqDelThr [ For_NUM_TYPES_FORUM ] =
{
ActReqDelThrCrsUsr ,
ActReqDelThrCrsTch ,
ActReqDelThrDegUsr ,
ActReqDelThrDegTch ,
ActReqDelThrCtrUsr ,
ActReqDelThrCtrTch ,
ActReqDelThrInsUsr ,
ActReqDelThrInsTch ,
ActReqDelThrGenUsr ,
ActReqDelThrGenTch ,
ActReqDelThrSWAUsr ,
ActReqDelThrSWATch ,
2017-04-18 19:55:56 +02:00
ActSeeFor , // For_FORUM_UNKNOWN
2014-12-01 23:55:08 +01:00
} ;
const Act_Action_t For_ActionsDelThrFor [ For_NUM_TYPES_FORUM ] =
{
ActDelThrForCrsUsr ,
ActDelThrForCrsTch ,
ActDelThrForDegUsr ,
ActDelThrForDegTch ,
ActDelThrForCtrUsr ,
ActDelThrForCtrTch ,
ActDelThrForInsUsr ,
ActDelThrForInsTch ,
ActDelThrForGenUsr ,
ActDelThrForGenTch ,
ActDelThrForSWAUsr ,
ActDelThrForSWATch ,
2017-04-18 19:55:56 +02:00
ActSeeFor , // For_FORUM_UNKNOWN
2014-12-01 23:55:08 +01:00
} ;
const Act_Action_t For_ActionsCutThrFor [ For_NUM_TYPES_FORUM ] =
{
ActCutThrForCrsUsr ,
ActCutThrForCrsTch ,
ActCutThrForDegUsr ,
ActCutThrForDegTch ,
ActCutThrForCtrUsr ,
ActCutThrForCtrTch ,
ActCutThrForInsUsr ,
ActCutThrForInsTch ,
ActCutThrForGenUsr ,
ActCutThrForGenTch ,
ActCutThrForSWAUsr ,
ActCutThrForSWATch ,
2017-04-18 19:55:56 +02:00
ActSeeFor , // For_FORUM_UNKNOWN
2014-12-01 23:55:08 +01:00
} ;
const Act_Action_t For_ActionsPasThrFor [ For_NUM_TYPES_FORUM ] =
{
ActPasThrForCrsUsr ,
ActPasThrForCrsTch ,
ActPasThrForDegUsr ,
ActPasThrForDegTch ,
ActPasThrForCtrUsr ,
ActPasThrForCtrTch ,
ActPasThrForInsUsr ,
ActPasThrForInsTch ,
ActPasThrForGenUsr ,
ActPasThrForGenTch ,
ActPasThrForSWAUsr ,
ActPasThrForSWATch ,
2017-04-18 19:55:56 +02:00
ActSeeFor , // For_FORUM_UNKNOWN
2014-12-01 23:55:08 +01:00
} ;
const Act_Action_t For_ActionsDelPstFor [ For_NUM_TYPES_FORUM ] =
{
ActDelPstForCrsUsr ,
ActDelPstForCrsTch ,
ActDelPstForDegUsr ,
ActDelPstForDegTch ,
ActDelPstForCtrUsr ,
ActDelPstForCtrTch ,
ActDelPstForInsUsr ,
ActDelPstForInsTch ,
ActDelPstForGenUsr ,
ActDelPstForGenTch ,
ActDelPstForSWAUsr ,
ActDelPstForSWATch ,
2017-04-18 19:55:56 +02:00
ActSeeFor , // For_FORUM_UNKNOWN
2014-12-01 23:55:08 +01:00
} ;
const Act_Action_t For_ActionsEnbPstFor [ For_NUM_TYPES_FORUM ] =
{
ActEnbPstForCrsUsr ,
ActEnbPstForCrsTch ,
ActEnbPstForDegUsr ,
ActEnbPstForDegTch ,
ActEnbPstForCtrUsr ,
ActEnbPstForCtrTch ,
ActEnbPstForInsUsr ,
ActEnbPstForInsTch ,
ActEnbPstForGenUsr ,
ActEnbPstForGenTch ,
ActEnbPstForSWAUsr ,
ActEnbPstForSWATch ,
2017-04-18 19:55:56 +02:00
ActSeeFor , // For_FORUM_UNKNOWN
2014-12-01 23:55:08 +01:00
} ;
const Act_Action_t For_ActionsDisPstFor [ For_NUM_TYPES_FORUM ] =
{
ActDisPstForCrsUsr ,
ActDisPstForCrsTch ,
ActDisPstForDegUsr ,
ActDisPstForDegTch ,
ActDisPstForCtrUsr ,
ActDisPstForCtrTch ,
ActDisPstForInsUsr ,
ActDisPstForInsTch ,
ActDisPstForGenUsr ,
ActDisPstForGenTch ,
ActDisPstForSWAUsr ,
ActDisPstForSWATch ,
2017-04-18 19:55:56 +02:00
ActSeeFor , // For_FORUM_UNKNOWN
2014-12-01 23:55:08 +01:00
} ;
2017-04-11 14:27:45 +02:00
// Links to go to <section>
2017-05-25 13:43:54 +02:00
# 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"
2017-04-10 12:41:26 +02:00
2016-04-10 14:09:50 +02:00
// Forum images will be saved with:
// - maximum width of For_IMAGE_SAVED_MAX_HEIGHT
// - maximum height of For_IMAGE_SAVED_MAX_HEIGHT
// - maintaining the original aspect ratio (aspect ratio recommended: 3:2)
# define For_IMAGE_SAVED_MAX_WIDTH 768
# define For_IMAGE_SAVED_MAX_HEIGHT 512
# define For_IMAGE_SAVED_QUALITY 75 // 1 to 100
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/***************************** Private prototypes ***************************/
/*****************************************************************************/
2016-04-10 19:19:20 +02:00
static bool For_GetIfForumPstExists ( long PstCod ) ;
static bool For_GetIfPstIsEnabled ( long PstCod ) ;
static void For_DeletePstFromDisabledPstTable ( long PstCod ) ;
static void For_InsertPstIntoBannedPstTable ( long PstCod ) ;
static long For_InsertForumPst ( long ThrCod , long UsrCod ,
const char * Subject , const char * Content ,
struct Image * Image ) ;
2016-04-10 23:59:45 +02:00
static bool For_RemoveForumPst ( long PstCod , struct Image * Image ) ;
2016-04-10 19:19:20 +02:00
static unsigned For_NumPstsInThrWithPstCod ( long PstCod , long * ThrCod ) ;
2017-04-19 12:34:38 +02:00
static long For_InsertForumThread ( long FirstPstCod ) ;
2016-04-10 19:19:20 +02:00
static void For_RemoveThreadOnly ( long ThrCod ) ;
static void For_RemoveThreadAndItsPsts ( long ThrCod ) ;
2017-01-17 03:10:43 +01:00
static void For_GetThrSubject ( long ThrCod , char Subject [ Cns_MAX_BYTES_SUBJECT + 1 ] ) ;
2017-04-18 19:55:56 +02:00
2016-04-10 19:19:20 +02:00
static void For_UpdateThrFirstAndLastPst ( long ThrCod , long FirstPstCod , long LastPstCod ) ;
static void For_UpdateThrLastPst ( long ThrCod , long LastPstCod ) ;
static long For_GetLastPstCod ( long ThrCod ) ;
2017-04-19 12:34:38 +02:00
static void For_UpdateThrReadTime ( long ThrCod ,
time_t CreatTimeUTCOfTheMostRecentPostRead ) ;
2015-10-24 20:12:03 +02:00
static unsigned For_GetNumOfReadersOfThr ( long ThrCod ) ;
static unsigned For_GetNumOfWritersInThr ( long ThrCod ) ;
static unsigned For_GetNumPstsInThr ( long ThrCod ) ;
static unsigned For_GetNumMyPstInThr ( long ThrCod ) ;
static time_t For_GetThrReadTime ( long ThrCod ) ;
2017-04-16 23:48:05 +02:00
static void For_DeleteThrFromReadThrs ( long ThrCod ) ;
2017-05-11 23:45:46 +02:00
static void For_ShowPostsOfAThread ( Ale_AlertType_t AlertType , const char * Message ) ;
2017-04-17 12:19:58 +02:00
static void For_PutIconNewPost ( void ) ;
2017-04-19 14:43:08 +02:00
static void For_PutAllHiddenParamsNewPost ( void ) ;
2016-11-07 10:53:03 +01:00
2017-04-19 12:34:38 +02:00
static void For_ShowAForumPost ( unsigned PstNum , long PstCod ,
2017-01-17 03:10:43 +01:00
bool LastPst , char LastSubject [ Cns_MAX_BYTES_SUBJECT + 1 ] ,
2016-11-07 10:53:03 +01:00
bool NewPst , bool ICanModerateForum ) ;
static void For_GetPstData ( long PstCod , long * UsrCod , time_t * CreatTimeUTC ,
2017-01-17 03:10:43 +01:00
char Subject [ Cns_MAX_BYTES_SUBJECT + 1 ] ,
char Content [ Cns_MAX_BYTES_LONG_TEXT + 1 ] ,
struct Image * Image ) ;
2017-04-19 12:34:38 +02:00
static void For_WriteNumberOfPosts ( long UsrCod ) ;
2016-11-07 10:53:03 +01:00
2017-04-18 01:25:44 +02:00
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 ) ;
2017-04-17 12:19:58 +02:00
2017-04-18 01:25:44 +02:00
static void For_ShowForumList ( void ) ;
2017-04-17 12:19:58 +02:00
static void For_PutIconsForums ( void ) ;
2014-12-01 23:55:08 +01:00
static void For_PutFormWhichForums ( void ) ;
2017-04-16 13:45:11 +02:00
2017-01-28 15:58:46 +01:00
static void For_WriteLinksToGblForums ( bool IsLastItemInLevel [ 1 + For_FORUM_MAX_LEVELS ] ) ;
2016-12-13 13:32:19 +01:00
static void For_WriteLinksToPlatformForums ( bool IsLastForum ,
2017-01-28 15:58:46 +01:00
bool IsLastItemInLevel [ 1 + For_FORUM_MAX_LEVELS ] ) ;
static long For_WriteLinksToInsForums ( long InsCod , bool IsLastIns ,
bool IsLastItemInLevel [ 1 + For_FORUM_MAX_LEVELS ] ) ;
static long For_WriteLinksToCtrForums ( long CtrCod , bool IsLastCtr ,
bool IsLastItemInLevel [ 1 + For_FORUM_MAX_LEVELS ] ) ;
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 ] ) ;
2017-04-18 01:25:44 +02:00
static void For_WriteLinkToForum ( struct Forum * Forum ,
2017-04-11 13:53:17 +02:00
bool Highlight , bool ShowNumOfPosts ,
2017-04-19 12:34:38 +02:00
unsigned Level ,
bool IsLastItemInLevel [ 1 + For_FORUM_MAX_LEVELS ] ) ;
static unsigned For_GetNumThrsWithNewPstsInForum ( struct Forum * Forum ,
2017-04-16 23:48:05 +02:00
unsigned NumThreads ) ;
2017-04-19 12:34:38 +02:00
static unsigned For_GetNumOfThreadsInForumNewerThan ( struct Forum * Forum ,
2017-04-16 23:48:05 +02:00
const char * Time ) ;
2014-12-01 23:55:08 +01:00
static unsigned For_GetNumOfUnreadPostsInThr ( long ThrCod , unsigned NumPostsInThr ) ;
static unsigned For_GetNumOfPostsInThrNewerThan ( long ThrCod , const char * Time ) ;
2015-04-11 14:00:23 +02:00
2014-12-28 17:00:11 +01:00
static void For_WriteNumThrsAndPsts ( unsigned NumThrs , unsigned NumThrsWithNewPosts , unsigned NumPosts ) ;
2017-04-17 12:19:58 +02:00
static void For_WriteNumberOfThrs ( unsigned NumThrs , unsigned NumThrsWithNewPosts ) ;
2017-04-18 09:55:25 +02:00
static void For_ShowForumThreadsHighlightingOneThread ( long ThrCodHighlighted ,
2017-05-11 23:45:46 +02:00
Ale_AlertType_t AlertType , const char * Message ) ;
2017-04-17 12:19:58 +02:00
static void For_PutIconNewThread ( void ) ;
2017-04-19 14:43:08 +02:00
static void For_PutAllHiddenParamsNewThread ( void ) ;
2017-04-19 12:34:38 +02:00
static unsigned For_GetNumThrsInForum ( struct Forum * Forum ) ;
static unsigned For_GetNumPstsInForum ( struct Forum * Forum ) ;
2017-04-13 23:53:57 +02:00
static void For_ListForumThrs ( long ThrCods [ Pag_ITEMS_PER_PAGE ] ,
2017-04-14 01:02:33 +02:00
long ThrCodHighlighted ,
2017-04-13 23:53:57 +02:00
struct Pagination * PaginationThrs ) ;
static void For_GetThrData ( struct ForumThread * Thr ) ;
2017-04-12 20:56:45 +02:00
2017-02-24 03:38:18 +01:00
static void For_GetParamsForum ( void ) ;
2017-04-16 13:45:11 +02:00
static void For_SetForumType ( void ) ;
static void For_RestrictAccess ( void ) ;
2014-12-01 23:55:08 +01:00
2017-04-18 01:25:44 +02:00
static void For_WriteFormForumPst ( bool IsReply , const char * Subject ) ;
2017-04-17 12:19:58 +02:00
static void For_UpdateNumUsrsNotifiedByEMailAboutPost ( long PstCod , unsigned NumUsrsToBeNotifiedByEMail ) ;
2017-04-28 10:35:41 +02:00
static void For_PutAllHiddenParamsRemThread ( void ) ;
2017-04-18 13:17:40 +02:00
static bool For_CheckIfICanMoveThreads ( void ) ;
2017-04-17 12:19:58 +02:00
static long For_GetThrInMyClipboard ( void ) ;
2017-04-19 12:34:38 +02:00
static bool For_CheckIfThrBelongsToForum ( long ThrCod , struct Forum * Forum ) ;
2017-04-17 12:19:58 +02:00
static void For_MoveThrToCurrentForum ( long ThrCod ) ;
static void For_InsertThrInClipboard ( long ThrCod ) ;
static void For_RemoveExpiredThrsClipboards ( void ) ;
static void For_RemoveThrCodFromThrClipboard ( long ThrCod ) ;
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/****************************** Enable a forum post **************************/
/*****************************************************************************/
2017-04-18 16:44:44 +02:00
void For_EnablePost ( void )
2014-12-01 23:55:08 +01:00
{
extern const char * Txt_Post_unbanned ;
2017-04-16 13:45:11 +02:00
/***** Get parameters related to forum *****/
2014-12-01 23:55:08 +01:00
For_GetParamsForum ( ) ;
/***** Delete post from table of disabled posts *****/
2017-04-18 01:25:44 +02:00
For_DeletePstFromDisabledPstTable ( Gbl . Forum . ForumSelected . PstCod ) ;
2014-12-01 23:55:08 +01:00
2017-04-18 13:17:40 +02:00
/***** Show forum list again *****/
For_ShowForumList ( ) ;
/***** Show threads again *****/
For_ShowForumThreadsHighlightingOneThread ( Gbl . Forum . ForumSelected . ThrCod ,
2017-05-11 23:45:46 +02:00
Ale_SUCCESS , NULL ) ;
2017-04-18 13:17:40 +02:00
2014-12-01 23:55:08 +01:00
/***** Show the posts again *****/
2017-05-11 23:45:46 +02:00
For_ShowPostsOfAThread ( Ale_SUCCESS , Txt_Post_unbanned ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/***************************** Disable a forum post **************************/
/*****************************************************************************/
2017-04-18 16:44:44 +02:00
void For_DisablePost ( void )
2014-12-01 23:55:08 +01:00
{
extern const char * Txt_Post_banned ;
2017-04-16 13:45:11 +02:00
/***** Get parameters related to forum *****/
2014-12-01 23:55:08 +01:00
For_GetParamsForum ( ) ;
/***** Check if post really exists, if it has not been removed *****/
2017-04-18 01:25:44 +02:00
if ( For_GetIfForumPstExists ( Gbl . Forum . ForumSelected . PstCod ) )
2014-12-01 23:55:08 +01:00
{
/***** Insert post into table of banned posts *****/
2017-04-18 01:25:44 +02:00
For_InsertPstIntoBannedPstTable ( Gbl . Forum . ForumSelected . PstCod ) ;
2017-04-18 09:55:25 +02:00
2017-04-18 13:17:40 +02:00
/***** Show forum list again *****/
For_ShowForumList ( ) ;
/***** Show threads again *****/
For_ShowForumThreadsHighlightingOneThread ( Gbl . Forum . ForumSelected . ThrCod ,
2017-05-11 23:45:46 +02:00
Ale_SUCCESS , NULL ) ;
2017-04-18 13:17:40 +02:00
2017-04-18 09:55:25 +02:00
/***** Show the posts again *****/
2017-05-11 23:45:46 +02:00
For_ShowPostsOfAThread ( Ale_SUCCESS , Txt_Post_banned ) ;
2014-12-01 23:55:08 +01:00
}
else
Lay_ShowErrorAndExit ( " The post to be banned no longer exists. " ) ;
}
/*****************************************************************************/
/******************** Get if a forum post exists in database *****************/
/*****************************************************************************/
2016-04-10 19:19:20 +02:00
static bool For_GetIfForumPstExists ( long PstCod )
2014-12-01 23:55:08 +01:00
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
/***** Get if a forum post exists from database *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " SELECT COUNT(*) FROM forum_post WHERE PstCod=%ld " ,
PstCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
return ( DB_QueryCOUNT_free ( Query , " can not check if a post of a forum already existed " ) ! = 0 ) ; // Post exists if it appears in table of forum posts
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*********************** Get if a forum post is enabled **********************/
/*****************************************************************************/
2016-04-10 19:19:20 +02:00
static bool For_GetIfPstIsEnabled ( long PstCod )
2014-12-01 23:55:08 +01:00
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
2016-12-30 01:20:49 +01:00
if ( PstCod > 0 )
{
/***** Get if post is disabled from database *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " SELECT COUNT(*) FROM forum_disabled_post "
" WHERE PstCod=%ld " ,
PstCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
return ( DB_QueryCOUNT_free ( Query , " can not check if a post of a forum is disabled " ) = = 0 ) ; // Post is enabled if it does not appear in table of disabled posts
2016-12-30 01:20:49 +01:00
}
else
return false ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/****************** Delete post from table of disabled posts *****************/
/*****************************************************************************/
2016-04-10 19:19:20 +02:00
static void For_DeletePstFromDisabledPstTable ( long PstCod )
2014-12-01 23:55:08 +01:00
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
/***** Remove post from disabled posts table *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " DELETE FROM forum_disabled_post WHERE PstCod=%ld " ,
PstCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
DB_QueryDELETE_free ( Query , " can not unban a post of a forum " ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/****************** Insert post into table of banned posts *******************/
/*****************************************************************************/
2016-04-10 19:19:20 +02:00
static void For_InsertPstIntoBannedPstTable ( long PstCod )
2014-12-01 23:55:08 +01:00
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
/***** Remove post from banned posts table *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " REPLACE INTO forum_disabled_post "
" (PstCod,UsrCod,DisableTime) "
" VALUES "
" (%ld,%ld,NOW()) " ,
PstCod , Gbl . Usrs . Me . UsrDat . UsrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
DB_QueryREPLACE_free ( Query , " can not ban a post of a forum " ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************** Insert a post new in the table of posts of forums ************/
/*****************************************************************************/
2016-04-10 19:19:20 +02:00
static long For_InsertForumPst ( long ThrCod , long UsrCod ,
const char * Subject , const char * Content ,
struct Image * Image )
2014-12-01 23:55:08 +01:00
{
2016-04-10 19:19:20 +02:00
char * Query ;
long PstCod ;
2016-04-11 02:16:27 +02:00
/***** Check if image is received and processed *****/
if ( Image - > Action = = Img_ACTION_NEW_IMAGE & & // Upload new image
Image - > Status = = Img_FILE_PROCESSED ) // The new image received has been processed
/* Move processed image to definitive directory */
Img_MoveImageToDefinitiveDirectory ( Image ) ;
2014-12-01 23:55:08 +01:00
/***** Insert forum post in the database *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " INSERT INTO forum_post "
" (ThrCod,UsrCod,CreatTime,ModifTime,NumNotif, "
" Subject,Content,ImageName,ImageTitle,ImageURL) "
" VALUES "
" (%ld,%ld,NOW(),NOW(),0, "
" '%s','%s','%s','%s','%s') " ,
ThrCod , UsrCod ,
Subject , Content ,
Image - > Name ,
Image - > Title ? Image - > Title : " " ,
Image - > URL ? Image - > URL : " " ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
PstCod = DB_QueryINSERTandReturnCode_free ( Query , " can not create a new post in a forum " ) ;
2016-04-10 19:19:20 +02:00
return PstCod ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/***************** Delete a post from the forum post table *******************/
/*****************************************************************************/
// Return true if the post thread is deleted
2016-04-10 23:59:45 +02:00
static bool For_RemoveForumPst ( long PstCod , struct Image * Image )
2014-12-01 23:55:08 +01:00
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
long ThrCod ;
bool ThreadDeleted = false ;
2016-04-10 23:59:45 +02:00
/***** Remove image file attached to forum post *****/
Img_RemoveImageFile ( Image - > Name ) ;
2014-12-01 23:55:08 +01:00
/***** If the post is the only one in its thread, delete that thread *****/
if ( For_NumPstsInThrWithPstCod ( PstCod , & ThrCod ) < 2 )
{
For_RemoveThreadOnly ( ThrCod ) ;
ThreadDeleted = true ;
}
/***** Delete post from forum post table *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " DELETE FROM forum_post WHERE PstCod=%ld " ,
PstCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
DB_QueryDELETE_free ( Query , " can not remove a post from a forum " ) ;
2014-12-01 23:55:08 +01:00
/***** Delete the post from the table of disabled forum posts *****/
For_DeletePstFromDisabledPstTable ( PstCod ) ;
/***** Update the last post of the thread *****/
if ( ! ThreadDeleted )
For_UpdateThrLastPst ( ThrCod , For_GetLastPstCod ( ThrCod ) ) ;
return ThreadDeleted ;
}
/*****************************************************************************/
/*********** Get the number of posts in the thread than holds a post *********/
/*****************************************************************************/
2016-04-10 19:19:20 +02:00
static unsigned For_NumPstsInThrWithPstCod ( long PstCod , long * ThrCod )
2014-12-01 23:55:08 +01:00
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
MYSQL_RES * mysql_res ;
MYSQL_ROW row ;
unsigned NumPsts ;
/***** Get number of posts in the thread that holds a post from database *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " SELECT COUNT(PstCod),ThrCod FROM forum_post "
" WHERE ThrCod IN "
" (SELECT ThrCod FROM forum_post "
" WHERE PstCod=%ld) GROUP BY ThrCod; " ,
PstCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
DB_QuerySELECT_free ( Query , & mysql_res , " can not get number of posts in a thread of a forum " ) ;
2014-12-01 23:55:08 +01:00
row = mysql_fetch_row ( mysql_res ) ;
if ( sscanf ( row [ 0 ] , " %u " , & NumPsts ) ! = 1 )
Lay_ShowErrorAndExit ( " Error when getting number of posts in a thread of a forum. " ) ;
if ( sscanf ( row [ 1 ] , " %ld " , ThrCod ) ! = 1 )
Lay_ShowErrorAndExit ( " Error when getting number of posts in a thread of a forum. " ) ;
DB_FreeMySQLResult ( & mysql_res ) ;
return NumPsts ;
}
/*****************************************************************************/
/*************** Insert a new thread in table of forum threads ***************/
/*****************************************************************************/
// Returns the code of the new inserted thread
2017-04-19 12:34:38 +02:00
static long For_InsertForumThread ( long FirstPstCod )
2014-12-01 23:55:08 +01:00
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
/***** Insert new thread in the database *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " INSERT INTO forum_thread "
" (ForumType,Location,FirstPstCod,LastPstCod) "
" VALUES "
" (%u,%ld,%ld,%ld) " ,
( unsigned ) Gbl . Forum . ForumSelected . Type ,
Gbl . Forum . ForumSelected . Location ,
FirstPstCod , FirstPstCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
return DB_QueryINSERTandReturnCode_free ( Query , " can not create a new thread in a forum " ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*************** Delete a thread from the forum thread table *****************/
/*****************************************************************************/
2016-04-10 19:19:20 +02:00
static void For_RemoveThreadOnly ( long ThrCod )
2014-12-01 23:55:08 +01:00
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
/***** Indicate that this thread has not been read by anyone *****/
For_DeleteThrFromReadThrs ( ThrCod ) ;
/***** Remove thread code from thread clipboard *****/
For_RemoveThrCodFromThrClipboard ( ThrCod ) ;
/***** Delete thread from forum thread table *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " DELETE FROM forum_thread WHERE ThrCod=%ld " ,
ThrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
DB_QueryDELETE_free ( Query , " can not remove a thread from a forum " ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*************** Delete a thread from the forum thread table *****************/
/*****************************************************************************/
2016-04-10 19:19:20 +02:00
static void For_RemoveThreadAndItsPsts ( long ThrCod )
2014-12-01 23:55:08 +01:00
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
/***** Delete banned posts in thread *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " DELETE forum_disabled_post "
" FROM forum_post,forum_disabled_post "
" WHERE forum_post.ThrCod=%ld "
" AND forum_post.PstCod=forum_disabled_post.PstCod " ,
ThrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
DB_QueryDELETE_free ( Query , " can not unban the posts of a thread of a forum " ) ;
2014-12-01 23:55:08 +01:00
/***** Delete thread posts *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " DELETE FROM forum_post WHERE ThrCod=%ld " ,
ThrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
DB_QueryDELETE_free ( Query , " can not remove the posts of a thread of a forum " ) ;
2014-12-01 23:55:08 +01:00
/***** Delete thread from forum thread table *****/
For_RemoveThreadOnly ( ThrCod ) ;
}
/*****************************************************************************/
/********************* Get the thread subject from a thread ******************/
/*****************************************************************************/
2017-01-17 03:10:43 +01:00
static void For_GetThrSubject ( long ThrCod , char Subject [ Cns_MAX_BYTES_SUBJECT + 1 ] )
2014-12-01 23:55:08 +01:00
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
MYSQL_RES * mysql_res ;
MYSQL_ROW row ;
/***** Get subject of a thread from database *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " SELECT forum_post.Subject FROM forum_thread,forum_post "
" WHERE forum_thread.ThrCod=%ld "
" AND forum_thread.FirstPstCod=forum_post.PstCod " ,
ThrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
DB_QuerySELECT_free ( Query , & mysql_res , " can not get the subject of a thread of a forum " ) ;
2014-12-01 23:55:08 +01:00
/***** Write the subject of the thread *****/
row = mysql_fetch_row ( mysql_res ) ;
2017-01-17 03:10:43 +01:00
Str_Copy ( Subject , row [ 0 ] ,
Cns_MAX_BYTES_SUBJECT ) ;
2014-12-01 23:55:08 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult ( & mysql_res ) ;
}
/*****************************************************************************/
2017-04-17 11:57:55 +02:00
/*************** Get the forum type and location of a post *******************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2017-04-19 12:34:38 +02:00
void For_GetForumTypeAndLocationOfAPost ( long PstCod , struct Forum * Forum )
2014-12-01 23:55:08 +01:00
{
2018-10-22 00:31:44 +02:00
char * Query ;
2017-04-18 19:55:56 +02:00
MYSQL_RES * mysql_res ;
MYSQL_ROW row ;
unsigned UnsignedNum ;
long LongNum ;
/***** Set default forum type and location *****/
2017-04-19 12:34:38 +02:00
Forum - > Type = For_FORUM_UNKNOWN ;
Forum - > Location = - 1L ;
2014-12-01 23:55:08 +01:00
/***** Get forum type of a forum from database *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " SELECT forum_thread.ForumType,forum_thread.Location "
" FROM forum_post,forum_thread "
" WHERE forum_post.PstCod=%ld "
" AND forum_post.ThrCod=forum_thread.ThrCod " ,
PstCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
2014-12-01 23:55:08 +01:00
/***** Check if there is a row with forum type *****/
2018-10-22 00:31:44 +02:00
if ( DB_QuerySELECT_free ( Query , & mysql_res , " can not get forum type and location " ) )
2014-12-01 23:55:08 +01:00
{
row = mysql_fetch_row ( mysql_res ) ;
2017-04-16 23:48:05 +02:00
/* Get forum type (row[0]) */
2017-04-18 19:55:56 +02:00
if ( sscanf ( row [ 0 ] , " %u " , & UnsignedNum ) = = 1 )
if ( UnsignedNum < For_NUM_TYPES_FORUM )
2017-04-19 12:34:38 +02:00
Forum - > Type = ( For_ForumType_t ) UnsignedNum ;
2017-04-16 23:48:05 +02:00
/* Get forum location (row[1]) */
2017-04-18 19:55:56 +02:00
if ( sscanf ( row [ 1 ] , " %ld " , & LongNum ) = = 1 )
2017-04-19 12:34:38 +02:00
Forum - > Location = LongNum ;
2014-12-01 23:55:08 +01:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult ( & mysql_res ) ;
}
/*****************************************************************************/
/********* Modify the codes of the first and last posts of a thread **********/
/*****************************************************************************/
2016-04-10 19:19:20 +02:00
static void For_UpdateThrFirstAndLastPst ( long ThrCod , long FirstPstCod , long LastPstCod )
2014-12-01 23:55:08 +01:00
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
/***** Update the code of the first and last posts of a thread *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " UPDATE forum_thread SET FirstPstCod=%ld,LastPstCod=%ld "
" WHERE ThrCod=%ld " ,
FirstPstCod , LastPstCod , ThrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
DB_QueryUPDATE_free ( Query , " can not update a thread of a forum " ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************** Modify the code of the last post of a thread *****************/
/*****************************************************************************/
2016-04-10 19:19:20 +02:00
static void For_UpdateThrLastPst ( long ThrCod , long LastPstCod )
2014-12-01 23:55:08 +01:00
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
/***** Update the code of the last post of a thread *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " UPDATE forum_thread SET LastPstCod=%ld "
" WHERE ThrCod=%ld " ,
LastPstCod , ThrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
DB_QueryUPDATE_free ( Query , " can not update a thread of a forum " ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/**************** Get the code of the last post of a thread ******************/
/*****************************************************************************/
2016-04-10 19:19:20 +02:00
static long For_GetLastPstCod ( long ThrCod )
2014-12-01 23:55:08 +01:00
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
MYSQL_RES * mysql_res ;
MYSQL_ROW row ;
long LastPstCod ;
/***** Get the code of the last post of a thread from database *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " SELECT PstCod FROM forum_post "
" WHERE ThrCod=%ld ORDER BY CreatTime DESC LIMIT 1 " ,
ThrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
DB_QuerySELECT_free ( Query , & mysql_res , " can not get the most recent post of a thread of a forum " ) ;
2014-12-01 23:55:08 +01:00
/***** Write the subject of the thread *****/
row = mysql_fetch_row ( mysql_res ) ;
if ( sscanf ( row [ 0 ] , " %ld " , & LastPstCod ) ! = 1 )
Lay_ShowErrorAndExit ( " Error when getting the most recent post of a thread of a forum. " ) ;
return LastPstCod ;
}
/*****************************************************************************/
/************* Update read date of a thread for the current user *************/
/*****************************************************************************/
// 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)
2017-04-19 12:34:38 +02:00
// Note that database is not updated with the current time,
// but with the creation time of the most recent post in this thread read by me.
2014-12-01 23:55:08 +01:00
2017-04-19 12:34:38 +02:00
static void For_UpdateThrReadTime ( long ThrCod ,
time_t CreatTimeUTCOfTheMostRecentPostRead )
2014-12-01 23:55:08 +01:00
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
/***** Insert or replace pair ThrCod-UsrCod in forum_thr_read *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " REPLACE INTO forum_thr_read "
" (ThrCod,UsrCod,ReadTime) "
" VALUES "
" (%ld,%ld,FROM_UNIXTIME(%ld)) " ,
ThrCod , Gbl . Usrs . Me . UsrDat . UsrCod ,
( long ) CreatTimeUTCOfTheMostRecentPostRead ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
DB_QueryREPLACE_free ( Query , " can not update the status of reading of a thread of a forum " ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/**************** Get number of users that have read a thread ****************/
/*****************************************************************************/
2015-10-24 20:12:03 +02:00
static unsigned For_GetNumOfReadersOfThr ( long ThrCod )
2014-12-01 23:55:08 +01:00
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
/***** Get number of distinct readers of a thread from database *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " SELECT COUNT(*) FROM forum_thr_read WHERE ThrCod=%ld " ,
ThrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
return ( unsigned ) DB_QueryCOUNT_free ( Query , " can not get the number of readers "
" of a thread of a forum " ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********** Get number of users that have write posts in a thread ************/
/*****************************************************************************/
2015-10-24 20:12:03 +02:00
static unsigned For_GetNumOfWritersInThr ( long ThrCod )
2014-12-01 23:55:08 +01:00
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
MYSQL_RES * mysql_res ;
MYSQL_ROW row ;
unsigned NumWriters ;
/***** Get number of distinct writers in a thread from database *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " SELECT COUNT(DISTINCT UsrCod) FROM forum_post "
" WHERE ThrCod=%ld " ,
ThrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
DB_QuerySELECT_free ( Query , & mysql_res , " can not get the number of writers "
" in a thread of a forum " ) ;
2014-12-01 23:55:08 +01:00
/* Get row with number of writers */
row = mysql_fetch_row ( mysql_res ) ;
/* Get number of writers (row[0]) */
if ( sscanf ( row [ 0 ] , " %u " , & NumWriters ) ! = 1 )
Lay_ShowErrorAndExit ( " Error when getting the number of writers in a thread of a forum. " ) ;
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult ( & mysql_res ) ;
return NumWriters ;
}
/*****************************************************************************/
/********************** Get number of posts in a thread **********************/
/*****************************************************************************/
2015-10-24 20:12:03 +02:00
static unsigned For_GetNumPstsInThr ( long ThrCod )
2014-12-01 23:55:08 +01:00
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
/***** Get number of posts in a thread from database *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " SELECT COUNT(*) FROM forum_post WHERE ThrCod=%ld " ,
ThrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
return ( unsigned ) DB_QueryCOUNT_free ( Query , " can not get the number of posts "
" in a thread of a forum " ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************** Get whether there are posts of mine in a thread **************/
/*****************************************************************************/
2015-10-24 20:12:03 +02:00
static unsigned For_GetNumMyPstInThr ( long ThrCod )
2014-12-01 23:55:08 +01:00
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
/***** Get if I have write posts in a thread from database *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " SELECT COUNT(*) FROM forum_post "
" WHERE ThrCod=%ld AND UsrCod=%ld " ,
ThrCod , Gbl . Usrs . Me . UsrDat . UsrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
2018-10-22 10:12:41 +02:00
return ( unsigned ) DB_QueryCOUNT_free ( Query , " can not check if you have written "
" posts in a thead of a forum " ) ;
2014-12-01 23:55:08 +01:00
}
2015-03-09 18:27:24 +01:00
/*****************************************************************************/
/*********************** Get number of posts from a user *********************/
/*****************************************************************************/
2015-03-14 02:26:59 +01:00
unsigned long For_GetNumPostsUsr ( long UsrCod )
2015-03-09 18:27:24 +01:00
{
2018-10-22 00:31:44 +02:00
char * Query ;
2015-03-09 18:27:24 +01:00
/***** Get number of posts from a user from database *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " SELECT COUNT(*) FROM forum_post WHERE UsrCod=%ld " ,
UsrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
return DB_QueryCOUNT_free ( Query , " can not number of posts from a user " ) ;
2015-03-09 18:27:24 +01:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/****************** Get thread read time for the current user ****************/
/*****************************************************************************/
2015-10-24 20:12:03 +02:00
static time_t For_GetThrReadTime ( long ThrCod )
2014-12-01 23:55:08 +01:00
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
MYSQL_RES * mysql_res ;
MYSQL_ROW row ;
2015-10-24 20:12:03 +02:00
time_t ReadTimeUTC ;
2014-12-01 23:55:08 +01:00
/***** Get read time of a thread from database *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " SELECT UNIX_TIMESTAMP(ReadTime) "
" FROM forum_thr_read "
" WHERE ThrCod=%ld AND UsrCod=%ld " ,
ThrCod , Gbl . Usrs . Me . UsrDat . UsrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
if ( DB_QuerySELECT_free ( Query , & mysql_res , " can not get date of reading of a thread of a forum " ) )
2014-12-01 23:55:08 +01:00
{
2015-10-24 20:12:03 +02:00
/***** There is a row ==> get read time *****/
2014-12-01 23:55:08 +01:00
row = mysql_fetch_row ( mysql_res ) ;
2015-10-24 20:12:03 +02:00
ReadTimeUTC = Dat_GetUNIXTimeFromStr ( row [ 0 ] ) ;
2014-12-01 23:55:08 +01:00
}
else
2015-10-24 20:12:03 +02:00
ReadTimeUTC = ( time_t ) 0 ; // If there is no row for this thread and current user, then current user has not read this thread
2014-12-01 23:55:08 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult ( & mysql_res ) ;
2015-10-24 20:12:03 +02:00
return ReadTimeUTC ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Delete thread read status for a thread ****************/
/*****************************************************************************/
2017-04-16 23:48:05 +02:00
static void For_DeleteThrFromReadThrs ( long ThrCod )
2014-12-01 23:55:08 +01:00
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
/***** Delete pairs ThrCod-UsrCod in forum_thr_read for a thread *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " DELETE FROM forum_thr_read WHERE ThrCod=%ld " ,
ThrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
DB_QueryDELETE_free ( Query , " can not remove the status of reading of a thread of a forum " ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************** Delete thread read status for an user ****************/
/*****************************************************************************/
void For_RemoveUsrFromReadThrs ( long UsrCod )
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
/***** Delete pairs ThrCod-UsrCod in forum_thr_read for a user *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " DELETE FROM forum_thr_read WHERE UsrCod=%ld " ,
UsrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
DB_QueryDELETE_free ( Query , " can not remove the status of reading by a user of all the threads of a forum " ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2017-04-13 20:09:22 +02:00
/************************ Show posts in a thread *****************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2017-05-11 23:45:46 +02:00
static void For_ShowPostsOfAThread ( Ale_AlertType_t AlertType , const char * Message )
2014-12-01 23:55:08 +01:00
{
2017-04-19 14:27:52 +02:00
extern const char * Hlp_SOCIAL_Forums_posts ;
2015-04-11 14:00:23 +02:00
extern const char * Txt_Thread ;
2014-12-01 23:55:08 +01:00
struct ForumThread Thr ;
2017-04-11 19:05:15 +02:00
char LastSubject [ Cns_MAX_BYTES_SUBJECT + 1 ] ;
char FrameTitle [ 128 + Cns_MAX_BYTES_SUBJECT ] ;
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
MYSQL_RES * mysql_res ;
MYSQL_ROW row ;
2017-01-17 03:10:43 +01:00
unsigned long NumRow ;
unsigned long NumRows ;
2014-12-01 23:55:08 +01:00
unsigned NumPst = 0 ; // Initialized to avoid warning
unsigned NumPsts ;
2015-10-24 20:12:03 +02:00
time_t ReadTimeUTC ; // Read time of thread for the current user
time_t CreatTimeUTC ; // Creation time of post
2017-04-13 20:09:22 +02:00
struct Pagination PaginationPsts ;
2014-12-01 23:55:08 +01:00
long PstCod ;
bool NewPst = false ;
bool ICanModerateForum = false ;
2017-04-16 13:45:11 +02:00
2014-12-01 23:55:08 +01:00
/***** Get data of the thread *****/
2017-04-18 01:25:44 +02:00
Thr . ThrCod = Gbl . Forum . ForumSelected . ThrCod ;
2014-12-01 23:55:08 +01:00
For_GetThrData ( & Thr ) ;
2017-04-18 13:17:40 +02:00
/***** Get if there is a thread ready to be moved *****/
if ( For_CheckIfICanMoveThreads ( ) )
2014-12-01 23:55:08 +01:00
Gbl . Forum . ThreadToMove = For_GetThrInMyClipboard ( ) ;
2017-04-18 13:17:40 +02:00
/***** Get thread read time for the current user *****/
2017-04-18 01:25:44 +02:00
ReadTimeUTC = For_GetThrReadTime ( Gbl . Forum . ForumSelected . ThrCod ) ;
2014-12-01 23:55:08 +01:00
2017-04-18 09:55:25 +02:00
/***** Show alert after action *****/
2017-05-25 13:43:54 +02:00
Lay_StartSection ( For_FORUM_POSTS_SECTION_ID ) ;
2017-04-18 09:55:25 +02:00
if ( Message )
if ( Message [ 0 ] )
2017-05-11 23:45:46 +02:00
Ale_ShowAlert ( AlertType , Message ) ;
2017-04-18 09:55:25 +02:00
2017-06-12 14:16:33 +02:00
/***** Start box *****/
2018-10-18 02:02:32 +02:00
snprintf ( FrameTitle , sizeof ( FrameTitle ) ,
" %s: %s " ,
Txt_Thread , Thr . Subject ) ;
2017-06-10 21:38:10 +02:00
Box_StartBox ( NULL , FrameTitle , For_PutIconNewPost ,
2017-06-12 15:03:29 +02:00
Hlp_SOCIAL_Forums_posts , Box_NOT_CLOSABLE ) ;
2017-04-11 19:05:15 +02:00
2014-12-01 23:55:08 +01:00
/***** Get posts of a thread from database *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " SELECT PstCod,UNIX_TIMESTAMP(CreatTime) "
" FROM forum_post "
" WHERE ThrCod=%ld ORDER BY PstCod " ,
Gbl . Forum . ForumSelected . ThrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
NumRows = DB_QuerySELECT_free ( Query , & mysql_res , " can not get posts of a thread " ) ;
2014-12-01 23:55:08 +01:00
NumPsts = ( unsigned ) NumRows ;
LastSubject [ 0 ] = ' \0 ' ;
if ( NumPsts ) // If there are posts...
{
/***** Check if I can moderate posts in forum *****/
2017-04-18 01:25:44 +02:00
switch ( Gbl . Forum . ForumSelected . Type )
2014-12-01 23:55:08 +01:00
{
2017-04-17 11:57:55 +02:00
case For_FORUM_GLOBAL_USRS :
case For_FORUM_GLOBAL_TCHS :
2017-04-18 19:55:56 +02:00
case For_FORUM__SWAD__USRS :
case For_FORUM__SWAD__TCHS :
2017-06-04 18:18:54 +02:00
ICanModerateForum = ( Gbl . Usrs . Me . Role . Logged = = Rol_SYS_ADM ) ;
2014-12-01 23:55:08 +01:00
break ;
2017-04-17 11:57:55 +02:00
case For_FORUM_INSTIT_USRS :
case For_FORUM_INSTIT_TCHS :
2017-06-04 18:18:54 +02:00
ICanModerateForum = ( Gbl . Usrs . Me . Role . Logged > = Rol_INS_ADM ) ;
2017-04-18 19:55:56 +02:00
break ;
case For_FORUM_CENTRE_USRS :
case For_FORUM_CENTRE_TCHS :
2017-06-04 18:18:54 +02:00
ICanModerateForum = ( Gbl . Usrs . Me . Role . Logged > = Rol_CTR_ADM ) ;
2014-12-01 23:55:08 +01:00
break ;
2017-04-17 11:57:55 +02:00
case For_FORUM_DEGREE_USRS :
case For_FORUM_DEGREE_TCHS :
case For_FORUM_COURSE_TCHS :
2017-06-04 18:18:54 +02:00
ICanModerateForum = ( Gbl . Usrs . Me . Role . Logged > = Rol_DEG_ADM ) ;
2014-12-01 23:55:08 +01:00
break ;
case For_FORUM_COURSE_USRS :
2017-06-04 18:18:54 +02:00
ICanModerateForum = ( Gbl . Usrs . Me . Role . Logged > = Rol_TCH ) ;
2017-04-18 19:55:56 +02:00
break ;
default :
ICanModerateForum = false ;
2014-12-01 23:55:08 +01:00
break ;
}
/***** Compute variables related to pagination *****/
2017-04-13 20:09:22 +02:00
PaginationPsts . NumItems = NumPsts ;
PaginationPsts . CurrentPage = ( int ) Gbl . Forum . CurrentPagePsts ;
Pag_CalculatePagination ( & PaginationPsts ) ;
2017-05-25 13:43:54 +02:00
PaginationPsts . Anchor = For_FORUM_POSTS_SECTION_ID ;
2017-04-13 20:09:22 +02:00
Gbl . Forum . CurrentPagePsts = ( unsigned ) PaginationPsts . CurrentPage ;
2014-12-01 23:55:08 +01:00
/***** Write links to pages *****/
2017-04-13 20:09:22 +02:00
if ( PaginationPsts . MoreThanOnePage )
2017-04-17 11:57:55 +02:00
Pag_WriteLinksToPagesCentered ( Pag_POSTS_FORUM ,
2017-04-18 01:25:44 +02:00
Gbl . Forum . ForumSelected . ThrCod ,
2017-04-17 11:57:55 +02:00
& PaginationPsts ) ;
2014-12-01 23:55:08 +01:00
2017-04-11 19:05:15 +02:00
/***** Start table *****/
2017-06-11 20:09:59 +02:00
Tbl_StartTableWide ( 2 ) ;
2014-12-01 23:55:08 +01:00
2017-04-11 19:05:15 +02:00
/***** Show posts from this page, the author and the date of last reply *****/
2017-04-13 20:09:22 +02:00
mysql_data_seek ( mysql_res , ( my_ulonglong ) ( PaginationPsts . FirstItemVisible - 1 ) ) ;
for ( NumRow = PaginationPsts . FirstItemVisible ;
NumRow < = PaginationPsts . LastItemVisible ;
2014-12-01 23:55:08 +01:00
NumRow + + )
{
row = mysql_fetch_row ( mysql_res ) ;
if ( sscanf ( row [ 0 ] , " %ld " , & PstCod ) ! = 1 )
Lay_ShowErrorAndExit ( " Wrong code of post. " ) ;
2015-10-24 20:12:03 +02:00
CreatTimeUTC = Dat_GetUNIXTimeFromStr ( row [ 1 ] ) ;
2014-12-01 23:55:08 +01:00
NumPst = ( unsigned ) NumRow ;
2015-10-24 20:12:03 +02:00
NewPst = ( CreatTimeUTC > ReadTimeUTC ) ;
2014-12-01 23:55:08 +01:00
2017-04-13 20:09:22 +02:00
if ( NewPst & & NumRow = = PaginationPsts . LastItemVisible )
2014-12-01 23:55:08 +01:00
/* 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
2017-04-19 12:34:38 +02:00
( even if any previous pages have been no read actually ) .
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 ,
CreatTimeUTC ) ;
2014-12-01 23:55:08 +01:00
/* Show post */
2017-04-19 12:34:38 +02:00
For_ShowAForumPost ( NumPst , PstCod ,
2015-10-24 20:12:03 +02:00
( NumRow = = NumRows ) , LastSubject ,
NewPst , ICanModerateForum ) ;
2014-12-01 23:55:08 +01:00
/* Mark possible notification as seen */
2017-04-18 01:25:44 +02:00
switch ( Gbl . Forum . ForumSelected . Type )
2014-12-01 23:55:08 +01:00
{
case For_FORUM_COURSE_TCHS :
case For_FORUM_COURSE_USRS :
2016-01-04 01:56:28 +01:00
Ntf_MarkNotifAsSeen ( Ntf_EVENT_FORUM_POST_COURSE ,
2016-01-20 21:18:38 +01:00
PstCod , Gbl . CurrentCrs . Crs . CrsCod ,
Gbl . Usrs . Me . UsrDat . UsrCod ) ;
2014-12-01 23:55:08 +01:00
break ;
default :
break ;
}
if ( Thr . NumMyPosts )
2016-01-04 01:56:28 +01:00
Ntf_MarkNotifAsSeen ( Ntf_EVENT_FORUM_REPLY ,
2016-01-20 21:18:38 +01:00
PstCod , - 1L ,
Gbl . Usrs . Me . UsrDat . UsrCod ) ;
2014-12-01 23:55:08 +01:00
}
2017-04-11 19:05:15 +02:00
/***** End table *****/
2017-06-11 20:09:59 +02:00
Tbl_EndTable ( ) ;
2014-12-01 23:55:08 +01:00
/***** Write again links to pages *****/
2017-04-13 20:09:22 +02:00
if ( PaginationPsts . MoreThanOnePage )
2017-04-17 11:57:55 +02:00
Pag_WriteLinksToPagesCentered ( Pag_POSTS_FORUM ,
2017-04-18 01:25:44 +02:00
Gbl . Forum . ForumSelected . ThrCod ,
2017-04-17 11:57:55 +02:00
& PaginationPsts ) ;
2014-12-01 23:55:08 +01:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult ( & mysql_res ) ;
2017-04-11 19:05:15 +02:00
2017-04-17 12:19:58 +02:00
/***** Form to write a new post in the thread *****/
2017-05-25 13:43:54 +02:00
Lay_StartSection ( For_NEW_POST_SECTION_ID ) ;
2017-04-18 01:25:44 +02:00
For_WriteFormForumPst ( true , LastSubject ) ;
2017-05-25 13:43:54 +02:00
Lay_EndSection ( ) ;
2017-04-11 19:05:15 +02:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2017-06-10 21:38:10 +02:00
Box_EndBox ( ) ;
2017-05-25 13:43:54 +02:00
Lay_EndSection ( ) ;
2014-12-01 23:55:08 +01:00
}
2016-11-07 10:53:03 +01:00
/*****************************************************************************/
2017-04-17 12:19:58 +02:00
/*********************** Put icon to write a new post ************************/
2017-04-10 12:41:26 +02:00
/*****************************************************************************/
2017-04-17 12:19:58 +02:00
static void For_PutIconNewPost ( void )
2017-04-10 12:41:26 +02:00
{
2017-04-17 12:19:58 +02:00
extern const char * Txt_New_post ;
2017-04-10 12:41:26 +02:00
2017-04-18 01:25:44 +02:00
Lay_PutContextualLink ( For_ActionsSeePstFor [ Gbl . Forum . ForumSelected . Type ] ,
2017-05-25 13:43:54 +02:00
For_NEW_POST_SECTION_ID , For_PutAllHiddenParamsNewPost ,
2017-04-17 19:03:21 +02:00
" plus64x64.png " ,
Txt_New_post , NULL ,
NULL ) ;
2017-04-10 12:41:26 +02:00
}
2017-04-19 14:43:08 +02:00
static void For_PutAllHiddenParamsNewPost ( void )
{
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 ,
- 1L ) ;
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/**************************** Show a post from forum *************************/
/*****************************************************************************/
2017-04-19 12:34:38 +02:00
static void For_ShowAForumPost ( unsigned PstNum , long PstCod ,
2017-01-17 03:10:43 +01:00
bool LastPst , char LastSubject [ Cns_MAX_BYTES_SUBJECT + 1 ] ,
2015-10-24 20:12:03 +02:00
bool NewPst , bool ICanModerateForum )
2014-12-01 23:55:08 +01:00
{
2017-04-13 20:09:22 +02:00
extern const char * Txt_MSG_New ;
2015-07-21 20:20:59 +02:00
extern const char * Txt_MSG_Open ;
2014-12-01 23:55:08 +01:00
extern const char * Txt_no_subject ;
extern const char * Txt_Post_X_allowed ;
extern const char * Txt_Post_banned ;
extern const char * Txt_Post_X_banned ;
extern const char * Txt_Post_X_allowed_Click_to_ban_it ;
extern const char * Txt_Post_X_banned_Click_to_unban_it ;
extern const char * Txt_This_post_has_been_banned_probably_for_not_satisfy_the_rules_of_the_forums ;
struct UsrData UsrDat ;
2015-10-24 20:12:03 +02:00
time_t CreatTimeUTC ; // Creation time of a post
2017-01-17 03:10:43 +01:00
char OriginalContent [ Cns_MAX_BYTES_LONG_TEXT + 1 ] ;
char Subject [ Cns_MAX_BYTES_SUBJECT + 1 ] ;
char Content [ Cns_MAX_BYTES_LONG_TEXT + 1 ] ;
2016-04-10 19:19:20 +02:00
struct Image Image ;
2014-12-01 23:55:08 +01:00
bool Enabled ;
2018-10-10 23:56:42 +02:00
bool ItsMe ;
2014-12-01 23:55:08 +01:00
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor ( & UsrDat ) ;
2016-04-10 19:19:20 +02:00
/***** Initialize image *****/
Img_ImageConstructor ( & Image ) ;
2014-12-01 23:55:08 +01:00
/***** Check if post is enabled *****/
Enabled = For_GetIfPstIsEnabled ( PstCod ) ;
/***** Get data of post *****/
2016-04-10 19:19:20 +02:00
For_GetPstData ( PstCod , & UsrDat . UsrCod , & CreatTimeUTC ,
Subject , OriginalContent , & Image ) ;
2016-04-11 02:16:27 +02:00
2014-12-01 23:55:08 +01:00
if ( Enabled )
/* Return this subject as last subject */
2017-01-17 03:10:43 +01:00
Str_Copy ( LastSubject , Subject ,
Cns_MAX_BYTES_SUBJECT ) ;
2014-12-01 23:55:08 +01:00
/***** Put an icon with post status *****/
fprintf ( Gbl . F . Out , " <tr> "
2017-05-02 12:29:53 +02:00
" <td class= \" CONTEXT_COL %s \" > "
2014-12-01 23:55:08 +01:00
" <img src= \" %s/%s16x16.gif \" "
2015-09-05 12:04:30 +02:00
" alt= \" %s \" title= \" %s \" "
2016-11-14 10:05:41 +01:00
" class= \" ICO20x20 \" /> "
2014-12-01 23:55:08 +01:00
" </td> " ,
NewPst ? " MSG_TIT_BG_NEW " :
" MSG_TIT_BG " ,
Gbl . Prefs . IconsURL ,
NewPst ? " msg-unread " :
2015-07-21 20:20:59 +02:00
" msg-open " ,
2017-04-13 20:09:22 +02:00
NewPst ? Txt_MSG_New :
2015-07-21 20:20:59 +02:00
Txt_MSG_Open ,
2017-04-13 20:09:22 +02:00
NewPst ? Txt_MSG_New :
2015-07-21 20:20:59 +02:00
Txt_MSG_Open ) ;
2014-12-01 23:55:08 +01:00
/***** Write post number *****/
Msg_WriteMsgNumber ( ( unsigned long ) PstNum , NewPst ) ;
/***** Write date *****/
2015-10-24 20:12:03 +02:00
Msg_WriteMsgDate ( CreatTimeUTC , NewPst ? " MSG_TIT_BG_NEW " :
" MSG_TIT_BG " ) ;
2014-12-01 23:55:08 +01:00
/***** Write subject *****/
2015-08-01 10:43:33 +02:00
fprintf ( Gbl . F . Out , " <td class= \" %s LEFT_TOP \" > " ,
2014-12-01 23:55:08 +01:00
NewPst ? " MSG_TIT_BG_NEW " :
" MSG_TIT_BG " ) ;
if ( Enabled )
{
if ( Subject [ 0 ] )
fprintf ( Gbl . F . Out , " %s " , Subject ) ;
else
fprintf ( Gbl . F . Out , " [%s] " , Txt_no_subject ) ;
}
else
fprintf ( Gbl . F . Out , " [%s] " , Txt_Post_banned ) ;
fprintf ( Gbl . F . Out , " </td> "
" </tr> " ) ;
2017-04-18 16:44:44 +02:00
/***** Form to ban/unban post *****/
2014-12-01 23:55:08 +01:00
fprintf ( Gbl . F . Out , " <tr> "
2017-05-02 12:29:53 +02:00
" <td class= \" CONTEXT_COL \" > " ) ;
2017-04-18 16:44:44 +02:00
if ( ICanModerateForum )
{
2018-10-15 14:07:12 +02:00
Act_StartFormAnchor ( Enabled ? For_ActionsDisPstFor [ Gbl . Forum . ForumSelected . Type ] :
2017-04-19 12:34:38 +02:00
For_ActionsEnbPstFor [ Gbl . Forum . ForumSelected . Type ] ,
2017-05-25 13:43:54 +02:00
For_FORUM_POSTS_SECTION_ID ) ;
2017-04-18 16:44:44 +02:00
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 ,
PstCod ) ;
2018-10-18 02:02:32 +02:00
snprintf ( Gbl . Title , sizeof ( Gbl . Title ) ,
Enabled ? Txt_Post_X_allowed_Click_to_ban_it :
Txt_Post_X_banned_Click_to_unban_it ,
PstNum ) ;
2017-04-18 16:44:44 +02:00
fprintf ( Gbl . F . Out , " <input type= \" image \" src= \" %s/%s-on64x64.png \" "
" alt= \" %s \" title= \" %s \" "
" class= \" ICO20x20 \" /> " ,
Gbl . Prefs . IconsURL ,
Enabled ? " eye " :
" eye-slash " ,
Gbl . Title ,
Gbl . Title ) ;
2018-10-15 14:07:12 +02:00
Act_EndForm ( ) ;
2017-04-18 16:44:44 +02:00
}
else
{
2018-10-18 02:02:32 +02:00
snprintf ( Gbl . Title , sizeof ( Gbl . Title ) ,
Enabled ? Txt_Post_X_allowed :
Txt_Post_X_banned ,
PstNum ) ;
2017-04-18 16:44:44 +02:00
fprintf ( Gbl . F . Out , " <span title= \" %s \" > "
" <img src= \" %s/%s-off64x64.png \" "
" alt= \" %s \" title= \" %s \" "
" class= \" ICO20x20 \" /> "
" </span> " ,
Gbl . Title ,
Gbl . Prefs . IconsURL ,
Enabled ? " eye " :
" eye-slash " ,
Gbl . Title ,
Gbl . Title ) ;
}
/***** Form to remove post *****/
2018-10-10 23:56:42 +02:00
if ( LastPst )
2014-12-01 23:55:08 +01:00
{
2018-10-10 23:56:42 +02:00
ItsMe = Usr_ItsMe ( UsrDat . UsrCod ) ;
if ( ItsMe )
{
// Post can be removed if post is the last (without answers) and it's mine
if ( PstNum = = 1 ) // First and unique post in thread
2018-10-15 14:07:12 +02:00
Act_StartFormAnchor ( For_ActionsDelPstFor [ Gbl . Forum . ForumSelected . Type ] ,
2018-10-10 23:56:42 +02:00
For_FORUM_THREADS_SECTION_ID ) ;
else // Last of several posts in thread
2018-10-15 14:07:12 +02:00
Act_StartFormAnchor ( For_ActionsDelPstFor [ Gbl . Forum . ForumSelected . Type ] ,
2018-10-10 23:56:42 +02:00
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 ,
PstCod ) ;
Ico_PutIconRemove ( ) ;
2018-10-15 14:07:12 +02:00
Act_EndForm ( ) ;
2018-10-10 23:56:42 +02:00
}
2014-12-01 23:55:08 +01:00
}
2017-04-18 16:44:44 +02:00
fprintf ( Gbl . F . Out , " </td> " ) ;
2014-12-01 23:55:08 +01:00
2017-04-18 16:44:44 +02:00
/***** Write author *****/
2017-05-02 01:05:23 +02:00
Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod ( & UsrDat ) ;
fprintf ( Gbl . F . Out , " <td colspan= \" 2 \" class= \" AUTHOR_TXT LEFT_TOP \" "
2017-05-01 21:17:38 +02:00
" style= \" width:150px; \" > " ) ;
2017-05-02 01:16:06 +02:00
Msg_WriteMsgAuthor ( & UsrDat , Enabled , NULL ) ;
2014-12-01 23:55:08 +01:00
if ( Enabled )
/* Write number of posts from this user */
2017-04-19 12:34:38 +02:00
For_WriteNumberOfPosts ( UsrDat . UsrCod ) ;
2017-05-01 21:17:38 +02:00
fprintf ( Gbl . F . Out , " </td> " ) ;
2014-12-01 23:55:08 +01:00
/***** Write post content *****/
2017-04-18 16:44:44 +02:00
fprintf ( Gbl . F . Out , " <td class= \" MSG_TXT LEFT_TOP \" > " ) ;
2014-12-01 23:55:08 +01:00
if ( Enabled )
{
2017-01-17 03:10:43 +01:00
Str_Copy ( Content , OriginalContent ,
Cns_MAX_BYTES_LONG_TEXT ) ;
2014-12-01 23:55:08 +01:00
Msg_WriteMsgContent ( Content , Cns_MAX_BYTES_LONG_TEXT , true , false ) ;
2016-04-10 19:19:20 +02:00
/***** Show image *****/
2016-04-15 14:30:28 +02:00
Img_ShowImage ( & Image , " FOR_IMG_CONTAINER " , " FOR_IMG " ) ;
2014-12-01 23:55:08 +01:00
}
else
fprintf ( Gbl . F . Out , " %s " , Txt_This_post_has_been_banned_probably_for_not_satisfy_the_rules_of_the_forums ) ;
2016-04-12 22:28:15 +02:00
fprintf ( Gbl . F . Out , " </td> "
2014-12-01 23:55:08 +01:00
" </tr> " ) ;
2016-04-10 19:19:20 +02:00
/***** Free image *****/
Img_ImageDestructor ( & Image ) ;
2014-12-01 23:55:08 +01:00
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor ( & UsrDat ) ;
}
/*****************************************************************************/
/*************************** Get data of a forum post ************************/
/*****************************************************************************/
2015-10-24 20:12:03 +02:00
static void For_GetPstData ( long PstCod , long * UsrCod , time_t * CreatTimeUTC ,
2017-01-17 03:10:43 +01:00
char Subject [ Cns_MAX_BYTES_SUBJECT + 1 ] ,
char Content [ Cns_MAX_BYTES_LONG_TEXT + 1 ] ,
struct Image * Image )
2014-12-01 23:55:08 +01:00
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
MYSQL_RES * mysql_res ;
MYSQL_ROW row ;
unsigned NumRows ;
/***** Get data of a post from database *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " SELECT UsrCod,UNIX_TIMESTAMP(CreatTime), "
" Subject,Content,ImageName,ImageTitle,ImageURL "
" FROM forum_post WHERE PstCod=%ld " ,
PstCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
NumRows = DB_QuerySELECT_free ( Query , & mysql_res , " can not get data of a post " ) ;
2014-12-01 23:55:08 +01:00
/***** Result should have a unique row *****/
if ( NumRows ! = 1 )
Lay_ShowErrorAndExit ( " Internal error in database when getting data of a post. " ) ;
/***** Get number of rows *****/
row = mysql_fetch_row ( mysql_res ) ;
/****** Get author code (row[1]) *****/
* UsrCod = Str_ConvertStrCodToLongCod ( row [ 0 ] ) ;
/****** Get creation time (row[1]) *****/
2015-10-24 20:12:03 +02:00
* CreatTimeUTC = Dat_GetUNIXTimeFromStr ( row [ 1 ] ) ;
2014-12-01 23:55:08 +01:00
/****** Get subject (row[2]) *****/
2017-01-17 03:10:43 +01:00
Str_Copy ( Subject , row [ 2 ] ,
Cns_MAX_BYTES_SUBJECT ) ;
2014-12-01 23:55:08 +01:00
/****** Get location (row[3]) *****/
2017-01-17 03:10:43 +01:00
Str_Copy ( Content , row [ 3 ] ,
Cns_MAX_BYTES_LONG_TEXT ) ;
2016-04-10 19:19:20 +02:00
2016-04-15 02:33:16 +02:00
/****** Get image name (row[4]), title (row[5]) and URL (row[6]) *****/
Img_GetImageNameTitleAndURLFromRow ( row [ 4 ] , row [ 5 ] , row [ 6 ] , Image ) ;
2014-12-01 23:55:08 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult ( & mysql_res ) ;
}
/*****************************************************************************/
2015-12-28 19:22:56 +01:00
/***************** Get summary and content for a forum post ******************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
// This function may be called inside a web service, so don't report error
2017-03-08 14:12:33 +01:00
void For_GetSummaryAndContentForumPst ( char SummaryStr [ Ntf_MAX_BYTES_SUMMARY + 1 ] ,
2017-01-13 10:49:56 +01:00
char * * ContentStr ,
2017-03-06 13:01:16 +01:00
long PstCod , bool GetContent )
2014-12-01 23:55:08 +01:00
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
MYSQL_RES * mysql_res ;
MYSQL_ROW row ;
2017-01-13 10:49:56 +01:00
size_t Length ;
2014-12-01 23:55:08 +01:00
SummaryStr [ 0 ] = ' \0 ' ; // Return nothing on error
/***** Get subject of message from database *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " SELECT Subject,Content FROM forum_post "
" WHERE PstCod=%ld " , PstCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
2014-12-01 23:55:08 +01:00
if ( ! mysql_query ( & Gbl . mysql , Query ) )
if ( ( mysql_res = mysql_store_result ( & Gbl . mysql ) ) ! = NULL )
{
/***** Result should have a unique row *****/
if ( mysql_num_rows ( mysql_res ) = = 1 )
{
/***** Get subject and content of the message *****/
row = mysql_fetch_row ( mysql_res ) ;
/***** Copy subject *****/
2017-03-06 13:01:16 +01:00
// TODO: Do only direct copy when Subject will be VARCHAR(255)
2017-03-08 14:12:33 +01:00
if ( strlen ( row [ 0 ] ) > Ntf_MAX_BYTES_SUMMARY )
2017-03-06 13:01:16 +01:00
{
strncpy ( SummaryStr , row [ 0 ] ,
2017-03-08 14:12:33 +01:00
Ntf_MAX_BYTES_SUMMARY ) ;
SummaryStr [ Ntf_MAX_BYTES_SUMMARY ] = ' \0 ' ;
2017-03-06 13:01:16 +01:00
}
else
Str_Copy ( SummaryStr , row [ 0 ] ,
2017-03-08 14:12:33 +01:00
Ntf_MAX_BYTES_SUMMARY ) ;
2014-12-01 23:55:08 +01:00
/***** Copy content *****/
if ( GetContent )
{
2017-01-13 10:49:56 +01:00
Length = strlen ( row [ 1 ] ) ;
if ( ( * ContentStr = ( char * ) malloc ( Length + 1 ) ) = = NULL )
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ( " Error allocating memory for notification content. " ) ;
2017-01-13 10:49:56 +01:00
2017-01-17 03:10:43 +01:00
if ( Length )
Str_Copy ( * ContentStr , row [ 1 ] ,
Length ) ;
else
* * ContentStr = ' \0 ' ;
2014-12-01 23:55:08 +01:00
}
}
mysql_free_result ( mysql_res ) ;
}
}
/*****************************************************************************/
/*************** Write number of posts in a forum of an user *****************/
/*****************************************************************************/
2017-04-19 12:34:38 +02:00
static void For_WriteNumberOfPosts ( long UsrCod )
2014-12-01 23:55:08 +01:00
{
extern const char * Txt_post ;
extern const char * Txt_posts ;
char SubQuery [ 256 ] ;
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
unsigned NumPsts ;
/***** Star table cell *****/
2017-05-02 01:05:23 +02:00
fprintf ( Gbl . F . Out , " <div class= \" AUTHOR_TXT LEFT_TOP \" > " ) ;
2014-12-01 23:55:08 +01:00
/***** Get number of posts from database *****/
2017-04-19 12:34:38 +02:00
if ( Gbl . Forum . ForumSelected . Location > 0 )
sprintf ( SubQuery , " AND forum_thread.Location=%ld " ,
Gbl . Forum . ForumSelected . Location ) ;
2017-04-16 23:48:05 +02:00
else
SubQuery [ 0 ] = ' \0 ' ;
2018-10-22 00:31:44 +02:00
if ( asprintf ( & 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 ) Gbl . Forum . ForumSelected . Type , SubQuery ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
NumPsts = ( unsigned ) DB_QueryCOUNT_free ( Query , " can not get the number of posts of a user in a forum " ) ;
2014-12-01 23:55:08 +01:00
/***** Write number of threads and number of posts *****/
if ( NumPsts = = 1 )
fprintf ( Gbl . F . Out , " [1 %s] " , Txt_post ) ;
else
fprintf ( Gbl . F . Out , " [%u %s] " , NumPsts , Txt_posts ) ;
/***** End table cell *****/
2017-05-02 01:05:23 +02:00
fprintf ( Gbl . F . Out , " </div> " ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2014-12-28 17:22:27 +01:00
/************ Put all the hidden parameters related to forums ****************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2017-04-18 16:44:44 +02:00
void For_PutAllHiddenParamsForum ( unsigned NumPageThreads ,
unsigned NumPagePosts ,
For_ForumSet_t ForumSet ,
2017-04-18 01:25:44 +02:00
For_Order_t Order ,
long Location ,
long ThrCod ,
long PstCod )
{
2017-04-18 16:44:44 +02:00
Pag_PutHiddenParamPagNum ( Pag_THREADS_FORUM , NumPageThreads ) ;
Pag_PutHiddenParamPagNum ( Pag_POSTS_FORUM , NumPagePosts ) ;
2017-04-18 01:25:44 +02:00
For_PutParamForumSet ( ForumSet ) ;
For_PutParamForumOrder ( Order ) ;
For_PutParamForumLocation ( Location ) ;
For_PutHiddenParamThrCod ( ThrCod ) ;
For_PutHiddenParamPstCod ( PstCod ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2017-04-17 19:03:21 +02:00
/********* Put a hidden parameter with set of forums I want to see ***********/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2017-04-18 01:25:44 +02:00
static void For_PutParamForumSet ( For_ForumSet_t ForumSet )
2014-12-01 23:55:08 +01:00
{
2017-04-18 01:25:44 +02:00
Par_PutHiddenParamUnsigned ( " ForumSet " , ( unsigned ) ForumSet ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2014-12-28 17:22:27 +01:00
/******** Put a hidden parameter with the order criterium for forums *********/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2017-04-18 01:25:44 +02:00
static void For_PutParamForumOrder ( For_Order_t Order )
2014-12-01 23:55:08 +01:00
{
2017-04-18 01:25:44 +02:00
Par_PutHiddenParamUnsigned ( " Order " , ( unsigned ) Order ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2017-04-16 23:48:05 +02:00
/************** Put hidden parameter with code of *****************/
2014-12-28 17:22:27 +01:00
/************** forum institution, centre, degree and course *****************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2017-04-18 01:25:44 +02:00
static void For_PutParamForumLocation ( long Location )
2014-12-01 23:55:08 +01:00
{
2017-04-18 01:25:44 +02:00
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 ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************** Show list of available forums ********************/
/*****************************************************************************/
2017-04-16 13:45:11 +02:00
static void For_ShowForumList ( void )
2014-12-01 23:55:08 +01:00
{
2016-11-13 21:33:15 +01:00
extern const char * Hlp_SOCIAL_Forums ;
2014-12-01 23:55:08 +01:00
extern const char * Txt_Forums ;
2017-01-28 15:58:46 +01:00
bool IsLastItemInLevel [ 1 + For_FORUM_MAX_LEVELS ] ;
2014-12-01 23:55:08 +01:00
MYSQL_RES * mysql_resCtr ;
MYSQL_RES * mysql_resDeg ;
MYSQL_RES * mysql_resCrs ;
MYSQL_ROW row ;
2017-04-16 23:48:05 +02:00
long InsCod ;
long CtrCod ;
long DegCod ;
long CrsCod ;
unsigned NumMyIns ;
unsigned NumCtr ;
unsigned NumCtrs ;
unsigned NumDeg ;
unsigned NumDegs ;
unsigned NumCrs ;
unsigned NumCrss ;
2014-12-01 23:55:08 +01:00
bool ICanSeeInsForum ;
bool ICanSeeCtrForum ;
bool ICanSeeDegForum ;
/***** Get if there is a thread ready to be moved *****/
2017-04-18 13:17:40 +02:00
if ( For_CheckIfICanMoveThreads ( ) )
2014-12-01 23:55:08 +01:00
Gbl . Forum . ThreadToMove = For_GetThrInMyClipboard ( ) ;
/***** Fill the list with the institutions I belong to *****/
2016-10-28 10:03:37 +02:00
Usr_GetMyInstits ( ) ;
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** Start box *****/
2017-06-10 21:38:10 +02:00
Box_StartBox ( NULL , Txt_Forums , For_PutIconsForums ,
2017-06-12 15:03:29 +02:00
Hlp_SOCIAL_Forums , Box_NOT_CLOSABLE ) ;
2014-12-01 23:55:08 +01:00
/***** Put a form to select which forums *****/
For_PutFormWhichForums ( ) ;
2017-04-13 23:53:57 +02:00
/***** Start list *****/
2016-12-19 00:55:24 +01:00
fprintf ( Gbl . F . Out , " <ul class= \" LIST_LEFT \" > " ) ;
2014-12-01 23:55:08 +01:00
/***** Links to global forums *****/
For_WriteLinksToGblForums ( IsLastItemInLevel ) ;
2017-04-17 11:57:55 +02:00
switch ( Gbl . Forum . ForumSet )
2014-12-01 23:55:08 +01:00
{
case For_ONLY_CURRENT_FORUMS :
2016-06-12 14:03:33 +02:00
if ( Gbl . CurrentIns . Ins . InsCod > 0 )
{
2017-06-04 18:18:54 +02:00
if ( Gbl . Usrs . Me . Role . Logged > = Rol_DEG_ADM )
2016-06-12 14:03:33 +02:00
ICanSeeInsForum = true ;
else
ICanSeeInsForum = Usr_CheckIfIBelongToIns ( Gbl . CurrentIns . Ins . InsCod ) ;
}
2014-12-01 23:55:08 +01:00
else
2016-06-12 14:03:33 +02:00
ICanSeeInsForum = false ;
2014-12-01 23:55:08 +01:00
/***** Links to forums about the platform *****/
For_WriteLinksToPlatformForums ( ! ICanSeeInsForum , IsLastItemInLevel ) ;
if ( ICanSeeInsForum )
{
2017-06-04 18:18:54 +02:00
if ( Gbl . Usrs . Me . Role . Logged > = Rol_DEG_ADM )
2014-12-01 23:55:08 +01:00
ICanSeeCtrForum = true ;
else
ICanSeeCtrForum = Usr_CheckIfIBelongToCtr ( Gbl . CurrentCtr . Ctr . CtrCod ) ;
/***** Links to forums of current institution *****/
2017-04-16 23:48:05 +02:00
if ( For_WriteLinksToInsForums ( Gbl . CurrentIns . Ins . InsCod ,
true ,
IsLastItemInLevel ) > 0 )
2014-12-01 23:55:08 +01:00
if ( ICanSeeCtrForum )
{
2017-06-04 18:18:54 +02:00
if ( Gbl . Usrs . Me . Role . Logged > = Rol_DEG_ADM )
2014-12-01 23:55:08 +01:00
ICanSeeDegForum = true ;
else
ICanSeeDegForum = Usr_CheckIfIBelongToDeg ( Gbl . CurrentDeg . Deg . DegCod ) ;
/***** Links to forums of current centre *****/
2017-04-16 23:48:05 +02:00
if ( For_WriteLinksToCtrForums ( Gbl . CurrentCtr . Ctr . CtrCod ,
true ,
IsLastItemInLevel ) > 0 )
2014-12-01 23:55:08 +01:00
if ( ICanSeeDegForum )
/***** Links to forums of current degree *****/
2017-04-16 23:48:05 +02:00
if ( For_WriteLinksToDegForums ( Gbl . CurrentDeg . Deg . DegCod ,
true ,
IsLastItemInLevel ) > 0 )
2015-01-20 20:03:38 +01:00
if ( Gbl . Usrs . Me . IBelongToCurrentCrs | |
2017-06-04 18:18:54 +02:00
Gbl . Usrs . Me . Role . Logged = = Rol_SYS_ADM )
2014-12-01 23:55:08 +01:00
/***** Links to forums of current degree *****/
2017-04-16 23:48:05 +02:00
For_WriteLinksToCrsForums ( Gbl . CurrentCrs . Crs . CrsCod ,
true ,
IsLastItemInLevel ) ;
2014-12-01 23:55:08 +01:00
}
}
break ;
case For_ALL_MY_FORUMS :
/***** Links to forums about the platform *****/
2016-10-28 10:03:37 +02:00
For_WriteLinksToPlatformForums ( ( Gbl . Usrs . Me . MyInss . Num = = 0 ) , IsLastItemInLevel ) ;
2014-12-01 23:55:08 +01:00
/***** Links to forums of users from my institutions, the degrees in each institution and the courses in each degree *****/
for ( NumMyIns = 0 ;
2016-10-28 10:03:37 +02:00
NumMyIns < Gbl . Usrs . Me . MyInss . Num ;
2014-12-01 23:55:08 +01:00
NumMyIns + + )
{
2017-04-16 23:48:05 +02:00
InsCod = Gbl . Usrs . Me . MyInss . Inss [ NumMyIns ] . InsCod ;
2014-12-01 23:55:08 +01:00
/* Links to forums of this institution */
2017-04-16 23:48:05 +02:00
For_WriteLinksToInsForums ( InsCod ,
( NumMyIns = = Gbl . Usrs . Me . MyInss . Num - 1 ) ,
IsLastItemInLevel ) ;
2014-12-01 23:55:08 +01:00
/* Get my centres in this institution from database */
2017-04-16 23:48:05 +02:00
if ( ( NumCtrs = Usr_GetCtrsFromUsr ( Gbl . Usrs . Me . UsrDat . UsrCod ,
InsCod ,
& mysql_resCtr ) ) > 0 ) // Centres found in this institution
2014-12-01 23:55:08 +01:00
for ( NumCtr = 0 ;
NumCtr < NumCtrs ;
NumCtr + + )
{
/* Get next centre */
row = mysql_fetch_row ( mysql_resCtr ) ;
2017-04-16 23:48:05 +02:00
CtrCod = Str_ConvertStrCodToLongCod ( row [ 0 ] ) ;
2014-12-01 23:55:08 +01:00
/* Links to forums of this centre */
2017-04-16 23:48:05 +02:00
if ( For_WriteLinksToCtrForums ( CtrCod ,
( NumCtr = = NumCtrs - 1 ) ,
IsLastItemInLevel ) > 0 )
2014-12-01 23:55:08 +01:00
{
/* Get my degrees in this institution from database */
2017-04-16 23:48:05 +02:00
if ( ( NumDegs = Usr_GetDegsFromUsr ( Gbl . Usrs . Me . UsrDat . UsrCod ,
CtrCod ,
& mysql_resDeg ) ) > 0 ) // Degrees found in this centre
2014-12-01 23:55:08 +01:00
for ( NumDeg = 0 ;
NumDeg < NumDegs ;
NumDeg + + )
{
/* Get next degree */
row = mysql_fetch_row ( mysql_resDeg ) ;
2017-04-16 23:48:05 +02:00
DegCod = Str_ConvertStrCodToLongCod ( row [ 0 ] ) ;
2014-12-01 23:55:08 +01:00
/* Links to forums of this degree */
2017-04-16 23:48:05 +02:00
if ( For_WriteLinksToDegForums ( DegCod ,
( NumDeg = = NumDegs - 1 ) ,
IsLastItemInLevel ) > 0 )
2014-12-01 23:55:08 +01:00
{
/* Get my courses in this degree from database */
2017-04-16 23:48:05 +02:00
if ( ( NumCrss = Usr_GetCrssFromUsr ( Gbl . Usrs . Me . UsrDat . UsrCod ,
DegCod ,
& mysql_resCrs ) ) > 0 ) // Courses found in this degree
2014-12-01 23:55:08 +01:00
for ( NumCrs = 0 ;
NumCrs < NumCrss ;
NumCrs + + )
{
/* Get next course */
row = mysql_fetch_row ( mysql_resCrs ) ;
2017-04-16 23:48:05 +02:00
CrsCod = Str_ConvertStrCodToLongCod ( row [ 0 ] ) ;
2014-12-01 23:55:08 +01:00
/* Links to forums of this course */
2017-04-16 23:48:05 +02:00
For_WriteLinksToCrsForums ( CrsCod ,
( NumCrs = = NumCrss - 1 ) ,
IsLastItemInLevel ) ;
2014-12-01 23:55:08 +01:00
}
/* Free structure that stores the query result */
DB_FreeMySQLResult ( & mysql_resCrs ) ;
}
}
/* Free structure that stores the query result */
DB_FreeMySQLResult ( & mysql_resDeg ) ;
}
}
/* Free structure that stores the query result */
DB_FreeMySQLResult ( & mysql_resCtr ) ;
}
break ;
default :
break ;
}
2017-04-13 23:53:57 +02:00
/***** End list *****/
2016-12-19 00:55:24 +01:00
fprintf ( Gbl . F . Out , " </ul> " ) ;
2017-04-13 23:53:57 +02:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2017-06-10 21:38:10 +02:00
Box_EndBox ( ) ;
2014-12-01 23:55:08 +01:00
}
2017-04-17 12:19:58 +02:00
/*****************************************************************************/
/********************** Put contextual icons in forums ***********************/
/*****************************************************************************/
static void For_PutIconsForums ( void )
{
/***** Put icon to show a figure *****/
Gbl . Stat . FigureType = Sta_FORUMS ;
Sta_PutIconToShowFigure ( ) ;
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2017-02-24 00:42:20 +01:00
/*************** Put form to select which forums I want to see ***************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
static void For_PutFormWhichForums ( void )
{
2017-04-17 19:03:21 +02:00
extern const char * Txt_FORUM_WHICH_FORUM [ For_NUM_FORUM_SETS ] ;
2017-04-17 11:57:55 +02:00
For_ForumSet_t ForumSet ;
2014-12-01 23:55:08 +01:00
2017-02-24 00:42:20 +01:00
/***** Form to select which forums I want to see:
- all my forums
- only the forums of current institution / degree / course * * * * */
2018-10-15 14:07:12 +02:00
Act_StartForm ( ActSeeFor ) ;
2017-04-18 13:17:40 +02:00
For_PutParamForumOrder ( Gbl . Forum . ThreadsOrder ) ;
2017-02-24 00:42:20 +01:00
fprintf ( Gbl . F . Out , " <div class= \" SEL_BELOW_TITLE \" > "
" <ul> " ) ;
2014-12-27 21:09:34 +01:00
2017-04-17 11:57:55 +02:00
for ( ForumSet = ( For_ForumSet_t ) 0 ;
2017-04-17 19:03:21 +02:00
ForumSet < For_NUM_FORUM_SETS ;
2017-04-17 11:57:55 +02:00
ForumSet + + )
2014-12-01 23:55:08 +01:00
{
2017-02-24 00:42:20 +01:00
fprintf ( Gbl . F . Out , " <li> "
" <label> "
2017-04-17 19:03:21 +02:00
" <input type= \" radio \" name= \" ForumSet \" "
2017-02-24 00:42:20 +01:00
" value= \" %u \" " ,
2017-04-17 11:57:55 +02:00
( unsigned ) ForumSet ) ;
if ( ForumSet = = Gbl . Forum . ForumSet )
2014-12-01 23:55:08 +01:00
fprintf ( Gbl . F . Out , " checked= \" checked \" " ) ;
2015-10-22 14:49:48 +02:00
fprintf ( Gbl . F . Out , " onclick= \" document.getElementById('%s').submit(); \" /> "
2014-12-27 21:09:34 +01:00
" %s "
2016-12-23 20:58:10 +01:00
" </label> "
2014-12-27 21:09:34 +01:00
" </li> " ,
2017-04-17 11:57:55 +02:00
Gbl . Form . Id , Txt_FORUM_WHICH_FORUM [ ForumSet ] ) ;
2014-12-01 23:55:08 +01:00
}
2015-07-24 13:51:29 +02:00
fprintf ( Gbl . F . Out , " </ul> "
" </div> " ) ;
2018-10-15 14:07:12 +02:00
Act_EndForm ( ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************* Write links to global forums **********************/
/*****************************************************************************/
2017-01-28 15:58:46 +01:00
static void For_WriteLinksToGblForums ( bool IsLastItemInLevel [ 1 + For_FORUM_MAX_LEVELS ] )
2014-12-01 23:55:08 +01:00
{
2017-04-11 13:53:17 +02:00
bool Highlight ;
2017-05-23 20:42:38 +02:00
bool ICanSeeTeacherForum ;
2017-04-19 12:34:38 +02:00
struct Forum Forum ;
2017-04-11 13:53:17 +02:00
2017-05-23 20:42:38 +02:00
/***** Can I see teachers's forums? *****/
Rol_GetRolesInAllCrssIfNotYetGot ( & Gbl . Usrs . Me . UsrDat ) ;
2017-06-04 18:18:54 +02:00
ICanSeeTeacherForum = Gbl . Usrs . Me . Role . Logged = = Rol_SYS_ADM | |
2017-06-08 15:32:33 +02:00
( Gbl . Usrs . Me . UsrDat . Roles . InCrss & ( ( 1 < < Rol_NET ) |
2017-05-23 20:42:38 +02:00
( 1 < < Rol_TCH ) ) ) ;
2014-12-01 23:55:08 +01:00
/***** Link to forum global *****/
2017-04-19 12:34:38 +02:00
Forum . Type = For_FORUM_GLOBAL_USRS ;
Forum . Location = - 1L ;
2017-04-18 01:25:44 +02:00
Highlight = ( Gbl . Forum . ForumSelected . Type = = For_FORUM_GLOBAL_USRS ) ;
2014-12-01 23:55:08 +01:00
IsLastItemInLevel [ 1 ] = false ;
2017-04-19 12:34:38 +02:00
For_WriteLinkToForum ( & Forum , Highlight , false , 0 , IsLastItemInLevel ) ;
2014-12-01 23:55:08 +01:00
/***** Link to forum of teachers global *****/
2016-12-13 13:32:19 +01:00
Rol_GetRolesInAllCrssIfNotYetGot ( & Gbl . Usrs . Me . UsrDat ) ;
2017-05-23 20:42:38 +02:00
if ( ICanSeeTeacherForum )
2014-12-01 23:55:08 +01:00
{
2017-04-19 12:34:38 +02:00
Forum . Type = For_FORUM_GLOBAL_TCHS ;
Forum . Location = - 1L ;
2017-04-18 01:25:44 +02:00
Highlight = ( Gbl . Forum . ForumSelected . Type = = For_FORUM_GLOBAL_TCHS ) ;
2014-12-01 23:55:08 +01:00
IsLastItemInLevel [ 1 ] = false ;
2017-04-19 12:34:38 +02:00
For_WriteLinkToForum ( & Forum , Highlight , false , 0 , IsLastItemInLevel ) ;
2014-12-01 23:55:08 +01:00
}
}
/*****************************************************************************/
/****************** Write links to forums about the platform *****************/
/*****************************************************************************/
2016-12-13 13:32:19 +01:00
static void For_WriteLinksToPlatformForums ( bool IsLastForum ,
2017-01-28 15:58:46 +01:00
bool IsLastItemInLevel [ 1 + For_FORUM_MAX_LEVELS ] )
2014-12-01 23:55:08 +01:00
{
2017-04-11 13:53:17 +02:00
bool Highlight ;
2016-12-13 13:32:19 +01:00
bool ICanSeeTeacherForum ;
2017-04-19 12:34:38 +02:00
struct Forum Forum ;
2016-12-13 13:32:19 +01:00
/***** Can I see teachers's forums? *****/
Rol_GetRolesInAllCrssIfNotYetGot ( & Gbl . Usrs . Me . UsrDat ) ;
2017-06-04 18:18:54 +02:00
ICanSeeTeacherForum = Gbl . Usrs . Me . Role . Logged = = Rol_SYS_ADM | |
2017-06-08 15:32:33 +02:00
( Gbl . Usrs . Me . UsrDat . Roles . InCrss & ( ( 1 < < Rol_NET ) |
2017-05-23 20:42:38 +02:00
( 1 < < Rol_TCH ) ) ) ;
2014-12-01 23:55:08 +01:00
/***** Link to forum of users about the platform *****/
2017-04-19 12:34:38 +02:00
Forum . Type = For_FORUM__SWAD__USRS ;
Forum . Location = - 1L ;
2017-04-18 19:55:56 +02:00
Highlight = ( Gbl . Forum . ForumSelected . Type = = For_FORUM__SWAD__USRS ) ;
2014-12-01 23:55:08 +01:00
IsLastItemInLevel [ 1 ] = ( IsLastForum & & ! ICanSeeTeacherForum ) ;
2017-04-19 12:34:38 +02:00
For_WriteLinkToForum ( & Forum , Highlight , false , 0 , IsLastItemInLevel ) ;
2014-12-01 23:55:08 +01:00
/***** Link to forum of teachers about the platform *****/
if ( ICanSeeTeacherForum )
{
2017-04-19 12:34:38 +02:00
Forum . Type = For_FORUM__SWAD__TCHS ;
Forum . Location = - 1L ;
2017-04-18 19:55:56 +02:00
Highlight = ( Gbl . Forum . ForumSelected . Type = = For_FORUM__SWAD__TCHS ) ;
2014-12-01 23:55:08 +01:00
IsLastItemInLevel [ 1 ] = IsLastForum ;
2017-04-19 12:34:38 +02:00
For_WriteLinkToForum ( & Forum , Highlight , false , 0 , IsLastItemInLevel ) ;
2014-12-01 23:55:08 +01:00
}
}
/*****************************************************************************/
/********************** Write links to institution forums ********************/
/*****************************************************************************/
// Returns institution code
2017-01-28 15:58:46 +01:00
static long For_WriteLinksToInsForums ( long InsCod , bool IsLastIns ,
bool IsLastItemInLevel [ 1 + For_FORUM_MAX_LEVELS ] )
2014-12-01 23:55:08 +01:00
{
2017-04-11 13:53:17 +02:00
bool Highlight ;
2017-05-23 20:42:38 +02:00
Rol_Role_t MaxRoleInIns ;
2014-12-01 23:55:08 +01:00
bool ICanSeeTeacherForum ;
2017-04-19 12:34:38 +02:00
struct Forum Forum ;
2014-12-01 23:55:08 +01:00
if ( InsCod > 0 )
{
2017-05-23 20:42:38 +02:00
MaxRoleInIns = Rol_GetMyMaxRoleInIns ( InsCod ) ;
2017-06-04 18:18:54 +02:00
ICanSeeTeacherForum = ( Gbl . Usrs . Me . Role . Logged = = Rol_SYS_ADM | |
2017-05-23 20:42:38 +02:00
MaxRoleInIns = = Rol_NET | |
MaxRoleInIns = = Rol_TCH ) ;
2014-12-01 23:55:08 +01:00
/***** Link to the forum of users from this institution *****/
2017-04-19 12:34:38 +02:00
Forum . Type = For_FORUM_INSTIT_USRS ;
Forum . Location = InsCod ;
2017-04-18 01:25:44 +02:00
Highlight = ( Gbl . Forum . ForumSelected . Type = = For_FORUM_INSTIT_USRS & &
Gbl . Forum . ForumSelected . Location = = InsCod ) ;
2014-12-01 23:55:08 +01:00
IsLastItemInLevel [ 1 ] = ( IsLastIns & & ! ICanSeeTeacherForum ) ;
2017-04-19 12:34:38 +02:00
For_WriteLinkToForum ( & Forum , Highlight , false , 1 , IsLastItemInLevel ) ;
2014-12-01 23:55:08 +01:00
/***** Link to forum of teachers from this institution *****/
if ( ICanSeeTeacherForum )
{
2017-04-19 12:34:38 +02:00
Forum . Type = For_FORUM_INSTIT_TCHS ;
Forum . Location = InsCod ;
2017-04-18 01:25:44 +02:00
Highlight = ( Gbl . Forum . ForumSelected . Type = = For_FORUM_INSTIT_TCHS & &
Gbl . Forum . ForumSelected . Location = = InsCod ) ;
2014-12-01 23:55:08 +01:00
IsLastItemInLevel [ 1 ] = IsLastIns ;
2017-04-19 12:34:38 +02:00
For_WriteLinkToForum ( & Forum , Highlight , false , 1 , IsLastItemInLevel ) ;
2014-12-01 23:55:08 +01:00
}
}
return InsCod ;
}
/*****************************************************************************/
/************************ Write links to centre forums ***********************/
/*****************************************************************************/
// Returns centre code
2017-01-28 15:58:46 +01:00
static long For_WriteLinksToCtrForums ( long CtrCod , bool IsLastCtr ,
bool IsLastItemInLevel [ 1 + For_FORUM_MAX_LEVELS ] )
2014-12-01 23:55:08 +01:00
{
2017-04-11 13:53:17 +02:00
bool Highlight ;
2017-05-23 20:42:38 +02:00
Rol_Role_t MaxRoleInCtr ;
2014-12-01 23:55:08 +01:00
bool ICanSeeTeacherForum ;
2017-04-19 12:34:38 +02:00
struct Forum Forum ;
2014-12-01 23:55:08 +01:00
if ( CtrCod > 0 )
{
2017-05-23 20:42:38 +02:00
MaxRoleInCtr = Rol_GetMyMaxRoleInCtr ( CtrCod ) ;
2017-06-04 18:18:54 +02:00
ICanSeeTeacherForum = ( Gbl . Usrs . Me . Role . Logged = = Rol_SYS_ADM | |
2017-05-23 20:42:38 +02:00
MaxRoleInCtr = = Rol_NET | |
MaxRoleInCtr = = Rol_TCH ) ;
2014-12-01 23:55:08 +01:00
/***** Link to the forum of users from this centre *****/
2017-04-19 12:34:38 +02:00
Forum . Type = For_FORUM_CENTRE_USRS ;
Forum . Location = CtrCod ;
2017-04-18 01:25:44 +02:00
Highlight = ( Gbl . Forum . ForumSelected . Type = = For_FORUM_CENTRE_USRS & &
Gbl . Forum . ForumSelected . Location = = CtrCod ) ;
2014-12-01 23:55:08 +01:00
IsLastItemInLevel [ 2 ] = ( IsLastCtr & & ! ICanSeeTeacherForum ) ;
2017-04-19 12:34:38 +02:00
For_WriteLinkToForum ( & Forum , Highlight , false , 2 , IsLastItemInLevel ) ;
2014-12-01 23:55:08 +01:00
/***** Link to forum of teachers from this centre *****/
if ( ICanSeeTeacherForum )
{
2017-04-19 12:34:38 +02:00
Forum . Type = For_FORUM_CENTRE_TCHS ;
Forum . Location = CtrCod ;
2017-04-18 01:25:44 +02:00
Highlight = ( Gbl . Forum . ForumSelected . Type = = For_FORUM_CENTRE_TCHS & &
Gbl . Forum . ForumSelected . Location = = CtrCod ) ;
2014-12-01 23:55:08 +01:00
IsLastItemInLevel [ 2 ] = IsLastCtr ;
2017-04-19 12:34:38 +02:00
For_WriteLinkToForum ( & Forum , Highlight , false , 2 , IsLastItemInLevel ) ;
2014-12-01 23:55:08 +01:00
}
}
return CtrCod ;
}
/*****************************************************************************/
/************************ Write links to degree forums ***********************/
/*****************************************************************************/
// Returns degree code
2017-01-28 15:58:46 +01:00
static long For_WriteLinksToDegForums ( long DegCod , bool IsLastDeg ,
bool IsLastItemInLevel [ 1 + For_FORUM_MAX_LEVELS ] )
2014-12-01 23:55:08 +01:00
{
2017-04-11 13:53:17 +02:00
bool Highlight ;
2017-05-23 20:42:38 +02:00
Rol_Role_t MaxRoleInDeg ;
2014-12-01 23:55:08 +01:00
bool ICanSeeTeacherForum ;
2017-04-19 12:34:38 +02:00
struct Forum Forum ;
2014-12-01 23:55:08 +01:00
if ( DegCod > 0 )
{
2017-05-23 20:42:38 +02:00
MaxRoleInDeg = Rol_GetMyMaxRoleInDeg ( DegCod ) ;
2017-06-04 18:18:54 +02:00
ICanSeeTeacherForum = ( Gbl . Usrs . Me . Role . Logged = = Rol_SYS_ADM | |
2017-05-23 20:42:38 +02:00
MaxRoleInDeg = = Rol_NET | |
MaxRoleInDeg = = Rol_TCH ) ;
2014-12-01 23:55:08 +01:00
/***** Link to the forum of users from this degree *****/
2017-04-19 12:34:38 +02:00
Forum . Type = For_FORUM_DEGREE_USRS ;
Forum . Location = DegCod ;
2017-04-18 01:25:44 +02:00
Highlight = ( Gbl . Forum . ForumSelected . Type = = For_FORUM_DEGREE_USRS & &
Gbl . Forum . ForumSelected . Location = = DegCod ) ;
2014-12-01 23:55:08 +01:00
IsLastItemInLevel [ 3 ] = ( IsLastDeg & & ! ICanSeeTeacherForum ) ;
2017-04-19 12:34:38 +02:00
For_WriteLinkToForum ( & Forum , Highlight , false , 3 , IsLastItemInLevel ) ;
2014-12-01 23:55:08 +01:00
/***** Link to forum of teachers from this degree *****/
if ( ICanSeeTeacherForum )
{
2017-04-19 12:34:38 +02:00
Forum . Type = For_FORUM_DEGREE_TCHS ;
Forum . Location = DegCod ;
2017-04-18 01:25:44 +02:00
Highlight = ( Gbl . Forum . ForumSelected . Type = = For_FORUM_DEGREE_TCHS & &
Gbl . Forum . ForumSelected . Location = = DegCod ) ;
2017-04-11 13:53:17 +02:00
IsLastItemInLevel [ 3 ] = IsLastDeg ;
2017-04-19 12:34:38 +02:00
For_WriteLinkToForum ( & Forum , Highlight , false , 3 , IsLastItemInLevel ) ;
2014-12-01 23:55:08 +01:00
}
}
return DegCod ;
}
/*****************************************************************************/
/************************ Write links to course forums ***********************/
/*****************************************************************************/
// Returns course code
2017-01-28 15:58:46 +01:00
static long For_WriteLinksToCrsForums ( long CrsCod , bool IsLastCrs ,
bool IsLastItemInLevel [ 1 + For_FORUM_MAX_LEVELS ] )
2014-12-01 23:55:08 +01:00
{
2017-04-11 13:53:17 +02:00
bool Highlight ;
2017-05-23 20:42:38 +02:00
Rol_Role_t MyRoleInCrs ;
2014-12-01 23:55:08 +01:00
bool ICanSeeTeacherForum ;
2017-04-19 12:34:38 +02:00
struct Forum Forum ;
2014-12-01 23:55:08 +01:00
if ( CrsCod > 0 )
{
2017-05-23 20:42:38 +02:00
MyRoleInCrs = Rol_GetMyRoleInCrs ( CrsCod ) ;
2017-06-04 18:18:54 +02:00
ICanSeeTeacherForum = ( Gbl . Usrs . Me . Role . Logged = = Rol_SYS_ADM | |
2017-05-23 20:42:38 +02:00
MyRoleInCrs = = Rol_NET | |
MyRoleInCrs = = Rol_TCH ) ;
2014-12-01 23:55:08 +01:00
/***** Link to the forum of users from this course *****/
2017-04-19 12:34:38 +02:00
Forum . Type = For_FORUM_COURSE_USRS ;
Forum . Location = CrsCod ;
2017-04-18 01:25:44 +02:00
Highlight = ( Gbl . Forum . ForumSelected . Type = = For_FORUM_COURSE_USRS & &
Gbl . Forum . ForumSelected . Location = = CrsCod ) ;
2014-12-01 23:55:08 +01:00
IsLastItemInLevel [ 4 ] = ( IsLastCrs & & ! ICanSeeTeacherForum ) ;
2017-04-19 12:34:38 +02:00
For_WriteLinkToForum ( & Forum , Highlight , false , 4 , IsLastItemInLevel ) ;
2014-12-01 23:55:08 +01:00
/***** Link to forum of teachers from this course *****/
if ( ICanSeeTeacherForum )
{
2017-04-19 12:34:38 +02:00
Forum . Type = For_FORUM_COURSE_TCHS ;
Forum . Location = CrsCod ;
2017-04-18 01:25:44 +02:00
Highlight = ( Gbl . Forum . ForumSelected . Type = = For_FORUM_COURSE_TCHS & &
Gbl . Forum . ForumSelected . Location = = CrsCod ) ;
2014-12-01 23:55:08 +01:00
IsLastItemInLevel [ 4 ] = IsLastCrs ;
2017-04-19 12:34:38 +02:00
For_WriteLinkToForum ( & Forum , Highlight , false , 4 , IsLastItemInLevel ) ;
2014-12-01 23:55:08 +01:00
}
}
return CrsCod ;
}
/*****************************************************************************/
/********************** Write title and link to a forum **********************/
/*****************************************************************************/
2017-04-19 12:34:38 +02:00
static void For_WriteLinkToForum ( struct Forum * Forum ,
2017-04-11 13:53:17 +02:00
bool Highlight , bool ShowNumOfPosts ,
2017-01-28 15:58:46 +01:00
unsigned Level ,
bool IsLastItemInLevel [ 1 + For_FORUM_MAX_LEVELS ] )
2014-12-01 23:55:08 +01:00
{
2017-04-19 12:34:38 +02:00
extern const char * The_ClassForm [ The_NUM_THEMES ] ;
extern const char * The_ClassFormBold [ The_NUM_THEMES ] ;
extern const char * Txt_Copy_not_allowed ;
extern const char * Txt_Paste_thread ;
unsigned NumThrs ;
unsigned NumThrsWithNewPosts ;
unsigned NumPosts ;
char ActTxt [ Act_MAX_BYTES_ACTION_TXT + 1 ] ;
const char * Style ;
2017-01-13 10:49:56 +01:00
char ForumName [ For_MAX_BYTES_FORUM_NAME + 1 ] ;
2014-12-01 23:55:08 +01:00
2017-04-19 12:34:38 +02:00
/***** Get number of threads and number of posts *****/
NumThrs = For_GetNumThrsInForum ( Forum ) ;
NumThrsWithNewPosts = For_GetNumThrsWithNewPstsInForum ( Forum , NumThrs ) ;
Style = ( NumThrsWithNewPosts ? The_ClassFormBold [ Gbl . Prefs . Theme ] :
The_ClassForm [ Gbl . Prefs . Theme ] ) ;
/***** Start row *****/
fprintf ( Gbl . F . Out , " <li " ) ;
if ( Highlight )
fprintf ( Gbl . F . Out , " class= \" LIGHT_BLUE \" " ) ;
fprintf ( Gbl . F . Out , " style= \" height:25px; \" > " ) ;
/***** Indent forum title *****/
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...
{
/* Check if thread to move is yet in current forum */
if ( For_CheckIfThrBelongsToForum ( Gbl . Forum . ThreadToMove , Forum ) )
fprintf ( Gbl . F . Out , " <img src= \" %s/paste_off16x16.gif \" "
" alt= \" %s \" title= \" %s \" "
" class= \" ICO20x20 \" /> " ,
Gbl . Prefs . IconsURL ,
Txt_Copy_not_allowed , Txt_Copy_not_allowed ) ;
else
{
2018-10-15 14:07:12 +02:00
Act_StartFormAnchor ( For_ActionsPasThrFor [ Forum - > Type ] ,
2017-05-25 13:43:54 +02:00
For_FORUM_THREADS_SECTION_ID ) ;
2017-04-19 12:34:38 +02:00
For_PutAllHiddenParamsForum ( 1 , // Page of threads = first
1 , // Page of posts = first
Gbl . Forum . ForumSet ,
Gbl . Forum . ThreadsOrder ,
Forum - > Location ,
Gbl . Forum . ThreadToMove ,
- 1L ) ;
fprintf ( Gbl . F . Out , " <input type= \" image \" src= \" %s/paste_on16x16.gif \" "
" alt= \" %s \" title= \" %s \" "
" class= \" ICO20x20 \" /> " ,
Gbl . Prefs . IconsURL ,
Txt_Paste_thread ,
Txt_Paste_thread ) ;
2018-10-15 14:07:12 +02:00
Act_EndForm ( ) ;
2017-04-19 12:34:38 +02:00
}
}
2014-12-01 23:55:08 +01:00
2017-04-19 12:34:38 +02:00
/***** Write link to forum *****/
2018-10-15 14:07:12 +02:00
Act_StartFormAnchor ( For_ActionsSeeFor [ Forum - > Type ] ,
2017-05-25 13:43:54 +02:00
For_FORUM_THREADS_SECTION_ID ) ;
2017-04-19 12:34:38 +02:00
For_PutAllHiddenParamsForum ( 1 , // Page of threads = first
1 , // Page of posts = first
Gbl . Forum . ForumSet ,
Gbl . Forum . ThreadsOrder ,
Forum - > Location ,
- 1L ,
- 1L ) ;
2018-04-24 13:21:53 +02:00
Act_LinkFormSubmit ( Act_GetActionTextFromDB ( Act_GetActCod ( For_ActionsSeeFor [ Forum - > Type ] ) , ActTxt ) ,
2017-04-19 12:34:38 +02:00
Style , NULL ) ;
For_SetForumName ( Forum , ForumName , Gbl . Prefs . Language , true ) ;
2017-04-18 01:25:44 +02:00
switch ( Forum - > Type )
2014-12-01 23:55:08 +01:00
{
case For_FORUM_GLOBAL_USRS :
case For_FORUM_GLOBAL_TCHS :
2017-04-19 12:34:38 +02:00
fprintf ( Gbl . F . Out , " <img src= \" %s/forum64x64.gif \" "
" alt= \" %s \" title= \" %s \" "
" class= \" ICO20x20 \" /> " ,
Gbl . Prefs . IconsURL , ForumName , ForumName ) ;
2014-12-01 23:55:08 +01:00
break ;
2017-04-18 19:55:56 +02:00
case For_FORUM__SWAD__USRS :
case For_FORUM__SWAD__TCHS :
2017-04-19 12:34:38 +02:00
fprintf ( Gbl . F . Out , " <img src= \" %s/swad64x64.gif \" "
" alt= \" %s \" title= \" %s \" "
" class= \" ICO20x20 \" /> " ,
Gbl . Prefs . IconsURL , ForumName , ForumName ) ;
break ;
case For_FORUM_INSTIT_USRS :
case For_FORUM_INSTIT_TCHS :
Log_DrawLogo ( Sco_SCOPE_INS , Forum - > Location , ForumName , 20 , NULL , true ) ;
break ;
case For_FORUM_CENTRE_USRS :
case For_FORUM_CENTRE_TCHS :
Log_DrawLogo ( Sco_SCOPE_CTR , Forum - > Location , ForumName , 20 , NULL , true ) ;
break ;
case For_FORUM_DEGREE_USRS :
case For_FORUM_DEGREE_TCHS :
Log_DrawLogo ( Sco_SCOPE_DEG , Forum - > Location , ForumName , 20 , NULL , true ) ;
2014-12-01 23:55:08 +01:00
break ;
case For_FORUM_COURSE_USRS :
case For_FORUM_COURSE_TCHS :
2017-04-19 12:34:38 +02:00
fprintf ( Gbl . F . Out , " <img src= \" %s/dot64x64.png \" "
" alt= \" %s \" title= \" %s \" "
" class= \" ICO20x20 \" /> " ,
Gbl . Prefs . IconsURL , ForumName , ForumName ) ;
2014-12-01 23:55:08 +01:00
break ;
2017-04-18 19:55:56 +02:00
default :
break ;
2014-12-01 23:55:08 +01:00
}
2017-04-19 12:34:38 +02:00
fprintf ( Gbl . F . Out , " %s " , ForumName ) ;
/***** Write total number of threads and posts in this forum *****/
if ( ShowNumOfPosts )
{
if ( ( NumPosts = For_GetNumPstsInForum ( Forum ) ) )
For_WriteNumThrsAndPsts ( NumThrs , NumThrsWithNewPosts , NumPosts ) ;
}
else
if ( NumThrs )
For_WriteNumberOfThrs ( NumThrs , NumThrsWithNewPosts ) ;
2014-12-01 23:55:08 +01:00
2017-04-19 12:34:38 +02:00
/***** End row *****/
fprintf ( Gbl . F . Out , " </a> " ) ;
2018-10-15 14:07:12 +02:00
Act_EndForm ( ) ;
2017-05-29 21:34:43 +02:00
/***** Put link to register students *****/
if ( Forum - > Type = = For_FORUM_COURSE_USRS )
Enr_PutButtonInlineToRegisterStds ( Forum - > Location ) ;
2017-04-19 12:34:38 +02:00
fprintf ( Gbl . F . Out , " </li> " ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************** Set the name of a forum **************************/
/*****************************************************************************/
2017-04-18 01:25:44 +02:00
void For_SetForumName ( struct Forum * Forum ,
2017-01-13 10:49:56 +01:00
char ForumName [ For_MAX_BYTES_FORUM_NAME + 1 ] ,
Txt_Language_t Language , bool UseHTMLEntities )
2014-12-01 23:55:08 +01:00
{
extern const char * Txt_General ;
2017-01-28 15:58:46 +01:00
extern const char * Txt_General_NO_HTML [ 1 + Txt_NUM_LANGUAGES ] ;
2014-12-01 23:55:08 +01:00
extern const char * Txt_only_teachers ;
2017-01-28 15:58:46 +01:00
extern const char * Txt_only_teachers_NO_HTML [ 1 + Txt_NUM_LANGUAGES ] ;
2017-04-18 19:55:56 +02:00
extern const char * Txt_Unknown_FORUM ;
2017-04-16 23:48:05 +02:00
struct Instit Ins ;
struct Centre Ctr ;
struct Degree Deg ;
struct Course Crs ;
2014-12-01 23:55:08 +01:00
2017-04-18 01:25:44 +02:00
switch ( Forum - > Type )
2014-12-01 23:55:08 +01:00
{
2017-04-18 19:55:56 +02:00
case For_FORUM_GLOBAL_USRS :
Str_Copy ( ForumName , UseHTMLEntities ? Txt_General :
Txt_General_NO_HTML [ Language ] ,
2017-01-17 03:10:43 +01:00
For_MAX_BYTES_FORUM_NAME ) ;
2014-12-01 23:55:08 +01:00
break ;
2017-04-18 19:55:56 +02:00
case For_FORUM_GLOBAL_TCHS :
2018-10-18 02:02:32 +02:00
snprintf ( ForumName , For_MAX_BYTES_FORUM_NAME + 1 ,
" %s%s " ,
UseHTMLEntities ? Txt_General :
Txt_General_NO_HTML [ Language ] ,
UseHTMLEntities ? Txt_only_teachers :
Txt_only_teachers_NO_HTML [ Language ] ) ;
2014-12-01 23:55:08 +01:00
break ;
2017-04-18 19:55:56 +02:00
case For_FORUM__SWAD__USRS :
Str_Copy ( ForumName , Cfg_PLATFORM_SHORT_NAME ,
2017-01-17 03:10:43 +01:00
For_MAX_BYTES_FORUM_NAME ) ;
2014-12-01 23:55:08 +01:00
break ;
2017-04-18 19:55:56 +02:00
case For_FORUM__SWAD__TCHS :
2018-10-18 02:02:32 +02:00
snprintf ( ForumName , For_MAX_BYTES_FORUM_NAME + 1 ,
" %s%s " , Cfg_PLATFORM_SHORT_NAME ,
UseHTMLEntities ? Txt_only_teachers :
Txt_only_teachers_NO_HTML [ Language ] ) ;
2017-04-18 19:55:56 +02:00
break ;
case For_FORUM_INSTIT_USRS :
Ins . InsCod = Forum - > Location ;
if ( ! Ins_GetDataOfInstitutionByCod ( & Ins , Ins_GET_BASIC_DATA ) )
Lay_ShowErrorAndExit ( " Institution not found. " ) ;
Str_Copy ( ForumName , Ins . ShrtName ,
For_MAX_BYTES_FORUM_NAME ) ;
break ;
case For_FORUM_INSTIT_TCHS :
Ins . InsCod = Forum - > Location ;
if ( ! Ins_GetDataOfInstitutionByCod ( & Ins , Ins_GET_BASIC_DATA ) )
Lay_ShowErrorAndExit ( " Institution not found. " ) ;
2018-10-18 02:02:32 +02:00
snprintf ( ForumName , For_MAX_BYTES_FORUM_NAME + 1 ,
" %s%s " , Ins . ShrtName ,
UseHTMLEntities ? Txt_only_teachers :
Txt_only_teachers_NO_HTML [ Language ] ) ;
2014-12-01 23:55:08 +01:00
break ;
case For_FORUM_CENTRE_USRS :
2017-04-18 01:25:44 +02:00
Ctr . CtrCod = Forum - > Location ;
2017-04-16 23:48:05 +02:00
if ( ! Ctr_GetDataOfCentreByCod ( & Ctr ) )
Lay_ShowErrorAndExit ( " Centre not found. " ) ;
Str_Copy ( ForumName , Ctr . ShrtName ,
2017-01-17 03:10:43 +01:00
For_MAX_BYTES_FORUM_NAME ) ;
2014-12-01 23:55:08 +01:00
break ;
case For_FORUM_CENTRE_TCHS :
2017-04-18 01:25:44 +02:00
Ctr . CtrCod = Forum - > Location ;
2017-04-16 23:48:05 +02:00
if ( ! Ctr_GetDataOfCentreByCod ( & Ctr ) )
Lay_ShowErrorAndExit ( " Centre not found. " ) ;
2018-10-18 02:02:32 +02:00
snprintf ( ForumName , For_MAX_BYTES_FORUM_NAME + 1 ,
" %s%s " , Ctr . ShrtName ,
UseHTMLEntities ? Txt_only_teachers :
Txt_only_teachers_NO_HTML [ Language ] ) ;
2014-12-01 23:55:08 +01:00
break ;
2017-04-18 19:55:56 +02:00
case For_FORUM_DEGREE_USRS :
Deg . DegCod = Forum - > Location ;
if ( ! Deg_GetDataOfDegreeByCod ( & Deg ) )
Lay_ShowErrorAndExit ( " Degree not found. " ) ;
Str_Copy ( ForumName , Deg . ShrtName ,
2017-01-17 03:10:43 +01:00
For_MAX_BYTES_FORUM_NAME ) ;
2014-12-01 23:55:08 +01:00
break ;
2017-04-18 19:55:56 +02:00
case For_FORUM_DEGREE_TCHS :
Deg . DegCod = Forum - > Location ;
if ( ! Deg_GetDataOfDegreeByCod ( & Deg ) )
Lay_ShowErrorAndExit ( " Degree not found. " ) ;
2018-10-18 02:02:32 +02:00
snprintf ( ForumName , For_MAX_BYTES_FORUM_NAME + 1 ,
" %s%s " , Deg . ShrtName ,
UseHTMLEntities ? Txt_only_teachers :
Txt_only_teachers_NO_HTML [ Language ] ) ;
2014-12-01 23:55:08 +01:00
break ;
2017-04-18 19:55:56 +02:00
case For_FORUM_COURSE_USRS :
Crs . CrsCod = Forum - > Location ;
if ( ! Crs_GetDataOfCourseByCod ( & Crs ) )
Lay_ShowErrorAndExit ( " Course not found. " ) ;
Str_Copy ( ForumName , Crs . ShrtName ,
2017-01-15 18:02:52 +01:00
For_MAX_BYTES_FORUM_NAME ) ;
2014-12-01 23:55:08 +01:00
break ;
2017-04-18 19:55:56 +02:00
case For_FORUM_COURSE_TCHS :
Crs . CrsCod = Forum - > Location ;
if ( ! Crs_GetDataOfCourseByCod ( & Crs ) )
Lay_ShowErrorAndExit ( " Course not found. " ) ;
2018-10-18 02:02:32 +02:00
snprintf ( ForumName , For_MAX_BYTES_FORUM_NAME + 1 ,
" %s%s " , Crs . ShrtName ,
UseHTMLEntities ? Txt_only_teachers :
Txt_only_teachers_NO_HTML [ Language ] ) ;
2014-12-01 23:55:08 +01:00
break ;
2017-04-18 19:55:56 +02:00
default :
Str_Copy ( ForumName , Txt_Unknown_FORUM ,
2017-01-17 03:10:43 +01:00
For_MAX_BYTES_FORUM_NAME ) ;
2014-12-01 23:55:08 +01:00
}
}
/*****************************************************************************/
/***** Get number of threads with new posts since my last read of a forum ****/
/*****************************************************************************/
2017-04-19 12:34:38 +02:00
static unsigned For_GetNumThrsWithNewPstsInForum ( struct Forum * Forum ,
2017-04-16 23:48:05 +02:00
unsigned NumThreads )
2014-12-01 23:55:08 +01:00
{
char SubQuery [ 256 ] ;
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
MYSQL_RES * mysql_res ;
MYSQL_ROW row ;
unsigned long NumRows ;
unsigned NumThrsWithNewPosts = NumThreads ; // By default, all the threads are new to me
/***** Get last time I read this forum from database *****/
2017-04-19 12:34:38 +02:00
if ( Forum - > Location > 0 )
sprintf ( SubQuery , " AND forum_thread.Location=%ld " , Forum - > Location ) ;
2017-04-16 23:48:05 +02:00
else
SubQuery [ 0 ] = ' \0 ' ;
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " SELECT MAX(forum_thr_read.ReadTime) "
" FROM forum_thr_read,forum_thread "
" WHERE forum_thr_read.UsrCod=%ld "
" AND forum_thr_read.ThrCod=forum_thread.ThrCod "
" AND forum_thread.ForumType=%u%s " ,
Gbl . Usrs . Me . UsrDat . UsrCod , ( unsigned ) Forum - > Type , SubQuery ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
NumRows = DB_QuerySELECT_free ( Query , & mysql_res , " can not get the date of reading of a forum " ) ;
2014-12-01 23:55:08 +01:00
if ( NumRows )
{
/***** Get number of threads with a last message modify time > newest read time (row[0]) *****/
row = mysql_fetch_row ( mysql_res ) ;
2017-04-19 12:34:38 +02:00
NumThrsWithNewPosts = For_GetNumOfThreadsInForumNewerThan ( Forum , row [ 0 ] ) ;
2014-12-01 23:55:08 +01:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult ( & mysql_res ) ;
return NumThrsWithNewPosts ;
}
/*****************************************************************************/
/**** Get number of threads in forum with a modify time > a specified time ***/
/*****************************************************************************/
2017-04-19 12:34:38 +02:00
static unsigned For_GetNumOfThreadsInForumNewerThan ( struct Forum * Forum ,
2017-04-16 23:48:05 +02:00
const char * Time )
2014-12-01 23:55:08 +01:00
{
char SubQuery [ 256 ] ;
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
2014-12-28 17:22:27 +01:00
/***** Get number of threads with a last message modify time
> specified time from database * * * * */
2017-04-19 12:34:38 +02:00
if ( Forum - > Location > 0 )
sprintf ( SubQuery , " AND forum_thread.Location=%ld " , Forum - > Location ) ;
2017-04-16 23:48:05 +02:00
else
SubQuery [ 0 ] = ' \0 ' ;
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " SELECT COUNT(*) FROM forum_thread,forum_post "
" WHERE forum_thread.ForumType=%u%s "
" AND forum_thread.LastPstCod=forum_post.PstCod "
" AND forum_post.ModifTime>'%s' " ,
( unsigned ) Forum - > Type , SubQuery , Time ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
return ( unsigned ) DB_QueryCOUNT_free ( Query , " can not check if there are new posts in a forum " ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/** Get number of unread posts in a thread since my last read of that thread */
/*****************************************************************************/
static unsigned For_GetNumOfUnreadPostsInThr ( long ThrCod , unsigned NumPostsInThr )
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
MYSQL_RES * mysql_res ;
MYSQL_ROW row ;
unsigned long NumRows ;
unsigned NumUnreadPosts = NumPostsInThr ; // By default, all the posts are unread by me
/***** Get last time I read this thread from database *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " SELECT ReadTime FROM forum_thr_read "
" WHERE ThrCod=%ld AND UsrCod=%ld " ,
ThrCod , Gbl . Usrs . Me . UsrDat . UsrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
NumRows = DB_QuerySELECT_free ( Query , & mysql_res , " can not get the date of reading of a thread " ) ;
2014-12-01 23:55:08 +01:00
/***** Get if last time I read this thread exists in database *****/
if ( NumRows )
{
/***** Get the number of posts in thread with a modify time > newest read time for me (row[0]) *****/
row = mysql_fetch_row ( mysql_res ) ;
NumUnreadPosts = For_GetNumOfPostsInThrNewerThan ( ThrCod , row [ 0 ] ) ;
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult ( & mysql_res ) ;
return NumUnreadPosts ;
}
/*****************************************************************************/
/**** Get number of posts in thread with a modify time > a specified time ****/
/*****************************************************************************/
static unsigned For_GetNumOfPostsInThrNewerThan ( long ThrCod , const char * Time )
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
/***** Get the number of posts in thread with a modify time > a specified time from database *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " SELECT COUNT(*) FROM forum_post "
" WHERE ThrCod=%ld AND ModifTime>'%s' " ,
ThrCod , Time ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
return ( unsigned ) DB_QueryCOUNT_free ( Query , " can not check if there are new posts in a thread of a forum " ) ;
2014-12-01 23:55:08 +01:00
}
2017-04-17 12:19:58 +02:00
/*****************************************************************************/
/*************** Get and write total number of threads and posts *************/
/*****************************************************************************/
static void For_WriteNumThrsAndPsts ( unsigned NumThrs , unsigned NumThrsWithNewPosts , unsigned NumPosts )
{
extern const char * Txt_thread ;
extern const char * Txt_threads ;
extern const char * Txt_post ;
extern const char * Txt_posts ;
extern const char * Txt_with_new_posts ;
/***** Write number of threads and number of posts *****/
fprintf ( Gbl . F . Out , " [ " ) ;
if ( NumThrs = = 1 )
{
fprintf ( Gbl . F . Out , " 1 %s " , Txt_thread ) ;
if ( NumThrsWithNewPosts )
fprintf ( Gbl . F . Out , " , 1 %s " , Txt_with_new_posts ) ;
fprintf ( Gbl . F . Out , " ; " ) ;
if ( NumPosts = = 1 )
fprintf ( Gbl . F . Out , " 1 %s " , Txt_post ) ;
else
fprintf ( Gbl . F . Out , " %u %s " , NumPosts , Txt_posts ) ;
}
else
{
fprintf ( Gbl . F . Out , " %u %s " , NumThrs , Txt_threads ) ;
if ( NumThrsWithNewPosts )
fprintf ( Gbl . F . Out , " , %u %s " , NumThrsWithNewPosts , Txt_with_new_posts ) ;
fprintf ( Gbl . F . Out , " ; %u %s " , NumPosts , Txt_posts ) ;
}
fprintf ( Gbl . F . Out , " ] " ) ;
}
/*****************************************************************************/
/************** Get and write total number of threads and posts **************/
/*****************************************************************************/
static void For_WriteNumberOfThrs ( unsigned NumThrs , unsigned NumThrsWithNewPosts )
{
extern const char * Txt_thread ;
extern const char * Txt_threads ;
extern const char * Txt_with_new_posts ;
/***** Write number of threads and number of posts *****/
fprintf ( Gbl . F . Out , " [ " ) ;
if ( NumThrs = = 1 )
fprintf ( Gbl . F . Out , " 1 %s " , Txt_thread ) ;
else
fprintf ( Gbl . F . Out , " %u %s " , NumThrs , Txt_threads ) ;
if ( NumThrsWithNewPosts )
fprintf ( Gbl . F . Out , " , %u %s " , NumThrsWithNewPosts , Txt_with_new_posts ) ;
fprintf ( Gbl . F . Out , " ] " ) ;
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/********************** Show available threads of a forum ********************/
/*****************************************************************************/
2017-04-18 16:44:44 +02:00
void For_ShowForumTheads ( void )
2017-04-14 01:02:33 +02:00
{
2017-04-16 13:45:11 +02:00
/***** Get parameters related to forum *****/
For_GetParamsForum ( ) ;
2017-04-18 13:17:40 +02:00
/***** Show forum list again *****/
For_ShowForumList ( ) ;
2017-04-16 13:45:11 +02:00
/***** Show forum threads with no one highlighted *****/
2017-05-11 23:45:46 +02:00
For_ShowForumThreadsHighlightingOneThread ( - 1L , Ale_SUCCESS , NULL ) ;
2017-04-14 01:02:33 +02:00
}
2017-04-16 13:45:11 +02:00
/*****************************************************************************/
/********** Show available threads of a forum highlighting a thread **********/
/*****************************************************************************/
2017-04-18 09:55:25 +02:00
static void For_ShowForumThreadsHighlightingOneThread ( long ThrCodHighlighted ,
2017-05-11 23:45:46 +02:00
Ale_AlertType_t AlertType , const char * Message )
2014-12-01 23:55:08 +01:00
{
2017-04-19 14:27:52 +02:00
extern const char * Hlp_SOCIAL_Forums_threads ;
2017-04-11 14:27:45 +02:00
extern const char * Txt_Forum ;
2014-12-01 23:55:08 +01:00
extern const char * Txt_MSG_Subject ;
extern const char * Txt_FORUM_THREAD_HELP_ORDER [ 2 ] ;
extern const char * Txt_FORUM_THREAD_ORDER [ 2 ] ;
extern const char * Txt_No_BR_msgs ;
extern const char * Txt_Unread_BR_msgs ;
extern const char * Txt_WriBRters ;
extern const char * Txt_ReaBRders ;
char SubQuery [ 256 ] ;
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
MYSQL_RES * mysql_res ;
MYSQL_ROW row ;
2017-04-11 14:27:45 +02:00
char FrameTitle [ 128 + For_MAX_BYTES_FORUM_NAME ] ;
char ForumName [ For_MAX_BYTES_FORUM_NAME + 1 ] ;
2017-04-11 13:53:17 +02:00
unsigned NumThr ;
unsigned NumThrs ;
2014-12-01 23:55:08 +01:00
unsigned NumThrInScreen ; // From 0 to Pag_ITEMS_PER_PAGE-1
2017-01-29 12:42:19 +01:00
For_Order_t Order ;
2014-12-01 23:55:08 +01:00
long ThrCods [ Pag_ITEMS_PER_PAGE ] ;
struct Pagination PaginationThrs ;
2017-04-11 13:53:17 +02:00
2017-04-11 14:27:45 +02:00
/***** Set forum name *****/
2017-04-18 01:25:44 +02:00
For_SetForumName ( & Gbl . Forum . ForumSelected ,
2017-04-11 14:27:45 +02:00
ForumName , Gbl . Prefs . Language , true ) ;
2014-12-01 23:55:08 +01:00
/***** Get threads of a forum from database *****/
2017-04-18 01:25:44 +02:00
if ( Gbl . Forum . ForumSelected . Location > 0 )
sprintf ( SubQuery , " AND forum_thread.Location=%ld " ,
Gbl . Forum . ForumSelected . Location ) ;
else
SubQuery [ 0 ] = ' \0 ' ;
2017-04-18 13:17:40 +02:00
switch ( Gbl . Forum . ThreadsOrder )
2014-12-01 23:55:08 +01:00
{
case For_FIRST_MSG :
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " SELECT forum_thread.ThrCod "
" FROM forum_thread,forum_post "
" 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 ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
2014-12-01 23:55:08 +01:00
break ;
case For_LAST_MSG :
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " SELECT forum_thread.ThrCod "
" FROM forum_thread,forum_post "
" 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 ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
2014-12-01 23:55:08 +01:00
break ;
}
2018-10-22 00:31:44 +02:00
NumThrs = ( unsigned ) DB_QuerySELECT_free ( Query , & mysql_res , " can not get thread of a forum " ) ;
2014-12-01 23:55:08 +01:00
/***** Compute variables related to pagination of threads *****/
PaginationThrs . NumItems = NumThrs ;
2017-04-13 20:09:22 +02:00
PaginationThrs . CurrentPage = ( int ) Gbl . Forum . CurrentPageThrs ;
2014-12-01 23:55:08 +01:00
Pag_CalculatePagination ( & PaginationThrs ) ;
2017-05-25 13:43:54 +02:00
PaginationThrs . Anchor = For_FORUM_THREADS_SECTION_ID ;
2017-04-13 20:09:22 +02:00
Gbl . Forum . CurrentPageThrs = ( unsigned ) PaginationThrs . CurrentPage ;
2014-12-01 23:55:08 +01:00
/***** Fill the list of threads for current page *****/
2016-10-26 01:23:02 +02:00
mysql_data_seek ( mysql_res , ( my_ulonglong ) ( PaginationThrs . FirstItemVisible - 1 ) ) ;
2014-12-01 23:55:08 +01:00
for ( NumThr = PaginationThrs . FirstItemVisible , NumThrInScreen = 0 ;
NumThr < = PaginationThrs . LastItemVisible ;
NumThr + + , NumThrInScreen + + )
{
row = mysql_fetch_row ( mysql_res ) ;
/* Get thread code(row[0]) */
if ( ( ThrCods [ NumThrInScreen ] = Str_ConvertStrCodToLongCod ( row [ 0 ] ) ) < 0 )
Lay_ShowErrorAndExit ( " Error when getting thread of a forum. " ) ;
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult ( & mysql_res ) ;
2017-04-18 09:55:25 +02:00
/***** Show alert after action *****/
2017-05-25 13:43:54 +02:00
Lay_StartSection ( For_FORUM_THREADS_SECTION_ID ) ;
2017-04-18 09:55:25 +02:00
if ( Message )
if ( Message [ 0 ] )
2017-05-11 23:45:46 +02:00
Ale_ShowAlert ( AlertType , Message ) ;
2017-04-18 09:55:25 +02:00
2017-06-12 14:16:33 +02:00
/***** Start box for threads of this forum *****/
2018-10-18 02:02:32 +02:00
snprintf ( FrameTitle , sizeof ( FrameTitle ) ,
" %s: %s " ,
Txt_Forum , ForumName ) ;
2017-06-10 21:38:10 +02:00
Box_StartBox ( NULL , FrameTitle , For_PutIconNewThread ,
2017-06-12 15:03:29 +02:00
Hlp_SOCIAL_Forums_threads , Box_NOT_CLOSABLE ) ;
2017-04-11 14:27:45 +02:00
2014-12-01 23:55:08 +01:00
/***** List the threads *****/
if ( NumThrs )
{
/***** Write links to all the pages in the listing of threads *****/
if ( PaginationThrs . MoreThanOnePage )
2017-04-17 11:57:55 +02:00
Pag_WriteLinksToPagesCentered ( Pag_THREADS_FORUM ,
0 ,
& PaginationThrs ) ;
2014-12-01 23:55:08 +01:00
/***** Heading row *****/
2017-06-11 20:09:59 +02:00
Tbl_StartTableWideMargin ( 2 ) ;
2017-05-01 12:36:24 +02:00
fprintf ( Gbl . F . Out , " <tr> "
2017-05-02 12:29:53 +02:00
" <th style= \" width:20px; \" ></th> "
" <th class= \" CONTEXT_COL \" ></th> " // Column for contextual icons
" <th class= \" LEFT_MIDDLE \" >%s</th> " ,
2014-12-01 23:55:08 +01:00
Txt_MSG_Subject ) ;
for ( Order = For_FIRST_MSG ;
Order < = For_LAST_MSG ;
Order + + )
{
2017-05-02 01:05:23 +02:00
fprintf ( Gbl . F . Out , " <th colspan= \" 2 \" class= \" CENTER_MIDDLE \" > " ) ;
2018-10-15 14:07:12 +02:00
Act_StartFormAnchor ( For_ActionsSeeFor [ Gbl . Forum . ForumSelected . Type ] ,
2017-05-25 13:43:54 +02:00
For_FORUM_THREADS_SECTION_ID ) ;
2017-04-18 16:44:44 +02:00
For_PutAllHiddenParamsForum ( Gbl . Forum . CurrentPageThrs , // Page of threads = current
1 , // Page of posts = first
Gbl . Forum . ForumSet ,
2017-04-18 01:25:44 +02:00
Order ,
Gbl . Forum . ForumSelected . Location ,
- 1L ,
- 1L ) ;
2016-07-01 17:13:41 +02:00
Act_LinkFormSubmit ( Txt_FORUM_THREAD_HELP_ORDER [ Order ] , " TIT_TBL " , NULL ) ;
2017-04-18 13:17:40 +02:00
if ( Order = = Gbl . Forum . ThreadsOrder )
2014-12-01 23:55:08 +01:00
fprintf ( Gbl . F . Out , " <u> " ) ;
fprintf ( Gbl . F . Out , " %s " , Txt_FORUM_THREAD_ORDER [ Order ] ) ;
2017-04-18 13:17:40 +02:00
if ( Order = = Gbl . Forum . ThreadsOrder )
2014-12-01 23:55:08 +01:00
fprintf ( Gbl . F . Out , " </u> " ) ;
2015-03-13 00:16:02 +01:00
fprintf ( Gbl . F . Out , " </a> " ) ;
2018-10-15 14:07:12 +02:00
Act_EndForm ( ) ;
2015-09-05 19:19:39 +02:00
fprintf ( Gbl . F . Out , " </th> " ) ;
2014-12-01 23:55:08 +01:00
}
2015-09-06 20:02:14 +02:00
fprintf ( Gbl . F . Out , " <th class= \" RIGHT_MIDDLE \" > "
2014-12-22 23:18:56 +01:00
" %s "
2015-09-05 19:19:39 +02:00
" </th> "
2015-09-06 20:02:14 +02:00
" <th class= \" RIGHT_MIDDLE \" > "
2014-12-22 23:18:56 +01:00
" %s "
2015-09-05 19:19:39 +02:00
" </th> "
2015-09-06 20:02:14 +02:00
" <th class= \" RIGHT_MIDDLE \" > "
2014-12-22 23:18:56 +01:00
" %s "
2015-09-05 19:19:39 +02:00
" </th> "
2015-09-06 20:02:14 +02:00
" <th class= \" RIGHT_MIDDLE \" > "
2014-12-22 23:18:56 +01:00
" %s "
2015-09-05 19:19:39 +02:00
" </th> "
2014-12-01 23:55:08 +01:00
" </tr> " ,
Txt_No_BR_msgs ,
Txt_Unread_BR_msgs ,
Txt_WriBRters ,
Txt_ReaBRders ) ;
/***** List the threads *****/
2017-04-14 01:02:33 +02:00
For_ListForumThrs ( ThrCods , ThrCodHighlighted , & PaginationThrs ) ;
2014-12-01 23:55:08 +01:00
/***** End table *****/
2017-06-11 20:09:59 +02:00
Tbl_EndTable ( ) ;
2014-12-01 23:55:08 +01:00
/***** Write links to all the pages in the listing of threads *****/
if ( PaginationThrs . MoreThanOnePage )
2017-04-17 11:57:55 +02:00
Pag_WriteLinksToPagesCentered ( Pag_THREADS_FORUM ,
0 ,
& PaginationThrs ) ;
2014-12-01 23:55:08 +01:00
}
2017-04-17 12:19:58 +02:00
/***** Put a form to write the first post of a new thread *****/
2017-05-25 13:43:54 +02:00
Lay_StartSection ( For_NEW_THREAD_SECTION_ID ) ;
2017-04-18 01:25:44 +02:00
For_WriteFormForumPst ( false , NULL ) ;
2017-05-25 13:43:54 +02:00
Lay_EndSection ( ) ;
2017-04-11 14:27:45 +02:00
2017-06-12 14:16:33 +02:00
/***** End box with threads of this forum ****/
2017-06-10 21:38:10 +02:00
Box_EndBox ( ) ;
2017-05-25 13:43:54 +02:00
Lay_EndSection ( ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2017-04-17 12:19:58 +02:00
/********************** Put icon to write a new thread ***********************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2017-04-17 12:19:58 +02:00
static void For_PutIconNewThread ( void )
2014-12-01 23:55:08 +01:00
{
2017-04-17 12:19:58 +02:00
extern const char * Txt_New_thread ;
2014-12-01 23:55:08 +01:00
2017-04-18 13:22:45 +02:00
Lay_PutContextualLink ( For_ActionsSeeFor [ Gbl . Forum . ForumSelected . Type ] ,
2017-05-25 13:43:54 +02:00
For_NEW_THREAD_SECTION_ID , For_PutAllHiddenParamsNewThread ,
2017-04-18 13:22:45 +02:00
" plus64x64.png " ,
Txt_New_thread , NULL ,
NULL ) ;
2014-12-01 23:55:08 +01:00
}
2017-04-19 14:43:08 +02:00
static void For_PutAllHiddenParamsNewThread ( void )
{
For_PutAllHiddenParamsForum ( 1 , // Page of threads = first
1 , // Page of posts = first
Gbl . Forum . ForumSet ,
Gbl . Forum . ThreadsOrder ,
Gbl . Forum . ForumSelected . Location ,
- 1L ,
- 1L ) ;
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/********************** Get number of forums of a type ***********************/
/*****************************************************************************/
unsigned For_GetNumTotalForumsOfType ( For_ForumType_t ForumType ,
2015-03-09 01:25:59 +01:00
long CtyCod , long InsCod , long CtrCod , long DegCod , long CrsCod )
2014-12-01 23:55:08 +01:00
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
MYSQL_RES * mysql_res ;
MYSQL_ROW row ;
unsigned NumForums ;
/***** Get number of forums of a type from database *****/
switch ( ForumType )
{
2017-04-18 19:55:56 +02:00
case For_FORUM_GLOBAL_USRS :
case For_FORUM_GLOBAL_TCHS :
case For_FORUM__SWAD__USRS :
case For_FORUM__SWAD__TCHS :
2014-12-01 23:55:08 +01:00
return 1 ; // Only one forum
2017-04-18 19:55:56 +02:00
case For_FORUM_INSTIT_USRS :
case For_FORUM_INSTIT_TCHS :
2014-12-01 23:55:08 +01:00
if ( InsCod > 0 ) // InsCod > 0 ==> 0 <= number of institutions forums for an institution <= 1
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(DISTINCT Location) "
" FROM forum_thread "
" WHERE ForumType=%u "
" AND Location=%ld " ,
( unsigned ) ForumType , InsCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2015-03-09 01:25:59 +01:00
else if ( CtyCod > 0 ) // InsCod <= 0 && CtyCod > 0 ==> Number of institution forums for a country
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(DISTINCT forum_thread.Location) "
" FROM forum_thread,institutions "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=institutions.InsCod "
" AND institutions.CtyCod=%ld " ,
( unsigned ) ForumType , CtyCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2015-03-09 01:25:59 +01:00
else // CtyCod <= 0 ==> Number of institutions forums for the whole platform
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(DISTINCT Location) "
" FROM forum_thread "
" WHERE ForumType=%u " ,
( unsigned ) ForumType ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
break ;
2017-04-18 19:55:56 +02:00
case For_FORUM_CENTRE_USRS :
case For_FORUM_CENTRE_TCHS :
2014-12-01 23:55:08 +01:00
if ( CtrCod > 0 ) // CtrCod > 0 ==> 0 <= number of centre forums for a centre <= 1
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(DISTINCT Location) "
" FROM forum_thread "
" WHERE ForumType=%u "
" AND Location=%ld " ,
( unsigned ) ForumType , CtrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
else if ( InsCod > 0 ) // CtrCod <= 0 && InsCod > 0 ==> Number of centre forums for an institution
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(DISTINCT forum_thread.Location) "
" FROM forum_thread,centres "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=centres.CtrCod "
" AND centres.InsCod=%ld " ,
( unsigned ) ForumType , InsCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2015-03-09 01:25:59 +01:00
else if ( CtyCod > 0 ) // InsCod <= 0 && CtyCod > 0 ==> Number of centre forums for a country
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(DISTINCT forum_thread.Location) "
" FROM forum_thread,centres,institutions "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=centres.CtrCod "
" AND centres.InsCod=institutions.InsCod "
" AND institutions.CtyCod=%ld " ,
( unsigned ) ForumType , CtyCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
else // InsCod <= 0 ==> Number of centre forums for the whole platform
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(DISTINCT Location) "
" FROM forum_thread "
" WHERE ForumType=%u " ,
( unsigned ) ForumType ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
break ;
2017-04-18 19:55:56 +02:00
case For_FORUM_DEGREE_USRS :
case For_FORUM_DEGREE_TCHS :
2014-12-01 23:55:08 +01:00
if ( DegCod > 0 ) // DegCod > 0 ==> 0 <= number of degree forums for a degree <= 1
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(DISTINCT Location) "
" FROM forum_thread "
" WHERE ForumType=%u "
" AND Location=%ld " ,
( unsigned ) ForumType , DegCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
else if ( CtrCod > 0 ) // DegCod <= 0 && CtrCod > 0 ==> Number of degree forums for a centre
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(DISTINCT forum_thread.Location) "
" FROM forum_thread,degrees "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=degrees.DegCod "
" AND degrees.CtrCod=%ld " ,
( unsigned ) ForumType , CtrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
else if ( InsCod > 0 ) // CtrCod <= 0 && InsCod > 0 ==> Number of degree forums for an institution
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(DISTINCT forum_thread.Location) "
" FROM forum_thread,degrees,centres "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=degrees.DegCod "
" AND degrees.CtrCod=centres.CtrCod "
" AND centres.InsCod=%ld " ,
( unsigned ) ForumType , InsCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2015-03-09 01:25:59 +01:00
else if ( CtyCod > 0 ) // InsCod <= 0 && CtyCod > 0 ==> Number of degree forums for a country
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(DISTINCT forum_thread.Location) "
" FROM forum_thread,degrees,centres,institutions "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=degrees.DegCod "
" AND degrees.CtrCod=centres.CtrCod "
" AND centres.InsCod=institutions.InsCod "
" AND institutions.CtyCod=%ld " ,
( unsigned ) ForumType , CtyCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
else // InsCod <= 0 ==> Number of degree forums for the whole platform
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(DISTINCT Location) "
" FROM forum_thread "
" WHERE ForumType=%u " ,
( unsigned ) ForumType ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
break ;
2017-04-18 19:55:56 +02:00
case For_FORUM_COURSE_USRS :
case For_FORUM_COURSE_TCHS :
2014-12-01 23:55:08 +01:00
if ( CrsCod > 0 ) // CrsCod > 0 ==> 0 <= number of course forums for a course <= 1
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(DISTINCT Location) "
" FROM forum_thread "
" WHERE ForumType=%u "
" AND Location=%ld " ,
( unsigned ) ForumType , CrsCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
else if ( DegCod > 0 ) // CrsCod <= 0 && DegCod > 0 ==> Number of course forums for a degree
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(DISTINCT forum_thread.Location) "
" FROM forum_thread,courses "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=courses.CrsCod "
" AND courses.DegCod=%ld " ,
( unsigned ) ForumType , DegCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
else if ( CtrCod > 0 ) // DegCod <= 0 && CtrCod > 0 ==> Number of course forums for a centre
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(DISTINCT forum_thread.Location) "
" FROM forum_thread,courses,degrees "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=courses.CrsCod "
" AND courses.DegCod=degrees.DegCod "
" AND degrees.CtrCod=%ld " ,
( unsigned ) ForumType , CtrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
else if ( InsCod > 0 ) // CtrCod <= 0 && InsCod > 0 ==> Number of course forums for an institution
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(DISTINCT forum_thread.Location) "
" FROM forum_thread,courses,degrees,centres "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=courses.CrsCod "
" AND courses.DegCod=degrees.DegCod "
" AND degrees.CtrCod=centres.CtrCod "
" AND centres.InsCod=%ld " ,
( unsigned ) ForumType , InsCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2015-03-09 01:25:59 +01:00
else if ( CtyCod > 0 ) // InsCod <= 0 && CtyCod > 0 ==> Number of course forums for a country
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(DISTINCT forum_thread.Location) "
" FROM forum_thread,courses,degrees,centres,institutions "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=courses.CrsCod "
" AND courses.DegCod=degrees.DegCod "
" AND degrees.CtrCod=centres.CtrCod "
" AND centres.InsCod=institutions.InsCod "
" AND institutions.CtyCod=%ld " ,
( unsigned ) ForumType , CtyCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
else // InsCod <= 0 ==> Number of course forums for the whole platform
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(DISTINCT Location) "
" FROM forum_thread "
" WHERE ForumType=%u " ,
( unsigned ) ForumType ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
break ;
2017-04-18 19:55:56 +02:00
default :
return 0 ;
2014-12-01 23:55:08 +01:00
}
2018-10-22 00:31:44 +02:00
DB_QuerySELECT_free ( Query , & mysql_res , " can not get number of forums of a type " ) ;
2014-12-01 23:55:08 +01:00
/* Get row with number of threads and number of posts */
row = mysql_fetch_row ( mysql_res ) ;
/* Get number of threads (row[0]) */
if ( sscanf ( row [ 0 ] , " %u " , & NumForums ) ! = 1 )
Lay_ShowErrorAndExit ( " Error when getting number of forums of a type. " ) ;
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult ( & mysql_res ) ;
return NumForums ;
}
/*****************************************************************************/
/*********** Get total number of threads in forums of this type **************/
/*****************************************************************************/
unsigned For_GetNumTotalThrsInForumsOfType ( For_ForumType_t ForumType ,
2015-03-09 01:25:59 +01:00
long CtyCod , long InsCod , long CtrCod , long DegCod , long CrsCod )
2014-12-01 23:55:08 +01:00
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
/***** Get total number of threads in forums of this type from database *****/
switch ( ForumType )
{
2017-04-18 19:55:56 +02:00
case For_FORUM_GLOBAL_USRS :
case For_FORUM_GLOBAL_TCHS :
case For_FORUM__SWAD__USRS :
case For_FORUM__SWAD__TCHS :
2014-12-01 23:55:08 +01:00
// Total number of threads in forums of this type
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " SELECT COUNT(*) "
" FROM forum_thread "
" WHERE ForumType=%u " ,
( unsigned ) ForumType ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
2014-12-01 23:55:08 +01:00
break ;
2017-04-18 19:55:56 +02:00
case For_FORUM_INSTIT_USRS :
case For_FORUM_INSTIT_TCHS :
2015-03-09 01:25:59 +01:00
if ( InsCod > 0 ) // InsCod > 0 ==> Number of threads in institution forums for an institution
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*) "
" FROM forum_thread "
" WHERE ForumType=%u "
" AND Location=%ld " ,
( unsigned ) ForumType , InsCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2015-03-09 01:25:59 +01:00
else if ( CtyCod > 0 ) // InsCod <= 0 && CtyCod > 0 ==> Number of threads in institution forums for a country
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*) "
" FROM forum_thread,institutions "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=institutions.InsCod "
" AND institutions.CtyCod=%ld " ,
( unsigned ) ForumType , CtyCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
else // InsCod <= 0 ==> Number of threads in institution forums for the whole platform
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*) "
" FROM forum_thread "
" WHERE ForumType=%u " ,
( unsigned ) ForumType ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
break ;
2017-04-18 19:55:56 +02:00
case For_FORUM_CENTRE_USRS :
case For_FORUM_CENTRE_TCHS :
2015-03-09 01:25:59 +01:00
if ( CtrCod > 0 ) // CtrCod > 0 ==> 0 <= Number of threads in centre forums for a centre <= 1
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*) "
" FROM forum_thread "
" WHERE ForumType=%u "
" AND Location=%ld " ,
( unsigned ) ForumType , CtrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2015-03-09 01:25:59 +01:00
else if ( InsCod > 0 ) // CtrCod <= 0 && InsCod > 0 ==> Number of threads in centre forums for an institution
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*) "
" FROM forum_thread,centres "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=centres.CtrCod "
" AND centres.InsCod=%ld " ,
( unsigned ) ForumType , InsCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2015-03-09 01:25:59 +01:00
else if ( CtyCod > 0 ) // InsCod <= 0 && CtyCod > 0 ==> Number of threads in centre forums for a country
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*) "
" FROM forum_thread,centres,institutions "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=centres.CtrCod "
" AND centres.InsCod=institutions.InsCod "
" AND institutions.CtyCod=%ld " ,
( unsigned ) ForumType , CtyCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
else // InsCod <= 0 ==> Number of threads in centre forums for the whole platform
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*) "
" FROM forum_thread "
" WHERE ForumType=%u " ,
( unsigned ) ForumType ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
break ;
2017-04-18 19:55:56 +02:00
case For_FORUM_DEGREE_USRS :
case For_FORUM_DEGREE_TCHS :
2015-03-09 01:25:59 +01:00
if ( DegCod > 0 ) // DegCod > 0 ==> Number of threads in degree forums for a degree
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*) "
" FROM forum_thread "
" WHERE ForumType=%u "
" AND Location=%ld " ,
( unsigned ) ForumType , DegCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
else if ( CtrCod > 0 ) // DegCod <= 0 && CtrCod > 0 ==> Number of threads in degree forums for a centre
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*) "
" FROM forum_thread,degrees "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=degrees.DegCod "
" AND degrees.CtrCod=%ld " ,
( unsigned ) ForumType , CtrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2015-03-09 01:25:59 +01:00
else if ( InsCod > 0 ) // CtrCod <= 0 && InsCod > 0 ==> Number of threads in degree forums for an institution
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*) "
" FROM forum_thread,degrees,centres "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=degrees.DegCod "
" AND degrees.CtrCod=centres.CtrCod "
" AND centres.InsCod=%ld " ,
( unsigned ) ForumType , InsCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2015-03-09 01:25:59 +01:00
else if ( CtyCod > 0 ) // InsCod <= 0 && CtyCod > 0 ==> Number of threads in degree forums for a country
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*) "
" FROM forum_thread,degrees,centres,institutions "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=degrees.DegCod "
" AND degrees.CtrCod=centres.CtrCod "
" AND centres.InsCod=institutions.InsCod "
" AND institutions.CtyCod=%ld " ,
( unsigned ) ForumType , CtyCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
else // InsCod <= 0 ==> Number of threads in degree forums for the whole platform
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*) "
" FROM forum_thread "
" WHERE ForumType=%u " ,
( unsigned ) ForumType ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
break ;
2017-04-18 19:55:56 +02:00
case For_FORUM_COURSE_USRS :
case For_FORUM_COURSE_TCHS :
2015-03-09 01:25:59 +01:00
if ( CrsCod > 0 ) // CrsCod > 0 ==> 0 <= Number of threads in course forums for a course
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*) "
" FROM forum_thread "
" WHERE ForumType=%u "
" AND Location=%ld " ,
( unsigned ) ForumType , CrsCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
else if ( DegCod > 0 ) // CrsCod <= 0 && DegCod > 0 ==> Number of threads in course forums for a degree
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*) "
" FROM forum_thread,courses "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=courses.CrsCod "
" AND courses.DegCod=%ld " ,
( unsigned ) ForumType , DegCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
else if ( CtrCod > 0 ) // DegCod <= 0 && CtrCod > 0 ==> Number of threads in course forums for a centre
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*) "
" FROM forum_thread,courses,degrees "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=courses.CrsCod "
" AND courses.DegCod=degrees.DegCod "
" AND degrees.CtrCod=%ld " ,
( unsigned ) ForumType , CtrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2015-03-09 01:25:59 +01:00
else if ( InsCod > 0 ) // CtrCod <= 0 && InsCod > 0 ==> Number of threads in course forums for an institution
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*) "
" FROM forum_thread,courses,degrees,centres "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=courses.CrsCod "
" AND courses.DegCod=degrees.DegCod "
" AND degrees.CtrCod=centres.CtrCod "
" AND centres.InsCod=%ld " ,
( unsigned ) ForumType , InsCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2015-03-09 01:25:59 +01:00
else if ( CtyCod > 0 ) // InsCod <= 0 && CtyCod > 0 ==> Number of threads in course forums for a country
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*) "
" FROM forum_thread,courses,degrees,centres,institutions "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=courses.CrsCod "
" AND courses.DegCod=degrees.DegCod "
" AND degrees.CtrCod=centres.CtrCod "
" AND centres.InsCod=institutions.InsCod "
" AND institutions.CtyCod=%ld " ,
( unsigned ) ForumType , CtyCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
else // InsCod <= 0 ==> Number of threads in course forums for the whole platform
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*) "
" FROM forum_thread "
" WHERE ForumType=%u " ,
( unsigned ) ForumType ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
break ;
2017-04-18 19:55:56 +02:00
default :
return 0 ;
2014-12-01 23:55:08 +01:00
}
2018-10-22 00:31:44 +02:00
return ( unsigned ) DB_QueryCOUNT_free ( Query , " can not get the number of threads in forums of a type " ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************* Get number of threads in a forum ************************/
/*****************************************************************************/
2017-04-19 12:34:38 +02:00
static unsigned For_GetNumThrsInForum ( struct Forum * Forum )
2014-12-01 23:55:08 +01:00
{
char SubQuery [ 256 ] ;
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
/***** Get number of threads in a forum from database *****/
2017-04-19 12:34:38 +02:00
if ( Forum - > Location > 0 )
sprintf ( SubQuery , " AND Location=%ld " , Forum - > Location ) ;
2017-04-16 23:48:05 +02:00
else
SubQuery [ 0 ] = ' \0 ' ;
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " SELECT COUNT(*) FROM forum_thread WHERE ForumType=%u%s " ,
( unsigned ) Forum - > Type , SubQuery ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
return ( unsigned ) DB_QueryCOUNT_free ( Query , " can not get number of threads in a forum " ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************** Get total number of posts in forums of a type ****************/
/*****************************************************************************/
unsigned For_GetNumTotalPstsInForumsOfType ( For_ForumType_t ForumType ,
2015-03-09 01:25:59 +01:00
long CtyCod , long InsCod , long CtrCod , long DegCod , long CrsCod ,
2014-12-01 23:55:08 +01:00
unsigned * NumUsrsToBeNotifiedByEMail )
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
MYSQL_RES * mysql_res ;
MYSQL_ROW row ;
unsigned NumPosts ;
/***** Get total number of posts in forums of this type from database *****/
switch ( ForumType )
{
2017-04-18 19:55:56 +02:00
case For_FORUM_GLOBAL_USRS :
case For_FORUM_GLOBAL_TCHS :
case For_FORUM__SWAD__USRS :
case For_FORUM__SWAD__TCHS :
2014-12-01 23:55:08 +01:00
// Total number of posts in forums of this type
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " SELECT COUNT(*),SUM(forum_post.NumNotif) "
" FROM forum_thread,forum_post "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.ThrCod=forum_post.ThrCod " ,
( unsigned ) ForumType ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
2014-12-01 23:55:08 +01:00
break ;
2016-10-28 00:23:02 +02:00
case For_FORUM_INSTIT_USRS : case For_FORUM_INSTIT_TCHS :
2014-12-01 23:55:08 +01:00
if ( InsCod > 0 ) // InsCod > 0 ==> Number of posts in institutions forums for an institution
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*),SUM(forum_post.NumNotif) "
" FROM forum_thread,forum_post "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=%ld "
" AND forum_thread.ThrCod=forum_post.ThrCod " ,
( unsigned ) ForumType , InsCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2015-03-09 01:25:59 +01:00
else if ( CtyCod > 0 ) // InsCod <= 0 && CtyCod > 0 ==> Number of posts in institutions forums for a country
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*),SUM(forum_post.NumNotif) "
" FROM forum_thread,institutions,forum_post "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=institutions.InsCod "
" AND institutions.CtyCod=%ld "
" AND forum_thread.ThrCod=forum_post.ThrCod " ,
( unsigned ) ForumType , CtyCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
else // InsCod <= 0 ==> Number of posts in institution forums for the whole platform
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*),SUM(forum_post.NumNotif) "
" FROM forum_thread,forum_post "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.ThrCod=forum_post.ThrCod " ,
( unsigned ) ForumType ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
break ;
2017-04-18 19:55:56 +02:00
case For_FORUM_CENTRE_USRS :
case For_FORUM_CENTRE_TCHS :
2014-12-01 23:55:08 +01:00
if ( CtrCod > 0 ) // CtrCod > 0 ==> Number of posts in centre forums for a centre
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*),SUM(forum_post.NumNotif) "
" FROM forum_thread,forum_post "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=%ld "
" AND forum_thread.ThrCod=forum_post.ThrCod " ,
( unsigned ) ForumType , CtrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
else if ( InsCod > 0 ) // CtrCod <= 0 && InsCod > 0 ==> Number of posts in centre forums for an institution
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*),SUM(forum_post.NumNotif) "
" FROM forum_thread,centres,forum_post "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=centres.CtrCod "
" AND centres.InsCod=%ld "
" AND forum_thread.ThrCod=forum_post.ThrCod " ,
( unsigned ) ForumType , InsCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2015-03-09 01:25:59 +01:00
else if ( CtyCod > 0 ) // InsCod <= 0 && CtyCod > 0 ==> Number of posts in centre forums for a country
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*),SUM(forum_post.NumNotif) "
" FROM forum_thread,centres,institutions,forum_post "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=centres.CtrCod "
" AND centres.InsCod=institutions.InsCod "
" AND institutions.CtyCod=%ld "
" AND forum_thread.ThrCod=forum_post.ThrCod " ,
( unsigned ) ForumType , CtyCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
else // InsCod <= 0 ==> Number of posts in centre forums for the whole platform
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*),SUM(forum_post.NumNotif) "
" FROM forum_thread,forum_post "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.ThrCod=forum_post.ThrCod " ,
( unsigned ) ForumType ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
break ;
2017-04-18 19:55:56 +02:00
case For_FORUM_DEGREE_USRS :
case For_FORUM_DEGREE_TCHS :
2014-12-01 23:55:08 +01:00
if ( DegCod > 0 ) // DegCod > 0 ==> Number of posts in degree forums for a degree
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*),SUM(forum_post.NumNotif) "
" FROM forum_thread,forum_post "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=%ld "
" AND forum_thread.ThrCod=forum_post.ThrCod " ,
( unsigned ) ForumType , DegCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
else if ( CtrCod > 0 ) // DegCod <= 0 && CtrCod > 0 ==> Number of posts in degree forums for a centre
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*),SUM(forum_post.NumNotif) "
" FROM forum_thread,degrees,forum_post "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=degrees.DegCod "
" AND degrees.CtrCod=%ld "
" AND forum_thread.ThrCod=forum_post.ThrCod " ,
( unsigned ) ForumType , CtrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
else if ( InsCod > 0 ) // CtrCod <= 0 && InsCod > 0 ==> Number of posts in degree forums for an institution
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*),SUM(forum_post.NumNotif) "
" FROM forum_thread,degrees,centres,forum_post "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=degrees.DegCod "
" AND degrees.CtrCod=centres.CtrCod "
" AND centres.InsCod=%ld "
" AND forum_thread.ThrCod=forum_post.ThrCod " ,
( unsigned ) ForumType , InsCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2015-03-09 01:25:59 +01:00
else if ( CtyCod > 0 ) // InsCod <= 0 && CtyCod > 0 ==> Number of posts in degree forums for a country
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*),SUM(forum_post.NumNotif) "
" FROM forum_thread,degrees,centres,institutions,forum_post "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=degrees.DegCod "
" AND degrees.CtrCod=centres.CtrCod "
" AND centres.InsCod=institutions.InsCod "
" AND institutions.CtyCod=%ld "
" AND forum_thread.ThrCod=forum_post.ThrCod " ,
( unsigned ) ForumType , CtyCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
else // InsCod <= 0 ==> Number of posts in degree forums for the whole platform
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*),SUM(forum_post.NumNotif) "
" FROM forum_thread,forum_post "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.ThrCod=forum_post.ThrCod " ,
( unsigned ) ForumType ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
break ;
2017-04-18 19:55:56 +02:00
case For_FORUM_COURSE_USRS :
case For_FORUM_COURSE_TCHS :
2014-12-01 23:55:08 +01:00
if ( CrsCod > 0 ) // CrsCod > 0 ==> 0 <= number of posts in course forums for a course
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*),SUM(forum_post.NumNotif) "
" FROM forum_thread,forum_post "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=%ld "
" AND forum_thread.ThrCod=forum_post.ThrCod " ,
( unsigned ) ForumType , CrsCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
else if ( DegCod > 0 ) // CrsCod <= 0 && DegCod > 0 ==> Number of posts in course forums for a degree
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*),SUM(forum_post.NumNotif) "
" FROM forum_thread,courses,forum_post "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=courses.CrsCod "
" AND courses.DegCod=%ld "
" AND forum_thread.ThrCod=forum_post.ThrCod " ,
( unsigned ) ForumType , DegCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
else if ( CtrCod > 0 ) // DegCod <= 0 && CtrCod > 0 ==> Number of posts in course forums for a centre
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*),SUM(forum_post.NumNotif) "
" FROM forum_thread,courses,degrees,forum_post "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=courses.CrsCod "
" AND courses.DegCod=degrees.DegCod "
" AND degrees.CtrCod=%ld "
" AND forum_thread.ThrCod=forum_post.ThrCod " ,
( unsigned ) ForumType , CtrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
else if ( InsCod > 0 ) // CtrCod <= 0 && InsCod > 0 ==> Number of posts in course forums for an institution
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*),SUM(forum_post.NumNotif) "
" FROM forum_thread,courses,degrees,centres,forum_post "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=courses.CrsCod "
" AND courses.DegCod=degrees.DegCod "
" AND degrees.CtrCod=centres.CtrCod "
" AND centres.InsCod=%ld "
" AND forum_thread.ThrCod=forum_post.ThrCod " ,
( unsigned ) ForumType , InsCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2015-03-09 01:25:59 +01:00
else if ( CtyCod > 0 ) // InsCod <= 0 && CtyCod > 0 ==> Number of posts in course forums for a country
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*),SUM(forum_post.NumNotif) "
" FROM forum_thread,courses,degrees,centres,institutions,forum_post "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.Location=courses.CrsCod "
" AND courses.DegCod=degrees.DegCod "
" AND degrees.CtrCod=centres.CtrCod "
" AND centres.InsCod=institutions.InsCod "
" AND institutions.CtyCod=%ld "
" AND forum_thread.ThrCod=forum_post.ThrCod " ,
( unsigned ) ForumType , CtyCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
else // CrsCod <= 0 && DegCod <= 0 && CtrCod <= 0 ==> Number of posts in course forums for the whole platform
2018-10-22 00:31:44 +02:00
{
if ( asprintf ( & Query , " SELECT COUNT(*),SUM(forum_post.NumNotif) "
" FROM forum_thread,forum_post "
" WHERE forum_thread.ForumType=%u "
" AND forum_thread.ThrCod=forum_post.ThrCod " ,
( unsigned ) ForumType ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
}
2014-12-01 23:55:08 +01:00
break ;
2017-04-18 19:55:56 +02:00
default :
return 0 ;
2014-12-01 23:55:08 +01:00
}
2018-10-22 00:31:44 +02:00
DB_QuerySELECT_free ( Query , & mysql_res , " can not get the total number of forums of a type " ) ;
2014-12-01 23:55:08 +01:00
/* Get row with number of posts */
row = mysql_fetch_row ( mysql_res ) ;
/* Get number of posts (row[0]) */
if ( sscanf ( row [ 0 ] , " %u " , & NumPosts ) ! = 1 )
Lay_ShowErrorAndExit ( " Error when getting the total number of forums of a type. " ) ;
/* Get number of users notified (row[1]) */
if ( row [ 1 ] )
{
if ( sscanf ( row [ 1 ] , " %u " , NumUsrsToBeNotifiedByEMail ) ! = 1 )
Lay_ShowErrorAndExit ( " Error when getting the total number of forums of a type. " ) ;
}
else
* NumUsrsToBeNotifiedByEMail = 0 ;
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult ( & mysql_res ) ;
return NumPosts ;
}
/*****************************************************************************/
/********************* Get number of posts in a forum ************************/
/*****************************************************************************/
2017-04-19 12:34:38 +02:00
static unsigned For_GetNumPstsInForum ( struct Forum * Forum )
2014-12-01 23:55:08 +01:00
{
char SubQuery [ 256 ] ;
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
/***** Get number of posts in a forum from database *****/
2017-04-19 12:34:38 +02:00
if ( Forum - > Location > 0 )
sprintf ( SubQuery , " AND forum_thread.Location=%ld " , Forum - > Location ) ;
2017-04-16 23:48:05 +02:00
else
SubQuery [ 0 ] = ' \0 ' ;
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " SELECT COUNT(*) FROM forum_thread,forum_post "
" WHERE forum_thread.ForumType=%u%s "
" AND forum_thread.ThrCod=forum_post.ThrCod " ,
( unsigned ) Forum - > Type , SubQuery ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
return ( unsigned ) DB_QueryCOUNT_free ( Query , " can not get the number of posts in a forum " ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************ List the threads of a forum ************************/
/*****************************************************************************/
2017-04-13 23:53:57 +02:00
static void For_ListForumThrs ( long ThrCods [ Pag_ITEMS_PER_PAGE ] ,
2017-04-14 01:02:33 +02:00
long ThrCodHighlighted ,
2017-04-13 23:53:57 +02:00
struct Pagination * PaginationThrs )
2014-12-01 23:55:08 +01:00
{
2015-07-27 21:25:45 +02:00
extern const char * The_ClassForm [ The_NUM_THEMES ] ;
extern const char * The_ClassFormBold [ The_NUM_THEMES ] ;
2014-12-01 23:55:08 +01:00
extern const char * Txt_You_have_written_1_post_in_this_thread ;
extern const char * Txt_You_have_written_X_posts_in_this_thread ;
extern const char * Txt_Thread_with_posts_from_you ;
extern const char * Txt_There_are_new_posts ;
extern const char * Txt_No_new_posts ;
extern const char * Txt_Move_thread ;
2015-12-29 11:35:01 +01:00
extern const char * Txt_Today ;
2014-12-01 23:55:08 +01:00
unsigned NumThr ;
unsigned NumThrInScreen ; // From 0 to Pag_ITEMS_PER_PAGE-1
2015-10-24 20:46:11 +02:00
unsigned UniqueId ;
2014-12-01 23:55:08 +01:00
struct ForumThread Thr ;
struct UsrData UsrDat ;
2017-01-29 12:42:19 +01:00
For_Order_t Order ;
2015-10-24 20:12:03 +02:00
time_t TimeUTC ;
2014-12-01 23:55:08 +01:00
struct Pagination PaginationPsts ;
const char * Style ;
long ThreadInMyClipboard = - 1L ;
unsigned Column ;
2015-09-04 17:43:18 +02:00
const char * BgColor ;
2017-04-18 13:17:40 +02:00
bool ICanMoveThreads ;
2014-12-01 23:55:08 +01:00
/***** Get if there is a thread ready to be moved *****/
2017-04-18 13:17:40 +02:00
if ( ( ICanMoveThreads = For_CheckIfICanMoveThreads ( ) ) )
2014-12-01 23:55:08 +01:00
ThreadInMyClipboard = For_GetThrInMyClipboard ( ) ;
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor ( & UsrDat ) ;
2015-10-24 20:46:11 +02:00
for ( NumThr = PaginationThrs - > FirstItemVisible , NumThrInScreen = 0 , UniqueId = 0 , Gbl . RowEvenOdd = 0 ;
2014-12-01 23:55:08 +01:00
NumThr < = PaginationThrs - > LastItemVisible ;
NumThr + + , NumThrInScreen + + , Gbl . RowEvenOdd = 1 - Gbl . RowEvenOdd )
{
/***** Get the data of this thread *****/
Thr . ThrCod = ThrCods [ NumThrInScreen ] ;
For_GetThrData ( & Thr ) ;
2017-03-03 21:34:25 +01:00
Style = ( Thr . NumUnreadPosts ? " AUTHOR_TXT_NEW " :
" AUTHOR_TXT " ) ;
2017-04-14 01:02:33 +02:00
BgColor = ( Thr . ThrCod = = ThreadInMyClipboard ) ? " LIGHT_GREEN " :
( ( Thr . ThrCod = = ThrCodHighlighted ) ? " LIGHT_BLUE " :
Gbl . ColorRows [ Gbl . RowEvenOdd ] ) ;
2014-12-01 23:55:08 +01:00
/***** Show my photo if I have any posts in this thread *****/
fprintf ( Gbl . F . Out , " <tr> "
2017-05-02 12:29:53 +02:00
" <td class= \" CENTER_TOP %s \" style= \" width:20px; \" > " ,
2015-09-04 17:43:18 +02:00
BgColor ) ;
2014-12-01 23:55:08 +01:00
if ( Thr . NumMyPosts )
{
2015-09-06 13:19:12 +02:00
fprintf ( Gbl . F . Out , " <img src= \" " ) ;
2014-12-01 23:55:08 +01:00
if ( Gbl . Usrs . Me . PhotoURL [ 0 ] ) // If I have photo
2015-07-21 20:20:59 +02:00
fprintf ( Gbl . F . Out , " %s " ,
Gbl . Usrs . Me . PhotoURL ) ;
2014-12-01 23:55:08 +01:00
else
2015-07-21 20:20:59 +02:00
fprintf ( Gbl . F . Out , " %s/usr_bl.jpg " ,
Gbl . Prefs . IconsURL ) ;
2015-09-06 13:19:12 +02:00
fprintf ( Gbl . F . Out , " \" alt= \" %s \" title= \" " ,
2014-12-01 23:55:08 +01:00
Txt_Thread_with_posts_from_you ) ;
2015-09-06 13:19:12 +02:00
if ( Thr . NumMyPosts = = 1 )
fprintf ( Gbl . F . Out , " %s " , Txt_You_have_written_1_post_in_this_thread ) ;
else
fprintf ( Gbl . F . Out , Txt_You_have_written_X_posts_in_this_thread ,
Thr . NumMyPosts ) ;
2015-12-13 12:51:41 +01:00
fprintf ( Gbl . F . Out , " \" class= \" PHOTO15x20 \" /> " ) ;
2014-12-01 23:55:08 +01:00
}
fprintf ( Gbl . F . Out , " </td> " ) ;
/***** Put an icon with thread status *****/
2017-05-02 12:29:53 +02:00
fprintf ( Gbl . F . Out , " <td class= \" CONTEXT_COL %s \" > "
2015-07-21 20:20:59 +02:00
" <img src= \" %s/%s16x16.gif \" "
" alt= \" %s \" title= \" %s \" "
2016-11-14 10:05:41 +01:00
" class= \" ICO20x20 \" /> " ,
2015-09-04 17:43:18 +02:00
BgColor ,
2014-12-01 23:55:08 +01:00
Gbl . Prefs . IconsURL ,
Thr . NumUnreadPosts ? " msg-unread " :
" msg-open " ,
2015-07-21 20:20:59 +02:00
Thr . NumUnreadPosts ? Txt_There_are_new_posts :
Txt_No_new_posts ,
2014-12-01 23:55:08 +01:00
Thr . NumUnreadPosts ? Txt_There_are_new_posts :
Txt_No_new_posts ) ;
2017-04-18 09:55:25 +02:00
/***** Put button to remove the thread *****/
2017-04-18 01:25:44 +02:00
if ( PermissionThreadDeletion [ Gbl . Forum . ForumSelected . Type ] &
2017-06-04 18:18:54 +02:00
( 1 < < Gbl . Usrs . Me . Role . Logged ) ) // If I have permission to remove thread in this forum...
2014-12-01 23:55:08 +01:00
{
fprintf ( Gbl . F . Out , " <br /> " ) ;
2018-10-15 14:07:12 +02:00
Act_StartFormAnchor ( For_ActionsReqDelThr [ Gbl . Forum . ForumSelected . Type ] ,
2017-05-25 13:43:54 +02:00
For_REMOVE_THREAD_SECTION_ID ) ;
2017-04-18 16:44:44 +02:00
For_PutAllHiddenParamsForum ( Gbl . Forum . CurrentPageThrs , // Page of threads = current
1 , // Page of posts = first
Gbl . Forum . ForumSet ,
2017-04-18 13:17:40 +02:00
Gbl . Forum . ThreadsOrder ,
2017-04-18 01:25:44 +02:00
Gbl . Forum . ForumSelected . Location ,
Thr . ThrCod ,
- 1L ) ;
2017-06-11 19:13:28 +02:00
Ico_PutIconRemove ( ) ;
2018-10-15 14:07:12 +02:00
Act_EndForm ( ) ;
2014-12-01 23:55:08 +01:00
}
2017-04-18 09:55:25 +02:00
/***** Put button to cut the thread for moving it to another forum *****/
2014-12-01 23:55:08 +01:00
if ( ICanMoveThreads )
{
fprintf ( Gbl . F . Out , " <br /> " ) ;
2018-10-15 14:07:12 +02:00
Act_StartFormAnchor ( For_ActionsCutThrFor [ Gbl . Forum . ForumSelected . Type ] ,
2017-05-25 13:43:54 +02:00
For_FORUM_THREADS_SECTION_ID ) ;
2017-04-18 16:44:44 +02:00
For_PutAllHiddenParamsForum ( Gbl . Forum . CurrentPageThrs , // Page of threads = current
1 , // Page of posts = first
Gbl . Forum . ForumSet ,
2017-04-18 13:17:40 +02:00
Gbl . Forum . ThreadsOrder ,
2017-04-18 01:25:44 +02:00
Gbl . Forum . ForumSelected . Location ,
Thr . ThrCod ,
- 1L ) ;
2014-12-01 23:55:08 +01:00
fprintf ( Gbl . F . Out , " <input type= \" image \" src= \" %s/cut16x16.gif \" "
2015-09-05 12:04:30 +02:00
" alt= \" %s \" title= \" %s \" "
2016-11-14 10:05:41 +01:00
" class= \" ICO20x20 \" /> " ,
2014-12-01 23:55:08 +01:00
Gbl . Prefs . IconsURL ,
Txt_Move_thread ,
Txt_Move_thread ) ;
2018-10-15 14:07:12 +02:00
Act_EndForm ( ) ;
2014-12-01 23:55:08 +01:00
}
fprintf ( Gbl . F . Out , " </td> " ) ;
/***** Write subject and links to thread pages *****/
2015-09-04 17:43:18 +02:00
fprintf ( Gbl . F . Out , " <td class= \" LEFT_TOP %s \" > " , BgColor ) ;
2014-12-01 23:55:08 +01:00
PaginationPsts . NumItems = Thr . NumPosts ;
PaginationPsts . CurrentPage = 1 ; // First page
Pag_CalculatePagination ( & PaginationPsts ) ;
2017-05-25 13:43:54 +02:00
PaginationPsts . Anchor = For_FORUM_POSTS_SECTION_ID ;
2017-04-17 11:57:55 +02:00
Pag_WriteLinksToPages ( Pag_POSTS_FORUM ,
Thr . ThrCod ,
& PaginationPsts ,
2014-12-01 23:55:08 +01:00
Thr . Enabled [ For_FIRST_MSG ] ,
Thr . Subject ,
2015-07-27 21:25:45 +02:00
Thr . NumUnreadPosts ? The_ClassFormBold [ Gbl . Prefs . Theme ] :
The_ClassForm [ Gbl . Prefs . Theme ] ,
2014-12-01 23:55:08 +01:00
true ) ;
fprintf ( Gbl . F . Out , " </td> " ) ;
2015-10-24 20:12:03 +02:00
/***** Write the authors and date-times of first and last posts *****/
2014-12-01 23:55:08 +01:00
for ( Order = For_FIRST_MSG ;
Order < = For_LAST_MSG ;
Order + + )
{
if ( Order = = For_FIRST_MSG | | Thr . NumPosts > 1 ) // Don't write twice the same author when thread has only one thread
{
/* Write the author of first or last message */
UsrDat . UsrCod = Thr . UsrCod [ Order ] ;
Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod ( & UsrDat ) ;
2017-05-02 01:05:23 +02:00
fprintf ( Gbl . F . Out , " <td class= \" %s LEFT_TOP %s \" > " , Style , BgColor ) ;
2017-05-02 01:16:06 +02:00
Msg_WriteMsgAuthor ( & UsrDat , Thr . Enabled [ Order ] , BgColor ) ;
2017-05-02 01:05:23 +02:00
fprintf ( Gbl . F . Out , " </td> " ) ;
2014-12-01 23:55:08 +01:00
/* Write the date of first or last message (it's in YYYYMMDDHHMMSS format) */
2015-10-24 20:12:03 +02:00
TimeUTC = Thr . WriteTime [ Order ] ;
UniqueId + + ;
2017-04-17 14:18:57 +02:00
fprintf ( Gbl . F . Out , " <td id= \" thr_date_%u \" class= \" %s LEFT_TOP %s \" > "
2015-10-24 20:12:03 +02:00
" <script type= \" text/javascript \" > "
2017-05-04 17:06:26 +02:00
" writeLocalDateHMSFromUTC('thr_date_%u',%ld, "
2017-05-05 09:41:56 +02:00
" %u,'<br />','%s',true,false,0x6); "
2015-10-24 20:12:03 +02:00
" </script> "
" </td> " ,
UniqueId , Style , BgColor ,
2017-05-04 17:06:26 +02:00
UniqueId , ( long ) TimeUTC ,
( unsigned ) Gbl . Prefs . DateFormat , Txt_Today ) ;
2014-12-01 23:55:08 +01:00
}
else
for ( Column = 1 ;
2017-05-02 01:05:23 +02:00
Column < = 2 ;
2014-12-01 23:55:08 +01:00
Column + + )
2015-09-04 17:43:18 +02:00
fprintf ( Gbl . F . Out , " <td class= \" %s LEFT_TOP %s \" > "
2014-12-22 23:18:56 +01:00
" </td> " ,
2015-09-04 17:43:18 +02:00
Style , BgColor ) ;
2014-12-01 23:55:08 +01:00
}
/***** Write number of posts in this thread *****/
2015-09-04 17:43:18 +02:00
fprintf ( Gbl . F . Out , " <td class= \" %s RIGHT_TOP %s \" > "
2014-12-22 23:18:56 +01:00
" %u "
" </td> " ,
2015-09-04 17:43:18 +02:00
Style , BgColor ,
2014-12-01 23:55:08 +01:00
Thr . NumPosts ) ;
/***** Write number of new posts in this thread *****/
2015-09-04 17:43:18 +02:00
fprintf ( Gbl . F . Out , " <td class= \" %s RIGHT_TOP %s \" > "
2014-12-22 23:18:56 +01:00
" %u "
" </td> " ,
2015-09-04 17:43:18 +02:00
Style , BgColor ,
2014-12-01 23:55:08 +01:00
Thr . NumUnreadPosts ) ;
/***** Write number of users who have write posts in this thread *****/
2015-09-04 17:43:18 +02:00
fprintf ( Gbl . F . Out , " <td class= \" %s RIGHT_TOP %s \" > "
2014-12-22 23:18:56 +01:00
" %u "
" </td> " ,
2015-09-04 17:43:18 +02:00
Style , BgColor ,
2014-12-01 23:55:08 +01:00
Thr . NumWriters ) ;
/***** Write number of users who have read this thread *****/
2015-09-04 17:43:18 +02:00
fprintf ( Gbl . F . Out , " <td class= \" %s RIGHT_TOP %s \" > "
2014-12-22 23:18:56 +01:00
" %u "
" </td> "
2014-12-01 23:55:08 +01:00
" </tr> " ,
2015-09-04 17:43:18 +02:00
Style , BgColor ,
2014-12-01 23:55:08 +01:00
Thr . NumReaders ) ;
}
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor ( & UsrDat ) ;
}
/*****************************************************************************/
/***************************** Get data of a thread **************************/
/*****************************************************************************/
2017-04-13 23:53:57 +02:00
static void For_GetThrData ( struct ForumThread * Thr )
2014-12-01 23:55:08 +01:00
{
extern const char * Txt_no_subject ;
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
MYSQL_RES * mysql_res ;
MYSQL_ROW row ;
unsigned long NumRows ;
2017-01-29 12:42:19 +01:00
For_Order_t Order ;
2014-12-01 23:55:08 +01:00
/***** Get data of a thread from database *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " SELECT m0.PstCod,m1.PstCod,m0.UsrCod,m1.UsrCod, "
" UNIX_TIMESTAMP(m0.CreatTime), "
" UNIX_TIMESTAMP(m1.CreatTime), "
" m0.Subject "
" FROM forum_thread,forum_post AS m0,forum_post AS m1 "
" WHERE forum_thread.ThrCod=%ld "
" AND forum_thread.FirstPstCod=m0.PstCod "
" AND forum_thread.LastPstCod=m1.PstCod " ,
Thr - > ThrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
NumRows = DB_QuerySELECT_free ( Query , & mysql_res , " can not get data of a thread of a forum " ) ;
2014-12-01 23:55:08 +01:00
/***** The result of the query should have one row *****/
if ( NumRows ! = 1 )
Lay_ShowErrorAndExit ( " Error when getting data of a thread of a forum. " ) ;
row = mysql_fetch_row ( mysql_res ) ;
2016-12-30 01:20:49 +01:00
/***** Get the code of the first post in this thread (row[0]) *****/
2017-04-18 20:09:12 +02:00
Thr - > PstCod [ For_FIRST_MSG ] = Str_ConvertStrCodToLongCod ( row [ 0 ] ) ;
2016-12-30 01:20:49 +01:00
/***** Get the code of the last post in this thread (row[1]) *****/
2017-04-18 20:09:12 +02:00
Thr - > PstCod [ For_LAST_MSG ] = Str_ConvertStrCodToLongCod ( row [ 1 ] ) ;
2016-12-30 01:20:49 +01:00
2014-12-01 23:55:08 +01:00
/***** Get the code of the first message in this thread (row[0]) *****/
if ( sscanf ( row [ 0 ] , " %ld " , & ( Thr - > PstCod [ For_FIRST_MSG ] ) ) ! = 1 )
Lay_ShowErrorAndExit ( " Wrong code of post. " ) ;
/***** Get the code of the last message in this thread (row[1]) *****/
if ( sscanf ( row [ 1 ] , " %ld " , & ( Thr - > PstCod [ For_LAST_MSG ] ) ) ! = 1 )
Lay_ShowErrorAndExit ( " Wrong code of post. " ) ;
2016-12-30 01:20:49 +01:00
/***** Get the author of the first post in this thread (row[2]) *****/
2014-12-01 23:55:08 +01:00
Thr - > UsrCod [ For_FIRST_MSG ] = Str_ConvertStrCodToLongCod ( row [ 2 ] ) ;
2016-12-30 01:20:49 +01:00
/***** Get the author of the last post in this thread (row[3]) *****/
Thr - > UsrCod [ For_LAST_MSG ] = Str_ConvertStrCodToLongCod ( row [ 3 ] ) ;
2014-12-01 23:55:08 +01:00
2016-12-30 01:20:49 +01:00
/***** Get the date of the first post in this thread (row[4]) *****/
2015-10-24 20:12:03 +02:00
Thr - > WriteTime [ For_FIRST_MSG ] = Dat_GetUNIXTimeFromStr ( row [ 4 ] ) ;
2014-12-01 23:55:08 +01:00
2016-12-30 01:20:49 +01:00
/***** Get the date of the last post in this thread (row[5]) *****/
2015-10-24 20:12:03 +02:00
Thr - > WriteTime [ For_LAST_MSG ] = Dat_GetUNIXTimeFromStr ( row [ 5 ] ) ;
2014-12-01 23:55:08 +01:00
/***** Get the subject of this thread (row[6]) *****/
2017-01-17 03:10:43 +01:00
Str_Copy ( Thr - > Subject , row [ 6 ] ,
Cns_MAX_BYTES_SUBJECT ) ;
2014-12-01 23:55:08 +01:00
if ( ! Thr - > Subject [ 0 ] )
2018-10-18 02:02:32 +02:00
snprintf ( Thr - > Subject , sizeof ( Thr - > Subject ) ,
" [%s] " ,
Txt_no_subject ) ;
2014-12-01 23:55:08 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult ( & mysql_res ) ;
/***** Get if first or last message are enabled *****/
for ( Order = For_FIRST_MSG ;
Order < = For_LAST_MSG ;
Order + + )
2017-04-18 20:09:12 +02:00
Thr - > Enabled [ Order ] = For_GetIfPstIsEnabled ( Thr - > PstCod [ Order ] ) ;
// Thr->Enabled[Order] = true;
2014-12-01 23:55:08 +01:00
/***** Get number of posts in this thread *****/
Thr - > NumPosts = For_GetNumPstsInThr ( Thr - > ThrCod ) ;
/***** Get number of unread (by me) posts in this thread *****/
Thr - > NumUnreadPosts = For_GetNumOfUnreadPostsInThr ( Thr - > ThrCod , Thr - > NumPosts ) ;
/***** Get number of posts that I have written in this thread *****/
Thr - > NumMyPosts = For_GetNumMyPstInThr ( Thr - > ThrCod ) ;
/***** Get number of users who have write posts in this thread *****/
Thr - > NumWriters = For_GetNumOfWritersInThr ( Thr - > ThrCod ) ;
/***** Get number of users who have read this thread *****/
Thr - > NumReaders = For_GetNumOfReadersOfThr ( Thr - > ThrCod ) ;
}
/*****************************************************************************/
/**************** Show posts of a thread in a discussion forum ***************/
/*****************************************************************************/
2017-04-18 16:44:44 +02:00
void For_ShowThreadPosts ( void )
2014-12-01 23:55:08 +01:00
{
2017-04-16 13:45:11 +02:00
/***** Get parameters related to forum *****/
2014-12-01 23:55:08 +01:00
For_GetParamsForum ( ) ;
2017-04-18 13:17:40 +02:00
/***** Show forum list again *****/
For_ShowForumList ( ) ;
/***** Show threads again *****/
For_ShowForumThreadsHighlightingOneThread ( Gbl . Forum . ForumSelected . ThrCod ,
2017-05-11 23:45:46 +02:00
Ale_SUCCESS , NULL ) ;
2017-04-18 13:17:40 +02:00
2014-12-01 23:55:08 +01:00
/***** Show the posts of that thread *****/
2017-05-11 23:45:46 +02:00
For_ShowPostsOfAThread ( Ale_SUCCESS , NULL ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Get parameters related to a forum *********************/
/*****************************************************************************/
2017-02-24 03:38:18 +01:00
static void For_GetParamsForum ( void )
2014-12-01 23:55:08 +01:00
{
2017-04-16 13:45:11 +02:00
/***** Set forum type *****/
For_SetForumType ( ) ;
2017-04-16 13:54:02 +02:00
/***** Get parameter with code of course, degree, centre or institution *****/
2017-04-18 01:25:44 +02:00
switch ( Gbl . Forum . ForumSelected . Type )
2017-04-16 13:54:02 +02:00
{
case For_FORUM_INSTIT_USRS :
case For_FORUM_INSTIT_TCHS :
2017-04-18 19:55:56 +02:00
case For_FORUM_CENTRE_USRS :
case For_FORUM_CENTRE_TCHS :
case For_FORUM_DEGREE_USRS :
case For_FORUM_DEGREE_TCHS :
case For_FORUM_COURSE_USRS :
case For_FORUM_COURSE_TCHS :
2017-04-18 01:25:44 +02:00
Gbl . Forum . ForumSelected . Location = Par_GetParToLong ( " Location " ) ;
2017-04-16 13:54:02 +02:00
break ;
default :
2017-04-18 01:25:44 +02:00
Gbl . Forum . ForumSelected . Location = - 1L ;
2017-04-16 13:54:02 +02:00
break ;
}
2017-04-17 19:03:21 +02:00
/***** Get optional parameter with code of a selected thread *****/
2017-04-18 01:25:44 +02:00
Gbl . Forum . ForumSelected . ThrCod = Par_GetParToLong ( " ThrCod " ) ;
/***** Get optional parameter with code of a selected post *****/
Gbl . Forum . ForumSelected . PstCod = Par_GetParToLong ( " PstCod " ) ;
2017-04-17 19:03:21 +02:00
2017-04-16 13:45:11 +02:00
/***** Get which forums I want to see *****/
2017-04-17 11:57:55 +02:00
Gbl . Forum . ForumSet = ( For_ForumSet_t )
2017-04-17 19:03:21 +02:00
Par_GetParToUnsignedLong ( " ForumSet " ,
0 ,
For_NUM_FORUM_SETS - 1 ,
( unsigned long ) For_DEFAULT_FORUM_SET ) ;
2017-04-16 13:45:11 +02:00
/***** Get order type *****/
2017-04-18 13:17:40 +02:00
Gbl . Forum . ThreadsOrder = ( For_Order_t )
2017-04-16 13:45:11 +02:00
Par_GetParToUnsignedLong ( " Order " ,
0 ,
For_NUM_ORDERS - 1 ,
( unsigned long ) For_DEFAULT_ORDER ) ;
2017-04-18 13:17:40 +02:00
/***** Get optional page numbers for threads and posts *****/
Gbl . Forum . CurrentPageThrs = Pag_GetParamPagNum ( Pag_THREADS_FORUM ) ;
Gbl . Forum . CurrentPagePsts = Pag_GetParamPagNum ( Pag_POSTS_FORUM ) ;
2017-04-16 13:45:11 +02:00
/***** Restrict access to forum *****/
For_RestrictAccess ( ) ;
}
2017-04-14 00:27:38 +02:00
2017-04-16 13:45:11 +02:00
/*****************************************************************************/
/***************************** Set the type of forum *************************/
/*****************************************************************************/
static void For_SetForumType ( void )
{
switch ( Gbl . Action . Act )
{
case ActSeeFor :
case ActSeeForGenUsr : case ActSeePstForGenUsr :
case ActRcvThrForGenUsr : case ActRcvRepForGenUsr :
case ActReqDelThrGenUsr : case ActDelThrForGenUsr :
case ActCutThrForGenUsr : case ActPasThrForGenUsr :
case ActDelPstForGenUsr :
case ActEnbPstForGenUsr : case ActDisPstForGenUsr :
2017-04-18 01:25:44 +02:00
Gbl . Forum . ForumSelected . Type = For_FORUM_GLOBAL_USRS ;
2017-04-16 13:45:11 +02:00
break ;
case ActSeeForGenTch : case ActSeePstForGenTch :
case ActRcvThrForGenTch : case ActRcvRepForGenTch :
case ActReqDelThrGenTch : case ActDelThrForGenTch :
case ActCutThrForGenTch : case ActPasThrForGenTch :
case ActDelPstForGenTch :
case ActEnbPstForGenTch : case ActDisPstForGenTch :
2017-04-18 01:25:44 +02:00
Gbl . Forum . ForumSelected . Type = For_FORUM_GLOBAL_TCHS ;
2017-04-16 13:45:11 +02:00
break ;
case ActSeeForSWAUsr : case ActSeePstForSWAUsr :
case ActRcvThrForSWAUsr : case ActRcvRepForSWAUsr :
case ActReqDelThrSWAUsr : case ActDelThrForSWAUsr :
case ActCutThrForSWAUsr : case ActPasThrForSWAUsr :
case ActDelPstForSWAUsr :
case ActEnbPstForSWAUsr : case ActDisPstForSWAUsr :
2017-04-18 19:55:56 +02:00
Gbl . Forum . ForumSelected . Type = For_FORUM__SWAD__USRS ;
2017-04-16 13:45:11 +02:00
break ;
case ActSeeForSWATch : case ActSeePstForSWATch :
case ActRcvThrForSWATch : case ActRcvRepForSWATch :
case ActReqDelThrSWATch : case ActDelThrForSWATch :
case ActCutThrForSWATch : case ActPasThrForSWATch :
case ActDelPstForSWATch :
case ActEnbPstForSWATch : case ActDisPstForSWATch :
2017-04-18 19:55:56 +02:00
Gbl . Forum . ForumSelected . Type = For_FORUM__SWAD__TCHS ;
2017-04-16 13:45:11 +02:00
break ;
case ActSeeForInsUsr : case ActSeePstForInsUsr :
case ActRcvThrForInsUsr : case ActRcvRepForInsUsr :
case ActReqDelThrInsUsr : case ActDelThrForInsUsr :
case ActCutThrForInsUsr : case ActPasThrForInsUsr :
case ActDelPstForInsUsr :
case ActEnbPstForInsUsr : case ActDisPstForInsUsr :
2017-04-18 01:25:44 +02:00
Gbl . Forum . ForumSelected . Type = For_FORUM_INSTIT_USRS ;
2017-04-16 13:45:11 +02:00
break ;
case ActSeeForInsTch : case ActSeePstForInsTch :
case ActRcvThrForInsTch : case ActRcvRepForInsTch :
case ActReqDelThrInsTch : case ActDelThrForInsTch :
case ActCutThrForInsTch : case ActPasThrForInsTch :
case ActDelPstForInsTch :
case ActEnbPstForInsTch : case ActDisPstForInsTch :
2017-04-18 01:25:44 +02:00
Gbl . Forum . ForumSelected . Type = For_FORUM_INSTIT_TCHS ;
2017-04-16 13:45:11 +02:00
break ;
case ActSeeForCtrUsr : case ActSeePstForCtrUsr :
case ActRcvThrForCtrUsr : case ActRcvRepForCtrUsr :
case ActReqDelThrCtrUsr : case ActDelThrForCtrUsr :
case ActCutThrForCtrUsr : case ActPasThrForCtrUsr :
case ActDelPstForCtrUsr :
case ActEnbPstForCtrUsr : case ActDisPstForCtrUsr :
2017-04-18 01:25:44 +02:00
Gbl . Forum . ForumSelected . Type = For_FORUM_CENTRE_USRS ;
2017-04-16 13:45:11 +02:00
break ;
case ActSeeForCtrTch : case ActSeePstForCtrTch :
case ActRcvThrForCtrTch : case ActRcvRepForCtrTch :
case ActReqDelThrCtrTch : case ActDelThrForCtrTch :
case ActCutThrForCtrTch : case ActPasThrForCtrTch :
case ActDelPstForCtrTch :
case ActEnbPstForCtrTch : case ActDisPstForCtrTch :
2017-04-18 01:25:44 +02:00
Gbl . Forum . ForumSelected . Type = For_FORUM_CENTRE_TCHS ;
2017-04-16 13:45:11 +02:00
break ;
case ActSeeForDegUsr : case ActSeePstForDegUsr :
case ActRcvThrForDegUsr : case ActRcvRepForDegUsr :
case ActReqDelThrDegUsr : case ActDelThrForDegUsr :
case ActCutThrForDegUsr : case ActPasThrForDegUsr :
case ActDelPstForDegUsr :
case ActEnbPstForDegUsr : case ActDisPstForDegUsr :
2017-04-18 01:25:44 +02:00
Gbl . Forum . ForumSelected . Type = For_FORUM_DEGREE_USRS ;
2017-04-16 13:45:11 +02:00
break ;
case ActSeeForDegTch : case ActSeePstForDegTch :
case ActRcvThrForDegTch : case ActRcvRepForDegTch :
case ActReqDelThrDegTch : case ActDelThrForDegTch :
case ActCutThrForDegTch : case ActPasThrForDegTch :
case ActDelPstForDegTch :
case ActEnbPstForDegTch : case ActDisPstForDegTch :
2017-04-18 01:25:44 +02:00
Gbl . Forum . ForumSelected . Type = For_FORUM_DEGREE_TCHS ;
2017-04-16 13:45:11 +02:00
break ;
case ActSeeForCrsUsr : case ActSeePstForCrsUsr :
case ActRcvThrForCrsUsr : case ActRcvRepForCrsUsr :
case ActReqDelThrCrsUsr : case ActDelThrForCrsUsr :
case ActCutThrForCrsUsr : case ActPasThrForCrsUsr :
case ActDelPstForCrsUsr :
case ActEnbPstForCrsUsr : case ActDisPstForCrsUsr :
2017-04-18 01:25:44 +02:00
Gbl . Forum . ForumSelected . Type = For_FORUM_COURSE_USRS ;
2017-04-16 13:45:11 +02:00
break ;
case ActSeeForCrsTch : case ActSeePstForCrsTch :
case ActRcvThrForCrsTch : case ActRcvRepForCrsTch :
case ActReqDelThrCrsTch : case ActDelThrForCrsTch :
case ActCutThrForCrsTch : case ActPasThrForCrsTch :
case ActDelPstForCrsTch :
case ActEnbPstForCrsTch : case ActDisPstForCrsTch :
2017-04-18 01:25:44 +02:00
Gbl . Forum . ForumSelected . Type = For_FORUM_COURSE_TCHS ;
2017-04-16 13:45:11 +02:00
break ;
2017-04-18 19:55:56 +02:00
default :
Gbl . Forum . ForumSelected . Type = For_FORUM_UNKNOWN ;
2017-04-14 00:27:38 +02:00
}
2014-12-01 23:55:08 +01:00
}
2017-04-16 13:45:11 +02:00
/*****************************************************************************/
/************************** Restrict access to forum *************************/
/*****************************************************************************/
static void For_RestrictAccess ( void )
{
extern const char * Txt_You_dont_have_permission_to_access_to_this_forum ;
2017-05-23 20:42:38 +02:00
Rol_Role_t MaxRole ;
2017-04-18 19:55:56 +02:00
bool ICanSeeForum ;
2017-04-16 13:45:11 +02:00
/***** Restrict access *****/
2017-04-18 01:25:44 +02:00
switch ( Gbl . Forum . ForumSelected . Type )
2017-04-16 13:45:11 +02:00
{
2017-04-18 19:55:56 +02:00
case For_FORUM_GLOBAL_USRS :
case For_FORUM__SWAD__USRS :
ICanSeeForum = true ;
2017-04-16 13:45:11 +02:00
break ;
2017-04-18 19:55:56 +02:00
case For_FORUM_GLOBAL_TCHS :
case For_FORUM__SWAD__TCHS :
Rol_GetRolesInAllCrssIfNotYetGot ( & Gbl . Usrs . Me . UsrDat ) ;
2017-06-08 15:32:33 +02:00
ICanSeeForum = ( Gbl . Usrs . Me . UsrDat . Roles . InCrss & ( ( 1 < < Rol_NET ) |
2017-05-23 20:42:38 +02:00
( 1 < < Rol_TCH ) ) ) ;
2017-04-16 13:45:11 +02:00
break ;
2017-04-18 19:55:56 +02:00
case For_FORUM_INSTIT_USRS :
2017-05-23 20:42:38 +02:00
MaxRole = Rol_GetMyMaxRoleInIns ( Gbl . Forum . ForumSelected . Location ) ;
2017-06-04 18:18:54 +02:00
ICanSeeForum = ( Gbl . Usrs . Me . Role . Logged = = Rol_SYS_ADM | |
2017-05-23 20:42:38 +02:00
MaxRole = = Rol_STD | |
MaxRole = = Rol_NET | |
MaxRole = = Rol_TCH ) ;
2017-04-16 13:45:11 +02:00
break ;
2017-04-18 19:55:56 +02:00
case For_FORUM_INSTIT_TCHS :
2017-05-23 20:42:38 +02:00
MaxRole = Rol_GetMyMaxRoleInIns ( Gbl . Forum . ForumSelected . Location ) ;
2017-06-04 18:18:54 +02:00
ICanSeeForum = ( Gbl . Usrs . Me . Role . Logged = = Rol_SYS_ADM | |
2017-05-23 20:42:38 +02:00
MaxRole = = Rol_NET | |
MaxRole = = Rol_TCH ) ;
2017-04-16 13:45:11 +02:00
break ;
case For_FORUM_CENTRE_USRS :
2017-05-23 20:42:38 +02:00
MaxRole = Rol_GetMyMaxRoleInCtr ( Gbl . Forum . ForumSelected . Location ) ;
2017-06-04 18:18:54 +02:00
ICanSeeForum = ( Gbl . Usrs . Me . Role . Logged = = Rol_SYS_ADM | |
2017-05-23 20:42:38 +02:00
MaxRole > = Rol_STD | |
MaxRole = = Rol_NET | |
MaxRole = = Rol_TCH ) ;
2017-04-16 13:45:11 +02:00
break ;
case For_FORUM_CENTRE_TCHS :
2017-05-23 20:42:38 +02:00
MaxRole = Rol_GetMyMaxRoleInCtr ( Gbl . Forum . ForumSelected . Location ) ;
2017-06-04 18:18:54 +02:00
ICanSeeForum = ( Gbl . Usrs . Me . Role . Logged = = Rol_SYS_ADM | |
2017-05-23 20:42:38 +02:00
MaxRole = = Rol_NET | |
MaxRole = = Rol_TCH ) ;
2017-04-16 13:45:11 +02:00
break ;
2017-04-18 19:55:56 +02:00
case For_FORUM_DEGREE_USRS :
2017-05-23 20:42:38 +02:00
MaxRole = Rol_GetMyMaxRoleInDeg ( Gbl . Forum . ForumSelected . Location ) ;
2017-06-04 18:18:54 +02:00
ICanSeeForum = ( Gbl . Usrs . Me . Role . Logged = = Rol_SYS_ADM | |
2017-05-23 20:42:38 +02:00
MaxRole > = Rol_STD | |
MaxRole = = Rol_NET | |
MaxRole = = Rol_TCH ) ;
2017-04-16 13:45:11 +02:00
break ;
2017-04-18 19:55:56 +02:00
case For_FORUM_DEGREE_TCHS :
2017-05-23 20:42:38 +02:00
MaxRole = Rol_GetMyMaxRoleInDeg ( Gbl . Forum . ForumSelected . Location ) ;
2017-06-04 18:18:54 +02:00
ICanSeeForum = ( Gbl . Usrs . Me . Role . Logged = = Rol_SYS_ADM | |
2017-05-23 20:42:38 +02:00
MaxRole = = Rol_NET | |
MaxRole = = Rol_TCH ) ;
2017-04-16 13:45:11 +02:00
break ;
2017-04-18 19:55:56 +02:00
case For_FORUM_COURSE_USRS :
2017-05-23 20:42:38 +02:00
MaxRole = Rol_GetMyRoleInCrs ( Gbl . Forum . ForumSelected . Location ) ;
2017-06-04 18:18:54 +02:00
ICanSeeForum = ( Gbl . Usrs . Me . Role . Logged = = Rol_SYS_ADM | |
2017-05-23 20:42:38 +02:00
MaxRole > = Rol_STD | |
MaxRole = = Rol_NET | |
MaxRole = = Rol_TCH ) ;
2017-04-16 13:45:11 +02:00
break ;
2017-04-18 19:55:56 +02:00
case For_FORUM_COURSE_TCHS :
2017-05-23 20:42:38 +02:00
MaxRole = Rol_GetMyRoleInCrs ( Gbl . Forum . ForumSelected . Location ) ;
2017-06-04 18:18:54 +02:00
ICanSeeForum = ( Gbl . Usrs . Me . Role . Logged = = Rol_SYS_ADM | |
2017-05-23 20:42:38 +02:00
MaxRole = = Rol_NET | |
MaxRole = = Rol_TCH ) ;
2017-04-16 13:45:11 +02:00
break ;
2017-04-18 19:55:56 +02:00
default :
ICanSeeForum = false ;
break ;
2017-04-16 13:45:11 +02:00
}
if ( ! ICanSeeForum )
Lay_ShowErrorAndExit ( Txt_You_dont_have_permission_to_access_to_this_forum ) ;
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/********************** Show an area to write a message **********************/
/*****************************************************************************/
2017-04-18 01:25:44 +02:00
static void For_WriteFormForumPst ( bool IsReply , const char * Subject )
2014-12-01 23:55:08 +01:00
{
2017-04-19 14:27:52 +02:00
extern const char * Hlp_SOCIAL_Forums_new_post ;
extern const char * Hlp_SOCIAL_Forums_new_thread ;
2015-07-27 21:25:45 +02:00
extern const char * The_ClassForm [ The_NUM_THEMES ] ;
2017-04-17 14:18:57 +02:00
extern const char * Txt_New_post ;
2014-12-01 23:55:08 +01:00
extern const char * Txt_New_thread ;
extern const char * Txt_MSG_Subject ;
2017-04-19 14:27:52 +02:00
extern const char * Txt_MSG_Content ;
2017-04-17 14:18:57 +02:00
extern const char * Txt_Send ;
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** Start box *****/
2017-06-11 22:26:40 +02:00
if ( IsReply )
Box_StartBox ( NULL , Txt_New_post , NULL ,
2017-06-12 15:03:29 +02:00
Hlp_SOCIAL_Forums_new_post , Box_NOT_CLOSABLE ) ;
2017-06-11 22:26:40 +02:00
else
Box_StartBox ( NULL , Txt_New_thread , NULL ,
2017-06-12 15:03:29 +02:00
Hlp_SOCIAL_Forums_new_thread , Box_NOT_CLOSABLE ) ;
2016-04-09 18:23:15 +02:00
/***** Start form *****/
2017-04-19 14:43:08 +02:00
if ( IsReply ) // Form to write a reply to a post of an existing thread
2014-12-01 23:55:08 +01:00
{
2018-10-15 14:07:12 +02:00
Act_StartFormAnchor ( For_ActionsRecRepFor [ Gbl . Forum . ForumSelected . Type ] ,
2017-05-25 13:43:54 +02:00
For_FORUM_POSTS_SECTION_ID ) ;
2017-04-19 14:43:08 +02:00
For_PutAllHiddenParamsNewPost ( ) ;
2014-12-01 23:55:08 +01:00
}
2017-04-19 14:43:08 +02:00
else // Form to write the first post of a new thread
2017-04-18 01:25:44 +02:00
{
2018-10-15 14:07:12 +02:00
Act_StartFormAnchor ( For_ActionsRecThrFor [ Gbl . Forum . ForumSelected . Type ] ,
2017-05-25 13:43:54 +02:00
For_FORUM_POSTS_SECTION_ID ) ;
2017-04-19 14:43:08 +02:00
For_PutAllHiddenParamsNewThread ( ) ;
2017-04-18 01:25:44 +02:00
}
2014-12-01 23:55:08 +01:00
2016-12-27 11:45:06 +01:00
/***** Subject and content *****/
2017-06-11 20:09:59 +02:00
Tbl_StartTableCenter ( 2 ) ;
2017-03-07 01:56:41 +01:00
2017-05-01 12:36:24 +02:00
// If writing a reply to a message of an existing thread ==> write subject
2017-03-07 01:56:41 +01:00
/* Subject */
fprintf ( Gbl . F . Out , " <tr> "
2017-04-18 16:44:44 +02:00
" <td class= \" RIGHT_MIDDLE \" > "
" <label for= \" Subject \" class= \" %s \" >%s:</label> "
" </td> "
" <td class= \" LEFT_MIDDLE \" > "
" <input type= \" text \" id= \" Subject \" name= \" Subject \" "
" class= \" MSG_SUBJECT \" "
" maxlength= \" %u \" value= \" %s \" "
" required= \" required \" /> "
" </td> "
" </tr> " ,
The_ClassForm [ Gbl . Prefs . Theme ] , Txt_MSG_Subject ,
Cns_MAX_CHARS_SUBJECT ,
IsReply ? Subject :
" " ) ;
2017-03-07 01:56:41 +01:00
/* Content */
fprintf ( Gbl . F . Out , " <tr> "
" <td class= \" RIGHT_TOP \" > "
2017-04-13 20:09:22 +02:00
" <label for= \" Content \" class= \" %s \" >%s:</label> "
2017-03-07 01:56:41 +01:00
" </td> "
" <td class= \" LEFT_TOP \" > "
" <textarea id= \" Content \" name= \" Content \" "
2017-04-13 20:09:22 +02:00
" class= \" MSG_CONTENT \" "
" rows= \" 10 \" > "
2017-03-07 01:56:41 +01:00
" </textarea> "
" </td> "
" </tr> " ,
2017-04-19 14:27:52 +02:00
The_ClassForm [ Gbl . Prefs . Theme ] , Txt_MSG_Content ) ;
2017-03-07 01:56:41 +01:00
2017-06-11 20:09:59 +02:00
Tbl_EndTable ( ) ;
2016-04-09 18:15:54 +02:00
2015-04-11 23:46:21 +02:00
/***** Help for text editor *****/
2015-04-11 14:00:23 +02:00
Lay_HelpPlainEditor ( ) ;
2016-04-10 14:09:50 +02:00
/***** Attached image (optional) *****/
2016-04-15 14:30:28 +02:00
Img_PutImageUploader ( - 1 , " FOR_IMG_TIT_URL " ) ;
2016-04-10 14:09:50 +02:00
2016-04-09 18:23:15 +02:00
/***** Send button *****/
2017-06-11 19:02:40 +02:00
Btn_PutCreateButton ( Txt_Send ) ;
2015-04-11 14:00:23 +02:00
/***** End form *****/
2018-10-15 14:07:12 +02:00
Act_EndForm ( ) ;
2016-04-09 18:23:15 +02:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2017-06-10 21:38:10 +02:00
Box_EndBox ( ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************** Receive message of a forum ***********************/
/*****************************************************************************/
2017-04-18 16:44:44 +02:00
void For_ReceiveForumPost ( void )
2014-12-01 23:55:08 +01:00
{
extern const char * Txt_Post_sent ;
2017-04-18 16:44:44 +02:00
bool IsReply = false ;
2014-12-01 23:55:08 +01:00
long PstCod = 0 ;
unsigned NumUsrsToBeNotifiedByEMail ;
2016-01-25 11:43:14 +01:00
struct SocialPublishing SocPub ;
2017-01-28 15:58:46 +01:00
char Content [ Cns_MAX_BYTES_LONG_TEXT + 1 ] ;
2016-04-10 14:09:50 +02:00
struct Image Image ;
2014-12-01 23:55:08 +01:00
2017-04-16 13:45:11 +02:00
/***** Get parameters related to forum *****/
2014-12-01 23:55:08 +01:00
For_GetParamsForum ( ) ;
/***** Get the code of the thread y the n<> mero of page *****/
2016-01-17 15:10:54 +01:00
if ( Gbl . Action . Act = = ActRcvRepForCrsUsr | | Gbl . Action . Act = = ActRcvRepForCrsTch | |
Gbl . Action . Act = = ActRcvRepForDegUsr | | Gbl . Action . Act = = ActRcvRepForDegTch | |
Gbl . Action . Act = = ActRcvRepForCtrUsr | | Gbl . Action . Act = = ActRcvRepForCtrTch | |
Gbl . Action . Act = = ActRcvRepForInsUsr | | Gbl . Action . Act = = ActRcvRepForInsTch | |
Gbl . Action . Act = = ActRcvRepForGenUsr | | Gbl . Action . Act = = ActRcvRepForGenTch | |
Gbl . Action . Act = = ActRcvRepForSWAUsr | | Gbl . Action . Act = = ActRcvRepForSWATch )
2017-04-18 16:44:44 +02:00
IsReply = true ;
2014-12-01 23:55:08 +01:00
/***** Get message subject *****/
Par_GetParToHTML ( " Subject " , Gbl . Msg . Subject , Cns_MAX_BYTES_SUBJECT ) ;
/***** Get message body *****/
Par_GetParAndChangeFormat ( " Content " , Content , Cns_MAX_BYTES_LONG_TEXT ,
Str_TO_RIGOROUS_HTML , false ) ;
2016-04-10 14:09:50 +02:00
/***** Initialize image *****/
Img_ImageConstructor ( & Image ) ;
/***** Get attached image (action, file and title) *****/
2016-04-14 19:19:55 +02:00
Image . Width = For_IMAGE_SAVED_MAX_WIDTH ;
Image . Height = For_IMAGE_SAVED_MAX_HEIGHT ;
Image . Quality = For_IMAGE_SAVED_QUALITY ;
2016-04-14 21:33:24 +02:00
Img_GetImageFromForm ( - 1 , & Image , NULL ) ;
2016-04-10 14:09:50 +02:00
2014-12-01 23:55:08 +01:00
/***** Create a new message *****/
2017-04-18 16:44:44 +02:00
if ( IsReply ) // This post is a reply to another posts in the thread
2014-12-01 23:55:08 +01:00
{
2017-04-18 01:25:44 +02:00
// Gbl.Forum.ForumSelected.ThrCod has been received from form
2014-12-01 23:55:08 +01:00
/***** Create last message of the thread *****/
2017-04-18 01:25:44 +02:00
PstCod = For_InsertForumPst ( Gbl . Forum . ForumSelected . ThrCod , Gbl . Usrs . Me . UsrDat . UsrCod ,
2016-04-10 19:19:20 +02:00
Gbl . Msg . Subject , Content , & Image ) ;
2014-12-01 23:55:08 +01:00
/***** Modify last message of the thread *****/
2017-04-18 01:25:44 +02:00
For_UpdateThrLastPst ( Gbl . Forum . ForumSelected . ThrCod , PstCod ) ;
2014-12-01 23:55:08 +01:00
}
2016-04-10 19:19:20 +02:00
else // This post is the first of a new thread
2014-12-01 23:55:08 +01:00
{
/***** Create new thread with unknown first and last message codes *****/
2017-04-19 12:34:38 +02:00
Gbl . Forum . ForumSelected . ThrCod = For_InsertForumThread ( - 1L ) ;
2014-12-01 23:55:08 +01:00
/***** Create first (and last) message of the thread *****/
2017-04-18 01:25:44 +02:00
PstCod = For_InsertForumPst ( Gbl . Forum . ForumSelected . ThrCod , Gbl . Usrs . Me . UsrDat . UsrCod ,
2016-04-10 19:19:20 +02:00
Gbl . Msg . Subject , Content , & Image ) ;
2014-12-01 23:55:08 +01:00
/***** Update first and last posts of new thread *****/
2017-04-18 01:25:44 +02:00
For_UpdateThrFirstAndLastPst ( Gbl . Forum . ForumSelected . ThrCod , PstCod , PstCod ) ;
2014-12-01 23:55:08 +01:00
}
2016-04-10 14:09:50 +02:00
/***** Free image *****/
Img_ImageDestructor ( & Image ) ;
2015-03-11 12:38:47 +01:00
/***** Increment number of forum posts in my user's figures *****/
2015-03-14 17:39:04 +01:00
Prf_IncrementNumForPstUsr ( Gbl . Usrs . Me . UsrDat . UsrCod ) ;
2015-03-11 12:38:47 +01:00
2014-12-01 23:55:08 +01:00
/***** Notify the new post to users in course *****/
2017-04-18 01:25:44 +02:00
switch ( Gbl . Forum . ForumSelected . Type )
2014-12-01 23:55:08 +01:00
{
case For_FORUM_COURSE_USRS :
case For_FORUM_COURSE_TCHS :
if ( ( NumUsrsToBeNotifiedByEMail = Ntf_StoreNotifyEventsToAllUsrs ( Ntf_EVENT_FORUM_POST_COURSE , PstCod ) ) )
For_UpdateNumUsrsNotifiedByEMailAboutPost ( PstCod , NumUsrsToBeNotifiedByEMail ) ;
break ;
default :
break ;
}
/***** Notify the new post to previous writers in this thread *****/
2017-04-18 16:44:44 +02:00
if ( IsReply )
2014-12-01 23:55:08 +01:00
if ( ( NumUsrsToBeNotifiedByEMail = Ntf_StoreNotifyEventsToAllUsrs ( Ntf_EVENT_FORUM_REPLY , PstCod ) ) )
For_UpdateNumUsrsNotifiedByEMailAboutPost ( PstCod , NumUsrsToBeNotifiedByEMail ) ;
2015-12-31 14:25:28 +01:00
/***** Insert forum post into public social activity *****/
2017-04-18 01:25:44 +02:00
switch ( Gbl . Forum . ForumSelected . Type ) // Only if forum is public for any logged user
2015-12-28 20:46:48 +01:00
{
case For_FORUM_GLOBAL_USRS :
2017-04-18 19:55:56 +02:00
case For_FORUM__SWAD__USRS :
2016-01-25 11:43:14 +01:00
Soc_StoreAndPublishSocialNote ( Soc_NOTE_FORUM_POST , PstCod , & SocPub ) ;
2015-12-28 20:46:48 +01:00
break ;
default :
break ;
}
2017-04-18 13:17:40 +02:00
/***** Show forum list again *****/
For_ShowForumList ( ) ;
/***** Show threads again *****/
For_ShowForumThreadsHighlightingOneThread ( Gbl . Forum . ForumSelected . ThrCod ,
2017-05-11 23:45:46 +02:00
Ale_SUCCESS , NULL ) ;
2017-04-18 13:17:40 +02:00
2014-12-01 23:55:08 +01:00
/***** Show again the posts of this thread of the forum *****/
2017-05-11 23:45:46 +02:00
For_ShowPostsOfAThread ( Ale_SUCCESS , Txt_Post_sent ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********* Update number of users notified in table of forum posts **********/
/*****************************************************************************/
static void For_UpdateNumUsrsNotifiedByEMailAboutPost ( long PstCod , unsigned NumUsrsToBeNotifiedByEMail )
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
/***** Update number of users notified *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " UPDATE forum_post SET NumNotif=NumNotif+%u "
" WHERE PstCod=%ld " ,
NumUsrsToBeNotifiedByEMail , PstCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
DB_QueryUPDATE_free ( Query , " can not update the number of notifications of a post " ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/***************************** Delete a forum post ***************************/
/*****************************************************************************/
2017-04-18 16:44:44 +02:00
void For_RemovePost ( void )
2014-12-01 23:55:08 +01:00
{
extern const char * Txt_Post_and_thread_removed ;
extern const char * Txt_Post_removed ;
struct UsrData UsrDat ;
2015-10-24 20:12:03 +02:00
time_t CreatTimeUTC ; // Creation time of a message
2017-01-28 15:58:46 +01:00
char Subject [ Cns_MAX_BYTES_SUBJECT + 1 ] ;
char OriginalContent [ Cns_MAX_BYTES_LONG_TEXT + 1 ] ;
2016-04-10 23:59:45 +02:00
struct Image Image ;
2018-10-10 23:56:42 +02:00
bool ItsMe ;
2014-12-01 23:55:08 +01:00
bool ThreadDeleted = false ;
2017-04-16 13:45:11 +02:00
/***** Get parameters related to forum *****/
2014-12-01 23:55:08 +01:00
For_GetParamsForum ( ) ;
2016-04-10 23:59:45 +02:00
/***** Initialize image *****/
Img_ImageConstructor ( & Image ) ;
/***** Get forum post data *****/
2017-04-18 01:25:44 +02:00
For_GetPstData ( Gbl . Forum . ForumSelected . PstCod , & UsrDat . UsrCod , & CreatTimeUTC ,
2016-04-10 23:59:45 +02:00
Subject , OriginalContent , & Image ) ;
/***** Check if I can remove the post *****/
2014-12-01 23:55:08 +01:00
/* Check if the message really exists, if it has not been removed */
2017-04-18 01:25:44 +02:00
if ( ! For_GetIfForumPstExists ( Gbl . Forum . ForumSelected . PstCod ) )
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ( " The post to remove no longer exists. " ) ;
/* Check if I am the author of the message */
2018-10-10 23:56:42 +02:00
ItsMe = Usr_ItsMe ( UsrDat . UsrCod ) ;
if ( ! ItsMe )
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ( " You can not remove post because you aren't the author. " ) ;
/* Check if the message is the last message in the thread */
2017-04-18 01:25:44 +02:00
if ( Gbl . Forum . ForumSelected . PstCod ! = For_GetLastPstCod ( Gbl . Forum . ForumSelected . ThrCod ) )
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ( " You can not remove post because it is not the last of the thread. " ) ;
2016-04-10 23:59:45 +02:00
/***** Remove the post *****/
2017-04-18 01:25:44 +02:00
ThreadDeleted = For_RemoveForumPst ( Gbl . Forum . ForumSelected . PstCod , & Image ) ;
2016-04-10 23:59:45 +02:00
/***** Free image *****/
Img_ImageDestructor ( & Image ) ;
2014-12-01 23:55:08 +01:00
/***** Mark possible notifications as removed *****/
2017-04-18 01:25:44 +02:00
Ntf_MarkNotifAsRemoved ( Ntf_EVENT_FORUM_POST_COURSE , Gbl . Forum . ForumSelected . PstCod ) ;
Ntf_MarkNotifAsRemoved ( Ntf_EVENT_FORUM_REPLY , Gbl . Forum . ForumSelected . PstCod ) ;
2014-12-01 23:55:08 +01:00
2016-01-03 19:45:15 +01:00
/***** Mark possible social note as unavailable *****/
2017-04-18 01:25:44 +02:00
switch ( Gbl . Forum . ForumSelected . Type ) // Only if forum is public for any logged user
2016-01-03 19:45:15 +01:00
{
case For_FORUM_GLOBAL_USRS :
2017-04-18 19:55:56 +02:00
case For_FORUM__SWAD__USRS :
2017-04-18 01:25:44 +02:00
Soc_MarkSocialNoteAsUnavailableUsingNoteTypeAndCod ( Soc_NOTE_FORUM_POST , Gbl . Forum . ForumSelected . PstCod ) ;
2016-01-03 19:45:15 +01:00
break ;
default :
break ;
}
2017-04-18 13:17:40 +02:00
/***** Show forum list again *****/
For_ShowForumList ( ) ;
2014-12-01 23:55:08 +01:00
if ( ThreadDeleted )
2017-04-18 13:17:40 +02:00
/***** Show the remaining threads *****/
2017-04-18 09:55:25 +02:00
For_ShowForumThreadsHighlightingOneThread ( Gbl . Forum . ForumSelected . ThrCod ,
2017-05-11 23:45:46 +02:00
Ale_SUCCESS , Txt_Post_and_thread_removed ) ;
2014-12-01 23:55:08 +01:00
else
2017-04-18 13:17:40 +02:00
{
/***** Show threads again *****/
For_ShowForumThreadsHighlightingOneThread ( Gbl . Forum . ForumSelected . ThrCod ,
2017-05-11 23:45:46 +02:00
Ale_SUCCESS , NULL ) ;
2017-04-18 13:17:40 +02:00
/***** Show the remaining posts *****/
2017-05-11 23:45:46 +02:00
For_ShowPostsOfAThread ( Ale_SUCCESS , Txt_Post_removed ) ;
2017-04-18 13:17:40 +02:00
}
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2017-04-18 01:25:44 +02:00
/***************** Request the removing of an existing thread ****************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2017-04-18 16:44:44 +02:00
void For_RequestRemoveThread ( void )
2014-12-01 23:55:08 +01:00
{
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 ;
2017-01-17 03:10:43 +01:00
char Subject [ Cns_MAX_BYTES_SUBJECT + 1 ] ;
2014-12-01 23:55:08 +01:00
2017-04-16 13:45:11 +02:00
/***** Get parameters related to forum *****/
2014-12-01 23:55:08 +01:00
For_GetParamsForum ( ) ;
2017-04-18 13:17:40 +02:00
/***** Get subject of the thread to delete *****/
2017-04-18 01:25:44 +02:00
For_GetThrSubject ( Gbl . Forum . ForumSelected . ThrCod , Subject ) ;
2014-12-01 23:55:08 +01:00
2017-04-18 13:17:40 +02:00
/***** Show forum list again *****/
For_ShowForumList ( ) ;
2017-04-28 10:35:41 +02:00
/***** Show question and button to remove the thread *****/
2017-05-25 13:43:54 +02:00
Lay_StartSection ( For_REMOVE_THREAD_SECTION_ID ) ;
2014-12-01 23:55:08 +01:00
if ( Subject [ 0 ] )
2018-10-16 23:08:04 +02:00
snprintf ( Gbl . Alert . Txt , sizeof ( Gbl . Alert . Txt ) ,
2018-10-16 21:56:01 +02:00
Txt_Do_you_really_want_to_remove_the_entire_thread_X ,
Subject ) ;
2014-12-01 23:55:08 +01:00
else
2018-10-16 15:16:32 +02:00
Str_Copy ( Gbl . Alert . Txt , Txt_Do_you_really_want_to_remove_the_entire_thread ,
Ale_MAX_BYTES_ALERT ) ;
2017-05-11 23:45:46 +02:00
Ale_ShowAlertAndButton ( Ale_QUESTION , Gbl . Alert . Txt ,
2017-05-11 21:53:37 +02:00
For_ActionsDelThrFor [ Gbl . Forum . ForumSelected . Type ] ,
2017-05-25 14:25:22 +02:00
For_FORUM_THREADS_SECTION_ID , NULL ,
2017-05-11 21:53:37 +02:00
For_PutAllHiddenParamsRemThread ,
2017-06-11 19:02:40 +02:00
Btn_REMOVE_BUTTON , Txt_Remove_thread ) ;
2017-05-25 13:43:54 +02:00
Lay_EndSection ( ) ;
2017-04-28 10:35:41 +02:00
/***** Show the threads again *****/
For_ShowForumThreadsHighlightingOneThread ( Gbl . Forum . ForumSelected . ThrCod ,
2017-05-11 23:45:46 +02:00
Ale_SUCCESS , NULL ) ;
2017-04-28 10:35:41 +02:00
}
static void For_PutAllHiddenParamsRemThread ( void )
{
2017-04-18 16:44:44 +02:00
For_PutAllHiddenParamsForum ( Gbl . Forum . CurrentPageThrs , // Page of threads = current
1 , // Page of posts = first
Gbl . Forum . ForumSet ,
2017-04-18 13:17:40 +02:00
Gbl . Forum . ThreadsOrder ,
2017-04-18 01:25:44 +02:00
Gbl . Forum . ForumSelected . Location ,
Gbl . Forum . ForumSelected . ThrCod ,
- 1L ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*************************** Remove an existing thread ***********************/
/*****************************************************************************/
2017-04-18 16:44:44 +02:00
void For_RemoveThread ( void )
2014-12-01 23:55:08 +01:00
{
extern const char * Txt_Thread_X_removed ;
extern const char * Txt_Thread_removed ;
2017-01-28 15:58:46 +01:00
char Subject [ Cns_MAX_BYTES_SUBJECT + 1 ] ;
2014-12-01 23:55:08 +01:00
2017-04-16 13:45:11 +02:00
/***** Get parameters related to forum *****/
2014-12-01 23:55:08 +01:00
For_GetParamsForum ( ) ;
2017-04-18 01:25:44 +02:00
if ( PermissionThreadDeletion [ Gbl . Forum . ForumSelected . Type ] &
2017-06-04 18:18:54 +02:00
( 1 < < Gbl . Usrs . Me . Role . Logged ) ) // If I have permission to remove thread in this forum...
2014-12-01 23:55:08 +01:00
{
/***** Get subject of thread to delete *****/
2017-04-18 01:25:44 +02:00
For_GetThrSubject ( Gbl . Forum . ForumSelected . ThrCod , Subject ) ;
2014-12-01 23:55:08 +01:00
/***** Remove the thread and all its posts *****/
2017-04-18 01:25:44 +02:00
For_RemoveThreadAndItsPsts ( Gbl . Forum . ForumSelected . ThrCod ) ;
2014-12-01 23:55:08 +01:00
2017-04-18 13:17:40 +02:00
/***** Show forum list again *****/
For_ShowForumList ( ) ;
/***** Show the threads again *****/
2014-12-01 23:55:08 +01:00
if ( Subject [ 0 ] )
{
2018-10-16 23:08:04 +02:00
snprintf ( Gbl . Alert . Txt , sizeof ( Gbl . Alert . Txt ) ,
2018-10-16 21:56:01 +02:00
Txt_Thread_X_removed , Subject ) ;
2017-04-18 09:55:25 +02:00
For_ShowForumThreadsHighlightingOneThread ( Gbl . Forum . ForumSelected . ThrCod ,
2017-05-11 23:45:46 +02:00
Ale_SUCCESS , Gbl . Alert . Txt ) ;
2017-04-18 09:55:25 +02:00
}
2014-12-01 23:55:08 +01:00
else
2017-04-18 09:55:25 +02:00
For_ShowForumThreadsHighlightingOneThread ( Gbl . Forum . ForumSelected . ThrCod ,
2017-05-11 23:45:46 +02:00
Ale_SUCCESS , Txt_Thread_removed ) ;
2014-12-01 23:55:08 +01:00
}
else
Lay_ShowErrorAndExit ( " You can not remove threads in this forum. " ) ;
}
/*****************************************************************************/
/*************** Cut a thread to move it to another forum ********************/
/*****************************************************************************/
2017-04-18 16:44:44 +02:00
void For_CutThread ( void )
2014-12-01 23:55:08 +01:00
{
extern const char * Txt_Thread_X_marked_to_be_moved ;
extern const char * Txt_Thread_marked_to_be_moved ;
2017-01-28 15:58:46 +01:00
char Subject [ Cns_MAX_BYTES_SUBJECT + 1 ] ;
2014-12-01 23:55:08 +01:00
2017-04-16 13:45:11 +02:00
/***** Get parameters related to forum *****/
2014-12-01 23:55:08 +01:00
For_GetParamsForum ( ) ;
/***** Get subject of thread to cut *****/
2017-04-18 01:25:44 +02:00
For_GetThrSubject ( Gbl . Forum . ForumSelected . ThrCod , Subject ) ;
2014-12-01 23:55:08 +01:00
/***** Mark the thread as cut *****/
2017-04-18 01:25:44 +02:00
For_InsertThrInClipboard ( Gbl . Forum . ForumSelected . ThrCod ) ;
2014-12-01 23:55:08 +01:00
2017-04-18 13:17:40 +02:00
/***** Show forum list again *****/
For_ShowForumList ( ) ;
/***** Show the threads again *****/
2014-12-01 23:55:08 +01:00
if ( Subject [ 0 ] )
2017-04-18 09:55:25 +02:00
{
2018-10-16 23:08:04 +02:00
snprintf ( Gbl . Alert . Txt , sizeof ( Gbl . Alert . Txt ) ,
2018-10-16 21:56:01 +02:00
Txt_Thread_X_marked_to_be_moved , Subject ) ;
2017-04-18 09:55:25 +02:00
For_ShowForumThreadsHighlightingOneThread ( Gbl . Forum . ForumSelected . ThrCod ,
2017-05-11 23:45:46 +02:00
Ale_SUCCESS , Gbl . Alert . Txt ) ;
2017-04-18 09:55:25 +02:00
}
2014-12-01 23:55:08 +01:00
else
2017-04-18 09:55:25 +02:00
For_ShowForumThreadsHighlightingOneThread ( Gbl . Forum . ForumSelected . ThrCod ,
2017-05-11 23:45:46 +02:00
Ale_SUCCESS , Txt_Thread_marked_to_be_moved ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************* Paste the thread in clipboard into current forum **************/
/*****************************************************************************/
2017-04-18 16:44:44 +02:00
void For_PasteThread ( void )
2014-12-01 23:55:08 +01:00
{
extern const char * Txt_The_thread_X_is_already_in_this_forum ;
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 ;
2017-01-28 15:58:46 +01:00
char Subject [ Cns_MAX_BYTES_SUBJECT + 1 ] ;
2014-12-01 23:55:08 +01:00
2017-04-16 13:45:11 +02:00
/***** Get parameters related to forum *****/
2014-12-01 23:55:08 +01:00
For_GetParamsForum ( ) ;
/***** Get subject of thread to paste *****/
2017-04-18 01:25:44 +02:00
For_GetThrSubject ( Gbl . Forum . ForumSelected . ThrCod , Subject ) ;
2014-12-01 23:55:08 +01:00
2017-04-18 09:55:25 +02:00
/***** Check if paste (move) the thread to current forum has sense *****/
2017-04-18 01:25:44 +02:00
if ( For_CheckIfThrBelongsToForum ( Gbl . Forum . ForumSelected . ThrCod , & Gbl . Forum . ForumSelected ) )
2014-12-01 23:55:08 +01:00
{
2017-04-18 13:17:40 +02:00
/***** Show forum list again *****/
For_ShowForumList ( ) ;
2017-04-18 09:55:25 +02:00
/***** Show the threads again *****/
2014-12-01 23:55:08 +01:00
if ( Subject [ 0 ] )
2017-04-18 09:55:25 +02:00
{
2018-10-16 23:08:04 +02:00
snprintf ( Gbl . Alert . Txt , sizeof ( Gbl . Alert . Txt ) ,
2018-10-16 21:56:01 +02:00
Txt_The_thread_X_is_already_in_this_forum ,
Subject ) ;
2017-04-18 09:55:25 +02:00
For_ShowForumThreadsHighlightingOneThread ( Gbl . Forum . ForumSelected . ThrCod ,
2017-05-11 23:45:46 +02:00
Ale_WARNING , Gbl . Alert . Txt ) ;
2017-04-18 09:55:25 +02:00
}
2014-12-01 23:55:08 +01:00
else
2017-04-18 09:55:25 +02:00
For_ShowForumThreadsHighlightingOneThread ( Gbl . Forum . ForumSelected . ThrCod ,
2017-05-11 23:45:46 +02:00
Ale_WARNING , Txt_The_thread_is_already_in_this_forum ) ;
2014-12-01 23:55:08 +01:00
}
else
{
2017-04-18 09:55:25 +02:00
/***** Paste (move) the thread to current forum *****/
2017-04-18 01:25:44 +02:00
For_MoveThrToCurrentForum ( Gbl . Forum . ForumSelected . ThrCod ) ;
2017-04-18 09:55:25 +02:00
2017-04-18 13:17:40 +02:00
/***** Show forum list again *****/
For_ShowForumList ( ) ;
2017-04-18 09:55:25 +02:00
/***** Show the threads again *****/
2014-12-01 23:55:08 +01:00
if ( Subject [ 0 ] )
2017-04-18 09:55:25 +02:00
{
2018-10-16 23:08:04 +02:00
snprintf ( Gbl . Alert . Txt , sizeof ( Gbl . Alert . Txt ) ,
2018-10-16 21:56:01 +02:00
Txt_Thread_X_moved_to_this_forum ,
Subject ) ;
2017-04-18 09:55:25 +02:00
For_ShowForumThreadsHighlightingOneThread ( Gbl . Forum . ForumSelected . ThrCod ,
2017-05-11 23:45:46 +02:00
Ale_SUCCESS , Gbl . Alert . Txt ) ;
2017-04-18 09:55:25 +02:00
}
2014-12-01 23:55:08 +01:00
else
2017-04-18 09:55:25 +02:00
For_ShowForumThreadsHighlightingOneThread ( Gbl . Forum . ForumSelected . ThrCod ,
2017-05-11 23:45:46 +02:00
Ale_SUCCESS , Txt_Thread_moved_to_this_forum ) ;
2014-12-01 23:55:08 +01:00
}
}
/*****************************************************************************/
2017-04-18 13:17:40 +02:00
/*********************** Check if I can move threads *************************/
/*****************************************************************************/
static bool For_CheckIfICanMoveThreads ( void )
{
2017-06-04 18:18:54 +02:00
return ( Gbl . Usrs . Me . Role . Logged = = Rol_SYS_ADM ) ; // If I have permission to move threads...
2017-04-18 13:17:40 +02:00
}
/*****************************************************************************/
/**************** Get if there is a thread ready to be moved *****************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2017-04-16 23:48:05 +02:00
static long For_GetThrInMyClipboard ( void )
2014-12-01 23:55:08 +01:00
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
MYSQL_RES * mysql_res ;
MYSQL_ROW row ;
unsigned long NumRows ;
long ThrCod = - 1L ; ;
/***** Get if there is a thread ready to move in my clipboard from database *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " SELECT ThrCod FROM forum_thr_clip WHERE UsrCod=%ld " ,
Gbl . Usrs . Me . UsrDat . UsrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
NumRows = DB_QuerySELECT_free ( Query , & mysql_res , " can not check if there is any thread ready to be moved " ) ;
2014-12-01 23:55:08 +01:00
if ( NumRows = = 1 )
{
/* Get thread code */
row = mysql_fetch_row ( mysql_res ) ;
if ( sscanf ( row [ 0 ] , " %ld " , & ThrCod ) ! = 1 )
Lay_ShowErrorAndExit ( " Error when checking if there is any thread ready to be moved. " ) ;
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult ( & mysql_res ) ;
return ThrCod ;
}
/*****************************************************************************/
2017-04-17 11:57:55 +02:00
/***************** Get if a thread belongs to current forum ******************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2017-04-19 12:34:38 +02:00
static bool For_CheckIfThrBelongsToForum ( long ThrCod , struct Forum * Forum )
2014-12-01 23:55:08 +01:00
{
char SubQuery [ 256 ] ;
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
/***** Get if a thread belong to current forum from database *****/
2017-04-19 12:34:38 +02:00
if ( Forum - > Location > 0 )
sprintf ( SubQuery , " AND forum_thread.Location=%ld " , Forum - > Location ) ;
2017-04-16 23:48:05 +02:00
else
SubQuery [ 0 ] = ' \0 ' ;
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " SELECT COUNT(*) FROM forum_thread "
" WHERE ThrCod=%ld AND ForumType=%u%s " ,
ThrCod , ( unsigned ) Forum - > Type , SubQuery ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
return ( DB_QueryCOUNT_free ( Query , " can not get if a thread belong to current forum " ) ! = 0 ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************ Move a thread to current forum *********************/
/*****************************************************************************/
2017-04-16 23:48:05 +02:00
static void For_MoveThrToCurrentForum ( long ThrCod )
2014-12-01 23:55:08 +01:00
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
/***** Move a thread to current forum *****/
2017-04-18 01:25:44 +02:00
switch ( Gbl . Forum . ForumSelected . Type )
2014-12-01 23:55:08 +01:00
{
2017-04-16 23:48:05 +02:00
case For_FORUM_GLOBAL_USRS :
case For_FORUM_GLOBAL_TCHS :
2017-04-18 19:55:56 +02:00
case For_FORUM__SWAD__USRS :
case For_FORUM__SWAD__TCHS :
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " UPDATE forum_thread "
" SET ForumType=%u,Location=-1 "
" WHERE ThrCod=%ld " ,
( unsigned ) Gbl . Forum . ForumSelected . Type ,
ThrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
2014-12-01 23:55:08 +01:00
break ;
2017-04-16 23:48:05 +02:00
case For_FORUM_INSTIT_USRS :
case For_FORUM_INSTIT_TCHS :
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " UPDATE forum_thread "
" SET ForumType=%u,Location=%ld "
" WHERE ThrCod=%ld " ,
( unsigned ) Gbl . Forum . ForumSelected . Type ,
Gbl . Forum . ForumSelected . Location ,
ThrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
2014-12-01 23:55:08 +01:00
break ;
2017-04-16 23:48:05 +02:00
case For_FORUM_CENTRE_USRS :
case For_FORUM_CENTRE_TCHS :
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " UPDATE forum_thread "
" SET ForumType=%u,Location=%ld "
" WHERE ThrCod=%ld " ,
( unsigned ) Gbl . Forum . ForumSelected . Type ,
Gbl . Forum . ForumSelected . Location ,
ThrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
2014-12-01 23:55:08 +01:00
break ;
2017-04-16 23:48:05 +02:00
case For_FORUM_DEGREE_USRS :
case For_FORUM_DEGREE_TCHS :
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " UPDATE forum_thread "
" SET ForumType=%u,Location=%ld "
" WHERE ThrCod=%ld " ,
( unsigned ) Gbl . Forum . ForumSelected . Type ,
Gbl . Forum . ForumSelected . Location ,
ThrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
2014-12-01 23:55:08 +01:00
break ;
2017-04-16 23:48:05 +02:00
case For_FORUM_COURSE_USRS :
case For_FORUM_COURSE_TCHS :
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " UPDATE forum_thread "
" SET ForumType=%u,Location=%ld "
" WHERE ThrCod=%ld " ,
( unsigned ) Gbl . Forum . ForumSelected . Type ,
Gbl . Forum . ForumSelected . Location ,
ThrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
2014-12-01 23:55:08 +01:00
break ;
2017-04-18 19:55:56 +02:00
default :
Lay_ShowErrorAndExit ( " Wrong forum. " ) ;
break ;
2014-12-01 23:55:08 +01:00
}
2018-10-22 00:31:44 +02:00
DB_QueryUPDATE_free ( Query , " can not move a thread to current forum " ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Insert thread in thread clipboard ********************/
/*****************************************************************************/
2017-04-16 23:48:05 +02:00
static void For_InsertThrInClipboard ( long ThrCod )
2014-12-01 23:55:08 +01:00
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
/***** Remove expired thread clipboards *****/
For_RemoveExpiredThrsClipboards ( ) ;
/***** Add thread to my clipboard *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " REPLACE INTO forum_thr_clip "
" (ThrCod,UsrCod) "
" VALUES "
" (%ld,%ld) " ,
ThrCod , Gbl . Usrs . Me . UsrDat . UsrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
DB_QueryREPLACE_free ( Query , " can not add thread to clipboard " ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************* Remove expired thread clipboards (from all users) *************/
/*****************************************************************************/
2017-04-16 23:48:05 +02:00
static void For_RemoveExpiredThrsClipboards ( void )
2014-12-01 23:55:08 +01:00
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
/***** Remove all expired clipboards *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " DELETE LOW_PRIORITY FROM forum_thr_clip "
" WHERE TimeInsert<FROM_UNIXTIME(UNIX_TIMESTAMP()-'%lu') " ,
Cfg_TIME_TO_DELETE_THREAD_CLIPBOARD ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
DB_QueryDELETE_free ( Query , " can not remove old threads from clipboards " ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/**************** Remove thread code from thread clipboard *******************/
/*****************************************************************************/
2017-04-16 23:48:05 +02:00
static void For_RemoveThrCodFromThrClipboard ( long ThrCod )
2014-12-01 23:55:08 +01:00
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
/***** Remove thread from thread clipboard *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " DELETE FROM forum_thr_clip WHERE ThrCod=%ld " ,
ThrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
DB_QueryDELETE_free ( Query , " can not remove a thread from clipboard " ) ;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Remove thread clipboard of a user *********************/
/*****************************************************************************/
void For_RemoveUsrFromThrClipboard ( long UsrCod )
{
2018-10-22 00:31:44 +02:00
char * Query ;
2014-12-01 23:55:08 +01:00
/***** Remove clipboard of specified user *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " DELETE FROM forum_thr_clip WHERE UsrCod=%ld " ,
UsrCod ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
DB_QueryDELETE_free ( Query , " can not remove a thread from the clipboard of a user " ) ;
2014-12-01 23:55:08 +01:00
}
2016-10-27 22:26:52 +02:00
2016-10-27 23:38:53 +02:00
/*****************************************************************************/
/********** Remove all the threads and posts in forums of a degree ***********/
/*****************************************************************************/
2017-04-16 23:48:05 +02:00
void For_RemoveForums ( Sco_Scope_t Scope , long ForumLocation )
2016-10-27 22:26:52 +02:00
{
2016-10-28 00:23:02 +02:00
static const struct
{
For_ForumType_t Usrs ;
For_ForumType_t Tchs ;
} ForumType [ Sco_NUM_SCOPES ] =
{
{ For_FORUM_GLOBAL_USRS , For_FORUM_GLOBAL_TCHS } , // Sco_SCOPE_UNK // No forums for this scope
{ For_FORUM_GLOBAL_USRS , For_FORUM_GLOBAL_TCHS } , // Sco_SCOPE_SYS // Not removable
{ For_FORUM_GLOBAL_USRS , For_FORUM_GLOBAL_TCHS } , // Sco_SCOPE_CTY // No forums for this scope
{ For_FORUM_INSTIT_USRS , For_FORUM_INSTIT_TCHS } , // Sco_SCOPE_INS
{ For_FORUM_CENTRE_USRS , For_FORUM_CENTRE_TCHS } , // Sco_SCOPE_CTR
{ For_FORUM_DEGREE_USRS , For_FORUM_DEGREE_TCHS } , // Sco_SCOPE_DEG
{ For_FORUM_COURSE_USRS , For_FORUM_COURSE_TCHS } , // Sco_SCOPE_CRS
} ;
2018-10-22 00:31:44 +02:00
char * Query ;
2016-10-27 22:26:52 +02:00
/***** Remove disabled posts *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " DELETE FROM forum_disabled_post "
" USING forum_thread,forum_post,forum_disabled_post "
" WHERE "
" (forum_thread.ForumType=%u "
" OR "
" forum_thread.ForumType=%u) "
" AND forum_thread.Location=%ld "
" AND forum_thread.ThrCod=forum_post.ThrCod "
" AND forum_post.PstCod=forum_disabled_post.PstCod " ,
ForumType [ Scope ] . Usrs ,
ForumType [ Scope ] . Tchs ,
ForumLocation ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
DB_QueryDELETE_free ( Query , " can not remove the disabled posts in forums " ) ;
2016-10-27 22:26:52 +02:00
/***** Remove posts *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " DELETE FROM forum_post "
" USING forum_thread,forum_post "
" WHERE "
" (forum_thread.ForumType=%u "
" OR "
" forum_thread.ForumType=%u) "
" AND forum_thread.Location=%ld "
" AND forum_thread.ThrCod=forum_post.ThrCod " ,
ForumType [ Scope ] . Usrs ,
ForumType [ Scope ] . Tchs ,
ForumLocation ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
DB_QueryDELETE_free ( Query , " can not remove posts in forums " ) ;
2016-10-27 22:26:52 +02:00
/***** Remove threads read *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " DELETE FROM forum_thr_read "
" USING forum_thread,forum_thr_read "
" WHERE "
" (forum_thread.ForumType=%u "
" OR "
" forum_thread.ForumType=%u) "
" AND forum_thread.Location=%ld "
" AND forum_thread.ThrCod=forum_thr_read.ThrCod " ,
ForumType [ Scope ] . Usrs ,
ForumType [ Scope ] . Tchs ,
ForumLocation ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
DB_QueryDELETE_free ( Query , " can not remove read threads in forums " ) ;
2016-10-27 22:26:52 +02:00
/***** Remove threads *****/
2018-10-22 00:31:44 +02:00
if ( asprintf ( & Query , " DELETE FROM forum_thread "
" WHERE "
" (forum_thread.ForumType=%u "
" OR "
" forum_thread.ForumType=%u) "
" AND Location=%ld " ,
ForumType [ Scope ] . Usrs ,
ForumType [ Scope ] . Tchs ,
ForumLocation ) < 0 )
Lay_NotEnoughMemoryExit ( ) ;
DB_QueryDELETE_free ( Query , " can not remove threads in forums " ) ;
2016-10-27 22:26:52 +02:00
}