forked from SciLifeLab/external_kpis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getCouchDbData.php
67 lines (58 loc) · 2.21 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 = "";
$designStr = "";
$dbStr = "";
//$group_levelStr = "group_level=2";
if (isset($_GET['view'])) {
$viewStr = addslashes($_GET['view']);
//echo "viewstr: $viewStr<br>";
if(strcmp($viewStr,'projects') != 0 && strcmp($viewStr, 'applications_projects') != 0 && strcmp($viewStr, 'applications_samples') != 0 && strcmp($viewStr, 'per_lane') != 0 && strcmp($viewStr, 'date_affiliation') != 0 && strcmp($viewStr, 'dates_and_load_per_sample') != 0) {
$viewStr = "";
}
//echo "viewstr: $viewStr<br>";
}
if(isset($_GET['design'])) {
$designStr = addslashes($_GET['design']);
if(strcmp($designStr,'kpi_external') != 0 && strcmp($designStr, 'reads') != 0 && strcmp($designStr, 'genomics-dashboard') != 0) {
$designStr = "";
}
}
if(isset($_GET['db'])) {
$dbStr = addslashes($_GET['db']);
//echo $dbStr . "<br>";
if(strcmp($dbStr,'projects') != 0 && strcmp($dbStr, 'flowcells') != 0) {
$dbStr = "";
}
}
if(isset($_GET['reduce'])) {
$reduceStr = addslashes($_GET['reduce']);
if(strcmp($reduceStr,'false') != 0) {
$reduceStr = "";
}
}
if(isset($_GET['group_level'])) {
$levelStr = addslashes($_GET['group_level']);
}
// 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";
//$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;
?>