swad-core/swad_holiday.c

1217 lines
41 KiB
C
Raw Normal View History

2014-12-01 23:55:08 +01:00
// swad_holiday.c: holidays
/*
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.
2018-04-24 13:21:53 +02:00
Copyright (C) 1999-2018 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 ***********************************/
/*****************************************************************************/
2018-10-22 10:21:34 +02:00
#define _GNU_SOURCE // For asprintf
2014-12-01 23:55:08 +01:00
#include <linux/stddef.h> // For NULL
2018-10-22 10:21:34 +02:00
#include <stdio.h> // For asprintf
2014-12-01 23:55:08 +01:00
#include <stdlib.h> // For calloc
#include <string.h> // For string functions
2017-06-10 21:38:10 +02:00
#include "swad_box.h"
2014-12-01 23:55:08 +01:00
#include "swad_database.h"
#include "swad_global.h"
#include "swad_holiday.h"
#include "swad_parameter.h"
2017-06-11 20:09:59 +02:00
#include "swad_table.h"
2014-12-01 23:55:08 +01:00
#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 Hld_GetParamHldOrder (void);
2016-03-19 01:02:52 +01:00
static void Hld_PutIconToEditHlds (void);
2016-11-28 14:48:16 +01:00
static void Hld_GetDataOfHolidayByCod (struct Holiday *Hld);
2014-12-01 23:55:08 +01:00
static Hld_HolidayType_t Hld_GetParamHldType (void);
static Hld_HolidayType_t Hld_GetTypeOfHoliday (const char *UnsignedStr);
static void Hld_ListHolidaysForEdition (void);
static void Hld_PutParamHldCod (long HldCod);
static void Hld_ChangeDate (Hld_StartOrEndDate_t StartOrEndDate);
static void Hld_PutFormToCreateHoliday (void);
static void Hld_PutHeadHolidays (void);
static void Hld_CreateHoliday (struct Holiday *Hld);
/*****************************************************************************/
/*************************** List all the holidays ***************************/
/*****************************************************************************/
void Hld_SeeHolidays (void)
{
2016-11-28 14:48:16 +01:00
extern const char *Hlp_INSTITUTION_Holidays;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Holidays;
extern const char *Txt_HOLIDAYS_HELP_ORDER[2];
extern const char *Txt_HOLIDAYS_ORDER[2];
extern const char *Txt_End_date;
extern const char *Txt_Holiday;
extern const char *Txt_All_places;
2017-03-26 23:16:51 +02:00
extern const char *Txt_No_holidays;
2017-03-27 13:38:10 +02:00
extern const char *Txt_New_holiday;
2017-01-29 12:42:19 +01:00
Hld_Order_t Order;
2014-12-01 23:55:08 +01:00
unsigned NumHld;
2017-05-05 02:03:28 +02:00
char StrDate[Cns_MAX_BYTES_DATE + 1];
2014-12-01 23:55:08 +01:00
if (Gbl.CurrentIns.Ins.InsCod > 0)
{
/***** Get parameter with the type of order in the list of holidays *****/
2017-01-29 12:42:19 +01:00
Hld_GetParamHldOrder ();
2014-12-01 23:55:08 +01:00
/***** Get list of holidays *****/
Hld_GetListHolidays ();
/***** Table head *****/
2017-06-10 21:38:10 +02:00
Box_StartBox (NULL,Txt_Holidays,
2017-06-11 22:26:40 +02:00
Gbl.Usrs.Me.Role.Logged >= Rol_INS_ADM ? Hld_PutIconToEditHlds :
NULL,
2017-06-12 15:03:29 +02:00
Hlp_INSTITUTION_Holidays,Box_NOT_CLOSABLE);
2017-03-25 22:34:15 +01:00
if (Gbl.Hlds.Num)
{
2017-06-11 20:09:59 +02:00
Tbl_StartTableWideMargin (2);
2017-05-01 12:36:24 +02:00
fprintf (Gbl.F.Out,"<tr>");
2017-03-25 22:34:15 +01:00
for (Order = Hld_ORDER_BY_PLACE;
Order <= Hld_ORDER_BY_START_DATE;
Order++)
2014-12-01 23:55:08 +01:00
{
2017-03-25 22:34:15 +01:00
fprintf (Gbl.F.Out,"<th class=\"LEFT_MIDDLE\">");
2018-10-15 14:07:12 +02:00
Act_StartForm (ActSeeHld);
2017-03-25 22:34:15 +01:00
Par_PutHiddenParamUnsigned ("Order",(unsigned) Order);
Act_LinkFormSubmit (Txt_HOLIDAYS_HELP_ORDER[Order],"TIT_TBL",NULL);
if (Order == Gbl.Hlds.SelectedOrder)
fprintf (Gbl.F.Out,"<u>");
fprintf (Gbl.F.Out,"%s",Txt_HOLIDAYS_ORDER[Order]);
if (Order == Gbl.Hlds.SelectedOrder)
fprintf (Gbl.F.Out,"</u>");
fprintf (Gbl.F.Out,"</a>");
2018-10-15 14:07:12 +02:00
Act_EndForm ();
2017-03-25 22:34:15 +01:00
fprintf (Gbl.F.Out,"</th>");
2014-12-01 23:55:08 +01:00
}
2017-03-25 22:34:15 +01:00
fprintf (Gbl.F.Out,"<th class=\"LEFT_MIDDLE\">"
"&nbsp;%s&nbsp;"
"</th>"
"<th class=\"LEFT_MIDDLE\">"
"%s"
"</th>"
2014-12-01 23:55:08 +01:00
"</tr>",
2017-03-25 22:34:15 +01:00
Txt_End_date,
Txt_Holiday);
/***** Write all the holidays *****/
for (NumHld = 0;
NumHld < Gbl.Hlds.Num;
NumHld++)
{
/* Write data of this holiday */
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"DAT LEFT_MIDDLE\">"
"%s"
"</td>",
Gbl.Hlds.Lst[NumHld].PlcCod <= 0 ? Txt_All_places :
Gbl.Hlds.Lst[NumHld].PlaceFullName);
2017-05-05 02:03:28 +02:00
Dat_ConvDateToDateStr (&Gbl.Hlds.Lst[NumHld].StartDate,StrDate);
2017-03-25 22:34:15 +01:00
fprintf (Gbl.F.Out,"<td class=\"DAT LEFT_MIDDLE\">"
2017-05-05 02:03:28 +02:00
"&nbsp;%s"
2017-03-25 22:34:15 +01:00
"</td>",
2017-05-05 02:03:28 +02:00
StrDate);
2017-03-25 22:34:15 +01:00
fprintf (Gbl.F.Out,"<td class=\"DAT LEFT_MIDDLE\">"
"&nbsp;");
switch (Gbl.Hlds.Lst[NumHld].HldTyp)
{
case Hld_HOLIDAY:
break;
case Hld_NON_SCHOOL_PERIOD:
2017-05-05 02:03:28 +02:00
Dat_ConvDateToDateStr (&Gbl.Hlds.Lst[NumHld].EndDate,StrDate);
fprintf (Gbl.F.Out,"%s",StrDate);
2017-03-25 22:34:15 +01:00
break;
}
fprintf (Gbl.F.Out,"</td>"
"<td class=\"DAT LEFT_MIDDLE\">"
"&nbsp;%s"
"</td>"
"</tr>",
Gbl.Hlds.Lst[NumHld].Name);
}
2017-06-11 20:09:59 +02:00
Tbl_EndTable ();
2017-03-25 22:34:15 +01:00
}
else // No holidays created in the current institution
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_INFO,Txt_No_holidays);
2017-03-25 22:34:15 +01:00
/***** Button to create centre *****/
2017-06-04 18:18:54 +02:00
if (Gbl.Usrs.Me.Role.Logged >= Rol_INS_ADM) // Institution admin or system admin
2017-03-25 22:34:15 +01:00
{
2018-10-15 14:07:12 +02:00
Act_StartForm (ActEdiHld);
2017-06-11 19:02:40 +02:00
Btn_PutConfirmButton (Txt_New_holiday);
2018-10-15 14:07:12 +02:00
Act_EndForm ();
2014-12-01 23:55:08 +01:00
}
2017-06-12 14:16:33 +02:00
/***** End table and box *****/
2017-06-10 21:38:10 +02:00
Box_EndBoxTable ();
2014-12-01 23:55:08 +01:00
/***** Free list of holidays *****/
Hld_FreeListHolidays ();
}
}
/*****************************************************************************/
/********* Get parameter with the type or order in list of holidays **********/
/*****************************************************************************/
2017-01-29 12:42:19 +01:00
static void Hld_GetParamHldOrder (void)
2014-12-01 23:55:08 +01:00
{
2017-01-29 12:42:19 +01:00
Gbl.Hlds.SelectedOrder = (Hld_Order_t)
2017-01-29 21:41:08 +01:00
Par_GetParToUnsignedLong ("Order",
0,
Hld_NUM_ORDERS - 1,
(unsigned long) Hld_DEFAULT_ORDER_TYPE);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
2016-03-19 01:02:52 +01:00
/************************* Put icon to edit holidays *************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-03-19 01:02:52 +01:00
static void Hld_PutIconToEditHlds (void)
2014-12-01 23:55:08 +01:00
{
2017-06-11 19:13:28 +02:00
Ico_PutContextualIconToEdit (ActEdiHld,NULL);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************ Put forms to edit degree types *********************/
/*****************************************************************************/
void Hld_EditHolidays (void)
{
/***** Get list of places *****/
Plc_GetListPlaces ();
/***** Get list of holidays *****/
Hld_GetListHolidays ();
/***** Put a form to create a new holiday *****/
Hld_PutFormToCreateHoliday ();
/***** Forms to edit current holidays *****/
if (Gbl.Hlds.Num)
Hld_ListHolidaysForEdition ();
/***** Free list of holidays *****/
Hld_FreeListHolidays ();
/***** Free list of places *****/
Plc_FreeListPlaces ();
}
/*****************************************************************************/
/*************************** List all the holidays ***************************/
/*****************************************************************************/
void Hld_GetListHolidays (void)
{
char OrderBySubQuery[256];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumHld;
struct Holiday *Hld;
if (Gbl.DB.DatabaseIsOpen)
{
if (Gbl.Hlds.LstIsRead)
Hld_FreeListHolidays ();
/***** Get holidays from database *****/
2017-01-29 12:42:19 +01:00
switch (Gbl.Hlds.SelectedOrder)
2014-12-01 23:55:08 +01:00
{
case Hld_ORDER_BY_PLACE:
sprintf (OrderBySubQuery,"Place,StartDate");
break;
case Hld_ORDER_BY_START_DATE:
sprintf (OrderBySubQuery,"StartDate,Place");
break;
}
2018-10-31 13:00:40 +01:00
Gbl.Hlds.Num =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get holidays",
"(SELECT holidays.HldCod,"
"holidays.PlcCod,"
"places.FullName as Place,"
"holidays.HldTyp,"
"DATE_FORMAT(holidays.StartDate,'%%Y%%m%%d') AS StartDate,"
"DATE_FORMAT(holidays.EndDate,'%%Y%%m%%d') AS EndDate,"
"holidays.Name"
" FROM holidays,places"
" WHERE holidays.InsCod=%ld"
" AND holidays.PlcCod=places.PlcCod"
" AND places.InsCod=%ld)"
" UNION "
"(SELECT HldCod,"
"PlcCod,"
"'' as Place,"
"HldTyp,"
"DATE_FORMAT(StartDate,'%%Y%%m%%d') AS StartDate,"
"DATE_FORMAT(EndDate,'%%Y%%m%%d') AS EndDate,"
"Name"
" FROM holidays"
" WHERE InsCod=%ld"
" AND PlcCod NOT IN"
"(SELECT DISTINCT PlcCod FROM places"
" WHERE InsCod=%ld))"
" ORDER BY %s",
Gbl.CurrentIns.Ins.InsCod,
Gbl.CurrentIns.Ins.InsCod,
Gbl.CurrentIns.Ins.InsCod,
Gbl.CurrentIns.Ins.InsCod,
OrderBySubQuery);
if (Gbl.Hlds.Num) // Holidays found...
2014-12-01 23:55:08 +01:00
{
/***** Create list of holidays *****/
if ((Gbl.Hlds.Lst = (struct Holiday *) calloc ((size_t) Gbl.Hlds.Num,sizeof (struct Holiday))) == NULL)
2018-10-18 20:06:54 +02:00
Lay_NotEnoughMemoryExit ();
2014-12-01 23:55:08 +01:00
/***** Get the holidays *****/
for (NumHld = 0;
NumHld < Gbl.Hlds.Num;
NumHld++)
{
Hld = &(Gbl.Hlds.Lst[NumHld]);
/* Get next holiday */
row = mysql_fetch_row (mysql_res);
/* Get holiday code (row[0]) */
if ((Hld->HldCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong holiday code.");
/* Get place code (row[1]) */
Hld->PlcCod = Str_ConvertStrCodToLongCod (row[1]);
/* Get the full name of the place (row[2]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Hld->PlaceFullName,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 type (row[3]) */
Hld->HldTyp = Hld_GetTypeOfHoliday (row[3]);
/* Get start date (row[4] holds the start date in YYYYMMDD format) */
if (!(Dat_GetDateFromYYYYMMDD (&(Hld->StartDate),row[4])))
Lay_ShowErrorAndExit ("Wrong start date.");
2016-11-28 14:48:16 +01:00
/* Set / get end date */
switch (Hld->HldTyp)
{
case Hld_HOLIDAY: // Only one day
/* Set end date = start date */
Dat_AssignDate (&Hld->EndDate,&Hld->StartDate);
break;
case Hld_NON_SCHOOL_PERIOD: // One or more days
/* Get end date (row[5] holds the end date in YYYYMMDD format) */
if (!(Dat_GetDateFromYYYYMMDD (&(Hld->EndDate),row[5])))
Lay_ShowErrorAndExit ("Wrong end date.");
break;
}
2014-12-01 23:55:08 +01:00
/* Get the name of the holiday/non school period (row[6]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Hld->Name,row[6],
2017-03-07 19:55:29 +01:00
Hld_MAX_BYTES_HOLIDAY_NAME);
2014-12-01 23:55:08 +01:00
}
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
Gbl.Hlds.LstIsRead = true;
}
}
/*****************************************************************************/
2016-11-28 14:48:16 +01:00
/************************* Get holiday data by code **************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
2016-11-28 14:48:16 +01:00
static void Hld_GetDataOfHolidayByCod (struct Holiday *Hld)
2014-12-01 23:55:08 +01:00
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
/***** Clear data *****/
Hld->PlcCod = -1L;
Hld->PlaceFullName[0] = '\0';
Hld->StartDate.Day =
Hld->StartDate.Month =
Hld->StartDate.Year = 0;
Hld->Name[0] = '\0';
/***** Check if holiday code is correct *****/
if (Hld->HldCod <= 0)
Lay_ShowErrorAndExit ("Wrong code of holiday.");
/***** Get data of holiday from database *****/
2018-10-31 13:00:40 +01:00
if (DB_QuerySELECT (&mysql_res,"can not get data of a holiday",
"(SELECT holidays.PlcCod,"
"places.FullName as Place,"
"holidays.HldTyp,"
"DATE_FORMAT(holidays.StartDate,'%%Y%%m%%d'),"
"DATE_FORMAT(holidays.EndDate,'%%Y%%m%%d'),"
"holidays.Name"
" FROM holidays,places"
" WHERE holidays.HldCod=%ld"
" AND holidays.InsCod=%ld"
" AND holidays.PlcCod=places.PlcCod"
" AND places.InsCod=%ld)"
" UNION "
"(SELECT PlcCod,"
"'' as Place,"
"HldTyp,"
"DATE_FORMAT(StartDate,'%%Y%%m%%d'),"
"DATE_FORMAT(EndDate,'%%Y%%m%%d'),"
"Name"
" FROM holidays"
" WHERE HldCod=%ld"
" AND InsCod=%ld"
" AND PlcCod NOT IN"
"(SELECT DISTINCT PlcCod FROM places"
" WHERE InsCod=%ld))",
Hld->HldCod,
Gbl.CurrentIns.Ins.InsCod,
Gbl.CurrentIns.Ins.InsCod,
Hld->HldCod,
Gbl.CurrentIns.Ins.InsCod,
Gbl.CurrentIns.Ins.InsCod)) // Holiday found...
2014-12-01 23:55:08 +01:00
{
/* Get row */
row = mysql_fetch_row (mysql_res);
/* Get place code (row[0]) */
Hld->PlcCod = Str_ConvertStrCodToLongCod (row[0]);
/* Get the full name of the place (row[1]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Hld->PlaceFullName,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 type (row[2]) */
Hld->HldTyp = Hld_GetTypeOfHoliday (row[2]);
/* Get start date (row[3] holds the start date in YYYYMMDD format) */
if (!(Dat_GetDateFromYYYYMMDD (&(Hld->StartDate),row[3])))
Lay_ShowErrorAndExit ("Wrong start date.");
2016-11-28 14:48:16 +01:00
/* Set / get end date */
switch (Hld->HldTyp)
{
case Hld_HOLIDAY: // Only one day
/* Assign end date = start date */
Dat_AssignDate (&Hld->EndDate,&Hld->StartDate);
break;
case Hld_NON_SCHOOL_PERIOD: // One or more days
/* Get end date (row[4] holds the end date in YYYYMMDD format) */
if (!(Dat_GetDateFromYYYYMMDD (&(Hld->EndDate),row[4])))
Lay_ShowErrorAndExit ("Wrong end date.");
break;
}
2014-12-01 23:55:08 +01:00
/* Get the name of the holiday/non school period (row[5]) */
2017-01-17 03:10:43 +01:00
Str_Copy (Hld->Name,row[5],
2017-03-07 19:55:29 +01:00
Hld_MAX_BYTES_HOLIDAY_NAME);
2014-12-01 23:55:08 +01:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/************ Get parameter from form with the type of a holiday *************/
/*****************************************************************************/
static Hld_HolidayType_t Hld_GetParamHldType (void)
{
2017-01-29 21:41:08 +01:00
return (Hld_HolidayType_t)
Par_GetParToUnsignedLong ("HldTyp",
0,
Hld_NUM_TYPES_HOLIDAY - 1,
(unsigned long) Hld_HOLIDAY_TYPE_DEFAULT);
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/********************* Get type of holiday from string ***********************/
/*****************************************************************************/
static Hld_HolidayType_t Hld_GetTypeOfHoliday (const char *UnsignedStr)
{
unsigned UnsignedNum;
if (sscanf (UnsignedStr,"%u",&UnsignedNum) != 1)
Lay_ShowErrorAndExit ("Wrong type of holiday.");
if (UnsignedNum >= Hld_NUM_TYPES_HOLIDAY)
Lay_ShowErrorAndExit ("Wrong type of holiday.");
return (Hld_HolidayType_t) UnsignedNum;
}
/*****************************************************************************/
/**************************** Free list of holidays **************************/
/*****************************************************************************/
void Hld_FreeListHolidays (void)
{
if (Gbl.Hlds.LstIsRead && Gbl.Hlds.Lst)
{
/***** Free memory used by the list of courses in degree *****/
free ((void *) Gbl.Hlds.Lst);
Gbl.Hlds.Lst = NULL;
Gbl.Hlds.Num = 0;
Gbl.Hlds.LstIsRead = false;
}
}
/*****************************************************************************/
/********************* List all the holidays for edition *********************/
/*****************************************************************************/
static void Hld_ListHolidaysForEdition (void)
{
2016-11-28 14:48:16 +01:00
extern const char *Hlp_INSTITUTION_Holidays_edit;
2014-12-01 23:55:08 +01:00
extern const char *Txt_Holidays;
extern const char *Txt_All_places;
extern const char *Txt_HOLIDAY_TYPES[Hld_NUM_TYPES_HOLIDAY];
unsigned NumHld;
unsigned NumPlc;
struct Holiday *Hld;
Hld_HolidayType_t HolidayType;
2017-06-12 14:16:33 +02:00
/***** Start box and table *****/
2017-06-10 21:38:10 +02:00
Box_StartBoxTable (NULL,Txt_Holidays,NULL,
2017-06-12 15:03:29 +02:00
Hlp_INSTITUTION_Holidays_edit,Box_NOT_CLOSABLE,2);
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** Write heading *****/
2014-12-01 23:55:08 +01:00
Hld_PutHeadHolidays ();
/***** Write all the holidays *****/
for (NumHld = 0;
NumHld < Gbl.Hlds.Num;
NumHld++)
{
Hld = &Gbl.Hlds.Lst[NumHld];
/* Put icon to remove holiday */
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"BM\">");
2018-10-15 14:07:12 +02:00
Act_StartForm (ActRemHld);
2014-12-01 23:55:08 +01:00
Hld_PutParamHldCod (Hld->HldCod);
2017-06-11 19:13:28 +02:00
Ico_PutIconRemove ();
2018-10-15 14:07:12 +02:00
Act_EndForm ();
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
/* Holiday code */
2015-08-03 20:22:41 +02:00
fprintf (Gbl.F.Out,"<td class=\"DAT RIGHT_MIDDLE\">"
2014-12-23 01:36:58 +01:00
"%ld&nbsp;"
"</td>",
2014-12-01 23:55:08 +01:00
Hld->HldCod);
/* Holiday place */
2015-08-03 20:22:41 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">");
2018-10-15 14:07:12 +02:00
Act_StartForm (ActChgHldPlc);
2014-12-01 23:55:08 +01:00
Hld_PutParamHldCod (Hld->HldCod);
2015-09-28 18:28:29 +02:00
fprintf (Gbl.F.Out,"<select name=\"PlcCod\" style=\"width:62px;\""
2015-10-22 14:49:48 +02:00
" onchange=\"document.getElementById('%s').submit();\">"
2014-12-01 23:55:08 +01:00
"<option value=\"-1\"",
2016-01-14 10:31:09 +01:00
Gbl.Form.Id);
2014-12-01 23:55:08 +01:00
if (Hld->PlcCod <= 0)
fprintf (Gbl.F.Out," selected=\"selected\"");
fprintf (Gbl.F.Out,">%s</option>",Txt_All_places);
for (NumPlc = 0;
NumPlc < Gbl.Plcs.Num;
NumPlc++)
fprintf (Gbl.F.Out,"<option value=\"%ld\"%s>%s</option>",
Gbl.Plcs.Lst[NumPlc].PlcCod,
Gbl.Plcs.Lst[NumPlc].PlcCod == Hld->PlcCod ? " selected=\"selected\"" :
"",
2016-10-28 10:03:37 +02:00
Gbl.Plcs.Lst[NumPlc].ShrtName);
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</select>");
2018-10-15 14:07:12 +02:00
Act_EndForm ();
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
/* Holiday type */
2015-08-03 20:22:41 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">");
2018-10-15 14:07:12 +02:00
Act_StartForm (ActChgHldTyp);
2014-12-01 23:55:08 +01:00
Hld_PutParamHldCod (Hld->HldCod);
2015-09-28 18:28:29 +02:00
fprintf (Gbl.F.Out,"<select name=\"HldTyp\" style=\"width:62px;\""
2015-10-22 14:49:48 +02:00
" onchange=\"document.getElementById('%s').submit();\">",
2016-01-14 10:31:09 +01:00
Gbl.Form.Id);
2014-12-01 23:55:08 +01:00
for (HolidayType = (Hld_HolidayType_t) 0;
HolidayType < Hld_NUM_TYPES_HOLIDAY;
HolidayType++)
fprintf (Gbl.F.Out,"<option value=\"%u\"%s>%s</option>",
(unsigned) HolidayType,
HolidayType == Hld->HldTyp ? " selected=\"selected\"" :
"",
Txt_HOLIDAY_TYPES[HolidayType]);
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</select>");
2018-10-15 14:07:12 +02:00
Act_EndForm ();
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
/* Holiday date / Non school period start date */
2015-08-03 20:22:41 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">");
2018-10-15 14:07:12 +02:00
Act_StartForm (ActChgHldStrDat);
2014-12-01 23:55:08 +01:00
Hld_PutParamHldCod (Hld->HldCod);
2015-10-23 01:06:32 +02:00
Dat_WriteFormDate (Gbl.Now.Date.Year - 1,
Gbl.Now.Date.Year + 1,
"Start",
2014-12-01 23:55:08 +01:00
&(Gbl.Hlds.Lst[NumHld].StartDate),
true,false);
2018-10-15 14:07:12 +02:00
Act_EndForm ();
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
/* Non school period end date */
2015-08-03 20:22:41 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">");
2018-10-15 14:07:12 +02:00
Act_StartForm (ActChgHldEndDat);
2014-12-01 23:55:08 +01:00
Hld_PutParamHldCod (Hld->HldCod);
2015-10-23 01:06:32 +02:00
Dat_WriteFormDate (Gbl.Now.Date.Year - 1,
Gbl.Now.Date.Year + 1,
"End",
2014-12-01 23:55:08 +01:00
&(Gbl.Hlds.Lst[NumHld].EndDate),
true,(Hld->HldTyp == Hld_HOLIDAY));
2018-10-15 14:07:12 +02:00
Act_EndForm ();
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</td>");
2014-12-01 23:55:08 +01:00
/* Holiday name */
2015-08-03 20:22:41 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">");
2018-10-15 14:07:12 +02:00
Act_StartForm (ActRenHld);
2014-12-01 23:55:08 +01:00
Hld_PutParamHldCod (Hld->HldCod);
2015-10-22 14:49:48 +02:00
fprintf (Gbl.F.Out,"<input type=\"text\" name=\"Name\""
" size=\"20\" maxlength=\"%u\" value=\"%s\""
" onchange=\"document.getElementById('%s').submit();\" />",
2017-03-07 19:55:29 +01:00
Hld_MAX_CHARS_HOLIDAY_NAME,Hld->Name,Gbl.Form.Id);
2018-10-15 14:07:12 +02:00
Act_EndForm ();
2015-03-13 00:16:02 +01:00
fprintf (Gbl.F.Out,"</td>"
"</tr>");
2014-12-01 23:55:08 +01:00
}
2017-06-12 14:16:33 +02:00
/***** End table and box *****/
2017-06-10 21:38:10 +02:00
Box_EndBoxTable ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************** Write parameter with code of holiday *******************/
/*****************************************************************************/
static void Hld_PutParamHldCod (long HldCod)
{
Par_PutHiddenParamLong ("HldCod",HldCod);
}
/*****************************************************************************/
/********************* Get parameter with code of holiday ********************/
/*****************************************************************************/
long Hld_GetParamHldCod (void)
{
2017-01-28 20:32:50 +01:00
/***** Get code of holiday *****/
return Par_GetParToLong ("HldCod");
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************************* Remove a holiday ****************************/
/*****************************************************************************/
2017-03-26 01:57:43 +01:00
void Hld_RemoveHoliday1 (void)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_Holiday_X_removed;
struct Holiday Hld;
/***** Get holiday code *****/
if ((Hld.HldCod = Hld_GetParamHldCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of holiday is missing.");
/***** Get data of the holiday from database *****/
Hld_GetDataOfHolidayByCod (&Hld);
/***** Remove holiday *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove a holiday",
"DELETE FROM holidays WHERE HldCod=%ld",
Hld.HldCod);
2014-12-01 23:55:08 +01:00
/***** Write message to show the change made *****/
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_SUCCESS;
2018-10-16 23:08:04 +02:00
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
2018-10-16 21:56:01 +02:00
Txt_Holiday_X_removed,
Hld.Name);
2017-03-26 01:57:43 +01:00
}
void Hld_RemoveHoliday2 (void)
{
/***** Show success message *****/
2017-05-11 23:45:46 +02:00
Ale_ShowPendingAlert ();
2014-12-01 23:55:08 +01:00
/***** Show the form again *****/
Hld_EditHolidays ();
}
/*****************************************************************************/
/************************* Change the place of a holiday *********************/
/*****************************************************************************/
2017-03-26 03:10:07 +02:00
void Hld_ChangeHolidayPlace1 (void)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_The_place_of_the_holiday_X_has_changed_to_Y;
struct Holiday *Hld;
struct Place NewPlace;
Hld = &Gbl.Hlds.EditingHld;
/***** Get parameters from form *****/
/* Get the code of the holiday */
if ((Hld->HldCod = Hld_GetParamHldCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of holiday is missing.");
/* Get the new place for the holiday */
NewPlace.PlcCod = Plc_GetParamPlcCod ();
/***** Get from the database the data of the place *****/
Plc_GetDataOfPlaceByCod (&NewPlace);
/***** Get from the database the data of the holiday *****/
Hld_GetDataOfHolidayByCod (Hld);
/***** Update the place in database *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the place of a holiday",
"UPDATE holidays SET PlcCod=%ld WHERE HldCod=%ld",
NewPlace.PlcCod,Hld->HldCod);
2017-03-26 03:10:07 +02:00
Hld->PlcCod = NewPlace.PlcCod;
Str_Copy (Hld->PlaceFullName,NewPlace.FullName,
Plc_MAX_BYTES_PLACE_FULL_NAME);
2014-12-01 23:55:08 +01:00
/***** Write message to show the change made *****/
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_SUCCESS;
2018-10-16 23:08:04 +02:00
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
2018-10-16 21:56:01 +02:00
Txt_The_place_of_the_holiday_X_has_changed_to_Y,
Hld->Name,NewPlace.FullName);
2017-03-26 03:10:07 +02:00
}
void Hld_ChangeHolidayPlace2 (void)
{
/***** Show success message *****/
2017-05-11 23:45:46 +02:00
Ale_ShowPendingAlert ();
2014-12-01 23:55:08 +01:00
/***** Show the form again *****/
Hld_EditHolidays ();
}
/*****************************************************************************/
/************************* Change the type of a holiday **********************/
/*****************************************************************************/
2017-03-26 01:51:00 +01:00
void Hld_ChangeHolidayType1 (void)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_The_type_of_the_holiday_X_has_changed;
struct Holiday *Hld;
Hld = &Gbl.Hlds.EditingHld;
/***** Get the code of the holiday *****/
if ((Hld->HldCod = Hld_GetParamHldCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of holiday is missing.");
/***** Get from the database the data of the holiday *****/
Hld_GetDataOfHolidayByCod (Hld);
/***** Get the new type for the holiday *****/
Hld->HldTyp = Hld_GetParamHldType ();
/***** Update holiday/no school period in database *****/
2016-11-28 14:48:16 +01:00
Dat_AssignDate (&Hld->EndDate,&Hld->StartDate);
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the type of a holiday",
"UPDATE holidays SET HldTyp=%u,EndDate=StartDate"
" WHERE HldCod=%ld",
(unsigned) Hld->HldTyp,Hld->HldCod);
2014-12-01 23:55:08 +01:00
/***** Write message to show the change made *****/
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_SUCCESS;
2018-10-16 23:08:04 +02:00
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
2018-10-16 21:56:01 +02:00
Txt_The_type_of_the_holiday_X_has_changed,
Hld->Name);
2017-03-26 01:51:00 +01:00
}
void Hld_ChangeHolidayType2 (void)
{
/***** Show success message *****/
2017-05-11 23:45:46 +02:00
Ale_ShowPendingAlert ();
2014-12-01 23:55:08 +01:00
/***** Show the form again *****/
Hld_EditHolidays ();
}
/*****************************************************************************/
/*** Change the date of a holiday / the start date of a non school period ****/
/*****************************************************************************/
2017-03-26 01:44:27 +01:00
void Hld_ChangeStartDate1 (void)
2014-12-01 23:55:08 +01:00
{
Hld_ChangeDate (HLD_START_DATE);
}
/*****************************************************************************/
/*************** Change the end date of a non school period ******************/
/*****************************************************************************/
2017-03-26 01:44:27 +01:00
void Hld_ChangeEndDate1 (void)
2014-12-01 23:55:08 +01:00
{
Hld_ChangeDate (HLD_END_DATE);
}
/*****************************************************************************/
/**************** Change the start/end date of a holiday *********************/
/*****************************************************************************/
static void Hld_ChangeDate (Hld_StartOrEndDate_t StartOrEndDate)
{
extern const char *Txt_The_date_of_the_holiday_X_has_changed_to_Y;
struct Holiday *Hld;
struct Date NewDate;
2016-12-05 23:13:58 +01:00
struct Date *PtrDate = NULL; // Initialized to avoid warning
const char *StrStartOrEndDate = NULL; // Initialized to avoid warning
2017-05-05 02:03:28 +02:00
char StrDate[Cns_MAX_BYTES_DATE + 1];
2014-12-01 23:55:08 +01:00
Hld = &Gbl.Hlds.EditingHld;
/***** Get the code of the holiday *****/
if ((Hld->HldCod = Hld_GetParamHldCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of holiday is missing.");
/***** Get from the database the data of the holiday *****/
Hld_GetDataOfHolidayByCod (Hld);
/***** Get the new date for the holiday *****/
switch (StartOrEndDate)
{
case HLD_START_DATE:
StrStartOrEndDate = "StartDate";
PtrDate = &(Hld->StartDate);
Dat_GetDateFromForm ("StartDay","StartMonth","StartYear",
&(NewDate.Day),&(NewDate.Month),&(NewDate.Year));
2016-11-28 14:48:16 +01:00
if (NewDate.Day == 0 ||
NewDate.Month == 0 ||
NewDate.Year == 0)
Dat_AssignDate (&NewDate,&Gbl.Now.Date);
2014-12-01 23:55:08 +01:00
break;
2016-11-28 14:48:16 +01:00
case HLD_END_DATE:
2014-12-01 23:55:08 +01:00
StrStartOrEndDate = "EndDate";
PtrDate = &(Hld->EndDate);
switch (Hld->HldTyp)
{
case Hld_HOLIDAY:
2016-11-28 14:48:16 +01:00
Dat_AssignDate (&NewDate,&Hld->StartDate);
2014-12-01 23:55:08 +01:00
break;
case Hld_NON_SCHOOL_PERIOD:
Dat_GetDateFromForm ("EndDay","EndMonth","EndYear",
&(NewDate.Day),&(NewDate.Month),&(NewDate.Year));
2016-11-28 14:48:16 +01:00
if (NewDate.Day == 0 ||
NewDate.Month == 0 ||
NewDate.Year == 0)
Dat_AssignDate (&NewDate,&Gbl.Now.Date);
2014-12-01 23:55:08 +01:00
break;
}
break;
}
/***** Update the date in database *****/
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the date of a holiday",
"UPDATE holidays SET %s='%04u%02u%02u' WHERE HldCod=%ld",
StrStartOrEndDate,
NewDate.Year,
NewDate.Month,
NewDate.Day,
Hld->HldCod);
2017-03-26 01:44:27 +01:00
Dat_AssignDate (PtrDate,&NewDate);
2014-12-01 23:55:08 +01:00
/***** Write message to show the change made *****/
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_SUCCESS;
2017-05-05 02:03:28 +02:00
Dat_ConvDateToDateStr (&NewDate,StrDate);
2018-10-16 23:08:04 +02:00
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
2018-10-16 21:56:01 +02:00
Txt_The_date_of_the_holiday_X_has_changed_to_Y,
Hld->Name,StrDate);
2017-03-26 01:44:27 +01:00
}
/*****************************************************************************/
/*********** Show message and form after changing a holiday date *************/
/*****************************************************************************/
void Hld_ChangeDate2 (void)
{
/***** Show success message *****/
2017-05-11 23:45:46 +02:00
Ale_ShowPendingAlert ();
2014-12-01 23:55:08 +01:00
/***** Show the form again *****/
Hld_EditHolidays ();
}
/*****************************************************************************/
/************************ Change the name of a degree ************************/
/*****************************************************************************/
2017-03-26 01:44:27 +01:00
void Hld_RenameHoliday1 (void)
2014-12-01 23:55:08 +01:00
{
extern const char *Txt_You_can_not_leave_the_name_of_the_holiday_X_empty;
extern const char *Txt_The_name_of_the_holiday_X_has_changed_to_Y;
extern const char *Txt_The_name_of_the_holiday_X_has_not_changed;
struct Holiday *Hld;
2017-03-07 19:55:29 +01:00
char NewHldName[Hld_MAX_BYTES_HOLIDAY_NAME + 1];
2014-12-01 23:55:08 +01:00
Hld = &Gbl.Hlds.EditingHld;
/***** Get parameters from form *****/
/* Get the code of the holiday */
if ((Hld->HldCod = Hld_GetParamHldCod ()) == -1L)
Lay_ShowErrorAndExit ("Code of holiday is missing.");
/* Get the new name for the holiday */
2017-03-07 19:55:29 +01:00
Par_GetParToText ("Name",NewHldName,Hld_MAX_BYTES_HOLIDAY_NAME);
2014-12-01 23:55:08 +01:00
/***** Get from the database the old names of the holiday *****/
Hld_GetDataOfHolidayByCod (Hld);
/***** Check if new name is empty *****/
if (!NewHldName[0])
{
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_WARNING;
2018-10-16 23:08:04 +02:00
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
2018-10-16 21:56:01 +02:00
Txt_You_can_not_leave_the_name_of_the_holiday_X_empty,
Hld->Name);
2014-12-01 23:55:08 +01:00
}
else
{
/***** Check if old and new names are the same (this happens when user press enter with no changes in the form) *****/
if (strcmp (Hld->Name,NewHldName)) // Different names
{
/***** If degree was in database... *****/
/* Update the table changing old name by new name */
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update the text of a holiday",
"UPDATE holidays SET Name='%s' WHERE HldCod=%ld",
NewHldName,Hld->HldCod);
2017-03-26 01:44:27 +01:00
Str_Copy (Hld->Name,NewHldName,
Hld_MAX_BYTES_HOLIDAY_NAME);
2014-12-01 23:55:08 +01:00
/***** Write message to show the change made *****/
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_SUCCESS;
2018-10-16 23:08:04 +02:00
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
2018-10-16 21:56:01 +02:00
Txt_The_name_of_the_holiday_X_has_changed_to_Y,
Hld->Name,NewHldName);
2014-12-01 23:55:08 +01:00
}
else // The same name
{
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_INFO;
2018-10-16 23:08:04 +02:00
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
2018-10-16 21:56:01 +02:00
Txt_The_name_of_the_holiday_X_has_not_changed,
Hld->Name);
2014-12-01 23:55:08 +01:00
}
}
2017-03-26 01:44:27 +01:00
}
void Hld_RenameHoliday2 (void)
{
/***** Write error/success message *****/
2017-05-11 23:45:46 +02:00
Ale_ShowPendingAlert ();
2014-12-01 23:55:08 +01:00
/***** Show the form again *****/
Hld_EditHolidays ();
}
/*****************************************************************************/
/********************* Put a form to create a new holiday ********************/
/*****************************************************************************/
static void Hld_PutFormToCreateHoliday (void)
{
2016-11-28 14:48:16 +01:00
extern const char *Hlp_INSTITUTION_Holidays_edit;
2014-12-01 23:55:08 +01:00
extern const char *Txt_All_places;
extern const char *Txt_New_holiday;
extern const char *Txt_Place;
extern const char *Txt_Type;
2016-12-15 00:39:52 +01:00
extern const char *Txt_START_END_TIME[Dat_NUM_START_END_TIME];
2014-12-01 23:55:08 +01:00
extern const char *Txt_Holiday;
extern const char *Txt_HOLIDAY_TYPES[Hld_NUM_TYPES_HOLIDAY];
extern const char *Txt_Create_holiday;
struct Holiday *Hld;
unsigned NumPlc;
Hld_HolidayType_t HolidayType;
Hld = &Gbl.Hlds.EditingHld;
/***** Start form *****/
2018-10-15 14:07:12 +02:00
Act_StartForm (ActNewHld);
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** Start box and table *****/
2017-06-10 21:38:10 +02:00
Box_StartBoxTable (NULL,Txt_New_holiday,NULL,
2017-06-12 15:03:29 +02:00
Hlp_INSTITUTION_Holidays_edit,Box_NOT_CLOSABLE,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 01:36:58 +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 01:36:58 +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 01:36:58 +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 01:36:58 +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 01:36:58 +01:00
"%s"
2015-09-05 19:19:39 +02:00
"</th>"
2014-12-01 23:55:08 +01:00
"</tr>",
Txt_Place,
Txt_Type,
2016-12-15 00:39:52 +01:00
Txt_START_END_TIME[Dat_START_TIME],
Txt_START_END_TIME[Dat_END_TIME],
2014-12-01 23:55:08 +01:00
Txt_Holiday);
/***** Holiday place *****/
fprintf (Gbl.F.Out,"<tr>"
2015-08-03 20:22:41 +02:00
"<td class=\"CENTER_MIDDLE\">"
2015-09-28 18:28:29 +02:00
"<select name=\"PlcCod\" style=\"width:62px;\">"
2014-12-01 23:55:08 +01:00
"<option value=\"-1\"");
if (Hld->PlcCod <= 0)
fprintf (Gbl.F.Out," selected=\"selected\"");
fprintf (Gbl.F.Out,">%s</option>",Txt_All_places);
for (NumPlc = 0;
NumPlc < Gbl.Plcs.Num;
NumPlc++)
fprintf (Gbl.F.Out,"<option value=\"%ld\"%s>%s</option>",
Gbl.Plcs.Lst[NumPlc].PlcCod,
Gbl.Plcs.Lst[NumPlc].PlcCod == Hld->PlcCod ? " selected=\"selected\"" :
"",
2016-10-28 10:03:37 +02:00
Gbl.Plcs.Lst[NumPlc].ShrtName);
2014-12-01 23:55:08 +01:00
fprintf (Gbl.F.Out,"</select>"
"</td>");
/***** Holiday type *****/
2015-08-03 20:22:41 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">"
2015-09-28 18:28:29 +02:00
"<select name=\"HldTyp\" style=\"width:62px;\">");
2014-12-01 23:55:08 +01:00
for (HolidayType = (Hld_HolidayType_t) 0;
HolidayType < Hld_NUM_TYPES_HOLIDAY;
HolidayType++)
fprintf (Gbl.F.Out,"<option value=\"%u\"%s>%s</option>",
(unsigned) HolidayType,
HolidayType == Hld->HldTyp ? " selected=\"selected\"" :
"",
Txt_HOLIDAY_TYPES[HolidayType]);
fprintf (Gbl.F.Out,"</select>"
"</td>");
/***** Holiday date / Non school period start date *****/
2015-08-03 20:22:41 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">");
2015-10-23 01:06:32 +02:00
Dat_WriteFormDate (Gbl.Now.Date.Year - 1,
Gbl.Now.Date.Year + 1,
"Start",
2014-12-01 23:55:08 +01:00
&(Hld->StartDate),
false,false);
fprintf (Gbl.F.Out,"</td>");
/***** Non school period end date *****/
2015-08-03 20:22:41 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">");
2015-10-23 01:06:32 +02:00
Dat_WriteFormDate (Gbl.Now.Date.Year - 1,
Gbl.Now.Date.Year + 1,
"End",
2014-12-01 23:55:08 +01:00
&(Hld->EndDate),
false,false);
fprintf (Gbl.F.Out,"</td>");
/***** Holiday name *****/
2015-08-03 20:22:41 +02:00
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">"
2015-10-23 01:31:08 +02:00
"<input type=\"text\" name=\"Name\""
2016-11-19 20:45:46 +01:00
" size=\"20\" maxlength=\"%u\" value=\"%s\""
" required=\"required\" />"
2014-12-01 23:55:08 +01:00
"</td>"
"<td></td>"
"</tr>",
2017-03-07 19:55:29 +01:00
Hld_MAX_CHARS_HOLIDAY_NAME,Hld->Name);
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** End table, send button and end box *****/
2017-06-11 19:02:40 +02:00
Box_EndBoxTableWithButton (Btn_CREATE_BUTTON,Txt_Create_holiday);
2014-12-01 23:55:08 +01:00
2017-06-12 14:16:33 +02:00
/***** End form *****/
2018-10-15 14:07:12 +02:00
Act_EndForm ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/******************* Write header with fields of a holiday *******************/
/*****************************************************************************/
static void Hld_PutHeadHolidays (void)
{
extern const char *Txt_Code;
extern const char *Txt_Place;
extern const char *Txt_Type;
2016-12-15 00:39:52 +01:00
extern const char *Txt_START_END_TIME[Dat_NUM_START_END_TIME];
2014-12-01 23:55:08 +01:00
extern const char *Txt_Holiday;
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 01:36:58 +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 01:36:58 +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 01:36:58 +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 01:36:58 +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 01:36:58 +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 01:36:58 +01:00
"%s"
2015-09-05 19:19:39 +02:00
"</th>"
2014-12-01 23:55:08 +01:00
"</tr>",
Txt_Code,
Txt_Place,
Txt_Type,
2016-12-15 00:39:52 +01:00
Txt_START_END_TIME[Dat_START_TIME],
Txt_START_END_TIME[Dat_END_TIME],
2014-12-01 23:55:08 +01:00
Txt_Holiday);
}
/*****************************************************************************/
/******************* Receive form to create a new holiday ********************/
/*****************************************************************************/
2017-03-26 00:20:34 +01:00
void Hld_RecFormNewHoliday1 (void)
2014-12-01 23:55:08 +01:00
{
2017-03-26 00:20:34 +01:00
extern const char *Txt_Created_new_holiday_X;
2014-12-01 23:55:08 +01:00
extern const char *Txt_You_must_specify_the_name_of_the_new_holiday;
struct Holiday *Hld;
Hld = &Gbl.Hlds.EditingHld;
/***** Get place code *****/
Hld->PlcCod = Plc_GetParamPlcCod ();
/***** Get the type of holiday *****/
Hld->HldTyp = Hld_GetParamHldType ();
/***** Get start date *****/
Dat_GetDateFromForm ("StartDay","StartMonth","StartYear",
&(Hld->StartDate.Day),&(Hld->StartDate.Month),&(Hld->StartDate.Year));
2016-11-28 14:48:16 +01:00
if (Hld->StartDate.Day == 0 ||
Hld->StartDate.Month == 0 ||
Hld->StartDate.Year == 0)
Dat_AssignDate (&Hld->StartDate,&Gbl.Now.Date);
2014-12-01 23:55:08 +01:00
2016-11-28 14:48:16 +01:00
/***** Set end date *****/
2014-12-01 23:55:08 +01:00
switch (Hld->HldTyp)
{
case Hld_HOLIDAY:
2016-11-28 14:48:16 +01:00
/* Set end date = start date (ignore end date from form) */
Dat_AssignDate (&Hld->EndDate,&Hld->StartDate);
2014-12-01 23:55:08 +01:00
break;
case Hld_NON_SCHOOL_PERIOD:
2016-11-28 14:48:16 +01:00
/* Get end date from form */
Dat_GetDateFromForm ("EndDay","EndMonth","EndYear",
&(Hld->EndDate.Day),&(Hld->EndDate.Month),&(Hld->EndDate.Year));
if (Hld->EndDate.Day == 0 ||
Hld->EndDate.Month == 0 ||
Hld->EndDate.Year == 0)
Dat_AssignDate (&Hld->EndDate,&Gbl.Now.Date);
2014-12-01 23:55:08 +01:00
break;
}
2016-11-28 14:48:16 +01:00
/***** Get holiday name *****/
2017-03-07 19:55:29 +01:00
Par_GetParToText ("Name",Hld->Name,Hld_MAX_BYTES_HOLIDAY_NAME);
2016-11-28 14:48:16 +01:00
2017-03-26 00:20:34 +01:00
/***** Create the new holiday or set warning message *****/
2014-12-01 23:55:08 +01:00
if (Hld->Name[0]) // If there's a holiday name
2017-03-26 00:20:34 +01:00
{
/* Create the new holiday */
2014-12-01 23:55:08 +01:00
Hld_CreateHoliday (Hld);
2017-03-26 00:20:34 +01:00
/* Success message */
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_SUCCESS;
2018-10-16 23:08:04 +02:00
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
2018-10-16 21:56:01 +02:00
Txt_Created_new_holiday_X,
Hld->Name);
2017-03-26 00:20:34 +01:00
}
2014-12-01 23:55:08 +01:00
else // If there is not a holiday name
{
2017-03-26 00:20:34 +01:00
/* Error message */
2017-05-11 23:45:46 +02:00
Gbl.Alert.Type = Ale_WARNING;
2018-10-16 15:16:32 +02:00
Str_Copy (Gbl.Alert.Txt,Txt_You_must_specify_the_name_of_the_new_holiday,
Ale_MAX_BYTES_ALERT);
2014-12-01 23:55:08 +01:00
}
2017-03-26 00:20:34 +01:00
}
void Hld_RecFormNewHoliday2 (void)
{
/***** Write error/success message *****/
2017-05-11 23:45:46 +02:00
Ale_ShowPendingAlert ();
2014-12-01 23:55:08 +01:00
/***** Show the form again *****/
Hld_EditHolidays ();
}
/*****************************************************************************/
/**************************** Create a new holiday ***************************/
/*****************************************************************************/
static void Hld_CreateHoliday (struct Holiday *Hld)
{
/***** Create a new holiday or no school period *****/
2018-11-02 19:37:11 +01:00
DB_QueryINSERT ("can not create holiday",
"INSERT INTO holidays"
" (InsCod,PlcCod,HldTyp,StartDate,EndDate,Name)"
" VALUES"
" (%ld,%ld,%u,'%04u%02u%02u','%04u%02u%02u','%s')",
Gbl.CurrentIns.Ins.InsCod,Hld->PlcCod,(unsigned) Hld->HldTyp,
Hld->StartDate.Year,
Hld->StartDate.Month,
Hld->StartDate.Day,
Hld->EndDate.Year,
Hld->EndDate.Month,
Hld->EndDate.Day,
Hld->Name);
2014-12-01 23:55:08 +01:00
}