Calendar - Version 1.2.1

Version Description

Download this release

Release Info

Developer KieranOShea
Plugin Icon 128x128 Calendar
Version 1.2.1
Comparing to
See all releases

Code changes from version 1.0 to 1.2.1

README DELETED
@@ -1,52 +0,0 @@
1
- ------ Calendar for WordPress v1.0 ------
2
-
3
- Author: Kieran O'Shea
4
- E-Mail: kieran@kieranoshea.com
5
- Website: http://www.kieranoshea.com
6
-
7
- -----------------------------------------
8
-
9
- Installing:
10
-
11
- 1. Add the lines in the .htaccess file to the bottom of you pre-existing .htaccess
12
- file in your WordPress root directory. Do not simply upload the file or else your
13
- permalink and other mod_rewrite rules will be deleted and may cause your blog to
14
- no longer function correctly.
15
-
16
- 2. Upload the other included files into the same directories as they are in the package
17
-
18
- 3. Visit the plugins page of your dashboard and activate Calendar 1.0 by Kieran O'Shea
19
-
20
- 4. Visit Manage -> Calendar in the dashboard to initialise the database and start adding
21
- calendar events into your system
22
-
23
- 5. Visit your blog URL /calendar to see your calendar in action
24
-
25
-
26
-
27
- Modifying the calendar page:
28
-
29
- 1. You can modify the look and layout of the public calendar page by editing
30
- wp-calendar.php
31
-
32
-
33
-
34
- Removing the link to me:
35
-
36
- 1. If you want to remove the text and link to my site from underneath the calendar you can
37
- do so in the calendar.php file. Please only do this if you have to though as it will stop
38
- other people from finding out how to get their own copy. You could always link to me in
39
- your blogroll or in your site footer as an alternative if you prefer. Ultimately it's your
40
- site however and if you don't want to link to me you are under no obligation to do so.
41
-
42
-
43
-
44
- Uninstalling:
45
-
46
- 1. Deactivate the plugin on the plugins page of your blog dashboard
47
-
48
- 2. Delete the uploaded files for the plugin
49
-
50
- 3. Remove the added lines from the .htaccess file
51
-
52
- 4. Drop the wp_calendar table from your database
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
calendar.php ADDED
@@ -0,0 +1,2341 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.1
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, __FILE__, 'edit_calendar');
113
+ }
114
+ if (function_exists('add_submenu_page'))
115
+ {
116
+ add_submenu_page(__FILE__, __('Manage Calendar'), __('Manage Calendar'), $allowed_group, __FILE__, 'edit_calendar');
117
+ add_action( "admin_head", 'calendar_add_javascript' );
118
+ // Note only admin can change calendar options
119
+ add_submenu_page(__FILE__, __('Manage Categories'), __('Manage Categories'), 'manage_options', 'manage-categories', 'manage_categories');
120
+ add_submenu_page(__FILE__, __('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" src="';
128
+ bloginfo('url');
129
+ echo '/wp-content/plugins/calendar/javascript.js"></script>
130
+ <script type="text/javascript">document.write(getCalendarStyles());</script>
131
+ ';
132
+ }
133
+
134
+ // Function to deal with loading the calendar into pages
135
+ function calendar_insert($content)
136
+ {
137
+ if (preg_match('{CALENDAR}',$content))
138
+ {
139
+ $content = str_replace('{CALENDAR}',calendar(),$content);
140
+ }
141
+ return $content;
142
+ }
143
+
144
+ // Function to check what version of Calendar is installed and install if needed
145
+ function check_calendar()
146
+ {
147
+ // Checks to make sure Calendar is installed, if not it adds the default
148
+ // database tables and populates them with test data. If it is, then the
149
+ // version is checked through various means and if it is not up to date
150
+ // then it is upgraded.
151
+
152
+ // Lets see if this is first run and create us a table if it is!
153
+ global $wpdb, $initial_style;
154
+
155
+ // All this style info will go into the database on a new install
156
+ // This looks nice in the Kubrick theme
157
+ $initial_style = " .calnk a:hover {
158
+ background-position:0 0;
159
+ text-decoration:none;
160
+ color:#000000;
161
+ border-bottom:1px dotted #000000;
162
+ }
163
+ .calnk a:visited {
164
+ text-decoration:none;
165
+ color:#000000;
166
+ border-bottom:1px dotted #000000;
167
+ }
168
+ .calnk a {
169
+ text-decoration:none;
170
+ color:#000000;
171
+ border-bottom:1px dotted #000000;
172
+ }
173
+ .calnk a span {
174
+ display:none;
175
+ }
176
+ .calnk a:hover span {
177
+ color:#333333;
178
+ background:#F6F79B;
179
+ display:block;
180
+ position:absolute;
181
+ margin-top:1px;
182
+ padding:5px;
183
+ width:150px;
184
+ z-index:100;
185
+ }
186
+ .calendar-table {
187
+ border:none;
188
+ width:100%;
189
+ }
190
+ .calendar-heading {
191
+ height:25px;
192
+ text-align:center;
193
+ border:1px solid #D6DED5;
194
+ background-color:#E4EBE3;
195
+ }
196
+ .calendar-next {
197
+ width:25%;
198
+ text-align:center;
199
+ }
200
+ .calendar-prev {
201
+ width:25%;
202
+ text-align:center;
203
+ }
204
+ .calendar-month {
205
+ width:50%;
206
+ text-align:center;
207
+ font-weight:bold;
208
+ }
209
+ .normal-day-heading {
210
+ text-align:center;
211
+ width:25px;
212
+ height:25px;
213
+ font-size:0.8em;
214
+ border:1px solid #DFE6DE;
215
+ background-color:#EBF2EA;
216
+ }
217
+ .weekend-heading {
218
+ text-align:center;
219
+ width:25px;
220
+ height:25px;
221
+ font-size:0.8em;
222
+ border:1px solid #DFE6DE;
223
+ background-color:#EBF2EA;
224
+ color:#FF0000;
225
+ }
226
+ .day-with-date {
227
+ vertical-align:text-top;
228
+ text-align:left;
229
+ width:60px;
230
+ height:60px;
231
+ border:1px solid #DFE6DE;
232
+ }
233
+ .no-events {
234
+
235
+ }
236
+ .day-without-date {
237
+ width:60px;
238
+ height:60px;
239
+ border:1px solid #E9F0E8;
240
+ }
241
+ span.weekend {
242
+ color:#FF0000;
243
+ }
244
+ .current-day {
245
+ vertical-align:text-top;
246
+ text-align:left;
247
+ width:60px;
248
+ height:60px;
249
+ border:1px solid #BFBFBF;
250
+ background-color:#E4EBE3;
251
+ }
252
+ span.event {
253
+ font-size:0.75em;
254
+ }
255
+ .kjo-link {
256
+ font-size:0.75em;
257
+ text-align:center;
258
+ }
259
+ .event-title {
260
+ text-align:center;
261
+ font-weight:bold;
262
+ font-size:1.2em;
263
+ }
264
+ .event-title-break {
265
+ width:96%;
266
+ margin-left:2%;
267
+ margin-right:2%;
268
+ margin-top:5px;
269
+ margin-bottom:5px;
270
+ text-align:center;
271
+ height:1px;
272
+ background-color:#000000;
273
+ }
274
+ .event-content-break {
275
+ width:96%;
276
+ margin-left:2%;
277
+ margin-right:2%;
278
+ margin-top:5px;
279
+ margin-bottom:5px;
280
+ text-align:center;
281
+ height:1px;
282
+ background-color:#000000;
283
+ }
284
+ .calendar-date-switcher {
285
+ height:25px;
286
+ text-align:center;
287
+ border:1px solid #D6DED5;
288
+ background-color:#E4EBE3;
289
+ }
290
+ .calendar-date-switcher form {
291
+ margin:0;
292
+ padding:0;
293
+ }
294
+ .calendar-date-switcher input {
295
+ border:1px #D6DED5 solid;
296
+ }
297
+ .calendar-date-switcher select {
298
+ border:1px #D6DED5 solid;
299
+ }
300
+ .cat-key {
301
+ width:100%;
302
+ margin-top:10px;
303
+ padding:5px;
304
+ border:1px solid #D6DED5;
305
+ }";
306
+
307
+
308
+ // Assume this is not a new install until we prove otherwise
309
+ $new_install = false;
310
+ $vone_point_one_upgrade = false;
311
+ $vone_point_two_beta_upgrade = false;
312
+
313
+ $wp_calendar_exists = false;
314
+ $wp_calendar_config_exists = false;
315
+ $wp_calendar_config_version_number_exists = false;
316
+
317
+ // Determine the calendar version
318
+ $tables = $wpdb->get_results("show tables;");
319
+ foreach ( $tables as $table )
320
+ {
321
+ foreach ( $table as $value )
322
+ {
323
+ if ( $value == WP_CALENDAR_TABLE )
324
+ {
325
+ $wp_calendar_exists = true;
326
+ }
327
+ if ( $value == WP_CALENDAR_CONFIG_TABLE )
328
+ {
329
+ $wp_calendar_config_exists = true;
330
+
331
+ // We now try and find the calendar version number
332
+ // This will be a lot easier than finding other stuff
333
+ // in the future.
334
+ $version_number = $wpdb->get_var("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='calendar_version'");
335
+ if ($version_number == "1.2")
336
+ {
337
+ $wp_calendar_config_version_number_exists = true;
338
+ }
339
+ }
340
+ }
341
+ }
342
+
343
+ if ($wp_calendar_exists == false && $wp_calendar_config_exists == false)
344
+ {
345
+ $new_install = true;
346
+ }
347
+ else if ($wp_calendar_exists == true && $wp_calendar_config_exists == false)
348
+ {
349
+ $vone_point_one_upgrade = true;
350
+ }
351
+ else if ($wp_calendar_exists == true && $wp_calendar_config_exists == true && $wp_calendar_config_version_number_exists == false)
352
+ {
353
+ $vone_point_two_beta_upgrade = true;
354
+ }
355
+
356
+ // Now we've determined what the current install is or isn't
357
+ // we perform operations according to the findings
358
+ if ( $new_install == true )
359
+ {
360
+ $sql = "CREATE TABLE " . WP_CALENDAR_TABLE . " (
361
+ event_id INT(11) NOT NULL AUTO_INCREMENT ,
362
+ event_begin DATE NOT NULL ,
363
+ event_end DATE NOT NULL ,
364
+ event_title VARCHAR(30) NOT NULL ,
365
+ event_desc TEXT NOT NULL ,
366
+ event_time TIME ,
367
+ event_recur CHAR(1) ,
368
+ event_repeats INT(3) ,
369
+ event_author BIGINT(20) UNSIGNED,
370
+ PRIMARY KEY (event_id)
371
+ )";
372
+ $wpdb->get_results($sql);
373
+ $sql = "CREATE TABLE " . WP_CALENDAR_CONFIG_TABLE . " (
374
+ config_item VARCHAR(30) NOT NULL ,
375
+ config_value TEXT NOT NULL ,
376
+ PRIMARY KEY (config_item)
377
+ )";
378
+ $wpdb->get_results($sql);
379
+ $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='can_manage_events', config_value='edit_posts'";
380
+ $wpdb->get_results($sql);
381
+ $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='calendar_style', config_value='".$initial_style."'";
382
+ $wpdb->get_results($sql);
383
+ $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='display_author', config_value='false'";
384
+ $wpdb->get_results($sql);
385
+ $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='display_jump', config_value='false'";
386
+ $wpdb->get_results($sql);
387
+ $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='display_todays', config_value='true'";
388
+ $wpdb->get_results($sql);
389
+ $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='display_upcoming', config_value='true'";
390
+ $wpdb->get_results($sql);
391
+ $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='display_upcoming_days', config_value=7";
392
+ $wpdb->get_results($sql);
393
+
394
+ $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='calendar_version', config_value='1.2'";
395
+ $wpdb->get_results($sql);
396
+ $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='enable_categories', config_value='false'";
397
+ $wpdb->get_results($sql);
398
+ $sql = "ALTER TABLE ".WP_CALENDAR_TABLE." ADD COLUMN event_category BIGINT(20) UNSIGNED";
399
+ $wpdb->get_results($sql);
400
+ $sql = "UPDATE " . WP_CALENDAR_TABLE . " SET event_category=1";
401
+ $wpdb->get_results($sql);
402
+ $sql = "ALTER TABLE ".WP_CALENDAR_TABLE." ADD COLUMN event_link TEXT";
403
+ $wpdb->get_results($sql);
404
+ $sql = "UPDATE " . WP_CALENDAR_TABLE . " SET event_link=''";
405
+ $wpdb->get_results($sql);
406
+ $sql = "CREATE TABLE " . WP_CALENDAR_CATEGORIES_TABLE . " (
407
+ category_id INT(11) NOT NULL AUTO_INCREMENT,
408
+ category_name VARCHAR(30) NOT NULL ,
409
+ category_colour VARCHAR(30) NOT NULL ,
410
+ PRIMARY KEY (category_id)
411
+ )";
412
+ $wpdb->get_results($sql);
413
+ $sql = "INSERT INTO " . WP_CALENDAR_CATEGORIES_TABLE . " SET category_id=0, category_name='General', category_colour='#F6F79B'";
414
+ $wpdb->get_results($sql);
415
+ }
416
+ else if ($vone_point_one_upgrade == true)
417
+ {
418
+ $sql = "ALTER TABLE ".WP_CALENDAR_TABLE." ADD COLUMN event_author BIGINT(20) UNSIGNED";
419
+ $wpdb->get_results($sql);
420
+ $sql = "UPDATE ".WP_CALENDAR_TABLE." SET event_author=".$wpdb->get_var("SELECT MIN(ID) FROM ".$wpdb->prefix."users",0,0);
421
+ $wpdb->get_results($sql);
422
+ $sql = "ALTER TABLE ".WP_CALENDAR_TABLE." MODIFY event_desc TEXT NOT NULL";
423
+ $wpdb->get_results($sql);
424
+ $sql = "CREATE TABLE " . WP_CALENDAR_CONFIG_TABLE . " (
425
+ config_item VARCHAR(30) NOT NULL ,
426
+ config_value TEXT NOT NULL ,
427
+ PRIMARY KEY (config_item)
428
+ )";
429
+ $wpdb->get_results($sql);
430
+ $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='can_manage_events', config_value='edit_posts'";
431
+ $wpdb->get_results($sql);
432
+ $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='calendar_style', config_value='".$initial_style."'";
433
+ $wpdb->get_results($sql);
434
+ $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='display_author', config_value='false'";
435
+ $wpdb->get_results($sql);
436
+ $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='display_jump', config_value='false'";
437
+ $wpdb->get_results($sql);
438
+ $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='display_todays', config_value='true'";
439
+ $wpdb->get_results($sql);
440
+ $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='display_upcoming', config_value='true'";
441
+ $wpdb->get_results($sql);
442
+ $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='display_upcoming_days', config_value=7";
443
+ $wpdb->get_results($sql);
444
+
445
+ $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='calendar_version', config_value='1.2'";
446
+ $wpdb->get_results($sql);
447
+ $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='enable_categories', config_value='false'";
448
+ $wpdb->get_results($sql);
449
+ $sql = "ALTER TABLE ".WP_CALENDAR_TABLE." ADD COLUMN event_category BIGINT(20) UNSIGNED";
450
+ $wpdb->get_results($sql);
451
+ $sql = "UPDATE " . WP_CALENDAR_TABLE . " SET event_category=1";
452
+ $wpdb->get_results($sql);
453
+ $sql = "ALTER TABLE ".WP_CALENDAR_TABLE." ADD COLUMN event_link TEXT";
454
+ $wpdb->get_results($sql);
455
+ $sql = "UPDATE " . WP_CALENDAR_TABLE . " SET event_link=''";
456
+ $wpdb->get_results($sql);
457
+ $sql = "CREATE TABLE " . WP_CALENDAR_CATEGORIES_TABLE . " (
458
+ category_id INT(11) NOT NULL AUTO_INCREMENT,
459
+ category_name VARCHAR(30) NOT NULL ,
460
+ category_colour VARCHAR(30) NOT NULL ,
461
+ PRIMARY KEY (category_id)
462
+ )";
463
+ $wpdb->get_results($sql);
464
+ $sql = "INSERT INTO " . WP_CALENDAR_CATEGORIES_TABLE . " SET category_id=0, category_name='General', category_colour='#F6F79B'";
465
+ $wpdb->get_results($sql);
466
+ }
467
+ else if ($vone_point_two_beta_upgrade == true)
468
+ {
469
+ $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='calendar_version', config_value='1.2'";
470
+ $wpdb->get_results($sql);
471
+ $sql = "INSERT INTO ".WP_CALENDAR_CONFIG_TABLE." SET config_item='enable_categories', config_value='false'";
472
+ $wpdb->get_results($sql);
473
+ $sql = "ALTER TABLE ".WP_CALENDAR_TABLE." ADD COLUMN event_category BIGINT(20) UNSIGNED";
474
+ $wpdb->get_results($sql);
475
+ $sql = "UPDATE " . WP_CALENDAR_TABLE . " SET event_category=1";
476
+ $wpdb->get_results($sql);
477
+ $sql = "ALTER TABLE ".WP_CALENDAR_TABLE." ADD COLUMN event_link TEXT";
478
+ $wpdb->get_results($sql);
479
+ $sql = "UPDATE " . WP_CALENDAR_TABLE . " SET event_link=''";
480
+ $wpdb->get_results($sql);
481
+ $sql = "CREATE TABLE " . WP_CALENDAR_CATEGORIES_TABLE . " (
482
+ category_id INT(11) NOT NULL AUTO_INCREMENT,
483
+ category_name VARCHAR(30) NOT NULL ,
484
+ category_colour VARCHAR(30) NOT NULL ,
485
+ PRIMARY KEY (category_id)
486
+ )";
487
+ $wpdb->get_results($sql);
488
+ $sql = "INSERT INTO " . WP_CALENDAR_CATEGORIES_TABLE . " SET category_id=1, category_name='General', category_colour='#F6F79B'";
489
+ $wpdb->get_results($sql);
490
+ $sql = "UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value='".$initial_style."' WHERE config_item='calendar_style'";
491
+ $wpdb->get_results($sql);
492
+ }
493
+ }
494
+
495
+ // Used on the manage events admin page to display a list of events
496
+ function wp_events_display_list()
497
+ {
498
+ global $wpdb;
499
+
500
+ $events = $wpdb->get_results("SELECT * FROM " . WP_CALENDAR_TABLE . " ORDER BY event_begin DESC");
501
+
502
+ if ( !empty($events) )
503
+ {
504
+ ?>
505
+ <table width="100%" cellpadding="3" cellspacing="3">
506
+ <tr>
507
+ <th scope="col"><?php _e('ID') ?></th>
508
+ <th scope="col"><?php _e('Title') ?></th>
509
+ <th scope="col"><?php _e('Description') ?></th>
510
+ <th scope="col"><?php _e('Start Date') ?></th>
511
+ <th scope="col"><?php _e('End Date') ?></th>
512
+ <th scope="col"><?php _e('Recurs') ?></th>
513
+ <th scope="col"><?php _e('Repeats') ?></th>
514
+ <th scope="col"><?php _e('Author') ?></th>
515
+ <th scope="col"><?php _e('Category') ?></th>
516
+ <th scope="col"><?php _e('Edit') ?></th>
517
+ <th scope="col"><?php _e('Delete') ?></th>
518
+ </tr>
519
+ <?php
520
+ $class = '';
521
+ foreach ( $events as $event )
522
+ {
523
+ $class = ($class == 'alternate') ? '' : 'alternate';
524
+ ?>
525
+ <tr class="<?php echo $class; ?>">
526
+ <th scope="row"><?php echo $event->event_id; ?></th>
527
+ <td><?php echo $event->event_title; ?></td>
528
+ <td><?php echo $event->event_desc; ?></td>
529
+ <td><?php echo $event->event_begin; ?></td>
530
+ <td><?php echo $event->event_end; ?></td>
531
+ <td>
532
+ <?php
533
+ // Interpret the DB values into something human readable
534
+ if ($event->event_recur == 'S') { echo 'Never'; }
535
+ else if ($event->event_recur == 'W') { echo 'Weekly'; }
536
+ else if ($event->event_recur == 'M') { echo 'Monthly'; }
537
+ else if ($event->event_recur == 'Y') { echo 'Yearly'; }
538
+ ?>
539
+ </td>
540
+ <td>
541
+ <?php
542
+ // Interpret the DB values into something human readable
543
+ if ($event->event_recur == 'S') { echo 'N/A'; }
544
+ else if ($event->event_repeats == 0) { echo 'Forever'; }
545
+ else if ($event->event_repeats > 0) { echo $event->event_repeats.' Times'; }
546
+ ?>
547
+ </td>
548
+ <td><?php $e = get_userdata($event->event_author); echo $e->display_name; ?></td>
549
+ <?php
550
+ $sql = "SELECT * FROM " . WP_CALENDAR_CATEGORIES_TABLE . " WHERE category_id=".$event->event_category;
551
+ $this_cat = $wpdb->get_row($sql);
552
+ ?>
553
+ <td style="background-color:<?php echo $this_cat->category_colour;?>;"><?php echo $this_cat->category_name; ?></td>
554
+ <?php unset($this_cat); ?>
555
+ <td><a href="<?php echo $_SERVER['REQUEST_URI'] ?>&amp;action=edit&amp;event_id=<?php echo $event->event_id;?>" class='edit'><?php echo __('Edit'); ?></a></td>
556
+ <td><a href="<?php echo $_SERVER['REQUEST_URI'] ?>&amp;action=delete&amp;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>
557
+ </tr>
558
+ <?php
559
+ }
560
+ ?>
561
+ </table>
562
+ <?php
563
+ }
564
+ else
565
+ {
566
+ ?>
567
+ <p><?php _e("There are no events in the database!") ?></p>
568
+ <?php
569
+ }
570
+ }
571
+
572
+
573
+ // The event edit form for the manage events admin page
574
+ function wp_events_edit_form($mode='add', $event_id=false)
575
+ {
576
+ global $wpdb;
577
+ $data = false;
578
+
579
+ if ( $event_id !== false )
580
+ {
581
+ if ( intval($event_id) != $event_id )
582
+ {
583
+ echo "<div class=\"error\"><p>Bad Monkey! No banana!</p></div>";
584
+ return;
585
+ }
586
+ else
587
+ {
588
+ $data = $wpdb->get_results("SELECT * FROM " . WP_CALENDAR_TABLE . " WHERE event_id='" . mysql_escape_string($event_id) . "' LIMIT 1");
589
+ if ( empty($data) )
590
+ {
591
+ echo "<div class=\"error\"><p>An event with that ID couldn't be found</p></div>";
592
+ return;
593
+ }
594
+ $data = $data[0];
595
+ }
596
+ }
597
+
598
+ ?>
599
+ <div id="pop_up_cal" style="position:absolute;margin-left:150px;visibility:hidden;background-color:white;layer-background-color:white;"></div>
600
+ <form name="quoteform" id="quoteform" class="wrap" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
601
+ <input type="hidden" name="action" value="<?php echo $mode; ?>">
602
+ <input type="hidden" name="event_id" value="<?php echo $event_id; ?>">
603
+
604
+ <div id="item_manager">
605
+ <div style="float: left; width: 98%; clear: both;" class="top">
606
+ <!-- List URL -->
607
+ <fieldset class="small"><legend><?php _e('Event Title'); ?></legend>
608
+ <input type="text" name="event_title" class="input" size="40" maxlength="30"
609
+ value="<?php if ( !empty($data) ) echo htmlspecialchars($data->event_title); ?>" />
610
+ </fieldset>
611
+
612
+ <fieldset class="small"><legend><?php _e('Event Description'); ?></legend>
613
+ <textarea name="event_desc" class="input" rows="5" cols="50"><?php if ( !empty($data) ) echo htmlspecialchars($data->event_desc); ?></textarea>
614
+ </fieldset>
615
+
616
+ <fieldset class="small"><legend><?php _e('Event Category'); ?></legend>
617
+ <select name="event_category">
618
+ <?php
619
+ // Grab all the categories and list them
620
+ $sql = "SELECT * FROM " . WP_CALENDAR_CATEGORIES_TABLE;
621
+ $cats = $wpdb->get_results($sql);
622
+ foreach($cats as $cat)
623
+ {
624
+ echo '<option value="'.$cat->category_id.'"';
625
+ if (!empty($data))
626
+ {
627
+ if ($data->event_category == $cat->category_id)
628
+ {
629
+ echo 'selected="selected"';
630
+ }
631
+ }
632
+ echo '>'.$cat->category_name.'</option>
633
+ ';
634
+ }
635
+ ?>
636
+ </select>
637
+ </fieldset>
638
+
639
+ <fieldset class="small"><legend><?php _e('Event Link (Optional)'); ?></legend>
640
+ <input type="text" name="event_link" class="input" size="40" value="<?php if ( !empty($data) ) echo htmlspecialchars($data->event_link); ?>" />
641
+ </fieldset>
642
+
643
+ <fieldset class="small"><legend><?php _e('Start Date'); ?></legend>
644
+ <script type="text/javascript">
645
+ var cal_begin = new CalendarPopup('pop_up_cal');
646
+ </script>
647
+ <input type="text" name="event_begin" class="input" size=12
648
+ value="<?php
649
+ if ( !empty($data) )
650
+ {
651
+ echo htmlspecialchars($data->event_begin);
652
+ }
653
+ else
654
+ {
655
+ echo date("Y-m-d");
656
+ }
657
+ ?>" /> <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>
658
+ </fieldset>
659
+
660
+ <fieldset class="small"><legend><?php _e('End Date'); ?></legend>
661
+ <script type="text/javascript">
662
+ function check_and_print() {
663
+ var cal_end = new CalendarPopup('pop_up_cal');
664
+ var newDate = new Date();
665
+ 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]);
666
+ newDate.setDate(newDate.getDate()-1);
667
+ cal_end.addDisabledDates(null, formatDate(newDate, "yyyy-MM-dd"));
668
+ cal_end.select(document.forms['quoteform'].event_end,'event_end_anchor','yyyy-MM-dd');
669
+ }
670
+ </script>
671
+ <input type="text" name="event_end" class="input" size=12
672
+ value="<?php
673
+ if ( !empty($data) )
674
+ {
675
+ echo htmlspecialchars($data->event_end);
676
+ }
677
+ else
678
+ {
679
+ echo date("Y-m-d");
680
+ }
681
+ ?>" /> <a href="#" onClick="check_and_print(); return false;" name="event_end_anchor" id="event_end_anchor">Select Date</a>
682
+ </fieldset>
683
+
684
+ <fieldset class="small"><legend><?php _e('Time (hh:mm)(optional, set blank if not required)'); ?></legend>
685
+ <input type="text" name="event_time" class="input" size=12
686
+ value="<?php
687
+ if ( !empty($data) )
688
+ {
689
+ if ($data->event_time == "00:00:00")
690
+ {
691
+ echo '';
692
+ }
693
+ else
694
+ {
695
+ echo date("H:i",strtotime(htmlspecialchars($data->event_time)));
696
+ }
697
+ }
698
+ else
699
+ {
700
+ echo date("H:i");
701
+ }
702
+ ?>" /> <?php _e('Current time difference from GMT is '); echo get_option('gmt_offset'); _e(' hour(s)'); ?>
703
+ </fieldset>
704
+
705
+ <fieldset class="small"><legend><?php _e('Recurring Events'); ?></legend>
706
+ <?php
707
+ if ($data->event_repeats != NULL)
708
+ {
709
+ $repeats = $data->event_repeats;
710
+ }
711
+ else
712
+ {
713
+ $repeats = 0;
714
+ }
715
+
716
+ if ($data->event_recur == "S")
717
+ {
718
+ $selected_s = 'selected="selected"';
719
+ }
720
+ else if ($data->event_recur == "W")
721
+ {
722
+ $selected_w = 'selected="selected"';
723
+ }
724
+ else if ($data->event_recur == "M")
725
+ {
726
+ $selected_m = 'selected="selected"';
727
+ }
728
+ else if ($data->event_recur == "Y")
729
+ {
730
+ $selected_y = 'selected="selected"';
731
+ }
732
+ ?>
733
+ Repeats for
734
+ <input type="text" name="event_repeats" class="input" size="1" value="<?php echo $repeats; ?>" />
735
+ <select name="event_recur" class="input">
736
+ <option class="input" <?php echo $selected_s; ?> value="S">None</option>
737
+ <option class="input" <?php echo $selected_w; ?> value="W">Weeks</option>
738
+ <option class="input" <?php echo $selected_m; ?> value="M">Months</option>
739
+ <option class="input" <?php echo $selected_y; ?> value="Y">Years</option>
740
+ </select><br />
741
+ Entering 0 means forever. Where the recurrance interval <br />
742
+ is left at none, the event will not reoccur.
743
+ </fieldset>
744
+ <br />
745
+ <input type="submit" name="save" class="button bold" value="Save &raquo;" />
746
+ </div>
747
+ <div style="clear:both; height:1px;">&nbsp;</div>
748
+ </div>
749
+ </form>
750
+ <?php
751
+ }
752
+
753
+ // The actual function called to render the manage events page and
754
+ // to deal with posts
755
+ function edit_calendar()
756
+ {
757
+ global $current_user, $wpdb;
758
+ ?>
759
+ <style type="text/css">
760
+ <!--
761
+ .error {
762
+ background: lightcoral;
763
+ border: 1px solid #e64f69;
764
+ margin: 1em 5% 10px;
765
+ padding: 0 1em 0 1em;
766
+ }
767
+
768
+ .center {
769
+ text-align: center;
770
+ }
771
+ .right { text-align: right;
772
+ }
773
+ .left {
774
+ text-align: left;
775
+ }
776
+ .top {
777
+ vertical-align: top;
778
+ }
779
+ .bold {
780
+ font-weight: bold;
781
+ }
782
+ .private {
783
+ color: #e64f69;
784
+ }
785
+ //-->
786
+ </style>
787
+
788
+ <?php
789
+
790
+ // First some quick cleaning up
791
+ $edit = $create = $save = $delete = false;
792
+
793
+ // Make sure we are collecting the variables we need to select years and months
794
+ $action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
795
+ $event_id = !empty($_REQUEST['event_id']) ? $_REQUEST['event_id'] : '';
796
+
797
+
798
+ // Lets see if this is first run and create us a table if it is!
799
+ check_calendar();
800
+
801
+ // Deal with adding an event to the database
802
+ if ( $action == 'add' )
803
+ {
804
+ $title = !empty($_REQUEST['event_title']) ? $_REQUEST['event_title'] : '';
805
+ $desc = !empty($_REQUEST['event_desc']) ? $_REQUEST['event_desc'] : '';
806
+ $begin = !empty($_REQUEST['event_begin']) ? $_REQUEST['event_begin'] : '';
807
+ $end = !empty($_REQUEST['event_end']) ? $_REQUEST['event_end'] : '';
808
+ $time = !empty($_REQUEST['event_time']) ? $_REQUEST['event_time'] : '';
809
+ $recur = !empty($_REQUEST['event_recur']) ? $_REQUEST['event_recur'] : '';
810
+ $repeats = !empty($_REQUEST['event_repeats']) ? $_REQUEST['event_repeats'] : '';
811
+ $category = !empty($_REQUEST['event_category']) ? $_REQUEST['event_category'] : '';
812
+ $linky = !empty($_REQUEST['event_link']) ? $_REQUEST['event_link'] : '';
813
+
814
+ // Deal with the fools who have left magic quotes turned on
815
+ if ( ini_get('magic_quotes_gpc') )
816
+ {
817
+ $title = stripslashes($title);
818
+ $desc = stripslashes($desc);
819
+ $begin = stripslashes($begin);
820
+ $end = stripslashes($end);
821
+ $time = stripslashes($time);
822
+ $recur = stripslashes($recur);
823
+ $repeats = stripslashes($repeats);
824
+ $category = stripslashes($category);
825
+ $linky = stripslashes($linky);
826
+ }
827
+
828
+ $sql = "INSERT INTO " . WP_CALENDAR_TABLE . " SET event_title='" . mysql_escape_string($title)
829
+ . "', event_desc='" . mysql_escape_string($desc) . "', event_begin='" . mysql_escape_string($begin)
830
+ . "', 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)."'";
831
+
832
+ $wpdb->get_results($sql);
833
+
834
+ $sql = "SELECT event_id FROM " . WP_CALENDAR_TABLE . " WHERE event_title='" . mysql_escape_string($title) . "'"
835
+ . " 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";
836
+ $result = $wpdb->get_results($sql);
837
+
838
+ if ( empty($result) || empty($result[0]->event_id) )
839
+ {
840
+ ?>
841
+ <div class="error"><p><strong>Error:</strong> For some bizare reason your event was not added. Why not try again?</p></div>
842
+ <?php
843
+ }
844
+ else
845
+ {
846
+ ?>
847
+ <div class="updated"><p>Event added. It will now show in your calendar.</p></div>
848
+ <?php
849
+ }
850
+ }
851
+ // Permit saving of events that have been edited
852
+ elseif ( $action == 'edit_save' )
853
+ {
854
+ $title = !empty($_REQUEST['event_title']) ? $_REQUEST['event_title'] : '';
855
+ $desc = !empty($_REQUEST['event_desc']) ? $_REQUEST['event_desc'] : '';
856
+ $begin = !empty($_REQUEST['event_begin']) ? $_REQUEST['event_begin'] : '';
857
+ $end = !empty($_REQUEST['event_end']) ? $_REQUEST['event_end'] : '';
858
+ $time = !empty($_REQUEST['event_time']) ? $_REQUEST['event_time'] : '';
859
+ $recur = !empty($_REQUEST['event_recur']) ? $_REQUEST['event_recur'] : '';
860
+ $repeats = !empty($_REQUEST['event_repeats']) ? $_REQUEST['event_repeats'] : '';
861
+ $category = !empty($_REQUEST['event_category']) ? $_REQUEST['event_category'] : '';
862
+ $linky = !empty($_REQUEST['event_link']) ? $_REQUEST['event_link'] : '';
863
+
864
+ // Deal with the fools who have left magic quotes turned on
865
+ if ( ini_get('magic_quotes_gpc') )
866
+ {
867
+ $title = stripslashes($title);
868
+ $desc = stripslashes($desc);
869
+ $begin = stripslashes($begin);
870
+ $end = stripslashes($end);
871
+ $time = stripslashes($time);
872
+ $recur = stripslashes($recur);
873
+ $repeats = stripslashes($repeats);
874
+ $category = stripslashes($category);
875
+ $linky = stripslashes($linky);
876
+ }
877
+
878
+ if ( empty($event_id) )
879
+ {
880
+ ?>
881
+ <div class="error"><p><strong>Failure:</strong> You can't update an event if you haven't submitted an event id</p></div>
882
+ <?php
883
+ }
884
+ else
885
+ {
886
+ $sql = "UPDATE " . WP_CALENDAR_TABLE . " SET event_title='" . mysql_escape_string($title)
887
+ . "', event_desc='" . mysql_escape_string($desc) . "', event_begin='" . mysql_escape_string($begin)
888
+ . "', 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) . "'";
889
+
890
+ $wpdb->get_results($sql);
891
+
892
+ $sql = "SELECT event_id FROM " . WP_CALENDAR_TABLE . " WHERE event_title='" . mysql_escape_string($title) . "'"
893
+ . " 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";
894
+ $result = $wpdb->get_results($sql);
895
+
896
+ if ( empty($result) || empty($result[0]->event_id) )
897
+ {
898
+ ?>
899
+ <div class="error"><p><strong>Failure:</strong> For some reason the event didnt update. Why not try again? </p></div>
900
+ <?php
901
+ }
902
+ else
903
+ {
904
+ ?>
905
+ <div class="updated"><p>Event updated successfully</p></div>
906
+ <?php
907
+ }
908
+ }
909
+ }
910
+ // Deal with deleting an event from the database
911
+ elseif ( $action == 'delete' )
912
+ {
913
+ if ( empty($event_id) )
914
+ {
915
+ ?>
916
+ <div class="error"><p><strong>Error:</strong> Good Lord you gave me nothing to delete, nothing I tell you!</p></div>
917
+ <?php
918
+ }
919
+ else
920
+ {
921
+ $sql = "DELETE FROM " . WP_CALENDAR_TABLE . " WHERE event_id='" . mysql_escape_string($event_id) . "'";
922
+ $wpdb->get_results($sql);
923
+
924
+ $sql = "SELECT event_id FROM " . WP_CALENDAR_TABLE . " WHERE event_id='" . mysql_escape_string($event_id) . "'";
925
+ $result = $wpdb->get_results($sql);
926
+
927
+ if ( empty($result) || empty($result[0]->event_id) )
928
+ {
929
+ ?>
930
+ <div class="updated"><p>Event deleted successfully</p></div>
931
+ <?php
932
+ }
933
+ else
934
+ {
935
+ ?>
936
+ <div class="error"><p><strong>Error:</strong> For some bizare reason the event could not be deleted. Why not try again?</p></div>
937
+ <?php
938
+
939
+ }
940
+ }
941
+ }
942
+
943
+ // Now follows a little bit of code that pulls in the main
944
+ // components of this page; the edit form and the list of events
945
+ ?>
946
+
947
+ <div class="wrap">
948
+ <?php
949
+ if ( $action == 'edit' )
950
+ {
951
+ ?>
952
+ <h2><?php _e('Edit Event'); ?></h2>
953
+ <?php
954
+ if ( empty($event_id) )
955
+ {
956
+ echo "<div class=\"error\"><p>Good lord you didn't provide an event id to edit, what were you thinking?</p></div>";
957
+ }
958
+ else
959
+ {
960
+ wp_events_edit_form('edit_save', $event_id);
961
+ }
962
+ }
963
+ else
964
+ {
965
+ ?>
966
+ <h2><?php _e('Add Event'); ?></h2>
967
+ <?php wp_events_edit_form(); ?>
968
+
969
+ <h2><?php _e('Manage Events'); ?></h2>
970
+ <?php
971
+ wp_events_display_list();
972
+ }
973
+ ?>
974
+ </div>
975
+
976
+ <?php
977
+
978
+ }
979
+
980
+ // Display the admin configuration page
981
+ function edit_calendar_config()
982
+ {
983
+ global $wpdb, $initial_style;
984
+
985
+ // We can't use this page unless Calendar is installed/upgraded
986
+ check_calendar();
987
+
988
+ if (isset($_POST['permissions']) && isset($_POST['style']))
989
+ {
990
+ if ($_POST['permissions'] == 'subscriber') { $new_perms = 'read'; }
991
+ else if ($_POST['permissions'] == 'contributor') { $new_perms = 'edit_posts'; }
992
+ else if ($_POST['permissions'] == 'author') { $new_perms = 'publish_posts'; }
993
+ else if ($_POST['permissions'] == 'editor') { $new_perms = 'moderate_comments'; }
994
+ else if ($_POST['permissions'] == 'admin') { $new_perms = 'manage_options'; }
995
+ else { $new_perms = 'manage_options'; }
996
+
997
+ $calendar_style = mysql_escape_string($_POST['style']);
998
+ $display_upcoming_days = mysql_escape_string($_POST['display_upcoming_days']);
999
+
1000
+ if (mysql_escape_string($_POST['display_author']) == 'on')
1001
+ {
1002
+ $disp_author = 'true';
1003
+ }
1004
+ else
1005
+ {
1006
+ $disp_author = 'false';
1007
+ }
1008
+
1009
+ if (mysql_escape_string($_POST['display_jump']) == 'on')
1010
+ {
1011
+ $disp_jump = 'true';
1012
+ }
1013
+ else
1014
+ {
1015
+ $disp_jump = 'false';
1016
+ }
1017
+
1018
+ if (mysql_escape_string($_POST['display_todays']) == 'on')
1019
+ {
1020
+ $disp_todays = 'true';
1021
+ }
1022
+ else
1023
+ {
1024
+ $disp_todays = 'false';
1025
+ }
1026
+
1027
+ if (mysql_escape_string($_POST['display_upcoming']) == 'on')
1028
+ {
1029
+ $disp_upcoming = 'true';
1030
+ }
1031
+ else
1032
+ {
1033
+ $disp_upcoming = 'false';
1034
+ }
1035
+
1036
+ if (mysql_escape_string($_POST['enable_categories']) == 'on')
1037
+ {
1038
+ $enable_categories = 'true';
1039
+ }
1040
+ else
1041
+ {
1042
+ $enable_categories = 'false';
1043
+ }
1044
+
1045
+ $wpdb->get_results("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '".$new_perms."' WHERE config_item='can_manage_events'");
1046
+ $wpdb->get_results("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '".$calendar_style."' WHERE config_item='calendar_style'");
1047
+ $wpdb->get_results("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '".$disp_author."' WHERE config_item='display_author'");
1048
+ $wpdb->get_results("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '".$disp_jump."' WHERE config_item='display_jump'");
1049
+ $wpdb->get_results("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '".$disp_todays."' WHERE config_item='display_todays'");
1050
+ $wpdb->get_results("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '".$disp_upcoming."' WHERE config_item='display_upcoming'");
1051
+ $wpdb->get_results("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '".$display_upcoming_days."' WHERE config_item='display_upcoming_days'");
1052
+ $wpdb->get_results("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '".$enable_categories."' WHERE config_item='enable_categories'");
1053
+
1054
+ // Check to see if we are replacing the original style
1055
+ if (mysql_escape_string($_POST['reset_styles']) == 'on')
1056
+ {
1057
+ $wpdb->get_results("UPDATE " . WP_CALENDAR_CONFIG_TABLE . " SET config_value = '".$initial_style."' WHERE config_item='calendar_style'");
1058
+ }
1059
+
1060
+ echo "<div class=\"updated\"><p><strong>Settings saved.</strong></p></div>";
1061
+ }
1062
+
1063
+ // Pull the values out of the database that we need for the form
1064
+ $configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='can_manage_events'");
1065
+ if (!empty($configs))
1066
+ {
1067
+ foreach ($configs as $config)
1068
+ {
1069
+ $allowed_group = $config->config_value;
1070
+ }
1071
+ }
1072
+
1073
+ $configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='calendar_style'");
1074
+ if (!empty($configs))
1075
+ {
1076
+ foreach ($configs as $config)
1077
+ {
1078
+ $calendar_style = $config->config_value;
1079
+ }
1080
+ }
1081
+ $configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='display_author'");
1082
+ if (!empty($configs))
1083
+ {
1084
+ foreach ($configs as $config)
1085
+ {
1086
+ if ($config->config_value == 'true')
1087
+ {
1088
+ $yes_disp_author = 'selected="selected"';
1089
+ }
1090
+ else
1091
+ {
1092
+ $no_disp_author = 'selected="selected"';
1093
+ }
1094
+ }
1095
+ }
1096
+ $configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='display_jump'");
1097
+ if (!empty($configs))
1098
+ {
1099
+ foreach ($configs as $config)
1100
+ {
1101
+ if ($config->config_value == 'true')
1102
+ {
1103
+ $yes_disp_jump = 'selected="selected"';
1104
+ }
1105
+ else
1106
+ {
1107
+ $no_disp_jump = 'selected="selected"';
1108
+ }
1109
+ }
1110
+ }
1111
+ $configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='display_todays'");
1112
+ if (!empty($configs))
1113
+ {
1114
+ foreach ($configs as $config)
1115
+ {
1116
+ if ($config->config_value == 'true')
1117
+ {
1118
+ $yes_disp_todays = 'selected="selected"';
1119
+ }
1120
+ else
1121
+ {
1122
+ $no_disp_todays = 'selected="selected"';
1123
+ }
1124
+ }
1125
+ }
1126
+ $configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='display_upcoming'");
1127
+ if (!empty($configs))
1128
+ {
1129
+ foreach ($configs as $config)
1130
+ {
1131
+ if ($config->config_value == 'true')
1132
+ {
1133
+ $yes_disp_upcoming = 'selected="selected"';
1134
+ }
1135
+ else
1136
+ {
1137
+ $no_disp_upcoming = 'selected="selected"';
1138
+ }
1139
+ }
1140
+ }
1141
+ $configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='display_upcoming_days'");
1142
+ if (!empty($configs))
1143
+ {
1144
+ foreach ($configs as $config)
1145
+ {
1146
+ $upcoming_days = $config->config_value;
1147
+ }
1148
+ }
1149
+ $configs = $wpdb->get_results("SELECT config_value FROM " . WP_CALENDAR_CONFIG_TABLE . " WHERE config_item='enable_categories'");
1150
+ if (!empty($configs))
1151
+ {
1152
+ foreach ($configs as $config)
1153
+ {
1154
+ if ($config->config_value == 'true')
1155
+ {
1156
+ $yes_enable_categories = 'selected="selected"';
1157
+ }
1158
+ else
1159
+ {
1160
+ $no_enable_categories = 'selected="selected"';
1161
+ }
1162
+ }
1163
+ }
1164
+ if ($allowed_group == 'read') { $subscriber_selected='selected="selected"';}
1165
+ else if ($allowed_group == 'edit_posts') { $contributor_selected='selected="selected"';}
1166
+ else if ($allowed_group == 'publish_posts') { $author_selected='selected="selected"';}
1167
+ else if ($allowed_group == 'moderate_comments') { $editor_selected='selected="selected"';}
1168
+ else if ($allowed_group == 'manage_options') { $admin_selected='selected="selected"';}
1169
+
1170
+ // Now we render the form
1171
+ ?>
1172
+ <style type="text/css">
1173
+ <!--
1174
+ .error {
1175
+ background: lightcoral;
1176
+ border: 1px solid #e64f69;
1177
+ margin: 1em 5% 10px;
1178
+ padding: 0 1em 0 1em;
1179
+ }
1180
+
1181
+ .center {
1182
+ text-align: center;
1183
+ }
1184
+ .right {
1185
+ text-align: right;
1186
+ }
1187
+ .left {
1188
+ text-align: left;
1189
+ }
1190
+ .top {
1191
+ vertical-align: top;
1192
+ }
1193
+ .bold {
1194
+ font-weight: bold;
1195
+ }
1196
+ .private {
1197
+ color: #e64f69;
1198
+ }
1199
+ //-->
1200
+ </style>
1201
+
1202
+ <div class="wrap">
1203
+ <h2><?php _e('Calendar Options'); ?></h2>
1204
+ <form name="quoteform" id="quoteform" class="wrap" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
1205
+ <div id="item_manager">
1206
+ <div style="float: left; width: 98%; clear: both;" class="top">
1207
+ <fieldset class="small"><legend><?php _e('Choose the lowest user group that may manage events'); ?></legend>
1208
+ <select name="permissions">
1209
+ <option value="subscriber"<?php echo $subscriber_seletced ?>><?php _e('Subscriber')?></option>
1210
+ <option value="contributor" <?php echo $contributor_selected ?>><?php _e('Contributor')?></option>
1211
+ <option value="author" <?php echo $author_selected ?>><?php _e('Author')?></option>
1212
+ <option value="editor" <?php echo $editor_selected ?>><?php _e('Editor')?></option>
1213
+ <option value="admin" <?php echo $admin_selected ?>><?php _e('Administrator')?></option>
1214
+ </select>
1215
+ </fieldset>
1216
+ <fieldset class="small"><legend><?php _e('Do you want to display the author name on events?'); ?></legend>
1217
+ <select name="display_author">
1218
+ <option value="on" <?php echo $yes_disp_author ?>><?php _e('Yes') ?></option>
1219
+ <option value="off" <?php echo $no_disp_author ?>><?php _e('No') ?></option>
1220
+ </select>
1221
+ </fieldset>
1222
+ <fieldset class="small"><legend><?php _e('Display a jumpbox for changing month and year quickly?'); ?></legend>
1223
+ <select name="display_jump">
1224
+ <option value="on" <?php echo $yes_disp_jump ?>><?php _e('Yes') ?></option>
1225
+ <option value="off" <?php echo $no_disp_jump ?>><?php _e('No') ?></option>
1226
+ </select>
1227
+ </fieldset>
1228
+ <fieldset class="small"><legend><?php _e('Display todays events?'); ?></legend>
1229
+ <select name="display_todays">
1230
+ <option value="on" <?php echo $yes_disp_todays ?>><?php _e('Yes') ?></option>
1231
+ <option value="off" <?php echo $no_disp_todays ?>><?php _e('No') ?></option>
1232
+ </select>
1233
+ </fieldset>
1234
+ <fieldset class="small"><legend><?php _e('Display upcoming events? If yes, state for how many days into the future'); ?></legend>
1235
+ <select name="display_upcoming">
1236
+ <option value="on" <?php echo $yes_disp_upcoming ?>><?php _e('Yes') ?></option>
1237
+ <option value="off" <?php echo $no_disp_upcoming ?>><?php _e('No') ?></option>
1238
+ </select>
1239
+ for <input type="text" name="display_upcoming_days" value="<?php echo $upcoming_days ?>" size="1" maxlength="2" /> days into the future
1240
+ </fieldset>
1241
+
1242
+ <fieldset class="small"><legend><?php _e('Enable event categories?'); ?></legend>
1243
+ <select name="enable_categories">
1244
+ <option value="on" <?php echo $yes_enable_categories ?>><?php _e('Yes') ?></option>
1245
+ <option value="off" <?php echo $no_enable_categories ?>><?php _e('No') ?></option>
1246
+ </select>
1247
+ </fieldset>
1248
+
1249
+ <fieldset class="small"><legend><?php _e('Configure the stylesheet for Calendar'); ?></legend>
1250
+ <textarea name="style" rows="10" cols="60" tabindex="2"><?php echo $calendar_style; ?></textarea>
1251
+ </fieldset>
1252
+ <fieldset class="small"><legend><?php _e('Reset Styles'); ?></legend>
1253
+ <input type="checkbox" name="reset_styles" /> <?php _e('Tick this box if you wish to reset the Calendar style to default'); ?>
1254
+ </fieldset>
1255
+ <br />
1256
+ <input type="submit" name="save" class="button bold" value="Save &raquo;" />
1257
+ </div>
1258
+ <div style="clear:both; height:1px;">&nbsp;</div>
1259
+ </div>
1260
+ </form>
1261
+ </div>
1262
+ <?php
1263
+
1264
+
1265
+ }
1266
+
1267
+ // Function to handle the management of categories
1268
+ function manage_categories()
1269
+ {
1270
+ global $wpdb;
1271
+
1272
+ // Calendar must be installed and upgraded before this will work
1273
+ check_calendar();
1274
+
1275
+ ?>
1276
+ <style type="text/css">
1277
+ <!--
1278
+ .error {
1279
+ background: lightcoral;
1280
+ border: 1px solid #e64f69;
1281
+ margin: 1em 5% 10px;
1282
+ padding: 0 1em 0 1em;
1283
+ }
1284
+
1285
+ .center {
1286
+ text-align: center;
1287
+ }
1288
+ .right {
1289
+ text-align: right;
1290
+ }
1291
+ .left {
1292
+ text-align: left;
1293
+ }
1294
+ .top {
1295
+ vertical-align: top;
1296
+ }
1297
+ .bold {
1298
+ font-weight: bold;
1299
+ }
1300
+ .private {
1301
+ color: #e64f69;
1302
+ }
1303
+ //-->
1304
+ </style>
1305
+ <?php
1306
+ // We do some checking to see what we're doing
1307
+ if (isset($_POST['mode']) && $_POST['mode'] == 'add')
1308
+ {
1309
+ $sql = "INSERT INTO " . WP_CALENDAR_CATEGORIES_TABLE . " SET category_name='".mysql_escape_string($_POST['category_name'])."', category_colour='".mysql_escape_string($_POST['category_colour'])."'";
1310
+ $wpdb->get_results($sql);
1311
+ echo "<div class=\"updated\"><p><strong>Category added successfully</strong></p></div>";
1312
+ }
1313
+ else if (isset($_GET['mode']) && isset($_GET['category_id']) && $_GET['mode'] == 'delete')
1314
+ {
1315
+ $sql = "DELETE FROM " . WP_CALENDAR_CATEGORIES_TABLE . " WHERE category_id=".mysql_escape_string($_GET['category_id']);
1316
+ $wpdb->get_results($sql);
1317
+ $sql = "UPDATE " . WP_CALENDAR_TABLE . " SET event_category=1 WHERE event_category=".mysql_escape_string($_GET['category_id']);
1318
+ $wpdb->get_results($sql);
1319
+ echo "<div class=\"updated\"><p><strong>Category deleted successfully</strong></p></div>";
1320
+ }
1321
+ else if (isset($_GET['mode']) && isset($_GET['category_id']) && $_GET['mode'] == 'edit' && !isset($_POST['mode']))
1322
+ {
1323
+ $sql = "SELECT * FROM " . WP_CALENDAR_CATEGORIES_TABLE . " WHERE category_id=".mysql_escape_string($_GET['category_id']);
1324
+ $cur_cat = $wpdb->get_row($sql);
1325
+ ?>
1326
+ <div class="wrap">
1327
+ <h2><?php _e('Edit Category'); ?></h2>
1328
+ <form name="catform" id="catform" class="wrap" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
1329
+ <input type="hidden" name="mode" value="edit" />
1330
+ <input type="hidden" name="category_id" value="<?php echo $cur_cat->category_id ?>" />
1331
+ <div id="item_manager">
1332
+ <div style="float: left; width: 98%; clear: both;" class="top">
1333
+ <fieldset class="small"><legend><?php _e('Category Name:'); ?></legend>
1334
+ <input type="text" name="category_name" class="input" size="30" maxlength="30" value="<?php echo $cur_cat->category_name ?>" />
1335
+ </fieldset>
1336
+ <fieldset class="small"><legend><?php _e('Category Colour (Hex format):'); ?></legend>
1337
+ <input type="text" name="category_colour" class="input" size="10" maxlength="7" value="<?php echo $cur_cat->category_colour ?>" />
1338
+ </fieldset>
1339
+ <br />
1340
+ <input type="submit" name="save" class="button bold" value="Save &raquo;" />
1341
+ </div>
1342
+ <div style="clear:both; height:1px;">&nbsp;</div>
1343
+ </div>
1344
+ </form>
1345
+ </div>
1346
+ <?php
1347
+ }
1348
+ else if (isset($_POST['mode']) && isset($_POST['category_id']) && isset($_POST['category_name']) && isset($_POST['category_colour']) && $_POST['mode'] == 'edit')
1349
+ {
1350
+ $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']);
1351
+ $wpdb->get_results($sql);
1352
+ echo "<div class=\"updated\"><p><strong>Category edited successfully</strong></p></div>";
1353
+ }
1354
+
1355
+ if ($_GET['mode'] != 'edit' || $_POST['mode'] == 'edit')
1356
+ {
1357
+ ?>
1358
+
1359
+ <div class="wrap">
1360
+ <h2><?php _e('Add Category'); ?></h2>
1361
+ <form name="catform" id="catform" class="wrap" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
1362
+ <input type="hidden" name="mode" value="add" />
1363
+ <input type="hidden" name="category_id" value="">
1364
+ <div id="item_manager">
1365
+ <div style="float: left; width: 98%; clear: both;" class="top">
1366
+ <fieldset class="small"><legend><?php _e('Category Name:'); ?></legend>
1367
+ <input type="text" name="category_name" class="input" size="30" maxlength="30" value="" />
1368
+ </fieldset>
1369
+ <fieldset class="small"><legend><?php _e('Category Colour (Hex format):'); ?></legend>
1370
+ <input type="text" name="category_colour" class="input" size="10" maxlength="7" value="" />
1371
+ </fieldset>
1372
+ <br />
1373
+ <input type="submit" name="save" class="button bold" value="Save &raquo;" />
1374
+ </div>
1375
+ <div style="clear:both; height:1px;">&nbsp;</div>
1376
+ </div>
1377
+ </form>
1378
+ <h2><?php _e('Manage Categories'); ?></h2>
1379
+ <?php
1380
+
1381
+ // We pull the categories from the database
1382
+ $categories = $wpdb->get_results("SELECT * FROM " . WP_CALENDAR_CATEGORIES_TABLE . " ORDER BY category_id ASC");
1383
+
1384
+ if ( !empty($categories) )
1385
+ {
1386
+ ?>
1387
+ <table width="50%" cellpadding="3" cellspacing="3">
1388
+ <tr>
1389
+ <th scope="col"><?php _e('ID') ?></th>
1390
+ <th scope="col"><?php _e('Category Name') ?></th>
1391
+ <th scope="col"><?php _e('Category Colour') ?></th>
1392
+ <th scope="col"><?php _e('Edit') ?></th>
1393
+ <th scope="col"><?php _e('Delete') ?></th>
1394
+ </tr>
1395
+ <?php
1396
+ $class = '';
1397
+ foreach ( $categories as $category )
1398
+ {
1399
+ $class = ($class == 'alternate') ? '' : 'alternate';
1400
+ ?>
1401
+ <tr class="<?php echo $class; ?>">
1402
+ <th scope="row"><?php echo $category->category_id; ?></th>
1403
+ <td><?php echo $category->category_name; ?></td>
1404
+ <td style="background-color:<?php echo $category->category_colour; ?>;">&nbsp;</td>
1405
+ <td><a href="<?php echo $_SERVER['REQUEST_URI'] ?>&amp;mode=edit&amp;category_id=<?php echo $category->category_id;?>" class='edit'><?php echo __('Edit'); ?></a></td>
1406
+ <?php
1407
+ if ($category->category_id == 1)
1408
+ {
1409
+ ?>
1410
+ <td>N/A</td>
1411
+ <?php
1412
+ }
1413
+ else
1414
+ {
1415
+ ?>
1416
+ <td><a href="<?php echo $_SERVER['REQUEST_URI'] ?>&amp;mode=delete&amp;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>
1417
+ <?php
1418
+ }
1419
+ ?>
1420
+ </tr>
1421
+ <?php
1422
+ }
1423
+ ?>
1424
+ </table>
1425
+ <?php
1426
+ }
1427
+ else
1428
+ {
1429
+ ?>
1430
+ <p><?php _e("There are no categories in the database - something has gone wrong!") ?></p>
1431
+ <?php
1432
+ }
1433
+
1434
+ ?>
1435
+ </div>
1436
+
1437
+ <?php
1438
+ }
1439
+ }
1440
+
1441
+ // Function to return a prefix which will allow the correct
1442
+ // placement of arguments into the query string.
1443
+ function permalink_prefix()
1444
+ {
1445
+ // Get the permalink structure from WordPress
1446
+ $p_link = get_permalink();
1447
+
1448
+ // Work out what the real URL we are viewing is
1449
+ $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
1450
+ $protocol = substr(strtolower($_SERVER["SERVER_PROTOCOL"]), 0, strpos(strtolower($_SERVER["SERVER_PROTOCOL"]), "/")).$s;
1451
+ $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
1452
+ $real_link = $protocol.'://'.$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
1453
+
1454
+ // Now use all of that to get the correctly craft the Calendar link prefix
1455
+ if (strstr($p_link, '?') && $p_link == $real_link)
1456
+ {
1457
+ $link_part = $p_link.'&';
1458
+ }
1459
+ else if ($p_link == $real_link)
1460
+ {
1461
+ $link_part = $p_link.'?';
1462
+ }
1463
+ else if (strstr($real_link, '?'))
1464
+ {
1465
+ if (isset($_GET['month']) && isset($_GET['yr']))
1466
+ {
1467
+ $new_tail = split("&", $real_link);
1468
+ foreach ($new_tail as $item)
1469
+ {
1470
+ if (!strstr($item, 'month') && !strstr($item, 'yr'))
1471
+ {
1472
+ $link_part .= $item.'&';
1473
+ }
1474
+ }
1475
+ if (!strstr($link_part, '?'))
1476
+ {
1477
+ $new_tail = split("month", $link_part);
1478
+ $link_part = $new_tail[0].'?'.$new_tail[1];
1479
+ }
1480
+ }
1481
+ else
1482
+ {
1483
+ $link_part = $real_link.'&';
1484
+ }
1485
+ }
1486
+ else
1487
+ {
1488
+ $link_part = $real_link.'?';
1489
+ }
1490
+
1491
+ return $link_part;
1492
+ }
1493
+
1494
+ // Configure the "Next" link in the calendar
1495
+ function next_link($cur_year,$cur_month)
1496
+ {
1497
+ $mod_rewrite_months = array(1=>'jan','feb','mar','apr','may','jun','jul','aug','sept','oct','nov','dec');
1498
+ $next_year = $cur_year + 1;
1499
+
1500
+ if ($cur_month == 12)
1501
+ {
1502
+ return '<a href="' . permalink_prefix() . 'month=jan&yr=' . $next_year . '">Next &raquo;</a>';
1503
+ }
1504
+ else
1505
+ {
1506
+ $next_month = $cur_month + 1;
1507
+ $month = $mod_rewrite_months[$next_month];
1508
+ return '<a href="' . permalink_prefix() . 'month='.$month.'&yr=' . $cur_year . '">Next &raquo;</a>';
1509
+ }
1510
+ }
1511
+
1512
+ // Configure the "Previous" link in the calendar
1513
+ function prev_link($cur_year,$cur_month)
1514
+ {
1515
+ $mod_rewrite_months = array(1=>'jan','feb','mar','apr','may','jun','jul','aug','sept','oct','nov','dec');
1516
+ $last_year = $cur_year - 1;
1517
+
1518
+ if ($cur_month == 1)
1519
+ {
1520
+ return '<a href="' . permalink_prefix() . 'month=dec&yr='. $last_year .'">&laquo; Prev</a>';
1521
+ }
1522
+ else
1523
+ {
1524
+ $next_month = $cur_month - 1;
1525
+ $month = $mod_rewrite_months[$next_month];
1526
+ return '<a href="' . permalink_prefix() . 'month='.$month.'&yr=' . $cur_year . '">&laquo; Prev</a>';
1527
+ }
1528
+ }
1529
+
1530
+ // Print upcoming events
1531
+ function upcoming_events()
1532
+ {
1533
+ global $wpdb;
1534
+
1535
+ // This function cannot be called unless calendar is up to date
1536
+ check_calendar();
1537
+
1538
+ // Find out if we should be displaying upcoming events
1539
+ $display = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='display_upcoming'",0,0);
1540
+
1541
+ if ($display == 'true')
1542
+ {
1543
+ // Get number of days we should go into the future
1544
+ $future_days = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='display_upcoming_days'",0,0);
1545
+ $day_count = 1;
1546
+
1547
+ while ($day_count < $future_days+1)
1548
+ {
1549
+ list($y,$m,$d) = split("-",date("Y-m-d",mktime($day_count*24,0,0,date("m"),date("d"),date("Y"))));
1550
+ $events = grab_events($y,$m,$d);
1551
+ usort($events, "time_cmp");
1552
+ if (count($events) != 0) {
1553
+ $output .= '<li>'.date(get_option('date_format'),mktime($day_count*24,0,0,date("m"),date("d"),date("Y"))).'<ul>';
1554
+ }
1555
+ foreach($events as $event)
1556
+ {
1557
+ if ($event->event_time == '00:00:00') {
1558
+ $time_string = ' all day';
1559
+ }
1560
+ else {
1561
+ $time_string = ' at '.date(get_option('time_format'), strtotime($event->event_time));
1562
+ }
1563
+ $output .= '<li>'.draw_widget_event($event).$time_string.'</li>';
1564
+ }
1565
+ if (count($events) != 0) {
1566
+ $output .= '</ul></li>';
1567
+ }
1568
+ $day_count = $day_count+1;
1569
+ }
1570
+
1571
+ if ($output != '')
1572
+ {
1573
+ $visual = '<li class="upcoming-events"><h2>Upcoming Events</h2><ul>';
1574
+ $visual .= $output;
1575
+ $visual .= '</ul></li>';
1576
+ return $visual;
1577
+ }
1578
+ }
1579
+ }
1580
+
1581
+ // Print todays events
1582
+ function todays_events()
1583
+ {
1584
+ global $wpdb;
1585
+
1586
+ // This function cannot be called unless calendar is up to date
1587
+ check_calendar();
1588
+
1589
+ // Find out if we should be displaying todays events
1590
+ $display = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='display_todays'",0,0);
1591
+
1592
+ if ($display == 'true')
1593
+ {
1594
+ $output = '<li class="todays-events"><h2>Todays Events</h2><ul>';
1595
+ $events = grab_events(date("Y"),date("m"),date("d"));
1596
+ usort($events, "time_cmp");
1597
+ foreach($events as $event)
1598
+ {
1599
+ if ($event->event_time == '00:00:00') {
1600
+ $time_string = ' all day';
1601
+ }
1602
+ else {
1603
+ $time_string = ' at '.date(get_option('time_format'), strtotime($event->event_time));
1604
+ }
1605
+ $output .= '<li>'.draw_widget_event($event).$time_string.'</li>';
1606
+ }
1607
+ $output .= '</ul></li>';
1608
+ if (count($events) != 0)
1609
+ {
1610
+ return $output;
1611
+ }
1612
+ }
1613
+ }
1614
+
1615
+ // Function to compare time in event objects
1616
+ function time_cmp($a, $b)
1617
+ {
1618
+ if ($a->event_time == $b->event_time) {
1619
+ return 0;
1620
+ }
1621
+ return ($a->event_time < $b->event_time) ? -1 : 1;
1622
+ }
1623
+
1624
+ // Used to draw multiple events
1625
+ function draw_events($events)
1626
+ {
1627
+ // We need to sort arrays of objects by time
1628
+ usort($events, "time_cmp");
1629
+
1630
+ // Now process the events
1631
+ foreach($events as $event)
1632
+ {
1633
+ $output .= draw_event($event);
1634
+ }
1635
+ return $output;
1636
+ }
1637
+
1638
+
1639
+ // The widget to show todays events in the sidebar
1640
+ function widget_init_calendar_today() {
1641
+ // Check for required functions
1642
+ if (!function_exists('register_sidebar_widget'))
1643
+ return;
1644
+
1645
+ function widget_calendar_today($args) {
1646
+ extract($args);
1647
+ ?>
1648
+ <?php echo todays_events(); ?>
1649
+ <?php
1650
+ }
1651
+
1652
+ register_sidebar_widget('Todays Events','widget_calendar_today');
1653
+ }
1654
+
1655
+ // The widget to show todays events in the sidebar
1656
+ function widget_init_calendar_upcoming() {
1657
+ // Check for required functions
1658
+ if (!function_exists('register_sidebar_widget'))
1659
+ return;
1660
+
1661
+ function widget_calendar_upcoming($args) {
1662
+ extract($args);
1663
+ ?>
1664
+ <?php echo upcoming_events(); ?>
1665
+ <?php
1666
+ }
1667
+
1668
+ register_sidebar_widget('Upcoming Events','widget_calendar_upcoming');
1669
+ }
1670
+
1671
+
1672
+ // Used to draw an event to the screen
1673
+ function draw_event($event)
1674
+ {
1675
+ global $wpdb;
1676
+
1677
+ // Calendar must be updated to run this function
1678
+ check_calendar();
1679
+
1680
+ // Before we do anything we want to know if we
1681
+ // should display the author and/or show categories.
1682
+ // We check for this later
1683
+ $display_author = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='display_author'",0,0);
1684
+ $show_cat = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='enable_categories'",0,0);
1685
+
1686
+ if ($show_cat == 'true')
1687
+ {
1688
+ $sql = "SELECT * FROM " . WP_CALENDAR_CATEGORIES_TABLE . " WHERE category_id=".$event->event_category;
1689
+ $cat_details = $wpdb->get_row($sql);
1690
+ $style = "background-color:".$cat_details->category_colour.";";
1691
+ }
1692
+
1693
+ $header_details .= '<div class="event-title">'.$event->event_title.'</div><div class="event-title-break"></div>';
1694
+ if ($event->event_time != "00:00:00")
1695
+ {
1696
+ $header_details .= '<strong>Time:</strong> ' . date(get_option('time_format'), strtotime($event->event_time)) . '<br />';
1697
+ }
1698
+ if ($display_author == 'true')
1699
+ {
1700
+ $e = get_userdata($event->event_author);
1701
+ $header_details .= '<strong>Posted by:</strong> '.$e->display_name.'<br />';
1702
+ }
1703
+ if ($display_author == 'true' || $event->event_time != "00:00:00")
1704
+ {
1705
+ $header_details .= '<div class="event-content-break"></div>';
1706
+ }
1707
+ if ($event->event_link != '') { $linky = $event->event_link; }
1708
+ else { $linky = '#'; }
1709
+
1710
+ $details = '<br />
1711
+ * <span class="calnk" nowrap="nowrap"><a href="'.$linky.'" style="'.$style.'">' . $event->event_title . '<span style="'.$style.'">' . $header_details . '' . $event->event_desc . '</span></a></span>';
1712
+
1713
+ return $details;
1714
+ }
1715
+
1716
+ // Draw an event but customise the HTML for use in the widget
1717
+ function draw_widget_event($event)
1718
+ {
1719
+ global $wpdb;
1720
+
1721
+ // Calendar must be updated to run this function
1722
+ check_calendar();
1723
+
1724
+ // Before we do anything we want to know if we
1725
+ // should display the author and/or show categories.
1726
+ // We check for this later
1727
+ $display_author = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='display_author'",0,0);
1728
+ $show_cat = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='enable_categories'",0,0);
1729
+
1730
+ if ($show_cat == 'true')
1731
+ {
1732
+ $sql = "SELECT * FROM " . WP_CALENDAR_CATEGORIES_TABLE . " WHERE category_id=".$event->event_category;
1733
+ $cat_details = $wpdb->get_row($sql);
1734
+ $style = "background-color:".$cat_details->category_colour.";";
1735
+ }
1736
+
1737
+ $header_details .= '<div class="event-title">'.$event->event_title.'</div><div class="event-title-break"></div>';
1738
+ if ($event->event_time != "00:00:00")
1739
+ {
1740
+ $header_details .= '<strong>Time:</strong> ' . date(get_option('time_format'), strtotime($event->event_time)) . '<br />';
1741
+ }
1742
+ if ($display_author == 'true')
1743
+ {
1744
+ $e = get_userdata($event->event_author);
1745
+ $header_details .= '<strong>Posted by:</strong> '.$e->display_name.'<br />';
1746
+ }
1747
+ if ($display_author == 'true' || $event->event_time != "00:00:00")
1748
+ {
1749
+ $header_details .= '<div class="event-content-break"></div>';
1750
+ }
1751
+ if ($event->event_link != '') { $linky = $event->event_link; }
1752
+ else { $linky = '#'; }
1753
+
1754
+ $details = '<span class="calnk" nowrap="nowrap"><a href="'.$linky.'">' . $event->event_title . '<span style="'.$style.'">' . $header_details . '' . $event->event_desc . '</span></a></span>';
1755
+
1756
+ return $details;
1757
+ }
1758
+
1759
+ // Grab all events for the requested date from calendar
1760
+ function grab_events($y,$m,$d)
1761
+ {
1762
+ global $wpdb;
1763
+
1764
+ $arr_events = array();
1765
+
1766
+ // Get the date format right
1767
+ $date = $y . '-' . $m . '-' . $d;
1768
+
1769
+ // Firstly we check for conventional events. These will form the first instance of a recurring event
1770
+ // or the only instance of a one-off event
1771
+ $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");
1772
+ if (!empty($events))
1773
+ {
1774
+ foreach($events as $event)
1775
+ {
1776
+ array_push($arr_events, $event);
1777
+ }
1778
+ }
1779
+
1780
+ // Even if there were results for that query, we may still have events recurring
1781
+ // from the past on this day. We now methodically check the for these events
1782
+
1783
+ /*
1784
+ The yearly code - easy because the day and month will be the same, so we return all yearly
1785
+ events that match the date part. Out of these we show those with a repeat of 0, and fast-foward
1786
+ a number of years for those with a value more than 0. Those that land in the future are displayed.
1787
+ */
1788
+
1789
+
1790
+ // Deal with forever recurring year events
1791
+ $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");
1792
+
1793
+ if (!empty($events))
1794
+ {
1795
+ foreach($events as $event)
1796
+ {
1797
+ // This is going to get complex so lets setup what we would place in for
1798
+ // an event so we can drop it in with ease
1799
+
1800
+ // Technically we don't care about the years, but we need to find out if the
1801
+ // event spans the turn of a year so we can deal with it appropriately.
1802
+ $year_begin = date('Y',strtotime($event->event_begin));
1803
+ $year_end = date('Y',strtotime($event->event_end));
1804
+
1805
+ if ($year_begin == $year_end)
1806
+ {
1807
+ if (date('m-d',strtotime($event->event_begin)) <= date('m-d',strtotime($date)) &&
1808
+ date('m-d',strtotime($event->event_end)) >= date('m-d',strtotime($date)))
1809
+ {
1810
+ array_push($arr_events, $event);
1811
+ }
1812
+ }
1813
+ else if ($year_begin < $year_end)
1814
+ {
1815
+ if (date('m-d',strtotime($event->event_begin)) <= date('m-d',strtotime($date)) ||
1816
+ date('m-d',strtotime($event->event_end)) >= date('m-d',strtotime($date)))
1817
+ {
1818
+ array_push($arr_events, $event);
1819
+ }
1820
+ }
1821
+ }
1822
+ }
1823
+
1824
+ // Now the ones that happen a finite number of times
1825
+ $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");
1826
+ if (!empty($events))
1827
+ {
1828
+ foreach($events as $event)
1829
+ {
1830
+ // This is going to get complex so lets setup what we would place in for
1831
+ // an event so we can drop it in with ease
1832
+
1833
+ // Technically we don't care about the years, but we need to find out if the
1834
+ // event spans the turn of a year so we can deal with it appropriately.
1835
+ $year_begin = date('Y',strtotime($event->event_begin));
1836
+ $year_end = date('Y',strtotime($event->event_end));
1837
+
1838
+ if ($year_begin == $year_end)
1839
+ {
1840
+ if (date('m-d',strtotime($event->event_begin)) <= date('m-d',strtotime($date)) &&
1841
+ date('m-d',strtotime($event->event_end)) >= date('m-d',strtotime($date)))
1842
+ {
1843
+ array_push($arr_events, $event);
1844
+ }
1845
+ }
1846
+ else if ($year_begin < $year_end)
1847
+ {
1848
+ if (date('m-d',strtotime($event->event_begin)) <= date('m-d',strtotime($date)) ||
1849
+ date('m-d',strtotime($event->event_end)) >= date('m-d',strtotime($date)))
1850
+ {
1851
+ array_push($arr_events, $event);
1852
+ }
1853
+ }
1854
+ }
1855
+ }
1856
+
1857
+ /*
1858
+ The monthly code - just as easy because as long as the day of the month is correct, then we
1859
+ show the event
1860
+ */
1861
+
1862
+ // The monthly events that never stop recurring
1863
+ $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");
1864
+ if (!empty($events))
1865
+ {
1866
+ foreach($events as $event)
1867
+ {
1868
+ // This is going to get complex so lets setup what we would place in for
1869
+ // an event so we can drop it in with ease
1870
+
1871
+ // Technically we don't care about the years or months, but we need to find out if the
1872
+ // event spans the turn of a year or month so we can deal with it appropriately.
1873
+ $month_begin = date('m',strtotime($event->event_begin));
1874
+ $month_end = date('m',strtotime($event->event_end));
1875
+
1876
+ if ($month_begin == $month_end)
1877
+ {
1878
+ if (date('d',strtotime($event->event_begin)) <= date('d',strtotime($date)) &&
1879
+ date('d',strtotime($event->event_end)) >= date('d',strtotime($date)))
1880
+ {
1881
+ array_push($arr_events, $event);
1882
+ }
1883
+ }
1884
+ else if ($month_begin < $month_end)
1885
+ {
1886
+ if ( ($event->event_begin <= date('Y-m-d',strtotime($date))) && (date('d',strtotime($event->event_begin)) <= date('d',strtotime($date)) ||
1887
+ date('d',strtotime($event->event_end)) >= date('d',strtotime($date))) )
1888
+ {
1889
+ array_push($arr_events, $event);
1890
+ }
1891
+ }
1892
+ }
1893
+ }
1894
+
1895
+
1896
+ // Now the ones that happen a finite number of times
1897
+ $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");
1898
+ if (!empty($events))
1899
+ {
1900
+ foreach($events as $event)
1901
+ {
1902
+ // This is going to get complex so lets setup what we would place in for
1903
+ // an event so we can drop it in with ease
1904
+
1905
+ // Technically we don't care about the years or months, but we need to find out if the
1906
+ // event spans the turn of a year or month so we can deal with it appropriately.
1907
+ $month_begin = date('m',strtotime($event->event_begin));
1908
+ $month_end = date('m',strtotime($event->event_end));
1909
+
1910
+ if ($month_begin == $month_end)
1911
+ {
1912
+ if (date('d',strtotime($event->event_begin)) <= date('d',strtotime($date)) &&
1913
+ date('d',strtotime($event->event_end)) >= date('d',strtotime($date)))
1914
+ {
1915
+ array_push($arr_events, $event);
1916
+ }
1917
+ }
1918
+ else if ($month_begin < $month_end)
1919
+ {
1920
+ if ( ($event->event_begin <= date('Y-m-d',strtotime($date))) && (date('d',strtotime($event->event_begin)) <= date('d',strtotime($date)) ||
1921
+ date('d',strtotime($event->event_end)) >= date('d',strtotime($date))) )
1922
+ {
1923
+ array_push($arr_events, $event);
1924
+ }
1925
+ }
1926
+ }
1927
+ }
1928
+
1929
+
1930
+ /*
1931
+ Weekly - well isn't this fun! We need to scan all weekly events, find what day they fell on
1932
+ and see if that matches the current day. If it does, we check to see if the repeats are 0.
1933
+ If they are, display the event, if not, we fast forward from the original day in week blocks
1934
+ until the number is exhausted. If the date we arrive at is in the future, display the event.
1935
+ */
1936
+
1937
+ // The weekly events that never stop recurring
1938
+ $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");
1939
+ if (!empty($events))
1940
+ {
1941
+ foreach($events as $event)
1942
+ {
1943
+ // This is going to get complex so lets setup what we would place in for
1944
+ // an event so we can drop it in with ease
1945
+
1946
+ // Now we are going to check to see what day the original event
1947
+ // fell on and see if the current date is both after it and on
1948
+ // the correct day. If it is, display the event!
1949
+ $day_start_event = date('D',strtotime($event->event_begin));
1950
+ $day_end_event = date('D',strtotime($event->event_end));
1951
+ $current_day = date('D',strtotime($date));
1952
+
1953
+ $plan = array();
1954
+ $plan['Mon'] = 1;
1955
+ $plan['Tue'] = 2;
1956
+ $plan['Wed'] = 3;
1957
+ $plan['Thu'] = 4;
1958
+ $plan['Fri'] = 5;
1959
+ $plan['Sat'] = 6;
1960
+ $plan['Sun'] = 7;
1961
+
1962
+ if ($plan[$day_start_event] > $plan[$day_end_event])
1963
+ {
1964
+ if (($plan[$day_start_event] <= $plan[$current_day]) || ($plan[$current_day] <= $plan[$day_end_event]))
1965
+ {
1966
+ array_push($arr_events, $event);
1967
+ }
1968
+ }
1969
+ else if (($plan[$day_start_event] < $plan[$day_end_event]) || ($plan[$day_start_event]== $plan[$day_end_event]))
1970
+ {
1971
+ if (($plan[$day_start_event] <= $plan[$current_day]) && ($plan[$current_day] <= $plan[$day_end_event]))
1972
+ {
1973
+ array_push($arr_events, $event);
1974
+ }
1975
+ }
1976
+
1977
+ }
1978
+ }
1979
+
1980
+ // The weekly events that have a limit on how many times they occur
1981
+ $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");
1982
+ if (!empty($events))
1983
+ {
1984
+ foreach($events as $event)
1985
+ {
1986
+ // This is going to get complex so lets setup what we would place in for
1987
+ // an event so we can drop it in with ease
1988
+
1989
+ // Now we are going to check to see what day the original event
1990
+ // fell on and see if the current date is both after it and on
1991
+ // the correct day. If it is, display the event!
1992
+ $day_start_event = date('D',strtotime($event->event_begin));
1993
+ $day_end_event = date('D',strtotime($event->event_end));
1994
+ $current_day = date('D',strtotime($date));
1995
+
1996
+ $plan = array();
1997
+ $plan['Mon'] = 1;
1998
+ $plan['Tue'] = 2;
1999
+ $plan['Wed'] = 3;
2000
+ $plan['Thu'] = 4;
2001
+ $plan['Fri'] = 5;
2002
+ $plan['Sat'] = 6;
2003
+ $plan['Sun'] = 7;
2004
+
2005
+ if ($plan[$day_start_event] > $plan[$day_end_event])
2006
+ {
2007
+ if (($plan[$day_start_event] <= $plan[$current_day]) || ($plan[$current_day] <= $plan[$day_end_event]))
2008
+ {
2009
+ array_push($arr_events, $event);
2010
+ }
2011
+ }
2012
+ else if (($plan[$day_start_event] < $plan[$day_end_event]) || ($plan[$day_start_event]== $plan[$day_end_event]))
2013
+ {
2014
+ if (($plan[$day_start_event] <= $plan[$current_day]) && ($plan[$current_day] <= $plan[$day_end_event]))
2015
+ {
2016
+ array_push($arr_events, $event);
2017
+ }
2018
+ }
2019
+
2020
+ }
2021
+ }
2022
+
2023
+ return $arr_events;
2024
+ }
2025
+
2026
+
2027
+ // Actually do the printing of the calendar
2028
+ // Compared to searching for and displaying events
2029
+ // this bit is really rather easy!
2030
+ function calendar()
2031
+ {
2032
+ global $wpdb;
2033
+
2034
+ // First things first, make sure calendar is up to date
2035
+ check_calendar();
2036
+
2037
+ // Deal with the week not starting on a monday
2038
+ if (get_option('start_of_week') == 0)
2039
+ {
2040
+ $name_days = array(1=>'Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
2041
+ }
2042
+ // Choose Monday if anything other than Sunday is set
2043
+ else
2044
+ {
2045
+ $name_days = array(1=>'Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');
2046
+ }
2047
+
2048
+ // Carry on with the script
2049
+ $name_months = array(1=>'January','February','March','April','May','June','July','August','September','October','November','December');
2050
+
2051
+ // If we don't pass arguments we want a calendar that is relevant to today
2052
+ if (empty($_GET['month']) || empty($_GET['yr']))
2053
+ {
2054
+ $c_year = date("Y");
2055
+ $c_month = date("m");
2056
+ $c_day = date("d");
2057
+ }
2058
+
2059
+ // Years get funny if we exceed 3000, so we use this check
2060
+ if ($_GET['yr'] <= 3000 && $_GET['yr'] >= 0)
2061
+ {
2062
+ // This is just plain nasty and all because of permalinks
2063
+ // which are no longer used, this will be cleaned up soon
2064
+ 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')
2065
+ {
2066
+
2067
+ // Again nasty code to map permalinks into something
2068
+ // databases can understand. This will be cleaned up
2069
+ $c_year = mysql_escape_string($_GET['yr']);
2070
+ if ($_GET['month'] == 'jan') { $t_month = 1; }
2071
+ else if ($_GET['month'] == 'feb') { $t_month = 2; }
2072
+ else if ($_GET['month'] == 'mar') { $t_month = 3; }
2073
+ else if ($_GET['month'] == 'apr') { $t_month = 4; }
2074
+ else if ($_GET['month'] == 'may') { $t_month = 5; }
2075
+ else if ($_GET['month'] == 'jun') { $t_month = 6; }
2076
+ else if ($_GET['month'] == 'jul') { $t_month = 7; }
2077
+ else if ($_GET['month'] == 'aug') { $t_month = 8; }
2078
+ else if ($_GET['month'] == 'sept') { $t_month = 9; }
2079
+ else if ($_GET['month'] == 'oct') { $t_month = 10; }
2080
+ else if ($_GET['month'] == 'nov') { $t_month = 11; }
2081
+ else if ($_GET['month'] == 'dec') { $t_month = 12; }
2082
+ $c_month = $t_month;
2083
+ $c_day = date("d");
2084
+ }
2085
+ // No valid month causes the calendar to default to today
2086
+ else
2087
+ {
2088
+ $c_year = date("Y");
2089
+ $c_month = date("m");
2090
+ $c_day = date("d");
2091
+ }
2092
+ }
2093
+ // No valid year causes the calendar to default to today
2094
+ else
2095
+ {
2096
+ $c_year = date("Y");
2097
+ $c_month = date("m");
2098
+ $c_day = date("d");
2099
+ }
2100
+
2101
+ // Fix the days of the week if week start is not on a monday
2102
+ if (get_option('start_of_week') == 0)
2103
+ {
2104
+ $first_weekday = date("w",mktime(0,0,0,$c_month,1,$c_year));
2105
+ $first_weekday = ($first_weekday==0?1:$first_weekday+1);
2106
+ }
2107
+ // Otherwise assume the week starts on a Monday. Anything other
2108
+ // than Sunday or Monday is just plain odd
2109
+ else
2110
+ {
2111
+ $first_weekday = date("w",mktime(0,0,0,$c_month,1,$c_year));
2112
+ $first_weekday = ($first_weekday==0?7:$first_weekday);
2113
+ }
2114
+
2115
+ $days_in_month = date("t", mktime (0,0,0,$c_month,1,$c_year));
2116
+
2117
+ // Start the table and add the header and naviagtion
2118
+ $calendar_body .= '
2119
+ <table cellspacing="1" cellpadding="0" class="calendar-table">
2120
+ ';
2121
+
2122
+ // We want to know if we should display the date switcher
2123
+ $date_switcher = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='display_jump'",0,0);
2124
+
2125
+ if ($date_switcher == 'true')
2126
+ {
2127
+ $calendar_body .= '<tr>
2128
+ <td colspan="7" class="calendar-date-switcher">
2129
+ <form method="GET" action="'.$_SERVER['REQUEST_URI'].'">
2130
+ ';
2131
+ $qsa = array();
2132
+ parse_str($_SERVER['QUERY_STRING'],$qsa);
2133
+ foreach ($qsa as $name => $argument)
2134
+ {
2135
+ if ($name != 'month' && $name != 'yr')
2136
+ {
2137
+ $calendar_body .= '<input type="hidden" name="'.$name.'" value="'.$argument.'" />
2138
+ ';
2139
+ }
2140
+ }
2141
+ function month_comparison($month)
2142
+ {
2143
+ $current_month = strtolower(date("M", time()));
2144
+ if (isset($_GET['yr']) && isset($_GET['month']))
2145
+ {
2146
+ if ($month == $_GET['month'])
2147
+ {
2148
+ return ' selected="selected"';
2149
+ }
2150
+ }
2151
+ elseif ($month == $current_month)
2152
+ {
2153
+ return ' selected="selected"';
2154
+ }
2155
+ }
2156
+ // We build the months in the switcher
2157
+ $calendar_body .= '
2158
+ Month: <select name="month" style="width:100px;">
2159
+ <option value="jan"'.month_comparison('jan').'>January</option>
2160
+ <option value="feb"'.month_comparison('feb').'>February</option>
2161
+ <option value="mar"'.month_comparison('mar').'>March</option>
2162
+ <option value="apr"'.month_comparison('apr').'>April</option>
2163
+ <option value="may"'.month_comparison('may').'>May</option>
2164
+ <option value="jun"'.month_comparison('jun').'>June</option>
2165
+ <option value="jul"'.month_comparison('jul').'>July</option>
2166
+ <option value="aug"'.month_comparison('aug').'>August</option>
2167
+ <option value="sept"'.month_comparison('sept').'>September</option>
2168
+ <option value="oct"'.month_comparison('oct').'>October</option>
2169
+ <option value="nov"'.month_comparison('nov').'>November</option>
2170
+ <option value="dec"'.month_comparison('dec').'>December</option>
2171
+ </select>
2172
+ Year: <select name="yr" style="width:60px;">
2173
+ ';
2174
+
2175
+ // The year builder is string mania. If you can make sense of this,
2176
+ // you know your PHP!
2177
+ function year_comparison($year)
2178
+ {
2179
+ $current_year = strtolower(date("Y", time()));
2180
+ if (isset($_GET['yr']) && isset($_GET['month']))
2181
+ {
2182
+ if ($year == $_GET['yr'])
2183
+ {
2184
+ return ' selected="selected"';
2185
+ }
2186
+ }
2187
+ else if ($year == $current_year)
2188
+ {
2189
+ return ' selected="selected"';
2190
+ }
2191
+ }
2192
+
2193
+ $past = 30;
2194
+ $future = 30;
2195
+ $fut = 1;
2196
+ while ($past > 0)
2197
+ {
2198
+ $p .= ' <option value="';
2199
+ $p .= date("Y",time())-$past;
2200
+ $p .= '"'.year_comparison(date("Y",time())-$past).'>';
2201
+ $p .= date("Y",time())-$past.'</option>
2202
+ ';
2203
+ $past = $past - 1;
2204
+ }
2205
+ while ($fut < $future)
2206
+ {
2207
+ $f .= ' <option value="';
2208
+ $f .= date("Y",time())+$fut;
2209
+ $f .= '"'.year_comparison(date("Y",time())+$fut).'>';
2210
+ $f .= date("Y",time())+$fut.'</option>
2211
+ ';
2212
+ $fut = $fut + 1;
2213
+ }
2214
+ $calendar_body .= $p;
2215
+ $calendar_body .= ' <option value="'.date("Y",time()).'"'.year_comparison(date("Y",time())).'>'.date("Y",time()).'</option>
2216
+ ';
2217
+ $calendar_body .= $f;
2218
+ $calendar_body .= '</select>
2219
+ <input type="submit" value="Go" />
2220
+ </form>
2221
+ </td>
2222
+ </tr>
2223
+ ';
2224
+ }
2225
+
2226
+ // The header of the calendar table and the links. Note calls to link functions
2227
+ $calendar_body .= '<tr>
2228
+ <td colspan="7" class="calendar-heading">
2229
+ <table border="0" cellpadding="0" cellspacing="0" width="100%">
2230
+ <tr>
2231
+ <td class="calendar-prev">' . prev_link($c_year,$c_month) . '</td>
2232
+ <td class="calendar-month">'.$name_months[(int)$c_month].' '.$c_year.'</td>
2233
+ <td class="calendar-next">' . next_link($c_year,$c_month) . '</td>
2234
+ </tr>
2235
+ </table>
2236
+ </td>
2237
+ </tr>
2238
+ ';
2239
+
2240
+ // Print the headings of the days of the week
2241
+ $calendar_body .= '<tr>
2242
+ ';
2243
+ for ($i=1; $i<=7; $i++)
2244
+ {
2245
+ // Colours need to be different if the starting day of the week is different
2246
+ if (get_option('start_of_week') == 0)
2247
+ {
2248
+ $calendar_body .= ' <td class="'.($i<7&&$i>1?'normal-day-heading':'weekend-heading').'">'.$name_days[$i].'</td>
2249
+ ';
2250
+ }
2251
+ else
2252
+ {
2253
+ $calendar_body .= ' <td class="'.($i<6?'normal-day-heading':'weekend-heading').'">'.$name_days[$i].'</td>
2254
+ ';
2255
+ }
2256
+ }
2257
+ $calendar_body .= '</tr>
2258
+ ';
2259
+
2260
+ for ($i=1; $i<=$days_in_month;)
2261
+ {
2262
+ $calendar_body .= '<tr>
2263
+ ';
2264
+ for ($ii=1; $ii<=7; $ii++)
2265
+ {
2266
+ if ($ii==$first_weekday && $i==1)
2267
+ {
2268
+ $go = TRUE;
2269
+ }
2270
+ elseif ($i > $days_in_month )
2271
+ {
2272
+ $go = FALSE;
2273
+ }
2274
+
2275
+ if ($go)
2276
+ {
2277
+ // Colours again, this time for the day numbers
2278
+ if (get_option('start_of_week') == 0)
2279
+ {
2280
+ // This bit of code is for styles believe it or not.
2281
+ $grabbed_events = grab_events($c_year,$c_month,$i);
2282
+ $no_events_class = '';
2283
+ if (!count($grabbed_events))
2284
+ {
2285
+ $no_events_class = ' no-events';
2286
+ }
2287
+ $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>
2288
+ ';
2289
+ }
2290
+ else
2291
+ {
2292
+ $grabbed_events = grab_events($c_year,$c_month,$i);
2293
+ $no_events_class = '';
2294
+ if (!count($grabbed_events))
2295
+ {
2296
+ $no_events_class = ' no-events';
2297
+ }
2298
+ $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>
2299
+ ';
2300
+ }
2301
+ }
2302
+ else
2303
+ {
2304
+ $calendar_body .= ' <td class="day-without-date">&nbsp;</td>
2305
+ ';
2306
+ }
2307
+ }
2308
+ $calendar_body .= '</tr>
2309
+ ';
2310
+ }
2311
+ $show_cat = $wpdb->get_var("SELECT config_value FROM ".WP_CALENDAR_CONFIG_TABLE." WHERE config_item='enable_categories'",0,0);
2312
+
2313
+ if ($show_cat == 'true')
2314
+ {
2315
+ $sql = "SELECT * FROM " . WP_CALENDAR_CATEGORIES_TABLE . " ORDER BY category_name ASC";
2316
+ $cat_details = $wpdb->get_results($sql);
2317
+ $calendar_body .= '<tr><td colspan="7">
2318
+ <table class="cat-key">
2319
+ <tr><td colspan="2"><strong>Category Key</strong></td></tr>
2320
+ ';
2321
+ foreach($cat_details as $cat_detail)
2322
+ {
2323
+ $calendar_body .= '<tr><td style="background-color:'.$cat_detail->category_colour.'; width:20px; height:20px;"></td><td>'.$cat_detail->category_name.'</td></tr>';
2324
+ }
2325
+ $calendar_body .= '</table>
2326
+ </td></tr>
2327
+ ';
2328
+ }
2329
+ $calendar_body .= '</table>
2330
+ ';
2331
+
2332
+ // A little link to yours truely. See the README if you wish to remove this
2333
+ $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>
2334
+ ';
2335
+
2336
+ // Phew! After that bit of string building, spit it all out.
2337
+ // The actual printing is done by the calling function.
2338
+ return $calendar_body;
2339
+ }
2340
+
2341
+ ?>
javascript.js ADDED
@@ -0,0 +1,1463 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // ===================================================================
2
+ // Author: Matt Kruse <matt@mattkruse.com>
3
+ // WWW: http://www.mattkruse.com/
4
+ //
5
+ // NOTICE: You may use this code for any purpose, commercial or
6
+ // private, without any further permission from the author. You may
7
+ // remove this notice from your final code if you wish, however it is
8
+ // appreciated by the author if at least my web site address is kept.
9
+ //
10
+ // You may *NOT* re-distribute this code in any way except through its
11
+ // use. That means, you can include it in your product, or your web
12
+ // site, or any other form where the code is actually being used. You
13
+ // may not put the plain javascript up on your site for download or
14
+ // include it in your javascript libraries for download.
15
+ // If you wish to share this code with others, please just point them
16
+ // to the URL instead.
17
+ // Please DO NOT link directly to my .js files from your site. Copy
18
+ // the files to your server and use them there. Thank you.
19
+ // ===================================================================
20
+
21
+
22
+ /* SOURCE FILE: AnchorPosition.js */
23
+
24
+ /*
25
+ AnchorPosition.js
26
+ Author: Matt Kruse
27
+ Last modified: 10/11/02
28
+
29
+ DESCRIPTION: These functions find the position of an <A> tag in a document,
30
+ so other elements can be positioned relative to it.
31
+
32
+ COMPATABILITY: Netscape 4.x,6.x,Mozilla, IE 5.x,6.x on Windows. Some small
33
+ positioning errors - usually with Window positioning - occur on the
34
+ Macintosh platform.
35
+
36
+ FUNCTIONS:
37
+ getAnchorPosition(anchorname)
38
+ Returns an Object() having .x and .y properties of the pixel coordinates
39
+ of the upper-left corner of the anchor. Position is relative to the PAGE.
40
+
41
+ getAnchorWindowPosition(anchorname)
42
+ Returns an Object() having .x and .y properties of the pixel coordinates
43
+ of the upper-left corner of the anchor, relative to the WHOLE SCREEN.
44
+
45
+ NOTES:
46
+
47
+ 1) For popping up separate browser windows, use getAnchorWindowPosition.
48
+ Otherwise, use getAnchorPosition
49
+
50
+ 2) Your anchor tag MUST contain both NAME and ID attributes which are the
51
+ same. For example:
52
+ <A NAME="test" ID="test"> </A>
53
+
54
+ 3) There must be at least a space between <A> </A> for IE5.5 to see the
55
+ anchor tag correctly. Do not do <A></A> with no space.
56
+ */
57
+
58
+ // getAnchorPosition(anchorname)
59
+ // This function returns an object having .x and .y properties which are the coordinates
60
+ // of the named anchor, relative to the page.
61
+ function getAnchorPosition(anchorname) {
62
+ // This function will return an Object with x and y properties
63
+ var useWindow=false;
64
+ var coordinates=new Object();
65
+ var x=0,y=0;
66
+ // Browser capability sniffing
67
+ var use_gebi=false, use_css=false, use_layers=false;
68
+ if (document.getElementById) { use_gebi=true; }
69
+ else if (document.all) { use_css=true; }
70
+ else if (document.layers) { use_layers=true; }
71
+ // Logic to find position
72
+ if (use_gebi && document.all) {
73
+ x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
74
+ y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
75
+ }
76
+ else if (use_gebi) {
77
+ var o=document.getElementById(anchorname);
78
+ x=AnchorPosition_getPageOffsetLeft(o);
79
+ y=AnchorPosition_getPageOffsetTop(o);
80
+ }
81
+ else if (use_css) {
82
+ x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
83
+ y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
84
+ }
85
+ else if (use_layers) {
86
+ var found=0;
87
+ for (var i=0; i<document.anchors.length; i++) {
88
+ if (document.anchors[i].name==anchorname) { found=1; break; }
89
+ }
90
+ if (found==0) {
91
+ coordinates.x=0; coordinates.y=0; return coordinates;
92
+ }
93
+ x=document.anchors[i].x;
94
+ y=document.anchors[i].y;
95
+ }
96
+ else {
97
+ coordinates.x=0; coordinates.y=0; return coordinates;
98
+ }
99
+ coordinates.x=x;
100
+ coordinates.y=y;
101
+ return coordinates;
102
+ }
103
+
104
+ // getAnchorWindowPosition(anchorname)
105
+ // This function returns an object having .x and .y properties which are the coordinates
106
+ // of the named anchor, relative to the window
107
+ function getAnchorWindowPosition(anchorname) {
108
+ var coordinates=getAnchorPosition(anchorname);
109
+ var x=0;
110
+ var y=0;
111
+ if (document.getElementById) {
112
+ if (isNaN(window.screenX)) {
113
+ x=coordinates.x-document.body.scrollLeft+window.screenLeft;
114
+ y=coordinates.y-document.body.scrollTop+window.screenTop;
115
+ }
116
+ else {
117
+ x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
118
+ y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
119
+ }
120
+ }
121
+ else if (document.all) {
122
+ x=coordinates.x-document.body.scrollLeft+window.screenLeft;
123
+ y=coordinates.y-document.body.scrollTop+window.screenTop;
124
+ }
125
+ else if (document.layers) {
126
+ x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
127
+ y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
128
+ }
129
+ coordinates.x=x;
130
+ coordinates.y=y;
131
+ return coordinates;
132
+ }
133
+
134
+ // Functions for IE to get position of an object
135
+ function AnchorPosition_getPageOffsetLeft (el) {
136
+ var ol=el.offsetLeft;
137
+ while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
138
+ return ol;
139
+ }
140
+ function AnchorPosition_getWindowOffsetLeft (el) {
141
+ return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
142
+ }
143
+ function AnchorPosition_getPageOffsetTop (el) {
144
+ var ot=el.offsetTop;
145
+ while((el=el.offsetParent) != null) { ot += el.offsetTop; }
146
+ return ot;
147
+ }
148
+ function AnchorPosition_getWindowOffsetTop (el) {
149
+ return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
150
+ }
151
+
152
+ /* SOURCE FILE: date.js */
153
+
154
+ // HISTORY
155
+ // ------------------------------------------------------------------
156
+ // May 17, 2003: Fixed bug in parseDate() for dates <1970
157
+ // March 11, 2003: Added parseDate() function
158
+ // March 11, 2003: Added "NNN" formatting option. Doesn't match up
159
+ // perfectly with SimpleDateFormat formats, but
160
+ // backwards-compatability was required.
161
+
162
+ // ------------------------------------------------------------------
163
+ // These functions use the same 'format' strings as the
164
+ // java.text.SimpleDateFormat class, with minor exceptions.
165
+ // The format string consists of the following abbreviations:
166
+ //
167
+ // Field | Full Form | Short Form
168
+ // -------------+--------------------+-----------------------
169
+ // Year | yyyy (4 digits) | yy (2 digits), y (2 or 4 digits)
170
+ // Month | MMM (name or abbr.)| MM (2 digits), M (1 or 2 digits)
171
+ // | NNN (abbr.) |
172
+ // Day of Month | dd (2 digits) | d (1 or 2 digits)
173
+ // Day of Week | EE (name) | E (abbr)
174
+ // Hour (1-12) | hh (2 digits) | h (1 or 2 digits)
175
+ // Hour (0-23) | HH (2 digits) | H (1 or 2 digits)
176
+ // Hour (0-11) | KK (2 digits) | K (1 or 2 digits)
177
+ // Hour (1-24) | kk (2 digits) | k (1 or 2 digits)
178
+ // Minute | mm (2 digits) | m (1 or 2 digits)
179
+ // Second | ss (2 digits) | s (1 or 2 digits)
180
+ // AM/PM | a |
181
+ //
182
+ // NOTE THE DIFFERENCE BETWEEN MM and mm! Month=MM, not mm!
183
+ // Examples:
184
+ // "MMM d, y" matches: January 01, 2000
185
+ // Dec 1, 1900
186
+ // Nov 20, 00
187
+ // "M/d/yy" matches: 01/20/00
188
+ // 9/2/00
189
+ // "MMM dd, yyyy hh:mm:ssa" matches: "January 01, 2000 12:30:45AM"
190
+ // ------------------------------------------------------------------
191
+
192
+ var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
193
+ var DAY_NAMES=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');
194
+ function LZ(x) {return(x<0||x>9?"":"0")+x}
195
+
196
+ // ------------------------------------------------------------------
197
+ // isDate ( date_string, format_string )
198
+ // Returns true if date string matches format of format string and
199
+ // is a valid date. Else returns false.
200
+ // It is recommended that you trim whitespace around the value before
201
+ // passing it to this function, as whitespace is NOT ignored!
202
+ // ------------------------------------------------------------------
203
+ function isDate(val,format) {
204
+ var date=getDateFromFormat(val,format);
205
+ if (date==0) { return false; }
206
+ return true;
207
+ }
208
+
209
+ // -------------------------------------------------------------------
210
+ // compareDates(date1,date1format,date2,date2format)
211
+ // Compare two date strings to see which is greater.
212
+ // Returns:
213
+ // 1 if date1 is greater than date2
214
+ // 0 if date2 is greater than date1 of if they are the same
215
+ // -1 if either of the dates is in an invalid format
216
+ // -------------------------------------------------------------------
217
+ function compareDates(date1,dateformat1,date2,dateformat2) {
218
+ var d1=getDateFromFormat(date1,dateformat1);
219
+ var d2=getDateFromFormat(date2,dateformat2);
220
+ if (d1==0 || d2==0) {
221
+ return -1;
222
+ }
223
+ else if (d1 > d2) {
224
+ return 1;
225
+ }
226
+ return 0;
227
+ }
228
+
229
+ // ------------------------------------------------------------------
230
+ // formatDate (date_object, format)
231
+ // Returns a date in the output format specified.
232
+ // The format string uses the same abbreviations as in getDateFromFormat()
233
+ // ------------------------------------------------------------------
234
+ function formatDate(date,format) {
235
+ format=format+"";
236
+ var result="";
237
+ var i_format=0;
238
+ var c="";
239
+ var token="";
240
+ var y=date.getYear()+"";
241
+ var M=date.getMonth()+1;
242
+ var d=date.getDate();
243
+ var E=date.getDay();
244
+ var H=date.getHours();
245
+ var m=date.getMinutes();
246
+ var s=date.getSeconds();
247
+ var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
248
+ // Convert real date parts into formatted versions
249
+ var value=new Object();
250
+ if (y.length < 4) {y=""+(y-0+1900);}
251
+ value["y"]=""+y;
252
+ value["yyyy"]=y;
253
+ value["yy"]=y.substring(2,4);
254
+ value["M"]=M;
255
+ value["MM"]=LZ(M);
256
+ value["MMM"]=MONTH_NAMES[M-1];
257
+ value["NNN"]=MONTH_NAMES[M+11];
258
+ value["d"]=d;
259
+ value["dd"]=LZ(d);
260
+ value["E"]=DAY_NAMES[E+7];
261
+ value["EE"]=DAY_NAMES[E];
262
+ value["H"]=H;
263
+ value["HH"]=LZ(H);
264
+ if (H==0){value["h"]=12;}
265
+ else if (H>12){value["h"]=H-12;}
266
+ else {value["h"]=H;}
267
+ value["hh"]=LZ(value["h"]);
268
+ if (H>11){value["K"]=H-12;} else {value["K"]=H;}
269
+ value["k"]=H+1;
270
+ value["KK"]=LZ(value["K"]);
271
+ value["kk"]=LZ(value["k"]);
272
+ if (H > 11) { value["a"]="PM"; }
273
+ else { value["a"]="AM"; }
274
+ value["m"]=m;
275
+ value["mm"]=LZ(m);
276
+ value["s"]=s;
277
+ value["ss"]=LZ(s);
278
+ while (i_format < format.length) {
279
+ c=format.charAt(i_format);
280
+ token="";
281
+ while ((format.charAt(i_format)==c) && (i_format < format.length)) {
282
+ token += format.charAt(i_format++);
283
+ }
284
+ if (value[token] != null) { result=result + value[token]; }
285
+ else { result=result + token; }
286
+ }
287
+ return result;
288
+ }
289
+
290
+ // ------------------------------------------------------------------
291
+ // Utility functions for parsing in getDateFromFormat()
292
+ // ------------------------------------------------------------------
293
+ function _isInteger(val) {
294
+ var digits="1234567890";
295
+ for (var i=0; i < val.length; i++) {
296
+ if (digits.indexOf(val.charAt(i))==-1) { return false; }
297
+ }
298
+ return true;
299
+ }
300
+ function _getInt(str,i,minlength,maxlength) {
301
+ for (var x=maxlength; x>=minlength; x--) {
302
+ var token=str.substring(i,i+x);
303
+ if (token.length < minlength) { return null; }
304
+ if (_isInteger(token)) { return token; }
305
+ }
306
+ return null;
307
+ }
308
+
309
+ // ------------------------------------------------------------------
310
+ // getDateFromFormat( date_string , format_string )
311
+ //
312
+ // This function takes a date string and a format string. It matches
313
+ // If the date string matches the format string, it returns the
314
+ // getTime() of the date. If it does not match, it returns 0.
315
+ // ------------------------------------------------------------------
316
+ function getDateFromFormat(val,format) {
317
+ val=val+"";
318
+ format=format+"";
319
+ var i_val=0;
320
+ var i_format=0;
321
+ var c="";
322
+ var token="";
323
+ var token2="";
324
+ var x,y;
325
+ var now=new Date();
326
+ var year=now.getYear();
327
+ var month=now.getMonth()+1;
328
+ var date=1;
329
+ var hh=now.getHours();
330
+ var mm=now.getMinutes();
331
+ var ss=now.getSeconds();
332
+ var ampm="";
333
+
334
+ while (i_format < format.length) {
335
+ // Get next token from format string
336
+ c=format.charAt(i_format);
337
+ token="";
338
+ while ((format.charAt(i_format)==c) && (i_format < format.length)) {
339
+ token += format.charAt(i_format++);
340
+ }
341
+ // Extract contents of value based on format token
342
+ if (token=="yyyy" || token=="yy" || token=="y") {
343
+ if (token=="yyyy") { x=4;y=4; }
344
+ if (token=="yy") { x=2;y=2; }
345
+ if (token=="y") { x=2;y=4; }
346
+ year=_getInt(val,i_val,x,y);
347
+ if (year==null) { return 0; }
348
+ i_val += year.length;
349
+ if (year.length==2) {
350
+ if (year > 70) { year=1900+(year-0); }
351
+ else { year=2000+(year-0); }
352
+ }
353
+ }
354
+ else if (token=="MMM"||token=="NNN"){
355
+ month=0;
356
+ for (var i=0; i<MONTH_NAMES.length; i++) {
357
+ var month_name=MONTH_NAMES[i];
358
+ if (val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()) {
359
+ if (token=="MMM"||(token=="NNN"&&i>11)) {
360
+ month=i+1;
361
+ if (month>12) { month -= 12; }
362
+ i_val += month_name.length;
363
+ break;
364
+ }
365
+ }
366
+ }
367
+ if ((month < 1)||(month>12)){return 0;}
368
+ }
369
+ else if (token=="EE"||token=="E"){
370
+ for (var i=0; i<DAY_NAMES.length; i++) {
371
+ var day_name=DAY_NAMES[i];
372
+ if (val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()) {
373
+ i_val += day_name.length;
374
+ break;
375
+ }
376
+ }
377
+ }
378
+ else if (token=="MM"||token=="M") {
379
+ month=_getInt(val,i_val,token.length,2);
380
+ if(month==null||(month<1)||(month>12)){return 0;}
381
+ i_val+=month.length;}
382
+ else if (token=="dd"||token=="d") {
383
+ date=_getInt(val,i_val,token.length,2);
384
+ if(date==null||(date<1)||(date>31)){return 0;}
385
+ i_val+=date.length;}
386
+ else if (token=="hh"||token=="h") {
387
+ hh=_getInt(val,i_val,token.length,2);
388
+ if(hh==null||(hh<1)||(hh>12)){return 0;}
389
+ i_val+=hh.length;}
390
+ else if (token=="HH"||token=="H") {
391
+ hh=_getInt(val,i_val,token.length,2);
392
+ if(hh==null||(hh<0)||(hh>23)){return 0;}
393
+ i_val+=hh.length;}
394
+ else if (token=="KK"||token=="K") {
395
+ hh=_getInt(val,i_val,token.length,2);
396
+ if(hh==null||(hh<0)||(hh>11)){return 0;}
397
+ i_val+=hh.length;}
398
+ else if (token=="kk"||token=="k") {
399
+ hh=_getInt(val,i_val,token.length,2);
400
+ if(hh==null||(hh<1)||(hh>24)){return 0;}
401
+ i_val+=hh.length;hh--;}
402
+ else if (token=="mm"||token=="m") {
403
+ mm=_getInt(val,i_val,token.length,2);
404
+ if(mm==null||(mm<0)||(mm>59)){return 0;}
405
+ i_val+=mm.length;}
406
+ else if (token=="ss"||token=="s") {
407
+ ss=_getInt(val,i_val,token.length,2);
408
+ if(ss==null||(ss<0)||(ss>59)){return 0;}
409
+ i_val+=ss.length;}
410
+ else if (token=="a") {
411
+ if (val.substring(i_val,i_val+2).toLowerCase()=="am") {ampm="AM";}
412
+ else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") {ampm="PM";}
413
+ else {return 0;}
414
+ i_val+=2;}
415
+ else {
416
+ if (val.substring(i_val,i_val+token.length)!=token) {return 0;}
417
+ else {i_val+=token.length;}
418
+ }
419
+ }
420
+ // If there are any trailing characters left in the value, it doesn't match
421
+ if (i_val != val.length) { return 0; }
422
+ // Is date valid for month?
423
+ if (month==2) {
424
+ // Check for leap year
425
+ if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
426
+ if (date > 29){ return 0; }
427
+ }
428
+ else { if (date > 28) { return 0; } }
429
+ }
430
+ if ((month==4)||(month==6)||(month==9)||(month==11)) {
431
+ if (date > 30) { return 0; }
432
+ }
433
+ // Correct hours value
434
+ if (hh<12 && ampm=="PM") { hh=hh-0+12; }
435
+ else if (hh>11 && ampm=="AM") { hh-=12; }
436
+ var newdate=new Date(year,month-1,date,hh,mm,ss);
437
+ return newdate.getTime();
438
+ }
439
+
440
+ // ------------------------------------------------------------------
441
+ // parseDate( date_string [, prefer_euro_format] )
442
+ //
443
+ // This function takes a date string and tries to match it to a
444
+ // number of possible date formats to get the value. It will try to
445
+ // match against the following international formats, in this order:
446
+ // y-M-d MMM d, y MMM d,y y-MMM-d d-MMM-y MMM d
447
+ // M/d/y M-d-y M.d.y MMM-d M/d M-d
448
+ // d/M/y d-M-y d.M.y d-MMM d/M d-M
449
+ // A second argument may be passed to instruct the method to search
450
+ // for formats like d/M/y (european format) before M/d/y (American).
451
+ // Returns a Date object or null if no patterns match.
452
+ // ------------------------------------------------------------------
453
+ function parseDate(val) {
454
+ var preferEuro=(arguments.length==2)?arguments[1]:false;
455
+ generalFormats=new Array('y-M-d','MMM d, y','MMM d,y','y-MMM-d','d-MMM-y','MMM d');
456
+ monthFirst=new Array('M/d/y','M-d-y','M.d.y','MMM-d','M/d','M-d');
457
+ dateFirst =new Array('d/M/y','d-M-y','d.M.y','d-MMM','d/M','d-M');
458
+ var checkList=new Array('generalFormats',preferEuro?'dateFirst':'monthFirst',preferEuro?'monthFirst':'dateFirst');
459
+ var d=null;
460
+ for (var i=0; i<checkList.length; i++) {
461
+ var l=window[checkList[i]];
462
+ for (var j=0; j<l.length; j++) {
463
+ d=getDateFromFormat(val,l[j]);
464
+ if (d!=0) { return new Date(d); }
465
+ }
466
+ }
467
+ return null;
468
+ }
469
+
470
+ /* SOURCE FILE: PopupWindow.js */
471
+
472
+ /*
473
+ PopupWindow.js
474
+ Author: Matt Kruse
475
+ Last modified: 02/16/04
476
+
477
+ DESCRIPTION: This object allows you to easily and quickly popup a window
478
+ in a certain place. The window can either be a DIV or a separate browser
479
+ window.
480
+
481
+ COMPATABILITY: Works with Netscape 4.x, 6.x, IE 5.x on Windows. Some small
482
+ positioning errors - usually with Window positioning - occur on the
483
+ Macintosh platform. Due to bugs in Netscape 4.x, populating the popup
484
+ window with <STYLE> tags may cause errors.
485
+
486
+ USAGE:
487
+ // Create an object for a WINDOW popup
488
+ var win = new PopupWindow();
489
+
490
+ // Create an object for a DIV window using the DIV named 'mydiv'
491
+ var win = new PopupWindow('mydiv');
492
+
493
+ // Set the window to automatically hide itself when the user clicks
494
+ // anywhere else on the page except the popup
495
+ win.autoHide();
496
+
497
+ // Show the window relative to the anchor name passed in
498
+ win.showPopup(anchorname);
499
+
500
+ // Hide the popup
501
+ win.hidePopup();
502
+
503
+ // Set the size of the popup window (only applies to WINDOW popups
504
+ win.setSize(width,height);
505
+
506
+ // Populate the contents of the popup window that will be shown. If you
507
+ // change the contents while it is displayed, you will need to refresh()
508
+ win.populate(string);
509
+
510
+ // set the URL of the window, rather than populating its contents
511
+ // manually
512
+ win.setUrl("http://www.site.com/");
513
+
514
+ // Refresh the contents of the popup
515
+ win.refresh();
516
+
517
+ // Specify how many pixels to the right of the anchor the popup will appear
518
+ win.offsetX = 50;
519
+
520
+ // Specify how many pixels below the anchor the popup will appear
521
+ win.offsetY = 100;
522
+
523
+ NOTES:
524
+ 1) Requires the functions in AnchorPosition.js
525
+
526
+ 2) Your anchor tag MUST contain both NAME and ID attributes which are the
527
+ same. For example:
528
+ <A NAME="test" ID="test"> </A>
529
+
530
+ 3) There must be at least a space between <A> </A> for IE5.5 to see the
531
+ anchor tag correctly. Do not do <A></A> with no space.
532
+
533
+ 4) When a PopupWindow object is created, a handler for 'onmouseup' is
534
+ attached to any event handler you may have already defined. Do NOT define
535
+ an event handler for 'onmouseup' after you define a PopupWindow object or
536
+ the autoHide() will not work correctly.
537
+ */
538
+
539
+ // Set the position of the popup window based on the anchor
540
+ function PopupWindow_getXYPosition(anchorname) {
541
+ var coordinates;
542
+ if (this.type == "WINDOW") {
543
+ coordinates = getAnchorWindowPosition(anchorname);
544
+ }
545
+ else {
546
+ coordinates = getAnchorPosition(anchorname);
547
+ }
548
+ this.x = coordinates.x;
549
+ this.y = coordinates.y;
550
+ }
551
+ // Set width/height of DIV/popup window
552
+ function PopupWindow_setSize(width,height) {
553
+ this.width = width;
554
+ this.height = height;
555
+ }
556
+ // Fill the window with contents
557
+ function PopupWindow_populate(contents) {
558
+ this.contents = contents;
559
+ this.populated = false;
560
+ }
561
+ // Set the URL to go to
562
+ function PopupWindow_setUrl(url) {
563
+ this.url = url;
564
+ }
565
+ // Set the window popup properties
566
+ function PopupWindow_setWindowProperties(props) {
567
+ this.windowProperties = props;
568
+ }
569
+ // Refresh the displayed contents of the popup
570
+ function PopupWindow_refresh() {
571
+ if (this.divName != null) {
572
+ // refresh the DIV object
573
+ if (this.use_gebi) {
574
+ document.getElementById(this.divName).innerHTML = this.contents;
575
+ }
576
+ else if (this.use_css) {
577
+ document.all[this.divName].innerHTML = this.contents;
578
+ }
579
+ else if (this.use_layers) {
580
+ var d = document.layers[this.divName];
581
+ d.document.open();
582
+ d.document.writeln(this.contents);
583
+ d.document.close();
584
+ }
585
+ }
586
+ else {
587
+ if (this.popupWindow != null && !this.popupWindow.closed) {
588
+ if (this.url!="") {
589
+ this.popupWindow.location.href=this.url;
590
+ }
591
+ else {
592
+ this.popupWindow.document.open();
593
+ this.popupWindow.document.writeln(this.contents);
594
+ this.popupWindow.document.close();
595
+ }
596
+ this.popupWindow.focus();
597
+ }
598
+ }
599
+ }
600
+ // Position and show the popup, relative to an anchor object
601
+ function PopupWindow_showPopup(anchorname) {
602
+ this.getXYPosition(anchorname);
603
+ this.x += this.offsetX;
604
+ this.y += this.offsetY;
605
+ if (!this.populated && (this.contents != "")) {
606
+ this.populated = true;
607
+ this.refresh();
608
+ }
609
+ if (this.divName != null) {
610
+ // Show the DIV object
611
+ if (this.use_gebi) {
612
+ document.getElementById(this.divName).style.left = this.x + "px";
613
+ document.getElementById(this.divName).style.top = this.y + "px";
614
+ document.getElementById(this.divName).style.visibility = "visible";
615
+ }
616
+ else if (this.use_css) {
617
+ document.all[this.divName].style.left = this.x;
618
+ document.all[this.divName].style.top = this.y;
619
+ document.all[this.divName].style.visibility = "visible";
620
+ }
621
+ else if (this.use_layers) {
622
+ document.layers[this.divName].left = this.x;
623
+ document.layers[this.divName].top = this.y;
624
+ document.layers[this.divName].visibility = "visible";
625
+ }
626
+ }
627
+ else {
628
+ if (this.popupWindow == null || this.popupWindow.closed) {
629
+ // If the popup window will go off-screen, move it so it doesn't
630
+ if (this.x<0) { this.x=0; }
631
+ if (this.y<0) { this.y=0; }
632
+ if (screen && screen.availHeight) {
633
+ if ((this.y + this.height) > screen.availHeight) {
634
+ this.y = screen.availHeight - this.height;
635
+ }
636
+ }
637
+ if (screen && screen.availWidth) {
638
+ if ((this.x + this.width) > screen.availWidth) {
639
+ this.x = screen.availWidth - this.width;
640
+ }
641
+ }
642
+ var avoidAboutBlank = window.opera || ( document.layers && !navigator.mimeTypes['*'] ) || navigator.vendor == 'KDE' || ( document.childNodes && !document.all && !navigator.taintEnabled );
643
+ this.popupWindow = window.open(avoidAboutBlank?"":"about:blank","window_"+anchorname,this.windowProperties+",width="+this.width+",height="+this.height+",screenX="+this.x+",left="+this.x+",screenY="+this.y+",top="+this.y+"");
644
+ }
645
+ this.refresh();
646
+ }
647
+ }
648
+ // Hide the popup
649
+ function PopupWindow_hidePopup() {
650
+ if (this.divName != null) {
651
+ if (this.use_gebi) {
652
+ document.getElementById(this.divName).style.visibility = "hidden";
653
+ }
654
+ else if (this.use_css) {
655
+ document.all[this.divName].style.visibility = "hidden";
656
+ }
657
+ else if (this.use_layers) {
658
+ document.layers[this.divName].visibility = "hidden";
659
+ }
660
+ }
661
+ else {
662
+ if (this.popupWindow && !this.popupWindow.closed) {
663
+ this.popupWindow.close();
664
+ this.popupWindow = null;
665
+ }
666
+ }
667
+ }
668
+ // Pass an event and return whether or not it was the popup DIV that was clicked
669
+ function PopupWindow_isClicked(e) {
670
+ if (this.divName != null) {
671
+ if (this.use_layers) {
672
+ var clickX = e.pageX;
673
+ var clickY = e.pageY;
674
+ var t = document.layers[this.divName];
675
+ if ((clickX > t.left) && (clickX < t.left+t.clip.width) && (clickY > t.top) && (clickY < t.top+t.clip.height)) {
676
+ return true;
677
+ }
678
+ else { return false; }
679
+ }
680
+ else if (document.all) { // Need to hard-code this to trap IE for error-handling
681
+ var t = window.event.srcElement;
682
+ while (t.parentElement != null) {
683
+ if (t.id==this.divName) {
684
+ return true;
685
+ }
686
+ t = t.parentElement;
687
+ }
688
+ return false;
689
+ }
690
+ else if (this.use_gebi && e) {
691
+ var t = e.originalTarget;
692
+ while (t.parentNode != null) {
693
+ if (t.id==this.divName) {
694
+ return true;
695
+ }
696
+ t = t.parentNode;
697
+ }
698
+ return false;
699
+ }
700
+ return false;
701
+ }
702
+ return false;
703
+ }
704
+
705
+ // Check an onMouseDown event to see if we should hide
706
+ function PopupWindow_hideIfNotClicked(e) {
707
+ if (this.autoHideEnabled && !this.isClicked(e)) {
708
+ this.hidePopup();
709
+ }
710
+ }
711
+ // Call this to make the DIV disable automatically when mouse is clicked outside it
712
+ function PopupWindow_autoHide() {
713
+ this.autoHideEnabled = true;
714
+ }
715
+ // This global function checks all PopupWindow objects onmouseup to see if they should be hidden
716
+ function PopupWindow_hidePopupWindows(e) {
717
+ for (var i=0; i<popupWindowObjects.length; i++) {
718
+ if (popupWindowObjects[i] != null) {
719
+ var p = popupWindowObjects[i];
720
+ p.hideIfNotClicked(e);
721
+ }
722
+ }
723
+ }
724
+ // Run this immediately to attach the event listener
725
+ function PopupWindow_attachListener() {
726
+ if (document.layers) {
727
+ document.captureEvents(Event.MOUSEUP);
728
+ }
729
+ window.popupWindowOldEventListener = document.onmouseup;
730
+ if (window.popupWindowOldEventListener != null) {
731
+ document.onmouseup = new Function("window.popupWindowOldEventListener(); PopupWindow_hidePopupWindows();");
732
+ }
733
+ else {
734
+ document.onmouseup = PopupWindow_hidePopupWindows;
735
+ }
736
+ }
737
+ // CONSTRUCTOR for the PopupWindow object
738
+ // Pass it a DIV name to use a DHTML popup, otherwise will default to window popup
739
+ function PopupWindow() {
740
+ if (!window.popupWindowIndex) { window.popupWindowIndex = 0; }
741
+ if (!window.popupWindowObjects) { window.popupWindowObjects = new Array(); }
742
+ if (!window.listenerAttached) {
743
+ window.listenerAttached = true;
744
+ PopupWindow_attachListener();
745
+ }
746
+ this.index = popupWindowIndex++;
747
+ popupWindowObjects[this.index] = this;
748
+ this.divName = null;
749
+ this.popupWindow = null;
750
+ this.width=0;
751
+ this.height=0;
752
+ this.populated = false;
753
+ this.visible = false;
754
+ this.autoHideEnabled = false;
755
+
756
+ this.contents = "";
757
+ this.url="";
758
+ this.windowProperties="toolbar=no,location=no,status=no,menubar=no,scrollbars=auto,resizable,alwaysRaised,dependent,titlebar=no";
759
+ if (arguments.length>0) {
760
+ this.type="DIV";
761
+ this.divName = arguments[0];
762
+ }
763
+ else {
764
+ this.type="WINDOW";
765
+ }
766
+ this.use_gebi = false;
767
+ this.use_css = false;
768
+ this.use_layers = false;
769
+ if (document.getElementById) { this.use_gebi = true; }
770
+ else if (document.all) { this.use_css = true; }
771
+ else if (document.layers) { this.use_layers = true; }
772
+ else { this.type = "WINDOW"; }
773
+ this.offsetX = 0;
774
+ this.offsetY = 0;
775
+ // Method mappings
776
+ this.getXYPosition = PopupWindow_getXYPosition;
777
+ this.populate = PopupWindow_populate;
778
+ this.setUrl = PopupWindow_setUrl;
779
+ this.setWindowProperties = PopupWindow_setWindowProperties;
780
+ this.refresh = PopupWindow_refresh;
781
+ this.showPopup = PopupWindow_showPopup;
782
+ this.hidePopup = PopupWindow_hidePopup;
783
+ this.setSize = PopupWindow_setSize;
784
+ this.isClicked = PopupWindow_isClicked;
785
+ this.autoHide = PopupWindow_autoHide;
786
+ this.hideIfNotClicked = PopupWindow_hideIfNotClicked;
787
+ }
788
+
789
+ /* SOURCE FILE: CalendarPopup.js */
790
+
791
+ // HISTORY
792
+ // ------------------------------------------------------------------
793
+ // Feb 7, 2005: Fixed a CSS styles to use px unit
794
+ // March 29, 2004: Added check in select() method for the form field
795
+ // being disabled. If it is, just return and don't do anything.
796
+ // March 24, 2004: Fixed bug - when month name and abbreviations were
797
+ // changed, date format still used original values.
798
+ // January 26, 2004: Added support for drop-down month and year
799
+ // navigation (Thanks to Chris Reid for the idea)
800
+ // September 22, 2003: Fixed a minor problem in YEAR calendar with
801
+ // CSS prefix.
802
+ // August 19, 2003: Renamed the function to get styles, and made it
803
+ // work correctly without an object reference
804
+ // August 18, 2003: Changed showYearNavigation and
805
+ // showYearNavigationInput to optionally take an argument of
806
+ // true or false
807
+ // July 31, 2003: Added text input option for year navigation.
808
+ // Added a per-calendar CSS prefix option to optionally use
809
+ // different styles for different calendars.
810
+ // July 29, 2003: Fixed bug causing the Today link to be clickable
811
+ // even though today falls in a disabled date range.
812
+ // Changed formatting to use pure CSS, allowing greater control
813
+ // over look-and-feel options.
814
+ // June 11, 2003: Fixed bug causing the Today link to be unselectable
815
+ // under certain cases when some days of week are disabled
816
+ // March 14, 2003: Added ability to disable individual dates or date
817
+ // ranges, display as light gray and strike-through
818
+ // March 14, 2003: Removed dependency on graypixel.gif and instead
819
+ /// use table border coloring
820
+ // March 12, 2003: Modified showCalendar() function to allow optional
821
+ // start-date parameter
822
+ // March 11, 2003: Modified select() function to allow optional
823
+ // start-date parameter
824
+ /*
825
+ DESCRIPTION: This object implements a popup calendar to allow the user to
826
+ select a date, month, quarter, or year.
827
+
828
+ COMPATABILITY: Works with Netscape 4.x, 6.x, IE 5.x on Windows. Some small
829
+ positioning errors - usually with Window positioning - occur on the
830
+ Macintosh platform.
831
+ The calendar can be modified to work for any location in the world by
832
+ changing which weekday is displayed as the first column, changing the month
833
+ names, and changing the column headers for each day.
834
+
835
+ USAGE:
836
+ // Create a new CalendarPopup object of type WINDOW
837
+ var cal = new CalendarPopup();
838
+
839
+ // Create a new CalendarPopup object of type DIV using the DIV named 'mydiv'
840
+ var cal = new CalendarPopup('mydiv');
841
+
842
+ // Easy method to link the popup calendar with an input box.
843
+ cal.select(inputObject, anchorname, dateFormat);
844
+ // Same method, but passing a default date other than the field's current value
845
+ cal.select(inputObject, anchorname, dateFormat, '01/02/2000');
846
+ // This is an example call to the popup calendar from a link to populate an
847
+ // input box. Note that to use this, date.js must also be included!!
848
+ <A HREF="#" onClick="cal.select(document.forms[0].date,'anchorname','MM/dd/yyyy'); return false;">Select</A>
849
+
850
+ // Set the type of date select to be used. By default it is 'date'.
851
+ cal.setDisplayType(type);
852
+
853
+ // When a date, month, quarter, or year is clicked, a function is called and
854
+ // passed the details. You must write this function, and tell the calendar
855
+ // popup what the function name is.
856
+ // Function to be called for 'date' select receives y, m, d
857
+ cal.setReturnFunction(functionname);
858
+ // Function to be called for 'month' select receives y, m
859
+ cal.setReturnMonthFunction(functionname);
860
+ // Function to be called for 'quarter' select receives y, q
861
+ cal.setReturnQuarterFunction(functionname);
862
+ // Function to be called for 'year' select receives y
863
+ cal.setReturnYearFunction(functionname);
864
+
865
+ // Show the calendar relative to a given anchor
866
+ cal.showCalendar(anchorname);
867
+
868
+ // Hide the calendar. The calendar is set to autoHide automatically
869
+ cal.hideCalendar();
870
+
871
+ // Set the month names to be used. Default are English month names
872
+ cal.setMonthNames("January","February","March",...);
873
+
874
+ // Set the month abbreviations to be used. Default are English month abbreviations
875
+ cal.setMonthAbbreviations("Jan","Feb","Mar",...);
876
+
877
+ // Show navigation for changing by the year, not just one month at a time
878
+ cal.showYearNavigation();
879
+
880
+ // Show month and year dropdowns, for quicker selection of month of dates
881
+ cal.showNavigationDropdowns();
882
+
883
+ // Set the text to be used above each day column. The days start with
884
+ // sunday regardless of the value of WeekStartDay
885
+ cal.setDayHeaders("S","M","T",...);
886
+
887
+ // Set the day for the first column in the calendar grid. By default this
888
+ // is Sunday (0) but it may be changed to fit the conventions of other
889
+ // countries.
890
+ cal.setWeekStartDay(1); // week is Monday - Sunday
891
+
892
+ // Set the weekdays which should be disabled in the 'date' select popup. You can
893
+ // then allow someone to only select week end dates, or Tuedays, for example
894
+ cal.setDisabledWeekDays(0,1); // To disable selecting the 1st or 2nd days of the week
895
+
896
+ // Selectively disable individual days or date ranges. Disabled days will not
897
+ // be clickable, and show as strike-through text on current browsers.
898
+ // Date format is any format recognized by parseDate() in date.js
899
+ // Pass a single date to disable:
900
+ cal.addDisabledDates("2003-01-01");
901
+ // Pass null as the first parameter to mean "anything up to and including" the
902
+ // passed date:
903
+ cal.addDisabledDates(null, "01/02/03");
904
+ // Pass null as the second parameter to mean "including the passed date and
905
+ // anything after it:
906
+ cal.addDisabledDates("Jan 01, 2003", null);
907
+ // Pass two dates to disable all dates inbetween and including the two
908
+ cal.addDisabledDates("January 01, 2003", "Dec 31, 2003");
909
+
910
+ // When the 'year' select is displayed, set the number of years back from the
911
+ // current year to start listing years. Default is 2.
912
+ // This is also used for year drop-down, to decide how many years +/- to display
913
+ cal.setYearSelectStartOffset(2);
914
+
915
+ // Text for the word "Today" appearing on the calendar
916
+ cal.setTodayText("Today");
917
+
918
+ // The calendar uses CSS classes for formatting. If you want your calendar to
919
+ // have unique styles, you can set the prefix that will be added to all the
920
+ // classes in the output.
921
+ // For example, normal output may have this:
922
+ // <SPAN CLASS="cpTodayTextDisabled">Today<SPAN>
923
+ // But if you set the prefix like this:
924
+ cal.setCssPrefix("Test");
925
+ // The output will then look like:
926
+ // <SPAN CLASS="TestcpTodayTextDisabled">Today<SPAN>
927
+ // And you can define that style somewhere in your page.
928
+
929
+ // When using Year navigation, you can make the year be an input box, so
930
+ // the user can manually change it and jump to any year
931
+ cal.showYearNavigationInput();
932
+
933
+ // Set the calendar offset to be different than the default. By default it
934
+ // will appear just below and to the right of the anchorname. So if you have
935
+ // a text box where the date will go and and anchor immediately after the
936
+ // text box, the calendar will display immediately under the text box.
937
+ cal.offsetX = 20;
938
+ cal.offsetY = 20;
939
+
940
+ NOTES:
941
+ 1) Requires the functions in AnchorPosition.js and PopupWindow.js
942
+
943
+ 2) Your anchor tag MUST contain both NAME and ID attributes which are the
944
+ same. For example:
945
+ <A NAME="test" ID="test"> </A>
946
+
947
+ 3) There must be at least a space between <A> </A> for IE5.5 to see the
948
+ anchor tag correctly. Do not do <A></A> with no space.
949
+
950
+ 4) When a CalendarPopup object is created, a handler for 'onmouseup' is
951
+ attached to any event handler you may have already defined. Do NOT define
952
+ an event handler for 'onmouseup' after you define a CalendarPopup object
953
+ or the autoHide() will not work correctly.
954
+
955
+ 5) The calendar popup display uses style sheets to make it look nice.
956
+
957
+ */
958
+
959
+ // CONSTRUCTOR for the CalendarPopup Object
960
+ function CalendarPopup() {
961
+ var c;
962
+ if (arguments.length>0) {
963
+ c = new PopupWindow(arguments[0]);
964
+ }
965
+ else {
966
+ c = new PopupWindow();
967
+ c.setSize(150,175);
968
+ }
969
+ c.offsetX = -152;
970
+ c.offsetY = 25;
971
+ c.autoHide();
972
+ // Calendar-specific properties
973
+ c.monthNames = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
974
+ c.monthAbbreviations = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
975
+ c.dayHeaders = new Array("S","M","T","W","T","F","S");
976
+ c.returnFunction = "CP_tmpReturnFunction";
977
+ c.returnMonthFunction = "CP_tmpReturnMonthFunction";
978
+ c.returnQuarterFunction = "CP_tmpReturnQuarterFunction";
979
+ c.returnYearFunction = "CP_tmpReturnYearFunction";
980
+ c.weekStartDay = 0;
981
+ c.isShowYearNavigation = false;
982
+ c.displayType = "date";
983
+ c.disabledWeekDays = new Object();
984
+ c.disabledDatesExpression = "";
985
+ c.yearSelectStartOffset = 2;
986
+ c.currentDate = null;
987
+ c.todayText="Today";
988
+ c.cssPrefix="";
989
+ c.isShowNavigationDropdowns=false;
990
+ c.isShowYearNavigationInput=false;
991
+ window.CP_calendarObject = null;
992
+ window.CP_targetInput = null;
993
+ window.CP_dateFormat = "MM/dd/yyyy";
994
+ // Method mappings
995
+ c.copyMonthNamesToWindow = CP_copyMonthNamesToWindow;
996
+ c.setReturnFunction = CP_setReturnFunction;
997
+ c.setReturnMonthFunction = CP_setReturnMonthFunction;
998
+ c.setReturnQuarterFunction = CP_setReturnQuarterFunction;
999
+ c.setReturnYearFunction = CP_setReturnYearFunction;
1000
+ c.setMonthNames = CP_setMonthNames;
1001
+ c.setMonthAbbreviations = CP_setMonthAbbreviations;
1002
+ c.setDayHeaders = CP_setDayHeaders;
1003
+ c.setWeekStartDay = CP_setWeekStartDay;
1004
+ c.setDisplayType = CP_setDisplayType;
1005
+ c.setDisabledWeekDays = CP_setDisabledWeekDays;
1006
+ c.addDisabledDates = CP_addDisabledDates;
1007
+ c.setYearSelectStartOffset = CP_setYearSelectStartOffset;
1008
+ c.setTodayText = CP_setTodayText;
1009
+ c.showYearNavigation = CP_showYearNavigation;
1010
+ c.showCalendar = CP_showCalendar;
1011
+ c.hideCalendar = CP_hideCalendar;
1012
+ c.getStyles = getCalendarStyles;
1013
+ c.refreshCalendar = CP_refreshCalendar;
1014
+ c.getCalendar = CP_getCalendar;
1015
+ c.select = CP_select;
1016
+ c.setCssPrefix = CP_setCssPrefix;
1017
+ c.showNavigationDropdowns = CP_showNavigationDropdowns;
1018
+ c.showYearNavigationInput = CP_showYearNavigationInput;
1019
+ c.copyMonthNamesToWindow();
1020
+ // Return the object
1021
+ return c;
1022
+ }
1023
+ function CP_copyMonthNamesToWindow() {
1024
+ // Copy these values over to the date.js
1025
+ if (typeof(window.MONTH_NAMES)!="undefined" && window.MONTH_NAMES!=null) {
1026
+ window.MONTH_NAMES = new Array();
1027
+ for (var i=0; i<this.monthNames.length; i++) {
1028
+ window.MONTH_NAMES[window.MONTH_NAMES.length] = this.monthNames[i];
1029
+ }
1030
+ for (var i=0; i<this.monthAbbreviations.length; i++) {
1031
+ window.MONTH_NAMES[window.MONTH_NAMES.length] = this.monthAbbreviations[i];
1032
+ }
1033
+ }
1034
+ }
1035
+ // Temporary default functions to be called when items clicked, so no error is thrown
1036
+ function CP_tmpReturnFunction(y,m,d) {
1037
+ if (window.CP_targetInput!=null) {
1038
+ var dt = new Date(y,m-1,d,0,0,0);
1039
+ if (window.CP_calendarObject!=null) { window.CP_calendarObject.copyMonthNamesToWindow(); }
1040
+ window.CP_targetInput.value = formatDate(dt,window.CP_dateFormat);
1041
+ }
1042
+ else {
1043
+ alert('Use setReturnFunction() to define which function will get the clicked results!');
1044
+ }
1045
+ }
1046
+ function CP_tmpReturnMonthFunction(y,m) {
1047
+ alert('Use setReturnMonthFunction() to define which function will get the clicked results!\nYou clicked: year='+y+' , month='+m);
1048
+ }
1049
+ function CP_tmpReturnQuarterFunction(y,q) {
1050
+ alert('Use setReturnQuarterFunction() to define which function will get the clicked results!\nYou clicked: year='+y+' , quarter='+q);
1051
+ }
1052
+ function CP_tmpReturnYearFunction(y) {
1053
+ alert('Use setReturnYearFunction() to define which function will get the clicked results!\nYou clicked: year='+y);
1054
+ }
1055
+
1056
+ // Set the name of the functions to call to get the clicked item
1057
+ function CP_setReturnFunction(name) { this.returnFunction = name; }
1058
+ function CP_setReturnMonthFunction(name) { this.returnMonthFunction = name; }
1059
+ function CP_setReturnQuarterFunction(name) { this.returnQuarterFunction = name; }
1060
+ function CP_setReturnYearFunction(name) { this.returnYearFunction = name; }
1061
+
1062
+ // Over-ride the built-in month names
1063
+ function CP_setMonthNames() {
1064
+ for (var i=0; i<arguments.length; i++) { this.monthNames[i] = arguments[i]; }
1065
+ this.copyMonthNamesToWindow();
1066
+ }
1067
+
1068
+ // Over-ride the built-in month abbreviations
1069
+ function CP_setMonthAbbreviations() {
1070
+ for (var i=0; i<arguments.length; i++) { this.monthAbbreviations[i] = arguments[i]; }
1071
+ this.copyMonthNamesToWindow();
1072
+ }
1073
+
1074
+ // Over-ride the built-in column headers for each day
1075
+ function CP_setDayHeaders() {
1076
+ for (var i=0; i<arguments.length; i++) { this.dayHeaders[i] = arguments[i]; }
1077
+ }
1078
+
1079
+ // Set the day of the week (0-7) that the calendar display starts on
1080
+ // This is for countries other than the US whose calendar displays start on Monday(1), for example
1081
+ function CP_setWeekStartDay(day) { this.weekStartDay = day; }
1082
+
1083
+ // Show next/last year navigation links
1084
+ function CP_showYearNavigation() { this.isShowYearNavigation = (arguments.length>0)?arguments[0]:true; }
1085
+
1086
+ // Which type of calendar to display
1087
+ function CP_setDisplayType(type) {
1088
+ if (type!="date"&&type!="week-end"&&type!="month"&&type!="quarter"&&type!="year") { alert("Invalid display type! Must be one of: date,week-end,month,quarter,year"); return false; }
1089
+ this.displayType=type;
1090
+ }
1091
+
1092
+ // How many years back to start by default for year display
1093
+ function CP_setYearSelectStartOffset(num) { this.yearSelectStartOffset=num; }
1094
+
1095
+ // Set which weekdays should not be clickable
1096
+ function CP_setDisabledWeekDays() {
1097
+ this.disabledWeekDays = new Object();
1098
+ for (var i=0; i<arguments.length; i++) { this.disabledWeekDays[arguments[i]] = true; }
1099
+ }
1100
+
1101
+ // Disable individual dates or ranges
1102
+ // Builds an internal logical test which is run via eval() for efficiency
1103
+ function CP_addDisabledDates(start, end) {
1104
+ if (arguments.length==1) { end=start; }
1105
+ if (start==null && end==null) { return; }
1106
+ if (this.disabledDatesExpression!="") { this.disabledDatesExpression+= "||"; }
1107
+ if (start!=null) { start = parseDate(start); start=""+start.getFullYear()+LZ(start.getMonth()+1)+LZ(start.getDate());}
1108
+ if (end!=null) { end=parseDate(end); end=""+end.getFullYear()+LZ(end.getMonth()+1)+LZ(end.getDate());}
1109
+ if (start==null) { this.disabledDatesExpression+="(ds<="+end+")"; }
1110
+ else if (end ==null) { this.disabledDatesExpression+="(ds>="+start+")"; }
1111
+ else { this.disabledDatesExpression+="(ds>="+start+"&&ds<="+end+")"; }
1112
+ }
1113
+
1114
+ // Set the text to use for the "Today" link
1115
+ function CP_setTodayText(text) {
1116
+ this.todayText = text;
1117
+ }
1118
+
1119
+ // Set the prefix to be added to all CSS classes when writing output
1120
+ function CP_setCssPrefix(val) {
1121
+ this.cssPrefix = val;
1122
+ }
1123
+
1124
+ // Show the navigation as an dropdowns that can be manually changed
1125
+ function CP_showNavigationDropdowns() { this.isShowNavigationDropdowns = (arguments.length>0)?arguments[0]:true; }
1126
+
1127
+ // Show the year navigation as an input box that can be manually changed
1128
+ function CP_showYearNavigationInput() { this.isShowYearNavigationInput = (arguments.length>0)?arguments[0]:true; }
1129
+
1130
+ // Hide a calendar object
1131
+ function CP_hideCalendar() {
1132
+ if (arguments.length > 0) { window.popupWindowObjects[arguments[0]].hidePopup(); }
1133
+ else { this.hidePopup(); }
1134
+ }
1135
+
1136
+ // Refresh the contents of the calendar display
1137
+ function CP_refreshCalendar(index) {
1138
+ var calObject = window.popupWindowObjects[index];
1139
+ if (arguments.length>1) {
1140
+ calObject.populate(calObject.getCalendar(arguments[1],arguments[2],arguments[3],arguments[4],arguments[5]));
1141
+ }
1142
+ else {
1143
+ calObject.populate(calObject.getCalendar());
1144
+ }
1145
+ calObject.refresh();
1146
+ }
1147
+
1148
+ // Populate the calendar and display it
1149
+ function CP_showCalendar(anchorname) {
1150
+ if (arguments.length>1) {
1151
+ if (arguments[1]==null||arguments[1]=="") {
1152
+ this.currentDate=new Date();
1153
+ }
1154
+ else {
1155
+ this.currentDate=new Date(parseDate(arguments[1]));
1156
+ }
1157
+ }
1158
+ this.populate(this.getCalendar());
1159
+ this.showPopup(anchorname);
1160
+ }
1161
+
1162
+ // Simple method to interface popup calendar with a text-entry box
1163
+ function CP_select(inputobj, linkname, format) {
1164
+ var selectedDate=(arguments.length>3)?arguments[3]:null;
1165
+ if (!window.getDateFromFormat) {
1166
+ alert("calendar.select: To use this method you must also include 'date.js' for date formatting");
1167
+ return;
1168
+ }
1169
+ if (this.displayType!="date"&&this.displayType!="week-end") {
1170
+ alert("calendar.select: This function can only be used with displayType 'date' or 'week-end'");
1171
+ return;
1172
+ }
1173
+ if (inputobj.type!="text" && inputobj.type!="hidden" && inputobj.type!="textarea") {
1174
+ alert("calendar.select: Input object passed is not a valid form input object");
1175
+ window.CP_targetInput=null;
1176
+ return;
1177
+ }
1178
+ if (inputobj.disabled) { return; } // Can't use calendar input on disabled form input!
1179
+ window.CP_targetInput = inputobj;
1180
+ window.CP_calendarObject = this;
1181
+ this.currentDate=null;
1182
+ var time=0;
1183
+ if (selectedDate!=null) {
1184
+ time = getDateFromFormat(selectedDate,format)
1185
+ }
1186
+ else if (inputobj.value!="") {
1187
+ time = getDateFromFormat(inputobj.value,format);
1188
+ }
1189
+ if (selectedDate!=null || inputobj.value!="") {
1190
+ if (time==0) { this.currentDate=null; }
1191
+ else { this.currentDate=new Date(time); }
1192
+ }
1193
+ window.CP_dateFormat = format;
1194
+ this.showCalendar(linkname);
1195
+ }
1196
+
1197
+ // Get style block needed to display the calendar correctly
1198
+ function getCalendarStyles() {
1199
+ var result = "";
1200
+ var p = "";
1201
+ if (this!=null && typeof(this.cssPrefix)!="undefined" && this.cssPrefix!=null && this.cssPrefix!="") { p=this.cssPrefix; }
1202
+ result += "<STYLE>\n";
1203
+ result += "."+p+"cpYearNavigation,."+p+"cpMonthNavigation { background-color:#C0C0C0; text-align:center; vertical-align:center; text-decoration:none; color:#000000; font-weight:bold; }\n";
1204
+ result += "."+p+"cpDayColumnHeader, ."+p+"cpYearNavigation,."+p+"cpMonthNavigation,."+p+"cpCurrentMonthDate,."+p+"cpCurrentMonthDateDisabled,."+p+"cpOtherMonthDate,."+p+"cpOtherMonthDateDisabled,."+p+"cpCurrentDate,."+p+"cpCurrentDateDisabled,."+p+"cpTodayText,."+p+"cpTodayTextDisabled,."+p+"cpText { font-family:arial; font-size:8pt; }\n";
1205
+ result += "TD."+p+"cpDayColumnHeader { text-align:right; border:solid thin #C0C0C0;border-width:0px 0px 1px 0px; }\n";
1206
+ result += "."+p+"cpCurrentMonthDate, ."+p+"cpOtherMonthDate, ."+p+"cpCurrentDate { text-align:right; text-decoration:none; }\n";
1207
+ result += "."+p+"cpCurrentMonthDateDisabled, ."+p+"cpOtherMonthDateDisabled, ."+p+"cpCurrentDateDisabled { color:#D0D0D0; text-align:right; text-decoration:line-through; }\n";
1208
+ result += "."+p+"cpCurrentMonthDate, .cpCurrentDate { color:#000000; }\n";
1209
+ result += "."+p+"cpOtherMonthDate { color:#808080; }\n";
1210
+ result += "TD."+p+"cpCurrentDate { color:white; background-color: #C0C0C0; border-width:1px; border:solid thin #800000; }\n";
1211
+ result += "TD."+p+"cpCurrentDateDisabled { border-width:1px; border:solid thin #FFAAAA; }\n";
1212
+ result += "TD."+p+"cpTodayText, TD."+p+"cpTodayTextDisabled { border:solid thin #C0C0C0; border-width:1px 0px 0px 0px;}\n";
1213
+ result += "A."+p+"cpTodayText, SPAN."+p+"cpTodayTextDisabled { height:20px; }\n";
1214
+ result += "A."+p+"cpTodayText { color:black; }\n";
1215
+ result += "."+p+"cpTodayTextDisabled { color:#D0D0D0; }\n";
1216
+ result += "."+p+"cpBorder { border:solid thin #808080; }\n";
1217
+ result += "</STYLE>\n";
1218
+ return result;
1219
+ }
1220
+
1221
+ // Return a string containing all the calendar code to be displayed
1222
+ function CP_getCalendar() {
1223
+ var now = new Date();
1224
+ // Reference to window
1225
+ if (this.type == "WINDOW") { var windowref = "window.opener."; }
1226
+ else { var windowref = ""; }
1227
+ var result = "";
1228
+ // If POPUP, write entire HTML document
1229
+ if (this.type == "WINDOW") {
1230
+ result += "<HTML><HEAD><TITLE>Calendar</TITLE>"+this.getStyles()+"</HEAD><BODY MARGINWIDTH=0 MARGINHEIGHT=0 TOPMARGIN=0 RIGHTMARGIN=0 LEFTMARGIN=0>\n";
1231
+ result += '<CENTER><TABLE WIDTH=100% BORDER=0 BORDERWIDTH=0 CELLSPACING=0 CELLPADDING=0>\n';
1232
+ }
1233
+ else {
1234
+ result += '<TABLE CLASS="'+this.cssPrefix+'cpBorder" WIDTH=144 BORDER=1 BORDERWIDTH=1 CELLSPACING=0 CELLPADDING=1>\n';
1235
+ result += '<TR><TD ALIGN=CENTER>\n';
1236
+ result += '<CENTER>\n';
1237
+ }
1238
+ // Code for DATE display (default)
1239
+ // -------------------------------
1240
+ if (this.displayType=="date" || this.displayType=="week-end") {
1241
+ if (this.currentDate==null) { this.currentDate = now; }
1242
+ if (arguments.length > 0) { var month = arguments[0]; }
1243
+ else { var month = this.currentDate.getMonth()+1; }
1244
+ if (arguments.length > 1 && arguments[1]>0 && arguments[1]-0==arguments[1]) { var year = arguments[1]; }
1245
+ else { var year = this.currentDate.getFullYear(); }
1246
+ var daysinmonth= new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
1247
+ if ( ( (year%4 == 0)&&(year%100 != 0) ) || (year%400 == 0) ) {
1248
+ daysinmonth[2] = 29;
1249
+ }
1250
+ var current_month = new Date(year,month-1,1);
1251
+ var display_year = year;
1252
+ var display_month = month;
1253
+ var display_date = 1;
1254
+ var weekday= current_month.getDay();
1255
+ var offset = 0;
1256
+
1257
+ offset = (weekday >= this.weekStartDay) ? weekday-this.weekStartDay : 7-this.weekStartDay+weekday ;
1258
+ if (offset > 0) {
1259
+ display_month--;
1260
+ if (display_month < 1) { display_month = 12; display_year--; }
1261
+ display_date = daysinmonth[display_month]-offset+1;
1262
+ }
1263
+ var next_month = month+1;
1264
+ var next_month_year = year;
1265
+ if (next_month > 12) { next_month=1; next_month_year++; }
1266
+ var last_month = month-1;
1267
+ var last_month_year = year;
1268
+ if (last_month < 1) { last_month=12; last_month_year--; }
1269
+ var date_class;
1270
+ if (this.type!="WINDOW") {
1271
+ result += "<TABLE WIDTH=144 BORDER=0 BORDERWIDTH=0 CELLSPACING=0 CELLPADDING=0>";
1272
+ }
1273
+ result += '<TR>\n';
1274
+ var refresh = windowref+'CP_refreshCalendar';
1275
+ var refreshLink = 'javascript:' + refresh;
1276
+ if (this.isShowNavigationDropdowns) {
1277
+ result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="78" COLSPAN="3"><select CLASS="'+this.cssPrefix+'cpMonthNavigation" name="cpMonth" onChange="'+refresh+'('+this.index+',this.options[this.selectedIndex].value-0,'+(year-0)+');">';
1278
+ for( var monthCounter=1; monthCounter<=12; monthCounter++ ) {
1279
+ var selected = (monthCounter==month) ? 'SELECTED' : '';
1280
+ result += '<option value="'+monthCounter+'" '+selected+'>'+this.monthNames[monthCounter-1]+'</option>';
1281
+ }
1282
+ result += '</select></TD>';
1283
+ result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="10">&nbsp;</TD>';
1284
+
1285
+ result += '<TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="56" COLSPAN="3"><select CLASS="'+this.cssPrefix+'cpYearNavigation" name="cpYear" onChange="'+refresh+'('+this.index+','+month+',this.options[this.selectedIndex].value-0);">';
1286
+ for( var yearCounter=year-this.yearSelectStartOffset; yearCounter<=year+this.yearSelectStartOffset; yearCounter++ ) {
1287
+ var selected = (yearCounter==year) ? 'SELECTED' : '';
1288
+ result += '<option value="'+yearCounter+'" '+selected+'>'+yearCounter+'</option>';
1289
+ }
1290
+ result += '</select></TD>';
1291
+ }
1292
+ else {
1293
+ if (this.isShowYearNavigation) {
1294
+ result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="10"><A CLASS="'+this.cssPrefix+'cpMonthNavigation" HREF="'+refreshLink+'('+this.index+','+last_month+','+last_month_year+');">&lt;</A></TD>';
1295
+ result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="58"><SPAN CLASS="'+this.cssPrefix+'cpMonthNavigation">'+this.monthNames[month-1]+'</SPAN></TD>';
1296
+ result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="10"><A CLASS="'+this.cssPrefix+'cpMonthNavigation" HREF="'+refreshLink+'('+this.index+','+next_month+','+next_month_year+');">&gt;</A></TD>';
1297
+ result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="10">&nbsp;</TD>';
1298
+
1299
+ result += '<TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="10"><A CLASS="'+this.cssPrefix+'cpYearNavigation" HREF="'+refreshLink+'('+this.index+','+month+','+(year-1)+');">&lt;</A></TD>';
1300
+ if (this.isShowYearNavigationInput) {
1301
+ result += '<TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="36"><INPUT NAME="cpYear" CLASS="'+this.cssPrefix+'cpYearNavigation" SIZE="4" MAXLENGTH="4" VALUE="'+year+'" onBlur="'+refresh+'('+this.index+','+month+',this.value-0);"></TD>';
1302
+ }
1303
+ else {
1304
+ result += '<TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="36"><SPAN CLASS="'+this.cssPrefix+'cpYearNavigation">'+year+'</SPAN></TD>';
1305
+ }
1306
+ result += '<TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="10"><A CLASS="'+this.cssPrefix+'cpYearNavigation" HREF="'+refreshLink+'('+this.index+','+month+','+(year+1)+');">&gt;</A></TD>';
1307
+ }
1308
+ else {
1309
+ result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="22"><A CLASS="'+this.cssPrefix+'cpMonthNavigation" HREF="'+refreshLink+'('+this.index+','+last_month+','+last_month_year+');">&lt;&lt;</A></TD>\n';
1310
+ result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="100"><SPAN CLASS="'+this.cssPrefix+'cpMonthNavigation">'+this.monthNames[month-1]+' '+year+'</SPAN></TD>\n';
1311
+ result += '<TD CLASS="'+this.cssPrefix+'cpMonthNavigation" WIDTH="22"><A CLASS="'+this.cssPrefix+'cpMonthNavigation" HREF="'+refreshLink+'('+this.index+','+next_month+','+next_month_year+');">&gt;&gt;</A></TD>\n';
1312
+ }
1313
+ }
1314
+ result += '</TR></TABLE>\n';
1315
+ result += '<TABLE WIDTH=120 BORDER=0 CELLSPACING=0 CELLPADDING=1 ALIGN=CENTER>\n';
1316
+ result += '<TR>\n';
1317
+ for (var j=0; j<7; j++) {
1318
+
1319
+ result += '<TD CLASS="'+this.cssPrefix+'cpDayColumnHeader" WIDTH="14%"><SPAN CLASS="'+this.cssPrefix+'cpDayColumnHeader">'+this.dayHeaders[(this.weekStartDay+j)%7]+'</TD>\n';
1320
+ }
1321
+ result += '</TR>\n';
1322
+ for (var row=1; row<=6; row++) {
1323
+ result += '<TR>\n';
1324
+ for (var col=1; col<=7; col++) {
1325
+ var disabled=false;
1326
+ if (this.disabledDatesExpression!="") {
1327
+ var ds=""+display_year+LZ(display_month)+LZ(display_date);
1328
+ eval("disabled=("+this.disabledDatesExpression+")");
1329
+ }
1330
+ var dateClass = "";
1331
+ if ((display_month == this.currentDate.getMonth()+1) && (display_date==this.currentDate.getDate()) && (display_year==this.currentDate.getFullYear())) {
1332
+ dateClass = "cpCurrentDate";
1333
+ }
1334
+ else if (display_month == month) {
1335
+ dateClass = "cpCurrentMonthDate";
1336
+ }
1337
+ else {
1338
+ dateClass = "cpOtherMonthDate";
1339
+ }
1340
+ if (disabled || this.disabledWeekDays[col-1]) {
1341
+ result += ' <TD CLASS="'+this.cssPrefix+dateClass+'"><SPAN CLASS="'+this.cssPrefix+dateClass+'Disabled">'+display_date+'</SPAN></TD>\n';
1342
+ }
1343
+ else {
1344
+ var selected_date = display_date;
1345
+ var selected_month = display_month;
1346
+ var selected_year = display_year;
1347
+ if (this.displayType=="week-end") {
1348
+ var d = new Date(selected_year,selected_month-1,selected_date,0,0,0,0);
1349
+ d.setDate(d.getDate() + (7-col));
1350
+ selected_year = d.getYear();
1351
+ if (selected_year < 1000) { selected_year += 1900; }
1352
+ selected_month = d.getMonth()+1;
1353
+ selected_date = d.getDate();
1354
+ }
1355
+ result += ' <TD CLASS="'+this.cssPrefix+dateClass+'"><A HREF="javascript:'+windowref+this.returnFunction+'('+selected_year+','+selected_month+','+selected_date+');'+windowref+'CP_hideCalendar(\''+this.index+'\');" CLASS="'+this.cssPrefix+dateClass+'">'+display_date+'</A></TD>\n';
1356
+ }
1357
+ display_date++;
1358
+ if (display_date > daysinmonth[display_month]) {
1359
+ display_date=1;
1360
+ display_month++;
1361
+ }
1362
+ if (display_month > 12) {
1363
+ display_month=1;
1364
+ display_year++;
1365
+ }
1366
+ }
1367
+ result += '</TR>';
1368
+ }
1369
+ var current_weekday = now.getDay() - this.weekStartDay;
1370
+ if (current_weekday < 0) {
1371
+ current_weekday += 7;
1372
+ }
1373
+ result += '<TR>\n';
1374
+ result += ' <TD COLSPAN=7 ALIGN=CENTER CLASS="'+this.cssPrefix+'cpTodayText">\n';
1375
+ if (this.disabledDatesExpression!="") {
1376
+ var ds=""+now.getFullYear()+LZ(now.getMonth()+1)+LZ(now.getDate());
1377
+ eval("disabled=("+this.disabledDatesExpression+")");
1378
+ }
1379
+ if (disabled || this.disabledWeekDays[current_weekday+1]) {
1380
+ result += ' <SPAN CLASS="'+this.cssPrefix+'cpTodayTextDisabled">'+this.todayText+'</SPAN>\n';
1381
+ }
1382
+ else {
1383
+ result += ' <A CLASS="'+this.cssPrefix+'cpTodayText" HREF="javascript:'+windowref+this.returnFunction+'(\''+now.getFullYear()+'\',\''+(now.getMonth()+1)+'\',\''+now.getDate()+'\');'+windowref+'CP_hideCalendar(\''+this.index+'\');">'+this.todayText+'</A>\n';
1384
+ }
1385
+ result += ' <BR>\n';
1386
+ result += ' </TD></TR></TABLE></CENTER></TD></TR></TABLE>\n';
1387
+ }
1388
+
1389
+ // Code common for MONTH, QUARTER, YEAR
1390
+ // ------------------------------------
1391
+ if (this.displayType=="month" || this.displayType=="quarter" || this.displayType=="year") {
1392
+ if (arguments.length > 0) { var year = arguments[0]; }
1393
+ else {
1394
+ if (this.displayType=="year") { var year = now.getFullYear()-this.yearSelectStartOffset; }
1395
+ else { var year = now.getFullYear(); }
1396
+ }
1397
+ if (this.displayType!="year" && this.isShowYearNavigation) {
1398
+ result += "<TABLE WIDTH=144 BORDER=0 BORDERWIDTH=0 CELLSPACING=0 CELLPADDING=0>";
1399
+ result += '<TR>\n';
1400
+ result += ' <TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="22"><A CLASS="'+this.cssPrefix+'cpYearNavigation" HREF="javascript:'+windowref+'CP_refreshCalendar('+this.index+','+(year-1)+');">&lt;&lt;</A></TD>\n';
1401
+ result += ' <TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="100">'+year+'</TD>\n';
1402
+ result += ' <TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="22"><A CLASS="'+this.cssPrefix+'cpYearNavigation" HREF="javascript:'+windowref+'CP_refreshCalendar('+this.index+','+(year+1)+');">&gt;&gt;</A></TD>\n';
1403
+ result += '</TR></TABLE>\n';
1404
+ }
1405
+ }
1406
+
1407
+ // Code for MONTH display
1408
+ // ----------------------
1409
+ if (this.displayType=="month") {
1410
+ // If POPUP, write entire HTML document
1411
+ result += '<TABLE WIDTH=120 BORDER=0 CELLSPACING=1 CELLPADDING=0 ALIGN=CENTER>\n';
1412
+ for (var i=0; i<4; i++) {
1413
+ result += '<TR>';
1414
+ for (var j=0; j<3; j++) {
1415
+ var monthindex = ((i*3)+j);
1416
+ result += '<TD WIDTH=33% ALIGN=CENTER><A CLASS="'+this.cssPrefix+'cpText" HREF="javascript:'+windowref+this.returnMonthFunction+'('+year+','+(monthindex+1)+');'+windowref+'CP_hideCalendar(\''+this.index+'\');" CLASS="'+date_class+'">'+this.monthAbbreviations[monthindex]+'</A></TD>';
1417
+ }
1418
+ result += '</TR>';
1419
+ }
1420
+ result += '</TABLE></CENTER></TD></TR></TABLE>\n';
1421
+ }
1422
+
1423
+ // Code for QUARTER display
1424
+ // ------------------------
1425
+ if (this.displayType=="quarter") {
1426
+ result += '<BR><TABLE WIDTH=120 BORDER=1 CELLSPACING=0 CELLPADDING=0 ALIGN=CENTER>\n';
1427
+ for (var i=0; i<2; i++) {
1428
+ result += '<TR>';
1429
+ for (var j=0; j<2; j++) {
1430
+ var quarter = ((i*2)+j+1);
1431
+ result += '<TD WIDTH=50% ALIGN=CENTER><BR><A CLASS="'+this.cssPrefix+'cpText" HREF="javascript:'+windowref+this.returnQuarterFunction+'('+year+','+quarter+');'+windowref+'CP_hideCalendar(\''+this.index+'\');" CLASS="'+date_class+'">Q'+quarter+'</A><BR><BR></TD>';
1432
+ }
1433
+ result += '</TR>';
1434
+ }
1435
+ result += '</TABLE></CENTER></TD></TR></TABLE>\n';
1436
+ }
1437
+
1438
+ // Code for YEAR display
1439
+ // ---------------------
1440
+ if (this.displayType=="year") {
1441
+ var yearColumnSize = 4;
1442
+ result += "<TABLE WIDTH=144 BORDER=0 BORDERWIDTH=0 CELLSPACING=0 CELLPADDING=0>";
1443
+ result += '<TR>\n';
1444
+ result += ' <TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="50%"><A CLASS="'+this.cssPrefix+'cpYearNavigation" HREF="javascript:'+windowref+'CP_refreshCalendar('+this.index+','+(year-(yearColumnSize*2))+');">&lt;&lt;</A></TD>\n';
1445
+ result += ' <TD CLASS="'+this.cssPrefix+'cpYearNavigation" WIDTH="50%"><A CLASS="'+this.cssPrefix+'cpYearNavigation" HREF="javascript:'+windowref+'CP_refreshCalendar('+this.index+','+(year+(yearColumnSize*2))+');">&gt;&gt;</A></TD>\n';
1446
+ result += '</TR></TABLE>\n';
1447
+ result += '<TABLE WIDTH=120 BORDER=0 CELLSPACING=1 CELLPADDING=0 ALIGN=CENTER>\n';
1448
+ for (var i=0; i<yearColumnSize; i++) {
1449
+ for (var j=0; j<2; j++) {
1450
+ var currentyear = year+(j*yearColumnSize)+i;
1451
+ result += '<TD WIDTH=50% ALIGN=CENTER><A CLASS="'+this.cssPrefix+'cpText" HREF="javascript:'+windowref+this.returnYearFunction+'('+currentyear+');'+windowref+'CP_hideCalendar(\''+this.index+'\');" CLASS="'+date_class+'">'+currentyear+'</A></TD>';
1452
+ }
1453
+ result += '</TR>';
1454
+ }
1455
+ result += '</TABLE></CENTER></TD></TR></TABLE>\n';
1456
+ }
1457
+ // Common
1458
+ if (this.type == "WINDOW") {
1459
+ result += "</BODY></HTML>\n";
1460
+ }
1461
+ return result;
1462
+ }
1463
+
readme.txt ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Calendar ===
2
+ Contributors: KieranOShea
3
+ Donate link: http://www.kjowebservices.co.uk
4
+ Tags: calendar, dates, times, events
5
+ Requires at least: 2.0
6
+ Tested up to: 2.6.2
7
+ Stable tag: 1.2.1
8
+
9
+ A simple but effective Calendar plugin for WordPress that allows you to
10
+ manage your events and appointments and display them to the world.
11
+
12
+ == Description ==
13
+
14
+ A simple but effective Calendar plugin for WordPress that allows you to
15
+ manage your events and appointments and display them to the world on your
16
+ website.
17
+
18
+ Features:
19
+
20
+ * Monthly view of events
21
+ * Mouse-over details for each event
22
+ * Events can have a timestamp (optional)
23
+ * Events can display their author (optional)
24
+ * Events can span more than one day
25
+ * Multiple events per day possible
26
+ * Events can repeat on a weekly, monthly or yearly basis
27
+ * Repeats can occur indefinitely or a limited number of times
28
+ * Easy to use events manager in admin dashboard
29
+ * Sidebar function/Widget to show todays events
30
+ * Sidebar function/Widget to show upcoming events
31
+ * Comprehensive options panel for admin
32
+ * Modifiable CSS using the options panel
33
+ * Optional drop down boxes to quickly change month and year
34
+ * User groups other than admin can be permitted to manage events
35
+ * Events can be placed into categories
36
+ * Categories system can be switched on or off
37
+ * Pop up javascript calendars help the choosing of dates
38
+ * Events can be links pointing to a location of your choice
39
+
40
+ == Installation ==
41
+
42
+ The installation is extremely simple and straightforward. It only takes a second.
43
+
44
+ Installing:
45
+
46
+ 1. Upload the whole calendar directory into your WordPress plugins directory.
47
+
48
+ 2. Activate the plugin on your WordPress plugins page
49
+
50
+ 3. Configure Calendar using:
51
+
52
+ Calendar -> Manage Events
53
+
54
+ Calendar -> Manage Categories
55
+
56
+ Calendar -> Calendar Options
57
+
58
+ 4. Edit or create a page on your blog which includes the text {CALENDAR} and visit
59
+ the page you have edited or created page. You should see your calendar in action.
60
+
61
+ Upgrading from 1.1:
62
+
63
+ 1. Deactivate the plugin (you will not lose any events)
64
+
65
+ 2. Remove the Rewrite rules from your .htaccess file that you added
66
+ when you first installed Calendar.
67
+
68
+ 3. Delete plugins/calendar.php, wp-admin/edit-calendar.php, wp-calendar.php
69
+
70
+ 4. Upload the whole calendar directory into your WordPress plugins directory.
71
+
72
+ 5. Activate the plugin on your WordPress plugins page
73
+
74
+ 6. Configure Calendar using:
75
+
76
+ Calendar -> Manage Events
77
+
78
+ Calendar -> Manage Categories
79
+
80
+ Calendar -> Calendar Options
81
+
82
+ 7. Edit or create a page on your blog which includes the text {CALENDAR} and visit
83
+ the page you have edited or created page. You should see your calendar in action.
84
+
85
+ Uninstalling:
86
+
87
+ 1. Deactivate the plugin on the plugins page of your blog dashboard
88
+
89
+ 2. Delete the uploaded files for the plugin
90
+
91
+ 3. Remove the text {CALENDAR} from the page you were using to show calendar, or delete that page
92
+
93
+ == Frequently Asked Questions ==
94
+
95
+ = Where are the frequently asked questions for Calendar? =
96
+
97
+ They are located on the [KJO Web Services forum](http://forum.kjowebservices.co.uk/viewtopic.php?f=13&t=10 "KJO Web Services forum")
98
+
99
+ = Where can I get support for the plugin? =
100
+
101
+ Support via e-mail became too much of a burden and the lack of e-mail
102
+ notifications made monitoring the WordPress forums impossible. There
103
+ is now a support area for Calendar on the [KJO Web Services forum](http://forum.kjowebservices.co.uk/viewtopic.php?f=13 "KJO Web Services forum")
104
+ which will be monitored and is the only official place to get support for Calendar.
105
+
106
+ = Can I remove the link to your company? =
107
+
108
+ Yes, you may do this, but please only do so if you absolutely have to (for
109
+ instance if you are using Calendar for a business site). Calendar is
110
+ popular and the business we get from users of Calendar deciding to comission
111
+ web work is what allows us to continue to provide Calendar free and open source.
112
+
113
+ == Screenshots ==
114
+
115
+ 1. Calendar being used on a blog page
116
+
117
+ 2. Widgets showing in the sidebar
118
+
119
+ 3. The event management screen of calendar
120
+
121
+ 4. The category management screen of calendar
122
+
123
+ 5. The options screen of Calendar
screenshot-1.png ADDED
Binary file
screenshot-2.png ADDED
Binary file
screenshot-3.png ADDED
Binary file
screenshot-4.png ADDED
Binary file
screenshot-5.png ADDED
Binary file
wp-admin/edit-calendar.php DELETED
@@ -1,386 +0,0 @@
1
- <?php
2
- /*
3
- Author: Kieran O'Shea
4
- Author URI: http://www.kieranoshea.com
5
- Description: Admin panel for the calendar plugin
6
- */
7
-
8
- require_once('admin.php');
9
- $title = __('Calendar');
10
- $parent_file = 'edit.php';
11
-
12
- // Global variable cleanup.
13
- $edit = $create = $save = $delete = false;
14
-
15
- // How to control the app
16
- $action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
17
- $event_id = !empty($_REQUEST['event_id']) ? $_REQUEST['event_id'] : '';
18
-
19
- // Messages for the user
20
- $debugText = '';
21
- $messages = '';
22
-
23
-
24
- require_once('admin-header.php');
25
- //get_currentuserinfo();
26
- ?>
27
-
28
- <style type="text/css">
29
- <!--
30
- .error
31
- {
32
- background: lightcoral;
33
- border: 1px solid #e64f69;
34
- margin: 1em 5% 10px;
35
- padding: 0 1em 0 1em;
36
- }
37
-
38
- .center { text-align: center; }
39
- .right { text-align: right; }
40
- .left { text-align: left; }
41
- .top { vertical-align: top; }
42
- .bold { font-weight: bold; }
43
- .private { color: #e64f69; }
44
- //-->
45
- </style>
46
-
47
- <?php
48
-
49
- //
50
- // Lets see if this is first run and create us a table if it is!
51
- //
52
- $tableExists = false;
53
- $tables = $wpdb->get_results("show tables;");
54
-
55
- foreach ( $tables as $table )
56
- {
57
- foreach ( $table as $value )
58
- {
59
- if ( $value == WP_CALENDAR_TABLE )
60
- {
61
- $tableExists=true;
62
- break;
63
- }
64
- }
65
- }
66
-
67
- if ( !$tableExists )
68
- {
69
- $sql = "CREATE TABLE `" . WP_CALENDAR_TABLE . "` (
70
- `event_id` INT(11) NOT NULL AUTO_INCREMENT ,
71
- `event_begin` DATE NOT NULL ,
72
- `event_end` DATE NOT NULL ,
73
- `event_title` VARCHAR(30) NOT NULL ,
74
- `event_desc` VARCHAR(255) NOT NULL ,
75
- PRIMARY KEY ( `event_id` )
76
- )";
77
- $wpdb->get_results($sql);
78
-
79
- echo "<div class=\"updated\"><p><strong>Greetings</strong><br /><br />
80
- This is the first time you have visited the admin page for calendar. The plugin has created a database table
81
- for you (" . WP_CALENDAR_TABLE . ") and all your events will be stored there. If you want
82
- to remove the data, make sure to delete that table after deactivating the plugin.
83
- This plugin's website is at <a href=\"http://www.kieranoshea.com/programming\">http://www.kieranoshea.com/programming</a></p></div>";
84
- }
85
- //
86
- // First run stage finished
87
- //
88
-
89
-
90
- //
91
- // Lets deal with the various functions
92
- //
93
- if ( $action == 'add' )
94
- {
95
- $title = !empty($_REQUEST['event_title']) ? $_REQUEST['event_title'] : '';
96
- $desc = !empty($_REQUEST['event_desc']) ? $_REQUEST['event_desc'] : '';
97
- $begin = !empty($_REQUEST['event_begin']) ? $_REQUEST['event_begin'] : '';
98
- $end = !empty($_REQUEST['event_end']) ? $_REQUEST['event_end'] : '';
99
-
100
- // Deal with the fools who have left magic quotes turned on
101
- if ( ini_get('magic_quotes_gpc') )
102
- {
103
- $title = stripslashes($title);
104
- $desc = stripslashes($desc);
105
- $begin = stripslashes($begin);
106
- $end = stripslashes($end);
107
- }
108
-
109
- $sql = "INSERT INTO " . WP_CALENDAR_TABLE . " SET event_title='" . mysql_escape_string($title)
110
- . "', event_desc='" . mysql_escape_string($desc) . "', event_begin='" . mysql_escape_string($begin)
111
- . "', event_end='" . mysql_escape_string($end) . "'";
112
-
113
- $wpdb->get_results($sql);
114
-
115
- $sql = "SELECT event_id FROM " . WP_CALENDAR_TABLE . " WHERE event_title='" . mysql_escape_string($title) . "'"
116
- . " AND event_desc='" . mysql_escape_string($desc) . "' AND event_begin='" . mysql_escape_string($begin) . "' AND event_end='" . mysql_escape_string($end) . "' LIMIT 1";
117
- $result = $wpdb->get_results($sql);
118
-
119
- if ( empty($result) || empty($result[0]->event_id) )
120
- {
121
- ?>
122
- <div class="error"><p><strong>Error:</strong> For some bizare reason your event was not added. Why not try again </p></div>
123
- <?php
124
- }
125
- else
126
- {
127
- ?>
128
- <div class="updated"><p>Event added. It will now show in your calendar.</p></div>
129
- <?php
130
- }
131
- }
132
- elseif ( $action == 'edit_save' )
133
- {
134
- $title = !empty($_REQUEST['event_title']) ? $_REQUEST['event_title'] : '';
135
- $desc = !empty($_REQUEST['event_desc']) ? $_REQUEST['event_desc'] : '';
136
- $begin = !empty($_REQUEST['event_begin']) ? $_REQUEST['event_begin'] : '';
137
- $end = !empty($_REQUEST['event_end']) ? $_REQUEST['event_end'] : '';
138
-
139
- // Deal with the fools who have left magic quotes turned on
140
- if ( ini_get('magic_quotes_gpc') )
141
- {
142
- $title = stripslashes($title);
143
- $desc = stripslashes($desc);
144
- $begin = stripslashes($begin);
145
- $end = stripslashes($end);
146
- }
147
-
148
- if ( empty($event_id) )
149
- {
150
- ?>
151
- <div class="error"><p><strong>Failure:</strong> You can't update an event if you haven't submitted an event id</p></div>
152
- <?php
153
- }
154
- else
155
- {
156
- $sql = "UPDATE " . WP_CALENDAR_TABLE . " SET event_title='" . mysql_escape_string($title)
157
- . "', event_desc='" . mysql_escape_string($desc) . "', event_begin='" . mysql_escape_string($begin)
158
- . "', event_end='" . mysql_escape_string($end) . "'" . " WHERE event_id='" . mysql_escape_string($event_id) . "'";
159
-
160
- $wpdb->get_results($sql);
161
-
162
- $sql = "SELECT event_id FROM " . WP_CALENDAR_TABLE . " WHERE event_title='" . mysql_escape_string($title) . "'"
163
- . " AND event_desc='" . mysql_escape_string($desc) . "' AND event_begin='" . mysql_escape_string($begin) . "' AND event_end='" . mysql_escape_string($end) . "' LIMIT 1";
164
- $result = $wpdb->get_results($sql);
165
-
166
- if ( empty($result) || empty($result[0]->event_id) )
167
- {
168
- ?>
169
- <div class="error"><p><strong>Failure:</strong> For some reason the event didn't update. Why not try again. </p></div>
170
- <?php
171
- }
172
- else
173
- {
174
- ?>
175
- <div class="updated"><p>Event updated successfully</p></div>
176
- <?php
177
- }
178
- }
179
- }
180
- elseif ( $action == 'delete' )
181
- {
182
- if ( empty($event_id) )
183
- {
184
- ?>
185
- <div class="error"><p><strong>Error:</strong> Good Lord you gave me nothing to delete, nothing I tell you!</p></div>
186
- <?php
187
- }
188
- else
189
- {
190
- $sql = "DELETE FROM " . WP_CALENDAR_TABLE . " WHERE event_id='" . mysql_escape_string($event_id) . "'";
191
- $wpdb->get_results($sql);
192
-
193
- $sql = "SELECT event_id FROM " . WP_CALENDAR_TABLE . " WHERE event_id='" . mysql_escape_string($event_id) . "'";
194
- $result = $wpdb->get_results($sql);
195
-
196
- if ( empty($result) || empty($result[0]->event_id) )
197
- {
198
- ?>
199
- <div class="updated"><p>Event deleted successfully</p></div>
200
- <?php
201
- }
202
- else
203
- {
204
- ?>
205
- <div class="error"><p><strong>Error:</strong> For some bizare reason the event could not be deleted. Why not try again.</p></div>
206
- <?php
207
-
208
- }
209
- }
210
- }
211
- //
212
- // End of the functionality definitions
213
- //
214
-
215
- ?>
216
-
217
- <div class="wrap">
218
- <?php
219
- if ( $action == 'edit' )
220
- {
221
- ?>
222
- <h2><?php _e('Edit Event'); ?></h2>
223
- <?php
224
- if ( empty($event_id) )
225
- {
226
- echo "<div class=\"error\"><p>Good lord you didn't provide an event id to edit, what were you thinking?</p></div>";
227
- }
228
- else
229
- {
230
- wp_events_edit_form('edit_save', $event_id);
231
- }
232
- }
233
- else
234
- {
235
- ?>
236
- <h2><?php _e('Add Event'); ?></h2>
237
- <?php wp_events_edit_form(); ?>
238
-
239
- <h2><?php _e('Manage Events'); ?></h2>
240
- <?php
241
- wp_events_display_list();
242
- }
243
- ?>
244
- </div>
245
-
246
- <?php
247
- include('admin-footer.php');
248
-
249
-
250
- /**
251
- * Display code for the listing
252
- */
253
- function wp_events_display_list()
254
- {
255
- global $wpdb;
256
-
257
- $events = $wpdb->get_results("SELECT * FROM " . WP_CALENDAR_TABLE . " ORDER BY event_begin DESC");
258
-
259
- if ( !empty($events) )
260
- {
261
- ?>
262
- <table width="100%" cellpadding="3" cellspacing="3">
263
- <tr>
264
- <th scope="col"><?php _e('ID') ?></th>
265
- <th scope="col"><?php _e('Title') ?></th>
266
- <th scope="col"><?php _e('Description') ?></th>
267
- <th scope="col"><?php _e('Start Date') ?></th>
268
- <th scope="col"><?php _e('End Date') ?></th>
269
- <th scope="col"><?php _e('Edit') ?></th>
270
- <th scope="col"><?php _e('Delete') ?></th>
271
- </tr>
272
- <?php
273
- $class = '';
274
- foreach ( $events as $event )
275
- {
276
- $class = ($class == 'alternate') ? '' : 'alternate';
277
- ?>
278
- <tr class="<?php echo $class; ?>">
279
- <th scope="row"><?php echo $event->event_id; ?></th>
280
- <td><?php echo $event->event_title; ?></td>
281
- <td><?php echo $event->event_desc; ?></td>
282
- <td><?php echo $event->event_begin; ?></td>
283
- <td><?php echo $event->event_end; ?></td>
284
- <td><a href="edit-calendar.php?action=edit&amp;event_id=<?php echo $event->event_id;?>" class='edit'><?php echo __('Edit'); ?></a></td>
285
- <td><a href="edit-calendar.php?action=delete&amp;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>
286
- </tr>
287
- <?php
288
- }
289
- ?>
290
- </table>
291
- <?php
292
- }
293
- else
294
- {
295
- ?>
296
- <p><?php _e("There are no events in the database!") ?></p>
297
- <?php
298
- }
299
- }
300
-
301
-
302
- /**
303
- * Display code for the add/edit form
304
- */
305
- function wp_events_edit_form($mode='add', $event_id=false)
306
- {
307
- global $wpdb;
308
- $data = false;
309
-
310
- if ( $event_id !== false )
311
- {
312
- if ( intval($event_id) != $event_id )
313
- {
314
- echo "<div class=\"error\"><p>Bad Monkey! No banana!</p></div>";
315
- return;
316
- }
317
- else
318
- {
319
- $data = $wpdb->get_results("SELECT * FROM " . WP_CALENDAR_TABLE . " WHERE event_id='" . mysql_escape_string($event_id) . "' LIMIT 1");
320
- if ( empty($data) )
321
- {
322
- echo "<div class=\"error\"><p>An event with that ID couldn't be found</p></div>";
323
- return;
324
- }
325
- $data = $data[0];
326
- }
327
- }
328
-
329
- ?>
330
- <form name="quoteform" id="quoteform" class="wrap" method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
331
- <input type="hidden" name="action" value="<?php echo $mode?>">
332
- <input type="hidden" name="event_id" value="<?php echo $event_id?>">
333
-
334
- <div id="item_manager">
335
- <div style="float: left; width: 98%; clear: both;" class="top">
336
- <!-- List URL -->
337
- <fieldset class="small"><legend><?php _e('Event Title'); ?></legend>
338
- <input type="text" name="event_title" class="input" size=30
339
- value="<?php if ( !empty($data) ) echo htmlspecialchars($data->event_title); ?>" />
340
- </fieldset>
341
-
342
- <fieldset class="small"><legend><?php _e('Event Description'); ?></legend>
343
- <input type="text" name="event_desc" class="input" size=50
344
- value="<?php if ( !empty($data) ) echo htmlspecialchars($data->event_desc); ?>" />
345
- </fieldset>
346
-
347
- <fieldset class="small"><legend><?php _e('Start Date'); ?></legend>
348
- <input type="text" name="event_begin" class="input" size=12
349
- value="
350
- <?php
351
- if ( !empty($data) )
352
- {
353
- echo htmlspecialchars($data->event_begin);
354
- }
355
- else
356
- {
357
- echo date("Y-m-j");
358
- }
359
- ?>
360
- " />
361
- </fieldset>
362
-
363
- <fieldset class="small"><legend><?php _e('End Date'); ?></legend>
364
- <input type="text" name="event_end" class="input" size=12
365
- value="
366
- <?php
367
- if ( !empty($data) )
368
- {
369
- echo htmlspecialchars($data->event_end);
370
- }
371
- else
372
- {
373
- echo date("Y-m-j");
374
- }
375
- ?>" />
376
- </fieldset>
377
- <br />
378
- <input type="submit" name="save" class="button bold" value="Save &raquo;" />
379
- </div>
380
- <div style="clear:both; height:1px;">&nbsp;</div>
381
- </div>
382
- </form>
383
- <?php
384
- }
385
-
386
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
wp-calendar.php DELETED
@@ -1,29 +0,0 @@
1
- <?php
2
- /*
3
- Calendar v1.0 for WordPress
4
- Author: Kieran O'Shea
5
- E-Mail: kieran@kieranoshea.com
6
- Website: http://www.kieranoshea.com
7
- */
8
-
9
-
10
- ### Require the standard WordPress header
11
- require(dirname(__FILE__).'/wp-blog-header.php');
12
-
13
- ### Get the title right
14
- add_filter('wp_title', 'calendar_pagetitle');
15
- function allquotes_pagetitle($calendar_pagetitle) {
16
- return ' &raquo; Calendar';
17
- }
18
-
19
- // Begin content of page
20
-
21
- get_header();
22
- ?>
23
-
24
- <h2>Calendar</h2>
25
-
26
- <?php echo calendar(); ?>
27
-
28
- <?php get_sidebar(); ?>
29
- <?php get_footer(); ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
wp-content/plugins/calendar.php DELETED
@@ -1,198 +0,0 @@
1
- <?php
2
- /*
3
- Plugin Name: Calendar
4
- Plugin URI: http://www.kieranoshea.com/
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.kieranoshea.com
8
- Version: 1.0
9
- */
10
-
11
- // Quotes table. I suppose you could change this.
12
- define('WP_CALENDAR_TABLE', $table_prefix . 'calendar');
13
-
14
- // Puts the events management link under manage
15
- function wp_events_admin_menu($content)
16
- {
17
- global $submenu;
18
- $submenu['edit.php'][50] = array(__('Calendar'), 9, 'edit-calendar.php');
19
- }
20
- add_action('admin_menu', 'wp_events_admin_menu');
21
-
22
-
23
- // Now we define the tonne of functions the calendar needs to run
24
-
25
- function next_link($cur_year,$cur_month)
26
- {
27
- $mod_rewrite_months = array(1=>'jan','feb','mar','apr','may','jun','jul','aug','sept','oct','nov','dec');
28
-
29
- $next_year = $cur_year + 1;
30
-
31
- if ($cur_month == 12)
32
- {
33
- return '<a href="/calendar/' . $next_year . '/jan">Next &raquo;</a>';
34
- }
35
- else
36
- {
37
- $next_month = $cur_month + 1;
38
- $month = $mod_rewrite_months[$next_month];
39
- return '<a href="/calendar/' . $cur_year . '/' . $month . '">Next &raquo;</a>';
40
- }
41
- }
42
-
43
- function prev_link($cur_year,$cur_month)
44
- {
45
- $mod_rewrite_months = array(1=>'jan','feb','mar','apr','may','jun','jul','aug','sept','oct','nov','dec');
46
-
47
- $last_year = $cur_year - 1;
48
-
49
- if ($cur_month == 1)
50
- {
51
- return '<a href="/calendar/'. $last_year .'/dec">&laquo; Prev</a>';
52
- }
53
- else
54
- {
55
- $next_month = $cur_month - 1;
56
- $month = $mod_rewrite_months[$next_month];
57
- return '<a href="/calendar/' . $cur_year . '/' . $month . '">&laquo; Prev</a>';
58
- }
59
- }
60
-
61
- function grab_events($y,$m,$d)
62
- {
63
- global $wpdb;
64
- $date = $y . '-' . $m . '-' . $d;
65
- $output = '';
66
- $events = $wpdb->get_results("SELECT * FROM " . WP_CALENDAR_TABLE . " WHERE event_begin <= '$date' AND event_end >= '$date' ORDER BY event_id");
67
- if (!empty($events))
68
- {
69
- foreach($events as $event)
70
- {
71
- $output .= '<br />* <a style="color:#333333; border-bottom: 1px dotted #333333;" title="' . $event->event_desc . '">' . $event->event_title . '</a>';
72
- }
73
- }
74
- return $output;
75
- }
76
-
77
- function calendar()
78
- {
79
-
80
- $name_days = array(1=>'Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');
81
- $name_months = array(1=>'January','February','March','April','May','June','July','August','September','October','November','December');
82
-
83
- if (empty($_GET['month']) || empty($_GET['year']))
84
- {
85
- $c_year = date("Y");
86
- $c_month = date("m");
87
- $c_day = date("d");
88
- }
89
- if ($_GET['year'] <= 3000 && $_GET['year'] >= 0)
90
- {
91
- 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')
92
- {
93
- $c_year = $_GET['year'];
94
- if ($_GET['month'] == 'jan')
95
- {
96
- $t_month = 1;
97
- }
98
- else if ($_GET['month'] == 'feb')
99
- {
100
- $t_month = 2;
101
- }
102
- else if ($_GET['month'] == 'mar')
103
- {
104
- $t_month = 3;
105
- }
106
- else if ($_GET['month'] == 'apr')
107
- {
108
- $t_month = 4;
109
- }
110
- else if ($_GET['month'] == 'may')
111
- {
112
- $t_month = 5;
113
- }
114
- else if ($_GET['month'] == 'jun')
115
- {
116
- $t_month = 6;
117
- }
118
- else if ($_GET['month'] == 'jul')
119
- {
120
- $t_month = 7;
121
- }
122
- else if ($_GET['month'] == 'aug')
123
- {
124
- $t_month = 8;
125
- }
126
- else if ($_GET['month'] == 'sept')
127
- {
128
- $t_month = 9;
129
- }
130
- else if ($_GET['month'] == 'oct')
131
- {
132
- $t_month = 10;
133
- }
134
- else if ($_GET['month'] == 'nov')
135
- {
136
- $t_month = 11;
137
- }
138
- else if ($_GET['month'] == 'dec')
139
- {
140
- $t_month = 12;
141
- }
142
- $c_month = $t_month;
143
- $c_day = date("d");
144
- }
145
- else
146
- {
147
- $c_year = date("Y");
148
- $c_month = date("m");
149
- $c_day = date("d");
150
- }
151
- }
152
- else
153
- {
154
- $c_year = date("Y");
155
- $c_month = date("m");
156
- $c_day = date("d");
157
- }
158
-
159
- $first_weekday = date("w",mktime(0,0,0,$c_month,1,$c_year));
160
- $first_weekday = ($first_weekday==0?7:$first_weekday);
161
-
162
- $days_in_month = date("t", mktime (0,0,0,$c_month,1,$c_year));
163
-
164
- $calendar_body = '<table border="0" cellspacing="1" cellpadding="0" width="100%">';
165
- $calendar_body .= '<tr>
166
- <td height="25" style="border: 1px solid #D6DED5;background-color:#E4EBE3;" colspan="7" align="center" valign="middle">
167
- <table border="0" cellpadding="0" cellspacing="0" width="100%">
168
- <tr>
169
- <td align="center" valign="middle" width="15%">' . prev_link($c_year,$c_month) . '</td>
170
- <td align="center" valign="middle" width="70%">'.$name_months[(int)$c_month].' '.$c_year.'</td>
171
- <td align="center" valign="middle" width="15%">' . next_link($c_year,$c_month) . '</td>
172
- </tr>
173
- </table>
174
- </td>
175
- </tr>';
176
-
177
- $calendar_body .= '<tr>';
178
- for($i=1;$i<=7;$i++) $calendar_body .= '<td style="font-size:0.8em; border: 1px solid #DFE6DE; background-color:#EBF2EA;'.($i<6?'':'color:red;').'" align="center" valign="middle" width="25" height="25">'.$name_days[$i].'</td>';
179
- $calendar_body .= '</tr>';
180
-
181
- for($i=1;$i<=$days_in_month;){
182
- $calendar_body .= '<tr>';
183
- for($ii=1;$ii<=7;$ii++){
184
- if($ii==$first_weekday AND $i==1) $go = TRUE;
185
- elseif($i > $days_in_month ) $go = FALSE;
186
-
187
- if($go) $calendar_body .= '<td align="left" valign="top" width="60" height="60" style="'.(date("Ymd", mktime (0,0,0,$c_month,$i,$c_year))==date("Ymd")?'border: 1px solid #BFBFBF;background-color:#E4EBE3;':'border: 1px solid #DFE6DE;').'"><span style="'.($ii<6?'':'color:red;').'">'.$i++.'</span><span style="font-size:0.7em;">' . grab_events($c_year,$c_month,($i-1)) . '</span></td>';
188
- else $calendar_body .= '<td width="60" height="60" style="border: 1px solid #E9F0E8;">&nbsp;</td>';
189
- }
190
- $calendar_body .= '</tr>';
191
- }
192
- $calendar_body .= '</table>';
193
- $calendar_body .= '<div style="font-size:0.7em; text-align:center; padding:2px;">Want your own calendar like this one? Download it from <a href="http://www.kieranoshea.com/programming">Kieran O\'Shea</a></div>';
194
-
195
- return $calendar_body;
196
- }
197
-
198
- ?>