ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilCertificateGUI.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
24include_once("./Services/Certificate/classes/class.ilCertificate.php");
25
34{
41
47 var $ctrl;
48
54 var $tree;
55
61 var $ilias;
62
68 var $tpl;
69
75 var $lng;
76
83
90 function ilCertificateGUI($adapter)
91 {
92 global $lng, $tpl, $ilCtrl, $ilias, $tree;
93
94 include_once "./Services/Certificate/classes/class.ilCertificate.php";
95 $this->object = new ilCertificate($adapter);
96 $this->lng =& $lng;
97 $this->tpl =& $tpl;
98 $this->ctrl =& $ilCtrl;
99 $this->ilias =& $ilias;
100 $this->tree =& $tree;
101 $this->ref_id = $_GET["ref_id"];
102 $this->lng->loadLanguageModule("certificate");
103 }
104
108 function &executeCommand()
109 {
110 $cmd = $this->ctrl->getCmd();
111 $next_class = $this->ctrl->getNextClass($this);
112
113 $cmd = $this->getCommand($cmd);
114 switch($next_class)
115 {
116 default:
117 $ret =& $this->$cmd();
118 break;
119 }
120 return $ret;
121 }
122
126 public function getCommand($cmd)
127 {
128 return $cmd;
129 }
130
134 public function certificateImport()
135 {
136 $this->certificateEditor();
137 }
138
142 public function certificatePreview()
143 {
144 $this->object->createPreview();
145 }
146
150 public function certificateExportFO()
151 {
152 $this->object->deliverExportFileXML();
153 }
154
159 {
160 $this->object->deleteBackgroundImage();
161 $this->certificateEditor();
162 }
163
167 public function certificateDelete()
168 {
169 // display confirmation message
170 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
171 $cgui = new ilConfirmationGUI();
172 $cgui->setFormAction($this->ctrl->getFormAction($this, "certificateEditor"));
173 $cgui->setHeaderText($this->lng->txt("certificate_confirm_deletion_text"));
174 $cgui->setCancel($this->lng->txt("no"), "certificateEditor");
175 $cgui->setConfirm($this->lng->txt("yes"), "certificateDeleteConfirm");
176
177 $this->tpl->setContent($cgui->getHTML());
178 }
179
183 public function certificateDeleteConfirm()
184 {
185 $this->object->deleteCertificate();
186 $this->ctrl->redirect($this, "certificateEditor");
187 }
188
193 {
194 $this->certificateEditor();
195 }
196
200 public function certificateUpload()
201 {
202 $this->certificateEditor();
203 }
204
208 protected function getFormFieldsFromPOST()
209 {
210 $form_fields = array(
211 "pageformat" => ilUtil::stripSlashes($_POST["pageformat"]),
212 "margin_body_top" => ilUtil::stripSlashes($_POST["margin_body"]["top"]),
213 "margin_body_right" => ilUtil::stripSlashes($_POST["margin_body"]["right"]),
214 "margin_body_bottom" => ilUtil::stripSlashes($_POST["margin_body"]["bottom"]),
215 "margin_body_left" => ilUtil::stripSlashes($_POST["margin_body"]["left"]),
216 "certificate_text" => ilUtil::stripSlashes($_POST["certificate_text"], FALSE),
217 "pageheight" => ilUtil::stripSlashes($_POST["pageheight"]),
218 "pagewidth" => ilUtil::stripSlashes($_POST["pagewidth"]),
219 "active" => ilUtil::stripSlashes($_POST["active"])
220 );
221 $this->object->getAdapter()->addFormFieldsFromPOST($form_fields);
222 return $form_fields;
223 }
224
228 protected function getFormFieldsFromFO()
229 {
230 $form_fields = $this->object->getFormFieldsFromFO();
231 $form_fields["active"] = $this->object->readActive();
232 $this->object->getAdapter()->addFormFieldsFromObject($form_fields);
233 return $form_fields;
234 }
235
239 public function certificateEditor()
240 {
244 global $ilAccess, $ilToolbar;
245
246 $form_fields = array();
247 if (strcmp($this->ctrl->getCmd(), "certificateSave") == 0)
248 {
249 $form_fields = $this->getFormFieldsFromPOST();
250 }
251 else
252 {
253 $form_fields = $this->getFormFieldsFromFO();
254 }
255 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
256 $form = new ilPropertyFormGUI();
257 $form->setPreventDoubleSubmission(false);
258 $form->setFormAction($this->ctrl->getFormAction($this));
259 $form->setTitle($this->lng->txt("certificate_edit"));
260 $form->setMultipart(TRUE);
261 $form->setTableWidth("100%");
262 $form->setId("certificate");
263
264 $active = new ilCheckboxInputGUI($this->lng->txt("active"), "active");
265 $active->setChecked($form_fields["active"]);
266 $form->addItem($active);
267
268 $import = new ilFileInputGUI($this->lng->txt("import"), "certificate_import");
269 $import->setRequired(FALSE);
270 $import->setSuffixes(array("zip"));
271 // handle the certificate import
272 if (strlen($_FILES["certificate_import"]["name"]))
273 {
274 if ($import->checkInput())
275 {
276 $result = $this->object->importCertificate($_FILES["certificate_import"]["tmp_name"], $_FILES["certificate_import"]["name"]);
277 if ($result == FALSE)
278 {
279 $import->setAlert($this->lng->txt("certificate_error_import"));
280 }
281 else
282 {
283 $this->ctrl->redirect($this, "certificateEditor");
284 }
285 }
286 }
287 $form->addItem($import);
288
289 $pageformat = new ilRadioGroupInputGUI($this->lng->txt("certificate_page_format"), "pageformat");
290 $pageformats = $this->object->getPageFormats();
291 $pageformat->setValue($form_fields["pageformat"]);
292 foreach($pageformats as $format)
293 {
294 $option = new ilRadioOption($format["name"], $format["value"]);
295 if(strcmp($format["value"], "custom") == 0)
296 {
297 $pageheight = new ilTextInputGUI($this->lng->txt("certificate_pageheight"), "pageheight");
298 $pageheight->setValue($form_fields["pageheight"]);
299 $pageheight->setSize(6);
300 $pageheight->setValidationRegexp("/[0123456789\\.](cm|mm|in|pt|pc|px|em)/is");
301 $pageheight->setInfo($this->lng->txt("certificate_unit_description"));
302 $pageheight->setRequired(true);
303 $option->addSubitem($pageheight);
304
305 $pagewidth = new ilTextInputGUI($this->lng->txt("certificate_pagewidth"), "pagewidth");
306 $pagewidth->setValue($form_fields["pagewidth"]);
307 $pagewidth->setSize(6);
308 $pagewidth->setValidationRegexp("/[0123456789\\.](cm|mm|in|pt|pc|px|em)/is");
309 $pagewidth->setInfo($this->lng->txt("certificate_unit_description"));
310 $pagewidth->setRequired(true);
311 $option->addSubitem($pagewidth);
312 }
313 $pageformat->addOption($option);
314 }
315 $pageformat->setRequired(true);
316 if (strcmp($this->ctrl->getCmd(), "certificateSave") == 0) $pageformat->checkInput();
317
318 $form->addItem($pageformat);
319
320 $bgimage = new ilImageFileInputGUI($this->lng->txt("certificate_background_image"), "background");
321 $bgimage->setRequired(FALSE);
322 $bgimage->setUseCache(false);
323 if (count($_POST))
324 {
325 // handle the background upload
326 if (strlen($_FILES["background"]["tmp_name"]))
327 {
328 if ($bgimage->checkInput())
329 {
330 $result = $this->object->uploadBackgroundImage($_FILES["background"]["tmp_name"]);
331 if ($result == FALSE)
332 {
333 $bgimage->setAlert($this->lng->txt("certificate_error_upload_bgimage"));
334 }
335 }
336 }
337 }
338 if (!$this->object->hasBackgroundImage())
339 {
340 include_once "./Services/Certificate/classes/class.ilObjCertificateSettingsAccess.php";
342 {
343 require_once('./Services/WebAccessChecker/classes/class.ilWACSignedPath.php');
346 }
347 }
348 else
349 {
350 require_once('./Services/WebAccessChecker/classes/class.ilWACSignedPath.php');
352 $bgimage->setImage(ilWACSignedPath::signFile($this->object->getBackgroundImageThumbPathWeb()));
353 }
354 $form->addItem($bgimage);
355
356 $rect = new ilCSSRectInputGUI($this->lng->txt("certificate_margin_body"), "margin_body");
357 $rect->setRequired(TRUE);
358 $rect->setUseUnits(TRUE);
359 $rect->setTop($form_fields["margin_body_top"]);
360 $rect->setBottom($form_fields["margin_body_bottom"]);
361 $rect->setLeft($form_fields["margin_body_left"]);
362 $rect->setRight($form_fields["margin_body_right"]);
363 $rect->setInfo($this->lng->txt("certificate_unit_description"));
364 if (strcmp($this->ctrl->getCmd(), "certificateSave") == 0) $rect->checkInput();
365 $form->addItem($rect);
366
367 $certificate = new ilTextAreaInputGUI($this->lng->txt("certificate_text"), "certificate_text");
368 $certificate->removePlugin('ilimgupload');
369 $certificate->setValue($form_fields["certificate_text"]);
370 $certificate->setRequired(TRUE);
371 $certificate->setRows(20);
372 $certificate->setCols(80);
373
374 // fraunhpatch start
375 $common_desc_tpl = new ilTemplate("tpl.common_desc.html", true, true, "Services/Certificate");
377 {
378 $common_desc_tpl->setCurrentBlock("cert_field");
379 $common_desc_tpl->setVariable("PH", $f["ph"]);
380 $common_desc_tpl->setVariable("PH_TXT", $f["name"]);
381 $common_desc_tpl->parseCurrentBlock();
382 }
383 $common_desc = $common_desc_tpl->get();
384 // fraunhpatch start
385
386 $certificate->setInfo($this->object->getAdapter()->getCertificateVariablesDescription().$common_desc);
387 $certificate->setUseRte(TRUE, '3.4.7');
388 $tags = array(
389 "br",
390 "em",
391 "font",
392 "li",
393 "ol",
394 "p",
395 "span",
396 "strong",
397 "u",
398 "ul"
399 );
400 $certificate->setRteTags($tags);
401 if (strcmp($this->ctrl->getCmd(), "certificateSave") == 0) $certificate->checkInput();
402 $form->addItem($certificate);
403
404 $this->object->getAdapter()->addAdditionalFormElements($form, $form_fields);
405
406 if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]))
407 {
408 if ($this->object->isComplete() || $this->object->hasBackgroundImage())
409 {
410 $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
411
412 require_once 'Services/UIComponent/Button/classes/class.ilSubmitButton.php';
414 $preview->setCaption('certificate_preview');
415 $preview->setCommand('certificatePreview');
416 $ilToolbar->addStickyItem($preview);
417
418 $export = ilSubmitButton::getInstance();
419 $export->setCaption('certificate_export');
420 $export->setCommand('certificateExportFO');
421 $ilToolbar->addButtonInstance($export);
422
423 $delete = ilSubmitButton::getInstance();
424 $delete->setCaption('delete');
425 $delete->setCommand('certificateDelete');
426 $ilToolbar->addButtonInstance($delete);
427 }
428 $form->addCommandButton("certificateSave", $this->lng->txt("save"));
429 }
430
431 $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
432
433 if (strcmp($this->ctrl->getCmd(), "certificateSave") == 0)
434 {
435 if ($_POST["background_delete"])
436 {
437 $this->object->deleteBackgroundImage();
438 }
439 if ($form->checkInput())
440 {
441 try
442 {
443 $xslfo = $this->object->processXHTML2FO($form_fields);
444 $this->object->getAdapter()->saveFormFields($form_fields);
445 $this->object->saveCertificate($xslfo);
446 $this->object->writeActive($form_fields["active"]);
447 ilUtil::sendSuccess($this->lng->txt("saved_successfully"), TRUE);
448 $this->ctrl->redirect($this, "certificateEditor");
449 }
450 catch (Exception $e)
451 {
452 ilUtil::sendFailure($e->getMessage());
453 }
454 }
455 }
456 }
457}
458
459?>
$result
$_GET["client_id"]
This class represents a text property in a property form.
GUI class to create PDF certificates.
certificateExportFO()
Exports the certificate.
getFormFieldsFromFO()
Get the form values from the certificate xsl-fo.
certificatePreview()
Creates a certificate preview.
certificateImport()
Import a certificate from a ZIP archive.
certificateDelete()
Deletes the certificate and all its data.
getCommand($cmd)
Retrieves the ilCtrl command.
certificateUpload()
Uploads the certificate.
certificateSave()
Saves the certificate.
certificateDeleteConfirm()
Deletes the certificate and all its data.
getFormFieldsFromPOST()
Get the form values from an HTTP POST.
certificateRemoveBackground()
Removes the background image of a certificate.
& executeCommand()
execute command
ilCertificateGUI($adapter)
ilCertificateGUI constructor
Create PDF certificates.
static getCustomCertificateFields()
Get custom certificate fields.
This class represents a checkbox property in a property form.
Confirmation screen class.
This class represents a file property in a property form.
This class represents an image file property in a property form.
static hasBackgroundImage()
Returns wheather or not a default background image exists.
static getBackgroundImageThumbPathWeb()
Returns the web path of the background image thumbnail.
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
static getInstance()
Factory.
special template class to simplify handling of ITX/PEAR
This class represents a text area property in a property form.
This class represents a text property in a property form.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static signFile($path_to_file)
static setTokenMaxLifetimeInSeconds($token_max_lifetime_in_seconds)
$_POST['username']
Definition: cron.php:12
if(@file_exists(dirname(__FILE__).'/lang/eng.php')) $certificate
Definition: example_052.php:77
global $ilCtrl
Definition: ilias.php:18
redirection script todo: (a better solution should control the processing via a xml file)
$cmd
Definition: sahs_server.php:35
$preview