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