Location: PHPKode > projects > Whiteboard > whiteboard1.0.3/program/restricted/histograms.php
<?php
/* Whiteboard Courseware System v1.0.3
   Copyright (C) 2002-2003 Todd Templeton

   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the Free
   Software Foundation; either version 2 of the License, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful, but WITHOUT
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
   more details.

   You should have received a copy of the GNU General Public License along with
   this program; if not, write to the Free Software Foundation, Inc., 59 Temple
   Place, Suite 330, Boston, MA 02111-1307 USA

   Contact info: my paper address changes often, but you can contact me at
   hide@address.com
*/


define ("MODULE", "histograms");
define ("PATHTOHTTPROOT", "../");

unset ($options);
unset ($page);

require (PATHTOHTTPROOT . "include/include.php");
require (PATHTOHTTPROOT . "include/gradesinclude.php");


$histograms['numperrow'] = NUMHISTOGRAMSPERROW;
$histograms['height'] = HISTOGRAMHEIGHT;
$histograms['columns'] = HISTOGRAMCOLUMNS;
$histograms['bgcolor'] = "#" . HISTOGRAMBACKGROUNDCOLOR;
$histograms['titlecolor'] = HISTOGRAMTITLECOLOR;
$histograms['textcolor'] = HISTOGRAMTEXTCOLOR;
$histograms['imagebordercolor'] = IMAGEHISTOGRAMBORDERCOLOR;
$histograms['imagebarbordercolor'] = IMAGEHISTOGRAMBARBORDERCOLOR;
$histograms['imagetype'] = IMAGEHISTOGRAMTYPE;
$histograms['imageborder'] = IMAGEHISTOGRAMBORDER;
$histograms['imagebarborder'] = IMAGEHISTOGRAMBARBORDER;
$histograms['imagebarspace'] = IMAGEHISTOGRAMBARSPACING;
$histograms['imagebarwidth'] = IMAGEHISTOGRAMBARWIDTH;
$histograms['imagetitlefont'] = IMAGEHISTOGRAMTITLEFONT;
$histograms['imagetitlefontsize'] = IMAGEHISTOGRAMTITLEFONTSIZE;
$histograms['imagefont'] = IMAGEHISTOGRAMFONT;
$histograms['imagefontsize'] = IMAGEHISTOGRAMFONTSIZE;
$histograms['imagetextoffset'] = IMAGEHISTOGRAMTEXTOFFSET;


/* determines if an assignment is a decimal grade (if any grade is a positive
     decimal)
   returns true/false
   $assignmentcolumn is a flat array of all grades for an assignment
*/
function isdecimalassignment ($assignmentcolumn) {
  if (!is_array ($assignmentcolumn))
    return false;
  for ($i = 0; $i < count ($assignmentcolumn); $i++) {
    if (isposnzdecimal ($assignmentcolumn[$i]))
      return true;
  }
  return false;
}


/* prints HTML table histogram
   returns nothing
   $name is the name of the histogram
   $color is the bar color (blue/green)
   $columnnames is a flat array of bar names
   $columnrowspan is a flat array of column heights (in table rows (10 pixels))
   $columnnumbers is a flat array of numbers that the bars represent
   $fieldname is the assignment
*/
function tablegraph ($name, $color, $columnnames, $columnrowspan, $columnnumbers, $fieldname) {
  global $course;
  global $semester;
  global $currentsemester;
  global $histograms;
  global $manuallycreateimages;
  global $time;
  $columnscount = count ($columnnames);
  prnt ("<span align=\"center\"><b class=\"histogramtitle\">");
  prnt ("<font color=\"" . $histograms['titlecolor'] . "\">" . $name);
  prnt ("</font>");
  prnt ("</b></span>");
  prnt ("<br><br>\n");
  prnt ("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"");
  prnt (" align=\"center\">\n");
  prnt ("<tr><td bgcolor=\"" . $histograms['bgcolor'] . "\">\n");
  prnt ("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"");
  prnt (" align=\"center\">\n");
  prnt ("<tr>");
  prnt ("<td align=\"center\">" . imagetag ("border1.gif") . "</td>");
  for ($i = 0; $i < $columnscount; $i++)
    prnt ("<td align=\"center\">" . imagetag ("hborder35.gif") . "</td>");
  prnt ("<td align=\"center\">" . imagetag ("border1.gif") . "</td>");
  prnt ("</tr>\n");
  for ($i = 0; $i < $columnscount; $i++)
    $columnrowspan[$i] = (int)$columnrowspan[$i];
  for ($i = $histograms['height'] + 3; $i > 1; $i--) {
    prnt ("<tr>");
    prnt ("<td align=\"center\">" . imagetag ("vborder10.gif") . "</td>");
    for ($j = 0; $j < $columnscount; $j++) {
      if ($i == ($columnrowspan[$j] + 3)) {
        prnt ("<th rowspan=\"2\" valign=\"bottom\"><font size=\"-1\" color=\"" . $histograms['textcolor'] . "\">");
        prnt ("$columnnumbers[$j]</font></th>");
      }
      else if ($i == $columnrowspan[$j])
        prnt ("<td align=\"center\">" . imagetag ($color . "bartop.gif") . "</td>");
      else if ($i < $columnrowspan[$j])
        prnt ("<td align=\"center\">" . imagetag ($color . "barmiddle.gif") . "</td>");
      else if ($i != ($columnrowspan[$j] + 2)) {
        prnt ("<td height=\"10\" width=\"35\">");
        prnt ("</td>");
      }
    }
    prnt ("<td align=\"center\">" . imagetag ("vborder10.gif") . "</td>");
    prnt ("</tr>\n");
  }
  prnt ("<tr>");
  prnt ("<td align=\"center\">" . imagetag ("vborder10.gif") . "</td>");
  for ($j = 0; $j < $columnscount; $j++) {
    if ($i <= $columnrowspan[$j])
      prnt ("<td align=\"center\">" . imagetag ($color . "barbottom.gif") . "</td>");
    else {
      prnt ("<td align=\"center\" valign=\"bottom\">");
      prnt (imagetag ("hborder35.gif") . "</td>");
    }
  }
  prnt ("<td align=\"center\">" . imagetag ("vborder10.gif") . "</td>");
  prnt ("</tr>\n");
  prnt ("<tr>");
  prnt ("<td align=\"center\">" . imagetag ("vborder50.gif") . "</td>");
  for ($i = 0; $i < $columnscount; $i++) {
    prnt ("<th width=\"35\"><font size=\"-1\" color=\"" . $histograms['textcolor'] . "\">$columnnames[$i]</font></th>");
    $columnrowspan[$i] = (int)$columnrowspan[$i];
  }
  prnt ("<td align=\"center\">" . imagetag ("vborder50.gif") . "</td>");
  prnt ("</tr>\n");
  prnt ("<tr>");
  prnt ("<td align=\"center\">" . imagetag ("border1.gif") . "</td>");
  for ($i = 0; $i < $columnscount; $i++)
    prnt ("<td align=\"center\">" . imagetag ("hborder35.gif") . "</td>");
  prnt ("<td align=\"center\">" . imagetag ("border1.gif") . "</td>");
  prnt ("</tr>\n");
  prnt ("</table>\n");
  prnt ("</td></tr>\n");
  prnt ("</table>");
  if ($manuallycreateimages) {
    prnt ("<br>\n");
    prnt ("<form method=\"post\" enctype=\"multipart/form-data\"");
    prnt (" action=\"histograms.php?course=$course");
    if ($semester != $currentsemester)
      prnt ("&semester=$semester");
    prnt ("&action=image");
    prnt ("&assignment=$fieldname&color=$color&update=$time\"");
    prnt (" target=\"_blank\">\n");
    prnt ("<input type=\"submit\" name=\"button\"");
    prnt (" value=\"Create Image\">\n");
    prnt ("</form>\n");
  }
}


/* produces image histogram
   returns nothing
   $name is the name of the histogram
   $color is the bar color (blue/green/hex color)
   $columnnames is a flat array of bar names
   $columnrowspan is a flat array of column heights (in table rows (10 pixels))
   $columnnumbers is a flat array of numbers that the bars represent
*/
function imagegraph ($name, $color, $columnnames, $columnrowspan, $columnnumbers) {
  global $histograms;
  $columnscount = count ($columnnames);
  $totalcolumnwidth = $histograms['imagebarwidth'] + $histograms['imagebarspace'] * 2;
  $maxtextwidth = floor ($histograms['imagebarwidth'] + $histograms['imagebarspace'] * 1.75);
  if (is_int ($histograms['imagetitlefont'])) {
    $titleheight = imagefontheight ($histograms['imagetitlefont']);
    $titlewidth = strlen ($name) * imagefontwidth ($histograms['imagetitlefont']);
  }
  else {
    $textinfo = imagettfbbox ($histograms['imagetitlefontsize'], 0, $histograms['imagetitlefont'], $name);
    $titleheight = abs ($textinfo[1] - $textinfo[7]);
    $titlewidth = abs ($textinfo[2] - $textinfo[0]);
  }
  if (is_int ($histograms['imagefont'])) {
    $fontheight = imagefontheight ($histograms['imagefont']);
    $fontwidth = imagefontwidth ($histograms['imagefont']);
  }
  else {
    $textinfo = imagettfbbox ($histograms['imagefontsize'], 0, $histograms['imagefont'], "0");
    $fontheight = abs ($textinfo[1] - $textinfo[7]);
  }
  $maxnameswidth = 0;
  $maxnamesheight = 0;
  $maxnumberswidth = 0;
  $maxnumbersheight = 0;
  $vertnames = false;
  $vertnumbers = false;
  for ($i = 0; $i < $columnscount; $i++) {
    $columnnames[$i] = str_replace ("<br>", " ", $columnnames[$i]);
    if (is_int ($histograms['imagefont'])) {
      $nameswidth[$i] = strlen ($columnnames[$i]) * $fontwidth;
      $namesheight[$i] = $fontheight;
      $numberswidth[$i] = strlen ($columnnumbers[$i]) * $fontwidth;
      $numbersheight[$i] = $fontheight;
    }
    else {
      $textinfo = imagettfbbox ($histograms['imagefontsize'], 0, $histograms['imagefont'], $columnnames[$i]);
      $nameswidth[$i] = abs ($textinfo[2] - $textinfo[0]);
      $namesheight[$i] = abs ($textinfo[1] - $textinfo[7]);
      $textinfo = imagettfbbox ($histograms['imagefontsize'], 0, $histograms['imagefont'], $columnnumbers[$i]);
      $numbersheight[$i] = abs ($textinfo[1] - $textinfo[7]);
      $numberswidth[$i] = abs ($textinfo[2] - $textinfo[0]);
    }
    if ($nameswidth[$i] > $maxnameswidth)
      $maxnameswidth = $nameswidth[$i];
    if ($namesheight[$i] > $maxnamesheight)
      $maxnamesheight = $namesheight[$i];
    if ($numberswidth[$i] > $maxnumberswidth)
      $maxnumberswidth = $numberswidth[$i];
    if ($numbersheight[$i] > $maxnumbersheight)
      $maxnumbersheight = $numbersheight[$i];
  }
  if ($maxnameswidth > $maxtextwidth) {
    $vertnames = true;
    $temp = $nameswidth;
    $nameswidth = $namesheight;
    $namesheight = $temp;
    $temp = $maxnameswidth;
    $maxnameswidth = $maxnamesheight;
    $maxnamesheight = $temp;
  }
  if ($maxnumberswidth > $maxtextwidth) {
    $vertnumbers = true;
    $temp = $numberswidth;
    $numberswidth = $numbersheight;
    $numbersheight = $temp;
    $temp = $maxnumberswidth;
    $maxnumberswidth = $maxnumbersheight;
    $maxnumbersheight = $temp;
  }
  $topoffset = $histograms['imageborder'] + $histograms['imagetextoffset'] * 2 + $titleheight;
  $bottomoffset = $histograms['imageborder'] + $histograms['imagetextoffset'] * 2 + $maxnamesheight;
  $graphheight = $histograms['height'] * 10 + $maxnumbersheight + $histograms['imagetextoffset'];
  $imageheight = $graphheight + $topoffset + $bottomoffset;
  $graphwidth = $columnscount * $totalcolumnwidth;
  $testwidth = $titlewidth + $histograms['imageborder'] * 2;
  if ($testwidth > $graphwidth) {
    $sideoffset = ($testwidth - $graphwidth) / 2;
    if (is_int (strpos ($sideoffset, ".")))
      $sideoffset = ceil ($sideoffset);
  }
  else
    $sideoffset = $histograms['imageborder'];
  $imagewidth = $graphwidth + $sideoffset * 2;
  $image = imagecreate ($imagewidth, $imageheight);
  if (!is_array ($bgcolor = ishexcolor ($histograms['bgcolor']))) {
    $errormsg = "Histogram background color is not a valid RRGGBB color";
    fatalerror ($errormsg, $errormsg);
  }
  if (!is_array ($titlecolor = ishexcolor ($histograms['titlecolor']))) {
    $errormsg = "Histogram title color is not a valid RRGGBB color";
    fatalerror ($errormsg, $errormsg);
  }
  if (!is_array ($textcolor = ishexcolor ($histograms['textcolor']))) {
    $errormsg = "Histogram text color is not a valid RRGGBB color";
    fatalerror ($errormsg, $errormsg);
  }
  if (!is_array ($bordercolor = ishexcolor ($histograms['imagebordercolor']))) {
    $errormsg = "Histograms border color is not a valid RRGGBB color";
    fatalerror ($errormsg, $errormsg);
  }
  if (!is_array ($barbordercolor = ishexcolor ($histograms['imagebarbordercolor']))) {
    $errormsg = "Histograms bar border color is not a valid RRGGBB color";
    fatalerror ($errormsg, $errormsg);
  }
  $bgcolor = imagecolorallocate ($image, $bgcolor[0], $bgcolor[1], $bgcolor[2]);
  $bordercolor = imagecolorallocate ($image, $bordercolor[0], $bordercolor[1], $bordercolor[2]);
  $barbordercolor = imagecolorallocate ($image, $barbordercolor[0], $barbordercolor[1], $barbordercolor[2]);
  $titlecolor = imagecolorallocate ($image, $titlecolor[0], $titlecolor[1], $titlecolor[2]);
  $textcolor = imagecolorallocate ($image, $textcolor[0], $textcolor[1], $textcolor[2]);
  $ishexcolor = ishexcolor ($color);
  if (is_array ($ishexcolor))
    $barcolor = imagecolorallocate ($image, $ishexcolor[0], $ishexcolor[1], $ishexcolor[2]);
  else if ($color == "green")
    $barcolor = imagecolorallocate ($image, 0x00, 0xFF, 0x00);
  else
    $barcolor = imagecolorallocate ($image, 0x00, 0x00, 0xFF);
  imagefill ($image, 0, 0, $bgcolor);
  $x1 = $sideoffset;
  $y1 = $topoffset - $histograms['imagetextoffset'];
  $x2 = $imagewidth - $sideoffset;
  $y2 = $imageheight - $bottomoffset;
  imagerectangle ($image, $x1, $y1, $x2, $y2, $bordercolor);
  $y1 = $y2;
  $y2 = $imageheight - $histograms['imageborder'];
  imagerectangle ($image, $x1, $y1, $x2, $y2, $bordercolor);
  if (is_int ($histograms['imagetitlefont']))
    $namey = $histograms['imageborder'];
  else
    $namey = $histograms['imageborder'] + $titleheight;
  $namex = ($imagewidth - $titlewidth) / 2;
  if (is_int ($histograms['imagetitlefont']))
    imagestring ($image, $histograms['imagetitlefont'], $namex, $namey, "$name", $titlecolor);
  else
    imagettftext ($image, $histograms['imagetitlefontsize'], 0, $namex, $namey, $titlecolor, $histograms['imagetitlefont'], "$name");
  $x = $sideoffset;
  $y2 = $imageheight - $bottomoffset;
  $mintextvertoffset = $imageheight - $histograms['imageborder'] - $histograms['imagetextoffset'];
  if (is_int ($histograms['imagefont']) && !$vertnames)
    $mintextvertoffset -= $maxnamesheight;
  for ($i = 0; $i < $columnscount; $i++) {
     $x1 = $x + $histograms['imagebarspace'];
     $y1 = $imageheight - $bottomoffset - $columnrowspan[$i] * 10;
     $x2 = $x1 + $histograms['imagebarwidth'];
     imagefilledrectangle ($image, $x1, $y1, $x2, $y2, $barcolor);
     imagerectangle ($image, $x1, $y1, $x2, $y2, $barbordercolor);
     imageline ($image, $x1, $y2, $x2, $y2, $bordercolor);
     $nametextx = $x + ($totalcolumnwidth - $nameswidth[$i]) / 2;
     if ($vertnames) {
       if (!is_int ($histograms['imagefont']))
         $nametextx += $nameswidth[$i];
       $nametexty = $mintextvertoffset - $maxnamesheight + $namesheight[$i];
     }
     else
       $nametexty = $mintextvertoffset - ($maxnamesheight - $namesheight[$i]) / 2;
     $numberstextx = $x + ($totalcolumnwidth - $numberswidth[$i]) / 2;
     if (is_int ($histograms['imagefont'])) {
       $numberstexty = $y1 - $histograms['imagetextoffset'] - $numbersheight[$i];
       if ($vertnames)
         imagestringup ($image, $histograms['imagefont'], $nametextx, $nametexty, "$columnnames[$i]", $textcolor);
       else
         imagestring ($image, $histograms['imagefont'], $nametextx, $nametexty, "$columnnames[$i]", $textcolor);
       if ($vertnumbers)
         imagestringup ($image, $histograms['imagefont'], $numberstextx, $numberstexty, "$columnnumbers[$i]", $textcolor);
       else
         imagestring ($image, $histograms['imagefont'], $numberstextx, $numberstexty, "$columnnumbers[$i]", $textcolor);
     }
     else {
       if ($vertnumbers)
         $numberstextx += $numberswidth[$i];
       $numberstexty = $y1 - $histograms['imagetextoffset'];
       if ($vertnames)
         $angle = 90;
       else
         $angle = 0;
       imagettftext ($image, $histograms['imagefontsize'], $angle, $nametextx, $nametexty, $textcolor, $histograms['imagefont'], "$columnnames[$i]");
       if ($vertnumbers)
         $angle = 90;
       else
         $angle = 0;
       imagettftext ($image, $histograms['imagefontsize'], $angle, $numberstextx, $numberstexty, $textcolor, $histograms['imagefont'], "$columnnumbers[$i]");
     }
     $x += $totalcolumnwidth;
  }
  $format = strtolower ($histograms['imagetype']);
  if ($format == "gif") {
    header ("Content-type: image/gif");
    imagegif ($image);
  }
  else if (($format == "jpeg") || ($format == "jpg")) {
    header ("Content-type: image/jpeg");
    imagejpeg ($image);
  }
  else {
    header ("Content-type: image/png");
    imagepng ($image);
  }
}


/* produces histograms
   returns nothing
   $selectedfields is a flat array of fields (assignments) to histogram
*/
function histograms ($selectedfields) {
  global $course;
  global $semester;
  global $currentsemester;
  global $color;
  global $options;
  global $gradeequivalents;
  global $histograms;
  global $alwayscreateimages;
  global $manuallycreateimages;
  global $action;
  global $studentinfofields;
  global $time;
  global $priv;
  for ($i = 0, $j = 0; $i < count ($selectedfields); $i++) {
    if (isemptystring ($selectedfields[$i]))
      continue;
    if ($selectedfields[$i] == "numeric_grade") {
      if ($options['hidenumericgrade'] && !$priv['isnonstudent'])
	continue;
    }
    $data[$j] = getassignmentcolumndata ($selectedfields[$i]);
    if (!is_array ($data[$j]) || (count ($data[$j]) < 2)) {
      unset ($data[$j]);
      continue;
    }
    if ($selectedfields[$i] == "numeric_grade") {
      $assignmentinfo[$j]['assignment'] = "numeric_grade";
      $assignmentinfo[$j]['name'] = $studentinfofields['numeric_grade'];
      $statistics[$j] = makestatistics (&$data[$j], false, true, false);
      $j++;
      continue;
    }
    if (!($assignmentinfo[$j] = getassignmentinfo ($selectedfields[$i]))) {
      unset ($data[$j]);
      unset ($assignmentinfo[$j]);
    }
    else if ($assignmentinfo[$j]['show_grades'] == 0) {
      unset ($data[$j]);
      unset ($assignmentinfo[$j]);
    }
    else {
      if ($assignmentinfo['type'] == 0)
	$lettergrade = false;
      else
	$lettergrade = true;
      $statistics[$j] = makestatistics (&$data[$j], $lettergrade, false, false);
      $j++;
    }
  }
  $numgrades = count ($gradeequivalents);
  reset ($gradeequivalents);
  for ($i = $numgrades - 1; $elementinfo = each ($gradeequivalents); $i--)
    $lettergradebins[$elementinfo['key']] = $i;
  $decimalincrement = pow (10, 0 - $options['floatround']);
  $selectedfieldscount = count ($data);
  if ($selectedfieldscount <= 0)
    inputerror ("No histograms selected.");
  $histogramsprinted = 0;
  if (!isset ($color)) {
    $firstcolor = "blue";
    $color = $firstcolor;
  }
  for ($i = 0; $i < $selectedfieldscount; $i++) {
    $decimalgrade = false;
    $lettergrade = false;
    if ($assignmentinfo[$i]['assignment'] == "numeric_grade")
      $decimalgrade = true;
    else if ($assignmentinfo[$i]['type'] != 0)
      $lettergrade = true;
    else if (isdecimalassignment ($data[$i]))
      $decimalgrade = true;
    if (($histogramsprinted % $histograms['numperrow']) == 0) {
      if ($histogramsprinted != 0) {
        prnt ("</tr>\n");
        if ($firstcolor == "blue")
          $firstcolor = "green";
        else
          $firstcolor = "blue";
        $color = $firstcolor;
      }
      $colspan = ($histograms['numperrow'] * 2) - 1;
      if ($i != 0)
        prnt ("<tr><td colspan=\"$colspan\" height=\"35\">&nbsp</td></tr>\n");
      prnt ("<tr>\n");
    }
    else
      prnt ("<td width=\"35\">&nbsp;</td>\n");
    prnt ("<td align=\"center\" valign=\"top\">\n");
    if ((!isset ($action) || isemptystring ($action)) && $alwayscreateimages) {
      prnt ("<img src=\"histograms.php?course=$course");
      if ($semester != $currentsemester)
        prnt ("&semester=$semester");
      prnt ("&action=image");
      prnt ("&assignment=" . $assignmentinfo[$i]['assignment'] . "&color=$color&update=$time\">\n");
      prnt ("</td>\n");
      if ($color == "blue")
        $color = "green";
      else
        $color = "blue";
      $histogramsprinted++;
      continue;
    }
    if ($histogramsprinted != 0) {
      unset ($columnnumbers);
      unset ($columnnames);
    }
    $maxcolumnnumber = 0;
    $datacount = count ($data[$i]);
    if ($lettergrade) {
      reset ($lettergradebins);
      while ($elementinfo = each ($lettergradebins)) {
        $columnnumbers[$elementinfo['value']] = 0;
        $columnnames[$elementinfo['value']] = $elementinfo['key'];
      }
      for ($j = 0; $j < $datacount; $j++) {
        $column = $lettergradebins[$data[$i][$j]];
        $columnnumbers[$column]++;
        if ($columnnumbers[$column] > $maxcolumnnumber)
          $maxcolumnnumber = $columnnumbers[$column];
      }
    }
    else {
      $range = $statistics[$i]['max'] - $statistics[$i]['min'];
      if ($range == 0) {
        $columnmax[0] = $statistics[$i]['min'];
        $columnnumbers[0] = 0;
        $columnnames[0] = $statistics[$i]['min'];
      }
      else {
        if (!$decimalgrade) {
          $increment = 1;
          $columnrange = ($range + 1) / $histograms['columns'];
          if (isdecimal ($columnrange))
            $columnrange = ceil ($columnrange);
          $columnscount = ($range + 1) / $columnrange;
          if (isdecimal ($columnscount))
            $columnscount = ceil ($columnscount);
        }
        else {
          $increment = $decimalincrement;
          $columnrange = $range / (double)$histograms['columns'];
          $columnscount = $histograms['columns'];
        }
        $min = $statistics[$i]['min'];
	if (!$decimalgrade && ($columnrange == 1))
	  $min--;
        $exactmin = $min;
        for ($j = 0; $j < $columnscount; $j++) {
          $max = $exactmin + $columnrange;
          if ($decimalgrade)
            $columnmax[$j] = decimalfix ($max, $options['floatround']);
          else
            $columnmax[$j] = $max;
          if ($j != 0)
            $min += $increment;
          if ($decimalgrade)
            $min = decimalfix ($min, $options['floatround']);
          $columnnumbers[$j] = 0;
          if ($decimalgrade)
            $columnnames[$j] = "$min<br>-<br>$columnmax[$j]";
          else if ($columnrange == 1)
            $columnnames[$j] = $columnmax[$j];
          else
            $columnnames[$j] = "$min -<br>$columnmax[$j]";
          $exactmin = $max;
          $min = $columnmax[$j];
        }
      }
      $column = 0;
      for ($j = 0; $j < $datacount; $j++) {
        while (1) {
          if ($decimalgrade)
            $number = decimalfix ($data[$i][$j], $options['floatround']);
          else
            $number = $data[$i][$j];
          if ($column >= $columnscount)
            break;
          if ($number <= $columnmax[$column])
            break;
          $column++;
        }
        $columnnumbers[$column]++;
        if ($columnnumbers[$column] > $maxcolumnnumber)
          $maxcolumnnumber = $columnnumbers[$column];
      }
    }
    $columnscount = count ($columnnames);
    $heightscalefactor = $histograms['height'] / $maxcolumnnumber;
    if (($selectedfieldscount == 1) || ($action == "Create Image"))
      $assignmentinfo[$i]['name'] = $course . ": " . $assignmentinfo[$i]['name'];
    for ($j = 0; $j < $columnscount; $j++)
      $columnrowspan[$j] = $columnnumbers[$j] * $heightscalefactor;
    if ($action == "Create Image")
      imagegraph ($assignmentinfo[$i]['name'], $color, $columnnames, $columnrowspan, $columnnumbers);
    else
      tablegraph ($assignmentinfo[$i]['name'], $color, $columnnames, $columnrowspan, $columnnumbers, $assignmentinfo[$i]['assignment']);
    prnt ("</td>\n");
    if ($color == "blue")
      $color = "green";
    else
      $color = "blue";
    $histogramsprinted++;
  }
  $histogramsprinted--;
  if (($histogramsprinted % $histograms['numperrow']) == 0) { 
    if ($histogramsprinted >= 0)
      prnt ("</tr>\n");
  }
}


if (isemptystring ($netid)) {
  $options = getdefaults ($courseconfigoptions);
  loginpage (courselink (PATHTOHTTPROOT . "restricted/userhome.php", false));
}
if (isemptystring ($course))
  inputerror ("Unknown course.");
if ($priv['isvisitor'])
  inputerror ("You do not have permission to access this module.");
$options = getcourseoptions ($department, $coursenumber);
if (!is_array ($options)) {
  $errormsg = "No course options available.";
  fatalerror ($errormsg, false);
}
sethistogramvars ($options['histograms'], &$createhistograms, &$alwayscreateimages, &$manuallycreateimages);
if (!is_bool ($alwayscreateimages))
  unset ($alwayscreateimages);
if (!is_bool ($manuallycreateimages))
  unset ($manuallycreateimages);
if (isset ($action) && ($action == "image"))
  $action = "Create Image";
if (isset ($action) && ($action != "Create Image"))
  unset ($action);
if (isset ($action))
  unset ($selectedfields);
if (isset ($assignment) && !isemptystring ($assignment)) {
  unset ($selectedfields);
  $selectedfields[0] = $assignment;
}
if (!$createhistograms)
  unset ($selectedfields);
/*set options from URL*/
if ($action == "Create Image") {
  if (isset ($bgcolor) && !isemptystring ($bgcolor)) {
    if (is_array (ishexcolor ($bgcolor)))
      $histograms['bgcolor'] = $bgcolor;
    else
      inputerror ("bgcolor is not a valid RRGGBB color.");
  }
  if (isset ($bordercolor) && !isemptystring ($bordercolor)) {
    if (is_array (ishexcolor ($bordercolor)))
      $histograms['imagebordercolor'] = $bordercolor;
    else
      inputerror ("imagebordercolor is not a valid RRGGBB color.");
  }
  if (isset ($barbordercolor) && !isemptystring ($barbordercolor)) {
    if (is_array (ishexcolor ($barbordercolor)))
      $histograms['imagebarbordercolor'] = $barbordercolor;
    else
      inputerror ("imagebarbordercolor is not a valid RRGGBB color.");
  }
  if (isset ($titlecolor) && !isemptystring ($titlecolor)) {
    if (is_array (ishexcolor ($titlecolor)))
      $histograms['titlecolor'] = $titlecolor;
    else
      inputerror ("titlecolor is not a valid RRGGBB color.");
  }
  if (isset ($textcolor) && !isemptystring ($textcolor)) {
    if (is_array (ishexcolor ($textcolor)))
      $histograms['textcolor'] = $textcolor;
    else
      inputerror ("textcolor is not a valid RRGGBB color.");
  }
}
$page['browsertitle'] = "Histograms";
$page['title'] = "Histograms";
histograms ($selectedfields);
if (!isset ($action) || isemptystring ($action))
  printpage ($page);
?>
Return current item: Whiteboard