2) { // state (e.g. California_CA.html) if (!$help) { $templateFilename = "templates/state.html"; } $fstate = substr($state, 0, strlen($state)-3); $state = substr($state, -2, 2); // test values... $dt = DBQuery("SELECT State FROM Locations WHERE FState = '".$fstate."'",1); $testvalue = $dt["State"]; if ($testvalue == "") { header("location:/"); } } else { // state-cities (e.g. CA.html) if (!$help) { $templateFilename = "templates/state-cities.html"; } $dt = DBQuery("SELECT FState FROM Locations WHERE State = '".$state."'",1); $fstate = $dt["FState"]; // check if valid location if ($fstate == "") { header("location:/"); } } } else { // city (e.g. CA.html) if (!$help) { $templateFilename = "templates/city.html"; } $fstate = $state; $dt = DBQuery("SELECT State FROM Locations WHERE FState = '".$fstate."' AND City = '".$city."'",1); $state = $dt["State"]; // check if valid location if ($state == "") { header("location:/"); } } // use above logic to determine template... // but for now: $fh = fopen($templateFilename, 'r'); $templateText = fread($fh, filesize($templateFilename)); fclose($fh); $templateText = str_replace("\$STATE$", $state, $templateText); $templateText = str_replace("\$FSTATE$", $fstate, $templateText); $templateText = str_replace("\$FSTATE_NOSPACE$", str_replace(" ", "_", $fstate), $templateText); $templateText = str_replace("\$CITY$", $city, $templateText); $templateText = str_replace("\$CITY_NOSPACE$", str_replace(" ", "_", $city), $templateText); $templateText = str_replace("\$STATECITIES_URL$", $APPROOTURL.$state.".".$FILEEXTENSION, $templateText); $templateText = str_replace("\$ALL_CITIES$", GetCityList($state), $templateText); $templateText = str_replace("\$ALL_CITIES_LINK_CITY$", GetCityList($state, true), $templateText); $templateText = str_replace("\$ALL_STATES$", GetStateList(false), $templateText); $templateText = str_replace("\$ALL_STATES_LINK_STATE$", GetStateList(false, true), $templateText); $templateText = str_replace("\$ALL_STATES_LINK_CITIES$", GetStateList(false, true, true), $templateText); $templateText = str_replace("\$ALL_FSTATES$", GetStateList(true), $templateText); $templateText = str_replace("\$ALL_FSTATES_LINK_STATE$", GetStateList(true, true), $templateText); $templateText = str_replace("\$ALL_FSTATES_LINK_CITIES$", GetStateList(true, true, true), $templateText); $templateText = str_replace("\$APPROOTURL$", $APPROOTURL, $templateText); if (strpos($templateText, '$RSS$') !== false) { $RSSREQUESTLOCATION = str_replace("\$STATE$", str_replace(" ", "%2B", $state), $RSSREQUESTLOCATION); $RSSREQUESTLOCATION = str_replace("\$FSTATE$", str_replace(" ", "%2B", $fstate), $RSSREQUESTLOCATION); $RSSREQUESTLOCATION = str_replace("\$CITY$", str_replace(" ", "%2B", $city), $RSSREQUESTLOCATION); include("./rssexecute.php"); $templateText = str_replace("\$RSS$", $rsscontents, $templateText); } print $templateText; function GetStateList($fullname = false, $showlinks = false, $tocitypage = false) { global $APPROOTURL; global $FILEEXTENSION; global $help; $listtext = " • "; $dt = DBQuery("SELECT DISTINCT State, FState FROM Locations ORDER BY FState"); while ($dr = mysql_fetch_row($dt)) { $statevalue = ""; if ($fullname) { $statevalue = $dr[1]; } else { $statevalue = $dr[0]; } if ($showlinks) { /* show links ... */ $url = $APPROOTURL; if ($help) { $url .= "h/"; } if ($tocitypage) { $url .= $dr[0]; // state name } else { $url .= str_replace(" ", "_", $dr[1])."_".$dr[0]; // state name } $url .= ".".$FILEEXTENSION; $listtext .= "".$statevalue." • "; } else { $listtext .= $statevalue." • "; } } return $listtext; } function GetCityList($state, $showlinks = false) { global $APPROOTURL; global $FILENAMECITY; global $FILEEXTENSION; global $help; $listtext = " • "; $dt = DBQuery("SELECT State, FState, City FROM Locations WHERE State = '$state' ORDER BY City"); while ($dr = mysql_fetch_row($dt)) { if ($showlinks) { /* show links ... */ $url = $APPROOTURL; if ($help) { $url .= "h/"; } $url .= str_replace(" ", "_", $dr[1])."/"; // state name $urlcity = $dr[2]; $urlcity = str_replace(" ", "_", $urlcity); $urlcity = str_replace(".", "-", $urlcity); $url .= str_replace("$", $urlcity, $FILENAMECITY).".".$FILEEXTENSION; // city name $listtext .= "".$dr[2]." • "; } else { $listtext .= $dr[2]." • "; } } return $listtext; } ?>