Version19.112.23

This commit is contained in:
Antonio Cañas Vargas 2020-01-07 22:07:06 +01:00
parent a8e670490f
commit 41964c4083
20 changed files with 430 additions and 364 deletions

View File

@ -582,7 +582,7 @@ void Ctr_GetListCentres (long InsCod)
{ {
Ctr = &(Gbl.Hierarchy.Ins.Ctrs.Lst[NumCtr]); Ctr = &(Gbl.Hierarchy.Ins.Ctrs.Lst[NumCtr]);
/* Get next centre */ /* Get centre data */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
Ctr_GetDataOfCentreFromRow (Ctr,row); Ctr_GetDataOfCentreFromRow (Ctr,row);
} }

View File

@ -583,7 +583,7 @@ static void CtrCfg_Institution (bool PrintView,bool PutForm)
if (PutForm) if (PutForm)
{ {
/* Get list of institutions of the current country */ /* Get list of institutions of the current country */
Ins_GetListInstitutions (Gbl.Hierarchy.Cty.CtyCod); Ins_GetBasicListOfInstitutions (Gbl.Hierarchy.Cty.CtyCod);
/* Put form to select institution */ /* Put form to select institution */
Frm_StartForm (ActChgCtrInsCfg); Frm_StartForm (ActChgCtrInsCfg);

View File

@ -492,7 +492,7 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - *
En OpenSWAD: En OpenSWAD:
ps2pdf source.ps destination.pdf ps2pdf source.ps destination.pdf
*/ */
#define Log_PLATFORM_VERSION "SWAD 19.112.22 (2020-01-07)" #define Log_PLATFORM_VERSION "SWAD 19.112.23 (2020-01-07)"
#define CSS_FILE "swad19.112.css" #define CSS_FILE "swad19.112.css"
#define JS_FILE "swad19.91.1.js" #define JS_FILE "swad19.91.1.js"
/* /*
@ -500,8 +500,8 @@ ps2pdf source.ps destination.pdf
// TODO: Impedir la creación y edición de proyectos si no son editables. // TODO: Impedir la creación y edición de proyectos si no son editables.
// TODO: No se puede entrar con DNI '1' suponiendo que no tenga password ¿por qué? // TODO: No se puede entrar con DNI '1' suponiendo que no tenga password ¿por qué?
// TODO: Mapas más estrechos en móvil // TODO: Mapas más estrechos en móvil
// TODO: Quitar todos los EXTRA_DATA.
Version 19.112.23:Jan 07, 2020 Optimization in number of centres in an institution. (278807 lines)
Version 19.112.22:Jan 07, 2020 Optimization in number of centres in a country. (278761 lines) Version 19.112.22:Jan 07, 2020 Optimization in number of centres in a country. (278761 lines)
Version 19.112.21:Jan 07, 2020 Optimization in number of degrees in a country. (278741 lines) Version 19.112.21:Jan 07, 2020 Optimization in number of degrees in a country. (278741 lines)
Version 19.112.20:Jan 07, 2020 Optimization in number of courses in a country. (278724 lines) Version 19.112.20:Jan 07, 2020 Optimization in number of courses in a country. (278724 lines)

View File

@ -161,7 +161,7 @@ void Cty_SeeCtyWithPendingInss (void)
Gbl.ColorRows[Gbl.RowEvenOdd]; Gbl.ColorRows[Gbl.RowEvenOdd];
/* Get data of country */ /* Get data of country */
Cty_GetDataOfCountryByCod (&Cty,Cty_GET_BASIC_DATA); Cty_GetDataOfCountryByCod (&Cty);
HTM_TR_Begin (NULL); HTM_TR_Begin (NULL);
@ -212,7 +212,7 @@ void Cty_ListCountries1 (void)
Cty_GetParamCtyOrder (); Cty_GetParamCtyOrder ();
/***** Get list of countries *****/ /***** Get list of countries *****/
Cty_GetListCountries (Cty_GET_EXTRA_DATA); Cty_GetFullListOfCountries ();
} }
void Cty_ListCountries2 (void) void Cty_ListCountries2 (void)
@ -658,7 +658,7 @@ static void Cty_EditCountriesInternal (void)
/***** Get list of countries *****/ /***** Get list of countries *****/
Gbl.Hierarchy.Sys.Ctys.SelectedOrder = Cty_ORDER_BY_COUNTRY; Gbl.Hierarchy.Sys.Ctys.SelectedOrder = Cty_ORDER_BY_COUNTRY;
Cty_GetListCountries (Cty_GET_EXTRA_DATA); Cty_GetFullListOfCountries ();
/***** Write menu to select country *****/ /***** Write menu to select country *****/
Hie_WriteMenuHierarchy (); Hie_WriteMenuHierarchy ();
@ -709,20 +709,12 @@ static void Cty_PutIconToViewCountries (void)
} }
/*****************************************************************************/ /*****************************************************************************/
/************************** List all the countries ***************************/ /********** Get basic list of countries ordered by name of country ***********/
/*****************************************************************************/ /*****************************************************************************/
#define Cty_MAX_BYTES_SUBQUERY_CTYS ((1 + Lan_NUM_LANGUAGES) * 32) void Cty_GetBasicListOfCountries (void)
void Cty_GetListCountries (Cty_GetExtraData_t GetExtraData)
{ {
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES]; extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
char StrField[32];
char SubQueryNam1[Cty_MAX_BYTES_SUBQUERY_CTYS + 1];
char SubQueryNam2[Cty_MAX_BYTES_SUBQUERY_CTYS + 1];
char SubQueryWWW1[Cty_MAX_BYTES_SUBQUERY_CTYS + 1];
char SubQueryWWW2[Cty_MAX_BYTES_SUBQUERY_CTYS + 1];
char *OrderBySubQuery = NULL;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows = 0; unsigned long NumRows = 0;
@ -731,88 +723,18 @@ void Cty_GetListCountries (Cty_GetExtraData_t GetExtraData)
Lan_Language_t Lan; Lan_Language_t Lan;
/***** Get countries from database *****/ /***** Get countries from database *****/
switch (GetExtraData) NumRows = DB_QuerySELECT (&mysql_res,"can not get countries",
{ "SELECT CtyCod,Alpha2,Name_%s"
case Cty_GET_BASIC_DATA: " FROM countries ORDER BY Name_%s",
NumRows = DB_QuerySELECT (&mysql_res,"can not get countries", Lan_STR_LANG_ID[Gbl.Prefs.Language],
"SELECT CtyCod,Alpha2,Name_%s" Lan_STR_LANG_ID[Gbl.Prefs.Language]);
" FROM countries ORDER BY Name_%s",
Lan_STR_LANG_ID[Gbl.Prefs.Language],
Lan_STR_LANG_ID[Gbl.Prefs.Language]);
break;
case Cty_GET_EXTRA_DATA:
SubQueryNam1[0] = '\0';
SubQueryNam2[0] = '\0';
SubQueryWWW1[0] = '\0';
SubQueryWWW2[0] = '\0';
for (Lan = (Lan_Language_t) 1;
Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES;
Lan++)
{
snprintf (StrField,sizeof (StrField),
"countries.Name_%s,",
Lan_STR_LANG_ID[Lan]);
Str_Concat (SubQueryNam1,StrField,
Cty_MAX_BYTES_SUBQUERY_CTYS);
snprintf (StrField,sizeof (StrField),
"Name_%s,",
Lan_STR_LANG_ID[Lan]);
Str_Concat (SubQueryNam2,StrField,
Cty_MAX_BYTES_SUBQUERY_CTYS);
snprintf (StrField,sizeof (StrField),
"countries.WWW_%s,",
Lan_STR_LANG_ID[Lan]);
Str_Concat (SubQueryWWW1,StrField,
Cty_MAX_BYTES_SUBQUERY_CTYS);
snprintf (StrField,sizeof (StrField),
"WWW_%s,",
Lan_STR_LANG_ID[Lan]);
Str_Concat (SubQueryWWW2,StrField,
Cty_MAX_BYTES_SUBQUERY_CTYS);
}
switch (Gbl.Hierarchy.Sys.Ctys.SelectedOrder)
{
case Cty_ORDER_BY_COUNTRY:
if (asprintf (&OrderBySubQuery,"Name_%s",
Lan_STR_LANG_ID[Gbl.Prefs.Language]) < 0)
Lay_NotEnoughMemoryExit ();
break;
case Cty_ORDER_BY_NUM_USRS:
if (asprintf (&OrderBySubQuery,"NumUsrs DESC,Name_%s",
Lan_STR_LANG_ID[Gbl.Prefs.Language]) < 0)
Lay_NotEnoughMemoryExit ();
break;
}
NumRows = DB_QuerySELECT (&mysql_res,"can not get countries",
"(SELECT countries.CtyCod,countries.Alpha2,"
"%s%sCOUNT(*) AS NumUsrs"
" FROM countries,usr_data"
" WHERE countries.CtyCod=usr_data.CtyCod"
" GROUP BY countries.CtyCod)"
" UNION "
"(SELECT CtyCod,Alpha2,%s%s0 AS NumUsrs"
" FROM countries"
" WHERE CtyCod NOT IN"
" (SELECT DISTINCT CtyCod FROM usr_data))"
" ORDER BY %s",
SubQueryNam1,SubQueryWWW1,
SubQueryNam2,SubQueryWWW2,OrderBySubQuery);
break;
}
/***** Free memory for subquery *****/
if (OrderBySubQuery)
free (OrderBySubQuery);
if (NumRows) // Countries found... if (NumRows) // Countries found...
{ {
Gbl.Hierarchy.Sys.Ctys.Num = (unsigned) NumRows; Gbl.Hierarchy.Sys.Ctys.Num = (unsigned) NumRows;
/***** Create list with countries *****/ /***** Create list with countries *****/
if ((Gbl.Hierarchy.Sys.Ctys.Lst = (struct Country *) calloc (NumRows,sizeof (struct Country))) == NULL) if ((Gbl.Hierarchy.Sys.Ctys.Lst = (struct Country *)
calloc (NumRows,sizeof (struct Country))) == NULL)
Lay_NotEnoughMemoryExit (); Lay_NotEnoughMemoryExit ();
/***** Get the countries *****/ /***** Get the countries *****/
@ -833,43 +755,168 @@ void Cty_GetListCountries (Cty_GetExtraData_t GetExtraData)
Str_Copy (Cty->Alpha2,row[1], Str_Copy (Cty->Alpha2,row[1],
2); 2);
switch (GetExtraData) for (Lan = (Lan_Language_t) 1;
{ Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES;
case Cty_GET_BASIC_DATA: Lan++)
for (Lan = (Lan_Language_t) 1; {
Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES; Cty->Name[Lan][0] = '\0';
Lan++) Cty->WWW[Lan][0] = '\0';
{ }
Cty->Name[Lan][0] = '\0';
Cty->WWW[Lan][0] = '\0';
}
Cty->NumUsrsWhoClaimToBelongToCty.Valid = false;
Cty->Inss.Num = 0;
/* Get the name of the country in current language */ /* Get the name of the country in current language */
Str_Copy (Cty->Name[Gbl.Prefs.Language],row[2], Str_Copy (Cty->Name[Gbl.Prefs.Language],row[2],
Cty_MAX_BYTES_NAME); Cty_MAX_BYTES_NAME);
break;
case Cty_GET_EXTRA_DATA:
/* Get the name of the country in several languages */
for (Lan = (Lan_Language_t) 1;
Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES;
Lan++)
{
Str_Copy (Cty->Name[Lan],row[1 + Lan],
Cty_MAX_BYTES_NAME);
Str_Copy (Cty->WWW[Lan],row[1 + Lan_NUM_LANGUAGES + Lan],
Cns_MAX_BYTES_WWW);
}
/* Get number of users who claim to belong to this country */ /* Number of users who claim to belong to country not got */
if (sscanf (row[1 + Lan_NUM_LANGUAGES * 2 + 1],"%u", Cty->NumUsrsWhoClaimToBelongToCty.Valid = false;
&(Cty->NumUsrsWhoClaimToBelongToCty.NumUsrs)) == 1)
Cty->NumUsrsWhoClaimToBelongToCty.Valid = true; /* Reset other fields */
else Cty->Inss.Num = 0;
Cty->NumUsrsWhoClaimToBelongToCty.Valid = false; Cty->Inss.Lst = NULL;
break; }
} }
else
Gbl.Hierarchy.Sys.Ctys.Num = 0;
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/********** Get full list of countries with names in all languages ***********/
/********** and number of users who claim to belong to them ***********/
/*****************************************************************************/
#define Cty_MAX_BYTES_SUBQUERY_CTYS ((1 + Lan_NUM_LANGUAGES) * 32)
void Cty_GetFullListOfCountries (void)
{
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
char StrField[32];
char SubQueryNam1[Cty_MAX_BYTES_SUBQUERY_CTYS + 1];
char SubQueryNam2[Cty_MAX_BYTES_SUBQUERY_CTYS + 1];
char SubQueryWWW1[Cty_MAX_BYTES_SUBQUERY_CTYS + 1];
char SubQueryWWW2[Cty_MAX_BYTES_SUBQUERY_CTYS + 1];
char *OrderBySubQuery = NULL;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows = 0;
unsigned NumCty;
struct Country *Cty;
Lan_Language_t Lan;
/***** Get countries from database *****/
SubQueryNam1[0] = '\0';
SubQueryNam2[0] = '\0';
SubQueryWWW1[0] = '\0';
SubQueryWWW2[0] = '\0';
for (Lan = (Lan_Language_t) 1;
Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES;
Lan++)
{
snprintf (StrField,sizeof (StrField),
"countries.Name_%s,",
Lan_STR_LANG_ID[Lan]);
Str_Concat (SubQueryNam1,StrField,
Cty_MAX_BYTES_SUBQUERY_CTYS);
snprintf (StrField,sizeof (StrField),
"Name_%s,",
Lan_STR_LANG_ID[Lan]);
Str_Concat (SubQueryNam2,StrField,
Cty_MAX_BYTES_SUBQUERY_CTYS);
snprintf (StrField,sizeof (StrField),
"countries.WWW_%s,",
Lan_STR_LANG_ID[Lan]);
Str_Concat (SubQueryWWW1,StrField,
Cty_MAX_BYTES_SUBQUERY_CTYS);
snprintf (StrField,sizeof (StrField),
"WWW_%s,",
Lan_STR_LANG_ID[Lan]);
Str_Concat (SubQueryWWW2,StrField,
Cty_MAX_BYTES_SUBQUERY_CTYS);
}
/* Build order subquery */
switch (Gbl.Hierarchy.Sys.Ctys.SelectedOrder)
{
case Cty_ORDER_BY_COUNTRY:
if (asprintf (&OrderBySubQuery,"Name_%s",
Lan_STR_LANG_ID[Gbl.Prefs.Language]) < 0)
Lay_NotEnoughMemoryExit ();
break;
case Cty_ORDER_BY_NUM_USRS:
if (asprintf (&OrderBySubQuery,"NumUsrs DESC,Name_%s",
Lan_STR_LANG_ID[Gbl.Prefs.Language]) < 0)
Lay_NotEnoughMemoryExit ();
break;
default:
Lay_WrongOrderExit ();
}
/* Query database */
NumRows = DB_QuerySELECT (&mysql_res,"can not get countries",
"(SELECT countries.CtyCod,countries.Alpha2,"
"%s%sCOUNT(*) AS NumUsrs"
" FROM countries,usr_data"
" WHERE countries.CtyCod=usr_data.CtyCod"
" GROUP BY countries.CtyCod)"
" UNION "
"(SELECT CtyCod,Alpha2,%s%s0 AS NumUsrs"
" FROM countries"
" WHERE CtyCod NOT IN"
" (SELECT DISTINCT CtyCod FROM usr_data))"
" ORDER BY %s",
SubQueryNam1,SubQueryWWW1,
SubQueryNam2,SubQueryWWW2,OrderBySubQuery);
/* Free memory for subquery */
free (OrderBySubQuery);
if (NumRows) // Countries found...
{
Gbl.Hierarchy.Sys.Ctys.Num = (unsigned) NumRows;
/***** Create list with countries *****/
if ((Gbl.Hierarchy.Sys.Ctys.Lst = (struct Country *)
calloc (NumRows,sizeof (struct Country))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the countries *****/
for (NumCty = 0;
NumCty < Gbl.Hierarchy.Sys.Ctys.Num;
NumCty++)
{
Cty = &(Gbl.Hierarchy.Sys.Ctys.Lst[NumCty]);
/* Get next country */
row = mysql_fetch_row (mysql_res);
/* Get numerical country code (row[0]) */
if ((Cty->CtyCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong code of country.");
/* Get Alpha-2 country code (row[1]) */
Str_Copy (Cty->Alpha2,row[1],
2);
/* Get the name of the country in several languages */
for (Lan = (Lan_Language_t) 1;
Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES;
Lan++)
{
Str_Copy (Cty->Name[Lan],row[1 + Lan],
Cty_MAX_BYTES_NAME);
Str_Copy (Cty->WWW[Lan],row[1 + Lan_NUM_LANGUAGES + Lan],
Cns_MAX_BYTES_WWW);
}
/* Get number of users who claim to belong to this country */
if (sscanf (row[1 + Lan_NUM_LANGUAGES * 2 + 1],"%u",
&(Cty->NumUsrsWhoClaimToBelongToCty.NumUsrs)) == 1)
Cty->NumUsrsWhoClaimToBelongToCty.Valid = true;
else
Cty->NumUsrsWhoClaimToBelongToCty.Valid = false;
} }
} }
else else
@ -947,7 +994,7 @@ void Cty_WriteCountryName (long CtyCod,const char *ClassLink)
Act_GetBrowserTab (Gbl.Action.Act) == Act_BRW_1ST_TAB; // Only in main browser tab Act_GetBrowserTab (Gbl.Action.Act) == Act_BRW_1ST_TAB; // Only in main browser tab
/***** Get country name *****/ /***** Get country name *****/
Cty_GetCountryName (CtyCod,CtyName); Cty_GetCountryName (CtyCod,Gbl.Prefs.Language,CtyName);
if (PutForm) if (PutForm)
{ {
@ -968,15 +1015,10 @@ void Cty_WriteCountryName (long CtyCod,const char *ClassLink)
/***************** Get basic data of country given its code ******************/ /***************** Get basic data of country given its code ******************/
/*****************************************************************************/ /*****************************************************************************/
bool Cty_GetDataOfCountryByCod (struct Country *Cty,Cty_GetExtraData_t GetExtraData) bool Cty_GetDataOfCountryByCod (struct Country *Cty)
{ {
extern const char *Txt_Another_country; extern const char *Txt_Another_country;
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES]; extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
char StrField[32];
char SubQueryNam1[Cty_MAX_BYTES_SUBQUERY_CTYS + 1];
char SubQueryNam2[Cty_MAX_BYTES_SUBQUERY_CTYS + 1];
char SubQueryWWW1[Cty_MAX_BYTES_SUBQUERY_CTYS + 1];
char SubQueryWWW2[Cty_MAX_BYTES_SUBQUERY_CTYS + 1];
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows = 0; unsigned long NumRows = 0;
@ -1016,55 +1058,13 @@ bool Cty_GetDataOfCountryByCod (struct Country *Cty,Cty_GetExtraData_t GetExtraD
// Here Cty->CtyCod > 0 // Here Cty->CtyCod > 0
/***** Get data of a country from database *****/ /***** Get data of a country from database *****/
switch (GetExtraData) NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a country",
{ "SELECT Alpha2,Name_%s,WWW_%s"
case Cty_GET_BASIC_DATA: " FROM countries"
NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a country", " WHERE CtyCod='%03ld'",
"SELECT Alpha2,Name_%s,WWW_%s" Lan_STR_LANG_ID[Gbl.Prefs.Language],
" FROM countries" Lan_STR_LANG_ID[Gbl.Prefs.Language],
" WHERE CtyCod='%03ld'", Cty->CtyCod);
Lan_STR_LANG_ID[Gbl.Prefs.Language],
Lan_STR_LANG_ID[Gbl.Prefs.Language],
Cty->CtyCod);
break;
case Cty_GET_EXTRA_DATA:
SubQueryNam1[0] = '\0';
SubQueryNam2[0] = '\0';
SubQueryWWW1[0] = '\0';
SubQueryWWW2[0] = '\0';
for (Lan = (Lan_Language_t) 1;
Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES;
Lan++)
{
snprintf (StrField,sizeof (StrField),
",countries.Name_%s",
Lan_STR_LANG_ID[Lan]);
Str_Concat (SubQueryNam1,StrField,
Cty_MAX_BYTES_SUBQUERY_CTYS);
snprintf (StrField,sizeof (StrField),
",Name_%s",
Lan_STR_LANG_ID[Lan]);
Str_Concat (SubQueryNam2,StrField,
Cty_MAX_BYTES_SUBQUERY_CTYS);
snprintf (StrField,sizeof (StrField),
",countries.WWW_%s",
Lan_STR_LANG_ID[Lan]);
Str_Concat (SubQueryWWW1,StrField,
Cty_MAX_BYTES_SUBQUERY_CTYS);
snprintf (StrField,sizeof (StrField),
",WWW_%s",
Lan_STR_LANG_ID[Lan]);
Str_Concat (SubQueryWWW2,StrField,
Cty_MAX_BYTES_SUBQUERY_CTYS);
}
NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a country",
"SELECT Alpha2,%s%s"
" FROM countries"
" WHERE CtyCod='%03ld'",
SubQueryNam2,SubQueryWWW2,Cty->CtyCod);
break;
}
/***** Count number of rows in result *****/ /***** Count number of rows in result *****/
if (NumRows) // Country found... if (NumRows) // Country found...
@ -1078,28 +1078,11 @@ bool Cty_GetDataOfCountryByCod (struct Country *Cty,Cty_GetExtraData_t GetExtraD
Str_Copy (Cty->Alpha2,row[0], Str_Copy (Cty->Alpha2,row[0],
2); 2);
switch (GetExtraData) /* Get name and WWW of the country in current language */
{ Str_Copy (Cty->Name[Gbl.Prefs.Language],row[1],
case Cty_GET_BASIC_DATA: Cty_MAX_BYTES_NAME);
/* Get name and WWW of the country in current language */ Str_Copy (Cty->WWW[Gbl.Prefs.Language],row[2],
Str_Copy (Cty->Name[Gbl.Prefs.Language],row[1], Cns_MAX_BYTES_WWW);
Cty_MAX_BYTES_NAME);
Str_Copy (Cty->WWW[Gbl.Prefs.Language],row[2],
Cns_MAX_BYTES_WWW);
break;
case Cty_GET_EXTRA_DATA:
/* Get name and WWW of the country in several languages */
for (Lan = (Lan_Language_t) 1;
Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES;
Lan++)
{
Str_Copy (Cty->Name[Lan],row[Lan],
Cty_MAX_BYTES_NAME);
Str_Copy (Cty->WWW[Lan],row[Lan_NUM_LANGUAGES + Lan],
Cns_MAX_BYTES_WWW);
}
break;
}
} }
else else
CtyFound = false; CtyFound = false;
@ -1116,11 +1099,13 @@ bool Cty_GetDataOfCountryByCod (struct Country *Cty,Cty_GetExtraData_t GetExtraD
void Cty_FlushCacheCountryName (void) void Cty_FlushCacheCountryName (void)
{ {
Gbl.Cache.CountryName.CtyCod = -1L; Gbl.Cache.CountryName.CtyCod = -1L;
Gbl.Cache.CountryName.Language = Lan_LANGUAGE_UNKNOWN;
Gbl.Cache.CountryName.CtyName[0] = '\0'; Gbl.Cache.CountryName.CtyName[0] = '\0';
} }
void Cty_GetCountryName (long CtyCod,char CtyName[Cty_MAX_BYTES_NAME + 1]) void Cty_GetCountryName (long CtyCod,Lan_Language_t Language,
char CtyName[Cty_MAX_BYTES_NAME + 1])
{ {
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES]; extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
@ -1134,7 +1119,8 @@ void Cty_GetCountryName (long CtyCod,char CtyName[Cty_MAX_BYTES_NAME + 1])
} }
/***** 2. Fast check: If cached... *****/ /***** 2. Fast check: If cached... *****/
if (CtyCod == Gbl.Cache.CountryName.CtyCod) if (CtyCod == Gbl.Cache.CountryName.CtyCod &&
Language == Gbl.Cache.CountryName.Language)
{ {
Str_Copy (CtyName,Gbl.Cache.CountryName.CtyName, Str_Copy (CtyName,Gbl.Cache.CountryName.CtyName,
Cty_MAX_BYTES_NAME); Cty_MAX_BYTES_NAME);
@ -1142,11 +1128,12 @@ void Cty_GetCountryName (long CtyCod,char CtyName[Cty_MAX_BYTES_NAME + 1])
} }
/***** 3. Slow: get country name from database *****/ /***** 3. Slow: get country name from database *****/
Gbl.Cache.CountryName.CtyCod = CtyCod; Gbl.Cache.CountryName.CtyCod = CtyCod;
Gbl.Cache.CountryName.Language = Language;
if (DB_QuerySELECT (&mysql_res,"can not get the name of a country", if (DB_QuerySELECT (&mysql_res,"can not get the name of a country",
"SELECT Name_%s FROM countries WHERE CtyCod='%03ld'", "SELECT Name_%s FROM countries WHERE CtyCod='%03ld'",
Lan_STR_LANG_ID[Gbl.Prefs.Language],CtyCod)) // Country found... Lan_STR_LANG_ID[Language],CtyCod)) // Country found...
{ {
/* Get row */ /* Get row */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1346,7 +1333,7 @@ void Cty_RemoveCountry (void)
Cty_EditingCty->CtyCod = Cty_GetAndCheckParamOtherCtyCod (0); Cty_EditingCty->CtyCod = Cty_GetAndCheckParamOtherCtyCod (0);
/***** Get data of the country from database *****/ /***** Get data of the country from database *****/
Cty_GetDataOfCountryByCod (Cty_EditingCty,Cty_GET_EXTRA_DATA); Cty_GetDataOfCountryByCod (Cty_EditingCty);
/***** Check if this country has users *****/ /***** Check if this country has users *****/
if (Ins_GetNumInssInCty (Cty_EditingCty->CtyCod)) // Country has institutions ==> don't remove if (Ins_GetNumInssInCty (Cty_EditingCty->CtyCod)) // Country has institutions ==> don't remove
@ -1413,13 +1400,15 @@ void Cty_RenameCountry (void)
Par_GetParToText ("Name",NewCtyName,Cty_MAX_BYTES_NAME); Par_GetParToText ("Name",NewCtyName,Cty_MAX_BYTES_NAME);
/***** Get from the database the data of the country *****/ /***** Get from the database the data of the country *****/
Cty_GetDataOfCountryByCod (Cty_EditingCty,Cty_GET_EXTRA_DATA); Cty_GetDataOfCountryByCod (Cty_EditingCty);
/***** Check if new name is empty *****/ /***** Check if new name is empty *****/
if (NewCtyName[0]) if (NewCtyName[0])
{ {
/***** Check if old and new names are the same /***** Check if old and new names are the same
(this happens when return is pressed without changes) *****/ (this happens when return is pressed without changes) *****/
Cty_GetCountryName (Cty_EditingCty->CtyCod,Language,
Cty_EditingCty->Name[Language]);
if (strcmp (Cty_EditingCty->Name[Language],NewCtyName)) // Different names if (strcmp (Cty_EditingCty->Name[Language],NewCtyName)) // Different names
{ {
/***** If country was in database... *****/ /***** If country was in database... *****/
@ -1537,7 +1526,7 @@ void Cty_ChangeCtyWWW (void)
Par_GetParToText ("WWW",NewWWW,Cns_MAX_BYTES_WWW); Par_GetParToText ("WWW",NewWWW,Cns_MAX_BYTES_WWW);
/***** Get from the database the data of the country *****/ /***** Get from the database the data of the country *****/
Cty_GetDataOfCountryByCod (Cty_EditingCty,Cty_GET_EXTRA_DATA); Cty_GetDataOfCountryByCod (Cty_EditingCty);
/***** Update the table changing old WWW by new WWW *****/ /***** Update the table changing old WWW by new WWW *****/
DB_QueryUPDATE ("can not update the web of a country", DB_QueryUPDATE ("can not update the web of a country",
@ -2023,7 +2012,7 @@ void Cty_ListCtysFound (MYSQL_RES **mysql_res,unsigned NumCtys)
Cty_PutHeadCountriesForSeeing (false); // Order not selectable Cty_PutHeadCountriesForSeeing (false); // Order not selectable
/***** List the countries (one row per country) *****/ /***** List the countries (one row per country) *****/
for (NumCty = 1; for (NumCty = 1;
NumCty <= NumCtys; NumCty <= NumCtys;
NumCty++) NumCty++)
{ {
@ -2034,7 +2023,7 @@ void Cty_ListCtysFound (MYSQL_RES **mysql_res,unsigned NumCtys)
Cty.CtyCod = Str_ConvertStrCodToLongCod (row[0]); Cty.CtyCod = Str_ConvertStrCodToLongCod (row[0]);
/* Get data of country */ /* Get data of country */
Cty_GetDataOfCountryByCod (&Cty,Cty_GET_EXTRA_DATA); Cty_GetDataOfCountryByCod (&Cty);
/* Write data of this country */ /* Write data of this country */
Cty_ListOneCountryForSeeing (&Cty,NumCty); Cty_ListOneCountryForSeeing (&Cty,NumCty);

View File

@ -72,12 +72,6 @@ typedef enum
} Cty_Order_t; } Cty_Order_t;
#define Cty_ORDER_DEFAULT Cty_ORDER_BY_NUM_USRS #define Cty_ORDER_DEFAULT Cty_ORDER_BY_NUM_USRS
typedef enum
{
Cty_GET_BASIC_DATA,
Cty_GET_EXTRA_DATA,
} Cty_GetExtraData_t;
/*****************************************************************************/ /*****************************************************************************/
/***************************** Public prototypes *****************************/ /***************************** Public prototypes *****************************/
/*****************************************************************************/ /*****************************************************************************/
@ -100,13 +94,15 @@ bool Cty_CheckIfCountryPhotoExists (struct Country *Cty);
void Cty_WriteScriptGoogleGeochart (void); void Cty_WriteScriptGoogleGeochart (void);
void Cty_PutHiddenParamCtyOrder (void); void Cty_PutHiddenParamCtyOrder (void);
void Cty_EditCountries (void); void Cty_EditCountries (void);
void Cty_GetListCountries (Cty_GetExtraData_t GetExtraData); void Cty_GetBasicListOfCountries (void);
void Cty_GetFullListOfCountries (void);
void Cty_FreeListCountries (void); void Cty_FreeListCountries (void);
void Cty_WriteSelectorOfCountry (void); void Cty_WriteSelectorOfCountry (void);
void Cty_WriteCountryName (long CtyCod,const char *ClassLink); void Cty_WriteCountryName (long CtyCod,const char *ClassLink);
bool Cty_GetDataOfCountryByCod (struct Country *Cty,Cty_GetExtraData_t GetExtraData); bool Cty_GetDataOfCountryByCod (struct Country *Cty);
void Cty_FlushCacheCountryName (void); void Cty_FlushCacheCountryName (void);
void Cty_GetCountryName (long CtyCod,char CtyName[Cty_MAX_BYTES_NAME + 1]); void Cty_GetCountryName (long CtyCod,Lan_Language_t Language,
char CtyName[Cty_MAX_BYTES_NAME + 1]);
void Cty_PutParamCtyCod (long CtyCod); void Cty_PutParamCtyCod (long CtyCod);
long Cty_GetAndCheckParamOtherCtyCod (long MinCodAllowed); long Cty_GetAndCheckParamOtherCtyCod (long MinCodAllowed);
void Cty_RemoveCountry (void); void Cty_RemoveCountry (void);

View File

@ -207,7 +207,7 @@ static void Crs_WriteListMyCoursesToSelectOne (void)
/***** Get data of this institution *****/ /***** Get data of this institution *****/
Cty.CtyCod = Str_ConvertStrCodToLongCod (row[0]); Cty.CtyCod = Str_ConvertStrCodToLongCod (row[0]);
if (!Cty_GetDataOfCountryByCod (&Cty,Cty_GET_BASIC_DATA)) if (!Cty_GetDataOfCountryByCod (&Cty))
Lay_ShowErrorAndExit ("Country not found."); Lay_ShowErrorAndExit ("Country not found.");
/***** Write link to country *****/ /***** Write link to country *****/

View File

@ -260,7 +260,7 @@ static void Dpt_EditDepartmentsInternal (void)
return; return;
/***** Get list of institutions *****/ /***** Get list of institutions *****/
Ins_GetListInstitutions (Gbl.Hierarchy.Cty.CtyCod); Ins_GetBasicListOfInstitutions (Gbl.Hierarchy.Cty.CtyCod);
/***** Get list of departments *****/ /***** Get list of departments *****/
Dpt_GetListDepartments (Gbl.Hierarchy.Ins.InsCod); Dpt_GetListDepartments (Gbl.Hierarchy.Ins.InsCod);

View File

@ -759,6 +759,7 @@ struct Globals
struct struct
{ {
long CtyCod; long CtyCod;
Lan_Language_t Language;
char CtyName[Cty_MAX_BYTES_NAME + 1]; char CtyName[Cty_MAX_BYTES_NAME + 1];
} CountryName; } CountryName;
struct struct

View File

@ -563,10 +563,8 @@ void Hie_InitHierarchy (void)
/***** If country code is available, get country data *****/ /***** If country code is available, get country data *****/
if (Gbl.Hierarchy.Cty.CtyCod > 0) if (Gbl.Hierarchy.Cty.CtyCod > 0)
{ if (!Cty_GetDataOfCountryByCod (&Gbl.Hierarchy.Cty)) // Country not found
if (!Cty_GetDataOfCountryByCod (&Gbl.Hierarchy.Cty,Cty_GET_BASIC_DATA)) // Country not found
Hie_ResetHierarchy (); Hie_ResetHierarchy ();
}
/***** Set current hierarchy level and code /***** Set current hierarchy level and code
depending on course code, degree code, etc. *****/ depending on course code, degree code, etc. *****/

View File

@ -73,6 +73,8 @@ static void Ins_EditInstitutionsInternal (void);
static void Ins_PutIconsEditingInstitutions (void); static void Ins_PutIconsEditingInstitutions (void);
static void Ins_PutIconToViewInstitutions (void); static void Ins_PutIconToViewInstitutions (void);
static void Ins_GetDataOfInstitFromRow (struct Instit *Ins,MYSQL_ROW row);
static void Ins_GetShrtNameAndCtyOfInstitution (struct Instit *Ins, static void Ins_GetShrtNameAndCtyOfInstitution (struct Instit *Ins,
char CtyName[Hie_MAX_BYTES_FULL_NAME + 1]); char CtyName[Hie_MAX_BYTES_FULL_NAME + 1]);
@ -265,7 +267,7 @@ void Ins_ShowInssOfCurrentCty (void)
Ins_GetParamInsOrder (); Ins_GetParamInsOrder ();
/***** Get list of institutions *****/ /***** Get list of institutions *****/
Ins_GetListInstitutions (Gbl.Hierarchy.Cty.CtyCod); Ins_GetFullListOfInstitutions (Gbl.Hierarchy.Cty.CtyCod);
/***** Write menu to select country *****/ /***** Write menu to select country *****/
Hie_WriteMenuHierarchy (); Hie_WriteMenuHierarchy ();
@ -402,7 +404,7 @@ static void Ins_ListOneInstitutionForSeeing (struct Instit *Ins,unsigned NumIns)
/***** Stats *****/ /***** Stats *****/
/* Number of users who claim to belong to this institution */ /* Number of users who claim to belong to this institution */
HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor); HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor);
HTM_Unsigned (Usr_GetNumUsrsWhoClaimToBelongToIns (Ins->InsCod)); HTM_Unsigned (Usr_GetNumUsrsWhoClaimToBelongToIns (Ins));
HTM_TD_End (); HTM_TD_End ();
/* Number of centres in this institution */ /* Number of centres in this institution */
@ -533,7 +535,7 @@ static void Ins_EditInstitutionsInternal (void)
extern const char *Txt_Institutions_of_COUNTRY_X; extern const char *Txt_Institutions_of_COUNTRY_X;
/***** Get list of institutions *****/ /***** Get list of institutions *****/
Ins_GetListInstitutions (Gbl.Hierarchy.Cty.CtyCod); Ins_GetFullListOfInstitutions (Gbl.Hierarchy.Cty.CtyCod);
/***** Write menu to select country *****/ /***** Write menu to select country *****/
Hie_WriteMenuHierarchy (); Hie_WriteMenuHierarchy ();
@ -549,7 +551,7 @@ static void Ins_EditInstitutionsInternal (void)
Ins_PutFormToCreateInstitution (); Ins_PutFormToCreateInstitution ();
/***** Forms to edit current institutions *****/ /***** Forms to edit current institutions *****/
if (Ins_GetNumInssInCty (Gbl.Hierarchy.Cty.CtyCod)) if (Gbl.Hierarchy.Cty.Inss.Num)
Ins_ListInstitutionsForEdition (); Ins_ListInstitutionsForEdition ();
/***** End box *****/ /***** End box *****/
@ -587,11 +589,10 @@ static void Ins_PutIconToViewInstitutions (void)
} }
/*****************************************************************************/ /*****************************************************************************/
/********************** Get list of current institutions *********************/ /******* Get basic list of institutions ordered by name of institution *******/
/*****************************************************************************/ /*****************************************************************************/
// If CtyCod <= 0, get all institutions
void Ins_GetListInstitutions (long CtyCod) void Ins_GetBasicListOfInstitutions (long CtyCod)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
@ -600,53 +601,18 @@ void Ins_GetListInstitutions (long CtyCod)
struct Instit *Ins; struct Instit *Ins;
/***** Get institutions from database *****/ /***** Get institutions from database *****/
switch (Gbl.Hierarchy.Cty.Inss.SelectedOrder) NumRows = DB_QuerySELECT (&mysql_res,"can not get institutions",
{ "SELECT InsCod," // row[0]
case Ins_ORDER_BY_INSTITUTION: "CtyCod," // row[1]
NumRows = DB_QuerySELECT (&mysql_res,"can not get institutions", "Status," // row[2]
"SELECT InsCod," // row[0] "RequesterUsrCod," // row[3]
"CtyCod," // row[1] "ShortName," // row[4]
"Status," // row[2] "FullName," // row[5]
"RequesterUsrCod," // row[3] "WWW" // row[6]
"ShortName," // row[4] " FROM institutions"
"FullName," // row[5] " WHERE CtyCod=%ld"
"WWW" // row[6] " ORDER BY FullName",
" FROM institutions" CtyCod);
" WHERE CtyCod=%ld"
" ORDER BY FullName",
CtyCod);
break;
case Ins_ORDER_BY_NUM_USRS:
NumRows = DB_QuerySELECT (&mysql_res,"can not get institutions",
"(SELECT institutions.InsCod," // row[0]
"institutions.CtyCod," // row[1]
"institutions.Status," // row[2]
"institutions.RequesterUsrCod," // row[3]
"institutions.ShortName," // row[4]
"institutions.FullName," // row[5]
"institutions.WWW," // row[6]
"COUNT(*) AS NumUsrs" // row[7]
" FROM institutions,usr_data"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=usr_data.InsCod"
" GROUP BY institutions.InsCod)"
" UNION "
"(SELECT InsCod," // row[0]
"CtyCod," // row[1]
"Status," // row[2]
"RequesterUsrCod," // row[3]
"ShortName," // row[4]
"FullName," // row[5]
"WWW," // row[6]
"0 AS NumUsrs" // row[7]
" FROM institutions"
" WHERE CtyCod=%ld"
" AND InsCod NOT IN"
" (SELECT DISTINCT InsCod FROM usr_data))"
" ORDER BY NumUsrs DESC,FullName",
CtyCod,CtyCod);
break;
}
if (NumRows) // Institutions found... if (NumRows) // Institutions found...
{ {
@ -665,34 +631,117 @@ void Ins_GetListInstitutions (long CtyCod)
{ {
Ins = &(Gbl.Hierarchy.Cty.Inss.Lst[NumIns]); Ins = &(Gbl.Hierarchy.Cty.Inss.Lst[NumIns]);
/* Get next institution */ /* Get institution data */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
Ins_GetDataOfInstitFromRow (Ins,row);
/* Get institution code (row[0]) */ /* Reset number of users who claim to belong to this institution */
if ((Ins->InsCod = Str_ConvertStrCodToLongCod (row[0])) < 0) Ins->NumUsrsWhoClaimToBelongToIns.Valid = false;
Lay_ShowErrorAndExit ("Wrong code of institution.");
/* Get country code (row[1]) */ /* Reset other fields */
Ins->CtyCod = Str_ConvertStrCodToLongCod (row[1]); Ins->Ctrs.Num = 0;
Ins->Ctrs.Lst = NULL;
Ins->Ctrs.SelectedOrder = Ctr_ORDER_DEFAULT;
}
}
else
{
Gbl.Hierarchy.Cty.Inss.Num = 0;
Gbl.Hierarchy.Cty.Inss.Lst = NULL;
}
/* Get institution status (row[2]) */ /***** Free structure that stores the query result *****/
if (sscanf (row[2],"%u",&(Ins->Status)) != 1) DB_FreeMySQLResult (&mysql_res);
Lay_ShowErrorAndExit ("Wrong institution status."); }
/* Get requester user's code (row[3]) */ /*****************************************************************************/
Ins->RequesterUsrCod = Str_ConvertStrCodToLongCod (row[3]); /************* Get full list of institutions **************/
/************* with number of users who claim to belong to them **************/
/*****************************************************************************/
/* Get the short name of the institution (row[4]) */ void Ins_GetFullListOfInstitutions (long CtyCod)
Str_Copy (Ins->ShrtName,row[4], {
Hie_MAX_BYTES_SHRT_NAME); char *OrderBySubQuery = NULL;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows = 0; // Initialized to avoid warning
unsigned NumIns;
struct Instit *Ins;
/* Get the full name of the institution (row[5]) */ /***** Get institutions from database *****/
Str_Copy (Ins->FullName,row[5], /* Build order subquery */
Hie_MAX_BYTES_FULL_NAME); switch (Gbl.Hierarchy.Cty.Inss.SelectedOrder)
{
case Ins_ORDER_BY_INSTITUTION:
OrderBySubQuery = "FullName";
break;
case Ins_ORDER_BY_NUM_USRS:
OrderBySubQuery = "NumUsrs DESC,FullName";
break;
default:
Lay_WrongOrderExit ();
}
/* Get the URL of the institution (row[6]) */ /* Query database */
Str_Copy (Ins->WWW,row[6], NumRows = DB_QuerySELECT (&mysql_res,"can not get institutions",
Cns_MAX_BYTES_WWW); "(SELECT institutions.InsCod," // row[0]
"institutions.CtyCod," // row[1]
"institutions.Status," // row[2]
"institutions.RequesterUsrCod," // row[3]
"institutions.ShortName," // row[4]
"institutions.FullName," // row[5]
"institutions.WWW," // row[6]
"COUNT(*) AS NumUsrs" // row[7]
" FROM institutions,usr_data"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=usr_data.InsCod"
" GROUP BY institutions.InsCod)"
" UNION "
"(SELECT InsCod," // row[0]
"CtyCod," // row[1]
"Status," // row[2]
"RequesterUsrCod," // row[3]
"ShortName," // row[4]
"FullName," // row[5]
"WWW," // row[6]
"0 AS NumUsrs" // row[7]
" FROM institutions"
" WHERE CtyCod=%ld"
" AND InsCod NOT IN"
" (SELECT DISTINCT InsCod FROM usr_data))"
" ORDER BY %s",
CtyCod,CtyCod,OrderBySubQuery);
if (NumRows) // Institutions found...
{
// NumRows should be equal to Deg->NumCourses
Gbl.Hierarchy.Cty.Inss.Num = (unsigned) NumRows;
/***** Create list with institutions *****/
if ((Gbl.Hierarchy.Cty.Inss.Lst = (struct Instit *)
calloc (NumRows,sizeof (struct Instit))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the institutions *****/
for (NumIns = 0;
NumIns < Gbl.Hierarchy.Cty.Inss.Num;
NumIns++)
{
Ins = &(Gbl.Hierarchy.Cty.Inss.Lst[NumIns]);
/* Get institution data */
row = mysql_fetch_row (mysql_res);
Ins_GetDataOfInstitFromRow (Ins,row);
/* Get number of users who claim to belong to this institution (row[7]) */
Ins->NumUsrsWhoClaimToBelongToIns.Valid = false;
if (sscanf (row[7],"%u",&(Ins->NumUsrsWhoClaimToBelongToIns.NumUsrs)) == 1)
Ins->NumUsrsWhoClaimToBelongToIns.Valid = true;
/* Reset other fields */
Ins->Ctrs.Num = 0;
Ins->Ctrs.Lst = NULL;
Ins->Ctrs.SelectedOrder = Ctr_ORDER_DEFAULT;
} }
} }
else else
@ -743,41 +792,26 @@ bool Ins_GetDataOfInstitutionByCod (struct Instit *Ins)
Ins->Ctrs.Num = 0; Ins->Ctrs.Num = 0;
Ins->Ctrs.Lst = NULL; Ins->Ctrs.Lst = NULL;
Ins->Ctrs.SelectedOrder = Ctr_ORDER_DEFAULT; Ins->Ctrs.SelectedOrder = Ctr_ORDER_DEFAULT;
Ins->NumUsrsWhoClaimToBelongToIns.Valid = false;
/***** Check if institution code is correct *****/ /***** Check if institution code is correct *****/
if (Ins->InsCod > 0) if (Ins->InsCod > 0)
{ {
/***** Get data of an institution from database *****/ /***** Get data of an institution from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get data of an institution", if (DB_QuerySELECT (&mysql_res,"can not get data of an institution",
"SELECT CtyCod,Status,RequesterUsrCod,ShortName,FullName,WWW" "SELECT InsCod," // row[0]
"CtyCod," // row[1]
"Status," // row[2]
"RequesterUsrCod," // row[3]
"ShortName," // row[4]
"FullName," // row[5]
"WWW" // row[6]
" FROM institutions WHERE InsCod=%ld", " FROM institutions WHERE InsCod=%ld",
Ins->InsCod)) // Institution found... Ins->InsCod)) // Institution found...
{ {
/* Get row */ /* Get institution data */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
Ins_GetDataOfInstitFromRow (Ins,row);
/* Get country code (row[0]) */
Ins->CtyCod = Str_ConvertStrCodToLongCod (row[0]);
/* Get centre status (row[1]) */
if (sscanf (row[1],"%u",&(Ins->Status)) != 1)
Lay_ShowErrorAndExit ("Wrong institution status.");
/* Get requester user's code (row[2]) */
Ins->RequesterUsrCod = Str_ConvertStrCodToLongCod (row[2]);
/* Get the short name of the institution (row[3]) */
Str_Copy (Ins->ShrtName,row[3],
Hie_MAX_BYTES_SHRT_NAME);
/* Get the full name of the institution (row[4]) */
Str_Copy (Ins->FullName,row[4],
Hie_MAX_BYTES_FULL_NAME);
/* Get the URL of the institution (row[5]) */
Str_Copy (Ins->WWW,row[5],
Cns_MAX_BYTES_WWW);
/* Set return value */ /* Set return value */
InsFound = true; InsFound = true;
@ -790,6 +824,39 @@ bool Ins_GetDataOfInstitutionByCod (struct Instit *Ins)
return InsFound; return InsFound;
} }
/*****************************************************************************/
/********** Get data of a centre from a row resulting of a query *************/
/*****************************************************************************/
static void Ins_GetDataOfInstitFromRow (struct Instit *Ins,MYSQL_ROW row)
{
/***** Get institution code (row[0]) *****/
if ((Ins->InsCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong code of institution.");
/***** Get country code (row[1]) *****/
Ins->CtyCod = Str_ConvertStrCodToLongCod (row[1]);
/***** Get institution status (row[2]) *****/
if (sscanf (row[2],"%u",&(Ins->Status)) != 1)
Lay_ShowErrorAndExit ("Wrong institution status.");
/***** Get requester user's code (row[3]) *****/
Ins->RequesterUsrCod = Str_ConvertStrCodToLongCod (row[3]);
/***** Get the short name of the institution (row[4]) *****/
Str_Copy (Ins->ShrtName,row[4],
Hie_MAX_BYTES_SHRT_NAME);
/***** Get the full name of the institution (row[5]) *****/
Str_Copy (Ins->FullName,row[5],
Hie_MAX_BYTES_FULL_NAME);
/***** Get the URL of the institution (row[6]) *****/
Str_Copy (Ins->WWW,row[6],
Cns_MAX_BYTES_WWW);
}
/*****************************************************************************/ /*****************************************************************************/
/*********** Get the short name of an institution from its code **************/ /*********** Get the short name of an institution from its code **************/
/*****************************************************************************/ /*****************************************************************************/
@ -1033,7 +1100,7 @@ static void Ins_ListInstitutionsForEdition (void)
ICanEdit = Ins_CheckIfICanEdit (Ins); ICanEdit = Ins_CheckIfICanEdit (Ins);
NumCtrss = Ctr_GetNumCtrsInIns (Ins->InsCod); NumCtrss = Ctr_GetNumCtrsInIns (Ins->InsCod);
NumUsrsInCrssOfIns = Usr_GetNumUsrsInCrssOfIns (Rol_UNK,Ins->InsCod); // Here Rol_UNK means "all users" NumUsrsInCrssOfIns = Usr_GetNumUsrsInCrssOfIns (Rol_UNK,Ins->InsCod); // Here Rol_UNK means "all users"
NumUsrsWhoClaimToBelongToIns = Usr_GetNumUsrsWhoClaimToBelongToIns (Ins->InsCod); NumUsrsWhoClaimToBelongToIns = Usr_GetNumUsrsWhoClaimToBelongToIns (Ins);
HTM_TR_Begin (NULL); HTM_TR_Begin (NULL);
@ -1301,7 +1368,7 @@ void Ins_RemoveInstitution (void)
// Institution has users ==> don't remove // Institution has users ==> don't remove
Ale_CreateAlert (Ale_WARNING,NULL, Ale_CreateAlert (Ale_WARNING,NULL,
Txt_To_remove_an_institution_you_must_first_remove_all_centres_and_users_in_the_institution); Txt_To_remove_an_institution_you_must_first_remove_all_centres_and_users_in_the_institution);
else if (Usr_GetNumUsrsWhoClaimToBelongToIns (Ins_EditingIns->InsCod)) else if (Usr_GetNumUsrsWhoClaimToBelongToIns (Ins_EditingIns))
// Institution has users ==> don't remove // Institution has users ==> don't remove
Ale_CreateAlert (Ale_WARNING,NULL, Ale_CreateAlert (Ale_WARNING,NULL,
Txt_To_remove_an_institution_you_must_first_remove_all_centres_and_users_in_the_institution); Txt_To_remove_an_institution_you_must_first_remove_all_centres_and_users_in_the_institution);

View File

@ -71,6 +71,11 @@ struct Instit
struct Centre *Lst; // List of centres struct Centre *Lst; // List of centres
Ctr_Order_t SelectedOrder; Ctr_Order_t SelectedOrder;
} Ctrs; } Ctrs;
struct
{
bool Valid;
unsigned NumUsrs;
} NumUsrsWhoClaimToBelongToIns;
}; };
#define Ins_NUM_ORDERS 2 #define Ins_NUM_ORDERS 2
@ -81,12 +86,6 @@ typedef enum
} Ins_Order_t; } Ins_Order_t;
#define Ins_ORDER_DEFAULT Ins_ORDER_BY_NUM_USRS #define Ins_ORDER_DEFAULT Ins_ORDER_BY_NUM_USRS
typedef enum
{
Ins_GET_BASIC_DATA,
Ins_GET_EXTRA_DATA,
} Ins_GetExtraData_t;
/*****************************************************************************/ /*****************************************************************************/
/***************************** Public prototypes *****************************/ /***************************** Public prototypes *****************************/
/*****************************************************************************/ /*****************************************************************************/
@ -99,7 +98,8 @@ void Ins_DrawInstitutionLogoAndNameWithLink (struct Instit *Ins,Act_Action_t Act
void Ins_ShowInssOfCurrentCty (void); void Ins_ShowInssOfCurrentCty (void);
void Ins_EditInstitutions (void); void Ins_EditInstitutions (void);
void Ins_GetListInstitutions (long CtyCod); void Ins_GetBasicListOfInstitutions (long CtyCod);
void Ins_GetFullListOfInstitutions (long CtyCod);
void Ins_WriteInstitutionNameAndCty (long InsCod); void Ins_WriteInstitutionNameAndCty (long InsCod);
bool Ins_GetDataOfInstitutionByCod (struct Instit *Ins); bool Ins_GetDataOfInstitutionByCod (struct Instit *Ins);

View File

@ -376,7 +376,7 @@ static void InsCfg_Country (bool PrintView,bool PutForm)
if (PutForm) if (PutForm)
{ {
/* Get list of countries */ /* Get list of countries */
Cty_GetListCountries (Cty_GET_BASIC_DATA); Cty_GetBasicListOfCountries ();
/* Put form to select country */ /* Put form to select country */
Frm_StartForm (ActChgInsCtyCfg); Frm_StartForm (ActChgInsCtyCfg);
@ -483,7 +483,7 @@ static void InsCfg_NumUsrs (void)
/* Data */ /* Data */
HTM_TD_Begin ("class=\"DAT LB\""); HTM_TD_Begin ("class=\"DAT LB\"");
HTM_Unsigned (Usr_GetNumUsrsWhoClaimToBelongToIns (Gbl.Hierarchy.Ins.InsCod)); HTM_Unsigned (Usr_GetNumUsrsWhoClaimToBelongToIns (&Gbl.Hierarchy.Ins));
HTM_TD_End (); HTM_TD_End ();
HTM_TR_End (); HTM_TR_End ();
@ -655,7 +655,7 @@ void InsCfg_ChangeInsCty (void)
if (NewCty.CtyCod != Gbl.Hierarchy.Ins.CtyCod) if (NewCty.CtyCod != Gbl.Hierarchy.Ins.CtyCod)
{ {
/***** Get data of the country from database *****/ /***** Get data of the country from database *****/
Cty_GetDataOfCountryByCod (&NewCty,Cty_GET_BASIC_DATA); Cty_GetDataOfCountryByCod (&NewCty);
/***** Check if it already exists an institution with the same name in the new country *****/ /***** Check if it already exists an institution with the same name in the new country *****/
if (Ins_CheckIfInsNameExistsInCty ("ShortName",Gbl.Hierarchy.Ins.ShrtName,-1L,NewCty.CtyCod)) if (Ins_CheckIfInsNameExistsInCty ("ShortName",Gbl.Hierarchy.Ins.ShrtName,-1L,NewCty.CtyCod))

View File

@ -1299,6 +1299,15 @@ void Lay_WrongScopeExit (void)
Lay_ShowErrorAndExit ("Wrong scope."); Lay_ShowErrorAndExit ("Wrong scope.");
} }
/*****************************************************************************/
/************* Write error message and exit when wrong order *****************/
/*****************************************************************************/
void Lay_WrongOrderExit (void)
{
Lay_ShowErrorAndExit ("Wrong order.");
}
/*****************************************************************************/ /*****************************************************************************/
/******* Write error message, close files, remove lock file, and exit ********/ /******* Write error message, close files, remove lock file, and exit ********/
/*****************************************************************************/ /*****************************************************************************/

View File

@ -71,6 +71,7 @@ void Lay_PutContextualCheckbox (Act_Action_t NextAction,
void Lay_NotEnoughMemoryExit (void); void Lay_NotEnoughMemoryExit (void);
void Lay_WrongScopeExit (void); void Lay_WrongScopeExit (void);
void Lay_WrongOrderExit (void);
void Lay_NoPermissionExit (void); void Lay_NoPermissionExit (void);
void Lay_ShowErrorAndExit (const char *Txt); void Lay_ShowErrorAndExit (const char *Txt);

View File

@ -292,7 +292,8 @@ void Log_GetAndShowLastClicks (void)
/* Get country code (row[4]) */ /* Get country code (row[4]) */
Cty.CtyCod = Str_ConvertStrCodToLongCod (row[4]); Cty.CtyCod = Str_ConvertStrCodToLongCod (row[4]);
Cty_GetCountryName (Cty.CtyCod,Cty.Name[Gbl.Prefs.Language]); Cty_GetCountryName (Cty.CtyCod,Gbl.Prefs.Language,
Cty.Name[Gbl.Prefs.Language]);
/* Get institution code (row[5]) */ /* Get institution code (row[5]) */
Ins.InsCod = Str_ConvertStrCodToLongCod (row[5]); Ins.InsCod = Str_ConvertStrCodToLongCod (row[5]);

View File

@ -3217,10 +3217,7 @@ static void Rec_ShowCountry (struct UsrData *UsrDat,bool PutForm)
/***** If list of countries is empty, try to get it *****/ /***** If list of countries is empty, try to get it *****/
if (!Gbl.Hierarchy.Sys.Ctys.Num) if (!Gbl.Hierarchy.Sys.Ctys.Num)
{ Cty_GetBasicListOfCountries ();
Gbl.Hierarchy.Sys.Ctys.SelectedOrder = Cty_ORDER_BY_COUNTRY;
Cty_GetListCountries (Cty_GET_BASIC_DATA);
}
/***** Selector of country *****/ /***** Selector of country *****/
HTM_TR_Begin (NULL); HTM_TR_Begin (NULL);
@ -3955,10 +3952,7 @@ static void Rec_ShowFormMyInsCtrDpt (bool IAmATeacher)
/* If list of countries is empty, try to get it */ /* If list of countries is empty, try to get it */
if (!Gbl.Hierarchy.Sys.Ctys.Num) if (!Gbl.Hierarchy.Sys.Ctys.Num)
{ Cty_GetBasicListOfCountries ();
Gbl.Hierarchy.Sys.Ctys.SelectedOrder = Cty_ORDER_BY_COUNTRY;
Cty_GetListCountries (Cty_GET_BASIC_DATA);
}
/* Begin form to select the country of my institution */ /* Begin form to select the country of my institution */
Frm_StartFormAnchor (ActChgCtyMyIns,Rec_MY_INS_CTR_DPT_ID); Frm_StartFormAnchor (ActChgCtyMyIns,Rec_MY_INS_CTR_DPT_ID);
@ -3994,7 +3988,7 @@ static void Rec_ShowFormMyInsCtrDpt (bool IAmATeacher)
/* Get list of institutions in this country */ /* Get list of institutions in this country */
Ins_FreeListInstitutions (); Ins_FreeListInstitutions ();
if (Gbl.Usrs.Me.UsrDat.InsCtyCod > 0) if (Gbl.Usrs.Me.UsrDat.InsCtyCod > 0)
Ins_GetListInstitutions (Gbl.Usrs.Me.UsrDat.InsCtyCod); Ins_GetBasicListOfInstitutions (Gbl.Usrs.Me.UsrDat.InsCtyCod);
/* Begin form to select institution */ /* Begin form to select institution */
Frm_StartFormAnchor (ActChgMyIns,Rec_MY_INS_CTR_DPT_ID); Frm_StartFormAnchor (ActChgMyIns,Rec_MY_INS_CTR_DPT_ID);

View File

@ -556,7 +556,7 @@ static void Rep_WriteSectionUsrInfo (void)
Gbl.Usrs.Me.UsrDat.Email); Gbl.Usrs.Me.UsrDat.Email);
/***** User's country *****/ /***** User's country *****/
Cty_GetCountryName (Gbl.Usrs.Me.UsrDat.CtyCod,CtyName); Cty_GetCountryName (Gbl.Usrs.Me.UsrDat.CtyCod,Gbl.Prefs.Language,CtyName);
fprintf (Gbl.F.Rep,"<li>%s: %s</li>", fprintf (Gbl.F.Rep,"<li>%s: %s</li>",
Txt_Country, Txt_Country,
CtyName); CtyName);

View File

@ -3280,7 +3280,7 @@ static void Sta_WriteCountry (long CtyCod)
{ {
/***** Get data of country *****/ /***** Get data of country *****/
Cty.CtyCod = CtyCod; Cty.CtyCod = CtyCod;
Cty_GetDataOfCountryByCod (&Cty,Cty_GET_BASIC_DATA); Cty_GetDataOfCountryByCod (&Cty);
/***** Form to go to country *****/ /***** Form to go to country *****/
Cty_DrawCountryMapAndNameWithLink (&Cty,ActSeeCtyInf, Cty_DrawCountryMapAndNameWithLink (&Cty,ActSeeCtyInf,

View File

@ -4674,25 +4674,35 @@ void Usr_FlushCacheNumUsrsWhoClaimToBelongToIns (void)
Gbl.Cache.NumUsrsWhoClaimToBelongToIns.NumUsrs = 0; Gbl.Cache.NumUsrsWhoClaimToBelongToIns.NumUsrs = 0;
} }
unsigned Usr_GetNumUsrsWhoClaimToBelongToIns (long InsCod) unsigned Usr_GetNumUsrsWhoClaimToBelongToIns (struct Instit *Ins)
{ {
/***** 1. Fast check: Trivial case *****/ /***** 1. Fast check: Trivial case *****/
if (InsCod <= 0) if (Ins->InsCod <= 0)
return 0; return 0;
/***** 2. Fast check: If cached... *****/ /***** 2. Fast check: If already got... *****/
if (InsCod == Gbl.Cache.NumUsrsWhoClaimToBelongToCtr.CtrCod) if (Ins->NumUsrsWhoClaimToBelongToIns.Valid)
return Gbl.Cache.NumUsrsWhoClaimToBelongToCtr.NumUsrs; return Ins->NumUsrsWhoClaimToBelongToIns.NumUsrs;
/***** 3. Slow: number of users who claim to belong to an institution /***** 3. Fast check: If cached... *****/
if (Ins->InsCod == Gbl.Cache.NumUsrsWhoClaimToBelongToIns.InsCod)
{
Ins->NumUsrsWhoClaimToBelongToIns.NumUsrs = Gbl.Cache.NumUsrsWhoClaimToBelongToIns.NumUsrs;
Ins->NumUsrsWhoClaimToBelongToIns.Valid = true;
return Ins->NumUsrsWhoClaimToBelongToIns.NumUsrs;
}
/***** 4. Slow: number of users who claim to belong to an institution
from database *****/ from database *****/
Gbl.Cache.NumUsrsWhoClaimToBelongToIns.InsCod = InsCod; Gbl.Cache.NumUsrsWhoClaimToBelongToIns.InsCod = Ins->InsCod;
Gbl.Cache.NumUsrsWhoClaimToBelongToIns.NumUsrs = Gbl.Cache.NumUsrsWhoClaimToBelongToIns.NumUsrs =
Ins->NumUsrsWhoClaimToBelongToIns.NumUsrs =
(unsigned) DB_QueryCOUNT ("can not get number of users", (unsigned) DB_QueryCOUNT ("can not get number of users",
"SELECT COUNT(UsrCod) FROM usr_data" "SELECT COUNT(UsrCod) FROM usr_data"
" WHERE InsCod=%ld", " WHERE InsCod=%ld",
InsCod); Ins->InsCod);
return Gbl.Cache.NumUsrsWhoClaimToBelongToIns.NumUsrs; Ins->NumUsrsWhoClaimToBelongToIns.Valid = true;
return Ins->NumUsrsWhoClaimToBelongToIns.NumUsrs;
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -429,7 +429,7 @@ unsigned Usr_GetNumUsrsWhoClaimToBelongToAnotherCty (void);
void Usr_FlushCacheNumUsrsWhoClaimToBelongToCty (void); void Usr_FlushCacheNumUsrsWhoClaimToBelongToCty (void);
unsigned Usr_GetNumUsrsWhoClaimToBelongToCty (struct Country *Cty); unsigned Usr_GetNumUsrsWhoClaimToBelongToCty (struct Country *Cty);
void Usr_FlushCacheNumUsrsWhoClaimToBelongToIns (void); void Usr_FlushCacheNumUsrsWhoClaimToBelongToIns (void);
unsigned Usr_GetNumUsrsWhoClaimToBelongToIns (long InsCod); unsigned Usr_GetNumUsrsWhoClaimToBelongToIns (struct Instit *Ins);
void Usr_FlushCacheNumUsrsWhoClaimToBelongToCtr (void); void Usr_FlushCacheNumUsrsWhoClaimToBelongToCtr (void);
unsigned Usr_GetNumUsrsWhoClaimToBelongToCtr (long CtrCod); unsigned Usr_GetNumUsrsWhoClaimToBelongToCtr (long CtrCod);
unsigned Usr_GetNumberOfTeachersInCentre (long CtrCod); unsigned Usr_GetNumberOfTeachersInCentre (long CtrCod);