00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00034 class ilTestCertificate
00035 {
00043 var $object;
00051 var $ctrl;
00059 var $tree;
00067 var $ilias;
00068
00076 var $tpl;
00077
00085 var $lng;
00086
00096 function ilTestCertificate(&$a_object)
00097 {
00098 global $lng, $tpl, $ilCtrl, $ilias, $tree;
00099
00100 $this->lng =& $lng;
00101 $this->tpl =& $tpl;
00102 $this->ctrl =& $ilCtrl;
00103 $this->ilias =& $ilias;
00104 $this->object =& $a_object;
00105 $this->tree =& $tree;
00106 }
00107
00116 function getCertificatePath()
00117 {
00118 return CLIENT_WEB_DIR . "/assessment/certificates/" . $this->object->getId() . "/";
00119 }
00120
00129 function getBackgroundImagePath()
00130 {
00131 return CLIENT_WEB_DIR . "/assessment/certificates/" . $this->object->getId() . "/" . $this->getBackgroundImageName();
00132 }
00133
00142 function getBackgroundImageName()
00143 {
00144 return "background.jpg";
00145 }
00146
00155 function getBackgroundImageThumbPath()
00156 {
00157 return CLIENT_WEB_DIR . "/assessment/certificates/" . $this->object->getId() . "/" . $this->getBackgroundImageName() . ".thumb.jpg";
00158 }
00159
00168 function getBackgroundImageTempfilePath()
00169 {
00170 return CLIENT_WEB_DIR . "/assessment/certificates/" . $this->object->getId() . "/background_upload";
00171 }
00172
00181 function getXSLPath()
00182 {
00183 return CLIENT_WEB_DIR . "/assessment/certificates/" . $this->object->getId() . "/" . $this->getXSLName();
00184 }
00185
00194 function getXSLName()
00195 {
00196 return "certificate.xml";
00197 }
00198
00207 function getBackgroundImagePathWeb()
00208 {
00209 include_once "./Services/Utilities/classes/class.ilUtil.php";
00210 $webdir = ilUtil::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/assessment/certificates/" . $this->object->getId() . "/" . $this->getBackgroundImageName();
00211 return str_replace(ilUtil::removeTrailingPathSeparators(ILIAS_ABSOLUTE_PATH), ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH), $webdir);
00212 }
00213
00222 function deleteBackgroundImage()
00223 {
00224 global $ilLog;
00225 $result = TRUE;
00226 if (file_exists($this->getBackgroundImageThumbPath()))
00227 {
00228 $ilLog->write("delete " . $this->getBackgroundImageThumbPath());
00229 $result = $result & unlink($this->getBackgroundImageThumbPath());
00230 }
00231 if (file_exists($this->getBackgroundImagePath()))
00232 {
00233 $ilLog->write("delete " . $this->getBackgroundImagePath());
00234 $result = $result & unlink($this->getBackgroundImagePath());
00235 }
00236 if (file_exists($this->getBackgroundImageTempfilePath()))
00237 {
00238 $ilLog->write("delete " . $this->getBackgroundImageTempfilePath());
00239 $result = $result & unlink($this->getBackgroundImageTempfilePath());
00240 }
00241 return $result;
00242 }
00243
00251 function deleteCertificate()
00252 {
00253 global $ilLog;
00254 if (file_exists($this->getCertificatePath()))
00255 {
00256 include_once "./Services/Utilities/classes/class.ilUtil.php";
00257 ilUtil::delDir($this->getCertificatePath());
00258 }
00259 }
00260
00270 function checkCertificateInput($form_fields)
00271 {
00272
00273 if ((strlen($form_fields["padding_top"]) == 0) ||
00274 (strlen($form_fields["margin_body_top"]) == 0) ||
00275 (strlen($form_fields["margin_body_right"]) == 0) ||
00276 (strlen($form_fields["margin_body_bottom"]) == 0) ||
00277 (strlen($form_fields["margin_body_left"]) == 0) ||
00278 (strlen($form_fields["certificate_text"]) == 0))
00279 {
00280 return $this->lng->txt("fill_out_all_required_fields");
00281 }
00282
00283 $unitexpression = "^([\d\.]+)(pt|pc|px|em|mm|cm|in){0,1}\$";
00284 if (!preg_match("/$unitexpression/", $form_fields["padding_top"], $matches))
00285 {
00286 return $this->lng->txt("certificate_wrong_unit");
00287 }
00288 if (strcmp($form_fields["pageformat"], "custom") == 0)
00289 {
00290 if (!preg_match("/$unitexpression/", $form_fields["pageheight"], $matches))
00291 {
00292 return $this->lng->txt("certificate_wrong_unit");
00293 }
00294 if (!preg_match("/$unitexpression/", $form_fields["pagewidth"], $matches))
00295 {
00296 return $this->lng->txt("certificate_wrong_unit");
00297 }
00298 }
00299 if (!preg_match("/$unitexpression/", $form_fields["margin_body_top"], $matches))
00300 {
00301 return $this->lng->txt("certificate_wrong_unit");
00302 }
00303 if (!preg_match("/$unitexpression/", $form_fields["margin_body_right"], $matches))
00304 {
00305 return $this->lng->txt("certificate_wrong_unit");
00306 }
00307 if (!preg_match("/$unitexpression/", $form_fields["margin_body_bottom"], $matches))
00308 {
00309 return $this->lng->txt("certificate_wrong_unit");
00310 }
00311 if (!preg_match("/$unitexpression/", $form_fields["margin_body_left"], $matches))
00312 {
00313 return $this->lng->txt("certificate_wrong_unit");
00314 }
00315 if (strlen($form_fields["certificate_text"]) == 0)
00316 {
00317 return $this->lng->txt("certificate_missing_text");
00318 }
00319 if (strlen($form_fields["certificate_text"]) > 0)
00320 {
00321 include_once "class.ilXMLChecker.php";
00322 $check = new ilXMLChecker();
00323 $check->setXMLContent(str_replace(" ", " ", "<html>" . $form_fields["certificate_text"] . "</html>"));
00324 $check->startParsing();
00325 if ($check->hasError())
00326 {
00327 return $this->lng->txt("certificate_not_well_formed");
00328 }
00329 }
00330 return TRUE;
00331 }
00332
00340 function processFO2XHTML()
00341 {
00342 if (file_exists($this->getXSLPath()))
00343 {
00344 $xslfo = file_get_contents($this->getXSLPath());
00345 }
00346
00347 $pagewidth = "21cm";
00348 if (preg_match("/page-width\=\"([^\"]+)\"/", $xslfo, $matches))
00349 {
00350 $pagewidth = $matches[1];
00351 }
00352 $pageheight = "29.7cm";
00353 if (preg_match("/page-height\=\"([^\"]+)\"/", $xslfo, $matches))
00354 {
00355 $pageheight = $matches[1];
00356 }
00357 $pagesize = "custom";
00358 if (((strcmp($pageheight, "29.7cm") == 0) || (strcmp($pageheight, "297mm") == 0)) && ((strcmp($pagewidth, "21cm") == 0) || (strcmp($pagewidth, "210mm") == 0)))
00359 {
00360 $pagesize = "a4";
00361 }
00362 else if (((strcmp($pagewidth, "29.7cm") == 0) || (strcmp($pagewidth, "297mm") == 0)) && ((strcmp($pageheight, "21cm") == 0) || (strcmp($pageheight, "210mm") == 0)))
00363 {
00364 $pagesize = "a4landscape";
00365 }
00366 else if (((strcmp($pageheight, "21cm") == 0) || (strcmp($pageheight, "210mm") == 0)) && ((strcmp($pagewidth, "14.8cm") == 0) || (strcmp($pagewidth, "148mm") == 0)))
00367 {
00368 $pagesize = "a5";
00369 }
00370 else if (((strcmp($pagewidth, "21cm") == 0) || (strcmp($pagewidth, "210mm") == 0)) && ((strcmp($pageheight, "14.8cm") == 0) || (strcmp($pageheight, "148mm") == 0)))
00371 {
00372 $pagesize = "a5landscape";
00373 }
00374 else if (((strcmp($pageheight, "11in") == 0)) && ((strcmp($pagewidth, "8.5in") == 0)))
00375 {
00376 $pagesize = "letter";
00377 }
00378 else if (((strcmp($pagewidth, "11in") == 0)) && ((strcmp($pageheight, "8.5in") == 0)))
00379 {
00380 $pagesize = "letterlandscape";
00381 }
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391 $paddingtop = "0cm";
00392 if (preg_match("/padding-top\=\"([^\"]+)\"/", $xslfo, $matches))
00393 {
00394 $paddingtop = $matches[1];
00395 }
00396 $marginbody_top = "0cm";
00397 $marginbody_right = "2cm";
00398 $marginbody_bottom = "0cm";
00399 $marginbody_left = "2cm";
00400 if (preg_match("/fo:flow[^>]*margin\=\"([^\"]+)\"/", $xslfo, $matches))
00401 {
00402 $marginbody = $matches[1];
00403 if (preg_match_all("/([^\s]+)/", $marginbody, $matches))
00404 {
00405 $marginbody_top = $matches[1][0];
00406 $marginbody_right = $matches[1][1];
00407 $marginbody_bottom = $matches[1][2];
00408 $marginbody_left = $matches[1][3];
00409 }
00410 }
00411
00412 $xsl = file_get_contents("./Modules/Test/xml/fo2xhtml.xsl");
00413 if ((strlen($xslfo)) && (strlen($xsl)))
00414 {
00415 $args = array( '/_xml' => $xslfo, '/_xsl' => $xsl );
00416 $xh = xslt_create();
00417 $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", NULL, $args, NULL);
00418 xslt_error($xh);
00419 xslt_free($xh);
00420 }
00421
00422 $output = preg_replace("/<\?xml[^>]+?>/", "", $output);
00423
00424
00425 $output = str_replace(" ", "<br />", $output);
00426 $output = str_replace(" ", "<br />", $output);
00427 return array(
00428 "pageformat" => $pagesize,
00429 "pagewidth" => $pagewidth,
00430 "pageheight" => $pageheight,
00431 "padding_top" => $paddingtop,
00432 "margin_body_top" => $marginbody_top,
00433 "margin_body_right" => $marginbody_right,
00434 "margin_body_bottom" => $marginbody_bottom,
00435 "margin_body_left" => $marginbody_left,
00436 "certificate_text" => $output,
00437 "certificate_visibility" => $this->object->getCertificateVisibility()
00438 );
00439 }
00440
00450 function processXHTML2FO($form_data, $for_export = FALSE)
00451 {
00452 $content = "<html><body>".$form_data["certificate_text"]."</body></html>";
00453 $content = str_replace("<p> </p>", "<p><br /></p>", $content);
00454 $content = str_replace(" ", " ", $content);
00455 $xsl = file_get_contents("./Modules/Test/xml/xhtml2fo.xsl");
00456 $args = array( '/_xml' => $content, '/_xsl' => $xsl );
00457 $xh = xslt_create();
00458 if (strcmp($form_data["pageformat"], "custom") == 0)
00459 {
00460 $pageheight = $form_data["pageheight"];
00461 $pagewidth = $form_data["pagewidth"];
00462 }
00463 else
00464 {
00465 $pageformats = $this->getPageFormats();
00466 $pageheight = $pageformats[$form_data["pageformat"]]["height"];
00467 $pagewidth = $pageformats[$form_data["pageformat"]]["width"];
00468 }
00469 $backgroundimage = $this->hasBackgroundImage() ? $this->getBackgroundImagePath() : "";
00470 $params = array(
00471 "pageheight" => $pageheight,
00472 "pagewidth" => $pagewidth,
00473 "backgroundimage" => $backgroundimage,
00474 "marginbody" => $form_data["margin_body_top"] . " " . $form_data["margin_body_right"] . " " . $form_data["margin_body_bottom"] . " " . $form_data["margin_body_left"],
00475 "paddingtop" => $form_data["padding_top"]
00476 );
00477 $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", NULL, $args, $params);
00478 xslt_error($xh);
00479 xslt_free($xh);
00480 return $output;
00481 }
00482
00491 function saveCertificateVisibility($a_value)
00492 {
00493 $this->object->saveCertificateVisibility($a_value);
00494 }
00495
00506 function exchangeCertificateVariables($certificate_text, $user_data = array())
00507 {
00508 if (count($user_data) == 0)
00509 {
00510 include_once "./classes/class.ilFormat.php";
00511 $user_data = array(
00512 "[USER_FULLNAME]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_fullname")),
00513 "[USER_FIRSTNAME]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_firstname")),
00514 "[USER_LASTNAME]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_lastname")),
00515 "[USER_TITLE]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_title")),
00516 "[USER_INSTITUTION]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_institution")),
00517 "[USER_DEPARTMENT]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_department")),
00518 "[USER_STREET]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_street")),
00519 "[USER_CITY]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_city")),
00520 "[USER_ZIPCODE]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_zipcode")),
00521 "[USER_COUNTRY]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_country")),
00522 "[RESULT_PASSED]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_result_passed")),
00523 "[RESULT_POINTS]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_result_points")),
00524 "[RESULT_PERCENT]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_result_percent")),
00525 "[MAX_POINTS]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_max_points")),
00526 "[RESULT_MARK_SHORT]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_result_mark_short")),
00527 "[RESULT_MARK_LONG]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_result_mark_long")),
00528 "[TEST_TITLE]" => ilUtil::prepareFormOutput($this->object->getTitle()),
00529 "[DATE]" => ilFormat::formatDate(ilFormat::unixtimestamp2datetime(time()), "date"),
00530 "[DATETIME]" => ilFormat::formatDate(ilFormat::unixtimestamp2datetime(time()), "datetime", TRUE)
00531 );
00532 }
00533 foreach ($user_data as $var => $value)
00534 {
00535 $certificate_text = str_replace($var, $value, $certificate_text);
00536 }
00537 return $certificate_text;
00538 }
00539
00540 function createArchiveDirectory()
00541 {
00542 $dir = $this->getCertificatePath() . time() . "__" . IL_INST_ID . "__" . "test" . "__" . $this->object->getId() . "__certificate/";
00543 include_once "./Services/Utilities/classes/class.ilUtil.php";
00544 ilUtil::makeDirParents($dir);
00545 return $dir;
00546 }
00547
00548 function addPDFtoArchiveDirectory($pdfdata, $dir, $filename)
00549 {
00550 $fh = fopen($dir . $filename, "wb");
00551 fwrite($fh, $pdfdata);
00552 fclose($fh);
00553 }
00554
00562 function outCertificates($userfilter = "", $passedonly = FALSE)
00563 {
00564 global $ilUser;
00565
00566 include_once "./Services/Utilities/classes/class.ilUtil.php";
00567 $archive_dir = $this->createArchiveDirectory();
00568 $total_users = array();
00569 $total_users =& $this->object->evalTotalPersonsArray();
00570 if (count($total_users))
00571 {
00572 foreach ($total_users as $active_id => $name)
00573 {
00574 $user_id = $this->object->_getUserIdFromActiveId($active_id);
00575 $pdf = $this->outCertificate($active_id, "", FALSE, $userfilter, $passedonly);
00576 if (strlen($pdf))
00577 {
00578 $this->addPDFtoArchiveDirectory($pdf, $archive_dir, $user_id . "_" . str_replace(" ", "_", ilUtil::getASCIIFilename($name)) . ".pdf");
00579 }
00580 }
00581 $zipfile = time() . "__" . IL_INST_ID . "__" . "test" . "__" . $this->object->getId() . "__certificates.zip";
00582 ilUtil::zip($archive_dir, $this->getCertificatePath() . $zipfile);
00583 ilUtil::delDir($archive_dir);
00584 ilUtil::deliverFile($this->getCertificatePath() . $zipfile, $zipfile, "application/zip");
00585 }
00586 }
00587
00595 function outCertificate($active_id, $pass, $deliver = TRUE, $userfilter = "", $passedonly = FALSE)
00596 {
00597 if (strlen($pass))
00598 {
00599 $result_array =& $this->object->getTestResult($active_id, $pass);
00600 }
00601 else
00602 {
00603 $result_array =& $this->object->getTestResult($active_id);
00604 }
00605 if (($passedonly) && ($result_array["test"]["passed"] == FALSE)) return "";
00606 $passed = $result_array["test"]["passed"] ? $this->lng->txt("certificate_passed") : $this->lng->txt("certificate_failed");
00607 if (!$result_array["test"]["total_max_points"])
00608 {
00609 $percentage = 0;
00610 }
00611 else
00612 {
00613 $percentage = ($result_array["test"]["total_reached_points"]/$result_array["test"]["total_max_points"])*100;
00614 }
00615 $mark_obj = $this->object->mark_schema->getMatchingMark($percentage);
00616 $user_id = $this->object->_getUserIdFromActiveId($active_id);
00617 include_once './Services/User/classes/class.ilObjUser.php';
00618 $user_data = ilObjUser::_lookupFields($user_id);
00619 if (strlen($userfilter))
00620 {
00621 if (!@preg_match("/$userfilter/i", $user_data["lastname"] . ", " . $user_data["firstname"] . " " . $user_data["title"]))
00622 {
00623 return "";
00624 }
00625 }
00626 include_once "./classes/class.ilFormat.php";
00627 $user_data = array(
00628 "[USER_FULLNAME]" => ilUtil::prepareFormOutput(trim($user_data["title"] . " " . $user_data["firstname"] . " " . $user_data["lastname"])),
00629 "[USER_FIRSTNAME]" => ilUtil::prepareFormOutput($user_data["firstname"]),
00630 "[USER_LASTNAME]" => ilUtil::prepareFormOutput($user_data["lastname"]),
00631 "[USER_TITLE]" => ilUtil::prepareFormOutput($user_data["title"]),
00632 "[USER_INSTITUTION]" => ilUtil::prepareFormOutput($user_data["institution"]),
00633 "[USER_DEPARTMENT]" => ilUtil::prepareFormOutput($user_data["department"]),
00634 "[USER_STREET]" => ilUtil::prepareFormOutput($user_data["street"]),
00635 "[USER_CITY]" => ilUtil::prepareFormOutput($user_data["city"]),
00636 "[USER_ZIPCODE]" => ilUtil::prepareFormOutput($user_data["zipcode"]),
00637 "[USER_COUNTRY]" => ilUtil::prepareFormOutput($user_data["country"]),
00638 "[RESULT_PASSED]" => ilUtil::prepareFormOutput($passed),
00639 "[RESULT_POINTS]" => ilUtil::prepareFormOutput($result_array["test"]["total_reached_points"]),
00640 "[RESULT_PERCENT]" => sprintf("%2.2f", $percentage) . "%",
00641 "[MAX_POINTS]" => ilUtil::prepareFormOutput($result_array["test"]["total_max_points"]),
00642 "[RESULT_MARK_SHORT]" => ilUtil::prepareFormOutput($mark_obj->getShortName()),
00643 "[RESULT_MARK_LONG]" => ilUtil::prepareFormOutput($mark_obj->getOfficialName()),
00644 "[TEST_TITLE]" => ilUtil::prepareFormOutput($this->object->getTitle()),
00645 "[DATE]" => ilFormat::formatDate(ilFormat::unixtimestamp2datetime(time()), "date"),
00646 "[DATETIME]" => ilFormat::formatDate(ilFormat::unixtimestamp2datetime(time()), "datetime", TRUE)
00647 );
00648 $xslfo = file_get_contents($this->getXSLPath());
00649 include_once "./Services/Transformation/classes/class.ilFO2PDF.php";
00650 $fo2pdf = new ilFO2PDF();
00651 $fo2pdf->setFOString($this->exchangeCertificateVariables($xslfo, $user_data));
00652 $result = $fo2pdf->send();
00653 if ($deliver)
00654 {
00655 include_once "./Services/Utilities/classes/class.ilUtil.php";
00656 ilUtil::deliverData($result, "certificate.pdf", "application/pdf");
00657 }
00658 else
00659 {
00660 return $result;
00661 }
00662 }
00663
00671 function createPreview()
00672 {
00673 $xslfo = file_get_contents($this->getXSLPath());
00674 include_once "./Services/Transformation/classes/class.ilFO2PDF.php";
00675 $fo2pdf = new ilFO2PDF();
00676 $fo2pdf->setFOString($this->exchangeCertificateVariables($xslfo));
00677 $result = $fo2pdf->send();
00678 include_once "./Services/Utilities/classes/class.ilUtil.php";
00679 ilUtil::deliverData($result, "certificate.pdf", "application/pdf");
00680 }
00681
00690 function saveCertificate($xslfo, $filename = "")
00691 {
00692 if (!file_exists($this->getCertificatePath()))
00693 {
00694 ilUtil::makeDirParents($this->getCertificatePath());
00695 }
00696 if (strlen($filename) == 0)
00697 {
00698 $filename = $this->getXSLPath();
00699 }
00700 $fh = fopen($filename, "w");
00701 fwrite($fh, $xslfo);
00702 fclose($fh);
00703 }
00704
00715 function uploadBackgroundImage($image_tempfilename)
00716 {
00717 if (!empty($image_tempfilename))
00718 {
00719 $image_filename = "background_upload";
00720 $convert_filename = $this->getBackgroundImageName();
00721 $imagepath = $this->getCertificatePath();
00722 if (!file_exists($imagepath))
00723 {
00724 ilUtil::makeDirParents($imagepath);
00725 }
00726
00727 if (!ilUtil::moveUploadedFile($image_tempfilename, $image_filename, $this->getBackgroundImageTempfilePath()))
00728 {
00729 return FALSE;
00730 }
00731
00732 ilUtil::convertImage($this->getBackgroundImageTempfilePath(), $this->getBackgroundImagePath(), "JPEG");
00733 ilUtil::convertImage($this->getBackgroundImageTempfilePath(), $this->getBackgroundImageThumbPath(), "JPEG", 100);
00734 if (!file_exists($this->getBackgroundImagePath()))
00735 {
00736
00737 if (!ilUtil::moveUploadedFile($this->getBackgroundImageTempfilePath(), $convert_filename, $this->getBackgroundImagePath()))
00738 {
00739 return FALSE;
00740 }
00741 }
00742 unlink($this->getBackgroundImageTempfilePath());
00743 if (file_exists($this->getBackgroundImagePath()) && (filesize($this->getBackgroundImagePath()) > 0))
00744 {
00745 return TRUE;
00746 }
00747 }
00748 return FALSE;
00749 }
00750
00759 function hasBackgroundImage()
00760 {
00761 if (file_exists($this->getBackgroundImagePath()) && (filesize($this->getBackgroundImagePath()) > 0))
00762 {
00763 return TRUE;
00764 }
00765 else
00766 {
00767 return FALSE;
00768 }
00769 }
00770
00779 function isComplete()
00780 {
00781 if (file_exists($this->getCertificatePath()))
00782 {
00783 if (file_exists($this->getXSLPath()) && (filesize($this->getXSLPath()) > 0))
00784 {
00785 return TRUE;
00786 }
00787 }
00788 return FALSE;
00789 }
00790
00799 function _isComplete($obj_id)
00800 {
00801 $certificatepath = CLIENT_WEB_DIR . "/assessment/certificates/" . $obj_id . "/";
00802 if (file_exists($certificatepath))
00803 {
00804 $xslpath = CLIENT_WEB_DIR . "/assessment/certificates/" . $obj_id . "/" . ilTestCertificate::getXSLName();
00805 if (file_exists($xslpath) && (filesize($xslpath) > 0))
00806 {
00807 return TRUE;
00808 }
00809 }
00810 return FALSE;
00811 }
00812
00821 function getPageFormats()
00822 {
00823 return array(
00824 "a4" => array(
00825 "name" => $this->lng->txt("certificate_a4"),
00826 "value" => "a4",
00827 "width" => "210mm",
00828 "height" => "297mm"
00829 ),
00830 "a4landscape" => array(
00831 "name" => $this->lng->txt("certificate_a4_landscape"),
00832 "value" => "a4landscape",
00833 "width" => "297mm",
00834 "height" => "210mm"
00835 ),
00836 "a5" => array(
00837 "name" => $this->lng->txt("certificate_a5"),
00838 "value" => "a5",
00839 "width" => "148mm",
00840 "height" => "210mm"
00841 ),
00842 "a5landscape" => array(
00843 "name" => $this->lng->txt("certificate_a5_landscape"),
00844 "value" => "a5landscape",
00845 "width" => "210mm",
00846 "height" => "148mm"
00847 ),
00848 "letter" => array(
00849 "name" => $this->lng->txt("certificate_letter"),
00850 "value" => "letter",
00851 "width" => "8.5in",
00852 "height" => "11in"
00853 ),
00854 "letterlandscape" => array(
00855 "name" => $this->lng->txt("certificate_letter_landscape"),
00856 "value" => "letterlandscape",
00857 "width" => "8.5in",
00858 "height" => "11in"
00859 ),
00860 "custom" => array(
00861 "name" => $this->lng->txt("certificate_custom"),
00862 "value" => "custom",
00863 "width" => "",
00864 "height" => ""
00865 )
00866 );
00867 }
00868
00876 function deliverExportFileXML()
00877 {
00878 include_once "./Services/Utilities/classes/class.ilUtil.php";
00879 $exportpath = $this->createArchiveDirectory();
00880 ilUtil::makeDir($exportpath);
00881 $xsl = file_get_contents($this->getXSLPath());
00882 $xslexport = str_replace($this->getCertificatePath(), "", $xsl);
00883
00884 $this->saveCertificate($xslexport, $exportpath . $this->getXSLName());
00885
00886 if ($this->hasBackgroundImage())
00887 {
00888 copy($this->getBackgroundImagePath(), $exportpath . $this->getBackgroundImageName());
00889 }
00890 $zipfile = time() . "__" . IL_INST_ID . "__" . "test" . "__" . $this->object->getId() . "__certificate.zip";
00891 ilUtil::zip($exportpath, $this->getCertificatePath() . $zipfile);
00892 ilUtil::delDir($exportpath);
00893 ilUtil::deliverFile($this->getCertificatePath() . $zipfile, $zipfile, "application/zip");
00894 }
00895
00904 function importCertificate($zipfile, $filename)
00905 {
00906 include_once "./Services/Utilities/classes/class.ilUtil.php";
00907 $importpath = $this->createArchiveDirectory();
00908 if (!ilUtil::moveUploadedFile($zipfile, $filename, $importpath . $filename))
00909 {
00910 ilUtil::delDir($importpath);
00911 return FALSE;
00912 }
00913 ilUtil::unzip($importpath . $filename, TRUE);
00914 $subdir = str_replace(".zip", "", strtolower($filename)) . "/";
00915 $copydir = "";
00916 if (is_dir($importpath . $subdir))
00917 {
00918 $dirinfo = ilUtil::getDir($importpath . $subdir);
00919 $copydir = $importpath . $subdir;
00920 }
00921 else
00922 {
00923 $dirinfo = ilUtil::getDir($importpath);
00924 $copydir = $importpath;
00925 }
00926 $xmlfiles = 0;
00927 $otherfiles = 0;
00928 foreach ($dirinfo as $file)
00929 {
00930 if (strcmp($file["type"], "file") == 0)
00931 {
00932 if (strpos($file["entry"], ".xml") !== FALSE)
00933 {
00934 $xmlfiles++;
00935 }
00936 else if (strpos($file["entry"], ".zip") !== FALSE)
00937 {
00938 }
00939 else
00940 {
00941 $otherfiles++;
00942 }
00943 }
00944 }
00945
00946 if ($xmlfiles == 1)
00947 {
00948 foreach ($dirinfo as $file)
00949 {
00950 if (strcmp($file["type"], "file") == 0)
00951 {
00952 if (strpos($file["entry"], ".xml") !== FALSE)
00953 {
00954 $xsl = file_get_contents($copydir . $file["entry"]);
00955
00956
00957 $xsl = preg_replace("/url\([']{0,1}(.*?)[']{0,1}\)/", "url(" . $this->getCertificatePath() . "\${1})", $xsl);
00958 $this->saveCertificate($xsl);
00959 }
00960 else if (strpos($file["entry"], ".zip") !== FALSE)
00961 {
00962 }
00963 else
00964 {
00965 @copy($copydir . $file["entry"], $this->getCertificatePath() . $file["entry"]);
00966 if (strcmp($this->getBackgroundImagePath(), $this->getCertificatePath() . $file["entry"]) == 0)
00967 {
00968
00969 ilUtil::convertImage($this->getBackgroundImagePath(), $this->getBackgroundImageThumbPath(), "JPEG", 100);
00970 }
00971 }
00972 }
00973 }
00974 }
00975 else
00976 {
00977 ilUtil::delDir($importpath);
00978 return FALSE;
00979 }
00980 ilUtil::delDir($importpath);
00981 return TRUE;
00982 }
00983 }
00984
00985 ?>