ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
24 include_once("./Services/Certificate/classes/class.ilCertificate.php");
25 
34 {
40  var $object;
41 
47  var $ctrl;
48 
54  var $tree;
55 
61  var $ilias;
62 
68  var $tpl;
69 
75  var $lng;
76 
82  var $ref_id;
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 
158  public function certificateRemoveBackground()
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 
192  function certificateSave()
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  "padding_top" => ilUtil::stripSlashes($_POST["padding_top"]),
213  "margin_body_top" => ilUtil::stripSlashes($_POST["margin_body"]["top"]),
214  "margin_body_right" => ilUtil::stripSlashes($_POST["margin_body"]["right"]),
215  "margin_body_bottom" => ilUtil::stripSlashes($_POST["margin_body"]["bottom"]),
216  "margin_body_left" => ilUtil::stripSlashes($_POST["margin_body"]["left"]),
217  "certificate_text" => ilUtil::stripSlashes($_POST["certificate_text"], FALSE),
218  "pageheight" => ilUtil::stripSlashes($_POST["pageheight"]),
219  "pagewidth" => ilUtil::stripSlashes($_POST["pagewidth"]),
220  "active" => ilUtil::stripSlashes($_POST["active"])
221  );
222  $this->object->getAdapter()->addFormFieldsFromPOST($form_fields);
223  return $form_fields;
224  }
225 
229  protected function getFormFieldsFromFO()
230  {
231  $form_fields = $this->object->getFormFieldsFromFO();
232  $form_fields["active"] = $this->object->readActive();
233  $this->object->getAdapter()->addFormFieldsFromObject($form_fields);
234  return $form_fields;
235  }
236 
240  public function certificateEditor()
241  {
242  global $ilAccess;
243 
244  $form_fields = array();
245  if (strcmp($this->ctrl->getCmd(), "certificateSave") == 0)
246  {
247  $form_fields = $this->getFormFieldsFromPOST();
248  }
249  else
250  {
251  $form_fields = $this->getFormFieldsFromFO();
252  }
253  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
254  $form = new ilPropertyFormGUI();
255  $form->setFormAction($this->ctrl->getFormAction($this));
256  $form->setTitle($this->lng->txt("certificate_edit"));
257  $form->setMultipart(TRUE);
258  $form->setTableWidth("100%");
259  $form->setId("certificate");
260 
261  $active = new ilCheckboxInputGUI($this->lng->txt("active"), "active");
262  $active->setChecked($form_fields["active"]);
263  $form->addItem($active);
264 
265  $import = new ilFileInputGUI($this->lng->txt("import"), "certificate_import");
266  $import->setRequired(FALSE);
267  $import->setSuffixes(array("zip"));
268  // handle the certificate import
269  if (strlen($_FILES["certificate_import"]["tmp_name"]))
270  {
271  if ($import->checkInput())
272  {
273  $result = $this->object->importCertificate($_FILES["certificate_import"]["tmp_name"], $_FILES["certificate_import"]["name"]);
274  if ($result == FALSE)
275  {
276  $import->setAlert($this->lng->txt("certificate_error_import"));
277  }
278  else
279  {
280  $this->ctrl->redirect($this, "certificateEditor");
281  }
282  }
283  }
284  $form->addItem($import);
285 
286  $pageformat = new ilSelectInputGUI($this->lng->txt("certificate_page_format"), "pageformat");
287  $pageformats = $this->object->getPageFormats();
288  $pageformat->setValue($form_fields["pageformat"]);
289  $options = array();
290  foreach ($pageformats as $format)
291  {
292  $options[$format["value"]] = $format["name"];
293  }
294  $pageformat->setRequired(TRUE);
295  $pageformat->setOptions($options);
296  if (strcmp($this->ctrl->getCmd(), "certificateSave") == 0) $pageformat->checkInput();
297 
298  if (strcmp($form_fields["pageformat"], "custom") == 0)
299  {
300  $pageheight = new ilTextInputGUI($this->lng->txt("certificate_pageheight"), "pageheight");
301  $pageheight->setValue($form_fields["pageheight"]);
302  $pageheight->setSize(6);
303  $pageheight->setValidationRegexp("/[0123456789\\.](cm|mm|in|pt|pc|px|em)/is");
304  $pageheight->setInfo($this->lng->txt("certificate_unit_description"));
305  if (strcmp($this->ctrl->getCmd(), "certificateSave") == 0) $pageheight->checkInput();
306  $pageformat->addSubitem($pageheight);
307 
308  $pagewidth = new ilTextInputGUI($this->lng->txt("certificate_pagewidth"), "pagewidth");
309  $pagewidth->setValue($form_fields["pagewidth"]);
310  $pagewidth->setSize(6);
311  $pagewidth->setValidationRegexp("/[0123456789\\.](cm|mm|in|pt|pc|px|em)/is");
312  $pagewidth->setInfo($this->lng->txt("certificate_unit_description"));
313  if (strcmp($this->ctrl->getCmd(), "certificateSave") == 0) $pagewidth->checkInput();
314  $pageformat->addSubitem($pagewidth);
315  }
316  $form->addItem($pageformat);
317 
318  $bgimage = new ilImageFileInputGUI($this->lng->txt("certificate_background_image"), "background");
319  $bgimage->setRequired(FALSE);
320  $bgimage->setUseCache(false);
321  if (count($_POST))
322  {
323  // handle the background upload
324  if (strlen($_FILES["background"]["tmp_name"]))
325  {
326  if ($bgimage->checkInput())
327  {
328  $result = $this->object->uploadBackgroundImage($_FILES["background"]["tmp_name"]);
329  if ($result == FALSE)
330  {
331  $bgimage->setAlert($this->lng->txt("certificate_error_upload_bgimage"));
332  }
333  }
334  }
335  }
336  if (!$this->object->hasBackgroundImage())
337  {
338  include_once "./Services/Certificate/classes/class.ilObjCertificateSettingsAccess.php";
340  {
342  }
343  }
344  else
345  {
346  $bgimage->setImage($this->object->getBackgroundImageThumbPathWeb());
347  }
348  $form->addItem($bgimage);
349 
350  $padding_top = new ilTextInputGUI($this->lng->txt("certificate_padding_top"), "padding_top");
351  $padding_top->setRequired(TRUE);
352  $padding_top->setValue($form_fields["padding_top"]);
353  $padding_top->setSize(6);
354  $padding_top->setValidationRegexp("/[0123456789\\.](cm|mm|in|pt|pc|px|em)/is");
355  $padding_top->setInfo($this->lng->txt("certificate_unit_description"));
356  if (strcmp($this->ctrl->getCmd(), "certificateSave") == 0) $padding_top->checkInput();
357  $form->addItem($padding_top);
358 
359  $rect = new ilCSSRectInputGUI($this->lng->txt("certificate_margin_body"), "margin_body");
360  $rect->setRequired(TRUE);
361  $rect->setUseUnits(TRUE);
362  $rect->setTop($form_fields["margin_body_top"]);
363  $rect->setBottom($form_fields["margin_body_bottom"]);
364  $rect->setLeft($form_fields["margin_body_left"]);
365  $rect->setRight($form_fields["margin_body_right"]);
366  $rect->setInfo($this->lng->txt("certificate_unit_description"));
367  if (strcmp($this->ctrl->getCmd(), "certificateSave") == 0) $rect->checkInput();
368  $form->addItem($rect);
369 
370  $certificate = new ilTextAreaInputGUI($this->lng->txt("certificate_text"), "certificate_text");
371  $certificate->removePlugin('ilimgupload');
372  $certificate->setValue($form_fields["certificate_text"]);
373  $certificate->setRequired(TRUE);
374  $certificate->setRows(20);
375  $certificate->setCols(80);
376 
377  // fraunhpatch start
378  $common_desc_tpl = new ilTemplate("tpl.common_desc.html", true, true, "Services/Certificate");
380  {
381  $common_desc_tpl->setCurrentBlock("cert_field");
382  $common_desc_tpl->setVariable("PH", $f["ph"]);
383  $common_desc_tpl->setVariable("PH_TXT", $f["name"]);
384  $common_desc_tpl->parseCurrentBlock();
385  }
386  $common_desc = $common_desc_tpl->get();
387  // fraunhpatch start
388 
389  $certificate->setInfo($this->object->getAdapter()->getCertificateVariablesDescription().$common_desc);
390  $certificate->setUseRte(TRUE, '3.4.7');
391  $tags = array(
392  "br",
393  "em",
394  "font",
395  "li",
396  "ol",
397  "p",
398  "span",
399  "strong",
400  "u",
401  "ul"
402  );
403  $certificate->setRteTags($tags);
404  if (strcmp($this->ctrl->getCmd(), "certificateSave") == 0) $certificate->checkInput();
405  $form->addItem($certificate);
406 
407  $this->object->getAdapter()->addAdditionalFormElements($form, $form_fields);
408 
409  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]))
410  {
411  if ($this->object->isComplete() || $this->object->hasBackgroundImage())
412  {
413  $form->addCommandButton("certificatePreview", $this->lng->txt("certificate_preview"));
414  $form->addCommandButton("certificateExportFO", $this->lng->txt("certificate_export"));
415  $form->addCommandButton("certificateDelete", $this->lng->txt("delete"));
416  }
417  $form->addCommandButton("certificateSave", $this->lng->txt("save"));
418  }
419 
420  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
421 
422  if (strcmp($this->ctrl->getCmd(), "certificateSave") == 0)
423  {
424  if ($_POST["background_delete"])
425  {
426  $this->object->deleteBackgroundImage();
427  }
428  if ($form->checkInput())
429  {
430  try
431  {
432  $xslfo = $this->object->processXHTML2FO($form_fields);
433  $this->object->getAdapter()->saveFormFields($form_fields);
434  $this->object->saveCertificate($xslfo);
435  $this->object->writeActive($form_fields["active"]);
436  ilUtil::sendSuccess($this->lng->txt("saved_successfully"), TRUE);
437  $this->ctrl->redirect($this, "certificateEditor");
438  }
439  catch (Exception $e)
440  {
441  ilUtil::sendFailure($e->getMessage());
442  }
443  }
444  }
445  }
446 }