swad-core/swad_room.c

1437 lines
49 KiB
C
Raw Normal View History

// swad_room.c: classrooms, laboratories, offices or other rooms in a center
2020-04-14 17:15:17 +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.
Copyright (C) 1999-2023 Antonio Ca<EFBFBD>as Vargas
2020-04-14 17:15:17 +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_action_list.h"
#include "swad_alert.h"
2020-04-14 17:15:17 +02:00
#include "swad_box.h"
2020-04-15 02:17:57 +02:00
#include "swad_building.h"
2020-04-14 17:15:17 +02:00
#include "swad_database.h"
#include "swad_error.h"
2020-04-14 17:15:17 +02:00
#include "swad_form.h"
#include "swad_global.h"
#include "swad_group_database.h"
2020-04-14 17:15:17 +02:00
#include "swad_HTML.h"
2020-09-02 00:13:32 +02:00
#include "swad_MAC.h"
#include "swad_parameter_code.h"
2020-04-14 17:15:17 +02:00
#include "swad_room.h"
#include "swad_room_database.h"
2020-04-14 17:15:17 +02:00
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
2020-04-19 02:39:20 +02:00
static const char *Roo_TypesIcons[Roo_NUM_TYPES] =
{
[Roo_NO_TYPE ] = "question.svg",
[Roo_ADMINISTRATION] = "user-tie.svg",
[Roo_AUDITORIUM ] = "landmark.svg",
[Roo_CAFETERIA ] = "coffee.svg",
[Roo_CANTEEN ] = "utensils.svg",
[Roo_CLASSROOM ] = "chalkboard-teacher.svg",
2020-04-19 19:55:41 +02:00
[Roo_CONCIERGE ] = "concierge-bell.svg",
2020-04-19 02:39:20 +02:00
[Roo_CORRIDOR ] = "walking.svg",
[Roo_GYM ] = "dumbbell.svg",
[Roo_HALL ] = "map-signs.svg",
[Roo_KINDERGARTEN ] = "child.svg",
[Roo_LABORATORY ] = "flask.svg",
[Roo_LIBRARY ] = "book.svg",
2020-04-19 19:55:41 +02:00
[Roo_OFFICE ] = "door-closed.svg",
2020-04-19 02:39:20 +02:00
[Roo_OUTDOORS ] = "cloud-sun.svg",
[Roo_PARKING ] = "car.svg",
[Roo_PAVILION ] = "volleyball-ball.svg",
2020-04-19 19:55:41 +02:00
[Roo_ROOM ] = "door-open.svg",
2020-04-19 02:39:20 +02:00
[Roo_SECRETARIAT ] = "stamp.svg",
2020-04-19 19:55:41 +02:00
[Roo_SEMINAR ] = "chalkboard.svg",
2020-04-19 02:39:20 +02:00
[Roo_SHOP ] = "shopping-cart.svg",
2020-04-19 19:55:41 +02:00
[Roo_STORE ] = "dolly.svg",
2020-04-19 02:39:20 +02:00
[Roo_TOILETS ] = "toilet.svg",
[Roo_VIRTUAL ] = "laptop-house.svg",
2020-04-19 19:55:41 +02:00
[Roo_YARD ] = "tree.svg",
2020-04-19 02:39:20 +02:00
};
2020-04-14 17:15:17 +02:00
/*****************************************************************************/
/***************************** Private variables *****************************/
/*****************************************************************************/
static struct Roo_Room *Roo_EditingRoom = NULL; // Static variable to keep the room being edited
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
2020-09-01 21:41:34 +02:00
static void Roo_GetAndListMACAddresses (long RooCod);
static void Roo_GetAndEditMACAddresses (long RooCod,const char *Anchor);
2020-09-01 12:49:11 +02:00
static Roo_Order_t Roo_GetParRoomOrder (void);
2020-04-14 17:15:17 +02:00
static bool Roo_CheckIfICanCreateRooms (void);
static void Roo_PutIconsListingRooms (__attribute__((unused)) void *Args);
static void Roo_PutIconToEditRooms (void);
static void Roo_PutIconsEditingRooms (__attribute__((unused)) void *Args);
static void Roo_GetRoomDataByCod (struct Roo_Room *Room);
static void Roo_GetRoomDataFromRow (MYSQL_RES *mysql_res,
struct Roo_Room *Room,
Roo_WhichData_t WhichData);
2020-04-15 14:33:31 +02:00
static void Roo_GetBldShrtName (struct Roo_Room *Room,const char *BldShrtNameFromDB);
2020-04-19 02:39:20 +02:00
static Roo_RoomType_t Roo_GetTypeFromString (const char *Str);
2020-04-15 14:33:31 +02:00
2020-04-14 17:15:17 +02:00
static void Roo_EditRoomsInternal (void);
2020-04-15 02:17:57 +02:00
static void Roo_ListRoomsForEdition (const struct Bld_Buildings *Buildings,
const struct Roo_Rooms *Rooms);
static void Roo_PutParRooCod (void *RooCod);
2020-04-15 02:17:57 +02:00
static void Roo_PutSelectorBuilding (long BldCod,
2020-04-15 14:33:31 +02:00
const struct Bld_Buildings *Buildings,
2020-04-27 03:16:55 +02:00
HTM_SubmitOnChange_t SubmitOnChange);
2020-04-19 02:39:20 +02:00
static void Roo_PutSelectorType (Roo_RoomType_t RoomType,
2020-04-27 03:16:55 +02:00
HTM_SubmitOnChange_t SubmitOnChange);
static int Roo_GetParFloor (void);
static Roo_RoomType_t Roo_GetParType (void);
2020-04-14 17:15:17 +02:00
static void Roo_RenameRoom (Cns_ShrtOrFullName_t ShrtOrFullName);
static void Roo_WriteCapacity (char Str[Cns_MAX_DECIMAL_DIGITS_UINT + 1],unsigned Capacity);
2020-04-15 02:17:57 +02:00
static void Roo_PutFormToCreateRoom (const struct Bld_Buildings *Buildings);
2020-04-14 17:15:17 +02:00
static void Roo_PutHeadRooms (void);
2020-04-19 02:39:20 +02:00
static void Roo_CreateRoom (struct Roo_Room *Room);
2020-04-14 17:15:17 +02:00
static void Roo_EditingRoomConstructor (void);
static void Roo_EditingRoomDestructor (void);
/*****************************************************************************/
/**************************** Reset rooms context ****************************/
/*****************************************************************************/
void Roo_ResetRooms (struct Roo_Rooms *Rooms)
{
Rooms->Num = 0; // Number of rooms
Rooms->Lst = NULL; // List of rooms
Rooms->SelectedOrder = Roo_ORDER_DEFAULT;
}
/*****************************************************************************/
/****************************** List all rooms *******************************/
2020-04-14 17:15:17 +02:00
/*****************************************************************************/
void Roo_SeeRooms (void)
{
extern const char *Hlp_CENTER_Rooms;
2020-04-14 17:15:17 +02:00
extern const char *Txt_Rooms;
extern const char *Txt_ROOMS_HELP_ORDER[Roo_NUM_ORDERS];
extern const char *Txt_ROOMS_ORDER[Roo_NUM_ORDERS];
2020-09-01 12:49:11 +02:00
extern const char *Txt_MAC_address;
2020-04-19 02:39:20 +02:00
extern const char *Txt_ROOM_TYPES[Roo_NUM_TYPES];
2020-04-14 17:15:17 +02:00
struct Roo_Rooms Rooms;
Roo_Order_t Order;
unsigned NumRoom;
char StrCapacity[Cns_MAX_DECIMAL_DIGITS_UINT + 1];
/***** Trivial check *****/
if (Gbl.Hierarchy.Ctr.CtrCod <= 0) // No center selected
2020-04-14 17:15:17 +02:00
return;
/***** Reset rooms context *****/
Roo_ResetRooms (&Rooms);
/***** Get parameter with the type of order in the list of rooms *****/
Rooms.SelectedOrder = Roo_GetParRoomOrder ();
2020-04-14 17:15:17 +02:00
/***** Get list of rooms *****/
Roo_GetListRooms (&Rooms,Roo_ALL_DATA);
/***** Table head *****/
Box_BoxBegin (NULL,Txt_Rooms,
Roo_PutIconsListingRooms,NULL,
Hlp_CENTER_Rooms,Box_NOT_CLOSABLE);
HTM_TABLE_BeginWideMarginPadding (2);
HTM_TR_Begin (NULL);
2020-09-01 12:49:11 +02:00
/* Columns visible by all */
for (Order = (Roo_Order_t) 0;
Order <= (Roo_Order_t) (Roo_NUM_ORDERS - 1);
Order++)
{
HTM_TH_Begin (HTM_HEAD_LEFT);
Frm_BeginForm (ActSeeRoo);
Par_PutParUnsigned (NULL,"Order",(unsigned) Order);
HTM_BUTTON_Submit_Begin (Txt_ROOMS_HELP_ORDER[Order],
"class=\"BT_LINK\"");
if (Order == Rooms.SelectedOrder)
HTM_U_Begin ();
HTM_Txt (Txt_ROOMS_ORDER[Order]);
if (Order == Rooms.SelectedOrder)
HTM_U_End ();
HTM_BUTTON_End ();
Frm_EndForm ();
HTM_TH_End ();
}
/* Column visible by admins */
switch (Gbl.Usrs.Me.Role.Logged)
{
case Rol_CTR_ADM:
case Rol_INS_ADM:
case Rol_SYS_ADM:
HTM_TH (Txt_MAC_address,HTM_HEAD_LEFT);
break;
default:
break;
}
2020-09-01 12:49:11 +02:00
HTM_TR_End ();
2020-04-14 17:15:17 +02:00
/***** Write list of rooms *****/
for (NumRoom = 0, The_ResetRowColor ();
NumRoom < Rooms.Num;
NumRoom++, The_ChangeRowColor ())
{
HTM_TR_Begin (NULL);
/* Building short name */
HTM_TD_Begin ("class=\"LT DAT_%s %s\"",
The_GetSuffix (),
The_GetColorRows ());
HTM_Txt (Rooms.Lst[NumRoom].BldShrtName);
HTM_TD_End ();
/* Floor */
HTM_TD_Begin ("class=\"RT DAT_%s %s\"",
The_GetSuffix (),
The_GetColorRows ());
HTM_Int (Rooms.Lst[NumRoom].Floor);
HTM_TD_End ();
/* Type */
HTM_TD_Begin ("class=\"LT DAT_%s %s\"",
The_GetSuffix (),
The_GetColorRows ());
Ico_PutIconOn (Roo_TypesIcons[Rooms.Lst[NumRoom].Type],Ico_BLACK,
Txt_ROOM_TYPES[Rooms.Lst[NumRoom].Type]);
HTM_TD_End ();
/* Short name */
HTM_TD_Begin ("class=\"LT DAT_%s %s\"",
The_GetSuffix (),
The_GetColorRows ());
HTM_Txt (Rooms.Lst[NumRoom].ShrtName);
HTM_TD_End ();
/* Full name */
HTM_TD_Begin ("class=\"LT DAT_%s %s\"",
The_GetSuffix (),
The_GetColorRows ());
HTM_Txt (Rooms.Lst[NumRoom].FullName);
HTM_TD_End ();
/* Capacity */
HTM_TD_Begin ("class=\"RT DAT_%s %s\"",
The_GetSuffix (),
The_GetColorRows ());
Roo_WriteCapacity (StrCapacity,Rooms.Lst[NumRoom].Capacity);
HTM_Txt (StrCapacity);
HTM_TD_End ();
/* Column visible by admins */
switch (Gbl.Usrs.Me.Role.Logged)
{
case Rol_CTR_ADM:
case Rol_INS_ADM:
case Rol_SYS_ADM:
HTM_TD_Begin ("class=\"LT DAT_%s %s\"",
The_GetSuffix (),
The_GetColorRows ());
Roo_GetAndListMACAddresses (Rooms.Lst[NumRoom].RooCod);
HTM_TD_End ();
break;
default:
break;
}
HTM_TR_End ();
}
/***** End table *****/
HTM_TABLE_End ();
2020-04-14 17:15:17 +02:00
/***** End box *****/
Box_BoxEnd ();
/***** Free list of rooms *****/
Roo_FreeListRooms (&Rooms);
}
2020-09-01 12:49:11 +02:00
/*****************************************************************************/
2020-09-01 21:41:34 +02:00
/************ Get and list the MAC addresses associated to a room ************/
2020-09-01 12:49:11 +02:00
/*****************************************************************************/
2020-09-01 21:41:34 +02:00
static void Roo_GetAndListMACAddresses (long RooCod)
2020-09-01 12:49:11 +02:00
{
MYSQL_RES *mysql_res;
unsigned NumMACs;
/***** Get MAC addresses from database *****/
NumMACs = Roo_DB_GetMACAddresses (&mysql_res,RooCod);
2020-09-01 21:41:34 +02:00
/***** Write the MAC addresses *****/
2020-09-02 00:13:32 +02:00
MAC_ListMACAddresses (NumMACs,&mysql_res);
2020-09-01 12:49:11 +02:00
}
2020-09-01 21:41:34 +02:00
/*****************************************************************************/
/****** Get and list for edition the MAC addresses associated to a room ******/
/*****************************************************************************/
static void Roo_GetAndEditMACAddresses (long RooCod,const char *Anchor)
{
MYSQL_RES *mysql_res;
unsigned NumMACs;
/***** Get MAC addresses from database *****/
NumMACs = Roo_DB_GetMACAddresses (&mysql_res,RooCod);
2020-09-01 21:41:34 +02:00
/***** Write the MAC addresses *****/
2020-09-02 00:13:32 +02:00
MAC_EditMACAddresses (RooCod,Anchor,NumMACs,&mysql_res);
2020-09-01 21:41:34 +02:00
}
/*****************************************************************************/
/**************************** Change MAC of a room ***************************/
/*****************************************************************************/
void Roo_ChangeMAC (void)
{
2020-09-02 12:20:21 +02:00
unsigned long long OldMACnum;
unsigned long long NewMACnum;
2020-09-01 21:41:34 +02:00
/***** Room constructor *****/
Roo_EditingRoomConstructor ();
/***** Get parameters from form *****/
/* Get room code */
Roo_EditingRoom->RooCod = ParCod_GetAndCheckPar (ParCod_Roo);
2020-09-01 21:41:34 +02:00
/* Get the old MAC address of the room */
2020-09-02 12:20:21 +02:00
OldMACnum = MAC_GetMACnumFromForm ("MAC");
2020-09-01 21:41:34 +02:00
/* Get the new MAC address of the room */
2020-09-02 12:20:21 +02:00
NewMACnum = MAC_GetMACnumFromForm ("NewMAC");
2020-09-01 21:41:34 +02:00
/***** Get data of the room from database *****/
Roo_GetRoomDataByCod (Roo_EditingRoom);
2020-09-01 21:41:34 +02:00
/***** Check if the new MAC is different from the old MAC *****/
2020-09-02 12:20:21 +02:00
if (OldMACnum)
Roo_DB_RemoveMACAddress (Roo_EditingRoom->RooCod,OldMACnum);
2020-09-02 12:20:21 +02:00
if (NewMACnum)
2020-09-01 21:41:34 +02:00
/***** Update the table of rooms-MACs changing the old MAC for the new one *****/
Roo_DB_UpdateMACAddress (Roo_EditingRoom->RooCod,NewMACnum);
2020-09-01 21:41:34 +02:00
2020-09-02 12:20:21 +02:00
Roo_EditingRoom->MACnum = NewMACnum;
2020-09-01 21:41:34 +02:00
}
2020-04-14 17:15:17 +02:00
/*****************************************************************************/
/*********** Get parameter with the type or order in list of rooms ***********/
/*****************************************************************************/
static Roo_Order_t Roo_GetParRoomOrder (void)
2020-04-14 17:15:17 +02:00
{
return (Roo_Order_t) Par_GetParUnsignedLong ("Order",
2020-04-14 17:15:17 +02:00
0,
Roo_NUM_ORDERS - 1,
(unsigned long) Roo_ORDER_DEFAULT);
}
/*****************************************************************************/
/*********************** Check if I can create rooms *************************/
/*****************************************************************************/
static bool Roo_CheckIfICanCreateRooms (void)
{
return Gbl.Usrs.Me.Role.Logged >= Rol_CTR_ADM;
2020-04-14 17:15:17 +02:00
}
/*****************************************************************************/
/****************** Put contextual icons in list of rooms ********************/
/*****************************************************************************/
static void Roo_PutIconsListingRooms (__attribute__((unused)) void *Args)
{
/***** Put icon to edit rooms *****/
if (Roo_CheckIfICanCreateRooms ())
Roo_PutIconToEditRooms ();
}
/*****************************************************************************/
/********************** Put a link (form) to edit rooms **********************/
/*****************************************************************************/
static void Roo_PutIconToEditRooms (void)
{
Ico_PutContextualIconToEdit (ActEdiRoo,NULL,
NULL,NULL);
}
/*****************************************************************************/
/*************************** Put forms to edit rooms *************************/
/*****************************************************************************/
void Roo_EditRooms (void)
{
/***** Room constructor *****/
Roo_EditingRoomConstructor ();
/***** Edit rooms *****/
Roo_EditRoomsInternal ();
/***** Room destructor *****/
Roo_EditingRoomDestructor ();
}
static void Roo_EditRoomsInternal (void)
{
extern const char *Hlp_CENTER_Rooms_edit;
2020-04-14 17:15:17 +02:00
extern const char *Txt_Rooms;
2020-04-15 02:17:57 +02:00
struct Bld_Buildings Buildings;
2020-04-14 17:15:17 +02:00
struct Roo_Rooms Rooms;
2020-04-15 02:17:57 +02:00
/***** Reset context *****/
Bld_ResetBuildings (&Buildings);
2020-04-14 17:15:17 +02:00
Roo_ResetRooms (&Rooms);
2020-04-15 02:17:57 +02:00
/***** Get lists of buildings and rooms *****/
Bld_GetListBuildings (&Buildings,Bld_ALL_DATA);
2020-04-14 17:15:17 +02:00
Roo_GetListRooms (&Rooms,Roo_ALL_DATA);
/***** Begin box *****/
Box_BoxBegin (NULL,Txt_Rooms,
Roo_PutIconsEditingRooms,NULL,
Hlp_CENTER_Rooms_edit,Box_NOT_CLOSABLE);
2020-04-14 17:15:17 +02:00
/***** Put a form to create a new room *****/
Roo_PutFormToCreateRoom (&Buildings);
2020-04-14 17:15:17 +02:00
/***** Forms to edit current rooms *****/
if (Rooms.Num)
Roo_ListRoomsForEdition (&Buildings,&Rooms);
2020-04-14 17:15:17 +02:00
/***** End box *****/
Box_BoxEnd ();
2020-04-15 02:17:57 +02:00
/***** Free lists of rooms and buildings *****/
2020-04-14 17:15:17 +02:00
Roo_FreeListRooms (&Rooms);
2020-04-15 02:17:57 +02:00
Bld_FreeListBuildings (&Buildings);
2020-04-14 17:15:17 +02:00
}
/*****************************************************************************/
/***************** Put contextual icons in edition of rooms ******************/
/*****************************************************************************/
static void Roo_PutIconsEditingRooms (__attribute__((unused)) void *Args)
{
/***** Put icon to view rooms *****/
Ico_PutContextualIconToView (ActSeeRoo,NULL,
NULL,NULL);
2020-04-14 17:15:17 +02:00
}
/*****************************************************************************/
/****************************** List all rooms *******************************/
2020-04-14 17:15:17 +02:00
/*****************************************************************************/
void Roo_GetListRooms (struct Roo_Rooms *Rooms,Roo_WhichData_t WhichData)
2020-04-14 17:15:17 +02:00
{
MYSQL_RES *mysql_res;
unsigned NumRoom;
/***** Get rooms from database *****/
if ((Rooms->Num = Roo_DB_GetListRooms (&mysql_res,Gbl.Hierarchy.Ctr.CtrCod,
WhichData,Rooms->SelectedOrder))) // Rooms found...
2020-04-14 17:15:17 +02:00
{
/***** Create list with courses in center *****/
if ((Rooms->Lst = calloc ((size_t) Rooms->Num,
sizeof (*Rooms->Lst))) == NULL)
Err_NotEnoughMemoryExit ();
2020-04-14 17:15:17 +02:00
/***** Get the rooms *****/
for (NumRoom = 0;
NumRoom < Rooms->Num;
NumRoom++)
Roo_GetRoomDataFromRow (mysql_res,&Rooms->Lst[NumRoom],WhichData);
2020-04-14 17:15:17 +02:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
2020-04-15 14:33:31 +02:00
/************* Get room data from database using the room code ***************/
2020-04-14 17:15:17 +02:00
/*****************************************************************************/
static void Roo_GetRoomDataByCod (struct Roo_Room *Room)
2020-04-14 17:15:17 +02:00
{
MYSQL_RES *mysql_res;
2020-04-15 14:33:31 +02:00
/***** Trivial check *****/
if (Room->RooCod <= 0)
return;
/***** Get data of a room from database *****/
if (Roo_DB_GetRoomDataByCod (&mysql_res,Room->RooCod)) // Room found...
Roo_GetRoomDataFromRow (mysql_res,Room,Roo_ALL_DATA);
2020-04-14 17:15:17 +02:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
2020-04-15 02:17:57 +02:00
/*****************************************************************************/
/********************* Get room data from database row ***********************/
/*****************************************************************************/
2020-04-15 02:17:57 +02:00
static void Roo_GetRoomDataFromRow (MYSQL_RES *mysql_res,
struct Roo_Room *Room,
Roo_WhichData_t WhichData)
{
MYSQL_ROW row;
2020-04-14 17:15:17 +02:00
/***** Get row *****/
row = mysql_fetch_row (mysql_res);
2020-04-19 02:39:20 +02:00
/***** Get room code (row[0]) *****/
if ((Room->RooCod = Str_ConvertStrCodToLongCod (row[0])) <= 0)
Err_WrongRoomExit ();
2020-04-14 17:15:17 +02:00
switch (WhichData)
{
case Roo_ALL_DATA:
/***** Get building code (row[1]) *****/
Room->BldCod = Str_ConvertStrCodToLongCod (row[1]);
/***** Get the short name of the building (row[2]) *****/
Roo_GetBldShrtName (Room,row[2]);
/***** Get floor (row[3]) *****/
Room->Floor = Str_ConvertStrCodToLongCod (row[3]);
/***** Get type (row[4]) *****/
Room->Type = Roo_GetTypeFromString (row[4]);
/***** Get the short (row[5]) and full (row[6]) names of the room *****/
Str_Copy (Room->ShrtName,row[5],sizeof (Room->ShrtName) - 1);
Str_Copy (Room->FullName,row[6],sizeof (Room->FullName) - 1);
/***** Get seating capacity in this room (row[7]) *****/
if (sscanf (row[7],"%u",&Room->Capacity) != 1)
Room->Capacity = Roo_UNLIMITED_CAPACITY;
break;
case Roo_ONLY_SHRT_NAME:
default:
/***** Get the short name of the room (row[1]) *****/
Str_Copy (Room->ShrtName,row[1],sizeof (Room->ShrtName) - 1);
break;
2020-04-15 14:33:31 +02:00
}
}
/*****************************************************************************/
/****************** Get building short name from database ********************/
/*****************************************************************************/
static void Roo_GetBldShrtName (struct Roo_Room *Room,const char *BldShrtNameFromDB)
{
extern const char *Txt_No_assigned_building;
extern const char *Txt_Another_building;
2020-04-14 17:15:17 +02:00
2020-04-15 14:33:31 +02:00
if (Room->BldCod < 0)
Str_Copy (Room->BldShrtName,Txt_No_assigned_building,
sizeof (Room->BldShrtName) - 1);
2020-04-15 14:33:31 +02:00
else if (Room->BldCod == 0)
Str_Copy (Room->BldShrtName,Txt_Another_building,
sizeof (Room->BldShrtName) - 1);
2020-04-15 14:33:31 +02:00
else // Room->BldCod > 0
{
Room->BldShrtName[0] = '\0';
if (BldShrtNameFromDB)
Str_Copy (Room->BldShrtName,BldShrtNameFromDB,
sizeof (Room->BldShrtName) - 1);
2020-04-14 17:15:17 +02:00
}
}
2020-04-19 02:39:20 +02:00
/*****************************************************************************/
/********************** Convert from string to type **************************/
/*****************************************************************************/
static Roo_RoomType_t Roo_GetTypeFromString (const char *Str)
{
extern const char *Roo_TypesDB[Roo_NUM_TYPES];
2020-04-19 02:39:20 +02:00
Roo_RoomType_t Type;
/***** Compare string with all string types *****/
for (Type = (Roo_RoomType_t) 0;
Type <= (Roo_RoomType_t) (Roo_NUM_TYPES - 1);
Type++)
if (!strcmp (Roo_TypesDB[Type],Str))
return Type;
return Roo_NO_TYPE;
}
2020-04-14 17:15:17 +02:00
/*****************************************************************************/
/**************************** Free list of rooms *****************************/
/*****************************************************************************/
void Roo_FreeListRooms (struct Roo_Rooms *Rooms)
{
if (Rooms->Lst)
{
/***** Free memory used by the list of rooms in institution *****/
free (Rooms->Lst);
Rooms->Lst = NULL;
Rooms->Num = 0;
}
}
/*****************************************************************************/
/***************************** List all rooms ********************************/
2020-04-14 17:15:17 +02:00
/*****************************************************************************/
2020-04-15 02:17:57 +02:00
static void Roo_ListRoomsForEdition (const struct Bld_Buildings *Buildings,
const struct Roo_Rooms *Rooms)
2020-04-14 17:15:17 +02:00
{
2020-04-14 22:45:10 +02:00
unsigned NumRoom;
2020-04-14 17:15:17 +02:00
struct Roo_Room *Room;
2020-04-19 20:42:18 +02:00
char *Anchor = NULL;
2020-04-14 17:15:17 +02:00
char StrCapacity[Cns_MAX_DECIMAL_DIGITS_UINT + 1];
HTM_TABLE_BeginWidePadding (2);
/***** Write heading *****/
Roo_PutHeadRooms ();
/***** Write all rooms *****/
for (NumRoom = 0;
NumRoom < Rooms->Num;
NumRoom++)
{
Room = &Rooms->Lst[NumRoom];
/* Build anchor string */
Frm_SetAnchorStr (Room->RooCod,&Anchor);
HTM_TR_Begin (NULL);
/* Put icon to remove room */
HTM_TD_Begin ("class=\"BT\"");
Ico_PutContextualIconToRemove (ActRemRoo,NULL,
Roo_PutParRooCod,&Room->RooCod);
HTM_TD_End ();
/* Room code */
HTM_TD_Begin ("class=\"CODE DAT_%s\"",The_GetSuffix ());
HTM_ARTICLE_Begin (Anchor);
HTM_Long (Room->RooCod);
HTM_ARTICLE_End ();
HTM_TD_End ();
/* Building */
HTM_TD_Begin ("class=\"CT\"");
Frm_BeginFormAnchor (ActChgRooBld,Anchor);
ParCod_PutPar (ParCod_Roo,Room->RooCod);
Roo_PutSelectorBuilding (Room->BldCod,Buildings,
HTM_SUBMIT_ON_CHANGE);
Frm_EndForm ();
HTM_TD_End ();
/* Floor */
HTM_TD_Begin ("class=\"LT\"");
Frm_BeginFormAnchor (ActChgRooFlo,Anchor);
ParCod_PutPar (ParCod_Roo,Room->RooCod);
HTM_INPUT_LONG ("Floor",(long) INT_MIN,(long) INT_MAX,(long) Room->Floor,
HTM_SUBMIT_ON_CHANGE,false,
"class=\"INPUT_LONG INPUT_%s\"",
The_GetSuffix ());
Frm_EndForm ();
HTM_TD_End ();
/* Room type */
HTM_TD_Begin ("class=\"CT\"");
Frm_BeginFormAnchor (ActChgRooTyp,Anchor);
ParCod_PutPar (ParCod_Roo,Room->RooCod);
Roo_PutSelectorType (Room->Type,
HTM_SUBMIT_ON_CHANGE);
Frm_EndForm ();
HTM_TD_End ();
/* Room short name */
HTM_TD_Begin ("class=\"LT\"");
Frm_BeginFormAnchor (ActRenRooSho,Anchor);
ParCod_PutPar (ParCod_Roo,Room->RooCod);
HTM_INPUT_TEXT ("ShortName",Roo_MAX_CHARS_SHRT_NAME,Room->ShrtName,
HTM_SUBMIT_ON_CHANGE,
"size=\"10\""
" class=\"INPUT_SHORT_NAME INPUT_%s\"",
The_GetSuffix ());
Frm_EndForm ();
HTM_TD_End ();
/* Room full name */
HTM_TD_Begin ("class=\"LT\"");
Frm_BeginFormAnchor (ActRenRooFul,Anchor);
ParCod_PutPar (ParCod_Roo,Room->RooCod);
HTM_INPUT_TEXT ("FullName",Roo_MAX_CHARS_FULL_NAME,Room->FullName,
HTM_SUBMIT_ON_CHANGE,
"size=\"20\""
" class=\"INPUT_FULL_NAME INPUT_%s\"",
The_GetSuffix ());
Frm_EndForm ();
HTM_TD_End ();
/* Seating capacity */
HTM_TD_Begin ("class=\"LT\"");
Frm_BeginFormAnchor (ActChgRooMaxUsr,Anchor);
ParCod_PutPar (ParCod_Roo,Room->RooCod);
Roo_WriteCapacity (StrCapacity,Room->Capacity);
HTM_INPUT_TEXT ("Capacity",Cns_MAX_DECIMAL_DIGITS_UINT,StrCapacity,
HTM_SUBMIT_ON_CHANGE,
"size=\"3\" class=\"INPUT_%s\"",
The_GetSuffix ());
Frm_EndForm ();
HTM_TD_End ();
/* MAC addresses */
HTM_TD_Begin ("class=\"LT\"");
Roo_GetAndEditMACAddresses (Room->RooCod,Anchor);
HTM_TD_End ();
HTM_TR_End ();
}
2020-04-14 17:15:17 +02:00
/***** End table *****/
HTM_TABLE_End ();
}
/*****************************************************************************/
/********************* Write parameter with code of room *********************/
/*****************************************************************************/
static void Roo_PutParRooCod (void *RooCod)
{
if (RooCod)
ParCod_PutPar (ParCod_Roo,*((long *) RooCod));
}
2020-04-15 02:17:57 +02:00
/*****************************************************************************/
2020-04-19 02:39:20 +02:00
/********** Put selector of the building to which the room belongs ***********/
2020-04-15 02:17:57 +02:00
/*****************************************************************************/
static void Roo_PutSelectorBuilding (long BldCod,
2020-04-15 14:33:31 +02:00
const struct Bld_Buildings *Buildings,
2020-04-27 03:16:55 +02:00
HTM_SubmitOnChange_t SubmitOnChange)
2020-04-15 02:17:57 +02:00
{
2020-04-15 02:17:57 +02:00