<?php
// input 
// infile (without the .txt suffix)
$linelimit 15;
   
$infile.='.csv';
   
$infopen("$infile","r");
   
$out'';
   
$out.="digraph goals {\n";
   
$out.="  edge  [arrowtail=normal arrowhead=none];\n";
   while(
$line =fgets($in,256)) {
       
$line=chop($line);
       
$fs explode(',',$line);
       
$l=$fs[0].' : '.$fs[1];
// need to format the text in the node a bit
       
$l=wordwrap($l,15' \\\n ');
       
$out.="{$fs[0]} [ label=\"$l\" ];\n"
       for(
$i=2; isset($fs[$i]); $i++) {
             if (
strlen($fs[$i]) > 0)
                 
$out.="{$fs[$i]} ->{$fs[0]} ;\n";
       }
   }
   
$out.="}";
// print($out);

//set output to be GIF
   
header("Content-type: image/gif");
//execute the dot program and pass thru the output back to the client
   
passthru("echo '$out' | /usr/local/graphviz/bin/dot -Tgif ");
   

?>