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 7/** 8* Class ilPCTabsGUI 9* 10* User Interface for Tabbed Content 11* 12* @author Alex Killing <alex.killing@gmx.de> 13* @version $Id$ 14* 15* @ingroup ServicesCOPage 16*/ 17class ilPCTabsGUI extends ilPageContentGUI 18{ 19 /** 20 * @var ilDB 21 */ 22 protected $db; 23 24 /** 25 * @var ilTabsGUI 26 */ 27 protected $tabs; 28 29 /** 30 * @var ilToolbarGUI 31 */ 32 protected $toolbar; 33 34 /** 35 * Constructor 36 * @access public 37 */ 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 51 /** 52 * execute command 53 */ 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 71 /** 72 * Insert new tabs 73 */ 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 87 /** 88 * Edit tabs 89 */ 90 public function editProperties() 91 { 92 $ilCtrl = $this->ctrl; 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 105 /** 106 * Insert tabs form. 107 */ 108 public function initForm($a_mode = "edit") 109 { 110 $ilCtrl = $this->ctrl; 111 $tpl = $this->tpl; 112 $lng = $this->lng; 113 114 include_once("./Services/Accordion/classes/class.ilAccordionGUI.php"); 115 ilAccordionGUI::addCss(); 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"); 130 $radg->setValue(ilPCTabs::ACCORDION_VER); 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 287 /** 288 * Get form values 289 */ 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 328 /** 329 * Create new tabs in dom and update page in db 330 */ 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 362 /** 363 * After creation processing 364 */ 365 public function afterCreation() 366 { 367 $ilCtrl = $this->ctrl; 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 379 /** 380 * Set properties by post 381 * 382 * @param 383 * @return 384 */ 385 public function setPropertiesByForm() 386 { 387 $c = $this->content_obj; 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"]) { 396 case ilPCTabs::ACCORDION_VER: 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 403 case ilPCTabs::ACCORDION_HOR: 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 420 /** 421 * Save tabs properties in db and return to page edit screen 422 */ 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 446 /** 447 * List all tabs 448 */ 449 public function edit() 450 { 451 $tpl = $this->tpl; 452 $ilTabs = $this->tabs; 453 $ilCtrl = $this->ctrl; 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 469 /** 470 * Save tabs properties in db and return to page edit screen 471 */ 472 public function saveTabs() 473 { 474 $ilCtrl = $this->ctrl; 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 490 /** 491 * Save tabs properties in db and return to page edit screen 492 */ 493 public function addTab() 494 { 495 $lng = $this->lng; 496 $ilCtrl = $this->ctrl; 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 505 /** 506 * Confirm tabs deletion 507 */ 508 public function confirmTabsDeletion() 509 { 510 $ilCtrl = $this->ctrl; 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 540 /** 541 * Cancel tab deletion 542 */ 543 public function cancelTabDeletion() 544 { 545 $ilCtrl = $this->ctrl; 546 $ilCtrl->redirect($this, "edit"); 547 } 548 549 /** 550 * Delete Tabs 551 */ 552 public function deleteTabs() 553 { 554 $ilCtrl = $this->ctrl; 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 568 /** 569 * Set tabs 570 */ 571 public function setTabs() 572 { 573 $ilTabs = $this->tabs; 574 $ilCtrl = $this->ctrl; 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} 597