Version 18.8.3

This commit is contained in:
Antonio Cañas Vargas 2018-10-25 18:42:27 +02:00
parent 86751f95b9
commit 234cdf47be
10 changed files with 554 additions and 639 deletions

View File

@ -355,10 +355,11 @@ En OpenSWAD:
ps2pdf source.ps destination.pdf
*/
#define Log_PLATFORM_VERSION "SWAD 18.8.2 (2018-10-25)"
#define Log_PLATFORM_VERSION "SWAD 18.8.3 (2018-10-25)"
#define CSS_FILE "swad18.4.css"
#define JS_FILE "swad17.17.1.js"
/*
Version 18.8.3: Oct 25, 2018 Some asprintf for database queries changed by internal function. (237968 lines)
Version 18.8.2: Oct 25, 2018 Changes in alerts.
Fixed bug in account creation. (238051 lines)
Version 18.8.1: Oct 25, 2018 Fixed bug in password, reported by Francisco A. Ocaña and Ana del Carmen Ruiz Reina. (238047 lines)

View File

@ -899,7 +899,6 @@ unsigned Crs_GetNumCrssWithUsrs (Rol_Role_t Role,const char *SubQuery)
void Crs_WriteSelectorOfCourse (void)
{
extern const char *Txt_Course;
char *Query;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumCrss;
@ -923,12 +922,11 @@ void Crs_WriteSelectorOfCourse (void)
if (Gbl.CurrentDeg.Deg.DegCod > 0)
{
/***** Get courses belonging to the current degree from database *****/
if (asprintf (&Query,"SELECT CrsCod,ShortName FROM courses"
DB_BuildQuery ("SELECT CrsCod,ShortName FROM courses"
" WHERE DegCod=%ld"
" ORDER BY ShortName",
Gbl.CurrentDeg.Deg.DegCod) < 0)
Lay_NotEnoughMemoryExit ();
NumCrss = (unsigned) DB_QuerySELECT_free (Query,&mysql_res,"can not get courses of a degree");
Gbl.CurrentDeg.Deg.DegCod);
NumCrss = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get courses of a degree");
/***** Get courses of this degree *****/
for (NumCrs = 0;
@ -987,7 +985,6 @@ void Crs_ShowCrssOfCurrentDeg (void)
static void Crs_GetListCoursesInDegree (Crs_WhatCourses_t WhatCourses)
{
char *Query;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumCrss;
@ -998,24 +995,22 @@ static void Crs_GetListCoursesInDegree (Crs_WhatCourses_t WhatCourses)
switch (WhatCourses)
{
case Crs_ACTIVE_COURSES:
if (asprintf (&Query,"SELECT CrsCod,DegCod,Year,InsCrsCod,Status,RequesterUsrCod,ShortName,FullName"
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) < 0)
Lay_NotEnoughMemoryExit ();
Gbl.CurrentDeg.Deg.DegCod);
break;
case Crs_ALL_COURSES_EXCEPT_REMOVED:
if (asprintf (&Query,"SELECT CrsCod,DegCod,Year,InsCrsCod,Status,RequesterUsrCod,ShortName,FullName"
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) < 0)
Lay_NotEnoughMemoryExit ();
(unsigned) Crs_STATUS_BIT_REMOVED);
break;
default:
break;
}
NumCrss = (unsigned) DB_QuerySELECT_free (Query,&mysql_res,"can not get the courses of a degree");
NumCrss = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get the courses of a degree");
if (NumCrss) // Courses found...
{
@ -2018,7 +2013,6 @@ void Crs_RemoveCourse (void)
bool Crs_GetDataOfCourseByCod (struct Course *Crs)
{
char *Query;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
bool CrsFound = false;
@ -2039,11 +2033,10 @@ bool Crs_GetDataOfCourseByCod (struct Course *Crs)
if (Crs->CrsCod > 0)
{
/***** Get data of a course from database *****/
if (asprintf (&Query,"SELECT CrsCod,DegCod,Year,InsCrsCod,Status,RequesterUsrCod,ShortName,FullName"
DB_BuildQuery ("SELECT CrsCod,DegCod,Year,InsCrsCod,Status,RequesterUsrCod,ShortName,FullName"
" FROM courses WHERE CrsCod=%ld",
Crs->CrsCod) < 0)
Lay_NotEnoughMemoryExit ();
if (DB_QuerySELECT_free (Query,&mysql_res,"can not get data of a course")) // Course found...
Crs->CrsCod);
if (DB_QuerySELECT_new (&mysql_res,"can not get data of a course")) // Course found...
{
/***** Get data of the course *****/
row = mysql_fetch_row (mysql_res);
@ -2112,7 +2105,6 @@ static void Crs_GetShortNamesByCod (long CrsCod,
char CrsShortName[Hie_MAX_BYTES_SHRT_NAME + 1],
char DegShortName[Hie_MAX_BYTES_SHRT_NAME + 1])
{
char *Query;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
@ -2121,13 +2113,12 @@ static void Crs_GetShortNamesByCod (long CrsCod,
if (CrsCod > 0)
{
/***** Get the short name of a degree from database *****/
if (asprintf (&Query,"SELECT courses.ShortName,degrees.ShortName"
DB_BuildQuery ("SELECT courses.ShortName,degrees.ShortName"
" FROM courses,degrees"
" WHERE courses.CrsCod=%ld"
" AND courses.DegCod=degrees.DegCod",
CrsCod) < 0)
Lay_NotEnoughMemoryExit ();
if (DB_QuerySELECT_free (Query,&mysql_res,"can not get the short name of a course") == 1)
CrsCod);
if (DB_QuerySELECT_new (&mysql_res,"can not get the short name of a course") == 1)
{
/***** Get the short name of this course *****/
row = mysql_fetch_row (mysql_res);
@ -3098,7 +3089,6 @@ void Crs_GetAndWriteCrssOfAUsr (const struct UsrData *UsrDat,Rol_Role_t Role)
extern const char *Txt_Course;
extern const char *Txt_ROLES_PLURAL_BRIEF_Abc[Rol_NUM_ROLES];
char SubQuery[32];
char *Query;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumCrss;
@ -3109,7 +3099,7 @@ void Crs_GetAndWriteCrssOfAUsr (const struct UsrData *UsrDat,Rol_Role_t Role)
SubQuery[0] = '\0'; // Role == Rol_UNK ==> any role
else
sprintf (SubQuery," AND crs_usr.Role=%u",(unsigned) Role);
if (asprintf (&Query,"SELECT degrees.DegCod,courses.CrsCod,degrees.ShortName,degrees.FullName,"
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"
@ -3117,11 +3107,10 @@ void Crs_GetAndWriteCrssOfAUsr (const struct UsrData *UsrDat,Rol_Role_t Role)
" AND courses.DegCod=degrees.DegCod"
" AND degrees.CtrCod=centres.CtrCod"
" ORDER BY degrees.FullName,courses.Year,courses.FullName",
UsrDat->UsrCod,SubQuery) < 0)
Lay_NotEnoughMemoryExit ();
UsrDat->UsrCod,SubQuery);
/***** List the courses (one row per course) *****/
if ((NumCrss = (unsigned) DB_QuerySELECT_free (Query,&mysql_res,"can not get courses of a user")))
if ((NumCrss = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get courses of a user")))
{
/* Start box and table */
Box_StartBoxTable ("100%",NULL,NULL,
@ -3186,7 +3175,7 @@ void Crs_GetAndWriteCrssOfAUsr (const struct UsrData *UsrDat,Rol_Role_t Role)
/*****************************************************************************/
// Returns number of courses found
unsigned Crs_ListCrssFound (const char *Query)
unsigned Crs_ListCrssFound (void)
{
extern const char *Txt_course;
extern const char *Txt_courses;
@ -3200,7 +3189,7 @@ unsigned Crs_ListCrssFound (const char *Query)
unsigned NumCrs;
/***** Query database *****/
NumCrss = (unsigned) DB_QuerySELECT_free (Query,&mysql_res,"can not get courses");
NumCrss = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get courses");
/***** List the courses (one row per course) *****/
if (NumCrss)
@ -3492,7 +3481,6 @@ void Crs_RemoveOldCrss (void)
extern const char *Txt_X_courses_have_been_eliminated;
unsigned MonthsWithoutAccess;
unsigned long SecondsWithoutAccess;
char *Query;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumCrs;
@ -3511,12 +3499,11 @@ void Crs_RemoveOldCrss (void)
SecondsWithoutAccess = (unsigned long) MonthsWithoutAccess * Dat_SECONDS_IN_ONE_MONTH;
/***** Get old courses from database *****/
if (asprintf (&Query,"SELECT CrsCod FROM crs_last WHERE"
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) < 0)
Lay_NotEnoughMemoryExit ();
if ((NumCrss = DB_QuerySELECT_free (Query,&mysql_res,"can not get old users")))
SecondsWithoutAccess);
if ((NumCrss = DB_QuerySELECT_new (&mysql_res,"can not get old users")))
{
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
Txt_Eliminating_X_courses_whithout_users_and_with_more_than_Y_months_without_access,

View File

@ -137,7 +137,7 @@ void Crs_ReqSelectOneOfMyCourses (void);
void Crs_GetAndWriteCrssOfAUsr (const struct UsrData *UsrDat,Rol_Role_t Role);
unsigned Crs_ListCrssFound (const char *Query);
unsigned Crs_ListCrssFound (void);
void Crs_UpdateCrsLast (void);

View File

@ -738,7 +738,6 @@ void Dat_PutHiddenParBrowserTZDiff (void)
void Dat_GetBrowserTimeZone (char BrowserTimeZone[Dat_MAX_BYTES_TIME_ZONE + 1])
{
char *Query;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
bool TZNameIsUsable = false;
@ -758,10 +757,9 @@ void Dat_GetBrowserTimeZone (char BrowserTimeZone[Dat_MAX_BYTES_TIME_ZONE + 1])
if (BrowserTimeZone[0])
{
/* Try to convert a date from server time zone to browser time zone */
if (asprintf (&Query,"SELECT CONVERT_TZ(NOW(),@@session.time_zone,'%s')",
BrowserTimeZone) < 0)
Lay_NotEnoughMemoryExit ();
if (DB_QuerySELECT_free (Query,&mysql_res,"can not check if time zone name is usable"))
DB_BuildQuery ("SELECT CONVERT_TZ(NOW(),@@session.time_zone,'%s')",
BrowserTimeZone);
if (DB_QuerySELECT_new (&mysql_res,"can not check if time zone name is usable"))
{
row = mysql_fetch_row (mysql_res);
if (row[0] != NULL)

View File

@ -134,7 +134,6 @@ void Deg_SeeDegWithPendingCrss (void)
extern const char *Txt_Degree;
extern const char *Txt_Courses_ABBREVIATION;
extern const char *Txt_There_are_no_degrees_with_requests_for_courses_to_be_confirmed;
char *Query;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumDegs;
@ -146,7 +145,7 @@ void Deg_SeeDegWithPendingCrss (void)
switch (Gbl.Usrs.Me.Role.Logged)
{
case Rol_DEG_ADM:
if (asprintf (&Query,"SELECT courses.DegCod,COUNT(*)"
DB_BuildQuery ("SELECT courses.DegCod,COUNT(*)"
" FROM admin,courses,degrees"
" WHERE admin.UsrCod=%ld AND admin.Scope='%s'"
" AND admin.Cod=courses.DegCod"
@ -154,24 +153,22 @@ void Deg_SeeDegWithPendingCrss (void)
" AND courses.DegCod=degrees.DegCod"
" GROUP BY courses.DegCod ORDER BY degrees.ShortName",
Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_DEG],
(unsigned) Crs_STATUS_BIT_PENDING) < 0)
Lay_NotEnoughMemoryExit ();
(unsigned) Crs_STATUS_BIT_PENDING);
break;
case Rol_SYS_ADM:
if (asprintf (&Query,"SELECT courses.DegCod,COUNT(*)"
DB_BuildQuery ("SELECT courses.DegCod,COUNT(*)"
" FROM courses,degrees"
" WHERE (courses.Status & %u)<>0"
" AND courses.DegCod=degrees.DegCod"
" GROUP BY courses.DegCod ORDER BY degrees.ShortName",
(unsigned) Crs_STATUS_BIT_PENDING) < 0)
Lay_NotEnoughMemoryExit ();
(unsigned) Crs_STATUS_BIT_PENDING);
break;
default: // Forbidden for other users
return;
}
/***** Get degrees *****/
if ((NumDegs = (unsigned) DB_QuerySELECT_free (Query,&mysql_res,"can not get degrees with pending courses")))
if ((NumDegs = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get degrees with pending courses")))
{
/***** Start box and table *****/
Box_StartBoxTable (NULL,Txt_Degrees_with_pending_courses,NULL,
@ -589,7 +586,6 @@ static void Deg_ShowNumUsrsInCrssOfDeg (Rol_Role_t Role)
void Deg_WriteSelectorOfDegree (void)
{
extern const char *Txt_Degree;
char *Query;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumDegs;
@ -614,11 +610,10 @@ void Deg_WriteSelectorOfDegree (void)
if (Gbl.CurrentCtr.Ctr.CtrCod > 0)
{
/***** Get degrees belonging to the current centre from database *****/
if (asprintf (&Query,"SELECT DegCod,ShortName FROM degrees"
DB_BuildQuery ("SELECT DegCod,ShortName FROM degrees"
" WHERE CtrCod=%ld ORDER BY ShortName",
Gbl.CurrentCtr.Ctr.CtrCod) < 0)
Lay_NotEnoughMemoryExit ();
NumDegs = (unsigned) DB_QuerySELECT_free (Query,&mysql_res,"can not get degrees of a centre");
Gbl.CurrentCtr.Ctr.CtrCod);
NumDegs = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get degrees of a centre");
/***** Get degrees of this centre *****/
for (NumDeg = 0;
@ -1418,13 +1413,12 @@ static void Deg_PutIconToViewDegrees (void)
void Deg_GetListAllDegsWithStds (struct ListDegrees *Degs)
{
char *Query;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumDeg;
/***** Get degrees admin by me from database *****/
if (asprintf (&Query,"SELECT DISTINCTROW degrees.DegCod,degrees.CtrCod,"
DB_BuildQuery ("SELECT DISTINCTROW degrees.DegCod,degrees.CtrCod,"
"degrees.DegTypCod,degrees.Status,degrees.RequesterUsrCod,"
"degrees.ShortName,degrees.FullName,degrees.WWW"
" FROM degrees,courses,crs_usr"
@ -1432,9 +1426,8 @@ void Deg_GetListAllDegsWithStds (struct ListDegrees *Degs)
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.Role=%u"
" ORDER BY degrees.ShortName",
(unsigned) Rol_STD) < 0)
Lay_NotEnoughMemoryExit ();
Degs->Num = (unsigned) DB_QuerySELECT_free (Query,&mysql_res,"can not get degrees admin by you");
(unsigned) Rol_STD);
Degs->Num = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get degrees admin by you");
if (Degs->Num) // Degrees found...
{
@ -1465,19 +1458,17 @@ void Deg_GetListAllDegsWithStds (struct ListDegrees *Degs)
void Deg_GetListDegsOfCurrentCtr (void)
{
char *Query;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
unsigned NumDeg;
/***** Get degrees of the current centre from database *****/
if (asprintf (&Query,"SELECT DegCod,CtrCod,DegTypCod,Status,RequesterUsrCod,"
DB_BuildQuery ("SELECT DegCod,CtrCod,DegTypCod,Status,RequesterUsrCod,"
"ShortName,FullName,WWW"
" FROM degrees WHERE CtrCod=%ld ORDER BY FullName",
Gbl.CurrentCtr.Ctr.CtrCod) < 0)
Lay_NotEnoughMemoryExit ();
NumRows = DB_QuerySELECT_free (Query,&mysql_res,"can not get degrees of a centre");
Gbl.CurrentCtr.Ctr.CtrCod);
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get degrees of a centre");
/***** Count number of rows in result *****/
if (NumRows) // Degrees found...
@ -1672,7 +1663,6 @@ long Deg_GetAndCheckParamOtherDegCod (long MinCodAllowed)
bool Deg_GetDataOfDegreeByCod (struct Degree *Deg)
{
char *Query;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
bool DegFound = false;
@ -1691,12 +1681,11 @@ bool Deg_GetDataOfDegreeByCod (struct Degree *Deg)
if (Deg->DegCod > 0)
{
/***** Get data of a degree from database *****/
if (asprintf (&Query,"SELECT DegCod,CtrCod,DegTypCod,Status,"
DB_BuildQuery ("SELECT DegCod,CtrCod,DegTypCod,Status,"
"RequesterUsrCod,ShortName,FullName,WWW"
" FROM degrees WHERE DegCod=%ld",
Deg->DegCod) < 0)
Lay_NotEnoughMemoryExit ();
if (DB_QuerySELECT_free (Query,&mysql_res,"can not get data of a degree")) // Degree found...
Deg->DegCod);
if (DB_QuerySELECT_new (&mysql_res,"can not get data of a degree")) // Degree found...
{
/***** Get data of degree *****/
row = mysql_fetch_row (mysql_res);
@ -1755,7 +1744,6 @@ static void Deg_GetDataOfDegreeFromRow (struct Degree *Deg,MYSQL_ROW row)
void Deg_GetShortNameOfDegreeByCod (struct Degree *Deg)
{
char *Query;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
@ -1763,10 +1751,9 @@ void Deg_GetShortNameOfDegreeByCod (struct Degree *Deg)
if (Deg->DegCod > 0)
{
/***** Get the short name of a degree from database *****/
if (asprintf (&Query,"SELECT ShortName FROM degrees WHERE DegCod=%ld",
Deg->DegCod) < 0)
Lay_NotEnoughMemoryExit ();
if (DB_QuerySELECT_free (Query,&mysql_res,"can not get the short name of a degree") == 1)
DB_BuildQuery ("SELECT ShortName FROM degrees WHERE DegCod=%ld",
Deg->DegCod);
if (DB_QuerySELECT_new (&mysql_res,"can not get the short name of a degree") == 1)
{
/***** Get the short name of this degree *****/
row = mysql_fetch_row (mysql_res);
@ -1786,7 +1773,6 @@ void Deg_GetShortNameOfDegreeByCod (struct Degree *Deg)
long Deg_GetCtrCodOfDegreeByCod (long DegCod)
{
char *Query;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
long CtrCod = -1L;
@ -1794,10 +1780,8 @@ long Deg_GetCtrCodOfDegreeByCod (long DegCod)
if (DegCod > 0)
{
/***** Get the centre code of a degree from database *****/
if (asprintf (&Query,"SELECT CtrCod FROM degrees WHERE DegCod=%ld",
DegCod) < 0)
Lay_NotEnoughMemoryExit ();
if (DB_QuerySELECT_free (Query,&mysql_res,"can not get the centre of a degree") == 1)
DB_BuildQuery ("SELECT CtrCod FROM degrees WHERE DegCod=%ld",DegCod);
if (DB_QuerySELECT_new (&mysql_res,"can not get the centre of a degree") == 1)
{
/***** Get the centre code of this degree *****/
row = mysql_fetch_row (mysql_res);
@ -1817,7 +1801,6 @@ long Deg_GetCtrCodOfDegreeByCod (long DegCod)
long Deg_GetInsCodOfDegreeByCod (long DegCod)
{
char *Query;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
long InsCod = -1L;
@ -1825,12 +1808,11 @@ long Deg_GetInsCodOfDegreeByCod (long DegCod)
if (DegCod > 0)
{
/***** Get the institution code of a degree from database *****/
if (asprintf (&Query,"SELECT centres.InsCod FROM degrees,centres"
DB_BuildQuery ("SELECT centres.InsCod FROM degrees,centres"
" WHERE degrees.DegCod=%ld"
" AND degrees.CtrCod=centres.CtrCod",
DegCod) < 0)
Lay_NotEnoughMemoryExit ();
if (DB_QuerySELECT_free (Query,&mysql_res,"can not get the institution of a degree") == 1)
DegCod);
if (DB_QuerySELECT_new (&mysql_res,"can not get the institution of a degree") == 1)
{
/***** Get the institution code of this degree *****/
row = mysql_fetch_row (mysql_res);
@ -1859,10 +1841,8 @@ void Deg_RemoveDegreeCompletely (long DegCod)
char PathDeg[PATH_MAX + 1];
/***** Get courses of a degree from database *****/
if (asprintf (&Query,"SELECT CrsCod FROM courses WHERE DegCod=%ld",
DegCod) < 0)
Lay_NotEnoughMemoryExit ();
NumRows = DB_QuerySELECT_free (Query,&mysql_res,"can not get courses of a degree");
DB_BuildQuery ("SELECT CrsCod FROM courses WHERE DegCod=%ld",DegCod);
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get courses of a degree");
/* Get courses in this degree */
for (NumRow = 0;

View File

@ -570,7 +570,6 @@ void DT_GetListDegreeTypes (Sco_Scope_t Scope,DT_Order_t Order)
"DegTypName", // DT_ORDER_BY_DEGREE_TYPE
"NumDegs DESC,DegTypName", // DT_ORDER_BY_NUM_DEGREES
};
char *Query;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRow;
@ -583,7 +582,7 @@ void DT_GetListDegreeTypes (Sco_Scope_t Scope,DT_Order_t Order)
all degree types with degrees
union with
all degree types without any degree */
if (asprintf (&Query,"(SELECT deg_types.DegTypCod,deg_types.DegTypName,"
DB_BuildQuery ("(SELECT deg_types.DegTypCod,deg_types.DegTypName,"
"COUNT(degrees.DegCod) AS NumDegs"
" FROM degrees,deg_types"
" WHERE degrees.DegTypCod=deg_types.DegTypCod"
@ -594,12 +593,11 @@ void DT_GetListDegreeTypes (Sco_Scope_t Scope,DT_Order_t Order)
" WHERE DegTypCod NOT IN"
" (SELECT DegTypCod FROM degrees))"
" ORDER BY %s",
OrderBySubQuery[Order]) < 0)
Lay_NotEnoughMemoryExit ();
OrderBySubQuery[Order]);
break;
case Sco_SCOPE_CTY:
/* Get only degree types with degrees in the current country */
if (asprintf (&Query,"SELECT deg_types.DegTypCod,deg_types.DegTypName,"
DB_BuildQuery ("SELECT deg_types.DegTypCod,deg_types.DegTypName,"
"COUNT(degrees.DegCod) AS NumDegs"
" FROM institutions,centres,degrees,deg_types"
" WHERE institutions.CtyCod=%ld"
@ -609,12 +607,11 @@ void DT_GetListDegreeTypes (Sco_Scope_t Scope,DT_Order_t Order)
" GROUP BY degrees.DegTypCod"
" ORDER BY %s",
Gbl.CurrentCty.Cty.CtyCod,
OrderBySubQuery[Order]) < 0)
Lay_NotEnoughMemoryExit ();
OrderBySubQuery[Order]);
break;
case Sco_SCOPE_INS:
/* Get only degree types with degrees in the current institution */
if (asprintf (&Query,"SELECT deg_types.DegTypCod,deg_types.DegTypName,"
DB_BuildQuery ("SELECT deg_types.DegTypCod,deg_types.DegTypName,"
"COUNT(degrees.DegCod) AS NumDegs"
" FROM centres,degrees,deg_types"
" WHERE centres.InsCod=%ld"
@ -623,12 +620,11 @@ void DT_GetListDegreeTypes (Sco_Scope_t Scope,DT_Order_t Order)
" GROUP BY degrees.DegTypCod"
" ORDER BY %s",
Gbl.CurrentIns.Ins.InsCod,
OrderBySubQuery[Order]) < 0)
Lay_NotEnoughMemoryExit ();
OrderBySubQuery[Order]);
break;
case Sco_SCOPE_CTR:
/* Get only degree types with degrees in the current centre */
if (asprintf (&Query,"SELECT deg_types.DegTypCod,deg_types.DegTypName,"
DB_BuildQuery ("SELECT deg_types.DegTypCod,deg_types.DegTypName,"
"COUNT(degrees.DegCod) AS NumDegs"
" FROM degrees,deg_types"
" WHERE degrees.CtrCod=%ld"
@ -636,13 +632,12 @@ void DT_GetListDegreeTypes (Sco_Scope_t Scope,DT_Order_t Order)
" GROUP BY degrees.DegTypCod"
" ORDER BY %s",
Gbl.CurrentCtr.Ctr.CtrCod,
OrderBySubQuery[Order]) < 0)
Lay_NotEnoughMemoryExit ();
OrderBySubQuery[Order]);
break;
case Sco_SCOPE_DEG:
case Sco_SCOPE_CRS:
/* Get only degree types with degrees in the current degree */
if (asprintf (&Query,"SELECT deg_types.DegTypCod,deg_types.DegTypName,"
DB_BuildQuery ("SELECT deg_types.DegTypCod,deg_types.DegTypName,"
"COUNT(degrees.DegCod) AS NumDegs"
" FROM degrees,deg_types"
" WHERE degrees.DegCod=%ld"
@ -650,14 +645,13 @@ void DT_GetListDegreeTypes (Sco_Scope_t Scope,DT_Order_t Order)
" GROUP BY degrees.DegTypCod"
" ORDER BY %s",
Gbl.CurrentDeg.Deg.DegCod,
OrderBySubQuery[Order]) < 0)
Lay_NotEnoughMemoryExit ();
OrderBySubQuery[Order]);
break;
default:
Lay_WrongScopeExit ();
break;
}
Gbl.Degs.DegTypes.Num = (unsigned) DB_QuerySELECT_free (Query,&mysql_res,"can not get types of degree");
Gbl.Degs.DegTypes.Num = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get types of degree");
/***** Get degree types *****/
if (Gbl.Degs.DegTypes.Num)
@ -824,7 +818,6 @@ static unsigned DT_CountNumDegsOfType (long DegTypCod)
bool DT_GetDataOfDegreeTypeByCod (struct DegreeType *DegTyp)
{
char *Query;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
@ -839,10 +832,9 @@ bool DT_GetDataOfDegreeTypeByCod (struct DegreeType *DegTyp)
}
/***** Get the name of a type of degree from database *****/
if (asprintf (&Query,"SELECT DegTypName FROM deg_types WHERE DegTypCod=%ld",
DegTyp->DegTypCod) < 0)
Lay_NotEnoughMemoryExit ();
NumRows = DB_QuerySELECT_free (Query,&mysql_res,"can not get the name of a type of degree");
DB_BuildQuery ("SELECT DegTypName FROM deg_types WHERE DegTypCod=%ld",
DegTyp->DegTypCod);
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get the name of a type of degree");
if (NumRows == 1)
{
@ -888,10 +880,9 @@ static void DT_RemoveDegreeTypeCompletely (long DegTypCod)
long DegCod;
/***** Get degrees of a type from database *****/
if (asprintf (&Query,"SELECT DegCod FROM degrees WHERE DegTypCod=%ld",
DegTypCod) < 0)
Lay_NotEnoughMemoryExit ();
NumRows = DB_QuerySELECT_free (Query,&mysql_res,"can not get degrees of a type");
DB_BuildQuery ("SELECT DegCod FROM degrees WHERE DegTypCod=%ld",
DegTypCod);
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get degrees of a type");
/* Get degrees of this type */
for (NumRow = 0;

View File

@ -261,7 +261,6 @@ void Dpt_EditDepartments (void)
void Dpt_GetListDepartments (long InsCod)
{
char OrderBySubQuery[256];
char *Query;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumDpt;
@ -282,7 +281,7 @@ void Dpt_GetListDepartments (long InsCod)
sprintf (OrderBySubQuery,"NumTchs DESC,FullName");
break;
}
if (asprintf (&Query,"(SELECT departments.DptCod,departments.InsCod,"
DB_BuildQuery ("(SELECT departments.DptCod,departments.InsCod,"
"departments.ShortName,departments.FullName,departments.WWW,"
"COUNT(DISTINCT usr_data.UsrCod) AS NumTchs"
" FROM departments,usr_data,crs_usr"
@ -300,9 +299,8 @@ void Dpt_GetListDepartments (long InsCod)
" ORDER BY %s",
InsCod,(unsigned) Rol_NET,(unsigned) Rol_TCH,
InsCod,(unsigned) Rol_NET,(unsigned) Rol_TCH,
OrderBySubQuery) < 0)
Lay_NotEnoughMemoryExit ();
Gbl.Dpts.Num = (unsigned) DB_QuerySELECT_free (Query,&mysql_res,"can not get departments");
OrderBySubQuery);
Gbl.Dpts.Num = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get departments");
if (Gbl.Dpts.Num) // Departments found...
{
@ -359,7 +357,6 @@ void Dpt_GetListDepartments (long InsCod)
void Dpt_GetDataOfDepartmentByCod (struct Department *Dpt)
{
extern const char *Txt_Another_department;
char *Query;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
@ -380,7 +377,7 @@ void Dpt_GetDataOfDepartmentByCod (struct Department *Dpt)
else if (Dpt->DptCod > 0)
{
/***** Get data of a department from database *****/
if (asprintf (&Query,"(SELECT departments.InsCod,departments.ShortName,departments.FullName,departments.WWW,"
DB_BuildQuery ("(SELECT departments.InsCod,departments.ShortName,departments.FullName,departments.WWW,"
"COUNT(DISTINCT usr_data.UsrCod) AS NumTchs"
" FROM departments,usr_data,crs_usr"
" WHERE departments.DptCod=%ld"
@ -395,9 +392,8 @@ void Dpt_GetDataOfDepartmentByCod (struct Department *Dpt)
" (SELECT DISTINCT usr_data.DptCod FROM usr_data,crs_usr"
" WHERE crs_usr.Role=%u AND crs_usr.UsrCod=usr_data.UsrCod))",
Dpt->DptCod,(unsigned) Rol_TCH,
Dpt->DptCod,(unsigned) Rol_TCH) < 0)
Lay_NotEnoughMemoryExit ();
NumRows = DB_QuerySELECT_free (Query,&mysql_res,"can not get data of a department");
Dpt->DptCod,(unsigned) Rol_TCH);
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get data of a department");
if (NumRows) // Department found...
{

View File

@ -136,7 +136,6 @@ void Dup_ListDuplicateUsrs (void)
extern const char *Hlp_USERS_Duplicates_possibly_duplicate_users;
extern const char *Txt_Possibly_duplicate_users;
extern const char *Txt_Informants;
char *Query;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumUsrs;
@ -149,12 +148,11 @@ void Dup_ListDuplicateUsrs (void)
Hlp_USERS_Duplicates_possibly_duplicate_users,Box_NOT_CLOSABLE);
/***** Build query *****/
if (asprintf (&Query,"SELECT UsrCod,COUNT(*) AS N,MIN(UNIX_TIMESTAMP(InformTime)) AS T"
DB_BuildQuery ("SELECT UsrCod,COUNT(*) AS N,MIN(UNIX_TIMESTAMP(InformTime)) AS T"
" FROM usr_duplicated"
" GROUP BY UsrCod"
" ORDER BY N DESC,T DESC") < 0)
Lay_NotEnoughMemoryExit ();
NumUsrs = (unsigned) DB_QuerySELECT_free (Query,&mysql_res,"can not get possibly duplicate users");
" ORDER BY N DESC,T DESC");
NumUsrs = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get possibly duplicate users");
/***** List possible duplicated users *****/
if (NumUsrs)
@ -261,7 +259,6 @@ static void Dup_ListSimilarUsrs (void)
extern const char *Hlp_USERS_Duplicates_similar_users;
extern const char *Txt_Similar_users;
struct UsrData UsrDat;
char *Query;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumUsrs;
@ -275,7 +272,7 @@ static void Dup_ListSimilarUsrs (void)
if (Gbl.Usrs.Other.UsrDat.Surname1[0] &&
Gbl.Usrs.Other.UsrDat.FirstName[0]) // Name and surname 1 not empty
{
if (asprintf (&Query,"SELECT DISTINCT UsrCod FROM"
DB_BuildQuery ("SELECT DISTINCT UsrCod FROM"
"(SELECT DISTINCT UsrCod FROM usr_IDs"
" WHERE UsrID IN (SELECT UsrID FROM usr_IDs WHERE UsrCod=%ld)"
" UNION"
@ -285,15 +282,13 @@ static void Dup_ListSimilarUsrs (void)
Gbl.Usrs.Other.UsrDat.UsrCod,
Gbl.Usrs.Other.UsrDat.Surname1,
Gbl.Usrs.Other.UsrDat.Surname2,
Gbl.Usrs.Other.UsrDat.FirstName) < 0)
Lay_NotEnoughMemoryExit ();
Gbl.Usrs.Other.UsrDat.FirstName);
}
else
if (asprintf (&Query,"SELECT DISTINCT UsrCod FROM usr_IDs"
DB_BuildQuery ("SELECT DISTINCT UsrCod FROM usr_IDs"
" WHERE UsrID IN (SELECT UsrID FROM usr_IDs WHERE UsrCod=%ld)",
Gbl.Usrs.Other.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
NumUsrs = (unsigned) DB_QuerySELECT_free (Query,&mysql_res,"can not get similar users");
Gbl.Usrs.Other.UsrDat.UsrCod);
NumUsrs = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get similar users");
/***** List possible similar users *****/
if (NumUsrs)

View File

@ -473,7 +473,6 @@ void Enr_GetNotifEnrolment (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
long CrsCod,long UsrCod)
{
extern const char *Txt_ROLES_SINGUL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
char *Query;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
struct UsrData UsrDat;
@ -483,13 +482,11 @@ void Enr_GetNotifEnrolment (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
// This function may be called inside a web service, so don't report error
/***** Get user's role in course from database *****/
if (asprintf (&Query,"SELECT Role"
DB_BuildQuery ("SELECT Role"
" FROM crs_usr"
" WHERE CrsCod=%ld AND UsrCod=%ld",
CrsCod,UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
if (DB_QuerySELECT_free (Query,&mysql_res,"can not get user's role"
CrsCod,UsrCod);
if (DB_QuerySELECT_new (&mysql_res,"can not get user's role"
" in course") == 1) // Result should have a unique row
{
/***** Get user's role in course *****/
@ -854,7 +851,6 @@ void Enr_RemoveOldUsrs (void)
extern const char *Txt_X_users_have_been_eliminated;
unsigned MonthsWithoutAccess;
time_t SecondsWithoutAccess;
char *Query;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumUsr;
@ -873,7 +869,7 @@ void Enr_RemoveOldUsrs (void)
SecondsWithoutAccess = (time_t) MonthsWithoutAccess * Dat_SECONDS_IN_ONE_MONTH;
/***** Get old users from database *****/
if (asprintf (&Query,"SELECT UsrCod FROM"
DB_BuildQuery ("SELECT UsrCod FROM"
"("
"SELECT UsrCod FROM usr_last WHERE"
" LastTime<FROM_UNIXTIME(UNIX_TIMESTAMP()-'%lu')"
@ -882,9 +878,8 @@ void Enr_RemoveOldUsrs (void)
" UsrCod NOT IN (SELECT UsrCod FROM usr_last)"
") AS candidate_usrs"
" WHERE UsrCod NOT IN (SELECT DISTINCT UsrCod FROM crs_usr)",
(unsigned long) SecondsWithoutAccess) < 0)
Lay_NotEnoughMemoryExit ();
if ((NumUsrs = DB_QuerySELECT_free (Query,&mysql_res,"can not get old users")))
(unsigned long) SecondsWithoutAccess);
if ((NumUsrs = DB_QuerySELECT_new (&mysql_res,"can not get old users")))
{
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
Txt_Eliminating_X_users_who_were_not_enroled_in_any_course_and_with_more_than_Y_months_without_access_to_Z,
@ -2044,12 +2039,11 @@ void Enr_SignUpInCrs (void)
Lay_ShowErrorAndExit ("Wrong role.");
/***** Try to get and old request of the same user in the same course from database *****/
if (asprintf (&Query,"SELECT ReqCod FROM crs_usr_requests"
DB_BuildQuery ("SELECT ReqCod FROM crs_usr_requests"
" WHERE CrsCod=%ld AND UsrCod=%ld",
Gbl.CurrentCrs.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
if (DB_QuerySELECT_free (Query,&mysql_res,"can not get enrolment request"))
Gbl.Usrs.Me.UsrDat.UsrCod);
if (DB_QuerySELECT_new (&mysql_res,"can not get enrolment request"))
{
row = mysql_fetch_row (mysql_res);
/* Get request code (row[0]) */
@ -2108,7 +2102,6 @@ void Enr_GetNotifEnrolmentRequest (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
long ReqCod,bool GetContent)
{
extern const char *Txt_ROLES_SINGUL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
char *Query;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
struct UsrData UsrDat;
@ -2118,13 +2111,11 @@ void Enr_GetNotifEnrolmentRequest (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
// This function may be called inside a web service, so don't report error
/***** Get user and requested role from database *****/
if (asprintf (&Query,"SELECT UsrCod,Role"
DB_BuildQuery ("SELECT UsrCod,Role"
" FROM crs_usr_requests"
" WHERE ReqCod=%ld",
ReqCod) < 0)
Lay_NotEnoughMemoryExit ();
if (DB_QuerySELECT_free (Query,&mysql_res,"can not get enrolment request") == 1) // Result should have a unique row
ReqCod);
if (DB_QuerySELECT_new (&mysql_res,"can not get enrolment request") == 1) // Result should have a unique row
{
/***** Get user and requested role *****/
row = mysql_fetch_row (mysql_res);
@ -2324,7 +2315,6 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
extern const char *Txt_Register;
extern const char *Txt_Reject;
extern const char *Txt_No_enrolment_requests;
char *Query;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumReq;
@ -2400,7 +2390,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
{
case Rol_TCH:
// Requests in all courses in which I am teacher
if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
DB_BuildQuery ("SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod,"
"crs_usr_requests.Role,"
@ -2413,12 +2403,11 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Rol_TCH,
RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
RolesSelected);
break;
case Rol_DEG_ADM:
// Requests in all degrees administrated by me
if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
DB_BuildQuery ("SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod,"
"crs_usr_requests.Role,"
@ -2430,12 +2419,11 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" AND ((1<<crs_usr_requests.Role)&%u)<>0"
" ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_DEG],
RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
RolesSelected);
break;
case Rol_CTR_ADM:
// Requests in all centres administrated by me
if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
DB_BuildQuery ("SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod,"
"crs_usr_requests.Role,"
@ -2448,12 +2436,11 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" AND ((1<<crs_usr_requests.Role)&%u)<>0"
" ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_CTR],
RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
RolesSelected);
break;
case Rol_INS_ADM:
// Requests in all institutions administrated by me
if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
DB_BuildQuery ("SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod,"
"crs_usr_requests.Role,"
@ -2467,12 +2454,11 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" AND ((1<<crs_usr_requests.Role)&%u)<>0"
" ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_INS],
RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
RolesSelected);
break;
case Rol_SYS_ADM:
// All requests
if (asprintf (&Query,"SELECT ReqCod,"
DB_BuildQuery ("SELECT ReqCod,"
"CrsCod,"
"UsrCod,"
"Role,"
@ -2480,8 +2466,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" FROM crs_usr_requests"
" WHERE ((1<<Role)&%u)<>0"
" ORDER BY RequestTime DESC",
RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
RolesSelected);
break;
default:
Lay_ShowErrorAndExit ("You don't have permission to list requesters.");
@ -2493,7 +2478,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
{
case Rol_TCH:
// Requests in courses of this country in which I am teacher
if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
DB_BuildQuery ("SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod,"
"crs_usr_requests.Role,"
@ -2512,12 +2497,11 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Rol_TCH,
Gbl.CurrentCty.Cty.CtyCod,
RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
RolesSelected);
break;
case Rol_DEG_ADM:
// Requests in degrees of this country administrated by me
if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
DB_BuildQuery ("SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod,"
"crs_usr_requests.Role,"
@ -2534,12 +2518,11 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_DEG],
Gbl.CurrentCty.Cty.CtyCod,
RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
RolesSelected);
break;
case Rol_CTR_ADM:
// Requests in centres of this country administrated by me
if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
DB_BuildQuery ("SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod,"
"crs_usr_requests.Role,"
@ -2556,12 +2539,11 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_CTR],
Gbl.CurrentCty.Cty.CtyCod,
RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
RolesSelected);
break;
case Rol_INS_ADM:
// Requests in institutions of this country administrated by me
if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
DB_BuildQuery ("SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod,"
"crs_usr_requests.Role,"
@ -2578,12 +2560,11 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_INS],
Gbl.CurrentCty.Cty.CtyCod,
RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
RolesSelected);
break;
case Rol_SYS_ADM:
// Requests in any course of this country
if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
DB_BuildQuery ("SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod,"
"crs_usr_requests.Role,"
@ -2597,8 +2578,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" AND ((1<<crs_usr_requests.Role)&%u)<>0"
" ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.CurrentCty.Cty.CtyCod,
RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
RolesSelected);
break;
default:
Lay_ShowErrorAndExit ("You don't have permission to list requesters.");
@ -2610,7 +2590,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
{
case Rol_TCH:
// Requests in courses of this institution in which I am teacher
if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
DB_BuildQuery ("SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod,"
"crs_usr_requests.Role,"
@ -2628,12 +2608,11 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Rol_TCH,
Gbl.CurrentIns.Ins.InsCod,
RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
RolesSelected);
break;
case Rol_DEG_ADM:
// Requests in degrees of this institution administrated by me
if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
DB_BuildQuery ("SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod,"
"crs_usr_requests.Role,"
@ -2649,12 +2628,11 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_DEG],
Gbl.CurrentIns.Ins.InsCod,
RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
RolesSelected);
break;
case Rol_CTR_ADM:
// Requests in centres of this institution administrated by me
if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
DB_BuildQuery ("SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod,"
"crs_usr_requests.Role,"
@ -2670,13 +2648,12 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_CTR],
Gbl.CurrentIns.Ins.InsCod,
RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
RolesSelected);
break;
case Rol_INS_ADM: // If I am logged as admin of this institution, I can view all the requesters from this institution
case Rol_SYS_ADM:
// Requests in any course of this institution
if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
DB_BuildQuery ("SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod,"
"crs_usr_requests.Role,"
@ -2689,8 +2666,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" AND ((1<<crs_usr_requests.Role)&%u)<>0"
" ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.CurrentIns.Ins.InsCod,
RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
RolesSelected);
break;
default:
Lay_ShowErrorAndExit ("You don't have permission to list requesters.");
@ -2702,7 +2678,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
{
case Rol_TCH:
// Requests in courses of this centre in which I am teacher
if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
DB_BuildQuery ("SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod,"
"crs_usr_requests.Role,"
@ -2719,12 +2695,11 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Rol_TCH,
Gbl.CurrentCtr.Ctr.CtrCod,
RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
RolesSelected);
break;
case Rol_DEG_ADM:
// Requests in degrees of this centre administrated by me
if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
DB_BuildQuery ("SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod,"
"crs_usr_requests.Role,"
@ -2739,14 +2714,13 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,Sco_ScopeDB[Sco_SCOPE_DEG],
Gbl.CurrentCtr.Ctr.CtrCod,
RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
RolesSelected);
break;
case Rol_CTR_ADM: // If I am logged as admin of this centre , I can view all the requesters from this centre
case Rol_INS_ADM: // If I am logged as admin of this institution, I can view all the requesters from this centre
case Rol_SYS_ADM:
// Request in any course of this centre
if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
DB_BuildQuery ("SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod,"
"crs_usr_requests.Role,"
@ -2758,8 +2732,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" AND ((1<<crs_usr_requests.Role)&%u)<>0"
" ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.CurrentCtr.Ctr.CtrCod,
RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
RolesSelected);
break;
default:
Lay_ShowErrorAndExit ("You don't have permission to list requesters.");
@ -2771,7 +2744,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
{
case Rol_TCH:
// Requests in courses of this degree in which I am teacher
if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
DB_BuildQuery ("SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod,"
"crs_usr_requests.Role,"
@ -2787,15 +2760,14 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Rol_TCH,
Gbl.CurrentDeg.Deg.DegCod,
RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
RolesSelected);
break;
case Rol_DEG_ADM: // If I am logged as admin of this degree , I can view all the requesters from this degree
case Rol_CTR_ADM: // If I am logged as admin of this centre , I can view all the requesters from this degree
case Rol_INS_ADM: // If I am logged as admin of this institution, I can view all the requesters from this degree
case Rol_SYS_ADM:
// Requests in any course of this degree
if (asprintf (&Query,"SELECT crs_usr_requests.ReqCod,"
DB_BuildQuery ("SELECT crs_usr_requests.ReqCod,"
"crs_usr_requests.CrsCod,"
"crs_usr_requests.UsrCod,"
"crs_usr_requests.Role,"
@ -2806,8 +2778,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
" AND ((1<<crs_usr_requests.Role)&%u)<>0"
" ORDER BY crs_usr_requests.RequestTime DESC",
Gbl.CurrentDeg.Deg.DegCod,
RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
RolesSelected);
break;
default:
Lay_ShowErrorAndExit ("You don't have permission to list requesters.");
@ -2823,15 +2794,14 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
case Rol_INS_ADM: // If I am logged as admin of this institution, I can view all the requesters from this course
case Rol_SYS_ADM:
// Requests in this course
if (asprintf (&Query,"SELECT ReqCod,CrsCod,UsrCod,Role,"
DB_BuildQuery ("SELECT ReqCod,CrsCod,UsrCod,Role,"
"UNIX_TIMESTAMP(RequestTime)"
" FROM crs_usr_requests"
" WHERE CrsCod=%ld"
" AND ((1<<Role)&%u)<>0"
" ORDER BY RequestTime DESC",
Gbl.CurrentCrs.Crs.CrsCod,
RolesSelected) < 0)
Lay_NotEnoughMemoryExit ();
RolesSelected);
break;
default:
Lay_ShowErrorAndExit ("You don't have permission to list requesters.");
@ -2843,7 +2813,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
break;
}
NumRequests = (unsigned) DB_QuerySELECT_free (Query,&mysql_res,"can not get requests for enrolment");
NumRequests = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get requests for enrolment");
/***** List requests *****/
if (NumRequests)
@ -3037,11 +3007,10 @@ static void Enr_RemoveEnrolmentRequest (long CrsCod,long UsrCod)
/***** Mark possible notifications as removed
Important: do this before removing the request *****/
/* Request request code (returns 0 or 1 rows) */
if (asprintf (&Query,"SELECT ReqCod FROM crs_usr_requests"
DB_BuildQuery ("SELECT ReqCod FROM crs_usr_requests"
" WHERE CrsCod=%ld AND UsrCod=%ld",
CrsCod,UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
if (DB_QuerySELECT_free (Query,&mysql_res,"can not get request code")) // Request exists
CrsCod,UsrCod);
if (DB_QuerySELECT_new (&mysql_res,"can not get request code")) // Request exists
{
/* Get request code */
row = mysql_fetch_row (mysql_res);

View File

@ -755,7 +755,6 @@ static unsigned Sch_SearchDegreesInDB (const char *RangeQuery)
static unsigned Sch_SearchCoursesInDB (const char *RangeQuery)
{
char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1];
char *Query;
/***** Check user's permission *****/
if (Sch_CheckIfIHavePermissionToSearch (Sch_SEARCH_COURSES))
@ -763,7 +762,7 @@ static unsigned Sch_SearchCoursesInDB (const char *RangeQuery)
if (Sch_BuildSearchQuery (SearchQuery,"courses.FullName",NULL,NULL))
{
/***** Query database and list courses found *****/
if (asprintf (&Query,"SELECT degrees.DegCod,courses.CrsCod,degrees.ShortName,degrees.FullName,"
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"
@ -773,9 +772,8 @@ static unsigned Sch_SearchCoursesInDB (const char *RangeQuery)
" AND institutions.CtyCod=countries.CtyCod"
"%s"
" ORDER BY courses.FullName,institutions.FullName,degrees.FullName,courses.Year",
SearchQuery,RangeQuery) < 0)
Lay_NotEnoughMemoryExit ();
return Crs_ListCrssFound (Query);
SearchQuery,RangeQuery);
return Crs_ListCrssFound ();
}
return 0;