2023-08-03 15:31:38 +08:00
< ? 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. " );
}
?>
2023-08-06 17:43:36 +08:00
< div class = " container " >
2023-08-03 15:31:38 +08:00
2023-08-19 20:44:21 +08:00
2023-08-06 17:43:36 +08:00
< br >
2023-08-19 20:44:21 +08:00
< h1 class = " display-6 " > Administration panel </ h1 >
2023-08-03 15:31:38 +08:00
2023-08-06 17:43:36 +08:00
< hr >
< div class = " row " >
2023-08-03 15:31:38 +08:00
2023-08-06 17:43:36 +08:00
< div class = " col-md-6 " >
2023-08-03 15:31:38 +08:00
2023-08-06 17:43:36 +08:00
<!-- Nav tabs -->
2023-08-07 16:39:19 +08:00
< ul class = " nav nav-tabs " id = " myTab " >
2023-08-03 15:31:38 +08:00
< li class = " nav-item " >
2023-08-07 16:39:19 +08:00
< a class = " nav-link active " href = " #tab-student-accounts " id = " batch_tab " > Create student accounts </ a >
2023-08-03 15:31:38 +08:00
</ li >
< li class = " nav-item " >
2023-08-07 16:39:19 +08:00
< a class = " nav-link " href = " #tab-ins-accounts " > Create instructor account </ a >
2023-08-03 15:31:38 +08:00
</ li >
< li class = " nav-item " >
2023-08-07 16:39:19 +08:00
< a class = " nav-link " href = " #tab-existing-accounts " id = " existing_accounts_tab " > Existing accounts </ a >
2023-08-03 15:31:38 +08:00
</ li >
</ ul >
2023-08-06 17:43:36 +08:00
<!-- Tab panes -->
2023-08-03 15:31:38 +08:00
< div class = " tab-content " >
2023-08-07 16:39:19 +08:00
<!-- code contributed by Xu Xiaopeng ( https :// github . com / xxp1999 ) -->
< div id = " tab-student-accounts " class = " tab-pane active " style = " margin-top:5px " >
< p class = " text-muted " > Copy & paste student number to the following box , and separate two student numbers with a space .</ p >
< form action = " batch_insert.php " method = " post " id = " batch_form " >
< textarea cols = " 60 " rows = " 16 " name = " users " required = " " ></ textarea >
< button type = " submit " class = " btn btn-primary " id = " register_btn " > Register students </ button >
</ form >
</ div >
< div id = " tab-ins-accounts " class = " tab-pane " >< br >
2023-08-03 15:31:38 +08:00
2023-08-06 17:43:36 +08:00
< ? php
2023-08-03 15:31:38 +08:00
if ( $_SESSION [ 'user_type' ] == " Lecturer " ) {
2023-08-07 16:39:19 +08:00
echo " <p class= \" text-muted \" >Create TA Accounts</p> " ;
2023-08-03 15:31:38 +08:00
}
else if ( $_SESSION [ 'user_type' ] == " Admin " ){
2023-08-07 16:39:19 +08:00
echo " <p class= \" text-muted \" >Create Lecturer Accounts</p> " ;
2023-08-03 15:31:38 +08:00
}
2023-08-06 17:43:36 +08:00
2023-08-03 15:31:38 +08:00
?>
< form method = " post " action = " Script.php " id = " create_account_form " >
< input type = " hidden " name = " frm_createlecturrer " value = " true " required = " " />
2023-08-04 15:24:51 +08:00
Full name
2023-08-07 16:39:19 +08:00
< input type = " text " name = " fullname " placeholder = " Full Name " class = " form-control " required = " " > < br >
2023-08-03 15:31:38 +08:00
Email
2023-08-07 16:39:19 +08:00
< input type = " text " name = " email " placeholder = " Email / Student Number " class = " form-control " required = " " > < br >
2023-08-04 15:24:51 +08:00
Passport number / ID ( used as the initial password )
2023-08-07 16:39:19 +08:00
< input type = " text " class = " form-control " name = " passport " placeholder = " Passport No./ID " required = " " > < br >
User type :
2023-08-06 17:43:36 +08:00
< ? php
2023-08-03 15:31:38 +08:00
if ( $_SESSION [ 'user_type' ] == " Lecturer " ) {
echo ' <input type="radio" name="type" value="TA" required="" id="role_TA"> TA (Teaching Assistant) ' ;
2023-08-07 16:39:19 +08:00
} else if ( $_SESSION [ 'user_type' ] == " Admin " ){
2023-08-03 15:31:38 +08:00
echo " <input type='radio' name = 'type' value = 'Lecturer' required = '' id='role_lecturer' > Lecturer " ;
}
2023-08-06 17:43:36 +08:00
?>
2023-08-19 20:37:53 +08:00
< br >< br >
2023-08-07 16:39:19 +08:00
< button type = " submit " class = " btn btn-primary " id = " create_btn " > Create </ button >
2023-08-03 15:31:38 +08:00
< ? 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 >
</ div >
2023-08-07 16:39:19 +08:00
< div id = " tab-existing-accounts " class = " tab-pane " >< br >
2023-08-03 15:31:38 +08:00
2023-08-07 16:39:19 +08:00
< table class = " table " style = " font-size: 10pt; " >
2023-08-03 15:31:38 +08:00
< 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 " ) {
2023-08-06 17:43:36 +08:00
2023-08-03 15:31:38 +08:00
$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' ];
2023-08-07 16:39:19 +08:00
$btn = " <button class='btn btn-warning' onclick= \" updatePass( " . $row [ 'User_ID' ] . " ,' $pass ') \" >Reset</button> " ;
2023-08-03 15:31:38 +08:00
if ( $row [ 'Status' ] == " Active " ) {
$newstatus = " Blocked " ;
2023-08-07 16:39:19 +08:00
$btnBlock = " <button class='btn btn-danger' onclick= \" blockUser( " . $row [ 'User_ID' ] . " ,' $newstatus ') \" id= \" block_account_1 \" >Block</button> " ;
2023-08-03 15:31:38 +08:00
} else {
$newstatus = " Active " ;
2023-08-07 16:39:19 +08:00
$btnBlock = " <button class='btn btn-success' onclick= \" blockUser( " . $row [ 'User_ID' ] . " ,' $newstatus ') \" id= \" activate_account_1 \" >Activate</button> " ;
2023-08-03 15:31:38 +08:00
}
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 >
2023-08-06 17:43:36 +08:00
</ div >
2023-08-03 15:31:38 +08:00
2023-08-06 17:43:36 +08:00
< div class = " col-md-6 " >
2023-08-03 15:31:38 +08:00
2023-08-07 16:39:19 +08:00
< ul class = " nav nav-tabs " id = " myTab " >
2023-08-03 15:31:38 +08:00
< li class = " nav-item " >
2023-08-07 16:39:19 +08:00
< a class = " nav-link active " href = " #tab-existing-courses " id = " existing_courses " > Existing courses </ a >
2023-08-03 15:31:38 +08:00
</ li >
</ ul >
2023-08-07 16:39:19 +08:00
< div id = " tab-existing-courses " class = " tab-pane active " >< br >
2023-08-06 17:43:36 +08:00
2023-08-07 16:39:19 +08:00
< p class = " text-muted " > Past courses </ p >
< table class = " table " style = " font-size: 10pt; " >
2023-08-06 17:43:36 +08:00
< tr >
2023-08-07 16:39:19 +08:00
< th > Course name </ th >
2023-08-06 17:43:36 +08:00
< th > Faculty </ th >
< th > Lecturer </ th >
< th > TAs </ th >
2023-08-07 16:39:19 +08:00
< th > Assign a new TA </ th >
2023-08-06 17:43:36 +08:00
</ 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 )) {
2023-08-07 16:39:19 +08:00
$ta = $ta . " " . $rowTA [ 'TA_NAME' ];
2023-08-06 17:43:36 +08:00
}
echo "
2023-08-03 15:31:38 +08:00
< 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 = '' > " ;
2023-08-06 17:43:36 +08:00
$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> " ;
}
2023-08-03 15:31:38 +08:00
}
2023-08-06 17:43:36 +08:00
2023-08-07 16:39:19 +08:00
echo " </select> <input type='hidden' name='assignTA' value='true'> <input type='hidden' name='id' value=' $c_id '> <button class='btn btn-outline-secondary btn-sm' type='submit' id='assign_btn_ $counter '>assign</button></form> </td></tr>
2023-08-06 17:43:36 +08:00
" ;
2023-08-03 15:31:38 +08:00
}
2023-08-06 17:43:36 +08:00
} ?>
2023-08-03 15:31:38 +08:00
2023-08-06 17:43:36 +08:00
</ table >
2023-08-03 15:31:38 +08:00
2023-08-06 17:43:36 +08:00
</ div >
2023-08-03 15:31:38 +08:00
2023-08-06 17:43:36 +08:00
</ div >
2023-08-03 15:31:38 +08:00
</ div >
2023-08-08 15:02:26 +08:00
2023-08-03 15:31:38 +08:00
</ div >
2023-08-19 20:39:45 +08:00
< ? php include 'Footer.php' ; ?>
2023-08-03 15:31:38 +08:00
< 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 ;
}
2023-08-07 16:39:19 +08:00
/* For tabs to work */
const triggerTabList = document . querySelectorAll ( '#myTab a' )
triggerTabList . forEach ( triggerEl => {
const tabTrigger = new bootstrap . Tab ( triggerEl )
triggerEl . addEventListener ( 'click' , event => {
event . preventDefault ()
tabTrigger . show ()
})
})
2023-08-03 15:31:38 +08:00
</ script >
2023-08-08 15:02:26 +08:00
</ body >
</ html >