/* * client-sided: * - builds dynamic menu * - calculates timestamps for query_strings * - checks consistency of time intervals * * (c) 2008 alexander.philipp.lintenhofer */ var defaultMinutes = 6*60; var minMinutes = 15; var maxMinutes = 14*24*60; var direction = 'to_past'; var currfile = 'overview.php'; function link2graph(which,graph) { resetMenuColors(); showHeatersettingsfields(false); showDurationfields(true); showLinevaluesfields(false); which.style.backgroundColor = "#fc0"; currfile = 'graph.php?graph='+graph; which.href = currfile+'&'+(createTimelineQuerystring()); } function link2dyngraph(which) { var naviform = document.forms['naviform']; var lineQuerystring = ''; resetMenuColors(); showHeatersettingsfields(false); showDurationfields(true); showLinevaluesfields(true); which.style.backgroundColor = "#fc0"; for (i = 0; i < naviform.selectedlinevalues.length; i++) { if (naviform.selectedlinevalues.options[i].selected == true) lineQuerystring += naviform.selectedlinevalues.options[i].value+'%20'; } currfile = 'dyngraph.php?lines='+(lineQuerystring.slice(0, -3)); which.href = currfile+'&'+(createTimelineQuerystring()); } function link2infocontent(which,file) { var timestamp = createTimestamp(); resetMenuColors(); showHeatersettingsfields(false); showDurationfields(false); showLinevaluesfields(false); which.style.backgroundColor = "#fc0"; currfile = file; which.href = file+'?start='+timestamp; } function link2servicecontent(which,file) { var naviform = document.forms['naviform']; var timestamp = createTimestamp(); resetMenuColors(); showDurationfields(false); showHeatersettingsfields(true); showLinevaluesfields(false); which.style.backgroundColor = "#fc0"; currfile = file; if (((tempeinsatz = Math.abs(naviform.tempeinsatz.value.replace(/^\s+|\s+$/g, '')))!='') && ((basissoll = Math.abs(naviform.basissoll.value.replace(/^\s+|\s+$/g, '')))!='') && ((steilheit = Math.abs(naviform.steilheit.value.replace(/^\s+|\s+$/g, '')))!='')) { if((tempeinsatz>20)||(tempeinsatz<5)) { alert("5° < Einsatztemperatur < 20°"); naviform.tempeinsatz.value=''; showSetValIcon(false); } else if((basissoll>40)||(basissoll<15)) { alert("15° < Basis-Soll < 40°"); naviform.basissoll.value=''; showSetValIcon(false); } else if((steilheit>100)||(steilheit<0)) { alert("0% < Steilheit < 100%"); naviform.steilheit.value=''; showSetValIcon(false); } else { which.href = file+'?start='+timestamp+'&tempeinsatz='+tempeinsatz+'&basissoll='+basissoll+'&steilheit='+steilheit; showSetValIcon(true); return true; } return false; } which.href = file+'?start='+timestamp; return true; } function link2statisticcontent(which,file) { resetMenuColors(); showDurationfields(false); showHeatersettingsfields(false); showSetValIcon(false); showLinevaluesfields(false); which.style.backgroundColor = "#fc0"; currfile = file; which.href = file; } /* ============================================================================================== */ /* ============================================================================================== */ function createTimelineQuerystring() { var naviform = document.forms['naviform']; var tsp_graphstart = 0; var tsp_now = Math.round((new Date()).getTime()/1000); var granularity = '1'; for (i=0; i0)?Math.abs(naviform.ticks.value)*granularity:defaultMinutes; if (minutesmaxMinutes) minutes=maxMinutes; if (direction == 'to_future') { tsp_graphstart = createTimestamp(); if (tsp_graphstart>=tsp_now) resetForm(); else if ((tsp_graphstart+(60*minutes))>tsp_now) { minutes = Math.round((tsp_now - tsp_graphstart)/60); if (minutesmaxMinutes) minutes = maxMinutes; tsp_graphstart = tsp_now-(60*minutes); insertTime2Form(tsp_graphstart); } else if (tsp_graphstart==0) resetForm(); } else { insertNowTime2Form(); document.getElementById('durationdesc').innerHTML = 'letzte'; } fillDurationform(minutes); return 'minutes='+minutes+'&start='+tsp_graphstart; } function createTimestamp() { var timestamp=0; var naviform = document.forms['naviform']; if (((yy = naviform.startyy.value.replace(/^\s+|\s+$/g, ''))!='') && ((mm = naviform.startmm.value.replace(/^\s+|\s+$/g, ''))!='') && ((dd = naviform.startdd.value.replace(/^\s+|\s+$/g, ''))!='') && ((hh = naviform.starthh.value.replace(/^\s+|\s+$/g, ''))!='') && ((min = naviform.startmin.value.replace(/^\s+|\s+$/g, ''))!='') ) timestamp = humanToTime(yy,mm,dd,hh,min); return timestamp; } function humanToTime(yy,mm,dd,hh,min) { var humDate = new Date(Date.UTC(yy, (stripLeadingZeroes(mm)-1), stripLeadingZeroes(dd), stripLeadingZeroes(hh), stripLeadingZeroes(min), 0)); offset =(isDaylightSaving(yy,mm,dd))?3600:7200; return (humDate.getTime()/1000.0)-offset; } function stripLeadingZeroes(input) { if((input.length > 1) && (input.substr(0,1) == "0")) return input.substr(1); else return input; } /* ============================================================================================== */ function isDaylightSaving(yy,mm,dd) { var gmt = new Date(yy,mm-1,dd); var lsm = new Date; var lso = new Date; lsm.setYear(yy); lsm.setMonth(2); // March lsm.setDate(31); var day = lsm.getDay();// day of week of 31st lsm.setDate(31-day-1); // last Sunday lso.setYear(yy); lso.setMonth(9); // October lso.setDate(31); day = lso.getDay(); lso.setDate(31-day-1); if (gmt > lso) return 1; // lso -> newyear else if (gmt > lsm) return 0; // lsm -> lso else return 1; // newyear -> lsm } /* ============================================================================================== */ function insertNowDate2Form() { var now = new Date(); var day = (now.getDate()>=10)?now.getDate():'0'+now.getDate(); var month = (now.getMonth()>=9)?now.getMonth()+1:'0'+(now.getMonth()+1); document.forms['naviform'].startdd.value=day; document.forms['naviform'].startmm.value=month; document.forms['naviform'].startyy.value=now.getFullYear(); } function insertNowTime2Form() { var now = new Date(); var hours = (now.getHours()>=10)?now.getHours():'0'+now.getHours(); var minutes = (now.getMinutes()>=10)?now.getMinutes():'0'+now.getMinutes(); document.forms['naviform'].starthh.value=hours; document.forms['naviform'].startmin.value=minutes; } function insertDate2Form(tsp) { alert(tsp); var now = new Date(tsp*1000); var day = (now.getDate()>=10)?now.getDate():'0'+now.getDate(); var month = (now.getMonth()>=9)?now.getMonth()+1:'0'+(now.getMonth()+1); document.forms['naviform'].startdd.value=day; document.forms['naviform'].startmm.value=month; document.forms['naviform'].startyy.value=now.getFullYear(); } function insertTime2Form(tsp) { var now = new Date(tsp*1000); var hours = (now.getHours()>=10)?now.getHours():'0'+now.getHours(); var minutes = (now.getMinutes()>=10)?now.getMinutes():'0'+now.getMinutes(); document.forms['naviform'].starthh.value=hours; document.forms['naviform'].startmin.value=minutes; } /* ============================================================================================== */ function fillDurationform(minutes) { var naviform = document.forms['naviform']; var granularity = 1; if (minutes%1440==0) granularity = 1440; else if (minutes%60==0) granularity = 60; naviform.ticks.value = minutes/granularity; for (i=0; i 1)? naviform.startmm.value.replace(/^\s+|\s+$/g, ''): '0'+naviform.startmm.value.replace(/^\s+|\s+$/g, ''); if(naviform.startdd.value!='') naviform.startdd.value = (naviform.startdd.value.length > 1)? naviform.startdd.value.replace(/^\s+|\s+$/g, ''): '0'+naviform.startdd.value.replace(/^\s+|\s+$/g, ''); if(naviform.starthh.value!='') naviform.starthh.value = (naviform.starthh.value.length > 1)? naviform.starthh.value.replace(/^\s+|\s+$/g, ''): '0'+naviform.starthh.value.replace(/^\s+|\s+$/g, ''); if(naviform.startmin.value!='') naviform.startmin.value = (naviform.startmin.value.length > 1)? naviform.startmin.value.replace(/^\s+|\s+$/g, ''): '0'+naviform.startmin.value.replace(/^\s+|\s+$/g, ''); } /* ============================================================================================== */ function changeDirection() { s = 'für'; document.getElementById('durationdesc').innerHTML = s; direction = 'to_future'; } /* ============================================================================================== */ function resetMenuColors() { var ul = navigation.getElementsByTagName('a'); for(var i=0;i < ul.length; i++) { ul[i].style.backgroundColor = "#f0f0f0"; } }