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

unset ($page);

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


if (isemptystring ($netid)) {
  $options = getdefaults ($courseconfigoptions);
  loginpage (courselink ("getsubmissions.php", false));
}
if (isemptystring ($course))
  inputerror ("Unknown course.");
if (!$priv['isnonstudent'])
  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);
}
$illegal = false;
if (!isset ($assignment) || isemptystring ($assignment))
  $illegal = true;
else if (!is_array ($assignmentinfo = getassignmentinfo ($assignment)))
  $illegal = true;
else if ($assignmentinfo['allow_submission'] == 0)
  $illegal = true;
/*assignment selection*/
if ($illegal) {
  $assignments = getassignments ();
  $categories = getcategories ();
  $orderedassignments = makeorderedassignments ($assignments, $categories);
  if (is_array ($orderedassignments)  && (count ($orderedassignments) == 1)) {
    $assignment = $orderedassignments[0]['assignment'];
    $assignmentinfo = $orderedassignments[0];
  }
  else {
    $page['title'] = "Submitted Assignments";
    $page['browsertitle'] = "Submitted Assignments";
    if (!is_array ($orderedassignments) || (count ($orderedassignments) <= 0))
      prnt ("<tr><td class=\"pagetext\">No Assignments</td></tr>\n");
    else
      assignmentbox ($orderedassignments);
    printpage ($page);
    exit ();
  }
}
if (!is_array ($submitinfo = getsubmitinfo ($assignment))) {
  $errormsg = "No submission options available.";
  $detailedmsg = "assignment '" . $assignment . "'";
  fatalerror ($errormsg, $detailedmsg);
}
/*make zip file*/
if (isset ($action) && ($action == "getzip")) {
  if (is_bool ($tempfile = tempnam (TEMPDIR, "zip"))) {
    $errormsg = "Unable to create temp file.";
    $detailedmsg = "Unable to create temp file in '" . TEMPDIR . "'.";
    fatalerror ($errormsg, $detailedmsg);
  }
  if (!chdir (COURSEDIR)) {
    $errormsg = "Unable to change directory.";
    $detailedmsg = "Unable to change directory to '" . COURSEDIR . "'.";
    fatalerror ($errormsg, $detailedmsg);
  }
  $dir = escapeshellarg ("./submissions/*/" . $assignment . "/*");
  $command = FINDCOMMAND . " . -maxdepth 4 -type f -path " . $dir;
  $command .= " -print | " . ZIPCOMMAND  . " " . escapeshellarg ($tempfile) . " -@";
  @exec ($command);
  $filename = $course . "_" . $semester . "_" . $assignment . "_submissions.zip";
  header ("Cache-control: private");
  header ("Content-Type: application/zip; name=\"" . $filename . "\"");
  header ("Content-Disposition: ; filename=\"" . $filename . "\"");
  if ($filesize = @filesize ($tempfile . ".zip"))
    header ("Content-Length: " . $filesize);
  @readfile ($tempfile . ".zip");
  @unlink ($tempfile);
  @unlink ($tempfile . ".zip");
  exit ();
}
$requiredfiles = false;
if (is_array ($submitinfo['requiredfilesconv'])) {
  if (count ($submitinfo['requiredfilesconv']) > 0) {
    while ($elementinfo = each ($submitinfo['requiredfilesconv'])) {
      if (!isemptystring ($elementinfo['value']))
        $requiredfiles[$elementinfo['value']] = false;
    }
  }
}
$page['title'] = "Submitted Assignments";
$page['subtitle'] = $assignmentinfo['name'];
$page['browsertitle'] = "Submitted Assignments";
$page['toplinks'][0]['text'] = "Assignment Submissions Zip File";
$page['toplinks'][0]['address'] = "getsubmissions.php?course=" . $course;
if ($semester != $currentsemester)
  $page['toplinks'][0]['address'] .= "&semester=" . $semester;
$page['toplinks'][0]['address'] .= "&assignment=" . $assignment;
$page['toplinks'][0]['address'] .= "&action=getzip";
$page['toplinks'][0]['target'] = "_blank";
$page['toplinks'][1]['text'] = "Assignment Submissions Log File";
$link = PATHTOHTTPROOT . "download.php";
$link .= "?course=" . $course;
if ($semester != $currentsemester)
  $link .= "&semester=" . $semester;
$link .= "&location=assignmentsubmissionslogfile&assignment=" . $assignment;
$page['toplinks'][1]['address'] = $link;
$page['toplinks'][1]['target'] = "_blank";
$page['toplinks'][2]['text'] = "Late Submissions Log File";
$link = PATHTOHTTPROOT . "download.php";
$link .= "?course=" . $course;
if ($semester != $currentsemester)
  $link .= "&semester=" . $semester;
$link .= "&location=latesubmissionslogfile";
$page['toplinks'][2]['address'] = $link;
$page['toplinks'][2]['target'] = "_blank";
$sort = getsort ();
$assignments = getassignments ();
$studentinfo = getallstudentinfo ($sort, $assignments);
if (!is_array ($studentinfo) || (count ($studentinfo) <= 0)) {
  prnt ("<tr><td class=\"pagetext\">No Students</td></tr>\n");
  printpage ($page);
  exit ();
}
$islate = false;
$isingraceperiod = false;
$filedeadline = false;
if (isposnzinteger ($submitinfo['deadlineconv'])) {
  if ($time > $submitinfo['deadlineconv'])
    $islate = true;
  $filedeadline = $submitinfo['deadlineconv'];
  if (isposinteger ($submitinfo['graceperiodconv'])) {
    $filedeadline += $submitinfo['graceperiodconv'];
    if ($time <= $submitinfo['graceperiodconv'])
      $isingraceperiod = true;
  }
  $page['topdata'][0]['field'] = "Deadline:";
  $page['topdata'][0]['data'] = $submitinfo['deadline'];
}
unset ($filesinfo);
reset ($studentinfo);
while ($elementinfo = each ($studentinfo)) { 
  $studentid = $elementinfo['value']['netid'];
  $filespath = SUBMISSIONSDIR . "/" . $studentid . "/" . $assignment;
  unset ($submittedfiles);
  $numnotsubmitted = dirfilesinfo ($filespath, &$submittedfiles, false, false, $requiredfiles, $filedeadline);
  $filesinfo[$studentid]['files'] = $submittedfiles;
  $filesinfo[$studentid]['numnotsubmitted'] = $numnotsubmitted;
}
reset ($filesinfo);
/*submitted files tables*/
for ($i = 0; $elementinfo = each ($filesinfo); $i++) {
  $key = $elementinfo['key'];
  $value = $elementinfo['value'];
  if (!is_array ($requiredfiles) || (count ($requiredfiles) <= 0))
    $title = $key;
  else if ($value['numnotsubmitted'] <= 0)
    $title = $key;
  else {
    $title = $key . " (missing " . $value['numnotsubmitted'] . " required ";
    $title .= plural ($value['numnotsubmitted'], "file", "files") . ")";
  }
  if ($i != 0)
    prnt (EMPTYTABLEROW . "\n");
  filetable ($value['files'], false, false, $key, $title);
}
printpage ($page);
?>
Return current item: Whiteboard