mszLanguageResource = str_replace("\\","/",dirname(__FILE__))."/TimeHandler.dbf"; // invoke constructor of parent parent::CWCWidget(); $this->mszTitle = trim($this->moMLT->get("0", "Select an Offset Time")); $this->mnPriority = PRIORITY_HIGH; // set the description for this widget $this->szWidgetDescription = <<moLabel = new CWCLabel( $this ); $this->maAttributes["TITLE"] = new StringAttribute( "TITLE", false ); $this->maAttributes["WIDGETCLASS"] = new StringAttribute( "WIDGETCLASS", false ); $this->mnMaturityLevel = MATURITY_BETA; } function InitDefaults() { parent::InitDefaults(); if (isset($this->maParams["WIDGETCLASS"])) $this->mszWidgetClass = strtoupper($this->maParams["WIDGETCLASS"]); } /** * get the javascript functions for this widget */ function GetJavascriptFunctions() { parent::GetJavascriptFunctions(); if (isset($this->maSharedResourceWidgets["CWCJSAPI"])) $bCWCJSAPI = 1; else $bCWCJSAPI = 0; $aReturn = array(); $szJsFunctionName = "changeOffset"; $szFunction = <<mszHTMLForm}.NAV_OFFSET.value=offset; {$this->mszHTMLForm}.SEL_OFFSET.value=box.options[box.selectedIndex].text; {$this->mszHTMLForm}.NAV_CMD.value = ""; {$this->mszHTMLForm}.submit(); } return; } EOT; $aReturn[$szJsFunctionName] = $szFunction; return $aReturn; } /** * get the HTML variables for this widget */ function GetHTMLHiddenVariables() { parent::GetHTMLHiddenVariables(); $szVariable = "NAV_OFFSET"; $szNavOffset = $this->getVar( "NAV_OFFSET" ); $szValue = " \n"; $aReturn[$szVariable] = $szValue; $szVariable = "SEL_OFFSET"; $szSelOffset = $this->getVar( "SEL_OFFSET" ); $szValue = " \n"; $aReturn[$szVariable] = $szValue; return $aReturn; } /** * process the url looking for timehandler requests */ function ParseURL() { parent::ParseURL(); if ($this->isVarSet( "NAV_OFFSET" ) && $this->getVar( "NAV_OFFSET" ) != "") { $szOffset = $this->getVar( "NAV_OFFSET" ); $oMap = $this->moMapObject->oMap; //hide mouseovers/insitu currents if offset is not 2 //get layers to alter $mouse_layer = $oMap->getLayerByName('Observation MouseOvers'); if ($szOffset != 2) { // hide MouseOver option in legend $mouse_layer->set('group','Hidden'); $mouse_layer->SetMetaData('legendvis','hidden'); //if MouseOvers are ON when the time is changed these will make sure it doesn't render $mouse_layer->set('minscale','10000000'); $codar_offset = $szOffset; } else { //return MouseOver to legend since -2 hrs $mouse_layer->set('group','Observations'); $mouse_layer->SetMetaData('legendvis',''); $codar_offset = $szOffset + 2; } //here is the meat of the time offset handling $label_layer = $oMap->getLayerByName('request_timestamp'); $class = $label_layer->getClass(0); //Eastern Time - offset for timestamp labelling $request_time_eastern = time() - ($szOffset * 60 * 60); //format and send to mapfile for labelling $timestamp = date('m-d-Y g\:\0\0 a', $request_time_eastern); $class->settext($label_layer,"$timestamp"); //GMT time - offset for DB request $request_time = (strtotime (gmdate("m/d/Y H:i:s"))) - ($szOffset * 60 * 60); //GMT time - offset and then reformatted for QuikSCAT WMS service $quikscat_time = date('Y_m_d_H_i_\0', $request_time); //GMT time - offset for CODAR DB request $codar_request_time = (strtotime (gmdate("m/d/Y H:i:s"))) - ($codar_offset * 60 * 60); $nLayers = $oMap->numlayers; for ($i=0;$i<$nLayers;$i++) { $oLayer = $oMap->getLayer($i); $db_processing = $oLayer->getMetaData('db_processing'); if ($oLayer->connectiontype == MS_WMS && $oLayer->group == 'Observations' && $oLayer->name != 'quikscat') { //$con_string = $oLayer->connection; $con_string = $oLayer->GetMetaData("wms_onlineresource"); $new_con_string = $con_string.'&time_offset_hours='.$szOffset; //print $new_con_string; $oLayer->set('connection', $new_con_string); } //handling for local QuikSCAT layers if ($oLayer->connectiontype == MS_WMS && $oLayer->name == 'quikscat_wms') { $qs_connection = $oLayer->GetMetaData("wms_onlineresource"); $new_qs_connection = $qs_connection.'&time='.$quikscat_time; //print $new_qs_connection; $oLayer->set('connection', $new_qs_connection); } // for seacoos_test OBS layers if ($oLayer->connectiontype == MS_POSTGIS && $db_processing == '1') { //timestamp format is 2006-01-19 16:00 $request_time_db = date('Y-m-d H\:i', $request_time); $oLayer->setFilter('report_time_stamp = date_trunc(\'hour\',timestamp without time zone \''.$request_time_db.'\')'); } // for codar layer - dif time stamp than regular obs if ($oLayer->connectiontype == MS_POSTGIS && $db_processing == '3') { //timestamp format is 2006-01-19 16:00 $request_codar_db = date('Y-m-d H\:i', $codar_request_time); $oLayer->setFilter('report_time_stamp = date_trunc(\'hour\',timestamp without time zone \''.$request_codar_db.'\')'); } // for IS surface currents - codar TS if ($oLayer->connectiontype == MS_POSTGIS && $db_processing == '2') { $cur_request_time = date('Y-m-d H\:i', $codar_request_time); $oLayer->setFilter('(report_time_stamp = date_trunc(\'hour\',timestamp without time zone \''.$cur_request_time.'\')) and (surface_or_bottom = \'surface\')'); } //for ADCP currents from Xenia - codar TS if ($oLayer->connectiontype == MS_POSTGIS && $db_processing == '4') { //timestamp format is 2006-01-19 16:00 $cur_request_time = date('Y-m-d H\:i', $codar_request_time); //$oLayer->setFilter('m_type_id = 41 and (sensor_id IN (select row_id from sensor where type_id = 4 )) and (d_report_hour = (timestamp without time zone \''.$cur_request_time.'\')) and (d_top_of_hour = 1)'); $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\'))'); } } } return true; } /** * draw this widget */ function DrawPublish() { if (!$this->mbVisible) return ""; if ($this->isVarSet( "SEL_OFFSET" )) $szSelOffset = $this->getVar( "SEL_OFFSET" ); else $szSelOffset = ""; if ($this->mszWidgetClass != "") $szWidgetClass = " CLASS=\"".$this->mszWidgetClass."\""; else $szWidgetClass = ""; $szResult = "\n"; if ($this->isVarSet( "NAV_OFFSET" ) && $this->getVar( "NAV_OFFSET" ) != "") { $timeOffset_end = $this->getVar( "NAV_OFFSET" ); } else { $timeOffset_end = 2; } //Eastern Time $EasternTime = time(); // use offset to build request times $request_time_end = $EasternTime - ($timeOffset_end * 60 * 60); $timeOffset_begin = $timeOffset_end + 1; $request_time_begin = $EasternTime - ($timeOffset_begin * 60 * 60); //$timestamp_now = date('m-d-Y g\:\0\0 a'); $timestamp_end = date('m-d-Y g\:\0\0 a', $request_time_end); $timestamp_end_hour = date('g\:\0\0 a', $request_time_end); $timestamp_begin = date('m-d-Y g\:\3\0 a', $request_time_begin); $timestamp_begin_hour = date('m-d-Y g\:\3\0', $request_time_begin); // RS Timestamp lookup for labeling - in GMT, out Eastern // Site Path $site_path = "/opt/inventory/htdocs/"; // Include ADODB library require_once($site_path . "/admin/adodb/adodb.inc.php"); // Connection definitions $database_type = "postgres7"; $database_user = "lookup"; $database_database = "seacoos_test"; $database_server = "coriolis.marine.unc.edu"; $database_password = "lookup"; // takes request time from WMS call above and reformts it $request_time = (strtotime (gmdate("m/d/Y H:i:s"))) - ($timeOffset_end * 60 * 60); $rs_request_time = date('Y-m-d H:i:\0\0', $request_time); // Initialize ADODB connection $db = ADONewConnection($database_type); $db->Connect($database_server, $database_user,$database_password,$database_database); // Construct queries - looks for nearest overpass time not older than 48 hrs // loop through for quikscat, modis_sst, avhrr $rs_layers = array("quikscat","modis_sst","avhrr"); foreach ($rs_layers as $l) { $table = $l."_timestamps"; $query = "select $l from $table" ." where abs(extract(epoch from timestamp without time zone '$rs_request_time')" ." - extract(epoch from $l))" ." = (select min(abs((extract(epoch from timestamp without time zone '$rs_request_time'))" ." - extract(epoch from $l)))" ." from $table)" ." and abs(extract(epoch from timestamp without time zone '$rs_request_time')" ." - extract(epoch from $l))" ." <= 60*60*24*2"; $recordSet = $db->Execute($query); if (!$recordSet) { print $db->ErrorMsg(); } else { while (!$recordSet->EOF) { $db_time = $recordSet->fields[0]; $recordSet->MoveNext(); } } $recordSet->Close(); $rs_timestamp_utc = strtotime($db_time); ## need to add Eastern to GMT offset var - hardcoded for now $rs_timestamp_eastern = $rs_timestamp_utc - (5*60*60); if ($l == "quikscat") { $quikscat_time = date('m-d-Y g\:\0\0 a', $rs_timestamp_eastern); } if ($l == "modis_sst") { $modis_timestamp = date('m-d-Y g\:i a', $rs_timestamp_eastern); } if ($l == "avhrr") { $avhrr_timestamp = date('m-d-Y g\:i a', $rs_timestamp_eastern); } } $db->Close(); //added b/c CODAR default will be -4 hrs if ($this->getVar( "NAV_OFFSET" ) == "" OR $this->getVar( "NAV_OFFSET" ) == "2" ) { $codar_time_raw = $EasternTime - (4 * 60 * 60); $codar_time = date('m-d-Y g\:\0\0 a', $codar_time_raw); } else { $codar_time = $timestamp_end; } //return time table //$szResult .="Now: ".$timestamp_now."\n"; $szResult .="Data Display Time: ".$timestamp_end."\n"; $szResult .="SST, Water Level, & Wind:".$timestamp_begin_hour." - ".$timestamp_end_hour."\n"; $szResult .="Precipitation RADAR: ".$timestamp_end."\n"; $szResult .="
\n"; $szResult .="QuikSCAT winds: ".$quikscat_time."\n"; $szResult .="Surface Currents: ".$codar_time."\n"; $szResult .="AVHRR SST: ".$avhrr_timestamp."\n"; $szResult .="MODIS RGB/SST: ".$modis_timestamp."\n"; $szResult = $this->moLabel->DrawPublish( $szResult ); return $szResult; } } ?>