<?php if (!$session->is_logged_in()) {
  //redirect_to("index.php");
    
//$session_class();
}
?>
<?php //require_once("includes/initialize.php");

$year = $_GET['type'];

//echo "Demolshu";
 $_SESSION['year']=$year;
 $id = $session->user_id;
$user_data = Userdata::find_by_id($session->user_id);
 $array_semester=array();



 if (substr($user_data->formno,2,2)>=20){
     
    // echo "Student Process ID: ".$user_data->std_process_id;
      
        Switch(substr($user_data->formno,2,2))
      {
          case '20':$table='form_data';
          break;
          
          case '21': $table='form_data21';
          break;
          
          case '22': $table='form_data22';
      }
      
       $biodata = Biodata2::find_by_id($table,$user_data->formno, $user_data->email);
       
      //echo "Feee: ".$biodata->formno;
      
      
          
          $level= $biodata->level;
     
        $new_dp = DEPARTMENTCLASS::new_admin_dept($biodata->formno);
        
        
        
          if (!isset($new_dp->department)){
           $biodata->courses ='Nil';   
          }else if ($new_dp->department=='Microbiology (Option)'){
      $biodata->courses= $biodata->department='Applied Science (Microbiology Option)'; 
      
      Schoolfees::updateDepartment($biodata->formno, $dept);
       
    }else if ($new_dp->department=='Environmental Biology (Option)'){
      $biodata->courses= $biodata->department='Applied Science (Environmental Biology Option)'; 
      
      Schoolfees::updateDepartment($biodata->formno, $dept);
       
    }else if ($new_dp->department=='Physics with Electronics (Option)'){
      $biodata->courses= $biodata->department='Applied Science (Physics with Electronics Option)'; 
      
      Schoolfees::updateDepartment($biodata->formno, $dept);
       
    }else if ($new_dp->department=='Chemistry (Option)'){
      $biodata->courses= $biodata->department='Applied Science (Chemistry Option)'; 
      
      Schoolfees::updateDepartment($biodata->formno, $dept);
       
    }else if  ($new_dp->department=='Electronic/Telecommunication (Option)'){
       $biodata->courses= $biodata->department = 'Electronics/Telecommunication (Option)';
       
        Schoolfees::updateDepartment($biodata->formno, $dept);
       
    }else{
       $dept= $biodata->courses = $new_dp->department;
          }
       $biodata->programme = $biodata->level;
       
       
       //echo "Department: ".$dept;
  
        // $pixf = substr($biodata->passport, 10);
       $dp = DEPARTMENTCLASS::department_authenticate($biodata->department);
       $pix = "http://admission.oscotechesaoke.edu.ng/passport/".trim($biodata->passport);
    
     
    
       
  }else{
     
     $biodata = Biodata::find_by_id($user_data->formno, $user_data->email); 

 if (substr($user_data->formno,2,2)=='19'){

 $new_dp = DEPARTMENTCLASS::new_admin_dept($user_data->formno);
  $biodata->courses = $new_dp->department;
  $biodata->programme = $biodata->level; 
  
   $dp = DEPARTMENTCLASS::department_authenticate($biodata->courses);
   $pix = "../application_account/passport/".$pixf;
   
 }else {


  $biodata = Biodata::find_by_id($user_data->formno, $user_data->email);
  
$dp = DEPARTMENTCLASS::department_authenticate($biodata->courses);

//print_r($session_class);

//$display_course = COURSECLASS::fetch_all_course($biodata->courses, $biodata->programme, $session_class->semester);
$alldp = DEPARTMENTCLASS::find_all($dp->faculty);
$pix = "../Oscotech-Wallet/passport/".$pixf;


//print_r($display_course);

}
$dept = $biodata->courses;
$level = $biodata->programme;

}

// $semester = $session_first->semester;
$getsession = $user_data->start_session;
$semester = 'First';

// $_SESSION["First"] = $semester;

// $level = $level . "I";
//echo "Level: ".$level;

$s= find_semester($user_data->std_process_id);
$clevel= find_level($user_data->std_process_id,$level);


//echo "Level Act: ".$clevel;

if (!empty($clevel)){
    

if (($clevel=='ND I') ||($clevel=='HND I')){
    
    $prs = '20'.substr($user_data->formno,2,2);
    $se = $prs.'/'.($prs+1);
    
    
     
         $array_semester = SESSIONCLASSNEW::fetch_semester_id($year,$clevel);
   
   //=====================================================================
   
         foreach ($array_semester as $cid){
             //echo "<br>Semester Id: ". $cid->sem_id;
             
                if ($cid->sem_id==1){
                    $s="First";
                    
                
             $regTable = return_reg_table($cid->sem_id, $clevel);
             
  //First semester of year one is using form no
//*********************************************************************          
    if ($dept=='Microbiology (Option)'){
        $dept='Applied Science (Microbiology Option)';
    }
             
                 
       
  $found= SESSIONCLASSNEW::Check_Stud_reg_rec($regTable, $cid->sem_id,$user_data->formno,$dept);
                
 if (isset($found->matricno)){
    
     //Registration already completed for first semester
     
     //Take me to second semester page
     
     $updateActivity = SESSIONCLASSNEW::update_to_Second_semester($user_data->formno,5);
     
     if ($updateActivity){
         
         redirect_to('https://eportal.oscotechesaoke.edu.ng/student_portal/dashboard.php?type=1');
     }
             
         $semester = $s;   
$msgs1 = 1;
 }else{
    
   
    if ($dept=='Microbiology (Option)'){
        $dept='Applied Science (Microbiology Option)';
    }
                    
$display_course = COURSECLASS::fetch_all_course($dept, $clevel, $s);



                    
    $_SESSION['sem_id'] = $cid->sem_id;                
                    
    //echo  "First Semester Course";               
                    
        $semester = $s;            
}
                
                
 //____________________________________________________________________               
                
 }
 
 
 
 /*
 else if ($user_data->matricno!=0){
             
         
 $found= SESSIONCLASSNEW::Check_Stud_reg_rec($regTable, $cid->sem_id,$user_data->matricno,$dept);
                
 if (isset($found->matricno)){
    
    
     //Registration already completed for first semester
                
  $msgs2 = 2;
 }else{
    
    
    
    echo $dept.' '. $clevel.' '. $s;             
//$display_course = COURSECLASS::fetch_all_course($dept, $clevel, $s);          
                    
               
   
  // print_r($display_course);            
               
               
               
               
 }
             
    
    
    
    //echo $regTable;
             
             
             }*/
             
             
             
             }
//=============================================================
//Checking for existing record of courses and displaying the semester which has not been registered for
     
}else if (($clevel=='ND II') ||($clevel=='HND II')){
    
    
     $prs = '20'.(substr($user_data->formno,2,2)+1);
     $se = $prs.'/'.($prs+1);
    
    
    $array_semester = SESSIONCLASSNEW::fetch_semester_id($year,$clevel);
         
         foreach ($array_semester as $cid){
             
          // echo "<br>Semester Id: ". $cid->sem_id;
             
             $regTable = return_reg_table($cid->sem_id, $clevel);
             
             if ($cid->sem_id==3){
               // echo "Form: ".$user_data->formno;
               
               if (isset($found->matricno)){
    
                 //Registration already completed for first semester
     
                //Take me to second semester page of ND II or HND II
                
                
                $updateActivity = SESSIONCLASSNEW::update_to_Second_semester($user_data->formno,8);
     
     if ($updateActivity){
         
         redirect_to('https://eportal.oscotechesaoke.edu.ng/student_portal/dashboard.php?type=2');
     }
                
                
                
                $semester = $s;
                
            $msgs1 = 1;
        }else{
    
         if ($dept=='Microbiology (Option)'){
        $dept='Applied Science (Microbiology Option)';
    }           
        $display_course = COURSECLASS::fetch_all_course($dept, $clevel, $s);          
                    
            $_SESSION['sem_id'] = $cid->sem_id;      
                    
        //echo  "alert(First Semester Course of HND II)";               
                    
            $semester = $s;        
       }
             
         //    echo $regTable;
             
        }
    
// }else{
//     //$msgs = 'Semester course registration not yet activated';
// }

         }
}

}


?>

<script src="../javascripts/jquery.min.js"></script>
<script src="../javascripts/bootstrap.min.js" type="text/javascript"></script>


<?php if (($level == "ND II") or ($level == "HND II") or ($level == "PGD II") and ($tag == 1) or ($tag == 3)){ ?>
<!--    <div class="art-content-layout">
        <div class="art-content-layout-row">

            <div class="art-layout-cell layout-item-0" style="width: 100%">

                <marquee behavior="alternate" scrolldelay="200" onmouseover="this.setAttribute('scrollamount',0,0);"
                         onmouseout="this.setAttribute('scrollamount',6,0);">
                    <div style="color:#F00; font-style:italic; font-weight:bolder;">NOTE: <span
                                style="color:#F00; font-style:italic;">Select Department, level and semester to borrow or register re-run courses </span>
                    </div>
                </marquee>


            </div>
        </div>
    </div> -->
<div class="art-content-layout">
    <!-- <div class="art-content-layout-row" align="center">
        <div class="art-layout-cell layout-item-0" style="width: 100%; margin:0; padding:0;">


            <div class="container" id="#tab">

                <div id="disabled">
                <span id="department1">
                    <select name="department" id="department" class="form-control action" style="width:150px" required="required"><option value="">Select Department</option>
                                  <?php foreach($alldp as $dep){?>
                                  <option value="<?php echo $dep->department;?>"><?php 
                                  echo ucwords($dep->department);?></option> <?php }?>
                              </select>
                </span>
                    <span id="level1">
                        <?php if($clevel == "HND II") {?>
                        <select name="level" id="level" class="action">
                        <option value="">Select Level</option>
                        <option value="HND I">HND I</option>
                    </select>
                        <?php }else if ($clevel == "ND II") { ?>
                    <select name="level" id="level" class="action">
                        <option value="">Select Level</option>
                        <option value="ND I">ND I</option>
                    </select> <?php } ?>
                </span>
                    <span id="semester1">
                    <select name="semester" id="semester" class="action">
                        <option value="">Select Semester</option>
                        <?php echo "<option value=" . $s . ">" . $s . "</option>"; ?>
                    </select>
                </span>
                </div>

            </div>
        </div>
    </div> -->

    <?php } ?>
    <br/>

    <div class="art-content-layout">
        <div class="art-content-layout-row">

            <div class="art-layout-cell layout-item-0" style="width: 100%">

                <marquee behavior="alternate" scrolldelay="200" onmouseover="this.setAttribute('scrollamount',0,0);"
                         onmouseout="this.setAttribute('scrollamount',6,0);">
                    <div style="color:#F00; font-style:italic; font-weight:bolder;">NOTE: <span
                                style="color:#F00; font-style:italic;">Register by clicking on your preferred courses</span>
                    </div>
                </marquee>


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


    <div class="art-content-layout">
        <div class="art-content-layout-row">

            <div class="art-layout-cell layout-item-0" style="width: 100%">


                <div style="text-transform:uppercase; color:#099; font-weight:bolder; border-bottom:inset #000 thin;">
                    semester courses
                </div>
                <!--<hr style="width:100%;">
                <br />-->
                <?php if ($message != "") {
                    echo output_message($message);
                } else {
                    echo "<br/>";
                }
                //$message =$transaction->responsecode;

                ?>

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


    <?php
    if ((($clevel == "ND I") or ($clevel == "HND I")or ($clevel == "PGD I")) )
    { 
        ?>

<script>//alert('My data');</script>

        <div class="art-content-layout">
            <div class="art-content-layout-row" align="center">
                <div class="art-layout-cell layout-item-0" style="width: 100%; margin:0; padding:0;">
                    <div>
                    </div>

                    <!--Left column-->
                    <h3 style="color:#033;"><?php echo trim(ucwords($s)); ?> Semester Courses</h3>
                    <form method="post" id="insert_data">
                        <table id="mytable2" border="2" align="center" class="">
                            <tr>
                                <th>Course Code</th>
                                <th>Course Title</th>
                                <th>Status</th>
                                <th>Unit</th>
                                <th>Select First<input type="checkbox" name="selectAll" id="selectAll" class="check-tab2"/>
                                </th>
                            </tr>

                            <?php foreach ($display_course as $display_cours)
                                echo '<tr>'
                                    . '<td>' . $display_cours->course_code . '</td>'
                                    . '<td>' . $display_cours->course_title . '</td>'
                                    . '<td>' . $display_cours->course_status . '</td>'
                                    . '<td>' . $display_cours->course_unit . '</td>'
                                    . '<td><input type="checkbox" class="check-tab2" name="check-tab2" value = ' . $display_cours->course_code . '</td>'
                                    . '</tr>'; ?>

                        </table>
                        <div id = "sum_unit">
                        </div>
                        <h6>C = Compulsory Courses</h6>
                        <h6>E = Elective Course(s)</h6>
                        <br/>
                        <input type="submit" name="register" id="register" class="btn btn-info" value="Register"
                               align="center"/>
                        <!--<form method="post" action="Report.php" id="print">-->
                        <!--  <input type="submit" name="print" id="print" clas="btn btn-info" value="Print" align="center" />
                      <!--</form>-->

                        <!-- </form>
                        </div>
                    </div>-->
                </div>


            </div>


        </div>

        <?php
    }
    else if ((($clevel == "ND II") or ($clevel == "HND II") or ($clevel == "PGD II")))
    { 
    ?>

    <!-- left column for ND II and HND II-->
    
    <!--<marquee behavior="alternate" scrolldelay="200" onmouseover="this.setAttribute('scrollamount',0,0);"
                         onmouseout="this.setAttribute('scrollamount',6,0);"> -->
                    <div style="color:#F00; font-style:italic; font-weight:bolder;">NOTE: <span
                                style="color:#F00; font-style:italic;">Select your carry-over course(s) (if any) then click the "Add button" to add it to your "Current Semester Courses"</span><br>
                                <span
                                style="color:#F00; font-style:italic;">Click the "Remove button" to remove Course(s) from "Current Semester Courses"</span>
                    </div>
                <!--</marquee>-->

    <div class="art-content-layout">
        <div class="art-content-layout-row">
            <div class="art-layout-cell layout-item-0" style="width: 45%; margin:0; padding:0;">
                <div>
                </div>

                <!-- Left column-->
                <h3 style="color:#033;">Current Semester Courses</h3>
                <!--<form method="post" id="insert_data">-->
                    <table id="mytable2" border="2" align="center" class="">
                        <tr>
                            <th>Course Code</th>
                            <th>Course Title</th>
                            <th>Status</th>
                            <th>Unit</th>
                            <th>Select<input type="checkbox" name="selectAll" id="selectAll" class="check-tab2"/></th>
                        </tr>
                        <?php    
                            if ($clevel == 'HND II') {$level = 'HND I';}
                            else if ($clevel == 'ND II') {$level = 'ND I';}
                            
                         // echo  $biodata->courses.''.$level.' '. $semester;
                         
                         $display_course = COURSECLASS::fetch_all_course($biodata->courses, $clevel, $semester);

                            $display_course_prev = COURSECLASS::fetch_all_course($biodata->courses, $level, $semester);

                        foreach ($display_course as $display_cours)
                            echo '<tr>'
                                . '<td>' . $display_cours->course_code . '</td>'
                                . '<td>' . $display_cours->course_title . '</td>'
                                . '<td>' . $display_cours->course_status . '</td>'
                                . '<td>' . $display_cours->course_unit . '</td>'
                                . '<td><input type="checkbox" class="check-tab2" name="check-tab2" value = ' . $display_cours->course_code . '</td>'
                                . '</tr>'; ?>

                    </table>
                    <br/>
                    <input type="submit" name="register" id="register" class="btn btn-info" value="Register"
                           align="center"/><br>
                    <button onclick="tab2_To_tab1();"><< Remove</button>

            </div>
           
            <!-- The left column for ND II and HND II ends here-->


            <div class="art-layout-cell layout-item-0" style="width: 45%">

                <!--right column-->

                <h3 style="color:#033;">Lower-Level Semester Courses</h3>
                <table id="mytable" class="" align="left" border="2">
                    <thead>
                    <tr>
                        <th>Course Code</th>
                        <th>Course Title</th>
                        <th>Status</th>
                        <th>Unit</th>
                        <th>Select</th>
                    </tr>
                    </thead>
                    
                    <?php foreach ($display_course_prev as $display_cours)
                            echo '<tr>'
                                . '<td>' . $display_cours->course_code . '</td>'
                                . '<td>' . $display_cours->course_title . '</td>'
                                . '<td>' . $display_cours->course_status . '</td>'
                                . '<td>' . $display_cours->course_unit . '</td>'
                                 . '<td><input type="checkbox" name="check-tab1"></td>'
                                // . '<td><input type="checkbox" class="check-tab2" name="check-tab2" value = ' . $display_cours->course_code . '</td>'
                                . '</tr>'; ?>
                    
                </table><br><br>
                 <div class="tab tab-btn">
                    <button onclick="tab1_To_tab2();"> << Add</button>
                </div>
            </div>
        </div>
    </div>
</div>

<?php }

else {

    if (($msgs1==1) AND ($msgs2==2)){
        
        $msgs='Registration completed for this session';
    }
echo '<h4 style="color:red; text-align:center; font-weight:bolder">'.$msgs.'</h4>';
 }?>

</article></div>
<style>
    #accept:hover {
        text-decoration: none;
        font-style: italic;
    }
</style>

<script src="../javascripts/jquery.min.js"></script>
<script src="../javascripts/bootstrap.min.js" type="text/javascript"></script>



<script type="text/javascript">





    $(document).ready(function () {
        
        //alert('semese');
        $('#semester').change(function () {
            if ($(this).val() != '') {
                var department = $('#department').val();
                var level = $('#level').val();
                var semester = $('#semester').val();
                alert(department + level + semester);
                {
                    $.ajax({
                        method: "POST",
                        url: "fetch_courses.php",
                        data: {department: department, level: level, semester: semester},
                        success: function (data) {
                            alert(data);
                            $('#mytable').html(data);
                        }
                    })
                }
            }
        });
        
         
         
          $('#selectAll').on('click', function (e) {
            
           //alert('Clicked');
           
            if (this.checked) {
                $('.check-tab2').each(function () {
                    this.checked = true;
                });
            } else {
                $('.check-tab2').each(function () {
                    this.checked = false;
                });
            }
        })




            
            $('#register').on('click', function (e) {
            
           // alert('Flikddd');
            e.preventDefault(e);
            var table2 = document.getElementById("mytable2"),
                checkboxes = document.getElementsByName("check-tab2"),
                course_code = "",
                count = 0;
            for (var i = 0; i < checkboxes.length; i++) {
                if (checkboxes[i].checked) {
                    course_code += table2.rows[i + 1].cells[0].innerHTML + ',';
                }
            }
            if (course_code == "") {
                alert("Please Select Courses");
            }
             else {
                 
                // alert(course_code);
                $.ajax({
                    method: "GET",
                    url: "insert_courses.php",
                    data: {course_code: course_code},
                    success: function (data) {
                          alert(data);
                        if (data == "Year I Registration Successful") 
                        {
                            //alert(semester);
                            $('#register').attr('disabled', 'disabled');
                          // window.open('Report.php'); 
                         // window.open('/dashboard.php');
                         alert('First Semester Registration Completed Successfully');
                         
                          
                          window.location.replace('https://eportal.oscotechesaoke.edu.ng/student_portal/dashboard.php?type=1'); 
   
                             $('#register').attr('disabled', 'disabled');
                            
                        }else if (data == "Year II Registration Successful"){
                            //alert(semester);
                            $('#register').attr('disabled', 'disabled');
                          // window.open('Report.php'); 
                         // window.open('/dashboard.php');
                         alert('First Semester Registration Completed Successfully');
                         
                          
                          window.location.replace('https://eportal.oscotechesaoke.edu.ng/student_portal/dashboard.php?type=2'); 
   
                             $('#register').attr('disabled', 'disabled');
                             
                        }else {
                            alert(data);
                        }
                    }

                })
             }
        })
  
   



    });


        
        
         function tab1_To_tab2() {
        var table1 = document.getElementById("mytable"),
            table2 = document.getElementById("mytable2"),
            checkboxes = document.getElementsByName("check-tab1");
        for (var i = 0; i < checkboxes.length; i++)
            if (checkboxes[i].checked) {
                // create new row and cells
                var newRow = table2.insertRow(table2.length),
                    cell1 = newRow.insertCell(0),
                    cell2 = newRow.insertCell(1),
                    cell3 = newRow.insertCell(2),
                    cell4 = newRow.insertCell(3);
                    cell5 = newRow.insertCell(4);
                // add values to the cells
                cell1.innerHTML = table1.rows[i + 1].cells[0].innerHTML;
                cell2.innerHTML = table1.rows[i + 1].cells[1].innerHTML;
                cell3.innerHTML = table1.rows[i + 1].cells[2].innerHTML;
                cell4.innerHTML = table1.rows[i + 1].cells[3].innerHTML;
                cell5.innerHTML = "<input type='checkbox' name='check-tab2' value = 'cell1.innerHTML'>";
                console.log(cell1.innerHTML);
                var index = table1.rows[i+1].rowIndex;
                table1.deleteRow(index);                
                i--;
            }
    }


    function tab2_To_tab1() {
        var table1 = document.getElementById("mytable"),
            table2 = document.getElementById("mytable2"),
            checkboxes = document.getElementsByName("check-tab2");
        for (var i = 0; i < checkboxes.length; i++)
            if (checkboxes[i].checked) {
                var index = table2.rows[i + 1].rowIndex;
                table2.deleteRow(index);

                i--;
            }
    }


















</script>        
                
                
    
<?php //redirect_to('https://eportal.oscotechesaoke.edu.ng/student_portal/dashboard.php?type=1'); ?>
   
          
