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

Secure PHP Development- P50 pot

5 239 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 102,82 KB

Nội dung

associative array called $breakdown. The breakdown contains login, logout, office hours, and extra hours. ◆ getLogs(): This method returns an associative array containing login, logout, office hours, and extra hours information for a given start and end timestamp of an activity log record. It works as follows: ■ The method is called with an associative array parameter called $params, which contains information from the configuration file (home.conf) regarding start of office hours (OFFICE_START), end of office hours (OFFICE_END), start of lunch hour (LUNCH_START), and end of lunch hour (LUNCH_END). These settings are found as follows in the default configuration file: define(‘OFFICE_START_TIME’, 10); //24 HRS TIME FORMAT define(‘LUNCH_START_TIME’, 13); //24 HRS TIME FORMAT define(‘LUNCH_END_TIME’, 14); //24 HRS TIME FORMAT define(‘OFFICE_END_TIME’, 19); //24 HRS TIME FORMAT ■ The method defines an associative array called $retArr, which is what it returns after inserting appropriate key = value parameters. ■ It stores the start ($start) parameter as the login time in the $retArr. Similarly, it stores the end ($end) parameter as the logout time in the $retArr. ■ Office hours are initialized in a method variable $office to be zero. Extra hours are initialized to a method variable called $extra to be zero. ■ A global parameter $WEEKEND is loaded. This parameter is set in the configuration file as an array. The default configuration in home.conf for this array is $WEEKEND = array(‘Sat’, ‘Sun’); ■ The method checks to see whether the day of $start timestamp is in the $WEEKEND array. If so, it sets the $office variable to zero, because only extra (overtime) hours are allowed on weekends. It calculates the $extra time by subtracting the $start from $end. ■ If the start ($start) timestamp does not represent a weekend day, the method calculates the office hours by excluding the lunch hours from the office hours. It also calculates any extra hours that are beyond the office hours. ■ The method returns $retArr with login, logout, total office, and total extra hour information. ◆ getOfficeAndExtraBreakdown(): This method returns an associative array containing total office hours and total extra hours information for a given start and end timestamp of an activity log record. 216 Part II: Developing Intranet Solutions 10 549669 ch07.qxd 4/4/03 9:25 AM Page 216 The method is called exactly as getLogs() is, and it performs the same way. The method returns total office and total extra hour information in an anonymous associative array. The following table describes the rest of the methods for this class: Method Description ActivityAnalyzer() The constructor method. It sets an object variable named dbi to point to the class.DBI.php-provided object, which is passed to the constructor by an application. dbi is used to communicate with the backend database. It also sets an object variable called activity_tbl to $ACTIVITY_TBL, which is loaded from the configuration file ( home.conf). The $ACTIVITY_TBL variable holds the name of the activity table. logUserOut() Records a logout activity (ACTIVITY_TYPE = 2) in the ACTIVITY table for a given user by inserting a new activity row for the user ( $uid) at given time ($time). If the logout activity is successfully inserted into the database, the method returns true. Otherwise it returns false. logUserIn() Records a login activity (ACTIVITY_TYPE = 1) in the ACTIVITY table for a given user by inserting a new activity row for the user ( $uid) at given time ($time). If the login activity is successfully inserted into the database, the method returns true; otherwise, it returns false. Creating the IntranetUser class This InternetUser class provides the intranet user object, which is used to retrieve and set user information. The ch07/home/class/class.IntranetUser.php file in the CD-ROM is an implementation of this class. Following are the methods available in this class: ◆ IntranetUser(): This is the constructor method, which performs the fol- lowing tasks: ■ Sets an object variable named dbi to point to the class.DBI.php- provided object, which is passed to the constructor by an application. The dbi object variable holds the DBI object, which is used to commu- nicate with the backend database. Chapter 7: Intranet System 217 10 549669 ch07.qxd 4/4/03 9:25 AM Page 217 ■ Sets an object variable called user_details_tbl to $USER_DETAILS_TBL, which is loaded from the home.conf file. The $USER_DETAILS_TBL variable holds the name of the users table. ■ Sets an object variable called user_pref_tbl to $USER_PREFERENCE_TBL, which is loaded from the home.conf file. The $USER_PREFERENCE_TBL variable holds the name of the user preference table. ■ If the constructor is called with a user ID ($uid), it is set to $this->uid. ◆ getContactInfo(): This method returns all information regarding a given user ID ($uid) from the USER_DETAILS table. It works as follows: ■ This method is called with the user ID ($uid) parameter. ■ It calls the setIntranetUserID() method to set the current user ID to $uid. ■ It creates an SQL SELECT statement, $statement, to select all informa- tion from the USER_DETAILS table for the given user ID ($uid). ■ The result of the executed select statement is stored in the $this- >contactInfo object. The following table describes the other methods of this class: Method Description setIntranetUserID() Sets the intranet user ID. If the intranet user ID ($uid) is provided as a parameter, it is set as the object’s intranet user ID ( $this->uid), or the current intranet user ID is returned. getName() Returns the first and last name of the current user. It gets this information from the $this->contactInfo object variable, which is a DBI result set object set by the getContactInfo() method. getPreferences() Returns the preferences for a given user in an associative array. updateAutoTip() Updates tool tip status for a given user. addAutoTip() Sets or resets the automatic tip preference. The method is called with the user ID ( $uid) and the tip preference option ($tip). It creates an SQL INSERT statement, $statement, that inserts the tip option for preference ID ( 2), which is the preference number for the automatic tip. It returns true if the tip preference is inserted successfully; otherwise, it returns false. 218 Part II: Developing Intranet Solutions 10 549669 ch07.qxd 4/4/03 9:25 AM Page 218 Setting Up Application Configuration Files Each of the applications in the intranet system uses a central configuration file called home.conf. For the given configuration file, the directory structure is shown here: Here’s the directory structure that the home.conf require: + htdocs ($ROOT_PATH same as %DocumentRoot%) | + home (applications and configuration files go here) | | | + class (class files go here) | | | + templates (html templates go here) | | | + themes (theme templates are stored here) | | | + tips (tips are stored here) | + photos (user photos are stored here) | + login (central login application) | + logout (central logout application) Here the home directory is assumed to be a top-level directory in the %DocumentRoot% of the intranet Web site. The photos directory is also a top-level directory within the site; user photos are optional, however, and can be placed in the directory manually as long as the file names are userid.jpg. A default photo called default_photo.jpg is provided in the photos directory for users without any photo in this directory. The login/logout directories are part of the central authentication discussed earlier in the book. To configure the applications for your directory structure, you have to change the settings as shown in Table 7-2. The messages displayed by the intranet applications are stored in the home.mes- sage file, which you can copy from the ch7/home directory within the CD-ROM. You can customize each message by using a text editor. The error messages displayed by the intranet applications are stored in error messages file called home.errors which can be found in ch7/home directory of the CD-ROM. You can customize each message by using a text editor. Chapter 7: Intranet System 219 10 549669 ch07.qxd 4/4/03 9:25 AM Page 219 TABLE 7-2 HOME.CONF SETTINGS Variable Values $PEAR_DIR Set to the directory where you have installed the PEAR packages. The DB class needs the class.DBI.php, which is part of the PEAR packages. $PHPLIB_DIR Set to the directory where the PHPLIB packages are stored, because the Template class (template.inc) is part of the PHPLIB packages. $APP_FRAMEWORK_DIR Point this to our application framework class directory. $AUTHENTICATION_URL Point the central authentication application (login.php), which is part of our application framework. The default value is /login/login.php, which should work if you have followed instructions in Chapter 5. $LOGOUT_URL Point the central logout application (logout.php), which is part of our application framework. The default value is /logout/logout.php, which should work if you have followed instructions in Chapter 5. $ROOT_PATH Point to the document root directory of your Web site where you host this application. $REL_ROOT_PATH Point to the relative path, which is the parent of the apps directory. $INTRANET _DB_URL Configure this to enable you to connect to the intranet database via the named host using the named username and password. For example, the default value mysql://root:foobar@localhost/INTRANET states that the intranet database called INTRANET is located in the localhost system and can be accessed by using the username root and password foobar. $USER_DB_URL Configure to enable you to connect to the user database. For example, the default value mysql://root:foobar@localhost/auth states that the authentication database called auth is located in the localhost system and can be accessed by using the username root and password foobar. 220 Part II: Developing Intranet Solutions 10 549669 ch07.qxd 4/4/03 9:25 AM Page 220 . class.DBI .php, which is part of the PEAR packages. $PHPLIB_DIR Set to the directory where the PHPLIB packages are stored, because the Template class (template.inc) is part of the PHPLIB packages. $APP_FRAMEWORK_DIR. directory. $AUTHENTICATION_URL Point the central authentication application (login .php) , which is part of our application framework. The default value is /login/login .php, which should work if you have followed instructions. 5. $LOGOUT_URL Point the central logout application (logout .php) , which is part of our application framework. The default value is /logout/logout .php, which should work if you have followed instructions

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

TỪ KHÓA LIÊN QUAN