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

register.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2005 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 
00024 
00034 require_once "include/inc.header.php";
00035 require_once "classes/class.ilUserAgreement.php";
00036 
00037 // catch hack attempts
00038 if (!$ilias->getSetting("enable_registration") or AUTH_CURRENT != AUTH_LOCAL)
00039 {
00040     if (empty($_SESSION["AccountId"]) and $_SESSION["AccountId"] !== false)
00041     {
00042         $ilias->raiseError($lng->txt("permission_denied"),$ilias->error_obj->WARNING);
00043     }
00044 }
00045 
00046 switch ($_GET["cmd"])
00047 {
00048         case "save":
00049                 saveForm();
00050                 break;
00051 
00052         case "login":
00053                 loginPage();
00054                 break;
00055 
00056         default:
00057                 displayForm();
00058                 break;
00059 }
00060 
00061 function loginPage()
00062 {
00063         global $tpl,$ilias,$lng;
00064 
00065         $tpl->addBlockFile("CONTENT", "content", "tpl.usr_registered.html");
00066         $tpl->setVariable("FORMACTION","login.php");
00067         $tpl->setVariable("TARGET","target=\"_parent\"");
00068         $tpl->setVariable("TXT_PAGEHEADLINE", $lng->txt("registration"));
00069         $tpl->setVariable("TXT_WELCOME", $lng->txt("welcome").", ".urldecode(ilUtil::stripSlashes($_GET["name"]))."!");
00070     if ($ilias->getSetting("auto_registration"))
00071     {
00072         $tpl->setVariable("TXT_REGISTERED", $lng->txt("txt_registered"));
00073     }
00074     else
00075     {
00076         $tpl->setVariable("TXT_REGISTERED", $lng->txt("txt_submitted"));
00077     }
00078         $tpl->setVariable("TXT_LOGIN", $lng->txt("login"));
00079         $tpl->setVariable("USERNAME", base64_decode($_GET["user"]));
00080         $tpl->setVariable("PASSWORD", base64_decode($_GET["pass"]));
00081 
00082         $ilias->auth->logout();
00083         session_destroy();
00084 
00085         $tpl->show();
00086 }
00087 
00088 function saveForm()
00089 {
00090         global $tpl, $ilias, $lng, $rbacadmin;
00091 
00092     //load ILIAS settings
00093     $settings = $ilias->getAllSettings();
00094 
00095         //$tpl->addBlockFile("CONTENT", "content", "tpl.group_basic.html");
00096         //sendInfo();
00097         //InfoPanel();
00098 
00099         //check, whether user-agreement has been accepted
00100         if (! ($_POST["status"]=="accepted") )
00101         {
00102                 $ilias->raiseError($lng->txt("force_accept_usr_agreement"),$ilias->error_obj->MESSAGE);
00103     }
00104 
00105     // check dynamically required fields
00106     foreach ($settings as $key => $val)
00107     {
00108         if (substr($key,0,8) == "require_")
00109         {
00110             if ($settings["passwd_auto_generate"] == 1 and ($key == "require_passwd" or $key == "require_passwd2"))
00111             {
00112                 continue;
00113             }
00114             
00115             $require_keys[] = substr($key,8);
00116         }
00117     }
00118 
00119     foreach ($require_keys as $key => $val)
00120     {
00121         if (isset($settings["require_" . $val]) && $settings["require_" . $val])
00122         {
00123             if (empty($_POST["Fobject"][$val]))
00124             {
00125                 $ilias->raiseError($lng->txt("fill_out_all_required_fields") . ": " . $lng->txt($val),$ilias->error_obj->MESSAGE);
00126             }
00127         }
00128     }
00129 
00130     // validate username
00131         if (!ilUtil::isLogin($_POST["Fobject"]["login"]))
00132         {
00133                 $ilias->raiseError($lng->txt("login_invalid"),$ilias->error_obj->MESSAGE);
00134         }
00135 
00136         // check loginname
00137         if (loginExists($_POST["Fobject"]["login"]))
00138         {
00139                 $ilias->raiseError($lng->txt("login_exists"),$ilias->error_obj->MESSAGE);
00140         }
00141 
00142     if ($settings["passwd_auto_generate"] != 1)
00143     {
00144         // check passwords
00145         if ($_POST["Fobject"]["passwd"] != $_POST["Fobject"]["passwd2"])
00146         {
00147             $ilias->raiseError($lng->txt("passwd_not_match"),$ilias->error_obj->MESSAGE);
00148         }
00149 
00150         // validate password
00151         if (!ilUtil::isPassword($_POST["Fobject"]["passwd"]))
00152         {
00153             $ilias->raiseError($lng->txt("passwd_invalid"),$ilias->error_obj->MESSAGE);
00154         }
00155     }
00156     else
00157     {    
00158         $passwd = ilUtil::generatePasswords(1);
00159         $_POST["Fobject"]["passwd"] = $passwd[0];
00160     }
00161         // The password type is not passed in the post data. Therefore we
00162         // append it here manually.
00163         require_once "classes/class.ilObjUser.php";
00164     $_POST["Fobject"]["passwd_type"] = IL_PASSWD_PLAIN;
00165 
00166         // validate email
00167         if (!ilUtil::is_email($_POST["Fobject"]["email"]))
00168         {
00169                 $ilias->raiseError($lng->txt("email_not_valid"),$ilias->error_obj->MESSAGE);
00170         }
00171 
00172         // validate role
00173         include_once("classes/class.ilObjRole.php");
00174         if (!ilObjRole::_lookupAllowRegister($_POST["Fobject"]["default_role"]))
00175         {
00176                 $ilias->raiseError("Invalid role selection in registration: ".
00177                         ilObject::_lookupTitle($_POST["Fobject"]["default_role"])." [".$_POST["Fobject"]["default_role"]."]".
00178                         ", IP: ".$_SERVER["REMOTE_ADDR"],$ilias->error_obj->FATAL);
00179         }
00180         
00181 
00182         // TODO: check if login or passwd already exists
00183         // TODO: check length of login and passwd
00184 
00185         // checks passed. save user
00186 
00187         $userObj = new ilObjUser();
00188         $userObj->assignData($_POST["Fobject"]);
00189         $userObj->setTitle($userObj->getFullname());
00190         $userObj->setDescription($userObj->getEmail());
00191 
00192         // Time limit
00193         $userObj->setTimeLimitOwner(7);
00194         $userObj->setTimeLimitUnlimited(1);
00195         $userObj->setTimeLimitFrom(time());
00196         $userObj->setTimeLimitUntil(time());
00197 
00198         $userObj->create();
00199 
00200     if (isset($settings["auto_registration"]) && ($settings["auto_registration"] == 1))
00201     {
00202         $userObj->setActive(1, 6);
00203     }
00204     else
00205     {
00206         $userObj->setActive(0, 0);
00207     }
00208 
00209     $userObj->updateOwner();
00210 
00211         //insert user data in table user_data
00212         $userObj->saveAsNew();
00213         
00214         // store acceptance of user agreement
00215         $userObj->writeAccepted();
00216 
00217         // setup user preferences
00218         $userObj->setLanguage($_POST["Fobject"]["language"]);
00219         $userObj->writePrefs();
00220 
00221         //set role entries
00222         $rbacadmin->assignUser($_POST["Fobject"]["default_role"],$userObj->getId(),true);
00223 
00224         // CREATE ENTRIES FOR MAIL BOX
00225         /* moved folder creation to ObjUser->saveAsNew
00226         include_once ("classes/class.ilMailbox.php");
00227         $mbox = new ilMailbox($userObj->getId());
00228         $mbox->createDefaultFolder();
00229 
00230         include_once "classes/class.ilMailOptions.php";
00231         $mail_options = new ilMailOptions($userObj->getId());
00232         $mail_options->createMailOptionsEntry();
00233 
00234         // create personal bookmark folder tree
00235         include_once "classes/class.ilBookmarkFolder.php";
00236         $bmf = new ilBookmarkFolder(0, $userObj->getId());
00237         $bmf->createNewBookmarkTree();*/
00238 
00239     if (!$ilias->getSetting("auto_registration"))
00240     {
00241         $approve_recipient = $ilias->getSetting("approve_recipient");
00242         if (empty($approve_recipient))
00243         {
00244             $approve_recipient = $userObj->getLoginByUserId(6);
00245         }
00246 
00247         include_once "classes/class.ilFormatMail.php";
00248 
00249         $umail = new ilFormatMail($userObj->getId());
00250 
00251         // mail subject
00252         $subject = $lng->txt("client_id") . " " . $ilias->client_id . ": " . $lng->txt("usr_new");
00253 
00254         // mail body
00255         $body = $lng->txt("login").": ".$userObj->getLogin()."\n\r".
00256                 $lng->txt("passwd").": ".$_POST["Fobject"]["passwd"]."\n\r".
00257                 $lng->txt("title").": ".$userObj->getTitle()."\n\r".
00258                 $lng->txt("gender").": ".$userObj->getGender()."\n\r".
00259                 $lng->txt("firstname").": ".$userObj->getFirstname()."\n\r".
00260                 $lng->txt("lastname").": ".$userObj->getLastname()."\n\r".
00261                 $lng->txt("institution").": ".$userObj->getInstitution()."\n\r".
00262                 $lng->txt("department").": ".$userObj->getDepartment()."\n\r".
00263                 $lng->txt("street").": ".$userObj->getStreet()."\n\r".
00264                 $lng->txt("city").": ".$userObj->getCity()."\n\r".
00265                 $lng->txt("zipcode").": ".$userObj->getZipcode()."\n\r".
00266                 $lng->txt("country").": ".$userObj->getCountry()."\n\r".
00267                 $lng->txt("phone_office").": ".$userObj->getPhoneOffice()."\n\r".
00268                 $lng->txt("phone_home").": ".$userObj->getPhoneHome()."\n\r".
00269                 $lng->txt("phone_mobile").": ".$userObj->getPhoneMobile()."\n\r".
00270                 $lng->txt("fax").": ".$userObj->getFax()."\n\r".
00271                 $lng->txt("email").": ".$userObj->getEmail()."\n\r".
00272                 $lng->txt("hobby").": ".$userObj->getHobby()."\n\r".
00273                 $lng->txt("referral_comment").": ".$userObj->getComment()."\n\r".
00274                 $lng->txt("matriculation").": ".$userObj->getMatriculation()."\n\r".
00275                 $lng->txt("create_date").": ".$userObj->getCreateDate()."\n\r".
00276                 $lng->txt("default_role").": ".$_POST["Fobject"]["default_role"]."\n\r";
00277 
00278         $error_message = $umail->sendMail($approve_recipient,"","",$subject,$body,array(),array("normal"));
00279     }
00280 
00281     if ($settings["passwd_auto_generate"] == 1)
00282     {
00283         include_once "classes/class.ilMimeMail.php";
00284 
00285                 $mmail = new ilMimeMail();
00286                 $mmail->autoCheck(false);
00287                 $mmail->From($settings["admin_email"]);
00288                 $mmail->To($userObj->getEmail());
00289 
00290         // mail subject
00291         $subject = $lng->txt("reg_mail_subject");
00292 
00293                 // mail body
00294                 $body = $lng->txt("reg_mail_body_salutation")." ".$userObj->getFullname().",\n\r".
00295                                 $lng->txt("reg_mail_body_welcome")."\n\r".
00296                                 $lng->txt("reg_mail_body_text1")."\n\r".
00297                                 $lng->txt("reg_mail_body_text2")."\n\r".
00298                                 ILIAS_HTTP_PATH."login.php?client_id=".$ilias->client_id."\n\r".
00299                                 $lng->txt("login").": ".$userObj->getLogin()."\n\r".
00300                                 $lng->txt("passwd").": ".$_POST["Fobject"]["passwd"]."\n\r\n\r".
00301                                 $lng->txt("reg_mail_body_text3")."\n\r".
00302                                 $lng->txt("title").": ".$userObj->getTitle()."\n\r".
00303                                 $lng->txt("gender").": ".$userObj->getGender()."\n\r".
00304                                 $lng->txt("firstname").": ".$userObj->getFirstname()."\n\r".
00305                                 $lng->txt("lastname").": ".$userObj->getLastname()."\n\r".
00306                                 $lng->txt("institution").": ".$userObj->getInstitution()."\n\r".
00307                                 $lng->txt("department").": ".$userObj->getDepartment()."\n\r".
00308                                 $lng->txt("street").": ".$userObj->getStreet()."\n\r".
00309                                 $lng->txt("city").": ".$userObj->getCity()."\n\r".
00310                                 $lng->txt("zipcode").": ".$userObj->getZipcode()."\n\r".
00311                                 $lng->txt("country").": ".$userObj->getCountry()."\n\r".
00312                                 $lng->txt("phone_office").": ".$userObj->getPhoneOffice()."\n\r".
00313                                 $lng->txt("phone_home").": ".$userObj->getPhoneHome()."\n\r".
00314                                 $lng->txt("phone_mobile").": ".$userObj->getPhoneMobile()."\n\r".
00315                                 $lng->txt("fax").": ".$userObj->getFax()."\n\r".
00316                                 $lng->txt("email").": ".$userObj->getEmail()."\n\r".
00317                                 $lng->txt("hobby").": ".$userObj->getHobby()."\n\r".
00318                                 $lng->txt("referral_comment").": ".$userObj->getComment()."\n\r".
00319                                 $lng->txt("create_date").": ".$userObj->getCreateDate()."\n\r".
00320                                 $lng->txt("default_role").": ".$_POST["Fobject"]["default_role"]."\n\r";
00321 
00322                 $mmail->Subject($subject);
00323                 $mmail->Body($body);
00324                 $mmail->Send();
00325     }
00326 
00327         ilUtil::redirect("register.php?lang=".$_GET["lang"]."&cmd=login&user=".base64_encode($_POST["Fobject"]["login"])."&pass=".base64_encode($_POST["Fobject"]["passwd"])."&name=".urlencode(ilUtil::stripSlashes($userObj->getFullname())));
00328 }
00329 
00330 
00331 function displayForm()
00332 {
00333         global $tpl,$ilias,$lng,$ObjDefinition;
00334 
00335     //load ILIAS settings
00336     $settings = $ilias->getAllSettings();
00337 
00338         // load login template
00339         $tpl->addBlockFile("CONTENT", "content", "tpl.usr_registration.html");
00340         $tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
00341 
00342         //sendInfo();
00343         //infoPanel();
00344         // role selection (only those roles marked with allow_register)
00345         // TODO put query in a function
00346         include_once("classes/class.ilObjRole.php");
00347         $reg_roles = ilObjRole::_lookupRegisterAllowed();
00348 
00349         $rol = array();
00350         foreach ($reg_roles as $role)
00351         {
00352                 $rol[$role["id"]] = $role["title"];
00353         }
00354 
00355         $role = ilUtil::formSelect($_SESSION["error_post_vars"]["Fobject"]["default_role"],"Fobject[default_role]",$rol,false,true);
00356 
00357         $data = array();
00358         $data["fields"] = array();
00359         $data["fields"]["login"] = "";
00360 
00361     if ($settings["passwd_auto_generate"] != 1)
00362     {
00363         $data["fields"]["passwd"] = "";
00364         $data["fields"]["passwd2"] = "";
00365     }
00366     
00367         $data["fields"]["title"] = "";
00368         $data["fields"]["gender"] = "";
00369         $data["fields"]["firstname"] = "";
00370         $data["fields"]["lastname"] = "";
00371         $data["fields"]["institution"] = "";
00372         $data["fields"]["department"] = "";
00373         $data["fields"]["street"] = "";
00374         $data["fields"]["city"] = "";
00375         $data["fields"]["zipcode"] = "";
00376         $data["fields"]["country"] = "";
00377         $data["fields"]["phone_office"] = "";
00378         $data["fields"]["phone_home"] = "";
00379         $data["fields"]["phone_mobile"] = "";
00380         $data["fields"]["fax"] = "";
00381         $data["fields"]["email"] = "";
00382         $data["fields"]["hobby"] = "";
00383         $data["fields"]["referral_comment"] = "";
00384         $data["fields"]["matriculation"] = "";
00385         $data["fields"]["default_role"] = $role;
00386 
00387         // fill presets
00388         foreach ($data["fields"] as $key => $val)
00389         {
00390                 $str = $lng->txt($key);
00391                 if ($key == "title")
00392                 {
00393                         $str = $lng->txt("person_title");
00394                 }
00395 
00396         // check to see if dynamically required
00397         if (isset($settings["require_" . $key]) && $settings["require_" . $key])
00398         {
00399             $str = $str . '<span class="asterisk">*</span>';
00400         }
00401 
00402                 $tpl->setVariable("TXT_".strtoupper($key), $str);
00403 
00404                 if ($key == "default_role")
00405                 {
00406                         $tpl->setVariable(strtoupper($key), $val);
00407                 }
00408                 else
00409                 {
00410                         $tpl->setVariable(strtoupper($key), ilUtil::prepareFormOutput($val,true));
00411                 }
00412         }
00413 
00414 
00415     if ($settings["passwd_auto_generate"] != 1)
00416     {
00417         // text label for passwd2 is nonstandard
00418         $str = $lng->txt("retype_password");
00419         if (isset($settings["require_passwd2"]) && $settings["require_passwd2"])
00420         {
00421             $str = $str . '<span class="asterisk">*</span>';
00422         }
00423 
00424         $tpl->setVariable("TXT_PASSWD2", $str);
00425     }
00426     else
00427     {
00428         $tpl->setVariable("TXT_PASSWD_SELECT", $lng->txt("passwd"));
00429         $tpl->setVariable("TXT_PASSWD_VIA_MAIL", $lng->txt("reg_passwd_via_mail"));
00430     }
00431 
00432         $tpl->setVariable("FORMACTION", "register.php?cmd=save&lang=".$_GET["lang"]);
00433         $tpl->setVariable("TXT_SAVE", $lng->txt("save"));
00434         $tpl->setVariable("TXT_REQUIRED_FIELDS", $lng->txt("required_field"));
00435         $tpl->setVariable("TXT_LOGIN_DATA", $lng->txt("login_data"));
00436         $tpl->setVariable("TXT_PERSONAL_DATA", $lng->txt("personal_data"));
00437         $tpl->setVariable("TXT_CONTACT_DATA", $lng->txt("contact_data"));
00438         $tpl->setVariable("TXT_SETTINGS", $lng->txt("settings"));
00439         $tpl->setVariable("TXT_OTHER", $lng->txt("user_profile_other"));
00440         $tpl->setVariable("TXT_LANGUAGE",$lng->txt("language"));
00441         $tpl->setVariable("TXT_GENDER_F",$lng->txt("gender_f"));
00442         $tpl->setVariable("TXT_GENDER_M",$lng->txt("gender_m"));
00443 
00444         // language selection
00445         $languages = $lng->getInstalledLanguages();
00446         
00447                 $count = (int) round(count($languages) / 2);
00448                 $num = 1;
00449                 
00450                 foreach ($languages as $lang_key)
00451                 {
00452                         /*
00453                         if ($num === $count)
00454                         {
00455                                 $tpl->touchBlock("lng_new_row");
00456                         }
00457                         */
00458 
00459                         $tpl->setCurrentBlock("languages");
00460                         $tpl->setVariable("LINK_LANG", "./register.php?lang=".$lang_key);
00461                         $tpl->setVariable("LANG_NAME", $lng->txt("lang_".$lang_key));
00462                         $tpl->setVariable("LANG_ICON", $lang_key);
00463                         $tpl->setVariable("BORDER", 0);
00464                         $tpl->setVariable("VSPACE", 0);
00465                         $tpl->parseCurrentBlock();
00466 
00467                         $num++;
00468                 }
00469                 
00470                 /*
00471                 if (count($languages) % 2)
00472                 {
00473                         $tpl->touchBlock("lng_empty_cell");
00474                 }
00475                 */
00476 
00477         // preselect previous chosen language otherwise default language
00478         $selected_lang = (isset($_SESSION["error_post_vars"]["Fobject"]["language"])) ? $_SESSION["error_post_vars"]["Fobject"]["language"] : $lng->lang_key;
00479 
00480         foreach ($languages as $lang_key)
00481         {
00482                 $tpl->setCurrentBlock("language_selection");
00483                 $tpl->setVariable("LANG", $lng->txt("lang_".$lang_key));
00484                 $tpl->setVariable("LANGSHORT", $lang_key);
00485 
00486                 if ($selected_lang == $lang_key)
00487                 {
00488                         $tpl->setVariable("SELECTED_LANG", "selected=\"selected\"");
00489                 }
00490 
00491                 $tpl->parseCurrentBlock();
00492         } // END language selection
00493 
00494         // FILL SAVED VALUES IN CASE OF ERROR
00495         if (isset($_SESSION["error_post_vars"]["Fobject"]))
00496         {
00497                 foreach ($_SESSION["error_post_vars"]["Fobject"] as $key => $val)
00498                 {
00499                         if ($key != "default_role" and $key != "language")
00500                         {
00501                                 $tpl->setVariable(strtoupper($key), ilUtil::prepareFormOutput($val,true));
00502                         }
00503                 }
00504 
00505                 // gender selection
00506                 $gender = strtoupper($_SESSION["error_post_vars"]["Fobject"]["gender"]);
00507 
00508                 if (!empty($gender))
00509                 {
00510                         $tpl->setVariable("BTN_GENDER_".$gender,"checked=\"checked\"");
00511                 }
00512         }
00513         
00514         $tpl->setVariable("TXT_PAGEHEADLINE", $lng->txt("registration"));
00515         $tpl->setVariable("TXT_PAGETITLE", "ILIAS3 - ".$lng->txt("registration"));
00516         $tpl->setVariable("TXT_REGISTER_INFO", $lng->txt("register_info"));
00517         $tpl->setVariable("AGREEMENT", ilUserAgreement::_getText());
00518         $tpl->setVariable("ACCEPT_CHECKBOX", ilUtil::formCheckbox(0, "status", "accepted"));
00519     $tpl->setVariable("ACCEPT_AGREEMENT", $lng->txt("accept_usr_agreement") . '<span class="asterisk">*</span>');
00520 
00521         $tpl->show();
00522 
00523 }
00524 
00525 ?>
00526 

Generated on Fri Dec 13 2013 09:06:37 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1