PluginProbe
RSVP and Event Management / 1.7.0
RSVP and Event Management v1.7.0
trunk 0.5.0 0.6.0 0.7.0 0.8.0 0.9.0 0.9.5 1.0.0 1.1.0 1.2.0 1.2.1 1.3.0 1.3.1 1.3.2 1.5.0 1.6.0 1.6.1 1.6.2 1.6.5 1.7.0 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 All 136 releases
rsvp / wp-rsvp.php

wp-rsvp.php in RSVP and Event Management 1.7.0, at wp-rsvp.php

1,391 lines 61.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package rsvp
4 * @author MDE Development, LLC
5 * @version 1.7.0
6 */
7 /*
8 Plugin Name: RSVP
9 Text Domain: rsvp-plugin
10 Plugin URI: http://wordpress.org/extend/plugins/rsvp/
11 Description: This plugin allows guests to RSVP to an event. It was made initially for weddings but could be used for other things.
12 Author: MDE Development, LLC
13 Version: 1.7.0
14 Author URI: http://mde-dev.com
15 License: GPL
16 */
17 #
18 # INSTALLATION: see readme.txt
19 #
20 # USAGE: Once the RSVP plugin has been installed, you can set the custom text
21 # via Settings -> RSVP Options in the admin area.
22 #
23 # To add, edit, delete and see rsvp status there will be a new RSVP admin
24 # area just go there.
25 #
26 # To allow people to rsvp create a new page and add "rsvp-pluginhere" to the text
27
28 session_start();
29 define("ATTENDEES_TABLE", $wpdb->prefix."attendees");
30 define("ASSOCIATED_ATTENDEES_TABLE", $wpdb->prefix."associatedAttendees");
31 define("QUESTIONS_TABLE", $wpdb->prefix."rsvpCustomQuestions");
32 define("QUESTION_TYPE_TABLE", $wpdb->prefix."rsvpQuestionTypes");
33 define("ATTENDEE_ANSWERS", $wpdb->prefix."attendeeAnswers");
34 define("QUESTION_ANSWERS_TABLE", $wpdb->prefix."rsvpCustomQuestionAnswers");
35 define("QUESTION_ATTENDEES_TABLE", $wpdb->prefix."rsvpCustomQuestionAttendees");
36 define("EDIT_SESSION_KEY", "RsvpEditAttendeeID");
37 define("EDIT_QUESTION_KEY", "RsvpEditQuestionID");
38 define("RSVP_FRONTEND_TEXT_CHECK", "rsvp-pluginhere");
39 define("OPTION_GREETING", "rsvp_custom_greeting");
40 define("OPTION_THANKYOU", "rsvp_custom_thankyou");
41 define("OPTION_DEADLINE", "rsvp_deadline");
42 define("OPTION_OPENDATE", 'rsvp_opendate');
43 define("OPTION_YES_VERBIAGE", "rsvp_yes_verbiage");
44 define("OPTION_NO_VERBIAGE", "rsvp_no_verbiage");
45 define("OPTION_KIDS_MEAL_VERBIAGE", "rsvp_kids_meal_verbiage");
46 define("OPTION_VEGGIE_MEAL_VERBIAGE", "rsvp_veggie_meal_verbiage");
47 define("OPTION_NOTE_VERBIAGE", "rsvp_note_verbiage");
48 define("RSVP_OPTION_HIDE_NOTE", "rsvp_hide_note_field");
49 define("OPTION_HIDE_VEGGIE", "rsvp_hide_veggie");
50 define("OPTION_HIDE_KIDS_MEAL", "rsvp_hide_kids_meal");
51 define("OPTION_HIDE_ADD_ADDITIONAL", "rsvp_hide_add_additional");
52 define("OPTION_NOTIFY_ON_RSVP", "rsvp_notify_when_rsvp");
53 define("OPTION_NOTIFY_EMAIL", "rsvp_notify_email_address");
54 define("OPTION_DEBUG_RSVP_QUERIES", "rsvp_debug_queries");
55 define("OPTION_WELCOME_TEXT", "rsvp_custom_welcome");
56 define("OPTION_RSVP_QUESTION", "rsvp_custom_question_text");
57 define("OPTION_RSVP_CUSTOM_YES_NO", "rsvp_custom_yes_no");
58 define("OPTION_RSVP_PASSCODE", "rsvp_passcode");
59 define("OPTION_RSVP_OPEN_REGISTRATION", "rsvp_open_registration");
60 define("RSVP_DB_VERSION", "9");
61 define("QT_SHORT", "shortAnswer");
62 define("QT_MULTI", "multipleChoice");
63 define("QT_LONG", "longAnswer");
64 define("QT_DROP", "dropdown");
65 define("QT_RADIO", "radio");
66 define("RSVP_START_PARA", "<p class=\"rsvpParagraph\">");
67 define("RSVP_END_PARA", "</p>\r\n");
68 define("RSVP_START_CONTAINER", "<div id=\"rsvpPlugin\">\r\n");
69 define("RSVP_END_CONTAINER", "</div>\r\n");
70 define("RSVP_START_FORM_FIELD", "<div class=\"rsvpFormField\">\r\n");
71 define("RSVP_END_FORM_FIELD", "</div>\r\n");
72
73 $my_plugin_file = __FILE__;
74
75 if (isset($plugin)) {
76 $my_plugin_file = $plugin;
77 }
78 else if (isset($mu_plugin)) {
79 $my_plugin_file = $mu_plugin;
80 }
81 else if (isset($network_plugin)) {
82 $my_plugin_file = $network_plugin;
83 }
84
85 define('RSVP_PLUGIN_FILE', $my_plugin_file);
86 define('RSVP_PLUGIN_PATH', WP_PLUGIN_DIR.'/'.basename(dirname($my_plugin_file)));
87 if((isset($_GET['page']) && (strToLower($_GET['page']) == 'rsvp-admin-export')) ||
88 (isset($_POST['rsvp-bulk-action']) && (strToLower($_POST['rsvp-bulk-action']) == "export"))) {
89 add_action('init', 'rsvp_admin_export');
90 }
91
92 require_once("rsvp_frontend.inc.php");
93 /*
94 * Description: Database setup for the rsvp plug-in.
95 */
96 function rsvp_database_setup() {
97 global $wpdb;
98 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
99 require_once("rsvp_db_setup.inc.php");
100 }
101
102 function rsvp_install_passcode_field() {
103 global $wpdb;
104 $table = ATTENDEES_TABLE;
105 $sql = "SHOW COLUMNS FROM `$table` LIKE 'passcode'";
106 if(!$wpdb->get_results($sql)) {
107 $sql = "ALTER TABLE `$table` ADD `passcode` VARCHAR(50) NOT NULL DEFAULT '';";
108 $wpdb->query($sql);
109 }
110 }
111
112 function rsvp_require_passcode() {
113 return ((get_option(OPTION_RSVP_PASSCODE) == "Y") || (get_option(OPTION_RSVP_OPEN_REGISTRATION) == "Y"));
114 }
115
116 /**
117 * This generates a random 6 character passcode to be used for guests when the option is enabled.
118 */
119 function rsvp_generate_passcode() {
120 $length = 6;
121 $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
122 $passcode = "";
123
124 for ($p = 0; $p < $length; $p++) {
125 $passcode .= $characters[mt_rand(0, strlen($characters))];
126 }
127
128 return $passcode;
129 }
130
131 function rsvp_admin_guestlist_options() {
132
133 if(rsvp_require_passcode()) {
134 global $wpdb;
135
136 rsvp_install_passcode_field();
137
138 $sql = "SELECT id, passcode FROM ".ATTENDEES_TABLE." WHERE passcode = ''";
139 $attendees = $wpdb->get_results($sql);
140 foreach($attendees as $a) {
141 $newPasscode = rsvp_generate_passcode();
142 $wpdb->update(ATTENDEES_TABLE,
143 array("passcode" => rsvp_generate_passcode()),
144 array("id" => $a->id),
145 array("%s"),
146 array("%d"));
147 }
148 }
149 ?>
150 <script type="text/javascript" language="javascript">
151 jQuery(document).ready(function() {
152 jQuery("#rsvp_opendate").datepicker();
153 jQuery("#rsvp_deadline").datepicker();
154 });
155 </script>
156 <div class="wrap">
157 <h2>RSVP Guestlist Options</h2>
158 <form method="post" action="options.php">
159 <?php settings_fields( 'rsvp-option-group' ); ?>
160 <table class="form-table">
161 <tr valign="top">
162 <th scope="row"><label for="rsvp_opendate">RSVP Open Date:</label></th>
163 <td align="left"><input type="text" name="rsvp_opendate" id="rsvp_opendate" value="<?php echo htmlspecialchars(get_option(OPTION_OPENDATE)); ?>" /></td>
164 </tr>
165 <tr valign="top">
166 <th scope="row"><label for="rsvp_deadline">RSVP Deadline:</label></th>
167 <td align="left"><input type="text" name="rsvp_deadline" id="rsvp_deadline" value="<?php echo htmlspecialchars(get_option(OPTION_DEADLINE)); ?>" /></td>
168 </tr>
169 <tr valign="top">
170 <th scope="row"><label for="rsvp_custom_greeting">Custom Greeting:</label></th>
171 <td align="left"><textarea name="rsvp_custom_greeting" id="rsvp_custom_greeting" rows="5" cols="60"><?php echo htmlspecialchars(get_option(OPTION_GREETING)); ?></textarea></td>
172 </tr>
173 <tr valign="top">
174 <th scope="row"><label for="rsvp_custom_welcome">Custom Welcome:</label></th>
175 <td align="left">Default is: &quot;There are a few more questions we need to ask you if you could please fill them out below to finish up the RSVP process.&quot;<br />
176 <textarea name="rsvp_custom_welcome" id="rsvp_custom_welcome" rows="5" cols="60"><?php echo htmlspecialchars(get_option(OPTION_WELCOME_TEXT)); ?></textarea></td>
177 </tr>
178 <tr valign="top">
179 <th scope="row"><label for="rsvp_custom_question_text">RSVP Question Verbiage:</label></th>
180 <td align="left">Default is: &quot;So, how about it?&quot;<br />
181 <input type="text" name="rsvp_custom_question_text" id="rsvp_custom_question_text"
182 value="<?php echo htmlspecialchars(get_option(OPTION_RSVP_QUESTION)); ?>" size="65" /></td>
183 </tr>
184 <tr valign="top">
185 <th scope="row"><label for="rsvp_yes_verbiage">RSVP Yes Verbiage:</label></th>
186 <td align="left"><input type="text" name="rsvp_yes_verbiage" id="rsvp_yes_verbiage"
187 value="<?php echo htmlspecialchars(get_option(OPTION_YES_VERBIAGE)); ?>" size="65" /></td>
188 </tr>
189 <tr valign="top">
190 <th scope="row"><label for="rsvp_no_verbiage">RSVP No Verbiage:</label></th>
191 <td align="left"><input type="text" name="rsvp_no_verbiage" id="rsvp_no_verbiage"
192 value="<?php echo htmlspecialchars(get_option(OPTION_NO_VERBIAGE)); ?>" size="65" /></td>
193 </tr>
194 <!--<tr valign="top">
195 <th scope="row"><label for="rsvp_custom_yes_no">Custom Yes/No Questions</label></th>
196 <td align="left">
197 This option allows a user to add in multiple yes or no options for when a user rsvps. This will over ride anything specified for the "RSVP Yes Verbiage" and "RSVP No Verbiage" options. The format of each question should be in the format:<br />
198 value | Text user to see and each on it's own line.<br /><br />
199 An example:<br />
200 Yes | Yes, I will gladly come<br />
201 Eh | Eh, I don't really know you and I know you are only inviting me for a gift
202 <br /><br />
203 <strong>Note:</strong> If you do not set a question with a value of "Yes" and one with a value of "No" the RSVP "Yes" and "No" counts will not be correct.
204 <br /><br />
205 <textarea name="rsvp_custom_yes_no" id="rsvp_custom_yes_no" rows="5" cols="60"><?php echo htmlspecialchars(get_option(OPTION_RSVP_CUSTOM_YES_NO)); ?></textarea>
206 </td>
207 </tr>-->
208 <tr valign="top">
209 <th scope="row"><label for="rsvp_kids_meal_verbiage">RSVP Kids Meal Verbiage:</label></th>
210 <td align="left"><input type="text" name="rsvp_kids_meal_verbiage" id="rsvp_kids_meal_verbiage"
211 value="<?php echo htmlspecialchars(get_option(OPTION_KIDS_MEAL_VERBIAGE)); ?>" size="65" /></td>
212 </tr>
213 <tr valign="top">
214 <th scope="row"><label for="rsvp_hide_kids_meal">Hide Kids Meal Question:</label></th>
215 <td align="left"><input type="checkbox" name="rsvp_hide_kids_meal" id="rsvp_hide_kids_meal"
216 value="Y" <?php echo ((get_option(OPTION_HIDE_KIDS_MEAL) == "Y") ? " checked=\"checked\"" : ""); ?> /></td>
217 </tr>
218 <tr valign="top">
219 <th scope="row"><label for="rsvp_veggie_meal_verbiage">RSVP Vegetarian Meal Verbiage:</label></th>
220 <td align="left"><input type="text" name="rsvp_veggie_meal_verbiage" id="rsvp_veggie_meal_verbiage"
221 value="<?php echo htmlspecialchars(get_option(OPTION_VEGGIE_MEAL_VERBIAGE)); ?>" size="65" /></td>
222 </tr>
223 <tr valign="top">
224 <th scope="row"><label for="rsvp_hide_veggie">Hide Vegetarian Meal Question:</label></th>
225 <td align="left"><input type="checkbox" name="rsvp_hide_veggie" id="rsvp_hide_veggie"
226 value="Y" <?php echo ((get_option(OPTION_HIDE_VEGGIE) == "Y") ? " checked=\"checked\"" : ""); ?> /></td>
227 </tr>
228 <tr valign="top">
229 <th scope="row"><label for="rsvp_note_verbiage">Note Verbiage:</label></th>
230 <td align="left"><textarea name="rsvp_note_verbiage" id="rsvp_note_verbiage" rows="3" cols="60"><?php
231 echo htmlspecialchars(get_option(OPTION_NOTE_VERBIAGE)); ?></textarea></td>
232 </tr>
233 <tr valign="top">
234 <th scope="row"><label for="rsvp_hide_note_field">Hide Note Field:</label></th>
235 <td align="left"><input type="checkbox" name="rsvp_hide_note_field" id="rsvp_hide_note_field" value="Y"
236 <?php echo ((get_option(RSVP_OPTION_HIDE_NOTE) == "Y") ? " checked=\"checked\"" : ""); ?> /></td>
237 </tr>
238 <tr valign="top">
239 <th scope="row"><label for="rsvp_custom_thankyou">Custom Thank You:</label></th>
240 <td align="left"><textarea name="rsvp_custom_thankyou" id="rsvp_custom_thankyou" rows="5" cols="60"><?php echo htmlspecialchars(get_option(OPTION_THANKYOU)); ?></textarea></td>
241 </tr>
242 <tr>
243 <th scope="row"><label for="rsvp_hide_add_additional">Do not allow additional guests</label></th>
244 <td align="left"><input type="checkbox" name="rsvp_hide_add_additional" id="rsvp_hide_add_additional" value="Y"
245 <?php echo ((get_option(OPTION_HIDE_ADD_ADDITIONAL) == "Y") ? " checked=\"checked\"" : ""); ?> /></td>
246 </tr>
247 <tr>
248 <th scope="row"><label for="rsvp_notify_when_rsvp">Notify When Guest RSVPs</label></th>
249 <td align="left"><input type="checkbox" name="rsvp_notify_when_rsvp" id="rsvp_notify_when_rsvp" value="Y"
250 <?php echo ((get_option(OPTION_NOTIFY_ON_RSVP) == "Y") ? " checked=\"checked\"" : ""); ?> /></td>
251 </tr>
252 <tr>
253 <th scope="row"><label for="rsvp_notify_email_address">Email address to notify</label></th>
254 <td align="left"><input type="text" name="rsvp_notify_email_address" id="rsvp_notify_email_address" value="<?php echo htmlspecialchars(get_option(OPTION_NOTIFY_EMAIL)); ?>"/></td>
255 </tr>
256 <tr>
257 <th scope="ropw"><label for="<?php echo OPTION_RSVP_PASSCODE; ?>">Require a Passcode to RSVP:</label></th>
258 <td align="left"><input type="checkbox" name="<?php echo OPTION_RSVP_PASSCODE; ?>" id="<?php echo OPTION_RSVP_PASSCODE; ?>" value="Y"
259 <?php echo ((get_option(OPTION_RSVP_PASSCODE) == "Y") ? " checked=\"checked\"" : ""); ?> /></td>
260 </tr>
261 <tr valign="top">
262 <th scope="row"><label for="<?PHP echo OPTION_RSVP_OPEN_REGISTRATION; ?>">Allow Open Registration (note - this will force passcodes for attendees):</label></th>
263 <td align="left"><input type="checkbox" name="<?php echo OPTION_RSVP_OPEN_REGISTRATION; ?>" id="<?php echo OPTION_RSVP_OPEN_REGISTRATION; ?>" value="Y"
264 <?php echo ((get_option(OPTION_RSVP_OPEN_REGISTRATION) == "Y") ? " checked=\"checked\"" : ""); ?> /></td>
265 </tr>
266 <tr valign="top">
267 <th scope="row"><label for="rsvp_debug_queries">Debug RSVP Queries:</label></th>
268 <td align="left"><input type="checkbox" name="rsvp_debug_queries" id="rsvp_debug_queries"
269 value="Y" <?php echo ((get_option(OPTION_DEBUG_RSVP_QUERIES) == "Y") ? " checked=\"checked\"" : ""); ?> /></td>
270 </tr>
271 </table>
272 <input type="hidden" name="action" value="update" />
273 <p class="submit">
274 <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
275 </p>
276 </form>
277 </div>
278 <?php
279 }
280
281 function rsvp_admin_guestlist() {
282 global $wpdb;
283
284 if(get_option("rsvp_db_version") != RSVP_DB_VERSION) {
285 rsvp_database_setup();
286 }
287 rsvp_install_passcode_field();
288 if((count($_POST) > 0) && ($_POST['rsvp-bulk-action'] == "delete") && (is_array($_POST['attendee']) && (count($_POST['attendee']) > 0))) {
289 foreach($_POST['attendee'] as $attendee) {
290 if(is_numeric($attendee) && ($attendee > 0)) {
291 $wpdb->query($wpdb->prepare("DELETE FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeID = %d OR associatedAttendeeID = %d",
292 $attendee,
293 $attendee));
294 $wpdb->query($wpdb->prepare("DELETE FROM ".ATTENDEES_TABLE." WHERE id = %d",
295 $attendee));
296 }
297 }
298 }
299
300 $sql = "SELECT id, firstName, lastName, rsvpStatus, note, kidsMeal, additionalAttendee, veggieMeal, personalGreeting, passcode FROM ".ATTENDEES_TABLE;
301 $orderBy = " lastName, firstName";
302 if(isset($_GET['sort'])) {
303 if(strToLower($_GET['sort']) == "rsvpstatus") {
304 $orderBy = " rsvpStatus ".((strtolower($_GET['sortDirection']) == "desc") ? "DESC" : "ASC") .", ".$orderBy;
305 }else if(strToLower($_GET['sort']) == "attendee") {
306 $direction = ((strtolower($_GET['sortDirection']) == "desc") ? "DESC" : "ASC");
307 $orderBy = " lastName $direction, firstName $direction";
308 } else if(strToLower($_GET['sort']) == "kidsmeal") {
309 $orderBy = " kidsMeal ".((strtolower($_GET['sortDirection']) == "desc") ? "DESC" : "ASC") .", ".$orderBy;
310 } else if(strToLower($_GET['sort']) == "additional") {
311 $orderBy = " additionalAttendee ".((strtolower($_GET['sortDirection']) == "desc") ? "DESC" : "ASC") .", ".$orderBy;
312 } else if(strToLower($_GET['sort']) == "vegetarian") {
313 $orderBy = " veggieMeal ".((strtolower($_GET['sortDirection']) == "desc") ? "DESC" : "ASC") .", ".$orderBy;
314 }
315 }
316 $sql .= " ORDER BY ".$orderBy;
317 $attendees = $wpdb->get_results($sql);
318 $sort = "";
319 $sortDirection = "asc";
320 if(isset($_GET['sort'])) {
321 $sort = $_GET['sort'];
322 }
323
324 if(isset($_GET['sortDirection'])) {
325 $sortDirection = $_GET['sortDirection'];
326 }
327 ?>
328 <script type="text/javascript" language="javascript">
329 jQuery(document).ready(function() {
330 jQuery("#cb").click(function() {
331 if(jQuery("#cb").attr("checked")) {
332 jQuery("input[name='attendee[]']").attr("checked", "checked");
333 } else {
334 jQuery("input[name='attendee[]']").removeAttr("checked");
335 }
336 });
337 });
338 </script>
339 <div class="wrap">
340 <div id="icon-edit" class="icon32"><br /></div>
341 <h2>List of current attendees</h2>
342 <form method="post" id="rsvp-form" enctype="multipart/form-data">
343 <input type="hidden" id="rsvp-bulk-action" name="rsvp-bulk-action" />
344 <input type="hidden" id="sortValue" name="sortValue" value="<?php echo htmlentities($sort, ENT_QUOTES); ?>" />
345 <input type="hidden" name="exportSortDirection" value="<?php echo htmlentities($sortDirection, ENT_QUOTES); ?>" />
346 <div class="tablenav">
347 <div class="alignleft actions">
348 <select id="rsvp-action-top" name="action">
349 <option value="" selected="selected"><?php _e('Bulk Actions', 'rsvp'); ?></option>
350 <option value="delete"><?php _e('Delete', 'rsvp'); ?></option>
351 </select>
352 <input type="submit" value="<?php _e('Apply', 'rsvp'); ?>" name="doaction" id="doaction" class="button-secondary action" onclick="document.getElementById('rsvp-bulk-action').value = document.getElementById('rsvp-action-top').value;" />
353 <input type="submit" value="<?php _e('Export Attendees', 'rsvp'); ?>" name="exportButton" id="exportButton" class="button-secondary action" onclick="document.getElementById('rsvp-bulk-action').value = 'export';" />
354 </div>
355 <?php
356 $yesResults = $wpdb->get_results("SELECT COUNT(*) AS yesCount FROM ".ATTENDEES_TABLE." WHERE rsvpStatus = 'Yes'");
357 $noResults = $wpdb->get_results("SELECT COUNT(*) AS noCount FROM ".ATTENDEES_TABLE." WHERE rsvpStatus = 'No'");
358 $noResponseResults = $wpdb->get_results("SELECT COUNT(*) AS noResponseCount FROM ".ATTENDEES_TABLE." WHERE rsvpStatus = 'NoResponse'");
359 $kidsMeals = $wpdb->get_results("SELECT COUNT(*) AS kidsMealCount FROM ".ATTENDEES_TABLE." WHERE kidsMeal = 'Y'");
360 $veggieMeals = $wpdb->get_results("SELECT COUNT(*) AS veggieMealCount FROM ".ATTENDEES_TABLE." WHERE veggieMeal = 'Y'");
361 ?>
362 <div class="alignright">RSVP Count -
363 Yes: <strong><?php echo $yesResults[0]->yesCount; ?></strong> &nbsp; &nbsp; &nbsp; &nbsp;
364 No: <strong><?php echo $noResults[0]->noCount; ?></strong> &nbsp; &nbsp; &nbsp; &nbsp;
365 No Response: <strong><?php echo $noResponseResults[0]->noResponseCount; ?></strong> &nbsp; &nbsp; &nbsp; &nbsp;
366 Kids Meals: <strong><?php echo $kidsMeals[0]->kidsMealCount; ?></strong> &nbsp; &nbsp; &nbsp; &nbsp;
367 Veggie Meals: <strong><?php echo $veggieMeals[0]->veggieMealCount; ?></strong>
368 </div>
369 <div class="clear"></div>
370 </div>
371 <table class="widefat post fixed" cellspacing="0">
372 <thead>
373 <tr>
374 <th scope="col" class="manage-column column-cb check-column" style=""><input type="checkbox" id="cb" /></th>
375 <th scope="col" id="attendeeName" class="manage-column column-title" style="">Attendee</a> &nbsp;
376 <a href="admin.php?page=rsvp-top-level&amp;sort=attendee&amp;sortDirection=asc">
377 <img src="<?php echo plugins_url(); ?>/rsvp/uparrow<?php
378 echo ((($sort == "attendee") && ($sortDirection == "asc")) ? "_selected" : ""); ?>.gif" width="11" height="9"
379 alt="Sort Ascending Attendee Status" title="Sort Ascending Attendee Status" border="0"></a> &nbsp;
380 <a href="admin.php?page=rsvp-top-level&amp;sort=attendee&amp;sortDirection=desc">
381 <img src="<?php echo plugins_url(); ?>/rsvp/downarrow<?php
382 echo ((($sort == "attendee") && ($sortDirection == "desc")) ? "_selected" : ""); ?>.gif" width="11" height="9"
383 alt="Sort Descending Attendee Status" title="Sort Descending Attendee Status" border="0"></a>
384 </th>
385 <th scope="col" id="rsvpStatus" class="manage-column column-title" style="">RSVP Status &nbsp;
386 <a href="admin.php?page=rsvp-top-level&amp;sort=rsvpStatus&amp;sortDirection=asc">
387 <img src="<?php echo plugins_url(); ?>/rsvp/uparrow<?php
388 echo ((($sort == "rsvpStatus") && ($sortDirection == "asc")) ? "_selected" : ""); ?>.gif" width="11" height="9"
389 alt="Sort Ascending RSVP Status" title="Sort Ascending RSVP Status" border="0"></a> &nbsp;
390 <a href="admin.php?page=rsvp-top-level&amp;sort=rsvpStatus&amp;sortDirection=desc">
391 <img src="<?php echo plugins_url(); ?>/rsvp/downarrow<?php
392 echo ((($sort == "rsvpStatus") && ($sortDirection == "desc")) ? "_selected" : ""); ?>.gif" width="11" height="9"
393 alt="Sort Descending RSVP Status" title="Sort Descending RSVP Status" border="0"></a>
394 </th>
395 <?php if(get_option(OPTION_HIDE_KIDS_MEAL) != "Y") {?>
396 <th scope="col" id="kidsMeal" class="manage-column column-title" style="">Kids Meal &nbsp;
397 <a href="admin.php?page=rsvp-top-level&amp;sort=kidsMeal&amp;sortDirection=asc">
398 <img src="<?php echo plugins_url(); ?>/rsvp/uparrow<?php
399 echo ((($sort == "kidsMeal") && ($sortDirection == "asc")) ? "_selected" : ""); ?>.gif" width="11" height="9"
400 alt="Sort Ascending Kids Meal Status" title="Sort Ascending Kids Meal Status" border="0"></a> &nbsp;
401 <a href="admin.php?page=rsvp-top-level&amp;sort=kidsMeal&amp;sortDirection=desc">
402 <img src="<?php echo plugins_url(); ?>/rsvp/downarrow<?php
403 echo ((($sort == "kidsMeal") && ($sortDirection == "desc")) ? "_selected" : ""); ?>.gif" width="11" height="9"
404 alt="Sort Descending Kids Meal Status" title="Sort Descending Kids Meal Status" border="0"></a>
405 </th>
406 <?php } ?>
407 <th scope="col" id="additionalAttendee" class="manage-column column-title" style="">Additional Attendee &nbsp;
408 <a href="admin.php?page=rsvp-top-level&amp;sort=additional&amp;sortDirection=asc">
409 <img src="<?php echo plugins_url(); ?>/rsvp/uparrow<?php
410 echo ((($sort == "additional") && ($sortDirection == "asc")) ? "_selected" : ""); ?>.gif" width="11" height="9"
411 alt="Sort Ascending Additional Attendees Status" title="Sort Ascending Additional Attendees Status" border="0"></a> &nbsp;
412 <a href="admin.php?page=rsvp-top-level&amp;sort=additional&amp;sortDirection=desc">
413 <img src="<?php echo plugins_url(); ?>/rsvp/downarrow<?php
414 echo ((($sort == "additional") && ($sortDirection == "desc")) ? "_selected" : ""); ?>.gif" width="11" height="9"
415 alt="Sort Descending Additional Attendees Status" title="Sort Descending Additional Atttendees Status" border="0"></a>
416 </th>
417 <?php if(get_option(OPTION_HIDE_VEGGIE) != "Y") {?>
418 <th scope="col" id="veggieMeal" class="manage-column column-title" style="">Vegetarian &nbsp;
419 <a href="admin.php?page=rsvp-top-level&amp;sort=vegetarian&amp;sortDirection=asc">
420 <img src="<?php echo plugins_url(); ?>/rsvp/uparrow<?php
421 echo ((($sort == "vegetarian") && ($sortDirection == "asc")) ? "_selected" : ""); ?>.gif" width="11" height="9"
422 alt="Sort Ascending Vegetarian Status" title="Sort Ascending Vegetarian Status" border="0"></a> &nbsp;
423 <a href="admin.php?page=rsvp-top-level&amp;sort=vegetarian&amp;sortDirection=desc">
424 <img src="<?php echo plugins_url(); ?>/rsvp/downarrow<?php
425 echo ((($sort == "vegetarian") && ($sortDirection == "desc")) ? "_selected" : ""); ?>.gif" width="11" height="9"
426 alt="Sort Descending Vegetarian Status" title="Sort Descending Vegetarian Status" border="0"></a>
427 </th>
428 <?php } ?>
429 <th scope="col" id="customMessage" class="manage-column column-title" style="">Custom Message</th>
430 <th scope="col" id="note" class="manage-column column-title" style="">Note</th>
431 <?php
432 if(rsvp_require_passcode()) {
433 ?>
434 <th scope="col" id="passcode" class="manage-column column-title" style="">Passcode</th>
435 <?php
436 }
437
438 ?>
439 <?php
440 $qRs = $wpdb->get_results("SELECT id, question FROM ".QUESTIONS_TABLE." ORDER BY sortOrder, id");
441 if(count($qRs) > 0) {
442 foreach($qRs as $q) {
443 ?>
444 <th scope="col" class="manage-column -column-title"><?php echo htmlentities(stripslashes($q->question)); ?></th>
445 <?php
446 }
447 }
448 ?>
449 <th scope="col" id="associatedAttendees" class="manage-column column-title" style="">Associated Attendees</th>
450 </tr>
451 </thead>
452 </table>
453 <div style="overflow: auto;height: 450px;">
454 <table class="widefat post fixed" cellspacing="0">
455 <?php
456 $i = 0;
457 foreach($attendees as $attendee) {
458 ?>
459 <tr class="<?php echo (($i % 2 == 0) ? "alternate" : ""); ?> author-self">
460 <th scope="row" class="check-column"><input type="checkbox" name="attendee[]" value="<?php echo $attendee->id; ?>" /></th>
461 <td>
462 <a href="<?php echo get_option("siteurl"); ?>/wp-admin/admin.php?page=rsvp-admin-guest&amp;id=<?php echo $attendee->id; ?>"><?php echo htmlentities(stripslashes($attendee->firstName)." ".stripslashes($attendee->lastName)); ?></a>
463 </td>
464 <td><?php echo $attendee->rsvpStatus; ?></td>
465 <?php if(get_option(OPTION_HIDE_KIDS_MEAL) != "Y") {?>
466 <td><?php
467 if($attendee->rsvpStatus == "NoResponse") {
468 echo "--";
469 } else {
470 echo (($attendee->kidsMeal == "Y") ? "Yes" : "No");
471 }?></td>
472 <?php } ?>
473 <td><?php
474 if($attendee->rsvpStatus == "NoResponse") {
475 echo "--";
476 } else {
477 echo (($attendee->additionalAttendee == "Y") ? "Yes" : "No");
478 }
479 ?></td>
480 <?php if(get_option(OPTION_HIDE_VEGGIE) != "Y") {?>
481 <td><?php
482 if($attendee->rsvpStatus == "NoResponse") {
483 echo "--";
484 } else {
485 echo (($attendee->veggieMeal == "Y") ? "Yes" : "No");
486 }
487 ?></td>
488 <?php } ?>
489 <td><?php
490 echo nl2br(stripslashes(trim($attendee->personalGreeting)));
491 ?></td>
492 <td><?php echo nl2br(stripslashes(trim($attendee->note))); ?></td>
493 <?php
494 if(rsvp_require_passcode()) {
495 ?>
496 <td><?php echo $attendee->passcode; ?></td>
497 <?php
498 }
499 $sql = "SELECT question, answer FROM ".QUESTIONS_TABLE." q
500 LEFT JOIN ".ATTENDEE_ANSWERS." ans ON q.id = ans.questionID AND ans.attendeeID = %d
501 ORDER BY q.sortOrder";
502 $aRs = $wpdb->get_results($wpdb->prepare($sql, $attendee->id));
503 if(count($aRs) > 0) {
504 foreach($aRs as $a) {
505 ?>
506 <td><?php echo htmlentities(stripslashes($a->answer)); ?></td>
507 <?php
508 }
509 }
510 ?>
511 <td>
512 <?php
513 $sql = "SELECT firstName, lastName FROM ".ATTENDEES_TABLE."
514 WHERE id IN (SELECT attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE associatedAttendeeID = %d)
515 OR id in (SELECT associatedAttendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeID = %d)";
516
517 $associations = $wpdb->get_results($wpdb->prepare($sql, $attendee->id, $attendee->id));
518 foreach($associations as $a) {
519 echo htmlentities(stripslashes($a->firstName." ".$a->lastName))."<br />";
520 }
521 ?>
522 </td>
523 </tr>
524 <?php
525 $i++;
526 }
527 ?>
528 </table>
529 </div>
530 </form>
531 </div>
532 <?php
533 }
534
535 function rsvp_admin_export() {
536 global $wpdb;
537 $sql = "SELECT id, firstName, lastName, rsvpStatus, note, kidsMeal, additionalAttendee, veggieMeal, passcode
538 FROM ".ATTENDEES_TABLE;
539
540 $orderBy = " lastName, firstName";
541 if(isset($_POST['sortValue'])) {
542 if(strToLower($_POST['sortValue']) == "rsvpstatus") {
543 $orderBy = " rsvpStatus ".((strtolower($_POST['exportSortDirection']) == "desc") ? "DESC" : "ASC") .", ".$orderBy;
544 }else if(strToLower($_POST['sortValue']) == "attendee") {
545 $direction = ((strtolower($_POST['exportSortDirection']) == "desc") ? "DESC" : "ASC");
546 $orderBy = " lastName $direction, firstName $direction";
547 } else if(strToLower($_POST['sortValue']) == "kidsmeal") {
548 $orderBy = " kidsMeal ".((strtolower($_POST['exportSortDirection']) == "desc") ? "DESC" : "ASC") .", ".$orderBy;
549 } else if(strToLower($_POST['sortValue']) == "additional") {
550 $orderBy = " additionalAttendee ".((strtolower($_POST['exportSortDirection']) == "desc") ? "DESC" : "ASC") .", ".$orderBy;
551 } else if(strToLower($_POST['sortValue']) == "vegetarian") {
552 $orderBy = " veggieMeal ".((strtolower($_POST['exportSortDirection']) == "desc") ? "DESC" : "ASC") .", ".$orderBy;
553 }
554 }
555 $sql .= " ORDER BY ".$orderBy;
556 $attendees = $wpdb->get_results($sql);
557 $csv = "\"Attendee\",\"RSVP Status\",";
558
559 if(get_option(OPTION_HIDE_KIDS_MEAL) != "Y") {
560 $csv .= "\"Kids Meal\",";
561 }
562 $csv .= "\"Additional Attendee\",";
563
564 if(get_option(OPTION_HIDE_VEGGIE) != "Y") {
565 $csv .= "\"Vegatarian\",";
566 }
567 if(rsvp_require_passcode()) {
568 $csv .= "\"Passcode\",";
569 }
570 $csv .= "\"Note\",\"Associated Attendees\"";
571
572 $qRs = $wpdb->get_results("SELECT id, question FROM ".QUESTIONS_TABLE." ORDER BY sortOrder, id");
573 if(count($qRs) > 0) {
574 foreach($qRs as $q) {
575 $csv .= ",\"".stripslashes($q->question)."\"";
576 }
577 }
578
579 $csv .= "\r\n";
580 foreach($attendees as $a) {
581 $csv .= "\"".stripslashes($a->firstName." ".$a->lastName)."\",\"".($a->rsvpStatus)."\",";
582
583 if(get_option(OPTION_HIDE_KIDS_MEAL) != "Y") {
584 $csv .= "\"".(($a->kidsMeal == "Y") ? "Yes" : "No")."\",";
585 }
586
587 $csv .= "\"".(($a->additionalAttendee == "Y") ? "Yes" : "No")."\",";
588
589 if(get_option(OPTION_HIDE_VEGGIE) != "Y") {
590 $csv .= "\"".(($a->veggieMeal == "Y") ? "Yes" : "No")."\",";
591 }
592
593 if(rsvp_require_passcode()) {
594 $csv .= "\"".(($a->passcode))."\",";
595 }
596
597 $csv .= "\"".(str_replace("\"", "\"\"", stripslashes($a->note)))."\",\"";
598
599 $sql = "SELECT firstName, lastName FROM ".ATTENDEES_TABLE."
600 WHERE id IN (SELECT attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE associatedAttendeeID = %d)
601 OR id in (SELECT associatedAttendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeID = %d)";
602
603 $associations = $wpdb->get_results($wpdb->prepare($sql, $a->id, $a->id));
604 foreach($associations as $assc) {
605 $csv .= trim(stripslashes($assc->firstName." ".$assc->lastName))."\r\n";
606 }
607 $csv .= "\"";
608
609 $qRs = $wpdb->get_results("SELECT id, question FROM ".QUESTIONS_TABLE." ORDER BY sortOrder, id");
610 if(count($qRs) > 0) {
611 foreach($qRs as $q) {
612 $aRs = $wpdb->get_results($wpdb->prepare("SELECT answer FROM ".ATTENDEE_ANSWERS." WHERE attendeeID = %d AND questionID = %d", $a->id, $q->id));
613 if(count($aRs) > 0) {
614 $csv .= ",\"".stripslashes($aRs[0]->answer)."\"";
615 } else {
616 $csv .= ",\"\"";
617 }
618 }
619 }
620
621 $csv .= "\r\n";
622 }
623 if(isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/MSIE/", $_SERVER['HTTP_USER_AGENT'])) {
624 // IE Bug in download name workaround
625 ini_set( 'zlib.output_compression','Off' );
626 }
627 header('Content-Description: RSVP Export');
628 header("Content-Type: application/vnd.ms-excel", true);
629 header('Content-Disposition: attachment; filename="rsvpEntries.csv"');
630 echo $csv;
631 exit();
632 }
633
634 function rsvp_admin_import() {
635 global $wpdb;
636 if(count($_FILES) > 0) {
637 check_admin_referer('rsvp-import');
638 require_once("Excel/reader.php");
639 $data = new Spreadsheet_Excel_Reader();
640 $data->read($_FILES['importFile']['tmp_name']);
641 if($data->sheets[0]['numCols'] >= 2) {
642 $count = 0;
643 for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
644 $fName = trim($data->sheets[0]['cells'][$i][1]);
645 $lName = trim($data->sheets[0]['cells'][$i][2]);
646 $personalGreeting = (isset($data->sheets[0]['cells'][$i][4])) ? $personalGreeting = $data->sheets[0]['cells'][$i][4] : "";
647 $passcode = (isset($data->sheets[0]['cells'][$i][5])) ? $data->sheets[0]['cells'][$i][5] : "";
648 if(!empty($fName) && !empty($lName)) {
649 $sql = "SELECT id FROM ".ATTENDEES_TABLE."
650 WHERE firstName = %s AND lastName = %s ";
651 $res = $wpdb->get_results($wpdb->prepare($sql, $fName, $lName));
652 if(count($res) == 0) {
653 $wpdb->insert(ATTENDEES_TABLE, array("firstName" => $fName,
654 "lastName" => $lName,
655 "personalGreeting" => $personalGreeting,
656 "passcode" => $passcode),
657 array('%s', '%s', '%s', '%s'));
658 $count++;
659 }
660 }
661 }
662
663 if($data->sheets[0]['numCols'] >= 3) {
664 // There must be associated users so let's associate them
665 for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
666 $fName = trim($data->sheets[0]['cells'][$i][1]);
667 $lName = trim($data->sheets[0]['cells'][$i][2]);
668 if(!empty($fName) && !empty($lName) && (count($data->sheets[0]['cells'][$i]) >= 3)) {
669 // Get the user's id
670 $sql = "SELECT id FROM ".ATTENDEES_TABLE."
671 WHERE firstName = %s AND lastName = %s ";
672 $res = $wpdb->get_results($wpdb->prepare($sql, $fName, $lName));
673 if((count($res) > 0) && isset($data->sheets[0]['cells'][$i][3])) {
674 $userId = $res[0]->id;
675
676 // Deal with the assocaited users...
677 $associatedUsers = explode(",", trim($data->sheets[0]['cells'][$i][3]));
678 if(is_array($associatedUsers)) {
679 foreach($associatedUsers as $au) {
680 $user = explode(" ", trim($au), 2);
681 // Three cases, they didn't enter in all of the information, user exists or doesn't.
682 // If user exists associate the two users
683 // If user does not exist add the user and then associate the two
684 if(is_array($user) && (count($user) == 2)) {
685 $sql = "SELECT id FROM ".ATTENDEES_TABLE."
686 WHERE firstName = %s AND lastName = %s ";
687 $userRes = $wpdb->get_results($wpdb->prepare($sql, trim($user[0]), trim($user[1])));
688 if(count($userRes) > 0) {
689 $newUserId = $userRes[0]->id;
690 } else {
691 // Insert them and then we can associate them...
692 $wpdb->insert(ATTENDEES_TABLE, array("firstName" => trim($user[0]), "lastName" => trim($user[1])), array('%s', '%s'));
693 $newUserId = $wpdb->insert_id;
694 $count++;
695 }
696
697 $wpdb->insert(ASSOCIATED_ATTENDEES_TABLE, array("attendeeID" => $newUserId,
698 "associatedAttendeeID" => $userId),
699 array("%d", "%d"));
700
701 $wpdb->insert(ASSOCIATED_ATTENDEES_TABLE, array("attendeeID" => $userId,
702 "associatedAttendeeID" => $newUserId),
703 array("%d", "%d"));
704 }
705 }
706 }
707 }
708 }
709 }
710 }
711 ?>
712 <p><strong><?php echo $count; ?></strong> total records were imported.</p>
713 <p>Continue to the RSVP <a href="admin.php?page=rsvp-top-level">list</a></p>
714 <?php
715 }
716 } else {
717 ?>
718 <form name="rsvp_import" method="post" enctype="multipart/form-data">
719 <?php wp_nonce_field('rsvp-import'); ?>
720 <p>Select an excel file (only xls please, xlsx is not supported....yet) in the following format:<br />
721 <strong>First Name</strong> | <strong>Last Name</strong> | <strong>Associated Attendees*</strong> | <strong>Custom Message</strong> | <strong>Passcode</strong>
722 </p>
723 <p>
724 * associated attendees should be separated by a comma it is assumed that the first space encountered will separate the first and last name.
725 </p>
726 <p>A header row is not expected.</p>
727 <p><input type="file" name="importFile" id="importFile" /></p>
728 <p><input type="submit" value="Import File" name="goRsvp" /></p>
729 </form>
730 <?php
731 }
732 }
733
734 function rsvp_admin_guest() {
735 global $wpdb;
736 if((count($_POST) > 0) && !empty($_POST['firstName']) && !empty($_POST['lastName'])) {
737 check_admin_referer('rsvp_add_guest');
738 $passcode = (isset($_POST['passcode'])) ? $_POST['passcode'] : "";
739
740 if(isset($_SESSION[EDIT_SESSION_KEY]) && is_numeric($_SESSION[EDIT_SESSION_KEY])) {
741 $wpdb->update(ATTENDEES_TABLE,
742 array("firstName" => trim($_POST['firstName']),
743 "lastName" => trim($_POST['lastName']),
744 "personalGreeting" => trim($_POST['personalGreeting']),
745 "rsvpStatus" => trim($_POST['rsvpStatus'])),
746 array("id" => $_SESSION[EDIT_SESSION_KEY]),
747 array("%s", "%s", "%s", "%s"),
748 array("%d"));
749 rsvp_printQueryDebugInfo();
750 $attendeeId = $_SESSION[EDIT_SESSION_KEY];
751 $wpdb->query($wpdb->prepare("DELETE FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeId = %d", $attendeeId));
752 } else {
753 $wpdb->insert(ATTENDEES_TABLE, array("firstName" => trim($_POST['firstName']),
754 "lastName" => trim($_POST['lastName']),
755 "personalGreeting" => trim($_POST['personalGreeting']),
756 "rsvpStatus" => trim($_POST['rsvpStatus'])),
757 array('%s', '%s', '%s', '%s'));
758 rsvp_printQueryDebugInfo();
759
760 $attendeeId = $wpdb->insert_id;
761 }
762
763 if(isset($_POST['associatedAttendees']) && is_array($_POST['associatedAttendees'])) {
764 foreach($_POST['associatedAttendees'] as $aid) {
765 if(is_numeric($aid) && ($aid > 0)) {
766 $wpdb->insert(ASSOCIATED_ATTENDEES_TABLE, array("attendeeID"=>$attendeeId, "associatedAttendeeID"=>$aid), array("%d", "%d"));
767 rsvp_printQueryDebugInfo();
768 }
769 }
770 }
771
772 if(rsvp_require_passcode()) {
773 if(empty($passcode)) {
774 $passcode = rsvp_generate_passcode();
775 }
776 $wpdb->update(ATTENDEES_TABLE,
777 array("passcode" => trim($passcode)),
778 array("id"=>$attendeeId),
779 array("%s"),
780 array("%d"));
781 }
782 ?>
783 <p>Attendee <?php echo htmlentities(stripslashes($_POST['firstName']." ".$_POST['lastName']));?> has been successfully saved</p>
784 <p>
785 <a href="<?php echo get_option('siteurl'); ?>/wp-admin/admin.php?page=rsvp-top-level">Continue to Attendee List</a> |
786 <a href="<?php echo get_option('siteurl'); ?>/wp-admin/admin.php?page=rsvp-admin-guest">Add a Guest</a>
787 </p>
788 <?php
789 } else {
790 $attendee = null;
791 unset($_SESSION[EDIT_SESSION_KEY]);
792 $associatedAttendees = array();
793 $firstName = "";
794 $lastName = "";
795 $personalGreeting = "";
796 $rsvpStatus = "NoResponse";
797 $passcode = "";
798
799 if(isset($_GET['id']) && is_numeric($_GET['id'])) {
800 $attendee = $wpdb->get_row("SELECT id, firstName, lastName, personalGreeting, rsvpStatus, passcode FROM ".ATTENDEES_TABLE." WHERE id = ".$_GET['id']);
801 if($attendee != null) {
802 $_SESSION[EDIT_SESSION_KEY] = $attendee->id;
803 $firstName = stripslashes($attendee->firstName);
804 $lastName = stripslashes($attendee->lastName);
805 $personalGreeting = stripslashes($attendee->personalGreeting);
806 $rsvpStatus = $attendee->rsvpStatus;
807 $passcode = stripslashes($attendee->passcode);
808
809 // Get the associated attendees and add them to an array
810 $associations = $wpdb->get_results("SELECT associatedAttendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeId = ".$attendee->id.
811 " UNION ".
812 "SELECT attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE associatedAttendeeID = ".$attendee->id);
813 foreach($associations as $aId) {
814 $associatedAttendees[] = $aId->associatedAttendeeID;
815 }
816 }
817 }
818 ?>
819 <form name="contact" action="admin.php?page=rsvp-admin-guest" method="post">
820 <?php wp_nonce_field('rsvp_add_guest'); ?>
821 <p class="submit">
822 <input type="submit" class="button-primary" value="<?php _e('Save'); ?>" />
823 </p>
824 <table class="form-table">
825 <tr valign="top">
826 <th scope="row"><label for="firstName"><?php echo __("First Name", 'rsvp-plugin'); ?>:</label></th>
827 <td align="left"><input type="text" name="firstName" id="firstName" size="30" value="<?php echo htmlentities($firstName); ?>" /></td>
828 </tr>
829 <tr valign="top">
830 <th scope="row"><label for="lastName"><?php echo __("Last Name", 'rsvp-plugin'); ?>:</label></th>
831 <td align="left"><input type="text" name="lastName" id="lastName" size="30" value="<?php echo htmlentities($lastName); ?>" /></td>
832 </tr>
833 <?php
834 if(rsvp_require_passcode()) {
835 ?>
836 <tr valign="top">
837 <th scope="row"><label for="passcode">Passcode:</label></th>
838 <td align="left"><input type="text" name="passcode" id="passcode" size="30" value="<?php echo htmlentities($passcode); ?>" maxlength="6" /></td>
839 </tr>
840 <?php
841 }
842 ?>
843 <tr>
844 <th scope="row"><label for="rsvpStatus">RSVP Status</label></th>
845 <td align="left">
846 <select name="rsvpStatus" id="rsvpStatus" size="1">
847 <option value="NoResponse" <?php
848 echo (($rsvpStatus == "NoResponse") ? " selected=\"selected\"" : "");
849 ?>>No Response</option>
850 <option value="Yes" <?php
851 echo (($rsvpStatus == "Yes") ? " selected=\"selected\"" : "");
852 ?>>Yes</option>
853 <option value="No" <?php
854 echo (($rsvpStatus == "No") ? " selected=\"selected\"" : "");
855 ?>>No</option>
856 </select>
857 </td>
858 </tr>
859 <tr valign="top">
860 <th scope="row" valign="top"><label for="personalGreeting">Custom Message:</label></th>
861 <td align="left"><textarea name="personalGreeting" id="personalGreeting" rows="5" cols="40"><?php echo htmlentities($personalGreeting); ?></textarea></td>
862 </tr>
863 <tr valign="top">
864 <th scope="row">Associated Attendees:</th>
865 <td align="left">
866 <select name="associatedAttendees[]" multiple="multiple" size="5" style="height: 200px;">
867 <?php
868 $attendees = $wpdb->get_results("SELECT id, firstName, lastName FROM ".$wpdb->prefix."attendees ORDER BY lastName, firstName");
869 foreach($attendees as $a) {
870 if($a->id != $_SESSION[EDIT_SESSION_KEY]) {
871 ?>
872 <option value="<?php echo $a->id; ?>"
873 <?php echo ((in_array($a->id, $associatedAttendees)) ? "selected=\"selected\"" : ""); ?>><?php echo htmlentities(stripslashes($a->firstName)." ".stripslashes($a->lastName)); ?></option>
874 <?php
875 }
876 }
877 ?>
878 </select>
879 </td>
880 </tr>
881 <?php
882 if(($attendee != null) && ($attendee->id > 0)) {
883 $sql = "SELECT question, answer FROM ".ATTENDEE_ANSWERS." ans
884 INNER JOIN ".QUESTIONS_TABLE." q ON q.id = ans.questionID
885 WHERE attendeeID = %d
886 ORDER BY q.sortOrder";
887 $aRs = $wpdb->get_results($wpdb->prepare($sql, $attendee->id));
888 if(count($aRs) > 0) {
889 ?>
890 <tr>
891 <td colspan="2">
892 <h4>Custom Questions Answered</h4>
893 <table cellpadding="2" cellspacing="0" border="0">
894 <tr>
895 <th>Question</th>
896 <th>Answer</th>
897 </tr>
898 <?php
899 foreach($aRs as $a) {
900 ?>
901 <tr>
902 <td><?php echo stripslashes($a->question); ?></td>
903 <td><?php echo stripslashes($a->answer); ?></td>
904 </tr>
905 <?php
906 }
907 ?>
908 </table>
909 </td>
910 </tr>
911 <?php
912 }
913 }
914 ?>
915 </table>
916 <p class="submit">
917 <input type="submit" class="button-primary" value="<?php _e('Save'); ?>" />
918 </p>
919 </form>
920 <?php
921 }
922 }
923
924 function rsvp_admin_questions() {
925 global $wpdb;
926
927 if((count($_POST) > 0) && ($_POST['rsvp-bulk-action'] == "delete") && (is_array($_POST['q']) && (count($_POST['q']) > 0))) {
928 foreach($_POST['q'] as $q) {
929 if(is_numeric($q) && ($q > 0)) {
930 $wpdb->query($wpdb->prepare("DELETE FROM ".QUESTIONS_TABLE." WHERE id = %d", $q));
931 $wpdb->query($wpdb->prepare("DELETE FROM ".ATTENDEE_ANSWERS." WHERE questionID = %d", $q));
932 }
933 }
934 } else if((count($_POST) > 0) && ($_POST['rsvp-bulk-action'] == "saveSortOrder")) {
935 $sql = "SELECT id FROM ".QUESTIONS_TABLE;
936 $sortQs = $wpdb->get_results($sql);
937 foreach($sortQs as $q) {
938 if(is_numeric($_POST['sortOrder'.$q->id]) && ($_POST['sortOrder'.$q->id] >= 0)) {
939 $wpdb->update(QUESTIONS_TABLE,
940 array("sortOrder" => $_POST['sortOrder'.$q->id]),
941 array("id" => $q->id),
942 array("%d"),
943 array("%d"));
944 rsvp_printQueryDebugInfo();
945 }
946 }
947 }
948
949 $sql = "SELECT id, question, sortOrder FROM ".QUESTIONS_TABLE." ORDER BY sortOrder ASC";
950 $customQs = $wpdb->get_results($sql);
951 ?>
952 <script type="text/javascript" language="javascript">
953 jQuery(document).ready(function() {
954 jQuery("#cb").click(function() {
955 if(jQuery("#cb").attr("checked")) {
956 jQuery("input[name='q[]']").attr("checked", "checked");
957 } else {
958 jQuery("input[name='q[]']").removeAttr("checked");
959 }
960 });
961
962 jQuery("#customQuestions").tableDnD({
963 onDrop: function(table, row) {
964 var rows = table.tBodies[0].rows;
965 for (var i=0; i<rows.length; i++) {
966 jQuery("#sortOrder" + rows[i].id).val(i);
967 }
968
969 }
970 });
971 });
972 </script>
973 <div class="wrap">
974 <div id="icon-edit" class="icon32"><br /></div>
975 <h2>List of current custom questions</h2>
976 <form method="post" id="rsvp-form" enctype="multipart/form-data">
977 <input type="hidden" id="rsvp-bulk-action" name="rsvp-bulk-action" />
978 <div class="tablenav">
979 <div class="alignleft actions">
980 <select id="rsvp-action-top" name="action">
981 <option value="" selected="selected"><?php _e('Bulk Actions', 'rsvp'); ?></option>
982 <option value="delete"><?php _e('Delete', 'rsvp'); ?></option>
983 </select>
984 <input type="submit" value="<?php _e('Apply', 'rsvp'); ?>" name="doaction" id="doaction" class="button-secondary action" onclick="document.getElementById('rsvp-bulk-action').value = document.getElementById('rsvp-action-top').value;" />
985 <input type="submit" value="<?php _e('Save Sort Order', 'rsvp'); ?>" name="saveSortButton" id="saveSortButton" class="button-secondary action" onclick="document.getElementById('rsvp-bulk-action').value = 'saveSortOrder';" />
986 </div>
987 <div class="clear"></div>
988 </div>
989 <table class="widefat post fixed" cellspacing="0">
990 <thead>
991 <tr>
992 <th scope="col" class="manage-column column-cb check-column" style=""><input type="checkbox" id="cb" /></th>
993 <th scope="col" id="questionCol" class="manage-column column-title" style="">Question</th>
994 </tr>
995 </thead>
996 </table>
997 <div style="overflow: auto;height: 450px;">
998 <table class="widefat post fixed" cellspacing="0" id="customQuestions">
999 <?php
1000 $i = 0;
1001 foreach($customQs as $q) {
1002 ?>
1003 <tr class="<?php echo (($i % 2 == 0) ? "alternate" : ""); ?> author-self" id="<?php echo $q->id; ?>">
1004 <th scope="row" class="check-column"><input type="checkbox" name="q[]" value="<?php echo $q->id; ?>" /></th>
1005 <td>
1006 <a href="<?php echo get_option("siteurl"); ?>/wp-admin/admin.php?page=rsvp-admin-custom-question&amp;id=<?php echo $q->id; ?>"><?php echo htmlentities(stripslashes($q->question)); ?></a>
1007 <input type="hidden" name="sortOrder<?php echo $q->id; ?>" id="sortOrder<?php echo $q->id; ?>" value="<?php echo $q->sortOrder; ?>" />
1008 </td>
1009 </tr>
1010 <?php
1011 $i++;
1012 }
1013 ?>
1014 </table>
1015 </div>
1016 </form>
1017 </div>
1018 <?php
1019 }
1020
1021 function rsvp_admin_custom_question() {
1022 global $wpdb;
1023 $answerQuestionTypes = array(2,4,5);
1024
1025 $radioQuestionType = $wpdb->get_results("SELECT id FROM ".QUESTION_TYPE_TABLE." WHERE questionType = 'radio'");
1026 if($radioQuestionType == 0) {
1027 $wpdb->insert(QUESTION_TYPE_TABLE, array("questionType" => "radio", "friendlyName" => "Radio"), array('%s', '%s'));
1028 rsvp_printQueryDebugInfo();
1029 }
1030
1031 if((count($_POST) > 0) && !empty($_POST['question']) && is_numeric($_POST['questionTypeID'])) {
1032 check_admin_referer('rsvp_add_custom_question');
1033 if(isset($_SESSION[EDIT_QUESTION_KEY]) && is_numeric($_SESSION[EDIT_QUESTION_KEY])) {
1034 $wpdb->update(QUESTIONS_TABLE,
1035 array("question" => trim($_POST['question']),
1036 "questionTypeID" => trim($_POST['questionTypeID']),
1037 "permissionLevel" => ((trim($_POST['permissionLevel']) == "private") ? "private" : "public")),
1038 array("id" => $_SESSION[EDIT_QUESTION_KEY]),
1039 array("%s", "%d", "%s"),
1040 array("%d"));
1041 rsvp_printQueryDebugInfo();
1042 $questionId = $_SESSION[EDIT_QUESTION_KEY];
1043
1044 $answers = $wpdb->get_results($wpdb->prepare("SELECT id FROM ".QUESTION_ANSWERS_TABLE." WHERE questionID = %d", $questionId));
1045 if(count($answers) > 0) {
1046 foreach($answers as $a) {
1047 if(isset($_POST['deleteAnswer'.$a->id]) && (strToUpper($_POST['deleteAnswer'.$a->id]) == "Y")) {
1048 $wpdb->query($wpdb->prepare("DELETE FROM ".QUESTION_ANSWERS_TABLE." WHERE id = %d", $a->id));
1049 } elseif(isset($_POST['answer'.$a->id]) && !empty($_POST['answer'.$a->id])) {
1050 $wpdb->update(QUESTION_ANSWERS_TABLE,
1051 array("answer" => trim($_POST['answer'.$a->id])),
1052 array("id"=>$a->id),
1053 array("%s"),
1054 array("%d"));
1055 rsvp_printQueryDebugInfo();
1056 }
1057 }
1058 }
1059 } else {
1060 $wpdb->insert(QUESTIONS_TABLE, array("question" => trim($_POST['question']),
1061 "questionTypeID" => trim($_POST['questionTypeID']),
1062 "permissionLevel" => ((trim($_POST['permissionLevel']) == "private") ? "private" : "public")),
1063 array('%s', '%d', '%s'));
1064 rsvp_printQueryDebugInfo();
1065 $questionId = $wpdb->insert_id;
1066 }
1067
1068 if(isset($_POST['numNewAnswers']) && is_numeric($_POST['numNewAnswers']) &&
1069 in_array($_POST['questionTypeID'], $answerQuestionTypes)) {
1070 for($i = 0; $i < $_POST['numNewAnswers']; $i++) {
1071 if(isset($_POST['newAnswer'.$i]) && !empty($_POST['newAnswer'.$i])) {
1072 $wpdb->insert(QUESTION_ANSWERS_TABLE, array("questionID"=>$questionId, "answer"=>$_POST['newAnswer'.$i]));
1073 rsvp_printQueryDebugInfo();
1074 }
1075 }
1076 }
1077
1078 if(strToLower(trim($_POST['permissionLevel'])) == "private") {
1079 $wpdb->query($wpdb->prepare("DELETE FROM ".QUESTION_ATTENDEES_TABLE." WHERE questionID = %d", $questionId));
1080 if(isset($_POST['attendees']) && is_array($_POST['attendees'])) {
1081 foreach($_POST['attendees'] as $aid) {
1082 if(is_numeric($aid) && ($aid > 0)) {
1083 $wpdb->insert(QUESTION_ATTENDEES_TABLE, array("attendeeID"=>$aid, "questionID"=>$questionId), array("%d", "%d"));
1084 rsvp_printQueryDebugInfo();
1085 }
1086 }
1087 }
1088 }
1089 ?>
1090 <p>Custom Question saved</p>
1091 <p>
1092 <a href="<?php echo get_option('siteurl'); ?>/wp-admin/admin.php?page=rsvp-admin-questions">Continue to Question List</a> |
1093 <a href="<?php echo get_option('siteurl'); ?>/wp-admin/admin.php?page=rsvp-admin-custom-question">Add another Question</a>
1094 </p>
1095 <?php
1096 } else {
1097 $questionTypeId = 0;
1098 $question = "";
1099 $isNew = true;
1100 $questionId = 0;
1101 $permissionLevel = "public";
1102 $savedAttendees = array();
1103 unset($_SESSION[EDIT_QUESTION_KEY]);
1104 if(isset($_GET['id']) && is_numeric($_GET['id'])) {
1105 $qRs = $wpdb->get_results($wpdb->prepare("SELECT id, question, questionTypeID, permissionLevel FROM ".QUESTIONS_TABLE." WHERE id = %d", $_GET['id']));
1106 if(count($qRs) > 0) {
1107 $isNew = false;
1108 $_SESSION[EDIT_QUESTION_KEY] = $qRs[0]->id;
1109 $questionId = $qRs[0]->id;
1110 $question = stripslashes($qRs[0]->question);
1111 $permissionLevel = stripslashes($qRs[0]->permissionLevel);
1112 $questionTypeId = $qRs[0]->questionTypeID;
1113
1114 if($permissionLevel == "private") {
1115 $aRs = $wpdb->get_results($wpdb->prepare("SELECT attendeeID FROM ".QUESTION_ATTENDEES_TABLE." WHERE questionID = %d", $questionId));
1116 if(count($aRs) > 0) {
1117 foreach($aRs as $a) {
1118 $savedAttendees[] = $a->attendeeID;
1119 }
1120 }
1121 }
1122 }
1123 }
1124
1125 $sql = "SELECT id, questionType, friendlyName FROM ".QUESTION_TYPE_TABLE;
1126 $questionTypes = $wpdb->get_results($sql);
1127 ?>
1128 <script type="text/javascript">
1129 function addAnswer(counterElement) {
1130 var currAnswer = jQuery("#numNewAnswers").val();
1131 if(isNaN(currAnswer)) {
1132 currAnswer = 0;
1133 }
1134
1135 var s = "<tr>\r\n"+
1136 "<td align=\"right\" width=\"75\"><label for=\"newAnswer" + currAnswer + "\">Answer:</label></td>\r\n" +
1137 "<td><input type=\"text\" name=\"newAnswer" + currAnswer + "\" id=\"newAnswer" + currAnswer + "\" size=\"40\" /></td>\r\n" +
1138 "</tr>\r\n";
1139 jQuery("#answerContainer").append(s);
1140 currAnswer++;
1141 jQuery("#numNewAnswers").val(currAnswer);
1142 return false;
1143 }
1144
1145 jQuery(document).ready(function() {
1146
1147 <?php
1148 if($isNew || !in_array($questionTypeId, $answerQuestionTypes)) {
1149 echo 'jQuery("#answerContainer").hide();';
1150 }
1151
1152 if($isNew || ($permissionLevel == "public")) {
1153 ?>
1154 jQuery("#attendeesArea").hide();
1155 <?php
1156 }
1157 ?>
1158 jQuery("#questionType").change(function() {
1159 var selectedValue = jQuery("#questionType").val();
1160 if((selectedValue == 2) || (selectedValue == 4) || (selectedValue == 5)) {
1161 jQuery("#answerContainer").show();
1162 } else {
1163 jQuery("#answerContainer").hide();
1164 }
1165 })
1166
1167 jQuery("#permissionLevel").change(function() {
1168 if(jQuery("#permissionLevel").val() != "public") {
1169 jQuery("#attendeesArea").show();
1170 } else {
1171 jQuery("#attendeesArea").hide();
1172 }
1173 })
1174 });
1175 </script>
1176 <form name="contact" action="admin.php?page=rsvp-admin-custom-question" method="post">
1177 <input type="hidden" name="numNewAnswers" id="numNewAnswers" value="0" />
1178 <?php wp_nonce_field('rsvp_add_custom_question'); ?>
1179 <p class="submit">
1180 <input type="submit" class="button-primary" value="<?php _e('Save'); ?>" />
1181 </p>
1182 <table id="customQuestions" class="form-table">
1183 <tr valign="top">
1184 <th scope="row"><label for="questionType">Question Type:</label></th>
1185 <td align="left"><select name="questionTypeID" id="questionType" size="1">
1186 <?php
1187 foreach($questionTypes as $qt) {
1188 echo "<option value=\"".$qt->id."\" ".(($questionTypeId == $qt->id) ? " selected=\"selected\"" : "").">".$qt->friendlyName."</option>\r\n";
1189 }
1190 ?>
1191 </select>
1192 </td>
1193 </tr>
1194 <tr valign="top">
1195 <th scope="row"><label for="question">Question:</label></th>
1196 <td align="left"><input type="text" name="question" id="question" size="40" value="<?php echo htmlentities($question); ?>" /></td>
1197 </tr>
1198 <tr>
1199 <th scope="row"><label for="permissionLevel">Question Permission Level:</label></th>
1200 <td align="left"><select name="permissionLevel" id="permissionLevel" size="1">
1201 <option value="public" <?php echo ($permissionLevel == "public") ? " selected=\"selected\"" : ""; ?>>Public</option>
1202 <option value="private" <?php echo ($permissionLevel == "private") ? " selected=\"selected\"" : ""; ?>>Private</option>
1203 </select></td>
1204 </tr>
1205 <tr>
1206 <td colspan="2">
1207 <table cellpadding="0" cellspacing="0" border="0" id="answerContainer">
1208 <tr>
1209 <th>Answers</th>
1210 <th align="right"><a href="#" onclick="return addAnswer();">Add new Answer</a></th>
1211 </tr>
1212 <?php
1213 if(!$isNew) {
1214 $aRs = $wpdb->get_results($wpdb->prepare("SELECT id, answer FROM ".QUESTION_ANSWERS_TABLE." WHERE questionID = %d", $questionId));
1215 if(count($aRs) > 0) {
1216 foreach($aRs as $answer) {
1217 ?>
1218 <tr>
1219 <td width="75" align="right"><label for="answer<?php echo $answer->id; ?>">Answer:</label></td>
1220 <td><input type="text" name="answer<?php echo $answer->id; ?>" id="answer<?php echo $answer->id; ?>" size="40" value="<?php echo htmlentities(stripslashes($answer->answer)); ?>" />
1221 &nbsp; <input type="checkbox" name="deleteAnswer<?php echo $answer->id; ?>" id="deleteAnswer<?php echo $answer->id; ?>" value="Y" /><label for="deleteAnswer<?php echo $answer->id; ?>">Delete</label></td>
1222 </tr>
1223 <?php
1224 }
1225 }
1226 }
1227 ?>
1228 </table>
1229 </td>
1230 </tr>
1231 <tr id="attendeesArea">
1232 <th scope="row"><label for="attendees">Attendees allowed to answer this question:</label></th>
1233 <td>
1234 <select name="attendees[]" id="attendees" style="height:75px;" multiple="multiple">
1235 <?php
1236 $attendees = $wpdb->get_results("SELECT id, firstName, lastName FROM ".$wpdb->prefix."attendees ORDER BY lastName, firstName");
1237 foreach($attendees as $a) {
1238 ?>
1239 <option value="<?php echo $a->id; ?>"
1240 <?php echo ((in_array($a->id, $savedAttendees)) ? " selected=\"selected\"" : ""); ?>><?php echo htmlentities(stripslashes($a->firstName)." ".stripslashes($a->lastName)); ?></option>
1241 <?php
1242 }
1243 ?>
1244 </select>
1245 </td>
1246 </tr>
1247 </table>
1248 </form>
1249 <?php
1250 }
1251 }
1252
1253 function rsvp_modify_menu() {
1254
1255 add_options_page('RSVP Options', //page title
1256 'RSVP Options', //subpage title
1257 'manage_options', //access
1258 'rsvp-options', //current file
1259 'rsvp_admin_guestlist_options' //options function above
1260 );
1261 $page = add_menu_page("RSVP Plugin",
1262 "RSVP Plugin",
1263 "publish_posts",
1264 "rsvp-top-level",
1265 "rsvp_admin_guestlist");
1266 add_action('admin_print_scripts-' . $page, 'rsvp_admin_scripts');
1267 $page = add_submenu_page("rsvp-top-level",
1268 "Add Guest",
1269 "Add Guest",
1270 "publish_posts",
1271 "rsvp-admin-guest",
1272 "rsvp_admin_guest");
1273 add_action('admin_print_scripts-' . $page, 'rsvp_admin_scripts');
1274 add_submenu_page("rsvp-top-level",
1275 "RSVP Export",
1276 "RSVP Export",
1277 "publish_posts",
1278 "rsvp-admin-export",
1279 "rsvp_admin_export");
1280 add_submenu_page("rsvp-top-level",
1281 "RSVP Import",
1282 "RSVP Import",
1283 "publish_posts",
1284 "rsvp-admin-import",
1285 "rsvp_admin_import");
1286 $page = add_submenu_page("rsvp-top-level",
1287 "Custom Questions",
1288 "Custom Questions",
1289 "publish_posts",
1290 "rsvp-admin-questions",
1291 "rsvp_admin_questions");
1292 add_action('admin_print_scripts-' . $page, 'rsvp_admin_scripts');
1293 $page = add_submenu_page("rsvp-top-level",
1294 "Add Custom Question",
1295 "Add Custom Question",
1296 "publish_posts",
1297 "rsvp-admin-custom-question",
1298 "rsvp_admin_custom_question");
1299
1300 add_action('admin_print_scripts-' . $page, 'rsvp_admin_scripts');
1301 }
1302
1303 function rsvp_register_settings() {
1304 register_setting('rsvp-option-group', OPTION_OPENDATE);
1305 register_setting('rsvp-option-group', OPTION_GREETING);
1306 register_setting('rsvp-option-group', OPTION_THANKYOU);
1307 register_setting('rsvp-option-group', OPTION_HIDE_VEGGIE);
1308 register_setting('rsvp-option-group', OPTION_HIDE_KIDS_MEAL);
1309 register_setting('rsvp-option-group', OPTION_NOTE_VERBIAGE);
1310 register_setting('rsvp-option-group', OPTION_VEGGIE_MEAL_VERBIAGE);
1311 register_setting('rsvp-option-group', OPTION_KIDS_MEAL_VERBIAGE);
1312 register_setting('rsvp-option-group', OPTION_YES_VERBIAGE);
1313 register_setting('rsvp-option-group', OPTION_NO_VERBIAGE);
1314 register_setting('rsvp-option-group', OPTION_DEADLINE);
1315 register_setting('rsvp-option-group', OPTION_THANKYOU);
1316 register_setting('rsvp-option-group', OPTION_HIDE_ADD_ADDITIONAL);
1317 register_setting('rsvp-option-group', OPTION_NOTIFY_EMAIL);
1318 register_setting('rsvp-option-group', OPTION_NOTIFY_ON_RSVP);
1319 register_setting('rsvp-option-group', OPTION_DEBUG_RSVP_QUERIES);
1320 register_setting('rsvp-option-group', OPTION_WELCOME_TEXT);
1321 register_setting('rsvp-option-group', OPTION_RSVP_QUESTION);
1322 register_setting('rsvp-option-group', OPTION_RSVP_CUSTOM_YES_NO);
1323 register_setting('rsvp-option-group', OPTION_RSVP_PASSCODE);
1324 register_setting('rsvp-option-group', RSVP_OPTION_HIDE_NOTE);
1325 register_setting('rsvp-option-group', OPTION_RSVP_OPEN_REGISTRATION);
1326
1327 wp_register_script('jquery_table_sort', plugins_url('jquery.tablednd_0_5.js',__FILE__));
1328 wp_register_script('jquery_ui', rsvp_getHttpProtocol()."://ajax.microsoft.com/ajax/jquery.ui/1.8.5/jquery-ui.js");
1329 wp_register_style('jquery_ui_stylesheet', rsvp_getHttpProtocol()."://ajax.microsoft.com/ajax/jquery.ui/1.8.5/themes/redmond/jquery-ui.css");
1330 }
1331
1332 function rsvp_admin_scripts() {
1333 wp_enqueue_script("jquery_table_sort");
1334 wp_enqueue_script("jquery_ui");
1335 wp_enqueue_style( 'jquery_ui_stylesheet');
1336 }
1337
1338 function rsvp_init() {
1339 wp_register_script('jquery_validate', rsvp_getHttpProtocol()."://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js");
1340 wp_register_script('rsvp_plugin', plugins_url("rsvp_plugin.js", RSVP_PLUGIN_FILE));
1341 wp_register_style('rsvp_css', plugins_url("rsvp_plugin.css", RSVP_PLUGIN_FILE));
1342 wp_enqueue_script('jquery');
1343 wp_enqueue_script('jquery_validate');
1344 wp_enqueue_script('rsvp_plugin');
1345 wp_enqueue_style("rsvp_css");
1346
1347
1348 load_plugin_textdomain('rsvp-plugin', false, basename( dirname( __FILE__ ) ) . '/languages' );
1349 }
1350
1351 function rsvp_printQueryDebugInfo() {
1352 global $wpdb;
1353
1354 if(get_option(OPTION_DEBUG_RSVP_QUERIES) == "Y") {
1355 echo "<br />Sql Output: ";
1356 $wpdb->print_error();
1357 echo "<br />";
1358 }
1359 }
1360
1361 /*
1362 This function checks to see if the page is running over SSL/HTTPs and will return the proper HTTP protocol.
1363
1364 Postcondition: The caller will receive the proper HTTP protocol to use at the beginning of a URL.
1365 */
1366 function rsvp_getHttpProtocol() {
1367 if(isset($_SERVER['HTTPS']) && (trim($_SERVER['HTTPS']) != "")) {
1368 return "https";
1369 }
1370 return "http";
1371 }
1372
1373 function rsvp_getCurrentPageURL() {
1374 $pageURL = rsvp_getHttpProtocol();
1375
1376 $pageURL .= "://";
1377 if ($_SERVER["SERVER_PORT"] != "80") {
1378 $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
1379 } else {
1380 $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
1381 }
1382 return $pageURL;
1383 }
1384
1385 add_action('admin_menu', 'rsvp_modify_menu');
1386 add_action('admin_init', 'rsvp_register_settings');
1387 add_action('init', 'rsvp_init');
1388 add_filter('the_content', 'rsvp_frontend_handler');
1389 register_activation_hook(__FILE__,'rsvp_database_setup');
1390 ?>
1391