Version 15.21

This commit is contained in:
Antonio Cañas Vargas 2015-10-25 00:23:22 +02:00
parent 5bde190ea8
commit 51d9385403
6 changed files with 298 additions and 25 deletions

View File

@ -108,11 +108,12 @@
/****************************** Public constants *****************************/
/*****************************************************************************/
#define Log_PLATFORM_VERSION "SWAD 15.20.2 (2015/10/24)"
#define Log_PLATFORM_VERSION "SWAD 15.21 (2015/10/25)"
// 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: 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)
Version 15.20: Oct 24, 2015 Date-times in notifications, messages and forums are displayed in client local date-time. (186334 lines)

View File

@ -63,10 +63,14 @@ const unsigned Dat_NumDaysMonth[1+12] =
/***************************** Private prototypes ****************************/
/*****************************************************************************/
static void Dat_WriteFormClientLocalDateTime (const char *Id,
time_t TimeUTC,
unsigned FirstYear,unsigned LastYear,
bool SubmitFormOnChange,bool Disabled);
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 ******************************/
@ -271,6 +275,69 @@ void Dat_WriteFormIniEndDates (void)
"</tr>");
}
/*****************************************************************************/
/*************** Show forms to enter initial and ending dates ****************/
/*****************************************************************************/
void Dat_PutFormStartEndClientLocalDateTimesWithYesterdayToday (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-time *****/
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"%s RIGHT_MIDDLE\">"
"%s:"
"</td>"
"<td class=\"LEFT_MIDDLE\">",
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);
/***** "Yesterday" and "Today" buttons *****/
fprintf (Gbl.F.Out,"</td>"
"<td rowspan=\"2\" class=\"LEFT_MIDDLE\">"
"<input type=\"button\" name=\"Yesterday\" value=\"%s\""
" onclick=\"setDateTo(this,%u,%u,%u)\" />"
"<input type=\"button\" name=\"Today\" value=\"%s\""
" onclick=\"setDateTo(this,%u,%u,%u)\" />"
"</td>"
"</tr>",
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-time *****/
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"%s RIGHT_MIDDLE\">"
"%s:"
"</td>"
"<td class=\"LEFT_MIDDLE\">",
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);
fprintf (Gbl.F.Out,"</td>"
"</tr>");
}
/*****************************************************************************/
/************* Show forms to enter initial and ending date-times *************/
@ -309,11 +376,11 @@ void Dat_PutFormStartEndClientLocalDateTimes (time_t TimeUTC[2])
Dates[StartOrEndTime]);
/* Date-time */
Dat_WriteFormClientLocalDateTime (Id[StartOrEndTime],
TimeUTC[StartOrEndTime],
Gbl.Now.Date.Year - 1,
Gbl.Now.Date.Year + 1,
false,false);
Dat_WriteFormClientLocalDateTimeFromTimeUTC (Id[StartOrEndTime],
TimeUTC[StartOrEndTime],
Gbl.Now.Date.Year - 1,
Gbl.Now.Date.Year + 1,
false,false);
fprintf (Gbl.F.Out,"</td>"
"</tr>"
@ -327,10 +394,10 @@ void Dat_PutFormStartEndClientLocalDateTimes (time_t TimeUTC[2])
/************************* Show a form to enter a date ***********************/
/*****************************************************************************/
static void Dat_WriteFormClientLocalDateTime (const char *Id,
time_t TimeUTC,
unsigned FirstYear,unsigned LastYear,
bool SubmitFormOnChange,bool Disabled)
static void Dat_WriteFormClientLocalDateTimeFromTimeUTC (const char *Id,
time_t TimeUTC,
unsigned FirstYear,unsigned LastYear,
bool SubmitFormOnChange,bool Disabled)
{
extern const char *Txt_MONTHS_SMALL[12];
unsigned Day;
@ -384,7 +451,7 @@ static void Dat_WriteFormClientLocalDateTime (const char *Id,
Month <= 12;
Month++)
fprintf (Gbl.F.Out,"<option value=\"%u\">%s</option>",
Month,Txt_MONTHS_SMALL[Month-1]);
Month,Txt_MONTHS_SMALL[Month - 1]);
fprintf (Gbl.F.Out,"</select>"
"</td>");
@ -479,12 +546,206 @@ static void Dat_WriteFormClientLocalDateTime (const char *Id,
/***** Script to set selectors to local date and time from UTC time *****/
fprintf (Gbl.F.Out,"<script type=\"text/javascript\">"
"setLocalDateTimeFormFromUTC('%s',%ld);"
"adjustDateForm('%s');"
"setLocalDateTimeFormFromUTC('%s',%ld);"
"adjustDateForm('%s');"
"</script>",
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,"<table>"
"<tr>");
/***** Year *****/
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">"
"<select id=\"%sYear\" name=\"%sYear\""
" onchange=\""
"adjustDateForm('%s');"
"setUTCFromLocalDateTimeForm('%s');",
Id,Id,Id,Id);
if (SubmitFormOnChange)
fprintf (Gbl.F.Out,"document.getElementById('%s').submit();",
Gbl.FormId);
fprintf (Gbl.F.Out,"\"");
if (Disabled)
fprintf (Gbl.F.Out," disabled=\"disabled\"");
fprintf (Gbl.F.Out,"><option value=\"0\">-</option>");
for (Year = FirstYear;
Year <= LastYear;
Year++)
{
fprintf (Gbl.F.Out,"<option value=\"%u\"",Year);
if (Year == DateSelected->Year)
fprintf (Gbl.F.Out," selected=\"selected\"");
fprintf (Gbl.F.Out,">%u</option>",Year);
}
fprintf (Gbl.F.Out,"</select>"
"</td>");
/***** Month *****/
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">"
"<select id=\"%sMonth\" name=\"%sMonth\""
" onchange=\""
"adjustDateForm('%s');"
"setUTCFromLocalDateTimeForm('%s');",
Id,Id,Id,Id);
if (SubmitFormOnChange)
fprintf (Gbl.F.Out,"document.getElementById('%s').submit();",
Gbl.FormId);
fprintf (Gbl.F.Out,"\"");
if (Disabled)
fprintf (Gbl.F.Out," disabled=\"disabled\"");
fprintf (Gbl.F.Out,"><option value=\"0\">-</option>");
for (Month = 1;
Month <= 12;
Month++)
{
fprintf (Gbl.F.Out,"<option value=\"%u\"",Month);
if (Month == DateSelected->Month)
fprintf (Gbl.F.Out," selected=\"selected\"");
fprintf (Gbl.F.Out,">%s</option>",Txt_MONTHS_SMALL[Month - 1]);
}
fprintf (Gbl.F.Out,"</select>"
"</td>");
/***** Day *****/
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">"
"<select id=\"%sDay\" name=\"%sDay\""
" onchange=\"setUTCFromLocalDateTimeForm('%s');",
Id,Id,Id);
if (SubmitFormOnChange)
fprintf (Gbl.F.Out,"document.getElementById('%s').submit();",
Gbl.FormId);
fprintf (Gbl.F.Out,"\"");
if (Disabled)
fprintf (Gbl.F.Out," disabled=\"disabled\"");
fprintf (Gbl.F.Out,">"
"<option value=\"0\">-</option>");
for (Day = 1;
Day <= NumDaysSelectedMonth;
Day++)
{
fprintf (Gbl.F.Out,"<option value=\"%u\"",Day);
if (Day == DateSelected->Day)
fprintf (Gbl.F.Out," selected=\"selected\"");
fprintf (Gbl.F.Out,">%u</option>",Day);
}
fprintf (Gbl.F.Out,"</select>"
"</td>");
/***** Hour *****/
fprintf (Gbl.F.Out,"<td class=\"DAT LEFT_MIDDLE\">,&nbsp;"
"<select id=\"%sHour\" name=\"%sHour\""
" onchange=\"setUTCFromLocalDateTimeForm('%s');",
Id,Id,Id);
if (SubmitFormOnChange)
fprintf (Gbl.F.Out,"document.getElementById('%s').submit();",
Gbl.FormId);
fprintf (Gbl.F.Out,"\"");
if (Disabled)
fprintf (Gbl.F.Out," disabled=\"disabled\"");
fprintf (Gbl.F.Out,">");
for (Hour = 0;
Hour <= 23;
Hour++)
{
fprintf (Gbl.F.Out,"<option value=\"%u\"",Hour);
if (Hour == TimeSelected.Hour)
fprintf (Gbl.F.Out," selected=\"selected\"");
fprintf (Gbl.F.Out,">%02u h</option>",Hour);
}
fprintf (Gbl.F.Out,"</select>"
"</td>");
/***** Minute *****/
fprintf (Gbl.F.Out,"<td class=\"LEFT_MIDDLE\">"
"<select id=\"%sMinute\" name=\"%sMinute\""
" onchange=\"setUTCFromLocalDateTimeForm('%s');",
Id,Id,Id);
if (SubmitFormOnChange)
fprintf (Gbl.F.Out,"document.getElementById('%s').submit();",
Gbl.FormId);
fprintf (Gbl.F.Out,"\"");
if (Disabled)
fprintf (Gbl.F.Out," disabled=\"disabled\"");
fprintf (Gbl.F.Out,">");
for (Minute = 0;
Minute <= 59;
Minute++)
{
fprintf (Gbl.F.Out,"<option value=\"%u\"",Minute);
if (Minute == TimeSelected.Minute)
fprintf (Gbl.F.Out," selected=\"selected\"");
fprintf (Gbl.F.Out,">%02u &#39;</option>",Minute);
}
fprintf (Gbl.F.Out,"</select>"
"</td>");
/***** Second *****/
fprintf (Gbl.F.Out,"<td class=\"LEFT_MIDDLE\">"
"<select id=\"%sSecond\" name=\"%sSecond\""
" onchange=\"setUTCFromLocalDateTimeForm('%s');",
Id,Id,Id);
if (SubmitFormOnChange)
fprintf (Gbl.F.Out,"document.getElementById('%s').submit();",
Gbl.FormId);
fprintf (Gbl.F.Out,"\"");
if (Disabled)
fprintf (Gbl.F.Out," disabled=\"disabled\"");
fprintf (Gbl.F.Out,">");
for (Second = 0;
Second <= 59;
Second++)
{
fprintf (Gbl.F.Out,"<option value=\"%u\"",Second);
if (Second == TimeSelected.Second)
fprintf (Gbl.F.Out," selected=\"selected\"");
fprintf (Gbl.F.Out,">%02u &quot;</option>",Second);
}
fprintf (Gbl.F.Out,"</select>"
"</td>");
/***** End table *****/
fprintf (Gbl.F.Out,"</tr>"
"</table>");
/***** Hidden field with UTC time (seconds since 1970) used to send time *****/
fprintf (Gbl.F.Out,"<input type=\"hidden\" id=\"%sTimeUTC\" name=\"%sTimeUTC\" value=\"0\" />",
Id,Id);
/***** Script to set UTC time from selectors with local date and time *****/
fprintf (Gbl.F.Out,"<script type=\"text/javascript\">"
"setUTCFromLocalDateTimeForm('%s');"
"adjustDateForm('%s');"
"</script>",
Id,Id);
}
/*****************************************************************************/
/***************** Get an hour-minute time from a form ***********************/
/*****************************************************************************/
@ -569,7 +830,7 @@ void Dat_WriteFormDate (unsigned FirstYear,unsigned LastYear,
fprintf (Gbl.F.Out,"<option value=\"%u\"",Month);
if (Month == DateSelected->Month)
fprintf (Gbl.F.Out," selected=\"selected\"");
fprintf (Gbl.F.Out,">%s</option>",Txt_MONTHS_SMALL[Month-1]);
fprintf (Gbl.F.Out,">%s</option>",Txt_MONTHS_SMALL[Month - 1]);
}
/***** Year *****/
@ -717,6 +978,7 @@ void Dat_GetIniEndDatesFromForm (void)
&Gbl.DateRange.DateIni.Day,
&Gbl.DateRange.DateIni.Month,
&Gbl.DateRange.DateIni.Year);
// TODO: Get hour, minute and second
if (Gbl.DateRange.DateIni.Day == 0 ||
Gbl.DateRange.DateIni.Month == 0 ||
Gbl.DateRange.DateIni.Year == 0)
@ -725,12 +987,14 @@ void Dat_GetIniEndDatesFromForm (void)
Gbl.DateRange.DateIni.Month = Cfg_LOG_START_MONTH;
Gbl.DateRange.DateIni.Year = Cfg_LOG_START_YEAR;
}
Gbl.DateRange.TimeUTC[0] = Dat_GetTimeUTCFromForm ("StartTimeUTC");
/***** Get end date *****/
Dat_GetDateFromForm ("EndDay","EndMonth","EndYear",
&Gbl.DateRange.DateEnd.Day,
&Gbl.DateRange.DateEnd.Month,
&Gbl.DateRange.DateEnd.Year);
// TODO: Get hour, minute and second
if (Gbl.DateRange.DateEnd.Day == 0 ||
Gbl.DateRange.DateEnd.Month == 0 ||
Gbl.DateRange.DateEnd.Year == 0)
@ -739,6 +1003,7 @@ void Dat_GetIniEndDatesFromForm (void)
Gbl.DateRange.DateEnd.Month = Gbl.Now.Date.Month;
Gbl.DateRange.DateEnd.Year = Gbl.Now.Date.Year;
}
Gbl.DateRange.TimeUTC[1] = Dat_GetTimeUTCFromForm ("EndTimeUTC");
}
/*****************************************************************************/

View File

@ -78,6 +78,7 @@ 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]);
time_t Dat_GetTimeUTCFromForm (const char *ParamName);

View File

@ -642,8 +642,9 @@ struct Globals
} Test;
struct
{
struct Date DateIni;
struct Date DateEnd;
struct Date DateIni; // TODO: Remove in future versions
struct Date DateEnd; // TODO: Remove in future versions
time_t TimeUTC[2];
} DateRange;
struct
{

View File

@ -506,7 +506,8 @@ void Sta_AskShowCrsHits (void)
"</tr>");
/***** Initial and final dates of the search *****/
Dat_WriteFormIniEndDates ();
// Dat_WriteFormIniEndDates ();
Dat_PutFormStartEndClientLocalDateTimesWithYesterdayToday ();
/***** Selection of action *****/
Sta_WriteSelectorAction ();
@ -643,7 +644,8 @@ void Sta_AskShowGblHits (void)
Lay_StartRoundFrameTable (NULL,2,Txt_Statistics_of_all_visits);
/***** Start and end dates for the search *****/
Dat_WriteFormIniEndDates ();
// Dat_WriteFormIniEndDates ();
Dat_PutFormStartEndClientLocalDateTimesWithYesterdayToday ();
/***** Users' roles whose accesses we want to see *****/
fprintf (Gbl.F.Out,"<tr>"

View File

@ -1120,7 +1120,8 @@ void Tst_ShowFormAskEditTsts (void)
/***** Starting and ending dates in the search *****/
fprintf (Gbl.F.Out,"<table class=\"CELLS_PAD_2\""
" style=\"margin:0 auto;\">");
Dat_WriteFormIniEndDates ();
// Dat_WriteFormIniEndDates ();
Dat_PutFormStartEndClientLocalDateTimesWithYesterdayToday ();
fprintf (Gbl.F.Out,"</table>"
"</div>");
@ -5948,7 +5949,8 @@ void Tst_SelUsrsToSeeUsrsTstExams (void)
"</tr>");
/***** Starting and ending dates in the search *****/
Dat_WriteFormIniEndDates ();
// Dat_WriteFormIniEndDates ();
Dat_PutFormStartEndClientLocalDateTimesWithYesterdayToday ();
fprintf (Gbl.F.Out,"</table>");
@ -5990,7 +5992,8 @@ void Tst_SelDatesToSeeMyTstExams (void)
/***** Starting and ending dates in the search *****/
Lay_StartRoundFrameTable (NULL,2,Txt_Exams);
Dat_WriteFormIniEndDates ();
// Dat_WriteFormIniEndDates ();
Dat_PutFormStartEndClientLocalDateTimesWithYesterdayToday ();
/***** Send button and end frame *****/
Lay_EndRoundFrameTableWithButton (Lay_CONFIRM_BUTTON,Txt_See_exams);