Version 18.11.1

This commit is contained in:
Antonio Cañas Vargas 2018-10-30 13:59:37 +01:00
parent f7b1f69fc3
commit c1559c1d52
7 changed files with 307 additions and 280 deletions

View File

@ -643,7 +643,8 @@ static void Att_GetListAttEvents (Att_OrderTime_t Order)
break; break;
} }
if (Gbl.CurrentCrs.Grps.WhichGrps == Grp_ONLY_MY_GROUPS) if (Gbl.CurrentCrs.Grps.WhichGrps == Grp_ONLY_MY_GROUPS)
DB_BuildQuery ("SELECT AttCod" NumRows = DB_QuerySELECT (&mysql_res,"can not get attendance events",
"SELECT AttCod"
" FROM att_events" " FROM att_events"
" WHERE CrsCod=%ld%s" " WHERE CrsCod=%ld%s"
" AND (AttCod NOT IN (SELECT AttCod FROM att_grp) OR" " AND (AttCod NOT IN (SELECT AttCod FROM att_grp) OR"
@ -654,12 +655,12 @@ static void Att_GetListAttEvents (Att_OrderTime_t Order)
Gbl.CurrentCrs.Crs.CrsCod,HiddenSubQuery, Gbl.CurrentCrs.Crs.CrsCod,HiddenSubQuery,
Gbl.Usrs.Me.UsrDat.UsrCod,OrderBySubQuery); Gbl.Usrs.Me.UsrDat.UsrCod,OrderBySubQuery);
else // Gbl.CurrentCrs.Grps.WhichGrps == Grp_ALL_GROUPS else // Gbl.CurrentCrs.Grps.WhichGrps == Grp_ALL_GROUPS
DB_BuildQuery ("SELECT AttCod" NumRows = DB_QuerySELECT (&mysql_res,"can not get attendance events",
"SELECT AttCod"
" FROM att_events" " FROM att_events"
" WHERE CrsCod=%ld%s" " WHERE CrsCod=%ld%s"
" ORDER BY %s", " ORDER BY %s",
Gbl.CurrentCrs.Crs.CrsCod,HiddenSubQuery,OrderBySubQuery); Gbl.CurrentCrs.Crs.CrsCod,HiddenSubQuery,OrderBySubQuery);
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get attendance events");
/* Free allocated memory for subqueries */ /* Free allocated memory for subqueries */
free ((void *) OrderBySubQuery); free ((void *) OrderBySubQuery);
@ -718,6 +719,7 @@ bool Att_GetDataOfAttEventByCod (struct AttendanceEvent *Att)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows;
bool Found = false; bool Found = false;
/***** Reset attendance event data *****/ /***** Reset attendance event data *****/
@ -726,7 +728,8 @@ bool Att_GetDataOfAttEventByCod (struct AttendanceEvent *Att)
if (Att->AttCod > 0) if (Att->AttCod > 0)
{ {
/***** Build query *****/ /***** Build query *****/
DB_BuildQuery ("SELECT AttCod,CrsCod,Hidden,UsrCod," NumRows = DB_QuerySELECT (&mysql_res,"can not get attendance event data",
"SELECT AttCod,CrsCod,Hidden,UsrCod,"
"UNIX_TIMESTAMP(StartTime)," "UNIX_TIMESTAMP(StartTime),"
"UNIX_TIMESTAMP(EndTime)," "UNIX_TIMESTAMP(EndTime),"
"NOW() BETWEEN StartTime AND EndTime," "NOW() BETWEEN StartTime AND EndTime,"
@ -737,7 +740,7 @@ bool Att_GetDataOfAttEventByCod (struct AttendanceEvent *Att)
Att->AttCod); Att->AttCod);
/***** Get data of attendance event from database *****/ /***** Get data of attendance event from database *****/
if ((Found = (DB_QuerySELECT_new (&mysql_res,"can not get attendance event data") != 0))) // Attendance event found... if ((Found = (NumRows != 0))) // Attendance event found...
{ {
/* Get row */ /* Get row */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -828,10 +831,10 @@ static void Att_GetAttEventTxtFromDB (long AttCod,char Txt[Cns_MAX_BYTES_TEXT +
unsigned long NumRows; unsigned long NumRows;
/***** Get text of attendance event from database *****/ /***** Get text of attendance event from database *****/
DB_BuildQuery ("SELECT Txt FROM att_events" NumRows = DB_QuerySELECT (&mysql_res,"can not get attendance event text",
"SELECT Txt FROM att_events"
" WHERE AttCod=%ld AND CrsCod=%ld", " WHERE AttCod=%ld AND CrsCod=%ld",
AttCod,Gbl.CurrentCrs.Crs.CrsCod); AttCod,Gbl.CurrentCrs.Crs.CrsCod);
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get attendance event text");
/***** The result of the query must have one row or none *****/ /***** The result of the query must have one row or none *****/
if (NumRows == 1) if (NumRows == 1)
@ -1507,14 +1510,14 @@ static void Att_GetAndWriteNamesOfGrpsAssociatedToAttEvent (struct AttendanceEve
unsigned NumGrps; unsigned NumGrps;
/***** Get groups associated to an attendance event from database *****/ /***** Get groups associated to an attendance event from database *****/
DB_BuildQuery ("SELECT crs_grp_types.GrpTypName,crs_grp.GrpName" NumGrps = (unsigned) DB_QuerySELECT (&mysql_res,"can not get groups of an attendance event",
"SELECT crs_grp_types.GrpTypName,crs_grp.GrpName"
" FROM att_grp,crs_grp,crs_grp_types" " FROM att_grp,crs_grp,crs_grp_types"
" WHERE att_grp.AttCod=%ld" " WHERE att_grp.AttCod=%ld"
" AND att_grp.GrpCod=crs_grp.GrpCod" " AND att_grp.GrpCod=crs_grp.GrpCod"
" AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod" " AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod"
" ORDER BY crs_grp_types.GrpTypName,crs_grp.GrpName", " ORDER BY crs_grp_types.GrpTypName,crs_grp.GrpName",
Att->AttCod); Att->AttCod);
NumGrps = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get groups of an attendance event");
/***** Write heading *****/ /***** Write heading *****/
fprintf (Gbl.F.Out,"<div class=\"%s\">%s: ", fprintf (Gbl.F.Out,"<div class=\"%s\">%s: ",
@ -1657,12 +1660,14 @@ unsigned Att_GetNumCoursesWithAttEvents (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 attendance events",
"SELECT COUNT(DISTINCT CrsCod)"
" FROM att_events" " FROM att_events"
" WHERE CrsCod>0"); " WHERE CrsCod>0");
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
DB_BuildQuery ("SELECT COUNT(DISTINCT att_events.CrsCod)" DB_QuerySELECT (&mysql_res,"can not get number of courses with attendance events",
"SELECT COUNT(DISTINCT att_events.CrsCod)"
" FROM centres,degrees,courses,att_events" " FROM centres,degrees,courses,att_events"
" WHERE centres.InsCod=%ld" " WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod" " AND centres.CtrCod=degrees.CtrCod"
@ -1672,7 +1677,8 @@ unsigned Att_GetNumCoursesWithAttEvents (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 att_events.CrsCod)" DB_QuerySELECT (&mysql_res,"can not get number of courses with attendance events",
"SELECT COUNT(DISTINCT att_events.CrsCod)"
" FROM degrees,courses,att_events" " FROM degrees,courses,att_events"
" WHERE degrees.CtrCod=%ld" " WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod" " AND degrees.DegCod=courses.DegCod"
@ -1681,7 +1687,8 @@ unsigned Att_GetNumCoursesWithAttEvents (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 att_events.CrsCod)" DB_QuerySELECT (&mysql_res,"can not get number of courses with attendance events",
"SELECT COUNT(DISTINCT att_events.CrsCod)"
" FROM courses,att_events" " FROM courses,att_events"
" WHERE courses.DegCod=%ld" " WHERE courses.DegCod=%ld"
" AND courses.Status=0" " AND courses.Status=0"
@ -1689,7 +1696,8 @@ unsigned Att_GetNumCoursesWithAttEvents (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 attendance events",
"SELECT COUNT(DISTINCT CrsCod)"
" FROM att_events" " FROM att_events"
" WHERE CrsCod=%ld", " WHERE CrsCod=%ld",
Gbl.CurrentCrs.Crs.CrsCod); Gbl.CurrentCrs.Crs.CrsCod);
@ -1698,7 +1706,6 @@ unsigned Att_GetNumCoursesWithAttEvents (Sco_Scope_t Scope)
Lay_WrongScopeExit (); Lay_WrongScopeExit ();
break; break;
} }
DB_QuerySELECT_new (&mysql_res,"can not get number of courses with attendance events");
/***** Get number of courses *****/ /***** Get number of courses *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1727,12 +1734,14 @@ unsigned Att_GetNumAttEvents (Sco_Scope_t Scope,unsigned *NumNotif)
switch (Scope) switch (Scope)
{ {
case Sco_SCOPE_SYS: case Sco_SCOPE_SYS:
DB_BuildQuery ("SELECT COUNT(*),SUM(NumNotif)" DB_QuerySELECT (&mysql_res,"can not get number of attendance events",
"SELECT COUNT(*),SUM(NumNotif)"
" FROM att_events" " FROM att_events"
" WHERE CrsCod>0"); " WHERE CrsCod>0");
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
DB_BuildQuery ("SELECT COUNT(*),SUM(att_events.NumNotif)" DB_QuerySELECT (&mysql_res,"can not get number of attendance events",
"SELECT COUNT(*),SUM(att_events.NumNotif)"
" FROM centres,degrees,courses,att_events" " FROM centres,degrees,courses,att_events"
" WHERE centres.InsCod=%ld" " WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod" " AND centres.CtrCod=degrees.CtrCod"
@ -1741,7 +1750,8 @@ unsigned Att_GetNumAttEvents (Sco_Scope_t Scope,unsigned *NumNotif)
Gbl.CurrentIns.Ins.InsCod); Gbl.CurrentIns.Ins.InsCod);
break; break;
case Sco_SCOPE_CTR: case Sco_SCOPE_CTR:
DB_BuildQuery ("SELECT COUNT(*),SUM(att_events.NumNotif)" DB_QuerySELECT (&mysql_res,"can not get number of attendance events",
"SELECT COUNT(*),SUM(att_events.NumNotif)"
" FROM degrees,courses,att_events" " FROM degrees,courses,att_events"
" WHERE degrees.CtrCod=%ld" " WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod" " AND degrees.DegCod=courses.DegCod"
@ -1749,14 +1759,16 @@ unsigned Att_GetNumAttEvents (Sco_Scope_t Scope,unsigned *NumNotif)
Gbl.CurrentCtr.Ctr.CtrCod); Gbl.CurrentCtr.Ctr.CtrCod);
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
DB_BuildQuery ("SELECT COUNT(*),SUM(att_events.NumNotif)" DB_QuerySELECT (&mysql_res,"can not get number of attendance events",
"SELECT COUNT(*),SUM(att_events.NumNotif)"
" FROM courses,att_events" " FROM courses,att_events"
" WHERE courses.DegCod=%ld" " WHERE courses.DegCod=%ld"
" AND courses.CrsCod=att_events.CrsCod", " AND courses.CrsCod=att_events.CrsCod",
Gbl.CurrentDeg.Deg.DegCod); Gbl.CurrentDeg.Deg.DegCod);
break; break;
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
DB_BuildQuery ("SELECT COUNT(*),SUM(NumNotif)" DB_QuerySELECT (&mysql_res,"can not get number of attendance events",
"SELECT COUNT(*),SUM(NumNotif)"
" FROM att_events" " FROM att_events"
" WHERE CrsCod=%ld", " WHERE CrsCod=%ld",
Gbl.CurrentCrs.Crs.CrsCod); Gbl.CurrentCrs.Crs.CrsCod);
@ -1765,7 +1777,6 @@ unsigned Att_GetNumAttEvents (Sco_Scope_t Scope,unsigned *NumNotif)
Lay_WrongScopeExit (); Lay_WrongScopeExit ();
break; break;
} }
DB_QuerySELECT_new (&mysql_res,"can not get number of attendance events");
/***** Get number of attendance events *****/ /***** Get number of attendance events *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -2177,12 +2188,10 @@ static void Att_PutParamsCodGrps (long AttCod)
/***** Get groups associated to an attendance event from database *****/ /***** Get groups associated to an attendance event from database *****/
if (Gbl.CurrentCrs.Grps.NumGrps) if (Gbl.CurrentCrs.Grps.NumGrps)
{ NumGrps = (unsigned) DB_QuerySELECT (&mysql_res,"can not get groups of an attendance event",
DB_BuildQuery ("SELECT GrpCod FROM att_grp" "SELECT GrpCod FROM att_grp"
" WHERE att_grp.AttCod=%ld", " WHERE att_grp.AttCod=%ld",
AttCod); AttCod);
NumGrps = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get groups of an attendance event");
}
else else
NumGrps = 0; NumGrps = 0;
@ -2465,14 +2474,17 @@ static bool Att_CheckIfUsrIsInTableAttUsr (long AttCod,long UsrCod,bool *Present
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned NumRows; unsigned long NumRows;
bool InDBTable; bool InDBTable;
/***** Check if a student is registered in an event in database *****/ /***** Check if a student is registered in an event in database *****/
DB_BuildQuery ("SELECT Present FROM att_usr" NumRows = DB_QuerySELECT (&mysql_res,"can not get if a student"
" is already registered"
" in an event",
"SELECT Present FROM att_usr"
" WHERE AttCod=%ld AND UsrCod=%ld", " WHERE AttCod=%ld AND UsrCod=%ld",
AttCod,UsrCod); AttCod,UsrCod);
if ((NumRows = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get if a student is already registered in an event"))) if (NumRows)
{ {
InDBTable = true; InDBTable = true;
@ -2517,14 +2529,18 @@ static bool Att_CheckIfUsrIsPresentInAttEventAndGetComments (long AttCod,long Us
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned NumRows; unsigned long NumRows;
bool Present; bool Present;
/***** Check if a students is registered in an event in database *****/ /***** Check if a students is registered in an event in database *****/
DB_BuildQuery ("SELECT Present,CommentStd,CommentTch FROM att_usr" NumRows = DB_QuerySELECT (&mysql_res,"can not get if a student"
" is already registered"
" in an event",
"SELECT Present,CommentStd,CommentTch"
" FROM att_usr"
" WHERE AttCod=%ld AND UsrCod=%ld", " WHERE AttCod=%ld AND UsrCod=%ld",
AttCod,UsrCod); AttCod,UsrCod);
if ((NumRows = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get if a student is already registered in an event"))) if (NumRows)
{ {
/* Get row */ /* Get row */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -2998,11 +3014,11 @@ static void Att_GetListSelectedAttCods (char **StrAttCodsSelected)
else // No students attended to this event else // No students attended to this event
{ {
/***** Get groups associated to an attendance event from database *****/ /***** Get groups associated to an attendance event from database *****/
DB_BuildQuery ("SELECT GrpCod FROM att_grp" NumGrpsInThisEvent = (unsigned) DB_QuerySELECT (&mysql_res,"can not get groups"
" of an attendance event",
"SELECT GrpCod FROM att_grp"
" WHERE att_grp.AttCod=%ld", " WHERE att_grp.AttCod=%ld",
Gbl.AttEvents.Lst[NumAttEvent].AttCod); Gbl.AttEvents.Lst[NumAttEvent].AttCod);
NumGrpsInThisEvent = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get groups of an attendance event");
if (NumGrpsInThisEvent) // This event is associated to groups if (NumGrpsInThisEvent) // This event is associated to groups
/* Get groups associated to this event */ /* Get groups associated to this event */
for (NumGrpInThisEvent = 0; for (NumGrpInThisEvent = 0;

View File

@ -65,7 +65,7 @@ extern struct Globals Gbl;
static void Ban_WriteListOfBanners (void); static void Ban_WriteListOfBanners (void);
static void Ban_PutFormToEditBanners (void); static void Ban_PutFormToEditBanners (void);
static void Ban_GetListBanners (void); static void Ban_GetListBanners (MYSQL_RES **mysql_res,unsigned long NumRows);
static void Ban_PutIconToViewBanners (void); static void Ban_PutIconToViewBanners (void);
static void Ban_ListBannersForEdition (void); static void Ban_ListBannersForEdition (void);
static void Ban_PutParamBanCod (long BanCod); static void Ban_PutParamBanCod (long BanCod);
@ -104,6 +104,8 @@ void Ban_SeeBanners (void)
extern const char *Txt_Banners; extern const char *Txt_Banners;
extern const char *Txt_No_banners; extern const char *Txt_No_banners;
extern const char *Txt_New_banner; extern const char *Txt_New_banner;
MYSQL_RES *mysql_res;
unsigned long NumRows;
/***** Put contextual links *****/ /***** Put contextual links *****/
fprintf (Gbl.F.Out,"<div class=\"CONTEXT_MENU\">"); fprintf (Gbl.F.Out,"<div class=\"CONTEXT_MENU\">");
@ -114,11 +116,12 @@ void Ban_SeeBanners (void)
fprintf (Gbl.F.Out,"</div>"); fprintf (Gbl.F.Out,"</div>");
/***** Get list of banners *****/ /***** Get list of banners *****/
DB_BuildQuery ("SELECT BanCod,Hidden,ShortName,FullName,Img,WWW" NumRows = DB_QuerySELECT (&mysql_res,"can not get banners",
"SELECT BanCod,Hidden,ShortName,FullName,Img,WWW"
" FROM banners" " FROM banners"
" WHERE Hidden='N'" " WHERE Hidden='N'"
" ORDER BY ShortName"); " ORDER BY ShortName");
Ban_GetListBanners (); Ban_GetListBanners (&mysql_res,NumRows);
/***** Start box *****/ /***** Start box *****/
Box_StartBox (NULL,Txt_Banners,Ban_PutFormToEditBanners, Box_StartBox (NULL,Txt_Banners,Ban_PutFormToEditBanners,
@ -197,6 +200,8 @@ void Ban_EditBanners (void)
{ {
extern const char *Hlp_SYSTEM_Banners_edit; extern const char *Hlp_SYSTEM_Banners_edit;
extern const char *Txt_Banners; extern const char *Txt_Banners;
MYSQL_RES *mysql_res;
unsigned long NumRows;
/***** Put contextual links *****/ /***** Put contextual links *****/
fprintf (Gbl.F.Out,"<div class=\"CONTEXT_MENU\">"); fprintf (Gbl.F.Out,"<div class=\"CONTEXT_MENU\">");
@ -207,9 +212,10 @@ void Ban_EditBanners (void)
fprintf (Gbl.F.Out,"</div>"); fprintf (Gbl.F.Out,"</div>");
/***** Get list of banners *****/ /***** Get list of banners *****/
DB_BuildQuery ("SELECT BanCod,Hidden,ShortName,FullName,Img,WWW" NumRows = DB_QuerySELECT (&mysql_res,"can not get banners",
"SELECT BanCod,Hidden,ShortName,FullName,Img,WWW"
" FROM banners ORDER BY ShortName"); " FROM banners ORDER BY ShortName");
Ban_GetListBanners (); Ban_GetListBanners (&mysql_res,NumRows);
/***** Start box *****/ /***** Start box *****/
Box_StartBox (NULL,Txt_Banners,Ban_PutIconToViewBanners, Box_StartBox (NULL,Txt_Banners,Ban_PutIconToViewBanners,
@ -233,25 +239,20 @@ void Ban_EditBanners (void)
/**************************** List all the banners ***************************/ /**************************** List all the banners ***************************/
/*****************************************************************************/ /*****************************************************************************/
static void Ban_GetListBanners (void) static void Ban_GetListBanners (MYSQL_RES **mysql_res,unsigned long NumRows)
{ {
MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows;
unsigned NumBan; unsigned NumBan;
struct Banner *Ban; struct Banner *Ban;
if (Gbl.DB.DatabaseIsOpen)
{
/***** Get banners from database *****/ /***** Get banners from database *****/
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get banners");
if (NumRows) // Banners found... if (NumRows) // Banners found...
{ {
Gbl.Banners.Num = (unsigned) NumRows; Gbl.Banners.Num = (unsigned) NumRows;
/***** Create list with banners *****/ /***** Create list with banners *****/
if ((Gbl.Banners.Lst = (struct Banner *) calloc (NumRows,sizeof (struct Banner))) == NULL) if ((Gbl.Banners.Lst = (struct Banner *)
calloc (NumRows,sizeof (struct Banner))) == NULL)
Lay_NotEnoughMemoryExit (); Lay_NotEnoughMemoryExit ();
/***** Get the banners *****/ /***** Get the banners *****/
@ -262,7 +263,7 @@ static void Ban_GetListBanners (void)
Ban = &(Gbl.Banners.Lst[NumBan]); Ban = &(Gbl.Banners.Lst[NumBan]);
/* Get next banner */ /* Get next banner */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (*mysql_res);
/* Get banner code (row[0]) */ /* Get banner code (row[0]) */
if ((Ban->BanCod = Str_ConvertStrCodToLongCod (row[0])) < 0) if ((Ban->BanCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
@ -292,8 +293,7 @@ static void Ban_GetListBanners (void)
Gbl.Banners.Num = 0; Gbl.Banners.Num = 0;
/***** Free structure that stores the query result *****/ /***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res); DB_FreeMySQLResult (mysql_res);
}
} }
/*****************************************************************************/ /*****************************************************************************/
@ -314,11 +314,10 @@ void Ban_GetDataOfBannerByCod (struct Banner *Ban)
if (Ban->BanCod > 0) if (Ban->BanCod > 0)
{ {
/***** Get data of a banner from database *****/ /***** Get data of a banner from database *****/
DB_BuildQuery ("SELECT Hidden,ShortName,FullName,Img,WWW" NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a banner",
"SELECT Hidden,ShortName,FullName,Img,WWW"
" FROM banners WHERE BanCod=%ld", " FROM banners WHERE BanCod=%ld",
Ban->BanCod); Ban->BanCod);
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get data of a banner");
if (NumRows) // Banner found... if (NumRows) // Banner found...
{ {
/* Get row */ /* Get row */
@ -1007,17 +1006,20 @@ static void Ban_CreateBanner (struct Banner *Ban)
void Ban_WriteMenuWithBanners (void) void Ban_WriteMenuWithBanners (void)
{ {
MYSQL_RES *mysql_res;
unsigned long NumRows;
unsigned NumBan; unsigned NumBan;
/***** Get random banner *****/ /***** Get random banner *****/
// The banner(s) will change once in a while // The banner(s) will change once in a while
DB_BuildQuery ("SELECT BanCod,Hidden,ShortName,FullName,Img,WWW" NumRows = DB_QuerySELECT (&mysql_res,"can not get banners",
"SELECT BanCod,Hidden,ShortName,FullName,Img,WWW"
" FROM banners" " FROM banners"
" WHERE Hidden='N'" " WHERE Hidden='N'"
" ORDER BY RAND(%lu) LIMIT %u", " ORDER BY RAND(%lu) LIMIT %u",
(unsigned long) (Gbl.StartExecutionTimeUTC / Cfg_TIME_TO_CHANGE_BANNER), (unsigned long) (Gbl.StartExecutionTimeUTC / Cfg_TIME_TO_CHANGE_BANNER),
Cfg_NUMBER_OF_BANNERS); Cfg_NUMBER_OF_BANNERS);
Ban_GetListBanners (); Ban_GetListBanners (&mysql_res,NumRows);
/***** Write all the banners *****/ /***** Write all the banners *****/
for (NumBan = 0; for (NumBan = 0;

View File

@ -144,17 +144,22 @@ void Ctr_SeeCtrWithPendingDegs (void)
switch (Gbl.Usrs.Me.Role.Logged) switch (Gbl.Usrs.Me.Role.Logged)
{ {
case Rol_CTR_ADM: case Rol_CTR_ADM:
DB_BuildQuery ("SELECT degrees.CtrCod,COUNT(*)" NumCtrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get centres"
" with pending degrees",
"SELECT degrees.CtrCod,COUNT(*)"
" FROM degrees,ctr_admin,centres" " FROM degrees,ctr_admin,centres"
" WHERE (degrees.Status & %u)<>0" " WHERE (degrees.Status & %u)<>0"
" AND degrees.CtrCod=ctr_admin.CtrCod" " AND degrees.CtrCod=ctr_admin.CtrCod"
" AND ctr_admin.UsrCod=%ld" " AND ctr_admin.UsrCod=%ld"
" AND degrees.CtrCod=centres.CtrCod" " AND degrees.CtrCod=centres.CtrCod"
" GROUP BY degrees.CtrCod ORDER BY centres.ShortName", " GROUP BY degrees.CtrCod ORDER BY centres.ShortName",
(unsigned) Deg_STATUS_BIT_PENDING,Gbl.Usrs.Me.UsrDat.UsrCod); (unsigned) Deg_STATUS_BIT_PENDING,
Gbl.Usrs.Me.UsrDat.UsrCod);
break; break;
case Rol_SYS_ADM: case Rol_SYS_ADM:
DB_BuildQuery ("SELECT degrees.CtrCod,COUNT(*)" NumCtrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get centres"
" with pending degrees",
"SELECT degrees.CtrCod,COUNT(*)"
" FROM degrees,centres" " FROM degrees,centres"
" WHERE (degrees.Status & %u)<>0" " WHERE (degrees.Status & %u)<>0"
" AND degrees.CtrCod=centres.CtrCod" " AND degrees.CtrCod=centres.CtrCod"
@ -164,9 +169,7 @@ void Ctr_SeeCtrWithPendingDegs (void)
default: // Forbidden for other users default: // Forbidden for other users
return; return;
} }
if (NumCtrs)
/***** Get centres *****/
if ((NumCtrs = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get centres with pending degrees")))
{ {
/***** Start box and table *****/ /***** Start box and table *****/
Box_StartBoxTable (NULL,Txt_Centres_with_pending_degrees,NULL, Box_StartBoxTable (NULL,Txt_Centres_with_pending_degrees,NULL,
@ -1052,7 +1055,8 @@ void Ctr_GetListCentres (long InsCod)
Lay_NotEnoughMemoryExit (); Lay_NotEnoughMemoryExit ();
break; break;
} }
DB_BuildQuery ("(SELECT centres.CtrCod,centres.InsCod,centres.PlcCod," NumRows = DB_QuerySELECT (&mysql_res,"can not get centres",
"(SELECT centres.CtrCod,centres.InsCod,centres.PlcCod,"
"centres.Status,centres.RequesterUsrCod," "centres.Status,centres.RequesterUsrCod,"
"centres.ShortName,centres.FullName,centres.WWW," "centres.ShortName,centres.FullName,centres.WWW,"
"COUNT(DISTINCT usr_data.UsrCod) AS NumUsrs" "COUNT(DISTINCT usr_data.UsrCod) AS NumUsrs"
@ -1071,7 +1075,6 @@ void Ctr_GetListCentres (long InsCod)
InsCod, InsCod,
InsCod, InsCod,
OrderBySubQuery); OrderBySubQuery);
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get centres");
free ((void *) OrderBySubQuery); free ((void *) OrderBySubQuery);
if (NumRows) // Centres found... if (NumRows) // Centres found...
@ -1151,6 +1154,7 @@ bool Ctr_GetDataOfCentreByCod (struct Centre *Ctr)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows;
bool CtrFound = false; bool CtrFound = false;
/***** Clear data *****/ /***** Clear data *****/
@ -1170,7 +1174,8 @@ bool Ctr_GetDataOfCentreByCod (struct Centre *Ctr)
if (Ctr->CtrCod > 0) if (Ctr->CtrCod > 0)
{ {
/***** Get data of a centre from database *****/ /***** Get data of a centre from database *****/
DB_BuildQuery ("(SELECT centres.InsCod,centres.PlcCod," NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a centre",
"(SELECT centres.InsCod,centres.PlcCod,"
"centres.Status,centres.RequesterUsrCod," "centres.Status,centres.RequesterUsrCod,"
"centres.ShortName,centres.FullName,centres.WWW," "centres.ShortName,centres.FullName,centres.WWW,"
"COUNT(DISTINCT usr_data.UsrCod) AS NumUsrs" "COUNT(DISTINCT usr_data.UsrCod) AS NumUsrs"
@ -1189,7 +1194,7 @@ bool Ctr_GetDataOfCentreByCod (struct Centre *Ctr)
" (SELECT DISTINCT CtrCod FROM usr_data))", " (SELECT DISTINCT CtrCod FROM usr_data))",
Ctr->CtrCod, Ctr->CtrCod,
Ctr->CtrCod); Ctr->CtrCod);
if (DB_QuerySELECT_new (&mysql_res,"can not get data of a centre")) // Centre found... if (NumRows) // Centre found...
{ {
/* Get row */ /* Get row */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1256,9 +1261,9 @@ long Ctr_GetInsCodOfCentreByCod (long CtrCod)
if (CtrCod > 0) if (CtrCod > 0)
{ {
/***** Get the institution code of a centre from database *****/ /***** Get the institution code of a centre from database *****/
DB_BuildQuery ("SELECT InsCod FROM centres WHERE CtrCod=%ld", if (DB_QuerySELECT (&mysql_res,"can not get the institution of a centre",
CtrCod); "SELECT InsCod FROM centres WHERE CtrCod=%ld",
if (DB_QuerySELECT_new (&mysql_res,"can not get the institution of a centre") == 1) CtrCod) == 1)
{ {
/***** Get the institution code of this centre *****/ /***** Get the institution code of this centre *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1285,10 +1290,10 @@ void Ctr_GetShortNameOfCentreByCod (struct Centre *Ctr)
if (Ctr->CtrCod > 0) if (Ctr->CtrCod > 0)
{ {
/***** Get the short name of a centre from database *****/ /***** Get the short name of a centre from database *****/
DB_BuildQuery ("SELECT ShortName FROM centres" if (DB_QuerySELECT (&mysql_res,"can not get the short name of a centre",
"SELECT ShortName FROM centres"
" WHERE CtrCod=%ld", " WHERE CtrCod=%ld",
Ctr->CtrCod); Ctr->CtrCod) == 1)
if (DB_QuerySELECT_new (&mysql_res,"can not get the short name of a centre") == 1)
{ {
/***** Get the short name of this centre *****/ /***** Get the short name of this centre *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1316,10 +1321,10 @@ static void Ctr_GetPhotoAttribution (long CtrCod,char **PhotoAttribution)
Ctr_FreePhotoAttribution (PhotoAttribution); Ctr_FreePhotoAttribution (PhotoAttribution);
/***** Get photo attribution from database *****/ /***** Get photo attribution from database *****/
DB_BuildQuery ("SELECT PhotoAttribution" if (DB_QuerySELECT (&mysql_res,"can not get photo attribution",
"SELECT PhotoAttribution"
" FROM centres WHERE CtrCod=%ld", " FROM centres WHERE CtrCod=%ld",
CtrCod); CtrCod))
if (DB_QuerySELECT_new (&mysql_res,"can not get photo attribution"))
{ {
/* Get row */ /* Get row */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1398,12 +1403,12 @@ void Ctr_WriteSelectorOfCentre (void)
if (Gbl.CurrentIns.Ins.InsCod > 0) if (Gbl.CurrentIns.Ins.InsCod > 0)
{ {
/***** Get centres from database *****/ /***** Get centres from database *****/
DB_BuildQuery ("SELECT DISTINCT CtrCod,ShortName" NumCtrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get centres",
"SELECT DISTINCT CtrCod,ShortName"
" FROM centres" " FROM centres"
" WHERE InsCod=%ld" " WHERE InsCod=%ld"
" ORDER BY ShortName", " ORDER BY ShortName",
Gbl.CurrentIns.Ins.InsCod); Gbl.CurrentIns.Ins.InsCod);
NumCtrs = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get centres");
/***** Get centres *****/ /***** Get centres *****/
for (NumCtr = 0; for (NumCtr = 0;
@ -2935,20 +2940,17 @@ unsigned Ctr_GetNumCtrsWithUsrs (Rol_Role_t Role,const char *SubQuery)
/*****************************************************************************/ /*****************************************************************************/
/****************************** List centres found ***************************/ /****************************** List centres found ***************************/
/*****************************************************************************/ /*****************************************************************************/
// Returns number of centres found
unsigned Ctr_ListCtrsFound (void) void Ctr_ListCtrsFound (MYSQL_RES **mysql_res,unsigned NumCtrs)
{ {
extern const char *Txt_centre; extern const char *Txt_centre;
extern const char *Txt_centres; extern const char *Txt_centres;
MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned NumCtrs;
unsigned NumCtr; unsigned NumCtr;
struct Centre Ctr; struct Centre Ctr;
/***** Query database *****/ /***** Query database *****/
if ((NumCtrs = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get centres"))) if (NumCtrs)
{ {
/***** Start box and table *****/ /***** Start box and table *****/
/* Number of centres found */ /* Number of centres found */
@ -2968,7 +2970,7 @@ unsigned Ctr_ListCtrsFound (void)
NumCtr++) NumCtr++)
{ {
/* Get next centre */ /* Get next centre */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (*mysql_res);
/* Get centre code (row[0]) */ /* Get centre code (row[0]) */
Ctr.CtrCod = Str_ConvertStrCodToLongCod (row[0]); Ctr.CtrCod = Str_ConvertStrCodToLongCod (row[0]);
@ -2985,7 +2987,5 @@ unsigned Ctr_ListCtrsFound (void)
} }
/***** Free structure that stores the query result *****/ /***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res); DB_FreeMySQLResult (mysql_res);
return NumCtrs;
} }

View File

@ -27,6 +27,8 @@
/********************************* Headers ***********************************/ /********************************* Headers ***********************************/
/*****************************************************************************/ /*****************************************************************************/
#include <mysql/mysql.h> // To access MySQL databases
#include "swad_action.h" #include "swad_action.h"
#include "swad_constant.h" #include "swad_constant.h"
#include "swad_degree.h" #include "swad_degree.h"
@ -134,6 +136,6 @@ unsigned Ctr_GetNumCtrsWithDegs (const char *SubQuery);
unsigned Ctr_GetNumCtrsWithCrss (const char *SubQuery); unsigned Ctr_GetNumCtrsWithCrss (const char *SubQuery);
unsigned Ctr_GetNumCtrsWithUsrs (Rol_Role_t Role,const char *SubQuery); unsigned Ctr_GetNumCtrsWithUsrs (Rol_Role_t Role,const char *SubQuery);
unsigned Ctr_ListCtrsFound (void); void Ctr_ListCtrsFound (MYSQL_RES **mysql_res,unsigned NumCtrs);
#endif #endif

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 (2018-10-30)" #define Log_PLATFORM_VERSION "SWAD 18.11.1 (2018-10-30)"
#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.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.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) Version 18.10.2: Oct 30, 2018 Fixed bugs in access to database. (235414 lines)
Version 18.10.1: Oct 30, 2018 Fixed bugs in access to database. (235399 lines) Version 18.10.1: Oct 30, 2018 Fixed bugs in access to database. (235399 lines)

View File

@ -273,10 +273,11 @@ void Cht_ShowListOfChatRoomsWithUsrs (void)
unsigned long NumRow,NumRows; unsigned long NumRow,NumRows;
/***** Get chat rooms with connected users from database *****/ /***** Get chat rooms with connected users from database *****/
DB_BuildQuery ("SELECT RoomCode,NumUsrs FROM chat" NumRows = DB_QuerySELECT (&mysql_res,"can not get chat rooms"
" WHERE NumUsrs>0 ORDER BY NumUsrs DESC,RoomCode"); " with connected users",
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get chat rooms with connected users"); "SELECT RoomCode,NumUsrs FROM chat"
" WHERE NumUsrs>0"
" ORDER BY NumUsrs DESC,RoomCode");
if (NumRows > 0) // If not empty chat rooms found if (NumRows > 0) // If not empty chat rooms found
{ {
/***** Start box and table *****/ /***** Start box and table *****/
@ -381,9 +382,10 @@ static unsigned Cht_GetNumUsrsInChatRoom (const char *RoomCode)
unsigned NumUsrs = 0; unsigned NumUsrs = 0;
/***** Get number of users connected to chat rooms from database *****/ /***** Get number of users connected to chat rooms from database *****/
DB_BuildQuery ("SELECT NumUsrs FROM chat WHERE RoomCode='%s'", if (DB_QuerySELECT (&mysql_res,"can not get number of users"
RoomCode); " connected to a chat room",
if (DB_QuerySELECT_new (&mysql_res,"can not get number of users connected to a chat room")) "SELECT NumUsrs FROM chat WHERE RoomCode='%s'",
RoomCode))
{ {
/* Get number of users connected to the chat room */ /* Get number of users connected to the chat room */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);

View File

@ -688,6 +688,8 @@ static unsigned Sch_SearchInstitutionsInDB (const char *RangeQuery)
static unsigned Sch_SearchCentresInDB (const char *RangeQuery) static unsigned Sch_SearchCentresInDB (const char *RangeQuery)
{ {
char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1]; char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1];
MYSQL_RES *mysql_res;
unsigned NumCtrs;
/***** Check scope *****/ /***** Check scope *****/
if (Gbl.Scope.Current != Sco_SCOPE_DEG && if (Gbl.Scope.Current != Sco_SCOPE_DEG &&
@ -698,7 +700,8 @@ static unsigned Sch_SearchCentresInDB (const char *RangeQuery)
if (Sch_BuildSearchQuery (SearchQuery,"centres.FullName",NULL,NULL)) if (Sch_BuildSearchQuery (SearchQuery,"centres.FullName",NULL,NULL))
{ {
/***** Query database and list centres found *****/ /***** Query database and list centres found *****/
DB_BuildQuery ("SELECT centres.CtrCod" NumCtrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get centres",
"SELECT centres.CtrCod"
" FROM centres,institutions,countries" " FROM centres,institutions,countries"
" WHERE %s" " WHERE %s"
" AND centres.InsCod=institutions.InsCod" " AND centres.InsCod=institutions.InsCod"
@ -706,7 +709,8 @@ static unsigned Sch_SearchCentresInDB (const char *RangeQuery)
"%s" "%s"
" ORDER BY centres.FullName,institutions.FullName", " ORDER BY centres.FullName,institutions.FullName",
SearchQuery,RangeQuery); SearchQuery,RangeQuery);
return Ctr_ListCtrsFound (); Ctr_ListCtrsFound (&mysql_res,NumCtrs);
return NumCtrs;
} }
return 0; return 0;