Version 20.81: May 22, 2021 New module swad_country_database for database queries related to countries.

This commit is contained in:
acanas 2021-05-22 12:34:10 +02:00
parent 34fb16932c
commit c1a0a2832b
14 changed files with 1264 additions and 1076 deletions

View File

@ -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 \

View File

@ -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];

View File

@ -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)

File diff suppressed because it is too large Load Diff

View File

@ -32,6 +32,8 @@
#include <stdlib.h> // For free
#include <string.h> // 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 ();

257
swad_country_database.c Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/********************************* Headers ***********************************/
/*****************************************************************************/
#define _GNU_SOURCE // For asprintf
// #include <stdbool.h> // For boolean type
// #include <stddef.h> // For NULL
#include <stdio.h> // For asprintf
// #include <stdlib.h> // For free
// #include <string.h> // 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);
}

52
swad_country_database.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/********************************* Headers ***********************************/
/*****************************************************************************/
#include <mysql/mysql.h> // 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

View File

@ -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 ();

View File

@ -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
}
/*****************************************************************************/

View File

@ -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;

View File

@ -27,11 +27,13 @@
/********************************* Headers ***********************************/
/*****************************************************************************/
#include <stdbool.h> // 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);

View File

@ -30,6 +30,7 @@
#include <mysql/mysql.h> // To access MySQL databases
#include "swad_cryptography.h"
#include "swad_string.h"
/*****************************************************************************/
/***************************** Public constants ******************************/

View File

@ -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
}
/*****************************************************************************/

View File

@ -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;