mirror of https://github.com/acanas/swad-core.git
Version 18.11.2
This commit is contained in:
parent
c1559c1d52
commit
adb9c1020d
|
@ -355,10 +355,11 @@ En OpenSWAD:
|
|||
ps2pdf source.ps destination.pdf
|
||||
*/
|
||||
|
||||
#define Log_PLATFORM_VERSION "SWAD 18.11.1 (2018-10-30)"
|
||||
#define Log_PLATFORM_VERSION "SWAD 18.11.2 (2018-10-30)"
|
||||
#define CSS_FILE "swad18.4.css"
|
||||
#define JS_FILE "swad17.17.1.js"
|
||||
/*
|
||||
Version 18.11.2: Oct 30, 2018 Joining building and performing query into one function. (235531 lines)
|
||||
Version 18.11.1: Oct 30, 2018 Joining building and performing query into one function. (235497 lines)
|
||||
Version 18.11: Oct 30, 2018 Joining building and performing query into one function. (235465 lines)
|
||||
Version 18.10.2: Oct 30, 2018 Fixed bugs in access to database. (235414 lines)
|
||||
|
|
351
swad_connected.c
351
swad_connected.c
|
@ -194,8 +194,8 @@ void Con_GetAndShowLastClicks (void)
|
|||
extern const char *Txt_ROLES_SINGUL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
unsigned NumRow;
|
||||
unsigned NumRows;
|
||||
unsigned long NumRow;
|
||||
unsigned long NumRows;
|
||||
long ActCod;
|
||||
const char *ClassRow;
|
||||
time_t TimeDiff;
|
||||
|
@ -207,20 +207,20 @@ void Con_GetAndShowLastClicks (void)
|
|||
/***** Get last clicks from database *****/
|
||||
/* Important for maximum performance:
|
||||
do the LIMIT in the big log table before the JOIN */
|
||||
DB_BuildQuery ("SELECT last_logs.LogCod,last_logs.ActCod,"
|
||||
"last_logs.Dif,last_logs.Role,"
|
||||
"last_logs.CtyCod,last_logs.InsCod,"
|
||||
"last_logs.CtrCod,last_logs.DegCod,"
|
||||
"actions.Txt"
|
||||
" FROM"
|
||||
" (SELECT LogCod,ActCod,"
|
||||
"UNIX_TIMESTAMP()-UNIX_TIMESTAMP(ClickTime) AS Dif,"
|
||||
"Role,CtyCod,InsCod,CtrCod,DegCod"
|
||||
" FROM log_recent ORDER BY LogCod DESC LIMIT 20)"
|
||||
" AS last_logs,actions"
|
||||
" WHERE last_logs.ActCod=actions.ActCod"
|
||||
" AND actions.Language='es'");
|
||||
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get last clicks");
|
||||
NumRows = DB_QuerySELECT (&mysql_res,"can not get last clicks",
|
||||
"SELECT last_logs.LogCod,last_logs.ActCod,"
|
||||
"last_logs.Dif,last_logs.Role,"
|
||||
"last_logs.CtyCod,last_logs.InsCod,"
|
||||
"last_logs.CtrCod,last_logs.DegCod,"
|
||||
"actions.Txt"
|
||||
" FROM"
|
||||
" (SELECT LogCod,ActCod,"
|
||||
"UNIX_TIMESTAMP()-UNIX_TIMESTAMP(ClickTime) AS Dif,"
|
||||
"Role,CtyCod,InsCod,CtrCod,DegCod"
|
||||
" FROM log_recent ORDER BY LogCod DESC LIMIT 20)"
|
||||
" AS last_logs,actions"
|
||||
" WHERE last_logs.ActCod=actions.ActCod"
|
||||
" AND actions.Language='es'");
|
||||
|
||||
/***** Write list of connected users *****/
|
||||
Tbl_StartTableCenter (1);
|
||||
|
@ -777,78 +777,96 @@ static void Con_GetNumConnectedUsrsWithARoleBelongingCurrentLocation (Rol_Role_t
|
|||
switch (Gbl.Scope.Current)
|
||||
{
|
||||
case Sco_SCOPE_SYS: // Show connected users in the whole platform
|
||||
DB_BuildQuery ("SELECT COUNT(DISTINCT connected.UsrCod),"
|
||||
"COUNT(DISTINCT usr_data.Sex),MIN(usr_data.Sex)"
|
||||
" FROM connected,crs_usr,usr_data"
|
||||
" WHERE connected.UsrCod=crs_usr.UsrCod"
|
||||
" AND crs_usr.Role=%u"
|
||||
" AND connected.UsrCod=usr_data.UsrCod",
|
||||
(unsigned) Role);
|
||||
DB_QuerySELECT (&mysql_res,"can not get number"
|
||||
" of connected users"
|
||||
" who belong to this location",
|
||||
"SELECT COUNT(DISTINCT connected.UsrCod),"
|
||||
"COUNT(DISTINCT usr_data.Sex),MIN(usr_data.Sex)"
|
||||
" FROM connected,crs_usr,usr_data"
|
||||
" WHERE connected.UsrCod=crs_usr.UsrCod"
|
||||
" AND crs_usr.Role=%u"
|
||||
" AND connected.UsrCod=usr_data.UsrCod",
|
||||
(unsigned) Role);
|
||||
break;
|
||||
case Sco_SCOPE_CTY: // Show connected users in the current country
|
||||
DB_BuildQuery ("SELECT COUNT(DISTINCT connected.UsrCod),"
|
||||
"COUNT(DISTINCT usr_data.Sex),MIN(usr_data.Sex)"
|
||||
" FROM institutions,centres,degrees,courses,crs_usr,connected,usr_data"
|
||||
" WHERE institutions.CtyCod=%ld"
|
||||
" AND institutions.InsCod=centres.InsCod"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=crs_usr.CrsCod"
|
||||
" AND crs_usr.Role=%u"
|
||||
" AND crs_usr.UsrCod=connected.UsrCod"
|
||||
" AND connected.UsrCod=usr_data.UsrCod",
|
||||
Gbl.CurrentCty.Cty.CtyCod,
|
||||
(unsigned) Role);
|
||||
DB_QuerySELECT (&mysql_res,"can not get number"
|
||||
" of connected users"
|
||||
" who belong to this location",
|
||||
"SELECT COUNT(DISTINCT connected.UsrCod),"
|
||||
"COUNT(DISTINCT usr_data.Sex),MIN(usr_data.Sex)"
|
||||
" FROM institutions,centres,degrees,courses,crs_usr,connected,usr_data"
|
||||
" WHERE institutions.CtyCod=%ld"
|
||||
" AND institutions.InsCod=centres.InsCod"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=crs_usr.CrsCod"
|
||||
" AND crs_usr.Role=%u"
|
||||
" AND crs_usr.UsrCod=connected.UsrCod"
|
||||
" AND connected.UsrCod=usr_data.UsrCod",
|
||||
Gbl.CurrentCty.Cty.CtyCod,
|
||||
(unsigned) Role);
|
||||
break;
|
||||
case Sco_SCOPE_INS: // Show connected users in the current institution
|
||||
DB_BuildQuery ("SELECT COUNT(DISTINCT connected.UsrCod),"
|
||||
"COUNT(DISTINCT usr_data.Sex),MIN(usr_data.Sex)"
|
||||
" FROM centres,degrees,courses,crs_usr,connected,usr_data"
|
||||
" WHERE centres.InsCod=%ld"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=crs_usr.CrsCod"
|
||||
" AND crs_usr.Role=%u"
|
||||
" AND crs_usr.UsrCod=connected.UsrCod"
|
||||
" AND connected.UsrCod=usr_data.UsrCod",
|
||||
Gbl.CurrentIns.Ins.InsCod,
|
||||
(unsigned) Role);
|
||||
DB_QuerySELECT (&mysql_res,"can not get number"
|
||||
" of connected users"
|
||||
" who belong to this location",
|
||||
"SELECT COUNT(DISTINCT connected.UsrCod),"
|
||||
"COUNT(DISTINCT usr_data.Sex),MIN(usr_data.Sex)"
|
||||
" FROM centres,degrees,courses,crs_usr,connected,usr_data"
|
||||
" WHERE centres.InsCod=%ld"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=crs_usr.CrsCod"
|
||||
" AND crs_usr.Role=%u"
|
||||
" AND crs_usr.UsrCod=connected.UsrCod"
|
||||
" AND connected.UsrCod=usr_data.UsrCod",
|
||||
Gbl.CurrentIns.Ins.InsCod,
|
||||
(unsigned) Role);
|
||||
break;
|
||||
case Sco_SCOPE_CTR: // Show connected users in the current centre
|
||||
DB_BuildQuery ("SELECT COUNT(DISTINCT connected.UsrCod),"
|
||||
"COUNT(DISTINCT usr_data.Sex),MIN(usr_data.Sex)"
|
||||
" FROM degrees,courses,crs_usr,connected,usr_data"
|
||||
" WHERE degrees.CtrCod=%ld"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=crs_usr.CrsCod"
|
||||
" AND crs_usr.Role=%u"
|
||||
" AND crs_usr.UsrCod=connected.UsrCod"
|
||||
" AND connected.UsrCod=usr_data.UsrCod",
|
||||
Gbl.CurrentCtr.Ctr.CtrCod,
|
||||
(unsigned) Role);
|
||||
DB_QuerySELECT (&mysql_res,"can not get number"
|
||||
" of connected users"
|
||||
" who belong to this location",
|
||||
"SELECT COUNT(DISTINCT connected.UsrCod),"
|
||||
"COUNT(DISTINCT usr_data.Sex),MIN(usr_data.Sex)"
|
||||
" FROM degrees,courses,crs_usr,connected,usr_data"
|
||||
" WHERE degrees.CtrCod=%ld"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=crs_usr.CrsCod"
|
||||
" AND crs_usr.Role=%u"
|
||||
" AND crs_usr.UsrCod=connected.UsrCod"
|
||||
" AND connected.UsrCod=usr_data.UsrCod",
|
||||
Gbl.CurrentCtr.Ctr.CtrCod,
|
||||
(unsigned) Role);
|
||||
break;
|
||||
case Sco_SCOPE_DEG: // Show connected users in the current degree
|
||||
DB_BuildQuery ("SELECT COUNT(DISTINCT connected.UsrCod),"
|
||||
"COUNT(DISTINCT usr_data.Sex),MIN(usr_data.Sex)"
|
||||
" FROM courses,crs_usr,connected,usr_data"
|
||||
" WHERE courses.DegCod=%ld"
|
||||
" AND courses.CrsCod=crs_usr.CrsCod"
|
||||
" AND crs_usr.Role=%u"
|
||||
" AND crs_usr.UsrCod=connected.UsrCod"
|
||||
" AND connected.UsrCod=usr_data.UsrCod",
|
||||
Gbl.CurrentDeg.Deg.DegCod,
|
||||
(unsigned) Role);
|
||||
DB_QuerySELECT (&mysql_res,"can not get number"
|
||||
" of connected users"
|
||||
" who belong to this location",
|
||||
"SELECT COUNT(DISTINCT connected.UsrCod),"
|
||||
"COUNT(DISTINCT usr_data.Sex),MIN(usr_data.Sex)"
|
||||
" FROM courses,crs_usr,connected,usr_data"
|
||||
" WHERE courses.DegCod=%ld"
|
||||
" AND courses.CrsCod=crs_usr.CrsCod"
|
||||
" AND crs_usr.Role=%u"
|
||||
" AND crs_usr.UsrCod=connected.UsrCod"
|
||||
" AND connected.UsrCod=usr_data.UsrCod",
|
||||
Gbl.CurrentDeg.Deg.DegCod,
|
||||
(unsigned) Role);
|
||||
break;
|
||||
case Sco_SCOPE_CRS: // Show connected users in the current course
|
||||
DB_BuildQuery ("SELECT COUNT(DISTINCT connected.UsrCod),"
|
||||
"COUNT(DISTINCT usr_data.Sex),MIN(usr_data.Sex)"
|
||||
" FROM crs_usr,connected,usr_data"
|
||||
" WHERE crs_usr.CrsCod=%ld"
|
||||
" AND crs_usr.Role=%u"
|
||||
" AND crs_usr.UsrCod=connected.UsrCod"
|
||||
" AND connected.UsrCod=usr_data.UsrCod",
|
||||
Gbl.CurrentCrs.Crs.CrsCod,
|
||||
(unsigned) Role);
|
||||
DB_QuerySELECT (&mysql_res,"can not get number"
|
||||
" of connected users"
|
||||
" who belong to this location",
|
||||
"SELECT COUNT(DISTINCT connected.UsrCod),"
|
||||
"COUNT(DISTINCT usr_data.Sex),MIN(usr_data.Sex)"
|
||||
" FROM crs_usr,connected,usr_data"
|
||||
" WHERE crs_usr.CrsCod=%ld"
|
||||
" AND crs_usr.Role=%u"
|
||||
" AND crs_usr.UsrCod=connected.UsrCod"
|
||||
" AND connected.UsrCod=usr_data.UsrCod",
|
||||
Gbl.CurrentCrs.Crs.CrsCod,
|
||||
(unsigned) Role);
|
||||
break;
|
||||
default:
|
||||
Lay_WrongScopeExit ();
|
||||
|
@ -859,7 +877,6 @@ static void Con_GetNumConnectedUsrsWithARoleBelongingCurrentLocation (Rol_Role_t
|
|||
Lay_ShowErrorAndExit ("Wrong role.");
|
||||
break;
|
||||
}
|
||||
DB_QuerySELECT_new (&mysql_res,"can not get number of connected users who belong to this location");
|
||||
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
|
||||
|
@ -899,17 +916,16 @@ static void Con_ComputeConnectedUsrsWithARoleCurrentCrsOneByOne (Rol_Role_t Role
|
|||
unsigned NumUsr = Gbl.Usrs.Connected.NumUsrs; // Save current number of users
|
||||
|
||||
/***** Get connected users who belong to current course from database *****/
|
||||
DB_BuildQuery ("SELECT connected.UsrCod,connected.LastCrsCod,"
|
||||
"UNIX_TIMESTAMP()-UNIX_TIMESTAMP(connected.LastTime) AS Dif"
|
||||
" FROM connected,crs_usr"
|
||||
" WHERE crs_usr.CrsCod=%ld AND crs_usr.Role=%u"
|
||||
" AND crs_usr.UsrCod=connected.UsrCod"
|
||||
" ORDER BY Dif",
|
||||
Gbl.CurrentCrs.Crs.CrsCod,
|
||||
(unsigned) Role);
|
||||
NumRows = DB_QuerySELECT_new (&mysql_res,
|
||||
"can not get list of connected users"
|
||||
" who belong to this course");
|
||||
NumRows = DB_QuerySELECT (&mysql_res,"can not get list of connected users"
|
||||
" who belong to this course",
|
||||
"SELECT connected.UsrCod,connected.LastCrsCod,"
|
||||
"UNIX_TIMESTAMP()-UNIX_TIMESTAMP(connected.LastTime) AS Dif"
|
||||
" FROM connected,crs_usr"
|
||||
" WHERE crs_usr.CrsCod=%ld AND crs_usr.Role=%u"
|
||||
" AND crs_usr.UsrCod=connected.UsrCod"
|
||||
" ORDER BY Dif",
|
||||
Gbl.CurrentCrs.Crs.CrsCod,
|
||||
(unsigned) Role);
|
||||
Gbl.Usrs.Connected.NumUsrs += (unsigned) NumRows;
|
||||
Gbl.Usrs.Connected.NumUsrsToList += (unsigned) NumRows;
|
||||
if (Gbl.Usrs.Connected.NumUsrsToList > Cfg_MAX_CONNECTED_SHOWN)
|
||||
|
@ -1052,7 +1068,7 @@ static void Con_ShowConnectedUsrsCurrentLocationOneByOneOnMainZone (Rol_Role_t R
|
|||
{
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
unsigned NumUsrs;
|
||||
unsigned NumUsrs = 0; // Initialized to avoid warning
|
||||
unsigned NumUsr;
|
||||
bool ThisCrs;
|
||||
time_t TimeDiff;
|
||||
|
@ -1070,11 +1086,13 @@ static void Con_ShowConnectedUsrsCurrentLocationOneByOneOnMainZone (Rol_Role_t R
|
|||
switch (Role)
|
||||
{
|
||||
case Rol_GST:
|
||||
DB_BuildQuery ("SELECT UsrCod,LastCrsCod,"
|
||||
"UNIX_TIMESTAMP()-UNIX_TIMESTAMP(LastTime) AS Dif"
|
||||
" FROM connected"
|
||||
" WHERE UsrCod NOT IN (SELECT UsrCod FROM crs_usr)"
|
||||
" ORDER BY Dif");
|
||||
NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get list of connected users"
|
||||
" who belong to this location",
|
||||
"SELECT UsrCod,LastCrsCod,"
|
||||
"UNIX_TIMESTAMP()-UNIX_TIMESTAMP(LastTime) AS Dif"
|
||||
" FROM connected"
|
||||
" WHERE UsrCod NOT IN (SELECT UsrCod FROM crs_usr)"
|
||||
" ORDER BY Dif");
|
||||
break;
|
||||
case Rol_STD:
|
||||
case Rol_NET:
|
||||
|
@ -1082,78 +1100,90 @@ static void Con_ShowConnectedUsrsCurrentLocationOneByOneOnMainZone (Rol_Role_t R
|
|||
switch (Gbl.Scope.Current)
|
||||
{
|
||||
case Sco_SCOPE_SYS: // Show connected users in the whole platform
|
||||
DB_BuildQuery ("SELECT DISTINCTROW connected.UsrCod,connected.LastCrsCod,"
|
||||
"UNIX_TIMESTAMP()-UNIX_TIMESTAMP(connected.LastTime) AS Dif"
|
||||
" FROM connected,crs_usr"
|
||||
" WHERE connected.UsrCod=crs_usr.UsrCod"
|
||||
" AND crs_usr.Role=%u"
|
||||
" ORDER BY Dif",
|
||||
(unsigned) Role);
|
||||
NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get list of connected users"
|
||||
" who belong to this location",
|
||||
"SELECT DISTINCTROW connected.UsrCod,connected.LastCrsCod,"
|
||||
"UNIX_TIMESTAMP()-UNIX_TIMESTAMP(connected.LastTime) AS Dif"
|
||||
" FROM connected,crs_usr"
|
||||
" WHERE connected.UsrCod=crs_usr.UsrCod"
|
||||
" AND crs_usr.Role=%u"
|
||||
" ORDER BY Dif",
|
||||
(unsigned) Role);
|
||||
break;
|
||||
case Sco_SCOPE_CTY: // Show connected users in the current country
|
||||
DB_BuildQuery ("SELECT DISTINCTROW connected.UsrCod,connected.LastCrsCod,"
|
||||
"UNIX_TIMESTAMP()-UNIX_TIMESTAMP(connected.LastTime) AS Dif"
|
||||
" FROM institutions,centres,degrees,courses,crs_usr,connected"
|
||||
" WHERE institutions.CtyCod=%ld"
|
||||
" AND institutions.InsCod=centres.InsCod"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=crs_usr.CrsCod"
|
||||
" AND crs_usr.Role=%u"
|
||||
" AND crs_usr.UsrCod=connected.UsrCod"
|
||||
" ORDER BY Dif",
|
||||
Gbl.CurrentCty.Cty.CtyCod,
|
||||
(unsigned) Role);
|
||||
NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get list of connected users"
|
||||
" who belong to this location",
|
||||
"SELECT DISTINCTROW connected.UsrCod,connected.LastCrsCod,"
|
||||
"UNIX_TIMESTAMP()-UNIX_TIMESTAMP(connected.LastTime) AS Dif"
|
||||
" FROM institutions,centres,degrees,courses,crs_usr,connected"
|
||||
" WHERE institutions.CtyCod=%ld"
|
||||
" AND institutions.InsCod=centres.InsCod"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=crs_usr.CrsCod"
|
||||
" AND crs_usr.Role=%u"
|
||||
" AND crs_usr.UsrCod=connected.UsrCod"
|
||||
" ORDER BY Dif",
|
||||
Gbl.CurrentCty.Cty.CtyCod,
|
||||
(unsigned) Role);
|
||||
break;
|
||||
case Sco_SCOPE_INS: // Show connected users in the current institution
|
||||
DB_BuildQuery ("SELECT DISTINCTROW connected.UsrCod,connected.LastCrsCod,"
|
||||
"UNIX_TIMESTAMP()-UNIX_TIMESTAMP(connected.LastTime) AS Dif"
|
||||
" FROM centres,degrees,courses,crs_usr,connected"
|
||||
" WHERE centres.InsCod=%ld"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=crs_usr.CrsCod"
|
||||
" AND crs_usr.Role=%u"
|
||||
" AND crs_usr.UsrCod=connected.UsrCod"
|
||||
" ORDER BY Dif",
|
||||
Gbl.CurrentIns.Ins.InsCod,
|
||||
(unsigned) Role);
|
||||
NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get list of connected users"
|
||||
" who belong to this location",
|
||||
"SELECT DISTINCTROW connected.UsrCod,connected.LastCrsCod,"
|
||||
"UNIX_TIMESTAMP()-UNIX_TIMESTAMP(connected.LastTime) AS Dif"
|
||||
" FROM centres,degrees,courses,crs_usr,connected"
|
||||
" WHERE centres.InsCod=%ld"
|
||||
" AND centres.CtrCod=degrees.CtrCod"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=crs_usr.CrsCod"
|
||||
" AND crs_usr.Role=%u"
|
||||
" AND crs_usr.UsrCod=connected.UsrCod"
|
||||
" ORDER BY Dif",
|
||||
Gbl.CurrentIns.Ins.InsCod,
|
||||
(unsigned) Role);
|
||||
break;
|
||||
case Sco_SCOPE_CTR: // Show connected users in the current centre
|
||||
DB_BuildQuery ("SELECT DISTINCTROW connected.UsrCod,connected.LastCrsCod,"
|
||||
"UNIX_TIMESTAMP()-UNIX_TIMESTAMP(connected.LastTime) AS Dif"
|
||||
" FROM degrees,courses,crs_usr,connected"
|
||||
" WHERE degrees.CtrCod=%ld"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=crs_usr.CrsCod"
|
||||
" AND crs_usr.Role=%u"
|
||||
" AND crs_usr.UsrCod=connected.UsrCod"
|
||||
" ORDER BY Dif",
|
||||
Gbl.CurrentCtr.Ctr.CtrCod,
|
||||
(unsigned) Role);
|
||||
NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get list of connected users"
|
||||
" who belong to this location",
|
||||
"SELECT DISTINCTROW connected.UsrCod,connected.LastCrsCod,"
|
||||
"UNIX_TIMESTAMP()-UNIX_TIMESTAMP(connected.LastTime) AS Dif"
|
||||
" FROM degrees,courses,crs_usr,connected"
|
||||
" WHERE degrees.CtrCod=%ld"
|
||||
" AND degrees.DegCod=courses.DegCod"
|
||||
" AND courses.CrsCod=crs_usr.CrsCod"
|
||||
" AND crs_usr.Role=%u"
|
||||
" AND crs_usr.UsrCod=connected.UsrCod"
|
||||
" ORDER BY Dif",
|
||||
Gbl.CurrentCtr.Ctr.CtrCod,
|
||||
(unsigned) Role);
|
||||
break;
|
||||
case Sco_SCOPE_DEG: // Show connected users in the current degree
|
||||
DB_BuildQuery ("SELECT DISTINCTROW connected.UsrCod,connected.LastCrsCod,"
|
||||
"UNIX_TIMESTAMP()-UNIX_TIMESTAMP(connected.LastTime) AS Dif"
|
||||
" FROM courses,crs_usr,connected"
|
||||
" WHERE courses.DegCod=%ld"
|
||||
" AND courses.CrsCod=crs_usr.CrsCod"
|
||||
" AND crs_usr.Role=%u"
|
||||
" AND crs_usr.UsrCod=connected.UsrCod"
|
||||
" ORDER BY Dif",
|
||||
Gbl.CurrentDeg.Deg.DegCod,
|
||||
(unsigned) Role);
|
||||
NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get list of connected users"
|
||||
" who belong to this location",
|
||||
"SELECT DISTINCTROW connected.UsrCod,connected.LastCrsCod,"
|
||||
"UNIX_TIMESTAMP()-UNIX_TIMESTAMP(connected.LastTime) AS Dif"
|
||||
" FROM courses,crs_usr,connected"
|
||||
" WHERE courses.DegCod=%ld"
|
||||
" AND courses.CrsCod=crs_usr.CrsCod"
|
||||
" AND crs_usr.Role=%u"
|
||||
" AND crs_usr.UsrCod=connected.UsrCod"
|
||||
" ORDER BY Dif",
|
||||
Gbl.CurrentDeg.Deg.DegCod,
|
||||
(unsigned) Role);
|
||||
break;
|
||||
case Sco_SCOPE_CRS: // Show connected users in the current course
|
||||
DB_BuildQuery ("SELECT connected.UsrCod,connected.LastCrsCod,"
|
||||
"UNIX_TIMESTAMP()-UNIX_TIMESTAMP(connected.LastTime) AS Dif"
|
||||
" FROM crs_usr,connected"
|
||||
" WHERE crs_usr.CrsCod=%ld"
|
||||
" AND crs_usr.Role=%u"
|
||||
" AND crs_usr.UsrCod=connected.UsrCod"
|
||||
" ORDER BY Dif",
|
||||
Gbl.CurrentCrs.Crs.CrsCod,
|
||||
(unsigned) Role);
|
||||
NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get list of connected users"
|
||||
" who belong to this location",
|
||||
"SELECT connected.UsrCod,connected.LastCrsCod,"
|
||||
"UNIX_TIMESTAMP()-UNIX_TIMESTAMP(connected.LastTime) AS Dif"
|
||||
" FROM crs_usr,connected"
|
||||
" WHERE crs_usr.CrsCod=%ld"
|
||||
" AND crs_usr.Role=%u"
|
||||
" AND crs_usr.UsrCod=connected.UsrCod"
|
||||
" ORDER BY Dif",
|
||||
Gbl.CurrentCrs.Crs.CrsCod,
|
||||
(unsigned) Role);
|
||||
break;
|
||||
default:
|
||||
Lay_WrongScopeExit ();
|
||||
|
@ -1164,11 +1194,6 @@ static void Con_ShowConnectedUsrsCurrentLocationOneByOneOnMainZone (Rol_Role_t R
|
|||
Lay_ShowErrorAndExit ("Wrong role.");
|
||||
break;
|
||||
}
|
||||
|
||||
NumUsrs = (unsigned) DB_QuerySELECT_new (&mysql_res,
|
||||
"can not get list of connected users"
|
||||
" who belong to this location");
|
||||
|
||||
if (NumUsrs)
|
||||
{
|
||||
/***** Initialize structure with user's data *****/
|
||||
|
|
145
swad_country.c
145
swad_country.c
|
@ -122,23 +122,23 @@ void Cty_SeeCtyWithPendingInss (void)
|
|||
switch (Gbl.Usrs.Me.Role.Logged)
|
||||
{
|
||||
case Rol_SYS_ADM:
|
||||
DB_BuildQuery ("SELECT institutions.CtyCod,COUNT(*)"
|
||||
" FROM institutions,countries"
|
||||
" WHERE (institutions.Status & %u)<>0"
|
||||
" AND institutions.CtyCod=countries.CtyCod"
|
||||
" GROUP BY institutions.CtyCod"
|
||||
" ORDER BY countries.Name_%s",
|
||||
(unsigned) Ins_STATUS_BIT_PENDING,
|
||||
Txt_STR_LANG_ID[Gbl.Prefs.Language]);
|
||||
NumCtys = (unsigned) DB_QuerySELECT (&mysql_res,"can not get countries"
|
||||
"with pending institutions",
|
||||
"SELECT institutions.CtyCod,COUNT(*)"
|
||||
" FROM institutions,countries"
|
||||
" WHERE (institutions.Status & %u)<>0"
|
||||
" AND institutions.CtyCod=countries.CtyCod"
|
||||
" GROUP BY institutions.CtyCod"
|
||||
" ORDER BY countries.Name_%s",
|
||||
(unsigned) Ins_STATUS_BIT_PENDING,
|
||||
Txt_STR_LANG_ID[Gbl.Prefs.Language]);
|
||||
break;
|
||||
default: // Forbidden for other users
|
||||
return;
|
||||
}
|
||||
|
||||
/***** Get countries *****/
|
||||
if ((NumCtys = (unsigned) DB_QuerySELECT_new (&mysql_res,
|
||||
"can not get countries"
|
||||
"with pending institutions")))
|
||||
if (NumCtys)
|
||||
{
|
||||
/***** Start box and table *****/
|
||||
Box_StartBoxTable (NULL,Txt_Countries_with_pending_institutions,NULL,
|
||||
|
@ -993,10 +993,10 @@ void Cty_GetListCountries (Cty_GetExtraData_t GetExtraData)
|
|||
char SubQueryNam2[Cty_MAX_BYTES_SUBQUERY_CTYS + 1];
|
||||
char SubQueryWWW1[Cty_MAX_BYTES_SUBQUERY_CTYS + 1];
|
||||
char SubQueryWWW2[Cty_MAX_BYTES_SUBQUERY_CTYS + 1];
|
||||
char *OrderBySubQuery;
|
||||
char *OrderBySubQuery = NULL;
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
unsigned long NumRows;
|
||||
unsigned long NumRows = 0;
|
||||
unsigned NumCty;
|
||||
struct Country *Cty;
|
||||
Txt_Language_t Lan;
|
||||
|
@ -1005,11 +1005,11 @@ void Cty_GetListCountries (Cty_GetExtraData_t GetExtraData)
|
|||
switch (GetExtraData)
|
||||
{
|
||||
case Cty_GET_BASIC_DATA:
|
||||
DB_BuildQuery ("SELECT CtyCod,Alpha2,Name_%s"
|
||||
" FROM countries ORDER BY Name_%s",
|
||||
Txt_STR_LANG_ID[Gbl.Prefs.Language],
|
||||
Txt_STR_LANG_ID[Gbl.Prefs.Language]);
|
||||
OrderBySubQuery = NULL;
|
||||
NumRows = DB_QuerySELECT (&mysql_res,"can not get countries",
|
||||
"SELECT CtyCod,Alpha2,Name_%s"
|
||||
" FROM countries ORDER BY Name_%s",
|
||||
Txt_STR_LANG_ID[Gbl.Prefs.Language],
|
||||
Txt_STR_LANG_ID[Gbl.Prefs.Language]);
|
||||
break;
|
||||
case Cty_GET_EXTRA_DATA:
|
||||
SubQueryNam1[0] = '\0';
|
||||
|
@ -1056,24 +1056,24 @@ void Cty_GetListCountries (Cty_GetExtraData_t GetExtraData)
|
|||
Lay_NotEnoughMemoryExit ();
|
||||
break;
|
||||
}
|
||||
DB_BuildQuery ("(SELECT countries.CtyCod,countries.Alpha2,%s%sCOUNT(*) AS NumUsrs"
|
||||
" FROM countries,usr_data"
|
||||
" WHERE countries.CtyCod=usr_data.CtyCod"
|
||||
" GROUP BY countries.CtyCod)"
|
||||
" UNION "
|
||||
"(SELECT CtyCod,Alpha2,%s%s0 AS NumUsrs"
|
||||
" FROM countries"
|
||||
" WHERE CtyCod NOT IN"
|
||||
" (SELECT DISTINCT CtyCod FROM usr_data))"
|
||||
" ORDER BY %s",
|
||||
SubQueryNam1,SubQueryWWW1,
|
||||
SubQueryNam2,SubQueryWWW2,OrderBySubQuery);
|
||||
|
||||
NumRows = DB_QuerySELECT (&mysql_res,"can not get countries",
|
||||
"(SELECT countries.CtyCod,countries.Alpha2,"
|
||||
"%s%sCOUNT(*) AS NumUsrs"
|
||||
" FROM countries,usr_data"
|
||||
" WHERE countries.CtyCod=usr_data.CtyCod"
|
||||
" GROUP BY countries.CtyCod)"
|
||||
" UNION "
|
||||
"(SELECT CtyCod,Alpha2,%s%s0 AS NumUsrs"
|
||||
" FROM countries"
|
||||
" WHERE CtyCod NOT IN"
|
||||
" (SELECT DISTINCT CtyCod FROM usr_data))"
|
||||
" ORDER BY %s",
|
||||
SubQueryNam1,SubQueryWWW1,
|
||||
SubQueryNam2,SubQueryWWW2,OrderBySubQuery);
|
||||
break;
|
||||
}
|
||||
|
||||
/***** Count number of rows in result *****/
|
||||
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get countries");
|
||||
|
||||
/***** Free memory for subquery *****/
|
||||
if (OrderBySubQuery)
|
||||
free ((void *) OrderBySubQuery);
|
||||
|
@ -1190,12 +1190,12 @@ void Cty_WriteSelectorOfCountry (void)
|
|||
Txt_Country);
|
||||
|
||||
/***** Get countries from database *****/
|
||||
DB_BuildQuery ("SELECT DISTINCT CtyCod,Name_%s"
|
||||
" FROM countries"
|
||||
" ORDER BY countries.Name_%s",
|
||||
Txt_STR_LANG_ID[Gbl.Prefs.Language],
|
||||
Txt_STR_LANG_ID[Gbl.Prefs.Language]);
|
||||
NumCtys = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get countries");
|
||||
NumCtys = (unsigned) DB_QuerySELECT (&mysql_res,"can not get countries",
|
||||
"SELECT DISTINCT CtyCod,Name_%s"
|
||||
" FROM countries"
|
||||
" ORDER BY countries.Name_%s",
|
||||
Txt_STR_LANG_ID[Gbl.Prefs.Language],
|
||||
Txt_STR_LANG_ID[Gbl.Prefs.Language]);
|
||||
|
||||
/***** List countries *****/
|
||||
for (NumCty = 0;
|
||||
|
@ -1270,7 +1270,7 @@ bool Cty_GetDataOfCountryByCod (struct Country *Cty,Cty_GetExtraData_t GetExtraD
|
|||
char SubQueryWWW2[Cty_MAX_BYTES_SUBQUERY_CTYS + 1];
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
unsigned long NumRows;
|
||||
unsigned long NumRows = 0;
|
||||
Txt_Language_t Lan;
|
||||
bool CtyFound;
|
||||
|
||||
|
@ -1309,12 +1309,13 @@ bool Cty_GetDataOfCountryByCod (struct Country *Cty,Cty_GetExtraData_t GetExtraD
|
|||
switch (GetExtraData)
|
||||
{
|
||||
case Cty_GET_BASIC_DATA:
|
||||
DB_BuildQuery ("SELECT Alpha2,Name_%s,WWW_%s"
|
||||
" FROM countries"
|
||||
" WHERE CtyCod='%03ld'",
|
||||
Txt_STR_LANG_ID[Gbl.Prefs.Language],
|
||||
Txt_STR_LANG_ID[Gbl.Prefs.Language],
|
||||
Cty->CtyCod);
|
||||
NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a country",
|
||||
"SELECT Alpha2,Name_%s,WWW_%s"
|
||||
" FROM countries"
|
||||
" WHERE CtyCod='%03ld'",
|
||||
Txt_STR_LANG_ID[Gbl.Prefs.Language],
|
||||
Txt_STR_LANG_ID[Gbl.Prefs.Language],
|
||||
Cty->CtyCod);
|
||||
break;
|
||||
case Cty_GET_EXTRA_DATA:
|
||||
SubQueryNam1[0] = '\0';
|
||||
|
@ -1347,23 +1348,22 @@ bool Cty_GetDataOfCountryByCod (struct Country *Cty,Cty_GetExtraData_t GetExtraD
|
|||
Str_Concat (SubQueryWWW2,StrField,
|
||||
Cty_MAX_BYTES_SUBQUERY_CTYS);
|
||||
}
|
||||
DB_BuildQuery ("(SELECT countries.Alpha2,%s%sCOUNT(*) AS NumUsrs"
|
||||
" FROM countries,usr_data"
|
||||
" WHERE countries.CtyCod='%03ld'"
|
||||
" AND countries.CtyCod=usr_data.CtyCod)"
|
||||
" UNION "
|
||||
"(SELECT Alpha2,%s%s0 AS NumUsrs"
|
||||
" FROM countries"
|
||||
" WHERE CtyCod='%03ld'"
|
||||
" AND CtyCod NOT IN"
|
||||
" (SELECT DISTINCT CtyCod FROM usr_data))",
|
||||
SubQueryNam1,SubQueryWWW1,Cty->CtyCod,
|
||||
SubQueryNam2,SubQueryWWW2,Cty->CtyCod);
|
||||
NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a country",
|
||||
"(SELECT countries.Alpha2,%s%sCOUNT(*) AS NumUsrs"
|
||||
" FROM countries,usr_data"
|
||||
" WHERE countries.CtyCod='%03ld'"
|
||||
" AND countries.CtyCod=usr_data.CtyCod)"
|
||||
" UNION "
|
||||
"(SELECT Alpha2,%s%s0 AS NumUsrs"
|
||||
" FROM countries"
|
||||
" WHERE CtyCod='%03ld'"
|
||||
" AND CtyCod NOT IN"
|
||||
" (SELECT DISTINCT CtyCod FROM usr_data))",
|
||||
SubQueryNam1,SubQueryWWW1,Cty->CtyCod,
|
||||
SubQueryNam2,SubQueryWWW2,Cty->CtyCod);
|
||||
break;
|
||||
}
|
||||
|
||||
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get data of a country");
|
||||
|
||||
/***** Count number of rows in result *****/
|
||||
if (NumRows) // Country found...
|
||||
{
|
||||
|
@ -1454,9 +1454,9 @@ void Cty_GetCountryName (long CtyCod,char CtyName[Cty_MAX_BYTES_NAME + 1])
|
|||
/***** 3. Slow: get country name from database *****/
|
||||
Gbl.Cache.CountryName.CtyCod = CtyCod;
|
||||
|
||||
DB_BuildQuery ("SELECT Name_%s FROM countries WHERE CtyCod='%03ld'",
|
||||
Txt_STR_LANG_ID[Gbl.Prefs.Language],CtyCod);
|
||||
if (DB_QuerySELECT_new (&mysql_res,"can not get the name of a country")) // Country found...
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get the name of a country",
|
||||
"SELECT Name_%s FROM countries WHERE CtyCod='%03ld'",
|
||||
Txt_STR_LANG_ID[Gbl.Prefs.Language],CtyCod)) // Country found...
|
||||
{
|
||||
/* Get row */
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
|
@ -1489,9 +1489,9 @@ static void Cty_GetMapAttribution (long CtyCod,char **MapAttribution)
|
|||
Cty_FreeMapAttribution (MapAttribution);
|
||||
|
||||
/***** Get photo attribution from database *****/
|
||||
DB_BuildQuery ("SELECT MapAttribution FROM countries WHERE CtyCod=%ld",
|
||||
CtyCod);
|
||||
if (DB_QuerySELECT_new (&mysql_res,"can not get photo attribution"))
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get photo attribution",
|
||||
"SELECT MapAttribution FROM countries WHERE CtyCod=%ld",
|
||||
CtyCod))
|
||||
{
|
||||
/* Get row */
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
|
@ -2365,20 +2365,17 @@ unsigned Cty_GetNumCtysWithUsrs (Rol_Role_t Role,const char *SubQuery)
|
|||
/*****************************************************************************/
|
||||
/***************************** List countries found **************************/
|
||||
/*****************************************************************************/
|
||||
// Returns number of countries found
|
||||
|
||||
unsigned Cty_ListCtysFound (void)
|
||||
void Cty_ListCtysFound (MYSQL_RES **mysql_res,unsigned NumCtys)
|
||||
{
|
||||
extern const char *Txt_country;
|
||||
extern const char *Txt_countries;
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
unsigned NumCtys;
|
||||
unsigned NumCty;
|
||||
struct Country Cty;
|
||||
|
||||
/***** Query database *****/
|
||||
if ((NumCtys = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get countries")))
|
||||
if (NumCtys)
|
||||
{
|
||||
/***** Start box and table *****/
|
||||
/* Number of countries found */
|
||||
|
@ -2398,7 +2395,7 @@ unsigned Cty_ListCtysFound (void)
|
|||
NumCty++)
|
||||
{
|
||||
/* Get next country */
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
row = mysql_fetch_row (*mysql_res);
|
||||
|
||||
/* Get country code (row[0]) */
|
||||
Cty.CtyCod = Str_ConvertStrCodToLongCod (row[0]);
|
||||
|
@ -2415,7 +2412,5 @@ unsigned Cty_ListCtysFound (void)
|
|||
}
|
||||
|
||||
/***** Free structure that stores the query result *****/
|
||||
DB_FreeMySQLResult (&mysql_res);
|
||||
|
||||
return NumCtys;
|
||||
DB_FreeMySQLResult (mysql_res);
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
/********************************* Headers ***********************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
#include <mysql/mysql.h> // To access MySQL databases
|
||||
#include <stdbool.h> // For boolean type
|
||||
|
||||
#include "swad_action.h"
|
||||
|
@ -116,6 +117,6 @@ unsigned Cty_GetNumCtysWithDegs (const char *SubQuery);
|
|||
unsigned Cty_GetNumCtysWithCrss (const char *SubQuery);
|
||||
unsigned Cty_GetNumCtysWithUsrs (Rol_Role_t Role,const char *SubQuery);
|
||||
|
||||
unsigned Cty_ListCtysFound (void);
|
||||
void Cty_ListCtysFound (MYSQL_RES **mysql_res,unsigned NumCtys);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -902,11 +902,12 @@ void Crs_WriteSelectorOfCourse (void)
|
|||
if (Gbl.CurrentDeg.Deg.DegCod > 0)
|
||||
{
|
||||
/***** Get courses belonging to the current degree from database *****/
|
||||
DB_BuildQuery ("SELECT CrsCod,ShortName FROM courses"
|
||||
" WHERE DegCod=%ld"
|
||||
" ORDER BY ShortName",
|
||||
Gbl.CurrentDeg.Deg.DegCod);
|
||||
NumCrss = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get courses of a degree");
|
||||
NumCrss = (unsigned) DB_QuerySELECT (&mysql_res,"can not get courses"
|
||||
" of a degree",
|
||||
"SELECT CrsCod,ShortName FROM courses"
|
||||
" WHERE DegCod=%ld"
|
||||
" ORDER BY ShortName",
|
||||
Gbl.CurrentDeg.Deg.DegCod);
|
||||
|
||||
/***** Get courses of this degree *****/
|
||||
for (NumCrs = 0;
|
||||
|
@ -975,23 +976,25 @@ static void Crs_GetListCoursesInDegree (Crs_WhatCourses_t WhatCourses)
|
|||
switch (WhatCourses)
|
||||
{
|
||||
case Crs_ACTIVE_COURSES:
|
||||
DB_BuildQuery ("SELECT CrsCod,DegCod,Year,InsCrsCod,Status,RequesterUsrCod,ShortName,FullName"
|
||||
" FROM courses WHERE DegCod=%ld AND Status=0"
|
||||
" ORDER BY Year,ShortName",
|
||||
Gbl.CurrentDeg.Deg.DegCod);
|
||||
NumCrss = (unsigned) DB_QuerySELECT (&mysql_res,"can not get courses"
|
||||
" of a degree",
|
||||
"SELECT CrsCod,DegCod,Year,InsCrsCod,Status,RequesterUsrCod,ShortName,FullName"
|
||||
" FROM courses WHERE DegCod=%ld AND Status=0"
|
||||
" ORDER BY Year,ShortName",
|
||||
Gbl.CurrentDeg.Deg.DegCod);
|
||||
break;
|
||||
case Crs_ALL_COURSES_EXCEPT_REMOVED:
|
||||
DB_BuildQuery ("SELECT CrsCod,DegCod,Year,InsCrsCod,Status,RequesterUsrCod,ShortName,FullName"
|
||||
" FROM courses WHERE DegCod=%ld AND (Status & %u)=0"
|
||||
" ORDER BY Year,ShortName",
|
||||
Gbl.CurrentDeg.Deg.DegCod,
|
||||
(unsigned) Crs_STATUS_BIT_REMOVED);
|
||||
NumCrss = (unsigned) DB_QuerySELECT (&mysql_res,"can not get courses"
|
||||
" of a degree",
|
||||
"SELECT CrsCod,DegCod,Year,InsCrsCod,Status,RequesterUsrCod,ShortName,FullName"
|
||||
" FROM courses WHERE DegCod=%ld AND (Status & %u)=0"
|
||||
" ORDER BY Year,ShortName",
|
||||
Gbl.CurrentDeg.Deg.DegCod,
|
||||
(unsigned) Crs_STATUS_BIT_REMOVED);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
NumCrss = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get the courses of a degree");
|
||||
|
||||
if (NumCrss) // Courses found...
|
||||
{
|
||||
/***** Create list with courses in degree *****/
|
||||
|
@ -2011,10 +2014,10 @@ bool Crs_GetDataOfCourseByCod (struct Course *Crs)
|
|||
if (Crs->CrsCod > 0)
|
||||
{
|
||||
/***** Get data of a course from database *****/
|
||||
DB_BuildQuery ("SELECT CrsCod,DegCod,Year,InsCrsCod,Status,RequesterUsrCod,ShortName,FullName"
|
||||
" FROM courses WHERE CrsCod=%ld",
|
||||
Crs->CrsCod);
|
||||
if (DB_QuerySELECT_new (&mysql_res,"can not get data of a course")) // Course found...
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get data of a course",
|
||||
"SELECT CrsCod,DegCod,Year,InsCrsCod,Status,RequesterUsrCod,ShortName,FullName"
|
||||
" FROM courses WHERE CrsCod=%ld",
|
||||
Crs->CrsCod)) // Course found...
|
||||
{
|
||||
/***** Get data of the course *****/
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
|
@ -2091,12 +2094,12 @@ static void Crs_GetShortNamesByCod (long CrsCod,
|
|||
if (CrsCod > 0)
|
||||
{
|
||||
/***** Get the short name of a degree from database *****/
|
||||
DB_BuildQuery ("SELECT courses.ShortName,degrees.ShortName"
|
||||
" FROM courses,degrees"
|
||||
" WHERE courses.CrsCod=%ld"
|
||||
" AND courses.DegCod=degrees.DegCod",
|
||||
CrsCod);
|
||||
if (DB_QuerySELECT_new (&mysql_res,"can not get the short name of a course") == 1)
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get the short name of a course",
|
||||
"SELECT courses.ShortName,degrees.ShortName"
|
||||
" FROM courses,degrees"
|
||||
" WHERE courses.CrsCod=%ld"
|
||||
" AND courses.DegCod=degrees.DegCod",
|
||||
CrsCod) == 1)
|
||||
{
|
||||
/***** Get the short name of this course *****/
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
|
@ -3045,16 +3048,16 @@ void Crs_GetAndWriteCrssOfAUsr (const struct UsrData *UsrDat,Rol_Role_t Role)
|
|||
if (asprintf (&SubQuery," AND crs_usr.Role=%u",(unsigned) Role) < 0)
|
||||
Lay_NotEnoughMemoryExit ();
|
||||
}
|
||||
DB_BuildQuery ("SELECT degrees.DegCod,courses.CrsCod,degrees.ShortName,degrees.FullName,"
|
||||
"courses.Year,courses.FullName,centres.ShortName,crs_usr.Accepted"
|
||||
" FROM crs_usr,courses,degrees,centres"
|
||||
" WHERE crs_usr.UsrCod=%ld%s"
|
||||
" AND crs_usr.CrsCod=courses.CrsCod"
|
||||
" AND courses.DegCod=degrees.DegCod"
|
||||
" AND degrees.CtrCod=centres.CtrCod"
|
||||
" ORDER BY degrees.FullName,courses.Year,courses.FullName",
|
||||
UsrDat->UsrCod,SubQuery);
|
||||
NumCrss = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get courses of a user");
|
||||
NumCrss = (unsigned) DB_QuerySELECT (&mysql_res,"can not get courses of a user",
|
||||
"SELECT degrees.DegCod,courses.CrsCod,degrees.ShortName,degrees.FullName,"
|
||||
"courses.Year,courses.FullName,centres.ShortName,crs_usr.Accepted"
|
||||
" FROM crs_usr,courses,degrees,centres"
|
||||
" WHERE crs_usr.UsrCod=%ld%s"
|
||||
" AND crs_usr.CrsCod=courses.CrsCod"
|
||||
" AND courses.DegCod=degrees.DegCod"
|
||||
" AND degrees.CtrCod=centres.CtrCod"
|
||||
" ORDER BY degrees.FullName,courses.Year,courses.FullName",
|
||||
UsrDat->UsrCod,SubQuery);
|
||||
|
||||
/***** Free allocated memory for subquery *****/
|
||||
free ((void *) SubQuery);
|
||||
|
@ -3125,7 +3128,7 @@ void Crs_GetAndWriteCrssOfAUsr (const struct UsrData *UsrDat,Rol_Role_t Role)
|
|||
/*****************************************************************************/
|
||||
// Returns number of courses found
|
||||
|
||||
unsigned Crs_ListCrssFound (void)
|
||||
void Crs_ListCrssFound (MYSQL_RES **mysql_res,unsigned NumCrss)
|
||||
{
|
||||
extern const char *Txt_course;
|
||||
extern const char *Txt_courses;
|
||||
|
@ -3133,14 +3136,9 @@ unsigned Crs_ListCrssFound (void)
|
|||
extern const char *Txt_Year_OF_A_DEGREE;
|
||||
extern const char *Txt_Course;
|
||||
extern const char *Txt_ROLES_PLURAL_BRIEF_Abc[Rol_NUM_ROLES];
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
unsigned NumCrss;
|
||||
unsigned NumCrs;
|
||||
|
||||
/***** Query database *****/
|
||||
NumCrss = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get courses");
|
||||
|
||||
/***** List the courses (one row per course) *****/
|
||||
if (NumCrss)
|
||||
{
|
||||
|
@ -3184,7 +3182,7 @@ unsigned Crs_ListCrssFound (void)
|
|||
NumCrs++)
|
||||
{
|
||||
/* Get next course */
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
row = mysql_fetch_row (*mysql_res);
|
||||
|
||||
/* Write data of this course */
|
||||
Crs_WriteRowCrsData (NumCrs,row,false);
|
||||
|
@ -3195,9 +3193,7 @@ unsigned Crs_ListCrssFound (void)
|
|||
}
|
||||
|
||||
/***** Free structure that stores the query result *****/
|
||||
DB_FreeMySQLResult (&mysql_res);
|
||||
|
||||
return NumCrss;
|
||||
DB_FreeMySQLResult (mysql_res);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -3446,11 +3442,12 @@ void Crs_RemoveOldCrss (void)
|
|||
SecondsWithoutAccess = (unsigned long) MonthsWithoutAccess * Dat_SECONDS_IN_ONE_MONTH;
|
||||
|
||||
/***** Get old courses from database *****/
|
||||
DB_BuildQuery ("SELECT CrsCod FROM crs_last WHERE"
|
||||
" LastTime<FROM_UNIXTIME(UNIX_TIMESTAMP()-'%lu')"
|
||||
" AND CrsCod NOT IN (SELECT DISTINCT CrsCod FROM crs_usr)",
|
||||
SecondsWithoutAccess);
|
||||
if ((NumCrss = DB_QuerySELECT_new (&mysql_res,"can not get old users")))
|
||||
NumCrss = DB_QuerySELECT (&mysql_res,"can not get old courses",
|
||||
"SELECT CrsCod FROM crs_last WHERE"
|
||||
" LastTime<FROM_UNIXTIME(UNIX_TIMESTAMP()-'%lu')"
|
||||
" AND CrsCod NOT IN (SELECT DISTINCT CrsCod FROM crs_usr)",
|
||||
SecondsWithoutAccess);
|
||||
if (NumCrss)
|
||||
{
|
||||
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
|
||||
Txt_Eliminating_X_courses_whithout_users_and_with_more_than_Y_months_without_access,
|
||||
|
|
|
@ -137,7 +137,7 @@ void Crs_ReqSelectOneOfMyCourses (void);
|
|||
|
||||
void Crs_GetAndWriteCrssOfAUsr (const struct UsrData *UsrDat,Rol_Role_t Role);
|
||||
|
||||
unsigned Crs_ListCrssFound (void);
|
||||
void Crs_ListCrssFound (MYSQL_RES **mysql_res,unsigned NumCrss);
|
||||
|
||||
void Crs_UpdateCrsLast (void);
|
||||
|
||||
|
|
|
@ -617,6 +617,8 @@ static unsigned Sch_SearchCountriesInDB (const char *RangeQuery)
|
|||
extern const char *Txt_STR_LANG_ID[1 + Txt_NUM_LANGUAGES];
|
||||
char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1];
|
||||
char FieldName[4+1+2+1]; // Example: Name_en
|
||||
MYSQL_RES *mysql_res;
|
||||
unsigned NumCtys;
|
||||
|
||||
/***** Check scope *****/
|
||||
if (Gbl.Scope.Current != Sco_SCOPE_INS &&
|
||||
|
@ -633,13 +635,15 @@ static unsigned Sch_SearchCountriesInDB (const char *RangeQuery)
|
|||
if (Sch_BuildSearchQuery (SearchQuery,FieldName,NULL,NULL))
|
||||
{
|
||||
/***** Query database and list institutions found *****/
|
||||
DB_BuildQuery ("SELECT CtyCod"
|
||||
" FROM countries"
|
||||
" WHERE %s%s"
|
||||
" ORDER BY Name_%s",
|
||||
SearchQuery,RangeQuery,
|
||||
Txt_STR_LANG_ID[Gbl.Prefs.Language]);
|
||||
return Cty_ListCtysFound ();
|
||||
NumCtys = (unsigned) DB_QuerySELECT (&mysql_res,"can not get countries",
|
||||
"SELECT CtyCod"
|
||||
" FROM countries"
|
||||
" WHERE %s%s"
|
||||
" ORDER BY Name_%s",
|
||||
SearchQuery,RangeQuery,
|
||||
Txt_STR_LANG_ID[Gbl.Prefs.Language]);
|
||||
Cty_ListCtysFound (&mysql_res,NumCtys);
|
||||
return NumCtys;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -756,6 +760,8 @@ static unsigned Sch_SearchDegreesInDB (const char *RangeQuery)
|
|||
static unsigned Sch_SearchCoursesInDB (const char *RangeQuery)
|
||||
{
|
||||
char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1];
|
||||
MYSQL_RES *mysql_res;
|
||||
unsigned NumCrss;
|
||||
|
||||
/***** Check user's permission *****/
|
||||
if (Sch_CheckIfIHavePermissionToSearch (Sch_SEARCH_COURSES))
|
||||
|
@ -763,18 +769,20 @@ static unsigned Sch_SearchCoursesInDB (const char *RangeQuery)
|
|||
if (Sch_BuildSearchQuery (SearchQuery,"courses.FullName",NULL,NULL))
|
||||
{
|
||||
/***** Query database and list courses found *****/
|
||||
DB_BuildQuery ("SELECT degrees.DegCod,courses.CrsCod,degrees.ShortName,degrees.FullName,"
|
||||
"courses.Year,courses.FullName,centres.ShortName"
|
||||
" FROM courses,degrees,centres,institutions,countries"
|
||||
" WHERE %s"
|
||||
" AND courses.DegCod=degrees.DegCod"
|
||||
" AND degrees.CtrCod=centres.CtrCod"
|
||||
" AND centres.InsCod=institutions.InsCod"
|
||||
" AND institutions.CtyCod=countries.CtyCod"
|
||||
"%s"
|
||||
" ORDER BY courses.FullName,institutions.FullName,degrees.FullName,courses.Year",
|
||||
SearchQuery,RangeQuery);
|
||||
return Crs_ListCrssFound ();
|
||||
NumCrss = (unsigned) DB_QuerySELECT (&mysql_res,"can not get courses",
|
||||
"SELECT degrees.DegCod,courses.CrsCod,degrees.ShortName,degrees.FullName,"
|
||||
"courses.Year,courses.FullName,centres.ShortName"
|
||||
" FROM courses,degrees,centres,institutions,countries"
|
||||
" WHERE %s"
|
||||
" AND courses.DegCod=degrees.DegCod"
|
||||
" AND degrees.CtrCod=centres.CtrCod"
|
||||
" AND centres.InsCod=institutions.InsCod"
|
||||
" AND institutions.CtyCod=countries.CtyCod"
|
||||
"%s"
|
||||
" ORDER BY courses.FullName,institutions.FullName,degrees.FullName,courses.Year",
|
||||
SearchQuery,RangeQuery);
|
||||
Crs_ListCrssFound (&mysql_res,NumCrss);
|
||||
return NumCrss;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue