session_start();
if (!$adminPathPrefix){
$adminPathPrefix = "";
}
if (strlen($adminPathPrefix)<1){
header('location: index.php');
}
if (empty($_SESSION['baseUrl'])){
$_SESSION['baseUrl'] = str_replace("index.php", "", $_SERVER['SCRIPT_FILENAME']);
}
include("db.php");
if(!function_exists("getNav")){
function getNav($type = null){
$menu = array();
if ($type == 1){
$menu[]= array('href'=>'editCategories.php', 'name'=>"Edit Categories");
$menu[]= array('href'=>'editProducts.php', 'name'=>"Edit Products");
//$menu[]= array('href'=>'editGallery.php', 'name'=>"Edit Picture Gallery");
//$menu[]= array('href'=>'editContact.php', 'name'=>"Edit Contact Info");
$menu[]= array('href'=>'images.php', 'name'=>"Upload Images");
$menu[]= array('href'=>'?logout=true', 'name'=>"Logout");
} else {
$menu[]= array('href'=>'index.php', 'name'=>"Home");
$menu[]= array('href'=>'products.php', 'name'=>"Products");
$menu[]= array('href'=>'gallery.php', 'name'=>"Picture Gallery");
$menu[]= array('href'=>'contact.php', 'name'=>"Contact Us");
//$menu[]= array('href'=>'warranty.php', 'name'=>"Warranty");
$menu[]= array('href'=>'https://www.facebook.com/AssaultMotorsportsLLC?fref=ts', 'name'=>"");
$menu[]= array('href'=>'http://instagram.com/assaultmotorsports?ref=badge', 'name'=>"");
}
return $menu;
}
}
if(!function_exists("getCategories")){
function getCategories(){
//Categories
$categories = array();
$queryCategories = "";
$queryCategories .= "SELECT `CategoryId`, `CategoryName`, `CategoryImage`, `CategoryOrder` ";
$queryCategories .= "FROM `categories` ";
$queryCategories .= "WHERE `Deleted`=0 ";
$queryCategories .= "ORDER BY `CategoryOrder`";
$resultCategories = mysql_query($queryCategories) or die('getCategories Query failed: ' . mysql_error());
while ($row = mysql_fetch_array($resultCategories, MYSQL_ASSOC)) {
$categories[] = $row;
}
return $categories;
}
}
if(!function_exists("getCategory")){
function getCategory($catId= 0){
//Categories
$category = array();
$queryCategory = "";
$queryCategory .= "SELECT `CategoryName`, `CategoryImage`, `CategoryOrder` ";
$queryCategory .= "FROM `categories` ";
$queryCategory .= "WHERE `CategoryId`='$catId' ";
$resultCategory = mysql_query($queryCategory) or die('getCategory Query failed: ' . mysql_error());
while ($row = mysql_fetch_array($resultCategory, MYSQL_ASSOC)) {
$category = $row;
}
return $category ;
}
}
if(!function_exists("navBar")){
function navBar($type = null){
$menuList = getNav($type);
$output = "";
$output .= "
\n";
return $output;
}
}
if(!function_exists("sideMenu")){
function sideMenu($selectedId = 0, $admin = null){
$page = "";
if ($admin == 1){
$page = "";
} else {
$page = "products.php";
}
$menuList = getCategories();
$output = "";
$output .= "\n";
$rowCount++;
if ($rowCount >= $rowLimit){
$output .= " \n";
$output .= " \n";
$output .= "\n";
return $output;
}
}
if(!function_exists("getProducts")){
function getProducts($category = ""){
//Products
$products = array();
$queryProduct = "";
$queryProduct .= "SELECT `ProductId`, `ProductName`, `ProductPrice`, `ProductPriceOld`, `ProductAddToCart`, `ProductImage`, `ProductDescription`, `ProductOrder` ";
$queryProduct .= "FROM `products` ";
$queryProduct .= "WHERE `Deleted`=0 ";
if (!empty($category)){
$cat = mysql_real_escape_string($category);
$queryProduct .= "AND `CategoryId`='".$cat."' ";
}
$queryProduct .= "ORDER BY `ProductOrder`";
$resultProduct = mysql_query($queryProduct) or die('getProducts Query failed: ' . mysql_error());
while ($row = mysql_fetch_array($resultProduct, MYSQL_ASSOC)) {
$products[] = $row;
}
return $products;
}
}
if(!function_exists("productsList")){
function productsList($products = null, $category = null, $forceCategory = false, $admin = false){
if (empty($products)){
if ($forceCategory && empty($category)){
$products = array();
} else {
$products = getProducts($category);
}
}
if (empty($products)){
echo "There are no products to display.";
} else {
$adminPathPrefix = "";
if ($admin){
$adminPathPrefix = "../";
} else {
$adminPathPrefix = "";
}
echo "\n";
foreach ($products as $product) {
echo "
\n"; //Product
if ($product['ProductPrice']) {
echo "
\n";
if ($product['ProductPriceOld']) {
echo "
Retail: $".($product['ProductPriceOld']/100)."
\n";
echo "
";
echo "Sale: ";
} else {
echo "
";
}
echo "$".($product['ProductPrice']/100)."
\n";
echo dbToHtml($product['ProductAddToCart']);
echo "
\n";
}
if ($product['ProductImage']) {
$pics = explode(",", $product['ProductImage']);
//echo "
\n";
//echo "
\n";
echo "
";
echo "
";
for ($num = 1; count($pics) > $num; $num++){
echo "
";
}
echo "
\n";
}
//echo "
\n";
echo "
\n";
echo "
{$product['ProductName']}
\n";
echo "
" . dbToDisp($product['ProductDescription']) . "
\n";
echo "
\n";
echo "
\n";
}
echo "
\n";
}
}
}
if(!function_exists("productsListTest")){
function productsListTest($products = null, $category = null, $forceCategory = false, $admin = false){
if (empty($products)){
if ($forceCategory && empty($category)){
$products = array();
} else {
$products = getProducts($category);
}
}
if (empty($products)){
echo "There are no products to display.";
} else {
$adminPathPrefix = "";
if ($admin){
$adminPathPrefix = "../";
} else {
$adminPathPrefix = "";
}
echo "
\n";
foreach ($products as $product) {
echo "
\n"; //Product
if ($product['ProductPrice']) {
echo "
\n";
if ($product['ProductPriceOld']) {
echo "
Retail: $".($product['ProductPriceOld']/100)."
\n";
echo "
";
echo "Sale: ";
} else {
echo "
";
}
echo "$".($product['ProductPrice']/100)."
\n";
echo dbToHtml($product['ProductAddToCart']);
echo "
\n";
}
if ($product['ProductImage']) {
$pics = explode(",", $product['ProductImage']);
//echo "
\n";
//echo "
\n";
echo "
";
echo "
";
for ($num = 1; count($pics) > $num; $num++){
echo "
";
}
echo "
\n";
}
//echo "
\n";
echo "
\n";
echo "
{$product['ProductName']}
\n";
echo "
" . dbToDisp($product['ProductDescription']) . "
\n";
echo "
\n";
echo "
\n";
}
echo "
\n";
}
}
}
if(!function_exists("getCarouselList")){
function getCarouselList(){
$menu = array();
$menu[]= array('href'=>'products.php?categoryid=dr', 'name'=>"DR Series LED Light Bars", 'img'=>"light0.jpg");
$menu[]= array('href'=>'products.php?categoryid=sr', 'name'=>"SR Series LED Light Bars", 'img'=>"light1.jpg");
$menu[]= array('href'=>'products.php?categoryid=hid', 'name'=>"HID Offroad Lights", 'img'=>"inc/css/gun2.jpg");
$menu[]= array('href'=>'products.php?categoryid=hid', 'name'=>"More Test", 'img'=>"inc/css/gun_400x200.jpg");
return $menu;
}
}
if(!function_exists("carousel")){
function carousel(){
$carouselList = getCarouselList();
$output = "";
$output .= "
\n";
$output .= "
\n";
$output .= "
\n";
$output .= "
\n";
$output .= " \n";
$output .= "
\n";
$output .= "
\n";
$output .= "
\n";
$num = 0;
foreach ($carouselList as $item){
$output .= "- '', // File name.
* 'shortname' => '', // File name.
* 'type' => '', // 'file' or 'dir'.
* 'writeable' => '', // TRUE if writeable.
* 'perms' => '', // Permissions.
* 'modified' => '', // Last modified. Unix timestamp.
* 'size' => '', // File size in bytes.
* )
*/
function get_filelist($dir, $sort = 'name') {
$filelist = array();
$subdirs = array();
if ($dirlink = @opendir($dir)) {
// Creates an array with all file names in current directory.
while (($file = readdir($dirlink)) !== false) {
if ($file != "." && $file != ".." && ((!is_dir("{$dir}/{$file}")) || is_dir("{$dir}/{$file}"))) { // Hide these two special cases and files and filetypes in blacklists.
$c = array();
$c['name'] = $file;
$c['shortname'] = $file;
$c['type'] = "file";
$c['writeable'] = is_writeable("{$dir}/{$file}");
// File permissions.
if ($c['perms'] = @fileperms("{$dir}/{$file}")) {
if (is_dir("{$dir}/{$file}")) {
$c['perms'] = substr(base_convert($c['perms'], 10, 8), 2);
} else {
$c['perms'] = substr(base_convert($c['perms'], 10, 8), 3);
}
}
$c['modified'] = @filemtime("{$dir}/{$file}");
$c['size'] = @filesize("{$dir}/{$file}");
if (is_dir("{$dir}/{$file}")) {
$c['size'] = 0;
$c['type'] = "dir";
if ($sublink = @opendir("{$dir}/{$file}")) {
while (($current = readdir($sublink)) !== false) {
if ($current != "." && $current != "..") {
$c['size']++;
}
}
closedir($sublink);
}
$subdirs[] = $c;
} else {
$filelist[] = $c;
}
}
}
closedir($dirlink);
// sort($filelist);
// Obtain a list of columns
$ext = array();
$name = array();
$date = array();
$size = array();
foreach ($filelist as $key => $row) {
$ext[$key] = strtolower($row['ext']);
$name[$key] = strtolower($row['name']);
$date[$key] = $row['modified'];
$size[$key] = $row['size'];
}
if ($sort == 'type') {
// Sort by file type and then name.
array_multisort($ext, SORT_ASC, $name, SORT_ASC, $filelist);
} elseif ($sort == 'size') {
// Sort by filesize date and then name.
array_multisort($size, SORT_ASC, $name, SORT_ASC, $filelist);
} elseif ($sort == 'date') {
// Sort by last modified date and then name.
array_multisort($date, SORT_DESC, $name, SORT_ASC, $filelist);
} else {
// Sort by file name.
array_multisort($name, SORT_ASC, $filelist);
}
// Always sort dirs by name.
sort($subdirs);
return array_merge($subdirs, $filelist);
} else {
return "dirfail";
}
}
}
if(!function_exists("linkPhone")){
function linkPhone($phoneNumber){
$phoneReplaceArray = array('.', '-', '(', ')', ' ', '_');
$phoneLink = str_replace($phoneReplaceArray, "", $phoneNumber);
if (strlen($phoneLink) < 11){
$phoneLink = "1".$phoneLink;
} else {
if (substr($phoneLink, 0, 1) != 1){
$phoneLink = "1".$phoneLink;
}
}
return $phoneLink;
}
}
if(!function_exists("dateDbToDisp")){
function dateDbToDisp($date){
$dateNew = null;
if (strlen($date) == 10){
$dateArr = explode('-', $date);
$dateNew = $dateArr[1]."-".$dateArr[2]."-".$dateArr[0];
}
return $dateNew;
}
}
if(!function_exists("dateDispToDb")){
function dateDispToDb($date){
$dateNew = null;
if (strlen($date) == 10){
$dateArr = explode('-', $date);
$dateNew = $dateArr[2]."-".$dateArr[0]."-".$dateArr[1];
}
return $dateNew;
}
}
if(!function_exists("dbToDisp")){
function dbToDisp($text){
$text = str_replace('"', '"', $text);
$text = str_replace("\'", "'", $text);
$text = str_replace('\r\n', "
", $text);
$text = str_replace("\n", "
", $text);
return $text;
}
}
if(!function_exists("textToDb")){
function textToDb($text){
$text = stripslashes($text);
$text = str_replace("'", "\'", $text);
$textNewLine = str_replace("\r\n", "
", $text);
//$textNewLine = str_replace("\r", "
", $textNewLine);
return $textNewLine;
}
}
if(!function_exists("dbToEdit")){
function dbToEdit($text){
$text = str_replace('"', '"', $text);
$textQuot = str_replace("\'", "'", $text);
$textNewLine = str_replace("
", "\r\n", $textQuot);
return $textNewLine;
}
}
if(!function_exists("dbToHtml")){
function dbToHtml($text){
$text = str_replace('"', '"', $text);
$textNewLine = str_replace("
", "\r\n", $text);
return $textNewLine;
}
}
?>