From b044148aa69c5788e2361b6642112b0ad9ee188e Mon Sep 17 00:00:00 2001 From: acanas Date: Mon, 20 Sep 2021 14:06:42 +0200 Subject: [PATCH] Version 21.7: Sep 18, 2021 New module swad_hierarchy_database for database queries related to hierarchy. --- Makefile | 3 +- swad_changelog.h | 3 +- swad_game_database.c | 15 ---- swad_game_database.h | 2 - swad_hierarchy.c | 174 +++++++++++++++----------------------- swad_hierarchy_database.c | 101 ++++++++++++++++++++++ swad_hierarchy_database.h | 46 ++++++++++ 7 files changed, 218 insertions(+), 126 deletions(-) create mode 100644 swad_hierarchy_database.c create mode 100644 swad_hierarchy_database.h diff --git a/Makefile b/Makefile index b66d7d87..c3da94bc 100644 --- a/Makefile +++ b/Makefile @@ -53,7 +53,8 @@ OBJS = swad_account.o swad_account_database.o swad_action.o swad_admin.o \ swad_form.o swad_forum.o swad_forum_database.o \ swad_game.o swad_game_database.o swad_global.o swad_group.o \ swad_group_database.o swad_help.o swad_hierarchy.o \ - swad_hierarchy_config.o swad_holiday.o swad_HTML.o \ + swad_hierarchy_config.o swad_hierarchy_database.o swad_holiday.o \ + swad_HTML.o \ swad_icon.o swad_ID.o swad_indicator.o swad_info.o swad_institution.o \ swad_institution_config.o swad_institution_database.o \ swad_language.o swad_layout.o swad_link.o swad_log.o swad_logo.o \ diff --git a/swad_changelog.h b/swad_changelog.h index a6cd3098..ba1db053 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -602,13 +602,14 @@ TODO: FIX BUG, URGENT! En las fechas como par TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo. */ -#define Log_PLATFORM_VERSION "SWAD 21.6.3 (2021-09-20)" +#define Log_PLATFORM_VERSION "SWAD 21.7 (2021-09-20)" #define CSS_FILE "swad20.45.css" #define JS_FILE "swad20.69.1.js" /* TODO: Rename CENTRE to CENTER in help wiki. TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams + Version 21.7: Sep 18, 2021 New module swad_hierarchy_database for database queries related to hierarchy. (315774 lines) Version 21.6.3: Sep 20, 2021 Queries moved to module swad_game_database. (315708 lines) Version 21.6.2: Sep 18, 2021 Queries moved to module swad_game_database. (315679 lines) Version 21.6.1: Sep 18, 2021 Queries moved to module swad_game_database. (315571 lines) diff --git a/swad_game_database.c b/swad_game_database.c index 5f621e6b..3c98384e 100644 --- a/swad_game_database.c +++ b/swad_game_database.c @@ -26,28 +26,13 @@ /*****************************************************************************/ #define _GNU_SOURCE // For asprintf -// #include // For DBL_MAX -// #include // For PATH_MAX -// #include // For NULL #include // For asprintf -// #include // For free -// #include // For string functions #include "swad_database.h" #include "swad_error.h" -// #include "swad_figure.h" -// #include "swad_form.h" #include "swad_game.h" #include "swad_game_database.h" #include "swad_global.h" -// #include "swad_hierarchy_level.h" -// #include "swad_HTML.h" -// #include "swad_match.h" -// #include "swad_match_result.h" -// #include "swad_pagination.h" -// #include "swad_role.h" -// #include "swad_test.h" -// #include "swad_test_visibility.h" /*****************************************************************************/ /************** External global variables from others modules ****************/ diff --git a/swad_game_database.h b/swad_game_database.h index f5bfe703..d107eee7 100644 --- a/swad_game_database.h +++ b/swad_game_database.h @@ -27,9 +27,7 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -// #include "swad_date.h" #include "swad_hierarchy_level.h" -// #include "swad_scope.h" /*****************************************************************************/ /************************** Public types and constants ***********************/ diff --git a/swad_hierarchy.c b/swad_hierarchy.c index f553b585..a1d36015 100644 --- a/swad_hierarchy.c +++ b/swad_hierarchy.c @@ -36,6 +36,7 @@ #include "swad_global.h" #include "swad_group_database.h" #include "swad_hierarchy.h" +#include "swad_hierarchy_database.h" #include "swad_hierarchy_level.h" #include "swad_HTML.h" #include "swad_logo.h" @@ -665,121 +666,80 @@ void Hie_GetAndWriteInsCtrDegAdminBy (long UsrCod,unsigned ColSpan) struct Hie_Hierarchy Hie; /***** Get institutions, centers, degrees admin by user from database *****/ - NumRows = (unsigned) - DB_QuerySELECT (&mysql_res,"can not get institutions, centers, degrees" - " admin by a user", - "(SELECT %u AS S," // row[0] - "-1 AS Cod," // row[1] - "'' AS FullName" // row[2] - " FROM usr_admins" - " WHERE UsrCod=%ld" - " AND Scope='%s')" - " UNION " - "(SELECT %u AS S," // row[0] - "usr_admins.Cod," // row[1] - "ins_instits.FullName" // row[2] - " FROM usr_admins," - "ins_instits" - " WHERE usr_admins.UsrCod=%ld" - " AND usr_admins.Scope='%s'" - " AND usr_admins.Cod=ins_instits.InsCod)" - " UNION " - "(SELECT %u AS S," // row[0] - "usr_admins.Cod," // row[1] - "ctr_centers.FullName" // row[2] - " FROM usr_admins," - "ctr_centers" - " WHERE usr_admins.UsrCod=%ld" - " AND usr_admins.Scope='%s'" - " AND usr_admins.Cod=ctr_centers.CtrCod)" - " UNION " - "(SELECT %u AS S," // row[0] - "usr_admins.Cod," // row[1] - "deg_degrees.FullName" // row[2] - " FROM usr_admins," - "deg_degrees" - " WHERE usr_admins.UsrCod=%ld" - " AND usr_admins.Scope='%s'" - " AND usr_admins.Cod=deg_degrees.DegCod)" - " ORDER BY S," - "FullName", - (unsigned) HieLvl_SYS,UsrCod,Sco_GetDBStrFromScope (HieLvl_SYS), - (unsigned) HieLvl_INS,UsrCod,Sco_GetDBStrFromScope (HieLvl_INS), - (unsigned) HieLvl_CTR,UsrCod,Sco_GetDBStrFromScope (HieLvl_CTR), - (unsigned) HieLvl_DEG,UsrCod,Sco_GetDBStrFromScope (HieLvl_DEG)); - if (NumRows) - /***** Get the list of degrees *****/ - for (NumRow = 1; - NumRow <= NumRows; - NumRow++) - { - HTM_TR_Begin (NULL); + NumRows = Hie_DB_GetInsCtrDegAdminBy (&mysql_res,UsrCod); - /***** Indent *****/ - HTM_TD_Begin ("class=\"RT COLOR%u\"",Gbl.RowEvenOdd); - Ico_PutIcon (NumRow == NumRows ? "subend20x20.gif" : - "submid20x20.gif", - "","ICO25x25"); - HTM_TD_End (); + /***** Get the list of degrees *****/ + for (NumRow = 1; + NumRow <= NumRows; + NumRow++) + { + HTM_TR_Begin (NULL); - /***** Write institution, center, degree *****/ - HTM_TD_Begin ("colspan=\"%u\" class=\"DAT_SMALL_NOBR LT COLOR%u\"", - ColSpan - 1,Gbl.RowEvenOdd); + /***** Indent *****/ + HTM_TD_Begin ("class=\"RT COLOR%u\"",Gbl.RowEvenOdd); + Ico_PutIcon (NumRow == NumRows ? "subend20x20.gif" : + "submid20x20.gif", + "","ICO25x25"); + HTM_TD_End (); - /* Get next institution, center, degree */ - row = mysql_fetch_row (mysql_res); + /***** Write institution, center, degree *****/ + HTM_TD_Begin ("colspan=\"%u\" class=\"DAT_SMALL_NOBR LT COLOR%u\"", + ColSpan - 1,Gbl.RowEvenOdd); - /* Get scope */ - switch (Sco_GetScopeFromUnsignedStr (row[0])) - { - case HieLvl_SYS: // System - Ico_PutIcon ("swad64x64.png",Txt_all_degrees,"ICO16x16"); - HTM_TxtF (" %s",Txt_all_degrees); - break; - case HieLvl_INS: // Institution - Hie.Ins.InsCod = Str_ConvertStrCodToLongCod (row[1]); - if (Hie.Ins.InsCod > 0) - { - /* Get data of institution */ - Ins_GetDataOfInstitutionByCod (&Hie.Ins); + /* Get next institution, center, degree */ + row = mysql_fetch_row (mysql_res); - /* Write institution logo and name */ - Ins_DrawInstitutionLogoAndNameWithLink (&Hie.Ins,ActSeeInsInf, - "BT_LINK DAT_SMALL_NOBR","LT"); - } - break; - case HieLvl_CTR: // Center - Hie.Ctr.CtrCod = Str_ConvertStrCodToLongCod (row[1]); - if (Hie.Ctr.CtrCod > 0) - { - /* Get data of center */ - Ctr_GetDataOfCenterByCod (&Hie.Ctr); + /* Get scope */ + switch (Sco_GetScopeFromUnsignedStr (row[0])) + { + case HieLvl_SYS: // System + Ico_PutIcon ("swad64x64.png",Txt_all_degrees,"ICO16x16"); + HTM_TxtF (" %s",Txt_all_degrees); + break; + case HieLvl_INS: // Institution + Hie.Ins.InsCod = Str_ConvertStrCodToLongCod (row[1]); + if (Hie.Ins.InsCod > 0) + { + /* Get data of institution */ + Ins_GetDataOfInstitutionByCod (&Hie.Ins); - /* Write center logo and name */ - Ctr_DrawCenterLogoAndNameWithLink (&Hie.Ctr,ActSeeCtrInf, - "BT_LINK DAT_SMALL_NOBR","LT"); - } - break; - case HieLvl_DEG: // Degree - Hie.Deg.DegCod = Str_ConvertStrCodToLongCod (row[1]); - if (Hie.Deg.DegCod > 0) - { - /* Get data of degree */ - Deg_GetDataOfDegreeByCod (&Hie.Deg); + /* Write institution logo and name */ + Ins_DrawInstitutionLogoAndNameWithLink (&Hie.Ins,ActSeeInsInf, + "BT_LINK DAT_SMALL_NOBR","LT"); + } + break; + case HieLvl_CTR: // Center + Hie.Ctr.CtrCod = Str_ConvertStrCodToLongCod (row[1]); + if (Hie.Ctr.CtrCod > 0) + { + /* Get data of center */ + Ctr_GetDataOfCenterByCod (&Hie.Ctr); - /* Write degree logo and name */ - Deg_DrawDegreeLogoAndNameWithLink (&Hie.Deg,ActSeeDegInf, - "BT_LINK DAT_SMALL_NOBR","LT"); - } - break; - default: // There are no administrators in other scopes - Err_WrongScopeExit (); - break; - } - HTM_TD_End (); + /* Write center logo and name */ + Ctr_DrawCenterLogoAndNameWithLink (&Hie.Ctr,ActSeeCtrInf, + "BT_LINK DAT_SMALL_NOBR","LT"); + } + break; + case HieLvl_DEG: // Degree + Hie.Deg.DegCod = Str_ConvertStrCodToLongCod (row[1]); + if (Hie.Deg.DegCod > 0) + { + /* Get data of degree */ + Deg_GetDataOfDegreeByCod (&Hie.Deg); - HTM_TR_End (); - } + /* Write degree logo and name */ + Deg_DrawDegreeLogoAndNameWithLink (&Hie.Deg,ActSeeDegInf, + "BT_LINK DAT_SMALL_NOBR","LT"); + } + break; + default: // There are no administrators in other scopes + Err_WrongScopeExit (); + break; + } + HTM_TD_End (); + + HTM_TR_End (); + } /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); diff --git a/swad_hierarchy_database.c b/swad_hierarchy_database.c new file mode 100644 index 00000000..0c648fe1 --- /dev/null +++ b/swad_hierarchy_database.c @@ -0,0 +1,101 @@ +// swad_hierarchy_database.c: hierarchy (system, institution, center, degree, course), operations with database + +/* + SWAD (Shared Workspace At a Distance), + is a web platform developed at the University of Granada (Spain), + and used to support university teaching. + + This file is part of SWAD core. + Copyright (C) 1999-2021 Antonio Caņas Vargas + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ +/*****************************************************************************/ +/********************************* Headers ***********************************/ +/*****************************************************************************/ + +#include "swad_database.h" +#include "swad_hierarchy_database.h" +#include "swad_hierarchy_level.h" +#include "swad_scope.h" + +/*****************************************************************************/ +/************** External global variables from others modules ****************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/*************************** Public constants ********************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/***************************** Private types *********************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/*************************** Private constants *******************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/*************************** Private prototypes ******************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/****** Get institutions, centers and degrees administrated by an admin *****/ +/*****************************************************************************/ + +unsigned Hie_DB_GetInsCtrDegAdminBy (MYSQL_RES **mysql_res,long UsrCod) + { + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get institutions, centers, degrees" + " admin by a user", + "(SELECT %u AS S," // row[0] + "-1 AS Cod," // row[1] + "'' AS FullName" // row[2] + " FROM usr_admins" + " WHERE UsrCod=%ld" + " AND Scope='%s')" + " UNION " + "(SELECT %u AS S," // row[0] + "usr_admins.Cod," // row[1] + "ins_instits.FullName" // row[2] + " FROM usr_admins," + "ins_instits" + " WHERE usr_admins.UsrCod=%ld" + " AND usr_admins.Scope='%s'" + " AND usr_admins.Cod=ins_instits.InsCod)" + " UNION " + "(SELECT %u AS S," // row[0] + "usr_admins.Cod," // row[1] + "ctr_centers.FullName" // row[2] + " FROM usr_admins," + "ctr_centers" + " WHERE usr_admins.UsrCod=%ld" + " AND usr_admins.Scope='%s'" + " AND usr_admins.Cod=ctr_centers.CtrCod)" + " UNION " + "(SELECT %u AS S," // row[0] + "usr_admins.Cod," // row[1] + "deg_degrees.FullName" // row[2] + " FROM usr_admins," + "deg_degrees" + " WHERE usr_admins.UsrCod=%ld" + " AND usr_admins.Scope='%s'" + " AND usr_admins.Cod=deg_degrees.DegCod)" + " ORDER BY S," + "FullName", + (unsigned) HieLvl_SYS,UsrCod,Sco_GetDBStrFromScope (HieLvl_SYS), + (unsigned) HieLvl_INS,UsrCod,Sco_GetDBStrFromScope (HieLvl_INS), + (unsigned) HieLvl_CTR,UsrCod,Sco_GetDBStrFromScope (HieLvl_CTR), + (unsigned) HieLvl_DEG,UsrCod,Sco_GetDBStrFromScope (HieLvl_DEG)); + } diff --git a/swad_hierarchy_database.h b/swad_hierarchy_database.h new file mode 100644 index 00000000..31235ec1 --- /dev/null +++ b/swad_hierarchy_database.h @@ -0,0 +1,46 @@ +// swad_hierarchy_database.h: hierarchy (system, institution, center, degree, course), operations with database + +#ifndef _SWAD_HIE_DB +#define _SWAD_HIE_DB +/* + SWAD (Shared Workspace At a Distance in Spanish), + is a web platform developed at the University of Granada (Spain), + and used to support university teaching. + + This file is part of SWAD core. + Copyright (C) 1999-2021 Antonio Caņas Vargas + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ +/*****************************************************************************/ +/********************************* Headers ***********************************/ +/*****************************************************************************/ + +#include // To access MySQL databases + +/*****************************************************************************/ +/***************************** Public constants ******************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/******************************* Public types ********************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/***************************** Public prototypes *****************************/ +/*****************************************************************************/ + +unsigned Hie_DB_GetInsCtrDegAdminBy (MYSQL_RES **mysql_res,long UsrCod); + +#endif