• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/Registration/classes/class.ilRegistrationGUI.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00038 require_once './Services/Registration/classes/class.ilRegistrationSettings.php';
00039 require_once "classes/class.ilUserAgreement.php";
00040 
00041 class ilRegistrationGUI
00042 {
00043         var $ctrl;
00044         var $tpl;
00045 
00046         function ilRegistrationGUI()
00047         {
00048                 global $ilCtrl,$tpl,$lng;
00049 
00050                 $this->tpl =& $tpl;
00051 
00052                 $this->ctrl =& $ilCtrl;
00053                 $this->ctrl->saveParameter($this,'lang');
00054                 
00055                 $this->lng =& $lng;
00056                 $this->lng->loadLanguageModule('registration');
00057 
00058                 $this->registration_settings = new ilRegistrationSettings();
00059         }
00060 
00061         function executeCommand()
00062         {
00063                 global $ilErr, $tpl;
00064                 
00065                 if($this->registration_settings->getRegistrationType() == IL_REG_DISABLED)
00066                 {
00067                         $ilErr->raiseError($this->lng->txt('reg_disabled'),$ilErr->FATAL);
00068                 }
00069 
00070                 $next_class = $this->ctrl->getNextClass($this);
00071                 $cmd = $this->ctrl->getCmd();
00072 
00073                 switch($next_class)
00074                 {
00075                         default:
00076                                 if($cmd)
00077                                 {
00078                                         $this->$cmd();
00079                                 }
00080                                 else
00081                                 {
00082                                         $this->displayForm();
00083                                 }
00084                                 break;
00085                 }
00086                 $tpl->show();
00087                 return true;
00088         }
00089 
00090         function login()
00091         {
00092                 global $ilias,$lng,$ilLog;
00093 
00094                 $ilLog->write("Entered login");
00095 
00096                 $this->tpl->addBlockFile("CONTENT", "content", "tpl.usr_registered.html");
00097 
00098                 $this->tpl->setVariable("IMG_USER",
00099                         ilUtil::getImagePath("icon_usr_b.gif"));
00100                 $this->tpl->setVariable("TXT_PAGEHEADLINE", $lng->txt("registration"));
00101                 $this->tpl->setVariable("TXT_WELCOME", $lng->txt("welcome").", ".$this->userObj->getTitle()."!");
00102                 
00103                 if ($this->registration_settings->getRegistrationType() == IL_REG_DIRECT and
00104                         !$this->registration_settings->passwordGenerationEnabled())
00105                 {
00106                         $this->tpl->setCurrentBlock("activation");
00107                         $this->tpl->setVariable("TXT_REGISTERED", $lng->txt("txt_registered"));
00108                         $this->tpl->setVariable("FORMACTION", "login.php?cmd=force_login&target=".$_GET["target"]);
00109                         $this->tpl->setVariable("TARGET","target=\"_parent\"");
00110                         $this->tpl->setVariable("TXT_LOGIN", $lng->txt("login_to_ilias"));
00111                         $this->tpl->setVariable("USERNAME",$this->userObj->getLogin());
00112                         $this->tpl->setVariable("PASSWORD",$_POST["user"]['passwd']);
00113                         $this->tpl->parseCurrentBlock();
00114                 }
00115                 else if ($this->registration_settings->getRegistrationType() == IL_REG_APPROVE)
00116                 {
00117                         $this->tpl->setVariable("TXT_REGISTERED", $lng->txt("txt_submitted"));
00118                 }
00119                 else
00120                 {
00121                         $this->tpl->setVariable("TXT_REGISTERED", $lng->txt("txt_registered_passw_gen"));
00122                 }
00123         }               
00124 
00125         function displayForm()
00126         {
00127                 global $ilias,$lng,$ObjDefinition;
00128 
00129                 $this->tpl->addBlockFile("CONTENT", "content", "tpl.usr_registration.html");
00130                 $this->tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
00131 
00132                 //load ILIAS settings
00133                 $settings = $ilias->getAllSettings();
00134 
00135 
00136                 $this->__showRoleSelection();
00137 
00138                 $data = array();
00139                 $data["fields"] = array();
00140                 $data["fields"]["login"] = "";
00141 
00142                 if (!$this->registration_settings->passwordGenerationEnabled())
00143                 {
00144                         $data["fields"]["passwd"] = "";
00145                         $data["fields"]["passwd2"] = "";
00146                 }
00147     
00148                 $data["fields"]["title"] = "";
00149                 $data["fields"]["gender"] = "";
00150                 $data["fields"]["firstname"] = "";
00151                 $data["fields"]["lastname"] = "";
00152                 $data["fields"]["institution"] = "";
00153                 $data["fields"]["department"] = "";
00154                 $data["fields"]["street"] = "";
00155                 $data["fields"]["city"] = "";
00156                 $data["fields"]["zipcode"] = "";
00157                 $data["fields"]["country"] = "";
00158                 $data["fields"]["phone_office"] = "";
00159                 $data["fields"]["phone_home"] = "";
00160                 $data["fields"]["phone_mobile"] = "";
00161                 $data["fields"]["fax"] = "";
00162                 $data["fields"]["email"] = "";
00163                 $data["fields"]["hobby"] = "";
00164                 $data["fields"]["referral_comment"] = "";
00165                 $data["fields"]["matriculation"] = "";
00166 
00167                 // fill presets
00168                 foreach ($data["fields"] as $key => $val)
00169                 {
00170                         $str = $lng->txt($key);
00171                         if ($key == "title")
00172                         {
00173                                 $str = $lng->txt("person_title");
00174                         }
00175                 
00176                         if (!in_array($key, array("login", "passwd", "passwd2",
00177                                                                           "firstname", "lastname", "gender")))
00178                         {
00179                                 if ($settings["usr_settings_hide_".$key] != 1)
00180                                 {
00181                                         $this->tpl->setCurrentBlock($key."_section");
00182                                 }
00183                                 else
00184                                 {
00185                                         continue;
00186                                 }
00187                         }
00188 
00189                         // check to see if dynamically required
00190                         if (isset($settings["require_" . $key]) && $settings["require_" . $key])
00191                         {
00192                                 $str = $str . '<span class="asterisk">*</span>';
00193                         }
00194 
00195                         $this->tpl->setVariable("TXT_".strtoupper($key), $str);
00196                         $this->tpl->setVariable(strtoupper($key), ilUtil::prepareFormOutput($_POST['user'][$key],true));
00197                 
00198                         if (!in_array($key, array("login", "passwd", "passwd2",
00199                                                                           "firstname", "lastname", "gender")))
00200                         {
00201                                 $this->tpl->parseCurrentBlock();
00202                         }
00203                 }
00204 
00205                 if (!$this->registration_settings->passwordGenerationEnabled())
00206                 {
00207                         // text label for passwd2 is nonstandard
00208                         $str = $lng->txt("retype_password");
00209                         if (isset($settings["require_passwd2"]) && $settings["require_passwd2"])
00210                         {
00211                                 $str = $str . '<span class="asterisk">*</span>';
00212                         }
00213 
00214                         $this->tpl->setVariable("TXT_PASSWD2", $str);
00215                 }
00216                 else
00217                 {
00218                         $this->tpl->setVariable("TXT_PASSWD_SELECT", $lng->txt("passwd"));
00219                         $this->tpl->setVariable("TXT_PASSWD_VIA_MAIL", $lng->txt("reg_passwd_via_mail"));
00220                 }
00221 
00222                 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00223                 $this->tpl->setVariable("TXT_SAVE", $lng->txt("register"));
00224                 $this->tpl->setVariable("TXT_REQUIRED_FIELDS", $lng->txt("required_field"));
00225                 $this->tpl->setVariable("TXT_LOGIN_DATA", $lng->txt("login_data"));
00226                 $this->tpl->setVariable("TXT_PERSONAL_DATA", $lng->txt("personal_data"));
00227                 $this->tpl->setVariable("TXT_CONTACT_DATA", $lng->txt("contact_data"));
00228                 $this->tpl->setVariable("TXT_SETTINGS", $lng->txt("settings"));
00229                 $this->tpl->setVariable("TXT_OTHER", $lng->txt("user_profile_other"));
00230                 $this->tpl->setVariable("TXT_LANGUAGE",$lng->txt("language"));
00231                 $this->tpl->setVariable("TXT_GENDER_F",$lng->txt("gender_f"));
00232                 $this->tpl->setVariable("TXT_GENDER_M",$lng->txt("gender_m"));
00233                 $this->tpl->setVariable("TXT_OK",$lng->txt("ok"));
00234                 $this->tpl->setVariable("TXT_CHOOSE_LANGUAGE", $lng->txt("choose_language"));
00235                 $this->tpl->setVariable("REG_LANG_FORMACTION",
00236                         $this->ctrl->getFormAction($this));
00237 
00238                 // language selection
00239                 $languages = $lng->getInstalledLanguages();
00240         
00241                 $count = (int) round(count($languages) / 2);
00242                 $num = 1;
00243                 
00244                 foreach ($languages as $lang_key)
00245                 {
00246                         /*
00247                          if ($num === $count)
00248                          {
00249                          $this->tpl->touchBlock("lng_new_row");
00250                          }
00251                         */
00252 
00253                         $this->tpl->setCurrentBlock("languages");
00254                         $this->tpl->setVariable("LINK_LANG",$this->ctrl->getLinkTarget($this,'displayForm'));
00255                         $this->tpl->setVariable("LANG_NAME",
00256                                                           ilLanguage::_lookupEntry($lang_key, "meta", "meta_l_".$lang_key));
00257                         $this->tpl->setVariable("LANG_ICON", $lang_key);
00258                         $this->tpl->setVariable("BORDER", 0);
00259                         $this->tpl->setVariable("VSPACE", 0);
00260                         $this->tpl->parseCurrentBlock();
00261 
00262                         $num++;
00263                 }
00264                 
00265                 // preselect previous chosen language otherwise default language
00266                 $selected_lang = (isset($_POST["user"]["language"])) ? 
00267                         $_POST["user"]["language"] : $lng->lang_key;
00268 
00269                 foreach ($languages as $lang_key)
00270                 {
00271                         $this->tpl->setCurrentBlock("language_selection");
00272                         $this->tpl->setVariable("LANG", $lng->txt("lang_".$lang_key));
00273                         $this->tpl->setVariable("LANGSHORT", $lang_key);
00274 
00275                         if ($selected_lang == $lang_key)
00276                         {
00277                                 $this->tpl->setVariable("SELECTED_LANG", "selected=\"selected\"");
00278                         }
00279 
00280                         $this->tpl->parseCurrentBlock();
00281                 } // END language selection
00282 
00283                 // FILL SAVED VALUES IN CASE OF ERROR
00284                 if (isset($_POST["user"]))
00285                 {
00286                         // gender selection
00287                         $gender = strtoupper($_POST["user"]["gender"]);
00288 
00289                         if (!empty($gender))
00290                         {
00291                                 $this->tpl->setVariable("BTN_GENDER_".$gender,"checked=\"checked\"");
00292                         }
00293                 }
00294 
00295                 $this->tpl->setVariable("IMG_USER",
00296                         ilUtil::getImagePath("icon_usr_b.gif"));
00297                 $this->tpl->setVariable("TXT_PAGEHEADLINE", $lng->txt("registration"));
00298                 $this->tpl->setVariable("TXT_PAGETITLE", "ILIAS3 - ".$lng->txt("registration"));
00299                 $this->tpl->setVariable("TXT_REGISTER_INFO", $lng->txt("register_info"));
00300                 $this->tpl->setVariable("AGREEMENT", ilUserAgreement::_getText());
00301                 $this->tpl->setVariable("ACCEPT_CHECKBOX", ilUtil::formCheckbox(0, "status", "accepted"));
00302                 $this->tpl->setVariable("ACCEPT_AGREEMENT", $lng->txt("accept_usr_agreement") . '<span class="asterisk">*</span>');
00303 
00304                 $this->showUserDefinedFields();
00305         }
00306 
00307         function showUserDefinedFields()
00308         {
00309                 include_once './classes/class.ilUserDefinedFields.php';
00310                 $user_defined_fields =& ilUserDefinedFields::_getInstance();
00311 
00312                 #$user_defined_data = $ilUser->getUserDefinedData();
00313                 foreach($user_defined_fields->getVisibleDefinitions() as $field_id => $definition)
00314                 {
00315                         if($definition['field_type'] == UDF_TYPE_TEXT)
00316                         {
00317                                 $old = isset($_POST["udf"][$field_id]) ?
00318                                         $_POST["udf"][$field_id] : '';
00319 
00320 
00321                                 $this->tpl->setCurrentBlock("field_text");
00322                                 $this->tpl->setVariable("FIELD_NAME",'udf['.$definition['field_id'].']');
00323                                 $this->tpl->setVariable("FIELD_VALUE",ilUtil::prepareFormOutput($old));
00324                                 if(!$definition['changeable'])
00325                                 {
00326                                         $this->tpl->setVariable("DISABLED_FIELD",'disabled=\"disabled\"');
00327                                 }
00328                                 $this->tpl->parseCurrentBlock();
00329                         }
00330                         else
00331                         {
00332                                 $this->tpl->setCurrentBlock("field_select");
00333                                 $this->tpl->setVariable("SELECT_BOX",ilUtil::formSelect($_POST['udf']["$definition[field_id]"],
00334                                                                                                                                   'udf['.$definition['field_id'].']',
00335                                                                                                                                   $user_defined_fields->fieldValuesToSelectArray(
00336                                                                                                                                           $definition['field_values']),
00337                                                                                                                                   false,
00338                                                                                                                                   true));
00339                                 $this->tpl->parseCurrentBlock();
00340                         }
00341                         $this->tpl->setCurrentBlock("user_defined");
00342 
00343                         if($definition['required'])
00344                         {
00345                                 $name = $definition['field_name']."<span class=\"asterisk\">*</span>";
00346                         }
00347                         else
00348                         {
00349                                 $name = $definition['field_name'];
00350                         }
00351                         $this->tpl->setVariable("TXT_FIELD_NAME",$name);
00352                         $this->tpl->parseCurrentBlock();
00353                 }
00354                 return true;
00355         }
00356 
00357 
00358         function checkUserDefinedRequiredFields()
00359         {
00360                 include_once './classes/class.ilUserDefinedFields.php';
00361                 $user_defined_fields =& ilUserDefinedFields::_getInstance();
00362 
00363                 foreach($user_defined_fields->getVisibleDefinitions() as $field_id => $definition)
00364                 {
00365                         if($definition['required'] and !strlen($_POST['udf'][$field_id]))
00366                         {
00367                                 return false;
00368                         }
00369                 }
00370                 return true;
00371         }
00372 
00373 
00374         function saveForm()
00375         {               
00376                 global $ilias, $lng, $rbacadmin, $ilDB, $ilErr;
00377 
00378                 //load ILIAS settings
00379                 $settings = $ilias->getAllSettings();
00380 
00381                 //check, whether user-agreement has been accepted
00382                 if ($_POST["status"] != "accepted")
00383                 {
00384                         sendInfo($lng->txt("force_accept_usr_agreement"),true);
00385                         $this->displayForm();
00386                         return false;
00387                 }
00388 
00389                 // check dynamically required fields
00390                 foreach ($settings as $key => $val)
00391                 {
00392                         if (substr($key,0,8) == "require_")
00393                         {
00394                                 if ($this->registration_settings->passwordGenerationEnabled() and 
00395                                         ($key == "require_passwd" or $key == "require_passwd2"))
00396                                 {
00397                                         continue;
00398                                 }
00399                                 if($key == 'require_default_role')
00400                                 {
00401                                         continue;
00402                                 }
00403             
00404                                 $require_keys[] = substr($key,8);
00405                         }
00406                 }
00407 
00408                 foreach ($require_keys as $key => $val)
00409                 {
00410                         if (isset($settings["require_" . $val]) && $settings["require_" . $val])
00411                         {
00412                                 if (empty($_POST["user"][$val]))
00413                                 {
00414                                         sendInfo($lng->txt("fill_out_all_required_fields") . ": " . $lng->txt($val),true);
00415                                         $this->displayForm();
00416                                         return false;
00417                                 }
00418                         }
00419                 }
00420 
00421                 if(!$this->checkUserDefinedRequiredFields())
00422                 {
00423                         sendInfo($lng->txt("fill_out_all_required_fields"),true);
00424                         $this->displayForm();
00425                         return false;
00426                 }
00427                 
00428                 // validate username
00429                 if (!ilUtil::isLogin($_POST["user"]["login"]))
00430                 {
00431                         sendInfo($lng->txt("login_invalid"),true);
00432                         $this->displayForm();
00433                         return false;
00434                 }
00435 
00436                 // check loginname
00437                 if (loginExists($_POST["user"]["login"]))
00438                 {
00439                         sendInfo($lng->txt("login_exists"),true);
00440                         $this->displayForm();
00441                         return false;
00442                 }
00443 
00444                 if (!$this->registration_settings->passwordGenerationEnabled())
00445                 {
00446                         // check passwords
00447                         if ($_POST["user"]["passwd"] != $_POST["user"]["passwd2"])
00448                         {
00449                                 sendInfo($lng->txt("passwd_not_match"),true);
00450                                 $this->displayForm();
00451                                 return false;
00452                         }
00453                         include_once("classes/class.ilObjRole.php");
00454                         $auth_mode = ilObjRole::_getAuthMode($_POST["user"]["default_role"]);
00455                         if($auth_mode != 'radius' and $auth_mode != 'ldap')
00456                         {
00457                                 // validate password
00458                                 if (!ilUtil::isPassword($_POST["user"]["passwd"]))
00459                                 {
00460                                         sendInfo($lng->txt("passwd_invalid"),true);
00461                                         $this->displayForm();
00462                                         return false;
00463                                 }
00464                         }
00465                 }
00466                 else
00467                 {    
00468                         $passwd = ilUtil::generatePasswords(1);
00469                         $_POST["user"]["passwd"] = $passwd[0];
00470                 }
00471                 // The password type is not passed in the post data. Therefore we
00472                 // append it here manually.
00473                 require_once "classes/class.ilObjUser.php";
00474                 $_POST["user"]["passwd_type"] = IL_PASSWD_PLAIN;
00475 
00476                 // validate email
00477                 if (!ilUtil::is_email($_POST["user"]["email"]))
00478                 {
00479                         sendInfo($lng->txt("email_not_valid"),true);
00480                         $this->displayForm();
00481                         return false;
00482                 }
00483 
00484 
00485                 // Do some Radius checks
00486                 $this->__validateRole();
00487 
00488                 // TODO: check if login or passwd already exists
00489                 // TODO: check length of login and passwd
00490 
00491                 // checks passed. save user
00492 
00493                 $this->userObj = new ilObjUser();
00494                 $this->userObj->assignData($_POST["user"]);
00495                 $this->userObj->setTitle($this->userObj->getFullname());
00496                 $this->userObj->setDescription($this->userObj->getEmail());
00497 
00498                 // Time limit
00499                 $this->userObj->setTimeLimitOwner(USER_FOLDER_ID);
00500                 $this->userObj->setTimeLimitUnlimited(1);
00501                 $this->userObj->setTimeLimitFrom(time());
00502                 $this->userObj->setTimeLimitUntil(time());
00503 
00504                 $this->userObj->setUserDefinedData($_POST['udf']);
00505                 $this->userObj->create();
00506 
00507                 if($this->registration_settings->getRegistrationType() == IL_REG_DIRECT)
00508                 {
00509                         $this->userObj->setActive(1);
00510                 }
00511                 else
00512                 {
00513                         $this->userObj->setActive(0,0);
00514                 }
00515 
00516                 $this->userObj->updateOwner();
00517 
00518                 //insert user data in table user_data
00519                 $this->userObj->saveAsNew();
00520         
00521                 // store acceptance of user agreement
00522                 $this->userObj->writeAccepted();
00523 
00524                 // setup user preferences
00525                 $this->userObj->setLanguage($_POST["user"]["language"]);
00526                 $hits_per_page = $ilias->getSetting("hits_per_page");
00527                 if ($hits_per_page < 10)
00528                 {
00529                         $hits_per_page = 10;
00530                 }
00531                 $this->userObj->setPref("hits_per_page", $ilias->getSetting("hits_per_page"));
00532                 $show_online = $ilias->getSetting("show_users_online");
00533                 if ($show_online == "")
00534                 {
00535                         $show_online = "y";
00536                 }
00537                 $this->userObj->setPref("show_users_online", $show_online);
00538                 $this->userObj->writePrefs();
00539 
00540                 // Assign role (depends on settings in administration)
00541                 $this->__assignRole();
00542 
00543                 // Distribute mails
00544                 $this->__distributeMails();
00545 
00546                 $this->login();
00547                 return true;
00548         }
00549 
00550 
00551         function __validateRole()
00552         {
00553                 global $ilDB,$ilias,$ilErr,$lng;
00554 
00555                 // validate role
00556                 include_once("classes/class.ilObjRole.php");
00557                 if ($this->registration_settings->roleSelectionEnabled() and 
00558                         !ilObjRole::_lookupAllowRegister($_POST["user"]["default_role"]))
00559                 {
00560                         $ilias->raiseError("Invalid role selection in registration: ".
00561                                                            ilObject::_lookupTitle($_POST["user"]["default_role"])." [".$_POST["user"]["default_role"]."]".
00562                                                            ", IP: ".$_SERVER["REMOTE_ADDR"],$ilias->error_obj->FATAL);
00563                 }
00564 
00565                 // get auth mode of role
00566                 $auth_mode = ilObjRole::_getAuthMode($_POST["user"]["default_role"]);
00567                 $_POST["user"]['auth_mode'] = $auth_mode;
00568         
00569                 // validate authentication, if mode != LOCAL
00570                 // to do: if auth is taken out of ilias class, this should be
00571                 // implemented better
00572                 // to do: also needed for ldap
00573                 if ($auth_mode == "radius")
00574                 {
00575                         $_POST['username'] = $_POST["user"]["login"];
00576                         $_POST['password'] = $_POST["user"]["passwd"];
00577 
00578                         include_once('classes/class.ilRADIUSAuthentication.php');
00579                         $radius_servers = ilRADIUSAuthentication::_getServers($ilDB);
00580                         $settings = $ilias->getAllSettings();
00581                 
00582                         foreach ($radius_servers as $radius_server)
00583                         {
00584                                 $rad_params['servers'][] = array($radius_server,$settings["radius_port"],$settings["radius_shared_secret"]);
00585                         }
00586                         $auth = new Auth("RADIUS", $rad_params,"",false);
00587                         $auth->start();
00588                         $err = $ilErr->getLastError();
00589                         if (!$auth->getAuth())
00590                         {
00591                                 $add = (!is_object($err))
00592                                         ? ""
00593                                         : "<br>".$err->getMessage();
00594                                 $ilias->raiseError($lng->txt("could_not_verify_account").
00595                                                                    $add, $ilErr->MESSAGE);
00596                         }
00597                 }
00598                 return true;
00599         }
00600 
00601         function __assignRole()
00602         {
00603                 global $rbacadmin;
00604 
00605                 // Assign chosen role
00606                 if($this->registration_settings->roleSelectionEnabled())
00607                 {
00608                         return $rbacadmin->assignUser((int) $_POST['user']['default_role'],
00609                                                                                   $this->userObj->getId(),true);
00610                 }
00611                 
00612                 // Assign by email
00613                 include_once 'Services/Registration/classes/class.ilRegistrationEmailRoleAssignments.php';
00614 
00615                 $registration_role_assignments = new ilRegistrationRoleAssignments();
00616 
00617                 return $rbacadmin->assignUser((int) $registration_role_assignments->getRoleByEmail($this->userObj->getEmail()),
00618                                                                           $this->userObj->getId(),
00619                                                                           true);
00620                         
00621         }
00622 
00623         function __showRoleSelection()
00624         {
00625                 if(!$this->registration_settings->roleSelectionEnabled())
00626                 {
00627                         return true;
00628                 }
00629                 
00630                 // TODO put query in a function
00631                 include_once("classes/class.ilObjRole.php");
00632                 $reg_roles = ilObjRole::_lookupRegisterAllowed();
00633 
00634                 $rol = array();
00635                 foreach ($reg_roles as $role)
00636                 {
00637                         $rol[$role["id"]] = $role["title"];
00638                 }
00639 
00640                 $this->tpl->setCurrentBlock("role");
00641                 $this->tpl->setVariable("TXT_DEFAULT_ROLE",$this->lng->txt('default_role'));
00642                 $this->tpl->setVariable("DEFAULT_ROLE",ilUtil::formSelect($_POST["user"]["default_role"],
00643                                                                                                                                   "user[default_role]",
00644                                                                                                                                   $rol,false,true));
00645                 $this->tpl->parseCurrentBlock();
00646 
00647                 return true;
00648         }
00649 
00650         function __distributeMails()
00651         {
00652                 global $ilias;
00653                 
00654                 include_once 'classes/class.ilLanguage.php';
00655                 include_once 'classes/class.ilObjUser.php';
00656         include_once "classes/class.ilFormatMail.php";
00657 
00658 
00659                 $settings = $ilias->getAllSettings();
00660                 
00661                 // Always send mail to approvers
00662         #if($this->registration_settings->getRegistrationType() == IL_REG_APPROVE)
00663                 {
00664                         // Send mail to approvers
00665                         foreach($this->registration_settings->getApproveRecipients() as $recipient)
00666                         {
00667                                 $lng = new ilLanguage(ilObjUser::_lookupLanguage($recipient));
00668                                 $lng->loadLanguageModule('registration');
00669 
00670                                 #$umail = new ilFormatMail(6); // Send as system administrator
00671                                 $umail = new ilFormatMail($this->userObj->getId());
00672                                 $umail->enableSoap(false);
00673 
00674                                 $subject = $lng->txt("client_id") . " " . $ilias->client_id . ": " . $lng->txt("usr_new");
00675 
00676                                 // build body
00677                                 $body = $lng->txt('reg_mail_new_user_body')."\n\n";
00678                                 $body .= $lng->txt('reg_mail_body_profile')."\n\n";
00679 
00680                                 $body .= $this->userObj->getProfileAsString($lng);
00681                                 $umail->sendMail(ilObjUser::_lookupLogin($recipient),"","",$subject,$body,array(),array("normal"));
00682                         }
00683                 }
00684                 // Send mail to new user
00685                 
00686                 // try individual account mail in user administration
00687                 include_once("classes/class.ilAccountMail.php");
00688                 include_once 'classes/class.ilObjUserFolder.php';
00689                 $amail = ilObjUserFolder::_lookupNewAccountMail($GLOBALS["lng"]->getDefaultLanguage());
00690                 if (trim($amail["body"]) != "" && trim($amail["subject"]) != "")
00691                 {
00692                         $acc_mail = new ilAccountMail();                
00693                         $acc_mail->setUser($this->userObj);
00694                         if ($this->registration_settings->passwordGenerationEnabled())
00695                         {
00696                                 $acc_mail->setUserPassword($_POST["user"]["passwd"]);
00697                         }
00698                         $acc_mail->send();
00699                 }
00700                 else    // do default mail
00701                 {
00702                         include_once "classes/class.ilMimeMail.php";
00703 
00704                         $mmail = new ilMimeMail();
00705                         $mmail->autoCheck(false);
00706                         $mmail->From($settings["admin_email"]);
00707                         $mmail->To($this->userObj->getEmail());
00708 
00709                         // mail subject
00710                         $subject = $this->lng->txt("reg_mail_subject");
00711         
00712                         // mail body
00713                         $body = $this->lng->txt("reg_mail_body_salutation")." ".$this->userObj->getFullname().",\n\n".
00714                                 $this->lng->txt("reg_mail_body_text1")."\n\n".
00715                                 $this->lng->txt("reg_mail_body_text2")."\n".
00716                                 ILIAS_HTTP_PATH."/login.php?client_id=".$ilias->client_id."\n".
00717                                 $this->lng->txt("login").": ".$this->userObj->getLogin()."\n";
00718                                 
00719                         if ($this->registration_settings->passwordGenerationEnabled())
00720                         {
00721                                 $body.= $this->lng->txt("passwd").": ".$_POST["user"]["passwd"]."\n";
00722                         }
00723                         $body.= "\n";
00724 
00725                         // Info about necessary approvement
00726                         if($this->registration_settings->getRegistrationType() == IL_REG_APPROVE)
00727                         {
00728                                 $body .= ($this->lng->txt('reg_mail_body_pwd_generation')."\n\n");
00729                         }
00730                         $body .= ($this->lng->txt("reg_mail_body_text3")."\n\r");
00731                         $body .= $this->userObj->getProfileAsString($this->lng,false);
00732                         $mmail->Subject($subject);
00733                         $mmail->Body($body);
00734                         $mmail->Send();
00735                 }
00736         }
00737 }
00738 ?>

Generated on Fri Dec 13 2013 13:52:12 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1