function edit_attendee_record()
{
    global $wpdb, $org_options;
    $attendee_num = 1;
    if ($_REQUEST['form_action'] == 'edit_attendee') {
        $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : '';
        $registration_id = isset($_REQUEST['registration_id']) ? $_REQUEST['registration_id'] : '';
        $multi_reg = false;
        $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 distinct primary_registration_id, registration_id from " . EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE . " where primary_registration_id = '{$registration_id}' ", ARRAY_A);
            $multi_reg = true;
        }
        /*
         * find the primary attendee so we know which form to present
         * since the additional attendees will have a different form
         */
        //Update the payment amount for the attendee
        if (!empty($_REQUEST['attendee_payment']) && $_REQUEST['attendee_payment'] == 'update_payment') {
            $attendee_cost_data = array("attendee_id" => $ext_attendee_id, "quantity" => $attendee_quantity, "cost" => $attendee_cost);
            $wpdb->insert(EVENTS_ATTENDEE_COST_TABLE, $attendee_cost_data);
            $c_sql = "UPDATE " . EVENTS_ATTENDEE_COST_TABLE . " SET cost = '" . $_REQUEST['amount_pd'] . "', quantity = '" . $_REQUEST['quantity'] . "' WHERE attendee_id = '" . $_REQUEST['id'] . "' ";
            $wpdb->query($c_sql);
            /*
             * Calculate total cost from attendee cost table
             */
            $event_cost = 0;
            if ($multi_reg) {
                foreach ($registration_ids as $reg_ids) {
                    $event_cost += $wpdb->get_var($wpdb->prepare("select ea.registration_id, sum(eac.cost * eac.quantity) from " . EVENTS_ATTENDEE_COST_TABLE . " eac inner join " . EVENTS_ATTENDEE_TABLE . " ea on eac.attendee_id = ea.id where ea.registration_id = '%s' group by ea.registration_id ", $reg_ids['registration_id']), 1, 0);
                }
            } else {
                $event_cost = $wpdb->get_var($wpdb->prepare("select ea.registration_id, sum(eac.cost * eac.quantity) from " . EVENTS_ATTENDEE_COST_TABLE . " eac inner join " . EVENTS_ATTENDEE_TABLE . " ea on eac.attendee_id = ea.id where ea.registration_id = '%s' group by ea.registration_id ", $registration_id), 1, 0);
            }
            $a_sql = "UPDATE " . EVENTS_ATTENDEE_TABLE . " SET quantity = '%d' WHERE id = '%d' ";
            $wpdb->query($wpdb->prepare($a_sql, $_REQUEST['quantity'], $_REQUEST['id']));
            /*
             * Get primary attendee id to update the amount_pd
             */
            $primary_attendee_id = $wpdb->get_var($wpdb->prepare("select id from " . EVENTS_ATTENDEE_TABLE . " where registration_id = '%s' order by id limit 1 ", $registration_id));
            $a_sql = "UPDATE " . EVENTS_ATTENDEE_TABLE . " SET amount_pd = '%f' WHERE id = '%d' ";
            $wpdb->query($wpdb->prepare($a_sql, $event_cost, $primary_attendee_id));
        }
        $r = $wpdb->get_row("SELECT id from " . EVENTS_ATTENDEE_TABLE . " WHERE registration_id ='{$registration_id}' ORDER BY id ");
        $primary_attendee = !empty($r->id) ? $r->id : $id;
        $is_additional_attendee = $primary_attendee != $id ? true : false;
        if (!empty($_REQUEST['attendee_action']) && $_REQUEST['attendee_action'] == 'delete_attendee') {
            $sql = " DELETE FROM " . EVENTS_ATTENDEE_TABLE . " WHERE id ='{$id}'";
            $wpdb->query($sql);
            if (defined('ESPRESSO_SEATING_CHART')) {
                $wpdb->query("DELETE FROM " . EVENTS_SEATING_CHART_EVENT_SEAT_TABLE . " where attendee_id = {$id}");
            }
            $wpdb->query("SELECT id from " . EVENTS_ATTENDEE_TABLE . " WHERE registration_id ='{$registration_id}' ");
            if ($wpdb->num_rows == 0) {
                $sql = " UPDATE " . EVENTS_ATTENDEE_TABLE . " SET quantity = IF(quantity IS NULL ,NULL,IF(quantity > 0,IF(quantity-1>0,quantity-1,1),0)) WHERE registration_id ='{$registration_id}'";
                $wpdb->query($sql);
                $sql = " UPDATE " . EVENTS_ATTENDEE_COST_TABLE . " SET quantity = IF(quantity IS NULL ,NULL,IF(quantity > 0,IF(quantity-1>0,quantity-1,1),0)) WHERE attendee_id ='{$id}'";
                $wpdb->query($sql);
                event_espresso_cleanup_multi_event_registration_id_group_data();
                event_espresso_cleanup_attendee_cost_data();
            }
        } else {
            if (!empty($_REQUEST['attendee_action']) && $_REQUEST['attendee_action'] == 'update_attendee') {
                /*
                 * Update the attendee information
                 */
                $update_time = false;
                if (isset($_POST['start_time_id'])) {
                    $times_sql = "SELECT ese.start_time, ese.end_time ";
                    $times_sql .= "FROM " . EVENTS_START_END_TABLE . " ese ";
                    $times_sql .= " WHERE ";
                    $times_sql .= "ese.id='" . $_POST['start_time_id'] . "' ";
                    $times = $wpdb->get_results($times_sql);
                    if ($wpdb->num_rows > 0) {
                        foreach ($times as $time) {
                            $start_time = $time->start_time;
                            $end_time = $time->end_time;
                        }
                        $update_time = true;
                    }
                }
                $fname = isset($_POST['fname']) ? $_POST['fname'] : '';
                $lname = isset($_POST['lname']) ? $_POST['lname'] : '';
                $address = isset($_POST['address']) ? $_POST['address'] : '';
                $address2 = isset($_POST['address2']) ? $_POST['address2'] : '';
                $city = isset($_POST['city']) ? $_POST['city'] : '';
                $state = isset($_POST['state']) ? $_POST['state'] : '';
                $zip = isset($_POST['zip']) ? $_POST['zip'] : '';
                $phone = isset($_POST['phone']) ? $_POST['phone'] : '';
                $email = isset($_POST['email']) ? $_POST['email'] : '';
                $event_id = isset($_POST['event_id']) ? $_POST['event_id'] : '';
                $txn_type = isset($_POST['txn_type']) ? $_POST['txn_type'] : '';
                $sql = "UPDATE " . EVENTS_ATTENDEE_TABLE . " SET fname='{$fname}', lname='{$lname}', address='{$address}',address2='{$address2}', city='{$city}', state='{$state}', zip='{$zip}', phone='{$phone}', email='{$email}', txn_type='{$txn_type}' ";
                if ($update_time == true) {
                    $sql .= ", event_time='{$start_time}', end_time='{$end_time}' ";
                }
                $sql .= " WHERE id ='{$id}' ";
                $wpdb->query($sql);
                // Insert Additional Questions From Post Here
                $reg_id = $id;
                $response_source = $_POST;
                $questions = $wpdb->get_row("SELECT question_groups, event_meta FROM " . EVENTS_DETAIL_TABLE . " WHERE id = " . $event_id . " ");
                $question_groups = unserialize($questions->question_groups);
                $event_meta = unserialize($questions->event_meta);
                if ($is_additional_attendee && isset($event_meta['add_attendee_question_groups']) && $event_meta['add_attendee_question_groups'] != NULL) {
                    $question_groups = $event_meta['add_attendee_question_groups'];
                }
                $questions_in = '';
                foreach ($question_groups as $g_id) {
                    $questions_in .= $g_id . ',';
                }
                $questions_in = substr($questions_in, 0, -1);
                $group_name = '';
                $counter = 0;
                //pull the list of questions that are relevant to this event
                $q_sql_1 = "SELECT q.*, q.id q_id, qg.group_name FROM " . EVENTS_QUESTION_TABLE . " q\n\t\t\t\t\t\tJOIN " . EVENTS_QST_GROUP_REL_TABLE . " qgr on q.id = qgr.question_id\n\t\t\t\t\t\tJOIN " . EVENTS_QST_GROUP_TABLE . " qg on qg.id = qgr.group_id\n\t\t\t\t\t\tWHERE qgr.group_id in (" . $questions_in . ")\n\t\t\t\t\t\tORDER BY qg.id, q.sequence ASC";
                $questions = $wpdb->get_results($q_sql_1);
                $a_sql = "SELECT id, question_id, answer FROM " . EVENTS_ANSWER_TABLE . " at WHERE at.attendee_id = '" . $id . "' ";
                $answers = $wpdb->get_results($a_sql, OBJECT_K);
                foreach ($answers as $answer) {
                    $answer_a[] = $answer->question_id;
                }
                if ($questions) {
                    foreach ($questions as $question) {
                        switch ($question->question_type) {
                            case "TEXT":
                            case "TEXTAREA":
                            case "DROPDOWN":
                                $post_val = $question->system_name != '' ? $response_source[$question->system_name] : $response_source[$question->question_type . '_' . $question->q_id];
                                if (in_array($question->q_id, $answer_a)) {
                                    $sql = "UPDATE " . EVENTS_ANSWER_TABLE . " SET answer='{$post_val}' WHERE attendee_id = '{$id}' AND question_id ='{$question->q_id}'";
                                } else {
                                    $sql = "INSERT INTO " . EVENTS_ANSWER_TABLE . " (registration_id, answer,attendee_id,question_id) VALUES ('{$registration_id}','{$post_val}', {$id},{$question->q_id})";
                                }
                                $wpdb->query($sql);
                                break;
                            case "SINGLE":
                                $post_val = $question->system_name != '' ? $response_source[$question->system_name] : $response_source[$question->question_type . '_' . $question->q_id];
                                if (in_array($question->q_id, $answer_a)) {
                                    $sql = "UPDATE " . EVENTS_ANSWER_TABLE . " SET answer='{$post_val}' WHERE attendee_id = '{$id}' AND question_id ='{$question->q_id}'";
                                } else {
                                    $sql = "INSERT INTO " . EVENTS_ANSWER_TABLE . " (registration_id, answer,attendee_id,question_id) VALUES ('{$registration_id}','{$post_val}', {$id},{$question->q_id})";
                                }
                                $wpdb->query($sql);
                                break;
                            case "MULTIPLE":
                                $value_string = '';
                                for ($i = 0; $i < count($response_source[$question->question_type . '_' . $question->id]); $i++) {
                                    $value_string .= trim($response_source[$question->question_type . '_' . $question->id][$i]) . ",";
                                }
                                if (in_array($question->q_id, $answer_a)) {
                                    $sql = "UPDATE " . EVENTS_ANSWER_TABLE . " SET answer='{$value_string}' WHERE attendee_id = '{$id}' AND question_id ='{$question->q_id}'";
                                } else {
                                    $sql = "INSERT INTO " . EVENTS_ANSWER_TABLE . " (registration_id, answer,attendee_id,question_id) VALUES ('{$registration_id}','{$value_string}', {$id}, {$question->q_id})";
                                }
                                $wpdb->query($sql);
                                break;
                        }
                    }
                }
            }
        }
        $counter = 0;
        $additional_attendees = NULL;
        $WHERE = isset($_REQUEST['registration_id']) ? "registration_id ='" . $_REQUEST['registration_id'] . "'" : "id = " . $_REQUEST['id'];
        if (isset($_REQUEST['attendee_num']) && $_REQUEST['attendee_num'] > 1 && isset($_REQUEST['registration_id']) && isset($_REQUEST['id'])) {
            $WHERE = " t1.registration_id ='" . $_REQUEST['registration_id'] . "' AND t1.id = " . $_REQUEST['id'];
        }
        $results = $wpdb->get_results("SELECT t1.*, t2.event_name, t2.question_groups, t2.event_meta FROM " . EVENTS_ATTENDEE_TABLE . " t1\n                 JOIN " . EVENTS_DETAIL_TABLE . " t2\n                 ON t1.event_id = t2.id\n                 WHERE {$WHERE}\n                 ORDER BY t1.id");
        foreach ($results as $result) {
            if ($counter == 0) {
                $id = $result->id;
                $registration_id = $result->registration_id;
                $lname = $result->lname;
                $fname = $result->fname;
                $address = $result->address;
                $address2 = $result->address2;
                $city = $result->city;
                $state = $result->state;
                $zip = $result->zip;
                $email = $result->email;
                $hear = isset($result->hear) ? $result->hear : '';
                $payment = $result->payment;
                $phone = $result->phone;
                $date = $result->date;
                $payment_status = $result->payment_status;
                $txn_type = $result->txn_type;
                $txn_id = $result->txn_id;
                $amount_pd = $result->amount_pd;
                $quantity = $result->quantity;
                $payment_date = $result->payment_date;
                $event_id = $result->event_id;
                $event_name = $result->event_name;
                $question_groups = unserialize($result->question_groups);
                $question_groups = unserialize($result->question_groups);
                $event_meta = unserialize($result->event_meta);
                $coupon_code = $result->coupon_code;
                $quantity = $result->quantity;
                $is_additional_attendee = $primary_attendee != $id ? true : false;
                $start_date = $result->start_date;
                $event_time = $result->event_time;
                $event_date = event_date_display($start_date . ' ' . $event_time, get_option('date_format') . ' g:i a');
                if ($is_additional_attendee && isset($event_meta['add_attendee_question_groups']) && $event_meta['add_attendee_question_groups'] != NULL) {
                    $question_groups = $event_meta['add_attendee_question_groups'];
                }
                $counter = 1;
            } else {
                $additional_attendees[$result->id] = array('full_name' => $result->fname . ' ' . $result->lname, 'email' => $result->email, 'phone' => $result->phone);
            }
        }
        if (!empty($_REQUEST['status']) && $_REQUEST['status'] == 'saved') {
            ?>

			<div id="message" class="updated fade">
			  <p><strong>
			<?php 
            _e('Attendee details saved for ' . $fname . ' ' . $lname . '.', 'event_espresso');
            ?>
			    </strong></p>
			</div>
			<?php 
        }
        ?>
		<div class="metabox-holder">
		  <div class="postbox">
		    <h3>
					<?php 
        _e('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">#' . $registration_id . '</a> | ID #' . $id . ' | Name: ' . $fname . ' ' . $lname . ' | 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>
		    <div class="inside">
		      <table width="100%">
		        <tr>
		          <td width="50%"><form method="post" action="<?php 
        echo $_SERVER['REQUEST_URI'];
        ?>
" class="espresso_form">
		              <h4>
		<?php 
        _e('Registration Information', 'event_espresso');
        ?>
		<?php 
        echo $is_additional_attendee == false ? '[ <span class="green_text">' . __('Primary Attendee Record', 'event_espresso') . '</span> ]' : '[ <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 Primary Attendee</a> ]';
        ?>
 </h4>
		              <fieldset>
		                <ul>
		                  <li>
		<?php 
        $time_id = 0;
        $sql = "SELECT id FROM " . EVENTS_START_END_TABLE . " WHERE event_id='" . $event_id . "' AND start_time = '" . $event_time . "' ";
        $event_times = $wpdb->get_results($sql);
        if ($wpdb->num_rows > 0) {
            $time_id = $wpdb->last_result[0]->id;
        }
        echo event_espresso_time_dropdown($event_id, $label = 1, $multi_reg = 0, $time_id);
        ?>
		                  </li>
		                  <li>
												<?php 
        if (count($question_groups) > 0) {
            $questions_in = '';
            foreach ($question_groups as $g_id) {
                $questions_in .= $g_id . ',';
            }
            $questions_in = substr($questions_in, 0, -1);
            $group_name = '';
            $counter = 0;
            $FILTER = '';
            if (isset($event_meta['additional_attendee_reg_info']) && $event_meta['additional_attendee_reg_info'] == '2' && isset($_REQUEST['attendee_num']) && $_REQUEST['attendee_num'] > 1) {
                $FILTER .= " AND qg.system_group = 1 ";
            }
            //pull the list of questions that are relevant to this event
            $q_sql_2 = "SELECT q.*, q.id q_id, at.*, qg.group_name, qg.show_group_description, qg.show_group_name FROM " . EVENTS_QUESTION_TABLE . " q\n\t\t\t\t\tLEFT JOIN " . EVENTS_ANSWER_TABLE . " at on q.id = at.question_id\n\t\t\t\t\tJOIN " . EVENTS_QST_GROUP_REL_TABLE . " qgr on q.id = qgr.question_id\n\t\t\t\t\tJOIN " . EVENTS_QST_GROUP_TABLE . " qg on qg.id = qgr.group_id\n\t\t\t\t\tWHERE qgr.group_id in (" . $questions_in . ")\n\t\t\t\t\tAND (at.attendee_id IS NULL OR at.attendee_id = '" . $id . "')\n\t\t\t\t\t" . $FILTER . "\n\t\t\t\t\tORDER BY qg.id, q.id ASC";
            $questions = $wpdb->get_results($q_sql_2);
            $num_rows = $wpdb->num_rows;
            if ($num_rows > 0) {
                //Output the questions
                $question_displayed = array();
                foreach ($questions as $question) {
                    $counter++;
                    if (!in_array($question->id, $question_displayed)) {
                        $question_displayed[] = $question->id;
                        echo '<p>';
                        echo event_form_build_edit($question, empty($question->answer) ? '' : $question->answer, $show_admin_only = true);
                        echo "</p>";
                        echo $counter == $num_rows ? '</fieldset>' : '';
                    }
                }
            }
            //end questions display
        }
        ?>
		                  </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="event_id" value="<?php 
        echo $event_id;
        ?>
" />
		                  <input type="hidden" name="display_action" value="view_list" />
		                  <input type="hidden" name="form_action" value="edit_attendee" />
		                  <input type="hidden" name="attendee_action" value="update_attendee" />
		                  <li>
		                    <input type="submit" name="Submit" value="<?php 
        _e('Update Record', 'event_espresso');
        ?>
" />
		                  </li>
		                </ul>
		              </fieldset>
		            </form></td>
		          <td  width="50%" valign="top"><?php 
        if (count($additional_attendees) > 0) {
            ?>
			            <h4>
			<?php 
            _e('Additional Attendees', 'event_espresso');
            ?>
			            </h4>
			            <ol>
			<?php 
            foreach ($additional_attendees as $att => $row) {
                $attendee_num++;
                ?>
				              <li><a href="admin.php?page=events&amp;event_admin_reports=edit_attendee_record&amp;event_id=<?php 
                echo $event_id;
                ?>
&amp;id=<?php 
                echo $att;
                ?>
&amp;registration_id=<?php 
                echo $registration_id;
                ?>
&amp;form_action=edit_attendee&amp;attendee_num=<?php 
                echo $attendee_num;
                ?>
" title="<?php 
                _e('Edit Attendee', 'event_espresso');
                ?>
"><strong><?php 
                echo $row['full_name'];
                ?>
</strong> (<?php 
                echo $row['email'];
                ?>
)</a> | <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;attendee_id=<?php 
                echo $att;
                ?>
&amp;form_action=edit_attendee&amp;attendee_action=delete_attendee&amp;id=<?php 
                echo $att;
                ?>
" title="<?php 
                _e('Delete Attendee', 'event_espresso');
                ?>
" onclick="return confirmDelete();">
				<?php 
                _e('Delete', 'event_espresso');
                ?>
				                </a></li>
				<?php 
            }
            ?>
			            </ol>
		<?php 
        }
        ?>
									<?php 
        /**
         * Begin Attendee Payment Information
         * */
        $has_seating_chart = false;
        if (defined('ESPRESSO_SEATING_CHART')) {
            $has_seating_chart = seating_chart::check_event_has_seating_chart($event_id);
        }
        /**
         * If attendee was added in old system i.e. before version 3.1.10 and attendee_cost table got introduced then this option can not be used
         * */
        $ice_age = true;
        $ice_row = $wpdb->get_row($wpdb->prepare("select * from " . EVENTS_ATTENDEE_COST_TABLE . " where attendee_id = '%d'", $id));
        if ($ice_row !== NULL) {
            $ice_age = false;
        }
        if (!$has_seating_chart && !$ice_age) {
            ?>
			            <h4>
									<?php 
            _e('Payment Information', 'event_espresso');
            ?>
			            </h4>
			            <form method="POST" action="<?php 
            echo $_SERVER['REQUEST_URI'];
            ?>
&status=saved" class="espresso_form">
			              <fieldset>
			                <ul>
			                  <li>
			                    <p><strong>
									<?php 
            _e('Payment Status:', 'event_espresso');
            ?>
			                      </strong> <?php 
            echo $payment_status;
            ?>
 <?php 
            echo event_espresso_paid_status_icon($payment_status);
            ?>
 [ <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');
            ?>
">
									<?php 
            _e('View/Edit Payment', 'event_espresso');
            ?>
			                      </a> ]</p>
			                  </li>
			                  <li>
			                    <p><strong>
									<?php 
            _e('Transaction ID:', 'event_espresso');
            ?>
			                      </strong> <?php 
            echo !empty($txn_id) ? $txn_id : 'N/A';
            ?>
</p>
			                  </li>
			                  <li>
			                    <p><strong>
										<?php 
            _e('Date Paid:', 'event_espresso');
            ?>
			                      </strong> <?php 
            echo !empty($payment_date) ? event_date_display($payment_date) : 'N/A';
            ?>
</p>
			                  </li>
			<?php 
            if ($multi_reg == true) {
                ?>
				                  <li>
				                    <p><strong>
				<?php 
                _e('Multiple Event Total:', 'event_espresso');
                ?>
				                      </strong> <?php 
                echo $org_options['currency_symbol'];
                echo espresso_attendee_price(array('attendee_id' => $id, 'session_total' => true));
                ?>
</p>
				                  </li>
															<?php 
            }
            ?>
			                  <li>
			                    <p><strong>
			<?php 
            _e('This Registration Total:', 'event_espresso');
            ?>
			                      </strong> <?php 
            echo $org_options['currency_symbol'];
            echo espresso_attendee_price(array('attendee_id' => $id, 'reg_total' => true));
            ?>
</p>
			                  </li>
			                  <li> <div  <?php 
            if (isset($_REQUEST['show_payment']) && $_REQUEST['show_payment'] == 'true') {
                echo ' class="yellow_inform"';
            }
            ?>
><strong>
			<?php 
            _e('This Attendee:', 'event_espresso');
            ?>
														</strong>
														<table width="100%" border="0">
															<tr>
																<td width="25%" align="left" valign="top"><label>
			<?php 
            _e('Amount:', 'event_espresso');
            ?>
																	</label></td>
																<td width="25%" align="left" valign="top"><label>
			<?php 
            _e('# Tickets:', 'event_espresso');
            ?>
																	</label></td>
																<td width="50%" align="left" valign="top"><label>
			<?php 
            _e('Total:', 'event_espresso');
            ?>
																	</label></td>
															</tr>
															<tr>
																<td align="left" valign="top"><?php 
            echo $org_options['currency_symbol'];
            ?>
																	<input name="amount_pd" type="text" value ="<?php 
            echo espresso_attendee_price(array('attendee_id' => $id, 'single_price' => true));
            ?>
" /></td>
																<td align="left" valign="top"> X
																	<input name="quantity" type="text" value ="<?php 
            echo !empty($quantity) ? $quantity : 1;
            ?>
"  /></td>
																<td align="left" valign="top"><?php 
            echo $org_options['currency_symbol'];
            echo espresso_attendee_price(array('attendee_id' => $id));
            ?>
</td>
															</tr>
														</table></div>
			                  </li>
			                  <li>
			                    <input type="submit" name="Submit" value="Update Payment" />
			                  </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="edit_attendee" />
			              <input type="hidden" name="event_id" value="<?php 
            echo $event_id;
            ?>
" />
			              <input type="hidden" name="attendee_payment" value="update_payment" />
			            </form>
			<?php 
        }
        // !$has_seating_chart
        ?>
</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>
		</div>
		<?php 
    }
}
?>
 <?php 
echo $payment_date == '' || $payment_status == 'Pending' && (espresso_payment_type($txn_type) == 'Invoice' || espresso_payment_type($txn_type) == 'Offline payment') ? '' : '<tr><td>' . __('Payment Date:', 'event_espresso') . '</td> <td>' . event_date_display($payment_date) . '</td></tr>';
?>
		</tr>
		<tr>
			<td><?php 
_e('Amount Paid/Owed:', 'event_espresso');
?>
</td>
			<td><?php 
echo $org_options['currency_symbol'];
echo $total_cost;
?>
				<?php 
event_espresso_paid_status_icon($payment_status);
?>
			</td>
		</tr>
		<tr>
			<td>
				<?php 
_e('Payment Status:', 'event_espresso');
?>
			</td>
			<?php 
// localize all the things!
switch ($payment_status) {
    case 'Pending':
        $payment_status_translated = __('Pending', 'event_espresso');
        break;
function event_espresso_my_events()
{
    global $espresso_premium;
    if ($espresso_premium != true) {
        return;
    }
    global $wpdb, $org_options;
    global $ticketing_installed;
    //$wpdb->show_errors();
    require_once 'user_vars.php';
    ?>
    
	<div id="configure_organization_form" class="wrap meta-box-sortables ui-sortable">
  	<div id="event_reg_theme" class="wrap">
	<div id="icon-options-event" class="icon32"></div><h2><?php 
    echo _e('My Events Management', 'event_espresso');
    ?>
</h2>
    <div id="poststuff" class="metabox-holder">
<?php 
    if ($_POST['cancel_registration']) {
        if (is_array($_POST['checkbox'])) {
            while (list($key, $value) = each($_POST['checkbox'])) {
                $del_id = $key;
                //Delete discount data
                $sql = "DELETE FROM " . EVENTS_ATTENDEE_TABLE . " WHERE id='{$del_id}'";
                $wpdb->query($sql);
                $sql = "DELETE FROM " . EVENTS_MEMBER_REL_TABLE . " WHERE attendee_id='{$del_id}'";
                $wpdb->query($sql);
            }
        }
        ?>
	<div id="message" class="updated fade"><p><strong><?php 
        _e('Your event(s) have been successfully removed from your account.', 'event_espresso');
        ?>
</strong></p></div>
<?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:5%;"></th>
		  <th class="manage-column column-title" id="name" scope="col" title="Click to Sort" style="width:10%;"><span><?php 
    _e('Event Name', '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('Option', 'event_espresso');
    ?>
</span>
            <span class="sorting-indicator"></span>
          </th>
		  <th class="manage-column column-author" id="start" scope="col" title="Click to Sort" style="width:10%;"><span><?php 
    _e('Start Date', 'event_espresso');
    ?>
</span><span class="sorting-indicator"></span></th>
          <th class="manage-column column-date" id="begins" scope="col" title="Click to Sort" style="width:10%;"><span><?php 
    _e('Start Time', 'event_espresso');
    ?>
</span><span class="sorting-indicator"></span></th>
          <th class="manage-column column-date" id="status" scope="col" title="Click to Sort" style="width:10%;"><span><?php 
    _e('Payment Status', 'event_espresso');
    ?>
</span><span class="sorting-indicator"></span></th>
          <th class="manage-column column-date" id="attendees" scope="col" title="Click to Sort" style="width:10%;"><span><?php 
    _e('Cost', 'event_espresso');
    ?>
</span><span class="sorting-indicator"></span></th>
          <?php 
    echo $ticketing_installed == true ? '<th class="manage-column column-author" id="ticket" scope="col" title="Click to Sort" style="width:20%;">' . __('Ticket', 'event_espresso') . '</th>' : '';
    ?>
		</tr>
</thead>
    <tbody>
<?php 
    $wpdb->get_results("SELECT id FROM " . EVENTS_MEMBER_REL_TABLE . " WHERE user_id = '" . $current_user->ID . "'");
    if ($wpdb->num_rows > 0) {
        $events = $wpdb->get_results("SELECT e.id event_id, e.event_name, e.event_code, e.start_date, e.event_desc, e.display_desc, a.id attendee_id, a.event_time start_time, a.payment_status, a.payment_date, a.amount_pd, u.user_id user_id, a.registration_id, a.lname, a.lname, a.price_option, a.event_time\n\t\t\t\t\t\t\t\t\t\t\t \tFROM " . EVENTS_ATTENDEE_TABLE . " a\n\t\t\t\t\t\t\t\t\t\t\t\tJOIN " . EVENTS_MEMBER_REL_TABLE . " u ON u.attendee_id = a.id\n\t\t\t\t\t\t\t\t\t\t\t\tJOIN " . EVENTS_DETAIL_TABLE . " e ON e.id = u.event_id\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE u.user_id = '" . $current_user->ID . "'");
        foreach ($events as $event) {
            $event_id = $event->event_id;
            $event_code = $event->event_code;
            $attendee_id = $event->attendee_id;
            $registration_id = $event->registration_id;
            $lname = $attendee->lname;
            $fname = $attendee->fname;
            $event_name = $event->event_name;
            $start_date = $event->start_date;
            $start_time = $event->start_time;
            $event_desc = $event->event_desc;
            $display_desc = $event->display_desc;
            $payment_status = $event->payment_status;
            $amount_pd = $event->amount_pd;
            $payment_date = $event->payment_date;
            $ticket_type = $event->price_option;
            if ($payment_status == '') {
                $payment_link = get_option('siteurl') . "/?page_id=" . $org_options['return_url'] . "&id=" . $attendee_id;
                $payment_status = '<a href="' . $payment_link . '">Pay Now</a>';
            }
            $event_url = home_url() . "/?page_id=" . $org_options['event_page_id'] . "&regevent_action=register&event_id=" . $event_id;
            $event_link = '<a class="row-title" href="' . $event_url . '">' . stripslashes_deep($event->event_name) . '</a>';
            //Build the payment link
            $payment_url = home_url() . "/?page_id=" . $org_options['return_url'] . "&amp;registration_id=" . $registration_id;
            //$payment_link = '<a href="' . $payment_url . '" title="'.__('View Your Payment Details').'">' . event_espresso_paid_status_icon( $payment_status ) . '</a>';
            //If the custom ticket is available, load the template file
            if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . "/ticketing/template.php")) {
                if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . "/ticketing/functions.php")) {
                    include_once EVENT_ESPRESSO_UPLOAD_DIR . "/ticketing/functions.php";
                    $qr_code = espresso_qr_code(array('attendee_id' => $attendee_id, 'event_name' => stripslashes_deep($event_name), 'attendee_first' => $fname, 'attendee_last' => $lname, 'registration_id' => $registration_id, 'event_code' => $event_code, 'ticket_type' => $ticket_type, 'event_time' => $event_time, 'amount_pd' => $amount_pd));
                }
                //Build the ticket link
                $ticket_url = home_url() . "/?download_ticket=true&amp;id=" . $attendee_id . "&amp;registration_id=" . $registration_id;
                $ticket_link = '<strong><a href="' . $ticket_url . '">' . __('Download Ticket Now!') . '</a></strong>';
            }
            ?>
	<tr>
	<td><input name="checkbox[<?php 
            echo $attendee_id;
            ?>
]" type="checkbox"  title="Cancel registration for <?php 
            echo $event_name;
            ?>
"></td>
			  <td class="post-title page-title column-title"><strong><?php 
            echo $event_link;
            ?>
</strong> </td>
              <td class="post-title page-title column-title"><?php 
            echo $ticket_type;
            ?>
</td>
			  <td class="date column-date"><?php 
            echo event_date_display($start_date);
            ?>
</td>
              <td class="date column-date"><?php 
            echo $start_time;
            ?>
</td>
              <td class="date column-date"><?php 
            echo '<a target="_blank" href="' . $payment_url . '" title="' . __('View Your Payment Details') . '">';
            event_espresso_paid_status_icon($payment_status) . '</a>';
            ?>
</td>
              <td class="date column-date"><?php 
            echo $org_options['currency_symbol'];
            echo $amount_pd;
            ?>
</td>
              <?php 
            echo $ticketing_installed == true ? '<td>' . $ticket_link . '</td>' : '';
            ?>
			  </tr>
              <div id="event_info_<?php 
            echo $attendee_id;
            ?>
" style="display:none">
              <?php 
            _e('<h2>Event Information</h2>', 'event_espresso');
            ?>
				<ul>
                <li><h3 class="h3_event_title" id="h3_event_title-<?php 
            echo $event_id;
            ?>
"><?php 
            echo $event_name;
            ?>
</h3>
					<p class="p_start_date"><?php 
            _e('Start Date:', 'event_espresso');
            ?>
 <?php 
            echo event_date_display($start_date);
            ?>
</p></li>
				<li><p class="p_event_time"><?php 
            _e('Start Time:', 'event_espresso');
            ?>
 <?php 
            echo $start_time;
            ?>
</p></li>
                <li><?php 
            if ($display_desc == "Y") {
                ?>
					<strong><?php 
                _e('Description:', 'event_espresso');
                ?>
</strong>
					<?php 
                echo htmlspecialchars_decode($event_desc);
                ?>
					<?php 
            }
            //End display description
            ?>
</li>
                
                </ul>
            </div>
	<?php 
        }
    }
    ?>
          </tbody>
          </table>
          <div style="clear:both; margin-bottom:30px;">
		<input type="checkbox" name="sAll" onclick="selectAll(this)" /> <strong><?php 
    _e('Check All', 'event_espresso');
    ?>
</strong> 
    	<input name="cancel_registration" type="submit" class="button-secondary" id="cancel_registration" value="<?php 
    _e('Cancel Registration', 'event_espresso');
    ?>
" style="margin-left:100px;" onclick="return confirmDelete();"> <a style="margin-left:20px" class="button-primary"  onclick="window.location='profile.php#event_espresso_profile'">
    <?php 
    _e('Your Profile', 'event_espresso');
    ?>
    </a>
    </div>
		</form>
   </div>
</div>       
         </div> 

<script>
jQuery(document).ready(function($) {						
		
	/* show the table data */
	var mytable = $('#table').dataTable( {
			"bStateSave": true,
			"sPaginationType": "full_numbers",

			"oLanguage": {	"sSearch": "<strong><?php 
    _e('Live Search Filter', 'event_espresso');
    ?>
:</strong>",
						 	"sZeroRecords": "<?php 
    _e('No Records Found!', 'event_espresso');
    ?>
" },
			"aoColumns": [
							{ "bSortable": false },
							 null,
							 null,
							 null,
							 null,
							 null,
							<?php 
    echo $ticketing_installed == true ? 'null,' : '';
    ?>
							 null
						]

	} );
	
} );
</script>

	
<?php 
}
Exemplo n.º 4
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 event_espresso_my_events()
    {
        global $espresso_premium;
        if ($espresso_premium != true) {
            return;
        }
        global $wpdb, $org_options;
        global $ticketing_installed;
        require_once 'user_vars.php';
        if (!is_user_logged_in()) {
            if ($login_page != '') {
                printf('<p>Please <a href="%s">log in</a> to view the events you are registered to attend.</p>', $login_page);
            } else {
                echo '<p>You must be logged in to view this page.</p>';
                return;
            }
        }
        ?>
		
		<div id="configure_organization_form" class="wrap meta-box-sortables ui-sortable">
		<div id="event_reg_theme" class="wrap">
		<div id="icon-options-event" class="icon32"></div><h2><?php 
        echo _e('My Events Management', 'event_espresso');
        ?>
</h2>
		<div id="poststuff" class="metabox-holder">
	<?php 
        if (isset($_POST['cancel_registration'])) {
            if (is_array($_POST['checkbox'])) {
                while (list($key, $value) = each($_POST['checkbox'])) {
                    $del_attendee = $wpdb->prepare("DELETE FROM " . EVENTS_ATTENDEE_TABLE . " WHERE id = %d", $key);
                    $wpdb->query($del_attendee);
                    $del_attendee_member_rel = $wpdb->prepare("DELETE FROM " . EVENTS_MEMBER_REL_TABLE . " WHERE attendee_id = %d and user_id = %d", $key, $userid);
                    $wpdb->query($del_attendee_member_rel);
                }
            }
            ?>
		<div id="message" class="updated fade"><p><strong><?php 
            _e('The event(s) have been successfully removed from your account.', 'event_espresso');
            ?>
</strong></p></div>
	<?php 
        }
        ?>
	<form id="form1" name="form1" method="post" action="<?php 
        echo $_SERVER["REQUEST_URI"];
        ?>
">
	<div style="clear:both; margin-bottom:30px;"></div>
	<table id="table" class="widefat my_events_table" width="100%"> 
		<thead>
			<tr>
			  <th class="manage-column column-cb check-column" id="cb" scope="col" style="width:5%;"></th>
			  <th class="manage-column column-title" id="name" scope="col" title="Click to Sort" style="width:10%;"><span><?php 
        _e('Event Name', '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('Type', 'event_espresso');
        ?>
</span>
				<span class="sorting-indicator"></span>
			  </th>
			  <th class="manage-column column-author" id="start" scope="col" title="Click to Sort" style="width:10%;"><span><?php 
        _e('Date', 'event_espresso');
        ?>
</span><span class="sorting-indicator"></span></th>
			  <th class="manage-column column-date" id="begins" scope="col" title="Click to Sort" style="width:5%;"><span><?php 
        _e('Time', 'event_espresso');
        ?>
</span><span class="sorting-indicator"></span></th>
			  <th class="manage-column column-date" id="status" scope="col" title="Click to Sort" style="width:5%;"><span><?php 
        _e('Status', 'event_espresso');
        ?>
</span><span class="sorting-indicator"></span></th>
			  <th class="manage-column column-date" id="attendees" scope="col" title="Click to Sort" style="width:5%;"><span><?php 
        _e('Cost', 'event_espresso');
        ?>
</span><span class="sorting-indicator"></span></th>
			  <th class="manage-column column-date" id="invoice" scope="col" style="width:5%;"><?php 
        _e('Invoice', 'event_espresso');
        ?>
</th>
			  <?php 
        echo $ticketing_installed == true ? '<th class="manage-column column-author" id="ticket" scope="col" style="width:10%;">' . __('Ticket', 'event_espresso') . '</th>' : '';
        ?>
			</tr>
	</thead>
		<tbody>
	<?php 
        $wpdb->get_results("SELECT id FROM " . EVENTS_MEMBER_REL_TABLE . " WHERE user_id = '" . $current_user->ID . "'");
        if ($wpdb->num_rows > 0) {
            $events = $wpdb->get_results("SELECT e.id event_id, e.event_name, e.event_code, e.start_date, e.event_desc, e.display_desc, a.id attendee_id, a.event_time start_time, a.payment_status, a.payment_date, a.amount_pd, u.user_id user_id, a.registration_id, a.fname, a.lname, a.price_option, a.event_time\n\t\t\t\t\t\t\t\t\t\t\t\t\tFROM " . EVENTS_ATTENDEE_TABLE . " a\n\t\t\t\t\t\t\t\t\t\t\t\t\tJOIN " . EVENTS_MEMBER_REL_TABLE . " u ON u.attendee_id = a.id\n\t\t\t\t\t\t\t\t\t\t\t\t\tJOIN " . EVENTS_DETAIL_TABLE . " e ON e.id = u.event_id\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE u.user_id = '" . $current_user->ID . "'");
            foreach ($events as $event) {
                $event_id = $event->event_id;
                $event_code = $event->event_code;
                $attendee_id = $event->attendee_id;
                $registration_id = $event->registration_id;
                $lname = $event->lname;
                $fname = $event->fname;
                $event_name = $event->event_name;
                $start_date = $event->start_date;
                $start_time = $event->start_time;
                $event_desc = $event->event_desc;
                $display_desc = $event->display_desc;
                $payment_status = $event->payment_status;
                $amount_pd = espresso_attendee_price(array('attendee_id' => $attendee_id));
                $payment_date = $event->payment_date;
                $ticket_type = $event->price_option;
                if ($payment_status == '') {
                    $payment_link = get_option('siteurl') . "/?page_id=" . $org_options['return_url'] . "&id=" . $attendee_id;
                    $payment_status = '<a href="' . $payment_link . '">Pay Now</a>';
                }
                $event_url = home_url() . "/?page_id=" . $org_options['event_page_id'] . "&regevent_action=register&event_id=" . $event_id;
                $event_link = '<a class="row-title" href="' . $event_url . '">' . stripslashes_deep($event->event_name) . '</a>';
                //Build the payment link
                $payment_url = home_url() . "/?page_id=" . $org_options['return_url'] . "&amp;registration_id=" . $registration_id;
                //$payment_link = '<a href="' . $payment_url . '" title="'.__('View Your Payment Details').'">' . event_espresso_paid_status_icon( $payment_status ) . '</a>';
                //Deprecated ticketing system support
                //If the custom ticket is available, load the template file
                if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . "/ticketing/template.php")) {
                    if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . "/ticketing/functions.php")) {
                        include_once EVENT_ESPRESSO_UPLOAD_DIR . "/ticketing/functions.php";
                        $qr_code = espresso_qr_code(array('attendee_id' => $attendee_id, 'event_name' => stripslashes_deep($event_name), 'attendee_first' => $fname, 'attendee_last' => $lname, 'registration_id' => $registration_id, 'event_code' => $event_code, 'ticket_type' => $ticket_type, 'event_time' => $event_time, 'amount_pd' => $amount_pd));
                    }
                    //Build the ticket link
                    $ticket_url = home_url() . "/?download_ticket=true&amp;id=" . $attendee_id . "&amp;registration_id=" . $registration_id;
                    $ticket_link = '<a href="' . $ticket_url . '">' . __('Download Ticket Now!') . '</a>';
                }
                //New ticketing system suport
                if (function_exists('espresso_ticket_launch')) {
                    $ticket_link = espresso_ticket_links($registration_id, $attendee_id);
                }
                ?>
		<tr>
		<td><input name="checkbox[<?php 
                echo $attendee_id;
                ?>
]" type="checkbox"  title="Cancel registration for <?php 
                echo $event_name;
                ?>
"></td>
				  <td class="post-title page-title column-title"><strong><?php 
                echo $event_link;
                ?>
</strong> </td>
				  <td class="post-title page-title column-title"><?php 
                echo $ticket_type;
                ?>
</td>
				  <td class="date column-date"><?php 
                echo event_date_display($start_date);
                ?>
</td>
				  <td class="date column-date"><?php 
                echo $start_time;
                ?>
</td>
				  <td class="date column-date"><?php 
                echo '<a target="_blank" href="' . $payment_url . '" title="' . __('View Your Payment Details') . '">';
                event_espresso_paid_status_icon($payment_status) . '</a>';
                ?>
</td>
				  <td class="date column-date"><?php 
                echo $org_options['currency_symbol'];
                echo $amount_pd;
                ?>
</td>
				  <td class="date column-date"><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></td>
				  <?php 
                echo $ticketing_installed == true ? '<td class="post-title page-title column-title">' . $ticket_link . '</td>' : '';
                ?>
				  </tr>
		<?php 
            }
        }
        ?>
			  </tbody>
			  </table>
			  <div class="bottom_settings" style="clear:both; margin-bottom:30px;">
			<input type="checkbox" name="sAll" onclick="selectAll(this)" /> <strong><?php 
        _e('Check All', 'event_espresso');
        ?>
</strong> 
			<input name="cancel_registration" type="submit" class="button-secondary" id="cancel_registration" value="<?php 
        _e('Cancel Registration', 'event_espresso');
        ?>
" onclick="return confirmDelete();"> <a style="margin-left:20px" class="button-primary"  onclick="window.location='<?php 
        echo admin_url();
        ?>
profile.php#event_espresso_profile'"><?php 
        _e('Your Profile', 'event_espresso');
        ?>
</a>
		</div>
			</form>
	   </div>
	</div>       
			 </div> 
	
	<script>
	jQuery(document).ready(function($) {						
			
		/* show the table data */
		var mytable = $('#table').dataTable( {
				"bStateSave": true,
				"sPaginationType": "full_numbers",
	
				"oLanguage": {	"sSearch": "<strong><?php 
        _e('Live Search Filter', 'event_espresso');
        ?>
:</strong>",
								"sZeroRecords": "<?php 
        _e('No Records Found!', 'event_espresso');
        ?>
" },
				"aoColumns": [
								{ "bSortable": false },
								 null,
								 null,
								 null,
								 null,
								 null,
								 null,
								 { "bSortable": false },
								<?php 
        echo $ticketing_installed == true ? '{ "bSortable": false }' : '';
        ?>
							]
	
		} );
		
	} );
	</script>	
	<?php 
    }
Exemplo n.º 6
0
function edit_attendee_record()
{
    do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, '');
    global $wpdb, $org_options;
    $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>';
    $attendee_num = 1;
    $is_additional_attendee = FALSE;
    // **************************************************************************
    // **************************** EDIT ATTENDEE  ****************************
    // **************************************************************************
    if ($_REQUEST['form_action'] == 'edit_attendee') {
        $id = isset($_REQUEST['id']) ? absint($_REQUEST['id']) : '';
        $registration_id = isset($_REQUEST['registration_id']) ? sanitize_text_field($_REQUEST['registration_id']) : '';
        $multi_reg = FALSE;
        // check for multi reg, additional attendees, and verify reg id for primary attendee
        $SQL = "SELECT * FROM " . EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE . " WHERE registration_id = %s";
        $check = $wpdb->get_row($wpdb->prepare($SQL, $registration_id));
        if ($check) {
            $registration_id = $check->primary_registration_id;
            $SQL = "SELECT distinct primary_registration_id, registration_id ";
            $SQL .= "FROM " . EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE . " ";
            $SQL .= "WHERE primary_registration_id = %s";
            $registration_ids = $wpdb->get_results($wpdb->prepare($SQL, $registration_id), ARRAY_A);
            $multi_reg = TRUE;
        }
        // find the primary attendee id so we know which form to present since the additional attendees will have a different form
        $SQL = "SELECT id FROM " . EVENTS_ATTENDEE_TABLE . " WHERE registration_id =%s AND is_primary = 1 ";
        if ($r = $wpdb->get_row($wpdb->prepare($SQL, $registration_id))) {
            $primary_attendee = !empty($r->id) ? $r->id : $id;
            $is_additional_attendee = $primary_attendee != $id ? TRUE : FALSE;
        } else {
            $primary_attendee = FALSE;
        }
        // **************************************************************************
        // **************************  UPDATE PAYMENT  **************************
        // **************************************************************************
        if (!empty($_REQUEST['attendee_payment']) && $_REQUEST['attendee_payment'] == 'update_price') {
            if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'edit_attendee_' . $registration_id . '_update_price_nonce')) {
                wp_die($failed_nonce_msg);
            }
            $upd_price = (double) number_format(abs(sanitize_text_field($_REQUEST['final_price'])), 2, '.', '');
            $upd_qty = absint($_REQUEST['quantity']);
            $set_cols_and_values = array('final_price' => $upd_price, 'quantity' => $upd_qty);
            $set_format = array('%f', '%d');
            $where_cols_and_values = array('id' => $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. Attendee ticket price details could not be updated.', 'event_espresso');
            } else {
                // now we need to gather all the ticket prices for all attendees for the entire registraion and calculate a new total cost
                $upd_total = 0;
                $SQL = "SELECT payment_status, amount_pd, final_price, quantity, is_primary FROM " . EVENTS_ATTENDEE_TABLE . " WHERE registration_id = %s";
                if ($attendee_tickets = $wpdb->get_results($wpdb->prepare($SQL, $registration_id))) {
                    // loop thru tickets
                    foreach ($attendee_tickets as $attendee_ticket) {
                        // calculate total for each attendee and add to total cost
                        $upd_total += $attendee_ticket->final_price * $attendee_ticket->quantity;
                        // grab amount paid by primary attendee
                        if ($attendee_ticket->is_primary) {
                            $amount_pd = (double) $attendee_ticket->amount_pd;
                            $payment_status = $attendee_ticket->payment_status;
                        }
                    }
                }
                // format new total_cost
                $upd_total = (double) number_format($upd_total, 2, '.', '');
                // compare new total_cost with amount_pd
                if ($upd_total == $amount_pd) {
                    $upd_payment_status = __('Completed', 'event_espresso');
                } elseif ($upd_total > $amount_pd) {
                    $upd_payment_status = __('Pending', 'event_espresso');
                } elseif ($upd_total < $amount_pd) {
                    $upd_payment_status = __('Refund', 'event_espresso');
                }
                //				echo '<h4>$amount_pd : ' . $amount_pd . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
                //				echo '<h4>$payment_status : ' . $payment_status . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
                //				echo '<h4>$upd_total : ' . $upd_total . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
                //				echo '<h4>$upd_payment_status : ' . $upd_payment_status . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
                // compare old payment status with new payment status and update if things have changed
                if ($upd_payment_status != $payment_status) {
                    // update payment status for ALL attendees for the entire registration
                    $set_cols_and_values = array('payment_status' => $upd_payment_status);
                    $set_format = array('%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 while attempting to update the payment status for attendeefrom this registration.', 'event_espresso');
                    }
                }
                // now update the primary registrant's total cost field'
                $set_cols_and_values = array('total_cost' => $upd_total);
                $set_format = array('%f');
                $where_cols_and_values = array('id' => $id, 'is_primary' => TRUE);
                $where_format = array('%d', '%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 primary attendee ticket total could not be updated.', 'event_espresso');
                }
                // let's base our success on the lack of errors
                $notifications['success'][] = empty($notifications['error']) ? __('All attendee ticket price details have been successfully updated.', 'event_espresso') : __('Some attendee ticket price details were successfully updated, but the following error(s) may have prevented others from being updated:', 'event_espresso');
            }
        }
        // **************************************************************************
        // **************************  DELETE ATTENDEE  **************************
        // **************************************************************************
        if (!empty($_REQUEST['attendee_action']) && $_REQUEST['attendee_action'] == 'delete_attendee') {
            if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'edit_attendee_' . $registration_id . '_delete_attendee_nonce')) {
                wp_die($failed_nonce_msg);
            }
            $SQL = "DELETE FROM " . EVENTS_ATTENDEE_TABLE . " WHERE id =%d";
            $del_results = $wpdb->query($wpdb->prepare($SQL, $id));
            if ($del_results === FALSE) {
                $notifications['error'][] = __('An error occured. The attendee could not be deleted.', 'event_espresso');
            } elseif ($del_results === 0) {
                $notifications['error'][] = __('The attendee record in the database could not be found and was therefore not deleted.', 'event_espresso');
            } else {
                if (defined('ESPRESSO_SEATING_CHART')) {
                    $SQL = "DELETE FROM " . EVENTS_SEATING_CHART_EVENT_SEAT_TABLE . " where attendee_id = %d";
                    if ($wpdb->query($wpdb->prepare($SQL, $id)) === FALSE) {
                        $notifications['error'][] = __('An error occured. The attendee seating chart data could not be deleted.', 'event_espresso');
                    }
                }
                // get id's for all attendees from this registration
                $SQL = "SELECT id from " . EVENTS_ATTENDEE_TABLE . " WHERE registration_id = %s";
                $attendees = $wpdb->query($wpdb->prepare($SQL, $registration_id));
                if ($attendees === FALSE) {
                    $notifications['error'][] = __('An error occured while attempting to retrieve additional attendee data from the database.', 'event_espresso');
                } else {
                    // update quantities for attendees
                    $SQL = " UPDATE " . EVENTS_ATTENDEE_TABLE . " SET quantity = IF(quantity IS NULL ,NULL,IF(quantity > 0,IF(quantity-1>0,quantity-1,1),0)) ";
                    $SQL .= "WHERE registration_id =%s";
                    if ($wpdb->update($SQL, $registration_id) === FALSE) {
                        $notifications['error'][] = __('An error occured while attempting to update additional attendee ticket quantities.', 'event_espresso');
                    }
                    event_espresso_cleanup_multi_event_registration_id_group_data();
                }
                // let's base our success on the lack of errors
                $notifications['success'][] = empty($notifications['error']) ? __('All attendee details have been successfully deleted.', 'event_espresso') : __('One or more errors may have prevented some attendee details from being successfully deleted.', 'event_espresso');
            }
            // **************************************************************************
            // **************************  UPDATE ATTENDEE  **************************
            // **************************************************************************
        } else {
            if (!empty($_REQUEST['attendee_action']) && $_REQUEST['attendee_action'] == 'update_attendee') {
                if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'edit_attendee_' . $registration_id . '_update_attendee_nonce')) {
                    wp_die($failed_nonce_msg);
                }
                $event_id = isset($_POST['event_id']) ? $_POST['event_id'] : '';
                $txn_type = isset($_POST['txn_type']) ? $_POST['txn_type'] : '';
                $set_cols_and_values = array('fname' => isset($_POST['fname']) ? $_POST['fname'] : '', 'lname' => isset($_POST['lname']) ? $_POST['lname'] : '', 'address' => isset($_POST['address']) ? $_POST['address'] : '', 'address2' => isset($_POST['address2']) ? $_POST['address2'] : '', 'city' => isset($_POST['city']) ? $_POST['city'] : '', 'state' => isset($_POST['state']) ? $_POST['state'] : '', 'zip' => isset($_POST['zip']) ? $_POST['zip'] : '', 'phone' => isset($_POST['phone']) ? $_POST['phone'] : '', 'email' => isset($_POST['email']) ? $_POST['email'] : '');
                $set_format = array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s');
                // Update the time ?
                if (isset($_POST['start_time_id'])) {
                    $SQL = "SELECT ese.start_time, ese.end_time FROM " . EVENTS_START_END_TABLE . " ese WHERE ese.id=%d";
                    if ($times = $wpdb->get_results($wpdb->prepare($SQL, absint($_POST['start_time_id'])))) {
                        foreach ($times as $time) {
                            $start_time = $time->start_time;
                            $end_time = $time->end_time;
                        }
                        $set_cols_and_values['event_time'] = $start_time;
                        $set_cols_and_values['end_time'] = $end_time;
                        array_push($set_format, '%s', '%s');
                    }
                }
                //printr( $_POST, '$_POST  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
                $where_cols_and_values = array('id' => $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. Attendee details could not be updated.', 'event_espresso');
                }
                // Added for seating chart addon
                $booking_id = 0;
                if (defined('ESPRESSO_SEATING_CHART')) {
                    if (seating_chart::check_event_has_seating_chart($event_id) !== false) {
                        if (isset($_POST['seat_id'])) {
                            $booking_id = seating_chart::parse_booking_info($_POST['seat_id']);
                            if ($booking_id > 0) {
                                seating_chart::confirm_a_seat($booking_id, $id);
                            }
                        }
                    }
                }
                // Insert Additional Questions From Post Here
                $reg_id = $id;
                $SQL = "SELECT question_groups, event_meta FROM " . EVENTS_DETAIL_TABLE . " WHERE id = %d";
                $questions = $wpdb->get_row($wpdb->prepare($SQL, $event_id));
                $question_groups = unserialize($questions->question_groups);
                $event_meta = unserialize($questions->event_meta);
                if ($is_additional_attendee && isset($event_meta['add_attendee_question_groups']) && $event_meta['add_attendee_question_groups'] != NULL) {
                    $question_groups = $event_meta['add_attendee_question_groups'];
                }
                $questions_in = '';
                foreach ($question_groups as $g_id) {
                    $questions_in .= $g_id . ',';
                }
                $questions_in = substr($questions_in, 0, -1);
                $group_name = '';
                $counter = 0;
                //pull the list of questions that are relevant to this event
                $SQL = "SELECT q.*, q.id AS q_id, at.id AS a_id, at.*, qg.group_name, qg.show_group_description, qg.show_group_name ";
                $SQL .= "FROM " . EVENTS_QUESTION_TABLE . " q ";
                $SQL .= "LEFT JOIN " . EVENTS_ANSWER_TABLE . " at on q.id = at.question_id ";
                $SQL .= "JOIN " . EVENTS_QST_GROUP_REL_TABLE . " qgr on q.id = qgr.question_id ";
                $SQL .= "JOIN " . EVENTS_QST_GROUP_TABLE . " qg on qg.id = qgr.group_id ";
                $SQL .= "WHERE qgr.group_id in ( {$questions_in} ) ";
                $SQL .= "AND (at.attendee_id IS NULL OR at.attendee_id = '%d') ";
                $SQL .= "ORDER BY qg.id, q.id ASC";
                $questions = $wpdb->get_results($wpdb->prepare($SQL, $id));
                //			printr( $questions, '$questions  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
                $SQL = "SELECT id, question_id, answer FROM " . EVENTS_ANSWER_TABLE . " at WHERE at.attendee_id = %d";
                $answers = $wpdb->get_results($wpdb->prepare($SQL, $id), OBJECT_K);
                foreach ($answers as $answer) {
                    $answer_a[$answer->id] = $answer->question_id;
                }
                if ($questions) {
                    foreach ($questions as $question) {
                        //printr( $question, '$question  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
                        switch ($question->question_type) {
                            case "TEXT":
                            case "TEXTAREA":
                            case "SINGLE":
                            case "DROPDOWN":
                                if ($question->system_name != '') {
                                    $post_val = isset($_POST[$question->system_name]) ? $_POST[$question->system_name] : '';
                                } else {
                                    $post_val = isset($_POST[$question->question_type . '_' . $question->a_id]) ? $_POST[$question->question_type . '_' . $question->a_id] : '';
                                }
                                $post_val = sanitize_text_field(stripslashes($post_val));
                                break;
                            case "MULTIPLE":
                                $post_val = '';
                                for ($i = 0; $i < count($_POST[$question->question_type . '_' . $question->a_id]); $i++) {
                                    $post_val .= trim($_POST[$question->question_type . '_' . $question->a_id][$i]) . ",";
                                }
                                $post_val = sanitize_text_field(substr(stripslashes($post_val), 0, -1));
                                break;
                        }
                        //					echo '<h4>$post_val : ' . $post_val . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
                        //					echo '<h4>$question->id : ' . $question->q_id . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
                        //					printr( $answer_a, '$answer_a  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
                        if (in_array($question->q_id, $answer_a)) {
                            // existing answer
                            $set_cols_and_values = array('answer' => html_entity_decode(trim($post_val), ENT_QUOTES, 'UTF-8'));
                            //echo "<pre>".print_r($set_cols_and_values,true)."</pre>";
                            $set_format = array('%s');
                            $where_cols_and_values = array('attendee_id' => $id, 'question_id' => $question->q_id);
                            $where_format = array('%d', '%d');
                            // run the update
                            $upd_success = $wpdb->update(EVENTS_ANSWER_TABLE, $set_cols_and_values, $where_cols_and_values, $set_format, $where_format);
                            //echo '<h4>last_query : ' . $wpdb->last_query . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
                        } else {
                            // new answer
                            $set_cols_and_values = array('registration_id' => $registration_id, 'attendee_id' => $id, 'question_id' => $question->q_id, 'answer' => html_entity_decode(trim($post_val), ENT_QUOTES, 'UTF-8'));
                            $set_format = array('%s', '%d', '%d', '%s');
                            // run the insert
                            $upd_success = $wpdb->insert(EVENTS_ANSWER_TABLE, $set_cols_and_values, $set_format);
                            //echo '<h4>last_query : ' . $wpdb->last_query . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
                        }
                    }
                }
                // let's base our success on the lack of errors
                $notifications['success'][] = empty($notifications['error']) ? __('All attendee details have been successfully updated.', 'event_espresso') : __('One or more errors may have prevented some attendee details from being successfully updated.', 'event_espresso');
            }
        }
        // **************************************************************************
        // *************************  RETRIEVE ATTENDEE  *************************
        // **************************************************************************
        $counter = 0;
        $additional_attendees = NULL;
        $SQL = "SELECT att.*, evt.event_name, evt.question_groups, evt.event_meta, evt.additional_limit FROM " . EVENTS_ATTENDEE_TABLE . " att ";
        $SQL .= "JOIN " . EVENTS_DETAIL_TABLE . " evt ON att.event_id = evt.id ";
        // are we looking for an additional attendee ?
        if (isset($_REQUEST['attendee_num']) && $_REQUEST['attendee_num'] > 1 && isset($_REQUEST['id'])) {
            $SQL .= "WHERE  att.id = " . sanitize_text_field($_REQUEST['id']);
        } else {
            // check for multi reg & additional attendees by first finding primary attendee
            $SQL2 = "SELECT primary_registration_id FROM " . EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE . " WHERE registration_id = %s";
            if ($primary_registration_id = $wpdb->get_var($wpdb->prepare($SQL2, sanitize_text_field($_REQUEST['registration_id'])))) {
                // now find all registrations
                $SQL3 = "SELECT registration_id FROM " . EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE . " WHERE primary_registration_id = %s";
                $reg_ids = $wpdb->get_col($wpdb->prepare($SQL3, $primary_registration_id));
                $reg_ids = "'" . implode("','", $reg_ids) . "'";
            } else {
                $reg_ids = "'" . sanitize_text_field($_REQUEST['registration_id']) . "'";
            }
            $SQL .= " WHERE registration_id IN ( {$reg_ids} ) ORDER BY att.id";
        }
        $attendees = $wpdb->get_results($wpdb->prepare($SQL, NULL));
        foreach ($attendees as $attendee) {
            if ($counter == 0) {
                $id = $attendee->id;
                $registration_id = $attendee->registration_id;
                $lname = $attendee->lname;
                $fname = $attendee->fname;
                $address = $attendee->address;
                $address2 = $attendee->address2;
                $city = $attendee->city;
                $state = $attendee->state;
                $zip = $attendee->zip;
                $email = $attendee->email;
                $payment = $attendee->payment;
                $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;
                $event_name = $attendee->event_name;
                $question_groups = unserialize($attendee->question_groups);
                $event_meta = unserialize($attendee->event_meta);
                $coupon_code = $attendee->coupon_code;
                $is_additional_attendee = $primary_attendee != $id ? true : false;
                $attendee_limit = $attendee->additional_limit;
                $amount_pd = $attendee->amount_pd;
                $total_cost = $attendee->total_cost;
                $orig_price = $attendee->orig_price;
                $final_price = $attendee->final_price;
                $start_date = $attendee->start_date;
                $event_time = $attendee->event_time;
                // Added for seating chart addon
                $booking_info = "";
                if (defined('ESPRESSO_SEATING_CHART')) {
                    $seating_chart_id = seating_chart::check_event_has_seating_chart($event_id);
                    if ($seating_chart_id !== false) {
                        $seat = $wpdb->get_row("select scs.* , sces.id as booking_id from " . EVENTS_SEATING_CHART_SEAT_TABLE . " scs inner join " . EVENTS_SEATING_CHART_EVENT_SEAT_TABLE . " sces on scs.id = sces.seat_id where sces.attendee_id = '" . $id . "' ");
                        if ($seat !== NULL) {
                            $booking_info = $seat->custom_tag . " #booking id: " . $seat->booking_id;
                        }
                    }
                }
                $event_date = event_date_display($start_date . ' ' . $event_time, get_option('date_format') . ' g:i a');
                if ($is_additional_attendee && isset($event_meta['add_attendee_question_groups']) && $event_meta['add_attendee_question_groups'] != NULL) {
                    $question_groups = $event_meta['add_attendee_question_groups'];
                }
                $counter++;
            } else {
                $additional_attendees[$attendee->id] = array('full_name' => $attendee->fname . ' ' . $attendee->lname, 'email' => $attendee->email, 'phone' => $attendee->phone);
            }
        }
        // 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>&laquo;&nbsp;<?php 
        _e('Back to Attendees List', 'event_espresso');
        ?>
</strong>
		</a>
	</p>
</div>

<div class="metabox-holder">
	<div class="postbox">
		<h3>
			<?php 
        _e('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">#' . $registration_id . '</a> | ID #' . $id . ' | Name: ' . $fname . ' ' . $lname . ' | 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>
		<div class="inside">
			<table width="100%">
				<tr>
					<td width="50%" valign="top">
						<form method="post" action="<?php 
        echo $_SERVER['REQUEST_URI'];
        ?>
" class="espresso_form">
							<h4 class="qrtr-margin">
								<?php 
        _e('Registration Information', 'event_espresso');
        ?>
								<?php 
        echo $is_additional_attendee == false ? '[ <span class="green_text">' . __('Primary Attendee Record', 'event_espresso') . '</span> ]' : '[ <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 Primary Attendee</a> ]';
        ?>
							</h4>
							<fieldset>
								<ul>
									<li>
										<?php 
        $time_id = 0;
        $SQL = "SELECT id FROM " . EVENTS_START_END_TABLE . " WHERE event_id=%d AND start_time =%s";
        if ($event_time = $wpdb->get_row($wpdb->prepare($SQL, $event_id, $event_time))) {
            $time_id = $event_time->id;
        }
        echo event_espresso_time_dropdown($event_id, $label = 1, $multi_reg = 0, $time_id);
        ?>
									</li>
									<li>
										<?php 
        //Added for seating chart addon.  Creates a field to select a seat from a popup.
        do_action('ee_seating_chart_css');
        do_action('ee_seating_chart_js');
        do_action('ee_seating_chart_flush_expired_seats');
        do_action('espresso_seating_chart_select', $event_id, $booking_info);
        ?>
									</li>
									<li>
										<?php 
        if (count($question_groups) > 0) {
            $questions_in = '';
            foreach ($question_groups as $g_id) {
                $questions_in .= $g_id . ',';
            }
            $questions_in = substr($questions_in, 0, -1);
            $group_name = '';
            $counter = 0;
            $FILTER = '';
            if (isset($event_meta['additional_attendee_reg_info']) && $event_meta['additional_attendee_reg_info'] == '2' && isset($_REQUEST['attendee_num']) && $_REQUEST['attendee_num'] > 1) {
                $FILTER .= " AND qg.system_group = 1 ";
            }
            //pull the list of questions that are relevant to this event
            $SQL = "SELECT q.*, at.*, qg.group_name, qg.show_group_description, qg.show_group_name ";
            $SQL .= "FROM " . EVENTS_QUESTION_TABLE . " q ";
            $SQL .= "LEFT JOIN " . EVENTS_ANSWER_TABLE . " at on q.id = at.question_id ";
            $SQL .= "JOIN " . EVENTS_QST_GROUP_REL_TABLE . " qgr on q.id = qgr.question_id ";
            $SQL .= "JOIN " . EVENTS_QST_GROUP_TABLE . " qg on qg.id = qgr.group_id ";
            $SQL .= "WHERE qgr.group_id in ( {$questions_in} ) ";
            $SQL .= "AND ( at.attendee_id IS NULL OR at.attendee_id = %d ) ";
            $SQL .= $FILTER . " ";
            $SQL .= "ORDER BY qg.id, q.id ASC";
            $questions = $wpdb->get_results($wpdb->prepare($SQL, $id));
            $num_rows = $wpdb->num_rows;
            if ($num_rows > 0) {
                //Output the questions
                $question_displayed = array();
                foreach ($questions as $question) {
                    $counter++;
                    if (!in_array($question->id, $question_displayed)) {
                        $question_displayed[] = $question->id;
                        //echo '<p>';
                        echo event_form_build_edit($question, $question->answer, $show_admin_only = true);
                        //echo "</p>";
                        #echo $counter == $num_rows ? '</fieldset>' : '';
                    }
                }
            }
            //end questions display
        }
        ?>
									</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="event_id" value="<?php 
        echo $event_id;
        ?>
" />
									<input type="hidden" name="display_action" value="view_list" />
									<input type="hidden" name="form_action" value="edit_attendee" />
									<input type="hidden" name="attendee_action" value="update_attendee" />
									<?php 
        wp_nonce_field('edit_attendee_' . $registration_id . '_update_attendee_nonce');
        ?>
									<li>
										<input type="submit" name="Submit" class="button-primary action"  value="<?php 
        _e('Update Record', 'event_espresso');
        ?>
" />
									</li>
								</ul>
							</fieldset>
						</form></td>
					<td  width="50%" valign="top">
						<?php 
        if (count($additional_attendees) > 0) {
            ?>
 
						<h4>
							<?php 
            _e('Additional Attendees', 'event_espresso');
            ?>
						</h4>
						<ol>
							<?php 
            foreach ($additional_attendees as $att => $row) {
                $attendee_num++;
                ?>
							<li>
								<?php 
                // create edit link
                $edit_att_url_params = array('event_admin_reports' => 'edit_attendee_record', 'form_action' => 'edit_attendee', 'registration_id' => $registration_id, 'id' => $att, 'attendee_num' => $attendee_num, 'event_id' => $event_id);
                // add url params
                $edit_attendee_link = add_query_arg($edit_att_url_params, 'admin.php?page=events');
                ?>
								
								<a href="<?php 
                echo $edit_attendee_link;
                ?>
" title="<?php 
                _e('Edit Attendee', 'event_espresso');
                ?>
">
									<strong><?php 
                echo $row['full_name'];
                ?>
</strong> (<?php 
                echo $row['email'];
                ?>
)
								</a>
								&nbsp;&nbsp;|&nbsp;&nbsp;
								<?php 
                // create delete link
                $delete_att_url_params = array('event_admin_reports' => 'edit_attendee_record', 'form_action' => 'edit_attendee', 'attendee_action' => 'delete_attendee', 'registration_id' => $registration_id, 'id' => $att, 'attendee_num' => $attendee_num, 'event_id' => $event_id);
                // add url params
                $delete_attendee_link = add_query_arg($delete_att_url_params, 'admin.php?page=events');
                // add nonce
                $edit_attendee_link = wp_nonce_url($delete_attendee_link, 'edit_attendee_' . $registration_id . '_delete_attendee_nonce');
                ?>
								
								<a href="<?php 
                echo $delete_attendee_link;
                ?>
" title="<?php 
                _e('Delete Attendee', 'event_espresso');
                ?>
" onclick="return confirmDelete();">
									<?php 
                _e('Delete', 'event_espresso');
                ?>
								</a>
							</li>
							<?php 
            }
            ?>
						</ol>
						<?php 
        }
        ?>
						
						
						<br/>
						<h4 class="qrtr-margin"><?php 
        _e('Ticket Prices', 'event_espresso');
        ?>
</h4>
						
						<form method="POST" action="<?php 
        echo $_SERVER['REQUEST_URI'];
        ?>
&status=saved" class="espresso_form">
							<fieldset>
								<ul>
									<li>
											<strong class="att-tckt-prc-lbl"><?php 
        _e('Payment Status:', 'event_espresso');
        ?>
</strong> 
											<?php 
        echo $payment_status;
        ?>
 <?php 
        echo event_espresso_paid_status_icon($payment_status);
        ?>
&nbsp;&nbsp;[&nbsp;<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');
        ?>
">
											<?php 
        _e('View/Edit Payment', 'event_espresso');
        ?>
											</a>&nbsp;]
									</li>
									<li>
											<strong class="att-tckt-prc-lbl"><?php 
        _e('Transaction ID:', 'event_espresso');
        ?>
</strong> 
											<?php 
        echo !empty($txn_id) ? $txn_id : 'N/A';
        ?>
									</li>
									<li>
											<strong class="att-tckt-prc-lbl"><?php 
        _e('Date Paid:', 'event_espresso');
        ?>
</strong> 
											<?php 
        echo !empty($payment_date) ? event_date_display($payment_date) : 'N/A';
        ?>
									</li>
									<li>
											<strong class="att-tckt-prc-lbl">
											<?php 
        _e('Total Amount Owing:', 'event_espresso');
        ?>
											</strong>
											<?php 
        echo $org_options['currency_symbol'];
        echo $total_cost;
        ?>
									</li>
									<li>
											<strong class="att-tckt-prc-lbl"><?php 
        _e('Total Amount Paid to Date:', 'event_espresso');
        ?>
</strong> 
											<?php 
        echo $org_options['currency_symbol'] . $amount_pd;
        //echo espresso_attendee_price(array('attendee_id' => $id, 'reg_total' => true));
        ?>
									</li>
									<li>
										<h6 class="qrtr-margin"><strong><?php 
        _e('Attendee Ticket Fees:', 'event_espresso');
        ?>
</strong></h6>
										<div  <?php 
        if (isset($_REQUEST['show_payment']) && $_REQUEST['show_payment'] == 'true') {
            echo ' class="yellow_inform"';
        }
        ?>
>
											<table  border="0">
												<tr>
													<td  align="left" valign="top">
														<label><?php 
        _e('Amount:', 'event_espresso');
        ?>
 ( <?php 
        echo $org_options['currency_symbol'];
        ?>
 )</label>
													</td>
													<td  align="center" valign="top">
														<label><?php 
        _e('# Tickets:', 'event_espresso');
        ?>
</label>
													</td>
													<td  align="right" valign="top">
														<label class="algn-rght"><?php 
        _e('Total:', 'event_espresso');
        ?>
</label>
													</td>
												</tr>
												<tr>
													<td align="left" valign="top">
														<input name="final_price" class="small-text algn-rght" type="text" value ="<?php 
        echo $final_price;
        ?>
" />
													</td>
													<td align="center" valign="top">
														<?php 
        // number of tickets currently purchased
        $quantity = !empty($quantity) ? $quantity : 1;
        // availalbe spaces left for event
        $available_spaces = get_number_of_attendees_reg_limit($event_id, 'number_available_spaces');
        if ($available_spaces != 'Unlimited') {
            // first add our purchased tickets ($quantity) back into available spaces
            // ( becuase a sold out show incluldes these tickets here, so admin should be allowed to play with these numbers - think about it )
            $available_spaces += $quantity;
            $attendee_limit = $attendee_limit <= $available_spaces ? $attendee_limit : $available_spaces;
        }
        // final check to make sure that attendee limit has to at LEAST be the number of tickets this attendee has already purchased
        // otherwise the ticket quantity selector may display less than what this attendee has already purchased
        $attendee_limit = $attendee_limit < $quantity ? $quantity : $attendee_limit;
        ?>
														<select name="quantity" class="price_id">
														<?php 
        for ($i = 0; $i <= $attendee_limit; $i++) {
            $selected = $i == $quantity ? ' selected="selected" ' : '';
            ?>
															<option <?php 
            echo $selected;
            ?>
 value="<?php 
            echo $i;
            ?>
"><?php 
            echo $i;
            ?>
</option>
														<?php 
        }
        ?>
														</select>
														<!--<input name="quantity" type="text" value ="<?php 
        echo !empty($quantity) ? $quantity : 1;
        ?>
"  />-->
													</td>
													<td  align="right" valign="top">
														<?php 
        $ticket_total = (double) ($final_price * $quantity) > 0 ? number_format($final_price * $quantity, 2, '.', '') : 0.0;
        ?>
														<input class="small-text algn-rght" type="text" name="total_owing" disabled="true" value ="<?php 
        echo $ticket_total;
        ?>
" />
													</td>
												</tr>
											</table>
										</div>
									</li>
									<li>
											<strong class="att-tckt-prc-lbl"><?php 
        _e('Original Ticket Price:', 'event_espresso');
        ?>
</strong> 
											<?php 
        echo $org_options['currency_symbol'] . '&nbsp;' . $orig_price;
        ?>
&nbsp;&nbsp;/&nbsp;&nbsp;<?php 
        _e('ticket', 'event_espresso');
        ?>
								
									</li>
									<li>
										<br/>
										<input type="submit" name="submit_ticket_prices" class="button-primary action"  value="Update Price" />
									</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="edit_attendee" />
							<input type="hidden" name="event_id" value="<?php 
        echo $event_id;
        ?>
" />
							<input type="hidden" name="attendee_payment" value="update_price" />
							<?php 
        wp_nonce_field('edit_attendee_' . $registration_id . '_update_price_nonce');
        ?>
						</form>
					</td>
				</tr>
			</table>
		</div>
	</div>
</div>
<?php 
    }
}
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 
}