function enter_attendee_payments()
{
    global $wpdb, $org_options;
    require_once EVENT_ESPRESSO_PLUGINFULLPATH . "includes/functions/attendee_functions.php";
    $notifications['success'] = array();
    $notifications['error'] = array();
    $failed_nonce_msg = '
<div id="message" class="error">
	<p>
		<strong>' . __('An Error Occurred. The request failed to pass a security check.', 'event_espresso') . '</strong><br/>
		<span style="font-size:.9em;">' . __('Please press the back button on your browser to return to the previous page.', 'event_espresso') . '</span>
	</p>
</div>';
    $multi_reg = FALSE;
    $event_id = isset($_POST['event_id']) ? absint($_POST['event_id']) : isset($_REQUEST['event_id']) ? absint($_REQUEST['event_id']) : '';
    $registration_id = isset($_POST['registration_id']) ? sanitize_text_field($_POST['registration_id']) : isset($_REQUEST['registration_id']) ? sanitize_text_field($_REQUEST['registration_id']) : FALSE;
    $registration_ids = array();
    //echo '<h4>$registration_id : ' . $registration_id . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
    $SQL = "SELECT * FROM " . EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE . " WHERE registration_id =%s LIMIT 1";
    if ($check = $wpdb->get_row($wpdb->prepare($SQL, $registration_id))) {
        //printr( $check, '$check  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
        $registration_id = $check->primary_registration_id;
        $SQL = "SELECT * FROM " . EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE . " WHERE primary_registration_id =%s";
        $registration_ids = $wpdb->get_results($wpdb->prepare($SQL, $registration_id), ARRAY_A);
        $registration_ids = $registration_ids !== FALSE ? $registration_ids : array();
        $multi_reg = TRUE;
    }
    //echo '<h4>$registration_id : ' . $registration_id . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
    //printr( $registration_ids, '$registration_ids  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
    switch ($_REQUEST['form_action']) {
        //Add payment info
        case 'payment':
            if (isset($_POST['attendee_action']) && $_POST['attendee_action'] == 'post_payment') {
                if (!wp_verify_nonce($_POST['_wpnonce'], 'payment_' . $registration_id . '_post_payment_nonce')) {
                    wp_die($failed_nonce_msg);
                }
                $attendees_to_email = array();
                // get the primary attendee id because amount paid info is kept with the primary attendee
                $SQL = "SELECT id, payment_status FROM " . EVENTS_ATTENDEE_TABLE . " WHERE registration_id =%s AND is_primary = 1 ORDER BY id LIMIT 0,1 ";
                $primary_att = $wpdb->get_row($wpdb->prepare($SQL, $registration_id));
                if (!$primary_att) {
                    $notifications['error'][] = __('An error occured. The primary attendee details could not be retrieved from the database.', 'event_espresso');
                } else {
                    $txn_type = isset($_POST['txn_type']) ? $_POST['txn_type'] : apply_filters('filter_hook_event_espresso_enter_attendee_payments_remove_require_txn_type', FALSE);
                    $txn_id = isset($_POST['txn_id']) ? $_POST['txn_id'] : apply_filters('filter_hook_event_espresso_enter_attendee_payments_remove_require_txn_id', FALSE);
                    $payment_date = isset($_POST['payment_date']) ? date_i18n(get_option('date_format'), strtotime($_POST['payment_date'])) : FALSE;
                    $coupon_code = isset($_POST['coupon_code']) ? $_POST['coupon_code'] : '';
                    $total_owing = isset($_POST['total_owing']) ? (double) number_format(sanitize_text_field($_POST['total_owing']), 2, '.', '') : 0.0;
                    $amount_pd = isset($_POST['amount_pd']) ? (double) number_format(sanitize_text_field($_POST['amount_pd']), 2, '.', '') : 0.0;
                    $new_payment = isset($_POST['new_payment']) && $_POST['new_payment'] != '' ? (double) number_format(sanitize_text_field($_POST['new_payment']), 2, '.', '') : 0.0;
                    $upd_payment_status = isset($_POST['payment_status']) ? $_POST['payment_status'] : 'Pending';
                    // if making a payment, we are going to require the txn type and txn id
                    if ($new_payment != 0.0) {
                        $fail = FALSE;
                        if (!$txn_type) {
                            $notifications['error'][] = __('You must enter a Transaction Type when making a payment.', 'event_espresso');
                            $fail = TRUE;
                        }
                        if (!$txn_id) {
                            $notifications['error'][] = __('You must enter a Transaction ID when making a payment.', 'event_espresso');
                            $fail = TRUE;
                        }
                        if ($fail) {
                            break;
                        }
                        $upd_total = $amount_pd + $new_payment;
                    } else {
                        $upd_total = $amount_pd;
                    }
                    // compare new total_cost with amount_pd
                    if ($new_payment != 'Cancelled') {
                        if ($new_payment == $total_owing) {
                            $upd_payment_status = 'Completed';
                        } elseif ($new_payment < $total_owing) {
                            $upd_payment_status = isset($_POST['payment_status']) && $_POST['payment_status'] == 'Incomplete' ? 'Incomplete' : 'Pending';
                        } elseif ($new_payment > $total_owing) {
                            $upd_payment_status = 'Refund';
                        }
                    }
                    //Update payment status information for primary attendee
                    $set_cols_and_values = array('payment_status' => $upd_payment_status, 'txn_type' => $txn_type, 'txn_id' => $txn_id, 'payment_date' => $payment_date, 'coupon_code' => $coupon_code, 'amount_pd' => $upd_total);
                    $set_format = array('%s', '%s', '%s', '%s', '%s', '%f');
                    $where_cols_and_values = array('id' => $primary_att->id);
                    $where_format = array('%d');
                    // run the update
                    $upd_success = $wpdb->update(EVENTS_ATTENDEE_TABLE, $set_cols_and_values, $where_cols_and_values, $set_format, $where_format);
                    // if there was an actual error
                    if ($upd_success === FALSE) {
                        $notifications['error'][] = __('An error occured. The attendee payment details could not be updated.', 'event_espresso');
                    } else {
                        $attendee_data = array('attendee_id' => $primary_att->id, 'payment_status' => $upd_payment_status, 'registration_id' => $registration_id, 'total_cost' => $upd_total, 'txn_type' => __('Manual Website Payment', 'event_espresso'), 'txn_id' => $txn_id);
                        do_action('action_hook_espresso_update_attendee_payment_status', $attendee_data);
                        if (count($registration_ids) > 0) {
                            foreach ($registration_ids as $reg_id) {
                                // Update payment status information for all attendees
                                // remove amount_pd from update data, since that only applies to the primary attendee
                                unset($set_cols_and_values['amount_pd']);
                                $set_format = array('%s', '%s', '%s', '%s', '%s');
                                $where_cols_and_values = array('registration_id' => $reg_id['registration_id']);
                                $where_format = array('%s');
                                // run the update
                                $upd_success = $wpdb->update(EVENTS_ATTENDEE_TABLE, $set_cols_and_values, $where_cols_and_values, $set_format, $where_format);
                                // if there was an actual error
                                if ($upd_success === FALSE) {
                                    $notifications['error'][] = __('An error occured. The payment details for the additional attendees could not be updated.', 'event_espresso');
                                }
                                $attendees_to_email[] = array('registration_id' => $reg_id['registration_id']);
                            }
                        } else {
                            // Update payment status information for all attendees
                            // remove amount_pd from update data, since that only applies to the primary attendee
                            unset($set_cols_and_values['amount_pd']);
                            $set_format = array('%s', '%s', '%s', '%s', '%s');
                            $where_cols_and_values = array('registration_id' => $registration_id);
                            $where_format = array('%s');
                            // run the update
                            $upd_success = $wpdb->update(EVENTS_ATTENDEE_TABLE, $set_cols_and_values, $where_cols_and_values, $set_format, $where_format);
                            // if there was an actual error
                            if ($upd_success === FALSE) {
                                $notifications['error'][] = __('An error occured. The payment details for the additional attendees could not be updated.', 'event_espresso');
                            }
                        }
                        //Send Payment Recieved Email
                        $send_payment_rec = isset($_POST['send_payment_rec']) ? $_POST['send_payment_rec'] : FALSE;
                        if ($send_payment_rec == "send_message") {
                            //event_espresso_send_payment_notification( $id );
                            if (count($attendees_to_email) > 0) {
                                //printr( $attendees_to_email, '$attendees_to_email  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); wp_die();
                                foreach ($attendees_to_email as $attendee_to_email) {
                                    $result = event_espresso_send_payment_notification($attendee_to_email);
                                    if (!empty($result)) {
                                        $notifications['error'][] = $result;
                                    }
                                }
                            } else {
                                $result = event_espresso_send_payment_notification(array('registration_id' => $registration_id));
                                if (!empty($result)) {
                                    $notifications['error'][] = $result;
                                }
                            }
                        }
                    }
                    // let's base our success on the lack of errors
                    $notifications['success'][] = empty($notifications['error']) ? __('All attendee payment details have been successfully updated.', 'event_espresso') : __('Some attendee payment details were successfully updated, but the following error(s) may have prevented others from being updated:', 'event_espresso');
                }
            }
            break;
            //Send Invoice
        //Send Invoice
        case 'send_invoice':
            if (!wp_verify_nonce($_POST['_wpnonce'], 'send_invoice_' . $registration_id . '_nonce')) {
                wp_die($failed_nonce_msg);
            }
            if ($org_options["use_attendee_pre_approval"] == "Y") {
                $pre_approve = $_POST['pre_approve'];
                if (count($registration_ids) > 0) {
                    foreach ($registration_ids as $reg_id) {
                        $SQL = "UPDATE " . EVENTS_ATTENDEE_TABLE . " SET pre_approve = %s WHERE registration_id = %s";
                        $wpdb->query($wpdb->prepare($SQL, $pre_approve, $reg_id['registration_id']));
                    }
                } else {
                    $SQL = "UPDATE " . EVENTS_ATTENDEE_TABLE . " SET pre_approve = %s WHERE registration_id = %s";
                    $wpdb->query($wpdb->prepare($SQL, $pre_approve, $registration_id));
                }
            } else {
                $pre_approve = 0;
            }
            if ($pre_approve == "0") {
                if (count($registration_ids) > 0) {
                    $reg_attendees = array();
                    foreach ($registration_ids as $reg_id) {
                        $SQL = 'SELECT * FROM ' . EVENTS_ATTENDEE_TABLE . ' WHERE registration_id =%s';
                        $more_reg_attendees = $wpdb->get_results($wpdb->prepare($SQL, $reg_id['registration_id']), 'OBJECT_K');
                        foreach ($more_reg_attendees as $another_reg_attendee) {
                            $reg_attendees[$another_reg_attendee->email] = $another_reg_attendee;
                        }
                    }
                    foreach ($reg_attendees as $reg_attendee) {
                        event_espresso_send_invoice($reg_attendee->registration_id, $_POST['invoice_subject'], $_POST['invoice_message']);
                    }
                } else {
                    event_espresso_send_invoice($registration_id, $_POST['invoice_subject'], $_POST['invoice_message']);
                }
                $notifications['success'][] = __('Invoice Sent.', 'event_espresso');
            }
            break;
    }
    $SQL = "SELECT * FROM " . EVENTS_ATTENDEE_TABLE . " WHERE registration_id ='%s' ORDER BY id LIMIT 1";
    $attendee = $wpdb->get_row($wpdb->prepare($SQL, $registration_id));
    if ($attendee === FALSE) {
        echo '<div id="message" class="error"><p><strong>' . __('An error occured. The requested attendee data could not be found.', 'event_espresso') . '</strong></p></div>';
        exit;
    }
    $id = $attendee->id;
    $lname = $attendee->lname;
    $fname = $attendee->fname;
    $address = $attendee->address;
    $city = $attendee->city;
    $state = $attendee->state;
    $zip = $attendee->zip;
    $email = $attendee->email;
    $phone = $attendee->phone;
    $date = $attendee->date;
    $payment_status = $attendee->payment_status;
    $txn_type = $attendee->txn_type;
    $txn_id = $attendee->txn_id;
    $quantity = $attendee->quantity;
    $payment_date = $attendee->payment_date;
    $event_id = $attendee->event_id;
    $coupon_code = $attendee->coupon_code;
    $pre_approve = $attendee->pre_approve;
    $start_date = $attendee->start_date;
    $event_time = $attendee->event_time;
    $amount_pd = $attendee->amount_pd;
    $total_cost = $attendee->total_cost;
    $orig_price = $attendee->orig_price;
    $final_price = $attendee->final_price;
    $SQL = "SELECT * FROM " . EVENTS_DETAIL_TABLE . " WHERE id='%d'";
    $event = $wpdb->get_row($wpdb->prepare($SQL, $event_id));
    if ($event === FALSE) {
        echo '<div id="message" class="error"><p><strong>' . __('An error occured. The event data for this registration could not be found.', 'event_espresso') . '</strong></p></div>';
        exit;
    }
    $event_id = $event->id;
    $event_name = $event->event_name;
    $event_desc = $event->event_desc;
    $event_description = $event->event_desc;
    $event_identifier = $event->event_identifier;
    $cost = isset($event->event_cost) ? $event->event_cost : 0;
    $active = $event->is_active;
    $event_date = event_date_display($start_date . ' ' . $event_time, get_option('date_format') . ' g:i a');
    //	$total_paid = espresso_attendee_price(array('registration_id'=>$_REQUEST['registration_id'], 'session_total'=>true));
    // display success messages
    if (!empty($notifications['success'])) {
        $success_msg = implode($notifications['success'], '<br />');
        ?>
			
<div id="message" class="updated fade">
<p>
	<strong><?php 
        echo $success_msg;
        ?>
</strong>
</p>
</div>

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

	<?php 
    }
    ?>

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

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

		</div>
	</div>
</div>
<?php 
    //This show what tags can be added to a custom email.
    event_espresso_custom_email_info();
    //event_list_attendees();
}
function event_process_payments()
{
    $org_options = get_option('events_organization_settings');
    global $wpdb;
    if ($_POST['perm_delete_event']) {
        if (is_array($_POST['checkbox'])) {
            while (list($key, $value) = each($_POST['checkbox'])) {
                $del_id = $key;
                event_espresso_empty_event_trash($del_id);
                //$sql = "DELETE FROM " . EVENTS_ATTENDEE_TABLE . " WHERE registration_id = '$del_id'";
                //$wpdb->query( $sql );
            }
        }
        ?>

        <div id="message" class="updated fade">
          <p><strong>
            <?php 
        _e('Event(s) have been permanently deleted.', 'event_espresso');
        ?>
            </strong></p>
        </div>
<?php 
    }
    ?>
	<h3><?php 
    _e('Select an event to view attendee details and payments', 'event_espresso');
    ?>
</h3>
 
 <div style="float:right; margin:10px 20px;">
  <ul>
    <li><button style="margin-left:20px" class="button-primary" onclick="window.location='<?php 
    echo get_bloginfo('wpurl') . "/wp-admin/admin.php?event_espresso&id=" . $event_id . "&export=report&action=payment&all_events=true";
    ?>
'" >
      <?php 
    _e('Export All Event Attendees to Excel', 'event_espresso');
    ?>
      </button>
      </li>
      </ul>
      </div>
   	<div id="tablewrapper">
		<div id="tableheader">
        	<div class="search">
                <select id="columns" onchange="sorter.search('query')"></select>
                <input type="text" id="query" onkeyup="sorter.search('query')" />
            </div>
            <span class="details">

				<div><?php 
    _e('Records', 'event_espresso');
    ?>
  <span id="startrecord"></span> - <span id="endrecord"></span>
                                <?php 
    _e('of', 'event_espresso');
    ?>
 <span id="totalrecords"></span>
</div>
        		<div><a href="javascript:sorter.reset()"><?php 
    _e('Reset', 'event_espresso');
    ?>
</a></div>
        	</span>
        </div>
        
   <form id="form1" name="form1" method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">
   
   <table id="table" class="tinytable"> 
    <thead>
           <tr>
            <th><h3><?php 
    _e('Delete', 'event_espresso');
    ?>
</h3></th>
            <th><h3><?php 
    _e('Event ID', 'event_espresso');
    ?>
</h3></th>
            <th><h3><?php 
    _e('Event Name', 'event_espresso');
    ?>
</h3></th>
            <th><h3><?php 
    _e('Start Date', 'event_espresso');
    ?>
</h3></th>
            <th><h3><?php 
    _e('Status', 'event_espresso');
    ?>
</h3></th>
            <th><h3><?php 
    _e('# Attendees', 'event_espresso');
    ?>
</h3></th>
            <th><h3><?php 
    _e('Action', 'event_espresso');
    ?>
</h3></th>
        </tr>
          </thead>
    <tbody>
<?php 
    $event_results = $wpdb->get_results("SELECT * FROM " . EVENTS_DETAIL_TABLE . " ORDER BY date(start_date) " . $limit);
    if ($wpdb->num_rows > 0) {
        foreach ($event_results as $event) {
            $event_id = $event->id;
            $event_name = $event->event_name;
            $event_desc = $event->event_desc;
            $event_description = $event->event_desc;
            $event_identifier = $event->event_identifier;
            $event_cost = $event->event_cost;
            $active = $event->is_active;
            $event_status = $event->event_status;
            $status = array();
            $status = event_espresso_get_is_active($event_id);
            $start_date = $event->start_date;
            $end_date = $event->end_date;
            $reg_limit = $event->reg_limit;
            ?>
          	<tr>
            <td>
            <?php 
            echo $event_status == 'D' ? '<input name="checkbox[' . $event_id . ']" type="checkbox"  title="Permanently delete ' . $event_name . '" />' : '';
            ?>
            
            </td>
            <td><?php 
            echo $event_id;
            ?>
</td>
            <td><a href="admin.php?page=events&amp;event_id=<?php 
            echo $event_id;
            ?>
&amp;event_admin_reports=list_attendee_payments" title="<?php 
            _e('View Attendees', 'event_espresso');
            ?>
"><?php 
            echo stripslashes($event_name);
            ?>
</a></td>
            <td><?php 
            echo event_date_display($start_date);
            ?>
</td>
            <td><?php 
            echo $status['display'];
            ?>
</td>
            <td><?php 
            echo get_number_of_attendees_reg_limit($event_id, 'num_attendees_slash_reg_limit');
            ?>
</td>
            <td><a href="admin.php?page=events&amp;event_id=<?php 
            echo $event_id;
            ?>
&amp;event_admin_reports=list_attendee_payments" title="<?php 
            _e('View Attendees', 'event_espresso');
            ?>
"><img src="<?php 
            echo EVENT_ESPRESSO_PLUGINFULLURL;
            ?>
images/icons/group.png" width="16" height="16" alt="<?php 
            _e('View Attendees', 'event_espresso');
            ?>
" /></a> | <a href="admin.php?page=events&amp;action=edit&amp;event_id=<?php 
            echo $event_id;
            ?>
" title="<?php 
            _e('Edit Event', 'event_espresso');
            ?>
"><img src="<?php 
            echo EVENT_ESPRESSO_PLUGINFULLURL;
            ?>
images/icons/calendar_edit.png" width="16" height="16" alt="<?php 
            _e('Edit Event', 'event_espresso');
            ?>
" /></a> | <a href="#" onclick="window.location='<?php 
            echo get_bloginfo('wpurl') . "/wp-admin/admin.php?event_espresso&amp;id=" . $event_id . "&amp;export=report&action=payment&amp;type=excel";
            ?>
'" title="<?php 
            _e('Export to Excel', 'event_espresso');
            ?>
"><img alt="<?php 
            _e('Export to Excel', 'event_espresso');
            ?>
" src="<?php 
            echo EVENT_ESPRESSO_PLUGINFULLURL;
            ?>
images/icons/excel_icon.png" width="16" height="16"  /></a> | <a href="#" onclick="window.location='<?php 
            echo get_bloginfo('wpurl') . "/wp-admin/admin.php?event_espresso&id=" . $event_id . "&export=report&action=payment&type=csv";
            ?>
'" title="<?php 
            _e('Export to CSV', 'event_espresso');
            ?>
"><img src="<?php 
            echo EVENT_ESPRESSO_PLUGINFULLURL;
            ?>
images/icons/csv_icon_sm.gif" width="15" height="16" alt="<?php 
            _e('Export to CSV', 'event_espresso');
            ?>
" /></a>
            | <a href="admin.php?page=events&amp;event_admin_reports=event_newsletter&amp;event_id=<?php 
            echo $event_id;
            ?>
" title="<?php 
            _e('Email Event Attendees', 'event_espresso');
            ?>
"><img src="<?php 
            echo EVENT_ESPRESSO_PLUGINFULLURL;
            ?>
images/icons/email_go.png" width="16" height="16" alt="<?php 
            _e('Email Event Attendees', 'event_espresso');
            ?>
" /></a></td>
  			</tr>
<?php 
        }
    } else {
        ?>
  		<tr>
    	<td><?php 
        _e('No Record Found!', 'event_espresso');
        ?>
</td>
  		</tr>
<?php 
    }
    ?>
  	</tbody>
	</table>
     <input type="checkbox" name="sAll" onclick="selectAll(this)" />
  <strong>
  <?php 
    _e('Check All', 'event_espresso');
    ?>
  </strong>
  <input name="perm_delete_event" type="submit" class="button-secondary" id="perm_delete_event" value="<?php 
    _e('Permanently Delete Events(s)', 'event_espresso');
    ?>
" style="margin-left:100px;" onclick="return confirmDelete();" />
  </form>
	<div id="tablefooter">
          <div id="tablenav">
            	<div>
                    <img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
images/first.gif" width="16" height="16" alt="First Page" onclick="sorter.move(-1,true)" />
                    <img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
images/previous.gif" width="16" height="16" alt="First Page" onclick="sorter.move(-1)" />
                    <img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
images/next.gif" width="16" height="16" alt="First Page" onclick="sorter.move(1)" />
                    <img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
images/last.gif" width="16" height="16" alt="Last Page" onclick="sorter.move(1,true)" />
</div>
                <div>
                	<select id="pagedropdown"></select>
				</div>
                <div>
                	<a href="javascript:sorter.showall()"><?php 
    _e('View All', 'event_espresso');
    ?>
</a>
                </div>
            </div>
			<div id="tablelocation">
            	<div>
                    <select onchange="sorter.size(this.value)">
                    <option value="5">5</option>
                        <option value="10" selected="selected">10</option>
                        <option value="20">20</option>
                        <option value="50">50</option>
                        <option value="100">100</option>
                    </select>
                    <span><?php 
    _e('Entries Per Page', 'event_espresso');
    ?>
</span>
                </div>
                <div class="page"><?php 
    _e('Page', 'event_espresso');
    ?>
 <span id="currentpage"></span> <?php 
    _e('of', 'event_espresso');
    ?>
                    <span id="totalpages"></span>
</div>
            </div>
        </div>
    </div>
  	<script type="text/javascript">
	var sorter = new TINY.table.sorter('sorter','table',{
		headclass:'head',
		ascclass:'asc',
		descclass:'desc',
		evenclass:'evenrow',
		oddclass:'oddrow',
		evenselclass:'evenselected',
		oddselclass:'oddselected',
		paginate:true,
		size:30,
		colddid:'columns',
		currentid:'currentpage',
		totalid:'totalpages',
		startingrecid:'startrecord',
		endingrecid:'endrecord',
		totalrecid:'totalrecords',
		hoverid:'selectedrow',
		pageddid:'pagedropdown',
		navid:'tablenav',
		sortcolumn:1,
		sortdir:1,
		//sum:[2],
		//avg:[2,7,8,9],
		//columns:[{index:7, format:'%', decimals:1},{index:2, format:'$', decimals:0}],
		init:true
	});
  	</script>
<?php 
}
function edit_event($event_id = 0)
{
    global $wpdb, $org_options, $espresso_premium;
    ob_start();
    $SQL = "SELECT e.*, ev.id as venue_id\n\t    FROM " . EVENTS_DETAIL_TABLE . " e\n\t    LEFT JOIN " . EVENTS_VENUE_REL_TABLE . " vr ON e.id = vr.event_id\n\t    LEFT JOIN " . EVENTS_VENUE_TABLE . " ev ON vr.venue_id = ev.id\n\t    WHERE e.id = %d";
    $events = $wpdb->get_results($wpdb->prepare($SQL, $event_id));
    if (!is_array($events) || count($events) <= 0) {
        event_espresso_edit_list();
        #echo "<div class='updated fade below-h2'><p>";
        #_e("Event is not available any more!","eventespresso");
        #echo "</p></div>";
        return 1;
    }
    foreach ($events as $event) {
        $event_id = $event->id;
        $event_name = htmlentities(stripslashes($event->event_name), ENT_QUOTES, 'UTF-8');
        $event_desc = htmlentities(stripslashes($event->event_desc), ENT_QUOTES, 'UTF-8');
        $display_desc = $event->display_desc;
        $display_reg_form = $event->display_reg_form;
        $member_only = $event->member_only;
        $phone = stripslashes_deep($event->phone);
        $externalURL = stripslashes_deep($event->externalURL);
        //Early discounts
        $early_disc = stripslashes_deep($event->early_disc);
        $early_disc_date = stripslashes_deep($event->early_disc_date);
        $early_disc_percentage = stripslashes_deep($event->early_disc_percentage);
        $post_id = $event->post_id;
        $post_type = $event->post_type;
        $event_identifier = stripslashes_deep($event->event_identifier);
        $registration_start = $event->registration_start;
        $registration_end = $event->registration_end;
        $registration_startT = $event->registration_startT;
        $resitration_endT = $event->registration_endT;
        $timezone_string = $event->timezone_string;
        $start_date = $event->start_date;
        $end_date = $event->end_date;
        $tax_percentage = $event->tax_percentage;
        $tax_mode = $event->tax_mode;
        $start_time = isset($event->start_time) ? $event->start_time : '';
        $end_time = isset($event->end_time) ? $event->end_time : '';
        $reg_limit = $event->reg_limit;
        $additional_limit = $event->additional_limit;
        $allow_overflow = $event->allow_overflow;
        $overflow_event_id = $event->overflow_event_id;
        $allow_multiple = $event->allow_multiple;
        $event_cost = unserialize(isset($event->event_cost) ? $event->event_cost : '');
        $is_active = $event->is_active;
        $status = array();
        $status = event_espresso_get_is_active($event_id);
        $event_status = $event->event_status;
        $conf_mail = stripslashes_deep($event->conf_mail);
        $send_mail = stripslashes_deep($event->send_mail);
        $use_coupon_code = $event->use_coupon_code;
        $alt_email = $event->alt_email;
        $address = stripslashes_deep($event->address);
        $address2 = stripslashes_deep($event->address2);
        $city = stripslashes_deep($event->city);
        $state = stripslashes_deep($event->state);
        $zip = stripslashes_deep($event->zip);
        $country = stripslashes_deep($event->country);
        $venue_id = stripslashes_deep($event->venue_id);
        $venue_title = stripslashes_deep($event->venue_title);
        $venue_url = stripslashes_deep($event->venue_url);
        $venue_phone = stripslashes_deep($event->venue_phone);
        $venue_image = stripslashes_deep($event->venue_image);
        $email_id = $event->email_id;
        $ticket_id = $event->ticket_id;
        $wp_user = $event->wp_user;
        $date_submitted = $event->submitted != '0000-00-00 00:00:00' ? empty($event->submitted) ? '' : event_date_display($event->submitted, get_option('date_format')) : 'N/A';
        $google_map_link = espresso_google_map_link(array('address' => $address, 'city' => $city, 'state' => $state, 'zip' => $zip, 'country' => $country));
        //Virtual location
        $virtual_url = stripslashes_deep($event->virtual_url);
        $virtual_phone = stripslashes_deep($event->virtual_phone);
        $question_groups = unserialize($event->question_groups);
        global $event_meta;
        $event_meta = unserialize($event->event_meta);
        $recurrence_id = $event->recurrence_id;
        $visible_on = $event->visible_on;
        $require_pre_approval = $event->require_pre_approval;
        if (function_exists('event_espresso_edit_event_groupon')) {
            $use_groupon_code = $event->use_groupon_code;
        }
    }
    $values = array(array('id' => 'Y', 'text' => __('Yes', 'event_espresso')), array('id' => 'N', 'text' => __('No', 'event_espresso')));
    //If user is an event manager, then show only their events
    if (function_exists('espresso_is_my_event') && espresso_is_my_event($event_id) != true) {
        echo '<h2>' . __('Sorry, you do not have permission to edit this event.', 'event_espresso') . '</h2>';
        return;
    }
    ?>
	<!--Update event display-->
	<div id="submitdiv" class="postbox">
		<div class="handlediv" title="Click to toggle"><br />
		</div>
		<h3 class='hndle'> <span>
	<?php 
    _e('Quick Overview', 'event_espresso');
    ?>
			</span> </h3>
		<div class="inside">
			<div class="submitbox" id="submitpost">
				<div id="minor-publishing">
					<div id="minor-publishing-actions" class="clearfix">
						<div id="preview-action"> <a class="preview button" href="<?php 
    echo espresso_reg_url($event_id);
    ?>
" target="_blank" id="event-preview" tabindex="5">
	<?php 
    _e('View Event', 'event_espresso');
    ?>
							</a>
							<input type="hidden" name="event-preview" id="event-preview" value="" />
						</div>
						<div id="copy-action"> <a class="preview button" href="admin.php?page=events&amp;action=copy_event&event_id=<?php 
    echo $event_id;
    ?>
" id="post-copy" tabindex="4" onclick="return confirm('<?php 
    _e('Are you sure you want to copy ' . $event_name . '?', 'event_espresso');
    ?>
')">
	<?php 
    _e('Duplicate Event', 'event_espresso');
    ?>
							</a>
							<input  type="hidden" name="event-copy" id="event-copy" value="" />
						</div>
					</div>
					<!-- /minor-publishing-actions -->

					<div id="misc-publishing-actions">
						<div class="misc-pub-section curtime" id="visibility"> <span id="timestamp">
	<?php 
    _e('Start Date', 'event_espresso');
    ?>
								<b> <?php 
    echo event_date_display($start_date);
    ?>
 <?php 
    echo event_date_display($start_time, get_option('time_format'));
    ?>
</b> </span> </div>
						<div class="misc-pub-section">
							<label for="post_status">
	<?php 
    _e('Current Status:', 'event_espresso');
    ?>
							</label>
							<span id="post-status-display"> <?php 
    echo $status['display'];
    ?>
</span> </div>
						<div class="misc-pub-section" id="visibility"> <img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
images/icons/group.png" width="16" height="16" alt="<?php 
    _e('View Attendees', 'event_espresso');
    ?>
" /> <?php 
    echo !empty($number_attendees) ? __('Attendees', 'event_espresso') : '<a href="admin.php?page=events&amp;event_admin_reports=list_attendee_payments&amp;event_id=' . $event_id . '">' . __('Attendees', 'event_espresso') . '</a>';
    ?>
: <?php 
    echo get_number_of_attendees_reg_limit($event_id, 'num_attendees_slash_reg_limit');
    ?>
 </div>
						<div class="misc-pub-section <?php 
    echo function_exists('espresso_is_admin') && espresso_is_admin() == true && $espresso_premium == true ? '' : 'misc-pub-section-last';
    ?>
" id="visibility2"> <a href="admin.php?page=events&amp;event_admin_reports=event_newsletter&amp;event_id=<?php 
    echo $event_id;
    ?>
" title="<?php 
    _e('Email Event Attendees', 'event_espresso');
    ?>
"><img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
images/icons/email_go.png" width="16" height="16" alt="<?php 
    _e('Newsletter', 'event_espresso');
    ?>
" /></a> <a href="admin.php?page=events&amp;event_admin_reports=event_newsletter&amp;event_id=<?php 
    echo $event_id;
    ?>
" title="<?php 
    _e('Email Event Attendees', 'event_espresso');
    ?>
">
						<?php 
    _e('Email Event Attendees', 'event_espresso');
    ?>
							</a></div>
						<?php 
    if (function_exists('espresso_is_admin') && espresso_is_admin() == true && $espresso_premium == true) {
        $user_name = espresso_user_meta($wp_user, 'user_firstname') != '' ? espresso_user_meta($wp_user, 'user_firstname') . ' ' . espresso_user_meta($wp_user, 'user_lastname') . ' (<a href="user-edit.php?user_id=' . $wp_user . '">' . espresso_user_meta($wp_user, 'user_nicename') . '</a>)' : espresso_user_meta($wp_user, 'display_name') . ' (<a href="user-edit.php?user_id=' . $wp_user . '">' . espresso_user_meta($wp_user, 'user_nicename') . '</a>)';
        $user_company = espresso_user_meta($wp_user, 'company') != '' ? espresso_user_meta($wp_user, 'company') : '';
        $user_organization = espresso_user_meta($wp_user, 'organization') != '' ? espresso_user_meta($wp_user, 'organization') : '';
        $user_co_org = $user_company != '' ? $user_company : $user_organization;
        echo '<div class="misc-pub-section misc-pub-section-last" id="visibility3">';
        echo '<ul>';
        echo '<li><strong>' . __('Submitted By:', 'event_espresso') . '</strong> ' . $user_name . '</li>';
        echo '<li><strong>' . __('Email:', 'event_espresso') . '</strong> ' . espresso_user_meta($wp_user, 'user_email') . '</li>';
        echo $user_co_org != '' ? '<li><strong>' . __('Organization:', 'event_espresso') . '</strong> ' . espresso_user_meta($wp_user, 'company') . '</li>' : '';
        echo '<li><strong>' . __('Date Submitted:', 'event_espresso') . '</strong> ' . $date_submitted . '</li>';
        echo '</ul>';
        echo '</div>';
    }
    ?>
					</div>
					<!-- /misc-publishing-actions -->
				</div>
				<!-- /minor-publishing -->

				<div id="major-publishing-actions" class="clearfix">
							<?php 
    if ($recurrence_id > 0) {
        ?>
						<div id="delete-action"> &nbsp; <a class="submitdelete deletion" href="admin.php?page=events&amp;action=delete_recurrence_series&recurrence_id=<?php 
        echo $recurrence_id;
        ?>
" onclick="return confirm('<?php 
        _e('Are you sure you want to delete ' . $event_name . '?', 'event_espresso');
        ?>
')">
						<?php 
        _e('Delete all events in this series', 'event_espresso');
        ?>
							</a> </div>
							<?php 
    } else {
        ?>
						<div id="delete-action"> <a class="submitdelete deletion" href="admin.php?page=events&amp;action=delete&event_id=<?php 
        echo $event_id;
        ?>
" onclick="return confirm('<?php 
        _e('Are you sure you want to delete ' . $event_name . '?', 'event_espresso');
        ?>
')">
						<?php 
        _e('Delete Event', 'event_espresso');
        ?>
							</a> </div>
	<?php 
    }
    ?>
					<div id="publishing-action">
						<input class="button-primary" type="submit" name="Submit" value="<?php 
    _e('Update Event', 'event_espresso');
    ?>
" id="save_event_setting" />
					</div>
					<!-- /publishing-action -->
				</div>
				<!-- /major-publishing-actions -->
			</div>
			<!-- /submitpost -->
		</div>
		<!-- /inside -->
	</div>
	<!-- /submitdiv -->

	<?php 
    if ($espresso_premium == true) {
        do_action('action_hook_espresso_edit_event_right_column_top', $event_id);
    }
    $advanced_options = '';
    if (file_exists(EVENT_ESPRESSO_PLUGINFULLPATH . 'includes/admin-files/event-management/advanced_settings.php')) {
        require_once EVENT_ESPRESSO_PLUGINFULLPATH . "includes/admin-files/event-management/advanced_settings.php";
    } else {
        //Display Lite version options
        $status = array(array('id' => 'A', 'text' => __('Active', 'event_espresso')), array('id' => 'D', 'text' => __('Deleted', 'event_espresso')));
        $advanced_options = '<p><strong>' . __('Advanced Options:', 'event_espresso') . '</strong></p>' . '<p><label>' . __('Is this an active event? ', 'event_espresso') . '</label>' . __(select_input('is_active', $values, $is_active)) . '</p>' . '<p><label>' . __('Display  description? ', 'event_espresso') . '</label>' . select_input('display_desc', $values, $display_desc) . '</p>' . '<p><label>' . __('Display  registration form? ', 'event_espresso') . '</label>' . select_input('display_reg_form', $values, $display_reg_form) . '</p>';
    }
    //Display Lite version options - End
    espresso_postbox('event-status', 'Event Options', '<p><label for"reg-limit">' . __('Attendee Limit', 'event_espresso') . ': </label><input name="reg_limit" id="reg-limit" size="10" type="text" value="' . $reg_limit . '" /><br />' . '<span>(' . __('leave blank for unlimited', 'event_espresso') . ')</span></p>' . '<p><label>' . __('Allow group registrations?', 'event_espresso') . '</label> ' . select_input('allow_multiple', $values, $allow_multiple) . '</p>' . '<p><label for="addit-limit">' . __('Max Group Registrants', 'event_espresso') . ':</label> <input type="text" id="addit-limit" name="additional_limit" value="' . $additional_limit . '" size="4" />' . '</p>' . $advanced_options);
    if (function_exists('espresso_ticket_dd') && $espresso_premium == true) {
        ?>
		<div id="event-category" class="postbox">
			<div class="handlediv" title="Click to toggle"><br>
			</div>
			<h3 class="hndle"> <span>
				<?php 
        _e('Custom Tickets', 'event_espresso');
        ?>
				</span> </h3>
			<div class="inside"> <?php 
        echo espresso_ticket_dd($ticket_id);
        ?>
 </div>
		</div>
	<?php 
    }
    if ($espresso_premium == true) {
        ?>
		<div id="featured-image-options" class="postbox">
				<div class="handlediv" title="Click to toggle"><br />
				</div>
				<h3 class="hndle"> <span>
					<?php 
        _e('Featured Image', 'event_espresso');
        ?>
					</span> </h3>
		<div class="inside">
			<div id="featured-image">
				<?php 
        if (!empty($event_meta['event_thumbnail_url'])) {
            $event_thumb = $event_meta['event_thumbnail_url'];
        } else {
            $event_thumb = '';
        }
        ?>
				<label for="upload_image">
					<?php 
        _e('Add Featured Image', 'event_espresso');
        ?>
				</label>
				<input id="upload_image" type="hidden" size="36" name="upload_image" value="<?php 
        echo $event_thumb;
        ?>
" />
				<input id="upload_image_button" type="button" value="<?php 
        _e('Upload Image', 'event_espresso');
        ?>
" />
				<?php 
        if ($event_thumb) {
            ?>
					<p class="event-featured-thumb"><img style="width: 100%;"  src="<?php 
            echo $event_thumb;
            ?>
" alt="" /></p>
					<a id='remove-image' href='#' title='<?php 
            _e('Remove Image', 'event_espresso');
            ?>
' onclick='return false;'><?php 
            _e('Remove Image', 'event_espresso');
            ?>
</a>
				<?php 
        }
        ?>
			</div>
			
		</div>
		</div>
	<?php 
    }
    /*
     * Added for seating chart addon
     */
    if (defined('ESPRESSO_SEATING_CHART')) {
        $seating_chart_id = 0;
        $seating_chart_event = $wpdb->get_row("select * from " . EVENTS_SEATING_CHART_EVENT_TABLE . " where event_id = {$event_id}");
        if ($seating_chart_event !== NULL) {
            $seating_chart_id = $seating_chart_event->seating_chart_id;
        }
        ?>
		<div style="display: block;" id="seating_chart-options" class="postbox">
			<div class="handlediv" title="Click to toggle"><br />
			</div>
			<h3 class="hndle"><span>
		<?php 
        _e('Seating chart', 'event_espresso');
        ?>
				</span></h3>
			<div class="inside">
				<p>
					<select name="seating_chart_id" id="seating_chart_id" style="float:none;">
						<option value="0" <?php 
        if ($seating_chart_id == 0) {
            echo 'selected="selected"';
        }
        ?>
 ><?php 
        _e('None', 'event_espresso');
        ?>
</option>
						<?php 
        $seating_charts = $wpdb->get_results("select * from " . EVENTS_SEATING_CHART_TABLE . " order by name");
        foreach ($seating_charts as $seating_chart) {
            ?>
							<option value="<?php 
            echo $seating_chart->id;
            ?>
" <?php 
            if ($seating_chart_id == $seating_chart->id) {
                echo 'selected="selected"';
            }
            ?>
 ><?php 
            echo $seating_chart->name;
            ?>
</option>
			<?php 
        }
        ?>
					</select>
					<?php 
        do_action('espresso_seating_chart_select', $event_id);
        ?>
					<?php 
        do_action('ee_seating_chart_js');
        ?>
					<?php 
        do_action('ee_seating_chart_css');
        ?>
					<?php 
        do_action('ee_seating_chart_flush_expired_seats');
        ?>
				</p>
			</div>
		</div>
		<?php 
    }
    /*
     * End
     */
    ###### Modification by wp-developers to introduce attendee pre-approval requirement ##########
    if (isset($org_options['use_attendee_pre_approval']) && $org_options['use_attendee_pre_approval'] == 'Y' && $espresso_premium == true) {
        ?>
		<div id="attendee-pre-approval-options" class="postbox">
			<div class="handlediv" title="Click to toggle"><br />
			</div>
			<h3 class="hndle"> <span>
					<?php 
        _e('Attendee pre-approval required?', 'event_espresso');
        ?>
				</span> </h3>
			<div class="inside">
				<p class="pre-approve">
		<?php 
        $pre_approval_values = array(array('id' => '1', 'text' => __('Yes', 'event_espresso')), array('id' => '0', 'text' => __('No', 'event_espresso')));
        echo select_input("require_pre_approval", $pre_approval_values, $require_pre_approval);
        ?>
				</p>
			</div>
		</div>
		<?php 
    }
    ########## END #################################
    if (defined('EVENT_ESPRESSO_MEMBERS_DIR') && $espresso_premium == true) {
        ?>
		<div  id="member-options" class="postbox">
			<div class="handlediv" title="Click to toggle"><br>
			</div>
			<h3 class="hndle"> <span>
		<?php 
        _e('Member Options', 'event_espresso');
        ?>
				</span> </h3>
			<div class="inside">
				<p><?php 
        echo event_espresso_member_only($member_only);
        ?>
</p>
			</div>
		</div>
		<!-- /member-options -->
		<?php 
    }
    if (defined('EVENTS_MAILCHIMP_ATTENDEE_REL_TABLE') && $espresso_premium == true) {
        MailChimpView::event_list_selection();
    }
    ?>
	
	<div  id="event-categories" class="postbox">
		<div class="handlediv" title="Click to toggle"><br>
		</div>
		<h3 class="hndle"> <span>
	<?php 
    _e('Event Category', 'event_espresso');
    ?>
			</span> </h3>
		<div class="inside"> <?php 
    echo event_espresso_get_categories($event_id);
    ?>
 </div>
	</div>
	<!-- /event-category -->

	<?php 
    if (file_exists(EVENT_ESPRESSO_PLUGINFULLPATH . 'includes/admin-files/event-management/promotions_box.php')) {
        require_once EVENT_ESPRESSO_PLUGINFULLPATH . 'includes/admin-files/event-management/promotions_box.php';
    }
    ?>
	<!-- /event-promotions -->

	<?php 
    echo espresso_event_question_groups($question_groups, $event_meta['add_attendee_question_groups'], $event);
    ?>
	<!-- /event-questions -->

	<?php 
    do_action('action_hook_espresso_staff_cb', $event_id, $recurrence_id);
    if (defined('EVENTS_GROUPON_CODES_TABLE') && $espresso_premium == true) {
        ?>
		<div id="groupon-options" class="postbox">
			<div class="handlediv" title="Click to toggle"><br>
			</div>
			<h3 class="hndle"> <span>
		<?php 
        _e('Groupon Options', 'event_espresso');
        ?>
				</span> </h3>
			<div class="inside">
				<p><?php 
        echo event_espresso_edit_event_groupon($use_groupon_code);
        ?>
</p>
			</div>
		</div>
		<!-- /groupon-options -->
			<?php 
    }
    if ($espresso_premium == true) {
        do_action('action_hook_espresso_edit_event_right_column_bottom', $event_id);
    }
    $sidebar_content = ob_get_clean();
    ob_start();
    ?>
	<div id="titlediv"> <strong>
	<?php 
    _e('Event Title', 'event_espresso');
    ?>
		</strong>
		<div id="titlewrap">
			<label class="screen-reader-text" for="title">
	<?php 
    _e('Event Title', 'event_espresso');
    ?>
			</label>
			<input type="text" name="event" size="30" tabindex="1" value="<?php 
    echo $event_name;
    ?>
" id="title" autocomplete="off" />
		</div>
		<!-- /titlewrap -->
		<div class="inside">
			<div id="edit-slug-box"> <strong>
	<?php 
    _e('Unique Event Identifier:', 'event_espresso');
    ?>
				</strong>
				<input disabled="disabled" type="text" size="30" tabindex="2" name="event_identifier" id="event_identifier" value ="<?php 
    echo $event_identifier;
    ?>
" />
	<?php 
    echo '<a href="#" class="button" onclick="prompt(&#39;Event Shortcode:&#39;, \'[SINGLEEVENT single_event_id=&#34;\' + jQuery(\'#event_identifier\').val() + \'&#34;]\'); return false;">' . __('Shortcode') . '</a>';
    ?>
 <?php 
    echo '<a href="#" class="button" onclick="prompt(&#39;Short URL:&#39;, \'' . espresso_reg_url($event_id) . '\'); return false;">' . __('Short URL') . '</a>';
    ?>
 <?php 
    echo '<a href="#" class="button" onclick="prompt(&#39;Full URL:&#39;, \'' . home_url() . '/?page_id=' . $org_options['event_page_id'] . '&amp;regevent_action=register&amp;event_id=' . $event_id . '\'); return false;">' . __('Full URL') . '</a>';
    ?>
 </div>
			<!-- /edit-slug-box -->
		</div>
		<!-- /.inside -->
	</div>
	<!-- /titlediv -->

	<div id="descriptiondivrich" class="postarea"> <strong>
		<?php 
    _e('Event Description', 'event_espresso');
    ?>
		</strong>
		<?php 
    if (function_exists('wp_editor')) {
        $args = array("textarea_rows" => 5, "textarea_name" => "event_desc", "editor_class" => "my_editor_custom");
        wp_editor(espresso_admin_format_content($event_desc), "event_desc", $args);
    } else {
        /*
         This is the editor used by WordPress. It is very very hard to find documentation for this thing, so I pasted everything I could find below.
         param: string $content Textarea content.
         param: string $id Optional, default is 'content'. HTML ID attribute value.
         param: string $prev_id Optional, default is 'title'. HTML ID name for switching back and forth between visual editors.
         param: bool $media_buttons Optional, default is true. Whether to display media buttons.
         param: int $tab_index Optional, default is 2. Tabindex for textarea element.
        */
        //the_editor($content, $id = 'content', $prev_id = 'title', $media_buttons = true, $tab_index = 2)
        //the_editor(espresso_admin_format_content($event_desc), $id = 'event_desc'/* , $prev_id = 'title', $media_buttons = true, $tab_index = 3 */);
        the_editor(espresso_admin_format_content($event_desc), $id = 'event_desc');
    }
    ?>
		<table id="post-status-info" cellspacing="0">
			<tbody>
				<tr>
					<td id="wp-word-count"></td>
					<td class="autosave-info"><span id="autosave">&nbsp;</span></td>
				</tr>
			</tbody>
		</table>
	</div>
	<!-- /postdivrich -->
	<?php 
    $main_post_content = ob_get_clean();
    ob_start();
    ?>
	<div id="normal-sortables" class="meta-box-sortables ui-sortable">
		<div style="display: block;" id="event-date-time" class="postbox">
			<div class="handlediv" title="Click to toggle"><br>
			</div>
			<h3 class="hndle"> <span>
	<?php 
    _e('Event Date/Times', 'event_espresso');
    ?>
				</span> </h3>
			<div class="inside">
				<table width="100%" border="0" cellpadding="5">
					<tr valign="top">
						<td class="a"><fieldset id="add-reg-dates">
								<legend>
	<?php 
    _e('Registration Dates', 'event_espresso');
    ?>
								</legend>
								<p>
									<label for="registration_start"> <?php 
    echo __('Registration Start:', 'event_espresso');
    ?>
</label>
									<input type="text" class="datepicker" size="15" id="registration_start" name="registration_start"  value="<?php 
    echo $registration_start;
    ?>
" />
								</p>
								<p>
									<label for="registration_end"><?php 
    echo __('Registration End:', 'event_espresso');
    ?>
</label>
									<input type="text" class="datepicker" size="15" id="registration_end" name="registration_end"  value="<?php 
    echo $registration_end;
    ?>
" />
								</p>
							</fieldset>
							<fieldset>
								<legend>
	<?php 
    _e('Event Dates', 'event_espresso');
    ?>
								</legend>
								<p>
									<label for="start_date"><?php 
    echo __('Event Start Date', 'event_espresso');
    ?>
</label>
									<input type="text" class="datepicker" size="15" id="start_date" name="start_date" value="<?php 
    echo $start_date;
    ?>
" />
								</p>
								<p>
									<label for="end_date"><?php 
    echo __('Event End Date', 'event_espresso');
    ?>
</label>
									<input type="text" class="datepicker" size="15" id="end_date" name="end_date" value="<?php 
    echo $end_date;
    ?>
" />
								</p>
							</fieldset>
										<?php 
    if (isset($org_options['use_event_timezones']) && $org_options['use_event_timezones'] == 'Y' && $espresso_premium == true) {
        ?>
								<fieldset id="event-timezone">
									<p>
										<label>
								<?php 
        _e('Event Timezone', 'event_espresso');
        ?>
											:</label>
		<?php 
        echo eventespresso_ddtimezone($event_id);
        ?>
</p>
								</fieldset>
									<?php 
    }
    ?>
</td>
								<?php 
    // ADD TIME REGISTRATION
    ?>
						<td class="b"><fieldset id="add-register-times">
								<legend>
	<?php 
    _e('Registration Times', 'event_espresso');
    ?>
								</legend>
									<?php 
    echo event_espresso_timereg_editor($event_id);
    ?>
							</fieldset>
							<fieldset id="add-event-times">
								<legend>
							<?php 
    _e('Event Times', 'event_espresso');
    ?>
								</legend>
									<?php 
    echo event_espresso_time_editor($event_id);
    ?>
							</fieldset>
									<?php 
    if ((!isset($org_options['use_event_timezones']) || $org_options['use_event_timezones'] != 'Y') && $espresso_premium == true) {
        ?>
								<p><span class="run-in">
								<?php 
        _e('Current Time', 'event_espresso');
        ?>
										:</span> <span class="current-date"> <?php 
        echo date(get_option('date_format')) . ' ' . date(get_option('time_format'));
        ?>
</span> <a class="change-date-time" href="options-general.php" target="_blank">
		<?php 
        _e('Change timezone and date format settings?', 'event_espresso');
        ?>
									</a></p>
		<?php 
    }
    ?>
</td>
					</tr>
				</table>
			</div>
		</div>
		<?php 
    /**
     * Load the recurring events form if the add-on has been installed.	*
     */
    if (defined('EVENT_ESPRESSO_RECURRENCE_TABLE') && $espresso_premium == true) {
        require_once EVENT_ESPRESSO_RECURRENCE_FULL_PATH . "functions/re_view_functions.php";
        //For now, only the recurring events will show the form
        if ($recurrence_id > 0) {
            event_espresso_re_form($recurrence_id);
        }
    }
    ?>
		<div id="event-pricing" class="postbox">
					<?php 
    defined('EVENT_ESPRESSO_MEMBERS_DIR') ? $members_active = 'class="members-active"' : ($members_active = '');
    ?>
			<div class="handlediv" title="Click to toggle"><br>
			</div>
			<h3 class="hndle"> <span>
	<?php 
    _e('Event Pricing', 'event_espresso');
    ?>
				</span> </h3>
			<div class="inside">
				<table <?php 
    echo $members_active;
    ?>
width="100%" border="0" cellpadding="5">
					<tr valign="top">
						<td id="standard-pricing" class="a"><?php 
    event_espresso_multi_price_update($event_id);
    //Standard pricing
    ?>
</td>
						<?php 
    //If the members addon is installed, define member only event settings
    if (defined('EVENT_ESPRESSO_MEMBERS_DIR') && $espresso_premium == true) {
        ?>
							<td id="member-pricing" class="b"><?php 
        echo event_espresso_member_only_pricing($event_id);
        //Show the the member only pricing options.
        ?>
</td>
	<?php 
    }
    ?>
					</tr>
				</table>
			</div>
		</div>
		<h2>
	<?php 
    _e('Advanced Options', 'event_espresso');
    ?>
		</h2>
		<?php 
    if ($espresso_premium == true) {
        do_action('action_hook_espresso_edit_event_left_column_advanced_options_top', $event_id);
    }
    ?>
		<div id="event-location" class="postbox">
			<div class="handlediv" title="Click to toggle"><br />
			</div>
			<h3 class="hndle"> <span>
	<?php 
    _e('Additional Event/Venue Information', 'event_espresso');
    ?>
				</span> </h3>
			<div class="inside">
				<table width="100%" border="0" cellpadding="5">
					<tr valign="top">

	<?php 
    if (function_exists('espresso_venue_dd') && $org_options['use_venue_manager'] == 'Y' && $espresso_premium == true) {
        $ven_type = 'class="use-ven-manager"';
        ?>
							<td <?php 
        echo $ven_type;
        ?>
><fieldset id="venue-manager">
									<legend><?php 
        echo __('Venue Information', 'event_espresso');
        ?>
</legend>
									<?php 
        if (!espresso_venue_dd()) {
            ?>
										<p class="info"><b>
										<?php 
            _e('You have not created any venues yet.', 'event_espresso');
            ?>
											</b></p>
										<p><a href="admin.php?page=event_venues"><?php 
            echo __('Add venues to the Venue Manager', 'event_espresso');
            ?>
</a></p>
							<?php 
        } else {
            ?>
								<?php 
            echo espresso_venue_dd($venue_id);
            ?>
							<?php 
        }
        ?>
								</fieldset></td>
		<?php 
    } else {
        $ven_type = 'class="manual-venue"';
        ?>
							<td <?php 
        echo $ven_type;
        ?>
><fieldset>
									<legend>
											<?php 
        _e('Physical Location', 'event_espresso');
        ?>
									</legend>
									<p>
										<label for="phys-addr">
		<?php 
        _e('Address:', 'event_espresso');
        ?>
										</label>
										<input size="20" id="phys-addr" tabindex="100"  type="text"  value="<?php 
        echo $address;
        ?>
" name="address" />
									</p>
									<p>
										<label for="phys-addr-2">
		<?php 
        _e('Address 2:', 'event_espresso');
        ?>
										</label>
										<input size="20" id="phys-addr-2" tabindex="101"  type="text"  value="<?php 
        echo $address2;
        ?>
" name="address2" />
									</p>
									<p>
										<label for="phys-city">
		<?php 
        _e('City:', 'event_espresso');
        ?>
										</label>
										<input size="20" id="phys-city" tabindex="102"  type="text"  value="<?php 
        echo $city;
        ?>
" name="city" />
									</p>
									<p>
										<label for="phys-state">
		<?php 
        _e('State:', 'event_espresso');
        ?>
										</label>
										<input size="20" id="phys-state" tabindex="103"  type="text"  value="<?php 
        echo $state;
        ?>
" name="state" />
									</p>
									<p>
										<label for="zip-postal">
		<?php 
        _e('Zip/Postal Code:', 'event_espresso');
        ?>
										</label>
										<input size="20" id="zip-postal"  tabindex="104"  type="text"  value="<?php 
        echo $zip;
        ?>
" name="zip" />
									</p>
									<p>
										<label for="phys-country">
										<?php 
        _e('Country:', 'event_espresso');
        ?>
										</label>
										<input size="20" id="phys-country" tabindex="105"  type="text"  value="<?php 
        echo $country;
        ?>
" name="country" />
									</p>
									<p>
		<?php 
        _e('Google Map Link (for email):', 'event_espresso');
        ?>
										<br />
		<?php 
        echo $google_map_link;
        ?>
 </p>
								</fieldset></td>
							<td <?php 
        echo $ven_type;
        ?>
>

								<fieldset>

									<legend>
											<?php 
        _e('Venue Information', 'event_espresso');
        ?>
									</legend>
									<p>
										<label for="ven-title">
		<?php 
        _e('Title:', 'event_espresso');
        ?>
										</label>
										<input size="20"id="ven-title" tabindex="106"  type="text"  value="<?php 
        echo $venue_title;
        ?>
" name="venue_title" />
									</p>
									<p>
										<label for="ven-website">
		<?php 
        _e('Website:', 'event_espresso');
        ?>
										</label>
										<input size="20" id="ven-website" tabindex="107"  type="text"  value="<?php 
        echo $venue_url;
        ?>
" name="venue_url" />
									</p>
									<p>
										<label for="ven-phone">
		<?php 
        _e('Phone:', 'event_espresso');
        ?>
										</label>
										<input size="20" id="ven-phone" tabindex="108"  type="text"  value="<?php 
        echo $venue_phone;
        ?>
" name="venue_phone" />
									</p>
									<p>
										<label for="ven-image">
									<?php 
        _e('Image:', 'event_espresso');
        ?>
										</label>
										<input size="20" id="ven-image" tabindex="110"  type="text"  value="<?php 
        echo $venue_image;
        ?>
" name="venue_image" />
									</p>
									<?php 
    }
    ?>
						</td>

						<td <?php 
    echo $ven_type;
    ?>
><fieldset id="virt-location">
								<legend>
										<?php 
    _e('Virtual Location', 'event_espresso');
    ?>
								</legend>
								<p>
									<label for="virt-phone">
	<?php 
    _e('Phone:', 'event_espresso');
    ?>
									</label>
									<input size="20" id="virt-phone" type="text" tabindex="111" value="<?php 
    echo $phone;
    ?>
" name="phone" />
								</p>
								<p>
									<label for="url-event">
	<?php 
    _e('URL of Event:', 'event_espresso');
    ?>
									</label>
									<textarea id="url-event" cols="30" rows="4" tabindex="112"  name="virtual_url"><?php 
    echo $virtual_url;
    ?>
</textarea>
								</p>
								<p>
									<label for="call-in-num">
	<?php 
    _e('Call in Number:', 'event_espresso');
    ?>
									</label>
									<input id="call-in-num" size="20" tabindex="113"  type="text"  value="<?php 
    echo $virtual_phone;
    ?>
" name="virtual_phone" />
								</p>
							</fieldset></td>
					</tr>

				</table>
			</div>
		</div>
		<!-- /event-location-->
					<?php 
    if ($espresso_premium == true) {
        ?>
			<div id="event-meta" class="postbox">
				<div class="handlediv" title="Click to toggle"><br>
				</div>
				<h3 class="hndle"> <span>
		<?php 
        _e('Event Meta', 'event_espresso');
        ?>
					</span> </h3>
				<div class="inside">
		<?php 
        event_espresso_meta_edit($event_meta);
        ?>
				</div>
			</div>
	<?php 
    }
    ?>
		<!-- /event-meta-->
		<div id="confirmation-email" class="postbox">
			<div class="handlediv" title="Click to toggle"><br />
			</div>
			<h3 class="hndle"> <span>
	<?php 
    _e('Email Confirmation:', 'event_espresso');
    ?>
				</span> </h3>
			<div class="inside">
				<div id="emaildescriptiondivrich" class="postarea">
					<div class="email-conf-opts">
						<p><?php 
    echo __('Send custom confirmation emails for this event?', 'event_espresso') . ' ' . select_input('send_mail', $values, $send_mail);
    ?>
 <?php 
    echo '<a class="thickbox" href="#TB_inline?height=300&width=400&inlineId=custom_email_info"><img src="' . EVENT_ESPRESSO_PLUGINFULLURL . '/images/question-frame.png" width="16" height="16" /></a>';
    ?>
</p>
								<?php 
    if ($espresso_premium == true) {
        ?>
							<p>
		<?php 
        _e('Use a ', 'event_espresso');
        ?>
								<a href="admin.php?page=event_emails" target="_blank">
							<?php 
        _e('pre-existing email', 'event_espresso');
        ?>
								</a>? <?php 
        echo espresso_db_dropdown('id', 'email_name', EVENTS_EMAIL_TABLE, 'email_name', $email_id, 'desc') . ' <a class="thickbox" href="#TB_inline?height=300&width=400&inlineId=email_manager_info"><img src="' . EVENT_ESPRESSO_PLUGINFULLURL . '/images/question-frame.png" width="16" height="16" /></a>';
        ?>
 </p>
							<br />
							<em>OR</em>
	<?php 
    }
    ?>
						<p>
						<?php 
    _e('Create a custom email:', 'event_espresso');
    ?>
  <?php 
    echo '<a class="thickbox" href="#TB_inline?height=300&width=400&inlineId=event_custom_emails"><img src="' . EVENT_ESPRESSO_PLUGINFULLURL . '/images/question-frame.png" width="16" height="16" /></a>';
    ?>
						</p>
					</div>

					<div class="postbox">
						<?php 
    //echo '<p>version_compare ='.(version_compare($wp_version, $wp_min_version) >= 0).'</p>';
    if (function_exists('wp_editor')) {
        $args = array("textarea_rows" => 5, "textarea_name" => "conf_mail", "editor_class" => "my_editor_custom");
        wp_editor(espresso_admin_format_content($conf_mail), "conf_mail", $args);
    } else {
        echo '<textarea name="conf_mail" class="theEditor" id="conf_mail">' . espresso_admin_format_content($conf_mail) . '</textarea>';
        espresso_tiny_mce();
    }
    ?>
											<?php 
    /* ?>  <textarea name="conf_mail" class="theEditor" id="conf_mail"><?php echo espresso_admin_format_content($conf_mail); ?></textarea><?php */
    ?>
						<table id="email-confirmation-form" cellspacing="0">
							<tr>
								<td class="aer-word-count"></td>
								<td class="autosave-info"><span><a class="thickbox" href="#TB_inline?height=300&width=400&inlineId=custom_email_info">
	<?php 
    _e('View Custom Email Tags', 'event_espresso');
    ?>
										</a> | <a class="thickbox" href="#TB_inline?height=300&width=400&inlineId=custom_email_example">
	<?php 
    _e('Email Example', 'event_espresso');
    ?>
										</a></span></td>
							</tr>
						</table>
					</div>
				</div>
			</div>
		</div>
		<!-- /confirmation-email-->
	<?php 
    if (file_exists(EVENT_ESPRESSO_PLUGINFULLPATH . 'includes/admin-files/event-management/edit_event_post.php')) {
        require_once EVENT_ESPRESSO_PLUGINFULLPATH . "includes/admin-files/event-management/edit_event_post.php";
    }
    ?>
	</div>
	<!-- /normal-sortables-->
	<?php 
    $center_metabox_content = ob_get_clean();
    espresso_choose_layout($main_post_content, $sidebar_content, $center_metabox_content);
    include_once 'create_events_help.php';
    ?>
	<?php 
    wp_nonce_field('espresso_verify_update_event_nonce', 'nonce_verify_update_event');
    //Security check using nonce
    ?>
	<input type="hidden" name="edit_action" value="update">
	<input type="hidden" name="date_submitted" value="<?php 
    echo $date_submitted;
    ?>
">
	<input type="hidden" name="recurrence_id" value="<?php 
    echo $recurrence_id;
    ?>
">
	<input type="hidden" name="action" value="edit">
	<input type="hidden" name="event_id" value="<?php 
    echo $event_id;
    ?>
">
	<script type="text/javascript" charset="utf-8">
		//<![CDATA[
		jQuery(document).ready(function() {

			postboxes.add_postbox_toggles('events');

			jQuery(".datepicker" ).datepicker({
				changeMonth: true,
				changeYear: true,
				dateFormat: "yy-mm-dd",
				showButtonPanel: true
			});
	
			//Image upload		
			var header_clicked = false;
			jQuery('#upload_image_button').click(function() {
				formfield = jQuery('#upload_image').attr('name');
				tb_show('', 'media-upload.php?type=image&amp;TB_iframe=1');
				jQuery('p.event-featured-thumb').addClass('old');
				header_clicked = true;
				return false;
			});		
					
			window.original_send_to_editor = window.send_to_editor;
		
			window.send_to_editor = function(html) {
				if(header_clicked) {
					imgurl = jQuery('img',html).attr('src');
					jQuery('#' + formfield).val(imgurl);
					jQuery('#featured-image').append("<p id='image-display'><img class='show-selected-image' src='"+imgurl+"' alt='' /></p>");
					header_clicked = false;
					tb_remove();
			
				} else {
					window.original_send_to_editor(html);
				}
			}
		
			// process the remove link in the metabox
			jQuery('#remove-image').click(function(){
				var answer = confirm("<?php 
    _e("Do you really want to delete this image? Please remember to update your event to complete the removal.", 'event_espresso');
    ?>
");
				if (answer){
					jQuery("#upload_image").val('');
					jQuery("p.event-featured-thumb").remove();
					jQuery("p#image-display").remove();
					jQuery('#remove-image').remove();
					jQuery("#show_thumb_in_lists, #show_on_calendar, #show_thumb_in_regpage").val(false);
				}
				return false;
			});
	
	
		});
		//]]>
	</script>
	<?php 
}
		<tr>
			<td><?php 
_e('Primary Registrant:', 'event_espresso');
?>
</td>
			<td><?php 
echo stripslashes_deep($fname . ' ' . $lname);
?>
</td>
		</tr>
		<tr>
			<?php 
echo $txn_type == '' ? '' : '<td>' . __('Payment Type:', 'event_espresso') . '</td> <td>' . stripslashes_deep(espresso_payment_type($txn_type)) . '</td>';
?>
 <?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>
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.º 6
0
function espresso_replace_ticket_shortcodes($content, $data)
{
    global $wpdb, $org_options;
    $SearchValues = array("[att_id]", "[qr_code]", "[gravatar]", "[event_id]", "[event_identifier]", "[registration_id]", "[registration_date]", "[fname]", "[lname]", "[event_name]", "[description]", "[cost]", "[ticket_type]", "[ticket_qty]", "[company]", "[co_add1]", "[co_add2]", "[co_city]", "[co_state]", "[co_zip]", "[start_date]", "[start_time]", "[end_date]", "[end_time]", "[ticket_content]", "[ticket_logo_url]", "[ticket_logo_image]", "[venue_title]", "[venue_address]", "[venue_address2]", "[venue_city]", "[venue_state]", "[venue_zip]", "[venue_country]", "[venue_phone]", "[venue_description]", "[venue_website]", "[venue_image]", "[google_map_image]", "[google_map_link]", "[seatingchart_tag]");
    $ReplaceValues = array($data->attendee->id, $data->qr_code, $data->gravatar, $data->attendee->event_id, $data->event->event_identifier, $data->attendee->registration_id, event_date_display($data->attendee->registration_date), stripslashes_deep($data->attendee->fname), stripslashes_deep($data->attendee->lname), stripslashes_deep($data->event->event_name), stripslashes_deep($data->event->event_desc), $org_options['currency_symbol'] . ' ' . $data->attendee->final_price, $data->attendee->price_option, $data->attendee->quantity, stripslashes_deep($org_options['organization']), $org_options['organization_street1'], $org_options['organization_street2'], $org_options['organization_city'], $org_options['organization_state'], $org_options['organization_zip'], event_date_display($data->attendee->start_date), event_date_display($data->attendee->event_time, get_option('time_format')), event_date_display($data->attendee->end_date), event_date_display($data->attendee->end_time, get_option('time_format')), espresso_format_content($data->event->ticket_content), $data->event->ticket_logo_url, $data->event->ticket_logo_image, $data->event->venue_name, $data->event->address, $data->event->address2, $data->event->city, $data->event->state, $data->event->zip, $data->event->country, isset($data->event->venue_meta['phone']) && !empty($data->event->venue_meta['phone']) ? $data->event->venue_meta['phone'] : '', isset($data->event->venue_meta['description']) && !empty($data->event->venue_meta['description']) ? espresso_format_content($data->event->venue_meta['description']) : '', isset($data->event->venue_meta['website']) && !empty($data->event->venue_meta['website']) ? $data->event->venue_meta['website'] : '', isset($data->event->venue_meta['image']) && !empty($data->event->venue_meta['image']) ? $data->event->venue_meta['image'] : '', $data->event->google_map_image, $data->event->google_map_link, isset($data->attendee->seatingchart_tag) && !empty($data->attendee->seatingchart_tag) ? $data->attendee->seatingchart_tag : '');
    //Get the questions and answers
    $questions = $wpdb->get_results("select qst.question as question, ans.answer as answer from " . EVENTS_ANSWER_TABLE . " ans inner join " . EVENTS_QUESTION_TABLE . " qst on ans.question_id = qst.id where ans.attendee_id = " . $data->attendee->id, ARRAY_A);
    //echo '<p>'.print_r($questions).'</p>';
    if ($wpdb->num_rows > 0 && $wpdb->last_result[0]->question != NULL) {
        foreach ($questions as $q) {
            $k = $q['question'];
            $v = $q['answer'];
            //Output the question
            array_push($SearchValues, "[" . 'question_' . $k . "]");
            array_push($ReplaceValues, $k);
            //Output the answer
            array_push($SearchValues, "[" . 'answer_' . $k . "]");
            array_push($ReplaceValues, $v);
        }
    }
    //Get the event meta
    //echo '<p>'.print_r($data->event->event_meta).'</p>';
    if (!empty($data->event->event_meta)) {
        foreach ($data->event->event_meta as $k => $v) {
            array_push($SearchValues, "[" . $k . "]");
            array_push($ReplaceValues, stripslashes_deep($v));
        }
    }
    return str_replace($SearchValues, $ReplaceValues, $content);
}
Exemplo n.º 7
0
 function event_espresso_send_attendee_registration_approval_pending($registration_id)
 {
     global $org_options, $wpdb;
     do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, '');
     //Get the event information
     $events = $wpdb->get_results("SELECT ed.* FROM " . EVENTS_DETAIL_TABLE . " ed\n\t\t\t\t\t\tJOIN " . EVENTS_ATTENDEE_TABLE . " ea\n\t\t\t\t\t\tON ed.id = ea.event_id\n\t\t\t\t\t\tWHERE ea.registration_id='" . $registration_id . "'");
     foreach ($events as $event) {
         $event_id = $event->id;
         $event_name = stripslashes_deep($event->event_name);
         $event_desc = stripslashes_deep($event->event_desc);
         $display_desc = $event->display_desc;
         $event_identifier = $event->event_identifier;
         $reg_limit = $event->reg_limit;
         $active = $event->is_active;
         $send_mail = $event->send_mail;
         $conf_mail = $event->conf_mail;
         $email_id = $event->email_id;
         $alt_email = $event->alt_email;
         $start_date = event_date_display($event->start_date);
         $end_date = $event->end_date;
         $virtual_url = $event->virtual_url;
         $virtual_phone = $event->virtual_phone;
         $event_address = $event->address;
         $event_address2 = $event->address2;
         $event_city = $event->city;
         $event_state = $event->state;
         $event_zip = $event->zip;
         $event_country = $event->country;
         $location = ($event_address != '' ? $event_address : '') . ($event_address2 != '' ? '<br />' . $event_address2 : '') . ($event_city != '' ? '<br />' . $event_city : '') . ($event_state != '' ? ', ' . $event_state : '') . ($event_zip != '' ? '<br />' . $event_zip : '') . ($event_country != '' ? '<br />' . $event_country : '');
         $location_phone = $event->phone;
         $require_pre_approval = $event->require_pre_approval;
         $google_map_link = espresso_google_map_link(array('address' => $event_address, 'city' => $event_city, 'state' => $event_state, 'zip' => $event_zip, 'country' => $event_country));
     }
     //Build links
     $event_url = espresso_reg_url($event_id);
     $event_link = '<a href="' . $event_url . '">' . $event_name . '</a>';
     $sql = "SELECT * FROM " . EVENTS_ATTENDEE_TABLE;
     if ($registration_id != '') {
         $sql .= " WHERE registration_id = '" . $registration_id . "' ";
     } elseif ($attendee_id != '') {
         $sql .= " WHERE id = '" . $attendee_id . "' ";
     } else {
         _e('No ID Supplied', 'event_espresso');
     }
     $sql .= " ORDER BY id ";
     $sql .= " LIMIT 0,1 ";
     //Get the first attendees details
     $attendees = $wpdb->get_results($sql);
     //global $attendee_id;
     foreach ($attendees as $attendee) {
         $attendee_id = $attendee->id;
         $attendee_email = $attendee->email;
         $lname = $attendee->lname;
         $fname = $attendee->fname;
         $address = $attendee->address;
         $address2 = $attendee->address2;
         $city = $attendee->city;
         $state = $attendee->state;
         $zip = $attendee->zip;
         $payment_status = $attendee->payment_status;
         $txn_type = $attendee->txn_type;
         $amount_pd = $attendee->amount_pd;
         $event_cost = $attendee->amount_pd;
         $payment_date = event_date_display($attendee->payment_date);
         $phone = $attendee->phone;
         $event_time = event_date_display($attendee->event_time, get_option('time_format'));
         $end_time = event_date_display($attendee->end_time, get_option('time_format'));
         $date = event_date_display($attendee->date);
         $pre_approve = $attendee->pre_approve;
     }
     $admin_email = $alt_email == '' ? $org_options['contact_email'] : $alt_email . ',' . $org_options['contact_email'];
     if (!empty($admin_email)) {
         $subject = "New attendee registration approval pending";
         $body = "\nEvent title: {$event_name}\n<br/>\nAttendee name: {$fname}&nbsp;{$lname}\n<br/>\nThank You.\n";
         $email_params = array('send_to' => $admin_email, 'email_subject' => __($subject, 'event_espresso'), 'email_body' => $body);
         event_espresso_send_email($email_params);
     }
     if (!empty($attendee_email)) {
         $subject = "Event registration pending";
         $body = "\nEvent title: {$event_name}\n<br/>\nAttendee name: {$fname}&nbsp;{$lname}\n<br/>\nYour registration is pending for approval from event admin. You will receive an email with payment info when admin approves your registration.\n<br/><br/>\nThank You.\n";
         $email_params = array('send_to' => $attendee_email, 'email_subject' => __($subject, 'event_espresso'), 'email_body' => $body);
         event_espresso_send_email($email_params);
     }
 }
Exemplo n.º 8
0
 function espresso_export_stuff()
 {
     //Export data to Excel file
     if (isset($_REQUEST['export'])) {
         switch ($_REQUEST['export']) {
             case "report":
                 global $wpdb;
                 $event_id = $_REQUEST['event_id'];
                 $today = date("Y-m-d-Hi", time());
                 $sql_x = "SELECT id, event_name, event_desc, event_identifier, question_groups, event_meta FROM " . EVENTS_DETAIL_TABLE;
                 $sql_x .= $_REQUEST['all_events'] == "true" ? '' : " WHERE id = '" . $event_id . "' ";
                 //echo $sql_x;
                 $results = $wpdb->get_row($sql_x, ARRAY_N);
                 list($event_id, $event_name, $event_description, $event_identifier, $question_groups, $event_meta) = $results;
                 $basic_header = array(__('Group', 'event_espresso'), __('Reg ID', 'event_espresso'), __('Last Name', 'event_espresso'), __('First Name', 'event_espresso'), __('Email', 'event_espresso'), __('Address', 'event_espresso'), __('Address 2', 'event_espresso'), __('City', 'event_espresso'), __('State', 'event_espresso'), __('Zip', 'event_espresso'), __('Phone', 'event_espresso'), __('Payment Method', 'event_espresso'), __('Reg Date', 'event_espresso'), __('Pay Status', 'event_espresso'), __('Type of Payment', 'event_espresso'), __('Transaction ID', 'event_espresso'), __('Payment', 'event_espresso'), __('Coupon Code', 'event_espresso'), __('# Attendees', 'event_espresso'), __('Date Paid', 'event_espresso'), __('Event Name', 'event_espresso'), __('Price Option', 'event_espresso'), __('Event Date', 'event_espresso'), __('Event Time', 'event_espresso'), __('Website Check-in', 'event_espresso'), __('Tickets Scanned', 'event_espresso'));
                 $question_groups = unserialize($question_groups);
                 $event_meta = unserialize($event_meta);
                 if (isset($event_meta['add_attendee_question_groups'])) {
                     $add_attendee_question_groups = $event_meta['add_attendee_question_groups'];
                     if (!empty($add_attendee_question_groups)) {
                         $question_groups = array_unique(array_merge((array) $question_groups, (array) $add_attendee_question_groups));
                     }
                 }
                 switch ($_REQUEST['action']) {
                     case "event":
                         espresso_event_export($event_name);
                         break;
                     case "payment":
                         $question_list = array();
                         //will be used to associate questions with correct answers
                         $question_filter = array();
                         //will be used to keep track of newly added and deleted questions
                         if (count($question_groups) > 0) {
                             $questions_in = '';
                             $question_sequence = array();
                             /*foreach ($question_groups as $g_id) 
                             		{
                             			$questions_in .= $g_id . ',';
                             		}*/
                             $questions_in = implode(",", $question_groups);
                             /*$questions_in = substr($questions_in,0,-1);*/
                             $group_name = '';
                             $counter = 0;
                             $quest_sql = "SELECT q.id, q.question FROM " . EVENTS_QUESTION_TABLE . " q ";
                             $quest_sql .= " JOIN " . EVENTS_QST_GROUP_REL_TABLE . " qgr on q.id = qgr.question_id ";
                             $quest_sql .= " JOIN " . EVENTS_QST_GROUP_TABLE . " qg on qg.id = qgr.group_id ";
                             $quest_sql .= " WHERE qgr.group_id in ( " . $questions_in . ") ";
                             if (function_exists('espresso_member_data') && (espresso_member_data('role') == 'espresso_event_manager' || espresso_member_data('role') == 'espresso_group_admin')) {
                                 $quest_sql .= " AND qg.wp_user = '******'id') . "' ";
                             }
                             //Fix from Jesse in the forums (http://eventespresso.com/forums/2010/10/form-questions-appearing-in-wrong-columns-in-excel-export/)
                             //$quest_sql .= " AND q.system_name is null ORDER BY qg.id, q.id ASC ";
                             $quest_sql .= " AND q.system_name is null ORDER BY q.sequence, q.id ASC ";
                             $questions = $wpdb->get_results($quest_sql);
                             $num_rows = $wpdb->num_rows;
                             if ($num_rows > 0) {
                                 foreach ($questions as $question) {
                                     $question_list[$question->id] = $question->question;
                                     $question_filter[$question->id] = $question->id;
                                     array_push($basic_header, escape_csv_val($question->question, $_REQUEST['type']));
                                     //array_push($question_sequence, $question->sequence);
                                 }
                             }
                         }
                         if (count($question_filter) > 0) {
                             $question_filter = implode(",", $question_filter);
                         }
                         //$participants = $wpdb->get_results("SELECT * FROM ".EVENTS_ATTENDEE_TABLE." WHERE event_id = '$event_id'");
                         //$participants = $wpdb->get_results("SELECT ed.event_name, ed.start_date, a.id, a.lname, a.fname, a.email, a.address, a.city, a.state, a.zip, a.phone, a.payment, a.date, a.payment_status, a.txn_type, a.txn_id, a.amount_pd, a.quantity, a.coupon_code, a.payment_date, a.event_time, a.price_option FROM " . EVENTS_ATTENDEE_TABLE . " a JOIN " . EVENTS_DETAIL_TABLE . " ed ON ed.id=a.event_id WHERE ed.id = '" . $event_id . "'");
                         $sql = "(";
                         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 .= "SELECT ed.event_name, ed.start_date, a.id, a.registration_id, a.lname, a.fname, a.email, a.address, a.address2, a.city";
                             $sql .= ", a.state, a.zip, a.phone, a.payment, a.date, a.payment_status, a.txn_type, a.txn_id";
                             $sql .= ", a.amount_pd, a.quantity, a.coupon_code, a.checked_in, a.checked_in_quantity";
                             $sql .= ", a.payment_date, a.event_time, a.price_option";
                             $sql .= " FROM " . EVENTS_ATTENDEE_TABLE . " a ";
                             $sql .= " JOIN " . EVENTS_DETAIL_TABLE . " ed ON ed.id=a.event_id ";
                             if ($group != '') {
                                 $sql .= " JOIN " . EVENTS_VENUE_REL_TABLE . " r ON r.event_id = ed.id ";
                                 $sql .= " JOIN " . EVENTS_LOCALE_REL_TABLE . " l ON  l.venue_id = r.venue_id ";
                             }
                             $sql .= $_REQUEST['all_events'] == "true" ? '' : " WHERE ed.id = '" . $event_id . "' ";
                             $sql .= $group != '' ? " AND  l.locale_id IN (" . $group . ") " : '';
                             $sql .= ") UNION (";
                         }
                         $sql .= "SELECT ed.event_name, ed.start_date, a.id, a.registration_id, a.lname, a.fname, a.email, a.address, a.address2, a.city";
                         $sql .= ", a.state, a.zip, a.phone, a.payment, a.date, a.payment_status, a.txn_type, a.txn_id";
                         $sql .= ", a.amount_pd, a.quantity, a.coupon_code, a.checked_in, a.checked_in_quantity";
                         $sql .= ", a.payment_date, a.event_time, a.price_option";
                         $sql .= " FROM " . EVENTS_ATTENDEE_TABLE . " a ";
                         $sql .= " JOIN " . EVENTS_DETAIL_TABLE . " ed ON ed.id=a.event_id ";
                         $sql .= $_REQUEST['all_events'] == "true" ? '' : " WHERE ed.id = '" . $event_id . "' ";
                         if (function_exists('espresso_member_data') && (espresso_member_data('role') == 'espresso_event_manager' || espresso_member_data('role') == 'espresso_group_admin')) {
                             $sql .= " AND ed.wp_user = '******'id') . "' ";
                         }
                         $sql .= ") ORDER BY id ";
                         $participants = $wpdb->get_results($sql);
                         $filename = $_REQUEST['all_events'] == "true" ? __('all-events', 'event_espresso') : sanitize_title_with_dashes($event_name);
                         $filename = $filename . "-" . $today;
                         switch ($_REQUEST['type']) {
                             case "csv":
                                 $st = "";
                                 $et = ",";
                                 $s = $et . $st;
                                 header("Content-type: application/x-msdownload");
                                 header("Content-Disposition: attachment; filename=" . $filename . ".csv");
                                 //header("Content-Disposition: attachment; filename='" .$filename .".csv'");
                                 header("Pragma: no-cache");
                                 header("Expires: 0");
                                 //echo header
                                 echo implode($s, $basic_header) . "\r\n";
                                 break;
                             default:
                                 $st = "";
                                 $et = "\t";
                                 $s = $et . $st;
                                 header("Content-Disposition: attachment; filename=" . $filename . ".xls");
                                 //header("Content-Disposition: attachment; filename='" .$filename .".xls'");
                                 header("Content-Type: application/vnd.ms-excel");
                                 header("Pragma: no-cache");
                                 header("Expires: 0");
                                 //echo header
                                 echo implode($s, $basic_header) . $et . "\r\n";
                                 break;
                         }
                         //echo data
                         if ($participants) {
                             $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
                             $group_counter = 1;
                             $amount_pd = 0;
                             foreach ($participants as $participant) {
                                 if ($temp_reg_id == '') {
                                     $temp_reg_id = $participant->registration_id;
                                     $amount_pd = $participant->amount_pd;
                                 }
                                 if ($temp_reg_id == $participant->registration_id) {
                                 } else {
                                     $group_counter++;
                                     $temp_reg_id = $participant->registration_id;
                                 }
                                 $attendees_group = "Group {$group_counter}";
                                 echo $attendees_group . $s . $participant->id . $s . escape_csv_val(stripslashes($participant->lname)) . $s . escape_csv_val(stripslashes($participant->fname)) . $s . stripslashes($participant->email) . $s . escape_csv_val(stripslashes($participant->address)) . $s . escape_csv_val(stripslashes($participant->address2)) . $s . escape_csv_val(stripslashes($participant->city)) . $s . escape_csv_val(stripslashes($participant->state)) . $s . escape_csv_val(stripslashes($participant->zip)) . $s . escape_csv_val(stripslashes($participant->phone)) . $s . escape_csv_val(stripslashes($participant->payment)) . $s . event_date_display($participant->date, 'Y-m-d') . $s . stripslashes($participant->payment_status) . $s . stripslashes($participant->txn_type) . $s . stripslashes($participant->txn_id) . $s . $participant->amount_pd . $s . escape_csv_val($participant->coupon_code) . $s . $participant->quantity . $s . event_date_display($participant->payment_date, 'Y-m-d') . $s . escape_csv_val($participant->event_name) . $s . $participant->price_option . $s . event_date_display($participant->start_date, 'Y-m-d') . $s . event_date_display($participant->event_time, get_option('time_format')) . $s . $participant->checked_in . $s . $participant->checked_in_quantity;
                                 $answers = $wpdb->get_results("SELECT a.question_id, a.answer FROM " . EVENTS_ANSWER_TABLE . " a WHERE question_id IN ({$question_filter}) AND attendee_id = '" . $participant->id . "'", OBJECT_K);
                                 foreach ($question_list as $k => $v) {
                                     /*
                                      * in case the event organizer removes a question from a question group,
                                      * the orphaned answers will remian in the answers table.  This check will make sure they don't get exported.
                                      */
                                     /*if (array_key_exists($k, $answers))
                                     		{*/
                                     $search = array("\r", "\n", "\t");
                                     $clean_answer = str_replace($search, " ", $answers[$k]->answer);
                                     $clean_answer = escape_csv_val($clean_answer);
                                     echo $s . $clean_answer;
                                     /*} 
                                     		else 
                                     		{
                                     			echo $s;
                                     		}*/
                                 }
                                 switch ($_REQUEST['type']) {
                                     case "csv":
                                         echo "\r\n";
                                         break;
                                     default:
                                         echo $et . "\r\n";
                                         break;
                                 }
                             }
                         } else {
                             echo __('No participant data has been collected.', 'event_espresso');
                         }
                         exit;
                         break;
                     default:
                         echo '<p>' . __('This Is Not A Valid Selection!', 'event_espresso') . '</p>';
                         break;
                 }
             default:
                 break;
         }
     }
 }
Exemplo n.º 9
0
 function espresso_event_time($event_id, $type, $format = '')
 {
     global $wpdb;
     $sql = "SELECT e.id, e.start_date start_date, e.end_date end_date, ese.start_time start_time, ese.end_time end_time ";
     $sql .= "FROM " . EVENTS_DETAIL_TABLE . " e ";
     $sql .= "LEFT JOIN " . EVENTS_START_END_TABLE . " ese ON ese.event_id = e.id ";
     $sql .= "WHERE e.id = '" . $event_id . "' LIMIT 0,1";
     $date_format = $format == '' ? get_option('date_format') : $format;
     $time_format = $format == '' ? get_option('time_format') : $format;
     $wpdb->get_results($sql);
     //event_date_display($date, $format = 'M d, Y');
     switch ($type) {
         case 'start_time':
             return event_date_display($wpdb->last_result[0]->start_time, $time_format);
             break;
         case 'end_time':
             return event_date_display($wpdb->last_result[0]->end_time, $time_format);
             break;
         case 'start_date':
             return event_date_display($wpdb->last_result[0]->start_date, $date_format);
             break;
         case 'end_date':
             return event_date_display($wpdb->last_result[0]->end_date, $date_format);
             break;
         case 'start_timestamp':
             return strtotime($wpdb->last_result[0]->start_date . ' ' . $wpdb->last_result[0]->start_time);
             break;
         case 'end_timestamp':
             return strtotime($wpdb->last_result[0]->end_date . ' ' . $wpdb->last_result[0]->end_time);
             break;
         case 'end_date_time':
             return event_date_display($wpdb->last_result[0]->end_date, $date_format) . ' ' . event_date_display($wpdb->last_result[0]->end_time, $time_format);
             break;
         case 'start_date_time':
         default:
             return event_date_display($wpdb->last_result[0]->start_date, $date_format) . ' ' . event_date_display($wpdb->last_result[0]->start_time, $time_format);
             break;
     }
 }
Exemplo n.º 10
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 
}
Exemplo n.º 11
0
function espresso_get_table($sql)
{
    global $wpdb, $org_options;
    //echo 'This page is located in ' . get_option( 'upload_path' );
    $event_page_id = $org_options['event_page_id'];
    $currency_symbol = $org_options['currency_symbol'];
    $events = $wpdb->get_results($sql);
    $category_name = $wpdb->last_result[0]->category_name;
    $category_desc = $wpdb->last_result[0]->category_desc;
    $display_desc = $wpdb->last_result[0]->display_desc;
    if ($display_desc == 'Y') {
        echo '<p>' . stripslashes_deep($category_name) . '</p>';
        echo '<p>' . stripslashes_deep($category_desc) . '</p>';
    }
    ?>
<table class="espresso-table" width="100%">
  
      <thead class="espresso-table-header-row">
      <tr>
          <th class="th-group"><?php 
    _e('Course', 'event_espresso');
    ?>
</th>
          <th class="th-group"><?php 
    _e('Location', 'event_espresso');
    ?>
</th>
          <th class="th-group"><?php 
    _e('City', 'event_espresso');
    ?>
</th>
          <th class="th-group"><?php 
    _e('State', 'event_espresso');
    ?>
</th>
          <th class="th-group"><?php 
    _e('Date', 'event_espresso');
    ?>
</th>
          <th class="th-group"><?php 
    _e('Time', 'event_espresso');
    ?>
</th>
          <th class="th-group"><?php 
    _e('', 'event_espresso');
    ?>
</th>
     </tr>
      </thead>
	<tbody>

      <?php 
    foreach ($events as $event) {
        $reg_limit = $event->reg_limit;
        $event_desc = wpautop($event->event_desc);
        $register_button = '<a id="a_register_link-' . $event->id . '" href="' . get_option('siteurl') . '/?page_id=' . $event_page_id . '&regevent_action=register&event_id=' . $event->id . '&name_of_event=' . stripslashes_deep($event->event_name) . '">Register</a>';
        //Check to see how many open spots are available
        $open_spots = get_number_of_attendees_reg_limit($event->id, 'available_spaces') == 'Unlimited' ? 999 : get_number_of_attendees_reg_limit($event->id, 'available_spaces');
        //echo $open_spots;
        if ($open_spots < 1) {
            $live_button = 'Closed';
        }
        ?>
      <tr class="espresso-table-row">
       	<td class="td-group">
            <?php 
        echo $event->event_name;
        ?>
          </td>	
          <td class="td-group">
            <?php 
        echo $event->address;
        ?>
          </td>
          <td class="td-group">
            <?php 
        echo $event->city;
        ?>
          </td>
      	  <td class="td-group">
            <?php 
        echo $event->state;
        ?>
          </td>
          <td class="td-group">
              <?php 
        echo event_date_display($event->start_date, $format = 'l, M d, Y');
        ?>
          </td>
          <td class="td-group">
              <?php 
        echo espresso_event_time($event->id, 'start_time', get_option('time_format'));
        ?>
          </td>
         
          <td class="td-group">
              <?php 
        echo $register_button;
        ?>
          </td>
      </tr>
      <?php 
    }
    //close foreach
    ?>
</tbody>
</table>

<?php 
}
function enter_attendee_payments()
{
    global $wpdb, $org_options;
    $event_id = $_REQUEST['event_id'];
    $today = date("d-m-Y");
    //Added by Imon
    $multi_reg = false;
    $registration_id = $_REQUEST['registration_id'];
    $registration_ids = array();
    $check = $wpdb->get_row("select * from " . EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE . " where registration_id = '{$registration_id}' ");
    if ($check !== NULL) {
        $registration_id = $check->primary_registration_id;
        $registration_ids = $wpdb->get_results("select * from " . EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE . " where primary_registration_id = '{$registration_id}' ", ARRAY_A);
        $multi_reg = true;
    }
    switch ($_REQUEST['form_action']) {
        //Add payment info
        case 'payment':
            if (isset($_REQUEST['attendee_action']) && $_REQUEST['attendee_action'] == 'post_payment') {
                //Added by Imon
                $primary_row = $wpdb->get_row("select id from " . EVENTS_ATTENDEE_TABLE . " where registration_id = '{$registration_id}' order by id limit 0,1 ");
                $primary_attendee_id = $primary_row->id;
                // GET the primary attendee id because amount paid info is kept with the primary attendee
                $payment_status = isset($_REQUEST['payment_status']) ? $_REQUEST['payment_status'] : '';
                $txn_type = isset($_REQUEST['txn_type']) ? $_REQUEST['txn_type'] : '';
                $txn_id = isset($_REQUEST['txn_id']) ? $_REQUEST['txn_id'] : '';
                //$quantity = isset($_REQUEST[ 'quantity' ]) ? $_REQUEST[ 'quantity' ]:'';
                $amount_pd = isset($_REQUEST['amount_pd']) ? $_REQUEST['amount_pd'] : '';
                $payment_date = isset($_REQUEST['payment_date']) ? $_REQUEST['payment_date'] : '';
                $coupon_code = isset($_REQUEST['coupon_code']) ? $_REQUEST['coupon_code'] : '';
                //Added/updated by Imon
                //Update payment status information for primary attendee
                $sql = "UPDATE " . EVENTS_ATTENDEE_TABLE . " SET payment_status = '{$payment_status}', txn_type = '{$txn_type}', txn_id = '{$txn_id}', amount_pd = '{$amount_pd}', payment_date ='{$payment_date}',  coupon_code ='{$coupon_code}' WHERE registration_id ='" . $registration_id . "' and id = {$primary_attendee_id} ";
                $wpdb->query($sql);
                if (count($registration_ids) > 0) {
                    foreach ($registration_ids as $reg_id) {
                        // Update payment status information for all attendees
                        $sql = "UPDATE " . EVENTS_ATTENDEE_TABLE . " SET payment_status = '{$payment_status}', txn_type = '{$txn_type}', txn_id = '{$txn_id}', payment_date ='{$payment_date}', coupon_code ='{$coupon_code}' WHERE registration_id ='" . $reg_id['registration_id'] . "' ";
                        $wpdb->query($sql);
                    }
                } else {
                    // Update payment status information for all attendees
                    $sql = "UPDATE " . EVENTS_ATTENDEE_TABLE . " SET payment_status = '{$payment_status}', txn_type = '{$txn_type}', txn_id = '{$txn_id}', payment_date ='{$payment_date}', coupon_code ='{$coupon_code}' WHERE registration_id ='" . $registration_id . "' ";
                    $wpdb->query($sql);
                }
                //Send Payment Recieved Email
                if ($_REQUEST['send_payment_rec'] == "send_message") {
                    /*
                     * @todo Do we send an email to each attendee in a group or just the main?
                     */
                    //event_espresso_send_payment_notification( $id );
                    //Added by Imon
                    if (count($registration_ids) > 0) {
                        foreach ($registration_ids as $reg_id) {
                            event_espresso_send_payment_notification(array('registration_id' => $reg_id['registration_id']));
                        }
                    } else {
                        event_espresso_send_payment_notification(array('registration_id' => $registration_id));
                    }
                }
            }
            break;
            //Send Invoice
        //Send Invoice
        case 'send_invoice':
            //Added by Imon
            if ($org_options["use_attendee_pre_approval"] == "Y") {
                $pre_approve = $_REQUEST['pre_approve'];
                if (count($registration_ids) > 0) {
                    foreach ($registration_ids as $reg_id) {
                        $sql = "UPDATE " . EVENTS_ATTENDEE_TABLE . " SET pre_approve = '{$pre_approve}' WHERE registration_id ='" . $reg_id['registration_id'] . "'";
                        $wpdb->query($sql);
                    }
                } else {
                    $sql = "UPDATE " . EVENTS_ATTENDEE_TABLE . " SET pre_approve = '{$pre_approve}' WHERE registration_id ='" . $registration_id . "'";
                    $wpdb->query($sql);
                }
            } else {
                $pre_approve = 0;
            }
            if ($pre_approve == "0") {
                if (count($registration_ids) > 0) {
                    foreach ($registration_ids as $reg_id) {
                        event_espresso_send_invoice($reg_id['registration_id'], $_REQUEST['invoice_subject'], $_REQUEST['invoice_message']);
                    }
                } else {
                    event_espresso_send_invoice($registration_id, $_REQUEST['invoice_subject'], $_REQUEST['invoice_message']);
                }
                echo '<div id="message" class="updated fade"><p><strong>' . __('Invoice Sent', 'event_espresso') . '</strong></p></div>';
            }
            break;
    }
    //Show the forms.
    // $id = $registration_id ;
    $attendees = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . EVENTS_ATTENDEE_TABLE . " WHERE registration_id ='%s' ORDER BY ID LIMIT 1", $registration_id));
    foreach ($attendees as $attendee) {
        $id = $attendee->id;
        //$registration_id = $attendee->registration_id;//Removed by Imon
        $lname = $attendee->lname;
        $fname = $attendee->fname;
        $address = $attendee->address;
        $city = $attendee->city;
        $state = $attendee->state;
        $zip = $attendee->zip;
        $email = $attendee->email;
        $phone = $attendee->phone;
        $date = $attendee->date;
        $payment_status = $attendee->payment_status;
        $txn_type = $attendee->txn_type;
        $txn_id = $attendee->txn_id;
        $amount_pd = $attendee->amount_pd;
        $quantity = $attendee->quantity;
        $payment_date = $attendee->payment_date;
        $event_id = $attendee->event_id;
        $coupon_code = $attendee->coupon_code;
        $pre_approve = $attendee->pre_approve;
        $start_date = $attendee->start_date;
        $event_time = $attendee->event_time;
    }
    $events = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . EVENTS_DETAIL_TABLE . " WHERE id='%d'", $event_id));
    foreach ($events as $event) {
        $event_id = $event->id;
        $event_name = $event->event_name;
        $event_desc = $event->event_desc;
        $event_description = $event->event_desc;
        $event_identifier = $event->event_identifier;
        $cost = isset($event->event_cost) ? $event->event_cost : 0;
        $active = $event->is_active;
    }
    $event_date = event_date_display($start_date . ' ' . $event_time, get_option('date_format') . ' g:i a');
    $total_paid = espresso_attendee_price(array('registration_id' => $_REQUEST['registration_id'], 'session_total' => true));
    if (isset($_REQUEST['status']) && $_REQUEST['status'] == 'saved') {
        ?>

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

        <?php 
        _e('Registered For:', 'event_espresso');
        ?>
         <a href="admin.php?page=events&event_admin_reports=list_attendee_payments&event_id=<?php 
        echo $event_id;
        ?>
"><?php 
        echo stripslashes_deep($event_name);
        ?>
</a> - <?php 
        echo $event_date;
        ?>
</h3>
<?php 
    } else {
        ?>
  <h3>
    <?php 
        echo __('Multiple Registration Payment for ', 'event_espresso');
        ?>
 <a href="admin.php?page=events&event_admin_reports=list_attendee_payments&event_id=<?php 
        echo $event_id;
        ?>
"><?php 
        echo stripslashes_deep($event_name);
        ?>
</a> - <?php 
        echo $event_date;
        ?>
  </h3>
  <?php 
    }
    ?>
  <div class="inside">
    <table width="100%" border="0">
      <tr>
        <td><strong>
          <?php 
    _e('Payment Details', 'event_espresso');
    ?>
          </strong></td>
        <td><strong>
          <?php 
    _e('Invoice/Payment Reminder', 'event_espresso');
    ?>
          </strong></td>
      </tr>
      <tr>
        <td valign="top">
        <?php 
    if (count($registration_ids) > 0) {
        echo '<p><strong>' . __('Registration Ids:', 'event_espresso') . '</strong></p>';
        echo '<ul>';
        foreach ($registration_ids as $reg_id) {
            //TODO:Display cost per registration id. At the moment it is not possible to display price per registration id because discount is calculated for total amount [IMON]
            echo '<li># ' . $reg_id['registration_id'] . ' [ <a href="admin.php?page=events&event_admin_reports=edit_attendee_record&event_id=' . $event_id . '&registration_id=' . $reg_id['registration_id'] . '&form_action=edit_attendee">' . __('View/Edit Registration', 'event_espresso') . '</a> ]</li>';
        }
    } else {
        echo '<p><strong>' . __('Registration Id:', 'event_espresso') . '</strong></p>';
        //TODO:Display cost per registration id. At the moment it is not possible to display price per registration id because discount is calculated for total amount [IMON]
        echo '<p># ' . $registration_id . ' [ <a href="admin.php?page=events&event_admin_reports=edit_attendee_record&event_id=' . $event_id . '&registration_id=' . $registration_id . '&form_action=edit_attendee">' . __('View/Edit Registration', 'event_espresso') . '</a> ]</p>';
    }
    echo '</ul><hr style="width:90%; margin:20px 0;" align="left" />';
    ?>
        <form method="POST" action="<?php 
    echo $_SERVER['REQUEST_URI'];
    ?>
&status=saved" class="espresso_form">
            <fieldset>
              <ul>
                <li>
                <label for="payment_status">
                  <?php 
    _e('Payment Status:', 'event_espresso');
    ?>
                </label>
<?php 
    $values = array(array('id' => '', 'text' => __('None', 'event_espresso')), array('id' => 'Completed', 'text' => __('Completed', 'event_espresso')), array('id' => 'Pending', 'text' => __('Pending', 'event_espresso')), array('id' => 'Payment Declined', 'text' => __('Payment Declined', 'event_espresso')), array('id' => 'Incomplete', 'text' => __('Incomplete', 'event_espresso')));
    echo select_input('payment_status', $values, $payment_status);
    ?>
                </li>
                <li>
                  <label for="txn_type">
                    <?php 
    _e('Transaction Type:', 'event_espresso');
    ?>
                  </label>
                  <?php 
    $txn_values = array(array('id' => '', 'text' => __('N/A', 'event_espresso')), array('id' => 'web_accept', 'text' => espresso_payment_type('web_accept')), array('id' => 'CC', 'text' => __('Credit Card', 'event_espresso')), array('id' => 'INV', 'text' => espresso_payment_type('INV')), array('id' => 'OFFLINE', 'text' => espresso_payment_type('OFFLINE')));
    echo select_input('txn_type', $txn_values, $txn_type);
    ?>
                </li>
                <li>
                  <label>
                    <?php 
    _e('Transaction ID:', 'event_espresso');
    ?>
                  </label>
                  <input type="text" name="txn_id" size="45" value ="<?php 
    echo $txn_id;
    ?>
" />
                </li>
                <li>
                  <label>
                    <?php 
    _e('Amount:', 'event_espresso');
    ?>
                  </label>
                  <?php 
    //TODO:Need to check this after pricing module is done [IMON]
    echo $org_options['currency_symbol'];
    ?>
                    <input style="width:100px;" readonly="true" type="text" name="amount_pd" size="20" value ="<?php 
    echo $total_paid;
    ?>
" /> <?php 
    echo ' [ <a href="admin.php?page=events&event_admin_reports=edit_attendee_record&event_id=' . $event_id . '&registration_id=' . $registration_id . '&form_action=edit_attendee&show_payment=true">' . __('Edit Payment', 'event_espresso') . '</a> ] ';
    ?>
                </li>
                <li>
                  <label>
                    <?php 
    _e('Coupon Code:', 'event_espresso');
    ?>
                    </label>
                  <input type="text" name="coupon_code" size="45" value ="<?php 
    echo $coupon_code;
    ?>
" />
                </li>
                <?php 
    /*?><li>
        <label>
          <?php _e( 'How Many People:', 'event_espresso' ); ?>
        </label>
        <input type="text" name="quantity" size="45" value ="<?php echo espresso_count_attendees_for_registration($id); ?>" />
      </li><?php */
    ?>
                <li>
					<label><?php 
    _e('Date Paid:', 'event_espresso');
    ?>
</label>
					<input type="text" name="payment_date" size="45" value ="<?php 
    echo !empty($payment_date) ? event_date_display($payment_date) : event_date_display($today);
    ?>
" />
                </li>
                <li>
                  <label>
                    <?php 
    _e('Do you want to send a payment recieved notice to registrant?', 'event_espresso');
    ?>
                  </label>
                  <input type="radio" name="send_payment_rec" value="send_message">
                  <?php 
    _e('Yes', 'event_espresso');
    ?>
                  <input type="radio" name="send_payment_rec" checked value="N">
                  <?php 
    _e('No', 'event_espresso');
    ?>
                </li>
                <input type="hidden" name="id" value="<?php 
    echo $id;
    ?>
">
                <input type="hidden" name="registration_id" value="<?php 
    echo $registration_id;
    ?>
">
                <input type="hidden" name="form_action" value="payment">
                <input type="hidden" name="attendee_pay" value="paynow">
                <input type="hidden" name="event_id" value="<?php 
    echo $event_id;
    ?>
">
                <input type="hidden" name="attendee_action" value="post_payment">
                <li>
                  <input type="submit" name="Submit" value="Update Payment">
                </li>
              </ul>
            </fieldset>
          </form></td>
        <td valign="top"><form method='post' action="<?php 
    echo $_SERVER['REQUEST_URI'];
    ?>
&status=invoiced">
            <input type="hidden" name="id" value="<?php 
    echo $id;
    ?>
">
            <input type="hidden" name="form_action" value="send_invoice">
            <input type="hidden" name="event_id" value="<?php 
    echo $event_id;
    ?>
">
            <ul>
              <li>
                <?php 
    _e('Use a ', 'event_espresso');
    ?>
                <a href="admin.php?page=event_emails" target="_blank">
                <?php 
    _e('pre-existing email', 'event_espresso');
    ?>
                </a>? <?php 
    echo espresso_db_dropdown('id', 'email_name', EVENTS_EMAIL_TABLE, 'email_name', '', 'desc') . ' <a class="thickbox" href="#TB_inline?height=300&width=400&inlineId=email_manager_info"><img src="' . EVENT_ESPRESSO_PLUGINFULLURL . '/images/question-frame.png" width="16" height="16" /></a>';
    ?>
 </li>
              <li>
                <?php 
    _e('OR', 'event_espresso');
    ?>
              </li>
              <li>
                <?php 
    _e('Create a custom email:', 'event_espresso');
    ?>
              </li>
              <li>
                <?php 
    _e('Invoice Subject', 'event_espresso');
    ?>
                :
                <input type="text" name="invoice_subject" size="45" value="<?php 
    _e('Payment Reminder for [event]', 'event_espresso');
    ?>
" />
              </li>
              <li>
                <p>
                  <?php 
    _e('Message:', 'event_espresso');
    ?>
                </p>
               
				<div class="postbox">
									 <?php 
    $email_content = __('Dear [fname] [lname], <p>Our records show that we have not received your payment of [cost] for [event_link].</p> <p>Please visit [payment_url] to view your payment options.</p><p>[invoice_link]</p><p>Sincerely,<br />' . ($Organization = $org_options['organization'] . '</p>'), 'event_espresso');
    if (function_exists('wp_editor')) {
        $args = array("textarea_rows" => 5, "textarea_name" => "invoice_message", "editor_class" => "my_editor_custom");
        wp_editor(espresso_admin_format_content($email_content), "invoice_message", $args);
    } else {
        echo '<textarea name="invoice_message" class="theEditor" id="invoice_message">' . espresso_admin_format_content($email_content) . '</textarea>';
        espresso_tiny_mce();
    }
    ?>
										<table id="email-confirmation-form" cellspacing="0">
											<tbody>
												<tr>
													<td class="aer-word-count"></td>
													<td class="autosave-info"><span>&nbsp;</span></td>
												</tr>
											</tbody>
										</table>
										<p><a class="thickbox" href="#TB_inline?height=300&width=400&inlineId=custom_email_info">
														<?php 
    _e('View Custom Email Tags', 'event_espresso');
    ?>
</a> | <a class="thickbox" href="#TB_inline?height=300&width=400&inlineId=custom_email_example">
														<?php 
    _e('Email Example', 'event_espresso');
    ?>
</a></p>
									</div>
									
              </li>
              <?php 
    if ($org_options["use_attendee_pre_approval"] == "Y") {
        $pre_approve = is_attendee_approved($event_id, $id) == true ? 1 : 0;
        ?>
              <li>
                <?php 
        _e("Attendee approved?", "event_espresso");
        ?>
                :
                <?php 
        $pre_approval_values = array(array('id' => '0', 'text' => __('Yes', 'event_espresso')), array('id' => '1', 'text' => __('No', 'event_espresso')));
        echo select_input("pre_approve", $pre_approval_values, $pre_approve);
        ?>
                <br />
                <?php 
        _e("(If not approved then invoice will not be sent.)", "event_espresso");
        ?>
              </li>
              <?php 
    }
    ?>
              <li>
                <input type="submit" name="Submit" value="Send Invoice">
              </li>
            </ul>
          </form></td>
      </tr>
    </table>
    <p> <strong> <a href="admin.php?page=events&event_id=<?php 
    echo $event_id;
    ?>
&event_admin_reports=list_attendee_payments"> &lt;&lt;
      <?php 
    _e('Back to List', 'event_espresso');
    ?>
      </a> </strong> </p>
  </div>
</div>
<?php 
    //This show what tags can be added to a custom email.
    event_espresso_custom_email_info();
    //event_list_attendees();
}
function add_new_attendee($event_id)
{
    if (isset($_REQUEST['regevent_action_admin']) && $_REQUEST['regevent_action_admin'] == 'post_attendee') {
        require_once EVENT_ESPRESSO_PLUGINFULLPATH . "includes/functions/attendee_functions.php";
        require_once EVENT_ESPRESSO_PLUGINFULLPATH . "includes/process-registration/add_attendees_to_db.php";
        $attendee_id = event_espresso_add_attendees_to_db();
        if ($attendee_id) {
            // SEND CONFIRMATION EMAIL MESSAGES
            event_espresso_email_confirmations(array('attendee_id' => $attendee_id, 'send_admin_email' => 'true', 'send_attendee_email' => 'true'));
            //echo $attendee_id;
            ?>
			<div id="message" class="updated fade">
			  <p><strong>
			    <?php 
            _e('Added Attendee to Database', 'event_espresso');
            ?>
			    </strong></p>
			</div>
		<?php 
        } else {
            global $notifications;
            $error_msg = implode($notifications['error'], '<br />');
            ?>
			<div id="message" class="error">
				<p>
					<strong><?php 
            echo $error_msg;
            ?>
</strong>
				</p>
			</div>
			<?php 
        }
    }
    wp_register_script('reCopy', EVENT_ESPRESSO_PLUGINFULLURL . "scripts/reCopy.js", false, '1.1.0');
    wp_print_scripts('reCopy');
    global $wpdb;
    $sql = "SELECT * FROM " . EVENTS_DETAIL_TABLE . " WHERE is_active='Y' AND event_status != 'D' AND id = '" . $event_id . "' LIMIT 0,1";
    //Build the registration page
    if ($wpdb->get_results($sql)) {
        $events = $wpdb->get_results($sql);
        //These are the variables that can be used throughout the regsitration page
        foreach ($events as $event) {
            $event_id = $event->id;
            $event_name = stripslashes($event->event_name);
            $event_desc = stripslashes($event->event_desc);
            $display_desc = $event->display_desc;
            $event_address = $event->address;
            $event_city = $event->city;
            $event_state = $event->state;
            $event_zip = $event->zip;
            $event_description = stripslashes($event->event_desc);
            $event_identifier = $event->event_identifier;
            $event_cost = isset($event->event_cost) ? $event->event_cost : '';
            $member_only = isset($event->member_only) ? $event->member_only : '';
            $reg_limit = isset($event->reg_limit) ? $event->reg_limit : '';
            $allow_multiple = $event->allow_multiple;
            $start_date = $event->start_date;
            $end_date = $event->end_date;
            $reg_limit = $event->reg_limit;
            $additional_limit = $event->additional_limit;
            $is_active = array();
            $question_groups = unserialize($event->question_groups);
            //This function gets the status of the event.
            $is_active = event_espresso_get_is_active($event_id);
            //If the coupon code system is intalled then use it
            if (function_exists('event_espresso_coupon_registration_page')) {
                $use_coupon_code = $event->use_coupon_code;
            }
            //If the groupon code addon is installed, then use it
            if (function_exists('event_espresso_groupon_payment_page')) {
                $use_groupon_code = $event->use_groupon_code;
            }
            //Set a default value for additional limit
            if ($additional_limit == '') {
                $additional_limit = '5';
            }
        }
        //End foreach ($events as $event)
        //This is the start of the registration form. This is where you can start editing your display.
        $num_attendees = get_number_of_attendees_reg_limit($event_id, 'num_attendees');
        //Get the number of attendees
        $available_spaces = get_number_of_attendees_reg_limit($event_id, 'available_spaces');
        //Gets a count of the available spaces
        $number_available_spaces = get_number_of_attendees_reg_limit($event_id, 'number_available_spaces');
        //Gets the number of available spaces
        ?>
<script>$jaer = jQuery.noConflict();
	jQuery(document).ready(function($jaer) {
	jQuery(function(){
		//Registration form validation
		jQuery('#espresso-admin-add-new-attendee-frm').validate();
	});
});

	</script>
<div class="metabox-holder">
  <div class="postbox">
    <div id="espresso-admin-add-new-attendee-dv">

        <form method="post" action="<?php 
        echo $_SERVER['REQUEST_URI'];
        ?>
" onsubmit="return validateForm(this)"  id="registration_form" class="espresso_form">
			<?php 
        wp_nonce_field('reg_nonce', 'reg_form_nonce');
        ?>
          <h3 class="h3_event_title" id="h3_event_title-<?php 
        echo $event_id;
        ?>
"><?php 
        echo $event_name;
        ?>
</h3>
           <div  class="padding">
     	     <div  class="inside">
				<fieldset>
		 		<h4 class="reg-quest-title section-title"><?php 
        _e('Event Dates and Times', 'event_espresso');
        ?>
</h4>
					<p class="start_date">
						<span class="span_event_date_label"><?php 
        _e('Start Date:', 'event_espresso');
        ?>
</span><span class="span_event_date_value"><?php 
        echo event_date_display($start_date);
        ?>
</span>
					</p>
		          	<p class="event_time">
		            <?php 
        $time_selected = '';
        //This block of code is used to display the times of an event in either a dropdown or text format.
        if (!empty($time_selected) && $time_selected == true) {
            //If the customer is coming from a page where the time was preselected.
            echo event_espresso_display_selected_time($time_id);
            //Optional parameters start, end, default
        } else {
            if ($time_selected == false) {
                echo event_espresso_time_dropdown($event_id);
            }
        }
        //End time selected
        ?>
	          		</p>
	          		<?php 
        // Added for seating chart addon
        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);
        ?>
				</fieldset>
			  <?php 
        echo event_espresso_add_question_groups($question_groups, '', null, 0, array('admin_only' => true), 'inline');
        //Coupons
        if (function_exists('event_espresso_coupon_registration_page')) {
            echo event_espresso_coupon_registration_page($use_coupon_code, $event_id);
        }
        //End coupons display
        //Groupons
        if (function_exists('event_espresso_groupon_registration_page')) {
            echo event_espresso_groupon_registration_page($use_groupon_code, $event_id);
        }
        //End groupons display
        ?>


	          <p class="event_form_field">
	            <label for="event_cost" class="inline">
	              <?php 
        _e('Amount Paid:', 'event_espresso');
        ?>
	            </label>
	            <input tabindex="9" type="text" maxlength="10" size="15" name="event_cost" id="event_cost-<?php 
        echo $event_id;
        ?>
" <?php 
        echo $event_cost ? 'value="' . $event_cost . '"' : "";
        ?>
 />
	            <input type="hidden" name="regevent_action_admin" id="regevent_action-<?php 
        echo $event_id;
        ?>
" value="post_attendee" />
	            <input type="hidden" name="event_id" id="event_id-<?php 
        echo $event_id;
        ?>
" value="<?php 
        echo $event_id;
        ?>
" />
	            <input type="hidden" name="admin" value="true" />
	          </p>
			 
			<?php 
        echo event_espresso_additional_attendees($event_id, $additional_limit, $number_available_spaces, __('Number of Tickets', 'event_espresso'), true, 'admin', 'inline');
        ?>
			
	          <p class="event_form_submit" id="event_form_submit-<?php 
        echo $event_id;
        ?>
">
	            <input class="btn_event_form_submit button-primary" id="event_form_field-<?php 
        echo $event_id;
        ?>
" type="submit" name="Submit" value="<?php 
        _e('Submit', 'event_espresso');
        ?>
" />
	          </p>
	      </div>
	      </div>
        </form>
      </div>
    </div>
  </div>
<?php 
        event_list_attendees();
    }
    //End Build the registration page
}
function update_event($recurrence_arr = array())
{
    //print_r($_REQUEST);
    global $wpdb, $org_options, $current_user, $espresso_premium;
    //Security check using nonce
    if (empty($_POST['nonce_verify_update_event']) || !wp_verify_nonce($_POST['nonce_verify_update_event'], 'espresso_verify_update_event_nonce')) {
        if ($recurrence_arr['bypass_nonce'] == FALSE) {
            print '<h3 class="error">' . __('Sorry, there was a security error and your event was not updated.', 'event_espresso') . '</h3>';
            return;
        }
    }
    $wpdb->show_errors();
    /*
     * Begin Recurrence handling
     *
     * Will clean up in V 1.2.0
     *
     */
    if (defined('EVENT_ESPRESSO_RECURRENCE_TABLE')) {
        require_once EVENT_ESPRESSO_RECURRENCE_FULL_PATH . "functions/re_functions.php";
        if ($_POST['recurrence_id'] > 0) {
            /*
             * If the array is empty, then find the recurring dates
             */
            if (count($recurrence_arr) == 0) {
                // Prepare the parameters array for use with various RE functions
                $re_params = array('start_date' => !empty($_POST['recurrence_start_date']) ? sanitize_text_field($_POST['recurrence_start_date']) : '', 'event_end_date' => !empty($_POST['recurrence_event_end_date']) ? sanitize_text_field($_POST['recurrence_event_end_date']) : '', 'end_date' => !empty($_POST['recurrence_end_date']) ? sanitize_text_field($_POST['recurrence_end_date']) : '', 'registration_start' => !empty($_POST['recurrence_regis_start_date']) ? sanitize_text_field($_POST['recurrence_regis_start_date']) : '', 'registration_end' => !empty($_POST['recurrence_regis_end_date']) ? sanitize_text_field($_POST['recurrence_regis_end_date']) : '', 'frequency' => !empty($_POST['recurrence_frequency']) ? sanitize_text_field($_POST['recurrence_frequency']) : '', 'interval' => !empty($_POST['recurrence_interval']) ? sanitize_text_field($_POST['recurrence_interval']) : '', 'recurrence_type' => !empty($_POST['recurrence_type']) ? sanitize_text_field($_POST['recurrence_type']) : '', 'weekdays' => !empty($_POST['recurrence_weekday']) ? $_POST['recurrence_weekday'] : '', 'repeat_by' => !empty($_POST['recurrence_repeat_by']) ? $_POST['recurrence_repeat_by'] : '', 'recurrence_manual_dates' => !empty($_POST['recurrence_manual_dates']) ? $_POST['recurrence_manual_dates'] : '', 'recurrence_manual_end_dates' => !empty($_POST['recurrence_manual_end_dates']) ? $_POST['recurrence_manual_end_dates'] : '', 'recurrence_id' => !empty($_POST['recurrence_id']) ? $_POST['recurrence_id'] : '', 'recurrence_regis_date_increment' => !empty($_POST['recurrence_regis_date_increment']) ? $_POST['recurrence_regis_date_increment'] : '');
                //$re_params['adding_to_db'] = 'Y';
                //Has the form been modified
                $recurrence_form_modified = recurrence_form_modified($re_params);
                //echo ($recurrence_form_modified) ? "Yes" : 'No';
                if ($_POST['recurrence_apply_changes_to'] == 2) {
                    //Update all events in the series based on recurrence id
                    $recurrence_dates = $_POST['recurrence_type'] == 'm' ? find_recurrence_manual_dates($re_params) : find_recurrence_dates($re_params);
                    $UPDATE_SQL = "SELECT id,start_date,event_identifier FROM " . EVENTS_DETAIL_TABLE . " WHERE recurrence_id = %d AND NOT event_status = 'D'";
                } else {
                    //Update this and upcoming events based on recurrence id and start_date >=start_date
                    $re_params['start_date'] = sanitize_text_field($_POST['start_date']);
                    $recurrence_dates = find_recurrence_dates($re_params);
                    $UPDATE_SQL = "SELECT id,start_date,event_identifier FROM " . EVENTS_DETAIL_TABLE . " WHERE start_date >='" . sanitize_text_field($_POST['start_date']) . "' AND recurrence_id = %d and NOT event_status = 'D' ";
                }
                //Recurrence Form modified and changes need to apply to all
                if ($recurrence_form_modified && $_POST['recurrence_apply_changes_to'] > 1) {
                    //Update the recurrence table record with the new RE selections
                    update_recurrence_master_record();
                    /*
                     * Delete the records that don't belong in the formula
                     */
                    if (count($recurrence_dates) > 0) {
                        $delete_in = '';
                        foreach ($recurrence_dates as $k => $v) {
                            $delete_in .= "'" . $k . "',";
                        }
                        $delete_in = substr($delete_in, 0, -1);
                    }
                    if ($_POST['recurrence_apply_changes_to'] == 2) {
                        //Update all events in the series based on recurrence id
                        //$DEL_SQL = 'UPDATE ' . EVENTS_DETAIL_TABLE . " SET event_status = 'D' WHERE start_date NOT IN (" . $delete_in . ") AND recurrence_id = " . $_POST['recurrence_id'];
                        $DEL_SQL = 'DELETE EDT, EAT FROM ' . EVENTS_DETAIL_TABLE . " EDT\n                            LEFT JOIN " . EVENTS_ATTENDEE_TABLE . " EAT\n                                ON EDT.id = EAT.event_id\n                            WHERE EAT.id IS NULL\n                            AND EDT.start_date NOT IN (" . $delete_in . ")\n                            AND recurrence_id = " . sanitize_text_field($_POST['recurrence_id']);
                        $UPDATE_SQL = "SELECT id,start_date,event_identifier FROM " . EVENTS_DETAIL_TABLE . " WHERE recurrence_id = %d and NOT event_status = 'D' ORDER BY start_date";
                    } else {
                        $DEL_SQL = 'DELETE EDT, EAT FROM ' . EVENTS_DETAIL_TABLE . " EDT\n                            LEFT JOIN " . EVENTS_ATTENDEE_TABLE . " EAT\n                                ON EDT.id = EAT.event_id\n                            WHERE EAT.id IS NULL\n                            AND EDT.start_date >='" . esc_sql(sanitize_text_field($_POST['start_date'])) . "'\n                            AND EDT.start_date NOT IN (" . $delete_in . ")\n                            AND recurrence_id = " . $_POST['recurrence_id'];
                        $UPDATE_SQL = "SELECT id,start_date,event_identifier FROM " . EVENTS_DETAIL_TABLE . " WHERE start_date >='" . sanitize_text_field($_POST['start_date']) . "' AND recurrence_id = %d AND NOT event_status = 'D'  ORDER BY start_date";
                    }
                    if ($delete_in != '') {
                        $wpdb->query($wpdb->prepare($DEL_SQL, NULL));
                    }
                    /*
                     * Add the new records based on the new formula
                     * The $recurrence_dates array will contain the new dates
                     */
                    if (!function_exists('add_event_to_db')) {
                        require_once 'insert_event.php';
                    }
                    foreach ($recurrence_dates as $k => $v) {
                        $result = $wpdb->get_row($wpdb->prepare("SELECT ID FROM " . EVENTS_DETAIL_TABLE . " WHERE recurrence_id = %d and start_date = %s and NOT event_status = 'D'", array($_POST['recurrence_id'], $k)));
                        if ($wpdb->num_rows == 0) {
                            add_event_to_db(array('recurrence_id' => sanitize_text_field($_POST['recurrence_id']), 'recurrence_start_date' => $v['start_date'], 'recurrence_event_end_date' => $v['event_end_date'], 'recurrence_end_date' => $v['start_date'], 'registration_start' => $v['registration_start'], 'registration_end' => $v['registration_end'], 'bypass_nonce' => TRUE));
                        } else {
                        }
                    }
                    /*
                     * Find all the event ids in the series and feed into the $recurrence_dates array
                     * This array will be used at the end of this document to invoke the recursion of update_event function so all the events in the series
                     * can be updated with the information.
                     */
                }
                $result = $wpdb->get_results($wpdb->prepare($UPDATE_SQL, array(sanitize_text_field($_POST['recurrence_id']))));
                foreach ($result as $row) {
                    if ($row->start_date != '') {
                        $recurrence_dates[$row->start_date]['event_id'] = $row->id;
                        $recurrence_dates[$row->start_date]['event_identifier'] = $row->event_identifier;
                    }
                }
            }
        }
    }
    //  echo_f('rd',$recurrence_dates);
    if (defined('EVENT_ESPRESSO_RECURRENCE_MODULE_ACTIVE') && !empty($_POST['recurrence']) && $_POST['recurrence'] == 'Y' && count($recurrence_arr) == 0 && $_POST['recurrence_apply_changes_to'] > 1) {
        //skip the first update
    } else {
        //Filters the event description based on user level
        $user_access = apply_filters('filter_hook_espresso_event_unfiltered_description', current_user_can('administrator'));
        $_REQUEST['event_desc'] = is_admin() || $user_access ? $_REQUEST['event_desc'] : apply_filters('filter_hook_espresso_event_wp_kses_post_description', wp_kses_post($_REQUEST['event_desc']));
        $event_meta = array();
        //will be used to hold event meta data
        $event_id = array_key_exists('event_id', $recurrence_arr) ? $recurrence_arr['event_id'] : (int) $_REQUEST['event_id'];
        $event_name = sanitize_text_field($_REQUEST['event']);
        $event_desc = !empty($_REQUEST['event_desc']) ? $_REQUEST['event_desc'] : '';
        $display_desc = sanitize_text_field($_REQUEST['display_desc']);
        $display_reg_form = sanitize_text_field($_REQUEST['display_reg_form']);
        $externalURL = !empty($_REQUEST['externalURL']) ? esc_html($_REQUEST['externalURL']) : '';
        $reg_limit = (int) $_REQUEST['reg_limit'];
        $allow_multiple = $_REQUEST['allow_multiple'];
        $overflow_event_id = empty($_REQUEST['overflow_event_id']) ? '0' : (int) $_REQUEST['overflow_event_id'];
        $allow_overflow = empty($_REQUEST['allow_overflow']) ? 'N' : sanitize_text_field($_REQUEST['allow_overflow']);
        $additional_limit = !empty($_REQUEST['additional_limit']) && $_REQUEST['additional_limit'] > 0 ? (int) $_REQUEST['additional_limit'] : '5';
        $member_only = empty($_REQUEST['member_only']) ? 'N' : sanitize_text_field($_REQUEST['member_only']);
        $is_active = !empty($_REQUEST['is_active']) ? sanitize_text_field($_REQUEST['is_active']) : 'Y';
        $event_status = !empty($_REQUEST['event_status']) ? sanitize_text_field($_REQUEST['event_status']) : 'A';
        //Get the first instance of the start and end times
        $start_time = sanitize_text_field($_REQUEST['start_time'][0]);
        $end_time = sanitize_text_field($_REQUEST['end_time'][0]);
        // Add registration times
        $registration_startT = event_date_display(sanitize_text_field($_REQUEST['registration_startT']), 'H:i');
        $registration_endT = event_date_display(sanitize_text_field($_REQUEST['registration_endT']), 'H:i');
        //Add timezone
        $timezone_string = empty($_REQUEST['timezone_string']) ? '' : sanitize_text_field($_REQUEST['timezone_string']);
        //Early discounts
        $early_disc = !empty($_REQUEST['early_disc']) ? sanitize_text_field($_REQUEST['early_disc']) : '';
        $early_disc_date = !empty($_REQUEST['early_disc_date']) ? sanitize_text_field($_REQUEST['early_disc_date']) : '';
        $early_disc_percentage = !empty($_REQUEST['early_disc_percentage']) ? sanitize_text_field($_REQUEST['early_disc_percentage']) : '';
        $conf_mail = esc_html($_REQUEST['conf_mail']);
        $use_coupon_code = !empty($_REQUEST['use_coupon_code']) ? sanitize_text_field($_REQUEST['use_coupon_code']) : '';
        $alt_email = isset($_REQUEST['alt_email']) && !empty($_REQUEST['alt_email']) ? sanitize_text_field($_REQUEST['alt_email']) : '';
        $send_mail = sanitize_text_field($_REQUEST['send_mail']);
        $email_id = isset($_REQUEST['email_name']) ? (int) $_REQUEST['email_name'] : '0';
        $ticket_id = isset($_REQUEST['ticket_id']) ? (int) $_REQUEST['ticket_id'] : '0';
        $event_category = empty($_REQUEST['event_category']) ? '' : serialize(sanitize_text_field($_REQUEST['event_category']));
        $event_discount = empty($_REQUEST['event_discount']) ? '' : serialize(sanitize_text_field($_REQUEST['event_discount']));
        $registration_start = array_key_exists('registration_start', $recurrence_arr) ? $recurrence_arr['registration_start'] : sanitize_text_field($_REQUEST['registration_start']);
        $registration_end = array_key_exists('registration_end', $recurrence_arr) ? $recurrence_arr['registration_end'] : sanitize_text_field($_REQUEST['registration_end']);
        $start_date = array_key_exists('recurrence_start_date', $recurrence_arr) ? $recurrence_arr['recurrence_start_date'] : (empty($_REQUEST['start_date']) ? $_REQUEST['recurrence_start_date'] : sanitize_text_field($_REQUEST['start_date']));
        $end_date = array_key_exists('recurrence_event_end_date', $recurrence_arr) ? $recurrence_arr['recurrence_event_end_date'] : (empty($_REQUEST['end_date']) ? sanitize_text_field($_REQUEST['recurrence_start_date']) : sanitize_text_field($_REQUEST['end_date']));
        $question_groups = serialize($_REQUEST['question_groups']);
        $add_attendee_question_groups = empty($_REQUEST['add_attendee_question_groups']) ? '' : $_REQUEST['add_attendee_question_groups'];
        //Venue Information
        $venue_title = isset($_REQUEST['venue_title']) ? sanitize_text_field($_REQUEST['venue_title']) : '';
        $venue_url = isset($_REQUEST['venue_url']) ? sanitize_text_field($_REQUEST['venue_url']) : '';
        $venue_phone = isset($_REQUEST['venue_phone']) ? sanitize_text_field($_REQUEST['venue_phone']) : '';
        $venue_image = isset($_REQUEST['venue_image']) ? sanitize_text_field($_REQUEST['venue_image']) : '';
        //Virtual location
        $virtual_url = isset($_REQUEST['virtual_url']) ? sanitize_text_field($_REQUEST['virtual_url']) : '';
        $virtual_phone = isset($_REQUEST['virtual_phone']) ? sanitize_text_field($_REQUEST['virtual_phone']) : '';
        //Address/venue information
        $address = !empty($_REQUEST['address']) ? sanitize_text_field($_REQUEST['address']) : '';
        $address2 = !empty($_REQUEST['address2']) ? sanitize_text_field($_REQUEST['address2']) : '';
        $city = !empty($_REQUEST['city']) ? sanitize_text_field($_REQUEST['city']) : '';
        $state = !empty($_REQUEST['state']) ? sanitize_text_field($_REQUEST['state']) : '';
        $zip = !empty($_REQUEST['zip']) ? sanitize_text_field($_REQUEST['zip']) : '';
        $country = !empty($_REQUEST['country']) ? sanitize_text_field($_REQUEST['country']) : '';
        $phone = !empty($_REQUEST['phone']) ? sanitize_text_field($_REQUEST['phone']) : '';
        $event_location = '';
        if (!empty($address)) {
            $event_location .= $address . ' ';
        }
        if (!empty($address2)) {
            $event_location .= '<br />' . $address2;
        }
        if (!empty($city)) {
            $event_location .= '<br />' . $city;
        }
        if (!empty($state)) {
            $event_location .= ', ' . $state;
        }
        if (!empty($zip)) {
            $event_location .= ', ' . $state;
        }
        if (!empty($country)) {
            $event_location .= '<br />' . $country;
        }
        if (isset($reg_limit) && empty($reg_limit)) {
            $reg_limit = 999999;
        }
        $event_meta['default_payment_status'] = !empty($_REQUEST['default_payment_status']) ? sanitize_text_field($_REQUEST['default_payment_status']) : '';
        $event_meta['venue_id'] = empty($_REQUEST['venue_id']) ? '' : (int) $_REQUEST['venue_id'][0];
        $event_meta['additional_attendee_reg_info'] = !empty($_REQUEST['additional_attendee_reg_info']) ? sanitize_text_field($_REQUEST['additional_attendee_reg_info']) : '';
        $event_meta['add_attendee_question_groups'] = $add_attendee_question_groups;
        $event_meta['date_submitted'] = sanitize_text_field($_REQUEST['date_submitted']);
        //Added for seating chart addon
        if (isset($_REQUEST['seating_chart_id'])) {
            $cls_seating_chart = new seating_chart();
            $seating_chart_result = $cls_seating_chart->associate_event_seating_chart((int) $_REQUEST['seating_chart_id'], $event_id);
            $tmp_seating_chart_id = (int) $_REQUEST['seating_chart_id'];
            if ($tmp_seating_chart_id > 0) {
                if ($seating_chart_result === false) {
                    $tmp_seating_chart_row = $wpdb->get_row($wpdb->prepare("select seating_chart_id from " . EVENTS_SEATING_CHART_EVENT_TABLE . " where event_id = {$event_id}", NULL));
                    if ($tmp_seating_chart_row !== NULL) {
                        $tmp_seating_chart_id = $tmp_seating_chart_row->seating_chart_id;
                    } else {
                        $tmp_seating_chart_id = 0;
                    }
                }
                if ($_REQUEST['allow_multiple'] == 'Y' && isset($_REQUEST['seating_chart_id']) && $tmp_seating_chart_id > 0) {
                    $event_meta['additional_attendee_reg_info'] = 3;
                }
            }
        }
        //Process thumbnail image
        $event_thumbnail_url = '';
        if (isset($_REQUEST['upload_image']) && !empty($_REQUEST['upload_image'])) {
            $event_meta['event_thumbnail_url'] = sanitize_text_field($_REQUEST['upload_image']);
            $event_thumbnail_url = sanitize_text_field($event_meta['event_thumbnail_url']);
        }
        if (!empty($_REQUEST['emeta'])) {
            foreach ($_REQUEST['emeta'] as $k => $v) {
                $event_meta[$v] = sanitize_text_field($_REQUEST['emetad'][$k]);
            }
        }
        //Filter to update the event meta as needed
        $event_meta = apply_filters('filter_hook_espresso_update_event_update_meta', $event_meta, $event_id);
        //print_r($_REQUEST['emeta'] );
        $event_meta = serialize($event_meta);
        ############ Added by wp-developers ######################
        $require_pre_approval = 0;
        if (isset($_REQUEST['require_pre_approval'])) {
            $require_pre_approval = sanitize_text_field($_REQUEST['require_pre_approval']);
        }
        ################# END #################
        //When adding colums to the following arrays, be sure both arrays have equal values.
        $sql = array('event_name' => $event_name, 'event_desc' => $event_desc, 'display_desc' => $display_desc, 'display_reg_form' => $display_reg_form, 'address' => $address, 'address2' => $address2, 'city' => $city, 'state' => $state, 'zip' => $zip, 'country' => $country, 'phone' => $phone, 'virtual_url' => $virtual_url, 'virtual_phone' => $virtual_phone, 'venue_title' => $venue_title, 'venue_url' => $venue_url, 'venue_phone' => $venue_phone, 'venue_image' => $venue_image, 'registration_start' => $registration_start, 'registration_end' => $registration_end, 'start_date' => $start_date, 'end_date' => $end_date, 'allow_multiple' => $allow_multiple, 'send_mail' => $send_mail, 'is_active' => $is_active, 'event_status' => $event_status, 'conf_mail' => $conf_mail, 'use_coupon_code' => $use_coupon_code, 'member_only' => $member_only, 'externalURL' => $externalURL, 'early_disc' => $early_disc, 'early_disc_date' => $early_disc_date, 'early_disc_percentage' => $early_disc_percentage, 'alt_email' => $alt_email, 'question_groups' => $question_groups, 'allow_overflow' => $allow_overflow, 'overflow_event_id' => $overflow_event_id, 'additional_limit' => $additional_limit, 'reg_limit' => $reg_limit, 'email_id' => $email_id, 'registration_startT' => $registration_startT, 'registration_endT' => $registration_endT, 'event_meta' => $event_meta, 'require_pre_approval' => $require_pre_approval, 'timezone_string' => $timezone_string, 'ticket_id' => $ticket_id);
        $sql_data = array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%d', '%d', '%s', '%s', '%s', '%s', '%s', '%d');
        $update_id = array('id' => $event_id);
        /* echo 'Debug: <br />';
           print_r($sql);
           echo '<br />';
           print 'Number of vars: ' . count ($sql);
           echo '<br />';
           print 'Number of cols: ' . count($sql_data); */
        if (function_exists('event_espresso_add_event_to_db_groupon')) {
            $sql = event_espresso_add_event_to_db_groupon($sql, $_REQUEST['use_groupon_code']);
            ///print count ($sql);
            $sql_data = array_merge((array) $sql_data, (array) '%s');
            //print count($sql_data);
            $wpdb->update(EVENTS_DETAIL_TABLE, $sql, $update_id, $sql_data, array('%d'));
            /* echo 'Debug: <br />';
               print 'Number of vars: ' . count ($sql);
               echo '<br />';
               print 'Number of cols: ' . count($sql_data); */
        } else {
            $wpdb->update(EVENTS_DETAIL_TABLE, $sql, $update_id, $sql_data, array('%d'));
            /* echo 'Debug: <br />';
               print 'Number of vars: ' . count ($sql);
               echo '<br />';
               print 'Number of cols: ' . count($sql_data); */
        }
        //print $wpdb->print_error();
        //BEGIN CATEGORY MODIFICATION
        //We first delete the previous entry then we get the category id's of the event and put them in events_detail_table.category_id as a well-formatted string (id,n id)
        $del_cats = "DELETE FROM " . EVENTS_CATEGORY_REL_TABLE . " WHERE event_id = '" . $event_id . "'";
        $wpdb->query($wpdb->prepare($del_cats, NULL));
        $update_event_detail_category_id = "UPDATE " . EVENTS_DETAIL_TABLE . " SET category_id = NULL WHERE id='" . $event_id . "'";
        $wpdb->query($wpdb->prepare($update_event_detail_category_id, NULL));
        $string_cat = '';
        if (!empty($_REQUEST['event_category'])) {
            foreach ($_REQUEST['event_category'] as $k => $v) {
                if (!empty($v)) {
                    $sql_cat = "INSERT INTO " . EVENTS_CATEGORY_REL_TABLE . " (event_id, cat_id) VALUES ('" . $event_id . "', '" . (int) $v . "')";
                    $wpdb->query($wpdb->prepare($sql_cat, array()));
                    $string_cat .= sanitize_text_field($v) . ",";
                }
            }
            if (!empty($string_cat) && $string_cat != ",") {
                $cleaned_string_cat = substr($string_cat, 0, -1);
                $tmp = explode(",", $cleaned_string_cat);
                sort($tmp);
                $cleaned_string_cat = implode(",", $tmp);
                trim($cleaned_string_cat);
                $sql_update_event_detail_category_id = "UPDATE " . EVENTS_DETAIL_TABLE . " SET category_id = '" . $cleaned_string_cat . "' WHERE id='" . $event_id . "'";
                $wpdb->query($wpdb->prepare($sql_update_event_detail_category_id, NULL));
            }
        }
        //END CATEGORY MODIFICATION
        //Staff
        $update_all_staff = FALSE;
        if (isset($_POST['rem_apply_to_all_staff']) && $_POST['recurrence_apply_changes_to'] == 2) {
            $update_all_staff = TRUE;
        }
        if ($_POST['event_id'] == $event_id || $update_all_staff == TRUE) {
            $del_ppl = "DELETE FROM " . EVENTS_PERSONNEL_REL_TABLE . " WHERE event_id = '" . $event_id . "'";
            $wpdb->query($wpdb->prepare($del_ppl, NULL));
            if (!empty($_REQUEST['event_person'])) {
                foreach ($_REQUEST['event_person'] as $k => $v) {
                    if (!empty($v)) {
                        $sql_ppl = "INSERT INTO " . EVENTS_PERSONNEL_REL_TABLE . " (event_id, person_id) VALUES ('" . $event_id . "', '" . (int) $v . "')";
                        $wpdb->query($wpdb->prepare($sql_ppl, array()));
                    }
                }
            }
        }
        //Venues
        $del_venues = "DELETE FROM " . EVENTS_VENUE_REL_TABLE . " WHERE event_id = '" . $event_id . "'";
        $wpdb->query($wpdb->prepare($del_venues, NULL));
        if (!empty($_REQUEST['venue_id'])) {
            foreach ($_REQUEST['venue_id'] as $k => $v) {
                if (!empty($v) && $v != 0) {
                    $sql_venues = "INSERT INTO " . EVENTS_VENUE_REL_TABLE . " (event_id, venue_id) VALUES ('" . $event_id . "', '" . (int) $v . "')";
                    $wpdb->query($wpdb->prepare($sql_venues, array()));
                }
            }
        }
        //Discounts
        $del_discounts = "DELETE FROM " . EVENTS_DISCOUNT_REL_TABLE . " WHERE event_id = '" . $event_id . "'";
        $wpdb->query($wpdb->prepare($del_discounts, NULL));
        if (!empty($_REQUEST['event_discount']) && $_REQUEST['use_coupon_code'] == 'Y') {
            //only re-add the coupon codes if they've specified to use all global coupon codes
            //and 'specific' coupon codes
            foreach ($_REQUEST['event_discount'] as $k => $v) {
                if (!empty($v)) {
                    $sql_discount = "INSERT INTO " . EVENTS_DISCOUNT_REL_TABLE . " (event_id, discount_id) VALUES ('" . $event_id . "', '" . (int) $v . "')";
                    $wpdb->query($wpdb->prepare($sql_discount, array()));
                }
            }
        }
        $del_times = "DELETE FROM " . EVENTS_START_END_TABLE . " WHERE event_id = '" . $event_id . "'";
        $wpdb->query($wpdb->prepare($del_times, NULL));
        if (!empty($_REQUEST['start_time'])) {
            foreach ($_REQUEST['start_time'] as $k => $v) {
                if (!empty($v)) {
                    $time_qty = empty($_REQUEST['time_qty'][$k]) ? '0' : "'" . (int) $_REQUEST['time_qty'][$k] . "'";
                    $sql_times = "INSERT INTO " . EVENTS_START_END_TABLE . " (event_id, start_time, end_time, reg_limit) VALUES ('" . $event_id . "', '" . event_date_display(sanitize_text_field($v), 'H:i') . "', '" . event_date_display(sanitize_text_field($_REQUEST['end_time'][$k]), 'H:i') . "', " . $time_qty . ")";
                    $wpdb->query($wpdb->prepare($sql_times, array()));
                }
            }
        }
        $del_prices = "DELETE FROM " . EVENTS_PRICES_TABLE . " WHERE event_id = '" . $event_id . "'";
        $wpdb->query($wpdb->prepare($del_prices, NULL));
        if (!empty($_REQUEST['event_cost'])) {
            foreach ($_REQUEST['event_cost'] as $k => $v) {
                if (!empty($v)) {
                    $v = (double) preg_replace('/[^0-9\\.]/ui', '', $v);
                    //Removes non-integer characters
                    $price_type = $_REQUEST['price_type'][$k] != '' ? sanitize_text_field(stripslashes_deep($_REQUEST['price_type'][$k])) : __('General Admission', 'event_espresso');
                    $member_price_type = !empty($_REQUEST['member_price_type'][$k]) ? sanitize_text_field(stripslashes_deep($_REQUEST['member_price_type'][$k])) : __('Members Admission', 'event_espresso');
                    $member_price = !empty($_REQUEST['member_price'][$k]) ? (double) $_REQUEST['member_price'][$k] : $v;
                    $sql_price = array('event_id' => $event_id, 'event_cost' => $v, 'surcharge' => sanitize_text_field($_REQUEST['surcharge'][$k]), 'surcharge_type' => sanitize_text_field($_REQUEST['surcharge_type'][$k]), 'price_type' => $price_type, 'member_price' => $member_price, 'member_price_type' => $member_price_type);
                    $sql_price_data = array('%d', '%s', '%s', '%s', '%s', '%s', '%s');
                    if (!$wpdb->insert(EVENTS_PRICES_TABLE, $sql_price, $sql_price_data)) {
                        $error = true;
                    }
                }
            }
        } else {
            $sql_price = "INSERT INTO " . EVENTS_PRICES_TABLE . " (event_id, event_cost, surcharge, price_type, member_price, member_price_type) VALUES ('" . $event_id . "', '0.00', '0.00', '" . __('Free', 'event_espresso') . "', '0.00', '" . __('Free', 'event_espresso') . "')";
            if (!$wpdb->query($wpdb->prepare($sql_price, array()))) {
                $error = true;
            }
        }
        ############# MailChimp Integration ###############
        if (defined('EVENTS_MAILCHIMP_ATTENDEE_REL_TABLE') && $espresso_premium == true) {
            MailChimpController::update_event_list_rel($event_id);
        }
        // Create Event Post Code Here
        if (isset($_REQUEST['create_post'])) {
            switch ($_REQUEST['create_post']) {
                case 'N':
                    $sql = " SELECT * FROM " . EVENTS_DETAIL_TABLE;
                    $sql .= " WHERE id = '" . $event_id . "' ";
                    $wpdb->get_results($wpdb->prepare($sql, NULL));
                    $post_id = $wpdb->last_result[0]->post_id;
                    if ($wpdb->num_rows > 0 && !empty($_REQUEST['delete_post']) && $_REQUEST['delete_post'] == 'Y') {
                        $sql = array('post_id' => '', 'post_type' => '');
                        $sql_data = array('%d', '%s');
                        $update_id = array('id' => $event_id);
                        $wpdb->update(EVENTS_DETAIL_TABLE, $sql, $update_id, $sql_data, array('%d'));
                        wp_delete_post($post_id, 'true');
                    }
                    break;
                case 'Y':
                    $post_type = $_REQUEST['espresso_post_type'];
                    if ($post_type == 'post') {
                        if (file_exists(EVENT_ESPRESSO_TEMPLATE_DIR . "event_post.php") || file_exists(EVENT_ESPRESSO_PLUGINFULLPATH . "templates/event_post.php")) {
                            // Load message from template into message post variable
                            ob_start();
                            if (file_exists(EVENT_ESPRESSO_TEMPLATE_DIR . "event_post.php")) {
                                require_once EVENT_ESPRESSO_TEMPLATE_DIR . "event_post.php";
                            } else {
                                require_once EVENT_ESPRESSO_PLUGINFULLPATH . "templates/event_post.php";
                            }
                            $post_content = ob_get_contents();
                            ob_end_clean();
                        } else {
                            _e('There was error finding a post template. Please verify your post templates are available.', 'event_espresso');
                        }
                    } elseif ($post_type == 'espresso_event') {
                        ob_start();
                        echo $event_desc;
                        $post_content = ob_get_contents();
                        ob_end_clean();
                        // if there's a cart link shortcode in the post, replace the shortcode with one that includes the event_id
                        if (preg_match("/ESPRESSO_CART_LINK/", $post_content)) {
                            $post_content = preg_replace('/ESPRESSO_CART_LINK/', 'ESPRESSO_CART_LINK event_id=' . $event_id, $post_content);
                        }
                    }
                    $my_post = array();
                    $sql = " SELECT * FROM " . EVENTS_DETAIL_TABLE;
                    $sql .= " WHERE id = '" . $event_id . "' ";
                    $wpdb->get_results($wpdb->prepare($sql, NULL));
                    $post_id = $wpdb->last_result[0]->post_id;
                    $post_type = $_REQUEST['espresso_post_type'];
                    if ($post_id > 0) {
                        $my_post['ID'] = $post_id;
                    }
                    $my_post['post_title'] = sanitize_text_field($_REQUEST['event']);
                    $my_post['post_content'] = $post_content;
                    $my_post['post_status'] = 'publish';
                    $my_post['post_author'] = !empty($_REQUEST['user']) ? (int) $_REQUEST['user'] : '';
                    $my_post['post_category'] = !empty($_REQUEST['post_category']) ? $_REQUEST['post_category'] : '';
                    $my_post['tags_input'] = !empty($_REQUEST['post_tags']) ? $_REQUEST['post_tags'] : '';
                    $my_post['post_type'] = !empty($post_type) ? $post_type : 'post';
                    //print_r($my_post);
                    // Insert the post into the database
                    if ($post_id > 0) {
                        $post_id = wp_update_post($my_post);
                        update_post_meta($post_id, 'event_id', $event_id);
                        update_post_meta($post_id, 'event_meta', $event_meta);
                        update_post_meta($post_id, 'event_identifier', $event_identifier);
                        update_post_meta($post_id, 'event_start_date', $start_date);
                        update_post_meta($post_id, 'event_end_date', $end_date);
                        update_post_meta($post_id, 'event_location', $event_location);
                        update_post_meta($post_id, 'event_thumbnail_url', $event_thumbnail_url);
                        update_post_meta($post_id, 'virtual_url', $virtual_url);
                        update_post_meta($post_id, 'virtual_phone', $virtual_phone);
                        //
                        update_post_meta($post_id, 'event_address', $address);
                        update_post_meta($post_id, 'event_address2', $address2);
                        update_post_meta($post_id, 'event_city', $city);
                        update_post_meta($post_id, 'event_state', $state);
                        update_post_meta($post_id, 'event_country', $country);
                        update_post_meta($post_id, 'event_phone', $phone);
                        update_post_meta($post_id, 'venue_title', $venue_title);
                        update_post_meta($post_id, 'venue_url', $venue_url);
                        update_post_meta($post_id, 'venue_phone', $venue_phone);
                        update_post_meta($post_id, 'venue_image', $venue_image);
                        update_post_meta($post_id, 'event_externalURL', $externalURL);
                        update_post_meta($post_id, 'event_reg_limit', $reg_limit);
                        update_post_meta($post_id, 'event_start_time', time_to_24hr($start_time));
                        update_post_meta($post_id, 'event_end_time', time_to_24hr($end_time));
                        update_post_meta($post_id, 'event_registration_start', $registration_start);
                        update_post_meta($post_id, 'event_registration_end', $registration_end);
                        update_post_meta($post_id, 'event_registration_startT', $registration_startT);
                        update_post_meta($post_id, 'event_registration_endT', $registration_endT);
                    } else {
                        $post_id = wp_insert_post($my_post);
                        add_post_meta($post_id, 'event_id', $event_id);
                        add_post_meta($post_id, 'event_meta', $event_meta);
                        add_post_meta($post_id, 'event_identifier', $event_identifier);
                        add_post_meta($post_id, 'event_start_date', $start_date);
                        add_post_meta($post_id, 'event_end_date', $end_date);
                        add_post_meta($post_id, 'event_location', $event_location);
                        add_post_meta($post_id, 'event_thumbnail_url', $event_thumbnail_url);
                        add_post_meta($post_id, 'virtual_url', $virtual_url);
                        add_post_meta($post_id, 'virtual_phone', $virtual_phone);
                        //
                        add_post_meta($post_id, 'event_address', $address);
                        add_post_meta($post_id, 'event_address2', $address2);
                        add_post_meta($post_id, 'event_city', $city);
                        add_post_meta($post_id, 'event_state', $state);
                        add_post_meta($post_id, 'event_country', $country);
                        add_post_meta($post_id, 'event_phone', $phone);
                        add_post_meta($post_id, 'venue_title', $venue_title);
                        add_post_meta($post_id, 'venue_url', $venue_url);
                        add_post_meta($post_id, 'venue_phone', $venue_phone);
                        add_post_meta($post_id, 'venue_image', $venue_image);
                        add_post_meta($post_id, 'event_externalURL', $externalURL);
                        add_post_meta($post_id, 'event_reg_limit', $reg_limit);
                        add_post_meta($post_id, 'event_start_time', time_to_24hr($start_time));
                        add_post_meta($post_id, 'event_end_time', time_to_24hr($end_time));
                        add_post_meta($post_id, 'event_registration_start', $registration_start);
                        add_post_meta($post_id, 'event_registration_end', $registration_end);
                        add_post_meta($post_id, 'event_registration_startT', $registration_startT);
                        add_post_meta($post_id, 'event_registration_endT', $registration_endT);
                    }
                    // Store the POST ID so it can be displayed on the edit page
                    $sql = array('post_id' => $post_id, 'post_type' => $post_type);
                    $sql_data = array('%d', '%s');
                    $update_id = array('id' => $event_id);
                    $wpdb->update(EVENTS_DETAIL_TABLE, $sql, $update_id, $sql_data, array('%d'));
                    break;
            }
        }
        ?>
        <div id="message" class="updated fade"><p><strong><?php 
        _e('Event details updated for', 'event_espresso');
        ?>
 <a href="<?php 
        echo espresso_reg_url($event_id);
        ?>
" target="_blank">
		<?php 
        echo htmlentities(stripslashes(sanitize_text_field($_REQUEST['event'])), ENT_QUOTES, 'UTF-8');
        ?>
 for <?php 
        echo date("m/d/Y", strtotime($start_date));
        ?>
</a>.</strong></p></div>
        
        <?php 
        /*
         * Added for seating chart addon
         */
        if (isset($seating_chart_result) && $seating_chart_result === false) {
            echo '<p>Failed to associate new seating chart with this event. (Seats from current seating chart might have been used by some attendees)</p>';
        }
    }
    /*
     * With the recursion of this function, additional recurring events will be updated
     */
    if (isset($recurrence_dates) && count($recurrence_dates) > 0 && $_POST['recurrence_apply_changes_to'] > 1) {
        //$recurrence_dates = array_shift($recurrence_dates); //Remove the first item from the array since it will be added after this recursion
        foreach ($recurrence_dates as $r_d) {
            if ($r_d['event_id'] != '' && count($r_d) > 2) {
                update_event(array('event_id' => $r_d['event_id'], 'event_identifier' => $r_d['event_identifier'], 'recurrence_id' => $r_d['recurrence_id'], 'recurrence_start_date' => $r_d['start_date'], 'recurrence_event_end_date' => $r_d['event_end_date'], 'registration_start' => $r_d['registration_start'], 'registration_end' => $r_d['registration_end'], 'visible_on' => $r_d['visible_on'], 'bypass_nonce' => TRUE));
            }
        }
    }
    /*
     * End recursion, as part of recurring events.
     */
    do_action('action_hook_espresso_update_event_success', $_REQUEST);
}
" class="event_price"><span class="section-title"><?php 
echo __('Price: ', 'event_espresso');
?>
</span> <?php 
echo $org_options['currency_symbol'] . $event->event_cost;
?>
</p>

        <p id="event_date-<?php 
echo $event_id;
?>
"><span class="section-title"><?php 
_e('Date:', 'event_espresso');
?>
</span>  <?php 
echo event_date_display($start_date, get_option('date_format'));
?>
</p>
    </div>
    <?php 
//Show short descriptions
if ($event_desc != '' && isset($org_options['display_short_description_in_event_list']) && $org_options['display_short_description_in_event_list'] == 'Y') {
    ?>
        <div class="event-desc">
            <p><?php 
    echo espresso_format_content($event_desc);
    ?>
</p>
        </div>
        <?php 
}
    function espresso_calendar($atts)
    {
        global $wpdb, $org_options, $espresso_calendar, $load_espresso_calendar_scripts;
        $load_espresso_calendar_scripts = true;
        //This tells the plugin to load the required scripts
        extract(shortcode_atts(array('event_category_id' => '', 'show_expired' => 'false', 'cal_view' => 'month'), $atts));
        $event_category_id = "{$event_category_id}";
        $show_expired = "{$show_expired}";
        $cal_view = "{$cal_view}";
        //Build the SQL to run
        //Get the categories
        if ($event_category_id != "") {
            $sql = "SELECT e.*, c.category_name, c.category_desc, c.display_desc, ese.start_time, ese.end_time FROM " . EVENTS_DETAIL_TABLE . " e ";
            $sql .= " JOIN " . EVENTS_CATEGORY_REL_TABLE . " r ON r.event_id = e.id ";
            $sql .= " JOIN " . EVENTS_CATEGORY_TABLE . " c ON  c.id = r.cat_id ";
            $sql .= " LEFT JOIN " . EVENTS_START_END_TABLE . " ese ON ese.event_id= e.id ";
            $sql .= " WHERE e.is_active = 'Y' ";
            $sql .= " AND e.event_status != 'D' ";
            $sql .= " AND e.event_status != 'S' ";
            $sql .= " AND e.event_status != 'P' ";
            $sql .= " AND e.event_status != 'X' ";
            $sql .= " AND e.event_status != 'R' ";
            $sql .= " AND c.category_identifier = '" . $event_category_id . "' ";
            if ($show_expired == "false") {
                $sql .= " AND start_date >= '" . date('Y-m-d') . "' ";
                $sql .= " AND e.registration_start <= '" . date('Y-m-d') . "' ";
                $sql .= " AND e.registration_end >= '" . date('Y-m-d') . "' ";
            }
        } else {
            $sql = "SELECT e.*, ese.start_time, ese.end_time FROM " . EVENTS_DETAIL_TABLE . " e ";
            $sql .= " LEFT JOIN " . EVENTS_START_END_TABLE . " ese ON ese.event_id= e.id ";
            $sql .= " WHERE is_active = 'Y' ";
            $sql .= " AND e.event_status != 'D' ";
            $sql .= " AND e.event_status != 'S' ";
            $sql .= " AND e.event_status != 'P' ";
            $sql .= " AND e.event_status != 'X' ";
            $sql .= " AND e.event_status != 'R' ";
            if ($show_expired == "false") {
                $sql .= " AND e.start_date >= '" . date('Y-m-d') . "' ";
                $sql .= " AND e.registration_start <= '" . date('Y-m-d') . "' ";
                $sql .= " AND e.registration_end >= '" . date('Y-m-d') . "' ";
            }
        }
        $sql .= " GROUP BY e.id ORDER BY date(start_date), id ASC";
        //Print the results of the query
        //echo $sql;
        $events_data = $wpdb->get_results($sql);
        $events = array();
        foreach ($events_data as $event) {
            //Get details about the category of the event
            //print_r( espresso_event_category_data($event->id) ); //Print the category id for each event.
            $category_data = espresso_event_category_data($event->id);
            switch ($espresso_calendar['espresso_page_post']) {
                case 'P':
                    $registration_url = get_option('siteurl') . '/?p=' . $event->post_id;
                    break;
                case 'R':
                default:
                    $registration_url = get_option('siteurl') . '/?page_id=' . $org_options['event_page_id'] . '&regevent_action=register&event_id=' . $event->id;
                    break;
            }
            //Checkthe status of the event. If the event is expired, the link to the registration page will be deactivated.
            $eventArray['url'] = '';
            $status = '';
            //Changed 8-30-2011 by Seth
            /*switch (event_espresso_get_status($event->id)){
            			case 'NOT_ACTIVE':
            				$status = ' - ' . __('Expired','event_espresso');
            			break;
            			case 'ACTIVE':
            				$status = '';
            			break;
            		}*/
            //End Seth
            //Gets the URL of the event and links the event to the registration form.
            $eventArray['url'] = $event->externalURL != '' ? htmlspecialchars_decode($event->externalURL) : $registration_url;
            //Id of the event
            $eventArray['id'] = $event->id;
            //Get the title of the event
            $eventArray['title'] = htmlspecialchars_decode(stripslashes_deep($event->event_name . $status), ENT_QUOTES);
            //Gets the description of the event. This can be used for hover effects such as jQuery Tooltips or QTip
            $eventArray['description'] = htmlspecialchars_decode(stripslashes_deep($event->event_desc), ENT_QUOTES);
            //Get the start and end times for each event
            //important! time must be in iso8601 format 2010-05-10T08:30  !!
            $eventArray['start'] = date("c", strtotime($event->start_date . ' ' . event_date_display($event->start_time, get_option('time_format'))));
            $eventArray['end'] = date("c", strtotime($event->end_date . ' ' . event_date_display($event->end_time, get_option('time_format'))));
            //Custom fields:
            //These can be used to perform special functions in your display.
            //This can be used to use the category id as the event type
            $eventArray['eventType'] = $category_data['category_name'];
            //Changed 8-30-2011 by Seth
            //This decalares the category ID as the CSS class name
            /*$sql_categories = 'select * from `wp_events_category_rel` where event_id='.$event->id ;
            			$categories_data = $wpdb->get_results($sql_categories);
            
            			$cssClass = $category_data['category_identifier'];
             			foreach($categories_data as $_category){
            				if(isset($categoryCss[$_category->cat_id])){
            					$cssClass .=' '.$categoryCss[$_category->cat_id] ;
            					continue;
            				}
            				$sql_cat = 'select * from `wp_events_category_detail` where id='.$_category->cat_id;
            				$category = $wpdb->get_results($sql_cat);
            				foreach($category as $_cat){
            					$cssClass .=' '.$_cat->category_identifier ;
            					$categoryCss[$_category->cat_id] = $_cat->category_identifier;
            					continue;
            				}
            
            			}
            
            			$eventArray['className'] = $cssClass;*/
            //End Seth
            //End custom fields
            //If set to true, events will be shown as all day events
            $eventArray['allDay'] = FALSE;
            //Array of the event details
            $events[] = $eventArray;
        }
        //Print the results of the code above
        //echo json_encode($events);
        //Start the output of the calendar
        ob_start();
        ?>
<script type="text/javascript">
		$jaer = jQuery.noConflict();
		jQuery(document).ready(function($jaer) {

				$jaer('#espresso_calendar').fullCalendar({


					/**
					* General Display
					* http://arshaw.com/fullcalendar/docs/text/
					**/

					//month, basicWeek, basicDay, agendaWeek, agendaDay
					defaultView: '<?php 
        echo $cal_view;
        ?>
',

					//Defines the buttons and title at the top of the calendar.
					header: { //Settings: http://arshaw.com/fullcalendar/docs/display/header/
						<?php 
        echo stripslashes_deep($espresso_calendar['espresso_calendar_header']);
        ?>
					},

					/**
					* Theme Settings
					*
					* Once you enable theming with true, you still need to include the CSS file for the theme you want.
					* For example, if you just downloaded a theme from the jQuery UI Themeroller, you need to put a <link> tag in your page's <head>.
					**/

					//Enables/disables use of jQuery UI theming.
					//theme: true, //Settings: http://arshaw.com/fullcalendar/docs/display/theme/

					//This option only applies to calendars that have jQuery UI theming enabled with the theme option.
					/*buttonIcons:{ //Settings: http://arshaw.com/fullcalendar/docs/display/buttonIcons/
						prev: 'circle-triangle-w',
						next: 'circle-triangle-e'
					},*/

					//The day that each week begins.
					//The value must be a number that represents the day of the week.
					//Sunday=0, Monday=1, Tuesday=2, etc.
					firstDay:<?php 
        echo $espresso_calendar['espresso_calendar_firstday'];
        ?>
, //Settings: http://arshaw.com/fullcalendar/docs/display/firstDay/

					//Displays the calendar in right-to-left mode.
					isRTL: false,

					//Whether to include Saturday/Sunday columns in any of the calendar views.
					weekends: <?php 
        echo $espresso_calendar['espresso_calendar_weekends'];
        ?>
,

					//Determines the number of weeks displayed in a month view. Also determines each week's height.
					weekMode:'fixed', //Settings: http://arshaw.com/fullcalendar/docs/display/weekMode/

					//Will make the entire calendar (including header) a pixel height.
					height:<?php 
        echo $espresso_calendar['espresso_calendar_height'];
        ?>
, //Settings: http://arshaw.com/fullcalendar/docs/display/height/

					//Will make the calendar's content area a pixel height.
					//contentHeight: 600, //Settings: http://arshaw.com/fullcalendar/docs/display/contentHeight/

					//Determines the width-to-height aspect ratio of the calendar.
					//aspectRatio: 2, //Settings: http://arshaw.com/fullcalendar/docs/display/aspectRatio/

					/**
					* Agenda Options
					* http://arshaw.com/fullcalendar/docs/agenda/
					* Note: These ptions that apply to the agendaWeek and agendaDay views, and have beft out intentionally.
					* Please refer to the URL above to add.manage your agenda views.
					**/

					/**
					* Text/Time Customization Settings
					* http://arshaw.com/fullcalendar/docs/text/
					**/

					//Determines the time-text that will be displayed on each event.
					timeFormat:{ //Settings: http://arshaw.com/fullcalendar/docs/text/timeFormat/
						// for agendaWeek and agendaDay
						agenda: 'h:mm{ - h:mm}', // 5:00 - 6:30

						// for all other views
						'': ''            // 7p
					},

					//Changes the colors of the events as seen here:
					//http://code.google.com/p/fullcalendar/issues/detail?id=6&can=1&q=css&colspec=ID%20Type%20Status%20Milestone%20Summary%20Stars
					eventRender: function(event, element) {

						//This displays the title of the event when hovering
						element.attr('title', event.title);

						//These are examples of custom parameters that can be passed
						/*if (event.myType == 'meeting') {
							element.addClass('meeting');
							//alert(event.myType );
						}*/

						//This example basically applies different classes to the event
						/*switch (event.myType){
						case 'meeting' :
							element.find('.n, .w, .c, .e, .s').css('background-color', '#00cc33');
						break;
						case 'project' :
							element.find('.n, .w, .c, .e, .s').css('background-color', 'red');
						break;
						default :
						break;
						}*/
					},

					//Determines the text that will be displayed on the calendar's column headings.
					columnFormat:{ //Settings: http://arshaw.com/fullcalendar/docs/text/columnFormat/
						<?php 
        echo stripslashes_deep($espresso_calendar['espresso_calendar_columnFormat']);
        ?>
						/*month: 'ddd',    // Mon
						week: 'ddd M/d', // Mon 9/7
						day: 'dddd M/d'  // Monday 9/7*/
					},

					//For date formatting options, please refer to: http://arshaw.com/fullcalendar/docs/utilities/formatDate/
					titleFormat:{ //Settings: http://arshaw.com/fullcalendar/docs/text/columnFormat/
						<?php 
        echo stripslashes_deep($espresso_calendar['espresso_calendar_titleFormat']);
        ?>
						/*month: 'MMMM yyyy',                             // September 2009
						week: "MMM d[ yyyy]{ '&#8212;'[ MMM] d yyyy}", // Sep 7 - 13 2009
						day: 'dddd, MMM d, yyyy'                  // Tuesday, Sep 8, 2009*/
					},

					//Text that will be displayed on buttons of the header.
					buttonText: { //Settings: http://arshaw.com/fullcalendar/docs/text/buttonText/
						<?php 
        echo stripslashes_deep($espresso_calendar['espresso_calendar_buttonText']);
        ?>
						/*prev:     '&nbsp;&#9668;&nbsp;',  // left triangle
						next:     '&nbsp;&#9658;&nbsp;',  // right triangle
						prevYear: '&nbsp;&lt;&lt;&nbsp;', // <<
						nextYear: '&nbsp;&gt;&gt;&nbsp;', // >>
						today:    'today',
						month:    'month',
						week:     'week',
						day:      'day'*/
					},

					//Full names of months.
					monthNames: [<?php 
        echo stripslashes_deep($espresso_calendar['espresso_calendar_monthNames']);
        ?>
/*'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'*/],

					//Abbreviated names of months.
					monthNamesShort: [<?php 
        echo stripslashes_deep($espresso_calendar['espresso_calendar_monthNamesShort']);
        ?>
/*'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'*/],

					//Full names of days-of-week.
					dayNames: [<?php 
        echo stripslashes_deep($espresso_calendar['espresso_calendar_dayNames']);
        ?>
/*'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'*/],

					//Abbreviated names of days-of-week.
					dayNamesShort: [<?php 
        echo stripslashes_deep($espresso_calendar['espresso_calendar_dayNamesShort']);
        ?>
/*'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'*/],

					//Load the events into json srrsy
					events: <?php 
        echo json_encode($events);
        ?>
,
					loading: function(bool) {
						if (bool) $('#loading').show();
						else $jaer('#loading').hide();
					}

				});
				// this line was overriding the cal_view defined inthe shortcode
				//$jaer('#espresso_calendar').fullCalendar('changeView','month');
			});

	</script>

		<div id='espresso_calendar'></div>
	<?php 
        $buffer = ob_get_contents();
        ob_end_clean();
        return $buffer;
        //End calendar output
    }
Exemplo n.º 17
0
    function register_attendees($single_event_id = NULL, $event_id_sc = 0, $reg_form_only = false)
    {
        //Declare the $data object
        $data = (object) array('event' => NULL);
        do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, '');
        //Run code for the seating chart addon
        if (function_exists('espresso_seating_version')) {
            do_action('ee_seating_chart_css');
            do_action('ee_seating_chart_js');
            do_action('ee_seating_chart_flush_expired_seats');
        }
        global $wpdb, $org_options;
        if (isset($_REQUEST['ee']) && $_REQUEST['ee'] != '') {
            $_REQUEST['event_id'] = $_REQUEST['ee'];
        }
        $event_id = $event_id_sc != '0' ? $event_id_sc : $_REQUEST['event_id'];
        if (!empty($_REQUEST['event_id_time'])) {
            $pieces = explode('|', $_REQUEST['event_id_time'], 3);
            $event_id = $pieces[0];
            $start_time = $pieces[1];
            $time_id = $pieces[2];
            $time_selected = true;
        }
        //The following variables are used to get information about your organization
        $event_page_id = $org_options['event_page_id'];
        $Organization = stripslashes_deep($org_options['organization']);
        $Organization_street1 = $org_options['organization_street1'];
        $Organization_street2 = $org_options['organization_street2'];
        $Organization_city = $org_options['organization_city'];
        $Organization_state = $org_options['organization_state'];
        $Organization_zip = $org_options['organization_zip'];
        $contact = $org_options['contact_email'];
        $registrar = $org_options['contact_email'];
        $currency_format = isset($org_options['currency_format']) ? $org_options['currency_format'] : '';
        $message = $org_options['message'];
        //Build event queries
        $sql = "SELECT e.*, ese.start_time, ese.end_time ";
        if (isset($org_options['use_venue_manager']) && $org_options['use_venue_manager'] == 'Y') {
            $sql .= ", v.name venue_name, v.address venue_address, v.address2 venue_address2, v.city venue_city, v.state venue_state, v.zip venue_zip, v.country venue_country, v.meta venue_meta ";
        }
        $sql .= " FROM " . EVENTS_DETAIL_TABLE . " e ";
        $sql .= " LEFT JOIN " . EVENTS_START_END_TABLE . " ese ON ese.event_id = e.id ";
        if (isset($org_options['use_venue_manager']) && $org_options['use_venue_manager'] == 'Y') {
            $sql .= " LEFT JOIN " . EVENTS_VENUE_REL_TABLE . " r ON r.event_id = e.id LEFT JOIN " . EVENTS_VENUE_TABLE . " v ON v.id = r.venue_id ";
        }
        $sql .= " WHERE e.is_active='Y' ";
        $sql .= " AND e.event_status != 'D' ";
        //Get the ID of a single event
        if ($single_event_id != NULL) {
            //If a single event needs to be displayed, get its ID
            $sql .= " AND event_identifier = '" . $single_event_id . "' ";
        } else {
            $sql .= " AND e.id = '" . $event_id . "' LIMIT 0,1";
        }
        //Support for diarise
        if (!empty($_REQUEST['post_event_id'])) {
            $sql = "SELECT e.* FROM " . EVENTS_DETAIL_TABLE . ' e';
            $sql .= " LEFT JOIN " . EVENTS_START_END_TABLE . " ese ON ese.event_id = e.id ";
            $sql .= " WHERE post_id = '" . $_REQUEST['post_event_id'] . "' ";
            $sql .= " LIMIT 0,1";
        }
        $data->event = $wpdb->get_row($wpdb->prepare($sql, NULL), OBJECT);
        $num_rows = $wpdb->num_rows;
        //Build the registration page
        if ($num_rows > 0) {
            //These are the variables that can be used throughout the registration page
            //foreach ($events as $event) {
            global $this_event_id;
            $event_id = $data->event->id;
            $this_event_id = $event_id;
            $event_name = stripslashes_deep($data->event->event_name);
            $event_desc = stripslashes_deep($data->event->event_desc);
            $display_desc = $data->event->display_desc;
            if ($reg_form_only == true) {
                $display_desc = "N";
            }
            $display_reg_form = $data->event->display_reg_form;
            $event_address = $data->event->address;
            $event_address2 = $data->event->address2;
            $event_city = $data->event->city;
            $event_state = $data->event->state;
            $event_zip = $data->event->zip;
            $event_country = $data->event->country;
            $event_description = stripslashes_deep($data->event->event_desc);
            $event_identifier = $data->event->event_identifier;
            $event_cost = isset($data->event->event_cost) ? $data->event->event_cost : "0.00";
            $member_only = $data->event->member_only;
            $reg_limit = $data->event->reg_limit;
            $allow_multiple = $data->event->allow_multiple;
            $start_date = $data->event->start_date;
            $end_date = $data->event->end_date;
            $allow_overflow = $data->event->allow_overflow;
            $overflow_event_id = $data->event->overflow_event_id;
            //Venue details
            $venue_title = $data->event->venue_title;
            $venue_url = $data->event->venue_url;
            $venue_image = $data->event->venue_image;
            $venue_phone = $data->event->venue_phone;
            $venue_address = '';
            $venue_address2 = '';
            $venue_city = '';
            $venue_state = '';
            $venue_zip = '';
            $venue_country = '';
            global $event_meta;
            $event_meta = unserialize($data->event->event_meta);
            //Venue information
            if ($org_options['use_venue_manager'] == 'Y') {
                $event_address = $data->event->venue_address;
                $event_address2 = $data->event->venue_address2;
                $event_city = $data->event->venue_city;
                $event_state = $data->event->venue_state;
                $event_zip = $data->event->venue_zip;
                $event_country = $data->event->venue_country;
                //Leaving these variables intact, just in case people wnat to use them
                $venue_title = $data->event->venue_name;
                $venue_address = $data->event->venue_address;
                $venue_address2 = $data->event->venue_address2;
                $venue_city = $data->event->venue_city;
                $venue_state = $data->event->venue_state;
                $venue_zip = $data->event->venue_zip;
                $venue_country = $data->event->venue_country;
                global $venue_meta;
                $add_venue_meta = array('venue_title' => $data->event->venue_name, 'venue_address' => $data->event->venue_address, 'venue_address2' => $data->event->venue_address2, 'venue_city' => $data->event->venue_city, 'venue_state' => $data->event->venue_state, 'venue_country' => $data->event->venue_country);
                $venue_meta = isset($data->event->venue_meta) && $data->event->venue_meta != '' && (isset($add_venue_meta) && $add_venue_meta != '') ? array_merge(unserialize($data->event->venue_meta), $add_venue_meta) : '';
                //print_r($venue_meta);
            }
            $virtual_url = stripslashes_deep($data->event->virtual_url);
            $virtual_phone = stripslashes_deep($data->event->virtual_phone);
            //Address formatting
            $location = (!empty($event_address) ? $event_address : '') . (!empty($event_address2) ? '<br />' . $event_address2 : '') . (!empty($event_city) ? '<br />' . $event_city : '') . (!empty($event_state) ? ', ' . $event_state : '') . (!empty($event_zip) ? '<br />' . $event_zip : '') . (!empty($event_country) ? '<br />' . $event_country : '');
            //Google map link creation
            $google_map_link = espresso_google_map_link(array('address' => $event_address, 'city' => $event_city, 'state' => $event_state, 'zip' => $event_zip, 'country' => $event_country, 'text' => 'Map and Directions', 'type' => 'text'));
            $question_groups = unserialize($data->event->question_groups);
            $reg_start_date = $data->event->registration_start;
            $reg_end_date = $data->event->registration_end;
            $today = date("Y-m-d");
            if (isset($data->event->timezone_string) && $data->event->timezone_string != '') {
                $timezone_string = $data->event->timezone_string;
            } else {
                $timezone_string = get_option('timezone_string');
                if (!isset($timezone_string) || $timezone_string == '') {
                    $timezone_string = 'America/New_York';
                }
            }
            $t = time();
            $today = date_at_timezone("Y-m-d H:i A", $timezone_string, $t);
            //echo event_date_display($today, get_option('date_format'). ' ' .get_option('time_format')) . ' ' . $timezone_string;
            //echo espresso_ddtimezone_simple();
            $reg_limit = $data->event->reg_limit;
            $additional_limit = $data->event->additional_limit;
            //If the coupon code system is intalled then use it
            $use_coupon_code = $data->event->use_coupon_code;
            //If the groupon code addon is installed, then use it
            $use_groupon_code = $data->event->use_groupon_code;
            //Set a default value for additional limit
            if ($additional_limit == '') {
                $additional_limit = '5';
            }
            $num_attendees = get_number_of_attendees_reg_limit($event_id, 'num_attendees');
            //Get the number of attendees
            $available_spaces = get_number_of_attendees_reg_limit($event_id, 'available_spaces');
            //Gets a count of the available spaces
            $number_available_spaces = get_number_of_attendees_reg_limit($event_id, 'number_available_spaces');
            //Gets the number of available spaces
            //echo $number_available_spaces;
            global $all_meta;
            $all_meta = array('event_id' => $event_id, 'event_name' => stripslashes_deep($event_name), 'event_desc' => stripslashes_deep($event_desc), 'event_address' => $event_address, 'event_address2' => $event_address2, 'event_city' => $event_city, 'event_state' => $event_state, 'event_zip' => $event_zip, 'event_country' => $event_country, 'venue_title' => $venue_title, 'venue_address' => $venue_address, 'venue_address2' => $venue_address2, 'venue_city' => $venue_city, 'venue_state' => $venue_state, 'venue_country' => $venue_country, 'location' => $location, 'is_active' => $data->event->is_active, 'event_status' => $data->event->event_status, 'contact_email' => empty($data->event->alt_email) ? $org_options['contact_email'] : $data->event->alt_email, 'start_time' => empty($data->event->start_time) ? '' : $data->event->start_time, 'end_time' => empty($data->event->end_time) ? '' : $data->event->end_time, 'registration_startT' => $data->event->registration_startT, 'registration_start' => $data->event->registration_start, 'registration_endT' => $data->event->registration_endT, 'registration_end' => $data->event->registration_end, 'start_date' => event_espresso_no_format_date($start_date, get_option('date_format')), 'end_date' => event_date_display($end_date, get_option('date_format')), 'google_map_link' => $google_map_link);
            //print_r($all_meta);
            //This function gets the status of the event.
            $is_active = array();
            $is_active = event_espresso_get_is_active(0, $all_meta);
            //echo '<p>'.print_r(event_espresso_get_is_active($event_id, $all_meta)).'</p>';;
            if ($org_options['use_captcha'] == 'Y' && empty($_REQUEST['edit_details'])) {
                ?>
                <script type="text/javascript">
                    var RecaptchaOptions = {
                        theme : '<?php 
                echo $org_options['recaptcha_theme'] == '' ? 'red' : $org_options['recaptcha_theme'];
                ?>
',
                        lang : '<?php 
                echo $org_options['recaptcha_language'] == '' ? 'en' : $org_options['recaptcha_language'];
                ?>
'
                    };
                </script>
                <?php 
            }
            //This is the start of the registration form. This is where you can start editing your display.
            //(Shows the regsitration form if enough spaces exist)
            if ($num_attendees >= $reg_limit) {
                ?>
                <div class="espresso_event_full event-display-boxes" id="espresso_event_full-<?php 
                echo $event_id;
                ?>
">
                    <h3 class="event_title"><?php 
                echo stripslashes_deep($event_name);
                ?>
</h3>
                    <div class="event-messages">
                        <p class="event_full"><strong><?php 
                _e('We are sorry but this event has reached the maximum number of attendees!', 'event_espresso');
                ?>
</strong></p>
                        <p class="event_full"><strong><?php 
                _e('Please check back in the event someone cancels.', 'event_espresso');
                ?>
</strong></p>
                        <p class="num_attendees"><?php 
                _e('Current Number of Attendees:', 'event_espresso');
                ?>
 <?php 
                echo $num_attendees;
                ?>
</p>
                    </div>
                <?php 
                $num_attendees = get_number_of_attendees_reg_limit($event_id, 'num_attendees');
                //Get the number of attendees. Please visit http://eventespresso.com/forums/?p=247 for available parameters for the get_number_of_attendees_reg_limit() function.
                if ($num_attendees >= $reg_limit && ($allow_overflow == 'Y' && $overflow_event_id != 0)) {
                    ?>
                        <p id="register_link-<?php 
                    echo $overflow_event_id;
                    ?>
" class="register-link-footer"><a class="a_register_link ui-button ui-button-big ui-priority-primary ui-state-default ui-state-hover ui-state-focus ui-corner-all" id="a_register_link-<?php 
                    echo $overflow_event_id;
                    ?>
" href="<?php 
                    echo espresso_reg_url($overflow_event_id);
                    ?>
" title="<?php 
                    echo stripslashes_deep($event_name);
                    ?>
"><?php 
                    _e('Join Waiting List', 'event_espresso');
                    ?>
</a></p>
                    <?php 
                }
                ?>
                </div>

                    <?php 
            } else {
                $member_options = get_option('events_member_settings');
                //echo "<pre>".print_r($member_options,true)."</pre>";
                //If enough spaces exist then show the form
                //Check to see if the Members plugin is installed.
                if (function_exists('espresso_members_installed') && espresso_members_installed() == true && !is_user_logged_in() && ($member_only == 'Y' || $member_options['member_only_all'] == 'Y')) {
                    event_espresso_user_login();
                } else {
                    //Serve up the registration form
                    //As of version 3.0.17 the registration details have been moved to registration_form.php
                    require 'registration_page_display.php';
                }
            }
            //End if ($num_attendees >= $reg_limit) (Shows the regsitration form if enough spaces exist)
        } else {
            //If there are no results from the query, display this message
            echo '<h3>' . __('This event has expired or is no longer available.', 'event_espresso') . '</h3>';
        }
        echo espresso_registration_footer();
        //Check to see how many database queries were performed
        //echo '<p>Database Queries: ' . get_num_queries() .'</p>';
    }
function add_event_to_db($recurrence_arr = array())
{
    global $wpdb, $org_options, $current_user, $espresso_premium;
    //Security check using nonce
    if (empty($_POST['nonce_verify_insert_event']) || !wp_verify_nonce($_POST['nonce_verify_insert_event'], 'espresso_verify_insert_event_nonce')) {
        if (!isset($recurrence_arr['bypass_nonce'])) {
            print '<h3 class="error">' . __('Sorry, there was a security error and your event was not saved.', 'event_espresso') . '</h3>';
            return;
        }
    }
    //Set FEM to false
    $use_fem = FALSE;
    $is_espresso_event_manager = false;
    //If using FEM
    if (isset($_REQUEST['ee_fem_action']) && $_REQUEST['ee_fem_action'] == 'ee_fem_add') {
        $use_fem = TRUE;
        if (function_exists('espresso_member_data') && espresso_member_data('role') == 'espresso_event_manager') {
            global $espresso_manager;
            $event_manager_approval = isset($espresso_manager['event_manager_approval']) && $espresso_manager['event_manager_approval'] == 'Y' ? true : false;
            $is_espresso_event_manager = TRUE;
        }
    }
    //Don't show sql errors if using the FEM
    if ($use_fem === FALSE) {
        $wpdb->show_errors();
    }
    static $recurrence_id = null;
    if (defined('EVENT_ESPRESSO_RECURRENCE_TABLE')) {
        require_once EVENT_ESPRESSO_RECURRENCE_FULL_PATH . "functions/re_functions.php";
        $recurrence_id = array_key_exists('recurrence_id', $recurrence_arr) ? $recurrence_arr['recurrence_id'] : Null;
        if ($_POST['recurrence'] == 'Y' && count($recurrence_arr) < 2) {
            if (is_null($recurrence_id)) {
                $recurrence_id = add_recurrence_master_record();
            }
            $re_params = array('start_date' => $_POST['recurrence_type'] == 'a' ? sanitize_text_field($_POST['recurrence_start_date']) : sanitize_text_field($_POST['recurrence_manual_dates']), 'event_end_date' => $_POST['recurrence_type'] == 'a' ? sanitize_text_field($_POST['recurrence_event_end_date']) : sanitize_text_field($_POST['recurrence_manual_end_dates']), 'end_date' => $_POST['recurrence_type'] == 'a' ? sanitize_text_field($_POST['recurrence_end_date']) : sanitize_text_field($_POST['end_date']), 'registration_start' => sanitize_text_field($_POST['recurrence_regis_start_date']), 'registration_end' => sanitize_text_field($_POST['recurrence_regis_end_date']), 'frequency' => sanitize_text_field($_POST['recurrence_frequency']), 'interval' => sanitize_text_field($_POST['recurrence_interval']), 'type' => sanitize_text_field($_POST['recurrence_type']), 'weekdays' => isset($_POST['recurrence_weekday']) ? $_POST['recurrence_weekday'] : '', 'repeat_by' => $_POST['recurrence_repeat_by'], 'recurrence_regis_date_increment' => $_POST['recurrence_regis_date_increment'], 'recurrence_manual_dates' => $_POST['recurrence_manual_dates'], 'recurrence_manual_end_dates' => $_POST['recurrence_manual_end_dates'], 'recurrence_id' => $recurrence_id, 'adding_to_db' => 'Y');
            $recurrence_dates = $_POST['recurrence_type'] == 'm' ? find_recurrence_manual_dates($re_params) : find_recurrence_dates($re_params);
        }
    }
    //echo_f('re array', $recurrence_dates);
    if (defined('EVENT_ESPRESSO_RECURRENCE_MODULE_ACTIVE') && $_POST['recurrence'] == 'Y' && count($recurrence_arr) == 0) {
        //skip the first insert because we do not have the start dates
    } else {
        $event_meta = array();
        //will be used to hold event meta data
        //Filters the event description based on user level
        $user_access = apply_filters('filter_hook_espresso_event_unfiltered_description', current_user_can('administrator'));
        $_REQUEST['event_desc'] = is_admin() || $user_access ? $_REQUEST['event_desc'] : apply_filters('filter_hook_espresso_event_wp_kses_post_description', wp_kses_post($_REQUEST['event_desc']));
        $event_code = uniqid($current_user->ID . '-');
        $event_name = !empty($_REQUEST['event']) ? sanitize_text_field($_REQUEST['event']) : $event_code;
        if (!isset($_REQUEST['event_identifier']) || $_REQUEST['event_identifier'] == '') {
            $event_identifier = sanitize_title_with_dashes($event_name . '-' . $event_code);
        } else {
            $event_identifier = sanitize_title_with_dashes($_REQUEST['event_identifier']) . $event_code;
        }
        $event_desc = !empty($_REQUEST['event_desc']) ? $_REQUEST['event_desc'] : '';
        $display_desc = !empty($_REQUEST['display_desc']) ? sanitize_text_field($_REQUEST['display_desc']) : 'Y';
        $display_reg_form = !empty($_REQUEST['display_reg_form']) ? sanitize_text_field($_REQUEST['display_reg_form']) : 'Y';
        $externalURL = isset($_REQUEST['externalURL']) ? sanitize_text_field($_REQUEST['externalURL']) : '';
        $post_type = !empty($_REQUEST['espresso_post_type']) ? sanitize_text_field($_REQUEST['espresso_post_type']) : '';
        $reg_limit = !empty($_REQUEST['reg_limit']) ? sanitize_text_field($_REQUEST['reg_limit']) : '999999';
        $_REQUEST['reg_limit'] = $reg_limit;
        $allow_multiple = !empty($_REQUEST['allow_multiple']) ? sanitize_text_field($_REQUEST['allow_multiple']) : 'N';
        $additional_limit = !empty($_REQUEST['additional_limit']) && $_REQUEST['additional_limit'] > 0 ? sanitize_text_field($_REQUEST['additional_limit']) : '5';
        $_REQUEST['additional_limit'] = $additional_limit;
        $member_only = !empty($_REQUEST['member_only']) ? sanitize_text_field($_REQUEST['member_only']) : 'N';
        $is_active = !empty($_REQUEST['is_active']) ? sanitize_text_field($_REQUEST['is_active']) : 'Y';
        $event_status = !empty($_REQUEST['event_status']) ? sanitize_text_field($_REQUEST['event_status']) : 'A';
        $use_coupon_code = !empty($_REQUEST['use_coupon_code']) ? sanitize_text_field($_REQUEST['use_coupon_code']) : 'N';
        $ticket_id = empty($_REQUEST['ticket_id']) ? 0 : sanitize_text_field($_REQUEST['ticket_id']);
        //Get the first instance of the start and end times
        $start_time = !empty($_REQUEST['start_time'][0]) ? sanitize_text_field($_REQUEST['start_time'][0]) : '8:00 AM';
        $_REQUEST['event_start_time'] = $start_time;
        $end_time = !empty($_REQUEST['end_time'][0]) ? sanitize_text_field($_REQUEST['end_time'][0]) : '5:00 PM';
        $_REQUEST['event_end_time'] = $end_time;
        // Add Timezone
        $timezone_string = isset($_REQUEST['timezone_string']) ? sanitize_text_field($_REQUEST['timezone_string']) : '';
        //Early discounts
        $early_disc = !empty($_REQUEST['early_disc']) ? sanitize_text_field($_REQUEST['early_disc']) : '';
        $early_disc_date = !empty($_REQUEST['early_disc_date']) ? sanitize_text_field($_REQUEST['early_disc_date']) : '';
        $early_disc_percentage = !empty($_REQUEST['early_disc_percentage']) ? sanitize_text_field($_REQUEST['early_disc_percentage']) : '';
        //Alternate email address field
        $alt_email = !empty($_REQUEST['alt_email']) ? sanitize_text_field($_REQUEST['alt_email']) : '';
        //Send a custom emal
        $send_mail = !empty($_REQUEST['send_mail']) ? sanitize_text_field($_REQUEST['send_mail']) : 'N';
        //Custom email content
        $conf_mail = !empty($_REQUEST['conf_mail']) ? esc_html($_REQUEST['conf_mail']) : '';
        //Use a premade custom email
        $email_id = isset($_REQUEST['email_name']) ? (int) $_REQUEST['email_name'] : '0';
        //Venue Information
        $venue_title = isset($_REQUEST['venue_title']) ? sanitize_text_field($_REQUEST['venue_title']) : '';
        $venue_url = isset($_REQUEST['venue_url']) ? sanitize_text_field($_REQUEST['venue_url']) : '';
        $venue_phone = isset($_REQUEST['venue_phone']) ? sanitize_text_field($_REQUEST['venue_phone']) : '';
        $venue_image = isset($_REQUEST['venue_image']) ? sanitize_text_field($_REQUEST['venue_image']) : '';
        //Virtual location
        $virtual_url = !empty($_REQUEST['virtual_url']) ? sanitize_text_field($_REQUEST['virtual_url']) : '';
        $virtual_phone = !empty($_REQUEST['virtual_phone']) ? sanitize_text_field($_REQUEST['virtual_phone']) : '';
        //Address/venue information
        $address = isset($_REQUEST['address']) ? sanitize_text_field($_REQUEST['address']) : '';
        $address2 = isset($_REQUEST['address2']) ? sanitize_text_field($_REQUEST['address2']) : '';
        $city = isset($_REQUEST['city']) ? sanitize_text_field($_REQUEST['city']) : '';
        $state = isset($_REQUEST['state']) ? sanitize_text_field($_REQUEST['state']) : '';
        $zip = isset($_REQUEST['zip']) ? sanitize_text_field($_REQUEST['zip']) : '';
        $country = isset($_REQUEST['country']) ? sanitize_text_field($_REQUEST['country']) : '';
        $phone = isset($_REQUEST['phone']) ? sanitize_text_field($_REQUEST['phone']) : '';
        $event_location = '';
        if (!empty($address)) {
            $event_location .= $address . ' ';
        }
        if (!empty($address2)) {
            $event_location .= '<br />' . $address2;
        }
        if (!empty($city)) {
            $event_location .= '<br />' . $city;
        }
        if (!empty($state)) {
            $event_location .= ', ' . $state;
        }
        if (!empty($zip)) {
            $event_location .= ', ' . $state;
        }
        if (!empty($country)) {
            $event_location .= '<br />' . $country;
        }
        if ($is_espresso_event_manager == true && $use_fem == true && $event_manager_approval == true) {
            $event_status = 'P';
        }
        //Get the registration start and end times
        $_REQUEST['registration_startT'] = !empty($_REQUEST['registration_startT']) ? sanitize_text_field($_REQUEST['registration_startT']) : '12:01 AM';
        $_REQUEST['registration_endT'] = !empty($_REQUEST['registration_endT']) ? sanitize_text_field($_REQUEST['registration_endT']) : '11:59 PM';
        // Add registration times
        $registration_startT = event_date_display($_REQUEST['registration_startT'], 'H:i');
        $registration_endT = event_date_display($_REQUEST['registration_endT'], 'H:i');
        $_REQUEST['registration_start'] = !empty($_REQUEST['registration_start']) ? sanitize_text_field($_REQUEST['registration_start']) : date('Y-m-d');
        $_REQUEST['registration_end'] = !empty($_REQUEST['registration_end']) ? sanitize_text_field($_REQUEST['registration_end']) : date('Y-m-d', time() + 60 * 60 * 24 * 29);
        $registration_start = array_key_exists('registration_start', $recurrence_arr) ? $recurrence_arr['registration_start'] : $_REQUEST['registration_start'];
        $registration_end = array_key_exists('registration_end', $recurrence_arr) ? $recurrence_arr['registration_end'] : $_REQUEST['registration_end'];
        //Check which start/end date to use.  Will be determined by recurring events addon, if installed.
        if (array_key_exists('recurrence_start_date', $recurrence_arr)) {
            //Recurring event
            $start_date = $recurrence_arr['recurrence_start_date'];
        } elseif (!empty($_REQUEST['start_date']) && !empty($_REQUEST['recurrence_start_date'])) {
            //If they leave the Event Start Date empty, the First Event Date in the recurrence module is selected
            $start_date = sanitize_text_field($_REQUEST['recurrence_start_date']);
        } elseif (isset($_POST['recurrence']) && $_POST['recurrence'] == 'Y' && !empty($_REQUEST['start_date'])) {
            $start_date = sanitize_text_field($_REQUEST['recurrence_manual_dates'][0]);
        } else {
            $start_date = !empty($_REQUEST['start_date']) ? sanitize_text_field($_REQUEST['start_date']) : date('Y-m-d', time() + 60 * 60 * 24 * 30);
        }
        $_REQUEST['start_date'] = $start_date;
        if (array_key_exists('recurrence_event_end_date', $recurrence_arr)) {
            //If this is a Recurring event
            $end_date = $recurrence_arr['recurrence_event_end_date'];
        } elseif (!empty($_REQUEST['end_date']) && !empty($_REQUEST['recurrence_event_end_date'])) {
            //If they leave the Event Start Date empty, the First Event Date in the recurrence module is selected
            $end_date = $_REQUEST['recurrence_event_end_date'];
        } elseif (isset($_POST['recurrence']) && $_POST['recurrence'] == 'Y' && !empty($_REQUEST['end_date'])) {
            $end_date = $_REQUEST['recurrence_manual_end_dates'][count($_REQUEST['recurrence_manual_end_dates']) - 1];
        } else {
            $end_date = !empty($_REQUEST['end_date']) ? $_REQUEST['end_date'] : date('Y-m-d', time() + 60 * 60 * 24 * 30);
        }
        $_REQUEST['end_date'] = $end_date;
        if (array_key_exists('visible_on', $recurrence_arr)) {
            //If this is a Recurring event
            $visible_on = $recurrence_arr['visible_on'];
        } elseif (isset($_REQUEST['visible_on']) && $_REQUEST['visible_on'] != '') {
            $visible_on = $_REQUEST['visible_on'];
        } elseif (isset($_REQUEST['visible_on']) && $_REQUEST['visible_on'] == '' && count($recurrence_dates) > 0) {
            $visible_on = $recurrence_dates[$start_date]['visible_on'];
        } else {
            $visible_on = date("Y-m-d");
        }
        //Questions/question groups
        $question_groups = empty($_REQUEST['question_groups']) ? serialize(array(1)) : serialize($_REQUEST['question_groups']);
        $add_attendee_question_groups = empty($_REQUEST['add_attendee_question_groups']) ? '' : $_REQUEST['add_attendee_question_groups'];
        //Process event meta data
        $event_meta['venue_id'] = isset($_REQUEST['venue_id']) ? $_REQUEST['venue_id'][0] : 0;
        $event_meta['additional_attendee_reg_info'] = !empty($_REQUEST['additional_attendee_reg_info']) ? sanitize_text_field($_REQUEST['additional_attendee_reg_info']) : '2';
        $event_meta['add_attendee_question_groups'] = $add_attendee_question_groups;
        $event_meta['date_submitted'] = date("Y-m-d H:i:s");
        $event_meta['default_payment_status'] = !empty($_REQUEST['default_payment_status']) ? sanitize_text_field($_REQUEST['default_payment_status']) : '';
        //Process thumbnail uploads
        $event_thumbnail_url = '';
        if (isset($_REQUEST['upload_image']) && !empty($_REQUEST['upload_image'])) {
            $event_meta['event_thumbnail_url'] = sanitize_text_field($_REQUEST['upload_image']);
            $event_thumbnail_url = sanitize_text_field($event_meta['event_thumbnail_url']);
        }
        if (isset($_REQUEST['emeta']) && !empty($_REQUEST['emeta'])) {
            foreach ($_REQUEST['emeta'] as $k => $v) {
                $event_meta[$v] = strlen(trim($_REQUEST['emetad'][$k])) > 0 ? sanitize_text_field($_REQUEST['emetad'][$k]) : '';
            }
        }
        $event_meta = serialize($event_meta);
        //echo strlen(trim($_REQUEST['emetad'][$k]));
        //print_r($_REQUEST['emeta'] );
        ############ Added by wp-developers ######################
        $require_pre_approval = 0;
        if (isset($_REQUEST['require_pre_approval'])) {
            $require_pre_approval = sanitize_text_field($_REQUEST['require_pre_approval']);
        }
        ################# END #################
        //When adding colums to the following arrays, be sure both arrays have equal values.
        $sql = array('event_code' => $event_code, 'event_name' => $event_name, 'event_desc' => $event_desc, 'display_desc' => $display_desc, 'display_reg_form' => $display_reg_form, 'event_identifier' => $event_identifier, 'address' => $address, 'address2' => $address2, 'city' => $city, 'state' => $state, 'zip' => $zip, 'country' => $country, 'phone' => $phone, 'virtual_url' => $virtual_url, 'virtual_phone' => $virtual_phone, 'venue_title' => $venue_title, 'venue_url' => $venue_url, 'venue_phone' => $venue_phone, 'venue_image' => $venue_image, 'registration_start' => $registration_start, 'registration_end' => $registration_end, 'start_date' => $start_date, 'end_date' => $end_date, 'allow_multiple' => $allow_multiple, 'send_mail' => $send_mail, 'is_active' => $is_active, 'event_status' => $event_status, 'conf_mail' => $conf_mail, 'use_coupon_code' => $use_coupon_code, 'member_only' => $member_only, 'externalURL' => $externalURL, 'early_disc' => $early_disc, 'early_disc_date' => $early_disc_date, 'early_disc_percentage' => $early_disc_percentage, 'alt_email' => $alt_email, 'question_groups' => $question_groups, 'registration_startT' => $registration_startT, 'registration_endT' => $registration_endT, 'reg_limit' => (int) $reg_limit, 'additional_limit' => (int) $additional_limit, 'recurrence_id' => $recurrence_id, 'email_id' => (int) $email_id, 'wp_user' => (int) $current_user->ID, 'event_meta' => $event_meta, 'require_pre_approval' => $require_pre_approval, 'timezone_string' => $timezone_string, 'submitted' => date('Y-m-d H:i:s', time()), 'ticket_id' => (int) $ticket_id);
        $sql_data = array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d', '%s', '%s', '%s', '%s', '%d');
        /* echo 'Debug: <br />';
        	  print_r($sql);
        	  echo '<br />';
        	  print 'Number of vars: ' . count ($sql);
        	  echo '<br />';
        	  print 'Number of cols: ' . count($sql_data); */
        //Add groupon reference if installed
        if (function_exists('event_espresso_add_event_to_db_groupon')) {
            $sql = event_espresso_add_event_to_db_groupon($sql, sanitize_text_field($_REQUEST['use_groupon_code']));
            //print count ($sql);
            $sql_data = array_merge((array) $sql_data, (array) '%s');
            //print count($sql_data);
            if (!$wpdb->insert(EVENTS_DETAIL_TABLE, $sql, $sql_data)) {
                $error = true;
            }
        } else {
            if (!$wpdb->insert(EVENTS_DETAIL_TABLE, $sql, $sql_data)) {
                $error = true;
            }
        }
        $last_event_id = $wpdb->insert_id;
        ############# MailChimp Integration ##############
        if (defined('EVENTS_MAILCHIMP_ATTENDEE_REL_TABLE') && $espresso_premium == true) {
            MailChimpController::add_event_list_rel($last_event_id);
        }
        if (function_exists('espresso_fb_createevent') == 'true' && $espresso_premium == true) {
            espresso_fb_createevent($last_event_id);
        }
        //Added for seating chart addon
        if (isset($_REQUEST['seating_chart_id'])) {
            $cls_seating_chart = new seating_chart();
            $cls_seating_chart->associate_event_seating_chart($_REQUEST['seating_chart_id'], $last_event_id);
        }
        //Add event to a category
        $string_cat = '';
        if (isset($_REQUEST['event_category']) && $_REQUEST['event_category'] != '') {
            foreach ($_REQUEST['event_category'] as $k => $v) {
                if ($v != '') {
                    $sql_cat = "INSERT INTO " . EVENTS_CATEGORY_REL_TABLE . " (event_id, cat_id) VALUES ('" . $last_event_id . "', '" . (int) $v . "')";
                    if (!$wpdb->query($wpdb->prepare($sql_cat, NULL))) {
                        $error = true;
                    }
                    //We get the category id's of the event and put them in events_detail_table.category_id as a well-formatted string (id,n id)
                    $string_cat .= $v . ",";
                }
            }
            if ($string_cat != "" && $string_cat != ",") {
                $cleaned_string_cat = substr($string_cat, 0, -1);
                $tmp = explode(",", $cleaned_string_cat);
                sort($tmp);
                $cleaned_string_cat = implode(",", $tmp);
                trim($cleaned_string_cat);
                $sql_insert_event_detail_category_id = "UPDATE " . EVENTS_DETAIL_TABLE . " SET category_id = '" . $cleaned_string_cat . "' WHERE id='" . $last_event_id . "'";
                $wpdb->query($wpdb->prepare($sql_insert_event_detail_category_id, NULL));
            }
        }
        //Process staff assignments
        if (isset($_REQUEST['event_person']) && !empty($_REQUEST['event_person'])) {
            foreach ($_REQUEST['event_person'] as $k => $v) {
                if ($v != '') {
                    $sql_ppl = "INSERT INTO " . EVENTS_PERSONNEL_REL_TABLE . " (event_id, person_id) VALUES ('" . $last_event_id . "', '" . $v . "')";
                    //echo "$sql_ppl <br>";
                    $wpdb->query($wpdb->prepare($sql_ppl, NULL));
                }
            }
        }
        //Process dynamic adding of venues
        //If we are adding an venue from within the event editor.
        //Then we need to add it to the venue database and add the id to the event.
        if (isset($_REQUEST['add_new_venue_dynamic']) && $_REQUEST['add_new_venue_dynamic'] == 'true' && $_REQUEST['venue_id'][0] == '0') {
            require_once EVENT_ESPRESSO_INCLUDES_DIR . 'admin-files/venue-management/add_venue_to_db.php';
            $_REQUEST['venue_id'][0] = add_venue_to_db();
        }
        //Process venues
        if (isset($_REQUEST['venue_id']) && !empty($_REQUEST['venue_id'])) {
            foreach ($_REQUEST['venue_id'] as $k => $v) {
                if ($v != '' && $v != 0) {
                    $sql_venues = "INSERT INTO " . EVENTS_VENUE_REL_TABLE . " (event_id, venue_id) VALUES ('" . $last_event_id . "', '" . $v . "')";
                    $wpdb->query($wpdb->prepare($sql_venues, NULL));
                }
            }
        }
        //Process the discounts
        if (isset($_REQUEST['event_discount']) && !empty($_REQUEST['event_discount']) && $_REQUEST['use_coupon_code'] == 'Y') {
            //if they have specified to use specific coupon codes, THEN we add entries ot teh discount rel table
            //otherwise we shouldn't
            foreach ($_REQUEST['event_discount'] as $k => $v) {
                if ($v != '') {
                    $sql_cat = "INSERT INTO " . EVENTS_DISCOUNT_REL_TABLE . " (event_id, discount_id) VALUES ('" . $last_event_id . "', '" . $v . "')";
                    if (!$wpdb->query($wpdb->prepare($sql_cat, NULL))) {
                        $error = true;
                    }
                }
            }
        }
        //Process event times
        if (isset($_REQUEST['start_time']) && !empty($_REQUEST['start_time'])) {
            foreach ($_REQUEST['start_time'] as $k => $v) {
                $time_qty = isset($_REQUEST['time_qty']) && strlen(trim($_REQUEST['time_qty'][$k])) > 0 ? "'" . $_REQUEST['time_qty'][$k] . "'" : '0';
                $v = !empty($v) ? $v : $start_time;
                $_REQUEST['end_time'][$k] = !empty($_REQUEST['end_time'][$k]) ? $_REQUEST['end_time'][$k] : $end_time;
                $sql3 = "INSERT INTO " . EVENTS_START_END_TABLE . " (event_id, start_time, end_time, reg_limit) VALUES ('" . $last_event_id . "', '" . event_date_display($v, 'H:i') . "', '" . event_date_display($_REQUEST['end_time'][$k], 'H:i') . "', " . $time_qty . ")";
                if (!$wpdb->query($wpdb->prepare($sql3, NULL))) {
                    $error = true;
                }
            }
        }
        //Process event costs
        if (isset($_REQUEST['event_cost']) && !empty($_REQUEST['event_cost'])) {
            foreach ($_REQUEST['event_cost'] as $k => $v) {
                if ($v != '') {
                    $v = (double) preg_replace('/[^0-9\\.]/ui', '', $v);
                    //Removes non-integer characters
                    $price_type = !empty($_REQUEST['price_type'][$k]) ? sanitize_text_field(stripslashes_deep($_REQUEST['price_type'][$k])) : __('General Admission', 'event_espresso');
                    $member_price_type = !empty($_REQUEST['member_price_type'][$k]) ? sanitize_text_field(stripslashes_deep($_REQUEST['member_price_type'][$k])) : __('Members Admission', 'event_espresso');
                    $member_price = !empty($_REQUEST['member_price'][$k]) ? $_REQUEST['member_price'][$k] : $v;
                    //$sql_price = "INSERT INTO " . EVENTS_PRICES_TABLE . " (event_id, event_cost, surcharge, surcharge_type, price_type, member_price, member_price_type) VALUES ('" . $last_event_id . "', '" . $v . "', '" . $_REQUEST['surcharge'][$k] . "', '" . $_REQUEST['surcharge_type'][$k] . "', '" . $price_type . "', '" . $member_price . "', '" . $member_price_type . "')";
                    //echo "$sql3 <br>";
                    $sql_price = array('event_id' => $last_event_id, 'event_cost' => $v, 'surcharge' => $_REQUEST['surcharge'][$k], 'surcharge_type' => $_REQUEST['surcharge_type'][$k], 'price_type' => $price_type, 'member_price' => $member_price, 'member_price_type' => $member_price_type);
                    $sql_price_data = array('%d', '%s', '%s', '%s', '%s', '%s', '%s');
                    if (!$wpdb->insert(EVENTS_PRICES_TABLE, $sql_price, $sql_price_data)) {
                        $error = true;
                    }
                }
            }
        } elseif (isset($_REQUEST['event_cost']) && $_REQUEST['event_cost'][0] == 0) {
            $sql_price = "INSERT INTO " . EVENTS_PRICES_TABLE . " (event_id, event_cost, surcharge, price_type, member_price, member_price_type) VALUES ('" . $last_event_id . "', '0.00', '0.00', '" . __('Free', 'event_espresso') . "', '0.00', '" . __('Free', 'event_espresso') . "')";
            if (!$wpdb->query($wpdb->prepare($sql_price, NULL))) {
                $error = true;
            }
        }
        //Process blog or custom post
        if (isset($_REQUEST['create_post']) && $_REQUEST['create_post'] == 'Y') {
            $post_type = !empty($_REQUEST['espresso_post_type']) ? $_REQUEST['espresso_post_type'] : 'post';
            if ($post_type == 'post') {
                if (file_exists(EVENT_ESPRESSO_TEMPLATE_DIR . "event_post.php") || file_exists(EVENT_ESPRESSO_PLUGINFULLPATH . "templates/event_post.php")) {
                    // Load message from template into message post variable
                    ob_start();
                    if (file_exists(EVENT_ESPRESSO_TEMPLATE_DIR . "event_post.php")) {
                        require_once EVENT_ESPRESSO_TEMPLATE_DIR . "event_post.php";
                    } else {
                        require_once EVENT_ESPRESSO_PLUGINFULLPATH . "templates/event_post.php";
                    }
                    $post_content = ob_get_contents();
                    ob_end_clean();
                } else {
                    _e('There was error finding a post template. Please verify your post templates are available.', 'event_espresso');
                }
            } elseif ($post_type == 'espresso_event') {
                ob_start();
                echo $event_desc;
                $post_content = ob_get_contents();
                ob_end_clean();
                // if there's a cart link shortcode in the post, replace the shortcode with one that includes the event_id
                if (preg_match("/ESPRESSO_CART_LINK/", $post_content)) {
                    $post_content = preg_replace('/ESPRESSO_CART_LINK/', 'ESPRESSO_CART_LINK event_id=' . $event_id, $post_content);
                }
            }
            $my_post = array();
            $my_post['post_title'] = sanitize_text_field($_REQUEST['event']);
            $my_post['post_content'] = $post_content;
            $my_post['post_status'] = 'publish';
            $my_post['post_author'] = !empty($_REQUEST['user']) ? $_REQUEST['user'] : '';
            $my_post['post_category'] = !empty($_REQUEST['post_category']) ? $_REQUEST['post_category'] : '';
            $my_post['tags_input'] = !empty($_REQUEST['post_tags']) ? $_REQUEST['post_tags'] : '';
            $my_post['post_type'] = !empty($post_type) ? $post_type : 'post';
            //print_r($my_post);
            // Insert the post into the database
            $post_id = wp_insert_post($my_post);
            // Store the POST ID so it can be displayed on the edit page
            $sql = array('post_id' => $post_id, 'post_type' => $post_type);
            add_post_meta($post_id, 'event_id', $last_event_id);
            add_post_meta($post_id, 'event_meta', $event_meta);
            add_post_meta($post_id, 'event_identifier', $event_identifier);
            add_post_meta($post_id, 'event_start_date', $start_date);
            add_post_meta($post_id, 'event_end_date', $end_date);
            add_post_meta($post_id, 'event_location', $event_location);
            add_post_meta($post_id, 'event_thumbnail_url', $event_thumbnail_url);
            add_post_meta($post_id, 'virtual_url', $virtual_url);
            add_post_meta($post_id, 'virtual_phone', $virtual_phone);
            add_post_meta($post_id, 'event_address', $address);
            add_post_meta($post_id, 'event_address2', $address2);
            add_post_meta($post_id, 'event_city', $city);
            add_post_meta($post_id, 'event_state', $state);
            add_post_meta($post_id, 'event_country', $country);
            add_post_meta($post_id, 'event_phone', $phone);
            add_post_meta($post_id, 'venue_title', $venue_title);
            add_post_meta($post_id, 'venue_url', $venue_url);
            add_post_meta($post_id, 'venue_phone', $venue_phone);
            add_post_meta($post_id, 'venue_image', $venue_image);
            add_post_meta($post_id, 'event_externalURL', $externalURL);
            add_post_meta($post_id, 'event_reg_limit', $reg_limit);
            add_post_meta($post_id, 'event_start_time', time_to_24hr($start_time));
            add_post_meta($post_id, 'event_end_time', time_to_24hr($end_time));
            add_post_meta($post_id, 'event_registration_start', $registration_start);
            add_post_meta($post_id, 'event_registration_end', $registration_end);
            add_post_meta($post_id, 'event_registration_startT', $registration_startT);
            add_post_meta($post_id, 'event_registration_endT', $registration_endT);
            //add_post_meta( $post_id, 'timezone_string', $_REQUEST['timezone_string'] );
            $sql_data = array('%d', '%s');
            $update_id = array('id' => $last_event_id);
            $wpdb->update(EVENTS_DETAIL_TABLE, $sql, $update_id, $sql_data, array('%d'));
        }
        if (empty($error)) {
            ?>
			<div id="message" class="updated fade"><p><strong><?php 
            _e('The event', 'event_espresso');
            ?>
			<a href="<?php 
            echo espresso_reg_url($last_event_id);
            ?>
" target="_blank">
				<?php 
            echo htmlentities(stripslashes(sanitize_text_field($_REQUEST['event'])), ENT_QUOTES, 'UTF-8');
            ?>
				
			</a>

			<?php 
            _e('has been added for ', 'event_espresso');
            echo date("m/d/Y", strtotime($start_date));
            ?>
 <a href="<?php 
            echo admin_url();
            ?>
admin.php?page=events&action=edit&event_id=<?php 
            echo $last_event_id;
            ?>
"><?php 
            _e('Edit this event?', 'event_espresso');
            ?>
</a></strong></p></div>
		<?php 
        } else {
            ?>
			<div id="message" class="error"><p><strong><?php 
            _e('There was an error in your submission. The event was not saved! Please try again.', 'event_espresso');
            ?>
 <?php 
            print $wpdb->print_error();
            ?>
</strong></p></div>
			<?php 
        }
    }
    //With the recursion of this function, additional recurring events will be added
    if (isset($recurrence_dates) && count($recurrence_dates) > 0) {
        foreach ($recurrence_dates as $k => $v) {
            add_event_to_db(array('recurrence_id' => $recurrence_id, 'recurrence_start_date' => $v['start_date'], 'recurrence_event_end_date' => $v['event_end_date'], 'registration_start' => $v['registration_start'], 'registration_end' => $v['registration_end']));
        }
    }
    $_REQUEST['event_id'] = !empty($last_event_id) ? $last_event_id : '';
    do_action('action_hook_espresso_insert_event_success', $_REQUEST);
    //If not using the FEM addon, then we return the event id
    if (!$use_fem === TRUE) {
        return @$last_event_id;
    }
}
Exemplo n.º 19
0
function espresso_confirm_registration($registration_id)
{
    global $wpdb, $org_options;
    //Get the questions for the attendee
    $questions = $wpdb->get_results("SELECT ea.answer, eq.question\n\t\t\t\t\t\tFROM " . EVENTS_ANSWER_TABLE . " ea\n\t\t\t\t\t\tLEFT JOIN " . EVENTS_QUESTION_TABLE . " eq ON eq.id = ea.question_id\n\t\t\t\t\t\tWHERE ea.registration_id = '" . $registration_id . "' AND system_name IS NULL ORDER BY eq.sequence asc ");
    //echo $wpdb->last_query;
    $display_questions = '';
    foreach ($questions as $question) {
        $display_questions .= '<p class="espresso_questions"><strong>' . $question->question . '</strong>:<br /> ' . str_replace(',', '<br />', $question->answer) . '</p>';
    }
    //Get the event information
    $events = $wpdb->get_results("SELECT ed.* FROM " . EVENTS_DETAIL_TABLE . " ed\n\t\t\t\t\t\tJOIN " . EVENTS_ATTENDEE_TABLE . " ea\n\t\t\t\t\t\tON ed.id = ea.event_id\n\t\t\t\t\t\tWHERE ea.registration_id='" . $registration_id . "'");
    foreach ($events as $event) {
        $event_id = $event->id;
        $event_name = stripslashes_deep($event->event_name);
        $event_desc = stripslashes_deep($event->event_desc);
        $display_desc = $event->display_desc;
        $event_identifier = $event->event_identifier;
        $reg_limit = $event->reg_limit;
        $active = $event->is_active;
        $send_mail = $event->send_mail;
        $conf_mail = $event->conf_mail;
        $email_id = $event->email_id;
        $alt_email = $event->alt_email;
        $start_date = event_date_display($event->start_date);
        $end_date = $event->end_date;
        $virtual_url = $event->virtual_url;
        $virtual_phone = $event->virtual_phone;
        $event_address = $event->address;
        $event_address2 = $event->address2;
        $event_city = $event->city;
        $event_state = $event->state;
        $event_zip = $event->zip;
        $event_country = $event->country;
        $location = ($event_address != '' ? $event_address : '') . ($event_address2 != '' ? '<br />' . $event_address2 : '') . ($event_city != '' ? '<br />' . $event_city : '') . ($event_state != '' ? ', ' . $event_state : '') . ($event_zip != '' ? '<br />' . $event_zip : '') . ($event_country != '' ? '<br />' . $event_country : '');
        $location_phone = $event->phone;
        $require_pre_approval = $event->require_pre_approval;
        $google_map_link = espresso_google_map_link(array('address' => $event_address, 'city' => $event_city, 'state' => $event_state, 'zip' => $event_zip, 'country' => $event_country));
    }
    //Build links
    $event_url = espresso_reg_url($event_id);
    $event_link = '<a href="' . $event_url . '">' . $event_name . '</a>';
    $sql = "SELECT * FROM " . EVENTS_ATTENDEE_TABLE;
    if ($registration_id != '') {
        $sql .= " WHERE registration_id = '" . $registration_id . "' ";
    } elseif ($attendee_id != '') {
        $sql .= " WHERE id = '" . $attendee_id . "' ";
    } else {
        _e('No ID Supplied', 'event_espresso');
    }
    $sql .= " ORDER BY id ";
    $sql .= " LIMIT 0,1 ";
    //Get the first attendees details
    $attendees = $wpdb->get_results($sql);
    //global $attendee_id;
    foreach ($attendees as $attendee) {
        $attendee_id = $attendee->id;
        $attendee_email = $attendee->email;
        $lname = $attendee->lname;
        $fname = $attendee->fname;
        $address = $attendee->address;
        $address2 = $attendee->address2;
        $city = $attendee->city;
        $state = $attendee->state;
        $zip = $attendee->zip;
        $payment_status = $attendee->payment_status;
        $txn_type = $attendee->txn_type;
        $amount_pd = $attendee->amount_pd;
        $event_cost = $attendee->amount_pd;
        $payment_date = $attendee->payment_date;
        $phone = $attendee->phone;
        $event_time = $attendee->event_time;
        $end_time = $attendee->end_time;
        $date = $attendee->date;
        $pre_approve = $attendee->pre_approve;
    }
    ####### Added by wp-developers ##############
    $pre_approval_check = is_attendee_approved($event_id, $attendee_id);
    ###########################################
    ###### Modified by wp-developers ###############
    if ($pre_approval_check) {
        //Pull in the "Thank You" page template
        if (file_exists(EVENT_ESPRESSO_TEMPLATE_DIR . "payment_page.php")) {
            require_once EVENT_ESPRESSO_TEMPLATE_DIR . "payment_page.php";
            //This is the path to the template file if available
        } else {
            require_once EVENT_ESPRESSO_PLUGINFULLPATH . "templates/payment_page.php";
        }
        if ($amount_pd != '0.00') {
            //Show payment options
            if (file_exists(EVENT_ESPRESSO_GATEWAY_DIR . "gateway_display.php")) {
                require_once EVENT_ESPRESSO_GATEWAY_DIR . "gateway_display.php";
            } else {
                require_once EVENT_ESPRESSO_PLUGINFULLPATH . "gateways/gateway_display.php";
            }
            //Check to see if the site owner wants to send an confirmation eamil before payment is recieved.
            if ($org_options['email_before_payment'] == 'Y') {
                event_espresso_email_confirmations(array('registration_id' => $registration_id, 'send_admin_email' => 'true', 'send_attendee_email' => 'true'));
            }
        } else {
            event_espresso_email_confirmations(array('registration_id' => $registration_id, 'send_admin_email' => 'true', 'send_attendee_email' => 'true'));
        }
    } else {
        if (file_exists(EVENT_ESPRESSO_PLUGINFULLPATH . 'includes/process-registration/pending_approval_page.php')) {
            require_once 'pending_approval_page.php';
            echo espresso_pending_registration_approval($registration_id);
            return;
        }
    }
    ################ End ##############################
    //return __('Your Registration Has Been Confirmed', 'event_espresso');
    //unset($_SESSION['espresso_session']['id']);
    //session_destroy();
}
Exemplo n.º 20
0
function update_event($recurrence_arr = array())
{
    //print_r($_REQUEST);
    global $wpdb, $org_options, $current_user, $espresso_premium;
    $wpdb->show_errors();
    /*
     * Begin Recurrence handling
     *
     * Will clean up in V 1.2.0
     *
     */
    if (get_option('event_espresso_re_active') == 1) {
        require_once EVENT_ESPRESSO_RECURRENCE_FULL_PATH . "functions/re_functions.php";
        if ($_POST['recurrence_id'] > 0) {
            /*
             * If the array is empty, then find the recurring dates
             */
            if (count($recurrence_arr) == 0) {
                // Prepare the parameters array for use with various RE functions
                $re_params = array('start_date' => $_POST['recurrence_start_date'], 'event_end_date' => $_POST['recurrence_event_end_date'], 'end_date' => $_POST['recurrence_end_date'], 'registration_start' => $_POST['recurrence_regis_start_date'], 'registration_end' => $_POST['recurrence_regis_end_date'], 'frequency' => $_POST['recurrence_frequency'], 'interval' => $_POST['recurrence_interval'], 'recurrence_type' => $_POST['recurrence_type'], 'weekdays' => $_POST['recurrence_weekday'], 'repeat_by' => $_POST['recurrence_repeat_by'], 'recurrence_regis_date_increment' => $_POST['recurrence_regis_date_increment'], 'recurrence_manual_dates' => $_POST['recurrence_manual_dates'], 'recurrence_manual_end_dates' => $_POST['recurrence_manual_end_dates'], 'recurrence_visibility' => $_POST['recurrence_visibility'], 'recurrence_id' => $_POST['recurrence_id']);
                //$re_params['adding_to_db'] = 'Y';
                //Has the form been modified
                $recurrence_form_modified = recurrence_form_modified($re_params);
                //echo ($recurrence_form_modified) ? "Yes" : 'No';
                if ($_POST['recurrence_apply_changes_to'] == 2) {
                    //Update all events in the series based on recurrence id
                    $recurrence_dates = $_POST['recurrence_type'] == 'm' ? find_recurrence_manual_dates($re_params) : find_recurrence_dates($re_params);
                    //$DEL_SQL = 'UPDATE ' . EVENTS_DETAIL_TABLE . " SET event_status = 'D' WHERE start_date NOT IN (" . $delete_in . ") AND recurrence_id = " . $wpdb->escape($_POST['recurrence_id']);
                    $UPDATE_SQL = "SELECT id,start_date,event_identifier FROM " . EVENTS_DETAIL_TABLE . " WHERE recurrence_id = %d AND NOT event_status = 'D'";
                } else {
                    //Update this and upcoming events based on recurrence id and start_date >=start_date
                    $re_params['start_date'] = $_POST['start_date'];
                    $recurrence_dates = find_recurrence_dates($re_params);
                    //$DEL_SQL = 'UPDATE ' . EVENTS_DETAIL_TABLE . " SET event_status = 'D' WHERE start_date >='" . $wpdb->escape($_POST['start_date']) . "' AND start_date NOT IN (" . $delete_in . ") AND recurrence_id = " . $_POST['recurrence_id'];
                    $UPDATE_SQL = "SELECT id,start_date,event_identifier FROM " . EVENTS_DETAIL_TABLE . " WHERE start_date >='" . $wpdb->escape($_POST['start_date']) . "' AND recurrence_id = %d and NOT event_status = 'D' ";
                }
                //Recurrence Form modified and changes need to apply to all
                if ($recurrence_form_modified && $_POST['recurrence_apply_changes_to'] > 1) {
                    //Update the recurrence table record with the new RE selections
                    update_recurrence_master_record();
                    /*
                     * Delete the records that don't belong in the formula
                     */
                    if (count($recurrence_dates) > 0) {
                        $delete_in = '';
                        foreach ($recurrence_dates as $k => $v) {
                            $delete_in .= "'" . $k . "',";
                        }
                        $delete_in = substr($delete_in, 0, -1);
                    }
                    if ($_POST['recurrence_apply_changes_to'] == 2) {
                        //Update all events in the series based on recurrence id
                        //$DEL_SQL = 'UPDATE ' . EVENTS_DETAIL_TABLE . " SET event_status = 'D' WHERE start_date NOT IN (" . $delete_in . ") AND recurrence_id = " . $_POST['recurrence_id'];
                        $DEL_SQL = 'DELETE EDT, EAT FROM ' . EVENTS_DETAIL_TABLE . " EDT\n                            LEFT JOIN " . EVENTS_ATTENDEE_TABLE . " EAT\n                                ON EDT.id = EAT.event_id\n                            WHERE EAT.id IS NULL\n                            AND EDT.start_date NOT IN (" . $delete_in . ")\n                            AND recurrence_id = " . $_POST['recurrence_id'];
                        $UPDATE_SQL = "SELECT id,start_date,event_identifier FROM " . EVENTS_DETAIL_TABLE . " WHERE recurrence_id = %d and NOT event_status = 'D' ORDER BY start_date";
                    } else {
                        //Update this and upcoming events based on recurrence id and start_date >=start_date
                        //$DEL_SQL = 'UPDATE ' . EVENTS_DETAIL_TABLE . " SET event_status = 'D' WHERE start_date >='" . $wpdb->escape($_POST['start_date']) . "' AND start_date NOT IN (" . $delete_in . ") AND recurrence_id = " . $_POST['recurrence_id'];
                        $DEL_SQL = 'DELETE EDT, EAT FROM ' . EVENTS_DETAIL_TABLE . " EDT\n                            LEFT JOIN " . EVENTS_ATTENDEE_TABLE . " EAT\n                                ON EDT.id = EAT.event_id\n                            WHERE EAT.id IS NULL\n                            AND EDT.start_date >='" . $wpdb->escape($_POST['start_date']) . "'\n                            AND start_date NOT IN (" . $delete_in . ")\n                            AND recurrence_id = " . $_POST['recurrence_id'];
                        $UPDATE_SQL = "SELECT id,start_date,event_identifier FROM " . EVENTS_DETAIL_TABLE . " WHERE start_date >='" . $wpdb->escape($_POST['start_date']) . "' AND recurrence_id = %d AND NOT event_status = 'D'  ORDER BY start_date";
                    }
                    if ($delete_in != '') {
                        $wpdb->query($DEL_SQL);
                    }
                    /*
                     * Add the new records based on the new formula
                     * The $recurrence_dates array will contain the new dates
                     */
                    if (!function_exists('add_event_to_db')) {
                        require_once 'insert_event.php';
                    }
                    foreach ($recurrence_dates as $k => $v) {
                        $result = $wpdb->get_row($wpdb->prepare("SELECT ID FROM " . EVENTS_DETAIL_TABLE . " WHERE recurrence_id = %d and start_date = %s and NOT event_status = 'D'", array($_POST['recurrence_id'], $k)));
                        if ($wpdb->num_rows == 0) {
                            add_event_to_db(array('recurrence_id' => $_POST['recurrence_id'], 'recurrence_start_date' => $v['start_date'], 'recurrence_event_end_date' => $v['end_date'], 'recurrence_end_date' => $v['start_date'], 'registration_start' => $v['registration_start'], 'registration_end' => $v['registration_end']));
                        } else {
                        }
                    }
                    /*
                     * Find all the event ids in the series and feed into the $recurrence_dates array
                     * This array will be used at the end of this document to invoke the recursion of update_event function so all the events in the series
                     * can be updated with the information.
                     */
                }
                $result = $wpdb->get_results($wpdb->prepare($UPDATE_SQL, array($_POST['recurrence_id'])));
                foreach ($result as $row) {
                    if ($row->start_date != '') {
                        $recurrence_dates[$row->start_date]['event_id'] = $row->id;
                        $recurrence_dates[$row->start_date]['event_identifier'] = $row->event_identifier;
                    }
                }
            }
        }
    }
    //  echo_f('rd',$recurrence_dates);
    if (defined('EVENT_ESPRESSO_RECURRENCE_MODULE_ACTIVE') && !empty($_POST['recurrence']) && $_POST['recurrence'] == 'Y' && count($recurrence_arr) == 0 && $_POST['recurrence_apply_changes_to'] > 1) {
        //skip the first update
    } else {
        $event_mata = array();
        //will be used to hold event meta data
        $event_id = array_key_exists('event_id', $recurrence_arr) ? $recurrence_arr['event_id'] : $_REQUEST['event_id'];
        $event_name = $_REQUEST['event'];
        //$event_identifier=array_key_exists('event_identifier', $recurrence_arr)?$recurrence_arr['event_identifier']:($_REQUEST['event_identifier'] == '') ? $event_identifier = sanitize_title_with_dashes($event_name.'-'.rand()) : $event_identifier = sanitize_title_with_dashes($_REQUEST['event_identifier']);
        $event_desc = $_REQUEST['event_desc'];
        $display_desc = $_REQUEST['display_desc'];
        $display_reg_form = $_REQUEST['display_reg_form'];
        $reg_limit = $_REQUEST['reg_limit'];
        $allow_multiple = $_REQUEST['allow_multiple'];
        $overflow_event_id = empty($_REQUEST['overflow_event_id']) ? '0' : $_REQUEST['overflow_event_id'];
        $allow_overflow = empty($_REQUEST['allow_overflow']) ? 'N' : $_REQUEST['allow_overflow'];
        $additional_limit = $_REQUEST['additional_limit'];
        //$member_only=$_REQUEST['member_only'];
        $member_only = empty($_REQUEST['member_only']) ? 'N' : $_REQUEST['member_only'];
        $is_active = $_REQUEST['is_active'];
        $event_status = $_REQUEST['event_status'];
        $address = !empty($_REQUEST['address']) ? esc_html($_REQUEST['address']) : '';
        $address2 = !empty($_REQUEST['address2']) ? esc_html($_REQUEST['address2']) : '';
        $city = !empty($_REQUEST['city']) ? esc_html($_REQUEST['city']) : '';
        $state = !empty($_REQUEST['state']) ? esc_html($_REQUEST['state']) : '';
        $zip = !empty($_REQUEST['zip']) ? esc_html($_REQUEST['zip']) : '';
        $country = !empty($_REQUEST['country']) ? esc_html($_REQUEST['country']) : '';
        $phone = !empty($_REQUEST['phone']) ? esc_html($_REQUEST['phone']) : '';
        $externalURL = !empty($_REQUEST['externalURL']) ? esc_html($_REQUEST['externalURL']) : '';
        //$event_location = $address . ' ' . $city . ', ' . $state . ' ' . $zip;
        $event_location = ($address != '' ? $address . ' ' : '') . ($city != '' ? '<br />' . $city : '') . ($state != '' ? ', ' . $state : '') . ($zip != '' ? '<br />' . $zip : '') . ($country != '' ? '<br />' . $country : '');
        //Get the first instance of the start and end times
        $start_time = $_REQUEST['start_time'][0];
        $end_time = $_REQUEST['end_time'][0];
        // Add registration times
        $registration_startT = event_date_display($_REQUEST['registration_startT'], 'H:i');
        $registration_endT = event_date_display($_REQUEST['registration_endT'], 'H:i');
        //Add timezone
        $timezone_string = empty($_REQUEST['timezone_string']) ? '' : $_REQUEST['timezone_string'];
        //Early discounts
        $early_disc = $_REQUEST['early_disc'];
        $early_disc_date = $_REQUEST['early_disc_date'];
        $early_disc_percentage = $_REQUEST['early_disc_percentage'];
        $conf_mail = $_REQUEST['conf_mail'];
        $use_coupon_code = $_REQUEST['use_coupon_code'];
        $alt_email = $_REQUEST['alt_email'];
        $send_mail = $_REQUEST['send_mail'];
        $email_id = empty($_REQUEST['email_name']) ? '' : $_REQUEST['email_name'];
        $event_category = serialize(empty($_REQUEST['event_category']) ? '' : $_REQUEST['event_category']);
        $event_discount = serialize(empty($_REQUEST['event_discount']) ? '' : $_REQUEST['event_discount']);
        $registration_start = array_key_exists('registration_start', $recurrence_arr) ? $recurrence_arr['registration_start'] : $_REQUEST['registration_start'];
        $registration_end = array_key_exists('registration_end', $recurrence_arr) ? $recurrence_arr['registration_end'] : $_REQUEST['registration_end'];
        $start_date = array_key_exists('recurrence_start_date', $recurrence_arr) ? $recurrence_arr['recurrence_start_date'] : ($_REQUEST['start_date'] == '' ? $_REQUEST['recurrence_start_date'] : $_REQUEST['start_date']);
        $end_date = array_key_exists('recurrence_event_end_date', $recurrence_arr) ? $recurrence_arr['recurrence_event_end_date'] : ($_REQUEST['end_date'] == '' ? $_REQUEST['recurrence_start_date'] : $_REQUEST['end_date']);
        $visible_on = array_key_exists('visible_on', $recurrence_arr) ? $recurrence_arr['visible_on'] : empty($_REQUEST['visible_on']) ? '' : $_REQUEST['visible_on'];
        //Venue Information
        $venue_title = isset($_REQUEST['venue_title']) ? $_REQUEST['venue_title'] : '';
        $venue_url = isset($_REQUEST['venue_url']) ? $_REQUEST['venue_url'] : '';
        $venue_phone = isset($_REQUEST['venue_phone']) ? $_REQUEST['venue_phone'] : '';
        $venue_image = isset($_REQUEST['venue_image']) ? $_REQUEST['venue_image'] : '';
        //Virtual location
        $virtual_url = isset($_REQUEST['virtual_url']) ? $_REQUEST['virtual_url'] : '';
        $virtual_phone = isset($_REQUEST['virtual_phone']) ? $_REQUEST['virtual_phone'] : '';
        if (isset($reg_limit) && $reg_limit == '') {
            $reg_limit = 999999;
        }
        $question_groups = serialize($_REQUEST['question_groups']);
        $add_attendee_question_groups = serialize(empty($_REQUEST['add_attendee_question_groups']) ? '' : $_REQUEST['add_attendee_question_groups']);
        $event_mata['default_payment_status'] = $_REQUEST['default_payment_status'];
        $event_mata['venue_id'] = empty($_REQUEST['venue_id']) ? '' : $_REQUEST['venue_id'][0];
        $event_mata['additional_attendee_reg_info'] = $_REQUEST['additional_attendee_reg_info'];
        $event_mata['add_attendee_question_groups'] = empty($_REQUEST['add_attendee_question_groups']) ? '' : $_REQUEST['add_attendee_question_groups'];
        $event_mata['date_submitted'] = $_REQUEST['date_submitted'];
        /*
         * Added for seating chart addon
         */
        if (isset($_REQUEST['seating_chart_id'])) {
            $cls_seating_chart = new seating_chart();
            $seating_chart_result = $cls_seating_chart->associate_event_seating_chart($_REQUEST['seating_chart_id'], $event_id);
            $tmp_seating_chart_id = $_REQUEST['seating_chart_id'];
            if ($tmp_seating_chart_id > 0) {
                if ($seating_chart_result === false) {
                    $tmp_seating_chart_row = $wpdb->get_row("select seating_chart_id from " . EVENTS_SEATING_CHART_EVENT_TABLE . " where event_id = {$event_id}");
                    if ($tmp_seating_chart_row !== NULL) {
                        $tmp_seating_chart_id = $tmp_seating_chart_row->seating_chart_id;
                    } else {
                        $tmp_seating_chart_id = 0;
                    }
                }
                if ($_REQUEST['allow_multiple'] == 'Y' && isset($_REQUEST['seating_chart_id']) && $tmp_seating_chart_id > 0) {
                    $event_mata['additional_attendee_reg_info'] = 3;
                }
            }
        }
        /*
         * End
         */
        if ($_REQUEST['emeta'] != '') {
            foreach ($_REQUEST['emeta'] as $k => $v) {
                $event_mata[$v] = $_REQUEST['emetad'][$k];
            }
        }
        $event_mata = serialize($event_mata);
        ############ Added by wp-developers ######################
        $require_pre_approval = 0;
        if (isset($_REQUEST['require_pre_approval'])) {
            $require_pre_approval = $_REQUEST['require_pre_approval'];
        }
        ################# END #################
        //When adding colums to the following arrays, be sure both arrays have equal values.
        $sql = array('event_name' => $event_name, 'event_desc' => $event_desc, 'display_desc' => $display_desc, 'display_reg_form' => $display_reg_form, 'address' => $address, 'address2' => $address2, 'city' => $city, 'state' => $state, 'zip' => $zip, 'country' => $country, 'phone' => $phone, 'virtual_url' => $virtual_url, 'virtual_phone' => $virtual_phone, 'venue_title' => $venue_title, 'venue_url' => $venue_url, 'venue_phone' => $venue_phone, 'venue_image' => $venue_image, 'registration_start' => $registration_start, 'registration_end' => $registration_end, 'start_date' => $start_date, 'end_date' => $end_date, 'allow_multiple' => $allow_multiple, 'send_mail' => $send_mail, 'is_active' => $is_active, 'event_status' => $event_status, 'conf_mail' => $conf_mail, 'use_coupon_code' => $use_coupon_code, 'member_only' => $member_only, 'externalURL' => $externalURL, 'early_disc' => $early_disc, 'early_disc_date' => $early_disc_date, 'early_disc_percentage' => $early_disc_percentage, 'alt_email' => $alt_email, 'question_groups' => $question_groups, 'allow_overflow' => $allow_overflow, 'overflow_event_id' => $overflow_event_id, 'additional_limit' => $additional_limit, 'reg_limit' => $reg_limit, 'email_id' => $email_id, 'registration_startT' => $registration_startT, 'registration_endT' => $registration_endT, 'event_meta' => $event_mata, 'require_pre_approval' => $require_pre_approval, 'timezone_string' => $timezone_string);
        $sql_data = array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%d', '%d', '%s', '%s', '%s', '%s', '%s');
        $update_id = array('id' => $event_id);
        /* echo 'Debug: <br />';
           print_r($sql);
           echo '<br />';
           print 'Number of vars: ' . count ($sql);
           echo '<br />';
           print 'Number of cols: ' . count($sql_data); */
        if (function_exists('event_espresso_add_event_to_db_groupon')) {
            $sql = event_espresso_add_event_to_db_groupon($sql, $_REQUEST['use_groupon_code']);
            ///print count ($sql);
            $sql_data = array_merge((array) $sql_data, (array) '%s');
            //print count($sql_data);
            $wpdb->update(EVENTS_DETAIL_TABLE, $sql, $update_id, $sql_data, array('%d'));
            /* echo 'Debug: <br />';
               print 'Number of vars: ' . count ($sql);
               echo '<br />';
               print 'Number of cols: ' . count($sql_data); */
        } else {
            $wpdb->update(EVENTS_DETAIL_TABLE, $sql, $update_id, $sql_data, array('%d'));
            /* echo 'Debug: <br />';
               print 'Number of vars: ' . count ($sql);
               echo '<br />';
               print 'Number of cols: ' . count($sql_data); */
        }
        //print $wpdb->print_error();
        $del_cats = "DELETE FROM " . EVENTS_CATEGORY_REL_TABLE . " WHERE event_id = '" . $event_id . "'";
        $wpdb->query($del_cats);
        if (!empty($_REQUEST['event_category'])) {
            foreach ($_REQUEST['event_category'] as $k => $v) {
                if ($v != '') {
                    $sql_cat = "INSERT INTO " . EVENTS_CATEGORY_REL_TABLE . " (event_id, cat_id) VALUES ('" . $event_id . "', '" . $v . "')";
                    //echo "$sql_cat <br>";
                    $wpdb->query($sql_cat);
                }
            }
        }
        $del_ppl = "DELETE FROM " . EVENTS_PERSONNEL_REL_TABLE . " WHERE event_id = '" . $event_id . "'";
        $wpdb->query($del_ppl);
        if (!empty($_REQUEST['event_person'])) {
            foreach ($_REQUEST['event_person'] as $k => $v) {
                if ($v != '') {
                    $sql_ppl = "INSERT INTO " . EVENTS_PERSONNEL_REL_TABLE . " (event_id, person_id) VALUES ('" . $event_id . "', '" . $v . "')";
                    //echo "$sql_ppl <br>";
                    $wpdb->query($sql_ppl);
                }
            }
        }
        $del_venues = "DELETE FROM " . EVENTS_VENUE_REL_TABLE . " WHERE event_id = '" . $event_id . "'";
        $wpdb->query($del_venues);
        if (!empty($_REQUEST['venue_id'])) {
            foreach ($_REQUEST['venue_id'] as $k => $v) {
                if ($v != '' && $v != 0) {
                    $sql_venues = "INSERT INTO " . EVENTS_VENUE_REL_TABLE . " (event_id, venue_id) VALUES ('" . $event_id . "', '" . $v . "')";
                    //echo "$sql_venues <br>";
                    $wpdb->query($sql_venues);
                }
            }
        }
        $del_discounts = "DELETE FROM " . EVENTS_DISCOUNT_REL_TABLE . " WHERE event_id = '" . $event_id . "'";
        $wpdb->query($del_discounts);
        if (!empty($_REQUEST['event_discount'])) {
            foreach ($_REQUEST['event_discount'] as $k => $v) {
                if ($v != '') {
                    $sql_discount = "INSERT INTO " . EVENTS_DISCOUNT_REL_TABLE . " (event_id, discount_id) VALUES ('" . $event_id . "', '" . $v . "')";
                    //echo "$sql_discount <br>";
                    $wpdb->query($sql_discount);
                }
            }
        }
        $del_times = "DELETE FROM " . EVENTS_START_END_TABLE . " WHERE event_id = '" . $event_id . "'";
        $wpdb->query($del_times);
        if ($_REQUEST['start_time'] != '') {
            foreach ($_REQUEST['start_time'] as $k => $v) {
                if ($v != '') {
                    $time_qty = empty($_REQUEST['time_qty'][$k]) ? '0' : "'" . $_REQUEST['time_qty'][$k] . "'";
                    $sql_times = "INSERT INTO " . EVENTS_START_END_TABLE . " (event_id, start_time, end_time, reg_limit) VALUES ('" . $event_id . "', '" . event_date_display($v, 'H:i') . "', '" . event_date_display($_REQUEST['end_time'][$k], 'H:i') . "', " . $time_qty . ")";
                    //echo "$sql_times <br>";
                    $wpdb->query($sql_times);
                }
            }
        }
        $del_prices = "DELETE FROM " . EVENTS_PRICES_TABLE . " WHERE event_id = '" . $event_id . "'";
        $wpdb->query($del_prices);
        if (!empty($_REQUEST['event_cost'])) {
            foreach ($_REQUEST['event_cost'] as $k => $v) {
                if ($v != '') {
                    $price_type = $_REQUEST['price_type'][$k] != '' ? $_REQUEST['price_type'][$k] : __('General Admission', 'event_espresso');
                    $member_price_type = !empty($_REQUEST['member_price_type'][$k]) ? $_REQUEST['member_price_type'][$k] : __('Members Admission', 'event_espresso');
                    $member_price = !empty($_REQUEST['member_price'][$k]) ? $_REQUEST['member_price'][$k] : $v;
                    $sql_prices = "INSERT INTO " . EVENTS_PRICES_TABLE . " (event_id, event_cost, surcharge, surcharge_type, price_type, member_price, member_price_type) VALUES ('" . $event_id . "', '" . $v . "', '" . $_REQUEST['surcharge'][$k] . "', '" . $_REQUEST['surcharge_type'][$k] . "', '" . $price_type . "', '" . $member_price . "', '" . $member_price_type . "')";
                    //echo "$sql_prices <br>";
                    $wpdb->query($sql_prices);
                }
            }
        } else {
            $sql_price = "INSERT INTO " . EVENTS_PRICES_TABLE . " (event_id, event_cost, surcharge, price_type, member_price, member_price_type) VALUES ('" . $event_id . "', '0.00', '0.00', '" . __('Free', 'event_espresso') . "', '0.00', '" . __('Free', 'event_espresso') . "')";
            if (!$wpdb->query($sql_price)) {
                $error = true;
            }
        }
        ############# MailChimp Integration ###############
        if (get_option('event_mailchimp_active') == 'true' && $espresso_premium == true) {
            MailChimpController::update_event_list_rel($event_id);
        }
        if (function_exists('espresso_fb_createevent') == 'true' && $espresso_premium == true) {
            espresso_fb_updateevent($event_id);
        }
        /// Create Event Post Code Here
        switch ($_REQUEST['create_post']) {
            case $_REQUEST['create_post'] == 'N':
                $sql = " SELECT * FROM " . EVENTS_DETAIL_TABLE;
                $sql .= " WHERE id = '" . $event_id . "' ";
                $wpdb->get_results($sql);
                $post_id = $wpdb->last_result[0]->post_id;
                if ($wpdb->num_rows > 0 && !empty($_REQUEST['delete_post']) && $_REQUEST['delete_post'] == 'Y') {
                    $sql = array('post_id' => '', 'post_type' => '');
                    $sql_data = array('%d', '%s');
                    $update_id = array('id' => $event_id);
                    $wpdb->update(EVENTS_DETAIL_TABLE, $sql, $update_id, $sql_data, array('%d'));
                    wp_delete_post($post_id, 'true');
                }
                break;
            case $_REQUEST['create_post'] == 'Y':
                $post_type = $_REQUEST['espresso_post_type'];
                if ($post_type == 'post') {
                    if (file_exists(EVENT_ESPRESSO_TEMPLATE_DIR . "event_post.php") || file_exists(EVENT_ESPRESSO_PLUGINFULLPATH . "templates/event_post.php")) {
                        // Load message from template into message post variable
                        ob_start();
                        if (file_exists(EVENT_ESPRESSO_TEMPLATE_DIR . "event_post.php")) {
                            require_once EVENT_ESPRESSO_TEMPLATE_DIR . "event_post.php";
                        } else {
                            require_once EVENT_ESPRESSO_PLUGINFULLPATH . "templates/event_post.php";
                        }
                        $post_content = ob_get_contents();
                        ob_end_clean();
                    } else {
                        _e('There was error finding a post template. Please verify your post templates are available.', 'event_espresso');
                    }
                } elseif ($post_type == 'espresso_event') {
                    ob_start();
                    echo $event_desc;
                    $post_content = ob_get_contents();
                    ob_end_clean();
                }
                $my_post = array();
                $sql = " SELECT * FROM " . EVENTS_DETAIL_TABLE;
                $sql .= " WHERE id = '" . $event_id . "' ";
                $wpdb->get_results($sql);
                $post_id = $wpdb->last_result[0]->post_id;
                $post_type = $_REQUEST['espresso_post_type'];
                if ($post_id > 0) {
                    $my_post['ID'] = $post_id;
                }
                $my_post['post_title'] = esc_html($_REQUEST['event']);
                $my_post['post_content'] = $post_content;
                $my_post['post_status'] = 'publish';
                $my_post['post_author'] = $_REQUEST['user'];
                $my_post['post_category'] = $_REQUEST['post_category'];
                //print_r ($my_post['post_category']);
                $my_post['tags_input'] = $_REQUEST['post_tags'];
                $my_post['post_type'] = $post_type;
                //print_r($my_post);
                // Insert the post into the database
                if ($post_id > 0) {
                    $post_id = wp_update_post($my_post);
                    update_post_meta($post_id, 'event_id', $event_id);
                    update_post_meta($post_id, 'event_identifier', $event_identifier);
                    update_post_meta($post_id, 'event_start_date', $start_date);
                    update_post_meta($post_id, 'event_end_date', $end_date);
                    update_post_meta($post_id, 'event_location', $event_location);
                    update_post_meta($post_id, 'virtual_url', $virtual_url);
                    update_post_meta($post_id, 'virtual_phone', $virtual_phone);
                    //
                    update_post_meta($post_id, 'event_address', $address);
                    update_post_meta($post_id, 'event_address2', $address2);
                    update_post_meta($post_id, 'event_city', $city);
                    update_post_meta($post_id, 'event_state', $state);
                    update_post_meta($post_id, 'event_country', $country);
                    update_post_meta($post_id, 'event_phone', $phone);
                    update_post_meta($post_id, 'venue_title', $venue_title);
                    update_post_meta($post_id, 'venue_url', $venue_url);
                    update_post_meta($post_id, 'venue_phone', $venue_phone);
                    update_post_meta($post_id, 'venue_image', $venue_image);
                    update_post_meta($post_id, 'event_externalURL', $externalURL);
                    update_post_meta($post_id, 'event_reg_limit', $reg_limit);
                    update_post_meta($post_id, 'event_start_time', time_to_24hr($start_time));
                    update_post_meta($post_id, 'event_end_time', time_to_24hr($end_time));
                    update_post_meta($post_id, 'event_registration_start', $registration_start);
                    update_post_meta($post_id, 'event_registration_end', $registration_end);
                    update_post_meta($post_id, 'event_registration_startT', $registration_startT);
                    update_post_meta($post_id, 'event_registration_endT', $registration_endT);
                    //update_post_meta( $post_id, 'timezone_string', $timezone_string );
                } else {
                    $post_id = wp_insert_post($my_post);
                    add_post_meta($post_id, 'event_id', $event_id);
                    add_post_meta($post_id, 'event_identifier', $event_identifier);
                    add_post_meta($post_id, 'event_start_date', $start_date);
                    add_post_meta($post_id, 'event_end_date', $end_date);
                    add_post_meta($post_id, 'event_location', $event_location);
                    add_post_meta($post_id, 'virtual_url', $virtual_url);
                    add_post_meta($post_id, 'virtual_phone', $virtual_phone);
                    //
                    add_post_meta($post_id, 'event_address', $address);
                    add_post_meta($post_id, 'event_address2', $address2);
                    add_post_meta($post_id, 'event_city', $city);
                    add_post_meta($post_id, 'event_state', $state);
                    add_post_meta($post_id, 'event_country', $country);
                    add_post_meta($post_id, 'event_phone', $phone);
                    add_post_meta($post_id, 'venue_title', $venue_title);
                    add_post_meta($post_id, 'venue_url', $venue_url);
                    add_post_meta($post_id, 'venue_phone', $venue_phone);
                    add_post_meta($post_id, 'venue_image', $venue_image);
                    add_post_meta($post_id, 'event_externalURL', $externalURL);
                    add_post_meta($post_id, 'event_reg_limit', $reg_limit);
                    add_post_meta($post_id, 'event_start_time', time_to_24hr($start_time));
                    add_post_meta($post_id, 'event_end_time', time_to_24hr($end_time));
                    add_post_meta($post_id, 'event_registration_start', $registration_start);
                    add_post_meta($post_id, 'event_registration_end', $registration_end);
                    add_post_meta($post_id, 'event_registration_startT', $registration_startT);
                    add_post_meta($post_id, 'event_registration_endT', $registration_endT);
                    //add_post_meta( $post_id, 'timezone_string', $timezone_string );
                }
                // Store the POST ID so it can be displayed on the edit page
                $sql = array('post_id' => $post_id, 'post_type' => $post_type);
                $sql_data = array('%d', '%s');
                $update_id = array('id' => $event_id);
                $wpdb->update(EVENTS_DETAIL_TABLE, $sql, $update_id, $sql_data, array('%d'));
                break;
        }
        ?>
        <div id="message" class="updated fade"><p><strong><?php 
        _e('Event details updated for', 'event_espresso');
        ?>
 <a href="<?php 
        echo espresso_reg_url($event_id);
        ?>
" target="_blank"><?php 
        echo stripslashes_deep($_REQUEST['event']);
        ?>
 for <?php 
        echo date("m/d/Y", strtotime($start_date));
        ?>
</a>.</strong></p></div>
        
        <?php 
        /*
         * Added for seating chart addon
         */
        if (isset($seating_chart_result) && $seating_chart_result === false) {
            ?>
        <p>Failed to associate new seating chart with this event. (Seats from current seating chart might have been used by some attendees)</p>
        <?php 
        }
        /*
         * End
         */
        ?>
   
        
        <?php 
    }
    /*
     * With the recursion of this function, additional recurring events will be updated
     */
    if (isset($recurrence_dates) && count($recurrence_dates) > 0 && $_POST['recurrence_apply_changes_to'] > 1) {
        //$recurrence_dates = array_shift($recurrence_dates); //Remove the first item from the array since it will be added after this recursion
        foreach ($recurrence_dates as $r_d) {
            if ($r_d['event_id'] != '' && count($r_d) > 2) {
                update_event(array('event_id' => $r_d['event_id'], 'event_identifier' => $r_d['event_identifier'], 'recurrence_id' => $r_d['recurrence_id'], 'recurrence_start_date' => $r_d['start_date'], 'recurrence_event_end_date' => $r_d['event_end_date'], 'registration_start' => $r_d['registration_start'], 'registration_end' => $r_d['registration_end'], 'visible_on' => $r_d['visible_on']));
            }
        }
    }
    /*
     * End recursion, as part of recurring events.
     */
}
Exemplo n.º 21
0
 function espresso_export_stuff()
 {
     $today = date("Y-m-d-Hi", time());
     $export_all_events = isset($_REQUEST['all_events']) && $_REQUEST['all_events'] == "true" ? TRUE : FALSE;
     //Export data to Excel file
     if (isset($_REQUEST['export'])) {
         switch ($_REQUEST['export']) {
             case "report":
                 global $wpdb;
                 $event_id = isset($_REQUEST['event_id']) ? $_REQUEST['event_id'] : FALSE;
                 // export for one event only ?
                 if ($event_id) {
                     $SQL = "SELECT event_name, event_desc, event_identifier, question_groups, event_meta FROM " . EVENTS_DETAIL_TABLE;
                     $SQL .= " WHERE id = %d";
                     if ($results = $wpdb->get_row($wpdb->prepare($SQL, $event_id), ARRAY_N)) {
                         list($event_name, $event_description, $event_identifier, $question_groups, $event_meta) = $results;
                         $question_groups = maybe_unserialize($question_groups);
                         $event_meta = maybe_unserialize($event_meta);
                         if (!empty($event_meta['add_attendee_question_groups'])) {
                             $question_groups = array_unique(array_merge((array) $question_groups, (array) $event_meta['add_attendee_question_groups']));
                         }
                     }
                 } else {
                     // export for ALL EVENTS
                     $question_groups = array();
                     $event_meta = array();
                     $SQL = "SELECT event_name, event_desc, event_identifier, question_groups, event_meta FROM " . EVENTS_DETAIL_TABLE;
                     if ($results = $wpdb->get_results($SQL, ARRAY_N)) {
                         foreach ($results as $result) {
                             list($event_name, $event_description, $event_identifier, $q_groups, $e_meta) = $result;
                             $question_groups = array_unique(array_merge($question_groups, (array) maybe_unserialize($q_groups)));
                             $e_meta = (array) maybe_unserialize($e_meta);
                             $event_meta = array_unique(array_merge($event_meta, (array) $e_meta['add_attendee_question_groups']));
                         }
                     }
                 }
                 $basic_header = array(__('Group', 'event_espresso'), __('ID', 'event_espresso'), __('Reg ID', 'event_espresso'), __('Payment Method', 'event_espresso'), __('Reg Date', 'event_espresso'), __('Pay Status', 'event_espresso'), __('Type of Payment', 'event_espresso'), __('Transaction ID', 'event_espresso'), __('Price', 'event_espresso'), __('Coupon Code', 'event_espresso'), __('# Attendees', 'event_espresso'), __('Amount Paid', 'event_espresso'), __('Date Paid', 'event_espresso'), __('Event Name', 'event_espresso'), __('Price Option', 'event_espresso'), __('Event Date', 'event_espresso'), __('Event Time', 'event_espresso'), __('Website Check-in', 'event_espresso'), __('Tickets Scanned', 'event_espresso'), __('Seat Tag', 'event_espresso'), __('First Name', 'event_espresso'), __('Last Name', 'event_espresso'), __('Email', 'event_espresso'));
                 $question_groups = maybe_unserialize($question_groups);
                 $event_meta = maybe_unserialize($event_meta);
                 if (isset($event_meta['add_attendee_question_groups'])) {
                     //					if ( is_serialized(  $event_meta['add_attendee_question_groups'] ) ){
                     //						$add_attendee_question_groups = unserialize($event_meta['add_attendee_question_groups']);
                     //					} else {
                     //						$add_attendee_question_groups = $event_meta['add_attendee_question_groups'];
                     //					}
                     if (!empty($add_attendee_question_groups)) {
                         $question_groups = array_unique(array_merge((array) $question_groups, (array) $event_meta['add_attendee_question_groups']));
                     }
                 }
                 switch ($_REQUEST['action']) {
                     case "event":
                         espresso_event_export($event_name);
                         break;
                     case "payment":
                         $question_list = array();
                         //will be used to associate questions with correct answers
                         $question_filter = array();
                         //will be used to keep track of newly added and deleted questions
                         if (count($question_groups) > 0) {
                             $question_sequence = array();
                             $questions_in = '';
                             foreach ($question_groups as $g_id) {
                                 $questions_in .= $g_id . ',';
                             }
                             $questions_in = substr($questions_in, 0, -1);
                             $group_name = '';
                             $counter = 0;
                             $quest_sql = "SELECT q.id, q.question FROM " . EVENTS_QUESTION_TABLE . " q ";
                             $quest_sql .= " JOIN " . EVENTS_QST_GROUP_REL_TABLE . " qgr on q.id = qgr.question_id ";
                             $quest_sql .= " JOIN " . EVENTS_QST_GROUP_TABLE . " qg on qg.id = qgr.group_id ";
                             $quest_sql .= " WHERE qgr.group_id in ( {$questions_in} ) ";
                             if (function_exists('espresso_member_data') && espresso_member_data('role') == 'espresso_event_manager') {
                                 $quest_sql .= " AND qg.wp_user = '******'id') . "' ";
                             }
                             //Fix from Jesse in the forums (http://eventespresso.com/forums/2010/10/form-questions-appearing-in-wrong-columns-in-excel-export/)
                             //$quest_sql .= " AND q.system_name is null ORDER BY qg.id, q.id ASC ";
                             //$quest_sql .= " AND q.system_name is null ";
                             $quest_sql .= " ORDER BY q.sequence, q.id ASC ";
                             $questions = $wpdb->get_results($quest_sql);
                             $ignore = array(1, 2, 3);
                             $num_rows = $wpdb->num_rows;
                             if ($num_rows > 0) {
                                 foreach ($questions as $question) {
                                     if (!isset($ignore[$question->id])) {
                                         $question_list[$question->id] = $question->question;
                                         $question_filter[$question->id] = $question->id;
                                         array_push($basic_header, escape_csv_val(stripslashes($question->question)));
                                         //array_push($question_sequence, $question->sequence);
                                     }
                                 }
                             }
                         }
                         if (count($question_filter) > 0) {
                             $question_filter = implode(",", $question_filter);
                         }
                         //$question_filter = str_replace( array( '1,','2,','3,' ), '', $question_filter );
                         $sql = '';
                         $espresso_member = function_exists('espresso_member_data') && espresso_member_data('role') == 'espresso_group_admin' ? TRUE : FALSE;
                         if ($espresso_member) {
                             $group = get_user_meta(espresso_member_data('id'), "espresso_group", true);
                             $group = maybe_unserialize($group);
                             $group = implode(",", $group);
                             $sql .= "(SELECT ed.event_name, ed.start_date, a.id AS att_id, a.registration_id, a.payment, a.date, a.payment_status, a.txn_type, a.txn_id";
                             $sql .= ", a.amount_pd, a.quantity, a.coupon_code, a.checked_in, a.checked_in_quantity";
                             $sql .= ", a.payment_date, a.event_time, a.price_option, a.final_price a_final_price, a.quantity a_quantity, a.fname, a.lname, a.email";
                             $sql .= " FROM " . EVENTS_ATTENDEE_TABLE . " a ";
                             $sql .= " JOIN " . EVENTS_DETAIL_TABLE . " ed ON ed.id=a.event_id ";
                             if ($group != '') {
                                 $sql .= " JOIN " . EVENTS_VENUE_REL_TABLE . " r ON r.event_id = ed.id ";
                                 $sql .= " JOIN " . EVENTS_LOCALE_REL_TABLE . " l ON  l.venue_id = r.venue_id ";
                             }
                             $sql .= $event_id ? " WHERE ed.id = '" . $event_id . "' " : '';
                             $sql .= $group != '' ? " AND  l.locale_id IN (" . $group . ") " : '';
                             $sql .= ") UNION (";
                         }
                         $sql .= "SELECT ed.event_name, ed.start_date, a.id AS att_id, a.registration_id, a.payment, a.date, a.payment_status, a.txn_type, a.txn_id";
                         $sql .= ", a.quantity, a.coupon_code, a.checked_in, a.checked_in_quantity, a.final_price a_final_price, a.amount_pd, a.quantity a_quantity";
                         $sql .= ", a.payment_date, a.event_time, a.price_option, a.fname, a.lname, a.email";
                         $sql .= " FROM " . EVENTS_ATTENDEE_TABLE . " a ";
                         $sql .= " JOIN " . EVENTS_DETAIL_TABLE . " ed ON ed.id=a.event_id ";
                         //$sql .= " JOIN " . EVENTS_ATTENDEE_COST_TABLE . " ac ON a.id=ac.attendee_id ";
                         $sql .= $event_id ? " WHERE ed.id = '" . $event_id . "' " : '';
                         if (function_exists('espresso_member_data') && (espresso_member_data('role') == 'espresso_event_manager' || espresso_member_data('role') == 'espresso_group_admin')) {
                             $sql .= " AND ed.wp_user = '******'id') . "' ";
                         }
                         $sql .= $espresso_member ? ") ORDER BY att_id " : " ORDER BY a.id ";
                         $participants = $wpdb->get_results($sql);
                         $filename = isset($_REQUEST['all_events']) && $_REQUEST['all_events'] == "true" ? __('all-events', 'event_espresso') : sanitize_title_with_dashes($event_name);
                         $filename = $filename . "-" . $today;
                         switch ($_REQUEST['type']) {
                             case "csv":
                                 $st = "";
                                 $et = ",";
                                 $s = $et . $st;
                                 header("Content-type: application/x-msdownload");
                                 header("Content-Disposition: attachment; filename=" . $filename . ".csv");
                                 //header("Content-Disposition: attachment; filename='" .$filename .".csv'");
                                 header("Pragma: no-cache");
                                 header("Expires: 0");
                                 //echo header
                                 echo implode($s, $basic_header) . "\r\n";
                                 break;
                             default:
                                 $st = "";
                                 $et = "\t";
                                 $s = $et . $st;
                                 header("Content-Disposition: attachment; filename=" . $filename . ".xls");
                                 //header("Content-Disposition: attachment; filename='" .$filename .".xls'");
                                 header("Content-Type: application/vnd.ms-excel");
                                 header("Pragma: no-cache");
                                 header("Expires: 0");
                                 //echo header
                                 echo implode($s, $basic_header) . $et . "\r\n";
                                 break;
                         }
                         if ($participants) {
                             $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
                             $group_counter = 1;
                             $amount_pd = 0;
                             foreach ($participants as $participant) {
                                 if ($temp_reg_id == '') {
                                     $temp_reg_id = $participant->registration_id;
                                     $amount_pd = $participant->amount_pd;
                                 }
                                 if ($temp_reg_id == $participant->registration_id) {
                                     //Do nothing
                                 } else {
                                     $group_counter++;
                                     $temp_reg_id = $participant->registration_id;
                                 }
                                 $attendees_group = "Group {$group_counter}";
                                 //Build the seating assignment
                                 $seatingchart_tag = '';
                                 if (defined("ESPRESSO_SEATING_CHART")) {
                                     if (class_exists("seating_chart")) {
                                         if (seating_chart::check_event_has_seating_chart($event_id)) {
                                             $rs = $wpdb->get_row("select scs.* from " . EVENTS_SEATING_CHART_EVENT_SEAT_TABLE . " sces inner join " . EVENTS_SEATING_CHART_SEAT_TABLE . " scs on sces.seat_id = scs.id where sces.attendee_id = " . $participant->att_id);
                                             if ($rs !== NULL) {
                                                 $participant->seatingchart_tag = $rs->custom_tag . " " . $rs->seat . " " . $rs->row;
                                             }
                                         }
                                     }
                                 } else {
                                     $participant->seatingchart_tag = '';
                                 }
                                 echo $attendees_group . $s . escape_csv_val($participant->att_id) . $s . escape_csv_val($participant->registration_id) . $s . escape_csv_val(stripslashes($participant->payment)) . $s . escape_csv_val(stripslashes(event_date_display($participant->date, get_option('date_format')))) . $s . escape_csv_val(stripslashes($participant->payment_status)) . $s . escape_csv_val(stripslashes($participant->txn_type)) . $s . escape_csv_val(stripslashes($participant->txn_id)) . $s . escape_csv_val($participant->a_final_price * $participant->a_quantity) . $s . escape_csv_val($participant->coupon_code) . $s . escape_csv_val($participant->quantity) . $s . escape_csv_val($participant->amount_pd) . $s . escape_csv_val(event_date_display($participant->payment_date, get_option('date_format'))) . $s . escape_csv_val($participant->event_name) . $s . escape_csv_val($participant->price_option) . $s . escape_csv_val(event_date_display($participant->start_date, get_option('date_format'))) . $s . escape_csv_val(event_date_display($participant->event_time, get_option('time_format'))) . $s . escape_csv_val($participant->checked_in) . $s . escape_csv_val($participant->checked_in_quantity) . $s . escape_csv_val($participant->seatingchart_tag) . $s . escape_csv_val($participant->fname) . $s . escape_csv_val($participant->lname) . $s . escape_csv_val($participant->email);
                                 $SQL = "SELECT question_id, answer FROM " . EVENTS_ANSWER_TABLE . " ";
                                 $SQL .= "WHERE question_id IN ({$question_filter}) AND attendee_id = %d";
                                 $answers = $wpdb->get_results($wpdb->prepare($SQL, $participant->att_id), OBJECT_K);
                                 foreach ($question_list as $k => $v) {
                                     // in case the event organizer removes a question from a question group,
                                     //  the orphaned answers will remian in the answers table.  This check will make sure they don't get exported.
                                     $search = array("\r", "\n", "\t");
                                     if (isset($answers[$k])) {
                                         $clean_answer = str_replace($search, " ", $answers[$k]->answer);
                                         $clean_answer = stripslashes(str_replace("&#039;", "'", trim($clean_answer)));
                                         $clean_answer = escape_csv_val($clean_answer);
                                         echo $s . $clean_answer;
                                     } else {
                                         echo $s;
                                     }
                                 }
                                 switch ($_REQUEST['type']) {
                                     case "csv":
                                         echo "\r\n";
                                         break;
                                     default:
                                         echo $et . "\r\n";
                                         break;
                                 }
                             }
                         } else {
                             echo __('No participant data has been collected.', 'event_espresso');
                         }
                         exit;
                         break;
                     default:
                         echo '<p>' . __('This Is Not A Valid Selection!', 'event_espresso') . '</p>';
                         break;
                 }
             default:
                 break;
         }
     }
 }
Exemplo n.º 22
0
    function event_espresso_shopping_cart()
    {
        global $wpdb, $org_options;
        //session_destroy();
        //echo "<pre>", print_r( $_SESSION ), "</pre>";
        $events_in_session = $_SESSION['espresso_session']['events_in_session'];
        if (event_espresso_invoke_cart_error($events_in_session)) {
            return false;
        }
        if (count($events_in_session) > 0) {
            foreach ($events_in_session as $event) {
                // echo $event['id'];
                if (is_numeric($event['id'])) {
                    $events_IN[] = $event['id'];
                }
            }
            $events_IN = implode(',', $events_IN);
            $sql = "SELECT e.* FROM " . EVENTS_DETAIL_TABLE . " e ";
            $sql .= " WHERE e.id in ({$events_IN}) ";
            $sql .= " AND e.event_status != 'D' ";
            $sql .= " ORDER BY e.start_date ";
            $result = $wpdb->get_results($sql);
            ?>

<form action='?page_id=<?php 
            echo $org_options['event_page_id'];
            ?>
&regevent_action=load_checkout_page' method='post' id="event_espresso_shopping_cart">

<?php 
            $counter = 1;
            //Counter that will keep track of the first events
            foreach ($result as $r) {
                $num_attendees = get_number_of_attendees_reg_limit($r->id, 'num_attendees');
                //Get the number of attendees
                $available_spaces = get_number_of_attendees_reg_limit($r->id, 'available_spaces');
                //Gets a count of the available spaces
                $number_available_spaces = get_number_of_attendees_reg_limit($r->id, 'number_available_spaces');
                //Gets the number of available spaces
                //echo "<pre>$r->id, $num_attendees,$available_spaces,$number_available_spaces</pre>";
                ?>
		<div class="multi_reg_cart_block event-display-boxes ui-widget"  id ="multi_reg_cart_block-<?php 
                echo $r->id;
                ?>
">

			<h3 class="event_title ui-widget-header ui-corner-top"><?php 
                echo stripslashes_deep($r->event_name);
                ?>
 <span class="remove-cart-item"> <img class="ee_delete_item_from_cart" id="cart_link_<?php 
                echo $r->id;
                ?>
" alt="Remove this item from your cart" src="<?php 
                echo EVENT_ESPRESSO_PLUGINFULLURL;
                ?>
images/icons/remove.gif" /> </span> </h3>
				<div class="event-data-display ui-widget-content ui-corner-bottom">
					<table id="cart-reg-details" class="event-display-tables">
						<thead>
							<tr>
								<th><?php 
                _e('Date', 'event_espresso');
                ?>
</th>
								<th><?php 
                _e('Time', 'event_espresso');
                ?>
</th>
							</tr>
						</thead>
						<tbody>
							<tr>
								<td><?php 
                echo event_date_display($r->start_date, get_option('date_format'));
                ?>
								<?php 
                /*_e( ' to ', 'event_espresso' ); ?> <?php echo event_date_display( $r->end_date, get_option( 'date_format' ) )*/
                ?>
</td>
								<td><?php 
                echo event_espresso_time_dropdown($r->id, 0, 1, $_SESSION['espresso_session']['events_in_session'][$r->id]['start_time_id']);
                ?>
</td>
							</tr>
							<tr>
								<td colspan="2"><?php 
                echo event_espresso_group_price_dropdown($r->id, 0, 1, $_SESSION['espresso_session']['events_in_session'][$r->id]['price_id']);
                ?>
</td>
							</tr>
					</table>
			<?php 
                //Coupons
                if (function_exists('event_espresso_coupon_registration_page')) {
                    // echo event_espresso_coupon_registration_page( $r->use_coupon_code, $r->id, 1 );
                }
                //End coupons display
                ?>

				<input type="hidden" name="event_name[<?php 
                echo $r->id;
                ?>
]" value="<?php 
                echo $r->event_name;
                ?>
" />
			</div><!-- / .event-data-display -->
		</div><!-- / .event-display-boxes -->

		<?php 
                $counter++;
            }
            ?>
		<div class="event-display-boxes ui-widget">
			<div class="mer-event-submit ui-widget-content ui-corner-all">
				<input type="hidden" name="event_name[<?php 
            echo $r->id;
            ?>
]" value="<?php 
            echo stripslashes_deep($r->event_name);
            ?>
" />
				<input type="hidden" name="regevent_action" value="load_checkout_page" />
			
			<?php 
            //Coupon code display
            //Uncomment the following code at your own risk. Just beware that all coupon codes will work for everyting in the cart.
            ?>
			<?php 
            /*?><div id="event_espresso_coupon_wrapper" class="clearfix event-data-display">
            			<label class="coupon-code" for="event_espresso_coupon_code">
            				<?php _e( 'Enter Coupon Code ', 'event_espresso' ); ?>
            			</label>
            			<input onkeydown="if(event.keyCode==13) {document.getElementById('event_espresso_refresh_total').focus(); return false;}" type="text" name="event_espresso_coupon_code" id ="event_espresso_coupon_code" value="<?php echo $_SESSION['espresso_session']['coupon_code']; ?>"/>
            		</div><?php */
            ?>

			<div id="event_espresso_total_wrapper" class="clearfix event-data-display">
					<a href="#" id="event_espresso_refresh_total"><?php 
            _e('Refresh Total', 'event_espresso');
            ?>
</a>
				<span class="event_total_price">
					<?php 
            _e('Total (' . $org_options['currency_symbol'] . '): <span id="event_total_price">' . $_SESSION['espresso_session']['grand_total'], 'event_espresso') . '</span>';
            ?>
				</span>
			</div>

			<input type="submit" class="submit btn_event_form_submit ui-priority-primary ui-state-default ui-state-hover ui-state-focus ui-corner-all" name="Continue" id="event_espresso_continue_registration" value="<?php 
            _e('Finish Registration', 'event_espresso');
            ?>
" />
		</div><!-- / .mer-event-submit -->
	</div><!-- / .event-display-boxes -->
</form>
<?php 
        }
    }
Exemplo n.º 23
0
        function widget($args, $instance)
        {
            extract($args);
            global $wpdb, $org_options;
            /* Our variables from the widget settings. */
            $title = apply_filters('widget_title', $instance['title']);
            /* Before widget (defined by themes). */
            echo $before_widget;
            /* Display the widget title if one was input (before and after defined by themes). */
            if ($title) {
                echo $before_title . $title . $after_title;
            }
            if ($instance['category_name'] != '') {
                $type = 'category';
            }
            $event_page_id = $org_options['event_page_id'];
            $show_expired = $instance['show_expired'] == 'false' ? " AND (e.start_date >= '" . date('Y-m-d') . "' OR e.event_status = 'O' OR e.registration_end >= '" . date('Y-m-d') . "') " : '';
            $show_secondary = $instance['show_secondary'] == 'false' ? " AND e.event_status != 'S' " : '';
            $show_deleted = $instance['show_deleted'] == 'false' ? " AND e.event_status != 'D' " : '';
            $show_recurrence = $instance['show_recurrence'] == 'false' ? " AND e.recurrence_id = '0' " : '';
            $limit = $instance['limit'] > 0 ? " LIMIT 0," . $instance['limit'] . " " : ' LIMIT 0,5 ';
            //$order_by = $order_by != 'NULL'? " ORDER BY ". $order_by ." ASC " : " ORDER BY date(start_date), id ASC ";
            $order_by = " ORDER BY date(start_date), id ASC ";
            if (isset($type) && $type == 'category') {
                $sql = "SELECT e.*, c.category_name, c.category_name, c.category_desc, ese.start_time FROM " . EVENTS_CATEGORY_TABLE . " c ";
                $sql .= " JOIN " . EVENTS_CATEGORY_REL_TABLE . " r ON r.cat_id = c.id ";
                $sql .= " JOIN " . EVENTS_DETAIL_TABLE . " e ON e.id = r.event_id ";
                $sql .= " LEFT JOIN " . EVENTS_START_END_TABLE . " ese ON ese.event_id = e.id ";
                $sql .= " WHERE c.id = '" . $instance['category_name'] . "' ";
                $sql .= " AND e.is_active = 'Y' ";
            } else {
                $sql = "SELECT e.*, ese.start_time FROM " . EVENTS_DETAIL_TABLE . " e ";
                $sql .= " LEFT JOIN " . EVENTS_START_END_TABLE . " ese ON ese.event_id = e.id ";
                $sql .= " WHERE e.is_active = 'Y' ";
            }
            $sql .= $show_expired;
            $sql .= $show_secondary;
            $sql .= $show_deleted;
            $sql .= $show_recurrence;
            $sql .= " GROUP BY e.id ";
            $sql .= $order_by;
            $sql .= $limit;
            $events = $wpdb->get_results($sql);
            //print_r($events);
            //event_espresso_get_event_details($sql);
            foreach ($events as $event) {
                $event->id = $event->id;
                $event->event_name = isset($event->event_name) ? $event->event_name : '';
                $event->start_date = isset($event->start_date) ? $event->start_date : '';
                $event->category_name = isset($event->category_name) ? $event->category_name : '';
                $event->category_desc = isset($event->category_desc) ? $event->category_desc : '';
                $event->externalURL = isset($event->externalURL) ? $event->externalURL : '';
                $registration_url = $event->externalURL != '' ? $event->externalURL : espresso_reg_url($event->id);
                $all_meta = array('is_active' => $event->is_active, 'event_status' => $event->event_status, 'event_address' => $event->address, 'event_address2' => $event->address2, 'registration_startT' => $event->registration_startT, 'registration_start' => $event->registration_start, 'registration_endT' => $event->registration_endT, 'registration_end' => $event->registration_end, 'start_date' => event_date_display($event->start_date, get_option('date_format')), 'start_time' => event_date_display($event->start_time, get_option('time_format')), 'end_date' => event_date_display($event->end_date, get_option('date_format')));
                //Here we can create messages based on the event status
                $status = event_espresso_get_is_active($event->id, $all_meta);
                //Print out the array of event status options
                //print_r (event_espresso_get_is_active($event->id));
                $status_display = ' - ' . $status['display_custom'];
                $status_display_ongoing = $status['status'] == 'ONGOING' ? ' - ' . $status['display_custom'] : '';
                $status_display_deleted = $status['status'] == 'DELETED' ? ' - ' . $status['display_custom'] : '';
                $status_display_secondary = $status['status'] == 'SECONDARY' ? ' - ' . $status['display_custom'] : '';
                //Waitlist event
                $status_display_reg_closed = $status['status'] == 'REGISTRATION_CLOSED' ? ' - ' . $status['display_custom'] : '';
                $status_display_not_open = $status['status'] == 'REGISTRATION_NOT_OPEN' ? ' - ' . $status['display_custom'] : '';
                $status_display_open = $status['status'] == 'REGISTRATION_OPEN' ? ' - ' . $status['display_custom'] : '';
                //You can also display a custom message. For example, this is a custom registration not open message:
                $status_display_custom_closed = $status['status'] == 'REGISTRATION_CLOSED' ? ' - <span class="espresso_closed">' . __('Regsitration is closed', 'event_espresso') . '</span>' : '';
                //End
                if (!is_user_logged_in() && defined('EVENTS_MEMBER_REL_TABLE') && !empty($member_only) && $member_only == 'Y') {
                    //Display a message if the user is not logged in.
                    //_e('Member Only Event. Please ','event_espresso') . event_espresso_user_login_link() . '.';
                } else {
                    //Serve up the event list
                    //As of version 3.0.17 the event list details have been moved to event_list_display.php
                    switch ($status['status']) {
                        case 'NOT_ACTIVE':
                            //Don't show the event if any of the above are true
                            break;
                        default:
                            ?>
                            <p><a href="<?php 
                            echo $registration_url;
                            ?>
"><?php 
                            echo stripslashes_deep($event->event_name);
                            ?>
 - <?php 
                            echo event_date_display($event->start_date);
                            ?>
</a>
                            <?php 
                            /* These are custom messages that can be displayed based on the event status. Just comment the one you want to use. */
                            ?>
                                <?php 
                            //echo $status_display; //Turn this on to display the overall status of the event.
                            ?>
                                <?php 
                            //echo $status_display_ongoing; //Turn this on to display the ongoing message.
                            ?>
                                <?php 
                            //echo $status_display_deleted; //Turn this on to display the deleted message.
                            ?>
                                <?php 
                            //echo $status_display_secondary; //Turn this on to display the waitlist message.
                            ?>
                                <?php 
                            //echo $status_display_reg_closed; //Turn this on to display the secondary message.
                            ?>
                                <?php 
                            //echo $status_display_not_open; //Turn this on to display the secondary message.
                            ?>
                                <?php 
                            //echo $status_display_open; //Turn this on to display the secondary message.
                            ?>
                                <?php 
                            //echo $status_display_custom_closed; //Turn this on to display the secondary message.
                            ?>
                            </p>
                                <?php 
                            break;
                    }
                }
            }
            /* After widget (defined by themes). */
            echo $after_widget;
        }
Exemplo n.º 24
0
function add_event_to_db($recurrence_arr = array())
{
    // echo "<pre>";
    //print_r($_POST);
    //echo "</pre>";
    global $wpdb, $org_options, $current_user, $espresso_premium;
    $wpdb->show_errors();
    static $recurrence_id;
    if (get_option('event_espresso_re_active') == 1) {
        require_once EVENT_ESPRESSO_RECURRENCE_FULL_PATH . "functions/re_functions.php";
        $recurrence_id = array_key_exists('recurrence_id', $recurrence_arr) ? $recurrence_arr['recurrence_id'] : Null;
        if ($_POST['recurrence'] == 'Y' && count($recurrence_arr) < 2) {
            if (is_null($recurrence_id)) {
                $recurrence_id = add_recurrence_master_record();
            }
            $re_params = array('start_date' => $_POST['recurrence_type'] == 'a' ? $_POST['recurrence_start_date'] : $_POST['recurrence_manual_dates'], 'event_end_date' => $_POST['recurrence_type'] == 'a' ? $_POST['recurrence_event_end_date'] : $_POST['recurrence_manual_end_dates'], 'end_date' => $_POST['recurrence_type'] == 'a' ? $_POST['recurrence_end_date'] : $_POST['end_date'], 'registration_start' => $_POST['recurrence_regis_start_date'], 'registration_end' => $_POST['recurrence_regis_end_date'], 'frequency' => $_POST['recurrence_frequency'], 'interval' => $_POST['recurrence_interval'], 'type' => $_POST['recurrence_type'], 'weekdays' => $_POST['recurrence_weekday'], 'repeat_by' => $_POST['recurrence_repeat_by'], 'recurrence_regis_date_increment' => $_POST['recurrence_regis_date_increment'], 'recurrence_manual_dates' => $_POST['recurrence_manual_dates'], 'recurrence_manual_end_dates' => $_POST['recurrence_manual_end_dates'], 'recurrence_visibility' => $_POST['recurrence_visibility'], 'recurrence_id' => $recurrence_id, 'adding_to_db' => 'Y');
            $recurrence_dates = $_POST['recurrence_type'] == 'm' ? find_recurrence_manual_dates($re_params) : find_recurrence_dates($re_params);
        }
    }
    //echo_f('re array', $recurrence_dates);
    if (defined('EVENT_ESPRESSO_RECURRENCE_MODULE_ACTIVE') && $_POST['recurrence'] == 'Y' && count($recurrence_arr) == 0) {
        //skip the first insert because we do not have the start dates
    } else {
        $event_mata = array();
        //will be used to hold event meta data
        //If the Espresso Facebook Events is installed, add the event to Facebook
        //$fb = new FacebookEvents();
        //echo $fb->espresso_createevent();
        //echo $_POST['event'];
        $event_name = $_REQUEST['event'];
        $event_code = uniqid($current_user->ID . '-');
        $event_identifier = $_REQUEST['event_identifier'] == '' ? $event_identifier = sanitize_title_with_dashes($event_name . '-' . $event_code) : ($event_identifier = sanitize_title_with_dashes($_REQUEST['event_identifier']) . $event_code);
        $event_desc = $_REQUEST['event_desc'];
        $display_desc = $_REQUEST['display_desc'];
        $display_reg_form = $_REQUEST['display_reg_form'];
        $address = esc_html($_REQUEST['address']);
        $address2 = esc_html($_REQUEST['address2']);
        $city = esc_html($_REQUEST['city']);
        $state = esc_html($_REQUEST['state']);
        $zip = esc_html($_REQUEST['zip']);
        $country = esc_html($_REQUEST['country']);
        $phone = esc_html($_REQUEST['phone']);
        $externalURL = esc_html($_REQUEST['externalURL']);
        $post_type = $_REQUEST['espresso_post_type'];
        //$event_location = $address . ' ' . $city . ', ' . $state . ' ' . $zip;
        $event_location = ($address != '' ? $address . ' ' : '') . ($address2 != '' ? '<br />' . $address2 : '') . ($city != '' ? '<br />' . $city : '') . ($state != '' ? ', ' . $state : '') . ($zip != '' ? '<br />' . $zip : '') . ($country != '' ? '<br />' . $country : '');
        $reg_limit = $_REQUEST['reg_limit'];
        $allow_multiple = $_REQUEST['allow_multiple'];
        $additional_limit = $_REQUEST['additional_limit'];
        $member_only = isset($_REQUEST['member_only']) ? $_REQUEST['member_only'] : '';
        $is_active = $_REQUEST['is_active'];
        $event_status = $_REQUEST['event_status'];
        //Get the first instance of the start and end times
        $start_time = $_REQUEST['start_time'][0];
        $end_time = $_REQUEST['end_time'][0];
        // Add registration times
        $registration_startT = event_date_display($_REQUEST['registration_startT'], 'H:i');
        $registration_endT = event_date_display($_REQUEST['registration_endT'], 'H:i');
        // Add Timezone
        $timezone_string = isset($_REQUEST['timezone_string']) ? $_REQUEST['timezone_string'] : '';
        //Early discounts
        $early_disc = $_REQUEST['early_disc'];
        $early_disc_date = $_REQUEST['early_disc_date'];
        $early_disc_percentage = $_REQUEST['early_disc_percentage'];
        $conf_mail = $_REQUEST['conf_mail'];
        $use_coupon_code = $_REQUEST['use_coupon_code'];
        $alt_email = $_REQUEST['alt_email'];
        $send_mail = $_REQUEST['send_mail'];
        $email_id = isset($_REQUEST['email_name']) ? $_REQUEST['email_name'] : '';
        //Venue Information
        $venue_title = $_REQUEST['venue_title'];
        $venue_url = $_REQUEST['venue_url'];
        $venue_phone = $_REQUEST['venue_phone'];
        $venue_image = $_REQUEST['venue_image'];
        //Virtual location
        $virtual_url = $_REQUEST['virtual_url'];
        $virtual_phone = $_REQUEST['virtual_phone'];
        $registration_start = array_key_exists('registration_start', $recurrence_arr) ? $recurrence_arr['registration_start'] : $_REQUEST['registration_start'];
        $registration_end = array_key_exists('registration_end', $recurrence_arr) ? $recurrence_arr['registration_end'] : $_REQUEST['registration_end'];
        //Check which start/end date to use.  Will be determined by recurrenig events addon, if installed.
        if (array_key_exists('recurrence_start_date', $recurrence_arr)) {
            //Recurring event
            $start_date = $recurrence_arr['recurrence_start_date'];
        } elseif ($_REQUEST['start_date'] == '' && $_REQUEST['recurrence_start_date'] != '') {
            //If they leave the Event Start Date empty, the First Event Date in the recurrence module is selected
            $start_date = $_REQUEST['recurrence_start_date'];
        } elseif (isset($_POST['recurrence']) && $_POST['recurrence'] == 'Y' && $_REQUEST['start_date'] == '') {
            $start_date = $_REQUEST['recurrence_manual_dates'][0];
        } else {
            $start_date = $_REQUEST['start_date'];
        }
        if (array_key_exists('recurrence_event_end_date', $recurrence_arr)) {
            //Recurring event
            $end_date = $recurrence_arr['recurrence_event_end_date'];
        } elseif ($_REQUEST['end_date'] == '' && $_REQUEST['recurrence_event_end_date'] != '') {
            //If they leave the Event Start Date empty, the First Event Date in the recurrence module is selected
            $end_date = $_REQUEST['recurrence_event_end_date'];
        } elseif (isset($_POST['recurrence']) && $_POST['recurrence'] == 'Y' && $_REQUEST['end_date'] == '') {
            $end_date = $_REQUEST['recurrence_manual_end_dates'][count($_REQUEST['recurrence_manual_end_dates']) - 1];
        } else {
            $end_date = $_REQUEST['end_date'];
        }
        //$start_date = array_key_exists('recurrence_start_date', $recurrence_arr)?$recurrence_arr['recurrence_start_date']:($_REQUEST['start_date']==''?$_REQUEST['recurrence_start_date']:$_REQUEST['start_date']);
        //$end_date = array_key_exists('recurrence_start_date', $recurrence_arr)?$recurrence_arr['recurrence_start_date']:($_REQUEST['end_date']==''?$_REQUEST['recurrence_start_date']:$_REQUEST['end_date']);
        if (array_key_exists('visible_on', $recurrence_arr)) {
            //Recurring event
            $visible_on = $recurrence_arr['visible_on'];
        } elseif (isset($_REQUEST['visible_on']) && $_REQUEST['visible_on'] != '') {
            $visible_on = $_REQUEST['visible_on'];
        } elseif (isset($_REQUEST['visible_on']) && $_REQUEST['visible_on'] == '' && count($recurrence_dates) > 0) {
            $visible_on = $recurrence_dates[$start_date]['visible_on'];
        } else {
            $visible_on = date("Y-m-d");
        }
        if ($reg_limit == '') {
            $reg_limit = 999;
        }
        $question_groups = empty($_REQUEST['question_groups']) ? '' : serialize($_REQUEST['question_groups']);
        $add_attendee_question_groups = empty($_REQUEST['add_attendee_question_groups']) ? '' : serialize($_REQUEST['add_attendee_question_groups']);
        $event_mata['venue_id'] = isset($_REQUEST['venue_id']) ? $_REQUEST['venue_id'][0] : '';
        $event_mata['additional_attendee_reg_info'] = $_REQUEST['additional_attendee_reg_info'];
        $event_mata['add_attendee_question_groups'] = $add_attendee_question_groups;
        $event_mata['date_submitted'] = date("Y-m-d H:i:s");
        $event_mata['default_payment_status'] = $_REQUEST['default_payment_status'];
        if ($_REQUEST['emeta'] != '') {
            foreach ($_REQUEST['emeta'] as $k => $v) {
                $event_mata[$v] = strlen(trim($_REQUEST['emetad'][$k])) > 0 ? $_REQUEST['emetad'][$k] : '';
            }
        }
        //echo strlen(trim($_REQUEST['emetad'][$k]));
        //print_r($_REQUEST['emeta'] );
        $event_mata = serialize($event_mata);
        ############ Added by wp-developers ######################
        $require_pre_approval = 0;
        if (isset($_REQUEST['require_pre_approval'])) {
            $require_pre_approval = $_REQUEST['require_pre_approval'];
        }
        ################# END #################
        //When adding colums to the following arrays, be sure both arrays have equal values.
        $sql = array('event_code' => $event_code, 'event_name' => $event_name, 'event_desc' => $event_desc, 'display_desc' => $display_desc, 'display_reg_form' => $display_reg_form, 'event_identifier' => $event_identifier, 'address' => $address, 'address2' => $address2, 'city' => $city, 'state' => $state, 'zip' => $zip, 'country' => $country, 'phone' => $phone, 'virtual_url' => $virtual_url, 'virtual_phone' => $virtual_phone, 'venue_title' => $venue_title, 'venue_url' => $venue_url, 'venue_phone' => $venue_phone, 'venue_image' => $venue_image, 'registration_start' => $registration_start, 'registration_end' => $registration_end, 'start_date' => $start_date, 'end_date' => $end_date, 'allow_multiple' => $allow_multiple, 'send_mail' => $send_mail, 'is_active' => $is_active, 'event_status' => $event_status, 'conf_mail' => $conf_mail, 'use_coupon_code' => $use_coupon_code, 'member_only' => $member_only, 'externalURL' => $externalURL, 'early_disc' => $early_disc, 'early_disc_date' => $early_disc_date, 'early_disc_percentage' => $early_disc_percentage, 'alt_email' => $alt_email, 'question_groups' => $question_groups, 'registration_startT' => $registration_startT, 'registration_endT' => $registration_endT, 'reg_limit' => $reg_limit, 'additional_limit' => $additional_limit, 'recurrence_id' => $recurrence_id, 'email_id' => $email_id, 'wp_user' => $current_user->ID, 'event_meta' => $event_mata, 'require_pre_approval' => $require_pre_approval, 'timezone_string' => $timezone_string, 'submitted' => date('Y-m-d H:i:s', time()));
        $sql_data = array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d', '%s', '%s', '%s', '%s');
        /* echo 'Debug: <br />';
           print_r($sql);
           echo '<br />';
           print 'Number of vars: ' . count ($sql);
           echo '<br />';
           print 'Number of cols: ' . count($sql_data); */
        //Add groupon reference if installed
        if (function_exists('event_espresso_add_event_to_db_groupon')) {
            $sql = event_espresso_add_event_to_db_groupon($sql, $_REQUEST['use_groupon_code']);
            //print count ($sql);
            $sql_data = array_merge((array) $sql_data, (array) '%s');
            //print count($sql_data);
            if (!$wpdb->insert(EVENTS_DETAIL_TABLE, $sql, $sql_data)) {
                $error = true;
            }
        } else {
            if (!$wpdb->insert(EVENTS_DETAIL_TABLE, $sql, $sql_data)) {
                $error = true;
            }
        }
        $last_event_id = $wpdb->insert_id;
        ############# MailChimp Integration ##############
        if (get_option('event_mailchimp_active') == 'true' && $espresso_premium == true) {
            MailChimpController::add_event_list_rel($last_event_id);
        }
        if (function_exists('espresso_fb_createevent') == 'true' && $espresso_premium == true) {
            espresso_fb_createevent($last_event_id);
        }
        /*
         * Added for seating chart addon
         */
        if (isset($_REQUEST['seating_chart_id'])) {
            $cls_seating_chart = new seating_chart();
            $cls_seating_chart->associate_event_seating_chart($_REQUEST['seating_chart_id'], $last_event_id);
        }
        /*
         * End
         */
        //Add event to a category
        if (isset($_REQUEST['event_category']) && $_REQUEST['event_category'] != '') {
            foreach ($_REQUEST['event_category'] as $k => $v) {
                if ($v != '') {
                    $sql_cat = "INSERT INTO " . EVENTS_CATEGORY_REL_TABLE . " (event_id, cat_id) VALUES ('" . $last_event_id . "', '" . $v . "')";
                    //echo "$sql3 <br>";
                    if (!$wpdb->query($sql_cat)) {
                        $error = true;
                    }
                }
            }
        }
        if (!empty($_REQUEST['event_person'])) {
            foreach ($_REQUEST['event_person'] as $k => $v) {
                if ($v != '') {
                    $sql_ppl = "INSERT INTO " . EVENTS_PERSONNEL_REL_TABLE . " (event_id, person_id) VALUES ('" . $last_event_id . "', '" . $v . "')";
                    //echo "$sql_ppl <br>";
                    $wpdb->query($sql_ppl);
                }
            }
        }
        if (!empty($_REQUEST['venue_id'])) {
            foreach ($_REQUEST['venue_id'] as $k => $v) {
                if ($v != '' && $v != 0) {
                    $sql_venues = "INSERT INTO " . EVENTS_VENUE_REL_TABLE . " (event_id, venue_id) VALUES ('" . $last_event_id . "', '" . $v . "')";
                    //echo "$sql_venues <br>";
                    $wpdb->query($sql_venues);
                }
            }
        }
        if (!empty($_REQUEST['event_discount'])) {
            foreach ($_REQUEST['event_discount'] as $k => $v) {
                if ($v != '') {
                    $sql_cat = "INSERT INTO " . EVENTS_DISCOUNT_REL_TABLE . " (event_id, discount_id) VALUES ('" . $last_event_id . "', '" . $v . "')";
                    //echo "$sql3 <br>";
                    if (!$wpdb->query($sql_cat)) {
                        $error = true;
                    }
                }
            }
        }
        if (!empty($_REQUEST['start_time'])) {
            foreach ($_REQUEST['start_time'] as $k => $v) {
                if ($v != '') {
                    $time_qty = $_REQUEST['time_qty'][$k] == '' ? '0' : "'" . $_REQUEST['time_qty'][$k] . "'";
                    $sql3 = "INSERT INTO " . EVENTS_START_END_TABLE . " (event_id, start_time, end_time, reg_limit) VALUES ('" . $last_event_id . "', '" . event_date_display($v, 'H:i') . "', '" . event_date_display($_REQUEST['end_time'][$k], 'H:i') . "', " . $time_qty . ")";
                    //echo "$sql3 <br>";
                    if (!$wpdb->query($sql3)) {
                        $error = true;
                    }
                }
            }
        }
        if (!empty($_REQUEST['event_cost'])) {
            foreach ($_REQUEST['event_cost'] as $k => $v) {
                if ($v != '') {
                    $price_type = $_REQUEST['price_type'][$k] != '' ? $_REQUEST['price_type'][$k] : __('General Admission', 'event_espresso');
                    $member_price_type = !empty($_REQUEST['member_price_type'][$k]) ? $_REQUEST['member_price_type'][$k] : __('Members Admission', 'event_espresso');
                    $member_price = !empty($_REQUEST['member_price'][$k]) ? $_REQUEST['member_price'][$k] : $v;
                    $sql_price = "INSERT INTO " . EVENTS_PRICES_TABLE . " (event_id, event_cost, surcharge, surcharge_type, price_type, member_price, member_price_type) VALUES ('" . $last_event_id . "', '" . $v . "', '" . $_REQUEST['surcharge'][$k] . "', '" . $_REQUEST['surcharge_type'][$k] . "', '" . $price_type . "', '" . $member_price . "', '" . $member_price_type . "')";
                    //echo "$sql3 <br>";
                    if (!$wpdb->query($sql_price)) {
                        $error = true;
                    }
                }
            }
        } elseif ($_REQUEST['event_cost'][0] == 0) {
            $sql_price = "INSERT INTO " . EVENTS_PRICES_TABLE . " (event_id, event_cost, surcharge, price_type, member_price, member_price_type) VALUES ('" . $last_event_id . "', '0.00', '0.00', '" . __('Free', 'event_espresso') . "', '0.00', '" . __('Free', 'event_espresso') . "')";
            if (!$wpdb->query($sql_price)) {
                $error = true;
            }
        }
        // Create Event Post Code Here
        if ($_REQUEST['create_post'] == 'Y') {
            $post_type = $_REQUEST['espresso_post_type'];
            if ($post_type == 'post') {
                if (file_exists(EVENT_ESPRESSO_TEMPLATE_DIR . "event_post.php") || file_exists(EVENT_ESPRESSO_PLUGINFULLPATH . "templates/event_post.php")) {
                    // Load message from template into message post variable
                    ob_start();
                    if (file_exists(EVENT_ESPRESSO_TEMPLATE_DIR . "event_post.php")) {
                        require_once EVENT_ESPRESSO_TEMPLATE_DIR . "event_post.php";
                    } else {
                        require_once EVENT_ESPRESSO_PLUGINFULLPATH . "templates/event_post.php";
                    }
                    $post_content = ob_get_contents();
                    ob_end_clean();
                } else {
                    _e('There was error finding a post template. Please verify your post templates are available.', 'event_espresso');
                }
            } elseif ($post_type == 'espresso_event') {
                ob_start();
                echo $event_desc;
                $post_content = ob_get_contents();
                ob_end_clean();
            }
            $my_post = array();
            $my_post['post_title'] = esc_html($_REQUEST['event']);
            $my_post['post_content'] = $post_content;
            $my_post['post_status'] = 'publish';
            $my_post['post_author'] = $_REQUEST['user'];
            $my_post['post_category'] = $_REQUEST['post_category'];
            $my_post['tags_input'] = $_REQUEST['post_tags'];
            $my_post['post_type'] = $post_type;
            //print_r($my_post);
            // Insert the post into the database
            $post_id = wp_insert_post($my_post);
            // Store the POST ID so it can be displayed on the edit page
            $sql = array('post_id' => $post_id, 'post_type' => $post_type);
            add_post_meta($post_id, 'event_id', $last_event_id);
            add_post_meta($post_id, 'event_identifier', $event_identifier);
            add_post_meta($post_id, 'event_start_date', $_REQUEST['start_date']);
            add_post_meta($post_id, 'event_end_date', $_REQUEST['end_date']);
            add_post_meta($post_id, 'event_location', $event_location);
            add_post_meta($post_id, 'virtual_url', $virtual_url);
            add_post_meta($post_id, 'virtual_phone', $virtual_phone);
            add_post_meta($post_id, 'event_address', $address);
            add_post_meta($post_id, 'event_address2', $address2);
            add_post_meta($post_id, 'event_city', $city);
            add_post_meta($post_id, 'event_state', $state);
            add_post_meta($post_id, 'event_country', $country);
            add_post_meta($post_id, 'event_phone', $phone);
            add_post_meta($post_id, 'venue_title', $venue_title);
            add_post_meta($post_id, 'venue_url', $venue_url);
            add_post_meta($post_id, 'venue_phone', $venue_phone);
            add_post_meta($post_id, 'venue_image', $venue_image);
            add_post_meta($post_id, 'event_externalURL', $externalURL);
            add_post_meta($post_id, 'event_reg_limit', $reg_limit);
            add_post_meta($post_id, 'event_start_time', time_to_24hr($start_time));
            add_post_meta($post_id, 'event_end_time', time_to_24hr($end_time));
            add_post_meta($post_id, 'event_registration_start', $registration_start);
            add_post_meta($post_id, 'event_registration_end', $registration_end);
            add_post_meta($post_id, 'event_registration_startT', $registration_startT);
            add_post_meta($post_id, 'event_registration_endT', $registration_endT);
            //add_post_meta( $post_id, 'timezone_string', $_REQUEST['timezone_string'] );
            $sql_data = array('%d', '%s');
            $update_id = array('id' => $last_event_id);
            $wpdb->update(EVENTS_DETAIL_TABLE, $sql, $update_id, $sql_data, array('%d'));
        }
        if (empty($error)) {
            ?>
            <div id="message" class="updated fade"><p><strong><?php 
            _e('The event', 'event_espresso');
            ?>
                        <a href="<?php 
            echo espresso_reg_url($last_event_id);
            ?>
" target="_blank"><?php 
            echo stripslashes_deep($_REQUEST['event']);
            ?>
</a>

            <?php 
            _e('has been added for ', 'event_espresso');
            echo date("m/d/Y", strtotime($start_date));
            ?>
 <a href="admin.php?page=events&action=edit&event_id=<?php 
            echo $last_event_id;
            ?>
"><?php 
            _e('Edit this event?', 'event_espresso');
            ?>
</a></strong></p></div>
        <?php 
        } else {
            ?>
            <div id="message" class="error"><p><strong><?php 
            _e('There was an error in your submission, please try again. The event was not saved!', 'event_espresso');
            print $wpdb->print_error();
            ?>
.</strong></p></div>
            <?php 
        }
    }
    /*
     * With the recursion of this function, additional recurring events will be added
     */
    if (isset($recurrence_dates) && count($recurrence_dates) > 0) {
        foreach ($recurrence_dates as $k => $v) {
            add_event_to_db(array('recurrence_id' => $recurrence_id, 'recurrence_start_date' => $v['start_date'], 'recurrence_event_end_date' => $v['event_end_date'], 'registration_start' => $v['registration_start'], 'registration_end' => $v['registration_end'], 'visible_on' => $v['visible_on']));
        }
    }
    /*
     * End recursion, as part of recurring events.
     */
    return $last_event_id;
}
function event_espresso_time_editor($event_id = 0)
{
    global $wpdb, $org_options;
    //$org_options['time_reg_limit'] = 'Y';
    $time_counter = 1;
    //echo get_option('time_format');
    ?>
<ul id="dynamicTimeInput">
	<?php 
    $times = $wpdb->get_results("SELECT * FROM " . EVENTS_START_END_TABLE . " WHERE event_id = '" . $event_id . "' ORDER BY id");
    if ($wpdb->num_rows > 0) {
        foreach ($times as $time) {
            echo '<li><p><label for="add-start-time">' . __('Start', 'event_espresso') . ' ' . $time_counter++ . '</label><input size="10"  type="text" id="add-start-time" name="start_time[]" value="' . event_date_display($time->start_time, get_option('time_format')) . '" /></p><p><label for="add-end-time"> ' . __('End', 'event_espresso') . '</label> <input size="10"  type="text" id="add-end-time" name="end_time[]" value="' . event_date_display($time->end_time, get_option('time_format')) . '"></p>' . (isset($org_options['time_reg_limit']) && $org_options['time_reg_limit'] == 'Y' ? '<p><label>' . __('Qty', 'event_espresso') . '</label> <input size="3"  type="text" name="time_qty[]" value="' . $time->reg_limit . '"></p><p><em class="important">' . __('Event time slot quantities should only be set for events where group registrations are disabled.', 'event_espresso') . '</em></p>' : '') . '<p><input class="remove-item xtra-time" type="button" value="Remove" onclick="this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);" /></p></li>';
        }
    } else {
        ?>
	<li>
		<p>
			<label for="add-start-time">
				<?php 
        _e('Start', 'event_espresso');
        ?>
			</label>
			<input size="10"  type="text" id="add-start-time" name="start_time[]" />
		</p>
		<p>
			<label for="add-end-time">
				<?php 
        _e('End', 'event_espresso');
        ?>
			</label>
			<input size="10"  type="text" id="add-end-time" name="end_time[]" />
		</p>
		<?php 
        echo isset($org_options['time_reg_limit']) && $org_options['time_reg_limit'] == 'Y' ? '<p><label>' . __('Qty', 'event_espresso') . '</label> <input size="3"  type="text" name="time_qty[]" /></p><p><em class="important">' . __('Event time slot quantities should only be set for events where group registrations are disabled.', 'event_espresso') . '</em></p>' : '';
        ?>
 </li>
	<?php 
    }
    ?>
</ul>
<?php 
    global $espresso_premium;
    if ($espresso_premium != true) {
        return;
    }
    ?>
<input type="button" class="button" id="add-time" value="<?php 
    _e('Add Additional Time', 'event_espresso');
    ?>
" onClick="addTimeInput('dynamicTimeInput');" />
<script type="text/javascript">
        //Dynamic form fields
        var counter = <?php 
    echo $time_counter++;
    ?>
;
        function addTimeInput(divName){
            var newdiv = document.createElement('li');
            newdiv.innerHTML = "<p><label for='add-start-time-"+ (counter) +"'><?php 
    _e('Start', 'event_espresso');
    ?>
 " + (counter) + "</label> <input type='text'id='add-start-time-"+ (counter) +"' name='start_time[]'></p><p><label for='add-end-time-"+ (counter) +"'> <?php 
    _e('End', 'event_espresso');
    ?>
:</label> <input type='text' id='add-end-time-"+ (counter) +"' name='end_time[]'></p><?php 
    echo $org_options['time_reg_limit'] == 'Y' ? '<p><label>' . __('Qty', 'event_espresso') . "</label> <input type='text'  size='3' name='time_qty[]'></p>" : '';
    ?>
<p><input class='remove-this xtra-time' id='remove-added-time' type='button' value='Remove' onclick='this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);'/></p>";
            document.getElementById(divName).appendChild(newdiv);
            counter++;
        }
    </script>
<?php 
}
function event_espresso_edit_list()
{
    global $wpdb, $org_options;
    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'));
    }
    // DELETE EVENT
    if (isset($_POST['delete_event'])) {
        if (is_array($_POST['checkbox'])) {
            while (list($key, $value) = each($_POST['checkbox'])) {
                $del_id = $key;
                event_espresso_delete_event($del_id);
            }
        }
        ?>
		<div id="message" class="updated fade">
			<p><strong>
					<?php 
        _e('Event(s) have been permanently deleted.', 'event_espresso');
        ?>
				</strong></p>
		</div>
		<?php 
    }
    // REALLY REALLY DELETE EVENT THIS TIME !!!
    if (isset($_POST['perm_delete_event'])) {
        if (is_array($_POST['checkbox'])) {
            while (list($key, $value) = each($_POST['checkbox'])) {
                $del_id = $key;
                event_espresso_empty_event_trash($del_id);
            }
        }
        ?>
		<div id="message" class="updated fade">
			<p><strong>
					<?php 
        _e('Event(s) have been permanently deleted.', 'event_espresso');
        ?>
				</strong></p>
		</div>
		<?php 
    }
    // dejavu ?
    $recurrence_icon = '';
    if (defined('EVENT_ESPRESSO_RECURRENCE_MODULE_ACTIVE')) {
        $recurrence_icon = '<img src="' . EVENT_ESPRESSO_PLUGINFULLURL . 'images/arrow_rotate_clockwise.png" alt="Recurring Event" title="Recurring Event" class="re_fr" />';
    }
    // get SQL for query
    $SQL = espresso_generate_events_page_list_table_sql();
    $events = $wpdb->get_results($SQL, OBJECT_K);
    $total_events = $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( $events, '$events  <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_events);
    } else {
        ?>
		<p>
			<strong><?php 
        _e('Advanced filters are available in the premium versions.', 'event_espresso');
        ?>
</strong> 
			<a href="http://eventespresso.com/pricing/?utm_source=ee_plugin_admin&utm_medium=link&utm_content=Advanced+filters+are+available+in+the+premium+versions<?php 
        echo '+ee_version_' . EVENT_ESPRESSO_VERSION;
        ?>
&utm_campaign=event_overview_tab" target="_blank">
				<?php 
        _e('Upgrade Now!', 'event_espresso');
        ?>
			</a>
		</p>
		<?php 
    }
    ?>
	<form id="form1" name="form1" method="post" action="admin.php?page=events<?php 
    //echo $_SERVER["REQUEST_URI"]
    ?>
">
		<table id="table" class="widefat event-list" width="100%">
			<thead>
				<tr>
					<th class="manage-column column-cb check-column" id="cb" scope="col" style="width:28px;"><input type="checkbox"></th>

					<th class="manage-column column-comments num" id="id" style="padding-top:7px; width:3%;" scope="col" title="Click to Sort">
						<span><?php 
    _e('ID', 'event_espresso');
    ?>
</span>
						<span class="sorting-indicator"></span>
					</th>

					<th class="manage-column column-title" id="name" scope="col" title="Click to Sort" style="width:26%;">
						<span><?php 
    _e('Name', 'event_espresso');
    ?>
</span>
						<span class="sorting-indicator"></span>
					</th>

					<th class="manage-column column-title" id="name" scope="col" title="Click to Sort" style="width:12%;">
						<span><?php 
    _e('Venue', 'event_espresso');
    ?>
</span>
						<span class="sorting-indicator"></span>
					</th>

					<th class="manage-column column-date" id="dow" scope="col" title="Click to Sort" style="width:4%;";>
						<span><?php 
    _e('DoW', '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:12%;">
						<span><?php 
    _e('Start Date', '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:7%;">
						<span><?php 
    _e('Start Time', '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:16%;">
						<span><?php 
    _e('Reg Begins', '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:8%;">
						<span><?php 
    _e('Status', 'event_espresso');
    ?>
</span>
						<span class="sorting-indicator"></span>
					</th>
					<?php 
    if (function_exists('espresso_is_admin') && espresso_is_admin() == true && $espresso_premium == true) {
        ?>
						<th class="manage-column column-date" id="status" scope="col" title="Click to Sort" style="width:10%;">
							<span><?php 
        _e('Creator', 'event_espresso');
        ?>
</span>
							<span class="sorting-indicator"></span>
						</th>
	<?php 
    }
    ?>
					<th class="manage-column column-date" id="attendees" scope="col" title="Click to Sort" style="width:7%;">
						<span><?php 
    _e('Attendees', 'event_espresso');
    ?>
</span>
						<span class="sorting-indicator"></span>
					</th>
					<th class="manage-column column-author" id="actions" scope="col" style="width:25%;">
	<?php 
    _e('Actions', 'event_espresso');
    ?>
					</th>

				</tr>
			</thead>

			<tbody>
				<?php 
    if ($total_events > 0) {
        // instead of doing queries for each event while looping through them, we're going to grab a list of event IDs and consolidate our queries outside the loop
        $event_ids = implode(',', array_keys($events));
        // first let's grab attendee counts in one BIG query instead of individual queries for each event
        $SQL = "SELECT event_id, SUM(quantity) AS quantity FROM " . EVENTS_ATTENDEE_TABLE . " ";
        $SQL .= "WHERE (payment_status='Completed' OR payment_status='Pending' OR payment_status='Refund') ";
        $SQL .= "GROUP BY event_id HAVING event_id IN ( {$event_ids} )";
        $attendees = $wpdb->get_results($SQL, OBJECT_K);
        //					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' );
        // now let's grab start times for each event
        $SQL = "SELECT event_id, start_time FROM " . EVENTS_START_END_TABLE . " ";
        $SQL .= "WHERE event_id IN ( {$event_ids} ) ";
        $SQL .= 'ORDER BY start_time ASC';
        $start_times = $wpdb->get_results($SQL, OBJECT_K);
        //					echo '<h4>' . $wpdb->last_query . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
        //					printr( $start_times, '$start_times  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
        foreach ($events as $event) {
            //printr( $event, '$event  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
            $event_id = $event->event_id;
            $event_name = stripslashes_deep($event->event_name);
            $event_identifier = stripslashes_deep($event->event_identifier);
            $reg_limit = isset($event->reg_limit) ? $event->reg_limit : '';
            $start_date = isset($event->start_date) ? $event->start_date : '';
            $start_time = isset($start_times[$event_id]) ? $start_times[$event_id]->start_time : '';
            $end_date = isset($event->end_date) ? $event->end_date : '';
            $is_active = isset($event->is_active) ? $event->is_active : '';
            $status = array();
            $recurrence_id = isset($event->recurrence_id) ? $event->recurrence_id : '';
            $registration_start = isset($event->registration_start) ? $event->registration_start : '';
            $registration_startT = isset($event->registration_startT) ? $event->registration_startT : '';
            $event_address = isset($event->address) ? $event->address : '';
            $event_address2 = isset($event->address2) ? $event->address2 : '';
            $event_city = isset($event->city) ? $event->city : '';
            $event_state = isset($event->state) ? $event->state : '';
            $event_zip = isset($event->zip) ? $event->zip : '';
            $event_country = isset($event->country) ? $event->country : '';
            //added new
            $venue_title = isset($event->venue_title) ? stripslashes_deep($event->venue_title) : '';
            $venue_locale = isset($event->locale_name) ? $event->locale_name : '';
            $wp_user = isset($event->wp_user) ? $event->wp_user : '';
            $event_meta = array();
            $event_meta['is_active'] = $is_active;
            $event_meta['event_status'] = $event->event_status;
            $event_meta['start_time'] = $start_time;
            $event_meta['start_date'] = $start_date;
            $event_meta['registration_start'] = $registration_start;
            $event_meta['registration_startT'] = $registration_startT;
            $registration_end = $event_meta['registration_end'] = $event->registration_end;
            $registration_endT = $event_meta['registration_endT'] = $event->registration_endT;
            $status = event_espresso_get_is_active($event_id, $event_meta);
            //Get number of attendees
            $num_attendees = isset($attendees[$event_id]) ? $attendees[$event_id]->quantity : 0;
            $location = (!empty($event_address) ? $event_address : '') . (!empty($event_address2) ? '<br />' . $event_address2 : '') . (!empty($event_city) ? '<br />' . $event_city : '') . (!empty($event_state) ? ', ' . $event_state : '') . (!empty($event_zip) ? '<br />' . $event_zip : '') . (!empty($event_country) ? '<br />' . $event_country : '');
            $dow = date("D", strtotime($start_date));
            ob_start();
            ?>
						<tr>
							<td class="check-column" style="padding:7px 0 22px 7px; vertical-align:top;"><!--Delete Events-->
			<?php 
            echo '<input name="checkbox[' . $event_id . ']" type="checkbox"  title="Delete Event ' . $event_name . '" />';
            ?>
</td>

							<td class="column-comments" style="padding-top:3px;"><?php 
            echo $event_id;
            ?>
</td>

							<td class="post-title page-title">
								<strong><a class="row-title" href="admin.php?page=events&action=edit&event_id=<?php 
            echo $event_id;
            ?>
"><?php 
            echo $event_name;
            ?>
</a> <?php 
            echo $recurrence_id > 0 ? $recurrence_icon : '';
            ?>
 </strong>
								<div class="row-actions"><span><a href="<?php 
            echo espresso_reg_url($event_id);
            ?>
" target="_blank"><?php 
            _e('View', 'event_espresso');
            ?>
</a> | </span><span class='edit'><a href="admin.php?page=events&amp;action=edit&amp;event_id=<?php 
            echo $event_id;
            ?>
"><?php 
            _e('Edit', 'event_espresso');
            ?>
</a> | </span><span class='delete'><a onclick="return confirmDelete();" href='admin.php?page=events&amp;action=delete&amp;event_id=<?php 
            echo $event_id;
            ?>
'><?php 
            _e('Delete', 'event_espresso');
            ?>
</a></span> | <span><a href="admin.php?page=events&amp;event_admin_reports=list_attendee_payments&amp;event_id=<?php 
            echo $event_id;
            ?>
"><?php 
            _e('Attendees', 'event_espresso');
            ?>
</a> | </span><span><a href="#" onclick="window.location='<?php 
            echo get_bloginfo('wpurl') . "/wp-admin/admin.php?event_espresso&amp;event_id=" . $event_id . "&amp;export=report&action=payment&amp;type=excel";
            ?>
'" title="<?php 
            _e('Export to Excel', 'event_espresso');
            ?>
"><?php 
            _e('Export', 'event_espresso');
            ?>
</a></span></div>
							</td>

							<td class="author">
								<?php 
            echo $venue_title != '' ? $venue_title : '';
            echo $venue_locale != '' ? '<br />[' . $venue_locale . ']' : '';
            ?>
						
							</td>

							<td class="date"><?php 
            echo $dow;
            ?>
</td>

							<td class="author"><?php 
            echo event_date_display($start_date, get_option('date_format'));
            ?>
</td>

							<td class="author"><?php 
            echo date(get_option('time_format'), strtotime($start_time));
            ?>
</td>

							<td class="date"><?php 
            echo event_date_display($registration_start, get_option('date_format'));
            ?>
 @ <?php 
            echo date(get_option('time_format'), strtotime($registration_startT));
            ?>
</td>

							<td class="date"><?php 
            echo $status['display'];
            ?>
</td>

							<?php 
            if (function_exists('espresso_is_admin') && espresso_is_admin() == true && $espresso_premium == true) {
                $user_company = espresso_user_meta($wp_user, 'company') != '' ? espresso_user_meta($wp_user, 'company') : '';
                $user_organization = espresso_user_meta($wp_user, 'organization') != '' ? espresso_user_meta($wp_user, 'organization') : '';
                $user_co_org = $user_company != '' ? $user_company : $user_organization;
                ?>
								<td class="date"><?php 
                echo espresso_user_meta($wp_user, 'user_firstname') != '' ? espresso_user_meta($wp_user, 'user_firstname') . ' ' . espresso_user_meta($wp_user, 'user_lastname') . ' (<a href="user-edit.php?user_id=' . $wp_user . '">' . espresso_user_meta($wp_user, 'user_nicename') . '</a>)' : espresso_user_meta($wp_user, 'display_name') . ' (<a href="user-edit.php?user_id=' . $wp_user . '">' . espresso_user_meta($wp_user, 'user_nicename') . '</a>)';
                ?>
				<?php 
                echo $user_co_org != '' ? '<br />[' . espresso_user_meta($wp_user, 'company') . ']' : '';
                ?>
								</td>
			<?php 
            }
            ?>

							<td class="author">
								<?php 
            $attendees_url = add_query_arg(array('event_admin_reports' => 'list_attendee_payments', 'event_id' => $event_id, 'event_status' => $event->event_status), EVT_ADMIN_URL);
            ?>
								<a href="<?php 
            echo $attendees_url;
            ?>
"><?php 
            echo $num_attendees . '/' . $reg_limit;
            ?>
</a>
							</td>
							
							<td class="date">
								<div style="width:180px;">
								
									<a href="<?php 
            echo espresso_reg_url($event_id);
            ?>
" title="<?php 
            _e('View Event', 'event_espresso');
            ?>
" target="_blank">
										<div class="view_btn"></div>
									</a>

									<a href="admin.php?page=events&amp;action=edit&amp;event_id=<?php 
            echo $event_id;
            ?>
" title="<?php 
            _e('Edit Event', 'event_espresso');
            ?>
">
										<div class="edit_btn"></div>
									</a>

									<a href="admin.php?page=events&amp;event_id=<?php 
            echo $event_id;
            ?>
&amp;event_admin_reports=list_attendee_payments" title="<?php 
            _e('View Attendees', 'event_espresso');
            ?>
">
										<div class="complete_btn"></div>
									</a>
									
									<a href="admin.php?page=events&event_admin_reports=charts&event_id=<?php 
            echo $event_id;
            ?>
" title="<?php 
            _e('View Report', 'event_espresso');
            ?>
">
										<div class="reports_btn"></div>
									</a>


									<a class="thickbox" href="#TB_inline?height=300&width=400&inlineId=unique_id_info_<?php 
            echo $event_id;
            ?>
" title="<?php 
            _e('Get Short URL/Shortcode', 'event_espresso');
            ?>
">
										<div class="shortcode_btn"></div>
									</a>

									<a href="#" onclick="window.location='<?php 
            echo get_bloginfo('wpurl') . "/wp-admin/admin.php?event_espresso&amp;event_id=" . $event_id . "&amp;export=report&action=payment&amp;type=excel";
            ?>
'" title="<?php 
            _e('Export to Excel', 'event_espresso');
            ?>
">
										<div class="excel_exp_btn"></div>
									</a>

									<a href="#" onclick="window.location='<?php 
            echo get_bloginfo('wpurl') . "/wp-admin/admin.php?event_espresso&event_id=" . $event_id . "&export=report&action=payment&type=csv";
            ?>
'" title="<?php 
            _e('Export to CSV', 'event_espresso');
            ?>
">
										<div class="csv_exp_btn"></div>
									</a>

									<a href="admin.php?page=events&amp;event_admin_reports=event_newsletter&amp;event_id=<?php 
            echo $event_id;
            ?>
" title="<?php 
            _e('Email Attendees', 'event_espresso');
            ?>
">
										<div class="newsletter_btn"></div>
									</a>
									
								</div>

								<div id="unique_id_info_<?php 
            echo $event_id;
            ?>
" style="display:none">
						<?php 
            _e('<h2>Short URL/Shortcode</h2><p>This is the short URL to this event:</p><p><span  class="updated fade">' . espresso_reg_url($event_id) . '</span></p><p>This will show the registration form for this event just about anywhere. Copy and paste the following shortcode into any page or post.</p><p><span  class="updated fade">[SINGLEEVENT single_event_id="' . $event_identifier . '"]</span></p> <p class="red_text"> Do not use in place of the main events page that is set in the Organization Settings page.', 'event_espresso');
            ?>
								</div>
								
							</td>
						</tr>
						<?php 
            $content = ob_get_contents();
            ob_end_clean();
            echo $content;
        }
        //End foreach ($events as $event){
    }
    ?>

			</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><?php 
    if (isset($_REQUEST['event_status']) && $_REQUEST['event_status'] == 'D') {
        ?>
				<input name="perm_delete_event" type="submit" class="button-secondary" id="perm_delete_event" value="<?php 
        _e('Permanently Delete Events(s)', 'event_espresso');
        ?>
" style="margin:10px 0 0 10px;" onclick="return confirmDelete();" />
			<?php 
    } else {
        ?>
				<input name="delete_event" type="submit" class="button-secondary" id="delete_event" value="<?php 
        _e('Delete Events(s)', 'event_espresso');
        ?>
" style="margin:10px 0 0 10px;" onclick="return confirmDelete();" />

				<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 style="margin-left:5px" class="button-secondary" href="#" onclick="window.location='<?php 
        echo get_bloginfo('wpurl') . "/wp-admin/admin.php?event_espresso&amp;export=report&action=payment&amp;type=excel&all_events=true";
        ?>
'" title="<?php 
        _e('Export to Excel', 'event_espresso');
        ?>
"><?php 
        _e('Export All Attendee Data', 'event_espresso');
        ?>
</a>
				<a class="button-secondary" href="#" onclick="window.location='<?php 
        echo get_bloginfo('wpurl') . "/wp-admin/admin.php?event_espresso&amp;export=report&action=event&amp;type=excel&all_events=true";
        ?>
'" title="<?php 
        _e('Export to Excel', 'event_espresso');
        ?>
"><?php 
        _e('Export All Event Data', 'event_espresso');
        ?>
</a>
				<a style="margin-left:5px" class="button-primary" href="admin.php?page=events&amp;action=add_new_event"><?php 
        _e('Add New 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">
	<?php 
    echo defined('EVENT_ESPRESSO_RECURRENCE_MODULE_ACTIVE') ? '<dt><img src="' . EVENT_ESPRESSO_PLUGINFULLURL . 'images/arrow_rotate_clockwise.png" alt="Recurring Event" title="Recurring Event"  /> - ' . __('Recurring Event', 'event_espresso') . '</dt>' : '';
    ?>
		<dt><img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
images/icons/magnifier.png" width="16" height="16" alt="<?php 
    _e('View Event', 'event_espresso');
    ?>
" /> - <?php 
    _e('View Event', 'event_espresso');
    ?>
</dt>

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

		<dt><img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
images/icons/group.png" width="16" height="16" alt="<?php 
    _e('Event Attendees', 'event_espresso');
    ?>
" /> - <?php 
    _e('Event Attendees', 'event_espresso');
    ?>
</dt>
		<dt><img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
images/icons/chart_bar.png" width="16" height="16" alt="<?php 
    _e('Send Event Email', 'event_espresso');
    ?>
" /> - <?php 
    _e('View Report', 'event_espresso');
    ?>
</dt>


	</dl>

	<dl style="float:left; margin-left:10px;">
		<dt><img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
images/icons/tag.png" width="16" height="16" alt="<?php 
    _e('Short Code', 'event_espresso');
    ?>
" /> - <?php 
    _e('Short Code', 'event_espresso');
    ?>
</dt>
		<dt><img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
images/icons/excel_icon.png" width="16" height="16" alt="<?php 
    _e('Excel Spreadsheet', 'event_espresso');
    ?>
" /> - <?php 
    _e('Excel Export', 'event_espresso');
    ?>
</dt>

		<dt><img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
images/icons/csv_icon_sm.gif" width="16" height="16" alt="<?php 
    _e('CSV Spreadsheet', 'event_espresso');
    ?>
" /> - <?php 
    _e('CSV Export', 'event_espresso');
    ?>
</dt>

		<dt><img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
images/icons/email_go.png" width="16" height="16" alt="<?php 
    _e('View Report', 'event_espresso');
    ?>
" /> - <?php 
    _e('Event Newsletter', 'event_espresso');
    ?>
</dt>
	</dl>

	<script>
		jQuery(document).ready(function($) {
			// show the table data 
			var mytable = $('#table').dataTable( {
				"sDom": 'Clfrtip',
				"aoColumns": [
					{ "bSortable": false },
					null,
					null,
					null,
					null,
					null,
					null,
					null,
					null,
	<?php 
    echo function_exists('espresso_is_admin') && espresso_is_admin() == true ? 'null,' : '';
    ?>
					null,
					{ "bSortable": false }
				],
				"aoColumnDefs": [
					{ "bVisible": false, "aTargets": [ <?php 
    echo $org_options['use_venue_manager'] == 'Y' ? '' : '3,';
    ?>
 4 ] }
				],
				"oColVis": {
					"aiExclude": [ 0, 1, 2 ],
					"buttonText": "Filter: Show / Hide Columns",
					"bRestore": true
				},
				"bAutoWidth": false,
				"bStateSave": true,
				"sPaginationType": "full_numbers",
				"oLanguage": {	"sSearch": "<strong><?php 
    _e('Live Search Filter', 'event_espresso');
    ?>
:</strong>",
					"sZeroRecords": "<?php 
    _e('No Records Found!', 'event_espresso');
    ?>
" }

			});
		});
	</script>

	<div id="coupon_code_info" style="display:none">
		<h2><?php 
    _e('Coupon/Promo Code', 'event_espresso');
    ?>
</h2><p><?php 
    _e('This is used to apply discounts to events.', 'event_espresso');
    ?>
</p><p><?php 
    _e('A coupon or promo code could can be anything you want. For example: Say you have an event that costs', 'event_espresso');
    ?>
 <?php 
    echo $org_options['currency_symbol'];
    ?>
200. <?php 
    _e('If you supplied a promo like "PROMO50" and entered 50.00 into the "Discount w/Promo Code" field your event will be discounted', 'event_espresso');
    ?>
  <?php 
    echo $org_options['currency_symbol'];
    ?>
50.00, <?php 
    _e('Bringing the cost of the event to', 'event_espresso');
    ?>
 <?php 
    echo $org_options['currency_symbol'];
    ?>
150. </p>
			<p><?php 
    _e("Note: Promo Codes which are marked to 'apply to all events', although not explicitly enumerated, can also be used for this event, provided it allows promo codes.", "event_espresso");
    ?>
</p>
	</div>
	<div id="unique_id_info" style="display:none">
		<h2><?php 
    _e('Event Identifier', 'event_espresso');
    ?>
</h2><p><?php 
    _e('This should be a unique identifier for the event. Example: "Event1" (without quotes.)</p><p>The unique ID can also be used in individual pages using the', 'event_espresso');
    ?>
 [SINGLEEVENT single_event_id="<?php 
    _e('Unique Event ID', 'event_espresso');
    ?>
"] <?php 
    _e('shortcode', 'event_espresso');
    ?>
.</p>
	</div>
	<?php 
    echo event_espresso_custom_email_info();
}
Exemplo n.º 27
0
function event_espresso_edit_list()
{
    global $wpdb, $org_options;
    define('EVT_ADMIN_URL', admin_url('admin.php?page=events'));
    $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', strtotime($curdate));
    $month_range = isset($_REQUEST['month_range']) && !empty($_REQUEST['month_range']) ? sanitize_text_field($_REQUEST['month_range']) : FALSE;
    $category_id = isset($_REQUEST['category_id']) && !empty($_REQUEST['category_id']) ? sanitize_text_field($_REQUEST['category_id']) : FALSE;
    $today_filter = isset($_REQUEST['today']) && $_REQUEST['today'] == 'true' ? TRUE : FALSE;
    $this_month_filter = isset($_REQUEST['this_month']) && $_REQUEST['this_month'] == 'true' ? TRUE : FALSE;
    $event_status = isset($_POST['event_status']) && !empty($_POST['event_status']) ? sanitize_text_field($_REQUEST['event_status']) : FALSE;
    if (isset($_POST['delete_event'])) {
        if (is_array($_POST['checkbox'])) {
            while (list($key, $value) = each($_POST['checkbox'])) {
                $del_id = $key;
                event_espresso_delete_event($del_id);
            }
        }
        ?>
		<div id="message" class="updated fade">
			<p><strong>
					<?php 
        _e('Event(s) have been permanently deleted.', 'event_espresso');
        ?>
				</strong></p>
		</div>
		<?php 
    }
    if (isset($_POST['perm_delete_event'])) {
        if (is_array($_POST['checkbox'])) {
            while (list($key, $value) = each($_POST['checkbox'])) {
                $del_id = $key;
                event_espresso_empty_event_trash($del_id);
            }
        }
        ?>

		<div id="message" class="updated fade">
			<p><strong>
					<?php 
        _e('Event(s) have been permanently deleted.', 'event_espresso');
        ?>
				</strong></p>
		</div>
		<?php 
    }
    $recurrence_icon = '';
    if (defined('EVENT_ESPRESSO_RECURRENCE_MODULE_ACTIVE')) {
        $recurrence_icon = '<img src="' . EVENT_ESPRESSO_PLUGINFULLURL . 'images/arrow_rotate_clockwise.png" alt="Recurring Event" title="Recurring Event" class="re_fr" />';
    }
    require_once '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 {
        echo '<p><strong>' . __('Advanced filters are now available in the premium versions.', 'event_espresso') . '</strong> <a href="http://eventespresso.com/download/" target="_blank">' . __('Upgrade Now!', 'event_espresso') . '</a></p>';
        //$total_events = espresso_total_events();
    }
    if ($month_range !== FALSE) {
        $pieces = explode('-', $month_range, 3);
        $year_r = $pieces[0];
        $month_r = $pieces[1];
    }
    $group = '';
    $sql = '';
    //Check if the venue manager is turned on
    $use_venue_manager = isset($org_options['use_venue_manager']) && $org_options['use_venue_manager'] == 'Y' ? TRUE : FALSE;
    $is_regional_manager = FALSE;
    //This checks to see if the user is a regional manager and creates a union to join the events that are in the users region based on the venue/locale combination
    if (function_exists('espresso_member_data') && espresso_member_data('role') == 'espresso_group_admin') {
        $is_regional_manager = TRUE;
        $group = get_user_meta(espresso_member_data('id'), "espresso_group", TRUE);
        if ($group != '0' && !empty($group)) {
            $sql = "(SELECT e.id event_id, e.event_name, e.event_identifier, e.reg_limit, e.registration_start, ";
            $sql .= " e.start_date, e.is_active, e.recurrence_id, e.registration_startT, e.wp_user ";
            //Get the venue information
            if ($use_venue_manager) {
                $sql .= ", v.name AS venue_title, v.address AS venue_address, v.address2 AS venue_address2, v.city AS venue_city, v.state AS venue_state, v.zip AS venue_zip, v.country AS venue_country ";
            } else {
                $sql .= ", e.venue_title, e.phone, e.address, e.address2, e.city, e.state, e.zip, e.country ";
            }
            //Get the locale fields
            if ($use_venue_manager) {
                $sql .= ", lc.name AS locale_name, e.wp_user ";
            }
            $sql .= " FROM " . EVENTS_DETAIL_TABLE . " e ";
            //Join the categories
            if ($today_filter) {
                $sql .= " JOIN " . EVENTS_CATEGORY_REL_TABLE . " cr ON cr.event_id = e.id ";
                $sql .= " JOIN " . EVENTS_CATEGORY_TABLE . " c ON  c.id = cr.cat_id ";
            }
            //Join the venues and locales
            if (!empty($group) && $use_venue_manager) {
                $sql .= " LEFT JOIN " . EVENTS_VENUE_REL_TABLE . " vr ON vr.event_id = e.id ";
                $sql .= " LEFT JOIN " . EVENTS_VENUE_TABLE . " v ON v.id = vr.venue_id ";
                $sql .= " LEFT JOIN " . EVENTS_LOCALE_REL_TABLE . " l ON  l.venue_id = vr.venue_id ";
                $sql .= " LEFT JOIN " . EVENTS_LOCALE_TABLE . " lc ON lc.id = l.locale_id ";
            }
            //Event status filter
            $sql .= $event_status !== FALSE && $event_status != 'IA' ? " WHERE e.event_status = '" . $event_status . "' " : " WHERE e.event_status != 'D' ";
            //Category filter
            $sql .= $category_id !== FALSE ? " AND c.id = '" . $category_id . "' " : '';
            //Find events in the locale
            $sql .= !empty($group) && $use_venue_manager == true ? " AND l.locale_id IN (" . implode(",", $group) . ") " : '';
            //Month filter
            if ($month_range !== FALSE) {
                $sql .= " AND e.start_date BETWEEN '" . date('Y-m-d', strtotime($year_r . '-' . $month_r . '-01')) . "' AND '" . date('Y-m-d', strtotime($year_r . '-' . $month_r . '-31')) . "' ";
            }
            //Todays events filter
            if ($today_filter) {
                $sql .= " AND e.start_date = '" . $curdate . "' ";
            }
            //This months events filter
            if ($this_month_filter) {
                $sql .= " AND e.start_date BETWEEN '" . date('Y-m-d', strtotime($this_year_r . '-' . $this_month_r . '-01')) . "' AND '" . date('Y-m-d', strtotime($this_year_r . '-' . $this_month_r . '-' . $days_this_month)) . "' ";
            }
            $sql .= ") UNION ";
        }
    }
    //This is the standard query to retrieve the events
    $sql .= "(SELECT e.id event_id, e.event_name, e.event_identifier, e.reg_limit, e.registration_start, ";
    $sql .= " e.start_date, e.is_active, e.recurrence_id, e.registration_startT, e.wp_user ";
    //Get the venue information
    if ($use_venue_manager) {
        //If using the venue manager, we need to get those fields
        $sql .= ", v.name AS venue_title, v.address AS venue_address, v.address2 AS venue_address2, v.city AS venue_city, v.state AS venue_state, v.zip AS venue_zip, v.country AS venue_country ";
    } else {
        //Otherwise we need to get the address fields from the individual events
        $sql .= ", e.venue_title, e.phone, e.address, e.address2, e.city, e.state, e.zip, e.country ";
    }
    //get the locale fields
    if ($is_regional_manager && $use_venue_manager) {
        $sql .= ", lc.name AS locale_name, e.wp_user ";
    }
    $sql .= " FROM " . EVENTS_DETAIL_TABLE . " e ";
    //Join the categories
    if ($category_id != FALSE) {
        $sql .= " JOIN " . EVENTS_CATEGORY_REL_TABLE . " cr ON cr.event_id = e.id ";
        $sql .= " JOIN " . EVENTS_CATEGORY_TABLE . " c ON  c.id = cr.cat_id ";
    }
    //Join the venues
    if ($use_venue_manager == true) {
        $sql .= " LEFT JOIN " . EVENTS_VENUE_REL_TABLE . " vr ON vr.event_id = e.id ";
        $sql .= " LEFT JOIN " . EVENTS_VENUE_TABLE . " v ON v.id = vr.venue_id ";
    }
    //Join the locales
    if (isset($is_regional_manager) && $is_regional_manager == true && $use_venue_manager == true) {
        $sql .= " LEFT JOIN " . EVENTS_LOCALE_REL_TABLE . " l ON  l.venue_id = vr.venue_id ";
        $sql .= " LEFT JOIN " . EVENTS_LOCALE_TABLE . " lc ON lc.id = l.locale_id ";
    }
    //Event status filter
    $sql .= isset($_POST['event_status']) && ($_POST['event_status'] != '' && $_POST['event_status'] != 'IA') ? " WHERE e.event_status = '" . $_POST['event_status'] . "' " : " WHERE e.event_status != 'D' ";
    //Category filter
    $sql .= $category_id !== FALSE ? " AND c.id = '" . $category_id . "' " : '';
    //Month filter
    if ($_POST['month_range'] != '') {
        $sql .= " AND e.start_date BETWEEN '" . date('Y-m-d', strtotime($year_r . '-' . $month_r . '-01')) . "' AND '" . date('Y-m-d', strtotime($year_r . '-' . $month_r . '-31')) . "' ";
    }
    //Todays events filter
    if (isset($_REQUEST['today']) && $_REQUEST['today'] == 'true') {
        $sql .= " AND e.start_date = '" . $curdate . "' ";
    }
    //This months events filter
    if (isset($_REQUEST['this_month']) && $_REQUEST['this_month'] == 'true') {
        $sql .= " AND e.start_date BETWEEN '" . date('Y-m-d', strtotime($this_year_r . '-' . $this_month_r . '-01')) . "' AND '" . date('Y-m-d', strtotime($this_year_r . '-' . $this_month_r . '-' . $days_this_month)) . "' ";
    }
    //If user is an event manager, then show only their events
    if (function_exists('espresso_member_data') && (espresso_member_data('role') == 'espresso_event_manager' || espresso_member_data('role') == 'espresso_group_admin')) {
        $sql .= " AND e.wp_user = '******'id') . "' ";
    }
    $sql .= ") ORDER BY start_date DESC ";
    $sql .= $records_to_show;
    $events = $wpdb->get_results($sql);
    $total_events = $wpdb->num_rows;
    ?>

	<form id="event-admin-list-page-select-frm" name="event_admin_list_page_select_frm" method="post" action="<?php 
    echo EVT_ADMIN_URL;
    ?>
">
		<div id="event-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 
    $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('max_rows' => $max_rows, 'start_rec' => $prev_rows), EVT_ADMIN_URL);
        ?>
			<a id="event-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_events >= $max_rows && $max_rows < 100000) {
        $next_rows = $start_rec + $max_rows + 1;
        $next_rows_url = add_query_arg(array('max_rows' => $max_rows, 'start_rec' => $next_rows), EVT_ADMIN_URL);
        ?>
			<a id="event-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="admin.php?page=events<?php 
    //echo $_SERVER["REQUEST_URI"]
    ?>
">
		<table id="table" class="widefat event-list" width="100%">
			<thead>
				<tr>
					<th class="manage-column column-cb check-column" id="cb" scope="col" style="width:28px;"><input type="checkbox"></th>

					<th class="manage-column column-comments num" id="id" style="padding-top:7px; width:3%;" scope="col" title="Click to Sort">
						<span><?php 
    _e('ID', 'event_espresso');
    ?>
</span>
						<span class="sorting-indicator"></span>
					</th>

					<th class="manage-column column-title" id="name" scope="col" title="Click to Sort" style="width:26%;">
						<span><?php 
    _e('Name', 'event_espresso');
    ?>
</span>
						<span class="sorting-indicator"></span>
					</th>

					<th class="manage-column column-title" id="name" scope="col" title="Click to Sort" style="width:12%;">
						<span><?php 
    _e('Venue', '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:12%;">
						<span><?php 
    _e('Start Date', '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 Time', 'event_espresso');
    ?>
</span>
						<span class="sorting-indicator"></span>
					</th>

					<th class="manage-column column-date" id="dow" scope="col" title="Click to Sort" style="width:6%;";>
							<span><?php 
    _e('DoW', '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:12%;">
						<span><?php 
    _e('Reg Begins', '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('Status', 'event_espresso');
    ?>
</span>
						<span class="sorting-indicator"></span>
					</th>
					<?php 
    if (function_exists('espresso_is_admin') && espresso_is_admin() == true && $espresso_premium == true) {
        ?>
						<th class="manage-column column-date" id="status" scope="col" title="Click to Sort" style="width:10%;">
							<span><?php 
        _e('Creator', 'event_espresso');
        ?>
</span>
							<span class="sorting-indicator"></span>
						</th>
					<?php 
    }
    ?>
					<th class="manage-column column-date" id="attendees" scope="col" title="Click to Sort" style="width:9%;">
						<span><?php 
    _e('Attendees', 'event_espresso');
    ?>
</span>
						<span class="sorting-indicator"></span>
					</th>
					<th class="manage-column column-author" id="actions" scope="col" style="width:25%;">
						<?php 
    _e('Actions', 'event_espresso');
    ?>
					</th>

				</tr>
			</thead>

			<tbody>
				<?php 
    if ($total_events > 0) {
        foreach ($events as $event) {
            //print_r ($event);
            $event_id = $event->event_id;
            $event_name = stripslashes_deep($event->event_name);
            $event_identifier = stripslashes_deep($event->event_identifier);
            $reg_limit = isset($event->reg_limit) ? $event->reg_limit : '';
            $registration_start = isset($event->registration_start) ? $event->registration_start : '';
            $start_date = isset($event->start_date) ? $event->start_date : '';
            $end_date = isset($event->end_date) ? $event->end_date : '';
            $is_active = isset($event->is_active) ? $event->is_active : '';
            $status = array();
            $status = event_espresso_get_is_active($event_id);
            $recurrence_id = isset($event->recurrence_id) ? $event->recurrence_id : '';
            $registration_startT = isset($event->registration_startT) ? $event->registration_startT : '';
            $event_address = isset($event->address) ? $event->address : '';
            $event_address2 = isset($event->address2) ? $event->address2 : '';
            $event_city = isset($event->city) ? $event->city : '';
            $event_state = isset($event->state) ? $event->state : '';
            $event_zip = isset($event->zip) ? $event->zip : '';
            $event_country = isset($event->country) ? $event->country : '';
            //added new
            $venue_title = isset($event->venue_title) ? $event->venue_title : '';
            $venue_locale = isset($event->locale_name) ? $event->locale_name : '';
            $wp_user = isset($event->wp_user) ? $event->wp_user : '';
            $location = (!empty($event_address) ? $event_address : '') . (!empty($event_address2) ? '<br />' . $event_address2 : '') . (!empty($event_city) ? '<br />' . $event_city : '') . (!empty($event_state) ? ', ' . $event_state : '') . (!empty($event_zip) ? '<br />' . $event_zip : '') . (!empty($event_country) ? '<br />' . $event_country : '');
            $dow = date("D", strtotime($start_date));
            ob_start();
            ?>
						<tr>
							<td class="check-column" style="padding:7px 0 22px 7px; vertical-align:top;"><!--Delete Events-->
								<?php 
            echo '<input name="checkbox[' . $event_id . ']" type="checkbox"  title="Delete Event ' . $event_name . '" />';
            ?>
</td>

							<td class="column-comments" style="padding-top:3px;"><?php 
            echo $event_id;
            ?>
</td>

							<td class="post-title page-title"><strong><a class="row-title" href="admin.php?page=events&action=edit&event_id=<?php 
            echo $event_id;
            ?>
"><?php 
            echo $event_name;
            ?>
</a> <?php 
            echo $recurrence_id > 0 ? $recurrence_icon : '';
            ?>
 </strong>
								<div class="row-actions"><span><a href="<?php 
            echo espresso_reg_url($event_id);
            ?>
" target="_blank"><?php 
            _e('View', 'event_espresso');
            ?>
</a> | </span><span class='edit'><a href="admin.php?page=events&amp;action=edit&amp;event_id=<?php 
            echo $event_id;
            ?>
"><?php 
            _e('Edit', 'event_espresso');
            ?>
</a> | </span><span class='delete'><a onclick="return confirmDelete();" href='admin.php?page=events&amp;action=delete&amp;event_id=<?php 
            echo $event_id;
            ?>
'><?php 
            _e('Delete', 'event_espresso');
            ?>
</a></span> | <span><a href="admin.php?page=events&amp;event_admin_reports=list_attendee_payments&amp;event_id=<?php 
            echo $event_id;
            ?>
"><?php 
            _e('Attendees', 'event_espresso');
            ?>
</a> | </span><span><a href="#" onclick="window.location='<?php 
            echo get_bloginfo('wpurl') . "/wp-admin/admin.php?event_espresso&amp;event_id=" . $event_id . "&amp;export=report&action=payment&amp;type=excel";
            ?>
'" title="<?php 
            _e('Export to Excel', 'event_espresso');
            ?>
"><?php 
            _e('Export', 'event_espresso');
            ?>
</a></span></div></td>

							<td class="author"><?php 
            echo $venue_title != '' ? $venue_title : '';
            echo $venue_locale != '' ? '<br />[' . $venue_locale . ']' : '';
            ?>
</td>

							<td class="author"><?php 
            echo event_date_display($start_date, get_option('date_format'));
            ?>
</td>

							<td class="author"><?php 
            echo event_espresso_get_time($event_id, 'start_time');
            ?>
</td>

							<td class="date"><?php 
            echo $dow;
            ?>
</td>

							<td class="date"><?php 
            echo event_date_display($registration_start, get_option('date_format'));
            ?>
 <br />
								<?php 
            echo $registration_startT;
            ?>
</td>

							<td class="date"><?php 
            echo $status['display'];
            ?>
</td>

							<?php 
            if (function_exists('espresso_is_admin') && espresso_is_admin() == true && $espresso_premium == true) {
                $user_company = espresso_user_meta($wp_user, 'company') != '' ? espresso_user_meta($wp_user, 'company') : '';
                $user_organization = espresso_user_meta($wp_user, 'organization') != '' ? espresso_user_meta($wp_user, 'organization') : '';
                $user_co_org = $user_company != '' ? $user_company : $user_organization;
                ?>
								<td class="date"><?php 
                echo espresso_user_meta($wp_user, 'user_firstname') != '' ? espresso_user_meta($wp_user, 'user_firstname') . ' ' . espresso_user_meta($wp_user, 'user_lastname') . ' (<a href="user-edit.php?user_id=' . $wp_user . '">' . espresso_user_meta($wp_user, 'user_nicename') . '</a>)' : espresso_user_meta($wp_user, 'display_name') . ' (<a href="user-edit.php?user_id=' . $wp_user . '">' . espresso_user_meta($wp_user, 'user_nicename') . '</a>)';
                ?>
									<?php 
                echo $user_co_org != '' ? '<br />[' . espresso_user_meta($wp_user, 'company') . ']' : '';
                ?>
								</td>
							<?php 
            }
            ?>

							<td class="author"><a href="admin.php?page=events&amp;event_admin_reports=list_attendee_payments&amp;event_id=<?php 
            echo $event_id;
            ?>
"><?php 
            echo get_number_of_attendees_reg_limit($event_id, 'num_attendees_slash_reg_limit');
            ?>
</a></td>
							<td class="date"><div style="width:180px;"><a href="<?php 
            echo espresso_reg_url($event_id);
            ?>
" title="<?php 
            _e('View Event', 'event_espresso');
            ?>
" target="_blank"><div class="view_btn"></div></a>

									<a href="admin.php?page=events&amp;action=edit&amp;event_id=<?php 
            echo $event_id;
            ?>
" title="<?php 
            _e('Edit Event', 'event_espresso');
            ?>
"><div class="edit_btn"></div></a>

									<a href="admin.php?page=events&amp;event_id=<?php 
            echo $event_id;
            ?>
&amp;event_admin_reports=list_attendee_payments" title="<?php 
            _e('View Attendees', 'event_espresso');
            ?>
"><div class="complete_btn"></div></a>
									<a href="admin.php?page=events&event_admin_reports=charts&event_id=<?php 
            echo $event_id;
            ?>
" title="<?php 
            _e('View Report', 'event_espresso');
            ?>
"><div class="reports_btn"></div></a>


									<a class="thickbox" href="#TB_inline?height=300&width=400&inlineId=unique_id_info_<?php 
            echo $event_id;
            ?>
" title="<?php 
            _e('Get Short URL/Shortcode', 'event_espresso');
            ?>
"><div class="shortcode_btn"></div></a>

									<a href="#" onclick="window.location='<?php 
            echo get_bloginfo('wpurl') . "/wp-admin/admin.php?event_espresso&amp;event_id=" . $event_id . "&amp;export=report&action=payment&amp;type=excel";
            ?>
'" title="<?php 
            _e('Export to Excel', 'event_espresso');
            ?>
"><div class="excel_exp_btn"></div></a>

									<a href="#" onclick="window.location='<?php 
            echo get_bloginfo('wpurl') . "/wp-admin/admin.php?event_espresso&event_id=" . $event_id . "&export=report&action=payment&type=csv";
            ?>
'" title="<?php 
            _e('Export to CSV', 'event_espresso');
            ?>
"><div class="csv_exp_btn"></div></a>

									<a href="admin.php?page=events&amp;event_admin_reports=event_newsletter&amp;event_id=<?php 
            echo $event_id;
            ?>
" title="<?php 
            _e('Email Attendees', 'event_espresso');
            ?>
"><div class="newsletter_btn"></div></a></div>

								<div id="unique_id_info_<?php 
            echo $event_id;
            ?>
" style="display:none">
									<?php 
            _e('<h2>Short URL/Shortcode</h2><p>This is the short URL to this event:</p><p><span  class="updated fade">' . espresso_reg_url($event_id) . '</span></p><p>This will show the registration form for this event just about anywhere. Copy and paste the following shortcode into any page or post.</p><p><span  class="updated fade">[SINGLEEVENT single_event_id="' . $event_identifier . '"]</span></p> <p class="red_text"> Do not use in place of the main events page that is set in the Organization Settings page.', 'event_espresso');
            ?>
								</div></td>
						</tr>
						<?php 
            //echo $_REQUEST['event_status'];
            if (!empty($_REQUEST['event_status'])) {
                $content = ob_get_contents();
                ob_end_clean();
                switch ($_REQUEST['event_status']) {
                    case 'A':
                        switch (event_espresso_get_status($event_id, empty($event_meta) ? '' : $event_meta)) {
                            case 'NOT_ACTIVE':
                                //Don't show the event if any of the above are true
                                break;
                            default:
                                echo $content;
                                break;
                        }
                        break;
                    case 'IA':
                        switch (event_espresso_get_status($event_id)) {
                            case 'NOT_ACTIVE':
                                echo $content;
                                break;
                            default:
                                //Don't show the event if any of the above are true
                                break;
                        }
                        break;
                    default:
                        echo $content;
                        break;
                }
            }
        }
        //End foreach ($events as $event){
    }
    ?>

			</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><?php 
    if (isset($_POST['event_status']) && $_POST['event_status'] == 'D') {
        ?>
				<input name="perm_delete_event" type="submit" class="button-secondary" id="perm_delete_event" value="<?php 
        _e('Permanently Delete Events(s)', 'event_espresso');
        ?>
" style="margin:10px 0 0 10px;" onclick="return confirmDelete();" />
			<?php 
    } else {
        ?>
				<input name="delete_event" type="submit" class="button-secondary" id="delete_event" value="<?php 
        _e('Delete Events(s)', 'event_espresso');
        ?>
" style="margin:10px 0 0 10px;" onclick="return confirmDelete();" />

				<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 style="margin-left:5px" class="button-secondary" href="#" onclick="window.location='<?php 
        echo get_bloginfo('wpurl') . "/wp-admin/admin.php?event_espresso&amp;id=" . $event_id . "&amp;export=report&action=payment&amp;type=excel&all_events=true";
        ?>
'" title="<?php 
        _e('Export to Excel', 'event_espresso');
        ?>
"><?php 
        _e('Export All Attendee Data', 'event_espresso');
        ?>
</a>
				<a class="button-secondary" href="#" onclick="window.location='<?php 
        echo get_bloginfo('wpurl') . "/wp-admin/admin.php?event_espresso&amp;id=" . $event_id . "&amp;export=report&action=event&amp;type=excel&all_events=true";
        ?>
'" title="<?php 
        _e('Export to Excel', 'event_espresso');
        ?>
"><?php 
        _e('Export All Event Data', 'event_espresso');
        ?>
</a>
				<a style="margin-left:5px" class="button-primary" href="admin.php?page=events&amp;action=add_new_event"><?php 
        _e('Add New 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">
		<?php 
    echo defined('EVENT_ESPRESSO_RECURRENCE_MODULE_ACTIVE') ? '<dt><img src="' . EVENT_ESPRESSO_PLUGINFULLURL . 'images/arrow_rotate_clockwise.png" alt="Recurring Event" title="Recurring Event"  /> - ' . __('Recurring Event', 'event_espresso') . '</dt>' : '';
    ?>
		<dt><img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
images/icons/magnifier.png" width="16" height="16" alt="<?php 
    _e('View Event', 'event_espresso');
    ?>
" /> - <?php 
    _e('View Event', 'event_espresso');
    ?>
</dt>

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

		<dt><img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
images/icons/group.png" width="16" height="16" alt="<?php 
    _e('Event Attendees', 'event_espresso');
    ?>
" /> - <?php 
    _e('Event Attendees', 'event_espresso');
    ?>
</dt>
		<dt><img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
images/icons/chart_bar.png" width="16" height="16" alt="<?php 
    _e('Send Event Email', 'event_espresso');
    ?>
" /> - <?php 
    _e('View Report', 'event_espresso');
    ?>
</dt>


	</dl>

	<dl style="float:left; margin-left:10px;">
		<dt><img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
images/icons/tag.png" width="16" height="16" alt="<?php 
    _e('Short Code', 'event_espresso');
    ?>
" /> - <?php 
    _e('Short Code', 'event_espresso');
    ?>
</dt>
		<dt><img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
images/icons/excel_icon.png" width="16" height="16" alt="<?php 
    _e('Excel Spreadsheet', 'event_espresso');
    ?>
" /> - <?php 
    _e('Excel Export', 'event_espresso');
    ?>
</dt>

		<dt><img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
images/icons/csv_icon_sm.gif" width="16" height="16" alt="<?php 
    _e('CSV Spreadsheet', 'event_espresso');
    ?>
" /> - <?php 
    _e('CSV Export', 'event_espresso');
    ?>
</dt>

		<dt><img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
images/icons/email_go.png" width="16" height="16" alt="<?php 
    _e('View Report', 'event_espresso');
    ?>
" /> - <?php 
    _e('Event Newsletter', 'event_espresso');
    ?>
</dt>
	</dl>

	<script>
		jQuery(document).ready(function($) {
			/* show the table data */
			var mytable = $('#table').dataTable( {
				"sDom": 'Clfrtip',
				"aoColumns": [
					{ "bSortable": false },
					null,
					null,
					null,
					null,
					null,
					null,
					null,
					null,
	<?php 
    echo function_exists('espresso_is_admin') && espresso_is_admin() == true ? 'null,' : '';
    ?>
					null,
					{ "bSortable": false }
				],
				"aoColumnDefs": [
					{ "bVisible": false, "aTargets": [ <?php 
    echo $org_options['use_venue_manager'] == 'Y' ? '' : '3,';
    ?>
 6 ] }
				],
				"oColVis": {
					"aiExclude": [ 0, 1, 2 ],
					"buttonText": "Filter: Show / Hide Columns",
					"bRestore": true
				},
				"bAutoWidth": false,
				"bStateSave": true,
				"sPaginationType": "full_numbers",
				"oLanguage": {	"sSearch": "<strong><?php 
    _e('Live Search Filter', 'event_espresso');
    ?>
:</strong>",
					"sZeroRecords": "<?php 
    _e('No Records Found!', 'event_espresso');
    ?>
" }

			});
		});
	</script>

	<div id="coupon_code_info" style="display:none">
		<h2><?php 
    _e('Coupon/Promo Code', 'event_espresso');
    ?>
</h2><p><?php 
    _e('This is used to apply discounts to events.', 'event_espresso');
    ?>
</p><p><?php 
    _e('A coupon or promo code could can be anything you want. For example: Say you have an event that costs', 'event_espresso');
    ?>
 <?php 
    echo $org_options['currency_symbol'];
    ?>
200. <?php 
    _e('If you supplied a promo like "PROMO50" and entered 50.00 into the "Discount w/Promo Code" field your event will be discounted', 'event_espresso');
    ?>
  <?php 
    echo $org_options['currency_symbol'];
    ?>
50.00, <?php 
    _e('Bringing the cost of the event to', 'event_espresso');
    ?>
 <?php 
    echo $org_options['currency_symbol'];
    ?>
150.</p>
	</div>
	<div id="unique_id_info" style="display:none">
		<h2><?php 
    _e('Event Identifier', 'event_espresso');
    ?>
</h2><p><?php 
    _e('This should be a unique identifier for the event. Example: "Event1" (without qoutes.)</p><p>The unique ID can also be used in individual pages using the', 'event_espresso');
    ?>
 [SINGLEEVENT single_event_id="<?php 
    _e('Unique Event ID', 'event_espresso');
    ?>
"] <?php 
    _e('shortcode', 'event_espresso');
    ?>
.</p>
	</div>
	<?php 
    echo event_espresso_custom_email_info();
}
    function event_espresso_get_event_details($sql)
    {
        //print_r( $_SESSION['event_espresso_sessionid']); //See if the session already exists
        global $wpdb, $org_options;
        //echo 'This page is located in ' . get_option( 'upload_path' );
        $event_page_id = $org_options['event_page_id'];
        $currency_symbol = $org_options['currency_symbol'];
        $events = $wpdb->get_results($sql);
        $category_id = $wpdb->last_result[0]->id;
        $category_name = $wpdb->last_result[0]->category_name;
        $category_desc = html_entity_decode(wpautop($wpdb->last_result[0]->category_desc));
        $display_desc = $wpdb->last_result[0]->display_desc;
        if ($display_desc == 'Y') {
            echo '<p id="events_category_name-' . $category_id . '" class="events_category_name">' . stripslashes_deep($category_name) . '</p>';
            echo wpautop($category_desc);
        }
        foreach ($events as $event) {
            $event_id = $event->id;
            $event_name = $event->event_name;
            $event_identifier = $event->event_identifier;
            $active = $event->is_active;
            $registration_start = $event->registration_start;
            $registration_end = $event->registration_end;
            $start_date = $event->start_date;
            $end_date = $event->end_date;
            $reg_limit = $event->reg_limit;
            $event_address = $event->address;
            $member_only = $event->member_only;
            $externalURL = $event->externalURL;
            $allow_overflow = $event->allow_overflow;
            $overflow_event_id = $event->overflow_event_id;
            $registration_url = $externalURL != '' ? $externalURL : get_option('siteurl') . '/?page_id=' . $event_page_id . '&regevent_action=register&event_id=' . $event_id . '&name_of_event=' . stripslashes_deep($event_name);
            if (!is_user_logged_in() && get_option('events_members_active') == 'true' && $member_only == 'Y') {
                //Display a message if the user is not logged in.
                //_e('Member Only Event. Please ','event_espresso') . event_espresso_user_login_link() . '.';
            } else {
                ?>
  
				<div id="event_data-<?php 
                echo $event_id;
                ?>
" class="event_data">
				<h3 id="event_title-<?php 
                echo $event_id;
                ?>
" class="event_title"><a title="<?php 
                echo stripslashes_deep($event_name);
                ?>
" class="a_event_title" id="a_event_title-<?php 
                echo $event_id;
                ?>
" href="<?php 
                echo get_option('siteurl');
                ?>
/?page_id=<?php 
                echo $event_page_id;
                ?>
&regevent_action=register&event_id=<?php 
                echo $event_id;
                ?>
&name_of_event=<?php 
                echo stripslashes_deep($event_name);
                ?>
"><?php 
                echo stripslashes_deep($event_name);
                ?>
</a></h3>
				<p id="p_event_price-<?php 
                echo $event_id;
                ?>
">
				<?php 
                echo __('Price: ', 'event_espresso') . event_espresso_get_price($event_id);
                ?>
				</p>
				
                <p id="event_date-<?php 
                echo $event_id;
                ?>
"><?php 
                _e('Start Date:', 'event_espresso');
                ?>
  <?php 
                echo event_date_display($start_date);
                ?>
 <br /> <?php 
                _e('End Date:', 'event_espresso');
                ?>
 <?php 
                echo event_date_display($end_date);
                ?>
</p>

				<p id="event_address-<?php 
                echo $event_id;
                ?>
"><?php 
                _e('Address:', 'event_espresso');
                ?>
 <?php 
                echo $event_address;
                ?>
</p>
<?php 
                /*
                * Display the amount of attendees and/or registration limit
                Available parameters for the get_number_of_attendees_reg_limit() function
                *  @ $event_id - required
                *  @ $type - 
                *	available_spaces = returns the number of available spaces
                *	num_attendees = returns the number of attendees
                *	reg_limit = returns the total number of spaces
                *	num_incomplete = returns the number of incomplete (non paid) registrations
                *	num_completed = returns the number of completed (paid) registrations
                *	num_completed_slash_incomplete = returns the number of completed and incomplete registrations separated by a slash (eg. 3/1)
                *		num_attendees_slash_reg_limit = returns the number of attendees and the registration limit separated by a slash (eg. 4/30)
                */
                $num_attendees = get_number_of_attendees_reg_limit($event_id, 'num_attendees');
                //Get the number of attendees
                if ($num_attendees >= $reg_limit) {
                    ?>
				<p id="available_spaces-<?php 
                    echo $event_id;
                    ?>
"><?php 
                    _e('Available Spaces:', 'event_espresso');
                    ?>
 <?php 
                    echo get_number_of_attendees_reg_limit($event_id, 'available_spaces');
                    ?>
</p>
							   
				<p id="register_link-<?php 
                    echo $overflow_event_id;
                    ?>
"><a class="a_register_link" id="a_register_link-<?php 
                    echo $overflow_event_id;
                    ?>
" href="<?php 
                    echo get_option('siteurl');
                    ?>
/?page_id=<?php 
                    echo $event_page_id;
                    ?>
&regevent_action=register&event_id=<?php 
                    echo $overflow_event_id;
                    ?>
&name_of_event=<?php 
                    echo stripslashes_deep($event_name);
                    ?>
" title="<?php 
                    echo stripslashes_deep($event_name);
                    ?>
"><?php 
                    _e('Join Waiting List', 'event_espresso');
                    ?>
</a></p> 
				</div>
<?php 
                } else {
                    ?>
		<p id="available_spaces-<?php 
                    echo $event_id;
                    ?>
"><?php 
                    _e('Available Spaces:', 'event_espresso');
                    ?>
 <?php 
                    echo get_number_of_attendees_reg_limit($event_id, 'available_spaces');
                    ?>
</p>
							   
				<p id="register_link-<?php 
                    echo $event_id;
                    ?>
"><a class="a_register_link" id="a_register_link-<?php 
                    echo $event_id;
                    ?>
" href="<?php 
                    echo get_option('siteurl');
                    ?>
/?page_id=<?php 
                    echo $event_page_id;
                    ?>
&regevent_action=register&event_id=<?php 
                    echo $event_id;
                    ?>
&name_of_event=<?php 
                    echo stripslashes_deep($event_name);
                    ?>
" title="<?php 
                    echo stripslashes_deep($event_name);
                    ?>
"><?php 
                    _e('Register Online', 'event_espresso');
                    ?>
</a></p> 
				<p><?php 
                    echo espresso_show_social_media($event_id, 'twitter');
                    ?>
 <?php 
                    echo espresso_show_social_media($event_id, 'facebook');
                    ?>
</p>
				</div>
<?php 
                }
            }
        }
        //Check to see how many database queries were performed
        //echo '<p>Database Queries: ' . get_num_queries() .'</p>';
    }
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 
    }
}
Exemplo n.º 30
0
 function event_espresso_get_event_details($attributes)
 {
     global $wpdb, $org_options, $events_in_session;
     $event_page_id = $org_options['event_page_id'];
     $currency_symbol = isset($org_options['currency_symbol']) ? $org_options['currency_symbol'] : '';
     $ee_search = isset($_REQUEST['ee_search']) && $_REQUEST['ee_search'] == 'true' && isset($_REQUEST['ee_name']) && !empty($_REQUEST['ee_name']) ? true : false;
     $ee_search_string = isset($_REQUEST['ee_name']) && !empty($_REQUEST['ee_name']) ? sanitize_text_field($_REQUEST['ee_name']) : '';
     //Check for Multi Event Registration
     $multi_reg = false;
     $category_name = '';
     if (function_exists('event_espresso_multi_reg_init')) {
         $multi_reg = true;
     }
     $default_attributes = array('category_identifier' => NULL, 'staff_id' => NULL, 'allow_override' => 0, 'show_expired' => 'false', 'show_secondary' => 'false', 'show_deleted' => 'false', 'show_recurrence' => 'true', 'limit' => '0', 'order_by' => 'NULL', 'sort' => 'ASC', 'css_class' => 'NULL', 'current_page' => 1, 'events_per_page' => 50, 'num_page_links_to_display' => 10, 'use_wrapper' => true);
     // loop thru default atts
     foreach ($default_attributes as $key => $default_attribute) {
         // check if att exists
         if (!isset($attributes[$key])) {
             $attributes[$key] = $default_attribute;
         }
     }
     // now extract shortcode attributes
     extract($attributes);
     //Create the query
     $DISTINCT = $ee_search == true ? "DISTINCT" : '';
     $sql = "SELECT {$DISTINCT} e.*, ese.start_time, ese.end_time, p.event_cost ";
     //Category sql
     $sql .= $category_identifier != NULL && !empty($category_identifier) ? ", c.category_name, c.category_desc, c.display_desc, c.category_identifier" : '';
     //Venue sql
     isset($org_options['use_venue_manager']) && $org_options['use_venue_manager'] == 'Y' ? $sql .= ", v.name venue_name, v.address venue_address, v.city venue_city, v.state venue_state, v.zip venue_zip, v.country venue_country, v.meta venue_meta " : '';
     //Staff sql
     isset($org_options['use_personnel_manager']) && $org_options['use_personnel_manager'] == 'Y' ? $sql .= ", st.name staff_name " : '';
     $sql .= " FROM " . EVENTS_DETAIL_TABLE . " e ";
     $sql .= $category_identifier != NULL && !empty($category_identifier) ? " JOIN " . EVENTS_CATEGORY_REL_TABLE . " r ON r.event_id = e.id  JOIN " . EVENTS_CATEGORY_TABLE . " c ON  c.id = r.cat_id " : '';
     //Venue sql
     isset($org_options['use_venue_manager']) && $org_options['use_venue_manager'] == 'Y' ? $sql .= " LEFT JOIN " . EVENTS_VENUE_REL_TABLE . " vr ON vr.event_id = e.id LEFT JOIN " . EVENTS_VENUE_TABLE . " v ON v.id = vr.venue_id " : '';
     //Venue sql
     isset($org_options['use_personnel_manager']) && $org_options['use_personnel_manager'] == 'Y' ? $sql .= " LEFT JOIN " . EVENTS_PERSONNEL_REL_TABLE . " str ON str.event_id = e.id LEFT JOIN " . EVENTS_PERSONNEL_TABLE . " st ON st.id = str.person_id " : '';
     $sql .= " LEFT JOIN " . EVENTS_START_END_TABLE . " ese ON ese.event_id= e.id ";
     $sql .= " LEFT JOIN " . EVENTS_PRICES_TABLE . " p ON p.event_id=e.id ";
     $sql .= " WHERE is_active = 'Y' ";
     //Category sql
     $sql .= $category_identifier !== NULL && !empty($category_identifier) ? " AND c.category_identifier = '" . $category_identifier . "' " : '';
     //Staff sql
     $sql .= $staff_id !== NULL && !empty($staff_id) ? " AND st.id = '" . $staff_id . "' " : '';
     $sql .= $show_expired == 'false' ? " AND (e.start_date >= '" . date('Y-m-d') . "' OR e.event_status = 'O' OR e.registration_end >= '" . date('Y-m-d') . "') " : '';
     if ($show_expired == 'true') {
         $allow_override = 1;
     }
     //If using the [ESPRESSO_VENUE_EVENTS] shortcode
     $sql .= isset($use_venue_id) && $use_venue_id == true ? " AND v.id = '" . $venue_id . "' " : '';
     $sql .= $show_secondary == 'false' ? " AND e.event_status != 'S' " : '';
     $sql .= $show_deleted == 'false' ? " AND e.event_status != 'D' " : " AND e.event_status = 'D' ";
     if ($show_deleted == 'true') {
         $allow_override = 1;
     }
     //echo '<p>'.$order_by.'</p>';
     $sql .= $show_recurrence == 'false' ? " AND e.recurrence_id = '0' " : '';
     //Search query
     if ($ee_search) {
         // search for full original string within bracketed search options
         $sql .= " AND ( e.event_name LIKE '%{$ee_search_string}%' ";
         // array of common words that we don't want to waste time looking for
         $words_to_strip = array(' the ', ' a ', ' or ', ' and ');
         $words = str_replace($words_to_strip, ' ', $ee_search_string);
         // break words array into individual strings
         $words = explode(' ', $words);
         // search for each word  as an OR statement
         foreach ($words as $word) {
             $sql .= " OR e.event_name LIKE '%{$word}%' ";
         }
         // close the search options
         $sql .= " ) ";
     }
     $sql .= " GROUP BY e.id ";
     $sql .= $order_by != 'NULL' ? " ORDER BY " . $order_by . " " . $sort . " " : " ORDER BY date(start_date), id ASC ";
     $sql .= $limit > 0 ? ' LIMIT 0, ' . $limit : '';
     //echo $sql;
     //echo 'This page is located in ' . get_option( 'upload_path' );
     $events = $wpdb->get_results($sql);
     $category_id = isset($wpdb->last_result[0]->id) ? $wpdb->last_result[0]->id : '';
     $category_name = isset($wpdb->last_result[0]->category_name) ? $wpdb->last_result[0]->category_name : '';
     $category_identifier = isset($wpdb->last_result[0]->category_identifier) ? $wpdb->last_result[0]->category_identifier : '';
     $category_desc = isset($wpdb->last_result[0]->category_desc) ? html_entity_decode(wpautop($wpdb->last_result[0]->category_desc)) : '';
     $display_desc = isset($wpdb->last_result[0]->display_desc) ? $wpdb->last_result[0]->display_desc : '';
     $total_events = count($events);
     $total_pages = ceil($total_events / $events_per_page);
     $offset = ($current_page - 1) * $events_per_page;
     $events = array_slice($events, $offset, $events_per_page);
     //Debug
     //var_dump($events);
     if ($use_wrapper) {
         echo "<div id='event_wrapper'>";
     }
     $page_link_ar = array();
     foreach ($attributes as $key => $attribute) {
         if (!in_array($key, array('current_page', 'use_wrapper'))) {
             $page_link_ar[] = "{$key}=" . urlencode($attribute);
         }
     }
     $page_link = implode('&', $page_link_ar);
     echo "<div id='event_search_code' style='display:none;' data='{$page_link}'></div>";
     //css_class='$css_class' allow_override='$allow_override' events_per_page='$events_per_page' num_page_links_to_display='$num_page_links_to_display'></div>";
     echo "<div id='event_container_pagination' >";
     if ($total_pages > 1) {
         $mid = ceil($num_page_links_to_display / 2);
         if ($num_page_links_to_display % 2 == 0) {
             $back = $mid;
         } else {
             $back = $mid - 1;
         }
         $start = $current_page - $back;
         if ($start < 1) {
             $start = 1;
         }
         $end = $start + $num_page_links_to_display;
         if ($end > $total_pages) {
             $end = $total_pages;
         }
         $prev = $current_page - 1;
         $prev_no_more = '';
         if ($prev < 1) {
             $prev = 1;
             $prev_no_more = 'no_more';
         }
         $next = $current_page + 1;
         $next_no_more = '';
         if ($next > $total_pages) {
             $next = $total_pages;
             $next_no_more = 'no_more';
         }
         $espresso_paginate = "<div class='page_navigation'>";
         $espresso_paginate .= "<a href='#' current_page=1 class='event_paginate {$prev_no_more} ui-icon ui-icon-seek-first'>&lt;&lt;</a>";
         $espresso_paginate .= "<a href='#' current_page={$prev} class='event_paginate {$prev_no_more} ui-icon ui-icon-seek-prev'>&lt;</a>";
         if ($start > 1) {
             $espresso_paginate .= "<span class='ellipse less'>...</span>";
         }
         for ($i = $start; $i <= $end; $i++) {
             $active_page = '';
             if ($i == $current_page) {
                 $active_page = 'active_page';
             }
             $espresso_paginate .= "<a class='page_link event_paginate {$active_page} ' current_page={$i} href='#' style='display: block; '>{$i}</a>";
         }
         if ($end < $total_pages) {
             $espresso_paginate .= "<span class='ellipse more'>...</span>";
         }
         $espresso_paginate .= "<a href='#' current_page={$next} class='event_paginate {$next_no_more} ui-icon ui-icon-seek-next'>&gt;</a>";
         $espresso_paginate .= "<a href='#' current_page={$total_pages} class='event_paginate {$next_no_more} ui-icon ui-icon-seek-end'>&gt;&gt;</a>";
         $espresso_paginate .= "</div>";
     }
     echo "<div id='event_content' class='event_content'>";
     if (count($events) < 1) {
         //echo $sql;
         echo __('No events available...', 'event_espresso');
     }
     if ($display_desc == 'Y') {
         echo '<p id="events_category_name-' . $category_id . '" class="events_category_name">' . stripslashes_deep($category_name) . '</p>';
         echo espresso_format_content($category_desc);
     }
     foreach ($events as $event) {
         $event_id = $event->id;
         $event_name = $event->event_name;
         $event_desc = stripslashes_deep($event->event_desc);
         $event_identifier = $event->event_identifier;
         $active = $event->is_active;
         $registration_start = $event->registration_start;
         $registration_end = $event->registration_end;
         $start_date = $event->start_date;
         $end_date = $event->end_date;
         $reg_limit = $event->reg_limit;
         $event_address = $event->address;
         $event_address2 = $event->address2;
         $event_city = $event->city;
         $event_state = $event->state;
         $event_zip = $event->zip;
         $event_country = $event->country;
         $member_only = $event->member_only;
         $externalURL = $event->externalURL;
         $recurrence_id = $event->recurrence_id;
         $display_reg_form = $event->display_reg_form;
         $allow_overflow = $event->allow_overflow;
         $overflow_event_id = $event->overflow_event_id;
         $event_desc = array_shift(explode('<!--more-->', $event_desc));
         global $event_meta;
         $event_meta = unserialize($event->event_meta);
         $event_meta['is_active'] = $event->is_active;
         $event_meta['event_status'] = $event->event_status;
         $event_meta['start_time'] = empty($event->start_time) ? '' : $event->start_time;
         $event_meta['start_date'] = $event->start_date;
         $event_meta['registration_start'] = $event->registration_start;
         $event_meta['registration_startT'] = $event->registration_startT;
         $event_meta['registration_end'] = $event->registration_end;
         $event_meta['registration_endT'] = $event->registration_endT;
         //Venue information
         if ($org_options['use_venue_manager'] == 'Y') {
             $event_address = empty($event->venue_address) ? '' : $event->venue_address;
             $event_address2 = empty($event->venue_address2) ? '' : $event->venue_address2;
             $event_city = empty($event->venue_city) ? '' : $event->venue_city;
             $event_state = empty($event->venue_state) ? '' : $event->venue_state;
             $event_zip = empty($event->venue_zip) ? '' : $event->venue_zip;
             $event_country = empty($event->venue_country) ? '' : $event->venue_country;
             //Leaving these variables intact, just in case people want to use them
             $venue_title = empty($event->venue_name) ? '' : $event->venue_name;
             $venue_address = $event_address;
             $venue_address2 = $event_address2;
             $venue_city = $event_city;
             $venue_state = $event_state;
             $venue_zip = $event_zip;
             $venue_country = $event_country;
             global $venue_meta;
             $add_venue_meta = array('venue_title' => $venue_title, 'venue_address' => $event_address, 'venue_address2' => $event_address2, 'venue_city' => $event_city, 'venue_state' => $event_state, 'venue_country' => $event_country);
             $venue_meta = !empty($event->venue_meta) && !empty($add_venue_meta) ? array_merge(unserialize($event->venue_meta), $add_venue_meta) : '';
             //print_r($venue_meta);
         }
         //Address formatting
         $location = (!empty($event_address) ? $event_address : '') . (!empty($event_address2) ? '<br />' . $event_address2 : '') . (!empty($event_city) ? '<br />' . $event_city : '') . (!empty($event_state) ? ', ' . $event_state : '') . (!empty($event_zip) ? '<br />' . $event_zip : '') . (!empty($event_country) ? '<br />' . $event_country : '');
         //Google map link creation
         $google_map_link = espresso_google_map_link(array('address' => $event_address, 'city' => $event_city, 'state' => $event_state, 'zip' => $event_zip, 'country' => $event_country, 'text' => 'Map and Directions', 'type' => 'text'));
         global $all_meta;
         $all_meta = array('event_id' => $event_id, 'event_name' => stripslashes_deep($event_name), 'event_desc' => stripslashes_deep($event_desc), 'event_address' => $event_address, 'event_address2' => $event_address2, 'event_city' => $event_city, 'event_state' => $event_state, 'event_zip' => $event_zip, 'event_country' => $venue_country, 'venue_title' => $venue_title, 'venue_address' => $venue_address, 'venue_address2' => $venue_address2, 'venue_city' => $venue_city, 'venue_state' => $venue_state, 'venue_country' => $venue_country, 'location' => $location, 'is_active' => $event->is_active, 'event_status' => $event->event_status, 'contact_email' => empty($event->alt_email) ? $org_options['contact_email'] : $event->alt_email, 'start_time' => empty($event->start_time) ? '' : $event->start_time, 'registration_startT' => $event->registration_startT, 'registration_start' => $registration_start, 'registration_endT' => $event->registration_endT, 'registration_end' => $registration_end, 'is_active' => empty($is_active) ? '' : $is_active, 'event_country' => $event_country, 'start_date' => event_date_display($start_date, get_option('date_format')), 'end_date' => event_date_display($end_date, get_option('date_format')), 'time' => empty($event->start_time) ? '' : $event->start_time, 'start_time' => empty($event->start_time) ? '' : $event->start_time, 'end_time' => empty($event->end_time) ? '' : $event->end_time, 'google_map_link' => $google_map_link, 'price' => empty($event->event_cost) ? '' : $event->event_cost, 'event_cost' => empty($event->event_cost) ? '' : $event->event_cost);
         //Debug
         //echo '<p>'.print_r($all_meta).'</p>';
         //These variables can be used with other the espresso_countdown, espresso_countup, and espresso_duration functions and/or any javascript based functions.
         //Warning: May cause additional database queries an should only be used for sites with a small amount of events.
         // $start_timestamp = espresso_event_time($event_id, 'start_timestamp');
         //$end_timestamp = espresso_event_time($event_id, 'end_timestamp');
         //This can be used in place of the registration link if you are usign the external URL feature
         $registration_url = $externalURL != '' ? $externalURL : espresso_reg_url($event_id);
         //Serve up the event list
         //As of version 3.0.17 the event list details have been moved to event_list_display.php
         if ($allow_override == 1) {
             //Uncomment to show active status array
             //print_r( event_espresso_get_is_active($event_id));
             include 'event_list_display.php';
         } else {
             switch (event_espresso_get_status($event_id)) {
                 case 'NOT_ACTIVE':
                     //Don't show the event
                     //Uncomment the following two lines to show events that are not active and the active status array
                     //print_r( event_espresso_get_is_active($event_id));
                     //include('event_list_display.php');
                     break;
                 case 'PENDING':
                     if (current_user_can('administrator') || function_exists('espresso_member_data') && espresso_can_view_event($event_id) == true) {
                         //Uncomment to show active status array
                         //print_r( event_espresso_get_is_active($event_id));
                         echo '<div class="pending_event">';
                         include 'event_list_display.php';
                         echo '</div>';
                     }
                     break;
                 default:
                     //Uncomment to show active status array
                     //print_r( event_espresso_get_is_active($event_id));
                     include 'event_list_display.php';
                     break;
             }
         }
     }
     echo "</div>";
     echo "</div>";
     if (isset($espresso_paginate)) {
         echo $espresso_paginate;
         // spit out the pagination links
     }
     if ($use_wrapper) {
         echo "</div>";
     }
     //Check to see how many database queries were performed
     //echo '<p>Database Queries: ' . get_num_queries() .'</p>';
     espresso_registration_footer();
 }