mirror of https://github.com/acanas/swad-core.git
Version 15.24
This commit is contained in:
parent
9bcd9e5dd6
commit
8eb096e41c
199
js/swad.js
199
js/swad.js
|
@ -24,7 +24,7 @@
|
|||
// Global variable used in refreshConnected()
|
||||
var ActionAJAX;
|
||||
|
||||
// Global variables used in writeLocalTime()
|
||||
// Global variables used in writeLocalClock()
|
||||
var secondsSince1970UTC;
|
||||
|
||||
// Global variables used in writeClockConnected()
|
||||
|
@ -88,93 +88,166 @@ function writeLocalDateTimeFromUTC(id,secsSince1970UTC,separator) {
|
|||
|
||||
// Set local date-time form fields from UTC time
|
||||
function setLocalDateTimeFormFromUTC(id,secsSince1970UTC) {
|
||||
var d = new Date;
|
||||
var YearForm = document.getElementById(id+'Year');
|
||||
var FormYea = document.getElementById(id+'Year');
|
||||
var FormMon = document.getElementById(id+'Month');
|
||||
var FormDay = document.getElementById(id+'Day');
|
||||
var FormHou = document.getElementById(id+'Hour');
|
||||
var FormMin = document.getElementById(id+'Minute');
|
||||
var FormSec = document.getElementById(id+'Second');
|
||||
var d;
|
||||
var Year;
|
||||
var YearIsValid = false;
|
||||
|
||||
d.setTime(secsSince1970UTC * 1000);
|
||||
if (secsSince1970UTC) {
|
||||
d = new Date;
|
||||
d.setTime(secsSince1970UTC * 1000);
|
||||
Year = d.getFullYear();
|
||||
for (var i=0; i<FormYea.options.length && !YearIsValid; i++)
|
||||
if (FormYea.options[i].value == Year) {
|
||||
FormYea.options[i].selected = true;
|
||||
YearIsValid = true;
|
||||
}
|
||||
FormMon.disabled = false;
|
||||
FormDay.disabled = false;
|
||||
FormHou.disabled = false;
|
||||
FormMin.disabled = false;
|
||||
FormSec.disabled = false;
|
||||
FormMon.options[d.getMonth()+1].selected = true;
|
||||
FormDay.options[d.getDate() ].selected = true;
|
||||
FormHou.options[d.getHours() ].selected = true;
|
||||
FormMin.options[d.getMinutes()].selected = true;
|
||||
FormSec.options[d.getSeconds()].selected = true;
|
||||
}
|
||||
|
||||
if (!YearIsValid) {
|
||||
FormYea.options[0].selected = true;
|
||||
FormMon.options[0].selected = true;
|
||||
FormDay.options[0].selected = true;
|
||||
FormHou.options[0].selected = true;
|
||||
FormMin.options[0].selected = true;
|
||||
FormSec.options[0].selected = true;
|
||||
|
||||
Year = d.getFullYear()
|
||||
for (var i=0; i<YearForm.options.length ; i++)
|
||||
if (YearForm.options[i].value == Year) {
|
||||
YearForm.options[i].selected = true;
|
||||
break;
|
||||
}
|
||||
document.getElementById(id+'Month' ).options[d.getMonth()+1].selected = true;
|
||||
document.getElementById(id+'Day' ).options[d.getDate() ].selected = true;
|
||||
document.getElementById(id+'Hour' ).options[d.getHours() ].selected = true;
|
||||
document.getElementById(id+'Minute').options[d.getMinutes()].selected = true;
|
||||
document.getElementById(id+'Second').options[d.getSeconds()].selected = true;
|
||||
FormMon.disabled = true;
|
||||
FormDay.disabled = true;
|
||||
FormHou.disabled = true;
|
||||
FormMin.disabled = true;
|
||||
FormSec.disabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
var FormYea = document.getElementById(id+'Year');
|
||||
var FormMon = document.getElementById(id+'Month');
|
||||
var FormDay = document.getElementById(id+'Day');
|
||||
var FormHou = document.getElementById(id+'Hour');
|
||||
var FormMin = document.getElementById(id+'Minute');
|
||||
var FormSec = document.getElementById(id+'Second');
|
||||
var FormTimeUTC = document.getElementById(id+'TimeUTC');
|
||||
var d;
|
||||
var Yea = FormYea.value;
|
||||
var Mon;
|
||||
var Day;
|
||||
|
||||
if (Year == 0 || Month == 0 || Day == 0)
|
||||
document.getElementById(id+'TimeUTC').value = 0;
|
||||
else {
|
||||
if (Yea == 0) {
|
||||
FormYea.options[0].selected = true;
|
||||
FormMon.options[0].selected = true;
|
||||
FormDay.options[0].selected = true;
|
||||
FormHou.options[0].selected = true;
|
||||
FormMin.options[0].selected = true;
|
||||
FormSec.options[0].selected = true;
|
||||
|
||||
FormMon.disabled = true;
|
||||
FormDay.disabled = true;
|
||||
FormHou.disabled = true;
|
||||
FormMin.disabled = true;
|
||||
FormSec.disabled = true;
|
||||
|
||||
FormTimeUTC.value = 0;
|
||||
}
|
||||
else {
|
||||
FormMon.disabled = false;
|
||||
FormDay.disabled = false;
|
||||
FormHou.disabled = false;
|
||||
FormMin.disabled = false;
|
||||
FormSec.disabled = false;
|
||||
|
||||
Mon = FormMon.value;
|
||||
if (Mon == 0)
|
||||
Mon = 1;
|
||||
Day = FormDay.value;
|
||||
if (Day == 0)
|
||||
Day = 1;
|
||||
|
||||
// Important: set year first in order to work properly with leap years
|
||||
d.setFullYear(Year);
|
||||
d.setMonth (Month-1);
|
||||
d = new (Date);
|
||||
d.setFullYear(Yea);
|
||||
d.setMonth (Mon-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.setHours (FormHou.value);
|
||||
d.setMinutes (FormMin.value);
|
||||
d.setSeconds (FormSec.value);
|
||||
d.setMilliseconds(0);
|
||||
|
||||
document.getElementById(id+'TimeUTC').value = d.getTime() / 1000;
|
||||
FormTimeUTC.value = d.getTime() / 1000;
|
||||
}
|
||||
}
|
||||
|
||||
// Adjust a date form correcting days in the month
|
||||
function adjustDateForm (id) {
|
||||
var Days = 31;
|
||||
var YearForm = document.getElementById(id+'Year' );
|
||||
var MonthForm = document.getElementById(id+'Month');
|
||||
var DayForm = document.getElementById(id+'Day' );
|
||||
var Year = YearForm.options[YearForm.selectedIndex].value;
|
||||
var FormYea = document.getElementById(id+'Year' );
|
||||
var FormMon = document.getElementById(id+'Month');
|
||||
var FormDay = document.getElementById(id+'Day' );
|
||||
var Yea = FormYea.options[FormYea.selectedIndex].value;
|
||||
var Days;
|
||||
|
||||
if (MonthForm.options[2].selected) // Adjust days of february
|
||||
Days = ((((Year % 4) == 0) && ((Year % 100) != 0)) || ((Year % 400) == 0)) ? 29 : 28;
|
||||
else if (MonthForm.options[ 4].selected ||
|
||||
MonthForm.options[ 6].selected ||
|
||||
MonthForm.options[ 9].selected ||
|
||||
MonthForm.options[11].selected)
|
||||
Days = 30;
|
||||
|
||||
if (DayForm.selectedIndex > Days)
|
||||
DayForm.options[Days].selected = true;
|
||||
|
||||
for (var i=DayForm.options.length; i<=Days ; i++) { // Create new days
|
||||
var x = String (i);
|
||||
DayForm.options[i] = new Option(x,x);
|
||||
if (FormYea.selectedIndex > 0) {
|
||||
if (FormMon.options[0].selected) { // No month selected, set to january
|
||||
FormMon.options[1].selected = true;
|
||||
Days = 31;
|
||||
}
|
||||
else if (FormMon.options[2].selected) // Adjust days of february
|
||||
Days = ((((Yea % 4) == 0) && ((Yea % 100) != 0)) || ((Yea % 400) == 0)) ? 29 : 28;
|
||||
else if (FormMon.options[ 4].selected ||
|
||||
FormMon.options[ 6].selected ||
|
||||
FormMon.options[ 9].selected ||
|
||||
FormMon.options[11].selected)
|
||||
Days = 30;
|
||||
else
|
||||
Days = 31;
|
||||
|
||||
if (FormDay.options[0].selected) // No day selected, set to 1
|
||||
FormDay.options[1].selected = true;
|
||||
else if (FormDay.selectedIndex > Days)
|
||||
FormDay.options[Days].selected = true;
|
||||
|
||||
for (var i=FormDay.options.length; i<=Days ; i++) { // Create new days
|
||||
var x = String (i);
|
||||
FormDay.options[i] = new Option(x,x);
|
||||
}
|
||||
for (var i=FormDay.options.length-1; i>Days; i--) // Remove days
|
||||
FormDay.options[i] = null;
|
||||
}
|
||||
for (var i=DayForm.options.length-1; i>Days; i--) // Remove days
|
||||
DayForm.options[i] = null;
|
||||
}
|
||||
|
||||
// Set a the date in a date form to a specified date
|
||||
function setDateTo (Day,Month,Year) {
|
||||
document.getElementById('StartYear' ).options[Year ].selected = true;
|
||||
document.getElementById('StartMonth' ).options[Month].selected = true;
|
||||
function setDateTo (Day,Mon,Yea) {
|
||||
document.getElementById('StartYear' ).options[Yea].selected = true;
|
||||
document.getElementById('StartMonth' ).options[Mon].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;
|
||||
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;
|
||||
document.getElementById('EndYear' ).options[Yea].selected = true;
|
||||
document.getElementById('EndMonth' ).options[Mon].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;
|
||||
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');
|
||||
}
|
||||
|
||||
|
@ -186,7 +259,7 @@ function writeLocalClock() {
|
|||
var StrH;
|
||||
var StrM;
|
||||
|
||||
setTimeout('writeLocalTime()',60000);
|
||||
setTimeout('writeLocalClock()',60000);
|
||||
|
||||
d.setTime(secondsSince1970UTC * 1000);
|
||||
secondsSince1970UTC += 60; // For next call
|
||||
|
|
|
@ -108,11 +108,13 @@
|
|||
/****************************** Public constants *****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
#define Log_PLATFORM_VERSION "SWAD 15.22.1 (2015/10/26)"
|
||||
#define Log_PLATFORM_VERSION "SWAD 15.24 (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.24: Oct 26, 2015 Lot of changes in swad.js related to date-times. (186336 lines)
|
||||
Version 15.23: Oct 26, 2015 Date-times to open groups are displayed in client local date-time. (186259 lines)
|
||||
Version 15.22.1: Oct 26, 2015 Date-times in notices are displayed in client local date-time. (186344 lines)
|
||||
Version 15.22: Oct 26, 2015 First click time in users' profiles is displayed in client local date-time. (186328 lines)
|
||||
Version 15.21.3: Oct 26, 2015 Changes in date-times of test exams. (186325 lines)
|
||||
|
|
124
swad_date.c
124
swad_date.c
|
@ -63,11 +63,6 @@ const unsigned Dat_NumDaysMonth[1+12] =
|
|||
/***************************** Private prototypes ****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
static void Dat_WriteFormClientLocalDateTimeFromTimeUTC (const char *Id,
|
||||
time_t TimeUTC,
|
||||
unsigned FirstYear,unsigned LastYear,
|
||||
bool SubmitFormOnChange,bool Disabled);
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************************** Get current time ******************************/
|
||||
/*****************************************************************************/
|
||||
|
@ -145,36 +140,6 @@ bool Dat_GetDateFromYYYYMMDD (struct Date *Date,const char *YYYYMMDD)
|
|||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/******* Get a struct DateTime from a string in YYYYMMDDHHMMSS format ********/
|
||||
/*****************************************************************************/
|
||||
|
||||
bool Dat_GetDateTimeFromYYYYMMDDHHMMSS (struct DateTime *DateTime,const char *YYYYMMDDHHMMSS)
|
||||
{
|
||||
if (sscanf (YYYYMMDDHHMMSS,"%04u%02u%02u%02u%02u%02u",
|
||||
&(DateTime->Date.Year),&(DateTime->Date.Month),&(DateTime->Date.Day),
|
||||
&(DateTime->Time.Hour),&(DateTime->Time.Minute),&(DateTime->Time.Second)) == 6)
|
||||
{
|
||||
strncpy (DateTime->Date.YYYYMMDD,YYYYMMDDHHMMSS,4+2+2);
|
||||
DateTime->YYYYMMDDHHMMSS[4+2+2] = '\0';
|
||||
|
||||
strncpy (DateTime->YYYYMMDDHHMMSS,YYYYMMDDHHMMSS,4+2+2+2+2+2);
|
||||
DateTime->YYYYMMDDHHMMSS[4+2+2+2+2+2] = '\0';
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
DateTime->Date.Year = DateTime->Date.Month = DateTime->Date.Day = 0;
|
||||
DateTime->Date.YYYYMMDD[0] = '\0';
|
||||
|
||||
DateTime->Time.Hour = DateTime->Time.Minute = DateTime->Time.Second = 0;
|
||||
DateTime->YYYYMMDDHHMMSS[0] = '\0';
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************** Write div for client local time ************************/
|
||||
/*****************************************************************************/
|
||||
|
@ -241,6 +206,7 @@ void Dat_PutFormStartEndClientLocalDateTimesWithYesterdayToday (void)
|
|||
Txt_Start_date);
|
||||
/* Date-time */
|
||||
Dat_WriteFormClientLocalDateTimeFromTimeUTC ("Start",
|
||||
"Start",
|
||||
Gbl.DateRange.TimeUTC[0],
|
||||
Cfg_LOG_START_YEAR,
|
||||
Gbl.Now.Date.Year,
|
||||
|
@ -274,6 +240,7 @@ void Dat_PutFormStartEndClientLocalDateTimesWithYesterdayToday (void)
|
|||
Txt_End_date);
|
||||
/* Date-time */
|
||||
Dat_WriteFormClientLocalDateTimeFromTimeUTC ("End",
|
||||
"End",
|
||||
Gbl.DateRange.TimeUTC[1],
|
||||
Cfg_LOG_START_YEAR,
|
||||
Gbl.Now.Date.Year,
|
||||
|
@ -321,6 +288,7 @@ void Dat_PutFormStartEndClientLocalDateTimes (time_t TimeUTC[2])
|
|||
|
||||
/* Date-time */
|
||||
Dat_WriteFormClientLocalDateTimeFromTimeUTC (Id[StartOrEndTime],
|
||||
Id[StartOrEndTime],
|
||||
TimeUTC[StartOrEndTime],
|
||||
Gbl.Now.Date.Year - 1,
|
||||
Gbl.Now.Date.Year + 1,
|
||||
|
@ -338,10 +306,11 @@ void Dat_PutFormStartEndClientLocalDateTimes (time_t TimeUTC[2])
|
|||
/************************* Show a form to enter a date ***********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
static void Dat_WriteFormClientLocalDateTimeFromTimeUTC (const char *Id,
|
||||
time_t TimeUTC,
|
||||
unsigned FirstYear,unsigned LastYear,
|
||||
bool SubmitFormOnChange,bool Disabled)
|
||||
void Dat_WriteFormClientLocalDateTimeFromTimeUTC (const char *Id,
|
||||
const char *ParamName,
|
||||
time_t TimeUTC,
|
||||
unsigned FirstYear,unsigned LastYear,
|
||||
bool SubmitFormOnChange,bool Disabled)
|
||||
{
|
||||
extern const char *Txt_MONTHS_SMALL[12];
|
||||
unsigned Day;
|
||||
|
@ -356,12 +325,12 @@ static void Dat_WriteFormClientLocalDateTimeFromTimeUTC (const char *Id,
|
|||
"<tr>");
|
||||
|
||||
/***** Year *****/
|
||||
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">"
|
||||
fprintf (Gbl.F.Out,"<td class=\"RIGHT_MIDDLE\">"
|
||||
"<select id=\"%sYear\" name=\"%sYear\""
|
||||
" onchange=\""
|
||||
"adjustDateForm('%s');"
|
||||
"setUTCFromLocalDateTimeForm('%s');",
|
||||
Id,Id,Id,Id);
|
||||
Id,ParamName,Id,Id);
|
||||
if (SubmitFormOnChange)
|
||||
fprintf (Gbl.F.Out,"document.getElementById('%s').submit();",
|
||||
Gbl.FormId);
|
||||
|
@ -383,14 +352,14 @@ static void Dat_WriteFormClientLocalDateTimeFromTimeUTC (const char *Id,
|
|||
" onchange=\""
|
||||
"adjustDateForm('%s');"
|
||||
"setUTCFromLocalDateTimeForm('%s');",
|
||||
Id,Id,Id,Id);
|
||||
Id,ParamName,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>");
|
||||
fprintf (Gbl.F.Out,"><option value=\"0\" disabled=\"disabled\">-</option>");
|
||||
for (Month = 1;
|
||||
Month <= 12;
|
||||
Month++)
|
||||
|
@ -400,10 +369,10 @@ static void Dat_WriteFormClientLocalDateTimeFromTimeUTC (const char *Id,
|
|||
"</td>");
|
||||
|
||||
/***** Day *****/
|
||||
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">"
|
||||
fprintf (Gbl.F.Out,"<td class=\"LEFT_MIDDLE\">"
|
||||
"<select id=\"%sDay\" name=\"%sDay\""
|
||||
" onchange=\"setUTCFromLocalDateTimeForm('%s');",
|
||||
Id,Id,Id);
|
||||
Id,ParamName,Id);
|
||||
if (SubmitFormOnChange)
|
||||
fprintf (Gbl.F.Out,"document.getElementById('%s').submit();",
|
||||
Gbl.FormId);
|
||||
|
@ -411,7 +380,7 @@ static void Dat_WriteFormClientLocalDateTimeFromTimeUTC (const char *Id,
|
|||
if (Disabled)
|
||||
fprintf (Gbl.F.Out," disabled=\"disabled\"");
|
||||
fprintf (Gbl.F.Out,">"
|
||||
"<option value=\"0\">-</option>");
|
||||
"<option value=\"0\" disabled=\"disabled\">-</option>");
|
||||
for (Day = 1;
|
||||
Day <= 31;
|
||||
Day++)
|
||||
|
@ -421,10 +390,10 @@ static void Dat_WriteFormClientLocalDateTimeFromTimeUTC (const char *Id,
|
|||
"</td>");
|
||||
|
||||
/***** Hour *****/
|
||||
fprintf (Gbl.F.Out,"<td class=\"DAT LEFT_MIDDLE\">, "
|
||||
fprintf (Gbl.F.Out,"<td class=\"RIGHT_MIDDLE\">"
|
||||
"<select id=\"%sHour\" name=\"%sHour\""
|
||||
" onchange=\"setUTCFromLocalDateTimeForm('%s');",
|
||||
Id,Id,Id);
|
||||
Id,ParamName,Id);
|
||||
if (SubmitFormOnChange)
|
||||
fprintf (Gbl.F.Out,"document.getElementById('%s').submit();",
|
||||
Gbl.FormId);
|
||||
|
@ -441,10 +410,10 @@ static void Dat_WriteFormClientLocalDateTimeFromTimeUTC (const char *Id,
|
|||
"</td>");
|
||||
|
||||
/***** Minute *****/
|
||||
fprintf (Gbl.F.Out,"<td class=\"LEFT_MIDDLE\">"
|
||||
fprintf (Gbl.F.Out,"<td class=\"CENTER_MIDDLE\">"
|
||||
"<select id=\"%sMinute\" name=\"%sMinute\""
|
||||
" onchange=\"setUTCFromLocalDateTimeForm('%s');",
|
||||
Id,Id,Id);
|
||||
Id,ParamName,Id);
|
||||
if (SubmitFormOnChange)
|
||||
fprintf (Gbl.F.Out,"document.getElementById('%s').submit();",
|
||||
Gbl.FormId);
|
||||
|
@ -464,7 +433,7 @@ static void Dat_WriteFormClientLocalDateTimeFromTimeUTC (const char *Id,
|
|||
fprintf (Gbl.F.Out,"<td class=\"LEFT_MIDDLE\">"
|
||||
"<select id=\"%sSecond\" name=\"%sSecond\""
|
||||
" onchange=\"setUTCFromLocalDateTimeForm('%s');",
|
||||
Id,Id,Id);
|
||||
Id,ParamName,Id);
|
||||
if (SubmitFormOnChange)
|
||||
fprintf (Gbl.F.Out,"document.getElementById('%s').submit();",
|
||||
Gbl.FormId);
|
||||
|
@ -486,7 +455,7 @@ static void Dat_WriteFormClientLocalDateTimeFromTimeUTC (const char *Id,
|
|||
|
||||
/***** Hidden field with UTC time (seconds since 1970) used to send time *****/
|
||||
fprintf (Gbl.F.Out,"<input type=\"hidden\" id=\"%sTimeUTC\" name=\"%sTimeUTC\" value=\"%ld\" />",
|
||||
Id,Id,(long) TimeUTC);
|
||||
Id,ParamName,(long) TimeUTC);
|
||||
|
||||
/***** Script to set selectors to local date and time from UTC time *****/
|
||||
fprintf (Gbl.F.Out,"<script type=\"text/javascript\">"
|
||||
|
@ -1137,54 +1106,3 @@ void Dat_AssignDate (struct Date *DateDst,struct Date *DateSrc)
|
|||
DateDst->Day = DateSrc->Day;
|
||||
DateDst->Week = DateSrc->Week;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/****************************** Compare dates ********************************/
|
||||
/*****************************************************************************/
|
||||
// Return <0 if Date1<Date2
|
||||
// Return >0 if Date1>Date2
|
||||
// Return 0 if Date1==Date2
|
||||
|
||||
int Dat_CompareDates (struct Date *Date1,struct Date *Date2)
|
||||
{
|
||||
if (Date1->Year < Date2->Year ) return -1;
|
||||
if (Date1->Year > Date2->Year ) return 1;
|
||||
|
||||
if (Date1->Month < Date2->Month) return -1;
|
||||
if (Date1->Month > Date2->Month) return 1;
|
||||
|
||||
if (Date1->Day < Date2->Day ) return -1;
|
||||
if (Date1->Day > Date2->Day ) return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************************** Compare datetimes ********************************/
|
||||
/*****************************************************************************/
|
||||
// Return <0 if DateTime1<DateTime2
|
||||
// Return >0 if DateTime1>DateTime2
|
||||
// Return 0 if DateTime1==DateTime2
|
||||
|
||||
int Dat_CompareDateTimes (struct DateTime *DateTime1,struct DateTime *DateTime2)
|
||||
{
|
||||
if (DateTime1->Date.Year < DateTime2->Date.Year ) return -1;
|
||||
if (DateTime1->Date.Year > DateTime2->Date.Year ) return 1;
|
||||
|
||||
if (DateTime1->Date.Month < DateTime2->Date.Month ) return -1;
|
||||
if (DateTime1->Date.Month > DateTime2->Date.Month ) return 1;
|
||||
|
||||
if (DateTime1->Date.Day < DateTime2->Date.Day ) return -1;
|
||||
if (DateTime1->Date.Day > DateTime2->Date.Day ) return 1;
|
||||
|
||||
if (DateTime1->Time.Hour < DateTime2->Time.Hour ) return -1;
|
||||
if (DateTime1->Time.Hour > DateTime2->Time.Hour ) return 1;
|
||||
|
||||
if (DateTime1->Time.Minute < DateTime2->Time.Minute) return -1;
|
||||
if (DateTime1->Time.Minute > DateTime2->Time.Minute) return 1;
|
||||
|
||||
if (DateTime1->Time.Second < DateTime2->Time.Second) return -1;
|
||||
if (DateTime1->Time.Second > DateTime2->Time.Second) return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -70,7 +70,6 @@ void Dat_GetAndConvertCurrentDateTime (void);
|
|||
|
||||
time_t Dat_GetUNIXTimeFromStr (const char *Str);
|
||||
bool Dat_GetDateFromYYYYMMDD (struct Date *Date,const char *YYYYMMDDString);
|
||||
bool Dat_GetDateTimeFromYYYYMMDDHHMMSS (struct DateTime *DateTime,const char *YYYYMMDDHHMMSS);
|
||||
|
||||
void Dat_ShowClientLocalTime (void);
|
||||
|
||||
|
@ -80,6 +79,11 @@ void Dat_ConvDateToDateStr (struct Date *Date,char *DateStr);
|
|||
void Dat_PutFormStartEndClientLocalDateTimesWithYesterdayToday (void);
|
||||
void Dat_PutFormStartEndClientLocalDateTimes (time_t TimeUTC[2]);
|
||||
|
||||
void Dat_WriteFormClientLocalDateTimeFromTimeUTC (const char *Id,
|
||||
const char *ParamName,
|
||||
time_t TimeUTC,
|
||||
unsigned FirstYear,unsigned LastYear,
|
||||
bool SubmitFormOnChange,bool Disabled);
|
||||
time_t Dat_GetTimeUTCFromForm (const char *ParamName);
|
||||
|
||||
void Dat_WriteFormDate (unsigned FirstYear,unsigned LastYear,
|
||||
|
@ -116,7 +120,4 @@ unsigned Dat_GetDayOfYear (struct Date *Date);
|
|||
void Dat_CalculateWeekOfYear (struct Date *Date);
|
||||
void Dat_AssignDate (struct Date *DateDst,struct Date *DateSrc);
|
||||
|
||||
int Dat_CompareDates (struct Date *Date1,struct Date *Date2);
|
||||
int Dat_CompareDateTimes (struct DateTime *DateTime1,struct DateTime *DateTime2);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -327,12 +327,7 @@ void Gbl_InitializeGlobals (void)
|
|||
Gbl.CurrentCrs.Grps.GrpTyp.MandatoryEnrollment = true;
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.MultipleEnrollment = false;
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.MustBeOpened = false;
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.OpenTime.Date.Year =
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.OpenTime.Date.Month =
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.OpenTime.Date.Day =
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.OpenTime.Time.Hour =
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.OpenTime.Time.Minute =
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.OpenTime.Time.Second = 0;
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.OpenTimeUTC = (time_t) 0;
|
||||
Gbl.CurrentCrs.Grps.GrpCod = -1L; // -1L stands for the whole course
|
||||
Gbl.CurrentCrs.Grps.GrpName[0] = '\0';
|
||||
Gbl.CurrentCrs.Grps.MaxStudents = INT_MAX;
|
||||
|
|
140
swad_group.c
140
swad_group.c
|
@ -89,7 +89,7 @@ static bool Grp_GetIfGrpIsAvailable (long GrpTypCod);
|
|||
static void Grp_GetLstCodGrpsUsrBelongs (long CrsCod,long GrpTypCod,long UsrCod,
|
||||
struct ListCodGrps *LstGrps);
|
||||
static bool Grp_CheckIfGrpIsInList (long GrpCod,struct ListCodGrps *LstGrps);
|
||||
static bool Grp_CheckIfOpenTimeInTheFuture (struct DateTime *OpenTime);
|
||||
static bool Grp_CheckIfOpenTimeInTheFuture (time_t OpenTimeUTC);
|
||||
static bool Grp_CheckIfGroupTypeNameExists (const char *GrpTypName,long GrpTypCod);
|
||||
static bool Grp_CheckIfGroupNameExists (long GrpTypCod,const char *GrpName,long GrpCod);
|
||||
static void Grp_CreateGroupType (void);
|
||||
|
@ -1123,15 +1123,17 @@ static void Grp_ListGroupTypesForEdition (void)
|
|||
extern const char *Txt_The_groups_will_automatically_open;
|
||||
extern const char *Txt_The_groups_will_not_automatically_open;
|
||||
unsigned NumGrpTyp;
|
||||
unsigned UniqueId;
|
||||
char Id[32];
|
||||
|
||||
/***** Write heading *****/
|
||||
Lay_StartRoundFrameTable (NULL,2,Txt_Types_of_group);
|
||||
Grp_WriteHeadingGroupTypes ();
|
||||
|
||||
/***** List group types with forms for edition *****/
|
||||
for (NumGrpTyp = 0;
|
||||
for (NumGrpTyp = 0, UniqueId=1;
|
||||
NumGrpTyp < Gbl.CurrentCrs.Grps.GrpTypes.Num;
|
||||
NumGrpTyp++)
|
||||
NumGrpTyp++, UniqueId++)
|
||||
{
|
||||
/* Put icon to remove group type */
|
||||
fprintf (Gbl.F.Out,"<tr>"
|
||||
|
@ -1218,14 +1220,13 @@ static void Grp_ListGroupTypesForEdition (void)
|
|||
Txt_The_groups_will_not_automatically_open,
|
||||
Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].MustBeOpened ? Txt_The_groups_will_automatically_open :
|
||||
Txt_The_groups_will_not_automatically_open);
|
||||
Dat_WriteFormDate (Gbl.Now.Date.Year,Gbl.Now.Date.Year + 1,"Open",
|
||||
&(Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].OpenTime.Date),
|
||||
true,false);
|
||||
fprintf (Gbl.F.Out,"</td>"
|
||||
"<td class=\"LEFT_MIDDLE\">");
|
||||
Dat_WriteFormHourMinute ("OpenHour","OpenMinute",
|
||||
&(Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].OpenTime.Time),
|
||||
true,false);
|
||||
sprintf (Id,"open_time_%u",UniqueId);
|
||||
Dat_WriteFormClientLocalDateTimeFromTimeUTC (Id,
|
||||
"Open",
|
||||
Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].OpenTimeUTC,
|
||||
Gbl.Now.Date.Year,
|
||||
Gbl.Now.Date.Year + 1,
|
||||
true,false);
|
||||
fprintf (Gbl.F.Out,"</td>"
|
||||
"</tr>"
|
||||
"</table>");
|
||||
|
@ -1913,6 +1914,7 @@ static void Grp_WriteGrpHead (struct GroupType *GrpTyp)
|
|||
extern const char *Txt_Max_BR_students;
|
||||
extern const char *Txt_Students_ABBREVIATION;
|
||||
extern const char *Txt_Vacants;
|
||||
static unsigned UniqueId = 0;
|
||||
|
||||
/***** Name of group type *****/
|
||||
fprintf (Gbl.F.Out,"<tr>"
|
||||
|
@ -1921,10 +1923,15 @@ static void Grp_WriteGrpHead (struct GroupType *GrpTyp)
|
|||
GrpTyp->GrpTypName);
|
||||
if (GrpTyp->MustBeOpened)
|
||||
{
|
||||
fprintf (Gbl.F.Out,"<br />%s: ",Txt_Opening_of_groups);
|
||||
Dat_WriteDate (GrpTyp->OpenTime.YYYYMMDDHHMMSS);
|
||||
fprintf (Gbl.F.Out," ");
|
||||
Dat_WriteHourMinute (&(GrpTyp->OpenTime.YYYYMMDDHHMMSS[8]));
|
||||
UniqueId++;
|
||||
fprintf (Gbl.F.Out,"<br />%s: "
|
||||
"<span id=\"open_time_%u\"></span>"
|
||||
"<script type=\"text/javascript\">"
|
||||
"writeLocalDateTimeFromUTC('open_time_%u',%ld,' ');"
|
||||
"</script>",
|
||||
Txt_Opening_of_groups,
|
||||
UniqueId,
|
||||
UniqueId,(long) GrpTyp->OpenTimeUTC);
|
||||
}
|
||||
fprintf (Gbl.F.Out,"</td>"
|
||||
"</tr>");
|
||||
|
@ -2097,12 +2104,12 @@ static void Grp_PutFormToCreateGroupType (void)
|
|||
fprintf (Gbl.F.Out,"<td class=\"LEFT_MIDDLE\">"
|
||||
"<table class=\"CELLS_PAD_2\">"
|
||||
"<tr>"
|
||||
"<td class=\"LEFT_MIDDLE\">"
|
||||
"<td class=\"LEFT_MIDDLE\" style=\"width:20px;\">"
|
||||
"<img src=\"%s/%s16x16.gif\""
|
||||
" alt=\"%s\" title=\"%s\""
|
||||
" class=\"ICON16x16\" />"
|
||||
"</td>"
|
||||
"<td class=\"LEFT_BOTTOM\" style=\"width:20px;\">",
|
||||
"<td class=\"LEFT_MIDDLE\">",
|
||||
Gbl.Prefs.IconsURL,
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.MustBeOpened ? "time" :
|
||||
"time-off",
|
||||
|
@ -2110,14 +2117,12 @@ static void Grp_PutFormToCreateGroupType (void)
|
|||
Txt_The_groups_will_not_automatically_open,
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.MustBeOpened ? Txt_The_groups_will_automatically_open :
|
||||
Txt_The_groups_will_not_automatically_open);
|
||||
Dat_WriteFormDate (Gbl.Now.Date.Year,Gbl.Now.Date.Year + 1,"Open",
|
||||
&(Gbl.CurrentCrs.Grps.GrpTyp.OpenTime.Date),
|
||||
false,false);
|
||||
fprintf (Gbl.F.Out,"</td>"
|
||||
"<td class=\"LEFT_MIDDLE\">");
|
||||
Dat_WriteFormHourMinute ("OpenHour","OpenMinute",
|
||||
&(Gbl.CurrentCrs.Grps.GrpTyp.OpenTime.Time),
|
||||
false,false);
|
||||
Dat_WriteFormClientLocalDateTimeFromTimeUTC ("open_time",
|
||||
"Open",
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.OpenTimeUTC,
|
||||
Gbl.Now.Date.Year,
|
||||
Gbl.Now.Date.Year + 1,
|
||||
false,false);
|
||||
fprintf (Gbl.F.Out,"</td>"
|
||||
"</tr>"
|
||||
"</table>"
|
||||
|
@ -2244,7 +2249,7 @@ void Grp_GetListGrpTypesInThisCrs (Grp_WhichGroupTypes_t WhichGroupTypes)
|
|||
sprintf (Query,"SELECT crs_grp_types.GrpTypCod,crs_grp_types.GrpTypName,"
|
||||
"crs_grp_types.Mandatory,crs_grp_types.Multiple,"
|
||||
"crs_grp_types.MustBeOpened,"
|
||||
"DATE_FORMAT(crs_grp_types.OpenTime,'%%Y%%m%%d%%H%%i%%S'),"
|
||||
"UNIX_TIMESTAMP(crs_grp_types.OpenTime),"
|
||||
"COUNT(crs_grp.GrpCod)"
|
||||
" FROM crs_grp_types,crs_grp"
|
||||
" WHERE crs_grp_types.CrsCod='%ld'"
|
||||
|
@ -2257,7 +2262,7 @@ void Grp_GetListGrpTypesInThisCrs (Grp_WhichGroupTypes_t WhichGroupTypes)
|
|||
sprintf (Query,"(SELECT crs_grp_types.GrpTypCod,crs_grp_types.GrpTypName AS GrpTypName,"
|
||||
"crs_grp_types.Mandatory,crs_grp_types.Multiple,"
|
||||
"crs_grp_types.MustBeOpened,"
|
||||
"DATE_FORMAT(crs_grp_types.OpenTime,'%%Y%%m%%d%%H%%i%%S'),"
|
||||
"UNIX_TIMESTAMP(crs_grp_types.OpenTime),"
|
||||
"COUNT(crs_grp.GrpCod)"
|
||||
" FROM crs_grp_types,crs_grp"
|
||||
" WHERE crs_grp_types.CrsCod='%ld'"
|
||||
|
@ -2266,7 +2271,9 @@ void Grp_GetListGrpTypesInThisCrs (Grp_WhichGroupTypes_t WhichGroupTypes)
|
|||
" UNION "
|
||||
"(SELECT GrpTypCod,GrpTypName,"
|
||||
"Mandatory,Multiple,"
|
||||
"MustBeOpened,DATE_FORMAT(OpenTime,'%%Y%%m%%d%%H%%i%%S'),'0'"
|
||||
"MustBeOpened,"
|
||||
"UNIX_TIMESTAMP(OpenTime),"
|
||||
"'0'"
|
||||
" FROM crs_grp_types WHERE CrsCod='%ld'"
|
||||
" AND GrpTypCod NOT IN (SELECT GrpTypCod FROM crs_grp))"
|
||||
" ORDER BY GrpTypName",
|
||||
|
@ -2309,10 +2316,9 @@ void Grp_GetListGrpTypesInThisCrs (Grp_WhichGroupTypes_t WhichGroupTypes)
|
|||
/* Groups of this type must be opened? (row[4]) */
|
||||
Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumRow].MustBeOpened = (Str_ConvertToUpperLetter (row[4][0]) == 'Y');
|
||||
|
||||
/* Get open time (row[5] holds the open time in YYYYMMDDHHMMSS format) */
|
||||
if (!(Dat_GetDateTimeFromYYYYMMDDHHMMSS (&(Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumRow].OpenTime),row[5])))
|
||||
Lay_ShowErrorAndExit ("Error when reading open time.");
|
||||
Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumRow].MustBeOpened &= Grp_CheckIfOpenTimeInTheFuture (&(Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumRow].OpenTime));
|
||||
/* Get open time (row[5] holds the open time UTC) */
|
||||
Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumRow].OpenTimeUTC = Dat_GetUNIXTimeFromStr (row[5]);
|
||||
Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumRow].MustBeOpened &= Grp_CheckIfOpenTimeInTheFuture (Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumRow].OpenTimeUTC);
|
||||
|
||||
/* Number of groups of this type (row[6]) */
|
||||
if (sscanf (row[6],"%u",&Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumRow].NumGrps) != 1)
|
||||
|
@ -2545,7 +2551,7 @@ static void Grp_GetDataOfGroupTypeByCod (struct GroupType *GrpTyp)
|
|||
unsigned long NumRows;
|
||||
|
||||
/***** Get data of a type of group from database *****/
|
||||
sprintf (Query,"SELECT GrpTypName,Mandatory,Multiple,MustBeOpened,DATE_FORMAT(OpenTime,'%%Y%%m%%d%%H%%i%%S')"
|
||||
sprintf (Query,"SELECT GrpTypName,Mandatory,Multiple,MustBeOpened,UNIX_TIMESTAMP(OpenTime)"
|
||||
" FROM crs_grp_types"
|
||||
" WHERE CrsCod='%ld' AND GrpTypCod='%ld'",
|
||||
Gbl.CurrentCrs.Crs.CrsCod,GrpTyp->GrpTypCod);
|
||||
|
@ -2560,9 +2566,8 @@ static void Grp_GetDataOfGroupTypeByCod (struct GroupType *GrpTyp)
|
|||
strcpy (GrpTyp->GrpTypName,row[0]);
|
||||
GrpTyp->MandatoryEnrollment = (Str_ConvertToUpperLetter (row[1][0]) == 'Y');
|
||||
GrpTyp->MultipleEnrollment = (Str_ConvertToUpperLetter (row[2][0]) == 'Y');
|
||||
GrpTyp->MustBeOpened = (Str_ConvertToUpperLetter (row[3][0]) == 'Y');
|
||||
if (!(Dat_GetDateTimeFromYYYYMMDDHHMMSS (&(GrpTyp->OpenTime),row[4])))
|
||||
Lay_ShowErrorAndExit ("Error when reading open time.");
|
||||
GrpTyp->MustBeOpened = (Str_ConvertToUpperLetter (row[3][0]) == 'Y');
|
||||
GrpTyp->OpenTimeUTC = Dat_GetUNIXTimeFromStr (row[4]);
|
||||
|
||||
/***** Free structure that stores the query result *****/
|
||||
DB_FreeMySQLResult (&mysql_res);
|
||||
|
@ -2942,9 +2947,11 @@ void Grp_GetLstCodGrpsWithFileZonesIBelong (struct ListCodGrps *LstGrps)
|
|||
|
||||
/***** Get groups which I belong to from database *****/
|
||||
sprintf (Query,"SELECT crs_grp.GrpCod FROM crs_grp_types,crs_grp,crs_grp_usr"
|
||||
" WHERE crs_grp_types.CrsCod='%ld' AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
|
||||
" WHERE crs_grp_types.CrsCod='%ld'"
|
||||
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
|
||||
" AND crs_grp.FileZones='Y'"
|
||||
" AND crs_grp.GrpCod=crs_grp_usr.GrpCod AND crs_grp_usr.UsrCod='%ld'"
|
||||
" AND crs_grp.GrpCod=crs_grp_usr.GrpCod"
|
||||
" AND crs_grp_usr.UsrCod='%ld'"
|
||||
" ORDER BY crs_grp_types.GrpTypName,crs_grp.GrpName",
|
||||
Gbl.CurrentCrs.Crs.CrsCod,Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||
LstGrps->NumGrps = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get the groups which I belong to");
|
||||
|
@ -3000,8 +3007,11 @@ void Grp_GetNamesGrpsStdBelongsTo (long GrpTypCod,long UsrCod,char *GroupNames)
|
|||
|
||||
/***** Get the names of groups which a user belongs to, from database *****/
|
||||
sprintf (Query,"SELECT crs_grp.GrpName FROM crs_grp,crs_grp_usr"
|
||||
" WHERE crs_grp.GrpTypCod='%ld' AND crs_grp.GrpCod=crs_grp_usr.GrpCod AND crs_grp_usr.UsrCod='%ld'"
|
||||
" ORDER BY crs_grp.GrpName",GrpTypCod,UsrCod);
|
||||
" WHERE crs_grp.GrpTypCod='%ld'"
|
||||
" AND crs_grp.GrpCod=crs_grp_usr.GrpCod"
|
||||
" AND crs_grp_usr.UsrCod='%ld'"
|
||||
" ORDER BY crs_grp.GrpName",
|
||||
GrpTypCod,UsrCod);
|
||||
NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get the names of groups a user belongs to");
|
||||
|
||||
/***** Get the groups *****/
|
||||
|
@ -3046,15 +3056,8 @@ void Grp_RecFormNewGrpTyp (void)
|
|||
Gbl.CurrentCrs.Grps.GrpTyp.MultipleEnrollment = (Str_ConvertToUpperLetter (YN[0]) == 'Y');
|
||||
|
||||
/* Get open time */
|
||||
Dat_GetDateFromForm ("OpenDay","OpenMonth","OpenYear",
|
||||
&(Gbl.CurrentCrs.Grps.GrpTyp.OpenTime.Date.Day),
|
||||
&(Gbl.CurrentCrs.Grps.GrpTyp.OpenTime.Date.Month),
|
||||
&(Gbl.CurrentCrs.Grps.GrpTyp.OpenTime.Date.Year));
|
||||
Dat_GetHourMinuteFromForm ("OpenHour","OpenMinute",
|
||||
&(Gbl.CurrentCrs.Grps.GrpTyp.OpenTime.Time.Hour),
|
||||
&(Gbl.CurrentCrs.Grps.GrpTyp.OpenTime.Time.Minute));
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.OpenTime.Time.Second = 0;
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.MustBeOpened = Grp_CheckIfOpenTimeInTheFuture (&(Gbl.CurrentCrs.Grps.GrpTyp.OpenTime));
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.OpenTimeUTC = Dat_GetTimeUTCFromForm ("OpenTimeUTC");
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.MustBeOpened = Grp_CheckIfOpenTimeInTheFuture (Gbl.CurrentCrs.Grps.GrpTyp.OpenTimeUTC);
|
||||
|
||||
if (Gbl.CurrentCrs.Grps.GrpTyp.GrpTypName[0]) // If there's a group type name
|
||||
{
|
||||
|
@ -3082,16 +3085,14 @@ void Grp_RecFormNewGrpTyp (void)
|
|||
/**************** Check if the open time if in the future ********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
static bool Grp_CheckIfOpenTimeInTheFuture (struct DateTime *OpenTime)
|
||||
static bool Grp_CheckIfOpenTimeInTheFuture (time_t OpenTimeUTC)
|
||||
{
|
||||
/***** If any part of the date is 0 ==> groups must no be opened *****/
|
||||
if (OpenTime->Date.Year == 0 ||
|
||||
OpenTime->Date.Month == 0 ||
|
||||
OpenTime->Date.Day == 0)
|
||||
/***** If open time is 0 ==> groups must no be opened *****/
|
||||
if (OpenTimeUTC == (time_t) 0)
|
||||
return false;
|
||||
|
||||
/***** Is open time in the future? *****/
|
||||
return (Dat_CompareDateTimes (OpenTime,&(Gbl.Now)) >= 0);
|
||||
return (OpenTimeUTC > Gbl.TimeStartExecution);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -3180,7 +3181,7 @@ static void Grp_CreateGroupType (void)
|
|||
|
||||
/***** Create a new group type *****/
|
||||
sprintf (Query,"INSERT INTO crs_grp_types (CrsCod,GrpTypName,Mandatory,Multiple,MustBeOpened,OpenTime)"
|
||||
" VALUES ('%ld','%s','%c','%c','%c','%04u%02u%02u%02u%02u%02u')",
|
||||
" VALUES ('%ld','%s','%c','%c','%c',FROM_UNIXTIME('%ld'))",
|
||||
Gbl.CurrentCrs.Crs.CrsCod,Gbl.CurrentCrs.Grps.GrpTyp.GrpTypName,
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.MandatoryEnrollment ? 'Y' :
|
||||
'N',
|
||||
|
@ -3188,12 +3189,7 @@ static void Grp_CreateGroupType (void)
|
|||
'N',
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.MustBeOpened ? 'Y' :
|
||||
'N',
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.OpenTime.Date.Year,
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.OpenTime.Date.Month,
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.OpenTime.Date.Day,
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.OpenTime.Time.Hour,
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.OpenTime.Time.Minute,
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.OpenTime.Time.Second);
|
||||
(long) Gbl.CurrentCrs.Grps.GrpTyp.OpenTimeUTC);
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.GrpTypCod = DB_QueryINSERTandReturnCode (Query,"can not create type of group");
|
||||
|
||||
/***** Write success message *****/
|
||||
|
@ -3769,27 +3765,15 @@ void Grp_ChangeOpenTimeGrpTyp (void)
|
|||
Grp_GetDataOfGroupTypeByCod (&Gbl.CurrentCrs.Grps.GrpTyp);
|
||||
|
||||
/***** Get open time *****/
|
||||
Dat_GetDateFromForm ("OpenDay","OpenMonth","OpenYear",
|
||||
&(Gbl.CurrentCrs.Grps.GrpTyp.OpenTime.Date.Day),
|
||||
&(Gbl.CurrentCrs.Grps.GrpTyp.OpenTime.Date.Month),
|
||||
&(Gbl.CurrentCrs.Grps.GrpTyp.OpenTime.Date.Year));
|
||||
Dat_GetHourMinuteFromForm ("OpenHour","OpenMinute",
|
||||
&(Gbl.CurrentCrs.Grps.GrpTyp.OpenTime.Time.Hour),
|
||||
&(Gbl.CurrentCrs.Grps.GrpTyp.OpenTime.Time.Minute));
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.OpenTime.Time.Second = 0;
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.MustBeOpened = Grp_CheckIfOpenTimeInTheFuture (&(Gbl.CurrentCrs.Grps.GrpTyp.OpenTime));
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.OpenTimeUTC = Dat_GetTimeUTCFromForm ("OpenTimeUTC");
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.MustBeOpened = Grp_CheckIfOpenTimeInTheFuture (Gbl.CurrentCrs.Grps.GrpTyp.OpenTimeUTC);
|
||||
|
||||
/***** Update of the table of types of group changing the old open time of enrollment by the new *****/
|
||||
sprintf (Query,"UPDATE crs_grp_types SET MustBeOpened='%c',OpenTime='%04u%02u%02u%02u%02u%02u'"
|
||||
sprintf (Query,"UPDATE crs_grp_types SET MustBeOpened='%c',OpenTime=FROM_UNIXTIME('%ld')"
|
||||
" WHERE GrpTypCod='%ld'",
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.MustBeOpened ? 'Y' :
|
||||
'N',
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.OpenTime.Date.Year,
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.OpenTime.Date.Month,
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.OpenTime.Date.Day,
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.OpenTime.Time.Hour,
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.OpenTime.Time.Minute,
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.OpenTime.Time.Second,
|
||||
(long) Gbl.CurrentCrs.Grps.GrpTyp.OpenTimeUTC,
|
||||
Gbl.CurrentCrs.Grps.GrpTyp.GrpTypCod);
|
||||
DB_QueryUPDATE (Query,"can not update enrollment type of a type of group");
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ struct GroupType
|
|||
bool MandatoryEnrollment; // Enrollment is mandatory?
|
||||
bool MultipleEnrollment; // Enrollment is multiple?
|
||||
bool MustBeOpened; // Groups must be opened?
|
||||
struct DateTime OpenTime; // Open groups automatically in this date-time. If == 0, don't open.
|
||||
time_t OpenTimeUTC; // Open groups automatically in this date-time. If == 0, don't open.
|
||||
unsigned NumGrps; // Number of groups of this type
|
||||
struct Group *LstGrps; // List of groups of this type
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue