■ Uses the logUserIn() method of the $analyzer object to log in the user. ■ Calls the reportDriver() method to render the updated access report. ◆ authorize(): This method authorizes access to this application. It works as follows: ■ It checks the current user ID using the getUID() method. Because all valid user IDs are positive numbers, it creates the DBI object called $user_dbi that points to the central user-authentication database (USER_DB_URL). ■ A user object called $userObj is created using the $user_dbi and the current user ID. ■ The getType() method is called to determine the user type of the cur- rent user. If the current user is of type administrator (ADMIN_TYPE), the $isAdmin variable is set to TRUE. ■ This method always returns TRUE, because everyone on the intranet can view this application. ◆ reportDriver(): This method generates and displays the user-access report. It works as follows: ■ Generates the appropriate report. For example, if the report type ($rpt) is a weekly report, the generateWeeklyReport() method is called to generate the weekly report. ■ Displays the report using the displayReport(). ◆ generateDailyReport(): This method generates the access report of a user for a specific day. This method works as follows: ■ If the user viewing the page has administrator privileges, this method shows her the admin block that includes a list of users from which she can select any user’s daily report. This block also includes a link to the overall summary report and the buttons for force login and force logout. ■ It finds out the timestamp of the day to be shown. Because the user has the option to scroll through the days by using the >> and << buttons, this timestamp is not always the current day. ■ It finds out the starting and ending timestamps of the given day and uses the ActivityAnalyzer object to retrieve the office hours and the extra hours for the day for that user. ■ It returns the formatted information that includes the date, the day, the start time, the end time, the total office hours, and the total extra hours. It also includes a brief summary with totals and averages. Chapter 7: Intranet System 231 10 549669 ch07.qxd 4/4/03 9:25 AM Page 231 ◆ generateWeeklyReport(): This method generates an access report of a user for a specific week. This method works as follows: ■ If the user viewing the page has administrator privileges, this method shows her the admin block that includes a list of users from which she can select any user’s daily report. The block includes a link to the over- all summary report and the buttons for force login and force logout. ■ It finds out the timestamp of the week to be shown. Because the user has the option to scroll through the weeks by using the >> and << but- tons, this timestamp is not always the current week. ■ It finds out the starting and ending timestamps of the given week and uses the ActivityAnalyzer object to retrieve the office hours and the extra hours for each day of the given week for that user. ■ It returns the formatted information that includes the date, the day, the start time, the end time, the total office hours, and the total extra hours, as well as a brief summary with totals and averages. ◆ generateMonthlyReport(): This method generates an access report of a user for a specific month. This method works as follows: ■ If the user viewing the page has administrator privileges, this method shows him the admin block that includes a list of users from which he can select any user’s monthly report. This includes a link to the overall summary report and the buttons for force login and force logout. ■ It finds out the timestamp of the month to be shown. As the user has the option to scroll through the months by using the >> and << but- tons, this timestamp is not always the current month. ■ It finds out the starting and ending timestamps of the given month and uses the ActivityAnalyzer object to retrieve the office hours and the extra hours for each day of the given month for that user. ■ It returns the formatted information that includes the date, the day, the start time, the end time, the total office hours, and the total extra hours and includes a brief summary with totals and averages. ◆ displayReport(): This method displays user-access reports. It works as follows: ■ It uses the Theme class to find out the preferred theme for this user. ■ It creates a new ThemeTemplate object called $themetemplate and loads the preferred theme template. ■ The content block of the $themeTemplate is loaded with $report, which is passed to this method as a parameter. ■ It renders the contents of $themeTemplate to the user. 232 Part II: Developing Intranet Solutions 10 549669 ch07.qxd 4/4/03 9:25 AM Page 232 Other methods for this application include those in the following table: Method Description convert() Converts time stamp values as taken from the seconds as input into hours, minutes, and remaining seconds and returns the resultant string. getWeeklyTSRange() Returns the weekly time stamp range for a given day, in an array containing the starting and ending time stamps of the week with any time stamp as input. getMonthlyTSRange() Returns the monthly time stamp range for a given day, in an array containing the starting and ending time stamps of the month with any time stamp as input. now() Returns the time stamp corresponding to the current date and time. Admin access reporter application The admin access reporter application, admin_access_reporter.php, shows the overall access report of all the employees/users that can be viewed only by the administrators. It is included on the CD-ROM in the ch07/apps directory. This application has the following methods. ◆ run(): When the application is run, this method is called. It checks whether the user has administrative privileges. If the user does not have administrative privileges, it exits from the application. If the user has administrative privileges, it calls the reportDriver() method. ◆ authorize(): This method authorizes only administrators to view the application. If the user has administrative privileges, it returns TRUE. Otherwise, it returns FALSE. It uses the $userObj object of User class to get the current user type; sets the isAdmin property of the application, depending on the type it finds; and returns the isAdmin property, which identifies whether the user is an administrator. ◆ generateDailyReport(): This method generates an access report of all users for a specific day. This method works as follows: ■ It finds out the timestamp of the day to be shown. Because the user has the option to scroll through the days by using the >> and << buttons, this timestamp is not always the current day. Chapter 7: Intranet System 233 10 549669 ch07.qxd 4/4/03 9:25 AM Page 233 ■ It finds out the starting and ending timestamps of the given day and then uses the ActivityAnalyzer object to retrieve the office hours and the extra hours for the day for all users. ■ It returns the formatted information that includes the user name, total office hours, and total extra hours of all users for that day, as well as a brief summary with totals and averages. ◆ generateWeeklyReport(): This method generates an access report of a user for a specific week. This method works as follows: ■ It finds out the timestamp of the week to be shown. Because the user has the option to scroll through the weeks by using the >> and << but- tons, this timestamp is not always the current week. ■ It finds out the starting and ending timestamps of the given week and uses the ActivityAnalyzer object to retrieve the office hours and the extra hours for each day of the given week for all users. ■ It returns the formatted information that includes the username, total office hours, and total extra hours of all users for that week, as well as a brief summary with totals and averages. ◆ generateMonthlyReport(): This method generates an access report of a user for a specific month. This method works as follows: ■ It finds out the timestamp of the month to be shown. Because the user has the option to scroll through the months by using the >> and << buttons, this timestamp is not always the current month. ■ It finds out the starting and ending timestamps of the given month and uses the ActivityAnalyzer object to retrieve the office hours and the extra hours for each day of the given month for all users. ■ It returns the formatted information that includes the username, total office hours, and total extra hours of all users for that month and a brief summary with totals and averages. ◆ displayReport(): This method is used to display user-access reports. It works as follows: ■ It uses the Theme class to find out the preferred theme for this user. ■ It creates a new ThemeTemplate object called $themeTemplate and loads the preferred theme template. ■ The content block of the $themeTemplate is loaded with $report, which is passed to this method as a parameter. ■ The contents of the $themeTemplate are rendered to the user. 234 Part II: Developing Intranet Solutions 10 549669 ch07.qxd 4/4/03 9:25 AM Page 234 The following tables describes the other methods for this application: Method Description reportDriver() Generates the appropriate report based on the type of report requested. (For example, if report type ( $rpt) is weekly report ( WEEKLY = 2), generateWeeklyReport() is called to generate the report.) It then calls displayReport() to display the report. convert() Converts timestamp values as taken from the seconds as input into hour, minute, and remaining seconds and returns the resultant string. getWeeklyTSRange() Returns the weekly timestamp range for a given day. This method returns an array containing the starting and ending timestamps of the week with any timestamp as input. getMonthlyTSRange() Returns the monthly timestamp range for a given day. This method returns an array containing the starting and ending timestamps of the month with any timestamp as input. now() Returns the timestamp corresponding to the current date and time. toggleSortCriteria() Toggles the sort criteria from ascending to descending and vice-versa. It takes the string ‘reverse’ or null as input and returns the other one of the two as output in an exclusive manner. sortByExtra() Sorts the report by extra hours of the users in descending order. It takes two arrays as parameters and returns 1 if the first one’s extra hour value is less than the other one’s; otherwise, it returns –1. sortByOffice() Sorts the report by office hours of the users in descending order. It takes two arrays as parameters and returns 1 if the first one’s office hour value is less than the other one’s; otherwise, it returns –1. reversesortByExtra() Sorts the extra hours of the users in ascending order. It takes two arrays as parameters and returns –1 if the first one’s extra hour value is less than the other one’s; otherwise, it returns 1. reversesortByOffice() Sorts the office hours of the users in ascending order. It takes two arrays as parameters and returns –1 if the first one’s office hour value is less than the other one’s; otherwise, it returns 1. Chapter 7: Intranet System 235 10 549669 ch07.qxd 4/4/03 9:25 AM Page 235 . time. Admin access reporter application The admin access reporter application, admin_access_reporter .php, shows the overall access report of all the employees/users that can be viewed only by the administrators.