From 5dc75275fcf2d5ef70dba265f846377442beabb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Mon, 26 Oct 2015 13:06:26 +0100 Subject: [PATCH] Version 15.21.1 --- js/swad.js | 53 +++++---- swad_action.c | 2 +- swad_changelog.h | 3 +- swad_date.c | 286 +++-------------------------------------------- swad_date.h | 1 - swad_global.c | 7 -- swad_statistic.c | 27 +---- swad_test.c | 14 ++- swad_test.h | 2 + 9 files changed, 70 insertions(+), 325 deletions(-) diff --git a/js/swad.js b/js/swad.js index c04d4ef06..4862d8740 100644 --- a/js/swad.js +++ b/js/swad.js @@ -110,17 +110,24 @@ function setLocalDateTimeFormFromUTC(id,secsSince1970UTC) { // Set UTC time from local date-time form fields function setUTCFromLocalDateTimeForm(id) { var d = new Date; + var Year = document.getElementById(id+'Year' ).value; + var Month = document.getElementById(id+'Month' ).value; + var Day = document.getElementById(id+'Day' ).value; - // Important: set year first in order to work properly with leap years - d.setFullYear(document.getElementById(id+'Year' ).value); - d.setMonth (document.getElementById(id+'Month' ).value-1); - d.setDate (document.getElementById(id+'Day' ).value); - d.setHours (document.getElementById(id+'Hour' ).value); - d.setMinutes (document.getElementById(id+'Minute').value); - d.setSeconds (document.getElementById(id+'Second').value); - d.setMilliseconds(0); - - document.getElementById(id+'TimeUTC').value = d.getTime() / 1000; + if (Year == 0 || Month == 0 || Day == 0) + document.getElementById(id+'TimeUTC').value = 0; + else { + // Important: set year first in order to work properly with leap years + d.setFullYear(Year); + d.setMonth (Month-1); + d.setDate (Day); + d.setHours (document.getElementById(id+'Hour' ).value); + d.setMinutes (document.getElementById(id+'Minute').value); + d.setSeconds (document.getElementById(id+'Second').value); + d.setMilliseconds(0); + + document.getElementById(id+'TimeUTC').value = d.getTime() / 1000; + } } // Adjust a date form correcting days in the month @@ -151,16 +158,24 @@ function adjustDateForm (id) { } // Set a the date in a date form to a specified date -function setDateTo (elem,Day,Month,Year) { - document.getElementById('StartYear' ).options[Year ].selected = true; - document.getElementById('StartMonth').options[Month].selected = true; - adjustDateForm (elem.form.StartDay,elem.form.StartMonth,elem.form.StartYear) - document.getElementById('StartDay' ).options[Day ].selected = true; +function setDateTo (Day,Month,Year) { + document.getElementById('StartYear' ).options[Year ].selected = true; + document.getElementById('StartMonth' ).options[Month].selected = true; + adjustDateForm ('Start') + document.getElementById('StartDay' ).options[Day ].selected = true; + document.getElementById('StartHour' ).options[0 ].selected = true; + document.getElementById('StartMinute').options[0 ].selected = true; + document.getElementById('StartSecond').options[0 ].selected = true; + setUTCFromLocalDateTimeForm('Start'); - document.getElementById('EndYear' ).options[Year ].selected = true; - document.getElementById('EndMonth').options[Month].selected = true; - adjustDateForm (elem.form.EndDay,elem.form.EndMonth,elem.form.EndYear) - document.getElementById('EndDay' ).options[Day ].selected = true; + document.getElementById('EndYear' ).options[Year ].selected = true; + document.getElementById('EndMonth' ).options[Month].selected = true; + adjustDateForm ('End') + document.getElementById('EndDay' ).options[Day ].selected = true; + document.getElementById('EndHour' ).options[23 ].selected = true; + document.getElementById('EndMinute' ).options[59 ].selected = true; + document.getElementById('EndSecond' ).options[59 ].selected = true; + setUTCFromLocalDateTimeForm('End'); } // Write clock in client local time updated every minute diff --git a/swad_action.c b/swad_action.c index 430e3ab7e..4c9b96809 100644 --- a/swad_action.c +++ b/swad_action.c @@ -2160,7 +2160,7 @@ struct Act_Actions Act_Actions[Act_NUM_ACTIONS] = /* ActSeeTst */{ 29,-1,TabAss,ActReqTst ,0x118,0x100,0x000,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,Tst_ShowNewTestExam ,NULL}, /* ActAssTst */{ 98,-1,TabAss,ActReqTst ,0x118,0x100,0x000,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,Tst_AssessTestExam ,NULL}, - /* ActEdiTstQst */{ 104,-1,TabAss,ActReqTst ,0x110,0x100,0x000,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,Tst_ShowFormAskEditTsts ,NULL}, + /* ActEdiTstQst */{ 104,-1,TabAss,ActReqTst ,0x110,0x100,0x000,Act_CONTENT_NORM,Act_MAIN_WINDOW,Tst_SetIniEndDates ,Tst_ShowFormAskEditTsts ,NULL}, /* ActEdiOneTstQst */{ 105,-1,TabAss,ActReqTst ,0x110,0x100,0x000,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,Tst_ShowFormEditOneQst ,NULL}, /* ActReqImpTstQst */{1007,-1,TabAss,ActReqTst ,0x110,0x100,0x000,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,TsI_ShowFormImportQstsFromXML ,NULL}, /* ActImpTstQst */{1008,-1,TabAss,ActReqTst ,0x110,0x100,0x000,Act_CONTENT_DATA,Act_MAIN_WINDOW,NULL ,TsI_ImportQstsFromXML ,NULL}, diff --git a/swad_changelog.h b/swad_changelog.h index 68ec0d3bc..274243958 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -108,11 +108,12 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 15.21 (2015/10/25)" +#define Log_PLATFORM_VERSION "SWAD 15.21.1 (2015/10/26)" // 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 15.21.1: Oct 26, 2015 New forms to enter range of date-times in statistic and test. (186313 lines) Version 15.21: Oct 25, 2015 New forms to enter range of date-times in statistic and test. Not finished. (186549 lines) Version 15.20.2: Oct 24, 2015 Code refactoring related to date-times forms. (186294 lines) Version 15.20.1: Oct 24, 2015 Detailed clics are displayed in client local date-time. (186333 lines) diff --git a/swad_date.c b/swad_date.c index 18ec0cf95..fdb1bde86 100644 --- a/swad_date.c +++ b/swad_date.c @@ -67,10 +67,6 @@ static void Dat_WriteFormClientLocalDateTimeFromTimeUTC (const char *Id, time_t TimeUTC, unsigned FirstYear,unsigned LastYear, bool SubmitFormOnChange,bool Disabled); -static void Dat_WriteFormClientLocalDateTimeFromYMDhms (const char *Id, - struct Date *DateSelected, - unsigned FirstYear,unsigned LastYear, - bool SubmitFormOnChange,bool Disabled); /*****************************************************************************/ /***************************** Get current time ******************************/ @@ -118,7 +114,12 @@ time_t Dat_GetUNIXTimeFromStr (const char *Str) { time_t Time; - if (sscanf (Str,"%ld",&Time) != 1) + if (Str[0]) + { + if (sscanf (Str,"%ld",&Time) != 1) + Time = (time_t) 0; + } + else Time = (time_t) 0; return Time; @@ -222,63 +223,6 @@ void Dat_ConvDateToDateStr (struct Date *Date,char *DateStr) /*************** Show forms to enter initial and ending dates ****************/ /*****************************************************************************/ -void Dat_WriteFormIniEndDates (void) - { - extern const char *The_ClassForm[The_NUM_THEMES]; - extern const char *Txt_Start_date; - extern const char *Txt_End_date; - extern const char *Txt_Yesterday; - extern const char *Txt_Today; - - /***** Start date *****/ - fprintf (Gbl.F.Out,"" - "" - "%s:" - "" - "", - The_ClassForm[Gbl.Prefs.Theme], - Txt_Start_date); - Dat_WriteFormDate (Cfg_LOG_START_YEAR,Gbl.Now.Date.Year,"Start", - &(Gbl.DateRange.DateIni), - false,false); - - /***** "Yesterday" and "Today" buttons *****/ - fprintf (Gbl.F.Out,"" - "" - "" - "" - "" - "", - Txt_Yesterday, - Gbl.Yesterday.Day, - Gbl.Yesterday.Month, - Gbl.Yesterday.Year - Cfg_LOG_START_YEAR + 1, - Txt_Today, - Gbl.Now.Date.Day, - Gbl.Now.Date.Month, - Gbl.Now.Date.Year - Cfg_LOG_START_YEAR + 1); - - /***** End date *****/ - fprintf (Gbl.F.Out,"" - "" - "%s:" - "" - "", - The_ClassForm[Gbl.Prefs.Theme], - Txt_End_date); - Dat_WriteFormDate (Cfg_LOG_START_YEAR,Gbl.Now.Date.Year,"End", - &(Gbl.DateRange.DateEnd), - false,false); - fprintf (Gbl.F.Out,"" - ""); - } - -/*****************************************************************************/ -/*************** Show forms to enter initial and ending dates ****************/ -/*****************************************************************************/ - void Dat_PutFormStartEndClientLocalDateTimesWithYesterdayToday (void) { extern const char *The_ClassForm[The_NUM_THEMES]; @@ -296,19 +240,19 @@ void Dat_PutFormStartEndClientLocalDateTimesWithYesterdayToday (void) The_ClassForm[Gbl.Prefs.Theme], Txt_Start_date); /* Date-time */ - Dat_WriteFormClientLocalDateTimeFromYMDhms ("Start", - &Gbl.DateRange.DateIni, - Cfg_LOG_START_YEAR, - Gbl.Now.Date.Year, - false,false); + Dat_WriteFormClientLocalDateTimeFromTimeUTC ("Start", + Gbl.DateRange.TimeUTC[0], + Cfg_LOG_START_YEAR, + Gbl.Now.Date.Year, + false,false); /***** "Yesterday" and "Today" buttons *****/ fprintf (Gbl.F.Out,"" "" "" + " onclick=\"setDateTo(%u,%u,%u);\" />" "" + " onclick=\"setDateTo(%u,%u,%u);\" />" "" "", Txt_Yesterday, @@ -329,11 +273,11 @@ void Dat_PutFormStartEndClientLocalDateTimesWithYesterdayToday (void) The_ClassForm[Gbl.Prefs.Theme], Txt_End_date); /* Date-time */ - Dat_WriteFormClientLocalDateTimeFromYMDhms ("End", - &Gbl.DateRange.DateEnd, - Cfg_LOG_START_YEAR, - Gbl.Now.Date.Year, - false,false); + Dat_WriteFormClientLocalDateTimeFromTimeUTC ("End", + Gbl.DateRange.TimeUTC[1], + Cfg_LOG_START_YEAR, + Gbl.Now.Date.Year, + false,false); fprintf (Gbl.F.Out,"" ""); @@ -552,200 +496,6 @@ static void Dat_WriteFormClientLocalDateTimeFromTimeUTC (const char *Id, Id,(long) TimeUTC,Id); } - -/*****************************************************************************/ -/************************* Show a form to enter a date ***********************/ -/*****************************************************************************/ - -static void Dat_WriteFormClientLocalDateTimeFromYMDhms (const char *Id, - struct Date *DateSelected, - unsigned FirstYear,unsigned LastYear, - bool SubmitFormOnChange,bool Disabled) - { - extern const char *Txt_MONTHS_SMALL[12]; - unsigned Day; - unsigned Month; - unsigned Year; - unsigned Hour; - unsigned Minute; - unsigned Second; - unsigned NumDaysSelectedMonth = (DateSelected->Month == 0) ? 31 : - ((DateSelected->Month == 2) ? Dat_GetNumDaysFebruary (DateSelected->Year) : - Dat_NumDaysMonth[DateSelected->Month]); - struct Time TimeSelected; // Put hour, minute and second in struct Date - TimeSelected.Hour = 0; - TimeSelected.Minute = 0; - TimeSelected.Second = 0; - - /***** Start table *****/ - fprintf (Gbl.F.Out,"" - ""); - - /***** Year *****/ - fprintf (Gbl.F.Out,""); - - /***** Month *****/ - fprintf (Gbl.F.Out,""); - - /***** Day *****/ - fprintf (Gbl.F.Out,""); - - /***** Hour *****/ - fprintf (Gbl.F.Out,""); - - /***** Minute *****/ - fprintf (Gbl.F.Out,""); - - /***** Second *****/ - fprintf (Gbl.F.Out,""); - - /***** End table *****/ - fprintf (Gbl.F.Out,"" - "
" - "" - "" - "" - "" - "" - ", " - "" - "" - "" - "" - "" - "
"); - - /***** Hidden field with UTC time (seconds since 1970) used to send time *****/ - fprintf (Gbl.F.Out,"", - Id,Id); - - /***** Script to set UTC time from selectors with local date and time *****/ - fprintf (Gbl.F.Out,"", - Id,Id); - } - /*****************************************************************************/ /***************** Get an hour-minute time from a form ***********************/ /*****************************************************************************/ diff --git a/swad_date.h b/swad_date.h index d770ed921..3f6d491fc 100644 --- a/swad_date.h +++ b/swad_date.h @@ -77,7 +77,6 @@ void Dat_ShowClientLocalTime (void); void Dat_GetLocalTimeFromClock (const time_t *clock); void Dat_ConvDateToDateStr (struct Date *Date,char *DateStr); -void Dat_WriteFormIniEndDates (void); void Dat_PutFormStartEndClientLocalDateTimesWithYesterdayToday (void); void Dat_PutFormStartEndClientLocalDateTimes (time_t TimeUTC[2]); diff --git a/swad_global.c b/swad_global.c index d1a56ebc9..baa4c42e0 100644 --- a/swad_global.c +++ b/swad_global.c @@ -393,13 +393,6 @@ void Gbl_InitializeGlobals (void) Gbl.Usrs.ClassPhoto.Cols = Usr_CLASS_PHOTO_COLS_DEF; - Gbl.DateRange.DateIni.Year = Cfg_LOG_START_YEAR; - Gbl.DateRange.DateIni.Month = Cfg_LOG_START_MONTH; - Gbl.DateRange.DateIni.Day = Cfg_LOG_START_DAY; - Gbl.DateRange.DateEnd.Year = Gbl.Now.Date.Year; - Gbl.DateRange.DateEnd.Month = Gbl.Now.Date.Month; - Gbl.DateRange.DateEnd.Day = Gbl.Now.Date.Day; - Gbl.Stat.ClicksGroupedBy = Sta_CLICKS_CRS_PER_USR; Gbl.Stat.CountType = Sta_TOTAL_CLICKS; Gbl.Stat.Role = Sta_IDENTIFIED_USRS; diff --git a/swad_statistic.c b/swad_statistic.c index 7bed92e8e..4356a563e 100644 --- a/swad_statistic.c +++ b/swad_statistic.c @@ -506,7 +506,6 @@ void Sta_AskShowCrsHits (void) ""); /***** Initial and final dates of the search *****/ - // Dat_WriteFormIniEndDates (); Dat_PutFormStartEndClientLocalDateTimesWithYesterdayToday (); /***** Selection of action *****/ @@ -644,7 +643,6 @@ void Sta_AskShowGblHits (void) Lay_StartRoundFrameTable (NULL,2,Txt_Statistics_of_all_visits); /***** Start and end dates for the search *****/ - // Dat_WriteFormIniEndDates (); Dat_PutFormStartEndClientLocalDateTimesWithYesterdayToday (); /***** Users' roles whose accesses we want to see *****/ @@ -801,29 +799,8 @@ static void Sta_WriteSelectorAction (void) void Sta_SetIniEndDates (void) { - extern const unsigned Dat_NumDaysMonth[1+12]; // Declaration in swad_date.c - - Gbl.DateRange.DateEnd.Day = Gbl.Now.Date.Day; - Gbl.DateRange.DateEnd.Month = Gbl.Now.Date.Month; - Gbl.DateRange.DateEnd.Year = Gbl.Now.Date.Year; - - if (Gbl.DateRange.DateEnd.Day >= Cfg_DAYS_IN_RECENT_LOG) - { - Gbl.DateRange.DateIni.Year = Gbl.DateRange.DateEnd.Year; - Gbl.DateRange.DateIni.Month = Gbl.DateRange.DateEnd.Month; - Gbl.DateRange.DateIni.Day = Gbl.DateRange.DateEnd.Day - (Cfg_DAYS_IN_RECENT_LOG-1); - } - else - { - Gbl.DateRange.DateIni.Year = (Gbl.DateRange.DateEnd.Month == 1) ? Gbl.DateRange.DateEnd.Year - 1 : - Gbl.DateRange.DateEnd.Year; - Gbl.DateRange.DateIni.Month = (Gbl.DateRange.DateEnd.Month == 1) ? 12 : - Gbl.DateRange.DateEnd.Month - 1; - Gbl.DateRange.DateIni.Day = ((Gbl.DateRange.DateIni.Month == 2) ? Dat_GetNumDaysFebruary (Gbl.DateRange.DateIni.Year) : - Dat_NumDaysMonth[Gbl.DateRange.DateIni.Month]) + - Gbl.DateRange.DateEnd.Day - - (Cfg_DAYS_IN_RECENT_LOG-1); - } + Gbl.DateRange.TimeUTC[0] = Gbl.TimeStartExecution - ((Cfg_DAYS_IN_RECENT_LOG - 1) * 24 * 60 * 60); + Gbl.DateRange.TimeUTC[1] = Gbl.TimeStartExecution; } /*****************************************************************************/ diff --git a/swad_test.c b/swad_test.c index c2c803d3f..4a46c384c 100644 --- a/swad_test.c +++ b/swad_test.c @@ -1079,6 +1079,17 @@ static void Tst_UpdateLastAccTst (void) DB_QueryUPDATE (Query,"can not update time and number of questions of this test"); } +/*****************************************************************************/ +/************ Set end date to current date ************/ +/************ and set initial date to end date minus several days ************/ +/*****************************************************************************/ + +void Tst_SetIniEndDates (void) + { + Gbl.DateRange.TimeUTC[0] = (time_t) 0; + Gbl.DateRange.TimeUTC[1] = Gbl.TimeStartExecution; + } + /*****************************************************************************/ /******* Select tags and dates for edition of the self-assessment test *******/ /*****************************************************************************/ @@ -1120,7 +1131,6 @@ void Tst_ShowFormAskEditTsts (void) /***** Starting and ending dates in the search *****/ fprintf (Gbl.F.Out,""); - // Dat_WriteFormIniEndDates (); Dat_PutFormStartEndClientLocalDateTimesWithYesterdayToday (); fprintf (Gbl.F.Out,"
" ""); @@ -5949,7 +5959,6 @@ void Tst_SelUsrsToSeeUsrsTstExams (void) ""); /***** Starting and ending dates in the search *****/ - // Dat_WriteFormIniEndDates (); Dat_PutFormStartEndClientLocalDateTimesWithYesterdayToday (); fprintf (Gbl.F.Out,""); @@ -5992,7 +6001,6 @@ void Tst_SelDatesToSeeMyTstExams (void) /***** Starting and ending dates in the search *****/ Lay_StartRoundFrameTable (NULL,2,Txt_Exams); - // Dat_WriteFormIniEndDates (); Dat_PutFormStartEndClientLocalDateTimesWithYesterdayToday (); /***** Send button and end frame *****/ diff --git a/swad_test.h b/swad_test.h index 60705f506..bddcb4b11 100644 --- a/swad_test.h +++ b/swad_test.h @@ -124,6 +124,8 @@ void Tst_ShowNewTestExam (void); void Tst_AssessTestExam (void); void Tst_WriteQstStem (const char *Stem,const char *ClassStem); void Tst_WriteQstFeedback (const char *Feedback,const char *ClassFeedback); + +void Tst_SetIniEndDates (void); void Tst_ShowFormAskEditTsts (void); void Tst_ListQuestionsToEdit (void); void Tst_WriteParamEditQst (void);