-
Notifications
You must be signed in to change notification settings - Fork 0
/
root_listbills_model.php
58 lines (55 loc) · 1.45 KB
/
root_listbills_model.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
<?php
session_start();
if(!isset($_SESSION['user'])) exit();
if(isset($_POST['q'])){
$q = @mysql_real_escape_string(substr($_POST['q'], 0, 40));
}
if(isset($_POST['s'])){
$s = $_POST['s'];
}
if(isset($_POST['cb_dtini'])){
$isDtIni = $_POST['cb_dtini'] == 'true' ? true : false;
$dtIni = $_POST['dtini'];
}
if(isset($_POST['cb_dtend'])){
$isDtEnd = $_POST['cb_dtend'] == 'true' ? true : false;
$dtEnd = $_POST['dtend'];
}
require('database_conect.php');
$res = [];
$user = $_POST['bk'];
if($user == ""){
$user = 'root';
$sql = "SELECT * FROM bills WHERE user != :user";
} else $sql = "SELECT * FROM bills WHERE user = :user";
$sqlB = array('user' => $user);
try {
if($q != ""){
$sql.=" AND ((hash LIKE :q) OR (matchjson LIKE :q) OR (apostador LIKE :q))";
$sqlB = array_merge($sqlB, array('q' => "%$q%"));
}
if($s != ""){
$sql.=" AND estado = :s";
$sqlB = array_merge($sqlB, array('s' => $s));
}
if($isDtIni){
$sql.=" AND data_criado > :dtini";
$sqlB = array_merge($sqlB, array('dtini' => $dtIni));
}
if($isDtEnd){
$sql.=" AND data_criado < :dtend";
$sqlB = array_merge($sqlB, array('dtend' => $dtEnd));
}
$sql .= " ORDER BY data_criado DESC";
$stm = $conn->prepare($sql);
$stm->execute($sqlB);
while($row = $stm->fetchObject()){
$row->valor = number_format((float)$row->valor, 2, ',', '');
$row->premio = number_format((float)$row->premio, 2, ',', '');;
array_push($res,$row);
}
} catch(PDOException $e){
exit();
}
echo json_encode($res);
?>