ILIAS  Release_5_0_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  // begin-patch lok
141  if($this->settings_template->getAutoGenerated())
142  {
143  $ti->setDisabled(true);
144  }
145  // end-patch lok
146  $this->form->addItem($ti);
147 
148  // description
149  $ti = new ilTextAreaInputGUI($lng->txt("description"), "description");
150  // begin-patch lok
151  if($this->settings_template->getAutoGenerated())
152  {
153  $ti->setDisabled(true);
154  }
155  $this->form->addItem($ti);
156 
157  // hidable tabs
158  $tabs = $this->getConfig()->getHidableTabs();
159  if (is_array($tabs) && count($tabs) > 0)
160  {
161  $sec = new ilFormSectionHeaderGUI();
162  $sec->setTitle($lng->txt("adm_hide_tabs"));
163  $this->form->addItem($sec);
164 
165  foreach($tabs as $t)
166  {
167  // hide tab $t?
168  $cb = new ilCheckboxInputGUI($t["text"], "tab_".$t["id"]);
169  $this->form->addItem($cb);
170  }
171  }
172 
173  // settings
174  $settings = $this->getConfig()->getSettings();
175  if (is_array($settings) && count($settings) > 0)
176  {
177  $sec = new ilFormSectionHeaderGUI();
178  $sec->setTitle($lng->txt("adm_predefined_settings"));
179  $this->form->addItem($sec);
180 
181  foreach($settings as $s)
182  {
183  // setting
184  $cb = new ilCheckboxInputGUI($s["text"], "set_".$s["id"]);
185  $this->form->addItem($cb);
186 
187  switch ($s["type"])
188  {
190 
191  $ti = new ilTextInputGUI($lng->txt("adm_value"), "value_".$s["id"]);
192  //$ti->setMaxLength();
193  //$ti->setSize();
194  $cb->addSubItem($ti);
195  break;
196 
198  $cb2 = new ilCheckboxInputGUI($lng->txt("adm_value"), "value_".$s["id"]);
199  $cb->addSubItem($cb2);
200  break;
201 
203  $si = new ilSelectInputGUI($lng->txt("adm_value"), "value_".$s["id"]);
204  $si->setOptions($s["options"]);
205  $cb->addSubItem($si);
206  break;
207 
209  $chbs = new ilCheckboxGroupInputGUI($lng->txt("adm_value"), "value_".$s["id"]);
210  foreach($s['options'] as $key => $value) {
211  $chbs->addOption($c = new ilCheckboxInputGUI($value, $key));
212  $c->setValue($key);
213  }
214  $cb->addSubItem($chbs);
215  break;
216  }
217 
218  if ($s['hidable']) {
219  // hide setting
220  $cb_hide = new ilCheckboxInputGUI($lng->txt("adm_hide"), "hide_".$s["id"]);
221  $cb->addSubItem($cb_hide);
222  }
223  }
224  }
225 
226  // save and cancel commands
227  if ($a_mode == "create")
228  {
229  $this->form->addCommandButton("saveSettingsTemplate", $lng->txt("save"));
230  $this->form->addCommandButton("listSettingsTemplates", $lng->txt("cancel"));
231  $this->form->setTitle($lng->txt("adm_add_settings_template"));
232  }
233  else
234  {
235  $this->form->addCommandButton("updateSettingsTemplate", $lng->txt("save"));
236  $this->form->addCommandButton("listSettingsTemplates", $lng->txt("cancel"));
237  $this->form->setTitle($lng->txt("adm_edit_settings_template"));
238  }
239 
240  $this->form->setFormAction($ilCtrl->getFormAction($this));
241  }
242 
246  public function getSettingsTemplateValues()
247  {
248  $values = array();
249 
250  $values["title"] = $this->settings_template->getTitle();
251  $values["description"] = $this->settings_template->getDescription();
252 
253  // save tabs to be hidden
254  $tabs = $this->settings_template->getHiddenTabs();
255  foreach ($tabs as $t)
256  {
257  $values["tab_".$t] = true;
258  }
259 
260  // save settings values
261  $set = $this->settings_template->getSettings();
262  foreach($this->getConfig()->getSettings() as $s)
263  {
264  if (isset($set[$s["id"]]))
265  {
266  $values["set_".$s["id"]] = true;
267 
268  if ($s['type'] == ilSettingsTemplateConfig::CHECKBOX) {
269  if (!is_array($set[$s["id"]]["value"]))
270  $ar = @unserialize($set[$s["id"]]["value"]);
271  else
272  $ar = $set[$s["id"]]["value"];
273  $values["value_".$s["id"]] = is_array($ar) ? $ar : array();
274  }
275  else {
276  $values["value_".$s["id"]] = $set[$s["id"]]["value"];
277  }
278 
279  $values["hide_".$s["id"]] = $set[$s["id"]]["hide"];
280  }
281  }
282  $this->form->setValuesByArray($values);
283  }
284 
288  public function saveSettingsTemplate()
289  {
290  global $tpl, $lng, $ilCtrl;
291 
292  $this->initSettingsTemplateForm("create");
293  if ($this->form->checkInput())
294  {
295  $settings_template = new ilSettingsTemplate();
296  $settings_template->setType($this->getConfig()->getType());
297 
298  $this->setValuesFromForm($settings_template);
299  $settings_template->create();
300 
301  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
302  $ilCtrl->redirect($this, "listSettingsTemplates");
303  }
304 
305  $this->form->setValuesByPost();
306  $tpl->setContent($this->form->getHtml());
307  }
308 
313  {
314  global $lng, $ilCtrl, $tpl;
315 
316  $this->initSettingsTemplateForm("edit");
317  if ($this->form->checkInput())
318  {
319  $this->setValuesFromForm($this->settings_template);
320  $this->settings_template->update();
321 
322  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
323  $ilCtrl->redirect($this, "listSettingsTemplates");
324  }
325 
326  $this->form->setValuesByPost();
327  $tpl->setContent($this->form->getHtml());
328  }
329 
336  function setValuesFromForm($a_set_templ)
337  {
338  // perform update
339  $a_set_templ->setTitle($_POST["title"]);
340  $a_set_templ->setDescription($_POST["description"]);
341 
342  // save tabs to be hidden
343  $a_set_templ->removeAllHiddenTabs();
344  foreach ($this->getConfig()->getHidableTabs() as $t)
345  {
346  if ($_POST["tab_".$t["id"]])
347  {
348  $a_set_templ->addHiddenTab($t["id"]);
349  }
350  }
351 
352  // save settings values
353  $a_set_templ->removeAllSettings();
354  foreach($this->getConfig()->getSettings() as $s)
355  {
356  if ($_POST["set_".$s["id"]])
357  {
358  $a_set_templ->setSetting(
359  $s["id"], $_POST["value_".$s["id"]],
360  $_POST["hide_".$s["id"]]);
361  }
362  }
363  }
364 
369  {
370  global $ilCtrl, $tpl, $lng;
371 
372  if (!is_array($_POST["tid"]) || count($_POST["tid"]) == 0)
373  {
374  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
375  $ilCtrl->redirect($this, "listSettingsTemplates");
376  }
377  else
378  {
379  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
380  $cgui = new ilConfirmationGUI();
381  $cgui->setFormAction($ilCtrl->getFormAction($this));
382  $cgui->setHeaderText($lng->txt("adm_sure_delete_settings_template"));
383  $cgui->setCancel($lng->txt("cancel"), "listSettingsTemplates");
384  $cgui->setConfirm($lng->txt("delete"), "deleteSettingsTemplate");
385 
386  foreach ($_POST["tid"] as $i)
387  {
388  $cgui->addItem("tid[]", $i, ilSettingsTemplate::lookupTitle($i));
389  }
390 
391  $tpl->setContent($cgui->getHTML());
392  }
393  }
394 
402  {
403  global $ilCtrl, $lng;
404 
405  if (is_array($_POST["tid"]))
406  {
407  foreach ($_POST["tid"] as $i)
408  {
409  $templ = new ilSettingsTemplate($i);
410  $templ->delete();
411  }
412  }
413  ilUtil::sendSuccess("msg_obj_modified");
414  $ilCtrl->redirect($this, "listSettingsTemplates");
415  }
416 
417 }
418 
419 ?>