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

Secure PHP Development- P82 ppsx

5 286 0
Tài liệu đã được kiểm tra trùng lặp

Đ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 84,17 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

◆ Next It creates a category object called $categoryObjand calls the addCategorywith the category name and parent category ID if given and the user ID.. ◆ Finally, the showWithThememetho

Trang 1

◆ 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 $categoryObjand calls the addCategory()with the category name and parent category ID (if given) and the user ID

◆ If the addCategory()method returns TRUEstatus, 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 CATEGORYtable or not using the existInList()method If the name exists, then it gives an appropriate message and returns null

◆ Next, it creates a categoryobject called $categoryObjand calls the modifyCategory()with the category ID, category name, parent category

ID (if given), and the user ID

◆ If the modifyCategory()method returns TRUEstatus, 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:

Trang 2

◆ 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 Categoryobject with the given category ID If it successfully deletes the category from the CATEGORYtable, 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 $menuTemplateis created To load the template file, $templateFileis passed to this method as input

◆ Next it creates a Categoryobject 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 $menuTemplateis created To load the template file, $templateFileis 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

Trang 3

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 $categoryObjis 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 $blockNameis set to jsblockblock, then it parses the jsCategoryBlockand sets the output into the $categoryvariable Otherwise, if the category ID is not equal to the $selectValue, it parses the categoryBlockblock and sets the output in the $categoryvariable

◆ Finally, this method returns the value of the $categoryvariable

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 $subcatagoryObjand 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 $subCategoryvariable 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:

Trang 4

◆ A template object called $menuTemplateis 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 $menuTemplateobject and assigns values to the HTML template variables using set_var()method of the $menuTemplateobject

◆ 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 $themeTemplateobject

◆ This method is called with a parameter called $output, which will

be shown with the theme template This $outputis 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/appsdirectory 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.phpfile in the CDROM is an implementa-tion of this applicaimplementa-tion This applicaimplementa-tion has the following methods

Trang 5

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->themeby calling the getUserTheme()method of the theme object created

◆ Next if the query parameter cmdis set to add, then it calls the addDriver()method; if $cmdis set to delete, then the delete()method starts running If $cmdis set to modify, then it calls the modifyDriver()

or if $cmdis 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, $stepis set to 1, then it calls the selectResource()

to show the option for selecting the resource to be modified

◆ If $stepis 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 $stepis 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:

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