Archive for May, 2008

Chapter 19: Web Forms Manager 685 . Set (Vps web hosting)

Saturday, May 31st, 2008

Chapter 19: Web Forms Manager 685 . Set file/directory permissions. Make sure that you have changed the file and directory permissions so that your intranet Web server can access all the files. Once you have performed the preceding steps, you are ready to test your Web Forms Manager applications. Testing the Web Forms Manager Once everything is installed, make a copy of one of your existing Web forms and rename it oldname.php. Here, we will rename a Web form called ask.html to ask.|php. The ask.php form can be found on the CD-ROM that accompanies this book in the ch19/webforms/example_forms directory. It is already configured for the setup discussed here. The changes in the Web form that we need to make are as follows: . Change the FORM ACTION line as shown here:

The action line should be pointing at the submit.php location. The preceding line shows the recommended location and what we used for this test. . Add the following two hidden fields > The form_id value is something you choose arbitrarily. This value must be used in webforms.conf as follows: $KNOWN_FORMS = array( X9393948482339290000 => contact.conf , X9393948482339295000 => newsletter.conf , X9393948482339292929 => askform.conf ); Here, the form_id X9393948482339292929 is associated with a configuration file called askform.conf. This configuration file must reside in the /webforms/apps/site_forms/askform directory. A sample configuration is shown in Listing 19-2. This configuration defines the form- specific database table name using FORM_TABLE.

Apache web server for windows - 684 Part V: Internet Applications Here is how

Saturday, May 31st, 2008

684 Part V: Internet Applications Here is how you can get your Web Forms Manager application up and running: . Install the application framework. If you have not yet installed the application framework discussed in Chapter 4, you must do so before proceeding further. . Install the WEBFORMS database. The quickest way to create the WEBFORMS database is to run the following commands: mysqladmin u root p create WEBFORMS mysql u root p D WEBFORMS < webforms.sql . The WEBFORMS.mysql script can be found on the accompanying CD-ROM in the ch19/sql directory. The second command in the preceding listing will create two tables, X_TBL and ASK_TBL, in your WEBFORMS database. The X_TBL is not really used, as it is a generic table that explains how a form X can be configured. However, ASK_TBL can be used by the ask.php form. . Note that if you cannot create a new database called WEBFORMS, you can use an existing one. Just make sure that you change the database URL in webforms.conf to reflect your database name as discussed in the following step. . Install the WEBFORMS applications. Now, from the ch19 directory of the CD-ROM, extract ch19.tar.gz in %DocumentRoot%. This will create WEBFORMS in your document root. Configure %DocumentRoot%/webforms/ apps/webforms.conf for the path and database settings. The applications are installed in the %DocumentRoot%/webforms/apps directory, and the templates are stored in %DocumentRoot%/webforms/apps/templates. You will have to keep your form-specific files (configuration files and upload directories) in different form directories in %DocumentRoot%/webforms/ apps/site_forms. If your MySQL server is hosted on the Internet Web server, it can be accessed via localhost. However, if your MySQL database is on a different server than your Web server, you can easily modify the database URLs in each application s configuration files. For example, the webforms.conf file has a database URL as follows: define( FORM_DB_URL , mysql://root:foobar@localhost/WEBFORMS ); Suppose that your database server is called db.domain.com and the user- name and password to access the WEBFORMS database (which you will create during this installation process) are admin and db123, respectively. In such a case, you would modify the database access URLs throughout each configuration file as follows: define( FORM_DB_URL , mysql://admin:db132@db.domain.com/WEBFORMS );

Web site construction - Chapter 19: Web Forms Manager 683 processRequest() This

Friday, May 30th, 2008

Chapter 19: Web Forms Manager 683 processRequest() This method is responsible for the entire process of enabling a user to download the form data. This is how it works: . First, it determines whether the passed form ID is valid. If it is empty, it displays an alert message and returns null. . Next, an object of FormData is created. Depending on the type of download (all records or latest records), the getFormData() or getData AfterRecordID() method is called to retrieve the appropriate data and then store it in the $dataArr array. In the case of the latest data download, the getLastDLRecordID() method is called to retrieve the top record id of the previously downloaded data so that the new download can start after it. . If $dataArr is not empty, a CSV file is created and opened in the temp directory of the application, and the $dataArr values are written in it, separated by commas. . After the data writing in the CSV file is done, the updateDownloadTrack() method is called to store the record id of the row that was last written in the CSV file. . Finally, the user is redirected to the CSV file, from which he can download the data as a CSV file. . If $dataArr is empty, the user is shown an alert message stating that the requested dataset is empty. Installing the Web Forms Manager In this section, it is assumed that you are using a Linux system with MySQL and the Apache server installed. During the installation process for the Web Forms Manager, we will refer to the Web document root directory as %DocumentRoot%. It is also assumed that you have installed the PHPLIB and PEAR libraries. Normally, these are installed during PHP installation. For your convenience, these are provided in the lib/phplib.tar.gz and lib/pear.tar.gz directories on the CD-ROM. In the following sample installation steps, it is further assumed that these are installed in the %DocumentRoot/phplib and %DocumentRoot/pear directories. Because your installation locations for these libraries are likely to differ, make sure that you replace these paths in the configuration files.

My space web page - 682 Part V: Internet Applications . It determines

Friday, May 30th, 2008

682 Part V: Internet Applications . It determines whether the given range for the report is valid. If not, an error message is stored in $msg, to be shown later. . If both of the preceding checks pass, an object of the FormData class is created and the getFormData() method is called to get the data submitted within that range of time from the given form. This data is stored in an array named $dataArr. . Dynamic contents of the report template are set. The form names and IDs are set to the select combo box for the forms. The starting date and ending date are set to the combo boxes accordingly. . Then the $dataArr array is checked to determine whether it has any data. If not, $msg is checked for any error messages. If there is an error message, it is set to the template to be parsed and printed to the user. Otherwise, it means that the requested range doesn t have any data for the given form. Therefore, a message is set and printed accordingly. . If $dataArr has any data in it, the headings of the data are set to the heading block of the template. Then the data block is set with the rows of data. The row colors are maintained according to the odd and even colors prescribed in the configuration file. . If the form id is selected and it is a valid and known form, the links for data download are set to the template. . Finally, the template is parsed and printed to the user s browser. Creating the CSV Data Exporter Application This application, CSVExporter.php, is responsible for allowing form administrators to download the data for a form. This application is included on the CD-ROM in the ch19/apps directory. This application has the methods described in the following sections. run() When the application is run, this method is called. It calls the processRequest() method with the form ID and the type of download (all records or latest records) to enable users to download data.

Free web hosting services - Chapter 19: Web Forms Manager 681 authorize() This

Thursday, May 29th, 2008

Chapter 19: Web Forms Manager 681 authorize() This method authorizes the client IP in the following way: . First, it determines the client IP. . Then it creates an object of class ACL (Access Control List) with the client IP, the allowed IP(s), and the denied IP(s). . Finally, the isAllowed() method of the ACL class is used to determine whether the client is allowed to access the application. Creating the Web Forms Reporter Application This application, webformsreporter.php, is responsible for showing the form report to the administrator. This application included is on the CD-ROM in the ch19/apps directory. This application has the methods described in the following sections. run() When the application is run, this method is called. This is how it works: . It calls the showReport() method with the form id, the range of the report (start and end date), the sorting criteria, and the toggle flag. . Form id, sort criteria, and toggle flag values are taken directly from the client request. If no starting or ending range is given, it assumes the start of the current day as the starting timestamp and the end of the current day as the ending timestamp. showReport() This method is responsible for showing the form report. This is how it works: . First, the template class is created with the report template file of the default template directory. All the blocks of the templates are set accordingly. . Then it determines whether the form id is valid. If it is empty, an error message is stored in $msg and the block to show the link for a data download for a specific form is set to null.

Web server on xp - 680 Part V: Internet Applications This application contains

Thursday, May 29th, 2008

680 Part V: Internet Applications This application contains the methods described in the following sections. run() When the application is run, this method is called. This is how it works: . First, it creates a FormSubmission object. Then it determines whether the id of the form for which the request is being made is configured. If it isn t, it displays an error alert and returns null. . Otherwise, the loadConfigFile() method of the FormSubmission class is called to load the configuration file for the form. Then the setupForm() method of the same class is called to set up the form variables. . Next, the authorize() method is called to authorize the request. If authorization is successful, the processForm() method is called to process the form data. . If processForm() returns a positive status, this method determines whether an auto redirect for this form exists. If yes, the user is redirected to the specified URL; otherwise, a thank-you message for submitting the form is displayed to the user by calling the showPage() method. . If processForm returns a negative status, the error message is prepared using the getErrorMessage() method of the Formsubmission class. Then the exact violation issue is retrieved, and the error message is displayed as an alert to the user. showPage() This method renders the given template on the user s browser. This is how it works: . It first determines whether the requested template exists in the form- specific template directory. If it does, the template directory for the template class is assumed to be the form template directory; otherwise, the default application template directory is assumed to be the template directory for the template class. . After the template class is instantiated with the appropriate template directory, all the data posted by the user is set to the template. . Finally, the template is parsed and printed to the user s browser.

Chapter 19: Web Forms Manager 679 Creating Application (Cheapest web hosting)

Wednesday, May 28th, 2008

Chapter 19: Web Forms Manager 679 Creating Application Templates The HTML interface templates needed for the applications are included on the CD-ROM. These templates contain various template tags for displaying necessary information dynamically. These templates are described in Table 19-3. TABLE 19-3 HTML TEMPLATES Configuration Variable Template File Purpose $REPORT_TEMPLATE report.html This template is used to show reports data collected via Web forms. $OUTBOUND_MAIL_TEMPLATE Outbound_mail.html This template is used to send mail to the user who fills out the form. $INBOUND_MAIL_TEMPLATE Inbound_mail.html This template is used to send mail to the form owner or the administrator. $SHOW_THANKYOU_TEMPLATE thanks.html This template is used to thank the user after the form has been filled out. Creating the Web Forms Submission Manager Application This application, submit.php, is responsible for managing the entire form-submission process. This application is included on the CD-ROM in the ch19/apps directory. It implements the following functionality: . Adds submitted data to the database . Sends mail to the appropriate recipient . Shows error messages in case of invalid data . Displays a thank-you page or redirects the user to a specified URL after form submission

678 Part V: Internet Applications TABLE 19-2 THE

Wednesday, May 28th, 2008

678 Part V: Internet Applications TABLE 19-2 THE X.CONF CONFIGURATION VARIABLES (Continued) Configuration Variable Purpose $FRM_TEMPLATE_DIR Form-specific template directory. Whenever a template is required, the application first searches for it here. If it doesn t find it here, it searches the default application template directory. $UPLOAD_FILE_FIELDS_ARRAY The array to identify any upload-related field names and their configurations. $SEND_OUTBOUND_MAIL The code to identify whether there should be outbound mail or not. $OUTBOUND_MAIL_TEMPLATE The template file used to send outbound mail. $OUTBOUND_MAIL_SUBJECT The subject line to be used in outbound mail. $EMAIL_FIELD The name of the form field containing the e-mail address of the user. $SEND_INBOUND_MAIL The code to identify whether there should be inbound mail or not. $INBOUND_MAIL_TEMPLATE The template file used to send outbound mail. $INBOUND_MAIL_TO The e-mail address to which inbound mail will be sent. $INBOUND_MAIL_SUBJECT The subject line to be used in outbound mail. $SHOW_THANKYOU_TEMPLATE The name of the template file used to thank the user after filling out the form. $AUTO_REDIRECT The code to identify whether the page should be redirected after the form is submitted. $AUTO_REDIRECT_URL The URL to which the page should be redirected after form submission. $ERRORS The array of error messages related to different fields. Creating the errors file The error messages displayed by the Web Forms Manager applications are stored in the ch19/apps/webforms.errors file on the CD-ROM. You can modify the error messages by using a text editor.

Web site directory - Chapter 19: Web Forms Manager 677 By changing

Tuesday, May 27th, 2008

Chapter 19: Web Forms Manager 677 By changing the following configuration parameters in webforms.conf, you can modify the directory structure to fit your site requirements: $PEAR_DIR = $_SERVER[ DOCUMENT_ROOT ] . /pear ; $PHPLIB_DIR = $_SERVER[ DOCUMENT_ROOT ] . /phplib ; $APP_FRAMEWORK_DIR = $_SERVER[ DOCUMENT_ROOT ] . /framework ; $ROOT_PATH = $_SERVER[ DOCUMENT_ROOT ]; $REL_ROOT_PATH = /webforms ; $REL_APP_PATH = $REL_ROOT_PATH . /apps ; $TEMPLATE_DIR = $ROOT_PATH . $REL_APP_PATH . /templates ; $CLASS_DIR = $ROOT_PATH . $REL_APP_PATH . /class ; Creating a sample form configuration file Now to examine a sample form configuration file. Assuming the name of the form is x, the configuration file name should be x.conf. Table 19-2 describes the configuration variables of x.conf, a typical form configuration file. TABLE 19-2 THE X.CONF CONFIGURATION VARIABLES Configuration Variable Purpose $ FORM_NAME The name of the form to be configured. $FORM_TABLE The name of the table in which the form data will be stored. $ACL_ALLOW_FROM Comma-separated list of IP addresses that are allowed to access this form. $ACL_DENY_FROM Comma-separated list of IP addresses that are denied access to this form. $FORM_LOG_FILE The name and path of the log file for the form. $FORM_FIELDS_ARRAY The array of form fields, along with their configurations. $UPLOAD_FILE The code to identify whether there is an upload for this form or not. $UPLOAD_FILE_DIR The name and path of the directory to store the uploaded file. Continued

Web site development - 676 Part V: Internet Applications TABLE 19-1 THE

Tuesday, May 27th, 2008

676 Part V: Internet Applications TABLE 19-1 THE WEBFORMS.CONF VARIABLES THAT NEED TO BE CHANGED (Continued) Configuration Variable Purpose $DEFAULT_COLOR Default color used as background in any row in the report. $MAX_YEAR The maximum year to be used in the report prompt. $MIN_YEAR The minimum year to be used in the report prompt. $REPORTER The name of the application that manages the report. $CSV_EXPORTER The name of the application that exports form data as CSV. $DOWNLOAD_TRACK_TBL The name of the table that tracks download information. $DOWNLOAD_TYPE_LATEST The code for identifying the type of download for which only the latest data is downloaded. $DOWNLOAD_TYPE_ALL The code for identifying the type of download for which all data is downloaded. The directory structure used in the webforms.conf file supplied in the ch19 directory on the CD-ROM might need to be tailored to your own system s requirements. The current directory structure looks like the following: htdocs ($ROOT_PATH == %DocumentRoot%) | +—webforms (Web Forms Manager Applications) | +—apps (apps and configuration files) | +—class (class files) | +—templates (HTML templates) | +—temp (Temporary folder to store the files to be downloaded) | +—site_forms (form configuration files) | +—x (configuration file for x form)