<?php session_start();  //Developed by ITechScripts
require 'include/announcements.php'; // ITECHBIDS Configuration File
require 'include/itechbids.php'; // ITECHBIDS Configuration File
require 'include/argvs.php'; // Server compatibility Patch
require 'include/options.php'; // ITECHBIDS Configuration File
require 'payments/display.php'; // ITECHBIDS Configuration File
$registration_fee=$_SESSION['registration_fee'];
$mem_plans=$_SESSION['mem_plans'];
if($registration_fee>0)
     {
$payment_status = "no";
}
if($registration_fee==0)
     {
$payment_status = "yes";
}


if($en_dis[8]=="yes"){
$app_status = "no";

  }
if($en_dis[8]=="no"){
$app_status = "yes";

  }

$duration = site_plans($mem_plans, 'duration');
function addDay($date,$interval) 
  { 
  if (!isset($date)) 
  $date = date("Y-m-d"); 
  $elts = explode("-", $date); 
  $inter=$interval*24*3600; 
  $dcour=mktime(1,0,0,$elts[1],$elts[2],$elts[0]); 
  $dres=$dcour+$inter; 
  $date1=date("Y-m-d",$dres);
  $sec=date("G:i:s");
  $ret_date="$date1"." "."$sec";
  return $ret_date; 
}
if($duration!=0)
{
$start_date=date("y-m-d");
$expir_date= addDay($start_date,$dur);  
}
if($duration==0)
{
$expir_date = "";
}
$step=$_POST[step];
$paymentid=$_POST[paymentid];

$_SESSION['regpay']="$paymentid";

$user_id=$_GET[user_id];
if($step==2)
{ 
  $user_id=$_POST[user_id];
  $username=$_POST[txtusername];
  $pass=$_POST[txtpass];
  $repass=$_POST[txtrepass];
  if(empty($username))
  {
   $err_user=$err_16;
  $err_flag=1;
  }
  else
  {
  $sql="select * from member_details where user_name='$username'";
  $res=mysql_query($sql);
  $chk=mysql_num_rows($res);
  if($chk!=0)
  {
   $err_user=$err_17;
  $err_flag=1;
  }
  }
  if(empty($pass))
  {
   $err_pass=$err_23;
   $err_flag=1;
  }
  else
  {
  if(strlen($pass)<6)
  {
   $err_pass=$err_19;
   $err_flag=1;
  }
  }
  if(empty($repass))
  {
   $err_repass=$err_22;
   $err_flag=1;
  }
  else
  {
  if(strlen($repass)<6 )
  {
   $err_repass=$err_19;
   $err_flag=1;
  }
  
  
   if((!empty($pass)) && (!empty($repass)))
	{
	if($pass!=$repass)
	{
	  $passmatch="Password fields must match.Check Both";
	  $err_flag=1;
	}
	}
}
  
    if($err_flag!=1)
  {
   	$secret=md5($username); 
        $veri_code=substr($secret,0,6);
 	$ses_sql="select * from member_details where user_id='$user_id'";
	$ses_res=mysql_query($ses_sql);
	$ses_row=mysql_fetch_array($ses_res);
	 $_SESSION[user_id]=$user_id;
	 $_SESSION[accout]=$ses_row[original_account];
	if($ses_row[original_account]==2)
	{
	 $admin_sql="select * from admin_setings where set_id=34";
	 $admin_res=mysql_query($admin_sql);
	 $admin_row=mysql_fetch_array($admin_res);
     $member_fee=$admin_row[set_value];
	 }
	else if($ses_row[original_account]==3)
	{
     $admin_sql="select * from genaralsettings where set_id=33";
	 $admin_res=mysql_query($admin_sql);
	 $admin_row=mysql_fetch_array($admin_res);
	 $member_fee=$admin_row[set_value];
	 }
	 $_SESSION[amount]=$member_fee;
$nrepass=seccheck($repass);
$_SESSION[repass]=$repass;
if($en_dis[9]=="yes"){

   $sql="update member_details set user_name='$username',password='$nrepass',veri_code='$veri_code',verified='no', payment_status='$payment_status', approved='$app_status', member_type=$mem_plans where user_id=$user_id";
   $res=mysql_query($sql);
  }
if($en_dis[9]=="no"){

   $sql="update member_details set user_name='$username',password='$nrepass',veri_code='$veri_code', verified='yes', payment_status='$payment_status', approved='$app_status', member_type=$mem_plans where user_id=$user_id";
   $res=mysql_query($sql);
  }
$query="insert into f_members (userid, start_date, exp_date, fee_id, status) values('$user_id', now(), '$expir_date', $mem_plans, 'Active')";
mysql_query($query);

   $user_sql="select * from member_details where user_id='$user_id'";
   $user_res=mysql_query($user_sql);
   $user_rec=mysql_fetch_array($user_res);
      if($registration_fee>0)
     {
$_SESSION['regmem']="$user_id";
     echo '<meta http-equiv="refresh" content="0;url=payment.php">';
     echo "You have been Re-Directed,if not please <a href=payment.php>$lang_117</a>";
     exit(); 
	 }
	 else
	 {
     echo '<meta http-equiv="refresh" content="0;url=verification_reg.php?user_id='.$user_id.'">';
     echo "$lang_675 <a href=verification_reg?user_id=$user_id>$lang_117</a>";
     exit(); 
	 }
   }
} 
?>
<? require 'themes/account_reg.tpl';  ?>
 