<?php
/**
 * 
 * Template Name: View Annonces
 */

get_header(); ?>

<div class="row">
    
<div id="row-fix">

	
    
			<div class="entry index-edit">
			
            	<table>

			<tr>
				<th>Titre de l'annonce</th>
				<th class="edit-excerpt">Extrait</th>
				<th>Satut de l'annonce</th>
				<th>Actions</th>
			</tr>
            <?php if ( is_user_logged_in() ):

    				global $current_user;
    				get_currentuserinfo();
			?>

			<?php $query = new WP_Query(array('post_type' => 'post','cat'  => '9', 'posts_per_page' =>'-1', 'author' => $current_user->ID, 'post_status' => array('publish', 'pending', 'draft', 'private') ) ); ?>

			<?php if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?>

			<tr>
				<td width="20%"><a href="<?php the_permalink(); ?>"><?php echo get_the_title(); ?></a></td>
				<td class="edit-excerpt" width="45%" style=" text-align:left;"><?php the_excerpt(); ?></td>
				<td width="20%"><?php echo get_post_status( get_the_ID() ) ?></td>

				<?php $edit_post = add_query_arg('post', get_the_ID(), get_permalink(124 + $_POST['_wp_http_referer'])); ?>

				<td width="15%">
					<a href="<?php echo $edit_post; ?>">Editer</a>

					<?php if( !(get_post_status() == 'trash') ) : ?>

						<a onclick="return confirm('Etes-vous sûr de vouloir supprimer cette annonce: <?php echo get_the_title() ?>?')"href="<?php echo get_delete_post_link( get_the_ID() ); ?>">Supprimer</a>

					<?php endif; ?>
                    <a href="<?php echo site_url(); ?>/publier-une-annonce/" title="Ajouter une annonces">Ajouter</a>
				</td>
			</tr>
			
		<?php endwhile; endif; ?>

		</table>

			</div>
		
		<div class="clear"></div>
        
	
  	
            
            
     
		

	
<?php else :

    		echo "not logged in";
			endif;
			?>

</div>   
</div>
</div>
<?php get_footer(); ?>