Main Page | Directories | File List | File Members

graphs.php File Reference

Go to the source code of this file.

Functions

 graphs_build ($result, $field=0, $dbdirect=1, $total=0)


Function Documentation

graphs_build result,
field = 0,
dbdirect = 1,
total = 0
 

Definition at line 28 of file graphs.php.

References $content, $result, $title, $total, db_numrows(), db_result, nbsp, and print.

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 }


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