Version 18.7.11

This commit is contained in:
Antonio Cañas Vargas 2018-10-19 01:54:47 +02:00
parent 04adb7ba16
commit 3e5a25259d
3 changed files with 208 additions and 181 deletions

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 "swad_box.h" #include "swad_box.h"
@ -144,7 +146,7 @@ void Cal_ShowFormToSelFirstDayOfWeek (Act_Action_t Action,void (*FuncParams) (),
void Cal_ChangeFirstDayOfWeek (void) void Cal_ChangeFirstDayOfWeek (void)
{ {
char Query[512]; char *Query;
/***** Get param with icon set *****/ /***** Get param with icon set *****/
Gbl.Prefs.FirstDayOfWeek = Cal_GetParamFirstDayOfWeek (); Gbl.Prefs.FirstDayOfWeek = Cal_GetParamFirstDayOfWeek ();
@ -152,11 +154,12 @@ void Cal_ChangeFirstDayOfWeek (void)
/***** Store icon first day of week database *****/ /***** Store icon first day of week database *****/
if (Gbl.Usrs.Me.Logged) if (Gbl.Usrs.Me.Logged)
{ {
sprintf (Query,"UPDATE usr_data SET FirstDayOfWeek=%u" if (asprintf (&Query,"UPDATE usr_data SET FirstDayOfWeek=%u"
" WHERE UsrCod=%ld", " WHERE UsrCod=%ld",
Gbl.Prefs.FirstDayOfWeek, Gbl.Prefs.FirstDayOfWeek,
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
DB_QueryUPDATE (Query,"can not update your preference about first day of week"); Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not update your preference about first day of week");
} }
/***** Set preferences from current IP *****/ /***** Set preferences from current IP *****/

View File

@ -25,8 +25,10 @@
/********************************* Headers ***********************************/ /********************************* Headers ***********************************/
/*****************************************************************************/ /*****************************************************************************/
#define _GNU_SOURCE // For asprintf
#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 asprintf
#include <stdlib.h> // For calloc #include <stdlib.h> // For calloc
#include <string.h> // For string functions #include <string.h> // For string functions
#include <sys/wait.h> // For the macro WEXITSTATUS #include <sys/wait.h> // For the macro WEXITSTATUS
@ -131,7 +133,7 @@ void Ctr_SeeCtrWithPendingDegs (void)
extern const char *Txt_Centre; extern const char *Txt_Centre;
extern const char *Txt_Degrees_ABBREVIATION; extern const char *Txt_Degrees_ABBREVIATION;
extern const char *Txt_There_are_no_centres_with_requests_for_degrees_to_be_confirmed; extern const char *Txt_There_are_no_centres_with_requests_for_degrees_to_be_confirmed;
char Query[1024]; char *Query;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned NumCtrs; unsigned NumCtrs;
@ -143,29 +145,31 @@ void Ctr_SeeCtrWithPendingDegs (void)
switch (Gbl.Usrs.Me.Role.Logged) switch (Gbl.Usrs.Me.Role.Logged)
{ {
case Rol_CTR_ADM: case Rol_CTR_ADM:
sprintf (Query,"SELECT degrees.CtrCod,COUNT(*)" if (asprintf (&Query,"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) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
case Rol_SYS_ADM: case Rol_SYS_ADM:
sprintf (Query,"SELECT degrees.CtrCod,COUNT(*)" if (asprintf (&Query,"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"
" GROUP BY degrees.CtrCod ORDER BY centres.ShortName", " GROUP BY degrees.CtrCod ORDER BY centres.ShortName",
(unsigned) Deg_STATUS_BIT_PENDING); (unsigned) Deg_STATUS_BIT_PENDING) < 0)
Lay_NotEnoughMemoryExit ();
break; break;
default: // Forbidden for other users default: // Forbidden for other users
return; return;
} }
/***** Get centres *****/ /***** Get centres *****/
if ((NumCtrs = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get centres with pending degrees"))) if ((NumCtrs = (unsigned) DB_QuerySELECT_free (Query,&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,
@ -1033,7 +1037,7 @@ static void Ctr_PutIconToViewCentres (void)
void Ctr_GetListCentres (long InsCod) void Ctr_GetListCentres (long InsCod)
{ {
char OrderBySubQuery[256]; char OrderBySubQuery[256];
char Query[1024]; char *Query;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows; unsigned long NumRows;
@ -1050,7 +1054,7 @@ void Ctr_GetListCentres (long InsCod)
sprintf (OrderBySubQuery,"NumUsrs DESC,FullName"); sprintf (OrderBySubQuery,"NumUsrs DESC,FullName");
break; break;
} }
sprintf (Query,"(SELECT centres.CtrCod,centres.InsCod,centres.PlcCod," if (asprintf (&Query,"(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"
@ -1068,8 +1072,9 @@ void Ctr_GetListCentres (long InsCod)
" ORDER BY %s", " ORDER BY %s",
InsCod, InsCod,
InsCod, InsCod,
OrderBySubQuery); OrderBySubQuery) < 0)
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get centres"); Lay_NotEnoughMemoryExit ();
NumRows = DB_QuerySELECT_free (Query,&mysql_res,"can not get centres");
if (NumRows) // Centres found... if (NumRows) // Centres found...
{ {
@ -1146,7 +1151,7 @@ void Ctr_GetListCentres (long InsCod)
bool Ctr_GetDataOfCentreByCod (struct Centre *Ctr) bool Ctr_GetDataOfCentreByCod (struct Centre *Ctr)
{ {
char Query[1024]; char *Query;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
bool CtrFound = false; bool CtrFound = false;
@ -1168,7 +1173,7 @@ 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 *****/
sprintf (Query,"(SELECT centres.InsCod,centres.PlcCod," if (asprintf (&Query,"(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"
@ -1186,8 +1191,9 @@ bool Ctr_GetDataOfCentreByCod (struct Centre *Ctr)
" AND CtrCod NOT IN" " AND CtrCod NOT IN"
" (SELECT DISTINCT CtrCod FROM usr_data))", " (SELECT DISTINCT CtrCod FROM usr_data))",
Ctr->CtrCod, Ctr->CtrCod,
Ctr->CtrCod); Ctr->CtrCod) < 0)
if (DB_QuerySELECT (Query,&mysql_res,"can not get data of a centre")) // Centre found... Lay_NotEnoughMemoryExit ();
if (DB_QuerySELECT_free (Query,&mysql_res,"can not get data of a centre")) // Centre found...
{ {
/* Get row */ /* Get row */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1247,7 +1253,7 @@ bool Ctr_GetDataOfCentreByCod (struct Centre *Ctr)
long Ctr_GetInsCodOfCentreByCod (long CtrCod) long Ctr_GetInsCodOfCentreByCod (long CtrCod)
{ {
char Query[128]; char *Query;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
long InsCod = -1L; long InsCod = -1L;
@ -1255,9 +1261,10 @@ 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 *****/
sprintf (Query,"SELECT InsCod FROM centres WHERE CtrCod=%ld", if (asprintf (&Query,"SELECT InsCod FROM centres WHERE CtrCod=%ld",
CtrCod); CtrCod) < 0)
if (DB_QuerySELECT (Query,&mysql_res,"can not get the institution of a centre") == 1) Lay_NotEnoughMemoryExit ();
if (DB_QuerySELECT_free (Query,&mysql_res,"can not get the institution of a centre") == 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);
@ -1277,7 +1284,7 @@ long Ctr_GetInsCodOfCentreByCod (long CtrCod)
void Ctr_GetShortNameOfCentreByCod (struct Centre *Ctr) void Ctr_GetShortNameOfCentreByCod (struct Centre *Ctr)
{ {
char Query[512]; char *Query;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
@ -1285,9 +1292,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 *****/
sprintf (Query,"SELECT ShortName FROM centres" if (asprintf (&Query,"SELECT ShortName FROM centres"
" WHERE CtrCod=%ld", " WHERE CtrCod=%ld",
Ctr->CtrCod); Ctr->CtrCod) < 0)
Lay_NotEnoughMemoryExit ();
if (DB_QuerySELECT (Query,&mysql_res,"can not get the short name of a centre") == 1) if (DB_QuerySELECT (Query,&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 *****/
@ -1308,7 +1316,7 @@ void Ctr_GetShortNameOfCentreByCod (struct Centre *Ctr)
static void Ctr_GetPhotoAttribution (long CtrCod,char **PhotoAttribution) static void Ctr_GetPhotoAttribution (long CtrCod,char **PhotoAttribution)
{ {
char Query[128]; char *Query;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
size_t Length; size_t Length;
@ -1317,9 +1325,11 @@ static void Ctr_GetPhotoAttribution (long CtrCod,char **PhotoAttribution)
Ctr_FreePhotoAttribution (PhotoAttribution); Ctr_FreePhotoAttribution (PhotoAttribution);
/***** Get photo attribution from database *****/ /***** Get photo attribution from database *****/
sprintf (Query,"SELECT PhotoAttribution FROM centres WHERE CtrCod=%ld", if (asprintf (&Query,"SELECT PhotoAttribution"
CtrCod); " FROM centres WHERE CtrCod=%ld",
if (DB_QuerySELECT (Query,&mysql_res,"can not get photo attribution")) CtrCod) < 0)
Lay_NotEnoughMemoryExit ();
if (DB_QuerySELECT_free (Query,&mysql_res,"can not get photo attribution"))
{ {
/* Get row */ /* Get row */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1375,7 +1385,7 @@ void Ctr_FreeListCentres (void)
void Ctr_WriteSelectorOfCentre (void) void Ctr_WriteSelectorOfCentre (void)
{ {
extern const char *Txt_Centre; extern const char *Txt_Centre;
char Query[128]; char *Query;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned NumCtrs; unsigned NumCtrs;
@ -1399,12 +1409,13 @@ void Ctr_WriteSelectorOfCentre (void)
if (Gbl.CurrentIns.Ins.InsCod > 0) if (Gbl.CurrentIns.Ins.InsCod > 0)
{ {
/***** Get centres from database *****/ /***** Get centres from database *****/
sprintf (Query,"SELECT DISTINCT CtrCod,ShortName" if (asprintf (&Query,"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) < 0)
NumCtrs = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get centres"); Lay_NotEnoughMemoryExit ();
NumCtrs = (unsigned) DB_QuerySELECT_free (Query,&mysql_res,"can not get centres");
/***** Get centres *****/ /***** Get centres *****/
for (NumCtr = 0; for (NumCtr = 0;
@ -1744,7 +1755,7 @@ void Ctr_RemoveCentre (void)
{ {
extern const char *Txt_To_remove_a_centre_you_must_first_remove_all_degrees_and_teachers_in_the_centre; extern const char *Txt_To_remove_a_centre_you_must_first_remove_all_degrees_and_teachers_in_the_centre;
extern const char *Txt_Centre_X_removed; extern const char *Txt_Centre_X_removed;
char Query[512]; char *Query;
struct Centre Ctr; struct Centre Ctr;
char PathCtr[PATH_MAX + 1]; char PathCtr[PATH_MAX + 1];
@ -1779,9 +1790,10 @@ void Ctr_RemoveCentre (void)
Fil_RemoveTree (PathCtr); Fil_RemoveTree (PathCtr);
/***** Remove centre *****/ /***** Remove centre *****/
sprintf (Query,"DELETE FROM centres WHERE CtrCod=%ld", if (asprintf (&Query,"DELETE FROM centres WHERE CtrCod=%ld",
Ctr.CtrCod); Ctr.CtrCod) < 0)
DB_QueryDELETE (Query,"can not remove a centre"); Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove a centre");
/***** 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),
@ -1872,12 +1884,13 @@ void Ctr_ContEditAfterChgCtrInConfig (void)
static void Ctr_UpdateCtrInsDB (long CtrCod,long InsCod) static void Ctr_UpdateCtrInsDB (long CtrCod,long InsCod)
{ {
char Query[128]; char *Query;
/***** Update institution in table of centres *****/ /***** Update institution in table of centres *****/
sprintf (Query,"UPDATE centres SET InsCod=%ld WHERE CtrCod=%ld", if (asprintf (&Query,"UPDATE centres SET InsCod=%ld WHERE CtrCod=%ld",
InsCod,CtrCod); InsCod,CtrCod) < 0)
DB_QueryUPDATE (Query,"can not update the institution of a centre"); Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not update the institution of a centre");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1938,11 +1951,12 @@ void Ctr_ChangeCtrPlcInConfig (void)
static void Ctr_UpdateCtrPlcDB (long CtrCod,long NewPlcCod) static void Ctr_UpdateCtrPlcDB (long CtrCod,long NewPlcCod)
{ {
char Query[256]; char *Query;
sprintf (Query,"UPDATE centres SET PlcCod=%ld WHERE CtrCod=%ld", if (asprintf (&Query,"UPDATE centres SET PlcCod=%ld WHERE CtrCod=%ld",
NewPlcCod,CtrCod); NewPlcCod,CtrCod) < 0)
DB_QueryUPDATE (Query,"can not update the place of a centre"); Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not update the place of a centre");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2066,13 +2080,14 @@ static void Ctr_RenameCentre (struct Centre *Ctr,Cns_ShrtOrFullName_t ShrtOrFull
static bool Ctr_CheckIfCtrNameExistsInIns (const char *FieldName,const char *Name,long CtrCod,long InsCod) static bool Ctr_CheckIfCtrNameExistsInIns (const char *FieldName,const char *Name,long CtrCod,long InsCod)
{ {
char Query[256 + Hie_MAX_BYTES_FULL_NAME]; char *Query;
/***** Get number of centres with a name from database *****/ /***** Get number of centres with a name from database *****/
sprintf (Query,"SELECT COUNT(*) FROM centres" if (asprintf (&Query,"SELECT COUNT(*) FROM centres"
" WHERE InsCod=%ld AND %s='%s' AND CtrCod<>%ld", " WHERE InsCod=%ld AND %s='%s' AND CtrCod<>%ld",
InsCod,FieldName,Name,CtrCod); InsCod,FieldName,Name,CtrCod) < 0)
return (DB_QueryCOUNT (Query,"can not check if the name of a centre already existed") != 0); Lay_NotEnoughMemoryExit ();
return (DB_QueryCOUNT_free (Query,"can not check if the name of a centre already existed") != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2081,12 +2096,13 @@ static bool Ctr_CheckIfCtrNameExistsInIns (const char *FieldName,const char *Nam
static void Ctr_UpdateInsNameDB (long CtrCod,const char *FieldName,const char *NewCtrName) static void Ctr_UpdateInsNameDB (long CtrCod,const char *FieldName,const char *NewCtrName)
{ {
char Query[128 + Hie_MAX_BYTES_FULL_NAME]; char *Query;
/***** Update centre changing old name by new name */ /***** Update centre changing old name by new name */
sprintf (Query,"UPDATE centres SET %s='%s' WHERE CtrCod=%ld", if (asprintf (&Query,"UPDATE centres SET %s='%s' WHERE CtrCod=%ld",
FieldName,NewCtrName,CtrCod); FieldName,NewCtrName,CtrCod) < 0)
DB_QueryUPDATE (Query,"can not update the name of a centre"); Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not update the name of a centre");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2169,12 +2185,13 @@ void Ctr_ChangeCtrWWWInConfig (void)
static void Ctr_UpdateCtrWWWDB (long CtrCod, static void Ctr_UpdateCtrWWWDB (long CtrCod,
const char NewWWW[Cns_MAX_BYTES_WWW + 1]) const char NewWWW[Cns_MAX_BYTES_WWW + 1])
{ {
char Query[256 + Cns_MAX_BYTES_WWW]; char *Query;
/***** Update database changing old WWW by new WWW *****/ /***** Update database changing old WWW by new WWW *****/
sprintf (Query,"UPDATE centres SET WWW='%s' WHERE CtrCod=%ld", if (asprintf (&Query,"UPDATE centres SET WWW='%s' WHERE CtrCod=%ld",
NewWWW,CtrCod); NewWWW,CtrCod) < 0)
DB_QueryUPDATE (Query,"can not update the web of a centre"); Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not update the web of a centre");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2184,7 +2201,7 @@ static void Ctr_UpdateCtrWWWDB (long CtrCod,
void Ctr_ChangeCtrStatus (void) void Ctr_ChangeCtrStatus (void)
{ {
extern const char *Txt_The_status_of_the_centre_X_has_changed; extern const char *Txt_The_status_of_the_centre_X_has_changed;
char Query[256]; char *Query;
Ctr_Status_t Status; Ctr_Status_t Status;
Ctr_StatusTxt_t StatusTxt; Ctr_StatusTxt_t StatusTxt;
@ -2206,9 +2223,10 @@ void Ctr_ChangeCtrStatus (void)
Ctr_GetDataOfCentreByCod (&Gbl.Ctrs.EditingCtr); Ctr_GetDataOfCentreByCod (&Gbl.Ctrs.EditingCtr);
/***** Update status in table of centres *****/ /***** Update status in table of centres *****/
sprintf (Query,"UPDATE centres SET Status=%u WHERE CtrCod=%ld", if (asprintf (&Query,"UPDATE centres SET Status=%u WHERE CtrCod=%ld",
(unsigned) Status,Gbl.Ctrs.EditingCtr.CtrCod); (unsigned) Status,Gbl.Ctrs.EditingCtr.CtrCod) < 0)
DB_QueryUPDATE (Query,"can not update the status of a centre"); Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not update the status of a centre");
Gbl.Ctrs.EditingCtr.Status = Status; Gbl.Ctrs.EditingCtr.Status = Status;
/***** Write message to show the change made /***** Write message to show the change made
@ -2481,7 +2499,7 @@ void Ctr_ReceivePhoto (void)
void Ctr_ChangeCtrPhotoAttribution (void) void Ctr_ChangeCtrPhotoAttribution (void)
{ {
char Query[256 + Img_MAX_BYTES_ATTRIBUTION]; char *Query;
char NewPhotoAttribution[Img_MAX_BYTES_ATTRIBUTION + 1]; char NewPhotoAttribution[Img_MAX_BYTES_ATTRIBUTION + 1];
/***** Get parameters from form *****/ /***** Get parameters from form *****/
@ -2489,10 +2507,11 @@ void Ctr_ChangeCtrPhotoAttribution (void)
Par_GetParToText ("Attribution",NewPhotoAttribution,Img_MAX_BYTES_ATTRIBUTION); Par_GetParToText ("Attribution",NewPhotoAttribution,Img_MAX_BYTES_ATTRIBUTION);
/***** Update the table changing old attribution by new attribution *****/ /***** Update the table changing old attribution by new attribution *****/
sprintf (Query,"UPDATE centres SET PhotoAttribution='%s'" if (asprintf (&Query,"UPDATE centres SET PhotoAttribution='%s'"
" WHERE CtrCod=%ld", " WHERE CtrCod=%ld",
NewPhotoAttribution,Gbl.CurrentCtr.Ctr.CtrCod); NewPhotoAttribution,Gbl.CurrentCtr.Ctr.CtrCod) < 0)
DB_QueryUPDATE (Query,"can not update the photo attribution of the current centre"); Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not update the photo attribution of the current centre");
/***** Show the centre information again *****/ /***** Show the centre information again *****/
Ctr_ShowConfiguration (); Ctr_ShowConfiguration ();
@ -2823,13 +2842,10 @@ static void Ctr_RecFormRequestOrCreateCtr (unsigned Status)
static void Ctr_CreateCentre (unsigned Status) static void Ctr_CreateCentre (unsigned Status)
{ {
extern const char *Txt_Created_new_centre_X; extern const char *Txt_Created_new_centre_X;
char Query[512 + char *Query;
Hie_MAX_BYTES_SHRT_NAME +
Hie_MAX_BYTES_FULL_NAME +
Cns_MAX_BYTES_WWW];
/***** Create a new centre *****/ /***** Create a new centre *****/
sprintf (Query,"INSERT INTO centres" if (asprintf (&Query,"INSERT INTO centres"
" (InsCod,PlcCod,Status,RequesterUsrCod," " (InsCod,PlcCod,Status,RequesterUsrCod,"
"ShortName,FullName,WWW,PhotoAttribution)" "ShortName,FullName,WWW,PhotoAttribution)"
" VALUES" " VALUES"
@ -2841,8 +2857,9 @@ static void Ctr_CreateCentre (unsigned Status)
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Ctrs.EditingCtr.ShrtName, Gbl.Ctrs.EditingCtr.ShrtName,
Gbl.Ctrs.EditingCtr.FullName, Gbl.Ctrs.EditingCtr.FullName,
Gbl.Ctrs.EditingCtr.WWW); Gbl.Ctrs.EditingCtr.WWW) < 0)
Gbl.Ctrs.EditingCtr.CtrCod = DB_QueryINSERTandReturnCode (Query,"can not create a new centre"); Lay_NotEnoughMemoryExit ();
Gbl.Ctrs.EditingCtr.CtrCod = DB_QueryINSERTandReturnCode_free (Query,"can not create a new centre");
/***** Write message to show the change made /***** Write message to show the change made
and put button to go to centre created *****/ and put button to go to centre created *****/
@ -2859,11 +2876,12 @@ static void Ctr_CreateCentre (unsigned Status)
unsigned Ctr_GetNumCtrsTotal (void) unsigned Ctr_GetNumCtrsTotal (void)
{ {
char Query[128]; char *Query;
/***** Get total number of centres from database *****/ /***** Get total number of centres from database *****/
sprintf (Query,"SELECT COUNT(*) FROM centres"); if (asprintf (&Query,"SELECT COUNT(*) FROM centres") < 0)
return (unsigned) DB_QueryCOUNT (Query,"can not get total number of centres"); Lay_NotEnoughMemoryExit ();
return (unsigned) DB_QueryCOUNT_free (Query,"can not get total number of centres");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2872,14 +2890,15 @@ unsigned Ctr_GetNumCtrsTotal (void)
unsigned Ctr_GetNumCtrsInCty (long CtyCod) unsigned Ctr_GetNumCtrsInCty (long CtyCod)
{ {
char Query[256]; char *Query;
/***** Get number of centres of a country from database *****/ /***** Get number of centres of a country from database *****/
sprintf (Query,"SELECT COUNT(*) FROM institutions,centres" if (asprintf (&Query,"SELECT COUNT(*) FROM institutions,centres"
" WHERE institutions.CtyCod=%ld" " WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod", " AND institutions.InsCod=centres.InsCod",
CtyCod); CtyCod) < 0)
return (unsigned) DB_QueryCOUNT (Query,"can not get number of centres in a country"); Lay_NotEnoughMemoryExit ();
return (unsigned) DB_QueryCOUNT_free (Query,"can not get number of centres in a country");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2888,14 +2907,14 @@ unsigned Ctr_GetNumCtrsInCty (long CtyCod)
unsigned Ctr_GetNumCtrsInIns (long InsCod) unsigned Ctr_GetNumCtrsInIns (long InsCod)
{ {
char Query[128]; char *Query;
/***** Get number of centres of an institution from database *****/ /***** Get number of centres of an institution from database *****/
sprintf (Query,"SELECT COUNT(*) FROM centres" if (asprintf (&Query,"SELECT COUNT(*) FROM centres"
" WHERE InsCod=%ld", " WHERE InsCod=%ld",
InsCod); InsCod) < 0)
return (unsigned) DB_QueryCOUNT (Query,"can not get number of centres in an institution"); Lay_NotEnoughMemoryExit ();
return (unsigned) DB_QueryCOUNT_free (Query,"can not get number of centres in an institution");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2904,13 +2923,14 @@ unsigned Ctr_GetNumCtrsInIns (long InsCod)
unsigned Ctr_GetNumCtrsInPlc (long PlcCod) unsigned Ctr_GetNumCtrsInPlc (long PlcCod)
{ {
char Query[256]; char *Query;
/***** Get number of centres (of the current institution) in a place *****/ /***** Get number of centres (of the current institution) in a place *****/
sprintf (Query,"SELECT COUNT(*) FROM centres" if (asprintf (&Query,"SELECT COUNT(*) FROM centres"
" WHERE InsCod=%ld AND PlcCod=%ld", " WHERE InsCod=%ld AND PlcCod=%ld",
Gbl.CurrentIns.Ins.InsCod,PlcCod); Gbl.CurrentIns.Ins.InsCod,PlcCod) < 0)
return (unsigned) DB_QueryCOUNT (Query,"can not get the number of centres in a place"); Lay_NotEnoughMemoryExit ();
return (unsigned) DB_QueryCOUNT_free (Query,"can not get the number of centres in a place");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2919,15 +2939,16 @@ unsigned Ctr_GetNumCtrsInPlc (long PlcCod)
unsigned Ctr_GetNumCtrsWithDegs (const char *SubQuery) unsigned Ctr_GetNumCtrsWithDegs (const char *SubQuery)
{ {
char Query[512]; char *Query;
/***** Get number of centres with degrees from database *****/ /***** Get number of centres with degrees from database *****/
sprintf (Query,"SELECT COUNT(DISTINCT centres.CtrCod)" if (asprintf (&Query,"SELECT COUNT(DISTINCT centres.CtrCod)"
" FROM institutions,centres,degrees" " FROM institutions,centres,degrees"
" WHERE %sinstitutions.InsCod=centres.InsCod" " WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod", " AND centres.CtrCod=degrees.CtrCod",
SubQuery); SubQuery) < 0)
return (unsigned) DB_QueryCOUNT (Query,"can not get number of centres with degrees"); Lay_NotEnoughMemoryExit ();
return (unsigned) DB_QueryCOUNT_free (Query,"can not get number of centres with degrees");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2936,16 +2957,17 @@ unsigned Ctr_GetNumCtrsWithDegs (const char *SubQuery)
unsigned Ctr_GetNumCtrsWithCrss (const char *SubQuery) unsigned Ctr_GetNumCtrsWithCrss (const char *SubQuery)
{ {
char Query[512]; char *Query;
/***** Get number of centres with courses from database *****/ /***** Get number of centres with courses from database *****/
sprintf (Query,"SELECT COUNT(DISTINCT centres.CtrCod)" if (asprintf (&Query,"SELECT COUNT(DISTINCT centres.CtrCod)"
" FROM institutions,centres,degrees,courses" " FROM institutions,centres,degrees,courses"
" WHERE %sinstitutions.InsCod=centres.InsCod" " WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod" " AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod", " AND degrees.DegCod=courses.DegCod",
SubQuery); SubQuery) < 0)
return (unsigned) DB_QueryCOUNT (Query,"can not get number of centres with courses"); Lay_NotEnoughMemoryExit ();
return (unsigned) DB_QueryCOUNT_free (Query,"can not get number of centres with courses");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2954,18 +2976,19 @@ 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)
{ {
char Query[512]; char *Query;
/***** Get number of centres with users from database *****/ /***** Get number of centres with users from database *****/
sprintf (Query,"SELECT COUNT(DISTINCT centres.CtrCod)" if (asprintf (&Query,"SELECT COUNT(DISTINCT centres.CtrCod)"
" FROM institutions,centres,degrees,courses,crs_usr" " FROM institutions,centres,degrees,courses,crs_usr"
" WHERE %sinstitutions.InsCod=centres.InsCod" " WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod" " AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod" " AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod" " AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.Role=%u", " AND crs_usr.Role=%u",
SubQuery,(unsigned) Role); SubQuery,(unsigned) Role) < 0)
return (unsigned) DB_QueryCOUNT (Query,"can not get number of centres with users"); Lay_NotEnoughMemoryExit ();
return (unsigned) DB_QueryCOUNT_free (Query,"can not get number of centres with users");
} }
/*****************************************************************************/ /*****************************************************************************/

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.10 (2018-10-19)" #define Log_PLATFORM_VERSION "SWAD 18.7.11 (2018-10-19)"
#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.11: Oct 19, 2018 Some sprintf for database queries changed by asprintf. (236884 lines)
Version 18.7.10: Oct 19, 2018 Some sprintf for database queries changed by asprintf. (236856 lines) Version 18.7.10: Oct 19, 2018 Some sprintf for database queries changed by asprintf. (236856 lines)
Version 18.7.9: Oct 19, 2018 Some sprintf for database queries changed by asprintf. (236836 lines) Version 18.7.9: Oct 19, 2018 Some sprintf for database queries changed by asprintf. (236836 lines)
Version 18.7.8: Oct 18, 2018 Some sprintf for database queries changed by asprintf. (236788 lines) Version 18.7.8: Oct 18, 2018 Some sprintf for database queries changed by asprintf. (236788 lines)