ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPCTabsGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2008 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 require_once("./Services/COPage/classes/class.ilPCTabs.php");
25 require_once("./Services/COPage/classes/class.ilPageContentGUI.php");
26 
38 {
39 
44  function ilPCTabsGUI(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id = "")
45  {
46  parent::ilPageContentGUI($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
47  }
48 
52  function &executeCommand()
53  {
54  // get next class that processes or forwards current command
55  $next_class = $this->ctrl->getNextClass($this);
56 
57  // get current command
58  $cmd = $this->ctrl->getCmd();
59 
60  switch($next_class)
61  {
62  default:
63  $ret =& $this->$cmd();
64  break;
65  }
66 
67  return $ret;
68  }
69 
70 
74  function insert()
75  {
76  $this->edit(true);
77  }
78 
82  function edit($a_insert = false)
83  {
84  global $ilCtrl, $tpl, $lng;
85 
86  $this->displayValidationError();
87 
88  // edit form
89  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
90  $form = new ilPropertyFormGUI();
91  $form->setFormAction($ilCtrl->getFormAction($this));
92  if ($a_insert)
93  {
94  $form->setTitle($this->lng->txt("cont_insert_tabs"));
95  }
96  else
97  {
98  $form->setTitle($this->lng->txt("cont_update_tabs"));
99  }
100 
101  // tabs type
102  $type_prop = new ilSelectInputGUI($this->lng->txt("cont_type"),
103  "type");
104  $types = array("HorizontalTabs" => $this->lng->txt("cont_tabs_hor_tabs"),
105  "Accordion" => $this->lng->txt("cont_tabs_accordion"));
106  $selected = ($a_insert)
107  ? ""
108  : $this->content_obj->getTabType();
109  $type_prop->setValue($selected);
110  $type_prop->setOptions($types);
111  $form->addItem($type_prop);
112 
113  // number of initial tabs
114  if ($a_insert)
115  {
116  $nr_prop = new ilSelectInputGUI($this->lng->txt("cont_number_of_tabs"),
117  "nr");
118  $nrs = array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6,
119  7 => 7, 8 => 8, 9 => 9, 10 => 10);
120  $nr_prop->setOptions($nrs);
121  $form->addItem($nr_prop);
122  }
123  else
124  {
125  $captions = $this->content_obj->getCaptions();
126  $i = 0;
127  foreach($captions as $caption)
128  {
129  $cap_prop[$i] = new ilTextInputGUI($this->lng->txt("cont_caption")." ".($i + 1),
130  "caption[$i]");
131  $cap_prop[$i]->setValue($caption);
132  $form->addItem($cap_prop[$i]);
133  $i++;
134  }
135  }
136 
137  // save/cancel buttons
138  if ($a_insert)
139  {
140  $form->addCommandButton("create_section", $lng->txt("save"));
141  $form->addCommandButton("cancelCreate", $lng->txt("cancel"));
142  }
143  else
144  {
145  $form->addCommandButton("update_section", $lng->txt("save"));
146  $form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
147  }
148  $html = $form->getHTML();
149  $tpl->setContent($html);
150  return $ret;
151  }
152 
153 
157  function create()
158  {
159  $this->content_obj = new ilPCTabs($this->dom);
160  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
161  $this->content_obj->addItems($_POST["nr"]);
162  $this->content_obj->setTabType($_POST["type"]);
163  $this->updated = $this->pg_obj->update();
164  if ($this->updated === true)
165  {
166  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
167  }
168  else
169  {
170  $this->insert();
171  }
172  }
173 
177  function update()
178  {
179  $this->content_obj->setTabType(ilUtil::stripSlashes($_POST["type"]));
180  if (is_array($_POST["caption"]))
181  {
182  $caption = array();
183  foreach($_POST["caption"] as $k => $v)
184  {
185  $caption[$k] = ilUtil::stripSlashes($v);
186  }
187  $this->content_obj->setCaptions($caption);
188  }
189  $this->updated = $this->pg_obj->update();
190  if ($this->updated === true)
191  {
192  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
193  }
194  else
195  {
196  $this->pg_obj->addHierIDs();
197  $this->edit();
198  }
199  }
200 }
201 ?>