<?php
session_start();
if (empty($_SESSION['namauser']) AND empty($_SESSION['passuser'])){
  echo "<link href='css/style.css' rel='stylesheet' type='text/css'>
 <center>Untuk mengakses modul, Anda harus login <br>";
  echo "<a href=index.php><b>LOGIN</b></a></center>";
}
else{
?>








<?php
include "koneksi2.php";
if(isset($_POST['submit'])){

	$nama_depan=addslashes(htmlentities(ucwords($_POST['nama_depan'])));
	$nama_belakang=addslashes(htmlentities(ucwords($_POST['nama_belakang'])));
	$email=addslashes(htmlentities($_POST['email']));
	$password=$_POST['password'];
	$kelamin=$_POST['kelamin'];
	
	$nama_photo=$_FILES['photo']['name'];
	$type = $_FILES['photo']['type'];
	$ukuran=$_FILES['photo']['size'];

	
	// Nih tambahan
	$verifikator=addslashes(htmlentities(ucwords($_POST['verifikator'])));
	$unit_org=addslashes(htmlentities(ucwords($_POST['unit_org'])));



		
	if(empty($nama_depan) || empty($nama_belakang) || empty($email) || empty($password) || empty($nama_photo)){
		echo "Maaf, Form belum lengkap!! <a href=index173.php> Silahkan ulangi</a>";
	}else{  
		$query_email=mysql_query("select * from tbl_user where email='$email'");
		$cek=mysql_num_rows($query_email);
		if($cek>0){
			echo "Maaf, Kode Register sudah ada dalam data base!! <a href=index173.php> Silahkan ulangi</a>";
		}else{
			if($type != "image/gif"  &&  $type != "image/jpg"  && $type != "image/jpeg" && $type != "image/png") {
				echo "File Yang Di izinkan Hanya jpg,jpeg,png,gif!! <a href=index173.php> Silahkan ulangi</a>";
			}else{
				if($ukuran>1000000){
					echo "File Yang Di izinkan Hanya berukuran kurang dari 1MB!! <a href=index173.php> Silahkan ulangi</a>";
				}else{
					$uploaddir='./photo/';
					$verifikatornya=$_SESSION[namalengkap];
					$rnd=date(His);				
					$nama_file_upload=$rnd.'-'.$nama_photo;
					$alamatfile=$uploaddir.$nama_file_upload;
					
					if (move_uploaded_file($_FILES['photo']['tmp_name'],$alamatfile))
					{
						$query=mysql_query("insert into tbl_user(nama_depan,nama_belakang,email,password,kelamin,photo,ukuran,type,verifikator,unit_org) 
										values('$nama_depan','$nama_belakang','$email','$password','$kelamin','$nama_file_upload','$ukuran','$type','$verifikatornya','$unit_org')");
							
						if($query){
							echo "Data Anda berhasil disimpan <a href=media.php?module=input2> View Data</a>";
						}else{
							echo mysql_query();
						}
					}else{
						echo "<p>Proses upload gagal, kode error = " . $_FILES['location']['error']."</p>";
					}
				}
			}
		}
	}
}else{
	unset($_POST['submit']);
}
?>





<?php
}
?>

