root/trunk/setups/katrin/services/katrin.php

Revision trunk,171, 3.4 kB (checked in by Suren A. Chilingaryan <csa@dside.dyndns.org>, 1 year ago)

KATRIN code by Sebastian and few fixes to integrate it

Line 
1 <?php
2 // $Id: katrin.php 1037 2009-09-23 13:54:51Z s_voec01 $
3 // Author: Sebastian Voecking <sebastian.voecking@uni-muenster.de>
4
5 //require("../adei.php");
6 //require($ADEI_ROOTDIR . "/setups/katrin/classes/kdbphp.php");
7
8 ADEI::RequireClass("KDBFileIdentifier", true);
9 ADEI::RequireClass("KDBPhp", true);
10 ADEI::RequireClass("KDBRunIdentifier", "true");
11 ADEI::RequireClass("INTERVAL");
12
13 function PrintXml($xml)
14 {
15     header("Content-type: text/xml");
16     header("Cache-Control: no-cache, must-revalidate");
17     header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
18
19     print $xml;
20 }
21
22 function GetContentType($filename)
23 {
24     if (substr($filename, -4) == ".png") {
25         return "image/png";
26     }
27     else if (substr($filename, -4) == ".txt") {
28         return "text/plain";
29     }
30     else if (substr($filename, -4) == ".xml") {
31         return "application/xml";
32     }
33     else {
34         return "application/octet-stream";
35     }
36 }
37
38 function PrintFile($path, $download)
39 {
40     if (!file_exists($path))
41         throw new ADEIException("File $path does not exist");
42
43     $mimetype = GetContentType($path);
44     $basename = basename($path);
45
46     header("Content-type: $mimetype");
47     if ($download)
48         header("Content-disposition: attachment; filename=\"$basename\"");
49     readfile($path);
50 }
51
52 function PrintError($error)
53 {
54     $xml = "<?xml version=\"1.0\"?>\n<result>\n";
55     $xml .= " <Error>$error</Error>\n</result>";
56
57     PrintXml($xml);
58 }
59
60 try {
61     $kdb = new KDBPhp();
62
63     switch ($_GET['target']) {
64         case 'runs':
65             $interval = new INTERVAL($_GET);
66             $start = $interval->GetWindowStart();
67             $end = $interval->GetWindowEnd();
68
69             PrintXml($kdb->ListRuns($start, $end));
70             break;
71
72         case 'info':
73             if (isset($_GET['run'])) {
74                 PrintXml($kdb->GetRun($_GET['run']));
75             }
76             else
77                 throw new ADEIException("No run specified");
78             break;
79
80         case 'rundesc':
81             if (!isset($_GET['run']))
82                 throw new ADEIException("No run specified");
83             $identifier = new KDBRunIdentifier($_GET['run']);
84             PrintXml($kdb->GetRunDescription($identifier));
85             break;
86
87         case 'file':
88             if (!isset($_GET['filename']))
89                 throw new ADEIException("No filename specified");
90             $filename = $_GET['filename'];
91             if (isset($_GET['run'])) {
92                 $identifier = new KDBRunIdentifier($_GET['run']);
93                 $file = new KDBFileIdentifier($identifier, $filename);
94                 $path = $kdb->GetAbsolutePath($file);
95             }
96             else {
97                 $file = new KDBFileIdentifier($filename);
98                 $path = $kdb->GetAbsolutePath($file);
99             }
100
101             if (isset($_GET['download']) && $_GET['download'] == "yes") {
102                 $download = true;
103             }
104             else {
105                 $download = false;
106             }
107
108             PrintFile($path, $download);
109             break;
110
111         default:
112             if (isset($_GET['target'])) {
113                 $target = $_GET['target'];
114                 $message = "Unknown target ($target) is specified";
115                 throw new ADEIException($message);
116             }
117             else
118                 throw new ADEIException("The target is not specified");
119     }
120 }
121 catch (ADEIException $e) {
122     PrintError($e->getMessage());
123 }
124 ?>
125
Note: See TracBrowser for help on using the browser.