-
Notifications
You must be signed in to change notification settings - Fork 17
/
swad_building.c
782 lines (629 loc) · 26.9 KB
/
swad_building.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
// swad_building.c: buildings in a center
/*
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-2024 Antonio Cañas Vargas
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <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"
#include "swad_box.h"
#include "swad_building.h"
#include "swad_building_database.h"
#include "swad_database.h"
#include "swad_error.h"
#include "swad_form.h"
#include "swad_global.h"
#include "swad_HTML.h"
#include "swad_parameter.h"
#include "swad_parameter_code.h"
#include "swad_room_database.h"
/*****************************************************************************/
/************** 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_GetParBuildingOrder (void);
static Usr_Can_t 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_GetBuildingDataFromRow (MYSQL_RES *mysql_res,
struct Bld_Building *Building,
Bld_WhichData_t WhichData);
static void Bld_ListBuildingsForEdition (const struct Bld_Buildings *Buildings);
static void Bld_PutParBldCod (void *BldCod);
static void Bld_RenameBuilding (Nam_ShrtOrFullName_t ShrtOrFull);
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;
}
/*****************************************************************************/
/****************************** List all buildings ***************************/
/*****************************************************************************/
void Bld_SeeBuildings (void)
{
extern const char *Hlp_CENTER_Buildings;
extern const char *Txt_Buildings;
extern const char *Txt_BUILDINGS_HELP_ORDER[Bld_NUM_ORDERS];
extern const char *Txt_BUILDINGS_ORDER[Bld_NUM_ORDERS];
struct Bld_Buildings Buildings;
Bld_Order_t Order;
unsigned NumBuilding;
/***** Trivial check *****/
if (Gbl.Hierarchy.Node[Hie_CTR].HieCod <= 0) // No center selected
return;
/***** Reset buildings context *****/
Bld_ResetBuildings (&Buildings);
/***** Get parameter with the type of order in the list of buildings *****/
Buildings.SelectedOrder = Bld_GetParBuildingOrder ();
/***** Get list of buildings *****/
Bld_GetListBuildings (&Buildings,Bld_ALL_DATA);
/***** Begin box and table *****/
Box_BoxTableBegin (Txt_Buildings,Bld_PutIconsListingBuildings,NULL,
Hlp_CENTER_Buildings,Box_NOT_CLOSABLE,2);
HTM_TR_Begin (NULL);
for (Order = (Bld_Order_t) 0;
Order <= (Bld_Order_t) (Bld_NUM_ORDERS - 1);
Order++)
{
HTM_TH_Begin (HTM_HEAD_LEFT);
Frm_BeginForm (ActSeeBld);
Par_PutParUnsigned (NULL,"Order",(unsigned) Order);
HTM_BUTTON_Submit_Begin (Txt_BUILDINGS_HELP_ORDER[Order],
"class=\"BT_LINK\"");
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 *****/
for (NumBuilding = 0, The_ResetRowColor ();
NumBuilding < Buildings.Num;
NumBuilding++, The_ChangeRowColor ())
{
HTM_TR_Begin (NULL);
/* Short name */
HTM_TD_Begin ("class=\"LM DAT_%s %s\"",
The_GetSuffix (),The_GetColorRows ());
HTM_Txt (Buildings.Lst[NumBuilding].ShrtName);
HTM_TD_End ();
/* Full name */
HTM_TD_Begin ("class=\"LM DAT_%s %s\"",
The_GetSuffix (),The_GetColorRows ());
HTM_Txt (Buildings.Lst[NumBuilding].FullName);
HTM_TD_End ();
/* Location */
HTM_TD_Begin ("class=\"LM DAT_%s %s\"",
The_GetSuffix (),The_GetColorRows ());
HTM_Txt (Buildings.Lst[NumBuilding].Location);
HTM_TD_End ();
HTM_TR_End ();
}
/***** End table and box *****/
Box_BoxTableEnd ();
/***** Free list of buildings *****/
Bld_FreeListBuildings (&Buildings);
}
/*****************************************************************************/
/********* Get parameter with the type or order in list of buildings *********/
/*****************************************************************************/
static Bld_Order_t Bld_GetParBuildingOrder (void)
{
return (Bld_Order_t) Par_GetParUnsignedLong ("Order",
0,
Bld_NUM_ORDERS - 1,
(unsigned long) Bld_ORDER_DEFAULT);
}
/*****************************************************************************/
/********************* Check if I can create buildings ***********************/
/*****************************************************************************/
static Usr_Can_t Bld_CheckIfICanCreateBuildings (void)
{
return (Gbl.Usrs.Me.Role.Logged >= Rol_CTR_ADM) ? Usr_CAN :
Usr_CAN_NOT;
}
/*****************************************************************************/
/**************** Put contextual icons in list of buildings ******************/
/*****************************************************************************/
static void Bld_PutIconsListingBuildings (__attribute__((unused)) void *Args)
{
/***** Put icon to edit buildings *****/
if (Bld_CheckIfICanCreateBuildings () == Usr_CAN)
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)
{
extern const char *Hlp_CENTER_Buildings_edit;
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 (Txt_Buildings,Bld_PutIconsEditingBuildings,NULL,
Hlp_CENTER_Buildings_edit,Box_NOT_CLOSABLE);
/***** Put a form to create a new building *****/
Bld_PutFormToCreateBuilding ();
/***** Forms to edit current buildings *****/
if (Buildings.Num)
Bld_ListBuildingsForEdition (&Buildings);
/***** 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 *****/
Ico_PutContextualIconToView (ActSeeBld,NULL,NULL,NULL);
}
/*****************************************************************************/
/***************************** List all buildings ****************************/
/*****************************************************************************/
void Bld_GetListBuildings (struct Bld_Buildings *Buildings,
Bld_WhichData_t WhichData)
{
MYSQL_RES *mysql_res;
unsigned NumBuilding;
/***** Get buildings from database *****/
Buildings->Num = Bld_DB_GetListBuildings (&mysql_res,WhichData,
Buildings->SelectedOrder);
/***** Count number of rows in result *****/
if (Buildings->Num) // Buildings found...
{
/***** Create list with buldings in center *****/
if ((Buildings->Lst = calloc ((size_t) Buildings->Num,
sizeof (*Buildings->Lst))) == NULL)
Err_NotEnoughMemoryExit ();
/***** Get the buildings *****/
for (NumBuilding = 0;
NumBuilding < Buildings->Num;
NumBuilding++)
Bld_GetBuildingDataFromRow (mysql_res,&Buildings->Lst[NumBuilding],
WhichData);
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/********************** Get building data using its code *********************/
/*****************************************************************************/
void Bld_GetBuildingDataByCod (struct Bld_Building *Building)
{
MYSQL_RES *mysql_res;
/***** 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 *****/
if (Bld_DB_GetBuildingDataByCod (&mysql_res,Building->BldCod)) // Building found...
Bld_GetBuildingDataFromRow (mysql_res,Building,Bld_ALL_DATA);
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
}
/*****************************************************************************/
/******************** Get building data from database row ********************/
/*****************************************************************************/
static void Bld_GetBuildingDataFromRow (MYSQL_RES *mysql_res,
struct Bld_Building *Building,
Bld_WhichData_t WhichData)
{
MYSQL_ROW row;
/***** Get next row from result *****/
row = mysql_fetch_row (mysql_res);
/***** Get building code (row[0]) *****/
if ((Building->BldCod = Str_ConvertStrCodToLongCod (row[0])) <= 0)
Err_WrongBuildingExit ();
/***** Get the short name of the building (row[1]) *****/
Str_Copy (Building->ShrtName,row[1],sizeof (Building->ShrtName) - 1);
if (WhichData == Bld_ALL_DATA)
{
/***** 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);
}
}
/*****************************************************************************/
/************************** 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;
}
}
/*****************************************************************************/
/**************************** List all buildings *****************************/
/*****************************************************************************/
static void Bld_ListBuildingsForEdition (const struct Bld_Buildings *Buildings)
{
static Act_Action_t ActionRename[Nam_NUM_SHRT_FULL_NAMES] =
{
[Nam_SHRT_NAME] = ActRenBldSho,
[Nam_FULL_NAME] = ActRenBldFul,
};
unsigned NumBld;
struct Bld_Building *Building;
char *Anchor = NULL;
const char *Names[Nam_NUM_SHRT_FULL_NAMES];
/***** Begin table *****/
HTM_TABLE_Begin ("TBL_SCROLL");
/***** Write heading *****/
Bld_PutHeadBuildings ();
/***** Write all buildings *****/
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_PutParBldCod,&Building->BldCod);
HTM_TD_End ();
/* Building code */
HTM_TD_Begin ("class=\"CODE DAT_%s\"",The_GetSuffix ());
HTM_ARTICLE_Begin (Anchor);
HTM_Long (Building->BldCod);
HTM_ARTICLE_End ();
HTM_TD_End ();
/* Building short name and full name */
Names[Nam_SHRT_NAME] = Building->ShrtName;
Names[Nam_FULL_NAME] = Building->FullName;
Nam_ExistingShortAndFullNames (ActionRename,
ParCod_Bld,Building->BldCod,
Names,
Frm_PUT_FORM);
/* Building location */
HTM_TD_Begin ("class=\"LM\"");
Frm_BeginFormAnchor (ActRenBldLoc,Anchor);
ParCod_PutPar (ParCod_Bld,Building->BldCod);
HTM_INPUT_TEXT ("Location",Bld_MAX_CHARS_LOCATION,Building->Location,
HTM_SUBMIT_ON_CHANGE,
"size=\"15\" class=\"INPUT_FULL_NAME INPUT_%s\"",
The_GetSuffix ());
Frm_EndForm ();
HTM_TD_End ();
HTM_TR_End ();
}
/***** End table *****/
HTM_TABLE_End ();
}
/*****************************************************************************/
/******************* Write parameter with code of building *******************/
/*****************************************************************************/
static void Bld_PutParBldCod (void *BldCod)
{
if (BldCod)
ParCod_PutPar (ParCod_Bld,*((long *) BldCod));
}
/*****************************************************************************/
/****************************** Remove a building ****************************/
/*****************************************************************************/
void Bld_RemoveBuilding (void)
{
extern const char *Txt_Building_X_removed;
/***** Building constructor *****/
Bld_EditingBuildingConstructor ();
/***** Get building code *****/
Bld_EditingBuilding->BldCod = ParCod_GetAndCheckPar (ParCod_Bld);
/***** Get data of the building from database *****/
Bld_GetBuildingDataByCod (Bld_EditingBuilding);
/***** Update rooms assigned to this building *****/
Roo_DB_RemoveBuildingFromRooms (Bld_EditingBuilding->BldCod);
/***** Remove building *****/
Bld_DB_RemoveBuilding (Bld_EditingBuilding->BldCod);
/***** 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_RenameBuildingShrt (void)
{
/***** Building constructor *****/
Bld_EditingBuildingConstructor ();
/***** Rename building *****/
Bld_RenameBuilding (Nam_SHRT_NAME);
}
/*****************************************************************************/
/******************** Change the full name of a building *********************/
/*****************************************************************************/
void Bld_RenameBuildingFull (void)
{
/***** Building constructor *****/
Bld_EditingBuildingConstructor ();
/***** Rename building *****/
Bld_RenameBuilding (Nam_FULL_NAME);
}
/*****************************************************************************/
/*********************** Change the name of a building ***********************/
/*****************************************************************************/
static void Bld_RenameBuilding (Nam_ShrtOrFullName_t ShrtOrFull)
{
extern const char *Nam_Fields[Nam_NUM_SHRT_FULL_NAMES];
extern unsigned Nam_MaxBytes[Nam_NUM_SHRT_FULL_NAMES];
extern const char *Txt_X_already_exists;
extern const char *Txt_The_building_X_has_been_renamed_as_Y;
extern const char *Txt_The_name_X_has_not_changed;
char *CurrentName[Nam_NUM_SHRT_FULL_NAMES] =
{
[Nam_SHRT_NAME] = Bld_EditingBuilding->ShrtName,
[Nam_FULL_NAME] = Bld_EditingBuilding->FullName,
};
char NewName[Nam_MAX_BYTES_FULL_NAME + 1];
/***** Get parameters from form *****/
/* Get the code of the building */
Bld_EditingBuilding->BldCod = ParCod_GetAndCheckPar (ParCod_Bld);
/* Get the new name for the building */
Nam_GetParShrtOrFullName (ShrtOrFull,NewName);
/***** Get from the database the old names of the building *****/
Bld_GetBuildingDataByCod (Bld_EditingBuilding);
/***** Check if new name is empty *****/
if (NewName[0])
{
/***** Check if old and new names are the same
(this happens when return is pressed without changes) *****/
if (strcmp (CurrentName[ShrtOrFull],NewName)) // Different names
{
/***** If building was in database... *****/
if (Bld_DB_CheckIfBuildingNameExists (Nam_Fields[ShrtOrFull],
NewName,Bld_EditingBuilding->BldCod,
-1L,0)) // Unused
Ale_CreateAlert (Ale_WARNING,NULL,Txt_X_already_exists,NewName);
else
{
/* Update the table changing old name by new name */
Bld_DB_UpdateBuildingField (Bld_EditingBuilding->BldCod,
Nam_Fields[ShrtOrFull],NewName);
/* Write message to show the change made */
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_The_building_X_has_been_renamed_as_Y,
CurrentName[ShrtOrFull],NewName);
}
}
else // The same name
Ale_CreateAlert (Ale_INFO,NULL,
Txt_The_name_X_has_not_changed,
CurrentName[ShrtOrFull]);
}
else
Ale_CreateAlertYouCanNotLeaveFieldEmpty ();
/***** Update building name *****/
Str_Copy (CurrentName[ShrtOrFull],NewName,
Nam_MaxBytes[ShrtOrFull]);
}
/*****************************************************************************/
/******************** Change the location of a building **********************/
/*****************************************************************************/
void Bld_ChangeBuildingLoc (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[Nam_MAX_BYTES_FULL_NAME + 1];
/***** Building constructor *****/
Bld_EditingBuildingConstructor ();
/***** Get parameters from form *****/
/* Get the code of the building */
Bld_EditingBuilding->BldCod = ParCod_GetAndCheckPar (ParCod_Bld);
/* Get the new location for the building */
Par_GetParText ("Location",NewLocation,Bld_MAX_BYTES_LOCATION);
/***** Get from the database the old location of the building *****/
Bld_GetBuildingDataByCod (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 */
Bld_DB_UpdateBuildingField (Bld_EditingBuilding->BldCod,
"Location",NewLocation);
Str_Copy (Bld_EditingBuilding->Location,NewLocation,
sizeof (Bld_EditingBuilding->Location) - 1);
/* 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)
{
const char *Names[Nam_NUM_SHRT_FULL_NAMES];
/***** Begin form to create *****/
Frm_BeginFormTable (ActNewBld,NULL,NULL,NULL,"TBL_SCROLL");
/***** Write heading *****/
Bld_PutHeadBuildings ();
HTM_TR_Begin (NULL);
/***** Column to remove building, disabled here *****/
HTM_TD_Begin ("class=\"BM\"");
HTM_TD_End ();
/***** Building code *****/
HTM_TD_Begin ("class=\"CODE\"");
HTM_TD_End ();
/***** Building short name and full name *****/
Names[Nam_SHRT_NAME] = Bld_EditingBuilding->ShrtName;
Names[Nam_FULL_NAME] = Bld_EditingBuilding->FullName;
Nam_NewShortAndFullNames (Names);
/***** Building location *****/
HTM_TD_Begin ("class=\"LM\"");
HTM_INPUT_TEXT ("Location",Bld_MAX_CHARS_LOCATION,Bld_EditingBuilding->Location,
HTM_NO_ATTR,
"size=\"15\" class=\"INPUT_FULL_NAME INPUT_%s\"",
The_GetSuffix ());
HTM_TD_End ();
HTM_TR_End ();
/***** End form to create *****/
Frm_EndFormTable (Btn_CREATE_BUTTON);
}
/*****************************************************************************/
/****************** 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);
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 );
HTM_TR_End ();
}
/*****************************************************************************/
/***************** Receive form to create a new building *********************/
/*****************************************************************************/
void Bld_ReceiveNewBuilding (void)
{
extern const char *Txt_Created_new_building_X;
char *Names[Nam_NUM_SHRT_FULL_NAMES];
/***** Building constructor *****/
Bld_EditingBuildingConstructor ();
/***** Get parameters from form *****/
/* Get building short name and full name */
Names[Nam_SHRT_NAME] = Bld_EditingBuilding->ShrtName;
Names[Nam_FULL_NAME] = Bld_EditingBuilding->FullName;
Nam_GetParsShrtAndFullName (Names);
/* Get building location */
Par_GetParText ("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 not in database... *****/
if (!Nam_CheckIfNameExists (Bld_DB_CheckIfBuildingNameExists,
(const char **) Names,
-1L,
-1L, // Unused
0)) // Unused
{
Bld_DB_CreateBuilding (Bld_EditingBuilding);
Ale_CreateAlert (Ale_SUCCESS,NULL,Txt_Created_new_building_X,
Names[Nam_FULL_NAME]);
}
}
else // If there is not a building name
Ale_CreateAlertYouMustSpecifyShrtNameAndFullName ();
}
/*****************************************************************************/
/************************ Building constructor/destructor ********************/
/*****************************************************************************/
static void Bld_EditingBuildingConstructor (void)
{
/***** Pointer must be NULL *****/
if (Bld_EditingBuilding != NULL)
Err_WrongBuildingExit ();
/***** Allocate memory for building *****/
if ((Bld_EditingBuilding = malloc (sizeof (*Bld_EditingBuilding))) == NULL)
Err_NotEnoughMemoryExit ();
/***** 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;
}
}