www.hope.ac.uk Faculty of Sciences and Social Sciences
HO
PE
Uploading Resources
Stewart Blakeway
FML 213
www.hope.ac.uk Faculty of Sciences and Social Sciences
HO
PE
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
www.hope.ac.uk Faculty of Sciences and Social Sciences
HO
PE
What we have done so far
• 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
www.hope.ac.uk Faculty of Sciences and Social Sciences
HO
PE
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.
Sati
sfact
ory
www.hope.ac.uk Faculty of Sciences and Social Sciences
HO
PE
What will we do today?
• Allow tutor to upload a resource– Make available– Make available given date– Close
www.hope.ac.uk Faculty of Sciences and Social Sciences
HO
PE
Recap
1. Create a connection to the SQL Server$conn = mysql_connect (“localhost”, “root”, “root”);
2. Select the databasemysql_select_db (“database” , $conn);
3. Construct the SQL statement$sql = (“what I want to do with the database”);
4. Execute the SQLmysql_query ($sql,$conn);
www.hope.ac.uk Faculty of Sciences and Social Sciences
HO
PE
Our Database
acetraining
only accounts for students! What about tutors and administrators
user
userIDuserForenameuserSurnameuserEmailuserPassworduserTypeuserActive
www.hope.ac.uk Faculty of Sciences and Social Sciences
HO
PE
We need to expand our database
• There may be many resources– Each tutor will have resources– Resources are made available or not
• This could be within a set period
www.hope.ac.uk Faculty of Sciences and Social Sciences
HO
PE
Our Databaseacetraining
We have not considered multiple courses in this implementation
user
userIDuserForenameuserSurnameuserEmailuserPassworduserTypeuserActive
resource
userIDresourceNameresourceLocationresourceStartresourceFinish
www.hope.ac.uk Faculty of Sciences and Social Sciences
HO
PE
showTutorPage()function showTutorPage() { echo (" <p>You are logged in as a tutor, what would you like to do?</p> <form id='form1' name='form1' method='post' action='enrolStudent.php'> <p> <input type='radio' name='enrolStudent' id='enrolStudent' value='showWaiting' /> Show students waiting to be authorised for your course<br /> <input type='radio' name='enrolStudent' id='enrolStudent' value='enterManually' /> Enter student registration details manually<br /> <input type='radio' name='enrolStudent' id='enrolStudent' value='fromList' /> Enrol students from a list </p> <p> <input type='submit' name='button' id='button' value='Submit' /> </p> </form> "); }
<form id='form2' name='form2' method='post' action='uploadResource.php'>
<p><input type='radio' name='upload' id=upload'
value='upload' /> Upload Resource<br /> </p> <p>
<input type='submit' name='button' id='button' value='Submit' />
</p></form>
www.hope.ac.uk Faculty of Sciences and Social Sciences
HO
PE
uploadResource.php
• What is the criteria?– make available?
• from start date / finish date
1. Get Resource
2. Get Start Date (available from)
3. Get Finish Date (available until)
4. Construct SQL based on 1,2 and 3
www.hope.ac.uk Faculty of Sciences and Social Sciences
HO
PE
getResource() 1,2 and 3echo ("<form enctype='multipart/form-data' action='$_SERVER[PHP_SELF]' method='POST'><p>Choose a resource to upload: <input name='uploadedfile' type='file' /></p><p>Resource Name<input name='resourceName' type='text' /></p><p>Resource Available from<input name='s_dd' type='text' size='2' /> / <input name='s_mm' type='text' size='2' /> / <input name='s_yyyy' type='text' size='4' />(dd/mm/yyyy)</p><p>Resource Available until<input name='f_dd' type='text' size='2' /> / <input name='f_mm' type='text' size='2' /> / <input name='f_yyyy' type='text' size='4' /> (dd/mm/yyyy)</p><input type='submit' value='Upload File' /></form>");
Can you sketch out what would be displayed by the browser?
www.hope.ac.uk Faculty of Sciences and Social Sciences
HO
PE
uploadFileandProcess() 4$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";
$conn = mysql_connect("localhost","root","root"); mysql_select_db("aceTraining",$conn);
$userID = $_SESSION['userID']; $resourceLocation = basename($_FILES['uploadedfile']['name']); $resourceName = $_POST['resourceName']; $startDate = $_POST['s_yyyy'] . "-" . $_POST['s_mm'] . "-" . $_POST['s_dd']; $finishDate = $_POST['f_yyyy'] . "-" . $_POST['f_mm'] . "-" . $_POST['f_dd'];
$sql = ("INSERT INTO resource (userID, resourceName, resourceLocation, resourceStart, resourceFinish) VALUES ('$_SESSION[userID]', '$resourceName', '$resourceLocation', '$startDate', '$finishDate')");
echo "<ul><li>" . $sql . "</li></ul>"; mysql_query($sql,$conn) or die(mysql_error()); }
From the form
Original Path namePath to
temporary file on the
server
www.hope.ac.uk Faculty of Sciences and Social Sciences
HO
PE
What we have done
• Allowed the tutor to upload a resource– specified start date– specified finish date– specified resource location– specified resource name
• Next?– displaying available resources
• dependent on start and finish date
www.hope.ac.uk Faculty of Sciences and Social Sciences
HO
PE
Assume student is logged in!
• display student page– we have prepared for this in login.php– function called showStudentPage()
• display resources available for download– ie, what the tutor has uploaded
www.hope.ac.uk Faculty of Sciences and Social Sciences
HO
PE
showStudentPage()
$currentDate = date('Ymd');$conn = mysql_connect("localhost","root","root");mysql_select_db("aceTraining",$conn);$sql = ("SELECT * FROM resource");$records = mysql_query($sql,$conn) or die (mysql_error());
while ($currentResource = mysql_fetch_array($records)) { echo "<ol>"; if ((str_replace("-", "", $currentResource['resourceStart']) <= $currentDate) && (str_replace("-", "", $currentResource['resourceFinish']) >= $currentDate)) { echo ("<li>" . "<a href='" . $currentResource ['resourceLocation'] . "'>" . $currentResource['resourceName'] . "</a></li>"); }
echo ("</ol>"); }
www.hope.ac.uk Faculty of Sciences and Social Sciences
HO
PE
Satisfactory
• We have done enough to pass the webpage criteria of the assessment– don’t forget you also have a report– and a presentation– and an exam
www.hope.ac.uk Faculty of Sciences and Social Sciences
HO
PE
Satisfactory• Student and Tutor can register
– tutor must authorise student, administrator must authorise tutor
• Student and Tutor can log in
• Tutor can– authorise pending students
– enrol students from a list
– upload resources (powerpoint, documents, pdf, etc)
– resources can be made available within a given period
• Students can– view available resources within the given period
www.hope.ac.uk Faculty of Sciences and Social Sciences
HO
PE
Considerations• Tutors
– we have not accounted for tutor(s) delivering multiple courses
– we haven’t allowed for the tutor to change start and finish times (or to delete) of uploaded files
– we don’t allow the tutor to structure resources (weeks, content type, file type)
– Tutors can not change their details (email address, password)
• Students– we have not accounted for student(s) enrolled for a particular
course (or multiple courses)
– we have not facilitated the tracking of student progress
– we don’t allow the student to change their details
www.hope.ac.uk Faculty of Sciences and Social Sciences
HO
PE
Next?
• Example code is online• Next week is a drop-in support session– students that can not get this working should
come and speak with me as soon as possible
Top Related