ILIAS  release_4-3 Revision
 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  $gui = new ilObjBlogGUI($this->node_id, ilObject2GUI::WORKSPACE_NODE_ID);
84  $ilCtrl->forwardCommand($gui);
85  break;
86 
87  case "ilobjfilegui":
88  include_once "Modules/File/classes/class.ilObjFileGUI.php";
89  $gui = new ilObjFileGUI($this->node_id, ilObject2GUI::WORKSPACE_NODE_ID);
90  $ilCtrl->forwardCommand($gui);
91  break;
92 
93  case "ilobjtestverificationgui":
94  include_once "Modules/Test/classes/class.ilObjTestVerificationGUI.php";
96  $ilCtrl->forwardCommand($gui);
97  break;
98 
99  case "ilobjexerciseverificationgui":
100  include_once "Modules/Exercise/classes/class.ilObjExerciseVerificationGUI.php";
102  $ilCtrl->forwardCommand($gui);
103  break;
104 
105  case "ilobjlinkresourcegui":
106  include_once "Modules/WebResource/classes/class.ilObjLinkResourceGUI.php";
107  $gui = new ilObjLinkResourceGUI($this->node_id, ilObject2GUI::WORKSPACE_NODE_ID);
108  $ilCtrl->forwardCommand($gui);
109  break;
110 
111  case "ilobjportfoliogui":
112  include_once "Services/Portfolio/classes/class.ilObjPortfolioGUI.php";
113  $gui = new ilObjPortfolioGUI();
114  $ilCtrl->forwardCommand($gui);
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 "Services/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 "Services/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 "Services/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", $_GET["gtp"]);
260  $ilCtrl->redirectByClass($gui, "preview");
261 
262  case "tstv":
263  case "excv":
264  $ilCtrl->setParameterByClass($gui, "wsp_id", $a_node_id);
265  $ilCtrl->redirectByClass($gui, "deliver");
266 
267  case "file":
268  case "webr":
269  $ilCtrl->setParameterByClass($gui, "wsp_id", $a_node_id);
270  $ilCtrl->redirectByClass($gui);
271 
272  case "prtf":
273  $ilCtrl->setParameterByClass($gui, "prt_id", $a_node_id);
274  $ilCtrl->redirectByClass($gui, "preview");
275 
276  default:
277  exit("invalid object type");
278  }
279  }
280 
281  protected function passwordForm($form = null)
282  {
283  global $tpl, $lng;
284 
285  $lng->loadLanguageModule("wsp");
286 
287  $tpl->setTitle($lng->txt("wsp_password_protected_resource"));
288  $tpl->setDescription($lng->txt("wsp_password_protected_resource_info"));
289 
290  if(!$form)
291  {
292  $form = $this->initPasswordForm();
293  }
294 
295  $tpl->setContent($form->getHTML());
296  }
297 
298  protected function initPasswordForm()
299  {
300  global $ilCtrl, $lng, $ilUser, $ilTabs;
301 
302  if($this->node_id)
303  {
304  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
305  $object_data = ilWorkspaceAccessHandler::getObjectDataFromNode($this->node_id);
306  }
307  else
308  {
309  $object_data["title"] = ilObject::_lookupTitle($this->portfolio_id);
310  }
311 
312  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
313  $form = new ilPropertyFormGUI();
314  $form->setFormAction($ilCtrl->getFormAction($this, "checkPassword"));
315  $form->setTitle($lng->txt("wsp_password_for").": ".$object_data["title"]);
316 
317  $password = new ilPasswordInputGUI($lng->txt("password"), "password");
318  $password->setRetype(false);
319  $password->setRequired(true);
320  $form->addItem($password);
321 
322  $form->addCommandButton("checkPassword", $lng->txt("submit"));
323 
324  if($ilUser->getId() && $ilUser->getId() != ANONYMOUS_USER_ID)
325  {
326  $ilTabs->setBackTarget($lng->txt("back"), $ilCtrl->getLinkTarget($this, "cancelPassword"));
327  $form->addCommandButton("cancelPassword", $lng->txt("cancel"));
328  }
329 
330  return $form;
331  }
332 
333  protected function cancelPassword()
334  {
335  global $ilUser;
336 
337  if($ilUser->getId() && $ilUser->getId() != ANONYMOUS_USER_ID)
338  {
339  if($this->node_id)
340  {
341  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
342  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
343  $tree = new ilWorkspaceTree($ilUser->getId());
344  $owner = $tree->lookupOwner($this->node_id);
345  ilUtil::redirect("ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToWorkspace&dsh=".$owner);
346  }
347  else
348  {
349  include_once "Services/Portfolio/classes/class.ilObjPortfolio.php";
350  $prtf = new ilObjPortfolio($this->portfolio_id, false);
351  $owner = $prtf->getOwner();
352  ilUtil::redirect("ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToPortfolio&dsh=".$owner);
353  }
354  }
355  }
356 
357  protected function checkPassword()
358  {
359  global $ilDB, $lng;
360 
361  $lng->loadLanguageModule("wsp");
362 
363  $form = $this->initPasswordForm();
364  if($form->checkInput())
365  {
366  $input = md5($form->getInput("password"));
367  if($this->node_id)
368  {
369  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
370  $password = ilWorkspaceAccessHandler::getSharedNodePassword($this->node_id);
371  }
372  else
373  {
374  include_once "Services/Portfolio/classes/class.ilPortfolioAccessHandler.php";
375  $password = ilPortfolioAccessHandler::getSharedNodePassword($this->portfolio_id);
376  }
377  if($input == $password)
378  {
379  if($this->node_id)
380  {
382  $this->redirectToResource($this->node_id);
383  }
384  else
385  {
386  ilPortfolioAccessHandler::keepSharedSessionPassword($this->portfolio_id, $input);
387  $this->redirectToResource($this->portfolio_id, true);
388  }
389  }
390  else
391  {
392  $item = $form->getItemByPostVar("password");
393  $item->setAlert($lng->txt("wsp_invalid_password"));
394  ilUtil::sendFailure($lng->txt("form_input_not_valid"));
395  }
396  }
397 
398  $form->setValuesByPost();
399  $this->passwordForm($form);
400  }
401 }
402 
403 ?>