/openshift/adei

To get this branch, use:
bzr branch http://darksoft.org/webbzr/openshift/adei

« back to all changes in this revision

Viewing changes to setups/katrin/services/katrin.php

  • Committer: Suren A. Chilingaryan
  • Date: 2012-02-07 22:44:15 UTC
  • Revision ID: csa@dside.dyndns.org-20120207224415-sy360wa1ammhd1ph
Use localization subsystem, updated Katrin configs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
// $Id: katrin.php 8100 2010-07-15 12:39:05Z s_voec01 $
3
 
// Author: Sebastian Voecking <sebastian.voecking@uni-muenster.de>
4
 
 
5
 
global $ADEI;
6
 
 
7
 
ADEI::RequireClass('KDBConstants', TRUE);
8
 
ADEI::RequireClass('KDBFileIdentifier', TRUE);
9
 
ADEI::RequireClass('KDBPhp', TRUE);
10
 
ADEI::RequireClass('KDBRunIdentifier', TRUE);
11
 
 
12
 
function PrintXml($out, $xml)
13
 
{
14
 
    header("Content-type: text/xml");
15
 
    header("Cache-Control: no-cache, must-revalidate");
16
 
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
17
 
 
18
 
    if ($out) {
19
 
        fwrite($out, $xml);
20
 
        fclose($out);
21
 
    }
22
 
    else {
23
 
        print $xml;
24
 
    }
25
 
}
26
 
 
27
 
function GetContentType($filename)
28
 
{
29
 
    if (substr($filename, -4) == ".png") {
30
 
        return "image/png";
31
 
    }
32
 
    else if (substr($filename, -4) == ".txt") {
33
 
        return "text/plain";
34
 
    }
35
 
    else if (substr($filename, -4) == ".xml") {
36
 
        return "application/xml";
37
 
    }
38
 
    else if (substr($filename, -4) == ".svg") {
39
 
        return "image/svg+xml";
40
 
    }
41
 
    else {
42
 
        return "application/octet-stream";
43
 
    }
44
 
}
45
 
 
46
 
function PrintFile($path, $download)
47
 
{
48
 
    if (!file_exists($path))
49
 
        throw new ADEIException("File $path does not exist");
50
 
 
51
 
    $mimetype = GetContentType($path);
52
 
    $basename = basename($path);
53
 
 
54
 
    header("Content-type: $mimetype");
55
 
    if ($download)
56
 
        header("Content-disposition: attachment; filename=\"$basename\"");
57
 
    readfile($path);
58
 
}
59
 
 
60
 
function PrintError($error)
61
 
{
62
 
    $xml = "<?xml version=\"1.0\"?>\n<result>\n";
63
 
    $xml .= " <Error>$error</Error>\n</result>";
64
 
 
65
 
    PrintXml(NULL, $xml);
66
 
}
67
 
 
68
 
$out = NULL;
69
 
 
70
 
try {
71
 
    $kdb = new KDBPhp();
72
 
    $req = new REQUEST();
73
 
 
74
 
    $target = $req->GetProp('target', NULL);
75
 
    $run = new KDBRunIdentifier($req->GetProp('kdb_run', ''));
76
 
    $xslt = $req->GetProp('xslt');
77
 
    $page = $req->GetProp('kdb_page', 1);
78
 
    $date = $req->GetProp('kdb_date', '');
79
 
    $search = urldecode($req->GetProp('kdb_search', ''));
80
 
    $parameters = urldecode($req->GetProp('kdb_parameters', ''));
81
 
    
82
 
    if ($xslt) {
83
 
        $temp_file = tempnam(sys_get_temp_dir(), 'adei_katrin.');
84
 
        $out = @fopen($temp_file, 'w');
85
 
        if (!$out) {
86
 
            throw new ADEIException("I'm not able to create temporary file \"%s\"",
87
 
                                    $temp_file);
88
 
        }
89
 
    }
90
 
    
91
 
    switch ($target) {
92
 
        case 'runs':
93
 
            $interval = $req->CreateInterval();
94
 
            $start = $interval->GetWindowStart();
95
 
            $end = $interval->GetWindowEnd();
96
 
 
97
 
            PrintXml($out, $kdb->ListRuns($start, $end));
98
 
            break;
99
 
 
100
 
        case 'info':
101
 
            if ($run->IsValid()) {
102
 
                PrintXml($out, $kdb->GetRun($_GET['run']));
103
 
            }
104
 
            else {
105
 
                throw new ADEIException("No run specified");
106
 
            }
107
 
            break;
108
 
 
109
 
        case 'rundesc':
110
 
            if (!$run->IsValid()) {
111
 
                PrintXml($out, $kdb->ListLastRuns($date, $search, $parameters,
112
 
                         $page, 30));
113
 
                break;
114
 
            }
115
 
 
116
 
            $subruns = $req->GetProp("kdb_subruns", false);
117
 
            PrintXml($out, $kdb->GetRunDescription($run, $subruns));
118
 
            break;
119
 
 
120
 
        case 'file':
121
 
            $type = KDBConstants::FileTypeValue($req->GetProp('kdb_type'));
122
 
            $file = new KDBFileIdentifier($run, $type);
123
 
            $file->SetName($req->GetProp('kdb_name', ''));
124
 
 
125
 
            $hardware = $req->GetProp('kdb_hardware', NULL);
126
 
            if (isset($hardware)) {
127
 
                $file->SetHardware(KDBConstants::HardwareValue($hardware));
128
 
            }
129
 
 
130
 
            PrintFile($kdb->GetAbsolutePath($file), $download);
131
 
            break;
132
 
 
133
 
        case 'dates':
134
 
            PrintXml($out, $kdb->GetDates($search));
135
 
            break;
136
 
 
137
 
        default:
138
 
            if (isset($target)) {
139
 
                $message = "Unknown target ($target) is specified";
140
 
                throw new ADEIException($message);
141
 
            }
142
 
            else {
143
 
                throw new ADEIException('The target is not specified');
144
 
            }
145
 
    }
146
 
}
147
 
catch (ADEIException $e) {
148
 
    PrintError($e->getMessage());
149
 
}
150
 
 
151
 
if ($temp_file) {
152
 
    echo $ADEI->TransformXML($xslt, $temp_file);
153
 
    @unlink($temp_file);
154
 
}
155
 
 
156
 
?>