<?php
$page_title = 'Tambah Karyawan Harian';
require_once('includes/load.php');
page_require_level(4);

if(isset($_POST['add_employee_harian'])){
    $req_fields = array('first_name','last_name', 'email', 'hire_date', 'job_title', 'status');
    validate_fields($req_fields);

    if(empty($errors)){
        $first_name = remove_junk($db->escape($_POST['first_name']));
        $last_name  = remove_junk($db->escape($_POST['last_name']));
        $email      = remove_junk($db->escape($_POST['email']));
        $phone      = remove_junk($db->escape($_POST['phone_number']));
        $hire_date  = remove_junk($db->escape($_POST['hire_date']));
        $job_title  = remove_junk($db->escape($_POST['job_title']));
        $status     = remove_junk($db->escape($_POST['status']));
        $kontak_darurat = remove_junk($db->escape($_POST['kontak_darurat']));

        $sql  = "INSERT INTO employees_harian (first_name, last_name, email, phone_number, hire_date, job_title, status, kontak_darurat)";
        $sql .= " VALUES ('{$first_name}', '{$last_name}', '{$email}', '{$phone}', '{$hire_date}', '{$job_title}', '{$status}', '{$kontak_darurat}')";

        if($db->query($sql)){
            $session->msg('s',"Data karyawan harian berhasil ditambahkan. ");
            redirect('employees_harian.php', false);
        } else {
            $session->msg('d','Gagal menambahkan data karyawan harian.');
            redirect('add_employee_harian.php', false);
        }
    } else {
        $session->msg("d", $errors);
        redirect('add_employee_harian.php',false);
    }
}
?>

<?php include_once('layouts/header.php'); ?>

<div class="row">
    <div class="col-md-12">
        <?php echo display_msg($msg); ?>
    </div>
</div>

<div class="row">
    <div class="col-md-9">
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>
                    <span class="glyphicon glyphicon-th"></span>
                    <span>Formulir Tambah Karyawan Harian</span>
                </strong>
            </div>
            <div class="panel-body">
                <div class="col-md-12">
                    <form method="post" action="add_employee_harian.php" class="clearfix">
                        <div class="form-group">
                            <label for="first_name">Nama Depan</label>
                            <input type="text" class="form-control" name="first_name" placeholder="Nama Depan" required>
                        </div>
                        <div class="form-group">
                            <label for="last_name">Nama Belakang</label>
                            <input type="text" class="form-control" name="last_name" placeholder="Nama Belakang" required>
                        </div>
                        <div class="form-group">
                            <label for="email">Email</label>
                            <input type="email" class="form-control" name="email" placeholder="contoh@domain.com" required>
                        </div>
                        <div class="form-group">
                            <label for="phone_number">Nomor Telepon</label>
                            <input type="text" class="form-control" name="phone_number" placeholder="Nomor Telepon">
                        </div>
                        <div class="form-group">
                            <label for="hire_date">Tanggal Masuk</label>
                            <input type="date" class="form-control" name="hire_date" required>
                        </div>
                        <div class="form-group">
                            <label for="job_title">Jabatan</label>
                            <input type="text" class="form-control" name="job_title" placeholder="Jabatan" required>
                        </div>
                        <div class="form-group">
                            <label for="status">Status</label>
                            <select class="form-control" name="status" required>
                                <option value="Active">Aktif</option>
                                <option value="On Leave">Cuti</option>
                                <option value="Terminated">Keluar</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="kontak_darurat">Kontak Darurat</label>
                            <input type="text" class="form-control" name="kontak_darurat" placeholder="Nama & Nomor Telepon">
                        </div>
                        <button type="submit" name="add_employee_harian" class="btn btn-info">Tambah Karyawan</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<?php include_once('layouts/footer.php'); ?>