-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·285 lines (237 loc) · 7.13 KB
/
index.php
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Mutasi | Transaksi</title>
<!-- CSS-->
<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.css">
<link href="node_modules/toastr/build/toastr.min.css" rel="stylesheet" />
<!-- Javascript-->
<script src="node_modules/jquery/dist/jquery.js"></script>
<script src="node_modules/bootstrap/dist/js/bootstrap.js"></script>
<script src="node_modules/toastr/build/toastr.min.js"></script>
<style type="text/css">
html,
body {
margin: 0;
padding: 0;
font-family: "Roboto";
}
.jumbotron {
position: absolute;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
height: 100%;
}
@media only screen and (max-width: 550px) {
#isi {
overflow: scroll;
}
}
</style>
</head>
<body>
<div class="jumbotron">
<div class="container mt-5">
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-header">
<span>MUTASI TRANSAKSI</span>
<a href="" onclick="return false" class="btn btn-primary btn-sm ml-3" id="tambah" style="display:none;">Tambah</a>
<a href="" class="btn btn-danger btn-sm ml-3" id="logout" style="display:none;float:right">Logout</a>
<div class="span" style="float:right">
<div id="user">
</div>
</div>
</div>
<div class="card-body" id="card">
<div id="myDiv" class="mb-3">
<!-- <img id="loading-image" src="loading.gif" style="display:none;" /> -->
<div class="total">
</div>
</div>
<form onsubmit="return false" method="POST" id="form-tambah" class="form-user mb-3" style="display:none;">
<div class="mb-3">
<label for="jumlah" class="form-label">Jumlah</label>
<input type="number" class="form-control" name="jumlah" aria-describedby="emailHelp" id="jumlah">
</div>
<div class="mb-3">
<label for="keterangan" class="form-label">keterangan</label>
<input type="text" class="form-control" name="keterangan" id="keterangan">
<input type="hidden" name="author">
</div>
<input type="submit" class="btn btn-primary btn-sm" id="tombol-simpan" name="tombol-simpan" value="Simpan">
</form>
<div id="login" style="display:block;">
<form id="loginForm" method="POST">
<label for="inputPassword5" class="form-label">Password</label>
<input type="password" id="inputPassword5" class="form-control" aria-labelledby="passwordHelpBlock" name="password" id="password">
<!-- <button type="submit" class="btn btn-primary" style="display:block;">Login</button> -->
</form>
<div id="passwordHelpBlock" class="form-text">
<i>* Untuk melihat dan menambahkan mutasi silahkan masukkan password </i> <br>
<i>* Untuk hanya akses melihat mutasi silahkan masukkan password </i>"<b>tamu</b>"<i> tanpa tanda kutip</i>
</div>
</div>
<div id="isi">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
tampil();
function ajaxku() {
$.ajax({
type: "GET",
url: "inc/data.php",
success: function(result) {
$("#isi").html(result);
$("#login").hide();
$("input[type='password']").val("");
}
});
$.ajax({
type: "GET",
url: "inc/total.php",
dataType:'json',
success: function(data) {
var total = data.saldo
$('.total').html('Sisa Hutang <b> Rp. '+total+'</b>');
}
});
}
function logged() {
toastr.success('Password terverifikasi');
ajaxku();
$('#login').slideUp();
$('#tambah').slideDown();
$('#logout').slideDown();
var login = localStorage.getItem('login');
var nama = localStorage.getItem('nama');
$('#user').html('Hai, ' + nama);
if (login === 'tamu') {
$('#tambah').hide();
}
}
function tampil() {
$("input[type='password']").keypress(function(e) {
var isi = $(this).val();
if (e.which == '13') {
e.preventDefault();
if (isi != '') {
$.ajax({
url: 'inc/login.php',
method: 'POST',
data: {
password: isi
},
success: function(response) {
var json = JSON.parse(response);
var id = json.id;
var nama = json.nama;
if (id == 1) {
localStorage.setItem('login', 'admin');
localStorage.setItem('nama', nama);
logged();
} else if (id == 2) {
localStorage.setItem('login', 'tamu');
localStorage.setItem('nama', nama);
logged();
}else if (id > 2) {
localStorage.setItem('login', 'admin2');
localStorage.setItem('nama', nama);
logged();
} else if (id == 0) {
toastr.error('Password salah');
}
},
error: function(xhr, status, error) {
console.log(xhr.responseText);
}
});
} else {
toastr.warning('Mohon isi password');
}
}
});
var login = localStorage.getItem('login');
if (login != null) {
logged();
} else {
toastr.info('Silahkan login');
}
}
$('#tambah').click(function() {
$("#form-tambah").slideToggle();
var nama = localStorage.getItem('nama');
$("input[type='hidden']").attr("value", nama);;
});
$("#tombol-simpan").click(function() {
var data = $('#form-tambah').serialize();
var jumlah = $('#jumlah').val();
var keterangan = $('#keterangan').val();
if (jumlah == '') {
toastr.warning('Jumlah wajib diisi ya sayang')
return;
} else if (jumlah == 0) {
toastr.warning('jumlah tidak boleh 0')
return;
} else if (jumlah > 1000000000 && keterangan.length > 100) {
toastr.error('Jumlah dan Keterangan melebihi batas karakter')
return;
} else if (jumlah > 1000000000 || jumlah < -1000000000) {
toastr.warning('Jumlah kelebihan')
return;
} else if (keterangan.length > 100) {
toastr.warning('Keterangan jangan melebihi 100 karakter')
return;
}
$.ajax({
type: 'POST',
url: "inc/post.php",
data: data,
success: function() {
$('#form-tambah').slideUp();
$('#form-tambah')[0].reset();
ajaxku();
toastr.success('<b>Hutang</b> baru kamu telah dibuat');
}
});
});
$('#logout').click(function(e) {
e.preventDefault();
logout();
});
function logout(){
localStorage.clear();
toastr.info('Logout berhasil');
$('#tambah').slideUp();
$('#logout').slideUp();
$('#login').slideDown();
$("#myTable").remove();
$(".total").hide();
$("#login").show();
$("#user").empty();
}
// Tidak bisa klik kanan
$(document).on("contextmenu", function(e) {
e.preventDefault();
toastr.error('<b>TIDAK BOLEH KLIK KANAN</b>');
});
for (var i = 0; i < localStorage.length; i++) {
var key = localStorage.key(i);
var value = localStorage.getItem(key);
console.log(key + ": " + value);
}
});
</script>
</body>
</html>