October
10, // February --> October
10, // Mars --> October
1, // April --> January
1, // May --> January
1, // June --> January
4, // July --> April
4, // August --> April
4, // September --> April
7, // October --> July
7, // November --> July
7 // December --> July
]; */
var StartingMonth = [ // Calendar starts one row before current month
2, // January --> February
3, // February --> Mars
4, // Mars --> April
5, // April --> May
6, // May --> June
7, // June --> July
8, // July --> August
9, // August --> September
10, // September --> October
11, // October --> November
12, // November --> December
1 // December --> January
];
var d = new Date();
d.setTime(TimeUTC * 1000);
var CurrentYear = d.getFullYear();
var CurrentMonth = d.getMonth() + 1;
var CurrentDay = d.getDate();
var Month = StartingMonth[CurrentMonth - 1];
var Year = (Month < CurrentMonth) ? CurrentYear :
CurrentYear - 1;
var i;
var MonthIdNum = 0;
var MonthId;
/***** Draw several months *****/
for (i = 0;
i < 24;
i++) {
MonthIdNum++;
MonthId = id + '_month_' + MonthIdNum;
Gbl_HTMLContent += '';
DrawMonth (MonthId,FirstDayOfWeek,
Year,Month,
CurrentYear,CurrentMonth,CurrentDay,
CurrentPlcCod,true,PrintView,ColorSuffix,
CGI,FormGoToCalendarParams,FormEventParams);
Gbl_HTMLContent += '
';
if (++Month == 13) {
Month = 1;
Year++;
}
}
document.getElementById(id).innerHTML = Gbl_HTMLContent;
}
/*****************************************************************************/
/***************************** Draw current month ****************************/
/*****************************************************************************/
function DrawCurrentMonth (id,FirstDayOfWeek,TimeUTC,CurrentPlcCod,ColorSuffix,
CGI,FormGoToCalendarParams,FormEventParams) {
var d = new Date();
d.setTime(TimeUTC * 1000);
var Year = d.getFullYear();
var Month = d.getMonth() + 1;
var CurrentDay = d.getDate();
DrawMonth (id,FirstDayOfWeek,
Year,Month,
Year,Month,CurrentDay,
CurrentPlcCod,false,false,ColorSuffix,
CGI,FormGoToCalendarParams,FormEventParams);
document.getElementById(id).innerHTML = Gbl_HTMLContent;
}
/*****************************************************************************/
/******************************* Draw a month ********************************/
/*****************************************************************************/
// FirstDayOfWeek == 0 ==> Weeks from Monday to Sunday
// FirstDayOfWeek == 6 ==> Weeks from Sunday to Saturday
function DrawMonth (id,FirstDayOfWeek,
YearToDraw,MonthToDraw,
CurrentYear,CurrentMonth,CurrentDay,
CurrentPlcCod,DrawingCalendar,PrintView,ColorSuffix,
CGI,FormGoToCalendarParams,FormEventParams) {
var Hld_HOLIDAY = 0;
var Hld_NON_SCHOOL_PERIOD = 1;
var Yea = YearToDraw;
var Mon = MonthToDraw;
var Day;
var ExaCod;
var StrMon;
var StrDay;
var StrDat;
var Week;
var DayOfWeek; /* 0, 1, 2, 3, 4, 5, 6 */
var NumDaysInMonth;
var YYYYMMDD;
var NumHld;
var ClassForDay; // Class of day depending on type of day
var TextForDay; // Text associated to a day, for example the name of the holiday
var NumExamAnnouncement; // Number of exam announcement
var ResultOfCmpStartDate;
var ContinueSearching;
var ThisDayHasEvent;
var IsToday;
var FormIdNum = 0;
var FormId;
/***** Compute number of day of month for the first box *****/
/* The initial day of month can be -5, -4, -3, -2, -1, 0, or 1
If it's -5 then write 6 boxes of the previous month.
If it's -4 then write 5 boxes of the previous month.
If it's -3 then write 4 boxes of the previous month.
If it's -2 then write 3 boxes of the previous month.
If it's -1 then write 2 boxes of the previous month.
If it's 0 then write 1 box of the previous month.
If it's 1 then write 0 boxes of the previous month. */
if ((DayOfWeek = (GetDayOfWeekMondayFirst (Yea,Mon,1) + 7 - FirstDayOfWeek) % 7) == 0)
Day = 1;
else {
if (Mon <= 1) {
Mon = 12;
Yea--;
} else
Mon--;
NumDaysInMonth = daysInMonth (Mon,Yea);
Day = NumDaysInMonth - DayOfWeek + 1;
}
/***** Start of month *****/
Gbl_HTMLContent += '';
/***** Month name *****/
if (DrawingCalendar)
Gbl_HTMLContent += '
';
else {
FormId = id + '_show_calendar';
Gbl_HTMLContent += '
';
/***** Month head: first letter for each day of week *****/
Gbl_HTMLContent += '
' + '';
for (DayOfWeek = 0; DayOfWeek < 7; DayOfWeek++)
Gbl_HTMLContent += '' +
DAYS2[(DayOfWeek + FirstDayOfWeek) % 7] +
' | ';
Gbl_HTMLContent += '
';
/***** Draw every week of the month *****/
for (Week = 0;
Week < 6;
Week++) {
Gbl_HTMLContent += '';
/***** Draw every day of the week *****/
for (DayOfWeek = 0;
DayOfWeek < 7;
DayOfWeek++) {
/***** Set class for day being drawn *****/
ClassForDay = ((Mon == MonthToDraw) ? 'DAY_WRK_' + ColorSuffix :
'DAY_WRK_LIGHT_' + ColorSuffix);
TextForDay = '';
/* Check if day is a holiday or a school day */
YYYYMMDD = Yea * 10000 + Mon * 100 + Day;
for (NumHld = 0, ContinueSearching = true;
NumHld < Hlds.length && ContinueSearching;
NumHld++)
if (Hlds[NumHld].PlcCod <= 0 ||
Hlds[NumHld].PlcCod == CurrentPlcCod) {
if (Hlds[NumHld].StartDate > YYYYMMDD) // List is ordered by start date. If start date is greater than date being drawn, don't continue searching
ContinueSearching = false;
else
// start date <= date being drawn
switch (Hlds[NumHld].HldTyp) {
case Hld_HOLIDAY:
if (Hlds[NumHld].StartDate == YYYYMMDD) { // If start date == date being drawn
ClassForDay = ((Mon == MonthToDraw) ? 'DAY_HLD_' + ColorSuffix :
'DAY_HLD_LIGHT_' + ColorSuffix);
TextForDay = Hlds[NumHld].Name;
ContinueSearching = false;
}
break;
case Hld_NON_SCHOOL_PERIOD:
if (Hlds[NumHld].EndDate >= YYYYMMDD) { // If start date <= date being drawn <= end date
ClassForDay = ((Mon == MonthToDraw) ? 'DAY_NO_WORK_' + ColorSuffix :
'DAY_NO_WORK_LIGHT_' + ColorSuffix);
TextForDay = Hlds[NumHld].Name;
}
break;
}
}
/* Day being drawn is sunday? */
if (DayOfWeek == 6 - FirstDayOfWeek) // All the sundays are holidays
ClassForDay = (Mon == MonthToDraw) ? 'DAY_HLD_' + ColorSuffix :
'DAY_HLD_LIGHT_' + ColorSuffix;
/* Date being drawn is today? */
IsToday = (Yea == YearToDraw &&
Mon == MonthToDraw &&
Yea == CurrentYear &&
Mon == CurrentMonth &&
Day == CurrentDay);
/* Check if day has a call for exam */
ThisDayHasEvent = false;
if (!DrawingCalendar || Mon == MonthToDraw) // If drawing calendar and the month is not the real one, don't draw call for exams
for (NumExamAnnouncement = 0;
NumExamAnnouncement < LstExamAnnouncements.length;
NumExamAnnouncement++)
if (Yea == LstExamAnnouncements[NumExamAnnouncement].Year &&
Mon == LstExamAnnouncements[NumExamAnnouncement].Month &&
Day == LstExamAnnouncements[NumExamAnnouncement].Day) {
ThisDayHasEvent = true;
if (!PrintView) {
ExaCod = LstExamAnnouncements[NumExamAnnouncement].ExaCod;
StrMon = ((Mon < 10) ? '0' : '') + Mon;
StrDay = ((Day < 10) ? '0' : '') + Day;
StrDat = Yea + StrMon + StrDay; // YYYYMMDD
TextForDay = STR_EXAM;
}
break; // Only last exam in the day (list is ordered from more recent to older)
}
/***** Write the box with the day *****/
Gbl_HTMLContent += '';
/* If day has an exam announcement */
if (!PrintView && ThisDayHasEvent) {
FormIdNum++;
FormId = id + '_event_' + FormIdNum;
Gbl_HTMLContent += ' | ';
/***** Set the next day *****/
NumDaysInMonth = daysInMonth (Mon,Yea);
if (++Day > NumDaysInMonth) {
if (++Mon > 12) {
Yea++;
Mon = 1;
}
Day = 1;
}
}
Gbl_HTMLContent += '
';
}
/***** End of month *****/
Gbl_HTMLContent += '
';
}
/*****************************************************************************/
/** Compute day of the week from a given date (first day of a week: monday) **/
/*****************************************************************************/
// Return 0 for monday, 1 for tuesday,... 6 for sunday
function GetDayOfWeekMondayFirst (Year,Month,Day) {
if (Month <= 2) {
Month += 12;
Year--;
}
return (((Day +
(Month * 2) +
Math.floor (((Month + 1) * 3) / 5) +
Year +
Math.floor (Year / 4) -
Math.floor (Year/100) +
Math.floor (Year/400) +
2) % 7) + 5) % 7;
}
/*****************************************************************************/
/************* Copy message subject and content to hidden fields *************/
/*****************************************************************************/
function CopyMessageToHiddenFields () {
var Subject = document.getElementById('MsgSubject');
var Content = document.getElementById('MsgContent');
var Subjects = document.getElementsByName("HiddenSubject");
var Contents = document.getElementsByName("HiddenContent");
var i;
if (Subject)
for (i = 0; i < Subjects.length; i++)
if (Subjects[i].type == "hidden")
Subjects[i].value = Subject.value;
if (Content)
for (i = 0; i < Contents.length; i++)
if (Contents[i].type == "hidden")
Contents[i].value = Content.value;
}
/*****************************************************************************/
/************************ Expand / contract a folder *************************/
/*****************************************************************************/
/*
Example of rows:
idParent = 'file_browser_1_1_2_1'
Children ids:
idRow = 'file_browser_1_1_2_1_1'
idRow = 'file_browser_1_1_2_1_2'
idRow = 'file_browser_1_1_2_1_2_1'
*/
function ExpandFolder (idParent) {
var parent = document.getElementById(idParent);
var iconToExpand = document.getElementById('expand_' + idParent);
var iconToContract = document.getElementById('contract_' + idParent);
var iconFolderClosed = document.getElementById('folder_closed_' + idParent);
var iconFolderOpen = document.getElementById('folder_open_' + idParent);
if (parent.dataset.folder == 'contracted') {
ExpandChildren (idParent);
parent.dataset.folder = 'expanded';
iconToExpand.style.display = 'none';
iconToContract.style.display = '';
iconFolderClosed.style.display = 'none';
iconFolderOpen.style.display = '';
}
}
function ExpandChildren (idParent) {
var parent = document.getElementById(idParent);
var rows = document.getElementsByTagName('tr');
var lengthIdParent = idParent.length;
var i;
var row;
var idRow;
var filename;
for (i = 0; i < rows.length; i++) {
row = rows[i];
if (row != parent) {
idRow = row.id;
if (idRow.indexOf(idParent + '_') == 0) { // row.id starts by idParent_, so it's a child
/* Get filename */
filename = idRow.substring(lengthIdParent + 1);
if (filename.indexOf("_") < 0) { // this child hangs directly from parent
/* Unhide row */
row.style.display = ''; // unhide
/* Expand children */
if (row.dataset.folder == 'expanded') // this child is an expanded folder
ExpandChildren (idRow); // recursive call
}
}
}
}
}
function ContractFolder (idParent) {
var parent = document.getElementById(idParent);
var iconToExpand = document.getElementById('expand_' + idParent);
var iconToContract = document.getElementById('contract_' + idParent);
var iconFolderClosed = document.getElementById('folder_closed_' + idParent);
var iconFolderOpen = document.getElementById('folder_open_' + idParent);
if (parent.dataset.folder == 'expanded') {
ContractChildren (idParent);
parent.dataset.folder = 'contracted';
iconToContract.style.display = 'none';
iconToExpand.style.display = '';
iconFolderOpen.style.display = 'none';
iconFolderClosed.style.display = '';
}
}
function ContractChildren (idParent) {
var parent = document.getElementById(idParent);
var rows = document.getElementsByTagName('tr');
var i;
var row;
var idRow;
for (i = 0; i < rows.length; i++) {
row = rows[i];
if (row != parent) {
idRow = row.id;
if (idRow.indexOf(idParent + '_') == 0) // row.id starts by idParent_, so it's a child
/* Hide row */
row.style.display = 'none'; // hide
}
}
}