File "employeeRegistration.php"
Full Path: /home/krishnamexports/public_html/panel/pages/sub_category/employeeRegistration.php
File size: 11.36 KB
MIME-type: text/x-php; charset=us-ascii
Charset: utf-8
<?php
if(isset($_POST['add']))
{
$name = mysqli_real_escape_string($cn,$_POST['name']);
$mobile = mysqli_real_escape_string($cn,$_POST['mobile']);
$email = mysqli_real_escape_string($cn,$_POST['email']);
$designation_id = $_POST['designation_id'];
$state_id = $_POST['state_id'];
$city_id = $_POST['city_id'];
$dob = date('Y-m-d',strtotime($_POST['dob']));
$doj = date('Y-m-d',strtotime($_POST['doj']));
$password = encryptIt($_POST['password']);
$salary = $_POST['salary'];
$address = mysqli_real_escape_string($cn,$_POST['address']);
$sql = mysqli_query($cn, "select * from `tbl_employee` where mobile='$mobile'");
if(mysqli_num_rows($sql)==0)
{
$sqlSubject = mysqli_query($cn, "insert into `tbl_employee` set `name`='$name', `mobile`='$mobile', `email`='$email', `designation_id`='$designation_id', `address`='$address', `dob`='$dob', `doj`='$doj', `state_id`='$state_id', `city_id`='$city_id', `password`='$password', `salary`='$salary', `date`=Now()");
if ($sqlSubject){
$employee_id = mysqli_insert_id($cn);
mysqli_query($cn, "insert into `tbl_permission` set `employee_id`='$employee_id'");
echo '<div class="alert alert-success"><strong>Success!</strong> Employee Added Successfully.</div>';
}
else
{
echo '<div class="alert alert-danger"><strong>Danger!</strong> Employee Not Added. Try Again.</div>';
}
}
else
{
echo '<div class="alert alert-danger"><strong>Danger!</strong> This Mobile Already Registred.</div>';
}
}
if(isset($_POST['edit']))
{
$edit_id = $_POST['edit_id'];
$name = mysqli_real_escape_string($cn,$_POST['name']);
$mobile = mysqli_real_escape_string($cn,$_POST['mobile']);
$email = mysqli_real_escape_string($cn,$_POST['email']);
$designation_id = $_POST['designation_id'];
$state_id = $_POST['state_id'];
$city_id = $_POST['city_id'];
$dob = date('Y-m-d',strtotime($_POST['dob']));
$doj = date('Y-m-d',strtotime($_POST['doj']));
$password = encryptIt($_POST['password']);
$salary = $_POST['salary'];
$address = mysqli_real_escape_string($cn,$_POST['address']);
$sqlSubject = mysqli_query($cn, "update `tbl_employee` set `name`='$name', `mobile`='$mobile', `email`='$email', `designation_id`='$designation_id', `address`='$address', `dob`='$dob', `doj`='$doj', `state_id`='$state_id', `city_id`='$city_id', `password`='$password', `salary`='$salary' where `id`='".$edit_id."'");
if ($sqlSubject){
echo '<div class="alert alert-success"><strong>Success!</strong> Employee Update Successfully.</div>';
}
else
{
echo '<div class="alert alert-danger"><strong>Danger!</strong> Employee Not Added. Try Again.</div>';
}
}
if(isset($_GET['edit_id']))
{
$id = $_GET['edit_id'];
$sql = mysqli_query($cn, "select * from `tbl_employee` where id='$id'");
$sqlData = mysqli_fetch_array ($sql);
}
if(isset($_GET['delete_id']))
{
$id = $_GET['delete_id'];
$sql = mysqli_query($cn, "update `tbl_employee` SET `status`=0 where id='$id'");
}
?>
<div class="col-md-12">
<div class="card">
<div class="card-body">
<h4 class="card-title"><?php if(isset($_GET['edit_id'])){ echo "Edit Employee Registation";}else{ echo "Employee Registation";}?></h4>
<form class="forms-sample" method="post" enctype="multipart/form-data">
<div class="row">
<div class="col-md-3">
<div class="form-group">
<label for="exampleInputCity1">Employee Name</label>
<input type="hidden" name="edit_id" value="<?php if(isset($_GET['edit_id'])) {echo $sqlData['id'];}?>">
<input type="text" class="form-control" name="name" value="<?php if(isset($_GET['edit_id'])) { echo $sqlData['name'];}?>" placeholder="Employee Name" required>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label for="exampleInputCity1">Mobile No.</label>
<input type="text" class="form-control" name="mobile" value="<?php if(isset($_GET['edit_id'])) { echo $sqlData['mobile'];}?>" placeholder="Mobile" required>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label for="exampleInputCity1">Email</label>
<input type="text" class="form-control" name="email" value="<?php if(isset($_GET['edit_id'])) { echo $sqlData['email'];}?>" placeholder="Email" required>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label for="exampleInputCity1">Desination </label>
<select class="form-control" name="designation_id" >
<option value="">Select Designation</option>
<?php
$sqlCategory = mysqli_query($cn, "select * from `tbl_designation` where `status`=1 and `id` NOT IN(2,3,4)");
while($sqlCategoryData = mysqli_fetch_array($sqlCategory)){?>
<option value="<?php echo $sqlCategoryData['id'];?>" <?php if(isset($_GET['edit_id'])){ if($sqlData['designation_id']==$sqlCategoryData['id']){ echo "selected";}}?>><?php echo $sqlCategoryData['name'];?></option>
<?php }?>
</select>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label for="exampleInputCity1">D.O.B</label>
<input type="text" class="form-control" id="datepicker1" name="dob" value="<?php if(isset($_GET['edit_id'])) { echo date('d-m-Y',strtotime($sqlData['dob']));}?>" placeholder="Date of Birth" required>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label for="exampleInputCity1">D.O.J</label>
<input type="text" class="form-control" id="datepicker2" name="doj" value="<?php if(isset($_GET['edit_id'])) { echo date('d-m-Y',strtotime($sqlData['doj']));}?>" placeholder="Date of Joining" required>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label for="exampleInputCity1">State </label>
<select class="form-control" onchange="getState(this.value);" name="state_id" required>
<option value="">Select State</option>
<?php
$sqlState = mysqli_query($cn, "select * from `tbl_state` order by `name`");
while($sqlStateData = mysqli_fetch_array($sqlState)){?>
<option value="<?php echo $sqlStateData['id'];?>" <?php if(isset($_GET['edit_id'])){ if($sqlData['state_id']==$sqlStateData['id']){ echo "selected";}}?>><?php echo $sqlStateData['name'];?></option>
<?php }?>
</select>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label for="exampleInputCity1">City </label>
<select class="form-control" id="city_id" name="city_id" required>
<option value="">Select City</option>
<?php
if(isset($_GET['edit_id'])){
$sqlCity = mysqli_query($cn,"select * from `tbl_city` where `parent_id`='".$sqlData['state_id']."' order by `name`");
while($sqlCityData = mysqli_fetch_array($sqlCity)){?>
<option value="<?php echo $sqlCityData['id'];?>" <?php if($sqlData['city_id']==$sqlCityData['id']){ echo "selected";}?>><?php echo $sqlCityData['name'];?></option>
<?php }}?>
</select>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label for="exampleInputCity1">Password</label>
<input type="text" class="form-control" name="password" value="<?php if(isset($_GET['edit_id'])) { echo decryptIt($sqlData['password']);}?>" placeholder="Password" required>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label for="exampleInputCity1">Current Salary</label>
<input type="text" class="form-control" name="salary" value="<?php if(isset($_GET['edit_id'])) { echo $sqlData['salary'];}?>" placeholder="Current Salary" required>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="exampleInputCity1">Address</label>
<textarea class="form-control" name="address" placeholder="Employee Address" required><?php if(isset($_GET['edit_id'])) {echo $sqlData['address'];}?></textarea>
</div>
</div>
</div>
<button type="submit" class="btn btn-success mr-2" name="<?php if(isset($_GET['edit_id'])) {echo "edit";}else{ echo "add";}?>">Submit</button>
</form>
</div>
</div>
</div>