Version 15.192

This commit is contained in:
Antonio Cañas Vargas 2016-04-10 19:19:20 +02:00
parent 13fd0917e8
commit ad2f5dbeac
6 changed files with 203 additions and 98 deletions

View File

@ -133,14 +133,23 @@
/****************************** Public constants *****************************/
/*****************************************************************************/
#define Log_PLATFORM_VERSION "SWAD 15.191 (2016-04-10)"
#define CSS_FILE "swad15.190.1.css"
#define Log_PLATFORM_VERSION "SWAD 15.192 (2016-04-10)"
#define CSS_FILE "swad15.192.css"
#define JS_FILE "swad15.190.1.js"
// Number of lines (includes comments but not blank lines) has been got with the following command:
// nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*.h sql/swad*.sql | tail -1
/*
Version 15.191: Apr 10, 2016 Forms to attach an image to a forum posts and messages. Not finished. (? lines)
Version 15.192: Apr 10, 2016 Get image attached to forum post / message. (199332 lines)
6 changes necessary in database:
ALTER TABLE forum_post ADD COLUMN ImageName VARCHAR(43) NOT NULL AFTER Content;
ALTER TABLE forum_post ADD COLUMN ImageTitle VARCHAR(255) NOT NULL AFTER ImageName;
ALTER TABLE msg_content ADD COLUMN ImageName VARCHAR(43) NOT NULL AFTER Content;
ALTER TABLE msg_content ADD COLUMN ImageTitle VARCHAR(255) NOT NULL AFTER ImageName;
ALTER TABLE msg_content_deleted ADD COLUMN ImageName VARCHAR(43) NOT NULL AFTER Content;
ALTER TABLE msg_content_deleted ADD COLUMN ImageTitle VARCHAR(255) NOT NULL AFTER ImageName;
Version 15.191: Apr 10, 2016 Forms to attach an image to a forum posts and messages. Not finished. (199247 lines)
Version 15.190.6: Apr 09, 2016 Changes in layout of form to write a new message. (199152 lines)
Version 15.190.5: Apr 09, 2016 Changes in layout of form to write a new forum post. (199156 lines)
Version 15.190.4: Apr 09, 2016 Changes in layout of form to write a new forum post. (199152 lines)

View File

@ -1100,19 +1100,21 @@ mysql> DESCRIBE forum_disabled_post;
/***** Table forum_post *****/
/*
mysql> DESCRIBE forum_post;
+-----------+----------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+----------+------+-----+---------------------+----------------+
| PstCod | int(11) | NO | PRI | NULL | auto_increment |
| ThrCod | int(11) | NO | MUL | NULL | |
| UsrCod | int(11) | NO | MUL | NULL | |
| CreatTime | datetime | NO | MUL | NULL | |
| ModifTime | datetime | NO | MUL | 0000-00-00 00:00:00 | |
| NumNotif | int(11) | NO | | 0 | |
| Subject | text | NO | | NULL | |
| Content | longtext | NO | | NULL | |
+-----------+----------+------+-----+---------------------+----------------+
8 rows in set (0.00 sec)
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| PstCod | int(11) | NO | PRI | NULL | auto_increment |
| ThrCod | int(11) | NO | MUL | NULL | |
| UsrCod | int(11) | NO | MUL | NULL | |
| CreatTime | datetime | NO | MUL | NULL | |
| ModifTime | datetime | NO | MUL | NULL | |
| NumNotif | int(11) | NO | | 0 | |
| Subject | text | NO | | NULL | |
| Content | longtext | NO | | NULL | |
| ImageName | varchar(43) | NO | | NULL | |
| ImageTitle | varchar(255) | NO | | NULL | |
+------------+--------------+------+-----+---------+----------------+
10 rows in set (0.00 sec)
*/
DB_CreateTable ("CREATE TABLE IF NOT EXISTS forum_post ("
"PstCod INT NOT NULL AUTO_INCREMENT,"
@ -1123,6 +1125,8 @@ mysql> DESCRIBE forum_post;
"NumNotif INT NOT NULL DEFAULT 0,"
"Subject TEXT NOT NULL,"
"Content LONGTEXT NOT NULL,"
"ImageName VARCHAR(43) NOT NULL,"
"ImageTitle VARCHAR(255) NOT NULL,"
"UNIQUE INDEX(PstCod),"
"INDEX(ThrCod),"
"INDEX(UsrCod),"
@ -1570,38 +1574,46 @@ mysql> DESCRIBE msg_banned;
/***** Table msg_content *****/
/*
mysql> DESCRIBE msg_content;
+---------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+----------+------+-----+---------+----------------+
| MsgCod | int(11) | NO | PRI | NULL | auto_increment |
| Subject | text | NO | MUL | NULL | |
| Content | longtext | NO | | NULL | |
+---------+----------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| MsgCod | int(11) | NO | PRI | NULL | auto_increment |
| Subject | text | NO | MUL | NULL | |
| Content | longtext | NO | | NULL | |
| ImageName | varchar(43) | NO | | NULL | |
| ImageTitle | varchar(255) | NO | | NULL | |
+------------+--------------+------+-----+---------+----------------+
5 rows in set (0.01 sec)
*/
DB_CreateTable ("CREATE TABLE IF NOT EXISTS msg_content ("
"MsgCod INT NOT NULL AUTO_INCREMENT,"
"Subject TEXT NOT NULL,"
"Content LONGTEXT NOT NULL,"
"ImageName VARCHAR(43) NOT NULL,"
"ImageTitle VARCHAR(255) NOT NULL,"
"UNIQUE INDEX(MsgCod),"
"FULLTEXT(Subject,Content)) ENGINE = MYISAM;");
/***** Table msg_content_deleted *****/
/*
mysql> DESCRIBE msg_content_deleted;
+---------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+----------+------+-----+---------+-------+
| MsgCod | int(11) | NO | PRI | NULL | |
| Subject | text | NO | MUL | NULL | |
| Content | longtext | NO | | NULL | |
+---------+----------+------+-----+---------+-------+
3 rows in set (0.00 sec)
+------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| MsgCod | int(11) | NO | PRI | NULL | |
| Subject | text | NO | MUL | NULL | |
| Content | longtext | NO | | NULL | |
| ImageName | varchar(43) | NO | | NULL | |
| ImageTitle | varchar(255) | NO | | NULL | |
+------------+--------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
*/
DB_CreateTable ("CREATE TABLE IF NOT EXISTS msg_content_deleted ("
"MsgCod INT NOT NULL,"
"Subject TEXT NOT NULL,"
"Content LONGTEXT NOT NULL,"
"ImageName VARCHAR(43) NOT NULL,"
"ImageTitle VARCHAR(255) NOT NULL,"
"UNIQUE INDEX(MsgCod),"
"FULLTEXT(Subject,Content)) ENGINE = MYISAM;");

View File

@ -250,6 +250,26 @@ const Act_Action_t For_ActionsDisPstFor[For_NUM_TYPES_FORUM] =
/***************************** Private prototypes ***************************/
/*****************************************************************************/
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);
static bool For_RemoveForumPst (long PstCod);
static unsigned For_NumPstsInThrWithPstCod (long PstCod,long *ThrCod);
static long For_InsertForumThread (For_ForumType_t ForumType,long FirstPstCod);
static void For_RemoveThreadOnly (long ThrCod);
static void For_RemoveThreadAndItsPsts (long ThrCod);
static void For_GetThrSubject (long ThrCod,char *Subject,size_t MaxSize);
static void For_UpdateThrFirstAndLastPst (long ThrCod,long FirstPstCod,long LastPstCod);
static void For_UpdateThrLastPst (long ThrCod,long LastPstCod);
static long For_GetLastPstCod (long ThrCod);
static void For_UpdateThrReadTime (long ThrCod,time_t ReadTimeUTC);
static unsigned For_GetNumOfReadersOfThr (long ThrCod);
static unsigned For_GetNumOfWritersInThr (long ThrCod);
@ -290,7 +310,7 @@ static void For_ShowAForumPost (struct ForumThread *Thr,unsigned PstNum,long Pst
bool LastPst,char *LastSubject,
bool NewPst,bool ICanModerateForum);
static void For_GetPstData (long PstCod,long *UsrCod,time_t *CreatTimeUTC,
char *Subject, char *Content);
char *Subject,char *Content,struct Image *Image);
static void For_WriteNumberOfPosts (For_ForumType_t ForumType,long UsrCod);
/*****************************************************************************/
@ -361,7 +381,7 @@ void For_DisPst (void)
/******************** Get if a forum post exists in database *****************/
/*****************************************************************************/
bool For_GetIfForumPstExists (long PstCod)
static bool For_GetIfForumPstExists (long PstCod)
{
char Query[512];
@ -376,7 +396,7 @@ bool For_GetIfForumPstExists (long PstCod)
/*********************** Get if a forum post is enabled **********************/
/*****************************************************************************/
bool For_GetIfPstIsEnabled (long PstCod)
static bool For_GetIfPstIsEnabled (long PstCod)
{
char Query[512];
@ -391,7 +411,7 @@ bool For_GetIfPstIsEnabled (long PstCod)
/****************** Delete post from table of disabled posts *****************/
/*****************************************************************************/
void For_DeletePstFromDisabledPstTable (long PstCod)
static void For_DeletePstFromDisabledPstTable (long PstCod)
{
char Query[512];
@ -406,7 +426,7 @@ void For_DeletePstFromDisabledPstTable (long PstCod)
/****************** Insert post into table of banned posts *******************/
/*****************************************************************************/
void For_InsertPstIntoBannedPstTable (long PstCod)
static void For_InsertPstIntoBannedPstTable (long PstCod)
{
char Query[512];
@ -422,16 +442,35 @@ void For_InsertPstIntoBannedPstTable (long PstCod)
/************** Insert a post new in the table of posts of forums ************/
/*****************************************************************************/
long For_InsertForumPst (long ThrCod,long UsrCod,const char *Subject,const char *Content)
static long For_InsertForumPst (long ThrCod,long UsrCod,
const char *Subject,const char *Content,
struct Image *Image)
{
char Query[256+Cns_MAX_BYTES_SUBJECT+Cns_MAX_BYTES_LONG_TEXT];
char *Query;
long PstCod;
/***** Allocate space for query *****/
if ((Query = malloc (512 +
strlen (Subject) +
strlen (Content) +
Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64+
Img_MAX_BYTES_TITLE)) == NULL)
Lay_ShowErrorAndExit ("Not enough memory to store database query.");
/***** Insert forum post in the database *****/
sprintf (Query,"INSERT INTO forum_post"
" (ThrCod,UsrCod,CreatTime,ModifTime,NumNotif,Subject,Content)"
" VALUES ('%ld','%ld',NOW(),NOW(),'0','%s','%s')",
ThrCod,UsrCod,Subject,Content);
return DB_QueryINSERTandReturnCode (Query,"can not create a new post in a forum");
" (ThrCod,UsrCod,CreatTime,ModifTime,NumNotif,"
"Subject,Content,ImageName,ImageTitle)"
" VALUES ('%ld','%ld',NOW(),NOW(),'0',"
"'%s','%s','%s','%s')",
ThrCod,UsrCod,
Subject,Content,Image->Name,Image->Title ? Image->Title : "");
PstCod = DB_QueryINSERTandReturnCode (Query,"can not create a new post in a forum");
/***** Free space used for query *****/
free ((void *) Query);
return PstCod;
}
/*****************************************************************************/
@ -439,7 +478,7 @@ long For_InsertForumPst (long ThrCod,long UsrCod,const char *Subject,const char
/*****************************************************************************/
// Return true if the post thread is deleted
bool For_RemoveForumPst (long PstCod)
static bool For_RemoveForumPst (long PstCod)
{
char Query[512];
long ThrCod;
@ -471,7 +510,7 @@ bool For_RemoveForumPst (long PstCod)
/*********** Get the number of posts in the thread than holds a post *********/
/*****************************************************************************/
unsigned For_NumPstsInThrWithPstCod (long PstCod,long *ThrCod)
static unsigned For_NumPstsInThrWithPstCod (long PstCod,long *ThrCod)
{
char Query[512];
MYSQL_RES *mysql_res;
@ -501,7 +540,7 @@ unsigned For_NumPstsInThrWithPstCod (long PstCod,long *ThrCod)
/*****************************************************************************/
// Returns the code of the new inserted thread
long For_InsertForumThread (For_ForumType_t ForumType,long FirstPstCod)
static long For_InsertForumThread (For_ForumType_t ForumType,long FirstPstCod)
{
char Query[512];
@ -553,7 +592,7 @@ long For_InsertForumThread (For_ForumType_t ForumType,long FirstPstCod)
/*************** Delete a thread from the forum thread table *****************/
/*****************************************************************************/
void For_RemoveThreadOnly (long ThrCod)
static void For_RemoveThreadOnly (long ThrCod)
{
char Query[512];
@ -573,7 +612,7 @@ void For_RemoveThreadOnly (long ThrCod)
/*************** Delete a thread from the forum thread table *****************/
/*****************************************************************************/
void For_RemoveThreadAndItsPsts (long ThrCod)
static void For_RemoveThreadAndItsPsts (long ThrCod)
{
char Query[512];
@ -598,7 +637,7 @@ void For_RemoveThreadAndItsPsts (long ThrCod)
/********************* Get the thread subject from a thread ******************/
/*****************************************************************************/
void For_GetThrSubject (long ThrCod,char *Subject,size_t MaxSize)
static void For_GetThrSubject (long ThrCod,char *Subject,size_t MaxSize)
{
char Query[512];
MYSQL_RES *mysql_res;
@ -661,7 +700,7 @@ For_ForumType_t For_GetForumTypeOfAPost (long PstCod)
/********* Modify the codes of the first and last posts of a thread **********/
/*****************************************************************************/
void For_UpdateThrFirstAndLastPst (long ThrCod,long FirstPstCod,long LastPstCod)
static void For_UpdateThrFirstAndLastPst (long ThrCod,long FirstPstCod,long LastPstCod)
{
char Query[512];
@ -676,7 +715,7 @@ void For_UpdateThrFirstAndLastPst (long ThrCod,long FirstPstCod,long LastPstCod)
/************** Modify the code of the last post of a thread *****************/
/*****************************************************************************/
void For_UpdateThrLastPst (long ThrCod,long LastPstCod)
static void For_UpdateThrLastPst (long ThrCod,long LastPstCod)
{
char Query[512];
@ -690,7 +729,7 @@ void For_UpdateThrLastPst (long ThrCod,long LastPstCod)
/**************** Get the code of the last post of a thread ******************/
/*****************************************************************************/
long For_GetLastPstCod (long ThrCod)
static long For_GetLastPstCod (long ThrCod)
{
char Query[512];
MYSQL_RES *mysql_res;
@ -1104,16 +1143,21 @@ static void For_ShowAForumPost (struct ForumThread *Thr,unsigned PstNum,long Pst
char OriginalContent[Cns_MAX_BYTES_LONG_TEXT+1];
char Subject[Cns_MAX_BYTES_SUBJECT+1];
char Content[Cns_MAX_BYTES_LONG_TEXT+1];
struct Image Image;
bool Enabled;
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
/***** Initialize image *****/
Img_ImageConstructor (&Image);
/***** Check if post is enabled *****/
Enabled = For_GetIfPstIsEnabled (PstCod);
/***** Get data of post *****/
For_GetPstData (PstCod,&UsrDat.UsrCod,&CreatTimeUTC,Subject,OriginalContent);
For_GetPstData (PstCod,&UsrDat.UsrCod,&CreatTimeUTC,
Subject,OriginalContent,&Image);
if (Enabled)
{
/* Return this subject as last subject */
@ -1248,6 +1292,9 @@ static void For_ShowAForumPost (struct ForumThread *Thr,unsigned PstNum,long Pst
strncpy (Content,OriginalContent,Cns_MAX_BYTES_LONG_TEXT);
Content[Cns_MAX_BYTES_LONG_TEXT] = '\0';
Msg_WriteMsgContent (Content,Cns_MAX_BYTES_LONG_TEXT,true,false);
/***** Show image *****/
Img_ShowImage (&Image,"FOR_IMG");
}
else
fprintf (Gbl.F.Out,"%s",Txt_This_post_has_been_banned_probably_for_not_satisfy_the_rules_of_the_forums);
@ -1255,6 +1302,9 @@ static void For_ShowAForumPost (struct ForumThread *Thr,unsigned PstNum,long Pst
"</td>"
"</tr>");
/***** Free image *****/
Img_ImageDestructor (&Image);
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
}
@ -1262,9 +1312,10 @@ static void For_ShowAForumPost (struct ForumThread *Thr,unsigned PstNum,long Pst
/*****************************************************************************/
/*************************** Get data of a forum post ************************/
/*****************************************************************************/
// If pointer to Image is NULL ==> do not get image
static void For_GetPstData (long PstCod,long *UsrCod,time_t *CreatTimeUTC,
char *Subject, char *Content)
char *Subject, char *Content,struct Image *Image)
{
char Query[512];
MYSQL_RES *mysql_res;
@ -1272,7 +1323,8 @@ static void For_GetPstData (long PstCod,long *UsrCod,time_t *CreatTimeUTC,
unsigned NumRows;
/***** Get data of a post from database *****/
sprintf (Query,"SELECT UsrCod,UNIX_TIMESTAMP(CreatTime),Subject,Content"
sprintf (Query,"SELECT UsrCod,UNIX_TIMESTAMP(CreatTime),"
"Subject,Content,ImageName,ImageTitle"
" FROM forum_post WHERE PstCod='%ld'",
PstCod);
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get data of a post");
@ -1291,10 +1343,16 @@ static void For_GetPstData (long PstCod,long *UsrCod,time_t *CreatTimeUTC,
*CreatTimeUTC = Dat_GetUNIXTimeFromStr (row[1]);
/****** Get subject (row[2]) *****/
strcpy (Subject,row[2]);
strncpy (Subject,row[2],Cns_MAX_BYTES_SUBJECT);
Subject[Cns_MAX_BYTES_SUBJECT] = '\0';
/****** Get location (row[3]) *****/
strcpy (Content,row[3]);
strncpy (Content,row[3],Cns_MAX_BYTES_LONG_TEXT);
Content[Cns_MAX_BYTES_LONG_TEXT] = '\0';
/****** Get image name (row[4]) and title (row[5]) *****/
if (Image)
Img_GetImageNameAndTitleFromRow (row[4],row[5],Image);
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
@ -2461,14 +2519,16 @@ void For_ShowForumThrs (void)
switch (Gbl.Forum.SelectedOrderType)
{
case For_FIRST_MSG:
sprintf (Query,"SELECT forum_thread.ThrCod FROM forum_thread,forum_post"
sprintf (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.ForumType,SubQuery);
break;
case For_LAST_MSG:
sprintf (Query,"SELECT forum_thread.ThrCod FROM forum_thread,forum_post"
sprintf (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",
@ -3533,8 +3593,10 @@ static void For_WriteThrSubject (long ThrCod)
long FirstPstCod;
/***** Get subject of a thread from database *****/
sprintf (Query,"SELECT forum_post.PstCod,forum_post.Subject FROM forum_thread,forum_post"
" WHERE forum_thread.ThrCod='%ld' AND forum_thread.FirstPstCod=forum_post.PstCod",
sprintf (Query,"SELECT forum_post.PstCod,forum_post.Subject"
" FROM forum_thread,forum_post"
" WHERE forum_thread.ThrCod='%ld'"
" AND forum_thread.FirstPstCod=forum_post.PstCod",
ThrCod);
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get the subject of a thread");
@ -3858,23 +3920,25 @@ void For_RecForumPst (void)
For_IMAGE_SAVED_QUALITY);
/***** Create a new message *****/
if (PstIsAReply)
if (PstIsAReply) // This post is a reply to another posts in the thread
{
// ThrCod has been received from form
/***** Create last message of the thread *****/
PstCod = For_InsertForumPst (ThrCod,Gbl.Usrs.Me.UsrDat.UsrCod,Gbl.Msg.Subject,Content);
PstCod = For_InsertForumPst (ThrCod,Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Msg.Subject,Content,&Image);
/***** Modify last message of the thread *****/
For_UpdateThrLastPst (ThrCod,PstCod);
}
else // New thread
else // This post is the first of a new thread
{
/***** Create new thread with unknown first and last message codes *****/
ThrCod = For_InsertForumThread (Gbl.Forum.ForumType,-1L);
/***** Create first (and last) message of the thread *****/
PstCod = For_InsertForumPst (ThrCod,Gbl.Usrs.Me.UsrDat.UsrCod,Gbl.Msg.Subject,Content);
PstCod = For_InsertForumPst (ThrCod,Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Msg.Subject,Content,&Image);
/***** Update first and last posts of new thread *****/
For_UpdateThrFirstAndLastPst (ThrCod,PstCod,PstCod);
@ -3972,7 +4036,8 @@ void For_DelPst (void)
Lay_ShowErrorAndExit ("The post to remove no longer exists.");
/* Check if I am the author of the message */
For_GetPstData (PstCod,&UsrDat.UsrCod,&CreatTimeUTC,Subject,OriginalContent);
For_GetPstData (PstCod,&UsrDat.UsrCod,&CreatTimeUTC,
Subject,OriginalContent,NULL);
if (Gbl.Usrs.Me.UsrDat.UsrCod != UsrDat.UsrCod)
Lay_ShowErrorAndExit ("You can not remove post because you aren't the author.");

View File

@ -89,22 +89,9 @@ typedef enum
void For_EnbPst (void);
void For_DisPst (void);
bool For_GetIfForumPstExists (long PstCod);
bool For_GetIfPstIsEnabled (long PstCod);
void For_DeletePstFromDisabledPstTable (long PstCod);
void For_InsertPstIntoBannedPstTable (long PstCod);
long For_InsertForumPst (long ThrCod,long UsrCod,const char *Subject,const char *Content);
bool For_RemoveForumPst (long PstCod);
unsigned For_NumPstsInThrWithPstCod (long PstCod,long *ThrCod);
long For_InsertForumThread (For_ForumType_t ForumType,long FirstPstCod);
void For_RemoveThreadOnly (long ThrCod);
void For_RemoveThreadAndItsPsts (long ThrCod);
void For_GetThrSubject (long ThrCod,char *Subject,size_t MaxSize);
For_ForumType_t For_GetForumTypeOfAPost (long PstCod);
void For_UpdateThrFirstAndLastPst (long ThrCod,long FirstPstCod,long LastPstCod);
void For_UpdateThrLastPst (long ThrCod,long LastPstCod);
long For_GetLastPstCod (long ThrCod);
unsigned long For_GetNumPostsUsr (long UsrCod);
void For_DeleteThrFromReadThrs (long ThrCod);
void For_RemoveUsrFromReadThrs (long UsrCod);

View File

@ -111,7 +111,8 @@ static void Msg_ExpandReceivedMsg (long MsgCod);
static void Msg_ContractSentMsg (long MsgCod);
static void Msg_ContractReceivedMsg (long MsgCod);
static long Msg_InsertNewMsg (const char *Subject,const char *Content);
static long Msg_InsertNewMsg (const char *Subject,const char *Content,
struct Image *Image);
static unsigned long Msg_DelSomeRecOrSntMsgsUsr (Msg_TypeOfMessages_t TypeOfMessages,long UsrCod,
long FilterCrsCod,const char *FilterFromToSubquery);
@ -126,7 +127,7 @@ static unsigned Msg_GetNumUnreadMsgs (long FilterCrsCod,const char *FilterFromTo
static void Msg_GetMsgSntData (long MsgCod,long *CrsCod,long *UsrCod,
time_t *CreatTimeUTC,char *Subject,bool *Deleted);
static void Msg_GetMsgContent (long MsgCod,char *Content);
static void Msg_GetMsgContent (long MsgCod,char *Content,struct Image *Image);
static void Msg_WriteSentOrReceivedMsgSubject (Msg_TypeOfMessages_t TypeOfMessages,long MsgCod,const char *Subject,bool Open,bool Expanded);
static void Msg_WriteFormToReply (long MsgCod,long CrsCod,const char *Subject,
@ -828,7 +829,7 @@ void Msg_RecMsgFromUsr (void)
if (!MsgAlreadyInserted)
{
// The message is inserted only once in the table of messages sent
NewMsgCod = Msg_InsertNewMsg (Gbl.Msg.Subject,Content);
NewMsgCod = Msg_InsertNewMsg (Gbl.Msg.Subject,Content,&Image);
MsgAlreadyInserted = true;
}
@ -1356,15 +1357,25 @@ void Msg_SetReceivedMsgAsOpen (long MsgCod,long UsrCod)
/*****************************************************************************/
// Return the code of the new inserted message
static long Msg_InsertNewMsg (const char *Subject,const char *Content)
static long Msg_InsertNewMsg (const char *Subject,const char *Content,
struct Image *Image)
{
char Query[128+Cns_MAX_BYTES_SUBJECT+Cns_MAX_BYTES_LONG_TEXT];
char *Query;
long MsgCod;
/***** Allocate space for query *****/
if ((Query = malloc (512 +
strlen (Subject) +
strlen (Content) +
Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64+
Img_MAX_BYTES_TITLE)) == NULL)
Lay_ShowErrorAndExit ("Not enough memory to store database query.");
/***** Insert message subject and content in the database *****/
sprintf (Query,"INSERT INTO msg_content (Subject,Content)"
" VALUES ('%s','%s')",
Subject,Content);
sprintf (Query,"INSERT INTO msg_content"
" (Subject,Content,ImageName,ImageTitle)"
" VALUES ('%s','%s','%s','%s')",
Subject,Content,Image->Name,Image->Title ? Image->Title : "");
MsgCod = DB_QueryINSERTandReturnCode (Query,"can not create message");
/***** Insert message in sent messages *****/
@ -1375,6 +1386,9 @@ static long Msg_InsertNewMsg (const char *Subject,const char *Content)
Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryINSERT (Query,"can not create message");
/***** Free space used for query *****/
free ((void *) Query);
/***** Increment number of messages sent by me *****/
Prf_IncrementNumMsgSntUsr (Gbl.Usrs.Me.UsrDat.UsrCod);
@ -1465,7 +1479,8 @@ static void Msg_InsertReceivedMsgIntoDB (long MsgCod,long UsrCod,bool NotifyByEm
char Query[512];
/***** Insert message received in the database *****/
sprintf (Query,"INSERT INTO msg_rcv (MsgCod,UsrCod,Notified,Open,Replied,Expanded)"
sprintf (Query,"INSERT INTO msg_rcv"
" (MsgCod,UsrCod,Notified,Open,Replied,Expanded)"
" VALUES ('%ld','%ld','%c','N','N','N')",
MsgCod,UsrCod,
NotifyByEmail ? 'Y' :
@ -2683,7 +2698,8 @@ void Msg_GetMsgSubject (long MsgCod,char *Subject)
{
/***** Get subject *****/
row = mysql_fetch_row (mysql_res);
strcpy (Subject,row[0]);
strncpy (Subject,row[0],Cns_MAX_BYTES_SUBJECT);
Subject[Cns_MAX_BYTES_SUBJECT] = '\0';
}
else
Subject[0] = '\0';
@ -2693,18 +2709,19 @@ void Msg_GetMsgSubject (long MsgCod,char *Subject)
}
/*****************************************************************************/
/************************** Get content of a message *************************/
/*************** Get content and optional image of a message *****************/
/*****************************************************************************/
static void Msg_GetMsgContent (long MsgCod,char *Content)
static void Msg_GetMsgContent (long MsgCod,char *Content,struct Image *Image)
{
char Query[128];
char Query[256];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
/***** Get content of message from database *****/
sprintf (Query,"SELECT Content FROM msg_content WHERE MsgCod='%ld'",
sprintf (Query,"SELECT Content,ImageName,ImageTitle"
" FROM msg_content WHERE MsgCod='%ld'",
MsgCod);
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get the content of a message");
@ -2719,6 +2736,9 @@ static void Msg_GetMsgContent (long MsgCod,char *Content)
strncpy (Content,row[0],Cns_MAX_BYTES_LONG_TEXT);
Content[Cns_MAX_BYTES_LONG_TEXT] = '\0';
/****** Get image name (row[1]) and title (row[2]) *****/
Img_GetImageNameAndTitleFromRow (row[1],row[2],Image);
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
@ -2811,6 +2831,7 @@ static void Msg_ShowASentOrReceivedMessage (Msg_TypeOfMessages_t TypeOfMessages,
long CrsCod;
char Subject[Cns_MAX_BYTES_SUBJECT+1];
char Content[Cns_MAX_BYTES_LONG_TEXT+1];
struct Image Image;
bool Deleted;
bool Open = true;
bool Replied = false; // Initialized to avoid warning
@ -2936,17 +2957,28 @@ static void Msg_ShowASentOrReceivedMessage (Msg_TypeOfMessages_t TypeOfMessages,
"<label class=\"MSG_TIT\">"
"%s: "
"</label>"
"</td>"
"<td colspan=\"2\" class=\"MSG_TXT LEFT_TOP\">",
"</td>",
Txt_MSG_Message);
Msg_GetMsgContent (MsgCod,Content);
/***** Initialize image *****/
Img_ImageConstructor (&Image);
/***** Get message content and optional image *****/
Msg_GetMsgContent (MsgCod,Content,&Image);
/***** Show content and image *****/
fprintf (Gbl.F.Out,"<td colspan=\"2\" class=\"MSG_TXT LEFT_TOP\">");
if (Content[0])
{
Msg_WriteMsgContent (Content,Cns_MAX_BYTES_LONG_TEXT,true,false);
fprintf (Gbl.F.Out,"<br />&nbsp;");
// fprintf (Gbl.F.Out,"<br />&nbsp;");
}
Img_ShowImage (&Image,"MSG_IMG");
fprintf (Gbl.F.Out,"</td>"
"</tr>");
/***** Free image *****/
Img_ImageDestructor (&Image);
}
/***** Free memory used for user's data *****/