Skip to content

Commit

Permalink
Changes according to Mantis issue #18752
Browse files Browse the repository at this point in the history
  • Loading branch information
mjansenDatabay committed Aug 8, 2016
1 parent c652117 commit 1b69594
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
19 changes: 15 additions & 4 deletions Modules/Test/classes/class.ilObjTestGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -3123,6 +3123,12 @@ function printobject()
$questionHeaderBlockBuilder = new ilTestQuestionHeaderBlockBuilder($this->lng);
$questionHeaderBlockBuilder->setHeaderMode($this->object->getTitleOutput());

if($isPdfDeliveryRequest)
{
require_once 'Services/WebAccessChecker/classes/class.ilWACSignedPath.php';
ilWACSignedPath::setTokenMaxLifetimeInSeconds(60);
}

foreach ($this->object->questions as $question)
{
$template->setCurrentBlock("question");
Expand Down Expand Up @@ -3157,7 +3163,6 @@ function printobject()

if( $isPdfDeliveryRequest )
{
//$this->object->deliverPDFfromHTML($template->get(), $this->object->getTitle());
require_once 'class.ilTestPDFGenerator.php';
ilTestPDFGenerator::generatePDF($template->get(), ilTestPDFGenerator::PDF_OUTPUT_DOWNLOAD, $this->object->getTitle());
}
Expand Down Expand Up @@ -3188,6 +3193,8 @@ function reviewobject()

$this->tpl->addCss(ilUtil::getStyleSheetLocation("output", "test_print.css", "Modules/Test"), "print");

$isPdfDeliveryRequest = isset($_GET['pdf']) && $_GET['pdf'];

global $ilUser;
$print_date = mktime(date("H"), date("i"), date("s"), date("m") , date("d"), date("Y"));
$max_points= 0;
Expand All @@ -3196,6 +3203,12 @@ function reviewobject()
require_once 'Modules/Test/classes/class.ilTestQuestionHeaderBlockBuilder.php';
$questionHeaderBlockBuilder = new ilTestQuestionHeaderBlockBuilder($this->lng);
$questionHeaderBlockBuilder->setHeaderMode($this->object->getTitleOutput());

if($isPdfDeliveryRequest)
{
require_once 'Services/WebAccessChecker/classes/class.ilWACSignedPath.php';
ilWACSignedPath::setTokenMaxLifetimeInSeconds(60);
}

foreach ($this->object->questions as $question)
{
Expand Down Expand Up @@ -3227,11 +3240,9 @@ function reviewobject()
$template->setVariable("TXT_MAXIMUM_POINTS", ilUtil::prepareFormOutput($this->lng->txt("tst_maximum_points")));
$template->setVariable("VALUE_MAXIMUM_POINTS", ilUtil::prepareFormOutput($max_points));

if (array_key_exists("pdf", $_GET) && ($_GET["pdf"] == 1))
if($isPdfDeliveryRequest)
{
//$this->object->deliverPDFfromHTML($template->get(), $this->object->getTitle());
require_once 'class.ilTestPDFGenerator.php';
$content = $template->get();
ilTestPDFGenerator::generatePDF($template->get(), ilTestPDFGenerator::PDF_OUTPUT_DOWNLOAD, $this->object->getTitle());
}
else
Expand Down
19 changes: 19 additions & 0 deletions Modules/Test/classes/class.ilTestPDFGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,26 @@ private static function makeHtmlDocument($contentHtml, $styleHtml)
}

$dom->encoding = 'UTF-8';

$img_src_map = array();
foreach($dom->getElementsByTagName('img') as $elm)
{
/** @var $elm DOMElement $uid */
$uid = 'img_src_' . uniqid();
$src = $elm->getAttribute('src');

$elm->setAttribute('src', $uid);

$img_src_map[$uid] = $src;
}

$cleaned_html = $dom->saveHTML();

foreach($img_src_map as $uid => $src)
{
$cleaned_html = str_replace($uid, $src, $cleaned_html);
}

if(!$cleaned_html)
{
return $html;
Expand Down

0 comments on commit 1b69594

Please sign in to comment.