C
// 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')
?> »" /></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')
?> »" /></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', '') ?> »">
</div>
</td>
<td>
<div class="submit">
<input type="submit" name="update_event" value="<?php _e('Add Event', '') ?> »">
</div>
</td>
</tr>
</fieldset>
</table>
</fieldset>
</form>
</div><?php
}
add_action('admin_menu', 'calendar_admin');
?>