...

View Full Version : PHP and Javascript Intergration



Golden_Eagle
10-04-2004, 04:39 AM
I am using PHPNuke and am trying to add a module into my site that is completely run by javascript.

This is the code -

<?
include("header.php");
OpenTable();
?>
<p align="center"><font size="2"><strong>[EAS] </strong></font><font size="2"><strong>TimeZone Calculator!</strong></font><br>
<br>
<FONT SIZE="-1">
<!--
//=========== Customizing this script ==========
// It's easy to change the locations displayed in the table. You can have as many places as you like listed.
// To add a location you need to know its standard offset from GMT (aka Universal Co-ordinated Time)
// If you know that it observes Daylight Savings Time that's useful, but not essential.
//
// The GMT offset and DST period are held in this format:
// "GMT offset%DST period" - the % is a separator.
//
//The GMT offset must be a value between 12 and -11 (a '+' is not needed for times ahead of GMT).
// I take "ahead of GMT/UCT" to mean East of London UK (e.g. India), "behind GMT" to mean West (e.g. USA).
//If the offset is not round hours, enter the minutes after a decimal point (full stop, period...)
// e.g. India (5 hours 30 mins ahead of GMT) = 5.30
//
//The DST period should be one of the following, which are 'built into' this page:
// 0 - Daylight Savings never used, or have no info.
// 1 - Uncertain; they do or have in the past, but don't have definite info.
// 2 - DST from 1st Sun in April to Last Sun in October (USA/Canada)
// 3 - DST from Last Sun in March to Last Sun in October (UK/Europe)
// 4 - DST from Last Sun in October to Last Sun in March (Australia - NSW, Vic, ACT, SA)
// 5 - DST from 1st Sun in October to Last Sun in March (Australia - Tasmania)
// 6 - DST from 1st Sun in October to 1st Sun on/after 15 March (New Zealand)
// 7 - DST from Last Sun in March to 1st Sun in September (Russia)
//
//Example: to add Italy the data would be stored as "1%3"
// (i.e. standard time 1 hour ahead of GMT, Daylight Savings period 3 in list above)
// to add Italy to the table, open this file in any text editor, go to CUSTOMIZE TABLE below and add the line -
// "1%3", "Italy",
//Don't forget about the quote marks!
//To add places to the list box go down to CUSTOMIZE SELECTION LIST and add a line in a similar format to the others. Delete any //lines you don't want to keep.
//-->
<script language="JavaScript">
<!--

function SymError()
{
return true;
}

window.onerror = SymError;

var SymRealWinOpen = window.open;

function SymWinOpen(url, name, attributes)
{
return (new Object());
}

window.open = SymWinOpen;

//-->
</script>

<script language="JavaScript">
<!--
function SymError()
{
return true;
}
window.onerror = SymError;
var SymRealWinOpen = window.open;
function SymWinOpen(url, name, attributes)
{
return (new Object());
}
window.open = SymWinOpen;
//-->
</script>
<script language="JavaScript">
<!--
function SymError()
{
return true;
}
window.onerror = SymError;
var SymRealWinOpen = window.open;
function SymWinOpen(url, name, attributes)
{
return (new Object());
}
window.open = SymWinOpen;
//-->
</script>
<SCRIPT language="JavaScript">
<!--
var TableLength = 0;
function writeTable () {
document.bgColor = "";
cities = new Array (
// ============================ CUSTOMIZE TABLE ===============
// IMPORTANT! - The last item in the list (currently "Sydney") must NOT have a comma after it! (the others must).
"0%3", "GMT London UK",
"-5%2", "EST New York USA",
"-8%2", "PST Los Angeles USA",
"10%4", "EST Sydney AUS"

// ===========================================================
); // <-Don't delete this!
//==CUSTOMIZE COLOURS AND CAPTIONS======
//==Play with these values to change the look of the table:
//==Table colour scheme:
var HBG="#18202C"; //Base Table BG
var HFG=""; //Header txt
var LBG=""; //Local BG
var LFG=""; //Local txt
var LFC=""; //Local center text
var SBG=""; //SubHeader BG
var SFG=""; //SubHeader txt
var PBG=""; //Places BG
var PFG=""; //Places txt
var DBG=""; //Detail BG
var DFG=""; //Detail txt
var CBG=""; //Selector BG
var FBG=""; //Footer BG
var FFG=""; //Footer txt
//== Captions:
var TH="<B><Font size=5 Face=Tahoma>INTERNATIONAL TIME<FONT COLOR=FF0000><I> NOW!</I></FONT></B>";
var TL1="<B>Your Local Time: </B>&nbsp;&nbsp;&nbsp;";
var TL2="&nbsp;&nbsp;&nbsp;<TT><B>24 Hour Display</B></TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
var TL3="<B>GMT(UCT): </font></B>";
var TP="<I>City / Nation</I>";
//=====PROGRAM:===============
document.write ("<CENTER>"
+"<TABLE WIDTH=90% BGCOLOR="+HBG+" BORDER=0>"
+"<TR NOWRAP><TD COLSPAN=5 ALIGN=center>"
+"<FONT SIZE=+2 COLOR="+HFG+">"+TH
+"</FONT></TD></TR>"
+"<TR NOWRAP BGCOLOR="+LBG+"><FORM NAME=headerTimes>"
+"<TD COLSPAN=5 ALIGN=center>"
+"<FONT COLOR="+LFG+">"+TL1+"</FONT>"
+"<INPUT TYPE=text SIZE=8>"
+"<FONT COLOR="+LFC+">"+TL2+"</FONT>"
+"<FONT COLOR="+LFG+">"+TL3+"</B></FONT>"
+"<INPUT TYPE=text SIZE=8></TD></TR>"
+"<TR NOWRAP ALIGN=center BGCOLOR="+SBG+">"
+"<TD><FONT face=tahoma size=3 COLOR="+SFG+"><B>"+TP+"</B></FONT></TD>"
+"<TD><FONT face=tahoma size=3 COLOR="+SFG+"><B>Players Time</B></FONT></TD>"
+"<TD><FONT face=tahoma size=3 COLOR="+SFG+"><B>Relative to Local</B></FONT></TD>"
+"<TD><FONT face=tahoma size=3 COLOR="+SFG+"><B>Relative to GMT</B></FONT></TD>"
+"<TD><FONT face=tahoma size=3 COLOR="+SFG+"><B>Daylight Savings?</B></FONT></TD></FORM></TR>"
+"<FORM NAME=dynTimes>");
if (document.linkColor=="#"+FBG) {FBG=document.bgColor};
for (var idx = 0; idx < cities.length; idx+=2) {
TableLength += 1;
var qGMTparse = parseFloat(cities[idx]);
var qGMToffset_hrs = parseInt(qGMTparse, 10) ;
var qGMToffset_min= parseInt ( Math.round((qGMTparse-qGMToffset_hrs) * 100), 10);
var qDSTperiod = cities[idx].charAt (cities[idx].length - 1);
var relGMT = (qGMToffset_hrs * 60) + qGMToffset_min;
if (dstZones [qDSTperiod]) {relGMT += 60};
TableTimes[idx/2] = relGMT;
qHandler( cities[idx] );
document.write ("<TR NOWRAP>"
+"<TD ALIGN=left BGCOLOR="+PBG+"><FONT FACE='tahoma' size=3 COLOR="+PFG+">" + cities[idx+1]
+"&nbsp&nbsp</FONT></TD>"
+"<TD ALIGN=center BGCOLOR="+PBG+"><INPUT TYPE=text SIZE=8></TD>"
+"<TD ALIGN=center BGCOLOR="+DBG+"><FONT face=tahoma size=2 COLOR="+DFG+">"+ qReport[1] +"</FONT></TD>"
+"<TD ALIGN=center BGCOLOR="+DBG+"><FONT face=tahoma size=2 COLOR="+DFG+">"+ qReport[2] +"</FONT></TD>"
+"<TD ALIGN=center BGCOLOR="+DBG+"><FONT face=tahoma size=2 COLOR="+DFG+">"+ qReport[3] +"</FONT></TD></TR>");};
document.write ("</FORM><FORM NAME=otherTimes"
+"<TR><TD BGCOLOR="+CBG+" COLSPAN=3 TD ALIGN=center VALIGN=middle>"
+"<TEXTAREA NAME=output ROWS=4 COLS=39 WRAP=virtual></TEXTAREA></TD>"
+"<TD BGCOLOR="+CBG+" COLSPAN=2 ALIGN=center VALIGN=middle>"
+"<SELECT NAME=PlaceSelector SIZE=5 "
+"onChange='qReply(document.forms[2].elements[1].options[document.forms[2].elements[1].selectedIndex].value)'>"
//==CUSTOMIZE SELECTION LIST=======================
+"<OPTION VALUE=4.30%0>Afghanistan"
+"<OPTION VALUE=-3%0>Argentina"
+"<OPTION VALUE=9.30%4>Australia - Adelaide"
+"<OPTION VALUE=10%0>Australia - Brisbane"
+"<OPTION VALUE=9.30%0>Australia - Darwin"
+"<OPTION VALUE=10%4>Australia - Melbourne"
+"<OPTION VALUE=8%0>Australia - Perth"
+"<OPTION VALUE=10%5>Australia - Tasmania"
+"<OPTION VALUE=-4%0>Bolivia"
+"<OPTION VALUE=-5%1>Brazil - Andes"
+"<OPTION VALUE=-3%1>Brazil - East"
+"<OPTION VALUE=-4%1>Brazil - West"
+"<OPTION VALUE=6.30%0>Burma (Myanmar)"
+"<OPTION VALUE=-7%2>Canada - Calgary"
+"<OPTION VALUE=-3.30%2>Canada - Newfoundland"
+"<OPTION VALUE=-4%2>Canada - Nova Scotia"
+"<OPTION VALUE=-5%2>Canada - Quebec"
+"<OPTION VALUE=-5%2>Canada - Toronto"
+"<OPTION VALUE=-8%2>Canada - Vancouver"
+"<OPTION VALUE=-6%2>Canada - Winnipeg"
+"<OPTION VALUE=8%1>China - Mainland"
+"<OPTION VALUE=8%0>China - Taiwan"
+"<OPTION VALUE=-5%0>Colombia"
+"<OPTION VALUE=-5%1>Cuba"
+"<OPTION VALUE=2%1>Egypt"
+"<OPTION VALUE=2%3>Finland"
+"<OPTION VALUE=1%3>France"
+"<OPTION VALUE=1%3>Germany"
+"<OPTION VALUE=0%0>Ghana"
+"<OPTION VALUE=2%3>Greece"
+"<OPTION VALUE=5.30%0>India"
+"<OPTION VALUE=8%0>Indonesia - Bali, Borneo"
+"<OPTION VALUE=9%0>Indonesia - Irian Jaya"
+"<OPTION VALUE=7%0>Indonesia - Sumatra, Java"
+"<OPTION VALUE=3.30%1>Iran"
+"<OPTION VALUE=3%0>Iraq"
+"<OPTION VALUE=2%1>Israel"
+"<OPTION VALUE=-5%1>Jamaica"
+"<OPTION VALUE=3%0>Kenya"
+"<OPTION VALUE=9%0>Korea (North & South)"
+"<OPTION VALUE=8%0>Malaysia"
+"<OPTION VALUE=-6%1>Mexico City"
+"<OPTION VALUE=0%0>Morocco"
+"<OPTION SELECTED VALUE=5.45%0>Nepal"
+"<OPTION VALUE=12%6>New Zealand"
+"<OPTION VALUE=5%0>Pakistan"
+"<OPTION VALUE=-5%0>Peru"
+"<OPTION VALUE=8%0>Philippines"
+"<OPTION VALUE=1%3>Poland"
+"<OPTION VALUE=11%7>Russia - Kamchatka"
+"<OPTION VALUE=3%7>Russia - Moscow"
+"<OPTION VALUE=9%7>Russia - Vladivostok"
+"<OPTION VALUE=8%0>Singapore"
+"<OPTION VALUE=2%0>South Africa"
+"<OPTION VALUE=1%3>Spain"
+"<OPTION VALUE=1%3>Sweden"
+"<OPTION VALUE=7%0>Thailand"
+"<OPTION VALUE=12%0>Tonga"
+"<OPTION VALUE=2%3>Turkey"
+"<OPTION VALUE=3%1>Ukraine"
+"<OPTION VALUE=5%0>Uzbekistan"
+"<OPTION VALUE=7%0>Vietnam"
+"<OPTION VALUE=-9%2>USA - Alaska"
+"<OPTION VALUE=-9%0>USA - Arizona"
+"<OPTION VALUE=-6%2>USA - Central"
+"<OPTION VALUE=-5%2>USA - Eastern"
+"<OPTION VALUE=-10%0>USA - Hawaii"
+"<OPTION VALUE=-5%0>USA - Indiana East"
+"<OPTION VALUE=-7%2>USA - Mountain"
+"<OPTION VALUE=-8%2>USA - Pacific"
//==END SELECTION LIST=======================
+"</SELECT></TD></TR>"
+"<TR NOWRAP><TD ALIGN=center COLSPAN=5>"
+"</TD></TR>"
+"</FORM></TABLE></CENTER>");
} // ---- writeTable
//Globals
dstZones = new Array ();
qReport = new Array ();
TableTimes = new Array();
currentQuery = null;
var NAV4 = (navigator.appVersion.charAt(0) == "4" && navigator.appName=="Netscape") ? true : false;
var timerID = null;
var timerRunning = false;
var Local = new Date();
var GMToffset = Local.getTimezoneOffset();
if (!(navigator.appName.charAt(0) == "M" && navigator.appVersion.charAt(0)==3)) {
if (GMToffset < 0) {GMToffset = Math.abs(GMToffset)}
else {GMToffset = GMToffset - (Math.abs(GMToffset) *2)};
};
var newline= (navigator.appVersion.lastIndexOf('Win') != -1) ? "\r\n" : "\n";
function Into24hrs (time) {
if ( time > 1440)
{ time -= 1440}
else
{ if ( time <0) { time = 1440 + time } };
return time;
} // --- Into24hrs
function GMTnow (GMT) {
var time = new Date();
hrs = time.getHours();
mins = time.getMinutes();
GMT = (hrs*60 + mins) - GMToffset;
GMT = Into24hrs(GMT);
return GMT;
}
function formatRelative (time) {
var Report = null;
var Direction = (time > 0) ? " ahead" : " behind";
time = Math.abs (time);
var Hours = Math.floor (time/60);
var Mins = (time - Hours * 60);
Report = Hours + "h ";
if (Mins != 0) {Report=Report+Mins + "m "};
Report = Report+ Direction;
if (time== 0) {Report="Same Time"};
return Report;
};
function formatTime (time) {
var fHours = Math.floor (time/60) ;
if (fHours <= 9) {fHours = "0" + fHours};
var fMins = time - (fHours * 60);
if (fMins <= 9) {fMins = "0" + fMins};
var fTime = fHours + ":" + fMins;
return fTime;
};
function CheckDST () {
var uNow = new Date();
var uYear = uNow.getYear();
var leap = ((uYear % 4 == 0 && uYear % 100 != 0) || uYear % 400 == 0 )? true : false;
MonthDays = new Array (0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334);
var TodayNum = MonthDays [uNow.getMonth()] + uNow.getDate();
if (leap && TodayNum > 59) {TodayNum += 1};
//FirstSun8Feb, FirstSun15Mar, LastSunMar, FirstSunApr, LastSunSep, FirstSunOct, FirstSun15Oct,LastSunOct,
ChangeDays = new Array (43, 78, 85, 92, 274, 281, 295, 302);
var NumChangeDays = ChangeDays.length;
if (leap) { for (var idx = 0; idx <= 6; idx++) {ChangeDays [idx] += 1} };
DSTdays = new Array ();
LastJan1 = new Date("Jan 1, " + uYear);
DayJan1 = LastJan1.getDay ();
for (var idx2 = 0; idx2 < NumChangeDays; idx2++) {
DSTdays [idx2] = ( TodayNum >= ChangeDays [idx2] - DayJan1 ) ? true : false;
};
dstZones[0] = null;
dstZones[1] = null;
dstZones[2] = ( DSTdays[3] && !DSTdays[7] ) ? true : false;//usa/canada
dstZones[3] = ( DSTdays[2] && !DSTdays[7] ) ? true : false;//uk/europe
dstZones[4] = ( DSTdays[7] || !DSTdays[2] ) ? true : false;//aus
dstZones[5] = ( DSTdays[5] || !DSTdays[2] ) ? true : false;//aus-tasmania
dstZones[6] = ( DSTdays[5] || !DSTdays[1] ) ? true : false;//nz
dstZones[7] = ( DSTdays[2] && !DSTdays[4] ) ? true : false;//russia
}
function qReply (ZoneData) {
currentQuery = ZoneData;
qHandler (ZoneData);
document.forms[2].elements[0].value =
"Current Time = " + formatTime ( qReport[0] )
+ newline + "Relative to Local = "+ qReport[1]
+ newline + "Relative to GMT = "+ qReport[2]
+ newline + "Using Daylight Savings? = " + qReport[3];
}
function qHandler(ZoneData) {
qReport[0] = ""; qReport[1] = ""; qReport[2] = ""; qReport[3] = "";
var qGMTparse = parseFloat(ZoneData);
var qGMToffset_hrs = parseInt(qGMTparse, 10) ;
var qGMToffset_min= parseInt ( Math.round((qGMTparse-qGMToffset_hrs) * 100), 10);
var qDSTperiod = ZoneData.charAt (ZoneData.length - 1);
var qGMTperiod = 1440/60;
if ( (qGMToffset_hrs > 12) || (qGMToffset_hrs <-11) ) {qReport[0] = "BAD DATA"; return};
if (qDSTperiod > dstZones.length) {qReport[3] = "BAD DATA"};
var relGMT = (qGMToffset_hrs * 60) + qGMToffset_min;
if (qDSTperiod>1 && dstZones [qDSTperiod]) {relGMT += 60; qReport[3] = "Yes (+1 hour)"} else {qReport[3] = "No"};
if (qDSTperiod == 0) {qReport[3] = "n/a"};
if (qDSTperiod == 1) {qReport[3] = "uncertain"};
var qPlaceTotMins = GMTnow (qPlaceTotMins);
qPlaceTotMins += relGMT;
qPlaceTotMins = Into24hrs (qPlaceTotMins);
qReport[0] = qPlaceTotMins;
qReport[2] = formatRelative (relGMT);
var relLoc = relGMT - GMToffset;
qReport[1] = formatRelative (relLoc);
}
function writeClocks () {
var GMT = GMTnow (GMT);
var fTime = formatTime ( Into24hrs (GMT + GMToffset) );
document.forms[0].elements[0].value = " "+ fTime;
var fTime = formatTime ( Into24hrs (GMT) );
document.forms[0].elements[1].value = " "+ fTime;
var TableClock = null;
for (var idx = 0; idx < TableLength; idx++) {
TableClock = null;
TableClock += (GMT+TableTimes[idx]);
document.forms[1].elements[idx].value = " "+ formatTime ( Into24hrs ( TableClock ) );
};
if (currentQuery != null) {qReply (currentQuery)};
}
function stopclocks (){
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
}
function showclocks () {
writeClocks();
timerID = setTimeout("showclocks()",1000);
timerRunning = true;
}
function startClocks () {
document.forms[2].output.value=newline + ' Other cities and countries...';
if (NAV4) {writeClocks();alert ("Sorry, the 'real time' clocks have been disabled for Netscape4(communicator)"
+" as they crash the browser.\n\n"
+"Reload to update the times.\n\nSoon to be fixed")
}
else {
stopclocks();
showclocks()};
}
CheckDST();
writeTable();
startClocks();
//-->
</SCRIPT>
</FONT><FONT SIZE="-1"><NOSCRIPT><B><font face="Verdana, Arial, Helvetica, sans-serif" size="-2">If
you can read this your browser is not JavaScript enabled, and the timr calculator
will not work.<BR>
It requires Netscape Navigator 3.0+: <A HREF="http://www.netscape.com/" target="_blank">
Get it here</A></font></B><font face="Verdana, Arial, Helvetica, sans-serif" size="-2">
- (it will also work with Internet Explorer 3.0+)</font>
<P> <font face="Verdana, Arial, Helvetica, sans-serif" size="-2"><B>If you <I>are</I>
using Navigator 3.0+ and you see this message, you need to enable JavaScript by
choosing:<BR>
<U>O</U>ptions | <U>N</U>etwork Preferences | Languages</B> </font></NOSCRIPT><HTM>
<script language="JavaScript">
<!--
var SymRealOnLoad;
var SymRealOnUnload;
function SymOnUnload()
{
window.open = SymWinOpen;
if(SymRealOnUnload != null)
SymRealOnUnload();
}
function SymOnLoad()
{
if(SymRealOnLoad != null)
SymRealOnLoad();
window.open = SymRealWinOpen;
SymRealOnUnload = window.onunload;
window.onunload = SymOnUnload;
}
SymRealOnLoad = window.onload;
window.onload = SymOnLoad;
//-->
</script></FONT></p>
</body>

</html>
<script language="JavaScript">
<!--
var SymRealOnLoad;
var SymRealOnUnload;

function SymOnUnload()
{
window.open = SymWinOpen;
if(SymRealOnUnload != null)
SymRealOnUnload();
}

function SymOnLoad()
{
if(SymRealOnLoad != null)
SymRealOnLoad();
window.open = SymRealWinOpen;
SymRealOnUnload = window.onunload;
window.onunload = SymOnUnload;
}

SymRealOnLoad = window.onload;
window.onload = SymOnLoad;

//-->
</script>
<?
CloseTable();
include("footer.php");
?>

The problem lies in the fact the the times do not show up. I have tested the Javascript without the header and footer tags and it works fine. Can anyone help?

This is what is happening
http://eas-clan.net/modules.php?name=TimeZone

Golden_Eagle
10-04-2004, 04:17 PM
I thought this one would be easy for the guru's. :rolleyes:

Is it because this has javascript section's that need to be added to the header? Making this post in the wrong place perhaps?

Nightfire
10-04-2004, 06:32 PM
It's a javascript problem you've got. Maybe it's conflicting with some javascript in your header?

jamescover
10-04-2004, 07:00 PM
First, start by fixing your markup--at a glance, you have 2 <body> tags, and 4 </body> tags on the same page.



-james

Golden_Eagle
10-04-2004, 09:57 PM
Not my Markup... PHPNuke designed that way mate.

It has <Body> tags in the header.php and footer.php includes I think. Strange I know.

Anyway. Is that <tbody> your referring too? I looked and couldnt see em.

Nor code NotePad.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum