exec("set datestyle TO postgres"); header("Content-type: text/javascript"); $day = 0; $local_timezone = true; $location_ids = array(); $region_id = 0; $includeRams = 0; if (isset($_COOKIE["wfToken"])) { $dbh_comm = WFDB::ConnectDB("community"); // Get Access Levels $stmt = "select access_level::text from session.directory s join accounts.directory a using (member_id) where session_id = ?"; $sth = $dbh_comm->prepare($stmt); $sth->execute(array($_COOKIE["wfToken"])); $result = $sth->fetchAll(); for ($i = 0; $i < count($result); $i++) { //if (ereg("(3|4|10|46|49|33)", $result[$i]['access_level'])) { if (preg_match("/(3|4|10|46|49|33)/", $result[$i]['access_level'])) { $includeRams = 1; } } } if (isset($_GET['day'])) { $day = abs($_GET['day']); } if (isset($_GET['utc'])) { $local_timezone = false; } if (isset($_GET['location_ids'])) { $location_ids = explode(',', $_GET['location_ids'], 500); } if (isset($_GET['regionID'])) { $region_id = urlencode($_GET['regionID']); } if (isset($_GET['siteids']) && count($location_ids) == 0) { $siteids = explode(',', $_GET['siteids']); $stmt = "SELECT location_id FROM location.siteinfo_location WHERE siteid in (?"; for ($i = 0; $i < count($siteids)-1; $i++) { $stmt .= ",?"; } $stmt .= ")"; $sth = $dbh->prepare($stmt); $sth->execute($siteids); $result = $sth->fetchAll(); for ($i = 0; $i < count($result); $i++) { array_push($location_ids, $result[$i]['location_id']); } } $wind_unit_conversion = 1; $wind_unit = 'mph'; if (isset($_GET['wind_unit'])) { switch ($_GET['wind_unit']) { case 'kts': $wind_unit_conversion = 0.8689762; $wind_unit = 'kts'; break; case 'mph': $wind_unit_conversion = 1; $wind_unit = 'mph'; break; case 'mps': $wind_unit_conversion = 0.44704; $wind_unit = 'm/s'; break; case 'kph': $wind_unit_conversion = 1.609344; $wind_unit = 'kph'; break; } } if (count($location_ids) == 0) { print "document.write('Invalid siteid or location_id given');"; exit(0); } $param_placeholders = ((int)$location_ids[0]); for ($i = 1; $i < count($location_ids); $i++) { $param_placeholders .= "," . ((int)$location_ids[$i]); } # Query the database for the preferred model data $model_time = $local_timezone ? "timezone(l.timezone_name, mt.model_time) as model_time" : "mt.model_time"; $stmt = "select d.wind_speed, d.wind_direction, $model_time, model_run_id, l.siteid, l.name, model.model_name, l.name as location_id, mg.group_name from location.location l join forecast.model_time mt on mt.model_run_id = ( select model_run_id from forecast.available_models am where am.location_id = l.location_id and date_trunc('day', timezone(timezone_name, now())) + cast(? as interval) < am.end_time "; if ($includeRams == 0) { $stmt .= " and model_group_id <> 11 "; } $stmt .= " limit 1 ) and date_trunc( 'day', timezone(l.timezone_name, mt.model_time) ) = date_trunc('day', timezone(l.timezone_name, now()) ) + cast(? as interval) join forecast.model_run using (model_run_id) join forecast.model using (model_id) join forecast.model_group mg using (model_group_id) LEFT JOIN forecast.data d on d.location_id = l.location_id and d.model_time_id = mt.model_time_id WHERE l.location_id in ($param_placeholders) and d.model_time_id is not null order by l.timezone_name, y(l.lonlat), model_time asc"; $sth = $dbh->prepare($stmt); $params = array_merge(array(($day+1) . " day", "$day day")); //, $location_ids); if ($sth->execute($params) == false) { print_r($sth->errInfo()); } $fx_data = array(); $day = ""; $first_day = ""; while ($row = $sth->fetch(PDO::FETCH_ASSOC)) { $location_id = $row['location_id']; $forecast_time = date_create($row['model_time']); $day = $forecast_time->format('l, F jS'); if ($first_day == "") { $first_day = $day; } $hour = $forecast_time->format('ga'); $hour = str_replace("m", "", $hour); if (isset($fx_data[$location_id]) == false) { $fx_data[$location_id] = array(); } if (isset($fx_data[$location_id]['data'][$hour]) == false) { $fx_data[$location_id]['data'][$hour] = array(); } if (isset($row['wind_speed'])) { $row['wind_speed'] = round($row['wind_speed'] * $wind_unit_conversion); $row['wind_speed_color'] = speed_to_color($row['wind_speed'] * $wind_unit_conversion); } if (isset($row['wind_direction'])) { $row['dir_img'] = dir_to_img($row['wind_direction']); } $fx_data[$location_id]['name'] = $row['name']; $fx_data[$location_id]['group_name'] = $row['group_name']; $fx_data[$location_id]['siteid'] = urlencode($row['siteid']); $fx_data[$location_id]['data'][$hour] = $row; } $day = $first_day; ?> //