<?php
	ob_start();
?>
<?php
	require_once("../../public/teacher_session.php");
	require_once("../../public/connection.php");
	require_once("../../public/functions.php");
	//require_once("staff_dashboard_processor.php");
?>
<?php
    if(!isset($_SESSION['teacher'])){
        exit('STOP DOING THAT');
    }
?>
<?php
	//////////////// DEFAULT NULL VALUES ///////////////
	date_default_timezone_set('Africa/Lagos');
	$date = date('d-M-Y');
	$select = "--select--";
	$oge = time();
	$time = date('H:i:s', $oge);
	$error = array();
	$year = date('Y');
?>
<?php
	//////////////////// GET USERS DATA FROM DATABASE AND DISPLAY IT ON DASHBOARD IF LOGIN IS SUCCESSFUL USING SESSION FROM LOGIN PAGE ////////////////
	$query = " SELECT * FROM `teachers` WHERE id = '{$_SESSION['teacher']}' ";
	$run_query = mysqli_query($connection, $query);
	if(mysqli_num_rows($run_query) == 1){
		while($result = mysqli_fetch_assoc($run_query)){
			$teacher_id = $result['id'];
			$teacher_username = $result['username'];
			$name = ucfirst($result['name']);
			$teacher_name = $name;
			$teacher_address = ucwords($result['address']);
			$teacher_phone = $result['phone'];
			$teacher_state = ucwords($result['state']);
			$teacher_lga = ucwords($result['lga']);
			$teacher_country = ucwords($result['country']);
            $sex = $result['sex'];
			$teacher_email = $result['email'];
            $teacher_status = $result['status'];
			$teacher_passport = "./".$result['passport'];
            $position = $result['teacher_position'];
            $date_registered = $result['date_registered'];
		}
	}
?>
<?php
    ////////// POST ACTION TO VIEW ALL THE UPLOADED ADMINISTRATIVE INFORMATION ////////////
    $query = " SELECT * FROM `administratives` ";
    $run_query = mysqli_query($connection, $query);

    if(mysqli_num_rows($run_query) > 0){
        while($result = mysqli_fetch_assoc($run_query)){
            $administratives_id = $result['id'];
            $admin_name = $result['school_name'];
            $admin_motto = $result['school_motto'];
            $admin_logo = $result['school_logo'];
            $admin_stamp = $result['school_stamp'];
            //echo "<img src='$admin_logo' />";
        }
    }
?>
<?php
    $query = " SELECT * FROM `current_season` ";
    $run_query = mysqli_query($connection, $query);
    if(mysqli_num_rows($run_query) == 1){
        while($result = mysqli_fetch_assoc($run_query)){
            $current_term = $result['current_term'];
            $current_session = $result['current_session'];
        }
    }
?>

<?php
	function abbreviateName($teacher_name) {
		// Split the name into words
		$words = explode(" ", $teacher_name);
		
		// If there are two words or less, return the name as is
		if (count($words) <= 2) {
			return $teacher_name;
		}
		
		// Abbreviate the first part of the name and keep the last word
		$abbreviated = "";
		for ($i = 0; $i < count($words) - 1; $i++) {
			$abbreviated .= strtoupper($words[$i][0]) . ". ";
		}
		
		// Add the last word in full
		$abbreviated .= end($words);
		
		return $abbreviated;
	}
?>


<!DOCTYPE html>
<html>
  <head>
    <meta charset='utf-8'>
    <meta charset='utf-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <meta name='viewport' content='width=device-width, initial-scale=1'>
    <link rel='stylesheet' type='text/css' href='../../assets/css/main.css'>
    <link rel='stylesheet' type='text/css' href='../../assets/css/defined.css'>
	<link id="favicon" rel="icon" type="image/png" sizes="8x8" href="../../images/145.png">
    <!-- Font-icon css-->
    <link rel="stylesheet" href="../../assets/css/font-awesome-4.7.0/css/font-awesome.css">
    <title><?php echo $name; ?> ~ School Portal</title>
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries-->
    <!--if lt IE 9
    script(src='https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js')
    script(src='https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js')
    -->
    <script type="text/javascript">
        window.onload = initClock;

        function initClock() {
          var now = new Date();
          var hr  = now.getHours();
          var min = now.getMinutes();
          var sec = now.getSeconds();
          if (min < 10) min = "0" + min;  // insert a leading zero
          if (sec < 10) sec = "0" + sec;
          document.getElementById('clockDisplay').innerHTML
                = hr + ":" + min + ":" + sec;
          setTimeout('initClock()', 500);
        }
    </script>
  </head>
  <body class='sidebar-mini fixed'>
    <div class='wrapper'>
      <!-- Navbar-->
      <header class='main-header hidden-print'><a class='logo' href='#'>School Portal</a>
        <nav class='navbar navbar-static-top'>
          <!-- Sidebar toggle button--><a class='sidebar-toggle' href='#' data-toggle='offcanvas'></a>
          <!-- Navbar Right Menu-->
          <div class='navbar-custom-menu'>
            <ul class='top-nav'>
              <!--Notification Menu-->
                <li class='dropdown notification-menu'><a class='dropdown-toggle' href='#' data-toggle='dropdown' aria-expanded='false'><?php echo $date; ?> <span id='clockDisplay'></span></a>
              </li>
              <!-- User Menu-->
              <li class='dropdown'><a class='dropdown-toggle' href='#' data-toggle='dropdown' role='button' aria-haspopup='true' aria-expanded='false'><i class='fa fa-user fa-lg'></i></a>
                <ul class='dropdown-menu settings-menu'>
                  <li><a href='teacher_dashboard.php?teacher_profile''><i class='fa fa-user fa-lg'></i> Profile</a></li>
                  <li><a href='teacher_dashboard.php?logout'><i class='fa fa-sign-out fa-lg'></i> Logout</a></li>
                </ul>
              </li>
            </ul>
          </div>
        </nav>
      </header>
      <!-- Side-Nav-->
      <aside class='main-sidebar hidden-print'>
        <section class='sidebar'>
          <div class='user-panel'>
            <div class='pull-left image'><img class='img-circle' src= '<?php echo $teacher_passport; ?>' alt='User Image'></div>
            <div class='pull-left info'>
              <p class='text-center'><?php echo $teacher_username; ?></p>
              <p class='designation text-center'><?php echo $position; ?></p>
            </div>
          </div>
          <!-- Sidebar Menu-->
          <ul class='sidebar-menu'>
            <li class='active'><a href='teacher_dashboard.php?dashboard'><i class='fa fa-dashboard'></i><span>Dashboard</span></a></li>
            <li><a href='teacher_dashboard.php?teacher_profile'><i class='fa fa-user'></i><span>Profile</span></a></li>
            <li><a href='teacher_dashboard.php?lesson_plans'><i class='fa fa-user'></i><span>Lesson Plans</span></a></li>
			<?php
				if ($position == 'Class Teacher') {
			?>
				<li><a href='teacher_dashboard.php?teacher_upload_attendance'><i class='fa fa-pie-chart'></i><span>Class Attendance</span></a></li>
				<li><a href='teacher_dashboard.php?teacher_view_attendance'><i class='fa fa-eye'></i><span>View Attendance Records</span></a></li>
				
				<li class='treeview'>
					<a href='#'><i class='fa fa-edit'></i><span>Behavioral Analysis</span><i class='fa fa-angle-right'></i></a>
					<ul class='treeview-menu'>
						<li><a href='teacher_dashboard.php?teacher_upload_conduct'><i class='fa fa-circle-o'></i> Manually Handled</a></li>
						<li><a href='teacher_dashboard.php?teacher_view_conduct'><i class='fa fa-circle-o'></i> View Uploaded Behavioral</a></li>
					</ul>
				</li>

				<li><a href='teacher_dashboard.php?view_students'><i class='fa fa-eye'></i><span>View Students</span></a></li>

				<li class='treeview'>
					<a href='#'><i class='fa fa-file-text'></i><span>Subject Management</span><i class='fa fa-angle-right'></i></a>
					<ul class='treeview-menu'>
						<li><a href='teacher_dashboard.php?register_student_subject'><i class='fa fa-circle-o'></i> Register Student Subject</a></li>
						<li><a href='teacher_dashboard.php?view_registered_subjects'><i class='fa fa-circle-o'></i> View Registered Subject</a></li>
					</ul>
				</li>

				<li class='treeview'>
					<a href='#'><i class='fa fa-book'></i><span>Result Management</span><i class='fa fa-angle-right'></i></a>
					<ul class='treeview-menu'>
						<li><a href='teacher_dashboard.php?upload_ca'><i class='fa fa-circle-o'></i> Upload CA Test</a></li>
						<li><a href='teacher_dashboard.php?upload_exam'><i class='fa fa-circle-o'></i> Upload Exam Score</a></li>	                    
						<li><a href='teacher_dashboard.php?teacher_excel_result_upload'><i class='fa fa-file-excel-o text-success'></i> Excel / CSV Result Upload</a></li>
						<li><a href='teacher_dashboard.php?view_uploaded_results'><i class='fa fa-circle-o'></i> View Uploaded Result</a></li>
					</ul>
				</li>

				<li><a href='teacher_dashboard.php?teacher_reset_password'><i class='fa fa-key'></i><span>Password Reset</span></a></li>
			<?php
				}

				if ($position == 'V.P Academics' || $position == 'V.P Admin' || $position == 'Head Master') {
			?>
				<li><a href='teacher_dashboard.php?vp_view_conduct'><i class='fa fa-circle-o'></i> View Uploaded Behavioral</a></li>
				<li><a href='teacher_dashboard.php?view_attendance_records'><i class='fa fa-eye'></i><span>View Attendance Records</span></a></li>

				<li class='treeview'>
					<a href='#'><i class='fa fa-search'></i><span>Search Students</span><i class='fa fa-angle-right'></i></a>
					<ul class='treeview-menu'>
						<li><a href='teacher_dashboard.php?student_search_by_reg_no'><i class='fa fa-circle-o'></i> Reg No</a></li>
						<li><a href='teacher_dashboard.php?student_search_by_class'><i class='fa fa-circle-o'></i> Class</a></li>
						<li><a href='teacher_dashboard.php?student_search_by_name'><i class='fa fa-circle-o'></i> Name</a></li>
					</ul>
				</li>

				<li class='treeview'>
					<a href='#'><i class='fa fa-laptop'></i><span>Student Management</span><i class='fa fa-angle-right'></i></a>
					<ul class='treeview-menu'>
						<li><a href='teacher_dashboard.php?add_new_student'><i class='fa fa-circle-o'></i> Register New Student</a></li>
						<li><a href='teacher_dashboard.php?promote_students'><i class='fa fa-circle-o'></i> Promote All Students</a></li>
						<li><a href='teacher_dashboard.php?promote_selected_students'><i class='fa fa-circle-o'></i> Promote Selected Students</a></li>
						<li><a href='teacher_dashboard.php?demote_students'><i class='fa fa-circle-o'></i> Demote Students</a></li>
						<!--<li><a href='teacher_dashboard.php?view_students'><i class='fa fa-circle-o'></i> View Students</a></li>-->
					</ul>
				</li>

				<li class='treeview'>
					<a href='#'><i class='fa fa-th'></i><span>Fees Management</span><i class='fa fa-angle-right'></i></a>
					<ul class='treeview-menu'>
						<li><a href='teacher_dashboard.php?student_fee'><i class='fa fa-circle-o'></i> View a Student Fee Record</a></li>
						<li><a href='teacher_dashboard.php?class_fee'><i class='fa fa-circle-o'></i> View Class Fee Record</a></li>
						<li><a href='teacher_dashboard.php?session_fees'><i class='fa fa-circle-o'></i> View Fees Paid in a Session</a></li>
					</ul>
				</li>

				<li class='treeview'>
					<a href='#'><i class='fa fa-file-text'></i><span>Subject Management</span><i class='fa fa-angle-right'></i></a>
					<ul class='treeview-menu'>
						<li><a href='teacher_dashboard.php?register_student_subject'><i class='fa fa-circle-o'></i> Register Student Subject</a></li>
						<li><a href='teacher_dashboard.php?view_registered_subjects'><i class='fa fa-circle-o'></i> View Registered Subject</a></li>
					</ul>
				</li>

				<li class='treeview'>
					<a href='#'><i class='fa fa-book'></i><span>Result Management</span><i class='fa fa-angle-right'></i></a>
					<ul class='treeview-menu'>
                        <li><a href='teacher_dashboard.php?vp_upload_ca'><i class='fa fa-circle-o'></i> Upload CA Test Scores</a></li>
                        <li><a href='teacher_dashboard.php?vp_upload_exam'><i class='fa fa-circle-o'></i> Upload Exam Scores</a></li>	   
                        <li><a href='teacher_dashboard.php?teacher_excel_result_upload'><i class='fa fa-file-excel-o text-success'></i> Excel / CSV Result Upload</a></li>
						<li><a href='teacher_dashboard.php?vp_view_upload'><i class='fa fa-circle-o'></i> View Uploaded Result</a></li>
                        <li><a href='teacher_dashboard.php?teacher_view_class_broadsheet'><i class='fa fa-circle-o'></i>View Class Broadsheet</a></li>
						<li><a href='teacher_dashboard.php?publish_result'><i class='fa fa-circle-o'></i> Publish Result</a></li>
						<li><a href='teacher_dashboard.php?teacher_view_published_result'><i class='fa fa-circle-o'></i> View Published Result</a></li>				
					<!--<li><a href='teacher_dashboard.php?vp_check_result'><i class='fa fa-circle-o'></i> Check Result</a></li>-->		
					</ul>
				</li>
				<li class='treeview'><a href='#'><i class='fa fa-bar-chart'></i><span>Student Performance</span><i class='fa fa-angle-right'></i></a>
				    <ul class='treeview-menu'>
						<li><a href='teacher_dashboard.php?performance_by_class'><i class='fa fa-circle-o'></i> By Class</a></li>
						<li><a href='teacher_dashboard.php?performance_by_subject'><i class='fa fa-circle-o'></i> By Subject</a></li>
					</ul>
				</li>
				<li class='treeview'>
					<a href='#'><i class='fa fa-user'></i><span>Generate Contacts</span><i class='fa fa-angle-right'></i></a>
					<ul class='treeview-menu'>
						<li><a href='teacher_dashboard.php?all_contact'><i class='fa fa-circle-o'></i> All Contacts</a></li>
					</ul>
				</li>

				<li><a href='teacher_dashboard.php?teacher_reset_password'><i class='fa fa-key'></i><span>Password Reset</span></a></li>
			<?php
				}
			?>
		
        </ul>
        </section>
      </aside>
      <div class='content-wrapper'>
        <?php
            if(isset($_GET['teacher_profile'])){
                require("teacher_profile.php");
            }
            elseif(isset($_GET['add_new_student'])){
                require("add_new_student.php");
            }
            elseif(isset($_GET['promote_students'])){
                require("promote_students.php");
            }
            elseif(isset($_GET['lesson_plans'])){
                require("lesson_plans.php");
            }
            elseif(isset($_GET['promote_selected_students'])){
                require_once("promote_selected_students.php");
            }
            elseif(isset($_GET['demote_students'])){
                require("demote_student.php");
            }			
            elseif(isset($_GET['view_students'])){
                require("teacher_view_students.php");
            }
            elseif(isset($_GET['vp_view_upload'])){
                require("vp_view_upload.php");
            }            
            elseif(isset($_GET['slip'])){
                require("teacher_print_slip.php");
            }
            elseif(isset($_GET['upload_ca'])){
                require_once("upload_ca.php");
            }	
            elseif(isset($_GET['upload_exam'])){
                require_once("upload_exam.php");
            }
            elseif(isset($_GET['vp_upload_ca'])){
                require_once("vp_upload_ca.php");
            }	
            elseif(isset($_GET['vp_upload_exam'])){
                require_once("vp_upload_exam.php");
            }                                    
            elseif(isset($_GET['publish_result'])){
                require("publish_result.php");
            }
            elseif(isset($_GET['teacher_view_published_result'])){
                require("teacher_view_published_result.php");
            }
            elseif(isset($_GET['vp_check_result'])){
                require_once("vp_check_result.php");
            }			
            elseif(isset($_GET['teacher_upload_attendance'])){
                require("teacher_upload_attendance.php");
            }
            elseif(isset($_GET['view_attendance_records'])){
                require("view_attendance_records.php");
            }
            elseif(isset($_GET['teacher_view_attendance'])){
                require("teacher_view_attendance.php");
            }            
            elseif(isset($_GET['vp_view_conduct'])){
                require("vp_view_conduct.php");
            }
            elseif(isset($_GET['export_conduct_sheet'])){
                require("teacher_export_conduct.php");
            }
            elseif(isset($_GET['teacher_upload_conduct'])){
                require("teacher_upload_conduct.php");
            }
            elseif(isset($_GET['teacher_view_conduct'])){
                require("teacher_view_conduct.php");
            }
            elseif(isset($_GET['performance_by_class'])){
                require("performance_by_subject.php");
            }
            elseif(isset($_GET['teacher_view_class_broadsheet']) || isset($_GET['teacher_view_broadsheet'])){
                require("teacher_view_broadsheet.php");
            }
            elseif(isset($_GET['register_student_subject'])){
                require("teacher_register_student_subject.php");
            }
            elseif(isset($_GET['view_registered_subjects'])){
                require("teacher_view_registered_subjects.php");
            }
            elseif(isset($_GET['upload_result'])){
                require("teacher_result_upload.php");
            }
            elseif(isset($_GET['excel_result_upload']) || isset($_GET['teacher_excel_result_upload'])){
                require("teacher_excel_result_upload.php");
            }
            elseif(isset($_GET['view_uploaded_results'])){
                require("teacher_view_upload.php");
            }
            elseif(isset($_GET['teacher_reset_password'])){
                require("teacher_reset_password.php");
            }
			elseif(isset($_GET['student_search_by_reg_no'])){
                require("teacher_student_search_by_reg_no.php");
            }
            elseif(isset($_GET['student_search_by_class'])){
                require("teacher_student_search_by_class.php");
            }
            elseif(isset($_GET['student_search_by_name'])){
                require("teacher_student_search_by_name.php");
            }
            elseif(isset($_GET['student_fee'])){
                require("student_fee.php");
            }
            elseif(isset($_GET['class_fee'])){
                require("class_fee.php");
            }
            elseif(isset($_GET['session_fees'])){
                require("session_fees.php");
            }
            elseif(isset($_GET['result_manager'])){
                require("teacher_result_manager.php");
            }
            elseif(isset($_GET['teachers_profile'])){
                require("teachers_profile.php");
            }
            elseif(isset($_GET['all_contact'])){
                require("all_contact.php");
            }			
            elseif(isset($_GET['logout'])){
                SESSION_UNSET(); // this unset every session and thus logs the user out
                redirect_to("../../index.php");
            }
            else {
                require_once("dashboard.php");
            }
        ?>
      </div>
    </div>
	<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <!-- Javascripts-->
    <script src="../../assets/js/jquery-2.1.4.min.js"></script>
    <script src="../../assets/js/bootstrap.min.js"></script>
    <script src="../../assets/js/plugins/pace.min.js"></script>
    <script src="../../assets/js/main.js"></script>
    <script type="text/javascript" src="../../assets/js/plugins/moment.min.js"></script>
    <script type="text/javascript" src="../../assets/js/plugins/jquery-ui.custom.min.js"></script>
    <script type="text/javascript" src="../../assets/js/plugins/fullcalendar.min.js"></script>
    <script type="text/javascript">
      $(document).ready(function() {
      
      	$('#external-events .fc-event').each(function() {
      
      		// store data so the calendar knows to render an event upon drop
      		$(this).data('event', {
      			title: $.trim($(this).text()), // use the element's text as the event title
      			stick: true // maintain when user navigates (see docs on the renderEvent method)
      		});
      
      		// make the event draggable using jQuery UI
      		$(this).draggable({
      			zIndex: 999,
      			revert: true,      // will cause the event to go back to its
      			revertDuration: 0  //  original position after the drag
      		});
      
      	});
      
      	$('#calendar').fullCalendar({
      		header: {
      			left: 'prev,next today',
      			center: 'title',
      			right: 'month,agendaWeek,agendaDay'
      		},
      		editable: true,
      		droppable: true, // this allows things to be dropped onto the calendar
      		drop: function() {
      			// is the "remove after drop" checkbox checked?
      			if ($('#drop-remove').is(':checked')) {
      				// if so, remove the element from the "Draggable Events" list
      				$(this).remove();
      			}
      		}
      	});
      
      
      });
    </script>
  </body>
</html>
