256 lines
		
	
	
		
			7.3 KiB
		
	
	
	
		
			PHP
		
	
	
			
		
		
	
	
			256 lines
		
	
	
		
			7.3 KiB
		
	
	
	
		
			PHP
		
	
	
| <?php
 | |
| include 'NoDirectPhpAcess.php';
 | |
| ?>
 | |
| 
 | |
| <?php
 | |
| $page = "admin";
 | |
| include 'Header.php';
 | |
| ?>
 | |
| 
 | |
| 
 | |
| <?php
 | |
| // Only Lecturer or Admin could access this page
 | |
| if ($_SESSION['user_type'] != "Lecturer" && $_SESSION['user_type'] != "Admin") {
 | |
|     die("Sorry.  Nothing to see here.");
 | |
| }
 | |
| ?>
 | |
| 
 | |
| <div class="container">
 | |
| 
 | |
|     <br>
 | |
|     <div>
 | |
| 	<h2> Administration panel </h2>
 | |
|     </div>
 | |
| 
 | |
|     <hr>
 | |
|     <div class="row">
 | |
| 
 | |
| 	<div class="col-md-6">
 | |
| 
 | |
|            <!-- Nav tabs -->
 | |
| 	    <ul class="nav nav-tabs">
 | |
| 		<li class="nav-item">
 | |
| 		    <a class="nav-link active" id="home" href="#home">Create TA account</a>
 | |
| 		</li>
 | |
| 
 | |
| 		<li class="nav-item">
 | |
| 		    <a class="nav-link" href="#menu1" id="batch_tab">Batch create student accounts</a>
 | |
| 		</li>
 | |
| 
 | |
| 		<li class="nav-item">
 | |
| 		    <a class="nav-link" href="#menu2" id="existing_accounts_tab">Existing accounts</a>
 | |
| 		</li>
 | |
| 	    </ul>
 | |
| 
 | |
|             <!-- Tab panes -->
 | |
| 	    <div class="tab-content">
 | |
| 
 | |
| 		<div id="home" class="tab-pane active"><br>
 | |
| 
 | |
| 		    <?php
 | |
| 		    if ($_SESSION['user_type'] == "Lecturer") {
 | |
| 
 | |
| 			echo "<b>Create TA Accounts </b>";
 | |
| 
 | |
| 		    }
 | |
| 		    else if($_SESSION['user_type'] == "Admin"){
 | |
| 			echo "<b>Create Lecturer Accounts </b>";
 | |
| 		    }
 | |
| 
 | |
| 		    ?>
 | |
| 		    <form method="post" action="Script.php" id="create_account_form">
 | |
| 			<input type="hidden" name="frm_createlecturrer" value="true" required="" />
 | |
| 			Full name
 | |
| 			<input type="text" name="fullname" placeholder="Full Name" class="form-control" required="">
 | |
| 			Email
 | |
| 			<input type="text" name="email" placeholder="Email / Student Number" class="form-control" required="">
 | |
| 
 | |
| 			Passport number/ID (used as the initial password)
 | |
| 			<input type="text" class="form-control" name="passport" placeholder="Passport No./ID" required="">
 | |
| 			<br> User type:
 | |
| 
 | |
| 			<?php
 | |
| 
 | |
| 			if ($_SESSION['user_type'] == "Lecturer") {
 | |
| 
 | |
| 			    echo ' <input type="radio" name="type" value="TA" required="" id="role_TA"> TA (Teaching Assistant) ';
 | |
| 
 | |
| 			}
 | |
| 			else if($_SESSION['user_type'] == "Admin"){
 | |
| 
 | |
| 			    echo " <input type='radio' name = 'type' value = 'Lecturer' required = '' id='role_lecturer' > Lecturer ";
 | |
| 
 | |
| 			}
 | |
| 
 | |
| 			?>
 | |
| 
 | |
| 			<input type="submit" class="btn btn-primary" value="Create" id="create_btn"><br>
 | |
| 
 | |
| 			<?php
 | |
| 
 | |
| 			error_reporting(E_ALL);
 | |
| 			if (isset($_SESSION['info_Admin_Users'])) {
 | |
| 			    echo  '<hr><div class="alert alert-info" role="alert">' . $_SESSION['info_Admin_Users'] . '</div>';
 | |
| 			    $_SESSION['info_Admin_Users'] = null;
 | |
| 			}
 | |
| 			if (isset($_SESSION['info_Admin_Users'])) {
 | |
| 			    echo  '<hr><div class="alert alert-info" role="alert">' . $_SESSION['info_Admin_Users'] . '</div>';
 | |
| 			    $_SESSION['info_Admin_Users'] = null;
 | |
| 			}
 | |
| 
 | |
| 			?>
 | |
| 
 | |
| 		    </form>
 | |
| 
 | |
| 		    <hr>
 | |
| 
 | |
| 		</div>
 | |
| 
 | |
| 
 | |
| 		<!-- code contributed by Xu Xiaopeng (https://github.com/xxp1999) -->
 | |
| 		<div id="menu1" class="tab-pane fade" style="margin-top:10px">
 | |
| 		    <b>Separate two student numbers with a space</b><br>
 | |
| 		    <form action="batch_insert.php" method="post" id="batch_form">
 | |
| 			<p>
 | |
| 			    <textarea cols="70" rows="16" name="users" required=""></textarea>
 | |
| 			</p>
 | |
| 			<input type="submit" class="btn btn-primary" value="Register students" id="register_btn"><br>
 | |
| 		    </form>
 | |
| 		</div>
 | |
| 
 | |
| 
 | |
| 		<div id="menu2" class="tab-pane fade"><br>
 | |
| 
 | |
| 		    <table class="table-bordered" style="font-size: 10pt;">
 | |
| 			<tr style="font-size:10pt;">
 | |
| 			    <th>ID</th>
 | |
| 			    <th>Name</th>
 | |
| 			    <th>Email</th>
 | |
| 			    <th>Passport / ID </th>
 | |
| 			    <th>Reset password </th>
 | |
| 			    <th>Block/Activate </th>
 | |
| 			</tr>
 | |
| 			<?php
 | |
| 
 | |
| 			if ($_SESSION['user_type'] == "Lecturer") {
 | |
| 
 | |
| 			    $result = mysqli_query(
 | |
| 				$con,
 | |
| 				"SELECT * FROM users_table WHERE UserType in ('TA')"
 | |
| 			    );
 | |
| 			}
 | |
| 
 | |
| 			else if ($_SESSION['user_type'] == "Admin"){
 | |
| 			    $result = mysqli_query(
 | |
| 				$con,
 | |
| 				"SELECT * FROM users_table WHERE UserType in ('Lecturer')"
 | |
| 			    );
 | |
| 			}
 | |
| 
 | |
| 			while ($row = mysqli_fetch_assoc($result)) {
 | |
| 			    $pass = $row['Passport_Number'];
 | |
| 			    $btn = "<button class='btn-warning' onclick=\"updatePass(" . $row['User_ID'] . ",'$pass')\">Reset</button>";
 | |
| 			    if ($row['Status'] == "Active") {
 | |
| 				$newstatus = "Blocked";
 | |
| 				$btnBlock = "<button class='btn-danger' onclick=\"blockUser(" . $row['User_ID'] . ",'$newstatus')\" id=\"block_account_1\">Block</button>";
 | |
| 			    } else {
 | |
| 				$newstatus = "Active";
 | |
| 				$btnBlock = "<button class='btn-success' onclick=\"blockUser(" . $row['User_ID'] . ",'$newstatus')\" id=\"activate_account_1\">Activate</button>";
 | |
| 			    }
 | |
| 
 | |
| 			    echo "<tr><td>" . $row['User_ID'] . "</td><td>" . $row['Full_Name'] . "</td><td>" . $row['Email'] . "</td> <td>" . $row['Passport_Number'] . "</td><td>$btn</td><td>$btnBlock</td></tr>";
 | |
| 			}
 | |
| 			?>
 | |
| 		    </table>
 | |
| 		</div>
 | |
| 
 | |
| 	    </div>
 | |
| 
 | |
| 	</div>
 | |
| 
 | |
| 	<div class="col-md-6">
 | |
| 
 | |
| 	    <ul class="nav nav-tabs" role="tablist">
 | |
| 		<li class="nav-item">
 | |
| 		    <a class="nav-link active" href="#menu3" id="existing_courses">Existing courses</a>
 | |
| 		</li>
 | |
| 	    </ul>
 | |
| 
 | |
|             <div id="menu3" class="container tab-pane active"><br>
 | |
| 
 | |
| 		<b> Past courses </b>
 | |
| 		<hr>
 | |
| 		<table class="table-bordered" style="font-size: 10pt;">
 | |
| 		    <tr>
 | |
| 			<th>Course Name</th>
 | |
| 			<th>Faculty</th>
 | |
| 			<th>Lecturer</th>
 | |
| 			<th>TAs</th>
 | |
| 			<th>Assign new TA </th>
 | |
| 		    </tr>
 | |
| 		    <?php
 | |
| 		    $user_id = $_SESSION['user_id'];
 | |
| 		    $result = mysqli_query($con, "SELECT `Course_ID`, `Course_Name`, `Academic_Year`, `Faculty`, `TA_User_ID`, `Course_Code`, `Full_Name` FROM courses_table INNER JOIN users_table ON users_table.User_ID=courses_table.Lecturer_User_ID WHERE User_ID=$user_id ORDER BY Academic_Year DESC;");
 | |
| 		    if (mysqli_num_rows($result) == 0) {
 | |
| 		    } else {
 | |
| 			$counter = 0;
 | |
| 			while ($row = mysqli_fetch_assoc($result)) {
 | |
| 			    $name = $row['Course_Name'];
 | |
| 			    $code = $row['Course_Code'];
 | |
| 			    $faculty = $row['Faculty'];
 | |
| 			    $lecturer = $row['Full_Name'];
 | |
| 			    $academic = $row['Academic_Year'];
 | |
| 			    $c_id = $row['Course_ID'];
 | |
| 			    $counter += 1;
 | |
| 
 | |
| 			    $resultTA = mysqli_query($con, "SELECT `Course_ID`, `TA`, users_table.Full_Name as TA_NAME FROM course_ta INNER JOIN users_table on users_table.User_ID=course_ta.TA where course_ta.Course_ID=$c_id");
 | |
| 
 | |
| 			    $ta = "";
 | |
| 			    while ($rowTA = mysqli_fetch_assoc($resultTA)) {
 | |
| 				$ta = $ta . "  - " . $rowTA['TA_NAME'];
 | |
| 			    }
 | |
| 
 | |
| 			    echo "
 | |
|                           <tr> <td>$code - $name</td>  <td>$faculty </td> <td>$lecturer</td><td>$ta</td>  <td><form method='get' action='Script.php' id='drop_menu_form_$counter'> <select name='ta' class=''>";
 | |
| 
 | |
| 			    $resultx = mysqli_query($con, "SELECT * FROM users_table WHERE UserType='TA'");
 | |
| 			    if (mysqli_num_rows($resultx) == 0) {
 | |
| 			    } else {
 | |
| 				while ($row = mysqli_fetch_assoc($resultx)) {
 | |
| 				    $id = $row['User_ID'];
 | |
| 				    $name = $row['Full_Name'];
 | |
| 				    echo "<option value='$id'> $name </option>";
 | |
| 				}
 | |
| 			    }
 | |
| 
 | |
| 			    echo "</select>  <input type='hidden' name='assignTA' value='true'> <input type='hidden' name='id' value='$c_id'>  <input type='submit' value='assign' id='assign_btn_$counter'></form> </td></tr>
 | |
|                             ";
 | |
| 			}
 | |
| 		    } ?>
 | |
| 
 | |
| 		</table>
 | |
| 
 | |
|             </div>
 | |
| 
 | |
| 	</div>
 | |
| 
 | |
|     </div>
 | |
| </div>
 | |
| 
 | |
| <script>
 | |
|  function updatePass(id, pass) {
 | |
|      if (!confirm('Are you sure to reset user password?')) {
 | |
|          return;
 | |
|      }
 | |
| 
 | |
|      window.location.href = "\Script.php\?action=passchange&uid=" + id + "&pass=" + pass;
 | |
|  }
 | |
| 
 | |
|  function blockUser(id, status) {
 | |
|      if (!confirm('Are you sure to change user status?')) {
 | |
|          return;
 | |
|      }
 | |
|      window.location.href = "\Script.php\?action=statuschange&uid=" + id + "&status=" + status;
 | |
|  }
 | |
| </script>
 |