コード例 #1
0
    /**
     * Generates a ZIP file containing all file uploads for a given test and the original id of the question
     *
     * @param int $test_id
     */
    public function getFileUploadZIPFile($test_id)
    {
        /** @var ilDB $ilDB */
        global $ilDB;
        $query = "\n\t\tSELECT \n\t\t\ttst_solutions.solution_id, tst_solutions.pass, tst_solutions.active_fi, tst_solutions.question_fi, \n\t\t\ttst_solutions.value1, tst_solutions.value2, tst_solutions.tstamp \n\t\tFROM tst_solutions, tst_active, qpl_questions \n\t\tWHERE tst_solutions.active_fi = tst_active.active_id \n\t\tAND tst_solutions.question_fi = qpl_questions.question_id \n\t\tAND tst_solutions.question_fi = %s \n\t\tAND tst_active.test_fi = %s \n\t\tORDER BY tst_solutions.active_fi, tst_solutions.tstamp";
        $result = $ilDB->queryF($query, array("integer", "integer"), array($this->getId(), $test_id));
        $zipfile = ilUtil::ilTempnam() . ".zip";
        $tempdir = ilUtil::ilTempnam();
        if ($result->numRows()) {
            $userdata = array();
            $data .= "<html><head>";
            $data .= '<meta http-equiv="content-type" content="text/html; charset=UTF-8" />';
            $data .= '<style>
			 table { border: 1px #333 solid; border-collapse:collapse;}	
			 td, th { border: 1px #333 solid; padding: 0.25em;}	
			 th { color: #fff; background-color: #666;}
			</style>
			';
            $data .= "<title>" . $this->getTitle() . "</title></head><body>\n";
            $data .= "<h1>" . $this->getTitle() . "</h1>\n";
            $data .= "<table><thead>\n";
            $data .= "<tr><th>" . $this->lng->txt("name") . "</th><th>" . $this->lng->txt("filename") . "</th><th>" . $this->lng->txt("pass") . "</th><th>" . $this->lng->txt("location") . "</th><th>" . $this->lng->txt("date") . "</th></tr></thead><tbody>\n";
            while ($row = $ilDB->fetchAssoc($result)) {
                ilUtil::makeDirParents($tempdir . "/" . $row["active_fi"] . "/" . $row["question_fi"]);
                @copy($this->getFileUploadPath($test_id, $row["active_fi"], $row["question_fi"]) . $row["value1"], $tempdir . "/" . $row["active_fi"] . "/" . $row["question_fi"] . "/" . $row["value1"]);
                if (!array_key_exists($row["active_fi"], $userdata)) {
                    include_once "./Modules/Test/classes/class.ilObjTestAccess.php";
                    $userdata[$row["active_fi"]] = ilObjTestAccess::_getParticipantData($row["active_fi"]);
                }
                $data .= "<tr><td>" . $userdata[$row["active_fi"]] . "</td><td><a href=\"" . $row["active_fi"] . "/" . $row["question_fi"] . "/" . $row["value1"] . "\" target=\"_blank\">" . $row["value2"] . "</a></td><td>" . $row["pass"] . "</td><td>" . $row["active_fi"] . "/" . $row["question_fi"] . "/" . $row["value1"] . "</td>";
                $data .= "<td>" . ilFormat::fmtDateTime(ilFormat::unixtimestamp2datetime($row["tstamp"]), $this->lng->txt("lang_dateformat"), $this->lng->txt("lang_timeformat"), "datetime", FALSE) . "</td>";
                $data .= "</tr>\n";
            }
            $data .= "</tbody></table>\n";
            $data .= "</body></html>\n";
            $indexfile = $tempdir . "/index.html";
            $fh = fopen($indexfile, 'w');
            fwrite($fh, $data);
            fclose($fh);
        }
        ilUtil::zip($tempdir, $zipfile);
        ilUtil::delDir($tempdir);
        ilUtil::deliverFile($zipfile, ilUtil::getASCIIFilename($this->getTitle() . ".zip"), "application/zip", false, true);
    }