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

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


  $lst->pageBegin(LS_OVERVIEW_DOCUMENT_TITLE, "the SQL training course");
  
  $sidebar = array(
    SideBarItem::AdvancedListNavigator,
    SideBarItem::Profile);
 
  $lst->contentsBeginWithSidebar($sidebar, LS_OVERVIEW_TITLE, LS_OVERVIEW_DESC);

  $mode = $_GET['mode'];
  if (!isset($mode))
    $mode = 'newest';
  
  $searchArray = $lst->GetGenericSearches();
  $searches = $searchArray[$mode];
  
  if (!isset($searches))
  {
    $lst->UI_Misc()->AddCenteredMessageBlock(LS_OVERVIEW_UNKNOWN_SEARCH);  
  }
  else
  {
    // ---------------------------------------------------------------------------------------------
    $lst->UI_Misc()->openGenericBlock($searches[0]);
    {
      $query = $searches[2]($lst->Database(), 100);      
      if (!empty($query[0]))
      {
        $firstEntry = null;
        
        foreach ($query as &$listItem)
        {
          $factoid = (isset($listItem['t_lists']['factoid'])) ? $listItem['t_lists']['factoid'] : $listItem[0]['factoid'];
          
          if ($firstEntry != null)
            print("<div style='border-top:1px dashed #ddd';><br>");
          
          $headline = StringWordBreak(stripslashes($listItem['t_lists']['list_headline']), 25);
          $desc = stripslashes($listItem['t_lists']['list_standfirst']);
          
          $suffix = "";
          if ($listItem['t_lists']['list_type'] == "image")
            $suffix = $lst->getImageListAdornmentHTML();
        
          printf("<div class='lst-searchresult'>");
          printf("<p class='ui-corner-all' id='factoid'>%s</p>", $factoid); 

          printf("<p style='margin:0px;'><a %s>%s</a>%s</p>", ListLink($listItem['t_lists']['list_id']), $headline, $suffix);
          printf("<p style='font-size:0.8em;'>%s</p>", $desc);

          printf("</div>");
          
          if ($firstEntry != null)
            print("</div>");
          $firstEntry = $listItem;
        }      
      }      
    }
    $lst->UI_Misc()->closeGenericBlock();    
  }
  
  
  $lst->contentsEnd();

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

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

<?php
  $lst->pageEnd();

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