home.php (5680B)
1 <?php 2 session_start(); 3 4 $root = realpath($_SERVER['DOCUMENT_ROOT']); 5 include "$root/php/db.php"; 6 7 # Here, check to see if user is NOT logged in 8 if (isset($_SESSION['is_logged_in'])) { 9 if ($_SESSION['is_logged_in'] == 0) { 10 # Redirect to login screen if not; access to home is forbidden 11 echo "<script type='text/javascript'> 12 window.location.replace('index.php'); 13 </script>"; 14 } 15 } else { 16 echo "<script type='text/javascript'> 17 window.location.replace('index.php'); 18 </script>"; 19 } 20 21 $db = database::get_connection(); 22 23 function get_role($db) { 24 $stmt = $db -> prepare("SELECT Role FROM Users WHERE UserName=?;"); 25 26 $stmt->bind_param('s', $_SESSION['user']); 27 28 $stmt->execute(); 29 30 $result = $stmt->get_result(); 31 32 while ($rows = mysqli_fetch_assoc($result)) 33 $role = $rows['Role']; 34 35 return $role; 36 } 37 38 $_SESSION['role'] = get_role($db); 39 40 ?> 41 42 <!DOCTYPE html> 43 <html lang='en-CA'> 44 <head> 45 <title>COSC4426AE-21F: Assignment II - Home</title> 46 <?php include 'import/head.html'; ?> 47 <!--Get role as JS var so we can display the appropriate actions for user--> 48 <script type='text/javascript'> 49 role = "<?php echo $_SESSION['role']; ?>"; 50 </script> 51 </head> 52 53 <body> 54 <header id='header'> 55 <h1>Welcome, <?php echo "$_SESSION[user]"; ?>!</h1> 56 <div id='header_options'> 57 <a href='#' id='actions'>Actions</a> 58 <a href='#' id='logout'>Logout</a> 59 </div> 60 </header> 61 62 <main> 63 <div id='nav' class='nav'> 64 <a href='javascript:void(0)' class='exit' onclick='exit()'>×</a> 65 <ul> 66 <!--Students can view their academic summary--> 67 <?php if ($_SESSION['role'] == 'Student') { ?> 68 <li> 69 <h1>Reports</h1> 70 <ul> 71 <a href='#' class='action' id='my_summary'><li>My Summary</li></a> 72 </ul> 73 </li> 74 <?php } ?> 75 76 <!--Instructors can view their courses--> 77 <?php if ($_SESSION['role'] == 'Instructor') { ?> 78 <li> 79 <h1>Reports</h1> 80 <ul> 81 <a href='#' class='action' id='my_courses'><li>My Courses</li></a> 82 </ul> 83 </li> 84 <?php } ?> 85 86 <!--Both admins and registrars can access the forms and reports--> 87 <?php if ($_SESSION['role'] == 'Admin' || $_SESSION['role'] == 'Registrar') { ?> 88 <li> 89 <h1>Forms</h1> 90 <ul> 91 <a href='#' class='action' id='add_faculty'><li>Add Faculty Member</li></a> 92 <a href='#' class='action' id='register_student'><li>Register Student</li></a> 93 <a href='#' class='action' id='assign_faculty'><li>Assign Faculty Member to Teach</li></a> 94 <a href='#' class='action' id='enroll'><li>Enroll Student in Course</li></a> 95 <a href='#' class='action' id='drop'><li>Drop Student from Course</li></a> 96 <a href='#' class='action' id='change_grade'><li>Change Grade</li></a> 97 </ul> 98 </li> 99 100 <li> 101 <h1>Reports</h1> 102 <ul> 103 <a href='#' class='action' id='class_list'><li>Class List</li></a> 104 <a href='#' class='action' id='student_transcript'><li>Student Transcript</li></a> 105 <a href='#' class='action' id='students_in_degree'><li>Students in Degree Program</li></a> 106 <a href='#' class='action' id='students_instructors'><li>Student's Instructors</li></a> 107 <a href='#' class='action' id='courses_taught'><li>Courses Taught by Instructor</li></a> 108 </ul> 109 </li> 110 <?php } ?> 111 112 <!--Only admins can manage user accounts --> 113 <?php if ($_SESSION['role'] == 'Admin') { ?> 114 <li> 115 <h1>Manage Users</h1> 116 <ul> 117 <a href='#' class='action' id='add_user'><li>Add User</li></a> 118 <a href='#' class='action' id='delete_user'><li>Delete User</li></a> 119 <a href='#' class='action' id='modify_user'><li>Modify User</li></a> 120 <a href='#' class='action' id='view_users'><li>View Users</li></a> 121 </ul> 122 </li> 123 <?php } ?> 124 </ul> 125 </div> 126 127 <div id='main'> 128 <!--Form inserted here via JavaScript--> 129 </div> 130 </main> 131 132 <footer> 133 </footer> 134 </body> 135 136 <?php include 'import/js.html'; ?> 137 <script type='text/javascript' src='/js/actions.js'></script> 138 <script type='text/javascript' src='/js/logout.js'></script> 139 <script type='text/javascript' src='/js/nav.js'></script> 140 </html>