ILIAS  Release_4_2_x_branch Revision 61807
 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;
35 
36  $next_class = $ilCtrl->getNextClass($this);
37  $cmd = $ilCtrl->getCmd();
38 
39  $tpl->getStandardTemplate();
40 
41  // #8509
42  $ilMainMenu->setActive("desktop");
43 
44  switch($next_class)
45  {
46  case "ilobjbloggui":
47  include_once "Modules/Blog/classes/class.ilObjBlogGUI.php";
48  $bgui = new ilObjBlogGUI($this->node_id, ilObject2GUI::WORKSPACE_NODE_ID);
49  $ilCtrl->forwardCommand($bgui);
50  break;
51 
52  case "ilobjfilegui":
53  include_once "Modules/File/classes/class.ilObjFileGUI.php";
54  $fgui = new ilObjFileGUI($this->node_id, ilObject2GUI::WORKSPACE_NODE_ID);
55  $ilCtrl->forwardCommand($fgui);
56  break;
57 
58  case "ilobjtestverificationgui":
59  include_once "Modules/Test/classes/class.ilObjTestVerificationGUI.php";
60  $tgui = new ilObjTestVerificationGUI($this->node_id, ilObject2GUI::WORKSPACE_NODE_ID);
61  $ilCtrl->forwardCommand($tgui);
62  break;
63 
64  case "ilobjexerciseverificationgui":
65  include_once "Modules/Exercise/classes/class.ilObjExerciseVerificationGUI.php";
67  $ilCtrl->forwardCommand($egui);
68  break;
69 
70  case "ilobjlinkresourcegui":
71  include_once "Modules/WebResource/classes/class.ilObjLinkResourceGUI.php";
72  $lgui = new ilObjLinkResourceGUI($this->node_id, ilObject2GUI::WORKSPACE_NODE_ID);
73  $ilCtrl->forwardCommand($lgui);
74  break;
75 
76  case "ilobjportfoliogui":
77  include_once "Services/Portfolio/classes/class.ilObjPortfolioGUI.php";
78  $pgui = new ilObjPortfolioGUI();
79  $ilCtrl->forwardCommand($pgui);
80  break;
81 
82  default:
83  if(!$cmd)
84  {
85  $cmd = "process";
86  }
87  $this->$cmd();
88  }
89 
90  $tpl->show();
91  }
92 
93  protected function process()
94  {
95  global $ilUser, $ilCtrl;
96 
97  if(!$this->node_id && !$this->portfolio_id)
98  {
99  exit("invalid call");
100  }
101 
102  // if already logged in, we need to re-check for public password
103  if($this->node_id)
104  {
105  if(!self::hasAccess($this->node_id))
106  {
107  exit("no permission");
108  }
109  $this->redirectToResource($this->node_id);
110  }
111  else
112  {
113  if(!self::hasAccess($this->portfolio_id, true))
114  {
115  exit("no permission");
116  }
117  $this->redirectToResource($this->portfolio_id, true);
118  }
119  }
120 
121  public static function hasAccess($a_node_id, $a_is_portfolio = false)
122  {
123  global $ilCtrl, $ilUser;
124 
125  // if we have current user - check with normal access handler
126  if($ilUser->getId() != ANONYMOUS_USER_ID)
127  {
128  if(!$a_is_portfolio)
129  {
130  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
131  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
132  $tree = new ilWorkspaceTree($ilUser->getId());
134  }
135  else
136  {
137  include_once "Services/Portfolio/classes/class.ilPortfolioAccessHandler.php";
139  }
140  if($access_handler->checkAccess("read", "", $a_node_id))
141  {
142  return true;
143  }
144  }
145 
146  // not logged in yet or no read access
147  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessGUI.php";
148 
149  if(!$a_is_portfolio)
150  {
151  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
152  $shared = ilWorkspaceAccessHandler::getPermissions($a_node_id);
153  }
154  else
155  {
156  include_once "Services/Portfolio/classes/class.ilPortfolioAccessHandler.php";
157  $shared = ilPortfolioAccessHandler::getPermissions($a_node_id);
158 
159  }
160 
161  // object is "public"
162  if(in_array(ilWorkspaceAccessGUI::PERMISSION_ALL, $shared))
163  {
164  return true;
165  }
166 
167  // password protected
168  if(in_array(ilWorkspaceAccessGUI::PERMISSION_ALL_PASSWORD, $shared))
169  {
170  if(!$a_is_portfolio)
171  {
172  ilUtil::redirect("ilias.php?baseClass=ilSharedResourceGUI&cmd=passwordForm&wsp_id=".$a_node_id);
173  }
174  else
175  {
176  ilUtil::redirect("ilias.php?baseClass=ilSharedResourceGUI&cmd=passwordForm&prt_id=".$a_node_id);
177  }
178  }
179 
180  return false;
181  }
182 
183  protected function redirectToResource($a_node_id, $a_is_portfolio = false)
184  {
185  global $ilCtrl, $objDefinition, $ilUser;
186 
187  if(!$a_is_portfolio)
188  {
189  $object_data = $this->getObjectDataFromNode($a_node_id);
190  if(!$object_data["obj_id"])
191  {
192  exit("invalid object");
193  }
194  }
195  else
196  {
197  if(!ilObject::_lookupType($a_node_id, false))
198  {
199  exit("invalid object");
200  }
201  $object_data["obj_id"] = $a_node_id;
202  $object_data["type"] = "prtf";
203  }
204 
205  $class = $objDefinition->getClassName($object_data["type"]);
206  $gui = "ilobj".$class."gui";
207 
208  switch($object_data["type"])
209  {
210  case "blog":
211  $ilCtrl->setParameterByClass($gui, "wsp_id", $a_node_id);
212  $ilCtrl->setParameterByClass($gui, "gtp", $_GET["gtp"]);
213  $ilCtrl->redirectByClass($gui, "preview");
214 
215  case "tstv":
216  case "excv":
217  $ilCtrl->setParameterByClass($gui, "wsp_id", $a_node_id);
218  $ilCtrl->redirectByClass($gui, "deliver");
219 
220  case "file":
221  case "webr":
222  $ilCtrl->setParameterByClass($gui, "wsp_id", $a_node_id);
223  $ilCtrl->redirectByClass($gui);
224 
225  case "prtf":
226  $ilCtrl->setParameterByClass($gui, "prt_id", $a_node_id);
227  $ilCtrl->redirectByClass($gui, "preview");
228 
229  default:
230  exit("invalid object type");
231  }
232  }
233 
234  protected function getObjectDataFromNode($a_node_id)
235  {
236  global $ilDB;
237 
238  $set = $ilDB->query("SELECT obj.obj_id, obj.type, obj.title".
239  " FROM object_reference_ws ref".
240  " JOIN tree_workspace tree ON (tree.child = ref.wsp_id)".
241  " JOIN object_data obj ON (ref.obj_id = obj.obj_id)".
242  " WHERE ref.wsp_id = ".$ilDB->quote($a_node_id, "integer"));
243  return $ilDB->fetchAssoc($set);
244  }
245 
246  protected function passwordForm($form = null)
247  {
248  global $tpl, $lng;
249 
250  $lng->loadLanguageModule("wsp");
251 
252  $tpl->setTitle($lng->txt("wsp_password_protected_resource"));
253  $tpl->setDescription($lng->txt("wsp_password_protected_resource_info"));
254 
255  if(!$form)
256  {
257  $form = $this->initPasswordForm();
258  }
259 
260  $tpl->setContent($form->getHTML());
261  }
262 
263  protected function initPasswordForm()
264  {
265  global $ilCtrl, $lng, $ilUser, $ilTabs;
266 
267  if($this->node_id)
268  {
269  $object_data = $this->getObjectDataFromNode($this->node_id);
270  }
271  else
272  {
273  $object_data["title"] = ilObject::_lookupTitle($this->portfolio_id);
274  }
275 
276  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
277  $form = new ilPropertyFormGUI();
278  $form->setFormAction($ilCtrl->getFormAction($this, "checkPassword"));
279  $form->setTitle($lng->txt("wsp_password_for").": ".$object_data["title"]);
280 
281  $password = new ilPasswordInputGUI($lng->txt("password"), "password");
282  $password->setRetype(false);
283  $password->setRequired(true);
284  $form->addItem($password);
285 
286  $form->addCommandButton("checkPassword", $lng->txt("submit"));
287 
288  if($ilUser->getId() && $ilUser->getId() != ANONYMOUS_USER_ID)
289  {
290  $ilTabs->setBackTarget($lng->txt("back"), $ilCtrl->getLinkTarget($this, "cancelPassword"));
291  $form->addCommandButton("cancelPassword", $lng->txt("cancel"));
292  }
293 
294  return $form;
295  }
296 
297  protected function cancelPassword()
298  {
299  global $ilUser;
300 
301  if($ilUser->getId() && $ilUser->getId() != ANONYMOUS_USER_ID)
302  {
303  if($this->node_id)
304  {
305  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
306  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
307  $tree = new ilWorkspaceTree($ilUser->getId());
308  $owner = $tree->lookupOwner($this->node_id);
309  ilUtil::redirect("ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToWorkspace&dsh=".$owner);
310  }
311  else
312  {
313  include_once "Services/Portfolio/classes/class.ilObjPortfolio.php";
314  $prtf = new ilObjPortfolio($this->portfolio_id, false);
315  $owner = $prtf->getOwner();
316  ilUtil::redirect("ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToPortfolio&dsh=".$owner);
317  }
318  }
319  }
320 
321  protected function checkPassword()
322  {
323  global $ilDB, $lng;
324 
325  $lng->loadLanguageModule("wsp");
326 
327  $form = $this->initPasswordForm();
328  if($form->checkInput())
329  {
330  $input = md5($form->getInput("password"));
331  if($this->node_id)
332  {
333  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
334  $password = ilWorkspaceAccessHandler::getSharedNodePassword($this->node_id);
335  }
336  else
337  {
338  include_once "Services/Portfolio/classes/class.ilPortfolioAccessHandler.php";
339  $password = ilPortfolioAccessHandler::getSharedNodePassword($this->portfolio_id);
340  }
341  if($input == $password)
342  {
343  if($this->node_id)
344  {
346  $this->redirectToResource($this->node_id);
347  }
348  else
349  {
350  ilPortfolioAccessHandler::keepSharedSessionPassword($this->portfolio_id, $input);
351  $this->redirectToResource($this->portfolio_id, true);
352  }
353  }
354  else
355  {
356  $item = $form->getItemByPostVar("password");
357  $item->setAlert($lng->txt("wsp_invalid_password"));
358  ilUtil::sendFailure($lng->txt("form_input_not_valid"));
359  }
360  }
361 
362  $form->setValuesByPost();
363  $this->passwordForm($form);
364  }
365 }
366 
367 ?>