Quizzes are done! I've spent tha past few days working on those and cleaning up the sidebar. I wrote a seperate php file for the sidebar that has intelligence for displaying the proper menu items based on the user. I manually added this logic to the seperate pages previously. Now I simply include them.
The only think remaining is my Managers page. I laid out the different information that I want to display.
- Outstanding Orders - These are orders that haven't been delivered yet. From this list, the manager will be able to modify the estimated delivery date.
- Today's Shipped Orders - A list of the orders that were delivered today.
- Today's Scans - A list of the scans for the day, ordered by tracking number.
- History - This allows a manager to view the orders shipped for the given month with an option to see the scans too.
Although a lot of package sites offer to send you emails with tracking information, many people still don't want to use it. They prefer to poll the site themselves by refreshing their browser every hour or so manually. So I decided to make tracking information available as an RSS feed. I generate an RSS feed for each tracking number via PHP. It was quite simple to do, but I felt it was a sensible use of XML.
From the tracking result page, I've added the alternate link for the RSS version of the page. Users with Mozilla will see the RSS icon in the address bar. I may add an RSS icon on the page for IE users.
Each scan results in a new item in the RSS feed. If the user clicks on it, then it will launch their browser to the tracking result page to an anchor on the exact column in the scans table.
PHP has similar capabilities. I had to automatically increment some dates, so I used mktime() to create the date, then I converted it to unix time and added the appropriate amount of seconds. Then I converted it back to time and printed it in the format that MySQL needed.
I've fully implemented the login feature. I really wanted to get this working before finishing work on the scans table, because I wanted the employee and the manager page to show up only for the right class of user. I've got three user classes:
A user can create their own account, but their user class will automatically be set to usr. The admin can create additional users with the other user classes, including another adm. If I get industrious, I may make a complete user editor.
I've made the change to attach a user to an order, but I'm not sure if I'll get the time to add the feature where a user can quickly find all of their orders. Therefore this feature is primarily to show the extra menu items and pages for different user classes. An employee will be able to add a scan for an order. A manager will be able to generate reports. And the admin can add users as mentioned above as well as reinstall the site.
I like to use POST for my forms because it cleans up the URL. However, it can be confusing to the user when they try to reload a page. I think this is an acceptable trade-off. I'll still use GET for some forms such as the tracking reports, because the user may want to save that URL as a bookmark to check later.
AUTO_INCREMENT sounded like a quick kill for allowing MySQL to generate the new Tracking IDs for me. I ran into two problems. First I tried to get the newly generated ID through the PHP function, mysql_insert_id(). Well, since our Tracking IDs are 11 digits, they grow outside of the boundaries of a standard MySQL INT and require a BIGINT. No big deal, exept this PHP function only returns up to a PHP int. So I had to rely on the MySQL function, LAST_INSERT_ID(), in a standard query. So I had to execute the query, get the resulting row, and use that.
I was testing LAST_INSERT_ID() in my mysql client as I was adding information with the webapp, and it was failing. Apparently it's only reliable within the same session that is inserting the rows.
SELECT MAX (id) AS id FROM my_table - Allows you to select the maximum value for a field. I can use this to add the newest tracking number when a new order is added.
AUTO_INCREMENT - This is, however, likely a better route to take for adding a new row and getting a new tracking number as a result. You can then get the last auto incremented value with LAST_INSERT_ID().
I'll likely use an integer for the tracking number with a maximum length and a zero fill option.
define() - Used to create static globals. I'll make use of them in config.php.
Fancy forms - This page has an example where a form is handled by the same page. When the page handles it correctly, the form disappears. I'll use this combined with the $_SESSION to make the login disappear. Slick.
Sorted out how to use MySQL queries with PHP. It's rather convenient, especially when combined with the easy of form processing of PHP. I've got my installation page working. I just need to add in support for the rest of my tables. When I wrap that up, I'm going to need to clean the code up. It's hard to find a style with PHP, especially with the XHTML mixed in. I'll have to search for some good examples. I'm still uncertain how to seperate the XHTML from the PHP. I guess I can read in pieces of XHTML and output them with PHP, but that seems a little kludgey.
So apparently if you want to add the following line of xhtml 1.1 valid text to the <head> section of your XHTML document, it will not work on IE.
Instead you should do the following:
Firefox handles both just fine.