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]);
/* Get next centre */
/* Get centre data */
row = mysql_fetch_row (mysql_res);
Ctr_GetDataOfCentreFromRow (Ctr,row);
}

View File

@ -583,7 +583,7 @@ static void CtrCfg_Institution (bool PrintView,bool PutForm)
if (PutForm)
{
/* 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 */
Frm_StartForm (ActChgCtrInsCfg);

View File

@ -492,7 +492,7 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - *
En OpenSWAD:
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 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: No se puede entrar con DNI '1' suponiendo que no tenga password ¿por qué?
// 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.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)

View File

@ -161,7 +161,7 @@ void Cty_SeeCtyWithPendingInss (void)
Gbl.ColorRows[Gbl.RowEvenOdd];
/* Get data of country */
Cty_GetDataOfCountryByCod (&Cty,Cty_GET_BASIC_DATA);
Cty_GetDataOfCountryByCod (&Cty);
HTM_TR_Begin (NULL);
@ -212,7 +212,7 @@ void Cty_ListCountries1 (void)
Cty_GetParamCtyOrder ();
/***** Get list of countries *****/
Cty_GetListCountries (Cty_GET_EXTRA_DATA);
Cty_GetFullListOfCountries ();
}
void Cty_ListCountries2 (void)
@ -658,7 +658,7 @@ static void Cty_EditCountriesInternal (void)
/***** Get list of countries *****/
Gbl.Hierarchy.Sys.Ctys.SelectedOrder = Cty_ORDER_BY_COUNTRY;
Cty_GetListCountries (Cty_GET_EXTRA_DATA);
Cty_GetFullListOfCountries ();
/***** Write menu to select country *****/
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_GetListCountries (Cty_GetExtraData_t GetExtraData)
void Cty_GetBasicListOfCountries (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;
@ -731,88 +723,18 @@ void Cty_GetListCountries (Cty_GetExtraData_t GetExtraData)
Lan_Language_t Lan;
/***** Get countries from database *****/
switch (GetExtraData)
{
case Cty_GET_BASIC_DATA:
NumRows = DB_QuerySELECT (&mysql_res,"can not get countries",
"SELECT CtyCod,Alpha2,Name_%s"
" 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);
NumRows = DB_QuerySELECT (&mysql_res,"can not get countries",
"SELECT CtyCod,Alpha2,Name_%s"
" FROM countries ORDER BY Name_%s",
Lan_STR_LANG_ID[Gbl.Prefs.Language],
Lan_STR_LANG_ID[Gbl.Prefs.Language]);
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)
if ((Gbl.Hierarchy.Sys.Ctys.Lst = (struct Country *)
calloc (NumRows,sizeof (struct Country))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the countries *****/
@ -833,43 +755,168 @@ void Cty_GetListCountries (Cty_GetExtraData_t GetExtraData)
Str_Copy (Cty->Alpha2,row[1],
2);
switch (GetExtraData)
{
case Cty_GET_BASIC_DATA:
for (Lan = (Lan_Language_t) 1;
Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES;
Lan++)
{
Cty->Name[Lan][0] = '\0';
Cty->WWW[Lan][0] = '\0';
}
Cty->NumUsrsWhoClaimToBelongToCty.Valid = false;
Cty->Inss.Num = 0;
for (Lan = (Lan_Language_t) 1;
Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES;
Lan++)
{
Cty->Name[Lan][0] = '\0';
Cty->WWW[Lan][0] = '\0';
}
/* Get the name of the country in current language */
Str_Copy (Cty->Name[Gbl.Prefs.Language],row[2],
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 the name of the country in current language */
Str_Copy (Cty->Name[Gbl.Prefs.Language],row[2],
Cty_MAX_BYTES_NAME);
/* 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;
break;
}
/* Number of users who claim to belong to country not got */
Cty->NumUsrsWhoClaimToBelongToCty.Valid = false;
/* Reset other fields */
Cty->Inss.Num = 0;
Cty->Inss.Lst = NULL;
}
}
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
@ -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
/***** Get country name *****/
Cty_GetCountryName (CtyCod,CtyName);
Cty_GetCountryName (CtyCod,Gbl.Prefs.Language,CtyName);
if (PutForm)
{
@ -968,15 +1015,10 @@ void Cty_WriteCountryName (long CtyCod,const char *ClassLink)
/***************** 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 *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_ROW row;
unsigned long NumRows = 0;
@ -1016,55 +1058,13 @@ bool Cty_GetDataOfCountryByCod (struct Country *Cty,Cty_GetExtraData_t GetExtraD
// Here Cty->CtyCod > 0
/***** Get data of a country from database *****/
switch (GetExtraData)
{
case Cty_GET_BASIC_DATA:
NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a country",
"SELECT Alpha2,Name_%s,WWW_%s"
" FROM countries"
" WHERE CtyCod='%03ld'",
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;
}
NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a country",
"SELECT Alpha2,Name_%s,WWW_%s"
" FROM countries"
" WHERE CtyCod='%03ld'",
Lan_STR_LANG_ID[Gbl.Prefs.Language],
Lan_STR_LANG_ID[Gbl.Prefs.Language],
Cty->CtyCod);
/***** Count number of rows in result *****/
if (NumRows) // Country found...
@ -1078,28 +1078,11 @@ bool Cty_GetDataOfCountryByCod (struct Country *Cty,Cty_GetExtraData_t GetExtraD
Str_Copy (Cty->Alpha2,row[0],
2);
switch (GetExtraData)
{
case Cty_GET_BASIC_DATA:
/* Get name and WWW of the country in current language */
Str_Copy (Cty->Name[Gbl.Prefs.Language],row[1],
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;
}
/* Get name and WWW of the country in current language */
Str_Copy (Cty->Name[Gbl.Prefs.Language],row[1],
Cty_MAX_BYTES_NAME);
Str_Copy (Cty->WWW[Gbl.Prefs.Language],row[2],
Cns_MAX_BYTES_WWW);
}
else
CtyFound = false;
@ -1116,11 +1099,13 @@ bool Cty_GetDataOfCountryByCod (struct Country *Cty,Cty_GetExtraData_t GetExtraD
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';
}
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];
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... *****/
if (CtyCod == Gbl.Cache.CountryName.CtyCod)
if (CtyCod == Gbl.Cache.CountryName.CtyCod &&
Language == Gbl.Cache.CountryName.Language)
{
Str_Copy (CtyName,Gbl.Cache.CountryName.CtyName,
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 *****/
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",
"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 */
row = mysql_fetch_row (mysql_res);
@ -1346,7 +1333,7 @@ void Cty_RemoveCountry (void)
Cty_EditingCty->CtyCod = Cty_GetAndCheckParamOtherCtyCod (0);
/***** 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 *****/
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);
/***** 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 *****/
if (NewCtyName[0])
{
/***** Check if old and new names are the same
(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 country was in database... *****/
@ -1537,7 +1526,7 @@ void Cty_ChangeCtyWWW (void)
Par_GetParToText ("WWW",NewWWW,Cns_MAX_BYTES_WWW);
/***** 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 *****/
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
/***** List the countries (one row per country) *****/
for (NumCty = 1;
for (NumCty = 1;
NumCty <= NumCtys;
NumCty++)
{
@ -2034,7 +2023,7 @@ void Cty_ListCtysFound (MYSQL_RES **mysql_res,unsigned NumCtys)
Cty.CtyCod = Str_ConvertStrCodToLongCod (row[0]);
/* Get data of country */
Cty_GetDataOfCountryByCod (&Cty,Cty_GET_EXTRA_DATA);
Cty_GetDataOfCountryByCod (&Cty);
/* Write data of this country */
Cty_ListOneCountryForSeeing (&Cty,NumCty);

View File

@ -72,12 +72,6 @@ typedef enum
} Cty_Order_t;
#define Cty_ORDER_DEFAULT Cty_ORDER_BY_NUM_USRS
typedef enum
{
Cty_GET_BASIC_DATA,
Cty_GET_EXTRA_DATA,
} Cty_GetExtraData_t;
/*****************************************************************************/
/***************************** Public prototypes *****************************/
/*****************************************************************************/
@ -100,13 +94,15 @@ bool Cty_CheckIfCountryPhotoExists (struct Country *Cty);
void Cty_WriteScriptGoogleGeochart (void);
void Cty_PutHiddenParamCtyOrder (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_WriteSelectorOfCountry (void);
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_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);
long Cty_GetAndCheckParamOtherCtyCod (long MinCodAllowed);
void Cty_RemoveCountry (void);

View File

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

View File

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

View File

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

View File

@ -563,10 +563,8 @@ void Hie_InitHierarchy (void)
/***** If country code is available, get country data *****/
if (Gbl.Hierarchy.Cty.CtyCod > 0)
{
if (!Cty_GetDataOfCountryByCod (&Gbl.Hierarchy.Cty,Cty_GET_BASIC_DATA)) // Country not found
if (!Cty_GetDataOfCountryByCod (&Gbl.Hierarchy.Cty)) // Country not found
Hie_ResetHierarchy ();
}
/***** Set current hierarchy level and code
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_PutIconToViewInstitutions (void);
static void Ins_GetDataOfInstitFromRow (struct Instit *Ins,MYSQL_ROW row);
static void Ins_GetShrtNameAndCtyOfInstitution (struct Instit *Ins,
char CtyName[Hie_MAX_BYTES_FULL_NAME + 1]);
@ -265,7 +267,7 @@ void Ins_ShowInssOfCurrentCty (void)
Ins_GetParamInsOrder ();
/***** Get list of institutions *****/
Ins_GetListInstitutions (Gbl.Hierarchy.Cty.CtyCod);
Ins_GetFullListOfInstitutions (Gbl.Hierarchy.Cty.CtyCod);
/***** Write menu to select country *****/
Hie_WriteMenuHierarchy ();
@ -402,7 +404,7 @@ static void Ins_ListOneInstitutionForSeeing (struct Instit *Ins,unsigned NumIns)
/***** Stats *****/
/* Number of users who claim to belong to this institution */
HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor);
HTM_Unsigned (Usr_GetNumUsrsWhoClaimToBelongToIns (Ins->InsCod));
HTM_Unsigned (Usr_GetNumUsrsWhoClaimToBelongToIns (Ins));
HTM_TD_End ();
/* Number of centres in this institution */
@ -533,7 +535,7 @@ static void Ins_EditInstitutionsInternal (void)
extern const char *Txt_Institutions_of_COUNTRY_X;
/***** Get list of institutions *****/
Ins_GetListInstitutions (Gbl.Hierarchy.Cty.CtyCod);
Ins_GetFullListOfInstitutions (Gbl.Hierarchy.Cty.CtyCod);
/***** Write menu to select country *****/
Hie_WriteMenuHierarchy ();
@ -549,7 +551,7 @@ static void Ins_EditInstitutionsInternal (void)
Ins_PutFormToCreateInstitution ();
/***** Forms to edit current institutions *****/
if (Ins_GetNumInssInCty (Gbl.Hierarchy.Cty.CtyCod))
if (Gbl.Hierarchy.Cty.Inss.Num)
Ins_ListInstitutionsForEdition ();
/***** 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_ROW row;
@ -600,53 +601,18 @@ void Ins_GetListInstitutions (long CtyCod)
struct Instit *Ins;
/***** Get institutions from database *****/
switch (Gbl.Hierarchy.Cty.Inss.SelectedOrder)
{
case Ins_ORDER_BY_INSTITUTION:
NumRows = DB_QuerySELECT (&mysql_res,"can not get institutions",
"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 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;
}
NumRows = DB_QuerySELECT (&mysql_res,"can not get institutions",
"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 CtyCod=%ld"
" ORDER BY FullName",
CtyCod);
if (NumRows) // Institutions found...
{
@ -665,34 +631,117 @@ void Ins_GetListInstitutions (long CtyCod)
{
Ins = &(Gbl.Hierarchy.Cty.Inss.Lst[NumIns]);
/* Get next institution */
/* Get institution data */
row = mysql_fetch_row (mysql_res);
Ins_GetDataOfInstitFromRow (Ins,row);
/* Get institution code (row[0]) */
if ((Ins->InsCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong code of institution.");
/* Reset number of users who claim to belong to this institution */
Ins->NumUsrsWhoClaimToBelongToIns.Valid = false;
/* Get country code (row[1]) */
Ins->CtyCod = Str_ConvertStrCodToLongCod (row[1]);
/* Reset other fields */
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]) */
if (sscanf (row[2],"%u",&(Ins->Status)) != 1)
Lay_ShowErrorAndExit ("Wrong institution status.");
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/* 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]) */
Str_Copy (Ins->ShrtName,row[4],
Hie_MAX_BYTES_SHRT_NAME);
void Ins_GetFullListOfInstitutions (long CtyCod)
{
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]) */
Str_Copy (Ins->FullName,row[5],
Hie_MAX_BYTES_FULL_NAME);
/***** Get institutions from database *****/
/* Build order subquery */
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]) */
Str_Copy (Ins->WWW,row[6],
Cns_MAX_BYTES_WWW);
/* Query database */
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 %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
@ -743,41 +792,26 @@ bool Ins_GetDataOfInstitutionByCod (struct Instit *Ins)
Ins->Ctrs.Num = 0;
Ins->Ctrs.Lst = NULL;
Ins->Ctrs.SelectedOrder = Ctr_ORDER_DEFAULT;
Ins->NumUsrsWhoClaimToBelongToIns.Valid = false;
/***** Check if institution code is correct *****/
if (Ins->InsCod > 0)
{
/***** Get data of an institution from database *****/
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",
Ins->InsCod)) // Institution found...
{
/* Get row */
/* Get institution data */
row = mysql_fetch_row (mysql_res);
/* 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);
Ins_GetDataOfInstitFromRow (Ins,row);
/* Set return value */
InsFound = true;
@ -790,6 +824,39 @@ bool Ins_GetDataOfInstitutionByCod (struct Instit *Ins)
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 **************/
/*****************************************************************************/
@ -1033,7 +1100,7 @@ static void Ins_ListInstitutionsForEdition (void)
ICanEdit = Ins_CheckIfICanEdit (Ins);
NumCtrss = Ctr_GetNumCtrsInIns (Ins->InsCod);
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);
@ -1301,7 +1368,7 @@ void Ins_RemoveInstitution (void)
// Institution has users ==> don't remove
Ale_CreateAlert (Ale_WARNING,NULL,
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
Ale_CreateAlert (Ale_WARNING,NULL,
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
Ctr_Order_t SelectedOrder;
} Ctrs;
struct
{
bool Valid;
unsigned NumUsrs;
} NumUsrsWhoClaimToBelongToIns;
};
#define Ins_NUM_ORDERS 2
@ -81,12 +86,6 @@ typedef enum
} Ins_Order_t;
#define Ins_ORDER_DEFAULT Ins_ORDER_BY_NUM_USRS
typedef enum
{
Ins_GET_BASIC_DATA,
Ins_GET_EXTRA_DATA,
} Ins_GetExtraData_t;
/*****************************************************************************/
/***************************** Public prototypes *****************************/
/*****************************************************************************/
@ -99,7 +98,8 @@ void Ins_DrawInstitutionLogoAndNameWithLink (struct Instit *Ins,Act_Action_t Act
void Ins_ShowInssOfCurrentCty (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);
bool Ins_GetDataOfInstitutionByCod (struct Instit *Ins);

View File

@ -376,7 +376,7 @@ static void InsCfg_Country (bool PrintView,bool PutForm)
if (PutForm)
{
/* Get list of countries */
Cty_GetListCountries (Cty_GET_BASIC_DATA);
Cty_GetBasicListOfCountries ();
/* Put form to select country */
Frm_StartForm (ActChgInsCtyCfg);
@ -483,7 +483,7 @@ static void InsCfg_NumUsrs (void)
/* Data */
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_TR_End ();
@ -655,7 +655,7 @@ void InsCfg_ChangeInsCty (void)
if (NewCty.CtyCod != Gbl.Hierarchy.Ins.CtyCod)
{
/***** 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 *****/
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.");
}
/*****************************************************************************/
/************* 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 ********/
/*****************************************************************************/

View File

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

View File

@ -292,7 +292,8 @@ void Log_GetAndShowLastClicks (void)
/* Get country code (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]) */
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 (!Gbl.Hierarchy.Sys.Ctys.Num)
{
Gbl.Hierarchy.Sys.Ctys.SelectedOrder = Cty_ORDER_BY_COUNTRY;
Cty_GetListCountries (Cty_GET_BASIC_DATA);
}
Cty_GetBasicListOfCountries ();
/***** Selector of country *****/
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 (!Gbl.Hierarchy.Sys.Ctys.Num)
{
Gbl.Hierarchy.Sys.Ctys.SelectedOrder = Cty_ORDER_BY_COUNTRY;
Cty_GetListCountries (Cty_GET_BASIC_DATA);
}
Cty_GetBasicListOfCountries ();
/* Begin form to select the country of my institution */
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 */
Ins_FreeListInstitutions ();
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 */
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);
/***** 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>",
Txt_Country,
CtyName);

View File

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

View File

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

View File

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