<?php session_start();  //Developed by ITechScripts
require 'include/configurations.php'; // ITECHBIDS Configuration File
require 'include/header.php'; 
require '../include/itechbids.php'; 
require 'include/argvs.php'; // ITECHBIDS Configuration File
?>
<?

$userid=$_GET['id'];
$mode=$_GET['mode'];

if($mode=="edit"){
	 $sql="select * from admin where admin_id='$userid'";
     $res=mysql_query($sql);
$row=mysql_fetch_array($res);
}
$step=$_POST[step];
if($step==1)
{
$txtfirst=$_POST[txtfirst];
$txtlast=$_POST[txtlast];
$email=$_POST[txtemail];
$reemail=$_POST[txtreemail];
$username1=$_POST[txtusername];
$pass=$_POST[txtpass];
$repass=$_POST[txtrepass]; 
$validEmailExpr= "^[0-9a-z~!#$%&_-]([.]?[0-9a-z~!#$%&_-])"."@[0-9a-z~!#$%&_-]([.]?[0-9a-z~!#$%&_-])".".[a-z]*$";
if(empty($username1))
  {
  $err_user="Please enter this information";
  $err_flag=1;
  }
  else
  {
  $sql="select * from admin 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($txtfirst))
  {
  $err_first="Please enter this information";
  $err_flag=1;
  }
  if(empty($txtlast))
  {
  $err_last="Please enter this information";
    $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 = "";
}

$username2 = seccheck($username1);
$pswd = seccheck($pass);

if($mode!="edit"){
  $date_of_registration=date('Y-m-d');
   $sql="insert into admin(user_name,password,email,status,fname,lname)";
    $sql.= "values('$username2','$pswd','$reemail','sub','$txtfirst','$txtlast')";
   $res=mysql_query($sql);
}
if($mode=="edit"){
  $date_of_registration=date('Y-m-d');
   $sql="UPDATE admin SET user_name = '$username2',password = '$pswd',fname = '$txtfirst',lname = '$txtlast' WHERE admin_id ='$userid'";
   $res=mysql_query($sql);
}


   if($res)
   {
   echo '<meta http-equiv="refresh" content="0;url=adminlist.php">';
   }
  }
}
$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="addadmin.php?mode=<?=$mode?>&id=<?=$userid?>" 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 Admin</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=<?= $row['fname']; ?>></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=<?= $row['lname']; ?>></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=<?= $row['email']; ?>></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=<?= $row['email']; ?>>
 <br>
    </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>
