ILIAS  release_4-3 Revision
 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.
 readActive ()
 writeActive ($a_value)
 getExchangeContent ()
 outCertificateWithGivenContentAndVariables ($content, $insert_tags)

Static Public Member Functions

static _getXSLName ()
 Returns the filename of the XSL-FO file.
static isActive ()
static isObjectActive ($a_obj_id)
static areObjectsActive (array $a_obj_ids)
static _goto ($ref_id)
 Creates a redirect to a certificate download.
static getCustomCertificateFields ()
 Get custom certificate fields.

Protected Attributes

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

Static Protected Attributes

static $is_active

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$

Definition at line 15 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 66 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 143 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 1003 of file class.ilCertificate.php.

{
global $ilCtrl;
include_once "./Services/Object/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:
$ilCtrl->redirectByClass("ilrepositorygui", "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 660 of file class.ilCertificate.php.

References $adapter, and _getXSLName().

Referenced by ilExerciseVerificationTableGUI\getItems(), ilTestEvaluationGUI\outEvaluation(), and ilObjExerciseGUI\showOverviewObject().

{
if (is_object($adapter) && method_exists($adapter, "getCertificatePath"))
{
if(self::isActive())
{
$obj_id = $adapter->getCertificateID();
if($obj_id && !self::isObjectActive($obj_id))
{
return FALSE;
}
$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 899 of file class.ilCertificate.php.

{
$fh = fopen($dir . $filename, "wb");
fwrite($fh, $pdfdata);
fclose($fh);
}
static ilCertificate::areObjectsActive ( array  $a_obj_ids)
static

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

Referenced by ilCourseCertificateAdapter\_preloadListData().

{
global $ilDB;
$all = array();
foreach($a_obj_ids as $id)
{
$all[$id] = false;
}
$set = $ilDB->query("SELECT obj_id FROM il_certificate".
" WHERE ".$ilDB->in("obj_id", $a_obj_ids, "", "integer"));
while($row = $ilDB->fetchAssoc($set))
{
$all[$row["obj_id"]] = true;
}
return $all;
}

+ Here is the caller graph for this function:

ilCertificate::cloneCertificate (   $newObject)

Clone the certificate for another test object.

Parameters
$newObjectThe new certificate object

Definition at line 201 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 884 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 510 of file class.ilCertificate.php.

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

{
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 178 of file class.ilCertificate.php.

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

{
$result = TRUE;
if (file_exists($this->getBackgroundImageThumbPath()))
{
}
if (file_exists($this->getBackgroundImagePath()))
{
$result = $result & unlink($this->getBackgroundImagePath());
}
if (file_exists($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 227 of file class.ilCertificate.php.

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

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

+ Here is the call graph for this function:

ilCertificate::deliverExportFileXML ( )

Builds an export file in ZIP format and delivers it.

Definition at line 742 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 423 of file class.ilCertificate.php.

References getAdapter().

Referenced by createPreview(), and outCertificate().

{
if (count($insert_tags) == 0)
{
$insert_tags = $this->getAdapter()->getCertificateVariablesForPreview();
foreach (self::getCustomCertificateFields() as $k => $f)
{
$insert_tags[$f["ph"]] = $f["name"];
}
}
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 93 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 83 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 153 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 113 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 103 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 166 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:

static ilCertificate::getCustomCertificateFields ( )
static

Get custom certificate fields.

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

Referenced by ilCertificateGUI\certificateEditor().

{
include_once("./Services/User/classes/class.ilUserDefinedFields.php");
$user_field_definitions = ilUserDefinedFields::_getInstance();
$fds = $user_field_definitions->getDefinitions();
$fields = array();
foreach ($fds as $f)
{
if ($f["certificate"])
{
$fields[$f["field_id"]] = array("name" => $f["field_name"],
"ph" => "[#".str_replace(" ", "_", strtoupper($f["field_name"]))."]");
}
}
return $fields;
}

+ Here is the caller graph for this function:

ilCertificate::getExchangeContent ( )
Returns
string

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

{
if(!file_exists($this->getXSLPath()))
{
return '';
}
$output = '';
$xsl_file_content = file_get_contents($this->getXSLPath());
$xsl = file_get_contents("./Services/Certificate/xml/fo2xhtml.xsl");
if((strlen($xsl_file_content)) && (strlen($xsl)))
{
$args = array('/_xml' => $xsl_file_content, '/_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);
return $output;
}
ilCertificate::getFormFieldsFromFO ( )

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

Definition at line 241 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";
}
else
{
$pagesize = "custom";
}
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))
{
// Backwards compatibility
$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];
}
}
else if(preg_match("/fo:region-body[^>]*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 691 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"), // (8.5 inch x 11 inch)
"value" => "letterlandscape",
"width" => "11in",
"height" => "8.5in"
),
"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 133 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 123 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 617 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 775 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:

static ilCertificate::isActive ( )
static

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

Referenced by ilCourseParticipantsTableGUI\__construct(), ilObjSAHSLearningModuleAccess\_lookupUserCertificate(), ilCourseCertificateAdapter\_preloadListData(), ilObjCourseGUI\deliverCertificateObject(), ilObjTestGUI\getSettingsSubTabs(), ilObjSAHSLearningModuleGUI\getTabs(), ilObjExercise\hasUserCertificate(), ilObjCourseGUI\initHeaderAction(), ilObjExerciseGUI\setSettingsSubTabs(), and ilObjCourseGUI\setSubTabs().

{
if(self::$is_active === null)
{
// basic admin setting active?
$certificate_active = new ilSetting("certificate");
$certificate_active = (bool)$certificate_active->get("active");
// java/rtpc-server active?
if($certificate_active)
{
include_once './Services/WebServices/RPC/classes/class.ilRPCServerSettings.php';
$certificate_active = ilRPCServerSettings::getInstance()->isEnabled();
}
self::$is_active = (bool)$certificate_active;
}
}

+ Here is the caller 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 634 of file class.ilCertificate.php.

References getAdapter(), and getXSLPath().

{
if(self::isActive())
{
$obj_id = $this->getAdapter()->getCertificateID();
if($obj_id && !self::isObjectActive($obj_id))
{
return FALSE;
}
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:

static ilCertificate::isObjectActive (   $a_obj_id)
static
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 446 of file class.ilCertificate.php.

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

{
global $ilLog;
$insert_tags = $this->getAdapter()->getCertificateVariablesForPresentation($params);
include_once("./Services/User/classes/class.ilUserDefinedData.php");
$cust_data = new ilUserDefinedData($this->getAdapter()->getUserIdForParams($params));
$cust_data = $cust_data->getAll();
foreach (self::getCustomCertificateFields() as $k => $f)
{
$insert_tags[$f["ph"]] = $cust_data["f_".$k];
}
$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::outCertificateWithGivenContentAndVariables (   $content,
  $insert_tags 
)

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

{
global $ilLog;
$form_fields = $this->getFormFieldsFromFO();
$form_fields['certificate_text'] = $content;
$xslfo = $this->processXHTML2FO($form_fields);
$content = $this->exchangeCertificateVariables($xslfo, $insert_tags);
$content = str_replace('[BR]', "<fo:block/>", $content);
include_once './Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
try
{
$pdf_base64 = ilRpcClientFactory::factory('RPCTransformationHandler')->ilFO2PDF($content);
include_once "./Services/Utilities/classes/class.ilUtil.php";
ilUtil::deliverData($pdf_base64->scalar, $this->getAdapter()->getCertificateFilename(array()), "application/pdf");
}
{
$ilLog->write(__METHOD__.': '.$e->getMessage());
return false;
}
catch(Exception $e)
{
$ilLog->write(__METHOD__.': '.$e->getMessage());
return false;
}
}
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 359 of file class.ilCertificate.php.

References $GLOBALS, 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");
// additional font support
$xsl = str_replace(
'font-family="Helvetica, unifont"',
'font-family="'.$GLOBALS['ilSetting']->get('rpc_pdf_font','Helvetica, unifont').'"',
$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::readActive ( )

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

{
global $ilDB;
$obj_id = $this->adapter->getCertificateID();
$set = $ilDB->query("SELECT obj_id FROM il_certificate".
" WHERE obj_id = ".$ilDB->quote($obj_id, "integer"));
return $ilDB->numRows($set);
}
ilCertificate::saveCertificate (   $xslfo,
  $filename = "" 
)

Saves the XSL-FO code to a file.

Parameters
string$xslfoXSL-FO code

Definition at line 554 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 870 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 576 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::writeActive (   $a_value)

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

Referenced by deleteCertificate().

{
global $ilDB;
$obj_id = $this->adapter->getCertificateID();
if((bool)$a_value)
{
$ilDB->replace("il_certificate",
array("obj_id"=>array("integer", $obj_id)),
array());
}
else
{
$ilDB->manipulate("DELETE FROM il_certificate".
" WHERE obj_id = ".$ilDB->quote($obj_id, "integer"));
}
}

+ Here is the caller 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 913 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 57 of file class.ilCertificate.php.

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

ilCertificate::$ctrl
protected

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

ilCertificate::$ilias
protected

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

Referenced by __construct().

ilCertificate::$is_active
staticprotected

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

ilCertificate::$lng
protected

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

Referenced by __construct().

ilCertificate::$tpl
protected

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

Referenced by __construct().

ilCertificate::$tree
protected

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

Referenced by __construct().


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