<?php

if (isset($_POST['full_name']) && !empty($_POST['full_name']) && isset($_POST['username']) && !empty($_POST['username']) && isset($_POST['email']) && !empty($_POST['email']) && isset($_POST['password'])) {
    $_POST['code'] = sha1($_SERVER['REMOTE_ADDR'] . microtime() . mt_rand(1, 100000)) . _Function::randomString(40, TRUE, TRUE, TRUE);
    $_POST['email'] = trim($_POST['email']);
    $_POST['full_name'] = _Function::spaces(trim($_POST['full_name']));
    $_POST['username'] = _Function::spaces(trim($_POST['username']));
    $_POST['password'] = _Function::spaces(trim($_POST['password']));
    $admin = $obj->getSettings();
    $emailAddress = $_POST['email'];
    $_POST['email_verify'] = $settings->email_verification;
    if ($_POST['full_name'] == '' || mb_strlen($_POST['full_name'], 'utf8') < 2 || mb_strlen($_POST['full_name'], 'utf8') > 20) {
        echo json_encode(array('res' => $_SESSION['LANG']['full_name_error'], 'focus' => 'full_name'));
    } else {
        if (preg_match('/[^a-z0-9\\_]/i', $_POST['username'])) {
            echo json_encode(array('res' => $_SESSION['LANG']['username_not_valid'], 'focus' => 'username'));
        } else {
            if (strlen($_POST['username']) < 1 || strlen($_POST['username']) > 15) {
                echo json_encode(array('res' => $_SESSION['LANG']['username_not_valid'], 'focus' => 'username'));
            } else {
                if (!filter_var($emailAddress, FILTER_VALIDATE_EMAIL)) {
                    echo json_encode(array('res' => $_SESSION['LANG']['email_not_valid'], 'focus' => 'email'));
                } else {
                    if (mb_strlen($_POST['password'], 'utf8') < 5 || mb_strlen($_POST['password'], 'utf8') > 20) {
                        echo json_encode(array('res' => $_SESSION['LANG']['password'], 'focus' => 'username'));
                    } else {
                        if ($_POST['terms'] == '') {
                            echo json_encode(array('res' => $_SESSION['LANG']['can_not_register']));
                        } else {
                            /* INSERT DATABASE */
                            $res = $obj->signUp();
  *   Require File
  * -------------------------
  */
 require_once '../../class_ajax_request/classAjax.php';
 /*
  * ----------------------
  *   Instance Class
  * ----------------------
  */
 $obj = new AjaxRequest();
 include_once '../../application/functions.php';
 include_once '../../application/DataConfig.php';
 $_POST['email'] = trim($_POST['email']);
 $_POST['mode'] = _Function::spaces(trim($_POST['mode']));
 $_POST['username'] = _Function::spaces(trim($_POST['username']));
 $_POST['country'] = _Function::spaces(trim($_POST['country']));
 $infoUser = $obj->infoUserLive($_SESSION['authenticated']);
 $emailAddress = $_POST['email'];
 //<<<--- Defaults Languages
 foreach (_Function::arrayLang() as $key => $value) {
     $defaultsLanguages[] = $value;
 }
 //<<<<--- Languages
 if (!in_array($_POST['lang'], $defaultsLanguages)) {
     $_POST['lang'] = 'en';
 } else {
     $_POST['lang'] = $_POST['lang'];
 }
 if ($infoUser->language != $_POST['lang']) {
     unset($_SESSION['lang_user']);
     $_SESSION['lang_user'] = $_POST['lang'];
  * --------------------------
  *   Require/Include Files
  * -------------------------
  */
 require_once '../../class_ajax_request/classAjax.php';
 include_once '../../application/functions.php';
 include_once '../../application/DataConfig.php';
 /*
  * ----------------------
  *   Instance Class
  * ----------------------
  */
 $obj = new AjaxRequest();
 $_POST['name'] = _Function::spaces(trim($_POST['name']));
 $_POST['location'] = _Function::spaces(trim(strip_tags($_POST['location'])));
 $_POST['website'] = _Function::spaces(trim($_POST['website']));
 $url = $_POST['website'];
 $_POST['website'] = trim($_POST['website'], '/');
 $_POST['bio'] = _Function::checkTextDb2(trim($_POST['bio']));
 $admin = $obj->getSettings();
 //<-------- * Cutting chain if greater than post_length  * --------->
 if (strlen(utf8_decode($_POST['bio'])) > $admin->post_length) {
     $_POST['bio'] = _Function::cropStringLimit($_POST['bio'], $admin->post_length);
 }
 if ($_POST['name'] == '' || strlen(utf8_decode($_POST['name'])) < 2 || strlen(utf8_decode($_POST['name'])) > 20) {
     echo json_encode(array('response' => $_SESSION['LANG']['full_name_error']));
 } else {
     if (!filter_var($url, FILTER_VALIDATE_URL) && $url != '') {
         echo json_encode(array('response' => $_SESSION['LANG']['url_not_valid']));
     } else {
         $_POST['name'] = htmlspecialchars($_POST['name']);
  * --------------------------
  *   Require/Include Files
  * -------------------------
  */
 require_once '../../class_ajax_request/classAjaxAdmin.php';
 include_once '../../application/functions.php';
 include_once '../../application/DataConfig.php';
 /*
  * ----------------------
  *   Instance Class
  * ----------------------
  */
 $obj = new AjaxRequestAdmin();
 $_POST['name_admin'] = _Function::spaces(trim($_POST['name_admin']));
 $_POST['user_admin'] = _Function::spaces(trim($_POST['user_admin']));
 $_POST['pass_new'] = _Function::spaces(trim($_POST['pass_new']));
 $_POST['repeat_pass'] = trim($_POST['repeat_pass']);
 if ($_POST['name_admin'] == '' || mb_strlen($_POST['name_admin'], 'utf8') < 2) {
     echo json_encode(array('res' => 'Name too short...', 'focus' => 'name_admin'));
 } else {
     if (preg_match('/[^a-z0-9\\_]/i', $_POST['user_admin'])) {
         echo json_encode(array('res' => 'Username not valid', 'focus' => 'user_admin'));
     } else {
         if (mb_strlen($_POST['pass_new'], 'utf8') < 5) {
             echo json_encode(array('res' => 'Password too short', 'focus' => 'pass_new'));
         } else {
             if ($_POST['pass_new'] !== $_POST['repeat_pass']) {
                 echo json_encode(array('res' => 'Passwords do not match'));
             } else {
                 /* INSERT DATABASE */
                 $res = $obj->addUser();