<?php
$http_form_vars = (count($_POST) > 0) ?
$_POST : ((count($_GET) > 0) ? $_GET : array() );
$start_time = $http_form_vars['START_TIME'];
$interval = $http_form_vars['INTERVAL'];
$end_time = $http_form_vars['END_TIME'];
// optional parameters
// assume defaults
$anim_label_base = array(98,3);
$anim_label_num_dashes = 12;
if (isset($http_form_vars['ANIM_LABEL_BASE'])) {
$anim_label_base = explode(',',$http_form_vars['ANIM_LABEL_BASE']);
}
if (isset($http_form_vars['ANIM_LABEL_NUM_DASHES'])) {
$anim_label_num_dashes = $http_form_vars['ANIM_LABEL_NUM_DASHES'];
}
if (isset($http_form_vars['PASS_BACK_IMAGE_ONLY'])) {
$pass_back_image_only = true;
}
else {
$pass_back_image_only = false;
}
// remove the lock file and strip it from the szPrevStateKey
// (no need for querymap when querying!)
$res = strstr($http_form_vars['gszCurrentState'],'IMAGEMAP_SESSION_ID=');
$imagemap_path = substr($res, strpos($res,'=')+1);
$imagemap_path = substr($imagemap_path,0,strpos($imagemap_path,'|'));
$imgmap_lock_only = $imagemap_path;
$imagemap_path = '/tmp/lock_'.$imagemap_path;
`rm -f $imagemap_path`;
$szPrevStateKey = str_replace($imgmap_lock_only,'',$szPrevStateKey);
$start_time_sec = mktime(substr($start_time,11,2),substr($start_time,14,2),substr($start_time,17,2),substr($start_time,5,2),substr($start_time,8,2),substr($start_time,0,4));
if (strlen($end_time) > 0) {
$end_time_sec = mktime(substr($end_time,11,2),substr($end_time,14,2),substr($end_time,17,2),substr($end_time,5,2),substr($end_time,8,2),substr($end_time,0,4));
}
else {
$end_time_sec = mktime() - 3*60*60;
}
// don't let them end up w/ an empty image
if ($end_time_sec <= $start_time_sec) {
$end_time_sec = $start_time_sec + 1;
}
$num_frames = ($end_time_sec - $start_time_sec) / $interval;
$this_frame = 0;
for ($i = $start_time_sec; $i <= $end_time_sec; $i += $interval) {
$time_stamp = date('Y_m_d_H_i_s',$i);
$gszCurrentState = explode('|',$http_form_vars['gszCurrentState']);
$gszCurrentState[11] = "TIME_STAMP=$time_stamp";
$http_form_vars['gszCurrentState'] = implode('|',$gszCurrentState);
$cmd = '/var/www/cgi-bin/php_cli '
. '/usr2/maps/seacoos/ui/portal_obs/wrapper/drawmap_cli.php '
. '\''.'gszMapName='.$http_form_vars['gszMapName'].'\' '
. '\''.'gszCurrentState='.$http_form_vars['gszCurrentState'].'\' '
. '\''.'map_session_mode='.$http_form_vars['map_session_mode'].'\' '
. '\''.'run_query='.$http_form_vars['run_query'].'\' '
. '\''.'gszPHPMapScriptModName='.$http_form_vars['gszPHPMapScriptModName'].'\' '
. '\''.'gszQueryCoords='.$http_form_vars['gszQueryCoords'].'\' '
. '\''.'sessionID='.$http_form_vars['sessionID'].'\'';
system ($cmd);
$local_time_stamp = date('m/d/Y H:i:s',$i)
.$http_form_vars['TIME_ZONE'];
$images .= "Time_Interval_$time_stamp.png,";
$intervals .= "$local_time_stamp,";
$cmd_string .= '"'.$cmd.'",';
# only print a anim_label_num_dashes '-' wide bar
$progress_bar = ' [';
for ($j = 0; $j <= ($anim_label_num_dashes - 1); $j++) {
$val = min(round($this_frame / ($num_frames / $anim_label_num_dashes)),$anim_label_num_dashes-1);
if ($val == $j) {
$progress_bar .= 'X';
}
else {
$progress_bar .= '-';
}
}
$progress_bar .= "]";
$this_frame++;
$cmd_filename = '/tmp/ms_tmp/'.$http_form_vars['sessionID'].'/anim_cmds.sh';
$im_cmd = '/usr/local/bin/convert'
.' -fill white -draw \"rectangle '
.$anim_label_base[0].','.$anim_label_base[1]
.' '
.($anim_label_base[0] + (11.417 * $anim_label_num_dashes))
.' '
.($anim_label_base[1] + 25)
.'\"'
.' -font arial -fill black -draw \"text '
.($anim_label_base[0] + 2)
.','
.($anim_label_base[1] + 12)
.' '
.'\''
.$local_time_stamp
.'\''
.'\"'
.' -font courier -fill black -draw \"text '
.($anim_label_base[0] + 2)
.','
.($anim_label_base[1] + 22)
.' '
.'\''
.$progress_bar
.'\''
.'\"'
.' /tmp/ms_tmp/'.$http_form_vars['sessionID']."/Time_Interval_$time_stamp.png"
.' /tmp/ms_tmp/'.$http_form_vars['sessionID']."/Time_Interval_$time_stamp.gif\n";
`echo "$im_cmd" >> $cmd_filename`;
}
$anim_cmd = '/usr/local/bin/gifsicle --delay=60 --loop --colors=256'
.' /tmp/ms_tmp/'.$http_form_vars['sessionID'].'/Time*.gif'
.' -o /tmp/ms_tmp/'.$http_form_vars['sessionID'].'/animation.gif';
`echo "$anim_cmd" >> $cmd_filename`;
`/bin/sh $cmd_filename`;
$size_start = strpos($http_form_vars['gszCurrentState'],'|MAPSIZE=') + strlen('|MAPSIZE=');
$size_right = substr($http_form_vars['gszCurrentState'],$size_start);
$size_only = explode(',',substr($size_right,0,strpos($size_right,'|')));
$images = rtrim($images,',');
$intervals = rtrim($intervals,',');
$cmd_string = rtrim($cmd_string,',');
if (!($pass_back_image_only)) {
echo '<img src="http://nautilus.baruch.sc.edu/ms_tmp/'.$http_form_vars['sessionID'].'/animation.gif">'."\n";
}
else {
@readfile('http://nautilus.baruch.sc.edu/ms_tmp/'.$http_form_vars['sessionID'].'/animation.gif');
}
?>
--
CharltonPurvis - 23 Mar 2005
to top