=')) {
//If this is an older version of WordPress, then we need to load this.
if (function_exists('wp_tiny_mce_preload_dialogs')) {
add_action('admin_print_footer_scripts', 'wp_tiny_mce_preload_dialogs', 30);
}
}
$show = true;
//If this is a newer version of wordress and we are the events page, we don't want to load the editor function
if (version_compare($wp_version, $wp_min_version, '>=')) {
//If this is the event editor page, we don't want to load the tiny mce editor because it breaks the page
if (isset($_REQUEST['page']) && ($_REQUEST['page'] == 'events')) {
$show = false;
}
//If this is the edit attendee payments page then we need to load the tiny mce editor.
//We need to do it this way because the 'event_admin_reports' is in the same URL string as 'event' above.
if (isset($_REQUEST['event_admin_reports']) && ($_REQUEST['event_admin_reports'] == 'enter_attendee_payments')) {
$show = true;
}
}
//Load the tiny mce editor
if ($show == true)
wp_tiny_mce(false, array("editor_selector" => "theEditor")); // true gives you a stripped down version of the editor
}
//function to delete event
//From now on I am making events disapear instead of deleting completely.
//If an event is active and has active attendees, it will send the attendees an email notification of the cancelled event.
//@param optional pass an event id to delete
if (!function_exists('event_espresso_delete_event')) {
function event_espresso_delete_event($event_id = 'NULL') {
global $wpdb;
if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete') {
$event_id = $_REQUEST['event_id'];
}
if ($event_id != 'NULL') {
$sql = array('event_status' => 'D');
$update_id = array('id' => $event_id);
$sql_data = array('%s');
/* if ($wpdb->update(EVENTS_DETAIL_TABLE, $sql, $update_id, $sql_data, array( '%d' ) ) && event_espresso_get_status($event_id) == 'ACTIVE'){
event_espresso_send_cancellation_notice($event_id);
} */
//Add an option in general settings for the following?
/* if (event_espresso_get_status($event_id) == 'ACTIVE') {
event_espresso_send_cancellation_notice($event_id);
} */
if ($wpdb->update(EVENTS_DETAIL_TABLE, $sql, $update_id, $sql_data, array('%d'))/* && event_espresso_get_status($event_id) == 'ACTIVE' */) {
$event_post = $wpdb->get_row("SELECT post_id FROM " . EVENTS_DETAIL_TABLE . " WHERE id =" . $event_id, ARRAY_A);
wp_delete_post($event_post['post_id']);
//echo $event_post['post_id'];
}
} else {
echo '
' . __('No ID Supplied', 'event_espresso') . '
';
}
}
}
//This function installs the tables
function event_espresso_run_install($table_name, $table_version, $sql) {
global $wpdb;
$wp_table_name = $wpdb->prefix . $table_name;
if ($wpdb->get_var("SHOW TABLES LIKE '" . $wp_table_name . "'") != $wp_table_name) {
$sql_create_table = "CREATE TABLE " . $wp_table_name . " ( " . $sql . " ) DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql_create_table);
//create option for table version
$option_name = $table_name . '_tbl_version';
$newvalue = $table_version;
if (get_option($option_name)) {
update_option($option_name, $newvalue);
} else {
$deprecated = '';
$autoload = 'no';
add_option($option_name, $newvalue, $deprecated, $autoload);
}
//create option for table name
$option_name = $table_name . '_tbl';
$newvalue = $wp_table_name;
if (get_option($option_name)) {
update_option($option_name, $newvalue);
} else {
$deprecated = '';
$autoload = 'no';
add_option($option_name, $newvalue, $deprecated, $autoload);
}
}
// Code here with new database upgrade info/table Must change version number to work.
$installed_ver = get_option($table_name . '_tbl_version');
if ($installed_ver != $table_version) {
$sql_create_table = "CREATE TABLE " . $wp_table_name . " ( " . $sql . " ) ;";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql_create_table);
update_option($table_name . '_tbl_version', $table_version);
}
}
//function to empty trash
//This will delete everything that is related to the events that have been deleted
function event_espresso_empty_event_trash($event_id) {
global $wpdb;
//if ( $_REQUEST['action'] == 'delete' ){
//$event_id=$_REQUEST['id'];
//Remove the event
$sql = "DELETE FROM " . EVENTS_DETAIL_TABLE . " WHERE id='" . $event_id . "'";
$wpdb->query($sql);
//Remove the event times
$sql = "DELETE FROM " . EVENTS_START_END_TABLE . " WHERE event_id='" . $event_id . "'";
$wpdb->query($sql);
//Remove the event prices
$sql = "DELETE FROM " . EVENTS_PRICES_TABLE . " WHERE event_id='" . $event_id . "'";
$wpdb->query($sql);
//Remove the event discount
$sql = "DELETE FROM " . EVENTS_DISCOUNT_REL_TABLE . " WHERE event_id='" . $event_id . "'";
$wpdb->query($sql);
$sql = "DELETE FROM " . EVENTS_ATTENDEE_TABLE . " WHERE event_id='" . $event_id . "'";
$wpdb->query($sql);
/* delete_price_from_event($event_id);
delete_category_from_event($event_id);
delete_discount_from_event($event_id);
delete_attendees_from_event($event_id); */
//}
}
/**
* Create a postbox widget
*/
function postbox($id, $title, $content) {
?>
0) {
return true;
} else {
return false;
}
} else {
if (($value != '') && (strtolower($value) != 'null') && (strlen(trim($value)) > 0)) {
return true;
} else {
return false;
}
}
}
function ee_tep_round($number, $precision) {
if (strpos($number, '.') && (strlen(substr($number, strpos($number, '.') + 1)) > $precision)) {
$number = substr($number, 0, strpos($number, '.') + 1 + $precision + 1);
if (substr($number, -1) >= 5) {
if ($precision > 1) {
$number = substr($number, 0, -1) + ('0.' . str_repeat(0, $precision - 1) . '1');
} elseif ($precision == 1) {
$number = substr($number, 0, -1) + 0.1;
} else {
$number = substr($number, 0, -1) + 1;
}
} else {
$number = substr($number, 0, -1);
}
}
return $number;
}
function ee_tep_output_string($string, $translate = false, $protected = false) {
if ($protected == true) {
return htmlspecialchars($string);
} else {
if ($translate == false) {
return ee_tep_parse_input_field_data($string, array('"' => '"'));
} else {
return ee_tep_parse_input_field_data($string, $translate);
}
}
}
function ee_tep_parse_input_field_data($data, $parse) {
return strtr(trim($data), $parse);
}
/* Turns an array into a select field */
function select_input($name, $values, $default = '', $parameters = '') {
$field = '';
return $field;
}
/* * ** These functions deals with moving templates and files *** */
//Creates folders in the uploads directory to facilitate addons and templates
function event_espresso_create_upload_directories() {
// Create the required folders
$folders = array(
EVENT_ESPRESSO_UPLOAD_DIR,
EVENT_ESPRESSO_TEMPLATE_DIR,
EVENT_ESPRESSO_GATEWAY_DIR,
EVENT_ESPRESSO_UPLOAD_DIR . '/logs/',
);
foreach ($folders as $folder) {
wp_mkdir_p($folder);
@ chmod($folder, 0755);
}
}
/**
* event_espresso_count_files, does exactly what the name says
*/
function event_espresso_count_files($path, $exclude = ".|..|.svn", $recursive = false) {
$result = array();
$path = rtrim($path, "/") . "/";
if (is_dir($path)) {
$folder_handle = opendir($path);
$exclude_array = explode("|", $exclude);
while (false !== ($filename = readdir($folder_handle))) {
if (!in_array(strtolower($filename), $exclude_array)) {
if (is_dir($path . $filename . "/")) {
if ($recursive)
$result[] = file_array($path, $exclude, true);
} else {
$result[] = $filename;
}
}
}
}
//return $result;
return count($result);
}
//Functions for copying and moving templates
function event_espresso_trigger_copy_templates() {
global $wpdb;
check_admin_referer('copy_templates');
event_espresso_smartCopy(EVENT_ESPRESSO_PLUGINFULLPATH . 'templates/', EVENT_ESPRESSO_TEMPLATE_DIR);
$_SESSION['event_espresso_themes_copied'] = true;
$sendback = wp_get_referer();
$sendback = add_query_arg('tab', $_SESSION['event_espresso_settings_curr_page'], remove_query_arg('tab', $sendback));
wp_redirect($sendback);
exit();
}
//Functions for copying and moving gateways
function event_espresso_trigger_copy_gateways() {
global $wpdb;
check_admin_referer('copy_gateways');
event_espresso_smartCopy(EVENT_ESPRESSO_PLUGINFULLPATH . 'gateways/', EVENT_ESPRESSO_GATEWAY_DIR);
$_SESSION['event_espresso_gateways_copied'] = true;
$sendback = wp_get_referer();
$sendback = add_query_arg('tab', $_SESSION['event_espresso_settings_curr_page'], remove_query_arg('tab', $sendback));
wp_redirect($sendback);
exit();
}
//Functions for copying and moving files and themes
function event_espresso_smartCopy($source, $dest, $folderPermission = 0755, $filePermission = 0644) {
# source=file & dest=dir => copy file from source-dir to dest-dir
# source=file & dest=file / not there yet => copy file from source-dir to dest and overwrite a file there, if present
# source=dir & dest=dir => copy all content from source to dir
# source=dir & dest not there yet => copy all content from source to a, yet to be created, dest-dir
$result = false;
if (is_file($source)) { # $source is file
if (is_dir($dest)) { # $dest is folder
if ($dest[strlen($dest) - 1] != '/') # add '/' if necessary
$__dest = $dest . "/";
$__dest .= basename($source);
}
else { # $dest is (new) filename
$__dest = $dest;
}
$result = copy($source, $__dest);
chmod($__dest, $filePermission);
} elseif (is_dir($source)) { # $source is dir
if (!is_dir($dest)) { # dest-dir not there yet, create it
@mkdir($dest, $folderPermission);
chmod($dest, $folderPermission);
}
if ($source[strlen($source) - 1] != '/') # add '/' if necessary
$source = $source . "/";
if ($dest[strlen($dest) - 1] != '/') # add '/' if necessary
$dest = $dest . "/";
# find all elements in $source
$result = true; # in case this dir is empty it would otherwise return false
$dirHandle = opendir($source);
while ($file = readdir($dirHandle)) { # note that $file can also be a folder
if ($file != "." && $file != "..") { # filter starting elements and pass the rest to this function again
# echo "$source$file ||| $dest$file \n";
$result = event_espresso_smartCopy($source . $file, $dest . $file, $folderPermission, $filePermission);
}
}
closedir($dirHandle);
} else {
$result = false;
}
return $result;
}
function espresso_getFileList($dir) {
#array to hold return value
$retval = array();
#add trailing slash if missing
if (substr($dir, -1) != "/")
$dir .= "/";
# open pointer to directory and read list of files
$d = @dir($dir) or die("getFileList: Failed opening directory $dir for reading");
while (false !== ($entry = $d->read())) {
# skip hidden files
if ($entry[0] == "." || $entry[0] == "_")
continue;
if (is_dir("$dir$entry")) {
$retval[] = array("name" => "$dir$entry/", "type" => filetype("$dir$entry"), "size" => 0, "lastmod" => filemtime("$dir$entry"));
} elseif (is_readable("$dir$entry")) {
$retval[] = array("name" => "$dir$entry", "type" => mime_content_type("$dir$entry"), "size" => filesize("$dir$entry"), "lastmod" => filemtime("$dir$entry"));
}
} $d->close();
return $retval;
}
/*
// espresso_getFileList() Usage
$dirlist = espresso_getFileList(EVENT_ESPRESSO_TEMPLATE_DIR);
echo "
';
}
}
}
function event_espresso_admin_news($url) {
return wp_remote_retrieve_body(wp_remote_get($url));
}
//Not sure if this works or not. Need to test at some point.
//This function should build the event editor description field.
function events_editor($content, $id = 'content', $prev_id = 'title') {
$media_buttons = false;
$richedit = user_can_richedit();
?>
***This is an automated response - Do Not Reply***
Thank you [fname] [lname] for registering for [event]. We hope that you will find this event both informative and enjoyable. Should have any questions, please contact [contact].
Ticket type: [ticket_type]
Print Tickets: [ticket_link] (A link Your Customized Ticket if the ticketing addon is installed.)
[qr_code] (generated by the QR Code addon, if installed)
If you have not done so already, please submit your payment in the amount of [cost].
Click here to review your payment information [payment_url].
Your questions: [custom_questions].
get_var("SHOW TABLES LIKE '" . EVENTS_ATTENDEE_TABLE . "'");
if (!empty($table_exists)) {
$sql = "SELECT id FROM " . EVENTS_ATTENDEE_TABLE . " WHERE registration_id IS NULL OR registration_id = '' OR registration_id = '0' OR quantity IS NULL OR quantity = '' OR quantity = '0' ";
$wpdb->get_results($sql);
if ($wpdb->num_rows > 0) {
return true;
}
}
}
function event_espresso_update_attendee_data() {
global $wpdb;
//$wpdb->show_errors();
$sql = "SELECT id FROM " . EVENTS_ATTENDEE_TABLE . " WHERE registration_id IS NULL OR registration_id = '' OR registration_id = '0' ";
$attendees = $wpdb->get_results($sql);
if ($wpdb->num_rows > 0) {
//echo $sql;
foreach ($attendees as $attendee) {
/**********************************
* ****** Update single registrations
* ********************************* */
$registration_id = uniqid('', true);
$update_attendee = "UPDATE " . EVENTS_ATTENDEE_TABLE . " SET registration_id = '" . $registration_id . "' WHERE id = '" . $attendee->id . "'";
$wpdb->query($update_attendee);
}
}
$sql2 = "SELECT id FROM " . EVENTS_ATTENDEE_TABLE . " WHERE quantity IS NULL OR quantity = '' OR quantity = '0' ";
$attendees2 = $wpdb->get_results($sql2);
if ($wpdb->num_rows > 0) {
//echo $sql;
foreach ($attendees2 as $attendee2) {
/** * *******************************
* ****** Update pricing
* ********************************* */
$update_attendee2 = "UPDATE " . EVENTS_ATTENDEE_TABLE . " SET quantity = '1' WHERE id = '" . $attendee2->id . "'";
$wpdb->query($update_attendee2);
}
}
}
//Function to show an admin message if the main pages are not setup.
function event_espresso_activation_notice() {
if (function_exists('admin_url')) {
echo '
';
}
}
//Function to show an admin message if registration id's are missing.
function event_espresso_registration_id_notice() {
if (function_exists('admin_url')) {
echo '
' . __('Event Espresso attendee data needs to be updated. Please visit the ', 'event_espresso') . ' ' . __('Support page', 'event_espresso') . ' ' . __('to configure update the attendee information.', 'event_espresso') . '
';
} else {
echo '
' . __('Event Espresso attendee data needs to be updated. Please visit the ', 'event_espresso') . ' ' . __('Support page', 'event_espresso') . ' ' . __('to configure update the attendee information.', 'event_espresso') . '
';
}
}
//This function returns a dropdown of secondary events
if (!function_exists('espresso_secondary_events_dd')) {
function espresso_secondary_events_dd($current_value = '0', $allow_overflow = 'N') {
global $wpdb;
$sql = "SELECT id, event_name FROM " . EVENTS_DETAIL_TABLE;
$sql .= " WHERE event_status = 'S' ";
$events = $wpdb->get_results($sql);
$num_rows = $wpdb->num_rows;
//return print_r( $events );
if ($num_rows > 0) {
$field = '";
$values = array(array('id' => 'Y', 'text' => __('Yes', 'event_espresso')), array('id' => 'N', 'text' => __('No', 'event_espresso')));
$html = '
';
return $html;
}
}
}
// Function espresso_db_dropdown creates a drop-down box
// by dynamically querying ID-Name pair from a lookup table
//
// Parameters:
// intIdField = Integer "ID" field of table, usually the primary key
// strNameField = Name field that user picks as a value
// strTableName = Name of MySQL table containing intIDField and strNameField
// strOrderField = Which field you want results sorted by
// strMethod = Sort as asc=ascending (default) or desc for descending
// $current_value = The current select value
// $strDDName = The name of the field
//
//
// Returns:
// HTML Drop-Down Box Mark-up Code
function espresso_db_dropdown($intIdField, $strNameField, $strTableName, $strOrderField, $current_value, $strMethod = "desc", $strDDName = "") {
global $wpdb;
$strQuery = "select $intIdField, $strNameField from $strTableName order by $strOrderField $strMethod";
//$rsrcResult = mysql_query($strQuery);
$data = $wpdb->get_results($strQuery, ARRAY_A);
//print_r($data);
$strDDName = $strDDName != "" ? $strDDName : $strNameField;
if ($wpdb->num_rows > 0) {
echo '";
} else {
_e('No Results', 'event_espresso');
}
}
function espresso_email_message($id) {
global $wpdb;
$results = $wpdb->get_results("SELECT * FROM " . EVENTS_EMAIL_TABLE . " WHERE id =" . $id);
foreach ($results as $result) {
$email_id = $result->id;
$email_name = stripslashes_deep($result->email_name);
$email_subject = stripslashes_deep($result->email_subject);
$email_text = stripslashes_deep($result->email_text);
}
$email_data = array('id' => $id, 'email_name' => $email_name, 'email_subject' => $email_subject, 'email_text' => $email_text);
return $email_data;
}
function espresso_category_dropdown($current_value = '') {
global $wpdb;
$strQuery = "select id, category_name from " . EVENTS_CATEGORY_TABLE;
$data = $wpdb->get_results($strQuery, ARRAY_A);
//print_r($data);
if ($wpdb->num_rows > 0) {
echo '";
} else {
return;
}
}
//This function grabs the event categories.
//@param optional $event_id = pass the event id to get the categories assigned to the event.
function event_espresso_list_categories($event_id = 0) {
global $wpdb;
$event_categories = $wpdb->get_results("SELECT * FROM " . EVENTS_CATEGORY_TABLE);
foreach ($event_categories as $category) {
$category_id = $category->id;
$category_name = $category->category_name;
$in_event_categories = $wpdb->get_results("SELECT * FROM " . EVENTS_CATEGORY_REL_TABLE . " WHERE event_id='" . $event_id . "' AND cat_id='" . $category_id . "'");
if ($wpdb->num_rows > 0) {
echo '