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