ILIAS  Release_4_1_x_branch Revision 61804
 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($a_omit_form_init = false)
53  {
54  global $tpl;
55 
56  $this->displayValidationError();
57 
58  if (!$a_omit_form_init)
59  {
60  $this->initForm("create");
61  }
62  $html = $this->form->getHTML();
63  $tpl->setContent($html);
64  }
65 
69  function edit()
70  {
71  global $ilCtrl, $lng, $tpl;
72 
73  $this->displayValidationError();
74  $this->setTabs();
75 
76  $this->initForm();
77  $this->getFormValues();
78  $html = $this->form->getHTML();
79  $tpl->setContent($html);
80  }
81 
85  function initForm($a_mode = "edit")
86  {
87  global $ilCtrl, $tpl, $lng;
88 
89  include_once("./Services/Accordion/classes/class.ilAccordionGUI.php");
91 
92  // edit form
93  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
94  $this->form = new ilPropertyFormGUI();
95  $this->form->setFormAction($ilCtrl->getFormAction($this));
96  if ($a_mode != "edit")
97  {
98  $this->form->setTitle($lng->txt("cont_ed_insert_tabs"));
99  }
100  else
101  {
102  $this->form->setTitle($lng->txt("cont_edit_tabs"));
103  }
104 
105  // tabs type
106  /*$type_prop = new ilSelectInputGUI($lng->txt("cont_type"),
107  "type");
108  $types = array(ilPCTabs::ACCORDION_VER => $lng->txt("cont_tabs_acc_ver"),
109  ilPCTabs::ACCORDION_HOR => $lng->txt("cont_tabs_acc_hor"));
110  $type_prop->setOptions($types);
111  $this->form->addItem($type_prop);*/
112 
113  $templ = $this->getTemplateOptions("vaccordion");
114 
115  require_once("./Services/Form/classes/class.ilAdvSelectInputGUI.php");
116  $vchar_prop = new ilAdvSelectInputGUI($this->lng->txt("cont_characteristic"),
117  "vaccord_templ");
118 
119  $vchars = array();
120  foreach($templ as $k => $te)
121  {
122  $t = explode(":", $k);
123  $html = $this->style->lookupTemplatePreview($t[1]).'<div style="clear:both" class="small">'.$te."</div>";
124  $vchar_prop->addOption($k, $te, $html);
125  if ($t[2] == "VerticalAccordion")
126  {
127  $vchar_prop->setValue($k);
128  }
129  }
130 
131  $templ = $this->getTemplateOptions("haccordion");
132  $hchar_prop = new ilAdvSelectInputGUI($this->lng->txt("cont_characteristic"),
133  "haccord_templ");
134  $hchars = array();
135  foreach($templ as $k => $te)
136  {
137  $t = explode(":", $k);
138  $html = $this->style->lookupTemplatePreview($t[1]).'<div style="clear:both" class="small">'.$te."</div>";
139  $hchar_prop->addOption($k, $te, $html);
140  if ($t[2] == "HorizontalAccordion")
141  {
142  $hchar_prop->setValue($k);
143  }
144  }
145 
146  $radg = new ilRadioGroupInputGUI($lng->txt("cont_type"), "type");
148  $op1 = new ilRadioOption($lng->txt("cont_tabs_acc_ver"), ilPCTabs::ACCORDION_VER);
149  $op1->addSubItem($vchar_prop);
150  $radg->addOption($op1);
151  $op2 = new ilRadioOption($lng->txt("cont_tabs_acc_hor"), ilPCTabs::ACCORDION_HOR);
152  $op2->addSubItem($hchar_prop);
153  $radg->addOption($op2);
154  $this->form->addItem($radg);
155 
156 
157  // number of initial tabs
158  if ($a_mode == "create")
159  {
160  $nr_prop = new ilSelectInputGUI($lng->txt("cont_number_of_tabs"),
161  "nr");
162  $nrs = array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6,
163  7 => 7, 8 => 8, 9 => 9, 10 => 10);
164  $nr_prop->setOptions($nrs);
165  $this->form->addItem($nr_prop);
166  }
167 
168  $ni = new ilNumberInputGUI($this->lng->txt("cont_tab_cont_width"), "content_width");
169  $ni->setMaxLength(4);
170  $ni->setSize(4);
171  $this->form->addItem($ni);
172 
173  $ni = new ilNumberInputGUI($this->lng->txt("cont_tab_cont_height"), "content_height");
174  $ni->setMaxLength(4);
175  $ni->setSize(4);
176  $this->form->addItem($ni);
177 
178  // behaviour
179  $options = array(
180  "AllClosed" => $lng->txt("cont_all_closed"),
181  "FirstOpen" => $lng->txt("cont_first_open"),
182  "ForceAllOpen" => $lng->txt("cont_force_all_open"),
183  );
184  $si = new ilSelectInputGUI($this->lng->txt("cont_behavior"), "behavior");
185  $si->setOptions($options);
186  $this->form->addItem($si);
187 
188 
189  // alignment
190  $align_opts = array("Left" => $lng->txt("cont_left"),
191  "Right" => $lng->txt("cont_right"), "Center" => $lng->txt("cont_center"),
192  "LeftFloat" => $lng->txt("cont_left_float"),
193  "RightFloat" => $lng->txt("cont_right_float"));
194  $align = new ilSelectInputGUI($this->lng->txt("cont_align"), "align");
195  $align->setOptions($align_opts);
196  $align->setValue("Center");
197  $align->setInfo($lng->txt("cont_tabs_hor_align_info"));
198  $this->form->addItem($align);
199 
200  // save/cancel buttons
201  if ($a_mode == "create")
202  {
203  $this->form->addCommandButton("create_section", $lng->txt("save"));
204  $this->form->addCommandButton("cancelCreate", $lng->txt("cancel"));
205  }
206  else
207  {
208  $this->form->addCommandButton("update", $lng->txt("save"));
209  $this->form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
210  }
211  }
212 
216  function getFormValues()
217  {
218  $values["type"] = $this->content_obj->getTabType();
219  $values["content_width"] = $this->content_obj->getContentWidth();
220  $values["content_height"] = $this->content_obj->getContentHeight();
221  $values["align"] = $this->content_obj->getHorizontalAlign();
222  $values["behavior"] = $this->content_obj->getBehavior();
223  $this->form->setValuesByArray($values);
224 
225  if ($values["type"] == ilPCTabs::ACCORDION_VER)
226  {
227  $va = $this->form->getItemByPostVar("vaccord_templ");
228  $v = "t:".
229  ilObjStyleSheet::_lookupTemplateIdByName($this->getStyleId(), $this->content_obj->getTemplate()).":".
230  $this->content_obj->getTemplate();
231  $va->setValue($v);
232  }
233  if ($values["type"] == ilPCTabs::ACCORDION_HOR)
234  {
235  $ha = $this->form->getItemByPostVar("haccord_templ");
236  $v = "t:".
237  ilObjStyleSheet::_lookupTemplateIdByName($this->getStyleId(), $this->content_obj->getTemplate()).":".
238  $this->content_obj->getTemplate();
239  $ha->setValue($v);
240  }
241  }
242 
246  function create()
247  {
248  global $ilDB, $lng;
249 
250  $this->initForm("create");
251  if ($this->form->checkInput())
252  {
253  $this->content_obj = new ilPCTabs($this->dom);
254  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
255  $this->content_obj->setTabType($_POST["type"]);
256  $this->content_obj->setContentWidth($_POST["content_width"]);
257  $this->content_obj->setContentHeight($_POST["content_height"]);
258  $this->content_obj->setHorizontalAlign($_POST["align"]);
259  $this->content_obj->setBehavior($_POST["behavior"]);
260  for ($i = 0; $i < (int) $_POST["nr"]; $i++)
261  {
262  $this->content_obj->addTab($lng->txt("cont_new_tab"));
263  }
264  if ($_POST["type"] == ilPCTabs::ACCORDION_VER)
265  {
266  $t = explode(":", $_POST["vaccord_templ"]);
267  $this->content_obj->setTemplate($t[2]);
268  }
269  if ($_POST["type"] == ilPCTabs::ACCORDION_HOR)
270  {
271  $t = explode(":", $_POST["haccord_templ"]);
272  $this->content_obj->setTemplate($t[2]);
273  }
274  $this->updated = $this->pg_obj->update();
275 
276  if ($this->updated === true)
277  {
278  $this->afterCreation();
279  //$this->ctrl->returnToParent($this, "jump".$this->hier_id);
280  }
281  else
282  {
283  $this->insert();
284  }
285  }
286  else
287  {
288  $this->form->setValuesByPost();
289  $this->insert(true);
290 // return $this->form->getHtml();
291  }
292  }
293 
297  function afterCreation()
298  {
299  global $ilCtrl;
300 
301  $this->pg_obj->stripHierIDs();
302  $this->pg_obj->addHierIDs();
303  $ilCtrl->setParameter($this, "hier_id", $this->content_obj->readHierId());
304  $ilCtrl->setParameter($this, "pc_id", $this->content_obj->readPCId());
305  $this->content_obj->setHierId($this->content_obj->readHierId());
306  $this->setHierId($this->content_obj->readHierId());
307  $this->content_obj->setPCId($this->content_obj->readPCId());
308  $this->editTabs();
309  }
310 
311 
315  function update()
316  {
317  $this->initForm();
318  if ($this->form->checkInput())
319  {
320  $this->content_obj->setTabType(ilUtil::stripSlashes($_POST["type"]));
321  $this->content_obj->setContentWidth($_POST["content_width"]);
322  $this->content_obj->setContentHeight($_POST["content_height"]);
323  $this->content_obj->setHorizontalAlign($_POST["align"]);
324  $this->content_obj->setTemplate("");
325  $this->content_obj->setBehavior($_POST["behavior"]);
326  if ($_POST["type"] == ilPCTabs::ACCORDION_VER)
327  {
328  $t = explode(":", $_POST["vaccord_templ"]);
329  $this->content_obj->setTemplate($t[2]);
330  }
331  if ($_POST["type"] == ilPCTabs::ACCORDION_HOR)
332  {
333  $t = explode(":", $_POST["haccord_templ"]);
334  $this->content_obj->setTemplate($t[2]);
335  }
336  }
337  $this->updated = $this->pg_obj->update();
338  if ($this->updated === true)
339  {
340  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
341  }
342  else
343  {
344  $this->pg_obj->addHierIDs();
345  $this->edit();
346  }
347  }
348 
349  //
350  // Edit Tabs
351  //
352 
353 
357  function editTabs()
358  {
359  global $tpl, $ilTabs;
360 
361  $this->setTabs();
362  $ilTabs->activateTab("cont_tabs");
363  include_once("./Services/COPage/classes/class.ilPCTabsTableGUI.php");
364  $table_gui = new ilPCTabsTableGUI($this, "editTabs", $this->content_obj);
365  $tpl->setContent($table_gui->getHTML());
366  }
367 
371  function saveTabs()
372  {
373  global $ilCtrl, $lng;
374 
375  if (is_array($_POST["caption"]))
376  {
377  $captions = ilUtil::stripSlashesArray($_POST["caption"]);
378  $this->content_obj->saveCaptions($captions);
379  }
380  if (is_array($_POST["position"]))
381  {
382  $positions = ilUtil::stripSlashesArray($_POST["position"]);
383  $this->content_obj->savePositions($positions);
384  }
385  $this->updated = $this->pg_obj->update();
386  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
387  $ilCtrl->redirect($this, "editTabs");
388  }
389 
393  function addTab()
394  {
395  global $lng, $ilCtrl;
396 
397  $this->content_obj->addTab($lng->txt("cont_new_tab"));
398  $this->updated = $this->pg_obj->update();
399 
400  ilUtil::sendSuccess($lng->txt("cont_added_tab"), true);
401  $ilCtrl->redirect($this, "editTabs");
402  }
403 
408  {
409  global $ilCtrl, $tpl, $lng;
410 
411  $this->setTabs();
412 
413  if (!is_array($_POST["tid"]) || count($_POST["tid"]) == 0)
414  {
415  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
416  $ilCtrl->redirect($this, "editTabs");
417  }
418  else
419  {
420  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
421  $cgui = new ilConfirmationGUI();
422  $cgui->setFormAction($ilCtrl->getFormAction($this));
423  $cgui->setHeaderText($lng->txt("cont_tabs_confirm_deletion"));
424  $cgui->setCancel($lng->txt("cancel"), "cancelTabDeletion");
425  $cgui->setConfirm($lng->txt("delete"), "deleteTabs");
426 
427  foreach ($_POST["tid"] as $k => $i)
428  {
429  $id = explode(":", $k);
430  $cgui->addItem("tid[]", $k,
431  $this->content_obj->getCaption($id[0], $id[1]));
432  }
433 
434  $tpl->setContent($cgui->getHTML());
435  }
436  }
437 
441  function cancelTabDeletion()
442  {
443  global $ilCtrl;
444  $ilCtrl->redirect($this, "editTabs");
445  }
446 
450  function deleteTabs()
451  {
452  global $ilCtrl;
453 
454  if (is_array($_POST["tid"]))
455  {
456  foreach($_POST["tid"] as $tid)
457  {
458  $ids = explode(":", $tid);
459  $this->content_obj->deleteTab($ids[0], $ids[1]);
460  }
461  }
462  $this->updated = $this->pg_obj->update();
463 
464  $ilCtrl->redirect($this, "editTabs");
465  }
466 
467 
471  function setTabs()
472  {
473  global $ilTabs, $ilCtrl, $lng;
474 
475  $ilTabs->setBackTarget($lng->txt("pg"),
476  $this->ctrl->getParentReturn($this));
477 
478  $ilTabs->addTarget("cont_tabs",
479  $ilCtrl->getLinkTarget($this, "editTabs"), "editTabs",
480  get_class($this));
481 
482  $ilTabs->addTarget("cont_edit_tabs",
483  $ilCtrl->getLinkTarget($this, "edit"), "edit",
484  get_class($this));
485 
486  }
487 }
488 ?>