Main Page | Directories | File List | File Members

graphs.php

Go to the documentation of this file.
00001 <?php
00002 # This file is part of the Savane project
00003 # <http://gna.org/projects/savane/>
00004 #
00005 # $Id: graphs.php 4567 2005-06-30 17:19:37Z toddy $
00006 #
00007 #  Copyright 2004 (c) Mathieu Roy <yeupou--at--gnu.org>
00008 #
00009 # The Savane project is free software; you can redistribute it and/or
00010 # modify it under the terms of the GNU General Public License
00011 # as published by the Free Software Foundation; either version 2
00012 # of the License, or (at your option) any later version.
00013 #
00014 # The Savane project is distributed in the hope that it will be useful,
00015 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 # GNU General Public License for more details.
00018 #
00019 # You should have received a copy of the GNU General Public License
00020 # along with the Savane project; if not, write to the Free Software
00021 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023 # Attempt to replace HTML_graphs.php with someone more spartian, efficient
00024 # and w3c compliant.
00025 
00026 # It can accept db result directy or an array.
00027 # Total must be an array too, if provided
00028 function graphs_build ($result, $field=0, $dbdirect=1,$total=0)
00029 {
00030   if (!$result)
00031     {
00032       fb(_("No data to work on, no graph will be built"), 1);
00033       break;
00034     }
00035 
00036   if ($dbdirect)
00037     {
00038       $content = array();
00039       for ($i=0; $i < db_numrows($result) ; $i++)
00040         {
00041           $content[db_result($result, $i, 0)] = db_result($result, $i, 1);
00042         }
00043     }
00044   else
00045     {
00046       $content = $result;
00047     }
00048 
00049   # Get the total number of items
00050   # Total should not be passed as argument, normally
00051   if (!$total)
00052     {
00053       $totalvar = 0;
00054       while(list($k, $v)=each($content))
00055         {
00056           $totalvar += $v;
00057         }
00058 
00059       $total = array();
00060       reset($content);
00061       while(list($k, $v)=each($content))
00062         {
00063           $total[$k] = $totalvar;
00064         }
00065     }
00066   else
00067     {
00068       # If total was passed as argument, no crosscheck, assume it is accurate
00069       $totalvar = 1;
00070     }
00071 
00072   # Print the stats, unless $total is nul
00073   # If total was passed as argument, strange result may be printed.
00074   if ($totalvar)
00075     {
00076       print "\n\n<table width=\"100%\">\n";
00077       reset($content);
00078       while(list($k, $v)=each($content))
00079         {
00080           if ($total[$k] > 0)
00081             {
00082               $percent_width = round(($v / $total[$k]) * 100);
00083               $percent_print = sprintf(_("%s%%"), $percent_width);
00084             }
00085           else
00086             {
00087               $percent_width = 0;
00088               $percent_print = _("n/a");
00089               $total[$k] = 0;
00090             }
00091 
00092           if ($field && $field == "assigned_to")
00093             { $title = utils_user_link($k); }
00094           else
00095             { $title = $k; }
00096 
00097 
00098           if ($percent_width > 25)
00099             { unset($class); }
00100           else
00101             { $class="closed"; }
00102 
00103           print '<tr width="100%">'.
00104             '<td width="15%" align="right" valign="center">'.$title.'</td>'.
00105             '<td width="5%" align="right" valign="center">'.sprintf(_("%s/%s"), $v, $total[$k]).'</td>'.
00106             '<td width="5%" align="center" valign="center">'.$percent_print.'</td>'.
00107             '<td width="75%" class="prioraclosed" align="left"><table class="priori'.$class.'" width="'.$percent_width.'%" cellpadding="0" cellspacing="0"><tr><td>&nbsp;</td></tr></table></td>'.
00108             '</tr>';
00109         }
00110       print "\n</table>\n\n";
00111     }
00112   else
00113     {
00114       print '<p class="warn">';
00115       print _("The total of results is zero.");
00116       print '</p>';
00117     }
00118 }
00119 
00120 ?>

Generated on Sun Feb 26 13:23:04 2006 for Savane PHP Frontend Developer Reference by  doxygen 1.4.4