Version 20.89: Jun 02, 2021 New module swad_department_database for database queries related to departments.

This commit is contained in:
acanas 2021-06-02 23:48:43 +02:00
parent b71f3fc86e
commit 1dbe256cbd
9 changed files with 412 additions and 319 deletions

View File

@ -41,7 +41,7 @@ OBJS = swad_account.o swad_account_database.o swad_action.o swad_agenda.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 \
swad_department_database.o swad_duplicate.o \
swad_enrolment.o swad_error.o swad_exam.o swad_exam_log.o \
swad_exam_print.o swad_exam_result.o swad_exam_session.o \
swad_exam_set.o \

View File

@ -25,27 +25,11 @@
/********************************* 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 ****************/

View File

@ -29,13 +29,9 @@
#include <mysql/mysql.h> // To access MySQL databases
// #include "swad_action.h"
#include "swad_center.h"
#include "swad_constant.h"
// #include "swad_degree.h"
// #include "swad_map.h"
#include "swad_media.h"
// #include "swad_role_type.h"
/*****************************************************************************/
/************************** Public types and constants ***********************/

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.88.3 (2021-06-02)"
#define Log_PLATFORM_VERSION "SWAD 20.89 (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.89: Jun 02, 2021 New module swad_department_database for database queries related to departments. (312824 lines)
Version 20.88.3: Jun 02, 2021 Queries moved to module swad_center_database. (312755 lines)
Version 20.88.2: Jun 02, 2021 Queries moved to module swad_center_database.
Fixed bug in visibility of exam results. Reported by Mancia Anguita López. (312738 lines)

View File

@ -34,6 +34,7 @@
#include "swad_constant.h"
#include "swad_database.h"
#include "swad_department.h"
#include "swad_department_database.h"
#include "swad_error.h"
#include "swad_form.h"
#include "swad_global.h"
@ -79,12 +80,9 @@ static void Dpt_ListDepartmentsForEdition (const struct Dpt_Departments *Departm
static void Dpt_PutParamDptCod (void *DptCod);
static void Dpt_RenameDepartment (Cns_ShrtOrFullName_t ShrtOrFullName);
static bool Dpt_CheckIfDepartmentNameExists (const char *FieldName,const char *Name,long DptCod);
static void Dpt_UpdateDegNameDB (long DptCod,const char *FieldName,const char *NewDptName);
static void Dpt_PutFormToCreateDepartment (void);
static void Dpt_PutHeadDepartments (void);
static void Dpt_CreateDepartment (struct Dpt_Department *Dpt);
static void Dpt_EditingDepartmentConstructor (void);
static void Dpt_EditingDepartmentDestructor (void);
@ -506,21 +504,6 @@ void Dpt_FreeListDepartments (struct Dpt_Departments *Departments)
Departments->Num = 0;
}
/*****************************************************************************/
/************** Get number of departments in an institution ******************/
/*****************************************************************************/
unsigned Dpt_GetNumDepartmentsInInstitution (long InsCod)
{
/***** Get number of departments in an institution from database *****/
return (unsigned)
DB_QueryCOUNT ("can not get number of departments in an institution",
"SELECT COUNT(*)"
" FROM dpt_departments"
" WHERE InsCod=%ld",
InsCod);
}
/*****************************************************************************/
/************************** List all the departments *************************/
/*****************************************************************************/
@ -797,14 +780,14 @@ static void Dpt_RenameDepartment (Cns_ShrtOrFullName_t ShrtOrFullName)
if (strcmp (CurrentDptName,NewDptName)) // Different names
{
/***** If degree was in database... *****/
if (Dpt_CheckIfDepartmentNameExists (ParamName,NewDptName,Dpt_EditingDpt->DptCod))
if (Dpt_DB_CheckIfDepartmentNameExists (ParamName,NewDptName,Dpt_EditingDpt->DptCod))
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_department_X_already_exists,
NewDptName);
else
{
/* Update the table changing old name by new name */
Dpt_UpdateDegNameDB (Dpt_EditingDpt->DptCod,FieldName,NewDptName);
Dpt_DB_UpdateDegName (Dpt_EditingDpt->DptCod,FieldName,NewDptName);
/* Write message to show the change made */
Ale_CreateAlert (Ale_SUCCESS,NULL,
@ -824,37 +807,6 @@ static void Dpt_RenameDepartment (Cns_ShrtOrFullName_t ShrtOrFullName)
Str_Copy (CurrentDptName,NewDptName,MaxBytes);
}
/*****************************************************************************/
/******************* Check if the name of department exists ******************/
/*****************************************************************************/
static bool Dpt_CheckIfDepartmentNameExists (const char *FieldName,const char *Name,long DptCod)
{
/***** Get number of departments with a name from database *****/
return (DB_QueryCOUNT ("can not check if the department name already existed",
"SELECT COUNT(*)"
" FROM dpt_departments"
" WHERE %s='%s'"
" AND DptCod<>%ld",
FieldName,Name,
DptCod) != 0);
}
/*****************************************************************************/
/************* Update department name in table of departments ****************/
/*****************************************************************************/
static void Dpt_UpdateDegNameDB (long DptCod,const char *FieldName,const char *NewDptName)
{
/***** Update department changing old name by new name *****/
DB_QueryUPDATE ("can not update the name of a department",
"UPDATE dpt_departments"
" SET %s='%s'"
" WHERE DptCod=%ld",
FieldName,NewDptName,
DptCod);
}
/******************************************************************************/
/*********************** Change the URL of a department *********************/
/*****************************************************************************/
@ -1054,17 +1006,17 @@ void Dpt_ReceiveFormNewDpt (void)
if (Dpt_EditingDpt->WWW[0])
{
/***** If name of department was in database... *****/
if (Dpt_CheckIfDepartmentNameExists ("ShortName",Dpt_EditingDpt->ShrtName,-1L))
if (Dpt_DB_CheckIfDepartmentNameExists ("ShortName",Dpt_EditingDpt->ShrtName,-1L))
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_department_X_already_exists,
Dpt_EditingDpt->ShrtName);
else if (Dpt_CheckIfDepartmentNameExists ("FullName",Dpt_EditingDpt->FullName,-1L))
else if (Dpt_DB_CheckIfDepartmentNameExists ("FullName",Dpt_EditingDpt->FullName,-1L))
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_department_X_already_exists,
Dpt_EditingDpt->FullName);
else // Add new department to database
{
Dpt_CreateDepartment (Dpt_EditingDpt);
Dpt_DB_CreateDepartment (Dpt_EditingDpt);
Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_Created_new_department_X,
Dpt_EditingDpt->FullName);
@ -1079,24 +1031,6 @@ void Dpt_ReceiveFormNewDpt (void)
Txt_You_must_specify_the_short_name_and_the_full_name_of_the_new_department);
}
/*****************************************************************************/
/************************** Create a new department **************************/
/*****************************************************************************/
static void Dpt_CreateDepartment (struct Dpt_Department *Dpt)
{
/***** Create a new department *****/
DB_QueryINSERT ("can not create a new department",
"INSERT INTO dpt_departments"
" (InsCod,ShortName,FullName,WWW)"
" VALUES"
" (%ld,'%s','%s','%s')",
Dpt->InsCod,
Dpt->ShrtName,
Dpt->FullName,
Dpt->WWW);
}
/*****************************************************************************/
/************************** Get number of departments ************************/
/*****************************************************************************/

View File

@ -67,7 +67,6 @@ struct Dpt_Departments
void Dpt_SeeDepts (void);
void Dpt_EditDepartments (void);
void Dpt_FreeListDepartments (struct Dpt_Departments *Departments);
unsigned Dpt_GetNumDepartmentsInInstitution (long InsCod);
void Dpt_GetDataOfDepartmentByCod (struct Dpt_Department *Dpt);
long Dpt_GetAndCheckParamDptCod (long MinCodAllowed);
void Dpt_RemoveDepartment (void);

131
swad_department_database.c Normal file
View File

@ -0,0 +1,131 @@
// swad_department_database.c: departments 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 calloc
// #include <string.h> // For string functions
// #include "swad_box.h"
// #include "swad_constant.h"
#include "swad_database.h"
#include "swad_department.h"
#include "swad_department_database.h"
// #include "swad_error.h"
// #include "swad_form.h"
#include "swad_global.h"
// #include "swad_HTML.h"
// #include "swad_institution.h"
// #include "swad_language.h"
// #include "swad_parameter.h"
// #include "swad_string.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/******************************* Private types *******************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private variables *****************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
/*****************************************************************************/
/************************** Create a new department **************************/
/*****************************************************************************/
void Dpt_DB_CreateDepartment (const struct Dpt_Department *Dpt)
{
/***** Create a new department *****/
DB_QueryINSERT ("can not create a new department",
"INSERT INTO dpt_departments"
" (InsCod,ShortName,FullName,WWW)"
" VALUES"
" (%ld,'%s','%s','%s')",
Dpt->InsCod,
Dpt->ShrtName,
Dpt->FullName,
Dpt->WWW);
}
/*****************************************************************************/
/******************* Check if the name of department exists ******************/
/*****************************************************************************/
bool Dpt_DB_CheckIfDepartmentNameExists (const char *FieldName,const char *Name,long DptCod)
{
/***** Get number of departments with a name from database *****/
return (DB_QueryCOUNT ("can not check if the department name already existed",
"SELECT COUNT(*)"
" FROM dpt_departments"
" WHERE %s='%s'"
" AND DptCod<>%ld",
FieldName,Name,
DptCod) != 0);
}
/*****************************************************************************/
/************** Get number of departments in an institution ******************/
/*****************************************************************************/
unsigned Dpt_DB_GetNumDepartmentsInInstitution (long InsCod)
{
/***** Get number of departments in an institution from database *****/
return (unsigned)
DB_QueryCOUNT ("can not get number of departments in an institution",
"SELECT COUNT(*)"
" FROM dpt_departments"
" WHERE InsCod=%ld",
InsCod);
}
/*****************************************************************************/
/************* Update department name in table of departments ****************/
/*****************************************************************************/
void Dpt_DB_UpdateDegName (long DptCod,const char *FieldName,const char *NewDptName)
{
/***** Update department changing old name by new name *****/
DB_QueryUPDATE ("can not update the name of a department",
"UPDATE dpt_departments"
" SET %s='%s'"
" WHERE DptCod=%ld",
FieldName,NewDptName,
DptCod);
}

View File

@ -0,0 +1,48 @@
// swad_department_database.h: departments operations with database
#ifndef _SWAD_DPT_DB
#define _SWAD_DPT_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 <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/********************************* Headers ***********************************/
/*****************************************************************************/
// #include "swad_constant.h"
#include "swad_department.h"
/*****************************************************************************/
/************************** Public types and constants ***********************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Public prototypes *****************************/
/*****************************************************************************/
void Dpt_DB_CreateDepartment (const struct Dpt_Department *Dpt);
bool Dpt_DB_CheckIfDepartmentNameExists (const char *FieldName,const char *Name,long DptCod);
unsigned Dpt_DB_GetNumDepartmentsInInstitution (long InsCod);
void Dpt_DB_UpdateDegName (long DptCod,const char *FieldName,const char *NewDptName);
#endif

View File

@ -32,7 +32,7 @@
#include <stdlib.h> // For free
#include "swad_database.h"
#include "swad_department.h"
#include "swad_department_database.h"
#include "swad_error.h"
#include "swad_figure_cache.h"
#include "swad_form.h"
@ -535,7 +535,7 @@ static void InsCfg_NumDpts (void)
/* Data */
HTM_TD_Begin ("class=\"DAT LB\"");
HTM_Unsigned (Dpt_GetNumDepartmentsInInstitution (Gbl.Hierarchy.Ins.InsCod));
HTM_Unsigned (Dpt_DB_GetNumDepartmentsInInstitution (Gbl.Hierarchy.Ins.InsCod));
HTM_TD_End ();
HTM_TR_End ();