-
Notifications
You must be signed in to change notification settings - Fork 5
/
api.php
56 lines (49 loc) · 1.1 KB
/
api.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
<?php
$option = $_REQUEST['option'];
$search = $_REQUEST['s'];
function listCharts() {
$dir = "charts";
$urlStem = "http://" . $_SERVER['HTTP_HOST'] . "/charts";
$output = array_diff(scandir("charts"), array('..', '.'));
foreach($output as $file) {
echo "$urlStem/$file\n";
}
}
function searchCharts($str) {
$dir = "charts";
$urlStem = "http://" . $_SERVER['HTTP_HOST'] . "/charts";
$output = array_diff(scandir("charts"), array('..', '.'));
foreach($output as $file) {
if (preg_match("/$str/i",$file)) {
echo "$urlStem/$file\n";
}
}
}
function getCustomers() {
$output = array_diff(scandir("charts"), array('..', '.'));
$custArray = array();
foreach($output as $file) {
$arr = explode("-", $file, 2);
if(!in_array($arr[0], $custArray)){
$custArray[]=$arr[0];
}
}
sort($custArray);
$clist = "";
foreach ($custArray as $cust) {
$clist .= "$cust, ";
}
echo substr($clist,0,-2);
}
// create SQL based on vars
switch ($option) {
case 'list':
listCharts();
break;
case 'search':
searchCharts($search);
break;
case 'getCustomers' :
getCustomers();
}
?>