Previous Thread
Next Thread
Print Thread
Rate Thread
#227120 10/31/2002 7:43 PM
Joined: Aug 2002
Posts: 1,191
Kahuna
Kahuna
Joined: Aug 2002
Posts: 1,191
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


Nikos
Sponsored Links
Joined: Nov 2001
Posts: 10,369
I type Like navaho
I type Like navaho
Joined: Nov 2001
Posts: 10,369
Thanks Nikos!

Joined: Aug 2002
Posts: 45
User
User
Offline
Joined: Aug 2002
Posts: 45
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?

Joined: Jun 2001
Posts: 3,273
That 70's Guy
That 70's Guy
Offline
Joined: Jun 2001
Posts: 3,273
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.

Joined: Apr 2002
Posts: 1,768
Addict
Addict
Offline
Joined: Apr 2002
Posts: 1,768
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);

Sponsored Links
Joined: Aug 2002
Posts: 45
User
User
Offline
Joined: Aug 2002
Posts: 45
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?

Last edited by kaspar; 11/01/2002 6:31 PM.
Joined: Nov 2001
Posts: 10,369
I type Like navaho
I type Like navaho
Joined: Nov 2001
Posts: 10,369
I kinda like it being the user's time. Handy.

Is there an easy way to convert it to 12 hr format?

Joined: Apr 2002
Posts: 1,768
Addict
Addict
Offline
Joined: Apr 2002
Posts: 1,768
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?

Joined: Aug 2002
Posts: 45
User
User
Offline
Joined: Aug 2002
Posts: 45
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.

Joined: Apr 2002
Posts: 1,768
Addict
Addict
Offline
Joined: Apr 2002
Posts: 1,768
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.

Sponsored Links
Joined: Aug 2002
Posts: 45
User
User
Offline
Joined: Aug 2002
Posts: 45
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.

Joined: Apr 2002
Posts: 1,768
Addict
Addict
Offline
Joined: Apr 2002
Posts: 1,768
I'd like to know how he did it.

Joined: Aug 2002
Posts: 45
User
User
Offline
Joined: Aug 2002
Posts: 45
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.

Joined: Jun 2001
Posts: 3,273
That 70's Guy
That 70's Guy
Offline
Joined: Jun 2001
Posts: 3,273
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.

Joined: Jun 2001
Posts: 3,273
That 70's Guy
That 70's Guy
Offline
Joined: Jun 2001
Posts: 3,273
I think I got this working here. If it is in fact working I'll post what I did to make it so.

Joined: Jan 2001
Posts: 374
Enthusiast
Enthusiast
Offline
Joined: Jan 2001
Posts: 374
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.


Joined: Jun 2001
Posts: 3,273
That 70's Guy
That 70's Guy
Offline
Joined: Jun 2001
Posts: 3,273
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.

Joined: Aug 2002
Posts: 1,191
Kahuna
Kahuna
Joined: Aug 2002
Posts: 1,191
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


Nikos

Link Copied to Clipboard
Donate Today!
Donate via PayPal

Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.

Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
isaac
isaac
California
Posts: 1,157
Joined: July 2001
Forum Statistics
Forums63
Topics37,573
Posts293,925
Members13,849
Most Online5,166
Sep 15th, 2019
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,833
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2024 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20221218)