2021-03-07 21:21:04 +01:00
|
|
|
|
// swad_building.c: buildings in a center
|
2020-04-22 03:19:27 +02:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
SWAD (Shared Workspace At a Distance),
|
|
|
|
|
is a web platform developed at the University of Granada (Spain),
|
|
|
|
|
and used to support university teaching.
|
|
|
|
|
|
|
|
|
|
This file is part of SWAD core.
|
2021-02-09 12:43:45 +01:00
|
|
|
|
Copyright (C) 1999-2021 Antonio Ca<EFBFBD>as Vargas
|
2020-04-22 03:19:27 +02: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 **********************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include <malloc.h> // For calloc, free
|
|
|
|
|
#include <stddef.h> // For NULL
|
|
|
|
|
#include <string.h> // For string functions
|
|
|
|
|
|
|
|
|
|
#include "swad_box.h"
|
|
|
|
|
#include "swad_building.h"
|
2021-06-01 23:19:59 +02:00
|
|
|
|
#include "swad_building_database.h"
|
2020-04-22 03:19:27 +02:00
|
|
|
|
#include "swad_database.h"
|
2021-04-26 15:27:27 +02:00
|
|
|
|
#include "swad_error.h"
|
2020-04-22 03:19:27 +02:00
|
|
|
|
#include "swad_form.h"
|
|
|
|
|
#include "swad_global.h"
|
|
|
|
|
#include "swad_HTML.h"
|
2021-10-13 22:52:59 +02:00
|
|
|
|
#include "swad_room_database.h"
|
2020-04-22 03:19:27 +02:00
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************** External global variables from others modules ****************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
extern struct Globals Gbl;
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Private variables *****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static struct Bld_Building *Bld_EditingBuilding = NULL; // Static variable to keep the building being edited
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Private prototypes ****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static Bld_Order_t Bld_GetParamBuildingOrder (void);
|
|
|
|
|
static bool Bld_CheckIfICanCreateBuildings (void);
|
|
|
|
|
static void Bld_PutIconsListingBuildings (__attribute__((unused)) void *Args);
|
|
|
|
|
static void Bld_PutIconToEditBuildings (void);
|
|
|
|
|
static void Bld_PutIconsEditingBuildings (__attribute__((unused)) void *Args);
|
|
|
|
|
|
|
|
|
|
static void Bld_EditBuildingsInternal (void);
|
|
|
|
|
|
|
|
|
|
static void Bld_ListBuildingsForEdition (const struct Bld_Buildings *Buildings);
|
2020-10-13 22:34:31 +02:00
|
|
|
|
static void Bld_PutParamBldCod (void *BldCod);
|
2020-04-22 03:19:27 +02:00
|
|
|
|
|
|
|
|
|
static void Bld_RenameBuilding (Cns_ShrtOrFullName_t ShrtOrFullName);
|
|
|
|
|
|
|
|
|
|
static void Bld_PutFormToCreateBuilding (void);
|
|
|
|
|
static void Bld_PutHeadBuildings (void);
|
|
|
|
|
|
|
|
|
|
static void Bld_EditingBuildingConstructor (void);
|
|
|
|
|
static void Bld_EditingBuildingDestructor (void);
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************** Reset buildings context **************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Bld_ResetBuildings (struct Bld_Buildings *Buildings)
|
|
|
|
|
{
|
|
|
|
|
Buildings->Num = 0; // Number of buildings
|
|
|
|
|
Buildings->Lst = NULL; // List of buildings
|
|
|
|
|
Buildings->SelectedOrder = Bld_ORDER_DEFAULT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-10-30 13:28:48 +02:00
|
|
|
|
/****************************** List all buildings ***************************/
|
2020-04-22 03:19:27 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Bld_SeeBuildings (void)
|
|
|
|
|
{
|
2021-03-07 21:21:04 +01:00
|
|
|
|
extern const char *Hlp_CENTER_Buildings;
|
2020-04-22 03:19:27 +02:00
|
|
|
|
extern const char *Txt_Buildings;
|
|
|
|
|
extern const char *Txt_BUILDINGS_HELP_ORDER[Bld_NUM_ORDERS];
|
|
|
|
|
extern const char *Txt_BUILDINGS_ORDER[Bld_NUM_ORDERS];
|
|
|
|
|
extern const char *Txt_New_building;
|
|
|
|
|
struct Bld_Buildings Buildings;
|
|
|
|
|
Bld_Order_t Order;
|
|
|
|
|
unsigned NumBuilding;
|
|
|
|
|
|
|
|
|
|
/***** Trivial check *****/
|
2021-03-07 21:21:04 +01:00
|
|
|
|
if (Gbl.Hierarchy.Ctr.CtrCod <= 0) // No center selected
|
2020-04-22 03:19:27 +02:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/***** Reset buildings context *****/
|
|
|
|
|
Bld_ResetBuildings (&Buildings);
|
|
|
|
|
|
|
|
|
|
/***** Get parameter with the type of order in the list of buildings *****/
|
|
|
|
|
Buildings.SelectedOrder = Bld_GetParamBuildingOrder ();
|
|
|
|
|
|
|
|
|
|
/***** Get list of buildings *****/
|
|
|
|
|
Bld_GetListBuildings (&Buildings,Bld_ALL_DATA);
|
|
|
|
|
|
|
|
|
|
/***** Table head *****/
|
|
|
|
|
Box_BoxBegin (NULL,Txt_Buildings,
|
|
|
|
|
Bld_PutIconsListingBuildings,NULL,
|
2021-03-07 21:21:04 +01:00
|
|
|
|
Hlp_CENTER_Buildings,Box_NOT_CLOSABLE);
|
2020-04-22 03:19:27 +02:00
|
|
|
|
|
2021-06-01 23:19:59 +02:00
|
|
|
|
HTM_TABLE_BeginWideMarginPadding (2);
|
|
|
|
|
HTM_TR_Begin (NULL);
|
|
|
|
|
for (Order = (Bld_Order_t) 0;
|
|
|
|
|
Order <= (Bld_Order_t) (Bld_NUM_ORDERS - 1);
|
|
|
|
|
Order++)
|
|
|
|
|
{
|
2022-01-02 15:17:30 +01:00
|
|
|
|
HTM_TH_Begin (HTM_HEAD_LEFT);
|
2021-06-01 23:19:59 +02:00
|
|
|
|
Frm_BeginForm (ActSeeBld);
|
2021-12-01 01:43:13 +01:00
|
|
|
|
Par_PutHiddenParamUnsigned (NULL,"Order",(unsigned) Order);
|
2022-04-01 01:06:44 +02:00
|
|
|
|
HTM_BUTTON_Submit_Begin (Txt_BUILDINGS_HELP_ORDER[Order],
|
|
|
|
|
"class=\"BT_LINK\"");
|
2021-06-01 23:19:59 +02:00
|
|
|
|
if (Order == Buildings.SelectedOrder)
|
|
|
|
|
HTM_U_Begin ();
|
|
|
|
|
HTM_Txt (Txt_BUILDINGS_ORDER[Order]);
|
|
|
|
|
if (Order == Buildings.SelectedOrder)
|
|
|
|
|
HTM_U_End ();
|
|
|
|
|
HTM_BUTTON_End ();
|
|
|
|
|
Frm_EndForm ();
|
|
|
|
|
HTM_TH_End ();
|
|
|
|
|
}
|
|
|
|
|
HTM_TR_End ();
|
|
|
|
|
|
|
|
|
|
/***** Write list of buildings *****/
|
2022-03-19 02:05:53 +01:00
|
|
|
|
for (NumBuilding = 0;
|
2021-06-01 23:19:59 +02:00
|
|
|
|
NumBuilding < Buildings.Num;
|
2022-03-24 01:18:19 +01:00
|
|
|
|
NumBuilding++, The_ChangeRowColor ())
|
2021-06-01 23:19:59 +02:00
|
|
|
|
{
|
|
|
|
|
HTM_TR_Begin (NULL);
|
|
|
|
|
|
|
|
|
|
/* Short name */
|
2022-03-26 22:17:38 +01:00
|
|
|
|
HTM_TD_Begin ("class=\"LM DAT_%s %s\"",
|
2022-04-05 01:00:24 +02:00
|
|
|
|
The_GetSuffix (),The_GetColorRows ());
|
2021-06-01 23:19:59 +02:00
|
|
|
|
HTM_Txt (Buildings.Lst[NumBuilding].ShrtName);
|
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
|
|
|
|
/* Full name */
|
2022-03-26 22:17:38 +01:00
|
|
|
|
HTM_TD_Begin ("class=\"LM DAT_%s %s\"",
|
2022-04-05 01:00:24 +02:00
|
|
|
|
The_GetSuffix (),The_GetColorRows ());
|
2021-06-01 23:19:59 +02:00
|
|
|
|
HTM_Txt (Buildings.Lst[NumBuilding].FullName);
|
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
|
|
|
|
/* Location */
|
2022-03-26 22:17:38 +01:00
|
|
|
|
HTM_TD_Begin ("class=\"LM DAT_%s %s\"",
|
2022-04-05 01:00:24 +02:00
|
|
|
|
The_GetSuffix (),The_GetColorRows ());
|
2021-06-01 23:19:59 +02:00
|
|
|
|
HTM_Txt (Buildings.Lst[NumBuilding].Location);
|
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
|
|
|
|
HTM_TR_End ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***** End table *****/
|
|
|
|
|
HTM_TABLE_End ();
|
|
|
|
|
|
|
|
|
|
/***** Button to create building *****/
|
|
|
|
|
if (Bld_CheckIfICanCreateBuildings ())
|
|
|
|
|
{
|
|
|
|
|
Frm_BeginForm (ActEdiBld);
|
|
|
|
|
Btn_PutConfirmButton (Txt_New_building);
|
|
|
|
|
Frm_EndForm ();
|
|
|
|
|
}
|
2020-04-22 03:19:27 +02:00
|
|
|
|
|
|
|
|
|
/***** End box *****/
|
|
|
|
|
Box_BoxEnd ();
|
|
|
|
|
|
|
|
|
|
/***** Free list of buildings *****/
|
|
|
|
|
Bld_FreeListBuildings (&Buildings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********* Get parameter with the type or order in list of buildings *********/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static Bld_Order_t Bld_GetParamBuildingOrder (void)
|
|
|
|
|
{
|
|
|
|
|
return (Bld_Order_t) Par_GetParToUnsignedLong ("Order",
|
|
|
|
|
0,
|
|
|
|
|
Bld_NUM_ORDERS - 1,
|
|
|
|
|
(unsigned long) Bld_ORDER_DEFAULT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************* Check if I can create buildings ***********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static bool Bld_CheckIfICanCreateBuildings (void)
|
|
|
|
|
{
|
2021-11-12 01:12:15 +01:00
|
|
|
|
return Gbl.Usrs.Me.Role.Logged >= Rol_CTR_ADM;
|
2020-04-22 03:19:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/**************** Put contextual icons in list of buildings ******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void Bld_PutIconsListingBuildings (__attribute__((unused)) void *Args)
|
|
|
|
|
{
|
|
|
|
|
/***** Put icon to edit buildings *****/
|
|
|
|
|
if (Bld_CheckIfICanCreateBuildings ())
|
|
|
|
|
Bld_PutIconToEditBuildings ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************** Put a link (form) to edit buildings ********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void Bld_PutIconToEditBuildings (void)
|
|
|
|
|
{
|
|
|
|
|
Ico_PutContextualIconToEdit (ActEdiBld,NULL,
|
|
|
|
|
NULL,NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************* Put forms to edit buildings ***********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Bld_EditBuildings (void)
|
|
|
|
|
{
|
|
|
|
|
/***** Building constructor *****/
|
|
|
|
|
Bld_EditingBuildingConstructor ();
|
|
|
|
|
|
|
|
|
|
/***** Edit buildings *****/
|
|
|
|
|
Bld_EditBuildingsInternal ();
|
|
|
|
|
|
|
|
|
|
/***** Building destructor *****/
|
|
|
|
|
Bld_EditingBuildingDestructor ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void Bld_EditBuildingsInternal (void)
|
|
|
|
|
{
|
2021-03-07 21:21:04 +01:00
|
|
|
|
extern const char *Hlp_CENTER_Buildings_edit;
|
2020-04-22 03:19:27 +02:00
|
|
|
|
extern const char *Txt_Buildings;
|
|
|
|
|
struct Bld_Buildings Buildings;
|
|
|
|
|
|
|
|
|
|
/***** Reset buildings context *****/
|
|
|
|
|
Bld_ResetBuildings (&Buildings);
|
|
|
|
|
|
|
|
|
|
/***** Get list of buildings *****/
|
|
|
|
|
Bld_GetListBuildings (&Buildings,Bld_ALL_DATA);
|
|
|
|
|
|
|
|
|
|
/***** Begin box *****/
|
|
|
|
|
Box_BoxBegin (NULL,Txt_Buildings,
|
|
|
|
|
Bld_PutIconsEditingBuildings,NULL,
|
2021-03-07 21:21:04 +01:00
|
|
|
|
Hlp_CENTER_Buildings_edit,Box_NOT_CLOSABLE);
|
2020-04-22 03:19:27 +02:00
|
|
|
|
|
2021-06-01 23:19:59 +02:00
|
|
|
|
/***** Put a form to create a new building *****/
|
|
|
|
|
Bld_PutFormToCreateBuilding ();
|
2020-04-22 03:19:27 +02:00
|
|
|
|
|
2021-06-01 23:19:59 +02:00
|
|
|
|
/***** Forms to edit current buildings *****/
|
|
|
|
|
if (Buildings.Num)
|
|
|
|
|
Bld_ListBuildingsForEdition (&Buildings);
|
2020-04-22 03:19:27 +02:00
|
|
|
|
|
|
|
|
|
/***** End box *****/
|
|
|
|
|
Box_BoxEnd ();
|
|
|
|
|
|
|
|
|
|
/***** Free list of buildings *****/
|
|
|
|
|
Bld_FreeListBuildings (&Buildings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*************** Put contextual icons in edition of buildings ****************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void Bld_PutIconsEditingBuildings (__attribute__((unused)) void *Args)
|
|
|
|
|
{
|
|
|
|
|
/***** Put icon to view buildings *****/
|
|
|
|
|
Bld_PutIconToViewBuildings ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************ Put icon to view buildings *************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Bld_PutIconToViewBuildings (void)
|
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_Buildings;
|
|
|
|
|
|
|
|
|
|
Lay_PutContextualLinkOnlyIcon (ActSeeBld,NULL,
|
|
|
|
|
NULL,NULL,
|
2021-12-22 00:20:06 +01:00
|
|
|
|
"building.svg",Ico_BLACK,
|
2020-04-22 03:19:27 +02:00
|
|
|
|
Txt_Buildings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-10-30 13:28:48 +02:00
|
|
|
|
/***************************** List all buildings ***************************/
|
2020-04-22 03:19:27 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Bld_GetListBuildings (struct Bld_Buildings *Buildings,
|
|
|
|
|
Bld_WhichData_t WhichData)
|
|
|
|
|
{
|
|
|
|
|
MYSQL_RES *mysql_res;
|
|
|
|
|
MYSQL_ROW row;
|
|
|
|
|
unsigned NumBuilding;
|
|
|
|
|
struct Bld_Building *Building;
|
|
|
|
|
|
|
|
|
|
/***** Get buildings from database *****/
|
2021-06-01 23:19:59 +02:00
|
|
|
|
Buildings->Num = Bld_DB_GetListBuildings (&mysql_res,WhichData,Buildings->SelectedOrder);
|
2020-04-22 03:19:27 +02:00
|
|
|
|
|
|
|
|
|
/***** Count number of rows in result *****/
|
2021-04-16 13:51:12 +02:00
|
|
|
|
if (Buildings->Num) // Buildings found...
|
2020-04-22 03:19:27 +02:00
|
|
|
|
{
|
2021-03-07 21:21:04 +01:00
|
|
|
|
/***** Create list with courses in center *****/
|
2021-04-16 13:51:12 +02:00
|
|
|
|
if ((Buildings->Lst = calloc ((size_t) Buildings->Num,sizeof (*Buildings->Lst))) == NULL)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_NotEnoughMemoryExit ();
|
2020-04-22 03:19:27 +02:00
|
|
|
|
|
|
|
|
|
/***** Get the buildings *****/
|
|
|
|
|
for (NumBuilding = 0;
|
|
|
|
|
NumBuilding < Buildings->Num;
|
|
|
|
|
NumBuilding++)
|
|
|
|
|
{
|
|
|
|
|
Building = &Buildings->Lst[NumBuilding];
|
|
|
|
|
|
|
|
|
|
/* Get next building */
|
|
|
|
|
row = mysql_fetch_row (mysql_res);
|
|
|
|
|
|
|
|
|
|
/* Get building code (row[0]) */
|
2021-04-25 13:24:39 +02:00
|
|
|
|
if ((Building->BldCod = Str_ConvertStrCodToLongCod (row[0])) <= 0)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_WrongBuildingExit ();
|
2020-04-22 03:19:27 +02:00
|
|
|
|
|
|
|
|
|
/* Get the short name of the building (row[1]) */
|
2021-02-15 16:25:55 +01:00
|
|
|
|
Str_Copy (Building->ShrtName,row[1],sizeof (Building->ShrtName) - 1);
|
2020-04-22 03:19:27 +02:00
|
|
|
|
|
|
|
|
|
if (WhichData == Bld_ALL_DATA)
|
|
|
|
|
{
|
2021-02-15 22:49:44 +01:00
|
|
|
|
/* Get full name (row[2]) and location (row[3]) of the building */
|
|
|
|
|
Str_Copy (Building->FullName,row[2],sizeof (Building->FullName) - 1);
|
|
|
|
|
Str_Copy (Building->Location,row[3],sizeof (Building->Location) - 1);
|
2020-04-22 03:19:27 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***** Free structure that stores the query result *****/
|
|
|
|
|
DB_FreeMySQLResult (&mysql_res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*************************** Get building full name **************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Bld_GetDataOfBuildingByCod (struct Bld_Building *Building)
|
|
|
|
|
{
|
|
|
|
|
MYSQL_RES *mysql_res;
|
|
|
|
|
MYSQL_ROW row;
|
|
|
|
|
|
|
|
|
|
/***** Clear data *****/
|
|
|
|
|
Building->ShrtName[0] = '\0';
|
|
|
|
|
Building->FullName[0] = '\0';
|
|
|
|
|
Building->Location[0] = '\0';
|
|
|
|
|
|
|
|
|
|
/***** Check if building code is correct *****/
|
|
|
|
|
if (Building->BldCod > 0)
|
|
|
|
|
{
|
|
|
|
|
/***** Get data of a building from database *****/
|
2021-06-01 23:19:59 +02:00
|
|
|
|
if (Bld_DB_GetDataOfBuildingByCod (&mysql_res,Building->BldCod)) // Building found...
|
2020-04-22 03:19:27 +02:00
|
|
|
|
{
|
|
|
|
|
/* Get row */
|
|
|
|
|
row = mysql_fetch_row (mysql_res);
|
|
|
|
|
|
2021-02-15 22:49:44 +01:00
|
|
|
|
/* Get short name (row[0]), full name (row[1])
|
|
|
|
|
and location (row[2]) of the building */
|
2021-02-15 16:25:55 +01:00
|
|
|
|
Str_Copy (Building->ShrtName,row[0],sizeof (Building->ShrtName) - 1);
|
|
|
|
|
Str_Copy (Building->FullName,row[1],sizeof (Building->FullName) - 1);
|
|
|
|
|
Str_Copy (Building->Location,row[2],sizeof (Building->Location) - 1);
|
2020-04-22 03:19:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***** Free structure that stores the query result *****/
|
|
|
|
|
DB_FreeMySQLResult (&mysql_res);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************** Free list of buildings ***************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Bld_FreeListBuildings (struct Bld_Buildings *Buildings)
|
|
|
|
|
{
|
|
|
|
|
if (Buildings->Lst)
|
|
|
|
|
{
|
|
|
|
|
/***** Free memory used by the list of buildings in institution *****/
|
|
|
|
|
free (Buildings->Lst);
|
|
|
|
|
Buildings->Lst = NULL;
|
|
|
|
|
Buildings->Num = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-10-30 13:28:48 +02:00
|
|
|
|
/**************************** List all buildings *****************************/
|
2020-04-22 03:19:27 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void Bld_ListBuildingsForEdition (const struct Bld_Buildings *Buildings)
|
|
|
|
|
{
|
|
|
|
|
unsigned NumBld;
|
|
|
|
|
struct Bld_Building *Building;
|
|
|
|
|
char *Anchor = NULL;
|
|
|
|
|
|
2021-06-01 23:19:59 +02:00
|
|
|
|
/***** Begin table *****/
|
2020-04-22 03:19:27 +02:00
|
|
|
|
HTM_TABLE_BeginWidePadding (2);
|
|
|
|
|
|
2021-06-01 23:19:59 +02:00
|
|
|
|
/***** Write heading *****/
|
|
|
|
|
Bld_PutHeadBuildings ();
|
|
|
|
|
|
2021-10-30 13:28:48 +02:00
|
|
|
|
/***** Write all buildings *****/
|
2021-06-01 23:19:59 +02:00
|
|
|
|
for (NumBld = 0;
|
|
|
|
|
NumBld < Buildings->Num;
|
|
|
|
|
NumBld++)
|
|
|
|
|
{
|
|
|
|
|
Building = &Buildings->Lst[NumBld];
|
|
|
|
|
|
|
|
|
|
/* Build anchor string */
|
|
|
|
|
Frm_SetAnchorStr (Building->BldCod,&Anchor);
|
|
|
|
|
|
|
|
|
|
HTM_TR_Begin (NULL);
|
|
|
|
|
|
|
|
|
|
/* Put icon to remove building */
|
|
|
|
|
HTM_TD_Begin ("class=\"BM\"");
|
|
|
|
|
Ico_PutContextualIconToRemove (ActRemBld,NULL,
|
|
|
|
|
Bld_PutParamBldCod,&Building->BldCod);
|
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
|
|
|
|
/* Building code */
|
2022-04-05 01:00:24 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"RM DAT_%s\"",The_GetSuffix ());
|
2021-06-01 23:19:59 +02:00
|
|
|
|
HTM_ARTICLE_Begin (Anchor);
|
|
|
|
|
HTM_Long (Building->BldCod);
|
|
|
|
|
HTM_ARTICLE_End ();
|
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
|
|
|
|
/* Building short name */
|
|
|
|
|
HTM_TD_Begin ("class=\"LM\"");
|
2021-06-29 15:25:42 +02:00
|
|
|
|
Frm_BeginFormAnchor (ActRenBldSho,Anchor);
|
2021-12-01 01:43:13 +01:00
|
|
|
|
Bld_PutParamBldCod (&Building->BldCod);
|
2021-06-01 23:19:59 +02:00
|
|
|
|
HTM_INPUT_TEXT ("ShortName",Bld_MAX_CHARS_SHRT_NAME,Building->ShrtName,
|
|
|
|
|
HTM_SUBMIT_ON_CHANGE,
|
2022-03-30 00:46:18 +02:00
|
|
|
|
"size=\"10\" class=\"INPUT_SHORT_NAME INPUT_%s\"",
|
2022-04-05 01:00:24 +02:00
|
|
|
|
The_GetSuffix ());
|
2021-06-01 23:19:59 +02:00
|
|
|
|
Frm_EndForm ();
|
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
|
|
|
|
/* Building full name */
|
|
|
|
|
HTM_TD_Begin ("class=\"LM\"");
|
2021-06-29 15:25:42 +02:00
|
|
|
|
Frm_BeginFormAnchor (ActRenBldFul,Anchor);
|
2021-12-01 01:43:13 +01:00
|
|
|
|
Bld_PutParamBldCod (&Building->BldCod);
|
2021-06-01 23:19:59 +02:00
|
|
|
|
HTM_INPUT_TEXT ("FullName",Bld_MAX_CHARS_FULL_NAME,Building->FullName,
|
|
|
|
|
HTM_SUBMIT_ON_CHANGE,
|
2022-03-30 00:46:18 +02:00
|
|
|
|
"size=\"20\" class=\"INPUT_FULL_NAME INPUT_%s\"",
|
2022-04-05 01:00:24 +02:00
|
|
|
|
The_GetSuffix ());
|
2021-06-01 23:19:59 +02:00
|
|
|
|
Frm_EndForm ();
|
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
|
|
|
|
/* Building location */
|
|
|
|
|
HTM_TD_Begin ("class=\"LM\"");
|
2021-06-29 15:25:42 +02:00
|
|
|
|
Frm_BeginFormAnchor (ActRenBldLoc,Anchor);
|
2021-12-01 01:43:13 +01:00
|
|
|
|
Bld_PutParamBldCod (&Building->BldCod);
|
2021-06-01 23:19:59 +02:00
|
|
|
|
HTM_INPUT_TEXT ("Location",Bld_MAX_CHARS_LOCATION,Building->Location,
|
|
|
|
|
HTM_SUBMIT_ON_CHANGE,
|
2022-03-30 00:46:18 +02:00
|
|
|
|
"size=\"15\" class=\"INPUT_FULL_NAME INPUT_%s\"",
|
2022-04-05 01:00:24 +02:00
|
|
|
|
The_GetSuffix ());
|
2021-06-01 23:19:59 +02:00
|
|
|
|
Frm_EndForm ();
|
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
|
|
|
|
HTM_TR_End ();
|
|
|
|
|
}
|
2020-04-22 03:19:27 +02:00
|
|
|
|
|
|
|
|
|
/***** End table *****/
|
|
|
|
|
HTM_TABLE_End ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************* Write parameter with code of building *******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-10-13 22:34:31 +02:00
|
|
|
|
static void Bld_PutParamBldCod (void *BldCod)
|
2020-04-22 03:19:27 +02:00
|
|
|
|
{
|
2020-10-13 22:34:31 +02:00
|
|
|
|
if (BldCod)
|
|
|
|
|
Par_PutHiddenParamLong (NULL,"BldCod",*((long *) BldCod));
|
2020-04-22 03:19:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************** Get parameter with code of building ********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
long Bld_GetParamBldCod (void)
|
|
|
|
|
{
|
|
|
|
|
/***** Get code of building *****/
|
|
|
|
|
return Par_GetParToLong ("BldCod");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/****************************** Remove a building ****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Bld_RemoveBuilding (void)
|
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_Building_X_removed;
|
|
|
|
|
|
|
|
|
|
/***** Building constructor *****/
|
|
|
|
|
Bld_EditingBuildingConstructor ();
|
|
|
|
|
|
|
|
|
|
/***** Get building code *****/
|
2021-04-25 13:24:39 +02:00
|
|
|
|
if ((Bld_EditingBuilding->BldCod = Bld_GetParamBldCod ()) <= 0)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_WrongBuildingExit ();
|
2020-04-22 03:19:27 +02:00
|
|
|
|
|
|
|
|
|
/***** Get data of the building from database *****/
|
|
|
|
|
Bld_GetDataOfBuildingByCod (Bld_EditingBuilding);
|
|
|
|
|
|
|
|
|
|
/***** Update rooms assigned to this building *****/
|
2021-06-01 23:19:59 +02:00
|
|
|
|
Roo_DB_RemoveBuildingFromRooms (Bld_EditingBuilding->BldCod);
|
2020-04-22 03:19:27 +02:00
|
|
|
|
|
|
|
|
|
/***** Remove building *****/
|
2021-06-01 23:19:59 +02:00
|
|
|
|
Bld_DB_RemoveBuilding (Bld_EditingBuilding->BldCod);
|
2020-04-22 03:19:27 +02:00
|
|
|
|
|
|
|
|
|
/***** Create message to show the change made *****/
|
|
|
|
|
Ale_CreateAlert (Ale_SUCCESS,NULL,
|
|
|
|
|
Txt_Building_X_removed,
|
|
|
|
|
Bld_EditingBuilding->FullName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************** Change the short name of a building ********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Bld_RenameBuildingShort (void)
|
|
|
|
|
{
|
|
|
|
|
/***** Building constructor *****/
|
|
|
|
|
Bld_EditingBuildingConstructor ();
|
|
|
|
|
|
|
|
|
|
/***** Rename building *****/
|
|
|
|
|
Bld_RenameBuilding (Cns_SHRT_NAME);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************** Change the full name of a building *********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Bld_RenameBuildingFull (void)
|
|
|
|
|
{
|
|
|
|
|
/***** Building constructor *****/
|
|
|
|
|
Bld_EditingBuildingConstructor ();
|
|
|
|
|
|
|
|
|
|
/***** Rename building *****/
|
|
|
|
|
Bld_RenameBuilding (Cns_FULL_NAME);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*********************** Change the name of a building ***********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void Bld_RenameBuilding (Cns_ShrtOrFullName_t ShrtOrFullName)
|
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_The_building_X_already_exists;
|
|
|
|
|
extern const char *Txt_The_building_X_has_been_renamed_as_Y;
|
2022-05-12 22:16:39 +02:00
|
|
|
|
extern const char *Txt_The_name_X_has_not_changed;
|
2020-04-22 03:19:27 +02:00
|
|
|
|
const char *ParamName = NULL; // Initialized to avoid warning
|
|
|
|
|
const char *FieldName = NULL; // Initialized to avoid warning
|
|
|
|
|
unsigned MaxBytes = 0; // Initialized to avoid warning
|
|
|
|
|
char *CurrentClaName = NULL; // Initialized to avoid warning
|
|
|
|
|
char NewClaName[Bld_MAX_BYTES_FULL_NAME + 1];
|
|
|
|
|
|
|
|
|
|
switch (ShrtOrFullName)
|
|
|
|
|
{
|
|
|
|
|
case Cns_SHRT_NAME:
|
|
|
|
|
ParamName = "ShortName";
|
|
|
|
|
FieldName = "ShortName";
|
|
|
|
|
MaxBytes = Bld_MAX_BYTES_SHRT_NAME;
|
|
|
|
|
CurrentClaName = Bld_EditingBuilding->ShrtName;
|
|
|
|
|
break;
|
|
|
|
|
case Cns_FULL_NAME:
|
|
|
|
|
ParamName = "FullName";
|
|
|
|
|
FieldName = "FullName";
|
|
|
|
|
MaxBytes = Bld_MAX_BYTES_FULL_NAME;
|
|
|
|
|
CurrentClaName = Bld_EditingBuilding->FullName;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***** Get parameters from form *****/
|
|
|
|
|
/* Get the code of the building */
|
2021-04-25 13:24:39 +02:00
|
|
|
|
if ((Bld_EditingBuilding->BldCod = Bld_GetParamBldCod ()) <= 0)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_WrongBuildingExit ();
|
2020-04-22 03:19:27 +02:00
|
|
|
|
|
|
|
|
|
/* Get the new name for the building */
|
|
|
|
|
Par_GetParToText (ParamName,NewClaName,MaxBytes);
|
|
|
|
|
|
|
|
|
|
/***** Get from the database the old names of the building *****/
|
|
|
|
|
Bld_GetDataOfBuildingByCod (Bld_EditingBuilding);
|
|
|
|
|
|
|
|
|
|
/***** Check if new name is empty *****/
|
|
|
|
|
if (NewClaName[0])
|
|
|
|
|
{
|
|
|
|
|
/***** Check if old and new names are the same
|
|
|
|
|
(this happens when return is pressed without changes) *****/
|
|
|
|
|
if (strcmp (CurrentClaName,NewClaName)) // Different names
|
|
|
|
|
{
|
|
|
|
|
/***** If building was in database... *****/
|
2021-06-01 23:19:59 +02:00
|
|
|
|
if (Bld_DB_CheckIfBuildingNameExists (ParamName,NewClaName,Bld_EditingBuilding->BldCod))
|
2020-04-22 03:19:27 +02:00
|
|
|
|
Ale_CreateAlert (Ale_WARNING,NULL,
|
|
|
|
|
Txt_The_building_X_already_exists,
|
|
|
|
|
NewClaName);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Update the table changing old name by new name */
|
2021-06-01 23:19:59 +02:00
|
|
|
|
Bld_DB_UpdateBuildingName (Bld_EditingBuilding->BldCod,FieldName,NewClaName);
|
2020-04-22 03:19:27 +02:00
|
|
|
|
|
|
|
|
|
/* Write message to show the change made */
|
|
|
|
|
Ale_CreateAlert (Ale_SUCCESS,NULL,
|
|
|
|
|
Txt_The_building_X_has_been_renamed_as_Y,
|
|
|
|
|
CurrentClaName,NewClaName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else // The same name
|
|
|
|
|
Ale_CreateAlert (Ale_INFO,NULL,
|
2022-05-12 22:16:39 +02:00
|
|
|
|
Txt_The_name_X_has_not_changed,CurrentClaName);
|
2020-04-22 03:19:27 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
Ale_CreateAlertYouCanNotLeaveFieldEmpty ();
|
|
|
|
|
|
|
|
|
|
/***** Update building name *****/
|
2021-02-15 16:25:55 +01:00
|
|
|
|
Str_Copy (CurrentClaName,NewClaName,MaxBytes);
|
2020-04-22 03:19:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************** Change the location of a building **********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Bld_ChangeBuildingLocation (void)
|
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_The_location_of_the_building_X_has_changed_to_Y;
|
|
|
|
|
extern const char *Txt_The_location_of_the_building_X_has_not_changed;
|
|
|
|
|
char NewLocation[Bld_MAX_BYTES_FULL_NAME + 1];
|
|
|
|
|
|
|
|
|
|
/***** Building constructor *****/
|
|
|
|
|
Bld_EditingBuildingConstructor ();
|
|
|
|
|
|
|
|
|
|
/***** Get parameters from form *****/
|
|
|
|
|
/* Get the code of the building */
|
2021-04-25 13:24:39 +02:00
|
|
|
|
if ((Bld_EditingBuilding->BldCod = Bld_GetParamBldCod ()) <= 0)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_WrongBuildingExit ();
|
2020-04-22 03:19:27 +02:00
|
|
|
|
|
|
|
|
|
/* Get the new location for the building */
|
|
|
|
|
Par_GetParToText ("Location",NewLocation,Bld_MAX_BYTES_LOCATION);
|
|
|
|
|
|
|
|
|
|
/***** Get from the database the old location of the building *****/
|
|
|
|
|
Bld_GetDataOfBuildingByCod (Bld_EditingBuilding);
|
|
|
|
|
|
|
|
|
|
/***** Check if old and new locations are the same
|
|
|
|
|
(this happens when return is pressed without changes) *****/
|
|
|
|
|
if (strcmp (Bld_EditingBuilding->Location,NewLocation)) // Different locations
|
|
|
|
|
{
|
|
|
|
|
/* Update the table changing old name by new name */
|
2021-06-01 23:19:59 +02:00
|
|
|
|
Bld_DB_UpdateBuildingName (Bld_EditingBuilding->BldCod,"Location",NewLocation);
|
2020-04-22 03:19:27 +02:00
|
|
|
|
Str_Copy (Bld_EditingBuilding->Location,NewLocation,
|
2021-02-15 16:25:55 +01:00
|
|
|
|
sizeof (Bld_EditingBuilding->Location) - 1);
|
2020-04-22 03:19:27 +02:00
|
|
|
|
|
|
|
|
|
/* Write message to show the change made */
|
|
|
|
|
Ale_CreateAlert (Ale_SUCCESS,NULL,
|
|
|
|
|
Txt_The_location_of_the_building_X_has_changed_to_Y,
|
|
|
|
|
Bld_EditingBuilding->FullName,NewLocation);
|
|
|
|
|
}
|
|
|
|
|
else // The same location
|
|
|
|
|
Ale_CreateAlert (Ale_INFO,NULL,
|
|
|
|
|
Txt_The_location_of_the_building_X_has_not_changed,
|
|
|
|
|
Bld_EditingBuilding->FullName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******* Show alerts after changing a building and continue editing **********/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Bld_ContEditAfterChgBuilding (void)
|
|
|
|
|
{
|
|
|
|
|
/***** Write message to show the change made *****/
|
|
|
|
|
Ale_ShowAlerts (NULL);
|
|
|
|
|
|
|
|
|
|
/***** Show the form again *****/
|
|
|
|
|
Bld_EditBuildingsInternal ();
|
|
|
|
|
|
|
|
|
|
/***** Building destructor *****/
|
|
|
|
|
Bld_EditingBuildingDestructor ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************** Put a form to create a new building ********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void Bld_PutFormToCreateBuilding (void)
|
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_New_building;
|
|
|
|
|
extern const char *Txt_Create_building;
|
|
|
|
|
|
|
|
|
|
/***** Begin form *****/
|
2021-03-02 00:54:26 +01:00
|
|
|
|
Frm_BeginForm (ActNewBld);
|
2020-04-22 03:19:27 +02:00
|
|
|
|
|
2021-06-01 23:19:59 +02:00
|
|
|
|
/***** Begin box and table *****/
|
|
|
|
|
Box_BoxTableBegin (NULL,Txt_New_building,
|
|
|
|
|
NULL,NULL,
|
|
|
|
|
NULL,Box_NOT_CLOSABLE,2);
|
2020-04-22 03:19:27 +02:00
|
|
|
|
|
2021-06-01 23:19:59 +02:00
|
|
|
|
/***** Write heading *****/
|
|
|
|
|
Bld_PutHeadBuildings ();
|
2020-04-22 03:19:27 +02:00
|
|
|
|
|
2021-06-01 23:19:59 +02:00
|
|
|
|
HTM_TR_Begin (NULL);
|
2020-04-22 03:19:27 +02:00
|
|
|
|
|
2021-06-01 23:19:59 +02:00
|
|
|
|
/***** Column to remove building, disabled here *****/
|
|
|
|
|
HTM_TD_Begin ("class=\"BM\"");
|
|
|
|
|
HTM_TD_End ();
|
2020-04-22 03:19:27 +02:00
|
|
|
|
|
2021-06-01 23:19:59 +02:00
|
|
|
|
/***** Building code *****/
|
|
|
|
|
HTM_TD_Begin ("class=\"CODE\"");
|
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
|
|
|
|
/***** Building short name *****/
|
|
|
|
|
HTM_TD_Begin ("class=\"LM\"");
|
|
|
|
|
HTM_INPUT_TEXT ("ShortName",Bld_MAX_CHARS_SHRT_NAME,Bld_EditingBuilding->ShrtName,
|
|
|
|
|
HTM_DONT_SUBMIT_ON_CHANGE,
|
2022-03-30 00:46:18 +02:00
|
|
|
|
"size=\"10\" class=\"INPUT_SHORT_NAME INPUT_%s\""
|
2021-12-20 09:24:49 +01:00
|
|
|
|
" required=\"required\"",
|
2022-04-05 01:00:24 +02:00
|
|
|
|
The_GetSuffix ());
|
2021-06-01 23:19:59 +02:00
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
|
|
|
|
/***** Building full name *****/
|
|
|
|
|
HTM_TD_Begin ("class=\"LM\"");
|
|
|
|
|
HTM_INPUT_TEXT ("FullName",Bld_MAX_CHARS_FULL_NAME,Bld_EditingBuilding->FullName,
|
|
|
|
|
HTM_DONT_SUBMIT_ON_CHANGE,
|
2022-03-30 00:46:18 +02:00
|
|
|
|
"size=\"20\" class=\"INPUT_FULL_NAME INPUT_%s\""
|
2021-12-20 09:24:49 +01:00
|
|
|
|
" required=\"required\"",
|
2022-04-05 01:00:24 +02:00
|
|
|
|
The_GetSuffix ());
|
2021-06-01 23:19:59 +02:00
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
|
|
|
|
/***** Building location *****/
|
|
|
|
|
HTM_TD_Begin ("class=\"LM\"");
|
|
|
|
|
HTM_INPUT_TEXT ("Location",Bld_MAX_CHARS_LOCATION,Bld_EditingBuilding->Location,
|
|
|
|
|
HTM_DONT_SUBMIT_ON_CHANGE,
|
2022-03-30 00:46:18 +02:00
|
|
|
|
"size=\"15\" class=\"INPUT_FULL_NAME INPUT_%s\"",
|
2022-04-05 01:00:24 +02:00
|
|
|
|
The_GetSuffix ());
|
2021-06-01 23:19:59 +02:00
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
|
|
|
|
HTM_TR_End ();
|
2020-04-22 03:19:27 +02:00
|
|
|
|
|
2021-06-01 23:19:59 +02:00
|
|
|
|
/***** End table, send button and end box *****/
|
|
|
|
|
Box_BoxTableWithButtonEnd (Btn_CREATE_BUTTON,Txt_Create_building);
|
2020-04-22 03:19:27 +02:00
|
|
|
|
|
|
|
|
|
/***** End form *****/
|
|
|
|
|
Frm_EndForm ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/****************** Write header with fields of a building *******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void Bld_PutHeadBuildings (void)
|
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_Code;
|
|
|
|
|
extern const char *Txt_Short_name;
|
|
|
|
|
extern const char *Txt_Full_name;
|
|
|
|
|
extern const char *Txt_Location;
|
|
|
|
|
|
|
|
|
|
HTM_TR_Begin (NULL);
|
|
|
|
|
|
2022-01-02 15:17:30 +01:00
|
|
|
|
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_Location ,HTM_HEAD_LEFT );
|
2020-04-22 03:19:27 +02:00
|
|
|
|
|
|
|
|
|
HTM_TR_End ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************** Receive form to create a new building *********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-05-05 21:49:00 +02:00
|
|
|
|
void Bld_ReceiveFormNewBuilding (void)
|
2020-04-22 03:19:27 +02:00
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_The_building_X_already_exists;
|
|
|
|
|
extern const char *Txt_Created_new_building_X;
|
|
|
|
|
|
|
|
|
|
/***** Building constructor *****/
|
|
|
|
|
Bld_EditingBuildingConstructor ();
|
|
|
|
|
|
|
|
|
|
/***** Get parameters from form *****/
|
|
|
|
|
/* Get building short name */
|
|
|
|
|
Par_GetParToText ("ShortName",Bld_EditingBuilding->ShrtName,Bld_MAX_BYTES_SHRT_NAME);
|
|
|
|
|
|
|
|
|
|
/* Get building full name */
|
|
|
|
|
Par_GetParToText ("FullName",Bld_EditingBuilding->FullName,Bld_MAX_BYTES_FULL_NAME);
|
|
|
|
|
|
|
|
|
|
/* Get building location */
|
|
|
|
|
Par_GetParToText ("Location",Bld_EditingBuilding->Location,Bld_MAX_BYTES_LOCATION);
|
|
|
|
|
|
|
|
|
|
if (Bld_EditingBuilding->ShrtName[0] &&
|
|
|
|
|
Bld_EditingBuilding->FullName[0]) // If there's a building name
|
|
|
|
|
{
|
|
|
|
|
/***** If name of building was in database... *****/
|
2021-06-01 23:19:59 +02:00
|
|
|
|
if (Bld_DB_CheckIfBuildingNameExists ("ShortName",Bld_EditingBuilding->ShrtName,-1L))
|
2020-04-22 03:19:27 +02:00
|
|
|
|
Ale_CreateAlert (Ale_WARNING,NULL,
|
|
|
|
|
Txt_The_building_X_already_exists,
|
|
|
|
|
Bld_EditingBuilding->ShrtName);
|
2021-06-01 23:19:59 +02:00
|
|
|
|
else if (Bld_DB_CheckIfBuildingNameExists ("FullName",Bld_EditingBuilding->FullName,-1L))
|
2020-04-22 03:19:27 +02:00
|
|
|
|
Ale_CreateAlert (Ale_WARNING,NULL,
|
|
|
|
|
Txt_The_building_X_already_exists,
|
|
|
|
|
Bld_EditingBuilding->FullName);
|
|
|
|
|
else // Add new building to database
|
|
|
|
|
{
|
2021-06-01 23:19:59 +02:00
|
|
|
|
Bld_DB_CreateBuilding (Bld_EditingBuilding);
|
2020-04-22 03:19:27 +02:00
|
|
|
|
Ale_CreateAlert (Ale_SUCCESS,NULL,
|
|
|
|
|
Txt_Created_new_building_X,
|
|
|
|
|
Bld_EditingBuilding->FullName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else // If there is not a building name
|
2022-06-18 19:50:40 +02:00
|
|
|
|
Ale_ShowAlertYouMustSpecifyTheShortNameAndTheFullName ();
|
2020-04-22 03:19:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************ Building constructor/destructor ********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void Bld_EditingBuildingConstructor (void)
|
|
|
|
|
{
|
|
|
|
|
/***** Pointer must be NULL *****/
|
|
|
|
|
if (Bld_EditingBuilding != NULL)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_WrongBuildingExit ();
|
2020-04-22 03:19:27 +02:00
|
|
|
|
|
|
|
|
|
/***** Allocate memory for building *****/
|
2021-02-15 16:25:55 +01:00
|
|
|
|
if ((Bld_EditingBuilding = malloc (sizeof (*Bld_EditingBuilding))) == NULL)
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_NotEnoughMemoryExit ();
|
2020-04-22 03:19:27 +02:00
|
|
|
|
|
|
|
|
|
/***** Reset building *****/
|
|
|
|
|
Bld_EditingBuilding->BldCod = -1L;
|
|
|
|
|
Bld_EditingBuilding->InsCod = -1L;
|
|
|
|
|
Bld_EditingBuilding->ShrtName[0] = '\0';
|
|
|
|
|
Bld_EditingBuilding->FullName[0] = '\0';
|
|
|
|
|
Bld_EditingBuilding->Location[0] = '\0';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void Bld_EditingBuildingDestructor (void)
|
|
|
|
|
{
|
|
|
|
|
/***** Free memory used for building *****/
|
|
|
|
|
if (Bld_EditingBuilding != NULL)
|
|
|
|
|
{
|
|
|
|
|
free (Bld_EditingBuilding);
|
|
|
|
|
Bld_EditingBuilding = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|