<?php


if($_GET["v"] != 4 ){
echo "<center>
	<h1>تحتاج إلى تحديث التطبيق</h1> 
	<input type=\"button\" onclick=\"location.href='https://play.google.com/store/apps/details?id=com.tooroq.qodorate';\" value=\"تحديث\" />
	</center>
";
return ;
}


    include '../../../admin/config.php';
    $conn = mysqli_connect($HostName, $HostUser, $HostPass, $DatabaseName);

	if (isset($_GET["email"])) {
		
		$email_check = $_GET["email"];
        $pass = $_GET["pass"];
		
		$query = "SELECT email FROM USERS WHERE email='$email_check' AND pass='$pass' ";
        $result = mysqli_query($conn,$query);
        if(!$row = mysqli_fetch_array($result)) {
		  	echo " ERROR email or password " ;
			return ;
         }
		 
	}
	
	if (!isset($_GET["email"])) {
		exit ;
	}
	
if (isset($_POST["email_address"])) {
	
		$title = $_POST["title"];
        $email = $_POST["email_address"];
		$subject = $_POST["subject"];
		$status = "true" ;
	    $date = date("Y-m-d") ;
		
		$respenst = false ;
		
	     $msg = "<hr>Date: $date" . "<br>".
		        "<b>Title: $title</b>" . "<br>".
				"$subject" ;

	    $query = "SELECT email FROM contact WHERE email='$email' ";
            $result = mysqli_query($conn,$query);
			
            if($row = mysqli_fetch_array($result)) {
		   	$respenst = true ;
              }
		
		
		if($respenst){
			$sql = "UPDATE contact SET title='$title' , email='$email' , msg=CONCAT(msg , '$msg') , status='$status' , date='$date' WHERE email='$email'"; 
            $conn->query($sql); 
			
			header( "Location: contact.php?email=$email_check&pass=$pass" );
		
		}else{
			$q="INSERT INTO contact (title , email , msg , status , date ) VALUES ( '$title' , '$email' , '$msg' , '$status' , '$date') " ;    
            mysqli_query($conn,$q) or die(mysqli_error($conn));
            mysqli_close($conn);
			
			
			header( "Location: contact.php?email=$email_check&pass=$pass" );
	    }

}


?>

<!DOCTYPE html>
<html>
<title><?php echo $title ; ?> Contact</title>	
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<center>
<form enctype="multipart/form-data" method="post" action="" accept-charset="UTF-8">

    <a href="my_oreders.php?email=<?php echo $email_check; ?>&pass=<?php echo $pass; ?>">طلبات السحب الخاصة بـك</a>
	<table cellspacing="5" cellpadding="5" border="0">

		<tr>
			<td valign="top">
			<strong></strong>
			</td>
		  <td valign="top"><br/>
		  <select name="title">
	      <option>استفسار</option> 
	      <option>ملاحظة</option>
		  <option>مشكل بالتطبيق</option> 
	      <option>الإعلان بالتطبيق</option>
		  <option>آخر</option>
	      </select>
	   	  </td>
		</tr>
		<tr>
			<td valign="top">
				<input type="hidden" name="email_address" value="<?php echo $email_check ; ?>" />
			</td>
		</tr>

	<tr>
			
   <td valign="top">
				<strong> الرسالة: </strong>
	</td>
   <td valign="top"><textarea cols="40" name="subject"  rows="6"></textarea>
    
   </td>
  </tr>
		<tr>
			<td colspan="2" align="center">
				<input type="submit" value=" إرسال " />
			</td>
		</tr>
	</table>	
	<br> suport : <?php echo $emailAdmin; ?>
</form>
</center>

<?php

  $query = "SELECT msg FROM contact WHERE email='$email_check' ";
  $result = mysqli_query($conn,$query);
  if($row = mysqli_fetch_array($result)) {
	  
	 $log_msg = $row['msg'] ;
				
   }
   
  echo " <div> <form>
	     <fieldset><legend>الرسائل : ستجد الرد هنا بالأسفل</legend>
					<h3></h3>
					<pre> $log_msg </pre>	
		 </fieldset>
		 </form> </div>" ;


?>

</html>
