ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 $tpl;
44 
50  protected $lng;
51 
57  protected $adapter;
58 
59  protected static $is_active;
60 
67  {
68  global $lng, $tpl, $ilCtrl, $ilias, $tree;
69 
70  $this->lng =& $lng;
71  $this->tpl =& $tpl;
72  $this->ctrl =& $ilCtrl;
73  $this->ilias =& $ilias;
74  $this->tree =& $tree;
75  $this->adapter =& $adapter;
76  }
77 
83  public function getBackgroundImagePath()
84  {
85  return $this->getAdapter()->getCertificatePath() . $this->getBackgroundImageName();
86  }
87 
93  public function getBackgroundImageName()
94  {
95  return "background.jpg";
96  }
97 
103  public function getBackgroundImageThumbPath()
104  {
105  return $this->getAdapter()->getCertificatePath() . $this->getBackgroundImageName() . ".thumb.jpg";
106  }
107 
114  {
115  return $this->getAdapter()->getCertificatePath() . "background_upload.tmp";
116  }
117 
123  public function getXSLPath()
124  {
125  return $this->getAdapter()->getCertificatePath() . $this->getXSLName();
126  }
127 
133  function getXSLName()
134  {
135  return "certificate.xml";
136  }
137 
143  public static function _getXSLName()
144  {
145  return "certificate.xml";
146  }
147 
153  public function getBackgroundImagePathWeb()
154  {
155  // TODO: this is generic now -> provide better solution
156  include_once "./Services/Utilities/classes/class.ilUtil.php";
157  $webdir = $this->getAdapter()->getCertificatePath() . $this->getBackgroundImageName();
159  }
160 
167  {
168  // TODO: this is generic now -> provide better solution
169  include_once "./Services/Utilities/classes/class.ilUtil.php";
171  }
172 
178  public function deleteBackgroundImage()
179  {
180  $result = TRUE;
181  if (file_exists($this->getBackgroundImageThumbPath()))
182  {
183  $result = $result & unlink($this->getBackgroundImageThumbPath());
184  }
185  if (file_exists($this->getBackgroundImagePath()))
186  {
187  $result = $result & unlink($this->getBackgroundImagePath());
188  }
189  if (file_exists($this->getBackgroundImageTempfilePath()))
190  {
191  $result = $result & unlink($this->getBackgroundImageTempfilePath());
192  }
193  return $result;
194  }
195 
201  public function cloneCertificate($newObject)
202  {
203  $xsl = $this->getXSLPath();
204  $bgimage = $this->getBackgroundImagePath();
205  $bgimagethumb = $this->getBackgroundImageThumbPath();
206  $certificatepath = $this->getAdapter()->getCertificatePath();
207 
208  $new_xsl = $newObject->getXSLPath();
209  $new_bgimage = $newObject->getBackgroundImagePath();
210  $new_bgimagethumb = $newObject->getBackgroundImageThumbPath();
211  $new_certificatepath = $newObject->getAdapter()->getCertificatePath();
212 
213  if (@file_exists($xsl))
214  {
215  ilUtil::makeDirParents($new_certificatepath);
216  @copy($xsl, $new_xsl);
217  if (@file_exists($bgimage)) @copy($bgimage, $new_bgimage);
218  if (@file_exists($bgimagethumb)) @copy($bgimagethumb, $new_bgimagethumb);
219  }
220 
221  // #10271
222  if($this->readActive())
223  {
224  $newObject->writeActive(true);
225  }
226  }
227 
233  public function deleteCertificate()
234  {
235  if (@file_exists($this->getAdapter()->getCertificatePath()))
236  {
237  include_once "./Services/Utilities/classes/class.ilUtil.php";
238  ilUtil::delDir($this->getAdapter()->getCertificatePath());
239  $this->getAdapter()->deleteCertificate();
240  }
241  $this->writeActive(false);
242  }
243 
247  public function getFormFieldsFromFO()
248  {
249  if (@file_exists($this->getXSLPath()))
250  {
251  $xslfo = file_get_contents($this->getXSLPath());
252  }
253  // retrieve form information (using a dirty way with regular expressions)
254  $pagewidth = "21cm";
255  if (preg_match("/page-width\=\"([^\"]+)\"/", $xslfo, $matches))
256  {
257  $pagewidth = $matches[1];
258  }
259  $pageheight = "29.7cm";
260  if (preg_match("/page-height\=\"([^\"]+)\"/", $xslfo, $matches))
261  {
262  $pageheight = $matches[1];
263  }
264  $certificatesettings = new ilSetting("certificate");
265  $pagesize = $certificatesettings->get("pageformat");;
266  if (((strcmp($pageheight, "29.7cm") == 0) || (strcmp($pageheight, "297mm") == 0)) && ((strcmp($pagewidth, "21cm") == 0) || (strcmp($pagewidth, "210mm") == 0)))
267  {
268  $pagesize = "a4";
269  }
270  else if (((strcmp($pagewidth, "29.7cm") == 0) || (strcmp($pagewidth, "297mm") == 0)) && ((strcmp($pageheight, "21cm") == 0) || (strcmp($pageheight, "210mm") == 0)))
271  {
272  $pagesize = "a4landscape";
273  }
274  else if (((strcmp($pageheight, "21cm") == 0) || (strcmp($pageheight, "210mm") == 0)) && ((strcmp($pagewidth, "14.8cm") == 0) || (strcmp($pagewidth, "148mm") == 0)))
275  {
276  $pagesize = "a5";
277  }
278  else if (((strcmp($pagewidth, "21cm") == 0) || (strcmp($pagewidth, "210mm") == 0)) && ((strcmp($pageheight, "14.8cm") == 0) || (strcmp($pageheight, "148mm") == 0)))
279  {
280  $pagesize = "a5landscape";
281  }
282  else if (((strcmp($pageheight, "11in") == 0)) && ((strcmp($pagewidth, "8.5in") == 0)))
283  {
284  $pagesize = "letter";
285  }
286  else if (((strcmp($pagewidth, "11in") == 0)) && ((strcmp($pageheight, "8.5in") == 0)))
287  {
288  $pagesize = "letterlandscape";
289  }
290  else
291  {
292  $pagesize = "custom";
293  }
294  if (!strlen($xslfo)) $pagesize = $certificatesettings->get("pageformat");;
295 
296  $marginbody_top = "0cm";
297  $marginbody_right = "2cm";
298  $marginbody_bottom = "0cm";
299  $marginbody_left = "2cm";
300  if(preg_match("/fo:flow[^>]*margin\=\"([^\"]+)\"/", $xslfo, $matches))
301  {
302  // Backwards compatibility
303  $marginbody = $matches[1];
304  if (preg_match_all("/([^\s]+)/", $marginbody, $matches))
305  {
306  $marginbody_top = $matches[1][0];
307  $marginbody_right = $matches[1][1];
308  $marginbody_bottom = $matches[1][2];
309  $marginbody_left = $matches[1][3];
310  }
311  }
312  else if(preg_match("/fo:region-body[^>]*margin\=\"([^\"]+)\"/", $xslfo, $matches))
313  {
314  $marginbody = $matches[1];
315  if (preg_match_all("/([^\s]+)/", $marginbody, $matches))
316  {
317  $marginbody_top = $matches[1][0];
318  $marginbody_right = $matches[1][1];
319  $marginbody_bottom = $matches[1][2];
320  $marginbody_left = $matches[1][3];
321  }
322  }
323 
324  $xsl = file_get_contents("./Services/Certificate/xml/fo2xhtml.xsl");
325  if ((strlen($xslfo)) && (strlen($xsl)))
326  {
327  $args = array( '/_xml' => $xslfo, '/_xsl' => $xsl );
328  $xh = xslt_create();
329  $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", NULL, $args, NULL);
330  xslt_error($xh);
331  xslt_free($xh);
332  }
333 
334  $output = preg_replace("/<\?xml[^>]+?>/", "", $output);
335  // dirty hack: the php xslt processing seems not to recognize the following
336  // replacements, so we do it in the code as well
337  $output = str_replace("&#xA0;", "<br />", $output);
338  $output = str_replace("&#160;", "<br />", $output);
339  $form_fields = array(
340  "pageformat" => $pagesize,
341  "pagewidth" => $pagewidth,
342  "pageheight" => $pageheight,
343  "margin_body_top" => $marginbody_top,
344  "margin_body_right" => $marginbody_right,
345  "margin_body_bottom" => $marginbody_bottom,
346  "margin_body_left" => $marginbody_left,
347  "certificate_text" => $output
348  );
349  $this->getAdapter()->addFormFieldsFromObject($form_fields);
350  return $form_fields;
351  }
352 
359  public function processXHTML2FO($form_data, $for_export = FALSE)
360  {
361  $content = "<html><body>".$form_data["certificate_text"]."</body></html>";
362  $content = preg_replace("/<p>(&nbsp;){1,}<\\/p>/", "<p></p>", $content);
363  $content = preg_replace("/<p>(\\s)*?<\\/p>/", "<p></p>", $content);
364 // $content = str_replace("<p>&nbsp;</p>", "<p><br /></p>", $content);
365 // $content = str_replace("<p> </p>", "<p><br /></p>", $content);
366  $content = str_replace("<p></p>", "<p class=\"emptyrow\"></p>", $content);
367  $content = str_replace("&nbsp;", "&#160;", $content);
368  $content = preg_replace("//", "", $content);
369 
370  include_once "./Services/Certificate/classes/class.ilXmlChecker.php";
371  $check = new ilXMLChecker();
372  $check->setXMLContent($content);
373  $check->startParsing();
374  if ($check->hasError())
375  {
376  throw new Exception($this->lng->txt("certificate_not_well_formed"));
377  }
378 
379  $xsl = file_get_contents("./Services/Certificate/xml/xhtml2fo.xsl");
380 
381  // additional font support
382  $xsl = str_replace(
383  'font-family="Helvetica, unifont"',
384  'font-family="'.$GLOBALS['ilSetting']->get('rpc_pdf_font','Helvetica, unifont').'"',
385  $xsl
386  );
387 
388  $args = array( '/_xml' => $content, '/_xsl' => $xsl );
389  $xh = xslt_create();
390  if (strcmp($form_data["pageformat"], "custom") == 0)
391  {
392  $pageheight = $form_data["pageheight"];
393  $pagewidth = $form_data["pagewidth"];
394  }
395  else
396  {
397  $pageformats = $this->getPageFormats();
398  $pageheight = $pageformats[$form_data["pageformat"]]["height"];
399  $pagewidth = $pageformats[$form_data["pageformat"]]["width"];
400  }
401  include_once "./Services/Certificate/classes/class.ilObjCertificateSettingsAccess.php";
403  $params = array(
404  "pageheight" => $pageheight,
405  "pagewidth" => $pagewidth,
406  "backgroundimage" => $backgroundimage,
407  "marginbody" => $form_data["margin_body_top"] . " " . $form_data["margin_body_right"] . " " . $form_data["margin_body_bottom"] . " " . $form_data["margin_body_left"]
408  );
409  $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", NULL, $args, $params);
410  xslt_error($xh);
411  xslt_free($xh);
412  return $output;
413  }
414 
422  private function exchangeCertificateVariables($certificate_text, $insert_tags = array())
423  {
424  if (count($insert_tags) == 0)
425  {
426  $insert_tags = $this->getAdapter()->getCertificateVariablesForPreview();
427 
428  foreach (self::getCustomCertificateFields() as $k => $f)
429  {
430  $insert_tags[$f["ph"]] = $f["name"];
431  }
432  }
433  foreach ($insert_tags as $var => $value)
434  {
435  $certificate_text = str_replace($var, $value, $certificate_text);
436  }
437  return $certificate_text;
438  }
439 
445  public function outCertificate($params, $deliver = TRUE)
446  {
447  global $ilLog;
449  $insert_tags = $this->getAdapter()->getCertificateVariablesForPresentation($params);
450 
451  include_once("./Services/User/classes/class.ilUserDefinedData.php");
452  $cust_data = new ilUserDefinedData($this->getAdapter()->getUserIdForParams($params));
453  $cust_data = $cust_data->getAll();
454  foreach (self::getCustomCertificateFields() as $k => $f)
455  {
456  $insert_tags[$f["ph"]] = $cust_data["f_".$k];
457  }
458 
459  $xslfo = file_get_contents($this->getXSLPath());
460 
461  include_once './Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
462  try
463  {
464  $pdf_base64 = ilRpcClientFactory::factory('RPCTransformationHandler')->ilFO2PDF(
465  $this->exchangeCertificateVariables($xslfo, $insert_tags));
466  if ($deliver)
467  {
468  include_once "./Services/Utilities/classes/class.ilUtil.php";
469  ilUtil::deliverData($pdf_base64->scalar, $this->getAdapter()->getCertificateFilename($params), "application/pdf");
470  }
471  else
472  {
473  return $pdf_base64->scalar;
474  }
475  }
476  catch(XML_RPC2_FaultException $e)
477  {
478  $ilLog->write(__METHOD__.': '.$e->getMessage());
479  return false;
480  }
481  catch(Exception $e)
482  {
483  $ilLog->write(__METHOD__.': '.$e->getMessage());
484  return false;
485  }
486 
488 
489  /*
490  include_once "./Services/Transformation/classes/class.ilFO2PDF.php";
491  $fo2pdf = new ilFO2PDF();
492  $fo2pdf->setFOString($this->exchangeCertificateVariables($xslfo, $insert_tags));
493  $result = $fo2pdf->send();
494  if ($deliver)
495  {
496  include_once "./Services/Utilities/classes/class.ilUtil.php";
497  ilUtil::deliverData($result, $this->getAdapter()->getCertificateFilename($params), "application/pdf");
498  }
499  else
500  {
501  return $result;
502  }
503  */
504  }
505 
509  public function createPreview()
510  {
511  global $ilLog;
512 
514 
515  $xslfo = file_get_contents($this->getXSLPath());
516 
517  include_once './Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
518  try
519  {
520  $pdf_base64 = ilRpcClientFactory::factory('RPCTransformationHandler')->ilFO2PDF(
521  $this->exchangeCertificateVariables($xslfo));
522  ilUtil::deliverData($pdf_base64->scalar, $this->getAdapter()->getCertificateFilename(), "application/pdf");
523 
524  }
525  catch(XML_RPC2_FaultException $e)
526  {
527  $ilLog->write(__METHOD__.': '.$e->getMessage());
528  return false;
529  }
530  catch(Exception $e)
531  {
532  $ilLog->write(__METHOD__.': '.$e->getMessage());
533  return false;
534  }
535 
537 
538  /*
539  include_once "./Services/Transformation/classes/class.ilFO2PDF.php";
540  $fo2pdf = new ilFO2PDF();
541  $fo2pdf->setFOString($this->exchangeCertificateVariables($xslfo));
542  $result = $fo2pdf->send();
543  include_once "./Services/Utilities/classes/class.ilUtil.php";
544  ilUtil::deliverData($result, $this->getAdapter()->getCertificateFilename(), "application/pdf");
545  */
546  }
547 
553  public function saveCertificate($xslfo, $filename = "")
554  {
555  if (!file_exists($this->getAdapter()->getCertificatePath()))
556  {
557  ilUtil::makeDirParents($this->getAdapter()->getCertificatePath());
558  }
559  if (strlen($filename) == 0)
560  {
561  $filename = $this->getXSLPath();
562  }
563  $fh = fopen($filename, "w");
564  fwrite($fh, $xslfo);
565  fclose($fh);
566  }
567 
575  public function uploadBackgroundImage($image_tempfilename)
576  {
577  if (!empty($image_tempfilename))
578  {
579  $convert_filename = $this->getBackgroundImageName();
580  $imagepath = $this->getAdapter()->getCertificatePath();
581  if (!file_exists($imagepath))
582  {
583  ilUtil::makeDirParents($imagepath);
584  }
585  // upload the file
587  $image_tempfilename,
588  basename($this->getBackgroundImageTempfilePath()),
590  )) {
591  return FALSE;
592  }
593  // convert the uploaded file to JPEG
596  if (!file_exists($this->getBackgroundImagePath()))
597  {
598  // something went wrong converting the file. use the original file and hope, that PDF can work with it
599  if (!ilUtil::moveUploadedFile($this->getBackgroundImageTempfilePath(), $convert_filename, $this->getBackgroundImagePath()))
600  {
601  return FALSE;
602  }
603  }
604  unlink($this->getBackgroundImageTempfilePath());
605  if (file_exists($this->getBackgroundImagePath()) && (filesize($this->getBackgroundImagePath()) > 0))
606  {
607  return TRUE;
608  }
609  }
610  return FALSE;
611  }
612 
618  public function hasBackgroundImage()
619  {
620  if (file_exists($this->getBackgroundImagePath()) && (filesize($this->getBackgroundImagePath()) > 0))
621  {
622  return TRUE;
623  }
624  else
625  {
626  return FALSE;
627  }
628  }
629 
635  public function isComplete()
636  {
637  if(self::isActive())
638  {
639  $obj_id = $this->getAdapter()->getCertificateID();
640  if($obj_id && !self::isObjectActive($obj_id))
641  {
642  return FALSE;
643  }
644  if (file_exists($this->getAdapter()->getCertificatePath()))
645  {
646  if (file_exists($this->getXSLPath()) && (filesize($this->getXSLPath()) > 0))
647  {
648  return TRUE;
649  }
650  }
651  }
652  return FALSE;
653  }
654 
662  {
663  if (is_object($adapter) && method_exists($adapter, "getCertificatePath"))
664  {
665  if(self::isActive())
666  {
667  $obj_id = $adapter->getCertificateID();
668  if($obj_id && !self::isObjectActive($obj_id))
669  {
670  return FALSE;
671  }
672 
673  $certificatepath = $adapter->getCertificatePath();
674  if (file_exists($certificatepath))
675  {
676  $xslpath = $adapter->getCertificatePath() . ilCertificate::_getXSLName();
677  if (file_exists($xslpath) && (filesize($xslpath) > 0))
678  {
679  return TRUE;
680  }
681  }
682  }
683  }
684  return FALSE;
685  }
686 
692  public function getPageFormats()
693  {
694  return array(
695  "a4" => array(
696  "name" => $this->lng->txt("certificate_a4"), // (297 mm x 210 mm)
697  "value" => "a4",
698  "width" => "210mm",
699  "height" => "297mm"
700  ),
701  "a4landscape" => array(
702  "name" => $this->lng->txt("certificate_a4_landscape"), // (210 mm x 297 mm)",
703  "value" => "a4landscape",
704  "width" => "297mm",
705  "height" => "210mm"
706  ),
707  "a5" => array(
708  "name" => $this->lng->txt("certificate_a5"), // (210 mm x 148.5 mm)
709  "value" => "a5",
710  "width" => "148mm",
711  "height" => "210mm"
712  ),
713  "a5landscape" => array(
714  "name" => $this->lng->txt("certificate_a5_landscape"), // (148.5 mm x 210 mm)
715  "value" => "a5landscape",
716  "width" => "210mm",
717  "height" => "148mm"
718  ),
719  "letter" => array(
720  "name" => $this->lng->txt("certificate_letter"), // (11 inch x 8.5 inch)
721  "value" => "letter",
722  "width" => "8.5in",
723  "height" => "11in"
724  ),
725  "letterlandscape" => array(
726  "name" => $this->lng->txt("certificate_letter_landscape"), // (8.5 inch x 11 inch)
727  "value" => "letterlandscape",
728  "width" => "11in",
729  "height" => "8.5in"
730  ),
731  "custom" => array(
732  "name" => $this->lng->txt("certificate_custom"),
733  "value" => "custom",
734  "width" => "",
735  "height" => ""
736  )
737  );
738  }
739 
743  public function deliverExportFileXML()
744  {
745  include_once "./Services/Utilities/classes/class.ilUtil.php";
746  $exportpath = $this->createArchiveDirectory();
747  ilUtil::makeDir($exportpath);
748  $xsl = file_get_contents($this->getXSLPath());
749  $xslexport = str_replace($this->getAdapter()->getCertificatePath(), "", $xsl);
750  // save export xsl file
751  $this->saveCertificate($xslexport, $exportpath . $this->getXSLName());
752  // save background image
753  if ($this->hasBackgroundImage())
754  {
755  copy($this->getBackgroundImagePath(), $exportpath . $this->getBackgroundImageName());
756  }
757  else
758  {
759  include_once "./Services/Certificate/classes/class.ilObjCertificateSettingsAccess.php";
761  {
763  }
764  }
765  $zipfile = time() . "__" . IL_INST_ID . "__" . $this->getAdapter()->getAdapterType() . "__" . $this->getAdapter()->getCertificateId() . "__certificate.zip";
766  ilUtil::zip($exportpath, $this->getAdapter()->getCertificatePath() . $zipfile);
767  ilUtil::delDir($exportpath);
768  ilUtil::deliverFile($this->getAdapter()->getCertificatePath() . $zipfile, $zipfile, "application/zip");
769  }
770 
776  public function importCertificate($zipfile, $filename)
777  {
778  include_once "./Services/Utilities/classes/class.ilUtil.php";
779  $importpath = $this->createArchiveDirectory();
780  if (!ilUtil::moveUploadedFile($zipfile, $filename, $importpath . $filename))
781  {
782  ilUtil::delDir($importpath);
783  return FALSE;
784  }
785  ilUtil::unzip($importpath . $filename, TRUE);
786  $subdir = str_replace(".zip", "", strtolower($filename)) . "/";
787  $copydir = "";
788  if (is_dir($importpath . $subdir))
789  {
790  $dirinfo = ilUtil::getDir($importpath . $subdir);
791  $copydir = $importpath . $subdir;
792  }
793  else
794  {
795  $dirinfo = ilUtil::getDir($importpath);
796  $copydir = $importpath;
797  }
798  $xmlfiles = 0;
799  $otherfiles = 0;
800  foreach ($dirinfo as $file)
801  {
802  if (strcmp($file["type"], "file") == 0)
803  {
804  if (strpos($file["entry"], ".xml") !== FALSE)
805  {
806  $xmlfiles++;
807  }
808  else if (strpos($file["entry"], ".zip") !== FALSE)
809  {
810  }
811  else
812  {
813  $otherfiles++;
814  }
815  }
816  }
817  // if one XML file is in the archive, we try to import it
818  if ($xmlfiles == 1)
819  {
820  foreach ($dirinfo as $file)
821  {
822  if (strcmp($file["type"], "file") == 0)
823  {
824  if (strpos($file["entry"], ".xml") !== FALSE)
825  {
826  $xsl = file_get_contents($copydir . $file["entry"]);
827  // as long as we cannot make RPC calls in a given directory, we have
828  // to add the complete path to every url
829  $xsl = preg_replace("/url\([']{0,1}(.*?)[']{0,1}\)/", "url(" . $this->getAdapter()->getCertificatePath() . "\${1})", $xsl);
830  $this->saveCertificate($xsl);
831  }
832  else if (strpos($file["entry"], ".zip") !== FALSE)
833  {
834  }
835  else
836  {
837  @copy($copydir . $file["entry"], $this->getAdapter()->getCertificatePath() . $file["entry"]);
838  if (strcmp($this->getBackgroundImagePath(), $this->getAdapter()->getCertificatePath() . $file["entry"]) == 0)
839  {
840  // upload of the background image, create a preview
842  }
843  }
844  }
845  }
846  }
847  else
848  {
849  ilUtil::delDir($importpath);
850  return FALSE;
851  }
852  ilUtil::delDir($importpath);
853  return TRUE;
854  }
855 
861  public function getAdapter()
862  {
863  return $this->adapter;
864  }
865 
871  public function setAdapter($adapter)
872  {
873  $this->adapter =& $adapter;
874  }
875 
876  /***************************************
877  /* BULK CERTIFICATE PROCESSING METHODS *
878  /***************************************
879 
885  public function createArchiveDirectory()
886  {
887  $dir = $this->getAdapter()->getCertificatePath() . time() . "__" . IL_INST_ID . "__" . $this->getAdapter()->getAdapterType() . "__" . $this->getAdapter()->getCertificateId() . "__certificate/";
888  include_once "./Services/Utilities/classes/class.ilUtil.php";
889  ilUtil::makeDirParents($dir);
890  return $dir;
891  }
892 
900  public function addPDFtoArchiveDirectory($pdfdata, $dir, $filename)
901  {
902  $fh = fopen($dir . $filename, "wb");
903  fwrite($fh, $pdfdata);
904  fclose($fh);
905  }
906 
914  public function zipCertificatesInArchiveDirectory($dir, $deliver = TRUE)
915  {
916  $zipfile = time() . "__" . IL_INST_ID . "__" . $this->getAdapter()->getAdapterType() . "__" . $this->getAdapter()->getCertificateId() . "__certificates.zip";
917  ilUtil::zip($dir, $this->getAdapter()->getCertificatePath() . $zipfile);
918  ilUtil::delDir($dir);
919  if ($deliver)
920  {
921  ilUtil::deliverFile($this->getAdapter()->getCertificatePath() . $zipfile, $zipfile, "application/zip");
922  }
923  return $this->getAdapter()->getCertificatePath() . $zipfile;
924  }
925 
926  public static function isActive()
927  {
928  if(self::$is_active === null)
929  {
930  // basic admin setting active?
931  $certificate_active = new ilSetting("certificate");
932  $certificate_active = (bool)$certificate_active->get("active");
933 
934  // java/rtpc-server active?
935  if($certificate_active)
936  {
937  include_once './Services/WebServices/RPC/classes/class.ilRPCServerSettings.php';
938  $certificate_active = ilRPCServerSettings::getInstance()->isEnabled();
939  }
940 
941  self::$is_active = (bool)$certificate_active;
942  }
943  return self::$is_active;
944  }
945 
946  public static function isObjectActive($a_obj_id)
947  {
948  $chk = self::areObjectsActive(array($a_obj_id));
949  return $chk[$a_obj_id];
950  }
951  public static function areObjectsActive(array $a_obj_ids)
952  {
953  global $ilDB;
954 
955  $all = array();
956  foreach($a_obj_ids as $id)
957  {
958  $all[$id] = false;
959  }
960 
961  $set = $ilDB->query("SELECT obj_id FROM il_certificate".
962  " WHERE ".$ilDB->in("obj_id", $a_obj_ids, "", "integer"));
963  while($row = $ilDB->fetchAssoc($set))
964  {
965  $all[$row["obj_id"]] = true;
966  }
967  return $all;
968  }
969 
970  public function readActive()
971  {
972  global $ilDB;
973 
974  $obj_id = $this->adapter->getCertificateID();
975  $set = $ilDB->query("SELECT obj_id FROM il_certificate".
976  " WHERE obj_id = ".$ilDB->quote($obj_id, "integer"));
977  return $ilDB->numRows($set);
978  }
979 
980  public function writeActive($a_value)
981  {
982  global $ilDB;
983 
984  $obj_id = $this->adapter->getCertificateID();
985 
986  if((bool)$a_value)
987  {
988  $ilDB->replace("il_certificate",
989  array("obj_id"=>array("integer", $obj_id)),
990  array());
991  }
992  else
993  {
994  $ilDB->manipulate("DELETE FROM il_certificate".
995  " WHERE obj_id = ".$ilDB->quote($obj_id, "integer"));
996  }
997  }
998 
1004  public static function _goto($ref_id)
1005  {
1006  global $ilCtrl;
1007  include_once "./Services/Object/classes/class.ilObject.php";
1008  $type = ilObject::_lookupType($ref_id, true);
1009  switch ($type)
1010  {
1011  case 'sahs':
1012  $cmd_link = "ilias.php?baseClass=ilSAHSPresentationGUI&ref_id=".$ref_id.
1013  "&cmd=downloadCertificate";
1014  ilUtil::redirect($cmd_link);
1015  break;
1016  case 'tst':
1017  default:
1018  $ilCtrl->redirectByClass("ilrepositorygui", "frameset");
1019  break;
1020  }
1021  }
1022 
1026  static function getCustomCertificateFields()
1027  {
1028  include_once("./Services/User/classes/class.ilUserDefinedFields.php");
1029  $user_field_definitions = ilUserDefinedFields::_getInstance();
1030  $fds = $user_field_definitions->getDefinitions();
1031  $fields = array();
1032  foreach ($fds as $f)
1033  {
1034  if ($f["certificate"])
1035  {
1036  $fields[$f["field_id"]] = array("name" => $f["field_name"],
1037  "ph" => "[#".str_replace(" ", "_", strtoupper($f["field_name"]))."]");
1038  }
1039  }
1040 
1041  return $fields;
1042  }
1043 
1047  public function getExchangeContent()
1048  {
1049  if(!file_exists($this->getXSLPath()))
1050  {
1051  return '';
1052  }
1053 
1054  $output = '';
1055  $xsl_file_content = file_get_contents($this->getXSLPath());
1056  $xsl = file_get_contents("./Services/Certificate/xml/fo2xhtml.xsl");
1057 
1058  if((strlen($xsl_file_content)) && (strlen($xsl)))
1059  {
1060  $args = array('/_xml' => $xsl_file_content, '/_xsl' => $xsl);
1061  $xh = xslt_create();
1062  $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", NULL, $args, NULL);
1063  xslt_error($xh);
1064  xslt_free($xh);
1065  }
1066 
1067  $output = preg_replace("/<\?xml[^>]+?>/", "", $output);
1068  // dirty hack: the php xslt processing seems not to recognize the following
1069  // replacements, so we do it in the code as well
1070  $output = str_replace("&#xA0;", "<br />", $output);
1071  $output = str_replace("&#160;", "<br />", $output);
1072 
1073  return $output;
1074  }
1075 
1076  public function outCertificateWithGivenContentAndVariables($content, $insert_tags)
1077  {
1078  global $ilLog;
1079 
1080  ilDatePresentation::setUseRelativeDates(false);
1081 
1082  $form_fields = $this->getFormFieldsFromFO();
1083  $form_fields['certificate_text'] = $content;
1084  $xslfo = $this->processXHTML2FO($form_fields);
1085 
1086  $content = $this->exchangeCertificateVariables($xslfo, $insert_tags);
1087  $content = str_replace('[BR]', "<fo:block/>", $content);
1088 
1089  include_once './Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
1090  try
1091  {
1092  $pdf_base64 = ilRpcClientFactory::factory('RPCTransformationHandler')->ilFO2PDF($content);
1093  include_once "./Services/Utilities/classes/class.ilUtil.php";
1094  ilUtil::deliverData($pdf_base64->scalar, $this->getAdapter()->getCertificateFilename(array()), "application/pdf");
1095  }
1096  catch(XML_RPC2_FaultException $e)
1097  {
1098  $ilLog->write(__METHOD__.': '.$e->getMessage());
1099  return false;
1100  }
1101  catch(Exception $e)
1102  {
1103  $ilLog->write(__METHOD__.': '.$e->getMessage());
1104  return false;
1105  }
1106 
1107  ilDatePresentation::setUseRelativeDates(true);
1108  }
1109 }
1110 
1111 ?>
xslt_create()
static makeDirParents($a_dir)
Create a new directory and all parent directories.
ILIAS Setting Class.
static deliverData($a_data, $a_filename, $mime="application/octet-stream", $charset="")
deliver data for download via browser.
print $file
processXHTML2FO($form_data, $for_export=FALSE)
Convert the certificate text to XSL-FO using XSL transformation.
deleteCertificate()
Deletes the certificate and all it&#39;s data.
outCertificate($params, $deliver=TRUE)
Creates a PDF certificate.
Class ilUserDefinedData.
$result
createPreview()
Creates a PDF preview of the XSL-FO certificate.
getFormFieldsFromFO()
Convert the XSL-FO to the certificate text and the form settings using XSL transformation.
xslt_free(&$proc)
getBackgroundImagePath()
Returns the filesystem path of the background image.
getBackgroundImagePathWeb()
Returns the web path of the background image.
static unzip($a_file, $overwrite=false, $a_flat=false)
unzip file
_isComplete($adapter)
Checks the status of the certificate.
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
static setUseRelativeDates($a_status)
set use relative dates
deleteBackgroundImage()
Deletes the background image of a certificate.
static getBackgroundImageName()
Returns the filename of the background image.
uploadBackgroundImage($image_tempfilename)
Uploads a background image for the certificate.
global $ilCtrl
Definition: ilias.php:18
hasBackgroundImage()
Checks for the background image of the certificate.
getBackgroundImageThumbPath()
Returns the filesystem path of the background image thumbnail.
xslt_error(&$proc)
saveCertificate($xslfo, $filename="")
Saves the XSL-FO code to a file.
getAdapter()
Gets the adapter.
getPageFormats()
Retrieves predefined page formats.
getXSLPath()
Returns the filesystem path of the XSL-FO file.
const ILIAS_ABSOLUTE_PATH
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
getBackgroundImageTempfilePath()
Returns the filesystem path of the background image temp file during upload.
redirection script todo: (a better solution should control the processing via a xml file) ...
XML checker.
static deliverFile($a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
static removeTrailingPathSeparators($path)
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
__construct($adapter)
ilCertificate constructor
static hasBackgroundImage()
Returns wheather or not a default background image exists.
$filename
Definition: buildRTE.php:89
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
importCertificate($zipfile, $filename)
Reads an import ZIP file and creates a certificate of it.
isComplete()
Checks the status of the certificate.
static factory($a_package)
Create an XML_RPC2 client instance.
static getBackgroundImagePath()
Returns the filesystem path of the background image.
setAdapter($adapter)
Sets the adapter.
getBackgroundImageName()
Returns the filename of the background image.
static convertImage($a_from, $a_to, $a_target_format="", $a_geometry="", $a_background_color="")
convert image
deliverExportFileXML()
Builds an export file in ZIP format and delivers it.
getBackgroundImageThumbPathWeb()
Returns the web path of the background image thumbnail.
Create PDF certificates.
exchangeCertificateVariables($certificate_text, $insert_tags=array())
Exchanges the variables in the certificate text with given values.
static _getXSLName()
Returns the filename of the XSL-FO file.
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
cloneCertificate($newObject)
Clone the certificate for another test object.
$params
Definition: example_049.php:96
getXSLName()
Returns the filename of the XSL-FO file.