swad-core/swad_system_config.c

422 lines
13 KiB
C
Raw Normal View History

2020-01-08 23:49:57 +01:00
// swad_system_config.c: configuration of system
/*
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
2020-01-08 23:49:57 +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 ***********************************/
/*****************************************************************************/
#define _GNU_SOURCE // For asprintf
#include <stdbool.h> // For boolean type
#include <stddef.h> // For NULL
#include <stdio.h> // For asprintf
#include <stdlib.h> // For free
#include <string.h> // For string functions
#include "swad_box.h"
#include "swad_config.h"
#include "swad_course.h"
#include "swad_database.h"
2020-05-01 19:15:59 +02:00
#include "swad_figure_cache.h"
2020-01-08 23:49:57 +01:00
#include "swad_form.h"
#include "swad_help.h"
2021-02-11 22:57:09 +01:00
#include "swad_hierarchy_level.h"
2020-01-08 23:49:57 +01:00
#include "swad_hierarchy_config.h"
#include "swad_HTML.h"
#include "swad_role.h"
#include "swad_system_config.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/******************************* Private types *******************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private variables *****************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
static void SysCfg_Configuration (bool PrintView);
2020-04-09 21:36:21 +02:00
static void SysCfg_PutIconToPrint (__attribute__((unused)) void *Args);
2020-01-08 23:49:57 +01:00
static void SysCfg_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom);
static void SysCfg_Map (void);
static void SysCfg_Platform (void);
static void SysCfg_Shortcut (bool PrintView);
static void SysCfg_QR (void);
static void SysCfg_NumCtys (void);
static void SysCfg_NumInss (void);
static void SysCfg_NumDegs (void);
static void SysCfg_NumCrss (void);
/*****************************************************************************/
/***************** Show information of the current country *******************/
/*****************************************************************************/
void SysCfg_ShowConfiguration (void)
{
SysCfg_Configuration (false);
/***** Show help to enrol me *****/
Hlp_ShowHelpWhatWouldYouLikeToDo ();
}
/*****************************************************************************/
/***************** Print information of the current country ******************/
/*****************************************************************************/
void SysCfg_PrintConfiguration (void)
{
SysCfg_Configuration (true);
}
/*****************************************************************************/
/******************** Information of the current country *********************/
/*****************************************************************************/
static void SysCfg_Configuration (bool PrintView)
{
extern const char *Hlp_SYSTEM_Information;
2020-01-25 21:34:20 +01:00
unsigned NumCtrs;
unsigned NumCtrsWithMap;
2020-01-08 23:49:57 +01:00
/***** Begin box *****/
if (PrintView)
2020-03-26 02:54:30 +01:00
Box_BoxBegin (NULL,Cfg_PLATFORM_SHORT_NAME,
NULL,NULL,
2020-01-08 23:49:57 +01:00
NULL,Box_NOT_CLOSABLE);
else
2020-03-26 02:54:30 +01:00
Box_BoxBegin (NULL,Cfg_PLATFORM_SHORT_NAME,
2020-04-09 21:36:21 +02:00
SysCfg_PutIconToPrint,NULL,
2020-01-08 23:49:57 +01:00
Hlp_SYSTEM_Information,Box_NOT_CLOSABLE);
/**************************** Left part ***********************************/
2020-01-14 14:16:14 +01:00
HTM_DIV_Begin ("class=\"HIE_CFG_LEFT HIE_CFG_WIDTH\"");
2020-01-08 23:49:57 +01:00
/***** Begin table *****/
HTM_TABLE_BeginWidePadding (2);
/***** Platform *****/
SysCfg_Platform ();
/***** Shortcut to the country *****/
SysCfg_Shortcut (PrintView);
/***** Get number of centers with map *****/
2020-05-03 21:56:55 +02:00
NumCtrsWithMap = Ctr_GetCachedNumCtrsWithMapInSys ();
2020-05-01 19:15:59 +02:00
2020-01-08 23:49:57 +01:00
if (PrintView)
/***** QR code with link to the country *****/
SysCfg_QR ();
else
{
/***** Get number of centers *****/
2020-05-03 20:58:03 +02:00
NumCtrs = Ctr_GetCachedNumCtrsInSys ();
2020-01-25 21:34:20 +01:00
2020-01-08 23:49:57 +01:00
/***** Number of countries,
number of institutions,
number of centers,
2020-01-08 23:49:57 +01:00
number of degrees,
number of courses *****/
SysCfg_NumCtys ();
SysCfg_NumInss ();
2020-01-26 14:10:27 +01:00
HieCfg_NumCtrs (NumCtrs,
false); // Don't put form
2020-01-25 22:18:01 +01:00
HieCfg_NumCtrsWithMap (NumCtrs,NumCtrsWithMap);
2020-01-08 23:49:57 +01:00
SysCfg_NumDegs ();
SysCfg_NumCrss ();
/***** Number of users in courses of this country *****/
2021-02-11 22:57:09 +01:00
HieCfg_NumUsrsInCrss (Hie_Lvl_SYS,-1L,Rol_TCH);
HieCfg_NumUsrsInCrss (Hie_Lvl_SYS,-1L,Rol_NET);
HieCfg_NumUsrsInCrss (Hie_Lvl_SYS,-1L,Rol_STD);
HieCfg_NumUsrsInCrss (Hie_Lvl_SYS,-1L,Rol_UNK);
2020-01-08 23:49:57 +01:00
}
/***** End table *****/
HTM_TABLE_End ();
/***** End of left part *****/
HTM_DIV_End ();
/**************************** Right part **********************************/
2020-01-25 21:34:20 +01:00
if (NumCtrsWithMap)
2020-01-08 23:49:57 +01:00
{
2020-01-14 14:16:14 +01:00
HTM_DIV_Begin ("class=\"HIE_CFG_RIGHT HIE_CFG_WIDTH\"");
2020-01-08 23:49:57 +01:00
/***** Country map *****/
SysCfg_Map ();
HTM_DIV_End ();
}
/***** End box *****/
Box_BoxEnd ();
}
/*****************************************************************************/
/************* Put icon to print the configuration of a country **************/
/*****************************************************************************/
2020-04-09 21:36:21 +02:00
static void SysCfg_PutIconToPrint (__attribute__((unused)) void *Args)
2020-01-08 23:49:57 +01:00
{
2020-04-09 21:36:21 +02:00
Ico_PutContextualIconToPrint (ActPrnSysInf,
NULL,NULL);
2020-01-08 23:49:57 +01:00
}
/*****************************************************************************/
/********* Get average coordinates of centers in current institution *********/
2020-01-08 23:49:57 +01:00
/*****************************************************************************/
static void SysCfg_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom)
{
char *Query;
/***** Get average coordinates of centers with both coordinates set
2020-01-08 23:49:57 +01:00
(coordinates 0, 0 means not set ==> don't show map) *****/
if (asprintf (&Query,
"SELECT AVG(Latitude)," // row[0]
"AVG(Longitude)," // row[1]
"GREATEST(MAX(Latitude)-MIN(Latitude),"
"MAX(Longitude)-MIN(Longitude))" // row[2]
" FROM ctr_centers"
2020-01-08 23:49:57 +01:00
" WHERE Latitude<>0"
" AND Longitude<>0") < 0)
2020-01-08 23:49:57 +01:00
Lay_NotEnoughMemoryExit ();
Map_GetCoordAndZoom (Coord,Zoom,Query);
free (Query);
}
/*****************************************************************************/
/****************************** Draw country map *****************************/
/*****************************************************************************/
2020-01-09 18:56:45 +01:00
#define SysCfg_MAP_CONTAINER_ID "sys_mapid"
2020-01-08 23:49:57 +01:00
static void SysCfg_Map (void)
{
MYSQL_RES *mysql_res;
struct Coordinates CtyAvgCoord;
unsigned Zoom;
unsigned NumCtrs;
unsigned NumCtr;
2021-02-11 00:58:53 +01:00
struct Ins_Instit Ins;
struct Ctr_Center Ctr;
2020-01-08 23:49:57 +01:00
/***** Leaflet CSS *****/
Map_LeafletCSS ();
/***** Leaflet script *****/
Map_LeafletScript ();
/***** Container for the map *****/
HTM_DIV_Begin ("id=\"%s\"",SysCfg_MAP_CONTAINER_ID);
HTM_DIV_End ();
/***** Script to draw the map *****/
HTM_SCRIPT_Begin (NULL,NULL);
/* Let's create a map with pretty Mapbox Streets tiles */
SysCfg_GetCoordAndZoom (&CtyAvgCoord,&Zoom);
Map_CreateMap (SysCfg_MAP_CONTAINER_ID,&CtyAvgCoord,Zoom);
/* Add Mapbox Streets tile layer to our map */
Map_AddTileLayer ();
/* Get centers with coordinates */
NumCtrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get centers with coordinates",
"SELECT CtrCod"
" FROM ctr_centers"
" WHERE ctr_centers.Latitude<>0"
" AND ctr_centers.Longitude<>0");
2020-01-08 23:49:57 +01:00
/* Add a marker and a popup for each center */
2020-01-08 23:49:57 +01:00
for (NumCtr = 0;
NumCtr < NumCtrs;
NumCtr++)
{
/* Get next center */
Ctr.CtrCod = DB_GetNextCode (mysql_res);
2020-01-08 23:49:57 +01:00
/* Get data of center */
Ctr_GetDataOfCenterByCod (&Ctr);
2020-01-08 23:49:57 +01:00
/* Get data of institution */
Ins.InsCod = Ctr.InsCod;
Ins_GetDataOfInstitutionByCod (&Ins);
/* Add marker */
Map_AddMarker (&Ctr.Coord);
/* Add popup */
Map_AddPopup (Ctr.ShrtName,Ins.ShrtName,
false); // Closed
}
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
HTM_SCRIPT_End ();
}
/*****************************************************************************/
/****************** Show platform in country configuration *******************/
/*****************************************************************************/
static void SysCfg_Platform (void)
{
extern const char *Txt_Platform;
/***** Institution *****/
HTM_TR_Begin (NULL);
/* Label */
Frm_LabelColumn ("RT",NULL,Txt_Platform);
/* Data */
HTM_TD_Begin ("class=\"DAT_N LB\"");
HTM_Txt (Cfg_PLATFORM_SHORT_NAME);
HTM_TD_End ();
HTM_TR_End ();
}
/*****************************************************************************/
/************** Show platform shortcut in system configuration ***************/
/*****************************************************************************/
static void SysCfg_Shortcut (bool PrintView)
{
HieCfg_Shortcut (PrintView,NULL,-1L);
}
/*****************************************************************************/
/***************** Show country QR in country configuration ******************/
/*****************************************************************************/
static void SysCfg_QR (void)
{
HieCfg_QR (NULL,-1L);
}
/*****************************************************************************/
/************ Show number of countries in system configuration ***************/
/*****************************************************************************/
static void SysCfg_NumCtys (void)
{
extern const char *Txt_Countries;
/***** Number of countries ******/
HTM_TR_Begin (NULL);
/* Label */
Frm_LabelColumn ("RT",NULL,Txt_Countries);
/* Data */
HTM_TD_Begin ("class=\"LB\"");
Frm_BeginFormGoTo (ActSeeCty);
2020-01-08 23:49:57 +01:00
HTM_BUTTON_SUBMIT_Begin (Txt_Countries,"BT_LINK DAT",NULL);
2020-05-03 20:58:03 +02:00
HTM_Unsigned (Cty_GetCachedNumCtysInSys ());
2020-01-08 23:49:57 +01:00
HTM_BUTTON_End ();
Frm_EndForm ();
HTM_TD_End ();
HTM_TR_End ();
}
/*****************************************************************************/
/*********** Show number of institutions in system configuration *************/
/*****************************************************************************/
static void SysCfg_NumInss (void)
{
extern const char *Txt_Institutions;
/***** Number of institutions ******/
HTM_TR_Begin (NULL);
/* Label */
Frm_LabelColumn ("RT",NULL,Txt_Institutions);
/* Data */
HTM_TD_Begin ("class=\"DAT LB\"");
2020-05-03 20:58:03 +02:00
HTM_Unsigned (Ins_GetCachedNumInssInSys ());
2020-01-08 23:49:57 +01:00
HTM_TD_End ();
HTM_TR_End ();
}
/*****************************************************************************/
/************* Show number of degrees in system configuration ****************/
/*****************************************************************************/
static void SysCfg_NumDegs (void)
{
extern const char *Txt_Degrees;
/***** Number of degrees *****/
HTM_TR_Begin (NULL);
/* Label */
Frm_LabelColumn ("RT",NULL,Txt_Degrees);
/* Data */
HTM_TD_Begin ("class=\"DAT LB\"");
2020-05-03 20:58:03 +02:00
HTM_Unsigned (Deg_GetCachedNumDegsInSys ());
2020-01-08 23:49:57 +01:00
HTM_TD_End ();
HTM_TR_End ();
}
/*****************************************************************************/
/************* Show number of courses in system configuration ****************/
/*****************************************************************************/
static void SysCfg_NumCrss (void)
{
extern const char *Txt_Courses;
/***** Number of courses *****/
HTM_TR_Begin (NULL);
/* Label */
Frm_LabelColumn ("RT",NULL,Txt_Courses);
/* Data */
HTM_TD_Begin ("class=\"DAT LB\"");
2020-05-03 20:58:03 +02:00
HTM_Unsigned (Crs_GetCachedNumCrssInSys ());
2020-01-08 23:49:57 +01:00
HTM_TD_End ();
HTM_TR_End ();
}