<?php
class Registration extends Index {

  public function __construct() { parent::__construct(); }
  
  //---[CZ]: registrace
  public function register() {
  
    if (substr(md5($_POST["hash"]), 0, 5)==$_POST["check"]) {
  
    if (preg_match("/^[0-9a-zA-Z]{3,128}$/", $_POST["login"])) {
    
    if ($_POST["password1"]!="" AND $_POST["password1"]==$_POST["password2"]) {
    
    $check=$this->db->query("SELECT id FROM ".TABLE_USERS." WHERE login='".$this->db->escape($_POST["login"])."'");
    $check=$this->db->fetch_array($check);
    
    if ($check["id"]=="") {
    
    $sql=$this->db->query("INSERT INTO ".TABLE_USERS." (login, password, regdate, mail_messages) values ('".$this->db->escape($_POST["login"])."', '".SHA1($_POST["password1"])."', ".time().", 1)");
    
    $this->status_messages->print_success(LANG_ACTION_WAS_SUCCESSFULLY_COMPLETED);
    
    }  else { $this->status_messages->print_error(LANG_THIS_USER_ALREADY_EXISTS); }

    } else { $this->status_messages->print_error(LANG_YOU_HAVE_NOT_FILLED_SOME_ITEMS); }
    
    } else { $this->status_messages->print_error(LANG_SOME_ITEMS_HAVE_INCORRECT_FORMAT); }
    
    } else { $this->status_messages->print_error(LANG_YOU_HAVE_ENTERED_BAD_CONTROL_CODE); }
    
  }
  
  //---[CZ]: vypsání stránky
  public function get_page() {
  
    if (isset($_POST["submit"])) { $this->register(); }
  
    echo "\n\n<form action=\"".$this->urls->fction("registration")."\" method=\"post\">
    
    <div>
    
    <p><strong>".LANG_USERNAME.":</strong><br /><input type=\"text\" name=\"login\" style=\"width: 200px;\" /></p>
    
    <table>
    <tr>
    <td style=\"width: 50%;\"><strong>".LANG_PASSWORD.":</strong><br /><input type=\"password\" id=\"password1\" name=\"password1\" style=\"width: 200px;\" /></td>
    <td style=\"width: 50%;\"><strong>".LANG_PASSWORD_AGAIN.":</strong><br /><input type=\"password\" id=\"password2\" name=\"password2\" style=\"width: 200px;\" /></td>
    </tr>
    </table>";
    
    if (!isset($_SESSION["user_id"])) {
    echo "<p><strong>".LANG_RETYPE_THIS_TEXT."</strong>:</p>";
    $this->captcha->create(1);
    }
    
    echo "</div>
    
    <div>
    
    <p><input type=\"submit\" name=\"submit\" value=\"".LANG_REGISTER."\" /></p>
    
    </div>
    
    </form>";
    
  }

}
?>