• 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 "./Services/User/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 './Services/User/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 './Services/User/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                         ilUtil::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                                         ilUtil::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                         ilUtil::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                         ilUtil::sendInfo($lng->txt("login_invalid"),true);
00432                         $this->displayForm();
00433                         return false;
00434                 }
00435 
00436                 // check loginname
00437                 if (ilObjUser::_loginExists($_POST["user"]["login"]))
00438                 {
00439                         ilUtil::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                                 ilUtil::sendInfo($lng->txt("passwd_not_match"),true);
00450                                 $this->displayForm();
00451                                 return false;
00452                         }
00453 
00454                         // validate password
00455                         if (!ilUtil::isPassword($_POST["user"]["passwd"]))
00456                         {
00457                                 ilUtil::sendInfo($lng->txt("passwd_invalid"),true);
00458                                 $this->displayForm();
00459                                 return false;
00460                         }
00461                 }
00462                 else
00463                 {    
00464                         $passwd = ilUtil::generatePasswords(1);
00465                         $_POST["user"]["passwd"] = $passwd[0];
00466                 }
00467                 // The password type is not passed in the post data. Therefore we
00468                 // append it here manually.
00469                 require_once './Services/User/classes/class.ilObjUser.php';
00470                 $_POST["user"]["passwd_type"] = IL_PASSWD_PLAIN;
00471 
00472                 // validate email
00473                 if (!ilUtil::is_email($_POST["user"]["email"]))
00474                 {
00475                         ilUtil::sendInfo($lng->txt("email_not_valid"),true);
00476                         $this->displayForm();
00477                         return false;
00478                 }
00479 
00480 
00481                 // Do some Radius checks
00482                 $this->__validateRole();
00483 
00484                 // TODO: check if login or passwd already exists
00485                 // TODO: check length of login and passwd
00486 
00487                 // checks passed. save user
00488 
00489                 $this->userObj = new ilObjUser();
00490                 $this->userObj->assignData($_POST["user"]);
00491                 $this->userObj->setTitle($this->userObj->getFullname());
00492                 $this->userObj->setDescription($this->userObj->getEmail());
00493 
00494                 // Time limit
00495                 $this->userObj->setTimeLimitOwner(7);
00496                 
00497                 if ($this->registration_settings->getAccessLimitation())
00498                 {
00499                         include_once 'Services/Registration/classes/class.ilRegistrationRoleAccessLimitations.php';
00500 
00501                         $access_limitations_obj = new ilRegistrationRoleAccessLimitations();
00502                         
00503                         if ($this->registration_settings->roleSelectionEnabled())
00504                         {
00505                                 $default_role = $_POST['user']['default_role'];
00506                         }
00507                         else
00508                         {
00509                                 // Assign by email
00510                                 include_once 'Services/Registration/classes/class.ilRegistrationEmailRoleAssignments.php';
00511 
00512                                 $registration_role_assignments = new ilRegistrationRoleAssignments();
00513                                 $default_role = $registration_role_assignments->getRoleByEmail($this->userObj->getEmail());
00514                         }
00515                         
00516                         $access_limit_mode = $access_limitations_obj->getMode($default_role);
00517                 
00518                         if ($access_limit_mode == 'absolute')
00519                         {
00520                                 $access_limit = $access_limitations_obj->getAbsolute($default_role);
00521                                 $this->userObj->setTimeLimitUnlimited(0);
00522                                 $this->userObj->setTimeLimitUntil($access_limit);
00523                         }
00524                         elseif ($access_limit_mode == 'relative')
00525                         {
00526                                 $rel_d = (int) $access_limitations_obj->getRelative($default_role,'d');
00527                                 $rel_m = (int) $access_limitations_obj->getRelative($default_role,'m');
00528                                 $rel_y = (int) $access_limitations_obj->getRelative($default_role,'y');
00529                                 
00530                                 $access_limit = $rel_d * 86400 + $rel_m * 2592000 + $rel_y * 31536000 + time();
00531                                 $this->userObj->setTimeLimitUnlimited(0);
00532                                 $this->userObj->setTimeLimitUntil($access_limit);
00533                         }
00534                         else
00535                         {
00536                                 $this->userObj->setTimeLimitUnlimited(1);
00537                                 $this->userObj->setTimeLimitUntil(time());
00538                         }                       
00539                 }
00540                 else
00541                 {
00542                         $this->userObj->setTimeLimitUnlimited(1);
00543                         $this->userObj->setTimeLimitUntil(time());
00544                 }
00545 
00546                 $this->userObj->setTimeLimitFrom(time());
00547 
00548                 $this->userObj->setUserDefinedData($_POST['udf']);
00549                 $this->userObj->create();
00550 
00551                 if($this->registration_settings->getRegistrationType() == IL_REG_DIRECT)
00552                 {
00553                         $this->userObj->setActive(1);
00554                 }
00555                 else
00556                 {
00557                         $this->userObj->setActive(0,0);
00558                 }
00559 
00560                 $this->userObj->updateOwner();
00561 
00562                 //insert user data in table user_data
00563                 $this->userObj->saveAsNew();
00564         
00565                 // store acceptance of user agreement
00566                 $this->userObj->writeAccepted();
00567 
00568                 // setup user preferences
00569                 $this->userObj->setLanguage($_POST["user"]["language"]);
00570                 $hits_per_page = $ilias->getSetting("hits_per_page");
00571                 if ($hits_per_page < 10)
00572                 {
00573                         $hits_per_page = 10;
00574                 }
00575                 $this->userObj->setPref("hits_per_page", $ilias->getSetting("hits_per_page"));
00576                 $show_online = $ilias->getSetting("show_users_online");
00577                 if ($show_online == "")
00578                 {
00579                         $show_online = "y";
00580                 }
00581                 $this->userObj->setPref("show_users_online", $show_online);
00582                 $this->userObj->writePrefs();
00583 
00584                 // Assign role (depends on settings in administration)
00585                 $this->__assignRole();
00586 
00587                 // Distribute mails
00588                 $this->__distributeMails();
00589 
00590                 $this->login();
00591                 return true;
00592         }
00593 
00594 
00595         function __validateRole()
00596         {
00597                 global $ilDB,$ilias,$ilErr,$lng;
00598 
00599                 // validate role
00600                 include_once("classes/class.ilObjRole.php");
00601                 if ($this->registration_settings->roleSelectionEnabled() and 
00602                         !ilObjRole::_lookupAllowRegister($_POST["user"]["default_role"]))
00603                 {
00604                         $ilias->raiseError("Invalid role selection in registration: ".
00605                                                            ilObject::_lookupTitle($_POST["user"]["default_role"])." [".$_POST["user"]["default_role"]."]".
00606                                                            ", IP: ".$_SERVER["REMOTE_ADDR"],$ilias->error_obj->FATAL);
00607                 }
00608                 return true;
00609         }
00610 
00611         function __assignRole()
00612         {
00613                 global $rbacadmin;
00614 
00615                 // Assign chosen role
00616                 if($this->registration_settings->roleSelectionEnabled())
00617                 {
00618                         return $rbacadmin->assignUser((int) $_POST['user']['default_role'],
00619                                                                                   $this->userObj->getId(),true);
00620                 }
00621                 
00622                 // Assign by email
00623                 include_once 'Services/Registration/classes/class.ilRegistrationEmailRoleAssignments.php';
00624 
00625                 $registration_role_assignments = new ilRegistrationRoleAssignments();
00626 
00627                 return $rbacadmin->assignUser((int) $registration_role_assignments->getRoleByEmail($this->userObj->getEmail()),
00628                                                                           $this->userObj->getId(),
00629                                                                           true);
00630                         
00631         }
00632 
00633         function __showRoleSelection()
00634         {
00635                 if(!$this->registration_settings->roleSelectionEnabled())
00636                 {
00637                         return true;
00638                 }
00639                 
00640                 // TODO put query in a function
00641                 include_once("classes/class.ilObjRole.php");
00642                 $reg_roles = ilObjRole::_lookupRegisterAllowed();
00643 
00644                 $rol = array();
00645                 foreach ($reg_roles as $role)
00646                 {
00647                         $rol[$role["id"]] = $role["title"];
00648                 }
00649 
00650                 $this->tpl->setCurrentBlock("role");
00651                 $this->tpl->setVariable("TXT_DEFAULT_ROLE",$this->lng->txt('default_role'));
00652                 $this->tpl->setVariable("DEFAULT_ROLE",ilUtil::formSelect($_POST["user"]["default_role"],
00653                                                                                                                                   "user[default_role]",
00654                                                                                                                                   $rol,false,true));
00655                 $this->tpl->parseCurrentBlock();
00656 
00657                 return true;
00658         }
00659 
00660         function __distributeMails()
00661         {
00662                 global $ilias;
00663                 
00664                 include_once './Services/Language/classes/class.ilLanguage.php';
00665                 include_once './Services/User/classes/class.ilObjUser.php';
00666         include_once "Services/Mail/classes/class.ilFormatMail.php";
00667 
00668 
00669                 $settings = $ilias->getAllSettings();
00670                 
00671                 // Always send mail to approvers
00672         #if($this->registration_settings->getRegistrationType() == IL_REG_APPROVE)
00673                 {
00674                         // Send mail to approvers
00675                         foreach($this->registration_settings->getApproveRecipients() as $recipient)
00676                         {
00677                                 $lng = new ilLanguage(ilObjUser::_lookupLanguage($recipient));
00678                                 $lng->loadLanguageModule('registration');
00679 
00680                                 #$umail = new ilFormatMail(6); // Send as system administrator
00681                                 $umail = new ilFormatMail($this->userObj->getId());
00682                                 $umail->enableSoap(false);
00683 
00684                                 $subject = $lng->txt("client_id") . " " . $ilias->client_id . ": " . $lng->txt("usr_new");
00685 
00686                                 // build body
00687                                 $body = $lng->txt('reg_mail_new_user_body')."\n\n";
00688                                 $body .= $lng->txt('reg_mail_body_profile')."\n\n";
00689 
00690                                 $body .= $this->userObj->getProfileAsString($lng);
00691                                 $umail->sendMail(ilObjUser::_lookupLogin($recipient),"","",$subject,$body,array(),array("normal"));
00692                         }
00693                 }
00694                 // Send mail to new user
00695                 
00696                 // try individual account mail in user administration
00697                 include_once("Services/Mail/classes/class.ilAccountMail.php");
00698                 include_once './Services/User/classes/class.ilObjUserFolder.php';
00699                 $amail = ilObjUserFolder::_lookupNewAccountMail($GLOBALS["lng"]->getDefaultLanguage());
00700                 if (trim($amail["body"]) != "" && trim($amail["subject"]) != "")
00701                 {
00702                         $acc_mail = new ilAccountMail();                
00703                         $acc_mail->setUser($this->userObj);
00704                         if ($this->registration_settings->passwordGenerationEnabled())
00705                         {
00706                                 $acc_mail->setUserPassword($_POST["user"]["passwd"]);
00707                         }
00708                         $acc_mail->send();
00709                 }
00710                 else    // do default mail
00711                 {
00712                         include_once "Services/Mail/classes/class.ilMimeMail.php";
00713 
00714                         $mmail = new ilMimeMail();
00715                         $mmail->autoCheck(false);
00716                         $mmail->From($settings["admin_email"]);
00717                         $mmail->To($this->userObj->getEmail());
00718 
00719                         // mail subject
00720                         $subject = $this->lng->txt("reg_mail_subject");
00721         
00722                         // mail body
00723                         $body = $this->lng->txt("reg_mail_body_salutation")." ".$this->userObj->getFullname().",\n\n".
00724                                 $this->lng->txt("reg_mail_body_text1")."\n\n".
00725                                 $this->lng->txt("reg_mail_body_text2")."\n".
00726                                 ILIAS_HTTP_PATH."/login.php?client_id=".$ilias->client_id."\n".
00727                                 $this->lng->txt("login").": ".$this->userObj->getLogin()."\n";
00728                                 
00729                         if ($this->registration_settings->passwordGenerationEnabled())
00730                         {
00731                                 $body.= $this->lng->txt("passwd").": ".$_POST["user"]["passwd"]."\n";
00732                         }
00733                         $body.= "\n";
00734 
00735                         // Info about necessary approvement
00736                         if($this->registration_settings->getRegistrationType() == IL_REG_APPROVE)
00737                         {
00738                                 $body .= ($this->lng->txt('reg_mail_body_pwd_generation')."\n\n");
00739                         }
00740                         $body .= ($this->lng->txt("reg_mail_body_text3")."\n\r");
00741                         $body .= $this->userObj->getProfileAsString($this->lng);
00742                         $mmail->Subject($subject);
00743                         $mmail->Body($body);
00744                         $mmail->Send();
00745                 }
00746         }
00747 }
00748 ?>

Generated on Fri Dec 13 2013 17:57:00 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1