366 lines
18 KiB
PHP
366 lines
18 KiB
PHP
|
<main class="common_margin" id="main">
|
||
|
<div class="main-wrap">
|
||
|
<div class="dashboard-cover">
|
||
|
<div class="subsec_sec">
|
||
|
<div class="subject_r">
|
||
|
<div class="subject_lsec">
|
||
|
<a href="javascript:history.back()"><button class="btn btn-dark btn-sm">Back</button></a>
|
||
|
<div class="common-heading">
|
||
|
<h2><?= $title; ?></h2>
|
||
|
</div>
|
||
|
|
||
|
<div class="alert alert-success" id="success" style="display:none;">
|
||
|
<?php if ($idVal == 0) { ?>
|
||
|
<strong>Success!</strong> The new book added successfully.
|
||
|
<?php } else { ?>
|
||
|
<strong>Success!</strong> The book data updated successfully.
|
||
|
<?php } ?>
|
||
|
</div>
|
||
|
|
||
|
<?php
|
||
|
$isbn = '';
|
||
|
$book_code = '';
|
||
|
$title = '';
|
||
|
$author = '';
|
||
|
$publisher = '';
|
||
|
$published_year = '';
|
||
|
$price = '';
|
||
|
$total_no_of_pages = '';
|
||
|
$total_quantity = '';
|
||
|
$rack_no = '';
|
||
|
$description = '';
|
||
|
$can_be_issued_for = '';
|
||
|
$fine_per_day = 0;
|
||
|
$cat_id = '';
|
||
|
$cat_na = '';
|
||
|
if (isset($details) && !empty($details)) {
|
||
|
$isbn = $details['isbn'];
|
||
|
$book_code = $details['book_code'];
|
||
|
$title = $details['title'];
|
||
|
$author = $details['author'];
|
||
|
$publisher = $details['publisher'];
|
||
|
$published_year = $details['published_year'];
|
||
|
$price = (int)$details['price'];
|
||
|
$total_no_of_pages = $details['total_no_of_pages'];
|
||
|
$total_quantity = $details['total_quantity'];
|
||
|
$rack_no = $details['rack_no'];
|
||
|
$description = $details['description'];
|
||
|
$can_be_issued_for = $details['can_be_issued_for'];
|
||
|
|
||
|
$category_id = $details['category_id'];
|
||
|
$data = $this->db->get_where('lms_categories', ['id' => $category_id])->row();
|
||
|
if (!empty($data)) {
|
||
|
$cat_id = $data->id;
|
||
|
$cat_name = $data->name;
|
||
|
}
|
||
|
}
|
||
|
if (isset($gSData) && !empty($gSData) && ($idVal == 0)) {
|
||
|
$fine_per_day = $gSData['due_fee_per_day'];
|
||
|
}
|
||
|
?>
|
||
|
<div class="common-sub-heading">Book Details</div>
|
||
|
<form id="bookForm" method="POST">
|
||
|
<input type="hidden" id="id" name="id" value="<?= $idVal; ?>" />
|
||
|
<input type="hidden" name="fine_per_day" value="<?= $fine_per_day; ?>">
|
||
|
<div class="subject_lformarea book-form-area">
|
||
|
<div class="form-group">
|
||
|
<input type="text" class="form-control txtData" placeholder="ISBN*" name="isbn" id="isbn" autocomplete="off" value="<?= $isbn; ?>">
|
||
|
<i class="fas fa-barcode"></i>
|
||
|
<p class="form_err" id="error-isbn"></p>
|
||
|
</div>
|
||
|
<div class="form-group">
|
||
|
<input type="text" class="form-control txtData" placeholder="Book Code" name="book_code" id="book_code" autocomplete="off" value="<?= $book_code; ?>">
|
||
|
<i class="fas fa-barcode"></i>
|
||
|
<p class="form_err" id="error-isbn"></p>
|
||
|
</div>
|
||
|
<div class="form-group">
|
||
|
<input type="text" class="form-control txtData" placeholder="Book Title*" name="title" id="title" autocomplete="off" value="<?= $title; ?>">
|
||
|
<p class="form_err" id="error-title"></p>
|
||
|
</div>
|
||
|
<div class="form-group assign_subject">
|
||
|
<select class="form-control txtData" name="category_id" id="category_id">
|
||
|
<?php if (!empty($data)) { ?>
|
||
|
<option value="<?= $cat_id; ?>" selected disabled><?= $cat_name; ?></option>
|
||
|
<?php } else { ?>
|
||
|
<option value="">Select Category*</option>
|
||
|
<?php } ?>
|
||
|
|
||
|
<?php if (isset($categoryData) && !empty($categoryData)) {
|
||
|
foreach ($categoryData as $cData) { ?>
|
||
|
<option value="<?= $cData['id']; ?>"><?= $cData['name']; ?></option>
|
||
|
<?php }
|
||
|
} ?>
|
||
|
</select>
|
||
|
<p class="form_err" id="error-category_id"></p>
|
||
|
</div>
|
||
|
<div class="form-group">
|
||
|
<input type="text" class="form-control txtData" placeholder="Author" name="author" id="author" autocomplete="off" value="<?= $author; ?>">
|
||
|
<p class="form_err" id="error-author"></p>
|
||
|
</div>
|
||
|
<div class="form-group">
|
||
|
<input type="text" class="form-control txtData" placeholder="Publisher" name="publisher" id="publisher" autocomplete="off" value="<?= $publisher; ?>">
|
||
|
<p class="form_err" id="error-publisher"></p>
|
||
|
</div>
|
||
|
<div class="form-group">
|
||
|
<input type="text" class="form-control txtData" placeholder="Year" name="published_year" id="published_year" autocomplete="off" value="<?= $published_year; ?>">
|
||
|
<p class="form_err" id="error-year"></p>
|
||
|
</div>
|
||
|
<div class="form-group">
|
||
|
<input type="text" class="form-control txtData" placeholder="Total Pages" name="total_no_of_pages" id="total_no_of_pages" autocomplete="off" value="<?= $total_no_of_pages; ?>">
|
||
|
<p class="form_err" id="error-ttl_page"></p>
|
||
|
</div>
|
||
|
<div class="form-group">
|
||
|
<input type="text" class="form-control txtData" placeholder="Total Quantity*" name="total_quantity" id="total_quantity" autocomplete="off" value="<?= $total_quantity; ?>">
|
||
|
<p class="form_err" id="error-ttl_qty"></p>
|
||
|
</div>
|
||
|
<div class="form-group">
|
||
|
<input type="text" class="form-control txtData" placeholder="Rack no" name="rack_no" id="rack_no" autocomplete="off" value="<?= $rack_no; ?>">
|
||
|
<p class="form_err" id="error-rack_no"></p>
|
||
|
</div>
|
||
|
<div class="form-group">
|
||
|
<input type="text" class="form-control txtData" placeholder="Price" name="price" id="price" autocomplete="off" value="<?= $price; ?>">
|
||
|
<p class="form_err" id="error-price"></p>
|
||
|
</div>
|
||
|
<div class="form-group">
|
||
|
<input type="text" class="form-control txtData" placeholder="Description" name="description" id="description" autocomplete="off" value="<?= $description; ?>">
|
||
|
<p class="form_err" id="error-description"></p>
|
||
|
</div>
|
||
|
<div class="form-group">
|
||
|
<div class="form-inner-div">
|
||
|
<input type="checkbox" id="overwriteDays" <?php if ($can_be_issued_for != 0) {
|
||
|
echo 'checked';
|
||
|
} else {
|
||
|
echo '';
|
||
|
} ?> onclick="check()" /><label>Overwrite default lending days</label>
|
||
|
<input type="number" step="1" min="0" class="form-control txtData" name="can_be_issued_for" id="can_be_issued_for" value="<?= $can_be_issued_for; ?>" autocomplete="off" />
|
||
|
</div>
|
||
|
<p class="form_err" id="error-lending_days"></p>
|
||
|
</div>
|
||
|
</div>
|
||
|
<button type="submit" class="subject_addbtn"><?= $button; ?></button>
|
||
|
</form>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</main>
|
||
|
<!--End right-top side-->
|
||
|
</div>
|
||
|
|
||
|
<!-- <script src="assets/js/jquery-3.2.1.slim.min.js"></script> -->
|
||
|
<script src="<?= base_url(); ?>assets-lms/js/jquery-3.4.1.min.js"></script>
|
||
|
<script src="<?= base_url(); ?>assets-lms/js/jquery.validate.js"></script>
|
||
|
<script src="<?= base_url(); ?>assets-lms/js/additional-methods.js"></script>
|
||
|
<script src="<?= base_url(); ?>assets-lms/js/bootstrap.min.js"></script>
|
||
|
<script src="<?= base_url(); ?>assets-lms/js/popper.min.js"></script>
|
||
|
|
||
|
<script defer src="<?= base_url(); ?>assets-lms/js/all.js"></script>
|
||
|
<script defer src="<?= base_url(); ?>assets-lms/js/main.js"></script>
|
||
|
<script src="<?= base_url(); ?>assets-lms/owl-carousel/js/owl.carousel.min.js"></script>
|
||
|
<script>
|
||
|
$(document).ready(function() {
|
||
|
$('.user-drpdown').click(function() {
|
||
|
$('.drpdown-items').toggle();
|
||
|
});
|
||
|
});
|
||
|
|
||
|
|
||
|
//table js
|
||
|
$('#tbl').DataTable({
|
||
|
"lengthMenu": [
|
||
|
[5, 10, 25, 50, -1],
|
||
|
[5, 10, 25, 50, "All"]
|
||
|
]
|
||
|
});
|
||
|
//table js end
|
||
|
//multiple select js start
|
||
|
$('select').selectpicker();
|
||
|
//multiple select js end
|
||
|
</script>
|
||
|
<script>
|
||
|
function check() {
|
||
|
var id = $('#id').val();
|
||
|
if ($("#overwriteDays").is(":checked")) {
|
||
|
$('#error-lending_days').text('Please enter lending days');
|
||
|
} else {
|
||
|
if (id > 0) {
|
||
|
$('#can_be_issued_for').val('');
|
||
|
} else {
|
||
|
$('#can_be_issued_for').val('');
|
||
|
}
|
||
|
$('#error-lending_days').html('');
|
||
|
}
|
||
|
}
|
||
|
</script>
|
||
|
<script>
|
||
|
$.validator.addMethod("nameRegex", function(value, element) {
|
||
|
return this.optional(element) || /^[a-zA-Z0-9\s]*$/.test(value);
|
||
|
}, "Contain only letters.");
|
||
|
|
||
|
$("#bookForm").validate({
|
||
|
errorClass: 'error',
|
||
|
rules: {
|
||
|
isbn: {
|
||
|
required: true,
|
||
|
minlength: 10,
|
||
|
maxlength: 13,
|
||
|
digits: true,
|
||
|
alphanumeric: true
|
||
|
},
|
||
|
title: {
|
||
|
required: true,
|
||
|
minlength: 3,
|
||
|
nameRegex: true
|
||
|
},
|
||
|
category_id: {
|
||
|
required: {
|
||
|
depends: function(element) {
|
||
|
return $("#category_id").val() == '';
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
author: {
|
||
|
nameRegex: true,
|
||
|
},
|
||
|
publisher: {
|
||
|
nameRegex: true
|
||
|
},
|
||
|
published_year: {
|
||
|
minlength: 4,
|
||
|
maxlength: 4,
|
||
|
digits: true
|
||
|
},
|
||
|
total_no_of_pages: {
|
||
|
digits: true,
|
||
|
alphanumeric: true
|
||
|
},
|
||
|
total_quantity: {
|
||
|
required: true,
|
||
|
digits: true,
|
||
|
alphanumeric: true
|
||
|
},
|
||
|
rack_no: {
|
||
|
alphanumeric: true
|
||
|
},
|
||
|
price: {
|
||
|
number: true,
|
||
|
alphanumeric: true
|
||
|
},
|
||
|
can_be_issued_for: {
|
||
|
min: 0
|
||
|
}
|
||
|
|
||
|
},
|
||
|
messages: {
|
||
|
isbn: {
|
||
|
required: "ISBN is required",
|
||
|
minlength: "At least 10 characters long",
|
||
|
maxlength: "Should not exceed 13 characters",
|
||
|
digits: "Accepts only integer",
|
||
|
alphanumeric: "Special character not allowed"
|
||
|
},
|
||
|
title: {
|
||
|
required: "Title is required",
|
||
|
minlength: "At least 3 characters long",
|
||
|
nameRegex: "Contains only characters"
|
||
|
},
|
||
|
category_id: {
|
||
|
required: "category is required"
|
||
|
},
|
||
|
author: {
|
||
|
nameRegex: "Contains only characters"
|
||
|
},
|
||
|
publisher: {
|
||
|
nameRegex: "Contains only characters"
|
||
|
},
|
||
|
published_year: {
|
||
|
minlength: "At least 4 characters long",
|
||
|
maxlength: "Should not exceed 4 characters",
|
||
|
digits: "Accepts only integer"
|
||
|
},
|
||
|
total_no_of_pages: {
|
||
|
digits: "Accepts only integer",
|
||
|
alphanumeric: "Special character not allowed"
|
||
|
},
|
||
|
total_quantity: {
|
||
|
required: "Total quantity is required",
|
||
|
digits: "Accepts only integer",
|
||
|
alphanumeric: "Special character not allowed"
|
||
|
},
|
||
|
rack_no: {
|
||
|
alphanumeric: "Special character not allowed"
|
||
|
},
|
||
|
price: {
|
||
|
number: "Accepts only integer",
|
||
|
alphanumeric: "Special character not allowed"
|
||
|
},
|
||
|
can_be_issued_for: {
|
||
|
min: "Value must be greater than 0"
|
||
|
}
|
||
|
},
|
||
|
errorPlacement: function(error, element) {
|
||
|
if (element.attr("name") == "isbn") {
|
||
|
error.appendTo($("#error-isbn"));
|
||
|
} else if (element.attr("name") == "title") {
|
||
|
error.appendTo($("#error-title"));
|
||
|
} else if (element.attr("name") == "category_id") {
|
||
|
error.appendTo($("#error-category_id"));
|
||
|
} else if (element.attr("name") == "author") {
|
||
|
error.appendTo($("#error-author"));
|
||
|
} else if (element.attr("name") == "publisher") {
|
||
|
error.appendTo($("#error-publisher"));
|
||
|
} else if (element.attr("name") == "published_year") {
|
||
|
error.appendTo($("#error-year"));
|
||
|
} else if (element.attr("name") == "total_no_of_pages") {
|
||
|
error.appendTo($("#error-ttl_page"));
|
||
|
} else if (element.attr("name") == "total_quantity") {
|
||
|
error.appendTo($("#error-ttl_qty"));
|
||
|
} else if (element.attr("name") == "rack_no") {
|
||
|
error.appendTo($("#error-rack_no"));
|
||
|
} else if (element.attr("name") == "price") {
|
||
|
error.appendTo($("#error-price"));
|
||
|
} else if (element.attr("name") == "can_be_issued_for") {
|
||
|
error.appendTo($("#error-lending_days"));
|
||
|
} else {
|
||
|
error.appendTo(element);
|
||
|
}
|
||
|
},
|
||
|
submitHandler: function(form) {
|
||
|
var formdata = new FormData(form);
|
||
|
var id = $('#id').val();
|
||
|
$.ajax({
|
||
|
type: 'post',
|
||
|
url: '<?= base_url(); ?>LmsAdmin/add_edit_book/' + id,
|
||
|
data: formdata,
|
||
|
cache: false,
|
||
|
contentType: false,
|
||
|
processData: false,
|
||
|
success: function(result) {
|
||
|
$('#error-isbn').html('');
|
||
|
if (result == 0) {
|
||
|
$("#error-ttl_qty").html('');
|
||
|
$('#error-isbn').text('Already exists book.');
|
||
|
} else if (result == 1) {
|
||
|
$('.txtData').val('');
|
||
|
$("#error-ttl_qty").html('');
|
||
|
$('#error-lending_days').html('');
|
||
|
$("#overwriteDays").prop('checked', false);
|
||
|
$('#success').show();
|
||
|
setTimeout(() => {
|
||
|
location.reload();
|
||
|
}, 2000);
|
||
|
} else {
|
||
|
var qtyVals = result.split('_');
|
||
|
var issuedQty = qtyVals[0];
|
||
|
var remQty = qtyVals[1];
|
||
|
$("#error-ttl_qty").text('Total quantity is having remaining and issued quantity respectively (' + remQty + '+' + issuedQty + '). if u want to edit enter greater than total value.');
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
</script>
|
||
|
</body>
|
||
|
|
||
|
</html>
|