ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 {
22  protected $db;
23 
27  protected $tabs;
28 
32  protected $toolbar;
33 
38  public function __construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id = "")
39  {
40  global $DIC;
41 
42  $this->tpl = $DIC["tpl"];
43  $this->ctrl = $DIC->ctrl();
44  $this->lng = $DIC->language();
45  $this->db = $DIC->database();
46  $this->tabs = $DIC->tabs();
47  $this->toolbar = $DIC->toolbar();
48  parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
49  }
50 
54  public function executeCommand()
55  {
56  // get next class that processes or forwards current command
57  $next_class = $this->ctrl->getNextClass($this);
58 
59  // get current command
60  $cmd = $this->ctrl->getCmd();
61 
62  switch ($next_class) {
63  default:
64  $ret = $this->$cmd();
65  break;
66  }
67 
68  return $ret;
69  }
70 
74  public function insert($a_omit_form_init = false)
75  {
76  $tpl = $this->tpl;
77 
78  $this->displayValidationError();
79 
80  if (!$a_omit_form_init) {
81  $this->initForm("create");
82  }
83  $html = $this->form->getHTML();
84  $tpl->setContent($html);
85  }
86 
90  public function editProperties()
91  {
93  $lng = $this->lng;
94  $tpl = $this->tpl;
95 
96  $this->displayValidationError();
97  $this->setTabs();
98 
99  $this->initForm();
100  $this->getFormValues();
101  $html = $this->form->getHTML();
102  $tpl->setContent($html);
103  }
104 
108  public function initForm($a_mode = "edit")
109  {
111  $tpl = $this->tpl;
112  $lng = $this->lng;
113 
114  include_once("./Services/Accordion/classes/class.ilAccordionGUI.php");
116 
117  // edit form
118  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
119  $this->form = new ilPropertyFormGUI();
120  $this->form->setFormAction($ilCtrl->getFormAction($this));
121  if ($a_mode != "edit") {
122  $this->form->setTitle($lng->txt("cont_ed_insert_tabs"));
123  } else {
124  $this->form->setTitle($lng->txt("cont_edit_tabs"));
125  }
126 
127 
128  // type selection
129  $radg = new ilRadioGroupInputGUI($lng->txt("cont_type"), "type");
131 
132  // type: vertical accordion
133  $op1 = new ilRadioOption($lng->txt("cont_tabs_acc_ver"), ilPCTabs::ACCORDION_VER);
134 
135  $templ = $this->getTemplateOptions("vaccordion");
136  require_once("./Services/Form/classes/class.ilAdvSelectInputGUI.php");
137  if (count($templ) > 0) {
138  $vchar_prop = new ilAdvSelectInputGUI(
139  $this->lng->txt("cont_characteristic"),
140  "vaccord_templ"
141  );
142  foreach ($templ as $k => $te) {
143  $t = explode(":", $k);
144  $html = $this->style->lookupTemplatePreview($t[1]) . '<div style="clear:both" class="small">' . $te . "</div>";
145  $vchar_prop->addOption($k, $te, $html);
146  if ($t[2] == "VerticalAccordion") {
147  $vchar_prop->setValue($k);
148  }
149  }
150  $op1->addSubItem($vchar_prop);
151  } else {
152  $vchar_prop = new ilHiddenInputGUI("vaccord_templ");
153  $this->form->addItem($vchar_prop);
154  }
155  $radg->addOption($op1);
156 
157 
158 
159  // type: horizontal accordion
160  $op2 = new ilRadioOption($lng->txt("cont_tabs_acc_hor"), ilPCTabs::ACCORDION_HOR);
161 
162  $templ = $this->getTemplateOptions("haccordion");
163  if (count($templ) > 0) {
164  $hchar_prop = new ilAdvSelectInputGUI(
165  $this->lng->txt("cont_characteristic"),
166  "haccord_templ"
167  );
168  foreach ($templ as $k => $te) {
169  $t = explode(":", $k);
170  $html = $this->style->lookupTemplatePreview($t[1]) . '<div style="clear:both" class="small">' . $te . "</div>";
171  $hchar_prop->addOption($k, $te, $html);
172  if ($t[2] == "HorizontalAccordion") {
173  $hchar_prop->setValue($k);
174  }
175  }
176  $op2->addSubItem($hchar_prop);
177  } else {
178  $hchar_prop = new ilHiddenInputGUI("haccord_templ");
179  $this->form->addItem($hchar_prop);
180  }
181 
182  $radg->addOption($op2);
183 
184  // type: carousel
185  $op3 = new ilRadioOption($lng->txt("cont_tabs_carousel"), ilPCTabs::CAROUSEL);
186  $templ = $this->getTemplateOptions("carousel");
187  require_once("./Services/Form/classes/class.ilAdvSelectInputGUI.php");
188  if (count($templ) > 0) {
189  $cchar_prop = new ilAdvSelectInputGUI(
190  $this->lng->txt("cont_characteristic"),
191  "carousel_templ"
192  );
193  foreach ($templ as $k => $te) {
194  $t = explode(":", $k);
195  $html = $this->style->lookupTemplatePreview($t[1]) . '<div style="clear:both" class="small">' . $te . "</div>";
196  $cchar_prop->addOption($k, $te, $html);
197  if ($t[2] == "Carousel") {
198  $cchar_prop->setValue($k);
199  }
200  }
201  $op3->addSubItem($cchar_prop);
202  } else {
203  $cchar_prop = new ilHiddenInputGUI("carousel_templ");
204  $this->form->addItem($cchar_prop);
205  }
206 
207  $radg->addOption($op3);
208  $this->form->addItem($radg);
209 
210 
211  // number of initial tabs
212  if ($a_mode == "create") {
213  $nr_prop = new ilSelectInputGUI(
214  $lng->txt("cont_number_of_tabs"),
215  "nr"
216  );
217  $nrs = array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6,
218  7 => 7, 8 => 8, 9 => 9, 10 => 10);
219  $nr_prop->setOptions($nrs);
220  $this->form->addItem($nr_prop);
221  }
222 
223  $ni = new ilNumberInputGUI($this->lng->txt("cont_tab_cont_width"), "content_width");
224  $ni->setMaxLength(4);
225  $ni->setSize(4);
226  $this->form->addItem($ni);
227 
228  $ni = new ilNumberInputGUI($this->lng->txt("cont_tab_cont_height"), "content_height");
229  $ni->setMaxLength(4);
230  $ni->setSize(4);
231  $this->form->addItem($ni);
232 
233  // behaviour
234  $options = array(
235  "AllClosed" => $lng->txt("cont_all_closed"),
236  "FirstOpen" => $lng->txt("cont_first_open"),
237  "ForceAllOpen" => $lng->txt("cont_force_all_open"),
238  );
239  $si = new ilSelectInputGUI($this->lng->txt("cont_behavior"), "vbehavior");
240  $si->setOptions($options);
241  $op1->addSubItem($si);
242  $si = new ilSelectInputGUI($this->lng->txt("cont_behavior"), "hbehavior");
243  $si->setOptions($options);
244  $op2->addSubItem($si);
245 
246 
247  // alignment
248  $align_opts = array("Left" => $lng->txt("cont_left"),
249  "Right" => $lng->txt("cont_right"), "Center" => $lng->txt("cont_center"),
250  "LeftFloat" => $lng->txt("cont_left_float"),
251  "RightFloat" => $lng->txt("cont_right_float"));
252  $align = new ilSelectInputGUI($this->lng->txt("cont_align"), "valign");
253  $align->setOptions($align_opts);
254  $align->setValue("Center");
255  //$align->setInfo($lng->txt("cont_tabs_hor_align_info"));
256  $op1->addSubItem($align);
257  $align = new ilSelectInputGUI($this->lng->txt("cont_align"), "calign");
258  $align->setOptions($align_opts);
259  $align->setValue("Center");
260  $op3->addSubItem($align);
261 
262  // carousel: time
263  $ti = new ilNumberInputGUI($this->lng->txt("cont_auto_time"), "auto_time");
264  $ti->setMaxLength(6);
265  $ti->setSize(6);
266  $ti->setSuffix("ms");
267  $ti->setMinValue(100);
268  $op3->addSubItem($ti);
269 
270  // carousel: random start
271  $cb = new ilCheckboxInputGUI($this->lng->txt("cont_rand_start"), "rand_start");
272  //$cb->setOptionTitle($this->lng->txt(""));
273  //$cb->setInfo($this->lng->txt(""));
274  $op3->addSubItem($cb);
275 
276 
277  // save/cancel buttons
278  if ($a_mode == "create") {
279  $this->form->addCommandButton("create_section", $lng->txt("save"));
280  $this->form->addCommandButton("cancelCreate", $lng->txt("cancel"));
281  } else {
282  $this->form->addCommandButton("update", $lng->txt("save"));
283  $this->form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
284  }
285  }
286 
290  public function getFormValues()
291  {
292  $values["type"] = $this->content_obj->getTabType();
293  $values["content_width"] = $this->content_obj->getContentWidth();
294  $values["content_height"] = $this->content_obj->getContentHeight();
295  $values["valign"] = $this->content_obj->getHorizontalAlign();
296  $values["calign"] = $this->content_obj->getHorizontalAlign();
297  $values["vbehavior"] = $this->content_obj->getBehavior();
298  $values["hbehavior"] = $this->content_obj->getBehavior();
299 
300  $values["auto_time"] = $this->content_obj->getAutoTime();
301  $values["rand_start"] = $this->content_obj->getRandomStart();
302 
303  $this->form->setValuesByArray($values);
304 
305  if ($values["type"] == ilPCTabs::ACCORDION_VER) {
306  $va = $this->form->getItemByPostVar("vaccord_templ");
307  $v = "t:" .
308  ilObjStyleSheet::_lookupTemplateIdByName($this->getStyleId(), $this->content_obj->getTemplate()) . ":" .
309  $this->content_obj->getTemplate();
310  $va->setValue($v);
311  }
312  if ($values["type"] == ilPCTabs::ACCORDION_HOR) {
313  $ha = $this->form->getItemByPostVar("haccord_templ");
314  $v = "t:" .
315  ilObjStyleSheet::_lookupTemplateIdByName($this->getStyleId(), $this->content_obj->getTemplate()) . ":" .
316  $this->content_obj->getTemplate();
317  $ha->setValue($v);
318  }
319  if ($values["type"] == ilPCTabs::CAROUSEL) {
320  $ca = $this->form->getItemByPostVar("carousel_templ");
321  $v = "t:" .
322  ilObjStyleSheet::_lookupTemplateIdByName($this->getStyleId(), $this->content_obj->getTemplate()) . ":" .
323  $this->content_obj->getTemplate();
324  $ca->setValue($v);
325  }
326  }
327 
331  public function create()
332  {
333  $ilDB = $this->db;
334  $lng = $this->lng;
335 
336  $this->initForm("create");
337  if ($this->form->checkInput()) {
338  $this->content_obj = new ilPCTabs($this->getPage());
339  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
340 
341  $this->setPropertiesByForm();
342 
343  for ($i = 0; $i < (int) $_POST["nr"]; $i++) {
344  $this->content_obj->addTab($lng->txt("cont_new_tab"));
345  }
346 
347  $this->updated = $this->pg_obj->update();
348 
349  if ($this->updated === true) {
350  $this->afterCreation();
351  //$this->ctrl->returnToParent($this, "jump".$this->hier_id);
352  } else {
353  $this->insert();
354  }
355  } else {
356  $this->form->setValuesByPost();
357  $this->insert(true);
358  // return $this->form->getHtml();
359  }
360  }
361 
365  public function afterCreation()
366  {
368 
369  $this->pg_obj->stripHierIDs();
370  $this->pg_obj->addHierIDs();
371  $ilCtrl->setParameter($this, "hier_id", $this->content_obj->readHierId());
372  $ilCtrl->setParameter($this, "pc_id", $this->content_obj->readPCId());
373  $this->content_obj->setHierId($this->content_obj->readHierId());
374  $this->setHierId($this->content_obj->readHierId());
375  $this->content_obj->setPCId($this->content_obj->readPCId());
376  $this->edit();
377  }
378 
385  public function setPropertiesByForm()
386  {
388  $f = $this->form;
389 
390  $c->setTabType($f->getInput("type"));
391 
392  $c->setContentWidth($f->getInput("content_width"));
393  $c->setContentHeight($f->getInput("content_height"));
394  $c->setTemplate("");
395  switch ($_POST["type"]) {
397  $t = explode(":", $f->getInput("vaccord_templ"));
398  $c->setTemplate($t[2]);
399  $c->setBehavior($f->getInput("vbehavior"));
400  $c->setHorizontalAlign($f->getInput("valign"));
401  break;
402 
404  $t = explode(":", $f->getInput("haccord_templ"));
405  $c->setTemplate($t[2]);
406  $c->setBehavior($f->getInput("hbehavior"));
407  break;
408 
409  case ilPCTabs::CAROUSEL:
410  $t = explode(":", $f->getInput("carousel_templ"));
411  $c->setTemplate($t[2]);
412  $c->setHorizontalAlign($f->getInput("calign"));
413  $c->setAutoTime($f->getInput("auto_time"));
414  $c->setRandomStart($f->getInput("rand_start"));
415  break;
416  }
417  }
418 
419 
423  public function update()
424  {
425  $this->initForm();
426  $this->updated = false;
427  if ($this->form->checkInput()) {
428  $this->setPropertiesByForm();
429  $this->updated = $this->pg_obj->update();
430  }
431  if ($this->updated === true) {
432  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
433  $this->ctrl->redirect($this, "editProperties");
434  //$this->ctrl->returnToParent($this, "jump".$this->hier_id);
435  } else {
436  $this->pg_obj->addHierIDs();
437  $this->editProperties();
438  }
439  }
440 
441  //
442  // Edit Tabs
443  //
444 
445 
449  public function edit()
450  {
451  $tpl = $this->tpl;
452  $ilTabs = $this->tabs;
454  $ilToolbar = $this->toolbar;
455  $lng = $this->lng;
456 
457  $ilToolbar->addButton(
458  $lng->txt("cont_add_tab"),
459  $ilCtrl->getLinkTarget($this, "addTab")
460  );
461 
462  $this->setTabs();
463  $ilTabs->activateTab("cont_tabs");
464  include_once("./Services/COPage/classes/class.ilPCTabsTableGUI.php");
465  $table_gui = new ilPCTabsTableGUI($this, "edit", $this->content_obj);
466  $tpl->setContent($table_gui->getHTML());
467  }
468 
472  public function saveTabs()
473  {
475  $lng = $this->lng;
476 
477  if (is_array($_POST["caption"])) {
478  $captions = ilUtil::stripSlashesArray($_POST["caption"]);
479  $this->content_obj->saveCaptions($captions);
480  }
481  if (is_array($_POST["position"])) {
482  $positions = ilUtil::stripSlashesArray($_POST["position"]);
483  $this->content_obj->savePositions($positions);
484  }
485  $this->updated = $this->pg_obj->update();
486  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
487  $ilCtrl->redirect($this, "edit");
488  }
489 
493  public function addTab()
494  {
495  $lng = $this->lng;
497 
498  $this->content_obj->addTab($lng->txt("cont_new_tab"));
499  $this->updated = $this->pg_obj->update();
500 
501  ilUtil::sendSuccess($lng->txt("cont_added_tab"), true);
502  $ilCtrl->redirect($this, "edit");
503  }
504 
508  public function confirmTabsDeletion()
509  {
511  $tpl = $this->tpl;
512  $lng = $this->lng;
513 
514  $this->setTabs();
515 
516  if (!is_array($_POST["tid"]) || count($_POST["tid"]) == 0) {
517  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
518  $ilCtrl->redirect($this, "edit");
519  } else {
520  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
521  $cgui = new ilConfirmationGUI();
522  $cgui->setFormAction($ilCtrl->getFormAction($this));
523  $cgui->setHeaderText($lng->txt("cont_tabs_confirm_deletion"));
524  $cgui->setCancel($lng->txt("cancel"), "cancelTabDeletion");
525  $cgui->setConfirm($lng->txt("delete"), "deleteTabs");
526 
527  foreach ($_POST["tid"] as $k => $i) {
528  $id = explode(":", $k);
529  $cgui->addItem(
530  "tid[]",
531  $k,
532  $this->content_obj->getCaption($id[0], $id[1])
533  );
534  }
535 
536  $tpl->setContent($cgui->getHTML());
537  }
538  }
539 
543  public function cancelTabDeletion()
544  {
546  $ilCtrl->redirect($this, "edit");
547  }
548 
552  public function deleteTabs()
553  {
555 
556  if (is_array($_POST["tid"])) {
557  foreach ($_POST["tid"] as $tid) {
558  $ids = explode(":", $tid);
559  $this->content_obj->deleteTab($ids[0], $ids[1]);
560  }
561  }
562  $this->updated = $this->pg_obj->update();
563 
564  $ilCtrl->redirect($this, "edit");
565  }
566 
567 
571  public function setTabs()
572  {
573  $ilTabs = $this->tabs;
575  $lng = $this->lng;
576 
577  $ilTabs->setBackTarget(
578  $lng->txt("pg"),
579  $this->ctrl->getParentReturn($this)
580  );
581 
582  $ilTabs->addTarget(
583  "cont_tabs",
584  $ilCtrl->getLinkTarget($this, "edit"),
585  "edit",
586  get_class($this)
587  );
588 
589  $ilTabs->addTarget(
590  "cont_edit_tabs",
591  $ilCtrl->getLinkTarget($this, "editProperties"),
592  "editProperties",
593  get_class($this)
594  );
595  }
596 }
static _lookupTemplateIdByName($a_style_id, $a_name)
Lookup table template preview.
__construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id="")
Constructor public.
This class represents an option in a radio group.
update()
Save tabs properties in db and return to page edit screen.
edit()
List all tabs.
This class represents a selection list property in a property form.
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
saveTabs()
Save tabs properties in db and return to page edit screen.
if(!array_key_exists('StateId', $_REQUEST)) $id
"color:#CC0000 style
Definition: example_001.php:92
deleteTabs()
Delete Tabs.
This class represents a checkbox property in a property form.
getTemplateOptions($a_type)
Get table templates.
create()
Create new tabs in dom and update page in db.
executeCommand()
execute command
global $ilCtrl
Definition: ilias.php:18
setPropertiesByForm()
Set properties by post.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
addTab()
Save tabs properties in db and return to page edit screen.
const ACCORDION_HOR
TableGUI class for tabs.
This class represents a hidden form property in a property form.
confirmTabsDeletion()
Confirm tabs deletion.
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
This class represents a property in a property form.
static addCss()
Add required css.
if(isset($_POST['submit'])) $form
cancelTabDeletion()
Cancel tab deletion.
This class represents a number property in a property form.
$values
afterCreation()
After creation processing.
displayValidationError()
display validation errors
const ACCORDION_VER
getStyleId()
Get Style Id.
getFormValues()
Get form values.
setOptions($a_options)
Set Options.
static stripSlashesArray($a_arr, $a_strip_html=true, $a_allow="")
Strip slashes from array.
insert($a_omit_form_init=false)
Insert new tabs.
editProperties()
Edit tabs.
setMaxLength($a_maxlength)
Set Max Length.
global $ilDB
$ret
Definition: parser.php:6
const CAROUSEL
$i
Definition: disco.tpl.php:19
Class ilPCTabsGUI.
setTabs()
Set tabs.
Class ilPCTabs.
This class represents an advanced selection list property in a property form.
$_POST["username"]
$html
Definition: example_001.php:87
initForm($a_mode="edit")
Insert tabs form.
setHierId($a_hier_id)
get hierarchical id in dom object
Confirmation screen class.