0;');
return (count(array_filter($array, $my_not_empty)) == 0) ? 1 : 0;
}
function espresso_edit_attendee($registration_id, $attendee_id, $event_id=0, $type='', $text='') {
global $org_options;
$html = '';
if ($text == '')
$text = __('Edit Attendee', 'event_espresso');
switch ($type) {
case'admin':
$html .= '' . $text . '';
break;
case'attendee':
default:
$array = array('r_id' => $registration_id, 'id' => $attendee_id, 'event_id' => $event_id, 'edit_attendee' => 'true', 'single' => 'true');
$url = add_query_arg($array, get_permalink($org_options['event_page_id']));
$html .= '' . $text . '';
//$html .= '' . $text . '';
break;
}
return $html;
}
function espresso_reg_url($event_id=0) {
global $org_options;
if ($event_id > 0) {
//return espresso_getTinyUrl(home_url().'/?page_id='.$org_options['event_page_id'].'®event_action=register&event_id='.$event_id);
$new_url = add_query_arg('ee', $event_id, get_permalink($org_options['event_page_id']));
return $new_url;
}/* else {
echo 'No event id supplied'; */
return;
//}
}
function espresso_getTinyUrl($url) {
return file_get_contents("http://tinyurl.com/api-create.php?url=" . $url);
}
//Text formatting function.
//This should fix all of the formatting issues of text output from the database.
function espresso_format_content($content='') {
return wpautop(stripslashes_deep(html_entity_decode(do_shortcode($content), ENT_QUOTES, "UTF-8")));
}
//This function pulls HTML entities back into HTML format first then strips it.
//Use it if you want to strip the HTML from the event_desc column in the daatabase.
//I have to store HTML as special chars in the database, because the html was breaking the sql queries.
//I tried doing add_slashes, then strip_slashes, but it kept adding to many slashes and not removing the extras. It was a nightmare so i decided to jsut make all HTML into special chars.
function event_espresso_strip_html_from_entity($html_entity) {
$stripped_html_entity = strip_tags(html_entity_decode($html_entity));
return $stripped_html_entity;
}
/* This function checks a registration id to see if their session is registered more than once, if so, it returns the session id */
function event_espresso_more_than_one($registration_id) {
global $wpdb;
$sql = "SELECT a.attendee_session FROM " . EVENTS_ATTENDEE_TABLE . " a JOIN " . EVENTS_ATTENDEE_TABLE . " b ON b.attendee_session = a.attendee_session WHERE b.registration_id='" . $registration_id . "' GROUP BY a.id";
$res = $wpdb->get_results($sql);
if ($wpdb->num_rows > 1) {
$attendee_session = $wpdb->get_var($sql . " ORDER BY a.id LIMIT 1 ");
return $attendee_session;
}
return null;
}
//For testing email functions
function event_espresso_test_email($optional_message = 'None') {
global $org_options;
$to = $org_options['contact_email'];
$subject = 'Event Espresso Test Message from' . $org_options['organization'];
$message = 'Event Espresso email is working properly. Optional message: ' . $optional_message;
$headers = 'From: ' . $org_options['contact_email'] . "\r\n" .
'Reply-To: ' . $org_options['contact_email'] . "\r\n" .
'X-Mailer: PHP/' . phpversion();
wp_mail($to, $subject, $message, $headers);
}
//This function is not currently used
function event_espresso_session_start() {
/* if(!isset($_SESSION['event_espresso_sessionid'])){
$sessionid = (mt_rand(100,999).time());
$_SESSION['event_espresso_sessionid'] = $sessionid;
} */
//print_r( $_SESSION['event_espresso_sessionid']); //See if the session already exists
}
//This function just returns the session id.
function event_espresso_session_id() {
if (!isset($_SESSION['espresso_session']['id'])) {
$sessionid = (mt_rand(100, 999) . time());
$_SESSION['espresso_session']['id'] = $sessionid;
}
return $_SESSION['espresso_session']['id'];
}
//This function just returns the session id.
function espresso_reg_sessionid($registration_id) {
/* if(empty($_SESSION['espresso_reg_sessionid'])){
$sessionid = $registration_id;
//$sessionid = (mt_rand(100,999).time());
$_SESSION['espresso_reg_sessionid'] = $sessionid;
}
return $_SESSION['espresso_reg_sessionid']; */
}
//Function to display additional attendee fields.
if (!function_exists('event_espresso_additional_attendees')) {
function event_espresso_additional_attendees($event_id=0, $additional_limit=2, $available_spaces=999, $label='', $show_label = true, $event_meta = '') {
$event_id = $event_id == 0 ? $_REQUEST['event_id'] : $event_id;
if ($event_meta == '' && ($event_id != '' || $event_id != 0)) {
$event_meta = event_espresso_get_event_meta($event_id);
}
$i = 0;
if ($event_meta['additional_attendee_reg_info'] == 1) {
$label = $label == '' ? __('Number of Tickets', 'event_espresso') : $label;
$html = '';
$html .= $show_label == true ? '' : '';
$html .= '';
//$html .= ' ';
$html .= '';
$html .= '';
$buffer = '';
} else {
while (($i <= $additional_limit) && ($i < $available_spaces)) {
$i++;
}
$i = $i - 1;
$html = '
' : '';
}
}
}//end questions display
} else
$html = '';
return $html;
}
}
//Social media buttons
if (!function_exists('espresso_show_social_media')) {
function espresso_show_social_media($event_id, $type = 'twitter') {
switch ($type) {
case 'twitter':
if (function_exists('espresso_twitter_button')) {
return espresso_twitter_button($event_id);
}
break;
case 'facebook':
if (function_exists('espresso_facebook_button')) {
return espresso_facebook_button($event_id);
}
break;
default:
break;
}
}
}
//Simple function to return the meta an event, venue, staff etc.
function ee_show_meta($meta, $name) {
if ($meta == '')
return;
foreach ($meta as $key => $value) {
switch ($key) {
case $name:
return $value;
break;
}
}
}
//This function returns an array of category data based on an event id
if (!function_exists('espresso_event_category_data')) {
function espresso_event_category_data($event_id, $all_cats=FALSE) {
global $wpdb;
$sql = "SELECT c.category_identifier, c.category_name, c.category_desc, c.display_desc FROM " . EVENTS_DETAIL_TABLE . " e ";
$sql .= " JOIN " . EVENTS_CATEGORY_REL_TABLE . " r ON r.event_id = e.id ";
$sql .= " JOIN " . EVENTS_CATEGORY_TABLE . " c ON c.id = r.cat_id ";
$sql .= " WHERE e.id = '" . $event_id . "' ";
$wpdb->get_results($sql);
$num_rows = $wpdb->num_rows;
if ($num_rows > 0 && $all_cats = FALSE) {
$category_data = array('category_identifier' => $wpdb->last_result[0]->category_identifier, 'category_name' => $wpdb->last_result[0]->category_name, 'category_desc' => $wpdb->last_result[0]->category_desc, 'display_desc' => $wpdb->last_result[0]->display_desc);
return $category_data;
} elseif ($num_rows > 0) {
$category_data = array('category_identifier' => '', 'category_name' => '', 'category_desc' => '', 'display_desc' => '');
foreach ($wpdb->last_result as $result) {
$category_data['category_identifier'] .= $result->category_identifier . ' ';
$category_data['category_name'] .= $result->category_name . ' ';
$category_data['category_desc'] .= $result->category_desc . ' ';
$category_data['display_desc'] .= $result->display_desc . ' ';
}
return $category_data;
} else {
//echo 'No Categories';
return;
}
}
}
if (!function_exists('espresso_registration_id')) {
function espresso_registration_id($attendee_id) {
global $wpdb;
$sql = $wpdb->get_results("SELECT registration_id FROM " . EVENTS_ATTENDEE_TABLE . " WHERE id ='" . $wpdb->escape($attendee_id) . "'");
$num_rows = $wpdb->num_rows;
if ($num_rows > 0) {
return $wpdb->last_result[0]->registration_id;
} else {
return 0;
}
}
}
if (!function_exists('espresso_attendee_id')) {
function espresso_attendee_id($registration_id) {
global $wpdb;
$sql = $wpdb->get_results("SELECT id FROM " . EVENTS_ATTENDEE_TABLE . " WHERE registration_id ='" . $wpdb->escape($registration_id) . "'");
$num_rows = $wpdb->num_rows;
if ($num_rows > 0) {
return $wpdb->last_result[0]->id;
} else {
return 0;
}
}
}
if (!function_exists('espresso_ticket_information')) {
function espresso_ticket_information($atts) {
global $wpdb;
extract($atts);
if (!empty($registration_id))
$registration_id = "{$registration_id}";
$price_option = "{$price_option}";
$type = "{$type}";
switch ($type) {
case 'ticket':
$sql = $wpdb->get_results("SELECT * FROM " . EVENTS_PRICES_TABLE . " WHERE id ='" . $price_option . "'");
$num_rows = $wpdb->num_rows;
if ($num_rows > 0) {
return $wpdb->last_result[0]->price_type;
}
break;
}
}
}
//Creates a Google Map Link
if (!function_exists('espresso_google_map_link')) {
function espresso_google_map_link($atts) {
extract($atts);
$address = "{$address}";
$city = "{$city}";
$state = "{$state}";
$zip = "{$zip}";
$country = "{$country}";
$text = isset($text) ? "{$text}" : "";
$type = isset($type) ? "{$type}" : "";
$map_w = isset($map_w) ? "{$map_w}" : 400;
$map_h = isset($map_h) ? "{$map_h}" : 400;
$gaddress = ($address != '' ? $address : '') . ($city != '' ? ',' . $city : '') . ($state != '' ? ',' . $state : '') . ($zip != '' ? ',' . $zip : '') . ($country != '' ? ',' . $country : '');
$google_map = htmlentities2('http://maps.google.com/maps?q=' . urlencode($gaddress));
switch ($type) {
case 'text':
default:
$text = $text == '' ? __('Map and Directions', 'event_espresso') : $text;
break;
case 'url':
$text = $google_map;
break;
case 'map':
$google_map_link = '' . '';
return $google_map_link;
}
$google_map_link = '' . $text . '';
return $google_map_link;
}
}
//Returns a string of keys and values
if (!function_exists("unkeyvaluepair")) {
function unkeyvaluepair($string) {
$array = array();
$pairs = explode("&", $string);
foreach ($pairs as $pair) {
list($key, $value) = explode("=", $pair, 2);
$array[$key] = urldecode($value);
}
return $array;
}
}
function espresso_add_query_vars($aVars) {
$aVars[] = "searchdate"; // represents the name of the date as shown in the URL
return $aVars;
}
// hook add_query_vars function into query_vars
//add_filter('query_vars', 'espresso_add_query_vars');
function espresso_serialize($data) {
if (!is_serialized($data)) {
return maybe_serialize($data);
}
return $data;
}
function espresso_unserialize($data, $return_format = '') {
if (is_serialized($data)) {
return maybe_unserialize($data);
}
return $data;
}
//Checks to see if the array is multidimensional
function is_multi($array) {
return (count($array) != count($array, 1));
}
//escape the commas in csv file export
function escape_csv_val($val) {
$type = ($_REQUEST['type']) ? $_REQUEST['type'] : '';
if (preg_match('/,/', $val) && $type == 'csv') {
return '"' . $val . '"';
}
return $val;
}
//return field(s) from a table
function get_event_field($field, $table, $where) {
global $wpdb;
$r = $wpdb->get_row('SELECT ' . $field . ' FROM ' . $table . $where, ARRAY_A);
return $r[$field];
}
/*
Shows the personnel that are assigned to an event
Example usage in a template file
espresso_show_personnel($event_id , array('wrapper_start'=>'
','wrapper_end'=>'
','before'=>'
','after'=>'
', 'limit'=>1,'show_info'=>true) );
Parameters:
event_id - id of event
wrapper_start - adds html to the beginning of the output block
wrapper_end - adds html the end of the output block
before - adds html to the beginning of each persons details
after - adds html to the end of each persons details
staff_id - show a single person by id (useful for showing people not assigned to an event)
limit - how many people to show
show_info - shows the persons role and organization (if available) */
if (!function_exists('espresso_show_personnel')) {
function espresso_show_personnel($event_id=0, $atts) {
global $espresso_premium;
if ($espresso_premium != true)
return;
global $wpdb;
extract($atts, EXTR_PREFIX_ALL, "v");
if ($event_id == 0 && ($v_staff_id == 0 || $v_staff_id == ''))
return;
$v_limit = $v_limit > 0 ? " LIMIT 0," . $v_limit . " " : '';
$sql = "SELECT s.id, s.name, s.role, s.meta ";
$sql .= " FROM " . EVENTS_PERSONNEL_TABLE . ' s ';
if ($v_staff_id > 0) {
$sql .= " WHERE s.id ='" . $v_staff_id . "' ";
} else {
$sql .= " JOIN " . EVENTS_PERSONNEL_REL_TABLE . " r ON r.person_id = s.id ";
$sql .= " WHERE r.event_id ='" . $event_id . "' ";
}
$sql .= $v_limit;
//echo $sql;
$event_personnel = $wpdb->get_results($sql);
$num_rows = $wpdb->num_rows;
if ($num_rows > 0) {
$html = '';
foreach ($event_personnel as $person) {
$person_id = $person->id;
$person_name = $person->name;
$person_role = $person->role;
$meta = unserialize($person->meta);
$person_organization = $meta['organization'] != '' ? $meta['organization'] : '';
//$person_title = $meta['title']!=''? $meta['title']:'';
$add_dash = ($person_role != '' && $person_organization != '') ? ' - ' : '';
if ($v_show_info == true)
$person_info = ($person_role != '' || $person_organization != '') ? ' [' . $person_role . $add_dash . $person_organization . ']' : '';
$html .= $v_before . $person_name . $person_info . $v_after;
}
}
return $v_wrapper_start . $html . $v_wrapper_end;
}
}
//Function to include a template file. Checks user templates folder first, then default template.
if (!function_exists('event_espresso_require_template')) {
/**
* event_espresso_require_template()
*
* @param mixed $template_file_name // Name of template file.
* @param bool $must_exist // Error if neither file exist.
* @param bool $as_require_once // True for require_once(), False for require()
* @return void // No return value. File already included.
*
* Usage: event_espresso_require_template('shopping_cart.php')
*/
function event_espresso_require_template($template_file_name, $must_exist = true, $as_require_once = true) {
event_espresso_require_file($template_file_name, EVENT_ESPRESSO_TEMPLATE_DIR, EVENT_ESPRESSO_PLUGINFULLPATH . 'templates/', $must_exist, $as_require_once);
}
}
//Function to include a gateway file. Checks user gateway folder first, then default template.
if (!function_exists('event_espresso_require_gateway')) {
/**
* event_espresso_require_gateway()
*
* @param mixed $template_file_name // Name of template file.
* @param bool $must_exist // Error if neither file exist.
* @param bool $as_require_once // True for require_once(), False for require()
* @return void // No return value. File already included.
*
* Usage: event_espresso_require_gateway('PaymentGateway.php')
*/
function event_espresso_require_gateway($template_file_name, $must_exist = true, $as_require_once = true) {
event_espresso_require_file($template_file_name, EVENT_ESPRESSO_GATEWAY_DIR . '/', EVENT_ESPRESSO_PLUGINFULLPATH . '/gateways/', $must_exist, $as_require_once);
}
}
//Function to include a template file. Checks user templates folder first, then default template.
if (!function_exists('event_espresso_require_file')) {
/**
* event_espresso_require_file()
*
* @param mixed $template_file_name // Name of template file.
* @param mixed $path_first // First choice for file location.
* @param mixed $path_first // Fallback location for file.
* @param bool $must_exist // Error if neither file exist.
* @param bool $as_require_once // True for require_once(), False for require()
* @return void // No return value. File already included.
*
* Usage: event_espresso_require_file('shopping_cart.php',EVENT_ESPRESSO_TEMPLATE_DIR,EVENT_ESPRESSO_PLUGINFULLPATH.'templates/')
*/
function event_espresso_require_file($template_file_name, $path_first, $path_else, $must_exist = true, $as_require_once = true) {
if (file_exists($path_first . $template_file_name)) {
// Use the template file in the user's upload folder
$full_path = $path_first . $template_file_name;
} else {
// Use the system file path
$full_path = $path_else . $template_file_name;
}
if (file_exists($full_path) || $must_exist) {
($as_require_once == true) ? require_once($full_path) : require($full_path);
}
}
}
//Added by Imon
//Function to clean up left out data from multi event registration id group table
if (!function_exists('event_espresso_cleanup_multi_event_registration_id_group_data')) {
/**
* event_espresso_cleanup_multi_event_registration_id_group_data()
*
* Usage: event_espresso_cleanup_multi_event_registration_id_group_data()
*/
function event_espresso_cleanup_multi_event_registration_id_group_data() {
global $wpdb;
$wpdb->query(" delete emerig from " . EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE . " emerig left join " . EVENTS_ATTENDEE_TABLE . " ea on emerig.registration_id = ea.registration_id where ea.registration_id is null ");
}
}
//Function to clean up left out data from attendee cost table
if (!function_exists('event_espresso_cleanup_attendee_cost_data')) {
/**
* event_espresso_cleanup_attendee_cost_data()
*
* Usage: event_espresso_cleanup_attendee_cost_data()
*/
function event_espresso_cleanup_attendee_cost_data() {
global $wpdb;
$wpdb->query(" delete eac from " . EVENTS_ATTENDEE_COST_TABLE . " eac left join " . EVENTS_ATTENDEE_TABLE . " ea on eac.attendee_id = ea.id where ea.id is null ");
}
}
function espresso_check_scripts() {
if (function_exists('wp_script_is')) {
if (!wp_script_is('jquery')) {
echo '
' . __('Jquery is not loaded!', 'event_espresso') . ' ' . __('Event Espresso is unable to load Jquery do to a conflict with your theme or another plugin.', 'event_espresso') . '
';
}
}
if (!function_exists('wp_head')) {
echo '
' . __('Missing wp_head() Function', 'event_espresso') . ' ' . __('The WordPress function wp_head() seems to be missing in your theme. Please contact the theme developer to make sure this is fixed before using Event Espresso.', 'event_espresso') . '
';
}
if (!function_exists('wp_footer')) {
echo '
' . __('Missing wp_footer() Function', 'event_espresso') . ' ' . __('The WordPress function wp_footer() seems to be missing in your theme. Please contact the theme developer to make sure this is fixed before using Event Espresso.', 'event_espresso') . '
';
}
}
//These functions were moved here from admin.php on 08-30-2011 by Seth
function espresso_edit_this($event_id) {
global $espresso_premium;
if ($espresso_premium != true)
return;
global $current_user;
wp_get_current_user();
$curauth = wp_get_current_user();
$user_id = $curauth->ID;
$user = new WP_User($user_id);
foreach ($user->roles as $role) {
//echo $role;
//Build the edit event link
$edit_link = '' . __('Edit Event') . '';
switch ($role) {
case 'administrator':
case 'espresso_event_admin':
case 'espresso_event_manager':
case 'espresso_group_admin':
//If user is an event manager, then show the edit link for their events
if (function_exists('espresso_member_data') && espresso_member_data('role') == 'espresso_eventmanager' && espresso_member_data('id') != espresso_is_my_event($event_id))
return;
return $edit_link;
break;
}
}
}
//Retrives the attendee count based on an attendee ids
function espresso_count_attendees_for_registration($attendee_id) {
global $wpdb;
$cnt = $wpdb->get_var("SELECT COUNT(1) as cnt FROM " . EVENTS_ATTENDEE_TABLE . " WHERE registration_id='" . espresso_registration_id($attendee_id) . "' ORDER BY id ");
if ($cnt == 1) {
$cnt = $wpdb->get_var("SELECT quantity FROM " . EVENTS_ATTENDEE_TABLE . " WHERE registration_id='" . espresso_registration_id($attendee_id) . "' ORDER BY id ");
if ($cnt == 0) {
return 1;
} elseif ($cnt > 0) {
return $cnt;
}
}
return $cnt;
}
function espresso_quantity_for_registration($attendee_id) {
global $wpdb;
$cnt = $wpdb->get_var("SELECT quantity FROM " . EVENTS_ATTENDEE_TABLE . " WHERE registration_id='" . espresso_registration_id($attendee_id) . "' ORDER BY id ");
return $cnt;
}
function espresso_is_primary_attendee($attendee_id) {
global $wpdb;
$sql = "SELECT am.meta_value FROM " . EVENTS_ATTENDEE_META_TABLE . " am ";
$sql .= " WHERE am.attendee_id = '" . $attendee_id . "' AND am.meta_key='primary_attendee' AND am.meta_value='1' ";
//echo $sql;
$wpdb->get_results($sql);
if ($wpdb->num_rows > 0) {
return true;
}
}
function espresso_get_primary_attendee_id($registration_id) {
global $wpdb;
$sql = "SELECT am.attendee_id FROM " . EVENTS_ATTENDEE_META_TABLE . " am ";
$sql .= " JOIN " . EVENTS_ATTENDEE_TABLE . " ea ON ea.id = am.attendee_id ";
$sql .= " WHERE ea.registration_id = '" . $registration_id . "' AND am.meta_key='primary_attendee' AND am.meta_value='1' ";
//echo $sql;
$wpdb->get_results($sql);
if ($wpdb->num_rows > 0) {
return $wpdb->last_result[0]->attendee_id;
}
}
function espresso_ticket_links($registration_id, $attendee_id) {
global $wpdb;
$sql = "SELECT * FROM " . EVENTS_ATTENDEE_TABLE;
if (espresso_is_primary_attendee($attendee_id) != true) {
$sql .= " WHERE id = '" . $attendee_id . "' ";
} else {
$sql .= " WHERE registration_id = '" . $registration_id . "' ";
}
//echo $sql;
$attendees = $wpdb->get_results($sql);
$ticket_link = '';
if ($wpdb->num_rows > 0) {
$group = $wpdb->num_rows > 1 ? '' . sprintf(__('Tickets Purchased (%s):', 'event_espresso'), $wpdb->num_rows) . ' ' : '';
$break = ' ';
foreach ($attendees as $attendee) {
$ticket_url = get_option('siteurl') . "/?download_ticket=true&id=" . $attendee->id . "®istration_id=" . $attendee->registration_id;
$ticket_link .= '' . __('Download/Print Ticket') . ' (' . $attendee->fname . ' ' . $attendee->lname . ')' . '' . $break;
}
return '
' . $group . $ticket_link . '
';
}
}
/**
* Function espresso_get_attendee_coupon_discount
* Get discount amount for a given attendee id and cost
*
* @global wpdb $wpdb
* @param int $attendee_id
* @param double $cost
*/
function espresso_get_attendee_coupon_discount($attendee_id, $cost) {
global $wpdb;
$coupon_code = "";
$row = $wpdb->get_row($wpdb->prepare("select * from " . EVENTS_ATTENDEE_TABLE . " where id = %d", $attendee_id), ARRAY_A);
if (!is_null($row['coupon_code']) && !empty($row['coupon_code'])) {
$coupon_code = $row['coupon_code'];
$event_id = $row['event_id'];
//$results = $wpdb->get_results("SELECT * FROM ". EVENTS_DISCOUNT_CODES_TABLE ." WHERE coupon_code = '".$_REQUEST['coupon_code']."'");
$discounts = $wpdb->get_results("SELECT d.* FROM " . EVENTS_DISCOUNT_CODES_TABLE . " d JOIN " . EVENTS_DISCOUNT_REL_TABLE . " r ON r.discount_id = d.id WHERE d.coupon_code = '" . $coupon_code . "' AND r.event_id = '" . $event_id . "' ");
if ($wpdb->num_rows > 0) {
$valid_discount = true;
foreach ($discounts as $discount) {
$discount_id = $discount->id;
$coupon_code = $discount->coupon_code;
$coupon_code_price = $discount->coupon_code_price;
$coupon_code_description = $discount->coupon_code_description;
$use_percentage = $discount->use_percentage;
}
$discount_type_price = $use_percentage == 'Y' ? $coupon_code_price . '%' : $org_options['currency_symbol'] . $coupon_code_price;
if ($use_percentage == 'Y') {
$pdisc = $coupon_code_price / 100;
$cost = $cost - ($cost * $pdisc);
} else {
$cost = $cost - $coupon_code_price;
}
}
}
return $cost;
}
//End