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

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

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