// ========== Language =========== // Day, Month var curr_url = $(location).attr('href'); var lang_url = curr_url.split("/",7); if(lang_url[6]=='TH-TH'){ var wordMonth = new Array("มกราคม", "กุมภาพันธ์", "มีนาคม", "เมษายน", "พฤษภาคม", "มิถุนายน", "กรกฎาคม", "สิงหาคม", "กันยายน", "ตุลาคม", "พฤศจิกายน", "ธันวาคม"); var wordDay_sun = "อา"; var wordDay_mon = "จ"; var wordDay_tue = "อ"; var wordDay_wed = "พ"; var wordDay_thu = "พฤ"; var wordDay_fri = "ศ"; var wordDay_sat = "ส"; }else{ var wordMonth = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); var wordDay_sun = "Sun"; var wordDay_mon = "Mon"; var wordDay_tue = "Tue"; var wordDay_wed = "Wed"; var wordDay_thu = "Thu"; var wordDay_fri = "Fri"; var wordDay_sat = "Sat"; } // =============================== // Global Variable var tiva_timetables = []; var gettiva_timetables = []; var tiva_current_date = new Date(); var tiva_current_month = tiva_current_date.getMonth() + 1; var tiva_current_year = tiva_current_date.getFullYear(); function sortByTime(a,b) { if (a.start_time < b.start_time) { return -1; } else if (a.start_time > b.start_time) { return 1; } else { return 0; } } function sortByEndTime(a,b) { if (a.end_time < b.end_time) { return -1; } else if (a.end_time > b.end_time) { return 1; } else { return 0; } } function getMinTime(timetables) { for (var i = 0; i < timetables.length; i++) { if (timetables[i].start_time) { return parseInt(timetables[i].start_time, 10); } } } function getMaxTime(timetables) { timetables.sort(sortByEndTime); for (var i = timetables.length-1; i >= 0; i--) { if (timetables[i].end_time) { var time = timetables[i].end_time.split(':'); if (time[1] == '00') { return time[0]; } else { return parseInt(time[0], 10) + 1; } } } } function calHour(time) { var t = time.split(':'); return parseInt(t[0], 10) + (t[1] / 60); } function getPosition(axis, start_time) { return parseInt((calHour(start_time) - axis) * 55, 10); // 1 cell top = 55px; } function getHeight(start_time, end_time) { return parseInt((calHour(end_time) - calHour(start_time)) * 55, 10); // 1 cell = 55px; } function checkMulti(timetable, timetables) { var count = 1; for (var i = 0; i < timetables.length; i++) { if (timetable.id != timetables[i].id) { if (((calHour(timetable.start_time) >= calHour(timetables[i].start_time)) && (calHour(timetable.start_time) < calHour(timetables[i].end_time))) || ((calHour(timetables[i].start_time) >= calHour(timetable.start_time)) && (calHour(timetables[i].start_time) < calHour(timetable.end_time)))) { count++; } } } return count; } function checkOrder(timetable, timetables) { var order = 0; for (var i = 0; i < timetables.length; i++) { if (timetable.id > timetables[i].id) { if (((calHour(timetable.start_time) >= calHour(timetables[i].start_time)) && (calHour(timetable.start_time) < calHour(timetables[i].end_time))) || ((calHour(timetables[i].start_time) >= calHour(timetable.start_time)) && (calHour(timetables[i].start_time) < calHour(timetable.end_time)))) { order++; } } } return order; } function getDayBefore(day, num) { var d = new Date(); return new Date(d.setTime(day.getTime() - (num * 24 * 60 * 60 * 1000))); } function getDayAfter(day, num) { var d = new Date(); return new Date(d.setTime(day.getTime() + (num * 24 * 60 * 60 * 1000))); } function naviClick(id, btn, weekNum, monthNum, yearNum) { createTimetable(jQuery('#' + id), btn, weekNum, monthNum, yearNum); } // Get timetables of day function getTimetables(tiva_timetables, day, month, year) { var timetables = []; for (var i = 0; i < tiva_timetables.length; i++) { if ((tiva_timetables[i].date == day) && (tiva_timetables[i].month == month) && (tiva_timetables[i].year == year)) { timetables.push(tiva_timetables[i]); } } return timetables; } // Get timetables of day function getTimetablesDay(tiva_timetables, day) { var timetables = []; for (var i = 0; i < tiva_timetables.length; i++) { if (tiva_timetables[i].day == day) { timetables.push(tiva_timetables[i]); } } return timetables; } // Get timetables of week function getTimetablesWeek(tiva_timetables, first_day, last_day) { var date_check; var timetables = []; for (var i = 0; i < tiva_timetables.length; i++) { date_check = new Date(tiva_timetables[i].year, Number(tiva_timetables[i].month) - 1, tiva_timetables[i].date); if ((first_day.getTime() <= date_check.getTime()) && (date_check.getTime() <= last_day.getTime())) { timetables.push(tiva_timetables[i]); } } return timetables; } // Change month or year on calendar function createTimetable(el, btn, weekNum, monthNum, yearNum) { // Variable var firstDate; var firstDay; var lastDate; var numbDays; var firstDateWeek; var todayDate = new Date(); if (btn == "prevyr") { yearNum--; } else if (btn == "nextyr") { yearNum++; } else if (btn == "prevmo") { monthNum--; } else if (btn == "nextmo") { monthNum++; } else if (btn == "prevwe") { firstDateWeek = new Date(weekNum); weekNum = getDayBefore(firstDateWeek, 7); } else if (btn == "nextwe") { firstDateWeek = new Date(weekNum); weekNum = getDayAfter(firstDateWeek, 7); } if (monthNum == 0) { monthNum = 12; yearNum--; } else if (monthNum == 13) { monthNum = 1; yearNum++ } // Get first day and number days of month firstDate = new Date(yearNum, monthNum - 1, 1); var date_start = (typeof el.attr('data-start') != "undefined") ? el.attr('data-start') : 'sunday'; if (date_start == 'sunday') { firstDay = firstDate.getDay() + 1; } else { firstDay = (firstDate.getDay() == 0) ? 7 : firstDate.getDay(); } lastDate = new Date(yearNum, monthNum, 0); numbDays = lastDate.getDate(); //console.log('monthNum',monthselect); //console.log('yearNum',yearNum); //console.log('tiva_timetables',tiva_timetables); var monthselect = monthNum - 1; var dateselect = yearNum+'-'+ ("0"+monthselect).substr(-2); var dataofmonth = [] = getDatativatimetables(dateselect); if(dataofmonth != ''){ tiva_timetables = dataofmonth; }else{ tiva_timetables = tiva_timetables; } // Create calendar var view = (typeof el.attr('data-view') != 'undefined') ? el.attr('data-view') : 'month'; if (view == 'week') { timetableWeek(el, tiva_timetables, weekNum); } else if (view == 'list') { timetableList(el, tiva_timetables, weekNum); } else if (view == 'compact') { timetableCompact(el, tiva_timetables, firstDay, numbDays, monthNum, yearNum); } else { timetableMonth(el, tiva_timetables, firstDay, numbDays, monthNum, yearNum); } } // Create timetable week function timetableWeek(el, tiva_timetables, firstDayWeek) { var firstWeek = new Date(firstDayWeek); var firstWeekDate = firstWeek.getDate(); var firstWeekMonth = firstWeek.getMonth() + 1; var firstWeekYear = firstWeek.getFullYear(); var lastWeek = getDayAfter(firstWeek, 6); var lastWeekDate = lastWeek.getDate(); var lastWeekMonth = lastWeek.getMonth() + 1; var lastWeekYear = lastWeek.getFullYear(); var dayArr; var d; var date; var month; var year; var first; var last; var header_time; // Set wordDay var wordDay; var date_start = (typeof el.attr('data-start') != "undefined") ? el.attr('data-start') : 'sunday'; var timetableString = ""; if (date_start == 'sunday') { wordDay = new Array(wordDay_sun, wordDay_mon, wordDay_tue, wordDay_wed, wordDay_thu, wordDay_fri, wordDay_sat); dayArr = new Array("sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"); } else { // Start with Monday wordDay = new Array(wordDay_mon, wordDay_tue, wordDay_wed, wordDay_thu, wordDay_fri, wordDay_sat, wordDay_sun); dayArr = new Array("monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"); } var week_nav; if ((firstWeekMonth != lastWeekMonth) && (firstWeekYear != lastWeekYear)) { week_nav = firstWeekDate + ' ' + wordMonth[firstWeekMonth - 1] + ' ' + (firstWeekYear+543) + ' - ' + lastWeekDate + ' ' + wordMonth[lastWeekMonth - 1] + ' ' + (lastWeekYear+543); } else if (firstWeekMonth != lastWeekMonth) { week_nav = firstWeekDate + ' ' + wordMonth[firstWeekMonth - 1] +' - ' + lastWeekDate + ' ' + wordMonth[lastWeekMonth - 1] + ' ' + (firstWeekYear+543); } else { week_nav = firstWeekDate + ' - ' + lastWeekDate + ' ' + wordMonth[firstWeekMonth - 1] + ' ' + (firstWeekYear+543); } if (!(el.attr('data-nav') == 'hide') && !(el.attr('data-mode') == 'day')) { timetableString += '
'; } // Get timetables week if (!(el.attr('data-mode') == 'day')) { tiva_timetables = getTimetablesWeek(tiva_timetables, new Date(firstWeekYear, firstWeekMonth - 1, firstWeekDate), new Date(lastWeekYear, lastWeekMonth - 1, lastWeekDate)); } // Get min, max time var min_time = getMinTime(tiva_timetables) ? getMinTime(tiva_timetables) : 0; var max_time = getMaxTime(tiva_timetables) ? getMaxTime(tiva_timetables) : 24; var show_time = (el.attr('data-header-time') == 'hide') ? '' : 'show-time'; timetableString += ' '; el.html(timetableString); // Popup el.find('.timetable-title').magnificPopup({ type: 'inline', removalDelay: 800, mainClass: 'my-mfp-zoom-in' }); } // Create timetable week function timetableList(el, tiva_timetables, firstDayWeek) { var firstWeek = new Date(firstDayWeek); var firstWeekDate = firstWeek.getDate(); var firstWeekMonth = firstWeek.getMonth() + 1; var firstWeekYear = firstWeek.getFullYear(); var lastWeek = getDayAfter(firstWeek, 6); var lastWeekDate = lastWeek.getDate(); var lastWeekMonth = lastWeek.getMonth() + 1; var lastWeekYear = lastWeek.getFullYear(); var dayArr; var d; var date; var month; var year; var first; var last; var header_time; if(lang_url[6]=='TH-TH'){ var year_first = firstWeekYear+543; var year_last = lastWeekYear+543; }else{ var year_first = firstWeekYear; var year_last = lastWeekYear; } // Set wordDay var wordDay; var date_start = (typeof el.attr('data-start') != "undefined") ? el.attr('data-start') : 'sunday'; var timetableString = ""; if (date_start == 'sunday') { wordDay = new Array(wordDay_sun, wordDay_mon, wordDay_tue, wordDay_wed, wordDay_thu, wordDay_fri, wordDay_sat); dayArr = new Array("sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"); } else { // Start with Monday wordDay = new Array(wordDay_mon, wordDay_tue, wordDay_wed, wordDay_thu, wordDay_fri, wordDay_sat, wordDay_sun); dayArr = new Array("monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"); } var week_nav; if ((firstWeekMonth != lastWeekMonth) && (firstWeekYear != lastWeekYear)) { week_nav = firstWeekDate + ' ' + wordMonth[firstWeekMonth - 1] + ' ' + year_first + ' - ' + lastWeekDate + ' ' + wordMonth[lastWeekMonth - 1] + ' ' + year_last } else if (firstWeekMonth != lastWeekMonth) { week_nav = firstWeekDate + ' ' + wordMonth[firstWeekMonth - 1] + ' - ' + lastWeekDate + ' ' + wordMonth[lastWeekMonth - 1] + ' ' + year_first; } else { week_nav = firstWeekDate + ' - ' + lastWeekDate + ' ' + wordMonth[firstWeekMonth - 1] + ' ' + year_first; } if (!(el.attr('data-nav') == 'hide') && !(el.attr('data-mode') == 'day')) { timetableString += ' '; } var timetables; timetableString += ' '; el.html(timetableString); // Popup el.find('.timetable-title').magnificPopup({ type: 'inline', removalDelay: 800, mainClass: 'my-mfp-zoom-in' }); } // Create timetable month function timetableMonth(el, tiva_timetables, firstDay, numbDays, monthNum, yearNum) { // Set wordDay var todaysDate = tiva_current_date.getDate(); var wordDay; var date_start = (typeof el.attr('data-start') != "undefined") ? el.attr('data-start') : 'sunday'; var timetableString = ""; var daycounter = 0; if (date_start == 'sunday') { wordDay = new Array(wordDay_sun, wordDay_mon, wordDay_tue, wordDay_wed, wordDay_thu, wordDay_fri, wordDay_sat); } else { // Start with Monday wordDay = new Array(wordDay_mon, wordDay_tue, wordDay_wed, wordDay_thu, wordDay_fri, wordDay_sat, wordDay_sun); } if (!(el.attr('data-nav') == 'hide')) { timetableString += ' '; } timetableString += '' + wordDay[m] + ' | '; } else { timetableString += '' + wordDay[m] + ' | '; } } timetableString += '
---|---|
';
if ((daycounter <= numbDays) && (daycounter >= 1)) {
timetableString += ' ' + daycounter + ' ';
}
// Get timetables of day
var timetables = getTimetables(tiva_timetables, daycounter, monthNum, yearNum);
for (var t = 0; t < timetables.length; t++) {
// Image
if (timetables[t].image) {
var timetable_image = '';
} else {
var timetable_image = '';
}
// End time
if (timetables[t].end_time) {
var timetable_end_time = ' - ' + timetables[t].end_time;
} else {
var timetable_end_time = '';
}
if (timetables[t].filename) {
var fileatt = timetables[t].filename;
var filetype = fileatt.split(".");
var fileattatch = 'FileName : ' + timetables[t].filename + ' '; var fileattatchdes = ''; }else{ var fileatt = ''; var filetype = ''; var fileattatch = ''; var fileattatchdes = ''; } //alert(filetype[1]); timetableString += ' '; } timetableString += ' | ';
}
timetableString += '
' + wordDay[m] + ' | '; } else { timetableString += '' + wordDay[m] + ' | '; } } timetableString += '|
---|---|---|
'; } else if(x == 7) { timetableString += ' | '; } else { timetableString += ' | ';
}
// Get timetables of day
var timetables = getTimetables(tiva_timetables, daycounter, monthNum, yearNum);
var timetableStringD = "";
var foundHoliday = 0;
var foundEvent = 0;
for (var t = 0; t < timetables.length; t++) {
// Image
if (timetables[t].image) {
var timetable_image = '';
} else {
var timetable_image = '';
}
// Time
var eventtime = "";
if ((timetables[t].date+"/"+timetables[t].month+"/"+timetables[t].year) == (timetables[t].end_date+"/"+timetables[t].end_month+"/"+timetables[t].endyear))
{
eventtime += timetables[t].date+"/"+timetables[t].month+"/"+(parseInt(timetables[t].year)+543)+" "; if (timetables[t].start_time != '00:00' && timetables[t].end_time != '00:00') { eventtime += timetables[t].start_time + ' - ' + timetables[t].end_time; } else { eventtime += 'ตลอดวัน'; } } else { if (timetables[t].start_time != '00:00' && timetables[t].end_time != '00:00') { eventtime += "วันที่ " + timetables[t].date+"/"+timetables[t].month+"/"+(parseInt(timetables[t].year)+543) + " เวลา " + timetables[t].start_time + " - วันที่ " + timetables[t].end_date+"/"+timetables[t].end_month+"/"+(parseInt(timetables[t].end_year)+543) + " เวลา " + timetables[t].end_time; } else { eventtime += timetables[t].date+"/"+timetables[t].month+"/"+(parseInt(timetables[t].year)+543)+" - "+ timetables[t].end_date+"/"+timetables[t].end_month+"/"+(parseInt(timetables[t].end_year)+543) +" "; eventtime += 'ตลอดวัน'; } } if (timetables[t].filename) { var fileatt = timetables[t].filename; var filetype = fileatt.split("."); var fileattatch = ' FileName : ' + timetables[t].filename + ' '; var fileattatchdes = ''; }else{ var fileatt = ''; var filetype = ''; var fileattatch = ''; var fileattatchdes = ''; } if(timetables[t].day_type == "1") { //แสดงเฉพาะวันธรรมดา foundEvent = 1; timetableStringD += ' '; }/* else { //วันหยุด foundHoliday = 1; timetableStringH += ' ' + daycounter + ' - ' + timetables[t].name + ' ';
}*/
}
if ((daycounter <= numbDays) && (daycounter >= 1)) {
if(foundHoliday == 1) {
timetableString += '' + daycounter + ' ';
} else if(foundEvent == 1) {
timetableString += '' + daycounter + ' ';
} else {
timetableString += '' + daycounter + ' ';
}
}
timetableString += timetableStringD;
timetableString += ' | ';
}
timetableString += '