Toolcube - A Simons Location Ad
News S2 Work
Interests Other About
  My Calendar

What's New

Calendar

Events


I maintain a calendar so freinds, family, co-workers, and clients can keep up with where I might be on a given week.

          <% /* Steve Simons - simons@toolcube.com ©2000. All rights reserved. mySQL Table: CREATE table calendar ( uid bigint(20) auto_increment primary key, datestart date not null, dateend date not null, timestart time not null, timeend time not null, every int(5) unsigned not null default '0', calkey varchar(20) not null, graphic varchar(128) not null, event varchar(128) not null, link varchar(128) not null, linktarget varchar(20) not null, key datestart (datestart), key dateend (dateend), key calkey (calkey) ); 3/14/2000 - Original 6/20/2000 - Modified for myobjects support */ /* For a given array, return a string with the 'key=value' space delimited */ function array2keypairs( $array) { $str = ''; if (is_array($array)) { reset( $array); while ( list( $key) = each( $array ) ) { $substr = '\"'.str_replace('$','\$',$array[$key]).'\"'; if ( $substr != '') { eval( "\$str .= \"$key=$substr \";" ); } elseif ( $substr == '###') { $str .= "$key "; } } } else { $str = $array; } return $str; } function override( &$base, $over) { if ( is_array( $over)) { reset( $over); while (list($key, $value) = each( $over)) { if (is_array( $value)) { override( $base[$key], $value); } else { $base[ $key] = $value; } } } } function unixdate2array( $date) { /* Return unix timestamp in array( y,m,d,h,m,s) */ return explode( '-',date('Y-m-j-H-i-s',$date)); } function array2unixdate( $a) { /* Return unix timestamp from array( y,m,d,h,m,s) */ while (sizeof($a) < 6) { $a[] = '0'; } return mktime($a[5],$a[4],$a[3],$a[1],$a[2],$a[0]); } function addsubdate( $date, $days, $months=0, $years=0) { /* Add or subtract to the unixdate */ $adate = unixdate2array( $date); $adate[2] += $days; $adate[1] += $months; $adate[0] += $years; return array2unixdate( $adate); } function getevents(&$DB,&$settings,$date,$caledit=false,$target='') { $html=''; $mysqldate = date('Y-m-j',$date); if ($settings['KEY'] != '') { $keysearch = "(calkey='".str_replace(" ","'||calkey='",$settings['KEY'])."') && "; } $query = "SELECT event,link,linktarget,timestart,timeend,graphic,uid ". "FROM ".$settings['DBTABLE']." WHERE $keysearch". "(dateend='0000-00-00'||dateend>='$mysqldate') && ". "(datestart<='$mysqldate') && ". "((every='0'&&datestart='$mysqldate') || (to_days(datestart)-to_days('$mysqldate'))%every=0)". " ORDER BY timestart"; $DB->performquery($query); $e=array(); while ($DB->getnextrecord()) { list($event,$link,$linktarget,$timestart,$timeend,$graphic,$uid)=$DB->record; $picture=''; if ($graphic!='') { $picture="\"Hi\""; } $time=''; if ($timestart!='00:00:00') { $parts=explode(':',$timestart); $parts[2] = ($parts[0]>=12 ? 'pm' : 'am'); $parts[0] -= ($parts[0]>12 ? 12 : ($parts[0] == 0 ? -12 : 0)); $time="".$parts[0].':'.$parts[1].$parts[2]; if ($timeend!='00:00:00') { $parts=explode(':',$timeend); $parts[2] = ($parts[0]>=12 ? 'pm' : 'am'); $parts[0] -= ($parts[0]>12 ? 12 : ($parts[0] == 0 ? -12 : 0)); $time.='-'.$parts[0].':'.$parts[1].$parts[2]; } $time.="
  "; } if ($caledit) { $link = _RETURNLINK_.$caledit; appendtourl($link,_QUERYKEY_,$uid); $e[]=$picture.$time.getbutton('Edit','',$event,$link,'',$target); } elseif ($link=='') { $e[]=$picture.$time."$event"; } else { $e[]=($picture==''?'':"$picture"). $time."$event"; } } $html = implode($e,'
'); return $html; } function calendar($specs='',$caledit=false,$edittarget='_blank') { $settings = array ( 'DBHOST' => 'localhost', /* Host of database */ 'DBUSER' => 'nobody', /* User to select data */ 'DBPSWD' => '', /* Password if required */ 'DB' => 'test', /* Database to connect */ 'DBTABLE' => 'calendar', /* Table in database */ 'START' => '', /* Blank for now, or m/d/y format */ 'WEEKS' => '8', /* Weeks to display */ 'KEY' => '', /* Blank is all events, sep multiple keys with space */ 'WIDTHS' => array ( '15%','14%','14%','14%','14%','14%','15%'), 'DATEFONT' => array ( 'SIZE' => '4', 'COLOR' => 'darkblue' ), 'TIMEFONT' => array ( 'SIZE' => '2', 'COLOR' => 'darkblue' ), 'EVENTFONT' => array ( 'SIZE' => '2' ), 'MONTHFONT' => array ( 'SIZE' => '5', 'COLOR' => 'darkblue' ), 'MONTHTITLE'=> array ( 'BGCOLOR' => '#CCCCCC' ), 'SHOWHEADER'=> 'Y', 'HEADERFONT'=> array ( 'SIZE' => '2', 'COLOR' => 'white' ), 'TABLE' => array ( 'BGCOLOR' => 'white', 'WIDTH' => '100%', 'BORDER' => '5', 'CELLSPACING' => '0', 'CELLPADDING' => '1' ), 'ROW' => array ( 'VALIGN' => 'top' ), 'CELL' => array ( 'ALIGN' => 'left', 'HEIGHT' => '60' ), 'GRAYCELL' => 'lightgrey' ); override( $settings, $specs); $begdate = explode( '/', str_replace('-','/',str_replace('.','/',$settings['START']))); if ( sizeof( $begdate) != 3) { /* Start date is today - get ride of hours/minutes */ $begdate = unixdate2array(mktime()); $calbeg = array2unixdate(array($begdate[0],$begdate[1],$begdate[2])); } else { $calbeg = array2unixdate(array($begdate[2],$begdate[0],$begdate[1])); } $week = 1; $newmonth = true; $tablestarted = false; $DB = new dbObj($settings['DB'],$settings['DBHOST'],$settings['DBUSER'],$settings['DBPSWD']); while ( $week < $settings['WEEKS']) { if ( $newmonth) { echo( ($tablestarted ? "

" : ""). "\n". "". "\n"); $tablestarted = true; $caldate = addsubdate( $calbeg, -date('w',$calbeg)); if ($settings['SHOWHEADER']='Y') { echo( ""); $cell = array('WIDTH'=>0,'ALIGN'=>'center','VALIGN'=>'middle'); for ($d=0;$d<7;$d++) { $cell['WIDTH'] = $settings['WIDTHS'][$d]; echo( "\n" ); } echo( "\n"); } $newmonth = false; } else { $week++; } echo( "\n"); for ( $d=0; $d<7; $d++) { $cell = $settings['CELL']; $cell['WIDTH'] = $settings['WIDTHS'][$d]; $data = ' '; if ((date('m',$caldate) > date('m',$calbeg) && date('Y',$caldate) == date('Y',$calbeg)) || date('Y',$caldate) > date('Y',$calbeg)) { $calbeg = $caldate; $newmonth = true; } if ( $newmonth) { $cell['BGCOLOR'] = $settings['GRAYCELL']; } else { if ( $caldate < $calbeg) { $cell['BGCOLOR'] = $settings['GRAYCELL']; } else { if ($settings['WIDTHS'][$d] != 0) { $date = date('d',$caldate); if ($caledit) { $link = _RETURNLINK_.$caledit; appendtourl($link,_DEFAULTSCHANGE_."[datestart]",date('Y-m-d',$caldate)); appendtourl($link,_DEFAULTSCHANGE_."[calkey]",$settings['KEY']); $date = getbutton(_NEWRECORD_,'',$date,$link,'a',$edittarget); } $data = "

${date}

"; $data .= getevents( $DB,$settings,$caldate,$caledit,$edittarget); } } $caldate = addsubdate( $caldate, 1); } echo( "\n"); } echo( "\n"); } echo( "

". date('F Y',$calbeg)."

"); if ($settings['WIDTHS'][$d] != 0) { echo( "

".date('l',addsubdate($caldate,$d))."

"); } echo( "
${data}
\n"); } %>