Ejemplo n.º 1
0
function drawEmptyResult($text = "None found.", $colspan = 1)
{
    //todo ~ obsolete.  tables should use joshlib's table class
    return draw_tag("tr", false, draw_tag("td", array("class" => "empty", "colspan" => $colspan), $text));
}
Ejemplo n.º 2
0
function main()
{
    global $tag_color;
    global $tag_color_high;
    $time_start = microtime(TRUE);
    /* only display tags on this particular floor */
    $floor = isset($_GET['floor']) ? intval($_GET['floor']) : 0;
    if ($floor < 1 || $floor > 3) {
        $floor = 1;
    }
    /* open floor specific image */
    $imgfile = '../images/brucon.png';
    $im_png = imagecreatefrompng($imgfile) or die('Cannot Initialize new GD image stream with file ' . $imgfile);
    /* get image size */
    $im_width = imagesx($im_png);
    $im_height = imagesy($im_png);
    $im = imagecreatetruecolor($im_width, $im_height) or die('Cannot initialize new GD image');
    /* enable antialiasing */
    imageantialias($im, true);
    /* specify colors */
    $bg_color = imagecolorallocate($im, 0x10, 0x10, 0x10);
    $inactive_color = imagecolorallocate($im, 150, 150, 150);
    $reader_color = imagecolorallocate($im, 255, 64, 32);
    $prox_color = imagecolorallocate($im, 128, 32, 16);
    $tag_color = imagecolorallocate($im, 32, 64, 128);
    $tag_color_high = imagecolorallocate($im, 255, 128, 64);
    $prox_color = array();
    for ($i = 1; $i <= MAX_PROX_COLORS; $i++) {
        $prox_color[$i] = imagecolorallocate($im, 255 / MAX_PROX_COLORS * $i, 64 / MAX_PROX_COLORS * $i, 32 / MAX_PROX_COLORS * $i);
    }
    imagecopy($im, $im_png, 0, 0, 0, 0, $im_width, $im_height);
    if (($data = @file_get_contents(DATA_FILE)) === FALSE) {
        die('can\'t open data file');
    }
    if (!($track = json_decode($data))) {
        die('can\'t decode JSON tracking state');
    }
    /* create associative list for reader id for current floor */
    $reader_list = array();
    foreach ($track->reader as $reader) {
        if ($reader->floor == $floor) {
            $reader_list[intval($reader->id)] = true;
            /* for BCC reader ID/IP is derieved from switch port number */
            $reader_id = sprintf("%s%03u", chr(ord('A') + ($reader->id >> 8 & 0x1f)), $reader->id & 0xff);
            imagefilledrectangle($im, $reader->px - 3, $reader->py - 3, $reader->px + 3, $reader->py + 3, $reader_color);
            imagestring($im, 4, $reader->px, $reader->py - 18, $reader_id, $inactive_color);
        }
    }
    $tag_list = array();
    foreach ($track->tag as $tag) {
        $tag_list[intval($tag->id)] = $tag;
    }
    /* draw all edges */
    foreach ($track->edge as $edge) {
        $tag_id1 = intval($edge->tag[0]);
        $tag_id2 = intval($edge->tag[1]);
        if (isset($tag_list[$tag_id1]) && isset($tag_list[$tag_id2])) {
            $tag1 = $tag_list[$tag_id1];
            $tag2 = $tag_list[$tag_id2];
            $power = $edge->power <= MAX_PROX_COLORS ? $edge->power : MAX_PROX_COLORS;
            imageline($im, $tag1->px, $tag1->py, $tag2->px, $tag2->py, $prox_color[$power]);
        }
    }
    /* draw all non-button-pressed tags */
    foreach ($track->tag as $tag) {
        if (!isset($tag->button) && isset($tag->reader) && isset($reader_list[$tag->reader])) {
            draw_tag($im, $tag->px, $tag->py, $tag->id, false);
        }
    }
    /* draw all button-pressed tags */
    foreach ($track->tag as $tag) {
        if (isset($tag->button) && isset($tag->reader) && isset($reader_list[$tag->reader])) {
            draw_tag($im, $tag->px, $tag->py, $tag->id, true);
        }
    }
    // timestamp
    $duration = sprintf(" [rate=%u/s, render=%ums]", $track->packets->rate, round((microtime(TRUE) - $time_start) * 1000, 1));
    imagestring($im, 4, $im_width - 470, $im_height - 30, date(DATE_RSS, $track->time) . $duration, $inactive_color);
    header('Content-type: image/png');
    header('Refresh: 1');
    imagepng($im);
    imagedestroy($im);
}