diff --git a/swad_API.c b/swad_API.c index 53fa20a23..f12492eca 100644 --- a/swad_API.c +++ b/swad_API.c @@ -121,6 +121,7 @@ cp -f /home/acanas/swad/swad/swad /var/www/cgi-bin/ #include "swad_password.h" #include "swad_question_database.h" #include "swad_role.h" +#include "swad_room_database.h" #include "swad_search.h" #include "swad_test_config.h" #include "swad_test_visibility.h" @@ -6057,28 +6058,7 @@ int swad__getLastLocation (struct soap *soap, The other user does not have to share any course with me, but at least some course of each one has to share center. */ - if (DB_QueryEXISTS ("can not check if you can see user location", - "SELECT EXISTS" - "(SELECT *" - " FROM (SELECT DISTINCT " - "deg_degrees.CtrCod" - " FROM crs_users," - "crs_courses," - "deg_degrees" - " WHERE crs_users.UsrCod=%ld" - " AND crs_users.CrsCod=crs_courses.CrsCod" - " AND crs_courses.DegCod=deg_degrees.DegCod) AS C1," // centers of my courses - "(SELECT DISTINCT " - "deg_degrees.CtrCod" - " FROM crs_users," - "crs_courses," - "deg_degrees" - " WHERE crs_users.UsrCod=%d" - " AND crs_users.CrsCod=crs_courses.CrsCod" - " AND crs_courses.DegCod=deg_degrees.DegCod) AS C2" // centers of user's courses - " WHERE C1.CtrCod=C2.CtrCod)", - Gbl.Usrs.Me.UsrDat.UsrCod, - userCode)) + if (Roo_DB_CheckIfICanSeeUsrLocation ((long) userCode)) { /***** Get list of locations *****/ NumLocs = (unsigned) diff --git a/swad_changelog.h b/swad_changelog.h index 97a60856e..8cd532b56 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.53 (2021-11-06)" +#define Log_PLATFORM_VERSION "SWAD 21.53.1 (2021-11-07)" #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.53.1: Nov 07, 2021 Queries moved to module swad_room_database. (321879 lines) Version 21.53: Nov 06, 2021 Queries moved to module swad_user_database and other modules. (321926 lines) Version 21.52.3: Nov 06, 2021 Queries moved to module swad_user_database. (321894 lines) Version 21.52.2: Nov 06, 2021 Query refactoring related to SELECT DISTINCT and UNION. (321899 lines) diff --git a/swad_role_database.c b/swad_role_database.c index da3036521..51cae4994 100644 --- a/swad_role_database.c +++ b/swad_role_database.c @@ -43,8 +43,6 @@ /************** External global variables from others modules ****************/ /*****************************************************************************/ -// extern struct Globals Gbl; - /*****************************************************************************/ /************************* Private global variables **************************/ /*****************************************************************************/ diff --git a/swad_room_database.c b/swad_room_database.c index f73e5f9d9..150920dfb 100644 --- a/swad_room_database.c +++ b/swad_room_database.c @@ -26,12 +26,15 @@ /*****************************************************************************/ #include "swad_database.h" +#include "swad_global.h" #include "swad_room.h" /*****************************************************************************/ /************** External global variables from others modules ****************/ /*****************************************************************************/ +extern struct Globals Gbl; + /*****************************************************************************/ /****************************** Public constants *****************************/ /*****************************************************************************/ @@ -329,6 +332,43 @@ unsigned Roo_DB_GetMACAddresses (MYSQL_RES **mysql_res,long RooCod) RooCod); } +/*****************************************************************************/ +/********************** Check if I can see user's location *******************/ +/*****************************************************************************/ + +bool Roo_DB_CheckIfICanSeeUsrLocation (long UsrCod) + { + /* + I can only consult the location of another user + if the intersection of the centers of our courses is not empty. + The other user does not have to share any course with me, + but at least some course of each one has to share center. + */ + return + DB_QueryEXISTS ("can not check if you can see user location", + "SELECT EXISTS" + "(SELECT *" + " FROM (SELECT DISTINCT " + "deg_degrees.CtrCod" + " FROM crs_users," + "crs_courses," + "deg_degrees" + " WHERE crs_users.UsrCod=%ld" + " AND crs_users.CrsCod=crs_courses.CrsCod" + " AND crs_courses.DegCod=deg_degrees.DegCod) AS C1," // centers of my courses + "(SELECT DISTINCT " + "deg_degrees.CtrCod" + " FROM crs_users," + "crs_courses," + "deg_degrees" + " WHERE crs_users.UsrCod=%ld" + " AND crs_users.CrsCod=crs_courses.CrsCod" + " AND crs_courses.DegCod=deg_degrees.DegCod) AS C2" // centers of user's courses + " WHERE C1.CtrCod=C2.CtrCod)", + Gbl.Usrs.Me.UsrDat.UsrCod, + UsrCod); + } + /*****************************************************************************/ /********************************* Remove room *******************************/ /*****************************************************************************/ diff --git a/swad_room_database.h b/swad_room_database.h index 1280baf30..95a6705dc 100644 --- a/swad_room_database.h +++ b/swad_room_database.h @@ -53,6 +53,7 @@ bool Roo_DB_CheckIfRoomNameExists (long CtrCod,long RooCod, const char *FieldName,const char *Name); unsigned Roo_DB_GetDataOfRoomByCod (MYSQL_RES **mysql_res,long RooCod); unsigned Roo_DB_GetMACAddresses (MYSQL_RES **mysql_res,long RooCod); +bool Roo_DB_CheckIfICanSeeUsrLocation (long UsrCod); void Roo_DB_RemoveRoom (long RooCod); void Roo_DB_RemoveMACAddress (long RooCod,unsigned long long MACnum); diff --git a/swad_user_database.c b/swad_user_database.c index 522d9661b..00e369ad8 100644 --- a/swad_user_database.c +++ b/swad_user_database.c @@ -25,60 +25,9 @@ /*********************************** Headers *********************************/ /*****************************************************************************/ -// #define _GNU_SOURCE // For asprintf -// #include // For isalnum, isdigit, etc. -// #include // For maximum values -// #include // For PATH_MAX -// #include // For NULL -// #include // For asprintf -// #include // For exit, system, malloc, free, rand, etc. -// #include // For string functions -// #include // For the macro WEXITSTATUS -// #include // For access, lstat, getpid, chdir, symlink, unlink - -// #include "swad_account.h" -// #include "swad_agenda.h" -// #include "swad_announcement.h" -// #include "swad_box.h" -// #include "swad_calendar.h" -// #include "swad_config.h" -// #include "swad_connected_database.h" -// #include "swad_course.h" #include "swad_database.h" -// #include "swad_department.h" -// #include "swad_duplicate.h" -// #include "swad_enrolment.h" #include "swad_error.h" -// #include "swad_figure.h" -// #include "swad_figure_cache.h" -// #include "swad_follow.h" -// #include "swad_form.h" #include "swad_global.h" -// #include "swad_group.h" -// #include "swad_help.h" -// #include "swad_hierarchy.h" -// #include "swad_hierarchy_level.h" -// #include "swad_HTML.h" -// #include "swad_ID.h" -// #include "swad_language.h" -// #include "swad_mail_database.h" -// #include "swad_message.h" -// #include "swad_MFU.h" -// #include "swad_nickname.h" -// #include "swad_nickname_database.h" -// #include "swad_notification.h" -// #include "swad_parameter.h" -// #include "swad_password.h" -// #include "swad_photo.h" -// #include "swad_privacy.h" -// #include "swad_QR.h" -// #include "swad_record.h" -// #include "swad_record_database.h" -// #include "swad_role.h" -// #include "swad_session_database.h" -// #include "swad_setting.h" -// #include "swad_tab.h" -// #include "swad_user.h" #include "swad_user_database.h" /*****************************************************************************/ diff --git a/swad_user_database.h b/swad_user_database.h index 57ef9de3f..211a13108 100644 --- a/swad_user_database.h +++ b/swad_user_database.h @@ -31,23 +31,8 @@ #include // For boolean type #include // For time_t -// #include "swad_action.h" -// #include "swad_constant.h" -// #include "swad_country.h" #include "swad_cryptography.h" -// #include "swad_date.h" -// #include "swad_degree.h" -// #include "swad_icon.h" -// #include "swad_layout.h" -// #include "swad_menu.h" -// #include "swad_nickname.h" -// #include "swad_password.h" -// #include "swad_privacy_visibility_type.h" -// #include "swad_role_type.h" -// #include "swad_scope.h" #include "swad_search.h" -// #include "swad_string.h" -// #include "swad_theme.h" /*****************************************************************************/ /****************************** Public constants *****************************/