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

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