From abc03e633c369c1a9c3f3c0eebecf466ad9a24bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Thu, 29 Oct 2015 14:56:01 +0100 Subject: [PATCH] Version 15.29 --- js/swad.js | 282 +++++++++++++++++++++++++++++++++++++++++++++++ swad_calendar.c | 10 +- swad_changelog.h | 3 +- swad_date.c | 1 + 4 files changed, 294 insertions(+), 2 deletions(-) diff --git a/js/swad.js b/js/swad.js index 505128e8e..17c040ba5 100644 --- a/js/swad.js +++ b/js/swad.js @@ -654,3 +654,285 @@ function disableDetailedClicks () { document.getElementById('GroupedBy').disabled = false; document.getElementById('RowsPage').disabled = true; } + +/*****************************************************************************/ +/******************************** Draw a month *******************************/ +/*****************************************************************************/ + +function DrawMonth (id,RealYear,RealMonth) + { + var MONTHS_CAPS = [ + 'ENERO', + 'FEBRERO', + 'MARZO', + 'ABRIL', + 'MAYO', + 'JUNIO', + 'JULIO', + 'AGOSTO', + 'SEPTIEMBRE', + 'OCTUBRE', + 'NOVIEMBRE', + 'DICIEMBRE' + ]; + var DAYS_CAPS = [ + 'L', + 'M', + 'M', + 'J', + 'V', + 'S', + 'D' + ]; + var NumDaysMonth = [ + 0, + 31, // 1: January + 28, // 2: February + 31, // 3: Mars + 30, // 4: April + 31, // 5: May + 30, // 6: June + 31, // 7: July + 31, // 8: Agoust + 30, // 9: September + 31, // 10: October + 30, // 11: November + 31, // 12: December + ]; + // var StrExamOfX; + var Week; + var DayOfWeek; /* 0, 1, 2, 3, 4, 5, 6 */ + var DayOfMonth; + var NumDaysInMonth; + var Year = RealYear; + var Month = RealMonth; + // 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 = false; + var IsToday; + + /***** 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 = GetDayOfWeek (Year,Month,1)) == 0) + DayOfMonth = 1; + else + { + if (Month <= 1) + { + Month = 12; + Year--; + } + else + Month--; + NumDaysInMonth = (Month == 2) ? GetNumDaysFebruary (Year) : + NumDaysMonth[Month]; + DayOfMonth = NumDaysInMonth - DayOfWeek + 1; + } + + /***** Start of month *****/ + HTMLContent = '
'; + + /***** Month name *****/ + HTMLContent += '
' + + MONTHS_CAPS[RealMonth-1] + ' ' + RealYear + + '
'; + + /***** Month head: first letter for each day of week *****/ + HTMLContent += '' + HTMLContent += ''; + for (DayOfWeek = 0; + DayOfWeek < 7; + DayOfWeek++) + HTMLContent += ''; + HTMLContent += ''; + + /***** Draw every week of the month *****/ + for (Week = 0; + Week < 6; + Week++) + { + HTMLContent += ''; + + /***** Draw every day of the week *****/ + for (DayOfWeek = 0; + DayOfWeek < 7; + DayOfWeek++) + { + /***** Set class for day being drawn *****/ + ClassForDay = (Month == RealMonth) ? 'DAY_WRK' : + 'DAY_WRK_LIGHT'; + /* Day being drawn is sunday? */ + if (DayOfWeek == 6) // All the sundays are holidays + ClassForDay = (Month == RealMonth) ? 'DAY_HLD' : + 'DAY_HLD_LIGHT'; + + /* Date being drawn is today? */ + /* + IsToday = (Gbl.CurrentAct != ActPrnCal && Month == RealMonth && + Year == Gbl.Now.Date.Year && + Month == Gbl.Now.Date.Month && + DayOfMonth == Gbl.Now.Date.Day); + */ + IsToday = false; + + /* Check if day has an exam announcement */ + /* + ThisDayHasEvent = false; + if (!DrawingCalendar || Month == RealMonth) // If drawing calendar and the month is not the real one, don't draw exam announcements + for (NumExamAnnouncement = 0; + NumExamAnnouncement < Gbl.LstExamAnnouncements.NumExamAnnounc; + NumExamAnnouncement++) + if (Year == Gbl.LstExamAnnouncements.Lst[NumExamAnnouncement].Year && + Month == Gbl.LstExamAnnouncements.Lst[NumExamAnnouncement].Month && + DayOfMonth == Gbl.LstExamAnnouncements.Lst[NumExamAnnouncement].Day) + { + ThisDayHasEvent = true; + if (PutLinkToEvents) + { + sprintf (StrExamOfX,Txt_Exam_of_X,Gbl.CurrentCrs.Crs.FullName); + sprintf (Gbl.Title,"%s: %02u/%02u/%04u", + StrExamOfX, + Gbl.LstExamAnnouncements.Lst[NumExamAnnouncement].Day, + Gbl.LstExamAnnouncements.Lst[NumExamAnnouncement].Month, + Gbl.LstExamAnnouncements.Lst[NumExamAnnouncement].Year); + } + break; + } + */ + + /***** Write the box with the day *****/ + HTMLContent += ''; + + /***** Set the next day *****/ + NumDaysInMonth = (Month == 2) ? GetNumDaysFebruary (Year) : + NumDaysMonth[Month]; + if (++DayOfMonth > NumDaysInMonth) + { + if (++Month > 12) + { + Year++; + Month = 1; + } + DayOfMonth = 1; + } + } + HTMLContent += ''; + } + + /***** End of month *****/ + HTMLContent += '
' + DAYS_CAPS[DayOfWeek] + '
'; + + /* If day has an exam announcement */ + /* if (PutLinkToEvents && ThisDayHasEvent) + { + Act_FormStart (ActSeeExaAnn); + fprintf (Gbl.F.Out,"" + "" + "" + "" + "
", + ClassForDay); + Act_LinkFormSubmit (Gbl.Title,ClassForDay); + } + else + { + */ + HTMLContent += '
" + "
"); + Act_FormEnd (); + } + else + */ + HTMLContent += ''; + + HTMLContent += '
'; + + document.getElementById(id).innerHTML = HTMLContent; + } + +/*****************************************************************************/ +/***************** Compute day of the week from a given date *****************/ +/*****************************************************************************/ +// Return 0 for monday, 1 for tuesday,... 6 for sunday + +function GetDayOfWeek (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; + } + +/*****************************************************************************/ +/****************** Return the number of days of february ********************/ +/*****************************************************************************/ + +function GetNumDaysFebruary (Year) + { + return (GetIfLeapYear (Year) ? 29 : + 28); + } + +/*****************************************************************************/ +/************************* Return true if year is leap ***********************/ +/*****************************************************************************/ + +function GetIfLeapYear (Year) + { + return (Year % 4 == 0) && ((Year % 100 != 0) || (Year % 400 == 0)); + } diff --git a/swad_calendar.c b/swad_calendar.c index e0ccdfd5a..a1ae79fc9 100644 --- a/swad_calendar.c +++ b/swad_calendar.c @@ -66,6 +66,14 @@ void Cal_DrawCurrentMonth (void) /***** Draw the month *****/ Cal_DrawMonth (Gbl.Now.Date.Year,Gbl.Now.Date.Month,false,true,false); + fprintf (Gbl.F.Out,"
" + "
" + "", + Gbl.Now.Date.Year, + Gbl.Now.Date.Month); + /***** Free list of dates of exam announcements *****/ Exa_FreeListExamAnnouncements (); } @@ -188,7 +196,7 @@ static void Cal_DrawMonth (unsigned RealYear,unsigned RealMonth, extern const char *Txt_Exam_of_X; char StrExamOfX[512+Crs_MAX_LENGTH_COURSE_FULL_NAME]; unsigned Week; - unsigned DayOfWeek; /* 0, 1, 2, 3, 4, 5 ó 6 */ + unsigned DayOfWeek; /* 0, 1, 2, 3, 4, 5, 6 */ unsigned DayOfMonth; unsigned NumDaysInMonth; unsigned Year = RealYear; diff --git a/swad_changelog.h b/swad_changelog.h index b8e1295c3..d0e1193f6 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -108,11 +108,12 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 15.28.1 (2015/10/28)" +#define Log_PLATFORM_VERSION "SWAD 15.29 (2015/10/29)" // 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.29: Oct 29, 2015 Writing JavaScript function to draw a month in browser. Not finished. (186684 lines) Version 15.28.1: Oct 28, 2015 Fixed bug in the calculation of some statistics. (186416 lines) Version 15.28: Oct 28, 2015 IANA zone names are used in the calculation of some statistics. (186407 lines) 1 change necessary in database: diff --git a/swad_date.c b/swad_date.c index 90eaa65e2..7cdc385fc 100644 --- a/swad_date.c +++ b/swad_date.c @@ -503,6 +503,7 @@ void Dat_GetBrowserTimeZone (char BrowserTimeZone[Dat_MAX_BYTES_TIME_ZONE+1]) // - http://pellepim.bitbucket.org/jstz/ // - https://bitbucket.org/pellepim/jstimezonedetect/ // The return value is an IANA zone info key (aka the Olson time zone database). + // https://en.wikipedia.org/wiki/List_of_tz_database_time_zones // For example, if browser is in Madrid(Spain) timezone, "Europe/Berlin" will be returned. Par_GetParToText ("BrowserTZName",BrowserTimeZone,Dat_MAX_BYTES_TIME_ZONE);