Guest User

Untitled

a guest
Oct 17th, 2017
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 12.56 KB | None | 0 0
  1. <?php
  2. require_once 'database.php';
  3. require_once 'mail.php';
  4. class Students_user{
  5.     private $ID;
  6.     private $Name;
  7.     private $Surname;
  8.     private $City;
  9.     private $Country;
  10.     private $Date_of_birth;
  11.     private $Email;
  12.     private $Username;
  13.     private $Password;
  14.     private $Eestec;
  15.     private $Photo;
  16.     private $Status;
  17.     private $date_of_creation;
  18.     private $CV;
  19.     private $Last_login;
  20.    
  21.     public function __construct()
  22.     {
  23.        
  24.        
  25.     }
  26.        
  27.     private function valid_email($email){
  28.         if (preg_match("#^[]{1,64}[^]{1,255}$#", $email))
  29.         {
  30.                        return false;
  31.         }
  32.         // Split it into sections to make life easier
  33.         $email_array = explode("@", $email);
  34.         $local_array = explode(".", $email_array[0]);
  35.         for ($i = 0; $i < sizeof($local_array); $i++){
  36.             if (!preg_match("#^(([A-Za-z0-9!$%&038;'*+/=?^{|}~-][A-Za-z0-9!$%&038;'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))#",$local_array[$i]))
  37.             {
  38.                             return false;
  39.             }
  40.         }
  41.         if (!preg_match("#^\[?[0-9\.]+\]?$#", $email_array[1])){
  42.         // Check if domain is IP. If not, it should be valid domain name
  43.             $domain_array = explode(".", $email_array[1]);
  44.             if (sizeof($domain_array) < 2)
  45.             {
  46.                             return false; // Not enough parts to domain
  47.             }
  48.             for ($i = 0; $i < sizeof($domain_array); $i++){
  49.                 if (!preg_match("#^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$#", $domain_array[$i]))
  50.                 {
  51.                             return false;
  52.                 }
  53.             }
  54.         }
  55.         return true;
  56.     }
  57.  
  58.     private function valid_username($username, $minlength = 3, $maxlength = 30){
  59.         $username = trim($username);
  60.         if (empty($username)){
  61.             return false; // it was empty
  62.         }
  63.         if (strlen($username) > $maxlength){
  64.             return false; // to long
  65.         }
  66.         if (strlen($username) < $minlength){
  67.             return false; //toshort
  68.         }
  69.      
  70.         preg_match("#^[A-Za-z0-9_\-]+$#", $username,$result); //only A-Z, a-z and 0-9 are allowed
  71.      
  72.         if ($result){
  73.             return true; // ok no invalid chars
  74.         } else {
  75.             return false; //invalid chars found
  76.         }
  77.         return false;
  78.     }
  79.  
  80.     private function valid_password($pass, $minlength = 6, $maxlength = 15){
  81.         $pass = trim($pass);
  82.         if (empty($pass)){
  83.             return false;
  84.         }
  85.         if (strlen($pass) < $minlength){
  86.             return false;
  87.         }
  88.         if (strlen($pass) > $maxlength){
  89.             return false;
  90.         }
  91.         preg_match("#^[A-Za-z0-9_\-]+$#", $pass,$result);
  92.         if ($result){
  93.             return true;
  94.         } else {
  95.             return false;
  96.         }
  97.         return false;
  98.     }
  99.    
  100.     private function user_exist($username){
  101.         $db= new database();
  102.         $sql="SELECT ID FROM `users` WHERE Username='".$username."'";  
  103.         list($result,$a)=$db->query($sql);
  104.         $c1=0;$c2=0;$c3=0;
  105.         if($result && mysql_num_rows($result)>0) $c1=1;
  106.         $sql="SELECT ID FROM `companys` WHERE Username='".$username."'";   
  107.         list($result,$a)=$db->query($sql);
  108.         if($result && mysql_num_rows($result)>0) $c2=1;
  109.         $sql="SELECT ID FROM `universitys` WHERE Username='".$username."'";
  110.         list($result,$a)=$db->query($sql);
  111.         if($result && mysql_num_rows($result)>0) $c2=1;
  112.        
  113.         if($c1 || $c2 || $c3) return false;
  114.         return true;
  115.     }
  116.    
  117.     public function save_to_database(){
  118.         $db= new database();
  119.         $i=0;
  120.         if($this->user_exist($this->Username)==false)
  121.         {
  122.             $i++;
  123.             echo '
  124.                 <script type="text/javascript">
  125.                     function errorhide(){
  126.                         $("#error_message").hide();
  127.                     }
  128.                 </script>
  129.                 <div id="error_message"><br/><br/>Username exists<br/><br/><a href="#" onclick="errorhide()">Close</a><br/></div>';
  130.         }
  131.         else if($this->valid_password($this->Password)==false && ($this->Password==$_POST['users_Password1'])==false && $i==0)
  132.         {
  133.             $i++;
  134.             echo '
  135.                 <script type="text/javascript">
  136.                     function errorhide(){
  137.                         $("#error_message").hide();
  138.                     }
  139.                 </script>
  140.                 <div id="error_message"><br/><br/>Invalid password<br/><br/><a href="#" onclick="errorhide()">Close</a><br/></div>';
  141.         }
  142.         else if($this->valid_username($this->Username)==false && $i==0)
  143.         {
  144.             $i++;
  145.             echo '
  146.                 <script type="text/javascript">
  147.                     function errorhide(){
  148.                         $("#error_message").hide();
  149.                     }
  150.                 </script>
  151.                 <div id="error_message"><br/><br/>Invalid username<br/><br/><a href="#" onclick="errorhide()">Close</a><br/></div>';
  152.         }
  153.         else if($this->valid_email($this->Email)==false && $i==0)
  154.         {
  155.             $i++;
  156.             echo '
  157.                 <script type="text/javascript">
  158.                     function errorhide(){
  159.                         $("#error_message").hide();
  160.                     }
  161.                 </script>
  162.                 <div id="error_message"><br/><br/>Invalid mail address<br/><br/><a href="#" onclick="errorhide()">Close</a><br/></div>';
  163.         }
  164.                 else{
  165.                     if($i==0)
  166.                     {
  167.                             $sql="INSERT INTO `students` (Name, Surname, Country, City,Email) VALUES
  168.                                    ('".htmlentities($this->Name)."','".htmlentities($this->Surname)."','".htmlentities($this->Country)."','".htmlentities($this->City)."','".@$this->Email."')";
  169.                             list($ba,$a)=$db->query($sql);
  170.                             $this->CV=$a;
  171.                              
  172.                             $sql="INSERT INTO `users` VALUES
  173.                                     (NULL,'".htmlentities($this->Name)."','".htmlentities($this->Surname)."','".htmlentities($this->City)."','".htmlentities($this->Country)."','".$this->Date_of_birth."','".$this->Email."','".htmlentities($this->Username)."',MD5('".$this->Password."'),'".$this->Eestec."','img/thumbs/avatar.jpg','Pending',NOW(),'".$this->CV."',NOW())";
  174.                             list($ba,$last_id)=$db->query($sql);
  175.                             $slq1="INSERT INTO `mm_messages_conv_users` VALUES(NULL,'".$last_id."','".htmlentities($this->Username)."','-1','student')";
  176.                             list($a,$a)=$db->query($slq1);
  177.                             $subject="Welcome to Lykeion";
  178.                             $message="Dear ".$this->Name." ".$this->Surname.",\n\nThank you for registering on Lykeion website. We honestly hope that this website will fulfill your expectations. You will recieve a mail when Administrator activates your account\n\n
  179. By becoming a user of Lykeion website you have chance to:\n
  180.     -enter your CV in unique database, which is viewed by companies AND universities from whole world
  181.     -apply for internships and jobs in high-tech companies
  182.     -apply for Bachelor, Master and PhD studies on technical universities worldwide
  183.     -establish direct communication channel with most recognizable and perspective universities, companies and experts worldwide
  184.     -follow up the latest news and notifications of your future employer\n
  185. Be the master of your opportunities!\n\n
  186. Lykeion website team";
  187.                             $m=new mail();
  188.                             $m->SendMail($last_id, "users", $subject, $message);
  189.                             header("Location: index.php?to=registered");
  190.                     } else {
  191.                             echo '
  192.                                    <script type="text/javascript">
  193.                                            function errorhide(){
  194.                                                    $("#error_message").hide();
  195.                                            }
  196.                                    </script>
  197.                                    <div id="error_message"><br/><br/>There was an error with entered data.<br/><br/><a href="#" onclick="errorhide()">Close</a><br/></div>';
  198.                     };
  199.                 }
  200.        
  201.     }
  202.    
  203.     public function update_to_database(){
  204.         $db= new database();
  205.         $sql="UPDATE `users` SET , Name='".$this->Name."', Surname='".$this->Surname."', City='".$this->City."', Country='".$this->Country."', Date_of_birth='".$this->Date_of_birth."', Email='".$this->Email."', Username='".$this->Username."', Password='".$this->Password."', Eestec='".$this->Eestec."', Photo='".$this->Photo."', Status='".$this->Status."' )";
  206.         list($a,$this->id)=$db->query($sql);
  207.     }
  208.    
  209.     public function load_from_database($id){
  210.         $db= new database();
  211.         $sql="SELECT * FROM students WHERE ID='".$id."'";
  212.         list($result,$a)=$db->query($sql);
  213.         if($result && mysql_num_rows($result)>0)
  214.         while ($podaci = mysql_fetch_array($result))
  215.         {
  216.             $this->ID=$podaci['ID'];
  217.             $this->Name=$podaci['Name'];
  218.             $this->Surname=$podaci['Surname'];
  219.             $this->City=$podaci['City'];
  220.             $this->Country=$podaci['Country'];
  221.             $this->Date_of_birth=$podaci['Date_of_birth'];
  222.             $this->Email=$podaci['Email'];
  223.             $this->Username=$podaci['Username'];
  224.             $this->Password=$podaci['Password'];
  225.             $this->Eestec=$podaci['Eestec'];
  226.             $this->Photo=$podaci['Photo'];
  227.             $this->Status=$podaci['Status'];
  228.             $this->date_of_creation=$podaci['date_of_creation'];
  229.             $this->CV=$podaci['CV'];
  230.             $this->Last_login=$podaci['Last_login'];
  231.         }
  232.     }
  233.    
  234.     public function load_from_post(){
  235.             $this->ID=$_POST['users_ID'];
  236.             $this->Name=addslashes($_POST['users_Name']);
  237.             $this->Surname=addslashes($_POST['users_Surname']);
  238.             $this->City=addslashes($_POST['users_City']);
  239.             $this->Country=addslashes($_POST['users_Country']);
  240.             $this->Date_of_birth=@$_POST['users_Date_of_birth'];
  241.             $this->Email=addslashes($_POST['users_Email']);
  242.             $this->Username=addslashes($_POST['users_Username']);
  243.             $this->Password=$_POST['users_Password'];
  244.             $this->Password1=$_POST['users_Password1'];
  245.             $this->Eestec=@$_POST['users_Eestec'];
  246.             $this->Photo=@$_POST['users_Photo'];
  247.             $this->Status=@$_POST['users_Status'];
  248.             $this->date_of_creation=@$_POST['users_date_of_creation'];
  249.             $this->CV=@$_POST['users_CV'];
  250.             $this->Last_login=@$_POST['users_Last_login'];
  251.     }
  252.  
  253.     public function show_register_form(){
  254.         echo '<form action="index.php" method="post" enctype="multipart/form-data" name="studentform" id="studentform">
  255.              <table width="100%" height="22" border="0" cellpadding="5" cellspacing="0">
  256.              <tr> <td width="9%" valign="top">Name</td><td width="91%"><label> <input name="users_Name" class="lykeion_textbox" type="text" id="users_Name" size="75" maxlength="99" style="width:98%" value="'.$this->Name.'"/> <input name="users_ID" class="lykeion_textbox" type="hidden" id="users_ID" size="75" maxlength="30" style="width:98%" value="'.$this->ID.'"/></label></td>  </tr>
  257.              <tr> <td width="9%" valign="top">Surname</td><td width="91%"><label> <input name="users_Surname" class="lykeion_textbox" type="text" id="users_Surname" size="75" maxlength="99" style="width:98%" value="'.$this->Surname.'"/> </label></td>  </tr>
  258.              <tr> <td width="9%" valign="top">City</td><td width="91%"><label> <input name="users_City" class="lykeion_textbox" type="text" id="users_City" size="75" maxlength="79" style="width:98%" value="'.$this->City.'"/> </label></td>  </tr>
  259.              <tr> <td width="9%" valign="top">Country</td><td width="91%"><label> <input name="users_Country" class="lykeion_textbox" type="text" id="users_Country" size="75" maxlength="79" style="width:98%" value="'.$this->Country.'"/> </label></td>  </tr>
  260.              <tr> <td width="9%" valign="top">Email</td><td width="91%"><label> <input name="users_Email" class="lykeion_textbox" type="text" id="users_Email" size="75" maxlength="199" style="width:98%" value="'.$this->Email.'"/> </label></td>  </tr>
  261.              <tr> <td width="9%" valign="top">Username</td><td width="91%"><label> <input name="users_Username" class="lykeion_textbox" type="text" id="users_Username" size="75" maxlength="49" style="width:98%" value="'.$this->Username.'"/> </label></td>  </tr>
  262.              <tr> <td width="9%" valign="top">Password</td><td width="91%"><label> <input name="users_Password" class="lykeion_textbox" type="password" id="users_Password" size="75" maxlength="59" style="width:98%" value="'.$this->Password.'"/> </label></td>  </tr>
  263.              <tr> <td width="9%" valign="top">Password(repeat)</td><td width="91%"><label> <input name="users_Password1" class="lykeion_textbox" type="password" id="users_Password1" size="75" maxlength="59" style="width:98%" value="'.$this->Password.'"/> </label></td>  </tr>
  264.              <tr> <td width="9%" valign="top">Eestec</td><td width="91%"><label> <input name="users_Eestec" class="lykeion_textbox" type="checkbox" id="users_Eestec" size="75" maxlength="30" style="width:98%" value="1" checked="'.$this->Eestec.'"/> </label></td>  </tr>
  265.              </table>
  266.              <div align="center"><input type="submit" name="student_register" class="lykeion_textbox" id="student_register" value="Register" /></div>
  267.              </form>';
  268.     }
  269.    
  270. }
  271.  
  272.     if(isset($_POST['student_register'])) {
  273.         $add_student= new Students_user();
  274.         $add_student->load_from_post();
  275.         $add_student->save_to_database();
  276.     }
  277.  
  278.  
  279. ?>
Add Comment
Please, Sign In to add comment