<?php
session_start();
require('core/connection.php');
if(!logged_in()){
redirect('index.php');
}
$username = $_SESSION['username'];
$id = $_SESSION['admin_id'];
$id2 = $_SESSION['admin_id2'];
$validate = $_SESSION['validating'];
$priviledges = $_SESSION['priviledge'];

if ($priviledges == "lecturer" || $priviledges == "student") {
  $logging = "yespls";
}else{
  $logging = "nopls";
}
if(!logged_in() || $logging == "nopls"){
redirect('index.php');
}

$select = $conn->query("SELECT * FROM semester LIMIT 1");
$fetch = $select->fetchAll(PDO::FETCH_OBJ);
$count = $select->rowCount();
if ($count > 0) {
  foreach ($fetch as $value2) {
    $activesemester = $value2->active;
  }
} 


if ($priviledges == 'student') {
$select = $conn->query("SELECT * FROM students WHERE id = '$id2' LIMIT 1");
$fetch = $select->fetchAll(PDO::FETCH_OBJ);
$count = $select->rowCount();
if ($count > 0) {
  foreach ($fetch as $value) {
    $dept = $value->dept;
    $matric = $value->matric;
    $level = $value->level;
  }
} 

}

if (isset($_GET['link'])) {
 $vlink = $_GET['link'];
}

if (isset($_GET['link2'])) {
 $vlink2 = $_GET['link2'];
}
?>

<?php
if (isset($_POST['uppro'])) {
  $email = $_POST['email'];
  $phone = $_POST['phone'];
  $file = $_FILES['pfile']['tmp_name'];
  if (empty($email) || empty($phone) || empty($file)) {
    echo "<script>alert('Please input all empty fields')</script>";


  }else{

    $temporary = explode("." , $_FILES [ "pfile" ][ "name" ]);
        $file_extension = end ($temporary );
        $pic = $_FILES['pfile']['name'];
        $picp = $_FILES['pfile']['tmp_name'];
        $pics = $_FILES['pfile']['size'];


        $hash = sha1($pic);
        $random = rand(000,999);
        $comb = $hash.$random;

        $ext1 = pathinfo($pic, PATHINFO_EXTENSION);
        $ext1 = strtolower($ext1);

        $upload_folder1 = "profile/".$comb.".".$ext1;
        $uploadpic = $comb.".".$ext1;

        $validextensions = array('png','jpeg','jpg','gif','PNG','JPEG','JPG','GIF');
        if (in_array($ext1, $validextensions) == false) {
          echo "<script>alert('Please input a valid extension')</script>";
        }else{
    $in = array('image' => $uploadpic,
          'phone' => $phone,
          'email' => $email,
    );
    move_uploaded_file($picp, $upload_folder1);
    update('lecturers',$in,'id',$id2);
    echo "<script>alert('You have successfully updated your profile')</script>";

      
      }
    
  }
 }

if ($priviledges == 'lecturer') {
$select2 = $conn->query("SELECT * FROM lecturers WHERE id = '$id2' ");
            $fetch2 = $select2->fetchAll(PDO::FETCH_OBJ);
            $count2 = $select2->rowCount();
            if ($count2 > 0) {
              foreach ($fetch2 as $value2) {
                $limageh = $value2->image;
                $lemailh = $value2->email;
                $lphoneh = $value2->phone;

              }
            }
}
?>
<!DOCTYPE html>
<html lang="en">
  <?php
  include('inc/header.php');
  ?>
  <script type="text/javascript">

    function pro(){
      document.getElementById('side').hidden = true;
      document.getElementById('side3').hidden = true;
    
    }
  </script>
    <script>
    if ( window.history.replaceState ) {
        window.history.replaceState( null, null, window.location.href );
    }
</script>
  <body class="nav-md" >
    <div class="container body">
      <div class="main_container">
        <div class="col-md-3 left_col" id="side">
          <div class="left_col scroll-view" id="side2">
            <div class="navbar nav_title" style="border: 0;">
              <a href="index.php" class="site_title"><i class="fa fa-dashboard"></i> <span>Admin</span></a>
            </div>

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

            <!-- menu profile quick info -->
            <div class="profile clearfix">
              <div class="profile_pic">
                <img src="images/user.png" alt="..." class="img-circle profile_img">
              </div>
              <div class="profile_info">
                <span>Welcome,</span>
                <h2><?php echo "$username"; ?></h2>
              </div>
            </div>
            <!-- /menu profile quick info -->

            <br />

            <!-- sidebar menu -->
            <div id="sidebar-menu" class="main_menu_side hidden-print main_menu">
              <div class="menu_section">
                <h3><?php echo "$priviledges ";?></h3>
                <?php
                  if ($priviledges == 'student') {
                 include('inc/sidemenu1.php');
                  }elseif ($priviledges == 'lecturer') {
                  include('inc/sidemenu2.php');
                  }
                  ?>
              </div>
            </div>
            <!-- /sidebar menu -->

            <!-- /menu footer buttons -->
            <div class="sidebar-footer hidden-small" id="process1">
              <a data-toggle="tooltip" data-placement="top" title="Logout" href="logout.php">
                <span class="glyphicon glyphicon-off" aria-hidden="true"></span>
              </a>
            </div>
            <!-- /menu footer buttons -->
          </div>
        </div>

        <!-- top navigation -->
        <div class="top_nav" >
          <div class="nav_menu" id="side3">
            <nav>
              <div class="nav toggle">
                <a id="menu_toggle"><i class="fa fa-bars"></i></a>
              </div>

              <ul class="nav navbar-nav navbar-right">
                <li class="">
                  <a href="javascript:;" class="user-profile dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                    <img src="images/user.png" alt=""><?php echo "$username"; ?>
                    <span class=" fa fa-angle-down"></span>
                  </a>
                  <ul class="dropdown-menu dropdown-usermenu pull-right">
                    <li><a data-toggle="modal" data-target="#updatethis2"><i class="fa fa-lock pull-right"></i> Update Password</a></li>
                    <?php
                    if ($priviledges == 'lecturer') {
                    ?>
                <li><a data-toggle="modal" data-target="#lecturer2"><i class="fa fa-plus pull-right"></i> Update Profile</a></li>
                    <?php
                    }
                    ?>
                    <li><a href="logout.php"><i class="fa fa-sign-out pull-right"></i> Log Out</a></li>
                    
                  </ul>
                </li>

                <li role="presentation" class="dropdown">
                  <a href="?mod=desk&link=load" class="dropdown-toggle info-number">
                  <i class="fa fa-envelope-o"></i>
                  <div id="acheck">
                    
                  </div>
                  
                  </a>  
                </li>
              </ul>
            </nav>
          </div>
        </div>
        <!-- /top navigation -->

            <div class="modal fade" id="lecturer2" role="dialog">
            <div class="modal-dialog modal-sm">
              <div class="modal-content">
                <div class="modal-body text-center">
                  <div class="panel panel-default">
                    <div class="panel-body">
                      <form method="post" enctype="multipart/form-data">
                        <?php
                        if (!empty($limageh)) {
                        ?>
                        <img src="profile/<?php echo $limageh ?>" width="120px">
                        <?php
                        }
                        ?>
                        <div class="form-group">
                          <label for="pfile">
                            Profile Pic
                          </label>
                          <input type="file" name="pfile" required class="form-control" accept="image/*" id="pfile">
                        </div>
                        <div class="form-group">
                          <label for="email">
                            Email
                          </label>
                          <input type="email" name="email" required class="form-control" accept="image/*" id="email" value="<?php echo $lemailh ?>">
                        </div>
                        <div class="form-group">
                          <label for="phone">
                            Phone Number
                          </label>
                          <input type="text" name="phone" required class="form-control" accept="image/*" id="phone" value="<?php echo $lphoneh ?>">
                        </div>
                        
                      
                    </div>
                 </div> 
                </div>
                <div class="modal-footer">
                  <button type="submit" class="btn btn-default" name="uppro">Ok</button>
                </div>
                </form>
              </div>
            </div>
          </div>

        <!-- page content -->
        <?php
        if (isset($_GET['mod']) && $_GET['mod'] == 'category' && isset($_GET['link']) && $_GET['link'] == 'faculty') {
        include 'inc/faculty.php';
         }elseif (isset($_GET['mod']) && $_GET['mod'] == 'category' && isset($_GET['link']) && $_GET['link'] == 'department') {
        include 'inc/department.php';
         }elseif (isset($_GET['mod']) && $_GET['mod'] == 'category' && isset($_GET['link']) && $_GET['link'] == 'course') {
        include 'inc/course.php';
         }elseif (isset($_GET['mod']) && $_GET['mod'] == 'book' && isset($_GET['link']) && $_GET['link'] == 'add') {
        include 'pages/addbook.php';
         }elseif (isset($_GET['mod']) && $_GET['mod'] == 'book' && isset($_GET['link']) && $_GET['link'] == 'view') {
        include 'pages/viewbooks.php';
         }elseif (isset($_GET['mod']) && $_GET['mod'] == 'staff' && isset($_GET['link']) && $_GET['link'] == 'add') {
        include 'pages/addstaff.php';
         }elseif (isset($_GET['mod']) && $_GET['mod'] == 'staff' && isset($_GET['link']) && $_GET['link'] == 'view') {
        include 'pages/viewstaff.php';
         }elseif (isset($_GET['mod']) && $_GET['mod'] == 'lecturer' && isset($_GET['link']) && $_GET['link'] == 'add') {
        include 'pages/addlecturer.php';
         }elseif (isset($_GET['mod']) && $_GET['mod'] == 'lecturer' && isset($_GET['link']) && $_GET['link'] == 'view') {
        include 'pages/viewlecturer.php';
         }elseif (isset($_GET['mod']) && $_GET['mod'] == 'student' && isset($_GET['link']) && $_GET['link'] == 'add') {
        include 'pages/addstudent.php';
         }elseif (isset($_GET['mod']) && $_GET['mod'] == 'student' && isset($_GET['link']) && $_GET['link'] == 'view') {
        include 'pages/viewstudent.php';
         }elseif (isset($_GET['mod']) && $_GET['mod'] == 'hstudent' && isset($_GET['link']) && $_GET['link'] == 'add') {
        include 'pages/addhstudent.php';
         }elseif (isset($_GET['mod']) && $_GET['mod'] == 'hstudent' && isset($_GET['link']) && $_GET['link'] == 'view') {
        include 'pages/viewhstudent.php';
         }elseif (isset($_GET['mod']) && $_GET['mod'] == 'class' && isset($_GET['link']) && $_GET['link'] == 'add') {
        include 'pages/addclass.php';
         }elseif (isset($_GET['mod']) && $_GET['mod'] == 'class' && isset($_GET['link']) && $_GET['link'] == 'view') {
        include 'pages/viewclass.php';
         }elseif (isset($_GET['mod']) && $_GET['mod'] == 'courses' && isset($_GET['link']) && $_GET['link'] == 'register') {
        include 'pages/registercourses.php';
         }elseif (isset($_GET['mod']) && $_GET['mod'] == 'courses' && isset($_GET['link']) && $_GET['link'] == 'over') {
        include 'pages/registerocourses.php';
         }elseif (isset($_GET['mod']) && $_GET['mod'] == 'desk' && isset($_GET['link']) && $_GET['link'] == 'load') {
        include 'pages/helpdesk.php';
         }elseif (isset($_GET['mod']) && $_GET['mod'] == 'hstudent') {
        include 'inc/classes.php';
         }elseif (isset($_GET['mod']) && $_GET['mod'] == 'hlecturer') {
        include 'inc/lclasses.php';
         }else{ 
        include 'pages/main.php';
      }
        ?>
        <!-- /page content -->
        <?php
        include('inc/footer.php');
        ?>
         </body>
</html>