Copyright (c) 2002, DM Solutions Group Inc. * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ include_once(dirname(__FILE__)."/../Widget.php"); include_once(dirname(__FILE__)."/../Label.php"); /** * TimeFilter * * @desc A widget that displays a time range combobox to * display specific layers */ class TimeFilter extends CWCWidget { var $mszInputClass = "CWCTimeFilterInputClass"; var $mszLabelClass = "CWCTimeFilterLabelClass"; var $mszInputStyle = ""; var $mszLabelStyle = ""; /** * build a new widget */ function TimeFilter() { $this->mszLanguageResource = str_replace("\\","/",dirname(__FILE__))."/TimeFilter.dbf"; // invoke constructor of parent parent::CWCWidget(); // set the description for this widget $this->szWidgetDescription = <<mnPriority = PRIORITY_SUPER; $this->maAttributes["INPUTCLASS"] = new StringAttribute( "INPUTCLASS", false ); $this->maAttributes["INPUTSTYLE"] = new StringAttribute( "INPUTSTYLE", false ); $this->maAttributes["LABELCLASS"] = new StringAttribute( "LABELCLASS", false ); $this->maAttributes["LABELSTYLE"] = new StringAttribute( "LABELSTYLE", false ); $this->maAttributes["EARLIESTYEAR"] = new StringAttribute( "EARLIESTYEAR", false ); $this->maAttributes["SHOWTIME"] = new BooleanAttribute( "SHOWTIME", false ); $this->mnMaturityLevel = MATURITY_BETA; } function InitDefaults() { parent::InitDefaults(); if (isset($this->maParams["INPUTCLASS"])) $this->mszInputClass = $this->maParams["INPUTCLASS"]; if (isset($this->maParams["INPUTSTYLE"])) $this->mszInputStyle = $this->maParams["INPUTSTYLE"]; if (isset($this->maParams["LABELCLASS"])) $this->mszLabelClass = $this->maParams["LABELCLASS"]; if (isset($this->maParams["LABELSTYLE"])) $this->mszLabelStyle = $this->maParams["LABELSTYLE"]; } function GetJavascriptOnLoadFunctions() { $bShowTime = $this->getValue("SHOWTIME", "FALSE"); $aReturn = array(); if (stristr($bShowTime, "TRUE") !== false) { $szJsFunctionName = "onloadTimeFilter"; $szFunction = "$szJsFunctionName();\n"; $aReturn[$szJsFunctionName] = $szFunction; } return $aReturn; } /** * get the javascript functions for this widget */ function GetJavascriptFunctions() { $aReturn = array(); $szJsFunctionName = "onloadTimeFilter"; $bSetStartTimezone = (($this->isVarSet( 'start_tz' )) ? "0" : "1"); $szFunction = <<mszHTMLForm}.start_tz.options[{$this->mszHTMLForm}.start_tz.selectedIndex].value; var end_tz = {$this->mszHTMLForm}.end_tz.options[{$this->mszHTMLForm}.end_tz.selectedIndex].value; var setStartTimezone = {$bSetStartTimezone}; if (setStartTimezone == 1) {$this->mszHTMLForm}.start_tz.value = timezone; } EOT; $aReturn[$szJsFunctionName] = $szFunction; $szJsFunctionName = "monthClicked"; $szFunction = <<mszHTMLForm}.start_year.options[{$this->mszHTMLForm}.start_year.selectedIndex].value; var end_year = {$this->mszHTMLForm}.end_year.options[{$this->mszHTMLForm}.end_year.selectedIndex].value; var start_month = {$this->mszHTMLForm}.start_month.options[{$this->mszHTMLForm}.start_month.selectedIndex].value; var end_month = {$this->mszHTMLForm}.end_month.options[{$this->mszHTMLForm}.end_month.selectedIndex].value; if (start_month == 12) { start_month = 1; start_year ++; } else start_month ++; if (end_month == 12) { end_month = 1; end_year ++; } else end_month ++; var startDate = new Date(start_year, start_month-1, 1); var startNbDay = startDate.getTime() - DAY; startDate = new Date(startNbDay); var endDate = new Date(end_year, end_month-1, 1); var endNbDay = endDate.getTime() - DAY; endDate = new Date(endNbDay); var nSelectedStartDay = {$this->mszHTMLForm}.start_day.selectedIndex; var nSelectedEndDay = {$this->mszHTMLForm}.end_day.selectedIndex; //clear day combo var nbEndDay = {$this->mszHTMLForm}.end_day.length; var nbStartDay = {$this->mszHTMLForm}.start_day.length; for (i=0;imszHTMLForm}.end_day.options[0] = null; } for (i=0;imszHTMLForm}.start_day.options[0] = null; } // add day nbEndDay = endDate.getDate(); ilength = {$this->mszHTMLForm}.end_day.length; optionName = new Option("SAME", -1, false, false); {$this->mszHTMLForm}.end_day.options[ilength] = optionName; for (i=0;imszHTMLForm}.end_day.length; {$this->mszHTMLForm}.end_day.options[ilength] = optionName; } nbStartDay = startDate.getDate(); for (i=0;imszHTMLForm}.start_day.length; {$this->mszHTMLForm}.start_day.options[ilength] = optionName; } } EOT; $aReturn[$szJsFunctionName] = $szFunction; return $aReturn; } /** * process the url looking for quickzoom requests */ function ParseURL() { parent::ParseURL(); if ($this->isVarSet( 'bEnableTimeQuery' ) && $this->getVar( 'bEnableTimeQuery' ) == "on") { $nStartYear = (($this->isVarSet( 'start_year' )) ? $this->getVar( 'start_year' ) : "" ); $nStartMonth = (($this->isVarSet( 'start_month' )) ? $this->getVar( 'start_month' ) : "" ); $nStartDay = (($this->isVarSet( 'start_day' )) ? $this->getVar( 'start_day' ) : "" ); $nStartHour = (($this->isVarSet( 'start_hour' )) ? $this->getVar( 'start_hour' ) : "" ); $nStartMinute= (($this->isVarSet( 'start_minute' )) ? $this->getVar( 'start_minute' ) : "" ); $nStartTz = (($this->isVarSet( 'start_tz' )) ? $this->getVar( 'start_tz' ) : "" ); $nEndYear = (($this->isVarSet( 'end_year' )) ? (($this->getVar( 'end_year' ) == -1) ? $this->getVar( 'start_year' ) : $this->getVar( 'end_year' )) : ""); $nEndMonth = (($this->isVarSet( 'end_month' )) ? (($this->getVar( 'end_month' ) == -1) ? $this->getVar( 'start_month' ) : $this->getVar( 'end_month' )) : ""); $nEndDay = (($this->isVarSet( 'end_day' )) ? (($this->getVar( 'end_day' ) == -1) ? $this->getVar( 'start_day' ) : $this->getVar( 'end_day' )) : ""); $nEndHour = (($this->isVarSet( 'end_hour' )) ? (($this->getVar( 'end_hour' ) == -1) ? $this->getVar( 'start_hour' ) : $this->getVar( 'end_hour' )) : ""); $nEndMinute= (($this->isVarSet( 'end_minute' )) ? (($this->getVar( 'end_minute' ) == -1) ? $this->getVar( 'start_minute' ) : $this->getVar( 'end_minute' )) : ""); $nEndTz = (($this->isVarSet( 'end_tz' )) ? (($this->getVar( 'end_tz' ) == -13) ? $this->getVar( 'start_tz' ) : $this->getVar( 'end_tz' )) : ""); $bShowTime = $this->getValue("SHOWTIME", "FALSE"); if (stristr($bShowTime, "TRUE")!==false) { $nStartTime = mktime(($nStartHour+$nStartTz), $nStartMinute,0, $nStartMonth , $nStartDay, $nStartYear); $nEndTime = mktime(($nEndHour+$nEndTz), $nEndMinute, 0, $nEndMonth , $nEndDay, $nEndYear); $szStartTime = date("Y-m-j", $nStartTime)."T". date("H:i", $nStartTime).":0.0Z"; $szEndTime = date("Y-m-j", $nEndTime)."T". date("H:i", $nEndTime).":0.0Z"; } else { $szStartTime = $nStartYear."-".$nStartMonth."-".$nStartDay; $szEndTime = $nEndYear."-".$nEndMonth."-".$nEndDay; } $szValue = $szStartTime."/".$szEndTime; } else $szValue = ""; if ($szValue != "") { $nLayers = $this->moMapObject->oMap->numlayers; for ($i=0;$i<$nLayers;$i++) { $oLayer = $this->moMapObject->oMap->getLayer($i); if ($oLayer->connectiontype == MS_WMS) { $oLayer->setMetadata("wms_time", $szValue); } } } } /** * draw this widget */ function DrawPublish() { $nEarliestYear = $this->getValue("EarliestYear", "1940"); $nStartYear = (($this->isVarSet( 'start_year' )) ? $this->getVar( 'start_year' ) : "" ); $nStartMonth = (($this->isVarSet( 'start_month' )) ? $this->getVar( 'start_month' ) : "" ); $nStartDay = (($this->isVarSet( 'start_day' )) ? $this->getVar( 'start_day' ) : "" ); $nStartHour = (($this->isVarSet( 'start_hour' )) ? $this->getVar( 'start_hour' ) : "" ); $nStartMinute= (($this->isVarSet( 'start_minute' )) ? $this->getVar( 'start_minute' ) : "" ); $nStartTz = (($this->isVarSet( 'start_tz' )) ? $this->getVar( 'start_tz' ) : "" ); $nEndYear = (($this->isVarSet( 'end_year' )) ? $this->getVar( 'end_year' ) : "" ); $nEndMonth = (($this->isVarSet( 'end_month' )) ? $this->getVar( 'end_month' ) : "" ); $nEndDay = (($this->isVarSet( 'end_day' )) ? $this->getVar( 'end_day' ) : "" ); $nEndHour = (($this->isVarSet( 'end_hour' )) ? $this->getVar( 'end_hour' ) : "-1" ); $nEndMinute= (($this->isVarSet( 'end_minute' )) ? $this->getVar( 'end_minute' ) : "-1" ); $nEndTz = (($this->isVarSet( 'end_tz' )) ? $this->getVar( 'end_tz' ) : "-13" ); $nCurrentYear = date("Y"); $bShowTime = $this->getValue("SHOWTIME", "FALSE"); if (!$this->mbVisible) return ""; if ($this->isVarSet( "START_TIME" ) && $this->isVarSet( "END_TIME" )) { $szStartTime = $this->getVar( "START_TIME" ); $szEndTime = $this->getVar( "END_TIME" ); } else { $szStartTime = ""; $szEndTime = ""; } //szInputClass and szInputStyle cause problems in NS4 $szInputClass = ""; //if ( strlen($this->mszInputClass) > 0 ) // $szInputClass = " CLASS=\"$this->mszInputClass\""; $szInputStyle = ""; //if ( strlen($this->mszInputStyle) > 0 ) // $szInputStyle = " STYLE=\"$this->mszInputStyle\""; $szLabelClass = ""; if ( strlen($this->mszLabelClass) > 0 ) $szLabelClass = " CLASS=\"$this->mszLabelClass\""; $szLabelStyle = ""; if ( strlen($this->mszLabelStyle) > 0 ) $szLabelStyle = " STYLE=\"$this->mszLabelStyle\""; $szResult = "\n"; $szResult .= "\n"; $szResult .= " \n"; $szResult .= " \n"; $szResult .= " \n"; $szResult .= " \n"; $szResult .= " \n"; if (stristr($bShowTime, "TRUE")!==false) { $szResult .= " \n"; $szResult .= " \n"; $szResult .= " \n"; } $szResult .= " \n"; $szResult .= " \n"; $szResult .= " \n"; $szResult .= " \n"; $szResult .= " \n" ; $szResult .= " \n"; if (stristr($bShowTime, "TRUE")!==false) { $szResult .= " \n"; $szResult .= " \n"; $szResult .= " \n"; } $szResult .= " \n"; $szResult .= " \n"; $szResult .= " \n"; $szResult .= " \n"; $szResult .= " \n"; $szResult .= " \n"; if (stristr($bShowTime, "TRUE")!==false) { $szResult .= " \n"; $szResult .= " \n"; $szResult .= " \n"; } $szResult .= " \n"; $szResult .= " \n"; $bEnableTimeQuery = (($this->isVarSet( 'bEnableTimeQuery' ) && $this->getVar( 'bEnableTimeQuery' ) == "on") ? "checked" : "" ); $szResult .= " \n"; $szResult .= "
".trim($this->moMLT->get("0","Year"))."

".trim($this->moMLT->get("1","Month"))."

".trim($this->moMLT->get("2","Day"))."

".trim($this->moMLT->get("3","Hour"))."

".trim($this->moMLT->get("4","Minute"))."

".trim($this->moMLT->get("5","Time Zone"))."

".trim($this->moMLT->get("6","From:"))."

"; for ($i=$nEarliestYear; $i<$nCurrentYear; $i++) { if ($nStartYear == $i) $szResult .= "\n"; else $szResult .= "\n"; } $szResult .= " "; for ($i=1; $i<=12; $i++) { if ($nStartMonth == $i) $szResult .= "\n"; else $szResult .= "\n"; } $szResult .= " \n"; for ($i=1;$i<=31;$i++) { if ($nStartDay == $i) $szResult .= "\n"; else $szResult .= "\n"; } $szResult .= " \n"; for ($i=0;$i<=23;$i++) { if ($nStartHour == $i) $szResult .= "\n"; else $szResult .= "\n"; } $szResult .= " \n"; for ($i=0;$i<=59;$i++) { if ($nStartMinute == $i) $szResult .= "\n"; else $szResult .= "\n"; } $szResult .= "\n"; for($i=-12;$i<=12;$i++) { if ($nStartTz == $i) $szResult .= ""; else $szResult .= ""; } $szResult .= "

".trim($this->moMLT->get("7","To:"))."

"; $szResult .= "\n"; for ($i=$nEarliestYear; $i<$nCurrentYear; $i++) { if ($nEndYear == $i) $szResult .= "\n"; else $szResult .= "\n"; } $szResult .= " "; $szResult .= "\n"; for ($i=1; $i<=12; $i++) { if ($nEndMonth == $i) $szResult .= "\n"; else $szResult .= "\n"; } $szResult .= " \n"; $szResult .= "\n"; for ($i=1;$i<=31;$i++) { if ($nEndDay == $i) $szResult .= "\n"; else $szResult .= "\n"; } $szResult .= " \n"; $szResult .= "\n"; for ($i=0;$i<=23;$i++) { if ($nEndHour == $i) $szResult .= "\n"; else $szResult .= "\n"; } $szResult .= " \n"; $szResult .= "\n"; for ($i=0;$i<=59;$i++) { if ($nEndMinute == $i) $szResult .= "\n"; else $szResult .= "\n"; } $szResult .= "\n"; $szResult .= "\n"; for($i=-12;$i<=12;$i++) { if ($nEndTz == $i) $szResult .= ""; else $szResult .= ""; } $szResult .= "
  Apply time filter

\n"; return $szResult; } } ?>