ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTestCertificateGUI.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 
35 {
43  var $object;
51  var $ctrl;
59  var $tree;
67  var $ilias;
68 
76  var $tpl;
77 
85  var $lng;
86  var $ref_id;
87 
97  function ilTestCertificateGUI(&$a_object)
98  {
99  global $lng, $tpl, $ilCtrl, $ilias, $tree;
100 
101  include_once "./Modules/Test/classes/class.ilTestCertificate.php";
102  $this->object = new ilTestCertificate($a_object);
103  $this->lng =& $lng;
104  $this->tpl =& $tpl;
105  $this->ctrl =& $ilCtrl;
106  $this->ilias =& $ilias;
107  $this->tree =& $tree;
108  $this->ref_id = $_GET["ref_id"];
109  }
110 
114  function &executeCommand()
115  {
116  $cmd = $this->ctrl->getCmd();
117  $next_class = $this->ctrl->getNextClass($this);
118 
119  $cmd = $this->getCommand($cmd);
120  switch($next_class)
121  {
122  default:
123  $ret =& $this->$cmd();
124  break;
125  }
126  return $ret;
127  }
128 
136  function getCommand($cmd)
137  {
138  return $cmd;
139  }
140 
148  function certificateImport()
149  {
150  $this->certificateEditor();
151  }
152 
161  {
162  $this->object->createPreview();
163  $this->certificateEditor();
164  }
165 
174  function exportCertificate()
175  {
176  $this->object->outCertificates($_GET["g_userfilter"], $_GET["g_passedonly"]);
177  }
178 
187  {
188  $this->object->deliverExportFileXML();
189  }
190 
191 
199  function certificateOutput()
200  {
201  $this->object->outCertificate($_GET["active_id"], $_GET["pass"]);
202  }
203 
212  {
213  $this->object->deleteBackgroundImage();
214  $this->certificateEditor();
215  }
216 
218  {
219  $form_fields = array(
220  "pageformat" => ilUtil::stripSlashes($_POST["pageformat"]),
221  "padding_top" => ilUtil::stripSlashes($_POST["padding_top"]),
222  "margin_body_top" => ilUtil::stripSlashes($_POST["margin_body_top"]),
223  "margin_body_right" => ilUtil::stripSlashes($_POST["margin_body_right"]),
224  "margin_body_bottom" => ilUtil::stripSlashes($_POST["margin_body_bottom"]),
225  "margin_body_left" => ilUtil::stripSlashes($_POST["margin_body_left"]),
226  "certificate_text" => ilUtil::stripSlashes($_POST["certificate_text"], FALSE),
227  "pageheight" => ilUtil::stripSlashes($_POST["pageheight"]),
228  "pagewidth" => ilUtil::stripSlashes($_POST["pagewidth"]),
229  "certificate_visibility" => ilUtil::stripSlashes($_POST["certificate_visibility"])
230  );
231  return $form_fields;
232  }
233 
241  function certificateDelete()
242  {
243  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.confirm_deletion.html", "Modules/Test");
244 
245  $this->tpl->setCurrentBlock("table_header");
246  $this->tpl->setVariable("TEXT", $this->lng->txt("confirmation"));
247  $this->tpl->parseCurrentBlock();
248  $this->tpl->setCurrentBlock("table_row");
249  $this->tpl->setVariable("CSS_ROW", "tblrow1");
250  $this->tpl->setVariable("TEXT_CONTENT", $this->lng->txt("certificate_confirm_deletion_text"));
251  $this->tpl->parseCurrentBlock();
252  $this->tpl->setCurrentBlock("operation_btn");
253  $this->tpl->setVariable("BTN_NAME", "certificateDeleteConfirm");
254  $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("yes"));
255  $this->tpl->parseCurrentBlock();
256  $this->tpl->setCurrentBlock("operation_btn");
257  $this->tpl->setVariable("BTN_NAME", "certificateEditor");
258  $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("no"));
259  $this->tpl->parseCurrentBlock();
260  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "certificateEditor"));
261  }
262 
271  {
272  $this->object->deleteCertificate();
273  $this->ctrl->redirect($this, "certificateEditor");
274  }
275 
283  function certificateSave()
284  {
285  $this->certificateEditor();
286  }
287 
295  function certificateUpload()
296  {
297  $this->certificateEditor();
298  }
299 
307  function certificateEditor()
308  {
309  global $ilAccess;
310  if (!$ilAccess->checkAccess("write", "", $this->ref_id))
311  {
312  // allow only write access
313  ilUtil::sendInfo($this->lng->txt("cannot_edit_test"), true);
314  $this->ctrl->redirectByClass("ilobjtestgui", "infoScreen");
315  }
316  $form_fields = array();
317  if (is_array($_POST))
318  {
319  if (count($_POST) > 0)
320  {
321  // handle the form post
322 
323  // handle the certificate import
324  if (strlen($_FILES["certificate_import"]["tmp_name"]))
325  {
326  $result = $this->object->importCertificate($_FILES["certificate_import"]["tmp_name"], $_FILES["certificate_import"]["name"]);
327  if ($result == FALSE)
328  {
329  ilUtil::sendInfo($this->lng->txt("certificate_error_import"));
330  }
331  else
332  {
333  $this->ctrl->redirect($this, "certificateEditor");
334  }
335  }
336 
337  // handle the file upload
338  if (strlen($_FILES["background"]["tmp_name"]))
339  {
340  $result = $this->object->uploadBackgroundImage($_FILES["background"]["tmp_name"]);
341  if ($result == FALSE)
342  {
343  ilUtil::sendInfo($this->lng->txt("certificate_error_upload_bgimage"));
344  }
345  }
346  $form_fields = $this->getFormFieldsFromPOST();
347  }
348  else
349  {
350  $form_fields = $this->object->processFO2XHTML();
351  }
352  }
353 
354  if ((strcmp($this->ctrl->getCmd(), "certificateSave") == 0) || (strcmp($this->ctrl->getCmd(), "certificateRemoveBackground") == 0))
355  {
356  // try to save the certificate to an XSL-FO document
357  // 1. run checks on all input fields
358  $result = $this->object->checkCertificateInput($form_fields);
359  if ($result !== TRUE)
360  {
362  }
363  else
364  {
365  $xslfo = $this->object->processXHTML2FO($form_fields);
366  $this->object->saveCertificateVisibility($form_fields["certificate_visibility"]);
367  $this->object->saveCertificate($xslfo);
368  }
369  }
370 
371  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_certificate_edit.html", "Modules/Test");
372 
373  if ($this->object->hasBackgroundImage())
374  {
375  $this->tpl->setCurrentBlock("background_exists");
376  $this->tpl->setVariable("BACKGROUND_THUMBNAIL", $this->object->getBackgroundImagePathWeb() . ".thumb.jpg");
377  $this->tpl->setVariable("THUMBNAIL_ALT", $this->lng->txt("preview"));
378  $this->tpl->setVariable("DELETE_BUTTON", $this->lng->txt("delete"));
379  $this->tpl->parseCurrentBlock();
380  }
381 
382  $pageformats = $this->object->getPageFormats();
383  foreach ($pageformats as $pageformat)
384  {
385  $this->tpl->setCurrentBlock("page_format_row");
386  $this->tpl->setVariable("VALUE_PAGE_FORMAT", $pageformat["value"]);
387  $this->tpl->setVariable("NAME_PAGE_FORMAT", $pageformat["name"]);
388  if (strcmp($form_fields["pageformat"], $pageformat["value"]) == 0)
389  {
390  $this->tpl->setVariable("SELECTED_PAGE_FORMAT", " selected=\"selected\"");
391  }
392  $this->tpl->parseCurrentBlock();
393  }
394 
395  if (strcmp($form_fields["pageformat"], "custom") == 0)
396  {
397  $this->tpl->setCurrentBlock("custom_format");
398  $this->tpl->setVariable("TEXT_PAGE_UNIT_DESCRIPTION", $this->lng->txt("certificate_unit_description"));
399  $this->tpl->setVariable("TEXT_PAGEHEIGHT", $this->lng->txt("certificate_pageheight"));
400  $this->tpl->setVariable("TEXT_PAGEWIDTH", $this->lng->txt("certificate_pagewidth"));
401  if (strlen($form_fields["pageheight"]))
402  {
403  $this->tpl->setVariable("VALUE_PAGEHEIGHT", " value=\"".$form_fields["pageheight"]."\"");
404  }
405  if (strlen($form_fields["pagewidth"]))
406  {
407  $this->tpl->setVariable("VALUE_PAGEWIDTH", " value=\"".$form_fields["pagewidth"]."\"");
408  }
409  $this->tpl->parseCurrentBlock();
410  }
411 
412  $this->tpl->setVariable("TEXT_CERTIFICATE", $this->lng->txt("certificate_edit"));
413  $this->tpl->setVariable("TEXT_STATUS", $this->lng->txt("certificate_status"));
414  if ($this->object->isComplete() || $this->object->hasBackgroundImage())
415  {
416  $this->tpl->setVariable("DELETE_BUTTON_CERTIFICATE", $this->lng->txt("certificate_delete"));
417  }
418  if ($this->object->isComplete())
419  {
420  $this->tpl->setVariable("VALUE_STATUS", $this->lng->txt("certificate_status_complete"));
421  include_once "./Services/Utilities/classes/class.ilUtil.php";
422  $this->tpl->setVariable("HREF_STATUS_IMAGE", ilUtil::getImagePath("icon_ok.gif"));
423  $this->tpl->setVariable("ALT_STATUS_IMAGE", $this->lng->txt("certificate_status_complete"));
424  $this->tpl->setVariable("PREVIEW_BUTTON_CERTIFICATE", $this->lng->txt("certificate_preview"));
425  $this->tpl->setVariable("PREVIEW_URL", $this->ctrl->getLinkTarget($this, "certificatePreview"));
426  $this->tpl->setVariable("IMG_PREVIEW", ilUtil::getImagePath("icon_preview.gif"));
427  $this->tpl->setVariable("IMG_EXPORT", ilUtil::getImagePath("icon_file.gif"));
428  $this->tpl->setVariable("CERTIFICATE_EXPORT", $this->lng->txt("certificate_export"));
429  $this->tpl->setVariable("EXPORT_URL", $this->ctrl->getLinkTarget($this, "certificateExportFO"));
430  }
431  else
432  {
433  $this->tpl->setVariable("VALUE_STATUS", $this->lng->txt("certificate_status_incomplete"));
434  }
435 
436  $this->tpl->setVariable("TEXT_CERTIFICATE_IMPORT", $this->lng->txt("import"));
437 
438  $this->tpl->setVariable("BUTTON_SET_PAGEFORMAT", $this->lng->txt("change"));
439  $this->tpl->setVariable("TEXT_PAGE_FORMAT", $this->lng->txt("certificate_page_format"));
440  $this->tpl->setVariable("TEXT_BACKGROUND_IMAGE", $this->lng->txt("certificate_background_image"));
441  $this->tpl->setVariable("TEXT_UPLOAD", $this->lng->txt("upload"));
442  $this->tpl->setVariable("TEXT_PADDING_TOP", $this->lng->txt("certificate_padding_top"));
443  if (strlen($form_fields["padding_top"]) > 0)
444  {
445  $this->tpl->setVariable("VALUE_PADDING_TOP", " value=\"".$form_fields["padding_top"]."\"");
446  }
447  $this->tpl->setVariable("TEXT_MARGIN_BODY", $this->lng->txt("certificate_margin_body"));
448  $this->tpl->setVariable("TEXT_MARGIN_BODY_TOP", $this->lng->txt("certificate_top"));
449  $this->tpl->setVariable("TEXT_MARGIN_BODY_RIGHT", $this->lng->txt("certificate_right"));
450  $this->tpl->setVariable("TEXT_MARGIN_BODY_BOTTOM", $this->lng->txt("certificate_bottom"));
451  $this->tpl->setVariable("TEXT_MARGIN_BODY_LEFT", $this->lng->txt("certificate_left"));
452  if (strlen($form_fields["margin_body_top"]) > 0)
453  {
454  $this->tpl->setVariable("VALUE_MARGIN_BODY_TOP", " value=\"".$form_fields["margin_body_top"]."\"");
455  }
456  if (strlen($form_fields["margin_body_right"]) > 0)
457  {
458  $this->tpl->setVariable("VALUE_MARGIN_BODY_RIGHT", " value=\"".$form_fields["margin_body_right"]."\"");
459  }
460  if (strlen($form_fields["margin_body_bottom"]) > 0)
461  {
462  $this->tpl->setVariable("VALUE_MARGIN_BODY_BOTTOM", " value=\"".$form_fields["margin_body_bottom"]."\"");
463  }
464  if (strlen($form_fields["margin_body_left"]) > 0)
465  {
466  $this->tpl->setVariable("VALUE_MARGIN_BODY_LEFT", " value=\"".$form_fields["margin_body_left"]."\"");
467  }
468  $this->tpl->setVariable("TEXT_CERTIFICATE_TEXT", $this->lng->txt("certificate_text"));
469  if (strlen($form_fields["certificate_text"]) > 0)
470  {
471  $this->tpl->setVariable("VALUE_CERTIFICATE_TEXT", $form_fields["certificate_text"]);
472  }
473  $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
474  $this->tpl->setVariable("TEXT_SAVE", $this->lng->txt("save"));
475  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "certificateSave"));
476 
477  $this->tpl->setVariable("PH_INTRODUCTION", $this->lng->txt("certificate_ph_introduction"));
478  $this->tpl->setVariable("PH_USER_FULLNAME", $this->lng->txt("certificate_ph_fullname"));
479  $this->tpl->setVariable("PH_USER_FIRSTNAME", $this->lng->txt("certificate_ph_firstname"));
480  $this->tpl->setVariable("PH_USER_LASTNAME", $this->lng->txt("certificate_ph_lastname"));
481  $this->tpl->setVariable("PH_RESULT_PASSED", $this->lng->txt("certificate_ph_passed"));
482  $this->tpl->setVariable("PH_RESULT_POINTS", $this->lng->txt("certificate_ph_resultpoints"));
483  $this->tpl->setVariable("PH_RESULT_PERCENT", $this->lng->txt("certificate_ph_resultpercent"));
484  $this->tpl->setVariable("PH_USER_TITLE", $this->lng->txt("certificate_ph_title"));
485  $this->tpl->setVariable("PH_USER_STREET", $this->lng->txt("certificate_ph_street"));
486  $this->tpl->setVariable("PH_USER_INSTITUTION", $this->lng->txt("certificate_ph_institution"));
487  $this->tpl->setVariable("PH_USER_DEPARTMENT", $this->lng->txt("certificate_ph_department"));
488  $this->tpl->setVariable("PH_USER_CITY", $this->lng->txt("certificate_ph_city"));
489  $this->tpl->setVariable("PH_USER_ZIPCODE", $this->lng->txt("certificate_ph_zipcode"));
490  $this->tpl->setVariable("PH_USER_COUNTRY", $this->lng->txt("certificate_ph_country"));
491  $this->tpl->setVariable("PH_MAX_POINTS", $this->lng->txt("certificate_ph_maxpoints"));
492  $this->tpl->setVariable("PH_RESULT_MARK_SHORT", $this->lng->txt("certificate_ph_markshort"));
493  $this->tpl->setVariable("PH_RESULT_MARK_LONG", $this->lng->txt("certificate_ph_marklong"));
494  $this->tpl->setVariable("PH_TEST_TITLE", $this->lng->txt("certificate_ph_testtitle"));
495  $this->tpl->setVariable("PH_DATE", $this->lng->txt("certificate_ph_date"));
496  $this->tpl->setVariable("PH_DATETIME", $this->lng->txt("certificate_ph_datetime"));
497 
498  $this->tpl->setVariable("TEXT_UNIT_DESCRIPTION", $this->lng->txt("certificate_unit_description"));
499  $this->tpl->setVariable("TEXT_CERTIFICATE_VISIBILITY", $this->lng->txt("certificate_visibility"));
500  $this->tpl->setVariable("TEXT_CERTIFICATE_VISIBILITY_INTRODUCTION", $this->lng->txt("certificate_visibility_introduction"));
501  $this->tpl->setVariable("TEXT_VISIBILITY_ALWAYS", $this->lng->txt("certificate_visibility_always"));
502  $this->tpl->setVariable("TEXT_VISIBILITY_NEVER", $this->lng->txt("certificate_visibility_never"));
503  $this->tpl->setVariable("TEXT_VISIBILITY_PASSED", $this->lng->txt("certificate_visibility_passed"));
504  switch ($form_fields["certificate_visibility"])
505  {
506  case 1:
507  $this->tpl->setVariable("CHECKED_CV_1", " checked=\"checked\"");
508  break;
509  case 2:
510  $this->tpl->setVariable("CHECKED_CV_2", " checked=\"checked\"");
511  break;
512  case 0:
513  default:
514  $this->tpl->setVariable("CHECKED_CV_0", " checked=\"checked\"");
515  break;
516  }
517 
518  include_once "./Services/RTE/classes/class.ilRTE.php";
519  $rtestring = ilRTE::_getRTEClassname();
520  include_once "./Services/RTE/classes/class.$rtestring.php";
521  $rte = new $rtestring();
522  include_once "./classes/class.ilObject.php";
523  $obj_id = $_GET["q_id"];
524  $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
525 
526  $tags = array(
527  "br",
528  "em",
529  "font",
530  "li",
531  "ol",
532  "p",
533  "span",
534  "strong",
535  "u",
536  "ul"
537  );
538  $rte->addCustomRTESupport($obj_id, $obj_type, $tags);
539 
540  $this->tpl->parseCurrentBlock();
541  }
542 
550  function outCertificate()
551  {
552  global $ilUser;
553 
554  $active_id = $this->object->object->getTestSession()->getActiveId();
555  $counted_pass = ilObjTest::_getResultPass($active_id);
556  $this->ctrl->setParameterByClass("iltestcertificategui","active_id", $active_id);
557  $this->ctrl->setParameterByClass("iltestcertificategui","pass", $counted_pass);
558  $this->ctrl->redirectByClass("iltestcertificategui", "certificateOutput");
559  }
560 }
561 
562 ?>