<?php
/**
* PHP versions 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to hide@address.com so we can mail you a copy immediately.
*
* @package QuickTicket
* @author Philippe Vandenberghe <hide@address.com>
* @copyright 2008-2012 The PHP Group
* @version 2.5 build:20101222
*/
session_start();
require_once('bin/qti_init.php');
if ( !$oVIP->CanView('V0') ) HtmlPage(10);
// INITIALISE
include('bin/qt_lib_smtp.php');
include(GetLang().'qti_reg.php');
$oVIP->selfurl = 'qti_form_reg.php';
$oVIP->selfname = $L['Register'];
$strChild = '0';
if ( isset($_GET['c']) ) $strChild = $_GET['c'];
if ( isset($_POST['child']) ) $strChild = $_POST['child'];
// --------
// SUBMITTED
// --------
if ( isset($_POST['ok']) )
{
// pre-checks
if ( empty($_POST['mail']) ) $error=$L['Email'].' '.$L['E_invalid'];
if ( empty($_POST['title']) ) $error=$L['Username'].' '.$L['E_invalid'];
if ( $_SESSION[QT]['register_safe']!='none' )
{
if ( trim($_POST['code'])=='' ) $error = $L['Type_code'];
if ( strlen($_POST['code'])!=6 ) $error = $L['Type_code'];
}
// check name
if ( empty($error) )
{
if ( get_magic_quotes_gpc() ) $_POST['title'] = stripslashes($_POST['title']);
$_POST['title'] = QTconv($_POST['title'],'U');
if ( !QTislogin($_POST['title']) ) $error=$L['Username'].' '.$L['E_invalid'];
}
// check mail
if ( empty($error) )
{
$_POST['mail'] = trim($_POST['mail']);
if (!QTismail($_POST['mail'])) $error=$L['Email'].' '.$L['E_invalid'];
}
// check parentmail
if ( QTI_USE_COPPA ) {
if ( empty($error) ) {
if ( $strChild!='0' ) {
$_POST['parentmail'] = trim($_POST['parentmail']);
if ( !QTismail($_POST['parentmail']) ) $error=$L['Parent_mail'].' '.$L['E_invalid'];
}}}
if ( !isset($_POST['parentmail']) ) $_POST['parentmail'] = '';
// check password
if ( empty($error) && $_SESSION[QT]['register_mode']=='direct' )
{
if ( get_magic_quotes_gpc() ) $_POST['pwd'] = stripslashes($_POST['pwd']);
$_POST['pwd'] = QTconv($_POST['pwd'],'U');
if ( !QTispassword($_POST['pwd']) ) $error = $L['Password'].' '.$L['E_invalid'];
if ( get_magic_quotes_gpc() ) $_POST['conpwd'] = stripslashes($_POST['conpwd']);
$_POST['conpwd'] = QTconv($_POST['conpwd'],'U');
if ( !QTispassword($_POST['conpwd']) ) $error = $L['Password'].' '.$L['E_invalid'];
}
if ( empty($error) && $_SESSION[QT]['register_mode']=='direct' )
{
if ( $_POST['conpwd']!=$_POST['pwd'] ) $error = $L['Password'].' '.$L['E_invalid'];
}
// check code
if ( empty($error) )
{
if ( $_SESSION[QT]['register_safe']!='none' )
{
$strCode = strtoupper(strip_tags(trim($_POST['code'])));
if ($strCode=='') $error = $L['Type_code'];
if ( $_SESSION['textcolor']!=sha1($strCode) ) $error = $L['Type_code'];
}
}
// --------
// register user
// --------
if ( empty($error) )
{
// email code
if ( $_SESSION[QT]['register_mode']=='email' ) $_POST['pwd'] = 'QT'.rand(0,9).rand(0,9).rand(0,9).rand(0,9);
$id = $oDB->Nextid(TABUSER);
$oDB->Query( 'INSERT INTO '.TABUSER.' (id,name,pwd,closed,role,mail,privacy,firstdate,lastdate,numpost,children,parentmail,photo) VALUES ('.$id.',"'.$_POST['title'].'","'.sha1($_POST['pwd']).'","0","U","'.$_POST['mail'].'","1","'.Date('Ymd His').'","'.Date('Ymd His').'",0,"'.$strChild.'","'.$_POST['parentmail'].'","0")' );
// Unregister global sys (will be recomputed on next page)
Unset($_SESSION[QT]['sys_states']);
// send email
$strSubject = $_SESSION[QT]['site_name'].' - Welcome';
$strMessage = "Please find here after your login and password to access the board {$_SESSION[QT]['site_name']}.\nLogin: %s\nPassword: %s";
$strFile = GetLang().'mail_registred.php';
if ( file_exists($strFile) ) include($strFile);
$strMessage = sprintf($strMessage,$_POST['title'],$_POST['pwd']);
QTmail($_POST['mail'],QTconv($strSubject,'-4'),QTconv($strMessage,'-4'),QTI_HTML_CHAR);
// parent mail
if ( QTI_USE_COPPA ) {
if ( $strChild!='0' ) {
$strSubject = $_SESSION[QT]['site_name'].' - Welcome';
$strMessage = "We inform you that your children has registered on the forum {$_SESSION[QT]['site_name']}.\nLogin: %s\nPassword: %s\nYour agreement is required to activte this account.";
$strFile = GetLang().'mail_registred_coppa.php';
if ( file_exists($strFile) ) include($strFile);
$strMessage = sprintf($strMessage,$_POST['title'],$_POST['pwd']);
QTmail($_POST['parentmail'],QTconv($strSubject,'-4'),QTconv($strMessage,'-4'),QTI_HTML_CHAR);
}}
// END MESSAGE
if ( $_SESSION[QT]['register_mode']=='email' )
{
$oVIP->exiturl = 'qti_index.php';
$oVIP->exitname = ObjTrans('index','i',$_SESSION[QT]['index_name']);
}
else
{
$L['Reg_mail'] = S;
$oVIP->exiturl = 'qti_login.php?dfltname='.urlencode($_POST['title']);
$oVIP->exitname = $L['Login'];
}
$oVIP->EndMessage(NULL,'<h2>'.$L['Register_completed'].'</h2><p>'.$L['Reg_mail'].'</p>',$_SESSION[QT]['skin_dir'],0,'350px','login_header','login');
}
}
// --------
// HTML START
// --------
$oHtml->links[] = '<link rel="stylesheet" type="text/css" href="'.$_SESSION[QT]['skin_dir'].'/qti_main2.css" />';
$strHeadScript = '
<script type="text/javascript" src="bin/qt_jquery.js"></script>
<script type="text/javascript">
<!--
function ValidateForm(theForm)
{
if (theForm.title.value.length==0) { alert(qtHtmldecode("'.$L['Missing'].': '.$L['Choose_name'].'")); return false; }
if (theForm.mail.value.length==0) { alert(qtHtmldecode("'.$L['Missing'].': '.$L['Your_mail'].'")); return false; }
if (theForm.code.value.length==0) { alert(qtHtmldecode("'.$L['Missing'].': '.$L['Security'].'")); return false; }
if (theForm.code.value=="QT") { alert(qtHtmldecode("'.$L['Missing'].': '.$L['Security'].'")); return false; }
return null;
}
function MinChar(strField,strValue)
{
if ( strValue.length>0 && strValue.length<4 )
{
document.getElementById(strField+"_err").innerHTML="<br />'.$L['E_min_4_char'].'";
return null;
}
else
{
document.getElementById(strField+"_err").innerHTML="";
return null;
}
}
$(function() {
$("#title").blur(function() {
$.post("qti_j_exists.php",
{f:"name",v:$("#title").val(),e1:"'.$L['E_min_4_char'].'",e2:"'.$L['E_already_used'].'"},
function(data) { if ( data.length>0 ) document.getElementById("title_err").innerHTML=data; });
});
});
-->
</script>
';
include('qti_p_header.php');
// DEFAULT VALUE RECOVERY (na)
if ( !isset($_POST['title']) ) $_POST['title']='';
if ( !isset($_POST['pwd']) ) $_POST['pwd']='';
if ( !isset($_POST['conpwd']) ) $_POST['conpwd']='';
if ( !isset($_POST['mail']) ) $_POST['mail']='';
if ( !isset($_POST['parentmail']) ) $_POST['parentmail']='';
if ( $_SESSION[QT]['register_safe']=='text' )
{
$keycode = 'QT'.rand(0,9).rand(0,9).rand(0,9).rand(0,9);
$_SESSION['textcolor'] = sha1($keycode);
}
// --------
// CONTENT
// --------
if ( QTI_USE_COPPA && $strChild!='0' )
{
echo '<div class="scrollmessage">';
$strFile = GetLang().'sys_rules_coppa.txt';
if ( file_exists($strFile) ) { include($strFile); } else { echo 'Missing file:<br />',$strFile; }
echo '</div>';
}
$oHtml->Msgbox($oVIP->selfname,array('style'=>'width:620px'),array('id'=>'login_header'));
echo '
<form method="post" action="',Href(),'" onsubmit="return ValidateForm(this);">
<table class="hidden" cellspacing="0">
<tr class="hidden">
<td class="hidden" style="width: 370px;">
<div id="login">
<fieldset class="fs_register">
<legend>',$L['Username'],'</legend>
<span class="small">',$L['Choose_name'],'</span>
<input type="text" id="title" name="title" size="20" maxlength="24" value="',$_POST['title'],'" onfocus="document.getElementById(\'title_err\').innerHTML=\'\';" /><br /><span id="title_err" class="error"></span><br />
';
if ( $_SESSION[QT]['register_mode']=='direct' )
{
echo '<span class="small">',$L['Choose_password'],'</span> <input type="password" id="pwd" name="pwd" size="20" maxlength="24" value="',$_POST['pwd'],'" onblur="MinChar(this.name,this.value)" /><span id="pwd_err" class="error"></span><br />';
echo '<span class="small">',$L['Confirm_password'],'</span> <input type="password" id="conpwd" name="conpwd" size="20" maxlength="24" value="',$_POST['conpwd'],'" onblur="MinChar(this.name,this.value)" /><span id="conpwd_err" class="error"></span><br />';
}
else
{
echo '<span class="small">',$L['Password_by_mail'],'</span><br />';
}
echo '
</fieldset>
<fieldset class="fs_register">
<legend>',$L['Email'],'</legend>
<span class="small">',$L['Your_mail'],'</span> <input type="text" id="mail" name="mail" size="32" maxlength="64" value="',$_POST['mail'],'" /><span id="mail_err" class="error"></span><br />
';
if ( QTI_USE_COPPA && $strChild!='0' ) echo ' <span class="small">',$L['Parent_mail'],'</span> <input type="text" id="parentmail" name="parentmail" size="32" maxlength="64" value="',$_POST['parentmail'],'" /><br />';
echo '
</fieldset>
<fieldset class="fs_register">
<legend>',$L['Security'],'</legend>
';
if ( $_SESSION[QT]['register_safe']=='image' ) echo '<img width="100" height="35" src="admin/qti_icode.php" alt="security" style="text-align:right" /> <input type="text" name="code" size="8" maxlength="8" value="QT" /><br /><span class="small">',$L['Type_code'],'</span>';
if ( $_SESSION[QT]['register_safe']=='text' ) echo $keycode,' <input type="text" id="code" name="code" size="8" maxlength="8" value="QT" /><br /><span class="small">',$L['Type_code'],'</span>';
echo '
</fieldset>
<input type="hidden" name="child" value="',$strChild,'" />
',(!empty($error) ? '<p class="error">'.$error.'</p>' : ''),'<input type="submit" name="ok" value="',$L['Register'],'" />
</div>
</td>
<td class="hidden" style="width:20px;"> </td>
<td class="hidden"><span class="small">',$L['Reg_help'],'</span></td>
</tr>
</table>
</form>
';
$oHtml->Msgbox();
// HTML END
include('qti_p_footer.php');
?>