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

Secure PHP Building 50 Practical Applications Development phần 5 potx

92 266 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 92
Dung lượng 653,54 KB

Nội dung

■ Sets a member variable named ‘fields’, which is a comma-separated list of calendar event table fields. ■ Calls setEventID() to set the given event ID to this object. ◆ loadEventInfo (): This method sets all the attribute values for a given event as member variables to this class. This is how it works: ■ The given event ID is set to a member variable called to eid using setEventID(). ■ A statement to select all the event table fields for the given event ID is created in $stmt. ■ Using the DBI object $this->dbi, the $stmt statement is run via the $this->dbi->query() method in DBI object. The result of the query is stored in the $result variable. ■ If there are more than zero rows in the $result object, each row is fetched in the $row variable. ■ For each message field of type text, the data is stripped for embedded slash characters. ■ Each message field data is stored as object variable using $this- >$fieldname run-time variable. ◆ getEvents (): This method returns all the events that are to be shown to the given user on a given date. It works as follows: ■ The date string (mm-dd-yyyy format) passed to this method is used to find out these three formats of the given date: the day of the week string, the day of the month string, and the month-day string. These formats are later used to check whether the given date is a weekly, monthly, or yearly repetitive date. ■ A statement to select all the events that are to be viewed by the given user on the given date is prepared. This statement also selects the events viewable by the given user that fall on this day because of the repetitive event feature. The statement is stored in a variable named $stmt. ■ Using the DBI object ($this->dbi), the $stmt statement is run via the $this->dbi->query() method in the DBI object. The result of the query is stored in the $result variable. ■ If there are more than zero rows in the $result object, each row is fetched in the $row variable. ■ An associative array is prepared using each row’s event ID and Event Title. ■ The method returns the array. If the result set is found to be empty, the method returns null. Chapter 10: Intranet Calendar Manager 339 13 549669 ch10.qxd 4/4/03 9:25 AM Page 339 ◆ getOwnEvents (): This method returns the events that are created by the given user for a given day. This is how it works: ■ The date string parameter is formatted using addslashes and the quote() method of the DBI object. ■ A statement to select all the events that are created by this user for the given date is prepared and stored in $stmt. ■ Using the DBI object $this->dbi, the $stmt statement is run via the $this->dbi->query() method in the DBI object. The result of the query is stored in the $result variable. ■ If there are more than zero rows in the $result object, each row is fetched in the $row variable. ■ An associative array is prepared using each row’s event ID and event title. ■ The method returns the array. If the result set is empty, the method returns null. ◆ getViewers (): This method returns all viewer IDs for a given event. This is how it works: ■ It sets the event ID using setEventID(). ■ A statement to select all the viewer IDs (user ID) of the event viewer table for the given event ID is prepared and stored in $stmt. ■ Using the DBI object ($this->dbi), the $stmt statement is run via the $this->dbi->query() method in the DBI object. The result of the query is stored in the $result variable. ■ If there are more than zero rows in the $result object, each row is fetched in the $row variable. ■ An associative array is prepared using each row’s event ID and event title. ■ The method returns the array. In case the result set found is empty, the method returns null. ◆ addEvent (): This method adds a new event into to the CALENDAR_EVENT table. Attributes such as user ID, event title, event date, event description, reminder ID, and flag are passed as an associative array to this method. It works as follows: ■ From the given parameter, all the values of text type in the database are escaped for characters such as quotation marks and slashes using $this->dbi->quote(addslashes()). 340 Part II: Developing Intranet Solutions 13 549669 ch10.qxd 4/4/03 9:25 AM Page 340 ■ A variable called $values is assigned a comma-separated list of all the parameter values. ■ A SQL statement, $stmt, is created to insert the new event data into the event table using the member variable ‘fields’ (contains attribute names) and $values. ■ The SQL statement is executed using $this->dbi->query(), and the result of the query is stored in the $result object. ■ If the $result status is not okay, the method returns FALSE to indicate an insert failure. Otherwise, it returns the newly created event’s ID by executing a second query. ◆ modifyEvent (): This method updates modified event information to the database. Attributes such as event ID, user ID, event title, event date, event description, reminder ID, and flag are passed as an associative array to this method. This is how it works: ■ From the given parameter, all the values that of text type in the data- base are escaped for characters such as quotation marks and slashes using $this->dbi->quote(addslashes()). ■ A SQL statement, $stmt, is created to update the event table using the parameter attributes and values. ■ The SQL statement is executed using $this->dbi->query(), and the result of the query is stored in the $result object. ■ If the $result status is not okay, the method returns FALSE to indicate an insert failure. Otherwise, it returns the newly created event’s ID by executing a second query. ◆ addViewer (): This method adds a viewer to a given event. This is how it works: ■ It takes the event ID and an array containing the viewer IDs (users ID) as a parameter. ■ setEventID()is called to set the given event ID. ■ It checks whether there is an entry of zero in the given array. If there is, it means that the event is viewable by all, and only a zero is added to the viewer table with the given event ID. ■ When the array has all the entries greater than zero, each of the array entries is added to the event viewer table with the given event ID. Chapter 10: Intranet Calendar Manager 341 13 549669 ch10.qxd 4/4/03 9:25 AM Page 341 ◆ getRepeatMode (): This method returns the repeat mode for a given event. This is how it works: ■ The given event ID is set using setEventID(). ■ A statement is prepared to select the repeat mode for a given event from the repetitive event table. The statement is stored in a variable named $stmt. ■ Using the DBI object $this->dbi, the $stmt statement is run via the $this->dbi->query() method in the DBI object, and the result is stored in the $result variable. ■ If the result set is not empty, the row is fetched using the fetchRow() method of the DBI object, and REPEAT_MODE is returned from there. Otherwise, it returns null. Here are the other methods of this class: Method Description setEventID() Sets the event ID (eid) of the event object. It takes the event ID from the user and, after setting it to member variable ‘eid’, returns the same. This setting is not done when the method is called without an event ID. In that case, the previously set event ID is returned. getEventTitle() Returns the title of the given event from the CALENDAR_EVENT table. It uses loadEventInfo() to set all the attribute members for the event, and returns the title of the event by getting the value from $this->EVENT_TITLE. This method takes the event ID as a parameter. getEventDate() Returns the date of the given event from the CALENDAR_EVENT table. It uses loadEventInfo() to set all the attribute members for the event, and returns the date of the event by getting the value from $this->EVENT_DATE. This method takes the event ID as a parameter. 342 Part II: Developing Intranet Solutions 13 549669 ch10.qxd 4/4/03 9:25 AM Page 342 Method Description getEventDesc() Returns the description of the given event from the CALENDAR_EVENT table. It uses loadEventInfo() to set all the attribute members for the event, and returns the title of the event by getting the value from $this->EVENT_DESC. This method takes the event ID as a parameter. getEventReminder() Returns the reminder (MOTD) ID of the given event from the CALENDAR_EVENT table. It uses loadEventInfo() to set all the attribute members for the event, and returns the title of the event by getting the value from $this->REMINDER_ID. This method takes the event ID as a parameter. deleteEvent() Deletes the event from the CALENDAR_EVENT table. It takes the event ID as a parameter and returns TRUE or FALSE, depending on the status of the deletion operation. deleteViewers() Deletes all viewers for a given event. It takes the event ID as a parameter and returns TRUE or FALSE, depending on the status of the deletion operation. addRepeatMode() Adds repeat mode for a given event into the CALENDAR_REPETITIVE_EVENTS table. It takes the event ID and the event mode as parameters and returns TRUE or FALSE depending on the status of the insertion operation. deleteRepeatMode() Deletes all repeat modes for a given event. It takes the event ID as a parameter and returns TRUE or FALSE on the success or failure of the deletion operation. The Application Configuration Files Like all other applications we’ve developed in this book, the intranet calendar man- ager applications also use a standard set of configuration, message, and error files. These files are discussed in the following sections. Chapter 10: Intranet Calendar Manager 343 13 549669 ch10.qxd 4/4/03 9:25 AM Page 343 The main configuration file The primary configuration file for the entire intranet calendar manager is called calendar.conf. Table 10-2 discusses each configuration variable. TABLE 10-2 CALENDAR.CONF VARIABLES Configuration Variable Purpose $PEAR_DIR Set to the directory containing the PEAR package; specifically the DB module needed for class.DBI.php in our application framework. $PHPLIB_DIR Set to the PHPLIB directory, which contains the PHPLIB packages; specifically the template.inc package needed for template manipulation. $APP_FRAMEWORK_DIR Set to our application framework directory. $PATH Set to the combined directory path consisting of the $PEAR_DIR, $PHPLIB_DIR, and the $APP_FRAMEWORK_DIR. This path is used with ini_set() to redefine the php.ini entry for include_path to include $PATH ahead of the default path. This allows PHP to find our application framework, PHPLIB, and PEAR-related files. $AUTHENTICATION_URL Set to the central login application URL. $LOGOUT_URL Set to the central logout application URL. $HOME_URL Set to the topmost URL of the site. If the URL redirection application does not find a valid URL in the e-campaign database to redirect to for a valid request, it uses this URL as a default. $APPLICATION_NAME Internal name of the application. $DEFAULT_LANGUAGE Set to the default two-digit language code. $ROOT_PATH Set to the root path of the application. $REL_ROOT_PATH Relative path to the root directory. $REL_APP_PATH Relative application path as seen from the web browser. $TEMPLATE_DIR The fully qualified path to the template directory. 344 Part II: Developing Intranet Solutions 13 549669 ch10.qxd 4/4/03 9:25 AM Page 344 Configuration Variable Purpose $THEME_TEMPLATE_DIR The fully qualified path to the theme template directory. $REL_PHOTO_DIR The Web-relative path to the photo directory used to store user photos. $PHOTO_DIR The fully qualified path to the photo directory. $DEFAULT_PHOTO Name of the default photo file, which is used when a user does not have a photo in the photo directory. $CLASS_DIR The fully qualified path to the class directory. $REL_TEMPLATE_DIR The Web-relative path to the template directory used. $EVENT_CLASS Name of the Event class file. $MESSAGE_CLASS Name of the Message class file. This class is developed for the MOTD application discussed in Chapter 9. $CALENDAR_DB_URL The fully qualified URL for the database used to store the calendar events. $CALENDAR_EVENT_TBL Name of the calendar event table in the database. $CALENDAR_EVENT_VIEW_TBL Name of the event viewer table in the database. $CALENDAR_EVENT_REPEAT_TBL Name of the event repeat table in the database. $USER_PREFERENCE_TBL Name of the user preference table in the database. $MESSAGE_TBL Name of the MOTD message table in the intranet database. $MSG_VIEWER_TBL Name of the message viewer list table in the intranet database. $AUTH_DB_TBL Name of the user authentication table in the auth database. $STATUS_TEMPLATE Name of the status template file used to display status messages. $CALENDAR_HOME_TEMPLATE Name of the calendar index template file. $CALENDAR_EVENT_TEMPLATE Name of the calendar event details template file. Continued Chapter 10: Intranet Calendar Manager 345 13 549669 ch10.qxd 4/4/03 9:25 AM Page 345 TABLE 10-2 CALENDAR.CONF VARIABLES (Continued) Configuration Variable Purpose TODAY_COLOR Color defined for current day when displaying calendar. WEEKEND_COLOR Color defined for weekends when displaying calendar. HOLIDAY_COLOR Color defined for holidays when displaying calendar. GLOBAL_EVENT_COLOR Color defined for global events when displaying calendar. PERSONAL_EVENT_COLOR Color defined for personal events when displaying calendar. SECONDS_PER_DAY Defines amount of seconds per day. USER_DB_URL The fully qualified authentication database URL. $DEFAULT_THEME The default theme index in the $THEME_TEMPLATE array. $USER_DEFAULTS A user’s theme and auto tip default settings. $TIP_SCRIPT The name of the tip script. $TIP_URL The Web-relative path for the tip files. $MAX_AVAILABLE_TIP The maximum number of tips from which to display the tip. $THEME_TEMPLATE[x] The list of theme templates. $PRINT_TEMPLATE[x] The list of print templates associated with the theme templates. The directory structure used in the calendar.conf file supplied in ch10 direc- tory on the CD-ROM might need to be tailored to your own system’s requirements. Here’s how the current directory structure looks: htdocs ($ROOT_PATH same as %DocumentRoot%) | + home (base intranet application discussed in chapter 7) | | | + templates | | 346 Part II: Developing Intranet Solutions 13 549669 ch10.qxd 4/4/03 9:25 AM Page 346 | + themes (theme templates used by all intranet apps) | + photos (user photos used by all intranet apps) | + calendar_mngr (Intranet Calendar Applications) | + apps (calendar apps and configuration files) | + class (calendar classes) | + templates (publisher HTML templates) | + themes (symlink to %DocumentRoot%/home/templates/themes) By changing the following configuration parameters in calendar.conf, you can modify the directory structure to fit your site requirements: $APP_FRAMEWORK_DIR=$_SERVER[‘DOCUMENT_ROOT’] . ‘/framework’; $PEAR =$_SERVER[‘DOCUMENT_ROOT’] . ‘/pear’; $PHPLIB =$_SERVER[‘DOCUMENT_ROOT’] . ‘/phplib’; $ROOT_PATH = $_SERVER[‘DOCUMENT_ROOT’]; $REL_ROOT_PATH = ‘/calendar_mngr’; $REL_APP_PATH = $REL_ROOT_PATH . ‘/apps’; $REL_PHOTO_DIR = ‘/photos’; $PHOTO_DIR = $ROOT_PATH . $REL_PHOTO_DIR; $TEMPLATE_DIR = $ROOT_PATH . $REL_APP_PATH . ‘/templates’; $THEME_TEMPLATE_DIR = $TEMPLATE_DIR . ‘/themes’; $CLASS_DIR = $ROOT_PATH . $REL_APP_PATH . ‘/class’; $REL_TEMPLATE_DIR = $REL_APP_PATH . ‘/templates/’; The messages file The messages displayed by the calendar manager applications are stored in the ch10/apps/calendar.messages file in the CDROM. You can change the messages using a text editor. The errors file The error messages displayed by the calendar manager applications are stored in the ch10/apps/calendar.errors file in the CDROM. You can modify the error messages using a text editor. Chapter 10: Intranet Calendar Manager 347 13 549669 ch10.qxd 4/4/03 9:25 AM Page 347 The Application Templates The HTML interface templates needed for the applications are included in the ch10/apps/templates directory in the CD-ROM. These templates contain various template tags to display necessary information dynamically. The templates are named in the calendar.conf file. These templates are listed in Table 10-3. TABLE 10-3 HTML TEMPLATES Configuration Variable Template File Purpose $STATUS_TEMPLATE calendar_status.html Used to show status message. $CALENDAR_HOME_TEMPLATE calendar_home.html The calendar index template. $CALENDAR_EVENT_TEMPLATE calendar_events.html The calendar event–related template. The Calendar Manager Application This calendar manager application is responsible for displaying an intranet calen- dar page to each user. The application, calendar_mngr.php, is included on the CD-ROM in the ch10/apps directory. It implements the following functionality: ◆ When the user logs in, he is shown a calendar of the current month. ◆ Dates of the month are highlighted and colored according to events scheduled for those days. ◆ The user can use the navigator buttons to browse forward and backward through different months. This application has the following methods: ◆ run(): This method is responsible for running this application. This is how it works: ■ It creates an object of the Theme class called $themeObj and sets it as a member variable. 348 Part II: Developing Intranet Solutions 13 549669 ch10.qxd 4/4/03 9:25 AM Page 348 [...]... the central messaging mechanism that you developed earlier Figure 10-6 shows an event reminder 13 54 9669 ch10.qxd 4/4/03 9: 25 AM Page 357 Chapter 10: Intranet Calendar Manager Figure 10 -5: Modifying an event Figure 10-6: Viewing an event reminder at login 357 13 54 9669 ch10.qxd 358 4/4/03 9: 25 AM Page 358 Part II: Developing Intranet Solutions Summary In this chapter, you saw how to create a central... http://yourserver/index .php or http://yourserver/ home/home .php using the user name and password you created in Chapter 6 and tested in Chapter 7 13 54 9669 ch10.qxd 4/4/03 9: 25 AM Page 355 Chapter 10: Intranet Calendar Manager Click on the Calendar link in the left navigation bar of your intranet home page or point your web browser to http://yourserver/calendar_mngr/apps/ calendar_mngr .php This shows you... the parameter to this method ■ After the passed content is set into the contentBlock, it is rendered to the user 349 13 54 9669 ch10.qxd 350 4/4/03 9: 25 AM Page 350 Part II: Developing Intranet Solutions The Calendar Event Manager Application This application, calendar_event_mngr .php, is responsible for managing calendar events This application is included on the CD-ROM in the ch10/apps directory The... event on July 7, 2003, move forward to July 2003 using the Next button and click on the day (7) After you’ve clicked on a date, a screen similar to the one in Figure 10-4 displays 355 13 54 9669 ch10.qxd 356 4/4/03 9: 25 AM Page 356 Part II: Developing Intranet Solutions Figure 10-4: Adding an event To add a reminder, add an event title, description, frequency (weekly, monthly, yearly, default is once only),... implement the Internet Resource Manager PHP Application Framework IRM Applications User Home Interface Central Login/Logout Message Object class.Message .php IrmCategory Object class.IrmCategory .php IrmContact Object class.IrmContact .php Messages IRM Figure 11-2: A system diagram for the IRM Here you will develop three classes that will provide these objects for your resource applications Designing and implementing... system 359 14 54 9669 ch11.qxd 360 4/4/03 9: 25 AM Page 360 Part II: Developing Intranet Solutions Understanding the Prerequisites This Internet Resource Manager builds on the Intranet classes discussed in Chapters 4 through 7 It uses the message class to announce event reminders The intranet calendar applications that we will develop here require the central login/logout, user management, and home applications. .. event ID If it finds a message, the message is modified using the modifyMessage() method of the Message class Otherwise, the new message is added using addMessage() and addViewer() 351 13 54 9669 ch10.qxd 352 4/4/03 9: 25 AM Page 352 Part II: Developing Intranet Solutions ■ If the event’s reminder option is turned off, all the messages and message viewers related to the event are deleted using deleteMessage()... specifically the DB module needed for class.DBI .php in our application framework $PHPLIB_DIR Set to the PHPLIB directory, which contains the PHPLIB packages; specifically the template.inc package needed for template manipulation $APP_FRAMEWORK_DIR Set to our application framework directory $PATH Set to the combined directory path consisting of the $PEAR_DIR, $PHPLIB_DIR, and $APP_FRAMEWORK_DIR This path... (root) to whatever is appropriate for your system After you have the Resource Manager database designed, you need to design the PHP classes that will be needed to implement the applications In the following sections, I discuss these classes 361 14 54 9669 ch11.qxd 362 4/4/03 9: 25 AM Page 362 Part II: Developing Intranet Solutions Designing and Implementing the Internet Resource Manager Application Classes... to this directory as %DocumentRoot% ◆ You’ve installed the PHPLIB and PEAR library Normally, these get installed during PHP installation For your convenience, I’ve provided these in the lib/phplib.tar.gz and lib/pear.tar.gz directories on the CD-ROM In the example installation steps, I assume that these are installed in the /%DocumentRoot%/phplib and / %DocumentRoot%/pear directories Because your installation . (CALENDAR_EVENT_TEMPLATE) is loaded in a template object called $template. 350 Part II: Developing Intranet Solutions 13 54 9669 ch10.qxd 4/4/03 9: 25 AM Page 350 ■ The template file includes a Web form that takes the. to the one in Figure 10-4 displays. Chapter 10: Intranet Calendar Manager 355 13 54 9669 ch10.qxd 4/4/03 9: 25 AM Page 355 Figure 10-4: Adding an event. To add a reminder, add an event title, description,. developed earlier. Figure 10-6 shows an event reminder. 356 Part II: Developing Intranet Solutions 13 54 9669 ch10.qxd 4/4/03 9: 25 AM Page 356 Figure 10 -5: Modifying an event. Figure 10-6: Viewing an event

Ngày đăng: 13/08/2014, 12:21

TỪ KHÓA LIÊN QUAN