<?php
require_once ("../config.inc.php");
require_once ("../includes/adminlogincheck.inc.php");
require_once ("../includes/mysql.inc.php");
require_once ("../includes/arrays.inc.php");
require_once ("../classes/users.class.php");

$page		= isset($_REQUEST['page'])	?	trim($_REQUEST['page'])	:	"1";
$id			= isset($_REQUEST['id'])	?	trim($_REQUEST['id'])	:	"0";
$pid		= isset($_REQUEST['pid'])	?	trim($_REQUEST['pid'])	:	"0";
$message	= "";
$arrImages	= array();
$objC		= new check();
if (!$objDB) {
	$message	= "Unable to Locate Database Server.";
} else {
	if ($id <= 0) {
		header("Location:manage_user.php?id=$id&page=$page");
		exit;
	}
	$objU		= new users($objDB);
	if (isset($_POST['BackNow'])) {
		if ($message == "") {
			header("Location: users.php?page=$page");
			exit;
		}
	}
	if (isset($_POST['RP'])) {
		$message	= $objU->delete_user_image($id, $pid);
	}
	$arrImages	= $objU->get_user_images($id);
	if (empty($arrImages))
		$message	.= "No images exists for this profile.<br>";
}

include_once('title.inc.php');

//total count of images uploaded by the user
$condition="where nUser_Id='".$id."'";
$totalImgCount=$objST->fetchSingleValue($objST->select_rows(TABLEPREFIX.'photos','count(nPhoto_Id) as cnt',$condition),'cnt');
?>
<script language="javascript" type="text/javascript">
function change_photo(uid, pid)
{
	imagewindow = window.open ('user_photo_popup.php?id='+uid+'&pid='+pid,
	"mywindow","menubar=0,statusbar=0,resizable=1,scrollbars=1,width=550,height=400");
	imagewindow.moveTo(180,150);
}
function validate()
{
	var frm	= document.frmUser;
	
	return true;

}
</script>
<link href="../js/facebox.css" media="screen" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../js/jquery.js"></script>
<script src="../js/facebox.js" type="text/javascript"></script>
<script type="text/javascript">
    jQuery(document).ready(function($) {
      $('a[rel*=facebox]').facebox()
    })
  </script>
  <?php include_once('tophtml.php');?>
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td valign="top" class="white"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="72%" valign="top">
			<table width="100%"  border="0" cellspacing="0" cellpadding="5">
          <tr>
            <td><table width="100%"  border="0" cellspacing="0" cellpadding="5">
              <tr>
                <td width="41%" class="headings1" colspan="2">Manage Profile Images </td>
              </tr>
			  </table>
			  <div class="bordernew padding2">
			  <table width="100%">
              <tr>
                <td colspan="2" class="maintext"><?php include_once('usertabs.php');?></td>
                </tr>
            </table>
			<form name="form1" method="post" action="">
          <table width="100%"  border="0" cellspacing="0" cellpadding="5">
            <tr>
              <td><table width="100%"  border="0" cellspacing="0" cellpadding="0">
				<?php if ($objDB) 
					  { 
                 			if (!empty($arrImages)) 
							{ 
				?>
                <tr align="left">
                  <td height="40" align="center" class="maintext2"><strong class="boldtext">#</strong></td>
                  <td class="maintext2"><strong class="boldtext">Image</strong></td>
                  <td class="maintext2"><strong class="boldtext">Title</strong></td>
                  <td class="maintext2"><strong class="boldtext">Action</strong></td>
                  </tr>
					<?php 	if(isset($message) && $message!='')
							{
					?>
                <tr align="left">
                  <td align="center" class="maintext2">&nbsp;</td>
                  <td colspan="3" class="maintext2 warning"><?php echo $message;?></td>
                  </tr>
					<?php  	}//end if
							foreach ($arrImages as $key => $value) 
							{ 
				?>
                <tr align="left" valign="top">
                  <td width="4%" align="center" class="maintext2"><?php echo $key+1?></td>
                  <td width="42%" class="maintext2"><a href="<?php echo PROFILE_IMAGE_URL."/".$value['vUrl']?>" rel="facebox"><img src="../<?php echo PROFILE_IMAGE_URL."/sthumb_".$value['vUrl']?>" width="75" height="75" border="0"></a></td>
                  <td width="22%" class="maintext2"><?php echo stripslashes($value['vTitle'])?></td>
                  <td width="32%" class="maintext2">
									  <input type="button" name="CP" value="Change Photo" onClick="change_photo(<?php echo $id?>, <?php echo $value['nPhoto_Id']?>);" class="signupbutton">
                                      <input type="submit" name="RP" value="Remove Photo" class="signupbutton">
									  <input type="hidden" name="id" value="<?php echo $id?>">
									  <input type="hidden" name="pid" value="<?php echo $value['nPhoto_Id']?>">
                                    </td>
                  </tr>
				<?php 			}//end foreach
					 		}//end if
						}//end first if
				?>
              </table>
				<?php if(!empty($arrImages))
					  {
				?>
                <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="82%">&nbsp;</td>
                    <td width="18%"><table width="100%"  border="0" cellspacing="2" cellpadding="0">
                        <tr align="center" class="textbox">
                          <td><?php echo $objP->links;?></td>
                          </tr>
                    </table></td>
                  </tr>
                </table><?php }//end if?>
                <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td align="right"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td>&nbsp;</td>
                      </tr>
                    </table>
                      <?php if ($objDB) 
					  { 
					?>
                      <table width="100%"  border="0" cellspacing="0" cellpadding="5">
                      <tr>
                        <td align="center"><table width="16%"  border="0" cellspacing="0" cellpadding="0">
                            <tr>
							 <?php
									if($totalImgCount<$siteTitle['maximgupload'])
									{
							 ?>
                              <td><input name="ANP" type="submit" style="margin-right:20px;" class="loginbutton" value="Add New Photo" onClick="change_photo(<?php echo $id?>, 0);"><input type="hidden" name="page" value="<?php echo $page?>">
                                        <input type="hidden" name="id" value="<?php echo $id?>">
								    </td><?php }//end if?>
							  <?php if ($id > 0) { ?>
                              <td><input name="BackNow" type="submit" class="back-btn" value="Back"></td>
							  <?php }//end if?>
                              </tr>
                        </table></td>
                      </tr>
                    </table>
					<?php 		
						}//end first if
				?></td>
                  </tr>
                </table></td>
            </tr>
          </table></form>
			</div>
			</td>
          </tr>
        </table>
		</td>
        </tr>
    </table>      
    </td>
  </tr>
</table>
<?php include_once('bottomhtml.php');?>