ILIAS  Release_4_2_x_branch Revision 61807
 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  $this->form_gui->addCommandButton('save', $this->lng->txt('save'));
170  }
171 
172  function initFormValues()
173  {
174  if($this->registration_settings->roleSelectionEnabled())
175  {
176  $role_type = IL_REG_ROLES_FIXED;
177  }
178  else if ($this->registration_settings->automaticRoleAssignmentEnabled())
179  {
180  $role_type = IL_REG_ROLES_EMAIL;
181  }
182 
183  $values = array(
184  'reg_type' => $this->registration_settings->getRegistrationType(),
185  'reg_hash_life_time' => (int)$this->registration_settings->getRegistrationHashLifetime(),
186  'reg_pwd' => $this->registration_settings->passwordGenerationEnabled(),
187  'reg_approver' => $this->registration_settings->getApproveRecipientLogins(),
188  'reg_role_type' => $role_type,
189  'reg_access_limitation' => $this->registration_settings->getAccessLimitation()
190  );
191 
192  $allow_codes = $this->registration_settings->getAllowCodes();
193  $reg_type = $this->registration_settings->getRegistrationType();
194  if($allow_codes && in_array($reg_type, array(IL_REG_DIRECT, IL_REG_APPROVE, IL_REG_ACTIVATION)))
195  {
196  $values['reg_codes_'.$reg_type] = true;
197  }
198 
199  $this->form_gui->setValuesByArray($values);
200  }
201 
202  function view()
203  {
204  global $ilAccess, $ilErr, $ilCtrl, $ilToolbar, $ilTabs;
205 
206  if(!$ilAccess->checkAccess('read','',$this->ref_id))
207  {
208  $ilErr->raiseError($this->lng->txt("msg_no_perm_read"),$ilErr->MESSAGE);
209  }
210 
211  $this->setSubTabs();
212 
213  // edit new accout mail
214  $ilCtrl->setParameterByClass("ilobjuserfoldergui", "ref_id", USER_FOLDER_ID);
215  $ilToolbar->addButton($this->lng->txt('registration_user_new_account_mail'),
216  $ilCtrl->getLinkTargetByClass(array("iladministrationgui", "ilobjuserfoldergui"), "newAccountMail"));
217  $ilCtrl->setParameterByClass("ilobjuserfoldergui", "ref_id", $_GET["ref_id"]);
218 
219  $this->initForm();
220  $this->initFormValues();
221  $this->tpl->setContent($this->form_gui->getHTML());
222  }
223 
224  function save()
225  {
226  global $ilAccess,$ilErr;
227 
228  if(!$ilAccess->checkAccess('write','',$this->ref_id))
229  {
230  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"),$ilErr->MESSAGE);
231  }
232 
233  $this->registration_settings->setRegistrationType((int) $_POST['reg_type']);
234  $this->registration_settings->setPasswordGenerationStatus((int) $_POST['reg_pwd']);
235  $this->registration_settings->setApproveRecipientLogins(ilUtil::stripSlashes($_POST['reg_approver']));
236  $this->registration_settings->setRoleType((int) $_POST['reg_role_type']);
237  $this->registration_settings->setAccessLimitation((int) $_POST['reg_access_limitation']);
238 
239  $allow_codes = false;
240  if(in_array((int)$_POST['reg_type'], array(IL_REG_DIRECT, IL_REG_APPROVE, IL_REG_ACTIVATION)))
241  {
242  $allow_codes = (bool)$_POST['reg_codes_'.(int)$_POST['reg_type']];
243  }
244  $this->registration_settings->setAllowCodes($allow_codes);
245 
246  if(!preg_match('/^([0]|([1-9][0-9]*))([\.,][0-9][0-9]*)?$/', (int)$_POST['reg_hash_life_time']))
247  $this->registration_settings->setRegistrationHashLifetime(ilRegistrationSettings::REG_HASH_LIFETIME_MIN_VALUE);
248  else
249  $this->registration_settings->setRegistrationHashLifetime(max((int)$_POST['reg_hash_life_time'], ilRegistrationSettings::REG_HASH_LIFETIME_MIN_VALUE));
250 
251  if($error_code = $this->registration_settings->validate())
252  {
253  switch($error_code)
254  {
256 
257  ilUtil::sendFailure($this->lng->txt('reg_unknown_recipients').' '.$this->registration_settings->getUnknown());
258  $this->view();
259  return false;
260 
262 
263  ilUtil::sendFailure($this->lng->txt('reg_approve_needs_recipient').' '.$this->registration_settings->getUnknown());
264  $this->view();
265  return false;
266 
267  }
268  }
269 
270  $this->registration_settings->save();
271  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
272  $this->view();
273 
274  return true;
275  }
276 
277  function editRoles()
278  {
279  include_once './Services/AccessControl/classes/class.ilObjRole.php';
280 
281  global $ilAccess,$ilErr,$rbacreview;
282 
283  if(!$ilAccess->checkAccess('write','',$this->ref_id))
284  {
285  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"),$ilErr->MESSAGE);
286  }
287 
288  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.edit_roles.html','Services/Registration');
289 
290  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
291  $this->tpl->setVariable("TXT_SELECTABLE_ROLES",$this->lng->txt('reg_selectable_roles'));
292  $this->tpl->setVariable("ARR_DOWNRIGHT",ilUtil::getImagePath('arrow_downright.gif'));
293  $this->tpl->setVariable("ACTIONS",$this->lng->txt('actions'));
294  $this->tpl->setVariable("UPDATE",$this->lng->txt('save'));
295  $this->tpl->setVariable("CANCEL",$this->lng->txt('cancel'));
296 
297  $counter = 0;
298  foreach($rbacreview->getGlobalRoles() as $role)
299  {
300  if($role == SYSTEM_ROLE_ID or $role == ANONYMOUS_ROLE_ID)
301  {
302  continue;
303  }
304  $this->tpl->setCurrentBlock("roles");
305  $this->tpl->setVariable("CSSROW",ilUtil::switchColor(++$counter,'tblrow1','tblrow2'));
306  $this->tpl->setVariable("CHECK_ROLE",ilUtil::formCheckbox(ilObjRole::_lookupAllowRegister($role),
307  "roles[$role]",
308  1));
309  $this->tpl->setVariable("ROLE",ilObjRole::_lookupTitle($role));
310  $this->tpl->parseCurrentBlock();
311 
312  }
313  }
314 
315  function updateRoles()
316  {
317  global $ilAccess,$ilErr,$rbacreview;
318 
319  if(!$ilAccess->checkAccess('write','',$this->ref_id))
320  {
321  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"),$ilErr->MESSAGE);
322  }
323  // Minimum one role
324  if(count($_POST['roles']) < 1)
325  {
326  ilUtil::sendFailure($this->lng->txt('msg_last_role_for_registration'));
327  $this->editRoles();
328  return false;
329  }
330  // update allow register
331  foreach($rbacreview->getGlobalRoles() as $role)
332  {
333  if($role_obj = ilObjectFactory::getInstanceByObjId($role,false))
334  {
335  $role_obj->setAllowRegister($_POST['roles'][$role] ? 1 : 0);
336  $role_obj->update();
337  }
338  }
339 
340  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
341  $this->view();
342 
343  return true;
344  }
345 
347  {
348  global $ilAccess,$ilErr,$rbacreview;
349 
350  if(!$ilAccess->checkAccess('write','',$this->ref_id))
351  {
352  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"),$ilErr->MESSAGE);
353  }
354 
355  $this->__initRoleAssignments();
356 
357  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.reg_email_role_assignments.html','Services/Registration');
358  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
359  $this->tpl->setVariable("TXT_EMAIL_ROLE_ASSIGN",$this->lng->txt('reg_email_role_assignment'));
360  $this->tpl->setVariable("TXT_MAIL",$this->lng->txt('reg_email'));
361  $this->tpl->setVariable("TXT_ROLE",$this->lng->txt('obj_role'));
362  $this->tpl->setVariable("TXT_DEFAULT",$this->lng->txt('reg_default'));
363  $this->tpl->setVariable("ARR_DOWNRIGHT",ilUtil::getImagePath('arrow_downright.gif'));
364  $this->tpl->setVariable("TXT_DOMAIN",$this->lng->txt('reg_domain'));
365 
366 
367  $this->tpl->setVariable("BTN_DELETE",$this->lng->txt('delete'));
368  $this->tpl->setVariable("BTN_SAVE",$this->lng->txt('save'));
369  $this->tpl->setVariable("BTN_ADD",$this->lng->txt('reg_add_assignment'));
370  $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt('cancel'));
371 
372  $counter = 0;
373  foreach($this->assignments_obj->getAssignments() as $assignment)
374  {
375  $this->tpl->setCurrentBlock("roles");
376  $this->tpl->setVariable("CSSROW",ilUtil::switchColor(++$counter,'tblrow1','tblrow1'));
377  $this->tpl->setVariable("ASSIGN_ID",$assignment['id']);
378  $this->tpl->setVariable("DOMAIN",$assignment['domain']);
379  $this->tpl->setVariable("CHECK_ROLE",ilUtil::formCheckbox(0,'del_assign[]',$assignment['id']));
380  $this->tpl->setVariable("ROLE_SEL",$this->__buildRoleSelection($assignment['id']));
381  $this->tpl->parseCurrentBlock();
382  }
383 
384  $this->tpl->setVariable("DEF_CSSROW",ilUtil::switchColor(++$counter,'tblrow1','tblrow1'));
385  $this->tpl->setVariable("TXT_DEFAULT",$this->lng->txt('default'));
386  $this->tpl->setVariable("DEF_ROLE",$this->__buildRoleSelection(-1));
387  }
388 
390  {
391  global $lng,$ilAccess,$ilErr,$rbacreview;
392 
393  if(!$ilAccess->checkAccess('write','',$this->ref_id))
394  {
395  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"),$ilErr->MESSAGE);
396  }
397 
399 
400  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.reg_role_access_limitations.html','Services/Registration');
401 
402  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
403  $this->tpl->setVariable("TXT_REG_ROLE_ACCESS_LIMITATIONS",$lng->txt('reg_role_access_limitations'));
404  $this->tpl->setVariable("TXT_ROLE",$lng->txt('obj_role'));
405  $this->tpl->setVariable("TXT_ACCESS_LIMITATION_MODE",$lng->txt('reg_access_limitation_mode'));
406 
407  $this->tpl->setVariable("BTN_SAVE",$lng->txt('save'));
408  $this->tpl->setVariable("BTN_CANCEL",$lng->txt('cancel'));
409 
410  $counter = 0;
411  include_once './Services/AccessControl/classes/class.ilObjRole.php';
412 
413  foreach(ilObjRole::_lookupRegisterAllowed() as $role)
414  {
415  $this->tpl->setCurrentBlock("roles");
416  $this->tpl->setVariable("CSSROW",ilUtil::switchColor(++$counter,'tblrow1','tblrow1'));
417  $this->tpl->setVariable("ROLE_ID",$role['id']);
418  $this->tpl->setVariable("ROLE_TITLE",$role['title']);
419  $this->tpl->setVariable("SEL_ACCESS_LIMITATION",$this->__buildAccessLimitationSelection($role['id']));
420  $this->tpl->setVariable("CSS_DISPLAY_ABSOLUTE",($this->access_limitations_obj->getMode($role['id']) == 'absolute') ? 'inline' : 'none');
421  $this->tpl->setVariable("CSS_DISPLAY_RELATIVE",($this->access_limitations_obj->getMode($role['id']) == 'relative') ? 'inline' : 'none');
422  $this->tpl->setVariable("CSS_DISPLAY_UNLIMITED",($this->access_limitations_obj->getMode($role['id']) == 'unlimited') ? 'inline' : 'none');
423  $this->tpl->setVariable("TXT_ACCESS_LIMITATION_UNLIMITED", $lng->txt('reg_access_limitation_none'));
424 
425  $date = $this->__prepareDateSelect($this->access_limitations_obj->getAbsolute($role['id']));
426  $this->tpl->setVariable("SEL_ACCESS_LIMITATION_ABSOLUTE",ilUtil::makeDateSelect('access_limitation_absolute_'.$role['id'],$date['y'],$date['m'],$date['d'],'2007'));
427 
428  $this->tpl->setVariable("TXT_DAYS",$lng->txt('days'));
429  $this->tpl->setVariable("TXT_MONTHS",$lng->txt('months'));
430  $this->tpl->setVariable("TXT_YEARS",$lng->txt('years'));
431 
432  $this->tpl->setVariable("DAYS",$this->access_limitations_obj->getRelative($role['id'],'d'));
433  $this->tpl->setVariable("MONTHS",$this->access_limitations_obj->getRelative($role['id'],'m'));
434  $this->tpl->setVariable("YEARS",$this->access_limitations_obj->getRelative($role['id'],'y'));
435  $this->tpl->parseCurrentBlock();
436  }
437  }
438 
439  function addAssignment()
440  {
441  global $ilAccess,$ilErr,$rbacreview;
442 
443  if(!$ilAccess->checkAccess('write','',$this->ref_id))
444  {
445  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"),$ilErr->MESSAGE);
446  }
447 
448  $this->__initRoleAssignments();
449  $this->assignments_obj->add();
450 
451  ilUtil::sendSuccess($this->lng->txt('reg_added_assignment'));
452  $this->editEmailAssignments();
453 
454  return true;
455  }
456 
457  function deleteAssignment()
458  {
459  global $ilAccess,$ilErr,$rbacreview;
460 
461  if(!$ilAccess->checkAccess('write','',$this->ref_id))
462  {
463  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"),$ilErr->MESSAGE);
464  }
465 
466  if(!count($_POST['del_assign']))
467  {
468  ilUtil::sendFailure($this->lng->txt('reg_select_one'));
469  $this->editEmailAssignments();
470  return false;
471  }
472 
473  $this->__initRoleAssignments();
474 
475  foreach($_POST['del_assign'] as $assignment_id)
476  {
477  $this->assignments_obj->delete($assignment_id);
478  }
479 
480  ilUtil::sendSuccess($this->lng->txt('reg_deleted_assignment'));
481  $this->editEmailAssignments();
482 
483  return true;
484  }
485 
486  function saveAssignment()
487  {
488  global $ilAccess,$ilErr,$rbacreview;
489 
490  if(!$ilAccess->checkAccess('write','',$this->ref_id))
491  {
492  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"),$ilErr->MESSAGE);
493  }
494 
495  $this->__initRoleAssignments();
496 
497  if (!is_array($_POST['domain']))
498  {
499  $_POST['domain'] = array();
500  }
501 
502  foreach($_POST['domain'] as $id => $data)
503  {
504  $this->assignments_obj->setDomain($id,ilUtil::stripSlashes($_POST['domain'][$id]['domain']));
505  $this->assignments_obj->setRole($id,ilUtil::stripSlashes($_POST['role'][$id]['role']));
506  }
507  $this->assignments_obj->setDefaultRole((int) $_POST['default_role']);
508 
509  if($err = $this->assignments_obj->validate())
510  {
511  switch($err)
512  {
514  ilUtil::sendFailure($this->lng->txt('reg_missing_domain'));
515  break;
516 
517  case IL_REG_MISSING_ROLE:
518  ilUtil::sendFailure($this->lng->txt('reg_missing_role'));
519  break;
520  }
521  $this->editEmailAssignments();
522  return false;
523  }
524 
525 
526  $this->assignments_obj->save();
527  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
528  $this->view();
529  return true;
530  }
531 
533  {
534  global $ilAccess,$ilErr,$rbacreview;
535 
536  if(!$ilAccess->checkAccess('write','',$this->ref_id))
537  {
538  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"),$ilErr->MESSAGE);
539  }
540 
542 
543  include_once './Services/AccessControl/classes/class.ilObjRole.php';
544 
545  foreach(ilObjRole::_lookupRegisterAllowed() as $role)
546  {
547  $this->access_limitations_obj->setMode($_POST['access_limitation_mode_'.$role['id']],$role['id']);
548  $this->access_limitations_obj->setAbsolute($_POST['access_limitation_absolute_'.$role['id']],$role['id']);
549  $this->access_limitations_obj->setRelative($_POST['access_limitation_relative_'.$role['id']],$role['id']);
550  }
551 
552  //var_dump("<pre>",$_POST,$this->access_limitations_obj->getAbsolute(4),time(),"</pre>");exit;
553 
554  if($err = $this->access_limitations_obj->validate())
555  {
556  switch($err)
557  {
559  ilUtil::sendFailure($this->lng->txt('reg_access_limitation_missing_mode'));
560  break;
561 
563  ilUtil::sendFailure($this->lng->txt('reg_access_limitation_out_of_date'));
564  break;
565  }
566  $this->editRoleAccessLimitations();
567  return false;
568  }
569 
570 
571  $this->access_limitations_obj->save();
572  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
573  $this->view();
574  return true;
575  }
576 
577  function __parseRoleList($roles, $url)
578  {
579  $tpl = new ilTemplate('tpl.registration_roles.html', true, true,'Services/Registration');
580 
581  $tpl->setVariable("EDIT", $this->lng->txt("edit"));
582  $tpl->setVariable("LINK_EDIT", $url);
583 
584  if (is_array($roles) && sizeof($roles))
585  {
586  foreach($roles as $role)
587  {
588  $tpl->setCurrentBlock("list_item");
589  $tpl->setVariable("LIST_ITEM_ITEM", $role);
590  $tpl->parseCurrentBlock();
591  }
592  }
593  else
594  {
595  $tpl->setVariable("NONE", $this->lng->txt('none'));
596  }
597 
598  return $tpl->get();
599  }
600 
601  function __prepareRoleList()
602  {
603  include_once './Services/AccessControl/classes/class.ilObjRole.php';
604 
605  $all = array();
606  foreach(ilObjRole::_lookupRegisterAllowed() as $role)
607  {
608  $all[] = $role['title'];
609  }
610  return $all;
611  }
612 
614  {
615  include_once './Services/AccessControl/classes/class.ilObjRole.php';
616  $this->__initRoleAssignments();
617 
618  $all = array();
619  foreach($this->assignments_obj->getAssignments() as $assignment)
620  {
621  if(strlen($assignment['domain']) and $assignment['role'])
622  {
623  $all[] = $assignment['domain'].' -> '.ilObjRole::_lookupTitle($assignment['role']);
624  }
625  }
626 
627  if(strlen($this->assignments_obj->getDefaultRole()))
628  {
629  $all[] = $this->lng->txt('reg_default').' -> '.ilObjRole::_lookupTitle($this->assignments_obj->getDefaultRole());
630  }
631 
632  return $all;
633  }
634 
636  {
637  global $lng;
638 
640 
641  include_once './Services/AccessControl/classes/class.ilObjRole.php';
642 
643  $all = array();
644  foreach(ilObjRole::_lookupRegisterAllowed() as $role)
645  {
646  switch ($this->access_limitations_obj->getMode($role['id']))
647  {
648  case 'absolute':
649  $txt_access_value = $lng->txt('reg_access_limitation_limited_until');
650  $txt_access_value .= " ".ilDatePresentation::formatDate(new ilDateTime($this->access_limitations_obj->getAbsolute($role['id'],IL_CAL_UNIX)));
651  break;
652 
653  case 'relative':
654  $years = $this->access_limitations_obj->getRelative($role['id'],'y');
655  $months = $this->access_limitations_obj->getRelative($role['id'],'m');
656  $days = $this->access_limitations_obj->getRelative($role['id'],'d');
657 
658  $txt_access_value = $lng->txt('reg_access_limitation_limited_time')." ";
659 
660  if ($years)
661  {
662  $txt_access_value .= $years." ";
663  $txt_access_value .= ($years == 1) ? $lng->txt('year') : $lng->txt('years');
664 
665  if ($months)
666  {
667  if ($days)
668  {
669  $txt_access_value .= ", ";
670  }
671  else
672  {
673  $txt_access_value .= " ".$lng->txt('and')." ";
674  }
675  }
676  elseif ($days)
677  {
678  $txt_access_value .= " ".$lng->txt('and')." ";
679  }
680  }
681 
682  if ($months)
683  {
684  $txt_access_value .= $months." ";
685  $txt_access_value .= ($months == 1) ? $lng->txt('month') : $lng->txt('months');
686 
687  if ($days)
688  {
689  $txt_access_value .= " ".$lng->txt('and')." ";
690  }
691  }
692 
693  if ($days)
694  {
695  $txt_access_value .= $days." ";
696  $txt_access_value .= ($days == 1) ? $lng->txt('day') : $lng->txt('days');
697  }
698  break;
699 
700  default:
701  $txt_access_value = $lng->txt('reg_access_limitation_none');
702  break;
703  }
704 
705  $all[] = $role['title'].' ('.$txt_access_value.')';
706  }
707 
708  return $all;
709  }
710 
712  {
713  if(is_object($this->assignments_obj))
714  {
715  return true;
716  }
717 
718  include_once 'Services/Registration/classes/class.ilRegistrationEmailRoleAssignments.php';
719 
720  $this->assignments_obj = new ilRegistrationRoleAssignments();
721  }
722 
724  {
725  if(is_object($this->access_limitations_obj))
726  {
727  return true;
728  }
729 
730  include_once 'Services/Registration/classes/class.ilRegistrationRoleAccessLimitations.php';
731 
732  $this->access_limitations_obj = new ilRegistrationRoleAccessLimitations();
733  }
734 
735  function __buildRoleSelection($assignment_id)
736  {
737  include_once './Services/AccessControl/classes/class.ilObjRole.php';
738 
739  global $rbacreview;
740 
741  $assignments = $this->assignments_obj->getAssignments();
742  $selected = ($assignment_id > 0) ?
743  $assignments[$assignment_id]['role'] :
744  $this->assignments_obj->getDefaultRole();
745 
746  if(!$selected)
747  {
748  $roles[0] = $this->lng->txt('please_choose');
749  }
750 
751  foreach($rbacreview->getGlobalRoles() as $role_id)
752  {
753  if($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, $lng;
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  ilUtil::deliverData(implode("\r\n", $codes), "ilias_registration_codes_".date("d-m-Y").".txt","text/plain");
984  }
985  else
986  {
987  ilUtil::sendFailure($this->lng->txt("registration_export_codes_no_data"));
988  $this->listCodes();
989  }
990  }
991 }
992 ?>