PluginProbe
RSVP and Event Management / 1.7.4
RSVP and Event Management v1.7.4
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.4, at wp-rsvp.php

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