PluginProbe
Calendar / 1.0
Calendar v1.0
trunk 1.0 1.1 1.1.1 1.1.2 1.2 1.2.1 1.2.2 1.2.3 1.3 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.16 1.3.17 1.3.18 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 All 28 releases
calendar / wp-admin / edit-calendar.php

edit-calendar.php in Calendar 1.0, at wp-admin/edit-calendar.php

387 lines 10.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 ?>
387