By Jack Herrington
Book Price: $29.95 USD
£20.99 GBP
PDF Price: $23.99
Cover | Table of Contents | Colophon
http://www.php.net/) and downloading either the source code or the binaries, along with documentation.C:\> php -v PHP 5.0.4 (cli) (built: Mar 31 2005 02:45:00) Copyright © 1997-2004 The PHP Group Zend Engine v2.0.4-dev, Copyright (c) 1998-2004 Zend Technologies
php executable is not found, you need to add c:\php5\bin to your path. Use the Advanced tab of the system control panel, and click on the Environment Variables button. From there, edit the Path variable, adding c:\php5\bin to whatever path you already have in place.http://www.php.net/) and downloading either the source code or the binaries, along with documentation.C:\> php -v PHP 5.0.4 (cli) (built: Mar 31 2005 02:45:00) Copyright © 1997-2004 The PHP Group Zend Engine v2.0.4-dev, Copyright (c) 1998-2004 Zend Technologies
php executable is not found, you need to add c:\php5\bin to your path. Use the Advanced tab of the system control panel, and click on the Environment Variables button. From there, edit the Path variable, adding c:\php5\bin to whatever path you already have in place.extension_dir line to read as follows:extension_dir = "c:\php5\ext"
http://pear.php.net/). There you can find the list of modules or search by module name. When you find a module you want to install, simply run the pear program on your command line.
C:\> pear install DB
downloading DB-1.7.6.tgz …
Starting to download DB-1.7.6.tgz (124,807 bytes)
............................done: 124,807 bytes
install ok: DB 1.7.6
pear program is just as easy:
% sudo pear install HTTP_Client
downloading HTTP_Client-1.0.0.tgz …
Starting to download HTTP_Client-1.0.0.tgz (6,396 bytes)
.....done: 6,396 bytes
install ok: HTTP_Client 1.0.0
%
HTTP_Client PEAR module
[Hack #84]
. You'll have to use the sudo command because the PEAR module will be installed system-wide.
<html>
<head>
<?php
$style = "default";
if ( $_GET["style"] )
$style = $_GET["style"];
$files = array();
$dh = opendir( "styles" );
while( $file = @readdir( $dh ) )
{
if( preg_match( "/[.]css$/", $file ) )
{
$file = preg_replace( "/[.]css$/", "", $file );
$files []= $file;
}
}
?>
<style type="text/css" media="all">@import url(styles/<?php echo($style); ?>.
css);</style>
</head>
<body>
<table width="800">
<tr>
<td width="200" class="menu" valign="top">
<div class="menu-active"><a href="home.php">Home</a></div>
<div class="menu-inactive"><a href="faq.php">FAQ</a></div>
<div class="menu-inactive"><a href="contact.php">Contact</a></div>
</td>
<td width="600" valign="top">
<table class="box">
<tr>
<td class="box-title">
Important information
</td>
</tr>
<tr>
<td class="box-content">
Lots of information about important events and
stuff.
</td>
</tr>
</table>
</td>
</tr>
</table>
<form>
Style: <select name="style">
<?php foreach( $files as $file ) { ?>
<option value="<?php echo($file); ?>"
<?php echo( $file == $style ? "selected" : "" ); ?>
><?php echo($file); ?></option>
<?php } ?>
</select>
<input type="submit" value="Select" />
</form>
</body>
</html>
<html>
<head>
<?php
$style = "default";
if ( $_GET["style"] )
$style = $_GET["style"];
$files = array();
$dh = opendir( "styles" );
while( $file = @readdir( $dh ) )
{
if( preg_match( "/[.]css$/", $file ) )
{
$file = preg_replace( "/[.]css$/", "", $file );
$files []= $file;
}
}
?>
<style type="text/css" media="all">@import url(styles/<?php echo($style); ?>.
css);</style>
</head>
<body>
<table width="800">
<tr>
<td width="200" class="menu" valign="top">
<div class="menu-active"><a href="home.php">Home</a></div>
<div class="menu-inactive"><a href="faq.php">FAQ</a></div>
<div class="menu-inactive"><a href="contact.php">Contact</a></div>
</td>
<td width="600" valign="top">
<table class="box">
<tr>
<td class="box-title">
Important information
</td>
</tr>
<tr>
<td class="box-content">
Lots of information about important events and
stuff.
</td>
</tr>
</table>
</td>
</tr>
</table>
<form>
Style: <select name="style">
<?php foreach( $files as $file ) { ?>
<option value="<?php echo($file); ?>"
<?php echo( $file == $style ? "selected" : "" ); ?>
><?php echo($file); ?></option>
<?php } ?>
</select>
<input type="submit" value="Select" />
</form>
</body>
</html>
<?php $id = $_GET['id']; if ( strlen( $id ) < 1 ) $id = "home"; $pages = array( home => array( id=>"home", parent=>"", title=>"Home", url=>"showpage.php?id=home" ), users => array( id=>"users", parent=>"home", title=>"Users", url=>"showpage.php?id=users" ), jack => array( id=>"jack", parent=>"users", title=>"Jack", url=>"showpage.php?id=jack" ) ); function breadcrumbs( $id, $pages ) { $bcl = array(); $pageid = $id; while( strlen( $pageid ) > 0 ) { $bcl[] = $pageid; $pageid = $pages[ $pageid ]['parent']; } for( $i = count( $bcl ) - 1; $i >= 0; $i-- ) { $page = $pages[$bcl[$i]]; if ( $i > 0 ) { echo( "<a href=\"" ); echo( $page['url'] ); echo( "\">" ); } echo( $page['title'] ); if ( $i > 0 ) { echo( "</a> | " ); } } } ?> <html> <head> <title>Page - <?php echo( $id ); ?></title> </head> <body> Breadcrumbs: <?php breadcrumbs( $id, $pages ); ?><br/> Page name: <?php echo( $id ); ?> </body> </html>
<html> <head> <? include( "box1.php" ); add_box_styles(); ?> </head> <body> <div style="width:200px;"> <? start_box( "News" ); ?> Today's news is that there is no news. Which is probably a good thing since the news can be fairly distressing at times.<br/><br/> <a href="morenews.html">more…</a> <? end_box(); ?> </div> </body> </html>
<?
function add_box_styles() { ?>
<style type="text/css">
.box {
font-family: arial, verdana, sans-serif;
font-size: x-small;
background: #ccc;
}
.box-title {
font-size: small;
font-weight: bold;
color: white;
background: #777;
padding: 5px;
text-align: center;
}
.box-content {
background: white;
padding: 5px;
}
</style>
<? }
function start_box( $name ) { ?>
<table class="box" cellspacing="2" cellpadding="0">
<tr><td class="box-title"><? print( $name ) ?></td></tr>
<tr><td class="box-content">
<? }
function end_box() { ?>
</td></tr></table>
<? } ?>
<?php
require_once("tabs.php");
?>
<html>
<head>
<?php tabs_header(); ?>
</head>
<body>
<div style="width:600px;">
<?php tabs_start(); ?>
<?php tab( "Tab one" ); ?>
This is the first tab.
<?php tab( "Tab two" ); ?>
This is the second tab.
<?php tabs_end(); ?>
</div>
</body>
</html>
<?php
$tabs = array();
function tabs_header()
{
?>
<style type="text/css">
.tab {
border-bottom: 1px solid black;
text-align: center;
font-family: arial, verdana;
}
.tab-active {
border-left: 1px solid black;
border-top: 1px solid black;
border-right: 1px solid black;
text-align: center;
font-family: arial, verdana;
font-weight: bold;
}
.tab-content {
padding: 5px;
border-left: 1px solid black;
border-right: 1px solid black;
border-bottom: 1px solid black;
}
</style>
<?php
}
function tabs_start()
{
ob_start();
}
function endtab()
{
global $tabs;
$text = ob_get_clean();
$tabs[ count( $tabs ) - 1 ][ 'text' ] = $text;
ob_start();
}
function tab( $title )
{
global $tabs;
if ( count( $tabs ) > 0 )
endtab();
$tabs []= array(
title => $title,
text => ""
);
}
function tabs_end()
{
global $tabs;
endtab();
ob_end_clean();
$index = 0;
if ( $_GET['tabindex'] )
$index = $_GET['tabindex'];
?>
<table width="100%" cellspacing="0" cellpadding="0">
<tr>
<?php
$baseuri = $_SERVER['REQUEST_URI'];
$baseuri = preg_replace( "/\?.*$/", "", $baseuri );
$curindex = 0;
foreach( $tabs as $tab )
{
$class = "tab";
if ( $index == $curindex )
$class ="tab-active";
?>
<td class="<?php echo($class); ?>">
<a href="<?php echo( $baseuri."?tabindex=".$curindex ); ?>">
<?php echo( $tab['title'] ); ?>
</a>
</td>
<?php
$curindex += 1;
}
?>
</tr>
<tr><td class="tab-content" colspan="<?php echo( count( $tabs ) + 1 ); ?>">
<?php echo( $tabs[$index ]['text'] ); ?>
</td></tr>
</table>
<?php
}
?>
<?php $xml = new DOMDocument(); $xml->Load( "input.xml" ); $xsl = new DOMDocument(); $xsl->Load( "format.xsl" ); $xslproc = new XSLTProcessor(); $xslproc->importStylesheet( $xsl ); print( $xslproc->transformToXML( $xml ) ); ?>
<books> <book name="Code Generation in Action" /> <book name="MDA Explained" /> <book name="PHP in a Nutshell" /> </books>
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html" /> <xsl:template match="/"> <html> <body> <xsl:for-each select="/books/book"> <xsl:value-of select="@name" /><br/> </xsl:for-each> </body> </html> </xsl:template> </xsl:stylesheet>
<html>
<?
$data = array(
array( "movies", 20 ),
array( "food", 30 ),
array( "workout", 10 ),
array( "work", 40 )
);
$max = 0;
foreach ( $data as $d ) { $max += $d[1]; }
?>
<body>
<table width="400" cellspacing="0" cellpadding="2">
<? foreach( $data as $d ) {
$percent = ( $d[1] / $max ) * 100;
?>
<tr>
<td width="20%"><? echo( $d[0] ) ?></td>
<td width="10%"><? echo( $d[1] ) ?>%</td>
<td>
<table width="<? echo($percent) ?>%" bgcolor="#aaa">
<tr><td> </td></tr>
</table>
</td>
</tr>
<? } ?>
</table>
</body>
</html>
$max. I then derive the percentage by dividing $max by the current value, and multiplying the result by 100 (to set the scale between 0 and 100). That number is stored in $percent, which is then used in the width attribute of the table.
height and width attributes on the img tag.img tags with the proper width and height attributes by using the getimagesize function to retrieve the actual width and height of the image.
<html>
<?php
function placegraphic( $file )
{
list( $width, $height ) = getimagesize("rss.png");
echo( "<img src=\"$file\" width=\"$width\" height=\"$height\" />" );
}
?>
<body>
<?php placegraphic( "rss.png" ); ?>
</body>
</html>
placegraphic function anywhere you would have put an img tag previously. But I don't recommend using this function in static headers or footers where the size of the images will never change. A performance overhead is associated with figuring out the size of an image. So you should use this function only when you don't know the size of the image until the graphic is requested.
<?php $to = "to@email.com"; $to_full = "Sally Cool"; $from = "from@email.com"; $from_full = "Joe Schmoe"; $subject = "HTML Mail Test"; $random_hash = "zzz582x"; ob_start(); ?> To: <?php echo($to_full); ?> <<?php echo($to); ?>> From: <?php echo($from_full); ?> <<?php echo($from); ?>> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="==Multipart_Boundary_<?php echo($random_hash); ?>" <?php $headers = ob_get_clean(); ob_start(); ?> This is a multi-part message in MIME format. --==Multipart_Boundary_<?php echo( $random_hash ); ?> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit This is the text of the message in a simple text format. --==Multipart_Boundary_<?php echo( $random_hash ); ?> Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 7bit <html> <body> <p>Here is something with <b>HTML</b> formatting. That can include all of the usual:</p> <ul> <li>Bulleted lists</li> <li>Tables</li> <li>Images (if you include them as attachments or external links)</li> <li>Character formatting</li> <li>…and more!</li> </ul> </body> </html> --==Multipart_Boundary_<?php echo( $random_hash ); ?>-- <?php $message = ob_get_clean(); $ok = @mail( $to, $subject, $message, $headers ); echo( $ok ? "Mail sent\n" : "Mail failed\n" ); ?>
http://activewidgets.com/) grid control to create a spreadsheet-style interface on a web page.
<?php $states = array(
array( "Alabama",4447100,1963711,52419.02,1675.01,50744,87.6,38.7 ),
array( "Alaska",626932,260978,663267.26,91316,571951.26,1.1,0.5 ),
array( "Arizona",5130632,2189189,113998.3,363.73,113634.57,45.2,19.3 ),
array( "Arkansas",2673400,1173043,53178.62,1110.45,52068.17,51.3,22.5 ),
array( "California",33871648,12214549,163695.57,7736.23,155959.34,217.2,78.3 ),
array( "Colorado",4301261,1808037,104093.57,376.04,103717.53,41.5,17.4 ),
array( "South Dakota",754844,323208,77116.49,1231.85,75884.64,9.9,4.3 ),
…
array( "Tennessee",5689283,2439443,42143.27,926.15,41217.12,138,59.2 ),
array( "Texas",20851820,8157575,268580.82,6783.7,261797.12,79.6,31.2 ),
array( "Utah",2233169,768594,84898.83,2755.18,82143.65,27.2,9.4 ),
array( "Vermont",608827,294382,9614.26,364.7,9249.56,65.8,31.8 ),
array( "Virginia",7078515,2904192,42774.2,3180.13,39594.07,178.8,73.3 ),
array( "Washington",5894121,2451075,71299.64,4755.58,66544.06,88.6,36.8 ),
array( "West Virginia",1808344,844623,24229.76,152.03,24077.73,75.1,35.1 ),
array( "Wisconsin",5363675,2321144,65497.82,11187.72,54310.1,98.8,42.7 ),
array( "Wyoming",493782,223854,97813.56,713.16,97100.4,5.1,2.3 ),
array( "Puerto Rico",3808610,1418476,5324.5,1899.94,3424.56,1112.1,414.2 )
);
?>
<html>
<head>
<link href="runtime/styles/xp/grid.css" rel="stylesheet" type="text/css" ></link>
<script src="runtime/lib/grid.js"></script>
</head>
<body>
<div style="width:500px;height:300px;">
<script>
var data = [
<?php $first = true; foreach( $states as $state ) { if ( !$first ) echo( "," );
?>
[ "<?php echo($state[0]); ?>", <?php echo($state[1]); ?>,
<?php echo($state[2]); ?>, <?php echo($state[3]); ?>,
<?php echo($state[4]); ?>, <?php echo($state[5]); ?>,
<?php echo($state[6]); ?>, <?php echo($state[7]); ?> ]
<?php $first = false; } ?>
];
var columns = [ "State", "Population", "Housing Units", "Total Area",
"Total Water", "Total Land", "Population Density", "Housing Density" ];
function dataLookup( row, col )
{
return data[row][col];
}
function headerLookup( col )
{
return columns[ col ];
}
var grid = new Active.Controls.Grid;
grid.setRowCount( data.length );
grid.setColumnCount( columns.length );
grid.setDataText( dataLookup );
grid.setColumnText( headerLookup );
document.write( grid );
</script>
</div>
</body>
</html>
http://activewidgets.com/) grid control to create a spreadsheet-style interface on a web page.
<?php $states = array(
array( "Alabama",4447100,1963711,52419.02,1675.01,50744,87.6,38.7 ),
array( "Alaska",626932,260978,663267.26,91316,571951.26,1.1,0.5 ),
array( "Arizona",5130632,2189189,113998.3,363.73,113634.57,45.2,19.3 ),
array( "Arkansas",2673400,1173043,53178.62,1110.45,52068.17,51.3,22.5 ),
array( "California",33871648,12214549,163695.57,7736.23,155959.34,217.2,78.3 ),
array( "Colorado",4301261,1808037,104093.57,376.04,103717.53,41.5,17.4 ),
array( "South Dakota",754844,323208,77116.49,1231.85,75884.64,9.9,4.3 ),
…
array( "Tennessee",5689283,2439443,42143.27,926.15,41217.12,138,59.2 ),
array( "Texas",20851820,8157575,268580.82,6783.7,261797.12,79.6,31.2 ),
array( "Utah",2233169,768594,84898.83,2755.18,82143.65,27.2,9.4 ),
array( "Vermont",608827,294382,9614.26,364.7,9249.56,65.8,31.8 ),
array( "Virginia",7078515,2904192,42774.2,3180.13,39594.07,178.8,73.3 ),
array( "Washington",5894121,2451075,71299.64,4755.58,66544.06,88.6,36.8 ),
array( "West Virginia",1808344,844623,24229.76,152.03,24077.73,75.1,35.1 ),
array( "Wisconsin",5363675,2321144,65497.82,11187.72,54310.1,98.8,42.7 ),
array( "Wyoming",493782,223854,97813.56,713.16,97100.4,5.1,2.3 ),
array( "Puerto Rico",3808610,1418476,5324.5,1899.94,3424.56,1112.1,414.2 )
);
?>
<html>
<head>
<link href="runtime/styles/xp/grid.css" rel="stylesheet" type="text/css" ></link>
<script src="runtime/lib/grid.js"></script>
</head>
<body>
<div style="width:500px;height:300px;">
<script>
var data = [
<?php $first = true; foreach( $states as $state ) { if ( !$first ) echo( "," );
?>
[ "<?php echo($state[0]); ?>", <?php echo($state[1]); ?>,
<?php echo($state[2]); ?>, <?php echo($state[3]); ?>,
<?php echo($state[4]); ?>, <?php echo($state[5]); ?>,
<?php echo($state[6]); ?>, <?php echo($state[7]); ?> ]
<?php $first = false; } ?>
];
var columns = [ "State", "Population", "Housing Units", "Total Area",
"Total Water", "Total Land", "Population Density", "Housing Density" ];
function dataLookup( row, col )
{
return data[row][col];
}
function headerLookup( col )
{
return columns[ col ];
}
var grid = new Active.Controls.Grid;
grid.setRowCount( data.length );
grid.setColumnCount( columns.length );
grid.setDataText( dataLookup );
grid.setColumnText( headerLookup );
document.write( grid );
</script>
</div>
</body>
</html>
http://www.bosrup.com/web/overlib/), you can have handy pop-up labels that appear above text on your page. This hack makes it a little easier to create these links by providing a PHP wrapper function to invoke the library.
<?php
function popup( $text, $popup )
{
?>
<a href="javascript:void(0);" onmouseover="return overlib('<?php echo($popup); ?>
');" onmouseout="return nd();"><?php echo($text); ?></a>
<?php
}
?>
<html>
<head>
<script type="text/javascript" src="overlib.js"><!-- overLIB (c) Erik Bosrup -->
</script>
</head>
<body>
<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;">
</div>
So this is just a test of popups. Not something interesting about <?php popup(
'rabbits', 'Small furry woodland creatures.<br/>Rabbits also make good pets.'
); ?>. Because that would just be silly.
</body>
</html>
http://tool-man.org/) to create drag-and-drop lists.
<html>
<head>
<style>
#states li { margin: 0px; }
ul.boxy li { margin: 3px; }
ul.sortable li {
position: relative;
}
ul.boxy {
list-style-type: none;
padding: 0px;
margin: 2px;
width: 20em;
font-size: 13px;
font-family: Arial, sans-serif;
}
ul.boxy li {
cursor:move;
padding: 2px 2px;
border: 1px solid #ccc;
background-color: #eee;
}
.clickable a {
display: block;
text-decoration: none;
cursor: pointer;
cursor: hand;
}
.clickable li:hover {
background-color: #f6f6f6;
}
</style>
<script language="JavaScript" type="text/javascript"
src="source/org/tool-man/core.js"></script>
<script language="JavaScript" type="text/javascript"
src="source/org/tool-man/events.js"></script>
<script language="JavaScript" type="text/javascript"
src="source/org/tool-man/css.js"></script>
<script language="JavaScript" type="text/javascript"
src="source/org/tool-man/coordinates.js"></script>
<script language="JavaScript" type="text/javascript"
src="source/org/tool-man/drag.js"></script>
<script language="JavaScript" type="text/javascript"
src="source/org/tool-man/dragsort.js"></script>
<script language="JavaScript" type="text/javascript"
src="source/org/tool-man/cookies.js"></script>
<script language="JavaScript" type="text/javascript">
<!--
var dragsort = ToolMan.dragsort()
var junkdrawer = ToolMan.junkdrawer()
window.onload = function()
{
dragsort.makeListSortable(document.getElementById("states"),
verticalOnly, saveOrder)
}
function verticalOnly(item) { item.toolManDragGroup.verticalOnly() }
function saveOrder(item) { }
function prepFields()
{
document.getElementById( "states_text" ).value = junkdrawer.
serializeList( document.getElementById( "states" ) );
return true;
}
//-->
</script>
</head>
<body>
<ul id="states" class="boxy">
<li>California</li>
<li>Texas</li>
<li>Alaska</li>
</ul>
<form method="post" action="tellme.php">
<input type="hidden" name="states" value="" id="states_text" />
<input type="submit" onclick="return prepFields();">
</form>
</body>
</html>
<?php $states = array(
array( "Alabama",4447100,1963711,52419.02,1675.01,50744,87.6,38.7 ),
array( "Alaska",626932,260978,663267.26,91316,571951.26,1.1,0.5 ),
array( "Arizona",5130632,2189189,113998.3,363.73,113634.57,45.2,19.3 ),
array( "Arkansas",2673400,1173043,53178.62,1110.45,52068.17,51.3,22.5 ),
array( "California",33871648,12214549,163695.57,7736.23,155959.34,217.2,78.3 ),
array( "Colorado",4301261,1808037,104093.57,376.04,103717.53,41.5,17.4 ),
…
array( "Washington",5894121,2451075,71299.64,4755.58,66544.06,88.6,36.8 ),
array( "West Virginia",1808344,844623,24229.76,152.03,24077.73,75.1,35.1 ),
array( "Wisconsin",5363675,2321144,65497.82,11187.72,54310.1,98.8,42.7 ),
array( "Wyoming",493782,223854,97813.56,713.16,97100.4,5.1,2.3 ),
array( "Puerto Rico",3808610,1418476,5324.5,1899.94,3424.56,1112.1,414.2 )
);
?>
<html>
<head>
<script language="Javascript">
var width = 300;
var height = 300;
var axes = [ "population", "housing_units", "total_area", "total_water", "total_
land", "people_density", "housing_density" ];
var data = [
<?php $first = true; foreach( $states as $state ) { if ( !$first ) echo( "," );
?>
{ state: "<?php echo($state[0]); ?>", population: <?php echo($state[1]); ?>,
housing_units: <?php echo($state[2]); ?>, total_area: <?php echo($state[3]); ?>,
total_water: <?php echo($state[4]); ?>, total_land: <?php echo($state[5]); ?>,
people_density: <?php echo($state[6]); ?>, housing_density: <?php
echo($state[7]); ?> }
<?php $first = false; } ?>
];
var axmin = {};
var axmax = {};
for( axind in axes )
{
axmin[ axes[axind] ] = 100000000;
axmax[ axes[axind] ] = -100000000;
}
for( ind in data )
{
row = data[ind];
for( axind in axes )
{
axis = axes[axind];
if ( row[axis] < axmin[axis] )
axmin[axis] = row[axis];
if ( row[axis] > axmax[axis] )
axmax[axis] = row[axis];
}
}
function cleargraph()
{
graph = document.getElementById( "graph" );
graph.innerHTML = "";
}
function adddot( value, size, x, y, text )
{
var left = x - ( size / 2 );
var top = width - ( y + ( size / 2 ) );
var cleft = "auto";
var ctop = "auto";
var cright = "auto";
var cbottom = "auto";
if ( left < 0 ) { cright = ( left * -1 ) + "px"; }
if ( left + size > width ) { cleft = ( width - left ) + "px"; }
if ( top < 0 ) { ctop = ( top * -1 ) + "px"; }
if ( top + size > height ) { cbottom = ( height - top ) + "px"; }
if ( value <= 0.25 )
img = "ltgray.gif";
else if ( value <= 0.50 )
img = "gray.gif";
else if ( value <= 0.75 )
img = "dkgray.gif";
else
img = "black.gif";
html = "<img src=\""+img+"\" width=\""+size+"\" height=\""+size+"\" ";
html += "style=\"position:absolute;left:"+left+"px;top:"+top+"px;";
html += "clip:rect( "+ctop+" "+cleft+" "+cbottom+" "+cright+" );";
html += "\" onclick=\"alert(\'"+text+"\')\"/>";
graph = document.getElementById( "graph" );
graph.innerHTML += html;
}
function calculate_value( row, field, min, max )
{
var val = row[ field ] - axmin[ field ];
var scale = ( max - min ) / ( axmax[ field ] - axmin[ field ] );
return min + ( scale * val );
}
function drawgraph()
{
cleargraph();
var xvar = document.getElementById( "bottom" ).value;
var yvar = document.getElementById( "side" ).value;
var sizevar = document.getElementById( "size" ).value;
var valuevar = document.getElementById( "color" ).value;
for( rowind in data )
{
var row = data[rowind];
var x = calculate_value( row, xvar, 5, width - 5 );
var y = calculate_value( row, yvar, 5, height - 5 );
var size = calculate_value( row, sizevar, 5, 30 );
var value = calculate_value( row, valuevar, 0, 1 );
adddot( value, size, x, y, row.state );
}
}
function buildselect( axis, current )
{
var html = "<select id=\""+axis+"\" onchange=\"drawgraph()\">";
for( axind in axes )
{
var selected = "";
if ( axes[axind] == current )
selected = " selected=\"true\"";
html += "<option value=\""+axes[axind]+"\""+selected+">"+axes[axind]+"
</option>";
}
html += "</select>";
document.write( html );
}
</script>
</head>
<body onload="drawgraph();">
Side: <script language="Javascript">buildselect( "side", "population" );</script>
Bottom: <script language="Javascript">buildselect( "bottom", "housing_units" );</
script>
Size: <script language="Javascript">buildselect( "size", "total_area" );</script>
Color: <script language="Javascript">buildselect( "color", "total_water" );</
script>
<div style="position:relative;border:1px solid #eee; clip:rect(0px 0px 300px
300px); width:300px; height:300px;" id="graph">
</div>
</body>
</html>
<?php
function start_section( $id, $title )
{
?>
<table cellspacing="0" cellpadding="0">
<tr>
<td width="30" valign="top">
<a href="javascript: void twist('<?php echo($id); ?>');">
<img src="up.gif" border="0" id="img_<?php echo($id); ?>"/>
</a>
</td>
<td width="90%">
<h1><?php echo( $title ); ?></h1>
<div style="visibility:hidden;position:absolute;"
id="<?php echo($id); ?>" class="spin-content">
<?php
}
function end_section()
{
?>
</div>
</td>
</tr>
</table>
<?php
}
function spinner_header()
{
?>
<style type="text/css">
body { font-family: arial, verdana; }
h1 { font-size: medium; border-bottom: 1px solid black; }
.spin-content { font-size: small; margin-left: 10px; padding: 10px; }
</style>
<script language="Javascript">
function twist( sid )
{
imgobj = document.getElementById( "img_"+sid );
divobj = document.getElementById( sid );
if ( imgobj.src.match( "up.gif" ) )
{
imgobj.src = "down.gif";
divobj.style.position = "relative";
divobj.style.visibility = "visible";
}
else
{
imgobj.src = "up.gif";
divobj.style.visibility = "hidden";
divobj.style.position = "absolute";
}
}
</script>
<?php
}
?>
<html>
<head>
<?php spinner_header() ?>
</head>
<body>
<?php start_section( "one", "Report part one" ) ?>
This report will tell you a lot of stuff you didn't know before.
And that's good. Because that's what a report should do.<br/><br/>
But it will tell you so much that it needs to be rolled up into sections
so that you don't have to gasp as you see it all at once.
<?php end_section() ?>
<?php start_section( "two", "Report part two" ) ?>
This is a table of numbers and such:<br/>
<table>
<tr><th>State</th><th>Total</th></tr>
<tr><td>CA</td><td>$35M</td></tr>
<tr><td>PA</td><td>$22M</td></tr>
<tr><td>NC</td><td>$5M</td></tr>
<tr><td>FL</td><td>$15M</td></tr>
</table>
<?php end_section() ?>
</body>
</html>
<?php
$nextid = 1;
function start_link( $text )
{
global $nextid;
$idtext = "a"+$nextid;
?><a href="javascript: void drop( '<?php echo($idtext); ?>' );">
<span id="a_<?php echo($idtext); ?>"><?php echo($text); ?></span></a>
<div id="<?php echo($idtext); ?>" class="drop" style="visibility:hidden;">
<table cellspacing="0" cellpadding="0" width="170"><tr>
<td valign="top" width="20">
<a href="javascript: void close(<?php echo($idtext); ?>)"><img src="close.gif"
border="0"></a>
</td>
<td valign="top" width="150">
<?php
}
function end_link()
{
?>
</td>
</tr></table>
</div><?php
}
function link_header()
{
?>
<style type="text/css">
body { font-family: arial, verdana; }
.drop {
padding: 5px;
font-size: small;
background: #eee;
border: 1px solid black;
position: absolute;
}
</style>
<script language="Javascript">
function drop( sid )
{
aobj = document.getElementById( "a_"+sid );
divobj = document.getElementById( sid );
divobj.style.top = aobj.offsetBottom+10;
divobj.style.left = aobj.offsetLeft+10;
divobj.style.visibility = "visible";
}
function close( sid )
{
divobj = document.getElementById( sid );
divobj.style.visibility = "hidden";
}
</script>
<?php
}
?>
<html>
<head>
<?php link_header(); ?>
</head>
<body>
Hey <?php start_link( "this is interesting" ); ?>
That really<br/>
Is interesting <?php end_link(); ?>. How about that.
<br/>
The popup will go over text and all that.<br/>
And it will stay up until it's dismissed with the close
button.
</body>
</html>
<?php require_once( "menu.php" ); $page = "home"; if ( $_GET['page'] ) $page = $_GET['page']; ?> <html> <head> <title>Page - <?php echo($page); ?></title> <?php echo menu_css(); ?> </head> <body> <table cellspaceing="0" cellpadding="5"> <tr> <td width="200" valign="top"> <?php page_menu( $page ); ?> </td> <td width="600" valign="top"> Page: <?php echo( $page ); ?> </td> </tr> </table> </body> </html>
<?php
function menu_css() {
?>
<style type="text/css">
.menu-inactive, .menu-active {
padding: 2px;
padding-left: 20px;
font-family: arial, verdana;
}
.menu-inactive { background: #ddd; }
.menu-active { background: #000; font-weight: bold; }
.menu-inactive a { text-decoration: none; }
.menu-active a { color: white; text-decoratio