1 |
<?php |
---|
2 |
/* |
---|
3 |
* this is a sample of a minimal application script required to |
---|
4 |
* get a chameleon application running with a template and a |
---|
5 |
* local map file. Most applications should actually just |
---|
6 |
* copy this file and modify the template and mapfile |
---|
7 |
* parts and should not need to do a lot more here. |
---|
8 |
*/ |
---|
9 |
include( "/usr/local/chameleon-2.2.1/htdocs/chameleon.php" ); |
---|
10 |
|
---|
11 |
|
---|
12 |
$szTemplate = "./nccoos.html"; |
---|
13 |
$szMapFile = "../maps/nccoos_metric.map"; |
---|
14 |
|
---|
15 |
class SampleApp extends Chameleon |
---|
16 |
{ |
---|
17 |
function SampleApp() |
---|
18 |
{ |
---|
19 |
parent::Chameleon(); |
---|
20 |
$this->moMapSession = new MapSession_RW; |
---|
21 |
$this->moMapSession->setTempDir( getSessionSavePath()); |
---|
22 |
} |
---|
23 |
|
---|
24 |
function CWCProcessURL(&$oHTTPFormVars) |
---|
25 |
{ |
---|
26 |
$bRes = parent::CWCProcessURL($oHTTPFormVars); |
---|
27 |
|
---|
28 |
if(empty($_REQUEST['OFFSET'])) |
---|
29 |
{ |
---|
30 |
$oMap = $this->moMapSession->oMap; |
---|
31 |
$label_layer = $oMap->getLayerByName('request_timestamp'); |
---|
32 |
$class = $label_layer->getClass(0); |
---|
33 |
|
---|
34 |
//Eastern Time - offset for timestamp labels |
---|
35 |
$time_eastern = time() - (2 * 60 * 60); |
---|
36 |
|
---|
37 |
//GMT - 2 hr offset for DB requests |
---|
38 |
$time_gmt = strtotime (gmdate('d M Y H:i:s')); |
---|
39 |
$offset = $time_gmt - (2 * 60 * 60); |
---|
40 |
|
---|
41 |
//GMT - 4 for CODAR default |
---|
42 |
$codar_offset = $time_gmt - (4 * 60 * 60); |
---|
43 |
|
---|
44 |
$timestamp = date('m-d-Y g\:\0\0 a', $time_eastern) ."\n"; |
---|
45 |
$class->settext($label_layer,"$timestamp"); |
---|
46 |
|
---|
47 |
$nLayers = $oMap->numlayers; |
---|
48 |
for ($i=0;$i<$nLayers;$i++) |
---|
49 |
{ |
---|
50 |
$oLayer = $oMap->getLayer($i); |
---|
51 |
$db_processing = $oLayer->getMetaData('db_processing'); |
---|
52 |
|
---|
53 |
// all WMS obs |
---|
54 |
if ($oLayer->connectiontype == MS_WMS && $oLayer->group == 'Observations') |
---|
55 |
{ |
---|
56 |
$con_string = $oLayer->GetMetaData("wms_onlineresource"); |
---|
57 |
$value = '&time_offset_hours=2'; |
---|
58 |
$new_con_string = $con_string.$value; |
---|
59 |
//print $new_con_string; |
---|
60 |
$oLayer->set('connection', $new_con_string); |
---|
61 |
} |
---|
62 |
|
---|
63 |
// for codar layer - dif time stamp than regular obs |
---|
64 |
if ($oLayer->connectiontype == MS_WMS && $oLayer->name == 'RADAR_large') |
---|
65 |
{ |
---|
66 |
//timestamp format is 2006-01-19 16:00 |
---|
67 |
$request_codar_time= date('Y_m_d_H_00_00', $codar_offset); |
---|
68 |
|
---|
69 |
$codar_connection = $oLayer->GetMetaData("wms_onlineresource"); |
---|
70 |
$new_codar_connection = $codar_connection.'&time='.$request_codar_time; |
---|
71 |
$oLayer->set('connection', $new_codar_connection); |
---|
72 |
} |
---|
73 |
|
---|
74 |
// DB 1 = JPOP winds |
---|
75 |
if ($oLayer->connectiontype == MS_POSTGIS && $db_processing == '1') |
---|
76 |
{ |
---|
77 |
//timestamp format is 2006-01-16 16:00 |
---|
78 |
$db_request_time = date('Y-m-d H\:i', $offset); |
---|
79 |
$oLayer->setFilter('report_time_stamp = date_trunc(\'hour\',timestamp without time zone \''.$db_request_time.'\')'); |
---|
80 |
} |
---|
81 |
|
---|
82 |
// DB 2 = IS currents, sync with codar TS |
---|
83 |
if ($oLayer->connectiontype == MS_POSTGIS && $db_processing == '2') |
---|
84 |
{ |
---|
85 |
$cur_request_time = date('Y-m-d H\:i', $codar_offset); |
---|
86 |
$oLayer->setFilter('(report_time_stamp = date_trunc(\'hour\',timestamp without time zone \''.$cur_request_time.'\')) and (surface_or_bottom = \'surface\')'); |
---|
87 |
} |
---|
88 |
|
---|
89 |
// for ADCP currents from Xenia - sync with codar TS |
---|
90 |
if ($oLayer->connectiontype == MS_POSTGIS && $db_processing == '4') |
---|
91 |
{ |
---|
92 |
//timestamp format is 2006-01-19 16:00 |
---|
93 |
$cur_request_time = date('Y-m-d H\:i', $codar_offset); |
---|
94 |
$oLayer->setFilter('m_type_id = 41 and (sensor_id IN (select row_id from sensor where type_id = 4 )) and (m_date > (timestamp without time zone \''.$cur_request_time.'\' - interval \'30 minutes\' )) and (m_date < (timestamp without time zone \''.$cur_request_time.'\' + interval \'31 minutes\'))'); |
---|
95 |
} |
---|
96 |
|
---|
97 |
|
---|
98 |
} |
---|
99 |
|
---|
100 |
return $bRes; |
---|
101 |
} |
---|
102 |
|
---|
103 |
else |
---|
104 |
{ |
---|
105 |
return $bRes; |
---|
106 |
} |
---|
107 |
|
---|
108 |
} |
---|
109 |
} |
---|
110 |
|
---|
111 |
$oApp = new SampleApp(); |
---|
112 |
$oApp->registerSkin( 'skins/sample' ); |
---|
113 |
$oApp->CWCInitialize( $szTemplate, $szMapFile ); |
---|
114 |
$oApp->CWCExecute(); |
---|
115 |
|
---|
116 |
?> |
---|