<?php
class Ajax {

  private $db;

  public function __construct() {
  
  $this->db = new Db_layer();
  
  }
  
  //---[CZ]: vypsání stránky
  public function update_comment() {
  
  $sql=$this->db->query("SELECT id, text FROM kcms_comments WHERE id=".$_GET["id"]);
  $sql=$this->db->fetch_array($sql);
  
  $text=str_replace("<br />", "\r\n", $sql["text"]);
  
  echo "<textarea name=\"c".$_GET["id"]."\" id=\"c".$_GET["id"]."\" cols=\"\" rows=\"\" style=\"width: 515px; height: 80px;\">$text</textarea>
  
  <input type=\"button\" onclick=\"save_comment(".$sql["id"].", document.getElementById('c".$_GET["id"]."').value);\" value=\"Uložit\" />";
    
  }
  
  //---[CZ]: vypsání stránky
  public function save_comment() {
  
  $text=htmlspecialchars($_GET["text"], ENT_NOQUOTES);
  $text=str_replace("\r\n", "<br />", $text);
  
  echo $text;

  $sql=$this->db->query("UPDATE kcms_comments SET text='".$this->db->escape($text)."' WHERE id=".$_GET["id"]);
    
  }
  
  //---[CZ]: vypsání stránky
  public function delete_comment() {

  $sql=$this->db->query("DELETE FROM kcms_comments WHERE id=".$_GET["id"]);
    
  }

}
?>