<?php 
require("common_begin.php");
require_once("Markdown/markdown.php");

$newsID = $_GET['id'];
if (!isset($newsID))
  die("no news ID set");

$elementID = $_POST['id'];
$newContent = $_POST['value'];
if (!isset($elementID) || !isset($newContent))
  die("editable components not sent");

$lst = Listopia::getInstance();

if ($lst->isLoggedIn())
{
  if ($lst->isUserAbleToEditNewsPage())
  {
    // post the modification
    $data = array(
      'message'         => $newContent,
      'timestamp_utc'   => time()
    );
    $ok = $lst->Database()->update('news', $data, 'news.news_id = ' . ((int)$newsID));
    
    if ($ok !== false)
    {
      echo Markdown(stripslashes($newContent));
    }
    else
    {
      echo "[update failed]";
    }
  }
  else
  {
    echo "[not allowed]";
  }
}
else
{
  echo "[not logged in]";
}

require("common_end.php");

