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

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

//////////// Check Droits utilisateur ////////////
if (!$l21auth->isSuperAdmin()) ReloadIndex('admin');
////////////


if(!isset($_GET['groupe']) || $_GET['groupe']==-1) $groupe=-1;
elseif($_GET['groupe']!=-1) {
  $groupe=$_GET['groupe'];
  $alphabeta=-1;
}

if(!isset($_GET['alphabeta']) || $_GET['alphabeta']==-1) $alphabeta=-1;
elseif($_GET['alphabeta']!=-1) {
  $alphabeta=$_GET['alphabeta'];
  $groupe=-1;
}

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

if($groupe!=-1 || $alphabeta!=-1) {
  $link_back="<div class=\"filter\"><a href=\"".$rub_link."&amp;todo=list\">"._t('user','all')."</a></div>";
  if($groupe!=-1) {
    $requete_count=SQLCount_getlistuser('GROUP', $groupe);
    $req_user_list=SQL_getlistuser($debut, SELECT_LIMIT, 'GROUP', $groupe);
  }
  if($alphabeta!=-1) {
    $requete_count=SQLCount_getlistuser('ALPHA', $alphabeta);
    $req_user_list=SQL_getlistuser($debut, SELECT_LIMIT, 'ALPHA', $alphabeta);
  }
}
else {
  $link_back='';
  // Liste des utilisateurs par défaut
  $requete_count=SQLCount_getlistuser();
  $req_user_list=SQL_getlistuser($debut);
}
$result_user_list=$sql_object->DBSelect($req_user_list);

$result_nb_req=$sql_object->DBSelect($requete_count);
$count_request=$result_nb_req[0]['num_rows'];



$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_self=$rub_link."&amp;todo=list&amp;groupe=".$groupe."&amp;alphabeta=".$alphabeta;
$link_list_group=$rub_link."&amp;todo=list&amp;groupe=";
$link_list_alphabetical=$rub_link."&amp;todo=list&amp;alphabeta=";


// Liste des groupes d'utilisateurs
$result_group=$sql_object->DBSelect($req_list_group);
$select_group="<select name=\"group_filter\" id=\"group_filter\"  onchange=\"ChangeLocation(this)\">\n";
$select_group.="<option value=\"-1\">"._t('user','selectgroup')."</option>\n";
for($i=0; $i<count($result_group); $i++)  {
  if($groupe==$result_group[$i]['catus_id']) $mask=" selected=\"selected\""; else $mask='';
  $select_group.="\t<option value=\"".$link_list_group.$result_group[$i]['catus_id']."\"".$mask.">".formatText($result_group[$i]['catus_name'])."</option>\n";
}
$select_group.="</select>\n";

// Liste alphabetique
$result_alphabetical=$sql_object->DBSelect($req_alphabetical);
$select_alphabetical="<select name=\"alhpabetical_filter\" id=\"alhpabetical_filter\" onchange=\"ChangeLocation(this)\">\n";
$select_alphabetical.="<option value=\"-1\">"._t('user','alphabetical')."</option>\n";
for($i=0; $i<count($result_alphabetical); $i++)  {
  if($alphabeta==$result_alphabetical[$i]['first_letter']) $mask=" selected=\"selected\""; else $mask='';
  $select_alphabetical.="\t<option value=\"".$link_list_alphabetical.$result_alphabetical[$i]['first_letter']."\"".$mask.">".formatText($result_alphabetical[$i]['first_letter'])."</option>\n";
}
$select_alphabetical.="</select>\n";

//nombre total d'utilisateurs
$result_group=$sql_object->DBSelect($req_nb_inscrit);
$nb_inscrits=$result_group[0]['nb_inscrit'];
$nb_inscrits_display = $nb_inscrits." "._t('user','nb_total')."<br />\n";
if($count_request<=1) $count_request_display = _t('divers','query_result')." : ".$count_request." "._t('divers','record')."<br />\n";
else $count_request_display = _t('divers','query_result')." : ".$count_request." "._t('divers','records')."<br />\n";
?>
<div id="chemin">
<ul>
	<li><a href="index.php" class="chemin_home"><?php echo _t('way','home'); ?></a></li>
	<li><a href="<?php echo $rub_link; ?>" id="chemin_<?php echo $rub; ?>" class="chemin_rub"><?php echo _t('menu','user'); ?></a></li>
	<li><span><?php echo formatNavTitle(_t('user','list')); ?></span></li>
</ul>
</div>
<!--end barre haute -->
<?php
include_once(THEME_ADMIN_PATH."quickicons.php");
?>
<div class="contentcontainer"><?php	include_once(override($dir.'/menurub.php', THEME_ADMIN_PATH));	?>
<div id="content"><?php
echo $link_back;
?>
<div class="filterselect"><?php
echo $select_group;
echo $select_alphabetical;

?></div>
<p><?php
echo $nb_inscrits_display;
echo $count_request_display;
?></p>
<?php
echo linkin_page($link_self, $count_request, $debut);

if($result_user_list!=0) {
  echo "<table cellspacing=\"0\" cellpadding=\"3\">\n";
  echo "<thead>\n";
  echo "<tr>\n";
  echo "<td>".mb_ucfirst(_t('user','login'))."</td>\n";
  echo "<td>".mb_ucfirst(_t('user','first_name')). ' - '.ucfirst(_t('user','last_name'))."</td>\n";
  echo "<td>".mb_ucfirst(_t('user','groupe'))."</td>\n";
  echo "<td>".mb_ucfirst(_t('user','date_record'))."</td>\n";
  echo "<td>&nbsp;<span class=\"semnone\">".mb_ucfirst(_t('user','actions'))."</span></td>\n";
  echo "</tr>\n";
  echo "</thead>\n";

  echo "<tbody>\n";
  for($i=0; $i<count($result_user_list); $i++) {
    echo "<tr>\n";
    echo "<td><a href=\"".$link_det.$result_user_list[$i]['user_id']."\" title=\"".formatText(_t('user','det'))."\">".formatText($result_user_list[$i]['user_login'])."</a></td>\n";
    echo "<td>".formatText($result_user_list[$i]['profile_firstname']. ' '.$result_user_list[$i]['profile_lastname'])."</td>\n";
    echo "<td>".formatText($result_user_list[$i]['catus_name'])."</td>\n";
    echo "<td>".$result_user_list[$i]['user_date_crea_display']."</td>\n";
    echo "<td>\n";
    echo "<div class=\"iconetab\">";
    echo "\t<a href=\"".$link_sup.$result_user_list[$i]['user_id']."\" class=\"ico_sup\" title=\""._t('user','sup')."\"></a>\n";
    echo "\t<a href=\"".$link_mod.$result_user_list[$i]['user_id']."\" class=\"ico_mod\" title=\""._t('user','mod')."\"></a>\n";
    echo "</div>";
    echo "</td>\n";
    echo "</tr>\n";
  }
  echo "</tbody>";
  echo "</table>";
} else {
  echo "<div class=\"info\">"._t('user','noresult')."</div>";
}

echo linkin_page($link_self, $count_request, $debut);
?></div>
<?php include_once(override($dir.'/help.php', THEME_ADMIN_PATH)); ?>
</div>