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,23 +643,24 @@ 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",
" FROM att_events" "SELECT AttCod"
" WHERE CrsCod=%ld%s" " FROM att_events"
" AND (AttCod NOT IN (SELECT AttCod FROM att_grp) OR" " WHERE CrsCod=%ld%s"
" AttCod IN (SELECT att_grp.AttCod FROM att_grp,crs_grp_usr" " AND (AttCod NOT IN (SELECT AttCod FROM att_grp) OR"
" WHERE crs_grp_usr.UsrCod=%ld" " AttCod IN (SELECT att_grp.AttCod FROM att_grp,crs_grp_usr"
" AND att_grp.GrpCod=crs_grp_usr.GrpCod))" " WHERE crs_grp_usr.UsrCod=%ld"
" ORDER BY %s", " AND att_grp.GrpCod=crs_grp_usr.GrpCod))"
Gbl.CurrentCrs.Crs.CrsCod,HiddenSubQuery, " ORDER BY %s",
Gbl.Usrs.Me.UsrDat.UsrCod,OrderBySubQuery); Gbl.CurrentCrs.Crs.CrsCod,HiddenSubQuery,
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",
" FROM att_events" "SELECT AttCod"
" WHERE CrsCod=%ld%s" " FROM att_events"
" ORDER BY %s", " WHERE CrsCod=%ld%s"
Gbl.CurrentCrs.Crs.CrsCod,HiddenSubQuery,OrderBySubQuery); " ORDER BY %s",
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get attendance events"); Gbl.CurrentCrs.Crs.CrsCod,HiddenSubQuery,OrderBySubQuery);
/* 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,18 +728,19 @@ 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",
"UNIX_TIMESTAMP(StartTime)," "SELECT AttCod,CrsCod,Hidden,UsrCod,"
"UNIX_TIMESTAMP(EndTime)," "UNIX_TIMESTAMP(StartTime),"
"NOW() BETWEEN StartTime AND EndTime," "UNIX_TIMESTAMP(EndTime),"
"CommentTchVisible," "NOW() BETWEEN StartTime AND EndTime,"
"Title" "CommentTchVisible,"
" FROM att_events" "Title"
" WHERE AttCod=%ld", " FROM att_events"
Att->AttCod); " WHERE AttCod=%ld",
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",
" WHERE AttCod=%ld AND CrsCod=%ld", "SELECT Txt FROM att_events"
AttCod,Gbl.CurrentCrs.Crs.CrsCod); " WHERE AttCod=%ld AND CrsCod=%ld",
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get attendance event text"); AttCod,Gbl.CurrentCrs.Crs.CrsCod);
/***** 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",
" FROM att_grp,crs_grp,crs_grp_types" "SELECT crs_grp_types.GrpTypName,crs_grp.GrpName"
" WHERE att_grp.AttCod=%ld" " FROM att_grp,crs_grp,crs_grp_types"
" AND att_grp.GrpCod=crs_grp.GrpCod" " WHERE att_grp.AttCod=%ld"
" AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod" " AND att_grp.GrpCod=crs_grp.GrpCod"
" ORDER BY crs_grp_types.GrpTypName,crs_grp.GrpName", " AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod"
Att->AttCod); " ORDER BY crs_grp_types.GrpTypName,crs_grp.GrpName",
NumGrps = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get groups of an attendance event"); Att->AttCod);
/***** Write heading *****/ /***** Write heading *****/
fprintf (Gbl.F.Out,"<div class=\"%s\">%s: ", fprintf (Gbl.F.Out,"<div class=\"%s\">%s: ",
@ -1657,48 +1660,52 @@ 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",
" FROM att_events" "SELECT COUNT(DISTINCT CrsCod)"
" WHERE CrsCod>0"); " FROM att_events"
" 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",
" FROM centres,degrees,courses,att_events" "SELECT COUNT(DISTINCT att_events.CrsCod)"
" WHERE centres.InsCod=%ld" " FROM centres,degrees,courses,att_events"
" AND centres.CtrCod=degrees.CtrCod" " WHERE centres.InsCod=%ld"
" AND degrees.DegCod=courses.DegCod" " AND centres.CtrCod=degrees.CtrCod"
" AND courses.Status=0" " AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=att_events.CrsCod", " AND courses.Status=0"
Gbl.CurrentIns.Ins.InsCod); " AND courses.CrsCod=att_events.CrsCod",
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",
" FROM degrees,courses,att_events" "SELECT COUNT(DISTINCT att_events.CrsCod)"
" WHERE degrees.CtrCod=%ld" " FROM degrees,courses,att_events"
" AND degrees.DegCod=courses.DegCod" " WHERE degrees.CtrCod=%ld"
" AND courses.Status=0" " AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=att_events.CrsCod", " AND courses.Status=0"
Gbl.CurrentCtr.Ctr.CtrCod); " AND courses.CrsCod=att_events.CrsCod",
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",
" FROM courses,att_events" "SELECT COUNT(DISTINCT att_events.CrsCod)"
" WHERE courses.DegCod=%ld" " FROM courses,att_events"
" AND courses.Status=0" " WHERE courses.DegCod=%ld"
" AND courses.CrsCod=att_events.CrsCod", " AND courses.Status=0"
Gbl.CurrentDeg.Deg.DegCod); " AND courses.CrsCod=att_events.CrsCod",
Gbl.CurrentDeg.Deg.DegCod);
break; break;
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
DB_BuildQuery ("SELECT COUNT(DISTINCT CrsCod)" DB_QuerySELECT (&mysql_res,"can not get number of courses with attendance events",
" FROM att_events" "SELECT COUNT(DISTINCT CrsCod)"
" WHERE CrsCod=%ld", " FROM att_events"
Gbl.CurrentCrs.Crs.CrsCod); " WHERE CrsCod=%ld",
Gbl.CurrentCrs.Crs.CrsCod);
break; break;
default: default:
Lay_WrongScopeExit (); Lay_WrongScopeExit ();
break; break;
} }
DB_QuerySELECT_new (&mysql_res,"can not get number of courses with attendance events");
/***** Get number of courses *****/ /***** Get number of courses *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1727,45 +1734,49 @@ 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",
" FROM att_events" "SELECT COUNT(*),SUM(NumNotif)"
" WHERE CrsCod>0"); " FROM att_events"
" 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",
" FROM centres,degrees,courses,att_events" "SELECT COUNT(*),SUM(att_events.NumNotif)"
" WHERE centres.InsCod=%ld" " FROM centres,degrees,courses,att_events"
" AND centres.CtrCod=degrees.CtrCod" " WHERE centres.InsCod=%ld"
" AND degrees.DegCod=courses.DegCod" " AND centres.CtrCod=degrees.CtrCod"
" AND courses.CrsCod=att_events.CrsCod", " AND degrees.DegCod=courses.DegCod"
Gbl.CurrentIns.Ins.InsCod); " AND courses.CrsCod=att_events.CrsCod",
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",
" FROM degrees,courses,att_events" "SELECT COUNT(*),SUM(att_events.NumNotif)"
" WHERE degrees.CtrCod=%ld" " FROM degrees,courses,att_events"
" AND degrees.DegCod=courses.DegCod" " WHERE degrees.CtrCod=%ld"
" AND courses.CrsCod=att_events.CrsCod", " AND degrees.DegCod=courses.DegCod"
Gbl.CurrentCtr.Ctr.CtrCod); " AND courses.CrsCod=att_events.CrsCod",
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",
" FROM courses,att_events" "SELECT COUNT(*),SUM(att_events.NumNotif)"
" WHERE courses.DegCod=%ld" " FROM courses,att_events"
" AND courses.CrsCod=att_events.CrsCod", " WHERE courses.DegCod=%ld"
Gbl.CurrentDeg.Deg.DegCod); " AND courses.CrsCod=att_events.CrsCod",
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",
" FROM att_events" "SELECT COUNT(*),SUM(NumNotif)"
" WHERE CrsCod=%ld", " FROM att_events"
Gbl.CurrentCrs.Crs.CrsCod); " WHERE CrsCod=%ld",
Gbl.CurrentCrs.Crs.CrsCod);
break; break;
default: default:
Lay_WrongScopeExit (); Lay_WrongScopeExit ();
break; break;
} }
DB_QuerySELECT_new (&mysql_res,"can not get number of 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"
" WHERE AttCod=%ld AND UsrCod=%ld", " is already registered"
AttCod,UsrCod); " in an event",
if ((NumRows = (unsigned) DB_QuerySELECT_new (&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",
AttCod,UsrCod);
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"
" WHERE AttCod=%ld AND UsrCod=%ld", " is already registered"
AttCod,UsrCod); " in an event",
if ((NumRows = (unsigned) DB_QuerySELECT_new (&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",
AttCod,UsrCod);
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"
" WHERE att_grp.AttCod=%ld", " of an attendance event",
Gbl.AttEvents.Lst[NumAttEvent].AttCod); "SELECT GrpCod FROM att_grp"
NumGrpsInThisEvent = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get groups of an attendance event"); " WHERE att_grp.AttCod=%ld",
Gbl.AttEvents.Lst[NumAttEvent].AttCod);
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",
" FROM banners" "SELECT BanCod,Hidden,ShortName,FullName,Img,WWW"
" WHERE Hidden='N'" " FROM banners"
" ORDER BY ShortName"); " WHERE Hidden='N'"
Ban_GetListBanners (); " ORDER BY ShortName");
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",
" FROM banners ORDER BY ShortName"); "SELECT BanCod,Hidden,ShortName,FullName,Img,WWW"
Ban_GetListBanners (); " FROM banners ORDER BY ShortName");
Ban_GetListBanners (&mysql_res,NumRows);
/***** Start box *****/ /***** Start box *****/
Box_StartBox (NULL,Txt_Banners,Ban_PutIconToViewBanners, Box_StartBox (NULL,Txt_Banners,Ban_PutIconToViewBanners,
@ -233,67 +239,61 @@ 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 *****/
if (NumRows) // Banners found...
{ {
/***** Get banners from database *****/ Gbl.Banners.Num = (unsigned) NumRows;
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get banners");
if (NumRows) // Banners found... /***** Create list with banners *****/
if ((Gbl.Banners.Lst = (struct Banner *)
calloc (NumRows,sizeof (struct Banner))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the banners *****/
for (NumBan = 0;
NumBan < Gbl.Banners.Num;
NumBan++)
{ {
Gbl.Banners.Num = (unsigned) NumRows; Ban = &(Gbl.Banners.Lst[NumBan]);
/***** Create list with banners *****/ /* Get next banner */
if ((Gbl.Banners.Lst = (struct Banner *) calloc (NumRows,sizeof (struct Banner))) == NULL) row = mysql_fetch_row (*mysql_res);
Lay_NotEnoughMemoryExit ();
/***** Get the banners *****/ /* Get banner code (row[0]) */
for (NumBan = 0; if ((Ban->BanCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
NumBan < Gbl.Banners.Num; Lay_ShowErrorAndExit ("Wrong code of banner.");
NumBan++)
{
Ban = &(Gbl.Banners.Lst[NumBan]);
/* Get next banner */ /* Get if banner is hidden (row[1]) */
row = mysql_fetch_row (mysql_res); Ban->Hidden = (row[1][0] == 'Y');
/* Get banner code (row[0]) */ /* Get the short name of the banner (row[2]) */
if ((Ban->BanCod = Str_ConvertStrCodToLongCod (row[0])) < 0) Str_Copy (Ban->ShrtName,row[2],
Lay_ShowErrorAndExit ("Wrong code of banner."); Ban_MAX_BYTES_SHRT_NAME);
/* Get if banner is hidden (row[1]) */ /* Get the full name of the banner (row[3]) */
Ban->Hidden = (row[1][0] == 'Y'); Str_Copy (Ban->FullName,row[3],
Ban_MAX_BYTES_FULL_NAME);
/* Get the short name of the banner (row[2]) */ /* Get the image of the banner (row[4]) */
Str_Copy (Ban->ShrtName,row[2], Str_Copy (Ban->Img,row[4],
Ban_MAX_BYTES_SHRT_NAME); Ban_MAX_BYTES_IMAGE);
/* Get the full name of the banner (row[3]) */ /* Get the URL of the banner (row[5]) */
Str_Copy (Ban->FullName,row[3], Str_Copy (Ban->WWW,row[5],
Ban_MAX_BYTES_FULL_NAME); Cns_MAX_BYTES_WWW);
/* Get the image of the banner (row[4]) */
Str_Copy (Ban->Img,row[4],
Ban_MAX_BYTES_IMAGE);
/* Get the URL of the banner (row[5]) */
Str_Copy (Ban->WWW,row[5],
Cns_MAX_BYTES_WWW);
}
} }
else
Gbl.Banners.Num = 0;
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
} }
else
Gbl.Banners.Num = 0;
/***** Free structure that stores the query result *****/
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",
" FROM banners WHERE BanCod=%ld", "SELECT Hidden,ShortName,FullName,Img,WWW"
Ban->BanCod); " FROM banners WHERE BanCod=%ld",
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get data of a banner"); Ban->BanCod);
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",
" FROM banners" "SELECT BanCod,Hidden,ShortName,FullName,Img,WWW"
" WHERE Hidden='N'" " FROM banners"
" ORDER BY RAND(%lu) LIMIT %u", " WHERE Hidden='N'"
(unsigned long) (Gbl.StartExecutionTimeUTC / Cfg_TIME_TO_CHANGE_BANNER), " ORDER BY RAND(%lu) LIMIT %u",
Cfg_NUMBER_OF_BANNERS); (unsigned long) (Gbl.StartExecutionTimeUTC / Cfg_TIME_TO_CHANGE_BANNER),
Ban_GetListBanners (); Cfg_NUMBER_OF_BANNERS);
Ban_GetListBanners (&mysql_res,NumRows);
/***** Write all the banners *****/ /***** Write all the banners *****/
for (NumBan = 0; for (NumBan = 0;

View File

@ -144,29 +144,32 @@ 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"
" FROM degrees,ctr_admin,centres" " with pending degrees",
" WHERE (degrees.Status & %u)<>0" "SELECT degrees.CtrCod,COUNT(*)"
" AND degrees.CtrCod=ctr_admin.CtrCod" " FROM degrees,ctr_admin,centres"
" AND ctr_admin.UsrCod=%ld" " WHERE (degrees.Status & %u)<>0"
" AND degrees.CtrCod=centres.CtrCod" " AND degrees.CtrCod=ctr_admin.CtrCod"
" GROUP BY degrees.CtrCod ORDER BY centres.ShortName", " AND ctr_admin.UsrCod=%ld"
(unsigned) Deg_STATUS_BIT_PENDING,Gbl.Usrs.Me.UsrDat.UsrCod); " AND degrees.CtrCod=centres.CtrCod"
" GROUP BY degrees.CtrCod ORDER BY centres.ShortName",
(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"
" FROM degrees,centres" " with pending degrees",
" WHERE (degrees.Status & %u)<>0" "SELECT degrees.CtrCod,COUNT(*)"
" AND degrees.CtrCod=centres.CtrCod" " FROM degrees,centres"
" GROUP BY degrees.CtrCod ORDER BY centres.ShortName", " WHERE (degrees.Status & %u)<>0"
(unsigned) Deg_STATUS_BIT_PENDING); " AND degrees.CtrCod=centres.CtrCod"
" GROUP BY degrees.CtrCod ORDER BY centres.ShortName",
(unsigned) Deg_STATUS_BIT_PENDING);
break; break;
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,26 +1055,26 @@ 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",
"centres.Status,centres.RequesterUsrCod," "(SELECT centres.CtrCod,centres.InsCod,centres.PlcCod,"
"centres.ShortName,centres.FullName,centres.WWW," "centres.Status,centres.RequesterUsrCod,"
"COUNT(DISTINCT usr_data.UsrCod) AS NumUsrs" "centres.ShortName,centres.FullName,centres.WWW,"
" FROM centres,usr_data" "COUNT(DISTINCT usr_data.UsrCod) AS NumUsrs"
" WHERE centres.InsCod=%ld" " FROM centres,usr_data"
" AND centres.CtrCod=usr_data.CtrCod" " WHERE centres.InsCod=%ld"
" GROUP BY centres.CtrCod)" " AND centres.CtrCod=usr_data.CtrCod"
" UNION " " GROUP BY centres.CtrCod)"
"(SELECT CtrCod,InsCod,PlcCod,Status,RequesterUsrCod," " UNION "
"ShortName,FullName,WWW,0 AS NumUsrs" "(SELECT CtrCod,InsCod,PlcCod,Status,RequesterUsrCod,"
" FROM centres" "ShortName,FullName,WWW,0 AS NumUsrs"
" WHERE centres.InsCod=%ld" " FROM centres"
" AND CtrCod NOT IN" " WHERE centres.InsCod=%ld"
" (SELECT DISTINCT CtrCod FROM usr_data))" " AND CtrCod NOT IN"
" ORDER BY %s", " (SELECT DISTINCT CtrCod FROM usr_data))"
InsCod, " ORDER BY %s",
InsCod, InsCod,
OrderBySubQuery); InsCod,
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get centres"); OrderBySubQuery);
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,26 +1174,27 @@ 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",
"centres.Status,centres.RequesterUsrCod," "(SELECT centres.InsCod,centres.PlcCod,"
"centres.ShortName,centres.FullName,centres.WWW," "centres.Status,centres.RequesterUsrCod,"
"COUNT(DISTINCT usr_data.UsrCod) AS NumUsrs" "centres.ShortName,centres.FullName,centres.WWW,"
" FROM centres,usr_data" "COUNT(DISTINCT usr_data.UsrCod) AS NumUsrs"
" WHERE centres.CtrCod=%ld" " FROM centres,usr_data"
" AND centres.CtrCod=usr_data.CtrCod" " WHERE centres.CtrCod=%ld"
" GROUP BY centres.CtrCod)" " AND centres.CtrCod=usr_data.CtrCod"
" UNION " " GROUP BY centres.CtrCod)"
"(SELECT InsCod,PlcCod," " UNION "
"Status,RequesterUsrCod," "(SELECT InsCod,PlcCod,"
"ShortName,FullName,WWW," "Status,RequesterUsrCod,"
"0 AS NumUsrs" "ShortName,FullName,WWW,"
" FROM centres" "0 AS NumUsrs"
" WHERE CtrCod=%ld" " FROM centres"
" AND CtrCod NOT IN" " WHERE CtrCod=%ld"
" (SELECT DISTINCT CtrCod FROM usr_data))", " AND CtrCod NOT IN"
Ctr->CtrCod, " (SELECT DISTINCT CtrCod FROM usr_data))",
Ctr->CtrCod); Ctr->CtrCod,
if (DB_QuerySELECT_new (&mysql_res,"can not get data of a centre")) // Centre found... Ctr->CtrCod);
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",
" WHERE CtrCod=%ld", "SELECT ShortName FROM centres"
Ctr->CtrCod); " WHERE CtrCod=%ld",
if (DB_QuerySELECT_new (&mysql_res,"can not get the short name of a centre") == 1) Ctr->CtrCod) == 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",
" FROM centres WHERE CtrCod=%ld", "SELECT PhotoAttribution"
CtrCod); " FROM centres WHERE CtrCod=%ld",
if (DB_QuerySELECT_new (&mysql_res,"can not get photo attribution")) CtrCod))
{ {
/* 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",
" FROM centres" "SELECT DISTINCT CtrCod,ShortName"
" WHERE InsCod=%ld" " FROM centres"
" ORDER BY ShortName", " WHERE InsCod=%ld"
Gbl.CurrentIns.Ins.InsCod); " ORDER BY ShortName",
NumCtrs = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get centres"); Gbl.CurrentIns.Ins.InsCod);
/***** 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,15 +700,17 @@ 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",
" FROM centres,institutions,countries" "SELECT centres.CtrCod"
" WHERE %s" " FROM centres,institutions,countries"
" AND centres.InsCod=institutions.InsCod" " WHERE %s"
" AND institutions.CtyCod=countries.CtyCod" " AND centres.InsCod=institutions.InsCod"
"%s" " AND institutions.CtyCod=countries.CtyCod"
" ORDER BY centres.FullName,institutions.FullName", "%s"
SearchQuery,RangeQuery); " ORDER BY centres.FullName,institutions.FullName",
return Ctr_ListCtrsFound (); SearchQuery,RangeQuery);
Ctr_ListCtrsFound (&mysql_res,NumCtrs);
return NumCtrs;
} }
return 0; return 0;