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_cryptography.o \
swad_database.o swad_date.o swad_degree.o swad_degree_config.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_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_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_print.o swad_exam_result.o swad_exam_session.o \
swad_exam_set.o \ swad_exam_set.o \

View File

@ -25,27 +25,11 @@
/********************************* Headers ***********************************/ /********************************* 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.h"
#include "swad_center_config.h" #include "swad_center_config.h"
#include "swad_database.h" #include "swad_database.h"
#include "swad_error.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_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 ****************/ /************** External global variables from others modules ****************/

View File

@ -29,13 +29,9 @@
#include <mysql/mysql.h> // To access MySQL databases #include <mysql/mysql.h> // To access MySQL databases
// #include "swad_action.h"
#include "swad_center.h" #include "swad_center.h"
#include "swad_constant.h" #include "swad_constant.h"
// #include "swad_degree.h"
// #include "swad_map.h"
#include "swad_media.h" #include "swad_media.h"
// #include "swad_role_type.h"
/*****************************************************************************/ /*****************************************************************************/
/************************** Public types and constants ***********************/ /************************** 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. 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 CSS_FILE "swad20.45.css"
#define JS_FILE "swad20.69.1.js" #define JS_FILE "swad20.69.1.js"
/* /*
TODO: Rename CENTRE to CENTER in help wiki. TODO: Rename CENTRE to CENTER in help wiki.
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams 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.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. 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) 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_constant.h"
#include "swad_database.h" #include "swad_database.h"
#include "swad_department.h" #include "swad_department.h"
#include "swad_department_database.h"
#include "swad_error.h" #include "swad_error.h"
#include "swad_form.h" #include "swad_form.h"
#include "swad_global.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_PutParamDptCod (void *DptCod);
static void Dpt_RenameDepartment (Cns_ShrtOrFullName_t ShrtOrFullName); 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_PutFormToCreateDepartment (void);
static void Dpt_PutHeadDepartments (void); static void Dpt_PutHeadDepartments (void);
static void Dpt_CreateDepartment (struct Dpt_Department *Dpt);
static void Dpt_EditingDepartmentConstructor (void); static void Dpt_EditingDepartmentConstructor (void);
static void Dpt_EditingDepartmentDestructor (void); static void Dpt_EditingDepartmentDestructor (void);
@ -144,88 +142,88 @@ void Dpt_SeeDepts (void)
Hlp_INSTITUTION_Departments,Box_NOT_CLOSABLE,2); Hlp_INSTITUTION_Departments,Box_NOT_CLOSABLE,2);
Str_FreeString (); Str_FreeString ();
/***** Write heading *****/ /***** Write heading *****/
HTM_TR_Begin (NULL); HTM_TR_Begin (NULL);
for (Order = Dpt_ORDER_BY_DEPARTMENT; for (Order = Dpt_ORDER_BY_DEPARTMENT;
Order <= Dpt_ORDER_BY_NUM_TCHS; Order <= Dpt_ORDER_BY_NUM_TCHS;
Order++) Order++)
{ {
HTM_TH_Begin (1,1,Order == Dpt_ORDER_BY_NUM_TCHS ? "RM" : HTM_TH_Begin (1,1,Order == Dpt_ORDER_BY_NUM_TCHS ? "RM" :
"LM"); "LM");
Frm_BeginForm (ActSeeDpt); Frm_BeginForm (ActSeeDpt);
Par_PutHiddenParamUnsigned (NULL,"Order",(unsigned) Order); Par_PutHiddenParamUnsigned (NULL,"Order",(unsigned) Order);
HTM_BUTTON_SUBMIT_Begin (Txt_DEPARTMENTS_HELP_ORDER[Order],"BT_LINK TIT_TBL",NULL); HTM_BUTTON_SUBMIT_Begin (Txt_DEPARTMENTS_HELP_ORDER[Order],"BT_LINK TIT_TBL",NULL);
if (Order == Departments.SelectedOrder) if (Order == Departments.SelectedOrder)
HTM_U_Begin (); HTM_U_Begin ();
HTM_Txt (Txt_DEPARTMENTS_ORDER[Order]); HTM_Txt (Txt_DEPARTMENTS_ORDER[Order]);
if (Order == Departments.SelectedOrder) if (Order == Departments.SelectedOrder)
HTM_U_End (); HTM_U_End ();
HTM_BUTTON_End (); HTM_BUTTON_End ();
Frm_EndForm (); Frm_EndForm ();
HTM_TH_End (); HTM_TH_End ();
} }
HTM_TR_End (); HTM_TR_End ();
/***** Write all the Dpt_GetListDepartmentsdepartments and their nuber of teachers *****/
for (NumDpt = 0;
NumDpt < Departments.Num;
NumDpt++)
{
/* Write data of this department */
HTM_TR_Begin (NULL);
HTM_TD_Begin ("class=\"LM\"");
HTM_A_Begin ("href=\"%s\" target=\"_blank\" class=\"DAT\"",
Departments.Lst[NumDpt].WWW);
HTM_Txt (Departments.Lst[NumDpt].FullName);
HTM_A_End ();
HTM_TD_End ();
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Unsigned (Departments.Lst[NumDpt].NumTchs);
HTM_TD_End ();
HTM_TR_End ();
}
/***** Separation row *****/
HTM_TR_Begin (NULL);
HTM_TD_Begin ("colspan=\"3\" class=\"DAT\"");
HTM_NBSP ();
HTM_TD_End ();
HTM_TR_End ();
/***** Write teachers of this institution with other department *****/
NumTchsInsInOtherDpts = Usr_GetNumTchsCurrentInsInDepartment (0);
/***** Write all the Dpt_GetListDepartmentsdepartments and their nuber of teachers *****/
for (NumDpt = 0;
NumDpt < Departments.Num;
NumDpt++)
{
/* Write data of this department */
HTM_TR_Begin (NULL); HTM_TR_Begin (NULL);
HTM_TD_Begin ("class=\"LM\""); HTM_TD_Begin ("class=\"DAT LM\"");
HTM_A_Begin ("href=\"%s\" target=\"_blank\" class=\"DAT\"", HTM_Txt (Txt_Other_departments);
Departments.Lst[NumDpt].WWW); HTM_TD_End ();
HTM_Txt (Departments.Lst[NumDpt].FullName);
HTM_A_End ();
HTM_TD_End ();
HTM_TD_Begin ("class=\"DAT RM\""); HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Unsigned (Departments.Lst[NumDpt].NumTchs); HTM_Unsigned (NumTchsInsInOtherDpts);
HTM_TD_End (); HTM_TD_End ();
HTM_TR_End (); HTM_TR_End ();
}
/***** Separation row *****/ /***** Write teachers with no department *****/
HTM_TR_Begin (NULL); NumTchsInsWithNoDpt = Usr_GetNumTchsCurrentInsInDepartment (-1L);
HTM_TD_Begin ("colspan=\"3\" class=\"DAT\"");
HTM_NBSP ();
HTM_TD_End ();
HTM_TR_End ();
/***** Write teachers of this institution with other department *****/ HTM_TR_Begin (NULL);
NumTchsInsInOtherDpts = Usr_GetNumTchsCurrentInsInDepartment (0);
HTM_TR_Begin (NULL); HTM_TD_Begin ("class=\"DAT LM\"");
HTM_Txt (Txt_Department_unspecified);
HTM_TD_End ();
HTM_TD_Begin ("class=\"DAT LM\""); HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Txt (Txt_Other_departments); HTM_Unsigned (NumTchsInsWithNoDpt);
HTM_TD_End (); HTM_TD_End ();
HTM_TD_Begin ("class=\"DAT RM\""); HTM_TR_End ();
HTM_Unsigned (NumTchsInsInOtherDpts);
HTM_TD_End ();
HTM_TR_End ();
/***** Write teachers with no department *****/
NumTchsInsWithNoDpt = Usr_GetNumTchsCurrentInsInDepartment (-1L);
HTM_TR_Begin (NULL);
HTM_TD_Begin ("class=\"DAT LM\"");
HTM_Txt (Txt_Department_unspecified);
HTM_TD_End ();
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Unsigned (NumTchsInsWithNoDpt);
HTM_TD_End ();
HTM_TR_End ();
/***** End table and box *****/ /***** End table and box *****/
Box_BoxTableEnd (); Box_BoxTableEnd ();
@ -298,12 +296,12 @@ static void Dpt_EditDepartmentsInternal (void)
Hlp_INSTITUTION_Departments_edit,Box_NOT_CLOSABLE); Hlp_INSTITUTION_Departments_edit,Box_NOT_CLOSABLE);
Str_FreeString (); Str_FreeString ();
/***** Put a form to create a new department *****/ /***** Put a form to create a new department *****/
Dpt_PutFormToCreateDepartment (); Dpt_PutFormToCreateDepartment ();
/***** Forms to edit current departments *****/ /***** Forms to edit current departments *****/
if (Departments.Num) if (Departments.Num)
Dpt_ListDepartmentsForEdition (&Departments); Dpt_ListDepartmentsForEdition (&Departments);
/***** End box *****/ /***** End box *****/
Box_BoxEnd (); Box_BoxEnd ();
@ -506,21 +504,6 @@ void Dpt_FreeListDepartments (struct Dpt_Departments *Departments)
Departments->Num = 0; 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 *************************/ /************************** List all the departments *************************/
/*****************************************************************************/ /*****************************************************************************/
@ -536,90 +519,90 @@ static void Dpt_ListDepartmentsForEdition (const struct Dpt_Departments *Departm
/***** Begin table *****/ /***** Begin table *****/
HTM_TABLE_BeginPadding (2); HTM_TABLE_BeginPadding (2);
/***** Write heading *****/ /***** Write heading *****/
Dpt_PutHeadDepartments (); Dpt_PutHeadDepartments ();
/***** Write all the departments *****/ /***** Write all the departments *****/
for (NumDpt = 0; for (NumDpt = 0;
NumDpt < Departments->Num; NumDpt < Departments->Num;
NumDpt++) NumDpt++)
{ {
Dpt = &Departments->Lst[NumDpt]; Dpt = &Departments->Lst[NumDpt];
/* Get data of institution of this department */ /* Get data of institution of this department */
Ins.InsCod = Dpt->InsCod; Ins.InsCod = Dpt->InsCod;
Ins_GetDataOfInstitutionByCod (&Ins); Ins_GetDataOfInstitutionByCod (&Ins);
HTM_TR_Begin (NULL); HTM_TR_Begin (NULL);
/* Put icon to remove department */ /* Put icon to remove department */
HTM_TD_Begin ("class=\"BM\""); HTM_TD_Begin ("class=\"BM\"");
if (Dpt->NumTchs) // Department has teachers ==> deletion forbidden if (Dpt->NumTchs) // Department has teachers ==> deletion forbidden
Ico_PutIconRemovalNotAllowed (); Ico_PutIconRemovalNotAllowed ();
else else
Ico_PutContextualIconToRemove (ActRemDpt,NULL, Ico_PutContextualIconToRemove (ActRemDpt,NULL,
Dpt_PutParamDptCod,&Dpt->DptCod); Dpt_PutParamDptCod,&Dpt->DptCod);
HTM_TD_End (); HTM_TD_End ();
/* Department code */ /* Department code */
HTM_TD_Begin ("class=\"DAT RM\""); HTM_TD_Begin ("class=\"DAT RM\"");
HTM_TxtF ("%ld&nbsp;",Dpt->DptCod); HTM_TxtF ("%ld&nbsp;",Dpt->DptCod);
HTM_TD_End (); HTM_TD_End ();
/* Institution */ /* Institution */
HTM_TD_Begin ("class=\"CM\""); HTM_TD_Begin ("class=\"CM\"");
Frm_BeginForm (ActChgDptIns); Frm_BeginForm (ActChgDptIns);
Dpt_PutParamDptCod (&Dpt->DptCod); Dpt_PutParamDptCod (&Dpt->DptCod);
HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE, HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE,
"name=\"OthInsCod\" class=\"HIE_SEL_NARROW\""); "name=\"OthInsCod\" class=\"HIE_SEL_NARROW\"");
HTM_OPTION (HTM_Type_STRING,"0",Dpt->InsCod == 0,false, HTM_OPTION (HTM_Type_STRING,"0",Dpt->InsCod == 0,false,
"%s",Txt_Another_institution); "%s",Txt_Another_institution);
for (NumIns = 0; for (NumIns = 0;
NumIns < Gbl.Hierarchy.Inss.Num; NumIns < Gbl.Hierarchy.Inss.Num;
NumIns++) NumIns++)
HTM_OPTION (HTM_Type_LONG,&Gbl.Hierarchy.Inss.Lst[NumIns].InsCod, HTM_OPTION (HTM_Type_LONG,&Gbl.Hierarchy.Inss.Lst[NumIns].InsCod,
Gbl.Hierarchy.Inss.Lst[NumIns].InsCod == Dpt->InsCod,false, Gbl.Hierarchy.Inss.Lst[NumIns].InsCod == Dpt->InsCod,false,
"%s",Gbl.Hierarchy.Inss.Lst[NumIns].ShrtName); "%s",Gbl.Hierarchy.Inss.Lst[NumIns].ShrtName);
HTM_SELECT_End (); HTM_SELECT_End ();
Frm_EndForm (); Frm_EndForm ();
HTM_TD_End (); HTM_TD_End ();
/* Department short name */ /* Department short name */
HTM_TD_Begin ("class=\"CM\""); HTM_TD_Begin ("class=\"CM\"");
Frm_BeginForm (ActRenDptSho); Frm_BeginForm (ActRenDptSho);
Dpt_PutParamDptCod (&Dpt->DptCod); Dpt_PutParamDptCod (&Dpt->DptCod);
HTM_INPUT_TEXT ("ShortName",Cns_HIERARCHY_MAX_CHARS_SHRT_NAME,Dpt->ShrtName, HTM_INPUT_TEXT ("ShortName",Cns_HIERARCHY_MAX_CHARS_SHRT_NAME,Dpt->ShrtName,
HTM_SUBMIT_ON_CHANGE, HTM_SUBMIT_ON_CHANGE,
"class=\"INPUT_SHORT_NAME\""); "class=\"INPUT_SHORT_NAME\"");
Frm_EndForm (); Frm_EndForm ();
HTM_TD_End (); HTM_TD_End ();
/* Department full name */ /* Department full name */
HTM_TD_Begin ("class=\"CM\""); HTM_TD_Begin ("class=\"CM\"");
Frm_BeginForm (ActRenDptFul); Frm_BeginForm (ActRenDptFul);
Dpt_PutParamDptCod (&Dpt->DptCod); Dpt_PutParamDptCod (&Dpt->DptCod);
HTM_INPUT_TEXT ("FullName",Cns_HIERARCHY_MAX_CHARS_FULL_NAME,Dpt->FullName, HTM_INPUT_TEXT ("FullName",Cns_HIERARCHY_MAX_CHARS_FULL_NAME,Dpt->FullName,
HTM_SUBMIT_ON_CHANGE, HTM_SUBMIT_ON_CHANGE,
"class=\"INPUT_FULL_NAME\""); "class=\"INPUT_FULL_NAME\"");
Frm_EndForm (); Frm_EndForm ();
HTM_TD_End (); HTM_TD_End ();
/* Department WWW */ /* Department WWW */
HTM_TD_Begin ("class=\"CM\""); HTM_TD_Begin ("class=\"CM\"");
Frm_BeginForm (ActChgDptWWW); Frm_BeginForm (ActChgDptWWW);
Dpt_PutParamDptCod (&Dpt->DptCod); Dpt_PutParamDptCod (&Dpt->DptCod);
HTM_INPUT_URL ("WWW",Dpt->WWW,HTM_SUBMIT_ON_CHANGE, HTM_INPUT_URL ("WWW",Dpt->WWW,HTM_SUBMIT_ON_CHANGE,
"class=\"INPUT_WWW_NARROW\" required=\"required\""); "class=\"INPUT_WWW_NARROW\" required=\"required\"");
Frm_EndForm (); Frm_EndForm ();
HTM_TD_End (); HTM_TD_End ();
/* Number of teachers */ /* Number of teachers */
HTM_TD_Begin ("class=\"DAT RM\""); HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Unsigned (Dpt->NumTchs); HTM_Unsigned (Dpt->NumTchs);
HTM_TD_End (); HTM_TD_End ();
HTM_TR_End (); HTM_TR_End ();
} }
/***** End table *****/ /***** End table *****/
HTM_TABLE_End (); HTM_TABLE_End ();
@ -797,14 +780,14 @@ static void Dpt_RenameDepartment (Cns_ShrtOrFullName_t ShrtOrFullName)
if (strcmp (CurrentDptName,NewDptName)) // Different names if (strcmp (CurrentDptName,NewDptName)) // Different names
{ {
/***** If degree was in database... *****/ /***** 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, Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_department_X_already_exists, Txt_The_department_X_already_exists,
NewDptName); NewDptName);
else else
{ {
/* Update the table changing old name by new name */ /* 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 */ /* Write message to show the change made */
Ale_CreateAlert (Ale_SUCCESS,NULL, Ale_CreateAlert (Ale_SUCCESS,NULL,
@ -824,37 +807,6 @@ static void Dpt_RenameDepartment (Cns_ShrtOrFullName_t ShrtOrFullName)
Str_Copy (CurrentDptName,NewDptName,MaxBytes); 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 *********************/ /*********************** Change the URL of a department *********************/
/*****************************************************************************/ /*****************************************************************************/
@ -934,62 +886,62 @@ static void Dpt_PutFormToCreateDepartment (void)
/***** Begin form *****/ /***** Begin form *****/
Frm_BeginForm (ActNewDpt); Frm_BeginForm (ActNewDpt);
/***** Begin box and table *****/ /***** Begin box and table *****/
Box_BoxTableBegin (NULL,Txt_New_department, Box_BoxTableBegin (NULL,Txt_New_department,
NULL,NULL, NULL,NULL,
NULL,Box_NOT_CLOSABLE,2); NULL,Box_NOT_CLOSABLE,2);
/***** Write heading *****/ /***** Write heading *****/
HTM_TR_Begin (NULL); HTM_TR_Begin (NULL);
HTM_TH (1,1,"LM",Txt_Institution); HTM_TH (1,1,"LM",Txt_Institution);
HTM_TH (1,1,"LM",Txt_Short_name); HTM_TH (1,1,"LM",Txt_Short_name);
HTM_TH (1,1,"LM",Txt_Full_name); HTM_TH (1,1,"LM",Txt_Full_name);
HTM_TH (1,1,"LM",Txt_WWW); HTM_TH (1,1,"LM",Txt_WWW);
HTM_TR_End (); HTM_TR_End ();
HTM_TR_Begin (NULL); HTM_TR_Begin (NULL);
/***** Institution *****/ /***** Institution *****/
HTM_TD_Begin ("class=\"CM\""); HTM_TD_Begin ("class=\"CM\"");
HTM_SELECT_Begin (HTM_DONT_SUBMIT_ON_CHANGE, HTM_SELECT_Begin (HTM_DONT_SUBMIT_ON_CHANGE,
"name=\"OthInsCod\" class=\"HIE_SEL_NARROW\""); "name=\"OthInsCod\" class=\"HIE_SEL_NARROW\"");
HTM_OPTION (HTM_Type_STRING,"0",Dpt_EditingDpt->InsCod == 0,false, HTM_OPTION (HTM_Type_STRING,"0",Dpt_EditingDpt->InsCod == 0,false,
"%s",Txt_Another_institution); "%s",Txt_Another_institution);
for (NumIns = 0; for (NumIns = 0;
NumIns < Gbl.Hierarchy.Inss.Num; NumIns < Gbl.Hierarchy.Inss.Num;
NumIns++) NumIns++)
HTM_OPTION (HTM_Type_LONG,&Gbl.Hierarchy.Inss.Lst[NumIns].InsCod, HTM_OPTION (HTM_Type_LONG,&Gbl.Hierarchy.Inss.Lst[NumIns].InsCod,
Gbl.Hierarchy.Inss.Lst[NumIns].InsCod == Dpt_EditingDpt->InsCod,false, Gbl.Hierarchy.Inss.Lst[NumIns].InsCod == Dpt_EditingDpt->InsCod,false,
"%s",Gbl.Hierarchy.Inss.Lst[NumIns].ShrtName); "%s",Gbl.Hierarchy.Inss.Lst[NumIns].ShrtName);
HTM_SELECT_End (); HTM_SELECT_End ();
HTM_TD_End (); HTM_TD_End ();
/***** Department short name *****/ /***** Department short name *****/
HTM_TD_Begin ("class=\"CM\""); HTM_TD_Begin ("class=\"CM\"");
HTM_INPUT_TEXT ("ShortName",Cns_HIERARCHY_MAX_CHARS_SHRT_NAME,Dpt_EditingDpt->ShrtName, HTM_INPUT_TEXT ("ShortName",Cns_HIERARCHY_MAX_CHARS_SHRT_NAME,Dpt_EditingDpt->ShrtName,
HTM_DONT_SUBMIT_ON_CHANGE, HTM_DONT_SUBMIT_ON_CHANGE,
"class=\"INPUT_SHORT_NAME\" required=\"required\""); "class=\"INPUT_SHORT_NAME\" required=\"required\"");
HTM_TD_End (); HTM_TD_End ();
/***** Department full name *****/ /***** Department full name *****/
HTM_TD_Begin ("class=\"CM\""); HTM_TD_Begin ("class=\"CM\"");
HTM_INPUT_TEXT ("FullName",Cns_HIERARCHY_MAX_CHARS_FULL_NAME,Dpt_EditingDpt->FullName, HTM_INPUT_TEXT ("FullName",Cns_HIERARCHY_MAX_CHARS_FULL_NAME,Dpt_EditingDpt->FullName,
HTM_DONT_SUBMIT_ON_CHANGE, HTM_DONT_SUBMIT_ON_CHANGE,
"class=\"INPUT_FULL_NAME\" required=\"required\""); "class=\"INPUT_FULL_NAME\" required=\"required\"");
HTM_TD_End (); HTM_TD_End ();
/***** Department WWW *****/ /***** Department WWW *****/
HTM_TD_Begin ("class=\"CM\""); HTM_TD_Begin ("class=\"CM\"");
HTM_INPUT_URL ("WWW",Dpt_EditingDpt->WWW,HTM_DONT_SUBMIT_ON_CHANGE, HTM_INPUT_URL ("WWW",Dpt_EditingDpt->WWW,HTM_DONT_SUBMIT_ON_CHANGE,
"class=\"INPUT_WWW_NARROW\" required=\"required\""); "class=\"INPUT_WWW_NARROW\" required=\"required\"");
HTM_TD_End (); HTM_TD_End ();
HTM_TR_End (); HTM_TR_End ();
/***** End table, send button and end box *****/ /***** End table, send button and end box *****/
Box_BoxTableWithButtonEnd (Btn_CREATE_BUTTON,Txt_Create_department); Box_BoxTableWithButtonEnd (Btn_CREATE_BUTTON,Txt_Create_department);
/***** End form *****/ /***** End form *****/
Frm_EndForm (); Frm_EndForm ();
@ -1010,13 +962,13 @@ static void Dpt_PutHeadDepartments (void)
HTM_TR_Begin (NULL); HTM_TR_Begin (NULL);
HTM_TH_Empty (1); HTM_TH_Empty (1);
HTM_TH (1,1,"RM",Txt_Code); HTM_TH (1,1,"RM",Txt_Code);
HTM_TH (1,1,"LM",Txt_Institution); HTM_TH (1,1,"LM",Txt_Institution);
HTM_TH (1,1,"LM",Txt_Short_name); HTM_TH (1,1,"LM",Txt_Short_name);
HTM_TH (1,1,"LM",Txt_Full_name); HTM_TH (1,1,"LM",Txt_Full_name);
HTM_TH (1,1,"LM",Txt_WWW); HTM_TH (1,1,"LM",Txt_WWW);
HTM_TH (1,1,"RM",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH]); HTM_TH (1,1,"RM",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH]);
HTM_TR_End (); HTM_TR_End ();
} }
@ -1054,17 +1006,17 @@ void Dpt_ReceiveFormNewDpt (void)
if (Dpt_EditingDpt->WWW[0]) if (Dpt_EditingDpt->WWW[0])
{ {
/***** If name of department was in database... *****/ /***** 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, Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_department_X_already_exists, Txt_The_department_X_already_exists,
Dpt_EditingDpt->ShrtName); 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, Ale_CreateAlert (Ale_WARNING,NULL,
Txt_The_department_X_already_exists, Txt_The_department_X_already_exists,
Dpt_EditingDpt->FullName); Dpt_EditingDpt->FullName);
else // Add new department to database else // Add new department to database
{ {
Dpt_CreateDepartment (Dpt_EditingDpt); Dpt_DB_CreateDepartment (Dpt_EditingDpt);
Ale_CreateAlert (Ale_SUCCESS,NULL, Ale_CreateAlert (Ale_SUCCESS,NULL,
Txt_Created_new_department_X, Txt_Created_new_department_X,
Dpt_EditingDpt->FullName); 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); 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 ************************/ /************************** Get number of departments ************************/
/*****************************************************************************/ /*****************************************************************************/
@ -1165,32 +1099,32 @@ void Dpt_WriteSelectorDepartment (long InsCod,long DptCod,
"id=\"%s\" name=\"%s\" class=\"%s\"", "id=\"%s\" name=\"%s\" class=\"%s\"",
Dpt_PARAM_DPT_COD_NAME,Dpt_PARAM_DPT_COD_NAME,SelectClass); Dpt_PARAM_DPT_COD_NAME,Dpt_PARAM_DPT_COD_NAME,SelectClass);
if (FirstOption <= 0) if (FirstOption <= 0)
{
/* Option when no department selected */
if (FirstOption < 0)
{ {
NoDptSelectable = false; /* Option when no department selected */
if (TextWhenNoDptSelected) if (FirstOption < 0)
if (TextWhenNoDptSelected[0]) {
NoDptSelectable = true; NoDptSelectable = false;
if (TextWhenNoDptSelected)
if (TextWhenNoDptSelected[0])
NoDptSelectable = true;
HTM_OPTION (HTM_Type_STRING,"-1",DptCod < 0,!NoDptSelectable, HTM_OPTION (HTM_Type_STRING,"-1",DptCod < 0,!NoDptSelectable,
"%s",TextWhenNoDptSelected); "%s",TextWhenNoDptSelected);
}
/* Another department selected (different to all departments listed) */
HTM_OPTION (HTM_Type_STRING,"0",DptCod == 0,false,
"%s",Txt_Another_department);
} }
/* Another department selected (different to all departments listed) */ /* List all departments */
HTM_OPTION (HTM_Type_STRING,"0",DptCod == 0,false, for (NumDpt = 0;
"%s",Txt_Another_department); NumDpt < Departments.Num;
} NumDpt++)
HTM_OPTION (HTM_Type_LONG,&Departments.Lst[NumDpt].DptCod,
/* List all departments */ Departments.Lst[NumDpt].DptCod == DptCod,false,
for (NumDpt = 0; "%s",Departments.Lst[NumDpt].FullName);
NumDpt < Departments.Num;
NumDpt++)
HTM_OPTION (HTM_Type_LONG,&Departments.Lst[NumDpt].DptCod,
Departments.Lst[NumDpt].DptCod == DptCod,false,
"%s",Departments.Lst[NumDpt].FullName);
/* End selector */ /* End selector */
HTM_SELECT_End (); HTM_SELECT_End ();

View File

@ -67,7 +67,6 @@ struct Dpt_Departments
void Dpt_SeeDepts (void); void Dpt_SeeDepts (void);
void Dpt_EditDepartments (void); void Dpt_EditDepartments (void);
void Dpt_FreeListDepartments (struct Dpt_Departments *Departments); void Dpt_FreeListDepartments (struct Dpt_Departments *Departments);
unsigned Dpt_GetNumDepartmentsInInstitution (long InsCod);
void Dpt_GetDataOfDepartmentByCod (struct Dpt_Department *Dpt); void Dpt_GetDataOfDepartmentByCod (struct Dpt_Department *Dpt);
long Dpt_GetAndCheckParamDptCod (long MinCodAllowed); long Dpt_GetAndCheckParamDptCod (long MinCodAllowed);
void Dpt_RemoveDepartment (void); 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 <stdlib.h> // For free
#include "swad_database.h" #include "swad_database.h"
#include "swad_department.h" #include "swad_department_database.h"
#include "swad_error.h" #include "swad_error.h"
#include "swad_figure_cache.h" #include "swad_figure_cache.h"
#include "swad_form.h" #include "swad_form.h"
@ -535,7 +535,7 @@ static void InsCfg_NumDpts (void)
/* Data */ /* Data */
HTM_TD_Begin ("class=\"DAT LB\""); 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_TD_End ();
HTM_TR_End (); HTM_TR_End ();