swad-core/swad_system_config.c

381 lines
11 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.
Copyright (C) 1999-2023 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_action_list.h"
2020-01-08 23:49:57 +01:00
#include "swad_box.h"
#include "swad_center_database.h"
2020-01-08 23:49:57 +01:00
#include "swad_config.h"
#include "swad_course.h"
#include "swad_database.h"
#include "swad_error.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_global.h"
2020-01-08 23:49:57 +01:00
#include "swad_help.h"
#include "swad_hierarchy_config.h"
#include "swad_hierarchy_level.h"
2020-01-08 23:49:57 +01:00
#include "swad_HTML.h"
#include "swad_role.h"
#include "swad_system_config.h"
/*****************************************************************************/
/***************************** 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_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 *****/
NumCtrsWithMap = Ctr_GetCachedNumCtrsWithMapInSys ();
if (PrintView)
/***** QR code with link to the country *****/
SysCfg_QR ();
else
{
/***** Get number of centers *****/
NumCtrs = Ctr_GetCachedNumCtrsInSys ();
/***** Number of countries,
number of institutions,
number of centers,
number of degrees,
number of courses *****/
SysCfg_NumCtys ();
SysCfg_NumInss ();
HieCfg_NumCtrs (NumCtrs,
false); // Don't put form
HieCfg_NumCtrsWithMap (NumCtrs,NumCtrsWithMap);
SysCfg_NumDegs ();
SysCfg_NumCrss ();
/***** Number of users in courses of this country *****/
HieCfg_NumUsrsInCrss (HieLvl_SYS,-1L,Rol_TCH);
HieCfg_NumUsrsInCrss (HieLvl_SYS,-1L,Rol_NET);
HieCfg_NumUsrsInCrss (HieLvl_SYS,-1L,Rol_STD);
HieCfg_NumUsrsInCrss (HieLvl_SYS,-1L,Rol_UNK);
}
/***** End table *****/
HTM_TABLE_End ();
2020-01-08 23:49:57 +01:00
/***** 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 ();
2020-01-08 23:49:57 +01:00
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
}
/*****************************************************************************/
/****************************** 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 Map_Coordinates CtyAvgCoord;
2020-01-08 23:49:57 +01:00
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 */
Ctr_DB_GetCoordAndZoom (&CtyAvgCoord,&Zoom);
Map_CreateMap (SysCfg_MAP_CONTAINER_ID,&CtyAvgCoord,Zoom);
2020-01-08 23:49:57 +01:00
/* Add Mapbox Streets tile layer to our map */
Map_AddTileLayer ();
2020-01-08 23:49:57 +01:00
/* Get centers with coordinates */
NumCtrs = Ctr_DB_GetCtrsWithCoords (&mysql_res);
2020-01-08 23:49:57 +01:00
/* Add a marker and a popup for each center */
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_GetCenterDataByCod (&Ctr);
/* Get data of institution */
Ins.InsCod = Ctr.InsCod;
Ins_GetInstitDataByCod (&Ins);
/* Add marker */
Map_AddMarker (&Ctr.Coord);
/* Add popup */
Map_AddPopup (Ctr.ShrtName,Ins.ShrtName,
false); // Closed
}
2020-01-08 23:49:57 +01:00
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
2020-01-08 23:49:57 +01:00
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=\"LB DAT_STRONG_%s\"",The_GetSuffix ());
2020-01-08 23:49:57 +01:00
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,ParCod_None,-1L);
2020-01-08 23:49:57 +01:00
}
/*****************************************************************************/
/***************** Show country QR in country configuration ******************/
/*****************************************************************************/
static void SysCfg_QR (void)
{
HieCfg_QR (ParCod_None,-1L);
2020-01-08 23:49:57 +01:00
}
/*****************************************************************************/
/************ 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);
2020-01-08 23:49:57 +01:00
/* Data */
HTM_TD_Begin ("class=\"LB DAT_%s\"",The_GetSuffix ());
Frm_BeginFormGoTo (ActSeeCty);
HTM_BUTTON_Submit_Begin (Txt_Countries,"class=\"LB BT_LINK\"");
HTM_Unsigned (Cty_GetCachedNumCtysInSys ());
HTM_BUTTON_End ();
Frm_EndForm ();
HTM_TD_End ();
2020-01-08 23:49:57 +01:00
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);
2020-01-08 23:49:57 +01:00
/* Data */
HTM_TD_Begin ("class=\"LB DAT_%s\"",The_GetSuffix ());
HTM_Unsigned (Ins_GetCachedNumInssInSys ());
HTM_TD_End ();
2020-01-08 23:49:57 +01:00
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);
2020-01-08 23:49:57 +01:00
/* Data */
HTM_TD_Begin ("class=\"LB DAT_%s\"",The_GetSuffix ());
HTM_Unsigned (Deg_GetCachedNumDegsInSys ());
HTM_TD_End ();
2020-01-08 23:49:57 +01:00
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);
2020-01-08 23:49:57 +01:00
/* Data */
HTM_TD_Begin ("class=\"LB DAT_%s\"",The_GetSuffix ());
HTM_Unsigned (Crs_GetCachedNumCrssInSys ());
HTM_TD_End ();
2020-01-08 23:49:57 +01:00
HTM_TR_End ();
}