Version 18.11.26

This commit is contained in:
Antonio Cañas Vargas 2018-11-03 15:33:20 +01:00
parent 8c11d2551e
commit 408fc80f28
6 changed files with 146 additions and 114 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.25 (2018-11-03)" #define Log_PLATFORM_VERSION "SWAD 18.11.26 (2018-11-03)"
#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.26: Nov 03, 2018 Joining building and performing query into one function. (236738 lines)
Version 18.11.25: Nov 03, 2018 Joining building and performing query into one function. (236705 lines) Version 18.11.25: Nov 03, 2018 Joining building and performing query into one function. (236705 lines)
Version 18.11.24: Nov 03, 2018 Joining building and performing query into one function. (236636 lines) Version 18.11.24: Nov 03, 2018 Joining building and performing query into one function. (236636 lines)
Version 18.11.23: Nov 03, 2018 Joining building and performing query into one function. (236630 lines) Version 18.11.23: Nov 03, 2018 Joining building and performing query into one function. (236630 lines)

View File

@ -444,9 +444,12 @@ void Dpt_FreeListDepartments (void)
unsigned Dpt_GetNumDepartmentsInInstitution (long InsCod) unsigned Dpt_GetNumDepartmentsInInstitution (long InsCod)
{ {
/***** Get number of departments in an institution from database *****/ /***** Get number of departments in an institution from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM departments WHERE InsCod=%ld",InsCod); return
return (unsigned) DB_QueryCOUNT_new ("can not get number of departments" (unsigned) DB_QueryCOUNT ("can not get number of departments"
" in an institution"); " in an institution",
"SELECT COUNT(*) FROM departments"
" WHERE InsCod=%ld",
InsCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -780,11 +783,11 @@ static void Dpt_RenameDepartment (Cns_ShrtOrFullName_t ShrtOrFullName)
static bool Dpt_CheckIfDepartmentNameExists (const char *FieldName,const char *Name,long DptCod) static bool Dpt_CheckIfDepartmentNameExists (const char *FieldName,const char *Name,long DptCod)
{ {
/***** Get number of departments with a name from database *****/ /***** Get number of departments with a name from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM departments" return (DB_QueryCOUNT ("can not check if the name"
" WHERE %s='%s' AND DptCod<>%ld", " of a department already existed",
FieldName,Name,DptCod); "SELECT COUNT(*) FROM departments"
return (DB_QueryCOUNT_new ("can not check if the name" " WHERE %s='%s' AND DptCod<>%ld",
" of a department already existed") != 0); FieldName,Name,DptCod) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1073,8 +1076,9 @@ static void Dpt_CreateDepartment (struct Department *Dpt)
unsigned Dpt_GetTotalNumberOfDepartments (void) unsigned Dpt_GetTotalNumberOfDepartments (void)
{ {
/***** Get number of departments from database *****/ /***** Get number of departments from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM departments"); return
return (unsigned) DB_QueryCOUNT_new ("can not get number of departments"); (unsigned) DB_QueryCOUNT ("can not get number of departments",
"SELECT COUNT(*) FROM departments");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1084,8 +1088,12 @@ unsigned Dpt_GetTotalNumberOfDepartments (void)
unsigned Dpt_GetNumDptsInIns (long InsCod) unsigned Dpt_GetNumDptsInIns (long InsCod)
{ {
/***** Get departments in an institution from database *****/ /***** Get departments in an institution from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM departments WHERE InsCod=%ld",InsCod); return
return (unsigned) DB_QueryCOUNT_new ("can not get number of departments in an institution"); (unsigned) DB_QueryCOUNT ("can not get number of departments"
" in an institution",
"SELECT COUNT(*) FROM departments"
" WHERE InsCod=%ld",
InsCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -388,9 +388,11 @@ static void Dup_ListSimilarUsrs (void)
static bool Dup_CheckIfUsrIsDup (long UsrCod) static bool Dup_CheckIfUsrIsDup (long UsrCod)
{ {
DB_BuildQuery ("SELECT COUNT(*) FROM usr_duplicated WHERE UsrCod=%ld", return (DB_QueryCOUNT ("can not if user is in list"
UsrCod); " of possible duplicate users",
return (DB_QueryCOUNT_new ("can not if user is in list of possible duplicate users") != 0); "SELECT COUNT(*) FROM usr_duplicated"
" WHERE UsrCod=%ld",
UsrCod) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -8165,6 +8165,7 @@ static void Brw_RenameAffectedExpandedFolders (Brw_FileBrowser_t FileBrowser,
static bool Brw_GetIfExpandedTree (const char Path[PATH_MAX + 1]) static bool Brw_GetIfExpandedTree (const char Path[PATH_MAX + 1])
{ {
bool Expanded;
long Cod = Brw_GetCodForExpandedFolders (); long Cod = Brw_GetCodForExpandedFolders ();
long WorksUsrCod = Brw_GetWorksUsrCodForExpandedFolders (); long WorksUsrCod = Brw_GetWorksUsrCodForExpandedFolders ();
Brw_FileBrowser_t FileBrowserForExpandedFolders = Brw_FileBrowserForDB_expanded_folders[Gbl.FileBrowser.Type]; Brw_FileBrowser_t FileBrowserForExpandedFolders = Brw_FileBrowserForDB_expanded_folders[Gbl.FileBrowser.Type];
@ -8173,32 +8174,35 @@ static bool Brw_GetIfExpandedTree (const char Path[PATH_MAX + 1])
if (Cod > 0) if (Cod > 0)
{ {
if (WorksUsrCod > 0) if (WorksUsrCod > 0)
DB_BuildQuery ("SELECT COUNT(*) FROM expanded_folders" Expanded = (DB_QueryCOUNT ("can not get check if a folder is expanded",
" WHERE UsrCod=%ld AND FileBrowser=%u" "SELECT COUNT(*) FROM expanded_folders"
" AND Cod=%ld AND WorksUsrCod=%ld" " WHERE UsrCod=%ld AND FileBrowser=%u"
" AND Path='%s/'", " AND Cod=%ld AND WorksUsrCod=%ld"
Gbl.Usrs.Me.UsrDat.UsrCod, " AND Path='%s/'",
(unsigned) FileBrowserForExpandedFolders, Gbl.Usrs.Me.UsrDat.UsrCod,
Cod,WorksUsrCod, (unsigned) FileBrowserForExpandedFolders,
Path); Cod,WorksUsrCod,
Path) != 0);
else else
DB_BuildQuery ("SELECT COUNT(*) FROM expanded_folders" Expanded = (DB_QueryCOUNT ("can not get check if a folder is expanded",
" WHERE UsrCod=%ld AND FileBrowser=%u" "SELECT COUNT(*) FROM expanded_folders"
" AND Cod=%ld" " WHERE UsrCod=%ld AND FileBrowser=%u"
" AND Path='%s/'", " AND Cod=%ld"
Gbl.Usrs.Me.UsrDat.UsrCod, " AND Path='%s/'",
(unsigned) FileBrowserForExpandedFolders, Gbl.Usrs.Me.UsrDat.UsrCod,
Cod, (unsigned) FileBrowserForExpandedFolders,
Path); Cod,
Path) != 0);
} }
else // Briefcase else // Briefcase
DB_BuildQuery ("SELECT COUNT(*) FROM expanded_folders" Expanded = (DB_QueryCOUNT ("can not get check if a folder is expanded",
" WHERE UsrCod=%ld AND FileBrowser=%u" "SELECT COUNT(*) FROM expanded_folders"
" AND Path='%s/'", " WHERE UsrCod=%ld AND FileBrowser=%u"
Gbl.Usrs.Me.UsrDat.UsrCod, " AND Path='%s/'",
(unsigned) FileBrowserForExpandedFolders, Gbl.Usrs.Me.UsrDat.UsrCod,
Path); (unsigned) FileBrowserForExpandedFolders,
return (DB_QueryCOUNT_new ("can not get check if a folder is expanded") != 0); Path) != 0);
return Expanded;
} }
/*****************************************************************************/ /*****************************************************************************/
@ -10063,17 +10067,16 @@ bool Brw_CheckIfFileOrFolderIsHidden (struct FileMetadata *FileMetadata)
or or
2) the argument Path begins by 'x/', where x is a path stored in database 2) the argument Path begins by 'x/', where x is a path stored in database
*/ */
DB_BuildQuery ("SELECT COUNT(*) FROM files" return (DB_QueryCOUNT ("can not check if a file or folder is hidden",
" WHERE FileBrowser=%u AND Cod=%ld AND ZoneUsrCod=%ld" "SELECT COUNT(*) FROM files"
" AND Hidden='Y'" " WHERE FileBrowser=%u AND Cod=%ld AND ZoneUsrCod=%ld"
" AND (Path='%s' OR LOCATE(CONCAT(Path,'/'),'%s')=1)", " AND Hidden='Y'"
FileMetadata->FileBrowser, " AND (Path='%s' OR LOCATE(CONCAT(Path,'/'),'%s')=1)",
FileMetadata->Cod, FileMetadata->FileBrowser,
FileMetadata->ZoneUsrCod, FileMetadata->Cod,
FileMetadata->FullPathInTree, FileMetadata->ZoneUsrCod,
FileMetadata->FullPathInTree); FileMetadata->FullPathInTree,
FileMetadata->FullPathInTree) != 0);
return (DB_QueryCOUNT_new ("can not check if a file or folder is hidden") != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -11583,13 +11586,13 @@ static bool Brw_GetIfFolderHasPublicFiles (const char Path[PATH_MAX + 1])
long ZoneUsrCod = Brw_GetZoneUsrCodForFiles (); long ZoneUsrCod = Brw_GetZoneUsrCodForFiles ();
/***** Get if a file or folder is public from database *****/ /***** Get if a file or folder is public from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM files" return (DB_QueryCOUNT ("can not check if a folder contains public files",
" WHERE FileBrowser=%u AND Cod=%ld AND ZoneUsrCod=%ld" "SELECT COUNT(*) FROM files"
" AND Path LIKE '%s/%%' AND Public='Y'", " WHERE FileBrowser=%u AND Cod=%ld AND ZoneUsrCod=%ld"
(unsigned) Brw_FileBrowserForDB_files[Gbl.FileBrowser.Type], " AND Path LIKE '%s/%%' AND Public='Y'",
Cod,ZoneUsrCod, (unsigned) Brw_FileBrowserForDB_files[Gbl.FileBrowser.Type],
Path); Cod,ZoneUsrCod,
return (DB_QueryCOUNT_new ("can not check if a folder contains public files") != 0); Path) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -11599,12 +11602,14 @@ static bool Brw_GetIfFolderHasPublicFiles (const char Path[PATH_MAX + 1])
unsigned Brw_GetNumFilesUsr (long UsrCod) unsigned Brw_GetNumFilesUsr (long UsrCod)
{ {
/***** Get current number of files published by a user from database *****/ /***** Get current number of files published by a user from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM files" return
" WHERE PublisherUsrCod=%ld AND FileType IN (%u,%u)", (unsigned) DB_QueryCOUNT ("can not get number of files from a user",
UsrCod, "SELECT COUNT(*) FROM files"
(unsigned) Brw_IS_FILE, " WHERE PublisherUsrCod=%ld"
(unsigned) Brw_IS_UNKNOWN); // Unknown entries are counted as files " AND FileType IN (%u,%u)",
return (unsigned) DB_QueryCOUNT_new ("can not get number of files from a user"); UsrCod,
(unsigned) Brw_IS_FILE,
(unsigned) Brw_IS_UNKNOWN); // Unknown entries are counted as files
} }
/*****************************************************************************/ /*****************************************************************************/
@ -11614,13 +11619,15 @@ unsigned Brw_GetNumFilesUsr (long UsrCod)
unsigned Brw_GetNumPublicFilesUsr (long UsrCod) unsigned Brw_GetNumPublicFilesUsr (long UsrCod)
{ {
/***** Get current number of public files published by a user from database *****/ /***** Get current number of public files published by a user from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM files" return
" WHERE PublisherUsrCod=%ld AND FileType IN (%u,%u)" (unsigned) DB_QueryCOUNT ("can not get number of public files from a user",
" AND Public='Y'", "SELECT COUNT(*) FROM files"
UsrCod, " WHERE PublisherUsrCod=%ld"
(unsigned) Brw_IS_FILE, " AND FileType IN (%u,%u)"
(unsigned) Brw_IS_UNKNOWN); // Unknown entries are counted as files " AND Public='Y'",
return (unsigned) DB_QueryCOUNT_new ("can not get number of public files from a user"); UsrCod,
(unsigned) Brw_IS_FILE,
(unsigned) Brw_IS_UNKNOWN); // Unknown entries are counted as files
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -445,10 +445,10 @@ bool Fol_CheckUsrIsFollowerOf (long FollowerCod,long FollowedCod)
return false; return false;
/***** Check if a user is a follower of another user *****/ /***** Check if a user is a follower of another user *****/
DB_BuildQuery ("SELECT COUNT(*) FROM usr_follow" return (DB_QueryCOUNT ("can not get if a user is a follower of another one",
" WHERE FollowerCod=%ld AND FollowedCod=%ld", "SELECT COUNT(*) FROM usr_follow"
FollowerCod,FollowedCod); " WHERE FollowerCod=%ld AND FollowedCod=%ld",
return (DB_QueryCOUNT_new ("can not get if a user is a follower of another one") != 0); FollowerCod,FollowedCod) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -458,9 +458,11 @@ bool Fol_CheckUsrIsFollowerOf (long FollowerCod,long FollowedCod)
unsigned Fol_GetNumFollowing (long UsrCod) unsigned Fol_GetNumFollowing (long UsrCod)
{ {
/***** Check if a user is a follower of another user *****/ /***** Check if a user is a follower of another user *****/
DB_BuildQuery ("SELECT COUNT(*) FROM usr_follow WHERE FollowerCod=%ld", return
UsrCod); (unsigned) DB_QueryCOUNT ("can not get number of followed",
return DB_QueryCOUNT_new ("can not get number of followed"); "SELECT COUNT(*) FROM usr_follow"
" WHERE FollowerCod=%ld",
UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -470,9 +472,11 @@ unsigned Fol_GetNumFollowing (long UsrCod)
unsigned Fol_GetNumFollowers (long UsrCod) unsigned Fol_GetNumFollowers (long UsrCod)
{ {
/***** Check if a user is a follower of another user *****/ /***** Check if a user is a follower of another user *****/
DB_BuildQuery ("SELECT COUNT(*) FROM usr_follow WHERE FollowedCod=%ld", return
UsrCod); (unsigned) DB_QueryCOUNT ("can not get number of followers",
return DB_QueryCOUNT_new ("can not get number of followers"); "SELECT COUNT(*) FROM usr_follow"
" WHERE FollowedCod=%ld",
UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -441,8 +441,9 @@ void For_DisablePost (void)
static bool For_GetIfForumPstExists (long PstCod) static bool For_GetIfForumPstExists (long PstCod)
{ {
/***** Get if a forum post exists from database *****/ /***** Get if a forum post exists from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM forum_post WHERE PstCod=%ld",PstCod); return (DB_QueryCOUNT ("can not check if a post of a forum already existed",
return (DB_QueryCOUNT_new ("can not check if a post of a forum already existed") != 0); // Post exists if it appears in table of forum posts "SELECT COUNT(*) FROM forum_post WHERE PstCod=%ld",
PstCod) != 0); // Post exists if it appears in table of forum posts
} }
/*****************************************************************************/ /*****************************************************************************/
@ -452,13 +453,11 @@ static bool For_GetIfForumPstExists (long PstCod)
static bool For_GetIfPstIsEnabled (long PstCod) static bool For_GetIfPstIsEnabled (long PstCod)
{ {
if (PstCod > 0) if (PstCod > 0)
{
/***** Get if post is disabled from database *****/ /***** Get if post is disabled from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM forum_disabled_post" return (DB_QueryCOUNT ("can not check if a post of a forum is disabled",
" WHERE PstCod=%ld", "SELECT COUNT(*) FROM forum_disabled_post"
PstCod); " WHERE PstCod=%ld",
return (DB_QueryCOUNT_new ("can not check if a post of a forum is disabled") == 0); // Post is enabled if it does not appear in table of disabled posts PstCod) == 0); // Post is enabled if it does not appear in table of disabled posts
}
else else
return false; return false;
} }
@ -794,10 +793,12 @@ static void For_UpdateThrReadTime (long ThrCod,
static unsigned For_GetNumOfReadersOfThr (long ThrCod) static unsigned For_GetNumOfReadersOfThr (long ThrCod)
{ {
/***** Get number of distinct readers of a thread from database *****/ /***** Get number of distinct readers of a thread from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM forum_thr_read WHERE ThrCod=%ld", return
ThrCod); (unsigned) DB_QueryCOUNT ("can not get the number of readers"
return (unsigned) DB_QueryCOUNT_new ("can not get the number of readers" " of a thread of a forum",
" of a thread of a forum"); "SELECT COUNT(*) FROM forum_thr_read"
" WHERE ThrCod=%ld",
ThrCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -837,9 +838,12 @@ static unsigned For_GetNumOfWritersInThr (long ThrCod)
static unsigned For_GetNumPstsInThr (long ThrCod) static unsigned For_GetNumPstsInThr (long ThrCod)
{ {
/***** Get number of posts in a thread from database *****/ /***** Get number of posts in a thread from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM forum_post WHERE ThrCod=%ld",ThrCod); return
return (unsigned) DB_QueryCOUNT_new ("can not get the number of posts" (unsigned) DB_QueryCOUNT ("can not get the number of posts"
" in a thread of a forum"); " in a thread of a forum",
"SELECT COUNT(*) FROM forum_post"
" WHERE ThrCod=%ld",
ThrCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -849,11 +853,12 @@ static unsigned For_GetNumPstsInThr (long ThrCod)
static unsigned For_GetNumMyPstInThr (long ThrCod) static unsigned For_GetNumMyPstInThr (long ThrCod)
{ {
/***** Get if I have write posts in a thread from database *****/ /***** Get if I have write posts in a thread from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM forum_post" return
" WHERE ThrCod=%ld AND UsrCod=%ld", (unsigned) DB_QueryCOUNT ("can not check if you have written"
ThrCod,Gbl.Usrs.Me.UsrDat.UsrCod); " posts in a thead of a forum",
return (unsigned) DB_QueryCOUNT_new ("can not check if you have written" "SELECT COUNT(*) FROM forum_post"
" posts in a thead of a forum"); " WHERE ThrCod=%ld AND UsrCod=%ld",
ThrCod,Gbl.Usrs.Me.UsrDat.UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -863,8 +868,9 @@ static unsigned For_GetNumMyPstInThr (long ThrCod)
unsigned long For_GetNumPostsUsr (long UsrCod) unsigned long For_GetNumPostsUsr (long UsrCod)
{ {
/***** Get number of posts from a user from database *****/ /***** Get number of posts from a user from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM forum_post WHERE UsrCod=%ld",UsrCod); return DB_QueryCOUNT ("can not number of posts from a user",
return DB_QueryCOUNT_new ("can not number of posts from a user"); "SELECT COUNT(*) FROM forum_post WHERE UsrCod=%ld",
UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1448,12 +1454,15 @@ static void For_WriteNumberOfPosts (long UsrCod)
Gbl.Forum.ForumSelected.Location); Gbl.Forum.ForumSelected.Location);
else else
SubQuery[0] = '\0'; SubQuery[0] = '\0';
DB_BuildQuery ("SELECT COUNT(*) FROM forum_post,forum_thread" NumPsts =
" WHERE forum_post.UsrCod=%ld" (unsigned) DB_QueryCOUNT ("can not get the number of posts of a user"
" AND forum_post.ThrCod=forum_thread.ThrCod" " in a forum",
" AND forum_thread.ForumType=%u%s", "SELECT COUNT(*) FROM forum_post,forum_thread"
UsrCod,(unsigned) Gbl.Forum.ForumSelected.Type,SubQuery); " WHERE forum_post.UsrCod=%ld"
NumPsts = (unsigned) DB_QueryCOUNT_new ("can not get the number of posts of a user in a forum"); " AND forum_post.ThrCod=forum_thread.ThrCod"
" AND forum_thread.ForumType=%u%s",
UsrCod,
(unsigned) Gbl.Forum.ForumSelected.Type,SubQuery);
/***** Write number of threads and number of posts *****/ /***** Write number of threads and number of posts *****/
if (NumPsts == 1) if (NumPsts == 1)
@ -2325,12 +2334,13 @@ static unsigned For_GetNumOfThreadsInForumNewerThan (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 COUNT(*) FROM forum_thread,forum_post" return
" WHERE forum_thread.ForumType=%u%s" (unsigned) DB_QueryCOUNT ("can not check if there are new posts in a forum",
" AND forum_thread.LastPstCod=forum_post.PstCod" "SELECT COUNT(*) FROM forum_thread,forum_post"
" AND forum_post.ModifTime>'%s'", " WHERE forum_thread.ForumType=%u%s"
(unsigned) Forum->Type,SubQuery,Time); " AND forum_thread.LastPstCod=forum_post.PstCod"
return (unsigned) DB_QueryCOUNT_new ("can not check if there are new posts in a forum"); " AND forum_post.ModifTime>'%s'",
(unsigned) Forum->Type,SubQuery,Time);
} }
/*****************************************************************************/ /*****************************************************************************/