<?php
//$course_id = $this->session->userdata('course_id');
//$course_batch_id = $this->session->userdata('course_batch_id');
?>
<?php if (!$course_id && !$course_batch_id) { ?>
    <div class="form-group col-sm-12">  
        <form action="<?php echo base_url(); ?>super_admin_student/save_student_course/<?php echo $person_id; ?>" method="post" name="userForm" enctype="multipart/form-data" >
            <!--Some Required Hidden Value -->
            <input type="hidden" name="person_id" value="<?php echo $person_id ?>">
            <br>
            <br>
            <div class="form-group col-sm-12" id="">
                <div class="form-group col-sm-4">
                    <label class="control-label" for="typeahead">Course Category<span style="color: red">*</span></label>
                    <div class="controls">
                        <select class="form-control" id="course_category" name ="course_category_id" onchange="selectCourse(this.value, 'course_list');">
                            <option value="">Select Course Category</option>
                            <?php foreach ($courses_all_categories as $v_course_category) { ?>
                                <option value="<?php echo $v_course_category->course_category_id; ?>"><?php echo $v_course_category->course_category_name; ?></option>
                            <?php } ?>
                        </select>
                        <script language="javascript">

                            document.forms['studentForm'].elements['course_category_id'].value = '<?php echo set_value('course_category_id'); ?>';
                            function selectCourse(categoryID, objID) {
                                serverPage = '<?php echo base_url(); ?>super_admin_course/select_all_available_course_by_cateogy_id/' + categoryID;
                                xmlhttp.open("GET", serverPage);
                                xmlhttp.onreadystatechange = function ()
                                {
                                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                                    {
                                        document.getElementById(objID).innerHTML = xmlhttp.responseText;
                                        localtion.reload();
                                    }
                                }
                                xmlhttp.send(null);
                            }
                        </script>
                    </div>
                </div>
                <div id="course_list">
                    <div class="form-group col-sm-4">
                        <label for="course_id">Course<span style="color: red">*</span></label>
                        <div class="controls">
                            <select class="form-control" name ="course_id" id ="course_id" >
                                <option value="">Select Course</option>
                            </select>
                        </div>
                    </div>
                </div>

                <div id="course_batch_list" class="col-sm-12">

                </div>

                <script>

                    document.forms['quizForm'].elements['course_batch_id'].value = '<?php echo set_value('course_batch_id'); ?>';

                    function addCourseBatch(courseBatch) {
                        if (courseBatch === 'other') {
                            document.getElementById('other_batch').innerHTML = "<label for='quiz_type'>Add Course Batch</label><span class='required'> * </span><input style='float:left;' type='text' class='form-control' id='course_new_batch' name='course_new_batch' value='<?php echo set_value('course_new_batch'); ?>'placeholder='Enter Course new Batch Name' onblur='checkCourseNewBatch(this.value);' >";
                            document.getElementById('batch_status').innerHTML = "<p style='color:red;'>Quiz Type Is required</p>";
                        } else {
                            document.getElementById('other_batch').innerHTML = "";
                            document.getElementById('batch_status').innerHTML = "";
                        }
                    }

                    function checkCourseNewBatch(courseNewBatch)
                    {
                        if (courseNewBatch != '') {
                            document.getElementById('batch_status').innerHTML = '';
                        } else if (courseNewBatch == '') {
                            document.getElementById('batch_status').innerHTML = '<p style="color:red;">Please Enter Course New Batch Name</p>';
                        }
                    }
                </script>

                <script language="javascript">
                    document.forms['studentForm'].elements['course_id'].value = '<?php echo set_value('course_id'); ?>';
                    function selectCourseBatch(courseID, objID) {
                        serverPage = '<?php echo base_url(); ?>super_admin_course/select_all_available_course_batch_by_course_id/' + courseID;
                        xmlhttp.open("GET", serverPage);
                        xmlhttp.onreadystatechange = function ()
                        {
//                            alert(xmlhttp.responseText);
                            if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                            {
                                document.getElementById(objID).innerHTML = xmlhttp.responseText;
                            }
                        }
                        xmlhttp.send(null);
                    }
                </script>

                <div class="form-group col-sm-12 danger"><?php echo form_error('person_country'); ?></div>
            </div>

            <div class="form-group col-sm-10">
                <div class="form-group col-sm-4">
                    <label for="student_type">Select Student Type:</label><span class="required"> * <?php // echo form_error('person_role');                                                                                               ?></span>
                    <select class="form-control" name="student_type" id="student_type">
                        <option value="">--Select Student Type--</option>
                        <option value="1">Class Room</option>
                        <option value="2">Online</option>
                        <option value="3">video Training</option>
                    </select>
                </div>
                <script>
                    document.forms['studentForm'].elements['student_type'].value = '<?php
                        if (set_value('student_type')) {
                            echo set_value('student_type');
                        } else {
                            echo $student_types;
                        }
                        ?>';</script>
            </div>
            <div class="form-group col-sm-8">

                <div class="checkbox col-sm-6" >
                    <?php if ($course_batch_id) { ?>
                        <button type="submit" id="update" class="btn btn-default" >Update</button>
                    <?php } else if ($person_id) { ?>
                        <button type="submit" id="submit2" class="btn btn-default">Submit</button>
                        <button type="reset" class="btn btn-default">Reset</button>
                    <?php } ?>

                </div>
            </div>
        </form>
    </div>
<?php } ?>


<?php if ($course_id && $course_batch_id) { ?>
    <div class="form-group col-sm-12">  
        <form action="<?php echo base_url(); ?>super_admin_student/save_student_course/<?php echo $person_id; ?>" method="post" name="userForm" enctype="multipart/form-data" >
            <!--Some Required Hidden Value -->
            <input type="hidden" name="person_id" value="<?php echo $person_id ?>">
            <br>
            <br>
            <div class="form-group col-sm-12" id="">
                <div class="form-group col-sm-4">
                    <label class="control-label" for="typeahead">Course Category<span style="color: red">*</span></label>
                    <div class="controls">
                        <select class="form-control" id="course_category" name ="course_category_id" onchange="selectCourse(this.value, 'course_list');">
                            <option value="">Select Course Category</option>
                            <?php foreach ($courses_all_categories as $v_course_category) { ?>
                                <option value="<?php echo $v_course_category->course_category_id; ?>"><?php echo $v_course_category->course_category_name; ?></option>
                            <?php } ?>
                        </select>
                        <script language="javascript">

                            document.forms['studentForm'].elements['course_category_id'].value = '<?php echo set_value('course_category_id'); ?>';
                            function selectCourse(categoryID, objID) {
                                serverPage = '<?php echo base_url(); ?>super_admin_course/select_all_available_course_by_cateogy_id/' + categoryID;
                                xmlhttp.open("GET", serverPage);
                                xmlhttp.onreadystatechange = function ()
                                {
//                                    alert(xmlhttp.responseText);
                                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                                    {
                                        aler(xmlhttp.responseText);
                                        document.getElementById(objID).innerHTML = xmlhttp.responseText;
                                        localtion.reload();
                                    }
                                }
                                xmlhttp.send(null);
                            }
                        </script>
                    </div>
                </div>
                <div id="course_list">
                    <div class="form-group col-sm-4">
                        <label for="course_id">Course<span style="color: red">*</span></label>
                        <div class="controls">
                            <select class="form-control" name ="course_id" id ="course_id" >
                                <option value="">Select Course</option>
                            </select>
                        </div>
                    </div>
                </div>

                <div id="course_batch_list" class="col-sm-12">

                </div>

                <script>

                    document.forms['quizForm'].elements['course_batch_id'].value = '<?php echo set_value('course_batch_id'); ?>';

                    function addCourseBatch(courseBatch) {
                        if (courseBatch === 'other') {
                            //                        alert();
                            document.getElementById('other_batch').innerHTML = "<label for='quiz_type'>Add Course Batch</label><span class='required'> * </span><input style='float:left;' type='text' class='form-control' id='course_new_batch' name='course_new_batch' value='<?php echo set_value('course_new_batch'); ?>'placeholder='Enter Course new Batch Name' onblur='checkCourseNewBatch(this.value);' >";
                            document.getElementById('batch_status').innerHTML = "<p style='color:red;'>Quiz Type Is required</p>";
                        } else {
                            document.getElementById('other_batch').innerHTML = "";
                            document.getElementById('batch_status').innerHTML = "";
                        }
                    }

                    function checkCourseNewBatch(courseNewBatch)
                    {
                        if (courseNewBatch != '') {
                            document.getElementById('batch_status').innerHTML = '';
                        } else if (courseNewBatch == '') {
                            document.getElementById('batch_status').innerHTML = '<p style="color:red;">Please Enter Course New Batch Name</p>';
                        }
                    }
                </script>

                <script language="javascript">
                    document.forms['studentForm'].elements['course_id'].value = '<?php echo set_value('course_id'); ?>';
                    function selectCourseBatch(courseID, objID) {
                        serverPage = '<?php echo base_url(); ?>super_admin_course/select_all_available_course_batch_by_course_id/' + courseID;
                        xmlhttp.open("GET", serverPage);
                        xmlhttp.onreadystatechange = function ()
                        {
                            if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                            {
                                document.getElementById(objID).innerHTML = xmlhttp.responseText;
                            }
                        }
                        xmlhttp.send(null);
                    }
                </script>

                <div class="form-group col-sm-12 danger"><?php echo form_error('person_country'); ?></div>
            </div> 

            <div class="form-group col-sm-10">
                <div class="form-group col-sm-4">
                    <label for="student_type">Select Student Type:</label><span class="required"> * <?php // echo form_error('person_role');                                                                                               ?></span>
                    <select class="form-control" name="student_type" id="student_type">
                        <option value="">--Select Student Type--</option>
                        <option value="1">Class Room</option>
                        <option value="2">Online</option>
                        <option value="3">video Training</option>
                    </select>
                </div>
                <script>
                    document.forms['studentForm'].elements['student_type'].value = '<?php
                        if (set_value('student_type')) {
                            echo set_value('student_type');
                        } else {
                            echo $role_id;
                        }
                        ?>';</script>
            </div>
            <div class="form-group col-sm-8">

                <div class="checkbox col-sm-6" >
                    <?php if ($course_batch_id) { ?>
                        <button type="submit" id="update2" class="btn btn-default" >Update</button>
                    <?php } else if ($person_id) { ?>
                        <button type="submit" id="submit2" class="btn btn-default">Submit</button>
                        <button type="reset" class="btn btn-default">Reset</button>
                    <?php } ?>
                        <script>
                            function checkRequiredField(){
                                var courseCategoryID = document.getElementById('course_category_id').value;
                                var courseID= document.getElementById('course_id').value;
                                var courseBatchID= document.getElementById('course_batch_id').value;
                            }
                        </script>
                </div>
            </div>
        </form>
    </div>
<?php } ?>
