diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 974355a..0000000 Binary files a/.DS_Store and /dev/null differ diff --git a/.gitignore b/.gitignore index faa1838..a0f0e53 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ .vscode - +.DS_Store diff --git a/Admin.php b/Admin.php index 8280aa5..ae92238 100644 --- a/Admin.php +++ b/Admin.php @@ -1,293 +1,289 @@ - - - - - - - - - - -
-
-

Administration Panel

-
- -
-
- - -
- - TA Account Management -
" ; - echo "TA Accounts
" ; - } - else if($_SESSION['user_type'] == "Admin"){ - echo "

Lecturer Account Management

-
"; - echo "Lecturer Accounts
"; - } - - ?> - -
- - - - - -
- -

- - Create TA Accounts "; - - } - else if($_SESSION['user_type'] == "Admin"){ - echo "Create Lecturer Accounts "; - } - - ?> -
- - Full Name - - Email - - - Passport Number / ID (Used as Initial Password) - -
User Type : - - TA (Teaching Assistant) '; - - } - else if($_SESSION['user_type'] == "Admin"){ - - echo " Lecturer "; - - } - - ?> - -
- - '; - $_SESSION['info_Admin_Users'] = null; - } - if (isset($_SESSION['info_Admin_Users'])) { - echo '
'; - $_SESSION['info_Admin_Users'] = null; - } - - ?> - -
- -
- -
- - - - - - - -
-
- -
- -
- -
- - - - - -
- - - -
- -
- - \ No newline at end of file + + + + + + + +
+ + +
+

Administration panel

+ +
+
+ +
+ + + + + +
+ + +
+

Copy & paste student number to the following box, and separate two student numbers with a space.

+
+ + +
+
+ +

+ + Create TA Accounts

"; + } + else if($_SESSION['user_type'] == "Admin"){ + echo "

Create Lecturer Accounts

"; + } + + ?> +
+ + Full name +
+ Email +
+ Initial password (Enter a strong password or leave it empty to let LRR generate one) +
+ User type: + TA (Teaching Assistant) '; + } else if ($_SESSION['user_type'] == "Admin"){ + echo " Lecturer "; + } + + ?> + +

+ + + '; + $_SESSION['info_Admin_Users'] = null; + } + ?> + +
+ +
+ + +

+ + + + + + + + + + console.log('here {$user_id}');"; // debug trick + // find the TAs in the courses taught by this instructor + $ta_result = mysqli_query( + $con, + "SELECT TA FROM course_ta INNER JOIN courses_table ON course_ta.Course_ID=courses_table.Course_ID WHERE courses_table.Lecturer_User_ID=$user_id" + ); + $ta_ids = array(-1); // -1 is non-existent ID + while ($row = mysqli_fetch_assoc($ta_result)) { + array_push($ta_ids, $row['TA']); + } + $ta_ids2 = implode(', ', $ta_ids); + $result = mysqli_query( + $con, + "SELECT * FROM users_table WHERE UserType in ('TA') and User_ID in ($ta_ids2)" + ); + } + + else if ($_SESSION['user_type'] == "Admin"){ + $result = mysqli_query( + $con, + "SELECT * FROM users_table WHERE UserType in ('Lecturer')" + ); + } + + $num_rows = 0; + while ($row = mysqli_fetch_assoc($result)) { + $pass = $row['Password']; + $btn = ""; + if ($row['Status'] == "Active") { + $newstatus = "Blocked"; + $btnBlock = ""; + } else { + $newstatus = "Active"; + $btnBlock = ""; + } + + echo ""; + $num_rows += 1; + } + if ($num_rows == 0) { + echo "

No TA

"; + } + ?> +
IDNameEmailReset password Block/Activate
" . $row['User_ID'] . "" . $row['Full_Name'] . "" . $row['Email'] . "$btn$btnBlock
+
+ +
+ +
+ +
+ + + +

+ +

Past courses

+ + + + + + + + + + + + "; + } + } + ?> + +
Course nameFacultyLecturerTAsAssign a new TA
$code - $name $faculty $lecturer$ta
+ +
+ +
+ +
+ +
+ + + + + + + + + + + + diff --git a/Course.php b/Course.php index 5dc8583..c469163 100644 --- a/Course.php +++ b/Course.php @@ -6,760 +6,734 @@ include 'NoDirectPhpAcess.php'; + +
+ + - Courses > $name ($code) > Lab Reports
Faculty: $faculty | Year: $academic | Lecturer: $lecturer -
"; - } else { - $ta_name = ""; - while ($row = mysqli_fetch_assoc($ta_result)) { - $ta_name = $ta_name.$row['Full_Name']." "; - } - $ta_name = trim ($ta_name); - echo "
- Courses > $name ($code) > Lab Reports
Faculty: $faculty | Year: $academic | Lecturer: $lecturer | Teaching Assistant: $ta_name -
"; + echo "No course matching the given course URL: ".$course_url; + + } else { + 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']; + $url = $row['URL']; + $course_id = $row['Course_ID']; + // also get teaching assistant names (if any) + $ta_result = mysqli_query($con, "SELECT Full_Name FROM users_table WHERE User_ID IN (SELECT TA FROM course_ta WHERE Course_ID='$course_id');"); + if (mysqli_num_rows($ta_result) == 0) { + echo "
+ Courses > ($code) $name > Assignments
+ Faculty: $faculty   Year: $academic   Lecturer: $lecturer +
"; + } else { + $ta_name = ""; + while ($row = mysqli_fetch_assoc($ta_result)) { + $ta_name = $ta_name.$row['Full_Name']." "; + } + $ta_name = trim($ta_name); + echo "
+ Courses > ($code) $name > Assignments
+ Faculty: $faculty   Year: $academic   Lecturer: $lecturer   Teaching Assistant: $ta_name +
"; + } } - } + } } -} -?> + ?> + + + ' . $_SESSION['info_general'] . ''; + $_SESSION['info_general'] = null; + } + + if (isset($_SESSION['info_courses'])) { + echo '
' . $_SESSION['info_courses'] . '
'; + $_SESSION['info_courses'] = null; + } + ?> + + + +
+ +
+ + + + + +
+ + + + + + + + + + + + + + + + +
+
+ +
+ +

My groups

+ + Create group"; + ?> + +
+ + Invite member "; + + if($status == "Invited") + { + $extra2 = " Accept"; + $extra3 = " Decline"; + } + + echo ""; + } + } + ?> +
+ +
+ + -
- -'; - $_SESSION['info_general']=null; -} - -if (isset($_SESSION['info_courses'])) { - echo '
'; - $_SESSION['info_courses']=null; -} -?> -
+ + + - -
- -
- -
- - - - - -
- - - - - - - - - - - - - - - - - - - - -
- -
- -
-

Class Groups

- - Create Group"; - - ?> - - - -
- Invite Others"; - - if($status=="Invited") - { - $extra2=" Accept"; - $extra3=" Decline"; - - } - - # Add "delete group" button and allow only group creator to delete it - $extra4 = ""; - - echo "
$name ($status) $extra $extra2 $extra3" . - (($status == "Created")? "$extra4": "") - ."
"; - - $rs2=mysqli_query($con,"SELECT `ID`, `Course_Group_id`, course_group_members_table.Student_ID, - course_group_members_table.`Status`,users_table.Full_Name FROM `course_group_members_table` -INNER JOIN users_table on users_table.Student_ID=course_group_members_table.Student_ID -where course_group_members_table.Course_Group_id=$id"); - - #Check whether the current user in session is the creator of the group - $rs3 = mysqli_query($con, "SELECT `Status` from course_group_members_table where Student_ID = $student_id"); - $flag = mysqli_fetch_assoc($rs3)['Status'] == "Created"; - - while($row = mysqli_fetch_assoc($rs2)) { - $name=$row['Full_Name']; - $id=$row['Course_Group_id']; - $status=$row['Status']; - $Student_ID=$row['Student_ID']; - - #Show group members + remove button next to each member except the creator of the group - if($flag){ - echo "
  • $name-$Student_ID ($status)".(($status != "Created")?"":"")."
  • "; - }else{ - echo "
  • $name-$Student_ID ($status)"; - } - - } - - - - - - - - } - } - ?> - - - - - -
  • - -
    - - - - - - - - - - - + + + + diff --git a/Courses.php b/Courses.php index 5bba2fc..2d939a8 100644 --- a/Courses.php +++ b/Courses.php @@ -4,110 +4,99 @@ include 'NoDirectPhpAcess.php'; -$user_d = $_SESSION['user_id']; +
    -if( $_SESSION['user_type']=="Lecturer" || $_SESSION['user_type']=="TA") -{ + + - +
    + + + -
    - - - - - - - - - - -
    - ($code) - $name -
    Faculty: $faculty | Year: $academic | Lecturer: $lecturer -
    -
    - "; - - echo "
    "; + + + 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']; + $url = $row['URL']; + $id = $row['Course_ID']; + $course_id = $row['Course_ID']; + echo "

    ($code) - $name

    +
    + Faculty: $faculty    Year: $academic    Lecturer: $lecturer +
    +
    "; + echo "
    "; + } + + // ------------------------------Editing Lab Assignment by Lecturer ------------------------------------ - if($_GET['act']=="edit"){ + if ($_GET['act'] == "edit") { $getid = mysqli_real_escape_string($con, $_GET["cid"]); $result1 = mysqli_query($con, "SELECT * from lab_reports_table WHERE Lab_Report_ID = '$getid'"); - while($row1 = mysqli_fetch_assoc($result1)) { $Deadline = $row1['Deadline']; $_SESSION['Date'] = trim( strstr($Deadline, ' ', true) ); @@ -117,8 +106,8 @@ New Date/Time
    query($sql) === TRUE) { $_SESSION["info_Updated"]="Assignment information updated successfully."; - } else { - // echo "Error: " . $sql . "
    " . $con->error; - echo "Serious error happened whiling updating assignment information."; + echo "Serious error happened while updating assignment information."; } } - - if( $_SESSION['user_type']=="Lecturer"){ + + if (isset($_POST['form_deletelab'])) { + $sql = "DELETE FROM lab_reports_table WHERE Lab_Report_ID='$getid'"; + if ($con->query($sql) === TRUE) { + $_SESSION["info_Updated"]="Assignment deleted successfully."; + } else { + echo "Serious error happened while deleting the assignment."; + } + } + + + if ($_SESSION['user_type'] == "Lecturer") { $Date = $_SESSION['Date']; $Time = $_SESSION['Time']; $Instructions = $_SESSION['Instructions']; $Title = $_SESSION['Title']; $Marks = $_SESSION['Marks']; $Type = $_SESSION['Type']; - - echo "

    Editing Lab Assignment

    "; - ?> -
    - + echo "

    Edit assignment information

    "; + ?> + + - + Deadline Date/Time -
    -
    ">
    -
    ">
    +
    +
    ">
    +
    ">
    Title - "> + "> Instructions - + Marks - "> + "> Attachment 1 - - + Attachment 2 - - + Attachment 3 - - - + Attachment 4 - +
    - - Individual Group"; } else { echo "Submission Type Individual Group"; - } + } ?> +
    +
    +



    +
    + +
    +
    + -
    -



    - - if( $_SESSION['user_type']=="Lecturer"){ +

    New assignment

    - ?> - -

    Post new Lab Assignment

    - -
    - - + + + - - Deadline Date/Time -
    -
    -
    + + Deadline (date and time) +
    +
    +
    Title - - Instructions - - Marks - + + Instruction + + Mark + Attachment 1 - - + Attachment 2 - - + Attachment 3 - - - + Attachment 4 - +
    - Submission Type Individual + Submission type: Individual - Group + Group
    -
    -



    -"; - - echo "

    Lab Report Assignment list

    "; - - error_reporting(0); - if(isset($_SESSION["info_Updated"])){ - echo '
    '; - $_SESSION['info_Updated'] = null; +
    +



    + '; - $_SESSION['info_courses'] = null; - } - if (isset($_SESSION['info_courses'])) { - echo '
    '; - $_SESSION['info_courses']=null; - } - - - - - $result = mysqli_query($con," SELECT `Lab_Report_ID`,Type,Marks, `Course_ID`, `Posted_Date`, `Deadline`, `Instructions`, `Title`, `Attachment_link_1`, `Attachment_link_2`, `Attachment_link_3`, " - . "`Attachment_link_4` FROM `lab_reports_table` WHERE Course_ID=$id ORDER by Lab_Report_ID DESC"); - - - if( $_SESSION['user_type']=="TA") - { - echo "*Only Lecturer can post a new lab report assignment
    "; - } - if(mysqli_num_rows($result)==0) - { - echo "No assignments posted so far."; - - } else { while($row = mysqli_fetch_assoc($result)) { - $marks=$row['Marks']; - $title=$row['Title']; - $ins=$row['Instructions']; - $posted=$row['Posted_Date']; - $deadline=$row['Deadline']; - $att1=$row['Attachment_link_1']; - $att2=$row['Attachment_link_2']; - $att3=$row['Attachment_link_3']; - $att4=$row['Attachment_link_4']; - $id=$row['Lab_Report_ID']; - $cours_id=$row['Course_ID']; - $as_type=$row['Type']; - $full_link="$att1"; - - if($att2!=""){ - $full_link= $full_link."  |  $att2"; - } - if($att3!=""){ - $full_link= $full_link."  |  $att3"; - } - - if($att4!=""){ - $full_link= $full_link."   |   $att4"; - } - - - - - $resultx1 = mysqli_query($con,"Select Count(*) as cnt from lab_report_submissions where lab_report_submissions.Lab_Report_ID=$id"); - while($row = mysqli_fetch_assoc($resultx1)) {$count_subs=$row['cnt'];} - - $resultx2 = mysqli_query($con,"Select COUNT(*) as cnt from lab_report_submissions where lab_report_submissions.Lab_Report_ID=$id and Marks is not null"); - if(mysqli_num_rows($resultx2)==0){$count_marked=0;} else { while($row = mysqli_fetch_assoc($resultx2)) {$count_marked =$row['cnt'];}} - - - $header="Courses > ".$name."($code) > Assignments > ".$title; - - echo "
    - $title ($as_type)
    $ins - -
    Posted : $posted Deadline : $deadline   ($marks Marks)           " - . "
    " - - . "    $count_subs Submissions ( $count_marked Marked )       Edit   |   View    |   Extend Deadline
    Attachments : $full_link
    " - . "  
    - "; - - - - }} - echo "
    "; - - - - - - $resultx1 = mysqli_query($con,"SELECT course_students_table.Student_ID,users_table.Full_Name FROM -`course_students_table` -INNER JOIN users_table on users_table.Student_ID=course_students_table.Student_ID -WHERE Course_ID=$course_id"); - - - echo ""; - - - - - return; - - } - - ?> - - - - - "; - - - $result = mysqli_query($con,"SELECT `Course_ID`, `Course_Name`, `Academic_Year`, `Faculty`, " - . "`Lecturer_User_ID`, `TA_User_ID`, `Course_Code`, `URL`, `Verify_New_Members` , users_table.Full_Name FROM `courses_table` INNER JOIN users_table ON users_table.User_ID=courses_table.Lecturer_User_ID where courses_table.Lecturer_User_ID=$user_d"); - - if($_SESSION['user_type']=="TA") - { - $result = mysqli_query($con,"SELECT course_ta.Course_ID, `Course_Name`, - `Academic_Year`, `Faculty`, `Lecturer_User_ID`, `TA_User_ID`, `Course_Code`, `URL`, `Verify_New_Members` FROM `courses_table` -INNER JOIN -course_ta ON course_ta.Course_ID=courses_table.Course_ID where course_ta.TA=$user_d"); - - } - // $result = mysqli_query($con,"SELECT `Course_ID`, `Course_Name`, `Academic_Year`, `Faculty`, `Lecturer_User_ID`, `TA_User_ID`, `Course_Code`, `URL`, `Verify_New_Members` , users_table.Full_Name FROM `courses_table` INNER JOIN users_table ON users_table.User_ID=courses_table.Lecturer_User_ID"); - - - if(mysqli_num_rows($result)==0) - {} else { while($row = mysqli_fetch_assoc($result)) { - $id=$row['Course_ID']; - $name=$row['Course_Name']; - $code=$row['Course_Code']; - $faculty=$row['Faculty']; - $lecturer=$row['Full_Name']; - $academic=$row['Academic_Year']; - $url=$row['URL']; - - $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=$id"); - - $ta=""; - while($rowTA = mysqli_fetch_assoc($resultTA)) { - $ta=$ta." - ".$rowTA['TA_NAME']; } - - - - echo" - -
    - ($code) - $name -
    Faculty : $faculty        Year : $academic        Lecturer :$lecturer        TA:$ta -
    - "; - - }}?> -
    -
    -
    - Course Joining Requests - - - No Course joining request so far for all your courses
    "; - } else { while($row = mysqli_fetch_assoc($result)) { - $id=$row['ID']; - - $name=$row['Course_Name']; - $code=$row['Course_Code']; - $faculty=$row['Faculty']; - $std_name=$row['Full_Name']; - $academic=$row['Academic_Year']; - - echo "
    - $std_name is Requesting to join
    [($code) - $name ]     
    Accept -    Decline -
    "; - - - } - } - ?> + echo "
    "; + echo "

    Assignment list

    "; + error_reporting(0); + if (isset($_SESSION["info_Updated"])) { + echo '
    '; + $_SESSION['info_Updated'] = null; + } + if (isset($_SESSION['info_courses'])) { + echo '
    '; + $_SESSION['info_courses'] = null; + } + if (isset($_SESSION['info_courses'])) { + echo '
    '; + $_SESSION['info_courses']=null; + } + if( $_SESSION['user_type'] == "TA") { + echo "Only Lecturer can post assignments.
    "; + } + $result = mysqli_query($con, "SELECT Lab_Report_ID, Type, Marks, Course_ID, Posted_Date, Deadline, Instructions, Title, Attachment_link_1, Attachment_link_2, Attachment_link_3, Attachment_link_4 + FROM lab_reports_table + WHERE Course_ID=$id ORDER BY Lab_Report_ID DESC"); + if(mysqli_num_rows($result)==0) { + echo "No assignments posted so far."; + } else { + while ($row = mysqli_fetch_assoc($result)) { + $marks = $row['Marks']; + $title = $row['Title']; + $ins = $row['Instructions']; + $posted = $row['Posted_Date']; + $deadline = $row['Deadline']; + $att1 = $row['Attachment_link_1']; + $att2 = $row['Attachment_link_2']; + $att3 = $row['Attachment_link_3']; + $att4 = $row['Attachment_link_4']; + $id = $row['Lab_Report_ID']; + $cours_id = $row['Course_ID']; + $as_type = $row['Type']; + $full_link = "$att1"; + if ($att2 != "") { + $full_link = $full_link."  |  $att2"; + } + if ($att3 != "") { + $full_link = $full_link."  |  $att3"; + } + if ($att4 != "") { + $full_link = $full_link."   |   $att4"; + } - -Only Lecturers can Post new Lab report Assignments"; - } - if( $_SESSION['user_type']=="Lecturer"){ ?> - - Create new Course Portal - -
    - - - Course Name - + $resultx1 = mysqli_query($con, "SELECT COUNT(*) AS cnt FROM lab_report_submissions WHERE lab_report_submissions.Lab_Report_ID=$id"); + while ($row = mysqli_fetch_assoc($resultx1)) { + $count_subs = $row['cnt']; + } - Course Code - + $resultx2 = mysqli_query($con, "SELECT COUNT(*) AS cnt FROM lab_report_submissions WHERE lab_report_submissions.Lab_Report_ID=$id AND Marks IS NOT null"); + if (mysqli_num_rows($resultx2) == 0) { + $count_marked = 0; + } else { + while ($row = mysqli_fetch_assoc($resultx2)) { + $count_marked = $row['cnt']; + } + } - URL (Leave blank to use Course Code & Year) - + $header="Courses > ".$name."($code) > Assignments > ".$title; - Academic Year - + echo "
    +
    +
    $title ($marks Marks, $as_type)
    +
    $ins
    +

    Posted: $posted    Deadline: $deadline

    +

    $count_subs Submissions ( $count_marked Marked )

    + Edit + View + Extend Deadline +

    Attachments: $full_link

    +
    +
    "; - Faculty
    - - - - - - - Verify Joining Students - Yes - No - -
    -
    - -
    - - - -
    - - - - - - - -
    -
    -
    Course Portal > Students
    -' . $_SESSION['info_Courses_student'] . ''; - $_SESSION['info_Courses_student'] = null; - } - ?> -

    -
    -
    -
    - - - - - -
    -
    - - - - Search Results for Course Code $search
    "; - $result = mysqli_query($con,"SELECT `Course_ID`, `Course_Name`, `Academic_Year`, `Faculty`," - . " `Lecturer_User_ID`, `TA_User_ID`, `Course_Code`, `URL`, `Verify_New_Members` " - . " , users_table.Full_Name FROM `courses_table` INNER JOIN users_table" - . " ON users_table.User_ID=courses_table.Lecturer_User_ID where Academic_Year >= $oldest_academic_year and Course_Code like '%{$search}%' and courses_table.Course_ID not in (select course_id from course_students_table where Student_ID=$student_id) order by Academic_Year desc"); - } - // the user has entered something under "Find course by Code" - else - { - echo "

    Find Courses under faculty $faculty

    "; - $result = mysqli_query($con,"SELECT `Course_ID`, `Course_Name`, `Academic_Year`, `Faculty`, - `Lecturer_User_ID`, `TA_User_ID`, `Course_Code`, `URL`, `Verify_New_Members` - , users_table.Full_Name FROM `courses_table` INNER JOIN users_table - ON users_table.User_ID=courses_table.Lecturer_User_ID where Academic_Year >= $oldest_academic_year and Faculty='$faculty' and courses_table.Course_ID not in (select course_id from course_students_table where Student_ID=$student_id) order by Academic_Year desc"); - } - - - if(mysqli_num_rows($result)==0) - { - echo "No results found for your Search
    "; - - } else { - - 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']; - $url=$row['URL']; - $id=$row['Course_ID']; - $v=$row['Verify_New_Members']; - $msg2="Join Course"; - if($v>0) - { - $msg=" Lecturer verification required"; - $msg2="Send Joining Request"; } - - echo "
    - [$code] $name
    ($url)
    $msg2 -
    Faculty: $faculty | Year: $academic | Lecturer: $lecturer
    $msg
    - "; } - } - } - // Otherwise, list the student's joined courses (already done), in reverse chronological order - echo "

    My Courses

    "; - $result = mysqli_query($con,"SELECT users_table.Full_Name, course_students_table.Status, courses_table.Course_ID, `Course_Name`, `Academic_Year`, `Faculty`, `Lecturer_User_ID`, `TA_User_ID`, `Course_Code`, `URL`, `Verify_New_Members` FROM `courses_table` -INNER JOIN users_table - ON users_table.User_ID=courses_table.Lecturer_User_ID + echo "
    "; -INNER JOIN course_students_table on course_students_table.Course_ID=courses_table.Course_ID + $resultx1 = mysqli_query($con, "SELECT DISTINCT course_students_table.Student_ID, users_table.Full_Name + FROM course_students_table + INNER JOIN users_table on users_table.Student_ID=course_students_table.Student_ID + WHERE Course_ID=$course_id"); - where course_students_table.Student_ID=$student_id order by Academic_Year desc"); - - if(mysqli_num_rows($result)==0) - { - echo " You are not Enrolled in any Course"; - } else { - 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']; - $url=$row['URL']; - $id=$row['Course_ID']; - $Status=$row['Status']; - - if($Status=="Joined") - { - echo "
    - ($code) - $name
    ($url)     $Status     
    Open -
    Faculty : $faculty Year : $academic Lecturer :$lecturer
    - "; + echo ""; + return; + } + + ?> + + + +
    + + My courses"; + + $result = mysqli_query($con, "SELECT Course_ID, Course_Name, Academic_Year, Faculty, Lecturer_User_ID, TA_User_ID, Course_Code, URL, Verify_New_Members, users_table.Full_Name + FROM courses_table + INNER JOIN users_table ON users_table.User_ID=courses_table.Lecturer_User_ID + WHERE courses_table.Lecturer_User_ID=$user_id + ORDER BY Academic_Year DESC, URL ASC"); + + if ($_SESSION['user_type'] == "TA") { + $result = mysqli_query($con, "SELECT course_ta.Course_ID, Course_Name, Academic_Year, Faculty, Lecturer_User_ID, TA_User_ID, Course_Code, URL, Verify_New_Members + FROM courses_table + INNER JOIN course_ta ON course_ta.Course_ID=courses_table.Course_ID + WHERE course_ta.TA=$user_id"); + } + + if (mysqli_num_rows($result) != 0) { + while ($row = mysqli_fetch_assoc($result)) { + $id = $row['Course_ID']; + $name = $row['Course_Name']; + $code = $row['Course_Code']; + $faculty = $row['Faculty']; + $lecturer = $row['Full_Name']; + $academic = $row['Academic_Year']; + $url = $row['URL']; + $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=$id"); + $ta = ""; + + while ($rowTA = mysqli_fetch_assoc($resultTA)) { + $ta = $ta." ".$rowTA['TA_NAME']; + } + + if ($ta == "") { + $ta = " None"; + } + + + echo" +
    + ($code) - $name +

    Faculty: $faculty        Year: $academic        Lecturer: $lecturer        TA:$ta

    +
    +
    "; + } + } + ?> + +
    +
    +
    + Course joining requests + + No course-joining request so far for your courses
    "; + } else { + while ($row = mysqli_fetch_assoc($result)) { + $id = $row['ID']; + $name = $row['Course_Name']; + $code = $row['Course_Code']; + $faculty = $row['Faculty']; + $student_name = $row['Full_Name']; + $academic = $row['Academic_Year']; + echo "
    - ($code) - $name $Status -
    Faculty : $faculty Year : $academic Lecturer :$lecturer
    - "; + $student_name is Requesting to join
    [($code) - $name ]     
    + Accept    Decline +
    "; + } + } + ?> + + + Only Lecturer can post assignments"; + } + + if ($_SESSION['user_type'] == "Lecturer"){ + ?> + + Create a new course + +
    + + + Course name + + + Course code + + + URL (leave blank to use course code & year) + + + Academic year + + + Faculty
    + + + + + Verify joining students? + Yes + No + +

    +
    + +
    + + + +
    + + + + + + +
    +
    + + ' . $_SESSION['info_Courses_student'] . ''; + $_SESSION['info_Courses_student'] = null; + } + if (isset($_SESSION['info_signup'])) { + echo '
    '; + $_SESSION['info_signup'] = null; + } + ?> +

    +
    +
    +
    + + +
    +
    + + Search results for course code: $search
    "; + $result = mysqli_query($con, "SELECT Course_ID, Course_Name, Academic_Year, Faculty, Lecturer_User_ID, TA_User_ID, Course_Code, URL, Verify_New_Members, users_table.Full_Name + FROM courses_table + INNER JOIN users_table + ON users_table.User_ID=courses_table.Lecturer_User_ID + WHERE Academic_Year >= $oldest_academic_year AND Course_Code LIKE '%{$search}%' AND courses_table.Course_ID NOT IN + (SELECT course_id FROM course_students_table WHERE Student_ID=$student_id) ORDER BY Academic_Year DESC"); + } else if ($faculty != "") { // the user has entered something under "Find course by Code" + echo "

    Find courses under faculty: $faculty

    "; + $result = mysqli_query($con, "SELECT Course_ID, Course_Name, Academic_Year, Faculty, Lecturer_User_ID, TA_User_ID, Course_Code, URL, Verify_New_Members, users_table.Full_Name + FROM courses_table + INNER JOIN users_table ON users_table.User_ID=courses_table.Lecturer_User_ID + WHERE Academic_Year >= $oldest_academic_year AND Faculty='$faculty' AND courses_table.Course_ID NOT IN + (SELECT course_id FROM course_students_table WHERE Student_ID=$student_id) ORDER BY Academic_Year DESC"); + } + + if (mysqli_num_rows($result) == 0) { + echo "No such course offered in this academic year. Please check that your have entered the correct course code.
    "; + } else { + 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']; + $url = $row['URL']; + $id = $row['Course_ID']; + $v = $row['Verify_New_Members']; + if($v > 0) { + $msg = " Lecturer verification required"; + $msg2 = "Send Joining Request"; + } + + echo "
    + ($code) $name
    ($url)
    + Join
    + Faculty: $faculty   Year: $academic   Lecturer: $lecturer
    + $msg +
    "; + } + } + } + // Otherwise, list the student's joined courses (already done), in reverse chronological order + echo "

    My courses

    "; + $result = mysqli_query($con, "SELECT users_table.Full_Name, course_students_table.Status, courses_table.Course_ID, Course_Name, Academic_Year, Faculty, Lecturer_User_ID, TA_User_ID, Course_Code, URL, Verify_New_Members + FROM courses_table + INNER JOIN users_table ON users_table.User_ID=courses_table.Lecturer_User_ID + INNER JOIN course_students_table ON course_students_table.Course_ID=courses_table.Course_ID + WHERE course_students_table.Student_ID=$student_id ORDER BY Academic_Year DESC, URL ASC"); + + if (mysqli_num_rows($result) == 0) { + echo " You are not enrolled in any Course"; + } else { + while($row = mysqli_fetch_assoc($result)) { + $name = $row['Course_Name']; + $code = $row['Course_Code']; + $faculty = $row['Faculty']; + $lecturer = $row['Full_Name']; + $academic_year = $row['Academic_Year']; + $url = $row['URL']; + $id = $row['Course_ID']; + $status = $row['Status']; + if($status == "Joined") { + echo " +
    + ($code) $name
    + ($url)     $status     
    + Faculty: $faculty   Year: $academic_year   Lecturer: $lecturer +
    +
    "; + } else { + echo "
    + ($code) $name $status
    + Faculty: $faculty   Year: $academic_year   Lecturer: $lecturer +
    "; + } + } + } + + echo "
    + +
    +
    +
    +
    +
    + Find new course by course code + +
    + +
    + List courses by faculty + -
    -List courses by faculty - +
    - } else { - echo""; - while($row = mysqli_fetch_assoc($result)) { - $fname=$row['Faculty']; - echo " "; - }} - - echo "
    - -
    -

    - +

    + +
    +
    +
    - -
    - +
    "; + } + ?> + -
    "; - +
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -} - -?> - - - - - - - - - - - - - - - + + diff --git a/Download.php b/Download.php index d59e90e..42db7d4 100644 --- a/Download.php +++ b/Download.php @@ -25,7 +25,7 @@ $type = filetype($file); $today = date("F j, Y, g:i a"); $time = time(); -if ((isset($_SESSION["user_student_id"]) && strpos($file, $_SESSION["user_student_id"]) > 0) || $_SESSION['user_type'] == "Lecturer" || $_SESSION['user_type'] == "TA" ) { +if ((isset($_SESSION["user_student_id"]) && (strpos($file, $_SESSION["user_student_id"]) > 0 || strpos($file, "Lab_Report_Assignments"))) || $_SESSION['user_type'] == "Lecturer" || $_SESSION['user_type'] == "TA" ) { // 发送文件头部 header("Content-type: $type"); header('Content-Disposition: attachment;filename="'.urldecode($filename).'"'); diff --git a/Footer.php b/Footer.php index de442d2..292966d 100644 --- a/Footer.php +++ b/Footer.php @@ -1,4 +1,3 @@ -








    -
    - -
    \ No newline at end of file +Copyright © 2018-" . date("Y") . " The Authors

    "; +?> diff --git a/Header.php b/Header.php index 63ad2ce..0733467 100644 --- a/Header.php +++ b/Header.php @@ -4,174 +4,197 @@ error_reporting(0); date_default_timezone_set('Asia/Shanghai'); include "get_mysql_credentials.php"; -$con = mysqli_connect("localhost", $mysql_username, $mysql_password, "lrr"); +try { + $con = mysqli_connect("localhost", $mysql_username, $mysql_password, "lrr"); +} catch (mysqli_sql_exception $e) { + echo $e->getMessage(); +} // Check database connection if (mysqli_connect_errno()) { - echo "Failed to connect to MySQL: " . mysqli_connect_error(); + echo " Error number: ".mysqli_connect_errno(); + exit(); } - ?> - + - + + + + LRR - - - - - + + - - - + + + + + - + - h1, - h2, - h3, - h4 { - color: #03407B; - } + - a { - color: #03407B; - } + - .break-word { - word-wrap: break-word; - white-space: -moz-pre-wrap !important; - /* Mozilla, since 1999 */ - white-space: -pre-wrap; - /* Opera 4-6 */ - white-space: -o-pre-wrap; - /* Opera 7 */ - white-space: pre-wrap; - /* css-3 */ - word-wrap: break-word; - /* Internet Explorer 5.5+ */ - white-space: -webkit-pre-wrap; - /* Newer versions of Chrome/Safari*/ - word-break: break-all; - white-space: normal; - } + + + + diff --git a/NoDirectPhpAcess.php b/NoDirectPhpAcess.php index 4e85779..3a3dafe 100644 --- a/NoDirectPhpAcess.php +++ b/NoDirectPhpAcess.php @@ -1,7 +1,7 @@ diff --git a/README.md b/README.md index b48e53a..e14051a 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,9 @@ LRR (Lab Report Repository) is an online software application for course instructors to post, receive and mark assignments, and for students to submit assignments, or submit re-marking requests. This software was originally developed by Mahomed Nor in 2018, a graduate student in the Department of Computer Science at the Zhejiang Normal University, -while he was taking a graduate course called **Advanced Software Engineering** (http://lanlab.org/course/2018f/se/homepage.html). +while he was taking a graduate course called Advanced Software Engineering. -The LRR's project home page is at http://121.4.94.30/homepage/. For potential project contributors, we recommend that you browse its home page first to familiarize yourself with the project. +For potential project contributors, we recommend that you browse its home page at ./homepage/index.html first to familiarize yourself with the project. @@ -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'`. 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 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 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 username -p lrr < lrr_database_dump.sql`. You must create database `lrr` first on your computer before doing the import. 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. We need to set a proper owner and accessibility for `lrr_submission` using the following two commands: @@ -51,6 +51,31 @@ Enable the site lrr: `sudo a2ensite lrr`. Restart the apache server: `sudo syst Visit the LRR application by entering this URL in a web browser: http://121.4.94.30/. +### Solving the coding problems in the dump file + +If the database contains Chinese characters, the dump file (e.g., lrr_database_dump.sql) may contain *weird* characters, e.g., `研究生`, so weird that no one can tell their meaning. + +We need to correct these abnormal characters before we import them to the new database, so that the PHP program can correctly display Chinese information. + +The simplest solution is using the ftfy (fixes text for you) Python package to convert them, as follows: + +``` +from ftfy import fix_text + +with open('lrr_database_dump.sql') as f: + content = f.read() + +content2 = fix_text(content) +with open('lrr_database_dump_sql_fixed.txt', 'w') as f: + f.write(content2) +``` + +Now, import data using lrr_database_dump_sql_*fixed*.txt. + +If you encounter the 'Unknown MySQL server host' problem during import, replace all apostrophes with a space in the dump file. For example, if a database table field contains *can't*, then the apostrophe between *n* and *t* can cause that problem. + + + ## Enock steps Enock, a graduate student here, has made a tutorial about how he deployed LRR to a remote server (http://lanlab.org/course/2021s/spm/PuTTY-Server.txt). @@ -134,7 +159,16 @@ https://github.com/spm2020spring/TeamCollaborationTutorial/blob/master/team.rst ## Testing -Make sure your changes can pass all the tests in folder [./test](http://121.4.94.30:3000/mrlan/LRR/src/branch/master/test). +Make sure your changes can pass all the tests in folder ./test. + +You cannot do too much unit testing for LRR because it almost does not +have functions or classes. However, you can do end-to-end testing. +It is important that you *restore* the database each time before your +run a test case. The fixture *restore_database* in ./test/conftest.py +is used to restore the database. Please check that. A use case for +this fixture can be found in the test script +./test/SeleniumMpiana/test_bug418_yaaqob.py. You could run this test script +by typing the following command: `pytest ./SeleniumMpiana/test_bug418_yaaqob.py` ## Communications Method @@ -148,10 +182,10 @@ We can also communicate through pull requests. You make a pull request, I revie ## Frequently Asked Questions -1. Q: The web application's front page does not show properly, i.e., elements are not well aligned. +1. Q: The web application's front page does not show properly, i.e., elements are not well aligned. A: You missed two folders `css` and `font-awesome`. These folders include third-party js or css files and therefore are not included. -1. Q: What if I do not have any information about the `lrr` database? +1. Q: What if I do not have any information about the `lrr` database? A: You could use `lrr_database.sql` to make a new database. @@ -224,6 +258,6 @@ Nicole-Rutagengwa - Nicole Rutagengwa - 2019169 # References -- 詹沈晨. (2020). [网页程序测试自动化 (Selenium) 测试效率](http://lanlab.org/ZhanShenchen-On-Automated-Web-Application-Test-Efficiency-with-Selenium.doc) +- 詹沈晨. (2020). 网页程序测试自动化 (Selenium) 测试效率. -- Ibrahim. (2021). [Defect analysis for LRR](http://lanlab.org/thesis/Defect-Analysis-for-LRR.docx) +- Ibrahim. (2021). Defect analysis for LRR] diff --git a/Reset_password.php b/Reset_password.php deleted file mode 100644 index d08d9ab..0000000 --- a/Reset_password.php +++ /dev/null @@ -1,49 +0,0 @@ - - -
    - -
    - -
    - -

    Reset your password

    -
    - -
    -
    - - - Email - -
    - New Password - - -
    - -
    - -
    -
    - -
    -
    - -
    - - - diff --git a/Script.php b/Script.php index c0bfd7e..ce42cf1 100644 --- a/Script.php +++ b/Script.php @@ -2,6 +2,7 @@ include 'NoDirectPhpAcess.php'; ?> + . Thanks."; - header("Location: signup.php"); - return; - } - - - // Check if the student number isn't already registered - - $student_result = mysqli_query($con, "SELECT * FROM `users_table` WHERE Student_ID='$student_id'"); - if (mysqli_num_rows($student_result) > 0) { - $_SESSION["info_signup"] = "This Student ID is already in use! Please contact Student Management Office for help."; - header("Location: signup.php"); - return; - } -} - -// ############################### CREATE STUDENT USER ################################## -if (!empty($_POST["form_signup"])) { - $fullname = mysqli_real_escape_string($con, $_POST["fullname"]); - $student_id = mysqli_real_escape_string($con, $_POST["user_student_id"]); $email = mysqli_real_escape_string($con, $_POST["email"]); $password = mysqli_real_escape_string($con, $_POST["password"]); $confirmpassword = mysqli_real_escape_string($con, $_POST["confirmpassword"]); - $_SESSION['user_fullname'] = $fullname; - $_SESSION['user_type'] = "Student"; - $_SESSION['user_email'] = $email; - $_SESSION['user_student_id'] = $student_id; - - // check confirmed password - if (strcasecmp($password, $confirmpassword) != 0) { - $_SESSION['info_signup'] = "Password confirmation failed."; - $_SESSION['user_fullname'] = null; // such that Header.php do not show the header information. - header("Location: signup.php"); - return; - } - - // validate email - if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { - $_SESSION['info_signup'] = "Invalid email address."; - header("Location: signup.php"); - return; - } $upperLetter = preg_match('@[A-Z]@', $password); $smallLetter = preg_match('@[a-z]@', $password); @@ -103,19 +53,128 @@ if (!empty($_POST["form_signup"])) { return; } + // Check confirmed password + if (strcasecmp($password, $confirmpassword) != 0) { + $_SESSION['info_signup'] = "Password confirmation failed."; + header("Location: signup.php"); + return; + } + + // validate email + if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { + $_SESSION['info_signup'] = "Invalid email address."; + header("Location: signup.php"); + return; + } + // check if email is taken $result = mysqli_query($con, "SELECT * FROM users_table WHERE email='$email'"); if (mysqli_num_rows($result) != 0) { - $_SESSION["info_signup"] = "Email address " . $email . " is already in use."; + $_SESSION["info_signup"] = "Email address " . $email . " is already in use. You have already signed up?"; + } + + $_SESSION['user_fullname'] = $_POST["fullname"]; + $_SESSION['user_fullname_temp'] = $_POST["fullname"]; + $_SESSION['user_email'] = $_POST["email"]; + $_SESSION['user_student_id_temp'] = $_POST["user_student_id"]; + + + + // validate student number + if (!is_valid_student_number($student_id)) { + $_SESSION["info_signup"] = "Invalid student number."; $_SESSION['user_fullname'] = null; header("Location: signup.php"); return; } + // Check if this student number is a legal one + $result = mysqli_query($con, "SELECT * FROM `students_data` WHERE Student_ID='$student_id'"); + if (mysqli_num_rows($result) == 0) { + $_SESSION["info_signup"] = "Your entered student number could not be verified. Please contact Student Management Office . Thanks."; + $_SESSION['user_fullname'] = null; + + + + header("Location: signup.php"); + return; + } + + + // Check if the student number isn't already registered + + $student_result = mysqli_query($con, "SELECT * FROM `users_table` WHERE Student_ID='$student_id'"); + if (mysqli_num_rows($student_result) > 0) { + $_SESSION["info_signup"] = "This Student ID is already in use! Please contact Student Management Office for help."; + $_SESSION['user_fullname'] = null; + header("Location: signup.php"); + return; + } +} + +// ############################### CREATE STUDENT USER ################################## +if (!empty($_POST["form_signup"])) { + $fullname = mysqli_real_escape_string($con, $_POST["fullname"]); + $student_id = mysqli_real_escape_string($con, $_POST["user_student_id"]); + + $email = mysqli_real_escape_string($con, $_POST["email"]); + $password = mysqli_real_escape_string($con, $_POST["password"]); + $confirmpassword = mysqli_real_escape_string($con, $_POST["confirmpassword"]); + + $_SESSION['user_student_id'] = $_POST["student_id"]; + $_SESSION['user_type'] = "Student"; + + // check confirmed password + if (strcasecmp($password, $confirmpassword) != 0) { + $_SESSION['info_signup'] = "Password confirmation failed."; + $_SESSION['user_fullname'] = null; // such that Header.php do not show the header information. + header("Location: signup.php"); + return; + } + + // validate email + if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { + $_SESSION['info_signup'] = "Invalid email address."; + $_SESSION['user_fullname'] = null; + + header("Location: signup.php"); + return; + } + + $upperLetter = preg_match('@[A-Z]@', $password); + $smallLetter = preg_match('@[a-z]@', $password); + $containsDigit = preg_match('@[0-9]@', $password); + $containsSpecial = preg_match('@[^\w]@', $password); + $containsAll = $upperLetter && $smallLetter && $containsDigit && $containsSpecial; + + // check for strong password + if (!$containsAll) { + $_SESSION['info_signup'] = "Password must have at least characters that include lowercase letters, uppercase letters, numbers and special characters (e.g., !?.,*^)."; + $_SESSION['user_fullname'] = null; + + header("Location: signup.php"); + return; + } + + // check if email is taken + $result = mysqli_query($con, "SELECT * FROM users_table WHERE email='$email'"); + if(mysqli_num_rows($result) != 0) + { + $_SESSION["info_signup"]="Email address ".$email." is already in use. Do you have an old LRR account?"; + } + + + $_SESSION['user_type'] = "Student"; + $_SESSION['user_email'] = $email; + $_SESSION['user_student_id'] = $student_id; + // apply password_hash() $password_hash = password_hash($password, PASSWORD_DEFAULT); - $sql = "INSERT INTO `users_table`(`Email`, `Password`, `Full_Name`, `UserType`, `Student_ID`) VALUES " - . "('$email','$password_hash','$fullname','Student','$student_id')"; + $sql = "INSERT INTO `users_table`(`Email`, `Password`, `HashPassword`, `Full_Name`, `UserType`, `Student_ID`) VALUES " + . "('$email','$password_hash','','$fullname','Student','$student_id')"; + + + $_SESSION['user_fullname'] =$_SESSION['user_fullname_temp']; if ($con->query($sql) === TRUE) { header("Location: Courses.php"); @@ -126,16 +185,20 @@ if (!empty($_POST["form_signup"])) { // ################################ LOGIN ##################################### -if (!empty($_POST["frm_login"])) { +if (!empty($_POST["form_login"])) { $user = mysqli_real_escape_string($con, $_POST["user"]); // user could be a 12-digit student number or an email address $is_student_number = 0; + $_SESSION["failed_login_user"] = $user; // Save the entered username in a session variable + echo "Failed login user: " . $_SESSION["failed_login_user"]; + // Validate student number if (is_valid_student_number($user)) { $is_student_number = 1; } + // Validate email address if what provided is not a student number if (!$is_student_number && !filter_var($user, FILTER_VALIDATE_EMAIL)) { $_SESSION["info_login"] = "Invalid email address: " . "$user"; @@ -177,17 +240,26 @@ if (!empty($_POST["frm_login"])) { header("Location: Admin.php"); } // report wrong pass if not correct - } else { + return; + + } else { + $_SESSION["wrong_pass"] = "Wrong Password."; + echo $_SESSION["wrong_pass"]; // Optional: Display the error message for debugging + header("Location: index.php"); + exit(); // Add this line to prevent further execution after redirect } + // Add the following line to reset the session variable when needed + unset($_SESSION["failed_login_user"]); + } } } // ################################ Recover Password ##################################### -if (!empty($_POST["frm_recover_password"])) { +if (!empty($_POST["form_recover_password"])) { $student_id = mysqli_real_escape_string($con, $_POST["sno"]); $email = mysqli_real_escape_string($con, $_POST["email"]); @@ -218,78 +290,53 @@ if (!empty($_POST["frm_recover_password"])) { } } -// ################################ RESET Password ##################################### - -if (!empty($_POST["frm_reset_password"])) { - $password = mysqli_real_escape_string($con, $_POST["password"]); - $token = mysqli_real_escape_string($con, $_POST["token"]); - $email = mysqli_real_escape_string($con, $_POST["email"]); - $result = mysqli_query( - $con, - "SELECT * FROM Users_Table WHERE email='$email'" - ); - if (mysqli_num_rows($result) == 0) { - - echo "invalid email"; - return; - } else { - while ($row = mysqli_fetch_assoc($result)) { - - $userid = $row['User_ID']; - - $email = $row['Email']; - $id = $row['Student_ID']; - - $user_token = $userid * $userid * $userid + $userid * 0.00343; - if ($user_token == $token) { - // Password Update - - // Password Update - $hashed_password = hash('sha512', $password); - $sql = "UPDATE users_table set HashPassword='$hashed_password' where User_ID='$userid';"; - if ($con->query($sql) === TRUE) { - - error_reporting(0); - - $_SESSION["info_login"] = " Password changed successfully , you can login now with your new password "; - header("Location: index.php"); - } else { - echo "Error: " . $sql . "
    " . $con->error; - } - } else { - echo "Invalid Token "; - } - } - } -} - // ############################### CREATE Lecturer/TA USER ################################## -if (!empty($_POST["frm_createlecturrer"])) { +if (!empty($_POST["form_createlecturer"])){ $email = mysqli_real_escape_string($con, $_POST["email"]); $fullname = mysqli_real_escape_string($con, $_POST["fullname"]); $type = mysqli_real_escape_string($con, $_POST["type"]); - $password = mysqli_real_escape_string($con, $_POST["passport"]); - // check if email is taken + $password = mysqli_real_escape_string($con, $_POST["password"]); + $pass_len = strlen($password); + if ($pass_len == 0) { + $password = generateStrongPassword(); + } + $result = mysqli_query( $con, - "SELECT * FROM Users_Table WHERE email='$email'" + "SELECT * FROM users_table WHERE email='$email'" ); if (mysqli_num_rows($result) != 0) { $_SESSION["info_Admin_Users"] = "Email address : " . $email . " is already in use."; header("Location: Admin.php"); + exit; } $password_hash = password_hash("$password", PASSWORD_DEFAULT); - $sql = "INSERT INTO `users_table`(`Email`, `Password`, `Full_Name`, `UserType`) VALUES " - . "('$email','$password_hash','$fullname','$type')"; + $sql = "INSERT INTO `users_table`(`Email`, `Password`, `HashPassword`, `Full_Name`, `UserType`) VALUES ('$email','$password_hash','','$fullname','$type')"; - if ($con->query($sql) === TRUE) { - $_SESSION["info_Admin_Users"] = $type . " user created successfully. Use email " . $email . " as account name and $password as password."; - header("Location: Admin.php"); - } else { - echo "Error: " . $sql . "
    " . $con->error; + try { + $result = mysqli_query($con, $sql); + $_SESSION["info_Admin_Users"] = $type . " user created successfully. Use email " . $email . " as account name and ". $password ." as password."; + header("Location: Admin.php?tacreated"); + } catch (Exception $ex) { + echo "$ex"; } } +// ### FUNCTION TO GENERATE INITIAL PASSWORDS ###// +function generateStrongPassword() { + + $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_'; + $password_length = 12; + $gen_password = ''; + for ($i = 0; $i < $password_length; $i++) { + $random_index = mt_rand(0, strlen($characters) - 1); + $gen_password .= $characters[$random_index]; + } + + // Return the generated password + return $gen_password; +} + // #### FUNCTION CHECK FILE TYPES //// function is_valid_file_format($file) @@ -340,7 +387,7 @@ function mkdirs($path) } // ############################### #Post Assignment ################################## -if (!empty($_POST["frm_uploadlab"])) { +if (!empty($_POST["form_uploadlab"])) { $course_id = mysqli_real_escape_string($con, $_POST["course_id"]); $deadlinedate = $_POST["deadlinedate"]; @@ -357,7 +404,7 @@ if (!empty($_POST["frm_uploadlab"])) { // GET UPLOADED FILES - $target_dir = Create_dir("Lab_Report_Assignments/" . $title . "/"); + $target_dir = Create_dir("./../../lrr_submission/Lab_Report_Assignments/$course_id/" . $title . "/"); $rnd = rand(10, 1000); $rnd = ""; // no more required , creating folder for each lab @@ -416,16 +463,16 @@ if (!empty($_POST["frm_uploadlab"])) { $targetfile4 = ""; if ($_FILES['attachment1']['name'] != "") { - $targetfile = "/" . $title . "/" . $_FILES['attachment1']['name']; + $targetfile = "/Lab_Report_Assignments/$course_id/" . $title . "/" . $_FILES['attachment1']['name']; } if ($_FILES['attachment2']['name'] != "") { - $targetfile2 = "/" . $title . "/" . $_FILES['attachment2']['name']; + $targetfile2 = "/Lab_Report_Assignments/$course_id" . $title . "/" . $_FILES['attachment2']['name']; } if ($_FILES['attachment3']['name'] != "") { - $targetfile3 = "/" . $title . "/" . $_FILES['attachment3']['name']; + $targetfile3 = "/Lab_Report_Assignments/$course_id" . $title . "/" . $_FILES['attachment3']['name']; } if ($_FILES['attachment4']['name'] != "") { - $targetfile4 = "/" . $title . "/" . $_FILES['attachment4']['name']; + $targetfile4 = "/Lab_Report_Assignments/$course_id" . $title . "/" . $_FILES['attachment4']['name']; } $sql = "INSERT INTO `lab_reports_table`(`Course_ID`, `Posted_Date`, `Deadline`, `Instructions`, @@ -434,7 +481,7 @@ if (!empty($_POST["frm_uploadlab"])) { if ($con->query($sql) === TRUE) { - $_SESSION["info_courses"] = $type . " lab report assignment posted successfully."; + $_SESSION["info_courses"] = $type . " lab report assignment posted successfully. "; header("Location: Courses.php?course=" . $url); } else { echo "Error: " . $sql . "
    " . $con->error; @@ -452,7 +499,7 @@ function checksize($file) } // ############################### Submit Assignment ################################## -if (!empty($_POST["frm_submitlab"])) { +if (!empty($_POST["form_submitlab"])) { $lab_id = mysqli_real_escape_string($con, $_POST["lab_id"]); $student_id = $_POST["student_id"]; @@ -585,7 +632,7 @@ if (!empty($_POST["frm_submitlab"])) { $con->query($sql = "UPDATE `lab_report_submissions` SET `Course_Group_id` = '0' WHERE `lab_report_submissions`.`Lab_Report_ID` = '$lab_id'"); } - $_SESSION["info_courses"] = "Thanks. Your lab report assignment is submitted successfully."; + $_SESSION["info_courses"] = "Thanks. You have successfully submitted your assignment."; header("Location: Course.php?url=" . $url); } else { echo "Error:
    " . $con->error; @@ -648,7 +695,7 @@ if (!empty($_GET["savemarks"])) { if ($con->query($sql) === TRUE) { - $_SESSION["info_Marking"] = "Lab Report Submission Marked"; + $_SESSION["info_Marking"] = "Assignment marked"; header("Location: Submissions.php?id=" . $labid . "&header=" . $header . "&total=" . $total); } else { echo "Error: " . $sql . "
    " . $con->error; @@ -693,7 +740,7 @@ if (!empty($_GET["remarking"])) { if ($con->query($sql) === TRUE) { $_SESSION["info_general"] = "Remarking Request Sent"; - header("Location: Course.php?url=" . $url); + header("Location: Course.php?url=" . $url . "&tab=Marked"); } else { echo "Error: " . $sql . "
    " . $con->error; } @@ -815,7 +862,7 @@ if (!empty($_GET["acceptinvite"])) { } if ($con->query($sql) === TRUE) { - $_SESSION["info_general"] = " Group Invite Updated"; + $_SESSION["info_general"] = " Group invitation status updated"; header("Location: Course.php?url=" . $url); } else { echo "Error: " . $sql . "
    " . $con->error; @@ -833,7 +880,7 @@ if (!empty($_GET["removemember"])) { $sql = "Delete from `course_group_members_table` where student_id=$student_id and Course_Group_id=$group_id"; if ($con->query($sql) === TRUE) { - $_SESSION["info_general"] = " Member " . $student_id . " removed from the group"; + $_SESSION["info_general"] = " Member " . $student_id . " is gone."; header("Location: Course.php?url=" . $url); } else { echo "Error: " . $sql . "
    " . $con->error; @@ -867,7 +914,7 @@ if (!empty($_GET["extenddeadline"])) { $time = mysqli_real_escape_string($con, $_GET["time"]); $type = mysqli_real_escape_string($con, $_GET["type"]); - $stdid = mysqli_real_escape_string($con, $_GET["stdid"]); + $studentid = mysqli_real_escape_string($con, $_GET["studentid"]); $reason = mysqli_real_escape_string($con, $_GET["reason"]); $url = mysqli_real_escape_string($con, $_GET["url"]); $deadline = $date . " " . $time; @@ -877,12 +924,12 @@ if (!empty($_GET["extenddeadline"])) { } else { $sql = "INSERT INTO `extended_deadlines_table`(`Student_ID`, " . "`Lab_Report_ID`, `Extended_Deadline_Date`," - . " `ReasonsForExtension`) VALUES ('$stdid','$id','$deadline','$reason')"; + . " `ReasonsForExtension`) VALUES ('$studentid','$id','$deadline','$reason')"; } if ($con->query($sql) === TRUE) { - $_SESSION["info_courses"] = " Lab Report Deadline extended successfully."; + $_SESSION["info_courses"] = " Assignment deadline extended successfully."; header("Location: Courses.php?course=" . $url); } else { echo "Error: " . $sql . "
    " . $con->error; @@ -903,7 +950,7 @@ if (!empty($_GET["ignoreremarking"])) { if ($con->query($sql) === TRUE) { - $_SESSION["info_Marking"] = "Remarking Request Ignored , Submission Updated to 'Marked' status"; + $_SESSION["info_Marking"] = "Remarking request ignored."; header("Location: Submissions.php?id=" . $id . "&header=" . $header . "&total=" . $total); } else { echo "Error: " . $sql . "
    " . $con->error; @@ -913,18 +960,32 @@ if (!empty($_GET["ignoreremarking"])) { #Assign TA if (!empty($_GET["assignTA"])) { - $id = mysqli_real_escape_string($con, $_GET["id"]); $ta = mysqli_real_escape_string($con, $_GET["ta"]); - $sql = "INSERT INTO `course_ta`(`Course_ID`, `TA`) VALUES ('$id','$ta')"; + // Check if the TA is already assigned to the course + $check_sql = "SELECT * FROM course_ta WHERE Course_ID='$id' AND TA='$ta'"; + $check_result = $con->query($check_sql); - if ($con->query($sql) === TRUE) { - - $_SESSION["info_Admin_Courses"] = $type . " Course TA Assigned "; - header("Location: Admin.php"); + if ($check_result->num_rows > 0) { + // Alert user about the duplicate assignment + echo ""; } else { - echo "Error: " . $sql . "
    " . $con->error; + // Proceed with the TA assignment + $sql = "INSERT INTO course_ta(Course_ID, TA) VALUES ('$id','$ta')"; + + if ($con->query($sql) === TRUE) { + $_SESSION["info_Admin_Courses"] = $type . " Course TA Assigned "; + header("Location: Admin.php"); + } else { + echo ""; + } } } @@ -987,20 +1048,19 @@ if (!empty($_GET["action"])) { } } - if ($action == "statuschange" && $_SESSION['user_id'] == $uid && ($_SESSION['user_type'] == "Lecturer" || $_SESSION['user_type'] == "Admin")) { + if ($action == "statuschange" && ($_SESSION['user_type'] == "Lecturer" || $_SESSION['user_type'] == "Admin")) { $sql = "UPDATE users_table set Status='$status' where User_ID='$uid';"; if ($con->query($sql) === TRUE) { $_SESSION["info_Admin_Users"] = $type . " user Status updated successfully "; header("Location: Admin.php"); } else { - // echo "Error: " . $sql . "
    " . $con->error; echo "Something really bad happened while changing status. Contact lanhui at zjnu.edu.cn. Thanks!"; } } } // ############################### CREATE STUDENT USER ################################## -if (!empty($_POST["frm_createCourse"])) { +if (!empty($_POST["form_createCourse"])) { $name = mysqli_real_escape_string($con, $_POST["name"]); $academic = mysqli_real_escape_string($con, $_POST["academic"]); $lecturer = mysqli_real_escape_string($con, $_POST["lecturer"]); @@ -1096,3 +1156,4 @@ WHERE lab_report_submissions.Lab_Report_ID='$lab'"; header("Expires: 0"); print "$header\n$data"; } +?> diff --git a/Student.php b/Student.php index 4541fc5..0c137f6 100644 --- a/Student.php +++ b/Student.php @@ -1,15 +1,14 @@ - - -


    - -
    - -
    -

    Student Account Created. Now you can Browse Course Portals

    -
    - -
    \ No newline at end of file + + +


    + +
    + +
    +

    Student account created. Now you can browse the course portal.

    +
    + +
    diff --git a/Submissions.php b/Submissions.php index 3df7614..29fa29e 100644 --- a/Submissions.php +++ b/Submissions.php @@ -24,22 +24,26 @@ if (!empty($_GET["total"])) { $total = 0; } -$resultx1 = mysqli_query($con, "SELECT `Lab_Report_ID`,Title, lab_reports_table.Course_ID, `Posted_Date`, `Deadline`, `Marks`, `Type` , courses_table.URL FROM `lab_reports_table` INNER JOIN courses_table ON courses_table.Course_ID=lab_reports_table.Course_ID WHERE Lab_Report_ID=$id"); +$resultx1 = mysqli_query($con, "SELECT Lab_Report_ID, Title, lab_reports_table.Course_ID, Posted_Date, Deadline, Marks, Type, courses_table.URL + FROM lab_reports_table + INNER JOIN courses_table ON courses_table.Course_ID=lab_reports_table.Course_ID + WHERE Lab_Report_ID=$id"); while ($row = mysqli_fetch_assoc($resultx1)) { - $Report_Type = $row['Type']; + $report_type = $row['Type']; $c_id = $row['Course_ID']; - $Report_Title = $row['Title']; + $report_title = $row['Title']; $url = $row['URL']; } - -echo " - "; - ?> -
    +"; +?> + + +
    '; + echo '
    ' . $_SESSION['info_Marking'] . '
    '; $_SESSION['info_Marking'] = null; } - $resultx1 = mysqli_query($con, "Select Count(*) as cnt from lab_report_submissions where lab_report_submissions.Lab_Report_ID=$id"); - while ($row = mysqli_fetch_assoc($resultx1)) { - $count_subs = $row['cnt']; - } + $resultx1 = mysqli_query($con, "SELECT Count(*) AS cnt FROM lab_report_submissions WHERE lab_report_submissions.Lab_Report_ID=$id"); + $row = mysqli_fetch_assoc($resultx1); + $count_submissions = $row['cnt']; - $resultx2 = mysqli_query($con, "Select COUNT(*) as cnt from lab_report_submissions where lab_report_submissions.Lab_Report_ID=$id and Status='Marked'"); - if (mysqli_num_rows($resultx2) == 0) { - $count_marked = 0; - } else { - while ($row = mysqli_fetch_assoc($resultx2)) { - $count_marked = $row['cnt']; - } - } + $resultx2 = mysqli_query($con, "SELECT COUNT(*) AS cnt FROM lab_report_submissions WHERE lab_report_submissions.Lab_Report_ID=$id and Status='Marked'"); + $row = mysqli_fetch_assoc($resultx2); + $count_marked = $row['cnt']; - $resultx3 = mysqli_query($con, "Select COUNT(*) as cnt from lab_report_submissions where lab_report_submissions.Lab_Report_ID=$id and Status='Pending'"); - if (mysqli_num_rows($resultx3) == 0) { - $count_unmarked = 0; - } else { - while ($row = mysqli_fetch_assoc($resultx3)) { - $count_unmarked = $row['cnt']; - } - } + $resultx3 = mysqli_query($con, "SELECT COUNT(*) AS cnt FROM lab_report_submissions WHERE lab_report_submissions.Lab_Report_ID=$id and Status='Pending'"); + $row = mysqli_fetch_assoc($resultx3); + $count_unmarked = $row['cnt']; - $resultx4 = mysqli_query($con, "Select COUNT(*) as cnt from lab_report_submissions where lab_report_submissions.Lab_Report_ID=$id and Status='Remarking'"); - if (mysqli_num_rows($resultx4) == 0) { - $count_remark = 0; - } else { - while ($row = mysqli_fetch_assoc($resultx4)) { - $count_remark = $row['cnt']; - } - } + $resultx4 = mysqli_query($con, "SELECT COUNT(*) AS cnt FROM lab_report_submissions WHERE lab_report_submissions.Lab_Report_ID=$id and Status='Remarking'"); + $row = mysqli_fetch_assoc($resultx4); + $count_remark = $row['cnt']; + + $resultx5 = mysqli_query($con, "SELECT COUNT(*) AS cnt FROM course_groups_table WHERE Course_id=$c_id"); + $row = mysqli_fetch_assoc($resultx5); + $count_group = $row['cnt']; ?> - Lab Report Submissions () +
    +

    Total submissions ()

    -