Location: PHPKode > projects > Whiteboard > whiteboard1.0.3/program/restricted/grades.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", "grades");
define ("PATHTOHTTPROOT", "../");

unset ($page);

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


/* generates one line of grade report
   returns a table row
   $assignmentinfo is an assignment info array
   $data is student's grade for assignment (empty string for none)
   $statistics is the return value of makestatistics () for assignment
   $isgrade is whether line is a real grade (as opposed to student info)
*/
function printgradereportline ($assignmentinfo, $data, $statistics, $isgrade) {
  global $createhistograms;
  global $options;
  if (!isset ($data) || isemptystring ($data)) {
    if ($isgrade)
      $data = "NG";
    else
      $data = "NA";
  }
  else if (isnegnumber ($data))
    $data = "Dropped";
  else if (isposinteger ($data) && ($assignmentinfo['assignment'] != "numeric_grade")) {
    if ($assignmentinfo['name'] != "Class Year")
      $data = integerfix ($data);
  }
  else if (isposnzdecimal ($data) || ($assignmentinfo['assignment'] == "numeric_grade"))
    $data = decimalfix ($data, $options['floatround']);
  else if (($assignmentinfo['type'] != 0) && !islettergrade ($data)) {
    if ($isgrade)
      $data = "NG";
    else
      $data = "NA";
  }
  if ($createhistograms) {
    if (is_array ($statistics)) {
      $element['align'] = "center";
      $element['text'] = "<input type=\"checkbox\" name=\"selectedfields[]\"";
      $element['text'] .= " value=\"" . $assignmentinfo['assignment'];
      $element['text'] .= "\">";
    }
    else
      $element['text'] = "";
    $row[] = $element;
    unset ($element['align']);
  }
  $element['class'] = "tablefieldname";
  $element['text'] = $assignmentinfo['name'];
  $row[] = $element;
  unset ($element['class']);
  $element['align'] = "center";
  $element['text'] = $data;
  $row[] = $element;
  if (isset ($assignmentinfo['num_points']))
    $element['text'] = $assignmentinfo['num_points'];
  else
    $element['text'] = "";
  $row[] = $element;
  if (is_array ($statistics) && (count ($statistics) > 0)) {
    $element['text'] = $statistics['min'] . " - " . $statistics['max'];
    $row[] = $element;
    $element['text'] = $statistics['avg'];
    $row[] = $element;
    $element['text'] = $statistics['med'];
    $row[] = $element;
    if (isset ($statistics['std']))
      $element['text'] = $statistics['std'];
    else
      $element['text'] = "";
    $row[] = $element;
  }
  else {
    $element['text'] = "";
    $element['colspan'] = 4;
    $row[] = $element;
  }
  return $row;
}


/* prints grade report
   returns nothing
   $netid is a student's netid
*/
function gradereport ($netid) {
  global $course;
  global $semester;
  global $currentsemester;
  global $options;
  global $createhistograms;
  global $studentinfofields;
  global $dateandtime;
  global $priv;
  if (!is_array ($studentinfo = getstudentinfo ($netid))) {
    $errormsg = "Unable to get student info.";
    $detailedmsg = "trying to get info for student '" . $netid . "'";
    fatalerror ($errormsg, $detailedmsg);
  }
  $assignments = getassignments ();
  $categories = getcategories ();
  if (!is_array ($grades = getgrades ($netid))) {
    $errormsg = "Unable to get student grades.";
    $detailedmsg = "trying to get grades for student '" . $netid . "'";
    fatalerror ($errormsg, $detailedmsg);
  }
  if (is_array ($assignments)) {
    reset ($assignments);
    while ($elementinfo = each ($assignments)) {
      $assignmentid = $elementinfo['value']['assignment'];
      $islettergrade = false;
      if ($assignments[$assignmentid]['type'] != 0) {
        $islettergrade = true;
        $assignments[$assignmentid]['num_points'] = "A";
      }
      else if (isposinteger ($assignments[$assignmentid]['num_points']))
        $assignments[$assignmentid]['num_points'] = integerfix ($assignments[$assignmentid]['num_points']);
      else if (isposdecimal ($assignments[$assignmentid]['num_points']))
        $assignments[$assignmentid]['num_points'] = decimalfix ($assignments[$assignmentid]['num_points'], $options['floatround']);
      else
        $assignments[$assignmentid]['num_points'] = 0;
      if (is_array ($assignmentcolumn = getassignmentcolumndata ($assignmentid))) {
        $statistics[$assignmentid] = makestatistics ($assignmentcolumn, $islettergrade, false, true);
      }
    }
  }
  $orderedassignments = makeorderedassignments ($assignments, $categories);
  if (!$options['hidenumericgrade'] || $priv['isnonstudent']) {
    $assignmentcolumn = getassignmentcolumndata ("numeric_grade");
    $statistics['numeric_grade'] = makestatistics ($assignmentcolumn, false, true, true);
    $assignments['numeric_grade']['num_points'] = decimalfix ("100.000", $options['floatround']);
    $assignments['numeric_grade']['assignment'] = "numeric_grade";
  }
  $table['tablewidth'] = "100%";
  $table['align'] = "center";
  if ($createhistograms) {
    $table['numcolumns'] = 8;
    $table['form']['address'] = "histograms.php";
    $table['form']['method'] = "POST";
    $table['form']['name'] = "gradesform";
    $table['form']['hidden'][0]['name'] = "netid";
    $table['form']['hidden'][0]['value'] = $netid;
    $table['form']['hidden'][1]['name'] = "course";
    $table['form']['hidden'][1]['value'] = $course;
    if ($semester != $currentsemester) {
      $table['form']['hidden'][2]['name'] = "semester";
      $table['form']['hidden'][2]['value'] = $semester;
    }
    $table['form']['buttons'][0]['name'] = "action";
    $table['form']['buttons'][0]['value'] = "View Histograms";
    $table['form']['buttons'][1]['value'] = "Select All";
    $table['form']['buttons'][1]['onclick'] = "selectall()";
    $table['form']['buttons'][2]['value'] = "Unselect All";
    $table['form']['buttons'][2]['reset'] = true;
  }
  else
    $table['numcolumns'] = 7;
  if ($createhistograms) {
    $heading['text'] = "Select";
    $table['headings'][] = $heading;
  }
  $heading['text'] = "";
  $heading['colspan'] = 2;
  $table['headings'][] = $heading;
  unset ($heading['colspan']);
  $heading['text'] = "Maximum";
  $table['headings'][] = $heading;
  $heading['text'] = "Range";
  $table['headings'][] = $heading;
  $heading['text'] = "Mean";
  $table['headings'][] = $heading;
  $heading['text'] = "Median";
  $table['headings'][] = $heading;
  $heading['text'] = "Std Dev";
  $table['headings'][] = $heading;
  $assignments['course']['name'] = "Course";
  $row = printgradereportline ($assignments['course'], $course, false, false);
  if (is_array ($row) && (count ($row) > 0))
    $table['rows'][] = $row;
  $assignments['semester']['name'] = "Semester";
  $row = printgradereportline ($assignments['semester'], semester2string ($semester), false, false);
  if (is_array ($row) && (count ($row) > 0))
    $table['rows'][] = $row;
  reset ($studentinfo);
  while ($elementinfo = each ($studentinfo)) {
    $key = $elementinfo['key'];
    if (!isset ($studentinfofields[$key]))
      continue;
    if ($key == "numeric_grade") {
      if ($options['hidenumericgrade'] && !$priv['isnonstudent'])
	continue;
    }
    $assignments[$key]['name'] = $studentinfofields[$key];
    $row = printgradereportline ($assignments[$key], $studentinfo[$key], $statistics[$key], false);
    if (is_array ($row) && (count ($row) > 0))
      $table['rows'][] = $row;
  }
  if (is_array ($orderedassignments)) {
    for ($i = 0; $i < count ($orderedassignments); $i++) {
      $assignment = $orderedassignments[$i]['assignment'];
      $row = printgradereportline ($assignments[$assignment], $grades[$assignment], $statistics[$assignment], true);
     if (is_array ($row) && (count ($row) > 0))
       $table['rows'][] = $row;
    }
  }
  prnt (printtable ($table));
}


if (isemptystring ($netid)) {
  $options = getdefaults ($courseconfigoptions);
  loginpage (courselink ("grades.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);
}
$page['browsertitle'] = "Grade Reports";
$page['title'] = "Grades";
/*allow non-students to choose student*/
if ($priv['isnonstudent']) {
  if (!isset ($studentid) || isemptystring ($studentid) || !isstudent ($studentid, $course, $semester)) {
    $sort = getsort ();
    $assignments = getassignments ();
    $studentinfo = getallstudentinfo ($sort, $assignments);
    if (is_array ($studentinfo) && (count ($studentinfo) == 1)) {
      reset ($studentinfo);
      $elementinfo = each ($studentinfo);
      $studentid = $elementinfo['value']['netid'];
    }
    else {
      if (is_array ($studentinfo) && (count ($studentinfo) > 0)) {
        reset ($studentinfo);
        for ($i = 0; $elementinfo = each ($studentinfo); $i++) {
          $studentselect[$i]['value'] = $elementinfo['value']['netid'];
          $studentselect[$i]['text'] = $elementinfo['value']['netid'];
        }
        $hiddenvals['course'] = $course;
        if ($semester != $currentsemester)
	  $hiddenvals['semester'] = $semester;
        prnt ("<tr><td>");
        prnt (selecttable ("Students", "studentid", $studentselect, "grades.php", $hiddenvals));
        prnt ("</td></tr>\n");
      }
      else
        prnt ("<tr><td class=\"pagetext\">No Students</td></tr>\n");
      printpage ($page);
      exit ();
    }
  }
}
else if ($priv['isstudent'])
  $studentid = $netid;
else
  inputerror ("Not a member of this class.");
sethistogramvars ($options['histograms'], &$createhistograms, &$alwayscreateimages, &$manuallycreateimages);
if (!is_bool ($alwayscreateimages))
  unset ($alwayscreateimages);
if (!is_bool ($manuallycreateimages))
  unset ($manuallycreateimages);
$page['message'] = $options['gradesmessage'];
$scripts = "function selectall() {\n";
$scripts .= "  for(var i=0; i<document.gradesform.elements.length; i++) {\n";
$scripts .= "    var currentelement = document.gradesform.elements[i];\n";
$scripts .= "    if (currentelement.type=='checkbox')\n";
$scripts .= "      currentelement.checked = true;\n";
$scripts .= "  }\n";
$scripts .= "}\n";
$page['scripts'] = $scripts;
gradereport ($studentid);
printpage ($page);
?>

Return current item: Whiteboard