-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.php
197 lines (164 loc) · 6.3 KB
/
config.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
<?php
class db{
var $host = "localhost";
var $username = "root";
var $password = "";
var $database = "db_spp";
var $koneksi = "";
function __construct(){
$this->koneksi = mysqli_connect($this->host, $this->username, $this->password, $this->database);
if(mysqli_connect_errno())
{
echo" Koneksi database gagal : ".mysqli_connect_error();
}
}
//siswa
function tampil_data()
{
$data = mysqli_query($this->koneksi,"select * from siswa");
while($row = mysqli_fetch_array($data)){
$hasil[] = $row;
}
return $hasil;
}
function tampil_data_spp(){
$data = mysqli_query($this->koneksi, "SELECT * FROM spp");
while($row = mysqli_fetch_array($data)){
$hasil[]=$row;
}
if(!isset($hasil)){
$hasil=[];
}
return $hasil;
}
//DATA SPP
function get_by_id_spp($id_spp)
{
$query = mysqli_query($this->koneksi,"select * from spp where id_spp='$id_spp'");
return $query->fetch_array();
}
function update_data_spp($id_spp, $tahun, $nominal)
{
$query = mysqli_query($this->koneksi,"update spp set tahun = '$tahun', nominal = '$nominal' where id_spp='$id_spp'");
}
function delete_data_spp($id_spp)
{
$query = mysqli_query($this->koneksi,"delete from spp where id_spp='$id_spp'");
}
function tambah_data_spp($id_spp, $tahun, $nominal)
{
mysqli_query($this->koneksi,"insert into spp values ('', '$tahun', '$nominal')");
}
//kelas
function tampil_data_kelas(){
$data = mysqli_query($this->koneksi,"select * from kelas");
while($row = mysqli_fetch_array($data)){
$hasil[] = $row;
}
if(!isset($hasil)){
$hasil=[];
}
return $hasil;
}
function get_by_id_kelas($id_kelas)
{
$query = mysqli_query($this->koneksi,"select * from kelas where id_kelas='$id_kelas'");
return $query->fetch_array();
}
function update_data_kelas($id_kelas, $nama_kelas, $kompetensi_keahlian)
{
$query = mysqli_query($this->koneksi,"update kelas set nama_kelas = '$nama_kelas', kompetensi_keahlian = '$kompetensi_keahlian' where id_kelas='$id_kelas'");
}
function delete_data_kelas($id_kelas)
{
$query = mysqli_query($this->koneksi,"delete from kelas where id_kelas='$id_kelas'");
}
function tambah_data_kelas($id_kelas, $nama_kelas, $kompetensi_keahlian)
{
mysqli_query($this->koneksi,"insert into kelas values ('', '$nama_kelas', '$kompetensi_keahlian')");
}
//petugas
function tampil_data_petugas(){
$data = mysqli_query($this->koneksi,"select * from petugas where level='petugas'");
while($row = mysqli_fetch_array($data)){
$hasil[] = $row;
}
if(!isset($hasil)){
$hasil=[];
}
return $hasil;
}
function get_by_id_petugas($id_petugas)
{
$query = mysqli_query($this->koneksi,"select * from petugas where id_petugas='$id_petugas'");
return $query->fetch_array();
}
function update_data_petugas($id_petugas, $username, $nama_petugas, $password, $level)
{
$query = mysqli_query($this->koneksi,"update petugas set username = '$username', nama_petugas = '$nama_petugas', password = '$password', level = '$level' where id_petugas='$id_petugas'");
}
function delete_data_petugas($id_petugas)
{
$query = mysqli_query($this->koneksi,"delete from petugas where id_petugas='$id_petugas'");
}
function tambah_data_petugas($id_petugas, $username, $nama_petugas, $password, $level)
{
mysqli_query($this->koneksi,"insert into petugas values ('$id_petugas', '$username', '$nama_petugas', '$password', '$level')");
}
function tambah_data($nisn,$nis,$nama,$id_kelas,$alamat,$no_telp,$id_spp)
{
mysqli_query($this->koneksi,"INSERT INTO siswa values('$nisn','$nis','$nama','$id_kelas','$alamat','$no_telp','$id_spp')");
}
function get_by_id($nisn)
{
$query = mysqli_query($this->koneksi,"SELECT * FROM siswa WHERE nisn='$nisn'");
return $query->fetch_array();
}
function update_data($nisn,$nis,$nama,$id_kelas,$alamat,$no_telp,$id_spp)
{
$query = mysqli_query($this->koneksi, "UPDATE siswa SET nisn='$nisn',nis='$nis',nama='$nama',id_kelas='$id_kelas',alamat='$alamat',no_telp='$no_telp',id_spp='$id_spp' WHERE nisn='$nisn'");
}
function delete_data($nisn)
{
$query = mysqli_query($this->koneksi, "DELETE FROM siswa WHERE nisn='$nisn'");
}
function login($user, $username, $pass) {
if($user == "siswa") {
$query = mysqli_query($this->koneksi, "SELECT * FROM siswa WHERE nisn='$username' AND nis='$pass'");
if($query->num_rows > 0) {
session_start();
$_SESSION['level'] = "siswa";
$_SESSION['username'] = "$username";
return TRUE;
}
else {
return FALSE;
}
}
else if($user == "admin") {
$query = mysqli_query($this->koneksi, "SELECT * FROM petugas WHERE username='$username' AND password='$pass'");
if($query->num_rows > 0) {
session_start();
$_SESSION['level'] = "admin";
$_SESSION['username'] = "$username";
return TRUE;
}
else {
return FALSE;
}
}
else if($user == "petugas") {
$query = mysqli_query($this->koneksi, "SELECT * FROM petugas WHERE username='$username' AND password='$pass'");
if($query->num_rows > 0) {
session_start();
$_SESSION['level'] = "petugas";
$_SESSION['username'] = "$username";
return TRUE;
}
else {
return FALSE;
}
}
}
}
?>