<?php 
	if(isset($_GET['id'])){$staffId = $_GET['id'];}
?>
<div class="right_col" role="main">
    <div class="">
        <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
					<div class="x_title">
						<h2>New Staff</h2>
						<div class="clearfix"></div>
					</div>
					<div class="x_content">
						<form class="form-horizontal form-label-left" method="post">
							
							<div class="form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12">Full Name</label>
								<div class="col-md-4 col-sm-3 col-xs-12">
									<input id="name" class="form-control col-md-7 col-xs-12" name="fullName" type="text" value="<?php if(isset($_GET['id'])){echo getDetailByTable('staffs',$staffId)['s_fullname'];} ?>">
							    </div>
							</div>
							
							<div class="form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12">Nickname</label>
								<div class="col-md-4 col-sm-3 col-xs-12">
									<input id="name" class="form-control col-md-7 col-xs-12" name="nickname" type="text" value="<?php if(isset($_GET['id'])){echo getDetailByTable('staffs',$staffId)['s_nickname'];} ?>">
							    </div>
							</div>
							
							<div class="form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12">Name Code</label>
								<div class="col-md-4 col-sm-3 col-xs-12">
									<input id="name" class="form-control col-md-7 col-xs-12" name="nameCode" type="text" value="<?php if(isset($_GET['id'])){echo getDetailByTable('staffs',$staffId)['s_namecode'];} ?>">
							    </div>
							</div>
							
							<div class="form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12">Username</label>
								<div class="col-md-4 col-sm-3 col-xs-12">
									<input id="name" class="form-control col-md-7 col-xs-12" name="username" type="text" value="<?php if(isset($_GET['id'])){echo getDetailByTable('staffs',$staffId)['s_username'];} ?>">
							    </div>
							</div>
							
							<div class="form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12">Password</label>
								<div class="col-md-4 col-sm-3 col-xs-12">
									<input id="name" class="form-control col-md-7 col-xs-12" name="password" type="password" value="<?php if(isset($_GET['id'])){echo getDetailByTable('staffs',$staffId)['s_password'];} ?>">
							    </div>
							</div>
							
							<div class="form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12">Contact</label>
								<div class="col-md-4 col-sm-3 col-xs-12">
									<input id="name" class="form-control col-md-7 col-xs-12" name="contact" type="text" value="<?php if(isset($_GET['id'])){echo getDetailByTable('staffs',$staffId)['s_contact'];} ?>">
							    </div>
							</div>
							
							<div class="form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12">E-Mail</label>
								<div class="col-md-4 col-sm-3 col-xs-12">
									<input id="name" class="form-control col-md-7 col-xs-12" name="email" type="text" value="<?php if(isset($_GET['id'])){echo getDetailByTable('staffs',$staffId)['s_email'];} ?>">
							    </div>
							</div>
							
							<div class="form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12">Authorization</label>
								<div class="col-md-4 col-sm-3 col-xs-12">
									<select class="form-control" name="auth">
										<!-- <option value="0">NONE</option> -->
										<?php foreach(authorizationType('ALL') as $item){ ?>
										<option value="<?php echo $item['id']; ?>" selected><?php echo $item['title']; ?></option>
										<?php } ?>
									</select>
								</div>
							</div>

							<div class="item form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12" for="note">Note</span>
								</label>
								<div class="col-md-4 col-sm-3 col-xs-12">
									<textarea id="message" class="form-control" name="note"><?php if(isset($_GET['id'])){echo getDetailByTable('staffs',$staffId)['s_note'];} ?></textarea>
								</div>
							</div>

							<div class="ln_solid"></div>

							<div class="form-group">
								<div class="col-md-6 col-md-offset-3">
									<button id="send" type="submit" class="btn btn-success" name="submit"><?php echo isset($_GET['id']) ? 'Update' : 'Add'; ?></button>
								</div>
							</div>

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



<?php 

	if(isset($_POST['submit'])){
		
		$postFullName = $_POST['fullName'];
		$postNickname = $_POST['nickname'];
		$postNameCode = $_POST['nameCode'];
		$postUsername = $_POST['username'];
		$postPassword = $_POST['password'];
		$contact = fixWhatsappNo($_POST['contact']);
		$email = $_POST['email'];
		$auth = $_POST['auth'];
		$note = $_POST['note'];
		
		//admin id
		$adminId = $_SESSION['admin']['a_id'];

		mysqli_query($conn, "INSERT INTO staffs (s_fullname, s_nickname, s_namecode, s_username, s_password, s_contact, s_email, s_authorization, s_note, a_id) VALUES ('$postFullName','$postNickname','$postNameCode','$postUsername','$postPassword','$contact','$email',$auth,'$note',$adminId)");

		header("Location: ?pagecontent=staffs");  
		//TELEGRAM NOTIFICATION
		$adminUsername = $_SESSION['admin']['a_username'];
		
$messaggio = "NEW STAFF ADDED by ".$adminUsername."

Name : ".$postFullName."
Nickname : ".$postNickname."
Name Code : ".$postNameCode."
Contact : ".$contact."
Email : ".$email."
Note : ".$note."

".$ipAddress;

sendMessage2(-550653212,$messaggio);
	}

?>