-
Notifications
You must be signed in to change notification settings - Fork 19
/
export_downtimes.php
43 lines (31 loc) · 1.29 KB
/
export_downtimes.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
<?php
session_start();
include_once 'directory.php';
$resourceID = $_GET['resourceID'];
$archivedFlag = (!empty($_GET['archived']) && $_GET['archived'] == 1) ? true:false;
$resource = new Resource(new NamedArguments(array('primaryKey' => $resourceID)));
$util = new Utility();
$organizationArray = $resource->getOrganizationArray();
$exportDowntimes = array();
if (count($organizationArray) > 0) {
$downtimedOrgs = array();
foreach ($organizationArray as $orgData) {
if (!in_array($orgData['organizationID'],$downtimedOrgs)) {
// todo: create downtimes repo so we don't have to initialize an organization object from the wrong module
$organization = new Organization(new NamedArguments(array('primaryKey' => $orgData['organizationID'])));
$exportDowntimes = array_merge($exportDowntimes,$organization->getExportableDowntimes($archivedFlag));
$downtimedOrgs[] = $orgData['organizationID'];
}
}
}
$exportDowntimes = array_merge($exportDowntimes,$resource->getExportableDowntimes($archivedFlag));
header("Pragma: public");
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=\"downtimes.csv\"");
$out = fopen('php://output', 'w');
fputcsv($out,array_keys($exportDowntimes[0]));
foreach ($exportDowntimes as $downtime) {
fputcsv($out, $downtime);
}
fclose($out);
?>