1<?php 2 3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */ 4 5require_once "./Services/Object/classes/class.ilObject2GUI.php"; 6include_once('./Modules/WebResource/classes/class.ilParameterAppender.php'); 7require_once 'Services/LinkChecker/interfaces/interface.ilLinkCheckerGUIRowHandling.php'; 8 9/** 10* Class ilObjLinkResourceGUI 11* 12* @author Stefan Meyer <smeyer.ilias@gmx.de> 13* @version $Id$ 14* 15* @ilCtrl_Calls ilObjLinkResourceGUI: ilObjectMetaDataGUI, ilPermissionGUI, ilInfoScreenGUI, ilObjectCopyGUI 16* @ilCtrl_Calls ilObjLinkResourceGUI: ilExportGUI, ilWorkspaceAccessGUI, ilCommonActionDispatcherGUI 17* @ilCtrl_Calls ilObjLinkResourceGUI: ilPropertyFormGUI, ilInternalLinkGUI 18* 19* 20* @ingroup ModulesWebResource 21*/ 22class ilObjLinkResourceGUI extends ilObject2GUI implements ilLinkCheckerGUIRowHandling 23{ 24 const VIEW_MODE_VIEW = 1; 25 const VIEW_MODE_MANAGE = 2; 26 const VIEW_MODE_SORT = 3; 27 28 const LINK_MOD_CREATE = 1; 29 const LINK_MOD_EDIT = 2; 30 const LINK_MOD_ADD = 3; 31 32 public function getType() 33 { 34 return "webr"; 35 } 36 37 public function executeCommand() 38 { 39 global $DIC; 40 41 $ilCtrl = $DIC['ilCtrl']; 42 $ilTabs = $DIC['ilTabs']; 43 $ilErr = $DIC['ilErr']; 44 $ilAccess = $DIC['ilAccess']; 45 46 47 //if($this->ctrl->getTargetScript() == 'link_resources.php') 48 if ($_GET["baseClass"] == 'ilLinkResourceHandlerGUI') { 49 $_GET['view_mode'] = isset($_GET['switch_mode']) ? $_GET['switch_mode'] : $_GET['view_mode']; 50 $ilCtrl->saveParameter($this, 'view_mode'); 51 $this->__prepareOutput(); 52 } 53 54 $this->lng->loadLanguageModule("webr"); 55 56 $next_class = $this->ctrl->getNextClass($this); 57 $cmd = $this->ctrl->getCmd(); 58 59 switch ($next_class) { 60 case "ilinfoscreengui": 61 $this->prepareOutput(); 62 $this->infoScreenForward(); // forwards command 63 break; 64 65 case 'ilobjectmetadatagui': 66 $this->checkPermission('write'); // #18563 67 $this->prepareOutput(); 68 $ilTabs->activateTab('id_meta_data'); 69 include_once 'Services/Object/classes/class.ilObjectMetaDataGUI.php'; 70 $md_gui = new ilObjectMetaDataGUI($this->object); 71 $this->ctrl->forwardCommand($md_gui); 72 break; 73 74 case 'ilpermissiongui': 75 $this->prepareOutput(); 76 $ilTabs->activateTab('id_permissions'); 77 include_once("Services/AccessControl/classes/class.ilPermissionGUI.php"); 78 $perm_gui = new ilPermissionGUI($this); 79 $ret = &$this->ctrl->forwardCommand($perm_gui); 80 break; 81 82 case 'ilobjectcopygui': 83 $this->prepareOutput(); 84 include_once './Services/Object/classes/class.ilObjectCopyGUI.php'; 85 $cp = new ilObjectCopyGUI($this); 86 $cp->setType('webr'); 87 $this->ctrl->forwardCommand($cp); 88 break; 89 90 case 'ilexportgui': 91 $this->prepareOutput(); 92 $this->tabs_gui->setTabActive('export'); 93 include_once './Services/Export/classes/class.ilExportGUI.php'; 94 $exp = new ilExportGUI($this); 95 $exp->addFormat('xml'); 96 $this->ctrl->forwardCommand($exp); 97 break; 98 99 case "ilcommonactiondispatchergui": 100 $this->prepareOutput(); 101 $gui = ilCommonActionDispatcherGUI::getInstanceFromAjaxCall(); 102 $this->ctrl->forwardCommand($gui); 103 break; 104 105 case "ilpropertyformgui": 106 include_once './Services/Form/classes/class.ilPropertyFormGUI.php'; 107 $this->initFormLink(self::LINK_MOD_EDIT); 108 $this->ctrl->forwardCommand($this->form); 109 break; 110 111 case "ilinternallinkgui": 112 $this->lng->loadLanguageModule("content"); 113 require_once("./Services/Link/classes/class.ilInternalLinkGUI.php"); 114 $link_gui = new ilInternalLinkGUI("RepositoryItem", 0); 115 $link_gui->filterLinkType("PageObject"); 116 $link_gui->filterLinkType("GlossaryItem"); 117 $link_gui->filterLinkType("RepositoryItem"); 118 $link_gui->setFilterWhiteList(true); 119 $ilCtrl->forwardCommand($link_gui); 120 break; 121 122 default: 123 if (!$cmd) { 124 $this->ctrl->setCmd("view"); 125 } 126 parent::executeCommand(); 127 } 128 129 if (!$this->getCreationMode()) { 130 // Fill meta header tags 131 include_once('Services/MetaData/classes/class.ilMDUtils.php'); 132 ilMDUtils::_fillHTMLMetaTags($this->object->getId(), $this->object->getId(), 'webr'); 133 134 $this->addHeaderAction(); 135 } 136 return true; 137 } 138 139 protected function initCreateForm($a_new_type) 140 { 141 $this->initFormLink(self::LINK_MOD_CREATE); 142 return $this->form; 143 } 144 145 /** 146 * Save new object 147 * @access public 148 */ 149 public function save() 150 { 151 global $DIC; 152 153 $ilCtrl = $DIC['ilCtrl']; 154 155 $this->initFormLink(self::LINK_MOD_CREATE); 156 if ($this->checkLinkInput(self::LINK_MOD_CREATE, 0, 0)) { 157 // Save new object 158 $_POST['title'] = $_POST['tit']; 159 $_POST['desc'] = $_POST['des']; 160 parent::save(); 161 } else { 162 // Data incomplete or invalid 163 ilUtil::sendFailure($this->lng->txt('err_check_input')); 164 $this->form->setValuesByPost(); 165 $this->tpl->setContent($this->form->getHTML()); 166 } 167 } 168 169 protected function afterSave(ilObject $a_new_object) 170 { 171 // Save link 172 $this->link->setLinkResourceId($a_new_object->getId()); 173 $link_id = $this->link->add(); 174 $this->link->updateValid(true); 175 176 ilUtil::sendSuccess($this->lng->txt('webr_link_added')); 177 178 // personal workspace 179 if ($this->id_type == self::WORKSPACE_NODE_ID) { 180 $this->ctrl->redirect($this, "editLinks"); 181 } 182 // repository 183 else { 184 ilUtil::redirect("ilias.php?baseClass=ilLinkResourceHandlerGUI&ref_id=" . 185 $a_new_object->getRefId() . "&cmd=switchViewMode&switch_mode=2"); 186 } 187 } 188 189 /** 190 * Edit settings 191 * Title, Description, Sorting 192 * @return 193 */ 194 protected function settings() 195 { 196 global $DIC; 197 198 $ilTabs = $DIC['ilTabs']; 199 200 $this->checkPermission('write'); 201 $ilTabs->activateTab('id_settings'); 202 203 $this->initFormSettings(); 204 $this->tpl->setContent($this->form->getHTML()); 205 } 206 207 /** 208 * Save container settings 209 * @return 210 */ 211 protected function saveSettings() 212 { 213 global $DIC; 214 215 $obj_service = $this->object_service; 216 $ilTabs = $DIC['ilTabs']; 217 218 $this->checkPermission('write'); 219 $ilTabs->activateTab('id_settings'); 220 221 $this->initFormSettings(); 222 if ($this->form->checkInput()) { 223 $this->object->setTitle($this->form->getInput('tit')); 224 $this->object->setDescription($this->form->getInput('des')); 225 $this->object->update(); 226 227 include_once './Services/Container/classes/class.ilContainerSortingSettings.php'; 228 $sort = new ilContainerSortingSettings($this->object->getId()); 229 $sort->setSortMode($this->form->getInput('sor')); 230 $sort->update(); 231 232 // tile image 233 $obj_service->commonSettings()->legacyForm($this->form, $this->object)->saveTileImage(); 234 235 236 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true); 237 $this->ctrl->redirect($this, 'settings'); 238 } 239 240 $this->form->setValuesByPost(); 241 ilUtil::sendFailure($this->lng->txt('err_check_input')); 242 $this->tpl->setContent($this->form->getHTML()); 243 } 244 245 246 /** 247 * Show settings form 248 * @return 249 */ 250 protected function initFormSettings() 251 { 252 $obj_service = $this->object_service; 253 254 include_once './Services/Form/classes/class.ilPropertyFormGUI.php'; 255 $this->form = new ilPropertyFormGUI(); 256 $this->form->setFormAction($this->ctrl->getFormAction($this, 'saveSettings')); 257 258 if (ilLinkResourceItems::lookupNumberOfLinks($this->object->getId()) > 1) { 259 $this->form->setTitle($this->lng->txt('webr_edit_settings')); 260 261 // Title 262 $tit = new ilTextInputGUI($this->lng->txt('webr_list_title'), 'tit'); 263 $tit->setValue($this->object->getTitle()); 264 $tit->setRequired(true); 265 $tit->setSize(40); 266 $tit->setMaxLength(127); 267 $this->form->addItem($tit); 268 269 // Description 270 $des = new ilTextAreaInputGUI($this->lng->txt('webr_list_desc'), 'des'); 271 $des->setValue($this->object->getDescription()); 272 $des->setCols(40); 273 $des->setRows(3); 274 $this->form->addItem($des); 275 276 $section = new ilFormSectionHeaderGUI(); 277 $section->setTitle($this->lng->txt('obj_presentation')); 278 $this->form->addItem($section); 279 280 // tile image 281 $obj_service->commonSettings()->legacyForm($this->form, $this->object)->addTileImage(); 282 283 // Sorting 284 include_once './Services/Container/classes/class.ilContainerSortingSettings.php'; 285 include_once './Services/Container/classes/class.ilContainer.php'; 286 287 $sor = new ilRadioGroupInputGUI($this->lng->txt('webr_sorting'), 'sor'); 288 $sor->setRequired(true); 289 include_once './Services/Container/classes/class.ilContainerSortingSettings.php'; 290 $sor->setValue(ilContainerSortingSettings::_lookupSortMode($this->object->getId())); 291 292 $opt = new ilRadioOption( 293 $this->lng->txt('webr_sort_title'), 294 ilContainer::SORT_TITLE 295 ); 296 $sor->addOption($opt); 297 298 $opm = new ilRadioOption( 299 $this->lng->txt('webr_sort_manual'), 300 ilContainer::SORT_MANUAL 301 ); 302 $sor->addOption($opm); 303 $this->form->addItem($sor); 304 } else { 305 $this->form->setTitle($this->lng->txt('obj_presentation')); 306 307 // hidden title 308 $tit = new ilHiddenInputGUI('tit'); 309 $tit->setValue($this->object->getTitle()); 310 $this->form->addItem($tit); 311 312 // hidden description 313 $des = new ilHiddenInputGUI('des'); 314 $des->setValue($this->object->getDescription()); 315 $this->form->addItem($des); 316 317 // tile image 318 $obj_service->commonSettings()->legacyForm($this->form, $this->object)->addTileImage(); 319 } 320 321 $this->form->addCommandButton('saveSettings', $this->lng->txt('save')); 322 $this->form->addCommandButton('view', $this->lng->txt('cancel')); 323 } 324 325 326 /** 327 * Edit a single link 328 * @return 329 */ 330 public function editLink() 331 { 332 global $DIC; 333 334 $ilCtrl = $DIC['ilCtrl']; 335 336 $this->checkPermission('write'); 337 $this->activateTabs('content', 'id_content_view'); 338 339 if (!(int) $_GET['link_id']) { 340 ilUtil::sendFailure($this->lng->txt('select_one'), true); 341 $ilCtrl->redirect($this, 'view'); 342 } 343 344 $this->initFormLink(self::LINK_MOD_EDIT); 345 $this->setValuesFromLink((int) $_GET['link_id']); 346 $this->tpl->setContent($this->form->getHTML()); 347 } 348 349 /** 350 * Save after editing 351 * @return 352 */ 353 public function updateLink() 354 { 355 global $DIC; 356 357 $ilCtrl = $DIC['ilCtrl']; 358 359 $this->initFormLink(self::LINK_MOD_EDIT); 360 if ($this->checkLinkInput(self::LINK_MOD_EDIT, $this->object->getId(), (int) $_REQUEST['link_id'])) { 361 $this->link->setLinkId((int) $_REQUEST['link_id']); 362 $this->link->update(); 363 if (ilParameterAppender::_isEnabled() and is_object($this->dynamic)) { 364 $this->dynamic->add((int) $_REQUEST['link_id']); 365 } 366 367 if ($this->isContainerMetaDataRequired()) { 368 $this->object->setTitle($this->form->getInput('tit')); 369 $this->object->setDescription($this->form->getInput('des')); 370 $this->object->update(); 371 } 372 373 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true); 374 $ilCtrl->redirect($this, 'view'); 375 } 376 ilUtil::sendFailure($this->lng->txt('err_check_input')); 377 $this->form->setValuesByPost(); 378 $this->tpl->setContent($this->form->getHTML()); 379 } 380 381 /** 382 * Add an additional link 383 * @return 384 */ 385 public function addLink() 386 { 387 $this->checkPermission('write'); 388 $this->activateTabs('content', 'id_content_view'); 389 390 $this->initFormLink(self::LINK_MOD_ADD); 391 $this->tpl->setContent($this->form->getHTML()); 392 } 393 394 /** 395 * Save form data 396 * @return 397 */ 398 public function saveAddLink() 399 { 400 global $DIC; 401 402 $ilCtrl = $DIC['ilCtrl']; 403 404 $this->checkPermission('write'); 405 406 $this->initFormLink(self::LINK_MOD_ADD); 407 if ($this->checkLinkInput(self::LINK_MOD_ADD, $this->object->getId(), 0)) { 408 if ($this->isContainerMetaDataRequired()) { 409 // Save list data 410 $this->object->setTitle($this->form->getInput('lti')); 411 $this->object->setDescription($this->form->getInput('tde')); 412 $this->object->update(); 413 } 414 415 // Save Link 416 $link_id = $this->link->add(); 417 $this->link->updateValid(true); 418 419 // Dynamic parameters 420 if (ilParameterAppender::_isEnabled() and is_object($this->dynamic)) { 421 $this->dynamic->add($link_id); 422 } 423 ilUtil::sendSuccess($this->lng->txt('webr_link_added'), true); 424 $ilCtrl->redirect($this, 'view'); 425 } 426 // Error handling 427 ilUtil::sendFailure($this->lng->txt('err_check_input')); 428 $this->form->setValuesByPost(); 429 430 $this->activateTabs('content', 'id_content_view'); 431 $this->tpl->setContent($this->form->getHTML()); 432 } 433 434 /** 435 * Delete a dynamic parameter 436 * @return 437 */ 438 protected function deleteParameter() 439 { 440 global $DIC; 441 442 $ilCtrl = $DIC['ilCtrl']; 443 444 $this->checkPermission('write'); 445 446 $this->ctrl->setParameter($this, 'link_id', (int) $_GET['link_id']); 447 448 if (!isset($_GET['param_id'])) { 449 ilUtil::sendFailure($this->lng->txt('select_one'), true); 450 $ilCtrl->redirect($this, 'view'); 451 } 452 453 include_once './Modules/WebResource/classes/class.ilParameterAppender.php'; 454 $param = new ilParameterAppender($this->object->getId()); 455 $param->delete((int) $_GET['param_id']); 456 457 ilUtil::sendSuccess($this->lng->txt('links_parameter_deleted'), true); 458 $ilCtrl->redirect($this, 'editLinks'); 459 } 460 461 protected function deleteParameterForm() 462 { 463 global $DIC; 464 465 $ilCtrl = $DIC['ilCtrl']; 466 467 $this->checkPermission('write'); 468 469 if (!isset($_GET['param_id'])) { 470 ilUtil::sendFailure($this->lng->txt('select_one'), true); 471 $ilCtrl->redirect($this, 'view'); 472 } 473 474 include_once './Modules/WebResource/classes/class.ilParameterAppender.php'; 475 $param = new ilParameterAppender($this->object->getId()); 476 $param->delete((int) $_GET['param_id']); 477 478 ilUtil::sendSuccess($this->lng->txt('links_parameter_deleted'), true); 479 $ilCtrl->redirect($this, 'view'); 480 } 481 482 483 /** 484 * Update all visible links 485 * @return 486 */ 487 protected function updateLinks() 488 { 489 global $DIC; 490 491 $ilCtrl = $DIC['ilCtrl']; 492 493 $this->checkPermission('write'); 494 $this->activateTabs('content', ''); 495 496 if (!is_array($_POST['ids'])) { 497 ilUtil::sendFailure($this->lng->txt('select_one'), true); 498 $ilCtrl->redirect($this, 'view'); 499 } 500 501 // Validate 502 $invalid = array(); 503 foreach ($_POST['ids'] as $link_id) { 504 $data = $_POST['links'][$link_id]; 505 506 // handle internal links 507 if ($_POST['tar_' . $link_id . '_ajax_type'] && 508 $_POST['tar_' . $link_id . '_ajax_id']) { 509 $data['tar'] = $_POST['links'][$link_id]['tar'] = 510 $_POST['tar_' . $link_id . '_ajax_type'] . '|' . 511 $_POST['tar_' . $link_id . '_ajax_id']; 512 } 513 514 515 if (!strlen($data['tit'])) { 516 $invalid[] = $link_id; 517 continue; 518 } 519 if (!strlen($data['tar'])) { 520 $invalid[] = $link_id; 521 continue; 522 } 523 if ($data['nam'] and !$data['val']) { 524 $invalid[] = $link_id; 525 continue; 526 } 527 if (!$data['nam'] and $data['val']) { 528 $invalid[] = $link_id; 529 continue; 530 } 531 } 532 533 if (count($invalid)) { 534 ilUtil::sendFailure($this->lng->txt('err_check_input')); 535 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.webr_manage.html', 'Modules/WebResource'); 536 537 include_once './Modules/WebResource/classes/class.ilWebResourceEditableLinkTableGUI.php'; 538 $table = new ilWebResourceEditableLinkTableGUI($this, 'view'); 539 $table->setInvalidLinks($invalid); 540 $table->parseSelectedLinks($_POST['ids']); 541 $table->updateFromPost(); 542 $this->tpl->setVariable('TABLE_LINKS', $table->getHTML()); 543 return false; 544 } 545 546 include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php'; 547 $links = new ilLinkResourceItems($this->object->getId()); 548 549 // Save Settings 550 include_once './Services/Form/classes/class.ilFormPropertyGUI.php'; 551 include_once './Services/Form/classes/class.ilLinkInputGUI.php'; 552 foreach ($_POST['ids'] as $link_id) { 553 $data = $_POST['links'][$link_id]; 554 555 $orig = ilLinkResourceItems::lookupItem($this->object->getId(), $link_id); 556 557 $links->setLinkId($link_id); 558 $links->setTitle(ilUtil::stripSlashes($data['tit'])); 559 $links->setDescription(ilUtil::stripSlashes($data['des'])); 560 $links->setTarget(str_replace('"', '', ilUtil::stripSlashes($data['tar']))); 561 $links->setActiveStatus((int) $data['act']); 562 $links->setDisableCheckStatus((int) $data['che']); 563 $links->setLastCheckDate($orig['last_check']); 564 $links->setValidStatus((int) $data['vali']); 565 $links->setInternal(ilLinkInputGUI::isInternalLink($data['tar'])); 566 $links->update(); 567 568 if (strlen($data['nam']) and $data['val']) { 569 $param = new ilParameterAppender($this->object->getId()); 570 $param->setName(ilUtil::stripSlashes($data['nam'])); 571 $param->setValue((int) $data['val']); 572 $param->add($link_id); 573 } 574 575 if ($this->isContainerMetaDataRequired()) { 576 $this->object->setTitle(ilUtil::stripSlashes($data['tit'])); 577 $this->object->setDescription(ilUtil::stripSlashes($data['des'])); 578 $this->object->update(); 579 } 580 581 // TODO: Dynamic parameters 582 } 583 584 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true); 585 $ilCtrl->redirect($this, 'view'); 586 } 587 588 /** 589 * Set form values from link 590 * @param object $a_link_id 591 * @return 592 */ 593 protected function setValuesFromLink($a_link_id) 594 { 595 include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php'; 596 $link = new ilLinkResourceItems($this->object->getId()); 597 598 $values = $link->getItem($a_link_id); 599 600 if (ilParameterAppender::_isEnabled()) { 601 } 602 603 $this->form->setValuesByArray( 604 array( 605 'tit' => $values['title'], 606 'tar' => $values['target'], 607 'des' => $values['description'], 608 'act' => (int) $values['active'], 609 'che' => (int) $values['disable_check'], 610 'vali' => (int) $values['valid'] 611 ) 612 ); 613 } 614 615 616 /** 617 * Check input after creating a new link 618 * @param object $a_mode 619 * @param object $a_webr_id [optional] 620 * @param object $a_link_id [optional] 621 * @return 622 */ 623 protected function checkLinkInput($a_mode, $a_webr_id = 0, $a_link_id = 0) 624 { 625 $valid = $this->form->checkInput(); 626 627 $link_input = $this->form->getInput('tar'); 628 629 include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php'; 630 $this->link = new ilLinkResourceItems($a_webr_id); 631 $this->link->setTarget(str_replace('"', '', ilUtil::stripSlashes($link_input))); 632 $this->link->setTitle($this->form->getInput('tit')); 633 $this->link->setDescription($this->form->getInput('des')); 634 $this->link->setDisableCheckStatus($this->form->getInput('che')); 635 $this->link->setInternal(ilLinkInputGUI::isInternalLink($link_input)); 636 637 if ($a_mode == self::LINK_MOD_CREATE) { 638 $this->link->setActiveStatus(true); 639 } else { 640 $this->link->setActiveStatus($this->form->getInput('act')); 641 } 642 643 if ($a_mode == self::LINK_MOD_EDIT) { 644 $this->link->setValidStatus($this->form->getInput('vali')); 645 } else { 646 $this->link->setValidStatus(true); 647 } 648 649 if (!ilParameterAppender::_isEnabled()) { 650 return $valid; 651 } 652 653 $this->dynamic = new ilParameterAppender($a_webr_id); 654 $this->dynamic->setName($this->form->getInput('nam')); 655 $this->dynamic->setValue($this->form->getInput('val')); 656 if (!$this->dynamic->validate()) { 657 switch ($this->dynamic->getErrorCode()) { 658 case LINKS_ERR_NO_NAME: 659 $this->form->getItemByPostVar('nam')->setAlert($this->lng->txt('links_no_name_given')); 660 return false; 661 662 case LINKS_ERR_NO_VALUE: 663 $this->form->getItemByPostVar('val')->setAlert($this->lng->txt('links_no_value_given')); 664 return false; 665 666 case LINKS_ERR_NO_NAME_VALUE: 667 // Nothing entered => no error 668 return $valid; 669 } 670 $this->dynamic = null; 671 } 672 return $valid; 673 } 674 675 676 /** 677 * Show create/edit single link 678 * @param int form mode 679 * @return 680 */ 681 protected function initFormLink($a_mode) 682 { 683 global $DIC; 684 685 $ilTabs = $DIC['ilTabs']; 686 687 $ilTabs->activateTab("id_content"); 688 689 include_once './Services/Form/classes/class.ilPropertyFormGUI.php'; 690 $this->form = new ilPropertyFormGUI(); 691 692 switch ($a_mode) { 693 case self::LINK_MOD_CREATE: 694 // Header 695 $this->ctrl->setParameter($this, 'new_type', 'webr'); 696 $this->form->setTitle($this->lng->txt('webr_new_link')); 697 $this->form->setTableWidth('600px'); 698 699 // Buttons 700 $this->form->addCommandButton('save', $this->lng->txt('webr_add')); 701 $this->form->addCommandButton('cancel', $this->lng->txt('cancel')); 702 break; 703 704 case self::LINK_MOD_ADD: 705 // Header 706 $this->form->setTitle($this->lng->txt('webr_new_link')); 707 708 // Buttons 709 $this->form->addCommandButton('saveAddLink', $this->lng->txt('webr_add')); 710 $this->form->addCommandButton('view', $this->lng->txt('cancel')); 711 break; 712 713 case self::LINK_MOD_EDIT: 714 // Header 715 $this->ctrl->setParameter($this, 'link_id', (int) $_REQUEST['link_id']); 716 $this->form->setTitle($this->lng->txt('webr_edit')); 717 718 // Buttons 719 $this->form->addCommandButton('updateLink', $this->lng->txt('save')); 720 $this->form->addCommandButton('view', $this->lng->txt('cancel')); 721 break; 722 } 723 724 725 $this->form->setFormAction($this->ctrl->getFormAction($this)); 726 727 if ($a_mode == self::LINK_MOD_ADD and $this->isContainerMetaDataRequired()) { 728 ilUtil::sendInfo($this->lng->txt('webr_container_info')); 729 730 731 $this->form->setTitle($this->lng->txt('webr_edit_list')); 732 733 // List Title 734 $title = new ilTextInputGUI($this->lng->txt('webr_list_title'), 'lti'); 735 $title->setRequired(true); 736 $title->setSize(40); 737 $title->setMaxLength(127); 738 $this->form->addItem($title); 739 740 // List Description 741 $desc = new ilTextAreaInputGUI($this->lng->txt('webr_list_desc'), 'tde'); 742 $desc->setRows(3); 743 $desc->setCols(40); 744 $this->form->addItem($desc); 745 746 // Addtional section 747 $sect = new ilFormSectionHeaderGUI(); 748 $sect->setTitle($this->lng->txt('webr_add')); 749 $this->form->addItem($sect); 750 } 751 752 // Target 753 /* 754 $tar = new ilTextInputGUI($this->lng->txt('webr_link_target'),'tar'); 755 $tar->setValue("http://"); 756 757 $tar->setSize(40); 758 $tar->setMaxLength(500); 759 */ 760 include_once 'Services/Form/classes/class.ilLinkInputGUI.php'; 761 $tar = new ilLinkInputGUI($this->lng->txt('webr_link_target'), 'tar'); 762 $tar->setInternalLinkFilterTypes( 763 array( 764 "PageObject", 765 "GlossaryItem", 766 "RepositoryItem", 767 'WikiPage' 768 ) 769 ); 770 $tar->setExternalLinkMaxLength(1000); 771 $tar->setInternalLinkFilterTypes(array("PageObject", "GlossaryItem", "RepositoryItem")); 772 $tar->setRequired(true); 773 $this->form->addItem($tar); 774 775 // Title 776 $tit = new ilTextInputGUI($this->lng->txt('webr_link_title'), 'tit'); 777 $tit->setRequired(true); 778 $tit->setSize(40); 779 $tit->setMaxLength(127); 780 $this->form->addItem($tit); 781 782 // Description 783 $des = new ilTextAreaInputGUI($this->lng->txt('description'), 'des'); 784 $des->setRows(3); 785 $des->setCols(40); 786 $this->form->addItem($des); 787 788 789 if ($a_mode != self::LINK_MOD_CREATE) { 790 // Active 791 $act = new ilCheckboxInputGUI($this->lng->txt('active'), 'act'); 792 $act->setChecked(true); 793 $act->setValue(1); 794 $this->form->addItem($act); 795 796 // Check 797 $che = new ilCheckboxInputGUI($this->lng->txt('webr_disable_check'), 'che'); 798 $che->setValue(1); 799 $this->form->addItem($che); 800 } 801 802 // Valid 803 if ($a_mode == self::LINK_MOD_EDIT) { 804 $val = new ilCheckboxInputGUI($this->lng->txt('valid'), 'vali'); 805 $this->form->addItem($val); 806 } 807 808 if (ilParameterAppender::_isEnabled() && $a_mode != self::LINK_MOD_CREATE) { 809 $dyn = new ilNonEditableValueGUI($this->lng->txt('links_dyn_parameter')); 810 $dyn->setInfo($this->lng->txt('links_dynamic_info')); 811 812 813 if (count($links = ilParameterAppender::_getParams((int) $_GET['link_id']))) { 814 $ex = new ilCustomInputGUI($this->lng->txt('links_existing_params'), 'ex'); 815 $dyn->addSubItem($ex); 816 817 foreach ($links as $id => $link) { 818 $p = new ilCustomInputGUI(); 819 820 $ptpl = new ilTemplate('tpl.link_dyn_param_edit.html', true, true, 'Modules/WebResource'); 821 $ptpl->setVariable('INFO_TXT', ilParameterAppender::parameterToInfo($link['name'], $link['value'])); 822 $this->ctrl->setParameter($this, 'param_id', $id); 823 $ptpl->setVariable('LINK_DEL', $this->ctrl->getLinkTarget($this, 'deleteParameterForm')); 824 $ptpl->setVariable('LINK_TXT', $this->lng->txt('delete')); 825 $p->setHtml($ptpl->get()); 826 $dyn->addSubItem($p); 827 } 828 } 829 830 // Existing parameters 831 832 // New parameter 833 if ($a_mode != self::LINK_MOD_CREATE) { 834 #$new = new ilCustomInputGUI($this->lng->txt('links_add_param'),''); 835 #$dyn->addSubItem($new); 836 } 837 838 // Dynyamic name 839 $nam = new ilTextInputGUI($this->lng->txt('links_name'), 'nam'); 840 $nam->setSize(12); 841 $nam->setMaxLength(128); 842 $dyn->addSubItem($nam); 843 844 // Dynamic value 845 $val = new ilSelectInputGUI($this->lng->txt('links_value'), 'val'); 846 $val->setOptions(ilParameterAppender::_getOptionSelect()); 847 $val->setValue(0); 848 $dyn->addSubItem($val); 849 850 $this->form->addItem($dyn); 851 } 852 } 853 854 /** 855 * Check if a new container title is required 856 * Necessary if there is more than one link 857 * @return 858 */ 859 protected function isContainerMetaDataRequired() 860 { 861 include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php'; 862 return ilLinkResourceItems::lookupNumberOfLinks($this->object->getId()) == 1; 863 } 864 865 /** 866 * Switch between "View" "Manage" and "Sort" 867 * @return 868 */ 869 protected function switchViewMode() 870 { 871 global $DIC; 872 873 $ilCtrl = $DIC['ilCtrl']; 874 875 $_REQUEST['view_mode'] = $_GET['view_mode'] = (int) $_GET['switch_mode']; 876 $this->view(); 877 } 878 879 /** 880 * Start with manage mode 881 * @return 882 */ 883 protected function editLinks() 884 { 885 $_GET['switch_mode'] = self::VIEW_MODE_MANAGE; 886 $this->switchViewMode(); 887 } 888 889 890 /** 891 * View object 892 * @return 893 */ 894 public function view() 895 { 896 global $DIC; 897 898 $ilErr = $DIC['ilErr']; 899 $ilTabs = $DIC['ilTabs']; 900 901 $ilTabs->activateTab("id_content"); 902 903 $this->checkPermission('read'); 904 905 if (strtolower($_GET["baseClass"]) == "iladministrationgui") { 906 parent::view(); 907 return true; 908 } else { 909 switch ((int) $_REQUEST['view_mode']) { 910 case self::VIEW_MODE_MANAGE: 911 $this->manage(); 912 break; 913 914 case self::VIEW_MODE_SORT: 915 // #14638 916 include_once './Services/Container/classes/class.ilContainerSortingSettings.php'; 917 if (ilContainerSortingSettings::_lookupSortMode($this->object->getId()) == ilContainer::SORT_MANUAL) { 918 $this->sort(); 919 break; 920 } 921 // fallthrough 922 923 // no break 924 default: 925 $this->showLinks(); 926 break; 927 } 928 } 929 $GLOBALS['DIC']['tpl']->setPermanentLink($this->object->getType(), $this->object->getRefId()); 930 return true; 931 } 932 933 /** 934 * Manage links 935 * @return 936 */ 937 protected function manage() 938 { 939 $this->checkPermission('write'); 940 $this->activateTabs('content', 'id_content_manage'); 941 942 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.webr_manage.html', 'Modules/WebResource'); 943 $this->showToolbar('ACTION_BUTTONS'); 944 945 include_once './Modules/WebResource/classes/class.ilWebResourceEditableLinkTableGUI.php'; 946 $table = new ilWebResourceEditableLinkTableGUI($this, 'view'); 947 $table->parse(); 948 949 include_once './Services/Link/classes/class.ilInternalLinkGUI.php'; 950 $js = ilInternalLinkGUI::getInitHTML(""); 951 952 $this->tpl->addJavaScript("Modules/WebResource/js/intLink.js"); 953 $this->tpl->addJavascript("Services/Form/js/Form.js"); 954 955 $this->tpl->setVariable('TABLE_LINKS', $table->getHTML() . $js); 956 } 957 958 /** 959 * Show all active links 960 * @return 961 */ 962 protected function showLinks() 963 { 964 $this->checkPermission('read'); 965 $this->activateTabs('content', 'id_content_view'); 966 967 include_once './Modules/WebResource/classes/class.ilWebResourceLinkTableGUI.php'; 968 $table = new ilWebResourceLinkTableGUI($this, 'showLinks'); 969 $table->parse(); 970 971 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.webr_view.html', 'Modules/WebResource'); 972 $this->showToolbar('ACTION_BUTTONS'); 973 $this->tpl->setVariable('LINK_TABLE', $table->getHTML()); 974 } 975 976 /** 977 * Sort web links 978 * @return 979 */ 980 protected function sort() 981 { 982 $this->checkPermission('write'); 983 $this->activateTabs('content', 'id_content_ordering'); 984 985 include_once './Modules/WebResource/classes/class.ilWebResourceLinkTableGUI.php'; 986 $table = new ilWebResourceLinkTableGUI($this, 'sort', true); 987 $table->parse(); 988 989 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.webr_view.html', 'Modules/WebResource'); 990 $this->showToolbar('ACTION_BUTTONS'); 991 $this->tpl->setVariable('LINK_TABLE', $table->getHTML()); 992 } 993 994 /** 995 * Save nmanual sorting 996 * @return 997 */ 998 protected function saveSorting() 999 { 1000 $this->checkPermission('write'); 1001 1002 include_once './Services/Container/classes/class.ilContainerSorting.php'; 1003 $sort = ilContainerSorting::_getInstance($this->object->getId()); 1004 $sort->savePost((array) $_POST['position']); 1005 1006 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true); 1007 $this->view(); 1008 } 1009 1010 1011 /** 1012 * Show toolbar 1013 * @param string $a_tpl_var Name of template variable 1014 * @return 1015 */ 1016 protected function showToolbar($a_tpl_var) 1017 { 1018 if (!$this->checkPermissionBool('write')) { 1019 return; 1020 } 1021 1022 include_once './Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php'; 1023 $tool = new ilToolbarGUI(); 1024 $tool->setFormAction($this->ctrl->getFormAction($this)); 1025 $tool->addButton( 1026 $this->lng->txt('webr_add'), 1027 $this->ctrl->getLinkTarget($this, 'addLink') 1028 ); 1029 1030 $this->tpl->setVariable($a_tpl_var, $tool->getHTML()); 1031 return; 1032 } 1033 1034 /** 1035 * Show delete confirmation screen 1036 * @return 1037 */ 1038 protected function confirmDeleteLink() 1039 { 1040 $this->checkPermission('write'); 1041 $this->activateTabs('content', 'id_content_view'); 1042 1043 $link_ids = array(); 1044 1045 if (is_array($_POST['link_ids'])) { 1046 $link_ids = $_POST['link_ids']; 1047 } elseif (isset($_GET['link_id'])) { 1048 $link_ids = array($_GET['link_id']); 1049 } 1050 1051 if (!count($link_ids) > 0) { 1052 ilUtil::sendFailure($this->lng->txt('select_one')); 1053 $this->view(); 1054 return false; 1055 } 1056 1057 include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php'; 1058 $links = new ilLinkResourceItems($this->object->getId()); 1059 1060 include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php'; 1061 $confirm = new ilConfirmationGUI(); 1062 $confirm->setFormAction($this->ctrl->getFormAction($this, 'view')); 1063 $confirm->setHeaderText($this->lng->txt('webr_sure_delete_items')); 1064 $confirm->setConfirm($this->lng->txt('delete'), 'deleteLinks'); 1065 $confirm->setCancel($this->lng->txt('cancel'), 'view'); 1066 1067 foreach ($link_ids as $link_id) { 1068 $link = $links->getItem($link_id); 1069 $confirm->addItem('link_ids[]', $link_id, $link['title']); 1070 } 1071 $this->tpl->setContent($confirm->getHTML()); 1072 } 1073 1074 /** 1075 * Delete links 1076 * @return 1077 */ 1078 protected function deleteLinks() 1079 { 1080 global $DIC; 1081 1082 $ilCtrl = $DIC['ilCtrl']; 1083 1084 $this->checkPermission('write'); 1085 1086 include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php'; 1087 $links = new ilLinkResourceItems($this->object->getId()); 1088 1089 foreach ($_POST['link_ids'] as $link_id) { 1090 $links->delete($link_id); 1091 } 1092 ilUtil::sendSuccess($this->lng->txt('webr_deleted_items'), true); 1093 $ilCtrl->redirect($this, 'view'); 1094 } 1095 1096 /** 1097 * Deactivate links 1098 * @return 1099 */ 1100 protected function deactivateLink() 1101 { 1102 global $DIC; 1103 1104 $ilCtrl = $DIC['ilCtrl']; 1105 1106 $this->checkPermission('write'); 1107 1108 include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php'; 1109 $links = new ilLinkResourceItems($this->object->getId()); 1110 1111 if (!$_GET['link_id']) { 1112 ilUtil::sendFailure($this->lng->txt('select_one'), true); 1113 $ilCtrl->redirect($this, 'view'); 1114 } 1115 1116 $links->setLinkId((int) $_GET['link_id']); 1117 $links->updateActive(false); 1118 1119 ilUtil::sendSuccess($this->lng->txt('webr_inactive_success'), true); 1120 $ilCtrl->redirect($this, 'view'); 1121 } 1122 1123 1124 /** 1125 * this one is called from the info button in the repository 1126 * not very nice to set cmdClass/Cmd manually, if everything 1127 * works through ilCtrl in the future this may be changed 1128 */ 1129 public function infoScreen() 1130 { 1131 $this->ctrl->setCmd("showSummary"); 1132 $this->ctrl->setCmdClass("ilinfoscreengui"); 1133 $this->infoScreenForward(); 1134 } 1135 1136 /** 1137 * show information screen 1138 */ 1139 public function infoScreenForward() 1140 { 1141 global $DIC; 1142 1143 $ilTabs = $DIC['ilTabs']; 1144 1145 if (!$this->checkPermissionBool('visible')) { 1146 $this->checkPermission('read'); 1147 } 1148 $ilTabs->activateTab('id_info'); 1149 1150 include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php"); 1151 $info = new ilInfoScreenGUI($this); 1152 1153 $info->enablePrivateNotes(); 1154 1155 // standard meta data 1156 $info->addMetaDataSections($this->object->getId(), 0, $this->object->getType()); 1157 1158 if ($this->id_type == self::WORKSPACE_NODE_ID) { 1159 $info->addProperty($this->lng->txt("perma_link"), $this->getPermanentLinkWidget()); 1160 } 1161 1162 // forward the command 1163 $this->ctrl->forwardCommand($info); 1164 } 1165 1166 1167 public function history() 1168 { 1169 global $DIC; 1170 1171 $ilTabs = $DIC['ilTabs']; 1172 1173 $this->checkPermission('write'); 1174 $ilTabs->activateTab('id_history'); 1175 1176 include_once("./Services/History/classes/class.ilHistoryTableGUI.php"); 1177 $hist_gui = new ilHistoryTableGUI($this, "history", $this->object->getId(), $this->object->getType); 1178 $hist_gui->initTable(); 1179 $this->tpl->setContent($hist_gui->getHTML()); 1180 } 1181 1182 /** 1183 * 1184 * @see ilLinkCheckerGUIRowHandling::formatInvalidLinkArray() 1185 * @param array Unformatted array 1186 * @return array Formatted array 1187 * @access public 1188 * 1189 */ 1190 public function formatInvalidLinkArray(array $row) 1191 { 1192 $this->object->items_obj->readItem($row['page_id']); 1193 $row['title'] = $this->object->items_obj->getTitle(); 1194 1195 require_once 'Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php'; 1196 $actions = new ilAdvancedSelectionListGUI(); 1197 $actions->setSelectionHeaderClass('small'); 1198 $actions->setItemLinkClass('xsmall'); 1199 $actions->setListTitle($this->lng->txt('actions')); 1200 $actions->setId($row['page_id']); 1201 $this->ctrl->setParameter($this, 'link_id', $row['page_id']); 1202 $actions->addItem( 1203 $this->lng->txt('edit'), 1204 '', 1205 $this->ctrl->getLinkTarget($this, 'editLink') 1206 ); 1207 $this->ctrl->clearParameters($this); 1208 $row['action_html'] = $actions->getHTML(); 1209 1210 return $row; 1211 } 1212 1213 /** 1214 * Show link validation 1215 * @return 1216 */ 1217 protected function linkChecker() 1218 { 1219 global $DIC; 1220 1221 $ilias = $DIC['ilias']; 1222 $ilUser = $DIC['ilUser']; 1223 $tpl = $DIC['tpl']; 1224 $ilTabs = $DIC['ilTabs']; 1225 1226 $this->checkPermission('write'); 1227 $ilTabs->activateTab('id_link_check'); 1228 1229 $this->__initLinkChecker(); 1230 $this->object->initLinkResourceItemsObject(); 1231 1232 require_once './Services/LinkChecker/classes/class.ilLinkCheckerTableGUI.php'; 1233 1234 $toolbar = new ilToolbarGUI(); 1235 1236 if ((bool) $ilias->getSetting('cron_web_resource_check')) { 1237 include_once './Services/LinkChecker/classes/class.ilLinkCheckNotify.php'; 1238 include_once 'Services/Form/classes/class.ilPropertyFormGUI.php'; 1239 1240 $chb = new ilCheckboxInputGUI($this->lng->txt('link_check_message_a'), 'link_check_message'); 1241 $chb->setValue(1); 1242 $chb->setChecked((bool) ilLinkCheckNotify::_getNotifyStatus($ilUser->getId(), $this->object->getId())); 1243 $chb->setOptionTitle($this->lng->txt('link_check_message_b')); 1244 1245 $toolbar->addInputItem($chb); 1246 $toolbar->addFormButton($this->lng->txt('save'), 'saveLinkCheck'); 1247 $toolbar->setFormAction($this->ctrl->getLinkTarget($this, 'saveLinkCheck')); 1248 } 1249 1250 $tgui = new ilLinkCheckerTableGUI($this, 'linkChecker'); 1251 $tgui->setLinkChecker($this->link_checker_obj) 1252 ->setRowHandler($this) 1253 ->setRefreshButton($this->lng->txt('refresh'), 'refreshLinkCheck'); 1254 1255 return $tpl->setContent($tgui->prepareHTML()->getHTML() . $toolbar->getHTML()); 1256 } 1257 1258 public function saveLinkCheck() 1259 { 1260 global $DIC; 1261 1262 $ilDB = $DIC['ilDB']; 1263 $ilUser = $DIC['ilUser']; 1264 1265 include_once './Services/LinkChecker/classes/class.ilLinkCheckNotify.php'; 1266 1267 $link_check_notify = new ilLinkCheckNotify($ilDB); 1268 $link_check_notify->setUserId($ilUser->getId()); 1269 $link_check_notify->setObjId($this->object->getId()); 1270 1271 if ($_POST['link_check_message']) { 1272 ilUtil::sendSuccess($this->lng->txt('link_check_message_enabled')); 1273 $link_check_notify->addNotifier(); 1274 } else { 1275 ilUtil::sendSuccess($this->lng->txt('link_check_message_disabled')); 1276 $link_check_notify->deleteNotifier(); 1277 } 1278 $this->linkChecker(); 1279 1280 return true; 1281 } 1282 1283 1284 1285 public function refreshLinkCheck() 1286 { 1287 $this->__initLinkChecker(); 1288 $this->object->initLinkResourceItemsObject(); 1289 1290 // Set all link to valid. After check invalid links will be set to invalid 1291 $this->object->items_obj->updateValidByCheck(); 1292 1293 foreach ($this->link_checker_obj->checkWebResourceLinks() as $invalid) { 1294 $this->object->items_obj->readItem($invalid['page_id']); 1295 $this->object->items_obj->setActiveStatus(false); 1296 $this->object->items_obj->setValidStatus(false); 1297 $this->object->items_obj->update(false); 1298 } 1299 1300 $this->object->items_obj->updateLastCheck(); 1301 ilUtil::sendSuccess($this->lng->txt('link_checker_refreshed')); 1302 1303 $this->linkChecker(); 1304 1305 return true; 1306 } 1307 1308 public function __initLinkChecker() 1309 { 1310 global $DIC; 1311 1312 $ilDB = $DIC['ilDB']; 1313 1314 include_once './Services/LinkChecker/classes/class.ilLinkChecker.php'; 1315 1316 $this->link_checker_obj = new ilLinkChecker($ilDB, false); 1317 $this->link_checker_obj->setObjId($this->object->getId()); 1318 1319 return true; 1320 } 1321 1322 1323 /** 1324 * Activate tab and subtabs 1325 * @param string $a_active_tab 1326 * @param string $a_active_subtab [optional] 1327 * @return 1328 */ 1329 protected function activateTabs($a_active_tab, $a_active_subtab = '') 1330 { 1331 global $DIC; 1332 1333 $ilCtrl = $DIC['ilCtrl']; 1334 $ilTabs = $DIC['ilTabs']; 1335 $lng = $DIC['lng']; 1336 1337 switch ($a_active_tab) { 1338 case 'content': 1339 if ($this->checkPermissionBool('write')) { 1340 $this->lng->loadLanguageModule('cntr'); 1341 1342 $this->ctrl->setParameter($this, 'switch_mode', self::VIEW_MODE_VIEW); 1343 $ilTabs->addSubTab( 1344 'id_content_view', 1345 $lng->txt('view'), 1346 $this->ctrl->getLinkTarget($this, 'switchViewMode') 1347 ); 1348 $this->ctrl->setParameter($this, 'switch_mode', self::VIEW_MODE_MANAGE); 1349 $ilTabs->addSubTab( 1350 'id_content_manage', 1351 $lng->txt('cntr_manage'), 1352 $this->ctrl->getLinkTarget($this, 'switchViewMode') 1353 ); 1354 include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php'; 1355 include_once './Services/Container/classes/class.ilContainerSortingSettings.php'; 1356 include_once './Services/Container/classes/class.ilContainer.php'; 1357 if ((ilLinkResourceItems::lookupNumberOfLinks($this->object->getId()) > 1) 1358 and ilContainerSortingSettings::_lookupSortMode($this->object->getId()) == ilContainer::SORT_MANUAL) { 1359 $this->ctrl->setParameter($this, 'switch_mode', self::VIEW_MODE_SORT); 1360 $ilTabs->addSubTab( 1361 'id_content_ordering', 1362 $this->lng->txt('cntr_ordering'), 1363 $this->ctrl->getLinkTarget($this, 'switchViewMode') 1364 ); 1365 } 1366 1367 $ilCtrl->clearParameters($this); 1368 $ilTabs->activateSubTab($a_active_subtab); 1369 } 1370 } 1371 1372 $ilTabs->activateTab('id_content'); 1373 } 1374 1375 1376 /** 1377 * get tabs 1378 * @access public 1379 */ 1380 public function setTabs() 1381 { 1382 global $DIC; 1383 1384 $ilTabs = $DIC['ilTabs']; 1385 $lng = $DIC['lng']; 1386 $ilHelp = $DIC['ilHelp']; 1387 1388 $ilHelp->setScreenIdComponent("webr"); 1389 1390 if ($this->checkPermissionBool('read')) { 1391 $ilTabs->addTab( 1392 "id_content", 1393 $lng->txt("content"), 1394 $this->ctrl->getLinkTarget($this, "view") 1395 ); 1396 } 1397 1398 if ( 1399 $this->checkPermissionBool('visible') || 1400 $this->checkPermissionBool('read') 1401 ) { 1402 $ilTabs->addTab( 1403 "id_info", 1404 $lng->txt("info_short"), 1405 $this->ctrl->getLinkTarget($this, "infoScreen") 1406 ); 1407 } 1408 1409 if ($this->checkPermissionBool('write') and !$this->getCreationMode()) { 1410 $ilTabs->addTab( 1411 "id_settings", 1412 $lng->txt("settings"), 1413 $this->ctrl->getLinkTarget($this, "settings") 1414 ); 1415 } 1416 1417 if ($this->checkPermissionBool('write')) { 1418 $ilTabs->addTab( 1419 "id_history", 1420 $lng->txt("history"), 1421 $this->ctrl->getLinkTarget($this, "history") 1422 ); 1423 } 1424 1425 if ($this->checkPermissionBool('write')) { 1426 // Check if pear library is available 1427 $ilTabs->addTab( 1428 "id_link_check", 1429 $lng->txt("link_check"), 1430 $this->ctrl->getLinkTarget($this, "linkChecker") 1431 ); 1432 } 1433 1434 if ($this->checkPermissionBool('write')) { 1435 include_once "Services/Object/classes/class.ilObjectMetaDataGUI.php"; 1436 $mdgui = new ilObjectMetaDataGUI($this->object); 1437 $mdtab = $mdgui->getTab(); 1438 if ($mdtab) { 1439 $ilTabs->addTab( 1440 "id_meta_data", 1441 $lng->txt("meta_data"), 1442 $mdtab 1443 ); 1444 } 1445 } 1446 1447 if ($this->checkPermissionBool('write')) { 1448 $ilTabs->addTab( 1449 'export', 1450 $this->lng->txt('export'), 1451 $this->ctrl->getLinkTargetByClass('ilexportgui', '') 1452 ); 1453 } 1454 1455 // will add permission tab if needed 1456 parent::setTabs(); 1457 } 1458 1459 // PRIVATE 1460 public function __prepareOutput() 1461 { 1462 // output objects 1463 // $this->tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html"); 1464 // $this->tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html"); 1465 1466 $this->tpl->setLocator(); 1467 1468 // output message 1469 if ($this->message) { 1470 ilUtil::sendInfo($this->message); 1471 } 1472 1473 // display infopanel if something happened 1474 ilUtil::infoPanel(); 1475 ; 1476 } 1477 1478 public function addLocatorItems() 1479 { 1480 global $DIC; 1481 1482 $ilLocator = $DIC['ilLocator']; 1483 1484 if (is_object($this->object)) { 1485 $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this), "", $this->object->getRefId(), "webr"); 1486 } 1487 } 1488 1489 protected function handleSubItemLinks($a_target) 1490 { 1491 // #15647 - handle internal links 1492 include_once "Services/Form/classes/class.ilFormPropertyGUI.php"; 1493 include_once "Services/Form/classes/class.ilLinkInputGUI.php"; 1494 1495 if (ilLinkInputGUI::isInternalLink($a_target)) { 1496 include_once("./Services/Link/classes/class.ilLink.php"); 1497 1498 // #10612 1499 $parts = explode("|", $a_target); 1500 1501 if ($parts[0] == 'wpage') { 1502 return ilLink::_getStaticLink( 1503 0, 1504 'wiki', 1505 true, 1506 '&target=wiki_wpage_' . $parts[1] 1507 ); 1508 } 1509 1510 if ($parts[0] == "term") { 1511 // #16894 1512 return ilLink::_getStaticLink( 1513 0, 1514 "git", 1515 true, 1516 "&target=git_" . $parts[1] 1517 ); 1518 } 1519 1520 if ($parts[0] == "page") { 1521 $parts[0] = "pg"; 1522 } 1523 1524 $a_target = ilLink::_getStaticLink($parts[1], $parts[0]); 1525 } 1526 1527 return $a_target; 1528 } 1529 1530 public function callDirectLink() 1531 { 1532 $obj_id = $this->object->getId(); 1533 1534 include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php'; 1535 if (ilLinkResourceItems::_isSingular($obj_id)) { 1536 $url = ilLinkResourceItems::_getFirstLink($obj_id); 1537 if ($url["target"]) { 1538 $url["target"] = $this->handleSubItemLinks($url["target"]); 1539 1540 include_once './Modules/WebResource/classes/class.ilParameterAppender.php'; 1541 if (ilParameterAppender::_isEnabled()) { 1542 $url = ilParameterAppender::_append($url); 1543 } 1544 1545 $this->redirectToLink($this->ref_id, $obj_id, $url["target"]); 1546 } 1547 } 1548 } 1549 1550 public function callLink() 1551 { 1552 if ($_REQUEST["link_id"]) { 1553 $obj_id = $this->object->getId(); 1554 1555 include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php'; 1556 $items = new ilLinkResourceItems($obj_id); 1557 $item = $items->getItem($_REQUEST["link_id"]); 1558 if ($item["target"]) { 1559 $item["target"] = $this->handleSubItemLinks($item["target"]); 1560 1561 include_once './Modules/WebResource/classes/class.ilParameterAppender.php'; 1562 if (ilParameterAppender::_isEnabled()) { 1563 $item = ilParameterAppender::_append($item); 1564 } 1565 ilLoggerFactory::getLogger('webr')->debug('Redirecting to: ' . $item['target']); 1566 $this->redirectToLink($this->ref_id, $obj_id, $item["target"]); 1567 } 1568 } 1569 } 1570 1571 protected function redirectToLink($a_ref_id, $a_obj_id, $a_url) 1572 { 1573 global $DIC; 1574 1575 $ilUser = $DIC['ilUser']; 1576 1577 if ($a_url) { 1578 require_once('Services/Tracking/classes/class.ilChangeEvent.php'); 1579 ilChangeEvent::_recordReadEvent( 1580 "webr", 1581 $a_ref_id, 1582 $a_obj_id, 1583 $ilUser->getId() 1584 ); 1585 1586 ilUtil::redirect($a_url); 1587 } 1588 } 1589 1590 public function exportHTML() 1591 { 1592 global $DIC; 1593 1594 $ilSetting = $DIC['ilSetting']; 1595 1596 $tpl = new ilTemplate("tpl.export_html.html", true, true, "Modules/WebResource"); 1597 1598 include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php'; 1599 $items = new ilLinkResourceItems($this->object->getId()); 1600 foreach ($items->getAllItems() as $item) { 1601 if (!$item["active"]) { 1602 continue; 1603 } 1604 1605 $target = $this->handleSubItemLinks($item["target"]); 1606 1607 $tpl->setCurrentBlock("link_bl"); 1608 $tpl->setVariable("LINK_URL", $target); 1609 $tpl->setVariable("LINK_TITLE", $item["title"]); 1610 $tpl->setVariable("LINK_DESC", $item["description"]); 1611 $tpl->setVariable("LINK_CREATE", $item["create_date"]); 1612 $tpl->setVariable("LINK_UPDATE", $item["last_update"]); 1613 $tpl->parseCurrentBlock(); 1614 } 1615 1616 $tpl->setVariable("CREATE_DATE", $this->object->getCreateDate()); 1617 $tpl->setVariable("LAST_UPDATE", $this->object->getLastUpdateDate()); 1618 $tpl->setVariable("TXT_TITLE", $this->object->getTitle()); 1619 $tpl->setVariable("TXT_DESC", $this->object->getLongDescription()); 1620 1621 $tpl->setVariable("INST_ID", ($ilSetting->get('short_inst_name') != "") 1622 ? $ilSetting->get('short_inst_name') 1623 : "ILIAS"); 1624 1625 ilUtil::deliverData($tpl->get(), "bookmarks.html"); 1626 } 1627 1628 public static function _goto($a_target, $a_additional = null) 1629 { 1630 global $DIC; 1631 1632 $ilAccess = $DIC['ilAccess']; 1633 $ilErr = $DIC['ilErr']; 1634 $lng = $DIC['lng']; 1635 1636 if ($a_additional && substr($a_additional, -3) == "wsp") { 1637 $_GET["baseClass"] = "ilsharedresourceGUI"; 1638 $_GET["wsp_id"] = $a_target; 1639 include("ilias.php"); 1640 exit; 1641 } 1642 1643 // Will be replaced in future releases by ilAccess::checkAccess() 1644 if ($ilAccess->checkAccess("read", "", $a_target)) { 1645 ilUtil::redirect("ilias.php?baseClass=ilLinkResourceHandlerGUI&ref_id=$a_target"); 1646 } else { 1647 // to do: force flat view 1648 if ($ilAccess->checkAccess("visible", "", $a_target)) { 1649 ilUtil::redirect("ilias.php?baseClass=ilLinkResourceHandlerGUI&ref_id=" . $a_target . "&cmd=infoScreen"); 1650 } else { 1651 if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID)) { 1652 ilUtil::sendFailure(sprintf( 1653 $lng->txt("msg_no_perm_read_item"), 1654 ilObject::_lookupTitle(ilObject::_lookupObjId($a_target)) 1655 ), true); 1656 ilObjectGUI::_gotoRepositoryRoot(); 1657 } 1658 } 1659 } 1660 1661 $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL); 1662 } 1663} // END class.ilObjLinkResource 1664