Make PHP having UTF-8 encoding.

Bug430-Eden2
Lan Hui 2023-08-03 15:31:38 +08:00
parent 020d7a2c04
commit 68f9db8e1d
6 changed files with 368 additions and 368 deletions

552
Admin.php
View File

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

View File

@ -1,2 +1,2 @@
<br><br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br><br>
<div style="background-color:white;width:100%di"></div> <div style="background-color:white;width:100%di"></div>

View File

@ -27,8 +27,8 @@ LRR needs Apache and MySQL to run. I followed [How To Install Linux, Apache, My
LRR uses a database called `lrr`. So create this database using MySQL root account. Open MySQL's prompt using `sudo mysql`. Create the database using command `CREATE DATABASE lrr;`, and grant all privileges to MySQL user `lrr` using command `GRANT ALL PRIVILEGES ON lrr.* TO 'mnc'@'localhost' WITH GRANT OPTION;`. If MySQL user mnc does not exist, create it using command `CREATE USER 'mnc'@'localhost' IDENTIFIED BY 'password'`. LRR uses a database called `lrr`. So create this database using MySQL root account. Open MySQL's prompt using `sudo mysql`. Create the database using command `CREATE DATABASE lrr;`, and grant all privileges to MySQL user `lrr` using command `GRANT ALL PRIVILEGES ON lrr.* TO 'mnc'@'localhost' WITH GRANT OPTION;`. If MySQL user mnc does not exist, create it using command `CREATE USER 'mnc'@'localhost' IDENTIFIED BY 'password'`.
To facilitate data migration, I need to export the existing `lrr` to a plain text file (including many sql commands) and import that text file to the newly created `lrr` database on the new server. To facilitate data migration, I need to export the existing `lrr` to a plain text file (including many sql commands) and import that text file to the newly created `lrr` database on the new server.
The command for exporting the database is `mysqldump -u mnc -p lrr > lrr_database_dump.txt`, where mnc after -u is MySQL's username, and lrr after -p is the database name. The command for exporting the database is `mysqldump -u mnc -p lrr > lrr_database_dump.sql`, where mnc after -u is MySQL's username, and lrr after -p is the database name.
The command for importing is `mysql -u mnc -p lrr < lrr_database_dump.txt`. Read [How to Import and Export MySQL Databases in Linux](https://phoenixnap.com/kb/import-and-export-mysql-database) for more detail. Do not have lrr_database_dump.txt? You can use lrr_database.sql in this repo instead. The command for importing is `mysql -u mnc -p lrr < lrr_database_dump.sql`. Read [How to Import and Export MySQL Databases in Linux](https://phoenixnap.com/kb/import-and-export-mysql-database) for more detail. Do not have lrr_database_dump.sql? You can use lrr_database.sql in this repo instead.
LRR also needs to store assignment submissions. We store them in a folder called `../../lrr_submission`. Note that `lrr_submission` is two levels above the project folder (where many PHP files reside). I copied this folder from the existing one. I think it is also OK if you create an empty folder. LRR also needs to store assignment submissions. We store them in a folder called `../../lrr_submission`. Note that `lrr_submission` is two levels above the project folder (where many PHP files reside). I copied this folder from the existing one. I think it is also OK if you create an empty folder.
We need to set a proper owner and accessibility for `lrr_submission` using the following two commands: We need to set a proper owner and accessibility for `lrr_submission` using the following two commands:

View File

@ -1,14 +1,14 @@
<?php <?php
$page = "student"; $page = "student";
include 'Header.php'; include 'Header.php';
?> ?>
<br><br><br> <br><br><br>
<div class="row" style="width:80%;margin:auto;"> <div class="row" style="width:80%;margin:auto;">
<div class="col-md-6"> <div class="col-md-6">
<h1> Student account created. Now you can browse the course portal. </h1> <h1> Student account created. Now you can browse the course portal. </h1>
</div> </div>
</div> </div>

View File

@ -1,24 +1,24 @@
<?php <?php
// Start a new session // Start a new session
session_start(); session_start();
// Destory sessions & redirect to index // Destory sessions & redirect to index
session_destroy(); session_destroy();
session_unset(); session_unset();
// Generate a new session ID // Generate a new session ID
session_regenerate_id(true); session_regenerate_id(true);
// Then finally, make sure you pick up the new session ID // Then finally, make sure you pick up the new session ID
$session_id = session_id(); $session_id = session_id();
unset($_SESSION['user_id']); unset($_SESSION['user_id']);
unset($_SESSION['user_email']); unset($_SESSION['user_email']);
unset($_SESSION['user_type']); unset($_SESSION['user_type']);
unset($_SESSION['user_student_id']); unset($_SESSION['user_student_id']);
unset($_SESSION['user_fullname']); unset($_SESSION['user_fullname']);
header("Location: index.php"); header("Location: index.php");
?> ?>

View File

@ -1,50 +1,50 @@
<?php <?php
include 'NoDirectPhpAcess.php'; include 'NoDirectPhpAcess.php';
?> ?>
<?php <?php
include 'Header.php'; include 'Header.php';
?> ?>
<div class="row"> <div class="row">
<div class="col-md-4 list-group" style="margin:auto;"> <div class="col-md-4 list-group" style="margin:auto;">
<br> <br>
<h4 class="list-group-item active"> Please fill in each field below </h4> <h4 class="list-group-item active"> Please fill in each field below </h4>
<div class="list-group-item"> <div class="list-group-item">
<div class="panel-body"> <div class="panel-body">
<form method="post" action="Script.php" id="signup_form"> <form method="post" action="Script.php" id="signup_form">
<input type="hidden" name="form_signup" value="true" /> <input type="hidden" name="form_signup" value="true" />
Full Name Full Name
<input type="text" name="fullname" placeholder="Your full name" class="form-control" value="<?php echo $_SESSION['user_fullname']; ?>" required="required" id="full_name"/> <input type="text" name="fullname" placeholder="Your full name" class="form-control" value="<?php echo $_SESSION['user_fullname']; ?>" required="required" id="full_name"/>
Student ID Student ID
<input type="text" name="user_student_id" placeholder="Entre your student ID" class="form-control" value="<?php echo $_SESSION['user_student_id']; ?>" required="required" id="student_id"> <input type="text" name="user_student_id" placeholder="Entre your student ID" class="form-control" value="<?php echo $_SESSION['user_student_id']; ?>" required="required" id="student_id">
Email Email
<input type="text" name="email" placeholder="Email" class="form-control" value="<?php echo $_SESSION['user_email']; ?>" required="required" id="email" /> <input type="text" name="email" placeholder="Email" class="form-control" value="<?php echo $_SESSION['user_email']; ?>" required="required" id="email" />
Password (<i>must include uppercase and lowercase letters, digits and special characters</i>) Password (<i>must include uppercase and lowercase letters, digits and special characters</i>)
<input type="password" class="form-control" name="password" placeholder="Enter password" required="required" id="password1" /> <input type="password" class="form-control" name="password" placeholder="Enter password" required="required" id="password1" />
Confirm Password Confirm Password
<input type="password" class="form-control" name="confirmpassword" placeholder="Confirm password" required="required" id="password2" /> <input type="password" class="form-control" name="confirmpassword" placeholder="Confirm password" required="required" id="password2" />
<br> <br>
<input type="submit" class="btn-primary" value="Sign up" id="signup_btn"> <input type="submit" class="btn-primary" value="Sign up" id="signup_btn">
<?php <?php
error_reporting(E_ALL); error_reporting(E_ALL);
if (isset($_SESSION['info_signup'])) { if (isset($_SESSION['info_signup'])) {
echo '<hr><div class="alert alert-danger" role="alert">' . $_SESSION['info_signup'] . '</div>'; echo '<hr><div class="alert alert-danger" role="alert">' . $_SESSION['info_signup'] . '</div>';
$_SESSION['info_signup'] = null; $_SESSION['info_signup'] = null;
} }
?> ?>
</form> </form>
</div> </div>
</div> </div>
</div> </div>
</div> </div>