ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilLicenseGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once "./Services/License/classes/class.ilLicense.php";
5 
16 class ilLicenseGUI {
17 
18 
22  protected $license;
26  protected $ctrl;
30  protected $tpl;
34  protected $lng;
35 
36 
42  public function __construct(ilObjectGUI $a_parent_gui) {
43  global $ilCtrl, $tpl, $lng;
44 
45  $this->ctrl = $ilCtrl;
46  $this->tpl = $tpl;
47  $this->lng = $lng;
48  $this->lng->loadLanguageModule("license");
49  $this->parent_gui = $a_parent_gui;
50  $this->license = new ilLicense($this->parent_gui->object->getId());
51  }
52 
53 
54  public function executeCommand() {
55  global $rbacsystem, $ilErr;
56 
57  // access to all functions in this class are only allowed if edit_permission is granted
58  if (!$rbacsystem->checkAccess("edit_permission", $this->parent_gui->object->getRefId())) {
59  $ilErr->raiseError($this->lng->txt("permission_denied"), $ilErr->MESSAGE);
60  }
61 
62  $cmd = $this->ctrl->getCmd("editLicense");
63  $this->$cmd();
64 
65  return true;
66  }
67 
68 
69  protected function initLicenseForm() {
70  include_once('Services/Form/classes/class.ilPropertyFormGUI.php');
71  $form = new ilPropertyFormGUI();
72  $form->setFormAction($this->ctrl->getFormAction($this, "updateLicense"));
73  $form->setTitle($this->lng->txt('edit_license'));
74 
75  $exist = new ilNumberInputGUI($this->lng->txt("existing_licenses"), "licenses");
76  $exist->setInfo($this->lng->txt("zero_licenses_explanation"));
77  $exist->setMaxLength(10);
78  $exist->setSize(10);
79  $exist->setValue($this->license->getLicenses());
80  $form->addItem($exist);
81 
82  $info_used = new ilNonEditableValueGUI($this->lng->txt("used_licenses"));
83  $info_used->setInfo($this->lng->txt("used_licenses_explanation"));
84  $info_used->setValue($this->license->getAccesses());
85  $form->addItem($info_used);
86 
87  $remaining_licenses = ($this->license->getLicenses() == "0") ? $this->lng->txt("arbitrary") : $this->license->getRemainingLicenses();
88 
89  $info_remain = new ilNonEditableValueGUI($this->lng->txt("remaining_licenses"));
90  $info_remain->setInfo($this->lng->txt("remaining_licenses_explanation"));
91  $info_remain->setValue($remaining_licenses);
92  $form->addItem($info_remain);
93 
94  $info_potential = new ilNonEditableValueGUI($this->lng->txt("potential_accesses"));
95  $info_potential->setInfo($this->lng->txt("potential_accesses_explanation"));
96  $info_potential->setValue($this->license->getPotentialAccesses());
97  $form->addItem($info_potential);
98 
99  $comm = new ilTextAreaInputGUI($this->lng->txt("comment"), "remarks");
100  $comm->setRows(5);
101  $comm->setValue($this->license->getRemarks());
102  $form->addItem($comm);
103 
104  $form->addCommandButton('updateLicense', $this->lng->txt('save'));
105 
106  return $form;
107  }
108 
109 
113  protected function editLicense(ilPropertyFormGUI $a_form = null) {
114  if (!$a_form) {
115  $a_form = $this->initLicenseForm();
116  }
117 
118  $this->tpl->setContent($a_form->getHTML());
119  }
120 
121 
125  public function updateLicense() {
126  $form = $this->initLicenseForm();
127  if ($form->checkInput()) {
128  $this->license->setLicenses($form->getInput("licenses"));
129  $this->license->setRemarks($form->getInput("remarks"));
130  $this->license->update();
131 
132  ilUtil::sendSuccess($this->lng->txt('license_updated'), true);
133  $this->ctrl->redirect($this, "editLicense");
134  }
135 
136  $form->setValuesByPost();
137  $this->editLicense($form);
138  }
139 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
global $ilErr
Definition: raiseError.php:16
This class represents a property form user interface.
setInfo($a_info)
Set Information Text.
$cmd
Definition: sahs_server.php:35
editLicense(ilPropertyFormGUI $a_form=null)
global $ilCtrl
Definition: ilias.php:18
setInfo($a_info)
Set Information Text.
__construct(ilObjectGUI $a_parent_gui)
ilLicenseGUI constructor.
This class represents a number property in a property form.
Class ilObjectGUI Basic methods of all Output classes.
updateLicense()
Save the license form.
This class represents a non editable value in a property form.
This class represents a text area property in a property form.