ILIAS  Release_4_2_x_branch Revision 61807
 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 
32 {
38  var $object;
39 
45  var $ctrl;
46 
52  var $tree;
53 
59  var $ilias;
60 
66  var $tpl;
67 
73  var $lng;
74 
80  var $ref_id;
81 
88  function ilCertificateGUI($adapter)
89  {
90  global $lng, $tpl, $ilCtrl, $ilias, $tree;
91 
92  include_once "./Services/Certificate/classes/class.ilCertificate.php";
93  $this->object = new ilCertificate($adapter);
94  $this->lng =& $lng;
95  $this->tpl =& $tpl;
96  $this->ctrl =& $ilCtrl;
97  $this->ilias =& $ilias;
98  $this->tree =& $tree;
99  $this->ref_id = $_GET["ref_id"];
100  $this->lng->loadLanguageModule("certificate");
101  }
102 
106  function &executeCommand()
107  {
108  $cmd = $this->ctrl->getCmd();
109  $next_class = $this->ctrl->getNextClass($this);
110 
111  $cmd = $this->getCommand($cmd);
112  switch($next_class)
113  {
114  default:
115  $ret =& $this->$cmd();
116  break;
117  }
118  return $ret;
119  }
120 
124  public function getCommand($cmd)
125  {
126  return $cmd;
127  }
128 
132  public function certificateImport()
133  {
134  $this->certificateEditor();
135  }
136 
140  public function certificatePreview()
141  {
142  $this->object->createPreview();
143  }
144 
148  public function certificateExportFO()
149  {
150  $this->object->deliverExportFileXML();
151  }
152 
156  public function certificateRemoveBackground()
157  {
158  $this->object->deleteBackgroundImage();
159  $this->certificateEditor();
160  }
161 
165  public function certificateDelete()
166  {
167  include_once("Services/Utilities/classes/class.ilSimpleConfirmationGUI.php");
168  $c_gui = new ilSimpleConfirmationGUI();
169 
170  // set confirm/cancel commands
171  $c_gui->setFormAction($this->ctrl->getFormAction($this, "certificateEditor"));
172  $c_gui->setHeaderText($this->lng->txt("certificate_confirm_deletion_text"));
173  $c_gui->setConfirm($this->lng->txt("yes"), "certificateDeleteConfirm");
174  $c_gui->setCancel($this->lng->txt("no"), "certificateEditor");
175  $this->tpl->setContent($c_gui->getHTML());
176  }
177 
181  public function certificateDeleteConfirm()
182  {
183  $this->object->deleteCertificate();
184  $this->ctrl->redirect($this, "certificateEditor");
185  }
186 
190  function certificateSave()
191  {
192  $this->certificateEditor();
193  }
194 
198  public function certificateUpload()
199  {
200  $this->certificateEditor();
201  }
202 
206  private function getFormFieldsFromPOST()
207  {
208  $form_fields = array(
209  "pageformat" => ilUtil::stripSlashes($_POST["pageformat"]),
210  "padding_top" => ilUtil::stripSlashes($_POST["padding_top"]),
211  "margin_body_top" => ilUtil::stripSlashes($_POST["margin_body"]["top"]),
212  "margin_body_right" => ilUtil::stripSlashes($_POST["margin_body"]["right"]),
213  "margin_body_bottom" => ilUtil::stripSlashes($_POST["margin_body"]["bottom"]),
214  "margin_body_left" => ilUtil::stripSlashes($_POST["margin_body"]["left"]),
215  "certificate_text" => ilUtil::stripSlashes($_POST["certificate_text"], FALSE),
216  "pageheight" => ilUtil::stripSlashes($_POST["pageheight"]),
217  "pagewidth" => ilUtil::stripSlashes($_POST["pagewidth"])
218  );
219  $this->object->getAdapter()->addFormFieldsFromPOST($form_fields);
220  return $form_fields;
221  }
222 
226  private function getFormFieldsFromFO()
227  {
228  $form_fields = $this->object->getFormFieldsFromFO();
229  $this->object->getAdapter()->addFormFieldsFromObject($form_fields);
230  return $form_fields;
231  }
232 
236  public function certificateEditor()
237  {
238  global $ilAccess;
239 
240  $form_fields = array();
241  if (strcmp($this->ctrl->getCmd(), "certificateSave") == 0)
242  {
243  $form_fields = $this->getFormFieldsFromPOST();
244  }
245  else
246  {
247  $form_fields = $this->getFormFieldsFromFO();
248  }
249  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
250  $form = new ilPropertyFormGUI();
251  $form->setFormAction($this->ctrl->getFormAction($this));
252  $form->setTitle($this->lng->txt("certificate_edit"));
253  $form->setMultipart(TRUE);
254  $form->setTableWidth("100%");
255  $form->setId("certificate");
256 
257  $import = new ilFileInputGUI($this->lng->txt("import"), "certificate_import");
258  $import->setRequired(FALSE);
259  $import->setSuffixes(array("zip"));
260  // handle the certificate import
261  if (strlen($_FILES["certificate_import"]["tmp_name"]))
262  {
263  if ($import->checkInput())
264  {
265  $result = $this->object->importCertificate($_FILES["certificate_import"]["tmp_name"], $_FILES["certificate_import"]["name"]);
266  if ($result == FALSE)
267  {
268  $import->setAlert($this->lng->txt("certificate_error_import"));
269  }
270  else
271  {
272  $this->ctrl->redirect($this, "certificateEditor");
273  }
274  }
275  }
276  $form->addItem($import);
277 
278  $pageformat = new ilSelectInputGUI($this->lng->txt("certificate_page_format"), "pageformat");
279  $pageformats = $this->object->getPageFormats();
280  $pageformat->setValue($form_fields["pageformat"]);
281  $options = array();
282  foreach ($pageformats as $format)
283  {
284  $options[$format["value"]] = $format["name"];
285  }
286  $pageformat->setRequired(TRUE);
287  $pageformat->setOptions($options);
288  if (strcmp($this->ctrl->getCmd(), "certificateSave") == 0) $pageformat->checkInput();
289 
290  if (strcmp($form_fields["pageformat"], "custom") == 0)
291  {
292  $pageheight = new ilTextInputGUI($this->lng->txt("certificate_pageheight"), "pageheight");
293  $pageheight->setValue($form_fields["pageheight"]);
294  $pageheight->setSize(6);
295  $pageheight->setValidationRegexp("/[0123456789\\.](cm|mm|in|pt|pc|px|em)/is");
296  $pageheight->setInfo($this->lng->txt("certificate_unit_description"));
297  if (strcmp($this->ctrl->getCmd(), "certificateSave") == 0) $pageheight->checkInput();
298  $pageformat->addSubitem($pageheight);
299 
300  $pagewidth = new ilTextInputGUI($this->lng->txt("certificate_pagewidth"), "pagewidth");
301  $pagewidth->setValue($form_fields["pagewidth"]);
302  $pagewidth->setSize(6);
303  $pagewidth->setValidationRegexp("/[0123456789\\.](cm|mm|in|pt|pc|px|em)/is");
304  $pagewidth->setInfo($this->lng->txt("certificate_unit_description"));
305  if (strcmp($this->ctrl->getCmd(), "certificateSave") == 0) $pagewidth->checkInput();
306  $pageformat->addSubitem($pagewidth);
307  }
308  $form->addItem($pageformat);
309 
310  $bgimage = new ilImageFileInputGUI($this->lng->txt("certificate_background_image"), "background");
311  $bgimage->setRequired(FALSE);
312  $bgimage->setUseCache(false);
313  if (count($_POST))
314  {
315  // handle the background upload
316  if (strlen($_FILES["background"]["tmp_name"]))
317  {
318  if ($bgimage->checkInput())
319  {
320  $result = $this->object->uploadBackgroundImage($_FILES["background"]["tmp_name"]);
321  if ($result == FALSE)
322  {
323  $bgimage->setAlert($this->lng->txt("certificate_error_upload_bgimage"));
324  }
325  }
326  }
327  }
328  if (!$this->object->hasBackgroundImage())
329  {
330  include_once "./Services/Certificate/classes/class.ilObjCertificateSettingsAccess.php";
332  {
334  }
335  }
336  else
337  {
338  $bgimage->setImage($this->object->getBackgroundImageThumbPathWeb());
339  }
340  $form->addItem($bgimage);
341 
342  $padding_top = new ilTextInputGUI($this->lng->txt("certificate_padding_top"), "padding_top");
343  $padding_top->setRequired(TRUE);
344  $padding_top->setValue($form_fields["padding_top"]);
345  $padding_top->setSize(6);
346  $padding_top->setValidationRegexp("/[0123456789\\.](cm|mm|in|pt|pc|px|em)/is");
347  $padding_top->setInfo($this->lng->txt("certificate_unit_description"));
348  if (strcmp($this->ctrl->getCmd(), "certificateSave") == 0) $padding_top->checkInput();
349  $form->addItem($padding_top);
350 
351  $rect = new ilCSSRectInputGUI($this->lng->txt("certificate_margin_body"), "margin_body");
352  $rect->setRequired(TRUE);
353  $rect->setUseUnits(TRUE);
354  $rect->setTop($form_fields["margin_body_top"]);
355  $rect->setBottom($form_fields["margin_body_bottom"]);
356  $rect->setLeft($form_fields["margin_body_left"]);
357  $rect->setRight($form_fields["margin_body_right"]);
358  $rect->setInfo($this->lng->txt("certificate_unit_description"));
359  if (strcmp($this->ctrl->getCmd(), "certificateSave") == 0) $rect->checkInput();
360  $form->addItem($rect);
361 
362  $certificate = new ilTextAreaInputGUI($this->lng->txt("certificate_text"), "certificate_text");
363  $certificate->setValue($form_fields["certificate_text"]);
364  $certificate->setRequired(TRUE);
365  $certificate->setRows(20);
366  $certificate->setCols(80);
367  $certificate->setInfo($this->object->getAdapter()->getCertificateVariablesDescription());
368  $certificate->setUseRte(TRUE);
369  $tags = array(
370  "br",
371  "em",
372  "font",
373  "li",
374  "ol",
375  "p",
376  "span",
377  "strong",
378  "u",
379  "ul"
380  );
381  $certificate->setRteTags($tags);
382  if (strcmp($this->ctrl->getCmd(), "certificateSave") == 0) $certificate->checkInput();
383  $form->addItem($certificate);
384 
385  $this->object->getAdapter()->addAdditionalFormElements($form, $form_fields);
386 
387  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]))
388  {
389  if ($this->object->isComplete() || $this->object->hasBackgroundImage())
390  {
391  $form->addCommandButton("certificatePreview", $this->lng->txt("certificate_preview"));
392  $form->addCommandButton("certificateExportFO", $this->lng->txt("certificate_export"));
393  $form->addCommandButton("certificateDelete", $this->lng->txt("delete"));
394  }
395  $form->addCommandButton("certificateSave", $this->lng->txt("save"));
396  }
397 
398  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
399 
400  if (strcmp($this->ctrl->getCmd(), "certificateSave") == 0)
401  {
402  if ($_POST["background_delete"])
403  {
404  $this->object->deleteBackgroundImage();
405  }
406  if ($form->checkInput())
407  {
408  try
409  {
410  $xslfo = $this->object->processXHTML2FO($form_fields);
411  $this->object->getAdapter()->saveFormFields($form_fields);
412  $this->object->saveCertificate($xslfo);
413  ilUtil::sendSuccess($this->lng->txt("saved_successfully"), TRUE);
414  $this->ctrl->redirect($this, "certificateEditor");
415  }
416  catch (Exception $e)
417  {
418  ilUtil::sendFailure($e->getMessage());
419  }
420  }
421  }
422  }
423 }
424 
425 ?>