From d38cf52c33d8ac413a6856810f5a86f958cfa74e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Tue, 4 Oct 2016 17:21:21 +0200 Subject: [PATCH] Version 16.13 --- swad_changelog.h | 3 +- swad_date.c | 42 ---------------------------- swad_date.h | 3 -- swad_report.c | 73 ++++++++++++++++++++++++++++++++++++++++-------- 4 files changed, 63 insertions(+), 58 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index a1f2ef849..2be2d1d3c 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -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 diff --git a/swad_date.c b/swad_date.c index bb304c9e6..e7c00fedb 100644 --- a/swad_date.c +++ b/swad_date.c @@ -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 *************/ /*****************************************************************************/ diff --git a/swad_date.h b/swad_date.h index 67cd207a3..54b3ead76 100644 --- a/swad_date.h +++ b/swad_date.h @@ -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); diff --git a/swad_report.c b/swad_report.c index 0c00607b9..45ea2b1b7 100644 --- a/swad_report.c +++ b/swad_report.c @@ -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,"\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,""); } +/*****************************************************************************/ +/********************* 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 ********************/ /*****************************************************************************/