ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilCertificate.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5
16{
22 protected $ctrl;
23
29 protected $tree;
30
36 protected $ilias;
37
43 protected $lng;
44
50 protected $adapter;
51
55 protected $settings;
56
60 protected $log;
61
65 protected $db;
66
70 protected static $is_active;
71
77 {
78 global $DIC;
79
80 $this->lng = $DIC['lng'];
81 $this->ctrl = $DIC['ilCtrl'];
82 $this->ilias = $DIC['ilias'];
83 $this->tree = $DIC['tree'];
84 $this->settings = $DIC['ilSetting'];
85 $this->log = $DIC['ilLog'];
86 $this->db = $DIC['ilDB'];
87
88 $this->adapter = $adapter;
89 }
90
95 public function formatNumberString($a_number)
96 {
97 return str_replace(',', '.', $a_number);
98 }
99
105 public function getBackgroundImagePath($asRelative = false)
106 {
107 if ($asRelative) {
108 return str_replace(
109 array(CLIENT_WEB_DIR, '//'),
110 array('[CLIENT_WEB_DIR]', '/'),
111 $this->getAdapter()->getCertificatePath() . $this->getBackgroundImageName()
112 );
113 }
114
115 return $this->getAdapter()->getCertificatePath() . $this->getBackgroundImageName();
116 }
117
123 public function getBackgroundImageName()
124 {
125 return "background.jpg";
126 }
127
134 {
135 return $this->getAdapter()->getCertificatePath() . $this->getBackgroundImageName() . ".thumb.jpg";
136 }
137
144 {
145 return $this->getAdapter()->getCertificatePath() . "background_upload.tmp";
146 }
147
153 public function getXSLPath()
154 {
155 return $this->getAdapter()->getCertificatePath() . $this->getXSLName();
156 }
157
163 public function getXSLName()
164 {
165 return "certificate.xml";
166 }
167
173 public static function _getXSLName()
174 {
175 return "certificate.xml";
176 }
177
184 {
185 // TODO: this is generic now -> provide better solution
186 include_once "./Services/Utilities/classes/class.ilUtil.php";
187 $webdir = $this->getAdapter()->getCertificatePath() . $this->getBackgroundImageName();
188 return str_replace(ilUtil::removeTrailingPathSeparators(ILIAS_ABSOLUTE_PATH), ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH), $webdir);
189 }
190
197 {
198 // TODO: this is generic now -> provide better solution
199 include_once "./Services/Utilities/classes/class.ilUtil.php";
200 return str_replace(ilUtil::removeTrailingPathSeparators(ILIAS_ABSOLUTE_PATH), ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH), $this->getBackgroundImageThumbPath());
201 }
202
208 public function deleteBackgroundImage()
209 {
210 $result = true;
211 if (file_exists($this->getBackgroundImageThumbPath())) {
212 $result = $result & unlink($this->getBackgroundImageThumbPath());
213 }
214 if (file_exists($this->getBackgroundImagePath())) {
215 $result = $result & unlink($this->getBackgroundImagePath());
216 }
217 if (file_exists($this->getBackgroundImageTempfilePath())) {
219 }
220 return $result;
221 }
222
228 public function cloneCertificate($newObject)
229 {
230 $xsl = $this->getXSLPath();
231 $bgimage = $this->getBackgroundImagePath();
232 $bgimagethumb = $this->getBackgroundImageThumbPath();
233 $certificatepath = $this->getAdapter()->getCertificatePath();
234
235 $new_xsl = $newObject->getXSLPath();
236 $new_bgimage = $newObject->getBackgroundImagePath();
237 $new_bgimagethumb = $newObject->getBackgroundImageThumbPath();
238 $new_certificatepath = $newObject->getAdapter()->getCertificatePath();
239
240 if (@file_exists($xsl)) {
241 ilUtil::makeDirParents($new_certificatepath);
242 @copy($xsl, $new_xsl);
243 if (@file_exists($bgimage)) {
244 @copy($bgimage, $new_bgimage);
245 }
246 if (@file_exists($bgimagethumb)) {
247 @copy($bgimagethumb, $new_bgimagethumb);
248 }
249 }
250
251 // #10271
252 if ($this->readActive()) {
253 $newObject->writeActive(true);
254 }
255 }
256
262 public function deleteCertificate()
263 {
264 if (@file_exists($this->getAdapter()->getCertificatePath())) {
265 include_once "./Services/Utilities/classes/class.ilUtil.php";
266 ilUtil::delDir($this->getAdapter()->getCertificatePath());
267 $this->getAdapter()->deleteCertificate();
268 }
269 $this->writeActive(false);
270 }
271
275 public function getFormFieldsFromFO()
276 {
277 if (@file_exists($this->getXSLPath())) {
278 $xslfo = file_get_contents($this->getXSLPath());
279 }
280 // retrieve form information (using a dirty way with regular expressions)
281 $pagewidth = "21cm";
282 if (preg_match("/page-width\=\"([^\"]+)\"/", $xslfo, $matches)) {
283 $pagewidth = $matches[1];
284 }
285 $pageheight = "29.7cm";
286 if (preg_match("/page-height\=\"([^\"]+)\"/", $xslfo, $matches)) {
287 $pageheight = $matches[1];
288 }
289 $certificatesettings = new ilSetting("certificate");
290 $pagesize = $certificatesettings->get("pageformat");
291 ;
292 if (((strcmp($pageheight, "29.7cm") == 0) || (strcmp($pageheight, "297mm") == 0)) && ((strcmp($pagewidth, "21cm") == 0) || (strcmp($pagewidth, "210mm") == 0))) {
293 $pagesize = "a4";
294 } elseif (((strcmp($pagewidth, "29.7cm") == 0) || (strcmp($pagewidth, "297mm") == 0)) && ((strcmp($pageheight, "21cm") == 0) || (strcmp($pageheight, "210mm") == 0))) {
295 $pagesize = "a4landscape";
296 } elseif (((strcmp($pageheight, "21cm") == 0) || (strcmp($pageheight, "210mm") == 0)) && ((strcmp($pagewidth, "14.8cm") == 0) || (strcmp($pagewidth, "148mm") == 0))) {
297 $pagesize = "a5";
298 } elseif (((strcmp($pagewidth, "21cm") == 0) || (strcmp($pagewidth, "210mm") == 0)) && ((strcmp($pageheight, "14.8cm") == 0) || (strcmp($pageheight, "148mm") == 0))) {
299 $pagesize = "a5landscape";
300 } elseif (((strcmp($pageheight, "11in") == 0)) && ((strcmp($pagewidth, "8.5in") == 0))) {
301 $pagesize = "letter";
302 } elseif (((strcmp($pagewidth, "11in") == 0)) && ((strcmp($pageheight, "8.5in") == 0))) {
303 $pagesize = "letterlandscape";
304 } else {
305 $pagesize = "custom";
306 }
307 if (!strlen($xslfo)) {
308 $pagesize = $certificatesettings->get("pageformat");
309 };
310
311 $marginbody_top = "0cm";
312 $marginbody_right = "2cm";
313 $marginbody_bottom = "0cm";
314 $marginbody_left = "2cm";
315 if (preg_match("/fo:flow[^>]*margin\=\"([^\"]+)\"/", $xslfo, $matches)) {
316 // Backwards compatibility
317 $marginbody = $matches[1];
318 if (preg_match_all("/([^\s]+)/", $marginbody, $matches)) {
319 $marginbody_top = $matches[1][0];
320 $marginbody_right = $matches[1][1];
321 $marginbody_bottom = $matches[1][2];
322 $marginbody_left = $matches[1][3];
323 }
324 } elseif (preg_match("/fo:region-body[^>]*margin\=\"([^\"]+)\"/", $xslfo, $matches)) {
325 $marginbody = $matches[1];
326 if (preg_match_all("/([^\s]+)/", $marginbody, $matches)) {
327 $marginbody_top = $matches[1][0];
328 $marginbody_right = $matches[1][1];
329 $marginbody_bottom = $matches[1][2];
330 $marginbody_left = $matches[1][3];
331 }
332 }
333
334 $xsl = file_get_contents("./Services/Certificate/xml/fo2xhtml.xsl");
335 if ((strlen($xslfo)) && (strlen($xsl))) {
336 $args = array( '/_xml' => $xslfo, '/_xsl' => $xsl );
337 $xh = xslt_create();
338 $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", null, $args, null);
339 xslt_error($xh);
340 xslt_free($xh);
341 }
342
343 $output = preg_replace("/<\?xml[^>]+?>/", "", $output);
344 // dirty hack: the php xslt processing seems not to recognize the following
345 // replacements, so we do it in the code as well
346 $output = str_replace("&#xA0;", "<br />", $output);
347 $output = str_replace("&#160;", "<br />", $output);
348 $form_fields = array(
349 "pageformat" => $pagesize,
350 "pagewidth" => $pagewidth,
351 "pageheight" => $pageheight,
352 "margin_body_top" => $marginbody_top,
353 "margin_body_right" => $marginbody_right,
354 "margin_body_bottom" => $marginbody_bottom,
355 "margin_body_left" => $marginbody_left,
356 "certificate_text" => $output
357 );
358 $this->getAdapter()->addFormFieldsFromObject($form_fields);
359 return $form_fields;
360 }
361
368 public function processXHTML2FO($form_data, $for_export = false)
369 {
370 $content = "<html><body>" . $form_data["certificate_text"] . "</body></html>";
371 $content = preg_replace("/<p>(&nbsp;){1,}<\\/p>/", "<p></p>", $content);
372 $content = preg_replace("/<p>(\\s)*?<\\/p>/", "<p></p>", $content);
373 // $content = str_replace("<p>&nbsp;</p>", "<p><br /></p>", $content);
374 // $content = str_replace("<p> </p>", "<p><br /></p>", $content);
375 $content = str_replace("<p></p>", "<p class=\"emptyrow\"></p>", $content);
376 $content = str_replace("&nbsp;", "&#160;", $content);
377 $content = preg_replace("//", "", $content);
378
379 include_once "./Services/Certificate/classes/class.ilXmlChecker.php";
380 $check = new ilXMLChecker();
381 $check->setXMLContent($content);
382 $check->startParsing();
383 if ($check->hasError()) {
384 throw new Exception($this->lng->txt("certificate_not_well_formed"));
385 }
386
387 $xsl = file_get_contents("./Services/Certificate/xml/xhtml2fo.xsl");
388
389 // additional font support
390 $xsl = str_replace(
391 'font-family="Helvetica, unifont"',
392 'font-family="' . $this->settings->get('rpc_pdf_font', 'Helvetica, unifont') . '"',
393 $xsl
394 );
395
396 $args = array( '/_xml' => $content, '/_xsl' => $xsl );
397 $xh = xslt_create();
398 if (strcmp($form_data["pageformat"], "custom") == 0) {
399 $pageheight = $form_data["pageheight"];
400 $pagewidth = $form_data["pagewidth"];
401 } else {
402 $pageformats = $this->getPageFormats();
403 $pageheight = $pageformats[$form_data["pageformat"]]["height"];
404 $pagewidth = $pageformats[$form_data["pageformat"]]["width"];
405 }
406 include_once "./Services/Certificate/classes/class.ilObjCertificateSettingsAccess.php";
408 $params = array(
409 "pageheight" => $pageheight,
410 "pagewidth" => $pagewidth,
411 "backgroundimage" => $backgroundimage,
412 "marginbody" => implode(' ', array(
413 $form_data["margin_body_top"],
414 $form_data["margin_body_right"],
415 $form_data["margin_body_bottom"],
416 $form_data["margin_body_left"]
417 ))
418 );
419 $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", null, $args, $params);
420 xslt_error($xh);
421 xslt_free($xh);
422 return $output;
423 }
424
432 private function exchangeCertificateVariables($certificate_text, $insert_tags = array())
433 {
434 if (count($insert_tags) == 0) {
435 $insert_tags = $this->getAdapter()->getCertificateVariablesForPreview();
436 foreach (self::getCustomCertificateFields() as $k => $f) {
437 $insert_tags[$f["ph"]] = ilUtil::prepareFormOutput($f["name"]);
438 }
439 }
440 foreach ($insert_tags as $var => $value) {
441 $certificate_text = str_replace($var, $value, $certificate_text);
442 }
443
444 $certificate_text = str_replace('[CLIENT_WEB_DIR]', CLIENT_WEB_DIR, $certificate_text);
445
446 return $certificate_text;
447 }
448
455 public function outCertificate($params, $deliver = true)
456 {
458 $insert_tags = $this->getAdapter()->getCertificateVariablesForPresentation($params);
459
460 include_once("./Services/User/classes/class.ilUserDefinedData.php");
461 $cust_data = new ilUserDefinedData($this->getAdapter()->getUserIdForParams($params));
462 $cust_data = $cust_data->getAll();
463 foreach (self::getCustomCertificateFields() as $k => $f) {
464 $insert_tags[$f["ph"]] = ilUtil::prepareFormOutput($cust_data["f_" . $k]);
465 }
466
467 $xslfo = file_get_contents($this->getXSLPath());
468
469 // render tex as fo graphics
470 require_once('Services/MathJax/classes/class.ilMathJax.php');
471 $xslfo = ilMathJax::getInstance()
474 ->insertLatexImages($xslfo);
475
476 include_once './Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
477 try {
478 $pdf_base64 = ilRpcClientFactory::factory('RPCTransformationHandler')->ilFO2PDF(
479 $this->exchangeCertificateVariables($xslfo, $insert_tags)
480 );
481 if ($deliver) {
482 include_once "./Services/Utilities/classes/class.ilUtil.php";
483 ilUtil::deliverData($pdf_base64->scalar, $this->getAdapter()->getCertificateFilename($params), "application/pdf");
484 } else {
485 return $pdf_base64->scalar;
486 }
487 } catch (Exception $e) {
488 $this->log->write(__METHOD__ . ': ' . $e->getMessage());
489 return false;
490 }
491
493 }
494
498 public function createPreview()
499 {
501
502 $xslfo = file_get_contents($this->getXSLPath());
503
504 // render tex as fo graphics
505 require_once('Services/MathJax/classes/class.ilMathJax.php');
506 $xslfo = ilMathJax::getInstance()
509 ->insertLatexImages($xslfo);
510
511 include_once './Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
512 try {
513 $pdf_base64 = ilRpcClientFactory::factory('RPCTransformationHandler')->ilFO2PDF(
514 $this->exchangeCertificateVariables($xslfo)
515 );
516 ilUtil::deliverData($pdf_base64->scalar, $this->getAdapter()->getCertificateFilename(), "application/pdf");
517 } catch (Exception $e) {
518 $this->log->write(__METHOD__ . ': ' . $e->getMessage());
519 return false;
520 }
521
523 }
524
530 public function saveCertificate($xslfo, $filename = "")
531 {
532 if (!file_exists($this->getAdapter()->getCertificatePath())) {
533 ilUtil::makeDirParents($this->getAdapter()->getCertificatePath());
534 }
535 if (strlen($filename) == 0) {
536 $filename = $this->getXSLPath();
537 }
538 $fh = fopen($filename, "w");
539 fwrite($fh, $xslfo);
540 fclose($fh);
541 }
542
550 public function uploadBackgroundImage($image_tempfilename)
551 {
552 if (!empty($image_tempfilename)) {
553 $convert_filename = $this->getBackgroundImageName();
554 $imagepath = $this->getAdapter()->getCertificatePath();
555 if (!file_exists($imagepath)) {
556 ilUtil::makeDirParents($imagepath);
557 }
558 // upload the file
559 if (!ilUtil::moveUploadedFile(
560 $image_tempfilename,
561 basename($this->getBackgroundImageTempfilePath()),
563 )) {
564 return false;
565 }
566 // convert the uploaded file to JPEG
569 if (!file_exists($this->getBackgroundImagePath())) {
570 // something went wrong converting the file. use the original file and hope, that PDF can work with it
571 if (!ilUtil::moveUploadedFile($this->getBackgroundImageTempfilePath(), $convert_filename, $this->getBackgroundImagePath())) {
572 return false;
573 }
574 }
575 unlink($this->getBackgroundImageTempfilePath());
576 if (file_exists($this->getBackgroundImagePath()) && (filesize($this->getBackgroundImagePath()) > 0)) {
577 return true;
578 }
579 }
580 return false;
581 }
582
588 public function hasBackgroundImage()
589 {
590 if (file_exists($this->getBackgroundImagePath()) && (filesize($this->getBackgroundImagePath()) > 0)) {
591 return true;
592 } else {
593 return false;
594 }
595 }
596
602 public function isComplete()
603 {
604 if (self::isActive()) {
605 $obj_id = $this->getAdapter()->getCertificateID();
606 if ($obj_id && !self::isObjectActive($obj_id)) {
607 return false;
608 }
609 if (file_exists($this->getAdapter()->getCertificatePath())) {
610 if (file_exists($this->getXSLPath()) && (filesize($this->getXSLPath()) > 0)) {
611 return true;
612 }
613 }
614 }
615 return false;
616 }
617
624 public static function _isComplete($adapter)
625 {
626 if (is_object($adapter) && method_exists($adapter, "getCertificatePath")) {
627 if (self::isActive()) {
628 $obj_id = $adapter->getCertificateID();
629 if ($obj_id && !self::isObjectActive($obj_id)) {
630 return false;
631 }
632
633 $certificatepath = $adapter->getCertificatePath();
634 if (file_exists($certificatepath)) {
635 $xslpath = $adapter->getCertificatePath() . ilCertificate::_getXSLName();
636 if (file_exists($xslpath) && (filesize($xslpath) > 0)) {
637 return true;
638 }
639 }
640 }
641 }
642 return false;
643 }
644
650 public function getPageFormats()
651 {
652 return array(
653 "a4" => array(
654 "name" => $this->lng->txt("certificate_a4"), // (297 mm x 210 mm)
655 "value" => "a4",
656 "width" => "210mm",
657 "height" => "297mm"
658 ),
659 "a4landscape" => array(
660 "name" => $this->lng->txt("certificate_a4_landscape"), // (210 mm x 297 mm)",
661 "value" => "a4landscape",
662 "width" => "297mm",
663 "height" => "210mm"
664 ),
665 "a5" => array(
666 "name" => $this->lng->txt("certificate_a5"), // (210 mm x 148.5 mm)
667 "value" => "a5",
668 "width" => "148mm",
669 "height" => "210mm"
670 ),
671 "a5landscape" => array(
672 "name" => $this->lng->txt("certificate_a5_landscape"), // (148.5 mm x 210 mm)
673 "value" => "a5landscape",
674 "width" => "210mm",
675 "height" => "148mm"
676 ),
677 "letter" => array(
678 "name" => $this->lng->txt("certificate_letter"), // (11 inch x 8.5 inch)
679 "value" => "letter",
680 "width" => "8.5in",
681 "height" => "11in"
682 ),
683 "letterlandscape" => array(
684 "name" => $this->lng->txt("certificate_letter_landscape"), // (8.5 inch x 11 inch)
685 "value" => "letterlandscape",
686 "width" => "11in",
687 "height" => "8.5in"
688 ),
689 "custom" => array(
690 "name" => $this->lng->txt("certificate_custom"),
691 "value" => "custom",
692 "width" => "",
693 "height" => ""
694 )
695 );
696 }
697
701 public function deliverExportFileXML()
702 {
703 include_once "./Services/Utilities/classes/class.ilUtil.php";
704 $exportpath = $this->createArchiveDirectory();
705 ilUtil::makeDir($exportpath);
706 $xsl = file_get_contents($this->getXSLPath());
707 $xslexport = str_replace($this->getAdapter()->getCertificatePath(), "", $xsl);
708 // save export xsl file
709 $this->saveCertificate($xslexport, $exportpath . $this->getXSLName());
710 // save background image
711 if ($this->hasBackgroundImage()) {
712 copy($this->getBackgroundImagePath(), $exportpath . $this->getBackgroundImageName());
713 } else {
714 include_once "./Services/Certificate/classes/class.ilObjCertificateSettingsAccess.php";
717 }
718 }
719 $zipfile = time() . "__" . IL_INST_ID . "__" . $this->getAdapter()->getAdapterType() . "__" . $this->getAdapter()->getCertificateId() . "__certificate.zip";
720 ilUtil::zip($exportpath, $this->getAdapter()->getCertificatePath() . $zipfile);
721 ilUtil::delDir($exportpath);
722 ilUtil::deliverFile($this->getAdapter()->getCertificatePath() . $zipfile, $zipfile, "application/zip");
723 }
724
730 public function importCertificate($zipfile, $filename)
731 {
732 include_once "./Services/Utilities/classes/class.ilUtil.php";
733 $importpath = $this->createArchiveDirectory();
734 if (!ilUtil::moveUploadedFile($zipfile, $filename, $importpath . $filename)) {
735 ilUtil::delDir($importpath);
736 return false;
737 }
738 ilUtil::unzip($importpath . $filename, true);
739 $subdir = str_replace(".zip", "", strtolower($filename)) . "/";
740 $copydir = "";
741 if (is_dir($importpath . $subdir)) {
742 $dirinfo = ilUtil::getDir($importpath . $subdir);
743 $copydir = $importpath . $subdir;
744 } else {
745 $dirinfo = ilUtil::getDir($importpath);
746 $copydir = $importpath;
747 }
748 $xmlfiles = 0;
749 $otherfiles = 0;
750 foreach ($dirinfo as $file) {
751 if (strcmp($file["type"], "file") == 0) {
752 if (strpos($file["entry"], ".xml") !== false) {
753 $xmlfiles++;
754 } elseif (strpos($file["entry"], ".zip") !== false) {
755 } else {
756 $otherfiles++;
757 }
758 }
759 }
760 // if one XML file is in the archive, we try to import it
761 if ($xmlfiles == 1) {
762 foreach ($dirinfo as $file) {
763 if (strcmp($file["type"], "file") == 0) {
764 if (strpos($file["entry"], ".xml") !== false) {
765 $xsl = file_get_contents($copydir . $file["entry"]);
766 // as long as we cannot make RPC calls in a given directory, we have
767 // to add the complete path to every url
768 $xsl = preg_replace_callback("/url\‍([']{0,1}(.*?)[']{0,1}\‍)/", function (array $matches) {
769 $basePath = rtrim(dirname($this->getBackgroundImagePath(true)), '/');
770 $fileName = basename($matches[1]);
771
772 return 'url(' . $basePath . '/' . $fileName . ')';
773 }, $xsl);
774 $this->saveCertificate($xsl);
775 } elseif (strpos($file["entry"], ".zip") !== false) {
776 } else {
777 @copy($copydir . $file["entry"], $this->getAdapter()->getCertificatePath() . $file["entry"]);
778 if (strcmp($this->getBackgroundImagePath(), $this->getAdapter()->getCertificatePath() . $file["entry"]) == 0) {
779 // upload of the background image, create a preview
781 }
782 }
783 }
784 }
785 } else {
786 ilUtil::delDir($importpath);
787 return false;
788 }
789 ilUtil::delDir($importpath);
790 return true;
791 }
792
798 public function getAdapter()
799 {
800 return $this->adapter;
801 }
802
808 public function setAdapter($adapter)
809 {
810 $this->adapter =&$adapter;
811 }
812
813 /***************************************
814 /* BULK CERTIFICATE PROCESSING METHODS *
815 /***************************************
816
822 public function createArchiveDirectory()
823 {
824 $dir = $this->getAdapter()->getCertificatePath() . time() . "__" . IL_INST_ID . "__" . $this->getAdapter()->getAdapterType() . "__" . $this->getAdapter()->getCertificateId() . "__certificate/";
825 include_once "./Services/Utilities/classes/class.ilUtil.php";
826 ilUtil::makeDirParents($dir);
827 return $dir;
828 }
829
837 public function addPDFtoArchiveDirectory($pdfdata, $dir, $filename)
838 {
839 $fh = fopen($dir . $filename, "wb");
840 fwrite($fh, $pdfdata);
841 fclose($fh);
842 }
843
851 public function zipCertificatesInArchiveDirectory($dir, $deliver = true)
852 {
853 $zipfile = time() . "__" . IL_INST_ID . "__" . $this->getAdapter()->getAdapterType() . "__" . $this->getAdapter()->getCertificateId() . "__certificates.zip";
854 ilUtil::zip($dir, $this->getAdapter()->getCertificatePath() . $zipfile);
855 ilUtil::delDir($dir);
856 if ($deliver) {
857 ilUtil::deliverFile($this->getAdapter()->getCertificatePath() . $zipfile, $zipfile, "application/zip");
858 }
859 return $this->getAdapter()->getCertificatePath() . $zipfile;
860 }
861
862 public static function isActive()
863 {
864 if (self::$is_active === null) {
865 // basic admin setting active?
866 $certificate_active = new ilSetting("certificate");
867 $certificate_active = (bool) $certificate_active->get("active");
868
869 // java/rtpc-server active?
870 if ($certificate_active) {
871 include_once './Services/WebServices/RPC/classes/class.ilRPCServerSettings.php';
872 $certificate_active = ilRPCServerSettings::getInstance()->isEnabled();
873 }
874
875 self::$is_active = (bool) $certificate_active;
876 }
877 return self::$is_active;
878 }
879
884 public static function isObjectActive($a_obj_id)
885 {
886 $chk = self::areObjectsActive(array($a_obj_id));
887 return $chk[$a_obj_id];
888 }
889
894 public static function areObjectsActive(array $a_obj_ids)
895 {
899 global $DIC;
900
901 $ilDB = $DIC['ilDB'];
902
903 $all = array();
904 foreach ($a_obj_ids as $id) {
905 $all[$id] = false;
906 }
907
908 $set = $ilDB->query("SELECT obj_id FROM il_certificate WHERE " . $ilDB->in("obj_id", $a_obj_ids, "", "integer"));
909 while ($row = $ilDB->fetchAssoc($set)) {
910 $all[$row["obj_id"]] = true;
911 }
912
913 return $all;
914 }
915
919 public function readActive()
920 {
921 $obj_id = $this->adapter->getCertificateID();
922 $set = $this->db->query("SELECT obj_id FROM il_certificate WHERE obj_id = " . $this->db->quote($obj_id, "integer"));
923 return $this->db->numRows($set);
924 }
925
929 public function writeActive($a_value)
930 {
931 $obj_id = $this->adapter->getCertificateID();
932
933 if ((bool) $a_value) {
934 $this->db->replace("il_certificate", array("obj_id" => array("integer", $obj_id)), array());
935 } else {
936 $this->db->manipulate("DELETE FROM il_certificate WHERE obj_id = " . $this->db->quote($obj_id, "integer"));
937 }
938 }
939
945 public static function _goto($ref_id)
946 {
950 global $DIC;
951
952 $ilCtrl = $DIC['ilCtrl'];
953
954 include_once "./Services/Object/classes/class.ilObject.php";
955 $type = ilObject::_lookupType($ref_id, true);
956 switch ($type) {
957 case 'sahs':
958 $cmd_link = "ilias.php?baseClass=ilSAHSPresentationGUI&ref_id=" . $ref_id .
959 "&cmd=downloadCertificate";
960 ilUtil::redirect($cmd_link);
961 break;
962 case 'tst':
963 default:
964 $ilCtrl->redirectByClass("ilrepositorygui", "frameset");
965 break;
966 }
967 }
968
972 public static function getCustomCertificateFields()
973 {
974 include_once("./Services/User/classes/class.ilUserDefinedFields.php");
975 $user_field_definitions = ilUserDefinedFields::_getInstance();
976 $fds = $user_field_definitions->getDefinitions();
977 $fields = array();
978 foreach ($fds as $f) {
979 if ($f["certificate"]) {
980 $fields[$f["field_id"]] = array("name" => $f["field_name"],
981 "ph" => "[#" . str_replace(" ", "_", strtoupper($f["field_name"])) . "]");
982 }
983 }
984
985 return $fields;
986 }
987
991 public function getExchangeContent()
992 {
993 if (!file_exists($this->getXSLPath())) {
994 return '';
995 }
996
997 $output = '';
998 $xsl_file_content = file_get_contents($this->getXSLPath());
999 $xsl = file_get_contents("./Services/Certificate/xml/fo2xhtml.xsl");
1000
1001 if ((strlen($xsl_file_content)) && (strlen($xsl))) {
1002 $args = array('/_xml' => $xsl_file_content, '/_xsl' => $xsl);
1003 $xh = xslt_create();
1004 $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", null, $args, null);
1005 xslt_error($xh);
1006 xslt_free($xh);
1007 }
1008
1009 $output = preg_replace("/<\?xml[^>]+?>/", "", $output);
1010 // dirty hack: the php xslt processing seems not to recognize the following
1011 // replacements, so we do it in the code as well
1012 $output = str_replace("&#xA0;", "<br />", $output);
1013 $output = str_replace("&#160;", "<br />", $output);
1014
1015 return $output;
1016 }
1017
1024 public function outCertificateWithGivenContentAndVariables($content, array $insert_tags)
1025 {
1026 ilDatePresentation::setUseRelativeDates(false);
1027
1028 $form_fields = $this->getFormFieldsFromFO();
1029 $form_fields['certificate_text'] = $content;
1030 $xslfo = $this->processXHTML2FO($form_fields);
1031
1032 $content = $this->exchangeCertificateVariables($xslfo, $insert_tags);
1033 $content = str_replace('[BR]', "<fo:block/>", $content);
1034
1035 include_once './Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
1036 try {
1037 $pdf_base64 = ilRpcClientFactory::factory('RPCTransformationHandler')->ilFO2PDF($content);
1038 include_once "./Services/Utilities/classes/class.ilUtil.php";
1039 ilUtil::deliverData($pdf_base64->scalar, $this->getAdapter()->getCertificateFilename(array()), "application/pdf");
1040 } catch (Exception $e) {
1041 $this->log->write(__METHOD__ . ': ' . $e->getMessage());
1042 return false;
1043 }
1044
1045 ilDatePresentation::setUseRelativeDates(true);
1046 }
1047}
$result
An exception for terminatinating execution or to throw for unit testing.
Adapter class to provide certificate data for the certificate generator.
Create PDF certificates.
cloneCertificate($newObject)
Clone the certificate for another test object.
getBackgroundImageTempfilePath()
Returns the filesystem path of the background image temp file during upload.
deliverExportFileXML()
Builds an export file in ZIP format and delivers it.
getBackgroundImageThumbPath()
Returns the filesystem path of the background image thumbnail.
deleteBackgroundImage()
Deletes the background image of a certificate.
getBackgroundImageThumbPathWeb()
Returns the web path of the background image thumbnail.
uploadBackgroundImage($image_tempfilename)
Uploads a background image for the certificate.
static _isComplete($adapter)
Checks the status of the certificate.
exchangeCertificateVariables($certificate_text, $insert_tags=array())
Exchanges the variables in the certificate text with given values.
getPageFormats()
Retrieves predefined page formats.
importCertificate($zipfile, $filename)
Reads an import ZIP file and creates a certificate of it.
getBackgroundImagePathWeb()
Returns the web path of the background image.
getBackgroundImagePath($asRelative=false)
Returns the filesystem path of the background image.
formatNumberString($a_number)
isComplete()
Checks the status of the certificate.
getXSLName()
Returns the filename of the XSL-FO file.
outCertificate($params, $deliver=true)
Creates a PDF certificate.
setAdapter($adapter)
Sets the adapter.
getBackgroundImageName()
Returns the filename of the background image.
deleteCertificate()
Deletes the certificate and all it's data.
hasBackgroundImage()
Checks for the background image of the certificate.
static _getXSLName()
Returns the filename of the XSL-FO file.
getFormFieldsFromFO()
Convert the XSL-FO to the certificate text and the form settings using XSL transformation.
__construct(ilCertificateAdapter $adapter)
ilCertificate constructor
createPreview()
Creates a PDF preview of the XSL-FO certificate.
processXHTML2FO($form_data, $for_export=false)
Convert the certificate text to XSL-FO using XSL transformation.
getXSLPath()
Returns the filesystem path of the XSL-FO file.
getAdapter()
Gets the adapter.
saveCertificate($xslfo, $filename="")
Saves the XSL-FO code to a file.
static setUseRelativeDates($a_status)
set use relative dates
static getInstance()
Singleton: get instance.
const PURPOSE_PDF
const RENDER_PNG_AS_FO_FILE
static hasBackgroundImage()
Returns wheather or not a default background image exists.
static getBackgroundImagePath($asRelative=false)
Returns the filesystem path of the background image.
static getBackgroundImageName()
Returns the filename of the background image.
static factory($a_package, $a_timeout=0)
Creates an ilRpcClient instance to our ilServer.
ILIAS Setting Class.
Class ilUserDefinedData.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static convertImage( $a_from, $a_to, $a_target_format="", $a_geometry="", $a_background_color="")
convert image
static deliverData($a_data, $a_filename, $mime="application/octet-stream", $charset="")
deliver data for download via browser.
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
static unzip($a_file, $overwrite=false, $a_flat=false)
unzip file
static makeDirParents($a_dir)
Create a new directory and all parent directories.
static removeTrailingPathSeparators($path)
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\s+" &#(? foreach( $entity_files as $file) $output
xslt_error(&$proc)
xslt_free(&$proc)
xslt_create()
redirection script todo: (a better solution should control the processing via a xml file)
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file
global $DIC
Definition: saml.php:7
settings()
Definition: settings.php:2
$params
Definition: disable.php:11