session_save_path("/home/users/web/b1408/apo.orange85/cgi-bin/tmp");
session_start();
//$_SESSION = array(); // reset session array
//session_destroy(); // destroy session.
include("header.inc");
$categoryID = $_REQUEST['categoryID'];
$subCategoryID = $_REQUEST['subCategoryID'];
$picType = 0;
if($categoryID) {
$q = "select *, (select count(*) from subCategories where categoryID=".$categoryID.") subCategoryCount from categories where categoryID=".$categoryID;
$result = mysql_query($q,$conn);
$r = mysql_fetch_array($result);
$category = $r['category'];
$hasSubCategories = $r['subCategoryCount'] > 0 ? true : false;
$text = $r['text'];
$picType = $r['picType'];
}
if($subCategoryID) {
$q = "select * from subCategories where subCategoryID=".$subCategoryID;
$result = mysql_query($q,$conn);
$r = mysql_fetch_array($result);
$subCategory = $r['subCategory'];
$text = $r['text'];
$picType = $r['picType'];
}
?>
$page = 1;
$count = 0;
$startRecord = 0;
if($_REQUEST['page'] != "") {
$page = $_REQUEST['page'];
}
if($_REQUEST['startRecord']) {
$startRecord = $_REQUEST['startRecord'];
$count = $startRecord;
}
else if($page != 1 && $_SESSION['page'.$page]['startRecord'] != NULL) {
$startRecord = $_SESSION['page'.$page]['startRecord'];
}
$_SESSION['page'.$page]['startRecord'] = $count;
$q = "";
if($subCategoryID) {
$q .= "subCategoryID=".$subCategoryID;
}
else {
$q .= "categoryID=".$categoryID." and subCategoryID=0";
}
$sql = "select count(*) from pictures where ".$q;
$result = mysql_query($sql,$conn);
$r = mysql_fetch_array($result);
$lastRecord = $r[0];
if($subCategoryID) {
?>
Pictures Available
}
$q .= " order by orientationRank, rank";
if($subCategoryID) {
$q .= ", subCategoryID";
}
else {
$q .= ", categoryID";
}
//$q .= " limit ".$startRecord.", ".$maxPerPage;
if($picType == 1) {
$maxPerPage = 1;
}
$sql = "select *, (select rank from orientations where orientation=p.orientation) orientationRank from pictures p where ".$q." limit ".$startRecord.", ".$maxPerPage;
$result = mysql_query($sql,$conn);
$dir = "categories/";
$category = str_replace("/","-",$category);
$dir .= $category;
if($subCategory) {
$subCategory = str_replace("/","-",$subCategory);
$dir .= "/".$subCategory;
}
$i = 0;
$orientation = "";
$rows = 0;
while($r=mysql_fetch_array($result)) {
$ext = strchr($r['name'],".");
$tn = str_replace($ext,"_tn".$ext,$r['name']);
if($r['orientation'] != $orientation) {
$img .= "
";
if($i > 0) {
break;
}
$orientation = $r['orientation'];
}
$dimensions = "";
// Only show dimensions if the category we are in is Photography
if($categoryID == 1) {
$dimensions = "
Dimensions";
switch($orientation) {
case "horizontal":
case "vertical":
$dimensions .= "
80" x 20"
60" x 18"
40" x 14"
20" x 7"
";
break;
case "horizontalSquare":
case "verticalSquare":
$dimensions .= "
32" x 40"
16" x 20"
11" x 14"
";
break;
}
}
$dimensions .= "
Custom sizes available upon request
";
$img .= "
";
$i++;
// orientation = fullPage, meaning we are displaying 1 per page
if($orientation == "fullPage") {
$img = "
";
break;
}
switch($orientation) {
case "horizontal":
if($i%2 == 0) {
$rows++;
}
break;
case "vertical":
if($i%7 == 0) {
$rows++;
}
break;
case "fullPage":
if($i%1 == 0) {
$rows++;
}
break;
default:
if($i%4 == 0) {
$rows++;
}
}
if($rows == $maxRows) {
break;
}
}
$count += $i;
if($i == 0) {
?>
No pictures available at this time
include("footer.inc");
die();
}
echo "
$img
";
?>
$url = $_SERVER["REQUEST_URI"];
if(strpos($url,"&")) {
$url = substr($url,0,strpos($url,"&"));
}
if($subCategoryID) {
$url .= "&subCategoryID=".$subCategoryID;
}
//echo "Page: ".$page." ";
if($count == $lastRecord && $page == 1) {
$prev = "«";
$next = "»";
?>
}
else if($page == 1) {
$prev = "«";
$next = "
»";
?>
}
else if($count == $lastRecord) {
$prev = "
«";
$next = "»";
?>
}
else {
$prev = "
«";
$next = "
»";
?>
}
$sql = "select *, (select rank from orientations where orientation=p.orientation) orientationRank from pictures p where ".$q;
$result = mysql_query($sql,$conn);
$i = 0;
$orientation = "";
$rows = 0;
$thisPage = 1;
echo $prev." ";
if($thisPage == $page) {
echo $thisPage;
}
else {
?>
}
$thisPage++;
while($r=mysql_fetch_array($result)) {
$ext = strchr($r['name'],".");
$tn = str_replace($ext,"_tn".$ext,$r['name']);
if($r['orientation'] != $orientation) {
$img .= "
";
if($i > 0) {
if($thisPage == $page) {
echo $thisPage;
}
else if($i != $lastRecord) {
?>
}
$rows = 0;
$thisPage++;
}
$orientation = $r['orientation'];
}
$i++;
switch($orientation) {
case "horizontal":
if($i%2 == 0) {
$rows++;
}
break;
case "vertical":
if($i%7 == 0) {
$rows++;
}
break;
case "fullPage":
$maxRows = 1;
if($i%1 == 0) {
$rows++;
}
break;
default:
if($i%4 == 0) {
$rows++;
}
}
if($rows == $maxRows) {
if($thisPage == $page) {
echo $thisPage;
}
else if($i != $lastRecord) {
?>
}
$rows = 0;
$thisPage++;
}
}
echo " ".$next;
?>
include("footer.inc");
?>