<?php
/**
 * Template Name: User Donations Page
 *
 * @package WordPress
 * @subpackage Charity
 * @since Charity 1.0
 */
?>
<?php
	if ( !is_user_logged_in() ) {
		$wplook_login_url = ot_get_option('wpl_login_link' ) ? get_permalink( ot_get_option('wpl_login_link' ) ) : home_url();
		return wp_redirect( $wplook_login_url  ); exit;
	}
	$wplook_page_header = (isset($wplook_page_meta['wpl_page_header'][0]) && $wplook_page_meta['wpl_page_header'][0] != '') ? $wplook_page_meta['wpl_page_header'][0] : false;
 ?>
<?php get_header(); ?>

	<div class="main">
		<div class="main-head">
			<div class="main-head-image fullscreener">
				<?php
					if ( $wplook_page_header ) {
						echo '<img class="hide" src="'.esc_url( $wplook_page_header ).'">';
					}?>
			</div><!-- /.main-head-image fullscreener -->

			<div class="main-head-content">
				<div class="grid-container">
					<div class="grid-x grid-margin-x">
						<div class="cell small-12">
							<h1 class="main-title main-title-alt"><?php the_title(); ?></h1><!-- /.main-title main-title-alt -->
							<?php if (ot_get_option('wpl_breadcrumbs_status') == 'on') : ?>
								<ul class="breadcrumbs">
									<?php wplook_breadcrumbs(); ?>
								</ul><!-- /.breadcrumbs -->
							<?php endif; ?>
						</div><!-- /.cell small-12 -->
					</div><!-- /.grid-x grid-margin-x -->
				</div><!-- /.grid-container -->
			</div><!-- /.main-head-content -->
		</div><!-- /.main-head -->
		<div class="main-body">
			<div class="grid-container">
				<div class="grid-x grid-margin-x">
					<div class="cell small-12 large-12">
						<div class="content">
							<?php do_action( 'wplook_user_urls' ); ?>
							<article id="post-<?php the_ID(); ?>" <?php post_class('post post-single post-event'); ?>>
							<?php
								$args = array(
									'post_type' => 'post_pledges',
									'post_status' => 'publish',
									'posts_per_page' => ot_get_option('wpl_docs_per_page'),
									'paged'=> $paged,
									'author' => get_current_user_id(),
								);

								$wp_query = null;
								$wp_query = new WP_Query( $args );
								//var_dump($wp_query );

								if ( $wp_query->post_count > 0 ) { ?>
									<table style="width: 100%;">
										<thead>
											<tr>
												<th><?php _e('Transaction ID', 'charity-wpl'); ?></th>
												<th><?php _e('Cause Name', 'charity-wpl'); ?></th>
												<!-- <th><?php _e('Date', 'charity-wpl'); ?></th> -->
												<th><?php _e('Amount', 'charity-wpl'); ?></th>
												<th><?php _e('Source', 'charity-wpl'); ?></th>
												<th><?php _e('Status', 'charity-wpl'); ?></th>
											</tr>
										</thead>
										<tbody>
											<?php if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post();
												$wplook_pid = $post->ID;
												$wplook_pledges_meta = get_post_meta($wplook_pid);
												$wplook_pledge_cause_id 	=  isset($wplook_pledges_meta['wpl_pledge_cause'][0]) ? $wplook_pledges_meta['wpl_pledge_cause'][0] : false;
												$wplook_pledge_payment_Status 	=  isset($wplook_pledges_meta['wpl_pledge_payment_Status'][0]) ? $wplook_pledges_meta['wpl_pledge_payment_Status'][0] : false;
												$wplook_pledge_payment_source 	=  isset($wplook_pledges_meta['wpl_pledge_payment_source'][0]) ? $wplook_pledges_meta['wpl_pledge_payment_source'][0] : false;
												$wplook_pledge_donation_amount 	=  isset($wplook_pledges_meta['wpl_pledge_donation_amount'][0]) ? $wplook_pledges_meta['wpl_pledge_donation_amount'][0] : false;
												if ($wplook_pledge_payment_source == 'bank_transfer') {
													$wplook_pledge_payment_source = __('Bank Transfer', 'charity-wpl');
												} elseif ($wplook_pledge_payment_source == 'check_cash') {
													$wplook_pledge_payment_source = __('Check or Cash', 'charity-wpl');
												}
										?>
											<tr>
												<td><?php the_title(); ?></td>
												<td>
													<?php echo '<a target="_blank" href="'. esc_url( get_permalink($wplook_pledge_cause_id) ).'">'.get_the_title($wplook_pledge_cause_id).'</a><br>'; ?>
													<i class="subheader"><?php printf( _x( '%1$s at %2$s', '[date] at [time]', 'charity-wpl' ), get_the_date(), get_the_time() ); ?></i>
												</td>
												<!-- <td></td> -->
												<td><?php echo '<strong>' .esc_html( $wplook_pledge_donation_amount ).'</strong> '; echo ot_get_option('wpl_curency_code') ?></td>
												<td><?php echo esc_html( ucfirst($wplook_pledge_payment_source) ); ?></td>
												<td><?php echo esc_html( ucfirst($wplook_pledge_payment_Status) ); ?></td>
											</tr>

											<?php endwhile; ?>
											<?php endif; ?>
											<?php wp_reset_postdata(); ?>
										</tbody>
									</table>
								<?php wplook_pagination() ?>
								<?php } else {
									_e('No transaction!' , 'charity-wpl');
								}
							?>
							</article>
						</div><!-- /.content -->
					</div><!-- /.cell large-12 -->
				</div><!-- /.grid-x grid-margin-x -->
			</div><!-- /.grid-container -->
		</div><!-- /.main-body -->
	</div><!-- /.main -->
<?php get_footer(); ?>
