ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
4 include_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;
36 
43  public function __construct($a_config)
44  {
45  global $DIC;
46 
47  $this->ctrl = $DIC->ctrl();
48  $this->tpl = $DIC["tpl"];
49  $this->toolbar = $DIC->toolbar();
50  $this->lng = $DIC->language();
51  $ilCtrl = $DIC->ctrl();
52 
53  $ilCtrl->saveParameter($this, array("templ_id"));
54 
55  $this->setConfig($a_config);
56 
57  $this->readSettingsTemplate();
58  }
59 
63  public function executeCommand()
64  {
66 
67  $cmd = $ilCtrl->getCmd("listSettingsTemplates");
68  $this->$cmd();
69  }
70 
76  public function setConfig($a_val)
77  {
78  $this->config = $a_val;
79  }
80 
86  public function getConfig()
87  {
88  return $this->config;
89  }
90 
97  public function readSettingsTemplate()
98  {
99  if ($this->getConfig()) {
100  $this->settings_template = new ilSettingsTemplate((int) $_GET["templ_id"], $this->getConfig());
101  } else {
102  $this->settings_template = new ilSettingsTemplate((int) $_GET["templ_id"]);
103  }
104  }
105 
112  public function listSettingsTemplates()
113  {
114  $tpl = $this->tpl;
115  $ilToolbar = $this->toolbar;
117  $lng = $this->lng;
118 
119  $ilToolbar->addButton(
120  $lng->txt("adm_add_settings_template"),
121  $ilCtrl->getLinkTarget($this, "addSettingsTemplate")
122  );
123 
124  include_once("./Services/Administration/classes/class.ilSettingsTemplateTableGUI.php");
126  $this,
127  "listSettingsTemplates",
128  $this->getConfig()->getType()
129  );
130 
131  $tpl->setContent($table->getHTML());
132  }
133 
137  public function addSettingsTemplate()
138  {
139  $tpl = $this->tpl;
140 
141  $this->initSettingsTemplateForm("create");
142  $tpl->setContent($this->form->getHTML());
143  }
144 
148  public function editSettingsTemplate()
149  {
150  $tpl = $this->tpl;
151 
152  $this->initSettingsTemplateForm("edit");
153  $this->getSettingsTemplateValues();
154  $tpl->setContent($this->form->getHTML());
155  }
156 
162  public function initSettingsTemplateForm($a_mode = "edit")
163  {
164  $lng = $this->lng;
166 
167  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
168  $this->form = new ilPropertyFormGUI();
169 
170  // title
171  $ti = new ilTextInputGUI($lng->txt("title"), "title");
172  $ti->setMaxLength(200);
173  $ti->setRequired(true);
174  // begin-patch lok
175  if ($this->settings_template->getAutoGenerated()) {
176  $ti->setDisabled(true);
177  }
178  // end-patch lok
179  $this->form->addItem($ti);
180 
181  // description
182  $ti = new ilTextAreaInputGUI($lng->txt("description"), "description");
183  // begin-patch lok
184  if ($this->settings_template->getAutoGenerated()) {
185  $ti->setDisabled(true);
186  }
187  $this->form->addItem($ti);
188 
189  // hidable tabs
190  $tabs = $this->getConfig()->getHidableTabs();
191  if (is_array($tabs) && count($tabs) > 0) {
192  $sec = new ilFormSectionHeaderGUI();
193  $sec->setTitle($lng->txt("adm_hide_tabs"));
194  $this->form->addItem($sec);
195 
196  foreach ($tabs as $t) {
197  // hide tab $t?
198  $cb = new ilCheckboxInputGUI($t["text"], "tab_" . $t["id"]);
199  $this->form->addItem($cb);
200  }
201  }
202 
203  // settings
204  $settings = $this->getConfig()->getSettings();
205  if (is_array($settings) && count($settings) > 0) {
206  $sec = new ilFormSectionHeaderGUI();
207  $sec->setTitle($lng->txt("adm_predefined_settings"));
208  $this->form->addItem($sec);
209 
210  foreach ($settings as $s) {
211  // setting
212  $cb = new ilCheckboxInputGUI($s["text"], "set_" . $s["id"]);
213  $this->form->addItem($cb);
214 
215  switch ($s["type"]) {
217 
218  $ti = new ilTextInputGUI($lng->txt("adm_value"), "value_" . $s["id"]);
219  //$ti->setMaxLength();
220  //$ti->setSize();
221  $cb->addSubItem($ti);
222  break;
223 
225  $cb2 = new ilCheckboxInputGUI($lng->txt("adm_value"), "value_" . $s["id"]);
226  $cb->addSubItem($cb2);
227  break;
228 
230  $si = new ilSelectInputGUI($lng->txt("adm_value"), "value_" . $s["id"]);
231  $si->setOptions($s["options"]);
232  $cb->addSubItem($si);
233  break;
234 
236  $chbs = new ilCheckboxGroupInputGUI($lng->txt("adm_value"), "value_" . $s["id"]);
237  foreach ($s['options'] as $key => $value) {
238  $chbs->addOption($c = new ilCheckboxInputGUI($value, $key));
239  $c->setValue($key);
240  }
241  $cb->addSubItem($chbs);
242  break;
243  }
244 
245  if ($s['hidable']) {
246  // hide setting
247  $cb_hide = new ilCheckboxInputGUI($lng->txt("adm_hide"), "hide_" . $s["id"]);
248  $cb->addSubItem($cb_hide);
249  }
250  }
251  }
252 
253  // save and cancel commands
254  if ($a_mode == "create") {
255  $this->form->addCommandButton("saveSettingsTemplate", $lng->txt("save"));
256  $this->form->addCommandButton("listSettingsTemplates", $lng->txt("cancel"));
257  $this->form->setTitle($lng->txt("adm_add_settings_template"));
258  } else {
259  $this->form->addCommandButton("updateSettingsTemplate", $lng->txt("save"));
260  $this->form->addCommandButton("listSettingsTemplates", $lng->txt("cancel"));
261  $this->form->setTitle($lng->txt("adm_edit_settings_template"));
262  }
263 
264  $this->form->setFormAction($ilCtrl->getFormAction($this));
265  }
266 
270  public function getSettingsTemplateValues()
271  {
272  $values = array();
273 
274  $values["title"] = $this->settings_template->getTitle();
275  $values["description"] = $this->settings_template->getDescription();
276 
277  // save tabs to be hidden
278  $tabs = $this->settings_template->getHiddenTabs();
279  foreach ($tabs as $t) {
280  $values["tab_" . $t] = true;
281  }
282 
283  // save settings values
284  $set = $this->settings_template->getSettings();
285  foreach ($this->getConfig()->getSettings() as $s) {
286  if (isset($set[$s["id"]])) {
287  $values["set_" . $s["id"]] = true;
288 
289  if ($s['type'] == ilSettingsTemplateConfig::CHECKBOX) {
290  if (!is_array($set[$s["id"]]["value"])) {
291  $ar = @unserialize($set[$s["id"]]["value"]);
292  } else {
293  $ar = $set[$s["id"]]["value"];
294  }
295  $values["value_" . $s["id"]] = is_array($ar) ? $ar : array();
296  } else {
297  $values["value_" . $s["id"]] = $set[$s["id"]]["value"];
298  }
299 
300  $values["hide_" . $s["id"]] = $set[$s["id"]]["hide"];
301  }
302  }
303  $this->form->setValuesByArray($values);
304  }
305 
309  public function saveSettingsTemplate()
310  {
311  $tpl = $this->tpl;
312  $lng = $this->lng;
314 
315  $this->initSettingsTemplateForm("create");
316  if ($this->form->checkInput()) {
317  $settings_template = new ilSettingsTemplate();
318  $settings_template->setType($this->getConfig()->getType());
319 
320  $this->setValuesFromForm($settings_template);
321  $settings_template->create();
322 
323  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
324  $ilCtrl->redirect($this, "listSettingsTemplates");
325  }
326 
327  $this->form->setValuesByPost();
328  $tpl->setContent($this->form->getHtml());
329  }
330 
334  public function updateSettingsTemplate()
335  {
336  $lng = $this->lng;
338  $tpl = $this->tpl;
339 
340  $this->initSettingsTemplateForm("edit");
341  if ($this->form->checkInput()) {
342  $this->setValuesFromForm($this->settings_template);
343  $this->settings_template->update();
344 
345  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
346  $ilCtrl->redirect($this, "listSettingsTemplates");
347  }
348 
349  $this->form->setValuesByPost();
350  $tpl->setContent($this->form->getHtml());
351  }
352 
359  public function setValuesFromForm($a_set_templ)
360  {
361  // perform update
362  $a_set_templ->setTitle($_POST["title"]);
363  $a_set_templ->setDescription($_POST["description"]);
364 
365  // save tabs to be hidden
366  $a_set_templ->removeAllHiddenTabs();
367  foreach ($this->getConfig()->getHidableTabs() as $t) {
368  if ($_POST["tab_" . $t["id"]]) {
369  $a_set_templ->addHiddenTab($t["id"]);
370  }
371  }
372 
373  // save settings values
374  $a_set_templ->removeAllSettings();
375  foreach ($this->getConfig()->getSettings() as $s) {
376  if ($_POST["set_" . $s["id"]]) {
377  $a_set_templ->setSetting(
378  $s["id"],
379  $_POST["value_" . $s["id"]],
380  $_POST["hide_" . $s["id"]]
381  );
382  }
383  }
384  }
385 
390  {
392  $tpl = $this->tpl;
393  $lng = $this->lng;
394 
395  if (!is_array($_POST["tid"]) || count($_POST["tid"]) == 0) {
396  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
397  $ilCtrl->redirect($this, "listSettingsTemplates");
398  } else {
399  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
400  $cgui = new ilConfirmationGUI();
401  $cgui->setFormAction($ilCtrl->getFormAction($this));
402  $cgui->setHeaderText($lng->txt("adm_sure_delete_settings_template"));
403  $cgui->setCancel($lng->txt("cancel"), "listSettingsTemplates");
404  $cgui->setConfirm($lng->txt("delete"), "deleteSettingsTemplate");
405 
406  foreach ($_POST["tid"] as $i) {
407  $cgui->addItem("tid[]", $i, ilSettingsTemplate::lookupTitle($i));
408  }
409 
410  $tpl->setContent($cgui->getHTML());
411  }
412  }
413 
420  public function deleteSettingsTemplate()
421  {
423  $lng = $this->lng;
424 
425  if (is_array($_POST["tid"])) {
426  foreach ($_POST["tid"] as $i) {
427  $templ = new ilSettingsTemplate($i);
428  $templ->delete();
429  }
430  }
431  ilUtil::sendSuccess("msg_obj_modified");
432  $ilCtrl->redirect($this, "listSettingsTemplates");
433  }
434 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
listSettingsTemplates()
List all settings template.
This class represents a selection list property in a property form.
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
This class represents a section header in a property form.
This class represents a checkbox property in a property form.
$s
Definition: pwgen.php:45
saveSettingsTemplate()
Save settings template form.
editSettingsTemplate()
Edit settings template.
global $ilCtrl
Definition: ilias.php:18
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
setValuesFromForm($a_set_templ)
Set values from form.
readSettingsTemplate()
Read settings template.
getSettingsTemplateValues()
Get current values for settings template from.
This class represents a text property in a property form.
addSettingsTemplate()
Add settings template.
initSettingsTemplateForm($a_mode="edit")
Init settings template form.
setMaxLength($a_maxlength)
Set Max Length.
This class represents a property in a property form.
static lookupTitle($a_id)
Lookup title.
Create styles array
The data for the language used.
if(!empty($this->data['faventry'])) $tabs
Definition: disco.tpl.php:124
setConfig($a_val)
Set config object.
__construct($a_config)
Constructor.
This class represents a text area property in a property form.
confirmSettingsTemplateDeletion()
Confirm settings template deletion.
$i
Definition: disco.tpl.php:19
if(empty($password)) $table
Definition: pwgen.php:24
deleteSettingsTemplate()
Delete settings template.
$key
Definition: croninfo.php:18
setDisabled($a_disabled)
Set Disabled.
$_POST["username"]
Settings template application class.
updateSettingsTemplate()
Update settings template.
Confirmation screen class.