ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 {
15  private $config;
16 
23  function __construct($a_config)
24  {
25  global $ilCtrl;
26 
27  $ilCtrl->saveParameter($this, array("templ_id"));
28 
29  $this->setConfig($a_config);
30 
31  $this->readSettingsTemplate();
32  }
33 
37  function executeCommand()
38  {
39  global $ilCtrl;
40 
41  $cmd = $ilCtrl->getCmd("listSettingsTemplates");
42  $this->$cmd();
43  }
44 
50  public function setConfig($a_val)
51  {
52  $this->config = $a_val;
53  }
54 
60  public function getConfig()
61  {
62  return $this->config;
63  }
64 
72  {
73  if ($this->getConfig()) {
74  $this->settings_template = new ilSettingsTemplate((int) $_GET[templ_id], $this->getConfig());
75  }
76  else {
77  $this->settings_template = new ilSettingsTemplate((int) $_GET[templ_id]);
78  }
79  }
80 
88  {
89  global $tpl, $ilToolbar, $ilCtrl, $lng;
90 
91  $ilToolbar->addButton($lng->txt("adm_add_settings_template"),
92  $ilCtrl->getLinkTarget($this, "addSettingsTemplate"));
93 
94  include_once("./Services/Administration/classes/class.ilSettingsTemplateTableGUI.php");
95  $table = new ilSettingsTemplateTableGUI($this, "listSettingsTemplates",
96  $this->getConfig()->getType());
97 
98  $tpl->setContent($table->getHTML());
99  }
100 
105  {
106  global $tpl;
107 
108  $this->initSettingsTemplateForm("create");
109  $tpl->setContent($this->form->getHTML());
110  }
111 
116  {
117  global $tpl;
118 
119  $this->initSettingsTemplateForm("edit");
120  $this->getSettingsTemplateValues();
121  $tpl->setContent($this->form->getHTML());
122  }
123 
129  public function initSettingsTemplateForm($a_mode = "edit")
130  {
131  global $lng, $ilCtrl;
132 
133  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
134  $this->form = new ilPropertyFormGUI();
135 
136  // title
137  $ti = new ilTextInputGUI($lng->txt("title"), "title");
138  $ti->setMaxLength(200);
139  $ti->setRequired(true);
140  $this->form->addItem($ti);
141 
142  // description
143  $ti = new ilTextAreaInputGUI($lng->txt("description"), "description");
144  $this->form->addItem($ti);
145 
146  // hidable tabs
147  $tabs = $this->getConfig()->getHidableTabs();
148  if (is_array($tabs) && count($tabs) > 0)
149  {
150  $sec = new ilFormSectionHeaderGUI();
151  $sec->setTitle($lng->txt("adm_hide_tabs"));
152  $this->form->addItem($sec);
153 
154  foreach($tabs as $t)
155  {
156  // hide tab $t?
157  $cb = new ilCheckboxInputGUI($t["text"], "tab_".$t["id"]);
158  $this->form->addItem($cb);
159  }
160  }
161 
162  // settings
163  $settings = $this->getConfig()->getSettings();
164  if (is_array($settings) && count($settings) > 0)
165  {
166  $sec = new ilFormSectionHeaderGUI();
167  $sec->setTitle($lng->txt("adm_predefined_settings"));
168  $this->form->addItem($sec);
169 
170  foreach($settings as $s)
171  {
172  // setting
173  $cb = new ilCheckboxInputGUI($s["text"], "set_".$s["id"]);
174  $this->form->addItem($cb);
175 
176  switch ($s["type"])
177  {
179 
180  $ti = new ilTextInputGUI($lng->txt("adm_value"), "value_".$s["id"]);
181  //$ti->setMaxLength();
182  //$ti->setSize();
183  $cb->addSubItem($ti);
184  break;
185 
187  $cb2 = new ilCheckboxInputGUI($lng->txt("adm_value"), "value_".$s["id"]);
188  $cb->addSubItem($cb2);
189  break;
190 
192  $si = new ilSelectInputGUI($lng->txt("adm_value"), "value_".$s["id"]);
193  $si->setOptions($s["options"]);
194  $cb->addSubItem($si);
195  break;
196 
198  $chbs = new ilCheckboxGroupInputGUI($lng->txt("adm_value"), "value_".$s["id"]);
199  foreach($s['options'] as $key => $value) {
200  $chbs->addOption($c = new ilCheckboxInputGUI($value, $key));
201  $c->setValue($key);
202  }
203  $cb->addSubItem($chbs);
204  break;
205  }
206 
207  if ($s['hidable']) {
208  // hide setting
209  $cb_hide = new ilCheckboxInputGUI($lng->txt("adm_hide"), "hide_".$s["id"]);
210  $cb->addSubItem($cb_hide);
211  }
212  }
213  }
214 
215  // save and cancel commands
216  if ($a_mode == "create")
217  {
218  $this->form->addCommandButton("saveSettingsTemplate", $lng->txt("save"));
219  $this->form->addCommandButton("listSettingsTemplates", $lng->txt("cancel"));
220  $this->form->setTitle($lng->txt("adm_add_settings_template"));
221  }
222  else
223  {
224  $this->form->addCommandButton("updateSettingsTemplate", $lng->txt("save"));
225  $this->form->addCommandButton("listSettingsTemplates", $lng->txt("cancel"));
226  $this->form->setTitle($lng->txt("adm_edit_settings_template"));
227  }
228 
229  $this->form->setFormAction($ilCtrl->getFormAction($this));
230  }
231 
235  public function getSettingsTemplateValues()
236  {
237  $values = array();
238 
239  $values["title"] = $this->settings_template->getTitle();
240  $values["description"] = $this->settings_template->getDescription();
241 
242  // save tabs to be hidden
243  $tabs = $this->settings_template->getHiddenTabs();
244  foreach ($tabs as $t)
245  {
246  $values["tab_".$t] = true;
247  }
248 
249  // save settings values
250  $set = $this->settings_template->getSettings();
251  foreach($this->getConfig()->getSettings() as $s)
252  {
253  if (isset($set[$s["id"]]))
254  {
255  $values["set_".$s["id"]] = true;
256 
257  if ($s['type'] == ilSettingsTemplateConfig::CHECKBOX) {
258  if (!is_array($set[$s["id"]]["value"]))
259  $ar = @unserialize($set[$s["id"]]["value"]);
260  else
261  $ar = $set[$s["id"]]["value"];
262  $values["value_".$s["id"]] = is_array($ar) ? $ar : array();
263  }
264  else {
265  $values["value_".$s["id"]] = $set[$s["id"]]["value"];
266  }
267 
268  $values["hide_".$s["id"]] = $set[$s["id"]]["hide"];
269  }
270  }
271  $this->form->setValuesByArray($values);
272  }
273 
277  public function saveSettingsTemplate()
278  {
279  global $tpl, $lng, $ilCtrl;
280 
281  $this->initSettingsTemplateForm("create");
282  if ($this->form->checkInput())
283  {
284  $settings_template = new ilSettingsTemplate();
285  $settings_template->setType($this->getConfig()->getType());
286 
287  $this->setValuesFromForm($settings_template);
288  $settings_template->create();
289 
290  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
291  $ilCtrl->redirect($this, "listSettingsTemplates");
292  }
293 
294  $this->form->setValuesByPost();
295  $tpl->setContent($this->form->getHtml());
296  }
297 
302  {
303  global $lng, $ilCtrl, $tpl;
304 
305  $this->initSettingsTemplateForm("edit");
306  if ($this->form->checkInput())
307  {
308  $this->setValuesFromForm($this->settings_template);
309  $this->settings_template->update();
310 
311  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
312  $ilCtrl->redirect($this, "listSettingsTemplates");
313  }
314 
315  $this->form->setValuesByPost();
316  $tpl->setContent($this->form->getHtml());
317  }
318 
325  function setValuesFromForm($a_set_templ)
326  {
327  // perform update
328  $a_set_templ->setTitle($_POST["title"]);
329  $a_set_templ->setDescription($_POST["description"]);
330 
331  // save tabs to be hidden
332  $a_set_templ->removeAllHiddenTabs();
333  foreach ($this->getConfig()->getHidableTabs() as $t)
334  {
335  if ($_POST["tab_".$t["id"]])
336  {
337  $a_set_templ->addHiddenTab($t["id"]);
338  }
339  }
340 
341  // save settings values
342  $a_set_templ->removeAllSettings();
343  foreach($this->getConfig()->getSettings() as $s)
344  {
345  if ($_POST["set_".$s["id"]])
346  {
347  $a_set_templ->setSetting(
348  $s["id"], $_POST["value_".$s["id"]],
349  $_POST["hide_".$s["id"]]);
350  }
351  }
352  }
353 
358  {
359  global $ilCtrl, $tpl, $lng;
360 
361  if (!is_array($_POST["tid"]) || count($_POST["tid"]) == 0)
362  {
363  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
364  $ilCtrl->redirect($this, "listSettingsTemplates");
365  }
366  else
367  {
368  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
369  $cgui = new ilConfirmationGUI();
370  $cgui->setFormAction($ilCtrl->getFormAction($this));
371  $cgui->setHeaderText($lng->txt("adm_sure_delete_settings_template"));
372  $cgui->setCancel($lng->txt("cancel"), "listSettingsTemplates");
373  $cgui->setConfirm($lng->txt("delete"), "deleteSettingsTemplate");
374 
375  foreach ($_POST["tid"] as $i)
376  {
377  $cgui->addItem("tid[]", $i, ilSettingsTemplate::lookupTitle($i));
378  }
379 
380  $tpl->setContent($cgui->getHTML());
381  }
382  }
383 
391  {
392  global $ilCtrl, $lng;
393 
394  if (is_array($_POST["tid"]))
395  {
396  foreach ($_POST["tid"] as $i)
397  {
398  $templ = new ilSettingsTemplate($i);
399  $templ->delete();
400  }
401  }
402  ilUtil::sendSuccess("msg_obj_modified");
403  $ilCtrl->redirect($this, "listSettingsTemplates");
404  }
405 
406 }
407 
408 ?>