Example #1
0
function event_list_attendees()
{
    global $wpdb, $org_options, $ticketing_installed, $espresso_premium;
    define('EVT_ADMIN_URL', admin_url('admin.php?page=events'));
    $EVT_ID = isset($_REQUEST['event_id']) && $_REQUEST['event_id'] != '' ? absint($_REQUEST['event_id']) : FALSE;
    if ($EVT_ID) {
        echo '<h1>' . espresso_event_list_attendee_title($EVT_ID) . '</h1>';
    }
    $max_rows = isset($_REQUEST['max_rows']) & !empty($_REQUEST['max_rows']) ? absint($_REQUEST['max_rows']) : 50;
    $start_rec = isset($_REQUEST['start_rec']) && !empty($_REQUEST['start_rec']) ? absint($_REQUEST['start_rec']) : 0;
    $records_to_show = " LIMIT {$max_rows} OFFSET {$start_rec} ";
    //Dates
    $curdate = date('Y-m-d');
    $this_year_r = date('Y');
    $this_month_r = date('m');
    $days_this_month = date('t', time());
    if (isset($_POST['delete_customer']) && !empty($_POST['delete_customer'])) {
        if (is_array($_POST['checkbox'])) {
            while (list($att_id, $value) = each($_POST['checkbox'])) {
                $SQL = "DELETE FROM " . EVENTS_ATTENDEE_TABLE . " WHERE id = '%d'";
                $wpdb->query($wpdb->prepare($SQL, $att_id));
                $SQL = "DELETE FROM " . EVENTS_ATTENDEE_META_TABLE . " WHERE attendee_id = '%d'";
                $wpdb->query($wpdb->prepare($SQL, $att_id));
                $SQL = "DELETE FROM " . EVENTS_ANSWER_TABLE . " WHERE attendee_id = '%d'";
                $wpdb->query($wpdb->prepare($SQL, $att_id));
            }
        }
        ?>
		<div id="message" class="updated fade">
			<p>
				<strong><?php 
        _e('Customer(s) have been successfully deleted from the event.', 'event_espresso');
        ?>
</strong>
			</p>
		</div>
		<?php 
    }
    //	MARKING USERS AS ATTENDED (OR NOT)
    if ((!empty($_POST['attended_customer']) || !empty($_POST['unattended_customer'])) && $ticketing_installed == TRUE) {
        if (is_array($_POST['checkbox'])) {
            while (list($att_id, $value) = each($_POST['checkbox'])) {
                // on / off value for attended status checkbox
                $checker = $value == "on" && $_POST['attended_customer'] ? 1 : 0;
                $SQL = "SELECT checked_in_quantity FROM " . EVENTS_ATTENDEE_TABLE . " WHERE id = %d ";
                $ticket_scanned = $wpdb->get_var($wpdb->prepare($SQL, $att_id));
                if ($ticket_scanned >= 1) {
                    ?>
					<div id="message" class="error fade">
						<p>
							<strong><?php 
                    _e('Scanned tickets cannot be redeemed/un-redeemed here.', 'event_espresso');
                    ?>
</strong>
						</p>
					</div>
					<?php 
                } else {
                    if ($wpdb->update(EVENTS_ATTENDEE_TABLE, array('checked_in' => $checker), array('id' => $att_id), array('%d'), array('%d'))) {
                        ?>
					<div id="message" class="updated fade">
					  <p><strong>
						<?php 
                        _e('Customer(s) attendance data successfully updated for this event.', 'event_espresso');
                        ?>
						</strong></p>
					</div>
					<?php 
                    }
                }
            }
        }
    }
    require_once EVENT_ESPRESSO_PLUGINFULLPATH . 'includes/event-management/queries.php';
    if (file_exists(EVENT_ESPRESSO_PLUGINFULLPATH . 'includes/admin-files/admin_reports_filters.php')) {
        require_once EVENT_ESPRESSO_PLUGINFULLPATH . 'includes/admin-files/admin_reports_filters.php';
    } else {
        ?>
		<p>
			<strong><?php 
        _e('Advanced filters are available in the premium versions.', 'event_espresso');
        ?>
</strong> 
			<a href="http://eventespresso.com/download/" target="_blank">
				<?php 
        _e('Upgrade Now!', 'event_espresso');
        ?>
			</a>
		</p>
		<?php 
    }
    $sql_clause = " WHERE ";
    $sql_a = "(";
    if (function_exists('espresso_member_data') && espresso_member_data('role') == 'espresso_group_admin') {
        $group = get_user_meta(espresso_member_data('id'), "espresso_group", true);
        $group = implode(",", $group);
        $sql_a .= "SELECT a.*, e.id event_id, e.event_name, checked_in FROM " . EVENTS_ATTENDEE_TABLE . " a ";
        $sql_a .= " LEFT JOIN " . EVENTS_DETAIL_TABLE . " e ON e.id=a.event_id ";
        if ($_REQUEST['category_id'] != '') {
            $sql_a .= " JOIN " . EVENTS_CATEGORY_REL_TABLE . " r ON r.event_id = e.id ";
            $sql_a .= " JOIN " . EVENTS_CATEGORY_TABLE . " c ON  c.id = r.cat_id ";
        }
        if ($group != '') {
            $sql_a .= " JOIN " . EVENTS_VENUE_REL_TABLE . " r ON r.event_id = e.id ";
            $sql_a .= " JOIN " . EVENTS_LOCALE_REL_TABLE . " l ON  l.venue_id = r.venue_id ";
        }
        $sql_a .= $_REQUEST['category_id'] != '' ? " AND c.id = '" . $_REQUEST['category_id'] . "' " : '';
        $sql_clause = " WHERE ";
        if ($_REQUEST['payment_status'] != '') {
            $sql_a .= " {$sql_clause} a.payment_status = '" . $_REQUEST['payment_status'] . "' ";
            $sql_clause = " AND ";
        }
        if ($_POST['month_range'] != '') {
            $pieces = explode('-', $_REQUEST['month_range'], 3);
            $year_r = $pieces[0];
            $month_r = $pieces[1];
            $sql_a .= " {$sql_clause} a.date BETWEEN '" . event_espresso_no_format_date($year_r . '-' . $month_r . '-01', $format = 'Y-m-d') . "' AND '" . event_espresso_no_format_date($year_r . '-' . $month_r . '-31', $format = 'Y-m-d') . "' ";
            $sql_clause = " AND ";
        }
        if ($EVT_ID) {
            $sql_a .= " {$sql_clause} a.event_id = '" . $EVT_ID . "' ";
            $sql_clause = " AND ";
        }
        if ($_REQUEST['today_a'] == 'true') {
            //$sql_a .= " $sql_clause a.date = '" . event_espresso_no_format_date($curdate,$format = 'Y-m-d') ."' ";
            $sql_a .= " {$sql_clause} a.date BETWEEN '" . $curdate . ' 00:00:00' . "' AND '" . $curdate . ' 23:59:59' . "' ";
            $sql_clause = " AND ";
        }
        if ($_REQUEST['this_month_a'] == 'true') {
            $sql_a .= " {$sql_clause} a.date BETWEEN '" . event_espresso_no_format_date($this_year_r . '-' . $this_month_r . '-01', $format = 'Y-m-d') . "' AND '" . event_espresso_no_format_date($this_year_r . '-' . $this_month_r . '-' . $days_this_month, $format = 'Y-m-d') . "' ";
            $sql_clause = " AND ";
        }
        $sql_a .= $group != '' ? $sql_clause . "  l.locale_id IN (" . $group . ") " : '';
        $sql_a .= " AND e.event_status != 'D' ";
        $sql_a .= ") UNION (";
    }
    $sql_a .= "SELECT a.*, e.id event_id, e.event_name, checked_in FROM " . EVENTS_ATTENDEE_TABLE . " a ";
    $sql_a .= " LEFT JOIN " . EVENTS_DETAIL_TABLE . " e ON e.id=a.event_id ";
    if (!empty($_REQUEST['category_id'])) {
        $sql_a .= " JOIN " . EVENTS_CATEGORY_REL_TABLE . " r ON r.event_id = e.id ";
        $sql_a .= " JOIN " . EVENTS_CATEGORY_TABLE . " c ON  c.id = r.cat_id ";
    }
    $sql_a .= !empty($_REQUEST['category_id']) ? " AND c.id = '" . $_REQUEST['category_id'] . "' " : '';
    $sql_clause = " WHERE ";
    if (!empty($_REQUEST['payment_status'])) {
        $sql_a .= " {$sql_clause} a.payment_status = '" . $_REQUEST['payment_status'] . "' ";
        $sql_clause = " AND ";
    }
    if (!empty($_POST['month_range'])) {
        $pieces = explode('-', $_REQUEST['month_range'], 3);
        $year_r = $pieces[0];
        $month_r = $pieces[1];
        $sql_a .= " {$sql_clause} a.date BETWEEN '" . event_espresso_no_format_date($year_r . '-' . $month_r . '-01', $format = 'Y-m-d') . "' AND '" . event_espresso_no_format_date($year_r . '-' . $month_r . '-31', $format = 'Y-m-d') . "' ";
        $sql_clause = " AND ";
    }
    if ($EVT_ID) {
        $sql_a .= " {$sql_clause} a.event_id = '" . $EVT_ID . "' ";
        $sql_clause = " AND ";
    }
    if (!empty($_REQUEST['today_a'])) {
        //$sql_a .= " $sql_clause a.date = '" . event_espresso_no_format_date($curdate,$format = 'Y-m-d') ."' ";
        $sql_a .= " {$sql_clause} a.date BETWEEN '" . $curdate . ' 00:00:00' . "' AND '" . $curdate . ' 23:59:59' . "' ";
        $sql_clause = " AND ";
    }
    if (!empty($_REQUEST['this_month_a'])) {
        $sql_a .= " {$sql_clause} a.date BETWEEN '" . event_espresso_no_format_date($this_year_r . '-' . $this_month_r . '-01', $format = 'Y-m-d') . "' AND '" . event_espresso_no_format_date($this_year_r . '-' . $this_month_r . '-' . $days_this_month, $format = 'Y-m-d') . "' ";
        $sql_clause = " AND ";
    }
    if (function_exists('espresso_member_data') && (espresso_member_data('role') == 'espresso_event_manager' || espresso_member_data('role') == 'espresso_group_admin')) {
        $sql_a .= $sql_clause . " e.wp_user = '******'id') . "' ";
    }
    $sql_a .= " {$sql_clause} e.event_status != 'D' ";
    $sql_a .= ") ORDER BY date DESC, id ASC ";
    $sql_a .= $records_to_show;
    $attendees = $wpdb->get_results($sql_a);
    $total_attendees = $wpdb->num_rows;
    $quantity = 0;
    $att_table_form_url = add_query_arg(array('event_admin_reports' => 'list_attendee_payments', 'event_id' => $EVT_ID), EVT_ADMIN_URL);
    ?>
<form id="attendee-admin-list-page-select-frm" name="attendee_admin_list_page_select_frm" method="post" action="<?php 
    echo $att_table_form_url;
    ?>
">
	<div id="attendee-admin-list-page-select-dv" class="admin-list-page-select-dv">
		<input name="navig" value="<?php 
    _e('Retrieve', 'event_espresso');
    ?>
" type="submit" class="button-secondary">
		<?php 
    //_e('a max total of', 'event_espresso');
    ?>
		<?php 
    $rows = array(50 => 50, 100 => 100, 250 => 250, 500 => 500, 100000 => 'all');
    ?>
		<select name="max_rows" size="1">
			<?php 
    foreach ($rows as $key => $value) {
        ?>
			<?php 
        $selected = $key == $max_rows ? ' selected="selected"' : '';
        ?>
			<option value="<?php 
        echo $key;
        ?>
"<?php 
        echo $selected;
        ?>
><?php 
        echo $value;
        ?>
&nbsp;&nbsp;</option>
			<?php 
    }
    ?>
		</select>		
		<?php 
    _e('rows from the db at a time', 'event_espresso');
    ?>
		<input name="start_rec" value="<?php 
    echo $start_rec;
    ?>
" class="textfield" type="hidden">
		<?php 
    if ($start_rec > 0 && $max_rows < 100000) {
        $prev_rows = $start_rec > $max_rows ? $start_rec - $max_rows - 1 : 0;
        $prev_rows_url = add_query_arg(array('event_admin_reports' => 'list_attendee_payments', 'event_id' => $EVT_ID, 'max_rows' => $max_rows, 'start_rec' => $prev_rows), EVT_ADMIN_URL);
        ?>
		<a id="attendee-admin-load-prev-rows-btn" href="<?php 
        echo $prev_rows_url;
        ?>
" title="load prev rows" class="button-secondary">
			<?php 
        echo __('Previous', 'event_espresso') . ' ' . $max_rows . ' ' . __('rows', 'event_espresso');
        ?>
		</a>
		<?php 
    }
    ?>
		<?php 
    if ($total_attendees >= $max_rows && $max_rows < 100000) {
        $next_rows = $start_rec + $max_rows + 1;
        $next_rows_url = add_query_arg(array('event_admin_reports' => 'list_attendee_payments', 'event_id' => $EVT_ID, 'max_rows' => $max_rows, 'start_rec' => $next_rows), EVT_ADMIN_URL);
        ?>
		<a id="attendee-admin-load-next-rows-btn" href="<?php 
        echo $next_rows_url;
        ?>
" title="load next rows" class="button-secondary">
		<?php 
        echo __('Next', 'event_espresso') . ' ' . $max_rows . ' ' . __('rows', 'event_espresso');
        ?>
		</a> 
		<?php 
    }
    ?>
	</div>
</form>
	
<form id="form1" name="form1" method="post" action="<?php 
    echo $att_table_form_url;
    ?>
">
	<table id="table" class="widefat fixed" width="100%">
		<thead>
			<tr>
				<th class="manage-column column-cb check-column" id="cb" scope="col" style="width:3%;min-width:35px !important;">
					<input type="checkbox">
				</th>
				<th class="manage-column column-att-id" id="att-id" scope="col" title="Click to Sort"style="width:3%;max-width:35px !important;"> 
					<span><?php 
    _e('ID', 'event_espresso');
    ?>
</span> <span class="sorting-indicator"></span> 
				</th>
				<th class="manage-column column-name" id="name" scope="col" title="Click to Sort"style="width: 10%;"> 
					<span><?php 
    _e('Attendee Name', 'event_espresso');
    ?>
</span> <span class="sorting-indicator"></span> 
				</th>
				<th class="manage-column column-registrationid" id="registrationid" scope="col" title="Click to Sort" style="width: 10%;">
				 	<span><?php 
    _e('Reg ID', 'event_espresso');
    ?>
</span> <span class="sorting-indicator"></span> 
				</th>
				<th class="manage-column column-date" id="registration" scope="col" title="Click to Sort" style="width: 10%;"> 
					<span><?php 
    _e('Registered', 'event_espresso');
    ?>
</span> <span class="sorting-indicator"></span> 
				</th>
				<th class="manage-column column-title" id="event-title" scope="col" title="Click to Sort" style="width: 10%;"> 
					<span><?php 
    _e('Event Title', 'event_espresso');
    ?>
</span> <span class="sorting-indicator"></span> 
				</th>
				<th class="manage-column column-title" id="event-time" scope="col" title="Click to Sort" style="width: 8%;"> 
					<span><?php 
    _e('Event Time', 'event_espresso');
    ?>
</span> <span class="sorting-indicator"></span> 
				</th>
				<?php 
    if ($ticketing_installed == true) {
        ?>
				<th class="manage-column column-title" id="attended" scope="col" title="Click to Sort" style="width: 8%;">
				 	<span><?php 
        _e('Attended', 'event_espresso');
        ?>
</span> <span class="sorting-indicator"></span> 
				</th>
				<?php 
    }
    ?>
				<th class="manage-column column-title" id="ticket-option" scope="col" title="Click to Sort" style="width: 13%;">
				 	<span><?php 
    _e('Option', 'event_espresso');
    ?>
</span> <span class="sorting-indicator"></span> 
				</th>
				<th align="center" class="manage-column column-date" id="amount" style="width: 5%;" title="Click to Sort" scope="col">
				 	<span><?php 
    _e('Payment', 'event_espresso');
    ?>
</span> <span class="sorting-indicator"></span> 
				</th>
				<th class="manage-column column-date" id="payment_type" scope="col" title="Click to Sort" style="width: 8%;">
				 	<span><?php 
    _e('Type', 'event_espresso');
    ?>
</span> <span class="sorting-indicator"></span> 
				</th>
				<th class="manage-column column-date" id="coupon" scope="col" title="Click to Sort" style="width: 10%;"> 
					<span><?php 
    _e('Coupon', 'event_espresso');
    ?>
</span> <span class="sorting-indicator"></span> 
				</th>
				<th class="manage-column column-date" id="txn_id" scope="col" title="Click to Sort" style="width: 10%;"> 
					<span><?php 
    _e('Transaction ID', 'event_espresso');
    ?>
</span> <span class="sorting-indicator"></span> 
				</th>
				<th class="manage-column column-date" id="action" scope="col" title="" >
					<?php 
    _e('Actions', 'event_espresso');
    ?>
				</th>
			</tr>
		</thead>
		<tbody>	
<?php 
    if ($total_attendees > 0) {
        foreach ($attendees as $attendee) {
            $id = $attendee->id;
            $registration_id = $attendee->registration_id;
            $lname = htmlspecialchars(stripslashes($attendee->lname), ENT_QUOTES, 'UTF-8');
            $fname = htmlspecialchars(stripslashes($attendee->fname), ENT_QUOTES, 'UTF-8');
            $address = htmlspecialchars(stripslashes($attendee->address), ENT_QUOTES, 'UTF-8');
            $city = htmlspecialchars(stripslashes($attendee->city), ENT_QUOTES, 'UTF-8');
            $state = htmlspecialchars(stripslashes($attendee->state), ENT_QUOTES, 'UTF-8');
            $zip = $attendee->zip;
            $email = '<span style="visibility:hidden">' . $attendee->email . '</span>';
            $phone = $attendee->phone;
            $quantity = $attendee->quantity > 1 ? '<br />(' . __('Total Attendees', 'event_espresso') . ': ' . $attendee->quantity . ')' : '';
            $attended = $attendee->checked_in;
            $ticket_scanned = $attendee->checked_in_quantity;
            $amount_pd = $attendee->amount_pd;
            $payment_status = $attendee->payment_status;
            $payment_date = $attendee->payment_date;
            $date = $attendee->date;
            $event_id = $attendee->event_id;
            $coupon_code = $attendee->coupon_code;
            $txn_id = $attendee->txn_id;
            $txn_type = $attendee->txn_type;
            $price_option = $attendee->price_option;
            $event_time = $attendee->event_time;
            $event_name = $attendee->event_name;
            $event_date = $attendee->start_date;
            ?>
			<tr>
			
				<td class="check-column" style="padding:7px 0 22px 7px; vertical-align:top;">
					<input name="checkbox[<?php 
            echo $id;
            ?>
]" type="checkbox"  title="Delete <?php 
            echo $fname;
            echo $lname;
            ?>
">
				</td>
				
	            <td nowrap="nowrap">
					<?php 
            echo $attendee->id;
            ?>
				</td>
				
	            <td class="row-title"  nowrap="nowrap">
					<a href="admin.php?page=events&amp;event_admin_reports=edit_attendee_record&amp;event_id=<?php 
            echo $event_id;
            ?>
&amp;registration_id=<?php 
            echo $registration_id;
            ?>
&amp;form_action=edit_attendee&amp;id=<?php 
            echo $id;
            ?>
" title="<?php 
            echo 'ID#:' . $id . ' [ REG#: ' . $registration_id . ' ] Email: ' . $attendee->email;
            ?>
">
						<?php 
            echo $fname;
            ?>
 <?php 
            echo $lname;
            ?>
 <?php 
            echo $email;
            ?>
	              </a>
				 </td>
				
	            <td nowrap="nowrap">
					<?php 
            echo $registration_id;
            ?>
				</td>
				
	            <td class="date column-date">
					<?php 
            echo event_date_display($date, get_option('date_format') . ' g:i a');
            ?>
				</td>
				
	            <td nowrap="nowrap">
					<a href="admin.php?page=events&amp;event_admin_reports=list_attendee_payments&amp;event_id=<?php 
            echo $event_id;
            ?>
" title="<?php 
            _e('View attendees for this event', 'event_espresso');
            ?>
">
						<?php 
            echo stripslashes_deep($event_name);
            ?>
					</a>
				</td>
				
	            <td nowrap="nowrap">
					<?php 
            echo event_date_display($event_time, get_option('time_format'));
            ?>
				</td>
				
	            <?php 
            if ($ticketing_installed == true) {
                ?>
	            <td nowrap="nowrap">
					<p style="padding-left:15px">
						<?php 
                echo $attended == 1 || $ticket_scanned >= 1 ? event_espresso_paid_status_icon('Checkedin') : event_espresso_paid_status_icon('NotCheckedin');
                ?>
					</p>
				</td>
	            <?php 
            }
            ?>
				
	            <td nowrap="nowrap">
					<?php 
            echo $price_option;
            ?>
				</td>
				
	            <td class="date column">
					<a href="admin.php?page=events&amp;attendee_pay=paynow&amp;form_action=payment&amp;registration_id=<?php 
            echo $registration_id;
            ?>
&amp;event_admin_reports=enter_attendee_payments&amp;event_id=<?php 
            echo $event_id;
            ?>
" title="<?php 
            _e('Edit Payment', 'event_espresso');
            ?>
 ID: <?php 
            echo $registration_id;
            ?>
">
	              		<p style="padding-left:17px"><?php 
            event_espresso_paid_status_icon($payment_status);
            ?>
</p>
	              	</a> 
				</td>
				
				<td class="">
					<?php 
            echo espresso_payment_type($txn_type);
            ?>
				</td>
				
	            <td class="">
					<?php 
            echo $coupon_code;
            ?>
				</td>
				
	            <td class="">
					<?php 
            echo $txn_id;
            ?>
				</td>
				
	            <td class="" >
	            
	            	<a href="admin.php?page=events&amp;attendee_pay=paynow&amp;form_action=payment&amp;registration_id=<?php 
            echo $registration_id;
            ?>
&amp;event_admin_reports=enter_attendee_payments&amp;event_id=<?php 
            echo $event_id;
            ?>
" title="<?php 
            _e('Edit Payment', 'event_espresso');
            ?>
 ID: <?php 
            echo $registration_id;
            ?>
">
						<img src="<?php 
            echo EVENT_ESPRESSO_PLUGINFULLURL;
            ?>
images/icons/money.png" width="16" height="16" alt="<?php 
            _e('Edit Payment', 'event_espresso');
            ?>
" />
					</a>
	            
	            	<a href="admin.php?page=events&amp;event_admin_reports=edit_attendee_record&amp;registration_id=<?php 
            echo $registration_id;
            ?>
&amp;event_id=<?php 
            echo $event_id;
            ?>
&amp;form_action=edit_attendee" title="<?php 
            _e('Edit Attendee', 'event_espresso');
            ?>
">
						<img src="<?php 
            echo EVENT_ESPRESSO_PLUGINFULLURL;
            ?>
images/icons/user_edit.png" width="16" height="16" alt="<?php 
            _e('Edit Attendee', 'event_espresso');
            ?>
" />
					</a>
	            
	            	<a href="admin.php?page=events&amp;event_admin_reports=resend_email&amp;registration_id=<?php 
            echo $registration_id;
            ?>
&amp;event_id=<?php 
            echo $event_id;
            ?>
&amp;form_action=resend_email" title="<?php 
            _e('Resend Registration Details', 'event_espresso');
            ?>
">
						<img src="<?php 
            echo EVENT_ESPRESSO_PLUGINFULLURL;
            ?>
images/icons/email_link.png" width="16" height="16" alt="<?php 
            _e('Resend Registration Details', 'event_espresso');
            ?>
" />
					</a>
					
	            	<?php 
            if ($espresso_premium == true) {
                ?>
	            	<a href="<?php 
                echo home_url();
                ?>
/?download_invoice=true&amp;admin=true&amp;registration_id=<?php 
                echo $registration_id;
                ?>
" target="_blank"  title="<?php 
                _e('Download Invoice', 'event_espresso');
                ?>
">
						<img src="<?php 
                echo EVENT_ESPRESSO_PLUGINFULLURL;
                ?>
images/icons/page_white_acrobat.png" width="16" height="16" alt="<?php 
                _e('Download Invoice', 'event_espresso');
                ?>
" />
					</a>
					<?php 
            }
            ?>
				
					<?php 
            if ($ticketing_installed == true && function_exists('espresso_ticket_url')) {
                ?>
					<a href="<?php 
                echo espresso_ticket_url($id, $registration_id);
                ?>
" target="_blank"  title="<?php 
                _e('View/Download Ticket', 'event_espresso');
                ?>
">
						<img src="<?php 
                echo EVENT_ESPRESSO_PLUGINFULLURL;
                ?>
images/icons/ticket-arrow-icon.png" width="16" height="16" alt="<?php 
                _e('Download Ticket', 'event_espresso');
                ?>
" />
					</a>
					<?php 
            }
            if ($org_options["use_attendee_pre_approval"] == "Y") {
                ?>
		  				<br/>
		  				<a href="admin.php?page=events&amp;attendee_pay=paynow&amp;form_action=payment&amp;registration_id=<?php 
                echo $registration_id;
                ?>
&amp;event_admin_reports=enter_attendee_payments&amp;event_id=<?php 
                echo $event_id;
                ?>
" title="<?php 
                _e('Edit Payment', 'event_espresso');
                ?>
 ID: <?php 
                echo $registration_id;
                ?>
">
		  				<?php 
                if (is_attendee_approved($event_id, $id)) {
                    ?>
		  					<strong><?php 
                    _e('Approved', 'event_espresso');
                    ?>
</strong><br/>
		  				<?php 
                } else {
                    ?>
		  					<span style="color:#FF0000"><strong><?php 
                    _e('Awaiting approval', 'event_espresso');
                    ?>
</strong></span>
		  				<?php 
                }
                ?>
		  				</a>
	  				<?php 
            }
            ?>
					
				</td>
				
			</tr>
<?php 
        }
    }
    ?>
		</tbody>
	</table>
	
  	<div style="clear:both; margin-bottom:30px;">
	
    	<input name="delete_customer" type="submit" class="button-secondary" id="delete_customer" value="<?php 
    _e('Delete Attendee(s)', 'event_espresso');
    ?>
" style="margin:10px 0 0 0;" onclick="return confirmDelete();" />
		
	    <?php 
    if ($ticketing_installed == true) {
        ?>
	    <input name="attended_customer" type="submit" class="button-secondary" id="attended_customer" value="<?php 
        _e('Mark as Attended', 'event_espresso');
        ?>
" style="margin:10px 0 0 10px;" />
	    <input name="unattended_customer" type="submit" class="button-secondary" id="attended_customer" value="<?php 
        _e('Unmark as Attended', 'event_espresso');
        ?>
" style="margin:10px 0 0 10px;" />
	    <?php 
    }
    ?>
		
	    <a style="margin-left:5px" class="button-secondary" href="admin.php?page=events&amp;action=csv_import">
	    <?php 
    _e('Import Events', 'event_espresso');
    ?>
	    </a> 
		
		<?php 
    if (function_exists('espresso_attendee_import') && $espresso_premium == true) {
        ?>
		<a style="margin-left:5px" class="button-secondary" href="admin.php?page=espresso_attendee_import">
			<?php 
        _e('Import Attendees', 'event_espresso');
        ?>
		</a>
		<?php 
    }
    ?>
		
		<a class="button-secondary" style="margin-left:5px" href="#" onclick="window.location='<?php 
    echo get_bloginfo('wpurl') . "/wp-admin/admin.php?event_espresso&amp;export=report&action=payment&amp;type=excel&amp;";
    echo $EVT_ID ? "event_id=" . $EVT_ID : "all_events=true";
    ?>
'" title="<?php 
    _e('Export to Excel', 'event_espresso');
    ?>
">
	    	<?php 
    _e('Export to Excel', 'event_espresso');
    ?>
	    </a> 
		
		<?php 
    if ($EVT_ID) {
        ?>
		<a style="margin-left:5px"  class="button-secondary"  href="admin.php?page=events&amp;event_admin_reports=add_new_attendee&amp;event_id=<?php 
        echo $EVT_ID;
        ?>
">
			<?php 
        _e('Add Attendee', 'event_espresso');
        ?>
		</a>
		<?php 
    }
    ?>
 
		
		<?php 
    if ($EVT_ID) {
        ?>
		<a style="margin-left:5px" class="button-primary" href="admin.php?page=events&amp;action=edit&amp;event_id=<?php 
        echo $EVT_ID;
        ?>
">
			<?php 
        _e('Edit Event', 'event_espresso');
        ?>
		</a>
		<?php 
    }
    ?>
 
		
	</div>
	
</form>

<h4 style="clear:both"><?php 
    _e('Legend', 'event_espresso');
    ?>
</h4>

<dl style="float:left; margin-left:10px; width:200px">
	<dt>
		<?php 
    event_espresso_paid_status_icon('Completed');
    ?>
 - <?php 
    _e('Completed', 'event_espresso');
    ?>
	</dt>
	<dt>
		<?php 
    event_espresso_paid_status_icon('Incomplete');
    ?>
 - <?php 
    _e('Incomplete', 'event_espresso');
    ?>
	</dt>
    <dt>
		<?php 
    event_espresso_paid_status_icon('Pending');
    ?>
 - <?php 
    _e('Pending', 'event_espresso');
    ?>
	</dt>
	<dt>
		<img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
images/icons/money.png" width="16" height="16" alt="<?php 
    _e('Payment Details', 'event_espresso');
    ?>
" /> - <?php 
    _e('Payment Details', 'event_espresso');
    ?>
	</dt>
</dl>

 <dl style="float:left; margin-left:10px; width:200px">
	<dt>
		<img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
images/icons/email_link.png" width="16" height="16" alt="<?php 
    _e('Resend Details', 'event_espresso');
    ?>
" /> - <?php 
    _e('Resend Email', 'event_espresso');
    ?>
	</dt>
	<dt>
		<img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
images/icons/page_white_acrobat.png" width="16" height="16" alt="<?php 
    _e('Download Invoice', 'event_espresso');
    ?>
" /> - <?php 
    _e('Download Invoice', 'event_espresso');
    ?>
	</dt>
	<dt>
		<img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
images/icons/user_edit.png" width="16" height="16" alt="<?php 
    _e(' Attendee Details', 'event_espresso');
    ?>
" /> - <?php 
    _e('Attendee Details', 'event_espresso');
    ?>
	</dt>
</dl>
<?php 
    $hide = $EVT_ID ? '1,5' : '1,3';
    $hide .= $ticketing_installed ? ',11,12' : ',10,11';
    ?>
<script>
	jQuery(document).ready(function($) {
		/* show the table data */
		var mytable = $('#table').dataTable( {
			"sDom": 'Clfrtip',
			"bAutoWidth": false,
			"bStateSave": true,
			"sPaginationType": "full_numbers",
			"oLanguage": {    "sSearch": "<strong><?php 
    _e('Live Search Filter', 'event_espresso');
    ?>
:</strong> (eg, email, txn id, event, etc.)",
			"sZeroRecords": "<?php 
    _e('No Records Found!', 'event_espresso');
    ?>
" },
			"aoColumns": [
				{ "bSortable": false },
				null,
				<?php 
    echo $ticketing_installed == true ? 'null,' : '';
    ?>
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				{ "bSortable": false }
			],
			"aoColumnDefs": [
				{ "bVisible": false, "aTargets": [<?php 
    echo $hide;
    ?>
] }
			],
			"oColVis": {
				"aiExclude": [0,2],
				"buttonText": "Filter: Show / Hide Columns",
				"bRestore": true
			},
		});
	});
</script>
<?php 
}
function espresso_confirm_registration($registration_id)
{
    global $wpdb, $org_options;
    //Get the questions for the attendee
    $questions = $wpdb->get_results("SELECT ea.answer, eq.question\n\t\t\t\t\t\tFROM " . EVENTS_ANSWER_TABLE . " ea\n\t\t\t\t\t\tLEFT JOIN " . EVENTS_QUESTION_TABLE . " eq ON eq.id = ea.question_id\n\t\t\t\t\t\tWHERE ea.registration_id = '" . $registration_id . "' AND system_name IS NULL ORDER BY eq.sequence asc ");
    //echo $wpdb->last_query;
    $display_questions = '';
    foreach ($questions as $question) {
        $display_questions .= '<p class="espresso_questions"><strong>' . $question->question . '</strong>:<br /> ' . str_replace(',', '<br />', $question->answer) . '</p>';
    }
    //Get the event information
    $events = $wpdb->get_results("SELECT ed.* FROM " . EVENTS_DETAIL_TABLE . " ed\n\t\t\t\t\t\tJOIN " . EVENTS_ATTENDEE_TABLE . " ea\n\t\t\t\t\t\tON ed.id = ea.event_id\n\t\t\t\t\t\tWHERE ea.registration_id='" . $registration_id . "'");
    foreach ($events as $event) {
        $event_id = $event->id;
        $event_name = stripslashes_deep($event->event_name);
        $event_desc = stripslashes_deep($event->event_desc);
        $display_desc = $event->display_desc;
        $event_identifier = $event->event_identifier;
        $reg_limit = $event->reg_limit;
        $active = $event->is_active;
        $send_mail = $event->send_mail;
        $conf_mail = $event->conf_mail;
        $email_id = $event->email_id;
        $alt_email = $event->alt_email;
        $start_date = event_date_display($event->start_date);
        $end_date = $event->end_date;
        $virtual_url = $event->virtual_url;
        $virtual_phone = $event->virtual_phone;
        $event_address = $event->address;
        $event_address2 = $event->address2;
        $event_city = $event->city;
        $event_state = $event->state;
        $event_zip = $event->zip;
        $event_country = $event->country;
        $location = ($event_address != '' ? $event_address : '') . ($event_address2 != '' ? '<br />' . $event_address2 : '') . ($event_city != '' ? '<br />' . $event_city : '') . ($event_state != '' ? ', ' . $event_state : '') . ($event_zip != '' ? '<br />' . $event_zip : '') . ($event_country != '' ? '<br />' . $event_country : '');
        $location_phone = $event->phone;
        $require_pre_approval = $event->require_pre_approval;
        $google_map_link = espresso_google_map_link(array('address' => $event_address, 'city' => $event_city, 'state' => $event_state, 'zip' => $event_zip, 'country' => $event_country));
    }
    //Build links
    $event_url = espresso_reg_url($event_id);
    $event_link = '<a href="' . $event_url . '">' . $event_name . '</a>';
    $sql = "SELECT * FROM " . EVENTS_ATTENDEE_TABLE;
    if ($registration_id != '') {
        $sql .= " WHERE registration_id = '" . $registration_id . "' ";
    } elseif ($attendee_id != '') {
        $sql .= " WHERE id = '" . $attendee_id . "' ";
    } else {
        _e('No ID Supplied', 'event_espresso');
    }
    $sql .= " ORDER BY id ";
    $sql .= " LIMIT 0,1 ";
    //Get the first attendees details
    $attendees = $wpdb->get_results($sql);
    //global $attendee_id;
    foreach ($attendees as $attendee) {
        $attendee_id = $attendee->id;
        $attendee_email = $attendee->email;
        $lname = $attendee->lname;
        $fname = $attendee->fname;
        $address = $attendee->address;
        $address2 = $attendee->address2;
        $city = $attendee->city;
        $state = $attendee->state;
        $zip = $attendee->zip;
        $payment_status = $attendee->payment_status;
        $txn_type = $attendee->txn_type;
        $amount_pd = $attendee->amount_pd;
        $event_cost = $attendee->amount_pd;
        $payment_date = $attendee->payment_date;
        $phone = $attendee->phone;
        $event_time = $attendee->event_time;
        $end_time = $attendee->end_time;
        $date = $attendee->date;
        $pre_approve = $attendee->pre_approve;
    }
    ####### Added by wp-developers ##############
    $pre_approval_check = is_attendee_approved($event_id, $attendee_id);
    ###########################################
    ###### Modified by wp-developers ###############
    if ($pre_approval_check) {
        //Pull in the "Thank You" page template
        if (file_exists(EVENT_ESPRESSO_TEMPLATE_DIR . "payment_page.php")) {
            require_once EVENT_ESPRESSO_TEMPLATE_DIR . "payment_page.php";
            //This is the path to the template file if available
        } else {
            require_once EVENT_ESPRESSO_PLUGINFULLPATH . "templates/payment_page.php";
        }
        if ($amount_pd != '0.00') {
            //Show payment options
            if (file_exists(EVENT_ESPRESSO_GATEWAY_DIR . "gateway_display.php")) {
                require_once EVENT_ESPRESSO_GATEWAY_DIR . "gateway_display.php";
            } else {
                require_once EVENT_ESPRESSO_PLUGINFULLPATH . "gateways/gateway_display.php";
            }
            //Check to see if the site owner wants to send an confirmation eamil before payment is recieved.
            if ($org_options['email_before_payment'] == 'Y') {
                event_espresso_email_confirmations(array('registration_id' => $registration_id, 'send_admin_email' => 'true', 'send_attendee_email' => 'true'));
            }
        } else {
            event_espresso_email_confirmations(array('registration_id' => $registration_id, 'send_admin_email' => 'true', 'send_attendee_email' => 'true'));
        }
    } else {
        if (file_exists(EVENT_ESPRESSO_PLUGINFULLPATH . 'includes/process-registration/pending_approval_page.php')) {
            require_once 'pending_approval_page.php';
            echo espresso_pending_registration_approval($registration_id);
            return;
        }
    }
    ################ End ##############################
    //return __('Your Registration Has Been Confirmed', 'event_espresso');
    //unset($_SESSION['espresso_session']['id']);
    //session_destroy();
}
function enter_attendee_payments()
{
    global $wpdb, $org_options;
    $event_id = $_REQUEST['event_id'];
    $today = date("d-m-Y");
    //Added by Imon
    $multi_reg = false;
    $registration_id = $_REQUEST['registration_id'];
    $registration_ids = array();
    $check = $wpdb->get_row("select * from " . EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE . " where registration_id = '{$registration_id}' ");
    if ($check !== NULL) {
        $registration_id = $check->primary_registration_id;
        $registration_ids = $wpdb->get_results("select * from " . EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE . " where primary_registration_id = '{$registration_id}' ", ARRAY_A);
        $multi_reg = true;
    }
    switch ($_REQUEST['form_action']) {
        //Add payment info
        case 'payment':
            if (isset($_REQUEST['attendee_action']) && $_REQUEST['attendee_action'] == 'post_payment') {
                //Added by Imon
                $primary_row = $wpdb->get_row("select id from " . EVENTS_ATTENDEE_TABLE . " where registration_id = '{$registration_id}' order by id limit 0,1 ");
                $primary_attendee_id = $primary_row->id;
                // GET the primary attendee id because amount paid info is kept with the primary attendee
                $payment_status = isset($_REQUEST['payment_status']) ? $_REQUEST['payment_status'] : '';
                $txn_type = isset($_REQUEST['txn_type']) ? $_REQUEST['txn_type'] : '';
                $txn_id = isset($_REQUEST['txn_id']) ? $_REQUEST['txn_id'] : '';
                //$quantity = isset($_REQUEST[ 'quantity' ]) ? $_REQUEST[ 'quantity' ]:'';
                $amount_pd = isset($_REQUEST['amount_pd']) ? $_REQUEST['amount_pd'] : '';
                $payment_date = isset($_REQUEST['payment_date']) ? $_REQUEST['payment_date'] : '';
                $coupon_code = isset($_REQUEST['coupon_code']) ? $_REQUEST['coupon_code'] : '';
                //Added/updated by Imon
                //Update payment status information for primary attendee
                $sql = "UPDATE " . EVENTS_ATTENDEE_TABLE . " SET payment_status = '{$payment_status}', txn_type = '{$txn_type}', txn_id = '{$txn_id}', amount_pd = '{$amount_pd}', payment_date ='{$payment_date}',  coupon_code ='{$coupon_code}' WHERE registration_id ='" . $registration_id . "' and id = {$primary_attendee_id} ";
                $wpdb->query($sql);
                if (count($registration_ids) > 0) {
                    foreach ($registration_ids as $reg_id) {
                        // Update payment status information for all attendees
                        $sql = "UPDATE " . EVENTS_ATTENDEE_TABLE . " SET payment_status = '{$payment_status}', txn_type = '{$txn_type}', txn_id = '{$txn_id}', payment_date ='{$payment_date}', coupon_code ='{$coupon_code}' WHERE registration_id ='" . $reg_id['registration_id'] . "' ";
                        $wpdb->query($sql);
                    }
                } else {
                    // Update payment status information for all attendees
                    $sql = "UPDATE " . EVENTS_ATTENDEE_TABLE . " SET payment_status = '{$payment_status}', txn_type = '{$txn_type}', txn_id = '{$txn_id}', payment_date ='{$payment_date}', coupon_code ='{$coupon_code}' WHERE registration_id ='" . $registration_id . "' ";
                    $wpdb->query($sql);
                }
                //Send Payment Recieved Email
                if ($_REQUEST['send_payment_rec'] == "send_message") {
                    /*
                     * @todo Do we send an email to each attendee in a group or just the main?
                     */
                    //event_espresso_send_payment_notification( $id );
                    //Added by Imon
                    if (count($registration_ids) > 0) {
                        foreach ($registration_ids as $reg_id) {
                            event_espresso_send_payment_notification(array('registration_id' => $reg_id['registration_id']));
                        }
                    } else {
                        event_espresso_send_payment_notification(array('registration_id' => $registration_id));
                    }
                }
            }
            break;
            //Send Invoice
        //Send Invoice
        case 'send_invoice':
            //Added by Imon
            if ($org_options["use_attendee_pre_approval"] == "Y") {
                $pre_approve = $_REQUEST['pre_approve'];
                if (count($registration_ids) > 0) {
                    foreach ($registration_ids as $reg_id) {
                        $sql = "UPDATE " . EVENTS_ATTENDEE_TABLE . " SET pre_approve = '{$pre_approve}' WHERE registration_id ='" . $reg_id['registration_id'] . "'";
                        $wpdb->query($sql);
                    }
                } else {
                    $sql = "UPDATE " . EVENTS_ATTENDEE_TABLE . " SET pre_approve = '{$pre_approve}' WHERE registration_id ='" . $registration_id . "'";
                    $wpdb->query($sql);
                }
            } else {
                $pre_approve = 0;
            }
            if ($pre_approve == "0") {
                if (count($registration_ids) > 0) {
                    foreach ($registration_ids as $reg_id) {
                        event_espresso_send_invoice($reg_id['registration_id'], $_REQUEST['invoice_subject'], $_REQUEST['invoice_message']);
                    }
                } else {
                    event_espresso_send_invoice($registration_id, $_REQUEST['invoice_subject'], $_REQUEST['invoice_message']);
                }
                echo '<div id="message" class="updated fade"><p><strong>' . __('Invoice Sent', 'event_espresso') . '</strong></p></div>';
            }
            break;
    }
    //Show the forms.
    // $id = $registration_id ;
    $attendees = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . EVENTS_ATTENDEE_TABLE . " WHERE registration_id ='%s' ORDER BY ID LIMIT 1", $registration_id));
    foreach ($attendees as $attendee) {
        $id = $attendee->id;
        //$registration_id = $attendee->registration_id;//Removed by Imon
        $lname = $attendee->lname;
        $fname = $attendee->fname;
        $address = $attendee->address;
        $city = $attendee->city;
        $state = $attendee->state;
        $zip = $attendee->zip;
        $email = $attendee->email;
        $phone = $attendee->phone;
        $date = $attendee->date;
        $payment_status = $attendee->payment_status;
        $txn_type = $attendee->txn_type;
        $txn_id = $attendee->txn_id;
        $amount_pd = $attendee->amount_pd;
        $quantity = $attendee->quantity;
        $payment_date = $attendee->payment_date;
        $event_id = $attendee->event_id;
        $coupon_code = $attendee->coupon_code;
        $pre_approve = $attendee->pre_approve;
        $start_date = $attendee->start_date;
        $event_time = $attendee->event_time;
    }
    $events = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . EVENTS_DETAIL_TABLE . " WHERE id='%d'", $event_id));
    foreach ($events as $event) {
        $event_id = $event->id;
        $event_name = $event->event_name;
        $event_desc = $event->event_desc;
        $event_description = $event->event_desc;
        $event_identifier = $event->event_identifier;
        $cost = isset($event->event_cost) ? $event->event_cost : 0;
        $active = $event->is_active;
    }
    $event_date = event_date_display($start_date . ' ' . $event_time, get_option('date_format') . ' g:i a');
    $total_paid = espresso_attendee_price(array('registration_id' => $_REQUEST['registration_id'], 'session_total' => true));
    if (isset($_REQUEST['status']) && $_REQUEST['status'] == 'saved') {
        ?>

        <div id="message" class="updated fade">
          <p><strong>
            <?php 
        _e('Payment details saved for', 'event_espresso');
        ?>
            <?php 
        echo $fname;
        ?>
 <?php 
        echo $lname;
        ?>
.
            <?php 
        if (isset($_REQUEST['send_payment_rec']) && $_REQUEST['send_payment_rec'] == "send_message") {
            ?>
            <?php 
            _e('Payment notification has been sent.', 'event_espresso');
            ?>
            <?php 
        }
        ?>
            </strong></p>
        </div>
<?php 
    }
    ?>
<div class="metabox-holder">
<div class="postbox">
<?php 
    if (!$multi_reg) {
        ?>
      <h3>
      <?php 
        _e('Name:', 'event_espresso');
        ?>
        <?php 
        echo $fname;
        ?>
 <?php 
        echo $lname;
        ?>
 |
        <?php 
        _e('ID:', 'event_espresso');
        ?>
 <?php 
        echo $id;
        ?>
 |

        <?php 
        _e('Registered For:', 'event_espresso');
        ?>
         <a href="admin.php?page=events&event_admin_reports=list_attendee_payments&event_id=<?php 
        echo $event_id;
        ?>
"><?php 
        echo stripslashes_deep($event_name);
        ?>
</a> - <?php 
        echo $event_date;
        ?>
</h3>
<?php 
    } else {
        ?>
  <h3>
    <?php 
        echo __('Multiple Registration Payment for ', 'event_espresso');
        ?>
 <a href="admin.php?page=events&event_admin_reports=list_attendee_payments&event_id=<?php 
        echo $event_id;
        ?>
"><?php 
        echo stripslashes_deep($event_name);
        ?>
</a> - <?php 
        echo $event_date;
        ?>
  </h3>
  <?php 
    }
    ?>
  <div class="inside">
    <table width="100%" border="0">
      <tr>
        <td><strong>
          <?php 
    _e('Payment Details', 'event_espresso');
    ?>
          </strong></td>
        <td><strong>
          <?php 
    _e('Invoice/Payment Reminder', 'event_espresso');
    ?>
          </strong></td>
      </tr>
      <tr>
        <td valign="top">
        <?php 
    if (count($registration_ids) > 0) {
        echo '<p><strong>' . __('Registration Ids:', 'event_espresso') . '</strong></p>';
        echo '<ul>';
        foreach ($registration_ids as $reg_id) {
            //TODO:Display cost per registration id. At the moment it is not possible to display price per registration id because discount is calculated for total amount [IMON]
            echo '<li># ' . $reg_id['registration_id'] . ' [ <a href="admin.php?page=events&event_admin_reports=edit_attendee_record&event_id=' . $event_id . '&registration_id=' . $reg_id['registration_id'] . '&form_action=edit_attendee">' . __('View/Edit Registration', 'event_espresso') . '</a> ]</li>';
        }
    } else {
        echo '<p><strong>' . __('Registration Id:', 'event_espresso') . '</strong></p>';
        //TODO:Display cost per registration id. At the moment it is not possible to display price per registration id because discount is calculated for total amount [IMON]
        echo '<p># ' . $registration_id . ' [ <a href="admin.php?page=events&event_admin_reports=edit_attendee_record&event_id=' . $event_id . '&registration_id=' . $registration_id . '&form_action=edit_attendee">' . __('View/Edit Registration', 'event_espresso') . '</a> ]</p>';
    }
    echo '</ul><hr style="width:90%; margin:20px 0;" align="left" />';
    ?>
        <form method="POST" action="<?php 
    echo $_SERVER['REQUEST_URI'];
    ?>
&status=saved" class="espresso_form">
            <fieldset>
              <ul>
                <li>
                <label for="payment_status">
                  <?php 
    _e('Payment Status:', 'event_espresso');
    ?>
                </label>
<?php 
    $values = array(array('id' => '', 'text' => __('None', 'event_espresso')), array('id' => 'Completed', 'text' => __('Completed', 'event_espresso')), array('id' => 'Pending', 'text' => __('Pending', 'event_espresso')), array('id' => 'Payment Declined', 'text' => __('Payment Declined', 'event_espresso')), array('id' => 'Incomplete', 'text' => __('Incomplete', 'event_espresso')));
    echo select_input('payment_status', $values, $payment_status);
    ?>
                </li>
                <li>
                  <label for="txn_type">
                    <?php 
    _e('Transaction Type:', 'event_espresso');
    ?>
                  </label>
                  <?php 
    $txn_values = array(array('id' => '', 'text' => __('N/A', 'event_espresso')), array('id' => 'web_accept', 'text' => espresso_payment_type('web_accept')), array('id' => 'CC', 'text' => __('Credit Card', 'event_espresso')), array('id' => 'INV', 'text' => espresso_payment_type('INV')), array('id' => 'OFFLINE', 'text' => espresso_payment_type('OFFLINE')));
    echo select_input('txn_type', $txn_values, $txn_type);
    ?>
                </li>
                <li>
                  <label>
                    <?php 
    _e('Transaction ID:', 'event_espresso');
    ?>
                  </label>
                  <input type="text" name="txn_id" size="45" value ="<?php 
    echo $txn_id;
    ?>
" />
                </li>
                <li>
                  <label>
                    <?php 
    _e('Amount:', 'event_espresso');
    ?>
                  </label>
                  <?php 
    //TODO:Need to check this after pricing module is done [IMON]
    echo $org_options['currency_symbol'];
    ?>
                    <input style="width:100px;" readonly="true" type="text" name="amount_pd" size="20" value ="<?php 
    echo $total_paid;
    ?>
" /> <?php 
    echo ' [ <a href="admin.php?page=events&event_admin_reports=edit_attendee_record&event_id=' . $event_id . '&registration_id=' . $registration_id . '&form_action=edit_attendee&show_payment=true">' . __('Edit Payment', 'event_espresso') . '</a> ] ';
    ?>
                </li>
                <li>
                  <label>
                    <?php 
    _e('Coupon Code:', 'event_espresso');
    ?>
                    </label>
                  <input type="text" name="coupon_code" size="45" value ="<?php 
    echo $coupon_code;
    ?>
" />
                </li>
                <?php 
    /*?><li>
        <label>
          <?php _e( 'How Many People:', 'event_espresso' ); ?>
        </label>
        <input type="text" name="quantity" size="45" value ="<?php echo espresso_count_attendees_for_registration($id); ?>" />
      </li><?php */
    ?>
                <li>
					<label><?php 
    _e('Date Paid:', 'event_espresso');
    ?>
</label>
					<input type="text" name="payment_date" size="45" value ="<?php 
    echo !empty($payment_date) ? event_date_display($payment_date) : event_date_display($today);
    ?>
" />
                </li>
                <li>
                  <label>
                    <?php 
    _e('Do you want to send a payment recieved notice to registrant?', 'event_espresso');
    ?>
                  </label>
                  <input type="radio" name="send_payment_rec" value="send_message">
                  <?php 
    _e('Yes', 'event_espresso');
    ?>
                  <input type="radio" name="send_payment_rec" checked value="N">
                  <?php 
    _e('No', 'event_espresso');
    ?>
                </li>
                <input type="hidden" name="id" value="<?php 
    echo $id;
    ?>
">
                <input type="hidden" name="registration_id" value="<?php 
    echo $registration_id;
    ?>
">
                <input type="hidden" name="form_action" value="payment">
                <input type="hidden" name="attendee_pay" value="paynow">
                <input type="hidden" name="event_id" value="<?php 
    echo $event_id;
    ?>
">
                <input type="hidden" name="attendee_action" value="post_payment">
                <li>
                  <input type="submit" name="Submit" value="Update Payment">
                </li>
              </ul>
            </fieldset>
          </form></td>
        <td valign="top"><form method='post' action="<?php 
    echo $_SERVER['REQUEST_URI'];
    ?>
&status=invoiced">
            <input type="hidden" name="id" value="<?php 
    echo $id;
    ?>
">
            <input type="hidden" name="form_action" value="send_invoice">
            <input type="hidden" name="event_id" value="<?php 
    echo $event_id;
    ?>
">
            <ul>
              <li>
                <?php 
    _e('Use a ', 'event_espresso');
    ?>
                <a href="admin.php?page=event_emails" target="_blank">
                <?php 
    _e('pre-existing email', 'event_espresso');
    ?>
                </a>? <?php 
    echo espresso_db_dropdown('id', 'email_name', EVENTS_EMAIL_TABLE, 'email_name', '', 'desc') . ' <a class="thickbox" href="#TB_inline?height=300&width=400&inlineId=email_manager_info"><img src="' . EVENT_ESPRESSO_PLUGINFULLURL . '/images/question-frame.png" width="16" height="16" /></a>';
    ?>
 </li>
              <li>
                <?php 
    _e('OR', 'event_espresso');
    ?>
              </li>
              <li>
                <?php 
    _e('Create a custom email:', 'event_espresso');
    ?>
              </li>
              <li>
                <?php 
    _e('Invoice Subject', 'event_espresso');
    ?>
                :
                <input type="text" name="invoice_subject" size="45" value="<?php 
    _e('Payment Reminder for [event]', 'event_espresso');
    ?>
" />
              </li>
              <li>
                <p>
                  <?php 
    _e('Message:', 'event_espresso');
    ?>
                </p>
               
				<div class="postbox">
									 <?php 
    $email_content = __('Dear [fname] [lname], <p>Our records show that we have not received your payment of [cost] for [event_link].</p> <p>Please visit [payment_url] to view your payment options.</p><p>[invoice_link]</p><p>Sincerely,<br />' . ($Organization = $org_options['organization'] . '</p>'), 'event_espresso');
    if (function_exists('wp_editor')) {
        $args = array("textarea_rows" => 5, "textarea_name" => "invoice_message", "editor_class" => "my_editor_custom");
        wp_editor(espresso_admin_format_content($email_content), "invoice_message", $args);
    } else {
        echo '<textarea name="invoice_message" class="theEditor" id="invoice_message">' . espresso_admin_format_content($email_content) . '</textarea>';
        espresso_tiny_mce();
    }
    ?>
										<table id="email-confirmation-form" cellspacing="0">
											<tbody>
												<tr>
													<td class="aer-word-count"></td>
													<td class="autosave-info"><span>&nbsp;</span></td>
												</tr>
											</tbody>
										</table>
										<p><a class="thickbox" href="#TB_inline?height=300&width=400&inlineId=custom_email_info">
														<?php 
    _e('View Custom Email Tags', 'event_espresso');
    ?>
</a> | <a class="thickbox" href="#TB_inline?height=300&width=400&inlineId=custom_email_example">
														<?php 
    _e('Email Example', 'event_espresso');
    ?>
</a></p>
									</div>
									
              </li>
              <?php 
    if ($org_options["use_attendee_pre_approval"] == "Y") {
        $pre_approve = is_attendee_approved($event_id, $id) == true ? 1 : 0;
        ?>
              <li>
                <?php 
        _e("Attendee approved?", "event_espresso");
        ?>
                :
                <?php 
        $pre_approval_values = array(array('id' => '0', 'text' => __('Yes', 'event_espresso')), array('id' => '1', 'text' => __('No', 'event_espresso')));
        echo select_input("pre_approve", $pre_approval_values, $pre_approve);
        ?>
                <br />
                <?php 
        _e("(If not approved then invoice will not be sent.)", "event_espresso");
        ?>
              </li>
              <?php 
    }
    ?>
              <li>
                <input type="submit" name="Submit" value="Send Invoice">
              </li>
            </ul>
          </form></td>
      </tr>
    </table>
    <p> <strong> <a href="admin.php?page=events&event_id=<?php 
    echo $event_id;
    ?>
&event_admin_reports=list_attendee_payments"> &lt;&lt;
      <?php 
    _e('Back to List', 'event_espresso');
    ?>
      </a> </strong> </p>
  </div>
</div>
<?php 
    //This show what tags can be added to a custom email.
    event_espresso_custom_email_info();
    //event_list_attendees();
}
function enter_attendee_payments()
{
    global $wpdb, $org_options;
    require_once EVENT_ESPRESSO_PLUGINFULLPATH . "includes/functions/attendee_functions.php";
    $notifications['success'] = array();
    $notifications['error'] = array();
    $failed_nonce_msg = '
<div id="message" class="error">
	<p>
		<strong>' . __('An Error Occurred. The request failed to pass a security check.', 'event_espresso') . '</strong><br/>
		<span style="font-size:.9em;">' . __('Please press the back button on your browser to return to the previous page.', 'event_espresso') . '</span>
	</p>
</div>';
    $multi_reg = FALSE;
    $event_id = isset($_POST['event_id']) ? absint($_POST['event_id']) : isset($_REQUEST['event_id']) ? absint($_REQUEST['event_id']) : '';
    $registration_id = isset($_POST['registration_id']) ? sanitize_text_field($_POST['registration_id']) : isset($_REQUEST['registration_id']) ? sanitize_text_field($_REQUEST['registration_id']) : FALSE;
    $registration_ids = array();
    //echo '<h4>$registration_id : ' . $registration_id . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
    $SQL = "SELECT * FROM " . EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE . " WHERE registration_id =%s LIMIT 1";
    if ($check = $wpdb->get_row($wpdb->prepare($SQL, $registration_id))) {
        //printr( $check, '$check  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
        $registration_id = $check->primary_registration_id;
        $SQL = "SELECT * FROM " . EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE . " WHERE primary_registration_id =%s";
        $registration_ids = $wpdb->get_results($wpdb->prepare($SQL, $registration_id), ARRAY_A);
        $registration_ids = $registration_ids !== FALSE ? $registration_ids : array();
        $multi_reg = TRUE;
    }
    //echo '<h4>$registration_id : ' . $registration_id . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
    //printr( $registration_ids, '$registration_ids  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
    switch ($_REQUEST['form_action']) {
        //Add payment info
        case 'payment':
            if (isset($_POST['attendee_action']) && $_POST['attendee_action'] == 'post_payment') {
                if (!wp_verify_nonce($_POST['_wpnonce'], 'payment_' . $registration_id . '_post_payment_nonce')) {
                    wp_die($failed_nonce_msg);
                }
                $attendees_to_email = array();
                // get the primary attendee id because amount paid info is kept with the primary attendee
                $SQL = "SELECT id, payment_status FROM " . EVENTS_ATTENDEE_TABLE . " WHERE registration_id =%s AND is_primary = 1 ORDER BY id LIMIT 0,1 ";
                $primary_att = $wpdb->get_row($wpdb->prepare($SQL, $registration_id));
                if (!$primary_att) {
                    $notifications['error'][] = __('An error occured. The primary attendee details could not be retrieved from the database.', 'event_espresso');
                } else {
                    $txn_type = isset($_POST['txn_type']) ? $_POST['txn_type'] : apply_filters('filter_hook_event_espresso_enter_attendee_payments_remove_require_txn_type', FALSE);
                    $txn_id = isset($_POST['txn_id']) ? $_POST['txn_id'] : apply_filters('filter_hook_event_espresso_enter_attendee_payments_remove_require_txn_id', FALSE);
                    $payment_date = isset($_POST['payment_date']) ? date_i18n(get_option('date_format'), strtotime($_POST['payment_date'])) : FALSE;
                    $coupon_code = isset($_POST['coupon_code']) ? $_POST['coupon_code'] : '';
                    $total_owing = isset($_POST['total_owing']) ? (double) number_format(sanitize_text_field($_POST['total_owing']), 2, '.', '') : 0.0;
                    $amount_pd = isset($_POST['amount_pd']) ? (double) number_format(sanitize_text_field($_POST['amount_pd']), 2, '.', '') : 0.0;
                    $new_payment = isset($_POST['new_payment']) && $_POST['new_payment'] != '' ? (double) number_format(sanitize_text_field($_POST['new_payment']), 2, '.', '') : 0.0;
                    $upd_payment_status = isset($_POST['payment_status']) ? $_POST['payment_status'] : 'Pending';
                    // if making a payment, we are going to require the txn type and txn id
                    if ($new_payment != 0.0) {
                        $fail = FALSE;
                        if (!$txn_type) {
                            $notifications['error'][] = __('You must enter a Transaction Type when making a payment.', 'event_espresso');
                            $fail = TRUE;
                        }
                        if (!$txn_id) {
                            $notifications['error'][] = __('You must enter a Transaction ID when making a payment.', 'event_espresso');
                            $fail = TRUE;
                        }
                        if ($fail) {
                            break;
                        }
                        $upd_total = $amount_pd + $new_payment;
                    } else {
                        $upd_total = $amount_pd;
                    }
                    // compare new total_cost with amount_pd
                    if ($new_payment != 'Cancelled') {
                        if ($new_payment == $total_owing) {
                            $upd_payment_status = 'Completed';
                        } elseif ($new_payment < $total_owing) {
                            $upd_payment_status = isset($_POST['payment_status']) && $_POST['payment_status'] == 'Incomplete' ? 'Incomplete' : 'Pending';
                        } elseif ($new_payment > $total_owing) {
                            $upd_payment_status = 'Refund';
                        }
                    }
                    //Update payment status information for primary attendee
                    $set_cols_and_values = array('payment_status' => $upd_payment_status, 'txn_type' => $txn_type, 'txn_id' => $txn_id, 'payment_date' => $payment_date, 'coupon_code' => $coupon_code, 'amount_pd' => $upd_total);
                    $set_format = array('%s', '%s', '%s', '%s', '%s', '%f');
                    $where_cols_and_values = array('id' => $primary_att->id);
                    $where_format = array('%d');
                    // run the update
                    $upd_success = $wpdb->update(EVENTS_ATTENDEE_TABLE, $set_cols_and_values, $where_cols_and_values, $set_format, $where_format);
                    // if there was an actual error
                    if ($upd_success === FALSE) {
                        $notifications['error'][] = __('An error occured. The attendee payment details could not be updated.', 'event_espresso');
                    } else {
                        $attendee_data = array('attendee_id' => $primary_att->id, 'payment_status' => $upd_payment_status, 'registration_id' => $registration_id, 'total_cost' => $upd_total, 'txn_type' => __('Manual Website Payment', 'event_espresso'), 'txn_id' => $txn_id);
                        do_action('action_hook_espresso_update_attendee_payment_status', $attendee_data);
                        if (count($registration_ids) > 0) {
                            foreach ($registration_ids as $reg_id) {
                                // Update payment status information for all attendees
                                // remove amount_pd from update data, since that only applies to the primary attendee
                                unset($set_cols_and_values['amount_pd']);
                                $set_format = array('%s', '%s', '%s', '%s', '%s');
                                $where_cols_and_values = array('registration_id' => $reg_id['registration_id']);
                                $where_format = array('%s');
                                // run the update
                                $upd_success = $wpdb->update(EVENTS_ATTENDEE_TABLE, $set_cols_and_values, $where_cols_and_values, $set_format, $where_format);
                                // if there was an actual error
                                if ($upd_success === FALSE) {
                                    $notifications['error'][] = __('An error occured. The payment details for the additional attendees could not be updated.', 'event_espresso');
                                }
                                $attendees_to_email[] = array('registration_id' => $reg_id['registration_id']);
                            }
                        } else {
                            // Update payment status information for all attendees
                            // remove amount_pd from update data, since that only applies to the primary attendee
                            unset($set_cols_and_values['amount_pd']);
                            $set_format = array('%s', '%s', '%s', '%s', '%s');
                            $where_cols_and_values = array('registration_id' => $registration_id);
                            $where_format = array('%s');
                            // run the update
                            $upd_success = $wpdb->update(EVENTS_ATTENDEE_TABLE, $set_cols_and_values, $where_cols_and_values, $set_format, $where_format);
                            // if there was an actual error
                            if ($upd_success === FALSE) {
                                $notifications['error'][] = __('An error occured. The payment details for the additional attendees could not be updated.', 'event_espresso');
                            }
                        }
                        //Send Payment Recieved Email
                        $send_payment_rec = isset($_POST['send_payment_rec']) ? $_POST['send_payment_rec'] : FALSE;
                        if ($send_payment_rec == "send_message") {
                            //event_espresso_send_payment_notification( $id );
                            if (count($attendees_to_email) > 0) {
                                //printr( $attendees_to_email, '$attendees_to_email  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); wp_die();
                                foreach ($attendees_to_email as $attendee_to_email) {
                                    $result = event_espresso_send_payment_notification($attendee_to_email);
                                    if (!empty($result)) {
                                        $notifications['error'][] = $result;
                                    }
                                }
                            } else {
                                $result = event_espresso_send_payment_notification(array('registration_id' => $registration_id));
                                if (!empty($result)) {
                                    $notifications['error'][] = $result;
                                }
                            }
                        }
                    }
                    // let's base our success on the lack of errors
                    $notifications['success'][] = empty($notifications['error']) ? __('All attendee payment details have been successfully updated.', 'event_espresso') : __('Some attendee payment details were successfully updated, but the following error(s) may have prevented others from being updated:', 'event_espresso');
                }
            }
            break;
            //Send Invoice
        //Send Invoice
        case 'send_invoice':
            if (!wp_verify_nonce($_POST['_wpnonce'], 'send_invoice_' . $registration_id . '_nonce')) {
                wp_die($failed_nonce_msg);
            }
            if ($org_options["use_attendee_pre_approval"] == "Y") {
                $pre_approve = $_POST['pre_approve'];
                if (count($registration_ids) > 0) {
                    foreach ($registration_ids as $reg_id) {
                        $SQL = "UPDATE " . EVENTS_ATTENDEE_TABLE . " SET pre_approve = %s WHERE registration_id = %s";
                        $wpdb->query($wpdb->prepare($SQL, $pre_approve, $reg_id['registration_id']));
                    }
                } else {
                    $SQL = "UPDATE " . EVENTS_ATTENDEE_TABLE . " SET pre_approve = %s WHERE registration_id = %s";
                    $wpdb->query($wpdb->prepare($SQL, $pre_approve, $registration_id));
                }
            } else {
                $pre_approve = 0;
            }
            if ($pre_approve == "0") {
                if (count($registration_ids) > 0) {
                    $reg_attendees = array();
                    foreach ($registration_ids as $reg_id) {
                        $SQL = 'SELECT * FROM ' . EVENTS_ATTENDEE_TABLE . ' WHERE registration_id =%s';
                        $more_reg_attendees = $wpdb->get_results($wpdb->prepare($SQL, $reg_id['registration_id']), 'OBJECT_K');
                        foreach ($more_reg_attendees as $another_reg_attendee) {
                            $reg_attendees[$another_reg_attendee->email] = $another_reg_attendee;
                        }
                    }
                    foreach ($reg_attendees as $reg_attendee) {
                        event_espresso_send_invoice($reg_attendee->registration_id, $_POST['invoice_subject'], $_POST['invoice_message']);
                    }
                } else {
                    event_espresso_send_invoice($registration_id, $_POST['invoice_subject'], $_POST['invoice_message']);
                }
                $notifications['success'][] = __('Invoice Sent.', 'event_espresso');
            }
            break;
    }
    $SQL = "SELECT * FROM " . EVENTS_ATTENDEE_TABLE . " WHERE registration_id ='%s' ORDER BY id LIMIT 1";
    $attendee = $wpdb->get_row($wpdb->prepare($SQL, $registration_id));
    if ($attendee === FALSE) {
        echo '<div id="message" class="error"><p><strong>' . __('An error occured. The requested attendee data could not be found.', 'event_espresso') . '</strong></p></div>';
        exit;
    }
    $id = $attendee->id;
    $lname = $attendee->lname;
    $fname = $attendee->fname;
    $address = $attendee->address;
    $city = $attendee->city;
    $state = $attendee->state;
    $zip = $attendee->zip;
    $email = $attendee->email;
    $phone = $attendee->phone;
    $date = $attendee->date;
    $payment_status = $attendee->payment_status;
    $txn_type = $attendee->txn_type;
    $txn_id = $attendee->txn_id;
    $quantity = $attendee->quantity;
    $payment_date = $attendee->payment_date;
    $event_id = $attendee->event_id;
    $coupon_code = $attendee->coupon_code;
    $pre_approve = $attendee->pre_approve;
    $start_date = $attendee->start_date;
    $event_time = $attendee->event_time;
    $amount_pd = $attendee->amount_pd;
    $total_cost = $attendee->total_cost;
    $orig_price = $attendee->orig_price;
    $final_price = $attendee->final_price;
    $SQL = "SELECT * FROM " . EVENTS_DETAIL_TABLE . " WHERE id='%d'";
    $event = $wpdb->get_row($wpdb->prepare($SQL, $event_id));
    if ($event === FALSE) {
        echo '<div id="message" class="error"><p><strong>' . __('An error occured. The event data for this registration could not be found.', 'event_espresso') . '</strong></p></div>';
        exit;
    }
    $event_id = $event->id;
    $event_name = $event->event_name;
    $event_desc = $event->event_desc;
    $event_description = $event->event_desc;
    $event_identifier = $event->event_identifier;
    $cost = isset($event->event_cost) ? $event->event_cost : 0;
    $active = $event->is_active;
    $event_date = event_date_display($start_date . ' ' . $event_time, get_option('date_format') . ' g:i a');
    //	$total_paid = espresso_attendee_price(array('registration_id'=>$_REQUEST['registration_id'], 'session_total'=>true));
    // display success messages
    if (!empty($notifications['success'])) {
        $success_msg = implode($notifications['success'], '<br />');
        ?>
			
<div id="message" class="updated fade">
<p>
	<strong><?php 
        echo $success_msg;
        ?>
</strong>
</p>
</div>

	<?php 
    }
    // display error messages
    if (!empty($notifications['error'])) {
        $error_msg = implode($notifications['error'], '<br />');
        ?>
			
<div id="message" class="error">
<p>
	<strong><?php 
        echo $error_msg;
        ?>
</strong>
</p>
</div>

	<?php 
    }
    ?>

<div>
	<p>				
		<a href="admin.php?page=events&event_id=<?php 
    echo $event_id;
    ?>
&event_admin_reports=list_attendee_payments">
			 <strong><span class="laquo big-text">&laquo;&nbsp;</span><?php 
    _e('Back to Attendees List', 'event_espresso');
    ?>
</strong>
		</a>				
	</p>
</div>		
		
<div class="metabox-holder">
	<div class="postbox">
		<?php 
    // create attendee list link
    $list_att_url_params = array('event_admin_reports' => 'list_attendee_payments', 'event_id' => $event_id);
    // add url params
    $list_attendee_link = add_query_arg($list_att_url_params, 'admin.php?page=events');
    ?>
		<?php 
    if (!$multi_reg) {
        ?>
		<h3>
			<?php 
        _e('Name:', 'event_espresso');
        ?>
			<b><?php 
        echo $fname;
        ?>
 <?php 
        echo $lname;
        ?>
</b>&nbsp;&nbsp;|&nbsp;&nbsp;
			<?php 
        _e('ID:', 'event_espresso');
        ?>
			<?php 
        echo $id;
        ?>
&nbsp;&nbsp;|&nbsp;&nbsp;
			<?php 
        _e('Registered For:', 'event_espresso');
        ?>
			<a href="<?php 
        echo $list_attendee_link;
        ?>
"><?php 
        echo stripslashes_deep($event_name);
        ?>
</a> - <?php 
        echo $event_date;
        ?>
		</h3>
			
		<?php 
    } else {
        ?>
		
		<h3>
			<?php 
        echo __('Multiple Registration Payment for ', 'event_espresso');
        ?>
 <a href="<?php 
        echo $list_attendee_link;
        ?>
"><?php 
        echo stripslashes_deep($event_name);
        ?>
</a> - <?php 
        echo $event_date;
        ?>
		</h3>
		
		<?php 
    }
    ?>
		
		<div class="inside">
			<table width="100%" border="0">
				<tr>
					<td>
						<h4 class="qrtr-margin"><strong><?php 
    _e('Payment Details', 'event_espresso');
    ?>
</strong></h4>
					</td>
					<td>
						<h4 class="qrtr-margin"><strong><?php 
    _e('Invoice/Payment Reminder', 'event_espresso');
    ?>
</strong></h4>
					</td>
				</tr>
				<tr>
					<td valign="top">
						<?php 
    // create edit attendee link
    $edit_att_url_params = array('event_admin_reports' => 'edit_attendee_record', 'form_action' => 'edit_attendee', 'registration_id' => $registration_id, 'event_id' => $event_id);
    // add url params
    $edit_attendee_link = add_query_arg($edit_att_url_params, 'admin.php?page=events');
    ?>
						
						<?php 
    if (count($registration_ids) > 0) {
        ?>
				
						<p>
							<strong><?php 
        _e('Registration Ids:', 'event_espresso');
        ?>
</strong>
						</p>
						<ul>
							<?php 
        foreach ($registration_ids as $reg_id) {
            ?>
					
		                		<li>
								#&nbsp;<?php 
            echo $reg_id['registration_id'];
            ?>
&nbsp;&nbsp;
								<a href="<?php 
            echo $edit_attendee_link;
            ?>
"><?php 
            _e('View / Edit Registration', 'event_espresso');
            ?>
</a>
							</li>				
							<?php 
        }
        ?>
						</ul>
						
						<?php 
    } else {
        ?>
				
						<p>
							<strong><?php 
        _e('Registration Id:', 'event_espresso');
        ?>
</strong>
						</p>
						<p>
							#&nbsp;<?php 
        echo $registration_id;
        ?>
&nbsp;&nbsp;<a href="<?php 
        echo $edit_attendee_link;
        ?>
"><?php 
        _e('View/Edit Registration', 'event_espresso');
        ?>
</a>
						</p>
						
						<?php 
    }
    ?>
				
						<hr style="width:90%; margin:20px 0;" align="left" />

						<form method="POST" action="<?php 
    echo $_SERVER['REQUEST_URI'];
    ?>
" class="espresso_form">
							<fieldset>
								<ul>
									<li>
										<label>
											<?php 
    _e('Payment Date:', 'event_espresso');
    ?>
										</label>
										<input type="text" class="medium-text" name="payment_date" size="45" value ="<?php 
    echo !empty($payment_date) ? event_date_display($payment_date) : event_date_display(date("d-m-Y"));
    ?>
" />
									</li>
									<li>
										<label for="payment_status">
											<?php 
    _e('Payment Status:', 'event_espresso');
    ?>
										</label>
										<?php 
    $values = array(array('id' => '', 'text' => __('- please select -', 'event_espresso')), array('id' => 'Completed', 'text' => __('Completed', 'event_espresso')), array('id' => 'Pending', 'text' => __('Pending', 'event_espresso')), array('id' => 'Payment Declined', 'text' => __('Payment Declined', 'event_espresso')), array('id' => 'Cancelled', 'text' => __('Cancelled', 'event_espresso')), array('id' => 'Incomplete', 'text' => __('Incomplete', 'event_espresso')), array('id' => 'Refund', 'text' => __('Overpaid', 'event_espresso')));
    echo select_input('payment_status', $values, $payment_status);
    ?>
									</li>
									<li>
										<label>
											<?php 
    _e('Total Amount Owing:', 'event_espresso');
    ?>
 ( <?php 
    echo $org_options['currency_symbol'];
    ?>
 )
										</label>
										<?php 
    $amount_owing = number_format($total_cost - $amount_pd, 2, '.', '');
    if ($amount_owing == 0.0) {
        $amnt_class = ' full-payment';
    } elseif ($amount_owing < $total_cost || $amount_owing > $total_cost) {
        $amnt_class = ' part-payment';
    } elseif ($amount_owing == $total_cost) {
        $amnt_class = ' no-payment';
    }
    ?>
									
										<input class="small-text algn-rght<?php 
    echo $amnt_class;
    ?>
" type="text" name="ttl_ow" disabled="true" value ="<?php 
    echo $amount_owing;
    ?>
" />
										<input type="hidden" name="total_owing" value ="<?php 
    echo $amount_owing;
    ?>
" />&nbsp;&nbsp;
										<a href="admin.php?page=events&event_admin_reports=edit_attendee_record&event_id=<?php 
    echo $event_id;
    ?>
&registration_id=<?php 
    echo $registration_id;
    ?>
&form_action=edit_attendee&show_payment=true">
											<?php 
    _e('Edit Ticket Price(s)', 'event_espresso');
    ?>
										</a>
									</li>
									<li>
										<label>
											<?php 
    _e('Total Amount Paid to Date:', 'event_espresso');
    ?>
 ( <?php 
    echo $org_options['currency_symbol'];
    ?>
 )
										</label>										
										<input class="small-text algn-rght<?php 
    echo $amnt_class;
    ?>
" type="text" name="amnt_pd" disabled="true" value ="<?php 
    echo $amount_pd;
    ?>
" />
										<input type="hidden" name="amount_pd" value ="<?php 
    echo $amount_pd;
    ?>
" />
									</li>
									<li>
										<label>
											<?php 
    _e('Enter New Payment Amount:', 'event_espresso');
    ?>
 ( <?php 
    echo $org_options['currency_symbol'];
    ?>
 )
										</label>										
										<input class="small-text algn-rght" type="text" name="new_payment" value ="" />
									</li>
									<li>
										<label>
											<?php 
    _e('Coupon Code:', 'event_espresso');
    ?>
										</label>
										<input type="text" class="medium-text" name="coupon_code" size="45" value ="<?php 
    echo $coupon_code;
    ?>
" />
									</li>
									<li>
										<label for="txn_type">
											<?php 
    _e('Transaction Type:', 'event_espresso');
    ?>
										</label>
										<?php 
    //												$txn_values=array(
    //													array('id' => '', 'text' => __('N/A', 'event_espresso')),
    //													array('id' => 'web_accept', 'text' => espresso_payment_type('web_accept')),
    //													array('id' => 'CC', 'text' => __('Credit Card', 'event_espresso')),
    //													array('id' => 'INV', 'text' => espresso_payment_type('INV')),
    //													array('id' => 'OFFLINE', 'text' => espresso_payment_type('OFFLINE')),
    //												);
    //												echo select_input('txn_type', $txn_values, $txn_type);
    ?>
											<input type="text" class="medium-text" name="txn_type" size="45" value ="<?php 
    echo stripslashes_deep(htmlentities($txn_type));
    ?>
" />
										</li>
									<li>
										<label>
											<?php 
    _e('Transaction ID: ', 'event_espresso');
    ?>
 <span class="smaller-text"><?php 
    _e('( or cheque #, gateway response, etc )', 'event_espresso');
    ?>
</span>
										</label>
										<input type="text" name="txn_id" size="45" value ="<?php 
    echo $txn_id;
    ?>
" />
									</li>
									<li>
										<label>
											<h4><?php 
    _e('Email Notice', 'event_espresso');
    ?>
</h4>
											<?php 
    _e('Do you want to send a payment received notice to registrant?', 'event_espresso');
    ?>
										</label>
										<label class="radio-btn-lbl">
											<input type="radio" name="send_payment_rec" value="send_message">
											<span class="big-text"><?php 
    _e('Yes', 'event_espresso');
    ?>
</span>
										</label>
										<label class="radio-btn-lbl">
											<input type="radio" name="send_payment_rec" checked value="N">
											<span class="big-text"><?php 
    _e('No', 'event_espresso');
    ?>
</span>
										</label>
									</li>
									<li>
										<p><br/><input type="submit" name="Submit" class="button-primary action"   value="Update Payment"></p>
									</li>
								</ul>
							</fieldset>
							<input type="hidden" name="id" value="<?php 
    echo $id;
    ?>
">
							<input type="hidden" name="registration_id" value="<?php 
    echo $registration_id;
    ?>
">
							<input type="hidden" name="form_action" value="payment">
							<input type="hidden" name="event_id" value="<?php 
    echo $event_id;
    ?>
">
							<input type="hidden" name="attendee_action" value="post_payment">
							<?php 
    wp_nonce_field('payment_' . $registration_id . '_post_payment_nonce');
    ?>
						</form>
					</td>
					<td valign="top">
						<form class="espresso_form" method='post' action="<?php 
    echo $_SERVER['REQUEST_URI'];
    ?>
">
							<input type="hidden" name="id" value="<?php 
    echo $id;
    ?>
">
							<input type="hidden" name="form_action" value="send_invoice">
							<input type="hidden" name="event_id" value="<?php 
    echo $event_id;
    ?>
">
							<input type="hidden" name="registration_id" value="<?php 
    echo $registration_id;
    ?>
">
							<?php 
    wp_nonce_field('send_invoice_' . $registration_id . '_nonce');
    ?>
							<ul>
								<li>
									<?php 
    _e('Use a ', 'event_espresso');
    ?>
									<a href="admin.php?page=event_emails" target="_blank">
									<?php 
    _e('pre-existing email', 'event_espresso');
    ?>
									</a>? <?php 
    echo espresso_db_dropdown('id', 'email_name', EVENTS_EMAIL_TABLE, 'email_name', '', 'desc') . ' <a class="thickbox" href="#TB_inline?height=300&width=400&inlineId=email_manager_info"><img src="' . EVENT_ESPRESSO_PLUGINFULLURL . '/images/question-frame.png" width="16" height="16" /></a>';
    ?>
 </li>
								<li>
									<?php 
    _e('OR', 'event_espresso');
    ?>
								</li>
								<li>
									<?php 
    _e('Create a custom email:', 'event_espresso');
    ?>
								</li>
								<li>
									<?php 
    _e('Invoice Subject', 'event_espresso');
    ?>
									:
									<input type="text" name="invoice_subject" size="45" value="<?php 
    _e('Payment Reminder for [event]', 'event_espresso');
    ?>
" />
								</li>
								<li>
									<p>
										<?php 
    _e('Message:', 'event_espresso');
    ?>
									</p>
									<div class="postbox">
										<?php 
    $email_content = __('Dear [fname] [lname], <p>Our records show that we have not received your payment of [cost] for [event_link].</p> <p>Please visit [payment_url] to view your payment options.</p><p>[invoice_link]</p><p>Sincerely,<br />' . ($Organization = $org_options['organization'] . '</p>'), 'event_espresso');
    if (function_exists('wp_editor')) {
        $args = array("textarea_rows" => 8, "textarea_name" => "invoice_message", "editor_class" => "my_editor_custom");
        wp_editor(espresso_admin_format_content($email_content), "invoice_message", $args);
    } else {
        echo '<textarea name="invoice_message" class="theEditor" id="invoice_message">' . espresso_admin_format_content($email_content) . '</textarea>';
        espresso_tiny_mce();
    }
    ?>
										<table id="email-confirmation-form" cellspacing="0">
											<tbody>
												<tr>
													<td class="aer-word-count"></td>
													<td class="autosave-info"><span>&nbsp;</span></td>
												</tr>
											</tbody>
										</table>
										<p><a class="thickbox" href="#TB_inline?height=300&width=400&inlineId=custom_email_info">
											<?php 
    _e('View Custom Email Tags', 'event_espresso');
    ?>
											</a> | <a class="thickbox" href="#TB_inline?height=300&width=400&inlineId=custom_email_example">
											<?php 
    _e('Email Example', 'event_espresso');
    ?>
											</a></p>
									</div>
								</li>
								<?php 
    if ($org_options["use_attendee_pre_approval"] == "Y") {
        $pre_approve = is_attendee_approved($event_id, $id) == true ? 1 : 0;
        ?>
								<li>
									<?php 
        _e("Attendee approved?", "event_espresso");
        ?>
									:
									<?php 
        $pre_approval_values = array(array('id' => '0', 'text' => __('Yes', 'event_espresso')), array('id' => '1', 'text' => __('No', 'event_espresso')));
        echo select_input("pre_approve", $pre_approval_values, $pre_approve);
        ?>
									<br />
									<?php 
        _e("(If not approved then invoice will not be sent.)", "event_espresso");
        ?>
								</li>
								<?php 
    }
    ?>
								<li>
									<br/>
									<input type="submit" class="button-primary action"   name="Submit" value="Send Invoice">
								</li>
							</ul>
						</form>
					</td>
				</tr>
			</table>

		</div>
	</div>
</div>
<?php 
    //This show what tags can be added to a custom email.
    event_espresso_custom_email_info();
    //event_list_attendees();
}
function espresso_confirm_registration()
{
    do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, '');
    global $wpdb, $org_options;
    if (!empty($_POST['confirm_registration'])) {
        $registration_id = sanitize_text_field($_POST['registration_id']);
    } else {
        wp_die(__('An error has occured. The registration ID could not be found.', 'event_espresso'));
    }
    echo '<div id="espresso-payment_page-dv" >';
    do_action('action_hook_espresso_confirmation_page_before', $registration_id);
    //Get the questions for the attendee
    $SQL = "SELECT ea.answer, eq.question FROM " . EVENTS_ANSWER_TABLE . " ea ";
    $SQL .= "LEFT JOIN " . EVENTS_QUESTION_TABLE . " eq ON eq.id = ea.question_id ";
    $SQL .= "WHERE ea.registration_id = %s ";
    $SQL .= "AND system_name IS NULL ORDER BY eq.sequence asc ";
    $questions = $wpdb->get_results($wpdb->prepare($SQL, $registration_id));
    //echo $wpdb->last_query;
    $display_questions = '';
    foreach ($questions as $question) {
        $question->question = trim(stripslashes(str_replace('&#039;', "'", $question->question)));
        $question->question = htmlspecialchars($question->question, ENT_QUOTES, 'UTF-8');
        $question->answer = trim(stripslashes(str_replace('&#039;', "'", $question->answer)));
        $question->answer = htmlspecialchars($question->answer, ENT_QUOTES, 'UTF-8');
        $display_questions .= '<p class="espresso_questions"><strong>' . $question->question . '</strong>:<br /> ' . str_replace(',', '<br />', $question->answer) . '</p>';
    }
    //Get the event information
    $SQL = "SELECT ed.*  FROM " . EVENTS_DETAIL_TABLE . " ed ";
    $SQL .= "JOIN " . EVENTS_ATTENDEE_TABLE . " ea ON ed.id = ea.event_id ";
    $SQL .= "WHERE ea.registration_id=%s";
    $events = $wpdb->get_results($wpdb->prepare($SQL, $registration_id));
    foreach ($events as $event) {
        $event_id = $event->id;
        $event_name = stripslashes_deep($event->event_name);
        $event_desc = stripslashes_deep($event->event_desc);
        $display_desc = $event->display_desc;
        $event_identifier = $event->event_identifier;
        $reg_limit = $event->reg_limit;
        $active = $event->is_active;
        $send_mail = $event->send_mail;
        $conf_mail = $event->conf_mail;
        $email_id = $event->email_id;
        $alt_email = $event->alt_email;
        $start_date = event_date_display($event->start_date);
        $end_date = $event->end_date;
        $virtual_url = $event->virtual_url;
        $virtual_phone = $event->virtual_phone;
        $event_address = $event->address;
        $event_address2 = $event->address2;
        $event_city = $event->city;
        $event_state = $event->state;
        $event_zip = $event->zip;
        $event_country = $event->country;
        $location = ($event_address != '' ? $event_address : '') . ($event_address2 != '' ? '<br />' . $event_address2 : '') . ($event_city != '' ? '<br />' . $event_city : '') . ($event_state != '' ? ', ' . $event_state : '') . ($event_zip != '' ? '<br />' . $event_zip : '') . ($event_country != '' ? '<br />' . $event_country : '');
        $location_phone = $event->phone;
        $require_pre_approval = $event->require_pre_approval;
        $google_map_link = espresso_google_map_link(array('address' => $event_address, 'city' => $event_city, 'state' => $event_state, 'zip' => $event_zip, 'country' => $event_country));
    }
    //Build links
    $event_url = espresso_reg_url($event_id);
    $event_link = '<a href="' . $event_url . '">' . $event_name . '</a>';
    $SQL = "SELECT * FROM " . EVENTS_ATTENDEE_TABLE;
    if ($registration_id != '') {
        $SQL .= " WHERE registration_id = '" . $registration_id . "' ";
    } elseif ($attendee_id != '') {
        $SQL .= " WHERE id = '" . $attendee_id . "' ";
    } else {
        _e('No ID Supplied', 'event_espresso');
    }
    $SQL .= " AND is_primary = 1 ";
    $SQL .= " ORDER BY id ";
    $SQL .= " LIMIT 0,1 ";
    //Get the first attendees details
    if (!($attendee = $wpdb->get_row($wpdb->prepare($SQL, NULL)))) {
        wp_die(__('An error occured. The primary attendee could not be found.', 'event_espresso'));
    }
    $attendee_id = $attendee->id;
    $attendee_email = isset($attendee->email) ? $attendee->email : '';
    $lname = isset($attendee->lname) ? htmlspecialchars(stripslashes($attendee->lname), ENT_QUOTES, 'UTF-8') : '';
    $fname = isset($attendee->fname) ? htmlspecialchars(stripslashes($attendee->fname), ENT_QUOTES, 'UTF-8') : '';
    $address = isset($attendee->address) ? htmlspecialchars(stripslashes($attendee->address), ENT_QUOTES, 'UTF-8') : '';
    $address2 = isset($attendee->address2) ? htmlspecialchars(stripslashes($attendee->address2), ENT_QUOTES, 'UTF-8') : '';
    $city = isset($attendee->city) ? htmlspecialchars(stripslashes($attendee->city), ENT_QUOTES, 'UTF-8') : '';
    $state = isset($attendee->state) ? htmlspecialchars(stripslashes($attendee->state), ENT_QUOTES, 'UTF-8') : '';
    $country = isset($attendee->country) ? htmlspecialchars(stripslashes($attendee->country), ENT_QUOTES, 'UTF-8') : '';
    $zip = isset($attendee->zip) ? $attendee->zip : '';
    $payment_status = $attendee->payment_status;
    $txn_type = $attendee->txn_type;
    $amount_pd = (double) $attendee->amount_pd;
    $total_cost = (double) $attendee->total_cost;
    $payment_date = $attendee->payment_date;
    $phone = $attendee->phone;
    $event_time = $attendee->event_time;
    $end_time = $attendee->end_time;
    $date = $attendee->date;
    $pre_approve = $attendee->pre_approve;
    $session_id = $attendee->attendee_session;
    if ($attendee->is_primary) {
        $event_cost = $total_cost;
    }
    $attendee_pre_approved = is_attendee_approved($event_id, $attendee_id);
    if ($attendee_pre_approved) {
        //Pull in the "Payment Overview" page template
        if (file_exists(EVENT_ESPRESSO_TEMPLATE_DIR . "payment_page.php")) {
            require_once EVENT_ESPRESSO_TEMPLATE_DIR . "payment_page.php";
            //This is the path to the template file if available
        } else {
            require_once EVENT_ESPRESSO_PLUGINFULLPATH . "templates/payment_page.php";
        }
        //Show payment options
        if ($total_cost > 0) {
            if (file_exists(EVENT_ESPRESSO_GATEWAY_DIR . "gateway_display.php")) {
                require_once EVENT_ESPRESSO_GATEWAY_DIR . "gateway_display.php";
            } else {
                require_once EVENT_ESPRESSO_PLUGINFULLPATH . "gateways/gateway_display.php";
            }
            //Check to see if the site owner wants to send an confirmation eamil before payment is recieved.
            if ($org_options['email_before_payment'] == 'Y') {
                event_espresso_email_confirmations(array('session_id' => $session_id, 'send_admin_email' => 'true', 'send_attendee_email' => 'true'));
            }
        } else {
            event_espresso_email_confirmations(array('session_id' => $session_id, 'send_admin_email' => 'true', 'send_attendee_email' => 'true'));
        }
    } else {
        if (file_exists(EVENT_ESPRESSO_PLUGINFULLPATH . 'includes/process-registration/pending_approval_page.php')) {
            require_once 'pending_approval_page.php';
            echo espresso_pending_registration_approval($registration_id);
            return;
        }
    }
    echo '</div>';
}
function event_list_attendees()
{
    global $wpdb, $org_options, $ticketing_installed, $espresso_premium;
    require_once EVENT_ESPRESSO_PLUGINFULLPATH . 'includes/event-management/queries.php';
    if (!defined('EVT_ADMIN_URL')) {
        define('EVT_ADMIN_URL', admin_url('admin.php?page=events'));
    }
    $EVT_ID = isset($_REQUEST['event_id']) && $_REQUEST['event_id'] != '' ? absint($_REQUEST['event_id']) : FALSE;
    if ($EVT_ID) {
        echo '<h1>' . espresso_event_list_attendee_title($EVT_ID) . '</h1>';
    }
    //Delete the attendee(s)
    if (isset($_POST['delete_customer']) && !empty($_POST['delete_customer'])) {
        if (is_array($_POST['checkbox'])) {
            while (list($att_id, $value) = each($_POST['checkbox'])) {
                //hook for before delete
                do_action('action_hook_espresso_before_delete_attendee_event_list', $att_id, $EVT_ID);
                $SQL = "DELETE FROM " . EVENTS_ATTENDEE_TABLE . " WHERE id = '%d'";
                $wpdb->query($wpdb->prepare($SQL, $att_id));
                $SQL = "DELETE FROM " . EVENTS_ATTENDEE_META_TABLE . " WHERE attendee_id = '%d'";
                $wpdb->query($wpdb->prepare($SQL, $att_id));
                $SQL = "DELETE FROM " . EVENTS_ANSWER_TABLE . " WHERE attendee_id = '%d'";
                $wpdb->query($wpdb->prepare($SQL, $att_id));
                //hook for after delete
                do_action('action_hook_espresso_after_delete_attendee_event_list', $att_id, $EVT_ID);
            }
        }
        ?>
		<div id="message" class="updated fade">
			<p>
				<strong><?php 
        _e('Customer(s) have been successfully deleted from the event.', 'event_espresso');
        ?>
</strong>
			</p>
		</div>
		<?php 
    }
    //	MARKING USERS AS ATTENDED (OR NOT)
    if ((!empty($_POST['attended_customer']) || !empty($_POST['unattended_customer'])) && $ticketing_installed == TRUE) {
        if (is_array($_POST['checkbox'])) {
            while (list($att_id, $value) = each($_POST['checkbox'])) {
                // on / off value for attended status checkbox
                $check_in_or_out = $value == "on" && array_key_exists('attended_customer', $_POST) ? 1 : 0;
                $SQL = "SELECT * FROM " . EVENTS_ATTENDEE_TABLE . " WHERE id = %d ";
                $attendee = $wpdb->get_row($wpdb->prepare($SQL, $att_id));
                $ticket_quantity_scanned = $attendee->checked_in_quantity;
                $tickets_for_attendee = $attendee->quantity;
                $updated_ticket_quantity = $check_in_or_out ? $tickets_for_attendee : 0;
                if ($ticket_quantity_scanned >= 1 && true == $check_in_or_out || $ticket_quantity_scanned <= 0 && false == $check_in_or_out) {
                    ?>
					<div id="message" class="error fade">
						<p>
							<strong><?php 
                    _e('Scanned tickets cannot be redeemed/un-redeemed here.', 'event_espresso');
                    ?>
</strong>
						</p>
					</div>
					<?php 
                } else {
                    if ($wpdb->update(EVENTS_ATTENDEE_TABLE, array('checked_in' => $check_in_or_out, 'checked_in_quantity' => $updated_ticket_quantity), array('id' => $att_id), array('%d', '%d'), array('%d'))) {
                        ?>
					<div id="message" class="updated fade">
					  <p><strong>
						<?php 
                        _e('Customer(s) attendance data successfully updated for this event.', 'event_espresso');
                        ?>
						</strong></p>
					</div>
					<?php 
                    }
                }
            }
        }
    }
    // get SQL for query
    $SQL = espresso_generate_events_page_list_table_sql(FALSE, TRUE);
    $attendees = $wpdb->get_results($SQL, OBJECT_K);
    $total_attendees = $wpdb->num_rows;
    //	echo '<h4>' . $wpdb->last_query . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
    //	printr( $attendees, '$attendees  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
    if (file_exists(EVENT_ESPRESSO_PLUGINFULLPATH . 'includes/admin-files/admin_reports_filters.php')) {
        require_once EVENT_ESPRESSO_PLUGINFULLPATH . 'includes/admin-files/admin_reports_filters.php';
        espresso_display_admin_reports_filters($total_attendees);
    } else {
        ?>
		<p>
			<strong><?php 
        _e('Advanced filters are available in the premium versions.', 'event_espresso');
        ?>
</strong> 
			<a href="http://eventespresso.com/download/" target="_blank">
				<?php 
        _e('Upgrade Now!', 'event_espresso');
        ?>
			</a>
		</p>
		<?php 
    }
    $updated_ticket_quantity = 0;
    $att_table_form_url = add_query_arg(array('event_admin_reports' => 'list_attendee_payments', 'event_id' => $EVT_ID), EVT_ADMIN_URL);
    ?>
	
<form id="form1" name="form1" method="post" action="<?php 
    echo $att_table_form_url;
    ?>
">
	<table id="table" class="widefat fixed" width="100%">
		<thead>
			<tr>
				<th class="manage-column column-cb check-column" id="cb" scope="col" style="width:3%;min-width:35px !important;">
					<input type="checkbox">
				</th>
				<th class="manage-column column-att-id" id="att-id" scope="col" title="Click to Sort"style="width:3%;max-width:35px !important;"> 
					<span><?php 
    _e('ID', 'event_espresso');
    ?>
</span> <span class="sorting-indicator"></span> 
				</th>
				<th class="manage-column column-name" id="name" scope="col" title="Click to Sort"style="width: 10%;"> 
					<span><?php 
    _e('Attendee Name', 'event_espresso');
    ?>
</span> <span class="sorting-indicator"></span> 
				</th>
				<th class="manage-column column-registrationid" id="registrationid" scope="col" title="Click to Sort" style="width: 10%;">
				 	<span><?php 
    _e('Reg ID', 'event_espresso');
    ?>
</span> <span class="sorting-indicator"></span> 
				</th>
				<th class="manage-column column-date" id="registration" scope="col" title="Click to Sort" style="width: 10%;"> 
					<span><?php 
    _e('Registered', 'event_espresso');
    ?>
</span> <span class="sorting-indicator"></span> 
				</th>
				<th class="manage-column column-title" id="event-title" scope="col" title="Click to Sort" style="width: 10%;"> 
					<span><?php 
    _e('Event Title', 'event_espresso');
    ?>
</span> <span class="sorting-indicator"></span> 
				</th>
				<th class="manage-column column-title" id="event-time" scope="col" title="Click to Sort" style="width: 8%;"> 
					<span><?php 
    _e('Event Time', 'event_espresso');
    ?>
</span> <span class="sorting-indicator"></span> 
				</th>
				<th class="manage-column column-title" id="attended" scope="col" title="Click to Sort" style="width: 8%;">
				 	<span><?php 
    echo $ticketing_installed == true ? __('Attended', 'event_espresso') : __('Quantity', 'event_espresso');
    ?>
</span> <span class="sorting-indicator"></span> 
				</th>
				<th class="manage-column column-title" id="ticket-option" scope="col" title="Click to Sort" style="width: 13%;">
				 	<span><?php 
    _e('Option', 'event_espresso');
    ?>
</span> <span class="sorting-indicator"></span> 
				</th>
				<th align="center" class="manage-column column-date" id="amount" style="width: 5%;" title="Click to Sort" scope="col">
				 	<span><?php 
    _e('Payment', 'event_espresso');
    ?>
</span> <span class="sorting-indicator"></span> 
				</th>
				<th class="manage-column column-date" id="payment_type" scope="col" title="Click to Sort" style="width: 8%;">
				 	<span><?php 
    _e('Type', 'event_espresso');
    ?>
</span> <span class="sorting-indicator"></span> 
				</th>
				<th class="manage-column column-date" id="coupon" scope="col" title="Click to Sort" style="width: 10%;"> 
					<span><?php 
    _e('Coupon', 'event_espresso');
    ?>
</span> <span class="sorting-indicator"></span> 
				</th>
				<th class="manage-column column-date" id="txn_id" scope="col" title="Click to Sort" style="width: 10%;"> 
					<span><?php 
    _e('Transaction ID', 'event_espresso');
    ?>
</span> <span class="sorting-indicator"></span> 
				</th>
				<th class="manage-column column-date" id="action" scope="col" title="" >
					<?php 
    _e('Actions', 'event_espresso');
    ?>
				</th>
			</tr>
		</thead>
		<tbody>	
<?php 
    if ($total_attendees > 0) {
        foreach ($attendees as $attendee) {
            $id = $attendee->id;
            $registration_id = $attendee->registration_id;
            $lname = htmlspecialchars(stripslashes($attendee->lname), ENT_QUOTES, 'UTF-8');
            $fname = htmlspecialchars(stripslashes($attendee->fname), ENT_QUOTES, 'UTF-8');
            $address = htmlspecialchars(stripslashes($attendee->address), ENT_QUOTES, 'UTF-8');
            $city = htmlspecialchars(stripslashes($attendee->city), ENT_QUOTES, 'UTF-8');
            $state = htmlspecialchars(stripslashes($attendee->state), ENT_QUOTES, 'UTF-8');
            $zip = $attendee->zip;
            $email = '<span style="visibility:hidden">' . $attendee->email . '</span>';
            $phone = $attendee->phone;
            $ticket_quantity_scanned = $attendee->checked_in_quantity;
            //$updated_ticket_quantity = $attendee->quantity > 1 ? '<div class="row-actions">(' . __('Qty', 'event_espresso') . ': ' . $attendee->quantity . ')</div>' : '';
            if ($ticketing_installed == TRUE) {
                $qty_scanned = $ticket_quantity_scanned . ' / ' . $attendee->quantity;
            } else {
                $qty_scanned = $attendee->quantity;
            }
            $attended = $attendee->checked_in;
            $amount_pd = $attendee->amount_pd;
            $payment_status = $attendee->payment_status;
            $payment_date = $attendee->payment_date;
            $date = $attendee->date;
            $event_id = $attendee->event_id;
            $coupon_code = $attendee->coupon_code;
            $txn_id = $attendee->txn_id;
            $txn_type = $attendee->txn_type;
            $price_option = $attendee->price_option;
            $event_time = $attendee->event_time;
            $event_name = $attendee->event_name;
            $event_date = $attendee->start_date;
            ?>
			<tr>
			
				<td class="check-column" style="padding:7px 0 22px 7px; vertical-align:top;">
					<input name="checkbox[<?php 
            echo $id;
            ?>
]" type="checkbox"  title="Delete <?php 
            echo $fname;
            echo $lname;
            ?>
">
				</td>
				
	            <td nowrap="nowrap">
					<?php 
            echo $attendee->id;
            ?>
				</td>
				
	            <td class="row-title" nowrap="nowrap" title="<?php 
            echo 'ID#:' . $id . ' [ REG#: ' . $registration_id . ' ] Email: ' . $attendee->email;
            ?>
">
					<a href="admin.php?page=events&amp;event_admin_reports=edit_attendee_record&amp;event_id=<?php 
            echo $event_id;
            ?>
&amp;registration_id=<?php 
            echo $registration_id;
            ?>
&amp;form_action=edit_attendee&amp;id=<?php 
            echo $id;
            ?>
">
						<?php 
            echo $fname;
            ?>
 <?php 
            echo $lname;
            ?>
 <?php 
            echo $email;
            ?>
	              </a>
				 </td>
				
	            <td nowrap="nowrap" title="<?php 
            echo $registration_id;
            ?>
">
					<?php 
            echo $registration_id;
            ?>
				</td>
				
	            <td class="date column-date">
					<?php 
            echo event_date_display($date, get_option('date_format') . ' g:i a');
            ?>
				</td>
				
	            <td nowrap="nowrap">
					<a href="admin.php?page=events&amp;event_admin_reports=list_attendee_payments&amp;event_id=<?php 
            echo $event_id;
            ?>
" title="<?php 
            _e('View attendees for this event', 'event_espresso');
            ?>
">
						<?php 
            echo stripslashes_deep($event_name);
            ?>
					</a>
				</td>
				
	            <td nowrap="nowrap">
					<?php 
            echo event_date_display($event_time, get_option('time_format'));
            ?>
				</td>
				
	            <td nowrap="nowrap" title="<?php 
            echo $qty_scanned;
            ?>
">
					<p style="padding-left:15px">
						<?php 
            echo $qty_scanned;
            ?>
					</p>
				</td>
				
	            <td nowrap="nowrap" title="<?php 
            echo $price_option;
            ?>
">
					<?php 
            echo $price_option;
            ?>
				</td>
				
	            <td class="date column">
					<a href="admin.php?page=events&amp;attendee_pay=paynow&amp;form_action=payment&amp;registration_id=<?php 
            echo $registration_id;
            ?>
&amp;event_admin_reports=enter_attendee_payments&amp;event_id=<?php 
            echo $event_id;
            ?>
" title="<?php 
            _e('Edit Payment', 'event_espresso');
            ?>
 ID: <?php 
            echo $registration_id;
            ?>
">
	              		<p style="padding-left:17px"><?php 
            event_espresso_paid_status_icon($payment_status);
            ?>
</p>
	              	</a> 
				</td>
				
				<td class="">
					<?php 
            echo espresso_payment_type($txn_type);
            ?>
				</td>
				
	            <td class="">
					<?php 
            echo $coupon_code;
            ?>
				</td>
				
	            <td class="">
					<?php 
            echo $txn_id;
            ?>
				</td>
				
	            <td class="" >
	            
	            	<a href="admin.php?page=events&amp;attendee_pay=paynow&amp;form_action=payment&amp;registration_id=<?php 
            echo $registration_id;
            ?>
&amp;event_admin_reports=enter_attendee_payments&amp;event_id=<?php 
            echo $event_id;
            ?>
" title="<?php 
            _e('Edit Payment', 'event_espresso');
            ?>
 ID: <?php 
            echo $registration_id;
            ?>
">
						<img src="<?php 
            echo EVENT_ESPRESSO_PLUGINFULLURL;
            ?>
images/icons/money.png" width="16" height="16" alt="<?php 
            _e('Edit Payment', 'event_espresso');
            ?>
" />
					</a>
	            
	            	<a href="admin.php?page=events&amp;event_admin_reports=edit_attendee_record&amp;registration_id=<?php 
            echo $registration_id;
            ?>
&amp;event_id=<?php 
            echo $event_id;
            ?>
&amp;form_action=edit_attendee" title="<?php 
            _e('Edit Attendee', 'event_espresso');
            ?>
">
						<img src="<?php 
            echo EVENT_ESPRESSO_PLUGINFULLURL;
            ?>
images/icons/user_edit.png" width="16" height="16" alt="<?php 
            _e('Edit Attendee', 'event_espresso');
            ?>
" />
					</a>
	            
	            	<a href="admin.php?page=events&amp;event_admin_reports=resend_email&amp;registration_id=<?php 
            echo $registration_id;
            ?>
&amp;event_id=<?php 
            echo $event_id;
            ?>
&amp;form_action=resend_email" title="<?php 
            _e('Resend Registration Details', 'event_espresso');
            ?>
">
						<img src="<?php 
            echo EVENT_ESPRESSO_PLUGINFULLURL;
            ?>
images/icons/email_link.png" width="16" height="16" alt="<?php 
            _e('Resend Registration Details', 'event_espresso');
            ?>
" />
					</a>
					
	            	<?php 
            if ($espresso_premium == true) {
                ?>
	            	<a href="<?php 
                echo home_url();
                ?>
/?download_invoice=true&amp;admin=true&amp;registration_id=<?php 
                echo $registration_id;
                ?>
" target="_blank"  title="<?php 
                _e('Download Invoice', 'event_espresso');
                ?>
">
						<img src="<?php 
                echo EVENT_ESPRESSO_PLUGINFULLURL;
                ?>
images/icons/page_white_acrobat.png" width="16" height="16" alt="<?php 
                _e('Download Invoice', 'event_espresso');
                ?>
" />
					</a>
					<?php 
            }
            ?>
				
					<?php 
            if ($ticketing_installed == true && function_exists('espresso_ticket_url')) {
                ?>
					<a href="<?php 
                echo espresso_ticket_url($id, $registration_id);
                ?>
" target="_blank"  title="<?php 
                _e('View/Download Ticket', 'event_espresso');
                ?>
">
						<img src="<?php 
                echo EVENT_ESPRESSO_PLUGINFULLURL;
                ?>
images/icons/ticket-arrow-icon.png" width="16" height="16" alt="<?php 
                _e('Download Ticket', 'event_espresso');
                ?>
" />
					</a>
					<?php 
            }
            if ($org_options["use_attendee_pre_approval"] == "Y") {
                ?>
		  				<br/>
		  				<a href="admin.php?page=events&amp;attendee_pay=paynow&amp;form_action=payment&amp;registration_id=<?php 
                echo $registration_id;
                ?>
&amp;event_admin_reports=enter_attendee_payments&amp;event_id=<?php 
                echo $event_id;
                ?>
" title="<?php 
                _e('Edit Payment', 'event_espresso');
                ?>
 ID: <?php 
                echo $registration_id;
                ?>
">
		  				<?php 
                if (is_attendee_approved($event_id, $id)) {
                    ?>
		  					<strong><?php 
                    _e('Approved', 'event_espresso');
                    ?>
</strong><br/>
		  				<?php 
                } else {
                    ?>
		  					<span style="color:#FF0000"><strong><?php 
                    _e('Awaiting approval', 'event_espresso');
                    ?>
</strong></span>
		  				<?php 
                }
                ?>
		  				</a>
	  				<?php 
            }
            ?>
					
				</td>
				
			</tr>
<?php 
        }
    }
    ?>
		</tbody>
	</table>
	
  	<div style="clear:both; margin-bottom:30px;">
	
    	<input name="delete_customer" type="submit" class="button-secondary" id="delete_customer" value="<?php 
    _e('Delete Attendee(s)', 'event_espresso');
    ?>
" style="margin:10px 0 0 0;" onclick="return confirmDelete();" />
		
	    <?php 
    if ($ticketing_installed == true) {
        ?>
	    <input name="attended_customer" type="submit" class="button-secondary" id="attended_customer" value="<?php 
        _e('Mark as Attended', 'event_espresso');
        ?>
" style="margin:10px 0 0 10px;" />
	    <input name="unattended_customer" type="submit" class="button-secondary" id="attended_customer" value="<?php 
        _e('Unmark as Attended', 'event_espresso');
        ?>
" style="margin:10px 0 0 10px;" />
	    <?php 
    }
    ?>
		
	    <a style="margin-left:5px" class="button-secondary" href="admin.php?page=events&amp;action=csv_import">
	    <?php 
    _e('Import Events', 'event_espresso');
    ?>
	    </a> 
		
		<?php 
    if (function_exists('espresso_attendee_import') && $espresso_premium == true) {
        ?>
		<a style="margin-left:5px" class="button-secondary" href="admin.php?page=espresso_attendee_import">
			<?php 
        _e('Import Attendees', 'event_espresso');
        ?>
		</a>
		<?php 
    }
    ?>
		
		<a class="button-secondary" style="margin-left:5px" href="#" onclick="window.location='<?php 
    echo get_bloginfo('wpurl') . "/wp-admin/admin.php?event_espresso&amp;export=report&action=payment&amp;type=excel&amp;";
    echo $EVT_ID ? "event_id=" . $EVT_ID : "all_events=true";
    ?>
'" title="<?php 
    _e('Export to Excel', 'event_espresso');
    ?>
">
	    	<?php 
    _e('Export to Excel', 'event_espresso');
    ?>
	    </a> 
		
		<?php 
    if ($EVT_ID) {
        ?>
		<a style="margin-left:5px"  class="button-secondary"  href="admin.php?page=events&amp;event_admin_reports=add_new_attendee&amp;event_id=<?php 
        echo $EVT_ID;
        ?>
">
			<?php 
        _e('Add Attendee', 'event_espresso');
        ?>
		</a>
		<?php 
    }
    ?>
 
		
		<?php 
    if ($EVT_ID) {
        ?>
		<a style="margin-left:5px" class="button-primary" href="admin.php?page=events&amp;action=edit&amp;event_id=<?php 
        echo $EVT_ID;
        ?>
">
			<?php 
        _e('Edit Event', 'event_espresso');
        ?>
		</a>
		<?php 
    }
    ?>
 
		
	</div>
	
</form>

<h4 style="clear:both"><?php 
    _e('Legend', 'event_espresso');
    ?>
</h4>

<dl style="float:left; margin-left:10px; width:200px">
	<dt>
		<?php 
    event_espresso_paid_status_icon('Completed');
    ?>
 - <?php 
    _e('Completed', 'event_espresso');
    ?>
	</dt>
	<dt>
		<?php 
    event_espresso_paid_status_icon('Incomplete');
    ?>
 - <?php 
    _e('Incomplete', 'event_espresso');
    ?>
	</dt>
    <dt>
		<?php 
    event_espresso_paid_status_icon('Pending');
    ?>
 - <?php 
    _e('Pending', 'event_espresso');
    ?>
	</dt>
	<dt>
		<img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
images/icons/money.png" width="16" height="16" alt="<?php 
    _e('Payment Details', 'event_espresso');
    ?>
" /> - <?php 
    _e('Payment Details', 'event_espresso');
    ?>
	</dt>
</dl>

 <dl style="float:left; margin-left:10px; width:200px">
	<dt>
		<img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
images/icons/email_link.png" width="16" height="16" alt="<?php 
    _e('Resend Details', 'event_espresso');
    ?>
" /> - <?php 
    _e('Resend Email', 'event_espresso');
    ?>
	</dt>
	<dt>
		<img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
images/icons/page_white_acrobat.png" width="16" height="16" alt="<?php 
    _e('Download Invoice', 'event_espresso');
    ?>
" /> - <?php 
    _e('Download Invoice', 'event_espresso');
    ?>
	</dt>
	<dt>
		<img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
images/icons/user_edit.png" width="16" height="16" alt="<?php 
    _e(' Attendee Details', 'event_espresso');
    ?>
" /> - <?php 
    _e('Attendee Details', 'event_espresso');
    ?>
	</dt>
</dl>
<?php 
    $hide = $EVT_ID ? '1,5' : '1,3';
    $hide .= ',11,12';
    ?>
<script>
	jQuery(document).ready(function($) {
		/* show the table data */
		var mytable = $('#table').dataTable( {
			"sDom": 'Clfrtip',
			"bAutoWidth": false,
			"bStateSave": true,
			"sPaginationType": "full_numbers",
			"oLanguage": {    "sSearch": "<strong><?php 
    _e('Live Search Filter', 'event_espresso');
    ?>
:</strong> (eg, email, txn id, event, etc.)",
			"sZeroRecords": "<?php 
    _e('No Records Found!', 'event_espresso');
    ?>
" },
			"aoColumns": [
				{ "bSortable": false },
				null,
				null,
				null,
				null,
				null,
				null,
				null,//Qty/Attended
				null,
				null,
				null,
				null,
				null,
				{ "bSortable": false }
			],
			"aoColumnDefs": [
				{ "bVisible": false, "aTargets": [<?php 
    echo $hide;
    ?>
] }
			],
			"oColVis": {
				"aiExclude": [0,2],
				"buttonText": "Filter: Show / Hide Columns",
				"bRestore": true
			},
		});
	});
</script>
<?php 
}
function event_list_attendees()
{
    global $wpdb, $org_options, $ticketing_installed;
    //Dates
    $curdate = date("Y-m-d");
    $pieces = explode('-', $curdate, 3);
    $this_year_r = $pieces[0];
    $this_month_r = $pieces[1];
    $days_this_month = date('t', strtotime($curdate));
    if (!empty($_POST['delete_customer'])) {
        if (is_array($_POST['checkbox'])) {
            while (list($key, $value) = each($_POST['checkbox'])) {
                $del_id = $key;
                $sql = "DELETE FROM " . EVENTS_ATTENDEE_TABLE . " WHERE id = '{$del_id}'";
                $wpdb->query($sql);
            }
        }
        ?>

<div id="message" class="updated fade">
  <p><strong>
    <?php 
        _e('Customer(s) have been successfully deleted from the event.', 'event_espresso');
        ?>
    </strong></p>
</div>
<?php 
    }
    //	MARKING USERS AS ATTENDED (OR NOT)
    if ((!empty($_POST['attended_customer']) || !empty($_POST['unattended_customer'])) && $ticketing_installed == true) {
        if (is_array($_POST['checkbox'])) {
            while (list($key, $value) = each($_POST['checkbox'])) {
                $del_id = $key;
                //echo $del_id . " / " . $value . "<br />\n";
                if ($value == "on" && $_POST['attended_customer']) {
                    $checker = 1;
                } else {
                    $checker = 0;
                }
                $wpdb->get_results("SELECT checked_in_quantity FROM " . EVENTS_ATTENDEE_TABLE . " WHERE id = '{$del_id}' LIMIT 0,1 ");
                $ticket_scanned = $wpdb->last_result[0]->checked_in_quantity;
                if ($ticket_scanned >= 1) {
                    ?>
					<div id="message" class="error fade">
					  <p><strong>
						<?php 
                    _e('Scanned tickets cannot be redeemed/un-redeemed here.', 'event_espresso');
                    ?>
						</strong></p>
					</div>
					<?php 
                } else {
                    $sql = "UPDATE " . EVENTS_ATTENDEE_TABLE . " SET checked_in = {$checker} WHERE id = '{$del_id}'";
                    $wpdb->query($sql);
                    //echo $sql;
                    ?>
					<div id="message" class="updated fade">
					  <p><strong>
						<?php 
                    _e('Customer(s) attendance data successfully updated for this event.', 'event_espresso');
                    ?>
						</strong></p>
					</div>
					<?php 
                }
            }
        }
    }
    require_once EVENT_ESPRESSO_PLUGINFULLPATH . 'includes/event-management/queries.php';
    $total_events = espresso_total_events();
    if (file_exists(EVENT_ESPRESSO_PLUGINFULLPATH . 'includes/admin-files/admin_reports_filters.php')) {
        require_once EVENT_ESPRESSO_PLUGINFULLPATH . 'includes/admin-files/admin_reports_filters.php';
    } else {
        echo '<p><strong>' . __('Advanced filters are available in the premium versions.', 'event_espresso') . '</strong> <a href="http://eventespresso.com/download/" target="_blank">' . __('Upgrade Now!', 'event_espresso') . '</a></p>';
    }
    if (isset($_REQUEST['event_id']) && $_REQUEST['event_id'] != '') {
        echo '<h3>' . espresso_event_list_attendee_title($_REQUEST['event_id']) . '</h3>';
    }
    ?>
<style type="text/css">
        .dataTables_paginate {margin-top:10px;}
        .sorting_asc .sorting_desc {}
        th.sorting_asc span.sorting-indicator {display:block; margin-left:3px; background-position: 0 0;}
        th.sorting_desc span.sorting-indicator {display:block; margin-left:3px; background-position: -7px 0;}
        #table thead tr th span {cursor:pointer; float:left;}
        #table thead tr th span:hover {color:#D54E21;}
        #table_filter input {width:250px; background:#fff;}

        /*fixing this */
        .view_btn:hover, .edit_btn:hover, .complete_btn:hover, .shortcode_btn:hover, .excel_exp_btn:hover, .csv_exp_btn:hover, .newsletter_btn:hover  {height: 18px; margin: 2px 3px 0 0;}
    </style>
<?php 
    /*if (!empty($_REQUEST['event_id'])) { ?>
    
            <h3 style="margin-bottom:15px;"><?php _e('Attendee Report for Event ID:', 'event_espresso'); ?> <?php espresso_event_list_attendee_title($_REQUEST['event_id']); ?></h3>
    
        <?php }*/
    ?>
<form id="form1" name="form1" method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">
  <table id="table" class="widefat fixed" width="100%">
    <thead>
      <tr>
        <th class="manage-column column-cb check-column" id="cb" scope="col" style="width: 4%;"><input type="checkbox"></th>
        <th class="manage-column column-title" id="name" scope="col" title="Click to Sort"style="width: 10%;"> <span>
          <?php 
    _e('Attendee Name', 'event_espresso');
    ?>
          <span> <span class="sorting-indicator"></span> </th>
        <th class="manage-column column-date" id="registrationid" scope="col" title="Click to Sort" style="width: 10%;"> <span>
          <?php 
    _e('Reg ID', 'event_espresso');
    ?>
          </span> <span class="sorting-indicator"></span> </th>
        <th class="manage-column column-date" id="registration" scope="col" title="Click to Sort" style="width: 10%;"> <span>
          <?php 
    _e('Registered', 'event_espresso');
    ?>
          </span> <span class="sorting-indicator"></span> </th>
        <th class="manage-column column-title" id="event" scope="col" title="Click to Sort" style="width: 10%;"> <span>
          <?php 
    _e('Event Title', 'event_espresso');
    ?>
          </span> <span class="sorting-indicator"></span> </th>
        <th class="manage-column column-title" id="event" scope="col" title="Click to Sort" style="width: 8%;"> <span>
          <?php 
    _e('Event Time', 'event_espresso');
    ?>
          </span> <span class="sorting-indicator"></span> </th>
        <?php 
    if ($ticketing_installed == true) {
        ?>
        <th class="manage-column column-title" id="attended" scope="col" title="Click to Sort" style="width: 8%;"> <span>
          <?php 
        _e('Attended', 'event_espresso');
        ?>
          </span> <span class="sorting-indicator"></span> </th>
        <?php 
    }
    ?>
        <th class="manage-column column-title" id="event" scope="col" title="Click to Sort" style="width: 8%;"> <span>
          <?php 
    _e('Option', 'event_espresso');
    ?>
          </span> <span class="sorting-indicator"></span> </th>
        <th align="center" class="manage-column column-date" id="amount" style="width: 10%;" title="Click to Sort" scope="col"> <span>
          <?php 
    _e('Payment', 'event_espresso');
    ?>
          </span> <span class="sorting-indicator"></span> </th>
        <th class="manage-column column-date" id="payment_type" scope="col" title="Click to Sort" style="width: 10%;"> <span>
          <?php 
    _e('Type', 'event_espresso');
    ?>
          </span> <span class="sorting-indicator"></span> </th>
        <th class="manage-column column-date" id="coupon" scope="col" title="Click to Sort" style="width: 12%;"> <span>
          <?php 
    _e('Coupon', 'event_espresso');
    ?>
          </span> <span class="sorting-indicator"></span> </th>
        <th class="manage-column column-date" id="txn_id" scope="col" title="Click to Sort" style="width: 15%;"> <span>
          <?php 
    _e('Transaction ID', 'event_espresso');
    ?>
          </span> <span class="sorting-indicator"></span> </th>
        <th class="manage-column column-date" id="action" scope="col" title="Click to Sort"style="width: 8%;"><?php 
    _e('Action', 'event_espresso');
    ?>
</th>
      </tr>
    </thead>
    <tbody>
      <?php 
    $temp_reg_id = '';
    //will temporarily hold the registration id for checking with the next row
    $attendees_group = '';
    //will hold the names of the group members
    $counter = 0;
    //used for keeping track of the last row.  If counter = num_rows, print
    $go = false;
    //triggers the output when true.  Set when the next reg id != temp_reg_id
    $sql_clause = " WHERE ";
    $sql_a = "(";
    if (function_exists('espresso_member_data') && espresso_member_data('role') == 'espresso_group_admin') {
        $group = get_user_meta(espresso_member_data('id'), "espresso_group", true);
        $group = unserialize($group);
        $group = implode(",", $group);
        $sql_a .= "SELECT a.*, e.id event_id, e.event_name, checked_in FROM " . EVENTS_ATTENDEE_TABLE . " a ";
        $sql_a .= " LEFT JOIN " . EVENTS_DETAIL_TABLE . " e ON e.id=a.event_id ";
        if ($_REQUEST['category_id'] != '') {
            $sql_a .= " JOIN " . EVENTS_CATEGORY_REL_TABLE . " r ON r.event_id = e.id ";
            $sql_a .= " JOIN " . EVENTS_CATEGORY_TABLE . " c ON  c.id = r.cat_id ";
        }
        if ($group != '') {
            $sql_a .= " JOIN " . EVENTS_VENUE_REL_TABLE . " r ON r.event_id = e.id ";
            $sql_a .= " JOIN " . EVENTS_LOCALE_REL_TABLE . " l ON  l.venue_id = r.venue_id ";
        }
        $sql_a .= $_REQUEST['category_id'] != '' ? " AND c.id = '" . $_REQUEST['category_id'] . "' " : '';
        $sql_clause = " WHERE ";
        if ($_REQUEST['payment_status'] != '') {
            $sql_a .= " {$sql_clause} a.payment_status = '" . $_REQUEST['payment_status'] . "' ";
            $sql_clause = " AND ";
        }
        if ($_POST['month_range'] != '') {
            $pieces = explode('-', $_REQUEST['month_range'], 3);
            $year_r = $pieces[0];
            $month_r = $pieces[1];
            $sql_a .= " {$sql_clause} a.date BETWEEN '" . event_espresso_no_format_date($year_r . '-' . $month_r . '-01', $format = 'Y-m-d') . "' AND '" . event_espresso_no_format_date($year_r . '-' . $month_r . '-31', $format = 'Y-m-d') . "' ";
            $sql_clause = " AND ";
        }
        if ($_REQUEST['event_id'] != '') {
            $sql_a .= " {$sql_clause} a.event_id = '" . $_REQUEST['event_id'] . "' ";
            $sql_clause = " AND ";
        }
        if ($_REQUEST['today_a'] == 'true') {
            //$sql_a .= " $sql_clause a.date = '" . event_espresso_no_format_date($curdate,$format = 'Y-m-d') ."' ";
            $sql_a .= " {$sql_clause} a.date BETWEEN '" . $curdate . ' 00:00:00' . "' AND '" . $curdate . ' 23:59:59' . "' ";
            $sql_clause = " AND ";
        }
        if ($_REQUEST['this_month_a'] == 'true') {
            $sql_a .= " {$sql_clause} a.date BETWEEN '" . event_espresso_no_format_date($this_year_r . '-' . $this_month_r . '-01', $format = 'Y-m-d') . "' AND '" . event_espresso_no_format_date($this_year_r . '-' . $this_month_r . '-' . $days_this_month, $format = 'Y-m-d') . "' ";
            $sql_clause = " AND ";
        }
        $sql_a .= $group != '' ? $sql_clause . "  l.locale_id IN (" . $group . ") " : '';
        $sql_a .= " AND e.event_status != 'D' ";
        $sql_a .= ") UNION (";
    }
    $sql_a .= "SELECT a.*, e.id event_id, e.event_name, checked_in FROM " . EVENTS_ATTENDEE_TABLE . " a ";
    $sql_a .= " LEFT JOIN " . EVENTS_DETAIL_TABLE . " e ON e.id=a.event_id ";
    if (!empty($_REQUEST['category_id'])) {
        $sql_a .= " JOIN " . EVENTS_CATEGORY_REL_TABLE . " r ON r.event_id = e.id ";
        $sql_a .= " JOIN " . EVENTS_CATEGORY_TABLE . " c ON  c.id = r.cat_id ";
    }
    $sql_a .= !empty($_REQUEST['category_id']) ? " AND c.id = '" . $_REQUEST['category_id'] . "' " : '';
    $sql_clause = " WHERE ";
    if (!empty($_REQUEST['payment_status'])) {
        $sql_a .= " {$sql_clause} a.payment_status = '" . $_REQUEST['payment_status'] . "' ";
        $sql_clause = " AND ";
    }
    if (!empty($_POST['month_range'])) {
        $pieces = explode('-', $_REQUEST['month_range'], 3);
        $year_r = $pieces[0];
        $month_r = $pieces[1];
        $sql_a .= " {$sql_clause} a.date BETWEEN '" . event_espresso_no_format_date($year_r . '-' . $month_r . '-01', $format = 'Y-m-d') . "' AND '" . event_espresso_no_format_date($year_r . '-' . $month_r . '-31', $format = 'Y-m-d') . "' ";
        $sql_clause = " AND ";
    }
    if (!empty($_REQUEST['event_id'])) {
        $sql_a .= " {$sql_clause} a.event_id = '" . $_REQUEST['event_id'] . "' ";
        $sql_clause = " AND ";
    }
    if (!empty($_REQUEST['today_a'])) {
        //$sql_a .= " $sql_clause a.date = '" . event_espresso_no_format_date($curdate,$format = 'Y-m-d') ."' ";
        $sql_a .= " {$sql_clause} a.date BETWEEN '" . $curdate . ' 00:00:00' . "' AND '" . $curdate . ' 23:59:59' . "' ";
        $sql_clause = " AND ";
    }
    if (!empty($_REQUEST['this_month_a'])) {
        $sql_a .= " {$sql_clause} a.date BETWEEN '" . event_espresso_no_format_date($this_year_r . '-' . $this_month_r . '-01', $format = 'Y-m-d') . "' AND '" . event_espresso_no_format_date($this_year_r . '-' . $this_month_r . '-' . $days_this_month, $format = 'Y-m-d') . "' ";
        $sql_clause = " AND ";
    }
    if (function_exists('espresso_member_data') && (espresso_member_data('role') == 'espresso_event_manager' || espresso_member_data('role') == 'espresso_group_admin')) {
        $sql_a .= $sql_clause . " e.wp_user = '******'id') . "' ";
    }
    $sql_a .= " {$sql_clause} e.event_status != 'D' ";
    $sql_a .= ") ORDER BY date DESC, id ASC ";
    $attendees = $wpdb->get_results($sql_a);
    //echo $sql_a;
    $total_attendees = $wpdb->num_rows;
    $quantity = 0;
    $attendees_group = '';
    if ($total_attendees > 0) {
        foreach ($attendees as $attendee) {
            /**
            		09-07-11 Edit Seth
            		Removing the grouping functionality to make attendees easier to manage
            	**/
            #if (isset($attendees[$i])){
            //if (isset($attendees[$i])){
            //$attendee = $attendees[$i];
            //echo 'Reg. Id: '.$registration_id.'<br />';
            $registration_id = $attendee->registration_id;
            $lname = $attendee->lname;
            $fname = $attendee->fname;
            $address = $attendee->address;
            $city = $attendee->city;
            $state = $attendee->state;
            $zip = $attendee->zip;
            $email = '<span style="visibility:hidden">' . $attendee->email . '</span>';
            $phone = $attendee->phone;
            $quantity = $attendee->quantity > 1 ? '<br />(' . __('Total Attendees', 'event_espresso') . ': ' . $attendee->quantity . ')' : '';
            //if ($temp_reg_id == '') {
            $id = $attendee->id;
            //$temp_reg_id = $registration_id;
            //echo 'Temp Reg. Id: '.$registration_id.'<br />';
            $attended = $attendee->checked_in;
            $ticket_scanned = $attendee->checked_in_quantity;
            $amount_pd = $attendee->amount_pd;
            $payment_status = $attendee->payment_status;
            $payment_date = $attendee->payment_date;
            $date = $attendee->date;
            $event_id = $attendee->event_id;
            $coupon_code = $attendee->coupon_code;
            $txn_id = $attendee->txn_id;
            $txn_type = $attendee->txn_type;
            $price_option = $attendee->price_option;
            $event_time = $attendee->event_time;
            $event_name = $attendee->event_name;
            $event_date = $attendee->start_date;
            ?>
                  <tr>
                    <td class="check-column" style="padding:7px 0 22px 7px; vertical-align:top;"><input name="checkbox[<?php 
            echo $id;
            ?>
]" type="checkbox"  title="Delete <?php 
            echo $fname;
            echo $lname;
            ?>
"></td>
                    <td class="row-title"  nowrap="nowrap"><a href="admin.php?page=events&amp;event_admin_reports=edit_attendee_record&amp;event_id=<?php 
            echo $event_id;
            ?>
&amp;registration_id=<?php 
            echo $registration_id;
            ?>
&amp;form_action=edit_attendee&amp;id=<?php 
            echo $id;
            ?>
" title="<?php 
            echo 'ID#:' . $id . ' [ REG#: ' . $registration_id . ' ]';
            ?>
"><?php 
            echo $fname;
            ?>
 <?php 
            echo $lname;
            ?>
                      <?php 
            /*?><ul>
                 <?php echo $attendees_group ?>
              </ul><?php */
            ?>
                      </a></td>
                    <td nowrap="nowrap"><?php 
            echo $registration_id;
            ?>
</td>
                    <td class="date column-date"><?php 
            echo event_date_display($date, get_option('date_format') . ' g:i a');
            ?>
</td>
                    <td nowrap="nowrap"><a href="admin.php?page=events&amp;event_admin_reports=list_attendee_payments&amp;event_id=<?php 
            echo $event_id;
            ?>
" title="<?php 
            _e('View attendees for this event', 'event_espresso');
            ?>
"><?php 
            echo stripslashes_deep($event_name);
            ?>
</a></td>
                    <td nowrap="nowrap"><?php 
            echo event_date_display($event_time, get_option('time_format'));
            ?>
</td>
                    <?php 
            if ($ticketing_installed == true) {
                ?>
                    <td nowrap="nowrap"><p style="padding-left:15px"><?php 
                echo $attended == 1 || $ticket_scanned >= 1 ? event_espresso_paid_status_icon('Checkedin') : event_espresso_paid_status_icon('NotCheckedin');
                ?>
</p></td>
                    <?php 
            }
            ?>
                    <td nowrap="nowrap"><?php 
            echo $price_option;
            ?>
</td>
                    <td class="date column"><a href="admin.php?page=events&amp;attendee_pay=paynow&amp;form_action=payment&amp;registration_id=<?php 
            echo $registration_id;
            ?>
&amp;event_admin_reports=enter_attendee_payments&amp;event_id=<?php 
            echo $event_id;
            ?>
" title="<?php 
            _e('Edit Payment', 'event_espresso');
            ?>
 ID: <?php 
            echo $registration_id;
            ?>
">
                      <p style="padding-left:17px"><?php 
            event_espresso_paid_status_icon($payment_status);
            ?>
</p>
                      </a> <?php 
            /*?><a href="admin.php?page=events&amp;attendee_pay=paynow&amp;form_action=payment&amp;registration_id=<?php echo $temp_reg_id ?>&amp;event_admin_reports=enter_attendee_payments&amp;event_id=<?php echo $event_id ?>" title="<?php _e('Edit Payment', 'event_espresso'); ?> ID: <?php echo $temp_reg_id ?>"><?php //echo $org_options['currency_symbol'] ?><?php //echo $total_amount_pd ?></a><?php */
            ?>
</td>
                    <td class="date column-date"><?php 
            echo espresso_payment_type($txn_type);
            ?>
</td>
                    <td class="date column-date"><?php 
            echo $coupon_code;
            ?>
</td>
                    <td class="date column-date"><?php 
            echo $txn_id;
            ?>
</td>
                    <td class="date column-date" >
                    
                    <a href="admin.php?page=events&amp;attendee_pay=paynow&amp;form_action=payment&amp;registration_id=<?php 
            echo $registration_id;
            ?>
&amp;event_admin_reports=enter_attendee_payments&amp;event_id=<?php 
            echo $event_id;
            ?>
" title="<?php 
            _e('Edit Payment', 'event_espresso');
            ?>
 ID: <?php 
            echo $registration_id;
            ?>
"><img src="<?php 
            echo EVENT_ESPRESSO_PLUGINFULLURL;
            ?>
images/icons/money.png" width="16" height="16" alt="<?php 
            _e('Edit Payment', 'event_espresso');
            ?>
" /></a>
                    
                    <a href="admin.php?page=events&amp;event_admin_reports=edit_attendee_record&amp;registration_id=<?php 
            echo $registration_id;
            ?>
&amp;event_id=<?php 
            echo $event_id;
            ?>
&amp;form_action=edit_attendee" title="<?php 
            _e('Edit Attendee', 'event_espresso');
            ?>
"><img src="<?php 
            echo EVENT_ESPRESSO_PLUGINFULLURL;
            ?>
images/icons/user_edit.png" width="16" height="16" alt="<?php 
            _e('Edit Attendee', 'event_espresso');
            ?>
" /></a>
                    
                    <a href="admin.php?page=events&amp;event_admin_reports=resend_email&amp;registration_id=<?php 
            echo $registration_id;
            ?>
&amp;event_id=<?php 
            echo $event_id;
            ?>
&amp;form_action=resend_email" title="<?php 
            _e('Resend Registration Details', 'event_espresso');
            ?>
"><img src="<?php 
            echo EVENT_ESPRESSO_PLUGINFULLURL;
            ?>
images/icons/email_link.png" width="16" height="16" alt="<?php 
            _e('Resend Registration Details', 'event_espresso');
            ?>
" /></a>
                    
                    <a href="<?php 
            echo home_url();
            ?>
/?download_invoice=true&amp;admin=true&amp;registration_id=<?php 
            echo $registration_id;
            ?>
" target="_blank"  title="<?php 
            _e('Download Invoice', 'event_espresso');
            ?>
"><img src="<?php 
            echo EVENT_ESPRESSO_PLUGINFULLURL;
            ?>
images/icons/page_white_acrobat.png" width="16" height="16" alt="<?php 
            _e('Download Invoice', 'event_espresso');
            ?>
" /></a>
          <?php 
            if ($org_options["use_attendee_pre_approval"] == "Y") {
                ?>
          <br/>
          <a href="admin.php?page=events&amp;attendee_pay=paynow&amp;form_action=payment&amp;registration_id=<?php 
                echo $registration_id;
                ?>
&amp;event_admin_reports=enter_attendee_payments&amp;event_id=<?php 
                echo $event_id;
                ?>
" title="<?php 
                _e('Edit Payment', 'event_espresso');
                ?>
 ID: <?php 
                echo $registration_id;
                ?>
">
          <?php 
                if (is_attendee_approved($event_id, $id)) {
                    ?>
          <strong>
          <?php 
                    _e('Approved', 'event_espresso');
                    ?>
          </strong><br/>
          <?php 
                } else {
                    ?>
          <span style="color:#FF0000"><strong>
          <?php 
                    _e('Awaiting approval', 'event_espresso');
                    ?>
          </strong></span>
          <?php 
                }
                ?>
          </a>
          <?php 
            }
            ?>
</td>
      </tr>
      <?php 
            $temp_reg_id = $registration_id;
            $registration_id = '';
        }
    }
    ?>
    </tbody>
  </table>
  <div style="clear:both; margin-bottom:30px;">
    <input name="delete_customer" type="submit" class="button-secondary" id="delete_customer" value="<?php 
    _e('Delete Attendee(s)', 'event_espresso');
    ?>
" style="margin:10px 0 0 0;" onclick="return confirmDelete();" />
    <?php 
    if ($ticketing_installed == true) {
        ?>
    <input name="attended_customer" type="submit" class="button-secondary" id="attended_customer" value="<?php 
        _e('Mark as Attended', 'event_espresso');
        ?>
" style="margin:10px 0 0 10px;" />
    <input name="unattended_customer" type="submit" class="button-secondary" id="attended_customer" value="<?php 
        _e('Unmark as Attended', 'event_espresso');
        ?>
" style="margin:10px 0 0 10px;" />
    <?php 
    }
    ?>
    <a style="margin-left:5px" class="button-primary" href="admin.php?page=events&amp;action=csv_import">
    <?php 
    _e('Import CSV', 'event_espresso');
    ?>
    </a> <a class="button-primary" style="margin-left:5px" href="#" onclick="window.location='<?php 
    echo get_bloginfo('wpurl') . "/wp-admin/admin.php?event_espresso&amp;event_id=" . $_REQUEST['event_id'] . "&amp;export=report&action=payment&amp;type=excel";
    echo $_REQUEST['event_id'] == '' ? '&amp;all_events=true' : '';
    ?>
'" title="<?php 
    _e('Export to Excel', 'event_espresso');
    ?>
">
    <?php 
    _e('Export to Excel', 'event_espresso');
    ?>
    </a> <?php 
    echo isset($_REQUEST['event_id']) ? '<a style="margin-left:5px"  class="button-primary"  href="admin.php?page=events&amp;event_admin_reports=add_new_attendee&amp;event_id=' . $_REQUEST['event_id'] . '">' . __('Add Attendee', 'event_espresso') . '</a>' : '';
    ?>
 <?php 
    echo isset($_REQUEST['event_id']) ? '<a style="margin-left:5px" class="button-primary" href="admin.php?page=events&amp;action=edit&amp;event_id=' . $_REQUEST['event_id'] . '">' . __('Edit Event', 'event_espresso') . '</a>' : '';
    ?>
 </div>
</form>
 <h4 style="clear:both"><?php 
    _e('Legend', 'event_espresso');
    ?>
</h4>
<dl style="float:left; margin-left:10px; width:200px">
  <dt><?php 
    event_espresso_paid_status_icon('Completed');
    ?>
 - <?php 
    _e('Completed', 'event_espresso');
    ?>
</dt>
  <dt><?php 
    event_espresso_paid_status_icon('Incomplete');
    ?>
 - <?php 
    _e('Incomplete', 'event_espresso');
    ?>
</dt>
    <dt><?php 
    event_espresso_paid_status_icon('Pending');
    ?>
 - <?php 
    _e('Pending', 'event_espresso');
    ?>
</dt>

  <dt><img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
images/icons/money.png" width="16" height="16" alt="<?php 
    _e('Payment Details', 'event_espresso');
    ?>
" /> - <?php 
    _e('Payment Details', 'event_espresso');
    ?>
</dt>

  
  </dl>
  <dl style="float:left; margin-left:10px; width:200px">
  <dt><img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
images/icons/email_link.png" width="16" height="16" alt="<?php 
    _e('Resend Details', 'event_espresso');
    ?>
" /> - <?php 
    _e('Resend Email', 'event_espresso');
    ?>
</dt>
  <dt><img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
images/icons/page_white_acrobat.png" width="16" height="16" alt="<?php 
    _e('Download Invoice', 'event_espresso');
    ?>
" /> - <?php 
    _e('Download Invoice', 'event_espresso');
    ?>
</dt>
  <dt><img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
images/icons/user_edit.png" width="16" height="16" alt="<?php 
    _e(' Attendee Details', 'event_espresso');
    ?>
" /> - <?php 
    _e('Attendee Details', 'event_espresso');
    ?>
</dt>
</dl>
<script>
		jQuery(document).ready(function($) {
			/* show the table data */
			var mytable = $('#table').dataTable( {
				"sDom": 'Clfrtip',
				"bAutoWidth": false,
				"bStateSave": true,
				"sPaginationType": "full_numbers",
				"oLanguage": {    "sSearch": "<strong><?php 
    _e('Live Search Filter', 'event_espresso');
    ?>
:</strong> (eg, email, txn id, event, etc.)",
				"sZeroRecords": "<?php 
    _e('No Records Found!', 'event_espresso');
    ?>
" },
				"aoColumns": [
					{ "bSortable": false },
					null,
					<?php 
    echo $ticketing_installed == true ? 'null,' : '';
    ?>
					null,
					null,
					null,
					null,
					null,
					null,
					null,
					null,
					null,
					{ "bSortable": false }
				],
				"aoColumnDefs": [
					{ "bVisible": false, "aTargets": [  <?php 
    if (isset($_REQUEST['event_id'])) {
        echo '4,';
    } else {
        echo '2,';
    }
    ?>
 <?php 
    echo $ticketing_installed == true ? '10,11' : '9,10';
    ?>
 ] }
				],
				"oColVis": {
					"aiExclude": [ 0, 1],
					"buttonText": "Filter: Show / Hide Columns",
					"bRestore": true
				},
			});
		});
	</script>
<?php 
}