ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilCertificate Class Reference

Create PDF certificates. More...

+ Collaboration diagram for ilCertificate:

Public Member Functions

 __construct ($adapter)
 ilCertificate constructor
 getBackgroundImagePath ()
 Returns the filesystem path of the background image.
 getBackgroundImageName ()
 Returns the filename of the background image.
 getBackgroundImageThumbPath ()
 Returns the filesystem path of the background image thumbnail.
 getBackgroundImageTempfilePath ()
 Returns the filesystem path of the background image temp file during upload.
 getXSLPath ()
 Returns the filesystem path of the XSL-FO file.
 getXSLName ()
 Returns the filename of the XSL-FO file.
 getBackgroundImagePathWeb ()
 Returns the web path of the background image.
 getBackgroundImageThumbPathWeb ()
 Returns the web path of the background image thumbnail.
 deleteBackgroundImage ()
 Deletes the background image of a certificate.
 cloneCertificate ($newObject)
 Clone the certificate for another test object.
 deleteCertificate ()
 Deletes the certificate and all it's data.
 getFormFieldsFromFO ()
 Convert the XSL-FO to the certificate text and the form settings using XSL transformation.
 processXHTML2FO ($form_data, $for_export=FALSE)
 Convert the certificate text to XSL-FO using XSL transformation.
 outCertificate ($params, $deliver=TRUE)
 Creates a PDF certificate.
 createPreview ()
 Creates a PDF preview of the XSL-FO certificate.
 saveCertificate ($xslfo, $filename="")
 Saves the XSL-FO code to a file.
 uploadBackgroundImage ($image_tempfilename)
 Uploads a background image for the certificate.
 hasBackgroundImage ()
 Checks for the background image of the certificate.
 isComplete ()
 Checks the status of the certificate.
 _isComplete ($adapter)
 Checks the status of the certificate.
 getPageFormats ()
 Retrieves predefined page formats.
 deliverExportFileXML ()
 Builds an export file in ZIP format and delivers it.
 importCertificate ($zipfile, $filename)
 Reads an import ZIP file and creates a certificate of it.
 getAdapter ()
 Gets the adapter.
 setAdapter ($adapter)
 Sets the adapter.
 createArchiveDirectory ()
 addPDFtoArchiveDirectory ($pdfdata, $dir, $filename)
 Adds PDF data as a file to a given directory.
 zipCertificatesInArchiveDirectory ($dir, $deliver=TRUE)
 Create a ZIP file from a directory with certificates.

Static Public Member Functions

static _getXSLName ()
 Returns the filename of the XSL-FO file.
static _goto ($ref_id)
 Creates a redirect to a certificate download.

Protected Attributes

 $ctrl
 $tree
 $ilias
 $tpl
 $lng
 $adapter

Private Member Functions

 exchangeCertificateVariables ($certificate_text, $insert_tags=array())
 Exchanges the variables in the certificate text with given values.

Detailed Description

Create PDF certificates.

Base class to create PDF certificates using XML-FO XML transformations

Author
Helmut Schottmüller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m
Version
Id:
class.ilCertificate.php 23078 2010-02-26 19:10:12Z hschottm

Definition at line 33 of file class.ilCertificate.php.

Constructor & Destructor Documentation

ilCertificate::__construct (   $adapter)

ilCertificate constructor

Parameters
object$adapterThe certificate adapter needed to construct the certificate

Definition at line 82 of file class.ilCertificate.php.

References $adapter, $ilCtrl, $ilias, $lng, $tpl, and $tree.

{
$this->lng =& $lng;
$this->tpl =& $tpl;
$this->ctrl =& $ilCtrl;
$this->ilias =& $ilias;
$this->tree =& $tree;
$this->adapter =& $adapter;
}

Member Function Documentation

static ilCertificate::_getXSLName ( )
static

Returns the filename of the XSL-FO file.

Returns
string The filename of the XSL-FO file

Definition at line 159 of file class.ilCertificate.php.

Referenced by _isComplete().

{
return "certificate.xml";
}

+ Here is the caller graph for this function:

static ilCertificate::_goto (   $ref_id)
static

Creates a redirect to a certificate download.

Parameters
integer$ref_idRef ID of the ILIAS object

Definition at line 884 of file class.ilCertificate.php.

{
global $ilCtrl;
include_once "./classes/class.ilObject.php";
switch ($type)
{
case 'sahs':
$cmd_link = "ilias.php?baseClass=ilSAHSPresentationGUI&ref_id=".$ref_id.
"&cmd=downloadCertificate";
ilUtil::redirect($cmd_link);
break;
case 'tst':
default:
include_once "./Services/Utilities/classes/class.ilUtil.php";
ilUtil::redirect("repository.php?cmd=frameset");
break;
}
}
ilCertificate::_isComplete (   $adapter)

Checks the status of the certificate.

Parameters
object$adapterThe certificate adapter
Returns
boolean Returns TRUE if the certificate is complete, FALSE otherwise

Definition at line 623 of file class.ilCertificate.php.

References $adapter, and _getXSLName().

Referenced by ilTestEvaluationGUI\outEvaluation().

{
if (is_object($adapter) && method_exists($adapter, "getCertificatePath"))
{
$certificatepath = $adapter->getCertificatePath();
if (file_exists($certificatepath))
{
$xslpath = $adapter->getCertificatePath() . ilCertificate::_getXSLName();
if (file_exists($xslpath) && (filesize($xslpath) > 0))
{
return TRUE;
}
}
}
return FALSE;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCertificate::addPDFtoArchiveDirectory (   $pdfdata,
  $dir,
  $filename 
)

Adds PDF data as a file to a given directory.

Parameters
binary$pdfdataBinary PDF data
string$dirDirectory to contain the PDF data
string$filenameThe filename to save the PDF data

Definition at line 853 of file class.ilCertificate.php.

{
$fh = fopen($dir . $filename, "wb");
fwrite($fh, $pdfdata);
fclose($fh);
}
ilCertificate::cloneCertificate (   $newObject)

Clone the certificate for another test object.

Parameters
$newObjectThe new certificate object

Definition at line 217 of file class.ilCertificate.php.

References getAdapter(), getBackgroundImagePath(), getBackgroundImageThumbPath(), getXSLPath(), and ilUtil\makeDirParents().

{
$xsl = $this->getXSLPath();
$bgimage = $this->getBackgroundImagePath();
$bgimagethumb = $this->getBackgroundImageThumbPath();
$certificatepath = $this->getAdapter()->getCertificatePath();
$new_xsl = $newObject->getXSLPath();
$new_bgimage = $newObject->getBackgroundImagePath();
$new_bgimagethumb = $newObject->getBackgroundImageThumbPath();
$new_certificatepath = $newObject->getAdapter()->getCertificatePath();
if (@file_exists($xsl))
{
ilUtil::makeDirParents($new_certificatepath);
@copy($xsl, $new_xsl);
if (@file_exists($bgimage)) @copy($bgimage, $new_bgimage);
if (@file_exists($bgimagethumb)) @copy($bgimagethumb, $new_bgimagethumb);
}
}

+ Here is the call graph for this function:

ilCertificate::createArchiveDirectory ( )

Definition at line 838 of file class.ilCertificate.php.

Referenced by deliverExportFileXML(), and importCertificate().

{
$dir = $this->getAdapter()->getCertificatePath() . time() . "__" . IL_INST_ID . "__" . $this->getAdapter()->getAdapterType() . "__" . $this->getAdapter()->getCertificateId() . "__certificate/";
include_once "./Services/Utilities/classes/class.ilUtil.php";
return $dir;
}

+ Here is the caller graph for this function:

ilCertificate::createPreview ( )

Creates a PDF preview of the XSL-FO certificate.

Definition at line 485 of file class.ilCertificate.php.

References $ilLog, ilUtil\deliverData(), exchangeCertificateVariables(), ilRpcClientFactory\factory(), and getXSLPath().

{
global $ilLog;
$xslfo = file_get_contents($this->getXSLPath());
include_once './Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
try
{
$pdf_base64 = ilRpcClientFactory::factory('RPCTransformationHandler')->ilFO2PDF(
ilUtil::deliverData($pdf_base64->scalar, $this->getAdapter()->getCertificateFilename(), "application/pdf");
}
{
$ilLog->write(__METHOD__.': '.$e->getMessage());
return false;
}
catch(Exception $e)
{
$ilLog->write(__METHOD__.': '.$e->getMessage());
return false;
}
/*
include_once "./Services/Transformation/classes/class.ilFO2PDF.php";
$fo2pdf = new ilFO2PDF();
$fo2pdf->setFOString($this->exchangeCertificateVariables($xslfo));
$result = $fo2pdf->send();
include_once "./Services/Utilities/classes/class.ilUtil.php";
ilUtil::deliverData($result, $this->getAdapter()->getCertificateFilename(), "application/pdf");
*/
}

+ Here is the call graph for this function:

ilCertificate::deleteBackgroundImage ( )

Deletes the background image of a certificate.

Returns
boolean TRUE if the process succeeds

Definition at line 194 of file class.ilCertificate.php.

References getBackgroundImagePath(), getBackgroundImageTempfilePath(), and getBackgroundImageThumbPath().

{
$result = TRUE;
if (file_exists($this->getBackgroundImageThumbPath()))
{
$result = $result & unlink($this->getBackgroundImageThumbPath());
}
if (file_exists($this->getBackgroundImagePath()))
{
$result = $result & unlink($this->getBackgroundImagePath());
}
if (file_exists($this->getBackgroundImageTempfilePath()))
{
$result = $result & unlink($this->getBackgroundImageTempfilePath());
}
return $result;
}

+ Here is the call graph for this function:

ilCertificate::deleteCertificate ( )

Deletes the certificate and all it's data.

public

Definition at line 243 of file class.ilCertificate.php.

References ilUtil\delDir(), and getAdapter().

{
if (@file_exists($this->getAdapter()->getCertificatePath()))
{
include_once "./Services/Utilities/classes/class.ilUtil.php";
ilUtil::delDir($this->getAdapter()->getCertificatePath());
$this->getAdapter()->deleteCertificate();
}
}

+ Here is the call graph for this function:

ilCertificate::deliverExportFileXML ( )

Builds an export file in ZIP format and delivers it.

Definition at line 696 of file class.ilCertificate.php.

References createArchiveDirectory(), ilUtil\delDir(), ilUtil\deliverFile(), getAdapter(), ilObjCertificateSettingsAccess\getBackgroundImageName(), getBackgroundImageName(), ilObjCertificateSettingsAccess\getBackgroundImagePath(), getBackgroundImagePath(), getXSLName(), getXSLPath(), ilObjCertificateSettingsAccess\hasBackgroundImage(), hasBackgroundImage(), ilUtil\makeDir(), saveCertificate(), and ilUtil\zip().

{
include_once "./Services/Utilities/classes/class.ilUtil.php";
$exportpath = $this->createArchiveDirectory();
ilUtil::makeDir($exportpath);
$xsl = file_get_contents($this->getXSLPath());
$xslexport = str_replace($this->getAdapter()->getCertificatePath(), "", $xsl);
// save export xsl file
$this->saveCertificate($xslexport, $exportpath . $this->getXSLName());
// save background image
if ($this->hasBackgroundImage())
{
copy($this->getBackgroundImagePath(), $exportpath . $this->getBackgroundImageName());
}
else
{
include_once "./Services/Certificate/classes/class.ilObjCertificateSettingsAccess.php";
{
}
}
$zipfile = time() . "__" . IL_INST_ID . "__" . $this->getAdapter()->getAdapterType() . "__" . $this->getAdapter()->getCertificateId() . "__certificate.zip";
ilUtil::zip($exportpath, $this->getAdapter()->getCertificatePath() . $zipfile);
ilUtil::delDir($exportpath);
ilUtil::deliverFile($this->getAdapter()->getCertificatePath() . $zipfile, $zipfile, "application/zip");
}

+ Here is the call graph for this function:

ilCertificate::exchangeCertificateVariables (   $certificate_text,
  $insert_tags = array() 
)
private

Exchanges the variables in the certificate text with given values.

Parameters
string$certificate_textThe XSL-FO certificate text
array$insert_tagsAn associative array containing the variables and the values to replace
Returns
string XSL-FO code

Definition at line 414 of file class.ilCertificate.php.

References getAdapter().

Referenced by createPreview(), and outCertificate().

{
if (count($insert_tags) == 0)
{
$insert_tags = $this->getAdapter()->getCertificateVariablesForPreview();
}
foreach ($insert_tags as $var => $value)
{
$certificate_text = str_replace($var, $value, $certificate_text);
}
return $certificate_text;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCertificate::getBackgroundImageName ( )

Returns the filename of the background image.

Returns
string The filename of the background image

Definition at line 109 of file class.ilCertificate.php.

Referenced by deliverExportFileXML(), getBackgroundImagePath(), getBackgroundImagePathWeb(), getBackgroundImageThumbPath(), and uploadBackgroundImage().

{
return "background.jpg";
}

+ Here is the caller graph for this function:

ilCertificate::getBackgroundImagePath ( )

Returns the filesystem path of the background image.

Returns
string The filesystem path of the background image

Definition at line 99 of file class.ilCertificate.php.

References getAdapter(), and getBackgroundImageName().

Referenced by cloneCertificate(), deleteBackgroundImage(), deliverExportFileXML(), hasBackgroundImage(), importCertificate(), processXHTML2FO(), and uploadBackgroundImage().

{
return $this->getAdapter()->getCertificatePath() . $this->getBackgroundImageName();
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCertificate::getBackgroundImagePathWeb ( )

Returns the web path of the background image.

Returns
string The web path of the background image

Definition at line 169 of file class.ilCertificate.php.

References getAdapter(), getBackgroundImageName(), ILIAS_ABSOLUTE_PATH, and ilUtil\removeTrailingPathSeparators().

{
// TODO: this is generic now -> provide better solution
include_once "./Services/Utilities/classes/class.ilUtil.php";
$webdir = $this->getAdapter()->getCertificatePath() . $this->getBackgroundImageName();
}

+ Here is the call graph for this function:

ilCertificate::getBackgroundImageTempfilePath ( )

Returns the filesystem path of the background image temp file during upload.

Returns
string The filesystem path of the background image temp file

Definition at line 129 of file class.ilCertificate.php.

References getAdapter().

Referenced by deleteBackgroundImage(), and uploadBackgroundImage().

{
return $this->getAdapter()->getCertificatePath() . "background_upload";
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCertificate::getBackgroundImageThumbPath ( )

Returns the filesystem path of the background image thumbnail.

Returns
string The filesystem path of the background image thumbnail

Definition at line 119 of file class.ilCertificate.php.

References getAdapter(), and getBackgroundImageName().

Referenced by cloneCertificate(), deleteBackgroundImage(), getBackgroundImageThumbPathWeb(), importCertificate(), and uploadBackgroundImage().

{
return $this->getAdapter()->getCertificatePath() . $this->getBackgroundImageName() . ".thumb.jpg";
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCertificate::getBackgroundImageThumbPathWeb ( )

Returns the web path of the background image thumbnail.

Returns
string The web path of the background image thumbnail

Definition at line 182 of file class.ilCertificate.php.

References getBackgroundImageThumbPath(), ILIAS_ABSOLUTE_PATH, and ilUtil\removeTrailingPathSeparators().

{
// TODO: this is generic now -> provide better solution
include_once "./Services/Utilities/classes/class.ilUtil.php";
}

+ Here is the call graph for this function:

ilCertificate::getFormFieldsFromFO ( )

Convert the XSL-FO to the certificate text and the form settings using XSL transformation.

Definition at line 256 of file class.ilCertificate.php.

References getAdapter(), getXSLPath(), xslt_create(), xslt_error(), xslt_free(), and xslt_process().

{
if (@file_exists($this->getXSLPath()))
{
$xslfo = file_get_contents($this->getXSLPath());
}
// retrieve form information (using a dirty way with regular expressions)
$pagewidth = "21cm";
if (preg_match("/page-width\=\"([^\"]+)\"/", $xslfo, $matches))
{
$pagewidth = $matches[1];
}
$pageheight = "29.7cm";
if (preg_match("/page-height\=\"([^\"]+)\"/", $xslfo, $matches))
{
$pageheight = $matches[1];
}
$certificatesettings = new ilSetting("certificate");
$pagesize = $certificatesettings->get("pageformat");;
if (((strcmp($pageheight, "29.7cm") == 0) || (strcmp($pageheight, "297mm") == 0)) && ((strcmp($pagewidth, "21cm") == 0) || (strcmp($pagewidth, "210mm") == 0)))
{
$pagesize = "a4";
}
else if (((strcmp($pagewidth, "29.7cm") == 0) || (strcmp($pagewidth, "297mm") == 0)) && ((strcmp($pageheight, "21cm") == 0) || (strcmp($pageheight, "210mm") == 0)))
{
$pagesize = "a4landscape";
}
else if (((strcmp($pageheight, "21cm") == 0) || (strcmp($pageheight, "210mm") == 0)) && ((strcmp($pagewidth, "14.8cm") == 0) || (strcmp($pagewidth, "148mm") == 0)))
{
$pagesize = "a5";
}
else if (((strcmp($pagewidth, "21cm") == 0) || (strcmp($pagewidth, "210mm") == 0)) && ((strcmp($pageheight, "14.8cm") == 0) || (strcmp($pageheight, "148mm") == 0)))
{
$pagesize = "a5landscape";
}
else if (((strcmp($pageheight, "11in") == 0)) && ((strcmp($pagewidth, "8.5in") == 0)))
{
$pagesize = "letter";
}
else if (((strcmp($pagewidth, "11in") == 0)) && ((strcmp($pageheight, "8.5in") == 0)))
{
$pagesize = "letterlandscape";
}
if (!strlen($xslfo)) $pagesize = $certificatesettings->get("pageformat");;
$paddingtop = "0cm";
if (preg_match("/padding-top\=\"([^\"]+)\"/", $xslfo, $matches))
{
$paddingtop = $matches[1];
}
$marginbody_top = "0cm";
$marginbody_right = "2cm";
$marginbody_bottom = "0cm";
$marginbody_left = "2cm";
if (preg_match("/fo:flow[^>]*margin\=\"([^\"]+)\"/", $xslfo, $matches))
{
$marginbody = $matches[1];
if (preg_match_all("/([^\s]+)/", $marginbody, $matches))
{
$marginbody_top = $matches[1][0];
$marginbody_right = $matches[1][1];
$marginbody_bottom = $matches[1][2];
$marginbody_left = $matches[1][3];
}
}
$xsl = file_get_contents("./Services/Certificate/xml/fo2xhtml.xsl");
if ((strlen($xslfo)) && (strlen($xsl)))
{
$args = array( '/_xml' => $xslfo, '/_xsl' => $xsl );
$xh = xslt_create();
$output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", NULL, $args, NULL);
xslt_error($xh);
xslt_free($xh);
}
$output = preg_replace("/<\?xml[^>]+?>/", "", $output);
// dirty hack: the php xslt processing seems not to recognize the following
// replacements, so we do it in the code as well
$output = str_replace("&#xA0;", "<br />", $output);
$output = str_replace("&#160;", "<br />", $output);
$form_fields = array(
"pageformat" => $pagesize,
"pagewidth" => $pagewidth,
"pageheight" => $pageheight,
"padding_top" => $paddingtop,
"margin_body_top" => $marginbody_top,
"margin_body_right" => $marginbody_right,
"margin_body_bottom" => $marginbody_bottom,
"margin_body_left" => $marginbody_left,
"certificate_text" => $output
);
$this->getAdapter()->addFormFieldsFromObject($form_fields);
return $form_fields;
}

+ Here is the call graph for this function:

ilCertificate::getPageFormats ( )

Retrieves predefined page formats.

Returns
array Associative array containing available page formats

Definition at line 645 of file class.ilCertificate.php.

Referenced by processXHTML2FO().

{
return array(
"a4" => array(
"name" => $this->lng->txt("certificate_a4"), // (297 mm x 210 mm)
"value" => "a4",
"width" => "210mm",
"height" => "297mm"
),
"a4landscape" => array(
"name" => $this->lng->txt("certificate_a4_landscape"), // (210 mm x 297 mm)",
"value" => "a4landscape",
"width" => "297mm",
"height" => "210mm"
),
"a5" => array(
"name" => $this->lng->txt("certificate_a5"), // (210 mm x 148.5 mm)
"value" => "a5",
"width" => "148mm",
"height" => "210mm"
),
"a5landscape" => array(
"name" => $this->lng->txt("certificate_a5_landscape"), // (148.5 mm x 210 mm)
"value" => "a5landscape",
"width" => "210mm",
"height" => "148mm"
),
"letter" => array(
"name" => $this->lng->txt("certificate_letter"), // (11 inch x 8.5 inch)
"value" => "letter",
"width" => "8.5in",
"height" => "11in"
),
"letterlandscape" => array(
"name" => $this->lng->txt("certificate_letter_landscape"), // (11 inch x 8.5 inch)
"value" => "letterlandscape",
"width" => "8.5in",
"height" => "11in"
),
"custom" => array(
"name" => $this->lng->txt("certificate_custom"),
"value" => "custom",
"width" => "",
"height" => ""
)
);
}

+ Here is the caller graph for this function:

ilCertificate::getXSLName ( )

Returns the filename of the XSL-FO file.

Returns
string The filename of the XSL-FO file

Definition at line 149 of file class.ilCertificate.php.

Referenced by deliverExportFileXML(), and getXSLPath().

{
return "certificate.xml";
}

+ Here is the caller graph for this function:

ilCertificate::getXSLPath ( )

Returns the filesystem path of the XSL-FO file.

Returns
string The filesystem path of the XSL-FO file

Definition at line 139 of file class.ilCertificate.php.

References getAdapter(), and getXSLName().

Referenced by cloneCertificate(), createPreview(), deliverExportFileXML(), getFormFieldsFromFO(), isComplete(), outCertificate(), and saveCertificate().

{
return $this->getAdapter()->getCertificatePath() . $this->getXSLName();
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCertificate::hasBackgroundImage ( )

Checks for the background image of the certificate.

Returns
boolean Returns TRUE if the certificate has a background image, FALSE otherwise

Definition at line 588 of file class.ilCertificate.php.

References getBackgroundImagePath().

Referenced by deliverExportFileXML(), and processXHTML2FO().

{
if (file_exists($this->getBackgroundImagePath()) && (filesize($this->getBackgroundImagePath()) > 0))
{
return TRUE;
}
else
{
return FALSE;
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCertificate::importCertificate (   $zipfile,
  $filename 
)

Reads an import ZIP file and creates a certificate of it.

Returns
boolean TRUE if the import succeeds, FALSE otherwise

Definition at line 729 of file class.ilCertificate.php.

References $file, $filename, ilUtil\convertImage(), createArchiveDirectory(), ilUtil\delDir(), getAdapter(), getBackgroundImagePath(), getBackgroundImageThumbPath(), ilUtil\getDir(), ilUtil\moveUploadedFile(), saveCertificate(), and ilUtil\unzip().

{
include_once "./Services/Utilities/classes/class.ilUtil.php";
$importpath = $this->createArchiveDirectory();
if (!ilUtil::moveUploadedFile($zipfile, $filename, $importpath . $filename))
{
ilUtil::delDir($importpath);
return FALSE;
}
ilUtil::unzip($importpath . $filename, TRUE);
$subdir = str_replace(".zip", "", strtolower($filename)) . "/";
$copydir = "";
if (is_dir($importpath . $subdir))
{
$dirinfo = ilUtil::getDir($importpath . $subdir);
$copydir = $importpath . $subdir;
}
else
{
$dirinfo = ilUtil::getDir($importpath);
$copydir = $importpath;
}
$xmlfiles = 0;
$otherfiles = 0;
foreach ($dirinfo as $file)
{
if (strcmp($file["type"], "file") == 0)
{
if (strpos($file["entry"], ".xml") !== FALSE)
{
$xmlfiles++;
}
else if (strpos($file["entry"], ".zip") !== FALSE)
{
}
else
{
$otherfiles++;
}
}
}
// if one XML file is in the archive, we try to import it
if ($xmlfiles == 1)
{
foreach ($dirinfo as $file)
{
if (strcmp($file["type"], "file") == 0)
{
if (strpos($file["entry"], ".xml") !== FALSE)
{
$xsl = file_get_contents($copydir . $file["entry"]);
// as long as we cannot make RPC calls in a given directory, we have
// to add the complete path to every url
$xsl = preg_replace("/url\([']{0,1}(.*?)[']{0,1}\)/", "url(" . $this->getAdapter()->getCertificatePath() . "\${1})", $xsl);
$this->saveCertificate($xsl);
}
else if (strpos($file["entry"], ".zip") !== FALSE)
{
}
else
{
@copy($copydir . $file["entry"], $this->getAdapter()->getCertificatePath() . $file["entry"]);
if (strcmp($this->getBackgroundImagePath(), $this->getAdapter()->getCertificatePath() . $file["entry"]) == 0)
{
// upload of the background image, create a preview
}
}
}
}
}
else
{
ilUtil::delDir($importpath);
return FALSE;
}
ilUtil::delDir($importpath);
return TRUE;
}

+ Here is the call graph for this function:

ilCertificate::isComplete ( )

Checks the status of the certificate.

Returns
boolean Returns TRUE if the certificate is complete, FALSE otherwise

Definition at line 605 of file class.ilCertificate.php.

References getAdapter(), and getXSLPath().

{
if (file_exists($this->getAdapter()->getCertificatePath()))
{
if (file_exists($this->getXSLPath()) && (filesize($this->getXSLPath()) > 0))
{
return TRUE;
}
}
return FALSE;
}

+ Here is the call graph for this function:

ilCertificate::outCertificate (   $params,
  $deliver = TRUE 
)

Creates a PDF certificate.

Parameters
array$paramsAn array of parameters which is needed to create the certificate

Definition at line 432 of file class.ilCertificate.php.

References $ilLog, ilUtil\deliverData(), exchangeCertificateVariables(), ilRpcClientFactory\factory(), getAdapter(), and getXSLPath().

{
global $ilLog;
$insert_tags = $this->getAdapter()->getCertificateVariablesForPresentation($params);
$xslfo = file_get_contents($this->getXSLPath());
include_once './Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
try
{
$pdf_base64 = ilRpcClientFactory::factory('RPCTransformationHandler')->ilFO2PDF(
$this->exchangeCertificateVariables($xslfo, $insert_tags));
if ($deliver)
{
include_once "./Services/Utilities/classes/class.ilUtil.php";
ilUtil::deliverData($pdf_base64->scalar, $this->getAdapter()->getCertificateFilename($params), "application/pdf");
}
else
{
return $pdf_base64->scalar;
}
}
{
$ilLog->write(__METHOD__.': '.$e->getMessage());
return false;
}
catch(Exception $e)
{
$ilLog->write(__METHOD__.': '.$e->getMessage());
return false;
}
/*
include_once "./Services/Transformation/classes/class.ilFO2PDF.php";
$fo2pdf = new ilFO2PDF();
$fo2pdf->setFOString($this->exchangeCertificateVariables($xslfo, $insert_tags));
$result = $fo2pdf->send();
if ($deliver)
{
include_once "./Services/Utilities/classes/class.ilUtil.php";
ilUtil::deliverData($result, $this->getAdapter()->getCertificateFilename($params), "application/pdf");
}
else
{
return $result;
}
*/
}

+ Here is the call graph for this function:

ilCertificate::processXHTML2FO (   $form_data,
  $for_export = FALSE 
)

Convert the certificate text to XSL-FO using XSL transformation.

Parameters
array$form_dataThe form data
Returns
string XSL-FO code

Definition at line 358 of file class.ilCertificate.php.

References ilObjCertificateSettingsAccess\getBackgroundImagePath(), getBackgroundImagePath(), getPageFormats(), hasBackgroundImage(), xslt_create(), xslt_error(), xslt_free(), and xslt_process().

{
$content = "<html><body>".$form_data["certificate_text"]."</body></html>";
$content = preg_replace("/<p>(&nbsp;){1,}<\\/p>/", "<p></p>", $content);
$content = preg_replace("/<p>(\\s)*?<\\/p>/", "<p></p>", $content);
// $content = str_replace("<p>&nbsp;</p>", "<p><br /></p>", $content);
// $content = str_replace("<p> </p>", "<p><br /></p>", $content);
$content = str_replace("<p></p>", "<p class=\"emptyrow\"></p>", $content);
$content = str_replace("&nbsp;", "&#160;", $content);
$content = preg_replace("//", "", $content);
include_once "./Services/Certificate/classes/class.ilXmlChecker.php";
$check = new ilXMLChecker();
$check->setXMLContent($content);
$check->startParsing();
if ($check->hasError())
{
throw new Exception($this->lng->txt("certificate_not_well_formed"));
}
$xsl = file_get_contents("./Services/Certificate/xml/xhtml2fo.xsl");
$args = array( '/_xml' => $content, '/_xsl' => $xsl );
$xh = xslt_create();
if (strcmp($form_data["pageformat"], "custom") == 0)
{
$pageheight = $form_data["pageheight"];
$pagewidth = $form_data["pagewidth"];
}
else
{
$pageformats = $this->getPageFormats();
$pageheight = $pageformats[$form_data["pageformat"]]["height"];
$pagewidth = $pageformats[$form_data["pageformat"]]["width"];
}
include_once "./Services/Certificate/classes/class.ilObjCertificateSettingsAccess.php";
$params = array(
"pageheight" => $pageheight,
"pagewidth" => $pagewidth,
"backgroundimage" => $backgroundimage,
"marginbody" => $form_data["margin_body_top"] . " " . $form_data["margin_body_right"] . " " . $form_data["margin_body_bottom"] . " " . $form_data["margin_body_left"],
"paddingtop" => $form_data["padding_top"]
);
$output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", NULL, $args, $params);
xslt_error($xh);
xslt_free($xh);
return $output;
}

+ Here is the call graph for this function:

ilCertificate::saveCertificate (   $xslfo,
  $filename = "" 
)

Saves the XSL-FO code to a file.

Parameters
string$xslfoXSL-FO code

Definition at line 525 of file class.ilCertificate.php.

References $filename, getAdapter(), getXSLPath(), and ilUtil\makeDirParents().

Referenced by deliverExportFileXML(), and importCertificate().

{
if (!file_exists($this->getAdapter()->getCertificatePath()))
{
ilUtil::makeDirParents($this->getAdapter()->getCertificatePath());
}
if (strlen($filename) == 0)
{
$filename = $this->getXSLPath();
}
$fh = fopen($filename, "w");
fwrite($fh, $xslfo);
fclose($fh);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCertificate::setAdapter (   $adapter)

Sets the adapter.

Parameters
object$adapterAdapter

Definition at line 824 of file class.ilCertificate.php.

References $adapter.

{
$this->adapter =& $adapter;
}
ilCertificate::uploadBackgroundImage (   $image_tempfilename)

Uploads a background image for the certificate.

Creates a new directory for the certificate if needed. Removes an existing certificate image if necessary

Parameters
string$image_tempfilenameName of the temporary uploaded image file
Returns
integer An errorcode if the image upload fails, 0 otherwise

Definition at line 547 of file class.ilCertificate.php.

References ilUtil\convertImage(), getAdapter(), getBackgroundImageName(), getBackgroundImagePath(), getBackgroundImageTempfilePath(), getBackgroundImageThumbPath(), ilUtil\makeDirParents(), and ilUtil\moveUploadedFile().

{
if (!empty($image_tempfilename))
{
$image_filename = "background_upload";
$convert_filename = $this->getBackgroundImageName();
$imagepath = $this->getAdapter()->getCertificatePath();
if (!file_exists($imagepath))
{
}
// upload the file
if (!ilUtil::moveUploadedFile($image_tempfilename, $image_filename, $this->getBackgroundImageTempfilePath()))
{
return FALSE;
}
// convert the uploaded file to JPEG
if (!file_exists($this->getBackgroundImagePath()))
{
// something went wrong converting the file. use the original file and hope, that PDF can work with it
{
return FALSE;
}
}
if (file_exists($this->getBackgroundImagePath()) && (filesize($this->getBackgroundImagePath()) > 0))
{
return TRUE;
}
}
return FALSE;
}

+ Here is the call graph for this function:

ilCertificate::zipCertificatesInArchiveDirectory (   $dir,
  $deliver = TRUE 
)

Create a ZIP file from a directory with certificates.

Parameters
string$dirDirectory containing the certificates
boolean$deliverTRUE to deliver the ZIP file, FALSE to return the filename only
Returns
string The created ZIP archive path

Definition at line 867 of file class.ilCertificate.php.

{
$zipfile = time() . "__" . IL_INST_ID . "__" . $this->getAdapter()->getAdapterType() . "__" . $this->getAdapter()->getCertificateId() . "__certificates.zip";
ilUtil::zip($dir, $this->getAdapter()->getCertificatePath() . $zipfile);
if ($deliver)
{
ilUtil::deliverFile($this->getAdapter()->getCertificatePath() . $zipfile, $zipfile, "application/zip");
}
return $this->getAdapter()->getCertificatePath() . $zipfile;
}

Field Documentation

ilCertificate::$adapter
protected

Definition at line 75 of file class.ilCertificate.php.

Referenced by __construct(), _isComplete(), getAdapter(), and setAdapter().

ilCertificate::$ctrl
protected

Definition at line 40 of file class.ilCertificate.php.

ilCertificate::$ilias
protected

Definition at line 54 of file class.ilCertificate.php.

Referenced by __construct().

ilCertificate::$lng
protected

Definition at line 68 of file class.ilCertificate.php.

Referenced by __construct().

ilCertificate::$tpl
protected

Definition at line 61 of file class.ilCertificate.php.

Referenced by __construct().

ilCertificate::$tree
protected

Definition at line 47 of file class.ilCertificate.php.

Referenced by __construct().


The documentation for this class was generated from the following file: