Sure thing. Here’s common.php:
[php]<?php
define(“NL”,"\n");
define(“TAB”,"\t");
session_start();
if(!isset($addrPrefix)) $addrPrefix="";
include(“functions.php”);
//The following lines set basic constants after determining whether we’re on the
//development server or the production server
if($_SERVER[“DOCUMENT_ROOT”]=="/opt/lampp/htdocs")
{
define(“SITEDIR”,“http://localhost/ebay/”);
define(“ROOTDIR”,"//opt/lampp/htdocs/ebay/");
define(“SMARTYDIR”,"//opt/lampp/htdocs/ebay/includes/smarty/");
}
else
{
define(“SITEDIR”,“http://www.mydomain.com/ebay/”);
define(“ROOTDIR”,"/home/mydomain/public_html/ebay/");
define(“SMARTYDIR”,"/home/mydomain/public_html/ebay/includes/smarty/");
}
require(SMARTYDIR.“Smarty.class.php”);
class objSiteSmarty extends Smarty
{
function objSiteSmarty()
{
// Class Constructor. These automatically get set with each new instance.
parent::__construct();
$this->template_dir = ROOTDIR.'includes/templates/';
$this->compile_dir = ROOTDIR.'includes/templates_c/';
$this->config_dir = ROOTDIR.'includes/configs/';
$this->cache_dir = ROOTDIR.'includes/cache/';
$this->assign('app_name','peekabay');
} // end function objSiteSmarty
} // end class objSiteSmarty
$smarty= new objSiteSmarty();
$smarty->assign(‘SITEDIR’,SITEDIR);
$smarty->assign(‘ROOTDIR’,ROOTDIR);
?>[/php]
And here’s functions.php:
[php]<?php
function __autoload($class)
{
echo “bye”;
die;
} // end function __autoload()
/*This is the actual __autoload function.
function __autoload($class)
{
$file=ROOTDIR.“includes/classes/”.$class.".php";
if(file_exists($file))
{
require($file);
}
else
{
die (“cannot instantiate class”);
}
} // end function __autoload()
*/
function string_entities($str)
{
return htmlentities(html_entity_decode($str));
}
function inToFeet($inches)
{
if($inches<1) return 0;
$ft=floor($inches/12);
$in=$inches%12;
return $ft."’ “.$in.”"";
} // end function intofeet
// Returns the whole part of a real number appended with .95
function dotNineFive($real)
{
return floor($real)+.95;
}
function odd($num)
{
return(is_int($num/2));
}
function InQuotes($strTempString,$dbl=true)
{
if($dbl)
{
return “”".$strTempString.""";
}
else
{
return “’”.$strTempString."’";
}
}
function viewArray($temp)
{
if(!is_array($temp)) return array(“error”);
foreach($temp as $k=>$v)
{
if(is_array($v))
{
echo “Subarray “.$k.”:
”;
viewArray($v);
echo “------
”;
}
else
{
echo $k." = “.$v.”
";
}
}
echo “
”;
}
//Generic Query String Building Function
function makeQS()
{
$strQS="";
$thisArr = func_get_arg(0);
$table = func_get_arg(1);
$mode = func_get_arg(2);
if (func_num_args() > 3) // filter for select, update or delete sent
{
$filter = func_get_arg(3);
}
switch ($mode)
{
case “add”:
$strQS=“INSERT INTO “.$table.” (”;
$strTemp = " VALUES (";
foreach($thisArr as $k=>$v)
{
$strQS .= $k.",";
$strTemp .= inQuotes($v).",";
}
$strTemp = rtrim($strTemp);
$strTemp = rtrim($strTemp,",").")";
$strQS = trim($strQS);
$strQS = trim($strQS,",").")";
$strQS .= $strTemp;
break;
case “get”:
$strQS=“SELECT * FROM “.$table;
if (is_array($filter))
{
$strQS .= " WHERE “;
foreach($filter as $k=>$v)
{
if (!trim($v))
{
}
else
{
$strQS .=$k.”=”.inQuotes($v).” AND ";
}
}
$strQS = trim($strQS," AND ");
$strQS = trim ($strQS," WHERE ");
}
break;
case "update":
$id=$thisArr["id"];
unset($thisArr["id"]);
$strQS = "UPDATE ".$table." SET ";
foreach($thisArr as $k=>$v)
{
if (is_numeric ( $v))
{
$strQS .= $k."=".$v.", ";
}
else
{
$strQS .= $k."="."'".$v."'".", ";
}
}
$strQS = trim($strQS);
$strQS = trim($strQS,",")."";
$strQS .= " where id=".$id;
break;
case "delete":
$strQS= "DELETE FROM ".$table;
if ($table == "categories") {
$strQS .= " WHERE cat_id = ".$filter;
$strQS .= " OR parent_id = ".$filter;
}
else if ($table == "option_labels") {
$strQS .= " WHERE optlabel_id = ".$filter;
}
else {
$strQS .= " WHERE opt_id = ".$filter;
}
break;
}
return $strQS;
}
?>[/php]
It’s all pretty basic stuff, really. Hope you can find a head-smacker in here somewhere. Thanks.