swad-core/swad_place.c

846 lines
28 KiB
C
Raw Normal View History

2014-12-01 23:55:08 +01:00
// swad_place.c: places
/*
SWAD (Shared Workspace At a Distance),
is a web platform developed at the University of Granada (Spain),
and used to support university teaching.
This file is part of SWAD core.
Copyright (C) 1999-2023 Antonio Ca<EFBFBD>as Vargas
2014-12-01 23:55:08 +01:00
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/********************************** Headers **********************************/
/*****************************************************************************/
2019-12-29 12:39:00 +01:00
#include <stddef.h> // For NULL
2014-12-01 23:55:08 +01:00
#include <stdlib.h> // For calloc
#include <string.h> // For string functions
#include "swad_action_list.h"
#include "swad_alert.h"
2017-06-10 21:38:10 +02:00
#include "swad_box.h"
#include "swad_center_database.h"
2014-12-01 23:55:08 +01:00
#include "swad_constant.h"
#include "swad_database.h"
#include "swad_error.h"
2018-11-09 20:47:39 +01:00
#include "swad_form.h"
2014-12-01 23:55:08 +01:00
#include "swad_global.h"
2019-10-23 19:05:05 +02:00
#include "swad_HTML.h"
2018-12-08 16:43:13 +01:00
#include "swad_language.h"
2014-12-01 23:55:08 +01:00
#include "swad_parameter.h"
#include "swad_parameter_code.h"
2014-12-01 23:55:08 +01:00
#include "swad_place.h"
#include "swad_place_database.h"
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/***************************** Private variables *****************************/
/*****************************************************************************/
2020-04-13 21:26:47 +02:00
static struct Plc_Place *Plc_EditingPlc = NULL; // Static variable to keep the place being edited
2019-04-09 00:24:50 +02:00
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
static Plc_Order_t Plc_GetParPlcOrder (void);
2018-11-15 10:33:45 +01:00
static bool Plc_CheckIfICanCreatePlaces (void);
2020-04-08 22:09:35 +02:00
static void Plc_PutIconsListingPlaces (__attribute__((unused)) void *Args);
2016-03-16 22:40:35 +01:00
static void Plc_PutIconToEditPlaces (void);
2019-04-09 00:24:50 +02:00
static void Plc_EditPlacesInternal (void);
2020-04-08 22:09:35 +02:00
static void Plc_PutIconsEditingPlaces (__attribute__((unused)) void *Args);
2018-11-15 10:13:53 +01:00
2020-04-13 21:26:47 +02:00
static void Plc_ListPlacesForEdition (const struct Plc_Places *Places);
static void Plc_PutParPlcCod (void *PlcCod);
2017-03-09 11:16:17 +01:00
2016-10-28 10:03:37 +02:00
static void Plc_RenamePlace (Cns_ShrtOrFullName_t ShrtOrFullName);
2017-03-09 11:16:17 +01:00
2014-12-01 23:55:08 +01:00
static void Plc_PutFormToCreatePlace (void);
static void Plc_PutHeadPlaces (void);
2019-04-09 00:24:50 +02:00
static void Plc_EditingPlaceConstructor (void);
static void Plc_EditingPlaceDestructor (void);
2020-04-13 21:26:47 +02:00
/*****************************************************************************/
/**************************** Reset places context ***************************/
/*****************************************************************************/
void Plc_ResetPlaces (struct Plc_Places *Places)
{
2020-04-13 22:04:46 +02:00
Places->Num = 0;
Places->Lst = NULL;
2020-04-13 21:26:47 +02:00
Places->SelectedOrder = Plc_ORDER_DEFAULT;
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/***************************** List all places *******************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
void Plc_SeePlaces (void)
{
2016-11-28 12:11:44 +01:00
extern const char *Hlp_INSTITUTION_Places;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Places;
extern const char *Txt_PLACES_HELP_ORDER[2];
extern const char *Txt_PLACES_ORDER[2];
extern const char *Txt_Other_places;
extern const char *Txt_Place_unspecified;
2017-03-27 13:38:10 +02:00
extern const char *Txt_New_place;
2020-04-13 21:26:47 +02:00
struct Plc_Places Places;
2017-01-29 12:42:19 +01:00
Plc_Order_t Order;
2014-12-01 23:55:08 +01:00
unsigned NumPlc;
unsigned NumCtrsWithPlc = 0;
unsigned NumCtrsInOtherPlcs;
2019-04-03 20:57:04 +02:00
if (Gbl.Hierarchy.Ins.InsCod > 0)
2014-12-01 23:55:08 +01:00
{
2020-04-13 21:26:47 +02:00
/***** Reset places context *****/
Plc_ResetPlaces (&Places);
2014-12-01 23:55:08 +01:00
/***** Get parameter with the type of order in the list of places *****/
Places.SelectedOrder = Plc_GetParPlcOrder ();
2014-12-01 23:55:08 +01:00
/***** Get list of places *****/
2020-04-13 21:26:47 +02:00
Plc_GetListPlaces (&Places);
2014-12-01 23:55:08 +01:00
/***** Table head *****/
2020-03-26 02:54:30 +01:00
Box_BoxBegin (NULL,Txt_Places,
2020-04-08 22:09:35 +02:00
Plc_PutIconsListingPlaces,NULL,
2017-06-12 15:03:29 +02:00
Hlp_INSTITUTION_Places,Box_NOT_CLOSABLE);
HTM_TABLE_BeginWideMarginPadding (2);
HTM_TR_Begin (NULL);
for (Order = (Plc_Order_t) 0;
Order <= (Plc_Order_t) (Plc_NUM_ORDERS - 1);
Order++)
{
HTM_TH_Begin (HTM_HEAD_LEFT);
Frm_BeginForm (ActSeePlc);
Par_PutParUnsigned (NULL,"Order",(unsigned) Order);
HTM_BUTTON_Submit_Begin (Txt_PLACES_HELP_ORDER[Order],
"class=\"BT_LINK\"");
if (Order == Places.SelectedOrder)
HTM_U_Begin ();
HTM_Txt (Txt_PLACES_ORDER[Order]);
if (Order == Places.SelectedOrder)
HTM_U_End ();
HTM_BUTTON_End ();
Frm_EndForm ();
HTM_TH_End ();
}
HTM_TR_End ();
/***** Write all places and their nuber of centers *****/
for (NumPlc = 0;
NumPlc < Places.Num;
NumPlc++)
{
/* Write data of this place */
HTM_TR_Begin (NULL);
HTM_TD_Begin ("class=\"LM DAT_%s\"",
The_GetSuffix ());
HTM_Txt (Places.Lst[NumPlc].FullName);
HTM_TD_End ();
HTM_TD_Begin ("class=\"RM DAT_%s\"",
The_GetSuffix ());
HTM_Unsigned (Places.Lst[NumPlc].NumCtrs);
HTM_TD_End ();
HTM_TR_End ();
NumCtrsWithPlc += Places.Lst[NumPlc].NumCtrs;
}
/***** Separation row *****/
HTM_TR_Begin (NULL);
HTM_TD_Begin ("colspan=\"2\" class=\"DAT_%s\"",
The_GetSuffix ());
HTM_NBSP ();
HTM_TD_End ();
HTM_TR_End ();
/***** Write centers (of the current institution) with other place *****/
NumCtrsInOtherPlcs = Ctr_DB_GetNumCtrsInPlc (0);
HTM_TR_Begin (NULL);
HTM_TD_Begin ("class=\"LM DAT_%s\"",
The_GetSuffix ());
HTM_Txt (Txt_Other_places);
HTM_TD_End ();
HTM_TD_Begin ("class=\"RM DAT_%s\"",
The_GetSuffix ());
HTM_Unsigned (NumCtrsInOtherPlcs);
HTM_TD_End ();
HTM_TR_End ();
NumCtrsWithPlc += NumCtrsInOtherPlcs;
/***** Write centers (of the current institution) with no place *****/
HTM_TR_Begin (NULL);
HTM_TD_Begin ("class=\"LM DAT_%s\"",The_GetSuffix ());
HTM_Txt (Txt_Place_unspecified);
HTM_TD_End ();
HTM_TD_Begin ("class=\"RM DAT_%s\"",The_GetSuffix ());
HTM_Unsigned (Ctr_GetNumCtrsInIns (Gbl.Hierarchy.Ins.InsCod) -
NumCtrsWithPlc);
HTM_TD_End ();
HTM_TR_End ();
/***** End table *****/
HTM_TABLE_End ();
/***** Button to create place *****/
if (Plc_CheckIfICanCreatePlaces ())
{
Frm_BeginForm (ActEdiPlc);
Btn_PutConfirmButton (Txt_New_place);
Frm_EndForm ();
}
2017-03-01 17:36:49 +01:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2014-12-01 23:55:08 +01:00
/***** Free list of places *****/
2020-04-13 21:26:47 +02:00
Plc_FreeListPlaces (&Places);
2014-12-01 23:55:08 +01:00
}
}
/*****************************************************************************/
/********** Get parameter with the type or order in list of places ***********/
/*****************************************************************************/
static Plc_Order_t Plc_GetParPlcOrder (void)
2014-12-01 23:55:08 +01:00
{
return (Plc_Order_t) Par_GetParUnsignedLong ("Order",
0,
Plc_NUM_ORDERS - 1,
(unsigned long) Plc_ORDER_DEFAULT);
2014-12-01 23:55:08 +01:00
}
2018-11-15 10:13:53 +01:00
/*****************************************************************************/
2018-11-15 10:33:45 +01:00
/********************** Check if I can create places *************************/
/*****************************************************************************/
static bool Plc_CheckIfICanCreatePlaces (void)
{
return Gbl.Usrs.Me.Role.Logged >= Rol_INS_ADM;
2018-11-15 10:33:45 +01:00
}
/*****************************************************************************/
/****************** Put contextual icons in list of places *******************/
2018-11-15 10:13:53 +01:00
/*****************************************************************************/
2020-04-08 22:09:35 +02:00
static void Plc_PutIconsListingPlaces (__attribute__((unused)) void *Args)
2018-11-15 10:13:53 +01:00
{
2020-04-08 22:09:35 +02:00
/***** Put icon to edit places *****/
if (Plc_CheckIfICanCreatePlaces ())
Plc_PutIconToEditPlaces ();
2018-11-15 10:13:53 +01:00
/***** Put icon to view centers *****/
Ctr_PutIconToViewCenters ();
2018-11-15 10:13:53 +01:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/********************** Put a link (form) to edit places *********************/
/*****************************************************************************/
2016-03-16 22:40:35 +01:00
static void Plc_PutIconToEditPlaces (void)
2014-12-01 23:55:08 +01:00
{
2020-03-26 02:54:30 +01:00
Ico_PutContextualIconToEdit (ActEdiPlc,NULL,
NULL,NULL);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*************************** Put forms to edit places ************************/
/*****************************************************************************/
void Plc_EditPlaces (void)
2019-04-09 00:24:50 +02:00
{
/***** Place constructor *****/
Plc_EditingPlaceConstructor ();
/***** Edit places *****/
Plc_EditPlacesInternal ();
/***** Place destructor *****/
Plc_EditingPlaceDestructor ();
}
static void Plc_EditPlacesInternal (void)
2014-12-01 23:55:08 +01:00
{
2017-04-30 21:00:56 +02:00
extern const char *Hlp_INSTITUTION_Places_edit;
extern const char *Txt_Places;
2020-04-13 21:26:47 +02:00
struct Plc_Places Places;
/***** Reset places context *****/
Plc_ResetPlaces (&Places);
2017-04-30 21:00:56 +02:00
2014-12-01 23:55:08 +01:00
/***** Get list of places *****/
2020-04-13 21:26:47 +02:00
Plc_GetListPlaces (&Places);
2014-12-01 23:55:08 +01:00
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
2020-03-26 02:54:30 +01:00
Box_BoxBegin (NULL,Txt_Places,
2020-04-08 22:09:35 +02:00
Plc_PutIconsEditingPlaces,NULL,
2017-06-12 15:03:29 +02:00
Hlp_INSTITUTION_Places_edit,Box_NOT_CLOSABLE);
2017-04-30 21:00:56 +02:00
2014-12-01 23:55:08 +01:00
/***** Put a form to create a new place *****/
Plc_PutFormToCreatePlace ();
/***** Forms to edit current places *****/
2020-04-13 21:26:47 +02:00
if (Places.Num)
Plc_ListPlacesForEdition (&Places);
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2017-04-30 21:00:56 +02:00
2014-12-01 23:55:08 +01:00
/***** Free list of places *****/
2020-04-13 21:26:47 +02:00
Plc_FreeListPlaces (&Places);
2014-12-01 23:55:08 +01:00
}
2017-04-30 21:00:56 +02:00
/*****************************************************************************/
/**************** Put contextual icons in edition of places *****************/
/*****************************************************************************/
2020-04-08 22:09:35 +02:00
static void Plc_PutIconsEditingPlaces (__attribute__((unused)) void *Args)
2017-04-30 21:00:56 +02:00
{
2020-04-08 22:09:35 +02:00
/***** Put icon to view places *****/
Plc_PutIconToViewPlaces ();
2018-11-15 10:41:11 +01:00
/***** Put icon to view centers *****/
Ctr_PutIconToViewCenters ();
2018-11-15 10:41:11 +01:00
}
/*****************************************************************************/
/************************** Put icon to view places **************************/
/*****************************************************************************/
void Plc_PutIconToViewPlaces (void)
{
2020-03-26 02:54:30 +01:00
Lay_PutContextualLinkOnlyIcon (ActSeePlc,NULL,
Ins_PutParInsCod,&Gbl.Hierarchy.Ins.InsCod,
"map-marker-alt.svg",Ico_BLACK);
2017-04-30 21:00:56 +02:00
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/******************************* List all places *****************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2020-04-13 21:26:47 +02:00
void Plc_GetListPlaces (struct Plc_Places *Places)
2014-12-01 23:55:08 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumPlc;
2020-04-13 21:26:47 +02:00
struct Plc_Place *Plc;
2014-12-01 23:55:08 +01:00
/***** Get places from database *****/
if ((Places->Num = Plc_DB_GetListPlaces (&mysql_res,Places->SelectedOrder))) // Places found...
2014-12-01 23:55:08 +01:00
{
/***** Create list with courses in center *****/
if ((Places->Lst = calloc ((size_t) Places->Num,
sizeof (*Places->Lst))) == NULL)
Err_NotEnoughMemoryExit ();
2014-12-01 23:55:08 +01:00
/***** Get the places *****/
for (NumPlc = 0;
2020-04-13 21:26:47 +02:00
NumPlc < Places->Num;
2014-12-01 23:55:08 +01:00
NumPlc++)
{
2020-04-13 21:26:47 +02:00
Plc = &(Places->Lst[NumPlc]);
2014-12-01 23:55:08 +01:00
/* Get next place */
row = mysql_fetch_row (mysql_res);
/* Get place code (row[0]) */
if ((Plc->PlcCod = Str_ConvertStrCodToLongCod (row[0])) <= 0)
Err_WrongPlaceExit ();
2014-12-01 23:55:08 +01:00
/* Get the short (row[1]) and full (row[2]) names of the place */
Str_Copy (Plc->ShrtName,row[1],sizeof (Plc->ShrtName) - 1);
Str_Copy (Plc->FullName,row[2],sizeof (Plc->FullName) - 1);
2014-12-01 23:55:08 +01:00
/* Get number of centers in this place (row[3]) */
2014-12-01 23:55:08 +01:00
if (sscanf (row[3],"%u",&Plc->NumCtrs) != 1)
Plc->NumCtrs = 0;
}
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/**************************** Get place full name ****************************/
/*****************************************************************************/
void Plc_GetPlaceDataByCod (struct Plc_Place *Plc)
2014-12-01 23:55:08 +01:00
{
2015-12-09 22:05:21 +01:00
extern const char *Txt_Place_unspecified;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Another_place;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
/***** Clear data *****/
2016-10-28 10:03:37 +02:00
Plc->ShrtName[0] = '\0';
2014-12-01 23:55:08 +01:00
Plc->FullName[0] = '\0';
Plc->NumCtrs = 0;
/***** Check if place code is correct *****/
2015-12-09 22:05:21 +01:00
if (Plc->PlcCod < 0)
{
Str_Copy (Plc->ShrtName,Txt_Place_unspecified,sizeof (Plc->ShrtName) - 1);
Str_Copy (Plc->FullName,Txt_Place_unspecified,sizeof (Plc->FullName) - 1);
2015-12-09 22:05:21 +01:00
}
else if (Plc->PlcCod == 0)
2014-12-01 23:55:08 +01:00
{
Str_Copy (Plc->ShrtName,Txt_Another_place ,sizeof (Plc->ShrtName) - 1);
Str_Copy (Plc->FullName,Txt_Another_place ,sizeof (Plc->FullName) - 1);
2014-12-01 23:55:08 +01:00
}
else if (Plc->PlcCod > 0)
{
/***** Get data of a place from database *****/
if (Plc_DB_GetPlaceDataByCod (&mysql_res,Plc->PlcCod)) // Place found...
2014-12-01 23:55:08 +01:00
{
/* Get row */
row = mysql_fetch_row (mysql_res);
/* Get the short (row[0]) and full (row[1]) names of the place */
Str_Copy (Plc->ShrtName,row[0],sizeof (Plc->ShrtName) - 1);
Str_Copy (Plc->FullName,row[1],sizeof (Plc->FullName) - 1);
2014-12-01 23:55:08 +01:00
/* Get number of centers in this place (row[2]) */
2014-12-01 23:55:08 +01:00
if (sscanf (row[2],"%u",&Plc->NumCtrs) != 1)
Plc->NumCtrs = 0;
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
}
/*****************************************************************************/
/**************************** Free list of places ****************************/
/*****************************************************************************/
2020-04-13 21:26:47 +02:00
void Plc_FreeListPlaces (struct Plc_Places *Places)
2014-12-01 23:55:08 +01:00
{
2020-04-13 21:26:47 +02:00
if (Places->Lst)
2014-12-01 23:55:08 +01:00
{
/***** Free memory used by the list of places in institution *****/
2020-04-13 21:26:47 +02:00
free (Places->Lst);
Places->Lst = NULL;
Places->Num = 0;
2014-12-01 23:55:08 +01:00
}
}
/*****************************************************************************/
/***************************** List all places *******************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2020-04-13 21:26:47 +02:00
static void Plc_ListPlacesForEdition (const struct Plc_Places *Places)
2014-12-01 23:55:08 +01:00
{
unsigned NumPlc;
2020-04-13 21:26:47 +02:00
struct Plc_Place *Plc;
2014-12-01 23:55:08 +01:00
/***** Begin table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginWidePadding (2);
2014-12-01 23:55:08 +01:00
/***** Write heading *****/
Plc_PutHeadPlaces ();
/***** Write all places *****/
for (NumPlc = 0;
NumPlc < Places->Num;
NumPlc++)
{
Plc = &Places->Lst[NumPlc];
HTM_TR_Begin (NULL);
/* Put icon to remove place */
HTM_TD_Begin ("class=\"BM\"");
if (Plc->NumCtrs) // Place has centers ==> deletion forbidden
Ico_PutIconRemovalNotAllowed ();
else
Ico_PutContextualIconToRemove (ActRemPlc,NULL,
Plc_PutParPlcCod,&Plc->PlcCod);
HTM_TD_End ();
/* Place code */
HTM_TD_Begin ("class=\"RM DAT_%s\"",The_GetSuffix ());
HTM_Long (Plc->PlcCod);
HTM_TD_End ();
/* Place short name */
HTM_TD_Begin ("class=\"CM\"");
Frm_BeginForm (ActRenPlcSho);
ParCod_PutPar (ParCod_Plc,Plc->PlcCod);
HTM_INPUT_TEXT ("ShortName",Plc_MAX_CHARS_PLACE_SHRT_NAME,Plc->ShrtName,
HTM_SUBMIT_ON_CHANGE,
"class=\"INPUT_SHORT_NAME INPUT_%s\"",
The_GetSuffix ());
Frm_EndForm ();
HTM_TD_End ();
/* Place full name */
HTM_TD_Begin ("class=\"CM\"");
Frm_BeginForm (ActRenPlcFul);
ParCod_PutPar (ParCod_Plc,Plc->PlcCod);
HTM_INPUT_TEXT ("FullName",Plc_MAX_CHARS_PLACE_FULL_NAME,Plc->FullName,
HTM_SUBMIT_ON_CHANGE,
"class=\"INPUT_FULL_NAME INPUT_%s\"",
The_GetSuffix ());
Frm_EndForm ();
HTM_TD_End ();
/* Number of centers */
HTM_TD_Begin ("class=\"RM DAT_%s\"",The_GetSuffix ());
HTM_Unsigned (Plc->NumCtrs);
HTM_TD_End ();
HTM_TR_End ();
}
2014-12-01 23:55:08 +01:00
2017-05-01 10:22:16 +02:00
/***** End table *****/
2019-10-23 19:05:05 +02:00
HTM_TABLE_End ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Write parameter with code of place *********************/
/*****************************************************************************/
static void Plc_PutParPlcCod (void *PlcCod)
2014-12-01 23:55:08 +01:00
{
2020-10-13 22:34:31 +02:00
if (PlcCod)
ParCod_PutPar (ParCod_Plc,*((long *) PlcCod));
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************************* Remove a place ******************************/
/*****************************************************************************/
void Plc_RemovePlace (void)
{
extern const char *Txt_To_remove_a_place_you_must_first_remove_all_centers_of_that_place;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Place_X_removed;
2019-04-09 00:24:50 +02:00
/***** Place constructor *****/
Plc_EditingPlaceConstructor ();
2014-12-01 23:55:08 +01:00
/***** Get place code *****/
Plc_EditingPlc->PlcCod = ParCod_GetAndCheckPar (ParCod_Plc);
2014-12-01 23:55:08 +01:00
/***** Get data of the place from database *****/
Plc_GetPlaceDataByCod (Plc_EditingPlc);
2014-12-01 23:55:08 +01:00
/***** Check if this place has centers *****/
if (Plc_EditingPlc->NumCtrs) // Place has centers ==> don't remove
2019-04-09 00:24:50 +02:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_To_remove_a_place_you_must_first_remove_all_centers_of_that_place);
else // Place has no centers ==> remove it
2014-12-01 23:55:08 +01:00
{
/***** Remove place *****/
Plc_DB_RemovePlace (Plc_EditingPlc->PlcCod);
2014-12-01 23:55:08 +01:00
/***** Write message to show the change made *****/
2019-04-09 00:24:50 +02:00
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_Place_X_removed,
Plc_EditingPlc->FullName);
2014-12-01 23:55:08 +01:00
}
}
/*****************************************************************************/
/********************* Change the short name of a place **********************/
/*****************************************************************************/
void Plc_RenamePlaceShort (void)
{
2019-04-09 00:24:50 +02:00
/***** Place constructor *****/
Plc_EditingPlaceConstructor ();
/***** Rename place *****/
2016-10-28 10:03:37 +02:00
Plc_RenamePlace (Cns_SHRT_NAME);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Change the full name of a place ***********************/
/*****************************************************************************/
void Plc_RenamePlaceFull (void)
{
2019-04-09 00:24:50 +02:00
/***** Place constructor *****/
Plc_EditingPlaceConstructor ();
/***** Rename place *****/
2014-12-01 23:55:08 +01:00
Plc_RenamePlace (Cns_FULL_NAME);
}
/*****************************************************************************/
/************************ Change the name of a place *************************/
/*****************************************************************************/
2016-10-28 10:03:37 +02:00
static void Plc_RenamePlace (Cns_ShrtOrFullName_t ShrtOrFullName)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_The_place_X_already_exists;
extern const char *Txt_The_place_X_has_been_renamed_as_Y;
extern const char *Txt_The_name_X_has_not_changed;
const char *ParName = NULL; // Initialized to avoid warning
const char *FldName = NULL; // Initialized to avoid warning
unsigned MaxBytes = 0; // Initialized to avoid warning
char *CurrentPlcName = NULL; // Initialized to avoid warning
2017-03-07 19:55:29 +01:00
char NewPlcName[Plc_MAX_BYTES_PLACE_FULL_NAME + 1];
2014-12-01 23:55:08 +01:00
2016-10-28 10:03:37 +02:00
switch (ShrtOrFullName)
2014-12-01 23:55:08 +01:00
{
2016-10-28 10:03:37 +02:00
case Cns_SHRT_NAME:
ParName = "ShortName";
FldName = "ShortName";
2017-03-07 19:55:29 +01:00
MaxBytes = Plc_MAX_BYTES_PLACE_SHRT_NAME;
2019-04-09 00:24:50 +02:00
CurrentPlcName = Plc_EditingPlc->ShrtName;
2014-12-01 23:55:08 +01:00
break;
case Cns_FULL_NAME:
ParName = "FullName";
FldName = "FullName";
2017-03-07 19:55:29 +01:00
MaxBytes = Plc_MAX_BYTES_PLACE_FULL_NAME;
2019-04-09 00:24:50 +02:00
CurrentPlcName = Plc_EditingPlc->FullName;
2014-12-01 23:55:08 +01:00
break;
}
/***** Get parameters from form *****/
/* Get the code of the place */
Plc_EditingPlc->PlcCod = ParCod_GetAndCheckPar (ParCod_Plc);
2014-12-01 23:55:08 +01:00
/* Get the new name for the place */
Par_GetParText (ParName,NewPlcName,MaxBytes);
2014-12-01 23:55:08 +01:00
/***** Get from the database the old names of the place *****/
Plc_GetPlaceDataByCod (Plc_EditingPlc);
2014-12-01 23:55:08 +01:00
/***** Check if new name is empty *****/
2019-12-20 00:30:54 +01:00
if (NewPlcName[0])
2014-12-01 23:55:08 +01:00
{
2019-01-02 15:10:51 +01:00
/***** Check if old and new names are the same
(this happens when return is pressed without changes) *****/
2014-12-01 23:55:08 +01:00
if (strcmp (CurrentPlcName,NewPlcName)) // Different names
{
/***** If place was in database... *****/
if (Plc_DB_CheckIfPlaceNameExists (Plc_EditingPlc->PlcCod,ParName,NewPlcName))
2019-04-09 00:24:50 +02:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_place_X_already_exists,
NewPlcName);
2014-12-01 23:55:08 +01:00
else
{
/* Update the table changing old name by new name */
Plc_DB_UpdatePlcName (Plc_EditingPlc->PlcCod,FldName,NewPlcName);
2014-12-01 23:55:08 +01:00
2017-03-09 11:16:17 +01:00
/* Write message to show the change made */
2019-04-09 00:24:50 +02:00
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_The_place_X_has_been_renamed_as_Y,
CurrentPlcName,NewPlcName);
2014-12-01 23:55:08 +01:00
}
}
else // The same name
2019-04-09 00:24:50 +02:00
Ale_CreateAlert (Ale_INFO,NULL,
Txt_The_name_X_has_not_changed,CurrentPlcName);
2014-12-01 23:55:08 +01:00
}
2019-12-20 00:30:54 +01:00
else
Ale_CreateAlertYouCanNotLeaveFieldEmpty ();
2014-12-01 23:55:08 +01:00
2019-04-09 00:24:50 +02:00
/***** Update place name *****/
Str_Copy (CurrentPlcName,NewPlcName,MaxBytes);
2014-12-01 23:55:08 +01:00
}
2019-04-09 00:24:50 +02:00
/*****************************************************************************/
/********** Show alerts after changing a place and continue editing **********/
/*****************************************************************************/
void Plc_ContEditAfterChgPlc (void)
{
/***** Write message to show the change made *****/
Ale_ShowAlerts (NULL);
/***** Show the form again *****/
Plc_EditPlacesInternal ();
/***** Place destructor *****/
Plc_EditingPlaceDestructor ();
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/********************* Put a form to create a new place **********************/
/*****************************************************************************/
static void Plc_PutFormToCreatePlace (void)
{
extern const char *Txt_New_place;
extern const char *Txt_Create_place;
2019-10-20 22:00:28 +02:00
/***** Begin form *****/
Frm_BeginForm (ActNewPlc);
2014-12-01 23:55:08 +01:00
/***** Begin box and table *****/
Box_BoxTableBegin (NULL,Txt_New_place,
NULL,NULL,
NULL,Box_NOT_CLOSABLE,2);
2014-12-01 23:55:08 +01:00
/***** Write heading *****/
Plc_PutHeadPlaces ();
2017-04-30 21:00:56 +02:00
HTM_TR_Begin (NULL);
2019-10-09 21:05:58 +02:00
/***** Column to remove place, disabled here *****/
HTM_TD_Begin ("class=\"BM\"");
HTM_TD_End ();
/***** Place code *****/
HTM_TD_Begin ("class=\"CODE\"");
HTM_TD_End ();
/***** Place short name *****/
HTM_TD_Begin ("class=\"CM\"");
HTM_INPUT_TEXT ("ShortName",Plc_MAX_CHARS_PLACE_SHRT_NAME,Plc_EditingPlc->ShrtName,
HTM_DONT_SUBMIT_ON_CHANGE,
"class=\"INPUT_SHORT_NAME INPUT_%s\""
" required=\"required\"",
The_GetSuffix ());
HTM_TD_End ();
/***** Place full name *****/
HTM_TD_Begin ("class=\"CM\"");
HTM_INPUT_TEXT ("FullName",Plc_MAX_CHARS_PLACE_FULL_NAME,Plc_EditingPlc->FullName,
HTM_DONT_SUBMIT_ON_CHANGE,
"class=\"INPUT_FULL_NAME INPUT_%s\""
" required=\"required\"",
The_GetSuffix ());
HTM_TD_End ();
/***** Number of centers *****/
HTM_TD_Begin ("class=\"RM DAT_%s\"",The_GetSuffix ());
HTM_Unsigned (0);
HTM_TD_End ();
2019-10-07 20:17:29 +02:00
HTM_TR_End ();
2017-04-30 21:00:56 +02:00
/***** End table, send button and end box *****/
Box_BoxTableWithButtonEnd (Btn_CREATE_BUTTON,Txt_Create_place);
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** End form *****/
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Write header with fields of a place ********************/
/*****************************************************************************/
static void Plc_PutHeadPlaces (void)
{
extern const char *Txt_Code;
2015-02-04 20:03:23 +01:00
extern const char *Txt_Short_name;
extern const char *Txt_Full_name;
extern const char *Txt_Centers;
2014-12-01 23:55:08 +01:00
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
HTM_TH_Span (NULL ,HTM_HEAD_CENTER,1,1,"BT");
HTM_TH (Txt_Code ,HTM_HEAD_RIGHT );
HTM_TH (Txt_Short_name,HTM_HEAD_LEFT );
HTM_TH (Txt_Full_name ,HTM_HEAD_LEFT );
HTM_TH (Txt_Centers ,HTM_HEAD_RIGHT );
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************* Receive form to create a new place **********************/
/*****************************************************************************/
2020-05-05 21:49:00 +02:00
void Plc_ReceiveFormNewPlace (void)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_The_place_X_already_exists;
2019-04-09 00:24:50 +02:00
extern const char *Txt_Created_new_place_X;
2014-12-01 23:55:08 +01:00
2019-04-09 00:24:50 +02:00
/***** Place constructor *****/
Plc_EditingPlaceConstructor ();
2014-12-01 23:55:08 +01:00
/***** Get parameters from form *****/
/* Get place short name */
Par_GetParText ("ShortName",Plc_EditingPlc->ShrtName,Plc_MAX_BYTES_PLACE_SHRT_NAME);
2014-12-01 23:55:08 +01:00
/* Get place full name */
Par_GetParText ("FullName",Plc_EditingPlc->FullName,Plc_MAX_BYTES_PLACE_FULL_NAME);
2014-12-01 23:55:08 +01:00
2019-04-09 00:24:50 +02:00
if (Plc_EditingPlc->ShrtName[0] &&
Plc_EditingPlc->FullName[0]) // If there's a place name
2014-12-01 23:55:08 +01:00
{
/***** If name of place was in database... *****/
if (Plc_DB_CheckIfPlaceNameExists (-1L,"ShortName",Plc_EditingPlc->ShrtName))
2019-04-09 00:24:50 +02:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_place_X_already_exists,
Plc_EditingPlc->ShrtName);
else if (Plc_DB_CheckIfPlaceNameExists (-1L,"FullName",Plc_EditingPlc->FullName))
2019-04-09 00:24:50 +02:00
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_place_X_already_exists,
Plc_EditingPlc->FullName);
2014-12-01 23:55:08 +01:00
else // Add new place to database
2019-04-09 00:24:50 +02:00
{
Plc_DB_CreatePlace (Plc_EditingPlc);
2019-04-09 00:24:50 +02:00
Ale_CreateAlert (Ale_SUCCESS,NULL,Txt_Created_new_place_X,
Plc_EditingPlc->FullName);
}
2014-12-01 23:55:08 +01:00
}
else // If there is not a place name
Ale_ShowAlertYouMustSpecifyTheShortNameAndTheFullName ();
2014-12-01 23:55:08 +01:00
}
2019-04-09 00:24:50 +02:00
/*****************************************************************************/
/************************* Place constructor/destructor **********************/
/*****************************************************************************/
static void Plc_EditingPlaceConstructor (void)
{
/***** Pointer must be NULL *****/
if (Plc_EditingPlc != NULL)
Err_WrongPlaceExit ();
2019-04-09 00:24:50 +02:00
/***** Allocate memory for place *****/
if ((Plc_EditingPlc = malloc (sizeof (*Plc_EditingPlc))) == NULL)
Err_NotEnoughMemoryExit ();
2019-04-09 00:24:50 +02:00
/***** Reset place *****/
Plc_EditingPlc->PlcCod = -1L;
Plc_EditingPlc->InsCod = -1L;
Plc_EditingPlc->ShrtName[0] = '\0';
Plc_EditingPlc->FullName[0] = '\0';
Plc_EditingPlc->NumCtrs = 0;
}
2014-12-01 23:55:08 +01:00
2019-04-09 00:24:50 +02:00
static void Plc_EditingPlaceDestructor (void)
{
/***** Free memory used for place *****/
if (Plc_EditingPlc != NULL)
{
2019-11-06 19:45:20 +01:00
free (Plc_EditingPlc);
2019-04-09 00:24:50 +02:00
Plc_EditingPlc = NULL;
}
2014-12-01 23:55:08 +01:00
}