<?php
/*
* Animated Collapsible DIV- © Dynamic Drive DHTML code library (www.pokazuha.tv)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.pokazuha.tv/ for this script and 100s more
* Last Update : Tuesday, November 13 2005
*/
class servertime
{
var $divid = 'Pendule'; // default id name
var $divstyle = 'position:absolute;'; // default for NS 4.7
var $divtag = 'span'; // other possibility: 'span'
var $divclass = ''; // default empty
var $title = ''; // default clock title
var $language = 'german'; // default language
var $shortmonth = false; // have 3-letter-months like "Apr" if true
#
# Internal use only: $ok_head and $ok_clock
#
var $ok_head = false; // InstallClockBody() and InstallClock() will check for this.
var $ok_clock = false; // InstallClockBody() will check for this, too.
#
# New on Oct 3 2003: offset_hours
#
var $offset_hours = 0;
// Feedy's edits
var $military = true; // use military time?
var $ucaseampm = true; // use upper case for am/pm?
var $showdate = true; // show the date?
var $alarmon = false; // alarms on?
var $alarmdate = false; // ahouls alarms check the date?
var $alarm = array(); // alarm times array (strings in military format "HH:MM" for time only and "YYYY-MM-DD HH:MM" for date & time check)
var $bodyonload = false; // If <body onload="clock()"> is used, set it to true, please
// End of Feedy's edits
#
# the programmer may support his/her own javascript alarm function.
#
var $onalarm = 'doAlarm'; // default value: javascript function to open a window
var $alarmpage = 'alarm.php'; // default page to be loaded
var $alarmpagew = '200'; // width of default alarm page
var $alarmpageh = '200'; // height of default alarm page
var $alarmpageopts = 'scrollbars=yes, resizable=yes'; // options for default alarm page
# $alarmpageopts is a comma separated string var and it can be an empty string for no options
# valid options include:
# toolbar -> shows the tool or button bar
# location -> shows the address field
# directories -> shows the directory or links bar
# menubar -> shows the menu
# scrollbars -> shows the scrollbars if the page to display is larger than the windown size
# resizable -> allows the window to be resized
# to get a normal browser window, you would use $alarmpageopts = 'toolbar,location,directories,menubar,scrollbars,resizable';
# This function is to be used in the <head> section of the page.
function InstallClockHead( )
{
echo "\n<script language=\"JavaScript\" type=\"text/javascript\">\n<!--\n";
if( $this->showdate == true ) // array with month names is not always necessary
{
if( $this->shortmonth == true )
{
switch ($this->language) {
case 'spanish' :
echo 'var monat=new Array("enc.","feb.","mar.","abr.","may.",'.
'"jun.","jul.","ago.","sep.","oct.","nov.","dic.");';
break;
case 'german':
echo 'var monat=new Array("Jan.","Feb.","Mär.","Apr.","Mai","Jun.",'.
'"Jul.","Aug.","Sep.","Okt.","Nov.","Dez.");';
break;
case 'french':
echo 'var monat=new Array("Jan","Fév","Mar","Avr","Mai","Jun",'.
'"Jul","Aou","Sep","Oct","Nov","Déc");';
break;
case 'english':
default:
echo 'var monat=new Array("Jan","Feb","Mar","Apr","May","Jun",'.
'"Jul","Aug","Sep","Oct","Nov","Dec");';
break;
}
}
else
{
switch ($this->language) {
case 'spanish' :
echo 'var monat=new Array("encro","febrero","marzo","abril","mayo",'.
'"junio","julio","agosto","septiembre","octubre","noviembre","diciembre");';
break;
case 'german':
echo 'var monat=new Array("Januar","Februar","März","April","Mai",'.
'"Juni","Juli","August","September","Oktober","November","Dezember");';
break;
case 'french':
echo 'var monat=new Array("Janvier","Février","Mars","Avril","Mai",'.
'"Juin","Juillet","Août","Septembre","Octobre","Novembre","Décembre");';
break;
case 'english':
default:
echo 'var monat=new Array("January","February","March","April","May",'.
'"June","July","August","September","October","November","December");';
break;
}
} // else ( $this->shortmonth != true )
} // if ( $this->showdate == true )
echo "\n";
#
# Here is where the server time comes into the script:
# date() is a php function which runs on the server, giving exactly
# the time the server has.
#
$datum =
date('M, d Y H:i:s',
mktime( date('H') + $this->offset_hours,
date('i'), date('s'), date('m'), date('d'), date( 'Y' ) ) );
echo 'var digital = new Date( "'.$datum.'");'; // <-- this is the trick!
echo "\n\nfunction writeLayer(layerID,txt)".
"\n{\n if(document.getElementById)\n {\n".
" document.getElementById(layerID).innerHTML=txt;\n".
" }\n else if(document.all)\n {\n document.all[layerID].innerHTML=txt;\n".
" }\n else if(document.layers)\n {\n".
" document.layers[layerID].document.open();\n".
" document.layers[layerID].document.write(txt);\n".
" document.layers[layerID].document.close();\n }\n}\n";
// Feedy's edits
// This is what happens when the alarm goes off...
// you can change this to open a window or whatever alse you would like to happen
if( $this->onalarm == 'doAlarm' )
{
echo "\n\nfunction doAlarm(alarmtext,alarmtime)\n".
"{\n".
" url = \"$this->alarmpage?alarmtext=\" + alarmtext + \"&alarmtime=\" + alarmtime;\n". // knito
" popupWin = window.open(url, 'alarm', 'width=$this->alarmpagew,height=$this->alarmpageh";
if ( strlen(trim($this->alarmpageopts))>0 ) echo ",$this->alarmpageopts";
echo "')\n}\n";
} // if( $this->onalarm == 'doAlarm' )
// End of Feedy's edits
echo "\n//-->\n</script>\n";
if( $this->alarmon == true and !file_exists( $this->alarmpage ) ) // knito
{
die( "Servertime: file $this->alarmpage is missing!\n" );
}
$this->ok_head = true; // Check later
} // eof InstallClockHead();
# This is to be used where you want the clock to appear on your page.
function InstallClock()
{
# To have it work with NS 4.7 the style "position:absolute" MUST be given (knito)
$klasse = strlen( trim( $this->divclass ) ) > 0 ? " class='$this->divclass'" : '';
$style = strlen( trim( $this->divstyle ) ) > 0 ? " style='$this->divstyle'" : '';
echo "<$this->divtag id='$this->divid'>$this->title</$this->divtag>";
// echo "<$this->divtag id='$this->divid'$style$klasse>$this->title</$this->divtag>";
if( $this->ok_head == false )
{
die("Servertime: InstallClockHead() is missing");
}
$this->ok_clock = true;
} // eof Clock()
# This function is to be used at the end of the <body> section of the page.
function InstallClockBody( )
{
echo "\n<script language='JavaScript' type='text/javascript'>\n<!--\n".
"function clock()\n{\n".
" var hours = digital.getHours();\n".
" var minutes = digital.getMinutes();\n".
" var seconds = digital.getSeconds();\n".
" var ampm = '';\n". // Feedy
" var d = digital.getDate();\n".
" var m = digital.getMonth();\n".
" var y = digital.getFullYear();\n".
" var dispTime;\n\n digital.setSeconds( seconds+1 );\n\n".
" if (minutes < 10) minutes = '0' + minutes;\n".
" if (seconds < 10) seconds = '0' + seconds;\n\n";
// Feedy's edits
if ( $this->alarmon ) {
echo " alid=new Array ();\n".
" altm=new Array ();\n";
reset($this->alarm);
$el=0;
while ($alarminfo = each($this->alarm)) {
echo " alid[$el] = '".$alarminfo['value']."';\n".
" altm[$el] = '".$alarminfo['key'].":00';\n";
$el++;
}
echo " timeCheck = hours + \":\" + minutes + \":\" + seconds;\n".
" if (hours < 10) timeCheck = '0' + timeCheck;\n";
if ($this->alarmdate) {
echo " timeCheck = d + \" \" + timeCheck;\n".
" if (d < 10) timeCheck = '0' + timeCheck;\n".
" timeCheck = (m+1) + \"-\" + timeCheck;\n".
" if ((m+1) < 10) timeCheck = '0' + timeCheck;\n".
" timeCheck = y + \"-\" + timeCheck;\n";
}
echo " alCt=altm.length;\n".
" for (var i=0; i < alCt; i++) {\n".
" if (timeCheck==altm[i]) $this->onalarm(alid[i],altm[i]);\n".
" }\n";
}
if ( !$this->military )
{
$ampm="\"pm\" : \"am\"";
if ( $this->ucaseampm ) $ampm=strtoupper($ampm);
echo " ampm = ( hours > 11 ) ? ".$ampm.";\n".
" hours = ( hours > 12 ) ? hours-12 : hours;\n".
" hours = ( hours == 0 ) ? 12 : hours;";
}
if ( $this->showdate )
{
switch ($this->language) {
case 'spanish':
echo " dispTime = \"$this->title \"+d+\" de \"+monat[m]+\" \"+".
"y+\" \"+hours + \":\" + minutes + \":\" + seconds + \" \" + ampm;\n";
break;
case 'german':
echo " dispTime = \"$this->title \"+d+\". \"+monat[m]+\" \"+".
"y+\" \"+hours + \":\" + minutes + \":\" + seconds + \" \" + ampm;\n";
break;
case 'french':
echo " dispTime = \"$this->title \"+d+\" \"+monat[m]+\" \"+".
"y+\" \"+hours + \":\" + minutes + \":\" + seconds + \" \" + ampm;\n";
break;
case 'english':
default:
echo " dispTime = \"$this->title \"+monat[m]+\", \"+d+\" \"+".
"y+\" \"+hours + \":\" + minutes + \":\" + seconds + \" \" + ampm;\n";
break;
}
}
else
{
switch ($this->language) {
case 'german':
#
# Germans don't like am/pm - we'd rather guess the right half of the day
# or like to use military time (knito)
#
echo " dispTime = \"$this->title \"+hours + \":\" + minutes + \":\" + seconds;\n";
break;
case 'english':
case 'french':
default:
echo " dispTime = \"$this->title \"+hours + \":\" + minutes + \":\" + seconds + \" \" + ampm;\n";
break;
}
}
// End of Feedy's edits
echo
" writeLayer( '$this->divid', dispTime );\n".
" setTimeout(\"clock()\", 1000);\n}\n\n";
if( $this->bodyonload==false ) echo " clock();\n//-->\n";
echo "</script>\n";
if( $this->ok_head == false )
{
die("Servertime: InstallClockHead() is missing");
}
if( $this->ok_clock == false )
{
die("Servertime: InstallClock() is missing");
}
} // eof InstallClockBody
function Help()
{
echo
"<br>Put InstallClockHead() into the <head> section".
"<br>Put InstallClock() where you want the clock to appear".
"<br>Put InstallClockBody() near the bottom of the document";
}
} // eoc ServerTime
?>