var viewType; var todayDate = new Date(); function Calendar() { this.idEl; this.lastId; this.colorCellSelected = "LIGHTYELLOW"; this.nextView; this.previousView; this.uid = calUid; this.cat = ''; this.currentTime = new Date(); } Calendar.prototype.dialog = function() { var divAddDialog = document.getElementById("divAddDialog"); if (_dragArea.initEvent > _dragArea.endEvent){ var temp = _dragArea.initEvent; _dragArea.initEvent = _dragArea.endEvent; _dragArea.endEvent = temp; } if(divAddDialog && divAddDialog.style.display != "none"){ divAddDialog.style.display = "none"; for (var hour = parseInt(_dragArea.initEvent); hour <= parseInt(_dragArea.endEvent);(hour%100 == 30)?hour+=70:hour+=30) try { document.getElementById(hour).style.background = ""; } catch (e) { break; }; _dragArea.initEvent = null; _dragArea.endEvent = null; try { document.getElementById("div_main").style.opacity = 1; document.getElementById("div_main").filters.alpha.opacity=100; } catch (e) {}; return true; } var cell = document.getElementById(_dragArea.endEvent); try { document.getElementById("div_main").style.opacity = 0.5; document.getElementById("div_main").filters.alpha.opacity=50; } catch (e) {}; var data = ''+calendar.parseDate(id2timeStamp(_dragArea.initEvent))+''; var xsl = XMLTools.load('xsl/addDialog.xsl?'+ Date.parse(new Date)); if(!divAddDialog) { divAddDialog = document.createElement("DIV"); divAddDialog.id = 'divAddDialog'; divAddDialog.style.zIndex = "10"; divAddDialog.style.position = "absolute"; divAddDialog.style.display = "none"; document.body.appendChild(divAddDialog); } divAddDialog.style.left = "300px"; //cell.offsetLeft + document.body.scrollLeft; divAddDialog.style.top = "200px"; //cell.offsetTop - 100 + document.getElementById('div_main').offsetTop; divAddDialog.style.display = "block"; divAddDialog.innerHTML = xtools.parse(data, xsl); var closeButton = document.getElementById('closeDialog'); if (is_ie) { closeButton.style.left = '285px'; closeButton.style.top = '5px'; } else { closeButton.style.left = '320px'; closeButton.style.top = '25px'; } document.getElementById('dragEventSubject').focus(); document.getElementById('addEventLink').innerHTML = get_lang("Add this event"); document.getElementById('addDetailsLink').innerHTML = get_lang("Add with details"); this.lastId = _dragArea.endEvent; } Calendar.prototype.getView = function(idEl, type, viewTime) { if (typeof(type) == 'undefined') return false; if (typeof(viewTime) == 'undefined') viewTime = calendar.currentTime.getTime(); if (type == 'Year'){ var handler = function (data) { var div_main = document.getElementById('div_main'); div_main.innerHTML = data; } cExecute('../index.php?menuaction=calendar.uicalendar.year&plain=True',handler); return; } this.idEl = idEl; var _this = this; this.lastId = null; var handler_getView = function(XMLdata) { _this.parseView(XMLdata,type); calendar.currentTime.setTime(id2timeStamp(document.getElementById('day').firstChild.id)); var dayMS = (60*60*24*1000); if (viewType == "Week"){ var previousWeek = new Date; previousWeek.setTime(calendar.currentTime.getTime()-(dayMS*7)); this.previousView = previousWeek.getTime(); var nextWeek = new Date; nextWeek.setTime(calendar.currentTime.getTime()+(dayMS*8)); this.nextView = nextWeek.getTime(); } if (viewType == "Day"){ this.previousView = calendar.currentTime.getTime()-dayMS; this.nextView = calendar.currentTime.getTime()+dayMS; } if (viewType == 'Month'){ var previousMonth = new Date; previousMonth.setTime(calendar.currentTime.getTime()); previousMonth.setMonth(calendar.currentTime.getMonth()-1); this.previousView = previousMonth.getTime(); var nextMonth = new Date; nextMonth.setTime(calendar.currentTime.getTime()); nextMonth.setMonth(calendar.currentTime.getMonth()+1); this.nextView = nextMonth.getTime(); } document.getElementById("l_date").innerHTML = "\<\< "; if (viewType == "Week") document.getElementById("l_date").innerHTML += calendar.parseWeek(id2timeStamp(document.getElementById('day').firstChild.id)); if (viewType == "Day") document.getElementById("l_date").innerHTML += calendar.parseDate(id2timeStamp(document.getElementById('day').firstChild.id)); if (viewType == "Month") document.getElementById("l_date").innerHTML += calendar.parseMonth(id2timeStamp(document.getElementById('day').firstChild.id)); document.getElementById("l_date").innerHTML += " \>\>"; var getEventsDay = function (data) { var xsl = XMLTools.load('xsl/events'+type+'.xsl'); var div = document.getElementById('div_main'); div.innerHTML += xtools.parse(data, xsl); var events = document.getElementById('returnEvents'); while(typeof(events.firstChild.id) == 'string') createEventDiv(events.firstChild); } XMLTools.__RETURN_MODE__ = 'XML'; XMLTools.request('$this.uicalendar.getEvents'+type+"&time="+timeStamp2id(calendar.currentTime.getTime())+'&uid='+calendar.uid+'&cat='+calendar.cat, 'GET', getEventsDay); }; XMLTools.__RETURN_MODE__ = 'XML'; viewType = type; screenTable = new Array(); XMLTools.request('$this.uicalendar.getView'+type+"&time="+timeStamp2id(viewTime)+'&uid='+this.uid, 'GET', handler_getView); }; Calendar.prototype.resetView = function() { document.getElementById("div_main").innerHTML = ""; } Calendar.prototype.parseView = function(data,type) { var _this = this; var div = document.getElementById(this.idEl); try { var xsl = XMLTools.load('xsl/view'+type+'.xsl?'+ Date.parse(new Date)); div.innerHTML = xtools.parse(data, xsl); } catch(e){ alert(e); } document.getElementById('divAppbox').style.height = "100%"; if (type == 'Week' || type == 'Month') { var trWeek = document.getElementById('tr_week'); for (var i=0; i < trWeek.childNodes.length; i++) trWeek.childNodes[i].innerHTML = get_lang(trWeek.childNodes[i].innerHTML)+(type=='Week'?" "+id2String((trWeek.childNodes[i].id).substr(8)):""); } }; Calendar.prototype.parseTime = function (first, last) { var hour = first.substring(8,10); var minute = first.substring(10,12); var startHour = hour+":"+minute; if(last && first != last) { hour = last.substring(8,10); minute = last.substring(10,12); } if(minute == "30") { hour = parseInt(hour,10); hour = normDec(hour+1); minute = "00"; } else { minute = "30"; } return startHour+ " - "+ hour+":"+minute; } Calendar.prototype.parseWeek = function (timeStamp) { dateObj=new Date(); dateObj.setTime(timeStamp); Year=dateObj.getYear(); if (Year < 70) { Year=Year*1+2000; } if (Year < 1900) { Year=Year*1+1900; } Then=new Date(Year, 0, 1); Then_Day=Then.getDay(); Diff=dateObj*1-Then*1; Days=Math.floor(Diff/(1000*60*60*24)+(1/24)); Week=Math.floor((Days+Then_Day)/7)+1; return get_lang("Week Number %1 of %2",Week,Year); } Calendar.prototype.parseMonth = function (timeStamp) { obj=new Date(); obj.setTime(timeStamp); switch(obj.getMonth()) { case 0: month = "January"; break; case 1: month = "February"; break; case 2: month = "March"; break; case 3: month = "April"; break; case 4: month = "May"; break; case 5: month = "June"; break; case 6: month = "July"; break; case 7: month = "August"; break; case 8: month = "September"; break; case 9: month = "October"; break; case 10: month = "November"; break; case 11: month = "December"; break; default: month = ""; break; } return get_lang("%1 of %2",get_lang(month),(obj.getYear()+1900)); } Calendar.prototype.parseDate = function (timeStamp) { var obj = new Date(); obj.setTime(timeStamp); var day; switch(obj.getDay()) { case 0: day = "Sunday"; break; case 1: day = "Monday"; break; case 2: day = "Tuesday"; break; case 3: day = "Wednesday"; break; case 4: day = "Thursday"; break; case 5: day = "Friday"; break; case 6: day = "Saturday"; break; default: day = ""; break; } var month; switch(obj.getMonth()) { case 0: month = "January"; break; case 1: month = "February"; break; case 2: month = "March"; break; case 3: month = "April"; break; case 4: month = "May"; break; case 5: month = "June"; break; case 6: month = "July"; break; case 7: month = "August"; break; case 8: month = "September"; break; case 9: month = "October"; break; case 10: month = "November"; break; case 11: month = "December"; break; default: month = ""; break; } year = (is_ie?parseInt(obj.getYear()):parseInt(obj.getYear())+1900); return get_lang(day)+", "+obj.getDate()+" "+get_lang("of")+" "+get_lang(month)+" "+get_lang("of")+" "+year; // FIXME USE FORMAT DATE AS PREFERENCE } var calendar = new Calendar(); // This array stores the events in table to avoid conflict in screen var screenTable = new Array(); var today = new Date(); var weekDay = today.getDay(); function createEventDiv(eventDiv){ eventDiv.className = "event_div"; eventDiv.style.height = parseInt(eventDiv.childNodes[1].id-eventDiv.childNodes[0].id)/120000+"px"; var end_ = timeStamp2id(eventDiv.childNodes[1].id).substr(8); var start_ = parseInt(timeStamp2id(eventDiv.childNodes[0].id).substr(8),10); if (viewType == "Day"){ if (!screenTable[weekDay]) screenTable[weekDay] = new Array(); eventDiv.style.width = "190px"; currentPos = 1; for (var hour = parseInt(start_,10); hour < parseInt(end_,10);(hour%100 == 30)?hour+=70:hour+=30){ if (!screenTable[weekDay][hour]) screenTable[weekDay][hour] = 0; if (currentPos <= screenTable[weekDay][hour]) currentPos = screenTable[weekDay][hour]+1; } for (var hour = parseInt(start_,10); hour < parseInt(end_,10);(hour%100 == 30)?hour+=70:hour+=30) screenTable[weekDay][hour] = currentPos; eventDiv.style.left = 90+(205*(currentPos-1)) + "px" ; eventDiv.onmouseover = function(){ createButtons(eventDiv); }; eventDiv.onmouseout = function(){ removeButtons(eventDiv); }; var resizeDiv = document.createElement('DIV'); resizeDiv.id = "resize_" + eventDiv.id; resizeDiv.className = 'resize_div'; resizeDiv.onmousedown = function() { resizeEvent(eventDiv); }; eventDiv.appendChild(resizeDiv); } if (viewType == "Week"){ var tempDate = new Date; tempDate.setTime(eventDiv.childNodes[1].id); if (!screenTable[tempDate.getDay()]) screenTable[tempDate.getDay()] = new Array(); currentPos = 1; if (!screenTable[tempDate.getDay()][start_]) screenTable[tempDate.getDay()][start_] = 0; if (currentPos <= screenTable[tempDate.getDay()][start_]) currentPos = screenTable[tempDate.getDay()][start_]+1; screenTable[tempDate.getDay()][start_] = currentPos; var widthValue = 100; eventDiv.style.width = widthValue+"px"; var headerElement = document.getElementById('weekday_'+timeStamp2id(eventDiv.childNodes[1].id).substr(0,8)); if (currentPos > 1) eventDiv.style.left = (10+(tempDate.getDay()*122)+(widthValue*currentPos))+"px"; headerElement.style.width = (widthValue*currentPos)+"px"; eventDiv.style.height = "20px"; eventDiv.style.cursor = "pointer"; eventDiv.onmouseover = function () { this.style.height = "auto"; this.style.zIndex = 2;}; eventDiv.onmouseout = function () { this.style.height = "20px"; this.style.zIndex = 1; }; eventDiv.onclick = function () { calendar.getView('div_main','Day',eventDiv.childNodes[1].id); }; } var tdElement = document.getElementById(timeStamp2id(eventDiv.childNodes[0].id)); if (viewType == "Month"){ var tdElement = document.getElementById(timeStamp2id(eventDiv.childNodes[0].id).substr(0,8)+'0000'); eventDiv.style.width = "60px"; eventDiv.style.height = "15px"; eventDiv.onmouseover = function () { if (this.childNodes[2].length > 9) this.style.width = "auto"; this.style.zIndex = 2; }; eventDiv.onmouseout = function () { this.style.width = "60px"; this.style.zIndex = 1; }; eventDiv.onclick = function () { calendar.getView('div_main','Day',eventDiv.childNodes[1].id); }; eventDiv.style.cursor = "pointer"; tdElement.style.height = (tdElement.childNodes.length * 10) + "px"; if (tdElement.childNodes.length > 3) eventDiv.style.margin = "20 0 0 "+(20+(tdElement.childNodes.length-4)*25); else eventDiv.style.margin = "0 0 0 "+(20+(tdElement.childNodes.length-1)*25); } if (tdElement == null) { orphan_table = document.getElementById('orphan_table'); if (!orphan_table) { orphan_table = document.createElement('table'); orphan_table.id = "orphan_table"; orphan_table.className = "table_common"; orphan_table.innerHTML = ""; document.getElementById('div_main').appendChild(orphan_table); } tr_el = document.createElement('TR'); td_el = document.createElement('TD'); td_el.className = "td_header"; td_el.innerHTML = get_lang("Out of table preferences"); tr_el.appendChild(td_el); td_el = document.createElement('TD'); td_el.className = "td_common"; tr_el.appendChild(td_el); eventDiv.style.position = "relative"; td_el.appendChild(eventDiv); orphan_table.firstChild.appendChild(tr_el); } else { eventDiv.style.top = (tdElement.offsetTop + 160) + "px"; tdElement.appendChild(eventDiv); } }