<?php 
error_reporting(E_ALL);
ini_set("display_errors", 1);
session_start();
require_once('dbconnection.php');



//Code for Registration 
if(isset($_POST['signup']))
{
	$dp_userName=$_POST['dp_userName'];
	$dp_userSurname=$_POST['dp_userSurname'];
	$dp_userEmail=$_POST['dp_userEmail'];
	$dp_userPassword=$_POST['dp_userPassword'];
	$dp_userPhone=$_POST['dp_userPhone'];
	$dp_userCompany=$_POST['dp_userCompany'];
	$enc_password=($dp_userPassword);
	$dp_user_date=date('Y-m-d H:i:s');
	$kayit_mail=$_POST['dp_userEmail'];
	$dp_userCurrent=rand(10000000,200);
	echo $dp_userCurrent;
	
	

	
	$kyt=mysqli_query($con,"Select * from dp_users where dp_userEmail='$kayit_mail'"); // E-mail kontrol
	if(mysqli_num_rows($kyt)) // e-mail veritabanı satır kontrol
	{
		echo "<script>alert('Bu mail adresi önceden kayıt yapılmıştır.!');</script>"; // hata nesajı
	}
	else // kullanıcı kaydı yoksa kayıt yönlendirme işlemi
	{
		$msg=mysqli_query($con,"insert into dp_users(dp_userName,dp_userSurname,dp_userEmail,dp_userCompany,dp_userPhone,dp_userPassword,dp_userDate,dp_userCurrent) 
		values('$dp_userName','$dp_userSurname','$dp_userEmail','$dp_userCompany','$dp_userPhone','$enc_password','$dp_user_date','$dp_userCurrent')"); // kullanıcı veritabanına ekleme

		if($msg)
		{
		echo "<script>alert('Kayıt Başarılı');</script>"; // başarılı mesajı
		}
	}
}
	
		
	if(isset($_POST['login']))
	{
	$password=$_POST['dp_userPassword'];
	$dec_password=$password;

		$ret=mysqli_query($con,"SELECT * FROM dp_users WHERE dp_userEmail='".$_POST['dp_userEmail']."' and dp_userPassword='$dec_password'");
		$num=mysqli_fetch_array($ret);
			if($num>0)
			{
			$extra="crmindex.php";
			$_SESSION['login']=$_POST['dp_userEmail'];
			$_SESSION['dp_userID']=$num['dp_userID'];
			$_SESSION['dp_userName']=$num['dp_userName'];
			$_SESSION['dp_userCurrent']=$num['dp_userCurrent'];
			$host=$_SERVER['HTTP_HOST'];
			$uri=rtrim(dirname($_SERVER['PHP_SELF']),'/\\');
			header("location:http://$host$uri/$extra");
			exit();
			}
			else
			{
			$_SESSION['action1']="Mail veya Şifre Geçersiz !";
			$extra="index.php";
			$host=$_SERVER['HTTP_HOST'];
			$uri=rtrim(dirname($_SERVER['PHP_SELF']),'/\\');
			header("location:http://$host$uri/$extra");
			exit();
			}
	}




//Code for Forgot Password

if(isset($_POST['send']))
{
$row1=mysqli_query($con,"select dp_userEmail,dp_userPassword from dp_users where dp_userEmail='".$_POST['dp_userEmail']."'");
$row2=mysql_fetch_array($row1);
if($row2>0)
{
$dp_user_mail = $row2['dp_userEmail'];
$subject = "Information about your password";
$password=$row2['dp_userPassword'];
$message = "Your password is ".$password;
mail($dp_user_mail, $subject, $message, "From: $dp_user_mail");
echo  "<script>alert('Your Password has been sent Successfully');</script>";
}
else
{
echo "<script>alert('Email not register with us');</script>";	
}
}

?>
<!DOCTYPE html>
<html>
<head>
<title>CRM</title>
<link href="css/style.css" rel='stylesheet' type='text/css' />
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="Elegent Tab Forms,Login Forms,Sign up Forms,Registration Forms,News latter Forms,Elements"./>
<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
</script>
<script src="js/jquery.min.js"></script>
<script src="js/easyResponsiveTabs.js" type="text/javascript"></script>
				<script type="text/javascript">
					$(document).ready(function () {
						$('#horizontalTab').easyResponsiveTabs({
							type: 'default',       
							width: 'auto', 
							fit: true 
						});
					});
				   </script>
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:200,400,600,700,200italic,300italic,400italic,600italic|Lora:400,700,400italic,700italic|Raleway:400,500,300,600,700,200,100' rel='stylesheet' type='text/css'>
</head>
<body>

<div class="main">
		
		<div class="logo"></div>
	 <div class="sap_tabs">	
			<div id="horizontalTab" style="display: block; width: 100%; margin: 0px;">
			  <ul class="resp-tabs-list">
			  	  <li class="resp-tab-item" aria-controls="tab_item-0" role="tab"><div class="top-img"><img src="images/top-note.png" alt=""/></div><span>Kayıt</span>
			  	  	
				</li>
				  <li class="resp-tab-item" aria-controls="tab_item-1" role="tab"><div class="top-img"><img src="images/top-lock.png" alt=""/></div><span>Giriş</span></li>
				  <li class="resp-tab-item lost" aria-controls="tab_item-2" role="tab"><div class="top-img"><img src="images/top-key.png" alt=""/></div><span>Şifre Yenile</span></li>
				  <div class="clear"></div>
			  </ul>		
			  	 
			<div class="resp-tabs-container" align="center">
					<div class="tab-1 resp-tab-content" aria-labelledby="tab_item-0">
					<div class="facts">
							<div class="register">
							<form name="registration" method="post" action="" enctype="multipart/form-data">
						<table width="300">
						<tr><td><p>Adı :</p></td><td><input type="text" class="text" value=""  name="dp_userName" required ></td></tr>
						<tr><td><p>Soyad :</p></td><td><input type="text" class="text" value="" name="dp_userSurname"  required ></td></tr>
						<tr><td><p>Mail : </p></td><td><input type="text" class="text" value="" name="dp_userEmail"></td></tr>
						<tr><td><p>Şifre :</p></td><td><input type="password" value="" name="dp_userPassword" required></td></tr>
		<tr><td><p>Telefon :</p></td><td><input type="text" class="text" value="" name="dp_userPhone" placeholder="(+90) - (___) - ___ - ____" maxlength="11" required ></td></tr>
						<tr><td><p>Firma :</p></td><td><input type="text" class="text" value="" name="dp_userCompany"  required ></td></tr>
						</table>
						<div class="sign-up">
									<input type="reset" value="TEMİZLE">
									<input type="submit" name="signup"  value="KAYIT" >
									<div class="clear"> </div>
								</div>
							</form>

						</div>
					</div>
				</div>		
			 <div class="tab-2 resp-tab-content" aria-labelledby="tab_item-1">
					 	<div class="facts">
							 <div class="login">
							<div class="buttons">
								
								
							</div>
							<form name="login" action="" method="post">
								<input type="text" class="text" name="dp_userEmail" value="" placeholder="Giriş için mail adresinizi giriniz. !"  ><a href="#" class=" icon email"></a>

								<input type="password" value="" name="dp_userPassword" placeholder="Şifrenizi giriniz. !"><a href="#" class=" icon lock"></a>

								<div class="p-container">
								
									<div class="submit two">
									<input type="submit" name="login" value="GİRİŞ" >
									</div>
									<div class="clear"> </div>
								</div>

							</form>
					</div>
				</div> 
			</div> 			        					 
				 <div class="tab-2 resp-tab-content" aria-labelledby="tab_item-1">
					 	<div class="facts">
							 <div class="login">
							<div class="buttons">
								
								
							</div>
							<form name="login" action="" method="post">
								<input type="text" class="text" name="dp_userEmail" value="" placeholder="Kayıtlı mail adresinizi giriniz. !" required  ><a href="#" class=" icon email"></a>
									
										<div class="submit three">
											<input type="submit" name="send" onClick="myFunction()" value="GÖNDER" >
										</div>
									</form>
									</div>
				         	</div>           	      
				        </div>	
				     </div>	
		        </div>
	        </div>
	     </div>

</body>
</html>