Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once 'database.php';
- require_once 'mail.php';
- class Students_user{
- private $ID;
- private $Name;
- private $Surname;
- private $City;
- private $Country;
- private $Date_of_birth;
- private $Email;
- private $Username;
- private $Password;
- private $Eestec;
- private $Photo;
- private $Status;
- private $date_of_creation;
- private $CV;
- private $Last_login;
- public function __construct()
- {
- }
- private function valid_email($email){
- if (preg_match("#^[]{1,64}[^]{1,255}$#", $email))
- {
- return false;
- }
- // Split it into sections to make life easier
- $email_array = explode("@", $email);
- $local_array = explode(".", $email_array[0]);
- for ($i = 0; $i < sizeof($local_array); $i++){
- if (!preg_match("#^(([A-Za-z0-9!$%&038;'*+/=?^{|}~-][A-Za-z0-9!$%&038;'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))#",$local_array[$i]))
- {
- return false;
- }
- }
- if (!preg_match("#^\[?[0-9\.]+\]?$#", $email_array[1])){
- // Check if domain is IP. If not, it should be valid domain name
- $domain_array = explode(".", $email_array[1]);
- if (sizeof($domain_array) < 2)
- {
- return false; // Not enough parts to domain
- }
- for ($i = 0; $i < sizeof($domain_array); $i++){
- if (!preg_match("#^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$#", $domain_array[$i]))
- {
- return false;
- }
- }
- }
- return true;
- }
- private function valid_username($username, $minlength = 3, $maxlength = 30){
- $username = trim($username);
- if (empty($username)){
- return false; // it was empty
- }
- if (strlen($username) > $maxlength){
- return false; // to long
- }
- if (strlen($username) < $minlength){
- return false; //toshort
- }
- preg_match("#^[A-Za-z0-9_\-]+$#", $username,$result); //only A-Z, a-z and 0-9 are allowed
- if ($result){
- return true; // ok no invalid chars
- } else {
- return false; //invalid chars found
- }
- return false;
- }
- private function valid_password($pass, $minlength = 6, $maxlength = 15){
- $pass = trim($pass);
- if (empty($pass)){
- return false;
- }
- if (strlen($pass) < $minlength){
- return false;
- }
- if (strlen($pass) > $maxlength){
- return false;
- }
- preg_match("#^[A-Za-z0-9_\-]+$#", $pass,$result);
- if ($result){
- return true;
- } else {
- return false;
- }
- return false;
- }
- private function user_exist($username){
- $db= new database();
- $sql="SELECT ID FROM `users` WHERE Username='".$username."'";
- list($result,$a)=$db->query($sql);
- $c1=0;$c2=0;$c3=0;
- if($result && mysql_num_rows($result)>0) $c1=1;
- $sql="SELECT ID FROM `companys` WHERE Username='".$username."'";
- list($result,$a)=$db->query($sql);
- if($result && mysql_num_rows($result)>0) $c2=1;
- $sql="SELECT ID FROM `universitys` WHERE Username='".$username."'";
- list($result,$a)=$db->query($sql);
- if($result && mysql_num_rows($result)>0) $c2=1;
- if($c1 || $c2 || $c3) return false;
- return true;
- }
- public function save_to_database(){
- $db= new database();
- $i=0;
- if($this->user_exist($this->Username)==false)
- {
- $i++;
- echo '
- <script type="text/javascript">
- function errorhide(){
- $("#error_message").hide();
- }
- </script>
- <div id="error_message"><br/><br/>Username exists<br/><br/><a href="#" onclick="errorhide()">Close</a><br/></div>';
- }
- else if($this->valid_password($this->Password)==false && ($this->Password==$_POST['users_Password1'])==false && $i==0)
- {
- $i++;
- echo '
- <script type="text/javascript">
- function errorhide(){
- $("#error_message").hide();
- }
- </script>
- <div id="error_message"><br/><br/>Invalid password<br/><br/><a href="#" onclick="errorhide()">Close</a><br/></div>';
- }
- else if($this->valid_username($this->Username)==false && $i==0)
- {
- $i++;
- echo '
- <script type="text/javascript">
- function errorhide(){
- $("#error_message").hide();
- }
- </script>
- <div id="error_message"><br/><br/>Invalid username<br/><br/><a href="#" onclick="errorhide()">Close</a><br/></div>';
- }
- else if($this->valid_email($this->Email)==false && $i==0)
- {
- $i++;
- echo '
- <script type="text/javascript">
- function errorhide(){
- $("#error_message").hide();
- }
- </script>
- <div id="error_message"><br/><br/>Invalid mail address<br/><br/><a href="#" onclick="errorhide()">Close</a><br/></div>';
- }
- else{
- if($i==0)
- {
- $sql="INSERT INTO `students` (Name, Surname, Country, City,Email) VALUES
- ('".htmlentities($this->Name)."','".htmlentities($this->Surname)."','".htmlentities($this->Country)."','".htmlentities($this->City)."','".@$this->Email."')";
- list($ba,$a)=$db->query($sql);
- $this->CV=$a;
- $sql="INSERT INTO `users` VALUES
- (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())";
- list($ba,$last_id)=$db->query($sql);
- $slq1="INSERT INTO `mm_messages_conv_users` VALUES(NULL,'".$last_id."','".htmlentities($this->Username)."','-1','student')";
- list($a,$a)=$db->query($slq1);
- $subject="Welcome to Lykeion";
- $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
- By becoming a user of Lykeion website you have chance to:\n
- -enter your CV in unique database, which is viewed by companies AND universities from whole world
- -apply for internships and jobs in high-tech companies
- -apply for Bachelor, Master and PhD studies on technical universities worldwide
- -establish direct communication channel with most recognizable and perspective universities, companies and experts worldwide
- -follow up the latest news and notifications of your future employer\n
- Be the master of your opportunities!\n\n
- Lykeion website team";
- $m=new mail();
- $m->SendMail($last_id, "users", $subject, $message);
- header("Location: index.php?to=registered");
- } else {
- echo '
- <script type="text/javascript">
- function errorhide(){
- $("#error_message").hide();
- }
- </script>
- <div id="error_message"><br/><br/>There was an error with entered data.<br/><br/><a href="#" onclick="errorhide()">Close</a><br/></div>';
- };
- }
- }
- public function update_to_database(){
- $db= new database();
- $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."' )";
- list($a,$this->id)=$db->query($sql);
- }
- public function load_from_database($id){
- $db= new database();
- $sql="SELECT * FROM students WHERE ID='".$id."'";
- list($result,$a)=$db->query($sql);
- if($result && mysql_num_rows($result)>0)
- while ($podaci = mysql_fetch_array($result))
- {
- $this->ID=$podaci['ID'];
- $this->Name=$podaci['Name'];
- $this->Surname=$podaci['Surname'];
- $this->City=$podaci['City'];
- $this->Country=$podaci['Country'];
- $this->Date_of_birth=$podaci['Date_of_birth'];
- $this->Email=$podaci['Email'];
- $this->Username=$podaci['Username'];
- $this->Password=$podaci['Password'];
- $this->Eestec=$podaci['Eestec'];
- $this->Photo=$podaci['Photo'];
- $this->Status=$podaci['Status'];
- $this->date_of_creation=$podaci['date_of_creation'];
- $this->CV=$podaci['CV'];
- $this->Last_login=$podaci['Last_login'];
- }
- }
- public function load_from_post(){
- $this->ID=$_POST['users_ID'];
- $this->Name=addslashes($_POST['users_Name']);
- $this->Surname=addslashes($_POST['users_Surname']);
- $this->City=addslashes($_POST['users_City']);
- $this->Country=addslashes($_POST['users_Country']);
- $this->Date_of_birth=@$_POST['users_Date_of_birth'];
- $this->Email=addslashes($_POST['users_Email']);
- $this->Username=addslashes($_POST['users_Username']);
- $this->Password=$_POST['users_Password'];
- $this->Password1=$_POST['users_Password1'];
- $this->Eestec=@$_POST['users_Eestec'];
- $this->Photo=@$_POST['users_Photo'];
- $this->Status=@$_POST['users_Status'];
- $this->date_of_creation=@$_POST['users_date_of_creation'];
- $this->CV=@$_POST['users_CV'];
- $this->Last_login=@$_POST['users_Last_login'];
- }
- public function show_register_form(){
- echo '<form action="index.php" method="post" enctype="multipart/form-data" name="studentform" id="studentform">
- <table width="100%" height="22" border="0" cellpadding="5" cellspacing="0">
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- </table>
- <div align="center"><input type="submit" name="student_register" class="lykeion_textbox" id="student_register" value="Register" /></div>
- </form>';
- }
- }
- if(isset($_POST['student_register'])) {
- $add_student= new Students_user();
- $add_student->load_from_post();
- $add_student->save_to_database();
- }
- ?>
Add Comment
Please, Sign In to add comment