This repository has been archived by the owner on Dec 6, 2019. It is now read-only.
/
Dashboard.php
194 lines (153 loc) · 6.72 KB
/
Dashboard.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<?php
/**
* phpVMS - Virtual Airline Administration Software
* Copyright (c) 2008 Nabeel Shahzad
* For more information, visit www.phpvms.net
* Forums: http://www.phpvms.net/forum
* Documentation: http://www.phpvms.net/docs
*
* phpVMS is licenced under the following license:
* Creative Commons Attribution Non-commercial Share Alike (by-nc-sa)
* View license.txt in the root, or visit http://creativecommons.org/licenses/by-nc-sa/3.0/
*
* @author Nabeel Shahzad
* @copyright Copyright (c) 2008, Nabeel Shahzad
* @link http://www.phpvms.net
* @license http://creativecommons.org/licenses/by-nc-sa/3.0/
* @package module_admin_dashboard
*/
/**
* This file handles any misc tasks that need to be done.
* Loaded at the very end
*/
class Dashboard extends CodonModule {
public function HTMLHead() {
$this->set('sidebar', 'sidebar_dashboard.tpl');
}
public function index() {
/* Dashboard.tpl calls the functions below
*/
$this->CheckForUpdates();
CentralData::send_vastats();
$this->set('unexported_count', count(PIREPData::getReportsByExportStatus(false)));
$this->render('dashboard.tpl');
}
public function pirepcounts() {
# Create the chart
//$reportcounts = '';
$data = PIREPData::getIntervalDataByDays(array(), 30);
if (!$data) {
$data = array(); // so it doesn't error out
}
$bar_values = array();
$bar_titles = array();
foreach ($data as $val) {
$bar_titles[] = $val->ym;
$bar_values[] = floatval($val->total);
}
OFCharts::add_data_set($bar_titles, $bar_values);
echo OFCharts::create_line_graph('Past 30 days PIREPS');
}
public function about() {
$this->render('core_about.tpl');
}
public function CheckInstallFolder() {
if (file_exists(SITE_ROOT . '/install')) {
$this->set('message', 'The install folder still exists!! This poses a security risk. Please delete it immediately');
$this->render('core_error.tpl');
}
}
/**
* Show the notification that an update is available
*/
public function CheckForUpdates() {
if (Config::Get('CHECK_RELEASE_VERSION') == true) {
$key = 'PHPVMS_LATEST_VERSION';
$feed = CodonCache::read($key);
if ($feed === false) {
$url = Config::Get('PHPVMS_API_SERVER') . '/version/get/json/';
# Default to fopen(), if that fails it'll use CURL
$file = new CodonWebService();
$contents = @$file->get($url);
# Something should have been returned
if ($contents == '') {
$msg = '<br /><b>Error:</b> The phpVMS update server could not be contacted.
Check to make sure allow_url_fopen is set to ON in your php.ini, or
that the cURL module is installed (contact your host).';
$this->set('latestnews', $msg);
return;
}
#$xml = @simplexml_load_string($contents);
$message = json_decode($contents);
if (!$message) {
$msg = '<br /><b>Error:</b> There was an error retrieving news. It may be temporary.
Check to make sure allow_url_fopen is set to ON in your php.ini, or
that the cURL module is installed (contact your host).';
$this->set('latestnews', $msg);
return;
}
CodonCache::write($key, $message, 'medium_well');
}
$version = $message->version;
if (Config::Get('CHECK_BETA_VERSION') == true) {
$version = $message->betaversion;
}
$postversion = intval(str_replace('.', '', trim($version)));
$currversion = intval(str_replace('.', '', PHPVMS_VERSION));
if ($currversion < $postversion) {
if (Config::Get('CHECK_BETA_VERSION') == true) {
$this->set('message', 'A beta version ' . $version . ' is available for download!');
} else {
$this->set('message', 'Version ' . $version . ' is available for download! Please update ASAP');
}
$this->set('updateinfo', Template::GetTemplate('core_error.tpl', true));
}
/* Retrieve latest news from Feedburner RSS, in case the phpVMS site is down
*/
$key = 'PHPVMS_NEWS_FEED';
$feed_contents = CodonCache::read($key);
if ($feed_contents === false) {
$feed_contents = $file->get(Config::Get('PHPVMS_NEWS_FEED'));
CodonCache::write($key, $feed_contents, 'medium_well');
}
$i = 1;
$count = 5;
$contents = '';
$feed = simplexml_load_string($feed_contents);
foreach ($feed->channel->item as $news) {
$news_content = (string) $news->description;
$guid = (string) $news->guid;
$title = (string) $news->title;
$date_posted = str_replace('-0400', '', (string) $news->pubDate);
$contents .= "<div class=\"newsitem\">";
$contents .= '<a href="'.$guid.'"><b>'.$title.'</b></a><br />';
$contents .= $news_content;
$contents .= '<br /><br />Posted: '.$date_posted;
$contents .= '</div>';
if ($i++ == $count)
break;
}
$this->set('phpvms_news', $contents);
if (Config::Get('VACENTRAL_ENABLED') == true) {
/* Get the latest vaCentral News */
$contents = $file->get(Config::Get('VACENTRAL_NEWS_FEED'));
$feed = simplexml_load_string($contents);
$contents = '';
$i = 1;
$count = 5; // Show the last 5
foreach ($feed->channel->item as $news) {
$news_content = (string )$news->description;
$date_posted = str_replace('-0400', '', (string )$news->pubDate);
$contents .= "<div class=\"newsitem\">
<b>{$news->title}</b> {$news_content}
<br /><br />
Posted: {$date_posted}
</div>";
if ($i++ == $count)
break;
}
$this->set('vacentral_news', $contents);
}
}
}
}