buildTop("NPB-1 Data", $page_arr, "hide_logos"); ?>
function rangeHasPlots($s_y, $s_m, $s_d, $e_y, $e_m, $e_d) {
$has_plots = false;
$min_timecode = mktime(0, 0, 0, $s_m, $s_d, $s_y);
$max_timecode = mktime(23, 59, 59, $e_m, $e_d, $e_y);
$query = "SELECT timecode FROM npb.npb_1_plots WHERE timecode >= ".$min_timecode." AND timecode <= ".$max_timecode." LIMIT 1";
$data_arr = getDBData($query, $GLOBALS["nanoos_db"]);
if (count($data_arr) > 0) $has_plots = true;
return $has_plots;
}
function getFirstDateAfterDate($year, $month, $day) {
$result_timecode = false;
$timecode = mktime(0, 0, 0, $month, $day, $year);
//echo $year."-".$month."-".$day." -- ".date("Y-m-d", $timecode)."
";
$query = "SELECT timecode FROM npb.npb_1_plots WHERE timecode >= ".$timecode." ORDER BY timecode ASC LIMIT 1";
$data_arr = getDBData($query, $GLOBALS["nanoos_db"]);
if (count($data_arr) > 0) $result_timecode = $data_arr[0]["timecode"];
return $result_timecode;
}
?>
$query = "SELECT timecode FROM npb.npb_1_plots ORDER BY timecode DESC LIMIT 1"; //get last timecode
$data_arr = getDBData($query, $GLOBALS["nanoos_db"]);
$end_timestamp = (count($data_arr) > 0)? $data_arr[0]["timecode"]: time();
$end_date = date("Ymd", $end_timestamp); //"20120806";
$end_year = substr($end_date, 0, 4);
$end_month = substr($end_date, 4, 2);
$end_day = substr($end_date, 6, 2);
$query = "SELECT timecode FROM npb.npb_1_plots ORDER BY timecode ASC LIMIT 1"; //get first timecode
$data_arr = getDBData($query, $GLOBALS["nanoos_db"]);
//$start_date = ($param_arr["start_date"])? $param_arr["start_date"]: $end_date;
$start_timestamp = (count($data_arr) > 0)? $data_arr[0]["timecode"]: $end_timestamp;
$start_date = date("Ymd", $start_timestamp);
$start_year = substr($start_date, 0, 4);
$start_month = substr($start_date, 4, 2);
$start_day = substr($start_date, 6, 2);
$selected_datecode = (!empty($_GET["datecode"]))? $_GET["datecode"]: null;
//IS $_GET["datecode"] VALID FORMAT??? - IF NOT, SET TO $end_date
$selected_date = "";
$selected_hour = "";
$show_most_recent = (empty($selected_datecode))? true: false;
if (strlen($selected_datecode) > 8) {
list($selected_date, $selected_hour) = explode("-", $selected_datecode);
} else {
$selected_date = $selected_datecode;
}
if (empty($selected_date)) $selected_date = $end_date;
if ($selected_date < $start_date) $selected_date = $start_date;
if ($selected_date > $end_date) $selected_date = $end_date;
$selected_year = substr($selected_date, 0, 4);
$selected_month = substr($selected_date, 4, 2);
if ($selected_month == "00") {
$next_timecode = getFirstDateAfterDate($selected_year, 1, 1);
$selected_month = date("m", $next_timecode);
}
$selected_day = substr($selected_date, 6, 2);
if ($selected_day == "00") {
$next_timecode = getFirstDateAfterDate($selected_year, $selected_month, 1);
$selected_day = date("d", $next_timecode);
}
?>
for ($i = $start_year; $i <= $end_year; $i++) {
$td_pre = ($i == $end_year)? "": " | ";
$td_post = " | ";
$pre = ($i == $selected_year)? "": "";
$post = "";
echo $td_pre.$pre.$i.$post.$td_post;
}
?>
|
$start_YYYYMM = $start_year.calPad($start_month);
$end_YYYYMM = $end_year.calPad($end_month);
$first_month = 1;
$last_month = 12;
for ($i = $first_month; $i <= $last_month; $i++) {
$this_MM = calPad($i);
$this_YYYYMM = $selected_year.$this_MM;
$td_pre = ($i == $last_month)? "": " | ";
$td_post = " | ";
$pre = "";
$post = " ";
if ($this_YYYYMM >= $start_YYYYMM && $this_YYYYMM <= $end_YYYYMM) {
if (rangeHasPlots($selected_year, $this_MM, 1, $selected_year, $this_MM, numDaysInMonthYear($this_MM, $selected_year))) {
$pre = ($i == $selected_month)? "": "";
$post = "";
}
}
echo $td_pre.$pre.monthIntToString($i, "shortstring").$post.$td_post;
}
?>
|
$start_YYYYMMDD = $start_year.calPad($start_month).calPad($start_day);
$end_YYYYMMDD = $end_year.calPad($end_month).calPad($end_day);
$first_day = 1;
$last_day = numDaysInMonthYear($selected_month, $selected_year);
for ($i = $first_day; $i <= $last_day; $i++) {
$this_YYYYMMDD = $selected_year.calPad($selected_month).calPad($i);
$td_pre = ($i == $last_day)? "": " | ";
$td_post = " | ";
$pre = "";
$post = " ";
if ($this_YYYYMMDD >= $start_YYYYMMDD && $this_YYYYMMDD <= $end_YYYYMMDD) {
if (rangeHasPlots($selected_year, $selected_month, $i, $selected_year, $selected_month, $i)) {
$pre = ($i == $selected_day)? "": "";
$post = "";
}
}
echo $td_pre.$pre.$i.$post.$td_post;
}
?>
|
$hours_arr = array();
$min_timecode = mktime(0, 0, 0, $selected_month, $selected_day, $selected_year);
$max_timecode = mktime(23, 59, 59, $selected_month, $selected_day, $selected_year);
$query = "SELECT timecode FROM npb.npb_1_plots WHERE timecode >= ".$min_timecode." AND timecode <= ".$max_timecode." GROUP BY timecode ORDER BY timecode"; //get first timecode
$data_arr = getDBData($query, $GLOBALS["nanoos_db"]);
foreach ($data_arr as $data) {
$hours_arr[] = date("Hi", $data["timecode"]);
}
if (count($hours_arr) == 0) {
echo "No Data Available for the Selected Date | ";
} else {
for ($i = 0; $i < count($hours_arr); $i++) {
$td_pre = ($i == count($hours_arr) - 1)? "": " | ";
$td_post = " | ";
$hour = $hours_arr[$i];
$hilite_hour = false;
if ($show_most_recent) {
if ($i == (count($hours_arr) - 1)) $hilite_hour = true;
} else {
if ($hour == $selected_hour || (empty($selected_hour) && $i == 0)) $hilite_hour = true;
}
if ($hilite_hour) {
$selected_hour = $hour;
$a_pre = "";
} else {
$a_pre = "";
}
$a_post = "";
echo $td_pre.$a_pre.substr($hour, 0, 2).":".substr($hour, 2, 2).$a_post.$td_post;
}
}
?>
|
if (!empty($selected_hour)) {
$IMG_WIDTH = 300;
$IMG_HEIGHT = 350;
$variable_arr = array("temperature",
"salinity",
"oxygen",
"chl",
"transmittance",
"ntu",
"O2sat",
"density",
"null",
"velocity",
"nitrate",
"par"
);
$selected_timecode = mktime(substr($selected_hour, 0, 2), substr($selected_hour, 2, 2), 0, $selected_month, $selected_day, $selected_year);
$query = "SELECT timecode, variable, plot_url FROM npb.npb_1_plots WHERE timecode = ".$selected_timecode;
$data_arr = getDBData($query, $GLOBALS["nanoos_db"]);
$plot_arr = array();
foreach ($data_arr as $data) {
$plot_arr[$data["variable"]] = $data["plot_url"];
}
$NUM_COLUMNS = 3;
$NUM_ROWS = ceil(count($variable_arr) / $NUM_COLUMNS);
$html = "";
$html .= " \n";
$counter = 0;
for ($i = 0; $i < $NUM_ROWS; $i++) {
$html .= " \n";
for ($k = 0; $k < $NUM_COLUMNS; $k++) {
if ($counter < count($variable_arr)) {
$url = (isset($plot_arr[$variable_arr[$counter]]))? $plot_arr[$variable_arr[$counter]]: false;
//if ($url && urlExists($url)) {
if ($url) {
$html .= " | ";
} else {
$html .= " | ";
}
} else {
$html .= " | ";
}
if ($k < $NUM_COLUMNS - 1) $html .= " | \n";
$counter++;
}
$html .= "
\n";
}
$html .= "
\n";
echo $html;
}
?>
buildBottom(); ?>