<?
session_start();
include('_db.connection.php');
include('_public.setup.php');

$folder_result = mysql_query("SELECT mid FROM folders WHERE folder_id = '$fid'", $db);
$folder = mysql_fetch_object($folder_result);

$member_result = mysql_query("SELECT * FROM members WHERE member_id = '$folder->mid'", $db);
$member = mysql_fetch_object($member_result);

$pfmid = $member->member_id;

$extra_height = 0;

if($member->custom_plan == 1){
	if($member->custom_branding == 1){
		$extra_height = 8;
	}
}
else{
	$plan_result = mysql_query("SELECT * FROM plans WHERE plan_id = '$member->plan'", $db);
	$plan = mysql_fetch_object($plan_result);
	
	if($plan->branding == 1){
		$extra_height = 8;
	}
}

?>
<center>
<br>
<table bgcolor="#ffffff" cellpadding="0" cellspacing="0" style="border: 1px solid #eeeeee">
	<tr>
		<td><!-- HEADER --></td>
	</tr>
	<tr>
		<td align="center">
			<table border="0" bgcolor="#ffffff">
				<?
					$cell = 0;
					$image_bytes = 0;
					$image_result = mysql_query("SELECT * FROM images WHERE fid = '$fid'", $db);
					$image_count = mysql_num_rows($image_result);
					
						if($image_count != 0){
							echo "<tr><td align=\"center\"><font face=\"Verdana\" size=\"2\" color=\"#8C8E91\"><b>Click on an image for a larger version</td></tr>";
						}
						else{
							echo "<tr><td align=\"center\"><table width=\"400\"><tr><td align=\"center\"><br><br><font face=\"Verdana\" size=\"2\" color=\"#8C8E91\"><b>There are no images in this portfolio.<br><br></td></tr></table></td></tr>";
						}
				?>
				<tr>
					<td>
						<table width="100%" bgcolor="#ffffff">
							<?php
								echo "<tr>";																
								while($image = mysql_fetch_object($image_result)){
									$src = "./usr/" . $pfmid . "/i_" . $image->filename;
									$size_in_bytes = $size_in_bytes + filesize($src);
									
									if($cell == 4){
										echo "</tr><tr><td colspan=\"5\" height=\"3\"></td></tr><tr>";
										$cell = 1;
									}
									else{
										$cell++;
									}
							?>
								<td style="border: 1px solid #B7B7B7" align="center" valign="top" width="150">
									<table cellpadding="0" cellspacing="0" width="150">
										<tr>
											<td align="center" style="padding: 3px;"><a href="#" OnClick="window.open('pf.window.php?i=<? echo $image->image_id; ?>', 'image_win', ['HEIGHT=<? echo $image->height + $extra_height; ?>', 'WIDTH=<? echo $image->width; ?>', 'dependent']);"><img src="./usr/<?php echo $pfmid; ?>/i_<?php echo $image->filename; ?>" style="border: 1px solid #000000;"></a></td>
										</tr>
										<tr>
											<td valign="bottom" align="left" style="padding: 4px;"><font face="verdana" size="1" color="#6F6F6F"><a href="#"  OnClick="window.open('pf.window.php?i=<? echo $image->image_id; ?>', 'image_win', ['HEIGHT=<? echo $image->height + $extra_width; ?>', 'WIDTH=<? echo $image->width; ?>', 'dependent']);" class="imgmgr"><b><?php echo $image->filename; ?></b></a><br><?php echo $image->caption; ?></td>
										</tr>
									</table>															
								</td>
							<?
								if($cell != 4){
									echo "<td>&nbsp;</td>";
								}
									
									}														
									$cell_remainder = 4 - $cell;
									if($cell_remainder != 0){
										$cell_remainder = $cell_remainder + 1;
										echo "<td colspan=\"$cell_remainder\">&nbsp;</td>";
									}															
									
										echo "</tr><tr><td colspan=\"5\" height=\"3\"></td></tr>";
										
									$image_megs = $size_in_bytes/1000000;
									$update_bw = $image_megs + $member->used_bandwidth;
									
									$sql = "UPDATE members SET used_bandwidth='$update_bw' WHERE member_id = '$pfmid;'";
									$result = mysql_query($sql);
							?>
						</table>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
<br>
</center>

