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