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