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

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