template_graph.php 1.51 KB
Newer Older
1 2 3
<?php
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2006, 2007 University of Utah and the Flux Group.
5 6 7
# All rights reserved.
#
include("defs.php3");
8
include_once("template_defs.php");
9 10 11

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

#
16 17 18 19 20 21
# Capture script errors and report back to user.
#
function SPITERROR($message = "", $death = 1)
{
    header("Content-type: image/gif");
    readfile("coming-soon-thumb.gif");
22
}
23 24 25 26 27 28 29 30
$session_interactive  = 0;
$session_errorhandler = 'SPITERROR';

#
# Verify page arguments.
#
$reqargs = RequiredPageArguments("template", PAGEARG_TEMPLATE);
$optargs = OptionalPageArguments("zoom",     PAGEARG_STRING);
31

32 33 34 35 36 37
if (isset($zoom)) {
    if ($zoom != "in" && $zoom != "out") {
	PAGEARGERROR("Invalid characters in zoom factor!");
    }
}

38
function SPITGRAPH($template)
39
{
40
    $data = NULL;
41

42
    if ($template->GraphImage($data) != 0 || $data == NULL || $data == "") {
43 44
	SPITERROR();
    }
45
    else {
46 47
	header("Content-type: image/png");
	echo "$data";
48
    }
49
}
50

51 52 53 54
#
# If the request did not specify a zoom, return whatever we have.
#
if (!isset($zoom)) {
55
    SPITGRAPH($template);
56 57 58 59 60 61 62 63
    return;
}

#
# Otherwise regen the picture, zooming in or out.
#
$optarg = "-z " . ($zoom == "in" ? "in" : "out");

64 65
$pid = $template->pid();
$gid = $template->gid();
66
$unix_gid = $template->UnixGID();
67 68 69 70 71 72 73 74

$retval = SUEXEC($uid, "$pid,$unix_gid", "webtemplate_graph $optarg $guid",
		 SUEXEC_ACTION_CONTINUE);

if ($retval) {
    SPITERROR();
}
else {
75
    SPITGRAPH($template);
76
}
77 78 79 80 81

#
# No Footer!
# 
?>