<?php session_start();  //Developed by ITechScripts
require 'include/configurations.php'; // ITECHBIDS Configuration File
require 'include/header.php'; 
require 'include/argvs.php'; 
require '../include/itechbids.php'; 
?>
<?
$step=$_POST[step];
if($step==1)
{
$first=$_POST[txtfirst];
$last=$_POST[txtlast];
$address=$_POST[txtaddress];
$city=$_POST[txtcity];
$state=$_POST[cbostate];
$country=$_POST[cbocountry];
$code=$_POST[txtzipcode];
$primary=$_POST[txtprimary];
$secondary=$_POST[txtsecondary];
$email=$_POST[txtemail];
$reemail=$_POST[txtreemail];
$username1=$_POST[txtusername];
$pass=$_POST[txtpass];
$repass=$_POST[txtrepass]; 
$member_type=$_POST[member_type];
$mem_plans=$_POST[mem_plans];

function check_email_address($email) {
// First, we check that there's one @ symbol, and that the lengths are right
if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
// Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
return false;
}
// Split it into sections to make life easier
$email_array = explode("@", $email);
$local_array = explode(".", $email_array[0]);
for ($i = 0; $i < sizeof($local_array); $i++) {
if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
return false;
}
}
if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name
$domain_array = explode(".", $email_array[1]);
if (sizeof($domain_array) < 2) {
return false; // Not enough parts to domain
}
for ($i = 0; $i < sizeof($domain_array); $i++) {
if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
return false;
}
}
}
return true;
}

if(empty($username1))
  {
  $err_user="Please enter this information";
  $err_flag=1;
  }
  else
  {
  $sql="select * from member_details where user_name='$username1'";
  $res=mysql_query($sql);
  $chk=mysql_num_rows($res);
  if($chk!=0)
  {
  $err_user="Already Exist";
  $err_flag=1;
  }
  }
  
  if(empty($pass))
  {
  $err_pass="Please enter this information";
    $err_flag=1;
  }
  else
  {
  if(strlen($pass)<6)
  {
      $err_pass="Please Choose 6 characters";
	      $err_flag=1;
  }
  }
  if(empty($repass))
  {
  $err_repass="Please enter this information";
    $err_flag=1;
  }
  else
  {
  if(strlen($repass)<6 )
  {
      $err_repass="Please Choose 6 characters";
	      $err_flag=1;
	    }
		}

 

  if(empty($first))
  {
  $err_first="Please enter this information";
  $err_flag=1;
  }
  if(empty($last))
  {
  $err_last="Please enter this information";
    $err_flag=1;
  }
  if(empty($address))
  {
  $err_add="Please enter this information";
    $err_flag=1;
  }
    if(empty($city))
	{
	  $err_city="Please enter this information";
	    $err_flag=1;
	  }
 if(empty($state))
 {
   $err_state="Please enter this information";
     $err_flag=1;
   }
 if(empty($country))
 {
  $err_country="Please enter this information";
    $err_flag=1;
 }
 if(empty($code))
 {
   $err_code="Please enter this information";
     $err_flag=1;
 }
 if( strlen($code)>6 )
 {
  $err_code="Your Zipcode is invalid";
    $err_flag=1;
 }
   if(empty($primary))
   {
     $err_primary="Please enter this information";
	   $err_flag=1;
   }
   if(!is_numeric($secondary))
   {
    $err_primary="Your Primary Phoneno is invalid";
    $err_flag=1;
	}
   if(empty($secondary))
   {
    $err_secondary="Please enter this information";
    $err_flag=1;
	}
    if(!is_numeric($secondary))
	{
      $err_secondary="Your Secondary Phoneno is invalid";
	  $err_flag=1;
	  }
   if(empty($email))
   {
    $err_email="Please enter this information";
    $err_flag=1;
	}
  else
   {
    if(!check_email_address($email))
	{
	 $err_email="Your Email address id invalid ";
	 $err_flag=1;
	}
	}
   if(empty($reemail))
   {
  $err_reemail="Please enter this information";
    $err_flag=1;
	}
  else
  {
    if(!check_email_address($reemail))
	{
	 $err_reemail="Your Email address id invalid ";
	 $err_flag=1;
	}
	}
   
   if(empty($err_email) && empty($err_reemail))
	{
	if($email!=$reemail)
	{
	   $err_email="Your email entries must match. Please check both.";
	   $err_remail="Your email entries must match. Please check both.";
	   $err_flag=1;
	}
	}
     
   if($err_flag!=1)
  {

$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 = "";
}


$nnpass=seccheck($pass);







  $date_of_registration=date('Y-m-d');
   $sql="insert into member_details(user_name,member_account,password,email,first_name,last_name,address,city,state,pin_code,country,home_phone,work_phone,status,date_of_registration)";
    $sql.= "values('$username1','$member_type','$nnpass','$reemail','$first','$last','$address','$city','$state','$code','$country','$primary','$secondary','Active','$date_of_registration')";
   $res=mysql_query($sql);
   if($res)
   {
   $user_id=mysql_insert_id();
$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);
   echo '<meta http-equiv="refresh" content="0;url=user.php">';
   }
   } 
} //step==1
 
$state_sql="select * from site_states where country_id=38 ";
$state_res=mysql_query($state_sql);
$country_sql="select * from site_countries";
$country_res=mysql_query($country_sql);
?>
<form name=reg action="addnew.php" method=post>
<html>
<head>
<title>Registration:enter information</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>
<body>
<table width="559" align="center" class="ft"  >

<tr height=40 >
  <td class="ct" height="25" colspan="2" align="center"><b>Add New User</b> 
<br><font size="-2">  ( Fields marked with an asterisk <font color="red">* </font>are required )</font></td></tr> 


 
 <tr ><td>
 <? if(!empty($err_first))
 {?>
 <img src="../images/xclabids.gif">&nbsp;<font size=2 color=red><?= $err_first ?></font>
 <br>
 <b><font size=2 color=red>First name</font></b>
 <?
  }
  else
  {
 ?>
   <b><font size=2 >First name <font color="red" size="-2">*</font></font></b>
   <? }
   ?>
 </td>
   <td ><input type="text" class="bluetext"name="txtfirst" style="width:250 " class="txtmed" value=<?= $first; ?>></td>
 <tr >
 <td>
 <? if(!empty($err_last))
 {?>
 <img src="../images/xclabids.gif">&nbsp;<font size=2 color=red><?= $err_last ?></font>
 <br>
 <b><font size=2 color=red>Last name</font></b>
 <?
  }
  else
  {
 ?>
 <b><font size=2>Last name <font color="red" size="-2">*</font></b>
   <? }
   ?>
   </td> <td><input type="text" class="bluetext"name="txtlast" style="width:250 " class="txtmed" value=<?= $last; ?>></td></tr>
    <tr ><td width=293>
 <? if(!empty($err_user))
 {?>
 <img src="../images/xclabids.gif">&nbsp;<font size=2 color=red><?= $err_user ?></font>
 <br>
 <b><font size=2 color=red>User name</font></b>
 <?
  }
  else
  {
 ?>
   <b><font size=2 >User name <font color="red" size="-2">*</font></b>
   <? }
   ?>
 </td>
      <td width=302><input type="text" class="bluetext"name="txtusername" style="width:250 " class="txtmed" value=<?= $username1; ?>></td></tr>
  <tr >
 <td>
 <? if(!empty($err_pass))
 {?>
 <img src="../images/xclabids.gif">&nbsp;<font size=2 color=red><?= $err_pass ?></font>
 <br>
 <b><font size=2 color=red>Password</font></b>
 <?
  }
  else
  {
 ?>
 <b><font size=2>Password <font color="red" size="-2">*</font></b>
   <? }
   ?>
   </td>
 <td width=302>
        <input type="password" name="txtpass" style="width:250 " class="txtmed" value=<?= $pass; ?>>
      <br>6 character minimum.</td></tr>
 
 
 <tr ><td > 
 <? if(!empty($err_repass))
 {
 ?>
 <img src="../images/xclabids.gif">&nbsp;<font size=2 color=red><?= $err_repass ?></font>
 <br>
 <b><font size=2 color=red>Re-enter Password</font></b>
 <?
  }
  else
  {
 ?>
 <b><font size=2>Re-enter Password <font color="red" size="-2">*</font></b>
   <? 
   }
   ?></td>
 <td ><input type="password" name="txtrepass" style="width:250 " class="txtmed" value=<?= $repass; ?>></td></tr>
 <tr >
 <td >
 <? if(!empty($err_email))
 {
 ?>
 <img src="../images/xclabids.gif">&nbsp;<font size=2 color=red><?= $err_email ; ?></font>
 <br>
 <b><font size=2 color=red>Email Address</font></b>
 <?
  }
  else
  {
 ?>
   <b><font size=2>Email Address <font color="red" size="-2">*</font></b>
   <?
   }
   ?>
 </td>

 <td width=302><input type="text" class="bluetext"name="txtemail" style="width:250 " class="txtbig" value=<?= $reemail; ?>></td>
 </tr>
 <tr ><td >
   <? if(!empty($err_reemail))
 {?>
 <img src="../images/xclabids.gif">&nbsp;<font size=2 color=red><?= $err_reemail ; ?></font>
 <br>
 <b><font size=2 color=red>Re-enter Email</font></b>
 <?
  }
  else
  {
 ?>
   <b><font size=2>Re-enter Email <font color="red" size="-2">*</font></b>
   <?
   }
   ?>
  </td><td width=302><input type="text" class="bluetext"name="txtreemail" style="width:250 " class="txtbig" value=<?= $reemail; ?>>
 <br>
    </td>
 </tr>
 <tr ><td>
 <? if(!empty($err_primary))
 {?>
 <img src="../images/xclabids.gif">&nbsp;<font size=2 color=red><?= $err_primary ?></font>
 <br>
 <b><font size=2 color=red>Primary telephone</font></b>
 <?
  }
  else
  {
 ?>
   <b><font size=2>Primary telephone <font color="red" size="-2">*</font></b>
   <?
   }
   ?></td><td>
 <input type="text" class="bluetext"name="txtprimary" class="txtmed" style="width:250 " value="<?= $primary; ?>"></td></tr>
 <tr >
   <td>
   <? if(!empty($err_secondary))
 {?>
 <img src="../images/xclabids.gif">&nbsp;<font size=2 color=red><?= $err_secondary ; ?></font>
 <br>
 <b><font size=2 color=red>Secondary telephone</font></b>
 <?
  }
  else
  {
 ?>
   <b><font size=2>Secondary telephone <font color="red" size="-2">*</font></b>
   <?
   }
   ?></td>
 
 <td width="302"><input type="text" class="bluetext"name="txtsecondary" class="txtmed" style="width:250 " value=<?= $secondary; ?>></td></tr>
  
 

  
 <tr ><td>
 <? if(!empty($err_add))
 {
 ?>
 <img src="../images/xclabids.gif">&nbsp;<font size=2 color=red><?= $err_add ?></font>
 <br>
 <b><font size=2 color=red>Street Address</font></b>
 <?
  }
  else
  {
 ?>
 <b><font size=2>Street Address <font color="red" size="-2">*</font></b>
   <? 
   }
   ?></td><td ><input type="text" class="bluetext"name="txtaddress" style="width:250 " class="txtbig" value=<?= $address; ?>></td> </tr>
 
 <tr ><td >
 <? if(!empty($err_city))
 {
 ?>
 <img src="../images/xclabids.gif">&nbsp;<font size=2 color=red><?= $err_city ?></font>
 <br>
 <b><font size=2 color=red>City</font></b>
 <?
  }
  else
  {
 ?>
 <b><font size=2>City <font color="red" size="-2">*</font></b></td>
 <? } ?>
 <td ><input type="text" class="bluetext"name="txtcity" class="txtbig" style="width:250 " value=<?= $city; ?>></td></tr>
 <tr ><td>
 <? if(!empty($err_state))
 {?>
 <img src="../images/xclabids.gif">&nbsp;<font size=2 color=red><?= $err_state ?></font>
 <br>
 <b><font size=2 color=red>State</font></b>
 <?
  }
  else
  {
 ?>
   <b><font size=2>State <font color="red" size="-2">*</font></b>
   <?
   }
   ?> 
   </td>
   <td>
   <input type="text" class="bluetext"name="cbostate" class="txtbig" style="width:250 " value=<?= $state; ?> >
   </td>
   </tr>
   <tr >
   <td>
   <? if(!empty($err_code))
 {?>
 <img src="../images/xclabids.gif">&nbsp;<font size=2 color=red><?= $err_code ?></font>
 <br>
 <b><font size=2 color=red>Zip\Postal Code</font></b>
 <?
  }
  else
  {
 ?>
   <b><font size=2>Zip\Postal Code <font color="red" size="-2">*</font></b>
   <?
   }
   ?>
</td><td><input type="text" class="bluetext"name="txtzipcode" style="width:250 " class="txtsmall" value=<?= $code; ?>></td></tr>

<tr >
<td width="293">
 <? if(!empty($err_country))
 {
 ?>
 <img src="../images/xclabids.gif">&nbsp;<font size=2 color=red><?= $err_country ?></font>
 <br>
 <b><font size=2 color=red>Country</font></b>
 <?
  }
  else
  {
 ?>
   <b><font size=2>Country <font color="red" size="-2">*</font></b>
   <?
   }
   ?>
</td><td><select name=cbocountry  style="width:250 ">
<option value="0" >Select</option>
  <? while($country_row=mysql_fetch_array($country_res))
  { 
   if(trim($country_row['country_id'])==trim($country))
  {
   ?>
     <option value="<?= $country_row['country_id'] ?>" selected><?= $country_row['country']?></option>
  <?
  }
  else
  {
  ?>
     <option value="<?= $country_row['country_id'] ?>"><?= $country_row['country']?></option>
  <?
  }
  }
  ?>
  
   
  </select></td>
 </tr>
 <tr><td width="293"><b><font size=2>Select Plan</font></b></td>
 <td>
 <?
 $fee_query="select * from site_fees where status='Active'";
$fee_table=mysql_query($fee_query);
?>
  <select name=mem_plans>
 <? 
for($i=1; $fee_row=mysql_fetch_array($fee_table); $i++)
 {
$admin_id = $fee_row[admin_id];
$duration = $fee_row[duration];
$registration_fee = $fee_row[registration_fee];
$scheme= $fee_row[scheme];
if($duration==0)
{
$duration = "Unlimited";
}
?>
   <option value=<?= $admin_id ?>> <?= $scheme ?>, <?=$registration_fee?> <?= $default_cur_code ?>/<?=$duration?> Days </option>
<?
}
?>
</select>
</td></tr>

  
 <input type="hidden" name=step value=2>
 <input type="hidden" name=user_id value="<?= $user_id;?>">
 
 <input type="hidden" name=step value=1>
 <tr><td colspan="6" align="center"><input type="submit" class="button"   value="Register" name=submit ></td></tr>
 </form>
  <? require'include/footer.php'; ?>
</table>
   
</body>
</html>
