1 / 21

Uploading Resources

Uploading Resources. Stewart Blakeway FML 213 blakews@hope.ac.uk. 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

evette
Download Presentation

Uploading Resources

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Uploading Resources Stewart Blakeway FML 213 blakews@hope.ac.uk

  2. 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

  3. 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

  4. 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

  5. What will we do today? • Allow tutor to upload a resource • Make available • Make available given date • Close

  6. Recap • Create a connection to the SQL Server $conn = mysql_connect (“localhost”, “root”, “root”); • Select the database mysql_select_db (“database” , $conn); • Construct the SQL statement $sql = (“what I want to do with the database”); • Execute the SQL mysql_query ($sql,$conn);

  7. Our Database acetraining user userID userForename userSurname userEmail userPassword userType userActive only accounts for students! What about tutors and administrators

  8. 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

  9. Our Database acetraining user userID userForename userSurname userEmail userPassword userType userActive resource userID resourceName resourceLocation resourceStart resourceFinish We have not considered multiple courses in this implementation

  10. 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>

  11. uploadResource.php • What is the criteria? • make available? • from start date / finish date • Get Resource • Get Start Date (available from) • Get Finish Date (available until) • Construct SQL based on 1,2 and 3

  12. getResource() 1,2 and 3 echo ("<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?

  13. 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 name Path to temporary file on the server

  14. 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

  15. 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

  16. 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>"); }

  17. 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

  18. 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

  19. 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

  20. 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

  21. Any Questions? • Remaining time is for student support

More Related