<?php
class Users extends Admin {

  public function __construct() { parent::__construct(); }

  //---[CZ]: změna práv
  public function change_rights() {
  
    $sql=$this->db->query("UPDATE ".TABLE_USERS." SET rights=".intval($_POST["rights"])." WHERE id=".intval($_GET["id"]));
    if ($sql) { parent::$this->status_messages->print_success(LANG_ACTION_WAS_SUCCESSFULLY_COMPLETED); } else { $this->status->print_error(LANG_AN_ERROR_OCCURED); }
    
  }

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

  //---[CZ]: vypsání
  public function output() {
  
    $sql=$this->db->query("SELECT id, login, rights, regdate, lastvisit FROM ".TABLE_USERS." ORDER by rights DESC");
    while ($data=$this->db->fetch_array($sql)) {
    
    echo "<form action=\"./admin.php?function=users&amp;action=change_rights&amp;id=".$data["id"]."\" method=\"post\">
    <tr>
    <td><a href=\"".parent::$this->urls->profile($data["login"])."\" target=\"_blank\">".$data["login"]."</a></td>
    <td style=\"text-align: center;\" class=\"small-text\">".date("d.m.Y, H:i", $data["regdate"])."</td>
    <td style=\"text-align: center;\" class=\"small-text\">";
    if ($data["lastvisit"]==0) { echo "-"; } else { echo (date("d.m.Y, H:i", $data["lastvisit"])); }
    echo "</td>
    <td style=\"text-align: center;\"><select name=\"rights\">";
    for ($i=0; $i<6; $i++) {
    echo "<option value=\"$i\"";
    if ($data["rights"]==$i) { echo " selected=\"selected\""; }
    echo ">$i</option>\n";
    }
    echo "</select></td>
    <td style=\"text-align: center;\"><input type=\"submit\" name=\"submit\" class=\"greenbutton\" value=\"".LANG_SAVE_CHANGES."\" /><input type=\"button\" class=\"redbutton\" class=\"trfbutton\" value=\"".LANG_DELETE."\" onclick=\"parent.location='./admin.php?function=users&amp;action=delete&amp;id=".$data["id"]."';\" /></td>
    </tr>
    </form>";
    
    }
    
  }

}
?>