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

Secure PHP Development- P82 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 (84.17 KB, 5 trang )


First, this method checks whether the category name ($newcategory) is
provided or not. If it is not provided, then an error message is shown and
it returns null.

Next it checks whether the category is already existing in the category list
of the database or not. If it already exists in the database, then it gives an
appropriate message. Otherwise, it follows the following processes.

Next It creates a category object called $categoryObj and calls the
addCategory() with the category name and parent category ID (if given)
and the user ID.

If the addCategory() method returns TRUE status, an appropriate status
message is shown. The status message is created using the getMessage()
method.

In case of failure to add, a failure status message is shown.

Finally, the showWithTheme() method is called with the status message
embedded in the user theme template.
modifyCategory()
This method updates modified information to the database. It works as follows:

First, this method checks whether the category name ($newcategory) is
provided or not. If it is not provided, then an error message is shown and
returns null.

Next, it checks whether the name of the category is changed or not. If
the name is changed, then it checks whether the new given name already
exists in the CATEGORY table or not using the existInList() method. If


the name exists, then it gives an appropriate message and returns null.

Next, it creates a category object called $categoryObj and calls the
modifyCategory() with the category ID, category name, parent category
ID (if given), and the user ID.

If the modifyCategory() method returns TRUE status, a successful
modification massage is shown. The message is constructed using the
getMessage() method.

In case of failure to modify, a failure status message is shown.

Finally the showWithTheme() method is called with the status message
embedded in the user theme template.
deleteCategory()
This method deletes category information. It works as follows:
376 Part II: Developing Intranet Solutions
14 549669 ch11.qxd 4/4/03 9:25 AM Page 376

This method first checks whether the category ID is provided or not. If it is
not given, then it shows an error message and returns null.

If the given category has resources or its subcategories have resources or
more subcategories, then it shows an error message and returns null.

Next it calls deleteCategory() method of the Category object with
the given category ID. If it successfully deletes the category from the
CATEGORY table, then it gives the category a successfully deleted message;
otherwise, it gives the deletion failure message.


Finally, it calls the showWithTheme() method to show the message with
the user’s theme.
displayModifyCategoryMenu()
This method displays the modify category Web form. It works as follows:

This method first checks whether any category is selected by the user to
modify or not. If it is not provided, then an error message is shown and
returns null.

A template object called $menuTemplate is created. To load the template
file, $templateFile is passed to this method as input.

Next it creates a Category object called $catObj.

If the selected category is a main category, then it calls the
getCategoryName() to get the selected main category name; otherwise, it
calls getCategoryName() for getting the main category and the selected
sub-category name.

Next it calls the populateCategory() method to generate the main cate-
gory names.

Then it parses the main block of the template and calls the
showWithTheme() method with the output template, which is embedded
in the user’s theme template.
displayAddCategoryMenu()
This method displays the add new category Web form. It works as follows:

A template object called $menuTemplate is created. To load the template
file, $templateFile is passed to this method as input.


Then it calls the populateCategory() method to generate the list of
parent (main) categories as an HTML drop-down list.

Finally, parsing the main block, it calls the showWithTheme() method
with the output template, which is embedded in the user’s theme template.
Chapter 11: Internet Resource Manager 377
14 549669 ch11.qxd 4/4/03 9:25 AM Page 377
populateCategory()
This method is used to populate the list of all available main categories. It works as
follows:

This method is called with the template name ($template), the block
name ($blockName), and the default selected value ($selectValue).

A new category object called $categoryObj is created and the
getCategoryList() method of that object is called to generate the avail-
able main categories name and stored in a array named $categoryList.

If the category list is not empty, then it sets the category ID and name for
each category in the list; otherwise, it returns null.

If $blockName is set to jsblock block, then it parses the
jsCategoryBlock and sets the output into the $category variable.
Otherwise, if the category ID is not equal to the $selectValue, it parses
the categoryBlock block and sets the output in the $category variable.

Finally, this method returns the value of the $category variable.
populateSubCategory()
This method is used to populate the subcategory list for the given category. It works

as follows:

This method is called with the template name ($template), category ID
($cat_id), and the HTML template block name ($blockName) in which
block the subcategory will be populated.

A new object of category class is created named $subcatagoryObj and
from that class, the getSubCategoryList() method is called with the
given category ID ($cat_id) as a parameter. The subcategory list is stored
in the array named $subcategoryList.

If the subcategory list is not there, it checks the given HTML template block
name. Then it sets the subcategory name and ID in respective variables in
the given block and sets the output in the $subCategory variable parsing
the block.

Finally, this method returns the subcategory list stored in the
$subCategory.
showMenu()
This method displays add, delete, and modify category options. It works as follows:
378 Part II: Developing Intranet Solutions
14 549669 ch11.qxd 4/4/03 9:25 AM Page 378

A template object called $menuTemplate is created. To load the template,
a file named $IRM_CAT_HOME_TEMPLATE (configurable via irm.conf) is
passed to the method.

Then it defines all the HTML template block names using set_block()
method of the $menuTemplate object and assigns values to the HTML
template variables using set_var() method of the $menuTemplate object.


Next it calls the populateCategory() and sets the return value in the
required blocks.

Finally it parses the main block and calls the showWithTheme() method
to show output with the user’s theme.
showWithTheme()
This method is used to show user’s theme template. It works as follows:

It creates a theme template object called $themeTemplate.

The user’s theme template is loaded into the $themeTemplate object.

This method is called with a parameter called $output, which will
be shown with the theme template. This $output is set into in the
‘CONTENT_BLOCK’ block.

Then it parses all the blocks and shows the final output.
authorize()
This method authorizes everyone on the intranet to view the resource manager and,
therefore, always returns TRUE.
Creating a Resource
Manager Application
This application, irm_resource_mngr.php, is responsible for managing resources.
This application is included on the CD-ROM in the ch11/apps directory. It imple-
ments the following functionality:

It allows administrators to create, modify, and delete resources.

Non-administrative users can only create resources.

The
ch11/apps/irm_resource_mngr.php file in the CDROM is an implementa-
tion of this application. This application has the following methods.
Chapter 11: Internet Resource Manager 379
14 549669 ch11.qxd 4/4/03 9:25 AM Page 379
run()
When the application is run, this method is called. It does the following:

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 if the query parameter cmd is set to add, then it calls the
addDriver() method; if $cmd is set to delete, then the delete() method
starts running. If $cmd is set to modify, then it calls the modifyDriver()
or if $cmd is set to the disdes (short for display description) then it calls
the displayDescription() method.
In other words, the
run() method decides which functionality is requested by
the user and calls the appropriate driver method to perform the desired operations.
addDriver()
This method controls how add operations are performed on resources. It works as
follows:

If $step, query parameter, is set to 2, when called this method is called.
It invokes the addResource() method to insert the resource then.

Otherwise, this method calls the showAddMenu() method to show the
resource creation options.

modifyDriver()
This method controls how modify operations are performed on categories. It works
as follows:

If query parameter, $step is set to 1, then it calls the selectResource()
to show the option for selecting the resource to be modified.

If $step is set to 2, then it calls the showModifyMenu() to show the
selected resource property where the user is able to modify the resource.

If the $step is set to 3, it calls the modifyResource() method to modify
the resource property.
populateCategory()
This method is used to populate the list of all available main categories. It works as
follows:
380 Part II: Developing Intranet Solutions
14 549669 ch11.qxd 4/4/03 9:25 AM Page 380

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

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