ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAccountRegistrationGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2008 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 
38 require_once './Services/Registration/classes/class.ilRegistrationSettings.php';
39 require_once "./Services/User/classes/class.ilUserAgreement.php";
40 
42 {
43  var $ctrl;
44  var $tpl;
45 
46  private $display_pdata = false;
47  private $display_cdata = false;
48  private $display_odata = false;
49 
50  public function __construct()
51  {
52  global $ilCtrl,$tpl,$lng;
53 
54  $this->tpl =& $tpl;
55 
56  $this->ctrl =& $ilCtrl;
57  $this->ctrl->saveParameter($this,'lang');
58 
59  $this->lng =& $lng;
60  $this->lng->loadLanguageModule('registration');
61 
62  $this->registration_settings = new ilRegistrationSettings();
63  }
64 
65  function executeCommand()
66  {
67  global $ilErr, $tpl;
68 
69  if($this->registration_settings->getRegistrationType() == IL_REG_DISABLED)
70  {
71  $ilErr->raiseError($this->lng->txt('reg_disabled'),$ilErr->FATAL);
72  }
73 
74  $next_class = $this->ctrl->getNextClass($this);
75  $cmd = $this->ctrl->getCmd();
76 
77  switch($next_class)
78  {
79  default:
80  if($cmd)
81  {
82  $this->$cmd();
83  }
84  else
85  {
86  $this->displayForm();
87  }
88  break;
89  }
90  $tpl->show();
91  return true;
92  }
93 
94  function login()
95  {
96  global $ilias,$lng,$ilLog;
97 
98  $ilLog->write("Entered login");
99 
100  $this->tpl->addBlockFile("CONTENT", "content", "tpl.usr_registered.html");
101 
102  $this->tpl->setVariable("IMG_USER",
103  ilUtil::getImagePath("icon_usr_b.gif"));
104  $this->tpl->setVariable("TXT_PAGEHEADLINE", $lng->txt("registration"));
105  $this->tpl->setVariable("TXT_WELCOME", $lng->txt("welcome").", ".$this->userObj->getTitle()."!");
106 
107  if ($this->registration_settings->getRegistrationType() == IL_REG_DIRECT and
108  !$this->registration_settings->passwordGenerationEnabled())
109  {
110  $this->tpl->setCurrentBlock("activation");
111  $this->tpl->setVariable("TXT_REGISTERED", $lng->txt("txt_registered"));
112  $this->tpl->setVariable("FORMACTION", "login.php?cmd=post&target=".$_GET["target"]);
113  $this->tpl->setVariable("TARGET","target=\"_parent\"");
114  $this->tpl->setVariable("TXT_LOGIN", $lng->txt("login_to_ilias"));
115  $this->tpl->setVariable("USERNAME",$this->userObj->getLogin());
116  $this->tpl->setVariable("PASSWORD",$_POST["user"]['passwd']);
117  $this->tpl->parseCurrentBlock();
118  }
119  else if ($this->registration_settings->getRegistrationType() == IL_REG_APPROVE)
120  {
121  $this->tpl->setVariable("TXT_REGISTERED", $lng->txt("txt_submitted"));
122  }
123  else if($this->registration_settings->getRegistrationType() == IL_REG_ACTIVATION)
124  {
125  $this->tpl->setVariable("TXT_REGISTERED", sprintf($lng->txt("reg_confirmation_link_successful"), './login.php'));
126  $this->tpl->setVariable("REDIRECT_URL", './login.php');
127  }
128  else
129  {
130  $this->tpl->setVariable("TXT_REGISTERED", $lng->txt("txt_registered_passw_gen"));
131  }
132  }
133 
134  private function getRegistrationFieldsArray()
135  {
136  $data = array();
137  $data["fields"] = array();
138  $data["fields"]["login"] = "";
139 
140  if (!$this->registration_settings->passwordGenerationEnabled())
141  {
142  $data["fields"]["passwd"] = "";
143  $data["fields"]["passwd2"] = "";
144  }
145 
146  $data["fields"]["title"] = "";
147  $data["fields"]["gender"] = "";
148  $data["fields"]["firstname"] = "";
149  $data["fields"]["lastname"] = "";
150  $data["fields"]["institution"] = "";
151  $data["fields"]["department"] = "";
152  $data["fields"]["street"] = "";
153  $data["fields"]["city"] = "";
154  $data["fields"]["zipcode"] = "";
155  $data["fields"]["country"] = "";
156  $data["fields"]["phone_office"] = "";
157  $data["fields"]["phone_home"] = "";
158  $data["fields"]["phone_mobile"] = "";
159  $data["fields"]["fax"] = "";
160  $data["fields"]["email"] = "";
161  $data["fields"]["hobby"] = "";
162  $data["fields"]["referral_comment"] = "";
163  $data["fields"]["matriculation"] = "";
164  $data["fields"]["delicious"] = "";
165 
166  return $data;
167  }
168 
169  function displayForm()
170  {
171  global $ilias,$lng,$ObjDefinition,$ilSetting;
172 
173  $this->tpl->addBlockFile("CONTENT", "content", "tpl.usr_registration.html");
174  $this->tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
175 
176  //load ILIAS settings
177  $settings = $ilias->getAllSettings();
178 
179  $this->__showRoleSelection();
180 
182 
183  // fill presets
184  foreach((array)$data["fields"] as $key => $val)
185  {
186  if(!in_array($key, array('login')))
187  {
188  // dont show fields, which are not enabled for registration
189  if( isset($settings['require_' . $key]) && (int)$settings['require_' . $key] ||
190  (int)$ilSetting->get('usr_settings_visib_reg_' . $key, '1') ||
191  in_array($key, array('passwd', 'passwd2')) ||
192  $key == 'email' && (
193  $this->registration_settings->passwordGenerationEnabled() ||
194  $this->registration_settings->getRegistrationType() == IL_REG_ACTIVATION ||
195  $this->registration_settings->getRegistrationType() == IL_REG_APPROVE
196  )
197  ){
198  $this->tpl->setCurrentBlock($key."_section");
199  }
200  else
201  {
202  continue;
203  }
204  }
205 
206  $str = $lng->txt($key);
207  if ($key == 'title')
208  {
209  $str = $lng->txt('person_title');
210  }
211 
212  // check to see if dynamically required
213  if (((isset($settings['require_' . $key]) &&
214  (int)$settings['require_' . $key]))
215  || in_array($key, array('login', 'passwd')) ||
216  ($key == 'email' && ($this->registration_settings->passwordGenerationEnabled() ||
217  $this->registration_settings->getRegistrationType() == IL_REG_ACTIVATION ||
218  $this->registration_settings->getRegistrationType() == IL_REG_APPROVE )))
219  {
220  $str = $str . '<span class="asterisk">*</span>';
221  }
222 
223  if($key == 'passwd2')
224  {
225  // text label for passwd2 is nonstandard
226  $str = $lng->txt('retype_password');
227  $str = $str . '<span class="asterisk">*</span>';
228  }
229 
230  $this->tpl->setVariable("TXT_".strtoupper($key), $str);
231  $this->tpl->setVariable(strtoupper($key), ilUtil::prepareFormOutput($_POST['user'][$key],true));
232 
233  if($key == 'matriculation' || $key == 'delicious')
234  {
235  $this->display_odata = true;
236  }
237  else if(in_array($key, array('title', 'gender', 'firstname', 'lastname')))
238  {
239  $this->display_pdata = true;
240  }
241  else if(in_array($key, array('institution', 'department', 'street', 'city',
242  'zipcode', 'country', 'phone_office', 'phone_home',
243  'phone_mobile', 'fax', 'email', 'hobby', 'referral_comment')))
244  {
245  $this->display_cdata = true;
246  }
247 
248  if($key == 'gender')
249  {
250  $this->tpl->setVariable('TXT_GENDER_F', $lng->txt('gender_f'));
251  $this->tpl->setVariable('TXT_GENDER_M', $lng->txt('gender_m'));
252 
253  // FILL SAVED VALUES IN CASE OF ERROR
254  if(isset($_POST['user']))
255  {
256  // gender selection
257  $gender = strtoupper($_POST['user']['gender']);
258  if(!empty($gender))
259  {
260  $this->tpl->setVariable('BTN_GENDER_'.$gender, 'checked="checked"');
261  }
262  }
263  }
264 
265  if(!in_array($key, array('login')))
266  {
267  $this->tpl->parseCurrentBlock();
268  }
269  }
270 
271  if($this->registration_settings->passwordGenerationEnabled())
272  {
273  $this->tpl->setCurrentBlock('select_password');
274  $this->tpl->setVariable("TXT_PASSWD_SELECT", $lng->txt("passwd"));
275  $this->tpl->setVariable("TXT_PASSWD_VIA_MAIL", $lng->txt("reg_passwd_via_mail"));
276  $this->tpl->parseCurrentBlock();
277  }
278 
279  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
280  $this->tpl->setVariable("TXT_SAVE", $lng->txt("register"));
281  $this->tpl->setVariable("TXT_REQUIRED_FIELDS", $lng->txt("required_field"));
282  $this->tpl->setVariable("TXT_SETTINGS", $lng->txt("settings"));
283  $this->tpl->setVariable("TXT_LOGIN_DATA", $lng->txt("login_data"));
284  $this->tpl->setVariable("TXT_LANGUAGE",$lng->txt("language"));
285  $this->tpl->setVariable("TXT_OK",$lng->txt("ok"));
286  $this->tpl->setVariable("TXT_CHOOSE_LANGUAGE", $lng->txt("choose_language"));
287  $this->tpl->setVariable("REG_LANG_FORMACTION",
288  $this->ctrl->getFormAction($this));
289 
290  // language selection
291  $languages = $lng->getInstalledLanguages();
292 
293  $count = (int) round(count($languages) / 2);
294  $num = 1;
295 
296  foreach ($languages as $lang_key)
297  {
298  /*
299  if ($num === $count)
300  {
301  $this->tpl->touchBlock("lng_new_row");
302  }
303  */
304 
305  $this->tpl->setCurrentBlock("languages");
306  $this->tpl->setVariable("LINK_LANG",$this->ctrl->getLinkTarget($this,'displayForm'));
307  $this->tpl->setVariable("LANG_NAME",
308  ilLanguage::_lookupEntry($lang_key, "meta", "meta_l_".$lang_key));
309  $this->tpl->setVariable("LANG_ICON", $lang_key);
310  $this->tpl->setVariable("BORDER", 0);
311  $this->tpl->setVariable("VSPACE", 0);
312  $this->tpl->parseCurrentBlock();
313 
314  $num++;
315  }
316 
317  // preselect previous chosen language otherwise default language
318  $selected_lang = (isset($_POST["user"]["language"])) ?
319  $_POST["user"]["language"] : $lng->lang_key;
320 
321  foreach ($languages as $lang_key)
322  {
323  $this->tpl->setCurrentBlock("language_selection");
324  $this->tpl->setVariable("LANG", $lng->txt("lang_".$lang_key));
325  $this->tpl->setVariable("LANGSHORT", $lang_key);
326 
327  if ($selected_lang == $lang_key)
328  {
329  $this->tpl->setVariable("SELECTED_LANG", "selected=\"selected\"");
330  }
331 
332  $this->tpl->parseCurrentBlock();
333  } // END language selection
334 
335 
336  $this->tpl->setVariable("IMG_USER",
337  ilUtil::getImagePath("icon_usr_b.gif"));
338  $this->tpl->setVariable("TXT_PAGEHEADLINE", $lng->txt("registration"));
339  $this->tpl->setVariable("TXT_PAGETITLE", "ILIAS3 - ".$lng->txt("registration"));
340  $this->tpl->setVariable("TXT_REGISTER_INFO", $lng->txt("register_info"));
341  $this->tpl->setVariable("AGREEMENT", ilUserAgreement::_getText());
342  $this->tpl->setVariable("ACCEPT_CHECKBOX", ilUtil::formCheckbox(0, "status", "accepted"));
343  $this->tpl->setVariable("ACCEPT_AGREEMENT", $lng->txt("accept_usr_agreement") . '<span class="asterisk">*</span>');
344 
345  $this->showUserDefinedFields();
346 
347  // show personal data if at least one field appears
348  if($this->display_pdata)
349  {
350  $this->tpl->setCurrentBlock('block_headline_personalinfo');
351  $this->tpl->setVariable("TXT_PERSONAL_DATA", $lng->txt("personal_data"));
352  $this->tpl->parseCurrentBlock();
353  }
354  // show contact data if at least one field appears
355  if($this->display_cdata)
356  {
357  $this->tpl->setCurrentBlock('block_headline_contactinfo');
358  $this->tpl->setVariable("TXT_CONTACT_DATA", $lng->txt("contact_data"));
359  $this->tpl->parseCurrentBlock();
360  }
361  // show other data if at least one field appears
362  if($this->display_odata)
363  {
364  $this->tpl->setCurrentBlock('block_headline_otherdata');
365  $this->tpl->setVariable("TXT_OTHER", $lng->txt("user_profile_other"));
366  $this->tpl->parseCurrentBlock();
367  }
368  }
369 
371  {
372  include_once './Services/User/classes/class.ilUserDefinedFields.php';
373  $user_defined_fields =& ilUserDefinedFields::_getInstance();
374 
375  #$user_defined_data = $ilUser->getUserDefinedData();
376  foreach($user_defined_fields->getRegistrationDefinitions() as $field_id => $definition)
377  {
378  $this->display_odata = true;
379 
380  if($definition['field_type'] == UDF_TYPE_TEXT)
381  {
382  $old = isset($_POST["udf"][$field_id]) ?
383  $_POST["udf"][$field_id] : '';
384 
385 
386  $this->tpl->setCurrentBlock("field_text");
387  $this->tpl->setVariable("FIELD_NAME",'udf['.$definition['field_id'].']');
388  $this->tpl->setVariable("FIELD_VALUE",ilUtil::prepareFormOutput($old));
389  if(!$definition['changeable'])
390  {
391  $this->tpl->setVariable("DISABLED_FIELD",'disabled=\"disabled\"');
392  }
393  $this->tpl->parseCurrentBlock();
394  }
395  else if($definition['field_type'] == UDF_TYPE_WYSIWYG)
396  {
397  include_once "./Services/RTE/classes/class.ilRTE.php";
398  $rtestring = ilRTE::_getRTEClassname();
399  include_once "./Services/RTE/classes/class.$rtestring.php";
400  $rte = new $rtestring();
401  include_once "./Services/Form/classes/class.ilTextAreaInputGUI.php";
402  $ta = new ilTextAreaInputGUI("","");
403  $rte->addCustomRTESupport(0, "", $ta->getRteTags());
404 
405  $old = isset($_POST["udf"][$field_id]) ?
406  $_POST["udf"][$field_id] : '';
407 
408  $this->tpl->setCurrentBlock("field_wysiwyg");
409  $this->tpl->setVariable("FIELD_NAME",'udf['.$definition['field_id'].']');
410  $this->tpl->setVariable("FIELD_VALUE",ilUtil::prepareFormOutput($old));
411  if(!$definition['changeable'])
412  {
413  $this->tpl->setVariable("DISABLED_FIELD",'disabled=\"disabled\"');
414  }
415  $this->tpl->parseCurrentBlock();
416  }
417  else
418  {
419  $this->tpl->setCurrentBlock("field_select");
420  $this->tpl->setVariable("SELECT_BOX",ilUtil::formSelect($_POST['udf']["$definition[field_id]"],
421  'udf['.$definition['field_id'].']',
422  $user_defined_fields->fieldValuesToSelectArray(
423  $definition['field_values']),
424  false,
425  true));
426  $this->tpl->parseCurrentBlock();
427  }
428  $this->tpl->setCurrentBlock("user_defined");
429 
430  if($definition['required'])
431  {
432  $name = $definition['field_name']."<span class=\"asterisk\">*</span>";
433  }
434  else
435  {
436  $name = $definition['field_name'];
437  }
438  $this->tpl->setVariable("TXT_FIELD_NAME",$name);
439  $this->tpl->parseCurrentBlock();
440  }
441  return true;
442  }
443 
444 
446  {
447  include_once './Services/User/classes/class.ilUserDefinedFields.php';
448  $user_defined_fields =& ilUserDefinedFields::_getInstance();
449 
450  foreach($user_defined_fields->getRegistrationDefinitions() as $field_id => $definition)
451  {
452  if($definition['required'] and !strlen($_POST['udf'][$field_id]))
453  {
454  return false;
455  }
456  }
457  return true;
458  }
459 
460 
461  function saveForm()
462  {
463  global $ilias, $lng, $rbacadmin, $ilDB, $ilErr, $ilSetting;
464 
465  require_once 'Services/User/classes/class.ilObjUser.php';
466 
467  //load ILIAS settings
468  $settings = $ilias->getAllSettings();
469 
470  //check, whether user-agreement has been accepted
471  if ($_POST["status"] != "accepted")
472  {
473  ilUtil::sendInfo($lng->txt("force_accept_usr_agreement"),true);
474  $this->displayForm();
475  return false;
476  }
477 
479  $require_keys = array();
480  $this->profile_incomplete = false;
481  foreach($data['fields'] as $key => $val)
482  {
483  if(in_array($key, array('login', 'passwd', 'passwd2')))
484  {
485  $require_keys[] = $key;
486  continue;
487  }
488 
489  if((int)$settings['require_'.$key])
490  {
491  #if((int)$settings['usr_settings_visib_reg_'.$key])
492  #{
493  $require_keys[] = $key;
494  #}
495  #else
496  #{
497  # $this->profile_incomplete = true;
498  #}
499  }
500  }
501 
502  // email address is required if password generation is enabled or registration type = link confirmation
503  if(($this->registration_settings->passwordGenerationEnabled() ||
504  $this->registration_settings->getRegistrationType() == IL_REG_ACTIVATION ||
505  $this->registration_settings->getRegistrationType() == IL_REG_APPROVE ) &&
506  !in_array('email', $require_keys))
507  {
508  $require_keys[] = 'email';
509  }
510 
511  foreach($require_keys as $key => $val)
512  {
513  if(empty($_POST['user'][$val]))
514  {
515  ilUtil::sendFailure($lng->txt('fill_out_all_required_fields') . ': ' . $lng->txt($val), true);
516  $this->displayForm();
517  return false;
518  }
519 
520  if($val == 'email')
521  {
522  // validate email
523  if(!ilUtil::is_email($_POST['user']['email']))
524  {
525  ilUtil::sendFailure($lng->txt('email_not_valid'), true);
526  $this->displayForm();
527  return false;
528  }
529  }
530  }
531 
532  if(!$this->checkUserDefinedRequiredFields())
533  {
534  ilUtil::sendFailure($lng->txt("fill_out_all_required_fields"),true);
535  $this->displayForm();
536  return false;
537  }
538 
539  // validate username
540  if (!ilUtil::isLogin($_POST["user"]["login"]))
541  {
542  ilUtil::sendFailure($lng->txt("login_invalid"),true);
543  $this->displayForm();
544  return false;
545  }
546 
547  // check loginname
548  if (ilObjUser::_loginExists($_POST["user"]["login"]))
549  {
550  ilUtil::sendFailure($lng->txt("login_exists"), true);
551  $this->displayForm();
552  return false;
553  }
554 
555  //check if loginname exists in history
556  if((int)$ilSetting->get('allow_change_loginname') &&
557  (int)$ilSetting->get('prevent_reuse_of_loginnames') &&
559  {
560  ilUtil::sendFailure($lng->txt('login_exists'), true);
561  $this->displayForm();
562  return false;
563  }
564 
565  if (!$this->registration_settings->passwordGenerationEnabled())
566  {
567  // check passwords
568  if ($_POST["user"]["passwd"] != $_POST["user"]["passwd2"])
569  {
570  ilUtil::sendFailure($lng->txt("passwd_not_match"),true);
571  $this->displayForm();
572  return false;
573  }
574 
575  // validate password
576  if (!ilUtil::isPassword($_POST["user"]["passwd"],$custom_error))
577  {
578  if($custom_error != '') ilUtil::sendFailure($custom_error,true);
579  else ilUtil::sendFailure($lng->txt("passwd_invalid"),true);
580 
581  $this->displayForm();
582  return false;
583  }
584  }
585  else
586  {
587  $passwd = ilUtil::generatePasswords(1);
588  $_POST["user"]["passwd"] = $passwd[0];
589  }
590  // The password type is not passed in the post data. Therefore we
591  // append it here manually.
592  $_POST["user"]["passwd_type"] = IL_PASSWD_PLAIN;
593 
594  // Do some Radius checks
595  $this->__validateRole();
596 
597  // TODO: check if login or passwd already exists
598  // TODO: check length of login and passwd
599 
600  // checks passed. save user
601 
602  $this->userObj = new ilObjUser();
603  $this->userObj->assignData($_POST["user"]);
604  $this->userObj->setTitle($this->userObj->getFullname());
605  $this->userObj->setDescription($this->userObj->getEmail());
606 
607  if($this->profile_incomplete)
608  $this->userObj->setProfileIncomplete(true);
609 
610  // Time limit
611  $this->userObj->setTimeLimitOwner(7);
612 
613  if ($this->registration_settings->getAccessLimitation())
614  {
615  include_once 'Services/Registration/classes/class.ilRegistrationRoleAccessLimitations.php';
616 
617  $access_limitations_obj = new ilRegistrationRoleAccessLimitations();
618 
619  if ($this->registration_settings->roleSelectionEnabled())
620  {
621  $default_role = $_POST['user']['default_role'];
622  }
623  else
624  {
625  // Assign by email
626  include_once 'Services/Registration/classes/class.ilRegistrationEmailRoleAssignments.php';
627 
628  $registration_role_assignments = new ilRegistrationRoleAssignments();
629  $default_role = $registration_role_assignments->getRoleByEmail($this->userObj->getEmail());
630  }
631 
632  $access_limit_mode = $access_limitations_obj->getMode($default_role);
633 
634  if ($access_limit_mode == 'absolute')
635  {
636  $access_limit = $access_limitations_obj->getAbsolute($default_role);
637  $this->userObj->setTimeLimitUnlimited(0);
638  $this->userObj->setTimeLimitUntil($access_limit);
639  }
640  elseif ($access_limit_mode == 'relative')
641  {
642  $rel_d = (int) $access_limitations_obj->getRelative($default_role,'d');
643  $rel_m = (int) $access_limitations_obj->getRelative($default_role,'m');
644  $rel_y = (int) $access_limitations_obj->getRelative($default_role,'y');
645 
646  $access_limit = $rel_d * 86400 + $rel_m * 2592000 + $rel_y * 31536000 + time();
647  $this->userObj->setTimeLimitUnlimited(0);
648  $this->userObj->setTimeLimitUntil($access_limit);
649  }
650  else
651  {
652  $this->userObj->setTimeLimitUnlimited(1);
653  $this->userObj->setTimeLimitUntil(time());
654  }
655  }
656  else
657  {
658  $this->userObj->setTimeLimitUnlimited(1);
659  $this->userObj->setTimeLimitUntil(time());
660  }
661 
662  $this->userObj->setTimeLimitFrom(time());
663 
664  $this->userObj->setUserDefinedData($_POST['udf']);
665  $this->userObj->create();
666 
667  if($this->registration_settings->getRegistrationType() == IL_REG_DIRECT)
668  {
669  $this->userObj->setActive(1);
670  }
671  else if($this->registration_settings->getRegistrationType() == IL_REG_ACTIVATION)
672  {
673  $this->userObj->setActive(0,0);
674  }
675  else
676  {
677  $this->userObj->setActive(0,0);
678  }
679 
680  $this->userObj->updateOwner();
681 
682 
683  // set a timestamp for last_password_change
684  // this ts is needed by the ACCOUNT_SECURITY_MODE_CUSTOMIZED
685  // in ilSecuritySettings
686  $this->userObj->setLastPasswordChangeTS( time() );
687 
688  //insert user data in table user_data
689  $this->userObj->saveAsNew();
690 
691  // store acceptance of user agreement
692  $this->userObj->writeAccepted();
693 
694  // setup user preferences
695  $this->userObj->setLanguage($_POST["user"]["language"]);
696  $hits_per_page = $ilias->getSetting("hits_per_page");
697  if ($hits_per_page < 10)
698  {
699  $hits_per_page = 10;
700  }
701  $this->userObj->setPref("hits_per_page", $ilias->getSetting("hits_per_page"));
702  $show_online = $ilias->getSetting("show_users_online");
703  if ($show_online == "")
704  {
705  $show_online = "y";
706  }
707  $this->userObj->setPref("show_users_online", $show_online);
708  $this->userObj->writePrefs();
709 
710  // Assign role (depends on settings in administration)
711  $this->__assignRole();
712 
713  // Distribute mails
714  $this->__distributeMails();
715 
716  $this->login();
717  return true;
718  }
719 
720 
721  function __validateRole()
722  {
723  global $ilDB,$ilias,$ilErr,$lng;
724 
725  // validate role
726  include_once("./Services/AccessControl/classes/class.ilObjRole.php");
727  if ($this->registration_settings->roleSelectionEnabled() and
728  !ilObjRole::_lookupAllowRegister($_POST["user"]["default_role"]))
729  {
730  $ilias->raiseError("Invalid role selection in registration: ".
731  ilObject::_lookupTitle($_POST["user"]["default_role"])." [".$_POST["user"]["default_role"]."]".
732  ", IP: ".$_SERVER["REMOTE_ADDR"],$ilias->error_obj->FATAL);
733  }
734  return true;
735  }
736 
737  function __assignRole()
738  {
739  global $rbacadmin;
740 
741  // Assign chosen role
742  if($this->registration_settings->roleSelectionEnabled())
743  {
744  return $rbacadmin->assignUser((int) $_POST['user']['default_role'],
745  $this->userObj->getId(),true);
746  }
747 
748  // Assign by email
749  include_once 'Services/Registration/classes/class.ilRegistrationEmailRoleAssignments.php';
750 
751  $registration_role_assignments = new ilRegistrationRoleAssignments();
752 
753  return $rbacadmin->assignUser((int) $registration_role_assignments->getRoleByEmail($this->userObj->getEmail()),
754  $this->userObj->getId(),
755  true);
756  }
757 
759  {
760  if(!$this->registration_settings->roleSelectionEnabled())
761  {
762  return true;
763  }
764 
765  // TODO put query in a function
766  include_once("./Services/AccessControl/classes/class.ilObjRole.php");
767  $reg_roles = ilObjRole::_lookupRegisterAllowed();
768 
769  $rol = array();
770  foreach ($reg_roles as $role)
771  {
772  $rol[$role["id"]] = $role["title"];
773  }
774 
775  $this->tpl->setCurrentBlock("role");
776  $this->tpl->setVariable("TXT_DEFAULT_ROLE",$this->lng->txt('default_role'));
777  $this->tpl->setVariable("DEFAULT_ROLE",ilUtil::formSelect($_POST["user"]["default_role"],
778  "user[default_role]",
779  $rol,false,true));
780  $this->tpl->parseCurrentBlock();
781 
782  return true;
783  }
784 
785  function __distributeMails()
786  {
787  global $ilias;
788 
789  include_once './Services/Language/classes/class.ilLanguage.php';
790  include_once './Services/User/classes/class.ilObjUser.php';
791  include_once "Services/Mail/classes/class.ilFormatMail.php";
792 
793  include_once './Services/Registration/classes/class.ilRegistrationMailNotification.php';
794 
795  $settings = $ilias->getAllSettings();
796 
797  // Always send mail to approvers
798  if($this->registration_settings->getRegistrationType() == IL_REG_APPROVE)
799  {
800  $mail = new ilRegistrationMailNotification();
802  $mail->setRecipients($this->registration_settings->getApproveRecipients());
803  $mail->setAdditionalInformation(array('usr' => $this->userObj));
804  $mail->send();
805  }
806  else
807  {
808  $mail = new ilRegistrationMailNotification();
810  $mail->setRecipients($this->registration_settings->getApproveRecipients());
811  $mail->setAdditionalInformation(array('usr' => $this->userObj));
812  $mail->send();
813 
814  }
815  // Send mail to new user
816 
817  // Registration with confirmation link ist enabled
818  if($this->registration_settings->getRegistrationType() == IL_REG_ACTIVATION)
819  {
820  include_once 'Services/Mail/classes/class.ilMail.php';
821  $mail_obj = new ilMail(ANONYMOUS_USER_ID);
822 
823  // mail subject
824  $subject = $this->lng->txt("reg_mail_subject_confirmation");
825 
826  // mail body
827  $hashcode = ilObjUser::_generateRegistrationHash($this->userObj->getId());
828  $body = $this->lng->txt("reg_mail_body_salutation")." ".$this->userObj->getFullname().",\n\n";
829  $body .= $this->lng->txt('reg_mail_body_confirmation')."\n".
830  ILIAS_HTTP_PATH.'/confirmReg.php?client_id='.CLIENT_ID."&rh=".$hashcode."\n\n";
831 
832  $body .= sprintf($this->lng->txt('reg_mail_body_2_confirmation'),
833  ilFormat::_secondsToString($this->registration_settings->getRegistrationHashLifetime()))."\n\n";
834 
835  $body .= $this->lng->txt('reg_mail_body_3_confirmation');
836 
837  $mail_obj->enableSoap(false);
838  $mail_obj->appendInstallationSignature(true);
839  $mail_obj->sendMail($this->userObj->getEmail(), '', '',
840  $subject,
841  $body,
842  array(), array('normal'));
843  }
844  else
845  {
846  // try individual account mail in user administration
847  include_once("Services/Mail/classes/class.ilAccountMail.php");
848  include_once './Services/User/classes/class.ilObjUserFolder.php';
849  $amail = ilObjUserFolder::_lookupNewAccountMail($GLOBALS["lng"]->getDefaultLanguage());
850  if (trim($amail["body"]) != "" && trim($amail["subject"]) != "")
851  {
852  $acc_mail = new ilAccountMail();
853  $acc_mail->setUser($this->userObj);
854  if ($this->registration_settings->passwordGenerationEnabled())
855  {
856  $acc_mail->setUserPassword($_POST["user"]["passwd"]);
857  }
858  $acc_mail->send();
859  }
860  else // do default mail
861  {
862  include_once "Services/Mail/classes/class.ilMimeMail.php";
863 
864  $mmail = new ilMimeMail();
865  $mmail->autoCheck(false);
866  $mmail->From($settings["admin_email"]);
867  $mmail->To($this->userObj->getEmail());
868 
869  // mail subject
870  $subject = $this->lng->txt("reg_mail_subject");
871 
872  // mail body
873  $body = $this->lng->txt("reg_mail_body_salutation")." ".$this->userObj->getFullname().",\n\n".
874  $this->lng->txt("reg_mail_body_text1")."\n\n".
875  $this->lng->txt("reg_mail_body_text2")."\n".
876  ILIAS_HTTP_PATH."/login.php?client_id=".$ilias->client_id."\n";
877  $body .= $this->lng->txt("login").": ".$this->userObj->getLogin()."\n";
878 
879  if ($this->registration_settings->passwordGenerationEnabled())
880  {
881  $body.= $this->lng->txt("passwd").": ".$_POST["user"]["passwd"]."\n";
882  }
883  $body.= "\n";
884 
885  // Info about necessary approvement
886  if($this->registration_settings->getRegistrationType() == IL_REG_APPROVE)
887  {
888  $body .= ($this->lng->txt('reg_mail_body_pwd_generation')."\n\n");
889  }
890 
891  $body .= ($this->lng->txt("reg_mail_body_text3")."\n\r");
892  $body .= $this->userObj->getProfileAsString($this->lng);
893  $mmail->Subject($subject);
894  $mmail->Body($body);
895  $mmail->Send();
896  }
897  }
898  }
899 }
900 ?>