<?php

include('includes/hlava.php');
title('Klub priateľov fotografie', '');

if ($link) {
  if ($db_selected) {
  
include('includes/vedla.php');
odkaz('');
include('includes/menu.php');
menu('clenovia','');
?>   
                  
          <div class="obsah">
          <h2>Prehľad <em>autorov</em></h2>
          <table class="clen">
          <tr>
            <th title="identifikačné číslo">id</th>
            <th>meno užívateľa</th>
            <th>počet fotografií</th>
            <th>počet bodov</th>
            <th>počet komentárov</th>
          </tr>
<?php

		if (!isset($_GET['ord']) || (int) $_GET['ord'] == 1) $zorad = 'priezvisko ASC';
		else {
      if ($_GET['ord'] == 0) $zorad = 'aid ASC';
      if ($_GET['ord'] == 1) $zorad = 'priezvisko ASC';
      if ($_GET['ord'] == 2) $zorad = 'fotky DESC';
      if ($_GET['ord'] == 3) $zorad = 'bbody DESC';
    }
    
    $sql = "SELECT A.meno, A.priezvisko, A.aid
            FROM kpf_author A
            WHERE A.aid!='1'
            ORDER BY $zorad;";
    $result = mysql_query($sql, $link);
      if ($result) {
	      $i = 0;
        while ($row = mysql_fetch_assoc($result)) {
          $i++;
          $zvysok = $i%2;
          if (($zvysok == 1)) echo '<tr class="light">';
          else echo '<tr class="dark">';
          echo '<td>'.$row['aid'].'</td><td><a href="author.php?id='.$row['aid'].'" class="author">'.$row['priezvisko'].' '.$row['meno'].'</a></td>';
          $sql2 = "SELECT count(P.id) AS fotky
                   FROM kpf_photos P
                   WHERE P.aid=".$row['aid'].";";
          $result2 = mysql_query($sql2, $link);
            if ($result2) {
              $row2 = mysql_fetch_assoc($result2);
              echo '<td>'.$row2['fotky'].'</td>';
            }
          $sql2 = "SELECT sum(H.body) AS bodky
                  FROM kpf_photos P, kpf_hodnot H
                  WHERE H.id=P.id AND P.aid='".$row['aid']."'";
          $result2 = mysql_query($sql2, $link);
            if ($result2) {
              $row2 = mysql_fetch_assoc($result2);
              if ($row2['bodky'] == '') $row2['bodky'] = '0'; 
              echo '<td>'.$row2['bodky'].'</td>';            
            }
          
          $sql2 = "SELECT count(H.id) AS komenty
                   FROM kpf_author A, kpf_hodnot H
                   WHERE H.aid='".$row['aid']."'
                   GROUP BY A.aid;";
          $result2 = mysql_query($sql2, $link);
            if ($result2) {
              $row2 = mysql_fetch_assoc($result2);
              if ($row2['komenty'] == '') $row2['komenty'] = '0';            
              echo '<td>'.$row2['komenty'].'</td></tr>';         
            }                                             
        }
      }            
    
?>
          </table>
<?php        
        		        		} // end vyber db
        		mysql_close($link);
        	} // end spojenie s db

include('includes/pata.php');
      ?>          
