Tải bản đầy đủ (.pdf) (5 trang)

Secure PHP Development- P69 ppsx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (98.2 KB, 5 trang )

Variable Purpose
$DEFAULT_THEME The default theme index in the
$THEME_TEMPLATE array.
$USER_DEFAULTS A user’s theme and auto tip default settings.
$TIP_SCRIPT The name of the tip script.
$TIP_URL The Web-relative path for the tip files.
$MAX_AVAILABLE_TIP The maximum number of tips from which to
display the tip.
$THEME_TEMPLATE[x] The list of theme templates
$PRINT_TEMPLATE[x] The list of print templates associated with the
theme templates.
The directory structure used in the contact.conf file (in the ch09 directory on
the CD-ROM) may need to be tailored to your own system’s requirements. Here is
how the current directory structure looks:
+ htdocs ($ROOT_PATH == %DocumentRoot%)
|
+ home (base intranet application discussed in chapter 7)
| |
| + templates
| |
| + themes (theme templates used by all intranet apps)
|
+ photos (user photos used by all intranet apps)
|
+ contact_mngr (Intranet Contact Manager Application)
|
+ apps (contact manager apps and configuration files)
|
+ class (contact manager apps and configuration)
|
+ templates (contact manager HTML templates)


|
+ themes (symbolic link to home/templates/themes)
Chapter 9: Intranet Contact Manager 311
12 549669 ch09.qxd 4/4/03 9:25 AM Page 311
By changing the following configuration parameters in contact.conf, you can
modify the directory structure to fit your site requirements:
$APP_FRAMEWORK_DIR=$_SERVER[‘DOCUMENT_ROOT’] . ‘/framework’;
$PEAR =$_SERVER[‘DOCUMENT_ROOT’] . ‘/pear’;
$PHPLIB =$_SERVER[‘DOCUMENT_ROOT’] . ‘/phplib’;
$ROOT_PATH = $_SERVER[‘DOCUMENT_ROOT’];
$REL_ROOT_PATH = ‘/contact_mngr’;
$REL_APP_PATH = $REL_ROOT_PATH . ‘/apps’;
$REL_PHOTO_DIR = ‘/photos’;
$PHOTO_DIR = $ROOT_PATH . $REL_PHOTO_DIR;
$TEMPLATE_DIR = $ROOT_PATH . $REL_APP_PATH . ‘/templates’;
$THEME_TEMPLATE_DIR = $TEMPLATE_DIR . ‘/themes’;
$CLASS_DIR = $ROOT_PATH . $REL_APP_PATH . ‘/class’;
$REL_TEMPLATE_DIR = $REL_APP_PATH . ‘/templates/’;
The messages file
The messages displayed by the contact manager applications are stored in the
ch9/apps/contact.messages file in the CDROM. You can change the messages
using a text editor.
The errors file
The error messages displayed by the contact manager applications are stored in the
ch9/apps/contact.errors file in the CDROM. You can modify the error messages
using a text editor.
The Application Templates
The HTML interface templates needed for the contact manager system applications
are included on the CD-ROM. These templates contain various template tags to dis-
play necessary information dynamically. They are named in the contact.conf file.

These templates are discussed in Table 9-3.
TABLE 9-3 HTML TEMPLATES
Configuration Variable Template File Purpose
$STATUS_TEMPLATE contact_status.html Shows status message.
$CONTACT_HOME_TEMPLATE contact_home.html Contact index template.
312 Part II: Developing Intranet Solutions
12 549669 ch09.qxd 4/4/03 9:25 AM Page 312
Configuration Variable Template File Purpose
$CONTACT_CAT_HOME_ contact_cat_home.html Category index template.
TEMPLATE
$CONTACT_INFO_ADD_ contact_info_add_
Web form template to
MOD_TEMPLATE mod.html add or modify contacts.
$CONTACT_CAT_ADD_ contact_cat_add_ Web form template to
MOD_TEMPLATE mod.html add or modify categories.
$CONTACT_DETAILS_ Contact_details.html Contact details template.
TEMPLATE
$CONTACT_SEARCH_ contact_search_
Shows the search
INPUT_TEMPLATE input.html options.
$CONTACT_SEARCH_ contact_search_ Shows the search output.
RESULT_TEMPLATE result.html
$REMINDER_MSG_TEMPLATE reminder_contents.html
Shows the reminder.
$CONTACT_MAIL_TEMPLATE contact_mail.html Takes input for the mail
to contact.
$CONTACT_MAIL_ contact_mail_ Shows details of each of
DETAIL_TEMPLATE detail.html the sent mails.
The Contact Category Manager
Application

The application contact_category_mngr.php is responsible for managing contact
categories. This application is included on the CD-ROM in the ch9/apps directory.
It implements the following functionality:

Allows administrative users to create, modify, and delete categories.

Does not allow non-administrative users to create, modify, or delete
categories.
This application has the following 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:
Chapter 9: Intranet Contact Manager 313
12 549669 ch09.qxd 4/4/03 9:25 AM Page 313

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.

Next, the appropriate driver is called according to the $cmd value. For
example, if the $cmd is set to ‘add’, then addDriver() is called.

setUserType(): This method sets $this->isAdmin to TRUE if the user is
administrator; otherwise, it sets it to FALSE. Here is how it works:

It checks whether the user has a valid user ID. If she does, then 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 contact.conf, then it sets the isAdmin as TRUE.
Otherwise, it sets isAdmin as False.

deleteCategory(): This method controls how categories are deleted. It
works as follows:

If del_opt is set to 1, it deletes the category and everything related to
that category, including subcategories and contacts, from the database.

If del_opt is set to 2, then siblings or children of this category are
assigned to the new given parent and only the category information is
deleted.

Whatever del_opt is, this method shows the appropriate confirmation
message at the end of the operation.

addCategory(): This method adds a new category or subcategory to the
database. If it’s adding a subcategory, it assigns a parent to the category.
This is how it works:

It checks whether the new category to be added is a parent or a subcat-
egory. If it is chosen to be a subcategory, the method finds out the par-
ent category for the category.

Then it prepares an associative array with the necessary attribute name
and the values to add the category to the CONTACT_CATEGORY table. The
parent category ID is set to 0 if the new category is a parent; otherwise,
the parent category ID that has been specified is set.


The array is passed into the addCategory() method of the category
class.

The status (success/failure) of the add operation is shown to the user at
the end.
314 Part II: Developing Intranet Solutions
12 549669 ch09.qxd 4/4/03 9:25 AM Page 314

displayDeleteOptions(): This method is used to display deletion
options (a deletion options page that contains two radio buttons and a list
box/combo box) to the user. This is how it works:

It checks whether there is a category ID supplied to the method. If there
is no category ID, it shows an alert message and returns to the previous
page.

A delete option menu template ($CONTACT_CAT_DEL_OPT_TEMPLATE) is
loaded in a template object called $template.

This template includes a Web form with two radio buttons. One of the
buttons is to delete all subcategories and contacts under the selected
category. The other button is to transfer all its subcategories and con-
tacts to some other category (to be selected from a combo box).

If the category to be deleted is a parent category, then the combo box
is loaded with all of the other parent categories.

If the category to be deleted is a subcategory, then the combo box is
loaded with the subcategories that fall under the subcategory’s parent.


The contents of the $template object are inserted into the
$themeTemplate object’s content block, and the results are printed on
user’s browser screen.

displayAddModifyMenu(): This method displays the add or modify cate-
gory Web form as needed. It works as follows:

An add modify menu template ($CONTACT_CAT_ADD_MOD_TEMPLATE) is
loaded in a template object called $template.

The template includes a Web form that takes input such as category
name, category description, and category hierarchy (parent/sub). The
list of parent categories becomes enabled when the user chooses the
category to be a parent category.

Finally, the contents of the $template object are inserted into the
$themeTemplate object’s content block and the results are printed on
the user’s browser screen.

modifyCategory(): This method is used to modify a given category. It
works as follows:

It checks whether there is category ID supplied to the method. If there
is no category ID, it shows an alert message and returns to the previous
page.

If the request is to change a parent category to a subcategory, this method
denies that if the parent (main) category already has subcategories (we’re
limited to one level of subcategory). Under this circumstance, it shows an
alert method and takes the administrator back to previous page.

Chapter 9: Intranet Contact Manager 315
12 549669 ch09.qxd 4/4/03 9:25 AM Page 315

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×