<?php
if (isset($_GET['link']) && (!empty($_GET['link'])) && $_GET['link'] != 0) {
$select0 = $conn->query("SELECT * FROM students WHERE id = '$id2'");
      $fetch = $select0->fetchAll(PDO::FETCH_OBJ);
      $count = $select0->rowCount();
      $serial = 1;
      if ($count > 0) {
        foreach ($fetch as $value) {
          $stuid = $value->id;
          $sname = $value->sname;
          $oname = $value->oname;
          $matric = $value->matric;
        }
      }

$select0 = $conn->query("SELECT * FROM stp WHERE studentid = '$id2' AND packageid = '$vlink'");
      $fetch = $select0->fetchAll(PDO::FETCH_OBJ);
      $count = $select0->rowCount();
      $serial = 1;
      if ($count > 0) {
        foreach ($fetch as $value) {
          $packageid = $value->packageid;

$select = $conn->query("SELECT * FROM package WHERE id = '$packageid'");
      $fetch = $select->fetchAll(PDO::FETCH_OBJ);
      $count = $select->rowCount();
      $serial = 1;
      if ($count > 0) {
        foreach ($fetch as $value) {
          $piden = $value->id;
          $level = $value->level;
          $semester = $value->semester;
          $course = $value->course;
          $lecturer = $value->lecturer;

     $select2 = $conn->query("SELECT * FROM course WHERE id = '$course' LIMIT 1");
            $fetch2 = $select2->fetchAll(PDO::FETCH_OBJ);
            $count2 = $select2->rowCount();
            if ($count2 > 0) {
              foreach ($fetch2 as $value2) {
                $name2 = $value2->name;
                $code2 = $value2->code;
              }
            } 
        $select2 = $conn->query("SELECT * FROM lecturers WHERE id = '$lecturer' ");
            $fetch2 = $select2->fetchAll(PDO::FETCH_OBJ);
            $count2 = $select2->rowCount();
            if ($count2 > 0) {
              foreach ($fetch2 as $value2) {
                $sname = $value2->sname;
                $oname = $value2->oname;
                $limage = $value2->image;
                $lemail = $value2->email;
                $lphone = $value2->phone;

                if (!empty($lemail)) {
                  $lemail = "Email: $lemail";
                }

                if (!empty($lphone)) {
                  $lphone = "Phone Number: $lphone";
                }
              }
            }
            }
            } 
          }
        }
?>
<script type="text/javascript">
  $(document).ready(function(){
    var package = <?php echo "$vlink"; ?>;
    var student = <?php echo "$id2"; ?>;
    setInterval(function() {
    var dataString = "id="+package+"&iden="+student+"&action=loadnotify";
    $.ajax({
        type: "POST",
        url: "control.php",
        cache : false,
        data : dataString,
        beforeSend : function(){
           
        },
        success : function(response){
          if (response > 0) {
            $("#noti").show();
            $("#innoti").html(response);
          }
        }
    });
  }, 2000);

  });
</script>
<!-- page content -->
        <div class="right_col" role="main">
          <div class="">
            <div class="page-title">
              <div class="title_left">
                <h3><a href="main.php">Dashboard</a>/<a href=" "><?php echo "$name2 ($code2) by $sname $oname" ?></a> <button class="btn btn-default" data-toggle="modal" data-target="#lecturer">View Lecturer's Profile</button> </h3>
              </div>
            </div>

            <div class="clearfix"></div>

            <div class="modal fade" id="lecturer" role="dialog">
            <div class="modal-dialog modal-md">
              <div class="modal-content">
                <div class="modal-body">
                  <div class="panel panel-default">
                    <div class="panel-body">
                      <?php
                      if (empty($limage)) {
                      ?>
                        <img src="images/user.png" alt="..." class="img-circle profile_img">
                      <?php
                      }else{
                      ?>
                      <img src="profile/<?php echo $limage ?>" alt="..." class="img-circle profile_img" style="width: 150px; margin: auto;">
                      <?php
                      }
                      ?>
                          
                          <h3><?php echo "$sname $oname"; ?></h3>
                          <h3><?php echo "$lphone"; ?></h3>
                          <h3><?php echo "$lemail"; ?></h3>
                    </div>
                 </div> 
                </div>
                <div class="modal-footer">
                  <button type="button" class="btn btn-default" data-dismiss="modal">Ok</button>
                </div>
              </div>
            </div>
          </div>

            <div class="row">
              <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <div class="row">
                      <div class="col-md-2 col-xs-6 col-sm-3">
                        <a href="?mod=hstudent&link=<?php echo $vlink ?>&action=viewannouncements"><button class="btn btn-success btn-block <?php if(isset($_GET['action']) && $_GET['action'] == "viewannouncements"){ echo "active";} ?>">Announcements <sup id="noti" style="display: none"><span id="innoti" style="background: #9c2e2e; color: white; border: 6px solid #9c2e2e; border-radius: 20px;"></span></sup></button></a>
                      </div>
                      <div class="col-md-2 col-xs-6 col-sm-3">
                        <a href="?mod=hstudent&link=<?php echo $vlink ?>&action=virtual"><button class="btn btn-success btn-block <?php if(isset($_GET['action']) && $_GET['action'] == "virtual"){ echo "active";} ?>">Virtual Class</button></a>
                      </div>
                      <div class="col-md-1 col-xs-6 col-sm-3">
                        <a href="?mod=hstudent&link=<?php echo $vlink ?>&action=notes"><button class="btn btn-success btn-block <?php if(isset($_GET['action']) && $_GET['action'] == "notes"){ echo "active";} ?>">Notes</button></a>
                      </div>
                      <div class="col-md-2 col-xs-6 col-sm-3">
                        <a href="?mod=hstudent&link=<?php echo $vlink ?>&action=slides"><button class="btn btn-success btn-block <?php if(isset($_GET['action']) && $_GET['action'] == "slides"){ echo "active";} ?>">Course Materials</button></a>
                      </div>
                      <div class="col-md-1 col-xs-6 col-sm-3">
                        <a href="?mod=hstudent&link=<?php echo $vlink ?>&action=audios"><button class="btn btn-success btn-block <?php if(isset($_GET['action']) && $_GET['action'] == "audios"){ echo "active";} ?>">Audios</button></a>
                      </div>
                      <div class="col-md-1 col-xs-6 col-sm-3">
                        <a href="?mod=hstudent&link=<?php echo $vlink ?>&action=videos"><button class="btn btn-success btn-block <?php if(isset($_GET['action']) && $_GET['action'] == "videos"){ echo "active";} ?>">Videos</button></a>
                      </div>
                      <div class="col-md-2 col-xs-6 col-sm-3">
                        <a href="?mod=hstudent&link=<?php echo $vlink ?>&action=viewassignments"><button class="btn btn-success btn-block <?php if(isset($_GET['action']) && $_GET['action'] == "viewassignments"){ echo "active";} ?>">Assignments</button></a>
                      </div>
                      <div class="col-md-1 col-xs-6 col-sm-3">
                        <a href="?mod=hstudent&link=<?php echo $vlink ?>&action=coursenames"><button class="btn btn-success btn-block <?php if(isset($_GET['action']) && $_GET['action'] == "coursenames"){ echo "active";} ?>">Course <br> Mates</button></a>
                      </div>
                    </div>
                    
                    <div class="clearfix"></div>
                  </div>
<?php
if(isset($_GET['action']) && $_GET['action'] == "coursemates"){
include('pages/coursemates.php');
}elseif (isset($_GET['action']) && $_GET['action'] == "notes") {
include('pages/viewnotes.php');
}elseif (isset($_GET['action']) && $_GET['action'] == "slides") {
include('pages/viewslides.php');
}elseif (isset($_GET['action']) && $_GET['action'] == "audios") {
include('pages/viewaudio.php');
}elseif (isset($_GET['action']) && $_GET['action'] == "videos") {
include('pages/viewvideo.php');
}elseif (isset($_GET['action']) && $_GET['action'] == "virtual") {
include('pages/virtual.php');
}elseif (isset($_GET['action']) && $_GET['action'] == "viewassignments") {
include('pages/viewassignments.php');
}elseif (isset($_GET['action']) && $_GET['action'] == "viewannouncements") {
include('pages/viewannouncement.php');
}else{
  include('pages/coursemates.php');  
}
?>
                            
                    
                  </div>
                </div>
              </div>
            </div>
          </div>
        <!-- /page content -->

<?php
}else{
?>
<!-- page content -->
        <div class="right_col" role="main">
          <div class="">
            <div class="page-title">
              <div class="title_left">
                <h3><a href="main.php">Dashboard</a>/<a href=" ">Classes</a></h3>
              </div>
            </div>

            <div class="clearfix"></div>

            <div class="row">
              <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <div class="row">
                        <h1>Error: Page not Found... Go back home</h1>
                    </div>
                    
                    <div class="clearfix"></div>
                  </div>                           
                    
                  </div>
                </div>
              </div>
            </div>
          </div>
        <!-- /page content -->

<?php
}
?>
