Metropolitan State University

ICS 325

Building Services on the Internet

 

Lab 18

Use Object-Oriented PHP to Implement an Interface

(Linux Redhat 7.1)

 

 

Log onto redhat.ics.metrostate.edu using your loginid and password given in class.

 

$ cd

$ cd public_html

$ mkdir lab18

$ cd lab18

$ mkdir images

$ cp /tmp/s04325/next.bmp images/

$ cp /tmp/s04325/current.bmp images/

 

1.         Create the Interface Class

§           Edit the following file with the name as “page.php” using pico:

 

<?php

class pageFormat  {

 

// Variables used in this class

 

var $title = "Test Page";

var $keywords = "Keywords";

var $foot = "</h5><font color=green>&copy;Copyright 2004

    <br />Metropolitan State University</font></h5>";

var $buttons;

 

// the following functions set the values to the class variables

 

function set_title($setTitle)  {

  $this->title = $setTitle;

}

function set_keywords($setKeywords)  {

  $this->keywords = $setKeywords;

}

function set_buttons($setButtons) {

  $this->buttons = $setButtons;

}

function display_title() {

  echo "<title>$this->title</title>\n";

}

function set_foot($setFoot) {

  $this->foot = $setFoot;

}

 

 

 

function display_kewords()  {

/**********************************

This function outputs the meta tag

keyword section to the web browser

**********************************/

  echo "<meta name=\"keywords\" content=\"$this->keywords\" />\n";

}

 

function display_navBar($navButtons) {

/**********************************

This function displays the navigation

bar on the web page.  This function

is a modified version of the display_Menu

from the class book.

**********************************/

  $tblSize = sizeof($this->buttons);

  echo "<table border=0>\n<tr>\n";

  for($i=0;$i<$tblSize;$i++)   {

    $this->display_button($this->buttons[$i],

       $this->isURLCurrentPage($this->buttons[$i]));   

  }

  echo "</tr>\n</table>\n";  

}

 

function isURLCurrentPage($url)   {

/**********************************

This function determines if the passed

in url is the same as the current

script.  This function is a modified

version of the IsURLCurrentPage from

the class book.

**********************************/

  if(strpos($GLOBALS["SCRIPT_NAME"],$url) == false){

    return false;

  }

  else{

    return true;

  } 

}

 

function display_button($url,$current)  {

/**********************************

This function displays one of two

buttons on the web page depending on

passed in Boolean value.  This function

is a modified version of the

DisplayButton from the class book.

**********************************/

  echo "<td width=\"28\"><a href=\"$url\"><img src=\"images/";

  if($current)  {

    echo "current.bmp";

  }

  else {

    echo "next.bmp";

  }

  echo "\" border=0 /></a></td>\n";

}

 

 

function display_top()   {

/**********************************

This function displays Top portion

of the web site.  Future improvements

on this function are recommended

**********************************/

  echo "<tr><td colspan=2 align=center>

       <font size=6 color=green face=arial>

       ICS 325 Online Learning - <b>XHTML</b></font></td></tr>";

}

function display_leftMenu() {

/**********************************

This function displays left menu

of the web site.  Future improvements

on this function are recommended

**********************************/

  echo "<table border=0>\n";

  echo "<tr>\n<a href=\"UnderCon.php\">

       <td bgcolor=\"green\" width=\"80\">PHP</td></a>\n</tr>\n";

  echo "<tr>\n<a href=\"UnderCon.php\">

       <td bgcolor=\"green\" width=\"80\">XHTML</td></a>\n</tr>\n";

  echo "<tr>\n<a href=\"UnderCon.php\">

         <td bgcolor=\"green\"width=\"80\">JavaScript</td>

            </a>\n</tr>\n";

  echo "<tr>\n<a href=\"UnderCon.php\">

       <td bgcolor=\"green\" width=\"80\">CSS</td>

          </a>\n</tr>\n";

  echo "<tr>\n<a href=\"UnderCon.php\">

       <td bgcolor=\"green\" width=\"80\">MySQL</td></a>\n</tr>\n";

  echo "<tr>\n<a href=\"UnderCon.php\">

       <td bgcolor=\"green\" width=\"80\">

          Flash MX</td></a>\n</tr>\n";

  echo "</table>";

}

 

function display_header()   {

/**********************************

This function implements the top

section of the web site

**********************************/

  echo "<html>\n<head>\n";

  $this->display_title();

  $this->display_kewords();

  echo "</head>\n<body bgcolor=\"#C7C7C7\">\n

       <table width=\"700\">\n";

  $this->display_top();

  echo "<tr><td width=100 /><td width=600 align=right>"; 

  $this->display_navBar($this->buttons);

  echo "</tr>";

  echo "<tr><td width=100 valign=top>";   

  $this->display_leftMenu();

  echo "</td><td width=600 valign=top>";   

}

 

 

function display_footer()   {

/**********************************

This function implements the bottom

section of the web site

**********************************/

  echo "$this->foot";

  echo "</tr>";

  echo "</table>\n</body>\n</html>\n";

}

}

?>

 

 

 

2.         Create the Header File

§           Edit the following file with the name as “customHead.php” using pico:

 

<?php

 

require("page.php");

  // adding more pages names here will cause the nav bar to grow

  // make sure that any page that you put in below list has the

  // same format.

$arrayOfBtns = array("XHTMLp1.php","XHTMLp2.php","XHTMLp3.php");

$formatPage = new pageFormat();

$formatPage->set_buttons($arrayOfBtns);

$formatPage->display_header();

?>

 

 

 

3.         Create the Footer File

§           Edit the following file with the name as “customFoot.php” using pico:

 

<?php

$footer = "</h5><font color=green>&copy;Copyright 2004 f04325??<br />Metropolitan State University</font></h5>";

$formatPage->set_foot($footer);

$formatPage->display_footer();

 

?>

 

 

 

4.         Create the Under Construction Page

§           Edit the following file with the name as “UnderCon.php” using pico:

 

<?php

require("customHead.php");

?>

 

<h1>This Page is under Construction</h1>

 

<?php

require("customFoot.php");

?>

 

 

 

 

 

5.         Create the Training PHP pages

§           Edit the following files with the naming convention as “XHTMLp1.php”, “XHTMLp2.php”, “XHTMLp3.php” … using pico:

 

 

<?php

// *************************************

 

require("customHead.php");

 

// the above lines should  be in each

// of the training php files.

// *************************************

 

 

// The following lines should be modified

// for each page of the training PHP pages

// Page 1, Page 2, Page 3, ...

 

?>

<h1>Page #1 of XHTML Online Learning</h1>

<p>&nbsp;</p>

<h3>Some Training Text Goes Here</h3>

<p>&nbsp;</p>

<h3>A coding Example Goes Here</h3>

 

<?php

// *************************************

 

require("customFoot.php");

 

// the above lines should  be in each

// of the training php files.

// *************************************

?>

 

§           Invoke the script using the following link,

http://redhat.ics.metrostate.edu/~f04325??/lab18/XHTMLp1.php