Version 18.11.13

This commit is contained in:
Antonio Cañas Vargas 2018-11-01 19:23:52 +01:00
parent a1a858edc7
commit 9dd42ee90c
10 changed files with 665 additions and 618 deletions

View File

@ -355,10 +355,11 @@ En OpenSWAD:
ps2pdf source.ps destination.pdf
*/
#define Log_PLATFORM_VERSION "SWAD 18.11.12 (2018-11-01)"
#define Log_PLATFORM_VERSION "SWAD 18.11.13 (2018-11-01)"
#define CSS_FILE "swad18.4.css"
#define JS_FILE "swad17.17.1.js"
/*
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.11: Nov 01, 2018 Joining building and performing query into one function. (235896 lines)
Version 18.11.10: Nov 01, 2018 Joining building and performing query into one function. (235861 lines)

View File

@ -1115,75 +1115,91 @@ void Fol_UnfollowUsr2 (void)
void Fol_GetAndShowRankingFollowers (void)
{
MYSQL_RES *mysql_res;
unsigned NumUsrs = 0; // Initialized to avoid warning
/***** Get ranking from database *****/
switch (Gbl.Scope.Current)
{
case Sco_SCOPE_SYS:
DB_BuildQuery ("SELECT FollowedCod,COUNT(FollowerCod) AS N"
" FROM usr_follow"
" GROUP BY FollowedCod"
" ORDER BY N DESC,FollowedCod LIMIT 100");
NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT FollowedCod,COUNT(FollowerCod) AS N"
" FROM usr_follow"
" GROUP BY FollowedCod"
" ORDER BY N DESC,FollowedCod LIMIT 100");
break;
case Sco_SCOPE_CTY:
DB_BuildQuery ("SELECT usr_follow.FollowedCod,COUNT(DISTINCT usr_follow.FollowerCod) AS N"
" FROM institutions,centres,degrees,courses,crs_usr,usr_follow"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=usr_follow.FollowedCod"
" GROUP BY usr_follow.FollowedCod"
" ORDER BY N DESC,usr_follow.FollowedCod LIMIT 100",
Gbl.CurrentCty.Cty.CtyCod);
NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT usr_follow.FollowedCod,COUNT(DISTINCT usr_follow.FollowerCod) AS N"
" FROM institutions,centres,degrees,courses,crs_usr,usr_follow"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=usr_follow.FollowedCod"
" GROUP BY usr_follow.FollowedCod"
" ORDER BY N DESC,usr_follow.FollowedCod LIMIT 100",
Gbl.CurrentCty.Cty.CtyCod);
break;
case Sco_SCOPE_INS:
DB_BuildQuery ("SELECT usr_follow.FollowedCod,COUNT(DISTINCT usr_follow.FollowerCod) AS N"
" FROM centres,degrees,courses,crs_usr,usr_follow"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=usr_follow.FollowedCod"
" GROUP BY usr_follow.FollowedCod"
" ORDER BY N DESC,usr_follow.FollowedCod LIMIT 100",
Gbl.CurrentIns.Ins.InsCod);
NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT usr_follow.FollowedCod,COUNT(DISTINCT usr_follow.FollowerCod) AS N"
" FROM centres,degrees,courses,crs_usr,usr_follow"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=usr_follow.FollowedCod"
" GROUP BY usr_follow.FollowedCod"
" ORDER BY N DESC,usr_follow.FollowedCod LIMIT 100",
Gbl.CurrentIns.Ins.InsCod);
break;
case Sco_SCOPE_CTR:
DB_BuildQuery ("SELECT usr_follow.FollowedCod,COUNT(DISTINCT usr_follow.FollowerCod) AS N"
" FROM degrees,courses,crs_usr,usr_follow"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=usr_follow.FollowedCod"
" GROUP BY usr_follow.FollowedCod"
" ORDER BY N DESC,usr_follow.FollowedCod LIMIT 100",
Gbl.CurrentCtr.Ctr.CtrCod);
NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT usr_follow.FollowedCod,COUNT(DISTINCT usr_follow.FollowerCod) AS N"
" FROM degrees,courses,crs_usr,usr_follow"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=usr_follow.FollowedCod"
" GROUP BY usr_follow.FollowedCod"
" ORDER BY N DESC,usr_follow.FollowedCod LIMIT 100",
Gbl.CurrentCtr.Ctr.CtrCod);
break;
case Sco_SCOPE_DEG:
DB_BuildQuery ("SELECT usr_follow.FollowedCod,COUNT(DISTINCT usr_follow.FollowerCod) AS N"
" FROM courses,crs_usr,usr_follow"
" WHERE courses.DegCod=%ld"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=usr_follow.FollowedCod"
" GROUP BY usr_follow.FollowedCod"
" ORDER BY N DESC,usr_follow.FollowedCod LIMIT 100",
Gbl.CurrentDeg.Deg.DegCod);
NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT usr_follow.FollowedCod,COUNT(DISTINCT usr_follow.FollowerCod) AS N"
" FROM courses,crs_usr,usr_follow"
" WHERE courses.DegCod=%ld"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=usr_follow.FollowedCod"
" GROUP BY usr_follow.FollowedCod"
" ORDER BY N DESC,usr_follow.FollowedCod LIMIT 100",
Gbl.CurrentDeg.Deg.DegCod);
break;
case Sco_SCOPE_CRS:
DB_BuildQuery ("SELECT usr_follow.FollowedCod,COUNT(DISTINCT usr_follow.FollowerCod) AS N"
" FROM crs_usr,usr_follow"
" WHERE crs_usr.CrsCod=%ld"
" AND crs_usr.UsrCod=usr_follow.FollowedCod"
" GROUP BY usr_follow.FollowedCod"
" ORDER BY N DESC,usr_follow.FollowedCod LIMIT 100",
Gbl.CurrentCrs.Crs.CrsCod);
NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT usr_follow.FollowedCod,COUNT(DISTINCT usr_follow.FollowerCod) AS N"
" FROM crs_usr,usr_follow"
" WHERE crs_usr.CrsCod=%ld"
" AND crs_usr.UsrCod=usr_follow.FollowedCod"
" GROUP BY usr_follow.FollowedCod"
" ORDER BY N DESC,usr_follow.FollowedCod LIMIT 100",
Gbl.CurrentCrs.Crs.CrsCod);
break;
default:
Lay_WrongScopeExit ();
break;
}
Prf_ShowRankingFigure ();
Prf_ShowRankingFigure (&mysql_res,NumUsrs);
}
/*****************************************************************************/

View File

@ -299,25 +299,32 @@ void Plc_GetListPlaces (void)
sprintf (OrderBySubQuery,"NumCtrs DESC,FullName");
break;
}
DB_BuildQuery ("(SELECT places.PlcCod,places.ShortName,places.FullName,COUNT(*) AS NumCtrs"
" FROM places,centres"
" WHERE places.InsCod=%ld"
" AND places.PlcCod=centres.PlcCod"
" AND centres.InsCod=%ld"
" GROUP BY places.PlcCod)"
" UNION "
"(SELECT PlcCod,ShortName,FullName,0 AS NumCtrs"
" FROM places"
" WHERE InsCod=%ld"
" AND PlcCod NOT IN"
" (SELECT DISTINCT PlcCod FROM centres WHERE InsCod=%ld))"
" ORDER BY %s",
Gbl.CurrentIns.Ins.InsCod,
Gbl.CurrentIns.Ins.InsCod,
Gbl.CurrentIns.Ins.InsCod,
Gbl.CurrentIns.Ins.InsCod,
OrderBySubQuery);
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get places");
NumRows = DB_QuerySELECT (&mysql_res,"can not get places",
"(SELECT places.PlcCod,"
"places.ShortName,"
"places.FullName,"
"COUNT(*) AS NumCtrs"
" FROM places,centres"
" WHERE places.InsCod=%ld"
" AND places.PlcCod=centres.PlcCod"
" AND centres.InsCod=%ld"
" GROUP BY places.PlcCod)"
" UNION "
"(SELECT PlcCod,"
"ShortName,"
"FullName,"
"0 AS NumCtrs"
" FROM places"
" WHERE InsCod=%ld"
" AND PlcCod NOT IN"
" (SELECT DISTINCT PlcCod FROM centres"
" WHERE InsCod=%ld))"
" ORDER BY %s",
Gbl.CurrentIns.Ins.InsCod,
Gbl.CurrentIns.Ins.InsCod,
Gbl.CurrentIns.Ins.InsCod,
Gbl.CurrentIns.Ins.InsCod,
OrderBySubQuery);
/***** Count number of rows in result *****/
if (NumRows) // Places found...
@ -397,22 +404,26 @@ void Plc_GetDataOfPlaceByCod (struct Place *Plc)
else if (Plc->PlcCod > 0)
{
/***** Get data of a place from database *****/
DB_BuildQuery ("(SELECT places.ShortName,places.FullName,COUNT(*)"
" FROM places,centres"
" WHERE places.PlcCod=%ld"
" AND places.PlcCod=centres.PlcCod"
" AND centres.PlcCod=%ld"
" GROUP BY places.PlcCod)"
" UNION "
"(SELECT ShortName,FullName,0"
" FROM places"
" WHERE PlcCod=%ld"
" AND PlcCod NOT IN"
" (SELECT DISTINCT PlcCod FROM centres))",
Plc->PlcCod,
Plc->PlcCod,
Plc->PlcCod);
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get data of a place");
NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a place",
"(SELECT places.ShortName,"
"places.FullName,"
"COUNT(*)"
" FROM places,centres"
" WHERE places.PlcCod=%ld"
" AND places.PlcCod=centres.PlcCod"
" AND centres.PlcCod=%ld"
" GROUP BY places.PlcCod)"
" UNION "
"(SELECT ShortName,"
"FullName,"
"0"
" FROM places"
" WHERE PlcCod=%ld"
" AND PlcCod NOT IN"
" (SELECT DISTINCT PlcCod FROM centres))",
Plc->PlcCod,
Plc->PlcCod,
Plc->PlcCod);
/***** Count number of rows in result *****/
if (NumRows) // Place found...

View File

@ -191,9 +191,9 @@ static void Plg_GetListPlugins (void)
struct Plugin *Plg;
/***** Get plugins from database *****/
DB_BuildQuery ("SELECT PlgCod,Name,Description,Logo,AppKey,URL,IP"
" FROM plugins ORDER BY Name");
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get plugins");
NumRows = DB_QuerySELECT (&mysql_res,"can not get plugins",
"SELECT PlgCod,Name,Description,Logo,AppKey,URL,IP"
" FROM plugins ORDER BY Name");
/***** Count number of rows in result *****/
if (NumRows) // Plugins found...
@ -274,11 +274,11 @@ bool Plg_GetDataOfPluginByCod (struct Plugin *Plg)
// Plg->PlgCod > 0
/***** Get data of a plugin from database *****/
DB_BuildQuery ("SELECT Name,Description,Logo,AppKey,URL,IP"
" FROM plugins"
" WHERE PlgCod=%ld",
Plg->PlgCod);
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get data of a plugin");
NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a plugin",
"SELECT Name,Description,Logo,AppKey,URL,IP"
" FROM plugins"
" WHERE PlgCod=%ld",
Plg->PlgCod);
/***** Count number of rows in result *****/
if (NumRows) // Plugin found...

View File

@ -129,10 +129,11 @@ void Pre_GetPrefsFromIP (void)
if (Gbl.IP[0])
{
/***** Get preferences from database *****/
DB_BuildQuery ("SELECT FirstDayOfWeek,DateFormat,Theme,IconSet,Menu,SideCols"
" FROM IP_prefs WHERE IP='%s'",
Gbl.IP);
if ((NumRows = DB_QuerySELECT_new (&mysql_res,"can not get preferences")))
NumRows = DB_QuerySELECT (&mysql_res,"can not get preferences",
"SELECT FirstDayOfWeek,DateFormat,Theme,IconSet,Menu,SideCols"
" FROM IP_prefs WHERE IP='%s'",
Gbl.IP);
if (NumRows)
{
if (NumRows != 1)
Lay_ShowErrorAndExit ("Internal error while getting preferences.");

View File

@ -625,12 +625,13 @@ void Prf_GetUsrFigures (long UsrCod,struct UsrFigures *UsrFigures)
unsigned NumRows;
/***** Get user's figures from database *****/
DB_BuildQuery ("SELECT UNIX_TIMESTAMP(FirstClickTime),"
"DATEDIFF(NOW(),FirstClickTime)+1,"
"NumClicks,NumFileViews,NumForPst,NumMsgSnt"
" FROM usr_figures WHERE UsrCod=%ld",
UsrCod);
if ((NumRows = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get user's figures")))
NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get user's figures",
"SELECT UNIX_TIMESTAMP(FirstClickTime),"
"DATEDIFF(NOW(),FirstClickTime)+1,"
"NumClicks,NumFileViews,NumForPst,NumMsgSnt"
" FROM usr_figures WHERE UsrCod=%ld",
UsrCod);
if (NumRows)
{
/***** Get user's figures *****/
row = mysql_fetch_row (mysql_res);
@ -838,11 +839,12 @@ static void Prf_GetFirstClickFromLogAndStoreAsUsrFigure (long UsrCod)
Prf_ResetUsrFigures (&UsrFigures);
/***** Get first click from log table *****/
DB_BuildQuery ("SELECT UNIX_TIMESTAMP("
"(SELECT MIN(ClickTime) FROM log_full WHERE UsrCod=%ld)"
")",
UsrCod);
if (DB_QuerySELECT_new (&mysql_res,"can not get user's first click"))
if (DB_QuerySELECT (&mysql_res,"can not get user's first click",
"SELECT UNIX_TIMESTAMP("
"(SELECT MIN(ClickTime) FROM log_full"
" WHERE UsrCod=%ld)"
")",
UsrCod))
{
/* Get first click */
row = mysql_fetch_row (mysql_res);
@ -1154,107 +1156,120 @@ void Prf_GetAndShowRankingMsgSnt (void)
static void Prf_GetAndShowRankingFigure (const char *FieldName)
{
MYSQL_RES *mysql_res;
unsigned NumUsrs = 0; // Initialized to avoid warning
/***** Get ranking from database *****/
switch (Gbl.Scope.Current)
{
case Sco_SCOPE_SYS:
DB_BuildQuery ("SELECT UsrCod,%s"
" FROM usr_figures"
" WHERE %s>=0"
" AND UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY %s DESC,UsrCod LIMIT 100",
FieldName,
FieldName,FieldName);
NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT UsrCod,%s"
" FROM usr_figures"
" WHERE %s>=0"
" AND UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY %s DESC,UsrCod LIMIT 100",
FieldName,
FieldName,FieldName);
break;
case Sco_SCOPE_CTY:
DB_BuildQuery ("SELECT DISTINCTROW usr_figures.UsrCod,usr_figures.%s"
" FROM institutions,centres,degrees,courses,crs_usr,usr_figures"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=usr_figures.UsrCod"
" AND usr_figures.%s>=0"
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY usr_figures.%s DESC,usr_figures.UsrCod LIMIT 100",
FieldName,
Gbl.CurrentCty.Cty.CtyCod,
FieldName,FieldName);
NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT DISTINCTROW usr_figures.UsrCod,usr_figures.%s"
" FROM institutions,centres,degrees,courses,crs_usr,usr_figures"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=usr_figures.UsrCod"
" AND usr_figures.%s>=0"
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY usr_figures.%s DESC,usr_figures.UsrCod LIMIT 100",
FieldName,
Gbl.CurrentCty.Cty.CtyCod,
FieldName,FieldName);
break;
case Sco_SCOPE_INS:
DB_BuildQuery ("SELECT DISTINCTROW usr_figures.UsrCod,usr_figures.%s"
" FROM centres,degrees,courses,crs_usr,usr_figures"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=usr_figures.UsrCod"
" AND usr_figures.%s>=0"
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY usr_figures.%s DESC,usr_figures.UsrCod LIMIT 100",
FieldName,
Gbl.CurrentIns.Ins.InsCod,
FieldName,FieldName);
NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT DISTINCTROW usr_figures.UsrCod,usr_figures.%s"
" FROM centres,degrees,courses,crs_usr,usr_figures"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=usr_figures.UsrCod"
" AND usr_figures.%s>=0"
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY usr_figures.%s DESC,usr_figures.UsrCod LIMIT 100",
FieldName,
Gbl.CurrentIns.Ins.InsCod,
FieldName,FieldName);
break;
case Sco_SCOPE_CTR:
DB_BuildQuery ("SELECT DISTINCTROW usr_figures.UsrCod,usr_figures.%s"
" FROM degrees,courses,crs_usr,usr_figures"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=usr_figures.UsrCod"
" AND usr_figures.%s>=0"
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY usr_figures.%s DESC,usr_figures.UsrCod LIMIT 100",
FieldName,
Gbl.CurrentCtr.Ctr.CtrCod,
FieldName,FieldName);
NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT DISTINCTROW usr_figures.UsrCod,usr_figures.%s"
" FROM degrees,courses,crs_usr,usr_figures"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=usr_figures.UsrCod"
" AND usr_figures.%s>=0"
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY usr_figures.%s DESC,usr_figures.UsrCod LIMIT 100",
FieldName,
Gbl.CurrentCtr.Ctr.CtrCod,
FieldName,FieldName);
break;
case Sco_SCOPE_DEG:
DB_BuildQuery ("SELECT DISTINCTROW usr_figures.UsrCod,usr_figures.%s"
" FROM courses,crs_usr,usr_figures"
" WHERE courses.DegCod=%ld"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=usr_figures.UsrCod"
" AND usr_figures.%s>=0"
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY usr_figures.%s DESC,usr_figures.UsrCod LIMIT 100",
FieldName,
Gbl.CurrentDeg.Deg.DegCod,
FieldName,FieldName);
NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT DISTINCTROW usr_figures.UsrCod,usr_figures.%s"
" FROM courses,crs_usr,usr_figures"
" WHERE courses.DegCod=%ld"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=usr_figures.UsrCod"
" AND usr_figures.%s>=0"
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY usr_figures.%s DESC,usr_figures.UsrCod LIMIT 100",
FieldName,
Gbl.CurrentDeg.Deg.DegCod,
FieldName,FieldName);
break;
case Sco_SCOPE_CRS:
DB_BuildQuery ("SELECT DISTINCTROW usr_figures.UsrCod,usr_figures.%s"
" FROM crs_usr,usr_figures"
" WHERE crs_usr.CrsCod=%ld"
" AND crs_usr.UsrCod=usr_figures.UsrCod"
" AND usr_figures.%s>=0"
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY usr_figures.%s DESC,usr_figures.UsrCod LIMIT 100",
FieldName,
Gbl.CurrentCrs.Crs.CrsCod,
FieldName,FieldName);
NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT DISTINCTROW usr_figures.UsrCod,usr_figures.%s"
" FROM crs_usr,usr_figures"
" WHERE crs_usr.CrsCod=%ld"
" AND crs_usr.UsrCod=usr_figures.UsrCod"
" AND usr_figures.%s>=0"
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY usr_figures.%s DESC,usr_figures.UsrCod LIMIT 100",
FieldName,
Gbl.CurrentCrs.Crs.CrsCod,
FieldName,FieldName);
break;
default:
Lay_WrongScopeExit ();
break;
}
Prf_ShowRankingFigure ();
Prf_ShowRankingFigure (&mysql_res,NumUsrs);
}
void Prf_ShowRankingFigure (void)
void Prf_ShowRankingFigure (MYSQL_RES **mysql_res,unsigned NumUsrs)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumUsrs;
unsigned NumUsr;
unsigned Rank;
struct UsrData UsrDat;
long FigureHigh = LONG_MAX;
long Figure;
NumUsrs = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get ranking");
if (NumUsrs)
{
/***** Initialize structure with user's data *****/
@ -1267,7 +1282,7 @@ void Prf_ShowRankingFigure (void)
NumUsr++, Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd)
{
/***** Get user and number of clicks *****/
row = mysql_fetch_row (mysql_res);
row = mysql_fetch_row (*mysql_res);
/* Get user's code (row[0]) */
UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0]);
@ -1302,7 +1317,7 @@ void Prf_ShowRankingFigure (void)
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
DB_FreeMySQLResult (mysql_res);
}
/*****************************************************************************/
@ -1313,7 +1328,7 @@ void Prf_GetAndShowRankingClicksPerDay (void)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumUsrs;
unsigned NumUsrs = 0; // Initialized to avoid warning
unsigned NumUsr;
unsigned Rank;
struct UsrData UsrDat;
@ -1324,94 +1339,106 @@ void Prf_GetAndShowRankingClicksPerDay (void)
switch (Gbl.Scope.Current)
{
case Sco_SCOPE_SYS:
DB_BuildQuery ("SELECT UsrCod,"
"NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1) AS NumClicksPerDay"
" FROM usr_figures"
" WHERE NumClicks>0"
" AND UNIX_TIMESTAMP(FirstClickTime)>0"
" AND UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY NumClicksPerDay DESC,UsrCod LIMIT 100");
NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT UsrCod,"
"NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1) AS NumClicksPerDay"
" FROM usr_figures"
" WHERE NumClicks>0"
" AND UNIX_TIMESTAMP(FirstClickTime)>0"
" AND UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY NumClicksPerDay DESC,UsrCod LIMIT 100");
break;
case Sco_SCOPE_CTY:
DB_BuildQuery ("SELECT DISTINCTROW usr_figures.UsrCod,"
"usr_figures.NumClicks/(DATEDIFF(NOW(),"
"usr_figures.FirstClickTime)+1) AS NumClicksPerDay"
" FROM institutions,centres,degrees,courses,crs_usr,usr_figures"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=usr_figures.UsrCod"
" AND usr_figures.NumClicks>0"
" AND UNIX_TIMESTAMP(usr_figures.FirstClickTime)>0"
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY NumClicksPerDay DESC,usr_figures.UsrCod LIMIT 100",
Gbl.CurrentCty.Cty.CtyCod);
NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT DISTINCTROW usr_figures.UsrCod,"
"usr_figures.NumClicks/(DATEDIFF(NOW(),"
"usr_figures.FirstClickTime)+1) AS NumClicksPerDay"
" FROM institutions,centres,degrees,courses,crs_usr,usr_figures"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=usr_figures.UsrCod"
" AND usr_figures.NumClicks>0"
" AND UNIX_TIMESTAMP(usr_figures.FirstClickTime)>0"
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY NumClicksPerDay DESC,usr_figures.UsrCod LIMIT 100",
Gbl.CurrentCty.Cty.CtyCod);
break;
case Sco_SCOPE_INS:
DB_BuildQuery ("SELECT DISTINCTROW usr_figures.UsrCod,"
"usr_figures.NumClicks/(DATEDIFF(NOW(),"
"usr_figures.FirstClickTime)+1) AS NumClicksPerDay"
" FROM centres,degrees,courses,crs_usr,usr_figures"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=usr_figures.UsrCod"
" AND usr_figures.NumClicks>0"
" AND UNIX_TIMESTAMP(usr_figures.FirstClickTime)>0"
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY NumClicksPerDay DESC,usr_figures.UsrCod LIMIT 100",
Gbl.CurrentIns.Ins.InsCod);
NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT DISTINCTROW usr_figures.UsrCod,"
"usr_figures.NumClicks/(DATEDIFF(NOW(),"
"usr_figures.FirstClickTime)+1) AS NumClicksPerDay"
" FROM centres,degrees,courses,crs_usr,usr_figures"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=usr_figures.UsrCod"
" AND usr_figures.NumClicks>0"
" AND UNIX_TIMESTAMP(usr_figures.FirstClickTime)>0"
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY NumClicksPerDay DESC,usr_figures.UsrCod LIMIT 100",
Gbl.CurrentIns.Ins.InsCod);
break;
case Sco_SCOPE_CTR:
DB_BuildQuery ("SELECT DISTINCTROW usr_figures.UsrCod,"
"usr_figures.NumClicks/(DATEDIFF(NOW(),"
"usr_figures.FirstClickTime)+1) AS NumClicksPerDay"
" FROM degrees,courses,crs_usr,usr_figures"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=usr_figures.UsrCod"
" AND usr_figures.NumClicks>0"
" AND UNIX_TIMESTAMP(usr_figures.FirstClickTime)>0"
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY NumClicksPerDay DESC,usr_figures.UsrCod LIMIT 100",
Gbl.CurrentCtr.Ctr.CtrCod);
NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT DISTINCTROW usr_figures.UsrCod,"
"usr_figures.NumClicks/(DATEDIFF(NOW(),"
"usr_figures.FirstClickTime)+1) AS NumClicksPerDay"
" FROM degrees,courses,crs_usr,usr_figures"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=usr_figures.UsrCod"
" AND usr_figures.NumClicks>0"
" AND UNIX_TIMESTAMP(usr_figures.FirstClickTime)>0"
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY NumClicksPerDay DESC,usr_figures.UsrCod LIMIT 100",
Gbl.CurrentCtr.Ctr.CtrCod);
break;
case Sco_SCOPE_DEG:
DB_BuildQuery ("SELECT DISTINCTROW usr_figures.UsrCod,"
"usr_figures.NumClicks/(DATEDIFF(NOW(),"
"usr_figures.FirstClickTime)+1) AS NumClicksPerDay"
" FROM courses,crs_usr,usr_figures"
" WHERE courses.DegCod=%ld"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=usr_figures.UsrCod"
" AND usr_figures.NumClicks>0"
" AND UNIX_TIMESTAMP(usr_figures.FirstClickTime)>0"
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY NumClicksPerDay DESC,usr_figures.UsrCod LIMIT 100",
Gbl.CurrentDeg.Deg.DegCod);
NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT DISTINCTROW usr_figures.UsrCod,"
"usr_figures.NumClicks/(DATEDIFF(NOW(),"
"usr_figures.FirstClickTime)+1) AS NumClicksPerDay"
" FROM courses,crs_usr,usr_figures"
" WHERE courses.DegCod=%ld"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=usr_figures.UsrCod"
" AND usr_figures.NumClicks>0"
" AND UNIX_TIMESTAMP(usr_figures.FirstClickTime)>0"
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY NumClicksPerDay DESC,usr_figures.UsrCod LIMIT 100",
Gbl.CurrentDeg.Deg.DegCod);
break;
case Sco_SCOPE_CRS:
DB_BuildQuery ("SELECT DISTINCTROW usr_figures.UsrCod,"
"usr_figures.NumClicks/(DATEDIFF(NOW(),"
"usr_figures.FirstClickTime)+1) AS NumClicksPerDay"
" FROM crs_usr,usr_figures"
" WHERE crs_usr.CrsCod=%ld"
" AND crs_usr.UsrCod=usr_figures.UsrCod"
" AND usr_figures.NumClicks>0"
" AND UNIX_TIMESTAMP(usr_figures.FirstClickTime)>0"
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY NumClicksPerDay DESC,usr_figures.UsrCod LIMIT 100",
Gbl.CurrentCrs.Crs.CrsCod);
NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT DISTINCTROW usr_figures.UsrCod,"
"usr_figures.NumClicks/(DATEDIFF(NOW(),"
"usr_figures.FirstClickTime)+1) AS NumClicksPerDay"
" FROM crs_usr,usr_figures"
" WHERE crs_usr.CrsCod=%ld"
" AND crs_usr.UsrCod=usr_figures.UsrCod"
" AND usr_figures.NumClicks>0"
" AND UNIX_TIMESTAMP(usr_figures.FirstClickTime)>0"
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY NumClicksPerDay DESC,usr_figures.UsrCod LIMIT 100",
Gbl.CurrentCrs.Crs.CrsCod);
break;
default:
Lay_WrongScopeExit ();
break;
}
NumUsrs = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get ranking");
if (NumUsrs)
{
/***** Initialize structure with user's data *****/

View File

@ -77,7 +77,7 @@ void Prf_GetAndShowRankingClicks (void);
void Prf_GetAndShowRankingFileViews (void);
void Prf_GetAndShowRankingForPst (void);
void Prf_GetAndShowRankingMsgSnt (void);
void Prf_ShowRankingFigure (void);
void Prf_ShowRankingFigure (MYSQL_RES **mysql_res,unsigned NumUsrs);
void Prf_GetAndShowRankingClicksPerDay (void);
void Prf_ShowUsrInRanking (struct UsrData *UsrDat,unsigned Rank);

View File

@ -169,7 +169,6 @@ static void Prj_PutFormsToRemEditOnePrj (long PrjCod,Prj_HiddenVisibl_t Hidden,
static bool Prj_CheckIfICanEditProject (long PrjCod);
static void Prj_GetDataOfProject (struct Project *Prj);
static void Prj_ResetProject (struct Project *Prj);
static void Prj_RequestCreatOrEditPrj (long PrjCod);
@ -1800,17 +1799,16 @@ static unsigned Prj_GetUsrsInPrj (long PrjCod,Prj_RoleInProject_t RoleInProject,
MYSQL_RES **mysql_res)
{
/***** Get users in project from database *****/
DB_BuildQuery ("SELECT prj_usr.UsrCod,"
"usr_data.Surname1 AS S1,"
"usr_data.Surname2 AS S2,"
"usr_data.FirstName AS FN"
" FROM prj_usr,usr_data"
" WHERE prj_usr.PrjCod=%ld AND RoleInProject=%u"
" AND prj_usr.UsrCod=usr_data.UsrCod"
" ORDER BY S1,S2,FN",
PrjCod,(unsigned) RoleInProject);
return (unsigned) DB_QuerySELECT_new (mysql_res,
"can not get users in project");
return (unsigned) DB_QuerySELECT (mysql_res,"can not get users in project",
"SELECT prj_usr.UsrCod,"
"usr_data.Surname1 AS S1,"
"usr_data.Surname2 AS S2,"
"usr_data.FirstName AS FN"
" FROM prj_usr,usr_data"
" WHERE prj_usr.PrjCod=%ld AND RoleInProject=%u"
" AND prj_usr.UsrCod=usr_data.UsrCod"
" ORDER BY S1,S2,FN",
PrjCod,(unsigned) RoleInProject);
}
/*****************************************************************************/
@ -1841,10 +1839,10 @@ Prj_RoleInProject_t Prj_GetMyRoleInProject (long PrjCod)
The result of the query will have one row or none *****/
Gbl.Cache.MyRoleInProject.PrjCod = PrjCod;
Gbl.Cache.MyRoleInProject.RoleInProject = Prj_ROLE_UNK;
DB_BuildQuery ("SELECT RoleInProject FROM prj_usr"
" WHERE PrjCod=%ld AND UsrCod=%ld",
PrjCod,Gbl.Usrs.Me.UsrDat.UsrCod);
if (DB_QuerySELECT_new (&mysql_res,"can not get my role in project"))
if (DB_QuerySELECT (&mysql_res,"can not get my role in project",
"SELECT RoleInProject FROM prj_usr"
" WHERE PrjCod=%ld AND UsrCod=%ld",
PrjCod,Gbl.Usrs.Me.UsrDat.UsrCod))
{
row = mysql_fetch_row (mysql_res);
Gbl.Cache.MyRoleInProject.RoleInProject = Prj_ConvertUnsignedStrToRoleInProject (row[0]);
@ -2288,7 +2286,7 @@ void Prj_GetListProjects (void)
char OrderBySubQuery[Prj_MAX_BYTES_SUBQUERY];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
unsigned long NumRows = 0; // Initialized to avoid warning
unsigned NumPrj;
if (Gbl.Prjs.LstIsRead)
@ -2386,31 +2384,33 @@ void Prj_GetListProjects (void)
case Prj_ORDER_START_TIME:
case Prj_ORDER_END_TIME:
case Prj_ORDER_TITLE:
DB_BuildQuery ("SELECT projects.PrjCod"
" FROM projects,prj_usr"
" WHERE projects.CrsCod=%ld"
"%s%s%s"
" AND projects.PrjCod=prj_usr.PrjCod"
" AND prj_usr.UsrCod=%ld"
" ORDER BY %s",
Gbl.CurrentCrs.Crs.CrsCod,
PreNonSubQuery,HidVisSubQuery,DptCodSubQuery,
Gbl.Usrs.Me.UsrDat.UsrCod,
OrderBySubQuery);
NumRows = DB_QuerySELECT (&mysql_res,"can not get projects",
"SELECT projects.PrjCod"
" FROM projects,prj_usr"
" WHERE projects.CrsCod=%ld"
"%s%s%s"
" AND projects.PrjCod=prj_usr.PrjCod"
" AND prj_usr.UsrCod=%ld"
" ORDER BY %s",
Gbl.CurrentCrs.Crs.CrsCod,
PreNonSubQuery,HidVisSubQuery,DptCodSubQuery,
Gbl.Usrs.Me.UsrDat.UsrCod,
OrderBySubQuery);
break;
case Prj_ORDER_DEPARTMENT:
DB_BuildQuery ("SELECT projects.PrjCod"
" FROM prj_usr,projects LEFT JOIN departments"
" ON projects.DptCod=departments.DptCod"
" WHERE projects.CrsCod=%ld"
"%s%s%s"
" AND projects.PrjCod=prj_usr.PrjCod"
" AND prj_usr.UsrCod=%ld"
" ORDER BY %s",
Gbl.CurrentCrs.Crs.CrsCod,
PreNonSubQuery,HidVisSubQuery,DptCodSubQuery,
Gbl.Usrs.Me.UsrDat.UsrCod,
OrderBySubQuery);
NumRows = DB_QuerySELECT (&mysql_res,"can not get projects",
"SELECT projects.PrjCod"
" FROM prj_usr,projects LEFT JOIN departments"
" ON projects.DptCod=departments.DptCod"
" WHERE projects.CrsCod=%ld"
"%s%s%s"
" AND projects.PrjCod=prj_usr.PrjCod"
" AND prj_usr.UsrCod=%ld"
" ORDER BY %s",
Gbl.CurrentCrs.Crs.CrsCod,
PreNonSubQuery,HidVisSubQuery,DptCodSubQuery,
Gbl.Usrs.Me.UsrDat.UsrCod,
OrderBySubQuery);
break;
}
else // Gbl.Prjs.My_All == Prj_ALL_PROJECTS
@ -2419,30 +2419,30 @@ void Prj_GetListProjects (void)
case Prj_ORDER_START_TIME:
case Prj_ORDER_END_TIME:
case Prj_ORDER_TITLE:
DB_BuildQuery ("SELECT projects.PrjCod"
" FROM projects"
" WHERE projects.CrsCod=%ld"
"%s%s%s"
" ORDER BY %s",
Gbl.CurrentCrs.Crs.CrsCod,
PreNonSubQuery,HidVisSubQuery,DptCodSubQuery,
OrderBySubQuery);
NumRows = DB_QuerySELECT (&mysql_res,"can not get projects",
"SELECT projects.PrjCod"
" FROM projects"
" WHERE projects.CrsCod=%ld"
"%s%s%s"
" ORDER BY %s",
Gbl.CurrentCrs.Crs.CrsCod,
PreNonSubQuery,HidVisSubQuery,DptCodSubQuery,
OrderBySubQuery);
break;
case Prj_ORDER_DEPARTMENT:
DB_BuildQuery ("SELECT projects.PrjCod"
" FROM projects LEFT JOIN departments"
" ON projects.DptCod=departments.DptCod"
" WHERE projects.CrsCod=%ld"
"%s%s%s"
" ORDER BY %s",
Gbl.CurrentCrs.Crs.CrsCod,
PreNonSubQuery,HidVisSubQuery,DptCodSubQuery,
OrderBySubQuery);
NumRows = DB_QuerySELECT (&mysql_res,"can not get projects",
"SELECT projects.PrjCod"
" FROM projects LEFT JOIN departments"
" ON projects.DptCod=departments.DptCod"
" WHERE projects.CrsCod=%ld"
"%s%s%s"
" ORDER BY %s",
Gbl.CurrentCrs.Crs.CrsCod,
PreNonSubQuery,HidVisSubQuery,DptCodSubQuery,
OrderBySubQuery);
break;
}
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get projects");
if (NumRows) // Projects found...
{
Gbl.Prjs.Num = (unsigned) NumRows;
@ -2485,8 +2485,9 @@ long Prj_GetCourseOfProject (long PrjCod)
if (PrjCod > 0)
{
/***** Get course code from database *****/
DB_BuildQuery ("SELECT CrsCod FROM projects WHERE PrjCod=%ld",PrjCod);
if (DB_QuerySELECT_new (&mysql_res,"can not get project course")) // Project found...
if (DB_QuerySELECT (&mysql_res,"can not get project course",
"SELECT CrsCod FROM projects WHERE PrjCod=%ld",
PrjCod)) // Project found...
{
/* Get row */
row = mysql_fetch_row (mysql_res);
@ -2508,35 +2509,104 @@ long Prj_GetCourseOfProject (long PrjCod)
void Prj_GetDataOfProjectByCod (struct Project *Prj)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
long NumLong;
Prj_Proposal_t Proposal;
if (Prj->PrjCod > 0)
{
/***** Build query *****/
DB_BuildQuery ("SELECT PrjCod,CrsCod,DptCod,Hidden,Preassigned,NumStds,Proposal,"
"UNIX_TIMESTAMP(CreatTime),"
"UNIX_TIMESTAMP(ModifTime),"
"Title,Description,Knowledge,Materials,URL"
" FROM projects"
" WHERE PrjCod=%ld AND CrsCod=%ld",
Prj->PrjCod,Gbl.CurrentCrs.Crs.CrsCod);
/*
row[ 0]: PrjCod
row[ 1]: CrsCod
row[ 2]: DptCod
row[ 3]: Hidden
row[ 4]: Preassigned
row[ 5]: NumStds
row[ 6]: Proposal
row[ 7]: UNIX_TIMESTAMP(CreatTime)
row[ 8]: UNIX_TIMESTAMP(ModifTime)
row[ 9]: Title
row[10]: Description
row[11]: Knowledge
row[12]: Materials
row[13]: URL
*/
/***** Clear all project data *****/
Prj_ResetProject (Prj);
/***** Get data of project *****/
Prj_GetDataOfProject (Prj);
if (DB_QuerySELECT (&mysql_res,"can not get project data",
"SELECT PrjCod," // row[ 0]
"CrsCod," // row[ 1]
"DptCod," // row[ 2]
"Hidden," // row[ 3]
"Preassigned," // row[ 4]
"NumStds," // row[ 5]
"Proposal," // row[ 6]
"UNIX_TIMESTAMP(CreatTime)," // row[ 7]
"UNIX_TIMESTAMP(ModifTime)," // row[ 8]
"Title," // row[ 9]
"Description," // row[10]
"Knowledge," // row[11]
"Materials," // row[12]
"URL" // row[13]
" FROM projects"
" WHERE PrjCod=%ld AND CrsCod=%ld",
Prj->PrjCod,
Gbl.CurrentCrs.Crs.CrsCod)) // Project found...
{
/* Get row */
row = mysql_fetch_row (mysql_res);
/* Get code of the project (row[0]) */
Prj->PrjCod = Str_ConvertStrCodToLongCod (row[0]);
/* Get code of the course (row[1]) */
Prj->CrsCod = Str_ConvertStrCodToLongCod (row[1]);
/* Get code of the department (row[2]) */
Prj->DptCod = Str_ConvertStrCodToLongCod (row[2]);
/* Get whether the project is hidden or not (row[3]) */
Prj->Hidden = (row[3][0] == 'Y') ? Prj_HIDDEN :
Prj_VISIBL;
/* Get if project is preassigned or not (row[4]) */
Prj->Preassigned = (row[4][0] == 'Y') ? Prj_PREASSIGNED :
Prj_NONPREASSIG;
/* Get if project is preassigned or not (row[5]) */
NumLong = Str_ConvertStrCodToLongCod (row[5]);
if (NumLong >= 0)
Prj->NumStds = (unsigned) NumLong;
else
Prj->NumStds = 1;
/* Get project status (row[6]) */
Prj->Proposal = Prj_PROPOSAL_DEFAULT;
for (Proposal = (Prj_Proposal_t) 0;
Proposal <= (Prj_Proposal_t) (Prj_NUM_PROPOSAL_TYPES - 1);
Proposal++)
if (!strcmp (Prj_Proposal_DB[Proposal],row[6]))
{
Prj->Proposal = Proposal;
break;
}
/* Get creation date/time (row[7] holds the creation UTC time) */
Prj->CreatTime = Dat_GetUNIXTimeFromStr (row[7]);
/* Get modification date/time (row[8] holds the modification UTC time) */
Prj->ModifTime = Dat_GetUNIXTimeFromStr (row[8]);
/* Get the title of the project (row[9]) */
Str_Copy (Prj->Title,row[9],
Prj_MAX_BYTES_PROJECT_TITLE);
/* Get the description of the project (row[10]) */
Str_Copy (Prj->Description,row[10],
Cns_MAX_BYTES_TEXT);
/* Get the required knowledge for the project (row[11]) */
Str_Copy (Prj->Knowledge,row[11],
Cns_MAX_BYTES_TEXT);
/* Get the required materials for the project (row[12]) */
Str_Copy (Prj->Materials,row[12],
Cns_MAX_BYTES_TEXT);
/* Get the URL of the project (row[13]) */
Str_Copy (Prj->URL,row[13],
Cns_MAX_BYTES_WWW);
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
else
{
@ -2546,108 +2616,6 @@ void Prj_GetDataOfProjectByCod (struct Project *Prj)
}
}
/*****************************************************************************/
/**************************** Get project data *******************************/
/*****************************************************************************/
static void Prj_GetDataOfProject (struct Project *Prj)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
long NumLong;
Prj_Proposal_t Proposal;
/***** Clear all project data *****/
Prj_ResetProject (Prj);
/***** Get data of project from database *****/
if (DB_QuerySELECT_new (&mysql_res,"can not get project data")) // Project found...
{
/* Get row */
row = mysql_fetch_row (mysql_res);
/*
row[ 0]: PrjCod
row[ 1]: CrsCod
row[ 2]: DptCod
row[ 3]: Hidden
row[ 4]: Preassigned
row[ 5]: NumStds
row[ 6]: Proposal
row[ 7]: UNIX_TIMESTAMP(CreatTime)
row[ 8]: UNIX_TIMESTAMP(ModifTime)
row[ 9]: Title
row[10]: Description
row[11]: Knowledge
row[12]: Materials
row[13]: URL
*/
/* Get code of the project (row[0]) */
Prj->PrjCod = Str_ConvertStrCodToLongCod (row[0]);
/* Get code of the course (row[1]) */
Prj->CrsCod = Str_ConvertStrCodToLongCod (row[1]);
/* Get code of the department (row[2]) */
Prj->DptCod = Str_ConvertStrCodToLongCod (row[2]);
/* Get whether the project is hidden or not (row[3]) */
Prj->Hidden = (row[3][0] == 'Y') ? Prj_HIDDEN :
Prj_VISIBL;
/* Get if project is preassigned or not (row[4]) */
Prj->Preassigned = (row[4][0] == 'Y') ? Prj_PREASSIGNED :
Prj_NONPREASSIG;
/* Get if project is preassigned or not (row[5]) */
NumLong = Str_ConvertStrCodToLongCod (row[5]);
if (NumLong >= 0)
Prj->NumStds = (unsigned) NumLong;
else
Prj->NumStds = 1;
/* Get project status (row[6]) */
Prj->Proposal = Prj_PROPOSAL_DEFAULT;
for (Proposal = (Prj_Proposal_t) 0;
Proposal <= (Prj_Proposal_t) (Prj_NUM_PROPOSAL_TYPES - 1);
Proposal++)
if (!strcmp (Prj_Proposal_DB[Proposal],row[6]))
{
Prj->Proposal = Proposal;
break;
}
/* Get creation date/time (row[7] holds the creation UTC time) */
Prj->CreatTime = Dat_GetUNIXTimeFromStr (row[7]);
/* Get modification date/time (row[8] holds the modification UTC time) */
Prj->ModifTime = Dat_GetUNIXTimeFromStr (row[8]);
/* Get the title of the project (row[9]) */
Str_Copy (Prj->Title,row[9],
Prj_MAX_BYTES_PROJECT_TITLE);
/* Get the description of the project (row[10]) */
Str_Copy (Prj->Description,row[10],
Cns_MAX_BYTES_TEXT);
/* Get the required knowledge for the project (row[11]) */
Str_Copy (Prj->Knowledge,row[11],
Cns_MAX_BYTES_TEXT);
/* Get the required materials for the project (row[12]) */
Str_Copy (Prj->Materials,row[12],
Cns_MAX_BYTES_TEXT);
/* Get the URL of the project (row[13]) */
Str_Copy (Prj->URL,row[13],
Cns_MAX_BYTES_WWW);
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/************************** Clear all project data ***************************/
/*****************************************************************************/
@ -3472,59 +3440,64 @@ unsigned Prj_GetNumCoursesWithProjects (Sco_Scope_t Scope)
switch (Scope)
{
case Sco_SCOPE_SYS:
DB_BuildQuery ("SELECT COUNT(DISTINCT CrsCod)"
" FROM projects"
" WHERE CrsCod>0");
DB_QuerySELECT (&mysql_res,"can not get number of courses with projects",
"SELECT COUNT(DISTINCT CrsCod)"
" FROM projects"
" WHERE CrsCod>0");
break;
case Sco_SCOPE_CTY:
DB_BuildQuery ("SELECT COUNT(DISTINCT projects.CrsCod)"
" FROM institutions,centres,degrees,courses,projects"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.Status=0"
" AND courses.CrsCod=projects.CrsCod",
Gbl.CurrentCty.Cty.CtyCod);
DB_QuerySELECT (&mysql_res,"can not get number of courses with projects",
"SELECT COUNT(DISTINCT projects.CrsCod)"
" FROM institutions,centres,degrees,courses,projects"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.Status=0"
" AND courses.CrsCod=projects.CrsCod",
Gbl.CurrentCty.Cty.CtyCod);
break;
case Sco_SCOPE_INS:
DB_BuildQuery ("SELECT COUNT(DISTINCT projects.CrsCod)"
" FROM centres,degrees,courses,projects"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.Status=0"
" AND courses.CrsCod=projects.CrsCod",
Gbl.CurrentIns.Ins.InsCod);
DB_QuerySELECT (&mysql_res,"can not get number of courses with projects",
"SELECT COUNT(DISTINCT projects.CrsCod)"
" FROM centres,degrees,courses,projects"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.Status=0"
" AND courses.CrsCod=projects.CrsCod",
Gbl.CurrentIns.Ins.InsCod);
break;
case Sco_SCOPE_CTR:
DB_BuildQuery ("SELECT COUNT(DISTINCT projects.CrsCod)"
" FROM degrees,courses,projects"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.Status=0"
" AND courses.CrsCod=projects.CrsCod",
Gbl.CurrentCtr.Ctr.CtrCod);
DB_QuerySELECT (&mysql_res,"can not get number of courses with projects",
"SELECT COUNT(DISTINCT projects.CrsCod)"
" FROM degrees,courses,projects"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.Status=0"
" AND courses.CrsCod=projects.CrsCod",
Gbl.CurrentCtr.Ctr.CtrCod);
break;
case Sco_SCOPE_DEG:
DB_BuildQuery ("SELECT COUNT(DISTINCT projects.CrsCod)"
" FROM courses,projects"
" WHERE courses.DegCod=%ld"
" AND courses.Status=0"
" AND courses.CrsCod=projects.CrsCod",
Gbl.CurrentDeg.Deg.DegCod);
DB_QuerySELECT (&mysql_res,"can not get number of courses with projects",
"SELECT COUNT(DISTINCT projects.CrsCod)"
" FROM courses,projects"
" WHERE courses.DegCod=%ld"
" AND courses.Status=0"
" AND courses.CrsCod=projects.CrsCod",
Gbl.CurrentDeg.Deg.DegCod);
break;
case Sco_SCOPE_CRS:
DB_BuildQuery ("SELECT COUNT(DISTINCT CrsCod)"
" FROM projects"
" WHERE CrsCod=%ld",
Gbl.CurrentCrs.Crs.CrsCod);
DB_QuerySELECT (&mysql_res,"can not get number of courses with projects",
"SELECT COUNT(DISTINCT CrsCod)"
" FROM projects"
" WHERE CrsCod=%ld",
Gbl.CurrentCrs.Crs.CrsCod);
break;
default:
Lay_WrongScopeExit ();
break;
}
DB_QuerySELECT_new (&mysql_res,"can not get number of courses with projects");
/***** Get number of courses *****/
row = mysql_fetch_row (mysql_res);
@ -3552,55 +3525,60 @@ unsigned Prj_GetNumProjects (Sco_Scope_t Scope)
switch (Scope)
{
case Sco_SCOPE_SYS:
DB_BuildQuery ("SELECT COUNT(*)"
" FROM projects"
" WHERE CrsCod>0");
DB_QuerySELECT (&mysql_res,"can not get number of projects",
"SELECT COUNT(*)"
" FROM projects"
" WHERE CrsCod>0");
break;
case Sco_SCOPE_CTY:
DB_BuildQuery ("SELECT COUNT(*)"
" FROM institutions,centres,degrees,courses,projects"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=projects.CrsCod",
Gbl.CurrentCty.Cty.CtyCod);
DB_QuerySELECT (&mysql_res,"can not get number of projects",
"SELECT COUNT(*)"
" FROM institutions,centres,degrees,courses,projects"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=projects.CrsCod",
Gbl.CurrentCty.Cty.CtyCod);
break;
case Sco_SCOPE_INS:
DB_BuildQuery ("SELECT COUNT(*)"
" FROM centres,degrees,courses,projects"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=projects.CrsCod",
Gbl.CurrentIns.Ins.InsCod);
DB_QuerySELECT (&mysql_res,"can not get number of projects",
"SELECT COUNT(*)"
" FROM centres,degrees,courses,projects"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=projects.CrsCod",
Gbl.CurrentIns.Ins.InsCod);
break;
case Sco_SCOPE_CTR:
DB_BuildQuery ("SELECT COUNT(*)"
" FROM degrees,courses,projects"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=projects.CrsCod",
Gbl.CurrentCtr.Ctr.CtrCod);
DB_QuerySELECT (&mysql_res,"can not get number of projects",
"SELECT COUNT(*)"
" FROM degrees,courses,projects"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=projects.CrsCod",
Gbl.CurrentCtr.Ctr.CtrCod);
break;
case Sco_SCOPE_DEG:
DB_BuildQuery ("SELECT COUNT(*)"
" FROM courses,projects"
" WHERE courses.DegCod=%ld"
" AND courses.CrsCod=projects.CrsCod",
Gbl.CurrentDeg.Deg.DegCod);
DB_QuerySELECT (&mysql_res,"can not get number of projects",
"SELECT COUNT(*)"
" FROM courses,projects"
" WHERE courses.DegCod=%ld"
" AND courses.CrsCod=projects.CrsCod",
Gbl.CurrentDeg.Deg.DegCod);
break;
case Sco_SCOPE_CRS:
DB_BuildQuery ("SELECT COUNT(*)"
" FROM projects"
" WHERE CrsCod=%ld",
Gbl.CurrentCrs.Crs.CrsCod);
DB_QuerySELECT (&mysql_res,"can not get number of projects",
"SELECT COUNT(*)"
" FROM projects"
" WHERE CrsCod=%ld",
Gbl.CurrentCrs.Crs.CrsCod);
break;
default:
Lay_WrongScopeExit ();
break;
}
DB_QuerySELECT_new (&mysql_res,"can not get number of projects");
/***** Get number of projects *****/
row = mysql_fetch_row (mysql_res);

View File

@ -231,12 +231,14 @@ void Rec_GetListRecordFieldsInCurrentCrs (void)
if (++Gbl.CurrentCrs.Records.LstFields.NestedCalls > 1) // If the list is already created, don't do anything
return;
/***** Get fields of cards of a course from database *****/
DB_BuildQuery ("SELECT FieldCod,FieldName,NumLines,Visibility"
" FROM crs_record_fields"
" WHERE CrsCod=%ld ORDER BY FieldName",
Gbl.CurrentCrs.Crs.CrsCod);
Gbl.CurrentCrs.Records.LstFields.Num = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get fields of cards of a course");
/***** Get fields of records in a course from database *****/
Gbl.CurrentCrs.Records.LstFields.Num =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get fields of records"
" in a course",
"SELECT FieldCod,FieldName,NumLines,Visibility"
" FROM crs_record_fields"
" WHERE CrsCod=%ld ORDER BY FieldName",
Gbl.CurrentCrs.Crs.CrsCod);
/***** Get the fields of records *****/
if (Gbl.CurrentCrs.Records.LstFields.Num)
@ -557,13 +559,13 @@ bool Rec_CheckIfRecordFieldIsRepeated (const char *FieldName)
unsigned long Rec_GetAllFieldsInCurrCrs (MYSQL_RES **mysql_res)
{
/***** Get fields of cards of current course from database *****/
DB_BuildQuery ("SELECT FieldCod,FieldName,Visibility"
" FROM crs_record_fields"
" WHERE CrsCod=%ld ORDER BY FieldName",
Gbl.CurrentCrs.Crs.CrsCod);
return DB_QuerySELECT_new (mysql_res,
"can not get fields of cards of a course");
/***** Get fields of records in current course from database *****/
return DB_QuerySELECT (mysql_res,"can not get fields of records"
" in a course",
"SELECT FieldCod,FieldName,Visibility"
" FROM crs_record_fields"
" WHERE CrsCod=%ld ORDER BY FieldName",
Gbl.CurrentCrs.Crs.CrsCod);
}
/*****************************************************************************/
@ -732,10 +734,12 @@ static void Rec_GetFieldByCod (long FieldCod,char Name[Rec_MAX_BYTES_NAME_FIELD
unsigned Vis;
/***** Get a field of a record in a course from database *****/
DB_BuildQuery ("SELECT FieldName,NumLines,Visibility FROM crs_record_fields"
" WHERE CrsCod=%ld AND FieldCod=%ld",
Gbl.CurrentCrs.Crs.CrsCod,FieldCod);
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get a field of a record in a course");
NumRows = DB_QuerySELECT (&mysql_res,"can not get a field of a record"
" in a course",
"SELECT FieldName,NumLines,Visibility"
" FROM crs_record_fields"
" WHERE CrsCod=%ld AND FieldCod=%ld",
Gbl.CurrentCrs.Crs.CrsCod,FieldCod);
/***** Count number of rows in result *****/
if (NumRows != 1)
@ -1941,10 +1945,11 @@ static void Rec_ShowCrsRecord (Rec_CourseRecordViewType_t TypeOfView,
unsigned long Rec_GetFieldFromCrsRecord (long UsrCod,long FieldCod,MYSQL_RES **mysql_res)
{
/***** Get the text of a field of a record from database *****/
DB_BuildQuery ("SELECT Txt FROM crs_records"
" WHERE FieldCod=%ld AND UsrCod=%ld",
FieldCod,UsrCod);
return DB_QuerySELECT_new (mysql_res,"can not get the text of a field of a record.");
return DB_QuerySELECT (mysql_res,"can not get the text"
" of a field of a record",
"SELECT Txt FROM crs_records"
" WHERE FieldCod=%ld AND UsrCod=%ld",
FieldCod,UsrCod);
}
/*****************************************************************************/

View File

@ -794,13 +794,15 @@ static void Rep_WriteSectionHitsPerAction (struct Rep_Report *Report)
Txt_Hits_per_action);
/***** Make the query *****/
DB_BuildQuery ("SELECT SQL_NO_CACHE ActCod,COUNT(*) AS N FROM log_full"
" WHERE ClickTime>=FROM_UNIXTIME(%ld) AND UsrCod=%ld"
" GROUP BY ActCod ORDER BY N DESC LIMIT %u",
(long) Report->UsrFigures.FirstClickTimeUTC,
Gbl.Usrs.Me.UsrDat.UsrCod,
Rep_MAX_ACTIONS);
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get clicks");
NumRows = DB_QuerySELECT (&mysql_res,"can not get clicks",
"SELECT SQL_NO_CACHE ActCod,COUNT(*) AS N"
" FROM log_full"
" WHERE ClickTime>=FROM_UNIXTIME(%ld)"
" AND UsrCod=%ld"
" GROUP BY ActCod ORDER BY N DESC LIMIT %u",
(long) Report->UsrFigures.FirstClickTimeUTC,
Gbl.Usrs.Me.UsrDat.UsrCod,
Rep_MAX_ACTIONS);
/***** Compute maximum number of hits per action *****/
Rep_ComputeMaxAndTotalHits (&Report->Hits,NumRows,mysql_res,1);
@ -929,43 +931,43 @@ static void Rep_GetMaxHitsPerYear (struct Rep_Report *Report)
MYSQL_RES *mysql_res;
MYSQL_ROW row;
DB_BuildQuery ("SELECT MAX(N) FROM ("
// Clicks without course selected ---------------------------
"SELECT "
"-1 AS CrsCod,"
"YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year,"
"%u AS Role,"
"COUNT(*) AS N"
" FROM log_full"
" WHERE ClickTime>=FROM_UNIXTIME(%ld)"
" AND UsrCod=%ld"
" AND CrsCod<=0"
" GROUP BY Year"
// ----------------------------------------------------------
" UNION "
// Clicks as student, non-editing teacher or teacher in courses
"SELECT "
"CrsCod,"
"YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year,"
"Role,"
"COUNT(*) AS N"
" FROM log_full"
" WHERE ClickTime>=FROM_UNIXTIME(%ld)"
" AND UsrCod=%ld"
" AND Role>=%u" // Student
" AND Role<=%u" // Teacher
" AND CrsCod>0"
" GROUP BY CrsCod,Year,Role"
// ----------------------------------------------------------
") AS hits_per_crs_year",
(unsigned) Rol_UNK,
(long) Report->UsrFigures.FirstClickTimeUTC,
Gbl.Usrs.Me.UsrDat.UsrCod,
(long) Report->UsrFigures.FirstClickTimeUTC,
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Rol_STD,
(unsigned) Rol_TCH);
DB_QuerySELECT_new (&mysql_res,"can not get last question index");
DB_QuerySELECT (&mysql_res,"can not get last question index",
"SELECT MAX(N) FROM ("
// Clicks without course selected --------------------------
"SELECT "
"-1 AS CrsCod,"
"YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year,"
"%u AS Role,"
"COUNT(*) AS N"
" FROM log_full"
" WHERE ClickTime>=FROM_UNIXTIME(%ld)"
" AND UsrCod=%ld"
" AND CrsCod<=0"
" GROUP BY Year"
// ---------------------------------------------------------
" UNION "
// Clicks as student, non-editing teacher or teacher in courses
"SELECT "
"CrsCod,"
"YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year,"
"Role,"
"COUNT(*) AS N"
" FROM log_full"
" WHERE ClickTime>=FROM_UNIXTIME(%ld)"
" AND UsrCod=%ld"
" AND Role>=%u" // Student
" AND Role<=%u" // Teacher
" AND CrsCod>0"
" GROUP BY CrsCod,Year,Role"
// ---------------------------------------------------------
") AS hits_per_crs_year",
(unsigned) Rol_UNK,
(long) Report->UsrFigures.FirstClickTimeUTC,
Gbl.Usrs.Me.UsrDat.UsrCod,
(long) Report->UsrFigures.FirstClickTimeUTC,
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Rol_STD,
(unsigned) Rol_TCH);
/***** Get number of users *****/
Report->MaxHitsPerYear = 0;
@ -1015,19 +1017,21 @@ static void Rep_GetAndWriteMyCurrentCrss (Rol_Role_t Role,
Txt_students_ABBREVIATION);
/***** Get courses of a user from database *****/
DB_BuildQuery ("SELECT crs_usr.CrsCod,log_full.CrsCod,COUNT(*) AS N"
" FROM crs_usr LEFT JOIN log_full ON"
" (crs_usr.CrsCod=log_full.CrsCod"
" AND crs_usr.UsrCod=log_full.UsrCod"
" AND crs_usr.Role=log_full.Role)"
" WHERE crs_usr.UsrCod=%ld"
" AND crs_usr.Role=%u"
" GROUP BY crs_usr.CrsCod"
" ORDER BY N DESC,log_full.CrsCod DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) Role);
NumCrss =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get courses of a user",
"SELECT crs_usr.CrsCod,log_full.CrsCod,COUNT(*) AS N"
" FROM crs_usr LEFT JOIN log_full ON"
" (crs_usr.CrsCod=log_full.CrsCod"
" AND crs_usr.UsrCod=log_full.UsrCod"
" AND crs_usr.Role=log_full.Role)"
" WHERE crs_usr.UsrCod=%ld"
" AND crs_usr.Role=%u"
" GROUP BY crs_usr.CrsCod"
" ORDER BY N DESC,log_full.CrsCod DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) Role);
/***** List the courses (one row per course) *****/
if ((NumCrss = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get courses of a user")))
if (NumCrss)
{
/* Heading row */
fprintf (Gbl.F.Rep,"<ol>");
@ -1099,17 +1103,19 @@ static void Rep_GetAndWriteMyHistoricCrss (Rol_Role_t Role,
long CrsCod;
/***** Get historic courses of a user from log *****/
DB_BuildQuery ("SELECT CrsCod,COUNT(*) AS N"
" FROM log_full"
" WHERE UsrCod=%ld AND Role=%u AND CrsCod>0"
" GROUP BY CrsCod"
" HAVING N>%u"
" ORDER BY N DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) Role,
Rep_MIN_CLICKS_CRS);
NumCrss =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get courses of a user",
"SELECT CrsCod,COUNT(*) AS N"
" FROM log_full"
" WHERE UsrCod=%ld AND Role=%u AND CrsCod>0"
" GROUP BY CrsCod"
" HAVING N>%u"
" ORDER BY N DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) Role,
Rep_MIN_CLICKS_CRS);
/***** List the courses (one row per course) *****/
if ((NumCrss = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get courses of a user")))
if (NumCrss)
{
/* Heading row */
snprintf (Gbl.Title,sizeof (Gbl.Title),
@ -1235,17 +1241,17 @@ static void Rep_ShowMyHitsPerYear (bool AnyCourse,long CrsCod,Rol_Role_t Role,
else
sprintf (SubQueryRol," AND Role=%u",(unsigned) Role);
DB_BuildQuery ("SELECT SQL_NO_CACHE "
"YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year,"
"COUNT(*) FROM log_full"
" WHERE ClickTime>=FROM_UNIXTIME(%ld)"
" AND UsrCod=%ld%s%s"
" GROUP BY Year DESC",
(long) Report->UsrFigures.FirstClickTimeUTC,
Gbl.Usrs.Me.UsrDat.UsrCod,
SubQueryCrs,
SubQueryRol);
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get clicks");
NumRows = DB_QuerySELECT (&mysql_res,"can not get clicks",
"SELECT SQL_NO_CACHE "
"YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year,"
"COUNT(*) FROM log_full"
" WHERE ClickTime>=FROM_UNIXTIME(%ld)"
" AND UsrCod=%ld%s%s"
" GROUP BY Year DESC",
(long) Report->UsrFigures.FirstClickTimeUTC,
Gbl.Usrs.Me.UsrDat.UsrCod,
SubQueryCrs,
SubQueryRol);
/***** Initialize first year *****/
Gbl.DateRange.DateIni.Date.Year = 1900 + Report->tm_FirstClickTime.tm_year;
@ -1397,10 +1403,12 @@ static void Rep_RemoveUsrReportsFiles (long UsrCod)
char PathUniqueDirReport[PATH_MAX + 1];
/***** Get directories for the reports *****/
DB_BuildQuery ("SELECT UniqueDirL,UniqueDirR FROM usr_report"
" WHERE UsrCod=%ld",
UsrCod);
NumReports = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get user's usage reports");
NumReports =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get user's usage reports",
"SELECT UniqueDirL,UniqueDirR"
" FROM usr_report"
" WHERE UsrCod=%ld",
UsrCod);
/***** Remove the reports *****/
for (NumReport = 0;