top2image.php3 1.76 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
<?php
include("defs.php3");

#
# This script generates the contents of an image. No headers or footers,
# just spit back an image. 
#

#
# Only known and logged in users can end experiments.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);

#
# Verify page arguments.
# 
if (!isset($pid) ||
    strcmp($pid, "") == 0) {
    USERERROR("You must provide a Project ID.", 1);
}

if (!isset($eid) ||
    strcmp($eid, "") == 0) {
    USERERROR("You must provide an Experiment ID.", 1);
}
$exp_eid = $eid;
$exp_pid = $pid;

Chad Barb's avatar
Chad Barb committed
30 31 32 33 34 35 36 37
# if they dont exist, or are non-numeric, use defaults.
# note: one can use is_numeric in php4 instead of ereg.
if (!isset($zoom) || !ereg("^[0-9]{1,50}.?[0-9]{0,50}$", $zoom)) { $zoom = 1; }
if (!isset($detail) || !ereg("^[0-9]{1,50}$", $detail)) { $detail = 0; }

if ($zoom > 8.0) { $zoom = 8.0; }
if ($zoom <= 0.0) { $zoom = 1.0; }

38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#
# Check to make sure this is a valid PID/EID tuple.
#
if (! TBValidExperiment($exp_pid, $exp_eid)) {
  USERERROR("The experiment $exp_eid is not a valid experiment ".
            "in project $exp_pid.", 1);
}

#
# Verify Permission.
#
if (! TBExptAccessCheck($uid, $exp_pid, $exp_eid, $TB_EXPT_READINFO)) {
    USERERROR("You do not have permission to view experiment $exp_eid!", 1);
}

53 54 55 56 57 58 59 60 61 62
#
# XXX If an admin type, then use an appropriate gid so that we can get
# get to the top file. This needs more thought.
#
$gid = "nobody";

if (ISADMIN($uid)) {
    $gid = $exp_pid;
}

Chad Barb's avatar
Chad Barb committed
63 64 65
# note that we've already ensured that $detail is numeric above.
if ($detail != 0) { $detailstring = "-d $detail"; } else { $detailstring = ""; }

66 67 68
#
# Spit out the image with a content header.
#
Chad Barb's avatar
Chad Barb committed
69 70

if ($fp = popen("$TBSUEXEC_PATH $uid $gid webvistopology $detailstring -z $zoom $pid $eid", "r")) {
71
    header("Content-type: image/png");
72 73 74 75 76 77 78
    fpassthru($fp);
}

#
# No Footer!
# 
?>
Chad Barb's avatar
Chad Barb committed
79 80 81