Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Apress committed Oct 11, 2016
0 parents commit aa1b46e
Show file tree
Hide file tree
Showing 1,240 changed files with 94,950 additions and 0 deletions.
Binary file added 3378.pdf
Binary file not shown.
Binary file added 9781590596487.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
111 changes: 111 additions & 0 deletions Code Download/Chapter 02/Code/business/error_handler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php
class ErrorHandler
{
// Private constructor to prevent direct creation of object
private function __construct()
{
}

/* Set user error handler method to ErrorHandler::Handler method */
public static function SetHandler($errTypes = ERROR_TYPES)
{
return set_error_handler(array ('ErrorHandler', 'Handler'), $errTypes);
}

// Error handler method
public static function Handler($errNo, $errStr, $errFile, $errLine)
{
/* The first two elements of the backtrace array are irrelevant:
- ErrorHandler.GetBacktrace
- ErrorHandler.Handler */
$backtrace = ErrorHandler::GetBacktrace(2);

// Error message to be displayed, logged, or mailed
$error_message = "\nERRNO: $errNo\nTEXT: $errStr" .
"\nLOCATION: $errFile, line " .
"$errLine, at " . date('F j, Y, g:i a') .
"\nShowing backtrace:\n$backtrace\n\n";

// Email the error details, in case SEND_ERROR_MAIL is true
if (SEND_ERROR_MAIL == true)
error_log($error_message, 1, ADMIN_ERROR_MAIL, "From: " .
SENDMAIL_FROM . "\r\nTo: " . ADMIN_ERROR_MAIL);

// Log the error, in case LOG_ERRORS is true
if (LOG_ERRORS == true)
error_log($error_message, 3, LOG_ERRORS_FILE);

/* Warnings don't abort execution if IS_WARNING_FATAL is false
E_NOTICE and E_USER_NOTICE errors don't abort execution */
if (($errNo == E_WARNING && IS_WARNING_FATAL == false) ||
($errNo == E_NOTICE || $errNo == E_USER_NOTICE))
// If the error is nonfatal ...
{
// Show message only if DEBUGGING is true
if (DEBUGGING == true)
echo '<pre>' . $error_message . '</pre>';
}
else
// If error is fatal ...
{
// Show error message
if (DEBUGGING == true)
echo '<pre>' . $error_message . '</pre>';
else
echo SITE_GENERIC_ERROR_MESSAGE;

// Stop processing the request
exit;
}
}

// Builds backtrace message
public static function GetBacktrace($irrelevantFirstEntries)
{
$s = '';
$MAXSTRLEN = 64;
$trace_array = debug_backtrace();

for ($i = 0; $i < $irrelevantFirstEntries; $i++)
array_shift($trace_array);
$tabs = sizeof($trace_array) - 1;

foreach ($trace_array as $arr)
{
$tabs -= 1;
if (isset ($arr['class']))
$s .= $arr['class'] . '.';
$args = array ();

if (!empty ($arr['args']))
foreach ($arr['args']as $v)
{
if (is_null($v))
$args[] = 'null';
elseif (is_array($v))
$args[] = 'Array[' . sizeof($v) . ']';
elseif (is_object($v))
$args[] = 'Object: ' . get_class($v);
elseif (is_bool($v))
$args[] = $v ? 'true' : 'false';
else
{
$v = (string)@$v;
$str = htmlspecialchars(substr($v, 0, $MAXSTRLEN));
if (strlen($v) > $MAXSTRLEN)
$str .= '...';
$args[] = '"' . $str . '"';
}
}

$s .= $arr['function'] . '(' . implode(', ', $args) . ')';
$line = (isset ($arr['line']) ? $arr['line']: 'unknown');
$file = (isset ($arr['file']) ? $arr['file']: 'unknown');
$s .= sprintf(' # line %4d, file: %s', $line, $file);
$s .= "\n";
}

return $s;
}
}
?>
43 changes: 43 additions & 0 deletions Code Download/Chapter 02/Code/hatshop.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
body
{
font-family: tahoma, verdana, arial;
font-size: 11px;
margin: 0px;
padding: 5px;
text-align: center;
}
body div
{
margin: 0px;
padding: 5px;
text-align: left;
}
.left_box
{
margin: 0px 15px 15px 0px;
padding: 2px;
width: 170px;
}
img
{
border: 0;
}
#header
{
left: 194px;
margin: 0px;
padding: 0px;
position: absolute;
text-align: right;
top: 10px;
width: 570px;
}
#content
{
left: 194px;
margin: 0px;
padding: 0px 0px 10px 10px;
position: absolute;
top: 110px;
width: 558px;
}
11 changes: 11 additions & 0 deletions Code Download/Chapter 02/Code/include/app_top.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
// Include utility files
require_once 'include/config.php';
require_once BUSINESS_DIR . 'error_handler.php';

// Sets the error handler
ErrorHandler::SetHandler();

// Load the page template
require_once PRESENTATION_DIR . 'page.php';
?>
36 changes: 36 additions & 0 deletions Code Download/Chapter 02/Code/include/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
// SITE_ROOT contains the full path to the hatshop folder
define('SITE_ROOT', dirname(dirname(__FILE__)));

// Application directories
define('PRESENTATION_DIR', SITE_ROOT . '/presentation/');
define('BUSINESS_DIR', SITE_ROOT . '/business/');

// Settings needed to configure the Smarty template engine
define('SMARTY_DIR', SITE_ROOT . '/libs/smarty/');
define('TEMPLATE_DIR', PRESENTATION_DIR . '/templates');
define('COMPILE_DIR', PRESENTATION_DIR . '/templates_c');
define('CONFIG_DIR', SITE_ROOT . '/include/configs');

// These should be true while developing the web site
define('IS_WARNING_FATAL', true);
define('DEBUGGING', true);

// The error types to be reported
define('ERROR_TYPES', E_ALL);

// Settings about mailing the error messages to admin
define('SEND_ERROR_MAIL', false);
define('ADMIN_ERROR_MAIL', '[email protected]');
define('SENDMAIL_FROM', '[email protected]');
ini_set('sendmail_from', SENDMAIL_FROM);

// By default we don't log errors to a file
define('LOG_ERRORS', false);
define('LOG_ERRORS_FILE', 'c:\\hatshop\\errors_log.txt'); // Windows
// define('LOG_ERRORS_FILE', '/var/tmp/hatshop_errors.log'); // Unix

/* Generic error message to be displayed instead of debug info
(when DEBUGGING is false) */
define('SITE_GENERIC_ERROR_MESSAGE', '<h2>HatShop Error!</h2>');
?>
1 change: 1 addition & 0 deletions Code Download/Chapter 02/Code/include/configs/site.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
site_title = "HatShop : Demo Site for Beginning PHP and PosgreSQL E-Commerce"
10 changes: 10 additions & 0 deletions Code Download/Chapter 02/Code/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
// Load Smarty library and config files
require_once 'include/app_top.php';

// Load Smarty template file
$page = new Page();

// Display the page
$page->display('index.tpl');
?>
21 changes: 21 additions & 0 deletions Code Download/Chapter 02/Code/presentation/page.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
// Reference Smarty library
require_once SMARTY_DIR . 'Smarty.class.php';

/* Class that extends Smarty, used to process and display Smarty
files */
class Page extends Smarty
{
// Class constructor
public function __construct()
{
// Call Smarty's constructor
parent::Smarty();

// Change the default template directories
$this->template_dir = TEMPLATE_DIR;
$this->compile_dir = COMPILE_DIR;
$this->config_dir = CONFIG_DIR;
}
}
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div id="header">
<a href="index.php">
<img src="images/title.png" alt="Site title" />
</a>
</div>
21 changes: 21 additions & 0 deletions Code Download/Chapter 02/Code/presentation/templates/index.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{* smarty *}
{config_load file="site.conf"}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<title>{#site_title#}</title>
<link href="hatshop.css" type="text/css" rel="stylesheet" />
</head>
<body>
<div>
<div class="left_box">
Place list of departments here
</div>
{include file="header.tpl"}
<div id="content">
Place contents here
</div>
</div>
</body>
</html>
1 change: 1 addition & 0 deletions Code Download/Chapter 02/Code/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php phpinfo(); ?>
7 changes: 7 additions & 0 deletions Code Download/Chapter 02/Database/chapter02.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE USER hatshopadmin
PASSWORD 'hatshopadmin'
SUPERUSER NOINHERIT NOCREATEDB NOCREATEROLE
VALID UNTIL 'infinity';

CREATE DATABASE hatshop WITH OWNER = hatshopadmin
ENCODING = 'UTF8';
18 changes: 18 additions & 0 deletions Code Download/Chapter 03/Code/business/catalog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
// Business tier class for reading product catalog information
class Catalog
{
// Retrieves all departments
public static function GetDepartments()
{
// Build SQL query
$sql = 'SELECT * FROM catalog_get_departments_list();';

// Prepare the statement with PDO-specific functionality
$result = DatabaseHandler::Prepare($sql);

// Execute the query and return the results
return DatabaseHandler::GetAll($result);
}
}
?>
Loading

0 comments on commit aa1b46e

Please sign in to comment.