ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilSharedResourceGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
17{
21 protected $ctrl;
22
26 protected $tpl;
27
31 protected $main_menu;
32
36 protected $locator;
37
41 protected $user;
42
46 protected $lng;
47
51 protected $obj_definition;
52
56 protected $tabs;
57
61 protected $db;
62
63 protected $node_id;
64 protected $portfolio_id;
65 protected $access_handler;
66
67 public function __construct()
68 {
69 global $DIC;
70
71 $this->ctrl = $DIC->ctrl();
72 $this->tpl = $DIC["tpl"];
73 $this->main_menu = $DIC["ilMainMenu"];
74 $this->locator = $DIC["ilLocator"];
75 $this->user = $DIC->user();
76 $this->lng = $DIC->language();
77 $this->obj_definition = $DIC["objDefinition"];
78 $this->tabs = $DIC->tabs();
79 $this->db = $DIC->database();
80 $ilCtrl = $DIC->ctrl();
81
82 $ilCtrl->saveParameter($this, "wsp_id");
83 $ilCtrl->saveParameter($this, "prt_id");
84 $this->node_id = (int) $_GET["wsp_id"];
85 $this->portfolio_id = (int) $_GET["prt_id"];
86 }
87
88 public function executeCommand()
89 {
92 $ilMainMenu = $this->main_menu;
93 $ilLocator = $this->locator;
96
97 $next_class = $ilCtrl->getNextClass($this);
98 $cmd = $ilCtrl->getCmd();
99
100 $tpl->getStandardTemplate();
101
102 // #8509
103 $ilMainMenu->setActive("desktop");
104
105 // #12096
106 if ($ilUser->getId() != ANONYMOUS_USER_ID &&
107 $next_class &&
108 !in_array($next_class, array("ilobjbloggui", "ilobjportfoliogui"))) {
109 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
110 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
111 $tree = new ilWorkspaceTree($ilUser->getId());
113 $owner_id = $tree->lookupOwner($this->node_id);
114 $obj_id = $tree->lookupObjectId($this->node_id);
115
116 $lng->loadLanguageModule("wsp");
117
118 // see ilPersonalWorkspaceGUI
119 if ($owner_id != $ilUser->getId()) {
120 $ilCtrl->setParameterByClass("ilpersonaldesktopgui", "dsh", $owner_id);
121 $link = $ilCtrl->getLinkTargetByClass("ilpersonaldesktopgui", "jumptoworkspace");
122 $ilLocator->addItem($lng->txt("wsp_tab_shared"), $link);
123
124 include_once "Services/User/classes/class.ilUserUtil.php";
125 $ilLocator->addItem(ilUserUtil::getNamePresentation($owner_id), $link);
126 } else {
127 $link = $ilCtrl->getLinkTargetByClass("ilpersonaldesktopgui", "jumptoworkspace");
128 $ilLocator->addItem($lng->txt("wsp_tab_personal"), $link);
129 }
130
131 $link = $access_handler->getGotoLink($this->node_id, $obj_id);
132 $ilLocator->addItem(ilObject::_lookupTitle($obj_id), $link);
133 $tpl->setLocator($ilLocator);
134 }
135
136 switch ($next_class) {
137 case "ilobjbloggui":
138 include_once "Modules/Blog/classes/class.ilObjBlogGUI.php";
139 $bgui = new ilObjBlogGUI($this->node_id, ilObject2GUI::WORKSPACE_NODE_ID);
140 $ilCtrl->forwardCommand($bgui);
141 break;
142
143 case "ilobjfilegui":
144 include_once "Modules/File/classes/class.ilObjFileGUI.php";
145 $fgui = new ilObjFileGUI($this->node_id, ilObject2GUI::WORKSPACE_NODE_ID);
146 $ilCtrl->forwardCommand($fgui);
147 break;
148
149 case "ilobjtestverificationgui":
150 include_once "Modules/Test/classes/class.ilObjTestVerificationGUI.php";
152 $ilCtrl->forwardCommand($tgui);
153 break;
154
155 case "ilobjexerciseverificationgui":
156 include_once "Modules/Exercise/classes/class.ilObjExerciseVerificationGUI.php";
158 $ilCtrl->forwardCommand($egui);
159 break;
160
161 case "ilobjlinkresourcegui":
162 include_once "Modules/WebResource/classes/class.ilObjLinkResourceGUI.php";
163 $lgui = new ilObjLinkResourceGUI($this->node_id, ilObject2GUI::WORKSPACE_NODE_ID);
164 $ilCtrl->forwardCommand($lgui);
165 break;
166
167 case "ilobjportfoliogui":
168 include_once "Modules/Portfolio/classes/class.ilObjPortfolioGUI.php";
169 $pgui = new ilObjPortfolioGUI($this->portfolio_id, ilObject2GUI::PORTFOLIO_OBJECT_ID);
170 $ilCtrl->forwardCommand($pgui);
171 break;
172
173 default:
174 if (!$cmd) {
175 $cmd = "process";
176 }
177 $this->$cmd();
178 }
179
180 $tpl->show();
181 }
182
183 protected function process()
184 {
185 if (!$this->node_id && !$this->portfolio_id) {
186 exit("invalid call");
187 }
188
189 // if already logged in, we need to re-check for public password
190 if ($this->node_id) {
191 if (!self::hasAccess($this->node_id)) {
192 exit("no permission");
193 }
194 $this->redirectToResource($this->node_id);
195 } else {
196 if (!self::hasAccess($this->portfolio_id, true)) {
197 exit("no permission");
198 }
199 $this->redirectToResource($this->portfolio_id, true);
200 }
201 }
202
203 public static function hasAccess($a_node_id, $a_is_portfolio = false)
204 {
205 global $DIC;
206
207 $ilUser = $DIC->user();
208 $ilSetting = $DIC->settings();
209
210 // if we have current user - check with normal access handler
211 if ($ilUser->getId() != ANONYMOUS_USER_ID) {
212 if (!$a_is_portfolio) {
213 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
214 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
215 $tree = new ilWorkspaceTree($ilUser->getId());
217 } else {
218 include_once "Modules/Portfolio/classes/class.ilPortfolioAccessHandler.php";
220 }
221 if ($access_handler->checkAccess("read", "", $a_node_id)) {
222 return true;
223 }
224 }
225
226 // not logged in yet or no read access
227 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessGUI.php";
228
229 if (!$a_is_portfolio) {
230 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
231 $shared = ilWorkspaceAccessHandler::_getPermissions($a_node_id);
232 } else {
233 // #12059
234 if (!$ilSetting->get('user_portfolios')) {
235 return false;
236 }
237
238 // #12039
239 include_once "Modules/Portfolio/classes/class.ilObjPortfolio.php";
240 $prtf = new ilObjPortfolio($a_node_id, false);
241 if (!$prtf->isOnline()) {
242 return false;
243 }
244
245 include_once "Modules/Portfolio/classes/class.ilPortfolioAccessHandler.php";
246 $shared = ilPortfolioAccessHandler::_getPermissions($a_node_id);
247 }
248
249 // object is "public"
250 if (in_array(ilWorkspaceAccessGUI::PERMISSION_ALL, $shared)) {
251 return true;
252 }
253
254 // password protected
255 if (in_array(ilWorkspaceAccessGUI::PERMISSION_ALL_PASSWORD, $shared)) {
256 if (!$a_is_portfolio) {
257 ilUtil::redirect("ilias.php?baseClass=ilSharedResourceGUI&cmd=passwordForm&wsp_id=" . $a_node_id);
258 } else {
259 ilUtil::redirect("ilias.php?baseClass=ilSharedResourceGUI&cmd=passwordForm&prt_id=" . $a_node_id);
260 }
261 }
262
263 return false;
264 }
265
266 protected function redirectToResource($a_node_id, $a_is_portfolio = false)
267 {
269 $objDefinition = $this->obj_definition;
270
271 if (!$a_is_portfolio) {
272 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
273 $object_data = ilWorkspaceAccessHandler::getObjectDataFromNode($a_node_id);
274 if (!$object_data["obj_id"]) {
275 exit("invalid object");
276 }
277 } else {
278 if (!ilObject::_lookupType($a_node_id, false)) {
279 exit("invalid object");
280 }
281 $object_data["obj_id"] = $a_node_id;
282 $object_data["type"] = "prtf";
283 }
284
285 $class = $objDefinition->getClassName($object_data["type"]);
286 $gui = "ilobj" . $class . "gui";
287
288 switch ($object_data["type"]) {
289 case "blog":
290 $ilCtrl->setParameterByClass($gui, "wsp_id", $a_node_id);
291 $ilCtrl->setParameterByClass($gui, "gtp", (int) $_GET["gtp"]);
292 $ilCtrl->redirectByClass($gui, "preview");
293
294 // no break
295 case "tstv":
296 case "excv":
297 case "crsv":
298 case "scov":
299 $ilCtrl->setParameterByClass($gui, "wsp_id", $a_node_id);
300 $ilCtrl->redirectByClass($gui, "deliver");
301
302 // no break
303 case "file":
304 case "webr":
305 $ilCtrl->setParameterByClass($gui, "wsp_id", $a_node_id);
306 $ilCtrl->redirectByClass($gui);
307
308 // no break
309 case "prtf":
310 $ilCtrl->setParameterByClass($gui, "prt_id", $a_node_id);
311 $ilCtrl->setParameterByClass($gui, "gtp", (int) $_GET["gtp"]);
312 if ($_GET["back_url"]) {
313 $ilCtrl->setParameterByClass($gui, "back_url", rawurlencode($_GET["back_url"]));
314 }
315 $ilCtrl->redirectByClass($gui, "preview");
316
317 // no break
318 default:
319 exit("invalid object type");
320 }
321 }
322
323 protected function passwordForm($form = null)
324 {
327
328 $lng->loadLanguageModule("wsp");
329
330 $tpl->setTitle($lng->txt("wsp_password_protected_resource"));
331 $tpl->setDescription($lng->txt("wsp_password_protected_resource_info"));
332
333 if (!$form) {
334 $form = $this->initPasswordForm();
335 }
336
337 $tpl->setContent($form->getHTML());
338 }
339
340 protected function initPasswordForm()
341 {
345 $ilTabs = $this->tabs;
346
347 if ($this->node_id) {
348 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
349 $object_data = ilWorkspaceAccessHandler::getObjectDataFromNode($this->node_id);
350 } else {
351 $object_data["title"] = ilObject::_lookupTitle($this->portfolio_id);
352 }
353
354 include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
355 $form = new ilPropertyFormGUI();
356 $form->setFormAction($ilCtrl->getFormAction($this, "checkPassword"));
357 $form->setTitle($lng->txt("wsp_password_for") . ": " . $object_data["title"]);
358
359 $password = new ilPasswordInputGUI($lng->txt("password"), "password");
360 $password->setRetype(false);
361 $password->setRequired(true);
362 $password->setSkipSyntaxCheck(true); // #17757
363 $form->addItem($password);
364
365 $form->addCommandButton("checkPassword", $lng->txt("submit"));
366
367 if ($ilUser->getId() && $ilUser->getId() != ANONYMOUS_USER_ID) {
368 $ilTabs->setBackTarget($lng->txt("back"), $ilCtrl->getLinkTarget($this, "cancelPassword"));
369 $form->addCommandButton("cancelPassword", $lng->txt("cancel"));
370 }
371
372 return $form;
373 }
374
375 protected function cancelPassword()
376 {
378
379 if ($ilUser->getId() && $ilUser->getId() != ANONYMOUS_USER_ID) {
380 if ($this->node_id) {
381 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
382 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
383 $tree = new ilWorkspaceTree($ilUser->getId());
384 $owner = $tree->lookupOwner($this->node_id);
385 ilUtil::redirect("ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToWorkspace&dsh=" . $owner);
386 } else {
387 include_once "Modules/Portfolio/classes/class.ilObjPortfolio.php";
388 $prtf = new ilObjPortfolio($this->portfolio_id, false);
389 $owner = $prtf->getOwner();
390 ilUtil::redirect("ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToPortfolio&dsh=" . $owner);
391 }
392 }
393 }
394
395 protected function checkPassword()
396 {
399
400 $lng->loadLanguageModule("wsp");
401
402 $form = $this->initPasswordForm();
403 if ($form->checkInput()) {
404 $input = md5($form->getInput("password"));
405 if ($this->node_id) {
406 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
408 } else {
409 include_once "Modules/Portfolio/classes/class.ilPortfolioAccessHandler.php";
411 }
412 if ($input == $password) {
413 if ($this->node_id) {
415 $this->redirectToResource($this->node_id);
416 } else {
417 ilPortfolioAccessHandler::keepSharedSessionPassword($this->portfolio_id, $input);
418 $this->redirectToResource($this->portfolio_id, true);
419 }
420 } else {
421 $item = $form->getItemByPostVar("password");
422 $item->setAlert($lng->txt("wsp_invalid_password"));
423 ilUtil::sendFailure($lng->txt("form_input_not_valid"));
424 }
425 }
426
427 $form->setValuesByPost();
428 $this->passwordForm($form);
429 }
430}
user()
Definition: user.php:4
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
Class ilObjBlogGUI.
GUI class for exercise verification.
GUI class for file objects.
Class ilObjLinkResourceGUI.
Portfolio view gui class.
GUI class for test verification.
static _lookupTitle($a_id)
lookup object title
static _lookupType($a_id, $a_reference=false)
lookup object type
This class represents a password property in a property form.
Access handler for portfolio.
static _getPermissions($a_node_id)
Get all permissions to node.
static keepSharedSessionPassword($a_node_id, $a_password)
This class represents a property form user interface.
Workspace deep link handler GUI.
redirectToResource($a_node_id, $a_is_portfolio=false)
static hasAccess($a_node_id, $a_is_portfolio=false)
static getNamePresentation( $a_user_id, $a_user_image=false, $a_profile_link=false, $a_profile_back_link="", $a_force_first_lastname=false, $a_omit_login=false, $a_sortable=true, $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
static redirect($a_script)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
Access handler for personal workspace.
static keepSharedSessionPassword($a_node_id, $a_password)
static _getPermissions($a_node_id)
Get all permissions to node.
Tree handler for personal workspace.
global $ilCtrl
Definition: ilias.php:18
global $ilSetting
Definition: privfeed.php:17
$password
Definition: pwgen.php:17
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7
global $ilDB
$ilUser
Definition: imgupload.php:18