<?php
/*
Register user
(c) 2004-2007 by "Oleg Savchuk" <hide@address.com>
part of phpProjectMaster project
http://phpprojmaster.sourceforge.net
The contents of this file are subject to the GNU GENERAL PUBLIC LICENSE
http://www.gnu.org/copyleft/gpl.html
*/
session_start();
require_once "../inc/sitelib.php" ;
require_once "../inc/form_utils.php" ;
require_once "../inc/user.php" ;
global_init();
//********* variables
//********* action!
$CGI_ACTIONS=array(
'' => 'show_add_item',
// 'AddNew' => 'show_add_item',
'Edit' => 'show_one_item',
'SaveRecAdd' => 'save_one_item_add',
'conf' => 'confirm_user',
);
go_action();
exit;
//***************************
function show_add_item(){
global $green_msg, $err_msg;
$hITEM=$_REQUEST['item'];
if (!$hITEM){ //init values
}
$ps=array(
);
$ps=array_merge($ps, $hITEM);
parse_page("/admin/register/add", $GLOBALS['PAGE_TPL'], $ps);
}
//*************************** save item info ADD
function save_one_item_add(){
global $green_msg, $err_msg;
global $root_domain;
if (validate_users_add($_REQUEST['item'])){
//prepare for insert - insert only particular fields
$IFORM=form2dbhash($_REQUEST['item'], 'email pwd');
# $IFORM['confcode']=get_rand_str(16); #!!!TODO for activation/check email
$sql="insert into users ".get_sqlinsert_set($IFORM,', add_time',', now()');
logger($sql);
$sth=db_query($sql);
$item_id=get_identity();
//send email to user with confirmation code
// $IFORM['ROOT_DOMAIN']=$root_domain;
// $msg_body=parse_page('/emails', 'email_actcode.txt', $IFORM);
// list($msg_subj, $msg_body)=email2subj_body($msg_body);
// send_email($IFORM['email'], $msg_subj, $msg_body);
show_user_added();
} else {
show_add_item();
}
}
//################# Validate item form values in IFORM
function validate_users_add($IFORM){
global $err_msg;
$REQFLD=array(
'email' => array('Email'),
'pwd' => array('Password'),
);
//VALIDATE REQUIRED FIELDS
if (!$err_msg) { $err_msg=validate_form($IFORM, $REQFLD); }
//VALIDATE if field unique
if (!$err_msg && is_dbrecord_exists2('users', 'email', $IFORM['email'], " and status<>127 ") ){
$err_msg="Such Email already registered. Please, login as a member or select another Email.";
}
if (!$err_msg && ($IFORM['pwd']!=$IFORM['pwd2'])){
$err_msg="Passwords are not equal. Please Enter Passwords again";
}
if ($err_msg) { return 0 ;}
return 1;
}
//#########################
function show_user_added(){
$ps=array(
);
$page=parse_page("/admin/register/added", $GLOBALS['PAGE_TPL'], $ps);
}
//######################### !!!TODO this is for user confirmation/email check
function confirm_user(){
$confcode=$_REQUEST['code'];
$hUW=get_users_wait_bycode($confcode);
if ($hUW){
//copy record to users table
$sql="insert into users (nick, fname, lname, address1, address2, city, state, zip, country, birthday, sex, email, pwd, add_time)
select nick, fname, lname, address1, address2, city, state, zip, country, birthday, sex, email, pwd, now()
from users_wait
where uw_id=".$hUW['uw_id']."
";
$sth=db_query($sql);
$u_id=get_identity();
//mark reg record as deleted
$sql="update users_wait
set status=127
where email=".db_quote($hUW['email'])."
";
$sth=db_query($sql);
//if there any newsletters waiting for subscription - subscribe them
$sql="insert into user_nl (u_id, nl_id, add_time)
select $u_id, nl_id, add_time
from users_wait_nl
where email=".db_quote($hUW['email'])."
";
$sth=db_query($sql);
//now go to login screen
$green_msg="Account successfully activated. Now you may log in.";
redirect_js("login.php?green_msg=".urlencode($green_msg));
} else { //display err message
show_err_msg('Account activation record not found or you already activated the account');
}
}
//#################
function show_err_msg($err_msg){
$ps=array(
);
$page=parse_page("/member/register/err", $GLOBALS['PAGE_TPL'], $ps);
}
?>