diff --git a/Makefile b/Makefile
index 22a01ed9..48adbe78 100644
--- a/Makefile
+++ b/Makefile
@@ -71,8 +71,8 @@ OBJS = swad_account.o swad_account_database.o swad_action.o swad_admin.o \
swad_notification.o swad_notification_database.o \
swad_pagination.o swad_parameter.o swad_password.o \
swad_password_database.o swad_photo.o swad_photo_database.o \
- swad_place.o swad_plugin.o swad_privacy.o swad_profile.o swad_program.o \
- swad_project.o \
+ swad_place.o swad_place_database.o swad_plugin.o swad_privacy.o \
+ swad_profile.o swad_program.o swad_project.o \
swad_QR.o \
swad_record.o swad_report.o swad_role.o swad_room.o swad_RSS.o \
swad_scope.o swad_search.o swad_session.o swad_setting.o \
diff --git a/swad_changelog.h b/swad_changelog.h
index 883061a6..e0aa79cc 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.24.1 (2021-10-05)"
+#define Log_PLATFORM_VERSION "SWAD 21.25 (2021-10-05)"
#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.25: Oct 05, 2021 New module swad_place_database for database queries related to place. (318514 lines)
Version 21.24.1: Oct 05, 2021 Queries moved to module swad_photo_database. (318406 lines)
Version 21.24: Oct 05, 2021 New module swad_photo_database for database queries related to users' photos. (318352 lines)
Version 21.23: Oct 04, 2021 New module swad_password_database for database queries related to passwords. (318197 lines)
diff --git a/swad_place.c b/swad_place.c
index ebefbe29..c0f1a0c7 100644
--- a/swad_place.c
+++ b/swad_place.c
@@ -40,6 +40,7 @@
#include "swad_language.h"
#include "swad_parameter.h"
#include "swad_place.h"
+#include "swad_place_database.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
@@ -76,13 +77,9 @@ static void Plc_ListPlacesForEdition (const struct Plc_Places *Places);
static void Plc_PutParamPlcCod (void *PlcCod);
static void Plc_RenamePlace (Cns_ShrtOrFullName_t ShrtOrFullName);
-static bool Plc_DB_CheckIfPlaceNameExists (long PlcCod,
- const char *FieldName,const char *Name);
-static void Plc_DB_UpdatePlcName (long PlcCod,const char *FieldName,const char *NewPlcName);
static void Plc_PutFormToCreatePlace (void);
static void Plc_PutHeadPlaces (void);
-static void Plc_DB_CreatePlace (struct Plc_Place *Plc);
static void Plc_EditingPlaceConstructor (void);
static void Plc_EditingPlaceDestructor (void);
@@ -355,49 +352,13 @@ void Plc_PutIconToViewPlaces (void)
void Plc_GetListPlaces (struct Plc_Places *Places)
{
- static const char *OrderBySubQuery[Plc_NUM_ORDERS] =
- {
- [Plc_ORDER_BY_PLACE ] = "FullName",
- [Plc_ORDER_BY_NUM_CTRS] = "NumCtrs DESC,FullName",
- };
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumPlc;
struct Plc_Place *Plc;
/***** Get places from database *****/
- Places->Num = (unsigned)
- DB_QuerySELECT (&mysql_res,"can not get places",
- "(SELECT plc_places.PlcCod," // row[0]
- "plc_places.ShortName," // row[1]
- "plc_places.FullName," // row[2]
- "COUNT(*) AS NumCtrs" // row[3]
- " FROM plc_places,"
- "ctr_centers"
- " WHERE plc_places.InsCod=%ld"
- " AND plc_places.PlcCod=ctr_centers.PlcCod"
- " AND ctr_centers.InsCod=%ld"
- " GROUP BY plc_places.PlcCod)"
- " UNION "
- "(SELECT PlcCod,"
- "ShortName,"
- "FullName,"
- "0 AS NumCtrs"
- " FROM plc_places"
- " WHERE InsCod=%ld"
- " AND PlcCod NOT IN"
- " (SELECT DISTINCT PlcCod"
- " FROM ctr_centers"
- " WHERE InsCod=%ld))"
- " ORDER BY %s",
- Gbl.Hierarchy.Ins.InsCod,
- Gbl.Hierarchy.Ins.InsCod,
- Gbl.Hierarchy.Ins.InsCod,
- Gbl.Hierarchy.Ins.InsCod,
- OrderBySubQuery[Places->SelectedOrder]);
-
- /***** Count number of rows in result *****/
- if (Places->Num) // Places found...
+ if ((Places->Num = Plc_DB_GetListPlaces (&mysql_res,Places->SelectedOrder))) // Places found...
{
/***** Create list with courses in center *****/
if ((Places->Lst = calloc ((size_t) Places->Num,
@@ -462,28 +423,7 @@ void Plc_GetDataOfPlaceByCod (struct Plc_Place *Plc)
else if (Plc->PlcCod > 0)
{
/***** Get data of a place from database *****/
- if (DB_QuerySELECT (&mysql_res,"can not get data of a place",
- "(SELECT plc_places.ShortName," // row[0]
- "plc_places.FullName," // row[1]
- "COUNT(*)" // row[2]
- " FROM plc_places,"
- "ctr_centers"
- " WHERE plc_places.PlcCod=%ld"
- " AND plc_places.PlcCod=ctr_centers.PlcCod"
- " AND ctr_centers.PlcCod=%ld"
- " GROUP BY plc_places.PlcCod)"
- " UNION "
- "(SELECT ShortName," // row[0]
- "FullName," // row[1]
- "0" // row[2]
- " FROM plc_places"
- " WHERE PlcCod=%ld"
- " AND PlcCod NOT IN"
- " (SELECT DISTINCT PlcCod"
- " FROM ctr_centers))",
- Plc->PlcCod,
- Plc->PlcCod,
- Plc->PlcCod)) // Place found...
+ if (Plc_DB_GetDataOfPlaceByCod (&mysql_res,Plc->PlcCod)) // Place found...
{
/* Get row */
row = mysql_fetch_row (mysql_res);
@@ -633,10 +573,7 @@ void Plc_RemovePlace (void)
else // Place has no centers ==> remove it
{
/***** Remove place *****/
- DB_QueryDELETE ("can not remove a place",
- "DELETE FROM plc_places"
- " WHERE PlcCod=%ld",
- Plc_EditingPlc->PlcCod);
+ Plc_DB_RemovePlace (Plc_EditingPlc->PlcCod);
/***** Write message to show the change made *****/
Ale_CreateAlert (Ale_SUCCESS,NULL,
@@ -748,40 +685,6 @@ static void Plc_RenamePlace (Cns_ShrtOrFullName_t ShrtOrFullName)
Str_Copy (CurrentPlcName,NewPlcName,MaxBytes);
}
-/*****************************************************************************/
-/********************** Check if the name of place exists ********************/
-/*****************************************************************************/
-
-static bool Plc_DB_CheckIfPlaceNameExists (long PlcCod,
- const char *FieldName,const char *Name)
- {
- /***** Get number of places with a name from database *****/
- return (DB_QueryCOUNT ("can not check if the name of a place"
- " already existed",
- "SELECT COUNT(*)"
- " FROM plc_places"
- " WHERE InsCod=%ld"
- " AND %s='%s'"
- " AND PlcCod<>%ld",
- Gbl.Hierarchy.Ins.InsCod,
- FieldName,Name,PlcCod) != 0);
- }
-
-/*****************************************************************************/
-/****************** Update place name in table of places *********************/
-/*****************************************************************************/
-
-static void Plc_DB_UpdatePlcName (long PlcCod,const char *FieldName,const char *NewPlcName)
- {
- /***** Update place changing old name by new name */
- DB_QueryUPDATE ("can not update the name of a place",
- "UPDATE plc_places"
- " SET %s='%s'"
- " WHERE PlcCod=%ld",
- FieldName,NewPlcName,
- PlcCod);
- }
-
/*****************************************************************************/
/********** Show alerts after changing a place and continue editing **********/
/*****************************************************************************/
@@ -920,23 +823,6 @@ void Plc_ReceiveFormNewPlace (void)
Txt_You_must_specify_the_short_name_and_the_full_name_of_the_new_place);
}
-/*****************************************************************************/
-/**************************** Create a new place *****************************/
-/*****************************************************************************/
-
-static void Plc_DB_CreatePlace (struct Plc_Place *Plc)
- {
- /***** Create a new place *****/
- DB_QueryINSERT ("can not create place",
- "INSERT INTO places"
- " (InsCod,ShortName,FullName)"
- " VALUES"
- " (%ld,'%s','%s')",
- Gbl.Hierarchy.Ins.InsCod,
- Plc->ShrtName,
- Plc->FullName);
- }
-
/*****************************************************************************/
/************************* Place constructor/destructor **********************/
/*****************************************************************************/
diff --git a/swad_place_database.c b/swad_place_database.c
new file mode 100644
index 00000000..92b07f13
--- /dev/null
+++ b/swad_place_database.c
@@ -0,0 +1,201 @@
+// swad_place_database.c: places, 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_center_database.h"
+// #include "swad_constant.h"
+#include "swad_database.h"
+// #include "swad_error.h"
+// #include "swad_form.h"
+#include "swad_global.h"
+// #include "swad_HTML.h"
+// #include "swad_language.h"
+// #include "swad_parameter.h"
+#include "swad_place.h"
+
+/*****************************************************************************/
+/************** External global variables from others modules ****************/
+/*****************************************************************************/
+
+extern struct Globals Gbl;
+
+/*****************************************************************************/
+/***************************** Private constants *****************************/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/******************************* Private types *******************************/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/***************************** Private variables *****************************/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/***************************** Private prototypes ****************************/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/**************************** Create a new place *****************************/
+/*****************************************************************************/
+
+void Plc_DB_CreatePlace (const struct Plc_Place *Plc)
+ {
+ DB_QueryINSERT ("can not create place",
+ "INSERT INTO places"
+ " (InsCod,ShortName,FullName)"
+ " VALUES"
+ " (%ld,'%s','%s')",
+ Gbl.Hierarchy.Ins.InsCod,
+ Plc->ShrtName,
+ Plc->FullName);
+ }
+
+/*****************************************************************************/
+/****************** Update place name in table of places *********************/
+/*****************************************************************************/
+
+void Plc_DB_UpdatePlcName (long PlcCod,const char *FieldName,const char *NewPlcName)
+ {
+ /***** Update place changing old name by new name */
+ DB_QueryUPDATE ("can not update the name of a place",
+ "UPDATE plc_places"
+ " SET %s='%s'"
+ " WHERE PlcCod=%ld",
+ FieldName,NewPlcName,
+ PlcCod);
+ }
+
+/*****************************************************************************/
+/************************** Get list of all places ***************************/
+/*****************************************************************************/
+
+unsigned Plc_DB_GetListPlaces (MYSQL_RES **mysql_res,Plc_Order_t SelectedOrder)
+ {
+ static const char *OrderBySubQuery[Plc_NUM_ORDERS] =
+ {
+ [Plc_ORDER_BY_PLACE ] = "FullName",
+ [Plc_ORDER_BY_NUM_CTRS] = "NumCtrs DESC,"
+ "FullName",
+ };
+
+ return (unsigned)
+ DB_QuerySELECT (mysql_res,"can not get places",
+ "(SELECT plc_places.PlcCod," // row[0]
+ "plc_places.ShortName," // row[1]
+ "plc_places.FullName," // row[2]
+ "COUNT(*) AS NumCtrs" // row[3]
+ " FROM plc_places,"
+ "ctr_centers"
+ " WHERE plc_places.InsCod=%ld"
+ " AND plc_places.PlcCod=ctr_centers.PlcCod"
+ " AND ctr_centers.InsCod=%ld"
+ " GROUP BY plc_places.PlcCod)"
+ " UNION "
+ "(SELECT PlcCod,"
+ "ShortName,"
+ "FullName,"
+ "0 AS NumCtrs"
+ " FROM plc_places"
+ " WHERE InsCod=%ld"
+ " AND PlcCod NOT IN"
+ " (SELECT DISTINCT PlcCod"
+ " FROM ctr_centers"
+ " 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 data of a place from database *********************/
+/*****************************************************************************/
+
+unsigned Plc_DB_GetDataOfPlaceByCod (MYSQL_RES **mysql_res,long PlcCod)
+ {
+ return (unsigned)
+ DB_QuerySELECT (mysql_res,"can not get data of a place",
+ "(SELECT plc_places.ShortName," // row[0]
+ "plc_places.FullName," // row[1]
+ "COUNT(*)" // row[2]
+ " FROM plc_places,"
+ "ctr_centers"
+ " WHERE plc_places.PlcCod=%ld"
+ " AND plc_places.PlcCod=ctr_centers.PlcCod"
+ " AND ctr_centers.PlcCod=%ld"
+ " GROUP BY plc_places.PlcCod)"
+ " UNION "
+ "(SELECT ShortName," // row[0]
+ "FullName," // row[1]
+ "0" // row[2]
+ " FROM plc_places"
+ " WHERE PlcCod=%ld"
+ " AND PlcCod NOT IN"
+ " (SELECT DISTINCT PlcCod"
+ " FROM ctr_centers))",
+ PlcCod,
+ PlcCod,
+ PlcCod);
+ }
+
+/*****************************************************************************/
+/********************** Check if the name of place exists ********************/
+/*****************************************************************************/
+
+bool Plc_DB_CheckIfPlaceNameExists (long PlcCod,
+ const char *FieldName,const char *Name)
+ {
+ return (DB_QueryCOUNT ("can not check if the name of a place"
+ " already existed",
+ "SELECT COUNT(*)"
+ " FROM plc_places"
+ " WHERE InsCod=%ld"
+ " AND %s='%s'"
+ " AND PlcCod<>%ld",
+ Gbl.Hierarchy.Ins.InsCod,
+ FieldName,Name,
+ PlcCod) != 0);
+ }
+
+/*****************************************************************************/
+/******************************** Remove place *******************************/
+/*****************************************************************************/
+
+void Plc_DB_RemovePlace (long PlcCod)
+ {
+ DB_QueryDELETE ("can not remove a place",
+ "DELETE FROM plc_places"
+ " WHERE PlcCod=%ld",
+ PlcCod);
+ }
diff --git a/swad_place_database.h b/swad_place_database.h
new file mode 100644
index 00000000..2c779e51
--- /dev/null
+++ b/swad_place_database.h
@@ -0,0 +1,51 @@
+// swad_place_database.h: places, operations with database
+
+#ifndef _SWAD_PLC_DB
+#define _SWAD_PLC_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_place.h"
+// #include "swad_string.h"
+
+/*****************************************************************************/
+/************************** Public types and constants ***********************/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/***************************** Public prototypes *****************************/
+/*****************************************************************************/
+
+void Plc_DB_CreatePlace (const struct Plc_Place *Plc);
+void Plc_DB_UpdatePlcName (long PlcCod,const char *FieldName,const char *NewPlcName);
+
+unsigned Plc_DB_GetListPlaces (MYSQL_RES **mysql_res,Plc_Order_t SelectedOrder);
+unsigned Plc_DB_GetDataOfPlaceByCod (MYSQL_RES **mysql_res,long PlcCod);
+bool Plc_DB_CheckIfPlaceNameExists (long PlcCod,
+ const char *FieldName,const char *Name);
+
+void Plc_DB_RemovePlace (long PlcCod);
+
+#endif