<?php
class Banns {

  private $db;
  private $status;

  public function __construct() {
    $this->db = new Db_layer();
    $this->status = new Status_messages();
  }

  //---[CZ]: přidání
  public function add() {
    $sql=$this->db->query("INSERT INTO kboard_banns (ip) values ('".$this->db->escape($_POST["ip"])."')");
    if ($sql) { $this->status->print_success(LANG_ACTION_WAS_SUCCESSFULLY_COMPLETED); } else { $this->status->print_error(LANG_AN_ERROR_OCCURED); }
  }

  //---[CZ]: smazání
  public function remove() {
    $sql=$this->db->query("DELETE FROM kboard_banns WHERE id=".intval($_GET["id"]));
    if ($sql) { $this->status->print_success(LANG_ACTION_WAS_SUCCESSFULLY_COMPLETED); } else { $this->status->print_error(LANG_AN_ERROR_OCCURED); }
  }

  //---[CZ]: vypsání
  public function print_data() {
    $sql=$this->db->query("SELECT id, ip FROM kboard_banns ORDER by id DESC");
    while (list($id, $ip)=$this->db->fetch_row($sql)) {
    echo "<tr>
    <td>$ip</td>
    <td style=\"text-align: center;\"><input type=\"button\" value=\"".LANG_DELETE."\" onclick=\"if (!confirm('".LANG_ARE_YOU_SURE."')) return false; parent.location='./admin.php?f=banns&amp;action=remove_ban&amp;id=$id';\" /></td>
    </tr>\n";
    }
  }

}
?>