RU beehive logo ITEC dept promo banner
ITEC 325
2012fall
ibarland

homelectsexamshws
D2Lbreeze (snow day)

hw05
DB connectivity

Due: 2012.Dec.01 (Sat) 23:59
(Due Sat. night to give you an extra day, yet still reserve a weekend-day to meet and work w/ your group on Sunday).

You will add to your hw04 by storing .W.o.W. skills in a database, retrieving information for one given skill, and retreiving a summary list of all skills. You will also add login sessions.

  1. Copy your hw04/ project directory to hw05/. (cp -pR hw03/ hw04 will Recursively copy directories, preserving timestamps.) I will grade your hw by visiting https://php.radford.edu/~yourUserId/itec325/hw05/hw05-files.php, which should
    1. before the deadline say something like “source not available until date”,
    2. and
    3. after the deadline have (for each pertinent file part of your hw05) its source-code, last-modified time, and a link to it. If you have your database password in a separate file, you can exclude that from the listing.
  2. (10%) Have a user login page which just takes a name and password, verifies that the name is “i325” and password is “web2”. If the user tries accessing any hw05 page but hasn't validated and visited a hw05 page for more than 30sec, redirect them to the login page. See lect08b-sessions-basic for an example.

    (That is: every page except the login page itself will include a header-file which calls session-start, and verifies that there has been a visit within the last 30sec. If not, redirect. If so, update their session-info with the time of the current visit.)

  3. (30%) Modify the ol' skill entry form so once the information is validated, the skill gets added to the database.
    (You may over-write any previously existing information for that skill, or see extra-credit below.)

    Here is a hw05-setup.sql file which you can use (either in MyPHP or Oracle SQL), to create the tables you'll need. (It's fine to adjust (or even ignore) this file, if you want something different.)

    As discussed in lecture, be sure to guard against SQL injection by calling mysql_real_escape_string on any user-provided text which becomes part of a SQL query (even if other validation requirements make such escaping moot).

    Note that I'll test the hw by entering skill-names which include spaces and apostrophes, and skill-descriptions which contain apostrophes and semicolons, to check that HTML/javascript and SQL injection attacks are being guarded against.

  4. (30%) Make a page which shows a summary list of all skills previously entered: just the skill name, the associated ability (“Wisdom” etc.), and the minimum-level. Your landing page, php.radford.edu/~yourUserId/hw05/index.php, should either be this page, or it should be your login page.

  5. (30%) Each skill-name on the summary list should be a link which, when clicked, brings you to a detailed-information page that includes the previous information plus the full description, who submitted the skill, and (for last 5%) all the classes that the skill is available to.

    (The layout of this information does not need to be anything elegant, but it should not be prone to HTML/script injection.)

    Note that this is asking for a link which behaves a little bit like a form-handler, since you won't have a separate URL for every single course — instead you'll have one page which (given a particular skill-name) pulls the detailed information out of the database. How do you have a link which provides an argument (skill-name) to another page? One easy way1 is to have the link contain the parameter(s) explicitly, e.g.<a href="skillDetail.php?skillName=juggling">…”, and the receiving page accesses that argument through $_GET.

    As always, to guard against HTML/script injection, be sure to call htmlspecialchars on any text which was originally proivded by a user (even if retrieved from the database). (This goes for all pages, even if other validation requirements make such escaping moot).

  6. As before, have a file sources.php (in the same directory) which simply show_sources all your other hw04 files ONLY after the due-date.
    Your forms do not need to otherwise contain a show_source.

  7. Extra credit (5%): Have most pages accessible without logging in; have logging-in apply only to entering skill information.
  8. Extra credit (5%): Allow for deleting a skill (if logged in).
  9. Extra credit (5%): Add a 'log out' button/link, as in lect07c-ch09-logout.php.
  10. Extra credit (15%): Allow for editing an existing skill. But do so in a way that is unified with entering a new skill: The user will submit a course-number (new or existing), and be taken to the information-entry form, with all database information already filled in. (Just like a sticky form.)
    (If you do this for only for the skill name/min-level/description, but not the available-to checkboxes, that's half of the extra-credit points.)
  11. Extra credit (15%; more involved): Handle the situation where a second person wants to edit an existing skill's info even while somebody else is in the process of editing it. You can either use a pessimistic approach (don't let the second person start), or an optimistic approach (when somebody submits, make sure that the database still has the same info as when they started — at least for any fields which they modified).

    The former case is easier, but you have to worry about the first user timing out. You can use database locks to help you with this (but you don't have to).

Guidelines


1

Transmitting the arguments through $_GET of course is vulnerable to over-the-shoulder snooping; if you wanted to still use $_POST but not require a “submit” button, you can set the link's onclick attribute to be javascript which (a) sets the value of a hidden input tag, and then (b) does something like document.getElementByID( 'theFormsId' ).submit().

     

homelectsexamshws
D2Lbreeze (snow day)


©2012, Ian Barland, Radford University
Last modified 2012.Nov.26 (Mon)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Powered by PLT Scheme