2020-05-22 20:10:45 +02:00
|
|
|
|
// swad_exam_log.c: exam access log
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
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.
|
2021-02-09 12:43:45 +01:00
|
|
|
|
Copyright (C) 1999-2021 Antonio Ca<EFBFBD>as Vargas
|
2020-05-22 20:10:45 +02:00
|
|
|
|
|
|
|
|
|
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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************************* Headers ***********************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-05-23 20:51:51 +02:00
|
|
|
|
#define _GNU_SOURCE // For asprintf
|
|
|
|
|
#include <stdio.h> // For asprintf
|
2020-05-25 00:18:09 +02:00
|
|
|
|
#include <stdlib.h> // For system, getenv, etc.
|
2020-05-23 20:51:51 +02:00
|
|
|
|
#include <string.h> // For string functions
|
|
|
|
|
|
2020-05-22 20:10:45 +02:00
|
|
|
|
#include "swad_action.h"
|
|
|
|
|
#include "swad_database.h"
|
2020-05-23 15:53:53 +02:00
|
|
|
|
#include "swad_exam_log.h"
|
2020-05-22 20:10:45 +02:00
|
|
|
|
#include "swad_global.h"
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************** External global variables from others modules ****************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
extern struct Globals Gbl;
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Private constants *****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************************* Private types *******************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Private variables *****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-05-23 13:24:08 +02:00
|
|
|
|
static struct
|
|
|
|
|
{
|
2020-05-23 15:53:53 +02:00
|
|
|
|
long PrnCod; // Exam print code
|
|
|
|
|
int QstInd; // Exam print question index
|
|
|
|
|
ExaLog_Action_t Action; // Action performed by user
|
2020-05-23 19:08:59 +02:00
|
|
|
|
bool ICanAnswer; // Exam print is open and accesible to answer by the user
|
2020-05-23 15:53:53 +02:00
|
|
|
|
} ExaLog_Log =
|
2020-05-23 13:24:08 +02:00
|
|
|
|
{
|
2020-05-23 19:08:59 +02:00
|
|
|
|
.PrnCod = -1L, // -1 means no print code set
|
|
|
|
|
.QstInd = -1, // -1 means no question index set
|
|
|
|
|
.Action = ExaLog_UNKNOWN_ACTION,
|
|
|
|
|
.ICanAnswer = false,
|
2020-05-23 13:24:08 +02:00
|
|
|
|
};
|
|
|
|
|
|
2020-05-22 20:10:45 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Private prototypes ****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-05-24 18:26:40 +02:00
|
|
|
|
static void ExaLog_LogSession (long LogCod,long PrnCod);
|
2020-05-24 15:42:51 +02:00
|
|
|
|
static void ExaLog_LogUsrAgent (long LogCod,long PrnCod);
|
|
|
|
|
|
2020-05-23 13:24:08 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************* Set and get current exam print code (used in log) *************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-05-23 15:53:53 +02:00
|
|
|
|
void ExaLog_SetAction (ExaLog_Action_t Action)
|
|
|
|
|
{
|
|
|
|
|
ExaLog_Log.Action = Action;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ExaLog_Action_t ExaLog_GetAction (void)
|
|
|
|
|
{
|
|
|
|
|
return ExaLog_Log.Action;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2020-05-23 19:08:59 +02:00
|
|
|
|
/******************** Set and get current exam print code ********************/
|
2020-05-23 15:53:53 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void ExaLog_SetPrnCod (long PrnCod)
|
2020-05-23 13:24:08 +02:00
|
|
|
|
{
|
2020-05-23 15:53:53 +02:00
|
|
|
|
ExaLog_Log.PrnCod = PrnCod;
|
2020-05-23 13:24:08 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-23 15:53:53 +02:00
|
|
|
|
long ExaLog_GetPrnCod (void)
|
2020-05-23 13:24:08 +02:00
|
|
|
|
{
|
2020-05-23 15:53:53 +02:00
|
|
|
|
return ExaLog_Log.PrnCod;
|
2020-05-23 13:24:08 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2020-05-23 19:08:59 +02:00
|
|
|
|
/************* Set and get current question index in exam print **************/
|
2020-05-23 13:24:08 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-05-23 15:53:53 +02:00
|
|
|
|
void ExaLog_SetQstInd (unsigned QstInd)
|
2020-05-23 13:24:08 +02:00
|
|
|
|
{
|
2020-05-23 15:53:53 +02:00
|
|
|
|
ExaLog_Log.QstInd = (int) QstInd;
|
2020-05-23 13:24:08 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-23 15:53:53 +02:00
|
|
|
|
int ExaLog_GetQstInd (void)
|
2020-05-23 13:24:08 +02:00
|
|
|
|
{
|
2020-05-23 15:53:53 +02:00
|
|
|
|
return ExaLog_Log.QstInd;
|
2020-05-23 13:24:08 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2020-05-23 19:08:59 +02:00
|
|
|
|
/************* Set and get if exam print is open and accessible **************/
|
2020-05-23 13:24:08 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-05-23 19:08:59 +02:00
|
|
|
|
void ExaLog_SetIfCanAnswer (bool ICanAnswer)
|
2020-05-23 13:24:08 +02:00
|
|
|
|
{
|
2020-05-23 19:08:59 +02:00
|
|
|
|
ExaLog_Log.ICanAnswer = ICanAnswer;
|
2020-05-23 13:24:08 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-23 19:08:59 +02:00
|
|
|
|
bool ExaLog_GetIfCanAnswer (void)
|
2020-05-23 13:24:08 +02:00
|
|
|
|
{
|
2020-05-23 19:08:59 +02:00
|
|
|
|
return ExaLog_Log.ICanAnswer;
|
2020-05-23 13:24:08 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-22 20:10:45 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/**************************** Log access in database *************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void ExaLog_LogAccess (long LogCod)
|
|
|
|
|
{
|
2020-05-23 15:53:53 +02:00
|
|
|
|
ExaLog_Action_t Action;
|
2020-05-22 20:10:45 +02:00
|
|
|
|
long PrnCod;
|
|
|
|
|
|
2020-05-23 15:53:53 +02:00
|
|
|
|
Action = ExaLog_GetAction ();
|
|
|
|
|
if (Action != ExaLog_UNKNOWN_ACTION)
|
2020-05-22 20:10:45 +02:00
|
|
|
|
{
|
2020-05-23 15:53:53 +02:00
|
|
|
|
PrnCod = ExaLog_GetPrnCod ();
|
2020-05-22 20:10:45 +02:00
|
|
|
|
|
|
|
|
|
if (PrnCod > 0) // Only if exam print is accesible (visible, open...)
|
2020-05-24 15:42:51 +02:00
|
|
|
|
{
|
2020-05-22 20:10:45 +02:00
|
|
|
|
/***** Insert access into database *****/
|
|
|
|
|
/* Log access in exam log.
|
|
|
|
|
Redundant data (also present in log table) are stored for speed */
|
|
|
|
|
DB_QueryINSERT ("can not log exam access",
|
|
|
|
|
"INSERT INTO exa_log "
|
2020-05-24 18:26:40 +02:00
|
|
|
|
"(LogCod,PrnCod,ActCod,QstInd,CanAnswer,ClickTime,IP)"
|
2020-05-22 20:10:45 +02:00
|
|
|
|
" VALUES "
|
2020-05-24 18:26:40 +02:00
|
|
|
|
"(%ld,%ld,%ld,%d,'%c',NOW(),'%s')",
|
2020-05-22 20:10:45 +02:00
|
|
|
|
LogCod,
|
|
|
|
|
PrnCod,
|
2020-05-23 15:53:53 +02:00
|
|
|
|
(unsigned) Action,
|
|
|
|
|
ExaLog_GetQstInd (),
|
2020-05-23 19:08:59 +02:00
|
|
|
|
ExaLog_GetIfCanAnswer () ? 'Y' :
|
|
|
|
|
'N',
|
2020-05-23 15:53:53 +02:00
|
|
|
|
// NOW() Redundant, for speed
|
2020-05-24 18:26:40 +02:00
|
|
|
|
Gbl.IP); // Redundant, for speed
|
2020-05-24 15:42:51 +02:00
|
|
|
|
|
2020-05-24 18:26:40 +02:00
|
|
|
|
/***** Log session and user agent *****/
|
|
|
|
|
ExaLog_LogSession (LogCod,PrnCod);
|
2020-05-24 15:42:51 +02:00
|
|
|
|
ExaLog_LogUsrAgent (LogCod,PrnCod);
|
|
|
|
|
}
|
2020-05-22 20:10:45 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-23 20:51:51 +02:00
|
|
|
|
|
2020-05-24 18:26:40 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*************************** Log session in database *************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void ExaLog_LogSession (long LogCod,long PrnCod)
|
|
|
|
|
{
|
|
|
|
|
bool TheSameAsTheLast;
|
|
|
|
|
|
|
|
|
|
/***** Get if the current session id
|
|
|
|
|
is the same as the last stored in database *****/
|
|
|
|
|
TheSameAsTheLast = (DB_QueryCOUNT ("can not check session",
|
|
|
|
|
"SELECT COUNT(*)"
|
|
|
|
|
" FROM exa_log_session"
|
|
|
|
|
" WHERE LogCod="
|
|
|
|
|
"(SELECT MAX(LogCod)"
|
|
|
|
|
" FROM exa_log_session"
|
|
|
|
|
" WHERE PrnCod=%ld)"
|
|
|
|
|
" AND SessionId='%s'",
|
|
|
|
|
PrnCod,
|
|
|
|
|
Gbl.Session.Id) != 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***** Insert session id into database
|
|
|
|
|
only if it's not the same as the last one stored *****/
|
|
|
|
|
if (!TheSameAsTheLast)
|
|
|
|
|
DB_QueryINSERT ("can not log session",
|
|
|
|
|
"INSERT INTO exa_log_session "
|
|
|
|
|
"(LogCod,PrnCod,SessionId)"
|
|
|
|
|
" VALUES "
|
|
|
|
|
"(%ld,%ld,'%s')",
|
|
|
|
|
LogCod,
|
|
|
|
|
PrnCod,
|
|
|
|
|
Gbl.Session.Id);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-24 15:42:51 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************** Log user agent in database ***********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Examples of HTTP_USER_AGENT:
|
|
|
|
|
Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0
|
|
|
|
|
Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0
|
|
|
|
|
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
|
|
|
|
|
Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1
|
|
|
|
|
Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0)
|
|
|
|
|
Googlebot/2.1 (+http://www.google.com/bot.html)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static void ExaLog_LogUsrAgent (long LogCod,long PrnCod)
|
|
|
|
|
{
|
|
|
|
|
bool TheSameAsTheLast;
|
|
|
|
|
const char *UserAgent;
|
|
|
|
|
char *UserAgentDB;
|
|
|
|
|
size_t MaxBytes;
|
|
|
|
|
|
|
|
|
|
/***** Get current user agent *****/
|
|
|
|
|
UserAgent = getenv ("HTTP_USER_AGENT");
|
|
|
|
|
if (UserAgent)
|
|
|
|
|
MaxBytes = strlen (UserAgent) * Str_MAX_BYTES_PER_CHAR;
|
|
|
|
|
else
|
|
|
|
|
MaxBytes = 0;
|
2021-02-15 16:25:55 +01:00
|
|
|
|
if ((UserAgentDB = malloc (MaxBytes + 1)) == NULL)
|
2020-05-24 15:42:51 +02:00
|
|
|
|
Lay_NotEnoughMemoryExit ();
|
|
|
|
|
if (UserAgent)
|
|
|
|
|
{
|
2021-02-15 16:25:55 +01:00
|
|
|
|
Str_Copy (UserAgentDB,UserAgent,MaxBytes);
|
2020-05-24 15:42:51 +02:00
|
|
|
|
Str_ChangeFormat (Str_FROM_TEXT,Str_TO_TEXT,
|
|
|
|
|
UserAgentDB,MaxBytes,true);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
UserAgentDB[0] = '\0';
|
|
|
|
|
|
|
|
|
|
/***** Get if the current user agent
|
|
|
|
|
is the same as the last stored in database *****/
|
|
|
|
|
TheSameAsTheLast = (DB_QueryCOUNT ("can not check user agent",
|
|
|
|
|
"SELECT COUNT(*)"
|
|
|
|
|
" FROM exa_log_user_agent"
|
|
|
|
|
" WHERE LogCod="
|
|
|
|
|
"(SELECT MAX(LogCod)"
|
|
|
|
|
" FROM exa_log_user_agent"
|
|
|
|
|
" WHERE PrnCod=%ld)"
|
|
|
|
|
" AND UserAgent='%s'",
|
|
|
|
|
PrnCod,
|
|
|
|
|
UserAgentDB) != 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***** Insert user agent into database
|
|
|
|
|
only if it's not the same as the last one stored *****/
|
|
|
|
|
if (!TheSameAsTheLast)
|
|
|
|
|
DB_QueryINSERT ("can not log user agent",
|
|
|
|
|
"INSERT INTO exa_log_user_agent "
|
|
|
|
|
"(LogCod,PrnCod,UserAgent)"
|
|
|
|
|
" VALUES "
|
|
|
|
|
"(%ld,%ld,'%s')",
|
|
|
|
|
LogCod,
|
|
|
|
|
PrnCod,
|
|
|
|
|
UserAgentDB);
|
|
|
|
|
|
|
|
|
|
/***** Free user agent *****/
|
|
|
|
|
free (UserAgentDB);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-23 20:51:51 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/****************************** Show exam log ********************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void ExaLog_ShowExamLog (const struct ExaPrn_Print *Print)
|
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_Hits;
|
2020-05-25 00:18:09 +02:00
|
|
|
|
extern const char *Txt_Click;
|
2020-05-23 20:51:51 +02:00
|
|
|
|
extern const char *Txt_Date_and_time;
|
|
|
|
|
extern const char *Txt_Action;
|
|
|
|
|
extern const char *Txt_Question;
|
|
|
|
|
extern const char *Txt_EXAM_Open;
|
|
|
|
|
extern const char *Txt_IP;
|
|
|
|
|
extern const char *Txt_Session;
|
2020-05-24 15:42:51 +02:00
|
|
|
|
extern const char *Txt_Web_browser;
|
2020-05-23 20:51:51 +02:00
|
|
|
|
extern const char *Txt_EXAM_LOG_ACTIONS[ExaLog_NUM_ACTIONS];
|
|
|
|
|
MYSQL_RES *mysql_res;
|
|
|
|
|
MYSQL_ROW row;
|
|
|
|
|
unsigned NumClicks;
|
|
|
|
|
unsigned NumClick;
|
|
|
|
|
unsigned ActCod;
|
2020-05-25 00:18:09 +02:00
|
|
|
|
ExaLog_Action_t Action;
|
2020-05-23 20:51:51 +02:00
|
|
|
|
int QstInd;
|
|
|
|
|
bool UsrCouldAnswer;
|
|
|
|
|
time_t ClickTimeUTC;
|
|
|
|
|
char IP[Cns_MAX_BYTES_IP + 1];
|
|
|
|
|
char *Id;
|
|
|
|
|
size_t Length;
|
2020-05-24 15:42:51 +02:00
|
|
|
|
char Anonymized[14 + 1]; // ***…***
|
2020-05-23 20:51:51 +02:00
|
|
|
|
// 12345678901234
|
2020-05-25 00:18:09 +02:00
|
|
|
|
char SessionId[Cns_BYTES_SESSION_ID + 1];
|
|
|
|
|
char *UserAgent;
|
|
|
|
|
const char *Class;
|
2020-05-23 20:51:51 +02:00
|
|
|
|
|
|
|
|
|
/***** Get print log from database *****/
|
|
|
|
|
NumClicks = (unsigned)
|
|
|
|
|
DB_QuerySELECT (&mysql_res,"can not get exam print log",
|
2020-05-24 15:42:51 +02:00
|
|
|
|
"SELECT exa_log.ActCod," // row[0]
|
|
|
|
|
"exa_log.QstInd," // row[1]
|
|
|
|
|
"exa_log.CanAnswer," // row[2]
|
|
|
|
|
"UNIX_TIMESTAMP(exa_log.ClickTime)," // row[3]
|
|
|
|
|
"exa_log.IP," // row[4]
|
2020-05-24 18:26:40 +02:00
|
|
|
|
"exa_log_session.SessionId," // row[5]
|
2020-05-24 15:42:51 +02:00
|
|
|
|
"exa_log_user_agent.UserAgent" // row[6]
|
2020-05-24 18:26:40 +02:00
|
|
|
|
" FROM exa_log LEFT JOIN exa_log_session"
|
|
|
|
|
" ON exa_log.LogCod=exa_log_session.LogCod"
|
|
|
|
|
" LEFT JOIN exa_log_user_agent"
|
2020-05-24 15:42:51 +02:00
|
|
|
|
" ON exa_log.LogCod=exa_log_user_agent.LogCod"
|
|
|
|
|
" WHERE exa_log.PrnCod=%ld"
|
|
|
|
|
" ORDER BY exa_log.LogCod",
|
2020-05-23 20:51:51 +02:00
|
|
|
|
Print->PrnCod);
|
|
|
|
|
|
|
|
|
|
if (NumClicks)
|
|
|
|
|
{
|
2020-05-24 18:26:40 +02:00
|
|
|
|
/***** Initialize last session id and last user agent ******/
|
2020-05-25 00:18:09 +02:00
|
|
|
|
SessionId[0] = '\0';
|
|
|
|
|
UserAgent = NULL;
|
2020-05-24 18:26:40 +02:00
|
|
|
|
|
2020-05-23 20:51:51 +02:00
|
|
|
|
/***** Begin box *****/
|
|
|
|
|
Box_BoxTableBegin (NULL,Txt_Hits,
|
|
|
|
|
NULL,NULL,
|
|
|
|
|
NULL,Box_CLOSABLE,2);
|
|
|
|
|
|
|
|
|
|
/***** Begin table *****/
|
|
|
|
|
HTM_TABLE_BeginWideMarginPadding (2);
|
|
|
|
|
|
|
|
|
|
/***** Write heading *****/
|
|
|
|
|
HTM_TR_Begin (NULL);
|
|
|
|
|
|
2020-05-25 00:18:09 +02:00
|
|
|
|
HTM_TH (1,1,"RB",Txt_Click);
|
2020-05-23 20:51:51 +02:00
|
|
|
|
HTM_TH (1,1,"LB",Txt_Date_and_time);
|
|
|
|
|
HTM_TH (1,1,"LB",Txt_Action);
|
|
|
|
|
HTM_TH (1,1,"RB",Txt_Question);
|
|
|
|
|
HTM_TH (1,1,"CB",Txt_EXAM_Open);
|
|
|
|
|
HTM_TH (1,1,"LB",Txt_IP);
|
|
|
|
|
HTM_TH (1,1,"LB",Txt_Session);
|
2020-05-24 15:42:51 +02:00
|
|
|
|
HTM_TH (1,1,"LB",Txt_Web_browser);
|
2020-05-23 20:51:51 +02:00
|
|
|
|
|
|
|
|
|
HTM_TR_End ();
|
|
|
|
|
|
|
|
|
|
/***** Write clicks *****/
|
|
|
|
|
for (NumClick = 0;
|
|
|
|
|
NumClick < NumClicks;
|
|
|
|
|
NumClick++)
|
|
|
|
|
{
|
2020-05-24 18:26:40 +02:00
|
|
|
|
Gbl.RowEvenOdd = NumClick % 2;
|
|
|
|
|
|
2020-05-23 20:51:51 +02:00
|
|
|
|
/***** Get row *****/
|
|
|
|
|
row = mysql_fetch_row (mysql_res);
|
|
|
|
|
|
|
|
|
|
/* Get code of action (row[0]) */
|
|
|
|
|
ActCod = Str_ConvertStrToUnsigned (row[0]);
|
2020-05-25 00:18:09 +02:00
|
|
|
|
if (ActCod < ExaLog_NUM_ACTIONS)
|
|
|
|
|
Action = (ExaLog_Action_t) ActCod;
|
|
|
|
|
else
|
|
|
|
|
Action = ExaLog_UNKNOWN_ACTION;
|
2020-05-23 20:51:51 +02:00
|
|
|
|
|
|
|
|
|
/* Get question index (row[1]) */
|
|
|
|
|
QstInd = (int) Str_ConvertStrCodToLongCod (row[1]);
|
|
|
|
|
|
|
|
|
|
/* Get if the user could answer (row[2]) */
|
|
|
|
|
UsrCouldAnswer = (row[2][0] == 'Y');
|
|
|
|
|
|
|
|
|
|
/* Get click time (row[3] holds the UTC time) */
|
|
|
|
|
ClickTimeUTC = Dat_GetUNIXTimeFromStr (row[3]);
|
|
|
|
|
|
|
|
|
|
/* Get IP (row[4]) */
|
2021-02-15 16:25:55 +01:00
|
|
|
|
Str_Copy (IP,row[4],sizeof (IP) - 1);
|
2020-05-23 20:51:51 +02:00
|
|
|
|
|
|
|
|
|
/* Get session id (row[5]) */
|
2021-02-15 16:25:55 +01:00
|
|
|
|
Str_Copy (SessionId,row[5] ? row[5] : // This row has a user agent stored in database
|
|
|
|
|
"=",
|
|
|
|
|
sizeof (SessionId) - 1);
|
2020-05-23 20:51:51 +02:00
|
|
|
|
|
2020-05-24 15:42:51 +02:00
|
|
|
|
/* Get session id (row[6]) */
|
2020-05-25 00:18:09 +02:00
|
|
|
|
if (asprintf (&UserAgent,"%s",row[6] ? row[6] :
|
|
|
|
|
"=") < 0)
|
|
|
|
|
Lay_NotEnoughMemoryExit ();
|
|
|
|
|
|
|
|
|
|
/***** Set color of row depending on action *****/
|
|
|
|
|
if (UsrCouldAnswer)
|
|
|
|
|
switch (Action)
|
|
|
|
|
{
|
|
|
|
|
case ExaLog_START_EXAM:
|
|
|
|
|
case ExaLog_RESUME_EXAM:
|
|
|
|
|
case ExaLog_FINISH_EXAM:
|
|
|
|
|
Class = "DAT_SMALL_N";
|
|
|
|
|
break;
|
|
|
|
|
case ExaLog_ANSWER_QUESTION:
|
|
|
|
|
Class = "DAT_SMALL";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Class = "DAT_SMALL_LIGHT";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else // Closed or not accesible exam print
|
|
|
|
|
Class = "DAT_SMALL_LIGHT";
|
2020-05-24 15:42:51 +02:00
|
|
|
|
|
2020-05-23 20:51:51 +02:00
|
|
|
|
/***** Write row *****/
|
|
|
|
|
HTM_TR_Begin (NULL);
|
|
|
|
|
|
2020-05-25 00:18:09 +02:00
|
|
|
|
/* Write number of click */
|
|
|
|
|
HTM_TD_Begin ("class=\"RT COLOR%u %s\"",
|
|
|
|
|
Gbl.RowEvenOdd,UsrCouldAnswer ? "DAT_SMALL" :
|
|
|
|
|
"DAT_SMALL_LIGHT");
|
|
|
|
|
HTM_Unsigned (NumClick + 1);
|
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
2020-05-23 20:51:51 +02:00
|
|
|
|
/* Write click time */
|
|
|
|
|
if (asprintf (&Id,"click_date_%u",NumClick) < 0)
|
|
|
|
|
Lay_NotEnoughMemoryExit ();
|
2020-05-25 00:18:09 +02:00
|
|
|
|
HTM_TD_Begin ("id=\"%s\" class=\"LT COLOR%u %s\"",Id,Gbl.RowEvenOdd,Class);
|
2020-05-23 20:51:51 +02:00
|
|
|
|
Dat_WriteLocalDateHMSFromUTC (Id,ClickTimeUTC,
|
|
|
|
|
Gbl.Prefs.DateFormat,Dat_SEPARATOR_COMMA,
|
|
|
|
|
true,true,true,0x7);
|
|
|
|
|
free (Id);
|
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
|
|
|
|
/* Write action */
|
2020-05-25 00:18:09 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"LT COLOR%u %s\"",Gbl.RowEvenOdd,Class);
|
|
|
|
|
HTM_Txt (Txt_EXAM_LOG_ACTIONS[Action]);
|
2020-05-23 20:51:51 +02:00
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
|
|
|
|
/* Write number of question */
|
2020-05-25 00:18:09 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"RT COLOR%u %s\"",Gbl.RowEvenOdd,Class);
|
2020-05-23 20:51:51 +02:00
|
|
|
|
if (QstInd >= 0)
|
|
|
|
|
HTM_Unsigned ((unsigned) QstInd + 1);
|
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
|
|
|
|
/* Write if exam print was open and accesible to answer */
|
2020-05-24 18:26:40 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"CT COLOR%u %s\"",
|
|
|
|
|
Gbl.RowEvenOdd,UsrCouldAnswer ? "DAT_SMALL_GREEN" :
|
|
|
|
|
"DAT_SMALL_RED");
|
2020-05-23 20:51:51 +02:00
|
|
|
|
HTM_Txt (UsrCouldAnswer ? "✓" :
|
|
|
|
|
"✗");
|
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
|
|
|
|
/* Write IP */
|
2020-05-25 00:18:09 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"LT COLOR%u %s\"",Gbl.RowEvenOdd,Class);
|
2020-05-23 20:51:51 +02:00
|
|
|
|
Length = strlen (IP);
|
|
|
|
|
if (Length > 6)
|
|
|
|
|
{
|
|
|
|
|
sprintf (Anonymized,"%c%c%c…%c%c%c",
|
|
|
|
|
IP[0],
|
|
|
|
|
IP[1],
|
|
|
|
|
IP[2],
|
|
|
|
|
IP[Length - 3],
|
|
|
|
|
IP[Length - 2],
|
|
|
|
|
IP[Length - 1]);
|
|
|
|
|
HTM_Txt (Anonymized);
|
|
|
|
|
}
|
|
|
|
|
else
|
2020-05-24 15:42:51 +02:00
|
|
|
|
HTM_Txt (IP);
|
2020-05-23 20:51:51 +02:00
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
|
|
|
|
/* Write session id */
|
2020-05-25 00:18:09 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"LT COLOR%u %s\"",Gbl.RowEvenOdd,Class);
|
|
|
|
|
if (SessionId[0])
|
2020-05-23 20:51:51 +02:00
|
|
|
|
{
|
2020-05-25 00:18:09 +02:00
|
|
|
|
Length = strlen (SessionId);
|
|
|
|
|
if (Length > 6)
|
|
|
|
|
{
|
|
|
|
|
sprintf (Anonymized,"%c%c%c…%c%c%c",
|
|
|
|
|
SessionId[0],
|
|
|
|
|
SessionId[1],
|
|
|
|
|
SessionId[2],
|
|
|
|
|
SessionId[Length - 3],
|
|
|
|
|
SessionId[Length - 2],
|
|
|
|
|
SessionId[Length - 1]);
|
|
|
|
|
HTM_Txt (Anonymized);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
HTM_Txt (SessionId);
|
2020-05-23 20:51:51 +02:00
|
|
|
|
}
|
2020-05-24 15:42:51 +02:00
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
|
|
|
|
/* Write user agent (row[6]) */
|
2020-05-25 00:18:09 +02:00
|
|
|
|
HTM_TD_Begin ("class=\"LT COLOR%u %s\"",Gbl.RowEvenOdd,Class);
|
|
|
|
|
if (UserAgent[0])
|
|
|
|
|
HTM_Txt (UserAgent);
|
2020-05-23 20:51:51 +02:00
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
|
|
|
|
HTM_TR_End ();
|
2020-05-25 00:18:09 +02:00
|
|
|
|
|
|
|
|
|
/***** Free user agent *****/
|
|
|
|
|
free (UserAgent);
|
2020-05-23 20:51:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***** End table and box *****/
|
|
|
|
|
Box_BoxTableEnd ();
|
2020-05-24 18:26:40 +02:00
|
|
|
|
}
|
2020-05-24 15:42:51 +02:00
|
|
|
|
|
2020-05-23 20:51:51 +02:00
|
|
|
|
/***** Free structure that stores the query result *****/
|
|
|
|
|
DB_FreeMySQLResult (&mysql_res);
|
|
|
|
|
}
|