-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibrary.php
208 lines (194 loc) · 5.95 KB
/
library.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
<?php
class Library
{
public function __construct()
{
try {
//create PDO connection
$this->db = new PDO('mysql:host=localhost;dbname=pemilu', 'root', '');
} catch(PDOException $e) {
//show error
die("Terjadi masalah: " . $e->getMessage());
}
}
public function addMhs($npm, $nama, $ttl, $telp, $jurusan, $angkatan, $alamat, $email, $password, $foto)
{
$sql = "INSERT INTO mahasiswa (npm, nama, ttl, no_telepon, email, jurusan, angkatan, alamat, foto)
VALUES ('$npm', '$nama', '$ttl', '$telp', '$email', '$jurusan', '$angkatan', '$alamat', '$foto')";
$query = $this->db->query($sql);
$sql = "INSERT INTO akun (username, password) VALUES ('$npm', '$password')";
$query = $this->db->query($sql);
if (!$query) {
return "Failed";
} else {
return "Success";
}
}
public function addKandidat($noUrut, $NPM, $visi, $misi)
{
$sql = "INSERT INTO kandidat (NO_URUT, NPM, VISI, MISI)
VALUES ('$noUrut', '$NPM', '$visi', '$misi')";
$query = $this->db->query($sql);
if (!$query) {
return "Failed";
} else {
return "Success";
}
}
public function voteKandidat($noUrut, $NPM, $kodeTPS)
{
$sql = "INSERT INTO vote (NO_URUT, NPM, Kode_TPS, Waktu)
VALUES ('$noUrut', '$NPM', '$kodeTPS', now())";
$query = $this->db->query($sql);
if (!$query) {
return "Failed";
} else {
return "Success";
}
}
public function addTPS($kodeTPS, $lokasiTPS)
{
$sql = "INSERT INTO tps (Kode_TPS, Lokasi)
VALUES ('$kodeTPS', '$lokasiTPS')";
$query = $this->db->query($sql);
if (!$query) {
return "Failed";
} else {
return "Success";
}
}
public function editMhs($npm)
{
$sql = "SELECT * FROM mahasiswa WHERE npm='$npm'";
$query = $this->db->query($sql);
return $query;
}
public function editTPS($kodeTPS)
{
$sql = "SELECT * FROM tps WHERE Kode_TPS='$kodeTPS'";
$query = $this->db->query($sql);
return $query;
}
public function editKandidat($NPM)
{
$sql = "SELECT * FROM kandidat WHERE NPM='$NPM'";
$query = $this->db->query($sql);
return $query;
}
public function updateMhs($npm, $nama, $ttl, $telp, $jurusan, $angkatan, $alamat, $email, $password)
{
$sql = "UPDATE mahasiswa SET npm='$npm', nama='$nama', ttl='$ttl', no_telepon='$telp', email='$email', jurusan='$jurusan', angkatan='$angkatan', alamat='$alamat' WHERE npm='$npm'";
$query = $this->db->query($sql);
$sql = "UPDATE Akun SET Username='$npm', Akun.password='$password' WHERE Username='$npm'";
$query = $this->db->query($sql);
if (!$query) {
return "Failed";
} else {
return "Success";
}
}
public function updateTPS($kodeTPS, $lokasiTPS, $kodeBefore)
{
$sql = "UPDATE tps SET Kode_TPS='$kodeTPS', Lokasi='$lokasiTPS' WHERE Kode_TPS='$kodeBefore'";
$query = $this->db->query($sql);
if (!$query) {
return "Failed";
} else {
return "Success";
}
}
public function updateKandidat($NPM, $visi, $misi, $NPMbefore)
{
$sql = "UPDATE kandidat SET NPM='$NPM', VISI='$visi', MISI='$misi' WHERE NPM='$NPMbefore'";
$query = $this->db->query($sql);
if (!$query) {
return "Failed";
} else {
return "Success";
}
}
public function showMhsNoVerif()
{
$sql = "SELECT * FROM mahasiswa, akun WHERE USERNAME = NPM and validasi=0 and admin = 0";
$query = $this->db->query($sql);
return $query;
}
public function showSuara()
{
$sql = "SELECT * FROM vote";
$query = $this->db->query($sql);
return $query;
}
public function showKandidatVote()
{
$sql = "SELECT * FROM kandidat";
$query = $this->db->query($sql);
return $query;
}
public function showMhsVerif()
{
$sql = "SELECT * FROM mahasiswa, akun WHERE USERNAME = NPM and validasi = 1 and admin = 0";
$query = $this->db->query($sql);
return $query;
}
public function showTPS()
{
$sql = "SELECT * FROM tps";
$query = $this->db->query($sql);
return $query;
}
public function showKandidat()
{
$sql = "SELECT * FROM kandidat";
$query = $this->db->query($sql);
return $query;
}
public function showPerson($npm)
{
$sql = "SELECT * FROM mahasiswa WHERE npm='$npm'";
$query = $this->db->query($sql);
return $query;
}
public function deleteMhs($npm)
{
$sql = "DELETE FROM akun WHERE USERNAME='$npm'";
$query = $this->db->query($sql);
$sql = "DELETE FROM mahasiswa WHERE NPM='$npm'";
$query = $this->db->query($sql);
if (!$query) {
return "Failed";
} else {
return "Success";
}
}
public function deleteTPS($kodeTPS)
{
$sql = "DELETE FROM tps WHERE Kode_TPS='$kodeTPS'";
$query = $this->db->query($sql);
if (!$query) {
return "Failed";
} else {
return "Success";
}
}
public function deleteKandidat($NPM)
{
$sql = "DELETE FROM kandidat WHERE NPM='$NPM'";
$query = $this->db->query($sql);
if (!$query) {
return "Failed";
} else {
return "Success";
}
}
public function validasiMhs($npm)
{
$sql = "UPDATE mahasiswa SET Validasi=1 WHERE npm='$npm'";
$query = $this->db->query($sql);
if (!$query) {
return "Failed";
} else {
return "Success";
}
}
}