<?php
function act_register($params, $user=0) {
set_title(_("Registration"));
if (is_http_post()) {
$new['password'] = readvar('setpassword');
$new['repeatpass'] = readvar('repeatpass');
$new['name'] = readvar('name');
$new['email'] = readvar('email');
$new['id'] = readvar('theid');
$Errors = array();
if (!ereg('^[A-Za-z0-9.-]{3,29}$',$new['id'])) {
$Errors[] = _("Account name must consist only of alphanumerics, hyphen and dot,".
" and must be longer than 2, and shorter than 30 characters.");
} else { // Check if it already exists
$q = mysql_query("select * from users where id='$new[id]'");
if ($q and mysql_fetch_array($q)) {
$Errors[] = _("Account with this name already exists. Choose another name.");
}
}
if (!ereg("^[A-Za-z._0-9-]+@[A-Za-z._0-9-]+$",$new['email'])) {
$Errors[] = _("Invalid e-mail format.");
} else { // Check if it's already used
$q = mysql_query("select * from users where email='$new[email]'");
if ($q and mysql_fetch_array($q)) {
$Errors[] = _("You cannot register two accounts with the same email address.");
}
}
if (strlen($new['password'])<4) {
$Errors[] = _("Password must be at least 4 characters.");
} elseif ($new['password'] != $new['repeatpass']) {
$Errors[] = _("Your passwords do not match.");
} else {
$password = md5($new['password']);
}
if (sizeof($Errors) > 0) {
printout(_("There were some errors. Please go back and fix them.\n"));
printout("<ul>\n");
foreach ($Errors as $msg) {
printout("<li>$msg</li>\n");
}
printout("</ul>\n\n");
} else {
$q = mysql_query("insert into users values " .
" ( '$new[id]', '$password', '$new[email]', '$new[name]', NOW() )");
if ($q) {
printout(_("Account has been created."));
} else {
printout (_("There was some unknown error while creating account."));
}
}
} else {
global $CREATEACCOUNT; // Template
set_title(_("Create account"));
$vars = array(''=>'');
printout(replace_vars($CREATEACCOUNT,$vars));
}
}
?>