Version 20.88: Jun 02, 2021 New module swad_center_database for database queries related to centers.

This commit is contained in:
acanas 2021-06-02 00:08:30 +02:00
parent 9ea5a0eeec
commit 17c04cc470
10 changed files with 854 additions and 735 deletions

View File

@ -33,11 +33,12 @@ OBJS = swad_account.o swad_account_database.o swad_action.o swad_agenda.o \
swad_banner.o swad_banner_database.o swad_box.o swad_building.o \
swad_building_database.o swad_button.o \
swad_calendar.o swad_call_for_exam.o swad_call_for_exam_database.o \
swad_center.o swad_center_config.o swad_chat.o swad_chat_database.o \
swad_config.o swad_connected.o swad_connected_database.o swad_cookie.o \
swad_cookie_database.o swad_country.o swad_country_config.o \
swad_country_database.o swad_course.o swad_course_config.o \
swad_course_database.o swad_cryptography.o \
swad_center.o swad_center_config.o swad_center_database.o swad_chat.o \
swad_chat_database.o swad_config.o swad_connected.o \
swad_connected_database.o swad_cookie.o swad_cookie_database.o \
swad_country.o swad_country_config.o swad_country_database.o \
swad_course.o swad_course_config.o swad_course_database.o \
swad_cryptography.o \
swad_database.o swad_date.o swad_degree.o swad_degree_config.o \
swad_degree_database.o swad_degree_type.o swad_department.o \
swad_duplicate.o \

View File

@ -25,17 +25,9 @@
/********************************** Headers **********************************/
/*****************************************************************************/
// #include <malloc.h> // For calloc, free
// #include <stddef.h> // For NULL
// #include <string.h> // For string functions
// #include "swad_box.h"
#include "swad_building.h"
#include "swad_database.h"
// #include "swad_error.h"
// #include "swad_form.h"
#include "swad_global.h"
// #include "swad_HTML.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/

View File

@ -30,7 +30,6 @@
#include <mysql/mysql.h> // To access MySQL databases
#include "swad_building.h"
// #include "swad_string.h"
/*****************************************************************************/
/************************** Public types and constants ***********************/

View File

@ -90,7 +90,7 @@ static Ctr_Status_t Ctr_GetStatusBitsFromStatusTxt (Ctr_StatusTxt_t StatusTxt);
static void Ctr_PutParamOtherCtrCod (void *CtrCod);
static void Ctr_UpdateInsNameDB (long CtrCod,const char *FieldName,const char *NewCtrName);
static void Ctr_DB_UpdateCtrName (long CtrCod,const char *FieldName,const char *NewCtrName);
static void Ctr_ShowAlertAndButtonToGoToCtr (void);
static void Ctr_PutParamGoToCtr (void *CtrCod);
@ -99,7 +99,7 @@ static void Ctr_PutFormToCreateCenter (const struct Plc_Places *Places);
static void Ctr_PutHeadCentersForSeeing (bool OrderSelectable);
static void Ctr_PutHeadCentersForEdition (void);
static void Ctr_ReceiveFormRequestOrCreateCtr (unsigned Status);
static void Ctr_CreateCenter (unsigned Status);
static void Ctr_DB_CreateCenter (unsigned Status);
static unsigned Ctr_GetNumCtrsInCty (long CtyCod);
@ -180,7 +180,7 @@ void Ctr_SeeCtrWithPendingDegs (void)
/***** List the centers *****/
for (NumCtr = 0;
NumCtr < NumCtrs;
NumCtr++)
NumCtr++, Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd)
{
/* Get next center */
row = mysql_fetch_row (mysql_res);
@ -206,7 +206,6 @@ void Ctr_SeeCtrWithPendingDegs (void)
HTM_Txt (row[1]);
HTM_TD_End ();
Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd;
HTM_TR_End ();
}
@ -299,6 +298,8 @@ static void Ctr_ListCenters (void)
{
/***** Begin table *****/
HTM_TABLE_BeginWideMarginPadding (2);
/***** Write heading *****/
Ctr_PutHeadCentersForSeeing (true); // Order selectable
/***** Write all the centers and their nuber of teachers *****/
@ -850,6 +851,7 @@ void Ctr_WriteSelectorOfCenter (void)
/***** Begin form *****/
Frm_BeginFormGoTo (ActSeeDeg);
/***** Begin selector *****/
if (Gbl.Hierarchy.Ins.InsCod > 0)
HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE,
"id=\"ctr\" name=\"ctr\" class=\"HIE_SEL\"");
@ -896,8 +898,10 @@ void Ctr_WriteSelectorOfCenter (void)
DB_FreeMySQLResult (&mysql_res);
}
/***** End form *****/
/***** End selector *****/
HTM_SELECT_End ();
/***** End form *****/
Frm_EndForm ();
}
@ -924,8 +928,10 @@ static void Ctr_ListCentersForEdition (const struct Plc_Places *Places)
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
/***** Write heading *****/
/***** Begin table *****/
HTM_TABLE_BeginWidePadding (2);
/***** Write heading *****/
Ctr_PutHeadCentersForEdition ();
/***** Write all the centers *****/
@ -943,8 +949,9 @@ static void Ctr_ListCentersForEdition (const struct Plc_Places *Places)
1 << Rol_NET |
1 << Rol_TCH); // Any user
/* Put icon to remove center */
HTM_TR_Begin (NULL);
/* Put icon to remove center */
HTM_TD_Begin ("class=\"BM\"");
if (!ICanEdit || // I cannot edit
NumDegs || // Center has degrees
@ -1095,6 +1102,7 @@ static void Ctr_ListCentersForEdition (const struct Plc_Places *Places)
else if (StatusTxt != Ctr_STATUS_ACTIVE) // If active ==> do not show anything
HTM_Txt (Txt_CENTER_STATUS[StatusTxt]);
HTM_TD_End ();
HTM_TR_End ();
}
@ -1290,7 +1298,7 @@ void Ctr_ChangeCtrPlc (void)
Ctr_GetDataOfCenterByCod (Ctr_EditingCtr);
/***** Update place in table of centers *****/
Ctr_UpdateCtrPlcDB (Ctr_EditingCtr->CtrCod,NewPlcCod);
Ctr_DB_UpdateCtrPlc (Ctr_EditingCtr->CtrCod,NewPlcCod);
Ctr_EditingCtr->PlcCod = NewPlcCod;
/***** Create alert to show the change made
@ -1303,7 +1311,7 @@ void Ctr_ChangeCtrPlc (void)
/************** Update database changing old place by new place **************/
/*****************************************************************************/
void Ctr_UpdateCtrPlcDB (long CtrCod,long NewPlcCod)
void Ctr_DB_UpdateCtrPlc (long CtrCod,long NewPlcCod)
{
DB_QueryUPDATE ("can not update the place of a center",
"UPDATE ctr_centers"
@ -1385,14 +1393,14 @@ void Ctr_RenameCenter (struct Ctr_Center *Ctr,Cns_ShrtOrFullName_t ShrtOrFullNam
if (strcmp (CurrentCtrName,NewCtrName)) // Different names
{
/***** If degree was in database... *****/
if (Ctr_CheckIfCtrNameExistsInIns (ParamName,NewCtrName,Ctr->CtrCod,Gbl.Hierarchy.Ins.InsCod))
if (Ctr_DB_CheckIfCtrNameExistsInIns (ParamName,NewCtrName,Ctr->CtrCod,Gbl.Hierarchy.Ins.InsCod))
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_center_X_already_exists,
NewCtrName);
else
{
/* Update the table changing old name by new name */
Ctr_UpdateInsNameDB (Ctr->CtrCod,FieldName,NewCtrName);
Ctr_DB_UpdateCtrName (Ctr->CtrCod,FieldName,NewCtrName);
/* Write message to show the change made */
Ale_CreateAlert (Ale_SUCCESS,NULL,
@ -1414,7 +1422,7 @@ void Ctr_RenameCenter (struct Ctr_Center *Ctr,Cns_ShrtOrFullName_t ShrtOrFullNam
/********************* Check if the name of center exists ********************/
/*****************************************************************************/
bool Ctr_CheckIfCtrNameExistsInIns (const char *FieldName,const char *Name,
bool Ctr_DB_CheckIfCtrNameExistsInIns (const char *FieldName,const char *Name,
long CtrCod,long InsCod)
{
/***** Get number of centers with a name from database *****/
@ -1435,7 +1443,7 @@ bool Ctr_CheckIfCtrNameExistsInIns (const char *FieldName,const char *Name,
/****************** Update center name in table of centers *******************/
/*****************************************************************************/
static void Ctr_UpdateInsNameDB (long CtrCod,const char *FieldName,const char *NewCtrName)
static void Ctr_DB_UpdateCtrName (long CtrCod,const char *FieldName,const char *NewCtrName)
{
/***** Update center changing old name by new name */
DB_QueryUPDATE ("can not update the name of a center",
@ -1472,7 +1480,7 @@ void Ctr_ChangeCtrWWW (void)
if (NewWWW[0])
{
/***** Update database changing old WWW by new WWW *****/
Ctr_UpdateCtrWWWDB (Ctr_EditingCtr->CtrCod,NewWWW);
Ctr_DB_UpdateCtrWWW (Ctr_EditingCtr->CtrCod,NewWWW);
Str_Copy (Ctr_EditingCtr->WWW,NewWWW,sizeof (Ctr_EditingCtr->WWW) - 1);
/***** Write message to show the change made
@ -1489,7 +1497,7 @@ void Ctr_ChangeCtrWWW (void)
/**************** Update database changing old WWW by new WWW ****************/
/*****************************************************************************/
void Ctr_UpdateCtrWWWDB (long CtrCod,const char NewWWW[Cns_MAX_BYTES_WWW + 1])
void Ctr_DB_UpdateCtrWWW (long CtrCod,const char NewWWW[Cns_MAX_BYTES_WWW + 1])
{
/***** Update database changing old WWW by new WWW *****/
DB_QueryUPDATE ("can not update the web of a center",
@ -1859,17 +1867,17 @@ static void Ctr_ReceiveFormRequestOrCreateCtr (unsigned Status)
if (Ctr_EditingCtr->WWW[0])
{
/***** If name of center was in database... *****/
if (Ctr_CheckIfCtrNameExistsInIns ("ShortName",Ctr_EditingCtr->ShrtName,-1L,Gbl.Hierarchy.Ins.InsCod))
if (Ctr_DB_CheckIfCtrNameExistsInIns ("ShortName",Ctr_EditingCtr->ShrtName,-1L,Gbl.Hierarchy.Ins.InsCod))
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_center_X_already_exists,
Ctr_EditingCtr->ShrtName);
else if (Ctr_CheckIfCtrNameExistsInIns ("FullName",Ctr_EditingCtr->FullName,-1L,Gbl.Hierarchy.Ins.InsCod))
else if (Ctr_DB_CheckIfCtrNameExistsInIns ("FullName",Ctr_EditingCtr->FullName,-1L,Gbl.Hierarchy.Ins.InsCod))
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_center_X_already_exists,
Ctr_EditingCtr->FullName);
else // Add new center to database
{
Ctr_CreateCenter (Status);
Ctr_DB_CreateCenter (Status);
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_Created_new_center_X,
Ctr_EditingCtr->FullName);
@ -1888,7 +1896,7 @@ static void Ctr_ReceiveFormRequestOrCreateCtr (unsigned Status)
/***************************** Create a new center ***************************/
/*****************************************************************************/
static void Ctr_CreateCenter (unsigned Status)
static void Ctr_DB_CreateCenter (unsigned Status)
{
/***** Create a new center *****/
Ctr_EditingCtr->CtrCod =
@ -2114,7 +2122,7 @@ unsigned Ctr_GetCachedNumCtrsWithMapInIns (long InsCod)
/******* Get number of centers (of the current institution) in a place *******/
/*****************************************************************************/
unsigned Ctr_GetNumCtrsInPlc (long PlcCod)
unsigned Ctr_DB_GetNumCtrsInPlc (long PlcCod)
{
/***** Get number of centers (of the current institution) in a place *****/
return (unsigned)

View File

@ -118,14 +118,14 @@ void Ctr_PutParamCtrCod (long CtrCod);
long Ctr_GetAndCheckParamOtherCtrCod (long MinCodAllowed);
void Ctr_RemoveCenter (void);
void Ctr_ChangeCtrPlc (void);
void Ctr_UpdateCtrPlcDB (long CtrCod,long NewPlcCod);
void Ctr_DB_UpdateCtrPlc (long CtrCod,long NewPlcCod);
void Ctr_RenameCenterShort (void);
void Ctr_RenameCenterFull (void);
void Ctr_RenameCenter (struct Ctr_Center *Ctr,Cns_ShrtOrFullName_t ShrtOrFullName);
bool Ctr_CheckIfCtrNameExistsInIns (const char *FieldName,const char *Name,
bool Ctr_DB_CheckIfCtrNameExistsInIns (const char *FieldName,const char *Name,
long CtrCod,long InsCod);
void Ctr_ChangeCtrWWW (void);
void Ctr_UpdateCtrWWWDB (long CtrCod,const char NewWWW[Cns_MAX_BYTES_WWW + 1]);
void Ctr_DB_UpdateCtrWWW (long CtrCod,const char NewWWW[Cns_MAX_BYTES_WWW + 1]);
void Ctr_ChangeCtrStatus (void);
void Ctr_ContEditAfterChgCtr (void);
@ -145,7 +145,7 @@ unsigned Ctr_GetCachedNumCtrsWithMapInSys (void);
unsigned Ctr_GetCachedNumCtrsWithMapInCty (long CtyCod);
unsigned Ctr_GetCachedNumCtrsWithMapInIns (long InsCod);
unsigned Ctr_GetNumCtrsInPlc (long PlcCod);
unsigned Ctr_DB_GetNumCtrsInPlc (long PlcCod);
unsigned Ctr_GetCachedNumCtrsWithDegs (const char *SubQuery,
HieLvl_Level_t Scope,long Cod);

View File

@ -101,7 +101,7 @@ static void CtrCfg_NumUsrs (void);
static void CtrCfg_NumDegs (void);
static void CtrCfg_NumCrss (void);
static void CtrCfg_UpdateCtrInsDB (long CtrCod,long InsCod);
static void Ctr_DB_UpdateCtrIns (long CtrCod,long InsCod);
static void CtrCfg_UpdateCtrCoordinateDB (long CtrCod,
const char *CoordField,double NewCoord);
@ -606,10 +606,12 @@ static void CtrCfg_Institution (bool PrintView,bool PutForm)
"BT_LINK LT DAT",NULL);
Hie_FreeGoToMsg ();
}
Lgo_DrawLogo (HieLvl_INS,Gbl.Hierarchy.Ins.InsCod,Gbl.Hierarchy.Ins.ShrtName,
20,"LM",true);
HTM_NBSP ();
HTM_Txt (Gbl.Hierarchy.Ins.FullName);
if (!PrintView)
{
HTM_BUTTON_End ();
@ -1037,7 +1039,7 @@ void CtrCfg_ChangeCtrIns (void)
Ins_GetDataOfInstitutionByCod (&NewIns);
/***** Check if it already exists a center with the same name in the new institution *****/
if (Ctr_CheckIfCtrNameExistsInIns ("ShortName",
if (Ctr_DB_CheckIfCtrNameExistsInIns ("ShortName",
Gbl.Hierarchy.Ctr.ShrtName,
Gbl.Hierarchy.Ctr.CtrCod,
NewIns.InsCod))
@ -1045,7 +1047,7 @@ void CtrCfg_ChangeCtrIns (void)
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_center_X_already_exists,
Gbl.Hierarchy.Ctr.ShrtName);
else if (Ctr_CheckIfCtrNameExistsInIns ("FullName",
else if (Ctr_DB_CheckIfCtrNameExistsInIns ("FullName",
Gbl.Hierarchy.Ctr.FullName,
Gbl.Hierarchy.Ctr.CtrCod,
NewIns.InsCod))
@ -1056,7 +1058,7 @@ void CtrCfg_ChangeCtrIns (void)
else
{
/***** Update institution in table of centers *****/
CtrCfg_UpdateCtrInsDB (Gbl.Hierarchy.Ctr.CtrCod,NewIns.InsCod);
Ctr_DB_UpdateCtrIns (Gbl.Hierarchy.Ctr.CtrCod,NewIns.InsCod);
Gbl.Hierarchy.Ctr.InsCod =
Gbl.Hierarchy.Ins.InsCod = NewIns.InsCod;
@ -1075,7 +1077,7 @@ void CtrCfg_ChangeCtrIns (void)
/******************* Update institution in table of centers ******************/
/*****************************************************************************/
static void CtrCfg_UpdateCtrInsDB (long CtrCod,long InsCod)
static void Ctr_DB_UpdateCtrIns (long CtrCod,long InsCod)
{
/***** Update institution in table of centers *****/
DB_QueryUPDATE ("can not update the institution of a center",
@ -1099,7 +1101,7 @@ void CtrCfg_ChangeCtrPlc (void)
NewPlcCod = Plc_GetParamPlcCod ();
/***** Update place in table of centers *****/
Ctr_UpdateCtrPlcDB (Gbl.Hierarchy.Ctr.CtrCod,NewPlcCod);
Ctr_DB_UpdateCtrPlc (Gbl.Hierarchy.Ctr.CtrCod,NewPlcCod);
Gbl.Hierarchy.Ctr.PlcCod = NewPlcCod;
/***** Write message to show the change made *****/
@ -1222,7 +1224,7 @@ void CtrCfg_ChangeCtrWWW (void)
if (NewWWW[0])
{
/***** Update database changing old WWW by new WWW *****/
Ctr_UpdateCtrWWWDB (Gbl.Hierarchy.Ctr.CtrCod,NewWWW);
Ctr_DB_UpdateCtrWWW (Gbl.Hierarchy.Ctr.CtrCod,NewWWW);
Str_Copy (Gbl.Hierarchy.Ctr.WWW,NewWWW,sizeof (Gbl.Hierarchy.Ctr.WWW) - 1);
/***** Write message to show the change made *****/

70
swad_center_database.c Normal file
View File

@ -0,0 +1,70 @@
// swad_center_database.c: centers 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 <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/********************************* Headers ***********************************/
/*****************************************************************************/
// #include <stdbool.h> // For boolean type
// #include <stddef.h> // For NULL
// #include <stdlib.h> // For free
// #include <string.h> // For string functions
#include "swad_center.h"
#include "swad_center_config.h"
// #include "swad_database.h"
// #include "swad_error.h"
// #include "swad_figure.h"
// #include "swad_figure_cache.h"
// #include "swad_form.h"
// #include "swad_forum.h"
#include "swad_global.h"
// #include "swad_hierarchy.h"
// #include "swad_hierarchy_level.h"
// #include "swad_HTML.h"
// #include "swad_logo.h"
// #include "swad_message.h"
// #include "swad_place.h"
// #include "swad_survey.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/******************************* Private types *******************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private variables *****************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/

46
swad_center_database.h Normal file
View File

@ -0,0 +1,46 @@
// swad_center_database.h: centers operations with database
#ifndef _SWAD_CTR_DB
#define _SWAD_CTR_DB
/*
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 <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/********************************* Headers ***********************************/
/*****************************************************************************/
// #include <mysql/mysql.h> // To access MySQL databases
// #include "swad_action.h"
// #include "swad_constant.h"
// #include "swad_degree.h"
// #include "swad_map.h"
// #include "swad_role_type.h"
/*****************************************************************************/
/************************** Public types and constants ***********************/
/*****************************************************************************/
/*****************************************************************************/
/****************************** Public prototypes ****************************/
/*****************************************************************************/
#endif

View File

@ -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 20.87.1 (2021-06-01)"
#define Log_PLATFORM_VERSION "SWAD 20.88 (2021-06-02)"
#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 20.88: Jun 02, 2021 New module swad_center_database for database queries related to centers. (312638 lines)
Version 20.87.1: Jun 01, 2021 Database function moved from swad_calendar to swad_setting. (312549 lines)
Version 20.87: Jun 01, 2021 New module swad_building_database for database queries related to buildings. (312538 lines)
Version 20.86.1: May 31, 2021 Queries moved to module swad_call_for_exam_database. (312420 lines)

View File

@ -181,7 +181,7 @@ void Plc_SeePlaces (void)
HTM_TR_End ();
/***** Write centers (of the current institution) with other place *****/
NumCtrsInOtherPlcs = Ctr_GetNumCtrsInPlc (0);
NumCtrsInOtherPlcs = Ctr_DB_GetNumCtrsInPlc (0);
HTM_TR_Begin (NULL);
HTM_TD_Begin ("class=\"DAT LM\"");