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

$lst = Listopia::getInstance();

$result = array();
        
if ($lst->isLoggedIn() && $lst->isAdminUser())
{
  $listID   = $_POST['id'];
  $listSort   = $_POST['sortorder'];

  // check our inputs
  if (!isset($listID) || !$lst->listIDIsValid($listID))
  {
    $result['result'] = "Missing or invalid list ID " . $listID;
  }
  else 
  {
      $data = array(
        'list_orderby' => $listSort
      );
      $okA = $lst->Database()->update('t_lists', $data, 't_lists.list_id = '.((int)$listID));
      
      if (isset($okA))
      {
        $result['success'] = true;
      }
        
      $result['result'] = $okA;    
  }
}
else
{
  $result['result'] = "Not logged in";
}

echo json_encode($result);

require("common_end.php");

