| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Calendar |
| 4 |
Plugin URI: http://www.kjowebservices.co.uk |
| 5 |
Description: This plugin allows you to display a calendar of all your events and appointments as a page on your site. |
| 6 |
Author: Kieran O'Shea |
| 7 |
Author URI: http://www.kjowebservices.co.uk |
| 8 |
Version: 1.2 |
| 9 |
*/ |
| 10 |
|
| 11 |
/* Copyright 2008 KJO Web Services (email : sales@kjowebservices.co.uk) |
| 12 |
|
| 13 |
This program is free software; you can redistribute it and/or modify |
| 14 |
it under the terms of the GNU General Public License as published by |
| 15 |
the Free Software Foundation; either version 2 of the License, or |
| 16 |
(at your option) any later version. |
| 17 |
|
| 18 |
This program is distributed in the hope that it will be useful, |
| 19 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 |
GNU General Public License for more details. |
| 22 |
|
| 23 |
You should have received a copy of the GNU General Public License |
| 24 |
along with this program; if not, write to the Free Software |
| 25 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 26 |
*/ |
| 27 |
|
| 28 |
// Define the tables used in Calendar |
| 29 |
define('WP_CALENDAR_TABLE', $table_prefix . 'calendar'); |
| 30 |
define('WP_CALENDAR_CONFIG_TABLE', $table_prefix . 'calendar_config'); |
| 31 |
define('WP_CALENDAR_CATEGORIES_TABLE', $table_prefix . 'calendar_categories'); |
| 32 |
|
| 33 |
// Create a master category for Calendar and its sub-pages |
| 34 |
add_action('admin_menu', 'calendar_menu'); |
| 35 |
|
| 36 |
// Enable the ability for the calendar to be loaded from pages |
| 37 |
add_filter('the_content','calendar_insert'); |
| 38 |
|
| 39 |
// Add the function that puts style information in the header |
| 40 |
add_action('wp_head', 'calendar_wp_head'); |
| 41 |
|
| 42 |
// Add the function that deals with deleted users |
| 43 |
add_action('delete_user', 'deal_with_deleted_user'); |
| 44 |
|
| 45 |
// Add the widgets if we are using version 2.5 |
| 46 |
add_action('widgets_init', 'widget_init_calendar_today'); |
| 47 |
add_action('widgets_init', 'widget_init_calendar_upcoming'); |
| 48 |
|
| 49 |
// Before we get on with the functions, we need to define the initial style used for Calendar |
| 50 |
|
| 51 |
// Function to deal with events posted by a user when that user is deleted |
| 52 |
function deal_with_deleted_user($id) |
| 53 |
{ |
| 54 |
global $wpdb; |
| 55 |
|
| 56 |
// This wouldn't work unless the database was up to date. Lets check. |
| 57 |
check_calendar(); |
| 58 |
|
| 59 |
// Do the query |
| 60 |
$wpdb->get_results("UPDATE ".WP_CALENDAR_TABLE." SET event_author=".$wpdb->get_var("SELECT MIN(ID) FROM ".$wpdb->prefix."users",0,0)." WHERE event_author=".$id); |
| 61 |
} |
| 62 |
|
| 63 |
// Function to add the calendar style into the header |
| 64 |
function calendar_wp_head() |
| 65 |
{ |
| 66 |
global $wpdb; |
| 67 |
|
| 68 |
// If the calendar isn't installed or upgraded this won't work |
| 69 |
check_calendar(); |
| 70 |
|
| 71 |
$styles = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='calendar_style'"); |
| 72 |
if (!empty($styles)) |
| 73 |
{ |
| 74 |
foreach ($styles as $style) |
| 75 |
{ |
| 76 |
echo '<style type="text/css"> |
| 77 |
<!-- |
| 78 |
'; |
| 79 |
echo $style->config_value.' |
| 80 |
'; |
| 81 |
echo '//--> |
| 82 |
</style> |
| 83 |
'; |
| 84 |
} |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
// Function to deal with adding the calendar menus |
| 89 |
function calendar_menu() |
| 90 |
{ |
| 91 |
global $wpdb; |
| 92 |
|
| 93 |
// We make use of the Calendar tables so we must have installed Calendar |
| 94 |
check_calendar(); |
| 95 |
|
| 96 |
// Set admin as the only one who can use Calendar for security |
| 97 |
$allowed_group = 'manage_options'; |
| 98 |
|
| 99 |
// Use the database to *potentially* override the above if allowed |
| 100 |
$configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='can_manage_events'"); |
| 101 |
if (!empty($configs)) |
| 102 |
{ |
| 103 |
foreach ($configs as $config) |
| 104 |
{ |
| 105 |
$allowed_group = $config->config_value; |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
// Add the admin panel pages for Calendar. Use permissions pulled from above |
| 110 |
if (function_exists('add_menu_page')) |
| 111 |
{ |
| 112 |
add_menu_page(__('Calendar'), __('Calendar'), $allowed_group, basename(__FILE__), 'edit_calendar'); |
| 113 |
} |
| 114 |
if (function_exists('add_submenu_page')) |
| 115 |
{ |
| 116 |
add_submenu_page('calendar.php', __('Manage Calendar'), __('Manage Calendar'), $allowed_group, basename(__FILE__), 'edit_calendar'); |
| 117 |
add_action( "admin_print_scripts", 'calendar_add_javascript' ); |
| 118 |
// Note only admin can change calendar options |
| 119 |
add_submenu_page('calendar.php', __('Manage Categories'), __('Manage Categories'), 'manage_options', 'manage-categories', 'manage_categories'); |
| 120 |
add_submenu_page('calendar.php', __('Calendar Config'), __('Calendar Options'), 'manage_options', 'calendar-config', 'edit_calendar_config'); |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
// Function to add the javascript to the admin header |
| 125 |
function calendar_add_javascript() |
| 126 |
{ |
| 127 |
//echo '<script type="text/javascript">'; |
| 128 |
//echo include('javascript.js'); |
| 129 |
//echo '</script>'; |
| 130 |
echo '<script type="text/javascript" src="'; |
| 131 |
bloginfo('url'); |
| 132 |
echo '/wp-content/plugins/calendar/javascript.js"></script> |
| 133 |
<script type="text/javascript">document.write(getCalendarStyles());</script>'; |
| 134 |
} |
| 135 |
|
| 136 |
// Function to deal with loading the calendar into pages |
| 137 |
function calendar_insert($content) |
| 138 |
{ |
| 139 |
if (preg_match('{CALENDAR}',$content)) |
| 140 |
{ |
| 141 |
$content = str_replace('{CALENDAR}',calendar(),$content); |
| 142 |
} |
| 143 |
return $content; |
| 144 |
} |
| 145 |
|
| 146 |
// Function to check what version of Calendar is installed and install if needed |
| 147 |
function check_calendar() |
| 148 |
{ |
| 149 |
// Checks to make sure Calendar is installed, if not it adds the default |
| 150 |
// database tables and populates them with test data. If it is, then the |
| 151 |
// version is checked through various means and if it is not up to date |
| 152 |
// then it is upgraded. |
| 153 |
|
| 154 |
// Lets see if this is first run and create us a table if it is! |
| 155 |
global $wpdb, $initial_style; |
| 156 |
|
| 157 |
// All this style info will go into the database on a new install |
| 158 |
// This looks nice in the Kubrick theme |
| 159 |
$initial_style = " .calnk a:hover { |
| 160 |
background-position:0 0; |
| 161 |
text-decoration:none; |
| 162 |
color:#000000; |
| 163 |
border-bottom:1px dotted #000000; |
| 164 |
} |
| 165 |
.calnk a:visited { |
| 166 |
text-decoration:none; |
| 167 |
color:#000000; |
| 168 |
border-bottom:1px dotted #000000; |
| 169 |
} |
| 170 |
.calnk a { |
| 171 |
text-decoration:none; |
| 172 |
color:#000000; |
| 173 |
border-bottom:1px dotted #000000; |
| 174 |
} |
| 175 |
.calnk a span { |
| 176 |
display:none; |
| 177 |
} |
| 178 |
.calnk a:hover span { |
| 179 |
color:#333333; |
| 180 |
background:#F6F79B; |
| 181 |
display:block; |
| 182 |
position:absolute; |
| 183 |
margin-top:1px; |
| 184 |
padding:5px; |
| 185 |
width:150px; |
| 186 |
z-index:100; |
| 187 |
} |
| 188 |
.calendar-table { |
| 189 |
border:none; |
| 190 |
width:100%; |
| 191 |
} |
| 192 |
.calendar-heading { |
| 193 |
height:25px; |
| 194 |
align:center; |
| 195 |
border:1px solid #D6DED5; |
| 196 |
background-color:#E4EBE3; |
| 197 |
} |
| 198 |
.calendar-next { |
| 199 |
width:25%; |
| 200 |
text-align:center; |
| 201 |
} |
| 202 |
.calendar-prev { |
| 203 |
width:25%; |
| 204 |
text-align:center; |
| 205 |
} |
| 206 |
.calendar-month { |
| 207 |
width:50%; |
| 208 |
text-align:center; |
| 209 |
font-weight:bold; |
| 210 |
} |
| 211 |
.normal-day-heading { |
| 212 |
text-align:center; |
| 213 |
width:25px; |
| 214 |
height:25px; |
| 215 |
font-size:0.8em; |
| 216 |
border:1px solid #DFE6DE; |
| 217 |
background-color:#EBF2EA; |
| 218 |
} |
| 219 |
.weekend-heading { |
| 220 |
text-align:center; |
| 221 |
width:25px; |
| 222 |
height:25px; |
| 223 |
font-size:0.8em; |
| 224 |
border:1px solid #DFE6DE; |
| 225 |
background-color:#EBF2EA; |
| 226 |
color:#FF0000; |
| 227 |
} |
| 228 |
.day-with-date { |
| 229 |
vertical-align:text-top; |
| 230 |
text-align:left; |
| 231 |
width:60px; |
| 232 |
height:60px; |
| 233 |
border:1px solid #DFE6DE; |
| 234 |
} |
| 235 |
.no-events { |
| 236 |
|
| 237 |
} |
| 238 |
.day-without-date { |
| 239 |
width:60px; |
| 240 |
height:60px; |
| 241 |
border:1px solid #E9F0E8; |
| 242 |
} |
| 243 |
span.weekend { |
| 244 |
color:#FF0000; |
| 245 |
} |
| 246 |
.current-day { |
| 247 |
vertical-align:text-top; |
| 248 |
text-align:left; |
| 249 |
width:60px; |
| 250 |
height:60px; |
| 251 |
border:1px solid #BFBFBF; |
| 252 |
background-color:#E4EBE3; |
| 253 |
} |
| 254 |
span.event { |
| 255 |
font-size:0.75em; |
| 256 |
} |
| 257 |
.kjo-link { |
| 258 |
font-size:0.75em; |
| 259 |
text-align:center; |
| 260 |
} |
| 261 |
.event-title { |
| 262 |
text-align:center; |
| 263 |
font-weight:bold; |
| 264 |
font-size:1.2em; |
| 265 |
} |
| 266 |
.event-title-break { |
| 267 |
width:96%; |
| 268 |
margin-left:2%; |
| 269 |
margin-right:2%; |
| 270 |
margin-top:5px; |
| 271 |
margin-bottom:5px; |
| 272 |
text-align:center; |
| 273 |
height:1px; |
| 274 |
background-color:#000000; |
| 275 |
} |
| 276 |
.event-content-break { |
| 277 |
width:96%; |
| 278 |
margin-left:2%; |
| 279 |
margin-right:2%; |
| 280 |
margin-top:5px; |
| 281 |
margin-bottom:5px; |
| 282 |
text-align:center; |
| 283 |
height:1px; |
| 284 |
background-color:#000000; |
| 285 |
} |
| 286 |
.calendar-date-switcher { |
| 287 |
height:25px; |
| 288 |
align:center; |
| 289 |
border:1px solid #D6DED5; |
| 290 |
background-color:#E4EBE3; |
| 291 |
} |
| 292 |
.calendar-date-switcher form { |
| 293 |
margin:0; |
| 294 |
padding:0; |
| 295 |
} |
| 296 |
.calendar-date-switcher input { |
| 297 |
border:1px #D6DED5 solid; |
| 298 |
} |
| 299 |
.calendar-date-switcher select { |
| 300 |
border:1px #D6DED5 solid; |
| 301 |
} |
| 302 |
.cat-key { |
| 303 |
width:100%; |
| 304 |
margin-top:10px; |
| 305 |
padding:5px; |
| 306 |
border:1px solid #D6DED5; |
| 307 |
}"; |
| 308 |
|
| 309 |
|
| 310 |
// Assume this is not a new install until we prove otherwise |
| 311 |
$new_install = false; |
| 312 |
$vone_point_one_upgrade = false; |
| 313 |
$vone_point_two_beta_upgrade = false; |
| 314 |
|
| 315 |
$wp_calendar_exists = false; |
| 316 |
$wp_calendar_config_exists = false; |
| 317 |
$wp_calendar_config_version_number_exists = false; |
| 318 |
|
| 319 |
// Determine the calendar version |
| 320 |
$tables = $wpdb->get_results("show tables;"); |
| 321 |
foreach ( $tables as $table ) |
| 322 |
{ |
| 323 |
foreach ( $table as $value ) |
| 324 |
{ |
| 325 |
if ( $value == WP_CALENDAR_TABLE ) |
| 326 |
{ |
| 327 |
$wp_calendar_exists = true; |
| 328 |
} |
| 329 |
if ( $value == WP_CALENDAR_CONFIG_TABLE ) |
| 330 |
{ |
| 331 |
$wp_calendar_config_exists = true; |
| 332 |
|
| 333 |
// We now try and find the calendar version number |
| 334 |
// This will be a lot easier than finding other stuff |
| 335 |
// in the future. |
| 336 |
$version_number = $wpdb->get_var("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='calendar_version'"); |
| 337 |
if ($version_number == "1.2") |
| 338 |
{ |
| 339 |
$wp_calendar_config_version_number_exists = true; |
| 340 |
} |
| 341 |
} |
| 342 |
} |
| 343 |
} |
| 344 |
|
| 345 |
if ($wp_calendar_exists == false && $wp_calendar_config_exists == false) |
| 346 |
{ |
| 347 |
$new_install = true; |
| 348 |
} |
| 349 |
else if ($wp_calendar_exists == true && $wp_calendar_config_exists == false) |
| 350 |
{ |
| 351 |
$vone_point_one_upgrade = true; |
| 352 |
} |
| 353 |
else if ($wp_calendar_exists == true && $wp_calendar_config_exists == true && $wp_calendar_config_version_number_exists == false) |
| 354 |
{ |
| 355 |
$vone_point_two_beta_upgrade = true; |
| 356 |
} |
| 357 |
|
| 358 |
// Now we've determined what the current install is or isn't |
| 359 |
// we perform operations according to the findings |
| 360 |
if ( $new_install == true ) |
| 361 |
{ |
| 362 |
$sql = "CREATE TABLE " . WP_CALENDAR_TABLE . " ( |
| 363 |
event_id INT(11) NOT NULL AUTO_INCREMENT , |
| 364 |
event_begin DATE NOT NULL , |
| 365 |
event_end DATE NOT NULL , |
| 366 |
event_title VARCHAR(30) NOT NULL , |
| 367 |
event_desc TEXT NOT NULL , |
| 368 |
event_time TIME , |
| 369 |
event_recur CHAR(1) , |
| 370 |
event_repeats INT(3) , |
| 371 |
event_author BIGINT(20) UNSIGNED, |
| 372 |
PRIMARY KEY (event_id) |
| 373 |
)"; |
| 374 |
$wpdb->get_results($sql); |
| 375 |
$sql = "CREATE TABLE " . WP_CALENDAR_CONFIG_TABLE . " ( |
| 376 |
config_item VARCHAR(30) NOT NULL , |
| 377 |
config_value TEXT NOT NULL , |
| 378 |
PRIMARY KEY (config_item) |
| 379 |
)"; |
| 380 |
$wpdb->get_results($sql); |
| 381 |
$sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='can_manage_events', config_value='edit_posts'"; |
| 382 |
$wpdb->get_results($sql); |
| 383 |
$sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='calendar_style', config_value='".$initial_style."'"; |
| 384 |
$wpdb->get_results($sql); |
| 385 |
$sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='display_author', config_value='false'"; |
| 386 |
$wpdb->get_results($sql); |
| 387 |
$sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='display_jump', config_value='false'"; |
| 388 |
$wpdb->get_results($sql); |
| 389 |
$sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='display_todays', config_value='true'"; |
| 390 |
$wpdb->get_results($sql); |
| 391 |
$sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='display_upcoming', config_value='true'"; |
| 392 |
$wpdb->get_results($sql); |
| 393 |
$sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='display_upcoming_days', config_value=7"; |
| 394 |
$wpdb->get_results($sql); |
| 395 |
|
| 396 |
$sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='calendar_version', config_value='1.2'"; |
| 397 |
$wpdb->get_results($sql); |
| 398 |
$sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='enable_categories', config_value='false'"; |
| 399 |
$wpdb->get_results($sql); |
| 400 |
$sql = "ALTER TABLE ".WP_CALENDAR_TABLE." ADD COLUMN event_category BIGINT(20) UNSIGNED"; |
| 401 |
$wpdb->get_results($sql); |
| 402 |
$sql = "UPDATE " . WP_CALENDAR_TABLE . " SET event_category=1"; |
| 403 |
$wpdb->get_results($sql); |
| 404 |
$sql = "ALTER TABLE ".WP_CALENDAR_TABLE." ADD COLUMN event_link TEXT"; |
| 405 |
$wpdb->get_results($sql); |
| 406 |
$sql = "UPDATE " . WP_CALENDAR_TABLE . " SET event_link=''"; |
| 407 |
$wpdb->get_results($sql); |
| 408 |
$sql = "CREATE TABLE " . WP_CALENDAR_CATEGORIES_TABLE . " ( |
| 409 |
category_id INT(11) NOT NULL AUTO_INCREMENT, |
| 410 |
category_name VARCHAR(30) NOT NULL , |
| 411 |
category_colour VARCHAR(30) NOT NULL , |
| 412 |
PRIMARY KEY (category_id) |
| 413 |
)"; |
| 414 |
$wpdb->get_results($sql); |
| 415 |
$sql = "INSERT INTO " . WP_CALENDAR_CATEGORIES_TABLE . " SET category_id=0, category_name='General', category_colour='#F6F79B'"; |
| 416 |
$wpdb->get_results($sql); |
| 417 |
} |
| 418 |
else if ($vone_point_one_upgrade == true) |
| 419 |
{ |
| 420 |
$sql = "ALTER TABLE ".WP_CALENDAR_TABLE." ADD COLUMN event_author BIGINT(20) UNSIGNED"; |
| 421 |
$wpdb->get_results($sql); |
| 422 |
$sql = "UPDATE ".WP_CALENDAR_TABLE." SET event_author=".$wpdb->get_var("SELECT MIN(ID) FROM ".$wpdb->prefix."users",0,0); |
| 423 |
$wpdb->get_results($sql); |
| 424 |
$sql = "ALTER TABLE ".WP_CALENDAR_TABLE." MODIFY event_desc TEXT NOT NULL"; |
| 425 |
$wpdb->get_results($sql); |
| 426 |
$sql = "CREATE TABLE " . WP_CALENDAR_CONFIG_TABLE . " ( |
| 427 |
config_item VARCHAR(30) NOT NULL , |
| 428 |
config_value TEXT NOT NULL , |
| 429 |
PRIMARY KEY (config_item) |
| 430 |
)"; |
| 431 |
$wpdb->get_results($sql); |
| 432 |
$sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='can_manage_events', config_value='edit_posts'"; |
| 433 |
$wpdb->get_results($sql); |
| 434 |
$sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='calendar_style', config_value='".$initial_style."'"; |
| 435 |
$wpdb->get_results($sql); |
| 436 |
$sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='display_author', config_value='false'"; |
| 437 |
$wpdb->get_results($sql); |
| 438 |
$sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='display_jump', config_value='false'"; |
| 439 |
$wpdb->get_results($sql); |
| 440 |
$sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='display_todays', config_value='true'"; |
| 441 |
$wpdb->get_results($sql); |
| 442 |
$sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='display_upcoming', config_value='true'"; |
| 443 |
$wpdb->get_results($sql); |
| 444 |
$sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='display_upcoming_days', config_value=7"; |
| 445 |
$wpdb->get_results($sql); |
| 446 |
|
| 447 |
$sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='calendar_version', config_value='1.2'"; |
| 448 |
$wpdb->get_results($sql); |
| 449 |
$sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='enable_categories', config_value='false'"; |
| 450 |
$wpdb->get_results($sql); |
| 451 |
$sql = "ALTER TABLE ".WP_CALENDAR_TABLE." ADD COLUMN event_category BIGINT(20) UNSIGNED"; |
| 452 |
$wpdb->get_results($sql); |
| 453 |
$sql = "UPDATE " . WP_CALENDAR_TABLE . " SET event_category=1"; |
| 454 |
$wpdb->get_results($sql); |
| 455 |
$sql = "ALTER TABLE ".WP_CALENDAR_TABLE." ADD COLUMN event_link TEXT"; |
| 456 |
$wpdb->get_results($sql); |
| 457 |
$sql = "UPDATE " . WP_CALENDAR_TABLE . " SET event_link=''"; |
| 458 |
$wpdb->get_results($sql); |
| 459 |
$sql = "CREATE TABLE " . WP_CALENDAR_CATEGORIES_TABLE . " ( |
| 460 |
category_id INT(11) NOT NULL AUTO_INCREMENT, |
| 461 |
category_name VARCHAR(30) NOT NULL , |
| 462 |
category_colour VARCHAR(30) NOT NULL , |
| 463 |
PRIMARY KEY (category_id) |
| 464 |
)"; |
| 465 |
$wpdb->get_results($sql); |
| 466 |
$sql = "INSERT INTO " . WP_CALENDAR_CATEGORIES_TABLE . " SET category_id=0, category_name='General', category_colour='#F6F79B'"; |
| 467 |
$wpdb->get_results($sql); |
| 468 |
} |
| 469 |
else if ($vone_point_two_beta_upgrade == true) |
| 470 |
{ |
| 471 |
$sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='calendar_version', config_value='1.2'"; |
| 472 |
$wpdb->get_results($sql); |
| 473 |
$sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='enable_categories', config_value='false'"; |
| 474 |
$wpdb->get_results($sql); |
| 475 |
$sql = "ALTER TABLE ".WP_CALENDAR_TABLE." ADD COLUMN event_category BIGINT(20) UNSIGNED"; |
| 476 |
$wpdb->get_results($sql); |
| 477 |
$sql = "UPDATE " . WP_CALENDAR_TABLE . " SET event_category=1"; |
| 478 |
$wpdb->get_results($sql); |
| 479 |
$sql = "ALTER TABLE ".WP_CALENDAR_TABLE." ADD COLUMN event_link TEXT"; |
| 480 |
$wpdb->get_results($sql); |
| 481 |
$sql = "UPDATE " . WP_CALENDAR_TABLE . " SET event_link=''"; |
| 482 |
$wpdb->get_results($sql); |
| 483 |
$sql = "CREATE TABLE " . WP_CALENDAR_CATEGORIES_TABLE . " ( |
| 484 |
category_id INT(11) NOT NULL AUTO_INCREMENT, |
| 485 |
category_name VARCHAR(30) NOT NULL , |
| 486 |
category_colour VARCHAR(30) NOT NULL , |
| 487 |
PRIMARY KEY (category_id) |
| 488 |
)"; |
| 489 |
$wpdb->get_results($sql); |
| 490 |
$sql = "INSERT INTO " . WP_CALENDAR_CATEGORIES_TABLE . " SET category_id=1, category_name='General', category_colour='#F6F79B'"; |
| 491 |
$wpdb->get_results($sql); |
| 492 |
$sql = "UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value='".$initial_style."' WHERE config_item='calendar_style'"; |
| 493 |
$wpdb->get_results($sql); |
| 494 |
} |
| 495 |
} |
| 496 |
|
| 497 |
// Used on the manage events admin page to display a list of events |
| 498 |
function wp_events_display_list() |
| 499 |
{ |
| 500 |
global $wpdb; |
| 501 |
|
| 502 |
$events = $wpdb->get_results("SELECT * FROM " . WP_CALENDAR_TABLE . " ORDER BY event_begin DESC"); |
| 503 |
|
| 504 |
if ( !empty($events) ) |
| 505 |
{ |
| 506 |
?> |
| 507 |
<table width="100%" cellpadding="3" cellspacing="3"> |
| 508 |
<tr> |
| 509 |
<th scope="col"><?php _e('ID') ?></th> |
| 510 |
<th scope="col"><?php _e('Title') ?></th> |
| 511 |
<th scope="col"><?php _e('Description') ?></th> |
| 512 |
<th scope="col"><?php _e('Start Date') ?></th> |
| 513 |
<th scope="col"><?php _e('End Date') ?></th> |
| 514 |
<th scope="col"><?php _e('Recurs') ?></th> |
| 515 |
<th scope="col"><?php _e('Repeats') ?></th> |
| 516 |
<th scope="col"><?php _e('Author') ?></th> |
| 517 |
<th scope="col"><?php _e('Category') ?></th> |
| 518 |
<th scope="col"><?php _e('Edit') ?></th> |
| 519 |
<th scope="col"><?php _e('Delete') ?></th> |
| 520 |
</tr> |
| 521 |
<?php |
| 522 |
$class = ''; |
| 523 |
foreach ( $events as $event ) |
| 524 |
{ |
| 525 |
$class = ($class == 'alternate') ? '' : 'alternate'; |
| 526 |
?> |
| 527 |
<tr class="<?php echo $class; ?>"> |
| 528 |
<th scope="row"><?php echo $event->event_id; ?></th> |
| 529 |
<td><?php echo $event->event_title; ?></td> |
| 530 |
<td><?php echo $event->event_desc; ?></td> |
| 531 |
<td><?php echo $event->event_begin; ?></td> |
| 532 |
<td><?php echo $event->event_end; ?></td> |
| 533 |
<td> |
| 534 |
<?php |
| 535 |
// Interpret the DB values into something human readable |
| 536 |
if ($event->event_recur == 'S') { echo 'Never'; } |
| 537 |
else if ($event->event_recur == 'W') { echo 'Weekly'; } |
| 538 |
else if ($event->event_recur == 'M') { echo 'Monthly'; } |
| 539 |
else if ($event->event_recur == 'Y') { echo 'Yearly'; } |
| 540 |
?> |
| 541 |
</td> |
| 542 |
<td> |
| 543 |
<?php |
| 544 |
// Interpret the DB values into something human readable |
| 545 |
if ($event->event_recur == 'S') { echo 'N/A'; } |
| 546 |
else if ($event->event_repeats == 0) { echo 'Forever'; } |
| 547 |
else if ($event->event_repeats > 0) { echo $event->event_repeats.' Times'; } |
| 548 |
?> |
| 549 |
</td> |
| 550 |
<td><?php $e = get_userdata($event->event_author); echo $e->display_name; ?></td> |
| 551 |
<?php |
| 552 |
$sql = "SELECT * FROM " . WP_CALENDAR_CATEGORIES_TABLE . " WHERE category_id=".$event->event_category; |
| 553 |
$this_cat = $wpdb->get_row($sql); |
| 554 |
?> |
| 555 |
<td style="background-color:<?php echo $this_cat->category_colour;?>;"><?php echo $this_cat->category_name; ?></td> |
| 556 |
<?php unset($this_cat); ?> |
| 557 |
<td><a href="<?php echo $_SERVER['REQUEST_URI'] ?>&action=edit&event_id=<?php echo $event->event_id;?>" class='edit'><?php echo __('Edit'); ?></a></td> |
| 558 |
<td><a href="<?php echo $_SERVER['REQUEST_URI'] ?>&action=delete&event_id=<?php echo $event->event_id;?>" class="delete" onclick="return confirm('Are you sure you want to delete this event?')"><?php echo __('Delete'); ?></a></td> |
| 559 |
</tr> |
| 560 |
<?php |
| 561 |
} |
| 562 |
?> |
| 563 |
</table> |
| 564 |
<?php |
| 565 |
} |
| 566 |
else |
| 567 |
{ |
| 568 |
?> |
| 569 |
<p><?php _e("There are no events in the database!") ?></p> |
| 570 |
<?php |
| 571 |
} |
| 572 |
} |
| 573 |
|
| 574 |
|
| 575 |
// The event edit form for the manage events admin page |
| 576 |
function wp_events_edit_form($mode='add', $event_id=false) |
| 577 |
{ |
| 578 |
global $wpdb; |
| 579 |
$data = false; |
| 580 |
|
| 581 |
if ( $event_id !== false ) |
| 582 |
{ |
| 583 |
if ( intval($event_id) != $event_id ) |
| 584 |
{ |
| 585 |
echo "<div class=\"error\"><p>Bad Monkey! No banana!</p></div>"; |
| 586 |
return; |
| 587 |
} |
| 588 |
else |
| 589 |
{ |
| 590 |
$data = $wpdb->get_results("SELECT * FROM " . WP_CALENDAR_TABLE . " WHERE event_id='" . mysql_escape_string($event_id) . "' LIMIT 1"); |
| 591 |
if ( empty($data) ) |
| 592 |
{ |
| 593 |
echo "<div class=\"error\"><p>An event with that ID couldn't be found</p></div>"; |
| 594 |
return; |
| 595 |
} |
| 596 |
$data = $data[0]; |
| 597 |
} |
| 598 |
} |
| 599 |
|
| 600 |
?> |
| 601 |
<div id="pop_up_cal" style="position:absolute;margin-left:150px;visibility:hidden;background-color:white;layer-background-color:white;"></div> |
| 602 |
<form name="quoteform" id="quoteform" class="wrap" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> |
| 603 |
<input type="hidden" name="action" value="<?php echo $mode; ?>"> |
| 604 |
<input type="hidden" name="event_id" value="<?php echo $event_id; ?>"> |
| 605 |
|
| 606 |
<div id="item_manager"> |
| 607 |
<div style="float: left; width: 98%; clear: both;" class="top"> |
| 608 |
<!-- List URL --> |
| 609 |
<fieldset class="small"><legend><?php _e('Event Title'); ?></legend> |
| 610 |
<input type="text" name="event_title" class="input" size="40" maxlength="30" |
| 611 |
value="<?php if ( !empty($data) ) echo htmlspecialchars($data->event_title); ?>" /> |
| 612 |
</fieldset> |
| 613 |
|
| 614 |
<fieldset class="small"><legend><?php _e('Event Description'); ?></legend> |
| 615 |
<textarea name="event_desc" class="input" rows="5" cols="50"><?php if ( !empty($data) ) echo htmlspecialchars($data->event_desc); ?></textarea> |
| 616 |
</fieldset> |
| 617 |
|
| 618 |
<fieldset class="small"><legend><?php _e('Event Category'); ?></legend> |
| 619 |
<select name="event_category"> |
| 620 |
<?php |
| 621 |
// Grab all the categories and list them |
| 622 |
$sql = "SELECT * FROM " . WP_CALENDAR_CATEGORIES_TABLE; |
| 623 |
$cats = $wpdb->get_results($sql); |
| 624 |
foreach($cats as $cat) |
| 625 |
{ |
| 626 |
echo '<option value="'.$cat->category_id.'"'; |
| 627 |
if (!empty($data)) |
| 628 |
{ |
| 629 |
if ($data->event_category == $cat->category_id) |
| 630 |
{ |
| 631 |
echo 'selected="selected"'; |
| 632 |
} |
| 633 |
} |
| 634 |
echo '>'.$cat->category_name.'</option> |
| 635 |
'; |
| 636 |
} |
| 637 |
?> |
| 638 |
</select> |
| 639 |
</fieldset> |
| 640 |
|
| 641 |
<fieldset class="small"><legend><?php _e('Event Link (Optional)'); ?></legend> |
| 642 |
<input type="text" name="event_link" class="input" size="40" value="<?php if ( !empty($data) ) echo htmlspecialchars($data->event_link); ?>" /> |
| 643 |
</fieldset> |
| 644 |
|
| 645 |
<fieldset class="small"><legend><?php _e('Start Date'); ?></legend> |
| 646 |
<script type="text/javascript"> |
| 647 |
var cal_begin = new CalendarPopup('pop_up_cal'); |
| 648 |
cal_begin.showNavigationDropdowns(); |
| 649 |
</script> |
| 650 |
<input type="text" name="event_begin" class="input" size=12 |
| 651 |
value="<?php |
| 652 |
if ( !empty($data) ) |
| 653 |
{ |
| 654 |
echo htmlspecialchars($data->event_begin); |
| 655 |
} |
| 656 |
else |
| 657 |
{ |
| 658 |
echo date("Y-m-d"); |
| 659 |
} |
| 660 |
?>" /> <a href="#" onClick="cal_begin.select(document.forms['quoteform'].event_begin,'event_begin_anchor','yyyy-MM-dd'); return false;" name="event_begin_anchor" id="event_begin_anchor">Select Date</a> |
| 661 |
</fieldset> |
| 662 |
|
| 663 |
<fieldset class="small"><legend><?php _e('End Date'); ?></legend> |
| 664 |
<script type="text/javascript"> |
| 665 |
function check_and_print() { |
| 666 |
var cal_end = new CalendarPopup('pop_up_cal'); |
| 667 |
var newDate = new Date(); |
| 668 |
newDate.setFullYear(document.forms['quoteform'].event_begin.value.split('-')[0],document.forms['quoteform'].event_begin.value.split('-')[1]-1,document.forms['quoteform'].event_begin.value.split('-')[2]); |
| 669 |
newDate.setDate(newDate.getDate()-1); |
| 670 |
cal_end.addDisabledDates(null, formatDate(newDate, "yyyy-MM-dd")); |
| 671 |
cal_end.showNavigationDropdowns(); |
| 672 |
cal_end.select(document.forms['quoteform'].event_end,'event_end_anchor','yyyy-MM-dd'); |
| 673 |
} |
| 674 |
</script> |
| 675 |
<input type="text" name="event_end" class="input" size=12 |
| 676 |
value="<?php |
| 677 |
if ( !empty($data) ) |
| 678 |
{ |
| 679 |
echo htmlspecialchars($data->event_end); |
| 680 |
} |
| 681 |
else |
| 682 |
{ |
| 683 |
echo date("Y-m-d"); |
| 684 |
} |
| 685 |
?>" /> <a href="#" onClick="check_and_print(); return false;" name="event_end_anchor" id="event_end_anchor">Select Date</a> |
| 686 |
</fieldset> |
| 687 |
|
| 688 |
<fieldset class="small"><legend><?php _e('Time (hh:mm)(optional, set blank if not required)'); ?></legend> |
| 689 |
<input type="text" name="event_time" class="input" size=12 |
| 690 |
value="<?php |
| 691 |
if ( !empty($data) ) |
| 692 |
{ |
| 693 |
if ($data->event_time == "00:00:00") |
| 694 |
{ |
| 695 |
echo ''; |
| 696 |
} |
| 697 |
else |
| 698 |
{ |
| 699 |
echo date("H:i",strtotime(htmlspecialchars($data->event_time))); |
| 700 |
} |
| 701 |
} |
| 702 |
else |
| 703 |
{ |
| 704 |
echo date("H:i"); |
| 705 |
} |
| 706 |
?>" /> <?php _e('Current time difference from GMT is '); echo get_option('gmt_offset'); _e(' hour(s)'); ?> |
| 707 |
</fieldset> |
| 708 |
|
| 709 |
<fieldset class="small"><legend><?php _e('Recurring Events'); ?></legend> |
| 710 |
<?php |
| 711 |
if ($data->event_repeats != NULL) |
| 712 |
{ |
| 713 |
$repeats = $data->event_repeats; |
| 714 |
} |
| 715 |
else |
| 716 |
{ |
| 717 |
$repeats = 0; |
| 718 |
} |
| 719 |
|
| 720 |
if ($data->event_recur == "S") |
| 721 |
{ |
| 722 |
$selected_s = 'selected="selected"'; |
| 723 |
} |
| 724 |
else if ($data->event_recur == "W") |
| 725 |
{ |
| 726 |
$selected_w = 'selected="selected"'; |
| 727 |
} |
| 728 |
else if ($data->event_recur == "M") |
| 729 |
{ |
| 730 |
$selected_m = 'selected="selected"'; |
| 731 |
} |
| 732 |
else if ($data->event_recur == "Y") |
| 733 |
{ |
| 734 |
$selected_y = 'selected="selected"'; |
| 735 |
} |
| 736 |
?> |
| 737 |
Repeats for |
| 738 |
<input type="text" name="event_repeats" class="input" size="1" value="<?php echo $repeats; ?>" /> |
| 739 |
<select name="event_recur" class="input"> |
| 740 |
<option class="input" <?php echo $selected_s; ?> value="S">None</option> |
| 741 |
<option class="input" <?php echo $selected_w; ?> value="W">Weeks</option> |
| 742 |
<option class="input" <?php echo $selected_m; ?> value="M">Months</option> |
| 743 |
<option class="input" <?php echo $selected_y; ?> value="Y">Years</option> |
| 744 |
</select><br /> |
| 745 |
Entering 0 means forever. Where the recurrance interval <br /> |
| 746 |
is left at none, the event will not reoccur. |
| 747 |
</fieldset> |
| 748 |
<br /> |
| 749 |
<input type="submit" name="save" class="button bold" value="Save »" /> |
| 750 |
</div> |
| 751 |
<div style="clear:both; height:1px;"> </div> |
| 752 |
</div> |
| 753 |
</form> |
| 754 |
<?php |
| 755 |
} |
| 756 |
|
| 757 |
// The actual function called to render the manage events page and |
| 758 |
// to deal with posts |
| 759 |
function edit_calendar() |
| 760 |
{ |
| 761 |
global $current_user, $wpdb; |
| 762 |
?> |
| 763 |
<style type="text/css"> |
| 764 |
<!-- |
| 765 |
.error { |
| 766 |
background: lightcoral; |
| 767 |
border: 1px solid #e64f69; |
| 768 |
margin: 1em 5% 10px; |
| 769 |
padding: 0 1em 0 1em; |
| 770 |
} |
| 771 |
|
| 772 |
.center { |
| 773 |
text-align: center; |
| 774 |
} |
| 775 |
.right { text-align: right; |
| 776 |
} |
| 777 |
.left { |
| 778 |
text-align: left; |
| 779 |
} |
| 780 |
.top { |
| 781 |
vertical-align: top; |
| 782 |
} |
| 783 |
.bold { |
| 784 |
font-weight: bold; |
| 785 |
} |
| 786 |
.private { |
| 787 |
color: #e64f69; |
| 788 |
} |
| 789 |
//--> |
| 790 |
</style> |
| 791 |
|
| 792 |
<?php |
| 793 |
|
| 794 |
// First some quick cleaning up |
| 795 |
$edit = $create = $save = $delete = false; |
| 796 |
|
| 797 |
// Make sure we are collecting the variables we need to select years and months |
| 798 |
$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : ''; |
| 799 |
$event_id = !empty($_REQUEST['event_id']) ? $_REQUEST['event_id'] : ''; |
| 800 |
|
| 801 |
|
| 802 |
// Lets see if this is first run and create us a table if it is! |
| 803 |
check_calendar(); |
| 804 |
|
| 805 |
// Deal with adding an event to the database |
| 806 |
if ( $action == 'add' ) |
| 807 |
{ |
| 808 |
$title = !empty($_REQUEST['event_title']) ? $_REQUEST['event_title'] : ''; |
| 809 |
$desc = !empty($_REQUEST['event_desc']) ? $_REQUEST['event_desc'] : ''; |
| 810 |
$begin = !empty($_REQUEST['event_begin']) ? $_REQUEST['event_begin'] : ''; |
| 811 |
$end = !empty($_REQUEST['event_end']) ? $_REQUEST['event_end'] : ''; |
| 812 |
$time = !empty($_REQUEST['event_time']) ? $_REQUEST['event_time'] : ''; |
| 813 |
$recur = !empty($_REQUEST['event_recur']) ? $_REQUEST['event_recur'] : ''; |
| 814 |
$repeats = !empty($_REQUEST['event_repeats']) ? $_REQUEST['event_repeats'] : ''; |
| 815 |
$category = !empty($_REQUEST['event_category']) ? $_REQUEST['event_category'] : ''; |
| 816 |
$linky = !empty($_REQUEST['event_link']) ? $_REQUEST['event_link'] : ''; |
| 817 |
|
| 818 |
// Deal with the fools who have left magic quotes turned on |
| 819 |
if ( ini_get('magic_quotes_gpc') ) |
| 820 |
{ |
| 821 |
$title = stripslashes($title); |
| 822 |
$desc = stripslashes($desc); |
| 823 |
$begin = stripslashes($begin); |
| 824 |
$end = stripslashes($end); |
| 825 |
$time = stripslashes($time); |
| 826 |
$recur = stripslashes($recur); |
| 827 |
$repeats = stripslashes($repeats); |
| 828 |
$category = stripslashes($category); |
| 829 |
$linky = stripslashes($linky); |
| 830 |
} |
| 831 |
|
| 832 |
$sql = "INSERT INTO " . WP_CALENDAR_TABLE . " SET event_title='" . mysql_escape_string($title) |
| 833 |
. "', event_desc='" . mysql_escape_string($desc) . "', event_begin='" . mysql_escape_string($begin) |
| 834 |
. "', event_end='" . mysql_escape_string($end) . "', event_time='" . mysql_escape_string($time) . "', event_recur='" . mysql_escape_string($recur) . "', event_repeats='" . mysql_escape_string($repeats) . "', event_author=".$current_user->ID.", event_category=".mysql_escape_string($category).", event_link='".mysql_escape_string($linky)."'"; |
| 835 |
|
| 836 |
$wpdb->get_results($sql); |
| 837 |
|
| 838 |
$sql = "SELECT event_id FROM " . WP_CALENDAR_TABLE . " WHERE event_title='" . mysql_escape_string($title) . "'" |
| 839 |
. " AND event_desc='" . mysql_escape_string($desc) . "' AND event_begin='" . mysql_escape_string($begin) . "' AND event_end='" . mysql_escape_string($end) . "' AND event_recur='" . mysql_escape_string($recur) . "' AND event_repeats='" . mysql_escape_string($repeats) . "' LIMIT 1"; |
| 840 |
$result = $wpdb->get_results($sql); |
| 841 |
|
| 842 |
if ( empty($result) || empty($result[0]->event_id) ) |
| 843 |
{ |
| 844 |
?> |
| 845 |
<div class="error"><p><strong>Error:</strong> For some bizare reason your event was not added. Why not try again?</p></div> |
| 846 |
<?php |
| 847 |
} |
| 848 |
else |
| 849 |
{ |
| 850 |
?> |
| 851 |
<div class="updated"><p>Event added. It will now show in your calendar.</p></div> |
| 852 |
<?php |
| 853 |
} |
| 854 |
} |
| 855 |
// Permit saving of events that have been edited |
| 856 |
elseif ( $action == 'edit_save' ) |
| 857 |
{ |
| 858 |
$title = !empty($_REQUEST['event_title']) ? $_REQUEST['event_title'] : ''; |
| 859 |
$desc = !empty($_REQUEST['event_desc']) ? $_REQUEST['event_desc'] : ''; |
| 860 |
$begin = !empty($_REQUEST['event_begin']) ? $_REQUEST['event_begin'] : ''; |
| 861 |
$end = !empty($_REQUEST['event_end']) ? $_REQUEST['event_end'] : ''; |
| 862 |
$time = !empty($_REQUEST['event_time']) ? $_REQUEST['event_time'] : ''; |
| 863 |
$recur = !empty($_REQUEST['event_recur']) ? $_REQUEST['event_recur'] : ''; |
| 864 |
$repeats = !empty($_REQUEST['event_repeats']) ? $_REQUEST['event_repeats'] : ''; |
| 865 |
$category = !empty($_REQUEST['event_category']) ? $_REQUEST['event_category'] : ''; |
| 866 |
$linky = !empty($_REQUEST['event_link']) ? $_REQUEST['event_link'] : ''; |
| 867 |
|
| 868 |
// Deal with the fools who have left magic quotes turned on |
| 869 |
if ( ini_get('magic_quotes_gpc') ) |
| 870 |
{ |
| 871 |
$title = stripslashes($title); |
| 872 |
$desc = stripslashes($desc); |
| 873 |
$begin = stripslashes($begin); |
| 874 |
$end = stripslashes($end); |
| 875 |
$time = stripslashes($time); |
| 876 |
$recur = stripslashes($recur); |
| 877 |
$repeats = stripslashes($repeats); |
| 878 |
$category = stripslashes($category); |
| 879 |
$linky = stripslashes($linky); |
| 880 |
} |
| 881 |
|
| 882 |
if ( empty($event_id) ) |
| 883 |
{ |
| 884 |
?> |
| 885 |
<div class="error"><p><strong>Failure:</strong> You can't update an event if you haven't submitted an event id</p></div> |
| 886 |
<?php |
| 887 |
} |
| 888 |
else |
| 889 |
{ |
| 890 |
$sql = "UPDATE " . WP_CALENDAR_TABLE . " SET event_title='" . mysql_escape_string($title) |
| 891 |
. "', event_desc='" . mysql_escape_string($desc) . "', event_begin='" . mysql_escape_string($begin) |
| 892 |
. "', event_end='" . mysql_escape_string($end) . "', event_time='" . mysql_escape_string($time) . "', event_recur='" . mysql_escape_string($recur) . "', event_repeats='" . mysql_escape_string($repeats) . "', event_author=".$current_user->ID . ", event_category=".mysql_escape_string($category).", event_link='".mysql_escape_string($linky)."' WHERE event_id='" . mysql_escape_string($event_id) . "'"; |
| 893 |
|
| 894 |
$wpdb->get_results($sql); |
| 895 |
|
| 896 |
$sql = "SELECT event_id FROM " . WP_CALENDAR_TABLE . " WHERE event_title='" . mysql_escape_string($title) . "'" |
| 897 |
. " AND event_desc='" . mysql_escape_string($desc) . "' AND event_begin='" . mysql_escape_string($begin) . "' AND event_end='" . mysql_escape_string($end) . "' AND event_recur='" . mysql_escape_string($recur) . "' AND event_repeats='" . mysql_escape_string($repeats) . "' LIMIT 1"; |
| 898 |
$result = $wpdb->get_results($sql); |
| 899 |
|
| 900 |
if ( empty($result) || empty($result[0]->event_id) ) |
| 901 |
{ |
| 902 |
?> |
| 903 |
<div class="error"><p><strong>Failure:</strong> For some reason the event didnt update. Why not try again? </p></div> |
| 904 |
<?php |
| 905 |
} |
| 906 |
else |
| 907 |
{ |
| 908 |
?> |
| 909 |
<div class="updated"><p>Event updated successfully</p></div> |
| 910 |
<?php |
| 911 |
} |
| 912 |
} |
| 913 |
} |
| 914 |
// Deal with deleting an event from the database |
| 915 |
elseif ( $action == 'delete' ) |
| 916 |
{ |
| 917 |
if ( empty($event_id) ) |
| 918 |
{ |
| 919 |
?> |
| 920 |
<div class="error"><p><strong>Error:</strong> Good Lord you gave me nothing to delete, nothing I tell you!</p></div> |
| 921 |
<?php |
| 922 |
} |
| 923 |
else |
| 924 |
{ |
| 925 |
$sql = "DELETE FROM " . WP_CALENDAR_TABLE . " WHERE event_id='" . mysql_escape_string($event_id) . "'"; |
| 926 |
$wpdb->get_results($sql); |
| 927 |
|
| 928 |
$sql = "SELECT event_id FROM " . WP_CALENDAR_TABLE . " WHERE event_id='" . mysql_escape_string($event_id) . "'"; |
| 929 |
$result = $wpdb->get_results($sql); |
| 930 |
|
| 931 |
if ( empty($result) || empty($result[0]->event_id) ) |
| 932 |
{ |
| 933 |
?> |
| 934 |
<div class="updated"><p>Event deleted successfully</p></div> |
| 935 |
<?php |
| 936 |
} |
| 937 |
else |
| 938 |
{ |
| 939 |
?> |
| 940 |
<div class="error"><p><strong>Error:</strong> For some bizare reason the event could not be deleted. Why not try again?</p></div> |
| 941 |
<?php |
| 942 |
|
| 943 |
} |
| 944 |
} |
| 945 |
} |
| 946 |
|
| 947 |
// Now follows a little bit of code that pulls in the main |
| 948 |
// components of this page; the edit form and the list of events |
| 949 |
?> |
| 950 |
|
| 951 |
<div class="wrap"> |
| 952 |
<?php |
| 953 |
if ( $action == 'edit' ) |
| 954 |
{ |
| 955 |
?> |
| 956 |
<h2><?php _e('Edit Event'); ?></h2> |
| 957 |
<?php |
| 958 |
if ( empty($event_id) ) |
| 959 |
{ |
| 960 |
echo "<div class=\"error\"><p>Good lord you didn't provide an event id to edit, what were you thinking?</p></div>"; |
| 961 |
} |
| 962 |
else |
| 963 |
{ |
| 964 |
wp_events_edit_form('edit_save', $event_id); |
| 965 |
} |
| 966 |
} |
| 967 |
else |
| 968 |
{ |
| 969 |
?> |
| 970 |
<h2><?php _e('Add Event'); ?></h2> |
| 971 |
<?php wp_events_edit_form(); ?> |
| 972 |
|
| 973 |
<h2><?php _e('Manage Events'); ?></h2> |
| 974 |
<?php |
| 975 |
wp_events_display_list(); |
| 976 |
} |
| 977 |
?> |
| 978 |
</div> |
| 979 |
|
| 980 |
<?php |
| 981 |
|
| 982 |
} |
| 983 |
|
| 984 |
// Display the admin configuration page |
| 985 |
function edit_calendar_config() |
| 986 |
{ |
| 987 |
global $wpdb, $initial_style; |
| 988 |
|
| 989 |
// We can't use this page unless Calendar is installed/upgraded |
| 990 |
check_calendar(); |
| 991 |
|
| 992 |
if (isset($_POST['permissions']) && isset($_POST['style'])) |
| 993 |
{ |
| 994 |
if ($_POST['permissions'] == 'subscriber') { $new_perms = 'read'; } |
| 995 |
else if ($_POST['permissions'] == 'contributor') { $new_perms = 'edit_posts'; } |
| 996 |
else if ($_POST['permissions'] == 'author') { $new_perms = 'publish_posts'; } |
| 997 |
else if ($_POST['permissions'] == 'editor') { $new_perms = 'moderate_comments'; } |
| 998 |
else if ($_POST['permissions'] == 'admin') { $new_perms = 'manage_options'; } |
| 999 |
else { $new_perms = 'manage_options'; } |
| 1000 |
|
| 1001 |
$calendar_style = mysql_escape_string($_POST['style']); |
| 1002 |
$display_upcoming_days = mysql_escape_string($_POST['display_upcoming_days']); |
| 1003 |
|
| 1004 |
if (mysql_escape_string($_POST['display_author']) == 'on') |
| 1005 |
{ |
| 1006 |
$disp_author = 'true'; |
| 1007 |
} |
| 1008 |
else |
| 1009 |
{ |
| 1010 |
$disp_author = 'false'; |
| 1011 |
} |
| 1012 |
|
| 1013 |
if (mysql_escape_string($_POST['display_jump']) == 'on') |
| 1014 |
{ |
| 1015 |
$disp_jump = 'true'; |
| 1016 |
} |
| 1017 |
else |
| 1018 |
{ |
| 1019 |
$disp_jump = 'false'; |
| 1020 |
} |
| 1021 |
|
| 1022 |
if (mysql_escape_string($_POST['display_todays']) == 'on') |
| 1023 |
{ |
| 1024 |
$disp_todays = 'true'; |
| 1025 |
} |
| 1026 |
else |
| 1027 |
{ |
| 1028 |
$disp_todays = 'false'; |
| 1029 |
} |
| 1030 |
|
| 1031 |
if (mysql_escape_string($_POST['display_upcoming']) == 'on') |
| 1032 |
{ |
| 1033 |
$disp_upcoming = 'true'; |
| 1034 |
} |
| 1035 |
else |
| 1036 |
{ |
| 1037 |
$disp_upcoming = 'false'; |
| 1038 |
} |
| 1039 |
|
| 1040 |
if (mysql_escape_string($_POST['enable_categories']) == 'on') |
| 1041 |
{ |
| 1042 |
$enable_categories = 'true'; |
| 1043 |
} |
| 1044 |
else |
| 1045 |
{ |
| 1046 |
$enable_categories = 'false'; |
| 1047 |
} |
| 1048 |
|
| 1049 |
$wpdb->get_results("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '".$new_perms."' WHERE config_item='can_manage_events'"); |
| 1050 |
$wpdb->get_results("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '".$calendar_style."' WHERE config_item='calendar_style'"); |
| 1051 |
$wpdb->get_results("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '".$disp_author."' WHERE config_item='display_author'"); |
| 1052 |
$wpdb->get_results("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '".$disp_jump."' WHERE config_item='display_jump'"); |
| 1053 |
$wpdb->get_results("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '".$disp_todays."' WHERE config_item='display_todays'"); |
| 1054 |
$wpdb->get_results("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '".$disp_upcoming."' WHERE config_item='display_upcoming'"); |
| 1055 |
$wpdb->get_results("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '".$display_upcoming_days."' WHERE config_item='display_upcoming_days'"); |
| 1056 |
$wpdb->get_results("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '".$enable_categories."' WHERE config_item='enable_categories'"); |
| 1057 |
|
| 1058 |
// Check to see if we are replacing the original style |
| 1059 |
if (mysql_escape_string($_POST['reset_styles']) == 'on') |
| 1060 |
{ |
| 1061 |
$wpdb->get_results("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '".$initial_style."' WHERE config_item='calendar_style'"); |
| 1062 |
} |
| 1063 |
|
| 1064 |
echo "<div class=\"updated\"><p><strong>Settings saved.</strong></p></div>"; |
| 1065 |
} |
| 1066 |
|
| 1067 |
// Pull the values out of the database that we need for the form |
| 1068 |
$configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='can_manage_events'"); |
| 1069 |
if (!empty($configs)) |
| 1070 |
{ |
| 1071 |
foreach ($configs as $config) |
| 1072 |
{ |
| 1073 |
$allowed_group = $config->config_value; |
| 1074 |
} |
| 1075 |
} |
| 1076 |
|
| 1077 |
$configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='calendar_style'"); |
| 1078 |
if (!empty($configs)) |
| 1079 |
{ |
| 1080 |
foreach ($configs as $config) |
| 1081 |
{ |
| 1082 |
$calendar_style = $config->config_value; |
| 1083 |
} |
| 1084 |
} |
| 1085 |
$configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='display_author'"); |
| 1086 |
if (!empty($configs)) |
| 1087 |
{ |
| 1088 |
foreach ($configs as $config) |
| 1089 |
{ |
| 1090 |
if ($config->config_value == 'true') |
| 1091 |
{ |
| 1092 |
$yes_disp_author = 'selected="selected"'; |
| 1093 |
} |
| 1094 |
else |
| 1095 |
{ |
| 1096 |
$no_disp_author = 'selected="selected"'; |
| 1097 |
} |
| 1098 |
} |
| 1099 |
} |
| 1100 |
$configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='display_jump'"); |
| 1101 |
if (!empty($configs)) |
| 1102 |
{ |
| 1103 |
foreach ($configs as $config) |
| 1104 |
{ |
| 1105 |
if ($config->config_value == 'true') |
| 1106 |
{ |
| 1107 |
$yes_disp_jump = 'selected="selected"'; |
| 1108 |
} |
| 1109 |
else |
| 1110 |
{ |
| 1111 |
$no_disp_jump = 'selected="selected"'; |
| 1112 |
} |
| 1113 |
} |
| 1114 |
} |
| 1115 |
$configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='display_todays'"); |
| 1116 |
if (!empty($configs)) |
| 1117 |
{ |
| 1118 |
foreach ($configs as $config) |
| 1119 |
{ |
| 1120 |
if ($config->config_value == 'true') |
| 1121 |
{ |
| 1122 |
$yes_disp_todays = 'selected="selected"'; |
| 1123 |
} |
| 1124 |
else |
| 1125 |
{ |
| 1126 |
$no_disp_todays = 'selected="selected"'; |
| 1127 |
} |
| 1128 |
} |
| 1129 |
} |
| 1130 |
$configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='display_upcoming'"); |
| 1131 |
if (!empty($configs)) |
| 1132 |
{ |
| 1133 |
foreach ($configs as $config) |
| 1134 |
{ |
| 1135 |
if ($config->config_value == 'true') |
| 1136 |
{ |
| 1137 |
$yes_disp_upcoming = 'selected="selected"'; |
| 1138 |
} |
| 1139 |
else |
| 1140 |
{ |
| 1141 |
$no_disp_upcoming = 'selected="selected"'; |
| 1142 |
} |
| 1143 |
} |
| 1144 |
} |
| 1145 |
$configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='display_upcoming_days'"); |
| 1146 |
if (!empty($configs)) |
| 1147 |
{ |
| 1148 |
foreach ($configs as $config) |
| 1149 |
{ |
| 1150 |
$upcoming_days = $config->config_value; |
| 1151 |
} |
| 1152 |
} |
| 1153 |
$configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='enable_categories'"); |
| 1154 |
if (!empty($configs)) |
| 1155 |
{ |
| 1156 |
foreach ($configs as $config) |
| 1157 |
{ |
| 1158 |
if ($config->config_value == 'true') |
| 1159 |
{ |
| 1160 |
$yes_enable_categories = 'selected="selected"'; |
| 1161 |
} |
| 1162 |
else |
| 1163 |
{ |
| 1164 |
$no_enable_categories = 'selected="selected"'; |
| 1165 |
} |
| 1166 |
} |
| 1167 |
} |
| 1168 |
if ($allowed_group == 'read') { $subscriber_selected='selected="selected"';} |
| 1169 |
else if ($allowed_group == 'edit_posts') { $contributor_selected='selected="selected"';} |
| 1170 |
else if ($allowed_group == 'publish_posts') { $author_selected='selected="selected"';} |
| 1171 |
else if ($allowed_group == 'moderate_comments') { $editor_selected='selected="selected"';} |
| 1172 |
else if ($allowed_group == 'manage_options') { $admin_selected='selected="selected"';} |
| 1173 |
|
| 1174 |
// Now we render the form |
| 1175 |
?> |
| 1176 |
<style type="text/css"> |
| 1177 |
<!-- |
| 1178 |
.error { |
| 1179 |
background: lightcoral; |
| 1180 |
border: 1px solid #e64f69; |
| 1181 |
margin: 1em 5% 10px; |
| 1182 |
padding: 0 1em 0 1em; |
| 1183 |
} |
| 1184 |
|
| 1185 |
.center { |
| 1186 |
text-align: center; |
| 1187 |
} |
| 1188 |
.right { |
| 1189 |
text-align: right; |
| 1190 |
} |
| 1191 |
.left { |
| 1192 |
text-align: left; |
| 1193 |
} |
| 1194 |
.top { |
| 1195 |
vertical-align: top; |
| 1196 |
} |
| 1197 |
.bold { |
| 1198 |
font-weight: bold; |
| 1199 |
} |
| 1200 |
.private { |
| 1201 |
color: #e64f69; |
| 1202 |
} |
| 1203 |
//--> |
| 1204 |
</style> |
| 1205 |
|
| 1206 |
<div class="wrap"> |
| 1207 |
<h2><?php _e('Calendar Options'); ?></h2> |
| 1208 |
<form name="quoteform" id="quoteform" class="wrap" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> |
| 1209 |
<div id="item_manager"> |
| 1210 |
<div style="float: left; width: 98%; clear: both;" class="top"> |
| 1211 |
<fieldset class="small"><legend><?php _e('Choose the lowest user group that may manage events'); ?></legend> |
| 1212 |
<select name="permissions"> |
| 1213 |
<option value="subscriber"<?php echo $subscriber_seletced ?>><?php _e('Subscriber')?></option> |
| 1214 |
<option value="contributor" <?php echo $contributor_selected ?>><?php _e('Contributor')?></option> |
| 1215 |
<option value="author" <?php echo $author_selected ?>><?php _e('Author')?></option> |
| 1216 |
<option value="editor" <?php echo $editor_selected ?>><?php _e('Editor')?></option> |
| 1217 |
<option value="admin" <?php echo $admin_selected ?>><?php _e('Administrator')?></option> |
| 1218 |
</select> |
| 1219 |
</fieldset> |
| 1220 |
<fieldset class="small"><legend><?php _e('Do you want to display the author name on events?'); ?></legend> |
| 1221 |
<select name="display_author"> |
| 1222 |
<option value="on" <?php echo $yes_disp_author ?>><?php _e('Yes') ?></option> |
| 1223 |
<option value="off" <?php echo $no_disp_author ?>><?php _e('No') ?></option> |
| 1224 |
</select> |
| 1225 |
</fieldset> |
| 1226 |
<fieldset class="small"><legend><?php _e('Display a jumpbox for changing month and year quickly?'); ?></legend> |
| 1227 |
<select name="display_jump"> |
| 1228 |
<option value="on" <?php echo $yes_disp_jump ?>><?php _e('Yes') ?></option> |
| 1229 |
<option value="off" <?php echo $no_disp_jump ?>><?php _e('No') ?></option> |
| 1230 |
</select> |
| 1231 |
</fieldset> |
| 1232 |
<fieldset class="small"><legend><?php _e('Display todays events?'); ?></legend> |
| 1233 |
<select name="display_todays"> |
| 1234 |
<option value="on" <?php echo $yes_disp_todays ?>><?php _e('Yes') ?></option> |
| 1235 |
<option value="off" <?php echo $no_disp_todays ?>><?php _e('No') ?></option> |
| 1236 |
</select> |
| 1237 |
</fieldset> |
| 1238 |
<fieldset class="small"><legend><?php _e('Display upcoming events? If yes, state for how many days into the future'); ?></legend> |
| 1239 |
<select name="display_upcoming"> |
| 1240 |
<option value="on" <?php echo $yes_disp_upcoming ?>><?php _e('Yes') ?></option> |
| 1241 |
<option value="off" <?php echo $no_disp_upcoming ?>><?php _e('No') ?></option> |
| 1242 |
</select> |
| 1243 |
for <input type="text" name="display_upcoming_days" value="<?php echo $upcoming_days ?>" size="1" maxlength="2" /> days into the future |
| 1244 |
</fieldset> |
| 1245 |
|
| 1246 |
<fieldset class="small"><legend><?php _e('Enable event categories?'); ?></legend> |
| 1247 |
<select name="enable_categories"> |
| 1248 |
<option value="on" <?php echo $yes_enable_categories ?>><?php _e('Yes') ?></option> |
| 1249 |
<option value="off" <?php echo $no_enable_categories ?>><?php _e('No') ?></option> |
| 1250 |
</select> |
| 1251 |
</fieldset> |
| 1252 |
|
| 1253 |
<fieldset class="small"><legend><?php _e('Configure the stylesheet for Calendar'); ?></legend> |
| 1254 |
<textarea name="style" rows="10" cols="60" tabindex="2"><?php echo $calendar_style; ?></textarea> |
| 1255 |
</fieldset> |
| 1256 |
<fieldset class="small"><legend><?php _e('Reset Styles'); ?></legend> |
| 1257 |
<input type="checkbox" name="reset_styles" /> <?php _e('Tick this box if you wish to reset the Calendar style to default'); ?> |
| 1258 |
</fieldset> |
| 1259 |
<br /> |
| 1260 |
<input type="submit" name="save" class="button bold" value="Save »" /> |
| 1261 |
</div> |
| 1262 |
</div> |
| 1263 |
</form> |
| 1264 |
</div> |
| 1265 |
<?php |
| 1266 |
|
| 1267 |
|
| 1268 |
} |
| 1269 |
|
| 1270 |
// Function to handle the management of categories |
| 1271 |
function manage_categories() |
| 1272 |
{ |
| 1273 |
global $wpdb; |
| 1274 |
|
| 1275 |
// Calendar must be installed and upgraded before this will work |
| 1276 |
check_calendar(); |
| 1277 |
|
| 1278 |
?> |
| 1279 |
<style type="text/css"> |
| 1280 |
<!-- |
| 1281 |
.error { |
| 1282 |
background: lightcoral; |
| 1283 |
border: 1px solid #e64f69; |
| 1284 |
margin: 1em 5% 10px; |
| 1285 |
padding: 0 1em 0 1em; |
| 1286 |
} |
| 1287 |
|
| 1288 |
.center { |
| 1289 |
text-align: center; |
| 1290 |
} |
| 1291 |
.right { |
| 1292 |
text-align: right; |
| 1293 |
} |
| 1294 |
.left { |
| 1295 |
text-align: left; |
| 1296 |
} |
| 1297 |
.top { |
| 1298 |
vertical-align: top; |
| 1299 |
} |
| 1300 |
.bold { |
| 1301 |
font-weight: bold; |
| 1302 |
} |
| 1303 |
.private { |
| 1304 |
color: #e64f69; |
| 1305 |
} |
| 1306 |
//--> |
| 1307 |
</style> |
| 1308 |
<?php |
| 1309 |
// We do some checking to see what we're doing |
| 1310 |
if (isset($_POST['mode']) && $_POST['mode'] == 'add') |
| 1311 |
{ |
| 1312 |
$sql = "INSERT INTO " . WP_CALENDAR_CATEGORIES_TABLE . " SET category_name='".mysql_escape_string($_POST['category_name'])."', category_colour='".mysql_escape_string($_POST['category_colour'])."'"; |
| 1313 |
$wpdb->get_results($sql); |
| 1314 |
echo "<div class=\"updated\"><p><strong>Category added successfully</strong></p></div>"; |
| 1315 |
} |
| 1316 |
else if (isset($_GET['mode']) && isset($_GET['category_id']) && $_GET['mode'] == 'delete') |
| 1317 |
{ |
| 1318 |
$sql = "DELETE FROM " . WP_CALENDAR_CATEGORIES_TABLE . " WHERE category_id=".mysql_escape_string($_GET['category_id']); |
| 1319 |
$wpdb->get_results($sql); |
| 1320 |
$sql = "UPDATE " . WP_CALENDAR_TABLE . " SET event_category=1 WHERE event_category=".mysql_escape_string($_GET['category_id']); |
| 1321 |
$wpdb->get_results($sql); |
| 1322 |
echo "<div class=\"updated\"><p><strong>Category deleted successfully</strong></p></div>"; |
| 1323 |
} |
| 1324 |
else if (isset($_GET['mode']) && isset($_GET['category_id']) && $_GET['mode'] == 'edit' && !isset($_POST['mode'])) |
| 1325 |
{ |
| 1326 |
$sql = "SELECT * FROM " . WP_CALENDAR_CATEGORIES_TABLE . " WHERE category_id=".mysql_escape_string($_GET['category_id']); |
| 1327 |
$cur_cat = $wpdb->get_row($sql); |
| 1328 |
?> |
| 1329 |
<div class="wrap"> |
| 1330 |
<h2><?php _e('Edit Category'); ?></h2> |
| 1331 |
<form name="catform" id="catform" class="wrap" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> |
| 1332 |
<input type="hidden" name="mode" value="edit" /> |
| 1333 |
<input type="hidden" name="category_id" value="<?php echo $cur_cat->category_id ?>" /> |
| 1334 |
<div id="item_manager"> |
| 1335 |
<div style="float: left; width: 98%; clear: both;" class="top"> |
| 1336 |
<fieldset class="small"><legend><?php _e('Category Name:'); ?></legend> |
| 1337 |
<input type="text" name="category_name" class="input" size="30" maxlength="30" value="<?php echo $cur_cat->category_name ?>" /> |
| 1338 |
</fieldset> |
| 1339 |
<fieldset class="small"><legend><?php _e('Category Colour (Hex format):'); ?></legend> |
| 1340 |
<input type="text" name="category_colour" class="input" size="10" maxlength="7" value="<?php echo $cur_cat->category_colour ?>" /> |
| 1341 |
</fieldset> |
| 1342 |
<br /> |
| 1343 |
<input type="submit" name="save" class="button bold" value="Save »" /> |
| 1344 |
</div> |
| 1345 |
</div> |
| 1346 |
</form> |
| 1347 |
</div> |
| 1348 |
<?php |
| 1349 |
} |
| 1350 |
else if (isset($_POST['mode']) && isset($_POST['category_id']) && isset($_POST['category_name']) && isset($_POST['category_colour']) && $_POST['mode'] == 'edit') |
| 1351 |
{ |
| 1352 |
$sql = "UPDATE " . WP_CALENDAR_CATEGORIES_TABLE . " SET category_name='".mysql_escape_string($_POST['category_name'])."', category_colour='".mysql_escape_string($_POST['category_colour'])."' WHERE category_id=".mysql_escape_string($_POST['category_id']); |
| 1353 |
$wpdb->get_results($sql); |
| 1354 |
echo "<div class=\"updated\"><p><strong>Category edited successfully</strong></p></div>"; |
| 1355 |
} |
| 1356 |
|
| 1357 |
if ($_GET['mode'] != 'edit' || $_POST['mode'] == 'edit') |
| 1358 |
{ |
| 1359 |
?> |
| 1360 |
|
| 1361 |
<div class="wrap"> |
| 1362 |
<h2><?php _e('Add Category'); ?></h2> |
| 1363 |
<form name="catform" id="catform" class="wrap" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> |
| 1364 |
<input type="hidden" name="mode" value="add" /> |
| 1365 |
<input type="hidden" name="category_id" value=""> |
| 1366 |
<div id="item_manager"> |
| 1367 |
<div style="float: left; width: 98%; clear: both;" class="top"> |
| 1368 |
<fieldset class="small"><legend><?php _e('Category Name:'); ?></legend> |
| 1369 |
<input type="text" name="category_name" class="input" size="30" maxlength="30" value="" /> |
| 1370 |
</fieldset> |
| 1371 |
<fieldset class="small"><legend><?php _e('Category Colour (Hex format):'); ?></legend> |
| 1372 |
<input type="text" name="category_colour" class="input" size="10" maxlength="7" value="" /> |
| 1373 |
</fieldset> |
| 1374 |
<br /> |
| 1375 |
<input type="submit" name="save" class="button bold" value="Save »" /> |
| 1376 |
</div> |
| 1377 |
</div> |
| 1378 |
</form> |
| 1379 |
<h2><?php _e('Manage Categories'); ?></h2> |
| 1380 |
<?php |
| 1381 |
|
| 1382 |
// We pull the categories from the database |
| 1383 |
$categories = $wpdb->get_results("SELECT * FROM " . WP_CALENDAR_CATEGORIES_TABLE . " ORDER BY category_id ASC"); |
| 1384 |
|
| 1385 |
if ( !empty($categories) ) |
| 1386 |
{ |
| 1387 |
?> |
| 1388 |
<table width="50%" cellpadding="3" cellspacing="3"> |
| 1389 |
<tr> |
| 1390 |
<th scope="col"><?php _e('ID') ?></th> |
| 1391 |
<th scope="col"><?php _e('Category Name') ?></th> |
| 1392 |
<th scope="col"><?php _e('Category Colour') ?></th> |
| 1393 |
<th scope="col"><?php _e('Edit') ?></th> |
| 1394 |
<th scope="col"><?php _e('Delete') ?></th> |
| 1395 |
</tr> |
| 1396 |
<?php |
| 1397 |
$class = ''; |
| 1398 |
foreach ( $categories as $category ) |
| 1399 |
{ |
| 1400 |
$class = ($class == 'alternate') ? '' : 'alternate'; |
| 1401 |
?> |
| 1402 |
<tr class="<?php echo $class; ?>"> |
| 1403 |
<th scope="row"><?php echo $category->category_id; ?></th> |
| 1404 |
<td><?php echo $category->category_name; ?></td> |
| 1405 |
<td style="background-color:<?php echo $category->category_colour; ?>;"> </td> |
| 1406 |
<td><a href="<?php echo $_SERVER['REQUEST_URI'] ?>&mode=edit&category_id=<?php echo $category->category_id;?>" class='edit'><?php echo __('Edit'); ?></a></td> |
| 1407 |
<?php |
| 1408 |
if ($category->category_id == 1) |
| 1409 |
{ |
| 1410 |
?> |
| 1411 |
<td>N/A</td> |
| 1412 |
<?php |
| 1413 |
} |
| 1414 |
else |
| 1415 |
{ |
| 1416 |
?> |
| 1417 |
<td><a href="<?php echo $_SERVER['REQUEST_URI'] ?>&mode=delete&category_id=<?php echo $category->category_id;?>" class="delete" onclick="return confirm('Are you sure you want to delete this category?')"><?php echo __('Delete'); ?></a></td> |
| 1418 |
<?php |
| 1419 |
} |
| 1420 |
?> |
| 1421 |
</tr> |
| 1422 |
<?php |
| 1423 |
} |
| 1424 |
?> |
| 1425 |
</table> |
| 1426 |
<?php |
| 1427 |
} |
| 1428 |
else |
| 1429 |
{ |
| 1430 |
?> |
| 1431 |
<p><?php _e("There are no categories in the database - something has gone wrong!") ?></p> |
| 1432 |
<?php |
| 1433 |
} |
| 1434 |
|
| 1435 |
?> |
| 1436 |
</div> |
| 1437 |
|
| 1438 |
<?php |
| 1439 |
} |
| 1440 |
} |
| 1441 |
|
| 1442 |
// Function to return a prefix which will allow the correct |
| 1443 |
// placement of arguments into the query string. |
| 1444 |
function permalink_prefix() |
| 1445 |
{ |
| 1446 |
// Get the permalink structure from WordPress |
| 1447 |
$p_link = get_permalink(); |
| 1448 |
|
| 1449 |
// Work out what the real URL we are viewing is |
| 1450 |
$s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; |
| 1451 |
$protocol = substr(strtolower($_SERVER["SERVER_PROTOCOL"]), 0, strpos(strtolower($_SERVER["SERVER_PROTOCOL"]), "/")).$s; |
| 1452 |
$port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); |
| 1453 |
$real_link = $protocol.'://'.$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI']; |
| 1454 |
|
| 1455 |
// Now use all of that to get the correctly craft the Calendar link prefix |
| 1456 |
if (strstr($p_link, '?') && $p_link == $real_link) |
| 1457 |
{ |
| 1458 |
$link_part = $p_link.'&'; |
| 1459 |
} |
| 1460 |
else if ($p_link == $real_link) |
| 1461 |
{ |
| 1462 |
$link_part = $p_link.'?'; |
| 1463 |
} |
| 1464 |
else if (strstr($real_link, '?')) |
| 1465 |
{ |
| 1466 |
if (isset($_GET['month']) && isset($_GET['yr'])) |
| 1467 |
{ |
| 1468 |
$new_tail = split("&", $real_link); |
| 1469 |
foreach ($new_tail as $item) |
| 1470 |
{ |
| 1471 |
if (!strstr($item, 'month') && !strstr($item, 'yr')) |
| 1472 |
{ |
| 1473 |
$link_part .= $item.'&'; |
| 1474 |
} |
| 1475 |
} |
| 1476 |
if (!strstr($link_part, '?')) |
| 1477 |
{ |
| 1478 |
$new_tail = split("month", $link_part); |
| 1479 |
$link_part = $new_tail[0].'?'.$new_tail[1]; |
| 1480 |
} |
| 1481 |
} |
| 1482 |
else |
| 1483 |
{ |
| 1484 |
$link_part = $real_link.'&'; |
| 1485 |
} |
| 1486 |
} |
| 1487 |
else |
| 1488 |
{ |
| 1489 |
$link_part = $real_link.'?'; |
| 1490 |
} |
| 1491 |
|
| 1492 |
return $link_part; |
| 1493 |
} |
| 1494 |
|
| 1495 |
// Configure the "Next" link in the calendar |
| 1496 |
function next_link($cur_year,$cur_month) |
| 1497 |
{ |
| 1498 |
$mod_rewrite_months = array(1=>'jan','feb','mar','apr','may','jun','jul','aug','sept','oct','nov','dec'); |
| 1499 |
$next_year = $cur_year + 1; |
| 1500 |
|
| 1501 |
if ($cur_month == 12) |
| 1502 |
{ |
| 1503 |
return '<a href="' . permalink_prefix() . 'month=jan&yr=' . $next_year . '">Next »</a>'; |
| 1504 |
} |
| 1505 |
else |
| 1506 |
{ |
| 1507 |
$next_month = $cur_month + 1; |
| 1508 |
$month = $mod_rewrite_months[$next_month]; |
| 1509 |
return '<a href="' . permalink_prefix() . 'month='.$month.'&yr=' . $cur_year . '">Next »</a>'; |
| 1510 |
} |
| 1511 |
} |
| 1512 |
|
| 1513 |
// Configure the "Previous" link in the calendar |
| 1514 |
function prev_link($cur_year,$cur_month) |
| 1515 |
{ |
| 1516 |
$mod_rewrite_months = array(1=>'jan','feb','mar','apr','may','jun','jul','aug','sept','oct','nov','dec'); |
| 1517 |
$last_year = $cur_year - 1; |
| 1518 |
|
| 1519 |
if ($cur_month == 1) |
| 1520 |
{ |
| 1521 |
return '<a href="' . permalink_prefix() . 'month=dec&yr='. $last_year .'">« Prev</a>'; |
| 1522 |
} |
| 1523 |
else |
| 1524 |
{ |
| 1525 |
$next_month = $cur_month - 1; |
| 1526 |
$month = $mod_rewrite_months[$next_month]; |
| 1527 |
return '<a href="' . permalink_prefix() . 'month='.$month.'&yr=' . $cur_year . '">« Prev</a>'; |
| 1528 |
} |
| 1529 |
} |
| 1530 |
|
| 1531 |
// Print upcoming events |
| 1532 |
function upcoming_events() |
| 1533 |
{ |
| 1534 |
global $wpdb; |
| 1535 |
|
| 1536 |
// This function cannot be called unless calendar is up to date |
| 1537 |
check_calendar(); |
| 1538 |
|
| 1539 |
// Find out if we should be displaying upcoming events |
| 1540 |
$display = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='display_upcoming'",0,0); |
| 1541 |
|
| 1542 |
if ($display == 'true') |
| 1543 |
{ |
| 1544 |
// Get number of days we should go into the future |
| 1545 |
$future_days = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='display_upcoming_days'",0,0); |
| 1546 |
$day_count = 1; |
| 1547 |
|
| 1548 |
while ($day_count < $future_days+1) |
| 1549 |
{ |
| 1550 |
list($y,$m,$d) = split("-",date("Y-m-d",mktime($day_count*24,0,0,date("m"),date("d"),date("Y")))); |
| 1551 |
$events = grab_events($y,$m,$d); |
| 1552 |
usort($events, "time_cmp"); |
| 1553 |
if (count($events) != 0) { |
| 1554 |
$output .= '<li>'.date(get_option('date_format'),mktime($day_count*24,0,0,date("m"),date("d"),date("Y"))).'<ul>'; |
| 1555 |
} |
| 1556 |
foreach($events as $event) |
| 1557 |
{ |
| 1558 |
if ($event->event_time == '00:00:00') { |
| 1559 |
$time_string = ' all day'; |
| 1560 |
} |
| 1561 |
else { |
| 1562 |
$time_string = ' at '.date(get_option('time_format'), strtotime($event->event_time)); |
| 1563 |
} |
| 1564 |
$output .= '<li>'.draw_widget_event($event).$time_string.'</li>'; |
| 1565 |
} |
| 1566 |
if (count($events) != 0) { |
| 1567 |
$output .= '</ul></li>'; |
| 1568 |
} |
| 1569 |
$day_count = $day_count+1; |
| 1570 |
} |
| 1571 |
|
| 1572 |
if ($output != '') |
| 1573 |
{ |
| 1574 |
$visual = '<li class="upcoming-events"><h2>Upcoming Events</h2><ul>'; |
| 1575 |
$visual .= $output; |
| 1576 |
$visual .= '</ul></li>'; |
| 1577 |
return $visual; |
| 1578 |
} |
| 1579 |
} |
| 1580 |
} |
| 1581 |
|
| 1582 |
// Print todays events |
| 1583 |
function todays_events() |
| 1584 |
{ |
| 1585 |
global $wpdb; |
| 1586 |
|
| 1587 |
// This function cannot be called unless calendar is up to date |
| 1588 |
check_calendar(); |
| 1589 |
|
| 1590 |
// Find out if we should be displaying todays events |
| 1591 |
$display = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='display_todays'",0,0); |
| 1592 |
|
| 1593 |
if ($display == 'true') |
| 1594 |
{ |
| 1595 |
$output = '<li class="todays-events"><h2>Todays Events</h2><ul>'; |
| 1596 |
$events = grab_events(date("Y"),date("m"),date("d")); |
| 1597 |
usort($events, "time_cmp"); |
| 1598 |
foreach($events as $event) |
| 1599 |
{ |
| 1600 |
if ($event->event_time == '00:00:00') { |
| 1601 |
$time_string = ' all day'; |
| 1602 |
} |
| 1603 |
else { |
| 1604 |
$time_string = ' at '.date(get_option('time_format'), strtotime($event->event_time)); |
| 1605 |
} |
| 1606 |
$output .= '<li>'.draw_widget_event($event).$time_string.'</li>'; |
| 1607 |
} |
| 1608 |
$output .= '</ul></li>'; |
| 1609 |
if (count($events) != 0) |
| 1610 |
{ |
| 1611 |
return $output; |
| 1612 |
} |
| 1613 |
} |
| 1614 |
} |
| 1615 |
|
| 1616 |
// Function to compare time in event objects |
| 1617 |
function time_cmp($a, $b) |
| 1618 |
{ |
| 1619 |
if ($a->event_time == $b->event_time) { |
| 1620 |
return 0; |
| 1621 |
} |
| 1622 |
return ($a->event_time < $b->event_time) ? -1 : 1; |
| 1623 |
} |
| 1624 |
|
| 1625 |
// Used to draw multiple events |
| 1626 |
function draw_events($events) |
| 1627 |
{ |
| 1628 |
// We need to sort arrays of objects by time |
| 1629 |
usort($events, "time_cmp"); |
| 1630 |
|
| 1631 |
// Now process the events |
| 1632 |
foreach($events as $event) |
| 1633 |
{ |
| 1634 |
$output .= draw_event($event); |
| 1635 |
} |
| 1636 |
return $output; |
| 1637 |
} |
| 1638 |
|
| 1639 |
|
| 1640 |
// The widget to show todays events in the sidebar |
| 1641 |
function widget_init_calendar_today() { |
| 1642 |
// Check for required functions |
| 1643 |
if (!function_exists('register_sidebar_widget')) |
| 1644 |
return; |
| 1645 |
|
| 1646 |
function widget_calendar_today($args) { |
| 1647 |
extract($args); |
| 1648 |
?> |
| 1649 |
<?php echo todays_events(); ?> |
| 1650 |
<?php |
| 1651 |
} |
| 1652 |
|
| 1653 |
register_sidebar_widget('Todays Events','widget_calendar_today'); |
| 1654 |
} |
| 1655 |
|
| 1656 |
// The widget to show todays events in the sidebar |
| 1657 |
function widget_init_calendar_upcoming() { |
| 1658 |
// Check for required functions |
| 1659 |
if (!function_exists('register_sidebar_widget')) |
| 1660 |
return; |
| 1661 |
|
| 1662 |
function widget_calendar_upcoming($args) { |
| 1663 |
extract($args); |
| 1664 |
?> |
| 1665 |
<?php echo upcoming_events(); ?> |
| 1666 |
<?php |
| 1667 |
} |
| 1668 |
|
| 1669 |
register_sidebar_widget('Upcoming Events','widget_calendar_upcoming'); |
| 1670 |
} |
| 1671 |
|
| 1672 |
|
| 1673 |
// Used to draw an event to the screen |
| 1674 |
function draw_event($event) |
| 1675 |
{ |
| 1676 |
global $wpdb; |
| 1677 |
|
| 1678 |
// Calendar must be updated to run this function |
| 1679 |
check_calendar(); |
| 1680 |
|
| 1681 |
// Before we do anything we want to know if we |
| 1682 |
// should display the author and/or show categories. |
| 1683 |
// We check for this later |
| 1684 |
$display_author = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='display_author'",0,0); |
| 1685 |
$show_cat = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='enable_categories'",0,0); |
| 1686 |
|
| 1687 |
if ($show_cat == 'true') |
| 1688 |
{ |
| 1689 |
$sql = "SELECT * FROM " . WP_CALENDAR_CATEGORIES_TABLE . " WHERE category_id=".$event->event_category; |
| 1690 |
$cat_details = $wpdb->get_row($sql); |
| 1691 |
$style = "background-color:".$cat_details->category_colour.";"; |
| 1692 |
} |
| 1693 |
|
| 1694 |
$header_details .= '<div class="event-title">'.$event->event_title.'</div><div class="event-title-break"></div>'; |
| 1695 |
if ($event->event_time != "00:00:00") |
| 1696 |
{ |
| 1697 |
$header_details .= '<strong>Time:</strong> ' . date(get_option('time_format'), strtotime($event->event_time)) . '<br />'; |
| 1698 |
} |
| 1699 |
if ($display_author == 'true') |
| 1700 |
{ |
| 1701 |
$e = get_userdata($event->event_author); |
| 1702 |
$header_details .= '<strong>Posted by:</strong> '.$e->display_name.'<br />'; |
| 1703 |
} |
| 1704 |
if ($display_author == 'true' || $event->event_time != "00:00:00") |
| 1705 |
{ |
| 1706 |
$header_details .= '<div class="event-content-break"></div>'; |
| 1707 |
} |
| 1708 |
if ($event->event_link != '') { $linky = $event->event_link; } |
| 1709 |
else { $linky = '#'; } |
| 1710 |
|
| 1711 |
$details = '<br /> |
| 1712 |
* <span class="calnk" nowrap="nowrap"><a href="'.$linky.'" style="'.$style.'">' . $event->event_title . '<span style="'.$style.'">' . $header_details . '' . $event->event_desc . '</span></a></span>'; |
| 1713 |
|
| 1714 |
return $details; |
| 1715 |
} |
| 1716 |
|
| 1717 |
// Draw an event but customise the HTML for use in the widget |
| 1718 |
function draw_widget_event($event) |
| 1719 |
{ |
| 1720 |
global $wpdb; |
| 1721 |
|
| 1722 |
// Calendar must be updated to run this function |
| 1723 |
check_calendar(); |
| 1724 |
|
| 1725 |
// Before we do anything we want to know if we |
| 1726 |
// should display the author and/or show categories. |
| 1727 |
// We check for this later |
| 1728 |
$display_author = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='display_author'",0,0); |
| 1729 |
$show_cat = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='enable_categories'",0,0); |
| 1730 |
|
| 1731 |
if ($show_cat == 'true') |
| 1732 |
{ |
| 1733 |
$sql = "SELECT * FROM " . WP_CALENDAR_CATEGORIES_TABLE . " WHERE category_id=".$event->event_category; |
| 1734 |
$cat_details = $wpdb->get_row($sql); |
| 1735 |
$style = "background-color:".$cat_details->category_colour.";"; |
| 1736 |
} |
| 1737 |
|
| 1738 |
$header_details .= '<div class="event-title">'.$event->event_title.'</div><div class="event-title-break"></div>'; |
| 1739 |
if ($event->event_time != "00:00:00") |
| 1740 |
{ |
| 1741 |
$header_details .= '<strong>Time:</strong> ' . date(get_option('time_format'), strtotime($event->event_time)) . '<br />'; |
| 1742 |
} |
| 1743 |
if ($display_author == 'true') |
| 1744 |
{ |
| 1745 |
$e = get_userdata($event->event_author); |
| 1746 |
$header_details .= '<strong>Posted by:</strong> '.$e->display_name.'<br />'; |
| 1747 |
} |
| 1748 |
if ($display_author == 'true' || $event->event_time != "00:00:00") |
| 1749 |
{ |
| 1750 |
$header_details .= '<div class="event-content-break"></div>'; |
| 1751 |
} |
| 1752 |
if ($event->event_link != '') { $linky = $event->event_link; } |
| 1753 |
else { $linky = '#'; } |
| 1754 |
|
| 1755 |
$details = '<span class="calnk" nowrap="nowrap"><a href="'.$linky.'">' . $event->event_title . '<span style="'.$style.'">' . $header_details . '' . $event->event_desc . '</span></a></span>'; |
| 1756 |
|
| 1757 |
return $details; |
| 1758 |
} |
| 1759 |
|
| 1760 |
// Grab all events for the requested date from calendar |
| 1761 |
function grab_events($y,$m,$d) |
| 1762 |
{ |
| 1763 |
global $wpdb; |
| 1764 |
|
| 1765 |
$arr_events = array(); |
| 1766 |
|
| 1767 |
// Get the date format right |
| 1768 |
$date = $y . '-' . $m . '-' . $d; |
| 1769 |
|
| 1770 |
// Firstly we check for conventional events. These will form the first instance of a recurring event |
| 1771 |
// or the only instance of a one-off event |
| 1772 |
$events = $wpdb->get_results("SELECT * FROM " . WP_CALENDAR_TABLE . " WHERE event_begin <= '$date' AND event_end >= '$date' AND event_recur = 'S' ORDER BY event_id"); |
| 1773 |
if (!empty($events)) |
| 1774 |
{ |
| 1775 |
foreach($events as $event) |
| 1776 |
{ |
| 1777 |
array_push($arr_events, $event); |
| 1778 |
} |
| 1779 |
} |
| 1780 |
|
| 1781 |
// Even if there were results for that query, we may still have events recurring |
| 1782 |
// from the past on this day. We now methodically check the for these events |
| 1783 |
|
| 1784 |
/* |
| 1785 |
The yearly code - easy because the day and month will be the same, so we return all yearly |
| 1786 |
events that match the date part. Out of these we show those with a repeat of 0, and fast-foward |
| 1787 |
a number of years for those with a value more than 0. Those that land in the future are displayed. |
| 1788 |
*/ |
| 1789 |
|
| 1790 |
|
| 1791 |
// Deal with forever recurring year events |
| 1792 |
$events = $wpdb->get_results("SELECT * FROM " . WP_CALENDAR_TABLE . " WHERE event_recur = 'Y' AND EXTRACT(YEAR FROM '$date') >= EXTRACT(YEAR FROM event_begin) AND event_repeats = 0 ORDER BY event_id"); |
| 1793 |
|
| 1794 |
if (!empty($events)) |
| 1795 |
{ |
| 1796 |
foreach($events as $event) |
| 1797 |
{ |
| 1798 |
// This is going to get complex so lets setup what we would place in for |
| 1799 |
// an event so we can drop it in with ease |
| 1800 |
|
| 1801 |
// Technically we don't care about the years, but we need to find out if the |
| 1802 |
// event spans the turn of a year so we can deal with it appropriately. |
| 1803 |
$year_begin = date('Y',strtotime($event->event_begin)); |
| 1804 |
$year_end = date('Y',strtotime($event->event_end)); |
| 1805 |
|
| 1806 |
if ($year_begin == $year_end) |
| 1807 |
{ |
| 1808 |
if (date('m-d',strtotime($event->event_begin)) <= date('m-d',strtotime($date)) && |
| 1809 |
date('m-d',strtotime($event->event_end)) >= date('m-d',strtotime($date))) |
| 1810 |
{ |
| 1811 |
array_push($arr_events, $event); |
| 1812 |
} |
| 1813 |
} |
| 1814 |
else if ($year_begin < $year_end) |
| 1815 |
{ |
| 1816 |
if (date('m-d',strtotime($event->event_begin)) <= date('m-d',strtotime($date)) || |
| 1817 |
date('m-d',strtotime($event->event_end)) >= date('m-d',strtotime($date))) |
| 1818 |
{ |
| 1819 |
array_push($arr_events, $event); |
| 1820 |
} |
| 1821 |
} |
| 1822 |
} |
| 1823 |
} |
| 1824 |
|
| 1825 |
// Now the ones that happen a finite number of times |
| 1826 |
$events = $wpdb->get_results("SELECT * FROM " . WP_CALENDAR_TABLE . " WHERE event_recur = 'Y' AND EXTRACT(YEAR FROM '$date') >= EXTRACT(YEAR FROM event_begin) AND event_repeats != 0 AND (EXTRACT(YEAR FROM '$date')-EXTRACT(YEAR FROM event_begin)) <= event_repeats ORDER BY event_id"); |
| 1827 |
if (!empty($events)) |
| 1828 |
{ |
| 1829 |
foreach($events as $event) |
| 1830 |
{ |
| 1831 |
// This is going to get complex so lets setup what we would place in for |
| 1832 |
// an event so we can drop it in with ease |
| 1833 |
|
| 1834 |
// Technically we don't care about the years, but we need to find out if the |
| 1835 |
// event spans the turn of a year so we can deal with it appropriately. |
| 1836 |
$year_begin = date('Y',strtotime($event->event_begin)); |
| 1837 |
$year_end = date('Y',strtotime($event->event_end)); |
| 1838 |
|
| 1839 |
if ($year_begin == $year_end) |
| 1840 |
{ |
| 1841 |
if (date('m-d',strtotime($event->event_begin)) <= date('m-d',strtotime($date)) && |
| 1842 |
date('m-d',strtotime($event->event_end)) >= date('m-d',strtotime($date))) |
| 1843 |
{ |
| 1844 |
array_push($arr_events, $event); |
| 1845 |
} |
| 1846 |
} |
| 1847 |
else if ($year_begin < $year_end) |
| 1848 |
{ |
| 1849 |
if (date('m-d',strtotime($event->event_begin)) <= date('m-d',strtotime($date)) || |
| 1850 |
date('m-d',strtotime($event->event_end)) >= date('m-d',strtotime($date))) |
| 1851 |
{ |
| 1852 |
array_push($arr_events, $event); |
| 1853 |
} |
| 1854 |
} |
| 1855 |
} |
| 1856 |
} |
| 1857 |
|
| 1858 |
/* |
| 1859 |
The monthly code - just as easy because as long as the day of the month is correct, then we |
| 1860 |
show the event |
| 1861 |
*/ |
| 1862 |
|
| 1863 |
// The monthly events that never stop recurring |
| 1864 |
$events = $wpdb->get_results("SELECT * FROM " . WP_CALENDAR_TABLE . " WHERE event_recur = 'M' AND EXTRACT(YEAR FROM '$date') >= EXTRACT(YEAR FROM event_begin) AND event_repeats = 0 ORDER BY event_id"); |
| 1865 |
if (!empty($events)) |
| 1866 |
{ |
| 1867 |
foreach($events as $event) |
| 1868 |
{ |
| 1869 |
// This is going to get complex so lets setup what we would place in for |
| 1870 |
// an event so we can drop it in with ease |
| 1871 |
|
| 1872 |
// Technically we don't care about the years or months, but we need to find out if the |
| 1873 |
// event spans the turn of a year or month so we can deal with it appropriately. |
| 1874 |
$month_begin = date('m',strtotime($event->event_begin)); |
| 1875 |
$month_end = date('m',strtotime($event->event_end)); |
| 1876 |
|
| 1877 |
if ($month_begin == $month_end) |
| 1878 |
{ |
| 1879 |
if (date('d',strtotime($event->event_begin)) <= date('d',strtotime($date)) && |
| 1880 |
date('d',strtotime($event->event_end)) >= date('d',strtotime($date))) |
| 1881 |
{ |
| 1882 |
array_push($arr_events, $event); |
| 1883 |
} |
| 1884 |
} |
| 1885 |
else if ($month_begin < $month_end) |
| 1886 |
{ |
| 1887 |
if ( ($event->event_begin <= date('Y-m-d',strtotime($date))) && (date('d',strtotime($event->event_begin)) <= date('d',strtotime($date)) || |
| 1888 |
date('d',strtotime($event->event_end)) >= date('d',strtotime($date))) ) |
| 1889 |
{ |
| 1890 |
array_push($arr_events, $event); |
| 1891 |
} |
| 1892 |
} |
| 1893 |
} |
| 1894 |
} |
| 1895 |
|
| 1896 |
|
| 1897 |
// Now the ones that happen a finite number of times |
| 1898 |
$events = $wpdb->get_results("SELECT * FROM " . WP_CALENDAR_TABLE . " WHERE event_recur = 'M' AND EXTRACT(YEAR FROM '$date') >= EXTRACT(YEAR FROM event_begin) AND event_repeats != 0 AND (PERIOD_DIFF(EXTRACT(YEAR_MONTH FROM '$date'),EXTRACT(YEAR_MONTH FROM event_begin))) <= event_repeats ORDER BY event_id"); |
| 1899 |
if (!empty($events)) |
| 1900 |
{ |
| 1901 |
foreach($events as $event) |
| 1902 |
{ |
| 1903 |
// This is going to get complex so lets setup what we would place in for |
| 1904 |
// an event so we can drop it in with ease |
| 1905 |
|
| 1906 |
// Technically we don't care about the years or months, but we need to find out if the |
| 1907 |
// event spans the turn of a year or month so we can deal with it appropriately. |
| 1908 |
$month_begin = date('m',strtotime($event->event_begin)); |
| 1909 |
$month_end = date('m',strtotime($event->event_end)); |
| 1910 |
|
| 1911 |
if ($month_begin == $month_end) |
| 1912 |
{ |
| 1913 |
if (date('d',strtotime($event->event_begin)) <= date('d',strtotime($date)) && |
| 1914 |
date('d',strtotime($event->event_end)) >= date('d',strtotime($date))) |
| 1915 |
{ |
| 1916 |
array_push($arr_events, $event); |
| 1917 |
} |
| 1918 |
} |
| 1919 |
else if ($month_begin < $month_end) |
| 1920 |
{ |
| 1921 |
if ( ($event->event_begin <= date('Y-m-d',strtotime($date))) && (date('d',strtotime($event->event_begin)) <= date('d',strtotime($date)) || |
| 1922 |
date('d',strtotime($event->event_end)) >= date('d',strtotime($date))) ) |
| 1923 |
{ |
| 1924 |
array_push($arr_events, $event); |
| 1925 |
} |
| 1926 |
} |
| 1927 |
} |
| 1928 |
} |
| 1929 |
|
| 1930 |
|
| 1931 |
/* |
| 1932 |
Weekly - well isn't this fun! We need to scan all weekly events, find what day they fell on |
| 1933 |
and see if that matches the current day. If it does, we check to see if the repeats are 0. |
| 1934 |
If they are, display the event, if not, we fast forward from the original day in week blocks |
| 1935 |
until the number is exhausted. If the date we arrive at is in the future, display the event. |
| 1936 |
*/ |
| 1937 |
|
| 1938 |
// The weekly events that never stop recurring |
| 1939 |
$events = $wpdb->get_results("SELECT * FROM " . WP_CALENDAR_TABLE . " WHERE event_recur = 'W' AND '$date' >= event_begin AND event_repeats = 0 ORDER BY event_id"); |
| 1940 |
if (!empty($events)) |
| 1941 |
{ |
| 1942 |
foreach($events as $event) |
| 1943 |
{ |
| 1944 |
// This is going to get complex so lets setup what we would place in for |
| 1945 |
// an event so we can drop it in with ease |
| 1946 |
|
| 1947 |
// Now we are going to check to see what day the original event |
| 1948 |
// fell on and see if the current date is both after it and on |
| 1949 |
// the correct day. If it is, display the event! |
| 1950 |
$day_start_event = date('D',strtotime($event->event_begin)); |
| 1951 |
$day_end_event = date('D',strtotime($event->event_end)); |
| 1952 |
$current_day = date('D',strtotime($date)); |
| 1953 |
|
| 1954 |
$plan = array(); |
| 1955 |
$plan['Mon'] = 1; |
| 1956 |
$plan['Tue'] = 2; |
| 1957 |
$plan['Wed'] = 3; |
| 1958 |
$plan['Thu'] = 4; |
| 1959 |
$plan['Fri'] = 5; |
| 1960 |
$plan['Sat'] = 6; |
| 1961 |
$plan['Sun'] = 7; |
| 1962 |
|
| 1963 |
if ($plan[$day_start_event] > $plan[$day_end_event]) |
| 1964 |
{ |
| 1965 |
if (($plan[$day_start_event] <= $plan[$current_day]) || ($plan[$current_day] <= $plan[$day_end_event])) |
| 1966 |
{ |
| 1967 |
array_push($arr_events, $event); |
| 1968 |
} |
| 1969 |
} |
| 1970 |
else if (($plan[$day_start_event] < $plan[$day_end_event]) || ($plan[$day_start_event]== $plan[$day_end_event])) |
| 1971 |
{ |
| 1972 |
if (($plan[$day_start_event] <= $plan[$current_day]) && ($plan[$current_day] <= $plan[$day_end_event])) |
| 1973 |
{ |
| 1974 |
array_push($arr_events, $event); |
| 1975 |
} |
| 1976 |
} |
| 1977 |
|
| 1978 |
} |
| 1979 |
} |
| 1980 |
|
| 1981 |
// The weekly events that have a limit on how many times they occur |
| 1982 |
$events = $wpdb->get_results("SELECT * FROM " . WP_CALENDAR_TABLE . " WHERE event_recur = 'W' AND '$date' >= event_begin AND event_repeats != 0 AND (event_repeats*7) >= (TO_DAYS('$date') - TO_DAYS(event_end)) ORDER BY event_id"); |
| 1983 |
if (!empty($events)) |
| 1984 |
{ |
| 1985 |
foreach($events as $event) |
| 1986 |
{ |
| 1987 |
// This is going to get complex so lets setup what we would place in for |
| 1988 |
// an event so we can drop it in with ease |
| 1989 |
|
| 1990 |
// Now we are going to check to see what day the original event |
| 1991 |
// fell on and see if the current date is both after it and on |
| 1992 |
// the correct day. If it is, display the event! |
| 1993 |
$day_start_event = date('D',strtotime($event->event_begin)); |
| 1994 |
$day_end_event = date('D',strtotime($event->event_end)); |
| 1995 |
$current_day = date('D',strtotime($date)); |
| 1996 |
|
| 1997 |
$plan = array(); |
| 1998 |
$plan['Mon'] = 1; |
| 1999 |
$plan['Tue'] = 2; |
| 2000 |
$plan['Wed'] = 3; |
| 2001 |
$plan['Thu'] = 4; |
| 2002 |
$plan['Fri'] = 5; |
| 2003 |
$plan['Sat'] = 6; |
| 2004 |
$plan['Sun'] = 7; |
| 2005 |
|
| 2006 |
if ($plan[$day_start_event] > $plan[$day_end_event]) |
| 2007 |
{ |
| 2008 |
if (($plan[$day_start_event] <= $plan[$current_day]) || ($plan[$current_day] <= $plan[$day_end_event])) |
| 2009 |
{ |
| 2010 |
array_push($arr_events, $event); |
| 2011 |
} |
| 2012 |
} |
| 2013 |
else if (($plan[$day_start_event] < $plan[$day_end_event]) || ($plan[$day_start_event]== $plan[$day_end_event])) |
| 2014 |
{ |
| 2015 |
if (($plan[$day_start_event] <= $plan[$current_day]) && ($plan[$current_day] <= $plan[$day_end_event])) |
| 2016 |
{ |
| 2017 |
array_push($arr_events, $event); |
| 2018 |
} |
| 2019 |
} |
| 2020 |
|
| 2021 |
} |
| 2022 |
} |
| 2023 |
|
| 2024 |
return $arr_events; |
| 2025 |
} |
| 2026 |
|
| 2027 |
|
| 2028 |
// Actually do the printing of the calendar |
| 2029 |
// Compared to searching for and displaying events |
| 2030 |
// this bit is really rather easy! |
| 2031 |
function calendar() |
| 2032 |
{ |
| 2033 |
global $wpdb; |
| 2034 |
|
| 2035 |
// First things first, make sure calendar is up to date |
| 2036 |
check_calendar(); |
| 2037 |
|
| 2038 |
// Deal with the week not starting on a monday |
| 2039 |
if (get_option('start_of_week') == 0) |
| 2040 |
{ |
| 2041 |
$name_days = array(1=>'Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); |
| 2042 |
} |
| 2043 |
// Choose Monday if anything other than Sunday is set |
| 2044 |
else |
| 2045 |
{ |
| 2046 |
$name_days = array(1=>'Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'); |
| 2047 |
} |
| 2048 |
|
| 2049 |
// Carry on with the script |
| 2050 |
$name_months = array(1=>'January','February','March','April','May','June','July','August','September','October','November','December'); |
| 2051 |
|
| 2052 |
// If we don't pass arguments we want a calendar that is relevant to today |
| 2053 |
if (empty($_GET['month']) || empty($_GET['yr'])) |
| 2054 |
{ |
| 2055 |
$c_year = date("Y"); |
| 2056 |
$c_month = date("m"); |
| 2057 |
$c_day = date("d"); |
| 2058 |
} |
| 2059 |
|
| 2060 |
// Years get funny if we exceed 3000, so we use this check |
| 2061 |
if ($_GET['yr'] <= 3000 && $_GET['yr'] >= 0) |
| 2062 |
{ |
| 2063 |
// This is just plain nasty and all because of permalinks |
| 2064 |
// which are no longer used, this will be cleaned up soon |
| 2065 |
if ($_GET['month'] == 'jan' || $_GET['month'] == 'feb' || $_GET['month'] == 'mar' || $_GET['month'] == 'apr' || $_GET['month'] == 'may' || $_GET['month'] == 'jun' || $_GET['month'] == 'jul' || $_GET['month'] == 'aug' || $_GET['month'] == 'sept' || $_GET['month'] == 'oct' || $_GET['month'] == 'nov' || $_GET['month'] == 'dec') |
| 2066 |
{ |
| 2067 |
|
| 2068 |
// Again nasty code to map permalinks into something |
| 2069 |
// databases can understand. This will be cleaned up |
| 2070 |
$c_year = mysql_escape_string($_GET['yr']); |
| 2071 |
if ($_GET['month'] == 'jan') { $t_month = 1; } |
| 2072 |
else if ($_GET['month'] == 'feb') { $t_month = 2; } |
| 2073 |
else if ($_GET['month'] == 'mar') { $t_month = 3; } |
| 2074 |
else if ($_GET['month'] == 'apr') { $t_month = 4; } |
| 2075 |
else if ($_GET['month'] == 'may') { $t_month = 5; } |
| 2076 |
else if ($_GET['month'] == 'jun') { $t_month = 6; } |
| 2077 |
else if ($_GET['month'] == 'jul') { $t_month = 7; } |
| 2078 |
else if ($_GET['month'] == 'aug') { $t_month = 8; } |
| 2079 |
else if ($_GET['month'] == 'sept') { $t_month = 9; } |
| 2080 |
else if ($_GET['month'] == 'oct') { $t_month = 10; } |
| 2081 |
else if ($_GET['month'] == 'nov') { $t_month = 11; } |
| 2082 |
else if ($_GET['month'] == 'dec') { $t_month = 12; } |
| 2083 |
$c_month = $t_month; |
| 2084 |
$c_day = date("d"); |
| 2085 |
} |
| 2086 |
// No valid month causes the calendar to default to today |
| 2087 |
else |
| 2088 |
{ |
| 2089 |
$c_year = date("Y"); |
| 2090 |
$c_month = date("m"); |
| 2091 |
$c_day = date("d"); |
| 2092 |
} |
| 2093 |
} |
| 2094 |
// No valid year causes the calendar to default to today |
| 2095 |
else |
| 2096 |
{ |
| 2097 |
$c_year = date("Y"); |
| 2098 |
$c_month = date("m"); |
| 2099 |
$c_day = date("d"); |
| 2100 |
} |
| 2101 |
|
| 2102 |
// Fix the days of the week if week start is not on a monday |
| 2103 |
if (get_option('start_of_week') == 0) |
| 2104 |
{ |
| 2105 |
$first_weekday = date("w",mktime(0,0,0,$c_month,1,$c_year)); |
| 2106 |
$first_weekday = ($first_weekday==0?1:$first_weekday+1); |
| 2107 |
} |
| 2108 |
// Otherwise assume the week starts on a Monday. Anything other |
| 2109 |
// than Sunday or Monday is just plain odd |
| 2110 |
else |
| 2111 |
{ |
| 2112 |
$first_weekday = date("w",mktime(0,0,0,$c_month,1,$c_year)); |
| 2113 |
$first_weekday = ($first_weekday==0?7:$first_weekday); |
| 2114 |
} |
| 2115 |
|
| 2116 |
$days_in_month = date("t", mktime (0,0,0,$c_month,1,$c_year)); |
| 2117 |
|
| 2118 |
// Start the table and add the header and naviagtion |
| 2119 |
$calendar_body .= ' |
| 2120 |
<table cellspacing="1" cellpadding="0" class="calendar-table"> |
| 2121 |
'; |
| 2122 |
|
| 2123 |
// We want to know if we should display the date switcher |
| 2124 |
$date_switcher = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='display_jump'",0,0); |
| 2125 |
|
| 2126 |
if ($date_switcher == 'true') |
| 2127 |
{ |
| 2128 |
$calendar_body .= '<tr> |
| 2129 |
<td colspan="7" class="calendar-date-switcher"> |
| 2130 |
<form method="GET" action="'.$_SERVER['REQUEST_URI'].'"> |
| 2131 |
'; |
| 2132 |
$qsa = array(); |
| 2133 |
parse_str($_SERVER['QUERY_STRING'],$qsa); |
| 2134 |
foreach ($qsa as $name => $argument) |
| 2135 |
{ |
| 2136 |
if ($name != 'month' && $name != 'yr') |
| 2137 |
{ |
| 2138 |
$calendar_body .= '<input type="hidden" name="'.$name.'" value="'.$argument.'" /> |
| 2139 |
'; |
| 2140 |
} |
| 2141 |
} |
| 2142 |
function month_comparison($month) |
| 2143 |
{ |
| 2144 |
$current_month = strtolower(date("M", time())); |
| 2145 |
if (isset($_GET['yr']) && isset($_GET['month'])) |
| 2146 |
{ |
| 2147 |
if ($month == $_GET['month']) |
| 2148 |
{ |
| 2149 |
return ' selected="selected"'; |
| 2150 |
} |
| 2151 |
} |
| 2152 |
elseif ($month == $current_month) |
| 2153 |
{ |
| 2154 |
return ' selected="selected"'; |
| 2155 |
} |
| 2156 |
} |
| 2157 |
// We build the months in the switcher |
| 2158 |
$calendar_body .= ' |
| 2159 |
Month: <select name="month" style="width:100px;"> |
| 2160 |
<option value="jan"'.month_comparison('jan').'>January</option> |
| 2161 |
<option value="feb"'.month_comparison('feb').'>February</option> |
| 2162 |
<option value="mar"'.month_comparison('mar').'>March</option> |
| 2163 |
<option value="apr"'.month_comparison('apr').'>April</option> |
| 2164 |
<option value="may"'.month_comparison('may').'>May</option> |
| 2165 |
<option value="jun"'.month_comparison('jun').'>June</option> |
| 2166 |
<option value="jul"'.month_comparison('jul').'>July</option> |
| 2167 |
<option value="aug"'.month_comparison('aug').'>August</option> |
| 2168 |
<option value="sept"'.month_comparison('sept').'>September</option> |
| 2169 |
<option value="oct"'.month_comparison('oct').'>October</option> |
| 2170 |
<option value="nov"'.month_comparison('nov').'>November</option> |
| 2171 |
<option value="dec"'.month_comparison('dec').'>December</option> |
| 2172 |
</select> |
| 2173 |
Year: <select name="yr" style="width:60px;"> |
| 2174 |
'; |
| 2175 |
|
| 2176 |
// The year builder is string mania. If you can make sense of this, |
| 2177 |
// you know your PHP! |
| 2178 |
function year_comparison($year) |
| 2179 |
{ |
| 2180 |
$current_year = strtolower(date("Y", time())); |
| 2181 |
if (isset($_GET['yr']) && isset($_GET['month'])) |
| 2182 |
{ |
| 2183 |
if ($year == $_GET['yr']) |
| 2184 |
{ |
| 2185 |
return ' selected="selected"'; |
| 2186 |
} |
| 2187 |
} |
| 2188 |
else if ($year == $current_year) |
| 2189 |
{ |
| 2190 |
return ' selected="selected"'; |
| 2191 |
} |
| 2192 |
} |
| 2193 |
|
| 2194 |
$past = 30; |
| 2195 |
$future = 30; |
| 2196 |
$fut = 1; |
| 2197 |
while ($past > 0) |
| 2198 |
{ |
| 2199 |
$p .= ' <option value="'; |
| 2200 |
$p .= date("Y",time())-$past; |
| 2201 |
$p .= '"'.year_comparison(date("Y",time())-$past).'>'; |
| 2202 |
$p .= date("Y",time())-$past.'</option> |
| 2203 |
'; |
| 2204 |
$past = $past - 1; |
| 2205 |
} |
| 2206 |
while ($fut < $future) |
| 2207 |
{ |
| 2208 |
$f .= ' <option value="'; |
| 2209 |
$f .= date("Y",time())+$fut; |
| 2210 |
$f .= '"'.year_comparison(date("Y",time())+$fut).'>'; |
| 2211 |
$f .= date("Y",time())+$fut.'</option> |
| 2212 |
'; |
| 2213 |
$fut = $fut + 1; |
| 2214 |
} |
| 2215 |
$calendar_body .= $p; |
| 2216 |
$calendar_body .= ' <option value="'.date("Y",time()).'"'.year_comparison(date("Y",time())).'>'.date("Y",time()).'</option> |
| 2217 |
'; |
| 2218 |
$calendar_body .= $f; |
| 2219 |
$calendar_body .= '</select> |
| 2220 |
<input type="submit" value="Go" /> |
| 2221 |
</form> |
| 2222 |
</td> |
| 2223 |
</tr> |
| 2224 |
'; |
| 2225 |
} |
| 2226 |
|
| 2227 |
// The header of the calendar table and the links. Note calls to link functions |
| 2228 |
$calendar_body .= '<tr> |
| 2229 |
<td colspan="7" class="calendar-heading"> |
| 2230 |
<table border="0" cellpadding="0" cellspacing="0" width="100%"> |
| 2231 |
<tr> |
| 2232 |
<td class="calendar-prev">' . prev_link($c_year,$c_month) . '</td> |
| 2233 |
<td class="calendar-month">'.$name_months[(int)$c_month].' '.$c_year.'</td> |
| 2234 |
<td class="calendar-next">' . next_link($c_year,$c_month) . '</td> |
| 2235 |
</tr> |
| 2236 |
</table> |
| 2237 |
</td> |
| 2238 |
</tr> |
| 2239 |
'; |
| 2240 |
|
| 2241 |
// Print the headings of the days of the week |
| 2242 |
$calendar_body .= '<tr> |
| 2243 |
'; |
| 2244 |
for ($i=1; $i<=7; $i++) |
| 2245 |
{ |
| 2246 |
// Colours need to be different if the starting day of the week is different |
| 2247 |
if (get_option('start_of_week') == 0) |
| 2248 |
{ |
| 2249 |
$calendar_body .= ' <td class="'.($i<7&&$i>1?'normal-day-heading':'weekend-heading').'">'.$name_days[$i].'</td> |
| 2250 |
'; |
| 2251 |
} |
| 2252 |
else |
| 2253 |
{ |
| 2254 |
$calendar_body .= ' <td class="'.($i<6?'normal-day-heading':'weekend-heading').'">'.$name_days[$i].'</td> |
| 2255 |
'; |
| 2256 |
} |
| 2257 |
} |
| 2258 |
$calendar_body .= '</tr> |
| 2259 |
'; |
| 2260 |
|
| 2261 |
for ($i=1; $i<=$days_in_month;) |
| 2262 |
{ |
| 2263 |
$calendar_body .= '<tr> |
| 2264 |
'; |
| 2265 |
for ($ii=1; $ii<=7; $ii++) |
| 2266 |
{ |
| 2267 |
if ($ii==$first_weekday && $i==1) |
| 2268 |
{ |
| 2269 |
$go = TRUE; |
| 2270 |
} |
| 2271 |
elseif ($i > $days_in_month ) |
| 2272 |
{ |
| 2273 |
$go = FALSE; |
| 2274 |
} |
| 2275 |
|
| 2276 |
if ($go) |
| 2277 |
{ |
| 2278 |
// Colours again, this time for the day numbers |
| 2279 |
if (get_option('start_of_week') == 0) |
| 2280 |
{ |
| 2281 |
// This bit of code is for styles believe it or not. |
| 2282 |
$grabbed_events = grab_events($c_year,$c_month,$i); |
| 2283 |
$no_events_class = ''; |
| 2284 |
if (!count($grabbed_events)) |
| 2285 |
{ |
| 2286 |
$no_events_class = ' no-events'; |
| 2287 |
} |
| 2288 |
$calendar_body .= ' <td class="'.(date("Ymd", mktime (0,0,0,$c_month,$i,$c_year))==date("Ymd")?'current-day':'day-with-date').$no_events_class.'"><span '.($ii<7&&$ii>1?'':'class="weekend"').'>'.$i++.'</span><span class="event">' . draw_events($grabbed_events) . '</span></td> |
| 2289 |
'; |
| 2290 |
} |
| 2291 |
else |
| 2292 |
{ |
| 2293 |
$grabbed_events = grab_events($c_year,$c_month,$i); |
| 2294 |
$no_events_class = ''; |
| 2295 |
if (!count($grabbed_events)) |
| 2296 |
{ |
| 2297 |
$no_events_class = ' no-events'; |
| 2298 |
} |
| 2299 |
$calendar_body .= ' <td class="'.(date("Ymd", mktime (0,0,0,$c_month,$i,$c_year))==date("Ymd")?'current-day':'day-with-date').$no_events_class.'"><span '.($ii<6?'':'class="weekend"').'>'.$i++.'</span><span class="event">' . draw_events($grabbed_events) . '</span></td> |
| 2300 |
'; |
| 2301 |
} |
| 2302 |
} |
| 2303 |
else |
| 2304 |
{ |
| 2305 |
$calendar_body .= ' <td class="day-without-date"> </td> |
| 2306 |
'; |
| 2307 |
} |
| 2308 |
} |
| 2309 |
$calendar_body .= '</tr> |
| 2310 |
'; |
| 2311 |
} |
| 2312 |
$show_cat = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='enable_categories'",0,0); |
| 2313 |
|
| 2314 |
if ($show_cat == 'true') |
| 2315 |
{ |
| 2316 |
$sql = "SELECT * FROM " . WP_CALENDAR_CATEGORIES_TABLE . " ORDER BY category_name ASC"; |
| 2317 |
$cat_details = $wpdb->get_results($sql); |
| 2318 |
$calendar_body .= '<tr><td colspan="7"> |
| 2319 |
<table class="cat-key"> |
| 2320 |
<tr><td colspan="2"><strong>Category Key</strong></td></tr> |
| 2321 |
'; |
| 2322 |
foreach($cat_details as $cat_detail) |
| 2323 |
{ |
| 2324 |
$calendar_body .= '<tr><td style="background-color:'.$cat_detail->category_colour.'; width:20px; height:20px;"></td><td>'.$cat_detail->category_name.'</td></tr>'; |
| 2325 |
} |
| 2326 |
$calendar_body .= '</table> |
| 2327 |
</td></tr> |
| 2328 |
'; |
| 2329 |
} |
| 2330 |
$calendar_body .= '</table> |
| 2331 |
'; |
| 2332 |
|
| 2333 |
// A little link to yours truely. See the README if you wish to remove this |
| 2334 |
$calendar_body .= '<div class="kjo-link"><p>Web development and hosting from <a href="http://www.kjowebservices.co.uk">KJO Web Services</a></p></div> |
| 2335 |
'; |
| 2336 |
|
| 2337 |
// Phew! After that bit of string building, spit it all out. |
| 2338 |
// The actual printing is done by the calling function. |
| 2339 |
return $calendar_body; |
| 2340 |
} |
| 2341 |
|
| 2342 |
?> |
| 2343 |
|