<?php
	require("header.php");
	include("connect.php");
	// function zen_rand($min = null, $max = null) {

 //    static $seeded;

 //    if (!$seeded) {
 //      mt_srand((double)microtime()*1000000);
 //      $seeded = true;
 //    }

 //    if (isset($min) && isset($max)) {
 //      if ($min >= $max) {
 //        return $min;
 //      } else {
 //        return mt_rand($min, $max);
 //      }
 //    } else {
 //      return mt_rand();
 //    }
 //  }
	// function zen_encrypt_password($plain) {
 //    	$password = '';
 //    	for ($i=0; $i<10; $i++) {
 //    		$password .= zen_rand();
 //    	}
 //    	$salt = substr(md5($password), 0, 2);
 //    	$password = md5($salt . $plain) . ':' . $salt;
	
 //    	return $password;
 //  	}

	if(isset($_POST['customers_firstname'])){
		// if($_POST['customers_password'] == $_POST['customers_password_repeat']){
			$dob = str_replace("/", "-", $_POST['customers_dob']);
			$dob = date("Y-m-d", strtotime($dob));
			// $passwd = zen_encrypt_password($_POST['customers_password']);
			echo "<script>console.log('pass: ".$passwd.", dob: ".$dob."')</script>";
			$qry = "INSERT INTO customers (customers_lastname, epwnumia, customers_AFM, customers_dob, customers_doy, customers_profession, customers_email_address, customers_telephone, customers_address, customers_city, customers_postal_code, customers_fax) VALUES ('".$_POST['customers_firstname'].' '.$_POST['customers_lastname']."','".$_POST['epwnumia']."','".$_POST['customers_AFM']."','".$dob."','".$_POST['customers_doy']."','".$_POST['customers_profession']."','".$_POST['customers_email_address']."','".$_POST['customers_telephone']."','".$_POST['customers_address']."','".$_POST['customers_city']."','".$_POST['customers_postal_code']."','".$_POST['customers_fax']."')";

			if(mysqli_query($dbC, $qry)){
				echo "<div id='info' class='green'>Ο Χρήστης Δημιουργήθηκε επιτυχώς!</div>";
			} else {
				echo "<div id='info' class='red'>".mysqli_error($dbC)."</div>";
			}
		// } else {
			// echo "<div id='info' class='red'>The Passwords don't match</div>";
		// }
		
	}
?>
<style>
	#info{
	    width:50vh;
	    margin:0 auto;
	    color:white;
	    font-weight:600;
	    padding:20px;
	    border-radius:4px;
	    z-index:999;
	}
	.green{
		background-color:rgba(39, 186, 39, 0.8);
	}
	.red{
		background-color:rgba(186, 39, 39, 0.8);
	}
</style>

<div class="row">
    <div class="box col-md-12">
        <div class="box-inner">
            <div class="box-header well" data-original-title="">
                <h2><i class="glyphicon glyphicon-edit"></i>Δημιουργία Νέου Χρήστη</h2>

                <div class="box-icon">
                    <a href="#" class="btn btn-setting btn-round btn-default"><i
                            class="glyphicon glyphicon-cog"></i></a>
                    <a href="#" class="btn btn-minimize btn-round btn-default"><i
                            class="glyphicon glyphicon-chevron-up"></i></a>
                    <a href="#" class="btn btn-close btn-round btn-default"><i
                            class="glyphicon glyphicon-remove"></i></a>
                </div>
            </div>
            <div class="box-content">
                <form method="POST" id="main_form">
                	<table class="table-striped">
                		<tr><td>Όνομα: </td><td><input type="text" name="customers_firstname" /></td></tr>
                		<tr><td>Επώνυμο: </td><td><input type="text" name="customers_lastname" /></td></tr>
                		<tr><td>Επωνυμία: </td><td><input type="text" name="epwnumia" /></td></tr>
                		<!-- <tr><td>Φύλλο: </td><td><select name="customers_gender"><option value="m" selected>Άνδρας</option><option value="f">Γυναίκα</option></select></td></tr> -->
                		<tr><td>ΑΦΜ: </td><td><input type="text" name="customers_AFM" /></td></tr>
                		<tr><td>ΔΟΥ: </td><td><input type="text" name="customers_doy" /></td></tr>
                		<tr><td>Επάγγελμα: </td><td><input type="text" name="customers_profession" /></td></tr>
                		<tr><td>Ημερομηνία Γέννησης: </td><td><input type="date" name="customers_dob" /></td></tr>
                		<tr><td>Διεύθυνση Email: </td><td><input type="text" name="customers_email_address" /></td></tr>
                		<tr><td>Τηλέφωνο Επικοινωνίας: </td><td><input type="text" name="customers_telephone" /></td></tr>
                		<tr><td>Διεύθυνση: </td><td><input type="text" name="customers_address" /></td></tr>
                		<tr><td>Πόλη: </td><td><input type="text" name="customers_city" /></td></tr>
                		<tr><td>Τ.Κ.: </td><td><input type="text" name="customers_postal_code" /></td></tr>
                		<tr><td>ΦΑΞ: </td><td><input type="text" name="customers_fax" /></td></tr>
                		<!-- <tr><td>Κωδικός Χρήστη: </td><td><input type="password" name="customers_password" /></td></tr> -->
                		<!-- <tr><td>Επαλήθευση Κωδικού χρήστη: </td><td><input type="password" name="customers_password_repeat" /></td></tr> -->
                		<tr><td colspan="2"><input type="button" name="btnsubmit" value="Δημιουργία Χρήστη" id="submit_btn"/></td></tr>
                	</table>
                </form>
            </div>
        </div>
    </div>
    <script>
function check_input(){
	empty = 0;
	$('input').each(function(){
		if($(this).val()==''){
			$(this).css('background-color','rgb(186, 39, 39)');
			empty++;
		} else {
			$(this).css('background-color','');
		}
	})
	return empty;
}

$('#submit_btn').click(function(){
	if(check_input()==0){
		$('#main_form').submit();
	}
})
</script>