/* About the only variables you need to set */ $path = "/home/virtual/site3/fst/var/www/html/aurora_temp/"; //Path to server-writable directory $user = 1; //Set to 0 if you want to disallow users from entering different ZIP codes $embed = 0; //Set to 1 to display only the table (no style elements, etc) $default_zip = "99515"; //ZIP to display index for by default $db_name = "alaskastudio_com_aurora"; //Database name $db_host = "localhost"; //Database host $db_user = "xxxxx"; //Database username $db_pass = "xxxxxxx"; //Database password $db_table = "zip_codes"; //ZIP code table if($user == 1 && (isset($_GET["zip"]) && (is_numeric($_GET["zip"]) || strlen($_GET["zip"]) == 6))) { $zip = $_GET["zip"]; if(strlen($zip) == 6) { $zip = str_split($zip,3); $zip = $zip[0]."+".$zip[1]; } }elseif(!isset($_GET["zip"]) || $user == 0) { $zip = $default_zip; }elseif(!is_numeric($_GET["zip"])) { die("
Invalid ZIP!\n\n"); } /* Establish MySQL connection, select DB, get coords */ $link = mysql_connect($db_host,$db_user,$db_pass); mysql_select_db($db_name); $sql = "SELECT state,latitude FROM ".$db_table." WHERE zip='".$zip."' LIMIT 0,1"; $res = mysql_query($sql); if((!$res || mysql_num_rows($res) == 0) && strlen($zip) != 7) { die("ZIP not found. Try another close ZIP, perhaps?"); } elseif(strlen($zip) == 7) { $coords[0] = ""; $coords[1] = 63; } else { $coords = mysql_fetch_row($res); $coords[0] = ", ".$coords[0]; } /* Source URLs - if you change them, you may also need to change the preg_match expressions */ $url_aurora = "http://www.gi.alaska.edu/cgi-bin/predict.cgi"; $url_weather = "http://www.wunderground.com/cgi-bin/findweather/getForecast?query=".$zip; /* File naming variable */ $fprefix = strftime("%d%b%g")."_".$zip."_"; /* Scores assigned to different weather/aurora conditions */ $aurora_score_array = array( "at its maximum peak" => 10, "high" => 9, "active" => 7, "moderate" => 5, "quiet" => 1 ); $weather_score_array2 = array( "Clear" => 0, "Mostly clear" => -2, "Partly cloudy" => -3, "A chance" => -7, "Mostly cloudy" => -7, "showers" => -2, "rain" => 0, "snow" => -2, "fog" => -2, "Cloudy" => -10, "Rain" => -10, "Showers" => -10, "Snow" => -10, ); /* Parsing source URLs and calculating scores, index, and rating */ preg_match_all("|Auroral activity will be (.+) today|Uis",get_put($url_aurora),$aurora); preg_match("/";
$content .= "
|
\nAurora Viewing Index for:
\n"
."".$title[1].$coords[0]."
\n"
.$aurora_rating." (".round($aurora_index,0)."%)
\n"
."Enter your ZIP/postal code:
\n"
."
\n"
."Example: 99801 or V6C3C9
\n"
."View Local Aurora Viewing Index
\n"
."