<?php
error_reporting(E_ALL | E_STRICT);
  ini_set("display_errors", 1);
  
  require("php/common_begin.php");

  $lst = Listopia::getInstance();
  // -------------------------------
  if (!$lst->isLoggedIn())
  {
    $lst->unloggedInPage();
    return;
  }
  // -------------------------------

  
  $lst->pageBegin(LS_GALLERY_DOCUMENT_TITLE, "bang on my pipes");
  
  $lst->contentsBeginSinglePage(LS_GALLERY_TITLE, LS_GALLERY_DESC);
   
  $query = $lst->Database()->select(array(
                          'fields'  => 'avatars.*, users.user_id, users.user_name',
                          'table'   => 'avatars',
                          'join'    => 'users on users.user_id = avatars.userid',
                          'order'   => 'rand()',
                          'limit'   => 10
                          ));
  if (!empty($query[0]))
  {
    print("<p class='smaller-centered'>A random selection. Reload to shuffle it up.</p><br/>");
    
    foreach ($query as &$avatar)
    {
      $profileLink = ProfileLink($avatar['users']['user_id'], '#PageContent');
      
      print("<div class='lst-pf-block' style='max-width:500px; padding: 8px; margin: 0px auto 10px auto;'><img class='ui-corner-all lst-avatar-img' alt='avatar' src='");
      print($avatar['avatars']['imagedata']);
      print("' />");
      
      $age = mt_rand(4,10);
      $deci = mt_rand(3,6);
      printf("<p style='text-align:center; font-size: 0.9em'> - <a %s>%s</a>, age %d %d/%dths</p>", $profileLink, $avatar['users']['user_name'], $age, $deci, $deci+1);
      
      print("</div>");
    }
  }

  $lst->contentsEnd();

  // default script loading
  $lst->pageEndScripts();

  $lst->pageEnd();

  require("php/common_end.php");
?>
