forked from SciLifeLab/genomics-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getCouchDbData.php
67 lines (58 loc) · 1.96 KB
/
getCouchDbData.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
<?php
//$viewStr = "KPI_applications";
$viewStr = "";
$designStr = "";
$dbStr = "";
//$levelStr = "";
//$group_levelStr = "group_level=2";
if (isset($_GET['view'])) {
$viewStr = $_GET['view'];
//echo "viewstr: $viewStr<br>";
//} else {
// $viewStr .= "?group_level=2";
}
if(isset($_GET['design'])) {
$designStr = $_GET['design'];
}
if(isset($_GET['db'])) {
$dbStr = $_GET['db'];
if(isset($_GET['local_dev'])) {
$dbStr = 'projects_dev';
}
}
if(isset($_GET['reduce'])) {
$reduceStr = $_GET['reduce'];
}
if(isset($_GET['group_level'])) {
$levelStr = $_GET['group_level'];
}
//$url = "http://localhost:5984/analysis/_design/process_flow/_view/KPI?group_level=2";
//$url = "http://tools.scilifelab.se:5984/analysis/_design/process_flow/_view/KPI?group_level=2";
// get user:password from file. File should contain one line on the form username:password
$fhandle = fopen("user_cred.txt", 'r');
$user_password = fgets($fhandle);
$user_password = str_replace("\n", '', $user_password);// in case there is \n at the end of the line
fclose($fhandle);
// set up curl and call couchDb view
$base_url = "http://[email protected]:5984";
if(isset($_GET['dev'])) {
$base_url = "http://[email protected]:5984";
}
if(isset($_GET['local']) || isset($_GET['local_dev'])) {
$base_url = "http://localhost:5984";
}
$url = "$base_url/$dbStr/_design/$designStr/_view/$viewStr";
if(isset($reduceStr)) {
$url .= "?reduce=$reduceStr";
}
if(isset($levelStr)) {
$url .= "?group_level=$levelStr";
}
//echo "url: $url<br>";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>