histogram: Make histograms crash less
[ninja.git] / application / helpers / csv.php
blobee0ed0b7afdc6e16a83f3a2ac82404616d38d218
1 <?php defined('SYSPATH') OR die('No direct access allowed.');
3 /**
4 * Helper for CSV functionality
5 */
6 class csv_Core
8 /**
9 * Set HTTP headers appropriate for CSV files
11 * This is trickier than it should be, due to IE
13 public static function csv_http_headers($type, $options) {
14 if (headers_sent()) {
15 // gosh darnit, now I can't do anything. Oh well...
16 return;
18 $filename = $type . '.csv';
19 if ($options['schedule_id']) {
20 $schedule_info = Scheduled_reports_Model::get_scheduled_data($options['schedule_id']);
21 if ($schedule_info)
22 $filename = $schedule_info['filename'];
24 header("Content-disposition: attachment; filename=".$filename);
25 if (isset($_SERVER['HTTP_USER_AGENT']) &&
26 (strpos($_SERVER['HTTP_USER_AGENT'],'MSIE 7') || strpos($_SERVER['HTTP_USER_AGENT'],'MSIE 8')))
28 header("Pragma: hack");
29 header("Content-Type: application/octet-stream");
30 header("Content-Transfer-Encoding: binary");
31 } else {
32 header("Content-type: text/csv");
36 /**
37 * Return the fields used in an avail report
39 public static function avail_fields($type)
41 $fields['hosts'] = array(
42 'HOST_NAME',
43 'TIME_UP_SCHEDULED',
44 'PERCENT_TIME_UP_SCHEDULED',
45 'PERCENT_KNOWN_TIME_UP_SCHEDULED',
46 'TIME_UP_UNSCHEDULED',
47 'PERCENT_TIME_UP_UNSCHEDULED',
48 'PERCENT_KNOWN_TIME_UP_UNSCHEDULED',
49 'TOTAL_TIME_UP',
50 'PERCENT_TOTAL_TIME_UP',
51 'PERCENT_KNOWN_TIME_UP',
52 'TIME_DOWN_SCHEDULED',
53 'PERCENT_TIME_DOWN_SCHEDULED',
54 'PERCENT_KNOWN_TIME_DOWN_SCHEDULED',
55 'TIME_DOWN_UNSCHEDULED',
56 'PERCENT_TIME_DOWN_UNSCHEDULED',
57 'PERCENT_KNOWN_TIME_DOWN_UNSCHEDULED',
58 'TOTAL_TIME_DOWN',
59 'PERCENT_TOTAL_TIME_DOWN',
60 'PERCENT_KNOWN_TIME_DOWN',
61 'TIME_UNREACHABLE_SCHEDULED',
62 'PERCENT_TIME_UNREACHABLE_SCHEDULED',
63 'PERCENT_KNOWN_TIME_UNREACHABLE_SCHEDULED',
64 'TIME_UNREACHABLE_UNSCHEDULED',
65 'PERCENT_TIME_UNREACHABLE_UNSCHEDULED',
66 'PERCENT_KNOWN_TIME_UNREACHABLE_UNSCHEDULED',
67 'TOTAL_TIME_UNREACHABLE',
68 'PERCENT_TOTAL_TIME_UNREACHABLE',
69 'PERCENT_KNOWN_TIME_UNREACHABLE',
70 'TIME_UNDETERMINED_NOT_RUNNING',
71 'PERCENT_TIME_UNDETERMINED_NOT_RUNNING',
72 'TIME_UNDETERMINED_NO_DATA',
73 'PERCENT_TIME_UNDETERMINED_NO_DATA',
74 'TOTAL_TIME_UNDETERMINED',
75 'PERCENT_TOTAL_TIME_UNDETERMINED'
77 $fields['services'] = array(
78 'HOST_NAME',
79 'SERVICE_DESCRIPTION',
80 'TIME_OK_SCHEDULED',
81 'PERCENT_TIME_OK_SCHEDULED',
82 'PERCENT_KNOWN_TIME_OK_SCHEDULED',
83 'TIME_OK_UNSCHEDULED',
84 'PERCENT_TIME_OK_UNSCHEDULED',
85 'PERCENT_KNOWN_TIME_OK_UNSCHEDULED',
86 'TOTAL_TIME_OK',
87 'PERCENT_TOTAL_TIME_OK',
88 'PERCENT_KNOWN_TIME_OK',
89 'TIME_WARNING_SCHEDULED',
90 'PERCENT_TIME_WARNING_SCHEDULED',
91 'PERCENT_KNOWN_TIME_WARNING_SCHEDULED',
92 'TIME_WARNING_UNSCHEDULED',
93 'PERCENT_TIME_WARNING_UNSCHEDULED',
94 'PERCENT_KNOWN_TIME_WARNING_UNSCHEDULED',
95 'TOTAL_TIME_WARNING',
96 'PERCENT_TOTAL_TIME_WARNING',
97 'PERCENT_KNOWN_TIME_WARNING',
98 'TIME_UNKNOWN_SCHEDULED',
99 'PERCENT_TIME_UNKNOWN_SCHEDULED',
100 'PERCENT_KNOWN_TIME_UNKNOWN_SCHEDULED',
101 'TIME_UNKNOWN_UNSCHEDULED',
102 'PERCENT_TIME_UNKNOWN_UNSCHEDULED',
103 'PERCENT_KNOWN_TIME_UNKNOWN_UNSCHEDULED',
104 'TOTAL_TIME_UNKNOWN',
105 'PERCENT_TOTAL_TIME_UNKNOWN',
106 'PERCENT_KNOWN_TIME_UNKNOWN',
107 'TIME_CRITICAL_SCHEDULED',
108 'PERCENT_TIME_CRITICAL_SCHEDULED',
109 'PERCENT_KNOWN_TIME_CRITICAL_SCHEDULED',
110 'TIME_CRITICAL_UNSCHEDULED',
111 'PERCENT_TIME_CRITICAL_UNSCHEDULED',
112 'PERCENT_KNOWN_TIME_CRITICAL_UNSCHEDULED',
113 'TOTAL_TIME_CRITICAL',
114 'PERCENT_TOTAL_TIME_CRITICAL',
115 'PERCENT_KNOWN_TIME_CRITICAL',
116 'TIME_UNDETERMINED_NOT_RUNNING',
117 'PERCENT_TIME_UNDETERMINED_NOT_RUNNING',
118 'TIME_UNDETERMINED_NO_DATA',
119 'PERCENT_TIME_UNDETERMINED_NO_DATA',
120 'TOTAL_TIME_UNDETERMINED',
121 'PERCENT_TOTAL_TIME_UNDETERMINED'
123 if (isset($fields[$type])) {
124 return $fields[$type];
126 else {
127 $ret = $fields[strpos($type, 'host') === 0 ? 'hosts' : 'services'];
128 array_unshift($ret, strtoupper($type));
129 return $ret;