swad-core/swad_country.c

2509 lines
84 KiB
C
Raw Normal View History

2014-12-01 23:55:08 +01:00
// swad_country.c: countries
/*
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.
2019-01-07 21:52:19 +01:00
Copyright (C) 1999-2019 Antonio Ca<EFBFBD>as Vargas
2014-12-01 23:55:08 +01:00
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 ***********************************/
/*****************************************************************************/
2018-10-20 01:07:58 +02:00
#define _GNU_SOURCE // For asprintf
2014-12-01 23:55:08 +01:00
#include <linux/stddef.h> // For NULL
#include <math.h> // For log10, ceil, pow...
2018-10-20 01:07:58 +02:00
#include <stdio.h> // For asprintf
2014-12-01 23:55:08 +01:00
#include <stdlib.h> // For calloc
#include <string.h> // For string functions
2017-06-10 21:38:10 +02:00
#include "swad_box.h"
2014-12-01 23:55:08 +01:00
#include "swad_constant.h"
#include "swad_country.h"
#include "swad_database.h"
2018-11-09 20:47:39 +01:00
#include "swad_form.h"
2014-12-01 23:55:08 +01:00
#include "swad_global.h"
2015-10-06 20:34:49 +02:00
#include "swad_help.h"
2019-10-23 19:05:05 +02:00
#include "swad_HTML.h"
2014-12-01 23:55:08 +01:00
#include "swad_institution.h"
2017-05-07 18:06:34 +02:00
#include "swad_language.h"
2014-12-01 23:55:08 +01:00
#include "swad_QR.h"
2019-03-26 11:53:21 +01:00
#include "swad_setting.h"
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/******************************* Private types *******************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private variables *****************************/
/*****************************************************************************/
2019-04-08 23:34:58 +02:00
static struct Country *Cty_EditingCty = NULL; // Static variable to keep the country being edited
2019-04-08 21:10:12 +02:00
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
static void Cty_Configuration (bool PrintView);
2016-03-18 19:59:27 +01:00
static void Cty_PutIconToPrint (void);
2017-05-21 14:43:10 +02:00
static void Cty_ShowNumUsrsInCrssOfCty (Rol_Role_t Role);
2014-12-01 23:55:08 +01:00
2017-02-28 00:59:01 +01:00
static void Cty_PutHeadCountriesForSeeing (bool OrderSelectable);
static void Cty_ListOneCountryForSeeing (struct Country *Cty,unsigned NumCty);
2016-11-06 23:24:11 +01:00
static bool Cty_CheckIfICanEditCountries (void);
2016-11-06 22:42:58 +01:00
2018-11-15 22:33:21 +01:00
static void Cty_PutIconsListingCountries (void);
2016-03-16 22:40:35 +01:00
static void Cty_PutIconToEditCountries (void);
2016-03-16 12:11:59 +01:00
2015-11-17 01:22:57 +01:00
static unsigned Cty_GetNumUsrsWhoClaimToBelongToCty (long CtyCod);
2017-01-29 12:42:19 +01:00
static void Cty_GetParamCtyOrder (void);
2017-04-30 20:20:25 +02:00
2019-04-08 21:10:12 +02:00
static void Cty_EditCountriesInternal (void);
2018-11-15 22:33:21 +01:00
static void Cty_PutIconsEditingCountries (void);
2017-04-30 20:20:25 +02:00
static void Cty_PutIconToViewCountries (void);
2014-12-01 23:55:08 +01:00
static void Cty_GetMapAttribution (long CtyCod,char **MapAttribution);
static void Cty_FreeMapAttribution (char **MapAttribution);
static void Cty_ListCountriesForEdition (void);
static void Cty_PutParamOtherCtyCod (long CtyCod);
2016-10-23 19:40:14 +02:00
static long Cty_GetParamOtherCtyCod (void);
2014-12-01 23:55:08 +01:00
static bool Cty_CheckIfNumericCountryCodeExists (long CtyCod);
2017-01-28 15:58:46 +01:00
static bool Cty_CheckIfAlpha2CountryCodeExists (const char Alpha2[2 + 1]);
2018-12-08 16:43:13 +01:00
static bool Cty_CheckIfCountryNameExists (Lan_Language_t Language,const char *Name,long CtyCod);
2017-03-10 02:40:01 +01:00
static void Cty_UpdateCtyNameDB (long CtyCod,const char *FieldName,const char *NewCtyName);
2019-04-08 21:10:12 +02:00
static void Cty_ShowAlertAndButtonToGoToCty (void);
static void Cty_PutParamGoToCty (void);
2014-12-01 23:55:08 +01:00
static void Cty_PutFormToCreateCountry (void);
2017-02-28 00:59:01 +01:00
static void Cty_PutHeadCountriesForEdition (void);
2019-04-08 21:10:12 +02:00
static void Cty_CreateCountry (void);
2014-12-01 23:55:08 +01:00
2019-04-08 21:10:12 +02:00
static void Cty_EditingCountryConstructor (void);
static void Cty_EditingCountryDestructor (void);
2019-04-04 11:22:08 +02:00
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/***************** List countries with pending institutions ******************/
/*****************************************************************************/
void Cty_SeeCtyWithPendingInss (void)
{
2017-03-27 13:38:10 +02:00
extern const char *Hlp_SYSTEM_Hierarchy_pending;
2018-12-08 16:43:13 +01:00
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
2014-12-01 23:55:08 +01:00
extern const char *Txt_Countries_with_pending_institutions;
extern const char *Txt_Country;
2015-12-09 19:51:17 +01:00
extern const char *Txt_Institutions_ABBREVIATION;
2014-12-01 23:55:08 +01:00
extern const char *Txt_There_are_no_countries_with_requests_for_institutions_to_be_confirmed;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumCtys;
unsigned NumCty;
struct Country Cty;
2015-09-04 19:26:08 +02:00
const char *BgColor;
2014-12-01 23:55:08 +01:00
/***** Get countries with pending institutions *****/
2017-06-04 18:18:54 +02:00
switch (Gbl.Usrs.Me.Role.Logged)
2014-12-01 23:55:08 +01:00
{
2015-04-07 21:44:24 +02:00
case Rol_SYS_ADM:
2018-10-30 14:47:31 +01:00
NumCtys = (unsigned) DB_QuerySELECT (&mysql_res,"can not get countries"
"with pending institutions",
"SELECT institutions.CtyCod,COUNT(*)"
" FROM institutions,countries"
" WHERE (institutions.Status & %u)<>0"
" AND institutions.CtyCod=countries.CtyCod"
" GROUP BY institutions.CtyCod"
" ORDER BY countries.Name_%s",
(unsigned) Ins_STATUS_BIT_PENDING,
2018-12-08 16:43:13 +01:00
Lan_STR_LANG_ID[Gbl.Prefs.Language]);
2014-12-01 23:55:08 +01:00
break;
default: // Forbidden for other users
return;
}
/***** Get countries *****/
2018-10-30 14:47:31 +01:00
if (NumCtys)
2014-12-01 23:55:08 +01:00
{
2019-10-26 02:19:42 +02:00
/***** Begin box and table *****/
2019-11-25 23:18:08 +01:00
Box_BoxTableBegin (NULL,Txt_Countries_with_pending_institutions,NULL,
2017-06-12 15:03:29 +02:00
Hlp_SYSTEM_Hierarchy_pending,Box_NOT_CLOSABLE,2);
2017-06-12 14:16:33 +02:00
/***** Write heading *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-11 09:09:19 +02:00
2019-10-23 19:05:05 +02:00
HTM_TH (1,1,"LM",Txt_Country);
HTM_TH (1,1,"RM",Txt_Institutions_ABBREVIATION);
2019-10-11 09:09:19 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
/***** List the countries *****/
for (NumCty = 0;
NumCty < NumCtys;
NumCty++)
{
/* Get next country */
row = mysql_fetch_row (mysql_res);
/* Get country code (row[0]) */
Cty.CtyCod = Str_ConvertStrCodToLongCod (row[0]);
2019-04-03 20:57:04 +02:00
BgColor = (Cty.CtyCod == Gbl.Hierarchy.Cty.CtyCod) ? "LIGHT_BLUE" :
Gbl.ColorRows[Gbl.RowEvenOdd];
2014-12-01 23:55:08 +01:00
/* Get data of country */
2015-12-09 19:51:17 +01:00
Cty_GetDataOfCountryByCod (&Cty,Cty_GET_BASIC_DATA);
2014-12-01 23:55:08 +01:00
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-06 12:00:55 +02:00
/* Country map */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LM %s\"",BgColor);
2015-11-19 18:33:16 +01:00
Cty_DrawCountryMapAndNameWithLink (&Cty,ActSeeIns,
2017-03-04 19:46:46 +01:00
"COUNTRY_SMALL",
"COUNTRY_MAP_SMALL",
2019-11-18 11:23:48 +01:00
"BT_LINK DAT");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Number of pending institutions (row[1]) */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor);
2019-11-10 12:36:37 +01:00
HTM_Txt (row[1]);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd;
}
2017-06-12 14:16:33 +02:00
/***** End table and box *****/
2019-11-25 23:18:08 +01:00
Box_BoxTableEnd ();
2014-12-01 23:55:08 +01:00
}
else
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_INFO,Txt_There_are_no_countries_with_requests_for_institutions_to_be_confirmed);
2014-12-01 23:55:08 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/***************** Show information of the current country *******************/
/*****************************************************************************/
void Cty_ShowConfiguration (void)
{
Cty_Configuration (false);
2015-10-06 01:19:21 +02:00
2017-03-30 11:20:06 +02:00
/***** Show help to enrol me *****/
2015-10-06 20:34:49 +02:00
Hlp_ShowHelpWhatWouldYouLikeToDo ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/***************** Print information of the current country ******************/
/*****************************************************************************/
void Cty_PrintConfiguration (void)
{
Cty_Configuration (true);
}
/*****************************************************************************/
/******************** Information of the current country *********************/
/*****************************************************************************/
static void Cty_Configuration (bool PrintView)
{
2016-11-13 16:19:18 +01:00
extern const char *Hlp_COUNTRY_Information;
2019-02-22 21:47:50 +01:00
extern const char *The_ClassFormInBox[The_NUM_THEMES];
2014-12-01 23:55:08 +01:00
extern const char *Txt_Country;
2015-03-07 18:09:42 +01:00
extern const char *Txt_Shortcut;
2018-12-08 16:43:13 +01:00
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
2014-12-01 23:55:08 +01:00
extern const char *Txt_QR_code;
2016-05-30 19:52:46 +02:00
extern const char *Txt_Institutions;
extern const char *Txt_Institutions_of_COUNTRY_X;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Centres;
extern const char *Txt_Degrees;
extern const char *Txt_Courses;
2015-12-09 19:51:17 +01:00
extern const char *Txt_Users_of_the_country;
2014-12-01 23:55:08 +01:00
char *MapAttribution = NULL;
2019-04-03 20:57:04 +02:00
bool PutLink;
2014-12-01 23:55:08 +01:00
2019-04-03 20:57:04 +02:00
/***** Trivial check *****/
if (Gbl.Hierarchy.Cty.CtyCod <= 0) // No country selected
return;
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
2019-04-03 20:57:04 +02:00
if (PrintView)
2019-10-25 22:48:34 +02:00
Box_BoxBegin (NULL,NULL,NULL,
2019-04-03 20:57:04 +02:00
NULL,Box_NOT_CLOSABLE);
else
2019-10-25 22:48:34 +02:00
Box_BoxBegin (NULL,NULL,Cty_PutIconToPrint,
2019-04-03 20:57:04 +02:00
Hlp_COUNTRY_Information,Box_NOT_CLOSABLE);
/***** Title *****/
PutLink = !PrintView && Gbl.Hierarchy.Cty.WWW[Gbl.Prefs.Language][0];
2019-10-23 21:37:01 +02:00
HTM_DIV_Begin ("class=\"FRAME_TITLE FRAME_TITLE_BIG\"");
2019-04-03 20:57:04 +02:00
if (PutLink)
2019-10-28 20:38:29 +01:00
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]);
2019-11-10 12:36:37 +01:00
HTM_Txt (Gbl.Hierarchy.Cty.Name[Gbl.Prefs.Language]);
2019-04-03 20:57:04 +02:00
if (PutLink)
2019-10-28 13:56:04 +01:00
HTM_A_End ();
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-04-03 20:57:04 +02:00
/***** Country map (and link to WWW if exists) *****/
if (Cty_CheckIfCountryMapExists (&Gbl.Hierarchy.Cty))
2014-12-01 23:55:08 +01:00
{
2019-04-03 20:57:04 +02:00
/* Get map attribution */
Cty_GetMapAttribution (Gbl.Hierarchy.Cty.CtyCod,&MapAttribution);
2014-12-08 17:35:48 +01:00
2019-04-03 20:57:04 +02:00
/* Map image */
2019-10-23 21:37:01 +02:00
HTM_DIV_Begin ("class=\"DAT_SMALL CM\"");
2014-12-01 23:55:08 +01:00
if (PutLink)
2019-10-28 20:38:29 +01:00
HTM_A_Begin ("href=\"%s\" target=\"_blank\"",
Gbl.Hierarchy.Cty.WWW[Gbl.Prefs.Language]);
2019-04-03 20:57:04 +02:00
Cty_DrawCountryMap (&Gbl.Hierarchy.Cty,PrintView ? "COUNTRY_MAP_PRINT" :
2019-10-28 20:38:29 +01:00
"COUNTRY_MAP_SHOW");
2014-12-01 23:55:08 +01:00
if (PutLink)
2019-10-28 13:56:04 +01:00
HTM_A_End ();
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2014-12-01 23:55:08 +01:00
2019-04-03 20:57:04 +02:00
/* Map attribution */
if (!PrintView && Cty_CheckIfICanEditCountries ())
2014-12-01 23:55:08 +01:00
{
2019-10-23 21:37:01 +02:00
HTM_DIV_Begin ("class=\"CM\"");
2019-04-03 20:57:04 +02:00
Frm_StartForm (ActChgCtyMapAtt);
2019-10-31 17:42:05 +01:00
HTM_TEXTAREA_Begin ("name=\"Attribution\" cols=\"50\" rows=\"2\""
2019-11-04 22:42:03 +01:00
" onchange=\"document.getElementById('%s').submit();return false;\"",
2019-10-31 17:42:05 +01:00
Gbl.Form.Id);
2019-04-03 20:57:04 +02:00
if (MapAttribution)
2019-11-10 12:36:37 +01:00
HTM_Txt (MapAttribution);
2019-10-31 17:42:05 +01:00
HTM_TEXTAREA_End ();
2019-04-03 20:57:04 +02:00
Frm_EndForm ();
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2014-12-01 23:55:08 +01:00
}
2019-04-03 20:57:04 +02:00
else if (MapAttribution)
2019-10-23 20:07:56 +02:00
{
2019-10-23 21:37:01 +02:00
HTM_DIV_Begin ("class=\"ATTRIBUTION\"");
2019-11-10 12:36:37 +01:00
HTM_Txt (MapAttribution);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
}
2019-04-03 20:57:04 +02:00
/* Free memory used for map attribution */
Cty_FreeMapAttribution (&MapAttribution);
}
2014-12-01 23:55:08 +01:00
2019-10-20 22:00:28 +02:00
/***** Begin table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginWidePadding (2);
2016-03-18 19:59:27 +01:00
2019-04-03 20:57:04 +02:00
/***** Country name (an link to WWW if exists) *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s RM\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s:",Txt_Country);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT_N LM\"");
2019-04-03 20:57:04 +02:00
if (!PrintView && Gbl.Hierarchy.Cty.WWW[Gbl.Prefs.Language][0])
2019-10-28 20:38:29 +01:00
HTM_A_Begin ("href=\"%s\" target=\"_blank\" class=\"DAT_N\"",
Gbl.Hierarchy.Cty.WWW[Gbl.Prefs.Language]);
2019-11-10 12:36:37 +01:00
HTM_Txt (Gbl.Hierarchy.Cty.Name[Gbl.Prefs.Language]);
2019-04-03 20:57:04 +02:00
if (!PrintView && Gbl.Hierarchy.Cty.WWW[Gbl.Prefs.Language][0])
2019-10-28 13:56:04 +01:00
HTM_A_End ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2019-04-03 20:57:04 +02:00
/***** Link to the country inside platform *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s RM\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s:",Txt_Shortcut);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT LM\"");
2019-10-28 20:38:29 +01:00
HTM_A_Begin ("href=\"%s/%s?cty=%ld\" class=\"DAT\" target=\"_blank\"",
Cfg_URL_SWAD_CGI,
Lan_STR_LANG_ID[Gbl.Prefs.Language],
Gbl.Hierarchy.Cty.CtyCod);
2019-11-11 00:15:44 +01:00
HTM_TxtF ("%s/%s?cty=%ld",
Cfg_URL_SWAD_CGI,
Lan_STR_LANG_ID[Gbl.Prefs.Language],
Gbl.Hierarchy.Cty.CtyCod);
2019-10-28 13:56:04 +01:00
HTM_A_End ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2019-04-03 20:57:04 +02:00
if (PrintView)
{
/***** QR code with link to the country *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s RM\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s:",Txt_QR_code);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT LM\"");
2019-04-03 20:57:04 +02:00
QR_LinkTo (250,"cty",Gbl.Hierarchy.Cty.CtyCod);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2019-04-03 20:57:04 +02:00
}
else
{
/***** Number of users who claim to belong to this country *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s RM\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s:",Txt_Users_of_the_country);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT LM\"");
2019-11-10 13:31:47 +01:00
HTM_Unsigned (Usr_GetNumUsrsWhoClaimToBelongToCty (Gbl.Hierarchy.Cty.CtyCod));
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2016-05-30 19:52:46 +02:00
2019-04-03 20:57:04 +02:00
/***** Number of institutions *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s RM\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s:",Txt_Institutions);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-04-03 20:57:04 +02:00
/* Form to go to see institutions of this country */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LM\"");
2019-04-03 20:57:04 +02:00
Frm_StartFormGoTo (ActSeeIns);
Cty_PutParamCtyCod (Gbl.Hierarchy.Cty.CtyCod);
snprintf (Gbl.Title,sizeof (Gbl.Title),
Txt_Institutions_of_COUNTRY_X,
Gbl.Hierarchy.Cty.Name[Gbl.Prefs.Language]);
2019-11-20 10:17:42 +01:00
HTM_BUTTON_SUBMIT_Begin (Gbl.Title,"BT_LINK DAT",NULL);
2019-11-10 13:31:47 +01:00
HTM_Unsigned (Ins_GetNumInssInCty (Gbl.Hierarchy.Cty.CtyCod));
2019-11-18 11:23:48 +01:00
HTM_BUTTON_End ();
2019-04-03 20:57:04 +02:00
Frm_EndForm ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2019-04-03 20:57:04 +02:00
/***** Number of centres *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s RM\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s:",Txt_Centres);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT LM\"");
2019-11-10 13:31:47 +01:00
HTM_Unsigned (Ctr_GetNumCtrsInCty (Gbl.Hierarchy.Cty.CtyCod));
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2016-03-18 19:59:27 +01:00
2019-04-03 20:57:04 +02:00
/***** Number of degrees *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s RM\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s:",Txt_Degrees);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT LM\"");
2019-11-10 13:31:47 +01:00
HTM_Unsigned (Deg_GetNumDegsInCty (Gbl.Hierarchy.Cty.CtyCod));
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2019-04-03 20:57:04 +02:00
/***** Number of courses *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s RM\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s:",Txt_Courses);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT LM\"");
2019-11-10 13:31:47 +01:00
HTM_Unsigned (Crs_GetNumCrssInCty (Gbl.Hierarchy.Cty.CtyCod));
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2019-04-03 20:57:04 +02:00
/***** Number of users in courses of this country *****/
Cty_ShowNumUsrsInCrssOfCty (Rol_TCH);
Cty_ShowNumUsrsInCrssOfCty (Rol_NET);
Cty_ShowNumUsrsInCrssOfCty (Rol_STD);
Cty_ShowNumUsrsInCrssOfCty (Rol_UNK);
2014-12-01 23:55:08 +01:00
}
2019-04-03 20:57:04 +02:00
/***** End table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2019-04-03 20:57:04 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2014-12-01 23:55:08 +01:00
}
2016-03-18 19:59:27 +01:00
/*****************************************************************************/
2016-03-18 20:07:40 +01:00
/************* Put icon to print the configuration of a country **************/
2016-03-18 19:59:27 +01:00
/*****************************************************************************/
static void Cty_PutIconToPrint (void)
{
2017-06-11 19:13:28 +02:00
Ico_PutContextualIconToPrint (ActPrnCtyInf,NULL);
2016-03-18 19:59:27 +01:00
}
2017-05-21 14:43:10 +02:00
/*****************************************************************************/
/**************** Number of users in courses of this country *****************/
/*****************************************************************************/
static void Cty_ShowNumUsrsInCrssOfCty (Rol_Role_t Role)
{
2019-02-22 21:47:50 +01:00
extern const char *The_ClassFormInBox[The_NUM_THEMES];
2017-05-21 14:43:10 +02:00
extern const char *Txt_Users_in_courses;
extern const char *Txt_ROLES_PLURAL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"%s RM\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s:",Role == Rol_UNK ? Txt_Users_in_courses :
Txt_ROLES_PLURAL_Abc[Role][Usr_SEX_UNKNOWN]);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT LM\"");
2019-11-10 13:31:47 +01:00
HTM_Unsigned (Usr_GetNumUsrsInCrssOfCty (Role,Gbl.Hierarchy.Cty.CtyCod));
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2017-05-21 14:43:10 +02:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/*************************** List all the countries **************************/
/*****************************************************************************/
void Cty_ListCountries (void)
{
Cty_ListCountries1 ();
Cty_ListCountries2 ();
}
/*****************************************************************************/
/*************************** List all the countries **************************/
/*****************************************************************************/
void Cty_ListCountries1 (void)
{
/***** Get parameter with the type of order in the list of countries *****/
2017-01-29 12:42:19 +01:00
Cty_GetParamCtyOrder ();
2014-12-01 23:55:08 +01:00
/***** Get list of countries *****/
Cty_GetListCountries (Cty_GET_EXTRA_DATA);
}
void Cty_ListCountries2 (void)
{
2016-11-13 14:55:01 +01:00
extern const char *Hlp_SYSTEM_Countries;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Countries;
extern const char *Txt_Other_countries;
extern const char *Txt_Country_unspecified;
unsigned NumCty;
2018-11-16 01:05:56 +01:00
/***** Write menu to select country *****/
Hie_WriteMenuHierarchy ();
2019-10-26 02:19:42 +02:00
/***** Begin box and table *****/
2019-11-25 23:18:08 +01:00
Box_BoxTableBegin (NULL,Txt_Countries,Cty_PutIconsListingCountries,
2017-06-12 15:03:29 +02:00
Hlp_SYSTEM_Countries,Box_NOT_CLOSABLE,2);
2017-06-12 14:16:33 +02:00
/***** Write heading *****/
2017-02-28 00:59:01 +01:00
Cty_PutHeadCountriesForSeeing (true); // Order selectable
2014-12-01 23:55:08 +01:00
/***** Write all the countries and their number of users and institutions *****/
for (NumCty = 0;
2019-04-04 10:45:15 +02:00
NumCty < Gbl.Hierarchy.Sys.Ctys.Num;
2014-12-01 23:55:08 +01:00
NumCty++)
2019-04-04 10:45:15 +02:00
Cty_ListOneCountryForSeeing (&Gbl.Hierarchy.Sys.Ctys.Lst[NumCty],NumCty + 1);
2014-12-01 23:55:08 +01:00
/***** Separation row *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
HTM_TD_Begin ("colspan=\"8\" class=\"DAT CM\"");
2019-11-14 08:59:11 +01:00
HTM_NBSP ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
2015-11-17 01:22:57 +01:00
/***** Write users and institutions in other countries *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT LM\"");
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt_Other_countries);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM\"");
2019-11-10 13:31:47 +01:00
HTM_Unsigned (Cty_GetNumUsrsWhoClaimToBelongToCty (0));
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM\"");
2019-11-10 13:31:47 +01:00
HTM_Unsigned (Ins_GetNumInssInCty (0));
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM\"");
2019-11-10 13:31:47 +01:00
HTM_Unsigned (Ctr_GetNumCtrsInCty (0));
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM\"");
2019-11-10 13:31:47 +01:00
HTM_Unsigned (Deg_GetNumDegsInCty (0));
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM\"");
2019-11-10 13:31:47 +01:00
HTM_Unsigned (Crs_GetNumCrssInCty (0));
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM\"");
2019-11-10 13:31:47 +01:00
HTM_Unsigned (Usr_GetNumUsrsInCrssOfCty (Rol_TCH,0));
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2015-11-17 01:22:57 +01:00
/***** Write users and institutions with unknown country *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT LM\"");
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt_Country_unspecified);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM\"");
2019-11-10 13:31:47 +01:00
HTM_Unsigned (Cty_GetNumUsrsWhoClaimToBelongToCty (-1L));
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM\"");
2019-11-10 13:31:47 +01:00
HTM_Unsigned (Ins_GetNumInssInCty (-1L));
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM\"");
2019-11-10 13:31:47 +01:00
HTM_Unsigned (Ctr_GetNumCtrsInCty (-1L));
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM\"");
2019-11-10 13:31:47 +01:00
HTM_Unsigned (Deg_GetNumDegsInCty (-1L));
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM\"");
2019-11-10 13:31:47 +01:00
HTM_Unsigned (Crs_GetNumCrssInCty (-1L));
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM\"");
2019-11-10 13:51:07 +01:00
HTM_Unsigned (0);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** End table and box *****/
2019-11-25 23:18:08 +01:00
Box_BoxTableEnd ();
2014-12-01 23:55:08 +01:00
/***** Div for Google Geochart *****/
2016-01-17 15:10:54 +01:00
if (Gbl.Action.Act == ActSeeCty)
2019-10-23 20:07:56 +02:00
{
2019-10-23 21:37:01 +02:00
HTM_DIV_Begin ("id=\"chart_div\"");
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
}
2014-12-01 23:55:08 +01:00
/***** Free list of countries *****/
Cty_FreeListCountries ();
}
2017-02-28 00:59:01 +01:00
/*****************************************************************************/
/******************* Write header with fields of a country *******************/
/*****************************************************************************/
static void Cty_PutHeadCountriesForSeeing (bool OrderSelectable)
{
extern const char *Txt_COUNTRIES_HELP_ORDER[2];
extern const char *Txt_COUNTRIES_ORDER[2];
extern const char *Txt_Institutions_ABBREVIATION;
extern const char *Txt_Centres_ABBREVIATION;
extern const char *Txt_Degrees_ABBREVIATION;
extern const char *Txt_Courses_ABBREVIATION;
2017-05-30 21:43:05 +02:00
extern const char *Txt_ROLES_PLURAL_BRIEF_Abc[Rol_NUM_ROLES];
2017-02-28 00:59:01 +01:00
Cty_Order_t Order;
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TH_Empty (1);
2017-02-28 00:59:01 +01:00
for (Order = Cty_ORDER_BY_COUNTRY;
Order <= Cty_ORDER_BY_NUM_USRS;
Order++)
{
2019-10-23 19:05:05 +02:00
HTM_TH_Begin (1,1,Order == Cty_ORDER_BY_COUNTRY ? "LM" :
2019-10-15 15:23:38 +02:00
"RM");
2017-02-28 00:59:01 +01:00
if (OrderSelectable)
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActSeeCty);
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamUnsigned (NULL,"Order",(unsigned) Order);
2019-11-20 10:17:42 +01:00
HTM_BUTTON_SUBMIT_Begin (Txt_COUNTRIES_HELP_ORDER[Order],"BT_LINK TIT_TBL",NULL);
2019-04-04 10:45:15 +02:00
if (Order == Gbl.Hierarchy.Sys.Ctys.SelectedOrder)
2019-11-10 16:41:47 +01:00
HTM_U_Begin ();
2017-02-28 00:59:01 +01:00
}
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt_COUNTRIES_ORDER[Order]);
2017-02-28 00:59:01 +01:00
if (OrderSelectable)
{
2019-04-04 10:45:15 +02:00
if (Order == Gbl.Hierarchy.Sys.Ctys.SelectedOrder)
2019-11-10 16:41:47 +01:00
HTM_U_End ();
2019-11-18 11:23:48 +01:00
HTM_BUTTON_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2017-02-28 00:59:01 +01:00
}
2019-10-23 19:05:05 +02:00
HTM_TH_End ();
2017-02-28 00:59:01 +01:00
}
2019-10-11 09:09:19 +02:00
2019-10-23 19:05:05 +02:00
HTM_TH (1,1,"RM",Txt_Institutions_ABBREVIATION);
HTM_TH (1,1,"RM",Txt_Centres_ABBREVIATION);
HTM_TH (1,1,"RM",Txt_Degrees_ABBREVIATION);
HTM_TH (1,1,"RM",Txt_Courses_ABBREVIATION);
HTM_TH_Begin (1,1,"RM");
2019-11-11 00:15:44 +01:00
HTM_TxtF ("%s+",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH]);
2019-11-09 21:08:20 +01:00
HTM_BR ();
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt_ROLES_PLURAL_BRIEF_Abc[Rol_STD]);
2019-10-23 19:05:05 +02:00
HTM_TH_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2017-02-28 00:59:01 +01:00
}
/*****************************************************************************/
/************************ List one country for seeing ************************/
/*****************************************************************************/
static void Cty_ListOneCountryForSeeing (struct Country *Cty,unsigned NumCty)
{
const char *BgColor;
2019-04-03 20:57:04 +02:00
BgColor = (Cty->CtyCod == Gbl.Hierarchy.Cty.CtyCod) ? "LIGHT_BLUE" :
Gbl.ColorRows[Gbl.RowEvenOdd];
2017-02-28 00:59:01 +01:00
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 00:05:24 +02:00
/***** Number of country in this list *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor);
2019-11-10 13:31:47 +01:00
HTM_Unsigned (NumCty);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2017-02-28 00:59:01 +01:00
/***** Country map (and link to WWW if exists) *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LM %s\"",BgColor);
2017-02-28 00:59:01 +01:00
Cty_DrawCountryMapAndNameWithLink (Cty,ActSeeIns,
2017-03-04 19:46:46 +01:00
"COUNTRY_SMALL",
"COUNTRY_MAP_SMALL",
2019-11-18 11:23:48 +01:00
"BT_LINK DAT_N");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2017-02-28 00:59:01 +01:00
/* Write stats of this country */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor);
2019-11-10 13:31:47 +01:00
HTM_Unsigned (Cty->NumUsrsWhoClaimToBelongToCty);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor);
2019-11-10 13:31:47 +01:00
HTM_Unsigned (Cty->Inss.Num);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor);
2019-11-10 13:31:47 +01:00
HTM_Unsigned (Cty->NumCtrs);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor);
2019-11-10 13:31:47 +01:00
HTM_Unsigned (Cty->NumDegs);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor);
2019-11-10 13:31:47 +01:00
HTM_Unsigned (Cty->NumCrss);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor);
2019-11-10 13:31:47 +01:00
HTM_Unsigned (Cty->NumUsrs);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2017-02-28 00:59:01 +01:00
Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd;
}
2016-11-06 22:42:58 +01:00
/*****************************************************************************/
/********************** Check if I can edit countries ************************/
/*****************************************************************************/
2016-11-06 23:24:11 +01:00
static bool Cty_CheckIfICanEditCountries (void)
2016-11-06 22:42:58 +01:00
{
2017-06-04 18:18:54 +02:00
return (bool) (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM);
2016-11-06 22:42:58 +01:00
}
2016-11-06 21:19:25 +01:00
/*****************************************************************************/
/***************** Put contextual icons in list of countries *****************/
/*****************************************************************************/
2018-11-15 22:33:21 +01:00
static void Cty_PutIconsListingCountries (void)
2016-11-06 21:19:25 +01:00
{
/***** Put icon to edit countries *****/
2016-11-06 23:24:11 +01:00
if (Cty_CheckIfICanEditCountries ())
2016-11-06 21:19:25 +01:00
Cty_PutIconToEditCountries ();
/***** Put icon to show a figure *****/
2019-02-12 14:46:14 +01:00
Gbl.Figures.FigureType = Fig_HIERARCHY;
Fig_PutIconToShowFigure ();
2016-11-06 21:19:25 +01:00
}
2016-03-16 12:11:59 +01:00
/*****************************************************************************/
2018-11-15 22:33:21 +01:00
/************************ Put icon to edit countries *************************/
2016-03-16 12:11:59 +01:00
/*****************************************************************************/
2016-03-16 22:40:35 +01:00
static void Cty_PutIconToEditCountries (void)
2016-03-16 12:11:59 +01:00
{
2017-06-11 19:13:28 +02:00
Ico_PutContextualIconToEdit (ActEdiCty,NULL);
2016-03-16 12:11:59 +01:00
}
2015-11-17 01:22:57 +01:00
/*****************************************************************************/
/******** Get number of users who claim to belong to other countries *********/
/*****************************************************************************/
static unsigned Cty_GetNumUsrsWhoClaimToBelongToCty (long CtyCod)
{
/***** Get number of users from database *****/
2018-11-03 13:13:11 +01:00
return
(unsigned) DB_QueryCOUNT ("can not get number of users"
" who claim to belong to other countries",
"SELECT COUNT(*) FROM usr_data"
" WHERE CtyCod=%ld",
CtyCod);
2015-11-17 01:22:57 +01:00
}
2015-01-16 01:28:42 +01:00
/*****************************************************************************/
2015-11-19 18:33:16 +01:00
/********************* Draw country map and name with link *******************/
2015-01-16 22:02:21 +01:00
/*****************************************************************************/
2015-11-19 18:33:16 +01:00
void Cty_DrawCountryMapAndNameWithLink (struct Country *Cty,Act_Action_t Action,
2017-03-04 19:46:46 +01:00
const char *ClassContainer,
const char *ClassMap,
const char *ClassLink)
2015-01-16 22:02:21 +01:00
{
2015-11-11 21:14:33 +01:00
extern const char *Txt_Go_to_X;
2017-03-10 02:40:01 +01:00
char CountryName[Cty_MAX_BYTES_NAME + 1];
2015-01-16 22:02:21 +01:00
2019-10-20 22:00:28 +02:00
/***** Begin form *****/
2018-11-09 20:47:39 +01:00
Frm_StartFormGoTo (Action);
2015-11-11 21:14:33 +01:00
Cty_PutParamCtyCod (Cty->CtyCod);
2019-10-23 21:37:01 +02:00
HTM_DIV_Begin ("class=\"%s\"",ClassContainer);
2015-11-11 21:14:33 +01:00
/***** Link to action *****/
2018-10-17 10:32:18 +02:00
snprintf (Gbl.Title,sizeof (Gbl.Title),
Txt_Go_to_X,
Cty->Name[Gbl.Prefs.Language]);
2019-11-20 10:17:42 +01:00
HTM_BUTTON_SUBMIT_Begin (Gbl.Title,ClassLink,NULL);
2015-11-11 21:14:33 +01:00
/***** Draw country map *****/
Cty_DrawCountryMap (Cty,ClassMap);
2019-10-28 13:56:04 +01:00
/***** Write country name *****/
2017-01-15 18:02:52 +01:00
Str_Copy (CountryName,Cty->Name[Gbl.Prefs.Language],
2017-03-10 02:40:01 +01:00
Cty_MAX_BYTES_NAME);
2019-11-11 10:59:24 +01:00
HTM_TxtF ("&nbsp;%s&nbsp;",CountryName);
2019-11-11 00:15:44 +01:00
HTM_TxtF ("(%s)",Cty->Alpha2);
2019-10-28 13:56:04 +01:00
/***** End link *****/
2019-11-18 11:23:48 +01:00
HTM_BUTTON_End ();
2015-11-11 21:14:33 +01:00
/***** End form *****/
2019-10-28 13:56:04 +01:00
HTM_DIV_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2015-01-16 22:02:21 +01:00
}
/*****************************************************************************/
/***************************** Draw country map ******************************/
2015-01-16 01:28:42 +01:00
/*****************************************************************************/
void Cty_DrawCountryMap (struct Country *Cty,const char *Class)
{
2019-10-30 22:31:03 +01:00
char *URL;
char *Icon;
2015-01-16 01:28:42 +01:00
/***** Draw country map *****/
2015-11-11 21:14:33 +01:00
if (Cty_CheckIfCountryMapExists (Cty))
2019-10-30 22:31:03 +01:00
{
if (asprintf (&URL,"%s/%s",
Cfg_URL_ICON_COUNTRIES_PUBLIC,
Cty->Alpha2) < 0)
Lay_NotEnoughMemoryExit ();
if (asprintf (&Icon,"%s.png",
Cty->Alpha2) < 0)
Lay_NotEnoughMemoryExit ();
HTM_IMG (URL,Icon,Cty->Name[Gbl.Prefs.Language],
"class=\"%s\"",Class);
2019-11-06 19:45:20 +01:00
free (Icon);
free (URL);
2019-10-30 22:31:03 +01:00
}
2015-11-11 21:14:33 +01:00
else
2019-10-30 22:31:03 +01:00
Ico_PutIcon ("tr16x16.gif",Cty->Name[Gbl.Prefs.Language],Class);
2015-01-16 01:28:42 +01:00
}
2015-11-11 21:14:33 +01:00
/*****************************************************************************/
/*********************** Check if country map exists *************************/
/*****************************************************************************/
bool Cty_CheckIfCountryMapExists (struct Country *Cty)
{
2017-01-28 15:58:46 +01:00
char PathMap[PATH_MAX + 1];
2015-11-11 21:14:33 +01:00
2018-10-17 10:32:18 +02:00
snprintf (PathMap,sizeof (PathMap),
2019-03-20 01:36:36 +01:00
"%s/%s/%s.png",
Cfg_PATH_ICON_COUNTRIES_PUBLIC,
2018-10-17 10:32:18 +02:00
Cty->Alpha2,
Cty->Alpha2);
2015-11-11 21:14:33 +01:00
return Fil_CheckIfPathExists (PathMap);
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/********************** Write script for Google Geochart *********************/
/*****************************************************************************/
void Cty_WriteScriptGoogleGeochart (void)
{
extern const char *Txt_Country_NO_HTML;
extern const char *Txt_Users_NO_HTML;
extern const char *Txt_Institutions_NO_HTML;
unsigned NumCty;
2016-02-06 12:50:05 +01:00
unsigned MaxUsrsInCountry = 0;
2014-12-01 23:55:08 +01:00
unsigned NumCtysWithUsrs = 0;
/***** Write start of the script *****/
2019-11-01 17:35:26 +01:00
HTM_SCRIPT_Begin ("https://www.google.com/jsapi",NULL);
HTM_SCRIPT_End ();
HTM_SCRIPT_Begin (NULL,NULL);
2019-11-11 00:15:44 +01:00
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);
2014-12-01 23:55:08 +01:00
/***** Write all the countries and their number of users and institutions *****/
for (NumCty = 0;
2019-04-04 10:45:15 +02:00
NumCty < Gbl.Hierarchy.Sys.Ctys.Num;
2014-12-01 23:55:08 +01:00
NumCty++)
2019-04-04 10:45:15 +02:00
if (Gbl.Hierarchy.Sys.Ctys.Lst[NumCty].NumUsrsWhoClaimToBelongToCty)
2014-12-01 23:55:08 +01:00
{
/* Write data of this country */
2019-11-11 00:15:44 +01:00
HTM_TxtF (" ['%s', %u, %u],\n",
Gbl.Hierarchy.Sys.Ctys.Lst[NumCty].Alpha2,
Gbl.Hierarchy.Sys.Ctys.Lst[NumCty].NumUsrsWhoClaimToBelongToCty,
Gbl.Hierarchy.Sys.Ctys.Lst[NumCty].Inss.Num);
2019-04-04 10:45:15 +02:00
if (Gbl.Hierarchy.Sys.Ctys.Lst[NumCty].NumUsrsWhoClaimToBelongToCty > MaxUsrsInCountry)
MaxUsrsInCountry = Gbl.Hierarchy.Sys.Ctys.Lst[NumCty].NumUsrsWhoClaimToBelongToCty;
2014-12-01 23:55:08 +01:00
NumCtysWithUsrs++;
}
/***** Write end of the script *****/
2019-11-11 00:15:44 +01:00
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);
2019-11-01 17:35:26 +01:00
HTM_SCRIPT_End ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******** Get parameter with the type or order in list of countries **********/
/*****************************************************************************/
2017-01-29 12:42:19 +01:00
static void Cty_GetParamCtyOrder (void)
2014-12-01 23:55:08 +01:00
{
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Sys.Ctys.SelectedOrder = (Cty_Order_t)
2017-01-29 21:41:08 +01:00
Par_GetParToUnsignedLong ("Order",
0,
Cty_NUM_ORDERS - 1,
(unsigned long) Cty_ORDER_DEFAULT);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Put forms to edit institution types ********************/
/*****************************************************************************/
void Cty_EditCountries (void)
2019-04-08 21:10:12 +02:00
{
/***** Country constructor *****/
Cty_EditingCountryConstructor ();
/***** Edit countries *****/
Cty_EditCountriesInternal ();
/***** Country destructor *****/
Cty_EditingCountryDestructor ();
}
static void Cty_EditCountriesInternal (void)
2014-12-01 23:55:08 +01:00
{
2017-04-30 20:20:25 +02:00
extern const char *Hlp_SYSTEM_Countries;
extern const char *Txt_Countries;
2014-12-01 23:55:08 +01:00
/***** Get list of countries *****/
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Sys.Ctys.SelectedOrder = Cty_ORDER_BY_COUNTRY;
2014-12-01 23:55:08 +01:00
Cty_GetListCountries (Cty_GET_EXTRA_DATA);
2018-11-16 01:05:56 +01:00
/***** Write menu to select country *****/
Hie_WriteMenuHierarchy ();
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
2019-10-25 22:48:34 +02:00
Box_BoxBegin (NULL,Txt_Countries,Cty_PutIconsEditingCountries,
2017-06-12 15:03:29 +02:00
Hlp_SYSTEM_Countries,Box_NOT_CLOSABLE);
2014-12-01 23:55:08 +01:00
/***** Put a form to create a new country *****/
Cty_PutFormToCreateCountry ();
/***** Forms to edit current countries *****/
2019-04-04 10:45:15 +02:00
if (Gbl.Hierarchy.Sys.Ctys.Num)
2014-12-01 23:55:08 +01:00
Cty_ListCountriesForEdition ();
2017-06-12 14:16:33 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2017-04-30 20:20:25 +02:00
2014-12-01 23:55:08 +01:00
/***** Free list of countries *****/
Cty_FreeListCountries ();
}
2017-04-30 20:20:25 +02:00
/*****************************************************************************/
/*************** Put contextual icons in edition of countries ****************/
/*****************************************************************************/
2018-11-15 22:33:21 +01:00
static void Cty_PutIconsEditingCountries (void)
{
/***** Put icon to view countries *****/
Cty_PutIconToViewCountries ();
/***** Put icon to show a figure *****/
2019-02-12 14:46:14 +01:00
Gbl.Figures.FigureType = Fig_HIERARCHY;
Fig_PutIconToShowFigure ();
2018-11-15 22:33:21 +01:00
}
/*****************************************************************************/
/************************ Put icon to view countries *************************/
/*****************************************************************************/
2017-04-30 20:20:25 +02:00
static void Cty_PutIconToViewCountries (void)
{
2018-11-15 22:33:21 +01:00
extern const char *Txt_Countries;
2019-01-12 03:00:59 +01:00
Lay_PutContextualLinkOnlyIcon (ActSeeCty,NULL,NULL,
"globe.svg",
Txt_Countries);
2017-04-30 20:20:25 +02:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************************** List all the countries ***************************/
/*****************************************************************************/
2018-12-08 16:43:13 +01:00
#define Cty_MAX_BYTES_SUBQUERY_CTYS ((1 + Lan_NUM_LANGUAGES) * 32)
2017-01-16 01:51:01 +01:00
2014-12-01 23:55:08 +01:00
void Cty_GetListCountries (Cty_GetExtraData_t GetExtraData)
{
2018-12-08 16:43:13 +01:00
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
2014-12-01 23:55:08 +01:00
char StrField[32];
2017-03-07 11:03:05 +01:00
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];
2018-10-30 14:47:31 +01:00
char *OrderBySubQuery = NULL;
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2018-10-30 14:47:31 +01:00
unsigned long NumRows = 0;
2014-12-01 23:55:08 +01:00
unsigned NumCty;
struct Country *Cty;
2018-12-08 16:43:13 +01:00
Lan_Language_t Lan;
2014-12-01 23:55:08 +01:00
/***** Get countries from database *****/
switch (GetExtraData)
{
2015-12-09 19:51:17 +01:00
case Cty_GET_BASIC_DATA:
2018-10-30 14:47:31 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get countries",
"SELECT CtyCod,Alpha2,Name_%s"
" FROM countries ORDER BY Name_%s",
2018-12-08 16:43:13 +01:00
Lan_STR_LANG_ID[Gbl.Prefs.Language],
Lan_STR_LANG_ID[Gbl.Prefs.Language]);
2014-12-01 23:55:08 +01:00
break;
case Cty_GET_EXTRA_DATA:
SubQueryNam1[0] = '\0';
SubQueryNam2[0] = '\0';
SubQueryWWW1[0] = '\0';
SubQueryWWW2[0] = '\0';
2019-12-15 01:10:36 +01:00
for (Lan = (Lan_Language_t) 1;
Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES;
2014-12-01 23:55:08 +01:00
Lan++)
{
2018-10-17 10:32:18 +02:00
snprintf (StrField,sizeof (StrField),
"countries.Name_%s,",
2018-12-08 16:43:13 +01:00
Lan_STR_LANG_ID[Lan]);
2017-01-17 03:33:05 +01:00
Str_Concat (SubQueryNam1,StrField,
2017-03-07 11:03:05 +01:00
Cty_MAX_BYTES_SUBQUERY_CTYS);
2018-10-17 10:32:18 +02:00
snprintf (StrField,sizeof (StrField),
"Name_%s,",
2018-12-08 16:43:13 +01:00
Lan_STR_LANG_ID[Lan]);
2017-01-17 03:33:05 +01:00
Str_Concat (SubQueryNam2,StrField,
2017-03-07 11:03:05 +01:00
Cty_MAX_BYTES_SUBQUERY_CTYS);
2014-12-01 23:55:08 +01:00
2018-10-17 10:32:18 +02:00
snprintf (StrField,sizeof (StrField),
"countries.WWW_%s,",
2018-12-08 16:43:13 +01:00
Lan_STR_LANG_ID[Lan]);
2017-01-17 03:33:05 +01:00
Str_Concat (SubQueryWWW1,StrField,
2017-03-07 11:03:05 +01:00
Cty_MAX_BYTES_SUBQUERY_CTYS);
2018-10-17 10:32:18 +02:00
snprintf (StrField,sizeof (StrField),
"WWW_%s,",
2018-12-08 16:43:13 +01:00
Lan_STR_LANG_ID[Lan]);
2017-01-17 03:33:05 +01:00
Str_Concat (SubQueryWWW2,StrField,
2017-03-07 11:03:05 +01:00
Cty_MAX_BYTES_SUBQUERY_CTYS);
2014-12-01 23:55:08 +01:00
}
2019-04-04 10:45:15 +02:00
switch (Gbl.Hierarchy.Sys.Ctys.SelectedOrder)
2014-12-01 23:55:08 +01:00
{
case Cty_ORDER_BY_COUNTRY:
2018-10-30 01:00:46 +01:00
if (asprintf (&OrderBySubQuery,"Name_%s",
2018-12-08 16:43:13 +01:00
Lan_STR_LANG_ID[Gbl.Prefs.Language]) < 0)
2018-10-30 01:00:46 +01:00
Lay_NotEnoughMemoryExit ();
2014-12-01 23:55:08 +01:00
break;
case Cty_ORDER_BY_NUM_USRS:
2018-10-30 01:00:46 +01:00
if (asprintf (&OrderBySubQuery,"NumUsrs DESC,Name_%s",
2018-12-08 16:43:13 +01:00
Lan_STR_LANG_ID[Gbl.Prefs.Language]) < 0)
2018-10-30 01:00:46 +01:00
Lay_NotEnoughMemoryExit ();
2014-12-01 23:55:08 +01:00
break;
}
2018-10-30 14:47:31 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get countries",
"(SELECT countries.CtyCod,countries.Alpha2,"
"%s%sCOUNT(*) AS NumUsrs"
" FROM countries,usr_data"
" WHERE countries.CtyCod=usr_data.CtyCod"
" GROUP BY countries.CtyCod)"
" UNION "
"(SELECT CtyCod,Alpha2,%s%s0 AS NumUsrs"
" FROM countries"
" WHERE CtyCod NOT IN"
" (SELECT DISTINCT CtyCod FROM usr_data))"
" ORDER BY %s",
SubQueryNam1,SubQueryWWW1,
SubQueryNam2,SubQueryWWW2,OrderBySubQuery);
2014-12-01 23:55:08 +01:00
break;
}
2018-10-30 01:00:46 +01:00
/***** Free memory for subquery *****/
if (OrderBySubQuery)
2019-11-06 19:45:20 +01:00
free (OrderBySubQuery);
2018-10-30 01:00:46 +01:00
2014-12-01 23:55:08 +01:00
if (NumRows) // Countries found...
{
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Sys.Ctys.Num = (unsigned) NumRows;
2014-12-01 23:55:08 +01:00
/***** Create list with countries *****/
2019-04-04 10:45:15 +02:00
if ((Gbl.Hierarchy.Sys.Ctys.Lst = (struct Country *) calloc (NumRows,sizeof (struct Country))) == NULL)
2018-10-18 20:06:54 +02:00
Lay_NotEnoughMemoryExit ();
2014-12-01 23:55:08 +01:00
/***** Get the countries *****/
for (NumCty = 0;
2019-04-04 10:45:15 +02:00
NumCty < Gbl.Hierarchy.Sys.Ctys.Num;
2014-12-01 23:55:08 +01:00
NumCty++)
{
2019-04-04 10:45:15 +02:00
Cty = &(Gbl.Hierarchy.Sys.Ctys.Lst[NumCty]);
2014-12-01 23:55:08 +01:00
/* Get next country */
row = mysql_fetch_row (mysql_res);
/* Get numerical country code (row[0]) */
if ((Cty->CtyCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong code of country.");
/* Get Alpha-2 country code (row[1]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Cty->Alpha2,row[1],
2);
2014-12-01 23:55:08 +01:00
switch (GetExtraData)
{
2015-12-09 19:51:17 +01:00
case Cty_GET_BASIC_DATA:
2019-12-15 01:10:36 +01:00
for (Lan = (Lan_Language_t) 1;
Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES;
2015-12-09 19:51:17 +01:00
Lan++)
{
Cty->Name[Lan][0] = '\0';
Cty->WWW[Lan][0] = '\0';
}
Cty->NumUsrsWhoClaimToBelongToCty = 0;
2019-04-04 10:45:15 +02:00
Cty->Inss.Num = Cty->NumCtrs = Cty->NumDegs = Cty->NumCrss = 0;
2015-12-14 12:13:41 +01:00
Cty->NumUsrs = 0;
2015-12-09 19:51:17 +01:00
2014-12-01 23:55:08 +01:00
/* Get the name of the country in current language */
2017-01-15 18:02:52 +01:00
Str_Copy (Cty->Name[Gbl.Prefs.Language],row[2],
2017-03-10 02:40:01 +01:00
Cty_MAX_BYTES_NAME);
2014-12-01 23:55:08 +01:00
break;
case Cty_GET_EXTRA_DATA:
/* Get the name of the country in several languages */
2019-12-15 01:10:36 +01:00
for (Lan = (Lan_Language_t) 1;
Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES;
2014-12-01 23:55:08 +01:00
Lan++)
{
2017-01-15 18:02:52 +01:00
Str_Copy (Cty->Name[Lan],row[1 + Lan],
2017-03-10 02:40:01 +01:00
Cty_MAX_BYTES_NAME);
2018-12-08 16:43:13 +01:00
Str_Copy (Cty->WWW[Lan],row[1 + Lan_NUM_LANGUAGES + Lan],
2017-03-07 01:56:41 +01:00
Cns_MAX_BYTES_WWW);
2014-12-01 23:55:08 +01:00
}
2015-12-09 19:51:17 +01:00
/* Get number of users who claim to belong to this country */
2018-12-08 16:43:13 +01:00
if (sscanf (row[1 + Lan_NUM_LANGUAGES * 2 + 1],"%u",
2017-01-28 15:58:46 +01:00
&Cty->NumUsrsWhoClaimToBelongToCty) != 1)
2015-12-09 19:51:17 +01:00
Cty->NumUsrsWhoClaimToBelongToCty = 0;
2014-12-01 23:55:08 +01:00
/* Get number of institutions in this country */
2019-04-04 10:45:15 +02:00
Cty->Inss.Num = Ins_GetNumInssInCty (Cty->CtyCod);
2015-12-09 19:51:17 +01:00
/* Get number of centres in this country */
Cty->NumCtrs = Ctr_GetNumCtrsInCty (Cty->CtyCod);
/* Get number of degrees in this country */
Cty->NumDegs = Deg_GetNumDegsInCty (Cty->CtyCod);
/* Get number of courses in this country */
Cty->NumCrss = Crs_GetNumCrssInCty (Cty->CtyCod);
/* Get number of users in courses of this country */
2017-05-18 19:13:41 +02:00
Cty->NumUsrs = Usr_GetNumUsrsInCrssOfCty (Rol_UNK,Cty->CtyCod); // Here Rol_UNK means "all users"
2014-12-01 23:55:08 +01:00
break;
}
}
}
else
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Sys.Ctys.Num = 0;
2014-12-01 23:55:08 +01:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/************************** Write selector of country ************************/
/*****************************************************************************/
2015-07-25 20:20:07 +02:00
void Cty_WriteSelectorOfCountry (void)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_Country;
2018-12-08 16:43:13 +01:00
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumCtys;
unsigned NumCty;
long CtyCod;
2019-10-20 22:00:28 +02:00
/***** Begin form *****/
2018-11-09 20:47:39 +01:00
Frm_StartFormGoTo (ActSeeIns);
2019-11-05 15:47:35 +01:00
HTM_SELECT_Begin (true,
"id=\"cty\" name=\"cty\" class=\"HIE_SEL\"");
2019-11-06 19:45:20 +01:00
HTM_OPTION (HTM_Type_STRING,"",Gbl.Hierarchy.Cty.CtyCod < 0,true,
2019-11-06 08:59:15 +01:00
"[%s]",Txt_Country);
2014-12-01 23:55:08 +01:00
/***** Get countries from database *****/
2018-10-30 14:47:31 +01:00
NumCtys = (unsigned) DB_QuerySELECT (&mysql_res,"can not get countries",
"SELECT DISTINCT CtyCod,Name_%s"
" FROM countries"
" ORDER BY countries.Name_%s",
2018-12-08 16:43:13 +01:00
Lan_STR_LANG_ID[Gbl.Prefs.Language],
Lan_STR_LANG_ID[Gbl.Prefs.Language]);
2014-12-01 23:55:08 +01:00
/***** List countries *****/
for (NumCty = 0;
NumCty < NumCtys;
NumCty++)
{
/* Get next country */
row = mysql_fetch_row (mysql_res);
/* Get country code (row[0]) */
if ((CtyCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong code of country.");
/* Write option */
2019-11-06 19:45:20 +01:00
HTM_OPTION (HTM_Type_LONG,&CtyCod,
2019-11-06 08:59:15 +01:00
CtyCod == Gbl.Hierarchy.Cty.CtyCod,false,
"%s",row[1]);
2014-12-01 23:55:08 +01:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
/***** End form *****/
2019-11-05 08:46:38 +01:00
HTM_SELECT_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2017-03-02 00:53:34 +01:00
/***************************** Write country name ****************************/
2015-12-08 00:25:56 +01:00
/*****************************************************************************/
2017-03-01 14:53:18 +01:00
// If ClassLink == NULL ==> do not put link
2015-12-08 00:25:56 +01:00
2017-03-01 14:53:18 +01:00
void Cty_WriteCountryName (long CtyCod,const char *ClassLink)
2015-12-08 00:25:56 +01:00
{
2017-03-10 02:40:01 +01:00
char CtyName[Cty_MAX_BYTES_NAME + 1];
2017-03-07 01:56:41 +01:00
char ActTxt[Act_MAX_BYTES_ACTION_TXT + 1];
2017-03-01 14:53:18 +01:00
bool PutForm = ClassLink &&
!Gbl.Form.Inside && // Only if not inside another form
2018-04-24 13:21:53 +02:00
Act_GetBrowserTab (Gbl.Action.Act) == Act_BRW_1ST_TAB; // Only in main browser tab
2015-12-08 00:25:56 +01:00
/***** Get country name *****/
Cty_GetCountryName (CtyCod,CtyName);
2016-09-09 01:17:53 +02:00
if (PutForm)
2015-12-15 01:33:09 +01:00
{
/***** Write country name with link to country information *****/
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActSeeCtyInf);
2015-12-15 01:33:09 +01:00
Cty_PutParamCtyCod (CtyCod);
2019-11-20 10:17:42 +01:00
HTM_BUTTON_SUBMIT_Begin (Act_GetActionTextFromDB (Act_GetActCod (ActSeeCtyInf),ActTxt),
2019-11-18 11:23:48 +01:00
ClassLink,NULL);
2019-11-10 12:36:37 +01:00
HTM_Txt (CtyName);
2019-11-18 11:23:48 +01:00
HTM_BUTTON_End ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2015-12-15 01:33:09 +01:00
}
2016-09-09 01:17:53 +02:00
else
/***** Write country name without link *****/
2019-11-10 12:36:37 +01:00
HTM_Txt (CtyName);
2015-12-08 00:25:56 +01:00
}
/*****************************************************************************/
2015-12-09 19:51:17 +01:00
/***************** Get basic data of country given its code ******************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2015-12-09 19:51:17 +01:00
bool Cty_GetDataOfCountryByCod (struct Country *Cty,Cty_GetExtraData_t GetExtraData)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_Another_country;
2018-12-08 16:43:13 +01:00
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
2014-12-01 23:55:08 +01:00
char StrField[32];
2017-03-07 11:03:05 +01:00
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];
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2018-10-30 14:47:31 +01:00
unsigned long NumRows = 0;
2018-12-08 16:43:13 +01:00
Lan_Language_t Lan;
2014-12-01 23:55:08 +01:00
bool CtyFound;
if (Cty->CtyCod < 0)
return false;
/***** Clear data *****/
2019-12-15 01:10:36 +01:00
for (Lan = (Lan_Language_t) 1;
Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES;
2014-12-01 23:55:08 +01:00
Lan++)
{
Cty->Name[Lan][0] = '\0';
Cty->WWW[Lan][0] = '\0';
}
2015-12-09 19:51:17 +01:00
Cty->NumUsrsWhoClaimToBelongToCty = 0;
2019-04-04 10:45:15 +02:00
Cty->Inss.Num = Cty->NumCtrs = Cty->NumDegs = Cty->NumCrss = 0;
2014-12-01 23:55:08 +01:00
Cty->NumUsrs = 0;
/***** Check if country code is correct *****/
if (Cty->CtyCod == 0)
{
2019-12-15 01:10:36 +01:00
for (Lan = (Lan_Language_t) 1;
Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES;
2014-12-01 23:55:08 +01:00
Lan++)
if (Lan == Gbl.Prefs.Language)
2017-01-15 18:02:52 +01:00
Str_Copy (Cty->Name[Lan],Txt_Another_country,
2017-03-10 02:40:01 +01:00
Cty_MAX_BYTES_NAME);
2014-12-01 23:55:08 +01:00
else
Cty->Name[Lan][0] = '\0';
return false;
}
2015-12-09 19:51:17 +01:00
// Here Cty->CtyCod > 0
2014-12-01 23:55:08 +01:00
/***** Get data of a country from database *****/
2015-12-09 19:51:17 +01:00
switch (GetExtraData)
2014-12-01 23:55:08 +01:00
{
2015-12-09 19:51:17 +01:00
case Cty_GET_BASIC_DATA:
2018-10-30 14:47:31 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a country",
"SELECT Alpha2,Name_%s,WWW_%s"
" FROM countries"
" WHERE CtyCod='%03ld'",
2018-12-08 16:43:13 +01:00
Lan_STR_LANG_ID[Gbl.Prefs.Language],
Lan_STR_LANG_ID[Gbl.Prefs.Language],
2018-10-30 14:47:31 +01:00
Cty->CtyCod);
2015-12-09 19:51:17 +01:00
break;
case Cty_GET_EXTRA_DATA:
SubQueryNam1[0] = '\0';
SubQueryNam2[0] = '\0';
SubQueryWWW1[0] = '\0';
SubQueryWWW2[0] = '\0';
2019-12-15 01:10:36 +01:00
for (Lan = (Lan_Language_t) 1;
Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES;
2015-12-09 19:51:17 +01:00
Lan++)
{
2018-10-17 10:32:18 +02:00
snprintf (StrField,sizeof (StrField),
"countries.Name_%s,",
2018-12-08 16:43:13 +01:00
Lan_STR_LANG_ID[Lan]);
2017-01-17 03:33:05 +01:00
Str_Concat (SubQueryNam1,StrField,
2017-03-07 11:03:05 +01:00
Cty_MAX_BYTES_SUBQUERY_CTYS);
2018-10-17 10:32:18 +02:00
snprintf (StrField,sizeof (StrField),
"Name_%s,",
2018-12-08 16:43:13 +01:00
Lan_STR_LANG_ID[Lan]);
2017-01-17 03:33:05 +01:00
Str_Concat (SubQueryNam2,StrField,
2017-03-07 11:03:05 +01:00
Cty_MAX_BYTES_SUBQUERY_CTYS);
2015-12-09 19:51:17 +01:00
2018-10-17 10:32:18 +02:00
snprintf (StrField,sizeof (StrField),
"countries.WWW_%s,",
2018-12-08 16:43:13 +01:00
Lan_STR_LANG_ID[Lan]);
2017-01-17 03:33:05 +01:00
Str_Concat (SubQueryWWW1,StrField,
2017-03-07 11:03:05 +01:00
Cty_MAX_BYTES_SUBQUERY_CTYS);
2018-10-17 10:32:18 +02:00
snprintf (StrField,sizeof (StrField),
"WWW_%s,",
2018-12-08 16:43:13 +01:00
Lan_STR_LANG_ID[Lan]);
2017-01-17 03:33:05 +01:00
Str_Concat (SubQueryWWW2,StrField,
2017-03-07 11:03:05 +01:00
Cty_MAX_BYTES_SUBQUERY_CTYS);
2015-12-09 19:51:17 +01:00
}
2018-10-30 14:47:31 +01:00
NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a country",
"(SELECT countries.Alpha2,%s%sCOUNT(*) AS NumUsrs"
" FROM countries,usr_data"
" WHERE countries.CtyCod='%03ld'"
" AND countries.CtyCod=usr_data.CtyCod)"
" UNION "
"(SELECT Alpha2,%s%s0 AS NumUsrs"
" FROM countries"
" WHERE CtyCod='%03ld'"
" AND CtyCod NOT IN"
" (SELECT DISTINCT CtyCod FROM usr_data))",
SubQueryNam1,SubQueryWWW1,Cty->CtyCod,
SubQueryNam2,SubQueryWWW2,Cty->CtyCod);
2015-12-09 19:51:17 +01:00
break;
2014-12-01 23:55:08 +01:00
}
2015-12-09 19:51:17 +01:00
2014-12-01 23:55:08 +01:00
/***** Count number of rows in result *****/
if (NumRows) // Country found...
{
CtyFound = true;
/* Get row */
row = mysql_fetch_row (mysql_res);
/* Get Alpha-2 country code (row[0]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Cty->Alpha2,row[0],
2);
2014-12-01 23:55:08 +01:00
2015-12-09 19:51:17 +01:00
switch (GetExtraData)
2014-12-01 23:55:08 +01:00
{
2015-12-09 19:51:17 +01:00
case Cty_GET_BASIC_DATA:
2016-11-13 16:19:18 +01:00
/* Get name and WWW of the country in current language */
2017-01-15 18:02:52 +01:00
Str_Copy (Cty->Name[Gbl.Prefs.Language],row[1],
2017-03-10 02:40:01 +01:00
Cty_MAX_BYTES_NAME);
2017-01-17 03:10:43 +01:00
Str_Copy (Cty->WWW[Gbl.Prefs.Language],row[2],
2017-03-07 01:56:41 +01:00
Cns_MAX_BYTES_WWW);
2015-12-09 19:51:17 +01:00
break;
case Cty_GET_EXTRA_DATA:
2016-11-13 16:19:18 +01:00
/* Get name and WWW of the country in several languages */
2019-12-15 01:10:36 +01:00
for (Lan = (Lan_Language_t) 1;
Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES;
2015-12-09 19:51:17 +01:00
Lan++)
{
2017-01-15 18:02:52 +01:00
Str_Copy (Cty->Name[Lan],row[Lan],
2017-03-10 02:40:01 +01:00
Cty_MAX_BYTES_NAME);
2018-12-08 16:43:13 +01:00
Str_Copy (Cty->WWW[Lan],row[Lan_NUM_LANGUAGES + Lan],
2017-03-07 01:56:41 +01:00
Cns_MAX_BYTES_WWW);
2015-12-09 19:51:17 +01:00
}
/* Get number of users who claim to belong to this country */
2018-12-08 16:43:13 +01:00
if (sscanf (row[Lan_NUM_LANGUAGES * 2 + 1],"%u",
2017-01-28 15:58:46 +01:00
&Cty->NumUsrsWhoClaimToBelongToCty) != 1)
2015-12-09 19:51:17 +01:00
Cty->NumUsrsWhoClaimToBelongToCty = 0;
/* Get number of user in courses of this institution */
2017-05-18 19:13:41 +02:00
Cty->NumUsrs = Usr_GetNumUsrsInCrssOfCty (Rol_UNK,Cty->CtyCod); // Here Rol_UNK means "all users"
2015-12-09 19:51:17 +01:00
/* Get number of institutions in this country */
2019-04-04 10:45:15 +02:00
Cty->Inss.Num = Ins_GetNumInssInCty (Cty->CtyCod);
2015-12-09 19:51:17 +01:00
break;
2014-12-01 23:55:08 +01:00
}
}
else
CtyFound = false;
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return CtyFound;
}
/*****************************************************************************/
/***************************** Get country name ******************************/
/*****************************************************************************/
2017-06-20 14:43:26 +02:00
void Cty_FlushCacheCountryName (void)
{
Gbl.Cache.CountryName.CtyCod = -1L;
Gbl.Cache.CountryName.CtyName[0] = '\0';
}
2017-03-10 02:40:01 +01:00
void Cty_GetCountryName (long CtyCod,char CtyName[Cty_MAX_BYTES_NAME + 1])
2014-12-01 23:55:08 +01:00
{
2018-12-08 16:43:13 +01:00
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
2014-12-01 23:55:08 +01:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2017-06-20 14:43:26 +02:00
/***** 1. Fast check: Trivial case *****/
2017-03-01 15:23:30 +01:00
if (CtyCod <= 0)
2014-12-01 23:55:08 +01:00
{
2017-06-20 14:43:26 +02:00
CtyName[0] = '\0'; // Empty name
return;
}
2014-12-01 23:55:08 +01:00
2017-06-20 14:43:26 +02:00
/***** 2. Fast check: If cached... *****/
if (CtyCod == Gbl.Cache.CountryName.CtyCod)
{
Str_Copy (CtyName,Gbl.Cache.CountryName.CtyName,
Cty_MAX_BYTES_NAME);
return;
}
2017-03-01 15:23:30 +01:00
2017-06-20 14:43:26 +02:00
/***** 3. Slow: get country name from database *****/
Gbl.Cache.CountryName.CtyCod = CtyCod;
2017-03-01 15:23:30 +01:00
2018-10-30 14:47:31 +01:00
if (DB_QuerySELECT (&mysql_res,"can not get the name of a country",
"SELECT Name_%s FROM countries WHERE CtyCod='%03ld'",
2018-12-08 16:43:13 +01:00
Lan_STR_LANG_ID[Gbl.Prefs.Language],CtyCod)) // Country found...
2017-06-20 14:43:26 +02:00
{
/* Get row */
row = mysql_fetch_row (mysql_res);
2014-12-01 23:55:08 +01:00
2017-06-20 14:43:26 +02:00
/* Get the name of the country */
Str_Copy (Gbl.Cache.CountryName.CtyName,row[0],
2017-03-10 02:40:01 +01:00
Cty_MAX_BYTES_NAME);
2014-12-01 23:55:08 +01:00
}
2017-06-20 14:43:26 +02:00
else
Gbl.Cache.CountryName.CtyName[0] = '\0';
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
Str_Copy (CtyName,Gbl.Cache.CountryName.CtyName,
Cty_MAX_BYTES_NAME);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Get map attribution from database **********************/
/*****************************************************************************/
static void Cty_GetMapAttribution (long CtyCod,char **MapAttribution)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2017-01-13 01:51:23 +01:00
size_t Length;
2014-12-01 23:55:08 +01:00
/***** Free possible former map attribution *****/
Cty_FreeMapAttribution (MapAttribution);
/***** Get photo attribution from database *****/
2018-10-30 14:47:31 +01:00
if (DB_QuerySELECT (&mysql_res,"can not get photo attribution",
"SELECT MapAttribution FROM countries WHERE CtyCod=%ld",
CtyCod))
2014-12-01 23:55:08 +01:00
{
/* Get row */
row = mysql_fetch_row (mysql_res);
/* Get the attribution of the map of the country (row[0]) */
if (row[0])
if (row[0][0])
{
2017-01-13 01:51:23 +01:00
Length = strlen (row[0]);
2019-04-04 11:22:08 +02:00
if ((*MapAttribution = (char *) malloc (Length + 1)) == NULL)
2014-12-01 23:55:08 +01:00
Lay_ShowErrorAndExit ("Error allocating memory for map attribution.");
2017-01-17 03:10:43 +01:00
Str_Copy (*MapAttribution,row[0],
Length);
2014-12-01 23:55:08 +01:00
}
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/******************* Free memory used for map attribution ********************/
/*****************************************************************************/
static void Cty_FreeMapAttribution (char **MapAttribution)
{
if (*MapAttribution)
{
2019-11-06 19:45:20 +01:00
free (*MapAttribution);
2014-12-01 23:55:08 +01:00
*MapAttribution = NULL;
}
}
/*****************************************************************************/
/*************************** Free list of countries **************************/
/*****************************************************************************/
void Cty_FreeListCountries (void)
{
2019-04-04 10:45:15 +02:00
if (Gbl.Hierarchy.Sys.Ctys.Lst)
2014-12-01 23:55:08 +01:00
{
/***** Free memory used by the list of courses in institution *****/
2019-11-06 19:45:20 +01:00
free (Gbl.Hierarchy.Sys.Ctys.Lst);
2019-04-04 10:45:15 +02:00
Gbl.Hierarchy.Sys.Ctys.Lst = NULL;
Gbl.Hierarchy.Sys.Ctys.Num = 0;
2014-12-01 23:55:08 +01:00
}
}
/*****************************************************************************/
/*************************** List all the countries **************************/
/*****************************************************************************/
static void Cty_ListCountriesForEdition (void)
{
2018-12-08 16:43:13 +01:00
extern const char *Txt_STR_LANG_NAME[1 + Lan_NUM_LANGUAGES];
2014-12-01 23:55:08 +01:00
unsigned NumCty;
struct Country *Cty;
2018-12-08 16:43:13 +01:00
Lan_Language_t Lan;
2014-12-01 23:55:08 +01:00
2017-04-30 20:20:25 +02:00
/***** Write heading *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginWidePadding (2);
2017-02-28 00:59:01 +01:00
Cty_PutHeadCountriesForEdition ();
2014-12-01 23:55:08 +01:00
/***** Write all the countries *****/
for (NumCty = 0;
2019-04-04 10:45:15 +02:00
NumCty < Gbl.Hierarchy.Sys.Ctys.Num;
2014-12-01 23:55:08 +01:00
NumCty++)
{
2019-04-04 10:45:15 +02:00
Cty = &Gbl.Hierarchy.Sys.Ctys.Lst[NumCty];
2014-12-01 23:55:08 +01:00
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-05 13:27:58 +02:00
/* Put icon to remove country */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("rowspan=\"%u\" class=\"BT\"",1 + Lan_NUM_LANGUAGES);
2019-04-04 10:45:15 +02:00
if (Cty->Inss.Num ||
2015-12-09 19:51:17 +01:00
Cty->NumUsrsWhoClaimToBelongToCty ||
2014-12-01 23:55:08 +01:00
Cty->NumUsrs) // Country has institutions or users ==> deletion forbidden
2017-06-11 19:13:28 +02:00
Ico_PutIconRemovalNotAllowed ();
2014-12-01 23:55:08 +01:00
else
{
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActRemCty);
2014-12-01 23:55:08 +01:00
Cty_PutParamOtherCtyCod (Cty->CtyCod);
2017-06-11 19:13:28 +02:00
Ico_PutIconRemove ();
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
}
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Numerical country code (ISO 3166-1) */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("rowspan=\"%u\" class=\"DAT RT\"",1 + Lan_NUM_LANGUAGES);
2019-11-11 00:15:44 +01:00
HTM_TxtF ("%03ld",Cty->CtyCod);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Alphabetic country code with 2 letters (ISO 3166-1) */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("rowspan=\"%u\" class=\"DAT RT\"",1 + Lan_NUM_LANGUAGES);
2019-11-10 12:36:37 +01:00
HTM_Txt (Cty->Alpha2);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
2019-10-23 19:05:05 +02:00
HTM_TD_Empty (3);
2014-12-01 23:55:08 +01:00
/* Number of users */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("rowspan=\"%u\" class=\"DAT RT\"",1 + Lan_NUM_LANGUAGES);
2019-11-10 13:31:47 +01:00
HTM_Unsigned (Cty->NumUsrsWhoClaimToBelongToCty);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Number of institutions */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("rowspan=\"%u\" class=\"DAT RT\"",1 + Lan_NUM_LANGUAGES);
2019-11-10 13:31:47 +01:00
HTM_Unsigned (Cty->Inss.Num);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-05 13:27:58 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
/* Country name in several languages */
2019-12-15 01:10:36 +01:00
for (Lan = (Lan_Language_t) 1;
Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES;
2014-12-01 23:55:08 +01:00
Lan++)
{
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-05 13:27:58 +02:00
/* Language */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RM\"");
2019-11-11 10:59:24 +01:00
HTM_TxtF ("%s:",Txt_STR_LANG_NAME[Lan]);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Name */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LT\"");
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActRenCty);
2014-12-01 23:55:08 +01:00
Cty_PutParamOtherCtyCod (Cty->CtyCod);
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamUnsigned (NULL,"Lan",(unsigned) Lan);
2019-11-04 12:25:48 +01:00
HTM_INPUT_TEXT ("Name",Cty_MAX_CHARS_NAME,Cty->Name[Lan],true,
"size=\"15\"");
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* WWW */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LT\"");
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActChgCtyWWW);
2014-12-01 23:55:08 +01:00
Cty_PutParamOtherCtyCod (Cty->CtyCod);
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamUnsigned (NULL,"Lan",(unsigned) Lan);
2019-11-04 12:25:48 +01:00
HTM_INPUT_URL ("WWW",Cty->WWW[Lan],true,
2019-12-19 11:00:14 +01:00
"class=\"INPUT_WWW_NARROW\" required=\"required\"");
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-05 13:27:58 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
}
}
2017-04-30 20:20:25 +02:00
/***** End table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Write parameter with code of country *******************/
/*****************************************************************************/
void Cty_PutParamCtyCod (long CtyCod)
{
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamLong (NULL,"cty",CtyCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Write parameter with code of country *******************/
/*****************************************************************************/
static void Cty_PutParamOtherCtyCod (long CtyCod)
{
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamLong (NULL,"OthCtyCod",CtyCod);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************* Get parameter with code of country **********************/
/*****************************************************************************/
2017-05-31 21:05:59 +02:00
long Cty_GetAndCheckParamOtherCtyCod (long MinCodAllowed)
2016-10-23 19:40:14 +02:00
{
long CtyCod;
/***** Get and check parameter with code of country *****/
2017-05-31 21:05:59 +02:00
if ((CtyCod = Cty_GetParamOtherCtyCod ()) < MinCodAllowed)
Lay_ShowErrorAndExit ("Code of country is missing or invalid.");
2016-10-23 19:40:14 +02:00
return CtyCod;
}
static long Cty_GetParamOtherCtyCod (void)
2014-12-01 23:55:08 +01:00
{
2017-01-28 20:32:50 +01:00
/***** Get code of country *****/
return Par_GetParToLong ("OthCtyCod");
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/****************************** Remove a country *****************************/
/*****************************************************************************/
void Cty_RemoveCountry (void)
{
extern const char *Txt_You_can_not_remove_a_country_with_institutions_or_users;
extern const char *Txt_Country_X_removed;
2019-04-08 21:10:12 +02:00
/***** Country constructor *****/
Cty_EditingCountryConstructor ();
2014-12-01 23:55:08 +01:00
/***** Get country code *****/
2019-04-08 21:10:12 +02:00
Cty_EditingCty->CtyCod = Cty_GetAndCheckParamOtherCtyCod (0);
2014-12-01 23:55:08 +01:00
/***** Get data of the country from database *****/
2019-04-08 21:10:12 +02:00
Cty_GetDataOfCountryByCod (Cty_EditingCty,Cty_GET_EXTRA_DATA);
2014-12-01 23:55:08 +01:00
/***** Check if this country has users *****/
2019-04-08 21:10:12 +02:00
if (Cty_EditingCty->Inss.Num ||
Cty_EditingCty->NumUsrsWhoClaimToBelongToCty ||
Cty_EditingCty->NumUsrs) // Country has institutions or users ==> don't remove
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_You_can_not_remove_a_country_with_institutions_or_users);
2014-12-01 23:55:08 +01:00
else // Country has no users ==> remove it
{
2016-10-28 00:30:18 +02:00
/***** Remove surveys of the country *****/
2019-04-08 21:10:12 +02:00
Svy_RemoveSurveys (Hie_CTY,Cty_EditingCty->CtyCod);
2016-10-28 00:30:18 +02:00
2014-12-01 23:55:08 +01:00
/***** Remove country *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove a country",
"DELETE FROM countries WHERE CtyCod='%03ld'",
2019-04-08 21:10:12 +02:00
Cty_EditingCty->CtyCod);
2014-12-01 23:55:08 +01:00
2017-06-20 14:43:26 +02:00
/***** Flush cache *****/
Cty_FlushCacheCountryName ();
2014-12-01 23:55:08 +01:00
/***** Write message to show the change made *****/
2019-04-08 21:10:12 +02:00
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_Country_X_removed,
Cty_EditingCty->Name[Gbl.Prefs.Language]);
2019-06-13 10:14:05 +02:00
Cty_EditingCty->CtyCod = -1L; // To not showing button to go to country
2014-12-01 23:55:08 +01:00
}
}
/*****************************************************************************/
/************************ Change the name of a country ***********************/
/*****************************************************************************/
void Cty_RenameCountry (void)
{
extern const char *Txt_The_country_X_already_exists;
extern const char *Txt_The_country_X_has_been_renamed_as_Y;
2018-12-08 16:43:13 +01:00
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
2014-12-01 23:55:08 +01:00
extern const char *Txt_The_name_of_the_country_X_has_not_changed;
2017-03-10 02:40:01 +01:00
char NewCtyName[Cty_MAX_BYTES_NAME + 1];
2018-12-08 16:43:13 +01:00
Lan_Language_t Language;
2017-03-10 02:40:01 +01:00
char FieldName[4 + 1 + 2 + 1]; // Example: "Name_en"
2014-12-01 23:55:08 +01:00
2019-04-04 11:22:08 +02:00
/***** Country constructor *****/
2019-04-08 21:10:12 +02:00
Cty_EditingCountryConstructor ();
2014-12-01 23:55:08 +01:00
2017-05-31 21:05:59 +02:00
/***** Get the code of the country *****/
2019-04-08 21:10:12 +02:00
Cty_EditingCty->CtyCod = Cty_GetAndCheckParamOtherCtyCod (0);
2014-12-01 23:55:08 +01:00
2017-05-31 21:05:59 +02:00
/***** Get the lenguage *****/
2017-05-07 18:06:34 +02:00
Language = Lan_GetParamLanguage ();
2014-12-01 23:55:08 +01:00
2017-05-31 21:05:59 +02:00
/***** Get the new name for the country *****/
2017-03-10 02:40:01 +01:00
Par_GetParToText ("Name",NewCtyName,Cty_MAX_BYTES_NAME);
2014-12-01 23:55:08 +01:00
/***** Get from the database the data of the country *****/
2019-04-08 21:10:12 +02:00
Cty_GetDataOfCountryByCod (Cty_EditingCty,Cty_GET_EXTRA_DATA);
2014-12-01 23:55:08 +01:00
/***** Check if new name is empty *****/
2019-12-20 00:30:54 +01:00
if (NewCtyName[0])
2014-12-01 23:55:08 +01:00
{
2019-01-02 15:10:51 +01:00
/***** Check if old and new names are the same
(this happens when return is pressed without changes) *****/
2019-04-08 21:10:12 +02:00
if (strcmp (Cty_EditingCty->Name[Language],NewCtyName)) // Different names
2017-05-31 21:05:59 +02:00
{
/***** If country was in database... *****/
2019-04-08 21:10:12 +02:00
if (Cty_CheckIfCountryNameExists (Language,NewCtyName,Cty_EditingCty->CtyCod))
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_country_X_already_exists,
NewCtyName);
2017-05-31 21:05:59 +02:00
else
{
/* Update the table changing old name by new name */
2018-10-17 10:32:18 +02:00
snprintf (FieldName,sizeof (FieldName),
"Name_%s",
2018-12-08 16:43:13 +01:00
Lan_STR_LANG_ID[Language]);
2019-04-08 21:10:12 +02:00
Cty_UpdateCtyNameDB (Cty_EditingCty->CtyCod,FieldName,NewCtyName);
2017-05-31 21:05:59 +02:00
/* Write message to show the change made */
2019-04-08 21:10:12 +02:00
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_The_country_X_has_been_renamed_as_Y,
Cty_EditingCty->Name[Language],NewCtyName);
2017-05-31 21:05:59 +02:00
/* Update country name */
2019-04-08 21:10:12 +02:00
Str_Copy (Cty_EditingCty->Name[Language],NewCtyName,
2017-05-31 21:05:59 +02:00
Cty_MAX_BYTES_NAME);
}
}
2014-12-01 23:55:08 +01:00
else // The same name
2019-04-08 21:10:12 +02:00
Ale_CreateAlert (Ale_INFO,NULL,
Txt_The_name_of_the_country_X_has_not_changed,
Cty_EditingCty->Name[Language]);
2014-12-01 23:55:08 +01:00
}
2019-12-20 00:30:54 +01:00
else
Ale_CreateAlertYouCanNotLeaveFieldEmpty ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************* Check if a numeric country code exists ******************/
/*****************************************************************************/
static bool Cty_CheckIfNumericCountryCodeExists (long CtyCod)
{
/***** Get number of countries with a name from database *****/
2018-11-03 13:13:11 +01:00
return (DB_QueryCOUNT ("can not check if the numeric code"
" of a country already existed",
"SELECT COUNT(*) FROM countries"
" WHERE CtyCod='%03ld'",
CtyCod) != 0);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*************** Check if an alphabetic country code exists ******************/
/*****************************************************************************/
2017-01-28 15:58:46 +01:00
static bool Cty_CheckIfAlpha2CountryCodeExists (const char Alpha2[2 + 1])
2014-12-01 23:55:08 +01:00
{
/***** Get number of countries with a name from database *****/
2018-11-03 13:13:11 +01:00
return (DB_QueryCOUNT ("can not check if the alphabetic code"
" of a country already existed",
"SELECT COUNT(*) FROM countries"
" WHERE Alpha2='%s'",
Alpha2) != 0);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Check if the name of country exists ********************/
/*****************************************************************************/
2018-12-08 16:43:13 +01:00
static bool Cty_CheckIfCountryNameExists (Lan_Language_t Language,const char *Name,long CtyCod)
2014-12-01 23:55:08 +01:00
{
2018-12-08 16:43:13 +01:00
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
2014-12-01 23:55:08 +01:00
/***** Get number of countries with a name from database *****/
2018-11-03 13:13:11 +01:00
return (DB_QueryCOUNT ("can not check if the name"
" of a country already existed",
"SELECT COUNT(*) FROM countries"
" WHERE Name_%s='%s' AND CtyCod<>'%03ld'",
2018-12-08 16:43:13 +01:00
Lan_STR_LANG_ID[Language],Name,CtyCod) != 0);
2014-12-01 23:55:08 +01:00
}
2017-03-10 02:40:01 +01:00
/*****************************************************************************/
/************ Update institution name in table of institutions ***************/
/*****************************************************************************/
static void Cty_UpdateCtyNameDB (long CtyCod,const char *FieldName,const char *NewCtyName)
{
/***** Update country changing old name by new name */
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the name of a country",
"UPDATE countries SET %s='%s' WHERE CtyCod='%03ld'",
FieldName,NewCtyName,CtyCod);
2017-06-20 14:43:26 +02:00
/***** Flush cache *****/
Cty_FlushCacheCountryName ();
2017-03-10 02:40:01 +01:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************************ Change the URL of a country ************************/
/*****************************************************************************/
void Cty_ChangeCtyWWW (void)
{
extern const char *Txt_The_new_web_address_is_X;
2018-12-08 16:43:13 +01:00
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
2017-03-07 01:56:41 +01:00
char NewWWW[Cns_MAX_BYTES_WWW + 1];
2018-12-08 16:43:13 +01:00
Lan_Language_t Language;
2014-12-01 23:55:08 +01:00
2019-04-04 11:22:08 +02:00
/***** Country constructor *****/
2019-04-08 21:10:12 +02:00
Cty_EditingCountryConstructor ();
2014-12-01 23:55:08 +01:00
2017-05-31 21:05:59 +02:00
/***** Get the code of the country *****/
2019-04-08 21:10:12 +02:00
Cty_EditingCty->CtyCod = Cty_GetAndCheckParamOtherCtyCod (0);
2014-12-01 23:55:08 +01:00
2017-05-31 21:05:59 +02:00
/***** Get the lenguage *****/
2017-05-07 18:06:34 +02:00
Language = Lan_GetParamLanguage ();
2014-12-01 23:55:08 +01:00
2017-05-31 21:05:59 +02:00
/***** Get the new WWW for the country *****/
2017-03-10 02:40:01 +01:00
Par_GetParToText ("WWW",NewWWW,Cns_MAX_BYTES_WWW);
2014-12-01 23:55:08 +01:00
/***** Get from the database the data of the country *****/
2019-04-08 21:10:12 +02:00
Cty_GetDataOfCountryByCod (Cty_EditingCty,Cty_GET_EXTRA_DATA);
2014-12-01 23:55:08 +01:00
/***** Update the table changing old WWW by new WWW *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the web of a country",
"UPDATE countries SET WWW_%s='%s'"
" WHERE CtyCod='%03ld'",
2019-04-08 21:10:12 +02:00
Lan_STR_LANG_ID[Language],NewWWW,Cty_EditingCty->CtyCod);
Str_Copy (Cty_EditingCty->WWW[Language],NewWWW,
2017-05-31 21:05:59 +02:00
Cns_MAX_BYTES_WWW);
2014-12-01 23:55:08 +01:00
/***** Write message to show the change made *****/
2019-04-08 21:10:12 +02:00
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_The_new_web_address_is_X,
NewWWW);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*********** Change the attribution of the map of current country ************/
/*****************************************************************************/
void Cty_ChangeCtyMapAttribution (void)
{
2019-03-02 21:49:11 +01:00
char NewMapAttribution[Med_MAX_BYTES_ATTRIBUTION + 1];
2014-12-01 23:55:08 +01:00
/***** Get parameters from form *****/
/* Get the new map attribution for the country */
2019-03-02 21:49:11 +01:00
Par_GetParToText ("Attribution",NewMapAttribution,Med_MAX_BYTES_ATTRIBUTION);
2014-12-01 23:55:08 +01:00
/***** Update the table changing old attribution by new attribution *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the map attribution of a country",
"UPDATE countries SET MapAttribution='%s'"
" WHERE CtyCod='%03ld'",
2019-04-03 20:57:04 +02:00
NewMapAttribution,Gbl.Hierarchy.Cty.CtyCod);
2014-12-01 23:55:08 +01:00
/***** Show the country information again *****/
Cty_ShowConfiguration ();
}
2019-04-08 21:10:12 +02:00
/*****************************************************************************/
/********* Show alerts after changing a country and continue editing *********/
/*****************************************************************************/
void Cty_ContEditAfterChgCty (void)
{
/***** Write message to show the change made
and put button to go to country changed *****/
Cty_ShowAlertAndButtonToGoToCty ();
/***** Show the form again *****/
Cty_EditCountriesInternal ();
/***** Country destructor *****/
Cty_EditingCountryDestructor ();
}
/*****************************************************************************/
/***************** Write message to show the change made *******************/
/***************** and put button to go to country changed *******************/
/*****************************************************************************/
static void Cty_ShowAlertAndButtonToGoToCty (void)
{
2019-06-13 10:14:05 +02:00
extern const char *Txt_Go_to_X;
2019-04-08 23:34:58 +02:00
// If the country being edited is different to the current one...
2019-04-08 21:10:12 +02:00
if (Cty_EditingCty->CtyCod != Gbl.Hierarchy.Cty.CtyCod)
{
/***** Alert with button to go to couuntry *****/
2019-06-13 10:14:05 +02:00
snprintf (Gbl.Title,sizeof (Gbl.Title),
Txt_Go_to_X,
Cty_EditingCty->Name[Gbl.Prefs.Language]);
2019-04-08 21:10:12 +02:00
Ale_ShowLastAlertAndButton (ActSeeIns,NULL,NULL,Cty_PutParamGoToCty,
Btn_CONFIRM_BUTTON,Gbl.Title);
}
else
/***** Alert *****/
Ale_ShowAlerts (NULL);
}
static void Cty_PutParamGoToCty (void)
{
/***** Put parameter *****/
Cty_PutParamCtyCod (Cty_EditingCty->CtyCod);
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/********************* Put a form to create a new country ********************/
/*****************************************************************************/
static void Cty_PutFormToCreateCountry (void)
{
extern const char *Txt_New_country;
2018-12-08 16:43:13 +01:00
extern const char *Txt_STR_LANG_NAME[1 + Lan_NUM_LANGUAGES];
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
2014-12-01 23:55:08 +01:00
extern const char *Txt_Create_country;
2018-12-08 16:43:13 +01:00
Lan_Language_t Lan;
2019-11-08 01:10:32 +01:00
char StrCtyCod[Cns_MAX_DECIMAL_DIGITS_LONG + 1];
2019-11-03 18:22:11 +01:00
char StrName[32];
2014-12-01 23:55:08 +01:00
2019-10-20 22:00:28 +02:00
/***** Begin form *****/
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActNewCty);
2014-12-01 23:55:08 +01:00
2019-10-26 02:19:42 +02:00
/***** Begin box and table *****/
2019-11-25 23:18:08 +01:00
Box_BoxTableBegin (NULL,Txt_New_country,NULL,
2017-06-12 15:03:29 +02:00
NULL,Box_NOT_CLOSABLE,2);
2014-12-01 23:55:08 +01:00
/***** Write heading *****/
2017-02-28 00:59:01 +01:00
Cty_PutHeadCountriesForEdition ();
2014-12-01 23:55:08 +01:00
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-05 13:27:58 +02:00
/***** Column to remove country, disabled here *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("rowspan=\"%u\" class=\"BT\"",1 + Lan_NUM_LANGUAGES);
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/***** Numerical country code (ISO 3166-1) *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("rowspan=\"%u\" class=\"RT\"",1 + Lan_NUM_LANGUAGES);
2019-04-08 21:10:12 +02:00
if (Cty_EditingCty->CtyCod > 0)
2019-11-03 18:22:11 +01:00
snprintf (StrCtyCod,sizeof (StrCtyCod),
"%03ld",
Cty_EditingCty->CtyCod);
else
StrCtyCod[0] = '\0';
2019-11-08 01:10:32 +01:00
HTM_INPUT_TEXT ("OthCtyCod",3,StrCtyCod,false,
2019-11-03 18:22:11 +01:00
"size=\"3\" required=\"required\"");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/***** Alphabetic country code with 2 letters (ISO 3166-1) *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("rowspan=\"%u\" class=\"RT\"",1 + Lan_NUM_LANGUAGES);
2019-11-04 12:25:48 +01:00
HTM_INPUT_TEXT ("Alpha2",2,Cty_EditingCty->Alpha2,false,
2019-11-03 18:22:11 +01:00
"size=\"2\" required=\"required\"");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
2019-10-23 19:05:05 +02:00
HTM_TD_Empty (3);
2014-12-01 23:55:08 +01:00
2019-10-05 13:27:58 +02:00
/***** Number of users *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("rowspan=\"%u\" class=\"DAT RT\"",1 + Lan_NUM_LANGUAGES);
2019-11-10 13:51:07 +01:00
HTM_Unsigned (0);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
2019-10-05 13:27:58 +02:00
/***** Number of institutions *****/
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("rowspan=\"%u\" class=\"DAT RT\"",1 + Lan_NUM_LANGUAGES);
2019-11-10 13:51:07 +01:00
HTM_Unsigned (0);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-05 13:27:58 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
/***** Country name in several languages *****/
2019-12-15 01:10:36 +01:00
for (Lan = (Lan_Language_t) 1;
Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES;
2014-12-01 23:55:08 +01:00
Lan++)
{
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-05 13:27:58 +02:00
/* Language */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"DAT RT\"");
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt_STR_LANG_NAME[Lan]);
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* Name */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LM\"");
2019-11-03 18:22:11 +01:00
snprintf (StrName,sizeof (StrName),
"Name_%s",
Lan_STR_LANG_ID[Lan]);
2019-11-04 12:25:48 +01:00
HTM_INPUT_TEXT (StrName,Cty_MAX_CHARS_NAME,Cty_EditingCty->Name[Lan],false,
2019-11-03 18:22:11 +01:00
"size=\"15\" required=\"required\"");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/* WWW */
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"LM\"");
2019-11-04 09:45:57 +01:00
snprintf (StrName,sizeof (StrName),
"WWW_%s",
Lan_STR_LANG_ID[Lan]);
2019-11-04 12:25:48 +01:00
HTM_INPUT_URL (StrName,Cty_EditingCty->WWW[Lan],false,
2019-12-19 11:00:14 +01:00
"class=\"INPUT_WWW_NARROW\" required=\"required\"");
2019-10-23 19:05:05 +02:00
HTM_TD_End ();
2019-10-05 13:27:58 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
}
2017-06-12 14:16:33 +02:00
/***** End table, send button and end box *****/
2019-11-25 23:18:08 +01:00
Box_BoxTableWithButtonEnd (Btn_CREATE_BUTTON,Txt_Create_country);
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** End form *****/
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************* Write header with fields of a country *******************/
/*****************************************************************************/
2017-02-28 00:59:01 +01:00
static void Cty_PutHeadCountriesForEdition (void)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_Numeric_BR_code_BR_ISO_3166_1;
extern const char *Txt_Alphabetic_BR_code_BR_ISO_3166_1;
extern const char *Txt_Name;
extern const char *Txt_WWW;
extern const char *Txt_Users;
2015-12-09 19:51:17 +01:00
extern const char *Txt_Institutions_ABBREVIATION;
2014-12-01 23:55:08 +01:00
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
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);
2019-10-07 00:05:24 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************* Receive form to create a new country ********************/
/*****************************************************************************/
void Cty_RecFormNewCountry (void)
{
extern const char *Txt_You_must_specify_the_numerical_code_of_the_new_country;
extern const char *Txt_The_numerical_code_X_already_exists;
extern const char *Txt_The_alphabetical_code_X_is_not_correct;
extern const char *Txt_The_alphabetical_code_X_already_exists;
2018-12-08 16:43:13 +01:00
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
2014-12-01 23:55:08 +01:00
extern const char *Txt_The_country_X_already_exists;
extern const char *Txt_You_must_specify_the_name_of_the_new_country_in_all_languages;
2019-04-08 21:10:12 +02:00
extern const char *Txt_Created_new_country_X;
2014-12-01 23:55:08 +01:00
char ParamName[32];
bool CreateCountry = true;
2018-12-08 16:43:13 +01:00
Lan_Language_t Lan;
2014-12-01 23:55:08 +01:00
unsigned i;
2019-04-04 11:22:08 +02:00
/***** Country constructoor *****/
2019-04-08 21:10:12 +02:00
Cty_EditingCountryConstructor ();
2014-12-01 23:55:08 +01:00
/***** Get parameters from form *****/
/* Get numeric country code */
2019-04-08 21:10:12 +02:00
if ((Cty_EditingCty->CtyCod = Cty_GetParamOtherCtyCod ()) < 0)
2014-12-01 23:55:08 +01:00
{
2019-04-08 21:10:12 +02:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_You_must_specify_the_numerical_code_of_the_new_country);
2014-12-01 23:55:08 +01:00
CreateCountry = false;
}
2019-04-08 21:10:12 +02:00
else if (Cty_CheckIfNumericCountryCodeExists (Cty_EditingCty->CtyCod))
2014-12-01 23:55:08 +01:00
{
2019-04-08 21:10:12 +02:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_numerical_code_X_already_exists,
Cty_EditingCty->CtyCod);
2014-12-01 23:55:08 +01:00
CreateCountry = false;
}
else // Numeric code correct
{
/* Get alphabetic-2 country code */
2019-04-08 21:10:12 +02:00
Par_GetParToText ("Alpha2",Cty_EditingCty->Alpha2,2);
Str_ConvertToUpperText (Cty_EditingCty->Alpha2);
2014-12-01 23:55:08 +01:00
for (i = 0;
i < 2 && CreateCountry;
i++)
2019-04-08 21:10:12 +02:00
if (Cty_EditingCty->Alpha2[i] < 'A' ||
Cty_EditingCty->Alpha2[i] > 'Z')
2014-12-01 23:55:08 +01:00
{
2019-04-08 21:10:12 +02:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_alphabetical_code_X_is_not_correct,
Cty_EditingCty->Alpha2);
2014-12-01 23:55:08 +01:00
CreateCountry = false;
}
if (CreateCountry)
{
2019-04-08 21:10:12 +02:00
if (Cty_CheckIfAlpha2CountryCodeExists (Cty_EditingCty->Alpha2))
2014-12-01 23:55:08 +01:00
{
2019-04-08 21:10:12 +02:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_alphabetical_code_X_already_exists,
Cty_EditingCty->Alpha2);
2014-12-01 23:55:08 +01:00
CreateCountry = false;
}
else // Alphabetic code correct
{
/* Get country name and WWW in different languages */
2019-12-15 01:10:36 +01:00
for (Lan = (Lan_Language_t) 1;
Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES;
2014-12-01 23:55:08 +01:00
Lan++)
{
2018-10-17 10:32:18 +02:00
snprintf (ParamName,sizeof (ParamName),
"Name_%s",
2018-12-08 16:43:13 +01:00
Lan_STR_LANG_ID[Lan]);
2019-04-08 21:10:12 +02:00
Par_GetParToText (ParamName,Cty_EditingCty->Name[Lan],Cty_MAX_BYTES_NAME);
2014-12-01 23:55:08 +01:00
2019-04-08 21:10:12 +02:00
if (Cty_EditingCty->Name[Lan][0]) // If there's a country name
2014-12-01 23:55:08 +01:00
{
/***** If name of country was in database... *****/
2019-04-08 21:10:12 +02:00
if (Cty_CheckIfCountryNameExists (Lan,Cty_EditingCty->Name[Lan],-1L))
2014-12-01 23:55:08 +01:00
{
2019-04-08 21:10:12 +02:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_country_X_already_exists,
Cty_EditingCty->Name[Lan]);
2014-12-01 23:55:08 +01:00
CreateCountry = false;
break;
}
}
else // If there is not a country name
{
2019-04-08 21:10:12 +02:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_You_must_specify_the_name_of_the_new_country_in_all_languages);
2014-12-01 23:55:08 +01:00
CreateCountry = false;
break;
}
2018-10-17 10:32:18 +02:00
snprintf (ParamName,sizeof (ParamName),
"WWW_%s",
2018-12-08 16:43:13 +01:00
Lan_STR_LANG_ID[Lan]);
2019-04-08 21:10:12 +02:00
Par_GetParToText (ParamName,Cty_EditingCty->WWW[Lan],Cns_MAX_BYTES_WWW);
2014-12-01 23:55:08 +01:00
}
}
}
}
if (CreateCountry)
2019-04-08 21:10:12 +02:00
{
Cty_CreateCountry (); // Add new country to database
Ale_ShowAlert (Ale_SUCCESS,Txt_Created_new_country_X,
Cty_EditingCty->Name);
}
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/**************************** Create a new country ***************************/
/*****************************************************************************/
2018-12-08 16:43:13 +01:00
#define Cty_MAX_BYTES_SUBQUERY_CTYS_NAME ((1 + Lan_NUM_LANGUAGES) * Cty_MAX_BYTES_NAME)
#define Cty_MAX_BYTES_SUBQUERY_CTYS_WWW ((1 + Lan_NUM_LANGUAGES) * Cns_MAX_BYTES_WWW)
2017-01-16 01:51:01 +01:00
2019-04-08 21:10:12 +02:00
static void Cty_CreateCountry (void)
2014-12-01 23:55:08 +01:00
{
2018-12-08 16:43:13 +01:00
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
Lan_Language_t Lan;
2014-12-01 23:55:08 +01:00
char StrField[32];
2017-03-07 11:03:05 +01:00
char SubQueryNam1[Cty_MAX_BYTES_SUBQUERY_CTYS + 1];
char SubQueryNam2[Cty_MAX_BYTES_SUBQUERY_CTYS_NAME + 1];
char SubQueryWWW1[Cty_MAX_BYTES_SUBQUERY_CTYS + 1];
char SubQueryWWW2[Cty_MAX_BYTES_SUBQUERY_CTYS_WWW + 1];
2014-12-01 23:55:08 +01:00
/***** Create a new country *****/
SubQueryNam1[0] = '\0';
SubQueryNam2[0] = '\0';
SubQueryWWW1[0] = '\0';
SubQueryWWW2[0] = '\0';
2019-12-15 01:10:36 +01:00
for (Lan = (Lan_Language_t) 1;
Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES;
2014-12-01 23:55:08 +01:00
Lan++)
{
2018-10-17 10:32:18 +02:00
snprintf (StrField,sizeof (StrField),
",Name_%s",
2018-12-08 16:43:13 +01:00
Lan_STR_LANG_ID[Lan]);
2017-01-17 03:33:05 +01:00
Str_Concat (SubQueryNam1,StrField,
2017-03-07 11:03:05 +01:00
Cty_MAX_BYTES_SUBQUERY_CTYS);
2014-12-01 23:55:08 +01:00
2017-01-17 03:33:05 +01:00
Str_Concat (SubQueryNam2,",'",
2017-03-07 11:03:05 +01:00
Cty_MAX_BYTES_SUBQUERY_CTYS_NAME);
2019-04-08 21:10:12 +02:00
Str_Concat (SubQueryNam2,Cty_EditingCty->Name[Lan],
2017-03-07 11:03:05 +01:00
Cty_MAX_BYTES_SUBQUERY_CTYS_NAME);
2017-01-17 03:33:05 +01:00
Str_Concat (SubQueryNam2,"'",
2017-03-07 11:03:05 +01:00
Cty_MAX_BYTES_SUBQUERY_CTYS_NAME);
2014-12-01 23:55:08 +01:00
2018-10-17 10:32:18 +02:00
snprintf (StrField,sizeof (StrField),
",WWW_%s",
2018-12-08 16:43:13 +01:00
Lan_STR_LANG_ID[Lan]);
2017-01-17 03:33:05 +01:00
Str_Concat (SubQueryWWW1,StrField,
2017-03-07 11:03:05 +01:00
Cty_MAX_BYTES_SUBQUERY_CTYS);
2017-01-17 03:33:05 +01:00
Str_Concat (SubQueryWWW2,",'",
2017-03-07 11:03:05 +01:00
Cty_MAX_BYTES_SUBQUERY_CTYS_WWW);
2019-04-08 21:10:12 +02:00
Str_Concat (SubQueryWWW2,Cty_EditingCty->WWW[Lan],
2017-03-07 11:03:05 +01:00
Cty_MAX_BYTES_SUBQUERY_CTYS_WWW);
2017-01-17 03:33:05 +01:00
Str_Concat (SubQueryWWW2,"'",
2017-03-07 11:03:05 +01:00
Cty_MAX_BYTES_SUBQUERY_CTYS_WWW);
2014-12-01 23:55:08 +01:00
}
2018-11-02 19:37:11 +01:00
DB_QueryINSERT ("can not create country",
"INSERT INTO countries"
2019-04-04 14:48:05 +02:00
" (CtyCod,Alpha2,MapAttribution%s%s)"
2018-11-02 19:37:11 +01:00
" VALUES"
2019-04-04 14:48:05 +02:00
" ('%03ld','%s',''%s%s)",
2018-11-02 19:37:11 +01:00
SubQueryNam1,SubQueryWWW1,
2019-04-08 21:10:12 +02:00
Cty_EditingCty->CtyCod,Cty_EditingCty->Alpha2,
SubQueryNam2,SubQueryWWW2);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*********************** Get total number of countries ***********************/
/*****************************************************************************/
unsigned Cty_GetNumCtysTotal (void)
{
2018-11-03 13:13:11 +01:00
/***** Get total number of countries from database *****/
2018-11-04 20:51:38 +01:00
return (unsigned) DB_GetNumRowsTable ("countries");
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/***************** Get number of countries with institutions *****************/
/*****************************************************************************/
unsigned Cty_GetNumCtysWithInss (const char *SubQuery)
{
/***** Get number of countries with institutions from database *****/
2018-11-03 13:13:11 +01:00
return
(unsigned) DB_QueryCOUNT ("can not get number of countries"
" with institutions",
"SELECT COUNT(DISTINCT countries.CtyCod)"
" FROM countries,institutions"
" WHERE %scountries.CtyCod=institutions.CtyCod",
SubQuery);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************* Get number of countries with centres ********************/
/*****************************************************************************/
unsigned Cty_GetNumCtysWithCtrs (const char *SubQuery)
{
/***** Get number of countries with centres from database *****/
2018-11-03 13:13:11 +01:00
return
(unsigned) DB_QueryCOUNT ("can not get number of countries with centres",
"SELECT COUNT(DISTINCT countries.CtyCod)"
" FROM countries,institutions,centres"
" WHERE %scountries.CtyCod=institutions.CtyCod"
" AND institutions.InsCod=centres.InsCod",
SubQuery);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************* Get number of countries with degrees ********************/
/*****************************************************************************/
unsigned Cty_GetNumCtysWithDegs (const char *SubQuery)
{
/***** Get number of countries with degrees from database *****/
2018-11-03 13:13:11 +01:00
return
(unsigned) DB_QueryCOUNT ("can not get number of countries with degrees",
"SELECT COUNT(DISTINCT countries.CtyCod)"
" FROM countries,institutions,centres,degrees"
" WHERE %scountries.CtyCod=institutions.CtyCod"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod",
SubQuery);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************* Get number of countries with courses ********************/
/*****************************************************************************/
unsigned Cty_GetNumCtysWithCrss (const char *SubQuery)
{
/***** Get number of countries with courses from database *****/
2018-11-03 13:13:11 +01:00
return
(unsigned) DB_QueryCOUNT ("can not get number of countries with courses",
"SELECT COUNT(DISTINCT countries.CtyCod)"
" FROM countries,institutions,centres,degrees,courses"
" WHERE %scountries.CtyCod=institutions.CtyCod"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod",
SubQuery);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************* Get number of countries with users **********************/
/*****************************************************************************/
unsigned Cty_GetNumCtysWithUsrs (Rol_Role_t Role,const char *SubQuery)
{
/***** Get number of countries with users from database *****/
2018-11-03 13:13:11 +01:00
return
(unsigned) DB_QueryCOUNT ("can not get number of countries with users",
"SELECT COUNT(DISTINCT countries.CtyCod)"
" FROM countries,institutions,centres,degrees,courses,crs_usr"
" WHERE %scountries.CtyCod=institutions.CtyCod"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.Role=%u",
SubQuery,(unsigned) Role);
2014-12-01 23:55:08 +01:00
}
2017-02-28 00:59:01 +01:00
/*****************************************************************************/
/***************************** List countries found **************************/
/*****************************************************************************/
2018-10-30 14:47:31 +01:00
void Cty_ListCtysFound (MYSQL_RES **mysql_res,unsigned NumCtys)
2017-02-28 00:59:01 +01:00
{
extern const char *Txt_country;
extern const char *Txt_countries;
MYSQL_ROW row;
unsigned NumCty;
struct Country Cty;
/***** Query database *****/
2018-10-30 14:47:31 +01:00
if (NumCtys)
2017-02-28 00:59:01 +01:00
{
2019-10-26 02:19:42 +02:00
/***** Begin box and table *****/
2017-02-28 00:59:01 +01:00
/* Number of countries found */
2018-10-17 10:32:18 +02:00
snprintf (Gbl.Title,sizeof (Gbl.Title),
"%u %s",
NumCtys,NumCtys == 1 ? Txt_country :
Txt_countries);
2019-11-25 23:18:08 +01:00
Box_BoxTableBegin (NULL,Gbl.Title,NULL,
2017-06-12 15:03:29 +02:00
NULL,Box_NOT_CLOSABLE,2);
2017-06-12 14:16:33 +02:00
/***** Write heading *****/
2017-02-28 00:59:01 +01:00
Cty_PutHeadCountriesForSeeing (false); // Order not selectable
/***** List the countries (one row per country) *****/
for (NumCty = 1;
NumCty <= NumCtys;
NumCty++)
{
/* Get next country */
2018-10-30 14:47:31 +01:00
row = mysql_fetch_row (*mysql_res);
2017-02-28 00:59:01 +01:00
/* Get country code (row[0]) */
Cty.CtyCod = Str_ConvertStrCodToLongCod (row[0]);
/* Get data of country */
Cty_GetDataOfCountryByCod (&Cty,Cty_GET_EXTRA_DATA);
/* Write data of this country */
Cty_ListOneCountryForSeeing (&Cty,NumCty);
}
2017-06-12 14:16:33 +02:00
/***** End table and box *****/
2019-11-25 23:18:08 +01:00
Box_BoxTableEnd ();
2017-02-28 00:59:01 +01:00
}
/***** Free structure that stores the query result *****/
2018-10-30 14:47:31 +01:00
DB_FreeMySQLResult (mysql_res);
2017-02-28 00:59:01 +01:00
}
2019-04-04 11:22:08 +02:00
/*****************************************************************************/
/*********************** Country constructor/destructor **********************/
/*****************************************************************************/
2019-04-08 21:10:12 +02:00
static void Cty_EditingCountryConstructor (void)
2019-04-04 11:22:08 +02:00
{
Lan_Language_t Lan;
2019-04-08 21:10:12 +02:00
/***** Pointer must be NULL *****/
if (Cty_EditingCty != NULL)
Lay_ShowErrorAndExit ("Error initializing country.");
2019-04-04 11:22:08 +02:00
/***** Allocate memory for country *****/
2019-04-08 21:10:12 +02:00
if ((Cty_EditingCty = (struct Country *) malloc (sizeof (struct Country))) == NULL)
2019-04-04 11:22:08 +02:00
Lay_ShowErrorAndExit ("Error allocating memory for country.");
/***** Reset country *****/
2019-04-08 21:10:12 +02:00
Cty_EditingCty->CtyCod = -1L;
Cty_EditingCty->Alpha2[0] = '\0';
2019-12-15 01:10:36 +01:00
for (Lan = (Lan_Language_t) 1;
Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES;
2019-04-04 11:22:08 +02:00
Lan++)
2019-04-04 14:48:05 +02:00
{
2019-04-08 21:10:12 +02:00
Cty_EditingCty->Name[Lan][0] = '\0';
Cty_EditingCty->WWW [Lan][0] = '\0';
2019-04-04 14:48:05 +02:00
}
2019-04-08 21:10:12 +02:00
Cty_EditingCty->Inss.Num = 0;
Cty_EditingCty->Inss.Lst = NULL;
Cty_EditingCty->Inss.SelectedOrder = Ins_ORDER_DEFAULT;
Cty_EditingCty->NumCtrs = 0;
Cty_EditingCty->NumDegs = 0;
Cty_EditingCty->NumCrss = 0;
Cty_EditingCty->NumUsrs = 0;
Cty_EditingCty->NumUsrsWhoClaimToBelongToCty = 0;
2019-04-04 11:22:08 +02:00
}
2019-04-08 21:10:12 +02:00
static void Cty_EditingCountryDestructor (void)
2019-04-04 11:22:08 +02:00
{
/***** Free memory used for country *****/
2019-04-08 21:10:12 +02:00
if (Cty_EditingCty != NULL)
2019-04-04 11:22:08 +02:00
{
2019-11-06 19:45:20 +01:00
free (Cty_EditingCty);
2019-04-08 21:10:12 +02:00
Cty_EditingCty = NULL;
2019-04-04 11:22:08 +02:00
}
}