Level: Intermediate Stony Yakovac (syakovac@gmail.com), Software engineer, Freelance
20 Mar 2007 This six-part series demonstrates how to leverage the power of XForms in conjunction with MySQL and PHP for support processing to create an online accounting tool called "X-Trapolate." Every good programming technology possesses a range of problems it excels at solving. The series highlights some of the problems that the XForms solves effectively, such as the need for live calculations and greater interactivity. This article, Part 1 of the series, provides an overview of the different forms and functionality that will be created in this series, examining some of the aspects of this type of tool you must consider when undertaking the design.
Why XForms?
The Web has been around for a long time, but it is only now that traditional applications are starting to
migrate from the desktop to the Web in great numbers. Why did it take so long?
The first problem was a lack of interactivity. The Web is a stateless place, where each time
you load a Web page it's a whole new ballgame as far as the server is concerned. Until recently,
it was almost impossible to even consider a Web application that gives a user instant feedback,
the way a traditional desktop application does.
Browser technologies such as JavaScript and Ajax have gone a long way in closing that gap, but they
do suffer from several problems, mostly regarding standardization. Browsers don't always implement advanced
features in the same way, leading to problems for developers who want to support multiple versions.
Even when browser differences don't get in the way, there are differences between developers and how
they implement various tasks.
XForms brings desktop-like interactivity into the picture while eliminating all of these differences.
It provides a standardized way to perform tasks like form validation, calculations, and conditional
output. It enables users to save a form to the local machine while offline and submit it to the server
later. Perhaps most of all, it separates form from function, providing a way to specify what a form
does while leaving the presentation up to the browser or other user-agent. That means that a browser,
a PDA, and a voice recognition system can all use exactly the same form.
XForms also provides a way to work with XML data directly.
In this series, you'll learn how to use the great advances made by XForms to create X-Trapolate,
an XForms-based online accounting tool designed for businesses. Here in Part 1, you'll see what needs
to be considered in designing such a project.
The rest of the team: XML, SQL, and PHP
A functioning example such as the accounting toolset requires some support. XForms in the browser provides presentation programming functionality. Though XForms contains some capabilities for interesting lightweight scripting and processing and the implementation provides some storage, most Web applications require some more permanent storage and some scripting outside the capabilities of XPath (which is used by XForms as a procedural calculation language). The accounting toolset uses SQL for the database storage system and PHP for the scripting that cannot be accomplished appropriately in XForms.
Without careful planning, interfacing SQL and XML becomes at best challenging, and, at worst, inefficient or even impossible. XML data defines the XForms implementation and becomes the data which needs to be stored. The SQL implementation requires a known and defined limit to the XML data. The accounting toolset leverages a number of tables interconnected to provide storage for the XML data provided by XForms.
Browser issues
Even in the utopian world of XForms, however, all is not entirely well. It's only recently that
XForms functionality has been available in Firefox, and Microsoft® Internet Explorer still requires an ActiveX
plugin. That doesn't necessarily solve the problem. The specification is fixed, so
there should be no more argument over how to do things. Unfortunately, browsers are still working
on full XForms support, so you're occasionally going to run into a situation in which something
should work, but it doesn't.
The Firefox add-on is the target processor for X-Trapolate.
Though impressive, there are some features of XForms that are not implemented in the Firefox add-on.
So although some of those features would be advantageous, they will not be used in this series. A brief theoretical
discussion addressing those features appears in the conclusion of this series.
Online accounting and XForms
Accounting tools enable business professionals to assess the status of various aspects of a
business and to perform day-to-day operations in a way that provides tracking and assignment of
responsibility in an easy-to-understand format. Different toolsets cover different aspects of
business. The X-Trapolate tools provide mechanisms for managing personnel and contacts, billing,
budgeting, shipping and order processing, procurement, payroll, and tools for analyzing the overall
financials of the business. Although we technically aren't creating a production application, the
tool will still contain much of the functionality needed in a real business tool, so we'll need to
take all of that into account. Each installment of the six-part series covers one or more of these
tools, with a few installments addressing enhancements to the tools.
Logging in -- The login form
Part 2 introduces a common topic for almost all modern Web-based applications, the concept of user authentication. Sometimes it provides personalized settings, sometimes it allows a hierarchy of access privileges. For X-Trapolate,
logging in offers a little of both, as well as some tracking. The login form takes input from the user in the form of a username and password. This implementation offers no level of security. PHP processes the username and password and an authentication token is assigned to the session for valid credentials. All interactions with the accounting tool require the availability of this information.
The login form demonstrates several features of XForms. The username and password use the "input" and "secret" form controls. The submission method makes use of posting XML data to a PHP script. The PHP script performs several functions including user credential authentication using the MySQL database, and the generation of an authentication token that persists for the duration of the user's session.
User registration -- The new user registration form
Another common resident of modern Web applications, the new user registration form, often appears conjunction with the login form. The registration form allows new users to create accounts for themselves. The basic account may be used for making orders or may be enhanced by an authorized user to allow more privileged access.
Also in Part 2, the new user registration form demonstrates a new form control, the "select1" control, and introduces "constraint" and "required" properties, as shown in Figure 1. The new user registration form uses another important feature of XForms, the "repeat" control processing structure. The "insert" action in conjunction with a "trigger" allows the user to enter any number of phone numbers or e-mail addresses that will be dynamically updated without the intervention of the server.
Figure 1. The registration form
Account administration -- The account management form
The last form that will be created in Part 2, the account administration form, introduces the concept of a form that dynamically adapts to its user. Logging in provides access to the user account management form. This allows the XForms form to have functionality particular to the user's access permissions. For example, salesmen see their commission rate where customers and executives see other fields displayed on the screen.
Lists of users utilize closed "select1" form controls. Another key feature of XForms, the "output" element, displays various data that the user may not change. Adapting the form to the user requires the introduction of an attribute, "relevant." The "relevant" attribute controls the visibility of elements of the XForms form.
Ordering and billing -- The order management form
The order management form, which will be developed in Part 3, allows users to review open accounts with unpaid balances. Each account is evaluated by the XForms form for one of four states: paid, due, past due, and delinquent. Delinquent invoices offer a submission control for submitting to a mythical collection agency, a total outstanding amount, and a listing of payments made on that account. Controls exist for altering all invoices manually from one state to another state. Each account with an outstanding balance allows the user to enter an amount paid on an account with a submit method to store that information in the database. A new window opens when the paid method activates displaying a receipt for that account.
The order management form introduces several new concepts, including multiple submission methods and opening a new window. An action which verifies the user and privileges triggers is based on an XForms event. Each account's outstanding balance uses the "calculate" attribute, demonstrating a variety of XPath functions.
Budgeting -- The budget management form
The budgeting form appears in Part 3 of the series. During budgeting, a business typically evaluates and performs one-time per year modifications to a plan and re-visits that plan many times during a year to track progress towards goals. The accounting toolset's budgeting tool builds on concepts already developed in prior forms requiring login and permissions just like the billing form. One can add or remove departments and sub-departments which compose a hierarchy. The hierarchy of departments and sub-departments display in an indented fashion similar to an outline with each department having children using a "readonly" sum of the budgets of the sub-departments. The budget numbers are user modifiable. The actual numbers base themselves on a date range and sum from the data in that range.
The budgeting XForms form demonstrates the "readonly" property as a configurable property. The insert and delete actions emerge again as well as more in-depth calculations using some key XPath functions critical to XForms processing.
Order processing -- The shipping and order processing form
The order processing form, which will be developed in Part 4, enables an activity that can be performed in many different roles. This implementation assumes the user performs the essential functions of filling and shipping orders remotely. The order processing and shipping form allows the user to fill orders based on inventory in multiple locations. As each order is selected, the order displays a more verbose format with each purchase separately listed. The user splits purchase lines between different sources and a back-order notice automatically displays in a separate window for portions of the order that are not filled.
More triggers and the copy function appear in this XForms form. Totaling, inserting, deleting, and the method for performing repeats on partial subsets of a node set enable splitting orders and validating totals. The "relevant" attribute controls the submission element insuring the correct actions have been taken before the recording.
Procurement -- The capital assets and procurement form
Continuing in Part 4, the capital assets form touts two basic displays depending on the role of the user. By referencing the user's department ID, non-procurement department users find a presentation of a list of the equipment associated with their department. The user may report, track, and confirm resolution of issues related to equipment. A text entry box allows the user to enter a description of the request and an option selection provides controls for choosing from replace, repair, or add.
Procurement users encounter a different portion of the XForms form. A basic display much like the order processing display exposes a list of requests that procurement users address. When the procurement user decides to repair a machine, a text box auto-fills with all the repair requests and contacts related to that machine. The procurement official selects from a dynamic set of suppliers. When the procurement submission activates, a purchase order displays. If the activity was a repair, the text of the repair appears in the display.
XPath functions appear in this XForms form to provide the auto-filling text box. The procurement form uses another previously unused input control, the text box. Switch/case/toggle structures enable conditional display of different views of the form.
Financial analysis -- The executive analysis form
Part 5 of the series contains the development of the financial analysis tool. The financial analysis tool allows an executive to analyze the performance of departments and the company as a whole. Graphics enable more understandable financial analysis. The financial analysys tool demonstrates the interaction of the graphics and the XForms form. The financial tool requires more involved and intricate implementations of calculate.
Payroll and payments due -- The payables form
The last new XForm, which will be developed in Part 5, plays a fundamental role in business management. There are many kinds of payments to be made and a variety of methods for paying those debts. The payroll and payments form demonstrates interfacing to Internet server-based APIs to perform payroll. Payroll management companies provide a variety of services, including managing payroll. This form demonstrates managing a staff of employees and their personal selections for payroll disbursement. Groups of payments selectable for draw on a configurable number of source accounts become available to the business. The payables form allows the user to relate a payment or a part of a payment to a specific department.
Summary
The X-Trapolate accounting toolset showcases a variety of standard XForms development methods and resources. The reader follows through the interface development of a functional XForms implementation. Fundamental form controls such as input, output, select, text entry, and secret play appropriate roles in the accounting tool. The introduction of each form control associates with a description of the control and a discussion of the choices made while implementing that control. Other non-visual XForms features also play an important role and the tutorial addressing that feature highlights the usefulness of that feature. Some examples of the features that will be covered include calculation, relevant, and required properties, toggles in conjunction with case and switch, interfacing to PHP, and interfacing to native XML servers. And now on to Part 2 and user authentication.
Resources Learn
-
Get a basic introduction to XForms in Introduction to XForms, Part 1: The new Web standard for forms (developerWorks, September 2006).
-
Learn all about XML and more about XForms in the IBM developerWorks XML zone.
-
Get the The PHP Manual.
-
Learn more about XForms submission events in XForms tip: Using form submission events (developerWorks, November 2006).
-
Find out how to accept XForms data in Java (developerWorks, October 2006), Perl (developerWorks, October 2006), and PHP (developerWorks, October 2006).
-
IBM XML certification: Find out how you can become an IBM-Certified Developer in XML and related technologies.
-
XML technical library: See the developerWorks XML Zone for a wide range of technical articles and tips, tutorials, standards, and IBM Redbooks.
-
developerWorks technical events and webcasts: Stay current with technology in these sessions.
Get products and technologies
-
The XForms Recommendation is maintained by the W3C.
-
Get MozzIE, an open-source control that allows you to render XForms in Internet Explorer.
Discuss
About the author  | |  | Stony Yakovac is an engineer and freelance author living in Lava Hot Springs, Idaho. He works on a wide variety of projects, including software and digital hardware designs. |
Rate this page
|