Morgen zusammen,
hab mal wieder ein Freitag-Morgen-Problem. Beiße mir nun schon seit 2 Tagen an einem "Realtime Serverzeit" Skript die Zähne aus. o.O Das Problem ist, dass es aus einer Kombination von JavaScript und PHP besteht und ich nicht genau weiß, wie man den header und body part ins Typo übertragen kann. -->Hier<-- das funktionierende Script.
Habe das Skript schon X-Mal umgebaut. Mal den header per TypoScript (page.headerDate = FILE oder per page.headerData = PHP_SCRIPT), mal direkt ins Html Template eingefügt, mal die inc_servertime.php auseinandergenommen und direkt eingefügt. Einfach alle möglichen Kombinationen durchprobiert.
Vielleicht findet ja jemand gefallen an dem Skript und hängt sich hier mit rein. Ist echt mal ne Herausforderung ... für mich zumindest #giggle#
Gruß
ein ganz verzweifelter sw-student
Hier noch die beiden Files:
[main.php] (Template Datei)
<!-- ###DOKUMENT###-->
<head>
<?php
include 'inc_servertime.php';
$st = new servertime;
$st->InstallClockHead();
?>
</head>
<body>
<br><br><br><br><br><br><br><br>
<table border="1" width="600" cellspacing="0" cellpadding="0" height="32">
<tr>
<td width="100" rowspan="3">###LOGO###</td>
<td width="500" valign="bottom" align="right" nowrap>
<?php
$st->InstallClock();
$st->InstallClockBody();
?>
</td>
<td width="100" rowspan="3">###LOGO2###</td>
<tr>
<td align="right">
<select class="selecta" name="location" size="1" onchange="updateclock(this);">
<option value="0" selected>Deutschland</option>
<option value="1">Südafrika</option>
<option value="-7">Mexiko</option>
<option value="0">Polen</option>
<option value="-4">Uruquay</option>
<option value="6">Thailand</option>
</select>
</td>
</tr>
<tr>
<td></td>
</tr>
</tr>
</table>
</body>
</html>
<!-- ###DOKUMENT###-->
[inc_servertime.php]
<?php
class servertime
{
var $divid = 'Pendule'; // default id name
var $divstyle = 'position:absolute;'; // default for NS 4.7
var $divtag = 'div'; // other possibility: 'span'
var $divclass = ''; // default empty
var $title = ''; // default clock title
#
# 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.
var $bodyonload = false; // If <body onload="clock()"> is used, set it to true, please
# This function is to be used in the <head> section of the page.
function InstallClockHead( )
{
echo "
<script language="JavaScript" type="text/javascript">
<!--
".
"var zone=0;
".
"function updateclock(z){
".
"zone=z.options[z.selectedIndex].value;
".
"}
";
# 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'), date('i'), date('s'), date('m'), date('d'), date( 'Y' ) ) );
echo 'var digital = new Date( "'.$datum.'");'; // <-- this is the trick!
echo "
function writeLayer(layerID,txt)".
"
{
if(document.getElementById)
{
".
" document.getElementById(layerID).innerHTML=txt;
".
" }
else if(document.all)
{
document.all[layerID].innerHTML=txt;
".
" }
else if(document.layers)
{
".
" document.layers[layerID].document.open();
".
" document.layers[layerID].document.write(txt);
".
" document.layers[layerID].document.close();
}
}
";
echo "
//-->
</script>
";
$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 "
<script language='JavaScript' type='text/javascript'>
<!--
".
"function clock()
{
".
" var hours = digital.getHours()+parseInt(zone);
".
" var minutes = digital.getMinutes();
".
" var seconds = digital.getSeconds();
".
" var ampm = '';
".
" var d = digital.getDate();
".
" var m = digital.getMonth()+1;
".
" var y = digital.getFullYear();
".
" var dispTime;
digital.setSeconds( seconds+1 );
".
" if (minutes < 10) minutes = '0' + minutes;
".
" if (seconds < 10) seconds = '0' + seconds;
".
" if (d < 10) d = '0' + d;
".
" if (m < 10) m = '0' + m;
";
$ampm=""pm" : "am"";
echo " ampm = ( hours > 11 ) ? ".$ampm.";
".
" hours = ( hours > 12 ) ? hours-12 : hours;
".
" hours = ( hours == 0 ) ? 12 : hours;".
" if (hours < 10) hours = '0' + hours;
";
echo " dispTime = "$this->title "+d+"."+m+"."+y+" - "+hours + ":" + minutes + ":" + seconds + " " + ampm;
";
echo
" writeLayer( '$this->divid', dispTime );
".
" setTimeout("clock()", 1000);
}
";
if( $this->bodyonload==false ) echo " clock();
//-->
";
echo "</script>
";
if( $this->ok_head == false )
{
die("Servertime: InstallClockHead() is missing");
}
if( $this->ok_clock == false )
{
die("Servertime: InstallClock() is missing");
}
} // eof InstallClockBody
} // eoc ServerTime
?>