ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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
4require_once("./Services/COPage/classes/class.ilPCTabs.php");
5require_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
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 editProperties()
70 {
71 global $ilCtrl, $lng, $tpl;
72
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");
147 $radg->setValue(ilPCTabs::ACCORDION_VER);
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->getPage());
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->edit();
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->editProperties();
346 }
347 }
348
349 //
350 // Edit Tabs
351 //
352
353
357 function edit()
358 {
359 global $tpl, $ilTabs, $ilCtrl, $ilToolbar, $lng;
360
361 $ilToolbar->addButton($lng->txt("cont_add_tab"),
362 $ilCtrl->getLinkTarget($this, "addTab"));
363
364 $this->setTabs();
365 $ilTabs->activateTab("cont_tabs");
366 include_once("./Services/COPage/classes/class.ilPCTabsTableGUI.php");
367 $table_gui = new ilPCTabsTableGUI($this, "edit", $this->content_obj);
368 $tpl->setContent($table_gui->getHTML());
369 }
370
374 function saveTabs()
375 {
376 global $ilCtrl, $lng;
377
378 if (is_array($_POST["caption"]))
379 {
380 $captions = ilUtil::stripSlashesArray($_POST["caption"]);
381 $this->content_obj->saveCaptions($captions);
382 }
383 if (is_array($_POST["position"]))
384 {
385 $positions = ilUtil::stripSlashesArray($_POST["position"]);
386 $this->content_obj->savePositions($positions);
387 }
388 $this->updated = $this->pg_obj->update();
389 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
390 $ilCtrl->redirect($this, "edit");
391 }
392
396 function addTab()
397 {
398 global $lng, $ilCtrl;
399
400 $this->content_obj->addTab($lng->txt("cont_new_tab"));
401 $this->updated = $this->pg_obj->update();
402
403 ilUtil::sendSuccess($lng->txt("cont_added_tab"), true);
404 $ilCtrl->redirect($this, "edit");
405 }
406
411 {
412 global $ilCtrl, $tpl, $lng;
413
414 $this->setTabs();
415
416 if (!is_array($_POST["tid"]) || count($_POST["tid"]) == 0)
417 {
418 ilUtil::sendInfo($lng->txt("no_checkbox"), true);
419 $ilCtrl->redirect($this, "edit");
420 }
421 else
422 {
423 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
424 $cgui = new ilConfirmationGUI();
425 $cgui->setFormAction($ilCtrl->getFormAction($this));
426 $cgui->setHeaderText($lng->txt("cont_tabs_confirm_deletion"));
427 $cgui->setCancel($lng->txt("cancel"), "cancelTabDeletion");
428 $cgui->setConfirm($lng->txt("delete"), "deleteTabs");
429
430 foreach ($_POST["tid"] as $k => $i)
431 {
432 $id = explode(":", $k);
433 $cgui->addItem("tid[]", $k,
434 $this->content_obj->getCaption($id[0], $id[1]));
435 }
436
437 $tpl->setContent($cgui->getHTML());
438 }
439 }
440
445 {
446 global $ilCtrl;
447 $ilCtrl->redirect($this, "edit");
448 }
449
453 function deleteTabs()
454 {
455 global $ilCtrl;
456
457 if (is_array($_POST["tid"]))
458 {
459 foreach($_POST["tid"] as $tid)
460 {
461 $ids = explode(":", $tid);
462 $this->content_obj->deleteTab($ids[0], $ids[1]);
463 }
464 }
465 $this->updated = $this->pg_obj->update();
466
467 $ilCtrl->redirect($this, "edit");
468 }
469
470
474 function setTabs()
475 {
476 global $ilTabs, $ilCtrl, $lng;
477
478 $ilTabs->setBackTarget($lng->txt("pg"),
479 $this->ctrl->getParentReturn($this));
480
481 $ilTabs->addTarget("cont_tabs",
482 $ilCtrl->getLinkTarget($this, "edit"), "edit",
483 get_class($this));
484
485 $ilTabs->addTarget("cont_edit_tabs",
486 $ilCtrl->getLinkTarget($this, "editProperties"), "editProperties",
487 get_class($this));
488
489 }
490}
491?>
static addCss()
Add required css.
This class represents an advanced selection list property in a property form.
Confirmation screen class.
This class represents a number property in a property form.
static _lookupTemplateIdByName($a_style_id, $a_name)
Lookup table template preview.
Class ilPCTabsGUI.
cancelTabDeletion()
Cancel tab deletion.
update()
Save tabs properties in db and return to page edit screen.
ilPCTabsGUI(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id="")
Constructor @access public.
confirmTabsDeletion()
Confirm tabs deletion.
afterCreation()
After creation processing.
insert($a_omit_form_init=false)
Insert new tabs.
& executeCommand()
execute command
deleteTabs()
Delete Tabs.
initForm($a_mode="edit")
Insert tabs form.
editProperties()
Edit tabs.
edit()
List all tabs.
getFormValues()
Get form values.
setTabs()
Set tabs.
create()
Create new tabs in dom and update page in db.
addTab()
Save tabs properties in db and return to page edit screen.
saveTabs()
Save tabs properties in db and return to page edit screen.
TableGUI class for tabs.
Class ilPCTabs.
const ACCORDION_HOR
const ACCORDION_VER
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
getTemplateOptions($a_type)
Get table templates.
displayValidationError()
display validation errors
setHierId($a_hier_id)
get hierarchical id in dom object
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a selection list property in a property form.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static stripSlashesArray($a_arr, $a_strip_html=true, $a_allow="")
Strip slashes from array.
$_POST['username']
Definition: cron.php:12
global $ilCtrl
Definition: ilias.php:18
$cmd
Definition: sahs_server.php:35
global $ilDB
if(!is_array($argv)) $options