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

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