3
require("stream/stream.php");
9
var $multimode; // STREAM is used for joining groups
11
var $multigroup; // Multiple groups expected
12
var $multirdr; // Multiple readers expected
25
const MASK_STANDARD = 0;
27
const MASK_SOURCE = 2;
28
const MASK_COMPLETE = 3;
30
function __construct(DATARequest &$props = NULL, STREAMObjectInterface &$h = NULL, &$format = NULL) {
31
if ($props) $this->req = &$props;
32
else $this->req = new DATARequest();
34
if ($format) $this->format = &$format;
35
else $this->format = $this->req->GetFormatInfo();
37
if ($this->format['handler']) {
38
if (!include_once("handlers/" . strtolower($this->format['handler']) . '.php')) {
39
throw new ADEIException(translate("Unsupported data handler is configured: \"%s\"", $format['handler']));
42
"class" => $this->format['handler'] . "Handler"
46
"class" => "CSVHandler"
50
$this->handler = new $handler["class"]($this->format);
52
if ($this->req->props['mask_mode']) {
53
$this->multimode = !$this->handler->multigroup;
54
} else $this->multimode = false;
58
if (($this->format['filter'])||($this->multimode)) {
59
$this->stream = new STREAM($this->format, $this->output, ($this->multimode?STREAM::MULTIMODE:0)|($this->handler->filewriter?STREAM::FILESTART:0));
60
if ($this->stream->filereader) $this->handler->RequestFilemode();
62
$this->stream = &$this->output;
66
$this->handler->SetOutput($this->stream);
70
function CheckMode() {
71
if ((!$this->multimode)&&(!$this->handler->multigroup)) {
72
if ((!$this->stream)||(!($this->stream instanceof STREAM))||(!$this->stream->joiner)) {
74
$this->stream = new STREAM($this->format, $this->output, STREAM::MULTIMODE|($this->handler->filewriter?STREAM::FILESTART:0));
75
if ($this->stream->filereader) $this->handler->RequestFilemode();
76
$this->handler->SetOutput($this->stream);
78
if (!$this->stream->joiner) {
79
throw new ADEIException(translate("The attempt to create joining STREAM is failed"));
82
$this->multimode = true;
88
if ($this->req->props['mask_mode'] > 1) {
89
switch($this->req->props['mask_mode']) {
90
case EXPORT::MASK_SOURCE:
91
return $this->ExportSource();
92
case EXPORT::MASK_COMPLETE:
93
return $this->ExportAll();
95
throw new ADEIException(translate("Unsupported mask mode (%u)", $this->req->props['mask_mode']));
99
$rdr = $this->req->CreateReader();
100
$grp = $rdr->CreateGroup();
101
$ivl = $rdr->CreateInterval($grp);
102
$msk = $rdr->CreateMask($grp);
104
$this->multigroup = false;
105
$this->multirdr = false;
107
$this->Start($rdr, $grp, $msk, $ivl, 1);
108
$this->SendHeaders($rdr, $grp, $msk, $ivl);
109
$this->ExportGroup($this->req, $rdr, $grp, $ivl, $msk);
113
function ExportSource() {
117
$rdr = $this->req->CreateReader();
119
$this->multigroup = true;
120
$this->multirdr = false;
122
$this->Start($rdr, NULL, $msk, NULL);
123
$this->SendHeaders($rdr, NULL, $msk, NULL);
125
$groups = $rdr->GetGroups();
126
foreach ($groups as &$grp) {
127
$ivl = $rdr->CreateInterval($grp);
129
$this->ExportGroup($this->req, $rdr, $grp, $ivl, $msk);
135
function ExportAll() {
140
$this->multigroup = true;
141
$this->multirdr = true;
143
$this->Start(NULL, NULL, $msk, NULL);
144
$this->SendHeaders(NULL, NULL, $msk, NULL);
146
$list = $this->req->GetSourceList(REQUEST::LIST_ALL);
147
foreach ($list as $sreq) {
149
$dreq = $sreq->CreateDataRequest();
150
} catch (ADEIException $e) {
154
$rdr = $dreq->CreateReader();
156
$groups = $rdr->GetGroups();
157
foreach ($groups as &$grp) {
158
$ivl = $rdr->CreateInterval($grp);
160
$this->ExportGroup($sreq, $rdr, $grp, $ivl, $msk);
167
function Start(READER $rdr = NULL, LOGGROUP $grp = NULL, MASK $msk = NULL, INTERVAL $ivl = NULL, $expected_groups = 0) {
168
$this->filename = false;
171
$this->specials = $this->stream->GetSpecials();
173
$this->stream_args = array(
174
"expected_blocks" => $expected_groups,
175
"extension" => $this->handler->GetExtension()
178
$this->stream->Open($this->stream_args);
180
$this->expected_groups = $expected_groups;
181
if ($this->handler->multigroup) {
182
$this->filename = $this->GetName($rdr, $grp, $msk, $ivl);
184
$stream_args = $this->stream_args;
185
$stream_args["block_number"] = 0;
186
$stream_args["block_title"] = $this->filename;
188
$this->stream->BlockStart($stream_args);
191
$this->specials = array();
194
$this->handler->SequenceStart();
198
$this->handler->SequenceEnd();
201
if ($this->handler->multigroup) $this->stream->BlockEnd();
202
$this->stream->Close();
207
function ExportGroup(REQUEST $req, READER $rdr, LOGGROUP $grp, INTERVAL $ivl, MASK $msk) {
208
global $ROOT_COMBIHIST_LIMIT;
210
if ($this->multirdr) $title = $this->GetGroupName($rdr->srvid, $rdr->dbname, $grp->gid, $msk->name);
211
elseif ($this->multigroup) $title = $this->GetGroupName(false, false, $grp->gid, $msk->name);
212
else $title = $this->GetGroupName(false, false, false, $msk->name);
215
$opts = &$req->GetOptions();
216
$subseconds = !$opts->Get('ignore_subsecond');
218
if (($this->stream)&&(!$this->handler->multigroup)) {
219
$stream_args = array_merge($this->stream_args, array(
220
"expected_blocks" => $this->expected_groups,
221
"block_title" => $title,
225
$stream_args["extension"] = $this->handler->GetExtension();
227
if (in_array("ROOT", $this->specials)) {
228
if ((!isset($ROOT_COMBIHIST_LIMIT))||($ivl->GetWindowSize() < $ROOT_COMBIHIST_LIMIT))
229
$stream_args['root__combhist'] = 1;
231
$stream_args['root__combhist'] = 0;
234
$this->stream->BlockStart($stream_args);
237
$this->handler->GroupStart($title, $subseconds);
238
$rdr->Export($this->handler, $grp, $msk, $ivl->GetWindowStart(), $ivl->GetWindowEnd());
239
$this->handler->GroupEnd();
241
if (($this->stream)&&(!$this->handler->multigroup)) $this->stream->BlockEnd();
244
function SendHeaders(READER $rdr = NULL, LOGGROUP $grp = NULL, MASK $msk = NULL, INTERVAL $ivl = NULL) {
246
$content_type = $this->stream->GetContentType();
248
$content_type = false;
250
if (!$content_type) $content_type = $this->handler->GetContentType();
251
if (!$content_type) {
252
if ($this->format["content_type"]) $content_type = $this->format["content_type"];
253
else $content_type = "application/binary";
257
$extension = $this->stream->GetExtension();
261
if (!$extension) $extension = $this->handler->GetExtension();
263
if($this->format["extension"]) $extension = $this->format["extension"];
264
else if ($this->req->props['format']) $extension = strtolower($this->req->props['format']);
265
else $extension = "adei";
268
if (isset($this->req->props['filename'])) {
269
$name = &$this->req->props['filename'];
270
if (($extension)&&(strpos($name, '.')===false)) $name .= ".$extension";
272
if ($this->filename) $name = $this->filename;
273
else $name = $this->GetName($rdr, $grp, $msk, $ivl);
274
if ($extension) $name .= ".$extension";
277
// echo "$content_type , $name\n";
280
header("Cache-Control: no-cache, must-revalidate");
281
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
282
header("Content-type: $content_type");
283
header("Content-Disposition: attachment; filename=\"$name\"");
286
function GetGroupName($sname, $dname, $gname, $mname, $iname = false) {
287
if ($this->multirdr) $title = $sname . "__" . $dname . "__" . $gname . "/" . $mname;
288
elseif ($this->multigroup) $title = $gname . "/" . $mname;
289
else $title = $mname;
293
function GetName(READER $rdr = NULL, LOGGROUP $grp = NULL, MASK $msk = NULL, INTERVAL $ivl = NULL) {
296
if ((!$this->multirdr)&&($rdr))
297
$name .= $rdr->srvid . "__" . $rdr->dbname;
299
if ((!$this->multigroup)&&($grp)) {
300
$name .= ($name?"__":"") . $grp->gid;
303
if ((!$this->multimask)&&($msk))
304
$name .= ($name?"__":"") . $msk->name;
306
if (!$this->multiivl) {
308
$ivl = new INTERVAL($this->req->GetIntervalInfo());
310
$name .= ($name?"__":"") . $ivl->GetName(NAME_FORMAT_ISO8601);
313
if ($name) return $name;
b'\\ No newline at end of file'