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 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 CSS_FILE "swad18.4.css"
#define JS_FILE "swad17.17.1.js" #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.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)
Version 18.11.10: Nov 01, 2018 Joining building and performing query into one function. (235861 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) void Fol_GetAndShowRankingFollowers (void)
{ {
MYSQL_RES *mysql_res;
unsigned NumUsrs = 0; // Initialized to avoid warning
/***** Get ranking from database *****/ /***** Get ranking from database *****/
switch (Gbl.Scope.Current) switch (Gbl.Scope.Current)
{ {
case Sco_SCOPE_SYS: case Sco_SCOPE_SYS:
DB_BuildQuery ("SELECT FollowedCod,COUNT(FollowerCod) AS N" NumUsrs =
" FROM usr_follow" (unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
" GROUP BY FollowedCod" "SELECT FollowedCod,COUNT(FollowerCod) AS N"
" ORDER BY N DESC,FollowedCod LIMIT 100"); " FROM usr_follow"
" GROUP BY FollowedCod"
" ORDER BY N DESC,FollowedCod LIMIT 100");
break; break;
case Sco_SCOPE_CTY: case Sco_SCOPE_CTY:
DB_BuildQuery ("SELECT usr_follow.FollowedCod,COUNT(DISTINCT usr_follow.FollowerCod) AS N" NumUsrs =
" FROM institutions,centres,degrees,courses,crs_usr,usr_follow" (unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
" WHERE institutions.CtyCod=%ld" "SELECT usr_follow.FollowedCod,COUNT(DISTINCT usr_follow.FollowerCod) AS N"
" AND institutions.InsCod=centres.InsCod" " FROM institutions,centres,degrees,courses,crs_usr,usr_follow"
" AND centres.CtrCod=degrees.CtrCod" " WHERE institutions.CtyCod=%ld"
" AND degrees.DegCod=courses.DegCod" " AND institutions.InsCod=centres.InsCod"
" AND courses.CrsCod=crs_usr.CrsCod" " AND centres.CtrCod=degrees.CtrCod"
" AND crs_usr.UsrCod=usr_follow.FollowedCod" " AND degrees.DegCod=courses.DegCod"
" GROUP BY usr_follow.FollowedCod" " AND courses.CrsCod=crs_usr.CrsCod"
" ORDER BY N DESC,usr_follow.FollowedCod LIMIT 100", " AND crs_usr.UsrCod=usr_follow.FollowedCod"
Gbl.CurrentCty.Cty.CtyCod); " GROUP BY usr_follow.FollowedCod"
" ORDER BY N DESC,usr_follow.FollowedCod LIMIT 100",
Gbl.CurrentCty.Cty.CtyCod);
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
DB_BuildQuery ("SELECT usr_follow.FollowedCod,COUNT(DISTINCT usr_follow.FollowerCod) AS N" NumUsrs =
" FROM centres,degrees,courses,crs_usr,usr_follow" (unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
" WHERE centres.InsCod=%ld" "SELECT usr_follow.FollowedCod,COUNT(DISTINCT usr_follow.FollowerCod) AS N"
" AND centres.CtrCod=degrees.CtrCod" " FROM centres,degrees,courses,crs_usr,usr_follow"
" AND degrees.DegCod=courses.DegCod" " WHERE centres.InsCod=%ld"
" AND courses.CrsCod=crs_usr.CrsCod" " AND centres.CtrCod=degrees.CtrCod"
" AND crs_usr.UsrCod=usr_follow.FollowedCod" " AND degrees.DegCod=courses.DegCod"
" GROUP BY usr_follow.FollowedCod" " AND courses.CrsCod=crs_usr.CrsCod"
" ORDER BY N DESC,usr_follow.FollowedCod LIMIT 100", " AND crs_usr.UsrCod=usr_follow.FollowedCod"
Gbl.CurrentIns.Ins.InsCod); " GROUP BY usr_follow.FollowedCod"
" ORDER BY N DESC,usr_follow.FollowedCod LIMIT 100",
Gbl.CurrentIns.Ins.InsCod);
break; break;
case Sco_SCOPE_CTR: case Sco_SCOPE_CTR:
DB_BuildQuery ("SELECT usr_follow.FollowedCod,COUNT(DISTINCT usr_follow.FollowerCod) AS N" NumUsrs =
" FROM degrees,courses,crs_usr,usr_follow" (unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
" WHERE degrees.CtrCod=%ld" "SELECT usr_follow.FollowedCod,COUNT(DISTINCT usr_follow.FollowerCod) AS N"
" AND degrees.DegCod=courses.DegCod" " FROM degrees,courses,crs_usr,usr_follow"
" AND courses.CrsCod=crs_usr.CrsCod" " WHERE degrees.CtrCod=%ld"
" AND crs_usr.UsrCod=usr_follow.FollowedCod" " AND degrees.DegCod=courses.DegCod"
" GROUP BY usr_follow.FollowedCod" " AND courses.CrsCod=crs_usr.CrsCod"
" ORDER BY N DESC,usr_follow.FollowedCod LIMIT 100", " AND crs_usr.UsrCod=usr_follow.FollowedCod"
Gbl.CurrentCtr.Ctr.CtrCod); " GROUP BY usr_follow.FollowedCod"
" ORDER BY N DESC,usr_follow.FollowedCod LIMIT 100",
Gbl.CurrentCtr.Ctr.CtrCod);
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
DB_BuildQuery ("SELECT usr_follow.FollowedCod,COUNT(DISTINCT usr_follow.FollowerCod) AS N" NumUsrs =
" FROM courses,crs_usr,usr_follow" (unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
" WHERE courses.DegCod=%ld" "SELECT usr_follow.FollowedCod,COUNT(DISTINCT usr_follow.FollowerCod) AS N"
" AND courses.CrsCod=crs_usr.CrsCod" " FROM courses,crs_usr,usr_follow"
" AND crs_usr.UsrCod=usr_follow.FollowedCod" " WHERE courses.DegCod=%ld"
" GROUP BY usr_follow.FollowedCod" " AND courses.CrsCod=crs_usr.CrsCod"
" ORDER BY N DESC,usr_follow.FollowedCod LIMIT 100", " AND crs_usr.UsrCod=usr_follow.FollowedCod"
Gbl.CurrentDeg.Deg.DegCod); " GROUP BY usr_follow.FollowedCod"
" ORDER BY N DESC,usr_follow.FollowedCod LIMIT 100",
Gbl.CurrentDeg.Deg.DegCod);
break; break;
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
DB_BuildQuery ("SELECT usr_follow.FollowedCod,COUNT(DISTINCT usr_follow.FollowerCod) AS N" NumUsrs =
" FROM crs_usr,usr_follow" (unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
" WHERE crs_usr.CrsCod=%ld" "SELECT usr_follow.FollowedCod,COUNT(DISTINCT usr_follow.FollowerCod) AS N"
" AND crs_usr.UsrCod=usr_follow.FollowedCod" " FROM crs_usr,usr_follow"
" GROUP BY usr_follow.FollowedCod" " WHERE crs_usr.CrsCod=%ld"
" ORDER BY N DESC,usr_follow.FollowedCod LIMIT 100", " AND crs_usr.UsrCod=usr_follow.FollowedCod"
Gbl.CurrentCrs.Crs.CrsCod); " GROUP BY usr_follow.FollowedCod"
" ORDER BY N DESC,usr_follow.FollowedCod LIMIT 100",
Gbl.CurrentCrs.Crs.CrsCod);
break; break;
default: default:
Lay_WrongScopeExit (); Lay_WrongScopeExit ();
break; break;
} }
Prf_ShowRankingFigure ();
Prf_ShowRankingFigure (&mysql_res,NumUsrs);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

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

View File

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

View File

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

View File

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

View File

@ -77,7 +77,7 @@ void Prf_GetAndShowRankingClicks (void);
void Prf_GetAndShowRankingFileViews (void); void Prf_GetAndShowRankingFileViews (void);
void Prf_GetAndShowRankingForPst (void); void Prf_GetAndShowRankingForPst (void);
void Prf_GetAndShowRankingMsgSnt (void); void Prf_GetAndShowRankingMsgSnt (void);
void Prf_ShowRankingFigure (void); void Prf_ShowRankingFigure (MYSQL_RES **mysql_res,unsigned NumUsrs);
void Prf_GetAndShowRankingClicksPerDay (void); void Prf_GetAndShowRankingClicksPerDay (void);
void Prf_ShowUsrInRanking (struct UsrData *UsrDat,unsigned Rank); 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 bool Prj_CheckIfICanEditProject (long PrjCod);
static void Prj_GetDataOfProject (struct Project *Prj);
static void Prj_ResetProject (struct Project *Prj); static void Prj_ResetProject (struct Project *Prj);
static void Prj_RequestCreatOrEditPrj (long PrjCod); static void Prj_RequestCreatOrEditPrj (long PrjCod);
@ -1800,17 +1799,16 @@ static unsigned Prj_GetUsrsInPrj (long PrjCod,Prj_RoleInProject_t RoleInProject,
MYSQL_RES **mysql_res) MYSQL_RES **mysql_res)
{ {
/***** Get users in project from database *****/ /***** Get users in project from database *****/
DB_BuildQuery ("SELECT prj_usr.UsrCod," return (unsigned) DB_QuerySELECT (mysql_res,"can not get users in project",
"usr_data.Surname1 AS S1," "SELECT prj_usr.UsrCod,"
"usr_data.Surname2 AS S2," "usr_data.Surname1 AS S1,"
"usr_data.FirstName AS FN" "usr_data.Surname2 AS S2,"
" FROM prj_usr,usr_data" "usr_data.FirstName AS FN"
" WHERE prj_usr.PrjCod=%ld AND RoleInProject=%u" " FROM prj_usr,usr_data"
" AND prj_usr.UsrCod=usr_data.UsrCod" " WHERE prj_usr.PrjCod=%ld AND RoleInProject=%u"
" ORDER BY S1,S2,FN", " AND prj_usr.UsrCod=usr_data.UsrCod"
PrjCod,(unsigned) RoleInProject); " ORDER BY S1,S2,FN",
return (unsigned) DB_QuerySELECT_new (mysql_res, PrjCod,(unsigned) RoleInProject);
"can not get users in project");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1841,10 +1839,10 @@ Prj_RoleInProject_t Prj_GetMyRoleInProject (long PrjCod)
The result of the query will have one row or none *****/ The result of the query will have one row or none *****/
Gbl.Cache.MyRoleInProject.PrjCod = PrjCod; Gbl.Cache.MyRoleInProject.PrjCod = PrjCod;
Gbl.Cache.MyRoleInProject.RoleInProject = Prj_ROLE_UNK; Gbl.Cache.MyRoleInProject.RoleInProject = Prj_ROLE_UNK;
DB_BuildQuery ("SELECT RoleInProject FROM prj_usr" if (DB_QuerySELECT (&mysql_res,"can not get my role in project",
" WHERE PrjCod=%ld AND UsrCod=%ld", "SELECT RoleInProject FROM prj_usr"
PrjCod,Gbl.Usrs.Me.UsrDat.UsrCod); " WHERE PrjCod=%ld AND UsrCod=%ld",
if (DB_QuerySELECT_new (&mysql_res,"can not get my role in project")) PrjCod,Gbl.Usrs.Me.UsrDat.UsrCod))
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
Gbl.Cache.MyRoleInProject.RoleInProject = Prj_ConvertUnsignedStrToRoleInProject (row[0]); Gbl.Cache.MyRoleInProject.RoleInProject = Prj_ConvertUnsignedStrToRoleInProject (row[0]);
@ -2288,7 +2286,7 @@ void Prj_GetListProjects (void)
char OrderBySubQuery[Prj_MAX_BYTES_SUBQUERY]; char OrderBySubQuery[Prj_MAX_BYTES_SUBQUERY];
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows; unsigned long NumRows = 0; // Initialized to avoid warning
unsigned NumPrj; unsigned NumPrj;
if (Gbl.Prjs.LstIsRead) if (Gbl.Prjs.LstIsRead)
@ -2386,31 +2384,33 @@ void Prj_GetListProjects (void)
case Prj_ORDER_START_TIME: case Prj_ORDER_START_TIME:
case Prj_ORDER_END_TIME: case Prj_ORDER_END_TIME:
case Prj_ORDER_TITLE: case Prj_ORDER_TITLE:
DB_BuildQuery ("SELECT projects.PrjCod" NumRows = DB_QuerySELECT (&mysql_res,"can not get projects",
" FROM projects,prj_usr" "SELECT projects.PrjCod"
" WHERE projects.CrsCod=%ld" " FROM projects,prj_usr"
"%s%s%s" " WHERE projects.CrsCod=%ld"
" AND projects.PrjCod=prj_usr.PrjCod" "%s%s%s"
" AND prj_usr.UsrCod=%ld" " AND projects.PrjCod=prj_usr.PrjCod"
" ORDER BY %s", " AND prj_usr.UsrCod=%ld"
Gbl.CurrentCrs.Crs.CrsCod, " ORDER BY %s",
PreNonSubQuery,HidVisSubQuery,DptCodSubQuery, Gbl.CurrentCrs.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod, PreNonSubQuery,HidVisSubQuery,DptCodSubQuery,
OrderBySubQuery); Gbl.Usrs.Me.UsrDat.UsrCod,
OrderBySubQuery);
break; break;
case Prj_ORDER_DEPARTMENT: case Prj_ORDER_DEPARTMENT:
DB_BuildQuery ("SELECT projects.PrjCod" NumRows = DB_QuerySELECT (&mysql_res,"can not get projects",
" FROM prj_usr,projects LEFT JOIN departments" "SELECT projects.PrjCod"
" ON projects.DptCod=departments.DptCod" " FROM prj_usr,projects LEFT JOIN departments"
" WHERE projects.CrsCod=%ld" " ON projects.DptCod=departments.DptCod"
"%s%s%s" " WHERE projects.CrsCod=%ld"
" AND projects.PrjCod=prj_usr.PrjCod" "%s%s%s"
" AND prj_usr.UsrCod=%ld" " AND projects.PrjCod=prj_usr.PrjCod"
" ORDER BY %s", " AND prj_usr.UsrCod=%ld"
Gbl.CurrentCrs.Crs.CrsCod, " ORDER BY %s",
PreNonSubQuery,HidVisSubQuery,DptCodSubQuery, Gbl.CurrentCrs.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod, PreNonSubQuery,HidVisSubQuery,DptCodSubQuery,
OrderBySubQuery); Gbl.Usrs.Me.UsrDat.UsrCod,
OrderBySubQuery);
break; break;
} }
else // Gbl.Prjs.My_All == Prj_ALL_PROJECTS else // Gbl.Prjs.My_All == Prj_ALL_PROJECTS
@ -2419,30 +2419,30 @@ void Prj_GetListProjects (void)
case Prj_ORDER_START_TIME: case Prj_ORDER_START_TIME:
case Prj_ORDER_END_TIME: case Prj_ORDER_END_TIME:
case Prj_ORDER_TITLE: case Prj_ORDER_TITLE:
DB_BuildQuery ("SELECT projects.PrjCod" NumRows = DB_QuerySELECT (&mysql_res,"can not get projects",
" FROM projects" "SELECT projects.PrjCod"
" WHERE projects.CrsCod=%ld" " FROM projects"
"%s%s%s" " WHERE projects.CrsCod=%ld"
" ORDER BY %s", "%s%s%s"
Gbl.CurrentCrs.Crs.CrsCod, " ORDER BY %s",
PreNonSubQuery,HidVisSubQuery,DptCodSubQuery, Gbl.CurrentCrs.Crs.CrsCod,
OrderBySubQuery); PreNonSubQuery,HidVisSubQuery,DptCodSubQuery,
OrderBySubQuery);
break; break;
case Prj_ORDER_DEPARTMENT: case Prj_ORDER_DEPARTMENT:
DB_BuildQuery ("SELECT projects.PrjCod" NumRows = DB_QuerySELECT (&mysql_res,"can not get projects",
" FROM projects LEFT JOIN departments" "SELECT projects.PrjCod"
" ON projects.DptCod=departments.DptCod" " FROM projects LEFT JOIN departments"
" WHERE projects.CrsCod=%ld" " ON projects.DptCod=departments.DptCod"
"%s%s%s" " WHERE projects.CrsCod=%ld"
" ORDER BY %s", "%s%s%s"
Gbl.CurrentCrs.Crs.CrsCod, " ORDER BY %s",
PreNonSubQuery,HidVisSubQuery,DptCodSubQuery, Gbl.CurrentCrs.Crs.CrsCod,
OrderBySubQuery); PreNonSubQuery,HidVisSubQuery,DptCodSubQuery,
OrderBySubQuery);
break; break;
} }
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get projects");
if (NumRows) // Projects found... if (NumRows) // Projects found...
{ {
Gbl.Prjs.Num = (unsigned) NumRows; Gbl.Prjs.Num = (unsigned) NumRows;
@ -2485,8 +2485,9 @@ long Prj_GetCourseOfProject (long PrjCod)
if (PrjCod > 0) if (PrjCod > 0)
{ {
/***** Get course code from database *****/ /***** Get course code from database *****/
DB_BuildQuery ("SELECT CrsCod FROM projects WHERE PrjCod=%ld",PrjCod); if (DB_QuerySELECT (&mysql_res,"can not get project course",
if (DB_QuerySELECT_new (&mysql_res,"can not get project course")) // Project found... "SELECT CrsCod FROM projects WHERE PrjCod=%ld",
PrjCod)) // Project found...
{ {
/* Get row */ /* Get row */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -2508,35 +2509,104 @@ long Prj_GetCourseOfProject (long PrjCod)
void Prj_GetDataOfProjectByCod (struct Project *Prj) void Prj_GetDataOfProjectByCod (struct Project *Prj)
{ {
MYSQL_RES *mysql_res;
MYSQL_ROW row;
long NumLong;
Prj_Proposal_t Proposal;
if (Prj->PrjCod > 0) if (Prj->PrjCod > 0)
{ {
/***** Build query *****/ /***** Clear all project data *****/
DB_BuildQuery ("SELECT PrjCod,CrsCod,DptCod,Hidden,Preassigned,NumStds,Proposal," Prj_ResetProject (Prj);
"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
*/
/***** Get data of project *****/ /***** 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 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 ***************************/ /************************** Clear all project data ***************************/
/*****************************************************************************/ /*****************************************************************************/
@ -3472,59 +3440,64 @@ unsigned Prj_GetNumCoursesWithProjects (Sco_Scope_t Scope)
switch (Scope) switch (Scope)
{ {
case Sco_SCOPE_SYS: case Sco_SCOPE_SYS:
DB_BuildQuery ("SELECT COUNT(DISTINCT CrsCod)" DB_QuerySELECT (&mysql_res,"can not get number of courses with projects",
" FROM projects" "SELECT COUNT(DISTINCT CrsCod)"
" WHERE CrsCod>0"); " FROM projects"
" WHERE CrsCod>0");
break; break;
case Sco_SCOPE_CTY: case Sco_SCOPE_CTY:
DB_BuildQuery ("SELECT COUNT(DISTINCT projects.CrsCod)" DB_QuerySELECT (&mysql_res,"can not get number of courses with projects",
" FROM institutions,centres,degrees,courses,projects" "SELECT COUNT(DISTINCT projects.CrsCod)"
" WHERE institutions.CtyCod=%ld" " FROM institutions,centres,degrees,courses,projects"
" AND institutions.InsCod=centres.InsCod" " WHERE institutions.CtyCod=%ld"
" AND centres.CtrCod=degrees.CtrCod" " AND institutions.InsCod=centres.InsCod"
" AND degrees.DegCod=courses.DegCod" " AND centres.CtrCod=degrees.CtrCod"
" AND courses.Status=0" " AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=projects.CrsCod", " AND courses.Status=0"
Gbl.CurrentCty.Cty.CtyCod); " AND courses.CrsCod=projects.CrsCod",
Gbl.CurrentCty.Cty.CtyCod);
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
DB_BuildQuery ("SELECT COUNT(DISTINCT projects.CrsCod)" DB_QuerySELECT (&mysql_res,"can not get number of courses with projects",
" FROM centres,degrees,courses,projects" "SELECT COUNT(DISTINCT projects.CrsCod)"
" WHERE centres.InsCod=%ld" " FROM centres,degrees,courses,projects"
" AND centres.CtrCod=degrees.CtrCod" " WHERE centres.InsCod=%ld"
" AND degrees.DegCod=courses.DegCod" " AND centres.CtrCod=degrees.CtrCod"
" AND courses.Status=0" " AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=projects.CrsCod", " AND courses.Status=0"
Gbl.CurrentIns.Ins.InsCod); " AND courses.CrsCod=projects.CrsCod",
Gbl.CurrentIns.Ins.InsCod);
break; break;
case Sco_SCOPE_CTR: case Sco_SCOPE_CTR:
DB_BuildQuery ("SELECT COUNT(DISTINCT projects.CrsCod)" DB_QuerySELECT (&mysql_res,"can not get number of courses with projects",
" FROM degrees,courses,projects" "SELECT COUNT(DISTINCT projects.CrsCod)"
" WHERE degrees.CtrCod=%ld" " FROM degrees,courses,projects"
" AND degrees.DegCod=courses.DegCod" " WHERE degrees.CtrCod=%ld"
" AND courses.Status=0" " AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=projects.CrsCod", " AND courses.Status=0"
Gbl.CurrentCtr.Ctr.CtrCod); " AND courses.CrsCod=projects.CrsCod",
Gbl.CurrentCtr.Ctr.CtrCod);
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
DB_BuildQuery ("SELECT COUNT(DISTINCT projects.CrsCod)" DB_QuerySELECT (&mysql_res,"can not get number of courses with projects",
" FROM courses,projects" "SELECT COUNT(DISTINCT projects.CrsCod)"
" WHERE courses.DegCod=%ld" " FROM courses,projects"
" AND courses.Status=0" " WHERE courses.DegCod=%ld"
" AND courses.CrsCod=projects.CrsCod", " AND courses.Status=0"
Gbl.CurrentDeg.Deg.DegCod); " AND courses.CrsCod=projects.CrsCod",
Gbl.CurrentDeg.Deg.DegCod);
break; break;
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
DB_BuildQuery ("SELECT COUNT(DISTINCT CrsCod)" DB_QuerySELECT (&mysql_res,"can not get number of courses with projects",
" FROM projects" "SELECT COUNT(DISTINCT CrsCod)"
" WHERE CrsCod=%ld", " FROM projects"
Gbl.CurrentCrs.Crs.CrsCod); " WHERE CrsCod=%ld",
Gbl.CurrentCrs.Crs.CrsCod);
break; break;
default: default:
Lay_WrongScopeExit (); Lay_WrongScopeExit ();
break; break;
} }
DB_QuerySELECT_new (&mysql_res,"can not get number of courses with projects");
/***** Get number of courses *****/ /***** Get number of courses *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -3552,55 +3525,60 @@ unsigned Prj_GetNumProjects (Sco_Scope_t Scope)
switch (Scope) switch (Scope)
{ {
case Sco_SCOPE_SYS: case Sco_SCOPE_SYS:
DB_BuildQuery ("SELECT COUNT(*)" DB_QuerySELECT (&mysql_res,"can not get number of projects",
" FROM projects" "SELECT COUNT(*)"
" WHERE CrsCod>0"); " FROM projects"
" WHERE CrsCod>0");
break; break;
case Sco_SCOPE_CTY: case Sco_SCOPE_CTY:
DB_BuildQuery ("SELECT COUNT(*)" DB_QuerySELECT (&mysql_res,"can not get number of projects",
" FROM institutions,centres,degrees,courses,projects" "SELECT COUNT(*)"
" WHERE institutions.CtyCod=%ld" " FROM institutions,centres,degrees,courses,projects"
" AND institutions.InsCod=centres.InsCod" " WHERE institutions.CtyCod=%ld"
" AND centres.CtrCod=degrees.CtrCod" " AND institutions.InsCod=centres.InsCod"
" AND degrees.DegCod=courses.DegCod" " AND centres.CtrCod=degrees.CtrCod"
" AND courses.CrsCod=projects.CrsCod", " AND degrees.DegCod=courses.DegCod"
Gbl.CurrentCty.Cty.CtyCod); " AND courses.CrsCod=projects.CrsCod",
Gbl.CurrentCty.Cty.CtyCod);
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
DB_BuildQuery ("SELECT COUNT(*)" DB_QuerySELECT (&mysql_res,"can not get number of projects",
" FROM centres,degrees,courses,projects" "SELECT COUNT(*)"
" WHERE centres.InsCod=%ld" " FROM centres,degrees,courses,projects"
" AND centres.CtrCod=degrees.CtrCod" " WHERE centres.InsCod=%ld"
" AND degrees.DegCod=courses.DegCod" " AND centres.CtrCod=degrees.CtrCod"
" AND courses.CrsCod=projects.CrsCod", " AND degrees.DegCod=courses.DegCod"
Gbl.CurrentIns.Ins.InsCod); " AND courses.CrsCod=projects.CrsCod",
Gbl.CurrentIns.Ins.InsCod);
break; break;
case Sco_SCOPE_CTR: case Sco_SCOPE_CTR:
DB_BuildQuery ("SELECT COUNT(*)" DB_QuerySELECT (&mysql_res,"can not get number of projects",
" FROM degrees,courses,projects" "SELECT COUNT(*)"
" WHERE degrees.CtrCod=%ld" " FROM degrees,courses,projects"
" AND degrees.DegCod=courses.DegCod" " WHERE degrees.CtrCod=%ld"
" AND courses.CrsCod=projects.CrsCod", " AND degrees.DegCod=courses.DegCod"
Gbl.CurrentCtr.Ctr.CtrCod); " AND courses.CrsCod=projects.CrsCod",
Gbl.CurrentCtr.Ctr.CtrCod);
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
DB_BuildQuery ("SELECT COUNT(*)" DB_QuerySELECT (&mysql_res,"can not get number of projects",
" FROM courses,projects" "SELECT COUNT(*)"
" WHERE courses.DegCod=%ld" " FROM courses,projects"
" AND courses.CrsCod=projects.CrsCod", " WHERE courses.DegCod=%ld"
Gbl.CurrentDeg.Deg.DegCod); " AND courses.CrsCod=projects.CrsCod",
Gbl.CurrentDeg.Deg.DegCod);
break; break;
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
DB_BuildQuery ("SELECT COUNT(*)" DB_QuerySELECT (&mysql_res,"can not get number of projects",
" FROM projects" "SELECT COUNT(*)"
" WHERE CrsCod=%ld", " FROM projects"
Gbl.CurrentCrs.Crs.CrsCod); " WHERE CrsCod=%ld",
Gbl.CurrentCrs.Crs.CrsCod);
break; break;
default: default:
Lay_WrongScopeExit (); Lay_WrongScopeExit ();
break; break;
} }
DB_QuerySELECT_new (&mysql_res,"can not get number of projects");
/***** Get number of projects *****/ /***** Get number of projects *****/
row = mysql_fetch_row (mysql_res); 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 if (++Gbl.CurrentCrs.Records.LstFields.NestedCalls > 1) // If the list is already created, don't do anything
return; return;
/***** Get fields of cards of a course from database *****/ /***** Get fields of records in a course from database *****/
DB_BuildQuery ("SELECT FieldCod,FieldName,NumLines,Visibility" Gbl.CurrentCrs.Records.LstFields.Num =
" FROM crs_record_fields" (unsigned) DB_QuerySELECT (&mysql_res,"can not get fields of records"
" WHERE CrsCod=%ld ORDER BY FieldName", " in a course",
Gbl.CurrentCrs.Crs.CrsCod); "SELECT FieldCod,FieldName,NumLines,Visibility"
Gbl.CurrentCrs.Records.LstFields.Num = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get fields of cards of a course"); " FROM crs_record_fields"
" WHERE CrsCod=%ld ORDER BY FieldName",
Gbl.CurrentCrs.Crs.CrsCod);
/***** Get the fields of records *****/ /***** Get the fields of records *****/
if (Gbl.CurrentCrs.Records.LstFields.Num) if (Gbl.CurrentCrs.Records.LstFields.Num)
@ -557,13 +559,13 @@ bool Rec_CheckIfRecordFieldIsRepeated (const char *FieldName)
unsigned long Rec_GetAllFieldsInCurrCrs (MYSQL_RES **mysql_res) unsigned long Rec_GetAllFieldsInCurrCrs (MYSQL_RES **mysql_res)
{ {
/***** Get fields of cards of current course from database *****/ /***** Get fields of records in current course from database *****/
DB_BuildQuery ("SELECT FieldCod,FieldName,Visibility" return DB_QuerySELECT (mysql_res,"can not get fields of records"
" FROM crs_record_fields" " in a course",
" WHERE CrsCod=%ld ORDER BY FieldName", "SELECT FieldCod,FieldName,Visibility"
Gbl.CurrentCrs.Crs.CrsCod); " FROM crs_record_fields"
return DB_QuerySELECT_new (mysql_res, " WHERE CrsCod=%ld ORDER BY FieldName",
"can not get fields of cards of a course"); Gbl.CurrentCrs.Crs.CrsCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -732,10 +734,12 @@ static void Rec_GetFieldByCod (long FieldCod,char Name[Rec_MAX_BYTES_NAME_FIELD
unsigned Vis; unsigned Vis;
/***** Get a field of a record in a course from database *****/ /***** Get a field of a record in a course from database *****/
DB_BuildQuery ("SELECT FieldName,NumLines,Visibility FROM crs_record_fields" NumRows = DB_QuerySELECT (&mysql_res,"can not get a field of a record"
" WHERE CrsCod=%ld AND FieldCod=%ld", " in a course",
Gbl.CurrentCrs.Crs.CrsCod,FieldCod); "SELECT FieldName,NumLines,Visibility"
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get a field of a record in a course"); " FROM crs_record_fields"
" WHERE CrsCod=%ld AND FieldCod=%ld",
Gbl.CurrentCrs.Crs.CrsCod,FieldCod);
/***** Count number of rows in result *****/ /***** Count number of rows in result *****/
if (NumRows != 1) 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) unsigned long Rec_GetFieldFromCrsRecord (long UsrCod,long FieldCod,MYSQL_RES **mysql_res)
{ {
/***** Get the text of a field of a record from database *****/ /***** Get the text of a field of a record from database *****/
DB_BuildQuery ("SELECT Txt FROM crs_records" return DB_QuerySELECT (mysql_res,"can not get the text"
" WHERE FieldCod=%ld AND UsrCod=%ld", " of a field of a record",
FieldCod,UsrCod); "SELECT Txt FROM crs_records"
return DB_QuerySELECT_new (mysql_res,"can not get the text of a field of a record."); " 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); Txt_Hits_per_action);
/***** Make the query *****/ /***** Make the query *****/
DB_BuildQuery ("SELECT SQL_NO_CACHE ActCod,COUNT(*) AS N FROM log_full" NumRows = DB_QuerySELECT (&mysql_res,"can not get clicks",
" WHERE ClickTime>=FROM_UNIXTIME(%ld) AND UsrCod=%ld" "SELECT SQL_NO_CACHE ActCod,COUNT(*) AS N"
" GROUP BY ActCod ORDER BY N DESC LIMIT %u", " FROM log_full"
(long) Report->UsrFigures.FirstClickTimeUTC, " WHERE ClickTime>=FROM_UNIXTIME(%ld)"
Gbl.Usrs.Me.UsrDat.UsrCod, " AND UsrCod=%ld"
Rep_MAX_ACTIONS); " GROUP BY ActCod ORDER BY N DESC LIMIT %u",
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get clicks"); (long) Report->UsrFigures.FirstClickTimeUTC,
Gbl.Usrs.Me.UsrDat.UsrCod,
Rep_MAX_ACTIONS);
/***** Compute maximum number of hits per action *****/ /***** Compute maximum number of hits per action *****/
Rep_ComputeMaxAndTotalHits (&Report->Hits,NumRows,mysql_res,1); 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_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
DB_BuildQuery ("SELECT MAX(N) FROM (" DB_QuerySELECT (&mysql_res,"can not get last question index",
// Clicks without course selected --------------------------- "SELECT MAX(N) FROM ("
"SELECT " // Clicks without course selected --------------------------
"-1 AS CrsCod," "SELECT "
"YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year," "-1 AS CrsCod,"
"%u AS Role," "YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year,"
"COUNT(*) AS N" "%u AS Role,"
" FROM log_full" "COUNT(*) AS N"
" WHERE ClickTime>=FROM_UNIXTIME(%ld)" " FROM log_full"
" AND UsrCod=%ld" " WHERE ClickTime>=FROM_UNIXTIME(%ld)"
" AND CrsCod<=0" " AND UsrCod=%ld"
" GROUP BY Year" " AND CrsCod<=0"
// ---------------------------------------------------------- " GROUP BY Year"
" UNION " // ---------------------------------------------------------
// Clicks as student, non-editing teacher or teacher in courses " UNION "
"SELECT " // Clicks as student, non-editing teacher or teacher in courses
"CrsCod," "SELECT "
"YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year," "CrsCod,"
"Role," "YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year,"
"COUNT(*) AS N" "Role,"
" FROM log_full" "COUNT(*) AS N"
" WHERE ClickTime>=FROM_UNIXTIME(%ld)" " FROM log_full"
" AND UsrCod=%ld" " WHERE ClickTime>=FROM_UNIXTIME(%ld)"
" AND Role>=%u" // Student " AND UsrCod=%ld"
" AND Role<=%u" // Teacher " AND Role>=%u" // Student
" AND CrsCod>0" " AND Role<=%u" // Teacher
" GROUP BY CrsCod,Year,Role" " AND CrsCod>0"
// ---------------------------------------------------------- " GROUP BY CrsCod,Year,Role"
") AS hits_per_crs_year", // ---------------------------------------------------------
(unsigned) Rol_UNK, ") AS hits_per_crs_year",
(long) Report->UsrFigures.FirstClickTimeUTC, (unsigned) Rol_UNK,
Gbl.Usrs.Me.UsrDat.UsrCod, (long) Report->UsrFigures.FirstClickTimeUTC,
(long) Report->UsrFigures.FirstClickTimeUTC, Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Usrs.Me.UsrDat.UsrCod, (long) Report->UsrFigures.FirstClickTimeUTC,
(unsigned) Rol_STD, Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Rol_TCH); (unsigned) Rol_STD,
DB_QuerySELECT_new (&mysql_res,"can not get last question index"); (unsigned) Rol_TCH);
/***** Get number of users *****/ /***** Get number of users *****/
Report->MaxHitsPerYear = 0; Report->MaxHitsPerYear = 0;
@ -1015,19 +1017,21 @@ static void Rep_GetAndWriteMyCurrentCrss (Rol_Role_t Role,
Txt_students_ABBREVIATION); Txt_students_ABBREVIATION);
/***** Get courses of a user from database *****/ /***** Get courses of a user from database *****/
DB_BuildQuery ("SELECT crs_usr.CrsCod,log_full.CrsCod,COUNT(*) AS N" NumCrss =
" FROM crs_usr LEFT JOIN log_full ON" (unsigned) DB_QuerySELECT (&mysql_res,"can not get courses of a user",
" (crs_usr.CrsCod=log_full.CrsCod" "SELECT crs_usr.CrsCod,log_full.CrsCod,COUNT(*) AS N"
" AND crs_usr.UsrCod=log_full.UsrCod" " FROM crs_usr LEFT JOIN log_full ON"
" AND crs_usr.Role=log_full.Role)" " (crs_usr.CrsCod=log_full.CrsCod"
" WHERE crs_usr.UsrCod=%ld" " AND crs_usr.UsrCod=log_full.UsrCod"
" AND crs_usr.Role=%u" " AND crs_usr.Role=log_full.Role)"
" GROUP BY crs_usr.CrsCod" " WHERE crs_usr.UsrCod=%ld"
" ORDER BY N DESC,log_full.CrsCod DESC", " AND crs_usr.Role=%u"
Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) Role); " 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) *****/ /***** 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 */ /* Heading row */
fprintf (Gbl.F.Rep,"<ol>"); fprintf (Gbl.F.Rep,"<ol>");
@ -1099,17 +1103,19 @@ static void Rep_GetAndWriteMyHistoricCrss (Rol_Role_t Role,
long CrsCod; long CrsCod;
/***** Get historic courses of a user from log *****/ /***** Get historic courses of a user from log *****/
DB_BuildQuery ("SELECT CrsCod,COUNT(*) AS N" NumCrss =
" FROM log_full" (unsigned) DB_QuerySELECT (&mysql_res,"can not get courses of a user",
" WHERE UsrCod=%ld AND Role=%u AND CrsCod>0" "SELECT CrsCod,COUNT(*) AS N"
" GROUP BY CrsCod" " FROM log_full"
" HAVING N>%u" " WHERE UsrCod=%ld AND Role=%u AND CrsCod>0"
" ORDER BY N DESC", " GROUP BY CrsCod"
Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) Role, " HAVING N>%u"
Rep_MIN_CLICKS_CRS); " ORDER BY N DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) Role,
Rep_MIN_CLICKS_CRS);
/***** List the courses (one row per course) *****/ /***** 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 */ /* Heading row */
snprintf (Gbl.Title,sizeof (Gbl.Title), snprintf (Gbl.Title,sizeof (Gbl.Title),
@ -1235,17 +1241,17 @@ static void Rep_ShowMyHitsPerYear (bool AnyCourse,long CrsCod,Rol_Role_t Role,
else else
sprintf (SubQueryRol," AND Role=%u",(unsigned) Role); sprintf (SubQueryRol," AND Role=%u",(unsigned) Role);
DB_BuildQuery ("SELECT SQL_NO_CACHE " NumRows = DB_QuerySELECT (&mysql_res,"can not get clicks",
"YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year," "SELECT SQL_NO_CACHE "
"COUNT(*) FROM log_full" "YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year,"
" WHERE ClickTime>=FROM_UNIXTIME(%ld)" "COUNT(*) FROM log_full"
" AND UsrCod=%ld%s%s" " WHERE ClickTime>=FROM_UNIXTIME(%ld)"
" GROUP BY Year DESC", " AND UsrCod=%ld%s%s"
(long) Report->UsrFigures.FirstClickTimeUTC, " GROUP BY Year DESC",
Gbl.Usrs.Me.UsrDat.UsrCod, (long) Report->UsrFigures.FirstClickTimeUTC,
SubQueryCrs, Gbl.Usrs.Me.UsrDat.UsrCod,
SubQueryRol); SubQueryCrs,
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get clicks"); SubQueryRol);
/***** Initialize first year *****/ /***** Initialize first year *****/
Gbl.DateRange.DateIni.Date.Year = 1900 + Report->tm_FirstClickTime.tm_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]; char PathUniqueDirReport[PATH_MAX + 1];
/***** Get directories for the reports *****/ /***** Get directories for the reports *****/
DB_BuildQuery ("SELECT UniqueDirL,UniqueDirR FROM usr_report" NumReports =
" WHERE UsrCod=%ld", (unsigned) DB_QuerySELECT (&mysql_res,"can not get user's usage reports",
UsrCod); "SELECT UniqueDirL,UniqueDirR"
NumReports = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get user's usage reports"); " FROM usr_report"
" WHERE UsrCod=%ld",
UsrCod);
/***** Remove the reports *****/ /***** Remove the reports *****/
for (NumReport = 0; for (NumReport = 0;