<?php
	require 'autoload.php';
	use Parse\ParseClient;
	use Parse\ParseObject;
	use Parse\ParseQuery;
	use Parse\ParseACL;
	use Parse\ParsePush;
	use Parse\ParseUser;
	use Parse\ParseInstallation;
	use Parse\ParseException;
	use Parse\ParseAnalytics;
	use Parse\ParseFile;
	use Parse\ParseCloud;
	
	include 'includes/func.php';
	include 'config.php';
	
	ParseClient::initialize($ApplicationID, $RestAPIKEY, $MasterKey);
	ParseClient::setServerURL($serverURLB4APP, '/');

	
	if(!empty($_SESSION['id'])){
		$AdminUsersID = $_SESSION['id'];	

		$objAdminUsers = new ParseQuery("admin");
		$objAdminUsers->get($AdminUsersID);
		$result = $objAdminUsers->find();
		
		$firstName = "";
		$lastName = "";
		$email = "";
		$password = "";
		$shopName = "";
		
	//get Data
	foreach($result as $key){		
		$shopName = $key->get('shop_name');
		$firstName = $key->get('first_name');
		$lastName = $key->get('last_name');
		$email = $key->get('email');
		$password = $key->get('password');			
	}	
}else{
	header('Location:login.php');
		exit;
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Edit Profile</title>
<!DOCTYPE html>
<html lang="en">
<head>
	<title>Add New Beacons</title>
	<?php include 'includes/head.php'; ?>
</head>
<body>
    <div id="wrapper">
        <?php include 'includes/header.php';?>
        <div id="page-wrapper">
          <div class="container-fluid">
                <div class="row">
					<div class="col-lg-12">
                         <h1 class="page-header">
                            Update <?php echo '<b>'.$firstName.' '.$lastName.'</b>'; ?>
							<a href="manage-admin.php" class="btn btn-danger pull-right">Go Back</a>
                        </h1>
						
							<?php
								if(isset($_POST["btnUpdateAdmin"]) ) {
									$objAdminUsers = new ParseObject("admin", $AdminUsersID);	
									$objAdminUsers->set( "shop_name", $_POST["shopName"] );
									$objAdminUsers->set( "first_name", $_POST["firstName"] );
									$objAdminUsers->set( "last_name", $_POST["lastName"]);
									$objAdminUsers->set( "email", $_POST["email"]);
									if($_POST["password"] != ""){
										$password = md5($_POST["password"]);
										$objAdminUsers->set( "password", $password);
									}
									$objAdminUsers->save();
									$_SESSION["email"] = $_POST["email"];	
									$_SESSION["fullname"] = $_POST["firstName"].' '.$_POST["lastName"];
									$_SESSION["shop_name"] = $_POST["shopName"];	
							 ?>
							 <script>
								//alertify.alert('Successfully saved', 'Beacon Device save successfully!');
								alertify.alert('Successfully updated', 'Profile has been edit successfully.!', function(){
									window.location = "index.php";
								});
							</script>
							<?php }?>
						
						<div class="panel panel-default">
						  <div class="panel-heading">Edit Profile details</div>
						  <div class="panel-body">
								<div class="row">
									<div class="col-md-6">
										<form method="post" >
											
											
											<div class="form-group">
												<label for="firstName" class="form-label">First Name</label>
												<input type="text" class="form-control" id="firstName" name="firstName" value="<?php echo $firstName; ?>" placeholder="Enter admin first name"  required data-error-msg="Please enter admin first name"  />
											</div>
											
											<div class="form-group">
												<label for="lastName" class="form-label">Last Name</label>
												<input type="text" class="form-control" id="lastName" name="lastName" value="<?php echo $lastName; ?>" placeholder="Enter admin last name"    />
											</div>
											<div class="form-group">
												<label for="email" class="form-label">Email</label>
												<input type="email" class="form-control" id="email" name="email" value="<?php echo $email; ?>" placeholder="Enter admin email"  required data-error-msg="Please enter admin email"  />
											</div>
											<div class="form-group">
												<label for="shopName" class="form-label">Phone Number</label>
												<input type="text" class="form-control" id="shopName" name="shopName" value="<?php echo $shopName; ?>" placeholder="Enter shop name"  />
											</div>
											<div class="form-group">
												<label for="password" class="form-label">Password</label>
												<input type="password" class="form-control" id="password" name="password"  placeholder="Enter admin password"data-error-msg="Please enter admin password"  />
											</div>
											<div class="form-group">
												<input type="submit"  class="btn btn-success" name="btnUpdateAdmin" value="Update" />
												 <input type="reset" class="btn btn-info" id="resetBtn" />
												<a href="manage-admin.php" class="btn btn-danger">Cancel</a>
											</div>
										</form>
									</div>
								</div>
						  </div>
						</div>
                    </div>
                </div>
                <!-- /.row -->
            </div>
            <!-- /.container-fluid -->
        </div>
        <!-- /#page-wrapper -->
    </div>
    <!-- /#wrapper -->
   <?php include 'includes/footer.php';?>  
    <script type="text/javascript">
	
	</script>
</body>

</html>