-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkfunctions.php
335 lines (318 loc) · 10.4 KB
/
kfunctions.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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
<?php
session_start();
class article{
public $articlename="";
public $article_volume="";
public $article_number="";
public $article_pages="";
public $article_document="";
}
class books{
public $book_publisher="";
public $book_volume="";
public $book_number="";
public $book_series="";
public $book_adress="";
public $book_edition="";
public $book_isbn="";
public $book_issn="";
}
class inbooks{
public $inb_publisher="";
public $inb_adress="";
public $inb_chapter="";
public $inb_pages="";
public $inb_volume="";
public $inb_series="";
public $inb_type="";
public $inb_number="";
public $inb_edition="";
public $inb_isbn="";
public $inb_issn="";
}
class inproceedings{
public $inp_booktitle="";
public $inp_editor="";
public $inp_series="";
public $inp_volume="";
public $inp_number="";
public $inp_pages="";
public $inp_organisation="";
public $inp_publisher="";
public $inp_adress="";
public $inp_document="";
}
class user{
public $username="";
public $role="";
public $numberofposts="";
public $date="";
}
function admin(){
$mysqli = mysqli_connect("localhost", "root", "", "annapp");
$stmt = $mysqli->prepare("SELECT username,role FROM user WHERE username = ?");
$stmt->bind_param("s", $_SESSION['username']);
$stmt->execute();
$result = $stmt->get_result();
$return="";
while($row = $result->fetch_assoc()) {
if($row['role']=="admin"){
$return="admin";
}
}
if($return==""){
$return="noadmin";
}
$stmt->close();
return json_encode($return);
}
function admin_add(){
$mysqli = mysqli_connect("localhost", "root", "", "annapp");
$username=$_POST['username'];
$password=$_POST['password'];
$role=$_POST['role'];
$stmt = $mysqli->prepare("INSERT INTO `user`(`username`, `password`, `role`) VALUES ('$username','$password','$role')");
$stmt->execute();
//$result = $stmt->get_result();
$return="ok";
$stmt->close();
return json_encode($username);
}
function admin_delete(){
$mysqli = mysqli_connect("localhost", "root", "", "annapp");
$username=$_POST['username'];
$stmt = $mysqli->prepare("DELETE FROM `user` WHERE username = '$username'");
$stmt->execute();
$return="ok";
$stmt->close();
return json_encode($username);
}
function admin_modify(){
$mysqli = mysqli_connect("localhost", "root", "", "annapp");
$stmt = $mysqli->prepare("SELECT * FROM `user`");
$stmt->execute();
$return=array();
$result = $stmt->get_result();
while($row = $result->fetch_assoc()){
$return[]=array("username" => $row['username'],
"password" => $row['password'],
"role" => $row['role']);
}
$stmt->close();
return json_encode($return);
}
function admin_modify_author(){
$mysqli = mysqli_connect("localhost", "root", "", "annapp");
$stmt = $mysqli->prepare("SELECT * FROM `authors");
$stmt->execute();
$return=array();
$result = $stmt->get_result();
while($row = $result->fetch_assoc()){
$return[]=array("username" => $row['username'],
"name" => $row['name'],
"surname" => $row['surname'],
"orcidurl" => $row['orcidurl'],
"url" => $row['url'],
"specialty" => $row['specialty']);
}
$stmt->close();
return json_encode($return);
}
function admin_modify_last(){
$mysqli = mysqli_connect("localhost", "root", "", "annapp");
$stmt = $mysqli->prepare("SELECT * FROM `user`");
$stmt->execute();
$return=array();
$result = $stmt->get_result();
while($row = $result->fetch_assoc()){
$return[]=array("username" => $row['username'],
"password" => $row['password'],
"role" => $row['role']);
}
//$length=mysqli_num_rows($result);
//for($i=1;$i<=$length;$i++){
// if($object[i].username!=$check[i].username){
// $last[]=array("username" => $object[i].username,
// "password" => $object[i].password,
// "role" => $object[i].role);
//}
//}
$stmt->close();
return json_encode("suckerrrr");
}
function keyup(){
$conn = mysqli_connect("localhost", "root", "", "annapp");
$inpText=$_POST['query'];
//gia articles
$query="SELECT articlename FROM article WHERE articlename LIKE '%$inpText%'";
$result=$conn->query($query);
if($result->num_rows>0){
while($row=$result->fetch_assoc()){
echo "<a href='#' class='list-group-item list-group-item-action border-1'>".$row['articlename']."</a>";
}
}
else{
echo "<a class='list-group-item border-1'>No Record for article</a>";
}
//gia books
$query="SELECT publisher FROM books WHERE publisher LIKE '%$inpText%'";
$result=$conn->query($query);
if($result->num_rows>0){
while($row=$result->fetch_assoc()){
echo "<a href='#' class='list-group-item list-group-item-action border-1'>".$row['publisher']."</a>";
}
}
else{
echo "<a class='list-group-item border-1'>No Record for books</a>";
}
//gia posts
$query="SELECT title FROM posts WHERE username LIKE '%$inpText%' OR title LIKE '%$inpText%'";
$result=$conn->query($query);
if($result->num_rows>0){
while($row=$result->fetch_assoc()){
echo "<a href='#' class='list-group-item list-group-item-action border-1'>".$row['title']."</a>";
}
}
else{
echo "<a class='list-group-item border-1'>No Record for posts</a>";
}
//gia inbooks
$query="SELECT publisher FROM inbooks WHERE publisher LIKE '%$inpText%' OR isbn LIKE '%$inpText%' OR issn LIKE '%$inpText%'";
$result=$conn->query($query);
if($result->num_rows>0){
while($row=$result->fetch_assoc()){
echo "<a href='#' class='list-group-item list-group-item-action border-1'>".$row['publisher']."</a>";
}
}
else{
echo "<a class='list-group-item border-1'>No Record for inbooks</a>";
}
//gia inproceedings
$query="SELECT booktitle FROM inproceedings WHERE booktitle LIKE '%$inpText%' OR editor LIKE '%$inpText%' OR publisher LIKE '%$inpText%'";
$result=$conn->query($query);
if($result->num_rows>0){
while($row=$result->fetch_assoc()){
echo "<a href='#' class='list-group-item list-group-item-action border-1'>".$row['booktitle']."</a>";
}
}
else{
echo "<a class='list-group-item border-1'>No Record for inproceedings</a>";
}
//gia user
$query="SELECT username FROM user WHERE username LIKE '%$inpText%' ";
$result=$conn->query($query);
if($result->num_rows>0){
while($row=$result->fetch_assoc()){
echo "<a href='#' class='list-group-item list-group-item-action border-1'>".$row['username']."</a>";
}
}
else{
echo "<a class='list-group-item border-1'>No Record for user</a>";
}
}
function search(){
$data=$_POST['query2'];
$return=array();
$conn=mysqli_connect("localhost","root","","annapp");
//an einai sta inbooks
$stmt=$conn->prepare("SELECT * FROM inbooks WHERE publisher = '$data' OR isbn= '$data' OR issn = '$data' OR type='$data'");
$stmt->execute();
$result = $stmt->get_result();
$return[]=1;
while($row = $result->fetch_assoc()){
$a=new inbooks();
$a->inb_publisher=$row['publisher'];
$a->inb_adress=$row['adress'];
$a->inb_chapter=$row['chapter'];
$a->inb_pages=$row['pages'];
$a->inb_volume=$row['volume'];
$a->inb_number=$row['number'];
$a->inb_series=$row['series'];
$a->inb_type=$row['type'];
$a->inb_edition=$row['edition'];
$a->inb_isbn=$row['isbn'];
$a->inb_issn=$row['issn'];
$return[]=$a;
}
$stmt->close();
//an einai sta inproceedings
$stmt=$conn->prepare("SELECT * FROM inproceedings WHERE booktitle = '$data' OR publisher = '$data'");
$stmt->execute();
$result = $stmt->get_result();
$return[]=2;
while($row = $result->fetch_assoc()){
$a=new inproceedings();
$a->inp_booktitle=$row['booktitle'];
$a->inp_editor=$row['editor'];
$a->inp_series=$row['series'];
$a->inp_volume=$row['volume'];
$a->inp_number=$row['number'];
$a->inp_pages=$row['pages'];
$a->inp_organisation=$row['organisation'];
$a->inp_publisher=$row['publisher'];
$a->inp_adress=$row['adress'];
$a->inp_document=$row['document'];
$return[]=$a;
}
$stmt->close();
//gia article
$stmt=$conn->prepare("SELECT * FROM article WHERE articlename = '$data'");
$stmt->execute();
$result = $stmt->get_result();
$return[]=3;
while($row = $result->fetch_assoc()){
$a=new article();
$a->articlename=$row['articlename'];
$a->article_volume=$row['volume'];
$a->article_number=$row['number'];
$a->article_pages=$row['pages'];
$a->article_document=$row['document'];
$return[]=$a;
}
$stmt->close();
//an einai sta books
$stmt=$conn->prepare("SELECT * FROM books WHERE publisher = '$data' OR isbn= '$data' OR issn = '$data'");
$stmt->execute();
$result = $stmt->get_result();
$return[]=4;
while($row = $result->fetch_assoc()){
$a=new books();
$a->book_publisher=$row['publisher'];
$a->book_volume=$row['volume'];
$a->book_number=$row['number'];
$a->book_series=$row['series'];
$a->book_adress=$row['adress'];
$a->book_edition=$row['edition'];
$a->book_isbn=$row['isbn'];
$a->book_issn=$row['issn'];
$return[]=$a;
}
$stmt->close();
return json_encode($return);
}
//gia emfanish pinakwn sthn selida
if(isset($_POST['query2'])){
echo search();
}
else if(isset($_POST['adminshit'])){
echo admin();
}
else if(isset($_POST['admin-add'])){
echo admin_add();
}
else if(isset($_POST['admin-delete'])){
echo admin_delete();
}
else if(isset($_POST['admin-modify'])){
echo admin_modify();
}
else if(isset($_POST['admin-modify-author'])){
echo admin_modify_author();
}
else if(isset($_POST['admin-modify-last'])){
echo admin_modify_last();
}
else if(isset($_POST['query'])){
echo keyup();
}
?>