ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilWorkspaceAccessGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
16 {
17  protected $ctrl;
18  protected $lng;
19  protected $node_id;
20  protected $access_handler;
21  protected $footer;
22 
25  const PERMISSION_ALL = -5;
26 
27 
28  function __construct($a_node_id, $a_access_handler, $a_is_portfolio = false, $a_footer = null)
29  {
30  global $ilCtrl, $lng;
31 
32  $this->ctrl = $ilCtrl;
33  $this->lng = $lng;
34  $this->node_id = $a_node_id;
35  $this->access_handler = $a_access_handler;
36  $this->is_portfolio = (bool)$a_is_portfolio;
37  $this->footer = $a_footer;
38  }
39 
40  function executeCommand()
41  {
42  global $ilTabs, $tpl;
43 
44  $next_class = $this->ctrl->getNextClass($this);
45  $cmd = $this->ctrl->getCmd();
46 
47  switch($next_class)
48  {
49  case "ilmailsearchcoursesgui";
50  $ilTabs->setBackTarget($this->lng->txt("back"),
51  $this->ctrl->getLinkTarget($this, "share"));
52  include_once('Services/Contact/classes/class.ilMailSearchCoursesGUI.php');
53  $csearch = new ilMailSearchCoursesGUI($this->access_handler, $this->node_id);
54  $this->ctrl->setReturn($this, 'share');
55  $this->ctrl->forwardCommand($csearch);
56 
57  $this->setObjectTitle();
58  break;
59 
60  case "ilmailsearchgroupsgui";
61  $ilTabs->setBackTarget($this->lng->txt("back"),
62  $this->ctrl->getLinkTarget($this, "share"));
63  include_once('Services/Contact/classes/class.ilMailSearchGroupsGUI.php');
64  $gsearch = new ilMailSearchGroupsGUI($this->access_handler, $this->node_id);
65  $this->ctrl->setReturn($this, 'share');
66  $this->ctrl->forwardCommand($gsearch);
67 
68  $this->setObjectTitle();
69  break;
70 
71  case "ilmailsearchgui";
72  $ilTabs->setBackTarget($this->lng->txt("back"),
73  $this->ctrl->getLinkTarget($this, "share"));
74  include_once('Services/Contact/classes/class.ilMailSearchGUI.php');
75  $usearch = new ilMailSearchGUI($this->access_handler, $this->node_id);
76  $this->ctrl->setReturn($this, 'share');
77  $this->ctrl->forwardCommand($usearch);
78 
79  $this->setObjectTitle();
80  break;
81 
82  case "ilpublicuserprofilegui";
83  $ilTabs->clearTargets();
84  $ilTabs->setBackTarget($this->lng->txt("back"),
85  $this->ctrl->getLinkTarget($this, "share"));
86 
87  include_once('./Services/User/classes/class.ilPublicUserProfileGUI.php');
88  $prof = new ilPublicUserProfileGUI($_REQUEST["user"]);
89  $prof->setBackUrl($this->ctrl->getLinkTarget($this, "share"));
90  $tpl->setContent($prof->getHTML());
91  break;
92 
93  default:
94  // $this->prepareOutput();
95  if(!$cmd)
96  {
97  $cmd = "share";
98  }
99  return $this->$cmd();
100  }
101 
102  return true;
103  }
104 
110  protected function setObjectTitle()
111  {
112  global $tpl;
113 
114  if(!$this->is_portfolio)
115  {
116  $obj_id = $this->access_handler->getTree()->lookupObjectId($this->node_id);
117  }
118  else
119  {
120  $obj_id = $this->node_id;
121  }
122  $tpl->setTitle(ilObject::_lookupTitle($obj_id));
123  }
124 
125  protected function getAccessHandler()
126  {
127  return $this->access_handler;
128  }
129 
130  protected function share()
131  {
132  global $ilToolbar, $tpl, $ilUser, $ilSetting;
133 
134  $options = array();
135  $options["user"] = $this->lng->txt("wsp_set_permission_single_user");
136 
137  include_once 'Modules/Group/classes/class.ilGroupParticipants.php';
138  $grp_ids = ilGroupParticipants::_getMembershipByType($ilUser->getId(), 'grp');
139  if(sizeof($grp_ids))
140  {
141  $options["group"] = $this->lng->txt("wsp_set_permission_group");
142  }
143 
144  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
145  $crs_ids = ilCourseParticipants::_getMembershipByType($ilUser->getId(), 'crs');
146  if(sizeof($crs_ids))
147  {
148  $options["course"] = $this->lng->txt("wsp_set_permission_course");
149  }
150 
151  if(!$this->getAccessHandler()->hasRegisteredPermission($this->node_id))
152  {
153  $options["registered"] = $this->lng->txt("wsp_set_permission_registered");
154  }
155 
156  if($ilSetting->get("enable_global_profiles"))
157  {
158  if(!$this->getAccessHandler()->hasGlobalPasswordPermission($this->node_id))
159  {
160  $options["password"] = $this->lng->txt("wsp_set_permission_all_password");
161  }
162 
163  if(!$this->getAccessHandler()->hasGlobalPermission($this->node_id))
164  {
165  $options["all"] = $this->lng->txt("wsp_set_permission_all");
166  }
167  }
168 
169  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
170  $actions = new ilSelectInputGUI("", "action");
171  $actions->setOptions($options);
172  $ilToolbar->addInputItem($actions);
173 
174  $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
175  $ilToolbar->addFormButton($this->lng->txt("add"), "addpermissionhandler");
176 
177  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessTableGUI.php";
178  $table = new ilWorkspaceAccessTableGUI($this, "share", $this->node_id, $this->getAccessHandler());
179  $tpl->setContent($table->getHTML().$this->footer);
180  }
181 
182  public function addPermissionHandler()
183  {
184  switch($_REQUEST["action"])
185  {
186  case "user":
187  $this->ctrl->setParameterByClass("ilmailsearchgui", "ref", "wsp");
188  $this->ctrl->redirectByClass("ilmailsearchgui");
189 
190  case "group":
191  $this->ctrl->setParameterByClass("ilmailsearchgroupsgui", "ref", "wsp");
192  $this->ctrl->redirectByClass("ilmailsearchgroupsgui");
193 
194  case "course":
195  $this->ctrl->setParameterByClass("ilmailsearchcoursesgui", "ref", "wsp");
196  $this->ctrl->redirectByClass("ilmailsearchcoursesgui");
197 
198  case "registered":
199  $this->getAccessHandler()->addPermission($this->node_id, self::PERMISSION_REGISTERED);
200  ilUtil::sendSuccess($this->lng->txt("wsp_permission_registered_info"), true);
201  $this->ctrl->redirect($this, "share");
202 
203  case "password":
204  $this->showPasswordForm();
205  break;
206 
207  case "all":
208  $this->getAccessHandler()->addPermission($this->node_id, self::PERMISSION_ALL);
209  ilUtil::sendSuccess($this->lng->txt("wsp_permission_all_info"), true);
210  $this->ctrl->redirect($this, "share");
211  }
212  }
213 
214  public function removePermission()
215  {
216  if($_REQUEST["obj_id"])
217  {
218  $this->getAccessHandler()->removePermission($this->node_id, (int)$_REQUEST["obj_id"]);
219  ilUtil::sendSuccess($this->lng->txt("wsp_permission_removed"), true);
220  }
221 
222  $this->ctrl->redirect($this, "share");
223  }
224 
225  protected function initPasswordForm()
226  {
227  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
228  $form = new ilPropertyFormGUI();
229  $form->setFormAction($this->ctrl->getFormAction($this));
230  $form->setTitle($this->lng->txt("wsp_set_permission_all_password"));
231 
232  $password = new ilPasswordInputGUI($this->lng->txt("password"), "password");
233  $password->setRequired(true);
234  $form->addItem($password);
235 
236  $form->addCommandButton('savepasswordform', $this->lng->txt("save"));
237  $form->addCommandButton('share', $this->lng->txt("cancel"));
238 
239  return $form;
240  }
241 
242  protected function showPasswordForm(ilPropertyFormGUI $a_form = null)
243  {
244  global $tpl;
245 
246  if(!$a_form)
247  {
248  $a_form = $this->initPasswordForm();
249  }
250  $tpl->setContent($a_form->getHTML());
251  }
252 
253  protected function savePasswordForm()
254  {
255  $form = $this->initPasswordForm();
256  if($form->checkInput())
257  {
258  $this->getAccessHandler()->addPermission($this->node_id,
259  self::PERMISSION_ALL_PASSWORD, md5($form->getInput("password")));
260  ilUtil::sendSuccess($this->lng->txt("wsp_permission_all_info"), true);
261  $this->ctrl->redirect($this, "share");
262  }
263 
264  $form->setValuesByPost();
265  $this->showPasswordForm($form);
266  }
267 }
268 
269 ?>