const SPREADSHEET_ID = '1kM5SXFp1Xd-GGjzwwCxNSAurmfZhntkTACFVdeIpixM';
const GRADE_SHEETS = {
'ט': 'מבחנים ט',
'י': 'מבחנים י',
'יא': 'מבחנים יא',
'יב': 'מבחנים יב'
};
function doGet() {
return HtmlService
.createTemplateFromFile('Index')
.evaluate()
.setTitle('לוח מבחנים ואירועים תשפ״ז')
.addMetaTag('viewport', 'width=device-width, initial-scale=1');
}
function getCalendarData(grade) {
const sheetName = GRADE_SHEETS[grade];
if (!sheetName) {
throw new Error('שכבה לא תקינה');
}
const ss = SpreadsheetApp.openById(SPREADSHEET_ID);
const sheet = ss.getSheetByName(sheetName);
if (!sheet) {
throw new Error('לא נמצאה הלשונית: ' + sheetName);
}
const values = sheet.getDataRange().getDisplayValues();
if (values.length String(v).trim());
const dateCol = findColumn(headers, ['תאריך']);
const typeCol = findColumn(headers, ['סוג']);
const publishCol = findColumn(headers, ['פרסום באתר']);
const holidayCol = findColumn(headers, ['חופשה / מועד', 'חופשה/מועד']);
if (dateCol === -1) {
throw new Error('לא נמצאה עמודת תאריך');
}
const events = [];
for (let r = headerRowIndex + 1; r = 0 ? clean(row[typeCol]) : ";
const publish = publishCol >= 0 ? clean(row[publishCol]) : ";
const holiday = holidayCol >= 0 ? clean(row[holidayCol]) : ";
/*
כל מבחן מוצג.
אירועים אחרים מוצגים רק כאשר "פרסום באתר"
מסומן לפרסום.
חופשה/מועד מוצגים גם הם.
*/
const isExam = type.includes('מבחן');
const isHoliday = holiday !== ";
const isPublished = shouldPublish(publish);
if (!isExam && !isHoliday && !isPublished) {
continue;
}
const date = parseSheetDate(dateText);
if (!date) continue;
// כל העמודות שאחרי "חופשה / מועד" הן בדרך כלל עמודות הכיתות.
const classTexts = [];
if (holidayCol >= 0) {
for (let c = holidayCol + 1; c {
events.push({
date: formatDate(date),
title: title,
type: getEventType(type, holiday),
grade: grade
});
});
}
return events;
}
function findColumn(headers, possibleNames) {
for (let i = 0; i < headers.length; i++) {
const current = normalize(headers[i]);
for (const name of possibleNames) {
if (current === normalize(name)) {
return i;
}
}
}
return -1;
}
function clean(value) {
return String(value || '').trim();
}
function normalize(value) {
return clean(value)
.replace(/\s+/g, ' ')
.replace(/\u05F3/g, "'")
.replace(/\u05F4/g, '"');
}
function shouldPublish(value) {
const v = normalize(value).toLowerCase();
return (
v === 'לפרסום' ||
v === 'כן' ||
v === 'true' ||
v === '1' ||
v === 'פרסום'
);
}
function getEventType(type, holiday) {
if (holiday) {
return 'holiday';
}
const t = normalize(type);
if (t.includes('מבחן')) {
return 'exam';
}
return 'school';
}
function parseSheetDate(value) {
if (!value) return null;
const text = clean(value);
// dd/mm/yyyy
let match = text.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/);
if (match) {
return new Date(
Number(match[3]),
Number(match[2]) – 1,
Number(match[1])
);
}
// yyyy-mm-dd
match = text.match(/^(\d{4})-(\d{1,2})-(\d{1,2})/);
if (match) {
return new Date(
Number(match[1]),
Number(match[2]) – 1,
Number(match[3])
);
}
const d = new Date(text);
if (!isNaN(d.getTime())) {
return d;
}
return null;
}
function formatDate(date) {
const y = date.getFullYear();
const m = String(date.getMonth() + 1).padStart(2, '0');
const d = String(date.getDate()).padStart(2, '0');
return `${y}-${m}-${d}`;
}
function unique(items) {
return […new Set(
items
.map(clean)
.filter(Boolean)
)];
}