2014-12-01 23:55:08 +01:00
|
|
|
|
// swad_place.c: places
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
SWAD (Shared Workspace At a Distance),
|
|
|
|
|
is a web platform developed at the University of Granada (Spain),
|
|
|
|
|
and used to support university teaching.
|
|
|
|
|
|
|
|
|
|
This file is part of SWAD core.
|
2017-01-13 01:51:23 +01:00
|
|
|
|
Copyright (C) 1999-2017 Antonio Ca<EFBFBD>as Vargas
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Affero General Public License as
|
|
|
|
|
published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************************** Headers **********************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include <linux/stddef.h> // For NULL
|
|
|
|
|
#include <stdlib.h> // For calloc
|
|
|
|
|
#include <string.h> // For string functions
|
|
|
|
|
|
|
|
|
|
#include "swad_constant.h"
|
|
|
|
|
#include "swad_database.h"
|
|
|
|
|
#include "swad_global.h"
|
|
|
|
|
#include "swad_parameter.h"
|
|
|
|
|
#include "swad_place.h"
|
|
|
|
|
#include "swad_text.h"
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************** External global variables from others modules ****************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
extern struct Globals Gbl;
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Private constants *****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************************* Private types *******************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Private variables *****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Private prototypes ****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2017-01-29 12:42:19 +01:00
|
|
|
|
static void Plc_GetParamPlcOrder (void);
|
2016-03-16 22:40:35 +01:00
|
|
|
|
static void Plc_PutIconToEditPlaces (void);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
static void Plc_ListPlacesForEdition (void);
|
|
|
|
|
static void Plc_PutParamPlcCod (long PlcCod);
|
2017-03-09 11:16:17 +01:00
|
|
|
|
|
2016-10-28 10:03:37 +02:00
|
|
|
|
static void Plc_RenamePlace (Cns_ShrtOrFullName_t ShrtOrFullName);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
static bool Plc_CheckIfPlaceNameExists (const char *FieldName,const char *Name,long PlcCod);
|
2017-03-09 11:16:17 +01:00
|
|
|
|
static void Plc_UpdatePlcNameDB (long PlcCod,const char *FieldName,const char *NewPlcName);
|
|
|
|
|
|
2014-12-01 23:55:08 +01:00
|
|
|
|
static void Plc_PutFormToCreatePlace (void);
|
|
|
|
|
static void Plc_PutHeadPlaces (void);
|
|
|
|
|
static void Plc_CreatePlace (struct Place *Plc);
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*************************** List all the places *****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Plc_SeePlaces (void)
|
|
|
|
|
{
|
2016-11-28 12:11:44 +01:00
|
|
|
|
extern const char *Hlp_INSTITUTION_Places;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
extern const char *Txt_Places;
|
|
|
|
|
extern const char *Txt_PLACES_HELP_ORDER[2];
|
|
|
|
|
extern const char *Txt_PLACES_ORDER[2];
|
|
|
|
|
extern const char *Txt_Other_places;
|
|
|
|
|
extern const char *Txt_Place_unspecified;
|
2017-03-01 17:36:49 +01:00
|
|
|
|
extern const char *Txt_Create_another_place;
|
|
|
|
|
extern const char *Txt_Create_place;
|
2017-01-29 12:42:19 +01:00
|
|
|
|
Plc_Order_t Order;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
unsigned NumPlc;
|
|
|
|
|
unsigned NumCtrsWithPlc = 0;
|
|
|
|
|
unsigned NumCtrsInOtherPlcs;
|
2017-03-01 17:36:49 +01:00
|
|
|
|
bool ICanEdit;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
if (Gbl.CurrentIns.Ins.InsCod > 0)
|
|
|
|
|
{
|
2017-03-01 17:36:49 +01:00
|
|
|
|
ICanEdit = (Gbl.Usrs.Me.LoggedRole >= Rol_INS_ADM);
|
|
|
|
|
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/***** Get parameter with the type of order in the list of places *****/
|
2017-01-29 12:42:19 +01:00
|
|
|
|
Plc_GetParamPlcOrder ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Get list of places *****/
|
|
|
|
|
Plc_GetListPlaces ();
|
|
|
|
|
|
|
|
|
|
/***** Table head *****/
|
2017-03-01 17:36:49 +01:00
|
|
|
|
Lay_StartRoundFrame (NULL,Txt_Places,
|
|
|
|
|
ICanEdit ? Plc_PutIconToEditPlaces :
|
|
|
|
|
NULL,
|
|
|
|
|
Hlp_INSTITUTION_Places);
|
|
|
|
|
fprintf (Gbl.F.Out,"<table class=\"FRAME_TBL CELLS_PAD_2\">"
|
|
|
|
|
"<tr>");
|
2014-12-01 23:55:08 +01:00
|
|
|
|
for (Order = Plc_ORDER_BY_PLACE;
|
|
|
|
|
Order <= Plc_ORDER_BY_NUM_CTRS;
|
|
|
|
|
Order++)
|
|
|
|
|
{
|
2015-09-06 20:02:14 +02:00
|
|
|
|
fprintf (Gbl.F.Out,"<th class=\"LEFT_MIDDLE\">");
|
2014-12-01 23:55:08 +01:00
|
|
|
|
Act_FormStart (ActSeePlc);
|
|
|
|
|
Par_PutHiddenParamUnsigned ("Order",(unsigned) Order);
|
2016-07-01 17:13:41 +02:00
|
|
|
|
Act_LinkFormSubmit (Txt_PLACES_HELP_ORDER[Order],"TIT_TBL",NULL);
|
2017-01-29 12:42:19 +01:00
|
|
|
|
if (Order == Gbl.Plcs.SelectedOrder)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
fprintf (Gbl.F.Out,"<u>");
|
|
|
|
|
fprintf (Gbl.F.Out,"%s",Txt_PLACES_ORDER[Order]);
|
2017-01-29 12:42:19 +01:00
|
|
|
|
if (Order == Gbl.Plcs.SelectedOrder)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
fprintf (Gbl.F.Out,"</u>");
|
2015-03-13 00:16:02 +01:00
|
|
|
|
fprintf (Gbl.F.Out,"</a>");
|
|
|
|
|
Act_FormEnd ();
|
2015-09-05 19:19:39 +02:00
|
|
|
|
fprintf (Gbl.F.Out,"</th>");
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
fprintf (Gbl.F.Out,"</tr>");
|
|
|
|
|
|
2015-11-15 23:07:19 +01:00
|
|
|
|
/***** Write all places and their nuber of centres *****/
|
2014-12-01 23:55:08 +01:00
|
|
|
|
for (NumPlc = 0;
|
|
|
|
|
NumPlc < Gbl.Plcs.Num;
|
|
|
|
|
NumPlc++)
|
|
|
|
|
{
|
|
|
|
|
/* Write data of this place */
|
|
|
|
|
fprintf (Gbl.F.Out,"<tr>"
|
2015-08-24 11:25:20 +02:00
|
|
|
|
"<td class=\"DAT LEFT_MIDDLE\">"
|
2014-12-23 22:47:09 +01:00
|
|
|
|
"%s"
|
2015-11-15 23:07:19 +01:00
|
|
|
|
"</td>"
|
|
|
|
|
"<td class=\"DAT RIGHT_MIDDLE\">"
|
2015-08-24 11:25:20 +02:00
|
|
|
|
"%u"
|
2014-12-23 22:47:09 +01:00
|
|
|
|
"</td>"
|
2014-12-01 23:55:08 +01:00
|
|
|
|
"</tr>",
|
2015-11-15 23:07:19 +01:00
|
|
|
|
Gbl.Plcs.Lst[NumPlc].FullName,
|
2014-12-01 23:55:08 +01:00
|
|
|
|
Gbl.Plcs.Lst[NumPlc].NumCtrs);
|
|
|
|
|
NumCtrsWithPlc += Gbl.Plcs.Lst[NumPlc].NumCtrs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***** Separation row *****/
|
|
|
|
|
fprintf (Gbl.F.Out,"<tr>"
|
2014-12-23 22:47:09 +01:00
|
|
|
|
"<td colspan=\"2\" class=\"DAT\">"
|
|
|
|
|
" "
|
|
|
|
|
"</td>"
|
2014-12-01 23:55:08 +01:00
|
|
|
|
"</tr>");
|
|
|
|
|
|
2015-11-15 23:07:19 +01:00
|
|
|
|
/***** Write centres (of the current institution) with other place *****/
|
2014-12-01 23:55:08 +01:00
|
|
|
|
NumCtrsInOtherPlcs = Ctr_GetNumCtrsInPlc (0);
|
|
|
|
|
fprintf (Gbl.F.Out,"<tr>"
|
2015-08-24 11:25:20 +02:00
|
|
|
|
"<td class=\"DAT LEFT_MIDDLE\">"
|
2014-12-23 22:47:09 +01:00
|
|
|
|
"%s"
|
|
|
|
|
"</td>"
|
2015-08-24 11:25:20 +02:00
|
|
|
|
"<td class=\"DAT RIGHT_MIDDLE\">"
|
|
|
|
|
"%u"
|
2014-12-23 22:47:09 +01:00
|
|
|
|
"</td>"
|
2014-12-01 23:55:08 +01:00
|
|
|
|
"</tr>",
|
|
|
|
|
Txt_Other_places,NumCtrsInOtherPlcs);
|
|
|
|
|
NumCtrsWithPlc += NumCtrsInOtherPlcs;
|
|
|
|
|
|
2015-11-15 23:07:19 +01:00
|
|
|
|
/***** Write centres (of the current institution) with no place *****/
|
2014-12-01 23:55:08 +01:00
|
|
|
|
fprintf (Gbl.F.Out,"<tr>"
|
2015-08-24 11:25:20 +02:00
|
|
|
|
"<td class=\"DAT LEFT_MIDDLE\">"
|
2014-12-23 22:47:09 +01:00
|
|
|
|
"%s"
|
|
|
|
|
"</td>"
|
2015-08-24 11:25:20 +02:00
|
|
|
|
"<td class=\"DAT RIGHT_MIDDLE\">"
|
|
|
|
|
"%u"
|
2014-12-23 22:47:09 +01:00
|
|
|
|
"</td>"
|
2014-12-01 23:55:08 +01:00
|
|
|
|
"</tr>",
|
|
|
|
|
Txt_Place_unspecified,
|
2015-11-15 23:07:19 +01:00
|
|
|
|
Ctr_GetNumCtrsInIns (Gbl.CurrentIns.Ins.InsCod) -
|
|
|
|
|
NumCtrsWithPlc);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2017-03-01 17:36:49 +01:00
|
|
|
|
fprintf (Gbl.F.Out,"</table>");
|
|
|
|
|
|
|
|
|
|
/***** Button to create place *****/
|
|
|
|
|
if (ICanEdit)
|
|
|
|
|
{
|
|
|
|
|
Act_FormStart (ActEdiPlc);
|
|
|
|
|
Lay_PutConfirmButton (Gbl.Plcs.Num ? Txt_Create_another_place :
|
|
|
|
|
Txt_Create_place);
|
|
|
|
|
Act_FormEnd ();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-20 13:47:46 +01:00
|
|
|
|
/***** End table *****/
|
2017-03-01 17:36:49 +01:00
|
|
|
|
Lay_EndRoundFrame ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Free list of places *****/
|
|
|
|
|
Plc_FreeListPlaces ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********** Get parameter with the type or order in list of places ***********/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2017-01-29 12:42:19 +01:00
|
|
|
|
static void Plc_GetParamPlcOrder (void)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2017-01-29 12:42:19 +01:00
|
|
|
|
Gbl.Plcs.SelectedOrder = (Plc_Order_t)
|
2017-01-29 21:41:08 +01:00
|
|
|
|
Par_GetParToUnsignedLong ("Order",
|
|
|
|
|
0,
|
|
|
|
|
Plc_NUM_ORDERS - 1,
|
|
|
|
|
(unsigned long) Plc_ORDER_DEFAULT);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************** Put a link (form) to edit places *********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2016-03-16 22:40:35 +01:00
|
|
|
|
static void Plc_PutIconToEditPlaces (void)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_Edit;
|
|
|
|
|
|
2016-07-01 16:32:42 +02:00
|
|
|
|
Lay_PutContextualLink (ActEdiPlc,NULL,
|
|
|
|
|
"edit64x64.png",
|
|
|
|
|
Txt_Edit,NULL,
|
|
|
|
|
NULL);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*************************** Put forms to edit places ************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Plc_EditPlaces (void)
|
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_There_are_no_places;
|
|
|
|
|
|
|
|
|
|
/***** Get list of places *****/
|
|
|
|
|
Plc_GetListPlaces ();
|
|
|
|
|
|
2016-03-16 13:28:16 +01:00
|
|
|
|
if (!Gbl.Plcs.Num)
|
2015-02-08 17:35:44 +01:00
|
|
|
|
/***** Help message *****/
|
2014-12-01 23:55:08 +01:00
|
|
|
|
Lay_ShowAlert (Lay_INFO,Txt_There_are_no_places);
|
|
|
|
|
|
|
|
|
|
/***** Put a form to create a new place *****/
|
|
|
|
|
Plc_PutFormToCreatePlace ();
|
|
|
|
|
|
|
|
|
|
/***** Forms to edit current places *****/
|
|
|
|
|
if (Gbl.Plcs.Num)
|
|
|
|
|
Plc_ListPlacesForEdition ();
|
|
|
|
|
|
|
|
|
|
/***** Free list of places *****/
|
|
|
|
|
Plc_FreeListPlaces ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/**************************** List all the places ****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Plc_GetListPlaces (void)
|
|
|
|
|
{
|
|
|
|
|
char OrderBySubQuery[256];
|
|
|
|
|
char Query[1024];
|
|
|
|
|
MYSQL_RES *mysql_res;
|
|
|
|
|
MYSQL_ROW row;
|
|
|
|
|
unsigned long NumRows;
|
|
|
|
|
unsigned NumPlc;
|
|
|
|
|
struct Place *Plc;
|
|
|
|
|
|
|
|
|
|
/***** Get places from database *****/
|
2017-01-29 12:42:19 +01:00
|
|
|
|
switch (Gbl.Plcs.SelectedOrder)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
|
|
|
|
case Plc_ORDER_BY_PLACE:
|
|
|
|
|
sprintf (OrderBySubQuery,"FullName");
|
|
|
|
|
break;
|
|
|
|
|
case Plc_ORDER_BY_NUM_CTRS:
|
|
|
|
|
sprintf (OrderBySubQuery,"NumCtrs DESC,FullName");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
sprintf (Query,"(SELECT places.PlcCod,places.ShortName,places.FullName,COUNT(*) AS NumCtrs"
|
|
|
|
|
" FROM places,centres"
|
|
|
|
|
" WHERE places.InsCod='%ld'"
|
|
|
|
|
" AND places.PlcCod=centres.PlcCod"
|
|
|
|
|
" AND centres.InsCod='%ld'"
|
|
|
|
|
" GROUP BY places.PlcCod)"
|
|
|
|
|
" UNION "
|
|
|
|
|
"(SELECT PlcCod,ShortName,FullName,0 AS NumCtrs"
|
|
|
|
|
" FROM places"
|
|
|
|
|
" WHERE InsCod='%ld'"
|
|
|
|
|
" AND PlcCod NOT IN"
|
|
|
|
|
" (SELECT DISTINCT PlcCod FROM centres WHERE InsCod='%ld'))"
|
|
|
|
|
" ORDER BY %s",
|
|
|
|
|
Gbl.CurrentIns.Ins.InsCod,
|
|
|
|
|
Gbl.CurrentIns.Ins.InsCod,
|
|
|
|
|
Gbl.CurrentIns.Ins.InsCod,
|
|
|
|
|
Gbl.CurrentIns.Ins.InsCod,
|
|
|
|
|
OrderBySubQuery);
|
|
|
|
|
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get places");
|
|
|
|
|
|
|
|
|
|
/***** Count number of rows in result *****/
|
|
|
|
|
if (NumRows) // Places found...
|
|
|
|
|
{
|
|
|
|
|
Gbl.Plcs.Num = (unsigned) NumRows;
|
|
|
|
|
|
|
|
|
|
/***** Create list with courses in centre *****/
|
|
|
|
|
if ((Gbl.Plcs.Lst = (struct Place *) calloc (NumRows,sizeof (struct Place))) == NULL)
|
|
|
|
|
Lay_ShowErrorAndExit ("Not enough memory to store places.");
|
|
|
|
|
|
|
|
|
|
/***** Get the places *****/
|
|
|
|
|
for (NumPlc = 0;
|
|
|
|
|
NumPlc < Gbl.Plcs.Num;
|
|
|
|
|
NumPlc++)
|
|
|
|
|
{
|
|
|
|
|
Plc = &(Gbl.Plcs.Lst[NumPlc]);
|
|
|
|
|
|
|
|
|
|
/* Get next place */
|
|
|
|
|
row = mysql_fetch_row (mysql_res);
|
|
|
|
|
|
|
|
|
|
/* Get place code (row[0]) */
|
|
|
|
|
if ((Plc->PlcCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
|
|
|
|
|
Lay_ShowErrorAndExit ("Wrong code of place.");
|
|
|
|
|
|
|
|
|
|
/* Get the short name of the place (row[1]) */
|
2017-01-17 03:10:43 +01:00
|
|
|
|
Str_Copy (Plc->ShrtName,row[1],
|
2017-03-07 19:55:29 +01:00
|
|
|
|
Plc_MAX_BYTES_PLACE_SHRT_NAME);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/* Get the full name of the place (row[2]) */
|
2017-01-17 03:10:43 +01:00
|
|
|
|
Str_Copy (Plc->FullName,row[2],
|
2017-03-07 19:55:29 +01:00
|
|
|
|
Plc_MAX_BYTES_PLACE_FULL_NAME);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/* Get number of centres in this place (row[3]) */
|
|
|
|
|
if (sscanf (row[3],"%u",&Plc->NumCtrs) != 1)
|
|
|
|
|
Plc->NumCtrs = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
Gbl.Plcs.Num = 0;
|
|
|
|
|
|
|
|
|
|
/***** Free structure that stores the query result *****/
|
|
|
|
|
DB_FreeMySQLResult (&mysql_res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/**************************** Get place full name ****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Plc_GetDataOfPlaceByCod (struct Place *Plc)
|
|
|
|
|
{
|
2015-12-09 22:05:21 +01:00
|
|
|
|
extern const char *Txt_Place_unspecified;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
extern const char *Txt_Another_place;
|
|
|
|
|
char Query[1024];
|
|
|
|
|
MYSQL_RES *mysql_res;
|
|
|
|
|
MYSQL_ROW row;
|
|
|
|
|
unsigned long NumRows;
|
|
|
|
|
|
|
|
|
|
/***** Clear data *****/
|
2016-10-28 10:03:37 +02:00
|
|
|
|
Plc->ShrtName[0] = '\0';
|
2014-12-01 23:55:08 +01:00
|
|
|
|
Plc->FullName[0] = '\0';
|
|
|
|
|
Plc->NumCtrs = 0;
|
|
|
|
|
|
|
|
|
|
/***** Check if place code is correct *****/
|
2015-12-09 22:05:21 +01:00
|
|
|
|
if (Plc->PlcCod < 0)
|
|
|
|
|
{
|
2017-01-15 18:02:52 +01:00
|
|
|
|
Str_Copy (Plc->ShrtName,Txt_Place_unspecified,
|
2017-03-07 19:55:29 +01:00
|
|
|
|
Plc_MAX_BYTES_PLACE_SHRT_NAME);
|
2017-01-15 18:02:52 +01:00
|
|
|
|
Str_Copy (Plc->FullName,Txt_Place_unspecified,
|
2017-03-07 19:55:29 +01:00
|
|
|
|
Plc_MAX_BYTES_PLACE_FULL_NAME);
|
2015-12-09 22:05:21 +01:00
|
|
|
|
}
|
|
|
|
|
else if (Plc->PlcCod == 0)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2017-01-17 03:10:43 +01:00
|
|
|
|
Str_Copy (Plc->ShrtName,Txt_Another_place,
|
2017-03-07 19:55:29 +01:00
|
|
|
|
Plc_MAX_BYTES_PLACE_SHRT_NAME);
|
2017-01-17 03:10:43 +01:00
|
|
|
|
Str_Copy (Plc->FullName,Txt_Another_place,
|
2017-03-07 19:55:29 +01:00
|
|
|
|
Plc_MAX_BYTES_PLACE_FULL_NAME);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
else if (Plc->PlcCod > 0)
|
|
|
|
|
{
|
|
|
|
|
/***** Get data of a place from database *****/
|
|
|
|
|
sprintf (Query,"(SELECT places.ShortName,places.FullName,COUNT(*)"
|
|
|
|
|
" FROM places,centres"
|
|
|
|
|
" WHERE places.PlcCod='%ld'"
|
|
|
|
|
" AND places.PlcCod=centres.PlcCod"
|
|
|
|
|
" AND centres.PlcCod='%ld'"
|
|
|
|
|
" GROUP BY places.PlcCod)"
|
|
|
|
|
" UNION "
|
|
|
|
|
"(SELECT ShortName,FullName,0"
|
|
|
|
|
" FROM places"
|
|
|
|
|
" WHERE PlcCod='%ld'"
|
|
|
|
|
" AND PlcCod NOT IN"
|
|
|
|
|
" (SELECT DISTINCT PlcCod FROM centres))",
|
|
|
|
|
Plc->PlcCod,
|
|
|
|
|
Plc->PlcCod,
|
|
|
|
|
Plc->PlcCod);
|
|
|
|
|
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get data of a place");
|
|
|
|
|
|
|
|
|
|
/***** Count number of rows in result *****/
|
|
|
|
|
if (NumRows) // Place found...
|
|
|
|
|
{
|
|
|
|
|
/* Get row */
|
|
|
|
|
row = mysql_fetch_row (mysql_res);
|
|
|
|
|
|
|
|
|
|
/* Get the short name of the place (row[0]) */
|
2017-01-17 03:10:43 +01:00
|
|
|
|
Str_Copy (Plc->ShrtName,row[0],
|
2017-03-07 19:55:29 +01:00
|
|
|
|
Plc_MAX_BYTES_PLACE_SHRT_NAME);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/* Get the full name of the place (row[1]) */
|
2017-01-17 03:10:43 +01:00
|
|
|
|
Str_Copy (Plc->FullName,row[1],
|
2017-03-07 19:55:29 +01:00
|
|
|
|
Plc_MAX_BYTES_PLACE_FULL_NAME);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/* Get number of centres in this place (row[2]) */
|
|
|
|
|
if (sscanf (row[2],"%u",&Plc->NumCtrs) != 1)
|
|
|
|
|
Plc->NumCtrs = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***** Free structure that stores the query result *****/
|
|
|
|
|
DB_FreeMySQLResult (&mysql_res);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/**************************** Free list of places ****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Plc_FreeListPlaces (void)
|
|
|
|
|
{
|
|
|
|
|
if (Gbl.Plcs.Lst)
|
|
|
|
|
{
|
|
|
|
|
/***** Free memory used by the list of places in institution *****/
|
|
|
|
|
free ((void *) Gbl.Plcs.Lst);
|
|
|
|
|
Gbl.Plcs.Lst = NULL;
|
|
|
|
|
Gbl.Plcs.Num = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*************************** List all the places *****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void Plc_ListPlacesForEdition (void)
|
|
|
|
|
{
|
2016-11-28 12:11:44 +01:00
|
|
|
|
extern const char *Hlp_INSTITUTION_Places_edit;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
extern const char *Txt_Places;
|
|
|
|
|
unsigned NumPlc;
|
|
|
|
|
struct Place *Plc;
|
|
|
|
|
|
2016-11-28 12:11:44 +01:00
|
|
|
|
Lay_StartRoundFrameTable (NULL,Txt_Places,
|
|
|
|
|
NULL,Hlp_INSTITUTION_Places_edit,2);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Table head *****/
|
|
|
|
|
Plc_PutHeadPlaces ();
|
|
|
|
|
|
|
|
|
|
/***** Write all the places *****/
|
|
|
|
|
for (NumPlc = 0;
|
|
|
|
|
NumPlc < Gbl.Plcs.Num;
|
|
|
|
|
NumPlc++)
|
|
|
|
|
{
|
|
|
|
|
Plc = &Gbl.Plcs.Lst[NumPlc];
|
|
|
|
|
|
|
|
|
|
/* Put icon to remove place */
|
|
|
|
|
fprintf (Gbl.F.Out,"<tr>"
|
|
|
|
|
"<td class=\"BM\">");
|
|
|
|
|
if (Plc->NumCtrs) // Place has centres ==> deletion forbidden
|
2015-07-22 19:20:30 +02:00
|
|
|
|
Lay_PutIconRemovalNotAllowed ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Act_FormStart (ActRemPlc);
|
|
|
|
|
Plc_PutParamPlcCod (Plc->PlcCod);
|
2015-07-22 19:59:28 +02:00
|
|
|
|
Lay_PutIconRemove ();
|
2015-03-13 00:16:02 +01:00
|
|
|
|
Act_FormEnd ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
fprintf (Gbl.F.Out,"</td>");
|
|
|
|
|
|
|
|
|
|
/* Place code */
|
2015-08-24 11:25:20 +02:00
|
|
|
|
fprintf (Gbl.F.Out,"<td class=\"DAT RIGHT_MIDDLE\">"
|
|
|
|
|
"%ld"
|
2014-12-23 22:47:09 +01:00
|
|
|
|
"</td>",
|
2014-12-01 23:55:08 +01:00
|
|
|
|
Plc->PlcCod);
|
|
|
|
|
|
|
|
|
|
/* Place short name */
|
2015-08-24 11:25:20 +02:00
|
|
|
|
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">");
|
2014-12-01 23:55:08 +01:00
|
|
|
|
Act_FormStart (ActRenPlcSho);
|
|
|
|
|
Plc_PutParamPlcCod (Plc->PlcCod);
|
2015-10-22 14:49:48 +02:00
|
|
|
|
fprintf (Gbl.F.Out,"<input type=\"text\" name=\"ShortName\""
|
2015-12-05 21:15:30 +01:00
|
|
|
|
" maxlength=\"%u\" value=\"%s\""
|
|
|
|
|
" class=\"INPUT_SHORT_NAME\""
|
2015-10-22 14:49:48 +02:00
|
|
|
|
" onchange=\"document.getElementById('%s').submit();\" />",
|
2017-03-07 19:55:29 +01:00
|
|
|
|
Plc_MAX_CHARS_PLACE_SHRT_NAME,Plc->ShrtName,Gbl.Form.Id);
|
2015-03-13 00:16:02 +01:00
|
|
|
|
Act_FormEnd ();
|
|
|
|
|
fprintf (Gbl.F.Out,"</td>");
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/* Place full name */
|
2015-08-24 11:25:20 +02:00
|
|
|
|
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">");
|
2014-12-01 23:55:08 +01:00
|
|
|
|
Act_FormStart (ActRenPlcFul);
|
|
|
|
|
Plc_PutParamPlcCod (Plc->PlcCod);
|
2015-10-22 14:49:48 +02:00
|
|
|
|
fprintf (Gbl.F.Out,"<input type=\"text\" name=\"FullName\""
|
2015-12-05 21:15:30 +01:00
|
|
|
|
" maxlength=\"%u\" value=\"%s\""
|
|
|
|
|
" class=\"INPUT_FULL_NAME\""
|
2015-10-22 14:49:48 +02:00
|
|
|
|
" onchange=\"document.getElementById('%s').submit();\" />",
|
2017-03-07 19:55:29 +01:00
|
|
|
|
Plc_MAX_CHARS_PLACE_FULL_NAME,Plc->FullName,Gbl.Form.Id);
|
2015-03-13 00:16:02 +01:00
|
|
|
|
Act_FormEnd ();
|
|
|
|
|
fprintf (Gbl.F.Out,"</td>");
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/* Number of centres */
|
2015-08-24 11:25:20 +02:00
|
|
|
|
fprintf (Gbl.F.Out,"<td class=\"DAT RIGHT_MIDDLE\">"
|
|
|
|
|
"%u"
|
2014-12-23 22:47:09 +01:00
|
|
|
|
"</td>"
|
2014-12-01 23:55:08 +01:00
|
|
|
|
"</tr>",
|
|
|
|
|
Plc->NumCtrs);
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-12 18:01:06 +02:00
|
|
|
|
Lay_EndRoundFrameTable ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************** Write parameter with code of place *********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void Plc_PutParamPlcCod (long PlcCod)
|
|
|
|
|
{
|
|
|
|
|
Par_PutHiddenParamLong ("PlcCod",PlcCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************* Get parameter with code of place **********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
long Plc_GetParamPlcCod (void)
|
|
|
|
|
{
|
2017-01-28 20:32:50 +01:00
|
|
|
|
/***** Get code of place *****/
|
|
|
|
|
return Par_GetParToLong ("PlcCod");
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************************* Remove a place ******************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Plc_RemovePlace (void)
|
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_To_remove_a_place_you_must_first_remove_all_centres_of_that_place;
|
|
|
|
|
extern const char *Txt_Place_X_removed;
|
2017-03-13 13:33:45 +01:00
|
|
|
|
char Query[128];
|
2014-12-01 23:55:08 +01:00
|
|
|
|
struct Place Plc;
|
|
|
|
|
|
|
|
|
|
/***** Get place code *****/
|
|
|
|
|
if ((Plc.PlcCod = Plc_GetParamPlcCod ()) == -1L)
|
|
|
|
|
Lay_ShowErrorAndExit ("Code of place is missing.");
|
|
|
|
|
|
|
|
|
|
/***** Get data of the place from database *****/
|
|
|
|
|
Plc_GetDataOfPlaceByCod (&Plc);
|
|
|
|
|
|
|
|
|
|
/***** Check if this place has centres *****/
|
|
|
|
|
if (Plc.NumCtrs) // Place has centres ==> don't remove
|
|
|
|
|
Lay_ShowAlert (Lay_WARNING,Txt_To_remove_a_place_you_must_first_remove_all_centres_of_that_place);
|
|
|
|
|
else // Place has no centres ==> remove it
|
|
|
|
|
{
|
|
|
|
|
/***** Remove place *****/
|
|
|
|
|
sprintf (Query,"DELETE FROM places WHERE PlcCod='%ld'",
|
|
|
|
|
Plc.PlcCod);
|
|
|
|
|
DB_QueryDELETE (Query,"can not remove a place");
|
|
|
|
|
|
|
|
|
|
/***** Write message to show the change made *****/
|
|
|
|
|
sprintf (Gbl.Message,Txt_Place_X_removed,
|
|
|
|
|
Plc.FullName);
|
|
|
|
|
Lay_ShowAlert (Lay_SUCCESS,Gbl.Message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***** Show the form again *****/
|
|
|
|
|
Plc_EditPlaces ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************* Change the short name of a place **********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Plc_RenamePlaceShort (void)
|
|
|
|
|
{
|
2016-10-28 10:03:37 +02:00
|
|
|
|
Plc_RenamePlace (Cns_SHRT_NAME);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************* Change the full name of a place ***********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Plc_RenamePlaceFull (void)
|
|
|
|
|
{
|
|
|
|
|
Plc_RenamePlace (Cns_FULL_NAME);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************ Change the name of a place *************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2016-10-28 10:03:37 +02:00
|
|
|
|
static void Plc_RenamePlace (Cns_ShrtOrFullName_t ShrtOrFullName)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_You_can_not_leave_the_name_of_the_place_X_empty;
|
|
|
|
|
extern const char *Txt_The_place_X_already_exists;
|
|
|
|
|
extern const char *Txt_The_place_X_has_been_renamed_as_Y;
|
|
|
|
|
extern const char *Txt_The_name_of_the_place_X_has_not_changed;
|
|
|
|
|
struct Place *Plc;
|
|
|
|
|
const char *ParamName = NULL; // Initialized to avoid warning
|
|
|
|
|
const char *FieldName = NULL; // Initialized to avoid warning
|
2017-03-07 19:55:29 +01:00
|
|
|
|
unsigned MaxBytes = 0; // Initialized to avoid warning
|
2014-12-01 23:55:08 +01:00
|
|
|
|
char *CurrentPlcName = NULL; // Initialized to avoid warning
|
2017-03-07 19:55:29 +01:00
|
|
|
|
char NewPlcName[Plc_MAX_BYTES_PLACE_FULL_NAME + 1];
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
Plc = &Gbl.Plcs.EditingPlc;
|
2016-10-28 10:03:37 +02:00
|
|
|
|
switch (ShrtOrFullName)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2016-10-28 10:03:37 +02:00
|
|
|
|
case Cns_SHRT_NAME:
|
2014-12-01 23:55:08 +01:00
|
|
|
|
ParamName = "ShortName";
|
|
|
|
|
FieldName = "ShortName";
|
2017-03-07 19:55:29 +01:00
|
|
|
|
MaxBytes = Plc_MAX_BYTES_PLACE_SHRT_NAME;
|
2016-10-28 10:03:37 +02:00
|
|
|
|
CurrentPlcName = Plc->ShrtName;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
break;
|
|
|
|
|
case Cns_FULL_NAME:
|
|
|
|
|
ParamName = "FullName";
|
|
|
|
|
FieldName = "FullName";
|
2017-03-07 19:55:29 +01:00
|
|
|
|
MaxBytes = Plc_MAX_BYTES_PLACE_FULL_NAME;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
CurrentPlcName = Plc->FullName;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***** Get parameters from form *****/
|
|
|
|
|
/* Get the code of the place */
|
|
|
|
|
if ((Plc->PlcCod = Plc_GetParamPlcCod ()) == -1L)
|
|
|
|
|
Lay_ShowErrorAndExit ("Code of place is missing.");
|
|
|
|
|
|
|
|
|
|
/* Get the new name for the place */
|
2017-03-07 19:55:29 +01:00
|
|
|
|
Par_GetParToText (ParamName,NewPlcName,MaxBytes);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Get from the database the old names of the place *****/
|
|
|
|
|
Plc_GetDataOfPlaceByCod (Plc);
|
|
|
|
|
|
|
|
|
|
/***** Check if new name is empty *****/
|
|
|
|
|
if (!NewPlcName[0])
|
|
|
|
|
{
|
|
|
|
|
sprintf (Gbl.Message,Txt_You_can_not_leave_the_name_of_the_place_X_empty,
|
|
|
|
|
CurrentPlcName);
|
|
|
|
|
Lay_ShowAlert (Lay_WARNING,Gbl.Message);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/***** Check if old and new names are the same (this happens when user press enter with no changes in the form) *****/
|
|
|
|
|
if (strcmp (CurrentPlcName,NewPlcName)) // Different names
|
|
|
|
|
{
|
|
|
|
|
/***** If place was in database... *****/
|
|
|
|
|
if (Plc_CheckIfPlaceNameExists (ParamName,NewPlcName,Plc->PlcCod))
|
|
|
|
|
{
|
|
|
|
|
sprintf (Gbl.Message,Txt_The_place_X_already_exists,
|
|
|
|
|
NewPlcName);
|
|
|
|
|
Lay_ShowAlert (Lay_WARNING,Gbl.Message);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Update the table changing old name by new name */
|
2017-03-09 11:16:17 +01:00
|
|
|
|
Plc_UpdatePlcNameDB (Plc->PlcCod,FieldName,NewPlcName);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2017-03-09 11:16:17 +01:00
|
|
|
|
/* Write message to show the change made */
|
2014-12-01 23:55:08 +01:00
|
|
|
|
sprintf (Gbl.Message,Txt_The_place_X_has_been_renamed_as_Y,
|
|
|
|
|
CurrentPlcName,NewPlcName);
|
|
|
|
|
Lay_ShowAlert (Lay_SUCCESS,Gbl.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else // The same name
|
|
|
|
|
{
|
|
|
|
|
sprintf (Gbl.Message,Txt_The_name_of_the_place_X_has_not_changed,
|
|
|
|
|
CurrentPlcName);
|
|
|
|
|
Lay_ShowAlert (Lay_INFO,Gbl.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***** Show the form again *****/
|
2017-01-17 03:10:43 +01:00
|
|
|
|
Str_Copy (CurrentPlcName,NewPlcName,
|
2017-03-07 19:55:29 +01:00
|
|
|
|
MaxBytes);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
Plc_EditPlaces ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************** Check if the name of place exists ********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static bool Plc_CheckIfPlaceNameExists (const char *FieldName,const char *Name,long PlcCod)
|
|
|
|
|
{
|
2017-03-09 11:16:17 +01:00
|
|
|
|
char Query[256 + Plc_MAX_BYTES_PLACE_FULL_NAME];
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Get number of places with a name from database *****/
|
|
|
|
|
sprintf (Query,"SELECT COUNT(*) FROM places"
|
|
|
|
|
" WHERE InsCod='%ld' AND %s='%s' AND PlcCod<>'%ld'",
|
|
|
|
|
Gbl.CurrentIns.Ins.InsCod,FieldName,Name,PlcCod);
|
|
|
|
|
return (DB_QueryCOUNT (Query,"can not check if the name of a place already existed") != 0);
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-09 11:16:17 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/****************** Update place name in table of places *********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void Plc_UpdatePlcNameDB (long PlcCod,const char *FieldName,const char *NewPlcName)
|
|
|
|
|
{
|
|
|
|
|
char Query[128 + Plc_MAX_BYTES_PLACE_FULL_NAME];
|
|
|
|
|
|
|
|
|
|
/***** Update place changing old name by new name */
|
|
|
|
|
sprintf (Query,"UPDATE places SET %s='%s' WHERE PlcCod='%ld'",
|
|
|
|
|
FieldName,NewPlcName,PlcCod);
|
|
|
|
|
DB_QueryUPDATE (Query,"can not update the name of a place");
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************* Put a form to create a new place **********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void Plc_PutFormToCreatePlace (void)
|
|
|
|
|
{
|
2016-11-28 12:11:44 +01:00
|
|
|
|
extern const char *Hlp_INSTITUTION_Places_edit;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
extern const char *Txt_New_place;
|
2015-02-04 20:03:23 +01:00
|
|
|
|
extern const char *Txt_Short_name;
|
|
|
|
|
extern const char *Txt_Full_name;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
extern const char *Txt_Create_place;
|
|
|
|
|
struct Place *Plc;
|
|
|
|
|
|
|
|
|
|
Plc = &Gbl.Plcs.EditingPlc;
|
|
|
|
|
|
|
|
|
|
/***** Start form *****/
|
|
|
|
|
Act_FormStart (ActNewPlc);
|
|
|
|
|
|
|
|
|
|
/***** Start of frame *****/
|
2016-11-28 12:11:44 +01:00
|
|
|
|
Lay_StartRoundFrameTable (NULL,Txt_New_place,
|
|
|
|
|
NULL,Hlp_INSTITUTION_Places_edit,2);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Write heading *****/
|
|
|
|
|
fprintf (Gbl.F.Out,"<tr>"
|
2015-09-06 20:02:14 +02:00
|
|
|
|
"<th class=\"LEFT_MIDDLE\">"
|
2014-12-23 22:47:09 +01:00
|
|
|
|
"%s"
|
2015-09-05 19:19:39 +02:00
|
|
|
|
"</th>"
|
2015-09-06 20:02:14 +02:00
|
|
|
|
"<th class=\"LEFT_MIDDLE\">"
|
2014-12-23 22:47:09 +01:00
|
|
|
|
"%s"
|
2015-09-05 19:19:39 +02:00
|
|
|
|
"</th>"
|
2014-12-01 23:55:08 +01:00
|
|
|
|
"</tr>",
|
2015-02-04 20:03:23 +01:00
|
|
|
|
Txt_Short_name,
|
|
|
|
|
Txt_Full_name);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Place short name *****/
|
|
|
|
|
fprintf (Gbl.F.Out,"<tr>"
|
2015-08-24 11:25:20 +02:00
|
|
|
|
"<td class=\"CENTER_MIDDLE\">"
|
2015-10-23 01:31:08 +02:00
|
|
|
|
"<input type=\"text\" name=\"ShortName\""
|
2015-12-05 21:15:30 +01:00
|
|
|
|
" maxlength=\"%u\" value=\"%s\""
|
2016-11-19 20:43:50 +01:00
|
|
|
|
" class=\"INPUT_SHORT_NAME\""
|
|
|
|
|
" required=\"required\" />"
|
2014-12-01 23:55:08 +01:00
|
|
|
|
"</td>",
|
2017-03-07 19:55:29 +01:00
|
|
|
|
Plc_MAX_CHARS_PLACE_SHRT_NAME,Plc->ShrtName);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Place full name *****/
|
2015-08-24 11:25:20 +02:00
|
|
|
|
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">"
|
2015-10-23 01:31:08 +02:00
|
|
|
|
"<input type=\"text\" name=\"FullName\""
|
2015-12-05 21:15:30 +01:00
|
|
|
|
" maxlength=\"%u\" value=\"%s\""
|
2016-11-19 20:43:50 +01:00
|
|
|
|
" class=\"INPUT_FULL_NAME\""
|
|
|
|
|
" required=\"required\" />"
|
2014-12-01 23:55:08 +01:00
|
|
|
|
"</td>"
|
|
|
|
|
"</tr>",
|
2017-03-07 19:55:29 +01:00
|
|
|
|
Plc_MAX_CHARS_PLACE_FULL_NAME,Plc->FullName);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2015-04-11 23:46:21 +02:00
|
|
|
|
/***** Send button and end frame *****/
|
2015-04-12 18:01:06 +02:00
|
|
|
|
Lay_EndRoundFrameTableWithButton (Lay_CREATE_BUTTON,Txt_Create_place);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2015-04-11 23:46:21 +02:00
|
|
|
|
/***** End formn *****/
|
2015-03-13 00:16:02 +01:00
|
|
|
|
Act_FormEnd ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************** Write header with fields of a place ********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void Plc_PutHeadPlaces (void)
|
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_Code;
|
2015-02-04 20:03:23 +01:00
|
|
|
|
extern const char *Txt_Short_name;
|
|
|
|
|
extern const char *Txt_Full_name;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
extern const char *Txt_Centres;
|
|
|
|
|
|
|
|
|
|
fprintf (Gbl.F.Out,"<tr>"
|
2015-09-05 19:19:39 +02:00
|
|
|
|
"<th class=\"BM\"></th>"
|
2015-09-06 20:02:14 +02:00
|
|
|
|
"<th class=\"RIGHT_MIDDLE\">"
|
2014-12-23 22:47:09 +01:00
|
|
|
|
"%s"
|
2015-09-05 19:19:39 +02:00
|
|
|
|
"</th>"
|
2015-09-06 20:02:14 +02:00
|
|
|
|
"<th class=\"LEFT_MIDDLE\">"
|
2014-12-23 22:47:09 +01:00
|
|
|
|
"%s"
|
2015-09-05 19:19:39 +02:00
|
|
|
|
"</th>"
|
2015-09-06 20:02:14 +02:00
|
|
|
|
"<th class=\"LEFT_MIDDLE\">"
|
2014-12-23 22:47:09 +01:00
|
|
|
|
"%s"
|
2015-09-05 19:19:39 +02:00
|
|
|
|
"</th>"
|
2015-09-06 20:02:14 +02:00
|
|
|
|
"<th class=\"RIGHT_MIDDLE\">"
|
2014-12-23 22:47:09 +01:00
|
|
|
|
"%s"
|
2015-09-05 19:19:39 +02:00
|
|
|
|
"</th>"
|
2014-12-01 23:55:08 +01:00
|
|
|
|
"</tr>",
|
|
|
|
|
Txt_Code,
|
2015-02-04 20:03:23 +01:00
|
|
|
|
Txt_Short_name,
|
|
|
|
|
Txt_Full_name,
|
2014-12-01 23:55:08 +01:00
|
|
|
|
Txt_Centres);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************* Receive form to create a new place **********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Plc_RecFormNewPlace (void)
|
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_The_place_X_already_exists;
|
|
|
|
|
extern const char *Txt_You_must_specify_the_short_name_and_the_full_name_of_the_new_place;
|
|
|
|
|
struct Place *Plc;
|
|
|
|
|
|
|
|
|
|
Plc = &Gbl.Plcs.EditingPlc;
|
|
|
|
|
|
|
|
|
|
/***** Get parameters from form *****/
|
|
|
|
|
/* Get place short name */
|
2017-03-07 19:55:29 +01:00
|
|
|
|
Par_GetParToText ("ShortName",Plc->ShrtName,Plc_MAX_BYTES_PLACE_SHRT_NAME);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/* Get place full name */
|
2017-03-07 19:55:29 +01:00
|
|
|
|
Par_GetParToText ("FullName",Plc->FullName,Plc_MAX_BYTES_PLACE_FULL_NAME);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2016-10-28 10:03:37 +02:00
|
|
|
|
if (Plc->ShrtName[0] && Plc->FullName[0]) // If there's a place name
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
|
|
|
|
/***** If name of place was in database... *****/
|
2016-10-28 10:03:37 +02:00
|
|
|
|
if (Plc_CheckIfPlaceNameExists ("ShortName",Plc->ShrtName,-1L))
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
|
|
|
|
sprintf (Gbl.Message,Txt_The_place_X_already_exists,
|
2016-10-28 10:03:37 +02:00
|
|
|
|
Plc->ShrtName);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
Lay_ShowAlert (Lay_WARNING,Gbl.Message);
|
|
|
|
|
}
|
|
|
|
|
else if (Plc_CheckIfPlaceNameExists ("FullName",Plc->FullName,-1L))
|
|
|
|
|
{
|
|
|
|
|
sprintf (Gbl.Message,Txt_The_place_X_already_exists,
|
|
|
|
|
Plc->FullName);
|
|
|
|
|
Lay_ShowAlert (Lay_WARNING,Gbl.Message);
|
|
|
|
|
}
|
|
|
|
|
else // Add new place to database
|
|
|
|
|
Plc_CreatePlace (Plc);
|
|
|
|
|
}
|
|
|
|
|
else // If there is not a place name
|
|
|
|
|
Lay_ShowAlert (Lay_WARNING,Txt_You_must_specify_the_short_name_and_the_full_name_of_the_new_place);
|
|
|
|
|
|
|
|
|
|
/***** Show the form again *****/
|
|
|
|
|
Plc_EditPlaces ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/**************************** Create a new place *****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void Plc_CreatePlace (struct Place *Plc)
|
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_Created_new_place_X;
|
2017-03-13 13:33:45 +01:00
|
|
|
|
char Query[256 +
|
|
|
|
|
Plc_MAX_BYTES_PLACE_SHRT_NAME +
|
|
|
|
|
Plc_MAX_BYTES_PLACE_FULL_NAME];
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Create a new place *****/
|
2017-03-13 13:17:53 +01:00
|
|
|
|
sprintf (Query,"INSERT INTO places"
|
|
|
|
|
" (InsCod,ShortName,FullName)"
|
2017-03-13 13:33:45 +01:00
|
|
|
|
" VALUES"
|
|
|
|
|
" ('%ld','%s','%s')",
|
2016-10-28 10:03:37 +02:00
|
|
|
|
Gbl.CurrentIns.Ins.InsCod,Plc->ShrtName,Plc->FullName);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
DB_QueryINSERT (Query,"can not create place");
|
|
|
|
|
|
|
|
|
|
/***** Write success message *****/
|
|
|
|
|
sprintf (Gbl.Message,Txt_Created_new_place_X,
|
|
|
|
|
Plc->FullName);
|
|
|
|
|
Lay_ShowAlert (Lay_SUCCESS,Gbl.Message);
|
|
|
|
|
}
|