mirror of https://github.com/acanas/swad-core.git
Version 20.89.1: Jun 05, 2021 Queries moved to module swad_department_database.
This commit is contained in:
parent
1dbe256cbd
commit
9e1efb5b02
|
@ -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.89 (2021-06-02)"
|
#define Log_PLATFORM_VERSION "SWAD 20.89.1 (2021-06-05)"
|
||||||
#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.1: Jun 05, 2021 Queries moved to module swad_department_database. (312869 lines)
|
||||||
Version 20.89: Jun 02, 2021 New module swad_department_database for database queries related to departments. (312824 lines)
|
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.
|
||||||
|
|
|
@ -321,11 +321,6 @@ static void Dpt_EditDepartmentsInternal (void)
|
||||||
|
|
||||||
static void Dpt_GetListDepartments (struct Dpt_Departments *Departments,long InsCod)
|
static void Dpt_GetListDepartments (struct Dpt_Departments *Departments,long InsCod)
|
||||||
{
|
{
|
||||||
static const char *OrderBySubQuery[Dpt_NUM_ORDERS] =
|
|
||||||
{
|
|
||||||
[Dpt_ORDER_BY_DEPARTMENT] = "FullName",
|
|
||||||
[Dpt_ORDER_BY_NUM_TCHS ] = "NumTchs DESC,FullName",
|
|
||||||
};
|
|
||||||
MYSQL_RES *mysql_res;
|
MYSQL_RES *mysql_res;
|
||||||
MYSQL_ROW row;
|
MYSQL_ROW row;
|
||||||
unsigned NumDpt;
|
unsigned NumDpt;
|
||||||
|
@ -337,40 +332,8 @@ static void Dpt_GetListDepartments (struct Dpt_Departments *Departments,long Ins
|
||||||
if (InsCod > 0) // Institution specified
|
if (InsCod > 0) // Institution specified
|
||||||
{
|
{
|
||||||
/***** Get departments from database *****/
|
/***** Get departments from database *****/
|
||||||
Departments->Num = (unsigned)
|
Departments->Num = Dpt_DB_GetListDepartments (&mysql_res,InsCod,
|
||||||
DB_QuerySELECT (&mysql_res,"can not get departments",
|
Departments->SelectedOrder);
|
||||||
"(SELECT dpt_departments.DptCod," // row[0]
|
|
||||||
"dpt_departments.InsCod," // row[1]
|
|
||||||
"dpt_departments.ShortName," // row[2]
|
|
||||||
"dpt_departments.FullName," // row[3]
|
|
||||||
"dpt_departments.WWW," // row[4]
|
|
||||||
"COUNT(DISTINCT usr_data.UsrCod) AS NumTchs" // row[5]
|
|
||||||
" FROM dpt_departments,"
|
|
||||||
"usr_data,"
|
|
||||||
"crs_users"
|
|
||||||
" WHERE dpt_departments.InsCod=%ld"
|
|
||||||
" AND dpt_departments.DptCod=usr_data.DptCod"
|
|
||||||
" AND usr_data.UsrCod=crs_users.UsrCod"
|
|
||||||
" AND crs_users.Role IN (%u,%u)"
|
|
||||||
" GROUP BY dpt_departments.DptCod)"
|
|
||||||
" UNION "
|
|
||||||
"(SELECT DptCod," // row[0]
|
|
||||||
"InsCod," // row[1]
|
|
||||||
"ShortName," // row[2]
|
|
||||||
"FullName," // row[3]
|
|
||||||
"WWW," // row[4]
|
|
||||||
"0 AS NumTchs" // row[5]
|
|
||||||
" FROM dpt_departments"
|
|
||||||
" WHERE InsCod=%ld"
|
|
||||||
" AND DptCod NOT IN"
|
|
||||||
" (SELECT DISTINCT usr_data.DptCod"
|
|
||||||
" FROM usr_data,crs_users"
|
|
||||||
" WHERE crs_users.Role IN (%u,%u)"
|
|
||||||
" AND crs_users.UsrCod=usr_data.UsrCod))"
|
|
||||||
" ORDER BY %s",
|
|
||||||
InsCod,(unsigned) Rol_NET,(unsigned) Rol_TCH,
|
|
||||||
InsCod,(unsigned) Rol_NET,(unsigned) Rol_TCH,
|
|
||||||
OrderBySubQuery[Departments->SelectedOrder]);
|
|
||||||
if (Departments->Num) // Departments found...
|
if (Departments->Num) // Departments found...
|
||||||
{
|
{
|
||||||
/***** Create list with courses in degree *****/
|
/***** Create list with courses in degree *****/
|
||||||
|
@ -414,7 +377,7 @@ static void Dpt_GetListDepartments (struct Dpt_Departments *Departments,long Ins
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/************************** Get department full name *************************/
|
/****************** Get data of department using its code ********************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
void Dpt_GetDataOfDepartmentByCod (struct Dpt_Department *Dpt)
|
void Dpt_GetDataOfDepartmentByCod (struct Dpt_Department *Dpt)
|
||||||
|
@ -437,36 +400,7 @@ void Dpt_GetDataOfDepartmentByCod (struct Dpt_Department *Dpt)
|
||||||
else if (Dpt->DptCod > 0)
|
else if (Dpt->DptCod > 0)
|
||||||
{
|
{
|
||||||
/***** Get data of a department from database *****/
|
/***** Get data of a department from database *****/
|
||||||
if (DB_QuerySELECT (&mysql_res,"can not get data of a department",
|
if (Dpt_DB_GetDataOfDepartmentByCod (&mysql_res,Dpt->DptCod)) // Department found...
|
||||||
"(SELECT dpt_departments.InsCod," // row[0]
|
|
||||||
"dpt_departments.ShortName," // row[1]
|
|
||||||
"dpt_departments.FullName," // row[2]
|
|
||||||
"dpt_departments.WWW," // row[3]
|
|
||||||
"COUNT(DISTINCT usr_data.UsrCod) AS NumTchs" // row[4]
|
|
||||||
" FROM dpt_departments,"
|
|
||||||
"usr_data,"
|
|
||||||
"crs_users"
|
|
||||||
" WHERE dpt_departments.DptCod=%ld"
|
|
||||||
" AND dpt_departments.DptCod=usr_data.DptCod"
|
|
||||||
" AND usr_data.UsrCod=crs_users.UsrCod"
|
|
||||||
" AND crs_users.Role=%u"
|
|
||||||
" GROUP BY dpt_departments.DptCod)"
|
|
||||||
" UNION "
|
|
||||||
"(SELECT InsCod," // row[0]
|
|
||||||
"ShortName," // row[1]
|
|
||||||
"FullName," // row[2]
|
|
||||||
"WWW," // row[3]
|
|
||||||
"0" // row[4]
|
|
||||||
" FROM dpt_departments"
|
|
||||||
" WHERE DptCod=%ld"
|
|
||||||
" AND DptCod NOT IN"
|
|
||||||
" (SELECT DISTINCT usr_data.DptCod"
|
|
||||||
" FROM usr_data,"
|
|
||||||
"crs_users"
|
|
||||||
" WHERE crs_users.Role=%u"
|
|
||||||
" AND crs_users.UsrCod=usr_data.UsrCod))",
|
|
||||||
Dpt->DptCod,(unsigned) Rol_TCH,
|
|
||||||
Dpt->DptCod,(unsigned) Rol_TCH)) // Department found...
|
|
||||||
{
|
{
|
||||||
/* Get row */
|
/* Get row */
|
||||||
row = mysql_fetch_row (mysql_res);
|
row = mysql_fetch_row (mysql_res);
|
||||||
|
@ -658,10 +592,7 @@ void Dpt_RemoveDepartment (void)
|
||||||
else // Department has no teachers ==> remove it
|
else // Department has no teachers ==> remove it
|
||||||
{
|
{
|
||||||
/***** Remove department *****/
|
/***** Remove department *****/
|
||||||
DB_QueryDELETE ("can not remove a department",
|
Dpt_DB_RemoveDepartment (Dpt_EditingDpt->DptCod);
|
||||||
"DELETE FROM dpt_departments"
|
|
||||||
" WHERE DptCod=%ld",
|
|
||||||
Dpt_EditingDpt->DptCod);
|
|
||||||
|
|
||||||
/***** Write message to show the change made *****/
|
/***** Write message to show the change made *****/
|
||||||
Ale_CreateAlert (Ale_SUCCESS,NULL,
|
Ale_CreateAlert (Ale_SUCCESS,NULL,
|
||||||
|
@ -693,12 +624,7 @@ void Dpt_ChangeDepartIns (void)
|
||||||
Dpt_GetDataOfDepartmentByCod (Dpt_EditingDpt);
|
Dpt_GetDataOfDepartmentByCod (Dpt_EditingDpt);
|
||||||
|
|
||||||
/***** Update institution in table of departments *****/
|
/***** Update institution in table of departments *****/
|
||||||
DB_QueryUPDATE ("can not update the institution of a department",
|
Dpt_DB_UpdateDptIns (Dpt_EditingDpt->DptCod,NewInsCod);
|
||||||
"UPDATE dpt_departments"
|
|
||||||
" SET InsCod=%ld"
|
|
||||||
" WHERE DptCod=%ld",
|
|
||||||
NewInsCod,
|
|
||||||
Dpt_EditingDpt->DptCod);
|
|
||||||
|
|
||||||
/***** Write message to show the change made *****/
|
/***** Write message to show the change made *****/
|
||||||
Ale_CreateAlert (Ale_SUCCESS,NULL,
|
Ale_CreateAlert (Ale_SUCCESS,NULL,
|
||||||
|
@ -787,7 +713,7 @@ static void Dpt_RenameDepartment (Cns_ShrtOrFullName_t ShrtOrFullName)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Update the table changing old name by new name */
|
/* Update the table changing old name by new name */
|
||||||
Dpt_DB_UpdateDegName (Dpt_EditingDpt->DptCod,FieldName,NewDptName);
|
Dpt_DB_UpdateDptName (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,
|
||||||
|
@ -833,12 +759,7 @@ void Dpt_ChangeDptWWW (void)
|
||||||
if (NewWWW[0])
|
if (NewWWW[0])
|
||||||
{
|
{
|
||||||
/* Update the table changing old WWW by new WWW */
|
/* Update the table changing old WWW by new WWW */
|
||||||
DB_QueryUPDATE ("can not update the web of a department",
|
Dpt_DB_UpdateDptWWW (Dpt_EditingDpt->DptCod,NewWWW);
|
||||||
"UPDATE dpt_departments"
|
|
||||||
" SET WWW='%s'"
|
|
||||||
" WHERE DptCod=%ld",
|
|
||||||
NewWWW,
|
|
||||||
Dpt_EditingDpt->DptCod);
|
|
||||||
|
|
||||||
/***** Write message to show the change made *****/
|
/***** Write message to show the change made *****/
|
||||||
Ale_CreateAlert (Ale_SUCCESS,NULL,
|
Ale_CreateAlert (Ale_SUCCESS,NULL,
|
||||||
|
|
|
@ -84,6 +84,94 @@ void Dpt_DB_CreateDepartment (const struct Dpt_Department *Dpt)
|
||||||
Dpt->WWW);
|
Dpt->WWW);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/************************** Get list of departments **************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
unsigned Dpt_DB_GetListDepartments (MYSQL_RES **mysql_res,
|
||||||
|
long InsCod,Dpt_Order_t SelectedOrder)
|
||||||
|
{
|
||||||
|
static const char *OrderBySubQuery[Dpt_NUM_ORDERS] =
|
||||||
|
{
|
||||||
|
[Dpt_ORDER_BY_DEPARTMENT] = "FullName",
|
||||||
|
[Dpt_ORDER_BY_NUM_TCHS ] = "NumTchs DESC,FullName",
|
||||||
|
};
|
||||||
|
|
||||||
|
return (unsigned)
|
||||||
|
DB_QuerySELECT (mysql_res,"can not get departments",
|
||||||
|
"(SELECT dpt_departments.DptCod," // row[0]
|
||||||
|
"dpt_departments.InsCod," // row[1]
|
||||||
|
"dpt_departments.ShortName," // row[2]
|
||||||
|
"dpt_departments.FullName," // row[3]
|
||||||
|
"dpt_departments.WWW," // row[4]
|
||||||
|
"COUNT(DISTINCT usr_data.UsrCod) AS NumTchs" // row[5]
|
||||||
|
" FROM dpt_departments,"
|
||||||
|
"usr_data,"
|
||||||
|
"crs_users"
|
||||||
|
" WHERE dpt_departments.InsCod=%ld"
|
||||||
|
" AND dpt_departments.DptCod=usr_data.DptCod"
|
||||||
|
" AND usr_data.UsrCod=crs_users.UsrCod"
|
||||||
|
" AND crs_users.Role IN (%u,%u)"
|
||||||
|
" GROUP BY dpt_departments.DptCod)"
|
||||||
|
" UNION "
|
||||||
|
"(SELECT DptCod," // row[0]
|
||||||
|
"InsCod," // row[1]
|
||||||
|
"ShortName," // row[2]
|
||||||
|
"FullName," // row[3]
|
||||||
|
"WWW," // row[4]
|
||||||
|
"0 AS NumTchs" // row[5]
|
||||||
|
" FROM dpt_departments"
|
||||||
|
" WHERE InsCod=%ld"
|
||||||
|
" AND DptCod NOT IN"
|
||||||
|
" (SELECT DISTINCT usr_data.DptCod"
|
||||||
|
" FROM usr_data,crs_users"
|
||||||
|
" WHERE crs_users.Role IN (%u,%u)"
|
||||||
|
" AND crs_users.UsrCod=usr_data.UsrCod))"
|
||||||
|
" ORDER BY %s",
|
||||||
|
InsCod,(unsigned) Rol_NET,(unsigned) Rol_TCH,
|
||||||
|
InsCod,(unsigned) Rol_NET,(unsigned) Rol_TCH,
|
||||||
|
OrderBySubQuery[SelectedOrder]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/****************** Get data of department using its code ********************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
unsigned Dpt_DB_GetDataOfDepartmentByCod (MYSQL_RES **mysql_res,long DptCod)
|
||||||
|
{
|
||||||
|
return (unsigned)
|
||||||
|
DB_QuerySELECT (mysql_res,"can not get data of a department",
|
||||||
|
"(SELECT dpt_departments.InsCod," // row[0]
|
||||||
|
"dpt_departments.ShortName," // row[1]
|
||||||
|
"dpt_departments.FullName," // row[2]
|
||||||
|
"dpt_departments.WWW," // row[3]
|
||||||
|
"COUNT(DISTINCT usr_data.UsrCod) AS NumTchs" // row[4]
|
||||||
|
" FROM dpt_departments,"
|
||||||
|
"usr_data,"
|
||||||
|
"crs_users"
|
||||||
|
" WHERE dpt_departments.DptCod=%ld"
|
||||||
|
" AND dpt_departments.DptCod=usr_data.DptCod"
|
||||||
|
" AND usr_data.UsrCod=crs_users.UsrCod"
|
||||||
|
" AND crs_users.Role=%u"
|
||||||
|
" GROUP BY dpt_departments.DptCod)"
|
||||||
|
" UNION "
|
||||||
|
"(SELECT InsCod," // row[0]
|
||||||
|
"ShortName," // row[1]
|
||||||
|
"FullName," // row[2]
|
||||||
|
"WWW," // row[3]
|
||||||
|
"0" // row[4]
|
||||||
|
" FROM dpt_departments"
|
||||||
|
" WHERE DptCod=%ld"
|
||||||
|
" AND DptCod NOT IN"
|
||||||
|
" (SELECT DISTINCT usr_data.DptCod"
|
||||||
|
" FROM usr_data,"
|
||||||
|
"crs_users"
|
||||||
|
" WHERE crs_users.Role=%u"
|
||||||
|
" AND crs_users.UsrCod=usr_data.UsrCod))",
|
||||||
|
DptCod,(unsigned) Rol_TCH,
|
||||||
|
DptCod,(unsigned) Rol_TCH);
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/******************* Check if the name of department exists ******************/
|
/******************* Check if the name of department exists ******************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -115,13 +203,26 @@ unsigned Dpt_DB_GetNumDepartmentsInInstitution (long InsCod)
|
||||||
InsCod);
|
InsCod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/****************** Update institution in table of departments ***************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Dpt_DB_UpdateDptIns (long DptCod,long NewInsCod)
|
||||||
|
{
|
||||||
|
DB_QueryUPDATE ("can not update the institution of a department",
|
||||||
|
"UPDATE dpt_departments"
|
||||||
|
" SET InsCod=%ld"
|
||||||
|
" WHERE DptCod=%ld",
|
||||||
|
NewInsCod,
|
||||||
|
DptCod);
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/************* Update department name in table of departments ****************/
|
/************* Update department name in table of departments ****************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
void Dpt_DB_UpdateDegName (long DptCod,const char *FieldName,const char *NewDptName)
|
void Dpt_DB_UpdateDptName (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",
|
DB_QueryUPDATE ("can not update the name of a department",
|
||||||
"UPDATE dpt_departments"
|
"UPDATE dpt_departments"
|
||||||
" SET %s='%s'"
|
" SET %s='%s'"
|
||||||
|
@ -129,3 +230,29 @@ void Dpt_DB_UpdateDegName (long DptCod,const char *FieldName,const char *NewDptN
|
||||||
FieldName,NewDptName,
|
FieldName,NewDptName,
|
||||||
DptCod);
|
DptCod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/**************** Update the table changing old WWW by new WWW ***************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Dpt_DB_UpdateDptWWW (long DptCod,char NewWWW[Cns_MAX_BYTES_WWW + 1])
|
||||||
|
{
|
||||||
|
DB_QueryUPDATE ("can not update the web of a department",
|
||||||
|
"UPDATE dpt_departments"
|
||||||
|
" SET WWW='%s'"
|
||||||
|
" WHERE DptCod=%ld",
|
||||||
|
NewWWW,
|
||||||
|
DptCod);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/***************************** Remove a department ***************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Dpt_DB_RemoveDepartment (long DptCod)
|
||||||
|
{
|
||||||
|
DB_QueryDELETE ("can not remove a department",
|
||||||
|
"DELETE FROM dpt_departments"
|
||||||
|
" WHERE DptCod=%ld",
|
||||||
|
DptCod);
|
||||||
|
}
|
||||||
|
|
|
@ -27,7 +27,9 @@
|
||||||
/********************************* Headers ***********************************/
|
/********************************* Headers ***********************************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
// #include "swad_constant.h"
|
#include <mysql/mysql.h> // To access MySQL databases
|
||||||
|
|
||||||
|
#include "swad_constant.h"
|
||||||
#include "swad_department.h"
|
#include "swad_department.h"
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -40,9 +42,16 @@
|
||||||
|
|
||||||
void Dpt_DB_CreateDepartment (const struct Dpt_Department *Dpt);
|
void Dpt_DB_CreateDepartment (const struct Dpt_Department *Dpt);
|
||||||
|
|
||||||
|
unsigned Dpt_DB_GetListDepartments (MYSQL_RES **mysql_res,
|
||||||
|
long InsCod,Dpt_Order_t SelectedOrder);
|
||||||
|
unsigned Dpt_DB_GetDataOfDepartmentByCod (MYSQL_RES **mysql_res,long DptCod);
|
||||||
bool Dpt_DB_CheckIfDepartmentNameExists (const char *FieldName,const char *Name,long DptCod);
|
bool Dpt_DB_CheckIfDepartmentNameExists (const char *FieldName,const char *Name,long DptCod);
|
||||||
unsigned Dpt_DB_GetNumDepartmentsInInstitution (long InsCod);
|
unsigned Dpt_DB_GetNumDepartmentsInInstitution (long InsCod);
|
||||||
|
|
||||||
void Dpt_DB_UpdateDegName (long DptCod,const char *FieldName,const char *NewDptName);
|
void Dpt_DB_UpdateDptIns (long DptCod,long NewInsCod);
|
||||||
|
void Dpt_DB_UpdateDptName (long DptCod,const char *FieldName,const char *NewDptName);
|
||||||
|
void Dpt_DB_UpdateDptWWW (long DptCod,char NewWWW[Cns_MAX_BYTES_WWW + 1]);
|
||||||
|
|
||||||
|
void Dpt_DB_RemoveDepartment (long DptCod);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue