<?php

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

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

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

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

$district_id = $_POST['district_id'];
$department_name = $_POST['department_name'];
$description = $_POST['description'];

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

echo "<p style='color:green;'>Department Added Successfully</p>";

}

?>

<div class="main">

<h2>Add Department</h2>

<form method="POST">

<label>Select District</label>

<select name="district_id" required>

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

<?php while($row=mysqli_fetch_assoc($districts)){ ?>

<option value="<?php echo $row['id']; ?>">
<?php echo $row['district_name']; ?>
</option>

<?php } ?>

</select>

<br><br>

<label>Department Name</label>

<input type="text" name="department_name" required>

<br><br>

<label>Description</label>

<textarea name="description" id="editor"></textarea>

<br><br>

<button type="submit" name="add" class="btn-success">Add Department</button>

</form>

</div>

<!-- CKEditor -->

<script src="https://cdn.ckeditor.com/4.21.0/standard/ckeditor.js"></script>

<script>
CKEDITOR.replace('editor');
</script>

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