From c1a0a2832bfaaec614fb4d8689f4b05fd72bf96b Mon Sep 17 00:00:00 2001 From: acanas Date: Sat, 22 May 2021 12:34:10 +0200 Subject: [PATCH] Version 20.81: May 22, 2021 New module swad_country_database for database queries related to countries. --- Makefile | 3 +- swad_center.h | 2 +- swad_changelog.h | 5 +- swad_country.c | 966 +++++++++++++++++--------------------- swad_country_config.c | 384 +++++++-------- swad_country_database.c | 257 ++++++++++ swad_country_database.h | 52 ++ swad_hierarchy.c | 126 ++--- swad_institution_config.c | 101 ++-- swad_map.c | 6 +- swad_map.h | 10 +- swad_media.h | 1 + swad_record.c | 421 +++++++++-------- swad_system_config.c | 6 +- 14 files changed, 1264 insertions(+), 1076 deletions(-) create mode 100644 swad_country_database.c create mode 100644 swad_country_database.h diff --git a/Makefile b/Makefile index 6d46c1ee..d983a14c 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,8 @@ OBJS = swad_account.o swad_account_database.o swad_action.o swad_agenda.o \ swad_center_config.o swad_chat.o swad_chat_database.o swad_config.o \ swad_connected.o swad_connected_database.o swad_cookie.o \ swad_cookie_database.o swad_country.o swad_country_config.o \ - swad_course.o swad_course_config.o swad_cryptography.o \ + swad_country_database.o swad_course.o swad_course_config.o \ + swad_cryptography.o \ swad_database.o swad_date.o swad_degree.o swad_degree_config.o \ swad_degree_type.o swad_department.o swad_duplicate.o \ swad_enrolment.o swad_error.o swad_exam.o swad_exam_log.o \ diff --git a/swad_center.h b/swad_center.h index 88c3117c..96cfd22e 100644 --- a/swad_center.h +++ b/swad_center.h @@ -67,7 +67,7 @@ struct Ctr_Center long PlcCod; // Place code Ctr_Status_t Status; // Center status long RequesterUsrCod; // User code of the person who requested the creation of this center - struct Coordinates Coord; // Geographical coordinates + struct Map_Coordinates Coord; // Geographical coordinates char ShrtName[Cns_HIERARCHY_MAX_BYTES_SHRT_NAME + 1]; char FullName[Cns_HIERARCHY_MAX_BYTES_FULL_NAME + 1]; char WWW[Cns_MAX_BYTES_WWW + 1]; diff --git a/swad_changelog.h b/swad_changelog.h index 0bce838e..9fc14ba5 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -602,14 +602,15 @@ TODO: FIX BUG, URGENT! En las fechas como par TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo. */ -#define Log_PLATFORM_VERSION "SWAD 20.80 (2021-05-20)" +#define Log_PLATFORM_VERSION "SWAD 20.81 (2021-05-22)" #define CSS_FILE "swad20.45.css" #define JS_FILE "swad20.69.1.js" /* TODO: Rename CENTRE to CENTER in help wiki. TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams - Version 20.80: May 20, 2021 New module swad_cookie_database for database queries related to cookies. (? lines) + Version 20.81: May 22, 2021 New module swad_country_database for database queries related to countries. (311632 lines) + Version 20.80: May 20, 2021 New module swad_cookie_database for database queries related to cookies. (311497 lines) Version 20.79: May 20, 2021 New module swad_connected_database for database queries related to connected users. (311415 lines) Version 20.78.2: May 20, 2021 Code formatting in games and matches. (311326 lines) Version 20.78.1: May 20, 2021 Fixed bug in matches. Reported by Jesús Garrido Alcázar. (311317 lines) diff --git a/swad_country.c b/swad_country.c index cceebe02..b712b00e 100644 --- a/swad_country.c +++ b/swad_country.c @@ -33,6 +33,7 @@ #include // For string functions #include "swad_country_config.h" +#include "swad_country_database.h" #include "swad_database.h" #include "swad_error.h" #include "swad_figure.h" @@ -84,9 +85,9 @@ static void Cty_ListCountriesForEdition (void); static void Cty_PutParamOtherCtyCod (void *CtyCod); static long Cty_GetParamOtherCtyCod (void); -static bool Cty_CheckIfNumericCountryCodeExists (long CtyCod); -static bool Cty_CheckIfAlpha2CountryCodeExists (const char Alpha2[2 + 1]); -static bool Cty_CheckIfCountryNameExists (Lan_Language_t Language,const char *Name,long CtyCod); +static bool Cty_DB_CheckIfNumericCountryCodeExists (long CtyCod); +static bool Cty_DB_CheckIfAlpha2CountryCodeExists (const char Alpha2[2 + 1]); +static bool Cty_DB_CheckIfCountryNameExists (Lan_Language_t Language,const char *Name,long CtyCod); static void Cty_UpdateCtyNameDB (long CtyCod,const char *FieldName,const char *NewCtyName); static void Cty_ShowAlertAndButtonToGoToCty (void); @@ -108,7 +109,6 @@ static void Cty_FormToGoToMap (struct Cty_Countr *Cty); void Cty_SeeCtyWithPendingInss (void) { extern const char *Hlp_SYSTEM_Pending; - extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES]; extern const char *Txt_Countries_with_pending_institutions; extern const char *Txt_Country; extern const char *Txt_Institutions_ABBREVIATION; @@ -120,78 +120,64 @@ void Cty_SeeCtyWithPendingInss (void) struct Cty_Countr Cty; const char *BgColor; - /***** Get countries with pending institutions *****/ + /***** Trivial check: only system admins can see countries with pending institutions *****/ switch (Gbl.Usrs.Me.Role.Logged) { case Rol_SYS_ADM: - NumCtys = (unsigned) - DB_QuerySELECT (&mysql_res,"can not get countries" - " with pending institutions", - "SELECT ins_instits.CtyCod," // row[0] - "COUNT(*)" // row[1] - " FROM ins_instits," - "cty_countrs" - " WHERE (ins_instits.Status & %u)<>0" - " AND ins_instits.CtyCod=cty_countrs.CtyCod" - " GROUP BY ins_instits.CtyCod" - " ORDER BY cty_countrs.Name_%s", - (unsigned) Ins_STATUS_BIT_PENDING, - Lan_STR_LANG_ID[Gbl.Prefs.Language]); break; default: // Forbidden for other users return; } - /***** Get countries *****/ - if (NumCtys) + /***** Get countries with pending institutions *****/ + if ((NumCtys = Cty_DB_GetListOfCountriesWithPendingInss (&mysql_res))) { /***** Begin box and table *****/ Box_BoxTableBegin (NULL,Txt_Countries_with_pending_institutions, NULL,NULL, Hlp_SYSTEM_Pending,Box_NOT_CLOSABLE,2); - /***** Write heading *****/ - HTM_TR_Begin (NULL); + /***** Write heading *****/ + HTM_TR_Begin (NULL); + HTM_TH (1,1,"LM",Txt_Country); + HTM_TH (1,1,"RM",Txt_Institutions_ABBREVIATION); + HTM_TR_End (); - HTM_TH (1,1,"LM",Txt_Country); - HTM_TH (1,1,"RM",Txt_Institutions_ABBREVIATION); + /***** List the countries *****/ + for (NumCty = 0; + NumCty < NumCtys; + NumCty++, Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd) + { + /* Get next country */ + row = mysql_fetch_row (mysql_res); - HTM_TR_End (); + /* Get country code (row[0]) */ + Cty.CtyCod = Str_ConvertStrCodToLongCod (row[0]); + BgColor = (Cty.CtyCod == Gbl.Hierarchy.Cty.CtyCod) ? "LIGHT_BLUE" : + Gbl.ColorRows[Gbl.RowEvenOdd]; - /***** List the countries *****/ - for (NumCty = 0; - NumCty < NumCtys; - NumCty++) - { - /* Get next country */ - row = mysql_fetch_row (mysql_res); + /* Get data of country */ + Cty_GetDataOfCountryByCod (&Cty); - /* Get country code (row[0]) */ - Cty.CtyCod = Str_ConvertStrCodToLongCod (row[0]); - BgColor = (Cty.CtyCod == Gbl.Hierarchy.Cty.CtyCod) ? "LIGHT_BLUE" : - Gbl.ColorRows[Gbl.RowEvenOdd]; + /* Begin row for this country */ + HTM_TR_Begin (NULL); - /* Get data of country */ - Cty_GetDataOfCountryByCod (&Cty); + /* Country map */ + HTM_TD_Begin ("class=\"LM %s\"",BgColor); + Cty_DrawCountryMapAndNameWithLink (&Cty,ActSeeIns, + "COUNTRY_SMALL", + "COUNTRY_MAP_SMALL", + "BT_LINK DAT"); + HTM_TD_End (); - HTM_TR_Begin (NULL); + /* Number of pending institutions (row[1]) */ + HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor); + HTM_Txt (row[1]); + HTM_TD_End (); - /* Country map */ - HTM_TD_Begin ("class=\"LM %s\"",BgColor); - Cty_DrawCountryMapAndNameWithLink (&Cty,ActSeeIns, - "COUNTRY_SMALL", - "COUNTRY_MAP_SMALL", - "BT_LINK DAT"); - HTM_TD_End (); - - /* Number of pending institutions (row[1]) */ - HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor); - HTM_Txt (row[1]); - HTM_TD_End (); - - HTM_TR_End (); - Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd; - } + /* End row for this country */ + HTM_TR_End (); + } /***** End table and box *****/ Box_BoxTableEnd (); @@ -242,107 +228,107 @@ void Cty_ListCountries2 (void) Cty_PutIconsListingCountries,NULL, Hlp_SYSTEM_Countries,Box_NOT_CLOSABLE,2); - /***** Write heading *****/ - Cty_PutHeadCountriesForSeeing (true); // Order selectable + /***** Write heading *****/ + Cty_PutHeadCountriesForSeeing (true); // Order selectable - /***** Write all the countries and their number of users and institutions *****/ - for (NumCty = 0; - NumCty < Gbl.Hierarchy.Ctys.Num; - NumCty++) - Cty_ListOneCountryForSeeing (&Gbl.Hierarchy.Ctys.Lst[NumCty],NumCty + 1); + /***** Write all the countries and their number of users and institutions *****/ + for (NumCty = 0; + NumCty < Gbl.Hierarchy.Ctys.Num; + NumCty++) + Cty_ListOneCountryForSeeing (&Gbl.Hierarchy.Ctys.Lst[NumCty],NumCty + 1); - /***** Separation row *****/ - HTM_TR_Begin (NULL); - HTM_TD_Begin ("colspan=\"8\" class=\"DAT CM\""); - HTM_NBSP (); - HTM_TD_End (); - HTM_TR_End (); + /***** Separation row *****/ + HTM_TR_Begin (NULL); + HTM_TD_Begin ("colspan=\"8\" class=\"DAT CM\""); + HTM_NBSP (); + HTM_TD_End (); + HTM_TR_End (); - /***** Write users and institutions in other countries *****/ - HTM_TR_Begin (NULL); + /***** Write users and institutions in other countries *****/ + HTM_TR_Begin (NULL); - HTM_TD_Begin ("class=\"DAT RM\""); - HTM_TD_End (); + HTM_TD_Begin ("class=\"DAT RM\""); + HTM_TD_End (); - HTM_TD_Begin ("class=\"DAT LM\""); - HTM_Txt (Txt_Other_countries); - HTM_TD_End (); + HTM_TD_Begin ("class=\"DAT LM\""); + HTM_Txt (Txt_Other_countries); + HTM_TD_End (); - /* Number of users who claim to belong to another country */ - HTM_TD_Begin ("class=\"DAT RM\""); - HTM_Unsigned (Usr_GetCachedNumUsrsWhoClaimToBelongToAnotherCty ()); - HTM_TD_End (); + /* Number of users who claim to belong to another country */ + HTM_TD_Begin ("class=\"DAT RM\""); + HTM_Unsigned (Usr_GetCachedNumUsrsWhoClaimToBelongToAnotherCty ()); + HTM_TD_End (); - /* Number of institutions in other countries */ - HTM_TD_Begin ("class=\"DAT RM\""); - HTM_Unsigned (Ins_GetCachedNumInssInCty (0)); - HTM_TD_End (); + /* Number of institutions in other countries */ + HTM_TD_Begin ("class=\"DAT RM\""); + HTM_Unsigned (Ins_GetCachedNumInssInCty (0)); + HTM_TD_End (); - /* Number of centers in other countries */ - HTM_TD_Begin ("class=\"DAT RM\""); - HTM_Unsigned (Ctr_GetCachedNumCtrsInCty (0)); - HTM_TD_End (); + /* Number of centers in other countries */ + HTM_TD_Begin ("class=\"DAT RM\""); + HTM_Unsigned (Ctr_GetCachedNumCtrsInCty (0)); + HTM_TD_End (); - /* Number of degrees in other countries */ - HTM_TD_Begin ("class=\"DAT RM\""); - HTM_Unsigned (Deg_GetCachedNumDegsInCty (0)); - HTM_TD_End (); + /* Number of degrees in other countries */ + HTM_TD_Begin ("class=\"DAT RM\""); + HTM_Unsigned (Deg_GetCachedNumDegsInCty (0)); + HTM_TD_End (); - /* Number of courses in other countries */ - HTM_TD_Begin ("class=\"DAT RM\""); - HTM_Unsigned (Crs_GetCachedNumCrssInCty (0)); - HTM_TD_End (); + /* Number of courses in other countries */ + HTM_TD_Begin ("class=\"DAT RM\""); + HTM_Unsigned (Crs_GetCachedNumCrssInCty (0)); + HTM_TD_End (); - /* Number of users in courses of other countries */ - HTM_TD_Begin ("class=\"DAT RM\""); - HTM_Unsigned (Usr_GetCachedNumUsrsInCrss (Hie_Lvl_CTY,0, - 1 << Rol_STD | - 1 << Rol_NET | - 1 << Rol_TCH)); // Any user - HTM_TD_End (); + /* Number of users in courses of other countries */ + HTM_TD_Begin ("class=\"DAT RM\""); + HTM_Unsigned (Usr_GetCachedNumUsrsInCrss (Hie_Lvl_CTY,0, + 1 << Rol_STD | + 1 << Rol_NET | + 1 << Rol_TCH)); // Any user + HTM_TD_End (); - HTM_TR_End (); + HTM_TR_End (); - /***** Write users and institutions with unknown country *****/ - HTM_TR_Begin (NULL); + /***** Write users and institutions with unknown country *****/ + HTM_TR_Begin (NULL); - HTM_TD_Begin ("class=\"DAT RM\""); - HTM_TD_End (); + HTM_TD_Begin ("class=\"DAT RM\""); + HTM_TD_End (); - HTM_TD_Begin ("class=\"DAT LM\""); - HTM_Txt (Txt_Country_unspecified); - HTM_TD_End (); + HTM_TD_Begin ("class=\"DAT LM\""); + HTM_Txt (Txt_Country_unspecified); + HTM_TD_End (); - /* Number of users who do not claim to belong to any country */ - HTM_TD_Begin ("class=\"DAT RM\""); - HTM_Unsigned (Usr_GetCachedNumUsrsWhoDontClaimToBelongToAnyCty ()); - HTM_TD_End (); + /* Number of users who do not claim to belong to any country */ + HTM_TD_Begin ("class=\"DAT RM\""); + HTM_Unsigned (Usr_GetCachedNumUsrsWhoDontClaimToBelongToAnyCty ()); + HTM_TD_End (); - /* Number of institutions with unknown country */ - HTM_TD_Begin ("class=\"DAT RM\""); - HTM_Unsigned (Ins_GetCachedNumInssInCty (-1L)); - HTM_TD_End (); + /* Number of institutions with unknown country */ + HTM_TD_Begin ("class=\"DAT RM\""); + HTM_Unsigned (Ins_GetCachedNumInssInCty (-1L)); + HTM_TD_End (); - /* Number of centers with unknown country */ - HTM_TD_Begin ("class=\"DAT RM\""); - HTM_Unsigned (Ctr_GetCachedNumCtrsInCty (-1L)); - HTM_TD_End (); + /* Number of centers with unknown country */ + HTM_TD_Begin ("class=\"DAT RM\""); + HTM_Unsigned (Ctr_GetCachedNumCtrsInCty (-1L)); + HTM_TD_End (); - /* Number of degrees with unknown country */ - HTM_TD_Begin ("class=\"DAT RM\""); - HTM_Unsigned (Deg_GetCachedNumDegsInCty (-1L)); - HTM_TD_End (); + /* Number of degrees with unknown country */ + HTM_TD_Begin ("class=\"DAT RM\""); + HTM_Unsigned (Deg_GetCachedNumDegsInCty (-1L)); + HTM_TD_End (); - /* Number of courses with unknown country */ - HTM_TD_Begin ("class=\"DAT RM\""); - HTM_Unsigned (Crs_GetCachedNumCrssInCty (-1L)); - HTM_TD_End (); + /* Number of courses with unknown country */ + HTM_TD_Begin ("class=\"DAT RM\""); + HTM_Unsigned (Crs_GetCachedNumCrssInCty (-1L)); + HTM_TD_End (); - HTM_TD_Begin ("class=\"DAT RM\""); - HTM_Unsigned (0); - HTM_TD_End (); + HTM_TD_Begin ("class=\"DAT RM\""); + HTM_Unsigned (0); + HTM_TD_End (); - HTM_TR_End (); + HTM_TR_End (); /***** End table and box *****/ Box_BoxTableEnd (); @@ -375,41 +361,41 @@ static void Cty_PutHeadCountriesForSeeing (bool OrderSelectable) HTM_TR_Begin (NULL); - HTM_TH_Empty (1); - for (Order = Cty_ORDER_BY_COUNTRY; - Order <= Cty_ORDER_BY_NUM_USRS; - Order++) - { - HTM_TH_Begin (1,1,Order == Cty_ORDER_BY_COUNTRY ? "LM" : - "RM"); - if (OrderSelectable) + HTM_TH_Empty (1); + for (Order = Cty_ORDER_BY_COUNTRY; + Order <= Cty_ORDER_BY_NUM_USRS; + Order++) { - Frm_BeginForm (ActSeeCty); - Par_PutHiddenParamUnsigned (NULL,"Order",(unsigned) Order); - HTM_BUTTON_SUBMIT_Begin (Txt_COUNTRIES_HELP_ORDER[Order],"BT_LINK TIT_TBL",NULL); - if (Order == Gbl.Hierarchy.Ctys.SelectedOrder) - HTM_U_Begin (); + HTM_TH_Begin (1,1,Order == Cty_ORDER_BY_COUNTRY ? "LM" : + "RM"); + if (OrderSelectable) + { + Frm_BeginForm (ActSeeCty); + Par_PutHiddenParamUnsigned (NULL,"Order",(unsigned) Order); + HTM_BUTTON_SUBMIT_Begin (Txt_COUNTRIES_HELP_ORDER[Order],"BT_LINK TIT_TBL",NULL); + if (Order == Gbl.Hierarchy.Ctys.SelectedOrder) + HTM_U_Begin (); + } + HTM_Txt (Txt_COUNTRIES_ORDER[Order]); + if (OrderSelectable) + { + if (Order == Gbl.Hierarchy.Ctys.SelectedOrder) + HTM_U_End (); + HTM_BUTTON_End (); + Frm_EndForm (); + } + HTM_TH_End (); } - HTM_Txt (Txt_COUNTRIES_ORDER[Order]); - if (OrderSelectable) - { - if (Order == Gbl.Hierarchy.Ctys.SelectedOrder) - HTM_U_End (); - HTM_BUTTON_End (); - Frm_EndForm (); - } - HTM_TH_End (); - } - HTM_TH (1,1,"RM",Txt_Institutions_ABBREVIATION); - HTM_TH (1,1,"RM",Txt_Centers_ABBREVIATION); - HTM_TH (1,1,"RM",Txt_Degrees_ABBREVIATION); - HTM_TH (1,1,"RM",Txt_Courses_ABBREVIATION); - HTM_TH_Begin (1,1,"RM"); - HTM_TxtF ("%s+",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH]); - HTM_BR (); - HTM_Txt (Txt_ROLES_PLURAL_BRIEF_Abc[Rol_STD]); - HTM_TH_End (); + HTM_TH (1,1,"RM",Txt_Institutions_ABBREVIATION); + HTM_TH (1,1,"RM",Txt_Centers_ABBREVIATION); + HTM_TH (1,1,"RM",Txt_Degrees_ABBREVIATION); + HTM_TH (1,1,"RM",Txt_Courses_ABBREVIATION); + HTM_TH_Begin (1,1,"RM"); + HTM_TxtF ("%s+",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH]); + HTM_BR (); + HTM_Txt (Txt_ROLES_PLURAL_BRIEF_Abc[Rol_STD]); + HTM_TH_End (); HTM_TR_End (); } @@ -427,51 +413,51 @@ static void Cty_ListOneCountryForSeeing (struct Cty_Countr *Cty,unsigned NumCty) HTM_TR_Begin (NULL); - /***** Number of country in this list *****/ - HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor); - HTM_Unsigned (NumCty); - HTM_TD_End (); + /***** Number of country in this list *****/ + HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor); + HTM_Unsigned (NumCty); + HTM_TD_End (); - /***** Country map (and link to WWW if exists) *****/ - HTM_TD_Begin ("class=\"LM %s\"",BgColor); - Cty_DrawCountryMapAndNameWithLink (Cty,ActSeeIns, - "COUNTRY_SMALL", - "COUNTRY_MAP_SMALL", - "BT_LINK DAT_N"); - HTM_TD_End (); + /***** Country map (and link to WWW if exists) *****/ + HTM_TD_Begin ("class=\"LM %s\"",BgColor); + Cty_DrawCountryMapAndNameWithLink (Cty,ActSeeIns, + "COUNTRY_SMALL", + "COUNTRY_MAP_SMALL", + "BT_LINK DAT_N"); + HTM_TD_End (); - /***** Number of users who claim to belong to this country *****/ - HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor); - HTM_Unsigned (Usr_GetCachedNumUsrsWhoClaimToBelongToCty (Cty)); - HTM_TD_End (); + /***** Number of users who claim to belong to this country *****/ + HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor); + HTM_Unsigned (Usr_GetCachedNumUsrsWhoClaimToBelongToCty (Cty)); + HTM_TD_End (); - /***** Number of institutions *****/ - HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor); - HTM_Unsigned (Ins_GetCachedNumInssInCty (Cty->CtyCod)); - HTM_TD_End (); + /***** Number of institutions *****/ + HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor); + HTM_Unsigned (Ins_GetCachedNumInssInCty (Cty->CtyCod)); + HTM_TD_End (); - /***** Number of centers *****/ - HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor); - HTM_Unsigned (Ctr_GetCachedNumCtrsInCty (Cty->CtyCod)); - HTM_TD_End (); + /***** Number of centers *****/ + HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor); + HTM_Unsigned (Ctr_GetCachedNumCtrsInCty (Cty->CtyCod)); + HTM_TD_End (); - /***** Number of degrees *****/ - HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor); - HTM_Unsigned (Deg_GetCachedNumDegsInCty (Cty->CtyCod)); - HTM_TD_End (); + /***** Number of degrees *****/ + HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor); + HTM_Unsigned (Deg_GetCachedNumDegsInCty (Cty->CtyCod)); + HTM_TD_End (); - /***** Number of courses *****/ - HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor); - HTM_Unsigned (Crs_GetCachedNumCrssInCty (Cty->CtyCod)); - HTM_TD_End (); + /***** Number of courses *****/ + HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor); + HTM_Unsigned (Crs_GetCachedNumCrssInCty (Cty->CtyCod)); + HTM_TD_End (); - /***** Number of users in courses *****/ - HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor); - HTM_Unsigned (Usr_GetCachedNumUsrsInCrss (Hie_Lvl_CTY,Cty->CtyCod, - 1 << Rol_STD | - 1 << Rol_NET | - 1 << Rol_TCH)); // Any user - HTM_TD_End (); + /***** Number of users in courses *****/ + HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor); + HTM_Unsigned (Usr_GetCachedNumUsrsInCrss (Hie_Lvl_CTY,Cty->CtyCod, + 1 << Rol_STD | + 1 << Rol_NET | + 1 << Rol_TCH)); // Any user + HTM_TD_End (); HTM_TR_End (); @@ -525,26 +511,30 @@ void Cty_DrawCountryMapAndNameWithLink (struct Cty_Countr *Cty,Act_Action_t Acti /***** Begin form *****/ Frm_BeginFormGoTo (Action); Cty_PutParamCtyCod (Cty->CtyCod); - HTM_DIV_Begin ("class=\"%s\"",ClassContainer); - /***** Link to action *****/ - HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (Cty->Name[Gbl.Prefs.Language]), - ClassLink,NULL); - Hie_FreeGoToMsg (); + /***** Begin container *****/ + HTM_DIV_Begin ("class=\"%s\"",ClassContainer); - /***** Draw country map *****/ - Cty_DrawCountryMap (Cty,ClassMap); + /***** Link to action *****/ + HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (Cty->Name[Gbl.Prefs.Language]), + ClassLink,NULL); + Hie_FreeGoToMsg (); - /***** Write country name *****/ - Str_Copy (CountryName,Cty->Name[Gbl.Prefs.Language],sizeof (CountryName) - 1); - HTM_TxtF (" %s ",CountryName); - HTM_TxtF ("(%s)",Cty->Alpha2); + /***** Draw country map *****/ + Cty_DrawCountryMap (Cty,ClassMap); - /***** End link *****/ - HTM_BUTTON_End (); + /***** Write country name *****/ + Str_Copy (CountryName,Cty->Name[Gbl.Prefs.Language],sizeof (CountryName) - 1); + HTM_TxtF (" %s ",CountryName); + HTM_TxtF ("(%s)",Cty->Alpha2); + + /***** End link *****/ + HTM_BUTTON_End (); + + /***** End container *****/ + HTM_DIV_End (); /***** End form *****/ - HTM_DIV_End (); Frm_EndForm (); /***** Map *****/ @@ -611,50 +601,50 @@ void Cty_WriteScriptGoogleGeochart (void) HTM_SCRIPT_End (); HTM_SCRIPT_Begin (NULL,NULL); - HTM_TxtF (" google.load('visualization', '1', {'packages': ['geochart']});\n" - " google.setOnLoadCallback(drawRegionsMap);\n" - " function drawRegionsMap() {\n" - " var data = new google.visualization.DataTable();\n" - " data.addColumn('string', '%s');\n" - " data.addColumn('number', '%s');\n" - " data.addColumn('number', '%s');\n" - " data.addRows([\n", - Txt_Country_NO_HTML, - Txt_Users_NO_HTML, - Txt_Institutions_NO_HTML); + HTM_TxtF (" google.load('visualization', '1', {'packages': ['geochart']});\n" + " google.setOnLoadCallback(drawRegionsMap);\n" + " function drawRegionsMap() {\n" + " var data = new google.visualization.DataTable();\n" + " data.addColumn('string', '%s');\n" + " data.addColumn('number', '%s');\n" + " data.addColumn('number', '%s');\n" + " data.addRows([\n", + Txt_Country_NO_HTML, + Txt_Users_NO_HTML, + Txt_Institutions_NO_HTML); - /***** Write all the countries and their number of users and institutions *****/ - for (NumCty = 0; - NumCty < Gbl.Hierarchy.Ctys.Num; - NumCty++) - { - NumUsrsCty = Usr_GetCachedNumUsrsWhoClaimToBelongToCty (&Gbl.Hierarchy.Ctys.Lst[NumCty]); - if (NumUsrsCty) - { - NumInss = Ins_GetCachedNumInssInCty (Gbl.Hierarchy.Ctys.Lst[NumCty].CtyCod); + /***** Write all the countries and their number of users and institutions *****/ + for (NumCty = 0; + NumCty < Gbl.Hierarchy.Ctys.Num; + NumCty++) + { + NumUsrsCty = Usr_GetCachedNumUsrsWhoClaimToBelongToCty (&Gbl.Hierarchy.Ctys.Lst[NumCty]); + if (NumUsrsCty) + { + NumInss = Ins_GetCachedNumInssInCty (Gbl.Hierarchy.Ctys.Lst[NumCty].CtyCod); - /* Write data of this country */ - HTM_TxtF (" ['%s', %u, %u],\n", - Gbl.Hierarchy.Ctys.Lst[NumCty].Alpha2,NumUsrsCty,NumInss); - if (NumUsrsCty > MaxUsrsInCountry) - MaxUsrsInCountry = NumUsrsCty; - NumCtysWithUsrs++; - } - } + /* Write data of this country */ + HTM_TxtF (" ['%s', %u, %u],\n", + Gbl.Hierarchy.Ctys.Lst[NumCty].Alpha2,NumUsrsCty,NumInss); + if (NumUsrsCty > MaxUsrsInCountry) + MaxUsrsInCountry = NumUsrsCty; + NumCtysWithUsrs++; + } + } - /***** Write end of the script *****/ - HTM_TxtF (" ]);\n" - " var options = {\n" - " width:600,\n" - " height:360,\n" - " backgroundColor:'white',\n" - " datalessRegionColor:'white',\n" - " colorAxis:{colors:['#EAF1F4','#4D88A1'],minValue:0,maxValue:%u}};\n" - " var chart = new google.visualization.GeoChart(document.getElementById('chart_div'));\n" - " chart.draw(data, options);\n" - " };\n", - NumCtysWithUsrs ? MaxUsrsInCountry : - 0); + /***** Write end of the script *****/ + HTM_TxtF (" ]);\n" + " var options = {\n" + " width:600,\n" + " height:360,\n" + " backgroundColor:'white',\n" + " datalessRegionColor:'white',\n" + " colorAxis:{colors:['#EAF1F4','#4D88A1'],minValue:0,maxValue:%u}};\n" + " var chart = new google.visualization.GeoChart(document.getElementById('chart_div'));\n" + " chart.draw(data, options);\n" + " };\n", + NumCtysWithUsrs ? MaxUsrsInCountry : + 0); HTM_SCRIPT_End (); } @@ -704,12 +694,12 @@ static void Cty_EditCountriesInternal (void) Cty_PutIconsEditingCountries,NULL, Hlp_SYSTEM_Countries,Box_NOT_CLOSABLE); - /***** Put a form to create a new country *****/ - Cty_PutFormToCreateCountry (); + /***** Put a form to create a new country *****/ + Cty_PutFormToCreateCountry (); - /***** Forms to edit current countries *****/ - if (Gbl.Hierarchy.Ctys.Num) - Cty_ListCountriesForEdition (); + /***** Forms to edit current countries *****/ + if (Gbl.Hierarchy.Ctys.Num) + Cty_ListCountriesForEdition (); /***** End box *****/ Box_BoxEnd (); @@ -751,24 +741,18 @@ static void Cty_PutIconToViewCountries (void) void Cty_GetBasicListOfCountries (void) { - extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES]; MYSQL_RES *mysql_res; MYSQL_ROW row; unsigned NumCty; struct Cty_Countr *Cty; Lan_Language_t Lan; + /***** Trivial check: if list is already got, nothing to do *****/ + if (Gbl.Hierarchy.Ctys.Num) + return; + /***** Get countries from database *****/ - Gbl.Hierarchy.Ctys.Num = (unsigned) - DB_QuerySELECT (&mysql_res,"can not get countries", - "SELECT CtyCod," // row[0] - "Alpha2," // row[1] - "Name_%s" // row[2] - " FROM cty_countrs" - " ORDER BY Name_%s", - Lan_STR_LANG_ID[Gbl.Prefs.Language], - Lan_STR_LANG_ID[Gbl.Prefs.Language]); - if (Gbl.Hierarchy.Ctys.Num) // Countries found... + if ((Gbl.Hierarchy.Ctys.Num = Cty_DB_GetBasicListOfCountries (&mysql_res))) // Countries found... { /***** Create list with countries *****/ if ((Gbl.Hierarchy.Ctys.Lst = calloc ((size_t) Gbl.Hierarchy.Ctys.Num, @@ -789,9 +773,7 @@ void Cty_GetBasicListOfCountries (void) if ((Cty->CtyCod = Str_ConvertStrCodToLongCod (row[0])) <= 0) Err_WrongCountrExit (); - /* Get Alpha-2 country code (row[1]) */ - Str_Copy (Cty->Alpha2,row[1],sizeof (Cty->Alpha2) - 1); - + /* Reset names and webs */ for (Lan = (Lan_Language_t) 1; Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES; Lan++) @@ -801,7 +783,7 @@ void Cty_GetBasicListOfCountries (void) } /* 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[1], sizeof (Cty->Name[Gbl.Prefs.Language]) - 1); /* Reset number of users who claim to belong to country */ @@ -822,79 +804,18 @@ void Cty_GetBasicListOfCountries (void) 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; - static const char *OrderBySubQueryFmt[Cty_NUM_ORDERS] = - { - [Cty_ORDER_BY_COUNTRY ] = "Name_%s", - [Cty_ORDER_BY_NUM_USRS] = "NumUsrs DESC,Name_%s", - }; MYSQL_RES *mysql_res; MYSQL_ROW row; unsigned NumCty; struct Cty_Countr *Cty; Lan_Language_t Lan; + /***** Trivial check: if list is already got, nothing to do *****/ + if (Gbl.Hierarchy.Ctys.Num) + return; + /***** 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),"cty_countrs.Name_%s,",Lan_STR_LANG_ID[Lan]); - Str_Concat (SubQueryNam1,StrField,sizeof (SubQueryNam1) - 1); - snprintf (StrField,sizeof (StrField),"Name_%s,",Lan_STR_LANG_ID[Lan]); - Str_Concat (SubQueryNam2,StrField,sizeof (SubQueryNam2) - 1); - - snprintf (StrField,sizeof (StrField),"cty_countrs.WWW_%s,",Lan_STR_LANG_ID[Lan]); - Str_Concat (SubQueryWWW1,StrField,sizeof (SubQueryWWW1) - 1); - snprintf (StrField,sizeof (StrField),"WWW_%s,",Lan_STR_LANG_ID[Lan]); - Str_Concat (SubQueryWWW2,StrField,sizeof (SubQueryWWW2) - 1); - } - - /* Build order subquery */ - if (asprintf (&OrderBySubQuery,OrderBySubQueryFmt[Gbl.Hierarchy.Ctys.SelectedOrder], - Lan_STR_LANG_ID[Gbl.Prefs.Language]) < 0) - Err_NotEnoughMemoryExit (); - - /* Query database */ - Gbl.Hierarchy.Ctys.Num = (unsigned) - DB_QuerySELECT (&mysql_res,"can not get countries", - "(SELECT cty_countrs.CtyCod," // row[0] - "cty_countrs.Alpha2," // row[1] - "%s" // row[...] - "%s" // row[...] - "COUNT(*) AS NumUsrs" // row[...] - " FROM cty_countrs," - "usr_data" - " WHERE cty_countrs.CtyCod=usr_data.CtyCod" - " GROUP BY cty_countrs.CtyCod)" - " UNION " - "(SELECT CtyCod," // row[0] - "Alpha2," // row[1] - "%s" // row[...] - "%s" // row[...] - "0 AS NumUsrs" // row[...] - " FROM cty_countrs" - " 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 (Gbl.Hierarchy.Ctys.Num) // Countries found... + if ((Gbl.Hierarchy.Ctys.Num = Cty_DB_GetFullListOfCountries (&mysql_res))) // Countries found... { /***** Create list with countries *****/ if ((Gbl.Hierarchy.Ctys.Lst = calloc ((size_t) Gbl.Hierarchy.Ctys.Num, @@ -948,54 +869,37 @@ void Cty_GetFullListOfCountries (void) void Cty_WriteSelectorOfCountry (void) { extern const char *Txt_Country; - extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES]; - MYSQL_RES *mysql_res; - MYSQL_ROW row; - unsigned NumCtys; unsigned NumCty; - long CtyCod; + + /***** Get list of countries *****/ + Cty_GetBasicListOfCountries (); /***** Begin form *****/ Frm_BeginFormGoTo (ActSeeIns); - HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, - "id=\"cty\" name=\"cty\" class=\"HIE_SEL\""); - HTM_OPTION (HTM_Type_STRING,"",Gbl.Hierarchy.Cty.CtyCod < 0,true, - "[%s]",Txt_Country); - /***** Get countries from database *****/ - NumCtys = (unsigned) - DB_QuerySELECT (&mysql_res,"can not get countries", - "SELECT DISTINCT CtyCod," // row[0] - "Name_%s" // row[1] - " FROM cty_countrs" - " ORDER BY Name_%s", - Lan_STR_LANG_ID[Gbl.Prefs.Language], - Lan_STR_LANG_ID[Gbl.Prefs.Language]); + /* Begin selector of country */ + HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, + "id=\"cty\" name=\"cty\" class=\"HIE_SEL\""); - /***** List countries *****/ - for (NumCty = 0; - NumCty < NumCtys; - NumCty++) - { - /* Get next country */ - row = mysql_fetch_row (mysql_res); + /* Initial disabled option */ + HTM_OPTION (HTM_Type_STRING,"",Gbl.Hierarchy.Cty.CtyCod < 0,true, + "[%s]",Txt_Country); - /* Get country code (row[0]) */ - if ((CtyCod = Str_ConvertStrCodToLongCod (row[0])) <= 0) - Err_WrongCountrExit (); + /* List countries */ + for (NumCty = 0; + NumCty < Gbl.Hierarchy.Ctys.Num; + NumCty++) + HTM_OPTION (HTM_Type_LONG,&Gbl.Hierarchy.Ctys.Lst[NumCty].CtyCod, + Gbl.Hierarchy.Ctys.Lst[NumCty].CtyCod == Gbl.Hierarchy.Cty.CtyCod,false, + "%s",Gbl.Hierarchy.Ctys.Lst[NumCty].Name[Gbl.Prefs.Language]); - /* Write option */ - HTM_OPTION (HTM_Type_LONG,&CtyCod, - CtyCod == Gbl.Hierarchy.Cty.CtyCod,false, - "%s",row[1]); - } - - /***** Free structure that stores the query result *****/ - DB_FreeMySQLResult (&mysql_res); + /* End selector of country */ + HTM_SELECT_End (); /***** End form *****/ - HTM_SELECT_End (); Frm_EndForm (); + + // Do not free list of countries here, because it can be reused } /*****************************************************************************/ @@ -1018,9 +922,9 @@ void Cty_WriteCountryName (long CtyCod,const char *ClassLink) /***** Write country name with link to country information *****/ Frm_BeginForm (ActSeeCtyInf); Cty_PutParamCtyCod (CtyCod); - HTM_BUTTON_SUBMIT_Begin (Act_GetActionText (ActSeeCtyInf),ClassLink,NULL); - HTM_Txt (CtyName); - HTM_BUTTON_End (); + HTM_BUTTON_SUBMIT_Begin (Act_GetActionText (ActSeeCtyInf),ClassLink,NULL); + HTM_Txt (CtyName); + HTM_BUTTON_End (); Frm_EndForm (); } else @@ -1192,44 +1096,44 @@ static void Cty_ListCountriesForEdition (void) HTM_TR_Begin (NULL); - /* Put icon to remove country */ - HTM_TD_Begin ("rowspan=\"%u\" class=\"BT\"",1 + Lan_NUM_LANGUAGES); - if (NumInss || // Country has institutions - NumUsrsCty) // Country has users - // Deletion forbidden - Ico_PutIconRemovalNotAllowed (); - else if (Usr_GetNumUsrsInCrss (Hie_Lvl_CTY,Cty->CtyCod, - 1 << Rol_STD | - 1 << Rol_NET | - 1 << Rol_TCH)) // Country has users - // Deletion forbidden - Ico_PutIconRemovalNotAllowed (); - else - Ico_PutContextualIconToRemove (ActRemCty,NULL, - Cty_PutParamOtherCtyCod,&Cty->CtyCod); - HTM_TD_End (); + /* Put icon to remove country */ + HTM_TD_Begin ("rowspan=\"%u\" class=\"BT\"",1 + Lan_NUM_LANGUAGES); + if (NumInss || // Country has institutions + NumUsrsCty) // Country has users + // Deletion forbidden + Ico_PutIconRemovalNotAllowed (); + else if (Usr_GetNumUsrsInCrss (Hie_Lvl_CTY,Cty->CtyCod, + 1 << Rol_STD | + 1 << Rol_NET | + 1 << Rol_TCH)) // Country has users + // Deletion forbidden + Ico_PutIconRemovalNotAllowed (); + else + Ico_PutContextualIconToRemove (ActRemCty,NULL, + Cty_PutParamOtherCtyCod,&Cty->CtyCod); + HTM_TD_End (); - /* Numerical country code (ISO 3166-1) */ - HTM_TD_Begin ("rowspan=\"%u\" class=\"DAT RT\"",1 + Lan_NUM_LANGUAGES); - HTM_TxtF ("%03ld",Cty->CtyCod); - HTM_TD_End (); + /* Numerical country code (ISO 3166-1) */ + HTM_TD_Begin ("rowspan=\"%u\" class=\"DAT RT\"",1 + Lan_NUM_LANGUAGES); + HTM_TxtF ("%03ld",Cty->CtyCod); + HTM_TD_End (); - /* Alphabetic country code with 2 letters (ISO 3166-1) */ - HTM_TD_Begin ("rowspan=\"%u\" class=\"DAT RT\"",1 + Lan_NUM_LANGUAGES); - HTM_Txt (Cty->Alpha2); - HTM_TD_End (); + /* Alphabetic country code with 2 letters (ISO 3166-1) */ + HTM_TD_Begin ("rowspan=\"%u\" class=\"DAT RT\"",1 + Lan_NUM_LANGUAGES); + HTM_Txt (Cty->Alpha2); + HTM_TD_End (); - HTM_TD_Empty (3); + HTM_TD_Empty (3); - /* Number of users */ - HTM_TD_Begin ("rowspan=\"%u\" class=\"DAT RT\"",1 + Lan_NUM_LANGUAGES); - HTM_Unsigned (NumUsrsCty); - HTM_TD_End (); + /* Number of users */ + HTM_TD_Begin ("rowspan=\"%u\" class=\"DAT RT\"",1 + Lan_NUM_LANGUAGES); + HTM_Unsigned (NumUsrsCty); + HTM_TD_End (); - /* Number of institutions */ - HTM_TD_Begin ("rowspan=\"%u\" class=\"DAT RT\"",1 + Lan_NUM_LANGUAGES); - HTM_Unsigned (NumInss); - HTM_TD_End (); + /* Number of institutions */ + HTM_TD_Begin ("rowspan=\"%u\" class=\"DAT RT\"",1 + Lan_NUM_LANGUAGES); + HTM_Unsigned (NumInss); + HTM_TD_End (); HTM_TR_End (); @@ -1240,31 +1144,31 @@ static void Cty_ListCountriesForEdition (void) { HTM_TR_Begin (NULL); - /* Language */ - HTM_TD_Begin ("class=\"DAT RM\""); - HTM_TxtColon (Txt_STR_LANG_NAME[Lan]); - HTM_TD_End (); + /* Language */ + HTM_TD_Begin ("class=\"DAT RM\""); + HTM_TxtColon (Txt_STR_LANG_NAME[Lan]); + HTM_TD_End (); - /* Name */ - HTM_TD_Begin ("class=\"LT\""); - Frm_BeginForm (ActRenCty); - Cty_PutParamOtherCtyCod (&Cty->CtyCod); - Par_PutHiddenParamUnsigned (NULL,"Lan",(unsigned) Lan); - HTM_INPUT_TEXT ("Name",Cty_MAX_CHARS_NAME,Cty->Name[Lan], - HTM_SUBMIT_ON_CHANGE, - "size=\"15\""); - Frm_EndForm (); - HTM_TD_End (); + /* Name */ + HTM_TD_Begin ("class=\"LT\""); + Frm_BeginForm (ActRenCty); + Cty_PutParamOtherCtyCod (&Cty->CtyCod); + Par_PutHiddenParamUnsigned (NULL,"Lan",(unsigned) Lan); + HTM_INPUT_TEXT ("Name",Cty_MAX_CHARS_NAME,Cty->Name[Lan], + HTM_SUBMIT_ON_CHANGE, + "size=\"15\""); + Frm_EndForm (); + HTM_TD_End (); - /* WWW */ - HTM_TD_Begin ("class=\"LT\""); - Frm_BeginForm (ActChgCtyWWW); - Cty_PutParamOtherCtyCod (&Cty->CtyCod); - Par_PutHiddenParamUnsigned (NULL,"Lan",(unsigned) Lan); - HTM_INPUT_URL ("WWW",Cty->WWW[Lan],HTM_SUBMIT_ON_CHANGE, - "class=\"INPUT_WWW_NARROW\" required=\"required\""); - Frm_EndForm (); - HTM_TD_End (); + /* WWW */ + HTM_TD_Begin ("class=\"LT\""); + Frm_BeginForm (ActChgCtyWWW); + Cty_PutParamOtherCtyCod (&Cty->CtyCod); + Par_PutHiddenParamUnsigned (NULL,"Lan",(unsigned) Lan); + HTM_INPUT_URL ("WWW",Cty->WWW[Lan],HTM_SUBMIT_ON_CHANGE, + "class=\"INPUT_WWW_NARROW\" required=\"required\""); + Frm_EndForm (); + HTM_TD_End (); HTM_TR_End (); } @@ -1412,7 +1316,7 @@ void Cty_RenameCountry (void) if (strcmp (Cty_EditingCty->Name[Language],NewCtyName)) // Different names { /***** If country was in database... *****/ - if (Cty_CheckIfCountryNameExists (Language,NewCtyName,Cty_EditingCty->CtyCod)) + if (Cty_DB_CheckIfCountryNameExists (Language,NewCtyName,Cty_EditingCty->CtyCod)) Ale_CreateAlert (Ale_WARNING,NULL, Txt_The_country_X_already_exists, NewCtyName); @@ -1446,7 +1350,7 @@ void Cty_RenameCountry (void) /******************* Check if a numeric country code exists ******************/ /*****************************************************************************/ -static bool Cty_CheckIfNumericCountryCodeExists (long CtyCod) +static bool Cty_DB_CheckIfNumericCountryCodeExists (long CtyCod) { /***** Get number of countries with a name from database *****/ return (DB_QueryCOUNT ("can not check if the numeric code" @@ -1461,7 +1365,7 @@ static bool Cty_CheckIfNumericCountryCodeExists (long CtyCod) /*************** Check if an alphabetic country code exists ******************/ /*****************************************************************************/ -static bool Cty_CheckIfAlpha2CountryCodeExists (const char Alpha2[2 + 1]) +static bool Cty_DB_CheckIfAlpha2CountryCodeExists (const char Alpha2[2 + 1]) { /***** Get number of countries with a name from database *****/ return (DB_QueryCOUNT ("can not check if the alphabetic code" @@ -1476,7 +1380,7 @@ static bool Cty_CheckIfAlpha2CountryCodeExists (const char Alpha2[2 + 1]) /******************** Check if the name of country exists ********************/ /*****************************************************************************/ -static bool Cty_CheckIfCountryNameExists (Lan_Language_t Language,const char *Name,long CtyCod) +static bool Cty_DB_CheckIfCountryNameExists (Lan_Language_t Language,const char *Name,long CtyCod) { extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES]; @@ -1614,82 +1518,82 @@ static void Cty_PutFormToCreateCountry (void) /***** Begin form *****/ Frm_BeginForm (ActNewCty); - /***** Begin box and table *****/ - Box_BoxTableBegin (NULL,Txt_New_country, - NULL,NULL, - NULL,Box_NOT_CLOSABLE,2); + /***** Begin box and table *****/ + Box_BoxTableBegin (NULL,Txt_New_country, + NULL,NULL, + NULL,Box_NOT_CLOSABLE,2); - /***** Write heading *****/ - Cty_PutHeadCountriesForEdition (); + /***** Write heading *****/ + Cty_PutHeadCountriesForEdition (); - HTM_TR_Begin (NULL); + HTM_TR_Begin (NULL); - /***** Column to remove country, disabled here *****/ - HTM_TD_Begin ("rowspan=\"%u\" class=\"BT\"",1 + Lan_NUM_LANGUAGES); - HTM_TD_End (); + /***** Column to remove country, disabled here *****/ + HTM_TD_Begin ("rowspan=\"%u\" class=\"BT\"",1 + Lan_NUM_LANGUAGES); + HTM_TD_End (); - /***** Numerical country code (ISO 3166-1) *****/ - HTM_TD_Begin ("rowspan=\"%u\" class=\"RT\"",1 + Lan_NUM_LANGUAGES); - if (Cty_EditingCty->CtyCod > 0) - snprintf (StrCtyCod,sizeof (StrCtyCod),"%03ld",Cty_EditingCty->CtyCod); - else - StrCtyCod[0] = '\0'; - HTM_INPUT_TEXT ("OthCtyCod",3,StrCtyCod,HTM_DONT_SUBMIT_ON_CHANGE, - "size=\"3\" required=\"required\""); - HTM_TD_End (); + /***** Numerical country code (ISO 3166-1) *****/ + HTM_TD_Begin ("rowspan=\"%u\" class=\"RT\"",1 + Lan_NUM_LANGUAGES); + if (Cty_EditingCty->CtyCod > 0) + snprintf (StrCtyCod,sizeof (StrCtyCod),"%03ld",Cty_EditingCty->CtyCod); + else + StrCtyCod[0] = '\0'; + HTM_INPUT_TEXT ("OthCtyCod",3,StrCtyCod,HTM_DONT_SUBMIT_ON_CHANGE, + "size=\"3\" required=\"required\""); + HTM_TD_End (); - /***** Alphabetic country code with 2 letters (ISO 3166-1) *****/ - HTM_TD_Begin ("rowspan=\"%u\" class=\"RT\"",1 + Lan_NUM_LANGUAGES); - HTM_INPUT_TEXT ("Alpha2",2,Cty_EditingCty->Alpha2,HTM_DONT_SUBMIT_ON_CHANGE, - "size=\"2\" required=\"required\""); - HTM_TD_End (); + /***** Alphabetic country code with 2 letters (ISO 3166-1) *****/ + HTM_TD_Begin ("rowspan=\"%u\" class=\"RT\"",1 + Lan_NUM_LANGUAGES); + HTM_INPUT_TEXT ("Alpha2",2,Cty_EditingCty->Alpha2,HTM_DONT_SUBMIT_ON_CHANGE, + "size=\"2\" required=\"required\""); + HTM_TD_End (); - HTM_TD_Empty (3); + HTM_TD_Empty (3); - /***** Number of users *****/ - HTM_TD_Begin ("rowspan=\"%u\" class=\"DAT RT\"",1 + Lan_NUM_LANGUAGES); - HTM_Unsigned (0); - HTM_TD_End (); + /***** Number of users *****/ + HTM_TD_Begin ("rowspan=\"%u\" class=\"DAT RT\"",1 + Lan_NUM_LANGUAGES); + HTM_Unsigned (0); + HTM_TD_End (); - /***** Number of institutions *****/ - HTM_TD_Begin ("rowspan=\"%u\" class=\"DAT RT\"",1 + Lan_NUM_LANGUAGES); - HTM_Unsigned (0); - HTM_TD_End (); + /***** Number of institutions *****/ + HTM_TD_Begin ("rowspan=\"%u\" class=\"DAT RT\"",1 + Lan_NUM_LANGUAGES); + HTM_Unsigned (0); + HTM_TD_End (); - HTM_TR_End (); + HTM_TR_End (); - /***** Country name in several languages *****/ - for (Lan = (Lan_Language_t) 1; - Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES; - Lan++) - { - HTM_TR_Begin (NULL); + /***** Country name in several languages *****/ + for (Lan = (Lan_Language_t) 1; + Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES; + Lan++) + { + HTM_TR_Begin (NULL); - /* Language */ - HTM_TD_Begin ("class=\"DAT RT\""); - HTM_Txt (Txt_STR_LANG_NAME[Lan]); - HTM_TD_End (); + /* Language */ + HTM_TD_Begin ("class=\"DAT RT\""); + HTM_Txt (Txt_STR_LANG_NAME[Lan]); + HTM_TD_End (); - /* Name */ - HTM_TD_Begin ("class=\"LM\""); - snprintf (StrName,sizeof (StrName),"Name_%s",Lan_STR_LANG_ID[Lan]); - HTM_INPUT_TEXT (StrName,Cty_MAX_CHARS_NAME,Cty_EditingCty->Name[Lan], - HTM_DONT_SUBMIT_ON_CHANGE, - "size=\"15\" required=\"required\""); - HTM_TD_End (); + /* Name */ + HTM_TD_Begin ("class=\"LM\""); + snprintf (StrName,sizeof (StrName),"Name_%s",Lan_STR_LANG_ID[Lan]); + HTM_INPUT_TEXT (StrName,Cty_MAX_CHARS_NAME,Cty_EditingCty->Name[Lan], + HTM_DONT_SUBMIT_ON_CHANGE, + "size=\"15\" required=\"required\""); + HTM_TD_End (); - /* WWW */ - HTM_TD_Begin ("class=\"LM\""); - snprintf (StrName,sizeof (StrName),"WWW_%s",Lan_STR_LANG_ID[Lan]); - HTM_INPUT_URL (StrName,Cty_EditingCty->WWW[Lan],HTM_DONT_SUBMIT_ON_CHANGE, - "class=\"INPUT_WWW_NARROW\" required=\"required\""); - HTM_TD_End (); + /* WWW */ + HTM_TD_Begin ("class=\"LM\""); + snprintf (StrName,sizeof (StrName),"WWW_%s",Lan_STR_LANG_ID[Lan]); + HTM_INPUT_URL (StrName,Cty_EditingCty->WWW[Lan],HTM_DONT_SUBMIT_ON_CHANGE, + "class=\"INPUT_WWW_NARROW\" required=\"required\""); + HTM_TD_End (); - HTM_TR_End (); - } + HTM_TR_End (); + } - /***** End table, send button and end box *****/ - Box_BoxTableWithButtonEnd (Btn_CREATE_BUTTON,Txt_Create_country); + /***** End table, send button and end box *****/ + Box_BoxTableWithButtonEnd (Btn_CREATE_BUTTON,Txt_Create_country); /***** End form *****/ Frm_EndForm (); @@ -1710,14 +1614,14 @@ static void Cty_PutHeadCountriesForEdition (void) HTM_TR_Begin (NULL); - HTM_TH (1,1,"BM",NULL); - HTM_TH (1,1,"RM",Txt_Numeric_BR_code_BR_ISO_3166_1); - HTM_TH (1,1,"RM",Txt_Alphabetic_BR_code_BR_ISO_3166_1); - HTM_TH_Empty (1); - HTM_TH (1,1,"LM",Txt_Name); - HTM_TH (1,1,"LM",Txt_WWW); - HTM_TH (1,1,"RM",Txt_Users); - HTM_TH (1,1,"RM",Txt_Institutions_ABBREVIATION); + HTM_TH (1,1,"BM",NULL); + HTM_TH (1,1,"RM",Txt_Numeric_BR_code_BR_ISO_3166_1); + HTM_TH (1,1,"RM",Txt_Alphabetic_BR_code_BR_ISO_3166_1); + HTM_TH_Empty (1); + HTM_TH (1,1,"LM",Txt_Name); + HTM_TH (1,1,"LM",Txt_WWW); + HTM_TH (1,1,"RM",Txt_Users); + HTM_TH (1,1,"RM",Txt_Institutions_ABBREVIATION); HTM_TR_End (); } @@ -1752,7 +1656,7 @@ void Cty_ReceiveFormNewCountry (void) Txt_You_must_specify_the_numerical_code_of_the_new_country); CreateCountry = false; } - else if (Cty_CheckIfNumericCountryCodeExists (Cty_EditingCty->CtyCod)) + else if (Cty_DB_CheckIfNumericCountryCodeExists (Cty_EditingCty->CtyCod)) { Ale_CreateAlert (Ale_WARNING,NULL, Txt_The_numerical_code_X_already_exists, @@ -1777,7 +1681,7 @@ void Cty_ReceiveFormNewCountry (void) } if (CreateCountry) { - if (Cty_CheckIfAlpha2CountryCodeExists (Cty_EditingCty->Alpha2)) + if (Cty_DB_CheckIfAlpha2CountryCodeExists (Cty_EditingCty->Alpha2)) { Ale_CreateAlert (Ale_WARNING,NULL, Txt_The_alphabetical_code_X_already_exists, @@ -1797,7 +1701,7 @@ void Cty_ReceiveFormNewCountry (void) if (Cty_EditingCty->Name[Lan][0]) // If there's a country name { /***** If name of country was in database... *****/ - if (Cty_CheckIfCountryNameExists (Lan,Cty_EditingCty->Name[Lan],-1L)) + if (Cty_DB_CheckIfCountryNameExists (Lan,Cty_EditingCty->Name[Lan],-1L)) { Ale_CreateAlert (Ale_WARNING,NULL, Txt_The_country_X_already_exists, @@ -2084,23 +1988,23 @@ void Cty_ListCtysFound (MYSQL_RES **mysql_res,unsigned NumCtys) NULL,Box_NOT_CLOSABLE,2); Str_FreeString (); - /***** Write heading *****/ - Cty_PutHeadCountriesForSeeing (false); // Order not selectable + /***** Write heading *****/ + Cty_PutHeadCountriesForSeeing (false); // Order not selectable - /***** List the countries (one row per country) *****/ - for (NumCty = 1; - NumCty <= NumCtys; - NumCty++) - { - /* Get next country */ - Cty.CtyCod = DB_GetNextCode (*mysql_res); + /***** List the countries (one row per country) *****/ + for (NumCty = 1; + NumCty <= NumCtys; + NumCty++) + { + /* Get next country */ + Cty.CtyCod = DB_GetNextCode (*mysql_res); - /* Get data of country */ - Cty_GetDataOfCountryByCod (&Cty); + /* Get data of country */ + Cty_GetDataOfCountryByCod (&Cty); - /* Write data of this country */ - Cty_ListOneCountryForSeeing (&Cty,NumCty); - } + /* Write data of this country */ + Cty_ListOneCountryForSeeing (&Cty,NumCty); + } /***** End table and box *****/ Box_BoxTableEnd (); diff --git a/swad_country_config.c b/swad_country_config.c index 06c9e9fa..ae8cb32a 100644 --- a/swad_country_config.c +++ b/swad_country_config.c @@ -32,6 +32,8 @@ #include // For free #include // For string functions +#include "swad_country_config.h" +#include "swad_country_database.h" #include "swad_database.h" #include "swad_error.h" #include "swad_figure_cache.h" @@ -67,7 +69,6 @@ extern struct Globals Gbl; static void CtyCfg_Configuration (bool PrintView); static void CtyCfg_PutIconToPrint (__attribute__((unused)) void *Args); static void CtyCfg_Title (bool PutLink); -static void CtyCfg_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom); static void CtyCfg_Map (void); static void CtyCfg_MapImage (bool PrintView,bool PutLink); static void CtyCfg_Platform (bool PrintView); @@ -138,68 +139,70 @@ static void CtyCfg_Configuration (bool PrintView) /**************************** Left part ***********************************/ HTM_DIV_Begin ("class=\"HIE_CFG_LEFT HIE_CFG_WIDTH\""); - /***** Begin table *****/ - HTM_TABLE_BeginWidePadding (2); + /* Begin table */ + HTM_TABLE_BeginWidePadding (2); - /***** Platform *****/ - CtyCfg_Platform (PrintView); + /* Platform */ + CtyCfg_Platform (PrintView); - /***** Country name (an link to WWW if exists) *****/ - CtyCfg_Name (PutLink); + /* Country name (an link to WWW if exists) */ + CtyCfg_Name (PutLink); - /***** Shortcut to the country *****/ - CtyCfg_Shortcut (PrintView); + /* Shortcut to the country */ + CtyCfg_Shortcut (PrintView); - NumCtrsWithMap = Ctr_GetCachedNumCtrsWithMapInCty (Gbl.Hierarchy.Cty.CtyCod); - if (PrintView) - /***** QR code with link to the country *****/ - CtyCfg_QR (); - else - { - NumCtrs = Ctr_GetCachedNumCtrsInCty (Gbl.Hierarchy.Cty.CtyCod); + NumCtrsWithMap = Ctr_GetCachedNumCtrsWithMapInCty (Gbl.Hierarchy.Cty.CtyCod); + if (PrintView) + /* QR code with link to the country */ + CtyCfg_QR (); + else + { + NumCtrs = Ctr_GetCachedNumCtrsInCty (Gbl.Hierarchy.Cty.CtyCod); - /***** Number of users who claim to belong to this country, - number of institutions, - number of centers, - number of degrees, - number of courses *****/ - CtyCfg_NumUsrs (); - CtyCfg_NumInss (); - HieCfg_NumCtrs (NumCtrs, - false); // Don't put form - HieCfg_NumCtrsWithMap (NumCtrs,NumCtrsWithMap); - CtyCfg_NumDegs (); - CtyCfg_NumCrss (); + /* Number of users who claim to belong to this country, + number of institutions, + number of centers, + number of degrees, + number of courses */ + CtyCfg_NumUsrs (); + CtyCfg_NumInss (); + HieCfg_NumCtrs (NumCtrs, + false); // Don't put form + HieCfg_NumCtrsWithMap (NumCtrs,NumCtrsWithMap); + CtyCfg_NumDegs (); + CtyCfg_NumCrss (); - /***** Number of users in courses of this country *****/ - HieCfg_NumUsrsInCrss (Hie_Lvl_CTY,Gbl.Hierarchy.Cty.CtyCod,Rol_TCH); - HieCfg_NumUsrsInCrss (Hie_Lvl_CTY,Gbl.Hierarchy.Cty.CtyCod,Rol_NET); - HieCfg_NumUsrsInCrss (Hie_Lvl_CTY,Gbl.Hierarchy.Cty.CtyCod,Rol_STD); - HieCfg_NumUsrsInCrss (Hie_Lvl_CTY,Gbl.Hierarchy.Cty.CtyCod,Rol_UNK); - } + /* Number of users in courses of this country */ + HieCfg_NumUsrsInCrss (Hie_Lvl_CTY,Gbl.Hierarchy.Cty.CtyCod,Rol_TCH); + HieCfg_NumUsrsInCrss (Hie_Lvl_CTY,Gbl.Hierarchy.Cty.CtyCod,Rol_NET); + HieCfg_NumUsrsInCrss (Hie_Lvl_CTY,Gbl.Hierarchy.Cty.CtyCod,Rol_STD); + HieCfg_NumUsrsInCrss (Hie_Lvl_CTY,Gbl.Hierarchy.Cty.CtyCod,Rol_UNK); + } - /***** End table *****/ - HTM_TABLE_End (); + /* End table */ + HTM_TABLE_End (); - /***** End of left part *****/ + /* End of left part */ HTM_DIV_End (); /**************************** Right part **********************************/ - /***** Check country map *****/ + /* Check country map */ MapImageExists = Cty_CheckIfCountryPhotoExists (&Gbl.Hierarchy.Cty); if (NumCtrsWithMap || MapImageExists) { + /* Begin container */ HTM_DIV_Begin ("class=\"HIE_CFG_RIGHT HIE_CFG_WIDTH\""); - /***** Country map *****/ - if (NumCtrsWithMap) - CtyCfg_Map (); + /* Country map */ + if (NumCtrsWithMap) + CtyCfg_Map (); - /***** Country map image *****/ - if (MapImageExists) - CtyCfg_MapImage (PrintView,PutLink); + /* Country map image */ + if (MapImageExists) + CtyCfg_MapImage (PrintView,PutLink); + /* End container */ HTM_DIV_End (); } @@ -223,46 +226,27 @@ static void CtyCfg_PutIconToPrint (__attribute__((unused)) void *Args) static void CtyCfg_Title (bool PutLink) { + /***** Begin container *****/ HTM_DIV_Begin ("class=\"FRAME_TITLE FRAME_TITLE_BIG\""); - if (PutLink) - HTM_A_Begin ("href=\"%s\" target=\"_blank\"" - " class=\"FRAME_TITLE_BIG\" title=\"%s\"", - Gbl.Hierarchy.Cty.WWW[Gbl.Prefs.Language], - Gbl.Hierarchy.Cty.Name[Gbl.Prefs.Language]); - HTM_Txt (Gbl.Hierarchy.Cty.Name[Gbl.Prefs.Language]); - if (PutLink) - HTM_A_End (); + + /* Begin link */ + if (PutLink) + HTM_A_Begin ("href=\"%s\" target=\"_blank\"" + " class=\"FRAME_TITLE_BIG\" title=\"%s\"", + Gbl.Hierarchy.Cty.WWW[Gbl.Prefs.Language], + Gbl.Hierarchy.Cty.Name[Gbl.Prefs.Language]); + + /* Country name */ + HTM_Txt (Gbl.Hierarchy.Cty.Name[Gbl.Prefs.Language]); + + /* End link */ + if (PutLink) + HTM_A_End (); + + /***** End container *****/ HTM_DIV_End (); } -/*****************************************************************************/ -/********* Get average coordinates of centers in current institution *********/ -/*****************************************************************************/ - -static void CtyCfg_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom) - { - char *Query; - - /***** Get average coordinates of centers of current country - with both coordinates set - (coordinates 0, 0 means not set ==> don't show map) *****/ - if (asprintf (&Query, - "SELECT AVG(ctr_centers.Latitude)," // row[0] - "AVG(ctr_centers.Longitude)," // row[1] - "GREATEST(MAX(ctr_centers.Latitude)-MIN(ctr_centers.Latitude)," - "MAX(ctr_centers.Longitude)-MIN(ctr_centers.Longitude))" // row[2] - " FROM ins_instits," - "ctr_centers" - " WHERE ins_instits.CtyCod=%ld" - " AND ins_instits.InsCod=ctr_centers.InsCod" - " AND ctr_centers.Latitude<>0" - " AND ctr_centers.Longitude<>0", - Gbl.Hierarchy.Cty.CtyCod) < 0) - Err_NotEnoughMemoryExit (); - Map_GetCoordAndZoom (Coord,Zoom,Query); - free (Query); - } - /*****************************************************************************/ /****************************** Draw country map *****************************/ /*****************************************************************************/ @@ -272,7 +256,7 @@ static void CtyCfg_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom) static void CtyCfg_Map (void) { MYSQL_RES *mysql_res; - struct Coordinates CtyAvgCoord; + struct Map_Coordinates CtyAvgCoord; unsigned Zoom; unsigned NumCtrs; unsigned NumCtr; @@ -292,50 +276,41 @@ static void CtyCfg_Map (void) /***** Script to draw the map *****/ HTM_SCRIPT_Begin (NULL,NULL); - /* Let's create a map with pretty Mapbox Streets tiles */ - CtyCfg_GetCoordAndZoom (&CtyAvgCoord,&Zoom); - Map_CreateMap (CtyCfg_MAP_CONTAINER_ID,&CtyAvgCoord,Zoom); + /* Let's create a map with pretty Mapbox Streets tiles */ + Cty_DB_GetCoordAndZoom (&CtyAvgCoord,&Zoom); + Map_CreateMap (CtyCfg_MAP_CONTAINER_ID,&CtyAvgCoord,Zoom); - /* Add Mapbox Streets tile layer to our map */ - Map_AddTileLayer (); + /* Add Mapbox Streets tile layer to our map */ + Map_AddTileLayer (); - /* Get centers with coordinates */ - NumCtrs = (unsigned) - DB_QuerySELECT (&mysql_res,"can not get centers with coordinates", - "SELECT ctr_centers.CtrCod" // row[0] - " FROM ins_instits," - "ctr_centers" - " WHERE ins_instits.CtyCod=%ld" - " AND ins_instits.InsCod=ctr_centers.InsCod" - " AND ctr_centers.Latitude<>0" - " AND ctr_centers.Longitude<>0", - Gbl.Hierarchy.Cty.CtyCod); + /* Get centers which have coordinates in the current country */ + NumCtrs = Cty_DB_GetCtrsWithCoordsInCurrentCty (&mysql_res); - /* Add a marker and a popup for each center */ - for (NumCtr = 0; - NumCtr < NumCtrs; - NumCtr++) - { - /* Get next center */ - Ctr.CtrCod = DB_GetNextCode (mysql_res); + /* Add a marker and a popup for each center */ + for (NumCtr = 0; + NumCtr < NumCtrs; + NumCtr++) + { + /* Get next center */ + Ctr.CtrCod = DB_GetNextCode (mysql_res); - /* Get data of center */ - Ctr_GetDataOfCenterByCod (&Ctr); + /* Get data of center */ + Ctr_GetDataOfCenterByCod (&Ctr); - /* Get data of institution */ - Ins.InsCod = Ctr.InsCod; - Ins_GetDataOfInstitutionByCod (&Ins); + /* Get data of institution */ + Ins.InsCod = Ctr.InsCod; + Ins_GetDataOfInstitutionByCod (&Ins); - /* Add marker */ - Map_AddMarker (&Ctr.Coord); + /* Add marker */ + Map_AddMarker (&Ctr.Coord); - /* Add popup */ - Map_AddPopup (Ctr.ShrtName,Ins.ShrtName, - false); // Closed - } + /* Add popup */ + Map_AddPopup (Ctr.ShrtName,Ins.ShrtName, + false); // Closed + } - /* Free structure that stores the query result */ - DB_FreeMySQLResult (&mysql_res); + /* Free structure that stores the query result */ + DB_FreeMySQLResult (&mysql_res); HTM_SCRIPT_End (); } @@ -353,33 +328,33 @@ static void CtyCfg_MapImage (bool PrintView,bool PutLink) /***** Map image *****/ HTM_DIV_Begin ("class=\"DAT_SMALL CM\""); - if (PutLink) - HTM_A_Begin ("href=\"%s\" target=\"_blank\"", - Gbl.Hierarchy.Cty.WWW[Gbl.Prefs.Language]); - Cty_DrawCountryMap (&Gbl.Hierarchy.Cty,PrintView ? "COUNTRY_MAP_PRINT" : - "COUNTRY_MAP_SHOW"); - if (PutLink) - HTM_A_End (); + if (PutLink) + HTM_A_Begin ("href=\"%s\" target=\"_blank\"", + Gbl.Hierarchy.Cty.WWW[Gbl.Prefs.Language]); + Cty_DrawCountryMap (&Gbl.Hierarchy.Cty,PrintView ? "COUNTRY_MAP_PRINT" : + "COUNTRY_MAP_SHOW"); + if (PutLink) + HTM_A_End (); HTM_DIV_End (); /***** Map attribution *****/ if (!PrintView && Cty_CheckIfICanEditCountries ()) { HTM_DIV_Begin ("class=\"CM\""); - Frm_BeginForm (ActChgCtyMapAtt); - HTM_TEXTAREA_Begin ("id=\"AttributionArea\" name=\"Attribution\" rows=\"3\"" - " onchange=\"document.getElementById('%s').submit();return false;\"", - Gbl.Form.Id); - if (MapAttribution) - HTM_Txt (MapAttribution); - HTM_TEXTAREA_End (); - Frm_EndForm (); + Frm_BeginForm (ActChgCtyMapAtt); + HTM_TEXTAREA_Begin ("id=\"AttributionArea\" name=\"Attribution\" rows=\"3\"" + " onchange=\"document.getElementById('%s').submit();return false;\"", + Gbl.Form.Id); + if (MapAttribution) + HTM_Txt (MapAttribution); + HTM_TEXTAREA_End (); + Frm_EndForm (); HTM_DIV_End (); } else if (MapAttribution) { HTM_DIV_Begin ("class=\"ATTRIBUTION\""); - HTM_Txt (MapAttribution); + HTM_Txt (MapAttribution); HTM_DIV_End (); } @@ -398,27 +373,27 @@ static void CtyCfg_Platform (bool PrintView) /***** Institution *****/ HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("RT",NULL,Txt_Platform); + /* Label */ + Frm_LabelColumn ("RT",NULL,Txt_Platform); - /* Data */ - HTM_TD_Begin ("class=\"DAT LB\""); - if (!PrintView) - { - Frm_BeginFormGoTo (ActSeeSysInf); - HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (Cfg_PLATFORM_SHORT_NAME), - "BT_LINK LT DAT",NULL); - Hie_FreeGoToMsg (); - } - Ico_PutIcon ("swad64x64.png",Cfg_PLATFORM_FULL_NAME,"ICO20x20"); - HTM_NBSP (); - HTM_Txt (Cfg_PLATFORM_SHORT_NAME); - if (!PrintView) - { - HTM_BUTTON_End (); - Frm_EndForm (); - } - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("class=\"DAT LB\""); + if (!PrintView) + { + Frm_BeginFormGoTo (ActSeeSysInf); + HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (Cfg_PLATFORM_SHORT_NAME), + "BT_LINK LT DAT",NULL); + Hie_FreeGoToMsg (); + } + Ico_PutIcon ("swad64x64.png",Cfg_PLATFORM_FULL_NAME,"ICO20x20"); + HTM_NBSP (); + HTM_Txt (Cfg_PLATFORM_SHORT_NAME); + if (!PrintView) + { + HTM_BUTTON_End (); + Frm_EndForm (); + } + HTM_TD_End (); HTM_TR_End (); } @@ -434,18 +409,18 @@ static void CtyCfg_Name (bool PutLink) /***** Country name *****/ HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("RT",NULL,Txt_Country); + /* Label */ + Frm_LabelColumn ("RT",NULL,Txt_Country); - /* Data */ - HTM_TD_Begin ("class=\"DAT_N LB\""); - if (PutLink) - HTM_A_Begin ("href=\"%s\" target=\"_blank\" class=\"DAT_N\"", - Gbl.Hierarchy.Cty.WWW[Gbl.Prefs.Language]); - HTM_Txt (Gbl.Hierarchy.Cty.Name[Gbl.Prefs.Language]); - if (PutLink) - HTM_A_End (); - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("class=\"DAT_N LB\""); + if (PutLink) + HTM_A_Begin ("href=\"%s\" target=\"_blank\" class=\"DAT_N\"", + Gbl.Hierarchy.Cty.WWW[Gbl.Prefs.Language]); + HTM_Txt (Gbl.Hierarchy.Cty.Name[Gbl.Prefs.Language]); + if (PutLink) + HTM_A_End (); + HTM_TD_End (); HTM_TR_End (); } @@ -479,13 +454,13 @@ static void CtyCfg_NumUsrs (void) /***** Number of users *****/ HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("RT",NULL,Txt_Users_of_the_country); + /* Label */ + Frm_LabelColumn ("RT",NULL,Txt_Users_of_the_country); - /* Data */ - HTM_TD_Begin ("class=\"DAT LB\""); - HTM_Unsigned (Usr_GetCachedNumUsrsWhoClaimToBelongToCty (&Gbl.Hierarchy.Cty)); - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("class=\"DAT LB\""); + HTM_Unsigned (Usr_GetCachedNumUsrsWhoClaimToBelongToCty (&Gbl.Hierarchy.Cty)); + HTM_TD_End (); HTM_TR_End (); } @@ -502,21 +477,21 @@ static void CtyCfg_NumInss (void) /***** Number of institutions ******/ HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("RT",NULL,Txt_Institutions); + /* Label */ + Frm_LabelColumn ("RT",NULL,Txt_Institutions); - /* Data */ - HTM_TD_Begin ("class=\"LB\""); - Frm_BeginFormGoTo (ActSeeIns); - Cty_PutParamCtyCod (Gbl.Hierarchy.Cty.CtyCod); - HTM_BUTTON_SUBMIT_Begin (Str_BuildStringStr (Txt_Institutions_of_COUNTRY_X, - Gbl.Hierarchy.Cty.Name[Gbl.Prefs.Language]), - "BT_LINK DAT",NULL); - Str_FreeString (); - HTM_Unsigned (Ins_GetCachedNumInssInCty (Gbl.Hierarchy.Cty.CtyCod)); - HTM_BUTTON_End (); - Frm_EndForm (); - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("class=\"LB\""); + Frm_BeginFormGoTo (ActSeeIns); + Cty_PutParamCtyCod (Gbl.Hierarchy.Cty.CtyCod); + HTM_BUTTON_SUBMIT_Begin (Str_BuildStringStr (Txt_Institutions_of_COUNTRY_X, + Gbl.Hierarchy.Cty.Name[Gbl.Prefs.Language]), + "BT_LINK DAT",NULL); + Str_FreeString (); + HTM_Unsigned (Ins_GetCachedNumInssInCty (Gbl.Hierarchy.Cty.CtyCod)); + HTM_BUTTON_End (); + Frm_EndForm (); + HTM_TD_End (); HTM_TR_End (); } @@ -532,13 +507,13 @@ static void CtyCfg_NumDegs (void) /***** Number of degrees *****/ HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("RT",NULL,Txt_Degrees); + /* Label */ + Frm_LabelColumn ("RT",NULL,Txt_Degrees); - /* Data */ - HTM_TD_Begin ("class=\"DAT LB\""); - HTM_Unsigned (Deg_GetCachedNumDegsInCty (Gbl.Hierarchy.Cty.CtyCod)); - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("class=\"DAT LB\""); + HTM_Unsigned (Deg_GetCachedNumDegsInCty (Gbl.Hierarchy.Cty.CtyCod)); + HTM_TD_End (); HTM_TR_End (); } @@ -554,13 +529,13 @@ static void CtyCfg_NumCrss (void) /***** Number of courses *****/ HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("RT",NULL,Txt_Courses); + /* Label */ + Frm_LabelColumn ("RT",NULL,Txt_Courses); - /* Data */ - HTM_TD_Begin ("class=\"DAT LB\""); - HTM_Unsigned (Crs_GetCachedNumCrssInCty (Gbl.Hierarchy.Cty.CtyCod)); - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("class=\"DAT LB\""); + HTM_Unsigned (Crs_GetCachedNumCrssInCty (Gbl.Hierarchy.Cty.CtyCod)); + HTM_TD_End (); HTM_TR_End (); } @@ -578,12 +553,8 @@ static void CtyCfg_GetMapAttr (long CtyCod,char **MapAttribution) /***** Free possible former map attribution *****/ CtyCfg_FreeMapAttr (MapAttribution); - /***** Get photo attribution from database *****/ - if (DB_QuerySELECT (&mysql_res,"can not get photo attribution", - "SELECT MapAttribution" // row[0] - " FROM cty_countrs" - " WHERE CtyCod=%ld", - CtyCod)) + /***** Get map attribution from database *****/ + if (Cty_DB_GetMapAttr (&mysql_res,CtyCod)) { /* Get row */ row = mysql_fetch_row (mysql_res); @@ -628,13 +599,8 @@ void CtyCfg_ChangeCtyMapAttr (void) /* Get the new map attribution for the country */ Par_GetParToText ("Attribution",NewMapAttribution,Med_MAX_BYTES_ATTRIBUTION); - /***** Update the table changing old attribution by new attribution *****/ - DB_QueryUPDATE ("can not update the map attribution of a country", - "UPDATE cty_countrs" - " SET MapAttribution='%s'" - " WHERE CtyCod='%03ld'", - NewMapAttribution, - Gbl.Hierarchy.Cty.CtyCod); + /***** Change old attribution by new attribution in database *****/ + Cty_DB_UpdateCtyMapAttr (NewMapAttribution); /***** Show the country information again *****/ CtyCfg_ShowConfiguration (); diff --git a/swad_country_database.c b/swad_country_database.c new file mode 100644 index 00000000..099957da --- /dev/null +++ b/swad_country_database.c @@ -0,0 +1,257 @@ +// swad_country_database.h: countries operations with database + +/* + SWAD (Shared Workspace At a Distance), + is a web platform developed at the University of Granada (Spain), + and used to support university teaching. + + This file is part of SWAD core. + Copyright (C) 1999-2021 Antonio Cañas Vargas + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ +/*****************************************************************************/ +/********************************* Headers ***********************************/ +/*****************************************************************************/ + +#define _GNU_SOURCE // For asprintf +// #include // For boolean type +// #include // For NULL +#include // For asprintf +// #include // For free +// #include // For string functions + +#include "swad_country_database.h" +#include "swad_database.h" +#include "swad_error.h" +#include "swad_global.h" + +/*****************************************************************************/ +/************** External global variables from others modules ****************/ +/*****************************************************************************/ + +extern struct Globals Gbl; + +/*****************************************************************************/ +/***************************** Private constants *****************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/******************************* Private types *******************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/***************************** Private variables *****************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/***************************** Private prototypes ****************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/********** Get basic list of countries ordered by name of country ***********/ +/*****************************************************************************/ + +unsigned Cty_DB_GetBasicListOfCountries (MYSQL_RES **mysql_res) + { + extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES]; + + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get countries", + "SELECT CtyCod," // row[0] + "Name_%s" // row[1] + " FROM cty_countrs" + " ORDER BY Name_%s", + Lan_STR_LANG_ID[Gbl.Prefs.Language], + Lan_STR_LANG_ID[Gbl.Prefs.Language]); + } + +/*****************************************************************************/ +/******************* Get countries with pending institutions *****************/ +/*****************************************************************************/ + +unsigned Cty_DB_GetListOfCountriesWithPendingInss (MYSQL_RES **mysql_res) + { + extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES]; + + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get countries" + " with pending institutions", + "SELECT ins_instits.CtyCod," // row[0] + "COUNT(*)" // row[1] + " FROM ins_instits," + "cty_countrs" + " WHERE (ins_instits.Status & %u)<>0" + " AND ins_instits.CtyCod=cty_countrs.CtyCod" + " GROUP BY ins_instits.CtyCod" + " ORDER BY cty_countrs.Name_%s", + (unsigned) Ins_STATUS_BIT_PENDING, + Lan_STR_LANG_ID[Gbl.Prefs.Language]); + } + +/*****************************************************************************/ +/********** 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) + +unsigned Cty_DB_GetFullListOfCountries (MYSQL_RES **mysql_res) + { + 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; + static const char *OrderBySubQueryFmt[Cty_NUM_ORDERS] = + { + [Cty_ORDER_BY_COUNTRY ] = "Name_%s", + [Cty_ORDER_BY_NUM_USRS] = "NumUsrs DESC,Name_%s", + }; + unsigned NumCtys; + 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),"cty_countrs.Name_%s,",Lan_STR_LANG_ID[Lan]); + Str_Concat (SubQueryNam1,StrField,sizeof (SubQueryNam1) - 1); + snprintf (StrField,sizeof (StrField),"Name_%s,",Lan_STR_LANG_ID[Lan]); + Str_Concat (SubQueryNam2,StrField,sizeof (SubQueryNam2) - 1); + + snprintf (StrField,sizeof (StrField),"cty_countrs.WWW_%s,",Lan_STR_LANG_ID[Lan]); + Str_Concat (SubQueryWWW1,StrField,sizeof (SubQueryWWW1) - 1); + snprintf (StrField,sizeof (StrField),"WWW_%s,",Lan_STR_LANG_ID[Lan]); + Str_Concat (SubQueryWWW2,StrField,sizeof (SubQueryWWW2) - 1); + } + + /* Build order subquery */ + if (asprintf (&OrderBySubQuery,OrderBySubQueryFmt[Gbl.Hierarchy.Ctys.SelectedOrder], + Lan_STR_LANG_ID[Gbl.Prefs.Language]) < 0) + Err_NotEnoughMemoryExit (); + + /* Query database */ + NumCtys = (unsigned) + DB_QuerySELECT (mysql_res,"can not get countries", + "(SELECT cty_countrs.CtyCod," // row[0] + "cty_countrs.Alpha2," // row[1] + "%s" // row[...] + "%s" // row[...] + "COUNT(*) AS NumUsrs" // row[...] + " FROM cty_countrs," + "usr_data" + " WHERE cty_countrs.CtyCod=usr_data.CtyCod" + " GROUP BY cty_countrs.CtyCod)" + " UNION " + "(SELECT CtyCod," // row[0] + "Alpha2," // row[1] + "%s" // row[...] + "%s" // row[...] + "0 AS NumUsrs" // row[...] + " FROM cty_countrs" + " WHERE CtyCod NOT IN" + " (SELECT DISTINCT CtyCod" + " FROM usr_data))" + " ORDER BY %s", + SubQueryNam1,SubQueryWWW1, + SubQueryNam2,SubQueryWWW2,OrderBySubQuery); + + /* Free memory for subquery */ + free (OrderBySubQuery); + + return NumCtys; + } + +/*****************************************************************************/ +/*********** Get average coordinates of centers in current country ***********/ +/*****************************************************************************/ + +void Cty_DB_GetCoordAndZoom (struct Map_Coordinates *Coord,unsigned *Zoom) + { + char *Query; + + /***** Get average coordinates of centers of current country + with both coordinates set + (coordinates 0, 0 means not set ==> don't show map) *****/ + if (asprintf (&Query, + "SELECT AVG(ctr_centers.Latitude)," // row[0] + "AVG(ctr_centers.Longitude)," // row[1] + "GREATEST(MAX(ctr_centers.Latitude)-MIN(ctr_centers.Latitude)," + "MAX(ctr_centers.Longitude)-MIN(ctr_centers.Longitude))" // row[2] + " FROM ins_instits," + "ctr_centers" + " WHERE ins_instits.CtyCod=%ld" + " AND ins_instits.InsCod=ctr_centers.InsCod" + " AND ctr_centers.Latitude<>0" + " AND ctr_centers.Longitude<>0", + Gbl.Hierarchy.Cty.CtyCod) < 0) + Err_NotEnoughMemoryExit (); + Map_GetCoordAndZoom (Coord,Zoom,Query); + free (Query); + } + +/*****************************************************************************/ +/*********** Get centres which have coordinates in current country ***********/ +/*****************************************************************************/ + +unsigned Cty_DB_GetCtrsWithCoordsInCurrentCty (MYSQL_RES **mysql_res) + { + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get centers with coordinates", + "SELECT ctr_centers.CtrCod" + " FROM ins_instits," + "ctr_centers" + " WHERE ins_instits.CtyCod=%ld" + " AND ins_instits.InsCod=ctr_centers.InsCod" + " AND ctr_centers.Latitude<>0" + " AND ctr_centers.Longitude<>0", + Gbl.Hierarchy.Cty.CtyCod); + } + +/*****************************************************************************/ +/******************** Get map attribution from database **********************/ +/*****************************************************************************/ + +unsigned Cty_DB_GetMapAttr (MYSQL_RES **mysql_res,long CtyCod) + { + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get map attribution", + "SELECT MapAttribution" // row[0] + " FROM cty_countrs" + " WHERE CtyCod=%ld", + CtyCod); + } + +/*****************************************************************************/ +/*********** Update the attribution of the map of current country ************/ +/*****************************************************************************/ + +void Cty_DB_UpdateCtyMapAttr (const char NewMapAttribution[Med_MAX_BYTES_ATTRIBUTION + 1]) + { + DB_QueryUPDATE ("can not update the map attribution", + "UPDATE cty_countrs" + " SET MapAttribution='%s'" + " WHERE CtyCod='%03ld'", + NewMapAttribution, + Gbl.Hierarchy.Cty.CtyCod); + } + diff --git a/swad_country_database.h b/swad_country_database.h new file mode 100644 index 00000000..1bb6f3b0 --- /dev/null +++ b/swad_country_database.h @@ -0,0 +1,52 @@ +// swad_country_database.h: countries operations with database + +#ifndef _SWAD_CTY_DB +#define _SWAD_CTY_DB +/* + SWAD (Shared Workspace At a Distance in Spanish), + is a web platform developed at the University of Granada (Spain), + and used to support university teaching. + + This file is part of SWAD core. + Copyright (C) 1999-2021 Antonio Cañas Vargas + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ +/*****************************************************************************/ +/********************************* Headers ***********************************/ +/*****************************************************************************/ + +#include // To access MySQL databases + +#include "swad_map.h" +#include "swad_media.h" + +/*****************************************************************************/ +/************************** Public types and constants ***********************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/***************************** Public prototypes *****************************/ +/*****************************************************************************/ + +unsigned Cty_DB_GetBasicListOfCountries (MYSQL_RES **mysql_res); +unsigned Cty_DB_GetListOfCountriesWithPendingInss (MYSQL_RES **mysql_res); +unsigned Cty_DB_GetFullListOfCountries (MYSQL_RES **mysql_res); + +void Cty_DB_GetCoordAndZoom (struct Map_Coordinates *Coord,unsigned *Zoom); +unsigned Cty_DB_GetCtrsWithCoordsInCurrentCty (MYSQL_RES **mysql_res); +unsigned Cty_DB_GetMapAttr (MYSQL_RES **mysql_res,long CtyCod); +void Cty_DB_UpdateCtyMapAttr (const char NewMapAttribution[Med_MAX_BYTES_ATTRIBUTION + 1]); + +#endif diff --git a/swad_hierarchy.c b/swad_hierarchy.c index c590f6f5..c90a0010 100644 --- a/swad_hierarchy.c +++ b/swad_hierarchy.c @@ -93,87 +93,87 @@ void Hie_WriteMenuHierarchy (void) /***** Begin table *****/ HTM_TABLE_BeginCenterPadding (2); - /***** Write a 1st selector - with all the countries *****/ - HTM_TR_Begin (NULL); - - /* Label */ - Frm_LabelColumn ("RT","cty",Txt_Country); - - /* Data */ - HTM_TD_Begin ("class=\"LT\""); - Cty_WriteSelectorOfCountry (); - HTM_TD_End (); - - HTM_TR_End (); - - if (Gbl.Hierarchy.Cty.CtyCod > 0) - { - /***** Write a 2nd selector - with the institutions of selected country *****/ + /***** Write a 1st selector + with all the countries *****/ HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("RT","ins",Txt_Institution); + /* Label */ + Frm_LabelColumn ("RT","cty",Txt_Country); - /* Data */ - HTM_TD_Begin ("class=\"LT\""); - Ins_WriteSelectorOfInstitution (); - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("class=\"LT\""); + Cty_WriteSelectorOfCountry (); + HTM_TD_End (); HTM_TR_End (); - if (Gbl.Hierarchy.Ins.InsCod > 0) - { - /***** Write a 3rd selector - with all the centers of selected institution *****/ - HTM_TR_Begin (NULL); + if (Gbl.Hierarchy.Cty.CtyCod > 0) + { + /***** Write a 2nd selector + with the institutions of selected country *****/ + HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("RT","ctr",Txt_Center); + /* Label */ + Frm_LabelColumn ("RT","ins",Txt_Institution); - /* Data */ - HTM_TD_Begin ("class=\"LT\""); - Ctr_WriteSelectorOfCenter (); - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("class=\"LT\""); + Ins_WriteSelectorOfInstitution (); + HTM_TD_End (); - HTM_TR_End (); + HTM_TR_End (); - if (Gbl.Hierarchy.Ctr.CtrCod > 0) - { - /***** Write a 4th selector - with all the degrees of selected center *****/ - HTM_TR_Begin (NULL); - - /* Label */ - Frm_LabelColumn ("RT","deg",Txt_Degree); - - /* Data */ - HTM_TD_Begin ("class=\"LT\""); - Deg_WriteSelectorOfDegree (); - HTM_TD_End (); - - HTM_TR_End (); - - if (Gbl.Hierarchy.Deg.DegCod > 0) - { - /***** Write a 5th selector - with all the courses of selected degree *****/ - HTM_TR_Begin (NULL); + if (Gbl.Hierarchy.Ins.InsCod > 0) + { + /***** Write a 3rd selector + with all the centers of selected institution *****/ + HTM_TR_Begin (NULL); /* Label */ - Frm_LabelColumn ("RT","crs",Txt_Course); + Frm_LabelColumn ("RT","ctr",Txt_Center); - /* Data */ + /* Data */ HTM_TD_Begin ("class=\"LT\""); - Crs_WriteSelectorOfCourse (); + Ctr_WriteSelectorOfCenter (); HTM_TD_End (); + HTM_TR_End (); + + if (Gbl.Hierarchy.Ctr.CtrCod > 0) + { + /***** Write a 4th selector + with all the degrees of selected center *****/ + HTM_TR_Begin (NULL); + + /* Label */ + Frm_LabelColumn ("RT","deg",Txt_Degree); + + /* Data */ + HTM_TD_Begin ("class=\"LT\""); + Deg_WriteSelectorOfDegree (); + HTM_TD_End (); + HTM_TR_End (); + + if (Gbl.Hierarchy.Deg.DegCod > 0) + { + /***** Write a 5th selector + with all the courses of selected degree *****/ + HTM_TR_Begin (NULL); + + /* Label */ + Frm_LabelColumn ("RT","crs",Txt_Course); + + /* Data */ + HTM_TD_Begin ("class=\"LT\""); + Crs_WriteSelectorOfCourse (); + HTM_TD_End (); + + HTM_TR_End (); + } } - } - } - } + } + } /***** End table *****/ HTM_TABLE_End (); diff --git a/swad_institution_config.c b/swad_institution_config.c index 455df6d8..e1d756cf 100644 --- a/swad_institution_config.c +++ b/swad_institution_config.c @@ -70,7 +70,7 @@ extern struct Globals Gbl; static void InsCfg_Configuration (bool PrintView); static void InsCfg_PutIconsToPrintAndUpload (__attribute__((unused)) void *Args); static void InsCfg_Title (bool PutLink); -static void InsCfg_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom); +static void InsCfg_GetCoordAndZoom (struct Map_Coordinates *Coord,unsigned *Zoom); static void InsCfg_Map (void); static void InsCfg_Country (bool PrintView,bool PutForm); static void InsCfg_FullName (bool PutForm); @@ -248,7 +248,7 @@ static void InsCfg_Title (bool PutLink) /********* Get average coordinates of centers in current institution *********/ /*****************************************************************************/ -static void InsCfg_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom) +static void InsCfg_GetCoordAndZoom (struct Map_Coordinates *Coord,unsigned *Zoom) { char *Query; @@ -279,7 +279,7 @@ static void InsCfg_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom) static void InsCfg_Map (void) { MYSQL_RES *mysql_res; - struct Coordinates InsAvgCoord; + struct Map_Coordinates InsAvgCoord; unsigned Zoom; unsigned NumCtrs; unsigned NumCtr; @@ -349,60 +349,59 @@ static void InsCfg_Country (bool PrintView,bool PutForm) extern const char *Txt_Country; unsigned NumCty; + /***** Get list of countries *****/ + Cty_GetBasicListOfCountries (); + /***** Country *****/ HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("RT",PutForm ? "OthCtyCod" : - NULL, - Txt_Country); + /* Label */ + Frm_LabelColumn ("RT",PutForm ? "OthCtyCod" : + NULL, + Txt_Country); - /* Data */ - HTM_TD_Begin ("class=\"DAT LB\""); - if (PutForm) - { - /* Get list of countries */ - Cty_GetBasicListOfCountries (); - - /* Put form to select country */ - Frm_BeginForm (ActChgInsCtyCfg); - HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, - "id=\"OthCtyCod\" name=\"OthCtyCod\"" - " class=\"INPUT_SHORT_NAME\""); - for (NumCty = 0; - NumCty < Gbl.Hierarchy.Ctys.Num; - NumCty++) - HTM_OPTION (HTM_Type_LONG,&Gbl.Hierarchy.Ctys.Lst[NumCty].CtyCod, - Gbl.Hierarchy.Ctys.Lst[NumCty].CtyCod == Gbl.Hierarchy.Cty.CtyCod,false, - "%s",Gbl.Hierarchy.Ctys.Lst[NumCty].Name[Gbl.Prefs.Language]); - HTM_SELECT_End (); - Frm_EndForm (); - - /* Free list of countries */ - Cty_FreeListCountries (); - } - else // I can not move institution to another country - { - if (!PrintView) - { - Frm_BeginFormGoTo (ActSeeCtyInf); - Cty_PutParamCtyCod (Gbl.Hierarchy.Cty.CtyCod); - HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (Gbl.Hierarchy.Cty.Name[Gbl.Prefs.Language]), - "BT_LINK LT DAT",NULL); - Hie_FreeGoToMsg (); - } - Cty_DrawCountryMap (&Gbl.Hierarchy.Cty,"COUNTRY_MAP_TINY"); - HTM_NBSP (); - HTM_Txt (Gbl.Hierarchy.Cty.Name[Gbl.Prefs.Language]); - if (!PrintView) - { - HTM_BUTTON_End (); - Frm_EndForm (); - } - } - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("class=\"DAT LB\""); + if (PutForm) + { + /* Put form to select country */ + Frm_BeginForm (ActChgInsCtyCfg); + HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, + "id=\"OthCtyCod\" name=\"OthCtyCod\"" + " class=\"INPUT_SHORT_NAME\""); + for (NumCty = 0; + NumCty < Gbl.Hierarchy.Ctys.Num; + NumCty++) + HTM_OPTION (HTM_Type_LONG,&Gbl.Hierarchy.Ctys.Lst[NumCty].CtyCod, + Gbl.Hierarchy.Ctys.Lst[NumCty].CtyCod == Gbl.Hierarchy.Cty.CtyCod,false, + "%s",Gbl.Hierarchy.Ctys.Lst[NumCty].Name[Gbl.Prefs.Language]); + HTM_SELECT_End (); + Frm_EndForm (); + } + else // I can not move institution to another country + { + if (!PrintView) + { + Frm_BeginFormGoTo (ActSeeCtyInf); + Cty_PutParamCtyCod (Gbl.Hierarchy.Cty.CtyCod); + HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (Gbl.Hierarchy.Cty.Name[Gbl.Prefs.Language]), + "BT_LINK LT DAT",NULL); + Hie_FreeGoToMsg (); + } + Cty_DrawCountryMap (&Gbl.Hierarchy.Cty,"COUNTRY_MAP_TINY"); + HTM_NBSP (); + HTM_Txt (Gbl.Hierarchy.Cty.Name[Gbl.Prefs.Language]); + if (!PrintView) + { + HTM_BUTTON_End (); + Frm_EndForm (); + } + } + HTM_TD_End (); HTM_TR_End (); + + // Do not free list of countries here, because it can be reused } /*****************************************************************************/ diff --git a/swad_map.c b/swad_map.c index aefe0347..6d5f3a98 100644 --- a/swad_map.c +++ b/swad_map.c @@ -89,7 +89,7 @@ void Map_LeafletScript (void) /*****************************************************************************/ void Map_CreateMap (const char *ContainerId, - const struct Coordinates *Coord,unsigned Zoom) + const struct Map_Coordinates *Coord,unsigned Zoom) { /* Let's create a map with pretty Mapbox Streets tiles */ Str_SetDecimalPointToUS (); // To write the decimal point as a dot @@ -136,7 +136,7 @@ void Map_AddTileLayer (void) /************************** Add a marker to our map **************************/ /*****************************************************************************/ -void Map_AddMarker (const struct Coordinates *Coord) +void Map_AddMarker (const struct Map_Coordinates *Coord) { Str_SetDecimalPointToUS (); // To write the decimal point as a dot HTM_TxtF ("\t" @@ -167,7 +167,7 @@ void Map_AddPopup (const char *Title,const char *Subtitle,bool Open) /********* Get average coordinates of centers in current institution *********/ /*****************************************************************************/ -void Map_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom, +void Map_GetCoordAndZoom (struct Map_Coordinates *Coord,unsigned *Zoom, const char *Query) { MYSQL_RES *mysql_res; diff --git a/swad_map.h b/swad_map.h index c275232c..4ebded42 100644 --- a/swad_map.h +++ b/swad_map.h @@ -27,11 +27,13 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ +#include // For boolean type + /*****************************************************************************/ /************************** Public types and constants ***********************/ /*****************************************************************************/ -struct Coordinates +struct Map_Coordinates { double Latitude; double Longitude; @@ -45,11 +47,11 @@ struct Coordinates void Map_LeafletCSS (void); void Map_LeafletScript (void); void Map_CreateMap (const char *ContainerId, - const struct Coordinates *Coord,unsigned Zoom); + const struct Map_Coordinates *Coord,unsigned Zoom); void Map_AddTileLayer (void); -void Map_AddMarker (const struct Coordinates *Coord); +void Map_AddMarker (const struct Map_Coordinates *Coord); void Map_AddPopup (const char *Title,const char *Subtitle,bool Open); -void Map_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom, +void Map_GetCoordAndZoom (struct Map_Coordinates *Coord,unsigned *Zoom, const char *Query); double Map_GetLatitudeFromStr (char *Str); double Map_GetLongitudeFromStr (char *Str); diff --git a/swad_media.h b/swad_media.h index f7b1a98f..00a9527d 100644 --- a/swad_media.h +++ b/swad_media.h @@ -30,6 +30,7 @@ #include // To access MySQL databases #include "swad_cryptography.h" +#include "swad_string.h" /*****************************************************************************/ /***************************** Public constants ******************************/ diff --git a/swad_record.c b/swad_record.c index 7a56c23e..0ffc9198 100644 --- a/swad_record.c +++ b/swad_record.c @@ -3278,41 +3278,42 @@ static void Rec_ShowCountry (struct UsrData *UsrDat,bool PutForm) unsigned NumCty; /***** If list of countries is empty, try to get it *****/ - if (!Gbl.Hierarchy.Ctys.Num) - Cty_GetBasicListOfCountries (); + Cty_GetBasicListOfCountries (); /***** Selector of country *****/ HTM_TR_Begin (NULL); - /* Label */ - if (PutForm) - { - Frm_LabelColumn ("REC_C1_BOT RM","OthCtyCod", - Str_BuildStringStr ("%s*",Txt_Country)); - Str_FreeString (); - } - else - Frm_LabelColumn ("REC_C1_BOT RM",NULL,Txt_Country); + /* Label */ + if (PutForm) + { + Frm_LabelColumn ("REC_C1_BOT RM","OthCtyCod", + Str_BuildStringStr ("%s*",Txt_Country)); + Str_FreeString (); + } + else + Frm_LabelColumn ("REC_C1_BOT RM",NULL,Txt_Country); - /* Data */ - HTM_TD_Begin ("colspan=\"2\" class=\"REC_C2_BOT LM\""); - HTM_SELECT_Begin (HTM_DONT_SUBMIT_ON_CHANGE, - "id=\"OthCtyCod\" name=\"OthCtyCod\"" - " class=\"REC_C2_BOT_INPUT\" required=\"required\""); - HTM_OPTION (HTM_Type_STRING,"",false,false, - "%s",Txt_Country); - HTM_OPTION (HTM_Type_STRING,"0",UsrDat->CtyCod == 0,false, - "%s",Txt_Another_country); - for (NumCty = 0; - NumCty < Gbl.Hierarchy.Ctys.Num; - NumCty++) - HTM_OPTION (HTM_Type_LONG,&Gbl.Hierarchy.Ctys.Lst[NumCty].CtyCod, - Gbl.Hierarchy.Ctys.Lst[NumCty].CtyCod == UsrDat->CtyCod,false, - "%s",Gbl.Hierarchy.Ctys.Lst[NumCty].Name[Gbl.Prefs.Language]); - HTM_SELECT_End (); - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("colspan=\"2\" class=\"REC_C2_BOT LM\""); + HTM_SELECT_Begin (HTM_DONT_SUBMIT_ON_CHANGE, + "id=\"OthCtyCod\" name=\"OthCtyCod\"" + " class=\"REC_C2_BOT_INPUT\" required=\"required\""); + HTM_OPTION (HTM_Type_STRING,"",false,false, + "%s",Txt_Country); + HTM_OPTION (HTM_Type_STRING,"0",UsrDat->CtyCod == 0,false, + "%s",Txt_Another_country); + for (NumCty = 0; + NumCty < Gbl.Hierarchy.Ctys.Num; + NumCty++) + HTM_OPTION (HTM_Type_LONG,&Gbl.Hierarchy.Ctys.Lst[NumCty].CtyCod, + Gbl.Hierarchy.Ctys.Lst[NumCty].CtyCod == UsrDat->CtyCod,false, + "%s",Gbl.Hierarchy.Ctys.Lst[NumCty].Name[Gbl.Prefs.Language]); + HTM_SELECT_End (); + HTM_TD_End (); HTM_TR_End (); + + // Do not free here list of countries, because it can be reused } /*****************************************************************************/ @@ -3476,22 +3477,22 @@ static void Rec_ShowInstitution (struct Ins_Instit *Ins,bool ShowData) /***** Institution *****/ HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("REC_C1_BOT RT",NULL,Txt_Institution); + /* Label */ + Frm_LabelColumn ("REC_C1_BOT RT",NULL,Txt_Institution); - /* Data */ - HTM_TD_Begin ("class=\"REC_C2_BOT DAT_N LT\""); - if (ShowData) - if (Ins->InsCod > 0) - { - if (Ins->WWW[0]) - HTM_A_Begin ("href=\"%s\" target=\"_blank\" class=\"DAT_N\"", - Ins->WWW); - HTM_Txt (Ins->FullName); - if (Ins->WWW[0]) - HTM_A_End (); - } - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("class=\"REC_C2_BOT DAT_N LT\""); + if (ShowData) + if (Ins->InsCod > 0) + { + if (Ins->WWW[0]) + HTM_A_Begin ("href=\"%s\" target=\"_blank\" class=\"DAT_N\"", + Ins->WWW); + HTM_Txt (Ins->FullName); + if (Ins->WWW[0]) + HTM_A_End (); + } + HTM_TD_End (); HTM_TR_End (); } @@ -3815,26 +3816,28 @@ void Rec_ShowMySharedRecordAndMore (void) /***** Begin container *****/ HTM_DIV_Begin ("class=\"REC_USR\""); - /***** Left part *****/ - HTM_DIV_Begin ("class=\"REC_LEFT\""); + /***** Left part *****/ + /* Begin container for left part */ + HTM_DIV_Begin ("class=\"REC_LEFT\""); - /* My shared record card */ - Rec_ShowSharedUsrRecord (Rec_SHA_MY_RECORD_FORM,&Gbl.Usrs.Me.UsrDat,NULL); + /* My shared record card */ + Rec_ShowSharedUsrRecord (Rec_SHA_MY_RECORD_FORM,&Gbl.Usrs.Me.UsrDat,NULL); - HTM_DIV_End (); + /* End container for left part */ + HTM_DIV_End (); - /***** Right part *****/ - /* Begin container for right part */ - HTM_DIV_Begin ("class=\"REC_RIGHT\""); + /***** Right part *****/ + /* Begin container for right part */ + HTM_DIV_Begin ("class=\"REC_RIGHT\""); - /* My institution, center and department */ - Rec_ShowFormMyInsCtrDpt (IAmATeacher); + /* My institution, center and department */ + Rec_ShowFormMyInsCtrDpt (IAmATeacher); - /* My webs / social networks */ - Net_ShowFormMyWebsAndSocialNets (); + /* My webs / social networks */ + Net_ShowFormMyWebsAndSocialNets (); - /* End container for right part */ - HTM_DIV_End (); + /* End container for right part */ + HTM_DIV_End (); /***** End container *****/ HTM_DIV_End (); @@ -3865,194 +3868,196 @@ static void Rec_ShowFormMyInsCtrDpt (bool IAmATeacher) unsigned NumCtr; char StrRecordWidth[Cns_MAX_DECIMAL_DIGITS_UINT + 1]; + /***** Get list of countries *****/ + Cty_GetBasicListOfCountries (); + /***** Begin section *****/ HTM_SECTION_Begin (Rec_MY_INS_CTR_DPT_ID); - /***** Begin box and table *****/ - sprintf (StrRecordWidth,"%upx",Rec_RECORD_WIDTH); - Box_BoxTableBegin (StrRecordWidth, - IAmATeacher ? Txt_Institution_center_and_department : - Txt_Institution, - NULL,NULL, - Hlp_PROFILE_Institution,Box_NOT_CLOSABLE,2); + /***** Begin box and table *****/ + sprintf (StrRecordWidth,"%upx",Rec_RECORD_WIDTH); + Box_BoxTableBegin (StrRecordWidth, + IAmATeacher ? Txt_Institution_center_and_department : + Txt_Institution, + NULL,NULL, + Hlp_PROFILE_Institution,Box_NOT_CLOSABLE,2); - /***** Country *****/ - HTM_TR_Begin (NULL); + /***** Country *****/ + HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("REC_C1_BOT RM","InsCtyCod", - Str_BuildStringStr ("%s*",Txt_Country)); - Str_FreeString (); + /* Label */ + Frm_LabelColumn ("REC_C1_BOT RM","InsCtyCod", + Str_BuildStringStr ("%s*",Txt_Country)); + Str_FreeString (); - /* Data */ - HTM_TD_Begin ("class=\"REC_C2_BOT LM\""); + /* Data */ + HTM_TD_Begin ("class=\"REC_C2_BOT LM\""); - /* If list of countries is empty, try to get it */ - if (!Gbl.Hierarchy.Ctys.Num) - Cty_GetBasicListOfCountries (); + /* Begin form to select the country of my institution */ + Frm_StartFormAnchor (ActChgCtyMyIns,Rec_MY_INS_CTR_DPT_ID); + HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, + "id=\"InsCtyCod\" name=\"OthCtyCod\"" + " class=\"REC_C2_BOT_INPUT\""); + HTM_OPTION (HTM_Type_STRING,"-1", + Gbl.Usrs.Me.UsrDat.InsCtyCod <= 0,true, + NULL); + for (NumCty = 0; + NumCty < Gbl.Hierarchy.Ctys.Num; + NumCty++) + HTM_OPTION (HTM_Type_LONG,&Gbl.Hierarchy.Ctys.Lst[NumCty].CtyCod, + Gbl.Hierarchy.Ctys.Lst[NumCty].CtyCod == Gbl.Usrs.Me.UsrDat.InsCtyCod,false, + "%s",Gbl.Hierarchy.Ctys.Lst[NumCty].Name[Gbl.Prefs.Language]); + HTM_SELECT_End (); + Frm_EndForm (); - /* Begin form to select the country of my institution */ - Frm_StartFormAnchor (ActChgCtyMyIns,Rec_MY_INS_CTR_DPT_ID); - HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, - "id=\"InsCtyCod\" name=\"OthCtyCod\"" - " class=\"REC_C2_BOT_INPUT\""); - HTM_OPTION (HTM_Type_STRING,"-1", - Gbl.Usrs.Me.UsrDat.InsCtyCod <= 0,true, - NULL); - for (NumCty = 0; - NumCty < Gbl.Hierarchy.Ctys.Num; - NumCty++) - HTM_OPTION (HTM_Type_LONG,&Gbl.Hierarchy.Ctys.Lst[NumCty].CtyCod, - Gbl.Hierarchy.Ctys.Lst[NumCty].CtyCod == Gbl.Usrs.Me.UsrDat.InsCtyCod,false, - "%s",Gbl.Hierarchy.Ctys.Lst[NumCty].Name[Gbl.Prefs.Language]); - HTM_SELECT_End (); - Frm_EndForm (); - HTM_TD_End (); + HTM_TD_End (); - HTM_TR_End (); + HTM_TR_End (); - /***** Institution *****/ - HTM_TR_Begin (NULL); + /***** Institution *****/ + HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("REC_C1_BOT RM","OthInsCod", - Str_BuildStringStr ("%s*",Txt_Institution)); - Str_FreeString (); + /* Label */ + Frm_LabelColumn ("REC_C1_BOT RM","OthInsCod", + Str_BuildStringStr ("%s*",Txt_Institution)); + Str_FreeString (); - /* Data */ - HTM_TD_Begin ("class=\"REC_C2_BOT LM\""); + /* Data */ + HTM_TD_Begin ("class=\"REC_C2_BOT LM\""); - /* Get list of institutions in this country */ - Ins_FreeListInstitutions (); - if (Gbl.Usrs.Me.UsrDat.InsCtyCod > 0) - Ins_GetBasicListOfInstitutions (Gbl.Usrs.Me.UsrDat.InsCtyCod); + /* Get list of institutions in this country */ + Ins_FreeListInstitutions (); + if (Gbl.Usrs.Me.UsrDat.InsCtyCod > 0) + Ins_GetBasicListOfInstitutions (Gbl.Usrs.Me.UsrDat.InsCtyCod); - /* Begin form to select institution */ - Frm_StartFormAnchor (ActChgMyIns,Rec_MY_INS_CTR_DPT_ID); - HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, - "id=\"OthInsCod\" name=\"OthInsCod\"" - " class=\"REC_C2_BOT_INPUT\""); - HTM_OPTION (HTM_Type_STRING,"-1", - Gbl.Usrs.Me.UsrDat.InsCod < 0,true, - NULL); - HTM_OPTION (HTM_Type_STRING,"0", - Gbl.Usrs.Me.UsrDat.InsCod == 0,false, - "%s",Txt_Another_institution); - for (NumIns = 0; - NumIns < Gbl.Hierarchy.Inss.Num; - NumIns++) - HTM_OPTION (HTM_Type_LONG,&Gbl.Hierarchy.Inss.Lst[NumIns].InsCod, - Gbl.Hierarchy.Inss.Lst[NumIns].InsCod == Gbl.Usrs.Me.UsrDat.InsCod,false, - "%s",Gbl.Hierarchy.Inss.Lst[NumIns].FullName); - HTM_SELECT_End (); - Frm_EndForm (); - HTM_TD_End (); + /* Begin form to select institution */ + Frm_StartFormAnchor (ActChgMyIns,Rec_MY_INS_CTR_DPT_ID); + HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, + "id=\"OthInsCod\" name=\"OthInsCod\"" + " class=\"REC_C2_BOT_INPUT\""); + HTM_OPTION (HTM_Type_STRING,"-1", + Gbl.Usrs.Me.UsrDat.InsCod < 0,true, + NULL); + HTM_OPTION (HTM_Type_STRING,"0", + Gbl.Usrs.Me.UsrDat.InsCod == 0,false, + "%s",Txt_Another_institution); + for (NumIns = 0; + NumIns < Gbl.Hierarchy.Inss.Num; + NumIns++) + HTM_OPTION (HTM_Type_LONG,&Gbl.Hierarchy.Inss.Lst[NumIns].InsCod, + Gbl.Hierarchy.Inss.Lst[NumIns].InsCod == Gbl.Usrs.Me.UsrDat.InsCod,false, + "%s",Gbl.Hierarchy.Inss.Lst[NumIns].FullName); + HTM_SELECT_End (); + Frm_EndForm (); + HTM_TD_End (); - HTM_TR_End (); + HTM_TR_End (); - if (IAmATeacher) - { - /***** Center *****/ - HTM_TR_Begin (NULL); + if (IAmATeacher) + { + /***** Center *****/ + HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("REC_C1_BOT RM","OthCtrCod", - Str_BuildStringStr ("%s*",Txt_Center)); - Str_FreeString (); + /* Label */ + Frm_LabelColumn ("REC_C1_BOT RM","OthCtrCod", + Str_BuildStringStr ("%s*",Txt_Center)); + Str_FreeString (); - /* Data */ - HTM_TD_Begin ("class=\"REC_C2_BOT LM\""); + /* Data */ + HTM_TD_Begin ("class=\"REC_C2_BOT LM\""); - /* Get list of centers in this institution */ - Ctr_FreeListCenters (); - if (Gbl.Usrs.Me.UsrDat.InsCod > 0) - Ctr_GetBasicListOfCenters (Gbl.Usrs.Me.UsrDat.InsCod); + /* Get list of centers in this institution */ + Ctr_FreeListCenters (); + if (Gbl.Usrs.Me.UsrDat.InsCod > 0) + Ctr_GetBasicListOfCenters (Gbl.Usrs.Me.UsrDat.InsCod); - /* Begin form to select center */ - Frm_StartFormAnchor (ActChgMyCtr,Rec_MY_INS_CTR_DPT_ID); - HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, - "id=\"OthCtrCod\" name=\"OthCtrCod\"" - " class=\"REC_C2_BOT_INPUT\""); - HTM_OPTION (HTM_Type_STRING,"-1", - Gbl.Usrs.Me.UsrDat.Tch.CtrCod < 0,true, - NULL); - HTM_OPTION (HTM_Type_STRING,"0", - Gbl.Usrs.Me.UsrDat.Tch.CtrCod == 0,false, - Txt_Another_center); - for (NumCtr = 0; - NumCtr < Gbl.Hierarchy.Ctrs.Num; - NumCtr++) - HTM_OPTION (HTM_Type_LONG,&Gbl.Hierarchy.Ctrs.Lst[NumCtr].CtrCod, - Gbl.Hierarchy.Ctrs.Lst[NumCtr].CtrCod == Gbl.Usrs.Me.UsrDat.Tch.CtrCod,false, - Gbl.Hierarchy.Ctrs.Lst[NumCtr].FullName); - HTM_SELECT_End (); - Frm_EndForm (); - HTM_TD_End (); + /* Begin form to select center */ + Frm_StartFormAnchor (ActChgMyCtr,Rec_MY_INS_CTR_DPT_ID); + HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, + "id=\"OthCtrCod\" name=\"OthCtrCod\"" + " class=\"REC_C2_BOT_INPUT\""); + HTM_OPTION (HTM_Type_STRING,"-1", + Gbl.Usrs.Me.UsrDat.Tch.CtrCod < 0,true, + NULL); + HTM_OPTION (HTM_Type_STRING,"0", + Gbl.Usrs.Me.UsrDat.Tch.CtrCod == 0,false, + Txt_Another_center); + for (NumCtr = 0; + NumCtr < Gbl.Hierarchy.Ctrs.Num; + NumCtr++) + HTM_OPTION (HTM_Type_LONG,&Gbl.Hierarchy.Ctrs.Lst[NumCtr].CtrCod, + Gbl.Hierarchy.Ctrs.Lst[NumCtr].CtrCod == Gbl.Usrs.Me.UsrDat.Tch.CtrCod,false, + Gbl.Hierarchy.Ctrs.Lst[NumCtr].FullName); + HTM_SELECT_End (); + Frm_EndForm (); + HTM_TD_End (); - HTM_TR_End (); + HTM_TR_End (); - /***** Department *****/ - HTM_TR_Begin (NULL); + /***** Department *****/ + HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("REC_C1_BOT RM",Dpt_PARAM_DPT_COD_NAME, - Str_BuildStringStr ("%s*",Txt_Department)); - Str_FreeString (); + /* Label */ + Frm_LabelColumn ("REC_C1_BOT RM",Dpt_PARAM_DPT_COD_NAME, + Str_BuildStringStr ("%s*",Txt_Department)); + Str_FreeString (); - /* Data */ - HTM_TD_Begin ("class=\"REC_C2_BOT LM\""); - Frm_StartFormAnchor (ActChgMyDpt,Rec_MY_INS_CTR_DPT_ID); - Dpt_WriteSelectorDepartment (Gbl.Usrs.Me.UsrDat.InsCod, // Departments in my institution - Gbl.Usrs.Me.UsrDat.Tch.DptCod, // Selected department - "REC_C2_BOT_INPUT", // Selector class - -1L, // First option - "", // Text when no department selected - true); // Submit on change - Frm_EndForm (); - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("class=\"REC_C2_BOT LM\""); + Frm_StartFormAnchor (ActChgMyDpt,Rec_MY_INS_CTR_DPT_ID); + Dpt_WriteSelectorDepartment (Gbl.Usrs.Me.UsrDat.InsCod, // Departments in my institution + Gbl.Usrs.Me.UsrDat.Tch.DptCod, // Selected department + "REC_C2_BOT_INPUT", // Selector class + -1L, // First option + "", // Text when no department selected + true); // Submit on change + Frm_EndForm (); + HTM_TD_End (); - HTM_TR_End (); + HTM_TR_End (); - /***** Office *****/ - HTM_TR_Begin (NULL); + /***** Office *****/ + HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("REC_C1_BOT RM","Office",Txt_Office); + /* Label */ + Frm_LabelColumn ("REC_C1_BOT RM","Office",Txt_Office); - /* Data */ - HTM_TD_Begin ("class=\"REC_C2_BOT LM\""); - Frm_StartFormAnchor (ActChgMyOff,Rec_MY_INS_CTR_DPT_ID); - HTM_INPUT_TEXT ("Office",Usr_MAX_CHARS_ADDRESS,Gbl.Usrs.Me.UsrDat.Tch.Office, - HTM_SUBMIT_ON_CHANGE, - "id=\"Office\" class=\"REC_C2_BOT_INPUT\""); - Frm_EndForm (); - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("class=\"REC_C2_BOT LM\""); + Frm_StartFormAnchor (ActChgMyOff,Rec_MY_INS_CTR_DPT_ID); + HTM_INPUT_TEXT ("Office",Usr_MAX_CHARS_ADDRESS,Gbl.Usrs.Me.UsrDat.Tch.Office, + HTM_SUBMIT_ON_CHANGE, + "id=\"Office\" class=\"REC_C2_BOT_INPUT\""); + Frm_EndForm (); + HTM_TD_End (); - HTM_TR_End (); + HTM_TR_End (); - /***** Office phone *****/ - HTM_TR_Begin (NULL); + /***** Office phone *****/ + HTM_TR_Begin (NULL); - /* Label */ - Frm_LabelColumn ("REC_C1_BOT RM","OfficePhone",Txt_Phone); + /* Label */ + Frm_LabelColumn ("REC_C1_BOT RM","OfficePhone",Txt_Phone); - /* Data */ - HTM_TD_Begin ("class=\"REC_C2_BOT LM\""); - Frm_StartFormAnchor (ActChgMyOffPho,Rec_MY_INS_CTR_DPT_ID); - HTM_INPUT_TEL ("OfficePhone",Gbl.Usrs.Me.UsrDat.Tch.OfficePhone, - HTM_SUBMIT_ON_CHANGE, - "id=\"OfficePhone\" class=\"REC_C2_BOT_INPUT\""); - Frm_EndForm (); - HTM_TD_End (); + /* Data */ + HTM_TD_Begin ("class=\"REC_C2_BOT LM\""); + Frm_StartFormAnchor (ActChgMyOffPho,Rec_MY_INS_CTR_DPT_ID); + HTM_INPUT_TEL ("OfficePhone",Gbl.Usrs.Me.UsrDat.Tch.OfficePhone, + HTM_SUBMIT_ON_CHANGE, + "id=\"OfficePhone\" class=\"REC_C2_BOT_INPUT\""); + Frm_EndForm (); + HTM_TD_End (); - HTM_TR_End (); - } + HTM_TR_End (); + } - /***** End table and box *****/ - Box_BoxTableEnd (); + /***** End table and box *****/ + Box_BoxTableEnd (); /***** End section *****/ HTM_SECTION_End (); + + // Do not free list of countries here, because it can be reused } /*****************************************************************************/ diff --git a/swad_system_config.c b/swad_system_config.c index 27f5b6ef..3fa7926c 100644 --- a/swad_system_config.c +++ b/swad_system_config.c @@ -68,7 +68,7 @@ static void SysCfg_Configuration (bool PrintView); static void SysCfg_PutIconToPrint (__attribute__((unused)) void *Args); -static void SysCfg_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom); +static void SysCfg_GetCoordAndZoom (struct Map_Coordinates *Coord,unsigned *Zoom); static void SysCfg_Map (void); static void SysCfg_Platform (void); static void SysCfg_Shortcut (bool PrintView); @@ -197,7 +197,7 @@ static void SysCfg_PutIconToPrint (__attribute__((unused)) void *Args) /********* Get average coordinates of centers in current institution *********/ /*****************************************************************************/ -static void SysCfg_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom) +static void SysCfg_GetCoordAndZoom (struct Map_Coordinates *Coord,unsigned *Zoom) { char *Query; @@ -225,7 +225,7 @@ static void SysCfg_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom) static void SysCfg_Map (void) { MYSQL_RES *mysql_res; - struct Coordinates CtyAvgCoord; + struct Map_Coordinates CtyAvgCoord; unsigned Zoom; unsigned NumCtrs; unsigned NumCtr;