<?php 
session_start();
/*
 * Administation/adminUsers.php
 * 
 * Copyright 2009, 2018 Pedro Quaresma <pedro@mat.uc.pt>
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 */

require_once("../servidor.php");

$pTipoUtilizador = $_SESSION['tipoUtilizador'];
if ($pTipoUtilizador=="anonymous" || $pTipoUtilizador=="regular") { // separa por tipo de utilizador
  require($entradaFILE.'headerUsers.php');
  require($entradaFILE.'menuAdmins.php');
  echo "<meta http-equiv='refresh' content='0; url=".$entradaURL."users.php' />";
  exit;  // os anonimos não têem acesso a esta página
}
else {
  require($entradaFILE.'headerAdmins.php');
  require($entradaFILE.'menuAdmins.php');
}

// coloca o valor para a página de ajuda apropriada
$_SESSION['helpsection']='logs';

require_once($entradaFILE.'dbLogin.php');

?>


<center>
<h3 class="maketitle">Users listing</h3>
</center>


<?php

// cria uma pesquisa
$sql = "SELECT userId,username,type,name
          FROM users
      ORDER BY userId";
$resultado = mysqli_query($ligacao,$sql);


// O números de campos obtidos
$ncampos =mysqli_num_fields($resultado);
$nlinhas =mysqli_num_rows($resultado);

echo "<center>";
echo "<h4 class='maketitle'>$nlinhas Users</h4>";
echo "</center>";


print "<p>&nbsp;</p>";
print "<center>";
print "<table border=1>\n";
print "<tr>\n";
print "<th> User Id</th><th> Name</th><th>&nbsp;</th><th>&nbsp;</th>\n";
print "<th> &nbsp;</th><th>&nbsp;</th><th>&nbsp;</th>\n";
print "</tr>\n\n";

// Uma ideia é transformar isto num formulário em que o utilizador
// podia seleccionar os teoremas dos quais quereria ver os detalhes.

while ($linha = mysqli_fetch_assoc($resultado)){
  print "<tr>\n";
  $pUserId=trim($linha['userId']);
  $pName=trim($linha['name']);
  $pType=trim($linha['type']);
  $pUsername=trim($linha['username']);
  print " <td align=center>$pUserId</td>\n"; 
  print " <td>$pName</td>\n";
  print " <td>$pUsername</td>\n"; 
  print " <td>$pType</td>\n";
  print " <td>&nbsp;</td>\n";
  print " <td><a href='".$entradaURL."Administration/formUser.php?argumento=$pUserId'>See details</a></td>\n";
  print " <td><a href='".$entradaURL."Administration/transformUser.php?argumento=$pUserId'>Change type</a></td>\n";
  print"</tr>";
 }
print "</table>\n";
print "</center>";
print "<p>&nbsp;</p>";

?>


<?php
  require($entradaFILE.'footer.php');
?>
