-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.ajax.php
104 lines (92 loc) · 3.12 KB
/
functions.ajax.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
<?php
header('Content-Type: application/json; charset=utf-8');
// close session for write for a fast response
session_write_close();
// load the class
require_once('./products.class.inc.php');
require_once('./currencies.class.inc.php');
require_once('./weather.class.inc.php');
$result['REQUEST_METHOD']=$_SERVER['REQUEST_METHOD'];
$result['REQUEST'] = $_REQUEST;
$result['result']=false;
require_once('./pdo.php');
if( !$pdo ){
echo $result;
exit();
}
function getProdList( $listType ){
global $pdo;
$products = new product( $pdo );
if( $prodList = $products->getProdList() ){
echo json_encode( $prodList );
}
return false;
}
if( isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD']==='GET' ){
switch($_GET['action']){
case 'getProdList':
$products = new product( $pdo );
if( $prodList = $products->getProdList() ){
$result['prodList'] = $prodList;
$result['result']=true;
}
break;
case 'checkProdPrice':
if( $cProd = new product( $pdo, str_replace('row_', '', $_GET['prodCode'] ) ) ){
$result['product']=$cProd;
if( ($cProd->price !== $_GET['price'] || $cProd->specialPrice !== $_GET['price']) && $cProd->specialStatus==1 ){
$result['result']=true;
}
}
break;
case 'getCurrency':
$currencyObj = new currencies( $pdo );
if( $result['data']=$currencyObj->getCurrency( $_GET['date'] ) ){
$result['result']=true;
}
break;
case 'getWeather':
$weatherObj = new weather( $pdo );
if( $result['data']=$weatherObj->getWeather( urlencode($_GET['location']), $_GET['date'] ) ){
$result['result']=true;
}
break;
default:
#code ...
break;
}
} else if( $_SERVER['REQUEST_METHOD']==='POST' ){
switch($_POST['action']){
case 'populateProductsTables':
require_once('./pdoRemote.php');
$sql = "SELECT * FROM `PRODUCTS` WHERE `status`='1' ORDER BY `prodNamePTBR`";
$result['sql'] = $sql;
$stmt = $pdoRemote->prepare( $sql );
$stmt->execute();
if( $stmt->rowCount() ){
while( $row = $stmt->fetchObject() ){
$result['prodList'][] = $row;
}
$result['result']=true;
}
break;
case 'reload-browser':
$result['output']=shell_exec('xdotool search --onlyvisible --class chromium|head -1');
$result['result']=true;
break;
case 'saveWeather':
$weatherObj = new weather( $pdo );
$result['result'] = $weatherObj->setWeather( $_POST['date'], $_POST['time'], $_POST['location'], $_POST['weather'], $_POST['description'], $_POST['temp'], $_POST['temp_min'], $_POST['temp_max'] );
break;
case 'saveCurrency':
$currencyObj = new currencies( $pdo );
$result['result'] = $currencyObj->setCurrency( $_POST['date'], $_POST['time'], $_POST['currency'], $_POST['value']);
break;
default:
#code ...
break;
}
}
echo json_encode( $result );
return false;
?>