<?php
/*
Template Name: My Reviews
*/

if ( is_user_logged_in() && 'POST' == $_SERVER['REQUEST_METHOD'] ) {
	set_query_var( 'delete_post', $_POST['user_review_id'] );
	wp_delete_post( get_query_var( 'delete_post' ), true );
}
	 
get_header(); global $gp;

gp_page_header( get_the_ID() );
			
?>

<div id="content-wrapper"<?php if ( $GLOBALS['gp_layout'] != 'gp-fullwidth' ) { ?> class="gp-container"<?php } ?>>

	<div id="content">

		<?php if ( is_user_logged_in() ) {
		
			gp_query_variables();

			$args = array(
				'post_status' => 'publish',
				'author' => $current_user->ID,
				'post_type' => 'gp_user_review',
				'paged' => $GLOBALS['gp_paged'],
				'posts_per_page' => $GLOBALS['gp_per_page'] ,
			);

			$gp_query = new wp_query( $args ); ?>
		
			<div class="blog-wrapper approved-reviews-wrapper <?php echo sanitize_html_class( $GLOBALS['gp_format'] ); ?> <?php echo sanitize_html_class( $GLOBALS['gp_size'] ); ?>"<?php echo gp_data_properties( 'approved-user-reviews' ); ?>>
		
				<div class="post-section-header">		
					<h3><?php _e( 'Approved Reviews', 'gp_lang' ); ?></h3>
					<span class="post-section-header-line"></span>
				</div>

				<?php if ( $gp_query->have_posts() ) : ?>
								
					<div class="inner-loop <?php echo sanitize_html_class( $gp['ajax'] ); ?>">
								
						<?php while ( $gp_query->have_posts() ) : $gp_query->the_post(); ?>
							   
						<?php get_template_part( 'review', 'loop' ); ?>
				
						<?php endwhile; ?>
			
					</div>

					<?php echo gp_pagination( $gp_query->max_num_pages ); ?>

				<?php else : ?>

					<strong class="no-items-found"><?php _e( 'No items found.', 'gp_lang' ); ?></strong>

				<?php endif; wp_reset_postdata(); ?>

			</div><!-- END BLOG WRAPPER -->
				
			<?php 
		
			$args = array(
				'post_status' => 'pending',
				'author' => $current_user->ID,
				'post_type' => 'gp_user_review',
				'paged' => $GLOBALS['gp_paged'],
				'posts_per_page' => $GLOBALS['gp_per_page'],
			);

			$gp_query = new wp_query( $args ); ?>
		
			<div class="blog-wrapper pending-reviews-wrapper <?php echo sanitize_html_class( $GLOBALS['gp_format'] ); ?> <?php echo sanitize_html_class( $GLOBALS['gp_size'] ); ?>"<?php echo gp_data_properties( 'pending-user-reviews' ); ?>>

				<div class="post-section-header">		
					<h3><?php _e( 'Pending Reviews', 'gp_lang' ); ?></h3>
					<span class="post-section-header-line"></span>
				</div>

				<?php if ( $gp_query->have_posts() ) : ?>
								
					<div class="inner-loop <?php echo sanitize_html_class( $gp['ajax'] ); ?>">
								
						<?php while ( $gp_query->have_posts() ) : $gp_query->the_post(); ?>
							   
						<?php get_template_part( 'review', 'loop' ); ?>
				
						<?php endwhile; ?>
			
					</div>

					<?php echo gp_pagination( $gp_query->max_num_pages ); ?>

				<?php else : ?>

					<strong class="no-items-found"><?php _e( 'No items found.', 'gp_lang' ); ?></strong>

				<?php endif; wp_reset_postdata(); ?>

			</div><!-- END BLOG WRAPPER -->
		
		<?php } else { ?>
		
			<strong class="no-items-found"><?php _e( 'You must be logged in to view your reviews.', 'gp_lang' ); ?></strong>
			
		<?php } ?>
								
	</div><!-- END CONTENT -->

	<?php get_sidebar(); ?>
	
</div><!-- END CONTENT WRAPPER -->

<?php get_footer(); ?>