<?php
include("includes/site_info.php");
include('session_handler.inc');
include_once __INCLUDE_CLASS_PATH."/class.Picture.php";
$picture = new Picture();

$WUserID = $_SESSION['Sess_UserId'];
$WUsername = $_SESSION['Sess_UserName'];
if ($_REQUEST['gid']) { $gid = $_REQUEST['gid']; }
else { $gid = 0; }
if ($_REQUEST['pid']) { $pid = $_REQUEST['pid']; }
else { $pid = 0; }
$prev_id = mysql_fetch_object(mysql_query("SELECT * FROM galleryitem WHERE Gallery_ID = '$gid' and GalleryItem_ID < '$pid' ORDER BY GalleryItem_ID ASC LIMIT 1"));
$next_id = mysql_fetch_object(mysql_query("SELECT * FROM galleryitem WHERE Gallery_ID = '$gid' and GalleryItem_ID > '$pid' ORDER BY GalleryItem_ID ASC LIMIT 1"));
$galleryitem_query=mysql_query("SELECT *, DATE_FORMAT(gal_date, '%M %d, %Y') as gal_date FROM galleryitem WHERE GalleryItem_ID = '$pid' and  Gallery_ID = '$gid'") or die(mysql_error());
$galleryitem_TOTAL = mysql_num_rows($galleryitem_query);
$gallery_TOTAL = mysql_num_rows(mysql_query("SELECT * FROM galleryitem WHERE Gallery_ID = '$gid'"));

$gallerymain_query=mysql_query("SELECT Name FROM gallery WHERE mem_id = '$WUserID' and Gallery_ID = '$gid'") or die(mysql_error());
$gallerymain_TOTAL = mysql_num_rows($gallerymain_query);
if ($gallerymain_TOTAL >0) {
	$gallerymain=mysql_fetch_object($gallerymain_query) or die(mysql_error());
} else {
?>

<div id="top_panel" class="grey_row_back">
	<?php include ("panel_top.php"); ?>
</div>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="5" class="white_back_t_xb">
				<tr>
					<td><div class="light_orang_h">
							<div style="background-color:#FF0000; width:10px; height:10px; float:left; margin-top:3px; margin-right:5px;"><img src="images/spacer.gif" width="10" height="10" /></div>
							Album </div>
						<div class="dot_line"><img src="images/spacer.gif" width="1" height="1" /></div>
						<div class="solid_line"><img src="images/spacer.gif" width="1" height="1" /></div></td>
				</tr>
				<tr class="lightgrey_10">
					<td align="center"><a title="Add Album" href="#caddalbum?tab=media" onclick="javascript: callpage(this.href);" rel="subpage_link">Add Album</a> | <a href="#cgalleries?tab=media" onclick="javascript: callpage(this.href);">Back to Galleries</a></td>
				</tr>
				<tr>
					<td align="center"><div class="padding_10">Can't find a photo to view.</div></td>
				</tr>
			</table></td>
	</tr>
</table>
<?php
	die;
}
?>
<script type="text/javascript">
jQuery.noConflict();
jQuery(document).ready(function($){

	$("#reply").click(function(){
		if ($(this).val()=="Please type in your message!")
		$(this).val('');
	});
	
});

function submit_form (galleryItemID, userID, userName) {

	var comment = jQuery("#reply").val();
    var dataString = 'userID='+ userID + '&galleryItemID=' + galleryItemID + '&userName='+ userName + '&comment=' + comment + '&Submit=addGalleryItemComment';
	
	if(comment=='')
     {
    jQuery("#reply").val("Please type in your message!");
     }
	else if(comment=='Please type in your message!')
     {
    jQuery("#reply").val("Please type in your message!");
     }
	else
	{
	jQuery("#load").html('<img src="images/loader1.gif">');
jQuery.ajax({
		type: "POST",
  url: "comments_action.php",
   data: dataString,
  cache: false,
  success: function(html){
 
   jQuery("#reply").val("");
	jQuery("#load").html('');
   jQuery("#CommentAll").prepend(html);
  }
 });
}
	}

function showmore(comment_id) {
	
	jQuery("#more"+comment_id).html('');
	jQuery("#Seemore"+comment_id).show();

	return false;
}
function deleteComment(comment_id, galleryItemID) {

    var dataString = 'Submit=deleteGalleryItemComment&galleryItemID='+ galleryItemID + '&comment_id=' + comment_id;
//	 alert (dataString);
	
jQuery.ajax({
		type: "POST",
  url: "comments_action.php",
   data: dataString,
	dataType: 'json',
  cache: false,
  success: function(result){
//	 alert (result.status);
	if (result.status=="1") {
	jQuery("#contentBox"+comment_id).html(result.result);
	jQuery("#commentBox"+comment_id).fadeOut(500);
	}else {
	jQuery("#contentBox"+comment_id).prepend(result.result);
	}
  }
 });
	}
  </script>
<div id="top_panel" class="grey_row_back">
	<?php include ("panel_top.php"); ?>
</div>
<?php 
	foreach($_POST as $field=>$data) {
	if ($field=="done") {
		echo'<div id="msg_content_done">Wow, Your request was done!</div>';
	}
	elseif ($field=="error") {
		echo'<div id="msg_content_error">Ops! Database Error, please try again!</div>';
	}
}
?>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="5" class="white_back_t_xb">
				<tr>
					<td><div class="light_orang_h">
							<div style="background-color:#FF0000; width:10px; height:10px; float:left; margin-top:3px; margin-right:5px;"><img src="images/spacer.gif" width="10" height="10" /></div>
							<?=$gallerymain->Name?>
						</div>
						<div class="dot_line"><img src="images/spacer.gif" width="1" height="1" /></div>
						<div class="solid_line"><img src="images/spacer.gif" width="1" height="1" /></div></td>
				</tr>
				<?php if ($galleryitem_TOTAL > 0){ 
		while ($gallery = mysql_fetch_object($galleryitem_query) ) {
		$pg = mysql_result(mysql_query("SELECT COUNT(Gallery_ID) FROM galleryitem WHERE GalleryItem_ID <= '$gallery->GalleryItem_ID' and Gallery_ID = '$gid'"),0) or die(mysql_error());
?>
				<tr class="lightgrey_10">
					<td align="center">Photo
						<?=$pg?>
						of
						<?=$gallery_TOTAL?>
						| <a href="#cgalleries?tab=media" onclick="javascript: callpage(this.href);">Back to Galleries</a> | <a href="#cgallery?tab=media&gid=<?=$gid?>" onclick="javascript:callpage(this.href);" rel="subpage_link">Back to Album</a> | <a href="#ceditgphoto?tab=media&gid=<?=$gid?>&pid=<?=$pid?>" onclick="javascript:callpage(this.href);" rel="subpage_link">Edit</a></td>
				</tr>
				<tr class="solid_line_separator">
					<td><div align="center" class="padding_10 grey_10 style_left">
							<?php if ($next_id) { 
				?>
							<img src="<?=$SITE_MAIN_WWW_ROOT?>/members/<?=$WUsername?>/gallery/<?=md5($next_id->GalleryItem_ID)?>.<?=$next_id->ext?>" width="0" border="0"> <a href="#cgphoto?tab=media&gid=<?=$gallery->Gallery_ID?>&pid=<?=$next_id->GalleryItem_ID?>" onclick="javascript: callpage(this.href);" rel="subpage_link"><img src="<?=$SITE_MAIN_WWW_ROOT?>/members/<?=$WUsername?>/gallery/<?=md5($gallery->GalleryItem_ID)?>.<?=$gallery->ext?>" class="img_b_p3" border="0"></a>
							<?php } elseif ($prev_id) { 
				?>
							<img src="<?=$SITE_MAIN_WWW_ROOT?>/members/<?=$WUsername?>/gallery/<?=md5($prev_id->GalleryItem_ID)?>.<?=$prev_id->ext?>" width="0" border="0"> <a href="#cgphoto?tab=media&gid=<?=$gallery->Gallery_ID?>&pid=<?=$prev_id->GalleryItem_ID?>" onclick="javascript: callpage(this.href);" rel="subpage_link"><img src="<?=$SITE_MAIN_WWW_ROOT?>/members/<?=$WUsername?>/gallery/<?=md5($gallery->GalleryItem_ID)?>.<?=$gallery->ext?>" class="img_b_p3" border="0"></a>
							<?php } else { 
				?>
							<img src="<?=$SITE_MAIN_WWW_ROOT?>/members/<?=$WUsername?>/gallery/<?=md5($gallery->GalleryItem_ID)?>.<?=$gallery->ext?>" class="img_b_p3" border="0">
							<?php } ?>
							<br />
							<?php 
			  if ($gallery->Description) { 
			  echo "<span class=\"line_height20 left\">";
			  echo nl2br($gallery->Description);
			  echo "<br />";
			  echo "</span>";
              } 
			  ?>
						</div></td>
				</tr>
				<tr>
					<td><div id="info"><span class="lightgrey_10">From the album: </span><br />
							<a href="#cgallery?tab=media&gid=<?=$gid?>" onclick="javascript:callpage(this.href);" rel="subpage_link">
							<?=$gallerymain->Name?>
							</a> <br />
							<br />
							<span class="lightgrey_10">Added</span><br />
							<?=$gallery->gal_date?>
							<br />
						</div>
						<div id="comment">
							<div id="replyBox">
								<form name="commentForm" id="commentForm" action="javascript: submit_form(<?=$gallery->GalleryItem_ID?>, <?=$WUserID?>, '<?=$WUsername?>')">
									<?php 
 $myhahaper_query=mysql_query("SELECT mem_userid, mem_username FROM members LEFT JOIN adverts ON (mem_userid=adv_userid) where mem_userid='$WUserID' AND mem_confirm='1' AND adv_approved='1'",$link);
 $check_count=mysql_num_rows($myhahaper_query);
 if ($check_count > 0) { 
 $ret_pic = mysql_fetch_object($myhahaper_query);
if ($WUserID==$ret_pic->mem_userid) {
$photo_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$ret_pic->mem_userid' and pic_default='Y'") or die(mysql_error()); 
} else {
$photo_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$ret_pic->mem_userid' and pic_default='Y' and pic_private='N'") or die(mysql_error()); 
}
$pics_count = mysql_num_rows($photo_query);
$aPicture = mysql_fetch_object($photo_query);
if ($pics_count > 0) {
	$medium = $aPicture->pic_picture."_ps.".$aPicture->ext;
	$male1_picture1 = "$SITE_MAIN_WWW_ROOT/members/$ret_pic->mem_username/picture/$medium";
             }else{
$male1_picture1=$CONST_LINK_ROOT."/".$picture->GetProfilePicture($ret_pic->mem_userid);
}
?>
									<div class="left w65_h58"><a href="javascript:;" onclick="javascript: callprofileInfo(<?=$ret_pic->mem_userid?>);"><img src="<?=$male1_picture1?>" border="0" title="Name:&nbsp;<?=ucwords($ret_pic->mem_username)?>" class="img_b_p3_white"/></a></div>
									<div align="right">
										<textarea name="reply" class="textarea" id="reply"></textarea>
										<span id="load"></span>
										<input name="comment" type="submit" value="Comment" class="button" />
									</div>
									<?php 
				} ?>
								</form>
							</div>
							<div id="CommentAll">
								<?php
						$comments_query=mysql_query("SELECT * FROM galleryitem_comment WHERE GalleryItem_ID = '$gallery->GalleryItem_ID' and com_approved='1' ORDER BY com_time desc") or die(mysql_error());
						$comments_TOTAL = mysql_num_rows($comments_query);
						if ($comments_TOTAL >0) {
						while ($comments = mysql_fetch_object($comments_query) ) {
if ($WUserID==$comments->com_memid) {
$photo_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$comments->com_memid' and pic_default='Y'") or die(mysql_error()); 
} else {
$photo_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$comments->com_memid' and pic_default='Y' and pic_private='N'") or die(mysql_error()); 
}
$pics_count = mysql_num_rows($photo_query);
$aPicture = mysql_fetch_object($photo_query);
if ($pics_count > 0) {
	$medium = $aPicture->pic_picture."_ps.".$aPicture->ext;
	$male1_picture1 = "$SITE_MAIN_WWW_ROOT/members/$comments->com_mem_username/picture/$medium";
             }else{
$male1_picture1=$CONST_LINK_ROOT."/".$picture->GetProfilePicture($comments->com_memid);
}
						?>
								<div id="commentBox<?=$comments->comment_id?>" class="comment_reply">
									<div class="left w65_h58"><a href="javascript:;" onclick="javascript: callprofileInfo(<?=$comments->com_memid?>);"><img src="<?=$male1_picture1?>" border="0" title="Name:&nbsp;<?=ucwords($comments->com_mem_username)?>" class="img_b_p3_white"/></a></div>
									<div class="comment_reply_text">
										<div class="delete"><a href="javascript:;" onclick="javascript: deleteComment(<?=$comments->comment_id?>, <?=$gallery->GalleryItem_ID?>);">x</a></div>
										<span id="contentBox<?=$comments->comment_id?>">
										<?php 
				$short_msg_text=strip_tags(stripslashes(substr($comments->comment,0,300)));
				echo $short_msg_text;
				if (strlen (strip_tags($comments->comment))>300) echo "<span id=\"more".$comments->comment_id."\">... <a href=\"javascript:;\" onclick=\"javascript: showmore(".$comments->comment_id.");\">more</a></span><span id=\"Seemore".$comments->comment_id."\" class=\"none\">".strip_tags(stripslashes(substr($comments->comment,300)))."</span>";
				?>
										</span> </div>
								</div>
								<?php 
						}
						}
						?>
							</div>
						</div></td>
				</tr>
				<?php }
		  } else {
?>
				<tr class="lightgrey_10">
					<td align="center"><a title="Add Album" href="#caddalbum?tab=media" onclick="javascript: callpage(this.href);" rel="subpage_link">Add Album</a> | <a href="#cgalleries?tab=media" onclick="javascript: callpage(this.href);">Back to Galleries</a></td>
				</tr>
				<tr class="solid_line_separator">
					<td align="center"><div class="padding_10">Can't find a photo to view.</div></td>
				</tr>
				<?php
	die;
}
?>
				<tr>
					<td>&nbsp;</td>
				</tr>
			</table></td>
	</tr>
</table>
