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

$lst = Listopia::getInstance();

$listID = $_POST['list'];
$listOrdering = $_POST['order'];

$result = array();

if (isset($listID) && isset($listOrdering) && $lst->listIDIsValid($listID))
{
  // build the new list HTML content
  $entries = $lst->getListEntries($listID, $listOrdering);
  $entryComments = $lst->getListEntryComments($listID);
  $minimumEntries = $lst->getListMinimumEntries($listID);
  $listData = $lst->getListData($listID);
  
  $result['content'] = $lst->generateListEntriesHTML($listID, $entries, $entryComments, $listData[0]);
  $result['entryCount'] = count($entries);
  $result['minimumEntries'] = $minimumEntries;
}
else
{
  $result['content'] = "Something has gone badly wrong";
}

echo json_encode($result);

require("common_end.php");

