BBnepal-Accounts/application/views/admin/ae_course.php
Sampanna Rimal 9cd05ef3cb commitall
2024-07-10 18:28:19 +05:45

251 lines
8.4 KiB
PHP

<link rel="stylesheet" href="<?php echo base_url(); ?>assets_admin/css/bootstrap-select.css">
<style>
form label.error, #secNameerr {
color : red;
}
</style>
<main class="wraper responsive-width" id="main">
<!----admin template course---->
<div class="admin_tempblock">
<div class="admin_tempsec">
<div class="admin_sec">
<?php if($this->session->flashdata('failed')) { ?>
<div class="alert alert-danger alert-dismissible fade show mb-3" role="alert">
<p><?php echo $this->session->flashdata('failed') ?></p>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<?php } ?>
<form action="<?php echo base_url() ?>admin/ae-course/<?php echo $id ?>" method="post" id="courseForm">
<?php if($id == 0) {?>
<div class="subsec_sec">
<div class="subject_l subject_l_full_width">
<div class="subject_lsec">
<div class="subject_lhead"><?php echo $title ?></div>
<div class="subject_lformarea">
<div class="form-group">
<label for="">Course Name<span class="text-danger font-weight-bold">*</span></label>
<input type="text" name="course_name" class="form-control" placeholder="Name of the course">
<label id="secNameerr" style="display : none"></label>
</div>
<div class="form-group assign_subject">
<label>Assign Subjects<span class="text-danger font-weight-bold">*</span></label>
<select name="csubject[]" id="csubject" class="selectpicker" multiple data-live-search="true">
<option disabled value="">Choose Subjects</option>
<?php foreach($subject_list as $subject) { ?>
<option value="<?= $subject['id']; ?>"><?= $subject['subject_name']; ?></option>
<?php } ?>
</select>
<label id="csubject-error" class="error" for="csubject" style="display:none"></label>
</div>
<div class="form-group assign_subject">
<label>Assign Sections<span class="text-danger font-weight-bold">*</span></label>
<select name="csection[]" id="csection" class="selectpicker" multiple data-live-search="true">
<option disabled value="">Choose Sections </option>
<?php foreach($section_list as $section) { ?>
<option value="<?= $section['id']; ?>"><?= $section['section_name']; ?></option>
<?php } ?>
</select>
<label id="csection-error" class="error" for="csection" style="display:none"></label>
</div>
<div class="form-group">
<label for="">Status<span class="text-danger font-weight-bold">*</span></label>
<select name="is_active" class="form-control">
<option selected disabled value="">Choose section status</option>
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
<label id="is_active-error" class="error" for="is_active" style="display:none"></label>
</div>
<input type="submit" class="subject_addbtn" value="Save">
<a href="<?= base_url(); ?>admin/course"><button type="button" class="subject_addbtn bg-dark ml-2">Back</button></a>
</div>
</div>
</div>
</div>
</form>
<?php } else { ?>
<div class="subsec_sec">
<div class="subject_l subject_l_full_width">
<div class="subject_lsec">
<div class="subject_lhead"><?php echo $title ?></div>
<div class="subject_lformarea">
<div class="form-group">
<label for="">Course Name<span class="text-danger font-weight-bold">*</span></label>
<input type="text" name="course_name" value="<?php echo $course_info['course_name'] ?>" class="form-control" placeholder="Name of the course">
<label id="secNameerr" style="display : none"></label>
</div>
<div class="form-group assign_subject">
<label>Assign Subjects<span class="text-danger font-weight-bold">*</span></label>
<select name="csubject[]" id="csubject" class="selectpicker" multiple data-live-search="true">
<option disabled value="">Choose Subjects</option>
<?php if($course_subject_info) {
foreach($course_subject_info as $subject) { ?>
<option selected value="<?= $subject['subject_id']; ?>"><?= $subject['subject_name']; ?></option>
<?php }
} ?>
<?php
if($difference_subject) {
foreach($difference_subject as $subject) { ?>
<option value="<?= $subject['id']; ?>"><?= $subject['subject_name']; ?></option>
<?php } }?>
</select>
<label id="csubject-error" class="error" for="csubject" style="display:none"></label>
</div>
<div class="form-group assign_subject">
<label>Assign Sections<span class="text-danger font-weight-bold">*</span></label>
<select name="csection[]" id="csection" class="selectpicker" multiple data-live-search="true">
<option disabled value="">Choose Sections </option>
<?php foreach($course_section_info as $section) { ?>
<option selected value="<?= $section['section_id']; ?>"><?= $section['section_name']; ?></option>
<?php } ?>
<?php foreach($difference_section as $section) { ?>
<option value="<?= $section['id']; ?>"><?= $section['section_name']; ?></option>
<?php } ?>
</select>
<label id="csection-error" class="error" for="csection" style="display:none"></label>
</div>
<div class="form-group">
<label for="">Status<span class="text-danger font-weight-bold">*</span></label>
<select name="is_active" class="form-control">
<option selected value="<?php echo $course_info['is_active'] ?>"><?php echo $course_info['is_active'] ?></option>
<?php if($course_info['is_active'] == 'yes') { ?>
<option value="no">no</option>
<?php } else {?>
<option value="yes">yes</option>
<?php } ?>
</select>
<label id="is_active-error" class="error" for="is_active" style="display:none"></label>
</div>
<input type="submit" class="subject_addbtn" value="Update">
<a href="<?= base_url(); ?>admin/course"><button type="button" class="subject_addbtn bg-dark ml-2">Back</button></a>
</div>
</div>
</div>
</div>
</form>
</form>
<?php } ?>
</div>
</div>
</div>
<!----admin template course end---->
</main>
<!--End right-top side-->
<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>
$(document).on('keypress', function(e){
if(e.which==13)
{
$('form').submit();
}
});
$(document).ready(function(){
jQuery.validator.addMethod("alphanumeric", function(value, element) {
return this.optional(element) || /^[a-z\0-9\-\s]+$/i.test(value);
}, "Please enter alphanumeric Characters only");
$("#courseForm").validate({
rules: {
course_name: {
required: true,
minlength: 1,
alphanumeric : true
},
'csubject[]' : "required",
'csection[]' : "required",
is_active : "required"
},
messages: {
course_name: {
required: "Please provide a course name",
minlength : "Please enter more than 4 Characters"
},
'csubject' : "Please choose 1 subject",
'csection' : "Please choose 1 section",
is_active : "Please select course's status"
},
submitHandler: function(form) {
var inputValue = $("input[name='course_name']",form).val();
inputValue = inputValue.toLowerCase();
let flag = false;
$.ajax({
url : '<?php echo base_url() ?>' + 'admin/ajax_validate_course_name',
data : {
value : inputValue,
id : <?php echo $id ?>
},
type : 'POST',
async : false,
success: function(data){
console.log(data);
if(data == 'success'){
flag = true
}
}
});
if(flag) {
form.submit();
} else {
$('#secNameerr').show();
$('#secNameerr').text('This course name already exists.');
}
}
});
});
</script>