diff --git a/Makefile b/Makefile index 8d4c1219..a36cf91c 100644 --- a/Makefile +++ b/Makefile @@ -75,8 +75,8 @@ OBJS = swad_account.o swad_account_database.o swad_action.o swad_admin.o \ swad_privacy.o swad_profile.o swad_profile_database.o swad_program.o \ swad_program_database.o swad_project.o swad_project_database.o \ swad_QR.o \ - swad_record.o swad_record_database.o swad_report.o swad_role.o \ - swad_room.o swad_RSS.o \ + swad_record.o swad_record_database.o swad_report.o \ + swad_report_database.o swad_role.o swad_room.o swad_RSS.o \ swad_scope.o swad_search.o swad_session.o swad_setting.o \ swad_statistic.o swad_string.o swad_survey.o swad_syllabus.o \ swad_system_config.o \ diff --git a/swad_changelog.h b/swad_changelog.h index b2a72655..6b754124 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -602,13 +602,14 @@ TODO: FIX BUG, URGENT! En las fechas como par TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo. */ -#define Log_PLATFORM_VERSION "SWAD 21.30.1 (2021-10-13)" +#define Log_PLATFORM_VERSION "SWAD 21.31 (2021-10-13)" #define CSS_FILE "swad20.45.css" #define JS_FILE "swad20.69.1.js" /* TODO: Rename CENTRE to CENTER in help wiki. TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams + Version 21.31: Oct 13, 2021 New module swad_report_database for database queries related to user reports. (319475 lines) Version 21.30.1: Oct 13, 2021 Queries moved to module swad_record_database. (319411 lines) Version 21.30: Oct 12, 2021 New module swad_record_database for database queries related to records. (319400 lines) Version 21.29: Oct 11, 2021 New module swad_project_database for database queries related to projects. (319208 lines) diff --git a/swad_profile.c b/swad_profile.c index d7baee8c..29f39fff 100644 --- a/swad_profile.c +++ b/swad_profile.c @@ -91,20 +91,20 @@ extern struct Globals Gbl; /*****************************************************************************/ static void Prf_ShowTimeSinceFirstClick (const struct UsrData *UsrDat, - const struct UsrFigures *UsrFigures); + const struct Prf_UsrFigures *UsrFigures); static void Prf_ShowNumCrssWithRole (const struct UsrData *UsrDat, Rol_Role_t Role); static void Prf_ShowNumFilesCurrentlyPublished (const struct UsrData *UsrDat); static void Prf_ShowNumClicks (const struct UsrData *UsrDat, - const struct UsrFigures *UsrFigures); + const struct Prf_UsrFigures *UsrFigures); static void Prf_ShowNumFileViews (const struct UsrData *UsrDat, - const struct UsrFigures *UsrFigures); + const struct Prf_UsrFigures *UsrFigures); static void Prf_ShowNumTimelinePubs (const struct UsrData *UsrDat, - const struct UsrFigures *UsrFigures); + const struct Prf_UsrFigures *UsrFigures); static void Prf_ShowNumForumPosts (const struct UsrData *UsrDat, - const struct UsrFigures *UsrFigures); + const struct Prf_UsrFigures *UsrFigures); static void Prf_ShowNumMessagesSent (const struct UsrData *UsrDat, - const struct UsrFigures *UsrFigures); + const struct Prf_UsrFigures *UsrFigures); static void Prf_BeginListItem (const char *Title,const char *Icon); static void Prf_EndListItem (void); static void Prf_PutLinkCalculateFigures (const char *EncryptedUsrCod); @@ -118,7 +118,7 @@ static void Prf_GetNumFileViewsAndStoreAsUsrFigure (long UsrCod); static void Prf_GetNumForumPostsAndStoreAsUsrFigure (long UsrCod); static void Prf_GetNumMessagesSentAndStoreAsUsrFigure (long UsrCod); -static void Prf_ResetUsrFigures (struct UsrFigures *UsrFigures); +static void Prf_ResetUsrFigures (struct Prf_UsrFigures *UsrFigures); static void Prf_GetAndShowRankingFigure (const char *FieldName); static void Prf_ShowUsrInRanking (struct UsrData *UsrDat,unsigned Rank,bool ItsMe); @@ -388,7 +388,7 @@ void Prf_ChangeExtendedProfileVis (void) void Prf_ShowDetailsUserProfile (const struct UsrData *UsrDat) { bool UsrIsBannedFromRanking; - struct UsrFigures UsrFigures; + struct Prf_UsrFigures UsrFigures; Rol_Role_t Role; /***** Get figures *****/ @@ -451,7 +451,7 @@ void Prf_ShowDetailsUserProfile (const struct UsrData *UsrDat) /*****************************************************************************/ static void Prf_ShowTimeSinceFirstClick (const struct UsrData *UsrDat, - const struct UsrFigures *UsrFigures) + const struct Prf_UsrFigures *UsrFigures) { extern const char *Txt_TIME_Since; extern const char *Txt_year; @@ -580,7 +580,7 @@ static void Prf_ShowNumFilesCurrentlyPublished (const struct UsrData *UsrDat) /*****************************************************************************/ static void Prf_ShowNumClicks (const struct UsrData *UsrDat, - const struct UsrFigures *UsrFigures) + const struct Prf_UsrFigures *UsrFigures) { extern const char *Txt_Clicks; extern const char *Txt_clicks; @@ -618,7 +618,7 @@ static void Prf_ShowNumClicks (const struct UsrData *UsrDat, /*****************************************************************************/ static void Prf_ShowNumFileViews (const struct UsrData *UsrDat, - const struct UsrFigures *UsrFigures) + const struct Prf_UsrFigures *UsrFigures) { extern const char *Txt_Downloads; extern const char *Txt_download; @@ -655,7 +655,7 @@ static void Prf_ShowNumFileViews (const struct UsrData *UsrDat, /*****************************************************************************/ static void Prf_ShowNumTimelinePubs (const struct UsrData *UsrDat, - const struct UsrFigures *UsrFigures) + const struct Prf_UsrFigures *UsrFigures) { extern const char *Txt_Timeline; extern const char *Txt_TIMELINE_post; @@ -692,7 +692,7 @@ static void Prf_ShowNumTimelinePubs (const struct UsrData *UsrDat, /*****************************************************************************/ static void Prf_ShowNumForumPosts (const struct UsrData *UsrDat, - const struct UsrFigures *UsrFigures) + const struct Prf_UsrFigures *UsrFigures) { extern const char *Txt_Forums; extern const char *Txt_FORUM_post; @@ -729,7 +729,7 @@ static void Prf_ShowNumForumPosts (const struct UsrData *UsrDat, /*****************************************************************************/ static void Prf_ShowNumMessagesSent (const struct UsrData *UsrDat, - const struct UsrFigures *UsrFigures) + const struct Prf_UsrFigures *UsrFigures) { extern const char *Txt_Messages; extern const char *Txt_message; @@ -801,7 +801,7 @@ static void Prf_PutLinkCalculateFigures (const char *EncryptedUsrCod) /********************** Select values on user's figures **********************/ /*****************************************************************************/ -void Prf_GetUsrFigures (long UsrCod,struct UsrFigures *UsrFigures) +void Prf_GetUsrFigures (long UsrCod,struct Prf_UsrFigures *UsrFigures) { MYSQL_RES *mysql_res; MYSQL_ROW row; @@ -882,7 +882,7 @@ static void Prf_ShowRanking (unsigned Rank,unsigned NumUsrs) void Prf_CalculateFigures (void) { - struct UsrFigures UsrFigures; + struct Prf_UsrFigures UsrFigures; /***** Get user's code *****/ Usr_GetParamOtherUsrCodEncryptedAndGetListIDs (); @@ -900,7 +900,7 @@ void Prf_CalculateFigures (void) /*****************************************************************************/ // Return true if any figure has been calculated and stored -bool Prf_GetAndStoreAllUsrFigures (long UsrCod,struct UsrFigures *UsrFigures) +bool Prf_GetAndStoreAllUsrFigures (long UsrCod,struct Prf_UsrFigures *UsrFigures) { bool UsrFiguresModified = false; @@ -952,7 +952,7 @@ static void Prf_GetFirstClickFromLogAndStoreAsUsrFigure (long UsrCod) { MYSQL_RES *mysql_res; MYSQL_ROW row; - struct UsrFigures UsrFigures; + struct Prf_UsrFigures UsrFigures; if (Usr_ChkIfUsrCodExists (UsrCod)) { @@ -986,7 +986,7 @@ static void Prf_GetFirstClickFromLogAndStoreAsUsrFigure (long UsrCod) static void Prf_GetNumClicksAndStoreAsUsrFigure (long UsrCod) { - struct UsrFigures UsrFigures; + struct Prf_UsrFigures UsrFigures; if (Usr_ChkIfUsrCodExists (UsrCod)) { @@ -1010,7 +1010,7 @@ static void Prf_GetNumClicksAndStoreAsUsrFigure (long UsrCod) static void Prf_GetNumTimelinePubsAndStoreAsUsrFigure (long UsrCod) { - struct UsrFigures UsrFigures; + struct Prf_UsrFigures UsrFigures; if (Usr_ChkIfUsrCodExists (UsrCod)) { @@ -1034,7 +1034,7 @@ static void Prf_GetNumTimelinePubsAndStoreAsUsrFigure (long UsrCod) static void Prf_GetNumFileViewsAndStoreAsUsrFigure (long UsrCod) { - struct UsrFigures UsrFigures; + struct Prf_UsrFigures UsrFigures; if (Usr_ChkIfUsrCodExists (UsrCod)) { @@ -1058,7 +1058,7 @@ static void Prf_GetNumFileViewsAndStoreAsUsrFigure (long UsrCod) static void Prf_GetNumForumPostsAndStoreAsUsrFigure (long UsrCod) { - struct UsrFigures UsrFigures; + struct Prf_UsrFigures UsrFigures; if (Usr_ChkIfUsrCodExists (UsrCod)) { @@ -1082,7 +1082,7 @@ static void Prf_GetNumForumPostsAndStoreAsUsrFigure (long UsrCod) static void Prf_GetNumMessagesSentAndStoreAsUsrFigure (long UsrCod) { - struct UsrFigures UsrFigures; + struct Prf_UsrFigures UsrFigures; if (Usr_ChkIfUsrCodExists (UsrCod)) { @@ -1106,7 +1106,7 @@ static void Prf_GetNumMessagesSentAndStoreAsUsrFigure (long UsrCod) void Prf_CreateNewUsrFigures (long UsrCod,bool CreatingMyOwnAccount) { - struct UsrFigures UsrFigures; + struct Prf_UsrFigures UsrFigures; /***** Reset user's figures *****/ Prf_ResetUsrFigures (&UsrFigures); @@ -1124,7 +1124,7 @@ void Prf_CreateNewUsrFigures (long UsrCod,bool CreatingMyOwnAccount) /********************** Reset values of user's figures ***********************/ /*****************************************************************************/ -static void Prf_ResetUsrFigures (struct UsrFigures *UsrFigures) +static void Prf_ResetUsrFigures (struct Prf_UsrFigures *UsrFigures) { UsrFigures->FirstClickTimeUTC = (time_t) 0; // unknown first click time or user never logged UsrFigures->NumDays = -1; // not applicable diff --git a/swad_profile.h b/swad_profile.h index a1d5daac..3a829d7b 100644 --- a/swad_profile.h +++ b/swad_profile.h @@ -27,6 +27,10 @@ /********************************** Headers **********************************/ /*****************************************************************************/ +#include // For time + +#include "swad_user.h" + /*****************************************************************************/ /****************************** Public constants *****************************/ /*****************************************************************************/ @@ -35,7 +39,7 @@ /******************************** Public types *******************************/ /*****************************************************************************/ -struct UsrFigures +struct Prf_UsrFigures { time_t FirstClickTimeUTC; // 0 ==> unknown first click time of user never logged int NumDays; // -1 ==> not applicable @@ -64,9 +68,9 @@ void Prf_ChangeBasicProfileVis (void); void Prf_ChangeExtendedProfileVis (void); void Prf_ShowDetailsUserProfile (const struct UsrData *UsrDat); -void Prf_GetUsrFigures (long UsrCod,struct UsrFigures *UsrFigures); +void Prf_GetUsrFigures (long UsrCod,struct Prf_UsrFigures *UsrFigures); void Prf_CalculateFigures (void); -bool Prf_GetAndStoreAllUsrFigures (long UsrCod,struct UsrFigures *UsrFigures); +bool Prf_GetAndStoreAllUsrFigures (long UsrCod,struct Prf_UsrFigures *UsrFigures); void Prf_CreateNewUsrFigures (long UsrCod,bool CreatingMyOwnAccount); diff --git a/swad_profile_database.c b/swad_profile_database.c index cb778858..3e1788e1 100644 --- a/swad_profile_database.c +++ b/swad_profile_database.c @@ -60,7 +60,7 @@ extern struct Globals Gbl; /**************************** Create user's figures **************************/ /*****************************************************************************/ -void Prf_DB_CreateUsrFigures (long UsrCod,const struct UsrFigures *UsrFigures, +void Prf_DB_CreateUsrFigures (long UsrCod,const struct Prf_UsrFigures *UsrFigures, bool CreatingMyOwnAccount) { char SubQueryFirstClickTime[64]; diff --git a/swad_profile_database.h b/swad_profile_database.h index 388aa9e8..993f294d 100644 --- a/swad_profile_database.h +++ b/swad_profile_database.h @@ -41,7 +41,7 @@ /****************************** Public prototypes ****************************/ /*****************************************************************************/ -void Prf_DB_CreateUsrFigures (long UsrCod,const struct UsrFigures *UsrFigures, +void Prf_DB_CreateUsrFigures (long UsrCod,const struct Prf_UsrFigures *UsrFigures, bool CreatingMyOwnAccount); void Prf_DB_UpdateFirstClickTimeUsr (long UsrCod,time_t FirstClickTimeUTC); void Prf_DB_UpdateNumClicksUsr (long UsrCod,int NumClicks); diff --git a/swad_record_database.c b/swad_record_database.c index d49b7949..39629a73 100644 --- a/swad_record_database.c +++ b/swad_record_database.c @@ -25,49 +25,13 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -// #define _GNU_SOURCE // For asprintf -// #include // For PATH_MAX -// #include // For NULL -// #include // For asprintf -// #include // For calloc -// #include - -// #include "swad_account.h" -// #include "swad_account_database.h" -// #include "swad_action.h" -// #include "swad_box.h" -// #include "swad_config.h" #include "swad_database.h" -// #include "swad_department.h" -// #include "swad_enrolment_database.h" -// #include "swad_error.h" -// #include "swad_follow_database.h" -// #include "swad_form.h" -// #include "swad_global.h" -// #include "swad_hierarchy_level.h" -// #include "swad_HTML.h" -// #include "swad_ID.h" -// #include "swad_logo.h" -// #include "swad_message.h" -// #include "swad_message_database.h" -// #include "swad_network.h" -// #include "swad_parameter.h" -// #include "swad_photo.h" -// #include "swad_privacy.h" -// #include "swad_QR.h" -// #include "swad_record.h" #include "swad_record_database.h" -// #include "swad_role.h" -// #include "swad_setting.h" -// #include "swad_timetable.h" -// #include "swad_user.h" /*****************************************************************************/ /************** External global variables from others modules ****************/ /*****************************************************************************/ -// extern struct Globals Gbl; - /*****************************************************************************/ /***************************** Private constants *****************************/ /*****************************************************************************/ diff --git a/swad_record_database.h b/swad_record_database.h index 839fc4f7..6695c91e 100644 --- a/swad_record_database.h +++ b/swad_record_database.h @@ -27,10 +27,7 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -// #include // To access MySQL databases - #include "swad_record.h" -// #include "swad_user.h" /*****************************************************************************/ /***************************** Public constants ******************************/ diff --git a/swad_report.c b/swad_report.c index 52251765..fdfd717a 100644 --- a/swad_report.c +++ b/swad_report.c @@ -39,6 +39,7 @@ #include "swad_HTML.h" #include "swad_ID.h" #include "swad_profile.h" +#include "swad_report_database.h" #include "swad_tab.h" /*****************************************************************************/ @@ -67,32 +68,6 @@ /****************************** Private types ********************************/ /*****************************************************************************/ -struct Rep_CurrentTimeUTC - { - char StrDate[3 * (Cns_MAX_DECIMAL_DIGITS_INT + 1)]; // Example: 2016-10-02 - char StrTime[3 * (Cns_MAX_DECIMAL_DIGITS_INT + 1)]; // Example: 19:03:49 - unsigned Date; // Example: 20161002 - unsigned Time; // Example: 190349 - }; - -struct Rep_Hits - { - unsigned long Num; - unsigned long Max; - }; - -struct Rep_Report - { - struct UsrFigures UsrFigures; - struct tm tm_FirstClickTime; - struct tm tm_CurrentTime; - struct Rep_CurrentTimeUTC CurrentTimeUTC; - struct Rep_Hits Hits; - unsigned long MaxHitsPerYear; - char FilenameReport[NAME_MAX + 1]; - char Permalink[Cns_MAX_BYTES_WWW + 1]; - }; - /*****************************************************************************/ /************** External global variables from others modules ****************/ /*****************************************************************************/ @@ -114,7 +89,6 @@ static void Rep_TitleReport (struct Rep_CurrentTimeUTC *CurrentTimeUTC); static void Rep_GetCurrentDateTimeUTC (struct Rep_Report *Report); static void Rep_CreateNewReportFile (struct Rep_Report *Report); -static void Rep_DB_CreateNewReport (const struct Rep_Report *Report); static void Rep_WriteHeader (const struct Rep_Report *Report); static void Rep_WriteSectionPlatform (void); static void Rep_WriteSectionUsrInfo (void); @@ -145,7 +119,6 @@ static void Rep_DrawBarNumHits (unsigned long HitsNum,unsigned long HitsMax, static void Rep_WriteDouble (double Num); static void Rep_RemoveUsrReportsFiles (long UsrCod); -static void Rep_DB_RemoveUsrReports (long UsrCod); /*****************************************************************************/ /******* Request my usage report (report on my use of the platform) **********/ @@ -207,7 +180,8 @@ static void Rep_CreateMyUsageReport (struct Rep_Report *Report) Rep_CreateNewReportFile (Report); /***** Store report entry into database *****/ - Rep_DB_CreateNewReport (Report); + Rep_DB_CreateNewReport (Gbl.Usrs.Me.UsrDat.UsrCod,Report, + Gbl.UniqueNameEncrypted); /***** Begin file *****/ Lay_BeginHTMLFile (Gbl.F.Rep,Report->FilenameReport); @@ -416,34 +390,6 @@ static void Rep_CreateNewReportFile (struct Rep_Report *Report) Str_Copy (Report->Permalink,Permalink,sizeof (Report->Permalink) - 1); } -/*****************************************************************************/ -/************** Insert a new user's usage report into database ***************/ -/*****************************************************************************/ - -static void Rep_DB_CreateNewReport (const struct Rep_Report *Report) - { - /***** Insert a new user's usage report into database *****/ - DB_QueryINSERT ("can not create new user's usage report", - "INSERT INTO usr_reports" - " (UsrCod,ReportTimeUTC," - "UniqueDirL,UniqueDirR,Filename,Permalink)" - " VALUES" - " (%ld,'%04d-%02d-%02d %02d:%02d:%02d'," - "'%c%c','%s','%s','%s')", - Gbl.Usrs.Me.UsrDat.UsrCod, - 1900 + Report->tm_CurrentTime.tm_year, // year - 1 + Report->tm_CurrentTime.tm_mon, // month - Report->tm_CurrentTime.tm_mday, // day of the month - Report->tm_CurrentTime.tm_hour, // hours - Report->tm_CurrentTime.tm_min, // minutes - Report->tm_CurrentTime.tm_sec, // seconds - 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 - Report->FilenameReport, - Report->Permalink); - } - /*****************************************************************************/ /******************** Write header of user's usage report ********************/ /*****************************************************************************/ @@ -1457,15 +1403,3 @@ static void Rep_RemoveUsrReportsFiles (long UsrCod) /***** 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_DB_RemoveUsrReports (long UsrCod) - { - DB_QueryDELETE ("can not remove user's usage reports", - "DELETE FROM usr_reports" - " WHERE UsrCod=%ld", - UsrCod); - } diff --git a/swad_report.h b/swad_report.h index aaea3c07..f4a87fe0 100644 --- a/swad_report.h +++ b/swad_report.h @@ -27,6 +27,9 @@ /********************************** Headers **********************************/ /*****************************************************************************/ +#include "swad_constant.h" +#include "swad_profile.h" + /*****************************************************************************/ /****************************** Public constants *****************************/ /*****************************************************************************/ @@ -35,6 +38,32 @@ /******************************** Public types *******************************/ /*****************************************************************************/ +struct Rep_CurrentTimeUTC + { + char StrDate[3 * (Cns_MAX_DECIMAL_DIGITS_INT + 1)]; // Example: 2016-10-02 + char StrTime[3 * (Cns_MAX_DECIMAL_DIGITS_INT + 1)]; // Example: 19:03:49 + unsigned Date; // Example: 20161002 + unsigned Time; // Example: 190349 + }; + +struct Rep_Hits + { + unsigned long Num; + unsigned long Max; + }; + +struct Rep_Report + { + struct Prf_UsrFigures UsrFigures; + struct tm tm_FirstClickTime; + struct tm tm_CurrentTime; + struct Rep_CurrentTimeUTC CurrentTimeUTC; + struct Rep_Hits Hits; + unsigned long MaxHitsPerYear; + char FilenameReport[NAME_MAX + 1]; + char Permalink[Cns_MAX_BYTES_WWW + 1]; + }; + /*****************************************************************************/ /****************************** Public prototypes ****************************/ /*****************************************************************************/ diff --git a/swad_report_database.c b/swad_report_database.c new file mode 100644 index 00000000..cfeb288d --- /dev/null +++ b/swad_report_database.c @@ -0,0 +1,111 @@ +// swad_report_database.c: report on my use of the platform, operations with database + +/* + SWAD (Shared Workspace At a Distance), + is a web platform developed at the University of Granada (Spain), + and used to support university teaching. + + This file is part of SWAD core. + Copyright (C) 1999-2021 Antonio Caņ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 . +*/ +/*****************************************************************************/ +/*********************************** Headers *********************************/ +/*****************************************************************************/ + +// #include // For free +// #include // For mkdir +// #include // For mkdir + +// #include "swad_box.h" +// #include "swad_browser_database.h" +#include "swad_database.h" +// #include "swad_error.h" +// #include "swad_form.h" +// #include "swad_global.h" +// #include "swad_hierarchy_level.h" +// #include "swad_HTML.h" +// #include "swad_ID.h" +// #include "swad_profile.h" +#include "swad_report.h" +#include "swad_report_database.h" +// #include "swad_tab.h" + +/*****************************************************************************/ +/****************************** Public constants *****************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/***************************** Private constants *****************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/****************************** Private types ********************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/************** External global variables from others modules ****************/ +/*****************************************************************************/ + +// extern struct Globals Gbl; + +/*****************************************************************************/ +/************************* Private global variables **************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/***************************** Private prototypes ****************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/************** Insert a new user's usage report into database ***************/ +/*****************************************************************************/ + +void Rep_DB_CreateNewReport (long UsrCod,const struct Rep_Report *Report, + const char UniqueNameEncrypted[Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64 + 1]) + { + /***** Insert a new user's usage report into database *****/ + DB_QueryINSERT ("can not create new user's usage report", + "INSERT INTO usr_reports" + " (UsrCod,ReportTimeUTC," + "UniqueDirL,UniqueDirR,Filename,Permalink)" + " VALUES" + " (%ld,'%04d-%02d-%02d %02d:%02d:%02d'," + "'%c%c','%s','%s','%s')", + UsrCod, + 1900 + Report->tm_CurrentTime.tm_year, // year + 1 + Report->tm_CurrentTime.tm_mon, // month + Report->tm_CurrentTime.tm_mday, // day of the month + Report->tm_CurrentTime.tm_hour, // hours + Report->tm_CurrentTime.tm_min, // minutes + Report->tm_CurrentTime.tm_sec, // seconds + UniqueNameEncrypted[0], // 2 leftmost chars from a unique 43 chars base64url codified from a unique SHA-256 string + UniqueNameEncrypted[1], + &UniqueNameEncrypted[2], // 41 rightmost chars from a unique 43 chars base64url codified from a unique SHA-256 string + Report->FilenameReport, + Report->Permalink); + } + +/*****************************************************************************/ +/********** Remove all user's usage reports of a user from database **********/ +/*****************************************************************************/ + +void Rep_DB_RemoveUsrReports (long UsrCod) + { + DB_QueryDELETE ("can not remove user's usage reports", + "DELETE FROM usr_reports" + " WHERE UsrCod=%ld", + UsrCod); + } diff --git a/swad_report_database.h b/swad_report_database.h new file mode 100644 index 00000000..73846473 --- /dev/null +++ b/swad_report_database.h @@ -0,0 +1,50 @@ +// swad_report_database.h: report on my use of the platform, operations with database + +#ifndef _SWAD_REP_DB +#define _SWAD_REP_DB +/* + SWAD (Shared Workspace At a Distance in Spanish), + 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-2021 Antonio Caņas Vargas + + 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 . +*/ +/*****************************************************************************/ +/********************************** Headers **********************************/ +/*****************************************************************************/ + +#include "swad_cryptography.h" +#include "swad_report.h" + +/*****************************************************************************/ +/****************************** Public constants *****************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/******************************** Public types *******************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/****************************** Public prototypes ****************************/ +/*****************************************************************************/ + +void Rep_DB_CreateNewReport (long UsrCod,const struct Rep_Report *Report, + const char UniqueNameEncrypted[Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64 + 1]); + +void Rep_DB_RemoveUsrReports (long UsrCod); + +#endif