Version 16.13

This commit is contained in:
Antonio Cañas Vargas 2016-10-04 17:21:21 +02:00
parent 37da766464
commit d38cf52c33
4 changed files with 63 additions and 58 deletions

View File

@ -143,13 +143,14 @@
/****************************** Public constants *****************************/
/*****************************************************************************/
#define Log_PLATFORM_VERSION "SWAD 16.12 (2016-10-04)"
#define Log_PLATFORM_VERSION "SWAD 16.13 (2016-10-04)"
#define CSS_FILE "swad15.229.css"
#define JS_FILE "swad15.238.1.js"
// Number of lines (includes comments but not blank lines) has been got with the following command:
// nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*.h sql/swad*.sql | tail -1
/*
Version 16.13: Oct 04, 2016 New filename for user's usage report. (205883 lines)
Version 16.12: Oct 04, 2016 Code refactoring in user's usage report. (205882 lines)
Copy icon/report64x64.png to icon directory

View File

@ -103,48 +103,6 @@ void Dat_GetAndConvertCurrentDateTime (void)
Dat_GetDateBefore (&Gbl.Now.Date,&Gbl.Yesterday);
}
/*****************************************************************************/
/********************* Get current date and time in UTC **********************/
/*****************************************************************************/
/*
char StrCurrentDateUTC[10+1]; // Example: 2016-10-02
// 1234567890
char StrCurrentTimeUTC[8+1]; // Example: 19:03:49
// 12345678
*/
void Dat_GetCurrentDateTimeUTC (char StrCurrentDateUTC[10+1],
char StrCurrentTimeUTC[8+1])
{
time_t CurrentTime;
struct tm tm_CurrentTime;
if (StrCurrentDateUTC &&
StrCurrentDateUTC) // If both pointers are not NULL
{
/***** Initialize to empty strings *****/
if (StrCurrentDateUTC)
StrCurrentDateUTC[0] = '\0';
if (StrCurrentTimeUTC)
StrCurrentTimeUTC[0] = '\0';
/***** Get current time UTC *****/
time (&CurrentTime);
if ((gmtime_r (&CurrentTime,&tm_CurrentTime)) != NULL)
{
if (StrCurrentDateUTC) // If not NULL
sprintf (StrCurrentDateUTC,"%04d-%02d-%02d",
1900 + tm_CurrentTime.tm_year, // year
1 + tm_CurrentTime.tm_mon, // month
tm_CurrentTime.tm_mday); // day of the month
if (StrCurrentTimeUTC) // If not NULL
sprintf (StrCurrentTimeUTC,"%02d:%02d:%02d",
tm_CurrentTime.tm_hour, // hours
tm_CurrentTime.tm_min, // minutes
tm_CurrentTime.tm_sec); // seconds
}
}
}
/*****************************************************************************/
/************ Get UNIX time (seconds since 1970 UTC) from string *************/
/*****************************************************************************/

View File

@ -76,9 +76,6 @@ struct DateTime
void Dat_GetStartExecutionTimeUTC (void);
void Dat_GetAndConvertCurrentDateTime (void);
void Dat_GetCurrentDateTimeUTC (char StrCurrentDateUTC[10+1],
char StrCurrentTimeUTC[8+1]);
time_t Dat_GetUNIXTimeFromStr (const char *Str);
bool Dat_GetDateFromYYYYMMDD (struct Date *Date,const char *YYYYMMDDString);

View File

@ -42,6 +42,8 @@
/***************************** Private constants *****************************/
/*****************************************************************************/
#define Rep_FILENAME_ROOT "report"
#define Rep_MIN_CLICKS_CRS 100 // Minimum number of clicks to show a course in historic log
#define Rep_MAX_BAR_WIDTH 50 // Maximum width of graphic bar
@ -63,6 +65,8 @@ struct CurrentTimeUTC
// 1234567890
char StrTime[8+1]; // Example: 19:03:49
// 12345678
unsigned Date; // Example: 20161002
unsigned Time; // Example: 190349
};
/*****************************************************************************/
@ -80,11 +84,15 @@ extern struct Globals Gbl;
/*****************************************************************************/
static void Rep_CreateMyUsageReport (struct CurrentTimeUTC *CurrentTimeUTC,
char *FilenameReport,
char *Permalink);
static void Rep_PutLinkToMyUsageReport (struct CurrentTimeUTC *CurrentTimeUTC,
const char *FilenameReport,
const char *Permalink);
static void Req_TitleReport (struct CurrentTimeUTC *CurrentTimeUTC);
static void Rep_GetCurrentDateTimeUTC (struct CurrentTimeUTC *CurrentTimeUTC);
static void Rep_WriteHeader (struct CurrentTimeUTC *CurrentTimeUTC,
const char *Permalink);
static void Rep_WriteSectionPlatform (void);
@ -134,8 +142,7 @@ void Rep_ReqMyUsageReport (void)
struct CurrentTimeUTC CurrentTimeUTC;
/***** Get current date-time *****/
Dat_GetCurrentDateTimeUTC (CurrentTimeUTC.StrDate,
CurrentTimeUTC.StrTime);
Rep_GetCurrentDateTimeUTC (&CurrentTimeUTC);
/***** Form to show my usage report *****/
Act_FormStart (ActSeeMyUsgRep);
@ -161,13 +168,14 @@ void Rep_ReqMyUsageReport (void)
void Rep_ShowMyUsageReport (void)
{
struct CurrentTimeUTC CurrentTimeUTC;
char FilenameReport[NAME_MAX+1];
char Permalink[PATH_MAX+1];
/***** Create my usage report *****/
Rep_CreateMyUsageReport (&CurrentTimeUTC,Permalink);
Rep_CreateMyUsageReport (&CurrentTimeUTC,FilenameReport,Permalink);
/***** Put link to my usage report *****/
Rep_PutLinkToMyUsageReport (&CurrentTimeUTC,Permalink);
Rep_PutLinkToMyUsageReport (&CurrentTimeUTC,FilenameReport,Permalink);
}
/*****************************************************************************/
@ -175,10 +183,10 @@ void Rep_ShowMyUsageReport (void)
/*****************************************************************************/
static void Rep_CreateMyUsageReport (struct CurrentTimeUTC *CurrentTimeUTC,
char *FilenameReport,
char *Permalink)
{
extern const char *Txt_Report_of_use_of_PLATFORM;
extern const char *Txt_Report;
struct UsrFigures UsrFigures;
char PathReports[PATH_MAX+1];
char PathDirReport[PATH_MAX+1];
@ -188,8 +196,7 @@ static void Rep_CreateMyUsageReport (struct CurrentTimeUTC *CurrentTimeUTC,
unsigned long MaxHitsPerYear;
/***** Get current date-time *****/
Dat_GetCurrentDateTimeUTC (CurrentTimeUTC->StrDate,
CurrentTimeUTC->StrTime);
Rep_GetCurrentDateTimeUTC (CurrentTimeUTC);
/***** Path for reports *****/
sprintf (PathReports,"%s/%s",
@ -210,20 +217,24 @@ static void Rep_CreateMyUsageReport (struct CurrentTimeUTC *CurrentTimeUTC,
Lay_ShowErrorAndExit ("Can not create directory for report.");
/* Path of the public file with the report */
sprintf (PathFileReport,"%s/index.html",PathDirReport);
sprintf (FilenameReport,"%s_%06u_%06u.html",
Rep_FILENAME_ROOT,CurrentTimeUTC->Date,CurrentTimeUTC->Time);
sprintf (PathFileReport,"%s/%s",
PathDirReport,FilenameReport);
if ((Gbl.F.Rep = fopen (PathFileReport,"wb")) == NULL)
Lay_ShowErrorAndExit ("Can not create report file.");
/* Permalink */
sprintf (Permalink,"%s/%s/%c%c/%s/",
sprintf (Permalink,"%s/%s/%c%c/%s/%s",
Cfg_URL_SWAD_PUBLIC,
Cfg_FOLDER_REP,
Gbl.UniqueNameEncrypted[0],
Gbl.UniqueNameEncrypted[1],
&Gbl.UniqueNameEncrypted[2]);
&Gbl.UniqueNameEncrypted[2],
FilenameReport);
/***** Start file *****/
Lay_StartHTMLFile (Gbl.F.Rep,Txt_Report);
Lay_StartHTMLFile (Gbl.F.Rep,FilenameReport);
fprintf (Gbl.F.Rep,"<body style=\"margin:1em;text-align:left;"
"font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;\">\n");
@ -270,6 +281,7 @@ static void Rep_CreateMyUsageReport (struct CurrentTimeUTC *CurrentTimeUTC,
/*****************************************************************************/
static void Rep_PutLinkToMyUsageReport (struct CurrentTimeUTC *CurrentTimeUTC,
const char *FilenameReport,
const char *Permalink)
{
extern const char *Txt_Report_of_use_of_PLATFORM;
@ -295,7 +307,7 @@ static void Rep_PutLinkToMyUsageReport (struct CurrentTimeUTC *CurrentTimeUTC,
Txt_Report,
Gbl.Prefs.IconsURL,
Txt_Report,
Permalink);
FilenameReport);
/***** End frame *****/
Lay_EndRoundFrame ();
@ -314,6 +326,43 @@ static void Req_TitleReport (struct CurrentTimeUTC *CurrentTimeUTC)
fprintf (Gbl.F.Out,"</div>");
}
/*****************************************************************************/
/********************* Get current date and time in UTC **********************/
/*****************************************************************************/
static void Rep_GetCurrentDateTimeUTC (struct CurrentTimeUTC *CurrentTimeUTC)
{
time_t CurrentTime;
struct tm tm_CurrentTime;
/***** Initialize to empty strings *****/
CurrentTimeUTC->StrDate[0] = '\0';
CurrentTimeUTC->StrTime[0] = '\0';
/***** Get current time UTC *****/
time (&CurrentTime);
if ((gmtime_r (&CurrentTime,&tm_CurrentTime)) != NULL)
{
/* Date and time as strings */
sprintf (CurrentTimeUTC->StrDate,"%04d-%02d-%02d",
1900 + tm_CurrentTime.tm_year, // year
1 + tm_CurrentTime.tm_mon, // month
tm_CurrentTime.tm_mday); // day of the month
sprintf (CurrentTimeUTC->StrTime,"%02d:%02d:%02d",
tm_CurrentTime.tm_hour, // hours
tm_CurrentTime.tm_min, // minutes
tm_CurrentTime.tm_sec); // seconds
/* Date and time as unsigned */
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;
}
}
/*****************************************************************************/
/******************** Write header of user's usage report ********************/
/*****************************************************************************/