Файл: adultscript-2.0.3-pro/files/mobile/components/user_signup.php
Строк: 150
<?php
defined('_VALID') or die('Restricted Access!');
error_reporting(E_ALL);
ini_set('display_errors', 1);
class VComponent_mobile_user_signup extends VComponent_mobile_user
{
public function __construct()
{
parent::__construct();
}
public function render()
{
$errors = array();
$messages = array();
$warnings = array();
$filter = VF::factory('filter');
$action = (isset($_POST['action'])) ? $filter->get('action') : 'register';
if ($action == 'register') {
$register = array(
'username' => '',
'email' => ''
);
if (isset($_POST['action'])) {
$username = $filter->get('username');
$password = trim($_POST['password']);
$email = $filter->get('email');
if ($username == '') {
$errors[] = __('username-empty');
} elseif (!VValid::length($username, 1, 32)) {
$errors[] = __('username-length', array(32));
} elseif (!VValid::aldash($username)) {
$errors[] = __('username-invalid');
} else {
$this->db->query("SELECT user_id
FROM #__user
WHERE username = '".$this->db->escape($username)."'
LIMIT 1");
if ($this->db->affected_rows()) {
$errors[] = __('username-used');
} else {
$register['username'] = $username;
}
}
if ($email == '') {
$errors[] = __('email-empty');
} elseif (!VValid::email($email)) {
$errors[] = __('email-invalid');
} else {
$this->db->query("SELECT user_id
FROM #__user
WHERE email = '".$this->db->escape($email)."'
LIMIT 1");
if ($this->db->affected_rows()) {
$errors[] = __('email-used');
} else {
$register['email'] = $email;
}
}
if ($password == '') {
$errors[] = __('password-empty');
}
if (!$errors) {
$date = date('Y-m-d h:i:s');
$ip = VServer::ip(true);
$this->db->query("INSERT INTO #__user
SET group_id = ".VAuth::get_group_id('Registered').",
username = '".$this->db->escape($username)."',
email = '".$this->db->escape($email)."',
password = '".VHash::encrypt($password)."',
login_date = '".$date."',
join_date = '".$date."',
join_ip = ".$ip.",
verified = '1',
status = '1'");
if ($this->db->affected_rows()) {
$user_id = $this->db->get_last_insert_id('#__user');
$this->db->query("INSERT INTO #__user_activity SET user_id = ".$user_id);
$this->db->query("INSERT INTO #__user_notifications SET user_id = ".$user_id);
$this->db->query("INSERT INTO #__user_preferences SET user_id = ".$user_id);
$this->db->query("INSERT INTO #__user_profile SET user_id = ".$user_id);
if (VModule::enabled('premium') &&
VModule::enabled('payment') &&
$this->mcfg['premium'] == '1') {
$messages[] = __('free-payment');
$action = 'payment';
$this->tpl->user_id = $user_id;
$this->tpl->username = $username;
$this->tpl->password = $password;
$this->tpl->email = $email;
} else {
$_SESSION['message'] = __('free-success', array($username));
VF::redirect(MOBILE_URL.'/login/');
}
} else {
$errors[] = 'Failed to add user! Application error!';
}
}
}
$this->tpl->register = $register;
}
if ($action == 'payment') {
$pcfg = VF::cfg('module.payment');
$methods = array();
$this->db->query("SELECT method_id, slug, translation, position_mobile
FROM #__payment_methods
WHERE status = '1'
ORDER BY position_mobile ASC");
if ($this->db->affected_rows()) {
$methods = $this->db->fetch_rows();
}
$packages = array();
if ($pcfg['system'] == 'subscription') {
$this->db->query("SELECT package_id, method_id, name, description,
period, price, fields, checked, orig_id
FROM #__package
WHERE status = '1'
AND mobile = '1'
ORDER BY method_id, price ASC");
if ($this->db->affected_rows()) {
$packages = $this->db->fetch_rows();
}
}
if (isset($_POST['action']) && isset($_POST['user_id'])) {
$user_id = (int) trim($_POST['user_id']);
$username = $filter->get('username');
$password = $filter->get('password');
$email = $filter->get('email');
$slug = $filter->get('radio-method');
if ($pcfg['system'] == 'subscription') {
$package_id = (isset($_POST['radio-package-'.$slug]))
? (int) trim($_POST['radio-package-'.$slug])
: 0;
} else {
$credit = $filter->get('credit');
$credit = preg_replace('/[^-0-9.]+/', '', $credit);
$credit = floatval($credit);
}
if ($slug == '') {
$errors[] = __('payment-select');
} else {
$this->db->query("SELECT m.method_id, m.gateway_id, g.slug
FROM #__payment_methods AS m
INNER JOIN #__payment_gateways AS g ON (g.gateway_id = m.gateway_id)
WHERE m.slug = '".$this->db->escape($slug)."'
LIMIT 1");
if ($this->db->affected_rows()) {
$method = $this->db->fetch_assoc();
} else {
$errors[] = __('payment-invalid');
}
}
if ($pcfg['system'] == 'subscription') {
if ($package_id === 0) {
$errors[] = __('package-invalid');
} else {
$package = array();
foreach ($packages as $pkg) {
if ($pkg['package_id'] == $package_id) {
$package = $pkg;
break;
}
}
if (empty($package)) {
$errors[] = __('pacakge-invalid');
}
}
} else {
if ($credit === 0) {
$errors[] = __('credit-invalid');
}
}
if (!$errors) {
$package_id = (isset($package_id)) ? $package_id : 0;
$amount = (isset($credit)) ? $credit : $package['price'];
$this->db->query("INSERT INTO #__payment
SET package_id = ".$package_id.",
method_id = ".$method['method_id'].",
gateway_id = ".(int) $method['gateway_id'].",
orig_id = '".$this->db->escape($package['orig_id'])."',
user_id = ".$user_id.",
method = '".$pcfg['system']."',
amount = ".$amount.",
period = ".$package['period'].",
currency = 'USD',
ip = ".VServer::ip(true).",
add_date = '".date('Y-m-d h:i:s')."',
parent = 'register',
status = '0'");
if ($this->db->affected_rows()) {
$payment_id = $this->db->get_last_insert_id('#__payment');
$code = VHash::encrypt(VF::cfg_core_item('secret').'_'.$payment_id);
$this->db->query("UPDATE #__payment
SET code = '".$code."'
WHERE payment_id = ".$payment_id."
LIMIT 1");
$start_date = (isset($package_id) && $package_id !== 0) ? date('Y-m-d') : '0000-00-00';
$end_date = '0000-00-00';
if (isset($package_id) && $package_id !== 0) {
$end_date = date('Y-m-d', (time()+($package['period']*86400)));
}
$this->db->query("INSERT INTO #__user_premium
SET user_id = ".$user_id.",
credit = ".$amount.",
start_date = '".$start_date."',
end_date = '".$end_date."',
status = '0'");
// few fixes here: hide_credits not needed
$payment = VF::factory('payment', array('driver' => $method['slug']));
$fields = array(
'amount' => number_format((float) $amount, 2, '.', ''),
'period' => (isset($package_id) && $package_id !== 0) ? $package['period'] : 2,
'item_name' => 'Register on '.$this->tpl->cfg['site_name'].' ('.$username.')',
'item_number' => $payment_id,
'item_code' => $code,
'user_id' => $user_id,
'custom' => $user_id,
'username' => $username,
'password' => $password,
'email' => $email,
'hide_credits' => 'True',
'selected' => (isset($package_id) && $package_id !== 0) ? $package['orig_id'] : 0,
'success_url' => BASE_URL.'/dashboard/',
'failed_url' => BASE_URL.'/premium/failed/register/',
'cancel_url' => BASE_URL.'/premium/cancel/register/',
'validate_url' => BASE_URL.'/premium/ipn/'
);
if (isset($package_id) && $package_id !== 0) {
if (isset($package['fields']) && !empty($package['fields'])) {
$fields = explode(';', $package['fields']);
foreach ($fields as $field) {
$array = explode('=', $field);
if (isset($array['0']) && !empty($array['0']) &&
isset($array['1']) && !empty($array['1'])) {
$fields[$array['0']] = $array['1'];
}
}
}
}
$messages[] = __('payment-success');
$action = 'redirect';
$this->tpl->form = $payment->get_form($fields);
} else {
$errors[] = 'Failed to add package information! Application error!?';
}
}
}
$this->tpl->methods = $methods;
$this->tpl->packages = $packages;
}
$this->tpl->menu = 'community';
$this->tpl->title = __('register-title', array($this->mcfg['site_name']));
$this->tpl->meta_title = __('register-title', array($this->mcfg['site_name']));
$this->tpl->meta_desc = __('register-desc', array($this->mcfg['site_name']));
$this->tpl->meta_keys = $this->mcfg['site_name'];
$this->tpl->canonical = BASE_URL.'/user/signup/';
$this->tpl->errors = $errors;
$this->tpl->messages = $messages;
$this->tpl->warnings = $warnings;
$this->tpl->action = $action;
$this->tpl->load(array('header', 'user_signup', 'footer'));
$this->tpl->display();
}
}