<?php
class Comments extends Admin {

  public function __construct() {

    parent::__construct();

  }

  //---[CZ]: výstup
  public function output() {
  
    if ($_GET["function"]=="overview") { $where=" WHERE confirmed=0"; } else { $where=""; }
  
    $sql=$this->db->query("SELECT id, article, author, text, user, added, confirmed FROM kcms_comments$where ORDER by added DESC");
    while($data=$this->db->fetch_array($sql)) {
    
    $article=$this->db->query("SELECT quick, title, section FROM kcms_articles WHERE id=".$data["article"]);
    $article=$this->db->fetch_array($article);

    echo "<tr>
    <td><span class=\"small-text\">".date("d.m.Y [H:i]", $data["added"])." &bull; "; if ($data["user"]==1) { echo parent::author_link($data["author"]); } else { echo $this->db->unescape($data["author"]); } echo " &bull; <a href=\"".$this->urls->article($article["quick"])."\" target=\"_blank\">".$this->db->unescape($article["title"])."</a></span><br />".$this->db->unescape($data["text"])."</td>
    <td style=\"text-align: center;\"><input type=\"button\" class=\"redbutton\" value=\"".LANG_DELETE."\" onclick=\"if (!confirm('".LANG_ARE_YOU_SURE."')) return false; parent.location='./admin.php?function=".$_GET["function"]."&amp;action=delete&amp;id=".$data["id"]."';\" />";
    if ($_GET["function"]=="overview" AND $data["confirmed"]==0) { echo "<br /><input type=\"button\" class=\"greenbutton\" value=\"".LANG_CONFIRM."\" onclick=\"parent.location='./admin.php?action=confirm&amp;id=".$data["id"]."';\" />"; }
    echo "</td>
    </tr>\n";
    
    }
    
  }
  
  //---[CZ]: smazání
  public function delete() {
  
  $sql=$this->db->query("DELETE FROM kcms_comments WHERE id=".intval($_GET["id"]));
  
  $this->status_messages->print_success(LANG_ACTION_WAS_SUCCESSFULLY_COMPLETED);
  
  }
  
  //---[CZ]: schválení
  public function confirm() {
  
  $sql=$this->db->query("UPDATE kcms_comments SET confirmed=1 WHERE id=".intval($_GET["id"]));
  
  $this->status_messages->print_success(LANG_ACTION_WAS_SUCCESSFULLY_COMPLETED);
  
  }

}
?>