UBB.Dev
Posted By: dimopoulos Real time clock on threads - 11/01/2002 2:43 AM
Hi all,

A friend of mine that is a java guru managed to knock something for my threads so here it is for those who want to use it.

This hack displays the current server time on the top navigation bar - before the Admin link

Open ubbt_registerednav.tmlp

Find this:
code:

<? //UBBTREMARK
echo <<<UBBTPRINT
<table width="{$theme['tablewidth']}" align="center" class="tablesurround" cellpadding="1" cellspacing="1">
<tr>
<td>
<table width="100%" class="tableborders" cellpadding="{$theme['cellpadding']}" cellspacing="{$theme['cellspacing']}">
<tr>
<td align="center" class="menubar">


and add BELOW it:
code:

<script language="JavaScript">
if (document.all||document.getElementById)
document.write('<span id="ClockSpan"></span>')

function ThreadsClock()
{
Now = new Date();
Seconds = Now.getSeconds();
Minutes = Now.getMinutes();
Hours = Now.getHours()

if (Hours < 0) Hours+=24;
if (Hours > 23) Hours-=24;

var FinalTime = ((Hours < 10)?"0"+Hours:Hours) + ':' + ((Minutes < 10)?"0"+Minutes:Minutes) + ':' + ((Seconds < 10)?"0"+Seconds:Seconds);

if (document.all)
ClockSpan.innerHTML = 'Server Time: ' + FinalTime + ' | '
else if (document.getElementById)
document.getElementById("ClockSpan").innerHTML = 'Server Time: ' + FinalTime + ' | '
else if (document.layers)
{
document.ClockNetscape.document.ClockNetscape2.document.write('Server Time: ' + FinalTime + ' | ')
document.ClockNetscape.document.ClockNetscape2.document.close()
}

setTimeout('ThreadsClock()',1000);
}

window.onload=ThreadsClock
//-->
</script>


<ilayer id="ClockNetscape" width=100% height=35><layer id="ClockNetscape2" width=100% height=35 left=0 top=0"></layer></ilayer>



Voila!

You can repeat the same with the ubbt_unregisterednav.tmpl.

Warm regards

Nikos
Posted By: JoshPet Re: Real time clock on threads - 11/01/2002 4:25 AM
Thanks Nikos!
Posted By: kaspar Re: Real time clock on threads - 11/01/2002 10:22 PM
I tried this out and it just showed me the time of my computer. It changes according to my clock on the desktop, so if I move it ahead 6 hours the java changes too which I know is not the correct server time. Did I do something wrong?
Posted By: JustDave Re: Real time clock on threads - 11/01/2002 10:41 PM
No, the javascript actually reflect's the viewer's time, not the server time. One would need to pull in the server time using php and set it up as a javascript variable for this code to use.
Posted By: Dave_L_dup1 Re: Real time clock on threads - 11/01/2002 10:49 PM
One would need to pull in the server time using php and set it up as a javascript variable for this code to use.

Which could be done like this:

Add before the "echo":

// milliseconds since January 1 1970 00:00:00 GMT
$server_unixtimestamp = time() * 1000;

In the Javascript, change:

Now = new Date();

to:

Now = new Date($server_unixtimestamp);
Posted By: kaspar Re: Real time clock on threads - 11/02/2002 1:11 AM
I tried that, and it kinda works but the clock isn't refreshing or "ticking" so to speak. I think cause the variable is called in once in the beginning and not called again. that's why the time is static till you refresh the page or go to another one. How do I make it work like the original one?

How are you able to use a php variable ($server_unixtimestamp) in the java script function?

Is it possible to create a php function to get the time and call this function in the java script?
Posted By: JoshPet Re: Real time clock on threads - 11/02/2002 1:44 AM
I kinda like it being the user's time. Handy.

Is there an easy way to convert it to 12 hr format?
Posted By: Dave_L_dup1 Re: Real time clock on threads - 11/02/2002 1:46 AM
Hmmm ... the problem is that PHP is executed server-side, and Javascript is executed client-side.

One solution would be to use a meta tag to force the page to refresh. And if you're going to do that, there's probably no point in using Javascript.

Maybe someone else has a better idea.

P.S. What's the point of this, anyway? Why do users want to see a continuously updated server-time display?
Posted By: kaspar Re: Real time clock on threads - 11/02/2002 2:04 AM
Well the reason we would like to have something like this is that we have over 2000+ users worldwide (and growing) and when make changes or announcements we always have a flurry of emails saying what? when? what's Pacific time? Daylight savings? etc etc. So for us it would be useful in some small way hopefully.
Posted By: Dave_L_dup1 Re: Real time clock on threads - 11/02/2002 2:15 AM
I see

For that purpose, I would think a static time display would be adequate.

But if you want the time to update continuously, what about a Javascript popup window that displays the current server time? That should be doable by writing a trivial PHP script that grabs the server time, and outputs the Javascript to open the popup window. The popup window could have the meta refresh tag in it, so it could update periodically without having to update the main window.
Posted By: kaspar Re: Real time clock on threads - 11/02/2002 2:40 AM
The crazy guy in the MIS dept (who owed me a favor) recoded it to work! woo hoo! If anyone is interested in how he did it, I can get his code and paste it here. It was pretty cool how he did it too.
Posted By: Dave_L_dup1 Re: Real time clock on threads - 11/02/2002 3:38 AM
I'd like to know how he did it.
Posted By: kaspar Re: Real time clock on threads - 11/02/2002 4:14 AM
Well, I celebrated too soon. It seemed to work briefly but now it seems like it doesn't work as well as we thought....drat. Oh well, he sed he'll work on it more.
Posted By: JustDave Re: Real time clock on threads - 11/02/2002 5:28 AM
I believe you would need to get the viewer's time offset and adjust the clock accordingly.

In the send header function add this:

$myOffset = $user['U_TimeOffset'] * 3600;


In the javascript change this:

Now = new Date();

to this:

Now = new Date() - $myOffset;



You would need to add U_TimeOffset to the basic auth list though since this will be needed on every page (for the most part)

Also, should set up a default if the viewer does not have their offset set.

And, if the viewer's offset is incorrect the time displayed will be incorrect also.

I'll add this here to see if it works.
Posted By: JustDave Re: Real time clock on threads - 11/02/2002 6:33 AM
I think I got this working here. If it is in fact working I'll post what I did to make it so.
Posted By: caymuc Re: Real time clock on threads - 11/02/2002 12:59 PM
I see the working sample on this board.

I really dislike the effect that now the mouse switches from "Pointer" to "In Use" every second. That makes me really nervous, and makes selections of things not easier.
(IE 5.1 /MAC Os 9x)

Sorry to say that. I have no use for this sort of thing and would like this script to be put off form this board again until this problem is eventually fixed.

Posted By: JustDave Re: Real time clock on threads - 11/02/2002 3:42 PM
I wondered how this would be on the Mac. Your older OS may also be lending to the problem as well. I removed the code.
Posted By: dimopoulos Re: Real time clock on threads - 11/05/2002 11:56 AM
Hi Josh,

To convert everything into 12Hr format you need to do use the following in the script:
code:

<script language="JavaScript">
if (document.all||document.getElementById)
document.write('<span id="ClockSpan"></span>')
function ThreadsClock()
{
Now = new Date();
Seconds = Now.getSeconds();
Minutes = Now.getMinutes();
Hours = Now.getHours();
if (Hours < 0) Hours+=24;
if (Hours > 23) Hours-=24;

AMPM = (Hour > 11)?"PM":"AM";

if (Hours == 0) Hours=12;
(Hours < 13)?Hours:Hours %= 12;

var FinalTime = ((Hours < 10)?"0"+Hours:Hours) + ':' + ((Minutes < 10)?"0"+Minutes:Minutes) + ':' + ((Seconds < 10)?"0"+Seconds:Seconds) + ' ' + AMPM;
if (document.all)
ClockSpan.innerHTML = FinalTime + ' | '
else if (document.getElementById)
document.getElementById("ClockSpan").innerHTML = FinalTime + ' | '
else if (document.layers)
{
document.ClockNetscape.document.ClockNetscape2.document.write(FinalTime + ' | ')
document.ClockNetscape.document.ClockNetscape2.document.close()
}
setTimeout('ThreadsClock()',1000);
}
window.onload=ThreadsClock
//-->
</script>
<ilayer id="ClockNetscape" width=100% height=35><layer id="ClockNetscape2" width=100% height=35 left=0 top=0"></layer></ilayer>



Warm regards

Nikos
© UBB.Developers