-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.js
115 lines (109 loc) · 2.4 KB
/
code.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
function showIssuedBooks(table) {
$('#issuedTable').css('display', 'block');
$.ajax({
url: 'show.php',
type: 'POST',
cache: false,
data: {'table': 'issuedTable', 'table2': table, 'typeau': 'User'},
success: function(response) {
$('#issuedTable').html(response);
}
});
}
function show(table, typeau) {
$.ajax({
url: 'show.php',
type: 'POST',
cache: false,
data: {'table': 'books', 'table2': table, 'typeau': typeau},
success: function(response) {
$('#table').html(response);
}
});
}
function issueBook(n, table, id) {
if (n == 0) {
alert("Book is not available.");
}
else{
$.ajax({
url: 'update.php',
type: 'POST',
cache: false,
data: {'action': 'issue', 'book_id': id, 'table': table},
success: function() {
alert("Book issued successfully");
show(table, 'User');
}
});
}
}
function returnBook(table, id) {
$.ajax ({
url: 'update.php',
type: 'POST',
cache: false,
data: {'action': 'return', 'book_id': id, 'table': table},
success: function() {
alert("Book returned successfully");
show(table, 'User');
showIssuedBooks(table);
}
});
}
function deleteBook(n, id) {
if (n == 0) {
alert("Book cannot be removed");
}
else {
$.ajax({
url: 'update.php',
type: 'POST',
cache: false,
data: {'action': 'remove', 'book_id': id},
success: function(a) {
show("", 'Admin');
alert("Book removed successfully");
}
});
}
}
function addBook(mode, name, author, publisher) {
if (mode == 0) {
$("#Add").css("display", "block");
}
else {
$.ajax({
url: 'update.php',
type: 'POST',
cache: false,
data: {'action': 'add', 'name': name, 'author': author, 'publisher': publisher},
success: function(){
alert("Book added successfully");
show("", 'Admin');
}
});
}
}
$(document).ready(function(){
$('#submit').click(function () {
var name = $('#name').val();
var author = $('#author').val();
var publisher = $('#publisher').val();
if (name == '' || author == '' || publisher == ''){
alert("Enter all details to add a book");
}
else {
$('#name').val("");
$('#author').val("");
$('#publisher').val("");
addBook(1, name, author, publisher);
}
});
});
window.onclick = function(event) {
if (event.target == document.getElementById('issuedTable') || event.target == document.getElementById('Add')) {
$('#issuedTable').css('display', 'none');
$('#Add').css('display', 'none');
}
}