swad-core/swad_report.c

1432 lines
52 KiB
C
Raw Normal View History

2016-09-08 18:04:30 +02:00
// swad_report.c: report on my use of the platform
/*
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-2016 Antonio Ca<EFBFBD>as Vargas
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 *********************************/
/*****************************************************************************/
2016-10-04 02:32:25 +02:00
#include <sys/stat.h> // For mkdir
#include <sys/types.h> // For mkdir
2016-09-08 18:04:30 +02:00
2016-09-11 21:25:14 +02:00
#include "swad_database.h"
2016-09-08 19:21:25 +02:00
#include "swad_global.h"
2016-09-11 12:46:52 +02:00
#include "swad_ID.h"
2016-09-08 19:21:25 +02:00
#include "swad_profile.h"
2016-10-08 20:25:26 +02:00
#include "swad_tab.h"
2016-09-08 18:04:30 +02:00
/*****************************************************************************/
/****************************** Public constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
2016-10-04 17:21:21 +02:00
#define Rep_FILENAME_ROOT "report"
2016-10-03 13:29:05 +02:00
#define Rep_MIN_CLICKS_CRS 100 // Minimum number of clicks to show a course in historic log
2016-10-08 20:25:26 +02:00
#define Rep_MAX_ACTIONS 50 // Maximum number of actions in list of frequent actions
2016-10-04 01:16:52 +02:00
#define Rep_MAX_BAR_WIDTH 50 // Maximum width of graphic bar
2016-10-03 13:29:05 +02:00
2016-09-12 10:02:17 +02:00
// #define Rep_BLOCK "&boxH;" // HTML code for a block in graphic bar
// #define Rep_BLOCK "&blk12;" // HTML code for a block in graphic bar
// #define Rep_BLOCK "&block;" // HTML code for a block in graphic bar
// #define Rep_BLOCK "&equiv;" // HTML code for a block in graphic bar
// #define Rep_BLOCK "&bull;" // HTML code for a block in graphic bar
2016-10-04 01:16:52 +02:00
// #define Rep_BLOCK "&squf;" // HTML code for a block in graphic bar
#define Rep_BLOCK "-"
2016-09-12 10:02:17 +02:00
2016-09-08 18:04:30 +02:00
/*****************************************************************************/
/****************************** Internal types *******************************/
/*****************************************************************************/
2016-10-04 00:22:59 +02:00
struct CurrentTimeUTC
{
char StrDate[10+1]; // Example: 2016-10-02
// 1234567890
char StrTime[8+1]; // Example: 19:03:49
// 12345678
2016-10-04 17:21:21 +02:00
unsigned Date; // Example: 20161002
unsigned Time; // Example: 190349
2016-10-04 00:22:59 +02:00
};
2016-09-08 18:04:30 +02:00
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
2016-09-08 19:21:25 +02:00
extern struct Globals Gbl;
2016-09-08 18:04:30 +02:00
/*****************************************************************************/
/************************* Internal global variables *************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
2016-10-04 00:22:59 +02:00
static void Rep_CreateMyUsageReport (struct CurrentTimeUTC *CurrentTimeUTC,
2016-10-04 17:21:21 +02:00
char *FilenameReport,
2016-10-04 00:22:59 +02:00
char *Permalink);
static void Rep_PutLinkToMyUsageReport (struct CurrentTimeUTC *CurrentTimeUTC,
2016-10-04 17:21:21 +02:00
const char *FilenameReport,
2016-10-04 00:22:59 +02:00
const char *Permalink);
2016-10-04 00:30:46 +02:00
static void Req_TitleReport (struct CurrentTimeUTC *CurrentTimeUTC);
2016-10-04 00:22:59 +02:00
2016-10-06 21:31:51 +02:00
static void Rep_GetCurrentDateTimeUTC (struct tm *tm_CurrentTime,
struct CurrentTimeUTC *CurrentTimeUTC);
2016-10-04 17:21:21 +02:00
2016-10-06 20:35:10 +02:00
static void Rep_CreateNewReportFile (const struct CurrentTimeUTC *CurrentTimeUTC,
char *FilenameReport,char *Permalink);
2016-10-06 21:31:51 +02:00
static void Rep_CreateNewReportEntryIntoDB (const struct tm *tm_CurrentTime,
const char *FilenameReport,
2016-10-06 20:35:10 +02:00
const char *Permalink);
static void Rep_WriteHeader (const struct CurrentTimeUTC *CurrentTimeUTC,
2016-10-04 00:22:59 +02:00
const char *Permalink);
2016-10-03 09:40:10 +02:00
static void Rep_WriteSectionPlatform (void);
2016-10-03 09:44:32 +02:00
static void Rep_WriteSectionUsrInfo (void);
2016-10-06 20:35:10 +02:00
static void Rep_WriteSectionUsrFigures (const struct UsrFigures *UsrFigures,
const struct tm *tm_FirstClickTime,
const struct CurrentTimeUTC *CurrentTimeUTC);
2016-10-08 20:25:26 +02:00
static void Rep_WriteSectionHitsPerAction (const struct UsrFigures *UsrFigures);
2016-10-06 20:35:10 +02:00
static void Rep_WriteSectionGlobalHits (const struct UsrFigures *UsrFigures,
const struct tm *tm_FirstClickTime);
static void Rep_WriteSectionCurrentCourses (const struct UsrFigures *UsrFigures,
const struct tm *tm_FirstClickTime,
const struct CurrentTimeUTC *CurrentTimeUTC,
2016-10-03 10:18:48 +02:00
unsigned long MaxHitsPerYear);
2016-10-06 20:35:10 +02:00
static void Rep_WriteSectionHistoricCourses (const struct UsrFigures *UsrFigures,
const struct tm *tm_FirstClickTime,
2016-10-03 11:38:13 +02:00
unsigned long MaxHitsPerYear);
2016-10-03 09:40:10 +02:00
2016-10-02 23:26:59 +02:00
static unsigned long Rep_GetMaxHitsPerYear (time_t FirstClickTimeUTC);
2016-10-07 02:23:24 +02:00
static void Rep_GetAndWriteMyCurrentCrss (Rol_Role_t Role,
time_t FirstClickTimeUTC,
const struct tm *tm_FirstClickTime,
unsigned long MaxHitsPerYear);
static void Rep_GetAndWriteMyHistoricClicsWithoutCrs (time_t FirstClickTimeUTC,
const struct tm *tm_FirstClickTime,
unsigned long MaxHitsPerYear);
static void Rep_GetAndWriteMyHistoricCrss (Rol_Role_t Role,
2016-10-02 19:42:47 +02:00
time_t FirstClickTimeUTC,
2016-10-06 20:35:10 +02:00
const struct tm *tm_FirstClickTime,
2016-10-02 19:42:47 +02:00
unsigned long MaxHitsPerYear);
static void Rep_WriteRowCrsData (long CrsCod,Rol_Role_t Role,
2016-09-29 01:34:17 +02:00
time_t FirstClickTimeUTC,
2016-10-06 20:35:10 +02:00
const struct tm *tm_FirstClickTime,
2016-10-07 02:23:24 +02:00
unsigned long MaxHitsPerYear,
bool WriteNumUsrs);
2016-10-02 17:56:05 +02:00
2016-10-02 19:42:47 +02:00
static void Rep_ShowMyHitsPerYear (bool AnyCourse,long CrsCod,Rol_Role_t Role,
2016-10-02 17:56:05 +02:00
time_t FirstClickTimeUTC,
2016-10-06 20:35:10 +02:00
const struct tm *tm_FirstClickTime,
2016-10-02 17:56:05 +02:00
unsigned long MaxHitsPerYear);
2016-09-12 10:02:17 +02:00
static void Rep_DrawBarNumHits (float HitsNum,float HitsMax,
unsigned MaxBarWidth);
2016-09-12 00:50:24 +02:00
2016-10-06 22:18:33 +02:00
static void Rep_RemoveUsrReportsFiles (long UsrCod);
static void Rep_RemoveUsrReportsFromDB (long UsrCod);
2016-09-08 18:04:30 +02:00
/*****************************************************************************/
2016-10-04 00:22:59 +02:00
/******* Request my usage report (report on my use of the platform) **********/
2016-09-08 18:04:30 +02:00
/*****************************************************************************/
2016-10-03 13:04:49 +02:00
void Rep_ReqMyUsageReport (void)
{
2016-10-03 18:16:05 +02:00
extern const char *Txt_Report_of_use_of_PLATFORM;
2016-10-03 13:04:49 +02:00
extern const char *Txt_Generate_report;
/***** Form to show my usage report *****/
Act_FormStart (ActSeeMyUsgRep);
/***** Start frame *****/
2016-10-03 18:16:05 +02:00
sprintf (Gbl.Title,Txt_Report_of_use_of_PLATFORM,Cfg_PLATFORM_SHORT_NAME);
Lay_StartRoundFrame (NULL,Gbl.Title,NULL);
2016-10-03 13:04:49 +02:00
/***** Header *****/
2016-10-06 21:31:51 +02:00
Req_TitleReport (NULL); // NULL means do not write date
2016-10-03 13:04:49 +02:00
/***** Send button and end frame *****/
Lay_EndRoundFrameWithButton (Lay_CONFIRM_BUTTON,Txt_Generate_report);
/***** End of form *****/
Act_FormEnd ();
}
2016-10-04 00:22:59 +02:00
/*****************************************************************************/
/********* Show my usage report (report on my use of the platform) ***********/
/*****************************************************************************/
2016-09-08 18:04:30 +02:00
void Rep_ShowMyUsageReport (void)
2016-10-04 00:22:59 +02:00
{
struct CurrentTimeUTC CurrentTimeUTC;
2016-10-04 17:21:21 +02:00
char FilenameReport[NAME_MAX+1];
2016-10-04 00:22:59 +02:00
char Permalink[PATH_MAX+1];
/***** Create my usage report *****/
2016-10-04 17:21:21 +02:00
Rep_CreateMyUsageReport (&CurrentTimeUTC,FilenameReport,Permalink);
2016-10-04 00:22:59 +02:00
/***** Put link to my usage report *****/
2016-10-04 17:21:21 +02:00
Rep_PutLinkToMyUsageReport (&CurrentTimeUTC,FilenameReport,Permalink);
2016-10-04 00:22:59 +02:00
}
/*****************************************************************************/
/******** Create my usage report (report on my use of the platform) **********/
/*****************************************************************************/
static void Rep_CreateMyUsageReport (struct CurrentTimeUTC *CurrentTimeUTC,
2016-10-04 17:21:21 +02:00
char *FilenameReport,
2016-10-04 00:22:59 +02:00
char *Permalink)
2016-09-09 00:36:44 +02:00
{
2016-10-03 22:41:45 +02:00
extern const char *Txt_Report_of_use_of_PLATFORM;
2016-10-06 21:31:51 +02:00
struct tm tm_CurrentTime;
2016-09-11 14:28:32 +02:00
struct UsrFigures UsrFigures;
2016-09-12 00:50:24 +02:00
struct tm tm_FirstClickTime;
2016-10-03 18:16:05 +02:00
bool GetUsrFiguresAgain;
2016-10-02 17:56:05 +02:00
unsigned long MaxHitsPerYear;
2016-10-02 21:14:07 +02:00
/***** Get current date-time *****/
2016-10-06 21:31:51 +02:00
Rep_GetCurrentDateTimeUTC (&tm_CurrentTime,CurrentTimeUTC);
2016-10-02 21:14:07 +02:00
2016-10-06 20:35:10 +02:00
/***** Create a new report file *****/
Rep_CreateNewReportFile (CurrentTimeUTC,FilenameReport,Permalink);
2016-10-03 14:12:01 +02:00
2016-10-06 20:35:10 +02:00
/***** Store report entry into database *****/
2016-10-06 21:31:51 +02:00
Rep_CreateNewReportEntryIntoDB (&tm_CurrentTime,FilenameReport,Permalink);
2016-10-04 02:32:25 +02:00
2016-10-03 14:12:01 +02:00
/***** Start file *****/
2016-10-04 17:21:21 +02:00
Lay_StartHTMLFile (Gbl.F.Rep,FilenameReport);
2016-10-04 23:57:32 +02:00
fprintf (Gbl.F.Rep,"<body style=\"margin:1em;"
" text-align:left;"
" font-family:Helvetica,Arial,sans-serif;\">\n");
2016-09-11 22:45:53 +02:00
2016-10-03 13:04:49 +02:00
/***** Header *****/
2016-10-04 00:22:59 +02:00
Rep_WriteHeader (CurrentTimeUTC,Permalink);
2016-10-02 22:54:30 +02:00
/***** Platform *****/
2016-10-03 09:40:10 +02:00
Rep_WriteSectionPlatform ();
2016-10-02 21:14:07 +02:00
2016-09-11 22:45:53 +02:00
/***** Personal information *****/
2016-10-03 09:44:32 +02:00
Rep_WriteSectionUsrInfo ();
2016-09-11 22:45:53 +02:00
/***** Figures *****/
2016-09-11 14:28:32 +02:00
Prf_GetUsrFigures (Gbl.Usrs.Me.UsrDat.UsrCod,&UsrFigures);
2016-10-03 18:16:05 +02:00
GetUsrFiguresAgain = Prf_GetAndStoreAllUsrFigures (Gbl.Usrs.Me.UsrDat.UsrCod,&UsrFigures);
if (GetUsrFiguresAgain)
Prf_GetUsrFigures (Gbl.Usrs.Me.UsrDat.UsrCod,&UsrFigures);
2016-09-11 14:28:32 +02:00
if (UsrFigures.FirstClickTimeUTC)
2016-10-03 09:59:57 +02:00
gmtime_r (&UsrFigures.FirstClickTimeUTC,&tm_FirstClickTime);
2016-10-04 00:22:59 +02:00
Rep_WriteSectionUsrFigures (&UsrFigures,&tm_FirstClickTime,CurrentTimeUTC);
2016-09-11 22:45:53 +02:00
2016-10-08 20:25:26 +02:00
/***** Global count of hits *****/
2016-10-03 10:07:49 +02:00
Rep_WriteSectionGlobalHits (&UsrFigures,&tm_FirstClickTime);
2016-10-02 23:38:40 +02:00
2016-10-08 20:25:26 +02:00
/***** Global hits distributed by action *****/
Rep_WriteSectionHitsPerAction (&UsrFigures);
2016-10-02 19:42:47 +02:00
/***** Current courses *****/
2016-10-02 23:26:59 +02:00
MaxHitsPerYear = Rep_GetMaxHitsPerYear (UsrFigures.FirstClickTimeUTC);
2016-10-03 10:18:48 +02:00
Rep_WriteSectionCurrentCourses (&UsrFigures,&tm_FirstClickTime,
2016-10-04 00:22:59 +02:00
CurrentTimeUTC,MaxHitsPerYear);
2016-09-11 22:45:53 +02:00
2016-10-02 19:42:47 +02:00
/***** Historic courses *****/
2016-10-03 11:38:13 +02:00
Rep_WriteSectionHistoricCourses (&UsrFigures,&tm_FirstClickTime,
MaxHitsPerYear);
2016-10-02 17:56:05 +02:00
2016-10-03 14:12:01 +02:00
/***** End file *****/
2016-10-04 01:16:52 +02:00
fprintf (Gbl.F.Rep,"</body>\n"
2016-10-03 22:41:45 +02:00
"</html>\n");
2016-10-03 14:12:01 +02:00
2016-10-03 22:41:45 +02:00
/***** Close report file *****/
2016-10-03 14:12:01 +02:00
Fil_CloseReportFile ();
2016-10-04 00:22:59 +02:00
}
/*****************************************************************************/
/******* Put link to my usage report (report on my use of the platform) ******/
/*****************************************************************************/
static void Rep_PutLinkToMyUsageReport (struct CurrentTimeUTC *CurrentTimeUTC,
2016-10-04 17:21:21 +02:00
const char *FilenameReport,
2016-10-04 00:22:59 +02:00
const char *Permalink)
{
extern const char *Txt_Report_of_use_of_PLATFORM;
extern const char *Txt_Report;
2016-10-06 23:15:14 +02:00
extern const char *Txt_This_link_will_remain_active_as_long_as_your_user_s_account_exists;
2016-10-03 14:12:01 +02:00
2016-10-03 22:41:45 +02:00
/***** Start frame *****/
sprintf (Gbl.Title,Txt_Report_of_use_of_PLATFORM,Cfg_PLATFORM_SHORT_NAME);
Lay_StartRoundFrame (NULL,Gbl.Title,NULL);
2016-09-09 00:36:44 +02:00
2016-10-03 22:41:45 +02:00
/***** Header *****/
2016-10-04 00:30:46 +02:00
Req_TitleReport (CurrentTimeUTC);
2016-09-09 00:36:44 +02:00
2016-10-03 22:41:45 +02:00
/***** Put anchor and report filename *****/
2016-10-04 02:32:25 +02:00
fprintf (Gbl.F.Out,"<div class=\"FILENAME CENTER_MIDDLE\">"
"<a href=\"%s\" class=\"FILENAME\""
" title=\"%s\" target=\"_blank\">"
"<img src=\"%s/report64x64.png\" alt=\"%s\""
" class=\"ICON64x64\" /><br />"
"%s"
2016-10-03 22:41:45 +02:00
"</a>"
"</div>",
Permalink,
2016-10-04 02:32:25 +02:00
Txt_Report,
Gbl.Prefs.IconsURL,
Txt_Report,
2016-10-04 17:21:21 +02:00
FilenameReport);
2016-10-06 23:15:14 +02:00
fprintf (Gbl.F.Out,"<div class=\"DAT_LIGHT\">%s</div>",
Txt_This_link_will_remain_active_as_long_as_your_user_s_account_exists);
2016-09-09 00:36:44 +02:00
2016-10-03 22:41:45 +02:00
/***** End frame *****/
Lay_EndRoundFrame ();
2016-09-09 00:36:44 +02:00
}
2016-09-11 21:25:14 +02:00
2016-10-04 00:30:46 +02:00
/*****************************************************************************/
/********************* Write title of user's usage report ********************/
/*****************************************************************************/
2016-10-06 21:31:51 +02:00
// CurrentTimeUTC == NULL ==> do not write date
2016-10-04 00:30:46 +02:00
static void Req_TitleReport (struct CurrentTimeUTC *CurrentTimeUTC)
{
2016-10-04 23:57:32 +02:00
extern const char *Txt_User[Usr_NUM_SEXS];
extern const char *Txt_Date;
fprintf (Gbl.F.Out,"<div class=\"DAT\" style=\"margin-bottom:10px;\">");
/***** User *****/
fprintf (Gbl.F.Out,"%s: <span class=\"DAT_N_BOLD\">%s</span>",
Txt_User[Gbl.Usrs.Me.UsrDat.Sex],
Gbl.Usrs.Me.UsrDat.FullName);
/***** Report date *****/
2016-10-06 21:31:51 +02:00
if (CurrentTimeUTC)
fprintf (Gbl.F.Out,"<br />"
"%s: <span class=\"DAT_N\">%s %s UTC</span>",
Txt_Date,
CurrentTimeUTC->StrDate,
CurrentTimeUTC->StrTime);
2016-10-04 23:57:32 +02:00
2016-10-04 00:30:46 +02:00
fprintf (Gbl.F.Out,"</div>");
}
2016-10-03 09:40:10 +02:00
/*****************************************************************************/
2016-10-04 17:21:21 +02:00
/********************* Get current date and time in UTC **********************/
/*****************************************************************************/
2016-10-06 21:31:51 +02:00
static void Rep_GetCurrentDateTimeUTC (struct tm *tm_CurrentTime,
struct CurrentTimeUTC *CurrentTimeUTC)
2016-10-04 17:21:21 +02:00
{
time_t CurrentTime;
/***** Initialize to empty strings *****/
CurrentTimeUTC->StrDate[0] = '\0';
CurrentTimeUTC->StrTime[0] = '\0';
/***** Get current time UTC *****/
time (&CurrentTime);
2016-10-06 21:31:51 +02:00
if ((gmtime_r (&CurrentTime,tm_CurrentTime)) != NULL)
2016-10-04 17:21:21 +02:00
{
/* Date and time as strings */
sprintf (CurrentTimeUTC->StrDate,"%04d-%02d-%02d",
2016-10-06 21:31:51 +02:00
1900 + tm_CurrentTime->tm_year, // year
1 + tm_CurrentTime->tm_mon, // month
tm_CurrentTime->tm_mday); // day of the month
2016-10-04 17:21:21 +02:00
sprintf (CurrentTimeUTC->StrTime,"%02d:%02d:%02d",
2016-10-06 21:31:51 +02:00
tm_CurrentTime->tm_hour, // hours
tm_CurrentTime->tm_min, // minutes
tm_CurrentTime->tm_sec); // seconds
2016-10-04 17:21:21 +02:00
/* Date and time as unsigned */
2016-10-06 21:31:51 +02:00
CurrentTimeUTC->Date = (1900 + tm_CurrentTime->tm_year) * 10000 +
(1 + tm_CurrentTime->tm_mon) * 100 +
tm_CurrentTime->tm_mday;
CurrentTimeUTC->Time = tm_CurrentTime->tm_hour * 10000 +
tm_CurrentTime->tm_min * 100 +
tm_CurrentTime->tm_sec;
2016-10-04 17:21:21 +02:00
}
}
2016-10-06 20:35:10 +02:00
/*****************************************************************************/
/*************** Create a new file for user's usage report *******************/
/*****************************************************************************/
static void Rep_CreateNewReportFile (const struct CurrentTimeUTC *CurrentTimeUTC,
char *FilenameReport,char *Permalink)
{
char PathReports[PATH_MAX+1];
char PathUniqueDirL[PATH_MAX+1];
char PathUniqueDirR[PATH_MAX+1];
char PathFileReport[PATH_MAX+1];
/***** Path for reports *****/
sprintf (PathReports,"%s/%s",
Cfg_PATH_SWAD_PUBLIC,Cfg_FOLDER_REP);
Fil_CreateDirIfNotExists (PathReports);
/***** Unique directory for the file with the report *****/
/* 1. Create a directory using the leftmost 2 chars of a unique name */
sprintf (PathUniqueDirL,"%s/%s/%c%c",
Cfg_PATH_SWAD_PUBLIC,Cfg_FOLDER_REP,
Gbl.UniqueNameEncrypted[0],
Gbl.UniqueNameEncrypted[1]);
Fil_CreateDirIfNotExists (PathUniqueDirL);
/* 2. Create a directory using the rightmost 41 chars of a unique name */
sprintf (PathUniqueDirR,"%s/%s",
PathUniqueDirL,
&Gbl.UniqueNameEncrypted[2]);
if (mkdir (PathUniqueDirR,(mode_t) 0xFFF))
Lay_ShowErrorAndExit ("Can not create directory for report.");
/***** Path of the public file with the report */
sprintf (FilenameReport,"%s_%06u_%06u.html",
Rep_FILENAME_ROOT,CurrentTimeUTC->Date,CurrentTimeUTC->Time);
sprintf (PathFileReport,"%s/%s",
PathUniqueDirR,FilenameReport);
if ((Gbl.F.Rep = fopen (PathFileReport,"wb")) == NULL)
Lay_ShowErrorAndExit ("Can not create report file.");
/***** Permalink *****/
sprintf (Permalink,"%s/%s/%c%c/%s/%s",
Cfg_URL_SWAD_PUBLIC,
Cfg_FOLDER_REP,
Gbl.UniqueNameEncrypted[0],
Gbl.UniqueNameEncrypted[1],
&Gbl.UniqueNameEncrypted[2],
FilenameReport);
}
/*****************************************************************************/
/************** Insert a new user's usage report into database ***************/
/*****************************************************************************/
2016-10-06 21:31:51 +02:00
static void Rep_CreateNewReportEntryIntoDB (const struct tm *tm_CurrentTime,
const char *FilenameReport,
2016-10-06 20:35:10 +02:00
const char *Permalink)
{
char Query[1024+PATH_MAX*2];
/***** Insert a new user's usage report into database *****/
sprintf (Query,"INSERT INTO usr_report"
2016-10-06 21:31:51 +02:00
" (UsrCod,ReportTimeUTC,"
"UniqueDirL,UniqueDirR,Filename,Permalink)"
2016-10-06 20:35:10 +02:00
" VALUES"
2016-10-06 21:31:51 +02:00
" ('%ld','%04d-%02d-%02d %02d:%02d:%02d',"
"'%c%c','%s','%s','%s')",
2016-10-06 20:35:10 +02:00
Gbl.Usrs.Me.UsrDat.UsrCod,
2016-10-06 21:31:51 +02:00
1900 + tm_CurrentTime->tm_year, // year
1 + tm_CurrentTime->tm_mon, // month
tm_CurrentTime->tm_mday, // day of the month
tm_CurrentTime->tm_hour, // hours
tm_CurrentTime->tm_min, // minutes
tm_CurrentTime->tm_sec, // seconds
2016-10-06 20:35:10 +02:00
Gbl.UniqueNameEncrypted[0], // 2 leftmost chars from a unique 43 chars base64url codified from a unique SHA-256 string
Gbl.UniqueNameEncrypted[1],
&Gbl.UniqueNameEncrypted[2], // 41 rightmost chars from a unique 43 chars base64url codified from a unique SHA-256 string
FilenameReport,Permalink);
2016-10-06 22:18:33 +02:00
DB_QueryINSERT (Query,"can not create new user's usage report");
2016-10-06 20:35:10 +02:00
}
2016-10-04 17:21:21 +02:00
/*****************************************************************************/
2016-10-03 09:40:10 +02:00
/******************** Write header of user's usage report ********************/
/*****************************************************************************/
2016-10-06 20:35:10 +02:00
static void Rep_WriteHeader (const struct CurrentTimeUTC *CurrentTimeUTC,
2016-10-04 00:22:59 +02:00
const char *Permalink)
2016-10-03 09:40:10 +02:00
{
extern const char *Txt_Report_of_use_of_PLATFORM;
2016-10-04 02:32:25 +02:00
extern const char *Txt_User[Usr_NUM_SEXS];
extern const char *Txt_Date;
extern const char *Txt_Permalink;
2016-10-03 09:40:10 +02:00
/***** Start of header *****/
2016-10-04 01:16:52 +02:00
fprintf (Gbl.F.Rep,"<header>");
2016-10-03 09:40:10 +02:00
/***** Main title *****/
sprintf (Gbl.Title,Txt_Report_of_use_of_PLATFORM,Cfg_PLATFORM_SHORT_NAME);
2016-10-04 02:32:25 +02:00
fprintf (Gbl.F.Rep,"<h1>%s</h1>"
"<ul>",
Gbl.Title);
2016-10-03 09:40:10 +02:00
2016-10-04 02:32:25 +02:00
/***** User *****/
fprintf (Gbl.F.Rep,"<li>%s: <strong>%s</strong></li>",
Txt_User[Gbl.Usrs.Me.UsrDat.Sex],
Gbl.Usrs.Me.UsrDat.FullName);
/***** Date-time *****/
fprintf (Gbl.F.Rep,"<li>%s: %s %s UTC</li>",
Txt_Date,
CurrentTimeUTC->StrDate,
CurrentTimeUTC->StrTime);
2016-10-03 22:41:45 +02:00
/***** Permalink *****/
2016-10-04 23:57:32 +02:00
fprintf (Gbl.F.Rep,"<li>%s: "
"<a href=\"%s\" target=\"_blank\""
" style=\"text-decoration:none;\">"
"%s"
"</a>"
"</li>",
2016-10-04 02:32:25 +02:00
Txt_Permalink,
2016-10-03 22:41:45 +02:00
Permalink,Permalink);
2016-10-03 09:40:10 +02:00
/***** End of header *****/
2016-10-04 23:57:32 +02:00
fprintf (Gbl.F.Rep,"</ul>"
"</header>\n");
2016-10-03 09:40:10 +02:00
}
/*****************************************************************************/
/************* Write section for platform in user's usage report *************/
/*****************************************************************************/
static void Rep_WriteSectionPlatform (void)
{
extern const char *Txt_Teaching_platform;
extern const char *Txt_Name;
extern const char *Txt_TAGLINE;
extern const char *Txt_URL;
/***** Start of section *****/
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"<section>"
2016-10-04 23:57:32 +02:00
"<h3>%s</h3>"
2016-10-03 09:40:10 +02:00
"<ul>",
Txt_Teaching_platform);
/***** Platform name *****/
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"<li>%s: %s, %s</li>",
2016-10-03 09:40:10 +02:00
Txt_Name,
Cfg_PLATFORM_FULL_NAME,Txt_TAGLINE);
/***** Server URL *****/
2016-10-04 23:57:32 +02:00
fprintf (Gbl.F.Rep,"<li>%s: "
"<a href=\"%s\" target=\"_blank\""
" style=\"text-decoration:none;\">"
"%s"
"</a>"
"</li>",
2016-10-03 09:40:10 +02:00
Txt_URL,Cfg_URL_SWAD_SERVER,Cfg_URL_SWAD_SERVER);
/***** End of section *****/
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"</ul>"
2016-10-03 10:18:48 +02:00
"</section>\n");
2016-10-03 09:40:10 +02:00
}
2016-10-02 19:42:47 +02:00
2016-10-03 09:44:32 +02:00
/*****************************************************************************/
/*********** Write section for user's info in user's usage report ************/
/*****************************************************************************/
static void Rep_WriteSectionUsrInfo (void)
{
extern const char *Txt_Personal_information;
extern const char *Txt_Name;
extern const char *Txt_Email;
extern const char *Txt_Country;
extern const char *Txt_Institution;
char CtyName[Cty_MAX_BYTES_COUNTRY_NAME+1];
struct Institution Ins;
/***** Start of section *****/
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"<section>"
2016-10-04 23:57:32 +02:00
"<h3>%s</h3>"
2016-10-03 09:44:32 +02:00
"<ul>",
Txt_Personal_information);
/***** User's name *****/
2016-10-04 02:32:25 +02:00
fprintf (Gbl.F.Rep,"<li>%s: %s</li>",
2016-10-03 09:44:32 +02:00
Txt_Name,
Gbl.Usrs.Me.UsrDat.FullName);
/***** User's e-mail *****/
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"<li>%s: %s</li>",
2016-10-03 09:44:32 +02:00
Txt_Email,
Gbl.Usrs.Me.UsrDat.Email);
/***** User's country *****/
Cty_GetCountryName (Gbl.Usrs.Me.UsrDat.CtyCod,CtyName);
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"<li>%s: %s</li>",
2016-10-03 09:44:32 +02:00
Txt_Country,
CtyName);
/***** User's institution *****/
Ins.InsCod = Gbl.Usrs.Me.UsrDat.InsCod;
Ins_GetDataOfInstitutionByCod (&Ins,Ins_GET_BASIC_DATA);
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"<li>%s: %s</li>",
2016-10-03 09:44:32 +02:00
Txt_Institution,
Ins.FullName);
/***** End of section *****/
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"</ul>"
2016-10-03 10:18:48 +02:00
"</section>\n");
2016-10-03 09:44:32 +02:00
}
2016-10-03 09:59:57 +02:00
/*****************************************************************************/
/********* Write section for user's figures in user's usage report ***********/
/*****************************************************************************/
2016-10-06 20:35:10 +02:00
static void Rep_WriteSectionUsrFigures (const struct UsrFigures *UsrFigures,
const struct tm *tm_FirstClickTime,
const struct CurrentTimeUTC *CurrentTimeUTC)
2016-10-03 09:59:57 +02:00
{
extern const char *Txt_Figures;
extern const char *Txt_TIME_Since;
extern const char *Txt_TIME_until;
extern const char *Txt_day;
extern const char *Txt_days;
extern const char *Txt_Clicks;
extern const char *Txt_Files_uploaded;
extern const char *Txt_file;
extern const char *Txt_files;
extern const char *Txt_public_FILES;
extern const char *Txt_Downloads;
extern const char *Txt_download;
extern const char *Txt_downloads;
extern const char *Txt_Forum_posts;
extern const char *Txt_post;
extern const char *Txt_posts;
extern const char *Txt_Messages_sent;
extern const char *Txt_message;
extern const char *Txt_messages;
unsigned NumFiles;
unsigned NumPublicFiles;
/***** Start of section *****/
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"<section>"
2016-10-04 23:57:32 +02:00
"<h3>%s</h3>"
2016-10-03 09:59:57 +02:00
"<ul>",
Txt_Figures);
/***** Time since first click until now *****/
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"<li>%s ",Txt_TIME_Since);
2016-10-03 09:59:57 +02:00
if (UsrFigures->FirstClickTimeUTC)
{
if (tm_FirstClickTime != NULL)
{
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"%04d-%02d-%02d %02d:%02d:%02d UTC",
2016-10-03 09:59:57 +02:00
1900 + tm_FirstClickTime->tm_year, // year
1 + tm_FirstClickTime->tm_mon, // month
tm_FirstClickTime->tm_mday, // day of the month
tm_FirstClickTime->tm_hour, // hours
tm_FirstClickTime->tm_min, // minutes
tm_FirstClickTime->tm_sec); // seconds
2016-10-04 00:22:59 +02:00
if (CurrentTimeUTC->StrDate[0])
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep," %s %s %s UTC",
2016-10-04 02:32:25 +02:00
Txt_TIME_until,
CurrentTimeUTC->StrDate,
CurrentTimeUTC->StrTime);
2016-10-03 09:59:57 +02:00
if (UsrFigures->NumDays > 0)
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep," (%d %s)",
2016-10-03 09:59:57 +02:00
UsrFigures->NumDays,
(UsrFigures->NumDays == 1) ? Txt_day :
Txt_days);
}
}
else // Time of first click is unknown
{
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"?");
2016-10-04 00:22:59 +02:00
if (CurrentTimeUTC->StrDate[0])
fprintf (Gbl.F.Rep," - %s %s UTC",
CurrentTimeUTC->StrDate,
CurrentTimeUTC->StrTime);
2016-10-03 09:59:57 +02:00
}
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"</li>");
2016-10-03 09:59:57 +02:00
/***** Number of clicks *****/
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"<li>%s: ",Txt_Clicks);
2016-10-03 09:59:57 +02:00
if (UsrFigures->NumClicks >= 0)
{
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"%ld",UsrFigures->NumClicks);
2016-10-03 09:59:57 +02:00
if (UsrFigures->NumDays > 0)
{
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep," (");
Str_WriteFloatNum (Gbl.F.Rep,
(float) UsrFigures->NumClicks /
2016-10-03 09:59:57 +02:00
(float) UsrFigures->NumDays);
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep," / %s)",Txt_day);
2016-10-03 09:59:57 +02:00
}
}
else // Number of clicks is unknown
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"?");
fprintf (Gbl.F.Rep,"</li>");
2016-10-03 09:59:57 +02:00
/***** Number of files currently published *****/
if ((NumFiles = Brw_GetNumFilesUsr (Gbl.Usrs.Me.UsrDat.UsrCod)))
NumPublicFiles = Brw_GetNumPublicFilesUsr (Gbl.Usrs.Me.UsrDat.UsrCod);
else
NumPublicFiles = 0;
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"<li>"
2016-10-03 09:59:57 +02:00
"%s: %u %s (%u %s)"
"</li>",
Txt_Files_uploaded,
NumFiles,
(NumFiles == 1) ? Txt_file :
Txt_files,
NumPublicFiles,Txt_public_FILES);
/***** Number of file views *****/
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"<li>%s: ",Txt_Downloads);
2016-10-03 09:59:57 +02:00
if (UsrFigures->NumFileViews >= 0)
{
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"%ld %s",
2016-10-03 09:59:57 +02:00
UsrFigures->NumFileViews,
(UsrFigures->NumFileViews == 1) ? Txt_download :
Txt_downloads);
if (UsrFigures->NumDays > 0)
{
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep," (");
Str_WriteFloatNum (Gbl.F.Rep,
(float) UsrFigures->NumFileViews /
2016-10-03 09:59:57 +02:00
(float) UsrFigures->NumDays);
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep," / %s)",Txt_day);
2016-10-03 09:59:57 +02:00
}
}
else // Number of file views is unknown
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"?");
fprintf (Gbl.F.Rep,"</li>");
2016-10-03 09:59:57 +02:00
/***** Number of posts in forums *****/
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"<li>%s: ",Txt_Forum_posts);
2016-10-03 09:59:57 +02:00
if (UsrFigures->NumForPst >= 0)
{
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"%ld %s",
2016-10-03 09:59:57 +02:00
UsrFigures->NumForPst,
(UsrFigures->NumForPst == 1) ? Txt_post :
Txt_posts);
if (UsrFigures->NumDays > 0)
{
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep," (");
Str_WriteFloatNum (Gbl.F.Rep,
(float) UsrFigures->NumForPst /
2016-10-03 09:59:57 +02:00
(float) UsrFigures->NumDays);
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep," / %s)",Txt_day);
2016-10-03 09:59:57 +02:00
}
}
else // Number of forum posts is unknown
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"?");
fprintf (Gbl.F.Rep,"</li>");
2016-10-03 09:59:57 +02:00
/***** Number of messages sent *****/
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"<li>%s: ",Txt_Messages_sent);
2016-10-03 09:59:57 +02:00
if (UsrFigures->NumMsgSnt >= 0)
{
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"%ld %s",
2016-10-03 09:59:57 +02:00
UsrFigures->NumMsgSnt,
(UsrFigures->NumMsgSnt == 1) ? Txt_message :
Txt_messages);
if (UsrFigures->NumDays > 0)
{
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep," (");
Str_WriteFloatNum (Gbl.F.Rep,
(float) UsrFigures->NumMsgSnt /
2016-10-03 09:59:57 +02:00
(float) UsrFigures->NumDays);
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep," / %s)",Txt_day);
2016-10-03 09:59:57 +02:00
}
}
else // Number of messages sent is unknown
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"?");
fprintf (Gbl.F.Rep,"</li>");
2016-10-03 09:59:57 +02:00
/***** End of section *****/
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"</ul>"
2016-10-03 10:18:48 +02:00
"</section>\n");
2016-10-03 09:59:57 +02:00
}
2016-10-03 10:07:49 +02:00
/*****************************************************************************/
/******** Write section for user's global hits in user's usage report ********/
/*****************************************************************************/
2016-10-06 20:35:10 +02:00
static void Rep_WriteSectionGlobalHits (const struct UsrFigures *UsrFigures,
const struct tm *tm_FirstClickTime)
2016-10-03 10:07:49 +02:00
{
2016-10-08 20:37:01 +02:00
extern const char *Txt_Hits_per_year;
2016-10-03 10:07:49 +02:00
/***** Start of section *****/
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"<section>"
2016-10-04 23:57:32 +02:00
"<h3>%s</h3>",
2016-10-08 20:37:01 +02:00
Txt_Hits_per_year);
2016-10-03 10:07:49 +02:00
/***** Global (in any course) hits per year *****/
Rep_ShowMyHitsPerYear (true,-1L, // Any course
Rol_UNKNOWN, // Any role
UsrFigures->FirstClickTimeUTC,
tm_FirstClickTime,
0); // MaxHitsPerYear not passed as an argument but computed inside the function
/***** End of section *****/
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"</section>\n");
2016-10-03 10:18:48 +02:00
}
2016-10-08 20:25:26 +02:00
/*****************************************************************************/
/******** Write section for user's global hits in user's usage report ********/
/*****************************************************************************/
static void Rep_WriteSectionHitsPerAction (const struct UsrFigures *UsrFigures)
{
extern struct Act_Actions Act_Actions[Act_NUM_ACTIONS];
extern Act_Action_t Act_FromActCodToAction[1+Act_MAX_ACTION_COD];
extern const char *Txt_TABS_FULL_TXT[Tab_NUM_TABS];
char Query[512];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
unsigned long NumRow;
struct Sta_Hits Hits;
long ActCod;
char ActTxt[Act_MAX_LENGTH_ACTION_TXT+1];
long NumClicks;
/***** Start of section *****/
fprintf (Gbl.F.Rep,"<section>"
"<h3>%s</h3>",
"Accesos (clics) por acci&oacute;n"); // TODO: Need translation!!!!
/***** Make the query *****/
sprintf (Query,"SELECT SQL_NO_CACHE ActCod,COUNT(*) AS N FROM log_full"
" WHERE ClickTime>=FROM_UNIXTIME('%ld') AND UsrCod='%ld'"
" GROUP BY ActCod ORDER BY N DESC LIMIT %u",
(long) UsrFigures->FirstClickTimeUTC,Gbl.Usrs.Me.UsrDat.UsrCod,
Rep_MAX_ACTIONS);
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get clicks");
/***** Compute maximum number of hits per action *****/
Sta_ComputeMaxAndTotalHits (&Hits,NumRows,mysql_res,1,1);
mysql_data_seek (mysql_res,0);
/***** Write rows *****/
for (NumRow = 1, NumClicks = 0;
NumRow <= NumRows;
NumRow++)
{
row = mysql_fetch_row (mysql_res);
/* Get the action (row[0]) */
ActCod = Str_ConvertStrCodToLongCod (row[0]);
/* Get number hits (in row[1]) */
Hits.Num = Str_GetFloatNumFromStr (row[1]);
NumClicks += (long) Hits.Num;
/* Draw bar proportional to number of hits */
Rep_DrawBarNumHits (Hits.Num,Hits.Max,Rep_MAX_BAR_WIDTH);
/* Write action text */
fprintf (Gbl.F.Rep,"&nbsp;");
if (ActCod >= 0)
{
if (Txt_TABS_FULL_TXT[Act_Actions[Act_FromActCodToAction[ActCod]].Tab])
fprintf (Gbl.F.Rep,"%s &gt; ",
Txt_TABS_FULL_TXT[Act_Actions[Act_FromActCodToAction[ActCod]].Tab]);
fprintf (Gbl.F.Rep,"%s",Act_GetActionTextFromDB (ActCod,ActTxt));
}
else
fprintf (Gbl.F.Rep,"?");
fprintf (Gbl.F.Rep,"<br />");
}
/***** Draw bar for the rest of the clicks *****/
if (UsrFigures->NumClicks > NumClicks)
fprintf (Gbl.F.Rep,"%ld&nbsp;(%s)<br />",
UsrFigures->NumClicks - NumClicks,
"otras acciones"); // TODO: Need translation!!!!
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
/***** End of section *****/
fprintf (Gbl.F.Rep,"</section>\n");
}
2016-10-03 10:18:48 +02:00
/*****************************************************************************/
/****** Write section for user's current courses in user's usage report ******/
/*****************************************************************************/
2016-10-06 20:35:10 +02:00
static void Rep_WriteSectionCurrentCourses (const struct UsrFigures *UsrFigures,
const struct tm *tm_FirstClickTime,
const struct CurrentTimeUTC *CurrentTimeUTC,
2016-10-03 10:18:48 +02:00
unsigned long MaxHitsPerYear)
{
extern const char *Txt_Courses;
Rol_Role_t Role;
/***** Start of section *****/
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"<section>"
2016-10-04 23:57:32 +02:00
"<h3>%s",
2016-10-03 10:18:48 +02:00
Txt_Courses);
2016-10-04 00:22:59 +02:00
if (CurrentTimeUTC->StrDate[0])
fprintf (Gbl.F.Rep," (%s)",CurrentTimeUTC->StrDate);
2016-10-04 23:57:32 +02:00
fprintf (Gbl.F.Rep,"</h3>"
2016-10-03 10:18:48 +02:00
"<ul>");
/***** Number of courses in which the user is student/teacher *****/
for (Role = Rol_STUDENT;
Role <= Rol_TEACHER;
Role++)
/* List my courses with this role */
2016-10-07 02:23:24 +02:00
Rep_GetAndWriteMyCurrentCrss (Role,
UsrFigures->FirstClickTimeUTC,tm_FirstClickTime,
MaxHitsPerYear);
2016-10-03 10:18:48 +02:00
/***** End of section *****/
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"</ul>"
2016-10-03 10:18:48 +02:00
"</section>\n");
2016-10-03 10:07:49 +02:00
}
2016-10-03 11:38:13 +02:00
/*****************************************************************************/
/***** Write section for user's historic courses in user's usage report ******/
/*****************************************************************************/
2016-10-06 20:35:10 +02:00
static void Rep_WriteSectionHistoricCourses (const struct UsrFigures *UsrFigures,
const struct tm *tm_FirstClickTime,
2016-10-03 11:38:13 +02:00
unsigned long MaxHitsPerYear)
{
extern const char *Txt_Courses;
extern const char *Txt_historical_log;
2016-10-03 13:29:05 +02:00
extern const char *Txt_Only_courses_with_more_than_X_clicks_are_shown;
2016-10-03 11:38:13 +02:00
Rol_Role_t Role;
/***** Start of section *****/
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"<section>"
2016-10-04 23:57:32 +02:00
"<h3>%s (%s)</h3>",
2016-10-03 11:38:13 +02:00
Txt_Courses,Txt_historical_log);
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,Txt_Only_courses_with_more_than_X_clicks_are_shown,
2016-10-03 13:29:05 +02:00
Rep_MIN_CLICKS_CRS);
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"<ul>");
2016-10-03 11:38:13 +02:00
2016-10-07 02:23:24 +02:00
/********* Historic clicks of a user without course selected ***********/
Rep_GetAndWriteMyHistoricClicsWithoutCrs (UsrFigures->FirstClickTimeUTC,tm_FirstClickTime,
2016-10-08 20:25:26 +02:00
MaxHitsPerYear);
2016-10-07 02:23:24 +02:00
/***** Historic courses in which the user clicked as student/teacher *****/
2016-10-03 11:38:13 +02:00
for (Role = Rol_STUDENT;
Role <= Rol_TEACHER;
Role++)
/* List my courses with this role */
2016-10-07 02:23:24 +02:00
Rep_GetAndWriteMyHistoricCrss (Role,
2016-10-08 20:25:26 +02:00
UsrFigures->FirstClickTimeUTC,tm_FirstClickTime,
MaxHitsPerYear);
2016-10-03 11:38:13 +02:00
/***** End of section *****/
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"</ul>"
2016-10-03 11:38:13 +02:00
"</section>\n");
}
2016-10-02 19:42:47 +02:00
/*****************************************************************************/
/************ Get the maximum number of hits per course-year-role ************/
/*****************************************************************************/
// Return the maximum number of hits per year
2016-10-02 23:26:59 +02:00
static unsigned long Rep_GetMaxHitsPerYear (time_t FirstClickTimeUTC)
2016-10-02 19:42:47 +02:00
{
2016-10-07 09:57:28 +02:00
char Query[1024];
2016-10-02 19:42:47 +02:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long MaxHitsPerYear = 0;
2016-10-07 09:57:28 +02:00
sprintf (Query,"SELECT MAX(N) FROM ("
// Clicks without course selected ---------------------------
"SELECT "
"'-1' AS CrsCod,"
"YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year,"
"'%u' AS Role,"
"COUNT(*) AS N"
" FROM log_full"
" WHERE ClickTime>=FROM_UNIXTIME('%ld')"
" AND UsrCod='%ld'"
" AND CrsCod<='0'"
" GROUP BY Year"
// ----------------------------------------------------------
" UNION "
// Clicks as student or teacher in courses ------------------
"SELECT "
2016-10-02 19:42:47 +02:00
"CrsCod,"
2016-10-02 23:26:59 +02:00
"YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year,"
2016-10-02 19:42:47 +02:00
"Role,"
"COUNT(*) AS N"
" FROM log_full"
" WHERE ClickTime>=FROM_UNIXTIME('%ld')"
2016-10-07 09:57:28 +02:00
" AND UsrCod='%ld'"
" AND Role>='%u'" // Student
" AND Role<='%u'" // Teacher
" AND CrsCod>'0'"
" GROUP BY CrsCod,Year,Role"
// ----------------------------------------------------------
") AS hits_per_crs_year",
(unsigned) Rol_UNKNOWN,
2016-10-02 19:42:47 +02:00
(long) FirstClickTimeUTC,
2016-10-02 23:26:59 +02:00
Gbl.Usrs.Me.UsrDat.UsrCod,
2016-10-07 09:57:28 +02:00
(long) FirstClickTimeUTC,
Gbl.Usrs.Me.UsrDat.UsrCod,
2016-10-02 23:26:59 +02:00
(unsigned) Rol_STUDENT,
(unsigned) Rol_TEACHER);
2016-10-02 19:42:47 +02:00
DB_QuerySELECT (Query,&mysql_res,"can not get last question index");
/***** Get number of users *****/
row = mysql_fetch_row (mysql_res);
if (row[0]) // There are questions
if (sscanf (row[0],"%lu",&MaxHitsPerYear) != 1)
Lay_ShowErrorAndExit ("Error when getting maximum hits.");
2016-10-08 20:25:26 +02:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2016-10-02 19:42:47 +02:00
return MaxHitsPerYear;
}
2016-09-11 21:25:14 +02:00
/*****************************************************************************/
2016-10-07 02:23:24 +02:00
/************************* Write my current courses **************************/
2016-09-11 21:25:14 +02:00
/*****************************************************************************/
2016-10-07 02:23:24 +02:00
static void Rep_GetAndWriteMyCurrentCrss (Rol_Role_t Role,
time_t FirstClickTimeUTC,
const struct tm *tm_FirstClickTime,
unsigned long MaxHitsPerYear)
2016-09-11 21:25:14 +02:00
{
2016-10-02 19:42:47 +02:00
extern const char *Txt_USER_in_COURSE;
extern const char *Txt_ROLES_SINGUL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
extern const char *Txt_course;
extern const char *Txt_courses;
extern const char *Txt_teachers_ABBREVIATION;
extern const char *Txt_students_ABBREVIATION;
2016-10-03 13:29:05 +02:00
char Query[512];
2016-10-02 19:42:47 +02:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumCrss;
unsigned NumCrs;
long CrsCod;
2016-10-07 02:23:24 +02:00
NumCrss = Usr_GetNumCrssOfUsrWithARole (Gbl.Usrs.Me.UsrDat.UsrCod,Role);
2016-10-02 19:42:47 +02:00
sprintf (Gbl.Title,Txt_USER_in_COURSE,Txt_ROLES_SINGUL_Abc[Role][Gbl.Usrs.Me.UsrDat.Sex]);
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"<li>%s %u %s",
2016-10-02 19:42:47 +02:00
Gbl.Title,
NumCrss,
NumCrss == 1 ? Txt_course :
Txt_courses);
if (NumCrss)
{
2016-10-04 23:57:32 +02:00
fprintf (Gbl.F.Rep," (%u %s / %u %s):",
2016-10-02 19:42:47 +02:00
Usr_GetNumUsrsInCrssOfAUsr (Gbl.Usrs.Me.UsrDat.UsrCod,Role,Rol_TEACHER),
Txt_teachers_ABBREVIATION,
Usr_GetNumUsrsInCrssOfAUsr (Gbl.Usrs.Me.UsrDat.UsrCod,Role,Rol_STUDENT),
Txt_students_ABBREVIATION);
/***** Get courses of a user from database *****/
2016-10-07 02:23:24 +02:00
sprintf (Query,"SELECT crs_usr.CrsCod,log_full.CrsCod,COUNT(*) AS N"
" FROM crs_usr LEFT JOIN log_full ON"
" (crs_usr.CrsCod=log_full.CrsCod"
" AND crs_usr.UsrCod=log_full.UsrCod"
" AND crs_usr.Role=log_full.Role)"
" WHERE crs_usr.UsrCod='%ld'"
" AND crs_usr.Role='%u'"
" GROUP BY crs_usr.CrsCod"
" ORDER BY N DESC,log_full.CrsCod DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) Role);
2016-10-02 19:42:47 +02:00
/***** List the courses (one row per course) *****/
if ((NumCrss = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get courses of a user")))
{
/* Heading row */
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"<ol>");
2016-10-02 19:42:47 +02:00
/* Write courses */
for (NumCrs = 1;
NumCrs <= NumCrss;
NumCrs++)
{
/* Get next course */
row = mysql_fetch_row (mysql_res);
/* Get course code (row[0]) */
CrsCod = Str_ConvertStrCodToLongCod (row[0]);
/* Write data of this course */
Rep_WriteRowCrsData (CrsCod,Role,
2016-10-02 23:26:59 +02:00
FirstClickTimeUTC,tm_FirstClickTime,
2016-10-07 02:23:24 +02:00
MaxHitsPerYear,
true); // Write number of users in course
2016-10-02 19:42:47 +02:00
}
/* End table */
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"</ol>");
2016-10-02 19:42:47 +02:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"</li>");
2016-10-02 19:42:47 +02:00
}
/*****************************************************************************/
2016-10-07 02:23:24 +02:00
/************* Write my historic clicks without course selected **************/
2016-10-02 19:42:47 +02:00
/*****************************************************************************/
2016-10-07 02:23:24 +02:00
static void Rep_GetAndWriteMyHistoricClicsWithoutCrs (time_t FirstClickTimeUTC,
const struct tm *tm_FirstClickTime,
unsigned long MaxHitsPerYear)
{
extern const char *Txt_Hits_without_course_selected;
/***** Heading row *****/
fprintf (Gbl.F.Rep,"<li>%s:"
"<ol>",
Txt_Hits_without_course_selected);
/***** Historic clicks *****/
Rep_WriteRowCrsData (-1L,
Rol_UNKNOWN, // Role does not matter
FirstClickTimeUTC,tm_FirstClickTime,
MaxHitsPerYear,
false); // Do not write number of users in course
/***** End of list *****/
fprintf (Gbl.F.Rep,"</ol>"
"</li>");
}
/*****************************************************************************/
/********************** Write historic courses of a user *********************/
/*****************************************************************************/
static void Rep_GetAndWriteMyHistoricCrss (Rol_Role_t Role,
time_t FirstClickTimeUTC,
const struct tm *tm_FirstClickTime,
unsigned long MaxHitsPerYear)
2016-10-02 19:42:47 +02:00
{
2016-10-02 22:54:30 +02:00
extern const char *Txt_Hits_as_a_USER;
2016-10-02 19:42:47 +02:00
extern const char *Txt_ROLES_SINGUL_abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
2016-10-03 13:29:05 +02:00
char Query[256];
2016-09-11 21:25:14 +02:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumCrss;
unsigned NumCrs;
2016-10-02 19:42:47 +02:00
long CrsCod;
2016-09-11 21:25:14 +02:00
2016-10-07 02:23:24 +02:00
/***** Get historic courses of a user from log *****/
2016-10-03 13:29:05 +02:00
sprintf (Query,"SELECT CrsCod,COUNT(*) AS N"
2016-10-02 19:42:47 +02:00
" FROM log_full"
2016-10-07 02:23:24 +02:00
" WHERE UsrCod='%ld' AND Role='%u' AND CrsCod>'0'"
2016-10-03 13:29:05 +02:00
" GROUP BY CrsCod"
" HAVING N>'%u'"
" ORDER BY N DESC",
2016-10-07 02:23:24 +02:00
Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) Role,
2016-10-03 13:29:05 +02:00
Rep_MIN_CLICKS_CRS);
2016-09-11 21:25:14 +02:00
/***** List the courses (one row per course) *****/
if ((NumCrss = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get courses of a user")))
{
/* Heading row */
2016-10-02 22:54:30 +02:00
sprintf (Gbl.Title,Txt_Hits_as_a_USER,
2016-10-02 19:42:47 +02:00
Txt_ROLES_SINGUL_abc[Role][Gbl.Usrs.Me.UsrDat.Sex]);
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"<li>%s:"
2016-10-02 19:42:47 +02:00
"<ol>",
Gbl.Title);
2016-09-11 21:25:14 +02:00
/* Write courses */
for (NumCrs = 1;
NumCrs <= NumCrss;
NumCrs++)
{
/* Get next course */
row = mysql_fetch_row (mysql_res);
2016-10-02 19:42:47 +02:00
/* Get course code (row[0]) */
CrsCod = Str_ConvertStrCodToLongCod (row[0]);
2016-09-11 21:25:14 +02:00
/* Write data of this course */
2016-10-02 19:42:47 +02:00
Rep_WriteRowCrsData (CrsCod,Role,
2016-10-02 23:26:59 +02:00
FirstClickTimeUTC,tm_FirstClickTime,
2016-10-07 02:23:24 +02:00
MaxHitsPerYear,
false); // Do not write number of users in course
}
2016-09-11 21:25:14 +02:00
2016-10-02 19:42:47 +02:00
/* End of list */
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"</ol>"
2016-10-02 19:42:47 +02:00
"</li>");
2016-09-11 21:25:14 +02:00
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/************** Write the data of a course (result of a query) ***************/
/*****************************************************************************/
2016-10-02 19:42:47 +02:00
static void Rep_WriteRowCrsData (long CrsCod,Rol_Role_t Role,
2016-09-29 01:34:17 +02:00
time_t FirstClickTimeUTC,
2016-10-06 20:35:10 +02:00
const struct tm *tm_FirstClickTime,
2016-10-07 02:23:24 +02:00
unsigned long MaxHitsPerYear,
bool WriteNumUsrs)
2016-09-11 21:25:14 +02:00
{
extern const char *Txt_YEAR_OF_DEGREE[1+Deg_MAX_YEARS_PER_DEGREE];
extern const char *Txt_teachers_ABBREVIATION;
extern const char *Txt_students_ABBREVIATION;
2016-10-02 20:03:21 +02:00
extern const char *Txt_unknown_removed_course;
2016-10-02 19:55:12 +02:00
extern const char *Txt_no_course_selected;
2016-10-02 19:42:47 +02:00
struct Course Crs;
2016-09-11 21:25:14 +02:00
struct Degree Deg;
2016-10-02 19:42:47 +02:00
/***** Get course data *****/
Crs.CrsCod = CrsCod;
Crs_GetDataOfCourseByCod (&Crs);
/***** Get degree data *****/
Deg.DegCod = Crs.DegCod;
Deg_GetDataOfDegreeByCod (&Deg);
2016-09-11 21:25:14 +02:00
/***** Start row *****/
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"<li>");
2016-09-11 21:25:14 +02:00
2016-10-02 19:42:47 +02:00
if (CrsCod > 0) // CrsCod > 0 in log ==> course selected
{
if (Crs.CrsCod > 0) // Course exists
{
/***** Write course full name *****/
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"<strong>%s</strong> -",Crs.FullName);
2016-09-11 21:45:29 +02:00
2016-10-02 19:42:47 +02:00
/***** Write year *****/
if (Crs.Year)
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep," %s",Txt_YEAR_OF_DEGREE[Crs.Year]);
2016-09-11 21:45:29 +02:00
2016-10-02 19:42:47 +02:00
/***** Write degree full name *****/
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep," %s",Deg.FullName);
2016-09-11 21:25:14 +02:00
2016-10-02 19:42:47 +02:00
/***** Write number of teachers / students in course *****/
2016-10-07 02:23:24 +02:00
if (WriteNumUsrs)
fprintf (Gbl.F.Rep," (%u %s / %u %s)",
Usr_GetNumUsrsInCrs (Rol_TEACHER,Crs.CrsCod),Txt_teachers_ABBREVIATION,
Usr_GetNumUsrsInCrs (Rol_STUDENT,Crs.CrsCod),Txt_students_ABBREVIATION);
2016-10-02 19:42:47 +02:00
}
else
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"(%s)",Txt_unknown_removed_course);
2016-10-02 19:42:47 +02:00
}
else // CrsCod <= 0 in log ==> no course selected
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"(%s)",Txt_no_course_selected);
2016-09-29 01:34:17 +02:00
/***** Write hits per year for this course *****/
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"<br />");
2016-10-02 19:42:47 +02:00
Rep_ShowMyHitsPerYear (false,CrsCod,Role,
2016-10-02 23:26:59 +02:00
FirstClickTimeUTC,tm_FirstClickTime,
2016-10-02 17:56:05 +02:00
MaxHitsPerYear);
2016-09-29 01:34:17 +02:00
2016-10-03 14:12:01 +02:00
fprintf (Gbl.F.Rep,"</li>");
2016-09-11 21:25:14 +02:00
}
2016-09-12 00:50:24 +02:00
2016-10-02 17:56:05 +02:00
/*****************************************************************************/
/********************** Write my hits grouped by years ***********************/
/*****************************************************************************/
2016-10-02 19:42:47 +02:00
static void Rep_ShowMyHitsPerYear (bool AnyCourse,long CrsCod,Rol_Role_t Role,
2016-10-02 17:56:05 +02:00
time_t FirstClickTimeUTC,
2016-10-06 20:35:10 +02:00
const struct tm *tm_FirstClickTime,
2016-10-02 17:56:05 +02:00
unsigned long MaxHitsPerYear)
{
2016-10-03 13:29:05 +02:00
char Query[512];
2016-10-02 17:56:05 +02:00
char SubQueryCrs[128];
2016-10-02 19:42:47 +02:00
char SubQueryRol[128];
2016-09-12 17:43:23 +02:00
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
unsigned long NumRow;
unsigned ReadYear;
unsigned LastYear;
unsigned Year;
struct Sta_Hits Hits;
/***** Make the query *****/
2016-10-02 19:42:47 +02:00
if (AnyCourse)
SubQueryCrs[0] = '\0';
else
2016-10-02 17:56:05 +02:00
sprintf (SubQueryCrs," AND CrsCod='%ld'",CrsCod);
2016-10-02 19:42:47 +02:00
if (Role == Rol_UNKNOWN) // Here Rol_UNKNOWN means any role
SubQueryRol[0] = '\0';
2016-09-29 01:34:17 +02:00
else
2016-10-02 19:42:47 +02:00
sprintf (SubQueryRol," AND Role='%u'",(unsigned) Role);
2016-10-02 17:56:05 +02:00
2016-09-12 17:43:23 +02:00
sprintf (Query,"SELECT SQL_NO_CACHE "
2016-10-02 23:26:59 +02:00
"YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year,"
2016-09-12 17:43:23 +02:00
"COUNT(*) FROM log_full"
" WHERE ClickTime>=FROM_UNIXTIME('%ld')"
2016-10-02 19:42:47 +02:00
" AND UsrCod='%ld'%s%s"
2016-09-12 17:43:23 +02:00
" GROUP BY Year DESC",
(long) FirstClickTimeUTC,
2016-09-29 01:34:17 +02:00
Gbl.Usrs.Me.UsrDat.UsrCod,
2016-10-02 19:42:47 +02:00
SubQueryCrs,
SubQueryRol);
2016-09-12 17:43:23 +02:00
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get clicks");
/***** Initialize first year *****/
Gbl.DateRange.DateIni.Date.Year = 1900 + tm_FirstClickTime->tm_year;
/***** Initialize LastYear *****/
LastYear = Gbl.Now.Date.Year;
2016-10-02 17:56:05 +02:00
/***** Set maximum number of hits per year *****/
if (MaxHitsPerYear)
/* Set maximum number of hits per year from parameter */
Hits.Max = (float) MaxHitsPerYear;
2016-09-29 01:48:52 +02:00
else
2016-10-02 17:56:05 +02:00
{
/* Compute maximum number of hits per year */
2016-09-29 01:48:52 +02:00
Sta_ComputeMaxAndTotalHits (&Hits,NumRows,mysql_res,1,1);
2016-10-02 17:56:05 +02:00
mysql_data_seek (mysql_res,0);
}
2016-09-12 17:43:23 +02:00
/***** Write rows *****/
for (NumRow = 1;
NumRow <= NumRows;
NumRow++)
{
row = mysql_fetch_row (mysql_res);
/* Get the year (in row[0] is the date in YYYY format) */
if (sscanf (row[0],"%04u",&ReadYear) != 1)
Lay_ShowErrorAndExit ("Wrong date.");
/* Get number hits (in row[1]) */
Hits.Num = Str_GetFloatNumFromStr (row[1]);
for (Year = LastYear;
Year >= ReadYear;
Year--)
{
/* Write the year */
2016-10-03 22:41:45 +02:00
fprintf (Gbl.F.Rep,"%04u&nbsp;",Year);
2016-09-12 17:43:23 +02:00
/* Draw bar proportional to number of hits */
Rep_DrawBarNumHits (Year == LastYear ? Hits.Num :
0.0,
Hits.Max,Rep_MAX_BAR_WIDTH);
2016-10-08 20:25:26 +02:00
fprintf (Gbl.F.Rep,"<br />");
2016-09-12 17:43:23 +02:00
}
LastYear = Year;
}
2016-10-08 20:25:26 +02:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2016-09-12 17:43:23 +02:00
/***** Finally, show the oldest years without clicks *****/
for (Year = LastYear;
Year >= Gbl.DateRange.DateIni.Date.Year;
Year--)
{
/* Write the year */
2016-10-03 22:41:45 +02:00
fprintf (Gbl.F.Rep,"%04u&nbsp;",Year);
2016-09-12 17:43:23 +02:00
/* Draw bar proportional to number of hits */
Rep_DrawBarNumHits (0.0,Hits.Max,Rep_MAX_BAR_WIDTH);
2016-10-08 20:25:26 +02:00
fprintf (Gbl.F.Rep,"<br />");
2016-09-12 17:43:23 +02:00
}
}
2016-09-12 01:06:36 +02:00
/*****************************************************************************/
/********************* Draw a bar with the number of hits ********************/
/*****************************************************************************/
2016-09-12 10:02:17 +02:00
static void Rep_DrawBarNumHits (float HitsNum,float HitsMax,
unsigned MaxBarWidth)
2016-09-12 01:06:36 +02:00
{
unsigned BarWidth;
2016-09-12 10:02:17 +02:00
unsigned i;
2016-09-12 01:06:36 +02:00
if (HitsNum != 0.0)
{
/***** Draw bar with a with proportional to the number of hits *****/
BarWidth = (unsigned) (((HitsNum * (float) MaxBarWidth) / HitsMax) + 0.5);
2016-10-04 01:16:52 +02:00
if (BarWidth)
{
fprintf (Gbl.F.Rep,"<strong>");
for (i = 0;
i < BarWidth;
i++)
fprintf (Gbl.F.Rep,Rep_BLOCK);
fprintf (Gbl.F.Rep,"</strong>");
}
2016-09-12 01:06:36 +02:00
/***** Write the number of hits *****/
2016-10-03 22:41:45 +02:00
fprintf (Gbl.F.Rep,"&nbsp;");
2016-10-03 14:12:01 +02:00
Str_WriteFloatNum (Gbl.F.Rep,HitsNum);
2016-09-12 01:06:36 +02:00
}
}
2016-10-06 22:18:33 +02:00
/*****************************************************************************/
/********** Remove all user's usage report of a user from database ***********/
/*****************************************************************************/
void Rep_RemoveUsrUsageReports (long UsrCod)
{
/***** Remove all user's usage report files of a user *****/
Rep_RemoveUsrReportsFiles (UsrCod);
/***** Remove all user's usage reports of a user from database *****/
Rep_RemoveUsrReportsFromDB (UsrCod);
}
/*****************************************************************************/
/********** Remove all user's usage reports of a user from database **********/
/*****************************************************************************/
static void Rep_RemoveUsrReportsFiles (long UsrCod)
{
char Query[128];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumReports;
unsigned NumReport;
char PathUniqueDirReport[PATH_MAX+1];
/***** Get directories for the reports *****/
sprintf (Query,"SELECT UniqueDirL,UniqueDirR FROM usr_report"
" WHERE UsrCod='%ld'",
UsrCod);
NumReports = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get user's usage reports");
/***** Remove the reports *****/
for (NumReport = 0;
NumReport < NumReports;
NumReport++)
{
/* Get next report */
row = mysql_fetch_row (mysql_res);
/* Remove report directory and file */
sprintf (PathUniqueDirReport,"%s/%s/%s/%s",
Cfg_PATH_SWAD_PUBLIC,Cfg_FOLDER_REP,row[0],row[1]);
Fil_RemoveTree (PathUniqueDirReport);
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/********** Remove all user's usage reports of a user from database **********/
/*****************************************************************************/
static void Rep_RemoveUsrReportsFromDB (long UsrCod)
{
char Query[128];
/***** Insert a new user's usage report into database *****/
sprintf (Query,"DELETE FROM usr_report WHERE UsrCod='%ld'",UsrCod);
DB_QueryDELETE (Query,"can not remove user's usage reports");
}