ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilRegistrationSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 require_once './Services/Registration/classes/class.ilRegistrationSettings.php';
25 
37 {
38  var $ctrl;
39  var $tpl;
40  var $ref_id;
41 
43  {
44  global $ilCtrl,$tpl,$lng;
45 
46  $this->tpl =& $tpl;
47  $this->ctrl =& $ilCtrl;
48 
49  $this->lng =& $lng;
50  $this->lng->loadLanguageModule('administration');
51  $this->lng->loadLanguageModule('registration');
52 
53  $this->ref_id = (int) $_GET['ref_id'];
54 
55  $this->registration_settings = new ilRegistrationSettings();
56  }
57 
58  function executeCommand()
59  {
60  $next_class = $this->ctrl->getNextClass($this);
61  $cmd = $this->ctrl->getCmd();
62  switch($next_class)
63  {
64  default:
65  if(!$cmd)
66  {
67  $cmd = 'diplayForm';
68  }
69  $this->$cmd();
70  break;
71  }
72  return true;
73  }
74 
79  function setSubTabs($activeTab = 'registration_settings')
80  {
81  global $ilTabs, $lng;
82 
83  $ilTabs->addSubTab("registration_settings",
84  $lng->txt("registration_tab_settings"),
85  $this->ctrl->getLinkTarget($this, 'view'));
86 
87  $ilTabs->addSubTab("registration_codes",
88  $lng->txt("registration_tab_codes"),
89  $this->ctrl->getLinkTarget($this, 'listCodes'));
90 
91  $ilTabs->activateSubTab($activeTab);
92  }
93 
94  function initForm()
95  {
96  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
97 
98  $this->form_gui = new ilPropertyFormGUI();
99  $this->form_gui->setFormAction($this->ctrl->getFormAction($this, 'save'));
100  $this->form_gui->setTitle($this->lng->txt('reg_settings_header'));
101 
102  $reg_type = new ilRadioGroupInputGUI($this->lng->txt('reg_type'), 'reg_type');
103  $reg_type->addOption(new ilRadioOption($this->lng->txt('reg_disabled'), IL_REG_DISABLED));
104  $option = new ilRadioOption($this->lng->txt('reg_direct'), IL_REG_DIRECT);
105  $option->setInfo($this->lng->txt('reg_direct_info'));
106  $cd = new ilCheckboxInputGUI($this->lng->txt('reg_allow_codes'), 'reg_codes_'.IL_REG_DIRECT);
107  $cd->setInfo($this->lng->txt('reg_allow_codes_info'));
108  $option->addSubItem($cd);
109  $reg_type->addOption($option);
110  $option = new ilRadioOption($this->lng->txt('reg_approve'), IL_REG_APPROVE);
111  $option->setInfo($this->lng->txt('reg_approve_info'));
112  $cd = new ilCheckboxInputGUI($this->lng->txt('reg_allow_codes'), 'reg_codes_'.IL_REG_APPROVE);
113  $cd->setInfo($this->lng->txt('reg_allow_codes_info'));
114  $option->addSubItem($cd);
115  $reg_type->addOption($option);
116  $option = new ilRadioOption($this->lng->txt('reg_type_confirmation'), IL_REG_ACTIVATION);
117  $option->setInfo($this->lng->txt('reg_type_confirmation_info'));
118  $lt = new ilNumberInputGUI($this->lng->txt('reg_confirmation_hash_life_time'), 'reg_hash_life_time');
119  $lt->setSize(5);
120  $lt->setMaxLength(5);
121  $lt->setMinValue(60);
122  $lt->setInfo($this->lng->txt('reg_confirmation_hash_life_time_info'));
123  $option->addSubItem($lt);
124  $cd = new ilCheckboxInputGUI($this->lng->txt('reg_allow_codes'), 'reg_codes_'.IL_REG_ACTIVATION);
125  $cd->setInfo($this->lng->txt('reg_allow_codes_info'));
126  $option->addSubItem($cd);
127  $reg_type->addOption($option);
128  $option = new ilRadioOption($this->lng->txt('registration_reg_type_codes'), IL_REG_CODES);
129  $option->setInfo($this->lng->txt('registration_reg_type_codes_info'));
130  $reg_type->addOption($option);
131  $this->form_gui->addItem($reg_type);
132 
133  $pwd_gen = new ilCheckboxInputGUI($this->lng->txt('passwd_generation'), 'reg_pwd');
134  $pwd_gen->setValue(1);
135  $pwd_gen->setInfo($this->lng->txt('reg_info_pwd'));
136  $this->form_gui->addItem($pwd_gen);
137 
138  $approver = new ilTextInputGUI($this->lng->txt('reg_notification'), 'reg_approver');
139  $approver->setSize(32);
140  $approver->setMaxLength(50);
141  $approver->setInfo($this->lng->txt('reg_notification_info'));
142  $this->form_gui->addItem($approver);
143 
144  $roles = new ilRadioGroupInputGUI($this->lng->txt('reg_role_assignment'), 'reg_role_type');
145  $option = new ilRadioOption($this->lng->txt('reg_fixed'), IL_REG_ROLES_FIXED);
146  $list = new ilCustomInputGUI($this->lng->txt('reg_available_roles'));
147  $edit = $this->ctrl->getLinkTarget($this,'editRoles');
148  $list->setHtml($this->__parseRoleList($this->__prepareRoleList(), $edit));
149  $option->addSubItem($list);
150  $roles->addOption($option);
151  $option = new ilRadioOption($this->lng->txt('reg_email'), IL_REG_ROLES_EMAIL);
152  $list = new ilCustomInputGUI($this->lng->txt('reg_available_roles'));
153  $edit = $this->ctrl->getLinkTarget($this,'editEmailAssignments');
154  $list->setHtml($this->__parseRoleList($this->__prepareAutomaticRoleList(), $edit));
155  $option->addSubItem($list);
156  $roles->addOption($option);
157  $this->form_gui->addItem($roles);
158 
159  $limit = new ilCheckboxInputGUI($this->lng->txt('reg_access_limitations'), 'reg_access_limitation');
160  $limit->setValue(1);
161  $list = new ilCustomInputGUI($this->lng->txt('reg_available_roles'));
162  $edit = $this->ctrl->getLinkTarget($this,'editRoleAccessLimitations');
163  $list->setHtml($this->__parseRoleList($this->__prepareAccessLimitationRoleList(), $edit));
164  $limit->addSubItem($list);
165  $this->form_gui->addItem($limit);
166 
167  $this->form_gui->addCommandButton('save', $this->lng->txt('save'));
168  }
169 
170  function initFormValues()
171  {
172  if($this->registration_settings->roleSelectionEnabled())
173  {
174  $role_type = IL_REG_ROLES_FIXED;
175  }
176  else if ($this->registration_settings->automaticRoleAssignmentEnabled())
177  {
178  $role_type = IL_REG_ROLES_EMAIL;
179  }
180 
181  $values = array(
182  'reg_type' => $this->registration_settings->getRegistrationType(),
183  'reg_hash_life_time' => (int)$this->registration_settings->getRegistrationHashLifetime(),
184  'reg_pwd' => $this->registration_settings->passwordGenerationEnabled(),
185  'reg_approver' => $this->registration_settings->getApproveRecipientLogins(),
186  'reg_role_type' => $role_type,
187  'reg_access_limitation' => $this->registration_settings->getAccessLimitation()
188  );
189 
190  $allow_codes = $this->registration_settings->getAllowCodes();
191  $reg_type = $this->registration_settings->getRegistrationType();
192  if($allow_codes && in_array($reg_type, array(IL_REG_DIRECT, IL_REG_APPROVE, IL_REG_ACTIVATION)))
193  {
194  $values['reg_codes_'.$reg_type] = true;
195  }
196 
197  $this->form_gui->setValuesByArray($values);
198  }
199 
200  function view()
201  {
202  global $ilAccess, $ilErr, $ilCtrl, $ilToolbar, $ilTabs;
203 
204  if(!$ilAccess->checkAccess('read','',$this->ref_id))
205  {
206  $ilErr->raiseError($this->lng->txt("msg_no_perm_read"),$ilErr->MESSAGE);
207  }
208 
209  $this->setSubTabs();
210 
211  // edit new accout mail
212  $ilCtrl->setParameterByClass("ilobjuserfoldergui", "ref_id", USER_FOLDER_ID);
213  $ilToolbar->addButton($this->lng->txt('registration_user_new_account_mail'),
214  $ilCtrl->getLinkTargetByClass(array("iladministrationgui", "ilobjuserfoldergui"), "newAccountMail"));
215  $ilCtrl->setParameterByClass("ilobjuserfoldergui", "ref_id", $_GET["ref_id"]);
216 
217  $this->initForm();
218  $this->initFormValues();
219  $this->tpl->setContent($this->form_gui->getHTML());
220  }
221 
222  function save()
223  {
224  global $ilAccess,$ilErr;
225 
226  if(!$ilAccess->checkAccess('write','',$this->ref_id))
227  {
228  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"),$ilErr->MESSAGE);
229  }
230 
231  $this->registration_settings->setRegistrationType((int) $_POST['reg_type']);
232  $this->registration_settings->setPasswordGenerationStatus((int) $_POST['reg_pwd']);
233  $this->registration_settings->setApproveRecipientLogins(ilUtil::stripSlashes($_POST['reg_approver']));
234  $this->registration_settings->setRoleType((int) $_POST['reg_role_type']);
235  $this->registration_settings->setAccessLimitation((int) $_POST['reg_access_limitation']);
236 
237  $allow_codes = false;
238  if(in_array((int)$_POST['reg_type'], array(IL_REG_DIRECT, IL_REG_APPROVE, IL_REG_ACTIVATION)))
239  {
240  $allow_codes = (bool)$_POST['reg_codes_'.(int)$_POST['reg_type']];
241  }
242  $this->registration_settings->setAllowCodes($allow_codes);
243 
244  if(!preg_match('/^([0]|([1-9][0-9]*))([\.,][0-9][0-9]*)?$/', (int)$_POST['reg_hash_life_time']))
245  $this->registration_settings->setRegistrationHashLifetime(0);
246  else
247  $this->registration_settings->setRegistrationHashLifetime((int)$_POST['reg_hash_life_time']);
248 
249  if($error_code = $this->registration_settings->validate())
250  {
251  switch($error_code)
252  {
254 
255  ilUtil::sendFailure($this->lng->txt('reg_unknown_recipients').' '.$this->registration_settings->getUnknown());
256  $this->view();
257  return false;
258 
260 
261  ilUtil::sendFailure($this->lng->txt('reg_approve_needs_recipient').' '.$this->registration_settings->getUnknown());
262  $this->view();
263  return false;
264 
265  }
266  }
267 
268  $this->registration_settings->save();
269  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
270  $this->view();
271 
272  return true;
273  }
274 
275  function editRoles()
276  {
277  include_once './Services/AccessControl/classes/class.ilObjRole.php';
278 
279  global $ilAccess,$ilErr,$rbacreview;
280 
281  if(!$ilAccess->checkAccess('write','',$this->ref_id))
282  {
283  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"),$ilErr->MESSAGE);
284  }
285 
286  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.edit_roles.html','Services/Registration');
287 
288  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
289  $this->tpl->setVariable("TXT_SELECTABLE_ROLES",$this->lng->txt('reg_selectable_roles'));
290  $this->tpl->setVariable("ARR_DOWNRIGHT",ilUtil::getImagePath('arrow_downright.gif'));
291  $this->tpl->setVariable("ACTIONS",$this->lng->txt('actions'));
292  $this->tpl->setVariable("UPDATE",$this->lng->txt('save'));
293  $this->tpl->setVariable("CANCEL",$this->lng->txt('cancel'));
294 
295  $counter = 0;
296  foreach($rbacreview->getGlobalRoles() as $role)
297  {
298  if($role == SYSTEM_ROLE_ID or
299  $role == ANONYMOUS_ROLE_ID)
300  {
301  continue;
302  }
303  $this->tpl->setCurrentBlock("roles");
304  $this->tpl->setVariable("CSSROW",ilUtil::switchColor(++$counter,'tblrow1','tblrow2'));
305  $this->tpl->setVariable("CHECK_ROLE",ilUtil::formCheckbox(ilObjRole::_lookupAllowRegister($role),
306  "roles[$role]",
307  1));
308  $this->tpl->setVariable("ROLE",ilObjRole::_lookupTitle($role));
309  $this->tpl->parseCurrentBlock();
310 
311  }
312  }
313 
314  function updateRoles()
315  {
316  global $ilAccess,$ilErr,$rbacreview;
317 
318  if(!$ilAccess->checkAccess('write','',$this->ref_id))
319  {
320  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"),$ilErr->MESSAGE);
321  }
322  // Minimum one role
323  if(count($_POST['roles']) < 1)
324  {
325  ilUtil::sendFailure($this->lng->txt('msg_last_role_for_registration'));
326  $this->editRoles();
327  return false;
328  }
329  // update allow register
330  foreach($rbacreview->getGlobalRoles() as $role)
331  {
332  if($role_obj = ilObjectFactory::getInstanceByObjId($role,false))
333  {
334  $role_obj->setAllowRegister($_POST['roles'][$role] ? 1 : 0);
335  $role_obj->update();
336  }
337  }
338 
339  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
340  $this->view();
341 
342  return true;
343  }
344 
346  {
347  global $ilAccess,$ilErr,$rbacreview;
348 
349  if(!$ilAccess->checkAccess('write','',$this->ref_id))
350  {
351  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"),$ilErr->MESSAGE);
352  }
353 
354  $this->__initRoleAssignments();
355 
356  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.reg_email_role_assignments.html','Services/Registration');
357  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
358  $this->tpl->setVariable("TXT_EMAIL_ROLE_ASSIGN",$this->lng->txt('reg_email_role_assignment'));
359  $this->tpl->setVariable("TXT_MAIL",$this->lng->txt('reg_email'));
360  $this->tpl->setVariable("TXT_ROLE",$this->lng->txt('obj_role'));
361  $this->tpl->setVariable("TXT_DEFAULT",$this->lng->txt('reg_default'));
362  $this->tpl->setVariable("ARR_DOWNRIGHT",ilUtil::getImagePath('arrow_downright.gif'));
363  $this->tpl->setVariable("TXT_DOMAIN",$this->lng->txt('reg_domain'));
364 
365 
366  $this->tpl->setVariable("BTN_DELETE",$this->lng->txt('delete'));
367  $this->tpl->setVariable("BTN_SAVE",$this->lng->txt('save'));
368  $this->tpl->setVariable("BTN_ADD",$this->lng->txt('reg_add_assignment'));
369  $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt('cancel'));
370 
371  $counter = 0;
372  foreach($this->assignments_obj->getAssignments() as $assignment)
373  {
374  $this->tpl->setCurrentBlock("roles");
375  $this->tpl->setVariable("CSSROW",ilUtil::switchColor(++$counter,'tblrow1','tblrow1'));
376  $this->tpl->setVariable("ASSIGN_ID",$assignment['id']);
377  $this->tpl->setVariable("DOMAIN",$assignment['domain']);
378  $this->tpl->setVariable("CHECK_ROLE",ilUtil::formCheckbox(0,'del_assign[]',$assignment['id']));
379  $this->tpl->setVariable("ROLE_SEL",$this->__buildRoleSelection($assignment['id']));
380  $this->tpl->parseCurrentBlock();
381  }
382 
383  $this->tpl->setVariable("DEF_CSSROW",ilUtil::switchColor(++$counter,'tblrow1','tblrow1'));
384  $this->tpl->setVariable("TXT_DEFAULT",$this->lng->txt('default'));
385  $this->tpl->setVariable("DEF_ROLE",$this->__buildRoleSelection(-1));
386  }
387 
389  {
390  global $lng,$ilAccess,$ilErr,$rbacreview;
391 
392  if(!$ilAccess->checkAccess('write','',$this->ref_id))
393  {
394  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"),$ilErr->MESSAGE);
395  }
396 
398 
399  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.reg_role_access_limitations.html','Services/Registration');
400 
401  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
402  $this->tpl->setVariable("TXT_REG_ROLE_ACCESS_LIMITATIONS",$lng->txt('reg_role_access_limitations'));
403  $this->tpl->setVariable("TXT_ROLE",$lng->txt('obj_role'));
404  $this->tpl->setVariable("TXT_ACCESS_LIMITATION_MODE",$lng->txt('reg_access_limitation_mode'));
405 
406  $this->tpl->setVariable("BTN_SAVE",$lng->txt('save'));
407  $this->tpl->setVariable("BTN_CANCEL",$lng->txt('cancel'));
408 
409  $counter = 0;
410  include_once './Services/AccessControl/classes/class.ilObjRole.php';
411 
412  foreach(ilObjRole::_lookupRegisterAllowed() as $role)
413  {
414  $this->tpl->setCurrentBlock("roles");
415  $this->tpl->setVariable("CSSROW",ilUtil::switchColor(++$counter,'tblrow1','tblrow1'));
416  $this->tpl->setVariable("ROLE_ID",$role['id']);
417  $this->tpl->setVariable("ROLE_TITLE",$role['title']);
418  $this->tpl->setVariable("SEL_ACCESS_LIMITATION",$this->__buildAccessLimitationSelection($role['id']));
419  $this->tpl->setVariable("CSS_DISPLAY_ABSOLUTE",($this->access_limitations_obj->getMode($role['id']) == 'absolute') ? 'inline' : 'none');
420  $this->tpl->setVariable("CSS_DISPLAY_RELATIVE",($this->access_limitations_obj->getMode($role['id']) == 'relative') ? 'inline' : 'none');
421  $this->tpl->setVariable("CSS_DISPLAY_UNLIMITED",($this->access_limitations_obj->getMode($role['id']) == 'unlimited') ? 'inline' : 'none');
422  $this->tpl->setVariable("TXT_ACCESS_LIMITATION_UNLIMITED", $lng->txt('reg_access_limitation_none'));
423 
424  $date = $this->__prepareDateSelect($this->access_limitations_obj->getAbsolute($role['id']));
425  $this->tpl->setVariable("SEL_ACCESS_LIMITATION_ABSOLUTE",ilUtil::makeDateSelect('access_limitation_absolute_'.$role['id'],$date['y'],$date['m'],$date['d'],'2007'));
426 
427  $this->tpl->setVariable("TXT_DAYS",$lng->txt('days'));
428  $this->tpl->setVariable("TXT_MONTHS",$lng->txt('months'));
429  $this->tpl->setVariable("TXT_YEARS",$lng->txt('years'));
430 
431  $this->tpl->setVariable("DAYS",$this->access_limitations_obj->getRelative($role['id'],'d'));
432  $this->tpl->setVariable("MONTHS",$this->access_limitations_obj->getRelative($role['id'],'m'));
433  $this->tpl->setVariable("YEARS",$this->access_limitations_obj->getRelative($role['id'],'y'));
434  $this->tpl->parseCurrentBlock();
435  }
436  }
437 
438  function addAssignment()
439  {
440  global $ilAccess,$ilErr,$rbacreview;
441 
442  if(!$ilAccess->checkAccess('write','',$this->ref_id))
443  {
444  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"),$ilErr->MESSAGE);
445  }
446 
447  $this->__initRoleAssignments();
448  $this->assignments_obj->add();
449 
450  ilUtil::sendSuccess($this->lng->txt('reg_added_assignment'));
451  $this->editEmailAssignments();
452 
453  return true;
454  }
455 
456  function deleteAssignment()
457  {
458  global $ilAccess,$ilErr,$rbacreview;
459 
460  if(!$ilAccess->checkAccess('write','',$this->ref_id))
461  {
462  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"),$ilErr->MESSAGE);
463  }
464 
465  if(!count($_POST['del_assign']))
466  {
467  ilUtil::sendFailure($this->lng->txt('reg_select_one'));
468  $this->editEmailAssignments();
469  return false;
470  }
471 
472  $this->__initRoleAssignments();
473 
474  foreach($_POST['del_assign'] as $assignment_id)
475  {
476  $this->assignments_obj->delete($assignment_id);
477  }
478 
479  ilUtil::sendSuccess($this->lng->txt('reg_deleted_assignment'));
480  $this->editEmailAssignments();
481 
482  return true;
483  }
484 
485  function saveAssignment()
486  {
487  global $ilAccess,$ilErr,$rbacreview;
488 
489  if(!$ilAccess->checkAccess('write','',$this->ref_id))
490  {
491  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"),$ilErr->MESSAGE);
492  }
493 
494  $this->__initRoleAssignments();
495 
496  if (!is_array($_POST['domain']))
497  {
498  $_POST['domain'] = array();
499  }
500 
501  foreach($_POST['domain'] as $id => $data)
502  {
503  $this->assignments_obj->setDomain($id,ilUtil::stripSlashes($_POST['domain'][$id]['domain']));
504  $this->assignments_obj->setRole($id,ilUtil::stripSlashes($_POST['role'][$id]['role']));
505  }
506  $this->assignments_obj->setDefaultRole((int) $_POST['default_role']);
507 
508  if($err = $this->assignments_obj->validate())
509  {
510  switch($err)
511  {
513  ilUtil::sendFailure($this->lng->txt('reg_missing_domain'));
514  break;
515 
516  case IL_REG_MISSING_ROLE:
517  ilUtil::sendFailure($this->lng->txt('reg_missing_role'));
518  break;
519  }
520  $this->editEmailAssignments();
521  return false;
522  }
523 
524 
525  $this->assignments_obj->save();
526  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
527  $this->view();
528  return true;
529  }
530 
532  {
533  global $ilAccess,$ilErr,$rbacreview;
534 
535  if(!$ilAccess->checkAccess('write','',$this->ref_id))
536  {
537  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"),$ilErr->MESSAGE);
538  }
539 
541 
542  include_once './Services/AccessControl/classes/class.ilObjRole.php';
543 
544  foreach(ilObjRole::_lookupRegisterAllowed() as $role)
545  {
546  $this->access_limitations_obj->setMode($_POST['access_limitation_mode_'.$role['id']],$role['id']);
547  $this->access_limitations_obj->setAbsolute($_POST['access_limitation_absolute_'.$role['id']],$role['id']);
548  $this->access_limitations_obj->setRelative($_POST['access_limitation_relative_'.$role['id']],$role['id']);
549  }
550 
551  //var_dump("<pre>",$_POST,$this->access_limitations_obj->getAbsolute(4),time(),"</pre>");exit;
552 
553  if($err = $this->access_limitations_obj->validate())
554  {
555  switch($err)
556  {
558  ilUtil::sendFailure($this->lng->txt('reg_access_limitation_missing_mode'));
559  break;
560 
562  ilUtil::sendFailure($this->lng->txt('reg_access_limitation_out_of_date'));
563  break;
564  }
565  $this->editRoleAccessLimitations();
566  return false;
567  }
568 
569 
570  $this->access_limitations_obj->save();
571  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
572  $this->view();
573  return true;
574  }
575 
576  function __parseRoleList($roles, $url)
577  {
578  $tpl = new ilTemplate('tpl.registration_roles.html', true, true,'Services/Registration');
579 
580  $tpl->setVariable("EDIT", $this->lng->txt("edit"));
581  $tpl->setVariable("LINK_EDIT", $url);
582 
583  if (is_array($roles) && sizeof($roles))
584  {
585  foreach($roles as $role)
586  {
587  $tpl->setCurrentBlock("list_item");
588  $tpl->setVariable("LIST_ITEM_ITEM", $role);
589  $tpl->parseCurrentBlock();
590  }
591  }
592  else
593  {
594  $tpl->setVariable("NONE", $this->lng->txt('none'));
595  }
596 
597  return $tpl->get();
598  }
599 
600  function __prepareRoleList()
601  {
602  include_once './Services/AccessControl/classes/class.ilObjRole.php';
603 
604  $all = array();
605  foreach(ilObjRole::_lookupRegisterAllowed() as $role)
606  {
607  $all[] = $role['title'];
608  }
609  return $all;
610  }
611 
613  {
614  include_once './Services/AccessControl/classes/class.ilObjRole.php';
615  $this->__initRoleAssignments();
616 
617  $all = array();
618  foreach($this->assignments_obj->getAssignments() as $assignment)
619  {
620  if(strlen($assignment['domain']) and $assignment['role'])
621  {
622  $all[] = $assignment['domain'].' -> '.ilObjRole::_lookupTitle($assignment['role']);
623  }
624  }
625 
626  if(strlen($this->assignments_obj->getDefaultRole()))
627  {
628  $all[] = $this->lng->txt('reg_default').' -> '.ilObjRole::_lookupTitle($this->assignments_obj->getDefaultRole());
629  }
630 
631  return $all;
632  }
633 
635  {
636  global $lng;
637 
639 
640  include_once './Services/AccessControl/classes/class.ilObjRole.php';
641 
642  $all = array();
643  foreach(ilObjRole::_lookupRegisterAllowed() as $role)
644  {
645  switch ($this->access_limitations_obj->getMode($role['id']))
646  {
647  case 'absolute':
648  $txt_access_value = $lng->txt('reg_access_limitation_limited_until');
649  $txt_access_value .= " ".ilDatePresentation::formatDate(new ilDateTime($this->access_limitations_obj->getAbsolute($role['id'],IL_CAL_UNIX)));
650  break;
651 
652  case 'relative':
653  $years = $this->access_limitations_obj->getRelative($role['id'],'y');
654  $months = $this->access_limitations_obj->getRelative($role['id'],'m');
655  $days = $this->access_limitations_obj->getRelative($role['id'],'d');
656 
657  $txt_access_value = $lng->txt('reg_access_limitation_limited_time')." ";
658 
659  if ($years)
660  {
661  $txt_access_value .= $years." ";
662  $txt_access_value .= ($years == 1) ? $lng->txt('year') : $lng->txt('years');
663 
664  if ($months)
665  {
666  if ($days)
667  {
668  $txt_access_value .= ", ";
669  }
670  else
671  {
672  $txt_access_value .= " ".$lng->txt('and')." ";
673  }
674  }
675  elseif ($days)
676  {
677  $txt_access_value .= " ".$lng->txt('and')." ";
678  }
679  }
680 
681  if ($months)
682  {
683  $txt_access_value .= $months." ";
684  $txt_access_value .= ($months == 1) ? $lng->txt('month') : $lng->txt('months');
685 
686  if ($days)
687  {
688  $txt_access_value .= " ".$lng->txt('and')." ";
689  }
690  }
691 
692  if ($days)
693  {
694  $txt_access_value .= $days." ";
695  $txt_access_value .= ($days == 1) ? $lng->txt('day') : $lng->txt('days');
696  }
697  break;
698 
699  default:
700  $txt_access_value = $lng->txt('reg_access_limitation_none');
701  break;
702  }
703 
704  $all[] = $role['title'].' ('.$txt_access_value.')';
705  }
706 
707  return $all;
708  }
709 
711  {
712  if(is_object($this->assignments_obj))
713  {
714  return true;
715  }
716 
717  include_once 'Services/Registration/classes/class.ilRegistrationEmailRoleAssignments.php';
718 
719  $this->assignments_obj = new ilRegistrationRoleAssignments();
720  }
721 
723  {
724  if(is_object($this->access_limitations_obj))
725  {
726  return true;
727  }
728 
729  include_once 'Services/Registration/classes/class.ilRegistrationRoleAccessLimitations.php';
730 
731  $this->access_limitations_obj = new ilRegistrationRoleAccessLimitations();
732  }
733 
734  function __buildRoleSelection($assignment_id)
735  {
736  include_once './Services/AccessControl/classes/class.ilObjRole.php';
737 
738  global $rbacreview;
739 
740  $assignments = $this->assignments_obj->getAssignments();
741  $selected = ($assignment_id > 0) ?
742  $assignments[$assignment_id]['role'] :
743  $this->assignments_obj->getDefaultRole();
744 
745  if(!$selected)
746  {
747  $roles[0] = $this->lng->txt('please_choose');
748  }
749 
750  foreach($rbacreview->getGlobalRoles() as $role_id)
751  {
752  if($role_id == SYSTEM_ROLE_ID or
753  $role_id == ANONYMOUS_ROLE_ID)
754  {
755  continue;
756  }
757  $roles[$role_id] = ilObjRole::_lookupTitle($role_id);
758  }
759 
760  if($assignment_id > 0)
761  {
762  return ilUtil::formSelect($selected,
763  "role[$assignment_id][role]",
764  $roles,false,true);
765  }
766  else
767  {
768  return ilUtil::formSelect($selected,
769  "default_role",
770  $roles,false,true);
771  }
772  }
773 
774  function __buildAccessLimitationSelection($a_role_id)
775  {
776  global $lng;
777 
778  $options = array(
779  'null' => $lng->txt('please_choose'),
780  'unlimited' => $lng->txt('reg_access_limitation_mode_unlimited'),
781  'absolute' => $lng->txt('reg_access_limitation_mode_absolute'),
782  'relative' => $lng->txt('reg_access_limitation_mode_relative')
783  );
784 
785  $attribs = array('onchange' => 'displayAccessLimitationSelectionForm(document.cmd.access_limitation_mode_'.$a_role_id.','.$a_role_id.')');
786 
787  $selected = $this->access_limitations_obj->getMode($a_role_id);
788 
789  return ilUtil::formSelect($selected,'access_limitation_mode_'.$a_role_id,$options,false,true,0,"",$attribs);
790 
791  }
792 
793  function __prepareDateSelect($a_unix_time)
794  {
795  if (!$a_unix_time)
796  {
797  $a_unix_time = time();
798  }
799 
800  return array('y' => date('Y',$a_unix_time),
801  'm' => date('n',$a_unix_time),
802  'd' => date('d',$a_unix_time));
803  }
804 
805  function listCodes()
806  {
807  global $ilAccess, $ilErr, $ilCtrl, $ilToolbar;
808 
809  if(!$ilAccess->checkAccess('read','',$this->ref_id))
810  {
811  $ilErr->raiseError($this->lng->txt("msg_no_perm_read"),$ilErr->MESSAGE);
812  }
813 
814  $this->setSubTabs('registration_codes');
815 
816  $ilToolbar->addButton($this->lng->txt("registration_codes_add"),
817  $this->ctrl->getLinkTarget($this, "addCodes"));
818 
819  include_once("./Services/Registration/classes/class.ilRegistrationCodesTableGUI.php");
820  $ctab = new ilRegistrationCodesTableGUI($this, "listCodes");
821  $this->tpl->setContent($ctab->getHTML());
822  }
823 
824  function initAddCodesForm()
825  {
826  global $rbacreview, $ilObjDataCache;
827 
828  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
829 
830  $this->form_gui = new ilPropertyFormGUI();
831  $this->form_gui->setFormAction($this->ctrl->getFormAction($this, 'createCodes'));
832  $this->form_gui->setTitle($this->lng->txt('registration_codes_edit_header'));
833 
834  $count = new ilNumberInputGUI($this->lng->txt('registration_codes_number'), 'reg_codes_number');
835  $count->setSize(4);
836  $count->setMaxLength(4);
837  $count->setMinValue(1);
838  $count->setMaxValue(1000);
839  $count->setRequired(true);
840  $this->form_gui->addItem($count);
841 
842  include_once './Services/AccessControl/classes/class.ilObjRole.php';
843  $options = array();
844  foreach($rbacreview->getGlobalRoles() as $role_id)
845  {
846  if(!in_array($role_id, array(SYSTEM_ROLE_ID, ANONYMOUS_ROLE_ID)))
847  {
848  $options[$role_id] = $ilObjDataCache->lookupTitle($role_id);
849  }
850  }
851  $roles = new ilSelectInputGUI($this->lng->txt("registration_codes_roles"), "reg_codes_role");
852  $roles->setOptions($options);
853  $roles->setRequired(true);
854  $this->form_gui->addItem($roles);
855 
856  $this->form_gui->addCommandButton('createCodes', $this->lng->txt('create'));
857  }
858 
859  function addCodes()
860  {
861  global $ilAccess, $ilErr;
862 
863  if(!$ilAccess->checkAccess('write', '', $this->ref_id))
864  {
865  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"), $ilErr->MESSAGE);
866  }
867 
868  $this->setSubTabs('registration_codes');
869 
870  $this->initAddCodesForm();
871  $this->tpl->setContent($this->form_gui->getHTML());
872  }
873 
874  function createCodes()
875  {
876  global $ilAccess, $ilErr;
877 
878  if(!$ilAccess->checkAccess('write', '', $this->ref_id))
879  {
880  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"), $ilErr->MESSAGE);
881  }
882 
883  $this->setSubTabs('registration_codes');
884 
885  $this->initAddCodesForm();
886  if($this->form_gui->checkInput())
887  {
888  $number = $this->form_gui->getInput('reg_codes_number');
889  $role = $this->form_gui->getInput('reg_codes_role');
890 
891  include_once './Services/Registration/classes/class.ilRegistrationCode.php';
892 
893  $stamp = time();
894  for($loop = 1; $loop <= $number; $loop++)
895  {
896  ilRegistrationCode::create($role, $stamp);
897  }
898 
899  ilUtil::sendSuccess($this->lng->txt('saved_successfully'), true);
900  $this->ctrl->redirect($this, "listCodes");
901  }
902  else
903  {
904  $this->form_gui->setValuesByPost();
905  $this->tpl->setContent($this->form_gui->getHtml());
906  }
907  }
908 
909  function deleteCodes()
910  {
911  include_once './Services/Registration/classes/class.ilRegistrationCode.php';
913 
914  ilUtil::sendSuccess($this->lng->txt('info_deleted'), true);
915  $this->ctrl->redirect($this, "listCodes");
916  }
917 
919  {
920  global $ilErr, $ilias;
921 
922  if(!isset($_POST["id"]))
923  {
924  $ilErr->raiseError($this->lng->txt("no_checkbox"), $ilErr->MESSAGE);
925  }
926 
927  $this->setSubTabs('registration_codes');
928 
929  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
930  $gui = new ilConfirmationGUI();
931  $gui->setHeaderText($this->lng->txt("info_delete_sure"));
932  $gui->setCancel($this->lng->txt("cancel"), "listCodes");
933  $gui->setConfirm($this->lng->txt("confirm"), "deleteCodes");
934  $gui->setFormAction($this->ctrl->getFormAction($this, "deleteCodes"));
935 
936  include_once './Services/Registration/classes/class.ilRegistrationCode.php';
938  foreach($data as $code)
939  {
940  $gui->addItem("id[]", $code["code_id"], $code["code"]);
941  }
942 
943  $this->tpl->setContent($gui->getHTML());
944  }
945 
946  function resetCodesFilter()
947  {
948  include_once("./Services/Registration/classes/class.ilRegistrationCodesTableGUI.php");
949  $utab = new ilRegistrationCodesTableGUI($this, "listCodes");
950  $utab->resetOffset();
951  $utab->resetFilter();
952 
953  $this->listCodes();
954  }
955 
956  function applyCodesFilter()
957  {
958  include_once("./Services/Registration/classes/class.ilRegistrationCodesTableGUI.php");
959  $utab = new ilRegistrationCodesTableGUI($this, "listCodes");
960  $utab->resetOffset();
961  $utab->writeFilterToSession();
962 
963  $this->listCodes();
964  }
965 
966  function exportCodes()
967  {
968  global $ilAccess, $ilErr;
969 
970  if(!$ilAccess->checkAccess('read', '', $this->ref_id))
971  {
972  $ilErr->raiseError($this->lng->txt("msg_no_perm_read"), $ilErr->MESSAGE);
973  }
974 
975  include_once("./Services/Registration/classes/class.ilRegistrationCodesTableGUI.php");
976  $utab = new ilRegistrationCodesTableGUI($this, "listCodes");
977 
978  include_once './Services/Registration/classes/class.ilRegistrationCode.php';
979  $codes = ilRegistrationCode::getCodesForExport($utab->filter["code"], $utab->filter["role"], $utab->filter["generated"]);
980 
981  if(sizeof($codes))
982  {
983  // :TODO: add url/link to login?!
984  ilUtil::deliverData(implode("\n", $codes), "ilias_registration_codes_".date("d-m-Y").".txt","text/plain");
985  }
986  else
987  {
988  ilUtil::sendFailure($this->lng->txt("registration_export_codes_no_data"));
989  $this->listCodes();
990  }
991  }
992 }
993 ?>