<?php
class make_time
{
// class vars
var $a=array();
var $y_delay=array(5, 0);
var $cor=array();
var $stamp=null;
//construct method
function make_time()
{
$this->mk_time();
if(isset($_POST['maketime']))
{
$mt=$_POST['maketime'];
$this->stamp = mktime($mt['H'], $mt['i'], $mt['s'], $mt['M'], $mt['j'], $mt['Y']);
}
}
// public methods
function display_form($tms=0)
{
$ret="";
$ret.="\n<div class=\"mktime\"><form action=\"\" method=\"post\">\n";
$ret.=$this->make_select("Y", $tms)."- ".
$this->make_select("M", $tms)."- ".
$this->make_select("j", $tms)." ".
$this->make_select("H", $tms).":".
$this->make_select("i", $tms).":".
$this->make_select("s", $tms);
$ret.="<input type=\"submit\" value=\"Do\" class=\"mktime_submit\">"; $ret.="</form></div>";
return $ret;
}
// private methods
function mk_time()
{
$fy=date("Y")-$this->y_delay[0];
$ly=date("Y")+$this->y_delay[1];
for($i=$fy; $i<=$ly; $i++)
{
$this->a['Y'][$i]=$i;
}
ksort($this->a['Y']);
$this->a['M']['Jan']=1;
$this->a['M']['Feb']=2;
$this->a['M']['Mar']=3;
$this->a['M']['Apr']=4;
$this->a['M']['May']=5;
$this->a['M']['Jun']=6;
$this->a['M']['Jul']=7;
$this->a['M']['Aug']=8;
$this->a['M']['Sep']=9;
$this->a['M']['Oct']=10;
$this->a['M']['Nov']=11;
$this->a['M']['Dec']=12;
$this->a['j']=range(0, 31);
foreach($this->a['j'] as $d)
{
$this->a['j'][$d]=$d;
}
$this->a['H']=range(0, 23);
foreach($this->a['H'] as $h)
{
$rh=$h<10 ? "0".$h : $h;
$this->a['H'][$rh]=$h;
if($h<10) { unset($this->a['H'][$h]); }
}
ksort($this->a['H'], SORT_STRING);
$this->a['i']=range(0, 59);
foreach($this->a['i'] as $p)
{
$rp=$p<10 ? "0".$p : $p ;
$this->a['i'][$rp]= $p;
if($p<10 ) { unset($this->a['i'][$p]); }
}
ksort($this->a['i'], SORT_STRING);
$this->a['s']=range(0, 59);
foreach($this->a['s'] as $s)
{
$rs=$s<10 ? "0".$s : $s ;
$this->a['s'][$rs]= $s;
if($s<10 ) { unset($this->a['s'][$s]); }
}
ksort($this->a['s'], SORT_STRING);
}
function make_select($k, $time=0)
{
if($time==0) { $t=time(); }
else { $t=$time; }
$ret="<select name=\"maketime[".$k."]\">\n";
foreach($this->a[$k] as $key => $v)
{
$ret.="<option value=\"".$v."\"";
if(isset($this->cor[$k])) { $cur=date($k, $t)+$this->cor[$k]; }
else { $cur=date($k, $t); }
if($key==$cur) { $ret.=" selected=\"selected\""; }
$ret.=">".$key."</option>\n";
}
$ret.="</select>\n";
return $ret;
}
}
?>