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

Secure PHP Development- P71 doc

5 147 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 123,55 KB

Nội dung

◆ displaySearchResult(): This method displays the result of the search performed according to the user’s query. The result shows a list of con- tacts that matches the search criteria. This is how it works: ■ A search result template (CONTACT_SEARCH_RESULT_TEMPLATE) is loaded in a template object called $template. ■ The ‘where’ clause of the search query is prepared using the informa- tion given by the user. ■ The ‘where’ clause is passed into the searchContact() method of the Contact class to search for the contact. searchContact() returns an array of contacts if it finds a match. ■ The array of contacts is then fed into the contact block of the template. If no match is found, the array is empty, the contact block is set with a message indicating that no match was found. ■ showContents() is called to render the template with the appropriate theme. ◆ displaySearchMenu(): This method displays the contact search Web form as needed. It works as follows: ■ A search input template (CONTACT_SEARCH_INPUT_TEMPLATE) is loaded in a template object called $template. ■ The template includes a Web form to take input such as company name, contact name, subcategory, category, and keywords to search for contacts. ■ The subcategory list is empty until the user chooses a category. ■ showContents() is called to render this template with the appropriate theme. ◆ displayMailMenu(): This method displays the e-mail menu where the user can write her e-mail to send to a contact. This is how it works: ■ A mail template (CONTACT_MAIL_TEMPLATE) is loaded in a template object called $template. ■ The template includes a Web form to take input (CC address, mail sub- ject, mail body, and so forth). ■ The ID of the contact that is the target of this mail is stored as hidden HTML field in this template for later use. ■ showContents()is called to render this template with appropriate theme. Chapter 9: Intranet Contact Manager 321 12 549669 ch09.qxd 4/4/03 9:25 AM Page 321 Here are the other methods used in this application: Method Description authorize() Authorizes the user access to this application. It authorizes all users only when the cmd value is search, detail, or null. (Other cmds (add/modify/delete) are available only to users with administrative privilege.) It returns TRUE if it finds the cmd to be one of the three. Otherwise, it depends on setUserType() to get the value of the isAdmin variable that identifies whether the user is an administrator or not and returns TRUE or FALSE depending on that value. setUserType() Sets $this->isAdmin to TRUE if the user is an administrator; otherwise, it sets it to FALSE. It checks whether the user has a valid user ID. If she does, it gets the type of the user using the getType() method of the User class. If the type of the user is the same as CONTACT_ADMIN_TYPE, which is taken from the conact.conf, then it sets the isAdmin to TRUE. Otherwise, it sets isAdmin to FALSE. mailDriver() Controls how e-mail operations are performed on contacts. If step is set to 1 or step is unset, it calls displayMailMenu() to show the e-mail input menu. If step is set to 2, it calls mailToContact() to send e-mail to the contact. If step is set to 3, it runs showMail() to display e-mail information. addDriver() Controls how new contacts are created. If step is set to 1 or step is unset, it calls displayAddModifyMenu() with mode as ‘add’ to display the create contact Web form. If step is set to 2, it runs addContact() to do the contact-creation process. modifyDriver() Controls how modify operations are performed on contacts. If step is set to 1 or step is unset, it calls displayAddModifyMenu() with mode as ‘modify’ to display the create contact Web form. If step is set to 2, it runs modifyContact() to do the contact creation process. 322 Part II: Developing Intranet Solutions 12 549669 ch09.qxd 4/4/03 9:25 AM Page 322 Method Description searchDriver() Controls how search operations are performed on contacts. If step is set to 1 or step is unset, it calls displaySearchMenu() to display the search contact Web form. If step is set to 2, it runs displaySearchResult() to display search output. showContents() Displays the given contents according to the theme preferences of the user. The user’s preferred theme template is loaded in a template object called $themeTemplate. The template contains a contentBlock that is to be filled by the parameter to this method. After the passed content is set into the contentBlock, it is rendered to the user. Installing Intranet Contract Manager Here I assume the following: ◆ You’re using a Linux system with MySQL and Apache server installed. ◆ You’ve followed the instructions in Chapters 5, 6, and 7 to create a base intranet system with user home page applications. ◆ Your intranet web server document root directory is /evoknow/ intranet/htdocs . Of course, if you have a different path, which is likely, you should change this path whenever you see it in a configuration file or instruction in this chapter. During the installation process, I refer to this directory as %DocumentRoot%. ◆ You’ve installed the PHPLIB and PEAR library. Normally, these get installed during PHP installation. For your convenience, I’ve provided these in the lib/phplib.tar.gz and lib/pear.tar.gz directories on the CD-ROM. In these sample installation steps, I assume that these are installed in %DocumentRoot%/phplib and %DocumentRoot%/pear directo- ries. Because your installation location for these libraries is likely to differ, make sure you replace these paths in the configuration files. ◆ You have installed the INTRANET database (see Chapter 7 for details). Chapter 9: Intranet Contact Manager 323 12 549669 ch09.qxd 4/4/03 9:25 AM Page 323 Here is how you can get your contact manager applications up and running: 1. Install base intranet applications. If you haven’t yet installed the base intranet user home application and the messaging system discussed in Chapter 7, you must do so before proceeding further. 2. Install intranet contact database tables. The ch9/sql/contact.sql file in the CDROM can be used to create the CONTACTS database. The quickest way to create this database is to run the following commands: mysqladmin –u root –p create CONTACTS mysql –u root –p –D CONTACTS < contact.sql 3. Install intranet contact manager applications. From the ch9 directory of the CD-ROM, extract ch9.tar.gz in %DocumentRoot%. This will create contact_mngr in your document root. Configure %DocumentRoot%/ contact_mngr/apps/contact.conf for path and database settings. The applications are installed in the %DocumentRoot%/contact_mngr/apps directory and the templates are stored in %DocumentRoot%/contact_mngr/apps/templates. Your MySQL server is hosted on the intranet web server and, therefore, it can be accessed via localhost. However, if this is not the case, you can easily modify the database URLs in each application’s configuration files. For example, the contact.conf file has a MySQL database access URLs such as: $INTRANET_DB_URL= ‘mysql://root:foobar@localhost/INTRANET’; $CONTACT_DB_URL = ‘mysql://root:foobar@localhost/CONTACTS’; $USER_DB_URL = ‘mysql://root:foobar@localhost/auth’; Say your database server is called db.domain.com and the user name and password to access the INTRANET and auth databases (which you will cre- ate during this installation process) are admin and db123. You would modify the database access URLs throughout each configuration file as $INTRANET_DB_URL = ‘mysql://admin:db123@db.domain.com/INTRANET’; $CONTACT_DB_URL= ‘mysql://admin:db123@db.domain.com/CONTACTS’; $USER_DB_URL = ‘mysql://admin:db123@db.domain.com auth’; 4. Set file/directory permissions. Make sure you have changed file and directory permissions so that your intranet web server can access all the files. 324 Part II: Developing Intranet Solutions 12 549669 ch09.qxd 4/4/03 9:25 AM Page 324 The default theme template (std_blue) has links to the document publish- ing application. If you’ve installed the document publishing applications anywhere other than %DocumentRoot%/contact_mngr/apps directory (default), you’ll need to modify the %DocumentRoot%/themes/ std_blue/home_left_nav.html file. Similarly, you have to modify the other (std_aqua, std_wheat) themes. After you’ve performed these steps, you’re ready to test your contact manager applications. Testing Contract Manager Log in to your intranet via http://yourserver/index.php or http://yours- erver/home/home.php using the user name and password you created in Chapter 6 and tested in Chapter 7. Click on the Contact Manager link in the left navigation bar of your intranet home page or point your web browser to http://yourserver/contact_mngr/ apps/contact_mngr.php after you’re logged in to the intranet. This displays the contact search interface, as shown in Figure 9-3. Figure 9-3: Contact manager search interface. Chapter 9: Intranet Contact Manager 325 12 549669 ch09.qxd 4/4/03 9:25 AM Page 325 . directory as %DocumentRoot%. ◆ You’ve installed the PHPLIB and PEAR library. Normally, these get installed during PHP installation. For your convenience, I’ve provided these in the lib/phplib.tar.gz. the CD-ROM. In these sample installation steps, I assume that these are installed in %DocumentRoot%/phplib and %DocumentRoot%/pear directo- ries. Because your installation location for these libraries. the ch9 directory of the CD-ROM, extract ch9.tar.gz in %DocumentRoot%. This will create contact_mngr in your document root. Configure %DocumentRoot%/ contact_mngr/apps/contact.conf for path and

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