function tickets_info($echo = true)
 {
     if ($this->get_api_key_id()) {
         global $wpdb;
         /* $event_id = $this->get_api_event();
         
         				  $query = apply_filters( 'tc_tickets_info_query', "SELECT tcp.ID, tcp.post_type, tco.post_status
         				  FROM $wpdb->posts tcp
         				  LEFT JOIN $wpdb->posts tco ON tcp.post_parent = tco.ID
         				  WHERE tcp.post_type = 'tc_tickets_instances'
         				  AND (tco.post_status = 'order_paid')
         				  ORDER BY tco.post_date
         				  DESC LIMIT %d
         				  OFFSET %d
         				  " );
         
         				  $results = $wpdb->get_results(
         				  $wpdb->prepare( $query, $this->results_per_page, (( $this->page_number - 1 ) * $this->results_per_page ) )
         				  , OBJECT ); */
         /* START OF THE NEW API */
         $event_id = $this->get_api_event();
         $event_ticket_types = array();
         if ($event_id == 'all') {
             $wp_events_search = new TC_Events_Search('', '', '', 'publish');
             foreach ($wp_events_search->get_results() as $event) {
                 $event_obj = new TC_Event($event->ID);
                 $event_ticket_types = array_merge($event_ticket_types, $event_obj->get_event_ticket_types());
             }
         } else {
             $event = new TC_Event($event_id);
             $event_ticket_types = $event->get_event_ticket_types();
         }
         $meta_query = array('relation' => 'OR');
         foreach ($event_ticket_types as $event_ticket_type) {
             $meta_query[] = array('key' => 'ticket_type_id', 'value' => (string) $event_ticket_type);
         }
         $orders_args = array('posts_per_page' => -1, 'post_type' => apply_filters('tc_order_post_type_name', array('tc_orders')), 'post_status' => apply_filters('tc_paid_post_statuses', array('order_paid')), 'fields' => 'ids', 'cache_results' => false);
         $query = new WP_Query($orders_args);
         $paid_orders_ids = $query->get_posts();
         $args = array('post_type' => 'tc_tickets_instances', 'post_status' => 'publish', 'meta_query' => $meta_query, 'posts_per_page' => $this->results_per_page, 'offset' => ($this->page_number - 1) * $this->results_per_page, 'post_parent__in' => $paid_orders_ids);
         $results = get_posts($args);
         /* END OF THE NEW API */
         $results_count = 0;
         foreach ($results as $result) {
             $ticket_instance = new TC_Ticket_Instance($result->ID);
             $ticket_type = new TC_Ticket($ticket_instance->details->ticket_type_id);
             //$ticket_type_event_id = get_post_meta( apply_filters( 'tc_ticket_type_id', $ticket_type->details->ID ), apply_filters( 'tc_event_name_field_name', 'event_name' ), true );
             $order = new TC_Order($ticket_instance->details->post_parent);
             $continue = false;
             if (in_array($order->details->post_status, apply_filters('tc_paid_post_statuses', array('order_paid')))) {
                 $order_is_paid = true;
             } else {
                 $order_is_paid = false;
             }
             $order_is_paid = apply_filters('tc_order_is_paid', $order_is_paid, $order->details->ID);
             if ($order_is_paid) {
                 /* OLD */
                 $check_ins = get_post_meta($ticket_instance->details->ID, 'tc_checkins', true);
                 $checkin_date = '';
                 if (!empty($check_ins)) {
                     foreach ($check_ins as $check_in) {
                         $checkin_date = tc_format_date($check_in['date_checked']);
                     }
                 }
                 $r['date_checked'] = $checkin_date;
                 $r['payment_date'] = tc_format_date(strtotime($order->details->post_modified));
                 //date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $order->details->post_modified ), false )
                 $r['transaction_id'] = $ticket_instance->details->ticket_code;
                 $r['checksum'] = $ticket_instance->details->ticket_code;
                 $buyer_full_name = isset($order->details->tc_cart_info['buyer_data']['first_name_post_meta']) ? $order->details->tc_cart_info['buyer_data']['first_name_post_meta'] . ' ' . $order->details->tc_cart_info['buyer_data']['last_name_post_meta'] : '';
                 $buyer_email = isset($order->details->tc_cart_info['buyer_data']['email_post_meta']) ? $order->details->tc_cart_info['buyer_data']['email_post_meta'] : '';
                 if (!empty($ticket_instance->details->first_name) && !empty($ticket_instance->details->last_name)) {
                     $r['buyer_first'] = $ticket_instance->details->first_name;
                     $r['buyer_last'] = $ticket_instance->details->last_name;
                 } else {
                     $r['buyer_first'] = apply_filters('tc_ticket_checkin_buyer_first_name', $order->details->tc_cart_info['buyer_data']['first_name_post_meta'], $order->details->ID);
                     $r['buyer_last'] = apply_filters('tc_ticket_checkin_buyer_last_name', $order->details->tc_cart_info['buyer_data']['last_name_post_meta'], $order->details->ID);
                 }
                 $r['custom_fields'] = array(array(apply_filters('tc_ticket_checkin_custom_field_title', 'Ticket Type'), apply_filters('tc_checkout_owner_info_ticket_title', $ticket_type->details->post_title, $ticket_type->details->ID)), array(apply_filters('tc_ticket_checkin_custom_field_title', 'Buyer Name'), apply_filters('tc_ticket_checkin_buyer_full_name', $buyer_full_name, $order->details->ID)), array(apply_filters('tc_ticket_checkin_custom_field_title', 'Buyer E-mail'), apply_filters('tc_ticket_checkin_buyer_email', $buyer_email, $order->details->ID)));
                 $r['custom_fields'] = apply_filters('tc_checkin_custom_fields', $r['custom_fields'], $result->ID, $event_id, $order, $ticket_type);
                 $r['custom_field_count'] = count($r['custom_fields']);
                 $r['address'] = '';
                 if ($r['address'] == '') {
                     $r['address'] = 'N/A';
                 }
                 $r['city'] = '';
                 if ($r['city'] == '') {
                     $r['city'] = 'N/A';
                 }
                 $r['state'] = '';
                 if ($r['state'] == '') {
                     $r['state'] = 'N/A';
                 }
                 $r['country'] = '';
                 if ($r['country'] == '') {
                     $r['country'] = 'N/A';
                 }
                 $rows[] = array('data' => $r);
                 /* END OLD */
                 $results_count++;
             }
         }
         $additional['results_count'] = $results_count;
         $rows[] = array('additional' => $additional);
         echo json_encode($rows);
         exit;
     }
 }
function tc_order_field_value($order_id, $value, $meta_key, $field_type, $field_id = false)
{
    global $tc;
    if ($field_type == 'order_status') {
        $new_value = str_replace('_', ' ', $value);
        if ($value == 'order_fraud') {
            $color = "red";
        } else {
            if ($value == 'order_received') {
                $color = "#ff6600";
                //yellow
            } else {
                if ($value == 'order_paid') {
                    $color = "green";
                } else {
                    $color = "black";
                }
            }
        }
        return sprintf(__('%1$s %2$s %3$s', 'tc'), '<font color="' . $color . '">', __(ucwords($new_value), 'tc'), '</font>');
    } else {
        if ($field_id == 'order_date') {
            return tc_format_date($value);
            //date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $value, false );
        } else {
            if ($field_id == 'customer') {
                $order = new TC_Order($order_id);
                $author_id = $order->details->post_author;
                if (!user_can($author_id, 'manage_options') && $author_id != 0) {
                    $buyer_info = '<a href="' . admin_url('user-edit.php?user_id=' . $author_id) . '">' . $value['buyer_data']['first_name_post_meta'] . ' ' . $value['buyer_data']['last_name_post_meta'] . '</a>';
                } else {
                    $buyer_info = $value['buyer_data']['first_name_post_meta'] . ' ' . $value['buyer_data']['last_name_post_meta'];
                }
                return $buyer_info;
            } elseif ($field_id == 'parent_event') {
                $events = $tc->get_cart_events($value);
                foreach ($events as $event_id) {
                    $event = new TC_Event($event_id);
                    echo '<a href="post.php?post=' . $event->details->ID . '&action=edit">' . $event->details->post_title . '</a> x ' . $tc->get_cart_event_tickets($value, $event->details->ID) . '<br />';
                }
            } elseif ($field_id == 'gateway') {
                return $value['gateway'];
            } elseif ($field_id == 'gateway_admin_name') {
                return $value['gateway_admin_name'];
            } elseif ($field_id == 'discount') {
                $discounts = new TC_Discounts();
                $discount_total = $discounts->get_discount_total_by_order($order_id);
                $discount_object = get_page_by_title($value['coupon_code'], OBJECT, 'tc_discounts');
                if ($discount_total > 0) {
                    $discount_total = apply_filters('tc_cart_currency_and_format', $discount_total) . '<br />' . __('Code: ', 'tc') . '<a href="edit.php?post_type=tc_events&page=tc_discount_codes&action=edit&ID=' . $discount_object->ID . '">' . $value['coupon_code'] . '</a>';
                } else {
                    $discount_total = '-';
                }
                return $discount_total;
            } elseif ($field_id == 'total') {
                return apply_filters('tc_cart_currency_and_format', $value['total']);
            } elseif ($field_id == 'subtotal') {
                return apply_filters('tc_cart_currency_and_format', $value['subtotal']);
            } elseif ($field_id == 'subtotal') {
                return apply_filters('tc_cart_currency_and_format', $value['subtotal']);
            } elseif ($field_id == 'fees_total') {
                return apply_filters('tc_cart_currency_and_format', $value['fees_total']);
            } elseif ($field_id == 'tax_total') {
                return apply_filters('tc_cart_currency_and_format', $value['tax_total']);
            } else {
                return $value;
            }
        }
    }
}
    ?>
				</tr>
				<?php 
    $style = '';
    if ($ticket_checkins) {
        arsort($ticket_checkins);
        foreach ($ticket_checkins as $ticket_checkin) {
            $style = ' class="alternate"' == $style ? '' : ' class="alternate"';
            ?>
  
						<tr <?php 
            echo $style;
            ?>
>
							<td><?php 
            echo tc_format_date($ticket_checkin['date_checked']);
            ?>
</td>
							<td><?php 
            echo apply_filters('tc_checkins_status', $ticket_checkin['status']);
            ?>
</td>
							<td><?php 
            echo apply_filters('tc_checkins_api_key_id', $ticket_checkin['api_key_id']);
            ?>
</td>
							<?php 
            if (current_user_can('manage_options') || current_user_can('delete_checkins_cap')) {
                ?>
								<td><?php 
                echo '<a class="tc_delete_link" href="' . wp_nonce_url(admin_url('admin.php?page=tc_attendees&action=details&ID=' . $_GET['ID'] . '&checkin_action=delete_checkin&checkin_entry=' . $ticket_checkin['date_checked']), 'delete_checkin') . '">' . __('Delete', 'tc') . '</a>';
function tc_get_order_date($field_name = '', $post_id = '')
{
    $value = get_post_meta($post_id, $field_name, true);
    echo tc_format_date($value);
    //date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $value, false );
}
 function tickets_info($echo = true)
 {
     if ($this->get_api_key_id()) {
         global $wpdb;
         $event_id = $this->get_api_event();
         /*
          SELECT tcp.ID, tcp.post_type, tco.post_status
          FROM wp_posts tcp
          LEFT JOIN wp_posts tco ON tcp.post_parent = tco.ID
          WHERE tcp.post_type =  'tc_tickets_instances'
          AND tco.post_status =  'order_paid'
         */
         $results = $wpdb->get_results($wpdb->prepare("SELECT tcp.ID, tcp.post_type, tco.post_status\n\t\t\t\t  FROM {$wpdb->posts} tcp\n\t\t\t\t  LEFT JOIN {$wpdb->posts} tco ON tcp.post_parent = tco.ID\n\t\t\t\t  WHERE tcp.post_type =  %s\n\t\t\t\t  AND tco.post_status =  'order_paid'\n\t\t\t\t  ORDER BY tco.post_date\n\t\t\t\t  DESC LIMIT %d\n\t\t\t\t  OFFSET %d\n\t\t\t\t", 'tc_tickets_instances', $this->results_per_page, ($this->page_number - 1) * $this->results_per_page), OBJECT);
         /* $ticket_search = new TC_Tickets_Instances_Search( $this->keyword, $this->page_number, $this->results_per_page, false, true, ($event_id == 'all' ? '' : 'event_id' ), ($event_id == 'all' ? '' : $event_id ), 'publish', true );
         
         				  $results = $ticket_search->get_results(); */
         $results_count = 0;
         foreach ($results as $result) {
             $ticket_instance = new TC_Ticket_Instance($result->ID);
             $ticket_type = new TC_Ticket($ticket_instance->details->ticket_type_id);
             $ticket_type_event_id = get_post_meta($ticket_type->details->ID, 'event_name', true);
             $order = new TC_Order($ticket_instance->details->post_parent);
             $continue = false;
             if ($event_id == 'all') {
                 $continue = true;
             } else {
                 if ($ticket_type_event_id == $event_id) {
                     $continue = true;
                 } else {
                     $continue = false;
                 }
             }
             if ($order->details->post_status == 'order_paid' && $continue) {
                 /* OLD */
                 $check_ins = get_post_meta($ticket_instance->details->ID, 'tc_checkins', true);
                 $checkin_date = '';
                 if (!empty($check_ins)) {
                     foreach ($check_ins as $check_in) {
                         $checkin_date = tc_format_date($check_in['date_checked']);
                     }
                 }
                 $r['date_checked'] = $checkin_date;
                 $r['payment_date'] = tc_format_date(strtotime($order->details->post_modified));
                 //date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $order->details->post_modified ), false )
                 $r['transaction_id'] = $ticket_instance->details->ticket_code;
                 $r['checksum'] = $ticket_instance->details->ticket_code;
                 if (!empty($ticket_instance->details->first_name) && !empty($ticket_instance->details->last_name)) {
                     $r['buyer_first'] = $ticket_instance->details->first_name;
                     $r['buyer_last'] = $ticket_instance->details->last_name;
                 } else {
                     $r['buyer_first'] = $order->details->tc_cart_info['buyer_data']['first_name_post_meta'];
                     $r['buyer_last'] = $order->details->tc_cart_info['buyer_data']['last_name_post_meta'];
                 }
                 $r['custom_fields'] = array(array(apply_filters('tc_ticket_checkin_custom_field_title', 'Ticket Type'), $ticket_type->details->post_title), array(apply_filters('tc_ticket_checkin_custom_field_title', 'Buyer Name'), $order->details->tc_cart_info['buyer_data']['first_name_post_meta'] . ' ' . $order->details->tc_cart_info['buyer_data']['last_name_post_meta']), array(apply_filters('tc_ticket_checkin_custom_field_title', 'Buyer E-mail'), $order->details->tc_cart_info['buyer_data']['email_post_meta']));
                 $r['custom_fields'] = apply_filters('tc_checkin_custom_fields', $r['custom_fields'], $result->ID, $event_id, $order, $ticket_type);
                 $r['custom_field_count'] = count($r['custom_fields']);
                 $r['address'] = '';
                 if ($r['address'] == '') {
                     $r['address'] = 'N/A';
                 }
                 $r['city'] = '';
                 if ($r['city'] == '') {
                     $r['city'] = 'N/A';
                 }
                 $r['state'] = '';
                 if ($r['state'] == '') {
                     $r['state'] = 'N/A';
                 }
                 $r['country'] = '';
                 if ($r['country'] == '') {
                     $r['country'] = 'N/A';
                 }
                 $rows[] = array('data' => $r);
                 /* END OLD */
                 $results_count++;
             }
         }
         $additional['results_count'] = $results_count;
         $rows[] = array('additional' => $additional);
         echo json_encode($rows);
         exit;
     }
 }
                } else {
                    if ($post_status == 'order_paid') {
                        $color = "green";
                    }
                }
            }
            if ($post_status == 'order_fraud') {
                $post_status = __('Held for Review', 'tc');
            }
            $post_status = ucwords(str_replace('_', ' ', $post_status));
            echo sprintf(__('%1$s %2$s %3$s', 'tc'), '<font color="' . apply_filters('tc_order_history_color', $color, $init_post_status) . '">', __(ucwords($post_status), 'tc'), '</font>');
            ?>
						</td>
						<td>
							<?php 
            echo tc_format_date($order->details->tc_order_date, true);
            ?>
						</td>
						<td>
							<?php 
            echo apply_filters('tc_cart_currency_and_format', $order->details->tc_payment_info['total']);
            ?>
						</td>
						<td>
							<?php 
            $order_status_url = $tc->tc_order_status_url($order, $order->details->tc_order_date, '', false);
            ?>
							<a href="<?php 
            echo $order_status_url;
            ?>
"><?php 
 function tickets_info($echo = true)
 {
     if ($this->get_api_key_id()) {
         $event_id = $this->get_api_event();
         $ticket_search = new TC_Tickets_Instances_Search($this->keyword, $this->page_number, $this->results_per_page, false, true, 'event_id', $event_id);
         $results = $ticket_search->get_results();
         $results_count = 0;
         foreach ($results as $result) {
             $ticket_instance = new TC_Ticket_Instance($result->ID);
             $ticket_type = new TC_Ticket($ticket_instance->details->ticket_type_id);
             $order = new TC_Order($ticket_instance->details->post_parent);
             if ($order->details->post_status == 'order_paid') {
                 /* OLD */
                 $check_ins = get_post_meta($ticket_instance->details->ID, 'tc_checkins', true);
                 $checkin_date = '';
                 if (!empty($check_ins)) {
                     foreach ($check_ins as $check_in) {
                         $checkin_date = date('Y-m-d H:i:s', $check_in['date_checked']);
                     }
                 }
                 $r['date_checked'] = $checkin_date;
                 $r['payment_date'] = tc_format_date(strtotime($order->details->post_modified));
                 ////date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $order->details->post_modified ), false );
                 $r['transaction_id'] = $ticket_instance->details->ticket_code;
                 $r['checksum'] = $ticket_instance->details->ticket_code;
                 if (!empty($ticket_instance->details->first_name) && !empty($ticket_instance->details->last_name)) {
                     $r['buyer_first'] = $ticket_instance->details->first_name;
                     $r['buyer_last'] = $ticket_instance->details->last_name;
                 } else {
                     $r['buyer_first'] = $order->details->tc_cart_info['buyer_data']['first_name_post_meta'];
                     $r['buyer_last'] = $order->details->tc_cart_info['buyer_data']['last_name_post_meta'];
                 }
                 $r['custom_fields'] = array(array('Ticket Type', $ticket_type->details->post_title), array('Buyer Name', $order->details->tc_cart_info['buyer_data']['first_name_post_meta'] . ' ' . $order->details->tc_cart_info['buyer_data']['last_name_post_meta']), array('Buyer E-mail', $order->details->tc_cart_info['buyer_data']['email_post_meta']));
                 $r['custom_fields'] = apply_filters('tc_checkin_custom_fields', $r['custom_fields'], $result->ID, $event_id);
                 $r['custom_field_count'] = count($r['custom_fields']);
                 $r['address'] = '';
                 if ($r['address'] == '') {
                     $r['address'] = 'N/A';
                 }
                 $r['city'] = '';
                 if ($r['city'] == '') {
                     $r['city'] = 'N/A';
                 }
                 $r['state'] = '';
                 if ($r['state'] == '') {
                     $r['state'] = 'N/A';
                 }
                 $r['country'] = '';
                 if ($r['country'] == '') {
                     $r['country'] = 'N/A';
                 }
                 $rows[] = array('data' => $r);
                 /* END OLD */
                 $results_count++;
             }
         }
         $additional['results_count'] = $results_count;
         $rows[] = array('additional' => $additional);
         echo json_encode($rows);
         exit;
     }
 }