2019-12-14 14:30:34 +01:00
|
|
|
|
// swad_log.c: access log stored in 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.
|
2022-09-21 10:46:14 +02:00
|
|
|
|
Copyright (C) 1999-2022 Antonio Ca<EFBFBD>as Vargas
|
2019-12-14 14:30:34 +01:00
|
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Affero General 3 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 *********************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-03-11 09:43:30 +01:00
|
|
|
|
#include <stdlib.h> // For free
|
|
|
|
|
#include <string.h> // For strlen
|
2020-03-07 00:14:35 +01:00
|
|
|
|
|
2019-12-14 14:30:34 +01:00
|
|
|
|
#include "swad_action.h"
|
2020-04-14 17:15:17 +02:00
|
|
|
|
#include "swad_banner.h"
|
2021-06-02 13:09:30 +02:00
|
|
|
|
#include "swad_center_database.h"
|
2019-12-14 14:30:34 +01:00
|
|
|
|
#include "swad_config.h"
|
|
|
|
|
#include "swad_database.h"
|
2021-05-27 23:30:16 +02:00
|
|
|
|
#include "swad_degree_database.h"
|
2020-05-22 20:10:45 +02:00
|
|
|
|
#include "swad_exam_log.h"
|
2019-12-14 14:30:34 +01:00
|
|
|
|
#include "swad_global.h"
|
2021-02-11 23:27:48 +01:00
|
|
|
|
#include "swad_hierarchy.h"
|
2019-12-14 14:30:34 +01:00
|
|
|
|
#include "swad_HTML.h"
|
2021-09-10 12:44:17 +02:00
|
|
|
|
#include "swad_institution_database.h"
|
2019-12-14 14:30:34 +01:00
|
|
|
|
#include "swad_log.h"
|
2021-09-22 14:41:49 +02:00
|
|
|
|
#include "swad_log_database.h"
|
2019-12-14 14:30:34 +01:00
|
|
|
|
#include "swad_profile.h"
|
2021-10-07 01:21:23 +02:00
|
|
|
|
#include "swad_profile_database.h"
|
2019-12-14 14:30:34 +01:00
|
|
|
|
#include "swad_role.h"
|
|
|
|
|
#include "swad_statistic.h"
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************** External global variables from others modules ****************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
extern struct Globals Gbl;
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/**************************** Log access in database *************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Log_LogAccess (const char *Comments)
|
|
|
|
|
{
|
|
|
|
|
long LogCod;
|
|
|
|
|
long ActCod = Act_GetActCod (Gbl.Action.Act);
|
2020-03-07 00:14:35 +01:00
|
|
|
|
size_t MaxLength;
|
|
|
|
|
char *CommentsDB;
|
2020-04-06 17:16:31 +02:00
|
|
|
|
long BanCodClicked;
|
2019-12-14 14:30:34 +01:00
|
|
|
|
Rol_Role_t RoleToStore = (Gbl.Action.Act == ActLogOut) ? Gbl.Usrs.Me.Role.LoggedBeforeCloseSession :
|
|
|
|
|
Gbl.Usrs.Me.Role.Logged;
|
|
|
|
|
|
|
|
|
|
/***** Insert access into database *****/
|
2020-04-05 18:32:56 +02:00
|
|
|
|
/* Log access in historical log */
|
2021-09-22 14:41:49 +02:00
|
|
|
|
LogCod = Log_DB_LogAccessInHistoricalLog (ActCod,RoleToStore);
|
2019-12-14 14:30:34 +01:00
|
|
|
|
|
|
|
|
|
/* Log access in recent log (log_recent) */
|
2021-09-22 14:41:49 +02:00
|
|
|
|
Log_DB_LogAccessInRecentLog (LogCod,ActCod,RoleToStore);
|
2019-12-14 14:30:34 +01:00
|
|
|
|
|
2020-05-22 20:10:45 +02:00
|
|
|
|
/* Log access while answering exam prints */
|
|
|
|
|
ExaLog_LogAccess (LogCod);
|
|
|
|
|
|
2019-12-14 14:30:34 +01:00
|
|
|
|
/* Log comments */
|
|
|
|
|
if (Comments)
|
2020-03-07 00:14:35 +01:00
|
|
|
|
{
|
|
|
|
|
MaxLength = strlen (Comments) * Str_MAX_BYTES_PER_CHAR;
|
2021-02-15 16:25:55 +01:00
|
|
|
|
if ((CommentsDB = malloc (MaxLength + 1)) != NULL)
|
2020-03-07 00:14:35 +01:00
|
|
|
|
{
|
2021-02-15 16:25:55 +01:00
|
|
|
|
Str_Copy (CommentsDB,Comments,MaxLength);
|
2020-03-07 00:14:35 +01:00
|
|
|
|
Str_ChangeFormat (Str_FROM_TEXT,Str_TO_TEXT,
|
|
|
|
|
CommentsDB,MaxLength,true); // Avoid SQL injection
|
2021-09-22 14:41:49 +02:00
|
|
|
|
Log_DB_LogComments (LogCod,CommentsDB);
|
2020-03-07 00:14:35 +01:00
|
|
|
|
free (CommentsDB);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-14 14:30:34 +01:00
|
|
|
|
|
|
|
|
|
/* Log search string */
|
|
|
|
|
if (Gbl.Search.LogSearch && Gbl.Search.Str[0])
|
2021-09-22 14:41:49 +02:00
|
|
|
|
Log_DB_LogSearchString (LogCod);
|
2019-12-14 14:30:34 +01:00
|
|
|
|
|
|
|
|
|
if (Gbl.WebService.IsWebService)
|
2021-09-22 14:41:49 +02:00
|
|
|
|
/* Log web service plugin and API function */
|
|
|
|
|
Log_DB_LogAPI (LogCod);
|
2020-04-06 17:16:31 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
BanCodClicked = Ban_GetBanCodClicked ();
|
|
|
|
|
if (BanCodClicked > 0)
|
|
|
|
|
/* Log banner clicked */
|
2021-09-22 14:41:49 +02:00
|
|
|
|
Log_DB_LogBanner (LogCod,BanCodClicked);
|
2020-04-06 17:16:31 +02:00
|
|
|
|
}
|
2019-12-14 14:30:34 +01:00
|
|
|
|
|
|
|
|
|
/***** Increment my number of clicks *****/
|
|
|
|
|
if (Gbl.Usrs.Me.Logged)
|
2021-07-08 15:00:17 +02:00
|
|
|
|
Prf_DB_IncrementNumClicksUsr (Gbl.Usrs.Me.UsrDat.UsrCod);
|
2019-12-14 14:30:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*************** Put a link to show last clicks in real time *****************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Log_PutLinkToLastClicks (void)
|
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_Last_clicks;
|
|
|
|
|
|
2020-03-26 02:54:30 +01:00
|
|
|
|
Lay_PutContextualLinkIconText (ActLstClk,NULL,
|
|
|
|
|
NULL,NULL,
|
2021-12-22 00:20:06 +01:00
|
|
|
|
"mouse-pointer.svg",Ico_BLACK,
|
2021-12-22 18:54:43 +01:00
|
|
|
|
Txt_Last_clicks,NULL);
|
2019-12-14 14:30:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/****************************** Show last clicks *****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Log_ShowLastClicks (void)
|
|
|
|
|
{
|
|
|
|
|
extern const char *Hlp_USERS_Connected_last_clicks;
|
|
|
|
|
extern const char *Txt_Last_clicks_in_real_time;
|
|
|
|
|
|
|
|
|
|
/***** Contextual menu *****/
|
|
|
|
|
Mnu_ContextMenuBegin ();
|
2021-09-22 14:41:49 +02:00
|
|
|
|
Sta_PutLinkToGlobalHits (); // Global hits
|
|
|
|
|
Sta_PutLinkToCourseHits (); // Course hits
|
2019-12-14 14:30:34 +01:00
|
|
|
|
Mnu_ContextMenuEnd ();
|
|
|
|
|
|
|
|
|
|
/***** Begin box *****/
|
2020-03-26 02:54:30 +01:00
|
|
|
|
Box_BoxBegin (NULL,Txt_Last_clicks_in_real_time,
|
|
|
|
|
NULL,NULL,
|
2019-12-14 14:30:34 +01:00
|
|
|
|
Hlp_USERS_Connected_last_clicks,Box_NOT_CLOSABLE);
|
|
|
|
|
|
2021-09-22 14:41:49 +02:00
|
|
|
|
/***** Get and show last clicks *****/
|
|
|
|
|
HTM_DIV_Begin ("id=\"lastclicks\" class=\"CM\""); // Used for AJAX based refresh
|
|
|
|
|
Log_GetAndShowLastClicks ();
|
|
|
|
|
HTM_DIV_End (); // Used for AJAX based refresh
|
2019-12-14 14:30:34 +01:00
|
|
|
|
|
|
|
|
|
/***** End box *****/
|
|
|
|
|
Box_BoxEnd ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/**************** Get last clicks from database and show them ****************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Log_GetAndShowLastClicks (void)
|
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_Click;
|
|
|
|
|
extern const char *Txt_ELAPSED_TIME;
|
|
|
|
|
extern const char *Txt_Role;
|
|
|
|
|
extern const char *Txt_Country;
|
|
|
|
|
extern const char *Txt_Institution;
|
2021-03-07 21:21:04 +01:00
|
|
|
|
extern const char *Txt_Center;
|
2019-12-14 14:30:34 +01:00
|
|
|
|
extern const char *Txt_Degree;
|
|
|
|
|
extern const char *Txt_Action;
|
|
|
|
|
extern const char *Txt_ROLES_SINGUL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
|
|
|
|
|
MYSQL_RES *mysql_res;
|
|
|
|
|
MYSQL_ROW row;
|
2021-04-16 13:51:12 +02:00
|
|
|
|
unsigned NumClicks;
|
|
|
|
|
unsigned NumClick;
|
2019-12-14 14:30:34 +01:00
|
|
|
|
long ActCod;
|
2020-01-02 14:12:22 +01:00
|
|
|
|
Act_Action_t Action;
|
2019-12-14 14:30:34 +01:00
|
|
|
|
const char *ClassRow;
|
|
|
|
|
time_t TimeDiff;
|
2021-02-11 23:27:48 +01:00
|
|
|
|
struct Hie_Hierarchy Hie;
|
2019-12-14 14:30:34 +01:00
|
|
|
|
|
|
|
|
|
/***** Get last clicks from database *****/
|
2021-09-22 14:41:49 +02:00
|
|
|
|
NumClicks = Log_DB_GetLastClicks (&mysql_res);
|
2019-12-14 14:30:34 +01:00
|
|
|
|
|
|
|
|
|
/***** Write list of connected users *****/
|
|
|
|
|
HTM_TABLE_BeginCenterPadding (1);
|
|
|
|
|
|
2021-10-15 16:46:57 +02:00
|
|
|
|
/* Heading row */
|
|
|
|
|
HTM_TR_Begin (NULL);
|
2022-01-02 15:17:30 +01:00
|
|
|
|
HTM_TH_Span (Txt_Click ,HTM_HEAD_RIGHT,1,1,"LC_CLK"); // Click
|
|
|
|
|
HTM_TH_Span (Txt_ELAPSED_TIME,HTM_HEAD_RIGHT,1,1,"LC_TIM"); // Elapsed time
|
|
|
|
|
HTM_TH_Span (Txt_Role ,HTM_HEAD_LEFT ,1,1,"LC_ROL"); // Role
|
|
|
|
|
HTM_TH_Span (Txt_Country ,HTM_HEAD_LEFT ,1,1,"LC_CTY"); // Country
|
|
|
|
|
HTM_TH_Span (Txt_Institution ,HTM_HEAD_LEFT ,1,1,"LC_INS"); // Institution
|
|
|
|
|
HTM_TH_Span (Txt_Center ,HTM_HEAD_LEFT ,1,1,"LC_CTR"); // Center
|
|
|
|
|
HTM_TH_Span (Txt_Degree ,HTM_HEAD_LEFT ,1,1,"LC_DEG"); // Degree
|
|
|
|
|
HTM_TH_Span (Txt_Action ,HTM_HEAD_LEFT ,1,1,"LC_ACT"); // Action
|
2021-06-02 13:09:30 +02:00
|
|
|
|
HTM_TR_End ();
|
2019-12-14 14:30:34 +01:00
|
|
|
|
|
2021-06-02 13:09:30 +02:00
|
|
|
|
for (NumClick = 0;
|
|
|
|
|
NumClick < NumClicks;
|
|
|
|
|
NumClick++)
|
|
|
|
|
{
|
|
|
|
|
row = mysql_fetch_row (mysql_res);
|
2019-12-14 14:30:34 +01:00
|
|
|
|
|
2021-06-02 13:09:30 +02:00
|
|
|
|
/* Get action code (row[1]) */
|
|
|
|
|
ActCod = Str_ConvertStrCodToLongCod (row[1]);
|
|
|
|
|
Action = Act_GetActionFromActCod (ActCod);
|
2019-12-14 14:30:34 +01:00
|
|
|
|
|
2021-06-02 13:09:30 +02:00
|
|
|
|
/* Use a special color for this row depending on the action */
|
2022-03-25 00:48:40 +01:00
|
|
|
|
ClassRow = (Act_GetBrowserTab (Action) == Act_DOWNLD_FILE) ? "DAT_SMALL_YELLOW" :
|
2021-06-02 13:09:30 +02:00
|
|
|
|
(ActCod == Act_GetActCod (ActLogIn ) ||
|
2022-03-25 00:48:40 +01:00
|
|
|
|
ActCod == Act_GetActCod (ActLogInNew)) ? "DAT_SMALL_GREEN" :
|
|
|
|
|
(ActCod == Act_GetActCod (ActLogOut )) ? "DAT_SMALL_RED" :
|
|
|
|
|
(ActCod == Act_GetActCod (ActWebSvc )) ? "DAT_SMALL_BLUE" :
|
|
|
|
|
"DAT_SMALL";
|
2019-12-14 14:30:34 +01:00
|
|
|
|
|
2021-06-02 13:09:30 +02:00
|
|
|
|
/* Compute elapsed time from last access */
|
|
|
|
|
if (sscanf (row[2],"%ld",&TimeDiff) != 1)
|
|
|
|
|
TimeDiff = (time_t) 0;
|
2019-12-14 14:30:34 +01:00
|
|
|
|
|
2021-06-02 13:09:30 +02:00
|
|
|
|
/* Get country code (row[4]) */
|
|
|
|
|
Hie.Cty.CtyCod = Str_ConvertStrCodToLongCod (row[4]);
|
|
|
|
|
Cty_GetCountryName (Hie.Cty.CtyCod,Gbl.Prefs.Language,
|
|
|
|
|
Hie.Cty.Name[Gbl.Prefs.Language]);
|
2019-12-14 14:30:34 +01:00
|
|
|
|
|
2021-10-15 16:46:57 +02:00
|
|
|
|
/* Get institution code (row[5]),
|
|
|
|
|
center code (row[6])
|
|
|
|
|
and degree code (row[7]) */
|
2021-06-02 13:09:30 +02:00
|
|
|
|
Hie.Ins.InsCod = Str_ConvertStrCodToLongCod (row[5]);
|
|
|
|
|
Hie.Ctr.CtrCod = Str_ConvertStrCodToLongCod (row[6]);
|
|
|
|
|
Hie.Deg.DegCod = Str_ConvertStrCodToLongCod (row[7]);
|
2021-10-15 16:46:57 +02:00
|
|
|
|
Ins_DB_GetShortNameOfInstitution (Hie.Ins.InsCod,Hie.Ins.ShrtName);
|
|
|
|
|
Ctr_DB_GetShortNameOfCenterByCod (Hie.Ctr.CtrCod,Hie.Ctr.ShrtName);
|
2021-06-02 13:09:30 +02:00
|
|
|
|
Deg_DB_GetShortNameOfDegreeByCod (Hie.Deg.DegCod,Hie.Deg.ShrtName);
|
|
|
|
|
|
|
|
|
|
/* Print table row */
|
|
|
|
|
HTM_TR_Begin (NULL);
|
|
|
|
|
|
2022-03-25 00:48:40 +01:00
|
|
|
|
HTM_TD_Begin ("class=\"LC_CLK %s_%s\"",
|
2022-04-05 01:00:24 +02:00
|
|
|
|
ClassRow,The_GetSuffix ());
|
2022-03-25 00:48:40 +01:00
|
|
|
|
HTM_Txt (row[0]); // Click
|
2021-06-02 13:09:30 +02:00
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
2022-03-25 00:48:40 +01:00
|
|
|
|
HTM_TD_Begin ("class=\"LC_TIM %s_%s\"",
|
2022-04-05 01:00:24 +02:00
|
|
|
|
ClassRow,The_GetSuffix ());
|
2022-03-25 00:48:40 +01:00
|
|
|
|
Dat_WriteHoursMinutesSecondsFromSeconds (TimeDiff); // Elapsed time
|
2021-06-02 13:09:30 +02:00
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
2022-03-25 00:48:40 +01:00
|
|
|
|
HTM_TD_Begin ("class=\"LC_ROL %s_%s\"",
|
2022-04-05 01:00:24 +02:00
|
|
|
|
ClassRow,The_GetSuffix ());
|
2021-06-02 13:09:30 +02:00
|
|
|
|
HTM_Txt (Txt_ROLES_SINGUL_Abc[Rol_ConvertUnsignedStrToRole (row[3])][Usr_SEX_UNKNOWN]); // Role
|
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
2022-03-25 00:48:40 +01:00
|
|
|
|
HTM_TD_Begin ("class=\"LC_CTY %s_%s\"",
|
2022-04-05 01:00:24 +02:00
|
|
|
|
ClassRow,The_GetSuffix ());
|
2022-03-25 00:48:40 +01:00
|
|
|
|
HTM_Txt (Hie.Cty.Name[Gbl.Prefs.Language]); // Country
|
2021-06-02 13:09:30 +02:00
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
2022-03-25 00:48:40 +01:00
|
|
|
|
HTM_TD_Begin ("class=\"LC_INS %s_%s\"",
|
2022-04-05 01:00:24 +02:00
|
|
|
|
ClassRow,The_GetSuffix ());
|
2022-03-25 00:48:40 +01:00
|
|
|
|
HTM_Txt (Hie.Ins.ShrtName); // Institution
|
2021-06-02 13:09:30 +02:00
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
2022-03-25 00:48:40 +01:00
|
|
|
|
HTM_TD_Begin ("class=\"LC_CTR %s_%s\"",
|
2022-04-05 01:00:24 +02:00
|
|
|
|
ClassRow,The_GetSuffix ());
|
2022-03-25 00:48:40 +01:00
|
|
|
|
HTM_Txt (Hie.Ctr.ShrtName); // Center
|
2021-06-02 13:09:30 +02:00
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
2022-03-25 00:48:40 +01:00
|
|
|
|
HTM_TD_Begin ("class=\"LC_DEG %s_%s\"",
|
2022-04-05 01:00:24 +02:00
|
|
|
|
ClassRow,The_GetSuffix ());
|
2022-03-25 00:48:40 +01:00
|
|
|
|
HTM_Txt (Hie.Deg.ShrtName); // Degree
|
2021-06-02 13:09:30 +02:00
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
2022-03-25 00:48:40 +01:00
|
|
|
|
HTM_TD_Begin ("class=\"LC_ACT %s_%s\"",
|
2022-04-05 01:00:24 +02:00
|
|
|
|
ClassRow,The_GetSuffix ());
|
2022-03-25 00:48:40 +01:00
|
|
|
|
HTM_Txt (Act_GetActionText (Action)); // Action
|
2021-06-02 13:09:30 +02:00
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
|
|
|
|
HTM_TR_End ();
|
|
|
|
|
}
|
2021-10-15 16:46:57 +02:00
|
|
|
|
|
2019-12-14 14:30:34 +01:00
|
|
|
|
HTM_TABLE_End ();
|
|
|
|
|
|
|
|
|
|
/***** Free structure that stores the query result *****/
|
2020-02-24 12:43:18 +01:00
|
|
|
|
DB_FreeMySQLResult (&mysql_res);
|
2019-12-14 14:30:34 +01:00
|
|
|
|
}
|