View file gmtclock/clock.php

File size: 3.02Kb
<?
/*We have our server slaved to NIST time servers by running a cron job
 *See http://www.bldrdoc.gov/timefreq/service/nts.htm for details
 *Alternatively, for each request you may connect to one of NIST time servers
 *and parse the returned string, format is:
 *51389 99-07-30 08:59:12 50 0 0 688.3 UTC(NIST) *

 *All PHP variables are set into WML vars using the setver clause,
 *including a session ID, (psid), passed back when you go to the menu.wml
 *
 *Tested with Nokia and Ericsson toolkits
 *
 *Once the clock is stopped by going back to the clockcard
 *you may restart the script as a chronometer
 +
 *A live demo is available at: http://wap.rila.bg/clock.wml
 *An HTML version at http://wap.rila.bg/users/clock.phtml
 *
 *Author: Atanas Kebedjiev, Rila Solutions, 2000
 */


//WMLscript will not convert strings with leading zeros to integer

function stripZero ($valStr)
    {
     return ($valStr[0]=="0")?$valStr[1]:$valStr;
    }
     $gmtDate = gmdate( "D, Y-m-d");
     $gmtTime = gmdate("H:i:s");
     $timeArr = explode(":",$gmtTime);
     $ghour   = stripZero($timeArr[0]);
     $gminute = stripZero($timeArr[1]);
     $gsecond = stripZero($timeArr[2]);
 header("Content-Type: text/vnd.wap.wml");
 echo '<?xml version="1.0"?>';
 echo '<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">';

?>

<wml>
 <card id = "clockcard" title="Clock menu">
  <onevent type="onenterforward">
   <go href="#chrono_card">
    <setvar name="hrs"    value="<? echo $ghour;   ?>"/>
    <setvar name="min"    value="<? echo $gminute; ?>"/>
    <setvar name="sec"    value="<? echo $gsecond; ?>"/>
    <setvar name="date"   value="<? echo $gmtDate; ?>"/>
    <setvar name="timeS"  value="<? echo $gmtTime; ?>"/>
    <setvar name="GMT"    value="GMT"/>
    <setvar name="psid" value="<? echo $psid; ?>"/>
   </go>
  </onevent>
  <p>
  $GMT : $timeS
  <br/>
  $(date)
  </p>
    <do type="Accept" label="Chronometer">
         <go href="#chrono_card">
           <setvar name="timeS" value="00:00:00"/>
           <setvar name="GMT" value="Chrono"/>
           <setvar name="hrs" value="0"/>
           <setvar name="min" value="0"/>
           <setvar name="sec" value="0"/>
         </go>
    </do>
    <do type="help" label="Help">
        <go href="#help_card">
        </go>
    </do>
     <do type="prev" label="Home">
        <go href="menu.wml" method="post">
            <postfield name="psid" value="$(psid)"/>
        </go>
     </do>

  </card>

  <card id="chrono_card" title="$(GMT)" ontimer="clock.wmls#addOne()" >

  <timer value="10"/>
   <p align="center">
     &nbsp; <br/>
     <b> $GMT : $timeS </b>
  </p>
     <do type="prev" label="Stop">
             <prev/>
     </do>
  </card>

  <card id="help_card" title="Help">
    <p>
      Server clock slaved to NIST atomic standard.<br/>
      Accuracy will depend on network lag.
    </p>
     <do type="prev" label="Back">
             <prev/>
     </do>
   </card>

</wml>