<?	ob_start();
session_start();
if($_SESSION['uname']=='' || $_SESSION['pwd']=='')
		{
			header("location:login.php");
		}
 include("../include/db.inc.php");
 include("../include/pager.php"); 
 include("../include/bit_functions.inc.php");
   $db1=new db;
   $db1->open();
    
   
   
   if(isset($_POST['add_subadmin']))
	{
		extract($_POST);
		
	 $sql_chk="select * from admin where uname='$adname'";
     $res_chk=mysql_query($sql_chk);
	 if(mysql_num_rows($res_chk)>0 || $adname=='')
	 {
  ?>
<script type=text/javascript language=javascript>
	    alert("Sorry This user already exist");
	    window.location.href="addsubadmin.php";
	   </script>
<?
	 } 
		else{
		 $sql="insert into admin set uname='$adname',pwd='$password',email='$ademail', block='1', type='$subadmin_type' ";
 		 $res=mysql_query($sql) or die(mysql_error().$sql);	
		  header("location:subadmin.php");
		
		}		
					
	}
	
	
	 if(isset($_POST['edit_subadmin']))
	{
		extract($_POST);
		
		
		 $sql="update admin set uname='$adname', pwd='$password', email='$ademail' , type='$subadmin_type' where id='$aid'";
 		 $res=mysql_query($sql) or die(mysql_error().$sql);	
		 header("location:subadmin.php");
		
		
					
	}
	
	if(isset($_GET['edit'])){
	
	$query_edit=mysql_query("select * from admin where id =".$_GET['edit']);
	$adminrow=mysql_fetch_array($query_edit);
	
	}
	

	?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Money Auctions | Admin Controls</title>
<link href="index.css" rel="stylesheet" type="text/css" />
<script language="JavaScript">
function veiwmem(id){
			window.open('view_user.php?id='+id,'','width=800,height=800,top=5,left=180');		
	}	
	</script>

</head>

<body bgcolor="#ffffff">
<div class="admin_wrapper">
<div class="logo_show"><? include("minorlogout.php");?></div>
<div style="float:left; width:200px">
<div class="topg_links_show"><? include("left.php");	?></div>
<div class="top_links_show"><? include("belowleft1.php");	?></div></div>
<div style="float:left; width:800px">
<div class="maximum">

<table width="80%" border="0" cellpadding="0" cellspacing="0" class="bodytxt">
              <tr> 
                <td width="33" valign="top"><img src="img/03.gif" width="33" height="23"></td>
                <td background="img/bg01.gif">
				<strong>&nbsp;ADD/EDIT SUBADMIN User</strong></td>
				<td background="img/bg01.gif"><a href="subadmin.php"><strong>&nbsp;Show Subadmin Details</strong></a></td>
                <td width="35"><img src="img/04.gif" width="35" height="23"></td>
              </tr>
            </table>
			
			<table  width="80%" border="0" cellpadding="0" cellspacing="0" class="bodytxt">
              <tr> 
                <td width="22" valign="top" background="img/tbl-left04.gif"><img src="img/tbl-left04.gif" width="22" height="13"></td>
                <td valign="top" align="center"> <br>

		<form name="form1" method="post" action=""  onSubmit="return checkform();">
		<input type="hidden" name="aid" value="<?=$_GET['edit']?>">
                 <table width="80%" border="0" cellspacing="1" cellpadding="1">
					<tr> 
						  <td width="66%">&nbsp;</td>
						  <td width="34%">&nbsp;</td>
					</tr>
									
                    <tr>
					
                      	<td >User :</td>
					   <td><input type="text" name="adname" value="<?=$adminrow['uname']?>" /></td>
                   </tr>
				   
                    <tr>
                     	 <td>Email :</td>
                      	<td><input type="text" name="ademail" value="<?=$adminrow['email']?>" /></td>
                    </tr>
					
                    <tr>
                     	 <td>Password :</td>
                      	<td><input type="password" name="password" value="<?=$adminrow['pwd']?>" />
                      	</td>
                    </tr>
					<tr >
					  <td  height="20">Subadmin Type:</td>
					 
					  <td><select name="subadmin_type" >
					  <option value="0">--Select Subadmin Type--</option>
					   <?   $sql_chk="select type from admin_type where type!='superadmin'";
     						$res_chk=mysql_query($sql_chk);
							while($type_admin=mysql_fetch_array($res_chk))
							{
					  if($type_admin['type']==$adminrow['type']){
					     echo   '<option  value="'.$type_admin[type].'" selected>'.$type_admin[type].' </option>';
						 }else{
						 echo   '<option  value="'.$type_admin[type].'">'.$type_admin[type].' </option>';
						 }
						 }
					  ?>
					  
					  </select></td>
                        </tr>
					
                     
                    <tr> <? if($_GET['edit']!=''){?>
                      <td align="center" colspan="2">
					 
					   <input type="submit"  name="edit_subadmin" value="Update Subadmin"  /></td>
					  <? }else{?>
					    <td align="center" colspan="2">
					  <input type="submit"  name="add_subadmin" value="Add Subadmin"  /></td>
					  <td><input type="reset" name="cancel" value="cancel"  /></td>
					  <? }?>
                      
                   	 </tr>
                  	</table>
     	 </form>
 				 </td>
<td width="19" valign="top" background="img/tbl-right04.gif"><img src="img/tbl-right04.gif" width="19" height="9">												</td>
              </tr>
            </table>
			
			 <table width="80%" border="0" cellpadding="0" cellspacing="0" class="bodytxt">
              <tr> 
                <td width="33"><img src="img/tbl-bot01.gif" width="33" height="12"></td>
                <td align="right" background="img/tbl-bg.gif"><img src="img/tbl-right05.gif" width="35" height="12"></td>
              </tr>
            </table>


<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::center ends:::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::footer starts:::::::::::::::::::::::::::::::::::::::::::::::::::::-->
</div></div>
<div class="bottom_links_show"><? include("footer.php");	?></div>
</div>
<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::footer ends:::::::::::::::::::::::::::::::::::::::::::::::::::::-->
</body>
</html>
