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