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,17 +1115,24 @@ 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 =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT FollowedCod,COUNT(FollowerCod) AS N"
" FROM usr_follow" " FROM usr_follow"
" GROUP BY FollowedCod" " GROUP BY FollowedCod"
" ORDER BY N DESC,FollowedCod LIMIT 100"); " 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 =
(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" " FROM institutions,centres,degrees,courses,crs_usr,usr_follow"
" WHERE institutions.CtyCod=%ld" " WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod" " AND institutions.InsCod=centres.InsCod"
@ -1138,7 +1145,9 @@ void Fol_GetAndShowRankingFollowers (void)
Gbl.CurrentCty.Cty.CtyCod); 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 =
(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" " FROM centres,degrees,courses,crs_usr,usr_follow"
" WHERE centres.InsCod=%ld" " WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod" " AND centres.CtrCod=degrees.CtrCod"
@ -1150,7 +1159,9 @@ void Fol_GetAndShowRankingFollowers (void)
Gbl.CurrentIns.Ins.InsCod); 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 =
(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" " FROM degrees,courses,crs_usr,usr_follow"
" WHERE degrees.CtrCod=%ld" " WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod" " AND degrees.DegCod=courses.DegCod"
@ -1161,7 +1172,9 @@ void Fol_GetAndShowRankingFollowers (void)
Gbl.CurrentCtr.Ctr.CtrCod); 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 =
(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" " FROM courses,crs_usr,usr_follow"
" WHERE courses.DegCod=%ld" " WHERE courses.DegCod=%ld"
" AND courses.CrsCod=crs_usr.CrsCod" " AND courses.CrsCod=crs_usr.CrsCod"
@ -1171,7 +1184,9 @@ void Fol_GetAndShowRankingFollowers (void)
Gbl.CurrentDeg.Deg.DegCod); 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 =
(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" " FROM crs_usr,usr_follow"
" WHERE crs_usr.CrsCod=%ld" " WHERE crs_usr.CrsCod=%ld"
" AND crs_usr.UsrCod=usr_follow.FollowedCod" " AND crs_usr.UsrCod=usr_follow.FollowedCod"
@ -1183,7 +1198,8 @@ void Fol_GetAndShowRankingFollowers (void)
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",
"(SELECT places.PlcCod,"
"places.ShortName,"
"places.FullName,"
"COUNT(*) AS NumCtrs"
" FROM places,centres" " FROM places,centres"
" WHERE places.InsCod=%ld" " WHERE places.InsCod=%ld"
" AND places.PlcCod=centres.PlcCod" " AND places.PlcCod=centres.PlcCod"
" AND centres.InsCod=%ld" " AND centres.InsCod=%ld"
" GROUP BY places.PlcCod)" " GROUP BY places.PlcCod)"
" UNION " " UNION "
"(SELECT PlcCod,ShortName,FullName,0 AS NumCtrs" "(SELECT PlcCod,"
"ShortName,"
"FullName,"
"0 AS NumCtrs"
" FROM places" " FROM places"
" WHERE InsCod=%ld" " WHERE InsCod=%ld"
" AND PlcCod NOT IN" " AND PlcCod NOT IN"
" (SELECT DISTINCT PlcCod FROM centres WHERE InsCod=%ld))" " (SELECT DISTINCT PlcCod FROM centres"
" WHERE InsCod=%ld))"
" ORDER BY %s", " ORDER BY %s",
Gbl.CurrentIns.Ins.InsCod, Gbl.CurrentIns.Ins.InsCod,
Gbl.CurrentIns.Ins.InsCod, Gbl.CurrentIns.Ins.InsCod,
Gbl.CurrentIns.Ins.InsCod, Gbl.CurrentIns.Ins.InsCod,
Gbl.CurrentIns.Ins.InsCod, Gbl.CurrentIns.Ins.InsCod,
OrderBySubQuery); OrderBySubQuery);
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get places");
/***** Count number of rows in result *****/ /***** Count number of rows in result *****/
if (NumRows) // Places found... if (NumRows) // Places found...
@ -397,14 +404,19 @@ 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",
"(SELECT places.ShortName,"
"places.FullName,"
"COUNT(*)"
" FROM places,centres" " FROM places,centres"
" WHERE places.PlcCod=%ld" " WHERE places.PlcCod=%ld"
" AND places.PlcCod=centres.PlcCod" " AND places.PlcCod=centres.PlcCod"
" AND centres.PlcCod=%ld" " AND centres.PlcCod=%ld"
" GROUP BY places.PlcCod)" " GROUP BY places.PlcCod)"
" UNION " " UNION "
"(SELECT ShortName,FullName,0" "(SELECT ShortName,"
"FullName,"
"0"
" FROM places" " FROM places"
" WHERE PlcCod=%ld" " WHERE PlcCod=%ld"
" AND PlcCod NOT IN" " AND PlcCod NOT IN"
@ -412,7 +424,6 @@ void Plc_GetDataOfPlaceByCod (struct Place *Plc)
Plc->PlcCod, Plc->PlcCod,
Plc->PlcCod, Plc->PlcCod,
Plc->PlcCod); Plc->PlcCod);
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get data of a place");
/***** 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",
"SELECT PlgCod,Name,Description,Logo,AppKey,URL,IP"
" FROM plugins ORDER BY Name"); " FROM plugins ORDER BY Name");
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get plugins");
/***** 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",
"SELECT Name,Description,Logo,AppKey,URL,IP"
" FROM plugins" " FROM plugins"
" WHERE PlgCod=%ld", " WHERE PlgCod=%ld",
Plg->PlgCod); Plg->PlgCod);
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get data of a plugin");
/***** 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",
"SELECT FirstDayOfWeek,DateFormat,Theme,IconSet,Menu,SideCols"
" FROM IP_prefs WHERE IP='%s'", " FROM IP_prefs WHERE IP='%s'",
Gbl.IP); Gbl.IP);
if ((NumRows = DB_QuerySELECT_new (&mysql_res,"can not get preferences"))) 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",
"SELECT UNIX_TIMESTAMP(FirstClickTime),"
"DATEDIFF(NOW(),FirstClickTime)+1," "DATEDIFF(NOW(),FirstClickTime)+1,"
"NumClicks,NumFileViews,NumForPst,NumMsgSnt" "NumClicks,NumFileViews,NumForPst,NumMsgSnt"
" FROM usr_figures WHERE UsrCod=%ld", " FROM usr_figures WHERE UsrCod=%ld",
UsrCod); UsrCod);
if ((NumRows = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get user's figures"))) 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"
" WHERE UsrCod=%ld)"
")", ")",
UsrCod); UsrCod))
if (DB_QuerySELECT_new (&mysql_res,"can not get user's first click"))
{ {
/* Get first click */ /* Get first click */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1154,11 +1156,16 @@ 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 =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT UsrCod,%s"
" FROM usr_figures" " FROM usr_figures"
" WHERE %s>=0" " WHERE %s>=0"
" AND UsrCod NOT IN (SELECT UsrCod FROM usr_banned)" " AND UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
@ -1167,7 +1174,9 @@ static void Prf_GetAndShowRankingFigure (const char *FieldName)
FieldName,FieldName); FieldName,FieldName);
break; break;
case Sco_SCOPE_CTY: case Sco_SCOPE_CTY:
DB_BuildQuery ("SELECT DISTINCTROW usr_figures.UsrCod,usr_figures.%s" 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" " FROM institutions,centres,degrees,courses,crs_usr,usr_figures"
" WHERE institutions.CtyCod=%ld" " WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod" " AND institutions.InsCod=centres.InsCod"
@ -1183,7 +1192,9 @@ static void Prf_GetAndShowRankingFigure (const char *FieldName)
FieldName,FieldName); FieldName,FieldName);
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
DB_BuildQuery ("SELECT DISTINCTROW usr_figures.UsrCod,usr_figures.%s" 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" " FROM centres,degrees,courses,crs_usr,usr_figures"
" WHERE centres.InsCod=%ld" " WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod" " AND centres.CtrCod=degrees.CtrCod"
@ -1198,7 +1209,9 @@ static void Prf_GetAndShowRankingFigure (const char *FieldName)
FieldName,FieldName); FieldName,FieldName);
break; break;
case Sco_SCOPE_CTR: case Sco_SCOPE_CTR:
DB_BuildQuery ("SELECT DISTINCTROW usr_figures.UsrCod,usr_figures.%s" 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" " FROM degrees,courses,crs_usr,usr_figures"
" WHERE degrees.CtrCod=%ld" " WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod" " AND degrees.DegCod=courses.DegCod"
@ -1212,7 +1225,9 @@ static void Prf_GetAndShowRankingFigure (const char *FieldName)
FieldName,FieldName); FieldName,FieldName);
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
DB_BuildQuery ("SELECT DISTINCTROW usr_figures.UsrCod,usr_figures.%s" NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT DISTINCTROW usr_figures.UsrCod,usr_figures.%s"
" FROM courses,crs_usr,usr_figures" " FROM courses,crs_usr,usr_figures"
" WHERE courses.DegCod=%ld" " WHERE courses.DegCod=%ld"
" AND courses.CrsCod=crs_usr.CrsCod" " AND courses.CrsCod=crs_usr.CrsCod"
@ -1225,7 +1240,9 @@ static void Prf_GetAndShowRankingFigure (const char *FieldName)
FieldName,FieldName); FieldName,FieldName);
break; break;
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
DB_BuildQuery ("SELECT DISTINCTROW usr_figures.UsrCod,usr_figures.%s" NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT DISTINCTROW usr_figures.UsrCod,usr_figures.%s"
" FROM crs_usr,usr_figures" " FROM crs_usr,usr_figures"
" WHERE crs_usr.CrsCod=%ld" " WHERE crs_usr.CrsCod=%ld"
" AND crs_usr.UsrCod=usr_figures.UsrCod" " AND crs_usr.UsrCod=usr_figures.UsrCod"
@ -1240,21 +1257,19 @@ static void Prf_GetAndShowRankingFigure (const char *FieldName)
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,7 +1339,9 @@ 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 =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT UsrCod,"
"NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1) AS NumClicksPerDay" "NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1) AS NumClicksPerDay"
" FROM usr_figures" " FROM usr_figures"
" WHERE NumClicks>0" " WHERE NumClicks>0"
@ -1333,7 +1350,9 @@ void Prf_GetAndShowRankingClicksPerDay (void)
" ORDER BY NumClicksPerDay DESC,UsrCod LIMIT 100"); " 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 =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT DISTINCTROW usr_figures.UsrCod,"
"usr_figures.NumClicks/(DATEDIFF(NOW()," "usr_figures.NumClicks/(DATEDIFF(NOW(),"
"usr_figures.FirstClickTime)+1) AS NumClicksPerDay" "usr_figures.FirstClickTime)+1) AS NumClicksPerDay"
" FROM institutions,centres,degrees,courses,crs_usr,usr_figures" " FROM institutions,centres,degrees,courses,crs_usr,usr_figures"
@ -1350,7 +1369,9 @@ void Prf_GetAndShowRankingClicksPerDay (void)
Gbl.CurrentCty.Cty.CtyCod); Gbl.CurrentCty.Cty.CtyCod);
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
DB_BuildQuery ("SELECT DISTINCTROW usr_figures.UsrCod," NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT DISTINCTROW usr_figures.UsrCod,"
"usr_figures.NumClicks/(DATEDIFF(NOW()," "usr_figures.NumClicks/(DATEDIFF(NOW(),"
"usr_figures.FirstClickTime)+1) AS NumClicksPerDay" "usr_figures.FirstClickTime)+1) AS NumClicksPerDay"
" FROM centres,degrees,courses,crs_usr,usr_figures" " FROM centres,degrees,courses,crs_usr,usr_figures"
@ -1366,7 +1387,9 @@ void Prf_GetAndShowRankingClicksPerDay (void)
Gbl.CurrentIns.Ins.InsCod); Gbl.CurrentIns.Ins.InsCod);
break; break;
case Sco_SCOPE_CTR: case Sco_SCOPE_CTR:
DB_BuildQuery ("SELECT DISTINCTROW usr_figures.UsrCod," NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT DISTINCTROW usr_figures.UsrCod,"
"usr_figures.NumClicks/(DATEDIFF(NOW()," "usr_figures.NumClicks/(DATEDIFF(NOW(),"
"usr_figures.FirstClickTime)+1) AS NumClicksPerDay" "usr_figures.FirstClickTime)+1) AS NumClicksPerDay"
" FROM degrees,courses,crs_usr,usr_figures" " FROM degrees,courses,crs_usr,usr_figures"
@ -1381,7 +1404,9 @@ void Prf_GetAndShowRankingClicksPerDay (void)
Gbl.CurrentCtr.Ctr.CtrCod); Gbl.CurrentCtr.Ctr.CtrCod);
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
DB_BuildQuery ("SELECT DISTINCTROW usr_figures.UsrCod," NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT DISTINCTROW usr_figures.UsrCod,"
"usr_figures.NumClicks/(DATEDIFF(NOW()," "usr_figures.NumClicks/(DATEDIFF(NOW(),"
"usr_figures.FirstClickTime)+1) AS NumClicksPerDay" "usr_figures.FirstClickTime)+1) AS NumClicksPerDay"
" FROM courses,crs_usr,usr_figures" " FROM courses,crs_usr,usr_figures"
@ -1395,7 +1420,9 @@ void Prf_GetAndShowRankingClicksPerDay (void)
Gbl.CurrentDeg.Deg.DegCod); Gbl.CurrentDeg.Deg.DegCod);
break; break;
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
DB_BuildQuery ("SELECT DISTINCTROW usr_figures.UsrCod," NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT DISTINCTROW usr_figures.UsrCod,"
"usr_figures.NumClicks/(DATEDIFF(NOW()," "usr_figures.NumClicks/(DATEDIFF(NOW(),"
"usr_figures.FirstClickTime)+1) AS NumClicksPerDay" "usr_figures.FirstClickTime)+1) AS NumClicksPerDay"
" FROM crs_usr,usr_figures" " FROM crs_usr,usr_figures"
@ -1411,7 +1438,7 @@ void Prf_GetAndShowRankingClicksPerDay (void)
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,7 +1799,8 @@ 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",
"SELECT prj_usr.UsrCod,"
"usr_data.Surname1 AS S1," "usr_data.Surname1 AS S1,"
"usr_data.Surname2 AS S2," "usr_data.Surname2 AS S2,"
"usr_data.FirstName AS FN" "usr_data.FirstName AS FN"
@ -1809,8 +1809,6 @@ static unsigned Prj_GetUsrsInPrj (long PrjCod,Prj_RoleInProject_t RoleInProject,
" AND prj_usr.UsrCod=usr_data.UsrCod" " AND prj_usr.UsrCod=usr_data.UsrCod"
" ORDER BY S1,S2,FN", " ORDER BY S1,S2,FN",
PrjCod,(unsigned) RoleInProject); PrjCod,(unsigned) RoleInProject);
return (unsigned) DB_QuerySELECT_new (mysql_res,
"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",
"SELECT RoleInProject FROM prj_usr"
" WHERE PrjCod=%ld AND UsrCod=%ld", " WHERE PrjCod=%ld AND UsrCod=%ld",
PrjCod,Gbl.Usrs.Me.UsrDat.UsrCod); PrjCod,Gbl.Usrs.Me.UsrDat.UsrCod))
if (DB_QuerySELECT_new (&mysql_res,"can not get my role in project"))
{ {
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,7 +2384,8 @@ 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",
"SELECT projects.PrjCod"
" FROM projects,prj_usr" " FROM projects,prj_usr"
" WHERE projects.CrsCod=%ld" " WHERE projects.CrsCod=%ld"
"%s%s%s" "%s%s%s"
@ -2399,7 +2398,8 @@ void Prj_GetListProjects (void)
OrderBySubQuery); 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",
"SELECT projects.PrjCod"
" FROM prj_usr,projects LEFT JOIN departments" " FROM prj_usr,projects LEFT JOIN departments"
" ON projects.DptCod=departments.DptCod" " ON projects.DptCod=departments.DptCod"
" WHERE projects.CrsCod=%ld" " WHERE projects.CrsCod=%ld"
@ -2419,7 +2419,8 @@ 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",
"SELECT projects.PrjCod"
" FROM projects" " FROM projects"
" WHERE projects.CrsCod=%ld" " WHERE projects.CrsCod=%ld"
"%s%s%s" "%s%s%s"
@ -2429,7 +2430,8 @@ void Prj_GetListProjects (void)
OrderBySubQuery); 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",
"SELECT projects.PrjCod"
" FROM projects LEFT JOIN departments" " FROM projects LEFT JOIN departments"
" ON projects.DptCod=departments.DptCod" " ON projects.DptCod=departments.DptCod"
" WHERE projects.CrsCod=%ld" " WHERE projects.CrsCod=%ld"
@ -2441,8 +2443,6 @@ void Prj_GetListProjects (void)
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);
@ -2507,80 +2508,40 @@ long Prj_GetCourseOfProject (long PrjCod)
/*****************************************************************************/ /*****************************************************************************/
void Prj_GetDataOfProjectByCod (struct Project *Prj) void Prj_GetDataOfProjectByCod (struct Project *Prj)
{
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
*/
/***** Get data of project *****/
Prj_GetDataOfProject (Prj);
}
else
{
/***** Clear all project data *****/
Prj->PrjCod = -1L;
Prj_ResetProject (Prj);
}
}
/*****************************************************************************/
/**************************** Get project data *******************************/
/*****************************************************************************/
static void Prj_GetDataOfProject (struct Project *Prj)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
long NumLong; long NumLong;
Prj_Proposal_t Proposal; Prj_Proposal_t Proposal;
if (Prj->PrjCod > 0)
{
/***** Clear all project data *****/ /***** Clear all project data *****/
Prj_ResetProject (Prj); Prj_ResetProject (Prj);
/***** Get data of project from database *****/ /***** Get data of project *****/
if (DB_QuerySELECT_new (&mysql_res,"can not get project data")) // Project found... 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 */ /* Get row */
row = mysql_fetch_row (mysql_res); 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]) */ /* Get code of the project (row[0]) */
Prj->PrjCod = Str_ConvertStrCodToLongCod (row[0]); Prj->PrjCod = Str_ConvertStrCodToLongCod (row[0]);
@ -2647,6 +2608,13 @@ static void Prj_GetDataOfProject (struct Project *Prj)
/***** Free structure that stores the query result *****/ /***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res); DB_FreeMySQLResult (&mysql_res);
} }
else
{
/***** Clear all project data *****/
Prj->PrjCod = -1L;
Prj_ResetProject (Prj);
}
}
/*****************************************************************************/ /*****************************************************************************/
/************************** Clear all project data ***************************/ /************************** Clear all project data ***************************/
@ -3472,12 +3440,14 @@ 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",
"SELECT COUNT(DISTINCT CrsCod)"
" FROM projects" " FROM projects"
" WHERE CrsCod>0"); " 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",
"SELECT COUNT(DISTINCT projects.CrsCod)"
" FROM institutions,centres,degrees,courses,projects" " FROM institutions,centres,degrees,courses,projects"
" WHERE institutions.CtyCod=%ld" " WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod" " AND institutions.InsCod=centres.InsCod"
@ -3488,7 +3458,8 @@ unsigned Prj_GetNumCoursesWithProjects (Sco_Scope_t Scope)
Gbl.CurrentCty.Cty.CtyCod); 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",
"SELECT COUNT(DISTINCT projects.CrsCod)"
" FROM centres,degrees,courses,projects" " FROM centres,degrees,courses,projects"
" WHERE centres.InsCod=%ld" " WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod" " AND centres.CtrCod=degrees.CtrCod"
@ -3498,7 +3469,8 @@ unsigned Prj_GetNumCoursesWithProjects (Sco_Scope_t Scope)
Gbl.CurrentIns.Ins.InsCod); 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",
"SELECT COUNT(DISTINCT projects.CrsCod)"
" FROM degrees,courses,projects" " FROM degrees,courses,projects"
" WHERE degrees.CtrCod=%ld" " WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod" " AND degrees.DegCod=courses.DegCod"
@ -3507,7 +3479,8 @@ unsigned Prj_GetNumCoursesWithProjects (Sco_Scope_t Scope)
Gbl.CurrentCtr.Ctr.CtrCod); 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",
"SELECT COUNT(DISTINCT projects.CrsCod)"
" FROM courses,projects" " FROM courses,projects"
" WHERE courses.DegCod=%ld" " WHERE courses.DegCod=%ld"
" AND courses.Status=0" " AND courses.Status=0"
@ -3515,7 +3488,8 @@ unsigned Prj_GetNumCoursesWithProjects (Sco_Scope_t Scope)
Gbl.CurrentDeg.Deg.DegCod); 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",
"SELECT COUNT(DISTINCT CrsCod)"
" FROM projects" " FROM projects"
" WHERE CrsCod=%ld", " WHERE CrsCod=%ld",
Gbl.CurrentCrs.Crs.CrsCod); Gbl.CurrentCrs.Crs.CrsCod);
@ -3524,7 +3498,6 @@ unsigned Prj_GetNumCoursesWithProjects (Sco_Scope_t Scope)
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,12 +3525,14 @@ 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",
"SELECT COUNT(*)"
" FROM projects" " FROM projects"
" WHERE CrsCod>0"); " 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",
"SELECT COUNT(*)"
" FROM institutions,centres,degrees,courses,projects" " FROM institutions,centres,degrees,courses,projects"
" WHERE institutions.CtyCod=%ld" " WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod" " AND institutions.InsCod=centres.InsCod"
@ -3567,7 +3542,8 @@ unsigned Prj_GetNumProjects (Sco_Scope_t Scope)
Gbl.CurrentCty.Cty.CtyCod); 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",
"SELECT COUNT(*)"
" FROM centres,degrees,courses,projects" " FROM centres,degrees,courses,projects"
" WHERE centres.InsCod=%ld" " WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod" " AND centres.CtrCod=degrees.CtrCod"
@ -3576,7 +3552,8 @@ unsigned Prj_GetNumProjects (Sco_Scope_t Scope)
Gbl.CurrentIns.Ins.InsCod); 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",
"SELECT COUNT(*)"
" FROM degrees,courses,projects" " FROM degrees,courses,projects"
" WHERE degrees.CtrCod=%ld" " WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod" " AND degrees.DegCod=courses.DegCod"
@ -3584,14 +3561,16 @@ unsigned Prj_GetNumProjects (Sco_Scope_t Scope)
Gbl.CurrentCtr.Ctr.CtrCod); 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",
"SELECT COUNT(*)"
" FROM courses,projects" " FROM courses,projects"
" WHERE courses.DegCod=%ld" " WHERE courses.DegCod=%ld"
" AND courses.CrsCod=projects.CrsCod", " AND courses.CrsCod=projects.CrsCod",
Gbl.CurrentDeg.Deg.DegCod); 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",
"SELECT COUNT(*)"
" FROM projects" " FROM projects"
" WHERE CrsCod=%ld", " WHERE CrsCod=%ld",
Gbl.CurrentCrs.Crs.CrsCod); Gbl.CurrentCrs.Crs.CrsCod);
@ -3600,7 +3579,6 @@ unsigned Prj_GetNumProjects (Sco_Scope_t Scope)
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 =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get fields of records"
" in a course",
"SELECT FieldCod,FieldName,NumLines,Visibility"
" FROM crs_record_fields" " FROM crs_record_fields"
" WHERE CrsCod=%ld ORDER BY FieldName", " WHERE CrsCod=%ld ORDER BY FieldName",
Gbl.CurrentCrs.Crs.CrsCod); 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 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"
" in a course",
"SELECT FieldCod,FieldName,Visibility"
" FROM crs_record_fields" " FROM crs_record_fields"
" WHERE CrsCod=%ld ORDER BY FieldName", " WHERE CrsCod=%ld ORDER BY FieldName",
Gbl.CurrentCrs.Crs.CrsCod); Gbl.CurrentCrs.Crs.CrsCod);
return DB_QuerySELECT_new (mysql_res,
"can not get fields of cards of a course");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -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"
" in a course",
"SELECT FieldName,NumLines,Visibility"
" FROM crs_record_fields"
" WHERE CrsCod=%ld AND FieldCod=%ld", " WHERE CrsCod=%ld AND FieldCod=%ld",
Gbl.CurrentCrs.Crs.CrsCod,FieldCod); Gbl.CurrentCrs.Crs.CrsCod,FieldCod);
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get a field of a record in a course");
/***** 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"
" of a field of a record",
"SELECT Txt FROM crs_records"
" WHERE FieldCod=%ld AND UsrCod=%ld", " WHERE FieldCod=%ld AND UsrCod=%ld",
FieldCod,UsrCod); FieldCod,UsrCod);
return DB_QuerySELECT_new (mysql_res,"can not get the text of a field of a record.");
} }
/*****************************************************************************/ /*****************************************************************************/

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"
" FROM log_full"
" WHERE ClickTime>=FROM_UNIXTIME(%ld)"
" AND UsrCod=%ld"
" GROUP BY ActCod ORDER BY N DESC LIMIT %u", " GROUP BY ActCod ORDER BY N DESC LIMIT %u",
(long) Report->UsrFigures.FirstClickTimeUTC, (long) Report->UsrFigures.FirstClickTimeUTC,
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
Rep_MAX_ACTIONS); Rep_MAX_ACTIONS);
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get clicks");
/***** 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,8 +931,9 @@ 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 ("
// Clicks without course selected --------------------------
"SELECT " "SELECT "
"-1 AS CrsCod," "-1 AS CrsCod,"
"YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year," "YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year,"
@ -941,7 +944,7 @@ static void Rep_GetMaxHitsPerYear (struct Rep_Report *Report)
" AND UsrCod=%ld" " AND UsrCod=%ld"
" AND CrsCod<=0" " AND CrsCod<=0"
" GROUP BY Year" " GROUP BY Year"
// ---------------------------------------------------------- // ---------------------------------------------------------
" UNION " " UNION "
// Clicks as student, non-editing teacher or teacher in courses // Clicks as student, non-editing teacher or teacher in courses
"SELECT " "SELECT "
@ -956,7 +959,7 @@ static void Rep_GetMaxHitsPerYear (struct Rep_Report *Report)
" AND Role<=%u" // Teacher " AND Role<=%u" // Teacher
" AND CrsCod>0" " AND CrsCod>0"
" GROUP BY CrsCod,Year,Role" " GROUP BY CrsCod,Year,Role"
// ---------------------------------------------------------- // ---------------------------------------------------------
") AS hits_per_crs_year", ") AS hits_per_crs_year",
(unsigned) Rol_UNK, (unsigned) Rol_UNK,
(long) Report->UsrFigures.FirstClickTimeUTC, (long) Report->UsrFigures.FirstClickTimeUTC,
@ -965,7 +968,6 @@ static void Rep_GetMaxHitsPerYear (struct Rep_Report *Report)
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Rol_STD, (unsigned) Rol_STD,
(unsigned) Rol_TCH); (unsigned) Rol_TCH);
DB_QuerySELECT_new (&mysql_res,"can not get last question index");
/***** Get number of users *****/ /***** Get number of users *****/
Report->MaxHitsPerYear = 0; Report->MaxHitsPerYear = 0;
@ -1015,7 +1017,9 @@ 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 =
(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" " FROM crs_usr LEFT JOIN log_full ON"
" (crs_usr.CrsCod=log_full.CrsCod" " (crs_usr.CrsCod=log_full.CrsCod"
" AND crs_usr.UsrCod=log_full.UsrCod" " AND crs_usr.UsrCod=log_full.UsrCod"
@ -1027,7 +1031,7 @@ static void Rep_GetAndWriteMyCurrentCrss (Rol_Role_t Role,
Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) Role); 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,7 +1103,9 @@ 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 =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get courses of a user",
"SELECT CrsCod,COUNT(*) AS N"
" FROM log_full" " FROM log_full"
" WHERE UsrCod=%ld AND Role=%u AND CrsCod>0" " WHERE UsrCod=%ld AND Role=%u AND CrsCod>0"
" GROUP BY CrsCod" " GROUP BY CrsCod"
@ -1109,7 +1115,7 @@ static void Rep_GetAndWriteMyHistoricCrss (Rol_Role_t Role,
Rep_MIN_CLICKS_CRS); 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,7 +1241,8 @@ 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",
"SELECT SQL_NO_CACHE "
"YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year," "YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year,"
"COUNT(*) FROM log_full" "COUNT(*) FROM log_full"
" WHERE ClickTime>=FROM_UNIXTIME(%ld)" " WHERE ClickTime>=FROM_UNIXTIME(%ld)"
@ -1245,7 +1252,6 @@ static void Rep_ShowMyHitsPerYear (bool AnyCourse,long CrsCod,Rol_Role_t Role,
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
SubQueryCrs, SubQueryCrs,
SubQueryRol); SubQueryRol);
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get clicks");
/***** 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 =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get user's usage reports",
"SELECT UniqueDirL,UniqueDirR"
" FROM usr_report"
" WHERE UsrCod=%ld", " WHERE UsrCod=%ld",
UsrCod); UsrCod);
NumReports = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get user's usage reports");
/***** Remove the reports *****/ /***** Remove the reports *****/
for (NumReport = 0; for (NumReport = 0;