ILIAS  Release_5_0_x_branch Revision 61816
 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 {
40 
41  var $ctrl;
42  var $tpl;
43  var $ref_id;
44 
46  {
47  global $ilCtrl,$tpl,$lng;
48 
49  $this->tpl =& $tpl;
50  $this->ctrl =& $ilCtrl;
51 
52  $this->lng =& $lng;
53  $this->lng->loadLanguageModule('administration');
54  $this->lng->loadLanguageModule('registration');
55  $this->lng->loadLanguageModule('user');
56 
57  $this->ref_id = (int) $_GET['ref_id'];
58 
59  $this->registration_settings = new ilRegistrationSettings();
60  }
61 
62  function executeCommand()
63  {
64  $next_class = $this->ctrl->getNextClass($this);
65  $cmd = $this->ctrl->getCmd();
66  switch($next_class)
67  {
68  default:
69  if(!$cmd)
70  {
71  $cmd = 'view';
72  }
73  $this->$cmd();
74  break;
75  }
76  return true;
77  }
78 
83  function setSubTabs($activeTab = 'registration_settings')
84  {
85  global $ilTabs, $lng;
86 
87  $ilTabs->addSubTab("registration_settings",
88  $lng->txt("registration_tab_settings"),
89  $this->ctrl->getLinkTarget($this, 'view'));
90 
91  $ilTabs->addSubTab("registration_codes",
92  $lng->txt("registration_tab_codes"),
93  $this->ctrl->getLinkTarget($this, 'listCodes'));
94 
95  $ilTabs->activateSubTab($activeTab);
96  }
97 
98  function initForm()
99  {
100  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
101 
102  $this->form_gui = new ilPropertyFormGUI();
103  $this->form_gui->setFormAction($this->ctrl->getFormAction($this, 'save'));
104  $this->form_gui->setTitle($this->lng->txt('reg_settings_header'));
105 
106  $reg_type = new ilRadioGroupInputGUI($this->lng->txt('reg_type'), 'reg_type');
107  $reg_type->addOption(new ilRadioOption($this->lng->txt('reg_disabled'), IL_REG_DISABLED));
108  $option = new ilRadioOption($this->lng->txt('reg_direct'), IL_REG_DIRECT);
109  $option->setInfo($this->lng->txt('reg_direct_info'));
110  $cd = new ilCheckboxInputGUI($this->lng->txt('reg_allow_codes'), 'reg_codes_'.IL_REG_DIRECT);
111  $cd->setInfo($this->lng->txt('reg_allow_codes_info'));
112  $option->addSubItem($cd);
113  $reg_type->addOption($option);
114  $option = new ilRadioOption($this->lng->txt('reg_approve'), IL_REG_APPROVE);
115  $option->setInfo($this->lng->txt('reg_approve_info'));
116  $cd = new ilCheckboxInputGUI($this->lng->txt('reg_allow_codes'), 'reg_codes_'.IL_REG_APPROVE);
117  $cd->setInfo($this->lng->txt('reg_allow_codes_info'));
118  $option->addSubItem($cd);
119  $reg_type->addOption($option);
120  $option = new ilRadioOption($this->lng->txt('reg_type_confirmation'), IL_REG_ACTIVATION);
121  $option->setInfo($this->lng->txt('reg_type_confirmation_info'));
122  $lt = new ilNumberInputGUI($this->lng->txt('reg_confirmation_hash_life_time'), 'reg_hash_life_time');
123  $lt->setSize(6); // #8511
124  $lt->setMaxLength(6);
126  $lt->setRequired(true);
127  $lt->setInfo($this->lng->txt('reg_confirmation_hash_life_time_info'));
128  $lt->setSuffix($this->lng->txt('seconds'));
129  $option->addSubItem($lt);
130  $cd = new ilCheckboxInputGUI($this->lng->txt('reg_allow_codes'), 'reg_codes_'.IL_REG_ACTIVATION);
131  $cd->setInfo($this->lng->txt('reg_allow_codes_info'));
132  $option->addSubItem($cd);
133  $reg_type->addOption($option);
134  $option = new ilRadioOption($this->lng->txt('registration_reg_type_codes'), IL_REG_CODES);
135  $option->setInfo($this->lng->txt('registration_reg_type_codes_info'));
136  $reg_type->addOption($option);
137  $this->form_gui->addItem($reg_type);
138 
139  $pwd_gen = new ilCheckboxInputGUI($this->lng->txt('passwd_generation'), 'reg_pwd');
140  $pwd_gen->setValue(1);
141  $pwd_gen->setInfo($this->lng->txt('reg_info_pwd'));
142  $this->form_gui->addItem($pwd_gen);
143 
144  require_once 'Services/Captcha/classes/class.ilCaptchaUtil.php';
145  $cap = new ilCheckboxInputGUI($this->lng->txt('adm_captcha_anonymous_short'), 'activate_captcha_anonym');
146  $cap->setInfo($this->lng->txt('adm_captcha_anonymous_reg'));
147  $cap->setValue(1);
149  {
150  $cap->setAlert(ilCaptchaUtil::getPreconditionsMessage());
151  }
152  $this->form_gui->addItem($cap);
153 
154  $approver = new ilTextInputGUI($this->lng->txt('reg_notification'), 'reg_approver');
155  $approver->setSize(32);
156  $approver->setMaxLength(50);
157  $approver->setInfo($this->lng->txt('reg_notification_info'));
158  $this->form_gui->addItem($approver);
159 
160  $roles = new ilRadioGroupInputGUI($this->lng->txt('reg_role_assignment'), 'reg_role_type');
161  $option = new ilRadioOption($this->lng->txt('reg_fixed'), IL_REG_ROLES_FIXED);
162  $list = new ilCustomInputGUI($this->lng->txt('reg_available_roles'));
163  $edit = $this->ctrl->getLinkTarget($this,'editRoles');
164  $list->setHtml($this->__parseRoleList($this->__prepareRoleList(), $edit));
165  $option->addSubItem($list);
166  $roles->addOption($option);
167  $option = new ilRadioOption($this->lng->txt('reg_email'), IL_REG_ROLES_EMAIL);
168  $list = new ilCustomInputGUI($this->lng->txt('reg_available_roles'));
169  $edit = $this->ctrl->getLinkTarget($this,'editEmailAssignments');
170  $list->setHtml($this->__parseRoleList($this->__prepareAutomaticRoleList(), $edit));
171  $option->addSubItem($list);
172  $roles->addOption($option);
173  $roles->setInfo($this->lng->txt('registration_codes_override_global_info'));
174  $this->form_gui->addItem($roles);
175 
176  $limit = new ilCheckboxInputGUI($this->lng->txt('reg_access_limitations'), 'reg_access_limitation');
177  $limit->setValue(1);
178  $list = new ilCustomInputGUI($this->lng->txt('reg_available_roles'));
179  $edit = $this->ctrl->getLinkTarget($this,'editRoleAccessLimitations');
180  $list->setHtml($this->__parseRoleList($this->__prepareAccessLimitationRoleList(), $edit));
181  $list->setInfo($this->lng->txt('registration_codes_override_global_info'));
182  $limit->addSubItem($list);
183  $this->form_gui->addItem($limit);
184 
185  $domains = new ilTextInputGUI($this->lng->txt('reg_allowed_domains'), 'reg_allowed_domains');
186  $domains->setInfo($this->lng->txt('reg_allowed_domains_info'));
187  $this->form_gui->addItem($domains);
188 
189  $this->form_gui->addCommandButton('save', $this->lng->txt('save'));
190  }
191 
192  function initFormValues()
193  {
194  if($this->registration_settings->roleSelectionEnabled())
195  {
196  $role_type = IL_REG_ROLES_FIXED;
197  }
198  else if ($this->registration_settings->automaticRoleAssignmentEnabled())
199  {
200  $role_type = IL_REG_ROLES_EMAIL;
201  }
202 
203  require_once 'Services/Captcha/classes/class.ilCaptchaUtil.php';
204  $values = array(
205  'reg_type' => $this->registration_settings->getRegistrationType(),
206  'reg_hash_life_time' => (int)$this->registration_settings->getRegistrationHashLifetime(),
207  'reg_pwd' => $this->registration_settings->passwordGenerationEnabled(),
208  'reg_approver' => $this->registration_settings->getApproveRecipientLogins(),
209  'reg_role_type' => $role_type,
210  'reg_access_limitation' => $this->registration_settings->getAccessLimitation(),
211  'reg_allowed_domains' => implode(';', $this->registration_settings->getAllowedDomains()),
212  'activate_captcha_anonym' => ilCaptchaUtil::isActiveForRegistration()
213  );
214 
215  $allow_codes = $this->registration_settings->getAllowCodes();
216  $reg_type = $this->registration_settings->getRegistrationType();
217  if($allow_codes && in_array($reg_type, array(IL_REG_DIRECT, IL_REG_APPROVE, IL_REG_ACTIVATION)))
218  {
219  $values['reg_codes_'.$reg_type] = true;
220  }
221 
222  $this->form_gui->setValuesByArray($values);
223  }
224 
225  function view()
226  {
227  global $ilAccess, $ilErr, $ilCtrl, $ilToolbar, $ilTabs;
228 
229  if(!$ilAccess->checkAccess('read','',$this->ref_id))
230  {
231  $ilErr->raiseError($this->lng->txt("msg_no_perm_read"),$ilErr->MESSAGE);
232  }
233 
234  $this->setSubTabs();
235 
236  // edit new accout mail
237  $ilCtrl->setParameterByClass("ilobjuserfoldergui", "ref_id", USER_FOLDER_ID);
238  $ilToolbar->addButton($this->lng->txt('registration_user_new_account_mail'),
239  $ilCtrl->getLinkTargetByClass(array("iladministrationgui", "ilobjuserfoldergui"), "newAccountMail"));
240  $ilCtrl->setParameterByClass("ilobjuserfoldergui", "ref_id", $_GET["ref_id"]);
241 
242  $this->initForm();
243  $this->initFormValues();
244  $this->tpl->setContent($this->form_gui->getHTML());
245  }
246 
247  function save()
248  {
249  global $ilAccess,$ilErr;
250 
251  if(!$ilAccess->checkAccess('write','',$this->ref_id))
252  {
253  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"),$ilErr->MESSAGE);
254  }
255 
256  $this->registration_settings->setRegistrationType((int) $_POST['reg_type']);
257  $this->registration_settings->setPasswordGenerationStatus((int) $_POST['reg_pwd']);
258  $this->registration_settings->setApproveRecipientLogins(ilUtil::stripSlashes($_POST['reg_approver']));
259  $this->registration_settings->setRoleType((int) $_POST['reg_role_type']);
260  $this->registration_settings->setAccessLimitation((int) $_POST['reg_access_limitation']);
261  $this->registration_settings->setAllowedDomains($_POST['reg_allowed_domains']);
262 
263  $allow_codes = false;
264  if(in_array((int)$_POST['reg_type'], array(IL_REG_DIRECT, IL_REG_APPROVE, IL_REG_ACTIVATION)))
265  {
266  $allow_codes = (bool)$_POST['reg_codes_'.(int)$_POST['reg_type']];
267  }
268  $this->registration_settings->setAllowCodes($allow_codes);
269 
270  if(!preg_match('/^([0]|([1-9][0-9]*))([\.,][0-9][0-9]*)?$/', (int)$_POST['reg_hash_life_time']))
271  $this->registration_settings->setRegistrationHashLifetime(ilRegistrationSettings::REG_HASH_LIFETIME_MIN_VALUE);
272  else
273  $this->registration_settings->setRegistrationHashLifetime(max((int)$_POST['reg_hash_life_time'], ilRegistrationSettings::REG_HASH_LIFETIME_MIN_VALUE));
274 
275  if($error_code = $this->registration_settings->validate())
276  {
277  switch($error_code)
278  {
280 
281  ilUtil::sendFailure($this->lng->txt('reg_unknown_recipients').' '.$this->registration_settings->getUnknown());
282  $this->view();
283  return false;
284 
286 
287  ilUtil::sendFailure($this->lng->txt('reg_approve_needs_recipient').' '.$this->registration_settings->getUnknown());
288  $this->view();
289  return false;
290 
291  }
292  }
293 
294  require_once 'Services/Captcha/classes/class.ilCaptchaUtil.php';
295  ilCaptchaUtil::setActiveForRegistration((bool)$_POST['activate_captcha_anonym']);
296 
297  $this->registration_settings->save();
298  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
299  $this->view();
300 
301  return true;
302  }
303 
304  function editRoles()
305  {
306  include_once './Services/AccessControl/classes/class.ilObjRole.php';
307 
308  global $ilAccess,$ilErr,$rbacreview;
309 
310  if(!$ilAccess->checkAccess('write','',$this->ref_id))
311  {
312  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"),$ilErr->MESSAGE);
313  }
314 
315  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.edit_roles.html','Services/Registration');
316 
317  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
318  $this->tpl->setVariable("TXT_SELECTABLE_ROLES",$this->lng->txt('reg_selectable_roles'));
319  $this->tpl->setVariable("ARR_DOWNRIGHT",ilUtil::getImagePath('arrow_downright.svg'));
320  $this->tpl->setVariable("ACTIONS",$this->lng->txt('actions'));
321  $this->tpl->setVariable("UPDATE",$this->lng->txt('save'));
322  $this->tpl->setVariable("CANCEL",$this->lng->txt('cancel'));
323 
324  $counter = 0;
325  foreach($rbacreview->getGlobalRoles() as $role)
326  {
327  if($role == SYSTEM_ROLE_ID or $role == ANONYMOUS_ROLE_ID)
328  {
329  continue;
330  }
331  $this->tpl->setCurrentBlock("roles");
332  $this->tpl->setVariable("CSSROW",ilUtil::switchColor(++$counter,'tblrow1','tblrow2'));
333  $this->tpl->setVariable("CHECK_ROLE",ilUtil::formCheckbox(ilObjRole::_lookupAllowRegister($role),
334  "roles[$role]",
335  1));
336  $this->tpl->setVariable("ROLE",ilObjRole::_lookupTitle($role));
337  $this->tpl->parseCurrentBlock();
338 
339  }
340  }
341 
342  function updateRoles()
343  {
344  global $ilAccess,$ilErr,$rbacreview;
345 
346  if(!$ilAccess->checkAccess('write','',$this->ref_id))
347  {
348  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"),$ilErr->MESSAGE);
349  }
350  // Minimum one role
351  if(count($_POST['roles']) < 1)
352  {
353  ilUtil::sendFailure($this->lng->txt('msg_last_role_for_registration'));
354  $this->editRoles();
355  return false;
356  }
357  // update allow register
358  foreach($rbacreview->getGlobalRoles() as $role)
359  {
360  if($role_obj = ilObjectFactory::getInstanceByObjId($role,false))
361  {
362  $role_obj->setAllowRegister($_POST['roles'][$role] ? 1 : 0);
363  $role_obj->update();
364  }
365  }
366 
367  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
368  $this->view();
369 
370  return true;
371  }
372 
374  {
375  global $ilAccess,$ilErr,$rbacreview;
376 
377  if(!$ilAccess->checkAccess('write','',$this->ref_id))
378  {
379  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"),$ilErr->MESSAGE);
380  }
381 
382  $this->__initRoleAssignments();
383 
384  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.reg_email_role_assignments.html','Services/Registration');
385  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
386  $this->tpl->setVariable("TXT_EMAIL_ROLE_ASSIGN",$this->lng->txt('reg_email_role_assignment'));
387  $this->tpl->setVariable("TXT_MAIL",$this->lng->txt('reg_email'));
388  $this->tpl->setVariable("TXT_ROLE",$this->lng->txt('obj_role'));
389  $this->tpl->setVariable("TXT_DEFAULT",$this->lng->txt('reg_default'));
390  $this->tpl->setVariable("ARR_DOWNRIGHT",ilUtil::getImagePath('arrow_downright.svg'));
391  $this->tpl->setVariable("TXT_DOMAIN",$this->lng->txt('reg_domain'));
392 
393 
394  $this->tpl->setVariable("BTN_DELETE",$this->lng->txt('delete'));
395  $this->tpl->setVariable("BTN_SAVE",$this->lng->txt('save'));
396  $this->tpl->setVariable("BTN_ADD",$this->lng->txt('reg_add_assignment'));
397  $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt('cancel'));
398 
399  $counter = 0;
400  foreach($this->assignments_obj->getAssignments() as $assignment)
401  {
402  $this->tpl->setCurrentBlock("roles");
403  $this->tpl->setVariable("CSSROW",ilUtil::switchColor(++$counter,'tblrow1','tblrow1'));
404  $this->tpl->setVariable("ASSIGN_ID",$assignment['id']);
405  $this->tpl->setVariable("DOMAIN",$assignment['domain']);
406  $this->tpl->setVariable("CHECK_ROLE",ilUtil::formCheckbox(0,'del_assign[]',$assignment['id']));
407  $this->tpl->setVariable("ROLE_SEL",$this->__buildRoleSelection($assignment['id']));
408  $this->tpl->parseCurrentBlock();
409  }
410 
411  $this->tpl->setVariable("DEF_CSSROW",ilUtil::switchColor(++$counter,'tblrow1','tblrow1'));
412  $this->tpl->setVariable("TXT_DEFAULT",$this->lng->txt('default'));
413  $this->tpl->setVariable("DEF_ROLE",$this->__buildRoleSelection(-1));
414  }
415 
417  {
418  global $lng,$ilAccess,$ilErr,$rbacreview;
419 
420  if(!$ilAccess->checkAccess('write','',$this->ref_id))
421  {
422  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"),$ilErr->MESSAGE);
423  }
424 
426 
427  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.reg_role_access_limitations.html','Services/Registration');
428 
429  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
430  $this->tpl->setVariable("TXT_REG_ROLE_ACCESS_LIMITATIONS",$lng->txt('reg_role_access_limitations'));
431  $this->tpl->setVariable("TXT_ROLE",$lng->txt('obj_role'));
432  $this->tpl->setVariable("TXT_ACCESS_LIMITATION_MODE",$lng->txt('reg_access_limitation_mode'));
433 
434  $this->tpl->setVariable("BTN_SAVE",$lng->txt('save'));
435  $this->tpl->setVariable("BTN_CANCEL",$lng->txt('cancel'));
436 
437  $counter = 0;
438  include_once './Services/AccessControl/classes/class.ilObjRole.php';
439 
440  foreach(ilObjRole::_lookupRegisterAllowed() as $role)
441  {
442  $this->tpl->setCurrentBlock("roles");
443  $this->tpl->setVariable("CSSROW",ilUtil::switchColor(++$counter,'tblrow1','tblrow1'));
444  $this->tpl->setVariable("ROLE_ID",$role['id']);
445  $this->tpl->setVariable("ROLE_TITLE",$role['title']);
446  $this->tpl->setVariable("SEL_ACCESS_LIMITATION",$this->__buildAccessLimitationSelection($role['id']));
447  $this->tpl->setVariable("CSS_DISPLAY_ABSOLUTE",($this->access_limitations_obj->getMode($role['id']) == 'absolute') ? 'inline' : 'none');
448  $this->tpl->setVariable("CSS_DISPLAY_RELATIVE",($this->access_limitations_obj->getMode($role['id']) == 'relative') ? 'inline' : 'none');
449  $this->tpl->setVariable("CSS_DISPLAY_UNLIMITED",($this->access_limitations_obj->getMode($role['id']) == 'unlimited') ? 'inline' : 'none');
450  $this->tpl->setVariable("TXT_ACCESS_LIMITATION_UNLIMITED", $lng->txt('reg_access_limitation_none'));
451 
452  $date = $this->__prepareDateSelect($this->access_limitations_obj->getAbsolute($role['id']));
453  $this->tpl->setVariable("SEL_ACCESS_LIMITATION_ABSOLUTE",ilUtil::makeDateSelect('access_limitation_absolute_'.$role['id'],$date['y'],$date['m'],$date['d'],'2007'));
454 
455  $this->tpl->setVariable("TXT_DAYS",$lng->txt('days'));
456  $this->tpl->setVariable("TXT_MONTHS",$lng->txt('months'));
457  $this->tpl->setVariable("TXT_YEARS",$lng->txt('years'));
458 
459  $this->tpl->setVariable("DAYS",$this->access_limitations_obj->getRelative($role['id'],'d'));
460  $this->tpl->setVariable("MONTHS",$this->access_limitations_obj->getRelative($role['id'],'m'));
461  $this->tpl->setVariable("YEARS",$this->access_limitations_obj->getRelative($role['id'],'y'));
462  $this->tpl->parseCurrentBlock();
463  }
464  }
465 
466  function addAssignment()
467  {
468  global $ilAccess,$ilErr,$rbacreview;
469 
470  if(!$ilAccess->checkAccess('write','',$this->ref_id))
471  {
472  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"),$ilErr->MESSAGE);
473  }
474 
475  $this->__initRoleAssignments();
476  $this->assignments_obj->add();
477 
478  ilUtil::sendSuccess($this->lng->txt('reg_added_assignment'));
479  $this->editEmailAssignments();
480 
481  return true;
482  }
483 
484  function deleteAssignment()
485  {
486  global $ilAccess,$ilErr,$rbacreview;
487 
488  if(!$ilAccess->checkAccess('write','',$this->ref_id))
489  {
490  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"),$ilErr->MESSAGE);
491  }
492 
493  if(!count($_POST['del_assign']))
494  {
495  ilUtil::sendFailure($this->lng->txt('reg_select_one'));
496  $this->editEmailAssignments();
497  return false;
498  }
499 
500  $this->__initRoleAssignments();
501 
502  foreach($_POST['del_assign'] as $assignment_id)
503  {
504  $this->assignments_obj->delete($assignment_id);
505  }
506 
507  ilUtil::sendSuccess($this->lng->txt('reg_deleted_assignment'));
508  $this->editEmailAssignments();
509 
510  return true;
511  }
512 
513  function saveAssignment()
514  {
515  global $ilAccess,$ilErr,$rbacreview;
516 
517  if(!$ilAccess->checkAccess('write','',$this->ref_id))
518  {
519  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"),$ilErr->MESSAGE);
520  }
521 
522  $this->__initRoleAssignments();
523 
524  if (!is_array($_POST['domain']))
525  {
526  $_POST['domain'] = array();
527  }
528 
529  foreach($_POST['domain'] as $id => $data)
530  {
531  $this->assignments_obj->setDomain($id,ilUtil::stripSlashes($_POST['domain'][$id]['domain']));
532  $this->assignments_obj->setRole($id,ilUtil::stripSlashes($_POST['role'][$id]['role']));
533  }
534  $this->assignments_obj->setDefaultRole((int) $_POST['default_role']);
535 
536  if($err = $this->assignments_obj->validate())
537  {
538  switch($err)
539  {
541  ilUtil::sendFailure($this->lng->txt('reg_missing_domain'));
542  break;
543 
544  case IL_REG_MISSING_ROLE:
545  ilUtil::sendFailure($this->lng->txt('reg_missing_role'));
546  break;
547  }
548  $this->editEmailAssignments();
549  return false;
550  }
551 
552 
553  $this->assignments_obj->save();
554  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
555  $this->view();
556  return true;
557  }
558 
560  {
561  global $ilAccess,$ilErr,$rbacreview;
562 
563  if(!$ilAccess->checkAccess('write','',$this->ref_id))
564  {
565  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"),$ilErr->MESSAGE);
566  }
567 
569 
570  include_once './Services/AccessControl/classes/class.ilObjRole.php';
571 
572  foreach(ilObjRole::_lookupRegisterAllowed() as $role)
573  {
574  $this->access_limitations_obj->setMode($_POST['access_limitation_mode_'.$role['id']],$role['id']);
575  $this->access_limitations_obj->setAbsolute($_POST['access_limitation_absolute_'.$role['id']],$role['id']);
576  $this->access_limitations_obj->setRelative($_POST['access_limitation_relative_'.$role['id']],$role['id']);
577  }
578 
579  //var_dump("<pre>",$_POST,$this->access_limitations_obj->getAbsolute(4),time(),"</pre>");exit;
580 
581  if($err = $this->access_limitations_obj->validate())
582  {
583  switch($err)
584  {
586  ilUtil::sendFailure($this->lng->txt('reg_access_limitation_missing_mode'));
587  break;
588 
590  ilUtil::sendFailure($this->lng->txt('reg_access_limitation_out_of_date'));
591  break;
592  }
593  $this->editRoleAccessLimitations();
594  return false;
595  }
596 
597 
598  $this->access_limitations_obj->save();
599  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
600  $this->view();
601  return true;
602  }
603 
604  function __parseRoleList($roles, $url)
605  {
606  $tpl = new ilTemplate('tpl.registration_roles.html', true, true,'Services/Registration');
607 
608  $tpl->setVariable("EDIT", $this->lng->txt("edit"));
609  $tpl->setVariable("LINK_EDIT", $url);
610 
611  if (is_array($roles) && sizeof($roles))
612  {
613  foreach($roles as $role)
614  {
615  $tpl->setCurrentBlock("list_item");
616  $tpl->setVariable("LIST_ITEM_ITEM", $role);
617  $tpl->parseCurrentBlock();
618  }
619  }
620  else
621  {
622  $tpl->setVariable("NONE", $this->lng->txt('none'));
623  }
624 
625  return $tpl->get();
626  }
627 
628  function __prepareRoleList()
629  {
630  include_once './Services/AccessControl/classes/class.ilObjRole.php';
631 
632  $all = array();
633  foreach(ilObjRole::_lookupRegisterAllowed() as $role)
634  {
635  $all[] = $role['title'];
636  }
637  return $all;
638  }
639 
641  {
642  include_once './Services/AccessControl/classes/class.ilObjRole.php';
643  $this->__initRoleAssignments();
644 
645  $all = array();
646  foreach($this->assignments_obj->getAssignments() as $assignment)
647  {
648  if(strlen($assignment['domain']) and $assignment['role'])
649  {
650  $all[] = $assignment['domain'].' -> '.ilObjRole::_lookupTitle($assignment['role']);
651  }
652  }
653 
654  if(strlen($this->assignments_obj->getDefaultRole()))
655  {
656  $all[] = $this->lng->txt('reg_default').' -> '.ilObjRole::_lookupTitle($this->assignments_obj->getDefaultRole());
657  }
658 
659  return $all;
660  }
661 
663  {
664  global $lng;
665 
667 
668  include_once './Services/AccessControl/classes/class.ilObjRole.php';
669 
670  $all = array();
671  foreach(ilObjRole::_lookupRegisterAllowed() as $role)
672  {
673  switch ($this->access_limitations_obj->getMode($role['id']))
674  {
675  case 'absolute':
676  $txt_access_value = $lng->txt('reg_access_limitation_limited_until');
677  $txt_access_value .= " ".ilDatePresentation::formatDate(new ilDateTime($this->access_limitations_obj->getAbsolute($role['id'],IL_CAL_UNIX)));
678  break;
679 
680  case 'relative':
681  $years = $this->access_limitations_obj->getRelative($role['id'],'y');
682  $months = $this->access_limitations_obj->getRelative($role['id'],'m');
683  $days = $this->access_limitations_obj->getRelative($role['id'],'d');
684 
685  $txt_access_value = $lng->txt('reg_access_limitation_limited_time')." ";
686 
687  if ($years)
688  {
689  $txt_access_value .= $years." ";
690  $txt_access_value .= ($years == 1) ? $lng->txt('year') : $lng->txt('years');
691 
692  if ($months)
693  {
694  if ($days)
695  {
696  $txt_access_value .= ", ";
697  }
698  else
699  {
700  $txt_access_value .= " ".$lng->txt('and')." ";
701  }
702  }
703  elseif ($days)
704  {
705  $txt_access_value .= " ".$lng->txt('and')." ";
706  }
707  }
708 
709  if ($months)
710  {
711  $txt_access_value .= $months." ";
712  $txt_access_value .= ($months == 1) ? $lng->txt('month') : $lng->txt('months');
713 
714  if ($days)
715  {
716  $txt_access_value .= " ".$lng->txt('and')." ";
717  }
718  }
719 
720  if ($days)
721  {
722  $txt_access_value .= $days." ";
723  $txt_access_value .= ($days == 1) ? $lng->txt('day') : $lng->txt('days');
724  }
725  break;
726 
727  default:
728  $txt_access_value = $lng->txt('reg_access_limitation_none');
729  break;
730  }
731 
732  $all[] = $role['title'].' ('.$txt_access_value.')';
733  }
734 
735  return $all;
736  }
737 
739  {
740  if(is_object($this->assignments_obj))
741  {
742  return true;
743  }
744 
745  include_once 'Services/Registration/classes/class.ilRegistrationEmailRoleAssignments.php';
746 
747  $this->assignments_obj = new ilRegistrationRoleAssignments();
748  }
749 
751  {
752  if(is_object($this->access_limitations_obj))
753  {
754  return true;
755  }
756 
757  include_once 'Services/Registration/classes/class.ilRegistrationRoleAccessLimitations.php';
758 
759  $this->access_limitations_obj = new ilRegistrationRoleAccessLimitations();
760  }
761 
762  function __buildRoleSelection($assignment_id)
763  {
764  include_once './Services/AccessControl/classes/class.ilObjRole.php';
765 
766  global $rbacreview;
767 
768  $assignments = $this->assignments_obj->getAssignments();
769  $selected = ($assignment_id > 0) ?
770  $assignments[$assignment_id]['role'] :
771  $this->assignments_obj->getDefaultRole();
772 
773  if(!$selected)
774  {
775  $roles[0] = $this->lng->txt('please_choose');
776  }
777 
778  foreach($rbacreview->getGlobalRoles() as $role_id)
779  {
780  if($role_id == ANONYMOUS_ROLE_ID)
781  {
782  continue;
783  }
784  $roles[$role_id] = ilObjRole::_lookupTitle($role_id);
785  }
786 
787  if($assignment_id > 0)
788  {
789  return ilUtil::formSelect($selected,
790  "role[$assignment_id][role]",
791  $roles,false,true);
792  }
793  else
794  {
795  return ilUtil::formSelect($selected,
796  "default_role",
797  $roles,false,true);
798  }
799  }
800 
801  function __buildAccessLimitationSelection($a_role_id)
802  {
803  global $lng;
804 
805  $options = array(
806  'null' => $lng->txt('please_choose'),
807  'unlimited' => $lng->txt('reg_access_limitation_mode_unlimited'),
808  'absolute' => $lng->txt('reg_access_limitation_mode_absolute'),
809  'relative' => $lng->txt('reg_access_limitation_mode_relative')
810  );
811 
812  $attribs = array('onchange' => 'displayAccessLimitationSelectionForm(document.cmd.access_limitation_mode_'.$a_role_id.','.$a_role_id.')');
813 
814  $selected = $this->access_limitations_obj->getMode($a_role_id);
815 
816  return ilUtil::formSelect($selected,'access_limitation_mode_'.$a_role_id,$options,false,true,0,"",$attribs);
817 
818  }
819 
820  function __prepareDateSelect($a_unix_time)
821  {
822  if (!$a_unix_time)
823  {
824  $a_unix_time = time();
825  }
826 
827  return array('y' => date('Y',$a_unix_time),
828  'm' => date('n',$a_unix_time),
829  'd' => date('d',$a_unix_time));
830  }
831 
832  function listCodes()
833  {
834  global $ilAccess, $ilErr, $ilCtrl, $ilToolbar;
835 
836  if(!$ilAccess->checkAccess('read','',$this->ref_id))
837  {
838  $ilErr->raiseError($this->lng->txt("msg_no_perm_read"),$ilErr->MESSAGE);
839  }
840 
841  $this->setSubTabs('registration_codes');
842 
843  $ilToolbar->addButton($this->lng->txt("registration_codes_add"),
844  $this->ctrl->getLinkTarget($this, "addCodes"));
845 
846  include_once("./Services/Registration/classes/class.ilRegistrationCodesTableGUI.php");
847  $ctab = new ilRegistrationCodesTableGUI($this, "listCodes");
848  $this->tpl->setContent($ctab->getHTML());
849  }
850 
851  function initAddCodesForm()
852  {
853  global $rbacreview, $ilObjDataCache, $lng;
854 
855  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
856 
857  $this->form_gui = new ilPropertyFormGUI();
858  $this->form_gui->setFormAction($this->ctrl->getFormAction($this, 'createCodes'));
859  $this->form_gui->setTitle($this->lng->txt('registration_codes_edit_header'));
860 
861  $count = new ilNumberInputGUI($this->lng->txt('registration_codes_number'), 'reg_codes_number');
862  $count->setSize(4);
863  $count->setMaxLength(4);
864  $count->setMinValue(1);
865  $count->setMaxValue(1000);
866  $count->setRequired(true);
867  $this->form_gui->addItem($count);
868 
869  // type
870  $code_type = new ilCheckboxGroupInputGUI($this->lng->txt('registration_codes_type'),'code_type');
871  $code_type->setRequired(TRUE);
872 
873  $code_type->addOption(
874  new ilCheckboxOption(
875  $this->lng->txt('registration_codes_type_reg'),
877  $this->lng->txt('registration_codes_type_reg_info'))
878  );
879  $code_type->addOption(
880  new ilCheckboxOption(
881  $this->lng->txt('registration_codes_type_ext'),
883  $this->lng->txt('registration_codes_type_ext_info'))
884  );
885  $this->form_gui->addItem($code_type);
886 
887 
888  $sec = new ilFormSectionHeaderGUI();
889  $sec->setTitle($this->lng->txt('registration_codes_roles_title'));
890  $this->form_gui->addItem($sec);
891 
892  include_once './Services/AccessControl/classes/class.ilObjRole.php';
893  $options = array("" => $this->lng->txt('registration_codes_no_assigned_role'));
894  foreach($rbacreview->getGlobalRoles() as $role_id)
895  {
896  if(!in_array($role_id, array(SYSTEM_ROLE_ID, ANONYMOUS_ROLE_ID)))
897  {
898  $options[$role_id] = $ilObjDataCache->lookupTitle($role_id);
899  }
900  }
901  $roles = new ilSelectInputGUI($this->lng->txt("registration_codes_roles"), "reg_codes_role");
902  $roles->setInfo($this->lng->txt("registration_codes_override_info"));
903  $roles->setOptions($options);
904  $this->form_gui->addItem($roles);
905 
906  $local = new ilTextInputGUI($this->lng->txt("registration_codes_roles_local"), "reg_codes_local");
907  $local->setMulti(true);
908  $local->setDataSource($this->ctrl->getLinkTarget($this, "getLocalRoleAutoComplete", "", true));
909  $this->form_gui->addItem($local);
910 
911 
912  $sec = new ilFormSectionHeaderGUI();
913  $sec->setTitle($this->lng->txt('reg_access_limitations'));
914  $this->form_gui->addItem($sec);
915 
916  $limit = new ilRadioGroupInputGUI($this->lng->txt("reg_access_limitation_mode"), "reg_limit");
917  $limit->setInfo($this->lng->txt("registration_codes_override_info"));
918  $this->form_gui->addItem($limit);
919 
920  $opt = new ilRadioOption($this->lng->txt("registration_codes_roles_limitation_none"), "none");
921  $limit->addOption($opt);
922 
923  $opt = new ilRadioOption($this->lng->txt("reg_access_limitation_none"), "unlimited");
924  $limit->addOption($opt);
925 
926  $opt = new ilRadioOption($this->lng->txt("reg_access_limitation_mode_absolute"), "absolute");
927  $limit->addOption($opt);
928 
929  $dt = new ilDateTimeInputGUI($this->lng->txt("reg_access_limitation_mode_absolute_target"), "abs_date");
930  $dt->setRequired(true);
931  $opt->addSubItem($dt);
932 
933  $opt = new ilRadioOption($this->lng->txt("reg_access_limitation_mode_relative"), "relative");
934  $limit->addOption($opt);
935 
936  $days = new ilTextInputGUI("", "rel_date[d]");
937  $days->setSize(5);
938  $days->setSuffix($this->lng->txt("days"));
939 
940  $mon = new ilTextInputGUI("", "rel_date[m]");
941  $mon->setSize(5);
942  $mon->setSuffix($this->lng->txt("months"));
943 
944  $yr = new ilTextInputGUI("", "rel_date[y]");
945  $yr->setSize(5);
946  $yr->setSuffix($this->lng->txt("years"));
947 
948  // custom input won't reload
949  if(is_array($_POST["rel_date"]))
950  {
951  $days->setValue($_POST["rel_date"]["d"]);
952  $mon->setValue($_POST["rel_date"]["m"]);
953  $yr->setValue($_POST["rel_date"]["y"]);
954  }
955 
956  $dur = new ilCustomInputGUI($this->lng->txt("reg_access_limitation_mode_relative_target"));
957  $dur->setRequired(true);
958  $dur->setHTML(
959  $days->getToolbarHTML()." ".
960  $mon->getToolbarHTML()." ".
961  $yr->getToolbarHTML()
962  );
963  $opt->addSubItem($dur);
964 
965  $this->form_gui->addCommandButton('createCodes', $this->lng->txt('create'));
966  $this->form_gui->addCommandButton('listCodes',$this->lng->txt('cancel'));
967  }
968 
969  // see ilRoleAutoCompleteInputGUI
971  {
972  $q = $_REQUEST["term"];
973  include_once("./Services/AccessControl/classes/class.ilRoleAutoComplete.php");
974  $list = ilRoleAutoComplete::getList($q);
975  echo $list;
976  exit;
977  }
978 
979  function addCodes()
980  {
981  global $ilAccess, $ilErr;
982 
983  if(!$ilAccess->checkAccess('write', '', $this->ref_id))
984  {
985  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"), $ilErr->MESSAGE);
986  }
987 
988  $this->setSubTabs('registration_codes');
989 
990  $this->initAddCodesForm();
991 
992  // default
993  $limit = $this->form_gui->getItemByPostVar("reg_limit");
994  $limit->setValue("none");
995 
996  $this->tpl->setContent($this->form_gui->getHTML());
997  }
998 
999  function createCodes()
1000  {
1001  global $ilAccess, $ilErr, $rbacreview;
1002 
1003  if(!$ilAccess->checkAccess('write', '', $this->ref_id))
1004  {
1005  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"), $ilErr->MESSAGE);
1006  }
1007 
1008  $this->setSubTabs('registration_codes');
1009 
1010  $this->initAddCodesForm();
1011  $valid = $this->form_gui->checkInput();
1012  if($valid)
1013  {
1014  $number = $this->form_gui->getInput('reg_codes_number');
1015  $role = $this->form_gui->getInput('reg_codes_role');
1016  $local = $this->form_gui->getInput("reg_codes_local");
1017 
1018  if(is_array($local))
1019  {
1020  $role_ids = array();
1021  foreach(array_unique($local) as $item)
1022  {
1023  if(trim($item))
1024  {
1025  $role_id = $rbacreview->roleExists($item);
1026  if($role_id)
1027  {
1028  $role_ids[] = $role_id;
1029  }
1030  }
1031  }
1032  if(sizeof($role_ids))
1033  {
1034  $local = $role_ids;
1035  }
1036  }
1037 
1038  $date = null;
1039  $limit = $this->form_gui->getInput("reg_limit");
1040  switch($limit)
1041  {
1042  case "absolute":
1043  $date = $this->form_gui->getInput("abs_date");
1044  $date = $date["date"];
1045  if($date < date("Y-m-d"))
1046  {
1047  $valid = false;
1048  }
1049  break;
1050 
1051  case "relative":
1052  $date = $this->form_gui->getInput("rel_date");
1053  if(!array_sum($date))
1054  {
1055  $valid = false;
1056  }
1057  break;
1058 
1059  case "none":
1060  $limit = null;
1061  break;
1062  }
1063  }
1064 
1065  if($valid)
1066  {
1067  include_once './Services/Registration/classes/class.ilRegistrationCode.php';
1068 
1069  $stamp = time();
1070  for($loop = 1; $loop <= $number; $loop++)
1071  {
1072  $code_types = (array) $this->form_gui->getInput('code_type');
1073 
1075  $role,
1076  $stamp,
1077  $local,
1078  $limit,
1079  $date,
1080  in_array(self::CODE_TYPE_REGISTRATION, $code_types) ? TRUE : FALSE,
1081  in_array(self::CODE_TYPE_EXTENSION, $code_types) ? TRUE : FALSE
1082  );
1083  }
1084 
1085  ilUtil::sendSuccess($this->lng->txt('saved_successfully'), true);
1086  $this->ctrl->redirect($this, "listCodes");
1087  }
1088  else
1089  {
1090  $this->form_gui->setValuesByPost();
1091  $this->tpl->setContent($this->form_gui->getHtml());
1092  }
1093  }
1094 
1095  function deleteCodes()
1096  {
1097  include_once './Services/Registration/classes/class.ilRegistrationCode.php';
1099 
1100  ilUtil::sendSuccess($this->lng->txt('info_deleted'), true);
1101  $this->ctrl->redirect($this, "listCodes");
1102  }
1103 
1105  {
1106  global $ilErr, $ilias;
1107 
1108  if(!isset($_POST["id"]))
1109  {
1110  $ilErr->raiseError($this->lng->txt("no_checkbox"), $ilErr->MESSAGE);
1111  }
1112 
1113  $this->setSubTabs('registration_codes');
1114 
1115  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
1116  $gui = new ilConfirmationGUI();
1117  $gui->setHeaderText($this->lng->txt("info_delete_sure"));
1118  $gui->setCancel($this->lng->txt("cancel"), "listCodes");
1119  $gui->setConfirm($this->lng->txt("confirm"), "deleteCodes");
1120  $gui->setFormAction($this->ctrl->getFormAction($this, "deleteCodes"));
1121 
1122  include_once './Services/Registration/classes/class.ilRegistrationCode.php';
1124  foreach($data as $code)
1125  {
1126  $gui->addItem("id[]", $code["code_id"], $code["code"]);
1127  }
1128 
1129  $this->tpl->setContent($gui->getHTML());
1130  }
1131 
1132  function resetCodesFilter()
1133  {
1134  include_once("./Services/Registration/classes/class.ilRegistrationCodesTableGUI.php");
1135  $utab = new ilRegistrationCodesTableGUI($this, "listCodes");
1136  $utab->resetOffset();
1137  $utab->resetFilter();
1138 
1139  $this->listCodes();
1140  }
1141 
1142  function applyCodesFilter()
1143  {
1144  include_once("./Services/Registration/classes/class.ilRegistrationCodesTableGUI.php");
1145  $utab = new ilRegistrationCodesTableGUI($this, "listCodes");
1146  $utab->resetOffset();
1147  $utab->writeFilterToSession();
1148 
1149  $this->listCodes();
1150  }
1151 
1152  function exportCodes()
1153  {
1154  global $ilAccess, $ilErr;
1155 
1156  if(!$ilAccess->checkAccess('read', '', $this->ref_id))
1157  {
1158  $ilErr->raiseError($this->lng->txt("msg_no_perm_read"), $ilErr->MESSAGE);
1159  }
1160 
1161  include_once("./Services/Registration/classes/class.ilRegistrationCodesTableGUI.php");
1162  $utab = new ilRegistrationCodesTableGUI($this, "listCodes");
1163 
1164  include_once './Services/Registration/classes/class.ilRegistrationCode.php';
1165  $codes = ilRegistrationCode::getCodesForExport($utab->filter["code"], $utab->filter["role"], $utab->filter["generated"], $utab->filter["alimit"]);
1166 
1167  if(sizeof($codes))
1168  {
1169  ilUtil::deliverData(implode("\r\n", $codes), "ilias_registration_codes_".date("d-m-Y").".txt","text/plain");
1170  }
1171  else
1172  {
1173  ilUtil::sendFailure($this->lng->txt("registration_export_codes_no_data"));
1174  $this->listCodes();
1175  }
1176  }
1177 }
1178 ?>