BBnepal-Accounts/application/views/admin/add-edit-staff.php

356 lines
18 KiB
PHP
Raw Normal View History

2024-07-10 12:43:19 +00:00
<link rel="stylesheet" href="<?php echo base_url(); ?>assets_admin/css/bootstrap-select.css">
<style type="text/css">
.error {
color: red;
}
</style>
<div class="wraper responsive-width">
<main class="" id="main">
<div class="from-group">
<a href="<?= base_url(); ?>admin/teacher"><button type="button" class="btn btn-success btn-sm btn-dark">Back</button></a>
</div>
<div class="admin_tempblock">
<div class="admin_tempsec">
<div class="admin_sec">
<div class="subsec_sec">
<div class="subject_l">
<div class="subject_lsec">
<div class="subject_lhead">
<?php if ($tid == 0) {
echo 'Add Staff';
} else {
echo 'Update Staff';
} ?></div>
<?php
// echo '<pre>';
// echo var_dump($assign_subjects);
$uname = '';
$name = '';
$email = '';
$mobile = '';
$address = '';
$img = '';
$passwd = '';
$csubject = '';
if (isset($detail)) {
// print_r($detail);
$uname = $detail['teacherId'];
$name = $detail['teacher_name'];
$email = $detail['email'];
$mobile = $detail['mobile'];
$address = $detail['address'];
$filePath = 'assets_admin/images/teacher-profile/' . $detail['photo'];
if (file_exists($filePath)) {
$img = base_url() . 'assets_admin/images/teacher-profile/' . $detail['photo'];
} else {
$img = base_url() . 'common_assets/No-Image.jpg';
}
$passwd = base64_decode($detail['password']);
}
?>
<form id="teacherform" method="post" action="<?php echo base_url(); ?>Admin/addedit_teacher" enctype="multipart/form-data">
<input type="hidden" name="tid" id="tid" value="<?= $tid; ?>">
<div class="subject_lformarea">
<?php //print_r($detail);
if (isset($detail)) { ?>
<div class="form-group">
<label for="">Staff Id</label>
<input type="text" name="uname" id="uname" class="form-control" value="<?= $uname; ?>" readonly placeholder="Enter User name">
<p id="uname_error" style="color:red;"></p>
</div>
<?php } ?>
<div class="row">
<div class="col">
<div class="form-group assign_subject">
<label>Assign Designation</label>
<select name="designation" id="designation" class="selectpicker" data-live-search="true">
<option value="0">Select Designation</option>
<?php
if (isset($hr_designation) && !empty($hr_designation)) {
foreach ($hr_designation as $designation) {
// if ($assign_subjects)
?>
<option value="<?php echo $designation['id']; ?>" <?= (isset($detail) && ($detail['designation'] == $designation['id'])) ? 'selected' : '' ?>>
<?php echo $designation['title']; ?>
</option>
<?php
}
}
?>
</select>
<label id="designation-error" class="error" for="designation"></label>
</div>
</div>
<div class="col">
<div class="form-group assign_subject">
<label>Assign Role</label>
<select name="role" id="role" class="selectpicker" data-live-search="true" required>
<option value="">
Select Role
</option>
<?php
if (isset($hr_roles) && !empty($hr_roles)) {
foreach ($hr_roles as $role) {
?>
<option value="<?php echo str_replace(' ', '_', strtolower($role['title'])); ?>" <?= (isset($detail) && ($detail['role'] == str_replace(' ', '_', strtolower($role['title'])))) ? 'selected' : '' ?>>
<?php echo $role['title']; ?>
</option>
<?php
}
}
?>
</select>
</div>
</div>
</div>
<div class="form-group">
<label for="">Full Name</label>
<input type="text" name="tname" id="tname" class="form-control" value="<?= $name; ?>" placeholder="Enter Staff name">
<p id="tname_error" style="color:red;"></p>
</div>
<div class="form-group">
<label for="">Email</label>
<input type="text" name="temail" id="temail" class="form-control" value="<?= $email; ?>" placeholder="Enter email address">
<p id="temail_error" style="color:red;"></p>
<p id="exists_error" style="color:red;"></p>
</div>
<div class="form-group">
<label for="">Mobile</label>
<input type="text" name="tmobile" id="tmobile" class="form-control" maxlength="10" value="<?= $mobile; ?>" placeholder="Enter mobile number">
<p id="tmobile_error" style="color:red;"></p>
</div>
</div>
<div class="form-group">
<label for="">Address</label>
<textarea type="text" name="taddress" id="taddress" rows="5" maxlength="300" class="form-control" placeholder="Enter address"><?= $address; ?></textarea>
<p id="taddress_error" style="color:red;"></p>
</div>
<div class="form-group">
<label for="">Password</label>
<div class="password-wrp">
<input type="password" name="tpassword" id="tpassword" class="form-control" value="<?= $passwd; ?>" placeholder="Enter password">
<div class="passwrd-icon sdfsd icon-y"><i class="far fa-eye"></i></div>
</div>
<p id="tpassword_error" style="color:red;"></p>
</div>
<label for="">Profile Picture <span style="font-size:13px">(gif, jpg, jpeg, png, jiff, jfif)</span></label>
<div class="upload-doc upload-doc-img">
<input type="file" onchange="readURL(this);" name="file" id="tpic" class="form-control">
<?php if (empty($img)) { ?>
<label for="tpic" class="upload-btn" id="uploadBtn">Upload image</label>
<?php } ?>
<?php if (!empty($img)) { ?>
<label for="tpic" class="upload-btn" id="uploadBtn">Re-Upload image</label>
<img src="<?= $img; ?>" alt="Profile Picture" width="50px;" height="50px;">
<?php } ?>
<p id="tpic_error" style="color:red;"></p>
<p id="success" style="color:green;"></p>
</div>
<div class="form-group assign_subject">
<label>Assign Subject*</label>
<select name="csubject[]" id="csubject" class="selectpicker" multiple data-live-search="true">
<?php
if (isset($subject_list) && !empty($subject_list)) {
foreach ($subject_list as $allSub) {
if ($assign_subjects)
?>
<option value="<?php echo $allSub['id']; ?>" <?php if (in_array($allSub['id'], $assign_subjects)) { ?>selected<?php } ?>>
<?php echo $allSub['subject_name']; ?>
</option>
<?php
}
}
?>
</select>
<label id="csubject-error" class="error" for="csubject"></label>
</div>
<button type="submit" class="subject_addbtn"><?php if ($tid == 0) {
echo 'Add Staff';
} else {
echo 'Update Staff';
} ?>
</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</main>
</div>
<script defer src="<?php echo base_url(); ?>assets_admin/js/bootstrap-select.min.js"></script>
<script>
$(document).ready(function() {
//multiple select js start
$('select').selectpicker();
//multiple select js end
});
</script>
<script type="text/javascript">
//PASSWORD-HIDE/SHOW
$(".sdfsd").click(function() {
var input = $("#tpassword");
if (input.attr("type") == "password") {
input.attr("type", "text");
$(".passwrd-icon").removeClass("icon-y");
} else {
input.attr("type", "password");
$(".passwrd-icon").addClass("icon-y");
}
});
function hide_all_teacher_error() {
// $('#uname_error').hide();
$('#tname_error').hide();
$('#temail_error').hide();
$('#tmobile_error').hide();
$('#csubject_error').hide();
$('#taddress_error').hide();
$('#tpic_error').hide();
$('#tpassword_error').hide();
$('#success').html('');
}
function cleanup_teacher_val() {
// $('#uname').val('');
$('#tname').val('');
$('#temail').val('');
$('#tmobile').val('');
$('#csubject').select('');
$('#taddress').val('');
$('#tpic').val('');
$('#tpassword').val('');
$('#exists_error').html('');
}
$(document).ready(function() {
jQuery.validator.addMethod("fullnameregex", function(value, element) {
return this.optional(element) || /^[a-zA-Z ]{3,30}$/.test(value);
}, 'Please enter alpha characters only ');
jQuery.validator.addMethod("passwordregex", function(value, element) {
return this.optional(element) || /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$#!%*?&])[A-Za-z\d@$#!%*?&]{6,16}$/.test(value);
}, 'Your password must be atleast 6 characters long, which inculdes one upper case, one numerical value and one special character.');
jQuery.validator.addMethod("emailregex", function(value, element) {
return this.optional(element) || /^[a-zA-Z0-9._-]+@[a-zA-Z-]+\.[a-zA-Z.]{2,5}$/.test(value);
}, 'Email Address is invalid: Please enter a valid email address.');
jQuery.validator.addMethod("phonenumberregex", function(value, element) {
return this.optional(element) || /^[0-9]{10,12}$/.test(value);
}, 'Please enter a 10 digits vaild phone number.');
jQuery.validator.addMethod("zipregex", function(value, element) {
return this.optional(element) || /^[0-9]{6}$/.test(value);
}, 'Please enter 6 digits number: digits only allowed');
jQuery.validator.addMethod("genral_regex", function(value, element) {
return this.optional(element) || /^[a-zA-Z -#]{1,50}$/.test(value);
}, 'Please enter alpha characters only');
$("#teacherform").validate({
// ignore: "input[type='text']:hidden",
rules: {
tname: {
required: true,
rangelength: [2, 50],
fullnameregex: true
},
temail: {
required: true,
emailregex: true
},
tmobile: {
required: true,
phonenumberregex: true
},
taddress: {
required: true
},
tpassword: {
required: true,
passwordregex: true
},
file: {
required: function(element) {
var name = $('#uploadBtn').text();
if (name == 'Upload image') {
return true;
} else {
return false;
}
}
},
'csubject[]': {
required: true
},
},
messages: {
tname: {
required: "Please Enter Name "
},
file: {
required: "Please add image"
},
csubject: {
required: "Please select Subject"
},
taddress: {
required: "Please add Address"
},
},
submitHandler: function(form) {
form.submit();
}
});
});
function readURL(input) {
let fileSize = input.files[0].size;
extension = $(input).val().split('.').pop().toLowerCase();
var fileExtension = ['jfif', 'jpeg', 'jpg', 'png', 'gif', 'jiff'];
if ($.inArray($(input).val().split('.').pop().toLowerCase(), fileExtension) == -1) {
alert("Only formats are allowed : " + fileExtension.join(', '));
input.value = '';
return;
}
}
</script>