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

Secure PHP Development- P83 pptx

5 198 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 81,83 KB

Nội dung

◆ This method is called with the template name ($template), HTML template 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 then it parses the jsCategoryBlock and sets the output into the $category variable. Otherwise, it parses the categoryBlock block to see whether the category ID is equal to the $selectValue or not and sets the output in the $category variable. ◆ Finally this method returns the value of $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 block name ($blockName) where the subcategory will be populated. ◆ A new object of category class is created named $subcatagoryObj and the getSubCategoryList() method is called of the class with the given category ID ($cat_id) as the parameter. The subcategory list is stored in the array named $subcategoryList. ◆ If the subcategory list is not there, then it checks the given block name. Then it sets the subcategory name and ID in respective variables in the given block and parses the block and sets the output in the $subCategory variable. ◆ Finally, this method returns the subcategory list stored in the $subCategory. showAddMenu() This method displays the Web form to add new resources. It works as follows: ◆ 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. Chapter 11: Internet Resource Manager 381 14 549669 ch11.qxd 4/4/03 9:25 AM Page 381 ◆ Next this method creates an object of user class named $userObj. Then it calls the getUserList() method of that object to get all users’ e-mail addresses. The user’s name is taken from each e-mail address field. ◆ Then This method calls populateCategory to generate the category list. ◆ Finally, the showWithTheme() method is called with the output of parsing main block to embed the message in the user theme template. addResource() This method adds the new resource to the database. It works as follows: ◆ First, this method checks whether it is called with valid and required input or not. It checks where the category is provided or not. If it is not provided, then it gives an error message of “category name missing” and returns null. ◆ Next, it checks if the resource name and URL are given or not. If they are not given, then an error message is shown and returns immediately. ◆ It checks the validity of the given URL. If it is not valid, then it shows the appropriate error message to the user and returns from the method. ◆ If a new category name is provided by the user of his own, then it checks whether the category is already existing or not. If not, then it adds the new category in the CATEGORY table. ◆ Now it creates an object of resource class and call the addResource() method with the proper parameter in the RESOURCE table. If it can success- fully add the resource, then it returns the resource ID. If it fails to add, then a message is shown that the resource could not be added. ◆ If the resource is added successfully, then it generates intranet MOTD messages for the requested users. ◆ Finally, it calls the displayWithTheme() method to show the message with the user’s theme. showModifyMenu() This method displays the modify resource Web form. It works as follows: ◆ First, this method checks whether any resource name ($resource) is selected or not. If not, it gives an error message and returns from the method. ◆ 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. 382 Part II: Developing Intranet Solutions 14 549669 ch11.qxd 4/4/03 9:25 AM Page 382 ◆ Then an object of Resource class is created named $resourceObj. It calls getResourceInfo() with the resource ID to get the information about the selected resource and calls getKeywords() to get keywords for the resource. ◆ Next it sets the resource information in the template. ◆ It calls populateCategory() to generate the category list. ◆ Finally, the showWithTheme() method is called with the output of parsing the main block to embed the message with the user theme template. modifyResource() This method updates modified resource information to the database. It works as follows: ◆ First, this method checks whether the category is provided. If the category is not provided, then it gives an error message and returns null. ◆ Next, the method checks whether the resource name and URL is given. If the resource name is not given, then an error message is shown and it returns null. ◆ Then It checks the validity of a given URL. If the URL is not valid, then it shows the appropriate error message to the user (“incorrect URL given”) and returns from the method. ◆ If a new category name is provided by the user of his own, then it checks whether the category already exists. If it doesn’t exist, then it adds the new category in the CATEGORY table. ◆ Then It creates an object of Resource class and calls the modifyResource() method with the proper parameter to resource in the RESOURCE table. If it successfully modifies the resource, then it returns the resource ID. If it fails to modify, then a message is shown that the resource is not modified. ◆ If the resource is modified successfully, then it deletes all the previous keywords and adds new keywords in the RESOURCE_KEYWORD table. ◆ Finally, it calls the displayWithTheme() method to show the message with the user’s theme. delete() This method deletes resource information. It works as follows: ◆ This method first checks whether any resource is selected to delete or not. If it is not given, then an error message is shown and returns null. Chapter 11: Internet Resource Manager 383 14 549669 ch11.qxd 4/4/03 9:25 AM Page 383 ◆ Then it creates an object of Resource class and calls deleteKeywords() with the selected resource ID as a parameter. ◆ If it successfully deletes the keywords, then it calls the deleteResource() method to delete the resource information from the RESOURCE table. ◆ Finally, it calls the displayWithTheme() method to show the status message of deletion with the user’s theme. displayDescription() This method is used to display the description of the given resource. It works as follows: ◆ A template object is created named $menuTemplate. This method then loads the $IRM_RESOURCE_DES_TEMPLATE template. ◆ Then It creates an object of Resource class and calls getResourceInfo() with the selected resource ID as a parameter, which returns the resource information. ◆ Next it sets the title and description in the template. ◆ Finally, it parses the main block and calls the displayWithTheme() method to show output with the user’s theme. selectResource() This method is used to give the user an option to choose a resource for modification. The method works as follows: ◆ First, the method creates an object of Category class named $catObj. ◆ Next it populates the main category by calling the populateCategory() method. ◆ If the $category is assigned any value, then it finds the subcategory list by calling the getSubCategoryList(). ◆ Then It checks whether the variable $change is assigned any value or not. If $change has any value, then it generates the resource list according to the main category or the subcategory changes. ◆ Finally the showWithTheme() method is called with the output of parsing the main block to embed the message with the user theme template. displayWithTheme() This method is used to show the user’s theme template. It works as follows: 384 Part II: Developing Intranet Solutions 14 549669 ch11.qxd 4/4/03 9:25 AM Page 384 ◆ 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 Tracking Application This application, irm_resource_track_mngr.php, is responsible for resources tracking. This application is included on the CD-ROM in the ch11/apps directory. The application has the following methods. run() This method is responsible for running the application. First it sets the user ID into a variable named $uid. Then it calls the keepTrack() method. keepTrack() This method keeps track of resource visits and updates the database. It works as follows: ◆ First it defines an array named $params containing the resource ID, visitor ID (user ID), and current time. ◆ Then it creates an object of Resource class and calls the trackResourceVisit() method with the $params array to insert records in the RESOURCE_VISITOR table. ◆ If it successfully inserts the data, then it calls the getResourceUrl() method to get the URL of the resource. ◆ Finally, it redirects the page to the resource URL. Chapter 11: Internet Resource Manager 385 14 549669 ch11.qxd 4/4/03 9:25 AM Page 385 . returns TRUE. Creating a Resource Tracking Application This application, irm_resource_track_mngr .php, is responsible for resources tracking. This application is included on the CD-ROM in the ch11/apps

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