From 840b2a2344b1d447df0b159d4764681fdd8b3481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Fri, 30 Oct 2015 17:05:33 +0100 Subject: [PATCH] Version 15.31 --- js/swad.js | 115 +++++++++++++++++++++++++++++++++++++---------- swad_calendar.c | 99 +++++++++++++++------------------------- swad_changelog.h | 6 ++- swad_layout.c | 77 +++++++++++++++++++++++++++++++ 4 files changed, 208 insertions(+), 89 deletions(-) diff --git a/js/swad.js b/js/swad.js index 16a4d37c2..56f14eea1 100644 --- a/js/swad.js +++ b/js/swad.js @@ -656,21 +656,89 @@ function disableDetailedClicks () { } /*****************************************************************************/ -/******************************** Draw a month *******************************/ +/************************ Draw an academic calendar **************************/ +/*****************************************************************************/ + +function Cal_DrawCalendar (id,TimeUTC,PrintView,CGI,CurrentPlcCod,FormGoToCalendarParams,FormEventParams) + { + var StartingMonth = [ // Calendar starts one row before current month + 9, // January --> September + 9, // February --> September + 9, // Mars --> September + 9, // April --> September + 1, // May --> January + 1, // June --> January + 1, // July --> January + 1, // August --> January + 5, // September --> May + 5, // October --> May + 5, // November --> May + 5 // December --> May + ]; + var d = new Date; + d.setTime(TimeUTC * 1000); + var CurrentMonth = d.getMonth() + 1; + var CurrentYear = d.getFullYear(); + var CurrentDay = d.getDate(); + var Month = StartingMonth[CurrentMonth - 1]; + var Year = (Month < CurrentMonth) ? CurrentYear : + CurrentYear - 1; + var Row; + var Col; + var MonthIdNum = 0; + var MonthId; + + /***** Draw several months *****/ + HTMLContent += ''; + + for (Row = 0; + Row < 4; + Row++) + { + HTMLContent += ''; + for (Col = 0; + Col < 4; + Col++) + { + MonthIdNum++; + MonthId = id + '_month_' + MonthIdNum; + + HTMLContent += ''; + if (++Month == 13) + { + Month = 1; + Year++; + } + } + HTMLContent += ''; + } + HTMLContent += '
'; + DrawMonth (MonthId,Year,Month,CurrentMonth,CurrentDay,true,PrintView,CGI,CurrentPlcCod,FormGoToCalendarParams,FormEventParams); + HTMLContent += '
'; + + document.getElementById(id).innerHTML = HTMLContent; + } + +/*****************************************************************************/ +/***************************** Draw current month ****************************/ /*****************************************************************************/ function DrawCurrentMonth (id,TimeUTC,CGI,CurrentPlcCod,FormGoToCalendarParams,FormEventParams) { var d = new Date; - d.setTime(TimeUTC * 1000); - DrawMonth (id,d.getFullYear(),d.getMonth() + 1,d.getDate(),false,false,CGI,CurrentPlcCod,FormGoToCalendarParams,FormEventParams); + var Year = d.getFullYear(); + var Month = d.getMonth() + 1; + var CurrentDay = d.getDate(); + + DrawMonth (id,Year,Month,Month,CurrentDay,false,false,CGI,CurrentPlcCod,FormGoToCalendarParams,FormEventParams); + document.getElementById(id).innerHTML = HTMLContent; } /*****************************************************************************/ /******************************** Draw a month *******************************/ /*****************************************************************************/ -function DrawMonth (id,Year,Month,Today,DrawingCalendar,PrintView,CGI,CurrentPlcCod,FormGoToCalendarParams,FormEventParams) +function DrawMonth (id,YearToDraw,MonthToDraw,CurrentMonth,CurrentDay,DrawingCalendar,PrintView,CGI,CurrentPlcCod,FormGoToCalendarParams,FormEventParams) { var NumDaysMonth = [ 0, @@ -693,8 +761,8 @@ function DrawMonth (id,Year,Month,Today,DrawingCalendar,PrintView,CGI,CurrentPlc var DayOfWeek; /* 0, 1, 2, 3, 4, 5, 6 */ var Day; var NumDaysInMonth; - var Yea = Year; - var Mon = Month; + var Yea = YearToDraw; + var Mon = MonthToDraw; var YYYYMMDD; var NumHld; var ClassForDay; // Class of day depending on type of day @@ -734,14 +802,14 @@ function DrawMonth (id,Year,Month,Today,DrawingCalendar,PrintView,CGI,CurrentPlc } /***** Start of month *****/ - HTMLContent = '
'; + HTMLContent += '
'; /***** Month name *****/ if (DrawingCalendar) HTMLContent += '
'; else { - FormId = 'show_calendar'; + FormId = id + '_show_calendar'; HTMLContent += '
'; } - HTMLContent += MONTHS_CAPS[Month-1] + ' ' + Year; + HTMLContent += MONTHS_CAPS[MonthToDraw-1] + ' ' + YearToDraw; if (DrawingCalendar) HTMLContent += '
'; else @@ -785,8 +853,8 @@ function DrawMonth (id,Year,Month,Today,DrawingCalendar,PrintView,CGI,CurrentPlc DayOfWeek++) { /***** Set class for day being drawn *****/ - ClassForDay = ((Mon == Month) ? 'DAY_WRK' : - 'DAY_WRK_LIGHT'); + ClassForDay = ((Mon == MonthToDraw) ? 'DAY_WRK' : + 'DAY_WRK_LIGHT'); TextForDay = ''; /* Check if day is a holiday or a school day */ @@ -805,8 +873,8 @@ function DrawMonth (id,Year,Month,Today,DrawingCalendar,PrintView,CGI,CurrentPlc case Hld_HOLIDAY: if (Hlds[NumHld].StartDate == YYYYMMDD) // If start date == date being drawn { - ClassForDay = ((Mon == Month) ? 'DAY_HLD' : - 'DAY_HLD_LIGHT'); + ClassForDay = ((Mon == MonthToDraw) ? 'DAY_HLD' : + 'DAY_HLD_LIGHT'); TextForDay = Hlds[NumHld].Name; ContinueSearching = false; } @@ -814,8 +882,8 @@ function DrawMonth (id,Year,Month,Today,DrawingCalendar,PrintView,CGI,CurrentPlc case Hld_NON_SCHOOL_PERIOD: if (Hlds[NumHld].EndDate >= YYYYMMDD) // If start date <= date being drawn <= end date { - ClassForDay = ((Mon == Month) ? 'DAY_NO_WORK' : - 'DAY_NO_WORK_LIGHT'); + ClassForDay = ((Mon == MonthToDraw) ? 'DAY_NO_WORK' : + 'DAY_NO_WORK_LIGHT'); TextForDay = Hlds[NumHld].Name; } break; @@ -824,17 +892,18 @@ function DrawMonth (id,Year,Month,Today,DrawingCalendar,PrintView,CGI,CurrentPlc /* Day being drawn is sunday? */ if (DayOfWeek == 6) // All the sundays are holidays - ClassForDay = (Mon == Month) ? 'DAY_HLD' : - 'DAY_HLD_LIGHT'; + ClassForDay = (Mon == MonthToDraw) ? 'DAY_HLD' : + 'DAY_HLD_LIGHT'; /* Date being drawn is today? */ - IsToday = (Yea == Year && - Mon == Month && - Day == Today); + IsToday = (Yea == YearToDraw && + Mon == MonthToDraw && + Mon == CurrentMonth && + Day == CurrentDay); /* Check if day has an exam announcement */ ThisDayHasEvent = false; - if (!DrawingCalendar || Mon == Month) // If drawing calendar and the month is not the real one, don't draw exam announcements + if (!DrawingCalendar || Mon == MonthToDraw) // If drawing calendar and the month is not the real one, don't draw exam announcements for (NumExamAnnouncement = 0; NumExamAnnouncement < LstExamAnnouncements.length; NumExamAnnouncement++) @@ -863,7 +932,7 @@ function DrawMonth (id,Year,Month,Today,DrawingCalendar,PrintView,CGI,CurrentPlc if (!PrintView && ThisDayHasEvent) { FormIdNum++; - FormId = 'cal_event_' + FormIdNum; + FormId = id + '_event_' + FormIdNum; HTMLContent += '\n" - " var MONTHS_CAPS = ["); - for (Month = 0; - Month < 12; - Month++) - { - if (Month) - fprintf (Gbl.F.Out,","); - fprintf (Gbl.F.Out,"'%s'",Txt_MONTHS_CAPS[Month]); - } - fprintf (Gbl.F.Out,"];\n"); - - fprintf (Gbl.F.Out," var DAYS_CAPS = ["); - for (DayOfWeek = 0; - DayOfWeek < 7; - DayOfWeek++) - { - if (DayOfWeek) - fprintf (Gbl.F.Out,","); - fprintf (Gbl.F.Out,"'%c'",Txt_DAYS_CAPS[DayOfWeek][0]); - } - fprintf (Gbl.F.Out,"];\n"); - - fprintf (Gbl.F.Out," var STR_EXAM = '"); - fprintf (Gbl.F.Out,Txt_Exam_of_X,Gbl.CurrentCrs.Crs.FullName); - fprintf (Gbl.F.Out,"';"); - - fprintf (Gbl.F.Out," var Hlds = [];\n"); - for (NumHld = 0; - NumHld < Gbl.Hlds.Num; - NumHld++) - fprintf (Gbl.F.Out," Hlds.push({ PlcCod: %ld, HldTyp: %u, StartDate: %s, EndDate: %s, Name: '%s' });\n", - Gbl.Hlds.Lst[NumHld].PlcCod, - (unsigned) Gbl.Hlds.Lst[NumHld].HldTyp, - Gbl.Hlds.Lst[NumHld].StartDate.YYYYMMDD, - Gbl.Hlds.Lst[NumHld].EndDate.YYYYMMDD, - Gbl.Hlds.Lst[NumHld].Name); - - fprintf (Gbl.F.Out," var LstExamAnnouncements = [];\n"); - for (NumExamAnnouncement = 0; - NumExamAnnouncement < Gbl.LstExamAnnouncements.NumExamAnnounc; - NumExamAnnouncement++) - fprintf (Gbl.F.Out," LstExamAnnouncements.push({ Year: %u, Month: %u, Day: %u });\n", - Gbl.LstExamAnnouncements.Lst[NumExamAnnouncement].Year, - Gbl.LstExamAnnouncements.Lst[NumExamAnnouncement].Month, - Gbl.LstExamAnnouncements.Lst[NumExamAnnouncement].Day); - - fprintf (Gbl.F.Out," DrawCurrentMonth ('CurrentMonth',%ld,'%s/%s',%ld,", + " var HTMLContent = '';\n" + " DrawCurrentMonth ('CurrentMonth',%ld,'%s/%s',%ld,", (long) Gbl.StartExecutionTimeUTC, Cfg_HTTPS_URL_SWAD_CGI,Txt_STR_LANG_ID[Gbl.Prefs.Language], Gbl.CurrentCtr.Ctr.PlcCod); @@ -166,6 +114,7 @@ void Cal_DrawCurrentMonth (void) void Cal_DrawCalendar (void) { extern const char *Txt_Print; + /* static unsigned StartingMonth[1+12] = // Calendar starts one row before current month { 0, // Not used @@ -176,18 +125,22 @@ void Cal_DrawCalendar (void) 1, // May --> January 1, // June --> January 1, // July --> January - 1, // Agoust --> January + 1, // August --> January 5, // September --> May 5, // October --> May 5, // November --> May 5, // December --> May }; - unsigned Row,Col; - unsigned Month = StartingMonth[Gbl.Now.Date.Month]; - unsigned Year = (Month < Gbl.Now.Date.Month) ? Gbl.Now.Date.Year : - Gbl.Now.Date.Year - 1; + */ + // unsigned Row,Col; + // unsigned Month = StartingMonth[Gbl.Now.Date.Month]; + // unsigned Year = (Month < Gbl.Now.Date.Month) ? Gbl.Now.Date.Year : + // Gbl.Now.Date.Year - 1; bool PrintView = (Gbl.CurrentAct == ActPrnCal); + extern const char *Txt_STR_LANG_ID[Txt_NUM_LANGUAGES]; + char Params[256+256+Ses_LENGTH_SESSION_ID+256]; + /***** Get list of holidays *****/ if (!Gbl.Hlds.LstIsRead) { @@ -195,6 +148,9 @@ void Cal_DrawCalendar (void) Hld_GetListHolidays (); } + /***** Create list of calls for examination *****/ + Exa_CreateListOfExamAnnouncements (); + /***** Start of table and title *****/ if (!PrintView) { @@ -209,13 +165,14 @@ void Cal_DrawCalendar (void) Gbl.CurrentDeg.Deg.DegCod, Gbl.CurrentCrs.Crs.CrsCod); - /***** Create list of calls for examination *****/ - Exa_CreateListOfExamAnnouncements (); - /***** Draw several months *****/ + /* JavaScript will write HTML here */ fprintf (Gbl.F.Out,"" "" - ""); + "
" + "
"); + + /* for (Row = 0; Row < 4; Row++) @@ -239,6 +196,22 @@ void Cal_DrawCalendar (void) fprintf (Gbl.F.Out,"
" "" ""); + */ + /* Write script to draw the month */ + fprintf (Gbl.F.Out,"\n",Params); + + fprintf (Gbl.F.Out,""); /***** Free list of dates of exam announcements *****/ Exa_FreeListExamAnnouncements (); diff --git a/swad_changelog.h b/swad_changelog.h index d2665612a..881f2a7d5 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -103,17 +103,19 @@ // TODO: Put headers Content-type and Content-disposition when redirecting with Location: // TODO: System admin should be able to remove/edit user's mail (when he/she detects a recipient does not exists, for example) // TODO: When a new assignment/attendance/survey is incorrect, the second time the form is shown, it should be filled with partial data, now is always empty +// TODO: Dates in Holidays should be shown in big-endian /*****************************************************************************/ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 15.30 (2015/10/30)" +#define Log_PLATFORM_VERSION "SWAD 15.31 (2015/10/30)" // 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.30: Oct 30, 2015 Current month is drown in browser using JavaScript. (186795 lines) + Version 15.31: Oct 30, 2015 Calendar is drawn in browser using JavaScript. (186902 lines) + Version 15.30: Oct 30, 2015 Current month is drawn in browser using JavaScript. (186795 lines) Version 15.29.4: Oct 29, 2015 Writing JavaScript function to draw a month in browser. Not finished. (186729 lines) Version 15.29.3: Oct 29, 2015 Writing JavaScript function to draw a month in browser. Not finished. (186703 lines) Version 15.29.2: Oct 29, 2015 Writing JavaScript function to draw a month in browser. Not finished. (186694 lines) diff --git a/swad_layout.c b/swad_layout.c index f264b3bdd..9363e0398 100644 --- a/swad_layout.c +++ b/swad_layout.c @@ -444,6 +444,15 @@ static void Lay_WriteRedirectionToMyLanguage (void) static void Lay_WriteScripts (void) { + extern const char *Txt_MONTHS_CAPS[12]; + extern const char *Txt_DAYS_CAPS[7]; + extern const char *Txt_Exam_of_X; + unsigned Month; + unsigned DayOfWeek; /* 0, 1, 2, 3, 4, 5, 6 */ + unsigned NumHld; + unsigned NumExamAnnouncement; // Number of exam announcement + char Params[256+256+Ses_LENGTH_SESSION_ID+256]; + /***** General scripts for swad *****/ fprintf (Gbl.F.Out,"\n", @@ -481,6 +490,74 @@ static void Lay_WriteScripts (void) Lay_WriteScriptConnectedUsrs (); } + /***** Prepare script to draw months *****/ + if ((Gbl.Prefs.Layout == Lay_LAYOUT_DESKTOP && + (Gbl.Prefs.SideCols & Lay_SHOW_LEFT_COLUMN)) || // Left column visible + Gbl.CurrentAct == ActSeeCal || + Gbl.CurrentAct == ActPrnCal) + { + /***** Get list of holidays *****/ + if (!Gbl.Hlds.LstIsRead) + { + Gbl.Hlds.SelectedOrderType = Hld_ORDER_BY_START_DATE; + Hld_GetListHolidays (); + } + + /***** Create list of calls for examination *****/ + Exa_CreateListOfExamAnnouncements (); + + /***** Write script to initialize variables used to draw months *****/ + fprintf (Gbl.F.Out,"\n"); + } + /***** Scripts depending on action *****/ switch (Gbl.CurrentAct) {