From 3b7a79f29a89db00ebe91129baf3707e86eccc6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Sun, 29 Dec 2019 14:02:58 +0100 Subject: [PATCH] Version19.104 --- Makefile | 6 +- swad_action.c | 33 +- swad_centre.c | 1278 +--------------------------------------- swad_centre.h | 23 +- swad_centre_config.c | 1320 ++++++++++++++++++++++++++++++++++++++++++ swad_centre_config.h | 57 ++ swad_changelog.h | 7 +- 7 files changed, 1412 insertions(+), 1312 deletions(-) create mode 100644 swad_centre_config.c create mode 100644 swad_centre_config.h diff --git a/Makefile b/Makefile index 11444d39a..8420385f2 100644 --- a/Makefile +++ b/Makefile @@ -29,9 +29,9 @@ OBJS = swad_account.o swad_action.o swad_agenda.o swad_alert.o \ swad_announcement.o swad_API.o swad_assignment.o swad_attendance.o \ swad_banner.o swad_box.o swad_button.o \ - swad_calendar.o swad_centre.o swad_chat.o swad_classroom.o \ - swad_config.o swad_connected.o swad_cookie.o swad_country.o \ - swad_course.o swad_course_config.o swad_cryptography.o \ + swad_calendar.o swad_centre.o swad_centre_config.o swad_chat.o \ + swad_classroom.o swad_config.o swad_connected.o swad_cookie.o \ + swad_country.o swad_course.o swad_course_config.o swad_cryptography.o \ swad_database.o swad_date.o swad_degree.o swad_degree_config.o \ swad_degree_type.o swad_department.o swad_duplicate.o \ swad_enrolment.o swad_exam.o \ diff --git a/swad_action.c b/swad_action.c index 47724d22f..deb8f75b5 100644 --- a/swad_action.c +++ b/swad_action.c @@ -35,6 +35,7 @@ #include "swad_announcement.h" #include "swad_banner.h" #include "swad_calendar.h" +#include "swad_centre_config.h" #include "swad_config.h" #include "swad_cookie.h" #include "swad_country.h" @@ -1829,26 +1830,26 @@ const struct Act_Actions Act_Actions[Act_NUM_ACTIONS] = // TabCtr ****************************************************************** // Actions in menu: - [ActSeeCtrInf ] = {1151, 0,TabCtr,ActSeeCtrInf , 0, 0, 0,0x3C7, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Ctr_ShowConfiguration ,"info" }, + [ActSeeCtrInf ] = {1151, 0,TabCtr,ActSeeCtrInf , 0, 0, 0,0x3C7, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,CtrCfg_ShowConfiguration ,"info" }, [ActSeeDeg ] = {1011, 1,TabCtr,ActSeeDeg , 0, 0, 0,0x3C7, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Deg_ShowDegsOfCurrentCtr ,"graduation-cap" }, [ActSeeCla ] = {1744, 2,TabCtr,ActSeeCla , 0, 0, 0,0x3C7, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Cla_SeeClassrooms ,"classroom" }, // Actions not in menu: - [ActPrnCtrInf ] = {1152,-1,TabUnk,ActSeeCtrInf , 0, 0, 0,0x3C7, 0, 0, 0,Act_CONT_NORM,Act_BRW_NEW_TAB,NULL ,Ctr_PrintConfiguration ,NULL}, - [ActChgCtrInsCfg ] = {1589,-1,TabUnk,ActSeeCtrInf , 0, 0, 0,0x200, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,Ctr_ChangeCtrInsInConfig ,Ctr_ContEditAfterChgCtrInConfig,NULL}, - [ActRenCtrShoCfg ] = {1595,-1,TabUnk,ActSeeCtrInf , 0, 0, 0,0x300, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,Ctr_RenameCentreShortInConfig ,Ctr_ContEditAfterChgCtrInConfig,NULL}, - [ActRenCtrFulCfg ] = {1594,-1,TabUnk,ActSeeCtrInf , 0, 0, 0,0x300, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,Ctr_RenameCentreFullInConfig ,Ctr_ContEditAfterChgCtrInConfig,NULL}, - [ActChgCtrPlcCfg ] = {1648,-1,TabUnk,ActSeeCtrInf , 0, 0, 0,0x380, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Ctr_ChangeCtrPlcInConfig ,NULL}, - [ActChgCtrLatCfg ] = {1815,-1,TabUnk,ActSeeCtrInf , 0, 0, 0,0x380, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Ctr_ChangeCtrLatitudeInConfig ,NULL}, - [ActChgCtrLgtCfg ] = {1816,-1,TabUnk,ActSeeCtrInf , 0, 0, 0,0x380, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Ctr_ChangeCtrLongitudeInConfig ,NULL}, - [ActChgCtrAltCfg ] = {1817,-1,TabUnk,ActSeeCtrInf , 0, 0, 0,0x380, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Ctr_ChangeCtrAltitudeInConfig ,NULL}, - [ActChgCtrWWWCfg ] = {1596,-1,TabUnk,ActSeeCtrInf , 0, 0, 0,0x380, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Ctr_ChangeCtrWWWInConfig ,NULL}, - [ActReqCtrLog ] = {1244,-1,TabUnk,ActSeeCtrInf , 0, 0, 0,0x380, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Ctr_RequestLogo ,NULL}, - [ActRecCtrLog ] = {1051,-1,TabUnk,ActSeeCtrInf , 0, 0, 0,0x380, 0, 0, 0,Act_CONT_DATA,Act_BRW_1ST_TAB,Ctr_ReceiveLogo ,Ctr_ShowConfiguration ,NULL}, - [ActRemCtrLog ] = {1342,-1,TabUnk,ActSeeCtrInf , 0, 0, 0,0x380, 0, 0, 0,Act_CONT_DATA,Act_BRW_1ST_TAB,Ctr_RemoveLogo ,Ctr_ShowConfiguration ,NULL}, - [ActReqCtrPho ] = {1160,-1,TabUnk,ActSeeCtrInf , 0, 0, 0,0x380, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Ctr_RequestPhoto ,NULL}, - [ActRecCtrPho ] = {1161,-1,TabUnk,ActSeeCtrInf , 0, 0, 0,0x380, 0, 0, 0,Act_CONT_DATA,Act_BRW_1ST_TAB,NULL ,Ctr_ReceivePhoto ,NULL}, - [ActChgCtrPhoAtt ] = {1159,-1,TabUnk,ActSeeCtrInf , 0, 0, 0,0x380, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Ctr_ChangeCtrPhotoAttribution ,NULL}, + [ActPrnCtrInf ] = {1152,-1,TabUnk,ActSeeCtrInf , 0, 0, 0,0x3C7, 0, 0, 0,Act_CONT_NORM,Act_BRW_NEW_TAB,NULL ,CtrCfg_PrintConfiguration ,NULL}, + [ActChgCtrInsCfg ] = {1589,-1,TabUnk,ActSeeCtrInf , 0, 0, 0,0x200, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,CtrCfg_ChangeCtrInsInConfig ,CtrCfg_ContEditAfterChgCtrInConfig,NULL}, + [ActRenCtrShoCfg ] = {1595,-1,TabUnk,ActSeeCtrInf , 0, 0, 0,0x300, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,CtrCfg_RenameCentreShortInConfig ,CtrCfg_ContEditAfterChgCtrInConfig,NULL}, + [ActRenCtrFulCfg ] = {1594,-1,TabUnk,ActSeeCtrInf , 0, 0, 0,0x300, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,CtrCfg_RenameCentreFullInConfig ,CtrCfg_ContEditAfterChgCtrInConfig,NULL}, + [ActChgCtrPlcCfg ] = {1648,-1,TabUnk,ActSeeCtrInf , 0, 0, 0,0x380, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,CtrCfg_ChangeCtrPlcInConfig ,NULL}, + [ActChgCtrLatCfg ] = {1815,-1,TabUnk,ActSeeCtrInf , 0, 0, 0,0x380, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,CtrCfg_ChangeCtrLatitudeInConfig ,NULL}, + [ActChgCtrLgtCfg ] = {1816,-1,TabUnk,ActSeeCtrInf , 0, 0, 0,0x380, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,CtrCfg_ChangeCtrLongitudeInConfig ,NULL}, + [ActChgCtrAltCfg ] = {1817,-1,TabUnk,ActSeeCtrInf , 0, 0, 0,0x380, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,CtrCfg_ChangeCtrAltitudeInConfig ,NULL}, + [ActChgCtrWWWCfg ] = {1596,-1,TabUnk,ActSeeCtrInf , 0, 0, 0,0x380, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,CtrCfg_ChangeCtrWWWInConfig ,NULL}, + [ActReqCtrLog ] = {1244,-1,TabUnk,ActSeeCtrInf , 0, 0, 0,0x380, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,CtrCfg_RequestLogo ,NULL}, + [ActRecCtrLog ] = {1051,-1,TabUnk,ActSeeCtrInf , 0, 0, 0,0x380, 0, 0, 0,Act_CONT_DATA,Act_BRW_1ST_TAB,CtrCfg_ReceiveLogo ,CtrCfg_ShowConfiguration ,NULL}, + [ActRemCtrLog ] = {1342,-1,TabUnk,ActSeeCtrInf , 0, 0, 0,0x380, 0, 0, 0,Act_CONT_DATA,Act_BRW_1ST_TAB,CtrCfg_RemoveLogo ,CtrCfg_ShowConfiguration ,NULL}, + [ActReqCtrPho ] = {1160,-1,TabUnk,ActSeeCtrInf , 0, 0, 0,0x380, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,CtrCfg_RequestPhoto ,NULL}, + [ActRecCtrPho ] = {1161,-1,TabUnk,ActSeeCtrInf , 0, 0, 0,0x380, 0, 0, 0,Act_CONT_DATA,Act_BRW_1ST_TAB,NULL ,CtrCfg_ReceivePhoto ,NULL}, + [ActChgCtrPhoAtt ] = {1159,-1,TabUnk,ActSeeCtrInf , 0, 0, 0,0x380, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,CtrCfg_ChangeCtrPhotoAttribution ,NULL}, [ActSeeDegTyp ] = {1013,-1,TabUnk,ActSeeDeg , 0, 0, 0,0x3C7, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,DT_SeeDegreeTypesInDegTab ,NULL}, [ActEdiDegTyp ] = { 573,-1,TabUnk,ActSeeDeg , 0, 0, 0,0x200, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,DT_EditDegreeTypes ,NULL}, diff --git a/swad_centre.c b/swad_centre.c index a1435498b..5d562bbef 100644 --- a/swad_centre.c +++ b/swad_centre.c @@ -25,30 +25,17 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -#define _GNU_SOURCE // For asprintf #include // For boolean type #include // For NULL -#include // For asprintf -#include // For calloc #include // For string functions -#include // For the macro WEXITSTATUS -#include // For unlink -#include "swad_box.h" #include "swad_centre.h" -#include "swad_constant.h" +#include "swad_centre_config.h" #include "swad_database.h" #include "swad_form.h" #include "swad_global.h" -#include "swad_help.h" -#include "swad_hierarchy.h" #include "swad_HTML.h" -#include "swad_institution.h" -#include "swad_language.h" #include "swad_logo.h" -#include "swad_map.h" -#include "swad_parameter.h" -#include "swad_string.h" /*****************************************************************************/ /************** External global variables from others modules ****************/ @@ -60,15 +47,6 @@ extern struct Globals Gbl; /***************************** Private constants *****************************/ /*****************************************************************************/ -// Centre photo will be saved with: -// - maximum width of Ctr_PHOTO_SAVED_MAX_HEIGHT -// - maximum height of Ctr_PHOTO_SAVED_MAX_HEIGHT -// - maintaining the original aspect ratio (aspect ratio recommended: 3:2) -#define Ctr_RECOMMENDED_ASPECT_RATIO "3:2" -#define Ctr_PHOTO_SAVED_MAX_WIDTH 768 -#define Ctr_PHOTO_SAVED_MAX_HEIGHT 512 -#define Ctr_PHOTO_SAVED_QUALITY 75 // 1 to 100 - /*****************************************************************************/ /******************************* Private types *******************************/ /*****************************************************************************/ @@ -83,29 +61,6 @@ static struct Centre *Ctr_EditingCtr = NULL; // Static variable to keep the cent /***************************** Private prototypes ****************************/ /*****************************************************************************/ -static void Ctr_Configuration (bool PrintView); -static void Ctr_PutIconsCtrConfig (void); -static void Ctr_PutIconToChangePhoto (void); -static void Ctr_ConfigTitle (bool PutLink); -static bool Ctr_GetIfMapIsAvailable (void); -static void Ctr_ConfigMap (void); -static void Ctr_ConfigLatitude (void); -static void Ctr_ConfigLongitude (void); -static void Ctr_ConfigAltitude (void); -static void Ctr_ConfigPhoto (bool PrintView,bool PutForm,bool PutLink, - const char PathPhoto[PATH_MAX + 1]); -static void Ctr_ConfigInstitution (bool PrintView,bool PutForm); -static void Ctr_ConfigFullName (bool PutForm); -static void Ctr_ConfigShrtName (bool PutForm); -static void Ctr_ConfigPlace (bool PutForm); -static void Ctr_ConfigWWW (bool PrintView,bool PutForm); -static void Ctr_ConfigShortcut (bool PrintView); -static void Ctr_ConfigQR (void); -static void Ctr_ConfigNumUsrs (void); -static void Ctr_ConfigNumDegs (void); -static void Ctr_ConfigNumCrss (void); -static void Ctr_ShowNumUsrsInCrssOfCtr (Rol_Role_t Role); - static void Ctr_ListCentres (void); static bool Ctr_CheckIfICanCreateCentres (void); static void Ctr_PutIconsListingCentres (void); @@ -118,8 +73,6 @@ static void Ctr_PutIconsEditingCentres (void); static void Ctr_GetDataOfCentreFromRow (struct Centre *Ctr,MYSQL_ROW row); -static void Ctr_GetPhotoAttribution (long CtrCod,char **PhotoAttribution); -static void Ctr_FreePhotoAttribution (char **PhotoAttribution); static void Ctr_ListCentresForEdition (void); static bool Ctr_CheckIfICanEditACentre (struct Centre *Ctr); static Ctr_StatusTxt_t Ctr_GetStatusTxtFromStatusBits (Ctr_Status_t Status); @@ -127,17 +80,8 @@ static Ctr_Status_t Ctr_GetStatusBitsFromStatusTxt (Ctr_StatusTxt_t StatusTxt); static void Ctr_PutParamOtherCtrCod (long CtrCod); -static void Ctr_UpdateCtrInsDB (long CtrCod,long InsCod); -static void Ctr_UpdateCtrPlcDB (long CtrCod,long NewPlcCod); - -static void Ctr_RenameCentre (struct Centre *Ctr,Cns_ShrtOrFullName_t ShrtOrFullName); -static bool Ctr_CheckIfCtrNameExistsInIns (const char *FieldName,const char *Name,long CtrCod,long InsCod); static void Ctr_UpdateInsNameDB (long CtrCod,const char *FieldName,const char *NewCtrName); -static void Ctr_UpdateCtrCoordinateDB (long CtrCod,const char *CoordField,double NewCoord); - -static void Ctr_UpdateCtrWWWDB (long CtrCod, - const char NewWWW[Cns_MAX_BYTES_WWW + 1]); static void Ctr_ShowAlertAndButtonToGoToCtr (void); static void Ctr_PutParamGoToCtr (void); @@ -284,712 +228,6 @@ void Ctr_DrawCentreLogoAndNameWithLink (struct Centre *Ctr,Act_Action_t Action, Frm_EndForm (); } -/*****************************************************************************/ -/****************** Show information of the current centre *******************/ -/*****************************************************************************/ - -void Ctr_ShowConfiguration (void) - { - Ctr_Configuration (false); - - /***** Show help to enrol me *****/ - Hlp_ShowHelpWhatWouldYouLikeToDo (); - } - -/*****************************************************************************/ -/****************** Print information of the current centre ******************/ -/*****************************************************************************/ - -void Ctr_PrintConfiguration (void) - { - Ctr_Configuration (true); - } - -/*****************************************************************************/ -/******************* Information of the current centre ***********************/ -/*****************************************************************************/ - -static void Ctr_Configuration (bool PrintView) - { - extern const char *Hlp_CENTRE_Information; - bool PutLink; - bool PutFormIns; - bool PutFormName; - bool PutFormPlc; - bool PutFormCoor; - bool PutFormWWW; - bool PutFormPhoto; - bool MapIsAvailable; - char PathPhoto[PATH_MAX + 1]; - bool PhotoExists; - - /***** Trivial check *****/ - if (Gbl.Hierarchy.Ctr.CtrCod <= 0) // No centre selected - return; - - /***** Initializations *****/ - PutLink = !PrintView && Gbl.Hierarchy.Ctr.WWW[0]; - PutFormIns = !PrintView && Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM; - PutFormName = !PrintView && Gbl.Usrs.Me.Role.Logged >= Rol_INS_ADM; - PutFormPlc = - PutFormCoor = - PutFormWWW = - PutFormPhoto = !PrintView && Gbl.Usrs.Me.Role.Logged >= Rol_CTR_ADM; - - /***** Begin box *****/ - if (PrintView) - Box_BoxBegin (NULL,NULL,NULL, - NULL,Box_NOT_CLOSABLE); - else - Box_BoxBegin (NULL,NULL,Ctr_PutIconsCtrConfig, - Hlp_CENTRE_Information,Box_NOT_CLOSABLE); - - /***** Title *****/ - Ctr_ConfigTitle (PutLink); - - /**************************** Left part ***********************************/ - HTM_DIV_Begin ("class=\"HIE_CFG_LEFT\""); - - /***** Begin table *****/ - HTM_TABLE_BeginWidePadding (2); - - /***** Institution *****/ - Ctr_ConfigInstitution (PrintView,PutFormIns); - - /***** Centre name *****/ - Ctr_ConfigFullName (PutFormName); - Ctr_ConfigShrtName (PutFormName); - - /***** Place *****/ - Ctr_ConfigPlace (PutFormPlc); - - /***** Coordinates *****/ - if (PutFormCoor) - { - Ctr_ConfigLatitude (); - Ctr_ConfigLongitude (); - Ctr_ConfigAltitude (); - } - - /***** Centre WWW *****/ - Ctr_ConfigWWW (PrintView,PutFormWWW); - - /***** Shortcut to the centre *****/ - Ctr_ConfigShortcut (PrintView); - - if (PrintView) - /***** QR code with link to the centre *****/ - Ctr_ConfigQR (); - else - { - /***** Number of users who claim to belong to this centre, - number of degrees, - number of courses *****/ - Ctr_ConfigNumUsrs (); - Ctr_ConfigNumDegs (); - Ctr_ConfigNumCrss (); - - /***** Number of users in courses of this centre *****/ - Ctr_ShowNumUsrsInCrssOfCtr (Rol_TCH); - Ctr_ShowNumUsrsInCrssOfCtr (Rol_NET); - Ctr_ShowNumUsrsInCrssOfCtr (Rol_STD); - Ctr_ShowNumUsrsInCrssOfCtr (Rol_UNK); - } - - /***** End table *****/ - HTM_TABLE_End (); - - /***** End of left part *****/ - HTM_DIV_End (); - - /**************************** Right part **********************************/ - /***** Check map *****/ - MapIsAvailable = Ctr_GetIfMapIsAvailable (); - - /***** Check photo *****/ - snprintf (PathPhoto,sizeof (PathPhoto), - "%s/%02u/%u/%u.jpg", - Cfg_PATH_CTR_PUBLIC, - (unsigned) (Gbl.Hierarchy.Ctr.CtrCod % 100), - (unsigned) Gbl.Hierarchy.Ctr.CtrCod, - (unsigned) Gbl.Hierarchy.Ctr.CtrCod); - PhotoExists = Fil_CheckIfPathExists (PathPhoto); - - if (MapIsAvailable || PhotoExists) - { - HTM_DIV_Begin ("class=\"HIE_CFG_RIGHT\""); - - /***** Centre map *****/ - if (MapIsAvailable) - Ctr_ConfigMap (); - - /***** Centre photo *****/ - if (PhotoExists) - Ctr_ConfigPhoto (PrintView,PutFormPhoto,PutLink,PathPhoto); - - HTM_DIV_End (); - } - - /***** End box *****/ - Box_BoxEnd (); - } - -/*****************************************************************************/ -/************ Put contextual icons in configuration of a centre **************/ -/*****************************************************************************/ - -static void Ctr_PutIconsCtrConfig (void) - { - /***** Put icon to print info about centre *****/ - Ico_PutContextualIconToPrint (ActPrnCtrInf,NULL); - - /***** Put icon to view places *****/ - Plc_PutIconToViewPlaces (); - - if (Gbl.Usrs.Me.Role.Logged >= Rol_CTR_ADM) - // Only centre admins, institution admins and system admins - // have permission to upload logo and photo of the centre - { - /***** Put icon to upload logo of centre *****/ - Lgo_PutIconToChangeLogo (Hie_CTR); - - /***** Put icon to upload photo of centre *****/ - Ctr_PutIconToChangePhoto (); - } - } - -/*****************************************************************************/ -/************* Put contextual icons to upload photo of centre ****************/ -/*****************************************************************************/ - -static void Ctr_PutIconToChangePhoto (void) - { - extern const char *Txt_Change_photo; - extern const char *Txt_Upload_photo; - char PathPhoto[PATH_MAX + 1]; - bool PhotoExists; - - /***** Link to upload photo of centre *****/ - snprintf (PathPhoto,sizeof (PathPhoto), - "%s/%02u/%u/%u.jpg", - Cfg_PATH_CTR_PUBLIC, - (unsigned) (Gbl.Hierarchy.Ctr.CtrCod % 100), - (unsigned) Gbl.Hierarchy.Ctr.CtrCod, - (unsigned) Gbl.Hierarchy.Ctr.CtrCod); - PhotoExists = Fil_CheckIfPathExists (PathPhoto); - Lay_PutContextualLinkOnlyIcon (ActReqCtrPho,NULL,NULL, - "camera.svg", - PhotoExists ? Txt_Change_photo : - Txt_Upload_photo); - } - -/*****************************************************************************/ -/******************** Show title in centre configuration *********************/ -/*****************************************************************************/ - -static void Ctr_ConfigTitle (bool PutLink) - { - Hie_ConfigTitle (PutLink, - Hie_CTR, // Logo scope - Gbl.Hierarchy.Ctr.CtrCod, // Logo code - Gbl.Hierarchy.Ctr.ShrtName, // Logo short name - Gbl.Hierarchy.Ctr.FullName, // Logo full name - Gbl.Hierarchy.Ctr.WWW, // Logo www - Gbl.Hierarchy.Ctr.FullName); // Text full name - } - -/*****************************************************************************/ -/******************** Check if centre map should be shown ********************/ -/*****************************************************************************/ - -static bool Ctr_GetIfMapIsAvailable (void) - { - /***** Coordinates 0, 0 means not set ==> don't show map *****/ - return (bool) (Gbl.Hierarchy.Ctr.Coord.Latitude || - Gbl.Hierarchy.Ctr.Coord.Longitude); - } - -/*****************************************************************************/ -/****************************** Draw centre map ******************************/ -/*****************************************************************************/ - -static void Ctr_ConfigMap (void) - { - /* https://leafletjs.com/examples/quick-start/ */ - /***** Leaflet CSS *****/ - HTM_Txt (""); - - /***** Leaflet script *****/ - /* Put this AFTER Leaflet's CSS */ - HTM_Txt (""); - - /***** Container for the map *****/ - HTM_DIV_Begin ("id=\"centre_mapid\""); - HTM_DIV_End (); - - /***** Script to draw the map *****/ - HTM_SCRIPT_Begin (NULL,NULL); - Str_SetDecimalPointToUS (); // To write the decimal point as a dot - - /* Let's create a map of the center of London with pretty Mapbox Streets tiles */ - HTM_TxtF ("\tvar mymap = L.map('centre_mapid').setView([%lg, %lg], 16);\n", - Gbl.Hierarchy.Ctr.Coord.Latitude, - Gbl.Hierarchy.Ctr.Coord.Longitude); - - /* Next we'll add a tile layer to add to our map, - in this case it's a Mapbox Streets tile layer. - Creating a tile layer usually involves - setting the URL template for the tile images, - the attribution text and the maximum zoom level of the layer. - In this example we'll use the mapbox/streets-v11 tiles - from Mapbox's Static Tiles API - (in order to use tiles from Mapbox, - you must also request an access token).*/ - HTM_Txt ("\tL.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}', {" - "attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA, Imagery © Mapbox'," - "maxZoom: 20," - "id: 'mapbox/streets-v11'," - "accessToken: 'pk.eyJ1IjoiYWNhbmFzIiwiYSI6ImNrNGFoNXFxOTAzdHozcnA4d3Y0M3BwOGkifQ.uSg754Lv2iZEJg0W2pjiOQ'" - "}).addTo(mymap);\n"); - - /* Marker */ - HTM_TxtF ("\tvar marker = L.marker([%lg, %lg]).addTo(mymap);", - Gbl.Hierarchy.Ctr.Coord.Latitude, - Gbl.Hierarchy.Ctr.Coord.Longitude); - - HTM_TxtF ("\tmarker.bindPopup(\"%s
%s\").openPopup();", - Gbl.Hierarchy.Ctr.ShrtName, - Gbl.Hierarchy.Ins.ShrtName); - - Str_SetDecimalPointToLocal (); // Return to local system - HTM_SCRIPT_End (); - } - -/*****************************************************************************/ -/************************** Edit centre coordinates **************************/ -/*****************************************************************************/ - -static void Ctr_ConfigLatitude (void) - { - extern const char *Txt_Latitude; - - /***** Latitude *****/ - HTM_TR_Begin (NULL); - - /* Label */ - Frm_LabelColumn ("RT","Latitude",Txt_Latitude); - - /* Data */ - HTM_TD_Begin ("class=\"LB\""); - Frm_StartForm (ActChgCtrLatCfg); - HTM_INPUT_FLOAT ("Latitude", - -90.0, // South Pole - 90.0, // North Pole - 0.0, // step="any" - Gbl.Hierarchy.Ctr.Coord.Latitude,false, - "class=\"INPUT_COORD\" required=\"required\""); - Frm_EndForm (); - HTM_TD_End (); - - HTM_TR_End (); - } - -static void Ctr_ConfigLongitude (void) - { - extern const char *Txt_Longitude; - - /***** Longitude *****/ - HTM_TR_Begin (NULL); - - /* Label */ - Frm_LabelColumn ("RT","Longitude",Txt_Longitude); - - /* Data */ - HTM_TD_Begin ("class=\"LB\""); - Frm_StartForm (ActChgCtrLgtCfg); - HTM_INPUT_FLOAT ("Longitude", - -180.0, // West - 180.0, // East - 0.0, // step="any" - Gbl.Hierarchy.Ctr.Coord.Longitude,false, - "class=\"INPUT_COORD\" required=\"required\""); - Frm_EndForm (); - HTM_TD_End (); - - HTM_TR_End (); - } - -static void Ctr_ConfigAltitude (void) - { - extern const char *Txt_Altitude; - - /***** Altitude *****/ - HTM_TR_Begin (NULL); - - /* Label */ - Frm_LabelColumn ("RT","Altitude",Txt_Altitude); - - /* Data */ - HTM_TD_Begin ("class=\"LB\""); - Frm_StartForm (ActChgCtrAltCfg); - HTM_INPUT_FLOAT ("Altitude", - -413.0, // Dead Sea shore - 8848.0, // Mount Everest - 0.0, // step="any" - Gbl.Hierarchy.Ctr.Coord.Altitude,false, - "class=\"INPUT_COORD\" required=\"required\""); - Frm_EndForm (); - HTM_TD_End (); - - HTM_TR_End (); - } - -/*****************************************************************************/ -/***************************** Draw centre photo *****************************/ -/*****************************************************************************/ - -static void Ctr_ConfigPhoto (bool PrintView,bool PutForm,bool PutLink, - const char PathPhoto[PATH_MAX + 1]) - { - char *PhotoAttribution = NULL; - char *URL; - char *Icon; - - /***** Trivial checks *****/ - if (!PathPhoto) - return; - if (!PathPhoto[0]) - return; - - /***** Get photo attribution *****/ - Ctr_GetPhotoAttribution (Gbl.Hierarchy.Ctr.CtrCod,&PhotoAttribution); - - /***** Photo image *****/ - HTM_DIV_Begin ("class=\"DAT_SMALL CM\""); - if (PutLink) - HTM_A_Begin ("href=\"%s\" target=\"_blank\" class=\"DAT_N\"", - Gbl.Hierarchy.Ctr.WWW); - if (asprintf (&URL,"%s/%02u/%u", - Cfg_URL_CTR_PUBLIC, - (unsigned) (Gbl.Hierarchy.Ctr.CtrCod % 100), - (unsigned) Gbl.Hierarchy.Ctr.CtrCod) < 0) - Lay_NotEnoughMemoryExit (); - if (asprintf (&Icon,"%u.jpg", - (unsigned) Gbl.Hierarchy.Ctr.CtrCod) < 0) - Lay_NotEnoughMemoryExit (); - HTM_IMG (URL,Icon,Gbl.Hierarchy.Ctr.FullName, - "class=\"%s\"",PrintView ? "CENTRE_PHOTO_PRINT" : - "CENTRE_PHOTO_SHOW"); - free (Icon); - free (URL); - if (PutLink) - HTM_A_End (); - HTM_DIV_End (); - - /****** Photo attribution ******/ - if (PutForm) - { - HTM_DIV_Begin ("class=\"CM\""); - Frm_StartForm (ActChgCtrPhoAtt); - HTM_TEXTAREA_Begin ("id=\"AttributionArea\" name=\"Attribution\" rows=\"3\"" - " onchange=\"document.getElementById('%s').submit();return false;\"", - Gbl.Form.Id); - if (PhotoAttribution) - HTM_Txt (PhotoAttribution); - HTM_TEXTAREA_End (); - Frm_EndForm (); - HTM_DIV_End (); - } - else if (PhotoAttribution) - { - HTM_DIV_Begin ("class=\"ATTRIBUTION\""); - HTM_Txt (PhotoAttribution); - HTM_DIV_End (); - } - - /****** Free memory used for photo attribution ******/ - Ctr_FreePhotoAttribution (&PhotoAttribution); - } - -/*****************************************************************************/ -/***************** Show institution in centre configuration ******************/ -/*****************************************************************************/ - -static void Ctr_ConfigInstitution (bool PrintView,bool PutForm) - { - extern const char *Txt_Institution; - extern const char *Txt_Go_to_X; - unsigned NumIns; - - /***** Institution *****/ - HTM_TR_Begin (NULL); - - /* Label */ - Frm_LabelColumn ("RT",PutForm ? "OthInsCod" : - NULL, - Txt_Institution); - - /* Data */ - HTM_TD_Begin ("class=\"DAT LB\""); - if (PutForm) - { - /* Get list of institutions of the current country */ - Ins_GetListInstitutions (Gbl.Hierarchy.Cty.CtyCod,Ins_GET_BASIC_DATA); - - /* Put form to select institution */ - Frm_StartForm (ActChgCtrInsCfg); - HTM_SELECT_Begin (true, - "id=\"OthInsCod\" name=\"OthInsCod\"" - " class=\"INPUT_SHORT_NAME\""); - for (NumIns = 0; - NumIns < Gbl.Hierarchy.Cty.Inss.Num; - NumIns++) - HTM_OPTION (HTM_Type_LONG,&Gbl.Hierarchy.Cty.Inss.Lst[NumIns].InsCod, - Gbl.Hierarchy.Cty.Inss.Lst[NumIns].InsCod == Gbl.Hierarchy.Ins.InsCod,false, - "%s",Gbl.Hierarchy.Cty.Inss.Lst[NumIns].ShrtName); - HTM_SELECT_End (); - Frm_EndForm (); - - /* Free list of institutions */ - Ins_FreeListInstitutions (); - } - else // I can not move centre to another institution - { - if (!PrintView) - { - Frm_StartFormGoTo (ActSeeInsInf); - Ins_PutParamInsCod (Gbl.Hierarchy.Ins.InsCod); - snprintf (Gbl.Title,sizeof (Gbl.Title), - Txt_Go_to_X, - Gbl.Hierarchy.Ins.ShrtName); - HTM_BUTTON_SUBMIT_Begin (Gbl.Title,"BT_LINK LT DAT",NULL); - } - Lgo_DrawLogo (Hie_INS,Gbl.Hierarchy.Ins.InsCod,Gbl.Hierarchy.Ins.ShrtName, - 20,"LM",true); - HTM_NBSP (); - HTM_Txt (Gbl.Hierarchy.Ins.FullName); - if (!PrintView) - { - HTM_BUTTON_End (); - Frm_EndForm (); - } - } - HTM_TD_End (); - - HTM_TR_End (); - } - -/*****************************************************************************/ -/************** Show centre full name in centre configuration ****************/ -/*****************************************************************************/ - -static void Ctr_ConfigFullName (bool PutForm) - { - extern const char *Txt_Centre; - - Hie_ConfigFullName (PutForm,Txt_Centre,ActRenCtrFulCfg, - Gbl.Hierarchy.Ctr.FullName); - } - -/*****************************************************************************/ -/************** Show centre short name in centre configuration ***************/ -/*****************************************************************************/ - -static void Ctr_ConfigShrtName (bool PutForm) - { - Hie_ConfigShrtName (PutForm,ActRenCtrShoCfg,Gbl.Hierarchy.Ctr.ShrtName); - } - -/*****************************************************************************/ -/**************** Show centre place in centre configuration ******************/ -/*****************************************************************************/ - -static void Ctr_ConfigPlace (bool PutForm) - { - extern const char *Txt_Place; - extern const char *Txt_Another_place; - struct Place Plc; - unsigned NumPlc; - - /***** Get data of place *****/ - Plc.PlcCod = Gbl.Hierarchy.Ctr.PlcCod; - Plc_GetDataOfPlaceByCod (&Plc); - - /***** Place *****/ - HTM_TR_Begin (NULL); - - /* Label */ - Frm_LabelColumn ("RT",PutForm ? "PlcCod" : - NULL, - Txt_Place); - - /* Data */ - HTM_TD_Begin ("class=\"DAT LB\""); - if (PutForm) - { - /* Get list of places of the current institution */ - Gbl.Plcs.SelectedOrder = Plc_ORDER_BY_PLACE; - Plc_GetListPlaces (); - - /* Put form to select place */ - Frm_StartForm (ActChgCtrPlcCfg); - HTM_SELECT_Begin (true, - "name=\"PlcCod\" class=\"INPUT_SHORT_NAME\""); - HTM_OPTION (HTM_Type_STRING,"0", - Gbl.Hierarchy.Ctr.PlcCod == 0,false, - "%s",Txt_Another_place); - for (NumPlc = 0; - NumPlc < Gbl.Plcs.Num; - NumPlc++) - HTM_OPTION (HTM_Type_LONG,&Gbl.Plcs.Lst[NumPlc].PlcCod, - Gbl.Plcs.Lst[NumPlc].PlcCod == Gbl.Hierarchy.Ctr.PlcCod,false, - "%s",Gbl.Plcs.Lst[NumPlc].ShrtName); - HTM_SELECT_End (); - Frm_EndForm (); - - /* Free list of places */ - Plc_FreeListPlaces (); - } - else // I can not change centre place - HTM_Txt (Plc.FullName); - HTM_TD_End (); - - HTM_TR_End (); - } - -/*****************************************************************************/ -/***************** Show centre WWW in centre configuration *******************/ -/*****************************************************************************/ - -static void Ctr_ConfigWWW (bool PrintView,bool PutForm) - { - Hie_ConfigWWW (PrintView,PutForm,ActChgCtrWWWCfg,Gbl.Hierarchy.Ctr.WWW); - } - -/*****************************************************************************/ -/*************** Show centre shortcut in centre configuration ****************/ -/*****************************************************************************/ - -static void Ctr_ConfigShortcut (bool PrintView) - { - Hie_ConfigShortcut (PrintView,"ctr",Gbl.Hierarchy.Ctr.CtrCod); - } - -/*****************************************************************************/ -/****************** Show centre QR in centre configuration *******************/ -/*****************************************************************************/ - -static void Ctr_ConfigQR (void) - { - Hie_ConfigQR ("ctr",Gbl.Hierarchy.Ctr.CtrCod); - } - -/*****************************************************************************/ -/*** Show number of users who claim to belong to centre in centre config. ****/ -/*****************************************************************************/ - -static void Ctr_ConfigNumUsrs (void) - { - extern const char *Txt_Users_of_the_centre; - - /***** Number of users *****/ - HTM_TR_Begin (NULL); - - /* Label */ - Frm_LabelColumn ("RT",NULL,Txt_Users_of_the_centre); - - /* Data */ - HTM_TD_Begin ("class=\"DAT LB\""); - HTM_Unsigned (Usr_GetNumUsrsWhoClaimToBelongToCtr (Gbl.Hierarchy.Ctr.CtrCod)); - HTM_TD_End (); - - HTM_TR_End (); - } - -/*****************************************************************************/ -/************** Show number of degrees in centre configuration ***************/ -/*****************************************************************************/ - -static void Ctr_ConfigNumDegs (void) - { - extern const char *Txt_Degrees; - extern const char *Txt_Degrees_of_CENTRE_X; - - /***** Number of degrees *****/ - HTM_TR_Begin (NULL); - - /* Label */ - Frm_LabelColumn ("RT",NULL,Txt_Degrees); - - /* Data */ - HTM_TD_Begin ("class=\"LB\""); - Frm_StartFormGoTo (ActSeeDeg); - Ctr_PutParamCtrCod (Gbl.Hierarchy.Ctr.CtrCod); - snprintf (Gbl.Title,sizeof (Gbl.Title), - Txt_Degrees_of_CENTRE_X, - Gbl.Hierarchy.Ctr.ShrtName); - HTM_BUTTON_SUBMIT_Begin (Gbl.Title,"BT_LINK DAT",NULL); - HTM_Unsigned (Deg_GetNumDegsInCtr (Gbl.Hierarchy.Ctr.CtrCod)); - HTM_BUTTON_End (); - Frm_EndForm (); - HTM_TD_End (); - - HTM_TR_End (); - } - -/*****************************************************************************/ -/************** Show number of courses in centre configuration ***************/ -/*****************************************************************************/ - -static void Ctr_ConfigNumCrss (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\""); - HTM_Unsigned (Crs_GetNumCrssInCtr (Gbl.Hierarchy.Ctr.CtrCod)); - HTM_TD_End (); - - HTM_TR_End (); - } - -/*****************************************************************************/ -/**************** Number of users in courses of this centre ******************/ -/*****************************************************************************/ - -static void Ctr_ShowNumUsrsInCrssOfCtr (Rol_Role_t Role) - { - extern const char *Txt_Users_in_courses; - extern const char *Txt_ROLES_PLURAL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS]; - - /***** Number of users in courses *****/ - HTM_TR_Begin (NULL); - - /* Label */ - Frm_LabelColumn ("RT",NULL, - Role == Rol_UNK ? Txt_Users_in_courses : - Txt_ROLES_PLURAL_Abc[Role][Usr_SEX_UNKNOWN]); - - /* Data */ - HTM_TD_Begin ("class=\"DAT LB\""); - HTM_Unsigned (Usr_GetNumUsrsInCrssOfCtr (Role,Gbl.Hierarchy.Ctr.CtrCod)); - HTM_TD_End (); - - HTM_TR_End (); - } - /*****************************************************************************/ /*************** Show the centres of the current institution *****************/ /*****************************************************************************/ @@ -1605,57 +843,6 @@ void Ctr_GetShortNameOfCentreByCod (struct Centre *Ctr) } } -/*****************************************************************************/ -/******************* Get photo attribution from database *********************/ -/*****************************************************************************/ - -static void Ctr_GetPhotoAttribution (long CtrCod,char **PhotoAttribution) - { - MYSQL_RES *mysql_res; - MYSQL_ROW row; - size_t Length; - - /***** Free possible former photo attribution *****/ - Ctr_FreePhotoAttribution (PhotoAttribution); - - /***** Get photo attribution from database *****/ - if (DB_QuerySELECT (&mysql_res,"can not get photo attribution", - "SELECT PhotoAttribution" - " FROM centres WHERE CtrCod=%ld", - CtrCod)) - { - /* Get row */ - row = mysql_fetch_row (mysql_res); - - /* Get the attribution of the photo of the centre (row[0]) */ - if (row[0]) - if (row[0][0]) - { - Length = strlen (row[0]); - if (((*PhotoAttribution) = (char *) malloc (Length + 1)) == NULL) - Lay_ShowErrorAndExit ("Error allocating memory for photo attribution."); - Str_Copy (*PhotoAttribution,row[0], - Length); - } - } - - /***** Free structure that stores the query result *****/ - DB_FreeMySQLResult (&mysql_res); - } - -/*****************************************************************************/ -/****************** Free memory used for photo attribution *******************/ -/*****************************************************************************/ - -static void Ctr_FreePhotoAttribution (char **PhotoAttribution) - { - if (*PhotoAttribution) - { - free (*PhotoAttribution); - *PhotoAttribution = NULL; - } - } - /*****************************************************************************/ /**************************** Free list of centres ***************************/ /*****************************************************************************/ @@ -2078,85 +1265,6 @@ void Ctr_RemoveCentre (void) } } -/*****************************************************************************/ -/********************* Change the institution of a centre ********************/ -/*****************************************************************************/ - -void Ctr_ChangeCtrInsInConfig (void) - { - extern const char *Txt_The_centre_X_already_exists; - extern const char *Txt_The_centre_X_has_been_moved_to_the_institution_Y; - struct Instit NewIns; - - /***** Get parameter with institution code *****/ - NewIns.InsCod = Ins_GetAndCheckParamOtherInsCod (1); - - /***** Check if institution has changed *****/ - if (NewIns.InsCod != Gbl.Hierarchy.Ctr.InsCod) - { - /***** Get data of new institution *****/ - Ins_GetDataOfInstitutionByCod (&NewIns,Ins_GET_BASIC_DATA); - - /***** Check if it already exists a centre with the same name in the new institution *****/ - if (Ctr_CheckIfCtrNameExistsInIns ("ShortName", - Gbl.Hierarchy.Ctr.ShrtName, - Gbl.Hierarchy.Ctr.CtrCod, - NewIns.InsCod)) - /***** Create warning message *****/ - Ale_CreateAlert (Ale_WARNING,NULL, - Txt_The_centre_X_already_exists, - Gbl.Hierarchy.Ctr.ShrtName); - else if (Ctr_CheckIfCtrNameExistsInIns ("FullName", - Gbl.Hierarchy.Ctr.FullName, - Gbl.Hierarchy.Ctr.CtrCod, - NewIns.InsCod)) - /***** Create warning message *****/ - Ale_CreateAlert (Ale_WARNING,NULL, - Txt_The_centre_X_already_exists, - Gbl.Hierarchy.Ctr.FullName); - else - { - /***** Update institution in table of centres *****/ - Ctr_UpdateCtrInsDB (Gbl.Hierarchy.Ctr.CtrCod,NewIns.InsCod); - Gbl.Hierarchy.Ctr.InsCod = - Gbl.Hierarchy.Ins.InsCod = NewIns.InsCod; - - /***** Initialize again current course, degree, centre... *****/ - Hie_InitHierarchy (); - - /***** Create message to show the change made *****/ - Ale_CreateAlert (Ale_SUCCESS,NULL, - Txt_The_centre_X_has_been_moved_to_the_institution_Y, - Gbl.Hierarchy.Ctr.FullName,NewIns.FullName); - } - } - } - -/*****************************************************************************/ -/** Show message of success after changing a centre in centre configuration **/ -/*****************************************************************************/ - -void Ctr_ContEditAfterChgCtrInConfig (void) - { - /***** Write error/success message *****/ - Ale_ShowAlerts (NULL); - - /***** Show the form again *****/ - Ctr_ShowConfiguration (); - } - -/*****************************************************************************/ -/******************* Update institution in table of centres ******************/ -/*****************************************************************************/ - -static void Ctr_UpdateCtrInsDB (long CtrCod,long InsCod) - { - /***** Update institution in table of centres *****/ - DB_QueryUPDATE ("can not update the institution of a centre", - "UPDATE centres SET InsCod=%ld WHERE CtrCod=%ld", - InsCod,CtrCod); - } - /*****************************************************************************/ /************************ Change the place of a centre ***********************/ /*****************************************************************************/ @@ -2188,30 +1296,11 @@ void Ctr_ChangeCtrPlc (void) Txt_The_place_of_the_centre_has_changed); } -void Ctr_ChangeCtrPlcInConfig (void) - { - extern const char *Txt_The_place_of_the_centre_has_changed; - long NewPlcCod; - - /***** Get parameter with place code *****/ - NewPlcCod = Plc_GetParamPlcCod (); - - /***** Update place in table of centres *****/ - Ctr_UpdateCtrPlcDB (Gbl.Hierarchy.Ctr.CtrCod,NewPlcCod); - Gbl.Hierarchy.Ctr.PlcCod = NewPlcCod; - - /***** Write message to show the change made *****/ - Ale_ShowAlert (Ale_SUCCESS,Txt_The_place_of_the_centre_has_changed); - - /***** Show the form again *****/ - Ctr_ShowConfiguration (); - } - /*****************************************************************************/ /************** Update database changing old place by new place **************/ /*****************************************************************************/ -static void Ctr_UpdateCtrPlcDB (long CtrCod,long NewPlcCod) +void Ctr_UpdateCtrPlcDB (long CtrCod,long NewPlcCod) { DB_QueryUPDATE ("can not update the place of a centre", "UPDATE centres SET PlcCod=%ld WHERE CtrCod=%ld", @@ -2242,25 +1331,11 @@ void Ctr_RenameCentreFull (void) Ctr_RenameCentre (Ctr_EditingCtr,Cns_FULL_NAME); } -/*****************************************************************************/ -/*************** Change the name of a centre in configuration ****************/ -/*****************************************************************************/ - -void Ctr_RenameCentreShortInConfig (void) - { - Ctr_RenameCentre (&Gbl.Hierarchy.Ctr,Cns_SHRT_NAME); - } - -void Ctr_RenameCentreFullInConfig (void) - { - Ctr_RenameCentre (&Gbl.Hierarchy.Ctr,Cns_FULL_NAME); - } - /*****************************************************************************/ /************************ Change the name of a centre ************************/ /*****************************************************************************/ -static void Ctr_RenameCentre (struct Centre *Ctr,Cns_ShrtOrFullName_t ShrtOrFullName) +void Ctr_RenameCentre (struct Centre *Ctr,Cns_ShrtOrFullName_t ShrtOrFullName) { extern const char *Txt_The_centre_X_already_exists; extern const char *Txt_The_centre_X_has_been_renamed_as_Y; @@ -2334,7 +1409,8 @@ static void Ctr_RenameCentre (struct Centre *Ctr,Cns_ShrtOrFullName_t ShrtOrFull /********************* Check if the name of centre exists ********************/ /*****************************************************************************/ -static bool Ctr_CheckIfCtrNameExistsInIns (const char *FieldName,const char *Name,long CtrCod,long InsCod) +bool Ctr_CheckIfCtrNameExistsInIns (const char *FieldName,const char *Name, + long CtrCod,long InsCod) { /***** Get number of centres with a name from database *****/ return (DB_QueryCOUNT ("can not check if the name of a centre" @@ -2356,107 +1432,6 @@ static void Ctr_UpdateInsNameDB (long CtrCod,const char *FieldName,const char *N FieldName,NewCtrName,CtrCod); } -/*****************************************************************************/ -/********************** Change the latitude of a centre **********************/ -/*****************************************************************************/ - -void Ctr_ChangeCtrLatitudeInConfig (void) - { - extern const char *Txt_The_new_latitude_is_X; - char LatitudeStr[64]; - double NewLatitude; - - /***** Get latitude *****/ - Par_GetParToText ("Latitude",LatitudeStr,sizeof (LatitudeStr) - 1); - NewLatitude = Str_GetDoubleFromStr (LatitudeStr); - if (NewLatitude < -90.0) - NewLatitude = -90.0; // South Pole - else if (NewLatitude > 90.0) - NewLatitude = 90.0; // North Pole - - /***** Update database changing old latitude by new latitude *****/ - Ctr_UpdateCtrCoordinateDB (Gbl.Hierarchy.Ctr.CtrCod,"Latitude",NewLatitude); - Gbl.Hierarchy.Ctr.Coord.Latitude = NewLatitude; - - /***** Write message to show the change made *****/ - Ale_ShowAlert (Ale_SUCCESS,Txt_The_new_latitude_is_X,NewLatitude); - - /***** Show the form again *****/ - Ctr_ShowConfiguration (); - } - -/*****************************************************************************/ -/********************** Change the longitude of a centre **********************/ -/*****************************************************************************/ - -void Ctr_ChangeCtrLongitudeInConfig (void) - { - extern const char *Txt_The_new_longitude_is_X; - char LongitudeStr[64]; - double NewLongitude; - - /***** Get longitude *****/ - Par_GetParToText ("Longitude",LongitudeStr,sizeof (LongitudeStr) - 1); - NewLongitude = Str_GetDoubleFromStr (LongitudeStr); - if (NewLongitude < -180.0) - NewLongitude = -180.0; // West - else if (NewLongitude > 180.0) - NewLongitude = 180.0; // East - - /***** Update database changing old longitude by new longitude *****/ - Ctr_UpdateCtrCoordinateDB (Gbl.Hierarchy.Ctr.CtrCod,"Longitude",NewLongitude); - Gbl.Hierarchy.Ctr.Coord.Longitude = NewLongitude; - - /***** Write message to show the change made *****/ - Ale_ShowAlert (Ale_SUCCESS,Txt_The_new_longitude_is_X,NewLongitude); - - /***** Show the form again *****/ - Ctr_ShowConfiguration (); - } - -/*****************************************************************************/ -/********************** Change the latitude of a centre **********************/ -/*****************************************************************************/ - -void Ctr_ChangeCtrAltitudeInConfig (void) - { - extern const char *Txt_The_new_altitude_is_X; - char AltitudeStr[64]; - double NewAltitude; - - /***** Get altitude *****/ - Par_GetParToText ("Altitude",AltitudeStr,sizeof (AltitudeStr) - 1); - NewAltitude = Str_GetDoubleFromStr (AltitudeStr); - if (NewAltitude < -413.0) - NewAltitude = -413.0; // Dead Sea shore - else if (NewAltitude > 8848.0) - NewAltitude = 8848.0; // Mount Everest - - /***** Update database changing old altitude by new altitude *****/ - Ctr_UpdateCtrCoordinateDB (Gbl.Hierarchy.Ctr.CtrCod,"Altitude",NewAltitude); - Gbl.Hierarchy.Ctr.Coord.Altitude = NewAltitude; - - /***** Write message to show the change made *****/ - Ale_ShowAlert (Ale_SUCCESS,Txt_The_new_altitude_is_X,NewAltitude); - - /***** Show the form again *****/ - Ctr_ShowConfiguration (); - } - -/*****************************************************************************/ -/******** Update database changing old coordinate by new coordinate **********/ -/*****************************************************************************/ - -static void Ctr_UpdateCtrCoordinateDB (long CtrCod,const char *CoordField,double NewCoord) - { - /***** Update database changing old coordinate by new coordinate *****/ - Str_SetDecimalPointToUS (); // To write the decimal point as a dot - DB_QueryUPDATE ("can not update a coordinate of a centre", - "UPDATE centres SET %s='%lg' WHERE CtrCod=%ld", - CoordField,NewCoord,CtrCod); - Str_SetDecimalPointToLocal (); // Return to local system - } - /*****************************************************************************/ /************************* Change the URL of a centre ************************/ /*****************************************************************************/ @@ -2496,40 +1471,11 @@ void Ctr_ChangeCtrWWW (void) Ale_CreateAlertYouCanNotLeaveFieldEmpty (); } -void Ctr_ChangeCtrWWWInConfig (void) - { - extern const char *Txt_The_new_web_address_is_X; - char NewWWW[Cns_MAX_BYTES_WWW + 1]; - - /***** Get parameters from form *****/ - /* Get the new WWW for the centre */ - Par_GetParToText ("WWW",NewWWW,Cns_MAX_BYTES_WWW); - - /***** Check if new WWW is empty *****/ - if (NewWWW[0]) - { - /***** Update database changing old WWW by new WWW *****/ - Ctr_UpdateCtrWWWDB (Gbl.Hierarchy.Ctr.CtrCod,NewWWW); - Str_Copy (Gbl.Hierarchy.Ctr.WWW,NewWWW, - Cns_MAX_BYTES_WWW); - - /***** Write message to show the change made *****/ - Ale_ShowAlert (Ale_SUCCESS,Txt_The_new_web_address_is_X, - NewWWW); - } - else - Ale_CreateAlertYouCanNotLeaveFieldEmpty (); - - /***** Show the form again *****/ - Ctr_ShowConfiguration (); - } - /*****************************************************************************/ /**************** Update database changing old WWW by new WWW ****************/ /*****************************************************************************/ -static void Ctr_UpdateCtrWWWDB (long CtrCod, - const char NewWWW[Cns_MAX_BYTES_WWW + 1]) +void Ctr_UpdateCtrWWWDB (long CtrCod,const char NewWWW[Cns_MAX_BYTES_WWW + 1]) { /***** Update database changing old WWW by new WWW *****/ DB_QueryUPDATE ("can not update the web of a centre", @@ -2626,218 +1572,6 @@ static void Ctr_PutParamGoToCtr (void) Ctr_PutParamCtrCod (Ctr_EditingCtr->CtrCod); } -/*****************************************************************************/ -/*********** Show a form for sending a logo of the current centre ************/ -/*****************************************************************************/ - -void Ctr_RequestLogo (void) - { - Lgo_RequestLogo (Hie_CTR); - } - -/*****************************************************************************/ -/***************** Receive the logo of the current centre ********************/ -/*****************************************************************************/ - -void Ctr_ReceiveLogo (void) - { - Lgo_ReceiveLogo (Hie_CTR); - } - -/*****************************************************************************/ -/****************** Remove the logo of the current centre ********************/ -/*****************************************************************************/ - -void Ctr_RemoveLogo (void) - { - Lgo_RemoveLogo (Hie_CTR); - } - -/*****************************************************************************/ -/*********** Show a form for sending a photo of the current centre ***********/ -/*****************************************************************************/ - -void Ctr_RequestPhoto (void) - { - extern const char *The_ClassFormInBox[The_NUM_THEMES]; - extern const char *Txt_Photo; - extern const char *Txt_Recommended_aspect_ratio; - extern const char *Txt_Recommended_resolution; - extern const char *Txt_XxY_pixels_or_higher; - extern const char *Txt_File_with_the_photo; - - /***** Begin form to upload photo *****/ - Frm_StartForm (ActRecCtrPho); - - /***** Begin box *****/ - Box_BoxBegin (NULL,Txt_Photo,NULL, - NULL,Box_NOT_CLOSABLE); - - /***** Write help message *****/ - Ale_ShowAlert (Ale_INFO,"%s: %s
" - "%s: %u×%u %s", - Txt_Recommended_aspect_ratio, - Ctr_RECOMMENDED_ASPECT_RATIO, - Txt_Recommended_resolution, - Ctr_PHOTO_SAVED_MAX_WIDTH, - Ctr_PHOTO_SAVED_MAX_HEIGHT, - Txt_XxY_pixels_or_higher); - - /***** Upload photo *****/ - HTM_LABEL_Begin ("class=\"%s\"",The_ClassFormInBox[Gbl.Prefs.Theme]); - HTM_TxtF ("%s: ",Txt_File_with_the_photo); - HTM_INPUT_FILE (Fil_NAME_OF_PARAM_FILENAME_ORG,"image/*",true,NULL); - HTM_LABEL_End (); - - /***** End box *****/ - Box_BoxEnd (); - - /***** End form *****/ - Frm_EndForm (); - } - -/*****************************************************************************/ -/****************** Receive a photo of the current centre ********************/ -/*****************************************************************************/ - -void Ctr_ReceivePhoto (void) - { - extern const char *Txt_Wrong_file_type; - char Path[PATH_MAX + 1]; - struct Param *Param; - char FileNameImgSrc[PATH_MAX + 1]; - char *PtrExtension; - size_t LengthExtension; - char MIMEType[Brw_MAX_BYTES_MIME_TYPE + 1]; - char PathFileImgTmp[PATH_MAX + 1]; // Full name (including path and .jpg) of the destination temporary file - char PathFileImg[PATH_MAX + 1]; // Full name (including path and .jpg) of the destination file - bool WrongType = false; - char Command[1024 + PATH_MAX * 2]; - int ReturnCode; - char ErrorMsg[256]; - - /***** Copy in disk the file received *****/ - Param = Fil_StartReceptionOfFile (Fil_NAME_OF_PARAM_FILENAME_ORG, - FileNameImgSrc,MIMEType); - - /* Check if the file type is image/ or application/octet-stream */ - if (strncmp (MIMEType,"image/",strlen ("image/"))) - if (strcmp (MIMEType,"application/octet-stream")) - if (strcmp (MIMEType,"application/octetstream")) - if (strcmp (MIMEType,"application/octet")) - WrongType = true; - if (WrongType) - { - Ale_ShowAlert (Ale_WARNING,Txt_Wrong_file_type); - return; - } - - /***** Create private directories if not exist *****/ - /* Create private directory for images if it does not exist */ - Fil_CreateDirIfNotExists (Cfg_PATH_MEDIA_PRIVATE); - - /* Create temporary private directory for images if it does not exist */ - Fil_CreateDirIfNotExists (Cfg_PATH_MEDIA_TMP_PRIVATE); - - /* Get filename extension */ - if ((PtrExtension = strrchr (FileNameImgSrc,(int) '.')) == NULL) - { - Ale_ShowAlert (Ale_WARNING,Txt_Wrong_file_type); - return; - } - LengthExtension = strlen (PtrExtension); - if (LengthExtension < Fil_MIN_BYTES_FILE_EXTENSION || - LengthExtension > Fil_MAX_BYTES_FILE_EXTENSION) - { - Ale_ShowAlert (Ale_WARNING,Txt_Wrong_file_type); - return; - } - - /* End the reception of image in a temporary file */ - snprintf (PathFileImgTmp,sizeof (PathFileImgTmp), - "%s/%s.%s", - Cfg_PATH_MEDIA_TMP_PRIVATE,Gbl.UniqueNameEncrypted,PtrExtension); - if (!Fil_EndReceptionOfFile (PathFileImgTmp,Param)) - { - Ale_ShowAlert (Ale_WARNING,"Error copying file."); - return; - } - - /***** Creates public directories if not exist *****/ - Fil_CreateDirIfNotExists (Cfg_PATH_CTR_PUBLIC); - snprintf (Path,sizeof (Path), - "%s/%02u", - Cfg_PATH_CTR_PUBLIC, - (unsigned) (Gbl.Hierarchy.Ctr.CtrCod % 100)); - Fil_CreateDirIfNotExists (Path); - snprintf (Path,sizeof (Path), - "%s/%02u/%u", - Cfg_PATH_CTR_PUBLIC, - (unsigned) (Gbl.Hierarchy.Ctr.CtrCod % 100), - (unsigned) Gbl.Hierarchy.Ctr.CtrCod); - Fil_CreateDirIfNotExists (Path); - - /***** Convert temporary file to public JPEG file *****/ - snprintf (PathFileImg,sizeof (PathFileImg), - "%s/%02u/%u/%u.jpg", - Cfg_PATH_CTR_PUBLIC, - (unsigned) (Gbl.Hierarchy.Ctr.CtrCod % 100), - (unsigned) Gbl.Hierarchy.Ctr.CtrCod, - (unsigned) Gbl.Hierarchy.Ctr.CtrCod); - - /* Call to program that makes the conversion */ - snprintf (Command,sizeof (Command), - "convert %s -resize '%ux%u>' -quality %u %s", - PathFileImgTmp, - Ctr_PHOTO_SAVED_MAX_WIDTH, - Ctr_PHOTO_SAVED_MAX_HEIGHT, - Ctr_PHOTO_SAVED_QUALITY, - PathFileImg); - ReturnCode = system (Command); - if (ReturnCode == -1) - Lay_ShowErrorAndExit ("Error when running command to process image."); - - /***** Write message depending on return code *****/ - ReturnCode = WEXITSTATUS(ReturnCode); - if (ReturnCode != 0) - { - snprintf (ErrorMsg,sizeof (ErrorMsg), - "Image could not be processed successfully.
" - "Error code returned by the program of processing: %d", - ReturnCode); - Lay_ShowErrorAndExit (ErrorMsg); - } - - /***** Remove temporary file *****/ - unlink (PathFileImgTmp); - - /***** Show the centre information again *****/ - Ctr_ShowConfiguration (); - } - -/*****************************************************************************/ -/**************** Change the attribution of a centre photo *******************/ -/*****************************************************************************/ - -void Ctr_ChangeCtrPhotoAttribution (void) - { - char NewPhotoAttribution[Med_MAX_BYTES_ATTRIBUTION + 1]; - - /***** Get parameters from form *****/ - /* Get the new photo attribution for the centre */ - Par_GetParToText ("Attribution",NewPhotoAttribution,Med_MAX_BYTES_ATTRIBUTION); - - /***** Update the table changing old attribution by new attribution *****/ - DB_QueryUPDATE ("can not update the photo attribution" - " of the current centre", - "UPDATE centres SET PhotoAttribution='%s'" - " WHERE CtrCod=%ld", - NewPhotoAttribution,Gbl.Hierarchy.Ctr.CtrCod); - - /***** Show the centre information again *****/ - Ctr_ShowConfiguration (); - } - /*****************************************************************************/ /********************* Put a form to create a new centre *********************/ /*****************************************************************************/ diff --git a/swad_centre.h b/swad_centre.h index 9ad6d8c7b..5bda26aad 100644 --- a/swad_centre.h +++ b/swad_centre.h @@ -100,9 +100,6 @@ void Ctr_SeeCtrWithPendingDegs (void); void Ctr_DrawCentreLogoAndNameWithLink (struct Centre *Ctr,Act_Action_t Action, const char *ClassLink,const char *ClassLogo); -void Ctr_ShowConfiguration (void); -void Ctr_PrintConfiguration (void); - void Ctr_ShowCtrsOfCurrentIns (void); void Ctr_EditCentres (void); @@ -118,28 +115,18 @@ void Ctr_WriteSelectorOfCentre (void); void Ctr_PutParamCtrCod (long CtrCod); long Ctr_GetAndCheckParamOtherCtrCod (long MinCodAllowed); void Ctr_RemoveCentre (void); -void Ctr_ChangeCtrInsInConfig (void); -void Ctr_ContEditAfterChgCtrInConfig (void); void Ctr_ChangeCtrPlc (void); -void Ctr_ChangeCtrPlcInConfig (void); +void Ctr_UpdateCtrPlcDB (long CtrCod,long NewPlcCod); void Ctr_RenameCentreShort (void); void Ctr_RenameCentreFull (void); -void Ctr_RenameCentreShortInConfig (void); -void Ctr_RenameCentreFullInConfig (void); -void Ctr_ChangeCtrLatitudeInConfig (void); -void Ctr_ChangeCtrLongitudeInConfig (void); -void Ctr_ChangeCtrAltitudeInConfig (void); +void Ctr_RenameCentre (struct Centre *Ctr,Cns_ShrtOrFullName_t ShrtOrFullName); +bool Ctr_CheckIfCtrNameExistsInIns (const char *FieldName,const char *Name, + long CtrCod,long InsCod); void Ctr_ChangeCtrWWW (void); -void Ctr_ChangeCtrWWWInConfig (void); +void Ctr_UpdateCtrWWWDB (long CtrCod,const char NewWWW[Cns_MAX_BYTES_WWW + 1]); void Ctr_ChangeCtrStatus (void); void Ctr_ContEditAfterChgCtr (void); -void Ctr_RequestLogo (void); -void Ctr_ReceiveLogo (void); -void Ctr_RemoveLogo (void); -void Ctr_RequestPhoto (void); -void Ctr_ReceivePhoto (void); -void Ctr_ChangeCtrPhotoAttribution (void); void Ctr_RecFormReqCtr (void); void Ctr_RecFormNewCtr (void); diff --git a/swad_centre_config.c b/swad_centre_config.c new file mode 100644 index 000000000..1dcda08a1 --- /dev/null +++ b/swad_centre_config.c @@ -0,0 +1,1320 @@ +// swad_centre_config.c: configuration of current centre + +/* + 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-2019 Antonio Cañas Vargas + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ +/*****************************************************************************/ +/********************************* Headers ***********************************/ +/*****************************************************************************/ + +#define _GNU_SOURCE // For asprintf +#include // For boolean type +#include // For NULL +#include // For asprintf +#include // For string functions +#include // For unlink + +#include "swad_centre.h" +#include "swad_database.h" +#include "swad_form.h" +#include "swad_global.h" +#include "swad_help.h" +#include "swad_HTML.h" +#include "swad_logo.h" + +/*****************************************************************************/ +/************** External global variables from others modules ****************/ +/*****************************************************************************/ + +extern struct Globals Gbl; + +/*****************************************************************************/ +/***************************** Private constants *****************************/ +/*****************************************************************************/ + +// Centre photo will be saved with: +// - maximum width of Ctr_PHOTO_SAVED_MAX_HEIGHT +// - maximum height of Ctr_PHOTO_SAVED_MAX_HEIGHT +// - maintaining the original aspect ratio (aspect ratio recommended: 3:2) +#define Ctr_RECOMMENDED_ASPECT_RATIO "3:2" +#define Ctr_PHOTO_SAVED_MAX_WIDTH 768 +#define Ctr_PHOTO_SAVED_MAX_HEIGHT 512 +#define Ctr_PHOTO_SAVED_QUALITY 75 // 1 to 100 + +/*****************************************************************************/ +/******************************* Private types *******************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/***************************** Private variables *****************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/***************************** Private prototypes ****************************/ +/*****************************************************************************/ + +static void CtrCfg_Configuration (bool PrintView); +static void CtrCfg_PutIconsCtrConfig (void); +static void CtrCfg_PutIconToChangePhoto (void); +static void CtrCfg_Title (bool PutLink); +static bool CtrCfg_GetIfMapIsAvailable (void); +static void CtrCfg_Map (void); +static void CtrCfg_Latitude (void); +static void CtrCfg_Longitude (void); +static void CtrCfg_Altitude (void); +static void CtrCfg_Photo (bool PrintView,bool PutForm,bool PutLink, + const char PathPhoto[PATH_MAX + 1]); +static void CtrCfg_GetPhotoAttribution (long CtrCod,char **PhotoAttribution); +static void CtrCfg_FreePhotoAttribution (char **PhotoAttribution); +static void CtrCfg_Institution (bool PrintView,bool PutForm); +static void CtrCfg_FullName (bool PutForm); +static void CtrCfg_ShrtName (bool PutForm); +static void CtrCfg_Place (bool PutForm); +static void CtrCfg_WWW (bool PrintView,bool PutForm); +static void CtrCfg_Shortcut (bool PrintView); +static void CtrCfg_QR (void); +static void CtrCfg_NumUsrs (void); +static void CtrCfg_NumDegs (void); +static void CtrCfg_NumCrss (void); +static void CtrCfg_NumUsrsInCrssOfCtr (Rol_Role_t Role); + +static void CtrCfg_UpdateCtrInsDB (long CtrCod,long InsCod); +static void CtrCfg_UpdateCtrCoordinateDB (long CtrCod, + const char *CoordField,double NewCoord); + +/*****************************************************************************/ +/****************** Show information of the current centre *******************/ +/*****************************************************************************/ + +void CtrCfg_ShowConfiguration (void) + { + CtrCfg_Configuration (false); + + /***** Show help to enrol me *****/ + Hlp_ShowHelpWhatWouldYouLikeToDo (); + } + +/*****************************************************************************/ +/****************** Print information of the current centre ******************/ +/*****************************************************************************/ + +void CtrCfg_PrintConfiguration (void) + { + CtrCfg_Configuration (true); + } + +/*****************************************************************************/ +/******************* Information of the current centre ***********************/ +/*****************************************************************************/ + +static void CtrCfg_Configuration (bool PrintView) + { + extern const char *Hlp_CENTRE_Information; + bool PutLink; + bool PutFormIns; + bool PutFormName; + bool PutFormPlc; + bool PutFormCoor; + bool PutFormWWW; + bool PutFormPhoto; + bool MapIsAvailable; + char PathPhoto[PATH_MAX + 1]; + bool PhotoExists; + + /***** Trivial check *****/ + if (Gbl.Hierarchy.Ctr.CtrCod <= 0) // No centre selected + return; + + /***** Initializations *****/ + PutLink = !PrintView && Gbl.Hierarchy.Ctr.WWW[0]; + PutFormIns = !PrintView && Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM; + PutFormName = !PrintView && Gbl.Usrs.Me.Role.Logged >= Rol_INS_ADM; + PutFormPlc = + PutFormCoor = + PutFormWWW = + PutFormPhoto = !PrintView && Gbl.Usrs.Me.Role.Logged >= Rol_CTR_ADM; + + /***** Begin box *****/ + if (PrintView) + Box_BoxBegin (NULL,NULL,NULL, + NULL,Box_NOT_CLOSABLE); + else + Box_BoxBegin (NULL,NULL,CtrCfg_PutIconsCtrConfig, + Hlp_CENTRE_Information,Box_NOT_CLOSABLE); + + /***** Title *****/ + CtrCfg_Title (PutLink); + + /**************************** Left part ***********************************/ + HTM_DIV_Begin ("class=\"HIE_CFG_LEFT\""); + + /***** Begin table *****/ + HTM_TABLE_BeginWidePadding (2); + + /***** Institution *****/ + CtrCfg_Institution (PrintView,PutFormIns); + + /***** Centre name *****/ + CtrCfg_FullName (PutFormName); + CtrCfg_ShrtName (PutFormName); + + /***** Place *****/ + CtrCfg_Place (PutFormPlc); + + /***** Coordinates *****/ + if (PutFormCoor) + { + CtrCfg_Latitude (); + CtrCfg_Longitude (); + CtrCfg_Altitude (); + } + + /***** Centre WWW *****/ + CtrCfg_WWW (PrintView,PutFormWWW); + + /***** Shortcut to the centre *****/ + CtrCfg_Shortcut (PrintView); + + if (PrintView) + /***** QR code with link to the centre *****/ + CtrCfg_QR (); + else + { + /***** Number of users who claim to belong to this centre, + number of degrees, + number of courses *****/ + CtrCfg_NumUsrs (); + CtrCfg_NumDegs (); + CtrCfg_NumCrss (); + + /***** Number of users in courses of this centre *****/ + CtrCfg_NumUsrsInCrssOfCtr (Rol_TCH); + CtrCfg_NumUsrsInCrssOfCtr (Rol_NET); + CtrCfg_NumUsrsInCrssOfCtr (Rol_STD); + CtrCfg_NumUsrsInCrssOfCtr (Rol_UNK); + } + + /***** End table *****/ + HTM_TABLE_End (); + + /***** End of left part *****/ + HTM_DIV_End (); + + /**************************** Right part **********************************/ + /***** Check map *****/ + MapIsAvailable = CtrCfg_GetIfMapIsAvailable (); + + /***** Check photo *****/ + snprintf (PathPhoto,sizeof (PathPhoto), + "%s/%02u/%u/%u.jpg", + Cfg_PATH_CTR_PUBLIC, + (unsigned) (Gbl.Hierarchy.Ctr.CtrCod % 100), + (unsigned) Gbl.Hierarchy.Ctr.CtrCod, + (unsigned) Gbl.Hierarchy.Ctr.CtrCod); + PhotoExists = Fil_CheckIfPathExists (PathPhoto); + + if (MapIsAvailable || PhotoExists) + { + HTM_DIV_Begin ("class=\"HIE_CFG_RIGHT\""); + + /***** Centre map *****/ + if (MapIsAvailable) + CtrCfg_Map (); + + /***** Centre photo *****/ + if (PhotoExists) + CtrCfg_Photo (PrintView,PutFormPhoto,PutLink,PathPhoto); + + HTM_DIV_End (); + } + + /***** End box *****/ + Box_BoxEnd (); + } + +/*****************************************************************************/ +/************ Put contextual icons in configuration of a centre **************/ +/*****************************************************************************/ + +static void CtrCfg_PutIconsCtrConfig (void) + { + /***** Put icon to print info about centre *****/ + Ico_PutContextualIconToPrint (ActPrnCtrInf,NULL); + + /***** Put icon to view places *****/ + Plc_PutIconToViewPlaces (); + + if (Gbl.Usrs.Me.Role.Logged >= Rol_CTR_ADM) + // Only centre admins, institution admins and system admins + // have permission to upload logo and photo of the centre + { + /***** Put icon to upload logo of centre *****/ + Lgo_PutIconToChangeLogo (Hie_CTR); + + /***** Put icon to upload photo of centre *****/ + CtrCfg_PutIconToChangePhoto (); + } + } + +/*****************************************************************************/ +/************* Put contextual icons to upload photo of centre ****************/ +/*****************************************************************************/ + +static void CtrCfg_PutIconToChangePhoto (void) + { + extern const char *Txt_Change_photo; + extern const char *Txt_Upload_photo; + char PathPhoto[PATH_MAX + 1]; + bool PhotoExists; + + /***** Link to upload photo of centre *****/ + snprintf (PathPhoto,sizeof (PathPhoto), + "%s/%02u/%u/%u.jpg", + Cfg_PATH_CTR_PUBLIC, + (unsigned) (Gbl.Hierarchy.Ctr.CtrCod % 100), + (unsigned) Gbl.Hierarchy.Ctr.CtrCod, + (unsigned) Gbl.Hierarchy.Ctr.CtrCod); + PhotoExists = Fil_CheckIfPathExists (PathPhoto); + Lay_PutContextualLinkOnlyIcon (ActReqCtrPho,NULL,NULL, + "camera.svg", + PhotoExists ? Txt_Change_photo : + Txt_Upload_photo); + } + +/*****************************************************************************/ +/******************** Show title in centre configuration *********************/ +/*****************************************************************************/ + +static void CtrCfg_Title (bool PutLink) + { + Hie_ConfigTitle (PutLink, + Hie_CTR, // Logo scope + Gbl.Hierarchy.Ctr.CtrCod, // Logo code + Gbl.Hierarchy.Ctr.ShrtName, // Logo short name + Gbl.Hierarchy.Ctr.FullName, // Logo full name + Gbl.Hierarchy.Ctr.WWW, // Logo www + Gbl.Hierarchy.Ctr.FullName); // Text full name + } + +/*****************************************************************************/ +/******************** Check if centre map should be shown ********************/ +/*****************************************************************************/ + +static bool CtrCfg_GetIfMapIsAvailable (void) + { + /***** Coordinates 0, 0 means not set ==> don't show map *****/ + return (bool) (Gbl.Hierarchy.Ctr.Coord.Latitude || + Gbl.Hierarchy.Ctr.Coord.Longitude); + } + +/*****************************************************************************/ +/****************************** Draw centre map ******************************/ +/*****************************************************************************/ + +static void CtrCfg_Map (void) + { + /* https://leafletjs.com/examples/quick-start/ */ + /***** Leaflet CSS *****/ + HTM_Txt (""); + + /***** Leaflet script *****/ + /* Put this AFTER Leaflet's CSS */ + HTM_Txt (""); + + /***** Container for the map *****/ + HTM_DIV_Begin ("id=\"centre_mapid\""); + HTM_DIV_End (); + + /***** Script to draw the map *****/ + HTM_SCRIPT_Begin (NULL,NULL); + Str_SetDecimalPointToUS (); // To write the decimal point as a dot + + /* Let's create a map of the center of London with pretty Mapbox Streets tiles */ + HTM_TxtF ("\tvar mymap = L.map('centre_mapid').setView([%lg, %lg], 16);\n", + Gbl.Hierarchy.Ctr.Coord.Latitude, + Gbl.Hierarchy.Ctr.Coord.Longitude); + + /* Next we'll add a tile layer to add to our map, + in this case it's a Mapbox Streets tile layer. + Creating a tile layer usually involves + setting the URL template for the tile images, + the attribution text and the maximum zoom level of the layer. + In this example we'll use the mapbox/streets-v11 tiles + from Mapbox's Static Tiles API + (in order to use tiles from Mapbox, + you must also request an access token).*/ + HTM_Txt ("\tL.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}', {" + "attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA, Imagery © Mapbox'," + "maxZoom: 20," + "id: 'mapbox/streets-v11'," + "accessToken: 'pk.eyJ1IjoiYWNhbmFzIiwiYSI6ImNrNGFoNXFxOTAzdHozcnA4d3Y0M3BwOGkifQ.uSg754Lv2iZEJg0W2pjiOQ'" + "}).addTo(mymap);\n"); + + /* Marker */ + HTM_TxtF ("\tvar marker = L.marker([%lg, %lg]).addTo(mymap);", + Gbl.Hierarchy.Ctr.Coord.Latitude, + Gbl.Hierarchy.Ctr.Coord.Longitude); + + HTM_TxtF ("\tmarker.bindPopup(\"%s
%s\").openPopup();", + Gbl.Hierarchy.Ctr.ShrtName, + Gbl.Hierarchy.Ins.ShrtName); + + Str_SetDecimalPointToLocal (); // Return to local system + HTM_SCRIPT_End (); + } + +/*****************************************************************************/ +/************************** Edit centre coordinates **************************/ +/*****************************************************************************/ + +static void CtrCfg_Latitude (void) + { + extern const char *Txt_Latitude; + + /***** Latitude *****/ + HTM_TR_Begin (NULL); + + /* Label */ + Frm_LabelColumn ("RT","Latitude",Txt_Latitude); + + /* Data */ + HTM_TD_Begin ("class=\"LB\""); + Frm_StartForm (ActChgCtrLatCfg); + HTM_INPUT_FLOAT ("Latitude", + -90.0, // South Pole + 90.0, // North Pole + 0.0, // step="any" + Gbl.Hierarchy.Ctr.Coord.Latitude,false, + "class=\"INPUT_COORD\" required=\"required\""); + Frm_EndForm (); + HTM_TD_End (); + + HTM_TR_End (); + } + +static void CtrCfg_Longitude (void) + { + extern const char *Txt_Longitude; + + /***** Longitude *****/ + HTM_TR_Begin (NULL); + + /* Label */ + Frm_LabelColumn ("RT","Longitude",Txt_Longitude); + + /* Data */ + HTM_TD_Begin ("class=\"LB\""); + Frm_StartForm (ActChgCtrLgtCfg); + HTM_INPUT_FLOAT ("Longitude", + -180.0, // West + 180.0, // East + 0.0, // step="any" + Gbl.Hierarchy.Ctr.Coord.Longitude,false, + "class=\"INPUT_COORD\" required=\"required\""); + Frm_EndForm (); + HTM_TD_End (); + + HTM_TR_End (); + } + +static void CtrCfg_Altitude (void) + { + extern const char *Txt_Altitude; + + /***** Altitude *****/ + HTM_TR_Begin (NULL); + + /* Label */ + Frm_LabelColumn ("RT","Altitude",Txt_Altitude); + + /* Data */ + HTM_TD_Begin ("class=\"LB\""); + Frm_StartForm (ActChgCtrAltCfg); + HTM_INPUT_FLOAT ("Altitude", + -413.0, // Dead Sea shore + 8848.0, // Mount Everest + 0.0, // step="any" + Gbl.Hierarchy.Ctr.Coord.Altitude,false, + "class=\"INPUT_COORD\" required=\"required\""); + Frm_EndForm (); + HTM_TD_End (); + + HTM_TR_End (); + } + +/*****************************************************************************/ +/***************************** Draw centre photo *****************************/ +/*****************************************************************************/ + +static void CtrCfg_Photo (bool PrintView,bool PutForm,bool PutLink, + const char PathPhoto[PATH_MAX + 1]) + { + char *PhotoAttribution = NULL; + char *URL; + char *Icon; + + /***** Trivial checks *****/ + if (!PathPhoto) + return; + if (!PathPhoto[0]) + return; + + /***** Get photo attribution *****/ + CtrCfg_GetPhotoAttribution (Gbl.Hierarchy.Ctr.CtrCod,&PhotoAttribution); + + /***** Photo image *****/ + HTM_DIV_Begin ("class=\"DAT_SMALL CM\""); + if (PutLink) + HTM_A_Begin ("href=\"%s\" target=\"_blank\" class=\"DAT_N\"", + Gbl.Hierarchy.Ctr.WWW); + if (asprintf (&URL,"%s/%02u/%u", + Cfg_URL_CTR_PUBLIC, + (unsigned) (Gbl.Hierarchy.Ctr.CtrCod % 100), + (unsigned) Gbl.Hierarchy.Ctr.CtrCod) < 0) + Lay_NotEnoughMemoryExit (); + if (asprintf (&Icon,"%u.jpg", + (unsigned) Gbl.Hierarchy.Ctr.CtrCod) < 0) + Lay_NotEnoughMemoryExit (); + HTM_IMG (URL,Icon,Gbl.Hierarchy.Ctr.FullName, + "class=\"%s\"",PrintView ? "CENTRE_PHOTO_PRINT" : + "CENTRE_PHOTO_SHOW"); + free (Icon); + free (URL); + if (PutLink) + HTM_A_End (); + HTM_DIV_End (); + + /****** Photo attribution ******/ + if (PutForm) + { + HTM_DIV_Begin ("class=\"CM\""); + Frm_StartForm (ActChgCtrPhoAtt); + HTM_TEXTAREA_Begin ("id=\"AttributionArea\" name=\"Attribution\" rows=\"3\"" + " onchange=\"document.getElementById('%s').submit();return false;\"", + Gbl.Form.Id); + if (PhotoAttribution) + HTM_Txt (PhotoAttribution); + HTM_TEXTAREA_End (); + Frm_EndForm (); + HTM_DIV_End (); + } + else if (PhotoAttribution) + { + HTM_DIV_Begin ("class=\"ATTRIBUTION\""); + HTM_Txt (PhotoAttribution); + HTM_DIV_End (); + } + + /****** Free memory used for photo attribution ******/ + CtrCfg_FreePhotoAttribution (&PhotoAttribution); + } + +/*****************************************************************************/ +/******************* Get photo attribution from database *********************/ +/*****************************************************************************/ + +static void CtrCfg_GetPhotoAttribution (long CtrCod,char **PhotoAttribution) + { + MYSQL_RES *mysql_res; + MYSQL_ROW row; + size_t Length; + + /***** Free possible former photo attribution *****/ + CtrCfg_FreePhotoAttribution (PhotoAttribution); + + /***** Get photo attribution from database *****/ + if (DB_QuerySELECT (&mysql_res,"can not get photo attribution", + "SELECT PhotoAttribution" + " FROM centres WHERE CtrCod=%ld", + CtrCod)) + { + /* Get row */ + row = mysql_fetch_row (mysql_res); + + /* Get the attribution of the photo of the centre (row[0]) */ + if (row[0]) + if (row[0][0]) + { + Length = strlen (row[0]); + if (((*PhotoAttribution) = (char *) malloc (Length + 1)) == NULL) + Lay_ShowErrorAndExit ("Error allocating memory for photo attribution."); + Str_Copy (*PhotoAttribution,row[0], + Length); + } + } + + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); + } + +/*****************************************************************************/ +/****************** Free memory used for photo attribution *******************/ +/*****************************************************************************/ + +static void CtrCfg_FreePhotoAttribution (char **PhotoAttribution) + { + if (*PhotoAttribution) + { + free (*PhotoAttribution); + *PhotoAttribution = NULL; + } + } + +/*****************************************************************************/ +/***************** Show institution in centre configuration ******************/ +/*****************************************************************************/ + +static void CtrCfg_Institution (bool PrintView,bool PutForm) + { + extern const char *Txt_Institution; + extern const char *Txt_Go_to_X; + unsigned NumIns; + + /***** Institution *****/ + HTM_TR_Begin (NULL); + + /* Label */ + Frm_LabelColumn ("RT",PutForm ? "OthInsCod" : + NULL, + Txt_Institution); + + /* Data */ + HTM_TD_Begin ("class=\"DAT LB\""); + if (PutForm) + { + /* Get list of institutions of the current country */ + Ins_GetListInstitutions (Gbl.Hierarchy.Cty.CtyCod,Ins_GET_BASIC_DATA); + + /* Put form to select institution */ + Frm_StartForm (ActChgCtrInsCfg); + HTM_SELECT_Begin (true, + "id=\"OthInsCod\" name=\"OthInsCod\"" + " class=\"INPUT_SHORT_NAME\""); + for (NumIns = 0; + NumIns < Gbl.Hierarchy.Cty.Inss.Num; + NumIns++) + HTM_OPTION (HTM_Type_LONG,&Gbl.Hierarchy.Cty.Inss.Lst[NumIns].InsCod, + Gbl.Hierarchy.Cty.Inss.Lst[NumIns].InsCod == Gbl.Hierarchy.Ins.InsCod,false, + "%s",Gbl.Hierarchy.Cty.Inss.Lst[NumIns].ShrtName); + HTM_SELECT_End (); + Frm_EndForm (); + + /* Free list of institutions */ + Ins_FreeListInstitutions (); + } + else // I can not move centre to another institution + { + if (!PrintView) + { + Frm_StartFormGoTo (ActSeeInsInf); + Ins_PutParamInsCod (Gbl.Hierarchy.Ins.InsCod); + snprintf (Gbl.Title,sizeof (Gbl.Title), + Txt_Go_to_X, + Gbl.Hierarchy.Ins.ShrtName); + HTM_BUTTON_SUBMIT_Begin (Gbl.Title,"BT_LINK LT DAT",NULL); + } + Lgo_DrawLogo (Hie_INS,Gbl.Hierarchy.Ins.InsCod,Gbl.Hierarchy.Ins.ShrtName, + 20,"LM",true); + HTM_NBSP (); + HTM_Txt (Gbl.Hierarchy.Ins.FullName); + if (!PrintView) + { + HTM_BUTTON_End (); + Frm_EndForm (); + } + } + HTM_TD_End (); + + HTM_TR_End (); + } + +/*****************************************************************************/ +/************** Show centre full name in centre configuration ****************/ +/*****************************************************************************/ + +static void CtrCfg_FullName (bool PutForm) + { + extern const char *Txt_Centre; + + Hie_ConfigFullName (PutForm,Txt_Centre,ActRenCtrFulCfg, + Gbl.Hierarchy.Ctr.FullName); + } + +/*****************************************************************************/ +/************** Show centre short name in centre configuration ***************/ +/*****************************************************************************/ + +static void CtrCfg_ShrtName (bool PutForm) + { + Hie_ConfigShrtName (PutForm,ActRenCtrShoCfg,Gbl.Hierarchy.Ctr.ShrtName); + } + +/*****************************************************************************/ +/**************** Show centre place in centre configuration ******************/ +/*****************************************************************************/ + +static void CtrCfg_Place (bool PutForm) + { + extern const char *Txt_Place; + extern const char *Txt_Another_place; + struct Place Plc; + unsigned NumPlc; + + /***** Get data of place *****/ + Plc.PlcCod = Gbl.Hierarchy.Ctr.PlcCod; + Plc_GetDataOfPlaceByCod (&Plc); + + /***** Place *****/ + HTM_TR_Begin (NULL); + + /* Label */ + Frm_LabelColumn ("RT",PutForm ? "PlcCod" : + NULL, + Txt_Place); + + /* Data */ + HTM_TD_Begin ("class=\"DAT LB\""); + if (PutForm) + { + /* Get list of places of the current institution */ + Gbl.Plcs.SelectedOrder = Plc_ORDER_BY_PLACE; + Plc_GetListPlaces (); + + /* Put form to select place */ + Frm_StartForm (ActChgCtrPlcCfg); + HTM_SELECT_Begin (true, + "name=\"PlcCod\" class=\"INPUT_SHORT_NAME\""); + HTM_OPTION (HTM_Type_STRING,"0", + Gbl.Hierarchy.Ctr.PlcCod == 0,false, + "%s",Txt_Another_place); + for (NumPlc = 0; + NumPlc < Gbl.Plcs.Num; + NumPlc++) + HTM_OPTION (HTM_Type_LONG,&Gbl.Plcs.Lst[NumPlc].PlcCod, + Gbl.Plcs.Lst[NumPlc].PlcCod == Gbl.Hierarchy.Ctr.PlcCod,false, + "%s",Gbl.Plcs.Lst[NumPlc].ShrtName); + HTM_SELECT_End (); + Frm_EndForm (); + + /* Free list of places */ + Plc_FreeListPlaces (); + } + else // I can not change centre place + HTM_Txt (Plc.FullName); + HTM_TD_End (); + + HTM_TR_End (); + } + +/*****************************************************************************/ +/***************** Show centre WWW in centre configuration *******************/ +/*****************************************************************************/ + +static void CtrCfg_WWW (bool PrintView,bool PutForm) + { + Hie_ConfigWWW (PrintView,PutForm,ActChgCtrWWWCfg,Gbl.Hierarchy.Ctr.WWW); + } + +/*****************************************************************************/ +/*************** Show centre shortcut in centre configuration ****************/ +/*****************************************************************************/ + +static void CtrCfg_Shortcut (bool PrintView) + { + Hie_ConfigShortcut (PrintView,"ctr",Gbl.Hierarchy.Ctr.CtrCod); + } + +/*****************************************************************************/ +/****************** Show centre QR in centre configuration *******************/ +/*****************************************************************************/ + +static void CtrCfg_QR (void) + { + Hie_ConfigQR ("ctr",Gbl.Hierarchy.Ctr.CtrCod); + } + +/*****************************************************************************/ +/*** Show number of users who claim to belong to centre in centre config. ****/ +/*****************************************************************************/ + +static void CtrCfg_NumUsrs (void) + { + extern const char *Txt_Users_of_the_centre; + + /***** Number of users *****/ + HTM_TR_Begin (NULL); + + /* Label */ + Frm_LabelColumn ("RT",NULL,Txt_Users_of_the_centre); + + /* Data */ + HTM_TD_Begin ("class=\"DAT LB\""); + HTM_Unsigned (Usr_GetNumUsrsWhoClaimToBelongToCtr (Gbl.Hierarchy.Ctr.CtrCod)); + HTM_TD_End (); + + HTM_TR_End (); + } + +/*****************************************************************************/ +/************** Show number of degrees in centre configuration ***************/ +/*****************************************************************************/ + +static void CtrCfg_NumDegs (void) + { + extern const char *Txt_Degrees; + extern const char *Txt_Degrees_of_CENTRE_X; + + /***** Number of degrees *****/ + HTM_TR_Begin (NULL); + + /* Label */ + Frm_LabelColumn ("RT",NULL,Txt_Degrees); + + /* Data */ + HTM_TD_Begin ("class=\"LB\""); + Frm_StartFormGoTo (ActSeeDeg); + Ctr_PutParamCtrCod (Gbl.Hierarchy.Ctr.CtrCod); + snprintf (Gbl.Title,sizeof (Gbl.Title), + Txt_Degrees_of_CENTRE_X, + Gbl.Hierarchy.Ctr.ShrtName); + HTM_BUTTON_SUBMIT_Begin (Gbl.Title,"BT_LINK DAT",NULL); + HTM_Unsigned (Deg_GetNumDegsInCtr (Gbl.Hierarchy.Ctr.CtrCod)); + HTM_BUTTON_End (); + Frm_EndForm (); + HTM_TD_End (); + + HTM_TR_End (); + } + +/*****************************************************************************/ +/************** Show number of courses in centre configuration ***************/ +/*****************************************************************************/ + +static void CtrCfg_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\""); + HTM_Unsigned (Crs_GetNumCrssInCtr (Gbl.Hierarchy.Ctr.CtrCod)); + HTM_TD_End (); + + HTM_TR_End (); + } + +/*****************************************************************************/ +/**************** Number of users in courses of this centre ******************/ +/*****************************************************************************/ + +static void CtrCfg_NumUsrsInCrssOfCtr (Rol_Role_t Role) + { + extern const char *Txt_Users_in_courses; + extern const char *Txt_ROLES_PLURAL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS]; + + /***** Number of users in courses *****/ + HTM_TR_Begin (NULL); + + /* Label */ + Frm_LabelColumn ("RT",NULL, + Role == Rol_UNK ? Txt_Users_in_courses : + Txt_ROLES_PLURAL_Abc[Role][Usr_SEX_UNKNOWN]); + + /* Data */ + HTM_TD_Begin ("class=\"DAT LB\""); + HTM_Unsigned (Usr_GetNumUsrsInCrssOfCtr (Role,Gbl.Hierarchy.Ctr.CtrCod)); + HTM_TD_End (); + + HTM_TR_End (); + } + +/*****************************************************************************/ +/*********** Show a form for sending a logo of the current centre ************/ +/*****************************************************************************/ + +void CtrCfg_RequestLogo (void) + { + Lgo_RequestLogo (Hie_CTR); + } + +/*****************************************************************************/ +/***************** Receive the logo of the current centre ********************/ +/*****************************************************************************/ + +void CtrCfg_ReceiveLogo (void) + { + Lgo_ReceiveLogo (Hie_CTR); + } + +/*****************************************************************************/ +/****************** Remove the logo of the current centre ********************/ +/*****************************************************************************/ + +void CtrCfg_RemoveLogo (void) + { + Lgo_RemoveLogo (Hie_CTR); + } + +/*****************************************************************************/ +/*********** Show a form for sending a photo of the current centre ***********/ +/*****************************************************************************/ + +void CtrCfg_RequestPhoto (void) + { + extern const char *The_ClassFormInBox[The_NUM_THEMES]; + extern const char *Txt_Photo; + extern const char *Txt_Recommended_aspect_ratio; + extern const char *Txt_Recommended_resolution; + extern const char *Txt_XxY_pixels_or_higher; + extern const char *Txt_File_with_the_photo; + + /***** Begin form to upload photo *****/ + Frm_StartForm (ActRecCtrPho); + + /***** Begin box *****/ + Box_BoxBegin (NULL,Txt_Photo,NULL, + NULL,Box_NOT_CLOSABLE); + + /***** Write help message *****/ + Ale_ShowAlert (Ale_INFO,"%s: %s
" + "%s: %u×%u %s", + Txt_Recommended_aspect_ratio, + Ctr_RECOMMENDED_ASPECT_RATIO, + Txt_Recommended_resolution, + Ctr_PHOTO_SAVED_MAX_WIDTH, + Ctr_PHOTO_SAVED_MAX_HEIGHT, + Txt_XxY_pixels_or_higher); + + /***** Upload photo *****/ + HTM_LABEL_Begin ("class=\"%s\"",The_ClassFormInBox[Gbl.Prefs.Theme]); + HTM_TxtF ("%s: ",Txt_File_with_the_photo); + HTM_INPUT_FILE (Fil_NAME_OF_PARAM_FILENAME_ORG,"image/*",true,NULL); + HTM_LABEL_End (); + + /***** End box *****/ + Box_BoxEnd (); + + /***** End form *****/ + Frm_EndForm (); + } + +/*****************************************************************************/ +/****************** Receive a photo of the current centre ********************/ +/*****************************************************************************/ + +void CtrCfg_ReceivePhoto (void) + { + extern const char *Txt_Wrong_file_type; + char Path[PATH_MAX + 1]; + struct Param *Param; + char FileNameImgSrc[PATH_MAX + 1]; + char *PtrExtension; + size_t LengthExtension; + char MIMEType[Brw_MAX_BYTES_MIME_TYPE + 1]; + char PathFileImgTmp[PATH_MAX + 1]; // Full name (including path and .jpg) of the destination temporary file + char PathFileImg[PATH_MAX + 1]; // Full name (including path and .jpg) of the destination file + bool WrongType = false; + char Command[1024 + PATH_MAX * 2]; + int ReturnCode; + char ErrorMsg[256]; + + /***** Copy in disk the file received *****/ + Param = Fil_StartReceptionOfFile (Fil_NAME_OF_PARAM_FILENAME_ORG, + FileNameImgSrc,MIMEType); + + /* Check if the file type is image/ or application/octet-stream */ + if (strncmp (MIMEType,"image/",strlen ("image/"))) + if (strcmp (MIMEType,"application/octet-stream")) + if (strcmp (MIMEType,"application/octetstream")) + if (strcmp (MIMEType,"application/octet")) + WrongType = true; + if (WrongType) + { + Ale_ShowAlert (Ale_WARNING,Txt_Wrong_file_type); + return; + } + + /***** Create private directories if not exist *****/ + /* Create private directory for images if it does not exist */ + Fil_CreateDirIfNotExists (Cfg_PATH_MEDIA_PRIVATE); + + /* Create temporary private directory for images if it does not exist */ + Fil_CreateDirIfNotExists (Cfg_PATH_MEDIA_TMP_PRIVATE); + + /* Get filename extension */ + if ((PtrExtension = strrchr (FileNameImgSrc,(int) '.')) == NULL) + { + Ale_ShowAlert (Ale_WARNING,Txt_Wrong_file_type); + return; + } + LengthExtension = strlen (PtrExtension); + if (LengthExtension < Fil_MIN_BYTES_FILE_EXTENSION || + LengthExtension > Fil_MAX_BYTES_FILE_EXTENSION) + { + Ale_ShowAlert (Ale_WARNING,Txt_Wrong_file_type); + return; + } + + /* End the reception of image in a temporary file */ + snprintf (PathFileImgTmp,sizeof (PathFileImgTmp), + "%s/%s.%s", + Cfg_PATH_MEDIA_TMP_PRIVATE,Gbl.UniqueNameEncrypted,PtrExtension); + if (!Fil_EndReceptionOfFile (PathFileImgTmp,Param)) + { + Ale_ShowAlert (Ale_WARNING,"Error copying file."); + return; + } + + /***** Creates public directories if not exist *****/ + Fil_CreateDirIfNotExists (Cfg_PATH_CTR_PUBLIC); + snprintf (Path,sizeof (Path), + "%s/%02u", + Cfg_PATH_CTR_PUBLIC, + (unsigned) (Gbl.Hierarchy.Ctr.CtrCod % 100)); + Fil_CreateDirIfNotExists (Path); + snprintf (Path,sizeof (Path), + "%s/%02u/%u", + Cfg_PATH_CTR_PUBLIC, + (unsigned) (Gbl.Hierarchy.Ctr.CtrCod % 100), + (unsigned) Gbl.Hierarchy.Ctr.CtrCod); + Fil_CreateDirIfNotExists (Path); + + /***** Convert temporary file to public JPEG file *****/ + snprintf (PathFileImg,sizeof (PathFileImg), + "%s/%02u/%u/%u.jpg", + Cfg_PATH_CTR_PUBLIC, + (unsigned) (Gbl.Hierarchy.Ctr.CtrCod % 100), + (unsigned) Gbl.Hierarchy.Ctr.CtrCod, + (unsigned) Gbl.Hierarchy.Ctr.CtrCod); + + /* Call to program that makes the conversion */ + snprintf (Command,sizeof (Command), + "convert %s -resize '%ux%u>' -quality %u %s", + PathFileImgTmp, + Ctr_PHOTO_SAVED_MAX_WIDTH, + Ctr_PHOTO_SAVED_MAX_HEIGHT, + Ctr_PHOTO_SAVED_QUALITY, + PathFileImg); + ReturnCode = system (Command); + if (ReturnCode == -1) + Lay_ShowErrorAndExit ("Error when running command to process image."); + + /***** Write message depending on return code *****/ + ReturnCode = WEXITSTATUS(ReturnCode); + if (ReturnCode != 0) + { + snprintf (ErrorMsg,sizeof (ErrorMsg), + "Image could not be processed successfully.
" + "Error code returned by the program of processing: %d", + ReturnCode); + Lay_ShowErrorAndExit (ErrorMsg); + } + + /***** Remove temporary file *****/ + unlink (PathFileImgTmp); + + /***** Show the centre information again *****/ + CtrCfg_ShowConfiguration (); + } + +/*****************************************************************************/ +/**************** Change the attribution of a centre photo *******************/ +/*****************************************************************************/ + +void CtrCfg_ChangeCtrPhotoAttribution (void) + { + char NewPhotoAttribution[Med_MAX_BYTES_ATTRIBUTION + 1]; + + /***** Get parameters from form *****/ + /* Get the new photo attribution for the centre */ + Par_GetParToText ("Attribution",NewPhotoAttribution,Med_MAX_BYTES_ATTRIBUTION); + + /***** Update the table changing old attribution by new attribution *****/ + DB_QueryUPDATE ("can not update the photo attribution" + " of the current centre", + "UPDATE centres SET PhotoAttribution='%s'" + " WHERE CtrCod=%ld", + NewPhotoAttribution,Gbl.Hierarchy.Ctr.CtrCod); + + /***** Show the centre information again *****/ + CtrCfg_ShowConfiguration (); + } + +/*****************************************************************************/ +/********************* Change the institution of a centre ********************/ +/*****************************************************************************/ + +void CtrCfg_ChangeCtrInsInConfig (void) + { + extern const char *Txt_The_centre_X_already_exists; + extern const char *Txt_The_centre_X_has_been_moved_to_the_institution_Y; + struct Instit NewIns; + + /***** Get parameter with institution code *****/ + NewIns.InsCod = Ins_GetAndCheckParamOtherInsCod (1); + + /***** Check if institution has changed *****/ + if (NewIns.InsCod != Gbl.Hierarchy.Ctr.InsCod) + { + /***** Get data of new institution *****/ + Ins_GetDataOfInstitutionByCod (&NewIns,Ins_GET_BASIC_DATA); + + /***** Check if it already exists a centre with the same name in the new institution *****/ + if (Ctr_CheckIfCtrNameExistsInIns ("ShortName", + Gbl.Hierarchy.Ctr.ShrtName, + Gbl.Hierarchy.Ctr.CtrCod, + NewIns.InsCod)) + /***** Create warning message *****/ + Ale_CreateAlert (Ale_WARNING,NULL, + Txt_The_centre_X_already_exists, + Gbl.Hierarchy.Ctr.ShrtName); + else if (Ctr_CheckIfCtrNameExistsInIns ("FullName", + Gbl.Hierarchy.Ctr.FullName, + Gbl.Hierarchy.Ctr.CtrCod, + NewIns.InsCod)) + /***** Create warning message *****/ + Ale_CreateAlert (Ale_WARNING,NULL, + Txt_The_centre_X_already_exists, + Gbl.Hierarchy.Ctr.FullName); + else + { + /***** Update institution in table of centres *****/ + CtrCfg_UpdateCtrInsDB (Gbl.Hierarchy.Ctr.CtrCod,NewIns.InsCod); + Gbl.Hierarchy.Ctr.InsCod = + Gbl.Hierarchy.Ins.InsCod = NewIns.InsCod; + + /***** Initialize again current course, degree, centre... *****/ + Hie_InitHierarchy (); + + /***** Create message to show the change made *****/ + Ale_CreateAlert (Ale_SUCCESS,NULL, + Txt_The_centre_X_has_been_moved_to_the_institution_Y, + Gbl.Hierarchy.Ctr.FullName,NewIns.FullName); + } + } + } + +/*****************************************************************************/ +/******************* Update institution in table of centres ******************/ +/*****************************************************************************/ + +static void CtrCfg_UpdateCtrInsDB (long CtrCod,long InsCod) + { + /***** Update institution in table of centres *****/ + DB_QueryUPDATE ("can not update the institution of a centre", + "UPDATE centres SET InsCod=%ld WHERE CtrCod=%ld", + InsCod,CtrCod); + } + +/*****************************************************************************/ +/************************ Change the place of a centre ***********************/ +/*****************************************************************************/ + +void CtrCfg_ChangeCtrPlcInConfig (void) + { + extern const char *Txt_The_place_of_the_centre_has_changed; + long NewPlcCod; + + /***** Get parameter with place code *****/ + NewPlcCod = Plc_GetParamPlcCod (); + + /***** Update place in table of centres *****/ + Ctr_UpdateCtrPlcDB (Gbl.Hierarchy.Ctr.CtrCod,NewPlcCod); + Gbl.Hierarchy.Ctr.PlcCod = NewPlcCod; + + /***** Write message to show the change made *****/ + Ale_ShowAlert (Ale_SUCCESS,Txt_The_place_of_the_centre_has_changed); + + /***** Show the form again *****/ + CtrCfg_ShowConfiguration (); + } + +/*****************************************************************************/ +/*************** Change the name of a centre in configuration ****************/ +/*****************************************************************************/ + +void CtrCfg_RenameCentreShortInConfig (void) + { + Ctr_RenameCentre (&Gbl.Hierarchy.Ctr,Cns_SHRT_NAME); + } + +void CtrCfg_RenameCentreFullInConfig (void) + { + Ctr_RenameCentre (&Gbl.Hierarchy.Ctr,Cns_FULL_NAME); + } + +/*****************************************************************************/ +/********************** Change the latitude of a centre **********************/ +/*****************************************************************************/ + +void CtrCfg_ChangeCtrLatitudeInConfig (void) + { + extern const char *Txt_The_new_latitude_is_X; + char LatitudeStr[64]; + double NewLatitude; + + /***** Get latitude *****/ + Par_GetParToText ("Latitude",LatitudeStr,sizeof (LatitudeStr) - 1); + NewLatitude = Str_GetDoubleFromStr (LatitudeStr); + if (NewLatitude < -90.0) + NewLatitude = -90.0; // South Pole + else if (NewLatitude > 90.0) + NewLatitude = 90.0; // North Pole + + /***** Update database changing old latitude by new latitude *****/ + CtrCfg_UpdateCtrCoordinateDB (Gbl.Hierarchy.Ctr.CtrCod,"Latitude",NewLatitude); + Gbl.Hierarchy.Ctr.Coord.Latitude = NewLatitude; + + /***** Write message to show the change made *****/ + Ale_ShowAlert (Ale_SUCCESS,Txt_The_new_latitude_is_X,NewLatitude); + + /***** Show the form again *****/ + CtrCfg_ShowConfiguration (); + } + +/*****************************************************************************/ +/********************** Change the longitude of a centre **********************/ +/*****************************************************************************/ + +void CtrCfg_ChangeCtrLongitudeInConfig (void) + { + extern const char *Txt_The_new_longitude_is_X; + char LongitudeStr[64]; + double NewLongitude; + + /***** Get longitude *****/ + Par_GetParToText ("Longitude",LongitudeStr,sizeof (LongitudeStr) - 1); + NewLongitude = Str_GetDoubleFromStr (LongitudeStr); + if (NewLongitude < -180.0) + NewLongitude = -180.0; // West + else if (NewLongitude > 180.0) + NewLongitude = 180.0; // East + + /***** Update database changing old longitude by new longitude *****/ + CtrCfg_UpdateCtrCoordinateDB (Gbl.Hierarchy.Ctr.CtrCod,"Longitude",NewLongitude); + Gbl.Hierarchy.Ctr.Coord.Longitude = NewLongitude; + + /***** Write message to show the change made *****/ + Ale_ShowAlert (Ale_SUCCESS,Txt_The_new_longitude_is_X,NewLongitude); + + /***** Show the form again *****/ + CtrCfg_ShowConfiguration (); + } + +/*****************************************************************************/ +/********************** Change the latitude of a centre **********************/ +/*****************************************************************************/ + +void CtrCfg_ChangeCtrAltitudeInConfig (void) + { + extern const char *Txt_The_new_altitude_is_X; + char AltitudeStr[64]; + double NewAltitude; + + /***** Get altitude *****/ + Par_GetParToText ("Altitude",AltitudeStr,sizeof (AltitudeStr) - 1); + NewAltitude = Str_GetDoubleFromStr (AltitudeStr); + if (NewAltitude < -413.0) + NewAltitude = -413.0; // Dead Sea shore + else if (NewAltitude > 8848.0) + NewAltitude = 8848.0; // Mount Everest + + /***** Update database changing old altitude by new altitude *****/ + CtrCfg_UpdateCtrCoordinateDB (Gbl.Hierarchy.Ctr.CtrCod,"Altitude",NewAltitude); + Gbl.Hierarchy.Ctr.Coord.Altitude = NewAltitude; + + /***** Write message to show the change made *****/ + Ale_ShowAlert (Ale_SUCCESS,Txt_The_new_altitude_is_X,NewAltitude); + + /***** Show the form again *****/ + CtrCfg_ShowConfiguration (); + } + +/*****************************************************************************/ +/******** Update database changing old coordinate by new coordinate **********/ +/*****************************************************************************/ + +static void CtrCfg_UpdateCtrCoordinateDB (long CtrCod, + const char *CoordField,double NewCoord) + { + /***** Update database changing old coordinate by new coordinate *****/ + Str_SetDecimalPointToUS (); // To write the decimal point as a dot + DB_QueryUPDATE ("can not update a coordinate of a centre", + "UPDATE centres SET %s='%lg' WHERE CtrCod=%ld", + CoordField,NewCoord,CtrCod); + Str_SetDecimalPointToLocal (); // Return to local system + } + +/*****************************************************************************/ +/************************* Change the URL of a centre ************************/ +/*****************************************************************************/ + +void CtrCfg_ChangeCtrWWWInConfig (void) + { + extern const char *Txt_The_new_web_address_is_X; + char NewWWW[Cns_MAX_BYTES_WWW + 1]; + + /***** Get parameters from form *****/ + /* Get the new WWW for the centre */ + Par_GetParToText ("WWW",NewWWW,Cns_MAX_BYTES_WWW); + + /***** Check if new WWW is empty *****/ + if (NewWWW[0]) + { + /***** Update database changing old WWW by new WWW *****/ + Ctr_UpdateCtrWWWDB (Gbl.Hierarchy.Ctr.CtrCod,NewWWW); + Str_Copy (Gbl.Hierarchy.Ctr.WWW,NewWWW, + Cns_MAX_BYTES_WWW); + + /***** Write message to show the change made *****/ + Ale_ShowAlert (Ale_SUCCESS,Txt_The_new_web_address_is_X, + NewWWW); + } + else + Ale_CreateAlertYouCanNotLeaveFieldEmpty (); + + /***** Show the form again *****/ + CtrCfg_ShowConfiguration (); + } + +/*****************************************************************************/ +/** Show message of success after changing a centre in centre configuration **/ +/*****************************************************************************/ + +void CtrCfg_ContEditAfterChgCtrInConfig (void) + { + /***** Write error/success message *****/ + Ale_ShowAlerts (NULL); + + /***** Show the form again *****/ + CtrCfg_ShowConfiguration (); + } diff --git a/swad_centre_config.h b/swad_centre_config.h new file mode 100644 index 000000000..4a16cac00 --- /dev/null +++ b/swad_centre_config.h @@ -0,0 +1,57 @@ +// swad_centre_config.h: configuration of current centre + +#ifndef _SWAD_CTR_CFG +#define _SWAD_CTR_CFG +/* + 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-2019 Antonio Cañas Vargas + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ +/*****************************************************************************/ +/********************************* Headers ***********************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/************************** Public types and constants ***********************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/****************************** Public prototypes ****************************/ +/*****************************************************************************/ + +void CtrCfg_ShowConfiguration (void); +void CtrCfg_PrintConfiguration (void); + +void CtrCfg_RequestLogo (void); +void CtrCfg_ReceiveLogo (void); +void CtrCfg_RemoveLogo (void); +void CtrCfg_RequestPhoto (void); +void CtrCfg_ReceivePhoto (void); +void CtrCfg_ChangeCtrPhotoAttribution (void); +void CtrCfg_ChangeCtrInsInConfig (void); +void CtrCfg_RenameCentreShortInConfig (void); +void CtrCfg_RenameCentreFullInConfig (void); +void CtrCfg_ChangeCtrPlcInConfig (void); +void CtrCfg_ChangeCtrLatitudeInConfig (void); +void CtrCfg_ChangeCtrLongitudeInConfig (void); +void CtrCfg_ChangeCtrAltitudeInConfig (void); +void CtrCfg_ChangeCtrWWWInConfig (void); +void CtrCfg_ContEditAfterChgCtrInConfig (void); + +#endif diff --git a/swad_changelog.h b/swad_changelog.h index 40ee0306b..c9953db00 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -492,7 +492,7 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - * En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 19.103 (2019-12-28)" +#define Log_PLATFORM_VERSION "SWAD 19.104 (2019-12-29)" #define CSS_FILE "swad19.101.5.css" #define JS_FILE "swad19.91.1.js" /* @@ -500,8 +500,9 @@ ps2pdf source.ps destination.pdf // TODO: Impedir la creación y edición de proyectos si no son editables. // TODO: No se puede entrar con DNI '1' suponiendo que no tenga password ¿por qué? - Version 19.10x: Dec 28, 2019 Map in country information. (? lines) - Version 19.10x: Dec 28, 2019 Map in institution information. (? lines) + Version 19.10x: Dec 29, 2019 Map in country information. (? lines) + Version 19.10x: Dec 29, 2019 Map in institution information. (? lines) + Version 19.104: Dec 29, 2019 New module swad_centre_config for centre configuration. (249534 lines) Version 19.103: Dec 29, 2019 New module swad_degree_config for degree configuration. (249457 lines) Version 19.102: Dec 29, 2019 New module swad_course_config for course configuration. (249397 lines) Version 19.101.5: Dec 28, 2019 Country information is splitted into two columns. (249330 lines)