<?php
$current_user = wp_get_current_user();
if (user_can($current_user->ID, 'remove_users')) {
	// C'est un administrateur : on affiche les brouillons
	?>
	<div class="changelog">
		<div class="feature-section images-stagger-right">
			<?php
			$drafts_query = new WP_Query( array(
				'post_type' => 'any',
				'post_status' => array('draft', 'pending'),
				'posts_per_page' => -1,
				'orderby' => 'modified',
				'order' => 'DESC'
			) );
			$drafts =& $drafts_query->posts;
			if ( $drafts && is_array( $drafts ) ) {
				$list = array();
				foreach ( $drafts as $draft ) {
					$url = get_edit_post_link( $draft->ID );
					$title = _draft_or_post_title( $draft->ID );
					$last_id = get_post_meta( $draft->ID, '_edit_last', true);
					$last_user = get_userdata($last_id);
					$obj = get_post_type_object(get_post_type($draft->ID));
					$postType =  $obj->labels->singular_name;
					if(property_exists('data', 'display_name')) {
						$last_modified = '<i>' . esc_html($last_user->display_name) . '</i>';
					}else{
						$last_modified = '';
					}
					$item = '<tr><td><a href="' . $url . '" title="' . sprintf( __( 'Modifier ce contenu' ), esc_attr( $title ) ) . '">' . esc_html($title) . '</a></td><td>' . $postType . '</td><td>' . sprintf(__('Le %2$s à %3$s'), $last_modified, mysql2date(get_option('date_format'), $draft->post_modified), mysql2date(get_option('time_format'), $draft->post_modified)) . '</td><td>'.$last_modified.'</td></tr>';
					$list[] = $item;
				}
				?>
				<table class="widefat">
					<thead>
					<tr>
						<th>Titre / lien</th>
						<th>Type</th>
						<th>Dernière modification</th>
					</tr>
					</thead>
					<tbody>
					<?php echo join( "\n", $list ); ?>
					</tbody>
				</table>
				<?php
			} else {
				echo 'Il n\'y a pas de brouillons enregistrés actuellement.';
			}
			?>
		</div>
	</div>
<?php } else {  /* user = editeur, auteur, etc */ ?>

	<?php
	if(user_can($current_user->ID, 'edit_posts')){
		?>

		<div class="changelog">
		<div class="feature-section images-stagger-right">
			<?php
			$drafts_query = new WP_Query(array(
				'post_type' => 'any',
				'post_status' => array('draft', 'pending'),
				'posts_per_page' => -1,
				'orderby' => 'modified',
				'order' => 'DESC',
			));
			$drafts =& $drafts_query->posts;
			if ($drafts && is_array($drafts)) {
				$list = array();
				foreach ($drafts as $draft) {
					$url = get_edit_post_link($draft->ID);
					$title = _draft_or_post_title($draft->ID);
					$last_id = get_post_meta($draft->ID, '_edit_last', true);
					$last_user = get_userdata($last_id);
					$obj = get_post_type_object(get_post_type($draft->ID));
					$postType = $obj->labels->singular_name;
					$last_modified = '<i>' . esc_html($last_user->display_name) . '</i>';
					$item = '<tr><td>' . esc_html($title) . '</td><td>' . $postType . '</td><td>' . sprintf(__('Le %2$s à %3$s'), $last_modified, mysql2date(get_option('date_format'), $draft->post_modified), mysql2date(get_option('time_format'), $draft->post_modified)) . '</td></tr>';
					$list[] = $item;
				}
				?>
				<table class="widefat">
					<thead>
					<tr>
						<th>Titre / lien</th>
						<th>Type</th>
						<th>Dernière modification</th>
					</tr>
					</thead>
					<tbody>
					<?php echo join("\n", $list); ?>
					</tbody>
				</table>
				<?php
			} else {
				echo 'Il n\'y a pas de brouillons enregistrés actuellement.';
			}
			?>
		</div>
		<?php
	}else{
		?>
		Vous n'avez pas la possibilité de voir les contenus en attente de publication
		<?php
	}
	?>
	</div>
	<?php
}
?>