Version 18.7.16

This commit is contained in:
Antonio Cañas Vargas 2018-10-20 18:53:22 +02:00
parent 9650339c7d
commit b5c03ba68a
3 changed files with 117 additions and 97 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.15 (2018-10-20)" #define Log_PLATFORM_VERSION "SWAD 18.7.16 (2018-10-20)"
#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.16: Oct 20, 2018 Some sprintf for database queries changed by asprintf. (237016 lines)
Version 18.7.15: Oct 20, 2018 Some sprintf for database queries changed by asprintf. (236996 lines) Version 18.7.15: Oct 20, 2018 Some sprintf for database queries changed by asprintf. (236996 lines)
Version 18.7.14: Oct 20, 2018 Some sprintf for database queries changed by asprintf. (236993 lines) Version 18.7.14: Oct 20, 2018 Some sprintf for database queries changed by asprintf. (236993 lines)
Version 18.7.13: Oct 20, 2018 Some sprintf for database queries changed by asprintf. (236953 lines) Version 18.7.13: Oct 20, 2018 Some sprintf for database queries changed by asprintf. (236953 lines)

View File

@ -25,6 +25,8 @@
/********************************* Headers ***********************************/ /********************************* Headers ***********************************/
/*****************************************************************************/ /*****************************************************************************/
#define _GNU_SOURCE // For asprintf
#include <stdio.h> // For asprintf
#include <string.h> // For string functions #include <string.h> // For string functions
#include <time.h> // For time functions (mktime...) #include <time.h> // For time functions (mktime...)
@ -177,7 +179,7 @@ void Dat_PutScriptDateFormat (Dat_Format_t Format)
void Dat_ChangeDateFormat (void) void Dat_ChangeDateFormat (void)
{ {
char Query[512]; char *Query;
/***** Get param with date format *****/ /***** Get param with date format *****/
Gbl.Prefs.DateFormat = Dat_GetParamDateFormat (); Gbl.Prefs.DateFormat = Dat_GetParamDateFormat ();
@ -185,11 +187,12 @@ void Dat_ChangeDateFormat (void)
/***** Store date format in database *****/ /***** Store date format in database *****/
if (Gbl.Usrs.Me.Logged) if (Gbl.Usrs.Me.Logged)
{ {
sprintf (Query,"UPDATE usr_data SET DateFormat=%u" if (asprintf (&Query,"UPDATE usr_data SET DateFormat=%u"
" WHERE UsrCod=%ld", " WHERE UsrCod=%ld",
(unsigned) Gbl.Prefs.DateFormat, (unsigned) Gbl.Prefs.DateFormat,
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
DB_QueryUPDATE (Query,"can not update your preference about date format"); Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not update your preference about date format");
} }
/***** Set preferences from current IP *****/ /***** Set preferences from current IP *****/
@ -735,7 +738,7 @@ void Dat_PutHiddenParBrowserTZDiff (void)
void Dat_GetBrowserTimeZone (char BrowserTimeZone[Dat_MAX_BYTES_TIME_ZONE + 1]) void Dat_GetBrowserTimeZone (char BrowserTimeZone[Dat_MAX_BYTES_TIME_ZONE + 1])
{ {
char Query[512]; char *Query;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
bool TZNameIsUsable = false; bool TZNameIsUsable = false;
@ -755,9 +758,10 @@ void Dat_GetBrowserTimeZone (char BrowserTimeZone[Dat_MAX_BYTES_TIME_ZONE + 1])
if (BrowserTimeZone[0]) if (BrowserTimeZone[0])
{ {
/* Try to convert a date from server time zone to browser time zone */ /* Try to convert a date from server time zone to browser time zone */
sprintf (Query,"SELECT CONVERT_TZ(NOW(),@@session.time_zone,'%s')", if (asprintf (&Query,"SELECT CONVERT_TZ(NOW(),@@session.time_zone,'%s')",
BrowserTimeZone); BrowserTimeZone) < 0)
if (DB_QuerySELECT (Query,&mysql_res,"can not check if time zone name is usable")) Lay_NotEnoughMemoryExit ();
if (DB_QuerySELECT_free (Query,&mysql_res,"can not check if time zone name is usable"))
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
if (row[0] != NULL) if (row[0] != NULL)

View File

@ -25,10 +25,11 @@
/********************************* Headers ***********************************/ /********************************* Headers ***********************************/
/*****************************************************************************/ /*****************************************************************************/
#define _GNU_SOURCE // For asprintf
#include <ctype.h> // For isprint, isspace, etc. #include <ctype.h> // For isprint, isspace, etc.
#include <linux/stddef.h> // For NULL #include <linux/stddef.h> // For NULL
#include <stdbool.h> // For boolean type #include <stdbool.h> // For boolean type
#include <stdio.h> // For fprintf, etc. #include <stdio.h> // For fprintf, asprintf, etc.
#include <stdlib.h> // For exit, system, calloc, free, etc. #include <stdlib.h> // For exit, system, calloc, free, etc.
#include <string.h> // For string functions #include <string.h> // For string functions
#include <mysql/mysql.h> // To access MySQL databases #include <mysql/mysql.h> // To access MySQL databases
@ -543,12 +544,13 @@ static void DT_PutHeadDegreeTypesForEdition (void)
static void DT_CreateDegreeType (struct DegreeType *DegTyp) static void DT_CreateDegreeType (struct DegreeType *DegTyp)
{ {
extern const char *Txt_Created_new_type_of_degree_X; extern const char *Txt_Created_new_type_of_degree_X;
char Query[128 + Deg_MAX_BYTES_DEGREE_TYPE_NAME]; char *Query;
/***** Create a new degree type *****/ /***** Create a new degree type *****/
sprintf (Query,"INSERT INTO deg_types SET DegTypName='%s'", if (asprintf (&Query,"INSERT INTO deg_types SET DegTypName='%s'",
DegTyp->DegTypName); DegTyp->DegTypName) < 0)
DB_QueryINSERT (Query,"can not create a new type of degree"); Lay_NotEnoughMemoryExit ();
DB_QueryINSERT_free (Query,"can not create a new type of degree");
/***** Write success message *****/ /***** Write success message *****/
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
@ -568,7 +570,7 @@ void DT_GetListDegreeTypes (Sco_Scope_t Scope,DT_Order_t Order)
"DegTypName", // DT_ORDER_BY_DEGREE_TYPE "DegTypName", // DT_ORDER_BY_DEGREE_TYPE
"NumDegs DESC,DegTypName", // DT_ORDER_BY_NUM_DEGREES "NumDegs DESC,DegTypName", // DT_ORDER_BY_NUM_DEGREES
}; };
char Query[1024]; char *Query;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRow; unsigned long NumRow;
@ -581,76 +583,81 @@ void DT_GetListDegreeTypes (Sco_Scope_t Scope,DT_Order_t Order)
all degree types with degrees all degree types with degrees
union with union with
all degree types without any degree */ all degree types without any degree */
sprintf (Query,"(SELECT deg_types.DegTypCod,deg_types.DegTypName," if (asprintf (&Query,"(SELECT deg_types.DegTypCod,deg_types.DegTypName,"
"COUNT(degrees.DegCod) AS NumDegs" "COUNT(degrees.DegCod) AS NumDegs"
" FROM degrees,deg_types" " FROM degrees,deg_types"
" WHERE degrees.DegTypCod=deg_types.DegTypCod" " WHERE degrees.DegTypCod=deg_types.DegTypCod"
" GROUP BY degrees.DegTypCod)" " GROUP BY degrees.DegTypCod)"
" UNION " " UNION "
"(SELECT DegTypCod,DegTypName,0 AS NumDegs" // Do not use '0' because NumDegs will be casted to string and order will be wrong "(SELECT DegTypCod,DegTypName,0 AS NumDegs" // Do not use '0' because NumDegs will be casted to string and order will be wrong
" FROM deg_types" " FROM deg_types"
" WHERE DegTypCod NOT IN" " WHERE DegTypCod NOT IN"
" (SELECT DegTypCod FROM degrees))" " (SELECT DegTypCod FROM degrees))"
" ORDER BY %s", " ORDER BY %s",
OrderBySubQuery[Order]); OrderBySubQuery[Order]) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
case Sco_SCOPE_CTY: case Sco_SCOPE_CTY:
/* Get only degree types with degrees in the current country */ /* Get only degree types with degrees in the current country */
sprintf (Query,"SELECT deg_types.DegTypCod,deg_types.DegTypName," if (asprintf (&Query,"SELECT deg_types.DegTypCod,deg_types.DegTypName,"
"COUNT(degrees.DegCod) AS NumDegs" "COUNT(degrees.DegCod) AS NumDegs"
" FROM institutions,centres,degrees,deg_types" " FROM institutions,centres,degrees,deg_types"
" WHERE institutions.CtyCod=%ld" " WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod" " AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod" " AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegTypCod=deg_types.DegTypCod" " AND degrees.DegTypCod=deg_types.DegTypCod"
" GROUP BY degrees.DegTypCod" " GROUP BY degrees.DegTypCod"
" ORDER BY %s", " ORDER BY %s",
Gbl.CurrentCty.Cty.CtyCod, Gbl.CurrentCty.Cty.CtyCod,
OrderBySubQuery[Order]); OrderBySubQuery[Order]) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
/* Get only degree types with degrees in the current institution */ /* Get only degree types with degrees in the current institution */
sprintf (Query,"SELECT deg_types.DegTypCod,deg_types.DegTypName," if (asprintf (&Query,"SELECT deg_types.DegTypCod,deg_types.DegTypName,"
"COUNT(degrees.DegCod) AS NumDegs" "COUNT(degrees.DegCod) AS NumDegs"
" FROM centres,degrees,deg_types" " FROM centres,degrees,deg_types"
" WHERE centres.InsCod=%ld" " WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod" " AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegTypCod=deg_types.DegTypCod" " AND degrees.DegTypCod=deg_types.DegTypCod"
" GROUP BY degrees.DegTypCod" " GROUP BY degrees.DegTypCod"
" ORDER BY %s", " ORDER BY %s",
Gbl.CurrentIns.Ins.InsCod, Gbl.CurrentIns.Ins.InsCod,
OrderBySubQuery[Order]); OrderBySubQuery[Order]) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
case Sco_SCOPE_CTR: case Sco_SCOPE_CTR:
/* Get only degree types with degrees in the current centre */ /* Get only degree types with degrees in the current centre */
sprintf (Query,"SELECT deg_types.DegTypCod,deg_types.DegTypName," if (asprintf (&Query,"SELECT deg_types.DegTypCod,deg_types.DegTypName,"
"COUNT(degrees.DegCod) AS NumDegs" "COUNT(degrees.DegCod) AS NumDegs"
" FROM degrees,deg_types" " FROM degrees,deg_types"
" WHERE degrees.CtrCod=%ld" " WHERE degrees.CtrCod=%ld"
" AND degrees.DegTypCod=deg_types.DegTypCod" " AND degrees.DegTypCod=deg_types.DegTypCod"
" GROUP BY degrees.DegTypCod" " GROUP BY degrees.DegTypCod"
" ORDER BY %s", " ORDER BY %s",
Gbl.CurrentCtr.Ctr.CtrCod, Gbl.CurrentCtr.Ctr.CtrCod,
OrderBySubQuery[Order]); OrderBySubQuery[Order]) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
/* Get only degree types with degrees in the current degree */ /* Get only degree types with degrees in the current degree */
sprintf (Query,"SELECT deg_types.DegTypCod,deg_types.DegTypName," if (asprintf (&Query,"SELECT deg_types.DegTypCod,deg_types.DegTypName,"
"COUNT(degrees.DegCod) AS NumDegs" "COUNT(degrees.DegCod) AS NumDegs"
" FROM degrees,deg_types" " FROM degrees,deg_types"
" WHERE degrees.DegCod=%ld" " WHERE degrees.DegCod=%ld"
" AND degrees.DegTypCod=deg_types.DegTypCod" " AND degrees.DegTypCod=deg_types.DegTypCod"
" GROUP BY degrees.DegTypCod" " GROUP BY degrees.DegTypCod"
" ORDER BY %s", " ORDER BY %s",
Gbl.CurrentDeg.Deg.DegCod, Gbl.CurrentDeg.Deg.DegCod,
OrderBySubQuery[Order]); OrderBySubQuery[Order]) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
default: default:
Lay_ShowErrorAndExit ("Wrong scope."); Lay_ShowErrorAndExit ("Wrong scope.");
break; break;
} }
Gbl.Degs.DegTypes.Num = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get types of degree"); Gbl.Degs.DegTypes.Num = (unsigned) DB_QuerySELECT_free (Query,&mysql_res,"can not get types of degree");
/***** Get degree types *****/ /***** Get degree types *****/
if (Gbl.Degs.DegTypes.Num) if (Gbl.Degs.DegTypes.Num)
@ -802,12 +809,13 @@ long DT_GetAndCheckParamOtherDegTypCod (long MinCodAllowed)
static unsigned DT_CountNumDegsOfType (long DegTypCod) static unsigned DT_CountNumDegsOfType (long DegTypCod)
{ {
char Query[128]; char *Query;
/***** Get number of degrees of a type from database *****/ /***** Get number of degrees of a type from database *****/
sprintf (Query,"SELECT COUNT(*) FROM degrees WHERE DegTypCod=%ld", if (asprintf (&Query,"SELECT COUNT(*) FROM degrees WHERE DegTypCod=%ld",
DegTypCod); DegTypCod) < 0)
return (unsigned) DB_QueryCOUNT (Query,"can not get number of degrees of a type"); Lay_NotEnoughMemoryExit ();
return (unsigned) DB_QueryCOUNT_free (Query,"can not get number of degrees of a type");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -816,7 +824,7 @@ static unsigned DT_CountNumDegsOfType (long DegTypCod)
bool DT_GetDataOfDegreeTypeByCod (struct DegreeType *DegTyp) bool DT_GetDataOfDegreeTypeByCod (struct DegreeType *DegTyp)
{ {
char Query[128]; char *Query;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows; unsigned long NumRows;
@ -831,9 +839,10 @@ bool DT_GetDataOfDegreeTypeByCod (struct DegreeType *DegTyp)
} }
/***** Get the name of a type of degree from database *****/ /***** Get the name of a type of degree from database *****/
sprintf (Query,"SELECT DegTypName FROM deg_types WHERE DegTypCod=%ld", if (asprintf (&Query,"SELECT DegTypName FROM deg_types WHERE DegTypCod=%ld",
DegTyp->DegTypCod); DegTyp->DegTypCod) < 0)
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get the name of a type of degree"); Lay_NotEnoughMemoryExit ();
NumRows = DB_QuerySELECT_free (Query,&mysql_res,"can not get the name of a type of degree");
if (NumRows == 1) if (NumRows == 1)
{ {
@ -872,16 +881,17 @@ bool DT_GetDataOfDegreeTypeByCod (struct DegreeType *DegTyp)
static void DT_RemoveDegreeTypeCompletely (long DegTypCod) static void DT_RemoveDegreeTypeCompletely (long DegTypCod)
{ {
char Query[128]; char *Query;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRow,NumRows; unsigned long NumRow,NumRows;
long DegCod; long DegCod;
/***** Get degrees of a type from database *****/ /***** Get degrees of a type from database *****/
sprintf (Query,"SELECT DegCod FROM degrees WHERE DegTypCod=%ld", if (asprintf (&Query,"SELECT DegCod FROM degrees WHERE DegTypCod=%ld",
DegTypCod); DegTypCod) < 0)
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get degrees of a type"); Lay_NotEnoughMemoryExit ();
NumRows = DB_QuerySELECT_free (Query,&mysql_res,"can not get degrees of a type");
/* Get degrees of this type */ /* Get degrees of this type */
for (NumRow = 0; for (NumRow = 0;
@ -903,8 +913,10 @@ static void DT_RemoveDegreeTypeCompletely (long DegTypCod)
DB_FreeMySQLResult (&mysql_res); DB_FreeMySQLResult (&mysql_res);
/***** Remove the degree type *****/ /***** Remove the degree type *****/
sprintf (Query,"DELETE FROM deg_types WHERE DegTypCod=%ld",DegTypCod); if (asprintf (&Query,"DELETE FROM deg_types WHERE DegTypCod=%ld",
DB_QueryDELETE (Query,"can not remove a type of degree"); DegTypCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove a type of degree");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -918,7 +930,7 @@ void DT_RenameDegreeType (void)
extern const char *Txt_The_type_of_degree_X_has_been_renamed_as_Y; extern const char *Txt_The_type_of_degree_X_has_been_renamed_as_Y;
extern const char *Txt_The_name_of_the_type_of_degree_X_has_not_changed; extern const char *Txt_The_name_of_the_type_of_degree_X_has_not_changed;
struct DegreeType *DegTyp; struct DegreeType *DegTyp;
char Query[128 + Deg_MAX_BYTES_DEGREE_TYPE_NAME]; char *Query;
char NewNameDegTyp[Deg_MAX_BYTES_DEGREE_TYPE_NAME + 1]; char NewNameDegTyp[Deg_MAX_BYTES_DEGREE_TYPE_NAME + 1];
DegTyp = &Gbl.Degs.EditingDegTyp; DegTyp = &Gbl.Degs.EditingDegTyp;
@ -958,10 +970,11 @@ void DT_RenameDegreeType (void)
else else
{ {
/* Update the table changing old name by new name */ /* Update the table changing old name by new name */
sprintf (Query,"UPDATE deg_types SET DegTypName='%s'" if (asprintf (&Query,"UPDATE deg_types SET DegTypName='%s'"
" WHERE DegTypCod=%ld", " WHERE DegTypCod=%ld",
NewNameDegTyp,DegTyp->DegTypCod); NewNameDegTyp,DegTyp->DegTypCod) < 0)
DB_QueryUPDATE (Query,"can not update the type of a degree"); Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not update the type of a degree");
/* Write message to show the change made */ /* Write message to show the change made */
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
@ -991,13 +1004,14 @@ void DT_RenameDegreeType (void)
static bool DT_CheckIfDegreeTypeNameExists (const char *DegTypName,long DegTypCod) static bool DT_CheckIfDegreeTypeNameExists (const char *DegTypName,long DegTypCod)
{ {
char Query[256 + Deg_MAX_BYTES_DEGREE_TYPE_NAME]; char *Query;
/***** Get number of degree types with a name from database *****/ /***** Get number of degree types with a name from database *****/
sprintf (Query,"SELECT COUNT(*) FROM deg_types" if (asprintf (&Query,"SELECT COUNT(*) FROM deg_types"
" WHERE DegTypName='%s' AND DegTypCod<>%ld", " WHERE DegTypName='%s' AND DegTypCod<>%ld",
DegTypName,DegTypCod); DegTypName,DegTypCod) < 0)
return (DB_QueryCOUNT (Query,"can not check if the name of a type of degree already existed") != 0); Lay_NotEnoughMemoryExit ();
return (DB_QueryCOUNT_free (Query,"can not check if the name of a type of degree already existed") != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1008,7 +1022,7 @@ void DT_ChangeDegreeType (void)
{ {
extern const char *Txt_The_type_of_degree_of_the_degree_X_has_changed; extern const char *Txt_The_type_of_degree_of_the_degree_X_has_changed;
long NewDegTypCod; long NewDegTypCod;
char Query[128]; char *Query;
/***** Get parameters from form *****/ /***** Get parameters from form *****/
/* Get degree code */ /* Get degree code */
@ -1021,9 +1035,10 @@ void DT_ChangeDegreeType (void)
Deg_GetDataOfDegreeByCod (&Gbl.Degs.EditingDeg); Deg_GetDataOfDegreeByCod (&Gbl.Degs.EditingDeg);
/***** Update the table of degrees changing old type by new type *****/ /***** Update the table of degrees changing old type by new type *****/
sprintf (Query,"UPDATE degrees SET DegTypCod=%ld WHERE DegCod=%ld", if (asprintf (&Query,"UPDATE degrees SET DegTypCod=%ld WHERE DegCod=%ld",
NewDegTypCod,Gbl.Degs.EditingDeg.DegCod); NewDegTypCod,Gbl.Degs.EditingDeg.DegCod) < 0)
DB_QueryUPDATE (Query,"can not update the type of a degree"); Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not update the type of a degree");
/***** Write message to show the change made /***** Write message to show the change made
and put button to go to degree changed *****/ and put button to go to degree changed *****/