swad-core/swad_country.c

1891 lines
63 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.
2021-02-09 12:43:45 +01:00
Copyright (C) 1999-2021 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
2019-12-29 19:07:59 +01:00
#include <stdbool.h> // For boolean type
2019-12-29 12:39:00 +01:00
#include <stddef.h> // For NULL
2018-10-20 01:07:58 +02:00
#include <stdio.h> // For asprintf
2020-01-03 22:16:51 +01:00
#include <stdlib.h> // For free
2014-12-01 23:55:08 +01:00
#include <string.h> // For string functions
2019-12-29 19:07:59 +01:00
#include "swad_country_config.h"
#include "swad_country_database.h"
2014-12-01 23:55:08 +01:00
#include "swad_database.h"
#include "swad_error.h"
2020-04-14 17:15:17 +02:00
#include "swad_figure.h"
2020-05-02 13:39:59 +02:00
#include "swad_figure_cache.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"
2021-02-11 22:57:09 +01:00
#include "swad_hierarchy.h"
#include "swad_hierarchy_level.h"
2019-10-23 19:05:05 +02:00
#include "swad_HTML.h"
2020-04-14 17:15:17 +02:00
#include "swad_survey.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 *****************************/
/*****************************************************************************/
2021-02-11 22:57:09 +01:00
static struct Cty_Countr *Cty_EditingCty = NULL; // Static variable to keep the country being edited
2019-12-23 22:13:02 +01:00
long Cty_CurrentCtyCod = -1L; // Used as parameter in contextual links
2019-04-08 21:10:12 +02:00
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
2017-02-28 00:59:01 +01:00
static void Cty_PutHeadCountriesForSeeing (bool OrderSelectable);
2021-02-11 22:57:09 +01:00
static void Cty_ListOneCountryForSeeing (struct Cty_Countr *Cty,unsigned NumCty);
2017-02-28 00:59:01 +01:00
2020-04-08 13:40:21 +02:00
static void Cty_PutIconsListingCountries (__attribute__((unused)) void *Args);
2016-03-16 22:40:35 +01:00
static void Cty_PutIconToEditCountries (void);
2016-03-16 12:11:59 +01:00
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);
2020-04-08 13:40:21 +02:00
static void Cty_PutIconsEditingCountries (__attribute__((unused)) void *Args);
2017-04-30 20:20:25 +02:00
static void Cty_PutIconToViewCountries (void);
2014-12-01 23:55:08 +01:00
static void Cty_ListCountriesForEdition (void);
2020-10-13 22:34:31 +02:00
static void Cty_PutParamOtherCtyCod (void *CtyCod);
2016-10-23 19:40:14 +02:00
static long Cty_GetParamOtherCtyCod (void);
static void Cty_UpdateCtyName (long CtyCod,const char *FieldName,const char *NewCtyName);
2017-03-10 02:40:01 +01:00
2019-04-08 21:10:12 +02:00
static void Cty_ShowAlertAndButtonToGoToCty (void);
2020-04-08 13:40:21 +02:00
static void Cty_PutParamGoToCty (void *CtyCod);
2019-04-08 21:10:12 +02:00
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);
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
2021-02-11 22:57:09 +01:00
static void Cty_FormToGoToMap (struct Cty_Countr *Cty);
2020-01-14 13:30:18 +01:00
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/***************** List countries with pending institutions ******************/
/*****************************************************************************/
void Cty_SeeCtyWithPendingInss (void)
{
2020-01-30 20:47:00 +01:00
extern const char *Hlp_SYSTEM_Pending;
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;
2021-02-11 22:57:09 +01:00
struct Cty_Countr Cty;
2015-09-04 19:26:08 +02:00
const char *BgColor;
2014-12-01 23:55:08 +01:00
/***** Trivial check: only system admins can see 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:
2014-12-01 23:55:08 +01:00
break;
default: // Forbidden for other users
return;
}
/***** Get countries with pending institutions *****/
if ((NumCtys = Cty_DB_GetCtysWithPendingInss (&mysql_res)))
2014-12-01 23:55:08 +01:00
{
2019-10-26 02:19:42 +02:00
/***** Begin box and table *****/
2020-03-26 02:54:30 +01:00
Box_BoxTableBegin (NULL,Txt_Countries_with_pending_institutions,
NULL,NULL,
2020-01-30 20:47:00 +01:00
Hlp_SYSTEM_Pending,Box_NOT_CLOSABLE,2);
2017-06-12 14:16:33 +02:00
/***** Write heading *****/
HTM_TR_Begin (NULL);
HTM_TH (1,1,"LM",Txt_Country);
HTM_TH (1,1,"RM",Txt_Institutions_ABBREVIATION);
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
/***** List the countries *****/
for (NumCty = 0;
NumCty < NumCtys;
NumCty++, Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd)
{
/* Get next country */
row = mysql_fetch_row (mysql_res);
/* Get country code (row[0]) */
Cty.CtyCod = Str_ConvertStrCodToLongCod (row[0]);
BgColor = (Cty.CtyCod == Gbl.Hierarchy.Cty.CtyCod) ? "LIGHT_BLUE" :
Gbl.ColorRows[Gbl.RowEvenOdd];
/* Get data of country */
Cty_GetDataOfCountryByCod (&Cty);
/* Begin row for this country */
HTM_TR_Begin (NULL);
/* Country map */
HTM_TD_Begin ("class=\"LM %s\"",BgColor);
Cty_DrawCountryMapAndNameWithLink (&Cty,ActSeeIns,
"COUNTRY_SMALL",
"COUNTRY_MAP_SMALL",
"BT_LINK DAT");
HTM_TD_End ();
/* Number of pending institutions (row[1]) */
HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor);
HTM_Txt (row[1]);
HTM_TD_End ();
/* End row for this country */
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
}
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);
}
/*****************************************************************************/
/*************************** 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 *****/
2020-01-07 22:07:06 +01:00
Cty_GetFullListOfCountries ();
2014-12-01 23:55:08 +01:00
}
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 *****/
2020-03-26 02:54:30 +01:00
Box_BoxTableBegin (NULL,Txt_Countries,
2020-04-08 13:40:21 +02:00
Cty_PutIconsListingCountries,NULL,
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 *****/
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;
NumCty < Gbl.Hierarchy.Ctys.Num;
NumCty++)
Cty_ListOneCountryForSeeing (&Gbl.Hierarchy.Ctys.Lst[NumCty],NumCty + 1);
2014-12-01 23:55:08 +01:00
/***** Separation row *****/
HTM_TR_Begin (NULL);
HTM_TD_Begin ("colspan=\"8\" class=\"DAT CM\"");
HTM_NBSP ();
HTM_TD_End ();
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
/***** Write users and institutions in other countries *****/
HTM_TR_Begin (NULL);
2019-10-07 00:05:24 +02:00
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_TD_End ();
HTM_TD_Begin ("class=\"DAT LM\"");
HTM_Txt (Txt_Other_countries);
HTM_TD_End ();
/* Number of users who claim to belong to another country */
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Unsigned (Usr_GetCachedNumUsrsWhoClaimToBelongToAnotherCty ());
HTM_TD_End ();
/* Number of institutions in other countries */
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Unsigned (Ins_GetCachedNumInssInCty (0));
HTM_TD_End ();
/* Number of centers in other countries */
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Unsigned (Ctr_GetCachedNumCtrsInCty (0));
HTM_TD_End ();
/* Number of degrees in other countries */
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Unsigned (Deg_GetCachedNumDegsInCty (0));
HTM_TD_End ();
/* Number of courses in other countries */
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Unsigned (Crs_GetCachedNumCrssInCty (0));
HTM_TD_End ();
/* Number of users in courses of other countries */
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Unsigned (Usr_GetCachedNumUsrsInCrss (HieLvl_CTY,0,
1 << Rol_STD |
1 << Rol_NET |
1 << Rol_TCH)); // Any user
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
HTM_TR_End ();
2015-11-17 01:22:57 +01:00
/***** Write users and institutions with unknown country *****/
HTM_TR_Begin (NULL);
2019-10-07 00:05:24 +02:00
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
HTM_TD_Begin ("class=\"DAT LM\"");
HTM_Txt (Txt_Country_unspecified);
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
/* Number of users who do not claim to belong to any country */
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Unsigned (Usr_GetCachedNumUsrsWhoDontClaimToBelongToAnyCty ());
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
/* Number of institutions with unknown country */
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Unsigned (Ins_GetCachedNumInssInCty (-1L));
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
/* Number of centers with unknown country */
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Unsigned (Ctr_GetCachedNumCtrsInCty (-1L));
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
/* Number of degrees with unknown country */
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Unsigned (Deg_GetCachedNumDegsInCty (-1L));
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
/* Number of courses with unknown country */
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Unsigned (Crs_GetCachedNumCrssInCty (-1L));
HTM_TD_End ();
2019-10-07 00:05:24 +02:00
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Unsigned (0);
HTM_TD_End ();
2019-10-07 00:05:24 +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_Centers_ABBREVIATION;
2017-02-28 00:59:01 +01:00
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
HTM_TH_Empty (1);
for (Order = Cty_ORDER_BY_COUNTRY;
Order <= Cty_ORDER_BY_NUM_USRS;
Order++)
2017-02-28 00:59:01 +01:00
{
HTM_TH_Begin (1,1,Order == Cty_ORDER_BY_COUNTRY ? "LM" :
"RM");
if (OrderSelectable)
{
Frm_BeginForm (ActSeeCty);
Par_PutHiddenParamUnsigned (NULL,"Order",(unsigned) Order);
HTM_BUTTON_SUBMIT_Begin (Txt_COUNTRIES_HELP_ORDER[Order],"BT_LINK TIT_TBL",NULL);
if (Order == Gbl.Hierarchy.Ctys.SelectedOrder)
HTM_U_Begin ();
}
HTM_Txt (Txt_COUNTRIES_ORDER[Order]);
if (OrderSelectable)
{
if (Order == Gbl.Hierarchy.Ctys.SelectedOrder)
HTM_U_End ();
HTM_BUTTON_End ();
Frm_EndForm ();
}
HTM_TH_End ();
2017-02-28 00:59:01 +01:00
}
2019-10-11 09:09:19 +02:00
HTM_TH (1,1,"RM",Txt_Institutions_ABBREVIATION);
HTM_TH (1,1,"RM",Txt_Centers_ABBREVIATION);
HTM_TH (1,1,"RM",Txt_Degrees_ABBREVIATION);
HTM_TH (1,1,"RM",Txt_Courses_ABBREVIATION);
HTM_TH_Begin (1,1,"RM");
HTM_TxtF ("%s+",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH]);
HTM_BR ();
HTM_Txt (Txt_ROLES_PLURAL_BRIEF_Abc[Rol_STD]);
HTM_TH_End ();
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 ************************/
/*****************************************************************************/
2021-02-11 22:57:09 +01:00
static void Cty_ListOneCountryForSeeing (struct Cty_Countr *Cty,unsigned NumCty)
2017-02-28 00:59:01 +01:00
{
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 *****/
HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor);
HTM_Unsigned (NumCty);
HTM_TD_End ();
/***** Country map (and link to WWW if exists) *****/
HTM_TD_Begin ("class=\"LM %s\"",BgColor);
Cty_DrawCountryMapAndNameWithLink (Cty,ActSeeIns,
"COUNTRY_SMALL",
"COUNTRY_MAP_SMALL",
"BT_LINK DAT_N");
HTM_TD_End ();
/***** Number of users who claim to belong to this country *****/
HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor);
HTM_Unsigned (Usr_GetCachedNumUsrsWhoClaimToBelongToCty (Cty));
HTM_TD_End ();
/***** Number of institutions *****/
HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor);
HTM_Unsigned (Ins_GetCachedNumInssInCty (Cty->CtyCod));
HTM_TD_End ();
/***** Number of centers *****/
HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor);
HTM_Unsigned (Ctr_GetCachedNumCtrsInCty (Cty->CtyCod));
HTM_TD_End ();
/***** Number of degrees *****/
HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor);
HTM_Unsigned (Deg_GetCachedNumDegsInCty (Cty->CtyCod));
HTM_TD_End ();
/***** Number of courses *****/
HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor);
HTM_Unsigned (Crs_GetCachedNumCrssInCty (Cty->CtyCod));
HTM_TD_End ();
/***** Number of users in courses *****/
HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor);
HTM_Unsigned (Usr_GetCachedNumUsrsInCrss (HieLvl_CTY,Cty->CtyCod,
1 << Rol_STD |
1 << Rol_NET |
1 << Rol_TCH)); // Any user
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 21:19:25 +01:00
/*****************************************************************************/
/***************** Put contextual icons in list of countries *****************/
/*****************************************************************************/
2020-04-08 13:40:21 +02:00
static void Cty_PutIconsListingCountries (__attribute__((unused)) void *Args)
2016-11-06 21:19:25 +01:00
{
2020-04-08 13:40:21 +02:00
/***** Put icon to edit countries *****/
if (Cty_CheckIfICanEditCountries ())
Cty_PutIconToEditCountries ();
2016-11-06 21:19:25 +01:00
2020-04-08 13:40:21 +02:00
/***** Put icon to show a figure *****/
Fig_PutIconToShowFigure (Fig_HIERARCHY);
2016-11-06 21:19:25 +01:00
}
2019-12-29 19:07:59 +01:00
/*****************************************************************************/
/********************** Check if I can edit countries ************************/
/*****************************************************************************/
bool Cty_CheckIfICanEditCountries (void)
{
return (bool) (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM);
}
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
{
2020-03-26 02:54:30 +01:00
Ico_PutContextualIconToEdit (ActEdiCty,NULL,
NULL,NULL);
2016-03-16 12:11:59 +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
/*****************************************************************************/
2021-02-11 22:57:09 +01:00
void Cty_DrawCountryMapAndNameWithLink (struct Cty_Countr *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
{
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 *****/
Frm_BeginFormGoTo (Action);
2015-11-11 21:14:33 +01:00
Cty_PutParamCtyCod (Cty->CtyCod);
/***** Begin container *****/
HTM_DIV_Begin ("class=\"%s\"",ClassContainer);
2015-11-11 21:14:33 +01:00
/***** Link to action *****/
HTM_BUTTON_SUBMIT_Begin (Hie_BuildGoToMsg (Cty->Name[Gbl.Prefs.Language]),
ClassLink,NULL);
Hie_FreeGoToMsg ();
/***** Draw country map *****/
Cty_DrawCountryMap (Cty,ClassMap);
/***** Write country name *****/
Str_Copy (CountryName,Cty->Name[Gbl.Prefs.Language],sizeof (CountryName) - 1);
HTM_TxtF ("&nbsp;%s&nbsp;",CountryName);
HTM_TxtF ("(%s)",Cty->Alpha2);
2015-11-11 21:14:33 +01:00
/***** End link *****/
HTM_BUTTON_End ();
2019-10-28 13:56:04 +01:00
/***** End container *****/
HTM_DIV_End ();
2015-11-11 21:14:33 +01:00
/***** End form *****/
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2020-01-14 13:30:18 +01:00
/***** Map *****/
Cty_FormToGoToMap (Cty);
2015-01-16 22:02:21 +01:00
}
/*****************************************************************************/
/***************************** Draw country map ******************************/
2015-01-16 01:28:42 +01:00
/*****************************************************************************/
2021-02-11 22:57:09 +01:00
void Cty_DrawCountryMap (struct Cty_Countr *Cty,const char *Class)
2015-01-16 01:28:42 +01:00
{
2019-10-30 22:31:03 +01:00
char *URL;
2015-01-16 01:28:42 +01:00
/***** Draw country map *****/
2020-01-03 21:15:54 +01:00
if (Cty_CheckIfCountryPhotoExists (Cty))
2019-10-30 22:31:03 +01:00
{
if (asprintf (&URL,"%s/%s",
Cfg_URL_ICON_COUNTRIES_PUBLIC,
Cty->Alpha2) < 0)
Err_NotEnoughMemoryExit ();
2019-12-30 21:47:07 +01:00
HTM_IMG (URL,Str_BuildStringStr ("%s.png",Cty->Alpha2),
Cty->Name[Gbl.Prefs.Language],
2019-10-30 22:31:03 +01:00
"class=\"%s\"",Class);
2019-12-30 21:47:07 +01:00
Str_FreeString ();
2019-11-06 19:45:20 +01:00
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 *************************/
/*****************************************************************************/
2021-02-11 22:57:09 +01:00
bool Cty_CheckIfCountryPhotoExists (struct Cty_Countr *Cty)
2015-11-11 21:14:33 +01:00
{
2017-01-28 15:58:46 +01:00
char PathMap[PATH_MAX + 1];
2015-11-11 21:14:33 +01:00
snprintf (PathMap,sizeof (PathMap),"%s/%s/%s.png",
2019-03-20 01:36:36 +01:00
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;
2020-05-03 20:58:03 +02:00
unsigned NumUsrsCty;
unsigned NumInss;
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);
HTM_TxtF (" google.load('visualization', '1', {'packages': ['geochart']});\n"
" google.setOnLoadCallback(drawRegionsMap);\n"
" function drawRegionsMap() {\n"
" var data = new google.visualization.DataTable();\n"
" data.addColumn('string', '%s');\n"
" data.addColumn('number', '%s');\n"
" data.addColumn('number', '%s');\n"
" data.addRows([\n",
Txt_Country_NO_HTML,
Txt_Users_NO_HTML,
Txt_Institutions_NO_HTML);
/***** Write all the countries and their number of users and institutions *****/
for (NumCty = 0;
NumCty < Gbl.Hierarchy.Ctys.Num;
NumCty++)
{
NumUsrsCty = Usr_GetCachedNumUsrsWhoClaimToBelongToCty (&Gbl.Hierarchy.Ctys.Lst[NumCty]);
if (NumUsrsCty)
{
NumInss = Ins_GetCachedNumInssInCty (Gbl.Hierarchy.Ctys.Lst[NumCty].CtyCod);
/* Write data of this country */
HTM_TxtF (" ['%s', %u, %u],\n",
Gbl.Hierarchy.Ctys.Lst[NumCty].Alpha2,NumUsrsCty,NumInss);
if (NumUsrsCty > MaxUsrsInCountry)
MaxUsrsInCountry = NumUsrsCty;
NumCtysWithUsrs++;
}
}
2014-12-01 23:55:08 +01:00
/***** Write end of the script *****/
HTM_TxtF (" ]);\n"
" var options = {\n"
" width:600,\n"
" height:360,\n"
" backgroundColor:'white',\n"
" datalessRegionColor:'white',\n"
" colorAxis:{colors:['#EAF1F4','#4D88A1'],minValue:0,maxValue:%u}};\n"
" var chart = new google.visualization.GeoChart(document.getElementById('chart_div'));\n"
" chart.draw(data, options);\n"
" };\n",
NumCtysWithUsrs ? MaxUsrsInCountry :
0);
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
{
2020-01-08 14:04:25 +01:00
Gbl.Hierarchy.Ctys.SelectedOrder = (Cty_Order_t)
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 *****/
2020-01-08 14:04:25 +01:00
Gbl.Hierarchy.Ctys.SelectedOrder = Cty_ORDER_BY_COUNTRY;
2020-01-07 22:07:06 +01:00
Cty_GetFullListOfCountries ();
2014-12-01 23:55:08 +01:00
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 *****/
2020-03-26 02:54:30 +01:00
Box_BoxBegin (NULL,Txt_Countries,
2020-04-08 13:40:21 +02:00
Cty_PutIconsEditingCountries,NULL,
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 ();
2014-12-01 23:55:08 +01:00
/***** Forms to edit current countries *****/
if (Gbl.Hierarchy.Ctys.Num)
Cty_ListCountriesForEdition ();
2014-12-01 23:55:08 +01:00
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 ****************/
/*****************************************************************************/
2020-04-08 13:40:21 +02:00
static void Cty_PutIconsEditingCountries (__attribute__((unused)) void *Args)
2018-11-15 22:33:21 +01:00
{
2020-04-08 13:40:21 +02:00
/***** Put icon to view countries *****/
Cty_PutIconToViewCountries ();
2018-11-15 22:33:21 +01:00
2020-04-08 13:40:21 +02:00
/***** Put icon to show a figure *****/
Fig_PutIconToShowFigure (Fig_HIERARCHY);
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;
2020-03-26 02:54:30 +01:00
Lay_PutContextualLinkOnlyIcon (ActSeeCty,NULL,
NULL,NULL,
2019-01-12 03:00:59 +01:00
"globe.svg",
Txt_Countries);
2017-04-30 20:20:25 +02:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2020-01-07 22:07:06 +01:00
/********** Get basic list of countries ordered by name of country ***********/
/*****************************************************************************/
void Cty_GetBasicListOfCountries (void)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumCty;
2021-02-11 22:57:09 +01:00
struct Cty_Countr *Cty;
2020-01-07 22:07:06 +01:00
Lan_Language_t Lan;
/***** Trivial check: if list is already got, nothing to do *****/
if (Gbl.Hierarchy.Ctys.Num)
return;
2020-01-07 22:07:06 +01:00
/***** Get countries from database *****/
if ((Gbl.Hierarchy.Ctys.Num = Cty_DB_GetCtysBasic (&mysql_res))) // Countries found...
2020-01-07 22:07:06 +01:00
{
/***** Create list with countries *****/
if ((Gbl.Hierarchy.Ctys.Lst = calloc ((size_t) Gbl.Hierarchy.Ctys.Num,
sizeof (*Gbl.Hierarchy.Ctys.Lst))) == NULL)
Err_NotEnoughMemoryExit ();
2020-01-07 22:07:06 +01:00
/***** Get the countries *****/
for (NumCty = 0;
2020-01-08 14:04:25 +01:00
NumCty < Gbl.Hierarchy.Ctys.Num;
2020-01-07 22:07:06 +01:00
NumCty++)
{
2020-01-08 14:04:25 +01:00
Cty = &(Gbl.Hierarchy.Ctys.Lst[NumCty]);
2020-01-07 22:07:06 +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)
Err_WrongCountrExit ();
2020-01-07 22:07:06 +01:00
/* Reset names and webs */
2020-01-07 22:07:06 +01:00
for (Lan = (Lan_Language_t) 1;
Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES;
Lan++)
{
Cty->Name[Lan][0] = '\0';
Cty->WWW[Lan][0] = '\0';
}
/* Get the name of the country in current language */
Str_Copy (Cty->Name[Gbl.Prefs.Language],row[1],
sizeof (Cty->Name[Gbl.Prefs.Language]) - 1);
2020-01-07 22:07:06 +01:00
2020-01-08 00:47:10 +01:00
/* Reset number of users who claim to belong to country */
2020-01-07 22:07:06 +01:00
Cty->NumUsrsWhoClaimToBelongToCty.Valid = false;
}
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/********** Get full list of countries with names in all languages ***********/
/********** and number of users who claim to belong to them ***********/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2020-01-07 22:07:06 +01:00
void Cty_GetFullListOfCountries (void)
2014-12-01 23:55:08 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumCty;
2021-02-11 22:57:09 +01:00
struct Cty_Countr *Cty;
2018-12-08 16:43:13 +01:00
Lan_Language_t Lan;
2014-12-01 23:55:08 +01:00
/***** Trivial check: if list is already got, nothing to do *****/
if (Gbl.Hierarchy.Ctys.Num)
return;
2018-10-30 14:47:31 +01:00
/***** Get countries from database *****/
if ((Gbl.Hierarchy.Ctys.Num = Cty_DB_GetCtysFull (&mysql_res))) // Countries found...
2014-12-01 23:55:08 +01:00
{
/***** Create list with countries *****/
if ((Gbl.Hierarchy.Ctys.Lst = calloc ((size_t) Gbl.Hierarchy.Ctys.Num,
sizeof (*Gbl.Hierarchy.Ctys.Lst))) == NULL)
Err_NotEnoughMemoryExit ();
2014-12-01 23:55:08 +01:00
/***** Get the countries *****/
for (NumCty = 0;
2020-01-08 14:04:25 +01:00
NumCty < Gbl.Hierarchy.Ctys.Num;
2014-12-01 23:55:08 +01:00
NumCty++)
{
2020-01-08 14:04:25 +01:00
Cty = &(Gbl.Hierarchy.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)
Err_WrongCountrExit ();
2014-12-01 23:55:08 +01:00
/* Get Alpha-2 country code (row[1]) */
Str_Copy (Cty->Alpha2,row[1],sizeof (Cty->Alpha2) - 1);
2014-12-01 23:55:08 +01:00
2020-01-07 22:07:06 +01:00
/* Get the name of the country in several languages */
for (Lan = (Lan_Language_t) 1;
Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES;
Lan++)
{
Str_Copy (Cty->Name[Lan],row[1 + Lan],
sizeof (Cty->Name[Lan]) - 1);
2020-01-07 22:07:06 +01:00
Str_Copy (Cty->WWW[Lan],row[1 + Lan_NUM_LANGUAGES + Lan],
sizeof (Cty->WWW[Lan]) - 1);
2020-01-07 22:07:06 +01:00
}
/* Get number of users who claim to belong to this country */
2020-01-08 00:47:10 +01:00
Cty->NumUsrsWhoClaimToBelongToCty.Valid = false;
2020-01-07 22:07:06 +01:00
if (sscanf (row[1 + Lan_NUM_LANGUAGES * 2 + 1],"%u",
&(Cty->NumUsrsWhoClaimToBelongToCty.NumUsrs)) == 1)
Cty->NumUsrsWhoClaimToBelongToCty.Valid = true;
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;
unsigned NumCty;
/***** Get list of countries *****/
Cty_GetBasicListOfCountries ();
2014-12-01 23:55:08 +01:00
2019-10-20 22:00:28 +02:00
/***** Begin form *****/
Frm_BeginFormGoTo (ActSeeIns);
2014-12-01 23:55:08 +01:00
/***** Begin selector of country *****/
HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE,
"id=\"cty\" name=\"cty\" class=\"HIE_SEL\"");
2014-12-01 23:55:08 +01:00
/***** Initial disabled option *****/
HTM_OPTION (HTM_Type_STRING,"",Gbl.Hierarchy.Cty.CtyCod < 0,true,
"[%s]",Txt_Country);
2014-12-01 23:55:08 +01:00
/***** List countries *****/
for (NumCty = 0;
NumCty < Gbl.Hierarchy.Ctys.Num;
NumCty++)
HTM_OPTION (HTM_Type_LONG,&Gbl.Hierarchy.Ctys.Lst[NumCty].CtyCod,
Gbl.Hierarchy.Ctys.Lst[NumCty].CtyCod == Gbl.Hierarchy.Cty.CtyCod,false,
"%s",Gbl.Hierarchy.Ctys.Lst[NumCty].Name[Gbl.Prefs.Language]);
2014-12-01 23:55:08 +01:00
/***** End selector of country *****/
HTM_SELECT_End ();
2014-12-01 23:55:08 +01:00
/***** End form *****/
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
// Do not free list of countries here, because it can be reused
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-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 *****/
2020-01-07 22:07:06 +01:00
Cty_GetCountryName (CtyCod,Gbl.Prefs.Language,CtyName);
2015-12-08 00:25:56 +01:00
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 *****/
Frm_BeginForm (ActSeeCtyInf);
2015-12-15 01:33:09 +01:00
Cty_PutParamCtyCod (CtyCod);
HTM_BUTTON_SUBMIT_Begin (Act_GetActionText (ActSeeCtyInf),ClassLink,NULL);
HTM_Txt (CtyName);
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
/*****************************************************************************/
2021-02-11 22:57:09 +01:00
bool Cty_GetDataOfCountryByCod (struct Cty_Countr *Cty)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_Another_country;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
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';
}
2020-01-07 13:14:42 +01:00
Cty->NumUsrsWhoClaimToBelongToCty.Valid = false;
2014-12-01 23:55:08 +01:00
/***** 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,
sizeof (Cty->Name[Lan]) - 1);
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 *****/
CtyFound = (Cty_DB_GetDataOfCountryByCod (&mysql_res,Cty->CtyCod) != 0);
if (CtyFound) // Country found...
2014-12-01 23:55:08 +01:00
{
/* Get row */
row = mysql_fetch_row (mysql_res);
/* Get Alpha-2 country code (row[0]) */
Str_Copy (Cty->Alpha2,row[0],sizeof (Cty->Alpha2) - 1);
2014-12-01 23:55:08 +01:00
2020-01-07 22:07:06 +01:00
/* Get name and WWW of the country in current language */
Str_Copy (Cty->Name[Gbl.Prefs.Language],row[1],
sizeof (Cty->Name[Gbl.Prefs.Language]) - 1);
2020-01-07 22:07:06 +01:00
Str_Copy (Cty->WWW[Gbl.Prefs.Language],row[2],
sizeof (Cty->WWW[Gbl.Prefs.Language]) - 1);
2014-12-01 23:55:08 +01:00
}
/***** 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)
{
2020-01-07 22:07:06 +01:00
Gbl.Cache.CountryName.CtyCod = -1L;
Gbl.Cache.CountryName.Language = Lan_LANGUAGE_UNKNOWN;
2017-06-20 14:43:26 +02:00
Gbl.Cache.CountryName.CtyName[0] = '\0';
}
2020-01-07 22:07:06 +01:00
void Cty_GetCountryName (long CtyCod,Lan_Language_t Language,
char CtyName[Cty_MAX_BYTES_NAME + 1])
2014-12-01 23:55:08 +01:00
{
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... *****/
2020-01-07 22:07:06 +01:00
if (CtyCod == Gbl.Cache.CountryName.CtyCod &&
Language == Gbl.Cache.CountryName.Language)
2017-06-20 14:43:26 +02:00
{
Str_Copy (CtyName,Gbl.Cache.CountryName.CtyName,Cty_MAX_BYTES_NAME);
2017-06-20 14:43:26 +02:00
return;
}
2017-03-01 15:23:30 +01:00
2017-06-20 14:43:26 +02:00
/***** 3. Slow: get country name from database *****/
Cty_DB_GetCountryName (CtyCod,Language,CtyName);
2020-01-07 22:07:06 +01:00
Gbl.Cache.CountryName.CtyCod = CtyCod;
Gbl.Cache.CountryName.Language = Language;
Str_Copy (Gbl.Cache.CountryName.CtyName,CtyName,Cty_MAX_BYTES_NAME);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*************************** Free list of countries **************************/
/*****************************************************************************/
void Cty_FreeListCountries (void)
{
2020-01-08 14:04:25 +01:00
if (Gbl.Hierarchy.Ctys.Lst)
2014-12-01 23:55:08 +01:00
{
/***** Free memory used by the list of courses in institution *****/
2020-01-08 14:04:25 +01:00
free (Gbl.Hierarchy.Ctys.Lst);
Gbl.Hierarchy.Ctys.Lst = NULL;
Gbl.Hierarchy.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;
2021-02-11 22:57:09 +01:00
struct Cty_Countr *Cty;
2020-05-03 20:58:03 +02:00
unsigned NumInss;
unsigned NumUsrsCty;
2018-12-08 16:43:13 +01:00
Lan_Language_t Lan;
2014-12-01 23:55:08 +01:00
/***** Begin table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginWidePadding (2);
2014-12-01 23:55:08 +01:00
/***** Write heading *****/
Cty_PutHeadCountriesForEdition ();
2014-12-01 23:55:08 +01:00
/***** Write all countries *****/
for (NumCty = 0;
NumCty < Gbl.Hierarchy.Ctys.Num;
NumCty++)
{
Cty = &Gbl.Hierarchy.Ctys.Lst[NumCty];
NumInss = Ins_GetNumInssInCty (Cty->CtyCod);
NumUsrsCty = Usr_GetNumUsrsWhoClaimToBelongToCty (Cty);
2019-10-05 13:27:58 +02:00
HTM_TR_Begin (NULL);
/* Put icon to remove country */
HTM_TD_Begin ("rowspan=\"%u\" class=\"BT\"",1 + Lan_NUM_LANGUAGES);
if (NumInss || // Country has institutions
NumUsrsCty) // Country has users
// Deletion forbidden
Ico_PutIconRemovalNotAllowed ();
else if (Usr_GetNumUsrsInCrss (HieLvl_CTY,Cty->CtyCod,
1 << Rol_STD |
1 << Rol_NET |
1 << Rol_TCH)) // Country has users
// Deletion forbidden
Ico_PutIconRemovalNotAllowed ();
else
Ico_PutContextualIconToRemove (ActRemCty,NULL,
Cty_PutParamOtherCtyCod,&Cty->CtyCod);
HTM_TD_End ();
/* Numerical country code (ISO 3166-1) */
HTM_TD_Begin ("rowspan=\"%u\" class=\"DAT RT\"",1 + Lan_NUM_LANGUAGES);
HTM_TxtF ("%03ld",Cty->CtyCod);
HTM_TD_End ();
/* Alphabetic country code with 2 letters (ISO 3166-1) */
HTM_TD_Begin ("rowspan=\"%u\" class=\"DAT RT\"",1 + Lan_NUM_LANGUAGES);
HTM_Txt (Cty->Alpha2);
HTM_TD_End ();
HTM_TD_Empty (3);
/* Number of users */
HTM_TD_Begin ("rowspan=\"%u\" class=\"DAT RT\"",1 + Lan_NUM_LANGUAGES);
HTM_Unsigned (NumUsrsCty);
HTM_TD_End ();
2019-10-05 13:27:58 +02:00
/* Number of institutions */
HTM_TD_Begin ("rowspan=\"%u\" class=\"DAT RT\"",1 + Lan_NUM_LANGUAGES);
HTM_Unsigned (NumInss);
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
HTM_TR_End ();
2019-10-05 13:27:58 +02:00
/* Country name in several languages */
for (Lan = (Lan_Language_t) 1;
Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES;
Lan++)
{
HTM_TR_Begin (NULL);
/* Language */
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_TxtColon (Txt_STR_LANG_NAME[Lan]);
HTM_TD_End ();
/* Name */
HTM_TD_Begin ("class=\"LT\"");
Frm_BeginForm (ActRenCty);
Cty_PutParamOtherCtyCod (&Cty->CtyCod);
Par_PutHiddenParamUnsigned (NULL,"Lan",(unsigned) Lan);
HTM_INPUT_TEXT ("Name",Cty_MAX_CHARS_NAME,Cty->Name[Lan],
HTM_SUBMIT_ON_CHANGE,
"size=\"15\"");
Frm_EndForm ();
HTM_TD_End ();
2019-10-05 13:27:58 +02:00
/* WWW */
HTM_TD_Begin ("class=\"LT\"");
Frm_BeginForm (ActChgCtyWWW);
Cty_PutParamOtherCtyCod (&Cty->CtyCod);
Par_PutHiddenParamUnsigned (NULL,"Lan",(unsigned) Lan);
HTM_INPUT_URL ("WWW",Cty->WWW[Lan],HTM_SUBMIT_ON_CHANGE,
"class=\"INPUT_WWW_NARROW\" required=\"required\"");
Frm_EndForm ();
HTM_TD_End ();
HTM_TR_End ();
}
}
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 *******************/
/*****************************************************************************/
2020-10-13 22:34:31 +02:00
static void Cty_PutParamOtherCtyCod (void *CtyCod)
2014-12-01 23:55:08 +01:00
{
2020-10-13 22:34:31 +02:00
if (CtyCod)
Par_PutHiddenParamLong (NULL,"OthCtyCod",*((long *) 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)
Err_WrongCountrExit ();
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 *****/
2020-01-07 22:07:06 +01:00
Cty_GetDataOfCountryByCod (Cty_EditingCty);
2014-12-01 23:55:08 +01:00
/***** Check if this country has users *****/
2020-01-07 13:14:42 +01:00
if (Ins_GetNumInssInCty (Cty_EditingCty->CtyCod)) // Country has institutions ==> don't remove
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_You_can_not_remove_a_country_with_institutions_or_users);
2020-01-07 14:52:28 +01:00
else if (Usr_GetNumUsrsWhoClaimToBelongToCty (Cty_EditingCty)) // Country has users ==> don't remove
2020-01-07 00:42:24 +01:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_You_can_not_remove_a_country_with_institutions_or_users);
else if (Usr_GetNumUsrsInCrss (HieLvl_CTY,Cty_EditingCty->CtyCod,
2020-01-08 23:49:04 +01:00
1 << Rol_STD |
1 << Rol_NET |
1 << Rol_TCH)) // Country has users
2019-04-08 21:10:12 +02:00
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 *****/
Svy_RemoveSurveys (HieLvl_CTY,Cty_EditingCty->CtyCod);
2016-10-28 00:30:18 +02:00
2014-12-01 23:55:08 +01:00
/***** Remove country *****/
Cty_DB_RemoveCty (Cty_EditingCty->CtyCod);
2014-12-01 23:55:08 +01:00
2017-06-20 14:43:26 +02:00
/***** Flush cache *****/
Cty_FlushCacheCountryName ();
2020-01-07 00:42:24 +01:00
Ins_FlushCacheNumInssInCty ();
2020-01-07 16:37:46 +01:00
Ctr_FlushCacheNumCtrsInCty ();
2020-01-07 16:08:13 +01:00
Deg_FlushCacheNumDegsInCty ();
2020-01-07 15:11:48 +01:00
Crs_FlushCacheNumCrssInCty ();
2020-01-07 13:37:00 +01:00
Usr_FlushCacheNumUsrsWhoClaimToBelongToCty ();
2017-06-20 14:43:26 +02:00
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 *****/
2020-01-07 22:07:06 +01:00
Cty_GetDataOfCountryByCod (Cty_EditingCty);
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) *****/
2020-01-07 22:07:06 +01:00
Cty_GetCountryName (Cty_EditingCty->CtyCod,Language,
Cty_EditingCty->Name[Language]);
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... *****/
if (Cty_DB_CheckIfCountryNameExists (Language,NewCtyName,Cty_EditingCty->CtyCod))
2019-04-08 21:10:12 +02:00
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 */
snprintf (FieldName,sizeof (FieldName),"Name_%s",
2018-12-08 16:43:13 +01:00
Lan_STR_LANG_ID[Language]);
Cty_UpdateCtyName (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,
sizeof (Cty_EditingCty->Name[Language]) - 1);
2017-05-31 21:05:59 +02:00
}
}
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
}
2017-03-10 02:40:01 +01:00
/*****************************************************************************/
/************ Update institution name in table of institutions ***************/
/*****************************************************************************/
static void Cty_UpdateCtyName (long CtyCod,const char *FieldName,const char *NewCtyName)
2017-03-10 02:40:01 +01:00
{
/***** Update country changing old name by new name */
Cty_DB_UpdateCtyField (CtyCod,FieldName,NewCtyName);
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;
char FieldName[3 + 1 + 2 + 1]; // Example: "WWW_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 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 *****/
2020-01-07 22:07:06 +01:00
Cty_GetDataOfCountryByCod (Cty_EditingCty);
2014-12-01 23:55:08 +01:00
/***** Update the table changing old WWW by new WWW *****/
snprintf (FieldName,sizeof (FieldName),"Name_%s",
Lan_STR_LANG_ID[Language]);
Cty_DB_UpdateCtyField (Cty_EditingCty->CtyCod,FieldName,NewWWW);
2019-04-08 21:10:12 +02:00
Str_Copy (Cty_EditingCty->WWW[Language],NewWWW,
sizeof (Cty_EditingCty->WWW[Language]) - 1);
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
}
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-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 *****/
2020-03-26 02:54:30 +01:00
Ale_ShowLastAlertAndButton (ActSeeIns,NULL,NULL,
2020-04-08 13:40:21 +02:00
Cty_PutParamGoToCty,&Cty_EditingCty->CtyCod,
2019-12-30 12:25:45 +01:00
Btn_CONFIRM_BUTTON,
Hie_BuildGoToMsg (Cty_EditingCty->Name[Gbl.Prefs.Language]));
Hie_FreeGoToMsg ();
2019-04-08 21:10:12 +02:00
}
else
/***** Alert *****/
Ale_ShowAlerts (NULL);
}
2020-04-08 13:40:21 +02:00
static void Cty_PutParamGoToCty (void *CtyCod)
2019-04-08 21:10:12 +02:00
{
2020-04-08 13:40:21 +02:00
if (CtyCod)
2020-03-26 02:54:30 +01:00
/***** Put parameter *****/
2020-04-08 18:18:46 +02:00
Cty_PutParamCtyCod (*((long *) CtyCod));
2019-04-08 21:10:12 +02:00
}
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 *****/
Frm_BeginForm (ActNewCty);
2014-12-01 23:55:08 +01:00
/***** Begin box and table *****/
Box_BoxTableBegin (NULL,Txt_New_country,
NULL,NULL,
NULL,Box_NOT_CLOSABLE,2);
2014-12-01 23:55:08 +01:00
/***** Write heading *****/
Cty_PutHeadCountriesForEdition ();
2014-12-01 23:55:08 +01:00
HTM_TR_Begin (NULL);
2014-12-01 23:55:08 +01:00
/***** Column to remove country, disabled here *****/
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) *****/
HTM_TD_Begin ("rowspan=\"%u\" class=\"RT\"",1 + Lan_NUM_LANGUAGES);
if (Cty_EditingCty->CtyCod > 0)
snprintf (StrCtyCod,sizeof (StrCtyCod),"%03ld",Cty_EditingCty->CtyCod);
else
StrCtyCod[0] = '\0';
HTM_INPUT_TEXT ("OthCtyCod",3,StrCtyCod,HTM_DONT_SUBMIT_ON_CHANGE,
"size=\"3\" required=\"required\"");
HTM_TD_End ();
2019-10-05 13:27:58 +02:00
/***** Alphabetic country code with 2 letters (ISO 3166-1) *****/
HTM_TD_Begin ("rowspan=\"%u\" class=\"RT\"",1 + Lan_NUM_LANGUAGES);
HTM_INPUT_TEXT ("Alpha2",2,Cty_EditingCty->Alpha2,HTM_DONT_SUBMIT_ON_CHANGE,
"size=\"2\" required=\"required\"");
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
HTM_TD_Empty (3);
2019-10-05 13:27:58 +02:00
/***** Number of users *****/
HTM_TD_Begin ("rowspan=\"%u\" class=\"DAT RT\"",1 + Lan_NUM_LANGUAGES);
HTM_Unsigned (0);
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
/***** Number of institutions *****/
HTM_TD_Begin ("rowspan=\"%u\" class=\"DAT RT\"",1 + Lan_NUM_LANGUAGES);
HTM_Unsigned (0);
HTM_TD_End ();
2014-12-01 23:55:08 +01:00
HTM_TR_End ();
2019-10-05 13:27:58 +02:00
/***** Country name in several languages *****/
for (Lan = (Lan_Language_t) 1;
Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES;
Lan++)
{
HTM_TR_Begin (NULL);
/* Language */
HTM_TD_Begin ("class=\"DAT RT\"");
HTM_Txt (Txt_STR_LANG_NAME[Lan]);
HTM_TD_End ();
/* Name */
HTM_TD_Begin ("class=\"LM\"");
snprintf (StrName,sizeof (StrName),"Name_%s",Lan_STR_LANG_ID[Lan]);
HTM_INPUT_TEXT (StrName,Cty_MAX_CHARS_NAME,Cty_EditingCty->Name[Lan],
HTM_DONT_SUBMIT_ON_CHANGE,
"size=\"15\" required=\"required\"");
HTM_TD_End ();
/* WWW */
HTM_TD_Begin ("class=\"LM\"");
snprintf (StrName,sizeof (StrName),"WWW_%s",Lan_STR_LANG_ID[Lan]);
HTM_INPUT_URL (StrName,Cty_EditingCty->WWW[Lan],HTM_DONT_SUBMIT_ON_CHANGE,
"class=\"INPUT_WWW_NARROW\" required=\"required\"");
HTM_TD_End ();
HTM_TR_End ();
}
2014-12-01 23:55:08 +01:00
/***** End table, send button and end box *****/
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
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 ********************/
/*****************************************************************************/
2020-05-05 21:49:00 +02:00
void Cty_ReceiveFormNewCountry (void)
2014-12-01 23:55:08 +01:00
{
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;
}
else if (Cty_DB_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)
{
if (Cty_DB_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++)
{
snprintf (ParamName,sizeof (ParamName),"Name_%s",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... *****/
if (Cty_DB_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;
}
snprintf (ParamName,sizeof (ParamName),"WWW_%s",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_DB_CreateCountry (Cty_EditingCty); // Add new country to database
2019-04-08 21:10:12 +02:00
Ale_ShowAlert (Ale_SUCCESS,Txt_Created_new_country_X,
Cty_EditingCty->Name);
}
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*********************** Get total number of countries ***********************/
/*****************************************************************************/
2020-05-03 20:58:03 +02:00
unsigned Cty_GetCachedNumCtysInSys (void)
2014-12-01 23:55:08 +01:00
{
2020-05-03 20:58:03 +02:00
unsigned NumCtys;
/***** Get number of countries from cache *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_CTYS,HieLvl_SYS,-1L,
2020-05-03 20:58:03 +02:00
FigCch_UNSIGNED,&NumCtys))
{
/***** Get current number of countries from database and update cache *****/
NumCtys = (unsigned) DB_GetNumRowsTable ("cty_countrs");
FigCch_UpdateFigureIntoCache (FigCch_NUM_CTYS,HieLvl_SYS,-1L,
2020-05-03 20:58:03 +02:00
FigCch_UNSIGNED,&NumCtys);
}
return NumCtys;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/***************** Get number of countries with institutions *****************/
/*****************************************************************************/
2020-05-03 20:58:03 +02:00
unsigned Cty_GetCachedNumCtysWithInss (void)
2014-12-01 23:55:08 +01:00
{
2020-05-03 20:58:03 +02:00
unsigned NumCtysWithInss;
/***** Get number of countries with institutions from cache *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_CTYS_WITH_INSS,HieLvl_SYS,-1L,
2020-05-03 20:58:03 +02:00
FigCch_UNSIGNED,&NumCtysWithInss))
{
/***** Get current number of countries with institutions from cache *****/
NumCtysWithInss = Cty_DB_GetNumCtysWithInss ();
FigCch_UpdateFigureIntoCache (FigCch_NUM_CTYS_WITH_INSS,HieLvl_SYS,-1L,
2020-05-03 20:58:03 +02:00
FigCch_UNSIGNED,&NumCtysWithInss);
}
return NumCtysWithInss;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************* Get number of countries with centers ********************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2020-05-03 20:58:03 +02:00
unsigned Cty_GetCachedNumCtysWithCtrs (void)
2014-12-01 23:55:08 +01:00
{
2020-05-03 20:58:03 +02:00
unsigned NumCtysWithCtrs;
/***** Get number of countries with centers from cache *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_CTYS_WITH_CTRS,HieLvl_SYS,-1L,
2020-05-03 20:58:03 +02:00
FigCch_UNSIGNED,&NumCtysWithCtrs))
{
/***** Get current number of countries with centers from database and update cache *****/
NumCtysWithCtrs = Cty_DB_GetNumCtysWithCtrs ();
FigCch_UpdateFigureIntoCache (FigCch_NUM_CTYS_WITH_CTRS,HieLvl_SYS,-1L,
2020-05-03 20:58:03 +02:00
FigCch_UNSIGNED,&NumCtysWithCtrs);
}
return NumCtysWithCtrs;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************* Get number of countries with degrees ********************/
/*****************************************************************************/
2020-05-03 20:58:03 +02:00
unsigned Cty_GetCachedNumCtysWithDegs (void)
2014-12-01 23:55:08 +01:00
{
2020-05-03 20:58:03 +02:00
unsigned NumCtysWithDegs;
/***** Get number of countries with degrees from cache *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_CTYS_WITH_DEGS,HieLvl_SYS,-1L,
2020-05-03 20:58:03 +02:00
FigCch_UNSIGNED,&NumCtysWithDegs))
{
/***** Get current number of countries with degrees from database and update cache *****/
NumCtysWithDegs = Cty_DB_GetNumCtysWithDegs ();
FigCch_UpdateFigureIntoCache (FigCch_NUM_CTYS_WITH_DEGS,HieLvl_SYS,-1L,
2020-05-03 20:58:03 +02:00
FigCch_UNSIGNED,&NumCtysWithDegs);
}
return NumCtysWithDegs;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************* Get number of countries with courses ********************/
/*****************************************************************************/
2020-05-03 20:58:03 +02:00
unsigned Cty_GetCachedNumCtysWithCrss (void)
2014-12-01 23:55:08 +01:00
{
2020-05-03 20:58:03 +02:00
unsigned NumCtysWithCrss;
/***** Get number of countries with courses from cache *****/
if (!FigCch_GetFigureFromCache (FigCch_NUM_CTYS_WITH_CRSS,HieLvl_SYS,-1L,
2020-05-03 20:58:03 +02:00
FigCch_UNSIGNED,&NumCtysWithCrss))
{
/***** Get current number of countries with courses from database and update cache *****/
NumCtysWithCrss = Cty_DB_GetNumCtysWithCrss ();
FigCch_UpdateFigureIntoCache (FigCch_NUM_CTYS_WITH_CRSS,HieLvl_SYS,-1L,
2020-05-03 20:58:03 +02:00
FigCch_UNSIGNED,&NumCtysWithCrss);
}
return NumCtysWithCrss;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************* Get number of countries with users **********************/
/*****************************************************************************/
2020-05-03 20:58:03 +02:00
unsigned Cty_GetCachedNumCtysWithUsrs (Rol_Role_t Role,const char *SubQuery,
HieLvl_Level_t Scope,long Cod)
2014-12-01 23:55:08 +01:00
{
2020-05-03 20:58:03 +02:00
static const FigCch_FigureCached_t FigureCtys[Rol_NUM_ROLES] =
{
[Rol_STD] = FigCch_NUM_CTYS_WITH_STDS, // Students
[Rol_NET] = FigCch_NUM_CTYS_WITH_NETS, // Non-editing teachers
[Rol_TCH] = FigCch_NUM_CTYS_WITH_TCHS, // Teachers
};
unsigned NumCtysWithUsrs;
/***** Get number of countries with users from cache *****/
if (!FigCch_GetFigureFromCache (FigureCtys[Role],Scope,Cod,
FigCch_UNSIGNED,&NumCtysWithUsrs))
{
/***** Get current number of countries with users from database and update cache *****/
NumCtysWithUsrs = Cty_DB_GetNumCtysWithUsrs (Role,SubQuery);
2020-05-03 20:58:03 +02:00
FigCch_UpdateFigureIntoCache (FigureCtys[Role],Scope,Cod,
FigCch_UNSIGNED,&NumCtysWithUsrs);
}
return NumCtysWithUsrs;
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;
unsigned NumCty;
2021-02-11 22:57:09 +01:00
struct Cty_Countr Cty;
2017-02-28 00:59:01 +01:00
/***** 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 */
2019-12-30 21:47:07 +01:00
Box_BoxTableBegin (NULL,Str_BuildStringLongStr ((long) NumCtys,
NumCtys == 1 ? Txt_country :
Txt_countries),
2020-03-26 02:54:30 +01:00
NULL,NULL,
NULL,Box_NOT_CLOSABLE,2);
2019-12-30 21:47:07 +01:00
Str_FreeString ();
2017-06-12 14:16:33 +02:00
/***** Write heading *****/
Cty_PutHeadCountriesForSeeing (false); // Order not selectable
2017-02-28 00:59:01 +01:00
/***** List the countries (one row per country) *****/
for (NumCty = 1;
NumCty <= NumCtys;
NumCty++)
{
/* Get next country */
Cty.CtyCod = DB_GetNextCode (*mysql_res);
2017-02-28 00:59:01 +01:00
/* Get data of country */
Cty_GetDataOfCountryByCod (&Cty);
2017-02-28 00:59:01 +01:00
/* Write data of this country */
Cty_ListOneCountryForSeeing (&Cty,NumCty);
}
2017-02-28 00:59:01 +01:00
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)
Err_WrongCountrExit ();
2019-04-04 11:22:08 +02:00
/***** Allocate memory for country *****/
if ((Cty_EditingCty = malloc (sizeof (*Cty_EditingCty))) == NULL)
Err_NotEnoughMemoryExit ();
2019-04-04 11:22:08 +02:00
/***** 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
}
2020-01-07 13:14:42 +01:00
Cty_EditingCty->NumUsrsWhoClaimToBelongToCty.Valid = false;
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
}
}
2020-01-09 15:36:12 +01:00
/*****************************************************************************/
2020-01-14 13:30:18 +01:00
/************************ Form to go to country map **************************/
/*****************************************************************************/
2021-02-11 22:57:09 +01:00
static void Cty_FormToGoToMap (struct Cty_Countr *Cty)
2020-01-14 13:30:18 +01:00
{
extern const char *Txt_Map;
if (Cty_DB_GetIfMapIsAvailable (Cty->CtyCod))
2020-01-14 13:30:18 +01:00
{
Cty_EditingCty = Cty; // Used to pass parameter with the code of the country
2020-03-26 02:54:30 +01:00
Lay_PutContextualLinkOnlyIcon (ActSeeCtyInf,NULL,
2020-04-08 13:40:21 +02:00
Cty_PutParamGoToCty,&Cty_EditingCty->CtyCod,
2020-01-14 13:30:18 +01:00
"map-marker-alt.svg",
Txt_Map);
}
}