Version 18.7.31

This commit is contained in:
Antonio Cañas Vargas 2018-10-22 18:29:08 +02:00
parent a8db616f03
commit ece2b6e2a0
2 changed files with 112 additions and 91 deletions

View File

@ -355,10 +355,11 @@ En OpenSWAD:
ps2pdf source.ps destination.pdf ps2pdf source.ps destination.pdf
*/ */
#define Log_PLATFORM_VERSION "SWAD 18.7.30 (2018-10-22)" #define Log_PLATFORM_VERSION "SWAD 18.7.31 (2018-10-22)"
#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.7.31: Oct 22, 2018 Some sprintf for database queries changed by asprintf. (237765 lines)
Version 18.7.30: Oct 22, 2018 Some sprintf for database queries changed by asprintf. (237744 lines) Version 18.7.30: Oct 22, 2018 Some sprintf for database queries changed by asprintf. (237744 lines)
Version 18.7.29: Oct 22, 2018 Some sprintf for database queries changed by asprintf. (237687 lines) Version 18.7.29: Oct 22, 2018 Some sprintf for database queries changed by asprintf. (237687 lines)
Version 18.7.28: Oct 22, 2018 Some sprintf for database queries changed by asprintf. (237674 lines) Version 18.7.28: Oct 22, 2018 Some sprintf for database queries changed by asprintf. (237674 lines)

View File

@ -25,9 +25,11 @@
/********************************* Headers ***********************************/ /********************************* Headers ***********************************/
/*****************************************************************************/ /*****************************************************************************/
#define _GNU_SOURCE // For asprintf
#include <limits.h> // For maximum values #include <limits.h> // For maximum values
#include <linux/limits.h> // For PATH_MAX, NAME_MAX #include <linux/limits.h> // For PATH_MAX, NAME_MAX
#include <linux/stddef.h> // For NULL #include <linux/stddef.h> // For NULL
#include <stdio.h> // For asprintf
#include <stdlib.h> // For getenv, etc #include <stdlib.h> // For getenv, etc
#include <stdsoap2.h> // For SOAP_OK and soap functions #include <stdsoap2.h> // For SOAP_OK and soap functions
#include <string.h> // For string functions #include <string.h> // For string functions
@ -520,15 +522,16 @@ static void Inf_PutCheckboxConfirmIHaveReadInfo (void)
static bool Inf_CheckIfIHaveReadInfo (void) static bool Inf_CheckIfIHaveReadInfo (void)
{ {
char Query[512]; char *Query;
/***** Get if info source is already stored in database *****/ /***** Get if info source is already stored in database *****/
sprintf (Query,"SELECT COUNT(*) FROM crs_info_read" if (asprintf (&Query,"SELECT COUNT(*) FROM crs_info_read"
" WHERE UsrCod=%ld AND CrsCod=%ld AND InfoType='%s'", " WHERE UsrCod=%ld AND CrsCod=%ld AND InfoType='%s'",
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.CurrentCrs.Crs.CrsCod, Gbl.CurrentCrs.Crs.CrsCod,
Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type]); Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type]) < 0)
return (DB_QueryCOUNT (Query,"can not get if I have read course info") != 0); Lay_NotEnoughMemoryExit ();
return (DB_QueryCOUNT_free (Query,"can not get if I have read course info") != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -537,7 +540,7 @@ static bool Inf_CheckIfIHaveReadInfo (void)
bool Inf_GetIfIMustReadAnyCrsInfoInThisCrs (void) bool Inf_GetIfIMustReadAnyCrsInfoInThisCrs (void)
{ {
char Query[1024]; char *Query;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRow,NumRows; unsigned long NumRow,NumRows;
@ -550,14 +553,15 @@ bool Inf_GetIfIMustReadAnyCrsInfoInThisCrs (void)
Gbl.CurrentCrs.Info.MustBeRead[InfoType] = false; Gbl.CurrentCrs.Info.MustBeRead[InfoType] = false;
/***** Get info types where students must read info *****/ /***** Get info types where students must read info *****/
sprintf (Query,"SELECT InfoType FROM crs_info_src" if (asprintf (&Query,"SELECT InfoType FROM crs_info_src"
" WHERE CrsCod=%ld AND MustBeRead='Y'" " WHERE CrsCod=%ld AND MustBeRead='Y'"
" AND InfoType NOT IN" " AND InfoType NOT IN"
" (SELECT InfoType FROM crs_info_read" " (SELECT InfoType FROM crs_info_read"
" WHERE UsrCod=%ld AND CrsCod=%ld)", " WHERE UsrCod=%ld AND CrsCod=%ld)",
Gbl.CurrentCrs.Crs.CrsCod, Gbl.CurrentCrs.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod,Gbl.CurrentCrs.Crs.CrsCod); Gbl.Usrs.Me.UsrDat.UsrCod,Gbl.CurrentCrs.Crs.CrsCod) < 0)
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get if you must read any course info"); Lay_NotEnoughMemoryExit ();
NumRows = DB_QuerySELECT_free (Query,&mysql_res,"can not get if you must read any course info");
/***** Set must-be-read to true for each rown in result *****/ /***** Set must-be-read to true for each rown in result *****/
for (NumRow = 0; for (NumRow = 0;
@ -696,15 +700,16 @@ static bool Inf_GetIfIHaveReadFromForm (void)
static void Inf_SetForceReadIntoDB (bool MustBeRead) static void Inf_SetForceReadIntoDB (bool MustBeRead)
{ {
char Query[512]; char *Query;
/***** Insert or replace info source for a specific type of course information *****/ /***** Insert or replace info source for a specific type of course information *****/
sprintf (Query,"UPDATE crs_info_src SET MustBeRead='%c'" if (asprintf (&Query,"UPDATE crs_info_src SET MustBeRead='%c'"
" WHERE CrsCod=%ld AND InfoType='%s'", " WHERE CrsCod=%ld AND InfoType='%s'",
MustBeRead ? 'Y' : MustBeRead ? 'Y' :
'N', 'N',
Gbl.CurrentCrs.Crs.CrsCod,Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type]); Gbl.CurrentCrs.Crs.CrsCod,Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type]) < 0)
DB_QueryUPDATE (Query,"can not update if info must be read"); Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not update if info must be read");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -713,29 +718,31 @@ static void Inf_SetForceReadIntoDB (bool MustBeRead)
static void Inf_SetIHaveReadIntoDB (bool IHaveRead) static void Inf_SetIHaveReadIntoDB (bool IHaveRead)
{ {
char Query[512]; char *Query;
if (IHaveRead) if (IHaveRead)
{ {
/***** Insert I have read course information *****/ /***** Insert I have read course information *****/
sprintf (Query,"REPLACE INTO crs_info_read" if (asprintf (&Query,"REPLACE INTO crs_info_read"
" (UsrCod,CrsCod,InfoType)" " (UsrCod,CrsCod,InfoType)"
" VALUES" " VALUES"
" (%ld,%ld,'%s')", " (%ld,%ld,'%s')",
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.CurrentCrs.Crs.CrsCod, Gbl.CurrentCrs.Crs.CrsCod,
Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type]); Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type]) < 0)
DB_QueryUPDATE (Query,"can not set that I have read course info"); Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not set that I have read course info");
} }
else else
{ {
/***** Remove I have read course information *****/ /***** Remove I have read course information *****/
sprintf (Query,"DELETE FROM crs_info_read" if (asprintf (&Query,"DELETE FROM crs_info_read"
" WHERE UsrCod=%ld AND CrsCod=%ld AND InfoType='%s'", " WHERE UsrCod=%ld AND CrsCod=%ld AND InfoType='%s'",
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.CurrentCrs.Crs.CrsCod, Gbl.CurrentCrs.Crs.CrsCod,
Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type]); Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type]) < 0)
DB_QueryDELETE (Query,"can not set that I have not read course info"); Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not set that I have not read course info");
} }
} }
@ -745,13 +752,14 @@ static void Inf_SetIHaveReadIntoDB (bool IHaveRead)
void Inf_RemoveUsrFromCrsInfoRead (long UsrCod,long CrsCod) void Inf_RemoveUsrFromCrsInfoRead (long UsrCod,long CrsCod)
{ {
char Query[512]; char *Query;
/***** Remove user's status about reading of course information *****/ /***** Remove user's status about reading of course information *****/
sprintf (Query,"DELETE FROM crs_info_read" if (asprintf (&Query,"DELETE FROM crs_info_read"
" WHERE UsrCod=%ld AND CrsCod=%ld", " WHERE UsrCod=%ld AND CrsCod=%ld",
UsrCod,CrsCod); UsrCod,CrsCod) < 0)
DB_QueryDELETE (Query,"can not set that I have not read course info"); Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not set that I have not read course info");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1483,39 +1491,47 @@ Inf_InfoSrc_t Inf_GetInfoSrcFromForm (void)
void Inf_SetInfoSrcIntoDB (Inf_InfoSrc_t InfoSrc) void Inf_SetInfoSrcIntoDB (Inf_InfoSrc_t InfoSrc)
{ {
char Query[512]; char *Query;
/***** Get if info source is already stored in database *****/ /***** Get if info source is already stored in database *****/
sprintf (Query,"SELECT COUNT(*) FROM crs_info_src" if (asprintf (&Query,"SELECT COUNT(*) FROM crs_info_src"
" WHERE CrsCod=%ld AND InfoType='%s'", " WHERE CrsCod=%ld AND InfoType='%s'",
Gbl.CurrentCrs.Crs.CrsCod, Gbl.CurrentCrs.Crs.CrsCod,
Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type]); Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type]) < 0)
Lay_NotEnoughMemoryExit ();
if (DB_QueryCOUNT (Query,"can not get if info source is already stored in database")) // Info is already stored in database, so update it if (DB_QueryCOUNT (Query,"can not get if info source is already stored in database")) // Info is already stored in database, so update it
{ // Update info source { // Update info source
if (InfoSrc == Inf_INFO_SRC_NONE) if (InfoSrc == Inf_INFO_SRC_NONE)
sprintf (Query,"UPDATE crs_info_src SET InfoSrc='%s',MustBeRead='N'" {
" WHERE CrsCod=%ld AND InfoType='%s'", if (asprintf (&Query,"UPDATE crs_info_src SET InfoSrc='%s',MustBeRead='N'"
Inf_NamesInDBForInfoSrc[Inf_INFO_SRC_NONE], " WHERE CrsCod=%ld AND InfoType='%s'",
Gbl.CurrentCrs.Crs.CrsCod, Inf_NamesInDBForInfoSrc[Inf_INFO_SRC_NONE],
Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type]); Gbl.CurrentCrs.Crs.CrsCod,
Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type]) < 0)
Lay_NotEnoughMemoryExit ();
}
else // MustBeRead remains unchanged else // MustBeRead remains unchanged
sprintf (Query,"UPDATE crs_info_src SET InfoSrc='%s'" {
" WHERE CrsCod=%ld AND InfoType='%s'", if (asprintf (&Query,"UPDATE crs_info_src SET InfoSrc='%s'"
Inf_NamesInDBForInfoSrc[InfoSrc], " WHERE CrsCod=%ld AND InfoType='%s'",
Gbl.CurrentCrs.Crs.CrsCod, Inf_NamesInDBForInfoSrc[InfoSrc],
Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type]); Gbl.CurrentCrs.Crs.CrsCod,
DB_QueryUPDATE (Query,"can not update info source"); Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type]) < 0)
Lay_NotEnoughMemoryExit ();
}
DB_QueryUPDATE_free (Query,"can not update info source");
} }
else // Info is not stored in database, so insert it else // Info is not stored in database, so insert it
{ {
sprintf (Query,"INSERT INTO crs_info_src" if (asprintf (&Query,"INSERT INTO crs_info_src"
" (CrsCod,InfoType,InfoSrc,MustBeRead)" " (CrsCod,InfoType,InfoSrc,MustBeRead)"
" VALUES" " VALUES"
" (%ld,'%s','%s','N')", " (%ld,'%s','%s','N')",
Gbl.CurrentCrs.Crs.CrsCod, Gbl.CurrentCrs.Crs.CrsCod,
Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type], Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type],
Inf_NamesInDBForInfoSrc[InfoSrc]); Inf_NamesInDBForInfoSrc[InfoSrc]) < 0)
DB_QueryINSERT (Query,"can not insert info source"); Lay_NotEnoughMemoryExit ();
DB_QueryINSERT_free (Query,"can not insert info source");
} }
} }
@ -1526,16 +1542,17 @@ void Inf_SetInfoSrcIntoDB (Inf_InfoSrc_t InfoSrc)
Inf_InfoSrc_t Inf_GetInfoSrcFromDB (long CrsCod,Inf_InfoType_t InfoType) Inf_InfoSrc_t Inf_GetInfoSrcFromDB (long CrsCod,Inf_InfoType_t InfoType)
{ {
char Query[512]; char *Query;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
Inf_InfoSrc_t InfoSrc; Inf_InfoSrc_t InfoSrc;
/***** Get info source for a specific type of info from database *****/ /***** Get info source for a specific type of info from database *****/
sprintf (Query,"SELECT InfoSrc FROM crs_info_src" if (asprintf (&Query,"SELECT InfoSrc FROM crs_info_src"
" WHERE CrsCod=%ld AND InfoType='%s'", " WHERE CrsCod=%ld AND InfoType='%s'",
CrsCod,Inf_NamesInDBForInfoType[InfoType]); CrsCod,Inf_NamesInDBForInfoType[InfoType]) < 0)
if (DB_QuerySELECT (Query,&mysql_res,"can not get info source")) Lay_NotEnoughMemoryExit ();
if (DB_QuerySELECT_free (Query,&mysql_res,"can not get info source"))
{ {
/* Get row */ /* Get row */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1560,7 +1577,7 @@ void Inf_GetAndCheckInfoSrcFromDB (long CrsCod,
Inf_InfoType_t InfoType, Inf_InfoType_t InfoType,
Inf_InfoSrc_t *InfoSrc,bool *MustBeRead) Inf_InfoSrc_t *InfoSrc,bool *MustBeRead)
{ {
char Query[512]; char *Query;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows; unsigned long NumRows;
@ -1570,10 +1587,11 @@ void Inf_GetAndCheckInfoSrcFromDB (long CrsCod,
*MustBeRead = false; *MustBeRead = false;
/***** Get info source for a specific type of info from database *****/ /***** Get info source for a specific type of info from database *****/
sprintf (Query,"SELECT InfoSrc,MustBeRead FROM crs_info_src" if (asprintf (&Query,"SELECT InfoSrc,MustBeRead FROM crs_info_src"
" WHERE CrsCod=%ld AND InfoType='%s'", " WHERE CrsCod=%ld AND InfoType='%s'",
CrsCod,Inf_NamesInDBForInfoType[InfoType]); CrsCod,Inf_NamesInDBForInfoType[InfoType]) < 0)
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get info source"); Lay_NotEnoughMemoryExit ();
NumRows = DB_QuerySELECT_free (Query,&mysql_res,"can not get info source");
/***** 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)
@ -1693,17 +1711,18 @@ Inf_InfoSrc_t Inf_ConvertFromStrDBToInfoSrc (const char *StrInfoSrcDB)
static void Inf_SetInfoTxtIntoDB (const char *InfoTxtHTML,const char *InfoTxtMD) static void Inf_SetInfoTxtIntoDB (const char *InfoTxtHTML,const char *InfoTxtMD)
{ {
char Query[256 + Cns_MAX_BYTES_LONG_TEXT]; char *Query;
/***** Insert or replace info source for a specific type of course information *****/ /***** Insert or replace info source for a specific type of course information *****/
sprintf (Query,"REPLACE INTO crs_info_txt" if (asprintf (&Query,"REPLACE INTO crs_info_txt"
" (CrsCod,InfoType,InfoTxtHTML,InfoTxtMD)" " (CrsCod,InfoType,InfoTxtHTML,InfoTxtMD)"
" VALUES" " VALUES"
" (%ld,'%s','%s','%s')", " (%ld,'%s','%s','%s')",
Gbl.CurrentCrs.Crs.CrsCod, Gbl.CurrentCrs.Crs.CrsCod,
Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type], Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type],
InfoTxtHTML,InfoTxtMD); InfoTxtHTML,InfoTxtMD) < 0)
DB_QueryREPLACE (Query,"can not update info text"); Lay_NotEnoughMemoryExit ();
DB_QueryREPLACE_free (Query,"can not update info text");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1714,16 +1733,17 @@ static void Inf_GetInfoTxtFromDB (long CrsCod,Inf_InfoType_t InfoType,
char InfoTxtHTML[Cns_MAX_BYTES_LONG_TEXT + 1], char InfoTxtHTML[Cns_MAX_BYTES_LONG_TEXT + 1],
char InfoTxtMD[Cns_MAX_BYTES_LONG_TEXT + 1]) char InfoTxtMD[Cns_MAX_BYTES_LONG_TEXT + 1])
{ {
char Query[512]; char *Query;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows; unsigned long NumRows;
/***** Get info source for a specific type of course information /***** Get info source for a specific type of course information
(bibliography, FAQ, links or evaluation) from database *****/ (bibliography, FAQ, links or evaluation) from database *****/
sprintf (Query,"SELECT InfoTxtHTML,InfoTxtMD FROM crs_info_txt" if (asprintf (&Query,"SELECT InfoTxtHTML,InfoTxtMD FROM crs_info_txt"
" WHERE CrsCod=%ld AND InfoType='%s'", " WHERE CrsCod=%ld AND InfoType='%s'",
CrsCod,Inf_NamesInDBForInfoType[InfoType]); CrsCod,Inf_NamesInDBForInfoType[InfoType]) < 0)
Lay_NotEnoughMemoryExit ();
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get info text"); NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get info text");
/***** The result of the query must have one row or none *****/ /***** The result of the query must have one row or none *****/