<?php

/***************************************************************************

 gallery_summary.php
 --------------------
 copyright : (C) 2002-2003 The ezContents Development Team

 ***************************************************************************/

/***************************************************************************
 The ezContents Development Team offers no warranties on this script.
 The owner/licensee of the script is solely responsible for any problems
 caused by installation of the script or use of the script.

 All copyright notices regarding ezContents must remain intact on the
 scripts and in the HTML for the scripts.

 For more info on ezContents,
 visit http://www.ezcontents.org/

/***************************************************************************

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the License which can be found within the
 *   zipped package.
 *
 ***************************************************************************/

global $HTTP_SERVER_VARS;
if ( (substr($HTTP_SERVER_VARS["PHP_SELF"],-11) == 'control.php') ||
	 (substr($HTTP_SERVER_VARS["PHP_SELF"],-10) == 'module.php') ||
	 (substr($HTTP_SERVER_VARS["PHP_SELF"],-16) == 'showcontents.php') ) {
	 require_once('./modules/moduleSec.php');
} else {
	require_once('../moduleSec.php');
}

include_once ($GLOBALS["admin_home"]."compile.php");

$strQuery = ModuleDataQuery($HTTP_POST_VARS["catcode"]);


$countres = dbRetrieve($strQuery,true,0,0);
$lRecCount = dbRowsReturned($countres);
dbFreeResult($countres);

$nCurrentPage = 0;
if ($HTTP_GET_VARS["page"] != "") { $nCurrentPage = $HTTP_GET_VARS["page"]; }
$nPages = intval(($lRecCount - 0.5) / $GLOBALS["scPerPage"]) + 1;
$lStartRec = $nCurrentPage * $GLOBALS["scPerPage"];
if ($nPages > 1) { SubModuleHdFt($nCurrentPage,$nPages);
} else { echo '<br />'; }


?><center><?php
if ($lRecCount == 0) { ModuleNoEntries();
} else {
	$result = dbRetrieve($strQuery,true,$lStartRec,$GLOBALS["scPerPage"]);
	if ($GLOBALS["scPerPage"] / 2 == floor($GLOBALS["scPerPage"] / 2)) { $images_per_col = 2; }
	elseif ($GLOBALS["scPerPage"] / 3 == floor($GLOBALS["scPerPage"] / 3)) { $images_per_col = 3; }
	elseif ($GLOBALS["scPerPage"] / 4 == floor($GLOBALS["scPerPage"] / 4)) { $images_per_col = 4; }
	elseif ($GLOBALS["scPerPage"] / 5 == floor($GLOBALS["scPerPage"] / 5)) { $images_per_col = 5; }
	else { $images_per_col = 1; }
	$maxwidth = floor($screenwidth / $images_per_col);
	?><table border="0" width="100%" cellspacing="0" cellpadding="0">
	<?php

	$colcount = 1;
	while ($rsContent = dbFetch($result)) {
		if ($colcount == 1) { echo '<tr><td align="center" valign="top">'; }
		?>
		<table border="0" width="100%" cellspacing="1" cellpadding="3" class="headercontent">
		<tr><td class="header"><?php echo htmlspecialchars($rsContent["title"]); ?></td></tr>
		<tr><td class="tablecontent" valign="top"><?php
		$bEncodeHTML = true;

		$filename = $rsContent["filename"];
		$fileref = explode('/',$filename);
		$filename = array_pop($fileref);
		$dir = implode('/',$fileref);
		$savedir = getcwd();
		chdir($GLOBALS["rootdp"].$GLOBALS["image_home"].$dir);
		$size = GetImageSize($filename);
		$width  = $size["0"];
		$height = $size["1"];
		chdir($savedir);

		if ($width > $maxwidth) {
			$factor = $width / $maxwidth;
			$width = floor($width / $factor);
			$height = floor($height / $factor);
		}

		if (($GLOBALS["gsUseFrames"] == 'Y') && ($EZ_SESSION_VARS["noframesbrowser"] != True)) {
			?><a href="<?php echo BuildLink('module.php')?>&topgroupname=<?php echo $HTTP_POST_VARS["topgroupname"]; ?>&groupname=<?php echo $HTTP_POST_VARS["groupname"]; ?>&subgroupname=<?php echo $HTTP_POST_VARS["subgroupname"]; ?>&link=<?php echo $GLOBALS["modules_home"].$GLOBALS["ModuleRef"]; ?>/showgallerydetails.php&galleryid=<?php echo $rsContent["galleryid"]; ?>&rlink=<?php echo $HTTP_GET_VARS["link"]; ?>"><?php
		} else {
			?><a href="<?php echo BuildLink('control.php')?>&topgroupname=<?php echo $HTTP_POST_VARS["topgroupname"]; ?>&groupname=<?php echo $HTTP_POST_VARS["groupname"]; ?>&subgroupname=<?php echo $HTTP_POST_VARS["subgroupname"]; ?>&galleryid=<?php echo $rsContent["galleryid"]; ?>&link=<?php echo $GLOBALS["modules_home"].$GLOBALS["ModuleRef"]; ?>/showgallerydetails.php&rlink=<?php echo $HTTP_GET_VARS["link"]; ?>"><?php
		}
		echo '<img src="'.$GLOBALS["image_home"].$rsContent["filename"].'" width="'.$width.'" height="'.$height.'" border="0">';
		echo '</a>';
		$bEncodeHTML = true;
		if ($rsContent["artist"] != '') {
			echo '<br /><b>'.ext_print(compile($GLOBALS["tqBlock1"].'html'.$GLOBALS["tqBlock2"].$rsContent["artist"].$GLOBALS["tqBlock1"].$GLOBALS["tqCloseBlock"].'html'.$GLOBALS["tqBlock2"], 'N', 'N', 'L'),$bEncodeHTML, 'L').'</b>';
		}
		if ($rsContent["caption"] != '') {
			echo '<br />'.ext_print(compile($GLOBALS["tqBlock1"].'html'.$GLOBALS["tqBlock2"].$rsContent["caption"].$GLOBALS["tqBlock1"].$GLOBALS["tqCloseBlock"].'html'.$GLOBALS["tqBlock2"], 'N', 'N', 'L'),$bEncodeHTML, 'L');
		}
		ShowContentFooter($GLOBALS["scPostedDate"],$GLOBALS["scPostedBy"],$rsContent);
		?></table><?php
		if ($colcount == $images_per_col) {
			echo '</td></tr>';
			$colcount = 1;
		} else {
			echo '</td><td align="center" valign="top">';
			$colcount++;
		}
	}
	echo '</table>';
}
dbFreeResult($result);

?>
</center>
<?php

if ($nPages > 1) { SubModuleHdFt($nCurrentPage,$nPages); }

?>
