Presentation is loading. Please wait.

Presentation is loading. Please wait.

Faculty of Sciences and Social Sciences HOPE Different Users and Uploading Files Stewart Blakeway FML 213

Similar presentations


Presentation on theme: "Faculty of Sciences and Social Sciences HOPE Different Users and Uploading Files Stewart Blakeway FML 213"— Presentation transcript:

1 www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Different Users and Uploading Files Stewart Blakeway FML 213 blakews@hope.ac.uk

2 www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Assessment Criteria Ace training requires a new system for students that enrol onto their course(s). There will typically be three methods of enrolment: from a list, by a tutor, or by a student. Students that register themselves require authorising by the tutor. Tutors are created by administrator(s) after the credentials of the tutor has been checked. To become a course tutor the individual will register as a tutor. The tutor will have the facility of uploading various resources, such as powerpoint presentations and documents. Once uploaded they should either: be made available to the student, not available or available within a specified date range. Satisfactory

3 www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE What we have done myPhpAdmin – Created a database – Tables – Fields Inserted Data – Registration (this could be a student or tutor) Selected Data – Used as part of the authentication process Session Variables – If the authentication process was successful The include statement – Makes our job much easier

4 www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE What will we do today? Applying user levels to your current users table – Registering as a tutor – Registering as a student Dynamically displaying different menus/links dependent on the user – Authorising the tutor – Authorising the student Allowing a tutor to upload a list of students for registration

5 www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Recap 1.Create a connection to the SQL Server $conn = mysql_connect (“localhost”, “root”, “root”); 2.Select the database mysql_select_db (“database”, $conn); 3.Construct the SQL statement $sql = (“what I want to do with the database”); 4.Execute the SQL mysql_query ($sql,$conn);

6 www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Our Database acetraining student studentID studentForename studentSurname studentEmail studentPassword only accounts for students! What about tutors and administrators user userID userForename userSurname userEmail userPassword userType userActive We change our structure to accommodate different types of users. Users remain inactive until authorised

7 www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE register and doregister Same as last week – updated to include a dropdown list (tutor/student) – updated to reflect new table name $sql = ("INSERT INTO user (userForename, userSurname, userEmail, userPassword, userType, userActive) VALUES ('$_POST[forename]', '$_POST[surname]', '$_POST[email]', '$_POST[password]', '$_POST[type]', false) ");

8 www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE login.php Same as last week – changes to reflect new table name and structure – changed session variable – added new functions if (!isset($_POST['email'])) { showLogin(); } else { doLogin(); } if (!isset($_POST['email'])) { showLogin(); } else { doLogin(); if (isset($_SESSION[‘type’]) { displayUserPage(); }

9 www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE doLogin() $conn = mysql_connect("localhost","root","root"); mysql_select_db("aceTraining",$conn); $sql = ("SELECT * FROM user WHERE (userEmail = '$_POST[email]' AND userPassword = '$_POST[password]')"); if ($resource = mysql_query($sql,$conn)) { echo ("sql --- OK"); if (mysql_num_rows($resource) == 1) { $currentRow = mysql_fetch_array($resource); $_SESSION['userType'] = $currentRow['userType']; echo (" login --- OK"); } else { echo (" login --- FAIL"); }

10 www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE displayUserPage() We have a session variable called type – this will hold values tutor, student or administrator if (!isset($_POST['email'])) { showLogin(); } else { doLogin(); } if (!isset($_POST['email'])) { showLogin(); } else { doLogin(); if (isset($_SESSION[‘type’])) { displayUserPage(); }

11 www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE displayUserPage() function displayUserPage() { if ($_SESSION['userType'] == "student") { showStudentPage(); } if ($_SESSION['userType'] == "tutor") { showTutorPage(); } if ($_SESSION['userType'] == "administrator") { showAdministatorPage(); }

12 www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE showTutorPage() function showTutorPage() { echo (" You are logged in as a tutor, what would you like to do? Show students waiting to be authorised for your course Enter student registration details manually Enrol students from a list "); }

13 www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE What we will do now Display students waiting to be authorised Allow for entry manually by tutor Allow tutor to upload a list

14 www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE enrolStudent.php if (($_SESSION['userType'] == "student") or (!isset($_SESSION['userType']))) { echo ("you are not authorised to view this page"); } else { if ($_POST['enrolStudent'] == "showWaiting") { showWaiting(); } if ($_POST['enrolStudent'] == "enterManually") { enterManually(); } if ($_POST['enrolStudent'] == "fromList") { getFile(); }

15 www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE showWaiting() $conn = mysql_connect("localhost","root","root"); mysql_select_db("aceTraining",$conn); $sql = ("SELECT * FROM user WHERE (userType = 'student' AND userActive = false)"); $resource = mysql_query($sql,$conn); echo (" "); while ($currentStudent = mysql_fetch_array($resource)) { echo ("<input name='userID[]' type='checkbox' id='userID' value='$currentStudent[userID]' />"); echo ($currentStudent['userForename']. " ". $currentStudent['userSurname']. " "); } echo (" ");

16 www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE enrolStudents($students) $conn = mysql_connect("localhost","root","root"); mysql_select_db("aceTraining",$conn); foreach ($students as $userID) { $sql = ("UPDATE `acetraining`.`user` SET `userActive` = true WHERE `user`.`userID` = $userID"); mysql_query($sql,$conn); }

17 www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE enterManually() We have done this already – Use the code from the register page to display the form – Use the code from the doRegister page, make a slight change to the SQL $sql = ("INSERT INTO user (userForename, userSurname, userEmail, userPassword, userType, userActive) VALUES ('$_POST[forename]', '$_POST[surname]', '$_POST[email]', '$_POST[password]', '$_POST[type]', false)"); $sql = ("INSERT INTO user (userForename, userSurname, userEmail, userPassword, userType, userActive) VALUES ('$_POST[forename]', '$_POST[surname]', '$_POST[email]', '$_POST[password]', 'student', true)");

18 www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE getFile() and uploadFileandProcess() This is where it gets a little tricky – we need to ensure a file structure – deviation from the file structure may cause errors – extra validation should be used to trap incorrectly formatted files – we can’t read from a file unless it is on the server the user must upload the file first

19 www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE getFile() echo (" Choose a file to upload: ");

20 www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE uploadFileandProcess() $target_path = basename($_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; $file = fopen (basename( $_FILES['uploadedfile']['name']),"r"); $conn = mysql_connect("localhost","root","root"); mysql_select_db("aceTraining",$conn); while (!feof($file)) { $line = fgets ($file); $columns = explode (",",$line); $sql = ("INSERT INTO user (userForename, userSurname, userEmail, userPassword, userType, userActive) VALUES ('$columns[0]', '$columns[1]', '$columns[2]', '$columns[2]', 'student', true)"); mysql_query($sql,$conn); }

21 www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE What we have covered Ace training requires a new system for students that enrol onto their course(s). There will typically be three methods of enrolment: from a list, by a tutor, or by a student. Students that register themselves require authorising by the tutor. Tutors are created by administrator(s) after the credentials of the tutor has been checked. To become a course tutor the individual will register as a tutor. The tutor will have the facility of uploading various resources, such as powerpoint presentations and documents. Once uploaded they should either: be made available to the student, not available or available within a specified date range. Satisfactory

22 www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Next? Example code is online Next week is a drop-in support session – we have covered a lot this week – students that can not get this working should come and speak with me next week

23 www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Any Questions?


Download ppt "Faculty of Sciences and Social Sciences HOPE Different Users and Uploading Files Stewart Blakeway FML 213"

Similar presentations


Ads by Google