diff --git a/Makefile b/Makefile
index c3da94bc..9710524c 100644
--- a/Makefile
+++ b/Makefile
@@ -54,7 +54,7 @@ OBJS = swad_account.o swad_account_database.o swad_action.o swad_admin.o \
swad_game.o swad_game_database.o swad_global.o swad_group.o \
swad_group_database.o swad_help.o swad_hierarchy.o \
swad_hierarchy_config.o swad_hierarchy_database.o swad_holiday.o \
- swad_HTML.o \
+ swad_holiday_database.o swad_HTML.o \
swad_icon.o swad_ID.o swad_indicator.o swad_info.o swad_institution.o \
swad_institution_config.o swad_institution_database.o \
swad_language.o swad_layout.o swad_link.o swad_log.o swad_logo.o \
diff --git a/swad_changelog.h b/swad_changelog.h
index ba1db053..a4d7f414 100644
--- a/swad_changelog.h
+++ b/swad_changelog.h
@@ -602,13 +602,14 @@ TODO: FIX BUG, URGENT! En las fechas como par
TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo.
*/
-#define Log_PLATFORM_VERSION "SWAD 21.7 (2021-09-20)"
+#define Log_PLATFORM_VERSION "SWAD 21.8 (2021-09-20)"
#define CSS_FILE "swad20.45.css"
#define JS_FILE "swad20.69.1.js"
/*
TODO: Rename CENTRE to CENTER in help wiki.
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
+ Version 21.8: Sep 18, 2021 New module swad_holiday_database for database queries related to holidays. (315883 lines)
Version 21.7: Sep 18, 2021 New module swad_hierarchy_database for database queries related to hierarchy. (315774 lines)
Version 21.6.3: Sep 20, 2021 Queries moved to module swad_game_database. (315708 lines)
Version 21.6.2: Sep 18, 2021 Queries moved to module swad_game_database. (315679 lines)
diff --git a/swad_holiday.c b/swad_holiday.c
index fc2f3031..06940447 100644
--- a/swad_holiday.c
+++ b/swad_holiday.c
@@ -36,6 +36,7 @@
#include "swad_form.h"
#include "swad_global.h"
#include "swad_holiday.h"
+#include "swad_holiday_database.h"
#include "swad_HTML.h"
#include "swad_language.h"
#include "swad_parameter.h"
@@ -79,7 +80,6 @@ static void Hld_PutParamHldCod (void *HldCod);
static void Hld_ChangeDate (Hld_StartOrEndDate_t StartOrEndDate);
static void Hld_PutFormToCreateHoliday (const struct Plc_Places *Places);
static void Hld_PutHeadHolidays (void);
-static void Hld_DB_CreateHoliday (const struct Hld_Holiday *Hld);
static void Hld_EditingHolidayConstructor (void);
static void Hld_EditingHolidayDestructor (void);
@@ -316,11 +316,6 @@ static void Hld_EditHolidaysInternal (void)
void Hld_GetListHolidays (struct Hld_Holidays *Holidays)
{
- static const char *OrderBySubQuery[Hld_NUM_ORDERS] =
- {
- [Hld_ORDER_BY_PLACE ] = "Place,StartDate",
- [Hld_ORDER_BY_START_DATE] = "StartDate,Place",
- };
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumHld;
@@ -332,41 +327,7 @@ void Hld_GetListHolidays (struct Hld_Holidays *Holidays)
Hld_FreeListHolidays (Holidays);
/***** Get holidays from database *****/
- Holidays->Num = (unsigned)
- DB_QuerySELECT (&mysql_res,"can not get holidays",
- "(SELECT hld_holidays.HldCod," // row[0]
- "hld_holidays.PlcCod," // row[1]
- "plc_places.FullName as Place," // row[2]
- "hld_holidays.HldTyp," // row[3]
- "DATE_FORMAT(hld_holidays.StartDate,'%%Y%%m%%d') AS StartDate," // row[4]
- "DATE_FORMAT(hld_holidays.EndDate,'%%Y%%m%%d') AS EndDate," // row[5]
- "hld_holidays.Name" // row[6]
- " FROM hld_holidays,"
- "plc_places"
- " WHERE hld_holidays.InsCod=%ld"
- " AND hld_holidays.PlcCod=plc_places.PlcCod"
- " AND plc_places.InsCod=%ld)"
- " UNION "
- "(SELECT HldCod," // row[0]
- "PlcCod," // row[1]
- "'' as Place," // row[2]
- "HldTyp," // row[3]
- "DATE_FORMAT(StartDate,'%%Y%%m%%d') AS StartDate," // row[4]
- "DATE_FORMAT(EndDate,'%%Y%%m%%d') AS EndDate," // row[5]
- "Name" // row[6]
- " FROM hld_holidays"
- " WHERE InsCod=%ld"
- " AND PlcCod NOT IN"
- "(SELECT DISTINCT PlcCod"
- " FROM plc_places"
- " WHERE InsCod=%ld))"
- " ORDER BY %s",
- Gbl.Hierarchy.Ins.InsCod,
- Gbl.Hierarchy.Ins.InsCod,
- Gbl.Hierarchy.Ins.InsCod,
- Gbl.Hierarchy.Ins.InsCod,
- OrderBySubQuery[Holidays->SelectedOrder]);
- if (Holidays->Num) // Holidays found...
+ if ((Holidays->Num = Hld_DB_GetListHolidays (&mysql_res,Holidays->SelectedOrder))) // Holidays found...
{
/***** Create list of holidays *****/
if ((Holidays->Lst = calloc (Holidays->Num,
@@ -449,43 +410,18 @@ static void Hld_GetDataOfHolidayByCod (struct Hld_Holiday *Hld)
Err_WrongHolidayExit ();
/***** Get data of holiday from database *****/
- if (DB_QuerySELECT (&mysql_res,"can not get data of a holiday",
- "(SELECT hld_holidays.PlcCod," // row[0]
- "plc_places.FullName as Place," // row[1]
- "hld_holidays.HldTyp," // row[2]
- "DATE_FORMAT(hld_holidays.StartDate,'%%Y%%m%%d')," // row[3]
- "DATE_FORMAT(hld_holidays.EndDate,'%%Y%%m%%d')," // row[4]
- "hld_holidays.Name" // row[5]
- " FROM hld_holidays,"
- "plc_places"
- " WHERE hld_holidays.HldCod=%ld"
- " AND hld_holidays.InsCod=%ld"
- " AND hld_holidays.PlcCod=plc_places.PlcCod"
- " AND plc_places.InsCod=%ld)"
- " UNION "
- "(SELECT PlcCod,"
- "'' as Place,"
- "HldTyp,"
- "DATE_FORMAT(StartDate,'%%Y%%m%%d'),"
- "DATE_FORMAT(EndDate,'%%Y%%m%%d'),"
- "Name"
- " FROM hld_holidays"
- " WHERE HldCod=%ld"
- " AND InsCod=%ld"
- " AND PlcCod NOT IN"
- "(SELECT DISTINCT PlcCod"
- " FROM plc_places"
- " WHERE InsCod=%ld))",
- Hld->HldCod,
- Gbl.Hierarchy.Ins.InsCod,
- Gbl.Hierarchy.Ins.InsCod,
- Hld->HldCod,
- Gbl.Hierarchy.Ins.InsCod,
- Gbl.Hierarchy.Ins.InsCod)) // Holiday found...
+ if (Hld_DB_GetDataOfHolidayByCod (&mysql_res,Hld->HldCod)) // Holiday found...
{
/* Get row */
row = mysql_fetch_row (mysql_res);
-
+ /*
+ row[0]: PlcCod
+ row[1]: Place
+ row[2]: HldTyp
+ row[3]: StartDate
+ row[4]: EndDate
+ row[5]: Name
+ */
/* Get place code (row[0]) */
Hld->PlcCod = Str_ConvertStrCodToLongCod (row[0]);
@@ -1179,30 +1115,6 @@ void Hld_ReceiveFormNewHoliday (void)
Txt_You_must_specify_the_name_of_the_new_holiday);
}
-/*****************************************************************************/
-/**************************** Create a new holiday ***************************/
-/*****************************************************************************/
-
-static void Hld_DB_CreateHoliday (const struct Hld_Holiday *Hld)
- {
- /***** Create a new holiday or no school period *****/
- DB_QueryINSERT ("can not create holiday",
- "INSERT INTO hld_holidays"
- " (InsCod,PlcCod,HldTyp,StartDate,EndDate,Name)"
- " VALUES"
- " (%ld,%ld,%u,'%04u%02u%02u','%04u%02u%02u','%s')",
- Gbl.Hierarchy.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);
- }
-
/*****************************************************************************/
/************************* Holiday constructor/destructor ********************/
/*****************************************************************************/
diff --git a/swad_holiday_database.c b/swad_holiday_database.c
new file mode 100644
index 00000000..552d0a8a
--- /dev/null
+++ b/swad_holiday_database.c
@@ -0,0 +1,179 @@
+// swad_holiday_database.c: holidays operations with database
+
+/*
+ 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-2021 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 .
+*/
+/*****************************************************************************/
+/********************************* Headers ***********************************/
+/*****************************************************************************/
+
+// #include // For NULL
+// #include // For calloc
+// #include // For string functions
+
+// #include "swad_box.h"
+// #include "swad_calendar.h"
+#include "swad_database.h"
+// #include "swad_error.h"
+// #include "swad_form.h"
+#include "swad_global.h"
+// #include "swad_holiday.h"
+#include "swad_holiday_database.h"
+// #include "swad_HTML.h"
+// #include "swad_language.h"
+// #include "swad_parameter.h"
+
+/*****************************************************************************/
+/************** External global variables from others modules ****************/
+/*****************************************************************************/
+
+extern struct Globals Gbl;
+
+/*****************************************************************************/
+/***************************** Private constants *****************************/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/******************************* Private types *******************************/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/***************************** Private variables *****************************/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/***************************** Private prototypes ****************************/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/****************** Create a new holiday or no school period *****************/
+/*****************************************************************************/
+
+void Hld_DB_CreateHoliday (const struct Hld_Holiday *Hld)
+ {
+ DB_QueryINSERT ("can not create holiday",
+ "INSERT INTO hld_holidays"
+ " (InsCod,PlcCod,HldTyp,StartDate,EndDate,Name)"
+ " VALUES"
+ " (%ld,%ld,%u,'%04u%02u%02u','%04u%02u%02u','%s')",
+ Gbl.Hierarchy.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);
+ }
+
+/*****************************************************************************/
+/*************************** List all the holidays ***************************/
+/*****************************************************************************/
+
+unsigned Hld_DB_GetListHolidays (MYSQL_RES **mysql_res,Hld_Order_t SelectedOrder)
+ {
+ static const char *OrderBySubQuery[Hld_NUM_ORDERS] =
+ {
+ [Hld_ORDER_BY_PLACE ] = "Place,"
+ "StartDate",
+ [Hld_ORDER_BY_START_DATE] = "StartDate,"
+ "Place",
+ };
+
+ return (unsigned)
+ DB_QuerySELECT (mysql_res,"can not get holidays",
+ "(SELECT hld_holidays.HldCod," // row[0]
+ "hld_holidays.PlcCod," // row[1]
+ "plc_places.FullName as Place," // row[2]
+ "hld_holidays.HldTyp," // row[3]
+ "DATE_FORMAT(hld_holidays.StartDate,'%%Y%%m%%d') AS StartDate," // row[4]
+ "DATE_FORMAT(hld_holidays.EndDate,'%%Y%%m%%d') AS EndDate," // row[5]
+ "hld_holidays.Name" // row[6]
+ " FROM hld_holidays,"
+ "plc_places"
+ " WHERE hld_holidays.InsCod=%ld"
+ " AND hld_holidays.PlcCod=plc_places.PlcCod"
+ " AND plc_places.InsCod=%ld)"
+ " UNION "
+ "(SELECT HldCod," // row[0]
+ "PlcCod," // row[1]
+ "'' as Place," // row[2]
+ "HldTyp," // row[3]
+ "DATE_FORMAT(StartDate,'%%Y%%m%%d') AS StartDate," // row[4]
+ "DATE_FORMAT(EndDate,'%%Y%%m%%d') AS EndDate," // row[5]
+ "Name" // row[6]
+ " FROM hld_holidays"
+ " WHERE InsCod=%ld"
+ " AND PlcCod NOT IN"
+ "(SELECT DISTINCT PlcCod"
+ " FROM plc_places"
+ " WHERE InsCod=%ld))"
+ " ORDER BY %s",
+ Gbl.Hierarchy.Ins.InsCod,
+ Gbl.Hierarchy.Ins.InsCod,
+ Gbl.Hierarchy.Ins.InsCod,
+ Gbl.Hierarchy.Ins.InsCod,
+ OrderBySubQuery[SelectedOrder]);
+ }
+
+/*****************************************************************************/
+/************************* Get holiday data by code **************************/
+/*****************************************************************************/
+
+unsigned Hld_DB_GetDataOfHolidayByCod (MYSQL_RES **mysql_res,long HldCod)
+ {
+ return (unsigned)
+ DB_QuerySELECT (mysql_res,"can not get data of a holiday",
+ "(SELECT hld_holidays.PlcCod," // row[0]
+ "plc_places.FullName as Place," // row[1]
+ "hld_holidays.HldTyp," // row[2]
+ "DATE_FORMAT(hld_holidays.StartDate,'%%Y%%m%%d')," // row[3]
+ "DATE_FORMAT(hld_holidays.EndDate,'%%Y%%m%%d')," // row[4]
+ "hld_holidays.Name" // row[5]
+ " FROM hld_holidays,"
+ "plc_places"
+ " WHERE hld_holidays.HldCod=%ld"
+ " AND hld_holidays.InsCod=%ld"
+ " AND hld_holidays.PlcCod=plc_places.PlcCod"
+ " AND plc_places.InsCod=%ld)"
+ " UNION "
+ "(SELECT PlcCod,"
+ "'' as Place,"
+ "HldTyp,"
+ "DATE_FORMAT(StartDate,'%%Y%%m%%d'),"
+ "DATE_FORMAT(EndDate,'%%Y%%m%%d'),"
+ "Name"
+ " FROM hld_holidays"
+ " WHERE HldCod=%ld"
+ " AND InsCod=%ld"
+ " AND PlcCod NOT IN"
+ "(SELECT DISTINCT PlcCod"
+ " FROM plc_places"
+ " WHERE InsCod=%ld))",
+ HldCod,
+ Gbl.Hierarchy.Ins.InsCod,
+ Gbl.Hierarchy.Ins.InsCod,
+ HldCod,
+ Gbl.Hierarchy.Ins.InsCod,
+ Gbl.Hierarchy.Ins.InsCod);
+ }
diff --git a/swad_holiday_database.h b/swad_holiday_database.h
new file mode 100644
index 00000000..17b16bc4
--- /dev/null
+++ b/swad_holiday_database.h
@@ -0,0 +1,45 @@
+// swad_holiday_database.h: holidays operations with database
+
+#ifndef _SWAD_HLD_DB
+#define _SWAD_HLD_DB
+/*
+ SWAD (Shared Workspace At a Distance in Spanish),
+ 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-2021 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 .
+*/
+/*****************************************************************************/
+/********************************* Headers ***********************************/
+/*****************************************************************************/
+
+#include "swad_holiday.h"
+
+/*****************************************************************************/
+/************************** Public types and constants ***********************/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/***************************** Public prototypes *****************************/
+/*****************************************************************************/
+
+void Hld_DB_CreateHoliday (const struct Hld_Holiday *Hld);
+
+unsigned Hld_DB_GetListHolidays (MYSQL_RES **mysql_res,Hld_Order_t SelectedOrder);
+unsigned Hld_DB_GetDataOfHolidayByCod (MYSQL_RES **mysql_res,long HldCod);
+
+#endif