1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once "./Services/Object/classes/class.ilObjectGUI.php" ;
5
6/**
7 * Web Resource Administration Settings.
8 *
9 * @author Jörg Lützenkirchen <luetzenkirchen@leifos.com>
10 * @version $Id:$
11 *
12 * @ilCtrl_Calls ilObjWebResourceAdministrationGUI: ilPermissionGUI
13 *
14 * @ingroup ModulesWebResource
15 */
16class ilObjWebResourceAdministrationGUI extends ilObjectGUI
17{
18    public function __construct($a_data, $a_id, $a_call_by_reference = true, $a_prepare_output = true)
19    {
20        $this->type = "wbrs";
21        parent::__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
22
23        $this->lng->loadLanguageModule("webr");
24    }
25
26    public function executeCommand()
27    {
28        global $DIC;
29
30        $ilAccess = $DIC['ilAccess'];
31        $ilErr = $DIC['ilErr'];
32
33        $next_class = $this->ctrl->getNextClass($this);
34        $cmd = $this->ctrl->getCmd();
35
36        $this->prepareOutput();
37
38        if (!$ilAccess->checkAccess("read", "", $this->object->getRefId())) {
39            $ilErr->raiseError($this->lng->txt("no_permission"), $ilErr->WARNING);
40        }
41
42        switch ($next_class) {
43            case 'ilpermissiongui':
44                $this->tabs_gui->setTabActive("perm_settings");
45                include_once "Services/AccessControl/classes/class.ilPermissionGUI.php";
46                $perm_gui = new ilPermissionGUI($this);
47                $this->ctrl->forwardCommand($perm_gui);
48                break;
49
50            default:
51                if (!$cmd || $cmd == "view") {
52                    $cmd = "editSettings";
53                }
54                $this->$cmd();
55                break;
56        }
57        return true;
58    }
59
60    public function getAdminTabs()
61    {
62        global $DIC;
63
64        $rbacsystem = $DIC['rbacsystem'];
65
66        if ($rbacsystem->checkAccess("visible,read", $this->object->getRefId())) {
67            $this->tabs_gui->addTarget(
68                "settings",
69                $this->ctrl->getLinkTarget($this, "editSettings"),
70                array("editSettings", "view")
71            );
72        }
73
74        if ($rbacsystem->checkAccess("edit_permission", $this->object->getRefId())) {
75            $this->tabs_gui->addTarget(
76                "perm_settings",
77                $this->ctrl->getLinkTargetByClass("ilpermissiongui", "perm"),
78                array(),
79                "ilpermissiongui"
80            );
81        }
82    }
83
84    public function editSettings(ilObjPropertyFormGUI $a_form = null)
85    {
86        $this->tabs_gui->setTabActive('settings');
87
88        if (!$a_form) {
89            $a_form = $this->initFormSettings();
90        }
91        $this->tpl->setContent($a_form->getHTML());
92        return true;
93    }
94
95    public function saveSettings()
96    {
97        global $DIC;
98
99        $ilSetting = $DIC['ilSetting'];
100
101        $this->checkPermission("write");
102
103        $form = $this->initFormSettings();
104        if ($form->checkInput()) {
105            $ilSetting->set("links_dynamic", $form->getInput("links_dynamic"));
106
107            ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
108            $this->ctrl->redirect($this, "editSettings");
109        }
110
111        $form->setValuesByPost();
112        $this->editSettings($form);
113    }
114
115    protected function initFormSettings()
116    {
117        global $DIC;
118
119        $ilSetting = $DIC['ilSetting'];
120        $ilAccess = $DIC['ilAccess'];
121
122        include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
123        $form = new ilPropertyFormGUI();
124        $form->setFormAction($this->ctrl->getFormAction($this, "saveSettings"));
125        $form->setTitle($this->lng->txt("settings"));
126
127        // dynamic web links
128        $cb = new ilCheckboxInputGUI($this->lng->txt("links_dynamic"), "links_dynamic");
129        $cb->setInfo($this->lng->txt("links_dynamic_info"));
130        $cb->setChecked($ilSetting->get("links_dynamic"));
131        $form->addItem($cb);
132
133        if ($ilAccess->checkAccess("write", '', $this->object->getRefId())) {
134            $form->addCommandButton("saveSettings", $this->lng->txt("save"));
135            $form->addCommandButton("view", $this->lng->txt("cancel"));
136        }
137
138        return $form;
139    }
140}
141