Version 18.11.14

This commit is contained in:
Antonio Cañas Vargas 2018-11-01 21:59:42 +01:00
parent 9dd42ee90c
commit a86d7ce36d
6 changed files with 1331 additions and 1112 deletions

View File

@ -160,12 +160,12 @@ static void RSS_WriteNotices (FILE *FileRSS,struct Course *Crs)
char Content[Cns_MAX_BYTES_TEXT + 1]; char Content[Cns_MAX_BYTES_TEXT + 1];
/***** Get active notices in course *****/ /***** Get active notices in course *****/
DB_BuildQuery ("SELECT NotCod,UNIX_TIMESTAMP(CreatTime) AS T,UsrCod,Content" NumNotices = DB_QuerySELECT (&mysql_res,"can not get notices from database",
" FROM notices" "SELECT NotCod,UNIX_TIMESTAMP(CreatTime) AS T,UsrCod,Content"
" WHERE CrsCod=%ld AND Status=%u" " FROM notices"
" ORDER BY T DESC", " WHERE CrsCod=%ld AND Status=%u"
Crs->CrsCod,(unsigned) Not_ACTIVE_NOTICE); " ORDER BY T DESC",
NumNotices = DB_QuerySELECT_new (&mysql_res,"can not get notices from database"); Crs->CrsCod,(unsigned) Not_ACTIVE_NOTICE);
/***** Write items with notices *****/ /***** Write items with notices *****/
if (NumNotices) if (NumNotices)
@ -257,14 +257,14 @@ static void RSS_WriteExamAnnouncements (FILE *FileRSS,struct Course *Crs)
if (Gbl.DB.DatabaseIsOpen) if (Gbl.DB.DatabaseIsOpen)
{ {
/***** Get exam announcements (only future exams) in current course from database *****/ /***** Get exam announcements (only future exams) in current course from database *****/
DB_BuildQuery ("SELECT ExaCod,UNIX_TIMESTAMP(CallDate) AS T," NumExamAnnouncements = DB_QuerySELECT (&mysql_res,"can not get exam announcements",
"DATE_FORMAT(ExamDate,'%%d/%%m/%%Y %%H:%%i')" "SELECT ExaCod,UNIX_TIMESTAMP(CallDate) AS T,"
" FROM exam_announcements" "DATE_FORMAT(ExamDate,'%%d/%%m/%%Y %%H:%%i')"
" WHERE CrsCod=%ld AND Status=%u AND ExamDate>=NOW()" " FROM exam_announcements"
" ORDER BY T", " WHERE CrsCod=%ld AND Status=%u AND ExamDate>=NOW()"
Gbl.CurrentCrs.Crs.CrsCod, " ORDER BY T",
(unsigned) Exa_VISIBLE_EXAM_ANNOUNCEMENT); Gbl.CurrentCrs.Crs.CrsCod,
NumExamAnnouncements = DB_QuerySELECT_new (&mysql_res,"can not get exam announcements"); (unsigned) Exa_VISIBLE_EXAM_ANNOUNCEMENT);
/***** Write items with notices *****/ /***** Write items with notices *****/
if (NumExamAnnouncements) if (NumExamAnnouncements)

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.13 (2018-11-01)" #define Log_PLATFORM_VERSION "SWAD 18.11.14 (2018-11-01)"
#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.14: Nov 01, 2018 Joining building and performing query into one function. (236211 lines)
Version 18.11.13: Nov 01, 2018 Joining building and performing query into one function. (236011 lines) Version 18.11.13: Nov 01, 2018 Joining building and performing query into one function. (236011 lines)
Version 18.11.12: Nov 01, 2018 Joining building and performing query into one function. (235965 lines) Version 18.11.12: Nov 01, 2018 Joining building and performing query into one function. (235965 lines)
Version 18.11.11: Nov 01, 2018 Joining building and performing query into one function. (235896 lines) Version 18.11.11: Nov 01, 2018 Joining building and performing query into one function. (235896 lines)

View File

@ -353,10 +353,10 @@ Rol_Role_t Rol_GetRoleUsrInCrs (long UsrCod,long CrsCod)
Gbl.Cache.RoleUsrInCrs.UsrCod = UsrCod; Gbl.Cache.RoleUsrInCrs.UsrCod = UsrCod;
Gbl.Cache.RoleUsrInCrs.CrsCod = CrsCod; Gbl.Cache.RoleUsrInCrs.CrsCod = CrsCod;
Gbl.Cache.RoleUsrInCrs.Role = Rol_UNK; Gbl.Cache.RoleUsrInCrs.Role = Rol_UNK;
DB_BuildQuery ("SELECT Role FROM crs_usr" if (DB_QuerySELECT (&mysql_res,"can not get the role of a user in a course",
" WHERE CrsCod=%ld AND UsrCod=%ld", "SELECT Role FROM crs_usr"
CrsCod,UsrCod); " WHERE CrsCod=%ld AND UsrCod=%ld",
if (DB_QuerySELECT_new (&mysql_res,"can not get the role of a user in a course") == 1) // User belongs to the course CrsCod,UsrCod) == 1) // User belongs to the course
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
Gbl.Cache.RoleUsrInCrs.Role = Rol_ConvertUnsignedStrToRole (row[0]); Gbl.Cache.RoleUsrInCrs.Role = Rol_ConvertUnsignedStrToRole (row[0]);
@ -383,11 +383,12 @@ void Rol_GetRolesInAllCrssIfNotYetGot (struct UsrData *UsrDat)
if (UsrDat->Roles.InCrss < 0) // Not yet filled if (UsrDat->Roles.InCrss < 0) // Not yet filled
{ {
/***** Get distinct roles in all courses of the user from database *****/ /***** Get distinct roles in all courses of the user from database *****/
DB_BuildQuery ("SELECT DISTINCT(Role) FROM crs_usr WHERE UsrCod=%ld", NumRoles =
UsrDat->UsrCod); (unsigned) DB_QuerySELECT (&mysql_res,"can not get the roles of a user"
NumRoles = (unsigned) DB_QuerySELECT_new (&mysql_res, " in all his/her courses",
"can not get the roles of a user" "SELECT DISTINCT(Role) FROM crs_usr"
" in all his/her courses"); " WHERE UsrCod=%ld",
UsrDat->UsrCod);
for (NumRole = 0, UsrDat->Roles.InCrss = 0; for (NumRole = 0, UsrDat->Roles.InCrss = 0;
NumRole < NumRoles; NumRole < NumRoles;
NumRole++) NumRole++)
@ -588,10 +589,10 @@ Rol_Role_t Rol_GetRequestedRole (long UsrCod)
Rol_Role_t Role = Rol_UNK; Rol_Role_t Role = Rol_UNK;
/***** Get requested role from database *****/ /***** Get requested role from database *****/
DB_BuildQuery ("SELECT Role FROM crs_usr_requests" if (DB_QuerySELECT (&mysql_res,"can not get requested role",
" WHERE CrsCod=%ld AND UsrCod=%ld", "SELECT Role FROM crs_usr_requests"
Gbl.CurrentCrs.Crs.CrsCod,UsrCod); " WHERE CrsCod=%ld AND UsrCod=%ld",
if (DB_QuerySELECT_new (&mysql_res,"can not get requested role")) Gbl.CurrentCrs.Crs.CrsCod,UsrCod))
{ {
/***** Get role *****/ /***** Get role *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);

View File

@ -257,15 +257,21 @@ bool Ses_GetSessionData (void)
unsigned UnsignedNum; unsigned UnsignedNum;
bool Result = false; bool Result = false;
/***** Query data of session from database *****/
DB_BuildQuery ("SELECT UsrCod,Password,Role,"
"CtyCod,InsCod,CtrCod,DegCod,CrsCod,"
"WhatToSearch,SearchStr"
" FROM sessions WHERE SessionId='%s'",
Gbl.Session.Id);
/***** Check if the session existed in the database *****/ /***** Check if the session existed in the database *****/
if (DB_QuerySELECT_new (&mysql_res,"can not get data of session")) if (DB_QuerySELECT (&mysql_res,"can not get data of session",
"SELECT UsrCod," // row[0]
"Password," // row[1]
"Role," // row[2]
"CtyCod," // row[3]
"InsCod," // row[4]
"CtrCod," // row[5]
"DegCod," // row[6]
"CrsCod," // row[7]
"WhatToSearch," // row[8]
"SearchStr" // row[9]
" FROM sessions"
" WHERE SessionId='%s'",
Gbl.Session.Id))
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -414,10 +420,15 @@ unsigned Ses_GetHiddenParFromDB (Act_Action_t NextAction,
if (Gbl.Session.IsOpen) // If the session is open, get parameter from DB if (Gbl.Session.IsOpen) // If the session is open, get parameter from DB
{ {
/***** Get a hidden parameter from database *****/ /***** Get a hidden parameter from database *****/
DB_BuildQuery ("SELECT ParamValue FROM hidden_params" NumRows = DB_QuerySELECT (&mysql_res,"can not get a hidden parameter",
" WHERE SessionId='%s' AND Action=%ld AND ParamName='%s'", "SELECT ParamValue"
Gbl.Session.Id,Act_GetActCod (NextAction),ParamName); " FROM hidden_params"
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get a hidden parameter"); " WHERE SessionId='%s'"
" AND Action=%ld"
" AND ParamName='%s'",
Gbl.Session.Id,
Act_GetActCod (NextAction),
ParamName);
/***** Check if the parameter is found in database *****/ /***** Check if the parameter is found in database *****/
if (NumRows) if (NumRows)

View File

@ -251,7 +251,8 @@ static unsigned Soc_GetNumTimesACommHasBeenFav (struct SocialComment *SocCom);
static void Soc_ShowUsrsWhoHaveSharedSocialNote (const struct SocialNote *SocNot); static void Soc_ShowUsrsWhoHaveSharedSocialNote (const struct SocialNote *SocNot);
static void Soc_ShowUsrsWhoHaveMarkedSocialNoteAsFav (const struct SocialNote *SocNot); static void Soc_ShowUsrsWhoHaveMarkedSocialNoteAsFav (const struct SocialNote *SocNot);
static void Soc_ShowUsrsWhoHaveMarkedSocialCommAsFav (const struct SocialComment *SocCom); static void Soc_ShowUsrsWhoHaveMarkedSocialCommAsFav (const struct SocialComment *SocCom);
static void Soc_ShowSharersOrFavers (unsigned NumUsrs); static void Soc_ShowSharersOrFavers (MYSQL_RES **mysql_res,
unsigned NumUsrs,unsigned NumFirstUsrs);
static void Soc_GetDataOfSocialNotByCod (struct SocialNote *SocNot); static void Soc_GetDataOfSocialNotByCod (struct SocialNote *SocNot);
static void Soc_GetDataOfSocialComByCod (struct SocialComment *SocCom); static void Soc_GetDataOfSocialComByCod (struct SocialComment *SocCom);
@ -517,6 +518,7 @@ static void Soc_BuildQueryToGetTimeline (char **Query,
} RangePubsToGet; } RangePubsToGet;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned NumPubs;
unsigned NumPub; unsigned NumPub;
long PubCod; long PubCod;
long NotCod; long NotCod;
@ -726,35 +728,42 @@ static void Soc_BuildQueryToGetTimeline (char **Query,
switch (TimelineUsrOrGbl) switch (TimelineUsrOrGbl)
{ {
case Soc_TIMELINE_USR: // Show the timeline of a user case Soc_TIMELINE_USR: // Show the timeline of a user
DB_BuildQuery ("SELECT PubCod,NotCod FROM social_pubs" NumPubs =
" WHERE %s%s%s%s" (unsigned) DB_QuerySELECT (&mysql_res,"can not get publishing",
" ORDER BY PubCod DESC LIMIT 1", "SELECT PubCod,NotCod FROM social_pubs"
SubQueryRangeBottom,SubQueryRangeTop, " WHERE %s%s%s%s"
SubQueryPublishers, " ORDER BY PubCod DESC LIMIT 1",
SubQueryAlreadyExists); SubQueryRangeBottom,SubQueryRangeTop,
SubQueryPublishers,
SubQueryAlreadyExists);
break; break;
case Soc_TIMELINE_GBL: // Show the global timeline case Soc_TIMELINE_GBL: // Show the global timeline
switch (Gbl.Social.WhichUsrs) switch (Gbl.Social.WhichUsrs)
{ {
case Soc_FOLLOWED: // Show the timeline of the users I follow case Soc_FOLLOWED: // Show the timeline of the users I follow
DB_BuildQuery ("SELECT PubCod,NotCod FROM social_pubs,publishers" NumPubs =
" WHERE %s%s%s%s" (unsigned) DB_QuerySELECT (&mysql_res,"can not get publishing",
" ORDER BY social_pubs.PubCod DESC LIMIT 1", "SELECT PubCod,NotCod FROM social_pubs,publishers"
SubQueryRangeBottom,SubQueryRangeTop, " WHERE %s%s%s%s"
SubQueryPublishers, " ORDER BY social_pubs.PubCod DESC LIMIT 1",
SubQueryAlreadyExists); SubQueryRangeBottom,SubQueryRangeTop,
SubQueryPublishers,
SubQueryAlreadyExists);
break; break;
case Soc_ALL_USRS: // Show the timeline of all users case Soc_ALL_USRS: // Show the timeline of all users
DB_BuildQuery ("SELECT PubCod,NotCod FROM social_pubs" NumPubs =
" WHERE %s%s%s" (unsigned) DB_QuerySELECT (&mysql_res,"can not get publishing",
" ORDER BY PubCod DESC LIMIT 1", "SELECT PubCod,NotCod FROM social_pubs"
SubQueryRangeBottom,SubQueryRangeTop, " WHERE %s%s%s"
SubQueryAlreadyExists); " ORDER BY PubCod DESC LIMIT 1",
SubQueryRangeBottom,SubQueryRangeTop,
SubQueryAlreadyExists);
break; break;
} }
break; break;
} }
if (DB_QuerySELECT_new (&mysql_res,"can not get publishing") == 1)
if (NumPubs == 1)
{ {
/* Get code of social publishing */ /* Get code of social publishing */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -813,9 +822,9 @@ static long Soc_GetPubCodFromSession (const char *FieldName)
long PubCod; long PubCod;
/***** Get last publishing code from database *****/ /***** Get last publishing code from database *****/
DB_BuildQuery ("SELECT %s FROM sessions WHERE SessionId='%s'", if (DB_QuerySELECT (&mysql_res,"can not get publishing code from session",
FieldName,Gbl.Session.Id); "SELECT %s FROM sessions WHERE SessionId='%s'",
if (DB_QuerySELECT_new (&mysql_res,"can not get publishing code from session") != 1) FieldName,Gbl.Session.Id) != 1)
Lay_ShowErrorAndExit ("Error when getting publishing code from session."); Lay_ShowErrorAndExit ("Error when getting publishing code from session.");
/***** Get last publishing code *****/ /***** Get last publishing code *****/
@ -1644,10 +1653,11 @@ static void Soc_GetAndWriteSocialPost (long PstCod)
Img_ImageConstructor (&Image); Img_ImageConstructor (&Image);
/***** Get social post from database *****/ /***** Get social post from database *****/
DB_BuildQuery ("SELECT Content,ImageName,ImageTitle,ImageURL" NumRows = DB_QuerySELECT (&mysql_res,"can not get the content"
" FROM social_posts WHERE PstCod=%ld", " of a social post",
PstCod); "SELECT Content,ImageName,ImageTitle,ImageURL"
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get the content of a social post"); " FROM social_posts WHERE PstCod=%ld",
PstCod);
/***** Result should have a unique row *****/ /***** Result should have a unique row *****/
if (NumRows == 1) if (NumRows == 1)
@ -2428,20 +2438,22 @@ static void Soc_WriteCommentsInSocialNote (const struct SocialNote *SocNot)
struct SocialComment SocCom; struct SocialComment SocCom;
/***** Get comments of this social note from database *****/ /***** Get comments of this social note from database *****/
DB_BuildQuery ("SELECT social_pubs.PubCod,social_pubs.PublisherCod," NumComments = DB_QuerySELECT (&mysql_res,"can not get social comments",
"social_pubs.NotCod," "SELECT social_pubs.PubCod," // row[0]
"UNIX_TIMESTAMP(social_pubs.TimePublish)," "social_pubs.PublisherCod," // row[1]
"social_comments.Content," "social_pubs.NotCod," // row[2]
"social_comments.ImageName," "UNIX_TIMESTAMP("
"social_comments.ImageTitle," "social_pubs.TimePublish)," // row[3]
"social_comments.ImageURL" "social_comments.Content," // row[4]
" FROM social_pubs,social_comments" "social_comments.ImageName," // row[5]
" WHERE social_pubs.NotCod=%ld" "social_comments.ImageTitle," // row[6]
" AND social_pubs.PubType=%u" "social_comments.ImageURL" // row[7]
" AND social_pubs.PubCod=social_comments.PubCod" " FROM social_pubs,social_comments"
" ORDER BY social_pubs.PubCod", " WHERE social_pubs.NotCod=%ld"
SocNot->NotCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE); " AND social_pubs.PubType=%u"
NumComments = DB_QuerySELECT_new (&mysql_res,"can not get social comments"); " AND social_pubs.PubCod=social_comments.PubCod"
" ORDER BY social_pubs.PubCod",
SocNot->NotCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE);
/***** List comments *****/ /***** List comments *****/
if (NumComments) // Comments to this social note found if (NumComments) // Comments to this social note found
@ -3732,9 +3744,9 @@ static void Soc_RemoveImgFileFromSocialPost (long PstCod)
MYSQL_ROW row; MYSQL_ROW row;
/***** Get name of image associated to a social post from database *****/ /***** Get name of image associated to a social post from database *****/
DB_BuildQuery ("SELECT ImageName FROM social_posts WHERE PstCod=%ld", if (DB_QuerySELECT (&mysql_res,"can not get image",
PstCod); "SELECT ImageName FROM social_posts WHERE PstCod=%ld",
if (DB_QuerySELECT_new (&mysql_res,"can not get image")) PstCod))
{ {
/***** Get image name (row[0]) *****/ /***** Get image name (row[0]) *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -3772,10 +3784,11 @@ static void Soc_RemoveASocialNoteFromDB (struct SocialNote *SocNot)
} }
/* Get comments of this social note */ /* Get comments of this social note */
DB_BuildQuery ("SELECT PubCod FROM social_pubs" NumComments = DB_QuerySELECT (&mysql_res,"can not get social comments",
" WHERE NotCod=%ld AND PubType=%u", "SELECT PubCod FROM social_pubs"
SocNot->NotCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE); " WHERE NotCod=%ld AND PubType=%u",
NumComments = DB_QuerySELECT_new (&mysql_res,"can not get social comments"); SocNot->NotCod,
(unsigned) Soc_PUB_COMMENT_TO_NOTE);
/* For each comment... */ /* For each comment... */
for (NumCom = 0; for (NumCom = 0;
@ -3857,9 +3870,9 @@ static long Soc_GetNotCodOfSocialPublishing (long PubCod)
long NotCod = -1L; long NotCod = -1L;
/***** Get code of social note from database *****/ /***** Get code of social note from database *****/
DB_BuildQuery ("SELECT NotCod FROM social_pubs WHERE PubCod=%ld", if (DB_QuerySELECT (&mysql_res,"can not get code of social note",
PubCod); "SELECT NotCod FROM social_pubs WHERE PubCod=%ld",
if (DB_QuerySELECT_new (&mysql_res,"can not get code of social note") == 1) // Result should have a unique row PubCod) == 1) // Result should have a unique row
{ {
/* Get code of social note */ /* Get code of social note */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -3883,10 +3896,10 @@ static long Soc_GetPubCodOfOriginalSocialNote (long NotCod)
long OriginalPubCod = -1L; long OriginalPubCod = -1L;
/***** Get code of social publishing of the original note *****/ /***** Get code of social publishing of the original note *****/
DB_BuildQuery ("SELECT PubCod FROM social_pubs" if (DB_QuerySELECT (&mysql_res,"can not get code of social publishing",
" WHERE NotCod=%ld AND PubType=%u", "SELECT PubCod FROM social_pubs"
NotCod,(unsigned) Soc_PUB_ORIGINAL_NOTE); " WHERE NotCod=%ld AND PubType=%u",
if (DB_QuerySELECT_new (&mysql_res,"can not get code of social publishing") == 1) // Result should have a unique row NotCod,(unsigned) Soc_PUB_ORIGINAL_NOTE) == 1) // Result should have a unique row
{ {
/* Get code of social publishing (row[0]) */ /* Get code of social publishing (row[0]) */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -4074,9 +4087,10 @@ static void Soc_RemoveImgFileFromSocialComment (long PubCod)
MYSQL_ROW row; MYSQL_ROW row;
/***** Get name of image associated to a social post from database *****/ /***** Get name of image associated to a social post from database *****/
DB_BuildQuery ("SELECT ImageName FROM social_comments WHERE PubCod=%ld", if (DB_QuerySELECT (&mysql_res,"can not get image",
PubCod); "SELECT ImageName FROM social_comments"
if (DB_QuerySELECT_new (&mysql_res,"can not get image")) " WHERE PubCod=%ld",
PubCod))
{ {
/***** Get image name (row[0]) *****/ /***** Get image name (row[0]) *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -4313,18 +4327,29 @@ static unsigned Soc_GetNumTimesACommHasBeenFav (struct SocialComment *SocCom)
static void Soc_ShowUsrsWhoHaveSharedSocialNote (const struct SocialNote *SocNot) static void Soc_ShowUsrsWhoHaveSharedSocialNote (const struct SocialNote *SocNot)
{ {
MYSQL_RES *mysql_res;
unsigned NumFirstUsrs = 0;
/***** Get users who have shared this note *****/ /***** Get users who have shared this note *****/
if (SocNot->NumShared) if (SocNot->NumShared)
DB_BuildQuery ("SELECT PublisherCod FROM social_pubs" NumFirstUsrs =
" WHERE NotCod=%ld" (unsigned) DB_QuerySELECT (&mysql_res,"can not get users",
" AND PublisherCod<>%ld" "SELECT PublisherCod FROM social_pubs"
" AND PubType=%u" " WHERE NotCod=%ld"
" ORDER BY PubCod LIMIT %u", " AND PublisherCod<>%ld"
SocNot->NotCod, " AND PubType=%u"
SocNot->UsrCod, " ORDER BY PubCod LIMIT %u",
(unsigned) Soc_PUB_SHARED_NOTE, SocNot->NotCod,
Soc_MAX_SHARERS_FAVERS_SHOWN); SocNot->UsrCod,
Soc_ShowSharersOrFavers (SocNot->NumShared); (unsigned) Soc_PUB_SHARED_NOTE,
Soc_MAX_SHARERS_FAVERS_SHOWN);
/***** Show users *****/
Soc_ShowSharersOrFavers (&mysql_res,SocNot->NumShared,NumFirstUsrs);
/***** Free structure that stores the query result *****/
if (SocNot->NumShared)
DB_FreeMySQLResult (&mysql_res);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -4333,16 +4358,28 @@ static void Soc_ShowUsrsWhoHaveSharedSocialNote (const struct SocialNote *SocNot
static void Soc_ShowUsrsWhoHaveMarkedSocialNoteAsFav (const struct SocialNote *SocNot) static void Soc_ShowUsrsWhoHaveMarkedSocialNoteAsFav (const struct SocialNote *SocNot)
{ {
MYSQL_RES *mysql_res;
unsigned NumFirstUsrs = 0;
/***** Get users who have marked this note as favourite *****/ /***** Get users who have marked this note as favourite *****/
if (SocNot->NumFavs) if (SocNot->NumFavs)
DB_BuildQuery ("SELECT UsrCod FROM social_notes_fav" /***** Get list of users from database *****/
" WHERE NotCod=%ld" NumFirstUsrs =
" AND UsrCod<>%ld" // Extra check (unsigned) DB_QuerySELECT (&mysql_res,"can not get users",
" ORDER BY FavCod LIMIT %u", "SELECT UsrCod FROM social_notes_fav"
SocNot->NotCod, " WHERE NotCod=%ld"
SocNot->UsrCod, " AND UsrCod<>%ld" // Extra check
Soc_MAX_SHARERS_FAVERS_SHOWN); " ORDER BY FavCod LIMIT %u",
Soc_ShowSharersOrFavers (SocNot->NumFavs); SocNot->NotCod,
SocNot->UsrCod,
Soc_MAX_SHARERS_FAVERS_SHOWN);
/***** Show users *****/
Soc_ShowSharersOrFavers (&mysql_res,SocNot->NumFavs,NumFirstUsrs);
/***** Free structure that stores the query result *****/
if (SocNot->NumFavs)
DB_FreeMySQLResult (&mysql_res);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -4351,16 +4388,28 @@ static void Soc_ShowUsrsWhoHaveMarkedSocialNoteAsFav (const struct SocialNote *S
static void Soc_ShowUsrsWhoHaveMarkedSocialCommAsFav (const struct SocialComment *SocCom) static void Soc_ShowUsrsWhoHaveMarkedSocialCommAsFav (const struct SocialComment *SocCom)
{ {
MYSQL_RES *mysql_res;
unsigned NumFirstUsrs = 0;
/***** Get users who have marked this comment as favourite *****/ /***** Get users who have marked this comment as favourite *****/
if (SocCom->NumFavs) if (SocCom->NumFavs)
DB_BuildQuery ("SELECT UsrCod FROM social_comments_fav" /***** Get list of users from database *****/
" WHERE PubCod=%ld" NumFirstUsrs =
" AND UsrCod<>%ld" // Extra check (unsigned) DB_QuerySELECT (&mysql_res,"can not get users",
" ORDER BY FavCod LIMIT %u", "SELECT UsrCod FROM social_comments_fav"
SocCom->PubCod, " WHERE PubCod=%ld"
SocCom->UsrCod, " AND UsrCod<>%ld" // Extra check
Soc_MAX_SHARERS_FAVERS_SHOWN); " ORDER BY FavCod LIMIT %u",
Soc_ShowSharersOrFavers (SocCom->NumFavs); SocCom->PubCod,
SocCom->UsrCod,
Soc_MAX_SHARERS_FAVERS_SHOWN);
/***** Show users *****/
Soc_ShowSharersOrFavers (&mysql_res,SocCom->NumFavs,NumFirstUsrs);
/***** Free structure that stores the query result *****/
if (SocCom->NumFavs)
DB_FreeMySQLResult (&mysql_res);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -4368,11 +4417,10 @@ static void Soc_ShowUsrsWhoHaveMarkedSocialCommAsFav (const struct SocialComment
/*****************************************************************************/ /*****************************************************************************/
// All forms in this function and nested functions must have unique identifiers // All forms in this function and nested functions must have unique identifiers
static void Soc_ShowSharersOrFavers (unsigned NumUsrs) static void Soc_ShowSharersOrFavers (MYSQL_RES **mysql_res,
unsigned NumUsrs,unsigned NumFirstUsrs)
{ {
MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned NumFirstUsrs;
unsigned NumUsr; unsigned NumUsr;
unsigned NumUsrsShown = 0; unsigned NumUsrsShown = 0;
struct UsrData UsrDat; struct UsrData UsrDat;
@ -4385,8 +4433,7 @@ static void Soc_ShowSharersOrFavers (unsigned NumUsrs)
if (NumUsrs) if (NumUsrs)
{ {
/***** Get list of users from database *****/ /***** A list of users has been got from database *****/
NumFirstUsrs = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get users");
if (NumFirstUsrs) if (NumFirstUsrs)
{ {
/***** Initialize structure with user's data *****/ /***** Initialize structure with user's data *****/
@ -4398,7 +4445,7 @@ static void Soc_ShowSharersOrFavers (unsigned NumUsrs)
NumUsr++) NumUsr++)
{ {
/***** Get user *****/ /***** Get user *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (*mysql_res);
/* Get user's code (row[0]) */ /* Get user's code (row[0]) */
UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0]); UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0]);
@ -4421,9 +4468,6 @@ static void Soc_ShowSharersOrFavers (unsigned NumUsrs)
Usr_UsrDataDestructor (&UsrDat); Usr_UsrDataDestructor (&UsrDat);
} }
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
if (NumUsrs > NumUsrsShown) if (NumUsrs > NumUsrsShown)
fprintf (Gbl.F.Out,"<div class=\"SOCIAL_SHARER\">" fprintf (Gbl.F.Out,"<div class=\"SOCIAL_SHARER\">"
"<img src=\"%s/ellipsis32x32.gif\"" "<img src=\"%s/ellipsis32x32.gif\""
@ -4448,11 +4492,17 @@ static void Soc_GetDataOfSocialNotByCod (struct SocialNote *SocNot)
if (SocNot->NotCod > 0) if (SocNot->NotCod > 0)
{ {
/***** Get data of social note from database *****/ /***** Get data of social note from database *****/
DB_BuildQuery ("SELECT NotCod,NoteType,Cod,UsrCod,HieCod,Unavailable,UNIX_TIMESTAMP(TimeNote)" if (DB_QuerySELECT (&mysql_res,"can not get data of social note",
" FROM social_notes" "SELECT NotCod," // row[0]
" WHERE NotCod=%ld", "NoteType," // row[1]
SocNot->NotCod); "Cod," // row[2]
if (DB_QuerySELECT_new (&mysql_res,"can not get data of social note")) "UsrCod," // row[3]
"HieCod," // row[4]
"Unavailable," // row[5]
"UNIX_TIMESTAMP(TimeNote)" // row[6]
" FROM social_notes"
" WHERE NotCod=%ld",
SocNot->NotCod))
{ {
/***** Get data of social note *****/ /***** Get data of social note *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -4482,19 +4532,20 @@ static void Soc_GetDataOfSocialComByCod (struct SocialComment *SocCom)
if (SocCom->PubCod > 0) if (SocCom->PubCod > 0)
{ {
/***** Get data of social comment from database *****/ /***** Get data of social comment from database *****/
DB_BuildQuery ("SELECT social_pubs.PubCod,social_pubs.PublisherCod," if (DB_QuerySELECT (&mysql_res,"can not get data of social comment",
"social_pubs.NotCod," "SELECT social_pubs.PubCod," // row[0]
"UNIX_TIMESTAMP(social_pubs.TimePublish)," "social_pubs.PublisherCod," // row[1]
"social_comments.Content," "social_pubs.NotCod," // row[2]
"social_comments.ImageName," "UNIX_TIMESTAMP(social_pubs.TimePublish)," // row[3]
"social_comments.ImageTitle," "social_comments.Content," // row[4]
"social_comments.ImageURL" "social_comments.ImageName," // row[5]
" FROM social_pubs,social_comments" "social_comments.ImageTitle," // row[6]
" WHERE social_pubs.PubCod=%ld" "social_comments.ImageURL" // row[7]
" AND social_pubs.PubType=%u" " FROM social_pubs,social_comments"
" AND social_pubs.PubCod=social_comments.PubCod", " WHERE social_pubs.PubCod=%ld"
SocCom->PubCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE); " AND social_pubs.PubType=%u"
if (DB_QuerySELECT_new (&mysql_res,"can not get data of social comment")) " AND social_pubs.PubCod=social_comments.PubCod",
SocCom->PubCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE))
{ {
/***** Get data of social comment *****/ /***** Get data of social comment *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -4734,10 +4785,14 @@ void Soc_GetNotifSocialPublishing (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
Content[0] = '\0'; Content[0] = '\0';
/***** Get summary and content from social post from database *****/ /***** Get summary and content from social post from database *****/
DB_BuildQuery ("SELECT PubCod,NotCod,PublisherCod,PubType,UNIX_TIMESTAMP(TimePublish)" if (DB_QuerySELECT (&mysql_res,"can not get data of social publishing",
" FROM social_pubs WHERE PubCod=%ld", "SELECT PubCod," // row[0]
PubCod); "NotCod," // row[1]
if (DB_QuerySELECT_new (&mysql_res,"can not get data of social publishing") == 1) // Result should have a unique row "PublisherCod," // row[2]
"PubType," // row[3]
"UNIX_TIMESTAMP(TimePublish)" // row[4]
" FROM social_pubs WHERE PubCod=%ld",
PubCod) == 1) // Result should have a unique row
{ {
/* Get data of social publishing */ /* Get data of social publishing */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -4762,10 +4817,11 @@ void Soc_GetNotifSocialPublishing (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
{ {
/***** Get content of social post from database *****/ /***** Get content of social post from database *****/
// TODO: What happens if content is empty and an image is attached? // TODO: What happens if content is empty and an image is attached?
DB_BuildQuery ("SELECT Content FROM social_posts" if (DB_QuerySELECT (&mysql_res,"can not get the content"
" WHERE PstCod=%ld", " of a social post",
SocNot.Cod); "SELECT Content FROM social_posts"
if (DB_QuerySELECT_new (&mysql_res,"can not get the content of a social post") == 1) // Result should have a unique row " WHERE PstCod=%ld",
SocNot.Cod) == 1) // Result should have a unique row
{ {
/***** Get row *****/ /***** Get row *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -4801,10 +4857,11 @@ void Soc_GetNotifSocialPublishing (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
case Soc_PUB_COMMENT_TO_NOTE: case Soc_PUB_COMMENT_TO_NOTE:
/***** Get content of social post from database *****/ /***** Get content of social post from database *****/
// TODO: What happens if content is empty and an image is attached? // TODO: What happens if content is empty and an image is attached?
DB_BuildQuery ("SELECT Content FROM social_comments" if (DB_QuerySELECT (&mysql_res,"can not get the content"
" WHERE PubCod=%ld", " of a comment to a social note",
SocPub.PubCod); "SELECT Content FROM social_comments"
if (DB_QuerySELECT_new (&mysql_res,"can not get the content of a comment to a social note") == 1) // Result should have a unique row " WHERE PubCod=%ld",
SocPub.PubCod) == 1) // Result should have a unique row
{ {
/***** Get row *****/ /***** Get row *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);

File diff suppressed because it is too large Load Diff