<?php
require_once('includes/config.php');

//Titre de la page
$pagetitle = 'Liste des membres';

//Stats : bbclone
define("_BBC_PAGE_NAME", $pagetitle);
define("_BBCLONE_DIR", "bbclone/");
define("COUNTER", _BBCLONE_DIR."mark_page.php");
if (is_readable(COUNTER)) include_once(COUNTER);

include_once('includes/header.php');
?>

<body>

<div id="container">

   	<?php
	   include_once('includes/header-logo.php');
	   include_once('includes/nav.php');
	?>

    	<div id="body">
	<div id="content">

	<?php include_once('includes/ariane.php'); ?>

		
        <?php
        //Message de création de compte...
        if(isset($_GET['action']) && $_GET['action'] == 'activation'){
		echo '<div class="alert-msg rnd8 success">Votre compte est en cours de création.<br />Vous allez recevoir, par e-mail, un lien afin de l\'activer.</div>';
        }

	if(isset($_GET['action']) && $_GET['action'] == 'noexistmember'){
		echo '<div class="alert-msg rnd8 error">Erreur : ce membre n\'existe pas.</div>';
	}
        ?>

	<br />	
	<div style="text-align: center; border:1px ridge black;">
		<h3>Rechercher un membre :</h3>
		<form action="<?php echo SITEURL; ?>/recherche-membres.php" method="post" id="rechercher" name="rechercher">
			<input type="text" alt="" name="requete" class="s" placeholder="Rechercher un membre ...">
			<input type="submit" alt="" value="Rechercher" class="searchsubmit formbutton">
		</form>
		<br />
	</div>

	<br />
	<div style="text-align: center;"><span style="font-size: 14pt; font-weight: bold;">Liste des membres :</span></div>
	<br />	

        <table>
        <tr>
		<th style="width: 250px;"><a style="color: #fff; text-decoration: none;" href="membres.php?tri=username&ordre=desc">&#x2191;</a>Pseudo<a style="color: #fff; text-decoration: none;" href="membres.php?tri=username&ordre=asc">&#x2193;</a></th>
		<th><a style="color: #fff; text-decoration: none;" href="membres.php?tri=memberDate&ordre=desc">&#x2191;</a>Inscription le<a style="color: #fff; text-decoration: none;" href="membres.php?tri=memberDate&ordre=asc">&#x2193;</a></th>
                <th style="text-align: center;"><a style="color: #fff; text-decoration: none;" href="membres.php?tri=uploaded&ordre=desc">&#x2191;</a>Envoyé<a style="color: #fff; text-decoration: none;" href="membres.php?tri=uploaded&ordre=asc">&#x2193;</a></th>
                <th style="text-align: center;"><a style="color: #fff; text-decoration: none;" href="membres.php?tri=downloaded&ordre=desc">&#x2191;</a>Téléchargé<a style="color: #fff; text-decoration: none;" href="membres.php?tri=downloaded&ordre=asc">&#x2193;</a></th>
		<th style="text-align: center;">Ratio</th>
        </tr>

        <?php
                try {
			// On affiche 15 membres par page
			$pages = new Paginator('15','p');

			$stmt = $db->query('SELECT memberID FROM blog_members');
			$pages->set_total($stmt->rowCount());

			// On met en place le tri
			if(isset($_GET['tri'])) {
                                $tri = html($_GET['tri']);
                        }
                        else {
				$memberID_tri = 'memberID';
                                $tri = html($memberID_tri);
                        }

                        if(isset($_GET['ordre'])) {
                                $ordre = html($_GET['ordre']);
                        }
                        else {
                                $ordre_tri = 'DESC';
				$ordre = html($ordre_tri);
                        }

			// Protection du tri -------------------------
			if (!empty($_GET['tri']) && !in_array($_GET['tri'], array('memberID','username', 'memberDate', 'uploaded', 'downloaded'))) {
				header('Location: index.php');
				exit();
			}

			if (!empty($_GET['ordre']) && !in_array($_GET['ordre'], array('asc','desc','ASC','DESC'))) {
				header('Location: index.php');
				exit();
			}


			// --------------------------------------------

                        $stmt = $db->query('SELECT * FROM blog_members,xbt_users WHERE blog_members.memberID=xbt_users.uid AND blog_members.username != "visiteur" AND blog_members.active = "yes" ORDER BY '.$tri.' '.$ordre.' '.$pages->get_limit());
                        while($row = $stmt->fetch()){

				echo '<tr>';

				if (!empty($row['avatar'])) {
					echo '<td style="font-weight: bold; font-size: 14px;"><img src="'.SITEURL.'/images/avatars/'.html($row['avatar']).'" alt="'.html($row['username']).'" style="float: left; margin-right: 5px; width: 30px; height: 30px;" /><a href="admin/profil.php?membre='.html($row['username']).'">'.html($row['username']).'</a></td>';
				}
				else {
					echo '<td style="font-weight: bold; font-size: 14px;"><img src="'.SITEURL.'/images/avatars/avatar.png" alt="'.html($row['username']).'" style="float: left; margin-right: 5px; width: 30px; height: 30px;" /><a href="admin/profil.php?membre='.html($row['username']).'">'.html($row['username']).'</a></td>';
				}			

				sscanf($row['memberDate'], "%4s-%2s-%2s %2s:%2s:%2s", $annee, $mois, $jour, $heure, $minute, $seconde);
				echo '<td style="font-size: 12px;">'.$jour.'-'.$mois.'-'.$annee.' à '.$heure.':'.$minute.':'.$seconde.'</td>';
                                echo '<td style="text-align: center;">'.makesize($row['uploaded']).'</td>';
                                echo '<td style="text-align: center;">'.makesize($row['downloaded']).'</td>';

				if (intval($row["downloaded"])>0) {
					$ratio=number_format($row["uploaded"]/$row["downloaded"],2);
				}
				else {
					$ratio='&#8734;';
				}

				echo '<td style="text-align: center;">'.$ratio.'</td>';
                                echo '</tr>';

                        }


                } catch(PDOException $e) {
                    echo $e->getMessage();
                }
        ?>
        </table>

	<?php
	echo $pages->page_links('?tri='.$tri.'&ordre='.$ordre.'&');
	?>

</div>

	<?php
	include_once 'sidebar.php';
	?>
        
    	<div class="clear"></div>
    </div>
</div>

<div id="footer">
	<?php
	include_once 'includes/footer.php';
	?>
</div>

</body>
</html>