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

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