Version 18.11.6

This commit is contained in:
Antonio Cañas Vargas 2018-10-31 09:40:43 +01:00
parent b1fbfa2f5f
commit ad7ec2156c
3 changed files with 519 additions and 450 deletions

View File

@ -355,10 +355,11 @@ En OpenSWAD:
ps2pdf source.ps destination.pdf ps2pdf source.ps destination.pdf
*/ */
#define Log_PLATFORM_VERSION "SWAD 18.11.5 (2018-10-31)" #define Log_PLATFORM_VERSION "SWAD 18.11.6 (2018-10-31)"
#define CSS_FILE "swad18.4.css" #define CSS_FILE "swad18.4.css"
#define JS_FILE "swad17.17.1.js" #define JS_FILE "swad17.17.1.js"
/* /*
Version 18.11.6: Oct 31, 2018 Joining building and performing query into one function. (235687 lines)
Version 18.11.5: Oct 31, 2018 Joining building and performing query into one function. (235619 lines) Version 18.11.5: Oct 31, 2018 Joining building and performing query into one function. (235619 lines)
Version 18.11.4: Oct 30, 2018 Joining building and performing query into one function. (235593 lines) Version 18.11.4: Oct 30, 2018 Joining building and performing query into one function. (235593 lines)
Version 18.11.3: Oct 30, 2018 Joining building and performing query into one function. (235553 lines) Version 18.11.3: Oct 30, 2018 Joining building and performing query into one function. (235553 lines)

View File

@ -69,9 +69,9 @@ extern struct Globals Gbl;
/***************************** Private prototypes ****************************/ /***************************** Private prototypes ****************************/
/*****************************************************************************/ /*****************************************************************************/
static unsigned Fol_GetUsrsWhoToFollow (unsigned MaxUsrsToShow, static unsigned long Fol_GetUsrsWhoToFollow (unsigned long MaxUsrsToShow,
bool OnlyUsrsWithPhotos, bool OnlyUsrsWithPhotos,
MYSQL_RES **mysql_res); MYSQL_RES **mysql_res);
static void Fol_PutIconsWhoToFollow (void); static void Fol_PutIconsWhoToFollow (void);
static void Fol_PutIconToUpdateWhoToFollow (void); static void Fol_PutIconToUpdateWhoToFollow (void);
@ -117,8 +117,8 @@ void Fol_SuggestUsrsToFollowMainZone (void)
extern const char *Txt_No_user_to_whom_you_can_follow_Try_again_later; extern const char *Txt_No_user_to_whom_you_can_follow_Try_again_later;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned NumUsrs; unsigned long NumUsrs;
unsigned NumUsr; unsigned long NumUsr;
struct UsrData UsrDat; struct UsrData UsrDat;
/***** Put links to request my public profile and another user's profile *****/ /***** Put links to request my public profile and another user's profile *****/
@ -185,8 +185,8 @@ void Fol_SuggestUsrsToFollowMainZoneOnRightColumn (void)
extern const char *Txt_No_user_to_whom_you_can_follow_Try_again_later; extern const char *Txt_No_user_to_whom_you_can_follow_Try_again_later;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned NumUsrs; unsigned long NumUsrs;
unsigned NumUsr; unsigned long NumUsr;
struct UsrData UsrDat; struct UsrData UsrDat;
/***** Get users *****/ /***** Get users *****/
@ -243,9 +243,9 @@ void Fol_SuggestUsrsToFollowMainZoneOnRightColumn (void)
/*************************** Get users to follow *****************************/ /*************************** Get users to follow *****************************/
/*****************************************************************************/ /*****************************************************************************/
static unsigned Fol_GetUsrsWhoToFollow (unsigned MaxUsrsToShow, static unsigned long Fol_GetUsrsWhoToFollow (unsigned long MaxUsrsToShow,
bool OnlyUsrsWithPhotos, bool OnlyUsrsWithPhotos,
MYSQL_RES **mysql_res) MYSQL_RES **mysql_res)
{ {
extern const char *Pri_VisibilityDB[Pri_NUM_OPTIONS_PRIVACY]; extern const char *Pri_VisibilityDB[Pri_NUM_OPTIONS_PRIVACY];
char SubQuery1[256]; char SubQuery1[256];
@ -291,119 +291,118 @@ static unsigned Fol_GetUsrsWhoToFollow (unsigned MaxUsrsToShow,
/***** Build query to get users to follow *****/ /***** Build query to get users to follow *****/
// Get only users with surname 1 and first name // Get only users with surname 1 and first name
DB_BuildQuery ("SELECT DISTINCT UsrCod FROM" return DB_QuerySELECT (mysql_res,"can not get users to follow",
" (" "SELECT DISTINCT UsrCod FROM"
/***** Likely known users *****/ " ("
"(SELECT DISTINCT UsrCod FROM" /***** Likely known users *****/
" (" "(SELECT DISTINCT UsrCod FROM"
// Users followed by my followed whose privacy is " ("
// Pri_VISIBILITY_SYSTEM or Pri_VISIBILITY_WORLD // Users followed by my followed whose privacy is
"(" // Pri_VISIBILITY_SYSTEM or Pri_VISIBILITY_WORLD
"SELECT DISTINCT usr_follow.FollowedCod AS UsrCod" "("
" FROM usr_follow," "SELECT DISTINCT usr_follow.FollowedCod AS UsrCod"
"(SELECT FollowedCod FROM usr_follow" " FROM usr_follow,"
" WHERE FollowerCod=%ld) AS my_followed," "(SELECT FollowedCod FROM usr_follow"
" usr_data" " WHERE FollowerCod=%ld) AS my_followed,"
" WHERE usr_follow.FollowerCod=my_followed.FollowedCod" " usr_data"
" AND usr_follow.FollowedCod<>%ld" " WHERE usr_follow.FollowerCod=my_followed.FollowedCod"
" AND usr_follow.FollowedCod=usr_data.UsrCod" " AND usr_follow.FollowedCod<>%ld"
" AND usr_data.ProfileVisibility IN ('%s','%s')" " AND usr_follow.FollowedCod=usr_data.UsrCod"
" AND usr_data.Surname1<>''" // Surname 1 not empty " AND usr_data.ProfileVisibility IN ('%s','%s')"
" AND usr_data.FirstName<>''" // First name not empty " AND usr_data.Surname1<>''" // Surname 1 not empty
"%s" // SubQuery1 " AND usr_data.FirstName<>''" // First name not empty
")" "%s" // SubQuery1
" UNION " ")"
// Users who share any course with me " UNION "
// and whose privacy is Pri_VISIBILITY_COURSE, // Users who share any course with me
// Pri_VISIBILITY_SYSTEM or Pri_VISIBILITY_WORLD // and whose privacy is Pri_VISIBILITY_COURSE,
"(" // Pri_VISIBILITY_SYSTEM or Pri_VISIBILITY_WORLD
"SELECT DISTINCT crs_usr.UsrCod" "("
" FROM crs_usr," "SELECT DISTINCT crs_usr.UsrCod"
"(SELECT CrsCod FROM crs_usr" " FROM crs_usr,"
" WHERE UsrCod=%ld) AS my_crs," "(SELECT CrsCod FROM crs_usr"
" usr_data" " WHERE UsrCod=%ld) AS my_crs,"
" WHERE crs_usr.CrsCod=my_crs.CrsCod" " usr_data"
" AND crs_usr.UsrCod<>%ld" " WHERE crs_usr.CrsCod=my_crs.CrsCod"
" AND crs_usr.UsrCod=usr_data.UsrCod" " AND crs_usr.UsrCod<>%ld"
" AND usr_data.ProfileVisibility IN ('%s','%s','%s')" " AND crs_usr.UsrCod=usr_data.UsrCod"
" AND usr_data.Surname1<>''" // Surname 1 not empty " AND usr_data.ProfileVisibility IN ('%s','%s','%s')"
" AND usr_data.FirstName<>''" // First name not empty " AND usr_data.Surname1<>''" // Surname 1 not empty
"%s" // SubQuery2 " AND usr_data.FirstName<>''" // First name not empty
")" "%s" // SubQuery2
" UNION " ")"
// Users who share any course with me with another role " UNION "
// and whose privacy is Pri_VISIBILITY_USER // Users who share any course with me with another role
"(" // and whose privacy is Pri_VISIBILITY_USER
"SELECT DISTINCT crs_usr.UsrCod" "("
" FROM crs_usr," "SELECT DISTINCT crs_usr.UsrCod"
"(SELECT CrsCod,Role FROM crs_usr" " FROM crs_usr,"
" WHERE UsrCod=%ld) AS my_crs_role," "(SELECT CrsCod,Role FROM crs_usr"
" usr_data" " WHERE UsrCod=%ld) AS my_crs_role,"
" WHERE crs_usr.CrsCod=my_crs_role.CrsCod" " usr_data"
" AND crs_usr.Role<>my_crs_role.Role" " WHERE crs_usr.CrsCod=my_crs_role.CrsCod"
" AND crs_usr.UsrCod=usr_data.UsrCod" " AND crs_usr.Role<>my_crs_role.Role"
" AND usr_data.ProfileVisibility='%s'" " AND crs_usr.UsrCod=usr_data.UsrCod"
" AND usr_data.Surname1<>''" // Surname 1 not empty " AND usr_data.ProfileVisibility='%s'"
" AND usr_data.FirstName<>''" // First name not empty " AND usr_data.Surname1<>''" // Surname 1 not empty
"%s" // SubQuery3 " AND usr_data.FirstName<>''" // First name not empty
")" "%s" // SubQuery3
") AS LikelyKnownUsrsToFollow" ")"
// Do not select my followed ") AS LikelyKnownUsrsToFollow"
" WHERE UsrCod NOT IN" // Do not select my followed
" (SELECT FollowedCod FROM usr_follow" " WHERE UsrCod NOT IN"
" WHERE FollowerCod=%ld)" " (SELECT FollowedCod FROM usr_follow"
// Get only MaxUsrsToShow * 2 users " WHERE FollowerCod=%ld)"
" ORDER BY RAND() LIMIT %u" // Get only MaxUsrsToShow * 2 users
")" " ORDER BY RAND() LIMIT %lu"
" UNION " ")"
"(" " UNION "
/***** Likely unknown users *****/ "("
// Add some likely unknown random users with privacy /***** Likely unknown users *****/
// Pri_VISIBILITY_SYSTEM or Pri_VISIBILITY_WORLD // Add some likely unknown random users with privacy
"SELECT UsrCod FROM usr_data" // Pri_VISIBILITY_SYSTEM or Pri_VISIBILITY_WORLD
" WHERE UsrCod<>%ld" "SELECT UsrCod FROM usr_data"
" AND ProfileVisibility IN ('%s','%s')" " WHERE UsrCod<>%ld"
" AND Surname1<>''" // Surname 1 not empty " AND ProfileVisibility IN ('%s','%s')"
" AND FirstName<>''" // First name not empty " AND Surname1<>''" // Surname 1 not empty
"%s" // SubQuery4 " AND FirstName<>''" // First name not empty
// Do not select my followed "%s" // SubQuery4
" AND UsrCod NOT IN" // Do not select my followed
" (SELECT FollowedCod FROM usr_follow" " AND UsrCod NOT IN"
" WHERE FollowerCod=%ld)" " (SELECT FollowedCod FROM usr_follow"
// Get only MaxUsrsToShow users " WHERE FollowerCod=%ld)"
" ORDER BY RAND() LIMIT %u" // Get only MaxUsrsToShow users
")" " ORDER BY RAND() LIMIT %lu"
") AS UsrsToFollow" ")"
// Get only MaxUsrsToShow users ") AS UsrsToFollow"
" ORDER BY RAND() LIMIT %u", // Get only MaxUsrsToShow users
" ORDER BY RAND() LIMIT %lu",
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
Pri_VisibilityDB[Pri_VISIBILITY_SYSTEM], Pri_VisibilityDB[Pri_VISIBILITY_SYSTEM],
Pri_VisibilityDB[Pri_VISIBILITY_WORLD ], Pri_VisibilityDB[Pri_VISIBILITY_WORLD ],
SubQuery1, SubQuery1,
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
Pri_VisibilityDB[Pri_VISIBILITY_COURSE], Pri_VisibilityDB[Pri_VISIBILITY_COURSE],
Pri_VisibilityDB[Pri_VISIBILITY_SYSTEM], Pri_VisibilityDB[Pri_VISIBILITY_SYSTEM],
Pri_VisibilityDB[Pri_VISIBILITY_WORLD ], Pri_VisibilityDB[Pri_VISIBILITY_WORLD ],
SubQuery2, SubQuery2,
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
Pri_VisibilityDB[Pri_VISIBILITY_USER ], Pri_VisibilityDB[Pri_VISIBILITY_USER ],
SubQuery3, SubQuery3,
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
MaxUsrsToShow * 2, // 2/3 likely known users MaxUsrsToShow * 2, // 2/3 likely known users
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
Pri_VisibilityDB[Pri_VISIBILITY_SYSTEM], Pri_VisibilityDB[Pri_VISIBILITY_SYSTEM],
Pri_VisibilityDB[Pri_VISIBILITY_WORLD ], Pri_VisibilityDB[Pri_VISIBILITY_WORLD ],
SubQuery4, SubQuery4,
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
MaxUsrsToShow, // 1/3 likely unknown users MaxUsrsToShow, // 1/3 likely unknown users
MaxUsrsToShow); MaxUsrsToShow);
return DB_QuerySELECT_new (mysql_res,"can not get users to follow");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -661,18 +660,20 @@ static void Fol_ListFollowingUsr (struct UsrData *UsrDat)
extern const char *Txt_User_not_found_or_you_do_not_have_permission_; extern const char *Txt_User_not_found_or_you_do_not_have_permission_;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned NumUsrs; unsigned long NumUsrs;
unsigned NumUsr; unsigned long NumUsr;
struct UsrData FollowingUsrDat; struct UsrData FollowingUsrDat;
/***** Show user's profile *****/ /***** Show user's profile *****/
if (Prf_ShowUserProfile (UsrDat)) if (Prf_ShowUserProfile (UsrDat))
{ {
/***** Check if a user is a follower of another user *****/ /***** Check if a user is a follower of another user *****/
DB_BuildQuery ("SELECT FollowedCod FROM usr_follow" NumUsrs = DB_QuerySELECT (&mysql_res,"can not get followed users",
" WHERE FollowerCod=%ld ORDER BY FollowTime DESC", "SELECT FollowedCod FROM usr_follow"
UsrDat->UsrCod); " WHERE FollowerCod=%ld"
NumUsrs = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get followed users"); " ORDER BY FollowTime DESC",
UsrDat->UsrCod);
if (NumUsrs) if (NumUsrs)
{ {
/***** Initialize structure with user's data *****/ /***** Initialize structure with user's data *****/
@ -744,8 +745,8 @@ static void Fol_ListFollowersUsr (struct UsrData *UsrDat)
extern const char *Txt_User_not_found_or_you_do_not_have_permission_; extern const char *Txt_User_not_found_or_you_do_not_have_permission_;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned NumUsrs; unsigned long NumUsrs;
unsigned NumUsr; unsigned long NumUsr;
struct UsrData FollowerUsrDat; struct UsrData FollowerUsrDat;
bool ItsMe; bool ItsMe;
@ -753,10 +754,12 @@ static void Fol_ListFollowersUsr (struct UsrData *UsrDat)
if (Prf_ShowUserProfile (UsrDat)) if (Prf_ShowUserProfile (UsrDat))
{ {
/***** Check if a user is a follower of another user *****/ /***** Check if a user is a follower of another user *****/
DB_BuildQuery ("SELECT FollowerCod FROM usr_follow" NumUsrs = DB_QuerySELECT (&mysql_res,"can not get followers",
" WHERE FollowedCod=%ld ORDER BY FollowTime DESC", "SELECT FollowerCod FROM usr_follow"
UsrDat->UsrCod); " WHERE FollowedCod=%ld"
NumUsrs = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get followers"); " ORDER BY FollowTime DESC",
UsrDat->UsrCod);
if (NumUsrs) if (NumUsrs)
{ {
/***** Initialize structure with user's data *****/ /***** Initialize structure with user's data *****/

View File

@ -567,12 +567,13 @@ static unsigned For_NumPstsInThrWithPstCod (long PstCod,long *ThrCod)
unsigned NumPsts; unsigned NumPsts;
/***** Get number of posts in the thread that holds a post from database *****/ /***** Get number of posts in the thread that holds a post from database *****/
DB_BuildQuery ("SELECT COUNT(PstCod),ThrCod FROM forum_post" DB_QuerySELECT (&mysql_res,"can not get number of posts"
" WHERE ThrCod IN" " in a thread of a forum",
" (SELECT ThrCod FROM forum_post" "SELECT COUNT(PstCod),ThrCod FROM forum_post"
" WHERE PstCod=%ld) GROUP BY ThrCod;", " WHERE ThrCod IN"
PstCod); " (SELECT ThrCod FROM forum_post"
DB_QuerySELECT_new (&mysql_res,"can not get number of posts in a thread of a forum"); " WHERE PstCod=%ld) GROUP BY ThrCod;",
PstCod);
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
if (sscanf (row[0],"%u",&NumPsts) != 1) if (sscanf (row[0],"%u",&NumPsts) != 1)
@ -651,11 +652,12 @@ static void For_GetThrSubject (long ThrCod,char Subject[Cns_MAX_BYTES_SUBJECT +
MYSQL_ROW row; MYSQL_ROW row;
/***** Get subject of a thread from database *****/ /***** Get subject of a thread from database *****/
DB_BuildQuery ("SELECT forum_post.Subject FROM forum_thread,forum_post" DB_QuerySELECT (&mysql_res,"can not get the subject"
" WHERE forum_thread.ThrCod=%ld" " of a thread of a forum",
" AND forum_thread.FirstPstCod=forum_post.PstCod", "SELECT forum_post.Subject FROM forum_thread,forum_post"
ThrCod); " WHERE forum_thread.ThrCod=%ld"
DB_QuerySELECT_new (&mysql_res,"can not get the subject of a thread of a forum"); " AND forum_thread.FirstPstCod=forum_post.PstCod",
ThrCod);
/***** Write the subject of the thread *****/ /***** Write the subject of the thread *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -681,15 +683,13 @@ void For_GetForumTypeAndLocationOfAPost (long PstCod,struct Forum *Forum)
Forum->Type = For_FORUM_UNKNOWN; Forum->Type = For_FORUM_UNKNOWN;
Forum->Location = -1L; Forum->Location = -1L;
/***** Get forum type of a forum from database *****/
DB_BuildQuery ("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);
/***** Check if there is a row with forum type *****/ /***** Check if there is a row with forum type *****/
if (DB_QuerySELECT_new (&mysql_res,"can not get forum type and location")) if (DB_QuerySELECT (&mysql_res,"can not get forum type and location",
"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))
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -744,10 +744,11 @@ static long For_GetLastPstCod (long ThrCod)
long LastPstCod; long LastPstCod;
/***** Get the code of the last post of a thread from database *****/ /***** Get the code of the last post of a thread from database *****/
DB_BuildQuery ("SELECT PstCod FROM forum_post" DB_QuerySELECT (&mysql_res,"can not get the most recent post"
" WHERE ThrCod=%ld ORDER BY CreatTime DESC LIMIT 1", " of a thread of a forum",
ThrCod); "SELECT PstCod FROM forum_post"
DB_QuerySELECT_new (&mysql_res,"can not get the most recent post of a thread of a forum"); " WHERE ThrCod=%ld ORDER BY CreatTime DESC LIMIT 1",
ThrCod);
/***** Write the subject of the thread *****/ /***** Write the subject of the thread *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -803,11 +804,11 @@ static unsigned For_GetNumOfWritersInThr (long ThrCod)
unsigned NumWriters; unsigned NumWriters;
/***** Get number of distinct writers in a thread from database *****/ /***** Get number of distinct writers in a thread from database *****/
DB_BuildQuery ("SELECT COUNT(DISTINCT UsrCod) FROM forum_post" DB_QuerySELECT (&mysql_res,"can not get the number of writers"
" WHERE ThrCod=%ld", " in a thread of a forum",
ThrCod); "SELECT COUNT(DISTINCT UsrCod) FROM forum_post"
DB_QuerySELECT_new (&mysql_res,"can not get the number of writers" " WHERE ThrCod=%ld",
" in a thread of a forum"); ThrCod);
/* Get row with number of writers */ /* Get row with number of writers */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -870,11 +871,12 @@ static time_t For_GetThrReadTime (long ThrCod)
time_t ReadTimeUTC; time_t ReadTimeUTC;
/***** Get read time of a thread from database *****/ /***** Get read time of a thread from database *****/
DB_BuildQuery ("SELECT UNIX_TIMESTAMP(ReadTime)" if (DB_QuerySELECT (&mysql_res,"can not get date of reading"
" FROM forum_thr_read" " of a thread of a forum",
" WHERE ThrCod=%ld AND UsrCod=%ld", "SELECT UNIX_TIMESTAMP(ReadTime)"
ThrCod,Gbl.Usrs.Me.UsrDat.UsrCod); " FROM forum_thr_read"
if (DB_QuerySELECT_new (&mysql_res,"can not get date of reading of a thread of a forum")) " WHERE ThrCod=%ld AND UsrCod=%ld",
ThrCod,Gbl.Usrs.Me.UsrDat.UsrCod))
{ {
/***** There is a row ==> get read time *****/ /***** There is a row ==> get read time *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -961,11 +963,12 @@ static void For_ShowPostsOfAThread (Ale_AlertType_t AlertType,const char *Messag
Hlp_SOCIAL_Forums_posts,Box_NOT_CLOSABLE); Hlp_SOCIAL_Forums_posts,Box_NOT_CLOSABLE);
/***** Get posts of a thread from database *****/ /***** Get posts of a thread from database *****/
DB_BuildQuery ("SELECT PstCod,UNIX_TIMESTAMP(CreatTime)" NumRows = DB_QuerySELECT (&mysql_res,"can not get posts of a thread",
" FROM forum_post" "SELECT PstCod,UNIX_TIMESTAMP(CreatTime)"
" WHERE ThrCod=%ld ORDER BY PstCod", " FROM forum_post"
Gbl.Forum.ForumSelected.ThrCod); " WHERE ThrCod=%ld ORDER BY PstCod",
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get posts of a thread"); Gbl.Forum.ForumSelected.ThrCod);
NumPsts = (unsigned) NumRows; NumPsts = (unsigned) NumRows;
LastSubject[0] = '\0'; LastSubject[0] = '\0';
if (NumPsts) // If there are posts... if (NumPsts) // If there are posts...
@ -1320,11 +1323,11 @@ 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 *****/
DB_BuildQuery ("SELECT UsrCod,UNIX_TIMESTAMP(CreatTime)," NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a post",
"Subject,Content,ImageName,ImageTitle,ImageURL" "SELECT UsrCod,UNIX_TIMESTAMP(CreatTime),"
" FROM forum_post WHERE PstCod=%ld", "Subject,Content,ImageName,ImageTitle,ImageURL"
PstCod); " FROM forum_post WHERE PstCod=%ld",
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get data of a post"); PstCod);
/***** Result should have a unique row *****/ /***** Result should have a unique row *****/
if (NumRows != 1) if (NumRows != 1)
@ -2274,13 +2277,14 @@ static unsigned For_GetNumThrsWithNewPstsInForum (struct Forum *Forum,
sprintf (SubQuery," AND forum_thread.Location=%ld",Forum->Location); sprintf (SubQuery," AND forum_thread.Location=%ld",Forum->Location);
else else
SubQuery[0] = '\0'; SubQuery[0] = '\0';
DB_BuildQuery ("SELECT MAX(forum_thr_read.ReadTime)" NumRows = DB_QuerySELECT (&mysql_res,"can not get the date of reading of a forum",
" FROM forum_thr_read,forum_thread" "SELECT MAX(forum_thr_read.ReadTime)"
" WHERE forum_thr_read.UsrCod=%ld" " FROM forum_thr_read,forum_thread"
" AND forum_thr_read.ThrCod=forum_thread.ThrCod" " WHERE forum_thr_read.UsrCod=%ld"
" AND forum_thread.ForumType=%u%s", " AND forum_thr_read.ThrCod=forum_thread.ThrCod"
Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) Forum->Type,SubQuery); " AND forum_thread.ForumType=%u%s",
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get the date of reading of a forum"); Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Forum->Type,SubQuery);
if (NumRows) if (NumRows)
{ {
@ -2330,10 +2334,11 @@ static unsigned For_GetNumOfUnreadPostsInThr (long ThrCod,unsigned NumPostsInThr
unsigned NumUnreadPosts = NumPostsInThr; // By default, all the posts are unread by me unsigned NumUnreadPosts = NumPostsInThr; // By default, all the posts are unread by me
/***** Get last time I read this thread from database *****/ /***** Get last time I read this thread from database *****/
DB_BuildQuery ("SELECT ReadTime FROM forum_thr_read" NumRows = DB_QuerySELECT (&mysql_res,"can not get the date of reading"
" WHERE ThrCod=%ld AND UsrCod=%ld", " of a thread",
ThrCod,Gbl.Usrs.Me.UsrDat.UsrCod); "SELECT ReadTime FROM forum_thr_read"
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get the date of reading of a thread"); " WHERE ThrCod=%ld AND UsrCod=%ld",
ThrCod,Gbl.Usrs.Me.UsrDat.UsrCod);
/***** Get if last time I read this thread exists in database *****/ /***** Get if last time I read this thread exists in database *****/
if (NumRows) if (NumRows)
@ -2475,23 +2480,26 @@ static void For_ShowForumThreadsHighlightingOneThread (long ThrCodHighlighted,
switch (Gbl.Forum.ThreadsOrder) switch (Gbl.Forum.ThreadsOrder)
{ {
case For_FIRST_MSG: case For_FIRST_MSG:
DB_BuildQuery ("SELECT forum_thread.ThrCod" NumThrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get thread of a forum",
" FROM forum_thread,forum_post" "SELECT forum_thread.ThrCod"
" WHERE forum_thread.ForumType=%u%s" " FROM forum_thread,forum_post"
" AND forum_thread.FirstPstCod=forum_post.PstCod" " WHERE forum_thread.ForumType=%u%s"
" ORDER BY forum_post.CreatTime DESC", " AND forum_thread.FirstPstCod=forum_post.PstCod"
(unsigned) Gbl.Forum.ForumSelected.Type,SubQuery); " ORDER BY forum_post.CreatTime DESC",
(unsigned) Gbl.Forum.ForumSelected.Type,SubQuery);
break; break;
case For_LAST_MSG: case For_LAST_MSG:
DB_BuildQuery ("SELECT forum_thread.ThrCod" NumThrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get thread of a forum",
" FROM forum_thread,forum_post" "SELECT forum_thread.ThrCod"
" WHERE forum_thread.ForumType=%u%s" " FROM forum_thread,forum_post"
" AND forum_thread.LastPstCod=forum_post.PstCod" " WHERE forum_thread.ForumType=%u%s"
" ORDER BY forum_post.CreatTime DESC", " AND forum_thread.LastPstCod=forum_post.PstCod"
(unsigned) Gbl.Forum.ForumSelected.Type,SubQuery); " ORDER BY forum_post.CreatTime DESC",
(unsigned) Gbl.Forum.ForumSelected.Type,SubQuery);
break; break;
default: // Impossible
return;
} }
NumThrs = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get thread of a forum");
/***** Compute variables related to pagination of threads *****/ /***** Compute variables related to pagination of threads *****/
PaginationThrs.NumItems = NumThrs; PaginationThrs.NumItems = NumThrs;
@ -2658,143 +2666,160 @@ unsigned For_GetNumTotalForumsOfType (For_ForumType_t ForumType,
case For_FORUM_INSTIT_USRS: case For_FORUM_INSTIT_USRS:
case For_FORUM_INSTIT_TCHS: case For_FORUM_INSTIT_TCHS:
if (InsCod > 0) // InsCod > 0 ==> 0 <= number of institutions forums for an institution <= 1 if (InsCod > 0) // InsCod > 0 ==> 0 <= number of institutions forums for an institution <= 1
DB_BuildQuery ("SELECT COUNT(DISTINCT Location)" DB_QuerySELECT (&mysql_res,"can not get number of forums of a type",
" FROM forum_thread" "SELECT COUNT(DISTINCT Location)"
" WHERE ForumType=%u" " FROM forum_thread"
" AND Location=%ld", " WHERE ForumType=%u"
(unsigned) ForumType,InsCod); " AND Location=%ld",
(unsigned) ForumType,InsCod);
else if (CtyCod > 0) // InsCod <= 0 && CtyCod > 0 ==> Number of institution forums for a country else if (CtyCod > 0) // InsCod <= 0 && CtyCod > 0 ==> Number of institution forums for a country
DB_BuildQuery ("SELECT COUNT(DISTINCT forum_thread.Location)" DB_QuerySELECT (&mysql_res,"can not get number of forums of a type",
" FROM forum_thread,institutions" "SELECT COUNT(DISTINCT forum_thread.Location)"
" WHERE forum_thread.ForumType=%u" " FROM forum_thread,institutions"
" AND forum_thread.Location=institutions.InsCod" " WHERE forum_thread.ForumType=%u"
" AND institutions.CtyCod=%ld", " AND forum_thread.Location=institutions.InsCod"
(unsigned) ForumType,CtyCod); " AND institutions.CtyCod=%ld",
(unsigned) ForumType,CtyCod);
else // CtyCod <= 0 ==> Number of institutions forums for the whole platform else // CtyCod <= 0 ==> Number of institutions forums for the whole platform
DB_BuildQuery ("SELECT COUNT(DISTINCT Location)" DB_QuerySELECT (&mysql_res,"can not get number of forums of a type",
" FROM forum_thread" "SELECT COUNT(DISTINCT Location)"
" WHERE ForumType=%u", " FROM forum_thread"
(unsigned) ForumType); " WHERE ForumType=%u",
(unsigned) ForumType);
break; break;
case For_FORUM_CENTRE_USRS: case For_FORUM_CENTRE_USRS:
case For_FORUM_CENTRE_TCHS: case For_FORUM_CENTRE_TCHS:
if (CtrCod > 0) // CtrCod > 0 ==> 0 <= number of centre forums for a centre <= 1 if (CtrCod > 0) // CtrCod > 0 ==> 0 <= number of centre forums for a centre <= 1
DB_BuildQuery ("SELECT COUNT(DISTINCT Location)" DB_QuerySELECT (&mysql_res,"can not get number of forums of a type",
" FROM forum_thread" "SELECT COUNT(DISTINCT Location)"
" WHERE ForumType=%u" " FROM forum_thread"
" AND Location=%ld", " WHERE ForumType=%u"
(unsigned) ForumType,CtrCod); " AND Location=%ld",
(unsigned) ForumType,CtrCod);
else if (InsCod > 0) // CtrCod <= 0 && InsCod > 0 ==> Number of centre forums for an institution else if (InsCod > 0) // CtrCod <= 0 && InsCod > 0 ==> Number of centre forums for an institution
DB_BuildQuery ("SELECT COUNT(DISTINCT forum_thread.Location)" DB_QuerySELECT (&mysql_res,"can not get number of forums of a type",
" FROM forum_thread,centres" "SELECT COUNT(DISTINCT forum_thread.Location)"
" WHERE forum_thread.ForumType=%u" " FROM forum_thread,centres"
" AND forum_thread.Location=centres.CtrCod" " WHERE forum_thread.ForumType=%u"
" AND centres.InsCod=%ld", " AND forum_thread.Location=centres.CtrCod"
(unsigned) ForumType,InsCod); " AND centres.InsCod=%ld",
(unsigned) ForumType,InsCod);
else if (CtyCod > 0) // InsCod <= 0 && CtyCod > 0 ==> Number of centre forums for a country else if (CtyCod > 0) // InsCod <= 0 && CtyCod > 0 ==> Number of centre forums for a country
DB_BuildQuery ("SELECT COUNT(DISTINCT forum_thread.Location)" DB_QuerySELECT (&mysql_res,"can not get number of forums of a type",
" FROM forum_thread,centres,institutions" "SELECT COUNT(DISTINCT forum_thread.Location)"
" WHERE forum_thread.ForumType=%u" " FROM forum_thread,centres,institutions"
" AND forum_thread.Location=centres.CtrCod" " WHERE forum_thread.ForumType=%u"
" AND centres.InsCod=institutions.InsCod" " AND forum_thread.Location=centres.CtrCod"
" AND institutions.CtyCod=%ld", " AND centres.InsCod=institutions.InsCod"
(unsigned) ForumType,CtyCod); " AND institutions.CtyCod=%ld",
(unsigned) ForumType,CtyCod);
else // InsCod <= 0 ==> Number of centre forums for the whole platform else // InsCod <= 0 ==> Number of centre forums for the whole platform
DB_BuildQuery ("SELECT COUNT(DISTINCT Location)" DB_QuerySELECT (&mysql_res,"can not get number of forums of a type",
" FROM forum_thread" "SELECT COUNT(DISTINCT Location)"
" WHERE ForumType=%u", " FROM forum_thread"
(unsigned) ForumType); " WHERE ForumType=%u",
(unsigned) ForumType);
break; break;
case For_FORUM_DEGREE_USRS: case For_FORUM_DEGREE_USRS:
case For_FORUM_DEGREE_TCHS: case For_FORUM_DEGREE_TCHS:
if (DegCod > 0) // DegCod > 0 ==> 0 <= number of degree forums for a degree <= 1 if (DegCod > 0) // DegCod > 0 ==> 0 <= number of degree forums for a degree <= 1
DB_BuildQuery ("SELECT COUNT(DISTINCT Location)" DB_QuerySELECT (&mysql_res,"can not get number of forums of a type",
" FROM forum_thread" "SELECT COUNT(DISTINCT Location)"
" WHERE ForumType=%u" " FROM forum_thread"
" AND Location=%ld", " WHERE ForumType=%u"
(unsigned) ForumType,DegCod); " AND Location=%ld",
(unsigned) ForumType,DegCod);
else if (CtrCod > 0) // DegCod <= 0 && CtrCod > 0 ==> Number of degree forums for a centre else if (CtrCod > 0) // DegCod <= 0 && CtrCod > 0 ==> Number of degree forums for a centre
DB_BuildQuery ("SELECT COUNT(DISTINCT forum_thread.Location)" DB_QuerySELECT (&mysql_res,"can not get number of forums of a type",
" FROM forum_thread,degrees" "SELECT COUNT(DISTINCT forum_thread.Location)"
" WHERE forum_thread.ForumType=%u" " FROM forum_thread,degrees"
" AND forum_thread.Location=degrees.DegCod" " WHERE forum_thread.ForumType=%u"
" AND degrees.CtrCod=%ld", " AND forum_thread.Location=degrees.DegCod"
(unsigned) ForumType,CtrCod); " AND degrees.CtrCod=%ld",
(unsigned) ForumType,CtrCod);
else if (InsCod > 0) // CtrCod <= 0 && InsCod > 0 ==> Number of degree forums for an institution else if (InsCod > 0) // CtrCod <= 0 && InsCod > 0 ==> Number of degree forums for an institution
DB_BuildQuery ("SELECT COUNT(DISTINCT forum_thread.Location)" DB_QuerySELECT (&mysql_res,"can not get number of forums of a type",
" FROM forum_thread,degrees,centres" "SELECT COUNT(DISTINCT forum_thread.Location)"
" WHERE forum_thread.ForumType=%u" " FROM forum_thread,degrees,centres"
" AND forum_thread.Location=degrees.DegCod" " WHERE forum_thread.ForumType=%u"
" AND degrees.CtrCod=centres.CtrCod" " AND forum_thread.Location=degrees.DegCod"
" AND centres.InsCod=%ld", " AND degrees.CtrCod=centres.CtrCod"
(unsigned) ForumType,InsCod); " AND centres.InsCod=%ld",
(unsigned) ForumType,InsCod);
else if (CtyCod > 0) // InsCod <= 0 && CtyCod > 0 ==> Number of degree forums for a country else if (CtyCod > 0) // InsCod <= 0 && CtyCod > 0 ==> Number of degree forums for a country
DB_BuildQuery ("SELECT COUNT(DISTINCT forum_thread.Location)" DB_QuerySELECT (&mysql_res,"can not get number of forums of a type",
" FROM forum_thread,degrees,centres,institutions" "SELECT COUNT(DISTINCT forum_thread.Location)"
" WHERE forum_thread.ForumType=%u" " FROM forum_thread,degrees,centres,institutions"
" AND forum_thread.Location=degrees.DegCod" " WHERE forum_thread.ForumType=%u"
" AND degrees.CtrCod=centres.CtrCod" " AND forum_thread.Location=degrees.DegCod"
" AND centres.InsCod=institutions.InsCod" " AND degrees.CtrCod=centres.CtrCod"
" AND institutions.CtyCod=%ld", " AND centres.InsCod=institutions.InsCod"
(unsigned) ForumType,CtyCod); " AND institutions.CtyCod=%ld",
(unsigned) ForumType,CtyCod);
else // InsCod <= 0 ==> Number of degree forums for the whole platform else // InsCod <= 0 ==> Number of degree forums for the whole platform
DB_BuildQuery ("SELECT COUNT(DISTINCT Location)" DB_QuerySELECT (&mysql_res,"can not get number of forums of a type",
" FROM forum_thread" "SELECT COUNT(DISTINCT Location)"
" WHERE ForumType=%u", " FROM forum_thread"
(unsigned) ForumType); " WHERE ForumType=%u",
(unsigned) ForumType);
break; break;
case For_FORUM_COURSE_USRS: case For_FORUM_COURSE_USRS:
case For_FORUM_COURSE_TCHS: case For_FORUM_COURSE_TCHS:
if (CrsCod > 0) // CrsCod > 0 ==> 0 <= number of course forums for a course <= 1 if (CrsCod > 0) // CrsCod > 0 ==> 0 <= number of course forums for a course <= 1
DB_BuildQuery ("SELECT COUNT(DISTINCT Location)" DB_QuerySELECT (&mysql_res,"can not get number of forums of a type",
" FROM forum_thread" "SELECT COUNT(DISTINCT Location)"
" WHERE ForumType=%u" " FROM forum_thread"
" AND Location=%ld", " WHERE ForumType=%u"
(unsigned) ForumType,CrsCod); " AND Location=%ld",
(unsigned) ForumType,CrsCod);
else if (DegCod > 0) // CrsCod <= 0 && DegCod > 0 ==> Number of course forums for a degree else if (DegCod > 0) // CrsCod <= 0 && DegCod > 0 ==> Number of course forums for a degree
DB_BuildQuery ("SELECT COUNT(DISTINCT forum_thread.Location)" DB_QuerySELECT (&mysql_res,"can not get number of forums of a type",
" FROM forum_thread,courses" "SELECT COUNT(DISTINCT forum_thread.Location)"
" WHERE forum_thread.ForumType=%u" " FROM forum_thread,courses"
" AND forum_thread.Location=courses.CrsCod" " WHERE forum_thread.ForumType=%u"
" AND courses.DegCod=%ld", " AND forum_thread.Location=courses.CrsCod"
(unsigned) ForumType,DegCod); " AND courses.DegCod=%ld",
(unsigned) ForumType,DegCod);
else if (CtrCod > 0) // DegCod <= 0 && CtrCod > 0 ==> Number of course forums for a centre else if (CtrCod > 0) // DegCod <= 0 && CtrCod > 0 ==> Number of course forums for a centre
DB_BuildQuery ("SELECT COUNT(DISTINCT forum_thread.Location)" DB_QuerySELECT (&mysql_res,"can not get number of forums of a type",
" FROM forum_thread,courses,degrees" "SELECT COUNT(DISTINCT forum_thread.Location)"
" WHERE forum_thread.ForumType=%u" " FROM forum_thread,courses,degrees"
" AND forum_thread.Location=courses.CrsCod" " WHERE forum_thread.ForumType=%u"
" AND courses.DegCod=degrees.DegCod" " AND forum_thread.Location=courses.CrsCod"
" AND degrees.CtrCod=%ld", " AND courses.DegCod=degrees.DegCod"
(unsigned) ForumType,CtrCod); " AND degrees.CtrCod=%ld",
(unsigned) ForumType,CtrCod);
else if (InsCod > 0) // CtrCod <= 0 && InsCod > 0 ==> Number of course forums for an institution else if (InsCod > 0) // CtrCod <= 0 && InsCod > 0 ==> Number of course forums for an institution
DB_BuildQuery ("SELECT COUNT(DISTINCT forum_thread.Location)" DB_QuerySELECT (&mysql_res,"can not get number of forums of a type",
" FROM forum_thread,courses,degrees,centres" "SELECT COUNT(DISTINCT forum_thread.Location)"
" WHERE forum_thread.ForumType=%u" " FROM forum_thread,courses,degrees,centres"
" AND forum_thread.Location=courses.CrsCod" " WHERE forum_thread.ForumType=%u"
" AND courses.DegCod=degrees.DegCod" " AND forum_thread.Location=courses.CrsCod"
" AND degrees.CtrCod=centres.CtrCod" " AND courses.DegCod=degrees.DegCod"
" AND centres.InsCod=%ld", " AND degrees.CtrCod=centres.CtrCod"
(unsigned) ForumType,InsCod); " AND centres.InsCod=%ld",
(unsigned) ForumType,InsCod);
else if (CtyCod > 0) // InsCod <= 0 && CtyCod > 0 ==> Number of course forums for a country else if (CtyCod > 0) // InsCod <= 0 && CtyCod > 0 ==> Number of course forums for a country
DB_BuildQuery ("SELECT COUNT(DISTINCT forum_thread.Location)" DB_QuerySELECT (&mysql_res,"can not get number of forums of a type",
" FROM forum_thread,courses,degrees,centres,institutions" "SELECT COUNT(DISTINCT forum_thread.Location)"
" WHERE forum_thread.ForumType=%u" " FROM forum_thread,courses,degrees,centres,institutions"
" AND forum_thread.Location=courses.CrsCod" " WHERE forum_thread.ForumType=%u"
" AND courses.DegCod=degrees.DegCod" " AND forum_thread.Location=courses.CrsCod"
" AND degrees.CtrCod=centres.CtrCod" " AND courses.DegCod=degrees.DegCod"
" AND centres.InsCod=institutions.InsCod" " AND degrees.CtrCod=centres.CtrCod"
" AND institutions.CtyCod=%ld", " AND centres.InsCod=institutions.InsCod"
(unsigned) ForumType,CtyCod); " AND institutions.CtyCod=%ld",
(unsigned) ForumType,CtyCod);
else // InsCod <= 0 ==> Number of course forums for the whole platform else // InsCod <= 0 ==> Number of course forums for the whole platform
DB_BuildQuery ("SELECT COUNT(DISTINCT Location)" DB_QuerySELECT (&mysql_res,"can not get number of forums of a type",
" FROM forum_thread" "SELECT COUNT(DISTINCT Location)"
" WHERE ForumType=%u", " FROM forum_thread"
(unsigned) ForumType); " WHERE ForumType=%u",
(unsigned) ForumType);
break; break;
default: default:
return 0; return 0;
} }
DB_QuerySELECT_new (&mysql_res,"can not get number of forums of a type");
/* Get row with number of threads and number of posts */ /* Get row with number of threads and number of posts */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -3009,169 +3034,206 @@ unsigned For_GetNumTotalPstsInForumsOfType (For_ForumType_t ForumType,
case For_FORUM__SWAD__USRS: case For_FORUM__SWAD__USRS:
case For_FORUM__SWAD__TCHS: case For_FORUM__SWAD__TCHS:
// Total number of posts in forums of this type // Total number of posts in forums of this type
DB_BuildQuery ("SELECT COUNT(*),SUM(forum_post.NumNotif)" DB_QuerySELECT (&mysql_res,"can not get the total number"
" FROM forum_thread,forum_post " " of forums of a type",
" WHERE forum_thread.ForumType=%u" "SELECT COUNT(*),SUM(forum_post.NumNotif)"
" AND forum_thread.ThrCod=forum_post.ThrCod", " FROM forum_thread,forum_post "
(unsigned) ForumType); " WHERE forum_thread.ForumType=%u"
" AND forum_thread.ThrCod=forum_post.ThrCod",
(unsigned) ForumType);
break; break;
case For_FORUM_INSTIT_USRS: case For_FORUM_INSTIT_TCHS: case For_FORUM_INSTIT_USRS: case For_FORUM_INSTIT_TCHS:
if (InsCod > 0) // InsCod > 0 ==> Number of posts in institutions forums for an institution if (InsCod > 0) // InsCod > 0 ==> Number of posts in institutions forums for an institution
DB_BuildQuery ("SELECT COUNT(*),SUM(forum_post.NumNotif)" DB_QuerySELECT (&mysql_res,"can not get the total number"
" FROM forum_thread,forum_post" " of forums of a type",
" WHERE forum_thread.ForumType=%u" "SELECT COUNT(*),SUM(forum_post.NumNotif)"
" AND forum_thread.Location=%ld" " FROM forum_thread,forum_post"
" AND forum_thread.ThrCod=forum_post.ThrCod", " WHERE forum_thread.ForumType=%u"
(unsigned) ForumType,InsCod); " AND forum_thread.Location=%ld"
" AND forum_thread.ThrCod=forum_post.ThrCod",
(unsigned) ForumType,InsCod);
else if (CtyCod > 0) // InsCod <= 0 && CtyCod > 0 ==> Number of posts in institutions forums for a country else if (CtyCod > 0) // InsCod <= 0 && CtyCod > 0 ==> Number of posts in institutions forums for a country
DB_BuildQuery ("SELECT COUNT(*),SUM(forum_post.NumNotif)" DB_QuerySELECT (&mysql_res,"can not get the total number"
" FROM forum_thread,institutions,forum_post" " of forums of a type",
" WHERE forum_thread.ForumType=%u" "SELECT COUNT(*),SUM(forum_post.NumNotif)"
" AND forum_thread.Location=institutions.InsCod" " FROM forum_thread,institutions,forum_post"
" AND institutions.CtyCod=%ld" " WHERE forum_thread.ForumType=%u"
" AND forum_thread.ThrCod=forum_post.ThrCod", " AND forum_thread.Location=institutions.InsCod"
(unsigned) ForumType,CtyCod); " AND institutions.CtyCod=%ld"
" AND forum_thread.ThrCod=forum_post.ThrCod",
(unsigned) ForumType,CtyCod);
else // InsCod <= 0 ==> Number of posts in institution forums for the whole platform else // InsCod <= 0 ==> Number of posts in institution forums for the whole platform
DB_BuildQuery ("SELECT COUNT(*),SUM(forum_post.NumNotif)" DB_QuerySELECT (&mysql_res,"can not get the total number"
" FROM forum_thread,forum_post " " of forums of a type",
" WHERE forum_thread.ForumType=%u" "SELECT COUNT(*),SUM(forum_post.NumNotif)"
" AND forum_thread.ThrCod=forum_post.ThrCod", " FROM forum_thread,forum_post "
(unsigned) ForumType); " WHERE forum_thread.ForumType=%u"
" AND forum_thread.ThrCod=forum_post.ThrCod",
(unsigned) ForumType);
break; break;
case For_FORUM_CENTRE_USRS: case For_FORUM_CENTRE_USRS:
case For_FORUM_CENTRE_TCHS: case For_FORUM_CENTRE_TCHS:
if (CtrCod > 0) // CtrCod > 0 ==> Number of posts in centre forums for a centre if (CtrCod > 0) // CtrCod > 0 ==> Number of posts in centre forums for a centre
DB_BuildQuery ("SELECT COUNT(*),SUM(forum_post.NumNotif)" DB_QuerySELECT (&mysql_res,"can not get the total number"
" FROM forum_thread,forum_post" " of forums of a type",
" WHERE forum_thread.ForumType=%u" "SELECT COUNT(*),SUM(forum_post.NumNotif)"
" AND forum_thread.Location=%ld" " FROM forum_thread,forum_post"
" AND forum_thread.ThrCod=forum_post.ThrCod", " WHERE forum_thread.ForumType=%u"
(unsigned) ForumType,CtrCod); " AND forum_thread.Location=%ld"
" AND forum_thread.ThrCod=forum_post.ThrCod",
(unsigned) ForumType,CtrCod);
else if (InsCod > 0) // CtrCod <= 0 && InsCod > 0 ==> Number of posts in centre forums for an institution else if (InsCod > 0) // CtrCod <= 0 && InsCod > 0 ==> Number of posts in centre forums for an institution
DB_BuildQuery ("SELECT COUNT(*),SUM(forum_post.NumNotif)" DB_QuerySELECT (&mysql_res,"can not get the total number"
" FROM forum_thread,centres,forum_post" " of forums of a type",
" WHERE forum_thread.ForumType=%u" "SELECT COUNT(*),SUM(forum_post.NumNotif)"
" AND forum_thread.Location=centres.CtrCod" " FROM forum_thread,centres,forum_post"
" AND centres.InsCod=%ld" " WHERE forum_thread.ForumType=%u"
" AND forum_thread.ThrCod=forum_post.ThrCod", " AND forum_thread.Location=centres.CtrCod"
(unsigned) ForumType,InsCod); " AND centres.InsCod=%ld"
" AND forum_thread.ThrCod=forum_post.ThrCod",
(unsigned) ForumType,InsCod);
else if (CtyCod > 0) // InsCod <= 0 && CtyCod > 0 ==> Number of posts in centre forums for a country else if (CtyCod > 0) // InsCod <= 0 && CtyCod > 0 ==> Number of posts in centre forums for a country
DB_BuildQuery ("SELECT COUNT(*),SUM(forum_post.NumNotif)" DB_QuerySELECT (&mysql_res,"can not get the total number"
" FROM forum_thread,centres,institutions,forum_post" " of forums of a type",
" WHERE forum_thread.ForumType=%u" "SELECT COUNT(*),SUM(forum_post.NumNotif)"
" AND forum_thread.Location=centres.CtrCod" " FROM forum_thread,centres,institutions,forum_post"
" AND centres.InsCod=institutions.InsCod" " WHERE forum_thread.ForumType=%u"
" AND institutions.CtyCod=%ld" " AND forum_thread.Location=centres.CtrCod"
" AND forum_thread.ThrCod=forum_post.ThrCod", " AND centres.InsCod=institutions.InsCod"
(unsigned) ForumType,CtyCod); " AND institutions.CtyCod=%ld"
" AND forum_thread.ThrCod=forum_post.ThrCod",
(unsigned) ForumType,CtyCod);
else // InsCod <= 0 ==> Number of posts in centre forums for the whole platform else // InsCod <= 0 ==> Number of posts in centre forums for the whole platform
DB_BuildQuery ("SELECT COUNT(*),SUM(forum_post.NumNotif)" DB_QuerySELECT (&mysql_res,"can not get the total number"
" FROM forum_thread,forum_post " " of forums of a type",
" WHERE forum_thread.ForumType=%u" "SELECT COUNT(*),SUM(forum_post.NumNotif)"
" AND forum_thread.ThrCod=forum_post.ThrCod", " FROM forum_thread,forum_post "
(unsigned) ForumType); " WHERE forum_thread.ForumType=%u"
" AND forum_thread.ThrCod=forum_post.ThrCod",
(unsigned) ForumType);
break; break;
case For_FORUM_DEGREE_USRS: case For_FORUM_DEGREE_USRS:
case For_FORUM_DEGREE_TCHS: case For_FORUM_DEGREE_TCHS:
if (DegCod > 0) // DegCod > 0 ==> Number of posts in degree forums for a degree if (DegCod > 0) // DegCod > 0 ==> Number of posts in degree forums for a degree
DB_BuildQuery ("SELECT COUNT(*),SUM(forum_post.NumNotif)" DB_QuerySELECT (&mysql_res,"can not get the total number"
" FROM forum_thread,forum_post " " of forums of a type",
" WHERE forum_thread.ForumType=%u" "SELECT COUNT(*),SUM(forum_post.NumNotif)"
" AND forum_thread.Location=%ld" " FROM forum_thread,forum_post "
" AND forum_thread.ThrCod=forum_post.ThrCod", " WHERE forum_thread.ForumType=%u"
(unsigned) ForumType,DegCod); " AND forum_thread.Location=%ld"
" AND forum_thread.ThrCod=forum_post.ThrCod",
(unsigned) ForumType,DegCod);
else if (CtrCod > 0) // DegCod <= 0 && CtrCod > 0 ==> Number of posts in degree forums for a centre else if (CtrCod > 0) // DegCod <= 0 && CtrCod > 0 ==> Number of posts in degree forums for a centre
DB_BuildQuery ("SELECT COUNT(*),SUM(forum_post.NumNotif)" DB_QuerySELECT (&mysql_res,"can not get the total number"
" FROM forum_thread,degrees,forum_post " " of forums of a type",
" WHERE forum_thread.ForumType=%u" "SELECT COUNT(*),SUM(forum_post.NumNotif)"
" AND forum_thread.Location=degrees.DegCod" " FROM forum_thread,degrees,forum_post "
" AND degrees.CtrCod=%ld" " WHERE forum_thread.ForumType=%u"
" AND forum_thread.ThrCod=forum_post.ThrCod", " AND forum_thread.Location=degrees.DegCod"
(unsigned) ForumType,CtrCod); " AND degrees.CtrCod=%ld"
" AND forum_thread.ThrCod=forum_post.ThrCod",
(unsigned) ForumType,CtrCod);
else if (InsCod > 0) // CtrCod <= 0 && InsCod > 0 ==> Number of posts in degree forums for an institution else if (InsCod > 0) // CtrCod <= 0 && InsCod > 0 ==> Number of posts in degree forums for an institution
DB_BuildQuery ("SELECT COUNT(*),SUM(forum_post.NumNotif)" DB_QuerySELECT (&mysql_res,"can not get the total number"
" FROM forum_thread,degrees,centres,forum_post" " of forums of a type",
" WHERE forum_thread.ForumType=%u" "SELECT COUNT(*),SUM(forum_post.NumNotif)"
" AND forum_thread.Location=degrees.DegCod" " FROM forum_thread,degrees,centres,forum_post"
" AND degrees.CtrCod=centres.CtrCod" " WHERE forum_thread.ForumType=%u"
" AND centres.InsCod=%ld" " AND forum_thread.Location=degrees.DegCod"
" AND forum_thread.ThrCod=forum_post.ThrCod", " AND degrees.CtrCod=centres.CtrCod"
(unsigned) ForumType,InsCod); " AND centres.InsCod=%ld"
" AND forum_thread.ThrCod=forum_post.ThrCod",
(unsigned) ForumType,InsCod);
else if (CtyCod > 0) // InsCod <= 0 && CtyCod > 0 ==> Number of posts in degree forums for a country else if (CtyCod > 0) // InsCod <= 0 && CtyCod > 0 ==> Number of posts in degree forums for a country
DB_BuildQuery ("SELECT COUNT(*),SUM(forum_post.NumNotif)" DB_QuerySELECT (&mysql_res,"can not get the total number"
" FROM forum_thread,degrees,centres,institutions,forum_post" " of forums of a type",
" WHERE forum_thread.ForumType=%u" "SELECT COUNT(*),SUM(forum_post.NumNotif)"
" AND forum_thread.Location=degrees.DegCod" " FROM forum_thread,degrees,centres,institutions,forum_post"
" AND degrees.CtrCod=centres.CtrCod" " WHERE forum_thread.ForumType=%u"
" AND centres.InsCod=institutions.InsCod" " AND forum_thread.Location=degrees.DegCod"
" AND institutions.CtyCod=%ld" " AND degrees.CtrCod=centres.CtrCod"
" AND forum_thread.ThrCod=forum_post.ThrCod", " AND centres.InsCod=institutions.InsCod"
(unsigned) ForumType,CtyCod); " AND institutions.CtyCod=%ld"
" AND forum_thread.ThrCod=forum_post.ThrCod",
(unsigned) ForumType,CtyCod);
else // InsCod <= 0 ==> Number of posts in degree forums for the whole platform else // InsCod <= 0 ==> Number of posts in degree forums for the whole platform
DB_BuildQuery ("SELECT COUNT(*),SUM(forum_post.NumNotif)" DB_QuerySELECT (&mysql_res,"can not get the total number"
" FROM forum_thread,forum_post " " of forums of a type",
" WHERE forum_thread.ForumType=%u" "SELECT COUNT(*),SUM(forum_post.NumNotif)"
" AND forum_thread.ThrCod=forum_post.ThrCod", " FROM forum_thread,forum_post "
(unsigned) ForumType); " WHERE forum_thread.ForumType=%u"
" AND forum_thread.ThrCod=forum_post.ThrCod",
(unsigned) ForumType);
break; break;
case For_FORUM_COURSE_USRS: case For_FORUM_COURSE_USRS:
case For_FORUM_COURSE_TCHS: case For_FORUM_COURSE_TCHS:
if (CrsCod > 0) // CrsCod > 0 ==> 0 <= number of posts in course forums for a course if (CrsCod > 0) // CrsCod > 0 ==> 0 <= number of posts in course forums for a course
DB_BuildQuery ("SELECT COUNT(*),SUM(forum_post.NumNotif)" DB_QuerySELECT (&mysql_res,"can not get the total number"
" FROM forum_thread,forum_post " " of forums of a type",
" WHERE forum_thread.ForumType=%u" "SELECT COUNT(*),SUM(forum_post.NumNotif)"
" AND forum_thread.Location=%ld" " FROM forum_thread,forum_post "
" AND forum_thread.ThrCod=forum_post.ThrCod", " WHERE forum_thread.ForumType=%u"
(unsigned) ForumType,CrsCod); " AND forum_thread.Location=%ld"
" AND forum_thread.ThrCod=forum_post.ThrCod",
(unsigned) ForumType,CrsCod);
else if (DegCod > 0) // CrsCod <= 0 && DegCod > 0 ==> Number of posts in course forums for a degree else if (DegCod > 0) // CrsCod <= 0 && DegCod > 0 ==> Number of posts in course forums for a degree
DB_BuildQuery ("SELECT COUNT(*),SUM(forum_post.NumNotif)" DB_QuerySELECT (&mysql_res,"can not get the total number"
" FROM forum_thread,courses,forum_post " " of forums of a type",
" WHERE forum_thread.ForumType=%u" "SELECT COUNT(*),SUM(forum_post.NumNotif)"
" AND forum_thread.Location=courses.CrsCod" " FROM forum_thread,courses,forum_post "
" AND courses.DegCod=%ld" " WHERE forum_thread.ForumType=%u"
" AND forum_thread.ThrCod=forum_post.ThrCod", " AND forum_thread.Location=courses.CrsCod"
(unsigned) ForumType,DegCod); " AND courses.DegCod=%ld"
" AND forum_thread.ThrCod=forum_post.ThrCod",
(unsigned) ForumType,DegCod);
else if (CtrCod > 0) // DegCod <= 0 && CtrCod > 0 ==> Number of posts in course forums for a centre else if (CtrCod > 0) // DegCod <= 0 && CtrCod > 0 ==> Number of posts in course forums for a centre
DB_BuildQuery ("SELECT COUNT(*),SUM(forum_post.NumNotif)" DB_QuerySELECT (&mysql_res,"can not get the total number"
" FROM forum_thread,courses,degrees,forum_post " " of forums of a type",
" WHERE forum_thread.ForumType=%u" "SELECT COUNT(*),SUM(forum_post.NumNotif)"
" AND forum_thread.Location=courses.CrsCod" " FROM forum_thread,courses,degrees,forum_post "
" AND courses.DegCod=degrees.DegCod" " WHERE forum_thread.ForumType=%u"
" AND degrees.CtrCod=%ld" " AND forum_thread.Location=courses.CrsCod"
" AND forum_thread.ThrCod=forum_post.ThrCod", " AND courses.DegCod=degrees.DegCod"
(unsigned) ForumType,CtrCod); " AND degrees.CtrCod=%ld"
" AND forum_thread.ThrCod=forum_post.ThrCod",
(unsigned) ForumType,CtrCod);
else if (InsCod > 0) // CtrCod <= 0 && InsCod > 0 ==> Number of posts in course forums for an institution else if (InsCod > 0) // CtrCod <= 0 && InsCod > 0 ==> Number of posts in course forums for an institution
DB_BuildQuery ("SELECT COUNT(*),SUM(forum_post.NumNotif)" DB_QuerySELECT (&mysql_res,"can not get the total number"
" FROM forum_thread,courses,degrees,centres,forum_post" " of forums of a type",
" WHERE forum_thread.ForumType=%u" "SELECT COUNT(*),SUM(forum_post.NumNotif)"
" AND forum_thread.Location=courses.CrsCod" " FROM forum_thread,courses,degrees,centres,forum_post"
" AND courses.DegCod=degrees.DegCod" " WHERE forum_thread.ForumType=%u"
" AND degrees.CtrCod=centres.CtrCod" " AND forum_thread.Location=courses.CrsCod"
" AND centres.InsCod=%ld" " AND courses.DegCod=degrees.DegCod"
" AND forum_thread.ThrCod=forum_post.ThrCod", " AND degrees.CtrCod=centres.CtrCod"
(unsigned) ForumType,InsCod); " AND centres.InsCod=%ld"
" AND forum_thread.ThrCod=forum_post.ThrCod",
(unsigned) ForumType,InsCod);
else if (CtyCod > 0) // InsCod <= 0 && CtyCod > 0 ==> Number of posts in course forums for a country else if (CtyCod > 0) // InsCod <= 0 && CtyCod > 0 ==> Number of posts in course forums for a country
DB_BuildQuery ("SELECT COUNT(*),SUM(forum_post.NumNotif)" DB_QuerySELECT (&mysql_res,"can not get the total number"
" FROM forum_thread,courses,degrees,centres,institutions,forum_post" " of forums of a type",
" WHERE forum_thread.ForumType=%u" "SELECT COUNT(*),SUM(forum_post.NumNotif)"
" AND forum_thread.Location=courses.CrsCod" " FROM forum_thread,courses,degrees,centres,institutions,forum_post"
" AND courses.DegCod=degrees.DegCod" " WHERE forum_thread.ForumType=%u"
" AND degrees.CtrCod=centres.CtrCod" " AND forum_thread.Location=courses.CrsCod"
" AND centres.InsCod=institutions.InsCod" " AND courses.DegCod=degrees.DegCod"
" AND institutions.CtyCod=%ld" " AND degrees.CtrCod=centres.CtrCod"
" AND forum_thread.ThrCod=forum_post.ThrCod", " AND centres.InsCod=institutions.InsCod"
(unsigned) ForumType,CtyCod); " AND institutions.CtyCod=%ld"
" AND forum_thread.ThrCod=forum_post.ThrCod",
(unsigned) ForumType,CtyCod);
else // CrsCod <= 0 && DegCod <= 0 && CtrCod <= 0 ==> Number of posts in course forums for the whole platform else // CrsCod <= 0 && DegCod <= 0 && CtrCod <= 0 ==> Number of posts in course forums for the whole platform
DB_BuildQuery ("SELECT COUNT(*),SUM(forum_post.NumNotif)" DB_QuerySELECT (&mysql_res,"can not get the total number"
" FROM forum_thread,forum_post " " of forums of a type",
" WHERE forum_thread.ForumType=%u" "SELECT COUNT(*),SUM(forum_post.NumNotif)"
" AND forum_thread.ThrCod=forum_post.ThrCod", " FROM forum_thread,forum_post "
(unsigned) ForumType); " WHERE forum_thread.ForumType=%u"
" AND forum_thread.ThrCod=forum_post.ThrCod",
(unsigned) ForumType);
break; break;
default: default:
return 0; return 0;
} }
DB_QuerySELECT_new (&mysql_res,"can not get the total number of forums of a type");
/* Get row with number of posts */ /* Get row with number of posts */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -3445,16 +3507,17 @@ static void For_GetThrData (struct ForumThread *Thr)
For_Order_t Order; For_Order_t Order;
/***** Get data of a thread from database *****/ /***** Get data of a thread from database *****/
DB_BuildQuery ("SELECT m0.PstCod,m1.PstCod,m0.UsrCod,m1.UsrCod," NumRows = DB_QuerySELECT (&mysql_res,"can not get data"
"UNIX_TIMESTAMP(m0.CreatTime)," " of a thread of a forum",
"UNIX_TIMESTAMP(m1.CreatTime)," "SELECT m0.PstCod,m1.PstCod,m0.UsrCod,m1.UsrCod,"
"m0.Subject" "UNIX_TIMESTAMP(m0.CreatTime),"
" FROM forum_thread,forum_post AS m0,forum_post AS m1" "UNIX_TIMESTAMP(m1.CreatTime),"
" WHERE forum_thread.ThrCod=%ld" "m0.Subject"
" AND forum_thread.FirstPstCod=m0.PstCod" " FROM forum_thread,forum_post AS m0,forum_post AS m1"
" AND forum_thread.LastPstCod=m1.PstCod", " WHERE forum_thread.ThrCod=%ld"
Thr->ThrCod); " AND forum_thread.FirstPstCod=m0.PstCod"
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get data of a thread of a forum"); " AND forum_thread.LastPstCod=m1.PstCod",
Thr->ThrCod);
/***** The result of the query should have one row *****/ /***** The result of the query should have one row *****/
if (NumRows != 1) if (NumRows != 1)
@ -4292,9 +4355,11 @@ static long For_GetThrInMyClipboard (void)
long ThrCod = -1L;; long ThrCod = -1L;;
/***** Get if there is a thread ready to move in my clipboard from database *****/ /***** Get if there is a thread ready to move in my clipboard from database *****/
DB_BuildQuery ("SELECT ThrCod FROM forum_thr_clip WHERE UsrCod=%ld", NumRows = DB_QuerySELECT (&mysql_res,"can not check if there is"
Gbl.Usrs.Me.UsrDat.UsrCod); " any thread ready to be moved",
NumRows = DB_QuerySELECT_new (&mysql_res,"can not check if there is any thread ready to be moved"); "SELECT ThrCod FROM forum_thr_clip"
" WHERE UsrCod=%ld",
Gbl.Usrs.Me.UsrDat.UsrCod);
if (NumRows == 1) if (NumRows == 1)
{ {