PluginProbe
RSVP and Event Management / 1.7.5
RSVP and Event Management v1.7.5
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.5, at wp-rsvp.php

1,476 lines 66.3 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.5
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.5
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 $skipFirstRow = false;
655 if($data->sheets[0]['numCols'] >= 6) {
656 // Associating private questions... have to skip the first row
657 $skipFirstRow = true;
658 }
659 if($data->sheets[0]['numCols'] >= 2) {
660 $count = 0;
661 $i = ($skipFirstRow) ? 2 : 1;
662 for ($i; $i <= $data->sheets[0]['numRows']; $i++) {
663 $fName = trim($data->sheets[0]['cells'][$i][1]);
664 $lName = trim($data->sheets[0]['cells'][$i][2]);
665 $personalGreeting = (isset($data->sheets[0]['cells'][$i][4])) ? $personalGreeting = $data->sheets[0]['cells'][$i][4] : "";
666 $passcode = (isset($data->sheets[0]['cells'][$i][5])) ? $data->sheets[0]['cells'][$i][5] : "";
667 if(!empty($fName) && !empty($lName)) {
668 $sql = "SELECT id FROM ".ATTENDEES_TABLE."
669 WHERE firstName = %s AND lastName = %s ";
670 $res = $wpdb->get_results($wpdb->prepare($sql, $fName, $lName));
671 if(count($res) == 0) {
672 $wpdb->insert(ATTENDEES_TABLE, array("firstName" => $fName,
673 "lastName" => $lName,
674 "personalGreeting" => $personalGreeting,
675 "passcode" => $passcode),
676 array('%s', '%s', '%s', '%s'));
677 $count++;
678 }
679 }
680 }
681
682 if($data->sheets[0]['numCols'] >= 3) {
683 // There must be associated users so let's associate them
684 $i = ($skipFirstRow) ? 2 : 1;
685 for ($i; $i <= $data->sheets[0]['numRows']; $i++) {
686 $fName = trim($data->sheets[0]['cells'][$i][1]);
687 $lName = trim($data->sheets[0]['cells'][$i][2]);
688 if(!empty($fName) && !empty($lName) && (count($data->sheets[0]['cells'][$i]) >= 3)) {
689 // Get the user's id
690 $sql = "SELECT id FROM ".ATTENDEES_TABLE."
691 WHERE firstName = %s AND lastName = %s ";
692 $res = $wpdb->get_results($wpdb->prepare($sql, $fName, $lName));
693 if((count($res) > 0) && isset($data->sheets[0]['cells'][$i][3])) {
694 $userId = $res[0]->id;
695
696 // Deal with the assocaited users...
697 $associatedUsers = explode(",", trim($data->sheets[0]['cells'][$i][3]));
698 if(is_array($associatedUsers)) {
699 foreach($associatedUsers as $au) {
700 $user = explode(" ", trim($au), 2);
701 // Three cases, they didn't enter in all of the information, user exists or doesn't.
702 // If user exists associate the two users
703 // If user does not exist add the user and then associate the two
704 if(is_array($user) && (count($user) == 2)) {
705 $sql = "SELECT id FROM ".ATTENDEES_TABLE."
706 WHERE firstName = %s AND lastName = %s ";
707 $userRes = $wpdb->get_results($wpdb->prepare($sql, trim($user[0]), trim($user[1])));
708 if(count($userRes) > 0) {
709 $newUserId = $userRes[0]->id;
710 } else {
711 // Insert them and then we can associate them...
712 $wpdb->insert(ATTENDEES_TABLE, array("firstName" => trim($user[0]), "lastName" => trim($user[1])), array('%s', '%s'));
713 $newUserId = $wpdb->insert_id;
714 $count++;
715 }
716
717 $wpdb->insert(ASSOCIATED_ATTENDEES_TABLE, array("attendeeID" => $newUserId,
718 "associatedAttendeeID" => $userId),
719 array("%d", "%d"));
720
721 $wpdb->insert(ASSOCIATED_ATTENDEES_TABLE, array("attendeeID" => $userId,
722 "associatedAttendeeID" => $newUserId),
723 array("%d", "%d"));
724 }
725 }
726 }
727 }
728 }
729 }
730 } // if($data->sheets[0]['numCols'] >= 3)...
731
732 if($data->sheets[0]['numCols'] >= 6) {
733 $private_questions = array();
734 for($qid = 6; $qid <= $data->sheets[0]['numCols']; $qid++) {
735 $pqid = str_replace("pq_", "", $data->sheets[0]['cells'][1][$qid]);
736 if(is_numeric($pqid)) {
737 $private_questions[$qid] = $pqid;
738 }
739 }
740 if(count($private_questions) > 0) {
741 for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) {
742 $fName = trim($data->sheets[0]['cells'][$i][1]);
743 $lName = trim($data->sheets[0]['cells'][$i][2]);
744 if(!empty($fName) && !empty($lName)) {
745 // Get the user's id
746 $sql = "SELECT id FROM ".ATTENDEES_TABLE."
747 WHERE firstName = %s AND lastName = %s ";
748 $res = $wpdb->get_results($wpdb->prepare($sql, $fName, $lName));
749 if(count($res) > 0) {
750 $userId = $res[0]->id;
751 foreach($private_questions as $key => $val) {
752 if(strToUpper($data->sheets[0]['cells'][$i][$key]) == "Y") {
753 $wpdb->insert(QUESTION_ATTENDEES_TABLE, array("attendeeID" => $userId,
754 "questionID" => $val),
755 array("%d", "%d"));
756 }
757 }
758 }
759 }
760 }
761 } // if(count($priv...))
762 } // if($data->sheets[0]['numCols'] >= 6)....
763 ?>
764 <p><strong><?php echo $count; ?></strong> total records were imported.</p>
765 <p>Continue to the RSVP <a href="admin.php?page=rsvp-top-level">list</a></p>
766 <?php
767 }
768 } else {
769 ?>
770 <form name="rsvp_import" method="post" enctype="multipart/form-data">
771 <?php wp_nonce_field('rsvp-import'); ?>
772 <p>Select an excel file (only xls please, xlsx is not supported....yet) in the following format:<br />
773 <strong>First Name</strong> | <strong>Last Name</strong> | <strong>Associated Attendees*</strong> | <strong>Custom Message</strong> | <strong>Passcode</strong> | <strong>Private Question Association**</strong>
774 </p>
775 <p>
776 * associated attendees should be separated by a comma it is assumed that the first space encountered will separate the first and last name.
777 </p>
778 <p>
779 ** This can be multiple columns each column is associated with one of the following private questions. If you wish
780 to have the guest associated with the question put a &quot;Y&quot; in the column otherwise put whatever else you want. The header name will be the &quot;private import key&quot; which is also listed below. It has the format of pq_* where * is a number.
781 <ul>
782 <?php
783 $questions = $wpdb->get_results("SELECT id, question FROM ".QUESTIONS_TABLE." WHERE permissionLevel = 'private'");
784 foreach($questions as $q) {
785 ?>
786 <li><?php echo htmlspecialchars(stripslashes($q->question)); ?> - pq_<?php echo $q->id; ?></li>
787 <?php
788 }
789 ?>
790 </ul>
791 </p>
792 <p>A header row is not expected, UNLESS you are associating private questions.</p>
793 <p><input type="file" name="importFile" id="importFile" /></p>
794 <p><input type="submit" value="Import File" name="goRsvp" /></p>
795 </form>
796 <?php
797 }
798 }
799
800 function rsvp_admin_guest() {
801 global $wpdb;
802 if((count($_POST) > 0) && !empty($_POST['firstName']) && !empty($_POST['lastName'])) {
803 check_admin_referer('rsvp_add_guest');
804 $passcode = (isset($_POST['passcode'])) ? $_POST['passcode'] : "";
805
806 if(isset($_SESSION[EDIT_SESSION_KEY]) && is_numeric($_SESSION[EDIT_SESSION_KEY])) {
807 $wpdb->update(ATTENDEES_TABLE,
808 array("firstName" => trim($_POST['firstName']),
809 "lastName" => trim($_POST['lastName']),
810 "personalGreeting" => trim($_POST['personalGreeting']),
811 "rsvpStatus" => trim($_POST['rsvpStatus'])),
812 array("id" => $_SESSION[EDIT_SESSION_KEY]),
813 array("%s", "%s", "%s", "%s"),
814 array("%d"));
815 rsvp_printQueryDebugInfo();
816 $attendeeId = $_SESSION[EDIT_SESSION_KEY];
817 $wpdb->query($wpdb->prepare("DELETE FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeId = %d", $attendeeId));
818 } else {
819 $wpdb->insert(ATTENDEES_TABLE, array("firstName" => trim($_POST['firstName']),
820 "lastName" => trim($_POST['lastName']),
821 "personalGreeting" => trim($_POST['personalGreeting']),
822 "rsvpStatus" => trim($_POST['rsvpStatus'])),
823 array('%s', '%s', '%s', '%s'));
824 rsvp_printQueryDebugInfo();
825
826 $attendeeId = $wpdb->insert_id;
827 }
828
829 if(isset($_POST['associatedAttendees']) && is_array($_POST['associatedAttendees'])) {
830 foreach($_POST['associatedAttendees'] as $aid) {
831 if(is_numeric($aid) && ($aid > 0)) {
832 $wpdb->insert(ASSOCIATED_ATTENDEES_TABLE, array("attendeeID"=>$attendeeId, "associatedAttendeeID"=>$aid), array("%d", "%d"));
833 rsvp_printQueryDebugInfo();
834 }
835 }
836 }
837
838 if(rsvp_require_passcode()) {
839 if(empty($passcode)) {
840 $passcode = rsvp_generate_passcode();
841 }
842 $wpdb->update(ATTENDEES_TABLE,
843 array("passcode" => trim($passcode)),
844 array("id"=>$attendeeId),
845 array("%s"),
846 array("%d"));
847 }
848 ?>
849 <p>Attendee <?php echo htmlspecialchars(stripslashes($_POST['firstName']." ".$_POST['lastName']));?> has been successfully saved</p>
850 <p>
851 <a href="<?php echo get_option('siteurl'); ?>/wp-admin/admin.php?page=rsvp-top-level">Continue to Attendee List</a> |
852 <a href="<?php echo get_option('siteurl'); ?>/wp-admin/admin.php?page=rsvp-admin-guest">Add a Guest</a>
853 </p>
854 <?php
855 } else {
856 $attendee = null;
857 unset($_SESSION[EDIT_SESSION_KEY]);
858 $associatedAttendees = array();
859 $firstName = "";
860 $lastName = "";
861 $personalGreeting = "";
862 $rsvpStatus = "NoResponse";
863 $passcode = "";
864
865 if(isset($_GET['id']) && is_numeric($_GET['id'])) {
866 $attendee = $wpdb->get_row("SELECT id, firstName, lastName, personalGreeting, rsvpStatus, passcode FROM ".ATTENDEES_TABLE." WHERE id = ".$_GET['id']);
867 if($attendee != null) {
868 $_SESSION[EDIT_SESSION_KEY] = $attendee->id;
869 $firstName = stripslashes($attendee->firstName);
870 $lastName = stripslashes($attendee->lastName);
871 $personalGreeting = stripslashes($attendee->personalGreeting);
872 $rsvpStatus = $attendee->rsvpStatus;
873 $passcode = stripslashes($attendee->passcode);
874
875 // Get the associated attendees and add them to an array
876 $associations = $wpdb->get_results("SELECT associatedAttendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeId = ".$attendee->id.
877 " UNION ".
878 "SELECT attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE associatedAttendeeID = ".$attendee->id);
879 foreach($associations as $aId) {
880 $associatedAttendees[] = $aId->associatedAttendeeID;
881 }
882 }
883 }
884 ?>
885 <form name="contact" action="admin.php?page=rsvp-admin-guest" method="post">
886 <?php wp_nonce_field('rsvp_add_guest'); ?>
887 <p class="submit">
888 <input type="submit" class="button-primary" value="<?php _e('Save'); ?>" />
889 </p>
890 <table class="form-table">
891 <tr valign="top">
892 <th scope="row"><label for="firstName"><?php echo __("First Name", 'rsvp-plugin'); ?>:</label></th>
893 <td align="left"><input type="text" name="firstName" id="firstName" size="30" value="<?php echo htmlspecialchars($firstName); ?>" /></td>
894 </tr>
895 <tr valign="top">
896 <th scope="row"><label for="lastName"><?php echo __("Last Name", 'rsvp-plugin'); ?>:</label></th>
897 <td align="left"><input type="text" name="lastName" id="lastName" size="30" value="<?php echo htmlspecialchars($lastName); ?>" /></td>
898 </tr>
899 <?php
900 if(rsvp_require_passcode()) {
901 ?>
902 <tr valign="top">
903 <th scope="row"><label for="passcode">Passcode:</label></th>
904 <td align="left"><input type="text" name="passcode" id="passcode" size="30" value="<?php echo htmlspecialchars($passcode); ?>" maxlength="6" /></td>
905 </tr>
906 <?php
907 }
908 ?>
909 <tr>
910 <th scope="row"><label for="rsvpStatus">RSVP Status</label></th>
911 <td align="left">
912 <select name="rsvpStatus" id="rsvpStatus" size="1">
913 <option value="NoResponse" <?php
914 echo (($rsvpStatus == "NoResponse") ? " selected=\"selected\"" : "");
915 ?>>No Response</option>
916 <option value="Yes" <?php
917 echo (($rsvpStatus == "Yes") ? " selected=\"selected\"" : "");
918 ?>>Yes</option>
919 <option value="No" <?php
920 echo (($rsvpStatus == "No") ? " selected=\"selected\"" : "");
921 ?>>No</option>
922 </select>
923 </td>
924 </tr>
925 <tr valign="top">
926 <th scope="row" valign="top"><label for="personalGreeting">Custom Message:</label></th>
927 <td align="left"><textarea name="personalGreeting" id="personalGreeting" rows="5" cols="40"><?php echo htmlspecialchars($personalGreeting); ?></textarea></td>
928 </tr>
929 <tr valign="top">
930 <th scope="row">Associated Attendees:</th>
931 <td align="left">
932 <select name="associatedAttendees[]" multiple="multiple" size="5" style="height: 200px;">
933 <?php
934 $attendees = $wpdb->get_results("SELECT id, firstName, lastName FROM ".$wpdb->prefix."attendees ORDER BY lastName, firstName");
935 foreach($attendees as $a) {
936 if($a->id != $_SESSION[EDIT_SESSION_KEY]) {
937 ?>
938 <option value="<?php echo $a->id; ?>"
939 <?php echo ((in_array($a->id, $associatedAttendees)) ? "selected=\"selected\"" : ""); ?>><?php echo htmlspecialchars(stripslashes($a->firstName)." ".stripslashes($a->lastName)); ?></option>
940 <?php
941 }
942 }
943 ?>
944 </select>
945 </td>
946 </tr>
947 <?php
948 if(($attendee != null) && ($attendee->id > 0)) {
949 $sql = "SELECT question, answer FROM ".ATTENDEE_ANSWERS." ans
950 INNER JOIN ".QUESTIONS_TABLE." q ON q.id = ans.questionID
951 WHERE attendeeID = %d
952 ORDER BY q.sortOrder";
953 $aRs = $wpdb->get_results($wpdb->prepare($sql, $attendee->id));
954 if(count($aRs) > 0) {
955 ?>
956 <tr>
957 <td colspan="2">
958 <h4>Custom Questions Answered</h4>
959 <table cellpadding="2" cellspacing="0" border="0">
960 <tr>
961 <th>Question</th>
962 <th>Answer</th>
963 </tr>
964 <?php
965 foreach($aRs as $a) {
966 ?>
967 <tr>
968 <td><?php echo stripslashes($a->question); ?></td>
969 <td><?php echo stripslashes($a->answer); ?></td>
970 </tr>
971 <?php
972 }
973 ?>
974 </table>
975 </td>
976 </tr>
977 <?php
978 }
979 }
980 ?>
981 </table>
982 <p class="submit">
983 <input type="submit" class="button-primary" value="<?php _e('Save'); ?>" />
984 </p>
985 </form>
986 <?php
987 }
988 }
989
990 function rsvp_admin_questions() {
991 global $wpdb;
992
993 if((count($_POST) > 0) && ($_POST['rsvp-bulk-action'] == "delete") && (is_array($_POST['q']) && (count($_POST['q']) > 0))) {
994 foreach($_POST['q'] as $q) {
995 if(is_numeric($q) && ($q > 0)) {
996 $wpdb->query($wpdb->prepare("DELETE FROM ".QUESTIONS_TABLE." WHERE id = %d", $q));
997 $wpdb->query($wpdb->prepare("DELETE FROM ".ATTENDEE_ANSWERS." WHERE questionID = %d", $q));
998 }
999 }
1000 } else if((count($_POST) > 0) && ($_POST['rsvp-bulk-action'] == "saveSortOrder")) {
1001 $sql = "SELECT id FROM ".QUESTIONS_TABLE;
1002 $sortQs = $wpdb->get_results($sql);
1003 foreach($sortQs as $q) {
1004 if(is_numeric($_POST['sortOrder'.$q->id]) && ($_POST['sortOrder'.$q->id] >= 0)) {
1005 $wpdb->update(QUESTIONS_TABLE,
1006 array("sortOrder" => $_POST['sortOrder'.$q->id]),
1007 array("id" => $q->id),
1008 array("%d"),
1009 array("%d"));
1010 rsvp_printQueryDebugInfo();
1011 }
1012 }
1013 }
1014
1015 $sql = "SELECT id, question, sortOrder, permissionLevel FROM ".QUESTIONS_TABLE." ORDER BY sortOrder ASC";
1016 $customQs = $wpdb->get_results($sql);
1017 ?>
1018 <script type="text/javascript" language="javascript">
1019 jQuery(document).ready(function() {
1020 jQuery("#cb").click(function() {
1021 if(jQuery("#cb").attr("checked")) {
1022 jQuery("input[name='q[]']").attr("checked", "checked");
1023 } else {
1024 jQuery("input[name='q[]']").removeAttr("checked");
1025 }
1026 });
1027
1028 jQuery("#customQuestions").tableDnD({
1029 onDrop: function(table, row) {
1030 var rows = table.tBodies[0].rows;
1031 for (var i=0; i<rows.length; i++) {
1032 jQuery("#sortOrder" + rows[i].id).val(i);
1033 }
1034
1035 }
1036 });
1037 });
1038 </script>
1039 <div class="wrap">
1040 <div id="icon-edit" class="icon32"><br /></div>
1041 <h2>List of current custom questions</h2>
1042 <form method="post" id="rsvp-form" enctype="multipart/form-data">
1043 <input type="hidden" id="rsvp-bulk-action" name="rsvp-bulk-action" />
1044 <div class="tablenav">
1045 <div class="alignleft actions">
1046 <select id="rsvp-action-top" name="action">
1047 <option value="" selected="selected"><?php _e('Bulk Actions', 'rsvp'); ?></option>
1048 <option value="delete"><?php _e('Delete', 'rsvp'); ?></option>
1049 </select>
1050 <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;" />
1051 <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';" />
1052 </div>
1053 <div class="clear"></div>
1054 </div>
1055 <table class="widefat post fixed" cellspacing="0">
1056 <thead>
1057 <tr>
1058 <th scope="col" class="manage-column column-cb check-column" style=""><input type="checkbox" id="cb" /></th>
1059 <th scope="col" id="questionCol" class="manage-column column-title" style="">Question</th>
1060 <th scope="col" class="manage-column column-title">Private Import Key</th>
1061 </tr>
1062 </thead>
1063 </table>
1064 <div style="overflow: auto;height: 450px;">
1065 <table class="widefat post fixed" cellspacing="0" id="customQuestions">
1066 <?php
1067 $i = 0;
1068 foreach($customQs as $q) {
1069 ?>
1070 <tr class="<?php echo (($i % 2 == 0) ? "alternate" : ""); ?> author-self" id="<?php echo $q->id; ?>">
1071 <th scope="row" class="check-column"><input type="checkbox" name="q[]" value="<?php echo $q->id; ?>" /></th>
1072 <td>
1073 <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>
1074 <input type="hidden" name="sortOrder<?php echo $q->id; ?>" id="sortOrder<?php echo $q->id; ?>" value="<?php echo $q->sortOrder; ?>" />
1075 </td>
1076 <td><?php
1077 if($q->permissionLevel == "private") {
1078 ?>
1079 pq_<?php echo $q->id; ?>
1080 <?php
1081 }
1082 ?></td>
1083 </tr>
1084 <?php
1085 $i++;
1086 }
1087 ?>
1088 </table>
1089 </div>
1090 </form>
1091 </div>
1092 <?php
1093 }
1094
1095 function rsvp_admin_custom_question() {
1096 global $wpdb;
1097 $answerQuestionTypes = array(2,4,5);
1098
1099 $radioQuestionType = $wpdb->get_results("SELECT id FROM ".QUESTION_TYPE_TABLE." WHERE questionType = 'radio'");
1100 if($radioQuestionType == 0) {
1101 $wpdb->insert(QUESTION_TYPE_TABLE, array("questionType" => "radio", "friendlyName" => "Radio"), array('%s', '%s'));
1102 rsvp_printQueryDebugInfo();
1103 }
1104
1105 if((count($_POST) > 0) && !empty($_POST['question']) && is_numeric($_POST['questionTypeID'])) {
1106 check_admin_referer('rsvp_add_custom_question');
1107 if(isset($_SESSION[EDIT_QUESTION_KEY]) && is_numeric($_SESSION[EDIT_QUESTION_KEY])) {
1108 $wpdb->update(QUESTIONS_TABLE,
1109 array("question" => trim($_POST['question']),
1110 "questionTypeID" => trim($_POST['questionTypeID']),
1111 "permissionLevel" => ((trim($_POST['permissionLevel']) == "private") ? "private" : "public")),
1112 array("id" => $_SESSION[EDIT_QUESTION_KEY]),
1113 array("%s", "%d", "%s"),
1114 array("%d"));
1115 rsvp_printQueryDebugInfo();
1116 $questionId = $_SESSION[EDIT_QUESTION_KEY];
1117
1118 $answers = $wpdb->get_results($wpdb->prepare("SELECT id FROM ".QUESTION_ANSWERS_TABLE." WHERE questionID = %d", $questionId));
1119 if(count($answers) > 0) {
1120 foreach($answers as $a) {
1121 if(isset($_POST['deleteAnswer'.$a->id]) && (strToUpper($_POST['deleteAnswer'.$a->id]) == "Y")) {
1122 $wpdb->query($wpdb->prepare("DELETE FROM ".QUESTION_ANSWERS_TABLE." WHERE id = %d", $a->id));
1123 } elseif(isset($_POST['answer'.$a->id]) && !empty($_POST['answer'.$a->id])) {
1124 $wpdb->update(QUESTION_ANSWERS_TABLE,
1125 array("answer" => trim($_POST['answer'.$a->id])),
1126 array("id"=>$a->id),
1127 array("%s"),
1128 array("%d"));
1129 rsvp_printQueryDebugInfo();
1130 }
1131 }
1132 }
1133 } else {
1134 $wpdb->insert(QUESTIONS_TABLE, array("question" => trim($_POST['question']),
1135 "questionTypeID" => trim($_POST['questionTypeID']),
1136 "permissionLevel" => ((trim($_POST['permissionLevel']) == "private") ? "private" : "public")),
1137 array('%s', '%d', '%s'));
1138 rsvp_printQueryDebugInfo();
1139 $questionId = $wpdb->insert_id;
1140 }
1141
1142 if(isset($_POST['numNewAnswers']) && is_numeric($_POST['numNewAnswers']) &&
1143 in_array($_POST['questionTypeID'], $answerQuestionTypes)) {
1144 for($i = 0; $i < $_POST['numNewAnswers']; $i++) {
1145 if(isset($_POST['newAnswer'.$i]) && !empty($_POST['newAnswer'.$i])) {
1146 $wpdb->insert(QUESTION_ANSWERS_TABLE, array("questionID"=>$questionId, "answer"=>$_POST['newAnswer'.$i]));
1147 rsvp_printQueryDebugInfo();
1148 }
1149 }
1150 }
1151
1152 if(strToLower(trim($_POST['permissionLevel'])) == "private") {
1153 $wpdb->query($wpdb->prepare("DELETE FROM ".QUESTION_ATTENDEES_TABLE." WHERE questionID = %d", $questionId));
1154 if(isset($_POST['attendees']) && is_array($_POST['attendees'])) {
1155 foreach($_POST['attendees'] as $aid) {
1156 if(is_numeric($aid) && ($aid > 0)) {
1157 $wpdb->insert(QUESTION_ATTENDEES_TABLE, array("attendeeID"=>$aid, "questionID"=>$questionId), array("%d", "%d"));
1158 rsvp_printQueryDebugInfo();
1159 }
1160 }
1161 }
1162 }
1163 ?>
1164 <p>Custom Question saved</p>
1165 <p>
1166 <a href="<?php echo get_option('siteurl'); ?>/wp-admin/admin.php?page=rsvp-admin-questions">Continue to Question List</a> |
1167 <a href="<?php echo get_option('siteurl'); ?>/wp-admin/admin.php?page=rsvp-admin-custom-question">Add another Question</a>
1168 </p>
1169 <?php
1170 } else {
1171 $questionTypeId = 0;
1172 $question = "";
1173 $isNew = true;
1174 $questionId = 0;
1175 $permissionLevel = "public";
1176 $savedAttendees = array();
1177 unset($_SESSION[EDIT_QUESTION_KEY]);
1178 if(isset($_GET['id']) && is_numeric($_GET['id'])) {
1179 $qRs = $wpdb->get_results($wpdb->prepare("SELECT id, question, questionTypeID, permissionLevel FROM ".QUESTIONS_TABLE." WHERE id = %d", $_GET['id']));
1180 if(count($qRs) > 0) {
1181 $isNew = false;
1182 $_SESSION[EDIT_QUESTION_KEY] = $qRs[0]->id;
1183 $questionId = $qRs[0]->id;
1184 $question = stripslashes($qRs[0]->question);
1185 $permissionLevel = stripslashes($qRs[0]->permissionLevel);
1186 $questionTypeId = $qRs[0]->questionTypeID;
1187
1188 if($permissionLevel == "private") {
1189 $aRs = $wpdb->get_results($wpdb->prepare("SELECT attendeeID FROM ".QUESTION_ATTENDEES_TABLE." WHERE questionID = %d", $questionId));
1190 if(count($aRs) > 0) {
1191 foreach($aRs as $a) {
1192 $savedAttendees[] = $a->attendeeID;
1193 }
1194 }
1195 }
1196 }
1197 }
1198
1199 $sql = "SELECT id, questionType, friendlyName FROM ".QUESTION_TYPE_TABLE;
1200 $questionTypes = $wpdb->get_results($sql);
1201 ?>
1202 <script type="text/javascript">
1203 function addAnswer(counterElement) {
1204 var currAnswer = jQuery("#numNewAnswers").val();
1205 if(isNaN(currAnswer)) {
1206 currAnswer = 0;
1207 }
1208
1209 var s = "<tr>\r\n"+
1210 "<td align=\"right\" width=\"75\"><label for=\"newAnswer" + currAnswer + "\">Answer:</label></td>\r\n" +
1211 "<td><input type=\"text\" name=\"newAnswer" + currAnswer + "\" id=\"newAnswer" + currAnswer + "\" size=\"40\" /></td>\r\n" +
1212 "</tr>\r\n";
1213 jQuery("#answerContainer").append(s);
1214 currAnswer++;
1215 jQuery("#numNewAnswers").val(currAnswer);
1216 return false;
1217 }
1218
1219 jQuery(document).ready(function() {
1220
1221 <?php
1222 if($isNew || !in_array($questionTypeId, $answerQuestionTypes)) {
1223 echo 'jQuery("#answerContainer").hide();';
1224 }
1225
1226 if($isNew || ($permissionLevel == "public")) {
1227 ?>
1228 jQuery("#attendeesArea").hide();
1229 <?php
1230 }
1231 ?>
1232 jQuery("#questionType").change(function() {
1233 var selectedValue = jQuery("#questionType").val();
1234 if((selectedValue == 2) || (selectedValue == 4) || (selectedValue == 5)) {
1235 jQuery("#answerContainer").show();
1236 } else {
1237 jQuery("#answerContainer").hide();
1238 }
1239 })
1240
1241 jQuery("#permissionLevel").change(function() {
1242 if(jQuery("#permissionLevel").val() != "public") {
1243 jQuery("#attendeesArea").show();
1244 } else {
1245 jQuery("#attendeesArea").hide();
1246 }
1247 })
1248 });
1249 </script>
1250 <form name="contact" action="admin.php?page=rsvp-admin-custom-question" method="post">
1251 <input type="hidden" name="numNewAnswers" id="numNewAnswers" value="0" />
1252 <?php wp_nonce_field('rsvp_add_custom_question'); ?>
1253 <p class="submit">
1254 <input type="submit" class="button-primary" value="<?php _e('Save'); ?>" />
1255 </p>
1256 <table id="customQuestions" class="form-table">
1257 <tr valign="top">
1258 <th scope="row"><label for="questionType">Question Type:</label></th>
1259 <td align="left"><select name="questionTypeID" id="questionType" size="1">
1260 <?php
1261 foreach($questionTypes as $qt) {
1262 echo "<option value=\"".$qt->id."\" ".(($questionTypeId == $qt->id) ? " selected=\"selected\"" : "").">".$qt->friendlyName."</option>\r\n";
1263 }
1264 ?>
1265 </select>
1266 </td>
1267 </tr>
1268 <tr valign="top">
1269 <th scope="row"><label for="question">Question:</label></th>
1270 <td align="left"><input type="text" name="question" id="question" size="40" value="<?php echo htmlspecialchars($question); ?>" /></td>
1271 </tr>
1272 <tr>
1273 <th scope="row"><label for="permissionLevel">Question Permission Level:</label></th>
1274 <td align="left"><select name="permissionLevel" id="permissionLevel" size="1">
1275 <option value="public" <?php echo ($permissionLevel == "public") ? " selected=\"selected\"" : ""; ?>>Public</option>
1276 <option value="private" <?php echo ($permissionLevel == "private") ? " selected=\"selected\"" : ""; ?>>Private</option>
1277 </select></td>
1278 </tr>
1279 <?php if(!$isNew && ($permissionLevel == "private")): ?>
1280 <tr>
1281 <th scope="row">Private Import Key:</th>
1282 <td align="left">pq_<?php echo $questionId; ?></td>
1283 </tr>
1284 <?php endif;?>
1285 <tr>
1286 <td colspan="2">
1287 <table cellpadding="0" cellspacing="0" border="0" id="answerContainer">
1288 <tr>
1289 <th>Answers</th>
1290 <th align="right"><a href="#" onclick="return addAnswer();">Add new Answer</a></th>
1291 </tr>
1292 <?php
1293 if(!$isNew) {
1294 $aRs = $wpdb->get_results($wpdb->prepare("SELECT id, answer FROM ".QUESTION_ANSWERS_TABLE." WHERE questionID = %d", $questionId));
1295 if(count($aRs) > 0) {
1296 foreach($aRs as $answer) {
1297 ?>
1298 <tr>
1299 <td width="75" align="right"><label for="answer<?php echo $answer->id; ?>">Answer:</label></td>
1300 <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)); ?>" />
1301 &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>
1302 </tr>
1303 <?php
1304 }
1305 }
1306 }
1307 ?>
1308 </table>
1309 </td>
1310 </tr>
1311 <tr id="attendeesArea">
1312 <th scope="row"><label for="attendees">Attendees allowed to answer this question:</label></th>
1313 <td>
1314 <select name="attendees[]" id="attendees" style="height:75px;" multiple="multiple">
1315 <?php
1316 $attendees = $wpdb->get_results("SELECT id, firstName, lastName FROM ".$wpdb->prefix."attendees ORDER BY lastName, firstName");
1317 foreach($attendees as $a) {
1318 ?>
1319 <option value="<?php echo $a->id; ?>"
1320 <?php echo ((in_array($a->id, $savedAttendees)) ? " selected=\"selected\"" : ""); ?>><?php echo htmlspecialchars(stripslashes($a->firstName)." ".stripslashes($a->lastName)); ?></option>
1321 <?php
1322 }
1323 ?>
1324 </select>
1325 </td>
1326 </tr>
1327 </table>
1328 </form>
1329 <?php
1330 }
1331 }
1332
1333 function rsvp_modify_menu() {
1334
1335 $page = add_options_page('RSVP Options', //page title
1336 'RSVP Options', //subpage title
1337 'manage_options', //access
1338 'rsvp-options', //current file
1339 'rsvp_admin_guestlist_options' //options function above
1340 );
1341 add_action('admin_print_scripts-' . $page, 'rsvp_admin_scripts');
1342 $page = add_menu_page("RSVP Plugin",
1343 "RSVP Plugin",
1344 "publish_posts",
1345 "rsvp-top-level",
1346 "rsvp_admin_guestlist");
1347 add_action('admin_print_scripts-' . $page, 'rsvp_admin_scripts');
1348 $page = add_submenu_page("rsvp-top-level",
1349 "Add Guest",
1350 "Add Guest",
1351 "publish_posts",
1352 "rsvp-admin-guest",
1353 "rsvp_admin_guest");
1354 add_action('admin_print_scripts-' . $page, 'rsvp_admin_scripts');
1355 add_submenu_page("rsvp-top-level",
1356 "RSVP Export",
1357 "RSVP Export",
1358 "publish_posts",
1359 "rsvp-admin-export",
1360 "rsvp_admin_export");
1361 add_submenu_page("rsvp-top-level",
1362 "RSVP Import",
1363 "RSVP Import",
1364 "publish_posts",
1365 "rsvp-admin-import",
1366 "rsvp_admin_import");
1367 $page = add_submenu_page("rsvp-top-level",
1368 "Custom Questions",
1369 "Custom Questions",
1370 "publish_posts",
1371 "rsvp-admin-questions",
1372 "rsvp_admin_questions");
1373 add_action('admin_print_scripts-' . $page, 'rsvp_admin_scripts');
1374 $page = add_submenu_page("rsvp-top-level",
1375 "Add Custom Question",
1376 "Add Custom Question",
1377 "publish_posts",
1378 "rsvp-admin-custom-question",
1379 "rsvp_admin_custom_question");
1380
1381 add_action('admin_print_scripts-' . $page, 'rsvp_admin_scripts');
1382 }
1383
1384 function rsvp_register_settings() {
1385 register_setting('rsvp-option-group', OPTION_OPENDATE);
1386 register_setting('rsvp-option-group', OPTION_GREETING);
1387 register_setting('rsvp-option-group', OPTION_THANKYOU);
1388 register_setting('rsvp-option-group', OPTION_HIDE_VEGGIE);
1389 register_setting('rsvp-option-group', OPTION_HIDE_KIDS_MEAL);
1390 register_setting('rsvp-option-group', OPTION_NOTE_VERBIAGE);
1391 register_setting('rsvp-option-group', OPTION_VEGGIE_MEAL_VERBIAGE);
1392 register_setting('rsvp-option-group', OPTION_KIDS_MEAL_VERBIAGE);
1393 register_setting('rsvp-option-group', OPTION_YES_VERBIAGE);
1394 register_setting('rsvp-option-group', OPTION_NO_VERBIAGE);
1395 register_setting('rsvp-option-group', OPTION_DEADLINE);
1396 register_setting('rsvp-option-group', OPTION_THANKYOU);
1397 register_setting('rsvp-option-group', OPTION_HIDE_ADD_ADDITIONAL);
1398 register_setting('rsvp-option-group', OPTION_NOTIFY_EMAIL);
1399 register_setting('rsvp-option-group', OPTION_NOTIFY_ON_RSVP);
1400 register_setting('rsvp-option-group', OPTION_DEBUG_RSVP_QUERIES);
1401 register_setting('rsvp-option-group', OPTION_WELCOME_TEXT);
1402 register_setting('rsvp-option-group', OPTION_RSVP_QUESTION);
1403 register_setting('rsvp-option-group', OPTION_RSVP_CUSTOM_YES_NO);
1404 register_setting('rsvp-option-group', OPTION_RSVP_PASSCODE);
1405 register_setting('rsvp-option-group', RSVP_OPTION_HIDE_NOTE);
1406 register_setting('rsvp-option-group', OPTION_RSVP_OPEN_REGISTRATION);
1407 register_setting('rsvp-option-group', OPTION_RSVP_DONT_USE_HASH);
1408 register_setting('rsvp-option-group', OPTION_RSVP_ADD_ADDITIONAL_VERBIAGE);
1409
1410 wp_register_script('jquery_table_sort', plugins_url('jquery.tablednd_0_5.js',RSVP_PLUGIN_FILE));
1411 wp_register_script('jquery_ui', rsvp_getHttpProtocol()."://ajax.microsoft.com/ajax/jquery.ui/1.8.5/jquery-ui.js");
1412 wp_register_style('jquery_ui_stylesheet', rsvp_getHttpProtocol()."://ajax.microsoft.com/ajax/jquery.ui/1.8.5/themes/redmond/jquery-ui.css");
1413 }
1414
1415 function rsvp_admin_scripts() {
1416 wp_enqueue_script("jquery");
1417 //wp_enqueue_script("jquery_ui");
1418 wp_enqueue_script("jquery-ui-datepicker");
1419 wp_enqueue_script("jquery_table_sort");
1420 wp_enqueue_style( 'jquery_ui_stylesheet');
1421 }
1422
1423 function rsvp_init() {
1424 wp_register_script('jquery_validate', rsvp_getHttpProtocol()."://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js");
1425 wp_register_script('rsvp_plugin', plugins_url("rsvp_plugin.js", RSVP_PLUGIN_FILE));
1426 wp_register_style('rsvp_css', plugins_url("rsvp_plugin.css", RSVP_PLUGIN_FILE));
1427 wp_enqueue_script('jquery');
1428 wp_enqueue_script('jquery_validate');
1429 wp_enqueue_script('rsvp_plugin');
1430 wp_enqueue_style("rsvp_css");
1431
1432
1433 load_plugin_textdomain('rsvp-plugin', false, basename( dirname( __FILE__ ) ) . '/languages' );
1434 }
1435
1436 function rsvp_printQueryDebugInfo() {
1437 global $wpdb;
1438
1439 if(get_option(OPTION_DEBUG_RSVP_QUERIES) == "Y") {
1440 echo "<br />Sql Output: ";
1441 $wpdb->print_error();
1442 echo "<br />";
1443 }
1444 }
1445
1446 /*
1447 This function checks to see if the page is running over SSL/HTTPs and will return the proper HTTP protocol.
1448
1449 Postcondition: The caller will receive the proper HTTP protocol to use at the beginning of a URL.
1450 */
1451 function rsvp_getHttpProtocol() {
1452 if(isset($_SERVER['HTTPS']) && (trim($_SERVER['HTTPS']) != "") && (strtolower(trim($_SERVER['HTTPS'])) != "off")) {
1453 return "https";
1454 }
1455 return "http";
1456 }
1457
1458 function rsvp_getCurrentPageURL() {
1459 $pageURL = rsvp_getHttpProtocol();
1460
1461 $pageURL .= "://";
1462 if ($_SERVER["SERVER_PORT"] != "80") {
1463 $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
1464 } else {
1465 $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
1466 }
1467 return $pageURL;
1468 }
1469
1470 add_action('admin_menu', 'rsvp_modify_menu');
1471 add_action('admin_init', 'rsvp_register_settings');
1472 add_action('init', 'rsvp_init');
1473 add_filter('the_content', 'rsvp_frontend_handler');
1474 register_activation_hook(__FILE__,'rsvp_database_setup');
1475 ?>
1476