00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00034 require_once "include/inc.header.php";
00035
00036
00037 if (!$ilias->getSetting("enable_registration") or AUTH_CURRENT != AUTH_LOCAL)
00038 {
00039 if (empty($_SESSION["AccountId"]) and $_SESSION["AccountId"] !== false)
00040 {
00041 $ilias->raiseError($lng->txt("permission_denied"),$ilias->error_obj->WARNING);
00042 }
00043 }
00044
00045 switch ($_GET["cmd"])
00046 {
00047 case "save":
00048 saveForm();
00049 break;
00050
00051 case "login":
00052 loginPage();
00053 break;
00054
00055 default:
00056 displayForm();
00057 break;
00058 }
00059
00060 function loginPage()
00061 {
00062 global $tpl,$ilias,$lng;
00063
00064 $tpl->addBlockFile("CONTENT", "content", "tpl.usr_registered.html");
00065 $tpl->setVariable("FORMACTION","login.php");
00066 $tpl->setVariable("TARGET","target=\"_parent\"");
00067 $tpl->setVariable("TXT_PAGEHEADLINE", $lng->txt("registration"));
00068 $tpl->setVariable("TXT_WELCOME", $lng->txt("welcome").", ".urldecode(ilUtil::stripSlashes($_GET["name"]))."!");
00069 if ($ilias->getSetting("auto_registration"))
00070 {
00071 $tpl->setVariable("TXT_REGISTERED", $lng->txt("txt_registered"));
00072 }
00073 else
00074 {
00075 $tpl->setVariable("TXT_REGISTERED", $lng->txt("txt_submitted"));
00076 }
00077 $tpl->setVariable("TXT_LOGIN", $lng->txt("login"));
00078 $tpl->setVariable("USERNAME", base64_decode($_GET["user"]));
00079 $tpl->setVariable("PASSWORD", base64_decode($_GET["pass"]));
00080
00081 $ilias->auth->logout();
00082 session_destroy();
00083
00084 $tpl->show();
00085 }
00086
00087 function saveForm()
00088 {
00089 global $tpl, $ilias, $lng, $rbacadmin;
00090
00091
00092 $settings = $ilias->getAllSettings();
00093
00094
00095
00096
00097
00098
00099 if (! ($_POST["status"]=="accepted") )
00100 {
00101 $ilias->raiseError($lng->txt("force_accept_usr_agreement"),$ilias->error_obj->MESSAGE);
00102 }
00103
00104
00105 foreach ($settings as $key => $val)
00106 {
00107 if (substr($key,0,8) == "require_")
00108 {
00109 if ($settings["passwd_auto_generate"] == 1 and ($key == "require_passwd" or $key == "require_passwd2"))
00110 {
00111 continue;
00112 }
00113
00114 $require_keys[] = substr($key,8);
00115 }
00116 }
00117
00118 foreach ($require_keys as $key => $val)
00119 {
00120 if (isset($settings["require_" . $val]) && $settings["require_" . $val])
00121 {
00122 if (empty($_POST["Fobject"][$val]))
00123 {
00124 $ilias->raiseError($lng->txt("fill_out_all_required_fields") . ": " . $lng->txt($val),$ilias->error_obj->MESSAGE);
00125 }
00126 }
00127 }
00128
00129
00130 if (!ilUtil::isLogin($_POST["Fobject"]["login"]))
00131 {
00132 $ilias->raiseError($lng->txt("login_invalid"),$ilias->error_obj->MESSAGE);
00133 }
00134
00135
00136 if (loginExists($_POST["Fobject"]["login"]))
00137 {
00138 $ilias->raiseError($lng->txt("login_exists"),$ilias->error_obj->MESSAGE);
00139 }
00140
00141 if ($settings["passwd_auto_generate"] != 1)
00142 {
00143
00144 if ($_POST["Fobject"]["passwd"] != $_POST["Fobject"]["passwd2"])
00145 {
00146 $ilias->raiseError($lng->txt("passwd_not_match"),$ilias->error_obj->MESSAGE);
00147 }
00148
00149
00150 if (!ilUtil::isPassword($_POST["Fobject"]["passwd"]))
00151 {
00152 $ilias->raiseError($lng->txt("passwd_invalid"),$ilias->error_obj->MESSAGE);
00153 }
00154 }
00155 else
00156 {
00157 $passwd = ilUtil::generatePasswords(1);
00158 $_POST["Fobject"]["passwd"] = $passwd[0];
00159 }
00160
00161
00162 if (!ilUtil::is_email($_POST["Fobject"]["email"]))
00163 {
00164 $ilias->raiseError($lng->txt("email_not_valid"),$ilias->error_obj->MESSAGE);
00165 }
00166
00167
00168
00169
00170
00171
00172 $userObj = new ilObjUser();
00173 $userObj->assignData($_POST["Fobject"]);
00174 $userObj->setTitle($userObj->getFullname());
00175 $userObj->setDescription($userObj->getEmail());
00176
00177
00178 $userObj->setTimeLimitOwner(7);
00179 $userObj->setTimeLimitUnlimited(1);
00180 $userObj->setTimeLimitFrom(time());
00181 $userObj->setTimeLimitUntil(time());
00182
00183 $userObj->create();
00184
00185 if (isset($settings["auto_registration"]) && ($settings["auto_registration"] == 1))
00186 {
00187 $userObj->setActive(1, 6);
00188 }
00189 else
00190 {
00191 $userObj->setActive(0, 0);
00192 }
00193
00194 $userObj->updateOwner();
00195
00196
00197 $userObj->saveAsNew();
00198
00199
00200 $userObj->writeAccepted();
00201
00202
00203 $userObj->setLanguage($_POST["Fobject"]["language"]);
00204 $userObj->writePrefs();
00205
00206
00207 $rbacadmin->assignUser($_POST["Fobject"]["default_role"],$userObj->getId(),true);
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224 if (!$ilias->getSetting("auto_registration"))
00225 {
00226 $approve_recipient = $ilias->getSetting("approve_recipient");
00227 if (empty($approve_recipient))
00228 {
00229 $approve_recipient = $userObj->getLoginByUserId(6);
00230 }
00231
00232 include_once "classes/class.ilFormatMail.php";
00233
00234 $umail = new ilFormatMail($userObj->getId());
00235
00236
00237 $subject = $lng->txt("client_id") . " " . $ilias->client_id . ": " . $lng->txt("usr_new");
00238
00239
00240 $body = $lng->txt("login").": ".$userObj->getLogin()."\n\r".
00241 $lng->txt("passwd").": ".$_POST["Fobject"]["passwd"]."\n\r".
00242 $lng->txt("title").": ".$userObj->getTitle()."\n\r".
00243 $lng->txt("gender").": ".$userObj->getGender()."\n\r".
00244 $lng->txt("firstname").": ".$userObj->getFirstname()."\n\r".
00245 $lng->txt("lastname").": ".$userObj->getLastname()."\n\r".
00246 $lng->txt("institution").": ".$userObj->getInstitution()."\n\r".
00247 $lng->txt("department").": ".$userObj->getDepartment()."\n\r".
00248 $lng->txt("street").": ".$userObj->getStreet()."\n\r".
00249 $lng->txt("city").": ".$userObj->getCity()."\n\r".
00250 $lng->txt("zipcode").": ".$userObj->getZipcode()."\n\r".
00251 $lng->txt("country").": ".$userObj->getCountry()."\n\r".
00252 $lng->txt("phone_office").": ".$userObj->getPhoneOffice()."\n\r".
00253 $lng->txt("phone_home").": ".$userObj->getPhoneHome()."\n\r".
00254 $lng->txt("phone_mobile").": ".$userObj->getPhoneMobile()."\n\r".
00255 $lng->txt("fax").": ".$userObj->getFax()."\n\r".
00256 $lng->txt("email").": ".$userObj->getEmail()."\n\r".
00257 $lng->txt("hobby").": ".$userObj->getHobby()."\n\r".
00258 $lng->txt("referral_comment").": ".$userObj->getComment()."\n\r".
00259 $lng->txt("matriculation").": ".$userObj->getMatriculation()."\n\r".
00260 $lng->txt("create_date").": ".$userObj->getCreateDate()."\n\r".
00261 $lng->txt("default_role").": ".$_POST["Fobject"]["default_role"]."\n\r";
00262
00263 $error_message = $umail->sendMail($approve_recipient,"","",$subject,$body,array(),array("normal"));
00264 }
00265
00266 if ($settings["passwd_auto_generate"] == 1)
00267 {
00268 include_once "classes/class.ilMimeMail.php";
00269
00270 $mmail = new ilMimeMail();
00271 $mmail->autoCheck(false);
00272 $mmail->From($settings["admin_email"]);
00273 $mmail->To($userObj->getEmail());
00274
00275
00276 $subject = $lng->txt("reg_mail_subject");
00277
00278
00279 $body = $lng->txt("reg_mail_body_salutation")." ".$userObj->getFullname().",\n\r".
00280 $lng->txt("reg_mail_body_welcome")."\n\r".
00281 $lng->txt("reg_mail_body_text1")."\n\r".
00282 $lng->txt("reg_mail_body_text2")."\n\r".
00283 ILIAS_HTTP_PATH."login.php?client_id=".$ilias->client_id."\n\r".
00284 $lng->txt("login").": ".$userObj->getLogin()."\n\r".
00285 $lng->txt("passwd").": ".$_POST["Fobject"]["passwd"]."\n\r\n\r".
00286 $lng->txt("reg_mail_body_text3")."\n\r".
00287 $lng->txt("title").": ".$userObj->getTitle()."\n\r".
00288 $lng->txt("gender").": ".$userObj->getGender()."\n\r".
00289 $lng->txt("firstname").": ".$userObj->getFirstname()."\n\r".
00290 $lng->txt("lastname").": ".$userObj->getLastname()."\n\r".
00291 $lng->txt("institution").": ".$userObj->getInstitution()."\n\r".
00292 $lng->txt("department").": ".$userObj->getDepartment()."\n\r".
00293 $lng->txt("street").": ".$userObj->getStreet()."\n\r".
00294 $lng->txt("city").": ".$userObj->getCity()."\n\r".
00295 $lng->txt("zipcode").": ".$userObj->getZipcode()."\n\r".
00296 $lng->txt("country").": ".$userObj->getCountry()."\n\r".
00297 $lng->txt("phone_office").": ".$userObj->getPhoneOffice()."\n\r".
00298 $lng->txt("phone_home").": ".$userObj->getPhoneHome()."\n\r".
00299 $lng->txt("phone_mobile").": ".$userObj->getPhoneMobile()."\n\r".
00300 $lng->txt("fax").": ".$userObj->getFax()."\n\r".
00301 $lng->txt("email").": ".$userObj->getEmail()."\n\r".
00302 $lng->txt("hobby").": ".$userObj->getHobby()."\n\r".
00303 $lng->txt("referral_comment").": ".$userObj->getComment()."\n\r".
00304 $lng->txt("create_date").": ".$userObj->getCreateDate()."\n\r".
00305 $lng->txt("default_role").": ".$_POST["Fobject"]["default_role"]."\n\r";
00306
00307 $mmail->Subject($subject);
00308 $mmail->Body($body);
00309 $mmail->Send();
00310 }
00311
00312 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())));
00313 }
00314
00315
00316 function displayForm()
00317 {
00318 global $tpl,$ilias,$lng,$ObjDefinition;
00319
00320
00321 $settings = $ilias->getAllSettings();
00322
00323
00324 $tpl->addBlockFile("CONTENT", "content", "tpl.usr_registration.html");
00325 $tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
00326
00327
00328
00329
00330
00331 $q = "SELECT * FROM role_data ".
00332 "LEFT JOIN object_data ON object_data.obj_id = role_data.role_id ".
00333 "WHERE allow_register = 1";
00334 $r = $ilias->db->query($q);
00335
00336 if ($r->numRows() > 0)
00337 {
00338 while ($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
00339 {
00340 $role_list[$row->obj_id] = fetchObjectData($row);
00341 }
00342 }
00343
00344 foreach ($role_list as $obj_data)
00345 {
00346 $rol[$obj_data["obj_id"]] = $obj_data["title"];
00347 }
00348
00349 $role = ilUtil::formSelect($_SESSION["error_post_vars"]["Fobject"]["default_role"],"Fobject[default_role]",$rol,false,true);
00350
00351 $data = array();
00352 $data["fields"] = array();
00353 $data["fields"]["login"] = "";
00354
00355 if ($settings["passwd_auto_generate"] != 1)
00356 {
00357 $data["fields"]["passwd"] = "";
00358 $data["fields"]["passwd2"] = "";
00359 }
00360
00361 $data["fields"]["title"] = "";
00362 $data["fields"]["gender"] = "";
00363 $data["fields"]["firstname"] = "";
00364 $data["fields"]["lastname"] = "";
00365 $data["fields"]["institution"] = "";
00366 $data["fields"]["department"] = "";
00367 $data["fields"]["street"] = "";
00368 $data["fields"]["city"] = "";
00369 $data["fields"]["zipcode"] = "";
00370 $data["fields"]["country"] = "";
00371 $data["fields"]["phone_office"] = "";
00372 $data["fields"]["phone_home"] = "";
00373 $data["fields"]["phone_mobile"] = "";
00374 $data["fields"]["fax"] = "";
00375 $data["fields"]["email"] = "";
00376 $data["fields"]["hobby"] = "";
00377 $data["fields"]["referral_comment"] = "";
00378 $data["fields"]["matriculation"] = "";
00379 $data["fields"]["default_role"] = $role;
00380
00381
00382 foreach ($data["fields"] as $key => $val)
00383 {
00384 $str = $lng->txt($key);
00385 if ($key == "title")
00386 {
00387 $str = $lng->txt("person_title");
00388 }
00389
00390
00391 if (isset($settings["require_" . $key]) && $settings["require_" . $key])
00392 {
00393 $str = $str . '<span class="asterisk">*</span>';
00394 }
00395
00396 $tpl->setVariable("TXT_".strtoupper($key), $str);
00397
00398 if ($key == "default_role")
00399 {
00400 $tpl->setVariable(strtoupper($key), $val);
00401 }
00402 else
00403 {
00404 $tpl->setVariable(strtoupper($key), ilUtil::prepareFormOutput($val,true));
00405 }
00406 }
00407
00408
00409 if ($settings["passwd_auto_generate"] != 1)
00410 {
00411
00412 $str = $lng->txt("retype_password");
00413 if (isset($settings["require_passwd2"]) && $settings["require_passwd2"])
00414 {
00415 $str = $str . '<span class="asterisk">*</span>';
00416 }
00417
00418 $tpl->setVariable("TXT_PASSWD2", $str);
00419 }
00420 else
00421 {
00422 $tpl->setVariable("TXT_PASSWD_SELECT", $lng->txt("passwd"));
00423 $tpl->setVariable("TXT_PASSWD_VIA_MAIL", $lng->txt("reg_passwd_via_mail"));
00424 }
00425
00426 $tpl->setVariable("FORMACTION", "register.php?cmd=save&lang=".$_GET["lang"]);
00427 $tpl->setVariable("TXT_SAVE", $lng->txt("save"));
00428 $tpl->setVariable("TXT_REQUIRED_FIELDS", $lng->txt("required_field"));
00429 $tpl->setVariable("TXT_LOGIN_DATA", $lng->txt("login_data"));
00430 $tpl->setVariable("TXT_PERSONAL_DATA", $lng->txt("personal_data"));
00431 $tpl->setVariable("TXT_CONTACT_DATA", $lng->txt("contact_data"));
00432 $tpl->setVariable("TXT_SETTINGS", $lng->txt("settings"));
00433 $tpl->setVariable("TXT_OTHER", $lng->txt("user_profile_other"));
00434 $tpl->setVariable("TXT_LANGUAGE",$lng->txt("language"));
00435 $tpl->setVariable("TXT_GENDER_F",$lng->txt("gender_f"));
00436 $tpl->setVariable("TXT_GENDER_M",$lng->txt("gender_m"));
00437
00438
00439 $languages = $lng->getInstalledLanguages();
00440
00441 $count = (int) round(count($languages) / 2);
00442 $num = 1;
00443
00444 foreach ($languages as $lang_key)
00445 {
00446
00447
00448
00449
00450
00451
00452
00453 $tpl->setCurrentBlock("languages");
00454 $tpl->setVariable("LINK_LANG", "./register.php?lang=".$lang_key);
00455 $tpl->setVariable("LANG_NAME", $lng->txt("lang_".$lang_key));
00456 $tpl->setVariable("LANG_ICON", $lang_key);
00457 $tpl->setVariable("BORDER", 0);
00458 $tpl->setVariable("VSPACE", 0);
00459 $tpl->parseCurrentBlock();
00460
00461 $num++;
00462 }
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472 $selected_lang = (isset($_SESSION["error_post_vars"]["Fobject"]["language"])) ? $_SESSION["error_post_vars"]["Fobject"]["language"] : $lng->lang_key;
00473
00474 foreach ($languages as $lang_key)
00475 {
00476 $tpl->setCurrentBlock("language_selection");
00477 $tpl->setVariable("LANG", $lng->txt("lang_".$lang_key));
00478 $tpl->setVariable("LANGSHORT", $lang_key);
00479
00480 if ($selected_lang == $lang_key)
00481 {
00482 $tpl->setVariable("SELECTED_LANG", "selected=\"selected\"");
00483 }
00484
00485 $tpl->parseCurrentBlock();
00486 }
00487
00488
00489 if (isset($_SESSION["error_post_vars"]["Fobject"]))
00490 {
00491 foreach ($_SESSION["error_post_vars"]["Fobject"] as $key => $val)
00492 {
00493 if ($key != "default_role" and $key != "language")
00494 {
00495 $tpl->setVariable(strtoupper($key), ilUtil::prepareFormOutput($val,true));
00496 }
00497 }
00498
00499
00500 $gender = strtoupper($_SESSION["error_post_vars"]["Fobject"]["gender"]);
00501
00502 if (!empty($gender))
00503 {
00504 $tpl->setVariable("BTN_GENDER_".$gender,"checked=\"checked\"");
00505 }
00506 }
00507
00508 $tpl->setVariable("TXT_PAGEHEADLINE", $lng->txt("registration"));
00509 $tpl->setVariable("TXT_PAGETITLE", "ILIAS3 - ".$lng->txt("registration"));
00510 $tpl->setVariable("TXT_REGISTER_INFO", $lng->txt("register_info"));
00511 $tpl->setVariable("AGREEMENT", getUserAgreement());
00512 $tpl->setVariable("ACCEPT_CHECKBOX", ilUtil::formCheckbox(0, "status", "accepted"));
00513 $tpl->setVariable("ACCEPT_AGREEMENT", $lng->txt("accept_usr_agreement") . '<span class="asterisk">*</span>');
00514
00515 $tpl->show();
00516
00517 }
00518
00519 function getUserAgreement()
00520 {
00521 global $lng, $ilias, $ilLog;
00522
00523 $tmpPath = getcwd();
00524 $tmpsave = getcwd();
00525 $agrPath = $tmpPath."/agreement";
00526 chdir($agrPath);
00527
00528 $agreement = "agreement_".$lng->lang_key.".html";
00529
00530
00531 if (!file_exists($agreement))
00532 {
00533 $ilLog->write("view_usr_agreement.php: Agreement file ".$agreement." has not been found (user language).");
00534 $agreement = "agreement_".$lng->lang_default.".html";
00535 }
00536
00537
00538
00539 if (!file_exists($agreement))
00540 {
00541 $ilLog->write("view_usr_agreement.php: Agreement file ".$agreement." has not been found (system language).");
00542 $agreement = "agreement_en.html";
00543 }
00544
00545
00546 if (file_exists($agreement))
00547 {
00548 if ($content = file($agreement))
00549 {
00550 foreach ($content as $key => $val)
00551 {
00552 $text .= trim(nl2br($val));
00553 }
00554 chdir($tmpsave);
00555 return $text;
00556 }
00557 else
00558 {
00559 $ilias->raiseError($lng->txt("usr_agreement_empty"),$ilias->error_obj->MESSAGE);
00560 }
00561 }
00562 else
00563 {
00564 $ilias->raiseError($lng->txt("file_not_found").": ".$agreement,
00565 $ilias->error_obj->MESSAGE);
00566 }
00567
00568 chdir($tmpsave);
00569 }
00570 ?>
00571