80 $this->lng = $DIC[
'lng'];
81 $this->ctrl = $DIC[
'ilCtrl'];
82 $this->
ilias = $DIC[
'ilias'];
83 $this->tree = $DIC[
'tree'];
85 $this->log = $DIC[
'ilLog'];
86 $this->db = $DIC[
'ilDB'];
97 return str_replace(
',',
'.', $a_number);
110 array(CLIENT_WEB_DIR,
'//'),
111 array(
'[CLIENT_WEB_DIR]',
'/'),
126 return "background.jpg";
146 return $this->
getAdapter()->getCertificatePath() .
"background_upload.tmp";
166 return "certificate.xml";
176 return "certificate.xml";
187 include_once
"./Services/Utilities/classes/class.ilUtil.php";
200 include_once
"./Services/Utilities/classes/class.ilUtil.php";
237 $certificatepath = $this->
getAdapter()->getCertificatePath();
239 $new_xsl = $newObject->getXSLPath();
240 $new_bgimage = $newObject->getBackgroundImagePath();
241 $new_bgimagethumb = $newObject->getBackgroundImageThumbPath();
242 $new_certificatepath = $newObject->getAdapter()->getCertificatePath();
244 if (@file_exists($xsl))
247 @copy($xsl, $new_xsl);
248 if (@file_exists($bgimage)) @copy($bgimage, $new_bgimage);
249 if (@file_exists($bgimagethumb)) @copy($bgimagethumb, $new_bgimagethumb);
255 $newObject->writeActive(
true);
266 if (@file_exists($this->
getAdapter()->getCertificatePath()))
268 include_once
"./Services/Utilities/classes/class.ilUtil.php";
282 $xslfo = file_get_contents($this->
getXSLPath());
286 if (preg_match(
"/page-width\=\"([^\"]+)\"/", $xslfo, $matches))
288 $pagewidth = $matches[1];
290 $pageheight =
"29.7cm";
291 if (preg_match(
"/page-height\=\"([^\"]+)\"/", $xslfo, $matches))
293 $pageheight = $matches[1];
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)))
301 else if (((strcmp($pagewidth,
"29.7cm") == 0) || (strcmp($pagewidth,
"297mm") == 0)) && ((strcmp($pageheight,
"21cm") == 0) || (strcmp($pageheight,
"210mm") == 0)))
303 $pagesize =
"a4landscape";
305 else if (((strcmp($pageheight,
"21cm") == 0) || (strcmp($pageheight,
"210mm") == 0)) && ((strcmp($pagewidth,
"14.8cm") == 0) || (strcmp($pagewidth,
"148mm") == 0)))
309 else if (((strcmp($pagewidth,
"21cm") == 0) || (strcmp($pagewidth,
"210mm") == 0)) && ((strcmp($pageheight,
"14.8cm") == 0) || (strcmp($pageheight,
"148mm") == 0)))
311 $pagesize =
"a5landscape";
313 else if (((strcmp($pageheight,
"11in") == 0)) && ((strcmp($pagewidth,
"8.5in") == 0)))
315 $pagesize =
"letter";
317 else if (((strcmp($pagewidth,
"11in") == 0)) && ((strcmp($pageheight,
"8.5in") == 0)))
319 $pagesize =
"letterlandscape";
323 $pagesize =
"custom";
325 if (!strlen($xslfo)) $pagesize = $certificatesettings->get(
"pageformat");;
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))
334 $marginbody = $matches[1];
335 if (preg_match_all(
"/([^\s]+)/", $marginbody, $matches))
337 $marginbody_top = $matches[1][0];
338 $marginbody_right = $matches[1][1];
339 $marginbody_bottom = $matches[1][2];
340 $marginbody_left = $matches[1][3];
343 else if(preg_match(
"/fo:region-body[^>]*margin\=\"([^\"]+)\"/", $xslfo, $matches))
345 $marginbody = $matches[1];
346 if (preg_match_all(
"/([^\s]+)/", $marginbody, $matches))
348 $marginbody_top = $matches[1][0];
349 $marginbody_right = $matches[1][1];
350 $marginbody_bottom = $matches[1][2];
351 $marginbody_left = $matches[1][3];
355 $xsl = file_get_contents(
"./Services/Certificate/xml/fo2xhtml.xsl");
356 if ((strlen($xslfo)) && (strlen($xsl)))
358 $args =
array(
'/_xml' => $xslfo,
'/_xsl' => $xsl );
360 $output = xslt_process($xh,
"arg:/_xml",
"arg:/_xsl", NULL, $args, NULL);
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,
380 $this->
getAdapter()->addFormFieldsFromObject($form_fields);
392 $content =
"<html><body>".$form_data[
"certificate_text"].
"</body></html>";
393 $content = preg_replace(
"/<p>( ){1,}<\\/p>/",
"<p></p>", $content);
394 $content = preg_replace(
"/<p>(\\s)*?<\\/p>/",
"<p></p>", $content);
397 $content = str_replace(
"<p></p>",
"<p class=\"emptyrow\"></p>", $content);
398 $content = str_replace(
" ",
" ", $content);
399 $content = preg_replace(
"//",
"", $content);
401 include_once
"./Services/Certificate/classes/class.ilXmlChecker.php";
403 $check->setXMLContent($content);
404 $check->startParsing();
405 if ($check->hasError())
407 throw new Exception($this->lng->txt(
"certificate_not_well_formed"));
410 $xsl = file_get_contents(
"./Services/Certificate/xml/xhtml2fo.xsl");
414 'font-family="Helvetica, unifont"',
415 'font-family="'.$this->
settings->get(
'rpc_pdf_font',
'Helvetica, unifont').
'"',
419 $args =
array(
'/_xml' => $content,
'/_xsl' => $xsl );
421 if (strcmp($form_data[
"pageformat"],
"custom") == 0)
423 $pageheight = $form_data[
"pageheight"];
424 $pagewidth = $form_data[
"pagewidth"];
429 $pageheight = $pageformats[$form_data[
"pageformat"]][
"height"];
430 $pagewidth = $pageformats[$form_data[
"pageformat"]][
"width"];
432 include_once
"./Services/Certificate/classes/class.ilObjCertificateSettingsAccess.php";
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"]
445 $output = xslt_process($xh,
"arg:/_xml",
"arg:/_xsl", NULL, $args,
$params);
460 if (count($insert_tags) == 0)
462 $insert_tags = $this->
getAdapter()->getCertificateVariablesForPreview();
463 foreach (self::getCustomCertificateFields() as $k => $f)
468 foreach ($insert_tags as $var => $value)
470 $certificate_text = str_replace($var, $value, $certificate_text);
473 $certificate_text = str_replace(
'[CLIENT_WEB_DIR]', CLIENT_WEB_DIR, $certificate_text);
475 return $certificate_text;
487 $insert_tags = $this->
getAdapter()->getCertificateVariablesForPresentation(
$params);
489 include_once(
"./Services/User/classes/class.ilUserDefinedData.php");
491 $cust_data = $cust_data->getAll();
492 foreach (self::getCustomCertificateFields() as $k => $f)
497 $xslfo = file_get_contents($this->
getXSLPath());
500 require_once(
'Services/MathJax/classes/class.ilMathJax.php');
504 ->insertLatexImages($xslfo);
506 include_once
'./Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
513 include_once
"./Services/Utilities/classes/class.ilUtil.php";
518 return $pdf_base64->scalar;
523 $this->log->write(__METHOD__.
': '.$e->getMessage());
538 $xslfo = file_get_contents($this->
getXSLPath());
541 require_once(
'Services/MathJax/classes/class.ilMathJax.php');
545 ->insertLatexImages($xslfo);
547 include_once
'./Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
552 ilUtil::deliverData($pdf_base64->scalar, $this->getAdapter()->getCertificateFilename(),
"application/pdf");
557 $this->log->write(__METHOD__.
': '.$e->getMessage());
572 if (!file_exists($this->
getAdapter()->getCertificatePath()))
594 if (!empty($image_tempfilename))
597 $imagepath = $this->
getAdapter()->getCertificatePath();
598 if (!file_exists($imagepath))
656 $obj_id = $this->
getAdapter()->getCertificateID();
657 if($obj_id && !self::isObjectActive($obj_id))
661 if (file_exists($this->
getAdapter()->getCertificatePath()))
684 $obj_id =
$adapter->getCertificateID();
685 if($obj_id && !self::isObjectActive($obj_id))
690 $certificatepath =
$adapter->getCertificatePath();
691 if (file_exists($certificatepath))
694 if (file_exists($xslpath) && (filesize($xslpath) > 0))
713 "name" => $this->lng->txt(
"certificate_a4"),
718 "a4landscape" =>
array(
719 "name" => $this->lng->txt(
"certificate_a4_landscape"),
720 "value" =>
"a4landscape",
725 "name" => $this->lng->txt(
"certificate_a5"),
730 "a5landscape" =>
array(
731 "name" => $this->lng->txt(
"certificate_a5_landscape"),
732 "value" =>
"a5landscape",
737 "name" => $this->lng->txt(
"certificate_letter"),
742 "letterlandscape" =>
array(
743 "name" => $this->lng->txt(
"certificate_letter_landscape"),
744 "value" =>
"letterlandscape",
749 "name" => $this->lng->txt(
"certificate_custom"),
762 include_once
"./Services/Utilities/classes/class.ilUtil.php";
765 $xsl = file_get_contents($this->
getXSLPath());
766 $xslexport = str_replace($this->
getAdapter()->getCertificatePath(),
"", $xsl);
776 include_once
"./Services/Certificate/classes/class.ilObjCertificateSettingsAccess.php";
782 $zipfile =
time() .
"__" . IL_INST_ID .
"__" . $this->
getAdapter()->getAdapterType() .
"__" . $this->
getAdapter()->getCertificateId() .
"__certificate.zip";
795 include_once
"./Services/Utilities/classes/class.ilUtil.php";
803 $subdir = str_replace(
".zip",
"", strtolower($filename)) .
"/";
805 if (is_dir($importpath . $subdir))
808 $copydir = $importpath . $subdir;
813 $copydir = $importpath;
817 foreach ($dirinfo as
$file)
819 if (strcmp($file[
"type"],
"file") == 0)
821 if (strpos($file[
"entry"],
".xml") !== FALSE)
825 else if (strpos($file[
"entry"],
".zip") !== FALSE)
837 foreach ($dirinfo as $file)
839 if (strcmp($file[
"type"],
"file") == 0)
841 if (strpos($file[
"entry"],
".xml") !== FALSE)
843 $xsl = file_get_contents($copydir . $file[
"entry"]);
846 $xsl = preg_replace(
"/url\([']{0,1}(.*?)[']{0,1}\)/",
"url(" . $this->
getAdapter()->getCertificatePath() .
"\${1})", $xsl);
849 else if (strpos($file[
"entry"],
".zip") !== FALSE)
854 @copy($copydir . $file[
"entry"], $this->
getAdapter()->getCertificatePath() . $file[
"entry"]);
static makeDirParents($a_dir)
Create a new directory and all parent directories.
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
static deliverData($a_data, $a_filename, $mime="application/octet-stream", $charset="")
deliver data for download via browser.
__construct(ilCertificateAdapter $adapter)
ilCertificate constructor
processXHTML2FO($form_data, $for_export=FALSE)
Convert the certificate text to XSL-FO using XSL transformation.
deleteCertificate()
Deletes the certificate and all it's data.
outCertificate($params, $deliver=TRUE)
Creates a PDF certificate.
static _isComplete($adapter)
Checks the status of the certificate.
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.
static getBackgroundImagePath($asRelative=false)
Returns the filesystem path of the background image.
static factory($a_package, $a_timeout=0)
Creates an ilRpcClient instance to our ilServer.
getBackgroundImagePathWeb()
Returns the web path of the background image.
static unzip($a_file, $overwrite=false, $a_flat=false)
unzip file
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
formatNumberString($a_number)
static setUseRelativeDates($a_status)
set use relative dates
deleteBackgroundImage()
Deletes the background image of a certificate.
getBackgroundImagePath($asRelative=false)
Returns the filesystem path of the background image.
static getBackgroundImageName()
Returns the filename of the background image.
uploadBackgroundImage($image_tempfilename)
Uploads a background image for the certificate.
hasBackgroundImage()
Checks for the background image of the certificate.
getBackgroundImageThumbPath()
Returns the filesystem path of the background image thumbnail.
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\+" &#(? foreach( $entity_files as $file) $output
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.
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) ...
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
Create styles array
The data for the language used.
static hasBackgroundImage()
Returns wheather or not a default background image exists.
const RENDER_PNG_AS_FO_FILE
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.
setAdapter($adapter)
Sets the adapter.
getBackgroundImageName()
Returns the filename of the background image.
static getInstance()
Singleton: get instance.
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.
Adapter class to provide certificate data for the certificate generator.
getBackgroundImageThumbPathWeb()
Returns the web path of the background image thumbnail.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
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.
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.
getXSLName()
Returns the filename of the XSL-FO file.