Facebook
From Kater, 6 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 334
  1. <?php
  2. if(!defined('INITIALIZED'))
  3.         exit;
  4.  
  5. //CREATE ACCOUNT FORM PAGE
  6. if($action == "")
  7. {
  8.         $main_content .= '<script type="text/javascript">
  9.  
  10. var accountHttp;
  11.  
  12. function checkAccount()
  13. {
  14.         if(document.getElementById("account_name").value=="")
  15.         {
  16.                 document.getElementById("acc_name_check").innerHTML = \'<b><font color="red">Please enter account name.</font></b>\';
  17.                 return;
  18.         }
  19.         accountHttp=GetXmlHttpObject();
  20.         if (accountHttp==null)
  21.         {
  22.                 return;
  23.         }
  24.         var account = document.getElementById("account_name").value;
  25.         var url="?subtopic=ajax_check_account&account=" + account + "&uid="+Math.random();
  26.         accountHttp.onreadystatechange=AccountStateChanged;
  27.         accountHttp.open("GET",url,true);
  28.         accountHttp.send(null);
  29. }
  30.  
  31. function AccountStateChanged()
  32. {
  33.         if (accountHttp.readyState==4)
  34.         {
  35.                 document.getElementById("acc_name_check").innerHTML=accountHttp.responseText;
  36.         }
  37. }
  38.  
  39. var emailHttp;
  40.  
  41. //sprawdza czy dane konto istnieje czy nie
  42. function checkEmail()
  43. {
  44.         if(document.getElementById("email").value=="")
  45.         {
  46.                 document.getElementById("email_check").innerHTML = \'<b><font color="red">Please enter e-mail.</font></b>\';
  47.                 return;
  48.         }
  49.         emailHttp=GetXmlHttpObject();
  50.         if (emailHttp==null)
  51.         {
  52.                 return;
  53.         }
  54.         var email = document.getElementById("email").value;
  55.         var url="?subtopic=ajax_check_email&email=" + email + "&uid="+Math.random();
  56.         emailHttp.onreadystatechange=EmailStateChanged;
  57.         emailHttp.open("GET",url,true);
  58.         emailHttp.send(null);
  59. }
  60.  
  61. function EmailStateChanged()
  62. {
  63.         if (emailHttp.readyState==4)
  64.         {
  65.                 document.getElementById("email_check").innerHTML=emailHttp.responseText;
  66.         }
  67. }
  68.  
  69.         function validate_required(field,alerttxt)
  70.         {
  71.                 with (field)
  72.                         {
  73.                         if (value==null||value==""||value==" ")
  74.                         {
  75.                                 alert(alerttxt);
  76.                                 return false;
  77.                         }
  78.                         else
  79.                         {
  80.                                 return true;
  81.                         }
  82.                 }
  83.         }
  84.  
  85.         function validate_email(field,alerttxt)
  86.         {
  87.                 with (field)
  88.                 {
  89.                         apos=value.indexOf("@");
  90.                         dotpos=value.lastIndexOf(".");
  91.                         if (apos<1||dotpos-apos<2)
  92.                         {
  93.                                 alert(alerttxt);
  94.                                 return false;
  95.                         }
  96.                         else
  97.                         {
  98.                                 return true;
  99.                         }
  100.                 }
  101.         }
  102.  
  103.         function validate_form(thisform)
  104.         {
  105.                 with (thisform)
  106.                 {
  107.                         if(validate_required(account_name,"Please enter name of new account!")==false)
  108.                         {
  109.                                 account_name.focus();
  110.                                 return false;
  111.                         }
  112.                         if(validate_required(email,"Please enter your e-mail!")==false)
  113.                         {
  114.                                 email.focus();
  115.                                 return false;
  116.                         }
  117.                         if(validate_email(email,"Invalid e-mail format!")==false)
  118.                         {
  119.                                 email.focus();
  120.                                 return false;
  121.                         }
  122.                         if(verifpass==1)
  123.                         {
  124.                                 if(validate_required(passor,"Please enter password!")==false)
  125.                                 {
  126.                                         passor.focus();
  127.                                         return false;
  128.                                 }
  129.                                 if (validate_required(passor2,"Please repeat password!")==false)
  130.                                 {
  131.                                         passor2.focus();
  132.                                         return false;
  133.                                 }
  134.                                 if(passor2.value!=passor.value)
  135.                                 {
  136.                                         alert(\'Repeated password is not equal to password!\');
  137.                                         return false;
  138.                                 }
  139.                         }
  140.                         if(verifya==1)
  141.                         {
  142.                                 if (validate_required(verify,"Please enter verification code!")==false)
  143.                                 {
  144.                                         verify.focus();return false;
  145.                                 }
  146.                         }
  147.                         if(rules.checked==false)
  148.                         {
  149.                                 alert(\'To create account you must accept server rules!\');
  150.                                 return false;
  151.                         }
  152.                 }
  153.         }
  154.         </script>';
  155.         $main_content .= 'To play on '.htmlspecialchars($config['server']['serverName']).' you need an account.
  156.                                                 All you have to do to create your new account is to enter your email address, password to new account, verification code from picture and to agree to the terms presented below.
  157.                                                 If you have done so, your account name, password and e-mail address will be shown on the following page and your account and password will be sent
  158.                                                 to your email address along with further instructions.<BR><BR>
  159.                                                 <FORM ACTION="?subtopic=createaccount&action=saveaccount" onsubmit="return validate_form(this)" METHOD=post>
  160.                                                 <TABLE WIDTH=100% BORDER=0 CELLSPACING=1 CELLPADDING=4>
  161.                                                 <TR><TD BGCOLOR="'.$config['site']['vdarkborder'].'" CLASS=white><B>Create an '.htmlspecialchars($config['server']['serverName']).' Account</B></TD></TR>
  162.                                                 <TR><TD BGCOLOR="'.$config['site']['darkborder'].'"><TABLE BORDER=0 CELLSPACING=8 CELLPADDING=0>
  163.                                                   <TR><TD>
  164.                                                     <TABLE BORDER=0 CELLSPACING=5 CELLPADDING=0>';
  165.         $main_content .= '<TR><TD width="150" valign="top"><B>Account name: </B></TD><TD colspan="2"><INPUT id="account_name" NAME="reg_name" onkeyup="checkAccount();" VALUE="" SIZE=30 MAXLENGTH=50><BR><font size="1" face="verdana,arial,helvetica">(Please enter your new account name)</font></TD></TR>
  166.                                           <TR><TD width="150"><b>Name status:</b></TD><TD colspan="2"><b><div id="acc_name_check">Please enter your account name.</div></b></TD></TR>
  167.                                         <TR><TD width="150" valign="top"><B>Email address: </B></TD><TD colspan="2"><INPUT id="email" NAME="reg_email" onkeyup="checkEmail();" VALUE="" SIZE=30 MAXLENGTH=50><BR><font size="1" face="verdana,arial,helvetica">(Your email address is required to recovery an '.htmlspecialchars($config['server']['serverName']).' account)</font></TD></TR>
  168.                                           <TR><TD width="150"><b>Email status:</b></TD><TD colspan="2"><b><div id="email_check">Please enter your e-mail.</div></b></TD></TR>';
  169.         if(!$config['site']['create_account_verify_mail'])
  170.         $main_content .= '<script type="text/javascript">var verifpass=1;</script>
  171.                                                 <TR><TD width="150" valign="top"><B>Password: </B></TD><TD colspan="2"><INPUT TYPE="password" id="passor" NAME="reg_password" VALUE="" SIZE=30 MAXLENGTH=50><BR><font size="1" face="verdana,arial,helvetica">(Here write your password to new account on '.htmlspecialchars($config['server']['serverName']).')</font></TD></TR>
  172.                                           <TR><TD width="150" valign="top"><B>Repeat password: </B></TD><TD colspan="2"><INPUT TYPE="password" id="passor2" NAME="reg_password2" VALUE="" SIZE=30 MAXLENGTH=50><BR><font size="1" face="verdana,arial,helvetica">(Repeat your password)</font></TD></TR>';
  173.         else
  174.                 $main_content .= '<script type="text/javascript">var verifpass=0;</script>';
  175.         if($config['site']['verify_code'])
  176.                 $main_content .= '<script type="text/javascript">var verifya=1;</script><TR><TD width="150"><B>Code: </B></TD><TD colspan="2"><img src="?subtopic=imagebuilder&image_refresher='.mt_rand(1,99999).'" border="0" alt="Image Verification is missing, please contact the administrator"></TD></TR>
  177.                                                   <TR><TD width="150" valign="top"><B>Verification Code: </B></TD><TD colspan="2"><INPUT id="verify" NAME="reg_code" VALUE="" SIZE=30 MAXLENGTH=50><BR><font size="1" face="verdana,arial,helvetica">(Here write verification code from picture)</font></TD></TR>';
  178.         else
  179.                 $main_content .= '<script type="text/javascript">var verifya=0;</script>';
  180.         $main_content .= '</TABLE>
  181.                                           </TD></TR>
  182.                                           <TR><TD>
  183.                                             <TABLE BORDER=0 CELLSPACING=5 CELLPADDING=0><TR><TD>
  184.                                                Please review the following terms and state your agreement below.
  185.                                             </TD></TR>
  186.                                             <TR><TD>
  187.                                               <B>'.htmlspecialchars($config['server']['serverName']).' Rules</B><BR>
  188.                                               <TEXTAREA ROWS="16" WRAP="physical" COLS="75" READONLY="true">';
  189.         //load server rules from file
  190.         include("pages/tibiarules.php");
  191.         $main_content .= '</TEXTAREA>
  192.                                             </TD></TR></TABLE>
  193.                                           </TD></TR>
  194.                                           <TR><TD>
  195.                                             <TABLE BORDER=0 CELLSPACING=5 CELLPADDING=0>
  196.                                             <TR><TD>
  197.                                               <INPUT TYPE="checkbox" NAME="rules" id="rules" value="true" /><label for="rules"><u> I agree to the '.htmlspecialchars($config['server']['serverName']).' Rules.</u></lable><BR>
  198.                                             </TD></TR>
  199.                                             <TR><TD>
  200.                                               If you fully agree to these terms, click on the "I Agree" button in order to create an '.htmlspecialchars($config['server']['serverName']).' account.<BR>
  201.                                               If you do not agree to these terms or do not want to create an '.htmlspecialchars($config['server']['serverName']).' account, please click on the "Cancel" button.
  202.                                             </TD></TR></TABLE>
  203.                                           </TD></TR>
  204.                                         </TABLE></TD></TR>
  205.                                         </TABLE>
  206.                                         <BR>
  207.                                         <TABLE BORDER=0 WIDTH=100%>
  208.                                           <TR><TD ALIGN=center>
  209.                                             <IMG SRC="'.$layout_name.'/images/blank.gif" WIDTH=120 HEIGHT=1 BORDER=0><BR>
  210.                                           </TD><TD ALIGN=center VALIGN=top>
  211.                                             <INPUT TYPE=image NAME="I Agree" SRC="'.$layout_name.'/images/buttons/sbutton_iagree.gif" BORDER=0 WIDTH=120 HEIGHT=18>
  212.                                             </FORM>
  213.                                           </TD><TD ALIGN=center>
  214.                                             <FORM  ACTION="?subtopic=latestnews" METHOD=post>
  215.                                             <INPUT TYPE=image NAME="Cancel" SRC="'.$layout_name.'/images/buttons/sbutton_cancel.gif" BORDER=0 WIDTH=120 HEIGHT=18>
  216.                                             </FORM>
  217.                                           </TD><TD ALIGN=center>
  218.                                             <IMG SRC="/images/blank.gif" WIDTH=120 HEIGHT=1 BORDER=0><BR>
  219.                                           </TD></TR>
  220.                                         </TABLE>
  221.                                         </TD>
  222.                                         <TD><IMG SRC="'.$layout_name.'/images/blank.gif" WIDTH=10 HEIGHT=1 BORDER=0></TD>
  223.                                         </TR>
  224.                                         </TABLE>';
  225. }
  226. //CREATE ACCOUNT PAGE (save account in database)
  227. if($action == "saveaccount")
  228. {
  229.         $reg_name = strtoupper(trim($_POST['reg_name']));
  230.         $reg_email = trim($_POST['reg_email']);
  231.         $reg_password = trim($_POST['reg_password']);
  232.         $reg_code = trim($_POST['reg_code']);
  233.         //FIRST check
  234.         //check e-mail
  235.         if(empty($reg_name))
  236.                 $reg_form_errors[] = "Please enter account name.";
  237.         elseif(!check_account_name($reg_name))
  238.                 $reg_form_errors[] = "Invalid account name format. Use only A-Z and numbers 0-9.";
  239.         if(empty($reg_email))
  240.                 $reg_form_errors[] = "Please enter your email address.";
  241.         else
  242.         {
  243.                 if(!check_mail($reg_email))
  244.                         $reg_form_errors[] = "E-mail address is not correct.";
  245.         }
  246.         if($config['site']['verify_code'])
  247.         {
  248.                 //check verification code
  249.                 $string = strtoupper($_SESSION['string']);
  250.                 $userstring = strtoupper($reg_code);
  251.                 session_destroy();
  252.                 if(empty($string))
  253.                         $reg_form_errors[] = "Information about verification code in session is empty.";
  254.                 else
  255.                 {
  256.                         if(empty($userstring))
  257.                                 $reg_form_errors[] = "Please enter verification code.";
  258.                         else
  259.                         {
  260.                                 if($string != $userstring)
  261.                                         $reg_form_errors[] = "Verification code is incorrect.";
  262.                         }
  263.                 }
  264.         }
  265.         //check password
  266.         if(empty($reg_password) && !$config['site']['create_account_verify_mail'])
  267.                 $reg_form_errors[] = "Please enter password to your new account.";
  268.         elseif(!$config['site']['create_account_verify_mail'])
  269.         {
  270.                 if(!check_password($reg_password))
  271.                         $reg_form_errors[] = "Password contains illegal chars (a-z, A-Z and 0-9 only!) or lenght.";
  272.         }
  273.         //SECOND check
  274.         //check e-mail address in database
  275.         if(empty($reg_form_errors))
  276.         {
  277.                 if($config['site']['one_email'])
  278.                 {
  279.                         $test_email_account = new Account();
  280.                         //load account with this e-mail
  281.                         $test_email_account->findByEmail($reg_email);
  282.                         if($test_email_account->isLoaded())
  283.                                 $reg_form_errors[] = "Account with this e-mail address already exist in database.";
  284.                 }
  285.                 $account_db = new Account();
  286.                 $account_db->find($reg_name);
  287.                 if($account_db->isLoaded())
  288.                         $reg_form_errors[] = 'Account with this name already exist.';
  289.         }
  290.         // ----------creates account-------------(save in database)
  291.         if(empty($reg_form_errors))
  292.         {
  293.                 //create object 'account' and generate new acc. number
  294.                 if($config['site']['create_account_verify_mail'])
  295.                 {
  296.                         $reg_password = '';
  297.                         for ($i = 1; $i <= 6; $i++)
  298.                                 $reg_password .= mt_rand(0,9);
  299.                 }
  300.                 $reg_account = new Account();
  301.                 // saves account information in database
  302.                 $reg_account->setName($reg_name);
  303.                 $reg_account->setPassword($reg_password);
  304.                 $reg_account->setEMail($reg_email);
  305.                 $reg_account->setGroupID(1);
  306.                 $reg_account->setCreateDate(time());
  307.                 $reg_account->setCreateIP(Visitor::getIP());
  308.                 $reg_account->setFlag(Website::getCountryCode(long2ip(Visitor::getIP())));
  309.                 if(isset($config['site']['newaccount_premdays']) && $config['site']['newaccount_premdays'] > 0)
  310.                 {
  311.                         $reg_account->set("premdays", $config['site']['newaccount_premdays']);
  312.                         $reg_account->set("lastday", time());
  313.                 }
  314.                 $reg_account->save();
  315.                 //show information about registration
  316.                 if($config['site']['send_emails'] && $config['site']['create_account_verify_mail'])
  317.                 {
  318.                         $mailBody = '<html>
  319.                         <body>
  320.                         <h3>Your account name and password!</h3>
  321.                         <p>You or someone else registred on server <a href="'.$config['server']['url'].'"><b>'.htmlspecialchars($config['server']['serverName']).'</b></a> with this e-mail.</p>
  322.                         <p>Account name: <b>'.htmlspecialchars($reg_name).'</b></p>
  323.                         <p>Password: <b>'.htmlspecialchars(trim($reg_password)).'</b></p>
  324.                         <br />
  325.                         <p>After login you can:</p>
  326.                         <li>Create new characters
  327.                         <li>Change your current password
  328.                         <li>Change your current e-mail
  329.                         </body>
  330.                         </html>';
  331.                         $mail = new PHPMailer();
  332.                         if ($config['site']['smtp_enabled'])
  333.                         {
  334.                                 $mail->IsSMTP();
  335.                                 $mail->Host = $config['site']['smtp_host'];
  336.                                 $mail->Port = (int)$config['site']['smtp_port'];
  337.                                 $mail->SMTPAuth = $config['site']['smtp_auth'];
  338.                                 $mail->Username = $config['site']['smtp_user'];
  339.                                 $mail->Password = $config['site']['smtp_pass'];
  340.                         }
  341.                         else
  342.                                 $mail->IsMail();
  343.                         $mail->IsHTML(true);
  344.                         $mail->From = $config['site']['mail_address'];
  345.                         $mail->AddAddress($reg_email);
  346.                         $mail->Subject = $config['server']['serverName']." - Registration";
  347.                         $mail->Body = $mailBody;
  348.                         if($mail->Send())
  349.                         {
  350.                                 $main_content .= 'Your account has been created. Check your e-mail. See you in Tibia!<BR><BR>';
  351.                                 $main_content .= '<TABLE WIDTH=100% BORDER=0 CELLSPACING=1 CELLPADDING=4>
  352.                                 <TR><TD BGCOLOR="'.$config['site']['vdarkborder'].'" CLASS=white><B>Account Created</B></TD></TR>
  353.                                 <TR><TD BGCOLOR="'.$config['site']['darkborder'].'">
  354.                                   <TABLE BORDER=0 CELLPADDING=1><TR><TD>
  355.                                     <BR>Your account name is <b>'.$reg_name.'</b>.
  356.                                         <BR><b><i>You will receive e-mail (<b>'.htmlspecialchars($reg_email).'</b>) with your password.</b></i><br>';
  357.                                 $main_content .= 'You will need the account name and your password to play on '.htmlspecialchars($config['server']['serverName']).'.
  358.                                     Please keep your account name and password in a safe place and
  359.                                     never give your account name or password to anybody.<BR><BR>';
  360.                                 $main_content .= '<br /><small>These informations were send on email address <b>'.htmlspecialchars($reg_email).'</b>. Please check your inbox/spam folder.';
  361.                         }
  362.                         else
  363.                         {
  364.                                 $main_content .= '<br /><small>An error occorred while sending email! Account not created. Try again.</small>';
  365.                                 $reg_account->delete();
  366.                         }
  367.                 }
  368.                 else
  369.                 {
  370.                         $main_content .= 'Your account has been created. Now you can login and create your first character. See you in Tibia!<BR><BR>';
  371.                         $main_content .= '<TABLE WIDTH=100% BORDER=0 CELLSPACING=1 CELLPADDING=4>
  372.                         <TR><TD BGCOLOR="'.$config['site']['vdarkborder'].'" CLASS=white><B>Account Created</B></TD></TR>
  373.                         <TR><TD BGCOLOR="'.$config['site']['darkborder'].'">
  374.                           <TABLE BORDER=0 CELLPADDING=1><TR><TD>
  375.                             <BR>Your account name is <b>'.htmlspecialchars($reg_name).'</b><br>You will need the account name and your password to play on '.htmlspecialchars($config['server']['serverName']).'.
  376.                             Please keep your account name and password in a safe place and
  377.                             never give your account name or password to anybody.<BR><BR>';
  378.                         if($config['site']['send_emails'] && $config['site']['send_register_email'])
  379.                         {
  380.                                 $mailBody = '<html>
  381.                                 <body>
  382.                                 <h3>Your account name and password!</h3>
  383.                                 <p>You or someone else registred on server <a href="'.$config['server']['url'].'"><b>'.htmlspecialchars($config['server']['serverName']).'</b></a> with this e-mail.</p>
  384.                                 <p>Account name: <b>'.htmlspecialchars($reg_name).'</b></p>
  385.                                 <p>Password: <b>'.htmlspecialchars(trim($reg_password)).'</b></p>
  386.                                 <br />
  387.                                 <p>After login you can:</p>
  388.                                 <li>Create new characters
  389.                                 <li>Change your current password
  390.                                 <li>Change your current e-mail
  391.                                 </body>
  392.                                 </html>';
  393.                                 $mail = new PHPMailer();
  394.                                 if ($config['site']['smtp_enabled'])
  395.                                 {
  396.                                         $mail->IsSMTP();
  397.                                         $mail->Host = $config['site']['smtp_host'];
  398.                                         $mail->Port = (int)$config['site']['smtp_port'];
  399.                                         $mail->SMTPAuth = $config['site']['smtp_auth'];
  400.                                         $mail->Username = $config['site']['smtp_user'];
  401.                                         $mail->Password = $config['site']['smtp_pass'];
  402.                                 }
  403.                                 else
  404.                                         $mail->IsMail();
  405.                                 $mail->IsHTML(true);
  406.                                 $mail->From = $config['site']['mail_address'];
  407.                                 $mail->AddAddress($reg_email);
  408.                                 $mail->Subject = $config['server']['serverName']." - Registration";
  409.                                 $mail->Body = $mailBody;
  410.                                 if($mail->Send())
  411.                                         $main_content .= '<br /><small>These informations were send on email address <b>'.htmlspecialchars($reg_email).'</b>.';
  412.                                 else
  413.                                         $main_content .= '<br /><small>An error occorred while sending email (<b>'.htmlspecialchars($reg_email).'</b>)!</small>';
  414.                         }
  415.                 }
  416.                 $main_content .= '</TD></TR></TABLE></TD></TR></TABLE><BR><BR>';
  417.         }
  418.         else
  419.         {
  420.                 //SHOW ERRORs if data from form is wrong
  421.                 $main_content .= '<div class="SmallBox" >  <div class="MessageContainer" >    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="ErrorMessage" >      <div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/attentionsign.gif);" /></div><b>The Following Errors Have Occurred:</b><br/>';
  422.                 foreach($reg_form_errors as $show_msg)
  423.                 {
  424.                                         $main_content .= '<li>'.$show_msg.'</li>';
  425.                 }
  426.                 $main_content .= '</div>    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>  </div></div><br/>
  427.                 <BR>
  428.                 <CENTER>
  429.                 <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><FORM ACTION=?subtopic=createaccount METHOD=post><TR><TD>
  430.                 <INPUT TYPE=hidden NAME=email VALUE="">
  431.  
  432.                 <INPUT TYPE=image NAME="Back" ALT="Back" SRC="'.$layout_name.'/images/buttons/sbutton_back.gif" BORDER=0 WIDTH=120 HEIGHT=18>
  433.                 </TD></TR></FORM></TABLE>
  434.                 </CENTER>';
  435.         }
  436. }