<?php
include_once '../session/admin-session.php';
include_once '../classes/class_admin.php';
include_once '../classes/validation.php';
include_once '../classes/common.php';
include_once 'read-configration.php';
ob_start();

$log = new common();
$objadm = new class_admin();
$val = new validation();

$working_semester_type = "AUTUMN";

$IdStr = $_REQUEST['IdStr'];
$IdStr = $val->ValidateString($IdStr);
$objadm->unique_code = $IdStr;

if ($_POST['course_btn']) {
    $course_title = $val->ValidateString($_REQUEST['course_title']);
    $slot = $val->ValidateString($_REQUEST['slot']);
    $semester_sel_arr = $_REQUEST['semester_sel'];
    $sem_sel_str = "";
    if (count($semester_sel_arr) > 0) {
        $sem_sel_str = implode(",", $semester_sel_arr);
    }

    $objadm->course_title = $course_title;
    $objadm->slot = $slot;
    $objadm->sem_sel_str = $sem_sel_str;

    $objadm->UpdateTempCourse();

    $success_msg = "Details Update Sucessfully!";
}

$GetTempCourseDetails = $objadm->GetTempCourseDetails();

while ($row = mysqli_fetch_array($GetTempCourseDetails)) {
    $bsms_code = $row['bsms_code'];
    $bsms_credit = $row['bsms_credit'];
    $phd_code = $row['phd_code'];
    $phd_credit = $row['phd_credit'];
    $course_title = $row['title'];
    $slot = $row['slot'];
    $sem = $row['sem'];
}
$db_semester_arr = array();
if (!empty($sem)) {
    $db_semester_arr = explode(",", $sem);
}
?>
<div class="container-fluid">
    <div class="row">
        <div class="col-xl-12 col-xxl-12 col-sm-12">
            <div class="card">
                <div class="card-header">
                    <h5 class="card-title">Course Curriculum Edit</h5>
                </div>
                <div class="card-body">
                    <div class="container">
                        <form action="" method="POST">
                            <fieldset class="box-container">
<?php if (!empty($success_msg)) { ?>
                                    <div class="text-success"><?php echo $success_msg; ?></div>
                                <?php } ?>
                                <!-- Course Details Row -->
                                <div class="row mb-3">
                                    <div class="col-md-3">
                                        <label class="form-label">Course Code</label>
                                        <input type="text" readonly="" class="form-control" name="course_code" id="course_code" value="<?php echo $bsms_code; ?>">
                                    </div>
                                    <div class="col-md-3">
                                        <label class="form-label">Credit</label>
                                        <input type="number" readonly="" class="form-control" name="course_credit" id="course_credit" value="<?php echo $bsms_credit; ?>">
                                    </div>
                                    <div class="col-md-3">
                                        <label class="form-label">PHD Code</label>
                                        <input type="text"readonly="" class="form-control" name="phd_code" id="phd_code" value="<?php echo $phd_code; ?>">
                                    </div>
                                    <div class="col-md-3">
                                        <label class="form-label">Credit</label>
                                        <input type="number" readonly="" class="form-control" name="phd_credit" id="phd_credit"  value="<?php echo $phd_credit; ?>">
                                    </div>
                                </div>

                                <!-- Title & Slot -->
                                <div class="row mb-3">
                                    <div class="col-md-9">
                                        <label class="form-label">Course Title</label>
                                        <input required="" type="text" class="form-control" name="course_title" id="course_title"  value="<?php echo $course_title; ?>">
                                    </div>
                                    <div class="col-md-3">
                                        <label class="form-label">Slot</label>
                                        <select name="slot" id="slot" class="form-control" required="">
<?php for ($char = "A"; $char <= "Z"; $char++) { ?>
                                                <option value="<?php echo $char; ?>"><?php echo $char; ?></option>
                                            <?php } ?>
                                        </select>
                                    </div>
                                </div>

                                <!-- Semester and Save Button -->
                                <div class="row">
                                    <div class="col-md-9">
                                        <label class="form-label">Semester</label><br/>
<?php if ($working_semester_type == "AUTUMN") { ?>

                                            <span> BSMS: <input type='checkbox' name='semester_sel[]' value="1" style='position: unset; opacity: 99' <?php
    if (in_array("1", $db_semester_arr)) {
        echo "CHECKED";
    }
    ?>/>&nbsp; 1&nbsp;&nbsp;<input type='checkbox' name='semester_sel[]' value="3" style='position: unset; opacity: 99' <?php
                                                if (in_array("3", $db_semester_arr)) {
                                                    echo "CHECKED";
                                                }
                                                ?>/>&nbsp;3&nbsp;&nbsp;<input type='checkbox' name='semester_sel[]' value="5" style='position: unset; opacity: 99' <?php
                                                                if (in_array("5", $db_semester_arr)) {
                                                                    echo "CHECKED";
                                                                }
                                                                ?>/>&nbsp;5&nbsp;&nbsp;<input type='checkbox' name='semester_sel[]' value="7" style='position: unset; opacity: 99' <?php
                                                                if (in_array("7", $db_semester_arr)) {
                                                                    echo "CHECKED";
                                                                }
                                                                ?>/>&nbsp;7&nbsp;&nbsp;<input type='checkbox' name='semester_sel[]' value="9" style='position: unset; opacity: 99' <?php
                                                                if (in_array("9", $db_semester_arr)) {
                                                                    echo "CHECKED";
                                                                }
                                                                ?>/>&nbsp;9&nbsp;&nbsp;</span><br/>
                                            <span> IPHD: <input type='checkbox' name='semester_sel[]' value="11" style='position: unset; opacity: 99' <?php
                                                                if (in_array("11", $db_semester_arr)) {
                                                                    echo "CHECKED";
                                                                }
                                                                ?>/>&nbsp;1&nbsp;&nbsp;<input type='checkbox' name='semester_sel[]' value="13" style='position: unset; opacity: 99' <?php
                                                if (in_array("13", $db_semester_arr)) {
                                                    echo "CHECKED";
                                                }
                                                ?>/>&nbsp;3&nbsp;&nbsp;</span><br/>
                                            <span>MSc: <input type='checkbox' name='semester_sel[]' value="31" style='position: unset; opacity: 99' <?php
                                                                if (in_array("31", $db_semester_arr)) {
                                                                    echo "CHECKED";
                                                                }
                                                                ?>/>&nbsp;1&nbsp;&nbsp;<input type='checkbox' name='semester_sel[]' value="33" style='position: unset; opacity: 99' <?php
                                                if (in_array("33", $db_semester_arr)) {
                                                    echo "CHECKED";
                                                }
                                                ?>/>&nbsp;3&nbsp;&nbsp;
                                            </span><br/>
                                            <span>PHD: <input type='checkbox' name='semester_sel[]' value="21" style='position: unset; opacity: 99' <?php
                                                          if (in_array("21", $db_semester_arr)) {
                                                              echo "CHECKED";
                                                          }
                                                ?>/>&nbsp;1&nbsp;&nbsp;</span><br/>
                                            <?php } else { ?>
                                            <span> BSMS: <input type='checkbox' name='semester_sel[]' value="2" style='position: unset; opacity: 99' <?php
                                                if (in_array("2", $db_semester_arr)) {
                                                    echo "CHECKED";
                                                }
                                                ?>/>&nbsp;2&nbsp;&nbsp;<input type='checkbox' name='semester_sel[]' value="4" style='position: unset; opacity: 99' <?php
                                                if (in_array("4", $db_semester_arr)) {
                                                    echo "CHECKED";
                                                }
                                                ?>/>&nbsp;4&nbsp;&nbsp;<input type='checkbox' name='semester_sel[]' value="6" style='position: unset; opacity: 99' <?php
                                                                if (in_array("6", $db_semester_arr)) {
                                                                    echo "CHECKED";
                                                                }
                                                                ?>/>&nbsp;6&nbsp;&nbsp;<input type='checkbox' name='semester_sel[]' value="8" style='position: unset; opacity: 99' <?php
                                                                if (in_array("8", $db_semester_arr)) {
                                                                    echo "CHECKED";
                                                                }
                                                                ?>/>&nbsp;8&nbsp;&nbsp;<input type='checkbox' name='semester_sel[]' value="10" style='position: unset; opacity: 99' <?php
                                                                if (in_array("10", $db_semester_arr)) {
                                                                    echo "CHECKED";
                                                                }
                                                                ?>/>&nbsp;10&nbsp;&nbsp;</span><br/>
                                            <span> IPHD: <input type='checkbox' name='semester_sel[]' value="12" style='position: unset; opacity: 99' <?php
                                                                if (in_array("12", $db_semester_arr)) {
                                                                    echo "CHECKED";
                                                                }
                                                                ?>/>&nbsp;2&nbsp;&nbsp;<input type='checkbox' name='semester_sel[]' value="14" style='position: unset; opacity: 99' <?php
                                                if (in_array("14", $db_semester_arr)) {
                                                    echo "CHECKED";
                                                }
                                                ?>/>&nbsp;4&nbsp;&nbsp;</span><br/>
                                            <span>MSc: <input type='checkbox' name='semester_sel[]' value="32" style='position: unset; opacity: 99' <?php
                                                                if (in_array("32", $db_semester_arr)) {
                                                                    echo "CHECKED";
                                                                }
                                                                ?>/>&nbsp;2&nbsp;&nbsp;<input type='checkbox' name='semester_sel[]' value="34" style='position: unset; opacity: 99' <?php
                                                if (in_array("34", $db_semester_arr)) {
                                                    echo "CHECKED";
                                                }
                                                ?>/>4</span>
                                            <span>PHD: <input type='checkbox' name='semester_sel[]' value="22" style='position: unset; opacity: 99' <?php
                                                              if (in_array("22", $db_semester_arr)) {
                                                                  echo "CHECKED";
                                                              }
                                                              ?>/>&nbsp;2&nbsp;&nbsp;</span><br/>

                                                          <?php } ?>
                                    </div>

                                    <div class="col-md-3">
                                        <input type="hidden" name="IdStr" id="IdStr" value="<?php echo $IdStr; ?>" />
                                        <input type="SUBMIT" name="course_btn" id="course_btn" class="btn btn-danger" value="SAVE" style="background: #a9181b;border: #a9181b;"/>
                                    </div>


                                    <!-- Save Button -->

                                </div>
                            </fieldset>

                        </form>
                    </div>


                </div>
            </div>

        </div>
    </div>
</div>
<?php
$pagemaincontent = ob_get_contents();
ob_clean();
$PAGENAME = 'course-curriculam-edit';
$HTMLTITLE = '';
$HTMLDESCRIPTION = '';
$HTMLKEYWORDS = '';
include("admin-master.php");
?>