ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTestCertificate.php
Go to the documentation of this file.
1 <?php
2  /*
3  +----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +----------------------------------------------------------------------------+
22 */
23 
35 {
43  var $object;
51  var $ctrl;
59  var $tree;
67  var $ilias;
68 
76  var $tpl;
77 
85  var $lng;
86 
96  function ilTestCertificate(&$a_object)
97  {
98  global $lng, $tpl, $ilCtrl, $ilias, $tree;
99 
100  $this->lng =& $lng;
101  $this->tpl =& $tpl;
102  $this->ctrl =& $ilCtrl;
103  $this->ilias =& $ilias;
104  $this->object =& $a_object;
105  $this->tree =& $tree;
106  }
107 
117  {
118  return CLIENT_WEB_DIR . "/assessment/certificates/" . $this->object->getId() . "/";
119  }
120 
130  {
131  return CLIENT_WEB_DIR . "/assessment/certificates/" . $this->object->getId() . "/" . $this->getBackgroundImageName();
132  }
133 
143  {
144  return "background.jpg";
145  }
146 
156  {
157  return CLIENT_WEB_DIR . "/assessment/certificates/" . $this->object->getId() . "/" . $this->getBackgroundImageName() . ".thumb.jpg";
158  }
159 
169  {
170  return CLIENT_WEB_DIR . "/assessment/certificates/" . $this->object->getId() . "/background_upload";
171  }
172 
181  function getXSLPath()
182  {
183  return CLIENT_WEB_DIR . "/assessment/certificates/" . $this->object->getId() . "/" . $this->getXSLName();
184  }
185 
194  function getXSLName()
195  {
196  return "certificate.xml";
197  }
198 
208  {
209  include_once "./Services/Utilities/classes/class.ilUtil.php";
210  $webdir = ilUtil::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/assessment/certificates/" . $this->object->getId() . "/" . $this->getBackgroundImageName();
212  }
213 
223  {
224  global $ilLog;
225  $result = TRUE;
226  if (file_exists($this->getBackgroundImageThumbPath()))
227  {
228  $ilLog->write("delete " . $this->getBackgroundImageThumbPath());
229  $result = $result & unlink($this->getBackgroundImageThumbPath());
230  }
231  if (file_exists($this->getBackgroundImagePath()))
232  {
233  $ilLog->write("delete " . $this->getBackgroundImagePath());
234  $result = $result & unlink($this->getBackgroundImagePath());
235  }
236  if (file_exists($this->getBackgroundImageTempfilePath()))
237  {
238  $ilLog->write("delete " . $this->getBackgroundImageTempfilePath());
239  $result = $result & unlink($this->getBackgroundImageTempfilePath());
240  }
241  return $result;
242  }
243 
251  function deleteCertificate()
252  {
253  global $ilLog;
254  if (file_exists($this->getCertificatePath()))
255  {
256  include_once "./Services/Utilities/classes/class.ilUtil.php";
258  }
259  }
260 
270  function checkCertificateInput($form_fields)
271  {
272  // 1. check the required fields
273  if ((strlen($form_fields["padding_top"]) == 0) ||
274  (strlen($form_fields["margin_body_top"]) == 0) ||
275  (strlen($form_fields["margin_body_right"]) == 0) ||
276  (strlen($form_fields["margin_body_bottom"]) == 0) ||
277  (strlen($form_fields["margin_body_left"]) == 0) ||
278  (strlen($form_fields["certificate_text"]) == 0))
279  {
280  return $this->lng->txt("fill_out_all_required_fields");
281  }
282 
283  $unitexpression = "^([\d\.]+)(pt|pc|px|em|mm|cm|in){0,1}\$";
284  if (!preg_match("/$unitexpression/", $form_fields["padding_top"], $matches))
285  {
286  return $this->lng->txt("certificate_wrong_unit");
287  }
288  if (strcmp($form_fields["pageformat"], "custom") == 0)
289  {
290  if (!preg_match("/$unitexpression/", $form_fields["pageheight"], $matches))
291  {
292  return $this->lng->txt("certificate_wrong_unit");
293  }
294  if (!preg_match("/$unitexpression/", $form_fields["pagewidth"], $matches))
295  {
296  return $this->lng->txt("certificate_wrong_unit");
297  }
298  }
299  if (!preg_match("/$unitexpression/", $form_fields["margin_body_top"], $matches))
300  {
301  return $this->lng->txt("certificate_wrong_unit");
302  }
303  if (!preg_match("/$unitexpression/", $form_fields["margin_body_right"], $matches))
304  {
305  return $this->lng->txt("certificate_wrong_unit");
306  }
307  if (!preg_match("/$unitexpression/", $form_fields["margin_body_bottom"], $matches))
308  {
309  return $this->lng->txt("certificate_wrong_unit");
310  }
311  if (!preg_match("/$unitexpression/", $form_fields["margin_body_left"], $matches))
312  {
313  return $this->lng->txt("certificate_wrong_unit");
314  }
315  if (strlen($form_fields["certificate_text"]) == 0)
316  {
317  return $this->lng->txt("certificate_missing_text");
318  }
319  if (strlen($form_fields["certificate_text"]) > 0)
320  {
321  include_once "class.ilXMLChecker.php";
322  $check = new ilXMLChecker();
323  $check->setXMLContent(str_replace("&nbsp;", " ", "<html>" . $form_fields["certificate_text"] . "</html>"));
324  $check->startParsing();
325  if ($check->hasError())
326  {
327  return $this->lng->txt("certificate_not_well_formed");
328  }
329  }
330  return TRUE;
331  }
332 
340  function processFO2XHTML()
341  {
342  if (file_exists($this->getXSLPath()))
343  {
344  $xslfo = file_get_contents($this->getXSLPath());
345  }
346  // retrieve form information (using a dirty way with regular expressions)
347  $pagewidth = "21cm";
348  if (preg_match("/page-width\=\"([^\"]+)\"/", $xslfo, $matches))
349  {
350  $pagewidth = $matches[1];
351  }
352  $pageheight = "29.7cm";
353  if (preg_match("/page-height\=\"([^\"]+)\"/", $xslfo, $matches))
354  {
355  $pageheight = $matches[1];
356  }
357  $pagesize = "custom";
358  if (((strcmp($pageheight, "29.7cm") == 0) || (strcmp($pageheight, "297mm") == 0)) && ((strcmp($pagewidth, "21cm") == 0) || (strcmp($pagewidth, "210mm") == 0)))
359  {
360  $pagesize = "a4";
361  }
362  else if (((strcmp($pagewidth, "29.7cm") == 0) || (strcmp($pagewidth, "297mm") == 0)) && ((strcmp($pageheight, "21cm") == 0) || (strcmp($pageheight, "210mm") == 0)))
363  {
364  $pagesize = "a4landscape";
365  }
366  else if (((strcmp($pageheight, "21cm") == 0) || (strcmp($pageheight, "210mm") == 0)) && ((strcmp($pagewidth, "14.8cm") == 0) || (strcmp($pagewidth, "148mm") == 0)))
367  {
368  $pagesize = "a5";
369  }
370  else if (((strcmp($pagewidth, "21cm") == 0) || (strcmp($pagewidth, "210mm") == 0)) && ((strcmp($pageheight, "14.8cm") == 0) || (strcmp($pageheight, "148mm") == 0)))
371  {
372  $pagesize = "a5landscape";
373  }
374  else if (((strcmp($pageheight, "11in") == 0)) && ((strcmp($pagewidth, "8.5in") == 0)))
375  {
376  $pagesize = "letter";
377  }
378  else if (((strcmp($pagewidth, "11in") == 0)) && ((strcmp($pageheight, "8.5in") == 0)))
379  {
380  $pagesize = "letterlandscape";
381  }
382 
383  /* only needed for upload of xsl-fo to convert existing background image
384  $backgroundimage = "";
385  if (preg_match("/background-image\=\"url\([']{0,1}([^\)]+)[']{0,1}\)/", $xslfo, $matches))
386  {
387  $backgroundimage = $matches[1];
388  echo $backgroundimage;
389  }
390  */
391  $paddingtop = "0cm";
392  if (preg_match("/padding-top\=\"([^\"]+)\"/", $xslfo, $matches))
393  {
394  $paddingtop = $matches[1];
395  }
396  $marginbody_top = "0cm";
397  $marginbody_right = "2cm";
398  $marginbody_bottom = "0cm";
399  $marginbody_left = "2cm";
400  if (preg_match("/fo:flow[^>]*margin\=\"([^\"]+)\"/", $xslfo, $matches))
401  {
402  $marginbody = $matches[1];
403  if (preg_match_all("/([^\s]+)/", $marginbody, $matches))
404  {
405  $marginbody_top = $matches[1][0];
406  $marginbody_right = $matches[1][1];
407  $marginbody_bottom = $matches[1][2];
408  $marginbody_left = $matches[1][3];
409  }
410  }
411 
412  $xsl = file_get_contents("./Modules/Test/xml/fo2xhtml.xsl");
413  if ((strlen($xslfo)) && (strlen($xsl)))
414  {
415  $args = array( '/_xml' => $xslfo, '/_xsl' => $xsl );
416  $xh = xslt_create();
417  $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", NULL, $args, NULL);
418  xslt_error($xh);
419  xslt_free($xh);
420  }
421 
422  $output = preg_replace("/<\?xml[^>]+?>/", "", $output);
423  // dirty hack: the php xslt processing seems not to recognize the following
424  // replacements, so we do it in the code as well
425  $output = str_replace("&#xA0;", "<br />", $output);
426  $output = str_replace("&#160;", "<br />", $output);
427  return array(
428  "pageformat" => $pagesize,
429  "pagewidth" => $pagewidth,
430  "pageheight" => $pageheight,
431  "padding_top" => $paddingtop,
432  "margin_body_top" => $marginbody_top,
433  "margin_body_right" => $marginbody_right,
434  "margin_body_bottom" => $marginbody_bottom,
435  "margin_body_left" => $marginbody_left,
436  "certificate_text" => $output,
437  "certificate_visibility" => $this->object->getCertificateVisibility()
438  );
439  }
440 
450  function processXHTML2FO($form_data, $for_export = FALSE)
451  {
452  $content = "<html><body>".$form_data["certificate_text"]."</body></html>";
453  $content = str_replace("<p>&nbsp;</p>", "<p><br /></p>", $content);
454  $content = str_replace("&nbsp;", " ", $content);
455  $xsl = file_get_contents("./Modules/Test/xml/xhtml2fo.xsl");
456  $args = array( '/_xml' => $content, '/_xsl' => $xsl );
457  $xh = xslt_create();
458  if (strcmp($form_data["pageformat"], "custom") == 0)
459  {
460  $pageheight = $form_data["pageheight"];
461  $pagewidth = $form_data["pagewidth"];
462  }
463  else
464  {
465  $pageformats = $this->getPageFormats();
466  $pageheight = $pageformats[$form_data["pageformat"]]["height"];
467  $pagewidth = $pageformats[$form_data["pageformat"]]["width"];
468  }
469  $backgroundimage = $this->hasBackgroundImage() ? $this->getBackgroundImagePath() : "";
470  $params = array(
471  "pageheight" => $pageheight,
472  "pagewidth" => $pagewidth,
473  "backgroundimage" => $backgroundimage,
474  "marginbody" => $form_data["margin_body_top"] . " " . $form_data["margin_body_right"] . " " . $form_data["margin_body_bottom"] . " " . $form_data["margin_body_left"],
475  "paddingtop" => $form_data["padding_top"]
476  );
477  $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", NULL, $args, $params);
478  xslt_error($xh);
479  xslt_free($xh);
480  return $output;
481  }
482 
491  function saveCertificateVisibility($a_value)
492  {
493  $this->object->saveCertificateVisibility($a_value);
494  }
495 
506  function exchangeCertificateVariables($certificate_text, $user_data = array())
507  {
508  if (count($user_data) == 0)
509  {
510  include_once "./classes/class.ilFormat.php";
511  $user_data = array(
512  "[USER_FULLNAME]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_fullname")),
513  "[USER_FIRSTNAME]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_firstname")),
514  "[USER_LASTNAME]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_lastname")),
515  "[USER_TITLE]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_title")),
516  "[USER_INSTITUTION]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_institution")),
517  "[USER_DEPARTMENT]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_department")),
518  "[USER_STREET]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_street")),
519  "[USER_CITY]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_city")),
520  "[USER_ZIPCODE]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_zipcode")),
521  "[USER_COUNTRY]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_user_country")),
522  "[RESULT_PASSED]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_result_passed")),
523  "[RESULT_POINTS]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_result_points")),
524  "[RESULT_PERCENT]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_result_percent")),
525  "[MAX_POINTS]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_max_points")),
526  "[RESULT_MARK_SHORT]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_result_mark_short")),
527  "[RESULT_MARK_LONG]" => ilUtil::prepareFormOutput($this->lng->txt("certificate_var_result_mark_long")),
528  "[TEST_TITLE]" => ilUtil::prepareFormOutput($this->object->getTitle()),
529  "[DATE]" => ilFormat::formatDate(ilFormat::unixtimestamp2datetime(time()), "date", FALSE, FALSE),
530  "[DATETIME]" => ilFormat::formatDate(ilFormat::unixtimestamp2datetime(time()), "datetime", TRUE, FALSE)
531  );
532  }
533  foreach ($user_data as $var => $value)
534  {
535  $certificate_text = str_replace($var, $value, $certificate_text);
536  }
537  return $certificate_text;
538  }
539 
541  {
542  $dir = $this->getCertificatePath() . time() . "__" . IL_INST_ID . "__" . "test" . "__" . $this->object->getId() . "__certificate/";
543  include_once "./Services/Utilities/classes/class.ilUtil.php";
545  return $dir;
546  }
547 
549  {
550  $fh = fopen($dir . $filename, "wb");
551  fwrite($fh, $pdfdata);
552  fclose($fh);
553  }
554 
562  function outCertificates($userfilter = "", $passedonly = FALSE)
563  {
564  global $ilUser;
565 
566  include_once "./Services/Utilities/classes/class.ilUtil.php";
567  $archive_dir = $this->createArchiveDirectory();
568  $total_users = array();
569  $total_users =& $this->object->evalTotalPersonsArray();
570  if (count($total_users))
571  {
572  foreach ($total_users as $active_id => $name)
573  {
574  $user_id = $this->object->_getUserIdFromActiveId($active_id);
575  $pdf = $this->outCertificate($active_id, "", FALSE, $userfilter, $passedonly);
576  if (strlen($pdf))
577  {
578  $this->addPDFtoArchiveDirectory($pdf, $archive_dir, $user_id . "_" . str_replace(" ", "_", ilUtil::getASCIIFilename($name)) . ".pdf");
579  }
580  }
581  $zipfile = time() . "__" . IL_INST_ID . "__" . "test" . "__" . $this->object->getId() . "__certificates.zip";
582  ilUtil::zip($archive_dir, $this->getCertificatePath() . $zipfile);
583  ilUtil::delDir($archive_dir);
584  ilUtil::deliverFile($this->getCertificatePath() . $zipfile, $zipfile, "application/zip");
585  }
586  }
587 
595  function outCertificate($active_id, $pass, $deliver = TRUE, $userfilter = "", $passedonly = FALSE)
596  {
597  if (strlen($pass))
598  {
599  $result_array =& $this->object->getTestResult($active_id, $pass);
600  }
601  else
602  {
603  $result_array =& $this->object->getTestResult($active_id);
604  }
605  if (($passedonly) && ($result_array["test"]["passed"] == FALSE)) return "";
606  $passed = $result_array["test"]["passed"] ? $this->lng->txt("certificate_passed") : $this->lng->txt("certificate_failed");
607  if (!$result_array["test"]["total_max_points"])
608  {
609  $percentage = 0;
610  }
611  else
612  {
613  $percentage = ($result_array["test"]["total_reached_points"]/$result_array["test"]["total_max_points"])*100;
614  }
615  $mark_obj = $this->object->mark_schema->getMatchingMark($percentage);
616  $user_id = $this->object->_getUserIdFromActiveId($active_id);
617  include_once './Services/User/classes/class.ilObjUser.php';
618  $user_data = ilObjUser::_lookupFields($user_id);
619  if (strlen($userfilter))
620  {
621  if (!@preg_match("/$userfilter/i", $user_data["lastname"] . ", " . $user_data["firstname"] . " " . $user_data["title"]))
622  {
623  return "";
624  }
625  }
626  include_once "./classes/class.ilFormat.php";
627  $user_data = array(
628  "[USER_FULLNAME]" => ilUtil::prepareFormOutput(trim($user_data["title"] . " " . $user_data["firstname"] . " " . $user_data["lastname"])),
629  "[USER_FIRSTNAME]" => ilUtil::prepareFormOutput($user_data["firstname"]),
630  "[USER_LASTNAME]" => ilUtil::prepareFormOutput($user_data["lastname"]),
631  "[USER_TITLE]" => ilUtil::prepareFormOutput($user_data["title"]),
632  "[USER_INSTITUTION]" => ilUtil::prepareFormOutput($user_data["institution"]),
633  "[USER_DEPARTMENT]" => ilUtil::prepareFormOutput($user_data["department"]),
634  "[USER_STREET]" => ilUtil::prepareFormOutput($user_data["street"]),
635  "[USER_CITY]" => ilUtil::prepareFormOutput($user_data["city"]),
636  "[USER_ZIPCODE]" => ilUtil::prepareFormOutput($user_data["zipcode"]),
637  "[USER_COUNTRY]" => ilUtil::prepareFormOutput($user_data["country"]),
638  "[RESULT_PASSED]" => ilUtil::prepareFormOutput($passed),
639  "[RESULT_POINTS]" => ilUtil::prepareFormOutput($result_array["test"]["total_reached_points"]),
640  "[RESULT_PERCENT]" => sprintf("%2.2f", $percentage) . "%",
641  "[MAX_POINTS]" => ilUtil::prepareFormOutput($result_array["test"]["total_max_points"]),
642  "[RESULT_MARK_SHORT]" => ilUtil::prepareFormOutput($mark_obj->getShortName()),
643  "[RESULT_MARK_LONG]" => ilUtil::prepareFormOutput($mark_obj->getOfficialName()),
644  "[TEST_TITLE]" => ilUtil::prepareFormOutput($this->object->getTitle()),
645  "[DATE]" => ilFormat::formatDate(ilFormat::unixtimestamp2datetime(time()), "date", FALSE, FALSE),
646  "[DATETIME]" => ilFormat::formatDate(ilFormat::unixtimestamp2datetime(time()), "datetime", TRUE, FALSE)
647  );
648  $xslfo = file_get_contents($this->getXSLPath());
649  include_once "./Services/Transformation/classes/class.ilFO2PDF.php";
650  $fo2pdf = new ilFO2PDF();
651  $fo2pdf->setFOString($this->exchangeCertificateVariables($xslfo, $user_data));
652  $result = $fo2pdf->send();
653  if ($deliver)
654  {
655  include_once "./Services/Utilities/classes/class.ilUtil.php";
656  ilUtil::deliverData($result, "certificate.pdf", "application/pdf");
657  }
658  else
659  {
660  return $result;
661  }
662  }
663 
671  function createPreview()
672  {
673  $xslfo = file_get_contents($this->getXSLPath());
674  include_once "./Services/Transformation/classes/class.ilFO2PDF.php";
675  $fo2pdf = new ilFO2PDF();
676  $fo2pdf->setFOString($this->exchangeCertificateVariables($xslfo));
677  $result = $fo2pdf->send();
678  include_once "./Services/Utilities/classes/class.ilUtil.php";
679  ilUtil::deliverData($result, "certificate.pdf", "application/pdf");
680  }
681 
690  function saveCertificate($xslfo, $filename = "")
691  {
692  if (!file_exists($this->getCertificatePath()))
693  {
695  }
696  if (strlen($filename) == 0)
697  {
698  $filename = $this->getXSLPath();
699  }
700  $fh = fopen($filename, "w");
701  fwrite($fh, $xslfo);
702  fclose($fh);
703  }
704 
715  function uploadBackgroundImage($image_tempfilename)
716  {
717  if (!empty($image_tempfilename))
718  {
719  $image_filename = "background_upload";
720  $convert_filename = $this->getBackgroundImageName();
721  $imagepath = $this->getCertificatePath();
722  if (!file_exists($imagepath))
723  {
724  ilUtil::makeDirParents($imagepath);
725  }
726  // upload the file
727  if (!ilUtil::moveUploadedFile($image_tempfilename, $image_filename, $this->getBackgroundImageTempfilePath()))
728  {
729  return FALSE;
730  }
731  // convert the uploaded file to JPEG
734  if (!file_exists($this->getBackgroundImagePath()))
735  {
736  // something went wrong converting the file. use the original file and hope, that PDF can work with it
737  if (!ilUtil::moveUploadedFile($this->getBackgroundImageTempfilePath(), $convert_filename, $this->getBackgroundImagePath()))
738  {
739  return FALSE;
740  }
741  }
742  unlink($this->getBackgroundImageTempfilePath());
743  if (file_exists($this->getBackgroundImagePath()) && (filesize($this->getBackgroundImagePath()) > 0))
744  {
745  return TRUE;
746  }
747  }
748  return FALSE;
749  }
750 
760  {
761  if (file_exists($this->getBackgroundImagePath()) && (filesize($this->getBackgroundImagePath()) > 0))
762  {
763  return TRUE;
764  }
765  else
766  {
767  return FALSE;
768  }
769  }
770 
779  function isComplete()
780  {
781  if (file_exists($this->getCertificatePath()))
782  {
783  if (file_exists($this->getXSLPath()) && (filesize($this->getXSLPath()) > 0))
784  {
785  return TRUE;
786  }
787  }
788  return FALSE;
789  }
790 
799  function _isComplete($obj_id)
800  {
801  $certificatepath = CLIENT_WEB_DIR . "/assessment/certificates/" . $obj_id . "/";
802  if (file_exists($certificatepath))
803  {
804  $xslpath = CLIENT_WEB_DIR . "/assessment/certificates/" . $obj_id . "/" . ilTestCertificate::getXSLName();
805  if (file_exists($xslpath) && (filesize($xslpath) > 0))
806  {
807  return TRUE;
808  }
809  }
810  return FALSE;
811  }
812 
821  function getPageFormats()
822  {
823  return array(
824  "a4" => array(
825  "name" => $this->lng->txt("certificate_a4"), // (297 mm x 210 mm)
826  "value" => "a4",
827  "width" => "210mm",
828  "height" => "297mm"
829  ),
830  "a4landscape" => array(
831  "name" => $this->lng->txt("certificate_a4_landscape"), // (210 mm x 297 mm)",
832  "value" => "a4landscape",
833  "width" => "297mm",
834  "height" => "210mm"
835  ),
836  "a5" => array(
837  "name" => $this->lng->txt("certificate_a5"), // (210 mm x 148.5 mm)
838  "value" => "a5",
839  "width" => "148mm",
840  "height" => "210mm"
841  ),
842  "a5landscape" => array(
843  "name" => $this->lng->txt("certificate_a5_landscape"), // (148.5 mm x 210 mm)
844  "value" => "a5landscape",
845  "width" => "210mm",
846  "height" => "148mm"
847  ),
848  "letter" => array(
849  "name" => $this->lng->txt("certificate_letter"), // (11 inch x 8.5 inch)
850  "value" => "letter",
851  "width" => "8.5in",
852  "height" => "11in"
853  ),
854  "letterlandscape" => array(
855  "name" => $this->lng->txt("certificate_letter_landscape"), // (11 inch x 8.5 inch)
856  "value" => "letterlandscape",
857  "width" => "8.5in",
858  "height" => "11in"
859  ),
860  "custom" => array(
861  "name" => $this->lng->txt("certificate_custom"),
862  "value" => "custom",
863  "width" => "",
864  "height" => ""
865  )
866  );
867  }
868 
874  public function cloneCertificate($new_id)
875  {
876  $xsl = $this->getXSLPath();
877  $bgimage = $this->getBackgroundImagePath();
878  $bgimagethumb = $this->getBackgroundImageThumbPath();
879  $certificatepath = $this->getCertificatePath();
880 
881  $new_certificatepath = str_replace("/" . $this->object->getId() . "/", "/" . $new_id . "/", $certificatepath);
882  $new_xsl = str_replace("/" . $this->object->getId() . "/", "/" . $new_id . "/", $xsl);
883  $new_bgimage = str_replace("/" . $this->object->getId() . "/", "/" . $new_id . "/", $bgimage);
884  $new_bgimagethumb = str_replace("/" . $this->object->getId() . "/", "/" . $new_id . "/", $bgimagethumb);
885 
886  if (@file_exists($xsl))
887  {
888  ilUtil::makeDirParents($new_certificatepath);
889  @copy($xsl, $new_xsl);
890  if (@file_exists($bgimage)) @copy($bgimage, $new_bgimage);
891  if (@file_exists($bgimagethumb)) @copy($bgimagethumb, $new_bgimagethumb);
892  }
893  }
894 
903  {
904  include_once "./Services/Utilities/classes/class.ilUtil.php";
905  $exportpath = $this->createArchiveDirectory();
906  ilUtil::makeDir($exportpath);
907  $xsl = file_get_contents($this->getXSLPath());
908  $xslexport = str_replace($this->getCertificatePath(), "", $xsl);
909  // save export xsl file
910  $this->saveCertificate($xslexport, $exportpath . $this->getXSLName());
911  // save background image
912  if ($this->hasBackgroundImage())
913  {
914  copy($this->getBackgroundImagePath(), $exportpath . $this->getBackgroundImageName());
915  }
916  $zipfile = time() . "__" . IL_INST_ID . "__" . "test" . "__" . $this->object->getId() . "__certificate.zip";
917  ilUtil::zip($exportpath, $this->getCertificatePath() . $zipfile);
918  ilUtil::delDir($exportpath);
919  ilUtil::deliverFile($this->getCertificatePath() . $zipfile, $zipfile, "application/zip");
920  }
921 
930  function importCertificate($zipfile, $filename)
931  {
932  include_once "./Services/Utilities/classes/class.ilUtil.php";
933  $importpath = $this->createArchiveDirectory();
934  if (!ilUtil::moveUploadedFile($zipfile, $filename, $importpath . $filename))
935  {
936  ilUtil::delDir($importpath);
937  return FALSE;
938  }
939  ilUtil::unzip($importpath . $filename, TRUE);
940  $subdir = str_replace(".zip", "", strtolower($filename)) . "/";
941  $copydir = "";
942  if (is_dir($importpath . $subdir))
943  {
944  $dirinfo = ilUtil::getDir($importpath . $subdir);
945  $copydir = $importpath . $subdir;
946  }
947  else
948  {
949  $dirinfo = ilUtil::getDir($importpath);
950  $copydir = $importpath;
951  }
952  $xmlfiles = 0;
953  $otherfiles = 0;
954  foreach ($dirinfo as $file)
955  {
956  if (strcmp($file["type"], "file") == 0)
957  {
958  if (strpos($file["entry"], ".xml") !== FALSE)
959  {
960  $xmlfiles++;
961  }
962  else if (strpos($file["entry"], ".zip") !== FALSE)
963  {
964  }
965  else
966  {
967  $otherfiles++;
968  }
969  }
970  }
971  // if one XML file is in the archive, we try to import it
972  if ($xmlfiles == 1)
973  {
974  foreach ($dirinfo as $file)
975  {
976  if (strcmp($file["type"], "file") == 0)
977  {
978  if (strpos($file["entry"], ".xml") !== FALSE)
979  {
980  $xsl = file_get_contents($copydir . $file["entry"]);
981  // as long as we cannot make RPC calls in a given directory, we have
982  // to add the complete path to every url
983  $xsl = preg_replace("/url\([']{0,1}(.*?)[']{0,1}\)/", "url(" . $this->getCertificatePath() . "\${1})", $xsl);
984  $this->saveCertificate($xsl);
985  }
986  else if (strpos($file["entry"], ".zip") !== FALSE)
987  {
988  }
989  else
990  {
991  @copy($copydir . $file["entry"], $this->getCertificatePath() . $file["entry"]);
992  if (strcmp($this->getBackgroundImagePath(), $this->getCertificatePath() . $file["entry"]) == 0)
993  {
994  // upload of the background image, create a preview
996  }
997  }
998  }
999  }
1000  }
1001  else
1002  {
1003  ilUtil::delDir($importpath);
1004  return FALSE;
1005  }
1006  ilUtil::delDir($importpath);
1007  return TRUE;
1008  }
1009 }
1010 
1011 ?>