RSVP Options in the admin area.
#
# To add, edit, delete and see rsvp status there will be a new RSVP admin
# area just go there.
#
# To allow people to rsvp create a new page and add "rsvp-pluginhere" to the text
session_start();
define("ATTENDEES_TABLE", $wpdb->prefix."attendees");
define("ASSOCIATED_ATTENDEES_TABLE", $wpdb->prefix."associatedAttendees");
define("QUESTIONS_TABLE", $wpdb->prefix."rsvpCustomQuestions");
define("QUESTION_TYPE_TABLE", $wpdb->prefix."rsvpQuestionTypes");
define("ATTENDEE_ANSWERS", $wpdb->prefix."attendeeAnswers");
define("QUESTION_ANSWERS_TABLE", $wpdb->prefix."rsvpCustomQuestionAnswers");
define("QUESTION_ATTENDEES_TABLE", $wpdb->prefix."rsvpCustomQuestionAttendees");
define("EDIT_SESSION_KEY", "RsvpEditAttendeeID");
define("EDIT_QUESTION_KEY", "RsvpEditQuestionID");
define("RSVP_FRONTEND_TEXT_CHECK", "rsvp-pluginhere");
define("OPTION_GREETING", "rsvp_custom_greeting");
define("OPTION_THANKYOU", "rsvp_custom_thankyou");
define("OPTION_DEADLINE", "rsvp_deadline");
define("OPTION_OPENDATE", 'rsvp_opendate');
define("OPTION_YES_VERBIAGE", "rsvp_yes_verbiage");
define("OPTION_NO_VERBIAGE", "rsvp_no_verbiage");
define("OPTION_KIDS_MEAL_VERBIAGE", "rsvp_kids_meal_verbiage");
define("OPTION_VEGGIE_MEAL_VERBIAGE", "rsvp_veggie_meal_verbiage");
define("OPTION_NOTE_VERBIAGE", "rsvp_note_verbiage");
define("OPTION_HIDE_VEGGIE", "rsvp_hide_veggie");
define("OPTION_HIDE_KIDS_MEAL", "rsvp_hide_kids_meal");
define("OPTION_HIDE_ADD_ADDITIONAL", "rsvp_hide_add_additional");
define("OPTION_NOTIFY_ON_RSVP", "rsvp_notify_when_rsvp");
define("OPTION_NOTIFY_EMAIL", "rsvp_notify_email_address");
define("RSVP_DB_VERSION", "6");
define("QT_SHORT", "shortAnswer");
define("QT_MULTI", "multipleChoice");
define("QT_LONG", "longAnswer");
define("QT_DROP", "dropdown");
define("QT_RADIO", "radio");
if((isset($_GET['page']) && (strToLower($_GET['page']) == 'rsvp-admin-export')) ||
(isset($_POST['rsvp-bulk-action']) && (strToLower($_POST['rsvp-bulk-action']) == "export"))) {
add_action('init', 'rsvp_admin_export');
}
require_once("rsvp_frontend.inc.php");
/*
* Description: Database setup for the rsvp plug-in.
*/
function rsvp_database_setup() {
global $wpdb;
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
require_once("rsvp_db_setup.inc.php");
}
function rsvp_admin_guestlist_options() {
?>
/wp-content/plugins/rsvp/jquery-ui-1.7.2.custom/css/ui-lightness/jquery-ui-1.7.2.custom.css" type="text/css" media="all" />
0) && ($_POST['rsvp-bulk-action'] == "delete") && (is_array($_POST['attendee']) && (count($_POST['attendee']) > 0))) {
foreach($_POST['attendee'] as $attendee) {
if(is_numeric($attendee) && ($attendee > 0)) {
$wpdb->query($wpdb->prepare("DELETE FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeID = %d OR associatedAttendeeID = %d",
$attendee,
$attendee));
$wpdb->query($wpdb->prepare("DELETE FROM ".ATTENDEES_TABLE." WHERE id = %d",
$attendee));
}
}
}
$sql = "SELECT id, firstName, lastName, rsvpStatus, note, kidsMeal, additionalAttendee, veggieMeal, personalGreeting FROM ".ATTENDEES_TABLE;
$orderBy = " lastName, firstName";
if(isset($_GET['sort'])) {
if(strToLower($_GET['sort']) == "rsvpstatus") {
$orderBy = " rsvpStatus ".((strtolower($_GET['sortDirection']) == "desc") ? "DESC" : "ASC") .", ".$orderBy;
}else if(strToLower($_GET['sort']) == "attendee") {
$direction = ((strtolower($_GET['sortDirection']) == "desc") ? "DESC" : "ASC");
$orderBy = " lastName $direction, firstName $direction";
} else if(strToLower($_GET['sort']) == "kidsmeal") {
$orderBy = " kidsMeal ".((strtolower($_GET['sortDirection']) == "desc") ? "DESC" : "ASC") .", ".$orderBy;
} else if(strToLower($_GET['sort']) == "additional") {
$orderBy = " additionalAttendee ".((strtolower($_GET['sortDirection']) == "desc") ? "DESC" : "ASC") .", ".$orderBy;
} else if(strToLower($_GET['sort']) == "vegetarian") {
$orderBy = " veggieMeal ".((strtolower($_GET['sortDirection']) == "desc") ? "DESC" : "ASC") .", ".$orderBy;
}
}
$sql .= " ORDER BY ".$orderBy;
$attendees = $wpdb->get_results($sql);
$sort = "";
$sortDirection = "asc";
if(isset($_GET['sort'])) {
$sort = $_GET['sort'];
}
if(isset($_GET['sortDirection'])) {
$sortDirection = $_GET['sortDirection'];
}
?>
List of current attendees
get_results($sql);
$csv = "\"Attendee\",\"RSVP Status\",";
if(get_option(OPTION_HIDE_KIDS_MEAL) != "Y") {
$csv .= "\"Kids Meal\",";
}
$csv .= "\"Additional Attendee\",";
if(get_option(OPTION_HIDE_VEGGIE) != "Y") {
$csv .= "\"Vegatarian\",";
}
$csv .= "\"Note\",\"Associated Attendees\"";
$qRs = $wpdb->get_results("SELECT id, question FROM ".QUESTIONS_TABLE." ORDER BY sortOrder, id");
if(count($qRs) > 0) {
foreach($qRs as $q) {
$csv .= ",\"".stripslashes($q->question)."\"";
}
}
$csv .= "\r\n";
foreach($attendees as $a) {
$csv .= "\"".utf8_decode(stripslashes($a->firstName." ".$a->lastName))."\",\"".($a->rsvpStatus)."\",";
if(get_option(OPTION_HIDE_KIDS_MEAL) != "Y") {
$csv .= "\"".(($a->kidsMeal == "Y") ? "Yes" : "No")."\",";
}
$csv .= "\"".(($a->additionalAttendee == "Y") ? "Yes" : "No")."\",";
if(get_option(OPTION_HIDE_VEGGIE) != "Y") {
$csv .= "\"".(($a->veggieMeal == "Y") ? "Yes" : "No")."\",";
}
$csv .= "\"".(str_replace("\"", "\"\"", stripslashes($a->note)))."\",\"";
$sql = "SELECT firstName, lastName FROM ".ATTENDEES_TABLE."
WHERE id IN (SELECT attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE associatedAttendeeID = %d)
OR id in (SELECT associatedAttendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeID = %d)";
$associations = $wpdb->get_results($wpdb->prepare($sql, $a->id, $a->id));
foreach($associations as $assc) {
$csv .= trim(stripslashes($assc->firstName." ".$assc->lastName))."\r\n";
}
$csv .= "\"";
$qRs = $wpdb->get_results("SELECT id, question FROM ".QUESTIONS_TABLE." ORDER BY sortOrder, id");
if(count($qRs) > 0) {
foreach($qRs as $q) {
$aRs = $wpdb->get_results($wpdb->prepare("SELECT answer FROM ".ATTENDEE_ANSWERS." WHERE attendeeID = %d AND questionID = %d", $a->id, $q->id));
if(count($aRs) > 0) {
$csv .= ",\"".stripslashes($aRs[0]->answer)."\"";
} else {
$csv .= ",\"\"";
}
}
}
$csv .= "\r\n";
}
if(isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/MSIE/", $_SERVER['HTTP_USER_AGENT'])) {
// IE Bug in download name workaround
ini_set( 'zlib.output_compression','Off' );
}
header('Content-Description: RSVP Export');
header("Content-Type: application/vnd.ms-excel", true);
header('Content-Disposition: attachment; filename="rsvpEntries.csv"');
echo $csv;
exit();
}
function rsvp_admin_import() {
global $wpdb;
if(count($_FILES) > 0) {
check_admin_referer('rsvp-import');
require_once("Excel/reader.php");
$data = new Spreadsheet_Excel_Reader();
$data->read($_FILES['importFile']['tmp_name']);
if($data->sheets[0]['numCols'] >= 2) {
$count = 0;
for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
$fName = trim($data->sheets[0]['cells'][$i][1]);
$lName = trim($data->sheets[0]['cells'][$i][2]);
$personalGreeting = (isset($data->sheets[0]['cells'][$i][4])) ? $personalGreeting = $data->sheets[0]['cells'][$i][4] : "";
if(!empty($fName) && !empty($lName)) {
$sql = "SELECT id FROM ".ATTENDEES_TABLE."
WHERE firstName = %s AND lastName = %s ";
$res = $wpdb->get_results($wpdb->prepare($sql, $fName, $lName));
if(count($res) == 0) {
$wpdb->insert(ATTENDEES_TABLE, array("firstName" => $fName,
"lastName" => $lName,
"personalGreeting" => $personalGreeting),
array('%s', '%s', '%s'));
$count++;
}
}
}
if($data->sheets[0]['numCols'] >= 3) {
// There must be associated users so let's associate them
for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
$fName = trim($data->sheets[0]['cells'][$i][1]);
$lName = trim($data->sheets[0]['cells'][$i][2]);
if(!empty($fName) && !empty($lName) && (count($data->sheets[0]['cells'][$i]) >= 3)) {
// Get the user's id
$sql = "SELECT id FROM ".ATTENDEES_TABLE."
WHERE firstName = %s AND lastName = %s ";
$res = $wpdb->get_results($wpdb->prepare($sql, $fName, $lName));
if((count($res) > 0) && isset($data->sheets[0]['cells'][$i][3])) {
$userId = $res[0]->id;
// Deal with the assocaited users...
$associatedUsers = explode(",", trim($data->sheets[0]['cells'][$i][3]));
if(is_array($associatedUsers)) {
foreach($associatedUsers as $au) {
$user = explode(" ", trim($au), 2);
// Three cases, they didn't enter in all of the information, user exists or doesn't.
// If user exists associate the two users
// If user does not exist add the user and then associate the two
if(is_array($user) && (count($user) == 2)) {
$sql = "SELECT id FROM ".ATTENDEES_TABLE."
WHERE firstName = %s AND lastName = %s ";
$userRes = $wpdb->get_results($wpdb->prepare($sql, trim($user[0]), trim($user[1])));
if(count($userRes) > 0) {
$newUserId = $userRes[0]->id;
} else {
// Insert them and then we can associate them...
$wpdb->insert(ATTENDEES_TABLE, array("firstName" => trim($user[0]), "lastName" => trim($user[1])), array('%s', '%s'));
$newUserId = $wpdb->insert_id;
$count++;
}
$wpdb->insert(ASSOCIATED_ATTENDEES_TABLE, array("attendeeID" => $newUserId,
"associatedAttendeeID" => $userId),
array("%d", "%d"));
$wpdb->insert(ASSOCIATED_ATTENDEES_TABLE, array("attendeeID" => $userId,
"associatedAttendeeID" => $newUserId),
array("%d", "%d"));
}
}
}
}
}
}
}
?>
total records were imported.
Continue to the RSVP list
0) && !empty($_POST['firstName']) && !empty($_POST['lastName'])) {
check_admin_referer('rsvp_add_guest');
if(isset($_SESSION[EDIT_SESSION_KEY]) && is_numeric($_SESSION[EDIT_SESSION_KEY])) {
$wpdb->update(ATTENDEES_TABLE,
array("firstName" => trim($_POST['firstName']),
"lastName" => trim($_POST['lastName']),
"personalGreeting" => trim($_POST['personalGreeting']),
"rsvpStatus" => trim($_POST['rsvpStatus'])),
array("id" => $_SESSION[EDIT_SESSION_KEY]),
array("%s", "%s", "%s", "%s"),
array("%d"));
$attendeeId = $_SESSION[EDIT_SESSION_KEY];
$wpdb->query($wpdb->prepare("DELETE FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeId = %d", $attendeeId));
} else {
$wpdb->insert(ATTENDEES_TABLE, array("firstName" => trim($_POST['firstName']),
"lastName" => trim($_POST['lastName']),
"personalGreeting" => trim($_POST['personalGreeting']),
"rsvpStatus" => trim($_POST['rsvpStatus'])),
array('%s', '%s', '%s', '%s'));
$attendeeId = $wpdb->insert_id;
}
if(isset($_POST['associatedAttendees']) && is_array($_POST['associatedAttendees'])) {
foreach($_POST['associatedAttendees'] as $aid) {
if(is_numeric($aid) && ($aid > 0)) {
$wpdb->insert(ASSOCIATED_ATTENDEES_TABLE, array("attendeeID"=>$attendeeId, "associatedAttendeeID"=>$aid), array("%d", "%d"));
}
}
}
?>
Attendee has been successfully saved
Continue to Attendee List |
Add a Guest
get_row("SELECT id, firstName, lastName, personalGreeting, rsvpStatus FROM ".ATTENDEES_TABLE." WHERE id = ".$_GET['id']);
if($attendee != null) {
$_SESSION[EDIT_SESSION_KEY] = $attendee->id;
$firstName = utf8_decode(stripslashes($attendee->firstName));
$lastName = utf8_decode(stripslashes($attendee->lastName));
$personalGreeting = stripslashes($attendee->personalGreeting);
$rsvpStatus = $attendee->rsvpStatus;
// Get the associated attendees and add them to an array
$associations = $wpdb->get_results("SELECT associatedAttendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeId = ".$attendee->id.
" UNION ".
"SELECT attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE associatedAttendeeID = ".$attendee->id);
foreach($associations as $aId) {
$associatedAttendees[] = $aId->associatedAttendeeID;
}
}
}
?>
0) && ($_POST['rsvp-bulk-action'] == "delete") && (is_array($_POST['q']) && (count($_POST['q']) > 0))) {
foreach($_POST['q'] as $q) {
if(is_numeric($q) && ($q > 0)) {
$wpdb->query($wpdb->prepare("DELETE FROM ".QUESTIONS_TABLE." WHERE id = %d", $q));
$wpdb->query($wpdb->prepare("DELETE FROM ".ATTENDEE_ANSWERS." WHERE questionID = %d", $q));
}
}
} else if((count($_POST) > 0) && ($_POST['rsvp-bulk-action'] == "saveSortOrder")) {
$sql = "SELECT id FROM ".QUESTIONS_TABLE;
$sortQs = $wpdb->get_results($sql);
foreach($sortQs as $q) {
if(is_numeric($_POST['sortOrder'.$q->id]) && ($_POST['sortOrder'.$q->id] >= 0)) {
$wpdb->update(QUESTIONS_TABLE,
array("sortOrder" => $_POST['sortOrder'.$q->id]),
array("id" => $q->id),
array("%d"),
array("%d"));
}
}
}
$sql = "SELECT id, question, sortOrder FROM ".QUESTIONS_TABLE." ORDER BY sortOrder ASC";
$customQs = $wpdb->get_results($sql);
?>
List of current custom questions
get_results("SELECT id FROM ".QUESTION_TYPE_TABLE." WHERE questionType = 'radio'");
if($radioQuestionType == 0) {
$wpdb->insert(QUESTION_TYPE_TABLE, array("questionType" => "radio", "friendlyName" => "Radio"), array('%s', '%s'));
}
if((count($_POST) > 0) && !empty($_POST['question']) && is_numeric($_POST['questionTypeID'])) {
check_admin_referer('rsvp_add_custom_question');
if(isset($_SESSION[EDIT_QUESTION_KEY]) && is_numeric($_SESSION[EDIT_QUESTION_KEY])) {
$wpdb->update(QUESTIONS_TABLE,
array("question" => trim($_POST['question']),
"questionTypeID" => trim($_POST['questionTypeID']),
"permissionLevel" => ((trim($_POST['permissionLevel']) == "private") ? "private" : "public")),
array("id" => $_SESSION[EDIT_QUESTION_KEY]),
array("%s", "%d", "%s"),
array("%d"));
$questionId = $_SESSION[EDIT_QUESTION_KEY];
$answers = $wpdb->get_results($wpdb->prepare("SELECT id FROM ".QUESTION_ANSWERS_TABLE." WHERE questionID = %d", $questionId));
if(count($answers) > 0) {
foreach($answers as $a) {
if(isset($_POST['deleteAnswer'.$a->id]) && (strToUpper($_POST['deleteAnswer'.$a->id]) == "Y")) {
$wpdb->query($wpdb->prepare("DELETE FROM ".QUESTION_ANSWERS_TABLE." WHERE id = %d", $a->id));
} elseif(isset($_POST['answer'.$a->id]) && !empty($_POST['answer'.$a->id])) {
$wpdb->update(QUESTION_ANSWERS_TABLE,
array("answer" => trim($_POST['answer'.$a->id])),
array("id"=>$a->id),
array("%s"),
array("%d"));
}
}
}
} else {
$wpdb->insert(QUESTIONS_TABLE, array("question" => trim($_POST['question']),
"questionTypeID" => trim($_POST['questionTypeID']),
"permissionLevel" => ((trim($_POST['permissionLevel']) == "private") ? "private" : "public")),
array('%s', '%d', '%s'));
$questionId = $wpdb->insert_id;
}
if(isset($_POST['numNewAnswers']) && is_numeric($_POST['numNewAnswers']) &&
in_array($_POST['questionTypeID'], $answerQuestionTypes)) {
for($i = 0; $i < $_POST['numNewAnswers']; $i++) {
if(isset($_POST['newAnswer'.$i]) && !empty($_POST['newAnswer'.$i])) {
$wpdb->insert(QUESTION_ANSWERS_TABLE, array("questionID"=>$questionId, "answer"=>$_POST['newAnswer'.$i]));
}
}
}
if(strToLower(trim($_POST['permissionLevel'])) == "private") {
$wpdb->query($wpdb->prepare("DELETE FROM ".QUESTION_ATTENDEES_TABLE." WHERE questionID = %d", $questionId));
if(isset($_POST['attendees']) && is_array($_POST['attendees'])) {
foreach($_POST['attendees'] as $aid) {
if(is_numeric($aid) && ($aid > 0)) {
$wpdb->insert(QUESTION_ATTENDEES_TABLE, array("attendeeID"=>$aid, "questionID"=>$questionId), array("%d", "%d"));
}
}
}
}
?>
Custom Question saved
Continue to Question List |
Add another Question
get_results($wpdb->prepare("SELECT id, question, questionTypeID, permissionLevel FROM ".QUESTIONS_TABLE." WHERE id = %d", $_GET['id']));
if(count($qRs) > 0) {
$isNew = false;
$_SESSION[EDIT_QUESTION_KEY] = $qRs[0]->id;
$questionId = $qRs[0]->id;
$question = stripslashes($qRs[0]->question);
$permissionLevel = stripslashes($qRs[0]->permissionLevel);
$questionTypeId = $qRs[0]->questionTypeID;
if($permissionLevel == "private") {
$aRs = $wpdb->get_results($wpdb->prepare("SELECT attendeeID FROM ".QUESTION_ATTENDEES_TABLE." WHERE questionID = %d", $questionId));
if(count($aRs) > 0) {
foreach($aRs as $a) {
$savedAttendees[] = $a->attendeeID;
}
}
}
}
}
$sql = "SELECT id, questionType, friendlyName FROM ".QUESTION_TYPE_TABLE;
$questionTypes = $wpdb->get_results($sql);
?>