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'); $is_currents_layer = $oMap->getLayerByName('in_situ_currents'); $is_currents_arrow_layer = $oMap->getLayerByName('in_situ_currents_arrow'); $qs_layer = $oMap->getLayerByName('QS_1'); 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'); //if is_current are ON when the time is changed these will make sure they don't render $is_currents_layer->set('minscale','10000000'); $is_currents_arrow_layer->set('minscale','10000000'); $codar_offset = $szOffset; } else { //return MouseOver to legend since -2 hrs $mouse_layer->set('group','Observations'); $mouse_layer->SetMetaData('legendvis',''); //return IS current layers to normal scale dependencies $is_currents_layer->set('minscale','150000'); $is_currents_arrow_layer->set('minscale','150000'); $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_\0_\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); } 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.'\')'); } 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.'\')'); } // if ($oLayer->connectiontype == MS_POSTGIS && $db_processing == '2') // { // $request_time_db = date('Y-m-d H\:i', $request_time); // $oLayer->setFilter('((select count(*) from current_prod where (report_time_stamp = date_trunc(\'hour\',timestamp without time zone \''.$request_time_db.'\'))) < 1)'); // } } } 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); //added to handle QuikSCAT overpass labeling - depends on request time of day $request_hour = date ('G', $request_time_end); //if request hour + offset is less than 9 (access time is 2am~9am), then use PM timestamp of the date prior or "no data" - this handles files that have not been created yet if ($request_hour + $timeOffset_end < "9") { //$quikscat_time = 'No overpass available'; $request_date_prior = $request_time_end - (24 * 60 * 60); $quikscat_time = date('m-d-Y \6\:\0\0\ - \7\:\0\0 \p\m', $request_date_prior); } //if request hour + offset is > 14 but < 22 (access time is 2pm~10pm), then AM timestamp should be returned or "no data" - this handles files that have not been created yet elseif ($request_hour + $timeOffset_end > "14" && $request_hour + $timeOffset_end < "22") { //$quikscat_time = 'No overpass available'; $quikscat_time = date('m-d-Y \5\:\0\0\ - \7\:\0\0 \a\m', $request_time_end); } //if request time is 1 Eastern and before or = 13 then QS time is 5am-7am of that date elseif ($request_hour >= "1" AND $request_hour <= "13") { $quikscat_time = date('m-d-Y \5\:\0\0\ - \7\:\0\0 \a\m', $request_time_end); } //if request time is 13 Eastern and before 23:59 then QS time is 6pm-7pm of that date else { $quikscat_time = date('m-d-Y \6\:\0\0\ - \7\:\0\0 \p\m', $request_time_end); } //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; } //get RS timestamps for given offset $avhrr_timestamp_raw = file_get_contents('http://seacoos3.marine.unc.edu/msapps/rs_timestamps/avhrrsst'.$timeOffset_end.'.txt'); //$avhrr_timestamp = str_replace("/","-",$avhrr_timestamp_raw); $avhrr_timestamp_utc = strtotime($avhrr_timestamp_raw); $avhrr_timestamp_eastern = $avhrr_timestamp_utc - ($TimeDiff*60*60); $avhrr_timestamp = date('m-d-Y g\:i a', $avhrr_timestamp_eastern); $modis_timestamp_raw = file_get_contents('http://seacoos3.marine.unc.edu/msapps/rs_timestamps/modissst'.$timeOffset_end.'.txt'); //$avhrr_timestamp_utc = str_replace("/","-",$modis_timestamp_raw); $modis_timestamp_utc = strtotime($modis_timestamp_raw); $modis_timestamp_eastern = $modis_timestamp_utc - ($TimeDiff*60*60); $modis_timestamp = date('m-d-Y g\:i a', $modis_timestamp_eastern); //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): ".$codar_time."\n"; $szResult .="AVHRR SST: ".$avhrr_timestamp."\n"; $szResult .="MODIS RGB/SST: ".$modis_timestamp."\n"; $szResult = $this->moLabel->DrawPublish( $szResult ); return $szResult; } } ?>