-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpurchases.php
executable file
·54 lines (49 loc) · 1.52 KB
/
purchases.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
<?php
require_once('config.php');
session_start();
$dbh = connect();
$return = array("success" => false, "menssage" => "you are not logged");
if(isset($_SESSION['logged'])){
$user = $_GET['user'];
$book_id = $_GET['book_id'];
$start = 0;
$length = NULL;
if (!$_GET['start'] == ""){
$start = $_GET['start'];
}
if (!$_GET['length'] == ""){
$length = $_GET['length'];
}
if($_SESSION['user']['type'] == "user"){
$return = array("success" => false, "menssage" => "you have no authorization");
if($_SESSION['user']['username'] == $user){
$query = $dbh->prepare("SELECT book_id, user FROM purchases WHERE user = :us");
if($query->execute(":us" => $user)){
$row = $query->fetchAll();
$count = $query->rowCount();
if($length == NULL){
$length = $count;
}
$return = NULL;
for($i = 0; $i < $length-$start; $i++){
$return[$i] = array("book_id" => $row[$start+$i]['book_id'] , "user" => $row[$start+$i]['user']);
}
}
}
}else if($_SESSION['user']['type'] == "admin"){
$query = $dbh->prepare("SELECT book_id, user FROM purchases WHERE user LIKE '%".$user."%' OR book_id = ".$book_id.);
if($query->execute(":us" => $user)){
$row = $query->fetchAll();
$count = $query->rowCount();
if($length == NULL){
$length = $count;
}
$return = NULL;
for($i = 0; $i < $length-$start; $i++){
$return[$i] = array("book_id" => $row[$start+$i]['book_id'] , "user" => $row[$start+$i]['user']);
}
}
}
}
exit(json_encode($return));
?>