<?php

include "../../config/master.php";
allowRoles([1]);

include "../layout/header.php";

/* HIDE SIDEBAR */
echo "<style>
.sidebar{display:none !important;}
.topbar{margin-left:0 !important;}
.main{margin-left:0 !important;padding-bottom:80px;}
</style>";

$districts = mysqli_query($conn,"SELECT * FROM districts ORDER BY district_name");

if(isset($_POST['add']))
{

$district_id = intval($_POST['district_id']);
$department_name = mysqli_real_escape_string($conn,$_POST['department_name']);
$description = $_POST['description'];

mysqli_query($conn,"INSERT INTO departments(district_id,department_name,description)
VALUES('$district_id','$department_name','$description')");

echo "<script>alert('Department Added Successfully');</script>";

}

?>

<div class="app-content">

<!-- HEADER -->
<div class="card-box">
<h4>Add Department</h4>
<p style="font-size:12px;color:#777;">Create new department</p>
</div>

<!-- FORM -->
<div class="card-box">

<form method="POST">

<label>Select District</label>
<select name="district_id" class="form-control" required>

<option value="">Select District</option>

<?php while($row=mysqli_fetch_assoc($districts)){ ?>
<option value="<?php echo $row['id']; ?>">
<?php echo htmlspecialchars($row['district_name']); ?>
</option>
<?php } ?>

</select>

<label style="margin-top:10px;">Department Name</label>
<input type="text" name="department_name" class="form-control" required>

<label style="margin-top:10px;">Description</label>
<textarea name="description" id="editor" class="form-control"></textarea>

<br>

<button type="submit" name="add" class="btn-mobile"
style="background:#27ae60;color:#fff;">
Add Department
</button>

</form>

</div>

</div>

<!-- CKEDITOR -->
<script src="https://cdn.ckeditor.com/4.21.0/standard/ckeditor.js"></script>
<script>
CKEDITOR.replace('editor');
</script>

<!-- ===== FOOTER ===== -->

<div class="bottom-nav">
    <a href="../dashboard.php">
        <i class="fa fa-house"></i>
        Home
    </a>

    <a href="../villages/village_data.php">
        <i class="fa fa-map"></i>
        Villages
    </a>

    <a href="../families/view_families.php">
        <i class="fa fa-users"></i>
        Families
    </a>

    <a href="../schemes/view_schemes.php">
        <i class="fa fa-list"></i>
        Schemes
    </a>
</div>

<?php include "../layout/footer.php"; ?>