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

$lst = Listopia::getInstance();

$result = array();

if ( !isset($_POST["blob"]) )
  die("missing credentials");


  $messageContent = base64_decode($_POST['blob']);

  $messageContent = mb_convert_encoding($messageContent, 'UTF-8', 'UTF-8');
  $messageContent = htmlentities($messageContent, ENT_QUOTES, 'UTF-8');

  $date = date("Y-m-d H:i:s", time());
  
  $data = array(
    'mess_from'         => 999,
    'mess_to'           => 101,
    'mess_from_status'  => 'read',
    'mess_to_status'    => 'unread',
    'mess_sent'         => $date,
    'mess_read'         => $date,
    'mess_content'      => htmlspecialchars($messageContent)
  );
  $insertResult = $lst->Database()->insert('messages', $data);
  
  if (isset($insertResult))
    $result['success'] = true;
    
  $result['result'] = "THAT PROBABLY WORKED. NOW WAIT.";



echo json_encode($result);

require("common_end.php");

