<?php
if(!defined("MCR")){ exit("Hacking Attempt!"); }
class module{
private $core, $db, $config, $lng, $user;
public $cfg = array();
public function __construct($core){
$this->core = $core;
$this->db = $core->db;
$this->user = $core->user;
$this->config = $core->config;
$this->lng = $core->lng_m;
$bc = array(
$this->lng['mod_name'] => BASE_URL."?mode=register"
);
$this->core->bc = $this->core->gen_bc($bc);
}
private function regmain(){
if(!$this->core->is_access('sys_register')){ $this->core->notify($this->core->lng['e_msg'], $this->lng['e_perm'], 1, "?mode=403"); }
if($this->user->is_auth){ $this->core->notify($this->core->lng['e_msg'], $this->lng['e_already'], 2, '?mode=403'); }
return $this->core->sp(MCR_THEME_PATH."modules/register/main.html");
}
private function accept(){
if(!isset($_GET['key'])){ $this->core->notify($this->core->lng['e_msg'], $this->core->lng['e_403'], 2, '?mode=403'); }
$key_string = $_GET['key'];
$array = explode("_", $key_string);
if(count($array)!==2){ $this->core->notify($this->core->lng['e_msg'], $this->core->lng['e_403'], 2, '?mode=403'); }
$uid = intval($array[0]);
$key = $array[1];
$query = $this->db->query("SELECT `salt`, `data` FROM `mcr_users` WHERE id='$uid' AND gid='1'");
if(!$query || $this->db->num_rows($query)<=0){ $this->core->notify($this->core->lng['e_attention'], $this->core->lng['e_sql_critical'], 1, "?mode=register"); }
$ar = $this->db->fetch_assoc($query);
if($key!==md5($ar['salt'])){ $this->core->notify($this->core->lng['e_msg'], $this->core->lng['e_403'], 2, '?mode=403'); }
$data = json_decode($ar['data']);
$newdata = array(
"time_create" => $data->time_create,
"time_last" => time(),
"firstname" => $data->firstname,
"lastname" => $data->lastname,
"gender" => $data->gender,
"birthday" => $data->birthday
);
$newdata = $this->db->safesql(json_encode($newdata));
$update = $this->db->query("UPDATE `mcr_users`
SET gid='2', ip_last='{$this->user->ip}', `data`='$newdata'
WHERE id='$uid' AND gid='1'");
if(!$update){ $this->core->notify($this->core->lng['e_attention'], $this->core->lng['e_sql_critical'], 1, "?mode=register"); }
// Лог действия
$this->db->actlog("Подтверждение регистрации", $uid);
$this->core->notify($this->core->lng['e_success'], $this->lng['e_accept'], 3);
}
public function content(){
$this->core->header = $this->core->sp(MCR_THEME_MOD."register/header.html");
$op = (isset($_GET['op'])) ? $_GET['op'] : false;
switch($op){
case 'accept': $content = $this->accept(); break;
default: $content = $this->regmain(); break;
}
return $content;
}
}
?>