<?php
  require("php/common_begin.php");

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

  
  $lst->pageBegin("Listopia - Everything", "get your bits out");
  
  $sidebar = array(
    SideBarItem::BasicListNavigator,
    SideBarItem::Profile);
 
  $lst->contentsBeginWithSidebar($sidebar, "Everything", "It goes on forever, and... oh my god, it's full of shit.");
  
  $query = $lst->Database()->select(array(
                    'fields'    => 't_lists.list_id, t_lists.list_headline',
                    'condition' => DBQ_CONDITION_PUBLIC_LIST,
                    'table'     => 't_lists',
                    'order'     => 'list_headline'
                    ));

  $listDict = array();
  foreach ($query as &$theList)
  {
    $listName = htmlspecialchars_decode(stripslashes($theList['t_lists']['list_headline']));
    $listSortCode = strtoupper($listName[0]);

    
    if ($listDict[$listSortCode] == null)
      $listDict[$listSortCode] = array();
      
    array_push($listDict[$listSortCode], $theList['t_lists']);
  }
  
  ksort($listDict);

  foreach($listDict as $k => $v) 
  {
    echo "<div class='lst-pf-block'>";
    echo "<p id='pf-title' class='ui-corner-br'>" . count($v) . " list(s)</p>";
    echo "<h1 style='padding-left:20px'>" . $k . "</h1>";
    
    foreach($v as $theList) 
    {
      printf("<p style='text-align:left;padding-left:30px'><a %s>%s</a></p>", 
        ListLink($theList['list_id'], "#PageContent"), 
        stripslashes($theList['list_headline']));    
    }
    
    echo "</div>";
  }
?>



<?php
  $lst->contentsEnd();

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

<!-- Local JS -->
<script type="text/javascript"">
</script>

<?php
  $lst->pageEnd();

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