<?php
    require_once 'common/database.php';
    global $db;
     
    // $id_akun = $_POST['id_akun'];
    $nama = $_POST['nama'];
    $username = $_POST['username'];
    $pass = $_POST['password'];
    $repass = $_POST['repassword'];
    $email = $_POST['email'];
    $role = 2;

    if($pass != $repass){
        echo "<script>alert('Password tidak sama.');
            window.location = 'regis.php'</script>";
    }
    else if($_POST['t1'] != $_SESSION['my_captcha']){
        echo "<script>alert('Captcha tidak sesuai.');
            window.location = 'regis.php'</script>";
    }
    else{
        $is_account_exist = CekAkun($username);
        if($is_account_exist > 0){
            echo "<script>alert('Username Sudah Dipakai');
                window.location = 'regis.php'</script>";
        }
        else{
            $do = AddAkun($nama,$username,$pass,$email,$role);
            if($do < 0){
                echo "<script>alert('Akun Berhasil Dibuat.');
                    window.location = 'index.php'</script>";
            }
            else{
                echo "<script>alert('Akun Gagal Dibuat.');
                window.location = 'index.php'</script>";
				}
            }
        }

?>