<?php 
error_reporting(0);
session_start();
if(!isset($_SESSION['admin']) || ($_SESSION['admin'] == "") )
{
	?>
    <script language="javascript">window.location.href="index.php";</script>
    <?php 
}
include "config.php";
?><!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
 
<meta charset="utf-8">
<title>Admin Manage</title>
<meta name="author" content="pixelcave">
<meta name="robots" content="noindex, nofollow">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="shortcut icon" href="img/favicon.ico">
<link rel="apple-touch-icon" href="img/apple-touch-icon.png">
<link rel="apple-touch-icon" sizes="57x57" href="img/apple-touch-icon-57x57-precomposed.png">
<link rel="apple-touch-icon" sizes="72x72" href="img/apple-touch-icon-72x72-precomposed.png">
<link rel="apple-touch-icon" sizes="114x114" href="img/apple-touch-icon-114x114-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="img/apple-touch-icon-precomposed.png">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto:400,400italic,700,700italic">
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/plugins.css">
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/themes.css">
<script src="js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script>
</head>
<body>
<div id="page-container">

<?php include 'header.php' ?>

<div id="inner-container">

<?php include 'left_menu.php' ?>

<div id="page-content">
<ul id="nav-info" class="clearfix">
<li><a href="#"><i class="icon-home"></i></a></li>

<li class="active"><a href="">Admin Manage</a></li>
</ul>

<?php 

if ($_POST['submit']) 
{
	$username=$_REQUEST['username'];
	$password=$_REQUEST['password'];
    $email=$_REQUEST['email'];
	$emp_name=$_REQUEST['emp_name'];
	$contact=$_REQUEST['contact'];
	$address=$_REQUEST['address'];
	$utype=$_REQUEST['utype'];
	
	$status=$_REQUEST['status'];
	 
	//$utype=$_REQUEST['utype'];
//	$ure2=mysql_query("select * from  tbl_user_type_mst where ut_id='$utype'");
//	$urow2=mysql_fetch_array($ure2);
//	$ut_id=$urow2['ut_id'];
//	$User_Type=$urow2['User_Type']; 
////	exit();
	//$qer = "SELECT * FROM adminmaster WHERE username = '$username'";
	//		$b_result=mysql_query($qer) or die(mysql_error());
	//		$num = mysql_num_rows($b_result);
			
	//		if($num == 0) 
	//		{
			
	//		if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
	
//	echo "<script>alert('E-mail is not Validate');
//	}
	//else
//	{
    $sql="INSERT 
		INTO 
		adminmaster
		(username,password,emp_name,email,contact,address,ut_id,utype,status) 
		VALUES 
       ('$username','$password','$emp_name','$email','$contact','$address','$ut_id','$utype','$status')";
mysql_query($sql);
		 
 	?>
    <script language="javascript">window.location.href="admin_list.php";</script>
    <?php 
} 
$id = $_GET['reg'];
 if(isset($_REQUEST['up'])) 
  {  		 
$username=$_REQUEST['username'];
$password=$_REQUEST['password'];
$email=$_REQUEST['email'];
$emp_name=$_REQUEST['emp_name'];
$contact=$_REQUEST['contact'];
$address=$_REQUEST['address'];
$utype=$_REQUEST['utype'];

	//$utype=$_REQUEST['utype'];
//	$ure=mysql_query("select * from  tbl_user_type_mst where ut_id='$utype'");
//	$urow=mysql_fetch_array($ure);
//	$ut_id=$urow['ut_id'];
//	$User_Type=$urow['User_Type'];
	
	
$status=$_REQUEST['status'];
	
 //	$email=$_REQUEST['email'];
	//if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
	
//	echo "<script>alert('E-mail is not Validate');
//	}
//	else
//	{
	$uupQry="UPDATE adminmaster SET username='$username',password='$password',email='$email',emp_name='$emp_name',contact='$contact',address='$address',ut_id='$ut_id',utype='$utype',status='$status' WHERE adminid='$id'";
	$uuresult=mysql_query($uupQry);
	?>
    <script language="javascript">window.location.href="admin_list.php";</script>
    <?php 
  
  } //}
  
   ?>
   	  <button id="addRow" class="btn btn-success" onClick="location.href = 'admin_list.php';">&nbsp;View Admin List</button>
      
      <?php 
		$ure=mysql_query("select * from adminmaster where adminid = '$id'");
		$urow=mysql_fetch_array($ure);
		?>
         
         
<form id="form-validation"  method="post" name="form" class="form-horizontal form-box remove-margin">

<div class="form-box-content">
<div class="control-group">
<label class="control-label" for="val_password">Username *&nbsp;</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-user"></i></span>
<input type="text" required id="" name="username" value="<?php echo $urow['username']; ?>">
</div>

<div class="input-prepend">
<label class="control-label" for="val_password">Password *&nbsp;</label>
<span class="add-on"><i class="icon-asterisk"></i></span><input type="text" id="" name="password" value="<?php echo $urow['password']; ?>">

</div>
</div>
</div>



<div class="control-group">
<label class="control-label" for="val_password">Emp Name&nbsp;&nbsp;</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-user"></i></span>
<input type="text" required id="" name="emp_name" value="<?php echo $urow['emp_name']; ?>">

</div>

<div class="input-prepend">
<label class="control-label" for="val_password"> Email * &nbsp;</label>
<span class="add-on"><i class="icon-envelope"></i></span>
<input type="text" id="" name="email" value="<?php echo $urow['email']; ?>">
</div>
</div>
</div>
<div class="control-group">
<label class="control-label" for="val_password">Address: &nbsp;&nbsp;</label>
<div class="controls">
<div class="input-prepend" style="width:280px;">
<textarea id="" name="address"><?php echo $urow['address']; ?></textarea>
</div>
<div class="input-prepend">
<label class="control-label" for="val_password"> Contact  &nbsp;</label>
<span class="add-on"><i class="icon-asterisk"></i></span>
<input type="text" id="" name="contact" value="<?php echo $urow['contact']; ?>">
</div>
</div>
</div>

<div class="control-group">
<label class="control-label" for="val_password">Status &nbsp;&nbsp;</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-asterisk"></i></span>



<select id="val_skill" name="status">
<option value="Enable" <?php if($urow['status'] == "Enable") echo 'selected="selected"';?>>Enable</option>
							<option value="Disable" <?php if($urow['status'] == "Disable") echo 'selected="selected"';?>>Disable	</option>
                            </select>

</div>
<div class="input-prepend">
<label class="control-label" for="val_password"> Utype  &nbsp;</label>
<span class="add-on"><i class="icon-asterisk"></i></span>
<select id="val_skill" name="utype">
<option value="">Select Type</option>
<option value="Succ-Director" <?php if($urow['utype'] == "Succ-Director") echo 'selected="selected"';?>>Succ-Director</option>
<option value="Succ-Employee" <?php if($urow['utype'] == "Succ-Employee") echo 'selected="selected"';?>>Succ-Employee	</option>
<option value="HK-Director" <?php if($urow['utype'] == "HK-Director") echo 'selected="selected"';?>>HK-Director	</option>
<option value="HK-Employee" <?php if($urow['utype'] == "HK-Employee") echo 'selected="selected"';?>>HK-Employee	</option>
                            </select>
<?php /*?><select id="val_skill" name="utype" required>
 <option value="">Select User Type</option>
 
  <?php 
		$ure1=mysql_query("SELECT * FROM tbl_user_type_mst ");		
		while($urow11=mysql_fetch_array($ure1)) 
		{
	?>
             <option value="<?php echo $inq_cat_id=$urow11['ut_id']; ?>" <?php if($urow['ut_id'] == $urow11['ut_id']) echo 'selected="selected"'?>><?php  echo $category_name=$urow11['User_Type']; ?></option>
			 
                        <?php } ?>
                      </select><?php */?>





</div>
</div>
</div>








<?php /*?><div class="control-group">
<label class="control-label" for="val_username">Username *&nbsp;</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-user"></i></span>
<input type="text" id="val_username" name="username" value="<?php echo $urow['username']; ?>">
</div>
</div>
</div><?php */?>

<?php /*?><div class="control-group">
<label class="control-label" for="val_password">Password *&nbsp;</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-asterisk"></i></span>
<input type="password" id="val_password" name="password" value="<?php echo $urow['password']; ?>">
</div>
</div>
</div><?php */?>
<?php /*?><div class="control-group">
<label class="control-label" for="val_email">Email *&nbsp;</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-envelope"></i></span>
<input type="text" id="val_email" name="email" value="<?php echo $urow['email']; ?>">
</div>
</div>
</div><?php */?>
<?php /*?><div class="control-group">
<label class="control-label" for="val_username">Employee Name *&nbsp;</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-user"></i></span>
<input type="text" id="val_username" name="emp_name" value="<?php echo $urow['emp_name']; ?>">
</div>
</div>
</div><?php */?>


<?php /*?><div class="control-group">
<label class="control-label" for="val_username">Contact *&nbsp;</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-user"></i></span>
<input type="text" id="val_username" name="contact" value="<?php echo $urow['contact']; ?>">
</div>
</div>
</div><?php */?>



<?php /*?><div class="control-group">
            <label class="control-label" for="val_username">Address &nbsp;&nbsp;</label>
            <div class="controls">
              <div class="input-prepend">
			  <!--<span class="add-on"><i class="icon-home"></i></span>-->
                <textarea id="" name="address"><?php echo $urow['address']; ?></textarea>
              </div>
            </div>
          </div><?php */?>

<?php /*?><div class="control-group">
<label class="control-label" for="val_skill">Status *</label>
<div class="controls">
<select id="val_skill" name="status">
<option value="Enable" <?php if($urow['status'] == "Enable") echo 'selected="selected"';?>>Enable</option>
							<option value="Disable" <?php if($urow['status'] == "Disable") echo 'selected="selected"';?>>Disable	</option>
                            </select>
</div>
</div><?php */?>


<?php /*?><div class="control-group">
<label class="control-label" for="val_skill">utype *</label>
<div class="controls">
<select id="val_skill" name="utype">
<option value="Employee" <?php if($urow['utype'] == "Employee") echo 'selected="selected"';?>>Employee</option>
							<option value="Admin" <?php if($urow['utype'] == "Admin") echo 'selected="selected"';?>>Admin	</option>
                            </select>
</div>
</div>
<?php */?>

<!--<div class="control-group">
<label class="control-label" for="val_confirm_password">Retype Password *</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-asterisk"></i></span>
<input type="password" id="val_confirm_password" name="cpassword">
</div>
</div>
</div>-->

<div class="form-actions">
<?php
					 
                        if($id)
						{
						?>
<input type="submit" name="up" value="Update Admin" class="btn btn-success"> 	
<?php 
}
else 
{

?>
<input type="submit" name="submit" value="Add New Admin" class="btn btn-success"> 
<?php } ?>


<button type="reset" class="btn btn-danger"><i class="icon-repeat"></i> Reset</button>
</div>
</div>
</form>
</div>


<?php include 'footer.php' ?>

</div>
</div>

<?php include 'profile_popup.php' ?>


<!--[if lte IE 8]><script src="js/helpers/excanvas.min.js"></script><![endif]-->
<script src="js/jquery.min.js"></script>
<script>!window.jQuery && document.write(unescape('%3Cscript src="js/vendor/jquery-1.9.1.min.js"%3E%3C/script%3E'));</script>
<script src="js/vendor/bootstrap.min.js"></script>
<script src="js/plugins.js"></script>
<script src="js/main.js"></script><script>$(function(){$("#form-validation").validate({errorClass:"help-block text-error",errorElement:"span",errorPlacement:function(t,e){e.parents(".controls").append(t)},highlight:function(t){$(t).closest(".control-group").removeClass("success error").addClass("error")},success:function(t){t.addClass("valid").closest(".control-group").removeClass("success error").addClass("success"),t.closest(".help-inline").remove(),t.closest(".help-block").remove()},rules:{val_username:{required:!0,minlength:2},val_password:{required:!0,minlength:5},val_confirm_password:{required:!0,minlength:5,equalTo:"#val_password"},val_email:{required:!0,email:!0},val_website:{required:!0,url:!0},val_date:{required:!0,date:!0},val_range:{required:!0,range:[1,100]},val_number:{required:!0,number:!0},val_digits:{required:!0,digits:!0},val_skill:{required:!0},val_credit_card:{required:!0,creditcard:!0},val_terms:{required:!0}},messages:{val_username:{required:"Please enter a username",minlength:"Your username must consist of at least 2 characters"},val_password:{required:"Please provide a password",minlength:"Your password must be at least 5 characters long"},val_confirm_password:{required:"Please provide a password",minlength:"Your password must be at least 5 characters long",equalTo:"Please enter the same password as above"},val_email:"Please enter a valid email address",val_website:"Please enter your website!",val_date:"Please select a date!",val_range:"Please enter a number between 1 and 100!",val_number:"Please enter a number!",val_digits:"Please enter digits!",val_credit_card:"Please enter a valid credit card!",val_skill:"Please select a skill!",val_terms:"You must agree to the terms!"}})});</script>


</body>
</html>
