ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilSettingsTemplateGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once("./Services/Administration/classes/class.ilSettingsTemplate.php");
5
14{
18 protected $ctrl;
19
23 protected $tpl;
24
28 protected $toolbar;
29
33 protected $lng;
34
35 private $config;
39 protected $dic;
43 protected $rbacsystem;
44
51 public function __construct($a_config)
52 {
53 global $DIC;
54 $this->dic = $DIC;
55 $this->rbacsystem = $this->dic->rbac()->system();
56 $this->ctrl = $this->dic->ctrl();
57 $this->tpl = $this->dic["tpl"];
58 $this->toolbar = $this->dic->toolbar();
59 $this->lng = $this->dic->language();
60 $ilCtrl = $this->dic->ctrl();
61
62 $ilCtrl->saveParameter($this, array("templ_id"));
63
64 $this->setConfig($a_config);
65
66 $this->readSettingsTemplate();
67 }
68
72 public function executeCommand()
73 {
75
76 $cmd = $ilCtrl->getCmd("listSettingsTemplates");
77 $this->$cmd();
78 }
79
85 public function setConfig($a_val)
86 {
87 $this->config = $a_val;
88 }
89
95 public function getConfig()
96 {
97 return $this->config;
98 }
99
106 public function readSettingsTemplate()
107 {
108 if ($this->getConfig()) {
109 $this->settings_template = new ilSettingsTemplate((int) $_GET["templ_id"], $this->getConfig());
110 } else {
111 $this->settings_template = new ilSettingsTemplate((int) $_GET["templ_id"]);
112 }
113 }
114
121 public function listSettingsTemplates()
122 {
124 $ilToolbar = $this->toolbar;
127
128 if ($this->rbacsystem->checkAccess('write', $_GET['ref_id'])) {
129 $ilToolbar->addButton(
130 $lng->txt("adm_add_settings_template"),
131 $ilCtrl->getLinkTarget($this, "addSettingsTemplate")
132 );
133 }
134
135 include_once("./Services/Administration/classes/class.ilSettingsTemplateTableGUI.php");
136 $table = new ilSettingsTemplateTableGUI(
137 $this,
138 "listSettingsTemplates",
139 $this->getConfig()->getType()
140 );
141
142 $tpl->setContent($table->getHTML());
143 }
144
148 public function addSettingsTemplate()
149 {
151
152 $this->initSettingsTemplateForm("create");
153 $tpl->setContent($this->form->getHTML());
154 }
155
159 public function editSettingsTemplate()
160 {
162
163 $this->initSettingsTemplateForm("edit");
165 $tpl->setContent($this->form->getHTML());
166 }
167
173 public function initSettingsTemplateForm($a_mode = "edit")
174 {
177
178 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
179 $this->form = new ilPropertyFormGUI();
180
181 // title
182 $ti = new ilTextInputGUI($lng->txt("title"), "title");
183 $ti->setMaxLength(200);
184 $ti->setRequired(true);
185 // begin-patch lok
186 if ($this->settings_template->getAutoGenerated()) {
187 $ti->setDisabled(true);
188 }
189 // end-patch lok
190 $this->form->addItem($ti);
191
192 // description
193 $ti = new ilTextAreaInputGUI($lng->txt("description"), "description");
194 // begin-patch lok
195 if ($this->settings_template->getAutoGenerated()) {
196 $ti->setDisabled(true);
197 }
198 $this->form->addItem($ti);
199
200 // hidable tabs
201 $tabs = $this->getConfig()->getHidableTabs();
202 if (is_array($tabs) && count($tabs) > 0) {
203 $sec = new ilFormSectionHeaderGUI();
204 $sec->setTitle($lng->txt("adm_hide_tabs"));
205 $this->form->addItem($sec);
206
207 foreach ($tabs as $t) {
208 // hide tab $t?
209 $cb = new ilCheckboxInputGUI($t["text"], "tab_" . $t["id"]);
210 $this->form->addItem($cb);
211 }
212 }
213
214 // settings
215 $settings = $this->getConfig()->getSettings();
216 if (is_array($settings) && count($settings) > 0) {
217 $sec = new ilFormSectionHeaderGUI();
218 $sec->setTitle($lng->txt("adm_predefined_settings"));
219 $this->form->addItem($sec);
220
221 foreach ($settings as $s) {
222 // setting
223 $cb = new ilCheckboxInputGUI($s["text"], "set_" . $s["id"]);
224 $this->form->addItem($cb);
225
226 switch ($s["type"]) {
228
229 $ti = new ilTextInputGUI($lng->txt("adm_value"), "value_" . $s["id"]);
230 //$ti->setMaxLength();
231 //$ti->setSize();
232 $cb->addSubItem($ti);
233 break;
234
236 $cb2 = new ilCheckboxInputGUI($lng->txt("adm_value"), "value_" . $s["id"]);
237 $cb->addSubItem($cb2);
238 break;
239
241 $si = new ilSelectInputGUI($lng->txt("adm_value"), "value_" . $s["id"]);
242 $si->setOptions($s["options"]);
243 $cb->addSubItem($si);
244 break;
245
247 $chbs = new ilCheckboxGroupInputGUI($lng->txt("adm_value"), "value_" . $s["id"]);
248 foreach ($s['options'] as $key => $value) {
249 $chbs->addOption($c = new ilCheckboxInputGUI($value, $key));
250 $c->setValue($key);
251 }
252 $cb->addSubItem($chbs);
253 break;
254 }
255
256 if ($s['hidable']) {
257 // hide setting
258 $cb_hide = new ilCheckboxInputGUI($lng->txt("adm_hide"), "hide_" . $s["id"]);
259 $cb->addSubItem($cb_hide);
260 }
261 }
262 }
263
264 if ($this->rbacsystem->checkAccess('write', $_GET['ref_id'])) {
265 // save and cancel commands
266 if ($a_mode == "create") {
267 $this->form->addCommandButton("saveSettingsTemplate", $lng->txt("save"));
268 $this->form->addCommandButton("listSettingsTemplates", $lng->txt("cancel"));
269 $this->form->setTitle($lng->txt("adm_add_settings_template"));
270 } else {
271 $this->form->addCommandButton("updateSettingsTemplate", $lng->txt("save"));
272 $this->form->addCommandButton("listSettingsTemplates", $lng->txt("cancel"));
273 $this->form->setTitle($lng->txt("adm_edit_settings_template"));
274 }
275 }
276
277 $this->form->setFormAction($ilCtrl->getFormAction($this));
278 }
279
284 {
285 $values = array();
286
287 $values["title"] = $this->settings_template->getTitle();
288 $values["description"] = $this->settings_template->getDescription();
289
290 // save tabs to be hidden
291 $tabs = $this->settings_template->getHiddenTabs();
292 foreach ($tabs as $t) {
293 $values["tab_" . $t] = true;
294 }
295
296 // save settings values
297 $set = $this->settings_template->getSettings();
298 foreach ($this->getConfig()->getSettings() as $s) {
299 if (isset($set[$s["id"]])) {
300 $values["set_" . $s["id"]] = true;
301
302 if ($s['type'] == ilSettingsTemplateConfig::CHECKBOX) {
303 if (!is_array($set[$s["id"]]["value"])) {
304 $ar = @unserialize($set[$s["id"]]["value"]);
305 } else {
306 $ar = $set[$s["id"]]["value"];
307 }
308 $values["value_" . $s["id"]] = is_array($ar) ? $ar : array();
309 } else {
310 $values["value_" . $s["id"]] = $set[$s["id"]]["value"];
311 }
312
313 $values["hide_" . $s["id"]] = $set[$s["id"]]["hide"];
314 }
315 }
316 $this->form->setValuesByArray($values);
317 }
318
322 public function saveSettingsTemplate()
323 {
327
328 $this->initSettingsTemplateForm("create");
329 if ($this->form->checkInput()) {
330 $settings_template = new ilSettingsTemplate();
331 $settings_template->setType($this->getConfig()->getType());
332
333 $this->setValuesFromForm($settings_template);
334 $settings_template->create();
335
336 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
337 $ilCtrl->redirect($this, "listSettingsTemplates");
338 }
339
340 $this->form->setValuesByPost();
341 $tpl->setContent($this->form->getHtml());
342 }
343
347 public function updateSettingsTemplate()
348 {
352
353 $this->initSettingsTemplateForm("edit");
354 if ($this->form->checkInput()) {
355 $this->setValuesFromForm($this->settings_template);
356 $this->settings_template->update();
357
358 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
359 $ilCtrl->redirect($this, "listSettingsTemplates");
360 }
361
362 $this->form->setValuesByPost();
363 $tpl->setContent($this->form->getHtml());
364 }
365
372 public function setValuesFromForm($a_set_templ)
373 {
374 // perform update
375 $a_set_templ->setTitle($_POST["title"]);
376 $a_set_templ->setDescription($_POST["description"]);
377
378 // save tabs to be hidden
379 $a_set_templ->removeAllHiddenTabs();
380 foreach ($this->getConfig()->getHidableTabs() as $t) {
381 if ($_POST["tab_" . $t["id"]]) {
382 $a_set_templ->addHiddenTab($t["id"]);
383 }
384 }
385
386 // save settings values
387 $a_set_templ->removeAllSettings();
388 foreach ($this->getConfig()->getSettings() as $s) {
389 if ($_POST["set_" . $s["id"]]) {
390 $a_set_templ->setSetting(
391 $s["id"],
392 $_POST["value_" . $s["id"]],
393 $_POST["hide_" . $s["id"]]
394 );
395 }
396 }
397 }
398
403 {
407
408 if (!is_array($_POST["tid"]) || count($_POST["tid"]) == 0) {
409 ilUtil::sendInfo($lng->txt("no_checkbox"), true);
410 $ilCtrl->redirect($this, "listSettingsTemplates");
411 } else {
412 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
413 $cgui = new ilConfirmationGUI();
414 $cgui->setFormAction($ilCtrl->getFormAction($this));
415 $cgui->setHeaderText($lng->txt("adm_sure_delete_settings_template"));
416 $cgui->setCancel($lng->txt("cancel"), "listSettingsTemplates");
417 $cgui->setConfirm($lng->txt("delete"), "deleteSettingsTemplate");
418
419 foreach ($_POST["tid"] as $i) {
420 $cgui->addItem("tid[]", $i, ilSettingsTemplate::lookupTitle($i));
421 }
422
423 $tpl->setContent($cgui->getHTML());
424 }
425 }
426
433 public function deleteSettingsTemplate()
434 {
437
438 if (is_array($_POST["tid"])) {
439 foreach ($_POST["tid"] as $i) {
440 $templ = new ilSettingsTemplate($i);
441 $templ->delete();
442 }
443 }
444 ilUtil::sendSuccess("msg_obj_modified");
445 $ilCtrl->redirect($this, "listSettingsTemplates");
446 }
447}
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
This class represents a property in a property form.
This class represents a checkbox property in a property form.
Confirmation screen class.
This class represents a section header in a property form.
This class represents a property form user interface.
This class represents a selection list property in a property form.
editSettingsTemplate()
Edit settings template.
initSettingsTemplateForm($a_mode="edit")
Init settings template form.
saveSettingsTemplate()
Save settings template form.
listSettingsTemplates()
List all settings template.
__construct($a_config)
Constructor.
getSettingsTemplateValues()
Get current values for settings template from.
addSettingsTemplate()
Add settings template.
deleteSettingsTemplate()
Delete settings template.
readSettingsTemplate()
Read settings template.
updateSettingsTemplate()
Update settings template.
confirmSettingsTemplateDeletion()
Confirm settings template deletion.
setConfig($a_val)
Set config object.
setValuesFromForm($a_set_templ)
Set values from form.
Settings template application class.
static lookupTitle($a_id)
Lookup title.
This class represents a text area property in a property form.
This class represents a text property in a property form.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
global $ilCtrl
Definition: ilias.php:18
$i
Definition: metadata.php:24
$DIC
Definition: xapitoken.php:46