<?php
/**
 * This file implements the post browsing
 *
 * This file is part of the b2evolution/evocms project - {@link http://b2evolution.net/}.
 * See also {@link http://sourceforge.net/projects/evocms/}.
 *
 * @copyright (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/}.
 * Parts of this file are copyright (c)2005 by Daniel HAHLER - {@link http://thequod.de/contact}.
 *
 * @license http://b2evolution.net/about/license.html GNU General Public License (GPL)
 *
 * @package admin
 *
 * @deprecated by postlist2
 *
 * {@internal Below is a list of authors who have contributed to design/coding of this file: }}
 * @author fplanque: Francois PLANQUE.
 *
 * @version $Id: _browse_posts_list.inc.php,v 1.12.2.2.2.2 2007/05/07 17:19:06 fplanque Exp $
 */
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );


/**
 * Includes:
 */
require_once $model_path.'items/_itemlist.class.php';

/**
 * @var Blog
 */
global $Blog;

global $dispatcher, $blog, $posts, $posts_per_page, $poststart, $postend, $c, $show_statuses, $ReqURI;
global $add_item_url, $edit_item_url, $delete_item_url;
global $comment_allowed_tags, $comments_use_autobr;

echo '<div class="NavBar">';

	/*
	 * @movedTo _b2browse.php
	 */

	// Display title depending on selection params:
	request_title( '<h2>', '</h2>', '<br />', 'htmlbody', true, false /* does not handle context */ );

	if( !$posts )
	{
		if( $posts_per_page )
		{
			$posts = $posts_per_page;
		}
		else
		{
			$posts = 10;
			$posts_per_page = $posts;
		}
	}

	if( !$poststart )
	{
		$poststart = 1;
	}

	if( !$postend )
	{
		$postend = $poststart + $posts - 1;
	}

	$nextXstart = $postend + 1;
	$nextXend = $postend + $posts;

	$previousXstart = ($poststart - $posts);
	$previousXend = $poststart - 1;
	if( $previousXstart < 1 )
	{
		$previousXstart = 1;
	}

	require dirname(__FILE__). '/_edit_navbar.php';

echo '</div>';

/*
 * Display posts:
 */
echo '<table class="grouped">';
echo "<tr>\n";
echo '<th>'.T_('Issue date')."</th>\n";
echo '<th>'.T_('Author')."</th>\n";
echo '<th colspan="2">'.T_('Visibility')."</th>\n";
echo '<th>'.T_('Title')."</th>\n";
if( $Blog->ID == 1 )
{ // "All blogs": display name of blog
	echo '<th>'.T_('Blog')."</th>\n";
}
echo '<th>'.T_('Actions')."</th>\n";
echo "</tr>\n";

$line_count = 0;
while( $Item = $MainList->get_item() )
{
	echo '<tr lang="';
	$Item->lang();
	echo '"';
	if( $line_count % 2 )
	{
		echo ' class="odd"';
	}
	echo '>';
	// We don't switch locales in the backoffice, since we use the user pref anyway

	echo '<td class="nowrap">';
	$Item->permanent_link( get_icon('permalink') );
	echo ' ';
	echo '<span class="date">';
	$Item->issue_date();
	echo "</span></td>\n";

	echo '<td>';
	$Item->get_creator_User();
	$Item->creator_User->preferred_name();
	echo "</td>\n";

	echo '<td class="shrinkwrap">';
	// Display publish NOW button if current user has the rights:
	$Item->publish_link( ' ', ' ', get_icon( 'publish' ), '#', '');

	// Display deprecate if current user has the rights:
	$Item->deprecate_link( ' ', ' ', get_icon( 'deprecate' ), '#', '');
	echo "</td>\n";

	echo '<td>';
	$Item->status();
	echo "</td>\n";


	echo '<td>';
	locale_flag( $Item->locale, 'w16px', 'flag', '' );

	if( $Blog->allowcomments != 'never' )
	{ // TODO: should use $Item->get_Blog() for $Blog == 1 (see also <th> for this).
		$nb_comments = generic_ctp_number($Item->ID, 'feedback');
		echo ' <a href="?ctrl=browse&amp;tab=posts&amp;blog='.$blog.'&amp;p='.$Item->ID.'&amp;c=1&amp;tb=1&amp;pb=1"
						title="'.sprintf( T_('%d feedbacks'), $nb_comments ).'" class="">';
		if( $nb_comments )
		{
			echo get_icon( 'comments' );
		}
		else
		{
			echo get_icon( 'nocomment' );
		}
		echo '</a> ';
	}

	echo '<a href="?ctrl=browse&amp;tab=posts&amp;blog='.$blog.'&amp;p='.$Item->ID.'&amp;c=1&amp;tb=1&amp;pb=1" class="">';
	$Item->title( '', '', false );
	echo '</a>';

	$Item->extra_status( ' - '.T_('Extra').':' );
	$Item->assigned_to( ' '.get_icon( 'assign', 'imgtag', array('title'=>T_('Assigned to')) ) );

	echo "</td>\n";


	if( $Blog->ID == 1 )
	{ // "All blogs": display name of blog, linked to browse this blog.
		echo '<td>';
		$Item_Blog = & $Item->get_Blog();

		echo '<a href="'.regenerate_url( 'blog', 'blog='.$Item_Blog->ID )
			.'" title="'.$Item_Blog->dget( 'name', 'htmlattr' )
			.'">'.$Item_Blog->dget( 'shortname', 'htmlattr' ).'</a>';
		echo "</td>\n";
	}

	// Actions:
	echo '<td class="shrinkwrap">';
	// Display edit button if current user has the rights:
	$Item->edit_link( ' ', ' ', get_icon( 'edit' ), '#', '', $edit_item_url );

	// Display delete button if current user has the rights:
	$Item->delete_link( ' ', ' ', get_icon( 'delete' ), '#', '', false, $delete_item_url );

	echo "</td>\n";

	echo '</tr>';
	$line_count++;
}
echo '</table>';


if( $MainList->get_total_num_posts() )
{ // don't display navbar twice if we have no post
	echo '<div class="NavBar">';
	require dirname(__FILE__). '/_edit_navbar.php';
	echo '</div>';
}
?>

<p class="center">
	<?php
	echo action_icon( T_('New post...'), 'new', $add_item_url, T_('New post...'), 3, 4 );
	?>
</p>


<?php

?>
