<?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, '/');
	

?>

<!DOCTYPE html>
<html lang="en">

<head>

	<title>Add New Staff</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">
                            Add New Staff
							<a href="manage-staff.php" class="btn btn-danger pull-right">Go Back</a>
                        </h1>
						
							<?php
								if ( isset($_POST["btnAddClient"]) ) {
									
									$password = $_POST["password"];
									$fullName = $_POST["firstname"].' '.$_POST["lastname"];
			
									// setting and saving
									$obj = new ParseUser();
									$obj->set( "firstname", $_POST["firstname"] );
									$obj->set( "lastname", $_POST["lastname"] );
									$obj->set( "username", $_POST["email"] );
									$obj->set( "email", $_POST["email"] );
									$obj->set( "emailVerified", false );
									$obj->set( "fullname", $fullName );
									$obj->set( "phoneNumber", $_POST["phoneNumber"] );
									$obj->set( "address", $_POST["address"] );
									$obj->set( "password", $password );
									$obj->set( "isClient", false);
									
									try {
									  $obj->signUp();
									  
									  ?>
							 <script>
								//alertify.alert('Successfully saved', 'Beacon Device save successfully!');
								alertify.alert('Successfully saved', 'New Staff has been added successfully.!', function(){
									//alertify.success('Ok'); 
									window.location = "manage-staff.php";
								});
							</script>
							<?php
							} catch (ParseException $ex) {  
									  // Execute any logic that should take place if the save fails.
									  // error is a ParseException object with an error code and message.
									  echo 'Failed to create new object, with error message: ' . $ex->getMessage();
									}
							 } 
							?>
						
						<div class="panel panel-default">
						  <div class="panel-heading">Add New Staff</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" placeholder="Type first name"  required data-error-msg="Please enter client 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" placeholder="Type last name" />
											</div>
											
											<div class="form-group">
												<label for="email"  class="form-label">Email Address</label>
												<input type="email"  class="form-control" id="email" name="email" placeholder="Type email address" required data-error-msg="Please enter client email address"/>
											</div>
											
											<div class="form-group">
												<label for="password"  class="form-label">Password</label>
												<input type="password"  class="form-control" id="password" name="password" placeholder="Type email address" required data-error-msg="Please enter client password"/>
											</div>
											
											<div class="form-group">
												<label for="phoneNumber"  class="form-label">Phone Number</label>
												<input type="text"  class="form-control" id="phoneNumber" name="phoneNumber" placeholder="Type phone number" />
											</div>
											
											<div class="form-group">
												<label for="address"  class="form-label">Address</label>
												<input type="text"  class="form-control" id="address" name="address" placeholder="Type address" />
											</div>
											
											<div class="form-group">
												<input type="submit"  class="btn btn-success" name="btnAddClient" value="Add New Staff" />
												 <input type="reset" class="btn btn-info" id="resetBtn" />
												<a href="manage-clients.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">
   
      $(document).ready(function(){
        $('#addClientDetails').attrvalidate();
        $('#resetBtn').click(function(){ 
			$('#addClientDetails').attrvalidate('reset'); 
		});
      });
    </script>

</body>

</html>
