diff --git a/soap/swad_web_service.h b/soap/swad_web_service.h index 75e9e393b..1c38919ee 100644 --- a/soap/swad_web_service.h +++ b/soap/swad_web_service.h @@ -440,7 +440,7 @@ struct swad__sendMessageOutput struct swad__usersArray usersArray; }; -/* structs used in getLocations */ +/* getLocations */ struct swad__getLocationsOutput { int institutionCode; @@ -458,6 +458,12 @@ struct swad__getLocationsOutput char *roomFullName; }; +/* sendCurrentLocation */ +struct swad__sendCurrentLocationOutput + { + int success; + }; + /*****************************************************************************/ /*************************** Web service functions ***************************/ /*****************************************************************************/ @@ -545,3 +551,6 @@ int swad__sendMessage (char *wsKey,int messageCode,char *to,char *subject,char * /* Wi-Fi-based positioning system */ int swad__getLocations (char *wsKey,char *MAC, struct swad__getLocationsOutput *getLocationsOut); +int swad__sendCurrentLocation (char *wsKey,int roomCode, + struct swad__sendCurrentLocationOutput *endCurrentLocationOut); + diff --git a/sql/cambios.sql b/sql/cambios.sql index d2b14372b..37d5422fe 100644 --- a/sql/cambios.sql +++ b/sql/cambios.sql @@ -13378,3 +13378,8 @@ WHERE ABS(ep.S-epq.S)<0.001; SELECT COUNT(*) FROM exa_log_user_agent WHERE LogCod=(SELECT MAX(LogCod) FROM exa_log_user_agent WHERE PrnCod=10) AND UserAgent='Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0'; + +---------------------------------- + + +INSERT INTO room_check_in (UsrCod,RooCod,CheckInTime) SELECT 1,RooCod,NOW() FROM rooms WHERE RooCod=1; diff --git a/sql/swad.sql b/sql/swad.sql index 20b2d65bf..121301ca3 100644 --- a/sql/swad.sql +++ b/sql/swad.sql @@ -1312,6 +1312,17 @@ CREATE TABLE IF NOT EXISTS room_MAC ( UNIQUE INDEX(RooCod,MAC), UNIQUE INDEX(MAC,RooCod)); -- +-- Table room_check_in: stores the history of locations of users +-- +CREATE TABLE IF NOT EXISTS room_check_in ( + ChkCod INT NOT NULL AUTO_INCREMENT, + UsrCod INT NOT NULL, + RooCod INT NOT NULL, + CheckInTime DATETIME NOT NULL, + UNIQUE INDEX(ChkCod), + INDEX(UsrCod,CheckInTime), + INDEX(CheckInTime)); +-- -- Table sessions: stores the information of open sessions -- CREATE TABLE IF NOT EXISTS sessions ( diff --git a/swad_API.c b/swad_API.c index 5a8bef1dd..d16bad2db 100644 --- a/swad_API.c +++ b/swad_API.c @@ -167,6 +167,7 @@ static const char *API_Functions[1 + API_NUM_FUNCTIONS] = [API_getMatchStatus ] = "getMatchStatus", // 30 [API_answerMatchQuestion ] = "answerMatchQuestion", // 31 [API_getLocations ] = "getLocations", // 32 + [API_sendCurrentLocation ] = "sendCurrentLocation", // 33 }; /* Web service roles (they do not match internal swad-core roles) */ @@ -6065,3 +6066,54 @@ int swad__getLocations (struct soap *soap, return SOAP_OK; } + +/*****************************************************************************/ +/***************** Check in (send user's current location) *******************/ +/*****************************************************************************/ + +int swad__sendCurrentLocation (struct soap *soap, + char *wsKey,int roomCode, // input + struct swad__sendCurrentLocationOutput *sendCurrentLocationOut) // output + { + int ReturnCode; + long ChkCod; + + /***** Initializations *****/ + API_Set_gSOAP_RuntimeEnv (soap); + Gbl.WebService.Function = API_sendCurrentLocation; + + /***** Default values returned on error *****/ + sendCurrentLocationOut->success = 0; // error + + /***** Check web service key *****/ + if ((ReturnCode = API_CheckWSKey (wsKey)) != SOAP_OK) + return ReturnCode; + if (Gbl.Usrs.Me.UsrDat.UsrCod < 0) // Web service key does not exist in database + return soap_receiver_fault (soap, + "Bad web service key", + "Web service key does not exist in database"); + + /***** Get some of my data *****/ + if (!API_GetSomeUsrDataFromUsrCod (&Gbl.Usrs.Me.UsrDat,Gbl.Hierarchy.Crs.CrsCod)) + return soap_receiver_fault (soap, + "Can not get user's data from database", + "User does not exist in database"); + Gbl.Usrs.Me.Logged = true; + Gbl.Usrs.Me.Role.Logged = Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Role; + + /***** Check in (insert pair user-room) in the database *****/ + /* Get the code of the inserted item */ + ChkCod = + DB_QueryINSERTandReturnCode ("can not save current location", + "INSERT INTO room_check_in" + " (UsrCod,RooCod,CheckInTime)" + " SELECT %ld,RooCod,NOW()" + " FROM rooms" + " WHERE RooCod=%d", // Check that room exists + Gbl.Usrs.Me.UsrDat.UsrCod,roomCode); + + /***** Return notification code *****/ + sendCurrentLocationOut->success = (ChkCod > 0) ? 1 : 0; + + return SOAP_OK; + } diff --git a/swad_API.h b/swad_API.h index 5189f7841..1657c1ad1 100644 --- a/swad_API.h +++ b/swad_API.h @@ -31,7 +31,7 @@ /***************************** Public constants ******************************/ /*****************************************************************************/ -#define API_NUM_FUNCTIONS 32 +#define API_NUM_FUNCTIONS 33 /*****************************************************************************/ /******************************* Public types ********************************/ @@ -73,6 +73,7 @@ typedef enum API_getMatchStatus = 30, API_answerMatchQuestion = 31, API_getLocations = 32, + API_sendCurrentLocation = 33, } API_Function_t; /*****************************************************************************/ diff --git a/swad_changelog.h b/swad_changelog.h index 21678f7b2..784f8a64c 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -493,12 +493,15 @@ contiene una de las que yo imparto. As Función API sendCurrentLocation... Parámetros a enviar a la función: - 1. Código único de ubicación (número) + 1. Código único de la sala (número roomCode) Almacenaría esa ubicación en una tabla - Código usuario - Código de ubicación (sacado de la tabla de ubicaciones) - Fecha-hora +La tabla contendría todas las ubicaciones de todos los usuarios en las últimas 12/24 horas como mucho. +Se eliminaría periódicamante en Lay_RefreshNotifsAndConnected(). + Haría falta una función API que envíe el histórico reciente de ubicaciones de un usuario Poblar base de datos: @@ -519,6 +522,11 @@ si la intersecci es decir, no tienen por qué compartir asignaturas, pero sí al menos alguna asignatura de cada uno tiene que compartir el centro (Por ej. Eva y Antonio comparten ETSIIT, pero no titulación ni asignatura) + +Se puede mostrar las últimas dos o tres ubicaciones (y dentro de ellas sólo el último instante de cada ubicación) +dentro siempre de lo que haya guardado en la tabla de ubicaciones limitada a 12/24 h. + + */ // TODO: Sugerencia de Jesús García Miranda. En las preguntas de tipo test de elección única (o un nuevo tipo con un nuevo nombre), @@ -557,15 +565,22 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - * En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 19.246.3 (2020-05-25)" +#define Log_PLATFORM_VERSION "SWAD 19.247 (2020-05-25)" #define CSS_FILE "swad19.238.2.css" #define JS_FILE "swad19.246.1.js" /* + Version 19.247: May 24, 2020 New API function getCurrentLocation. (302622 lines) + 1 change necessary in database: +CREATE TABLE IF NOT EXISTS room_check_in (ChkCod INT NOT NULL AUTO_INCREMENT,UsrCod INT NOT NULL,RooCod INT NOT NULL,CheckInTime DATETIME NOT NULL,UNIQUE INDEX(ChkCod),INDEX(UsrCod,CheckInTime),INDEX(CheckInTime)); + If you want to use MyISAM: +ALTER TABLE room_check_in ENGINE=MyISAM; + Version 19.246.3: May 25, 2020 Fixed bug in notices. (302529 lines) Version 19.246.2: May 25, 2020 Links to edition of tags in test and test configuration. (302518 lines) Version 19.246.1: May 25, 2020 Removed unused JavaScript code. (302515 lines) Version 19.246: May 24, 2020 Fixed issue answering exam prints: when answer is been sent, button to send exam is disabled. (302527 lines) Version 19.245: May 24, 2020 Session id is stored in a separated table. (302439 lines) + 2 changes necessary in database: ALTER TABLE exa_log DROP COLUMN SessionId; CREATE TABLE IF NOT EXISTS exa_log_session (LogCod INT NOT NULL,PrnCod INT NOT NULL,SessionId CHAR(43) NOT NULL,UNIQUE INDEX(LogCod),UNIQUE INDEX(PrnCod,LogCod)); If you want to use MyISAM: diff --git a/swad_database.c b/swad_database.c index c06c99ae8..d8905daaa 100644 --- a/swad_database.c +++ b/swad_database.c @@ -2759,6 +2759,28 @@ mysql> DESCRIBE room_MAC; "UNIQUE INDEX(RooCod,MAC)," "UNIQUE INDEX(MAC,RooCod))"); + /***** Table room_check_in *****/ +/* +mysql> DESCRIBE room_check_in; ++-------------+----------+------+-----+---------+----------------+ +| Field | Type | Null | Key | Default | Extra | ++-------------+----------+------+-----+---------+----------------+ +| ChkCod | int(11) | NO | PRI | NULL | auto_increment | +| UsrCod | int(11) | NO | MUL | NULL | | +| RooCod | int(11) | NO | | NULL | | +| CheckInTime | datetime | NO | MUL | NULL | | ++-------------+----------+------+-----+---------+----------------+ +4 rows in set (0.00 sec) +*/ + DB_CreateTable ("CREATE TABLE IF NOT EXISTS room_check_in (" + "ChkCod INT NOT NULL AUTO_INCREMENT," + "UsrCod INT NOT NULL," + "RooCod INT NOT NULL," + "CheckInTime DATETIME NOT NULL," + "UNIQUE INDEX(ChkCod)," + "INDEX(UsrCod,CheckInTime)," + "INDEX(CheckInTime))"); + /***** Table sessions *****/ /* mysql> DESCRIBE sessions;