ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 {
109 return str_replace(
110 array(CLIENT_WEB_DIR, '//'),
111 array('[CLIENT_WEB_DIR]', '/'),
112 $this->getAdapter()->getCertificatePath() . $this->getBackgroundImageName()
113 );
114 }
115
116 return $this->getAdapter()->getCertificatePath() . $this->getBackgroundImageName();
117 }
118
124 public function getBackgroundImageName()
125 {
126 return "background.jpg";
127 }
128
135 {
136 return $this->getAdapter()->getCertificatePath() . $this->getBackgroundImageName() . ".thumb.jpg";
137 }
138
145 {
146 return $this->getAdapter()->getCertificatePath() . "background_upload.tmp";
147 }
148
154 public function getXSLPath()
155 {
156 return $this->getAdapter()->getCertificatePath() . $this->getXSLName();
157 }
158
164 function getXSLName()
165 {
166 return "certificate.xml";
167 }
168
174 public static function _getXSLName()
175 {
176 return "certificate.xml";
177 }
178
185 {
186 // TODO: this is generic now -> provide better solution
187 include_once "./Services/Utilities/classes/class.ilUtil.php";
188 $webdir = $this->getAdapter()->getCertificatePath() . $this->getBackgroundImageName();
189 return str_replace(ilUtil::removeTrailingPathSeparators(ILIAS_ABSOLUTE_PATH), ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH), $webdir);
190 }
191
198 {
199 // TODO: this is generic now -> provide better solution
200 include_once "./Services/Utilities/classes/class.ilUtil.php";
201 return str_replace(ilUtil::removeTrailingPathSeparators(ILIAS_ABSOLUTE_PATH), ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH), $this->getBackgroundImageThumbPath());
202 }
203
209 public function deleteBackgroundImage()
210 {
211 $result = TRUE;
212 if (file_exists($this->getBackgroundImageThumbPath()))
213 {
214 $result = $result & unlink($this->getBackgroundImageThumbPath());
215 }
216 if (file_exists($this->getBackgroundImagePath()))
217 {
218 $result = $result & unlink($this->getBackgroundImagePath());
219 }
220 if (file_exists($this->getBackgroundImageTempfilePath()))
221 {
223 }
224 return $result;
225 }
226
232 public function cloneCertificate($newObject)
233 {
234 $xsl = $this->getXSLPath();
235 $bgimage = $this->getBackgroundImagePath();
236 $bgimagethumb = $this->getBackgroundImageThumbPath();
237 $certificatepath = $this->getAdapter()->getCertificatePath();
238
239 $new_xsl = $newObject->getXSLPath();
240 $new_bgimage = $newObject->getBackgroundImagePath();
241 $new_bgimagethumb = $newObject->getBackgroundImageThumbPath();
242 $new_certificatepath = $newObject->getAdapter()->getCertificatePath();
243
244 if (@file_exists($xsl))
245 {
246 ilUtil::makeDirParents($new_certificatepath);
247 @copy($xsl, $new_xsl);
248 if (@file_exists($bgimage)) @copy($bgimage, $new_bgimage);
249 if (@file_exists($bgimagethumb)) @copy($bgimagethumb, $new_bgimagethumb);
250 }
251
252 // #10271
253 if($this->readActive())
254 {
255 $newObject->writeActive(true);
256 }
257 }
258
264 public function deleteCertificate()
265 {
266 if (@file_exists($this->getAdapter()->getCertificatePath()))
267 {
268 include_once "./Services/Utilities/classes/class.ilUtil.php";
269 ilUtil::delDir($this->getAdapter()->getCertificatePath());
270 $this->getAdapter()->deleteCertificate();
271 }
272 $this->writeActive(false);
273 }
274
278 public function getFormFieldsFromFO()
279 {
280 if (@file_exists($this->getXSLPath()))
281 {
282 $xslfo = file_get_contents($this->getXSLPath());
283 }
284 // retrieve form information (using a dirty way with regular expressions)
285 $pagewidth = "21cm";
286 if (preg_match("/page-width\=\"([^\"]+)\"/", $xslfo, $matches))
287 {
288 $pagewidth = $matches[1];
289 }
290 $pageheight = "29.7cm";
291 if (preg_match("/page-height\=\"([^\"]+)\"/", $xslfo, $matches))
292 {
293 $pageheight = $matches[1];
294 }
295 $certificatesettings = new ilSetting("certificate");
296 $pagesize = $certificatesettings->get("pageformat");;
297 if (((strcmp($pageheight, "29.7cm") == 0) || (strcmp($pageheight, "297mm") == 0)) && ((strcmp($pagewidth, "21cm") == 0) || (strcmp($pagewidth, "210mm") == 0)))
298 {
299 $pagesize = "a4";
300 }
301 else if (((strcmp($pagewidth, "29.7cm") == 0) || (strcmp($pagewidth, "297mm") == 0)) && ((strcmp($pageheight, "21cm") == 0) || (strcmp($pageheight, "210mm") == 0)))
302 {
303 $pagesize = "a4landscape";
304 }
305 else if (((strcmp($pageheight, "21cm") == 0) || (strcmp($pageheight, "210mm") == 0)) && ((strcmp($pagewidth, "14.8cm") == 0) || (strcmp($pagewidth, "148mm") == 0)))
306 {
307 $pagesize = "a5";
308 }
309 else if (((strcmp($pagewidth, "21cm") == 0) || (strcmp($pagewidth, "210mm") == 0)) && ((strcmp($pageheight, "14.8cm") == 0) || (strcmp($pageheight, "148mm") == 0)))
310 {
311 $pagesize = "a5landscape";
312 }
313 else if (((strcmp($pageheight, "11in") == 0)) && ((strcmp($pagewidth, "8.5in") == 0)))
314 {
315 $pagesize = "letter";
316 }
317 else if (((strcmp($pagewidth, "11in") == 0)) && ((strcmp($pageheight, "8.5in") == 0)))
318 {
319 $pagesize = "letterlandscape";
320 }
321 else
322 {
323 $pagesize = "custom";
324 }
325 if (!strlen($xslfo)) $pagesize = $certificatesettings->get("pageformat");;
326
327 $marginbody_top = "0cm";
328 $marginbody_right = "2cm";
329 $marginbody_bottom = "0cm";
330 $marginbody_left = "2cm";
331 if(preg_match("/fo:flow[^>]*margin\=\"([^\"]+)\"/", $xslfo, $matches))
332 {
333 // Backwards compatibility
334 $marginbody = $matches[1];
335 if (preg_match_all("/([^\s]+)/", $marginbody, $matches))
336 {
337 $marginbody_top = $matches[1][0];
338 $marginbody_right = $matches[1][1];
339 $marginbody_bottom = $matches[1][2];
340 $marginbody_left = $matches[1][3];
341 }
342 }
343 else if(preg_match("/fo:region-body[^>]*margin\=\"([^\"]+)\"/", $xslfo, $matches))
344 {
345 $marginbody = $matches[1];
346 if (preg_match_all("/([^\s]+)/", $marginbody, $matches))
347 {
348 $marginbody_top = $matches[1][0];
349 $marginbody_right = $matches[1][1];
350 $marginbody_bottom = $matches[1][2];
351 $marginbody_left = $matches[1][3];
352 }
353 }
354
355 $xsl = file_get_contents("./Services/Certificate/xml/fo2xhtml.xsl");
356 if ((strlen($xslfo)) && (strlen($xsl)))
357 {
358 $args = array( '/_xml' => $xslfo, '/_xsl' => $xsl );
359 $xh = xslt_create();
360 $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", NULL, $args, NULL);
361 xslt_error($xh);
362 xslt_free($xh);
363 }
364
365 $output = preg_replace("/<\?xml[^>]+?>/", "", $output);
366 // dirty hack: the php xslt processing seems not to recognize the following
367 // replacements, so we do it in the code as well
368 $output = str_replace("&#xA0;", "<br />", $output);
369 $output = str_replace("&#160;", "<br />", $output);
370 $form_fields = array(
371 "pageformat" => $pagesize,
372 "pagewidth" => $pagewidth,
373 "pageheight" => $pageheight,
374 "margin_body_top" => $marginbody_top,
375 "margin_body_right" => $marginbody_right,
376 "margin_body_bottom" => $marginbody_bottom,
377 "margin_body_left" => $marginbody_left,
378 "certificate_text" => $output
379 );
380 $this->getAdapter()->addFormFieldsFromObject($form_fields);
381 return $form_fields;
382 }
383
390 public function processXHTML2FO($form_data, $for_export = FALSE)
391 {
392 $content = "<html><body>".$form_data["certificate_text"]."</body></html>";
393 $content = preg_replace("/<p>(&nbsp;){1,}<\\/p>/", "<p></p>", $content);
394 $content = preg_replace("/<p>(\\s)*?<\\/p>/", "<p></p>", $content);
395// $content = str_replace("<p>&nbsp;</p>", "<p><br /></p>", $content);
396// $content = str_replace("<p> </p>", "<p><br /></p>", $content);
397 $content = str_replace("<p></p>", "<p class=\"emptyrow\"></p>", $content);
398 $content = str_replace("&nbsp;", "&#160;", $content);
399 $content = preg_replace("//", "", $content);
400
401 include_once "./Services/Certificate/classes/class.ilXmlChecker.php";
402 $check = new ilXMLChecker();
403 $check->setXMLContent($content);
404 $check->startParsing();
405 if ($check->hasError())
406 {
407 throw new Exception($this->lng->txt("certificate_not_well_formed"));
408 }
409
410 $xsl = file_get_contents("./Services/Certificate/xml/xhtml2fo.xsl");
411
412 // additional font support
413 $xsl = str_replace(
414 'font-family="Helvetica, unifont"',
415 'font-family="'.$this->settings->get('rpc_pdf_font','Helvetica, unifont').'"',
416 $xsl
417 );
418
419 $args = array( '/_xml' => $content, '/_xsl' => $xsl );
420 $xh = xslt_create();
421 if (strcmp($form_data["pageformat"], "custom") == 0)
422 {
423 $pageheight = $form_data["pageheight"];
424 $pagewidth = $form_data["pagewidth"];
425 }
426 else
427 {
428 $pageformats = $this->getPageFormats();
429 $pageheight = $pageformats[$form_data["pageformat"]]["height"];
430 $pagewidth = $pageformats[$form_data["pageformat"]]["width"];
431 }
432 include_once "./Services/Certificate/classes/class.ilObjCertificateSettingsAccess.php";
434 $params = array(
435 "pageheight" => $pageheight,
436 "pagewidth" => $pagewidth,
437 "backgroundimage" => $backgroundimage,
438 "marginbody" => implode(' ', array(
439 $form_data["margin_body_top"],
440 $form_data["margin_body_right"],
441 $form_data["margin_body_bottom"],
442 $form_data["margin_body_left"]
443 ))
444 );
445 $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", NULL, $args, $params);
446 xslt_error($xh);
447 xslt_free($xh);
448 return $output;
449 }
450
458 private function exchangeCertificateVariables($certificate_text, $insert_tags = array())
459 {
460 if (count($insert_tags) == 0)
461 {
462 $insert_tags = $this->getAdapter()->getCertificateVariablesForPreview();
463 foreach (self::getCustomCertificateFields() as $k => $f)
464 {
465 $insert_tags[$f["ph"]] = ilUtil::prepareFormOutput($f["name"]);
466 }
467 }
468 foreach ($insert_tags as $var => $value)
469 {
470 $certificate_text = str_replace($var, $value, $certificate_text);
471 }
472
473 $certificate_text = str_replace('[CLIENT_WEB_DIR]', CLIENT_WEB_DIR, $certificate_text);
474
475 return $certificate_text;
476 }
477
484 public function outCertificate($params, $deliver = TRUE)
485 {
487 $insert_tags = $this->getAdapter()->getCertificateVariablesForPresentation($params);
488
489 include_once("./Services/User/classes/class.ilUserDefinedData.php");
490 $cust_data = new ilUserDefinedData($this->getAdapter()->getUserIdForParams($params));
491 $cust_data = $cust_data->getAll();
492 foreach (self::getCustomCertificateFields() as $k => $f)
493 {
494 $insert_tags[$f["ph"]] = ilUtil::prepareFormOutput($cust_data["f_".$k]);
495 }
496
497 $xslfo = file_get_contents($this->getXSLPath());
498
499 // render tex as fo graphics
500 require_once('Services/MathJax/classes/class.ilMathJax.php');
501 $xslfo = ilMathJax::getInstance()
504 ->insertLatexImages($xslfo);
505
506 include_once './Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
507 try
508 {
509 $pdf_base64 = ilRpcClientFactory::factory('RPCTransformationHandler')->ilFO2PDF(
510 $this->exchangeCertificateVariables($xslfo, $insert_tags));
511 if ($deliver)
512 {
513 include_once "./Services/Utilities/classes/class.ilUtil.php";
514 ilUtil::deliverData($pdf_base64->scalar, $this->getAdapter()->getCertificateFilename($params), "application/pdf");
515 }
516 else
517 {
518 return $pdf_base64->scalar;
519 }
520 }
521 catch(Exception $e)
522 {
523 $this->log->write(__METHOD__.': '.$e->getMessage());
524 return false;
525 }
526
528
529 }
530
534 public function createPreview()
535 {
537
538 $xslfo = file_get_contents($this->getXSLPath());
539
540 // render tex as fo graphics
541 require_once('Services/MathJax/classes/class.ilMathJax.php');
542 $xslfo = ilMathJax::getInstance()
545 ->insertLatexImages($xslfo);
546
547 include_once './Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
548 try
549 {
550 $pdf_base64 = ilRpcClientFactory::factory('RPCTransformationHandler')->ilFO2PDF(
551 $this->exchangeCertificateVariables($xslfo));
552 ilUtil::deliverData($pdf_base64->scalar, $this->getAdapter()->getCertificateFilename(), "application/pdf");
553
554 }
555 catch(Exception $e)
556 {
557 $this->log->write(__METHOD__.': '.$e->getMessage());
558 return false;
559 }
560
562
563 }
564
570 public function saveCertificate($xslfo, $filename = "")
571 {
572 if (!file_exists($this->getAdapter()->getCertificatePath()))
573 {
574 ilUtil::makeDirParents($this->getAdapter()->getCertificatePath());
575 }
576 if (strlen($filename) == 0)
577 {
578 $filename = $this->getXSLPath();
579 }
580 $fh = fopen($filename, "w");
581 fwrite($fh, $xslfo);
582 fclose($fh);
583 }
584
592 public function uploadBackgroundImage($image_tempfilename)
593 {
594 if (!empty($image_tempfilename))
595 {
596 $convert_filename = $this->getBackgroundImageName();
597 $imagepath = $this->getAdapter()->getCertificatePath();
598 if (!file_exists($imagepath))
599 {
600 ilUtil::makeDirParents($imagepath);
601 }
602 // upload the file
604 $image_tempfilename,
605 basename($this->getBackgroundImageTempfilePath()),
607 )) {
608 return FALSE;
609 }
610 // convert the uploaded file to JPEG
613 if (!file_exists($this->getBackgroundImagePath()))
614 {
615 // something went wrong converting the file. use the original file and hope, that PDF can work with it
616 if (!ilUtil::moveUploadedFile($this->getBackgroundImageTempfilePath(), $convert_filename, $this->getBackgroundImagePath()))
617 {
618 return FALSE;
619 }
620 }
621 unlink($this->getBackgroundImageTempfilePath());
622 if (file_exists($this->getBackgroundImagePath()) && (filesize($this->getBackgroundImagePath()) > 0))
623 {
624 return TRUE;
625 }
626 }
627 return FALSE;
628 }
629
635 public function hasBackgroundImage()
636 {
637 if (file_exists($this->getBackgroundImagePath()) && (filesize($this->getBackgroundImagePath()) > 0))
638 {
639 return TRUE;
640 }
641 else
642 {
643 return FALSE;
644 }
645 }
646
652 public function isComplete()
653 {
654 if(self::isActive())
655 {
656 $obj_id = $this->getAdapter()->getCertificateID();
657 if($obj_id && !self::isObjectActive($obj_id))
658 {
659 return FALSE;
660 }
661 if (file_exists($this->getAdapter()->getCertificatePath()))
662 {
663 if (file_exists($this->getXSLPath()) && (filesize($this->getXSLPath()) > 0))
664 {
665 return TRUE;
666 }
667 }
668 }
669 return FALSE;
670 }
671
678 public static function _isComplete($adapter)
679 {
680 if (is_object($adapter) && method_exists($adapter, "getCertificatePath"))
681 {
682 if(self::isActive())
683 {
684 $obj_id = $adapter->getCertificateID();
685 if($obj_id && !self::isObjectActive($obj_id))
686 {
687 return FALSE;
688 }
689
690 $certificatepath = $adapter->getCertificatePath();
691 if (file_exists($certificatepath))
692 {
693 $xslpath = $adapter->getCertificatePath() . ilCertificate::_getXSLName();
694 if (file_exists($xslpath) && (filesize($xslpath) > 0))
695 {
696 return TRUE;
697 }
698 }
699 }
700 }
701 return FALSE;
702 }
703
709 public function getPageFormats()
710 {
711 return array(
712 "a4" => array(
713 "name" => $this->lng->txt("certificate_a4"), // (297 mm x 210 mm)
714 "value" => "a4",
715 "width" => "210mm",
716 "height" => "297mm"
717 ),
718 "a4landscape" => array(
719 "name" => $this->lng->txt("certificate_a4_landscape"), // (210 mm x 297 mm)",
720 "value" => "a4landscape",
721 "width" => "297mm",
722 "height" => "210mm"
723 ),
724 "a5" => array(
725 "name" => $this->lng->txt("certificate_a5"), // (210 mm x 148.5 mm)
726 "value" => "a5",
727 "width" => "148mm",
728 "height" => "210mm"
729 ),
730 "a5landscape" => array(
731 "name" => $this->lng->txt("certificate_a5_landscape"), // (148.5 mm x 210 mm)
732 "value" => "a5landscape",
733 "width" => "210mm",
734 "height" => "148mm"
735 ),
736 "letter" => array(
737 "name" => $this->lng->txt("certificate_letter"), // (11 inch x 8.5 inch)
738 "value" => "letter",
739 "width" => "8.5in",
740 "height" => "11in"
741 ),
742 "letterlandscape" => array(
743 "name" => $this->lng->txt("certificate_letter_landscape"), // (8.5 inch x 11 inch)
744 "value" => "letterlandscape",
745 "width" => "11in",
746 "height" => "8.5in"
747 ),
748 "custom" => array(
749 "name" => $this->lng->txt("certificate_custom"),
750 "value" => "custom",
751 "width" => "",
752 "height" => ""
753 )
754 );
755 }
756
760 public function deliverExportFileXML()
761 {
762 include_once "./Services/Utilities/classes/class.ilUtil.php";
763 $exportpath = $this->createArchiveDirectory();
764 ilUtil::makeDir($exportpath);
765 $xsl = file_get_contents($this->getXSLPath());
766 $xslexport = str_replace($this->getAdapter()->getCertificatePath(), "", $xsl);
767 // save export xsl file
768 $this->saveCertificate($xslexport, $exportpath . $this->getXSLName());
769 // save background image
770 if ($this->hasBackgroundImage())
771 {
772 copy($this->getBackgroundImagePath(), $exportpath . $this->getBackgroundImageName());
773 }
774 else
775 {
776 include_once "./Services/Certificate/classes/class.ilObjCertificateSettingsAccess.php";
778 {
780 }
781 }
782 $zipfile = time() . "__" . IL_INST_ID . "__" . $this->getAdapter()->getAdapterType() . "__" . $this->getAdapter()->getCertificateId() . "__certificate.zip";
783 ilUtil::zip($exportpath, $this->getAdapter()->getCertificatePath() . $zipfile);
784 ilUtil::delDir($exportpath);
785 ilUtil::deliverFile($this->getAdapter()->getCertificatePath() . $zipfile, $zipfile, "application/zip");
786 }
787
793 public function importCertificate($zipfile, $filename)
794 {
795 include_once "./Services/Utilities/classes/class.ilUtil.php";
796 $importpath = $this->createArchiveDirectory();
797 if (!ilUtil::moveUploadedFile($zipfile, $filename, $importpath . $filename))
798 {
799 ilUtil::delDir($importpath);
800 return FALSE;
801 }
802 ilUtil::unzip($importpath . $filename, TRUE);
803 $subdir = str_replace(".zip", "", strtolower($filename)) . "/";
804 $copydir = "";
805 if (is_dir($importpath . $subdir))
806 {
807 $dirinfo = ilUtil::getDir($importpath . $subdir);
808 $copydir = $importpath . $subdir;
809 }
810 else
811 {
812 $dirinfo = ilUtil::getDir($importpath);
813 $copydir = $importpath;
814 }
815 $xmlfiles = 0;
816 $otherfiles = 0;
817 foreach ($dirinfo as $file)
818 {
819 if (strcmp($file["type"], "file") == 0)
820 {
821 if (strpos($file["entry"], ".xml") !== FALSE)
822 {
823 $xmlfiles++;
824 }
825 else if (strpos($file["entry"], ".zip") !== FALSE)
826 {
827 }
828 else
829 {
830 $otherfiles++;
831 }
832 }
833 }
834 // if one XML file is in the archive, we try to import it
835 if ($xmlfiles == 1)
836 {
837 foreach ($dirinfo as $file)
838 {
839 if (strcmp($file["type"], "file") == 0)
840 {
841 if (strpos($file["entry"], ".xml") !== FALSE)
842 {
843 $xsl = file_get_contents($copydir . $file["entry"]);
844 // as long as we cannot make RPC calls in a given directory, we have
845 // to add the complete path to every url
846 $xsl = preg_replace("/url\‍([']{0,1}(.*?)[']{0,1}\‍)/", "url(" . $this->getAdapter()->getCertificatePath() . "\${1})", $xsl);
847 $this->saveCertificate($xsl);
848 }
849 else if (strpos($file["entry"], ".zip") !== FALSE)
850 {
851 }
852 else
853 {
854 @copy($copydir . $file["entry"], $this->getAdapter()->getCertificatePath() . $file["entry"]);
855 if (strcmp($this->getBackgroundImagePath(), $this->getAdapter()->getCertificatePath() . $file["entry"]) == 0)
856 {
857 // upload of the background image, create a preview
859 }
860 }
861 }
862 }
863 }
864 else
865 {
866 ilUtil::delDir($importpath);
867 return FALSE;
868 }
869 ilUtil::delDir($importpath);
870 return TRUE;
871 }
872
878 public function getAdapter()
879 {
880 return $this->adapter;
881 }
882
888 public function setAdapter($adapter)
889 {
890 $this->adapter =& $adapter;
891 }
892
893 /***************************************
894 /* BULK CERTIFICATE PROCESSING METHODS *
895 /***************************************
896
902 public function createArchiveDirectory()
903 {
904 $dir = $this->getAdapter()->getCertificatePath() . time() . "__" . IL_INST_ID . "__" . $this->getAdapter()->getAdapterType() . "__" . $this->getAdapter()->getCertificateId() . "__certificate/";
905 include_once "./Services/Utilities/classes/class.ilUtil.php";
906 ilUtil::makeDirParents($dir);
907 return $dir;
908 }
909
917 public function addPDFtoArchiveDirectory($pdfdata, $dir, $filename)
918 {
919 $fh = fopen($dir . $filename, "wb");
920 fwrite($fh, $pdfdata);
921 fclose($fh);
922 }
923
931 public function zipCertificatesInArchiveDirectory($dir, $deliver = TRUE)
932 {
933 $zipfile = time() . "__" . IL_INST_ID . "__" . $this->getAdapter()->getAdapterType() . "__" . $this->getAdapter()->getCertificateId() . "__certificates.zip";
934 ilUtil::zip($dir, $this->getAdapter()->getCertificatePath() . $zipfile);
935 ilUtil::delDir($dir);
936 if ($deliver)
937 {
938 ilUtil::deliverFile($this->getAdapter()->getCertificatePath() . $zipfile, $zipfile, "application/zip");
939 }
940 return $this->getAdapter()->getCertificatePath() . $zipfile;
941 }
942
943 public static function isActive()
944 {
945 if(self::$is_active === null)
946 {
947 // basic admin setting active?
948 $certificate_active = new ilSetting("certificate");
949 $certificate_active = (bool)$certificate_active->get("active");
950
951 // java/rtpc-server active?
952 if($certificate_active)
953 {
954 include_once './Services/WebServices/RPC/classes/class.ilRPCServerSettings.php';
955 $certificate_active = ilRPCServerSettings::getInstance()->isEnabled();
956 }
957
958 self::$is_active = (bool)$certificate_active;
959 }
960 return self::$is_active;
961 }
962
967 public static function isObjectActive($a_obj_id)
968 {
969 $chk = self::areObjectsActive(array($a_obj_id));
970 return $chk[$a_obj_id];
971 }
972
977 public static function areObjectsActive(array $a_obj_ids)
978 {
982 global $DIC;
983
984 $ilDB = $DIC['ilDB'];
985
986 $all = array();
987 foreach($a_obj_ids as $id)
988 {
989 $all[$id] = false;
990 }
991
992 $set = $ilDB->query("SELECT obj_id FROM il_certificate WHERE ".$ilDB->in("obj_id", $a_obj_ids, "", "integer"));
993 while($row = $ilDB->fetchAssoc($set))
994 {
995 $all[$row["obj_id"]] = true;
996 }
997
998 return $all;
999 }
1000
1004 public function readActive()
1005 {
1006 $obj_id = $this->adapter->getCertificateID();
1007 $set = $this->db->query("SELECT obj_id FROM il_certificate WHERE obj_id = " . $this->db->quote($obj_id, "integer"));
1008 return $this->db->numRows($set);
1009 }
1010
1014 public function writeActive($a_value)
1015 {
1016 $obj_id = $this->adapter->getCertificateID();
1017
1018 if((bool)$a_value)
1019 {
1020 $this->db->replace("il_certificate", array("obj_id" => array("integer", $obj_id)), array());
1021 }
1022 else
1023 {
1024 $this->db->manipulate("DELETE FROM il_certificate WHERE obj_id = " . $this->db->quote($obj_id, "integer"));
1025 }
1026 }
1027
1033 public static function _goto($ref_id)
1034 {
1038 global $DIC;
1039
1040 $ilCtrl = $DIC['ilCtrl'];
1041
1042 include_once "./Services/Object/classes/class.ilObject.php";
1043 $type = ilObject::_lookupType($ref_id, true);
1044 switch ($type)
1045 {
1046 case 'sahs':
1047 $cmd_link = "ilias.php?baseClass=ilSAHSPresentationGUI&ref_id=".$ref_id.
1048 "&cmd=downloadCertificate";
1049 ilUtil::redirect($cmd_link);
1050 break;
1051 case 'tst':
1052 default:
1053 $ilCtrl->redirectByClass("ilrepositorygui", "frameset");
1054 break;
1055 }
1056 }
1057
1061 static function getCustomCertificateFields()
1062 {
1063 include_once("./Services/User/classes/class.ilUserDefinedFields.php");
1064 $user_field_definitions = ilUserDefinedFields::_getInstance();
1065 $fds = $user_field_definitions->getDefinitions();
1066 $fields = array();
1067 foreach ($fds as $f)
1068 {
1069 if ($f["certificate"])
1070 {
1071 $fields[$f["field_id"]] = array("name" => $f["field_name"],
1072 "ph" => "[#".str_replace(" ", "_", strtoupper($f["field_name"]))."]");
1073 }
1074 }
1075
1076 return $fields;
1077 }
1078
1082 public function getExchangeContent()
1083 {
1084 if(!file_exists($this->getXSLPath()))
1085 {
1086 return '';
1087 }
1088
1089 $output = '';
1090 $xsl_file_content = file_get_contents($this->getXSLPath());
1091 $xsl = file_get_contents("./Services/Certificate/xml/fo2xhtml.xsl");
1092
1093 if((strlen($xsl_file_content)) && (strlen($xsl)))
1094 {
1095 $args = array('/_xml' => $xsl_file_content, '/_xsl' => $xsl);
1096 $xh = xslt_create();
1097 $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", NULL, $args, NULL);
1098 xslt_error($xh);
1099 xslt_free($xh);
1100 }
1101
1102 $output = preg_replace("/<\?xml[^>]+?>/", "", $output);
1103 // dirty hack: the php xslt processing seems not to recognize the following
1104 // replacements, so we do it in the code as well
1105 $output = str_replace("&#xA0;", "<br />", $output);
1106 $output = str_replace("&#160;", "<br />", $output);
1107
1108 return $output;
1109 }
1110
1117 public function outCertificateWithGivenContentAndVariables($content, array $insert_tags)
1118 {
1119 ilDatePresentation::setUseRelativeDates(false);
1120
1121 $form_fields = $this->getFormFieldsFromFO();
1122 $form_fields['certificate_text'] = $content;
1123 $xslfo = $this->processXHTML2FO($form_fields);
1124
1125 $content = $this->exchangeCertificateVariables($xslfo, $insert_tags);
1126 $content = str_replace('[BR]', "<fo:block/>", $content);
1127
1128 include_once './Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
1129 try
1130 {
1131 $pdf_base64 = ilRpcClientFactory::factory('RPCTransformationHandler')->ilFO2PDF($content);
1132 include_once "./Services/Utilities/classes/class.ilUtil.php";
1133 ilUtil::deliverData($pdf_base64->scalar, $this->getAdapter()->getCertificateFilename(array()), "application/pdf");
1134 }
1135 catch(Exception $e)
1136 {
1137 $this->log->write(__METHOD__.': '.$e->getMessage());
1138 return false;
1139 }
1140
1141 ilDatePresentation::setUseRelativeDates(true);
1142 }
1143}
$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.
processXHTML2FO($form_data, $for_export=FALSE)
Convert the certificate text to XSL-FO using XSL transformation.
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.
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.
outCertificate($params, $deliver=TRUE)
Creates a PDF certificate.
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 moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
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)
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
static convertImage($a_from, $a_to, $a_target_format="", $a_geometry="", $a_background_color="")
convert image
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 deliverFile($a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
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 ...
$params
Definition: example_049.php:96
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
settings()
Definition: settings.php:2
global $DIC