ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilSharedResourceGUI.php
Go to the documentation of this file.
1<?php
2
20
30{
31 protected ilCtrl $ctrl;
34 protected ilObjUser $user;
35 protected ilLanguage $lng;
37 protected ilTabsGUI $tabs;
38 protected int $node_id;
39 protected int $portfolio_id;
41
42 public function __construct()
43 {
44 global $DIC;
45
46 $this->ctrl = $DIC->ctrl();
47 $this->tpl = $DIC->ui()->mainTemplate();
48 $this->locator = $DIC["ilLocator"];
49 $this->user = $DIC->user();
50 $this->lng = $DIC->language();
51 $this->obj_definition = $DIC["objDefinition"];
52 $this->tabs = $DIC->tabs();
53 $ilCtrl = $DIC->ctrl();
54
55 $this->request = new StandardGUIRequest(
56 $DIC->http(),
57 $DIC->refinery()
58 );
59
60 $ilCtrl->saveParameter($this, "wsp_id");
61 $ilCtrl->saveParameter($this, "prt_id");
62 $this->node_id = $this->request->getWspId();
63 $this->portfolio_id = $this->request->getPrtId();
64 }
65
66 public function executeCommand(): void
67 {
68 $ilCtrl = $this->ctrl;
70 $ilLocator = $this->locator;
71 $ilUser = $this->user;
73
74 $next_class = $ilCtrl->getNextClass($this);
75 $cmd = $ilCtrl->getCmd();
76
78
79 // #12096
80 if ($ilUser->getId() != ANONYMOUS_USER_ID &&
81 $next_class &&
82 !in_array($next_class, array("ilobjbloggui", "ilobjportfoliogui"))) {
83 $tree = new ilWorkspaceTree($ilUser->getId());
84 $access_handler = new ilWorkspaceAccessHandler($tree);
85 $owner_id = $tree->lookupOwner($this->node_id);
86 $obj_id = $tree->lookupObjectId($this->node_id);
87
89
90 // see ilPersonalWorkspaceGUI
91 if ($owner_id != $ilUser->getId()) {
92 $ilCtrl->setParameterByClass("ildashboardgui", "dsh", $owner_id);
93 $link = $ilCtrl->getLinkTargetByClass("ildashboardgui", "jumptoworkspace");
94 $ilLocator->addItem($lng->txt("wsp_tab_shared"), $link);
95
96 $ilLocator->addItem(ilUserUtil::getNamePresentation($owner_id), $link);
97 } else {
98 $link = $ilCtrl->getLinkTargetByClass("ildashboardgui", "jumptoworkspace");
99 $ilLocator->addItem($lng->txt("wsp_tab_personal"), $link);
100 }
101
102 $link = $access_handler->getGotoLink($this->node_id, $obj_id);
103 $ilLocator->addItem(ilObject::_lookupTitle($obj_id), $link);
104 $tpl->setLocator();
105 }
106
107 switch ($next_class) {
108 case "ilobjbloggui":
109 $bgui = new ilObjBlogGUI($this->node_id, ilObject2GUI::WORKSPACE_NODE_ID);
110 $ilCtrl->forwardCommand($bgui);
111 break;
112
113 case "ilobjfilegui":
114 $fgui = new ilObjFileGUI($this->node_id, ilObject2GUI::WORKSPACE_NODE_ID);
115 $ilCtrl->forwardCommand($fgui);
116 break;
117
118 case "ilobjtestverificationgui":
120 $ilCtrl->forwardCommand($tgui);
121 break;
122
123 case "ilobjexerciseverificationgui":
125 $ilCtrl->forwardCommand($egui);
126 break;
127
128 case "ilobjlinkresourcegui":
129 $lgui = new ilObjLinkResourceGUI($this->node_id, ilObject2GUI::WORKSPACE_NODE_ID);
130 $ilCtrl->forwardCommand($lgui);
131 break;
132
133 case "ilobjportfoliogui":
134 $pgui = new ilObjPortfolioGUI($this->portfolio_id);
135 $ilCtrl->forwardCommand($pgui);
136 break;
137
138 default:
139 if (!$cmd) {
140 $cmd = "process";
141 }
142 $this->$cmd();
143 }
144
146 }
147
148 protected function process(): void
149 {
150 if (!$this->node_id && !$this->portfolio_id) {
151 throw new ilPermissionException("invalid call");
152 }
153
154 // if already logged in, we need to re-check for public password
155 if ($this->node_id) {
156 if (!self::hasAccess($this->node_id)) {
157 throw new ilPermissionException("no permission");
158 }
159 $this->redirectToResource($this->node_id);
160 } else {
161 if (!self::hasAccess($this->portfolio_id, true)) {
162 throw new ilPermissionException("no permission");
163 }
164 $this->redirectToResource($this->portfolio_id, true);
165 }
166 }
167
168 public static function hasAccess(
169 int $a_node_id,
170 bool $a_is_portfolio = false
171 ): bool {
172 global $DIC;
173
174 $ilUser = $DIC->user();
175 $ilSetting = $DIC->settings();
176
177 // if we have current user - check with normal access handler
178 if ($ilUser->getId() != ANONYMOUS_USER_ID) {
179 if (!$a_is_portfolio) {
180 $tree = new ilWorkspaceTree($ilUser->getId());
181 $access_handler = new ilWorkspaceAccessHandler($tree);
182 } else {
183 $access_handler = new ilPortfolioAccessHandler();
184 }
185 if ($access_handler->checkAccess("read", "", $a_node_id)) {
186 return true;
187 }
188 }
189
190 if (!$a_is_portfolio) {
191 $shared = ilWorkspaceAccessHandler::_getPermissions($a_node_id);
192 } else {
193 // #12059
194 if (!$ilSetting->get('user_portfolios')) {
195 return false;
196 }
197
198 // #12039
199 $prtf = new ilObjPortfolio($a_node_id, false);
200 if (!$prtf->isOnline()) {
201 return false;
202 }
203
204 $shared = ilPortfolioAccessHandler::_getPermissions($a_node_id);
205 }
206
207 // object is "public"
208 if (in_array(ilWorkspaceAccessGUI::PERMISSION_ALL, $shared)) {
209 return true;
210 }
211
212 // password protected
213 if (in_array(ilWorkspaceAccessGUI::PERMISSION_ALL_PASSWORD, $shared)) {
214 if (!$a_is_portfolio) {
215 ilUtil::redirect("ilias.php?baseClass=ilSharedResourceGUI&cmd=passwordForm&wsp_id=" . $a_node_id);
216 } else {
217 ilUtil::redirect("ilias.php?baseClass=ilSharedResourceGUI&cmd=passwordForm&prt_id=" . $a_node_id);
218 }
219 }
220
221 return false;
222 }
223
224 protected function redirectToResource(
225 int $a_node_id,
226 bool $a_is_portfolio = false
227 ): void {
228 $ilCtrl = $this->ctrl;
229 $objDefinition = $this->obj_definition;
230
231 if (!$a_is_portfolio) {
232 $object_data = ilWorkspaceAccessHandler::getObjectDataFromNode($a_node_id);
233 if (!$object_data["obj_id"]) {
234 throw new ilPermissionException("invalid object");
235 }
236 } else {
237 if (!ilObject::_lookupType($a_node_id, false)) {
238 throw new ilPermissionException("invalid object");
239 }
240 $object_data["obj_id"] = $a_node_id;
241 $object_data["type"] = "prtf";
242 }
243
244 $class = $objDefinition->getClassName($object_data["type"]);
245 $gui = "ilobj" . $class . "gui";
246
247 switch ($object_data["type"]) {
248 case "blog":
249 $ilCtrl->setParameterByClass($gui, "wsp_id", $a_node_id);
250 $ilCtrl->setParameterByClass($gui, "gtp", $this->request->getBlogGtp());
251 $ilCtrl->setParameterByClass($gui, "edt", $this->request->getBlogEdt());
252 $ilCtrl->redirectByClass($gui, "preview");
253 break;
254
255 case "tstv":
256 case "excv":
257 case "crsv":
258 case "scov":
259 case "cmxv":
260 case "ltiv":
261 $ilCtrl->setParameterByClass($gui, "wsp_id", $a_node_id);
262 $ilCtrl->redirectByClass($gui, "deliver");
263 break;
264
265 case "file":
266 case "webr":
267 $ilCtrl->setParameterByClass($gui, "wsp_id", $a_node_id);
268 $ilCtrl->redirectByClass($gui);
269 break;
270
271 case "prtf":
272 $ilCtrl->setParameterByClass($gui, "prt_id", $a_node_id);
273 $ilCtrl->setParameterByClass($gui, "gtp", $this->request->getBlogGtp());
274 if ($this->request->getBackUrl()) {
275 $ilCtrl->setParameterByClass($gui, "back_url", rawurlencode($this->request->getBackUrl()));
276 }
277 $ilCtrl->redirectByClass($gui, "preview");
278 break;
279
280 default:
281 exit("invalid object type");
282 }
283 }
284
285 protected function passwordForm(?ilPropertyFormGUI $form = null): void
286 {
287 $tpl = $this->tpl;
289
290 $lng->loadLanguageModule("wsp");
291
292 $tpl->setTitle($lng->txt("wsp_password_protected_resource"));
293 $tpl->setDescription($lng->txt("wsp_password_protected_resource_info"));
294
295 if (!$form) {
296 $form = $this->initPasswordForm();
297 }
298
299 $tpl->setContent($form->getHTML());
300 }
301
303 {
304 $ilCtrl = $this->ctrl;
306 $ilUser = $this->user;
307 $ilTabs = $this->tabs;
308
309 if ($this->node_id) {
310 $object_data = ilWorkspaceAccessHandler::getObjectDataFromNode($this->node_id);
311 } else {
312 $object_data["title"] = ilObject::_lookupTitle($this->portfolio_id);
313 }
314
315 $form = new ilPropertyFormGUI();
316 $form->setFormAction($ilCtrl->getFormAction($this, "checkPassword"));
317 $form->setTitle($lng->txt("wsp_password_for") . ": " . $object_data["title"]);
318
319 $password = new ilPasswordInputGUI($lng->txt("password"), "password");
320 $password->setRetype(false);
321 $password->setRequired(true);
322 $password->setSkipSyntaxCheck(true); // #17757
323 $form->addItem($password);
324
325 $form->addCommandButton("checkPassword", $lng->txt("submit"));
326
327 if ($ilUser->getId() && $ilUser->getId() != ANONYMOUS_USER_ID) {
328 $ilTabs->setBackTarget($lng->txt("back"), $ilCtrl->getLinkTarget($this, "cancelPassword"));
329 $form->addCommandButton("cancelPassword", $lng->txt("cancel"));
330 }
331
332 return $form;
333 }
334
335 protected function cancelPassword(): void
336 {
337 $ilUser = $this->user;
338
339 if ($ilUser->getId() && $ilUser->getId() != ANONYMOUS_USER_ID) {
340 if ($this->node_id) {
341 $tree = new ilWorkspaceTree($ilUser->getId());
342 $owner = $tree->lookupOwner($this->node_id);
343 ilUtil::redirect("ilias.php?baseClass=ilDashboardGUI&cmd=jumpToWorkspace&dsh=" . $owner);
344 } else {
345 $prtf = new ilObjPortfolio($this->portfolio_id, false);
346 $owner = $prtf->getOwner();
347 ilUtil::redirect("ilias.php?baseClass=ilDashboardGUI&cmd=jumpToPortfolio&dsh=" . $owner);
348 }
349 }
350 }
351
352 protected function checkPassword(): void
353 {
355
356 $lng->loadLanguageModule("wsp");
357
358 $form = $this->initPasswordForm();
359 if ($form->checkInput()) {
360 $input = md5($form->getInput("password"));
361 if ($this->node_id) {
362 $password = ilWorkspaceAccessHandler::getSharedNodePassword($this->node_id);
363 } else {
364 $password = ilPortfolioAccessHandler::getSharedNodePassword($this->portfolio_id);
365 }
366 if ($input == $password) {
367 if ($this->node_id) {
369 $this->redirectToResource($this->node_id);
370 } else {
371 ilPortfolioAccessHandler::keepSharedSessionPassword($this->portfolio_id, $input);
372 $this->redirectToResource($this->portfolio_id, true);
373 }
374 } else {
375 $item = $form->getItemByPostVar("password");
376 $item->setAlert($lng->txt("wsp_invalid_password"));
377 $this->tpl->setOnScreenMessage('failure', $lng->txt("form_input_not_valid"));
378 }
379 }
380
381 $form->setValuesByPost();
382 $this->passwordForm($form);
383 }
384}
Class ilCtrl provides processing control methods.
language handling
loadLanguageModule(string $a_module)
Load language module.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
@ilCtrl_Calls ilObjBlogGUI: ilBlogPostingGUI, ilWorkspaceAccessGUI @ilCtrl_Calls ilObjBlogGUI: ilInfo...
GUI class for exercise verification.
GUI class for file objects.
Class ilObjLinkResourceGUI.
@ilCtrl_Calls ilObjPortfolioGUI: ilPortfolioPageGUI, ilPageObjectGUI @ilCtrl_Calls ilObjPortfolioGUI:...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
GUI class for test verification.
User class.
parses the objects.xml it handles the xml-description of all ilias objects
static _lookupType(int $id, bool $reference=false)
static _lookupTitle(int $obj_id)
This class represents a password property in a property form.
Access handler for portfolio NOTE: This file needs to stay in the classes directory,...
static keepSharedSessionPassword(int $a_node_id, string $a_password)
static getSharedNodePassword(int $a_node_id)
static _getPermissions(int $a_node_id)
Get all permissions to node.
This class represents a property form user interface.
Workspace deep link handler GUI.
static hasAccess(int $a_node_id, bool $a_is_portfolio=false)
redirectToResource(int $a_node_id, bool $a_is_portfolio=false)
ilObjectDefinition $obj_definition
ilGlobalTemplateInterface $tpl
passwordForm(?ilPropertyFormGUI $form=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link='', bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path=null)
Default behaviour is:
static redirect(string $a_script)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getSharedNodePassword(int $a_node_id)
static getObjectDataFromNode(int $a_node_id)
static _getPermissions(int $a_node_id)
Get all permissions to node.
static keepSharedSessionPassword(int $a_node_id, string $a_password)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const ANONYMOUS_USER_ID
Definition: constants.php:27
exit
setLocator()
Insert locator.
setDescription(string $a_descr)
Sets description below title in standard template.
loadStandardTemplate()
This loads the standard template "tpl.adm_content.html" and "tpl.statusline.html" the CONTENT and STA...
setTitle(string $a_title, bool $hidden=false)
Sets title in standard template.
printToStdout(string $part=self::DEFAULT_BLOCK, bool $has_tabs=true, bool $skip_main_menu=false)
setContent(string $a_html)
Sets content for standard template.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $lng
Definition: privfeed.php:31
global $ilSetting
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26