◆ 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.. I
Trang 1associative 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 = valueparameters
■ 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 $officeto be zero Extra hours are initialized to a method variable called $extrato be zero
■ A global parameter $WEEKENDis 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 $starttimestamp is in the $WEEKENDarray If so, it sets the $officevariable to zero, because only extra (overtime) hours are allowed on weekends It calculates the
$extratime by subtracting the $startfrom $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 $retArrwith 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
Trang 2The 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:
ActivityAnalyzer() The constructor method It sets an object variable named
dbito 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_tblto
$ACTIVITY_TBL, which is loaded from the configuration file (home.conf) The $ACTIVITY_TBLvariable 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 InternetUserclass provides the intranet user object, which is used to retrieve and set user information The ch07/home/class/class.IntranetUser.phpfile 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 dbito point to the class.DBI.php -provided object, which is passed to the constructor by an application
The dbiobject variable holds the DBIobject, which is used to commu-nicate with the backend database
Trang 3■ Sets an object variable called user_details_tblto
$USER_DETAILS_TBL, which is loaded from the home.conffile The
$USER_DETAILS_TBLvariable 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.conffile 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_DETAILStable 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 SELECTstatement, $statement, to select all informa-tion from the USER_DETAILStable for the given user ID ($uid)
■ The result of the executed select statement is stored in the
$this->contactInfoobject
The following table describes the other methods of this class:
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->contactInfoobject variable, which is a DBIresult 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 INSERTstatement, $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
Trang 4Setting 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 photosdirectory 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.errorswhich can be found in ch7/homedirectory of the CD-ROM You can customize each message by using a text editor
Trang 5T ABLE 7-2 HOME.CONF SETTINGS
$PEAR_DIR Set to the directory where you have installed the PEAR
packages The DBclass needs the class.DBI.php, which is part of the PEARpackages
$PHPLIB_DIR Set to the directory where the PHPLIBpackages are stored,
because the Templateclass (template.inc) is part of the
PHPLIBpackages
$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 rootdirectory 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 INTRANETis located
in the localhostsystem and can be accessed by using the username rootand 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 authis located in the localhostsystem and can be accessed by using the username rootand password foobar