ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjWorkspaceFolderGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once "./Services/Object/classes/class.ilObject2GUI.php";
6 
18 {
19  function getType()
20  {
21  return "wfld";
22  }
23 
24  function setTabs($a_show_settings = true)
25  {
26  global $lng, $ilHelp;
27 
28  $ilHelp->setScreenIdComponent("wfld");
29 
30  $this->ctrl->setParameter($this,"wsp_id",$this->node_id);
31 
32  $this->tabs_gui->addTab("wsp", $lng->txt("wsp_tab_personal"),
33  $this->ctrl->getLinkTarget($this, ""));
34 
35  $this->ctrl->setParameterByClass("ilObjWorkspaceRootFolderGUI", "wsp_id",
36  $this->getAccessHandler()->getTree()->getRootId());
37 
38  $this->tabs_gui->addTab("share", $lng->txt("wsp_tab_shared"),
39  $this->ctrl->getLinkTargetByClass("ilObjWorkspaceRootFolderGUI", "share"));
40 
41  $this->tabs_gui->addTab("ownership", $lng->txt("wsp_tab_ownership"),
42  $this->ctrl->getLinkTargetByClass(array("ilObjWorkspaceRootFolderGUI", "ilObjectOwnershipManagementGUI"), "listObjects"));
43 
44  if(!$this->ctrl->getNextClass($this))
45  {
46  if(stristr($this->ctrl->getCmd(), "share"))
47  {
48  $this->tabs_gui->activateTab("share");
49  }
50  else
51  {
52  $this->tabs_gui->activateTab("wsp");
53 
54  if($a_show_settings)
55  {
56  if ($this->checkPermissionBool("read"))
57  {
58  $this->tabs_gui->addSubTab("content",
59  $lng->txt("content"),
60  $this->ctrl->getLinkTarget($this, ""));
61  }
62 
63  if ($this->checkPermissionBool("write"))
64  {
65  $this->tabs_gui->addSubTab("settings",
66  $lng->txt("settings"),
67  $this->ctrl->getLinkTarget($this, "edit"));
68  }
69  }
70  }
71  }
72  }
73 
74  function &executeCommand()
75  {
76  $next_class = $this->ctrl->getNextClass($this);
77  $cmd = $this->ctrl->getCmd();
78 
79  switch($next_class)
80  {
81  case "ilcommonactiondispatchergui":
82  include_once("Services/Object/classes/class.ilCommonActionDispatcherGUI.php");
84  $this->ctrl->forwardCommand($gui);
85  break;
86 
87  case "ilobjectownershipmanagementgui":
88  $this->prepareOutput();
89  $this->tabs_gui->activateTab("ownership");
90  include_once("Services/Object/classes/class.ilObjectOwnershipManagementGUI.php");
91  $gui = new ilObjectOwnershipManagementGUI();
92  $this->ctrl->forwardCommand($gui);
93  break;
94 
95  default:
96  $this->prepareOutput();
97  if($this->type != "wsrt")
98  {
99  $this->addHeaderAction();
100  }
101  if(!$cmd)
102  {
103  $cmd = "render";
104  }
105  $this->$cmd();
106  break;
107  }
108 
109  return true;
110  }
111 
112  protected function initCreationForms($a_new_type)
113  {
114  $forms = array(
115  self::CFORM_NEW => $this->initCreateForm($a_new_type)
116  );
117 
118  return $forms;
119  }
120 
124  function render()
125  {
126  global $tpl, $ilUser, $ilTabs;
127 
128  unset($_SESSION['clipboard']['wsp2repo']);
129 
130  include_once "Services/Object/classes/class.ilObjectListGUI.php";
132  $this->ctrl->getLinkTargetByClass(array("ilcommonactiondispatchergui", "ilnotegui"), "", "", true, false),
133  $this->ctrl->getLinkTargetByClass(array("ilcommonactiondispatchergui", "iltagginggui"), "", "", true, false));
134 
135  include_once "Modules/WorkspaceFolder/classes/class.ilObjWorkspaceFolderTableGUI.php";
136  $table = new ilObjWorkspaceFolderTableGUI($this, "render", $this->node_id, $this->getAccessHandler());
137  $tpl->setContent($table->getHTML());
138 
139  include_once "Modules/WorkspaceFolder/classes/class.ilWorkspaceFolderExplorer.php";
140  $exp = new ilWorkspaceFolderExplorer($this->ctrl->getLinkTarget($this), $ilUser->getId());
141 
142  if($this->node_id != $exp->getRoot())
143  {
144  $ilTabs->activateSubTab("content");
145  }
146 
147  $left = "";
148 
149  // sub-folders
150  if($this->node_id != $exp->getRoot() || $exp->hasFolders($this->node_id))
151  {
152  $exp->setTargetGet("wsp_id");
153  $exp->setSessionExpandVariable('wspexpand');
154  $exp->setExpand($this->node_id);
155  $exp->setExpandTarget($this->ctrl->getLinkTarget($this));
156 
157  if ($_GET["wspexpand"] != "")
158  {
159  $exp->setExpand($_GET["wspexpand"]);
160  }
161 
162  $exp->highlightNode($this->node_id);
163  $exp->setOutput(0);
164 
165  $left .= $exp->getOutput();
166  }
167 
168  $tpl->setLeftNavContent($left);
169  }
170 
171  function edit()
172  {
173  parent::edit();
174 
175  $this->tabs_gui->activateTab("wsp");
176  $this->tabs_gui->activateSubTab("settings");
177  }
178 
179  function update()
180  {
181  parent::update();
182 
183  $this->tabs_gui->activateTab("wsp");
184  $this->tabs_gui->activateSubTab("settings");
185  }
186 
192  function cut()
193  {
194  if (!$_REQUEST["item_ref_id"])
195  {
196  ilUtil::sendFailure($this->lng->txt("no_checkbox"), true);
197  $this->ctrl->redirect($this);
198  }
199 
200  $current_node = $_REQUEST["item_ref_id"];
201  $parent_node = $this->tree->getParentId($current_node);
202 
203  // on cancel or fail we return to parent node
204  $this->ctrl->setParameter($this, "wsp_id", $parent_node);
205 
206  // check permission
207  $no_cut = array();
208  foreach ($this->tree->getSubTree($this->tree->getNodeData($current_node)) as $node)
209  {
210  if (!$this->checkPermissionBool("delete", "", "", $node["wsp_id"]))
211  {
212  $obj = ilObjectFactory::getInstanceByObjId($node["obj_id"]);
213  $no_cut[$node["wsp_id"]] = $obj->getTitle();
214  unset($obj);
215  }
216  }
217  if (count($no_cut))
218  {
219  ilUtil::sendFailure($this->lng->txt("msg_no_perm_cut")." ".implode(',', $no_cut), true);
220  $this->ctrl->redirect($this);
221  }
222 
223  // open current position
224  // using the explorer session storage directly is basically a hack
225  // as we do not use setExpanded() [see below]
226  $_SESSION['paste_cut_wspexpand'] = array();
227  foreach((array)$this->tree->getPathId($parent_node) as $node_id)
228  {
229  $_SESSION['paste_cut_wspexpand'][] = $node_id;
230  }
231 
232  // remember source node
233  $_SESSION['clipboard']['source_id'] = $current_node;
234  $_SESSION['clipboard']['cmd'] = 'cut';
235 
236  return $this->showMoveIntoObjectTree();
237  }
238 
245  {
246  $_SESSION['clipboard']['wsp2repo'] = true;
247  $this->cut();
248  }
249 
255  function copy()
256  {
257  global $ilUser;
258 
259  if (!$_REQUEST["item_ref_id"])
260  {
261  ilUtil::sendFailure($this->lng->txt("no_checkbox"), true);
262  $this->ctrl->redirect($this);
263  }
264 
265  $current_node = $_REQUEST["item_ref_id"];
266  $owner = $this->tree->lookupOwner($current_node);
267  if($owner == $ilUser->getId())
268  {
269  $parent_node = $this->tree->getParentId($current_node);
270 
271  // on cancel or fail we return to parent node
272  $this->ctrl->setParameter($this, "wsp_id", $parent_node);
273 
274  // open current position
275  // using the explorer session storage directly is basically a hack
276  // as we do not use setExpanded() [see below]
277  $_SESSION['paste_copy_wspexpand'] = array();
278  foreach((array)$this->tree->getPathId($parent_node) as $node_id)
279  {
280  $_SESSION['paste_copy_wspexpand'][] = $node_id;
281  }
282  }
283  else
284  {
285  // see copyShared()
286  ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
287  $this->ctrl->redirect($this);
288  }
289 
290  // remember source node
291  $_SESSION['clipboard']['source_id'] = $current_node;
292  $_SESSION['clipboard']['cmd'] = 'copy';
293 
294  return $this->showMoveIntoObjectTree();
295  }
296 
297  function copyShared()
298  {
299  if (!$_REQUEST["item_ref_id"])
300  {
301  $this->ctrl->redirect($this, "share");
302  }
303 
304  $current_node = $_REQUEST["item_ref_id"];
305  $handler = $this->getAccessHandler();
306 
307  // see ilSharedRessourceGUI::hasAccess()
308  if($handler->checkAccess("read", "", $current_node))
309  {
310  // remember source node
311  $_SESSION['clipboard']['source_id'] = $current_node;
312  $_SESSION['clipboard']['cmd'] = 'copy';
313  $_SESSION['clipboard']['shared'] = true;
314 
315  return $this->showMoveIntoObjectTree();
316  }
317  else
318  {
319  $perms = $handler->getPermissions($current_node);
321  {
322  return $this->passwordForm($current_node);
323  }
324  }
325 
326  ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
327  $this->ctrl->redirect($this, "share");
328  }
329 
336  {
337  $_SESSION['clipboard']['wsp2repo'] = true;
338  $this->copy();
339  }
340 
345  {
346  global $ilTabs, $tree;
347 
348  $ilTabs->clearTargets();
349 
350  if(!$_SESSION['clipboard']['shared'])
351  {
352  $ilTabs->setBackTarget($this->lng->txt('back'),
353  $this->ctrl->getLinkTarget($this));
354  }
355  else
356  {
357  $ilTabs->setBackTarget($this->lng->txt('back'),
358  $this->ctrl->getLinkTarget($this, 'share'));
359  }
360 
361  $mode = $_SESSION['clipboard']['cmd'];
362 
363  ilUtil::sendInfo($this->lng->txt('msg_'.$mode.'_clipboard'));
364 
365  $this->tpl->addBlockfile('ADM_CONTENT', 'adm_content',
366  'tpl.paste_into_multiple_objects.html', "Services/Object");
367 
368  // move/copy in personal workspace
369  if(!$_SESSION['clipboard']['wsp2repo'])
370  {
371  require_once 'Services/PersonalWorkspace/classes/class.ilWorkspaceExplorer.php';
373  'paste_'.$mode.'_wspexpand', $this->tree, $this->getAccessHandler());
374  $exp->setTargetGet('wsp_id');
375 
376  if($_GET['paste_'.$mode.'_wspexpand'] == '')
377  {
378  // not really used as session is already set [see above]
379  $expanded = $this->tree->readRootId();
380  }
381  else
382  {
383  $expanded = $_GET['paste_'.$mode.'_wspexpand'];
384  }
385 
386  }
387  // move/copy to repository
388  else
389  {
390  require_once './Services/Object/classes/class.ilPasteIntoMultipleItemsExplorer.php';
392  '', 'paste_'.$mode.'_repexpand');
393  $exp->setTargetGet('ref_id');
394 
395  if($_GET['paste_'.$mode.'_repexpand'] == '')
396  {
397  $expanded = $tree->readRootId();
398  }
399  else
400  {
401  $expanded = $_GET['paste_'.$mode.'_repexpand'];
402  }
403  }
404 
405  $exp->setCheckedItems(array((int)$_POST['node']));
406  $exp->setExpandTarget($this->ctrl->getLinkTarget($this, 'showMoveIntoObjectTree'));
407  $exp->setPostVar('node');
408  $exp->setExpand($expanded);
409  $exp->setOutput(0);
410 
411  $this->tpl->setVariable('OBJECT_TREE', $exp->getOutput());
412  unset($exp);
413 
414  $this->tpl->setVariable('FORM_TARGET', '_top');
415  $this->tpl->setVariable('FORM_ACTION',
416  $this->ctrl->getFormAction($this, 'performPasteIntoMultipleObjects'));
417 
418  $this->tpl->setVariable('CMD_SUBMIT', 'performPasteIntoMultipleObjects');
419  $this->tpl->setVariable('TXT_SUBMIT', $this->lng->txt('paste'));
420  }
421 
426  {
427  global $objDefinition, $tree, $ilAccess, $ilUser;
428 
429  $mode = $_SESSION['clipboard']['cmd'];
430  $source_node_id = $_SESSION['clipboard']['source_id'];
431  $target_node_id = $_REQUEST['node'];
432 
433  if(!$source_node_id)
434  {
435  ilUtil::sendFailure($this->lng->txt('select_at_least_one_object'), true);
436  $this->ctrl->redirect($this);
437  }
438  if(!$target_node_id)
439  {
440  ilUtil::sendFailure($this->lng->txt('select_at_least_one_object'), true);
441  $this->ctrl->redirect($this, "showMoveIntoObjectTree");
442  }
443 
444  // object instances
445  $source_obj_id = $this->tree->lookupObjectId($source_node_id);
446  $source_object = ilObjectFactory::getInstanceByObjId($source_obj_id);
447 
448  if(!$_SESSION['clipboard']['wsp2repo'])
449  {
450  $target_obj_id = $this->tree->lookupObjectId($target_node_id);
451  }
452  else
453  {
454  $target_obj_id = ilObject::_lookupObjId($target_node_id);
455  }
456  $target_object = ilObjectFactory::getInstanceByObjId($target_obj_id);
457 
458 
459  // sanity checks
460 
461  $fail = array();
462 
463  if($source_node_id == $target_node_id)
464  {
465  $fail[] = sprintf($this->lng->txt('msg_obj_exists_in_folder'),
466  $source_object->getTitle(), $target_object->getTitle());
467  }
468 
469  if(!in_array($source_object->getType(), array_keys($objDefinition->getSubObjects($target_object->getType()))))
470  {
471  $fail[] = sprintf($this->lng->txt('msg_obj_may_not_contain_objects_of_type'),
472  $target_object->getTitle(), $source_object->getType());
473  }
474 
475  // if object is shared permission to copy has been checked above
476  $owner = $this->tree->lookupOwner($source_node_id);
477  if($mode == "copy" && $ilUser->getId() == $owner && !$this->checkPermissionBool('copy', '', '', $source_node_id))
478  {
479  $fail[] = $this->lng->txt('permission_denied');
480  }
481 
482  if(!$_SESSION['clipboard']['wsp2repo'])
483  {
484  if($mode == "cut" && $this->tree->isGrandChild($source_node_id, $target_node_id))
485  {
486  $fail[] = sprintf($this->lng->txt('msg_paste_object_not_in_itself'),
487  $source_object->getTitle());
488  }
489 
490  if(!$this->checkPermissionBool('create', '', $source_object->getType(), $target_node_id))
491  {
492  $fail[] = sprintf($this->lng->txt('msg_no_perm_paste_object_in_folder'),
493  $source_object->getTitle(), $target_object->getTitle());
494  }
495 
496  }
497  else
498  {
499  if(!$ilAccess->checkAccess('create', '', $target_node_id, $source_object->getType()))
500  {
501  $fail[] = sprintf($this->lng->txt('msg_no_perm_paste_object_in_folder'),
502  $source_object->getTitle(), $target_object->getTitle());
503  }
504  }
505 
506  if(sizeof($fail))
507  {
508  ilUtil::sendFailure(implode("<br />", $fail), true);
509  $this->ctrl->redirect($this);
510  }
511 
512 
513  // move the node
514  if($mode == "cut")
515  {
516  if(!$_SESSION['clipboard']['wsp2repo'])
517  {
518  $this->tree->moveTree($source_node_id, $target_node_id);
519  }
520  else
521  {
522  $parent_id = $this->tree->getParentId($source_node_id);
523 
524  // remove from personal workspace
525  $this->getAccessHandler()->removePermission($source_node_id);
526  $this->tree->deleteReference($source_node_id);
527  $source_node = $this->tree->getNodeData($source_node_id);
528  $this->tree->deleteTree($source_node);
529 
530  // add to repository
531  $source_object->createReference();
532  $source_object->putInTree($target_node_id);
533  $source_object->setPermissions($target_node_id);
534 
535  $source_node_id = $parent_id;
536  }
537  }
538  // copy the node
539  else if($mode == "copy")
540  {
541  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
543  $wizard_options = ilCopyWizardOptions::_getInstance($copy_id);
544  $wizard_options->saveOwner($ilUser->getId());
545  $wizard_options->saveRoot($source_node_id);
546  $wizard_options->read();
547 
548  $new_obj = $source_object->cloneObject($target_node_id, $copy_id, !$_SESSION['clipboard']['wsp2repo']);
549 
550  // insert into workspace tree
551  if($new_obj && !$_SESSION['clipboard']['wsp2repo'])
552  {
553  $new_obj_node_id = $this->tree->insertObject($target_node_id, $new_obj->getId());
554  $this->getAccessHandler()->setPermissions($target_node_id, $new_obj_node_id);
555  }
556 
557  $wizard_options->deleteAll();
558  }
559 
560  // redirect to target if not repository
561  if(!$_SESSION['clipboard']['wsp2repo'])
562  {
563  $redirect_node = $target_node_id;
564  }
565  else
566  {
567  // reload current folder
568  $redirect_node = $this->node_id;
569  }
570 
571  unset($_SESSION['clipboard']['cmd']);
572  unset($_SESSION['clipboard']['source_id']);
573  unset($_SESSION['clipboard']['wsp2repo']);
574  unset($_SESSION['clipboard']['shared']);
575 
576  ilUtil::sendSuccess($this->lng->txt('msg_cut_copied'), true);
577  $this->ctrl->setParameter($this, "wsp_id", $redirect_node);
578  $this->ctrl->redirect($this);
579  }
580 
581  function share()
582  {
583  global $tpl, $ilToolbar;
584 
585  $users = $this->getAccessHandler()->getSharedOwners();
586 
587  // user selection
588  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
589  $si = new ilSelectInputGUI($this->lng->txt("user"), "user");
590  $si->setOptions(array(""=>"-")+$users);
591  $ilToolbar->addInputItem($si);
592 
593  $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
594  $ilToolbar->addFormButton($this->lng->txt("ok"), "share");
595 
596  if(!$_REQUEST["user"])
597  {
598  ilUtil::sendInfo($this->lng->txt("wsp_share_select_user"));
599  }
600  else
601  {
602  $si->setValue($_REQUEST["user"]);
603 
604  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceShareTableGUI.php";
605  $tbl = new ilWorkspaceShareTableGUI($this, "share", $this->getAccessHandler(), $_REQUEST["user"], $this->node_id);
606  $tpl->setContent($tbl->getHTML());
607  }
608  }
609 
610  function applyShareFilter()
611  {
612  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceShareTableGUI.php";
613  $tbl = new ilWorkspaceShareTableGUI($this, "share", $this->getAccessHandler());
614  $tbl->resetOffset();
615  $tbl->writeFilterToSession();
616 
617  $this->share();
618  }
619 
620  function resetShareFilter()
621  {
622  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceShareTableGUI.php";
623  $tbl = new ilWorkspaceShareTableGUI($this, "share", $this->getAccessHandler());
624  $tbl->resetOffset();
625  $tbl->resetFilter();
626 
627  $this->share();
628  }
629 
630  protected function passwordForm($a_node_id, $form = null)
631  {
632  global $tpl, $lng, $ilTabs;
633 
634  $tpl->setTitle($lng->txt("wsp_password_protected_resource"));
635  $tpl->setDescription($lng->txt("wsp_password_protected_resource_info"));
636 
637  $ilTabs->clearTargets();
638  $ilTabs->setBackTarget($lng->txt("back"),
639  $this->ctrl->getLinkTarget($this, "share"));
640 
641  if(!$form)
642  {
643  $form = $this->initPasswordForm($a_node_id);
644  }
645 
646  $tpl->setContent($form->getHTML());
647  }
648 
649  protected function initPasswordForm($a_node_id)
650  {
651  global $ilCtrl, $lng;
652 
653  $this->ctrl->setParameter($this, "item_ref_id", $a_node_id);
654 
655  $object_data = $this->getAccessHandler()->getObjectDataFromNode($a_node_id);
656 
657  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
658  $form = new ilPropertyFormGUI();
659  $form->setFormAction($ilCtrl->getFormAction($this, "checkPassword"));
660  $form->setTitle($lng->txt("wsp_password_for").": ".$object_data["title"]);
661 
662  $password = new ilPasswordInputGUI($lng->txt("password"), "password");
663  $password->setRetype(false);
664  $password->setRequired(true);
665  $password->setSkipSyntaxCheck(true);
666  $form->addItem($password);
667 
668  $form->addCommandButton("checkPassword", $lng->txt("submit"));
669  $form->addCommandButton("share", $lng->txt("cancel"));
670 
671  return $form;
672  }
673 
674  protected function checkPassword()
675  {
676  global $lng;
677 
678  $node_id = $_REQUEST["item_ref_id"];
679  if(!$node_id)
680  {
681  $this->ctrl->redirect($this, "share");
682  }
683 
684  $form = $this->initPasswordForm($node_id);
685  if($form->checkInput())
686  {
687  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
689  $input = md5($form->getInput("password"));
690  if($input == $password)
691  {
692  // we save password and start over
694 
695  $this->ctrl->setParameter($this, "item_ref_id", $node_id);
696  $this->ctrl->redirect($this, "copyShared");
697  }
698  else
699  {
700  $item = $form->getItemByPostVar("password");
701  $item->setAlert($lng->txt("wsp_invalid_password"));
702  ilUtil::sendFailure($lng->txt("form_input_not_valid"));
703  }
704  }
705 
706  $form->setValuesByPost();
707  $this->passwordForm($node_id, $form);
708  }
709 
715  function _goto($a_target)
716  {
717  $id = explode("_", $a_target);
718 
719  $_GET["baseClass"] = "ilsharedresourceGUI";
720  $_GET["wsp_id"] = $id[0];
721  include("ilias.php");
722  exit;
723  }
724 }
725 
726 ?>