ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 = $_GET["wsp_id"];
29  $this->portfolio_id = $_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  $form->addItem($password);
328 
329  $form->addCommandButton("checkPassword", $lng->txt("submit"));
330 
331  if($ilUser->getId() && $ilUser->getId() != ANONYMOUS_USER_ID)
332  {
333  $ilTabs->setBackTarget($lng->txt("back"), $ilCtrl->getLinkTarget($this, "cancelPassword"));
334  $form->addCommandButton("cancelPassword", $lng->txt("cancel"));
335  }
336 
337  return $form;
338  }
339 
340  protected function cancelPassword()
341  {
342  global $ilUser;
343 
344  if($ilUser->getId() && $ilUser->getId() != ANONYMOUS_USER_ID)
345  {
346  if($this->node_id)
347  {
348  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
349  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
350  $tree = new ilWorkspaceTree($ilUser->getId());
351  $owner = $tree->lookupOwner($this->node_id);
352  ilUtil::redirect("ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToWorkspace&dsh=".$owner);
353  }
354  else
355  {
356  include_once "Modules/Portfolio/classes/class.ilObjPortfolio.php";
357  $prtf = new ilObjPortfolio($this->portfolio_id, false);
358  $owner = $prtf->getOwner();
359  ilUtil::redirect("ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToPortfolio&dsh=".$owner);
360  }
361  }
362  }
363 
364  protected function checkPassword()
365  {
366  global $ilDB, $lng;
367 
368  $lng->loadLanguageModule("wsp");
369 
370  $form = $this->initPasswordForm();
371  if($form->checkInput())
372  {
373  $input = md5($form->getInput("password"));
374  if($this->node_id)
375  {
376  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
377  $password = ilWorkspaceAccessHandler::getSharedNodePassword($this->node_id);
378  }
379  else
380  {
381  include_once "Modules/Portfolio/classes/class.ilPortfolioAccessHandler.php";
382  $password = ilPortfolioAccessHandler::getSharedNodePassword($this->portfolio_id);
383  }
384  if($input == $password)
385  {
386  if($this->node_id)
387  {
389  $this->redirectToResource($this->node_id);
390  }
391  else
392  {
393  ilPortfolioAccessHandler::keepSharedSessionPassword($this->portfolio_id, $input);
394  $this->redirectToResource($this->portfolio_id, true);
395  }
396  }
397  else
398  {
399  $item = $form->getItemByPostVar("password");
400  $item->setAlert($lng->txt("wsp_invalid_password"));
401  ilUtil::sendFailure($lng->txt("form_input_not_valid"));
402  }
403  }
404 
405  $form->setValuesByPost();
406  $this->passwordForm($form);
407  }
408 }
409 
410 ?>