ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilUserStartingPointGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2016 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
14 {
15  protected $log;
16  protected $lng;
17  protected $tpl;
18  protected $parent_ref_id;
19 
24  public function __construct($a_parent_ref_id)
25  {
26  global $lng,$tpl,$ilToolbar, $ilCtrl;
27 
28  $this->log = ilLoggerFactory::getLogger("user");
29  $this->lng = $lng;
30  $this->tpl = $tpl;
31  $this->toolbar = $ilToolbar;
32  $this->ctrl = $ilCtrl;
33  $this->parent_ref_id = $a_parent_ref_id;
34  $this->lng->loadLanguageModule("administration");
35  }
36  public function &executeCommand()
37  {
38  global $ilCtrl;
39 
40  $cmd = $ilCtrl->getCmd();
41  if ($cmd == "roleStartingPointform" || !$cmd) {
42  $cmd = "initRoleStartingPointForm";
43  }
44 
45  $this->$cmd();
46 
47  return true;
48  }
49 
53  public function startingPoints()
54  {
55  include_once "Services/User/classes/class.ilUserRoleStartingPointTableGUI.php";
56 
57  require_once "./Services/AccessControl/classes/class.ilStartingPoint.php";
59 
60  if (!empty($roles_without_point)) {
61  $this->toolbar->addButton(
62  $this->lng->txt('create_starting_point'),
63  $this->ctrl->getLinkTarget($this, "roleStartingPointform")
64  );
65  } else {
66  ilUtil::sendInfo($this->lng->txt("all_roles_has_starting_point"));
67  }
68 
69 
71 
72  $this->tpl->setContent($tbl->getHTML());
73  }
74 
76  {
77  if (!($form instanceof ilPropertyFormGUI)) {
79  }
80  $this->tpl->setContent($form->getHTML());
81  }
82 
84  {
85  if (!($form instanceof ilPropertyFormGUI)) {
87  }
88  $this->tpl->setContent($form->getHTML());
89  }
90 
91  protected function getUserStartingPointForm()
92  {
93  global $ilCtrl;
94 
95  require_once("Services/Form/classes/class.ilPropertyFormGUI.php");
96  require_once "Services/User/classes/class.ilUserUtil.php";
97 
98  $form = new ilPropertyFormGUI();
99 
100  // starting point: personal
101  $startp = new ilCheckboxInputGUI($this->lng->txt("user_chooses_starting_page"), "usr_start_pers");
102  $startp->setInfo($this->lng->txt("adm_user_starting_point_personal_info"));
103  $startp->setChecked(ilUserUtil::hasPersonalStartingPoint());
104 
105  $form->addItem($startp);
106 
107  $form->addCommandButton("saveUserStartingPoint", $this->lng->txt("save"));
108  $form->setFormAction($ilCtrl->getFormAction($this));
109 
110  return $form;
111  }
112 
116  protected function getRoleStartingPointForm()
117  {
118  global $ilCtrl, $rbacsystem, $ilErr;
119 
120  if (!$rbacsystem->checkAccess("write", $this->parent_ref_id)) {
121  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
122  }
123 
124  require_once "Services/Form/classes/class.ilPropertyFormGUI.php";
125  require_once "./Services/AccessControl/classes/class.ilObjRole.php";
126  require_once "./Services/AccessControl/classes/class.ilStartingPoint.php";
127  include_once "Services/User/classes/class.ilUserUtil.php";
128 
129  $form = new ilPropertyFormGUI();
130  $ilCtrl->saveParameter($this, array("spid"));
131 
132  $spoint_id = $_REQUEST['spid'];
133 
134  //edit no default
135  if ($spoint_id > 0 && $spoint_id != 'default') {
136  $st_point = new ilStartingPoint($spoint_id);
137 
138  //starting point role based
139  if ($st_point->getRuleType() == ilStartingPoint::ROLE_BASED && $_REQUEST['rolid']) {
140  $rolid = (int) $_REQUEST['rolid'];
141  if ($role = new ilObjRole($rolid)) {
142  $options[$rolid] = $role->getTitle();
143  $starting_point = $st_point->getStartingPoint();
144  $si_roles = new ilSelectInputGUI($this->lng->txt("editing_this_role"), 'role_disabled');
145  $si_roles->setOptions($options);
146  $si_roles->setDisabled(true);
147  $form->addItem($si_roles);
148 
149  $hi = new ilHiddenInputGUI("role");
150  $hi->setValue($rolid);
151  $form->addItem($hi);
152 
153  $hidde_sp_id = new ilHiddenInputGUI("start_point_id");
154  $hidde_sp_id->setValue($spoint_id);
155  $form->addItem($hidde_sp_id);
156  }
157  }
158  }
159  //create
160  elseif (!$spoint_id || $spoint_id !='default') {
161  //starting point role based
164 
165  foreach ($roles as $role) {
166  $options[$role['id']] = $role['title'];
167  }
168  $si_roles = new ilSelectInputGUI($this->lng->txt("roles_without_starting_point"), 'role');
169  $si_roles->setOptions($options);
170  $form->addItem($si_roles);
171  }
172  } else {
173  $starting_point = ilUserUtil::getStartingPoint();
174  }
175 
176  // starting point
177 
178  $si = new ilRadioGroupInputGUI($this->lng->txt("adm_user_starting_point"), "start_point");
179  $si->setRequired(true);
180  $si->setInfo($this->lng->txt("adm_user_starting_point_info"));
182  foreach (ilUserUtil::getPossibleStartingPoints(true) as $value => $caption) {
183  $opt = new ilRadioOption($caption, $value);
184  $si->addOption($opt);
185 
186  if (!in_array($value, $valid)) {
187  $opt->setInfo($this->lng->txt("adm_user_starting_point_invalid_info"));
188  }
189  }
190  $si->setValue($starting_point);
191  $form->addItem($si);
192 
193  // starting point: repository object
194  $repobj = new ilRadioOption($this->lng->txt("adm_user_starting_point_object"), ilUserUtil::START_REPOSITORY_OBJ);
195  $repobj_id = new ilTextInputGUI($this->lng->txt("adm_user_starting_point_ref_id"), "start_object");
196  $repobj_id->setRequired(true);
197  $repobj_id->setSize(5);
198  //$i has the starting_point value, so we are here only when edit one role or setting the default role.
199  if ($si->getValue() == ilUserUtil::START_REPOSITORY_OBJ) {
200  if ($st_point) {
201  $start_ref_id = $st_point->getStartingObject();
202  } else {
203  $start_ref_id = ilUserUtil::getStartingObject();
204  }
205 
206  $repobj_id->setValue($start_ref_id);
207  if ($start_ref_id) {
208  $start_obj_id = ilObject::_lookupObjId($start_ref_id);
209  if ($start_obj_id) {
210  $repobj_id->setInfo($this->lng->txt("obj_" . ilObject::_lookupType($start_obj_id)) .
211  ": " . ilObject::_lookupTitle($start_obj_id));
212  }
213  }
214  }
215  $repobj->addSubItem($repobj_id);
216  $si->addOption($repobj);
217 
218  // save and cancel commands
219  $form->addCommandButton("saveStartingPoint", $this->lng->txt("save"));
220  $form->addCommandButton("startingPoints", $this->lng->txt("cancel"));
221 
222  $form->setTitle($this->lng->txt("starting_point_settings"));
223  $form->setFormAction($ilCtrl->getFormAction($this));
224 
225  return $form;
226  }
227 
228  protected function saveUserStartingPoint()
229  {
230  global $ilCtrl, $rbacsystem, $ilErr;
231 
232  if (!$rbacsystem->checkAccess("write", $this->parent_ref_id)) {
233  $ilErr->raiseError($this->lng->txt("msg_no_perm_read"), $ilErr->FATAL);
234  }
235 
236  include_once "Services/User/classes/class.ilUserUtil.php";
237 
238  $form = $this->getUserStartingPointForm();
239 
240  if ($form->checkInput()) {
241  ilUserUtil::togglePersonalStartingPoint($form->getInput('usr_start_pers'));
242  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
243  $ilCtrl->redirect($this, "startingPoints");
244  }
245  ilUtil::sendFailure($this->lng->txt("msg_error"), true);
246  $ilCtrl->redirect($this, "startingPoints");
247  }
248 
252  protected function saveStartingPoint()
253  {
254  global $ilCtrl, $tree, $rbacsystem, $ilErr, $tpl;
255 
256  if (!$rbacsystem->checkAccess("write", $this->parent_ref_id)) {
257  $ilErr->raiseError($this->lng->txt("msg_no_perm_read"), $ilErr->FATAL);
258  }
259 
260  if ((int) $_POST['start_point_id'] > 0) {
261  $start_point_id = (int) $_POST['start_point_id'];
262  }
263 
264  //add from form
265  $form = $this->getRoleStartingPointForm();
266  if ($form->checkInput()) {
267  //if role
268  if ($form->getInput('role')) {
269 
270  //create starting point
271  if ($start_point_id) {
272  $starting_point = new ilStartingPoint($start_point_id);
273  } else { //edit
274  $starting_point = new ilStartingPoint();
275  }
276  $starting_point->setRuleType(ilStartingPoint::ROLE_BASED);
277  $starting_point->setStartingPoint($form->getInput("start_point"));
278  $rules = array("role_id" => $form->getInput('role'));
279  $starting_point->setRuleOptions(serialize($rules));
280 
281  $obj_id = $form->getInput('start_object');
282  if ($obj_id && ($starting_point->getStartingPoint() == ilUserUtil::START_REPOSITORY_OBJ)) {
283  if (ilObject::_lookupObjId($obj_id) && !$tree->isDeleted($obj_id)) {
284  $starting_point->setStartingObject($obj_id);
285  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
286  } else {
287  ilUtil::sendFailure($this->lng->txt("obj_ref_id_not_exist"), true);
288  }
289  } else {
290  $starting_point->setStartingObject(0);
291  }
292 
293  if ($start_point_id) {
294  $starting_point->update();
295  } else {
296  $starting_point->save();
297  }
298  } else { //default
299  ilUserUtil::setStartingPoint($form->getInput('start_point'), $form->getInput('start_object'));
300  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
301  }
302 
303  $ilCtrl->redirect($this, "startingPoints");
304  }
305  $tpl->setContent($form->getHTML());
306 
307  //$ilCtrl->redirect($this, "startingPoints");
308  }
309 
310  public function saveOrder()
311  {
312  global $ilCtrl, $rbacsystem, $ilErr;
313 
314  if (!$rbacsystem->checkAccess("write", $this->parent_ref_id)) {
315  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
316  }
317 
318  if ($_POST['position']) {
319  require_once "./Services/AccessControl/classes/class.ilStartingPoint.php";
320 
321  $sp = new ilStartingPoint();
322  $sp->saveOrder($_POST['position']);
323  }
324 
325  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
326  $ilCtrl->redirect($this, "startingPoints");
327  }
328 
332  public function confirmDeleteStartingPoint()
333  {
334  global $ilCtrl, $lng, $tpl, $ilTabs;
335 
336  $ilTabs->clearTargets();
337  $ilTabs->setBackTarget($lng->txt('back_to_starting_points_list'), $ilCtrl->getLinkTarget($this, 'startingPoints'));
338 
339  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
340  $conf = new ilConfirmationGUI();
341  $conf->setFormAction($ilCtrl->getFormAction($this));
342  $conf->setHeaderText($lng->txt('confirm_delete_starting_point'));
343 
344  //if type role based
345  if ($_REQUEST['rolid'] && $_REQUEST['spid']) {
346  include_once "./Services/AccessControl/classes/class.ilObjRole.php";
347 
348  $rolid = (int) $_REQUEST['rolid'];
349  $spid = (int) $_REQUEST['spid'];
350 
351  $role = new ilObjRole($rolid);
352 
353  $conf->addItem('rolid', $rolid, $role->getTitle());
354  $conf->addItem('spid', $spid, "");
355  }
356 
357  $conf->setConfirm($lng->txt('delete'), 'deleteStartingPoint');
358  $conf->setCancel($lng->txt('cancel'), 'startingPoints');
359 
360  $tpl->setContent($conf->getHTML());
361  }
362 
366  protected function deleteStartingPoint()
367  {
368  global $ilCtrl, $rbacsystem, $ilErr;
369 
370  if (!$rbacsystem->checkAccess("write", $this->parent_ref_id)) {
371  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
372  }
373 
374  require_once "./Services/AccessControl/classes/class.ilObjRole.php";
375 
376  if ($rolid = $_REQUEST['rolid'] && $spid = $_REQUEST['spid']) {
377  include_once("./Services/AccessControl/classes/class.ilStartingPoint.php");
378  $sp = new ilStartingPoint($spid);
379  $sp->delete();
380  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
381  } else {
382  ilUtil::sendFailure($this->lng->txt("msg_spoint_not_modified"), true);
383  }
384  $ilCtrl->redirect($this, "startingPoints");
385  }
386 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
Class ilObjRole.
global $ilErr
Definition: raiseError.php:16
This class represents an option in a radio group.
This class represents a selection list property in a property form.
This class represents a property form user interface.
$tbl
Definition: example_048.php:81
Class ilStartingPoint.
saveStartingPoint()
store starting point from the form
$valid
TableGUI class for LTI consumer listing.
This class represents a checkbox property in a property form.
static _lookupTitle($a_id)
lookup object title
static getGlobalRolesWithoutStartingPoint()
Get id and title of the roles without starting points.
static getStartingPoint()
Get current starting point setting.
setInfo($a_info)
Set Info.
static hasPersonalStartingPoint()
Can starting point be personalized?
initRoleStartingPointForm(ilPropertyFormGUI $form=null)
global $ilCtrl
Definition: ilias.php:18
static getPossibleStartingPoints($a_force_all=false)
Get all valid starting points.
setInfo($a_info)
Set Information Text.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
This class represents a hidden form property in a property form.
startingPoints()
table form to set up starting points depends of user roles
This class represents a property in a property form.
setValue($a_value)
Set Value.
confirmDeleteStartingPoint()
Confirm delete starting point.
if(isset($_POST['submit'])) $form
initUserStartingPointForm(ilPropertyFormGUI $form=null)
Class ilUserStartingPointGUI.
static _lookupObjId($a_id)
static getStartingObject()
Get ref id of starting object.
This class represents a text property in a property form.
setOptions($a_options)
Set Options.
deleteStartingPoint()
Set to 0 the starting point values.
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
const START_REPOSITORY_OBJ
static getLogger($a_component_id)
Get component logger.
__construct($a_parent_ref_id)
Constructor public.
static setStartingPoint($a_value, $a_ref_id=null)
Set starting point setting.
static togglePersonalStartingPoint($a_value)
Toggle personal starting point setting.
$_POST["username"]
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
Confirmation screen class.