■ It prepares an associative array with the necessary attribute name and the values to update the category table. ■ The array is passed into the modifyCategory() method of the Category class. ■ The status (success/failure) of the modify operation is shown to the user at the end. ◆ showContents(): This method displays the given contents according to the theme preferences of the user. This is how it works: ■ 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 para- meter to this method. ■ After the passed content is set into the contentBlock, it is rendered to the user. The following are the other methods used by this application: Method Description authorize() Authorizes access to this application. It calls setUserType() to set the member variable isAdmin and returns the value of isAdmin. This means that only users only with administrative authority can access this application. deleteDriver() Controls how delete operations are performed on categories. If step is set to 1 or is not set, it calls displayDeleteOptions() to display delete options. If step is set to 2, it runs deleteCategory() to do the category-deletion process. modifyDriver() Controls how modify operations are performed on documents and categories. If step is set to 1 or is unset, it calls displayAddModifyMenu() with a modify parameter to display the modify category Web form. If step is set to 2, it runs modifyCategory() to start the category modification process. 316 Part II: Developing Intranet Solutions 12 549669 ch09.qxd 4/4/03 9:25 AM Page 316 Method Description addDriver() Controls how add operations are performed on contacts and categories. If step is set to 1 or is unset, it calls displayAddModifyMenu() with an add parameter to display the new category Web form. If step is set to 2, it runs addCategory() to start the category-creation process. deleteContactsByCatID() Deletes all contacts for the given category. All information related to the contacts is also deleted. It takes the category ID as the parameter and uses the getContactsByCatID() and deleteContact() methods of the Contact class to find and delete the contacts, respectively. The Contact Manager Application The application contact_mngr.php is responsible for managing contacts. This application is included on the CD-ROM in the ch9/apps directory. Let’s take a look at its methods: ◆ run(): When the application is run, this method is called. It decides which functionality is requested by the user and calls the appropriate driver method to perform the desired operations: ■ Creates a theme object, $this->themeObj. ■ The current user’s theme choice is stored in $this->theme by calling the getUserTheme() method of the theme object created. Remembers, themes are part of the intranet as they allow users see the intranet pages in a certain look and feel. ■ It decides which method to call depending on the value of cmd. ■ If no cmd is specified, it calls searchDriver() to show the search menu. ◆ mailToContact(): This method gets e-mail information for the given contact, such as e-mail address, CC To, subject, body, and so forth, and sends e-mail to the contact. This is how it works: ■ It checks whether the e-mail body has been supplied or not. If not, it shows an alert message and takes the user back to the previous page. Chapter 9: Intranet Contact Manager 317 12 549669 ch09.qxd 4/4/03 9:25 AM Page 317 ■ The storeMail() method of the Contact class is used to store the e-mail information that includes the contact ID, CC address, subject of the mail, and mail send time. ■ The PHP’s mail API is used to send the e-mail with appropriate headers. ■ The user receives a confirmation after the e-mail is sent successfully. ◆ showMail(): This method displays e-mail information of a previously sent e-mail. This is how it works: ■ A mail content template (CONTACT_MAIL_DETAIL_TEMPLATE) is loaded in a template object called $template. ■ The template contains different blocks for date, mail to, mail CC to, mail subject, mail body, and so forth. ■ These blocks are set with appropriate values retrieved using the getMailDetails() method of the Contact class. ■ The template is parsed and printed to the user. ◆ showDetail(): This method shows detailed information of the given con- tact. This is how it works: ■ It checks whether the contact ID has been provided. If not, it shows an alert message and returns to previous page. ■ A contact detail template (CONTACT_DETAILS_TEMPLATE) is loaded in a template object called $template. ■ A new contact object is created and stored in $contactObj. The getKeywords() method of the Contact object is used to retrieve the keywords for the given contact and all keywords are stored into an array named $keywordArr. ■ The values of $keywordArr are taken into a string after separating them with commas. This string is set into appropriate blocks in the template later. ■ Reminders for the contact are also retrieved and set in the template. ■ All the attribute values of the CONTACT_INFO table are retrieved using the getColumnValue() method of the Contact object, and are ren- dered in the template file. ■ The sent e-mails are retrieved using getMails(). Sent e-mails are shown only to users having admin privilege. For non administrative users, this mail block is set to null to hide it from her. ■ showContents() is called to show the output of this template in the preferred theme template of the user. 318 Part II: Developing Intranet Solutions 12 549669 ch09.qxd 4/4/03 9:25 AM Page 318 ◆ displayContactMngrHome(): This method shows the administrator home page for the contact manager application. It shows all add, delete, and modify options for contacts and categories. This is how it works: ■ A contact home template (CONTACT_HOME_TEMPLATE) is loaded in a template object called $template. ■ The template includes combo boxes for category, subcategory, and con- tacts, and add, delete, modify links for both contacts and categories. ■ When the user first comes to this page, she sees the subcategory and contact lists to be empty and the category list loaded with all the par- ent categories that are retrieved using the getParentCategories() method of category class. ■ After she chooses a main category, the subcategory list loads with that category’s subcategories, retrieved using the getSubCategories() method of the Category class. Similarly, all the contacts of a chosen subcategory are shown using the getContactsByCatID() method of the Contact class. ■ Then showContents()is called to render the template with the appro- priate theme. ◆ deleteContact(): This method deletes the given contact and all related information such as: e-mails, reminders, keywords, and so on from the database. This is how it works: ■ It checks whether the category ID has been supplied. If not, it returns to previous page and shows an alert message. ■ It finds the MOTDs related to this contact using the getRelatedMOTDs() method of the Contact class, and then uses the deleteMessage() and deleteViewers() methods of the Message class to delete the messages and their viewers. ■ It calls the deleteContact() method of the Contact class to delete the contact. ■ It shows a confirmation message to the user depending on the status of the delete operation. ◆ addContact(): This method s adds new contacts to the database. It works as follows: ■ It creates an associative array with the given values such as first name, last name, phone, address, and so forth. ■ It uses the addContact() method of the Contact class and passes the array as parameter to add the new contact to the contact table. Chapter 9: Intranet Contact Manager 319 12 549669 ch09.qxd 4/4/03 9:25 AM Page 319 ■ It adds the keywords for this contact using the addKeywords() method of Contact class. ■ It adds reminder messages in the MOTD table, using the addMessage() and addViewer() methods of the Message class, if there are any reminders for this contact. A reminder entry is also added in the reminder table in this case using addReminder() method of the Contact class. ◆ modifyContact(): This method updates the database with the modified information. It works as follows: ■ It creates an associative array with the given values like contact ID, first name, last name, phone, address, and so on. The array contains all the attributes of the contact table as index and the modified contact information as values to those indexes. ■ It uses the modifyContact() method of the Contact class with this array to add the new contact to the CONTACT_INFO table. ■ It modifies the keywords for this contact using the modifyKeywords() method of the Contact class. ■ It deletes the previous messages from the MESSAGE table in the INTRANET database and previous reminders from the CONTACT_REMINDER table in the CONTACT database using deleteMessage(), deleteViewers(), and deleteRemindersByContactID(). ■ It adds the new reminder messages using the addMessage() and addViewer() methods of the Message class, if there are any reminders for this contact. The new reminder is also added in the CONTACT_REMINDER table in this case using the addReminder() method of the Contact class. ◆ displayAddModifyMenu(): This method displays the add or modify con- tact Web form, as needed. It works as follows: ■ A contact add/modify template (CONTACT_INFO_ADD_MOD_TEMPLATE) is loaded in a template object called $template. ■ The template includes a Web form to take personal information of the contact, the keywords for the contact, and the reminders for this contact. ■ The template also includes category and subcategory lists from which the user has to choose the appropriate category and subcategory for this contact. The lists are loaded using the getParentCategories() and getSubCategories() methods of the Category class. ■ Then the showContents() method is called to render the template with appropriate theme. 320 Part II: Developing Intranet Solutions 12 549669 ch09.qxd 4/4/03 9:25 AM Page 320 . delete the contacts, respectively. The Contact Manager Application The application contact_mngr .php is responsible for managing contacts. This application is included on the CD-ROM in the ch9/apps. information that includes the contact ID, CC address, subject of the mail, and mail send time. ■ The PHP s mail API is used to send the e-mail with appropriate headers. ■ The user receives a confirmation