diff --git a/sql/cambios.sql b/sql/cambios.sql index 8411119a..65df25d7 100644 --- a/sql/cambios.sql +++ b/sql/cambios.sql @@ -13112,6 +13112,10 @@ SELECT AVG(Latitude),AVG(Longitude),MAX(MAX(Latitude)-MIN(Latitude),MAX(Longitud +SELECT COUNT(*) FROM centres WHERE InsCod=1 AND Latitude<>0 AND Longitude<>0; +SELECT EXISTS (SELECT * FROM centres WHERE InsCod=1 AND Latitude<>0 AND Longitude<>0); + + \ No newline at end of file diff --git a/swad_centre.c b/swad_centre.c index 2ccf5b8b..24997713 100644 --- a/swad_centre.c +++ b/swad_centre.c @@ -392,10 +392,9 @@ static void Ctr_ListOneCentreForSeeing (struct Centre *Ctr,unsigned NumCtr) HTM_Txt (Plc.ShrtName); HTM_TD_End (); - /***** Place *****/ + /***** Map *****/ HTM_TD_Begin ("class=\"%s CM %s\"",TxtClassNormal,BgColor); - if (Ctr->Coord.Latitude || - Ctr->Coord.Longitude) + if (Ctr_GetIfMapIsAvailable (Ctr)) { Ctr_EditingCtr = Ctr; // Used to pass parameter with the code of the centre Lay_PutContextualLinkOnlyIcon (ActSeeCtrInf,NULL,Ctr_PutParamGoToCtr, @@ -2129,3 +2128,14 @@ static void Ctr_EditingCentreDestructor (void) Ctr_EditingCtr = NULL; } } + +/*****************************************************************************/ +/************************ Check if a centre has map **************************/ +/*****************************************************************************/ + +bool Ctr_GetIfMapIsAvailable (const struct Centre *Ctr) + { + /***** Coordinates 0, 0 means not set ==> don't show map *****/ + return (bool) (Ctr->Coord.Latitude || + Ctr->Coord.Longitude); + } diff --git a/swad_centre.h b/swad_centre.h index 61cf994a..3f12eeb7 100644 --- a/swad_centre.h +++ b/swad_centre.h @@ -144,4 +144,6 @@ unsigned Ctr_GetNumCtrsWithUsrs (Rol_Role_t Role,const char *SubQuery); void Ctr_ListCtrsFound (MYSQL_RES **mysql_res,unsigned NumCtrs); +bool Ctr_GetIfMapIsAvailable (const struct Centre *Ctr); + #endif diff --git a/swad_centre_config.c b/swad_centre_config.c index 9cf4334f..3938213c 100644 --- a/swad_centre_config.c +++ b/swad_centre_config.c @@ -77,7 +77,6 @@ static void CtrCfg_Configuration (bool PrintView); static void CtrCfg_PutIconsCtrConfig (void); static void CtrCfg_PutIconToChangePhoto (void); static void CtrCfg_Title (bool PutLink); -static bool CtrCfg_GetIfMapIsAvailable (void); static void CtrCfg_Map (void); static void CtrCfg_Latitude (void); static void CtrCfg_Longitude (void); @@ -222,7 +221,7 @@ static void CtrCfg_Configuration (bool PrintView) /**************************** Right part **********************************/ /***** Check map *****/ - MapIsAvailable = CtrCfg_GetIfMapIsAvailable (); + MapIsAvailable = Ctr_GetIfMapIsAvailable (&Gbl.Hierarchy.Ctr); /***** Check photo *****/ snprintf (PathPhoto,sizeof (PathPhoto), @@ -316,17 +315,6 @@ static void CtrCfg_Title (bool PutLink) Gbl.Hierarchy.Ctr.FullName); // Text full name } -/*****************************************************************************/ -/******************** Check if centre map should be shown ********************/ -/*****************************************************************************/ - -static bool CtrCfg_GetIfMapIsAvailable (void) - { - /***** Coordinates 0, 0 means not set ==> don't show map *****/ - return (bool) (Gbl.Hierarchy.Ctr.Coord.Latitude || - Gbl.Hierarchy.Ctr.Coord.Longitude); - } - /*****************************************************************************/ /****************************** Draw centre map ******************************/ /*****************************************************************************/ diff --git a/swad_changelog.h b/swad_changelog.h index c6814dbf..e91c58c2 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -492,7 +492,7 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - * En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 19.114 (2020-01-08)" +#define Log_PLATFORM_VERSION "SWAD 19.115 (2020-01-09)" #define CSS_FILE "swad19.112.css" #define JS_FILE "swad19.91.1.js" /* @@ -501,6 +501,8 @@ ps2pdf source.ps destination.pdf // TODO: No se puede entrar con DNI '1' suponiendo que no tenga password ¿por qué? // TODO: Mapas más estrechos en móvil + Version 19.115: Jan 09, 2020 Map column in listing of institutions. + Fixed bug in edition of timetable, reported by Miguel Damas Hermoso. (? lines) Version 19.114: Jan 08, 2020 New option in System tab to view platform configuration. Optimizations in number of users in courses. (278462 lines) Version 19.113: Jan 08, 2020 Code refactoring related to hierarchy. diff --git a/swad_country.c b/swad_country.c index 332673fc..4d1c42b7 100644 --- a/swad_country.c +++ b/swad_country.c @@ -2069,3 +2069,34 @@ static void Cty_EditingCountryDestructor (void) Cty_EditingCty = NULL; } } + +/*****************************************************************************/ +/************ Check if any of the centres in a country has map ***************/ +/*****************************************************************************/ + +bool Cty_GetIfMapIsAvailable (long CtyCod) + { + MYSQL_RES *mysql_res; + MYSQL_ROW row; + bool MapIsAvailable = false; + + /***** Get if any centre in current country has a coordinate set + (coordinates 0, 0 means not set ==> don't show map) *****/ + if (DB_QuerySELECT (&mysql_res,"can not get if map is available", + "SELECT EXISTS" + "(SELECT * FROM FROM institutions,centres" + " WHERE institutions.CtyCod=%ld" + " AND institutions.InsCod=centres.InsCod" + " AND (centres.Latitude<>0 OR centres.Longitude<>0))", + CtyCod)) + { + /* Get if map is available */ + row = mysql_fetch_row (mysql_res); + MapIsAvailable = (row[0][0] == '1'); + } + + /* Free structure that stores the query result */ + DB_FreeMySQLResult (&mysql_res); + + return MapIsAvailable; + } diff --git a/swad_country.h b/swad_country.h index 1aa9b26c..d5626749 100644 --- a/swad_country.h +++ b/swad_country.h @@ -121,4 +121,6 @@ unsigned Cty_GetNumCtysWithUsrs (Rol_Role_t Role,const char *SubQuery); void Cty_ListCtysFound (MYSQL_RES **mysql_res,unsigned NumCtys); +bool Cty_GetIfMapIsAvailable (long CtyCod); + #endif diff --git a/swad_country_config.c b/swad_country_config.c index f23911e3..528e5471 100644 --- a/swad_country_config.c +++ b/swad_country_config.c @@ -64,7 +64,6 @@ extern struct Globals Gbl; static void CtyCfg_Configuration (bool PrintView); static void CtyCfg_PutIconToPrint (void); static void CtyCfg_Title (bool PutLink); -static bool CtyCfg_GetIfMapIsAvailable (void); static void CtyCfg_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom); static void CtyCfg_Map (void); static void CtyCfg_MapImage (bool PrintView,bool PutLink); @@ -178,7 +177,7 @@ static void CtyCfg_Configuration (bool PrintView) /**************************** Right part **********************************/ /***** Check map *****/ - MapIsAvailable = CtyCfg_GetIfMapIsAvailable (); + MapIsAvailable = Cty_GetIfMapIsAvailable (Gbl.Hierarchy.Cty.CtyCod); /***** Check country map *****/ MapImageExists = Cty_CheckIfCountryPhotoExists (&Gbl.Hierarchy.Cty); @@ -229,25 +228,6 @@ static void CtyCfg_Title (bool PutLink) HTM_DIV_End (); } -/*****************************************************************************/ -/******************** Check if country map should be shown *******************/ -/*****************************************************************************/ - -static bool CtyCfg_GetIfMapIsAvailable (void) - { - /***** Get number of centres of current country - with both coordinates set - (coordinates 0, 0 means not set ==> don't show map) *****/ - return - (unsigned) DB_QueryCOUNT ("can not get centres with coordinates", - "SELECT COUNT(*) FROM institutions,centres" - " WHERE institutions.CtyCod=%ld" - " AND institutions.InsCod=centres.InsCod" - " AND centres.Latitude<>0" - " AND centres.Longitude<>0", - Gbl.Hierarchy.Cty.CtyCod); - } - /*****************************************************************************/ /********* Get average coordinates of centres in current institution *********/ /*****************************************************************************/ diff --git a/swad_institution.c b/swad_institution.c index 40c91590..07b2b904 100644 --- a/swad_institution.c +++ b/swad_institution.c @@ -369,6 +369,7 @@ static void Ins_PutIconToEditInstitutions (void) static void Ins_ListOneInstitutionForSeeing (struct Instit *Ins,unsigned NumIns) { + extern const char *Txt_Map; extern const char *Txt_INSTITUTION_STATUS[Ins_NUM_STATUS_TXT]; const char *TxtClassNormal; const char *TxtClassStrong; @@ -401,12 +402,23 @@ static void Ins_ListOneInstitutionForSeeing (struct Instit *Ins,unsigned NumIns) TxtClassStrong,"CM"); HTM_TD_End (); - /***** Stats *****/ - /* Number of users who claim to belong to this institution */ + /***** Number of users who claim to belong to this institution *****/ HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor); HTM_Unsigned (Usr_GetNumUsrsWhoClaimToBelongToIns (Ins)); HTM_TD_End (); + /***** Map *****/ + HTM_TD_Begin ("class=\"%s CM %s\"",TxtClassNormal,BgColor); + if (Ins_GetIfMapIsAvailable (Ins->InsCod)) + { + Ins_EditingIns = Ins; // Used to pass parameter with the code of the institution + Lay_PutContextualLinkOnlyIcon (ActSeeInsInf,NULL,Ins_PutParamGoToIns, + "map-marker-alt.svg", + Txt_Map); + } + HTM_TD_End (); + + /***** Other stats *****/ /* Number of centres in this institution */ HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor); HTM_Unsigned (Ctr_GetNumCtrsInIns (Ins->InsCod)); @@ -456,6 +468,7 @@ static void Ins_PutHeadInstitutionsForSeeing (bool OrderSelectable) extern const char *Txt_INSTITUTIONS_HELP_ORDER[2]; extern const char *Txt_INSTITUTIONS_ORDER[2]; extern const char *Txt_ROLES_PLURAL_BRIEF_Abc[Rol_NUM_ROLES]; + extern const char *Txt_Map; extern const char *Txt_Centres_ABBREVIATION; extern const char *Txt_Degrees_ABBREVIATION; extern const char *Txt_Courses_ABBREVIATION; @@ -498,6 +511,7 @@ static void Ins_PutHeadInstitutionsForSeeing (bool OrderSelectable) HTM_TH_End (); } + HTM_TH (1,1,"CM",Txt_Map); HTM_TH (1,1,"RM",Txt_Centres_ABBREVIATION); HTM_TH (1,1,"RM",Txt_Degrees_ABBREVIATION); HTM_TH (1,1,"RM",Txt_Courses_ABBREVIATION); @@ -2098,3 +2112,33 @@ static void Ins_EditingInstitutionDestructor (void) Ins_EditingIns = NULL; } } + +/*****************************************************************************/ +/********** Check if any of the centres in an institution has map ************/ +/*****************************************************************************/ + +bool Ins_GetIfMapIsAvailable (long InsCod) + { + MYSQL_RES *mysql_res; + MYSQL_ROW row; + bool MapIsAvailable = false; + + /***** Get if any centre in current institution has a coordinate set + (coordinates 0, 0 means not set ==> don't show map) *****/ + if (DB_QuerySELECT (&mysql_res,"can not get if map is available", + "SELECT EXISTS" + "(SELECT * FROM centres" + " WHERE InsCod=%ld" + " AND (Latitude<>0 OR Longitude<>0))", + InsCod)) + { + /* Get if map is available */ + row = mysql_fetch_row (mysql_res); + MapIsAvailable = (row[0][0] == '1'); + } + + /* Free structure that stores the query result */ + DB_FreeMySQLResult (&mysql_res); + + return MapIsAvailable; + } diff --git a/swad_institution.h b/swad_institution.h index 6eb7492e..ae92a912 100644 --- a/swad_institution.h +++ b/swad_institution.h @@ -139,4 +139,6 @@ unsigned Ins_GetNumInssWithUsrs (Rol_Role_t Role,const char *SubQuery); void Ins_ListInssFound (MYSQL_RES **mysql_res,unsigned NumInss); +bool Ins_GetIfMapIsAvailable (long InsCod); + #endif diff --git a/swad_institution_config.c b/swad_institution_config.c index 5810cf7e..583971ba 100644 --- a/swad_institution_config.c +++ b/swad_institution_config.c @@ -65,7 +65,6 @@ extern struct Globals Gbl; static void InsCfg_Configuration (bool PrintView); static void InsCfg_PutIconsToPrintAndUpload (void); static void InsCfg_Title (bool PutLink); -static bool InsCfg_GetIfMapIsAvailable (void); static void InsCfg_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom); static void InsCfg_Map (void); static void InsCfg_Country (bool PrintView,bool PutForm); @@ -188,7 +187,7 @@ static void InsCfg_Configuration (bool PrintView) /**************************** Right part **********************************/ /***** Check map *****/ - MapIsAvailable = InsCfg_GetIfMapIsAvailable (); + MapIsAvailable = Ins_GetIfMapIsAvailable (Gbl.Hierarchy.Ins.InsCod); if (MapIsAvailable) { @@ -236,24 +235,6 @@ static void InsCfg_Title (bool PutLink) Gbl.Hierarchy.Ins.FullName); // Text full name } -/*****************************************************************************/ -/******************** Check if centre map should be shown ********************/ -/*****************************************************************************/ - -static bool InsCfg_GetIfMapIsAvailable (void) - { - /***** Get number of centres of current institution - with both coordinates set - (coordinates 0, 0 means not set ==> don't show map) *****/ - return - (unsigned) DB_QueryCOUNT ("can not get centres with coordinates", - "SELECT COUNT(*) FROM centres" - " WHERE InsCod=%ld" - " AND Latitude<>0" - " AND Longitude<>0", - Gbl.Hierarchy.Ins.InsCod); - } - /*****************************************************************************/ /********* Get average coordinates of centres in current institution *********/ /*****************************************************************************/ diff --git a/swad_map.c b/swad_map.c index c9b97ae4..57534811 100644 --- a/swad_map.c +++ b/swad_map.c @@ -261,6 +261,6 @@ static unsigned Map_GetZoomFromDistance (double MaxDistance) ((MaxDistance < 0.1 ) ? 12 : ((MaxDistance < 1.0 ) ? 8 : ((MaxDistance < 10.0 ) ? 6 : - ((MaxDistance < 100.0 ) ? 3 : + ((MaxDistance < 50.0 ) ? 2 : 1)))); } diff --git a/swad_system_config.c b/swad_system_config.c index 404532ff..f72b99b3 100644 --- a/swad_system_config.c +++ b/swad_system_config.c @@ -186,18 +186,31 @@ static void SysCfg_PutIconToPrint (void) } /*****************************************************************************/ -/******************** Check if country map should be shown *******************/ +/******************* Check if any of the centres has map *********************/ /*****************************************************************************/ static bool SysCfg_GetIfMapIsAvailable (void) { - /***** Get number of centres with both coordinates set + MYSQL_RES *mysql_res; + MYSQL_ROW row; + bool MapIsAvailable = false; + + /***** Get if any centre has a coordinate set (coordinates 0, 0 means not set ==> don't show map) *****/ - return - (unsigned) DB_QueryCOUNT ("can not get centres with coordinates", - "SELECT COUNT(*) FROM centres" - " WHERE centres.Latitude<>0" - " AND centres.Longitude<>0"); + if (DB_QuerySELECT (&mysql_res,"can not get if map is available", + "SELECT EXISTS" + "(SELECT * FROM centres" + " WHERE centres.Latitude<>0 OR centres.Longitude<>0)")) + { + /* Get if map is available */ + row = mysql_fetch_row (mysql_res); + MapIsAvailable = (row[0] == '1'); + } + + /* Free structure that stores the query result */ + DB_FreeMySQLResult (&mysql_res); + + return MapIsAvailable; } /*****************************************************************************/ diff --git a/swad_timetable.c b/swad_timetable.c index 5b2d02df..839bd59a 100644 --- a/swad_timetable.c +++ b/swad_timetable.c @@ -1651,12 +1651,17 @@ static void TT_TimeTableDrawCell (unsigned Weekday,unsigned Interval,unsigned Co for (Dur = 0; Dur <= MaxDuration; Dur++) - HTM_OPTION (HTM_Type_STRING,"", + { + if (asprintf (&TTDur,"%u:%02u", + (Dur / Gbl.TimeTable.Config.IntervalsPerHour), // Hours + (Dur % Gbl.TimeTable.Config.IntervalsPerHour) * + Gbl.TimeTable.Config.Range.MinutesPerInterval) < 0) // Minutes + Lay_NotEnoughMemoryExit (); + HTM_OPTION (HTM_Type_STRING,TTDur, Dur == DurationNumIntervals,false, - "%u:%02u", - (Dur / Gbl.TimeTable.Config.IntervalsPerHour), // Hours - (Dur % Gbl.TimeTable.Config.IntervalsPerHour) * - Gbl.TimeTable.Config.Range.MinutesPerInterval); // Minutes + "%s",TTDur); + free (TTDur); + } HTM_SELECT_End (); if (Gbl.TimeTable.View == TT_CRS_EDIT)