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

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