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

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