All pastes #372276 Raw Edit

nicola

public text v1 · immutable
#372276 ·published 2007-02-25 22:51 UTC
rendered paste body
<?php
/*
Plugin Name: Calendar
Plugin URI: http://n0id.hexium.net/plugins
Description: Nice and simple Calendar with events support and full customization:)
Author: Vanguard
Version: 2.0
Author URI: http://n0id.hexium.net/
*/ 

// mySQL table
$calendar_table = $table_prefix."calendar";

// default options
$calendar_defaults = array(

'bgcolor' => '#CACACA',
'shadow_color' => '#777777',
'weekdays_color' => '#000000',
'weekdays_bgcolor' => '#EAEAEA',
'weekend_bgcolor' => '#F6F6F6',
'weekend_textcolor' => '#000000',
'month_color' => '#000000',
'month_bgcolor' => '#FFFFFF',
'day_color' => '#FFFFFF',
'day_textcolor' => '#000000',
'today_color' => '#D0D0D0',
'today_textcolor' => '#000000',
'event_bgcolor' => '#F0F0F0',
'event_textcolor' => '#000000',
'event_bgcolor2' => '#FFFFFF',
'event_textcolor2' => '#000000',
'event_border' => '#000000',
'start_day' => '1',
);

// presets
// lightblue
$calendar_preset[lightblue] = array(

'bgcolor' => '#d6e6ff',
'shadow_color' => '#777777',
'weekdays_color' => '#333333',
'weekdays_bgcolor' => '#b5d2ff',
'weekend_bgcolor' => '#e9f2ff',
'weekend_textcolor' => '#333333',
'month_color' => '#333333',
'month_bgcolor' => '#FFFFFF',
'day_color' => '#FFFFFF',
'day_textcolor' => '#333333',
'today_color' => '#99BBFF',
'today_textcolor' => '#333333',
'event_bgcolor' => '#f1f6fe',
'event_textcolor' => '#000000',
'event_bgcolor2' => '#FFFFFF',
'event_textcolor2' => '#333333',
'event_border' => '#005581',
'start_day' => '1',
);

// red
$calendar_preset[red] = array(

'bgcolor' => '#FFFFFF',
'shadow_color' => '#a82727',
'weekdays_color' => '#ffffff',
'weekdays_bgcolor' => '#a82727',
'weekend_bgcolor' => '#eaa2a2',
'weekend_textcolor' => '#ffffff',
'month_color' => '#333333',
'month_bgcolor' => '#fff2f2',
'day_color' => '#ffe7e7',
'day_textcolor' => '#333333',
'today_color' => '#b93b3b',
'today_textcolor' => '#FFFFFF',
'event_bgcolor' => '#f9d3d3',
'event_textcolor' => '#000000',
'event_bgcolor2' => '#fff2f2',
'event_textcolor2' => '#333333',
'event_border' => '#a82727',
'start_day' => '1',
);

// light green
$calendar_preset[green] = array (

'bgcolor' => '#FFFFFF',
'shadow_color' => '#4c7f30',
'weekdays_color' => '#000000',
'weekdays_bgcolor' => '#aded8a',
'weekend_bgcolor' => '#c9eeb1',
'weekend_textcolor' => '#333333',
'month_color' => '#333333',
'month_bgcolor' => '#ffffff',
'day_color' => '#f4fcef',
'day_textcolor' => '#333333',
'today_color' => '#a8e283',
'today_textcolor' => '#000000',
'event_bgcolor' => '#d6f3c3',
'event_textcolor' => '#000000',
'event_bgcolor2' => '#f4fcef',
'event_textcolor2' => '#333333',
'event_border' => '#c9eeb1',
'start_day' => '1',
);

// gold
$calendar_preset[gold] = array (

'bgcolor' => '#FFFFFF',
'shadow_color' => '#cbc55b',
'weekdays_color' => '#000000',
'weekdays_bgcolor' => '#fff65e',
'weekend_bgcolor' => '#fff99d',
'weekend_textcolor' => '#333333',
'month_color' => '#333333',
'month_bgcolor' => '#ffffff',
'day_color' => '#fffdde',
'day_textcolor' => '#333333',
'today_color' => '#ffee00',
'today_textcolor' => '#000000',
'event_bgcolor' => '#fffbb3',
'event_textcolor' => '#000000',
'event_bgcolor2' => '#fffeea',
'event_textcolor2' => '#333333',
'event_border' => '#c8bd00',
'start_day' => '1',
);

// multi-color
$calendar_preset[multi] = array (

'bgcolor' => '#FFFFFF',
'shadow_color' => '#666666',
'weekdays_color' => '#ffffff',
'weekdays_bgcolor' => '#2b589d',
'weekend_bgcolor' => '#f6f6f6',
'weekend_textcolor' => '#ff0000',
'month_color' => '#333333',
'month_bgcolor' => '#ffffff',
'day_color' => '#f6f6f6',
'day_textcolor' => '#333333',
'today_color' => '#f6f6f6',
'today_textcolor' => '#0060ff',
'event_bgcolor' => '#f6f6f6',
'event_textcolor' => '#328400',
'event_bgcolor2' => '#ffffff',
'event_textcolor2' => '#333333',
'event_border' => '#000000',
'start_day' => '1',
);


// end of presets

if (!get_settings('calendar_options')) {
update_option('calendar_options',$calendar_defaults);
}

$calendar_options = get_settings('calendar_options');
//$calendar_options[start_day]=1;

calendar_check_table();

// internal function for multilang support

function _ee($locale, $default) {

if (__($locale) != $locale) { echo __($locale); }
else echo $default;
}

function build_calendar() {
global $calendar_options;
$month=date("n")+1+$_GET[month]; $year=date("Y"); $today=date("j");
// total days of the current month
$days=date("j", mktime(0,0,0,$month,0,$year));
// month starts on:

$starts=(date("w", mktime(0,0,0,($month-1),1,$year))+7);
if (!$calendar_options[start_day]) { $starts=$starts+1; }
$month_text=date("F", mktime(0,0,0,($month-1),1,$year));
echo "<table width=\"100%\" cellspacing=\"0\" cellpading=\"0\" border=\"0\"><tr><td>";
echo "<table width=\"100%\" bgcolor=\"$calendar_options[bgcolor]\" cellspacing=\"1\" cellpadding=\"2\" border=\"0\" style=\"font-face: Verdana; font-size: 11px; text-align: center;\">";
echo "<tr bgcolor=\"$calendar_options[month_bgcolor]\" style=\"color: $calendar_options[month_color];\"><td colspan=\"7\">";
echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">";
echo "<tr>";
echo "<td align=\"left\"><a href=\"?month=".($_GET[month]-1)."\"><img src=\"".get_settings('siteurl')."/wp-content/plugins/Calendar/images/arrow_left.gif\" style=\"padding-left: 5px;\" border=\"0\"></a></td>";
echo "<td align=\"center\">";
_e($month_text);
if ($_GET[month] <= (date("n")*(-1))) { echo " ".date("Y", mktime(0,0,0,($month-1),1,$year)); }
echo "</td>";
echo "<td align=\"right\"><a href=\"?month=".($_GET[month]+1)."\"><img src=\"".get_settings('siteurl')."/wp-content/plugins/Calendar/images/arrow_right.gif\" style=\"padding-right: 5px;\" border=\"0\"></a></td>";
echo "</tr></table>";
echo "</td></tr>";
if ($calendar_options[start_day]) {
echo "<tr bgcolor=\"$calendar_options[weekdays_bgcolor]\" style=\"color: $calendar_options[weekdays_color];\"><td align=\"center\">";
_ee('M_Monday_initial','M');
echo "</td><td align=\"center\">";
_ee('T_Tuesday_initial','T');
echo "</td><td align=\"center\">";
_ee('W_Wednesday_initial','W');
echo "</td>
<td align=\"center\">";
_ee('T_Thursday_initial','T');
echo "</td><td align=\"center\">";
_ee('F_Friday_initial','F');
echo "</td><td align=\"center\">";
_ee('S_Saturday_initial','S');
echo "</td><td align=\"center\">";
_ee('S_Sunday_initial','S');
echo "</td></tr>\n";
}
else {
echo "<tr bgcolor=\"$calendar_options[weekdays_bgcolor]\" style=\"color: $calendar_options[weekdays_color];\"><td align=\"center\">";
_ee('S_Sunday_initial','S');
echo "</td><td align=\"center\">";
_ee('M_Monday_initial','M');
echo "</td><td align=\"center\">";
_ee('T_Tuesday_initial','T');
echo "</td><td align=\"center\">";
_ee('W_Wednesday_initial','W');
echo "</td>
<td align=\"center\">";
_ee('T_Thursday_initial','T');
echo "</td><td align=\"center\">";
_ee('F_Friday_initial','F');
echo "</td><td align=\"center\">";
_ee('S_Saturday_initial','S');
echo "</td></tr>\n";
}

if ($starts > 7) { $starts=$starts-7; }
$calendar_edays="<tr bgcolor=\"$calendar_options[day_color]\" style=\"color: $calendar_options[day_textcolor];\">".str_repeat("<td>&nbsp;</td>", ($starts-1));

while ($day_count<$days) {
$starts++;
$day_events=count_events(mktime(0,0,0,($month-1),($day_count+1),$year));
if ($starts == 2) { echo "<tr bgcolor=\"$calendar_options[day_color]\" style=\"color: $calendar_options[day_textcolor];\">"; }
if ($day_count < 1) { echo $calendar_edays; }
if (($day_count+1 == $today) && !$_GET[month]) { 
 if ($day_events) { echo "<td bgcolor=\"$calendar_options[today_color]\" style=\"color: $calendar_options[event_textcolor];\""; }
 else { echo "<td bgcolor=\"$calendar_options[today_color]\" style=\"color: $calendar_options[today_textcolor];\""; }
}
elseif ($calendar_options[start_day] && $starts > 6) { 
if ($day_events) { echo "<td bgcolor=\"$calendar_options[event_bgcolor]\" style=\"color: $calendar_options[event_textcolor];\""; }
else { echo "<td bgcolor=\"$calendar_options[weekend_bgcolor]\" style=\"color: $calendar_options[weekend_textcolor];\""; }
}
elseif (!$calendar_options[start_day] && ($starts > 7 || $starts == 2)) {
if ($day_events) { echo "<td bgcolor=\"$calendar_options[event_bgcolor]\" style=\"color: $calendar_options[event_textcolor];\""; }
else { echo "<td bgcolor=\"$calendar_options[weekend_bgcolor]\" style=\"color: $calendar_options[weekend_textcolor];\""; }
}
else { 
if ($day_events) { echo "<td bgcolor=\"$calendar_options[event_bgcolor]\" style=\"color: $calendar_options[event_textcolor];\""; }
else { echo "<td "; }
}
if ($day_events) {

echo " onMouseOver=\"return _show('day_".($day_count+1)."');\" onMouseOut=\"_close('day_".($day_count+1)."'); return false;\"";
}
echo ">".($day_count+1)."</td>";
get_events(mktime(0,0,0,($month-1),($day_count+1),$year));
if ($starts > 7) { echo "</tr>\n"; $starts=1; }
$day_count++;
}
if ($starts < 7 && $starts > 1) {
echo "<td colspan=\"".(8-$starts)."\"></td></tr>";
}

// close table
echo "</table></td></tr></table>";
}

function write_javascript() {
?>
<script language="JavaScript" type="text/JavaScript">
<!--

var _top=0
var _left=0
var _eventopen=false

var distancecursorX=0 //Customize x offset of tooltip
var distancecursorY=0 //Customize y offset of tooltip

var offsetdivfrompointerX=5 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=5 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).


var ie=document.all
var ns6=document.getElementById && !document.all

function _show(_object) {

if (document.getElementById){
subobj=document.getElementById(_object)
_eventopen=true
//subobj.style.width = 200
//subobj.style.height = 100

subobj.style.left=_left
subobj.style.top=_top

subobj.style.display="block"
return false
}
else { return true }

}

function _close(subobj){
document.getElementById(subobj).style.display="none"
_eventopen=false
}
function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function mousepos(e) {

if (_eventopen){
var nondefaultpos=false
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

var rightedge=ie&&!window.opera? winwidth-event.clientX-distancecursorX : winwidth-e.clientX-distancecursorX
var bottomedge=ie&&!window.opera? winheight-event.clientY-distancecursorY : winheight-e.clientY-distancecursorY

var leftedge=(distancecursorX<0)? distancecursorX*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<subobj.offsetWidth){
//move the horizontal position of the menu to the left by it's width
subobj.style.left=curX-subobj.offsetWidth+"px"
nondefaultpos=true
}
else if (curX<leftedge)
subobj.style.left="5px"
else{
//position the horizontal position of the menu where the mouse is positioned
subobj.style.left=curX+distancecursorX-offsetdivfrompointerX+"px"

}

//same concept with the vertical position
if (bottomedge<subobj.offsetHeight){
subobj.style.top=curY-subobj.offsetHeight-distancecursorY+"px"
nondefaultpos=true
}
else{
subobj.style.top=curY+distancecursorY+offsetdivfrompointerY+"px"
}
subobj.style.visibility="visible"
}
// when _eventopen is false
else {

var nondefaultpos=false
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

var rightedge=ie&&!window.opera? winwidth-event.clientX-distancecursorX : winwidth-e.clientX-distancecursorX
var bottomedge=ie&&!window.opera? winheight-event.clientY-distancecursorY : winheight-e.clientY-distancecursorY

var leftedge=(distancecursorX<0)? distancecursorX*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<200){
//move the horizontal position of the menu to the left by it's width
_left=curX+"px"
nondefaultpos=true
}
else if (curX<leftedge)
_left="5px"
else{
//position the horizontal position of the menu where the mouse is positioned
_left=curX+distancecursorX-offsetdivfrompointerX+"px"

}

//same concept with the vertical position
if (bottomedge<100){
_top=curY-distancecursorY+"px"
nondefaultpos=true
}
else{
_top=curY+distancecursorY+offsetdivfrompointerY+"px"
}


// end of _eventopen == false
}


}
document.onmousemove=mousepos
//-->
</script>
<?
}
function count_events($timestamp) {
global $calendar_table;
$query=mysql_query("SELECT * FROM $calendar_table WHERE timestamp >= $timestamp AND timestamp < ($timestamp + 86400)");
$events=mysql_num_rows($query);
return $events;
}

function get_events($timestamp) {
global $calendar_options, $calendar_table;
$query=mysql_query("SELECT * FROM $calendar_table WHERE timestamp >= $timestamp AND timestamp < ($timestamp + 86400)");
$events=mysql_num_rows($query);
if ($events > 0) {
echo "<div id=\"day_".date("j", $timestamp)."\" style=\"display: none; position: absolute; width:200px; height:".($events*50)."px; z-index:1; left: 245px; top: 70px; border: 1px solid $calendar_options[event_border]; padding: 5px; font-size: 11px; background: $calendar_options[event_bgcolor2]; filter: progid:DXImageTransform.Microsoft.Shadow(color=$calendar_options[shadow_color],direction=135, strength=4);\">"; 
echo "<span style=\"background: url(".get_settings('siteurl')."/wp-content/plugins/Calendar/images/dot.gif) repeat-x bottom;\"><b>Events for</b>: ".date("jS F Y",$timestamp)."</span>";
echo "<div style=\"padding-top: 5px; margin-top: 0px; margin-bottom: 0px;\">";
while ($day_events=mysql_fetch_array($query)) {
echo $day_events[text]."<br>";
}
echo "</div></div>";
}
}

function do_calendar() {
 write_javascript();
 build_calendar();
}

function calendar_check_table() {
global $calendar_table;

$query=mysql_query("SHOW TABLES");

while ($fetch=mysql_fetch_array($query)) {
if ($fetch[0] == $calendar_table) { return; }
}
// table does not exists. creating.
mysql_query("

CREATE TABLE `$calendar_table` (
  `timestamp` int(11) NOT NULL default '0',
  `type` varchar(255) NOT NULL default '',
  `text` text NOT NULL,
  PRIMARY KEY  (`timestamp`),
  UNIQUE KEY `timestamp` (`timestamp`)
) TYPE=MyISAM COMMENT='wordpress Calendar plugin by Vanguard'
");


}

// administration panel

function calendar_admin() {
    if (function_exists('add_options_page')) {
add_options_page('Calendar Options', 'Calendar', 8, basename(__FILE__), 'calendar_admin_page');
    }
 }

function calendar_admin_page() {
global $calendar_options, $calendar_defaults, $calendar_table, $calendar_preset;

if (isset($_POST['theme_update'])) {

switch ($_POST[theme]) {
case '1': $update_options=$calendar_defaults; break;
case '2': $update_options=$calendar_preset[lightblue]; break;
case '3': $update_options=$calendar_preset[red]; break;
case '4': $update_options=$calendar_preset[green]; break;
case '5': $update_options=$calendar_preset[gold]; break;
case '6': $update_options=$calendar_preset[multi]; break;
default:
$update_options=$calendar_defaults;
}

update_option('calendar_options',$update_options);
$calendar_options = get_settings('calendar_options');
    ?><div class="updated"><p><strong><?php 
_e('Calendar Preset applied!','');
echo "</strong></p></div>";
}
  if (isset($_POST['info_update'])) {
    ?><div class="updated"><p><strong><?php 
_e('Calendar settings successfully updated!','');

// updating settings.
$updated_options=array(
'bgcolor' => $_POST['bgcolor'],
'shadow_color' => $_POST['shadow_color'],
'weekdays_color' => $_POST['weekdays_color'],
'weekdays_bgcolor' => $_POST['weekdays_bgcolor'],
'weekend_bgcolor' => $_POST['weekend_bgcolor'],
'weekend_textcolor' => $_POST['weekend_textcolor'],
'month_color' => $_POST['month_color'],
'month_bgcolor' => $_POST['month_bgcolor'],
'day_color' => $_POST['day_color'],
'day_textcolor' => $_POST['day_textcolor'],
'today_color' => $_POST['today_color'],
'today_textcolor' => $_POST['today_textcolor'],
'event_bgcolor' => $_POST['event_bgcolor'],
'event_textcolor' => $_POST['event_textcolor'],
'event_bgcolor2' => $_POST['event_bgcolor2'],
'event_textcolor2' => $_POST['event_textcolor2'],
'event_border' => $_POST['event_border'],
'start_day' => $_POST['start_day'],
);
update_option('calendar_options',$updated_options);
$calendar_options = get_settings('calendar_options');
    ?></strong></p></div><?php
	} 
if (isset($_POST['update_event'])) {
?><div class="updated"><p><strong>
<? 
$time=explode(":",$_POST['time']);
$timestamp=mktime($time[0],$time[1],0,$_POST[month], $_POST[day], $_POST[year]);
$event_text=nl2br($_POST[text]);
if ($_POST[updating] == 1) {
$total=mysql_num_rows(mysql_query("SELECT * FROM $calendar_table WHERE timestamp = '$timestamp'"));
if ($total > 0) {
mysql_query("UPDATE $calendar_table SET text = '$event_text' WHERE timestamp = '$timestamp'");
_e('Calendar event successfully updated!','');
}
else { 
mysql_query("INSERT INTO $calendar_table VALUES('$timestamp','note','$event_text')");
_e('Calendar event successfully added!','');
}

}
else { 
mysql_query("INSERT INTO $calendar_table VALUES('$timestamp','note','$event_text')"); 
_e('Calendar event successfully added!','');
}
echo "</strong></p></div>";
}
if (isset($_POST[remove_event])) {

$i=0;
$events_array=$_POST[events];
while(list($key,$val) = each($events_array)) {
mysql_query("DELETE FROM $calendar_table WHERE timestamp = $val");
//echo "deleting: $key - $val<br>";
$i++;
}
echo "<div class=\"updated\"><p><strong>";
_e('Calendar event(s) deleted!','');
echo "</strong></p></div>";
}
?>
<div class=wrap>
  <form name="calendar" method="post">
    <h2>Calendar Options</h2>
     <fieldset name="set">
	<legend><?php _e('Predefined Themes') ?></legend>
<p>The options listed below ARE presets. If you want to customize one of these presets first you have to 'apply' 
it and then change its values on the Display Settings.</p>
<table width="100%" cellspacing="2" cellpadding="5" style="text-align: left;">
<tr valign="top">
<th scope="row" width="196"><input type="radio" name="theme" value="1"> grey (default)</th>
<th scope="row" width="196"><input type="radio" name="theme" value="2"> light blue</th>
<th scope="row" width="196"><input type="radio" name="theme" value="3"> red</th>
</tr>
<tr>
<td><img src="<? echo get_settings('siteurl') ?>/wp-content/plugins/Calendar/images/previews/grey.gif"></td>
<td><img src="<? echo get_settings('siteurl') ?>/wp-content/plugins/Calendar/images/previews/lightblue.gif"></td>
<td><img src="<? echo get_settings('siteurl') ?>/wp-content/plugins/Calendar/images/previews/red.gif"></td>
</tr>
<tr valign="top">
<th scope="row" width="196"><input type="radio" name="theme" value="4"> light green</th>
<th scope="row" width="196"><input type="radio" name="theme" value="5"> gold</th>
<th scope="row" width="196"><input type="radio" name="theme" value="6"> multi color</th>
</tr>
<tr>
<td><img src="<? echo get_settings('siteurl') ?>/wp-content/plugins/Calendar/images/previews/lightgreen.gif"></td>
<td><img src="<? echo get_settings('siteurl') ?>/wp-content/plugins/Calendar/images/previews/gold.gif"></td>
<td><img src="<? echo get_settings('siteurl') ?>/wp-content/plugins/Calendar/images/previews/multi.gif"></td>
</tr>

</table>
     </fieldset>
<div class="submit">
  <input type="submit" name="theme_update" value="<?php
    _e('Apply Preset')
	?> &raquo;" /></div>
     <fieldset name="set1">
	<legend><?php _e('Display Settings') ?></legend>
<p>Here you can customize the visual of this plugin. All colors are in <a href="http://en.wikipedia.org/wiki/Web_colors" target="_blank">hexadecimal</a> format.<br>
Any questions please report to this <a href="http://n0id.hexium.net/plugins" target="_blank">plugin website</a>.</p>
<table width="100%" cellspacing="2" cellpadding="5" style="text-align: left;">
<tr valign="top">
<th scope="row" width="200">background:</th>
<td><input name="bgcolor" value="<? echo $calendar_options[bgcolor]; ?>"></td>
<th scope="row" width="200">week days text color:</th>
<td><input name="weekdays_color" value="<? echo $calendar_options[weekdays_color]; ?>"></td></tr>
<tr valign="top">
<th scope="row">week days background:</th>
<td><input name="weekdays_bgcolor" value="<? echo $calendar_options[weekdays_bgcolor]; ?>"></td>
<th scope="row">weekend background:</th>
<td><input name="weekend_bgcolor" value="<? echo $calendar_options[weekend_bgcolor] ?>"></td></tr>
<tr valign="top">
<th scope="row">weekend text color:</th>
<td><input name="weekend_textcolor" value="<? echo $calendar_options[weekend_textcolor] ?>"></td>
<th scope="row">month text color:</th>
<td><input name="month_color" value="<? echo $calendar_options[month_color] ?>"></td></tr>
<tr valign="top">
<th scope="row">month background:</th>
<td><input name="month_bgcolor" value="<? echo $calendar_options[month_bgcolor] ?>"></td>
<th scope="row">day background:</th>
<td><input name="day_color" value="<? echo $calendar_options[day_color] ?>"></td></tr>
<tr valign="top">
<th scope="row">day text color:</th>
<td><input name="day_textcolor" value="<? echo $calendar_options[day_textcolor] ?>"></td>
<th scope="row">today background:</th>
<td><input name="today_color" value="<? echo $calendar_options[today_color] ?>"></td></tr>
<tr valign="top">
<th scope="row">today text color:</th>
<td><input name="today_textcolor" value="<? echo $calendar_options[today_textcolor] ?>"></td>
<th scope="row">event day background:</th>
<td><input name="event_bgcolor" value="<? echo $calendar_options[event_bgcolor] ?>"></td></tr>
<tr valign="top">
<th scope="row">event day text color:</th>
<td><input name="event_textcolor" value="<? echo $calendar_options[event_textcolor] ?>"></td>
<th scope="row">event layer background:</th>
<td><input name="event_bgcolor2" value="<? echo $calendar_options[event_bgcolor2] ?>"></td></tr>
<tr valign="top">
<th scope="row">event layer text color:</th>
<td><input name="event_textcolor2" value="<? echo $calendar_options[event_textcolor2] ?>"></td>
<th scope="row">event layer border color:</th>
<td><input name="event_border" value="<? echo $calendar_options[event_border] ?>"></td></tr>

<tr valign="top">
<th scope="row">shadow color:</th>
<td><input name="shadow_color" value="<? echo $calendar_options[shadow_color] ?>"></td>
</tr>
<tr valign="top">
<th scope="row">week starts on monday</th>
<td><input type="checkbox" name="start_day" value="1" <? if ($calendar_options[start_day]) echo "checked"; ?>></td></tr>

</table>
     </fieldset>

<div class="submit">
<input type="submit" name="info_update" value="<?php
    _e('Update options')
	?> &raquo;" /></div>

     <fieldset name="set2">
	<legend><?php _e('Manage Events', '') ?></legend>
<p>Here you can manage all of your events. Add, Edit and Remove.</p>
<script language="JavaScript" type="text/JavaScript">
<!--

function wp_calendar_edit(_day,_month,_year,_time,_text) {

document.calendar.day.value = _day; 
document.calendar.month.value = _month;
document.calendar.year.value = _year;
document.calendar.time.value = _time;
document.calendar.text.value = _text;
document.calendar.updating.value = 1;
}
//-->
</script>
<table width="100%" valign="top" cellspacing="2" cellpadding="1" style="text-align: left;">
<tr><td><h3 class="unapproved">Remove</h3></td><td><h3 class="unapproved">Add/Edit</h3></td></tr>
<tr><td valign="top" width="500">
<div style="height: 200px; width: 95%; overflow: auto; margin: 0px;">
<table cellspacing="0" cellpadding="0" border="0">
<tr><td>
<?
$query=mysql_query("SELECT * FROM $calendar_table ORDER BY timestamp DESC");
$events_total=mysql_num_rows($query);
if ($events_total > 0) {

while ($fetch=mysql_fetch_array($query)) {

if (!$current) { $current=date("jS F", $fetch[timestamp]); echo "<b>".date("jS F",$fetch[timestamp])."</b><ul>"; }
if ($current != date("jS F", $fetch[timestamp])) { echo "</ul><b>\n".date("jS F",$fetch[timestamp])."</b><ul>"; $current=date("jS F", $fetch[timestamp]); }

echo "<img onClick=\"wp_calendar_edit('".date("j",$fetch[timestamp])."','".date("m",$fetch[timestamp])."','".date("Y",$fetch[timestamp])."','".date("H:i",$fetch[timestamp])."','$fetch[text]')\" src=\"../wp-content/plugins/Calendar/images/edit.gif\" alt=\"edit this event\" style=\"position: middle; cursor: hand;\"><input type=\"checkbox\" name=\"events[]\" value=\"$fetch[timestamp]\"> $fetch[text]<br>";
}

}
?>
</td></tr>
</table>
</div>
</td>
<fieldset name="set3">
<td valign="top">
Timestamp:<br>
<input name="day" title="day of the month" value="<? echo date("j"); ?>" size="2"> <input name="month" title="month of the year" value="<? echo date("m"); ?>" size="2"> <input name="year" title="year" value="<? echo date("Y"); ?>" size="4">
at <input name="time" title="time" value="<? echo date("H:i"); ?>" style="width: 40px">
<br><br>
Event:<br>
<textarea name="text" rows="8" style="width: 97%"></textarea>
<input type="hidden" name="updating" value="0">
</td></tr>
<tr><td>
<div class="submit" style="padding-right: 20px;">
<input type="submit" name="remove_event" value="<?php _e('Remove', '') ?> &raquo;">
</div>
</td>
<td>
<div class="submit">
<input type="submit" name="update_event" value="<?php _e('Add Event', '') ?> &raquo;">
</div>
</td>
</tr>
</fieldset>
</table>
     </fieldset>
  </form>
 </div><?php

}

add_action('admin_menu', 'calendar_admin');
?>