ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPCTabsGUI.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 require_once("./Services/COPage/classes/class.ilPCTabs.php");
5 require_once("./Services/COPage/classes/class.ilPageContentGUI.php");
6 
18 {
23  function ilPCTabsGUI(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id = "")
24  {
25  parent::ilPageContentGUI($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
26  }
27 
31  function &executeCommand()
32  {
33  // get next class that processes or forwards current command
34  $next_class = $this->ctrl->getNextClass($this);
35 
36  // get current command
37  $cmd = $this->ctrl->getCmd();
38 
39  switch($next_class)
40  {
41  default:
42  $ret =& $this->$cmd();
43  break;
44  }
45 
46  return $ret;
47  }
48 
52  function insert()
53  {
54  global $tpl;
55 
56  $this->displayValidationError();
57 
58  $this->initForm("create");
59  $html = $this->form->getHTML();
60  $tpl->setContent($html);
61  }
62 
66  function edit()
67  {
68  global $ilCtrl, $lng, $tpl;
69 
70  $this->displayValidationError();
71  $this->setTabs();
72 
73  $this->initForm();
74  $this->getFormValues();
75  $html = $this->form->getHTML();
76  $tpl->setContent($html);
77  }
78 
82  function initForm($a_mode = "edit")
83  {
84  global $ilCtrl, $tpl, $lng;
85 
86  include_once("./Services/Accordion/classes/class.ilAccordionGUI.php");
88 
89  // edit form
90  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
91  $this->form = new ilPropertyFormGUI();
92  $this->form->setFormAction($ilCtrl->getFormAction($this));
93  if ($a_mode != "edit")
94  {
95  $this->form->setTitle($lng->txt("cont_ed_insert_tabs"));
96  }
97  else
98  {
99  $this->form->setTitle($lng->txt("cont_edit_tabs"));
100  }
101 
102  // tabs type
103  /*$type_prop = new ilSelectInputGUI($lng->txt("cont_type"),
104  "type");
105  $types = array(ilPCTabs::ACCORDION_VER => $lng->txt("cont_tabs_acc_ver"),
106  ilPCTabs::ACCORDION_HOR => $lng->txt("cont_tabs_acc_hor"));
107  $type_prop->setOptions($types);
108  $this->form->addItem($type_prop);*/
109 
110  $templ = $this->getTemplateOptions("vaccordion");
111 
112  require_once("./Services/Form/classes/class.ilAdvSelectInputGUI.php");
113  $vchar_prop = new ilAdvSelectInputGUI($this->lng->txt("cont_characteristic"),
114  "vaccord_templ");
115 
116  $vchars = array();
117  foreach($templ as $k => $te)
118  {
119  $t = explode(":", $k);
120  $html = $this->style->lookupTemplatePreview($t[1]).'<div style="clear:both" class="small">'.$te."</div>";
121  $vchar_prop->addOption($k, $te, $html);
122  if ($t[2] == "VerticalAccordion")
123  {
124  $vchar_prop->setValue($k);
125  }
126  }
127 
128  $templ = $this->getTemplateOptions("haccordion");
129  $hchar_prop = new ilAdvSelectInputGUI($this->lng->txt("cont_characteristic"),
130  "haccord_templ");
131  $hchars = array();
132  foreach($templ as $k => $te)
133  {
134  $t = explode(":", $k);
135  $html = $this->style->lookupTemplatePreview($t[1]).'<div style="clear:both" class="small">'.$te."</div>";
136  $hchar_prop->addOption($k, $te, $html);
137  if ($t[2] == "HorizontalAccordion")
138  {
139  $hchar_prop->setValue($k);
140  }
141  }
142 
143  $radg = new ilRadioGroupInputGUI($lng->txt("cont_type"), "type");
145  $op1 = new ilRadioOption($lng->txt("cont_tabs_acc_ver"), ilPCTabs::ACCORDION_VER);
146  $op1->addSubItem($vchar_prop);
147  $radg->addOption($op1);
148  $op2 = new ilRadioOption($lng->txt("cont_tabs_acc_hor"), ilPCTabs::ACCORDION_HOR);
149  $op2->addSubItem($hchar_prop);
150  $radg->addOption($op2);
151  $this->form->addItem($radg);
152 
153 
154  // number of initial tabs
155  if ($a_mode == "create")
156  {
157  $nr_prop = new ilSelectInputGUI($lng->txt("cont_number_of_tabs"),
158  "nr");
159  $nrs = array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6,
160  7 => 7, 8 => 8, 9 => 9, 10 => 10);
161  $nr_prop->setOptions($nrs);
162  $this->form->addItem($nr_prop);
163  }
164 
165  $ni = new ilNumberInputGUI($this->lng->txt("cont_tab_cont_width"), "content_width");
166  $ni->setMaxLength(4);
167  $ni->setSize(4);
168  $this->form->addItem($ni);
169 
170  $ni = new ilNumberInputGUI($this->lng->txt("cont_tab_cont_height"), "content_height");
171  $ni->setMaxLength(4);
172  $ni->setSize(4);
173  $this->form->addItem($ni);
174 
175  // behaviour
176  $options = array(
177  "AllClosed" => $lng->txt("cont_all_closed"),
178  "FirstOpen" => $lng->txt("cont_first_open"),
179  "ForceAllOpen" => $lng->txt("cont_force_all_open"),
180  );
181  $si = new ilSelectInputGUI($this->lng->txt("cont_behavior"), "behavior");
182  $si->setOptions($options);
183  $this->form->addItem($si);
184 
185 
186  // alignment
187  $align_opts = array("Left" => $lng->txt("cont_left"),
188  "Right" => $lng->txt("cont_right"), "Center" => $lng->txt("cont_center"),
189  "LeftFloat" => $lng->txt("cont_left_float"),
190  "RightFloat" => $lng->txt("cont_right_float"));
191  $align = new ilSelectInputGUI($this->lng->txt("cont_align"), "align");
192  $align->setOptions($align_opts);
193  $align->setValue("Center");
194  $align->setInfo($lng->txt("cont_tabs_hor_align_info"));
195  $this->form->addItem($align);
196 
197  // save/cancel buttons
198  if ($a_mode == "create")
199  {
200  $this->form->addCommandButton("create_section", $lng->txt("save"));
201  $this->form->addCommandButton("cancelCreate", $lng->txt("cancel"));
202  }
203  else
204  {
205  $this->form->addCommandButton("update", $lng->txt("save"));
206  $this->form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
207  }
208  }
209 
213  function getFormValues()
214  {
215  $values["type"] = $this->content_obj->getTabType();
216  $values["content_width"] = $this->content_obj->getContentWidth();
217  $values["content_height"] = $this->content_obj->getContentHeight();
218  $values["align"] = $this->content_obj->getHorizontalAlign();
219  $values["behavior"] = $this->content_obj->getBehavior();
220  $this->form->setValuesByArray($values);
221 
222  if ($values["type"] == ilPCTabs::ACCORDION_VER)
223  {
224  $va = $this->form->getItemByPostVar("vaccord_templ");
225  $v = "t:".
226  ilObjStyleSheet::_lookupTemplateIdByName($this->getStyleId(), $this->content_obj->getTemplate()).":".
227  $this->content_obj->getTemplate();
228  $va->setValue($v);
229  }
230  if ($values["type"] == ilPCTabs::ACCORDION_HOR)
231  {
232  $ha = $this->form->getItemByPostVar("haccord_templ");
233  $v = "t:".
234  ilObjStyleSheet::_lookupTemplateIdByName($this->getStyleId(), $this->content_obj->getTemplate()).":".
235  $this->content_obj->getTemplate();
236  $ha->setValue($v);
237  }
238  }
239 
243  function create()
244  {
245  global $ilDB, $lng;
246 
247  $this->initForm();
248  if ($this->form->checkInput())
249  {
250  $this->content_obj = new ilPCTabs($this->dom);
251  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
252  $this->content_obj->setTabType($_POST["type"]);
253  $this->content_obj->setContentWidth($_POST["content_width"]);
254  $this->content_obj->setContentHeight($_POST["content_height"]);
255  $this->content_obj->setHorizontalAlign($_POST["align"]);
256  $this->content_obj->setBehavior($_POST["behavior"]);
257  for ($i = 0; $i < (int) $_POST["nr"]; $i++)
258  {
259  $this->content_obj->addTab($lng->txt("cont_new_tab"));
260  }
261  if ($_POST["type"] == ilPCTabs::ACCORDION_VER)
262  {
263  $t = explode(":", $_POST["vaccord_templ"]);
264  $this->content_obj->setTemplate($t[2]);
265  }
266  if ($_POST["type"] == ilPCTabs::ACCORDION_HOR)
267  {
268  $t = explode(":", $_POST["haccord_templ"]);
269  $this->content_obj->setTemplate($t[2]);
270  }
271  }
272  $this->updated = $this->pg_obj->update();
273 
274  if ($this->updated === true)
275  {
276  $this->afterCreation();
277  //$this->ctrl->returnToParent($this, "jump".$this->hier_id);
278  }
279  else
280  {
281  $this->insert();
282  }
283  }
284 
288  function afterCreation()
289  {
290  global $ilCtrl;
291 
292  $this->pg_obj->stripHierIDs();
293  $this->pg_obj->addHierIDs();
294  $ilCtrl->setParameter($this, "hier_id", $this->content_obj->readHierId());
295  $ilCtrl->setParameter($this, "pc_id", $this->content_obj->readPCId());
296  $this->content_obj->setHierId($this->content_obj->readHierId());
297  $this->setHierId($this->content_obj->readHierId());
298  $this->content_obj->setPCId($this->content_obj->readPCId());
299  $this->editTabs();
300  }
301 
302 
306  function update()
307  {
308  $this->initForm();
309  if ($this->form->checkInput())
310  {
311  $this->content_obj->setTabType(ilUtil::stripSlashes($_POST["type"]));
312  $this->content_obj->setContentWidth($_POST["content_width"]);
313  $this->content_obj->setContentHeight($_POST["content_height"]);
314  $this->content_obj->setHorizontalAlign($_POST["align"]);
315  $this->content_obj->setTemplate("");
316  $this->content_obj->setBehavior($_POST["behavior"]);
317  if ($_POST["type"] == ilPCTabs::ACCORDION_VER)
318  {
319  $t = explode(":", $_POST["vaccord_templ"]);
320  $this->content_obj->setTemplate($t[2]);
321  }
322  if ($_POST["type"] == ilPCTabs::ACCORDION_HOR)
323  {
324  $t = explode(":", $_POST["haccord_templ"]);
325  $this->content_obj->setTemplate($t[2]);
326  }
327  }
328  $this->updated = $this->pg_obj->update();
329  if ($this->updated === true)
330  {
331  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
332  }
333  else
334  {
335  $this->pg_obj->addHierIDs();
336  $this->edit();
337  }
338  }
339 
340  //
341  // Edit Tabs
342  //
343 
344 
348  function editTabs()
349  {
350  global $tpl, $ilTabs;
351 
352  $this->setTabs();
353  $ilTabs->activateTab("cont_tabs");
354  include_once("./Services/COPage/classes/class.ilPCTabsTableGUI.php");
355  $table_gui = new ilPCTabsTableGUI($this, "editTabs", $this->content_obj);
356  $tpl->setContent($table_gui->getHTML());
357  }
358 
362  function saveTabs()
363  {
364  global $ilCtrl;
365 
366  if (is_array($_POST["caption"]))
367  {
368  $this->content_obj->saveCaptions($_POST["caption"]);
369  }
370  if (is_array($_POST["position"]))
371  {
372  $this->content_obj->savePositions($_POST["position"]);
373  }
374  $this->updated = $this->pg_obj->update();
375  $ilCtrl->redirect($this, "editTabs");
376  }
377 
381  function addTab()
382  {
383  global $lng, $ilCtrl;
384 
385  $this->content_obj->addTab($lng->txt("cont_new_tab"));
386  $this->updated = $this->pg_obj->update();
387  $ilCtrl->redirect($this, "editTabs");
388  }
389 
394  {
395  global $ilCtrl, $tpl, $lng;
396 
397  $this->setTabs();
398 
399  if (!is_array($_POST["tid"]) || count($_POST["tid"]) == 0)
400  {
401  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
402  $ilCtrl->redirect($this, "editTabs");
403  }
404  else
405  {
406  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
407  $cgui = new ilConfirmationGUI();
408  $cgui->setFormAction($ilCtrl->getFormAction($this));
409  $cgui->setHeaderText($lng->txt("cont_tabs_confirm_deletion"));
410  $cgui->setCancel($lng->txt("cancel"), "cancelTabDeletion");
411  $cgui->setConfirm($lng->txt("delete"), "deleteTabs");
412 
413  foreach ($_POST["tid"] as $k => $i)
414  {
415  $id = explode(":", $k);
416  $cgui->addItem("tid[]", $k,
417  $this->content_obj->getCaption($id[0], $id[1]));
418  }
419 
420  $tpl->setContent($cgui->getHTML());
421  }
422  }
423 
427  function cancelTabDeletion()
428  {
429  global $ilCtrl;
430  $ilCtrl->redirect($this, "editTabs");
431  }
432 
436  function deleteTabs()
437  {
438  global $ilCtrl;
439 
440  if (is_array($_POST["tid"]))
441  {
442  foreach($_POST["tid"] as $tid)
443  {
444  $ids = explode(":", $tid);
445  $this->content_obj->deleteTab($ids[0], $ids[1]);
446  }
447  }
448  $this->updated = $this->pg_obj->update();
449 
450  $ilCtrl->redirect($this, "editTabs");
451  }
452 
453 
457  function setTabs()
458  {
459  global $ilTabs, $ilCtrl, $lng;
460 
461  $ilTabs->setBackTarget($lng->txt("pg"),
462  $this->ctrl->getParentReturn($this));
463 
464  $ilTabs->addTarget("cont_edit_tabs",
465  $ilCtrl->getLinkTarget($this, "edit"), "edit",
466  get_class($this));
467 
468  $ilTabs->addTarget("cont_tabs",
469  $ilCtrl->getLinkTarget($this, "editTabs"), "editTabs",
470  get_class($this));
471 
472  }
473 }
474 ?>