<?php
require_once('../assets/constants/config.php');
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname;charset=utf8mb4;collation=utf8_general_ci;prefix=''", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);


$stmt = $conn->prepare("SELECT * FROM tbl_school_info");
$stmt->execute();
$result = $stmt->fetchAll();

foreach($result as $row) {

$currency = $row[6];
date_default_timezone_set($row[5]);

}

}catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
require_once('constants/check-login.php');

if (isset($_GET['node'])) {

$exam_id = $_GET['node'];

try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname;charset=utf8mb4;collation=utf8_general_ci;prefix=''", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);


$stmt = $conn->prepare("SELECT * FROM tbl_exams WHERE exam_id = :id");
$stmt->bindParam(':id', $exam_id);
$stmt->execute();
$result = $stmt->fetchAll();
$rec = count($result);

if ($rec < 1) {
header("location:./");
}

foreach($result as $row)
{
$exam_name = $row[1];
$duration = $row[2];
$passmark = $row[3];
$reexam = $row[4];
$deadline = $row[5];
$department = $row[6];
$class = $row[7];
$subject = $row[8];
$type = $row[9];
$fee = $row[10];
$terms = $row[11];
$corrections = $row[13];
$questions = $row[14];


}

}catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}


}else{

header("location:./");
}
?>
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>OES - Edit <?php echo $exam_name; ?></title>
<link rel="icon" href="../assets/images/favicon.ico">
<link href="../assets/google-fonts/nunito.css" rel="stylesheet">
<link type="text/css" rel="stylesheet" href="../assets/loader/waitMe.css"><link rel="stylesheet" href="../assets/styles/css/themes/lite-purple.min.css">
<link rel="stylesheet" href="../assets/styles/vendor/perfect-scrollbar.css">
<link rel="stylesheet" href="../assets/styles/vendor/datatables.min.css">
<link rel="stylesheet" href="../assets/styles/vendor/pickadate/classic.css">
<link rel="stylesheet" href="../assets/styles/vendor/pickadate/classic.date.css">
<link href="../assets/plugins/toastr/toastr.min.css" rel="stylesheet" type="text/css"/>
<script src="../assets/plugins/summernote/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<link href="../assets/plugins/summernote/summernote-lite.min.css" rel="stylesheet">
<script src="../assets/plugins/summernote/summernote-lite.min.js"></script>
<script src="../assets/plugins/summernote/summernote-fontawesome.js"></script>
<link rel="stylesheet" href="../assets/styles/css/themes/icons.css">

<script type="text/javascript">
function update(str)
{

var txt;
var xmlhttp;

if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}

xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
document.getElementById("class-data").innerHTML = xmlhttp.responseText;
}
}

xmlhttp.open("GET","constants/fetch-class.php?opt="+str, true);
xmlhttp.send();

}


</script>

<script>
function updateb(str)
{

var txt;
var xmlhttp;

if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}

xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
document.getElementById("subject-data").innerHTML = xmlhttp.responseText;
}
}

xmlhttp.open("GET","constants/fetch-subjects.php?opt="+str, true);
xmlhttp.send();

}
</script>

</head>

<style>


</style>

<body>
<div class="app-admin-wrap">
<div class="main-header">
<div class="logo">
<img src="../assets/images/logo.png" alt="">
</div>

<div class="menu-toggle">
<div></div>
<div></div>
<div></div>
</div>

<div class="d-flex align-items-center">
<div class="search-bar">
<input type="text" placeholder="Search students..">
<i class="search-icon text-muted i-Magnifi-Glass1"></i>
</div>
</div>

<div style="margin: auto"></div>

<div class="header-part-right">

<i class="i-Full-Screen header-icon d-none d-sm-inline-block" data-fullscreen></i>


<div class="dropdown">
<div class="user colalign-self-end">
<?php
if ($myvataor == null) {

print ' <img class="img-crop" src="../assets/images/blank_avatar.png" id="userDropdown" alt="" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">';

}else{

print ' <img class="img-crop" src="../assets/uploads/avatar/'.$myvataor.'" id="userDropdown" alt="" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">';

}

?>


<div class="dropdown-menu dropdown-menu-right" aria-labelledby="userDropdown">
<div class="dropdown-header">
<i class="i-Lock-User mr-1"></i> <?php echo $myemail; ?>
</div>
<a class="dropdown-item" href="account">Account settings</a>
<a class="dropdown-item" href="../logout">Sign out</a>
</div>
</div>
</div>
</div>

</div>

<div class="side-content-wrap">
<div class="sidebar-left open" data-perfect-scrollbar data-suppress-scroll-x="true">
<ul class="navigation-left">
<li class="nav-item" >
<a class="nav-item-hold" href="./">
<i class="nav-icon i-Bar-Chart"></i>
<span class="nav-text">Dashboard</span>
</a>
<div class="triangle"></div>
</li>
<li class="nav-item">
<a class="nav-item-hold" href="departments">
<i class="nav-icon i-File"></i>
<span class="nav-text">Departments</span>
</a>
<div class="triangle"></div>
</li>
<li class="nav-item">
<a class="nav-item-hold" href="classes">
<i class="nav-icon i-Folder-Open"></i>
<span class="nav-text">Classes</span>
</a>
<div class="triangle"></div>
</li>
<li class="nav-item">
<a class="nav-item-hold" href="subjects">
<i class="nav-icon i-Library"></i>
<span class="nav-text">Subjects</span>
</a>
<div class="triangle"></div>
</li>
<li class="nav-item">
<a class="nav-item-hold" href="students">
<i class="nav-icon i-Administrator"></i>
<span class="nav-text">Students</span>
</a>
<div class="triangle"></div>
</li>
<li class="nav-item   active">
<a class="nav-item-hold" href="exams">
<i class="nav-icon i-File-Horizontal-Text"></i>
<span class="nav-text">Examinations</span>
</a>
<div class="triangle"></div>
</li>
<li class="nav-item">
<a class="nav-item-hold" href="notice">
<i class="nav-icon i-Bell"></i>
<span class="nav-text">Notice</span>
</a>
<div class="triangle"></div>
</li>
<li class="nav-item">
<a class="nav-item-hold" href="enroll_numbers">
<i class="nav-icon i-File-Clipboard-File--Text"></i>
<span class="nav-text">Enroll Numbers</span>
</a>
<div class="triangle"></div>
</li>
<li class="nav-item">
<a class="nav-item-hold" href="school">
<i class="nav-icon i-Big-Data"></i>
<span class="nav-text">School Info</span>
</a>
<div class="triangle"></div>
</li>

<li class="nav-item">
<a class="nav-item-hold" href="smtp">
<i class="nav-icon i-Email"></i>
<span class="nav-text">SMTP</span>
</a>
<div class="triangle"></div>
</li>

</ul>
</div>


<div class="sidebar-overlay"></div>
</div>


<div class="main-content-wrap sidenav-open d-flex flex-column">
<div class="breadcrumb">
<h1>Edit <?php echo $exam_name; ?></h1>
<p id="app_data"></p>

</div>
<div class="separator-breadcrumb border-top"></div>
<div class="row mb-4">
<div class="col-md-12 mb-4">
<div class="card text-left">
<div class="card-body">

<div class="mr-3 ml-3">

</div>
<div class="tab-content" id="myPillTabContent">
<div class="tab-pane fade active show" id="addPIll" role="tabpanel" aria-labelledby="home-icon-pill">

<form class="app_form"  action="app/update-exam.php" method="POST" autocomplete="OFF">
<input type="hidden" name="id" value="<?php echo $exam_id; ?>">
<div class="form-group row">
<label for="inputEmail3" class="col-sm-2 col-form-label">Exam Name</label>
<div class="col-sm-10">
<input type="text" value="<?php echo $exam_name; ?>" required name="name" class="txt-tit form-control" id="inputEmail3" placeholder="Enter exam name">
</div>
</div>

<div class="form-group row">
<label for="inputEmail3" class="col-sm-2 col-form-label">Exam Duration (Minutes)</label>
<div class="col-sm-10">
<input type="number" value="<?php echo $duration; ?>" name="duration" class="form-control" id="inputEmail3" placeholder="Enter duration in minutes (LEAVE BLANK FOR UNTIMED)">
</div>
</div>

<div class="form-group row">
<label for="inputEmail3" class="col-sm-2 col-form-label">Passmark (%)</label>
<div class="col-sm-10">
<input type="number" value="<?php echo $passmark; ?>" required name="passmark" class="form-control" id="inputEmail3" placeholder="Enter passmark in percent">
</div>
</div>

<div class="form-group row">
<label for="inputEmail3" class="col-sm-2 col-form-label">Re-exam</label>
<div class="col-sm-10">
<input type="number" value="<?php echo $reexam; ?>" name="attempts" class="form-control" id="inputEmail3" placeholder="If student take exam then show it again after some days  (LEAVE BLANK FOR NO RE-EXAM)">
</div>
</div>

<div class="form-group row">
<label for="inputEmail3" class="col-sm-2 col-form-label">Deadline</label>
<div class="col-sm-10">
<input required id="picker2" value="<?php echo $deadline; ?>" class="form-control" placeholder="Deadline" name="deadline">
</div>
</div>



<div class="form-group row">
<label for="inputEmail3" class="col-sm-2 col-form-label">Department</label>
<div class="col-sm-10">
<select onchange="update(this.value)" required name="department" class="form-control" >
<option value=""selected disabled>Select department</option>
<?php
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname;charset=utf8mb4;collation=utf8_general_ci;prefix=''", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);


$stmt = $conn->prepare("SELECT * FROM tbl_departments ORDER BY name");
$stmt->execute();
$result = $stmt->fetchAll();

foreach($result as $row)
{
print '<option'; if ($department == $row[0]) { print ' selected '; } print ' value="'.$row[0].'">'.$row[1].'</option>';

}

}catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
?>
</select>
</div>
</div>

<div class="form-group row">
<label for="inputEmail3" class="col-sm-2 col-form-label">Class</label>
<div class="col-sm-10">
<select onchange="updateb(this.value)" required id="class-data" name="class" class="form-control" >
<?php
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname;charset=utf8mb4;collation=utf8_general_ci;prefix=''", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);


$stmt = $conn->prepare("SELECT * FROM tbl_classes WHERE department = :dep ORDER BY name");
$stmt->bindParam(':dep', $department);
$stmt->execute();
$result = $stmt->fetchAll();

foreach($result as $row)
{
print '<option'; if ($class == $row[0]) { print ' selected '; } print ' value="'.$row[0].'">'.$row[1].'</option>';

}

}catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
?>

</select>
</div>
</div>

<div class="form-group row">
<label for="inputEmail3" class="col-sm-2 col-form-label">Subject</label>
<div class="col-sm-10">
<select required id="subject-data" name="subject" class="form-control" >

<?php
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname;charset=utf8mb4;collation=utf8_general_ci;prefix=''", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);


$stmt = $conn->prepare("SELECT * FROM tbl_subjects WHERE class = :class ORDER BY name");
$stmt->bindParam(':class', $class);
$stmt->execute();
$result = $stmt->fetchAll();

foreach($result as $row)
{
print '<option'; if ($subject == $row[0]) { print ' selected '; } print ' value="'.$row[0].'">'.$row[1].'</option>';

}

}catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
?>

</select>
</div>
</div>

<div class="form-group row">
<label for="inputEmail3" class="col-sm-2 col-form-label">Questions</label>

<div class="col-sm-10">
<input value="<?php echo $questions; ?>" required type="number" name="questions" class="form-control" placeholder="Enter number of questions to display">
</div>
</div>

<div class="form-group row">
<label for="inputEmail3" class="col-sm-2 col-form-label">Exam Type</label>
<div class="col-sm-6">
<label class="radio radio-outline-primary">
<input type="radio" <?php if ($type == "Free") { print ' checked="true" '; } ?> name="type" value="Free" required>
<span>Enroll students for Free</span>
<span class="checkmark"></span>
</label>
<label class="radio radio-outline-primary">
<input type="radio" <?php if ($type == "Paid") { print ' checked="true" '; } ?> name="type" value="Paid" required>
<span>Enroll students using enroll number</span>
<span class="checkmark"></span>
</label>
</div>

<div class="col-sm-4 input-group mb-4">
<input type="number" class="form-control" value="<?php echo $fee; ?>" name="price" placeholder="Exam fee if available (<?php echo $currency; ?>)" aria-describedby="basic-addon2">

</div>
</div>

<div class="form-group row">
<label for="inputEmail3" class="col-sm-2 col-form-label">Terms and Conditions</label>
<div class="col-sm-10">

<textarea id="summernote" name="terms" > <?php echo $terms; ?></textarea>
<script>
$('#summernote').summernote({
tabsize: 2,
height: 120,
toolbar: [
['style', ['style']],
['font', ['bold', 'underline', 'clear']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']],
['table', ['table']],
['insert', ['link', 'video']],
['view', ['codeview', 'help']]
]
});
</script>
</div>
</div>

<div class="form-group row">
<label for="inputEmail3" class="col-sm-2 col-form-label">Corrections</label>
<div class="col-sm-10">
<label class="switch switch-primary">
<span>Show exam corrections</span>
<input name="corrections" type="checkbox" <?php if ($corrections == "1") { print 'checked="checked"'; } ?>>
<span class="slider"></span>
</label>
</div>
</div>


<div class="form-group row">
<label for="inputEmail3" class="col-sm-2 col-form-label"></label>
<div class="col-sm-10">
<button type="submit"   class="btn btn-primary app_btn ">Save</button>
</div>
</div>
</form>

</div>


</div>
</div>


</div>
</div>


</div>

<div class="flex-grow-1"></div>


</div>

</div>
<div class="search-ui">
<div class="search-header">
<img src="assets/images/logo.png" alt="" class="logo">
<button class="search-close btn btn-icon bg-transparent float-right mt-2">
<i class="i-Close-Window text-22 text-muted"></i>
</button>
</div>
<form class="app_form"  action="search" method="GET" autocomplete="OFF">
<input type="text" name="keyword" required  placeholder="first name OR last name" class="search-input" autofocus>
</form>

</div>

<script src="../assets/js/vendor/jquery-3.3.1.min.js"></script>
<script src="../assets/js/vendor/bootstrap.bundle.min.js"></script>
<script src="../assets/js/vendor/perfect-scrollbar.min.js"></script>

<script src="../assets/js/vendor/pickadate/picker.js"></script>
<script src="../assets/js/vendor/pickadate/picker.date.js"></script>

<script src="../assets/js/vendor/datatables.min.js"></script>
<script src="../assets/loader/waitMe.js"></script><script src="../assets/js/es5/script.min.js"></script>
<script src="../assets/js/datatables.script.js"></script>
<script src="../assets/js/form.basic.script.js"></script>

<script>
$("[data-toggle=popover]").popover();
</script>
<script src="../assets/plugins/toastr/toastr.min.js"></script>
<?php require_once('../assets/constants/check-reply.php') ;?>


</body>



</html>
