<?php
/**
 * @package linea21.modules
 * @subpackage news
 * @author linea21 <info@linea21.com>
 * @version $id SVN
 * @access public
 * @license http://opensource.org/licenses/gpl-3.0.html
 */

//////////// Check Inclusion de pages ////////////
if (!function_exists('AuthenthificationProcess')) {
    include_once("../lib/lib_common.php");
    ReloadIndex('admin');
}
////////////

//////////// Check Droits utilisateur ////////////
if (!HaveRight('news')) ReloadIndex('admin');
////////////

if(!isset($_GET['statut']) || $_GET['statut']==-1) $statut=-1;
elseif($_GET['statut']!=-1) $statut=$_GET['statut'];


if(!isset($_GET['debut'])) $debut=0;
else $debut=$_GET['debut'];

$mask_statut_1='';
$mask_statut_2='';
$mask_statut_3='';
$mask_statut_4='';
if($statut=='public') $mask_statut_1='selected="selected"';
if($statut=='draft') $mask_statut_2='selected="selected"';
if($statut=='archives_p') $mask_statut_3='selected="selected"';
if($statut=='archives_a') $mask_statut_4='selected="selected"';

// Nombre d'enregistrement total dans la bdd
$result_nb_req=$sql_object->DBSelect($req_count_news);
$bdd_nb_news=$result_nb_req[0]['num_rows'];
$bdd_nb_news_display = $bdd_nb_news." ".$GLOBALS['lang']['news']['nb_total']."<br />\n";

if($statut!=-1) {
	$link_back="<div class=\"filter\"><a href=\"".$rub_link."&amp;todo=list\">".$GLOBALS['lang']['news']['all']."</a></div>";
	$req_count_news=SQL_getCountNewsList($statut);
	$result_nb_req=$sql_object->DBSelect($req_count_news);
	$count_request=$result_nb_req[0]['num_rows'];
	$req_list_news=SQL_getNewsList($debut, SELECT_LIMIT, $statut);
	$result_news_list=$sql_object->DBSelect($req_list_news);
} else {
	$link_back='';
	$count_request=$bdd_nb_news;
	$req_list_news=SQL_getNewsList($debut, SELECT_LIMIT, $statut);
	$result_news_list=$sql_object->DBSelect($req_list_news);
}

if($count_request<=1) $count_request_display = $GLOBALS['lang']['divers']['query_result']." : ".$count_request." ".$GLOBALS['lang']['divers']['record']."<br />\n";
else $count_request_display = $GLOBALS['lang']['divers']['query_result']." : ".$count_request." ".$GLOBALS['lang']['divers']['records']."<br />\n";

$link_sup=$rub_link."&amp;todo=sup&amp;id=";
$link_mod=$rub_link."&amp;todo=mod&amp;id=";
$link_det=$rub_link."&amp;todo=det&amp;id=";
$link_statut=$rub_link."&amp;todo=list&amp;statut=";
$link_self=$link_statut.$statut;


// Liste des statuts disponibles
$select_statut="<select name=\"statut_filter\" id=\"statut_filter\"  onchange=\"ChangeLocation(this)\">\n";
$select_statut.="<option value=\"-1\">".$GLOBALS['lang']['news']['statut_filter']."</option>\n";
$select_statut.="<option value=\"".$link_statut."public\"".$mask_statut_1.">".display_statut('P')."</option>\n";
$select_statut.="<option value=\"".$link_statut."draft\"".$mask_statut_2.">".display_statut('D')."</option>\n";
$select_statut.="<option value=\"".$link_statut."archives_p\"".$mask_statut_3.">".display_statut('PA')."</option>\n";
$select_statut.="<option value=\"".$link_statut."archives_a\"".$mask_statut_4.">".display_statut('AA')."</option>\n";
$select_statut.="</select>\n";
?>
<div id="chemin">
	<ul>
		<li>
			<a href="index.php"><? echo $GLOBALS['lang']['way']['home']; ?></a>
		</li>
		<li>
			<a href="<?php echo $rub_link; ?>"><? echo $GLOBALS['lang']['menu']['news']; ?></a>
		</li>
		<li>
			<span><? echo formatNavTitle($GLOBALS['lang']['news']['list']); ?></span>
		</li>
	</ul>
</div>
  <!--end barre haute -->
<?php
include_once("quickicons.php");
?>
<div class="contentcontainer">
<?php	include_once($dir."/menurub.php");	?>
<div id="content">
<?php
		echo $link_back;
?>
	<div class="filterselect">
		<?php
		echo $select_statut;
		?>
	</div>
	<p><?php
	echo $bdd_nb_news_display;
	echo $count_request_display;
	?>
	</p>
<?php
echo linkin_page($link_self, $count_request, $debut);

if($result_news_list!=0) {
echo "<table cellspacing=\"0\" cellpadding=\"3\">\n";
echo "<thead>\n";
	echo "<tr>\n"; 
	echo "<td>".$GLOBALS['lang']['news']['title']."</td>\n";
	echo "<td>".$GLOBALS['lang']['divers']['date_crea']."</td>\n";
	echo "<td>".cutText($GLOBALS['lang']['divers']['date_publi'], 13, 1, '')."</td>\n";
	echo "<td>&nbsp;<span class=\"semnone\">".$GLOBALS['lang']['divers']['actions']."</span></td>\n";
	echo "</tr>\n";
echo "</thead>\n";

echo "<tbody>\n";


for($i=0; $i<count($result_news_list); $i++) {
	$news_title=formatText(cutText($result_news_list[$i]['news_title'],53), '2HTML');
	$news_owner=$result_news_list[$i]['news_posted_by'];
	$news_statut=$result_news_list[$i]['news_statut'];
	$news_published_date = $news_statut=='D' ? $GLOBALS['lang']['statut']['draft'] : $result_news_list[$i]['news_published_date_display'];
	echo "<tr>\n";
	echo "<td><a href=\"".$link_det.$result_news_list[$i]['news_id']."\" title=\"".$GLOBALS['lang']['news']['det']."\">".$news_title."</a></td>\n";
	echo "<td>".$result_news_list[$i]['news_date_crea_display']."</td>\n";
	echo "<td>".$news_published_date."</td>\n";
	echo "<td style=\"width:50px\">\n";
	
	if (GetSessionElement('id') == $news_owner || IsSuperAdmin()) {
		echo "<div class=\"iconetab\">\n";
		echo "<a href=\"".$link_sup.$result_news_list[$i]['news_id']."\" class=\"ico_sup\" title=\"".$GLOBALS['lang']['news']['sup']."\"></a>\n";
		echo "<a href=\"".$link_mod.$result_news_list[$i]['news_id']."\" class=\"ico_mod\" title=\"".$GLOBALS['lang']['news']['mod']."\"></a>\n";
		echo "</div>\n";
	} else echo '';
	echo "</td>\n";
	echo "</tr>\n";
}

echo "</tbody>";
echo "</table>";
} else {
	echo "<div class=\"info\">".$GLOBALS['lang']['news']['noresult']."</div>";
}
echo linkin_page($link_self, $count_request, $debut);

?>
</div>
<?php include_once($dir."/help.php"); ?>
</div>
  
