1. Trang chủ
  2. » Công Nghệ Thông Tin

Secure PHP Development- P102 pot

5 97 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 5
Dung lượng 101,17 KB

Nội dung

survey form and a target list. In other words, each survey campaign can only be sent to a single target predefined target list using a predefined survey form in the system. ◆ View survey reports. The survey administrator can access automatically generated survey reports via the management application suite. The customer, the survey participant, can receive a survey form via e-mail and respond to the survey questions. The result is not accessible by the customer. As shown in Figure 14-1, there are six applications in the survey system: ◆ List Manager: Responsible for creating simple survey lists from comma- separated value (CSV) files that have three fields — EMAIL, FIRSTNAME, and LASTNAME — in the previously mentioned order. When a new list is added to the system, the List Manager application automatically creates one user ID per e-mail address entered into the new list from the CSV file. It auto- matically protects the list against duplicate entries, and it can also apply filters on all the data fields. This application also allows the user to remove existing lists from the database. ◆ Form Manager: This application is responsible for adding new survey forms in the system. The survey forms must follow a specific HTML form development guideline, which is specified in a later section. ◆ Campaign Manager: This application is responsible for creating new survey campaigns using existing survey forms and target lists. It also allows the user to delete old surveys. ◆ Report Manager: This application is responsible for displaying the survey response report. ◆ Execution Manager: This application executes a given survey by sending e-mails using the appropriate survey form to the appropriate survey target list. ◆ Response Manager: When a customer fills out a survey form, this applica- tion writes the survey response data to the survey database. The system diagram also shows that all the applications use five objects: list, form, survey, report, and response. These objects are described in the “Designing and Implementing the Survey Classes” section of this chapter in detail. Before the classes providing the objects can be defined, you need to implement the database needed to support the features discussed earlier. 476 Part III: Developing E-mail Solutions 18 549669 ch14.qxd 4/4/03 9:26 AM Page 476 Designing the Database Figure 14-3 shows the database diagram for the survey system. In the following sections, I describe each table in details. Figure 14-3: Survey system database diagram. SURVEY Table This table is the integral part of this database. This table holds the survey name (NAME), survey list number (LIST_ID), survey form number (FORM_ID), execution status (STATUS), survey creation time (CREATE_TS), and user ID of the user who cre- ated the survey (CREATOR_ID). The survey number (SURVEY_ID) is automatically generated by the database. SURVEY_LIST Table This table contains the survey list information. The survey list consists of a list number (LIST_ID), which is automatically generated when the list is created. It con- tains the list name (NAME), the user’s uploaded data file name (FILENAME) used to cre- ate the list, the number of records (RECORDS), the survey creation time (CREATE_TS), and the user ID of the user who created the survey (CREATOR_ID). SURVEY_LIST_DATA Table This table holds the list data. The list is identified by the LIST_ID field from the SURVEY_LIST table. Each list contains survey user ID (SUID), e-mail address (EMAIL), first name (FIRST), and last name (LAST) fields. The FIRST and the LAST fields can be used to personalize the survey form sent out by the system. These fields are accessed in the survey form as {FIRST} and {LAST} tags. LIST_ID NAME FILENAME RECORDS CREATE_TS CREATOR_ID CHECKFLAG 1 ∞ ∞ SURVEY_LIST SURVEY_ID NAME LIST_ID FORM_ID CREATE_TS CREATOR_ID STATUS SURVEY FORM_ID NAME TEMPLATE SUBJECT MAILFROM CREATE_TS CREATOR_ID CHECKFLAG SURVEY_FORM LIST_ID SUIC EMAIL FIRST LAST SURVEY_LIST_DATA EXEC_ID SUID SUBMIT_TS SURVEY_RESPONSE_RECORD FORM_ID FIELD_ID LABEL SURVEY_FORM_FIELD_LBL ID EXEC_ID SUID FIELD_ID VALUE SURVEY_RESPONSE EXEC_ID SURVEY_ID SURVEY_TS SURVEY_EXECUTION 1 1 1 1 ∞ ∞ ∞ ∞ ∞ Chapter 14: E-mail Survey System 477 18 549669 ch14.qxd 4/4/03 9:26 AM Page 477 SURVEY_FORM Table This table holds information about the survey form that is uploaded by the user. It contains the name of the form (NAME), form template (that is, file name) name (TEMPLATE), subject (SUBJECT) of the survey, from address (MAILFROM), survey cre- ation time (CREATE_TS), and user ID of the user who created the survey (CREATOR_ID). The form ID (FORM_ID) is automatically generated when a new survey form is added to the system. The CHECKFLAG field is used to protect the system against multiple uploading of the same form if the user accidentally refreshes the browser during the form upload process. SURVEY_FORM_FIELD_LBL Table This table contains labels for questions asked in a survey form. Each survey form consists of a set of questions, which are stored in this table to allow the reporting of the collected survey data. The FORM_ID identifies a form in the SURVEY_FORM table, the FIELD_ID identifies a field in the survey form and the LABEL field holds the question or label to identify the form data. SURVEY_EXECUTION Table This table is used to store information about how many times each survey is exe- cuted. The EXEC_ID is automatically generated per new execution of the survey. The SURVEY_ID identifies the survey being executed, the SURVEY_TS is used to store the execution time of the survey. SURVEY_RESPONSE Table This table holds the survey response data per survey participant. The ID field is used to create an automatic sequence number, which is unique per row. The EXEC_ID identifies the execution number of the survey, which is identified by SURVEY_ID. The SUID field is the user ID for the participant, the FIELD_ID identifies the ques- tion, and the VALUE field stores the response data. SURVEY_RESPONSE_RECORD Table This table is used to control how many times a user participating in a single survey posts data. Currently, one survey response per user is allowed. The EXEC_ID identi- fies the survey response being recorded for a given survey, the SUID identifies the participant, and the SUBMIT_TS stores the survey response time. The ch14/sql/survey_tool.sql file in the CDROM is an implementation of the survey database. To implement this survey database in MySQL you can create a database called SURVEY in your database server and run the following command: mysql -u root -p -D SURVEY < survey_tool.sql Make sure you change the user name (root) to whatever is appropriate for your system. When you have the survey database designed you need to design the PHP classes that will be needed to implement the applications. In the following sections, I discuss these classes. 478 Part III: Developing E-mail Solutions 18 549669 ch14.qxd 4/4/03 9:26 AM Page 478 Designing and Implementing the Survey Classes As shown in the system diagram (Figure 14-2) five objects are needed to implement the survey system. Here you will develop five classes that will provide these objects for your survey applications. Designing and implementing the Survey Class The Survey class is used to manipulate each survey. It allows an application to create and delete a survey and its execution data. The ch14/apps/class/class. Survey.php in the CDROM is an implementation of this class. This class imple- ments the following methods. SURVEY() This is the constructor method. It performs the following functions: ◆ Sets a member variable named survey_tbl to $SURVEY_TBL, which is loaded from the survey.conf file. The $SURVEY_TBL holds the name of the survey table. ◆ Sets a member variable named survey_execution_tbl to $SURVEY_ EXECUTION_TBL , which is loaded from the survey.conf file. The $SURVEY_EXECUTION_TBL holds the name of the survey execution table. ◆ Sets a member variable named response_tbl to $SURVEY_RESPONSE_TBL, which is loaded from the survey.conf file. The $SURVEY_RESPONSE_TBL holds the name of the survey response table. ◆ Sets a member variable named response_rec_tbl to $SURVEY_RESPONSE_ RECORD_TBL , which is loaded from the survey.conf file. The $SURVEY_ RESPONSE_RECORD_TBL holds the name of the survey response record table. ◆ Sets a member variable named dbi to point to the class.DBI.php-provided object, which is passed to the constructor by an application. The dbi mem- ber variable holds the DBI object, which is used to communicate with the back-end database. ◆ Sets a member variable called SURVEY_ID to the given survey ID, if any. GETSURVEYID() This method returns the current survey ID of the Survey object. SETSURVEYID() This method sets the survey ID of the Survey object. GETSTATUS() This method returns the status ( STATUS field) of the survey from the SURVEY table. Chapter 14: E-mail Survey System 479 18 549669 ch14.qxd 4/4/03 9:26 AM Page 479 SETSTATUS() This method updates the status (STATUS field) of the survey in the SURVEY table. GETSURVEYINFO() This method returns all the information about the survey from the SURVEY table. GETLISTID() This method returns the list ID that is used for a survey. GETFORMID() This method returns the form ID for a given survey. ADDSURVEY() This method adds a new survey into to the SURVEY table. The sur- vey name, list ID, form ID, and the creator ID (user ID) are passed as parameters to the method. DELETESURVEY() This method deletes the named survey from the database. It will delete all data related to the survey from the survey database. This includes the response data as well. DELETEEXECUTIONRECORDS() This method deletes all execution records related to a survey. DELETERESPONSESBYEXECID() This method deletes all responses related to an execution of a survey. GETEXECUTIONRECORDLIST() This method returns the execution records for a given survey. The execution records are returned an associative array, with execu- tion ID ( EXEC_ID) being the key and the full execution record as a row object. ADDEXECUTIONRECORD() This method adds an execution record for a given sur- vey in the SURVEY_EXECUTION table and returns the newly created EXEC_ID for the survey. The method first inserts the new execution record in the SURVEY_EXECUTION table and then selects the EXEC_ID from the same table. GETAVAILABLESURVEYS() This method returns a list of available surveys in the database. It returns an associative array, which uses the SURVEY_ID as the key and survey name (NAME) as the value. GETRETURNVALUE() This is a utility method that returns TRUE if the DBI returned result is set to DB_OK, which notifies that the SQL operation was successful; other- wise, it returns FALSE. Designing and implementing the SurveyList Class This class provides the survey List object. The List object is used to manipulate survey lists. It allows an application to create and delete survey lists. Survey lists 480 Part III: Developing E-mail Solutions 18 549669 ch14.qxd 4/4/03 9:26 AM Page 480 . appropriate for your system. When you have the survey database designed you need to design the PHP classes that will be needed to implement the applications. In the following sections, I discuss. application to create and delete a survey and its execution data. The ch14/apps/class/class. Survey .php in the CDROM is an implementation of this class. This class imple- ments the following methods. SURVEY(). the survey response record table. ◆ Sets a member variable named dbi to point to the class.DBI .php- provided object, which is passed to the constructor by an application. The dbi mem- ber variable

Ngày đăng: 07/07/2014, 07:20

TỪ KHÓA LIÊN QUAN