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 *****************************/ /****************************** Public constants *****************************/
/*****************************************************************************/ /*****************************************************************************/
#define Log_PLATFORM_VERSION "SWAD 15.191 (2016-04-10)" #define Log_PLATFORM_VERSION "SWAD 15.192 (2016-04-10)"
#define CSS_FILE "swad15.190.1.css" #define CSS_FILE "swad15.192.css"
#define JS_FILE "swad15.190.1.js" #define JS_FILE "swad15.190.1.js"
// Number of lines (includes comments but not blank lines) has been got with the following command: // 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 // 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.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.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) 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 *****/ /***** Table forum_post *****/
/* /*
mysql> DESCRIBE forum_post; mysql> DESCRIBE forum_post;
+-----------+----------+------+-----+---------------------+----------------+ +------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra | | Field | Type | Null | Key | Default | Extra |
+-----------+----------+------+-----+---------------------+----------------+ +------------+--------------+------+-----+---------+----------------+
| PstCod | int(11) | NO | PRI | NULL | auto_increment | | PstCod | int(11) | NO | PRI | NULL | auto_increment |
| ThrCod | int(11) | NO | MUL | NULL | | | ThrCod | int(11) | NO | MUL | NULL | |
| UsrCod | int(11) | NO | MUL | NULL | | | UsrCod | int(11) | NO | MUL | NULL | |
| CreatTime | datetime | NO | MUL | NULL | | | CreatTime | datetime | NO | MUL | NULL | |
| ModifTime | datetime | NO | MUL | 0000-00-00 00:00:00 | | | ModifTime | datetime | NO | MUL | NULL | |
| NumNotif | int(11) | NO | | 0 | | | NumNotif | int(11) | NO | | 0 | |
| Subject | text | NO | | NULL | | | Subject | text | NO | | NULL | |
| Content | longtext | NO | | NULL | | | Content | longtext | NO | | NULL | |
+-----------+----------+------+-----+---------------------+----------------+ | ImageName | varchar(43) | NO | | NULL | |
8 rows in set (0.00 sec) | ImageTitle | varchar(255) | NO | | NULL | |
+------------+--------------+------+-----+---------+----------------+
10 rows in set (0.00 sec)
*/ */
DB_CreateTable ("CREATE TABLE IF NOT EXISTS forum_post (" DB_CreateTable ("CREATE TABLE IF NOT EXISTS forum_post ("
"PstCod INT NOT NULL AUTO_INCREMENT," "PstCod INT NOT NULL AUTO_INCREMENT,"
@ -1123,6 +1125,8 @@ mysql> DESCRIBE forum_post;
"NumNotif INT NOT NULL DEFAULT 0," "NumNotif INT NOT NULL DEFAULT 0,"
"Subject TEXT NOT NULL," "Subject TEXT NOT NULL,"
"Content LONGTEXT NOT NULL," "Content LONGTEXT NOT NULL,"
"ImageName VARCHAR(43) NOT NULL,"
"ImageTitle VARCHAR(255) NOT NULL,"
"UNIQUE INDEX(PstCod)," "UNIQUE INDEX(PstCod),"
"INDEX(ThrCod)," "INDEX(ThrCod),"
"INDEX(UsrCod)," "INDEX(UsrCod),"
@ -1570,38 +1574,46 @@ mysql> DESCRIBE msg_banned;
/***** Table msg_content *****/ /***** Table msg_content *****/
/* /*
mysql> DESCRIBE msg_content; mysql> DESCRIBE msg_content;
+---------+----------+------+-----+---------+----------------+ +------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra | | Field | Type | Null | Key | Default | Extra |
+---------+----------+------+-----+---------+----------------+ +------------+--------------+------+-----+---------+----------------+
| MsgCod | int(11) | NO | PRI | NULL | auto_increment | | MsgCod | int(11) | NO | PRI | NULL | auto_increment |
| Subject | text | NO | MUL | NULL | | | Subject | text | NO | MUL | NULL | |
| Content | longtext | NO | | NULL | | | Content | longtext | NO | | NULL | |
+---------+----------+------+-----+---------+----------------+ | ImageName | varchar(43) | NO | | NULL | |
3 rows in set (0.00 sec) | ImageTitle | varchar(255) | NO | | NULL | |
+------------+--------------+------+-----+---------+----------------+
5 rows in set (0.01 sec)
*/ */
DB_CreateTable ("CREATE TABLE IF NOT EXISTS msg_content (" DB_CreateTable ("CREATE TABLE IF NOT EXISTS msg_content ("
"MsgCod INT NOT NULL AUTO_INCREMENT," "MsgCod INT NOT NULL AUTO_INCREMENT,"
"Subject TEXT NOT NULL," "Subject TEXT NOT NULL,"
"Content LONGTEXT NOT NULL," "Content LONGTEXT NOT NULL,"
"ImageName VARCHAR(43) NOT NULL,"
"ImageTitle VARCHAR(255) NOT NULL,"
"UNIQUE INDEX(MsgCod)," "UNIQUE INDEX(MsgCod),"
"FULLTEXT(Subject,Content)) ENGINE = MYISAM;"); "FULLTEXT(Subject,Content)) ENGINE = MYISAM;");
/***** Table msg_content_deleted *****/ /***** Table msg_content_deleted *****/
/* /*
mysql> DESCRIBE msg_content_deleted; mysql> DESCRIBE msg_content_deleted;
+---------+----------+------+-----+---------+-------+ +------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra | | Field | Type | Null | Key | Default | Extra |
+---------+----------+------+-----+---------+-------+ +------------+--------------+------+-----+---------+-------+
| MsgCod | int(11) | NO | PRI | NULL | | | MsgCod | int(11) | NO | PRI | NULL | |
| Subject | text | NO | MUL | NULL | | | Subject | text | NO | MUL | NULL | |
| Content | longtext | NO | | NULL | | | Content | longtext | NO | | NULL | |
+---------+----------+------+-----+---------+-------+ | ImageName | varchar(43) | NO | | NULL | |
3 rows in set (0.00 sec) | ImageTitle | varchar(255) | NO | | NULL | |
+------------+--------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
*/ */
DB_CreateTable ("CREATE TABLE IF NOT EXISTS msg_content_deleted (" DB_CreateTable ("CREATE TABLE IF NOT EXISTS msg_content_deleted ("
"MsgCod INT NOT NULL," "MsgCod INT NOT NULL,"
"Subject TEXT NOT NULL," "Subject TEXT NOT NULL,"
"Content LONGTEXT NOT NULL," "Content LONGTEXT NOT NULL,"
"ImageName VARCHAR(43) NOT NULL,"
"ImageTitle VARCHAR(255) NOT NULL,"
"UNIQUE INDEX(MsgCod)," "UNIQUE INDEX(MsgCod),"
"FULLTEXT(Subject,Content)) ENGINE = MYISAM;"); "FULLTEXT(Subject,Content)) ENGINE = MYISAM;");

View File

@ -250,6 +250,26 @@ const Act_Action_t For_ActionsDisPstFor[For_NUM_TYPES_FORUM] =
/***************************** Private prototypes ***************************/ /***************************** 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 void For_UpdateThrReadTime (long ThrCod,time_t ReadTimeUTC);
static unsigned For_GetNumOfReadersOfThr (long ThrCod); static unsigned For_GetNumOfReadersOfThr (long ThrCod);
static unsigned For_GetNumOfWritersInThr (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 LastPst,char *LastSubject,
bool NewPst,bool ICanModerateForum); bool NewPst,bool ICanModerateForum);
static void For_GetPstData (long PstCod,long *UsrCod,time_t *CreatTimeUTC, 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); 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 *****************/ /******************** Get if a forum post exists in database *****************/
/*****************************************************************************/ /*****************************************************************************/
bool For_GetIfForumPstExists (long PstCod) static bool For_GetIfForumPstExists (long PstCod)
{ {
char Query[512]; char Query[512];
@ -376,7 +396,7 @@ bool For_GetIfForumPstExists (long PstCod)
/*********************** Get if a forum post is enabled **********************/ /*********************** Get if a forum post is enabled **********************/
/*****************************************************************************/ /*****************************************************************************/
bool For_GetIfPstIsEnabled (long PstCod) static bool For_GetIfPstIsEnabled (long PstCod)
{ {
char Query[512]; char Query[512];
@ -391,7 +411,7 @@ bool For_GetIfPstIsEnabled (long PstCod)
/****************** Delete post from table of disabled posts *****************/ /****************** Delete post from table of disabled posts *****************/
/*****************************************************************************/ /*****************************************************************************/
void For_DeletePstFromDisabledPstTable (long PstCod) static void For_DeletePstFromDisabledPstTable (long PstCod)
{ {
char Query[512]; char Query[512];
@ -406,7 +426,7 @@ void For_DeletePstFromDisabledPstTable (long PstCod)
/****************** Insert post into table of banned posts *******************/ /****************** Insert post into table of banned posts *******************/
/*****************************************************************************/ /*****************************************************************************/
void For_InsertPstIntoBannedPstTable (long PstCod) static void For_InsertPstIntoBannedPstTable (long PstCod)
{ {
char Query[512]; char Query[512];
@ -422,16 +442,35 @@ void For_InsertPstIntoBannedPstTable (long PstCod)
/************** Insert a post new in the table of posts of forums ************/ /************** 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 *****/ /***** Insert forum post in the database *****/
sprintf (Query,"INSERT INTO forum_post" sprintf (Query,"INSERT INTO forum_post"
" (ThrCod,UsrCod,CreatTime,ModifTime,NumNotif,Subject,Content)" " (ThrCod,UsrCod,CreatTime,ModifTime,NumNotif,"
" VALUES ('%ld','%ld',NOW(),NOW(),'0','%s','%s')", "Subject,Content,ImageName,ImageTitle)"
ThrCod,UsrCod,Subject,Content); " VALUES ('%ld','%ld',NOW(),NOW(),'0',"
return DB_QueryINSERTandReturnCode (Query,"can not create a new post in a forum"); "'%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 // Return true if the post thread is deleted
bool For_RemoveForumPst (long PstCod) static bool For_RemoveForumPst (long PstCod)
{ {
char Query[512]; char Query[512];
long ThrCod; long ThrCod;
@ -471,7 +510,7 @@ bool For_RemoveForumPst (long PstCod)
/*********** Get the number of posts in the thread than holds a post *********/ /*********** 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]; char Query[512];
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
@ -501,7 +540,7 @@ unsigned For_NumPstsInThrWithPstCod (long PstCod,long *ThrCod)
/*****************************************************************************/ /*****************************************************************************/
// Returns the code of the new inserted thread // 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]; char Query[512];
@ -553,7 +592,7 @@ long For_InsertForumThread (For_ForumType_t ForumType,long FirstPstCod)
/*************** Delete a thread from the forum thread table *****************/ /*************** Delete a thread from the forum thread table *****************/
/*****************************************************************************/ /*****************************************************************************/
void For_RemoveThreadOnly (long ThrCod) static void For_RemoveThreadOnly (long ThrCod)
{ {
char Query[512]; char Query[512];
@ -573,7 +612,7 @@ void For_RemoveThreadOnly (long ThrCod)
/*************** Delete a thread from the forum thread table *****************/ /*************** Delete a thread from the forum thread table *****************/
/*****************************************************************************/ /*****************************************************************************/
void For_RemoveThreadAndItsPsts (long ThrCod) static void For_RemoveThreadAndItsPsts (long ThrCod)
{ {
char Query[512]; char Query[512];
@ -598,7 +637,7 @@ void For_RemoveThreadAndItsPsts (long ThrCod)
/********************* Get the thread subject from a thread ******************/ /********************* 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]; char Query[512];
MYSQL_RES *mysql_res; 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 **********/ /********* 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]; 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 *****************/ /************** 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]; char Query[512];
@ -690,7 +729,7 @@ void For_UpdateThrLastPst (long ThrCod,long LastPstCod)
/**************** Get the code of the last post of a thread ******************/ /**************** Get the code of the last post of a thread ******************/
/*****************************************************************************/ /*****************************************************************************/
long For_GetLastPstCod (long ThrCod) static long For_GetLastPstCod (long ThrCod)
{ {
char Query[512]; char Query[512];
MYSQL_RES *mysql_res; 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 OriginalContent[Cns_MAX_BYTES_LONG_TEXT+1];
char Subject[Cns_MAX_BYTES_SUBJECT+1]; char Subject[Cns_MAX_BYTES_SUBJECT+1];
char Content[Cns_MAX_BYTES_LONG_TEXT+1]; char Content[Cns_MAX_BYTES_LONG_TEXT+1];
struct Image Image;
bool Enabled; bool Enabled;
/***** Initialize structure with user's data *****/ /***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat); Usr_UsrDataConstructor (&UsrDat);
/***** Initialize image *****/
Img_ImageConstructor (&Image);
/***** Check if post is enabled *****/ /***** Check if post is enabled *****/
Enabled = For_GetIfPstIsEnabled (PstCod); Enabled = For_GetIfPstIsEnabled (PstCod);
/***** Get data of post *****/ /***** Get data of post *****/
For_GetPstData (PstCod,&UsrDat.UsrCod,&CreatTimeUTC,Subject,OriginalContent); For_GetPstData (PstCod,&UsrDat.UsrCod,&CreatTimeUTC,
Subject,OriginalContent,&Image);
if (Enabled) if (Enabled)
{ {
/* Return this subject as last subject */ /* 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); strncpy (Content,OriginalContent,Cns_MAX_BYTES_LONG_TEXT);
Content[Cns_MAX_BYTES_LONG_TEXT] = '\0'; Content[Cns_MAX_BYTES_LONG_TEXT] = '\0';
Msg_WriteMsgContent (Content,Cns_MAX_BYTES_LONG_TEXT,true,false); Msg_WriteMsgContent (Content,Cns_MAX_BYTES_LONG_TEXT,true,false);
/***** Show image *****/
Img_ShowImage (&Image,"FOR_IMG");
} }
else else
fprintf (Gbl.F.Out,"%s",Txt_This_post_has_been_banned_probably_for_not_satisfy_the_rules_of_the_forums); 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>" "</td>"
"</tr>"); "</tr>");
/***** Free image *****/
Img_ImageDestructor (&Image);
/***** Free memory used for user's data *****/ /***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat); Usr_UsrDataDestructor (&UsrDat);
} }
@ -1262,9 +1312,10 @@ static void For_ShowAForumPost (struct ForumThread *Thr,unsigned PstNum,long Pst
/*****************************************************************************/ /*****************************************************************************/
/*************************** Get data of a forum post ************************/ /*************************** 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, 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]; char Query[512];
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
@ -1272,7 +1323,8 @@ static void For_GetPstData (long PstCod,long *UsrCod,time_t *CreatTimeUTC,
unsigned NumRows; unsigned NumRows;
/***** Get data of a post from database *****/ /***** 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'", " FROM forum_post WHERE PstCod='%ld'",
PstCod); PstCod);
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get data of a post"); 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]); *CreatTimeUTC = Dat_GetUNIXTimeFromStr (row[1]);
/****** Get subject (row[2]) *****/ /****** 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]) *****/ /****** 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 *****/ /***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res); DB_FreeMySQLResult (&mysql_res);
@ -2461,14 +2519,16 @@ void For_ShowForumThrs (void)
switch (Gbl.Forum.SelectedOrderType) switch (Gbl.Forum.SelectedOrderType)
{ {
case For_FIRST_MSG: 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" " WHERE forum_thread.ForumType='%u'%s"
" AND forum_thread.FirstPstCod=forum_post.PstCod" " AND forum_thread.FirstPstCod=forum_post.PstCod"
" ORDER BY forum_post.CreatTime DESC", " ORDER BY forum_post.CreatTime DESC",
(unsigned) Gbl.Forum.ForumType,SubQuery); (unsigned) Gbl.Forum.ForumType,SubQuery);
break; break;
case For_LAST_MSG: 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" " WHERE forum_thread.ForumType='%u'%s"
" AND forum_thread.LastPstCod=forum_post.PstCod" " AND forum_thread.LastPstCod=forum_post.PstCod"
" ORDER BY forum_post.CreatTime DESC", " ORDER BY forum_post.CreatTime DESC",
@ -3533,8 +3593,10 @@ static void For_WriteThrSubject (long ThrCod)
long FirstPstCod; long FirstPstCod;
/***** Get subject of a thread from database *****/ /***** Get subject of a thread from database *****/
sprintf (Query,"SELECT forum_post.PstCod,forum_post.Subject FROM forum_thread,forum_post" sprintf (Query,"SELECT forum_post.PstCod,forum_post.Subject"
" WHERE forum_thread.ThrCod='%ld' AND forum_thread.FirstPstCod=forum_post.PstCod", " FROM forum_thread,forum_post"
" WHERE forum_thread.ThrCod='%ld'"
" AND forum_thread.FirstPstCod=forum_post.PstCod",
ThrCod); ThrCod);
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get the subject of a thread"); 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); For_IMAGE_SAVED_QUALITY);
/***** Create a new message *****/ /***** 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 // ThrCod has been received from form
/***** Create last message of the thread *****/ /***** 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 *****/ /***** Modify last message of the thread *****/
For_UpdateThrLastPst (ThrCod,PstCod); 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 *****/ /***** Create new thread with unknown first and last message codes *****/
ThrCod = For_InsertForumThread (Gbl.Forum.ForumType,-1L); ThrCod = For_InsertForumThread (Gbl.Forum.ForumType,-1L);
/***** Create first (and last) message of the thread *****/ /***** 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 *****/ /***** Update first and last posts of new thread *****/
For_UpdateThrFirstAndLastPst (ThrCod,PstCod,PstCod); For_UpdateThrFirstAndLastPst (ThrCod,PstCod,PstCod);
@ -3972,7 +4036,8 @@ void For_DelPst (void)
Lay_ShowErrorAndExit ("The post to remove no longer exists."); Lay_ShowErrorAndExit ("The post to remove no longer exists.");
/* Check if I am the author of the message */ /* 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) if (Gbl.Usrs.Me.UsrDat.UsrCod != UsrDat.UsrCod)
Lay_ShowErrorAndExit ("You can not remove post because you aren't the author."); 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_EnbPst (void);
void For_DisPst (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); 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); unsigned long For_GetNumPostsUsr (long UsrCod);
void For_DeleteThrFromReadThrs (long ThrCod); void For_DeleteThrFromReadThrs (long ThrCod);
void For_RemoveUsrFromReadThrs (long UsrCod); 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_ContractSentMsg (long MsgCod);
static void Msg_ContractReceivedMsg (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, static unsigned long Msg_DelSomeRecOrSntMsgsUsr (Msg_TypeOfMessages_t TypeOfMessages,long UsrCod,
long FilterCrsCod,const char *FilterFromToSubquery); 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, static void Msg_GetMsgSntData (long MsgCod,long *CrsCod,long *UsrCod,
time_t *CreatTimeUTC,char *Subject,bool *Deleted); 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_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, static void Msg_WriteFormToReply (long MsgCod,long CrsCod,const char *Subject,
@ -828,7 +829,7 @@ void Msg_RecMsgFromUsr (void)
if (!MsgAlreadyInserted) if (!MsgAlreadyInserted)
{ {
// The message is inserted only once in the table of messages sent // 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; MsgAlreadyInserted = true;
} }
@ -1356,15 +1357,25 @@ void Msg_SetReceivedMsgAsOpen (long MsgCod,long UsrCod)
/*****************************************************************************/ /*****************************************************************************/
// Return the code of the new inserted message // 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; 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 *****/ /***** Insert message subject and content in the database *****/
sprintf (Query,"INSERT INTO msg_content (Subject,Content)" sprintf (Query,"INSERT INTO msg_content"
" VALUES ('%s','%s')", " (Subject,Content,ImageName,ImageTitle)"
Subject,Content); " VALUES ('%s','%s','%s','%s')",
Subject,Content,Image->Name,Image->Title ? Image->Title : "");
MsgCod = DB_QueryINSERTandReturnCode (Query,"can not create message"); MsgCod = DB_QueryINSERTandReturnCode (Query,"can not create message");
/***** Insert message in sent messages *****/ /***** Insert message in sent messages *****/
@ -1375,6 +1386,9 @@ static long Msg_InsertNewMsg (const char *Subject,const char *Content)
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryINSERT (Query,"can not create message"); DB_QueryINSERT (Query,"can not create message");
/***** Free space used for query *****/
free ((void *) Query);
/***** Increment number of messages sent by me *****/ /***** Increment number of messages sent by me *****/
Prf_IncrementNumMsgSntUsr (Gbl.Usrs.Me.UsrDat.UsrCod); Prf_IncrementNumMsgSntUsr (Gbl.Usrs.Me.UsrDat.UsrCod);
@ -1465,7 +1479,8 @@ static void Msg_InsertReceivedMsgIntoDB (long MsgCod,long UsrCod,bool NotifyByEm
char Query[512]; char Query[512];
/***** Insert message received in the database *****/ /***** 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')", " VALUES ('%ld','%ld','%c','N','N','N')",
MsgCod,UsrCod, MsgCod,UsrCod,
NotifyByEmail ? 'Y' : NotifyByEmail ? 'Y' :
@ -2683,7 +2698,8 @@ void Msg_GetMsgSubject (long MsgCod,char *Subject)
{ {
/***** Get subject *****/ /***** Get subject *****/
row = mysql_fetch_row (mysql_res); 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 else
Subject[0] = '\0'; 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_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows; unsigned long NumRows;
/***** Get content of message from database *****/ /***** 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); MsgCod);
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get the content of a message"); 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); strncpy (Content,row[0],Cns_MAX_BYTES_LONG_TEXT);
Content[Cns_MAX_BYTES_LONG_TEXT] = '\0'; 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 *****/ /***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res); DB_FreeMySQLResult (&mysql_res);
} }
@ -2811,6 +2831,7 @@ static void Msg_ShowASentOrReceivedMessage (Msg_TypeOfMessages_t TypeOfMessages,
long CrsCod; long CrsCod;
char Subject[Cns_MAX_BYTES_SUBJECT+1]; char Subject[Cns_MAX_BYTES_SUBJECT+1];
char Content[Cns_MAX_BYTES_LONG_TEXT+1]; char Content[Cns_MAX_BYTES_LONG_TEXT+1];
struct Image Image;
bool Deleted; bool Deleted;
bool Open = true; bool Open = true;
bool Replied = false; // Initialized to avoid warning bool Replied = false; // Initialized to avoid warning
@ -2936,17 +2957,28 @@ static void Msg_ShowASentOrReceivedMessage (Msg_TypeOfMessages_t TypeOfMessages,
"<label class=\"MSG_TIT\">" "<label class=\"MSG_TIT\">"
"%s: " "%s: "
"</label>" "</label>"
"</td>" "</td>",
"<td colspan=\"2\" class=\"MSG_TXT LEFT_TOP\">",
Txt_MSG_Message); 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]) if (Content[0])
{ {
Msg_WriteMsgContent (Content,Cns_MAX_BYTES_LONG_TEXT,true,false); 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>" fprintf (Gbl.F.Out,"</td>"
"</tr>"); "</tr>");
/***** Free image *****/
Img_ImageDestructor (&Image);
} }
/***** Free memory used for user's data *****/ /***** Free memory used for user's data *****/