<?php 
/*
##################################################################
#                       PHP 4&5 MySQL 4&5                        #
##################################################################
#           Copyright (c) 2004-2008 Armia Systems Inc            #
##################################################################
#               This file is part of Cybermatch site             #
##################################################################
#    Developed By: simi (simi@armia.com)                         #

##################################################################
#               Developed On:   03-04-2008                       #
##################################################################
#               Modified By:                                     #
##################################################################
#               Modified On:                                     #
##################################################################
# This script may not be distributed, sold, given away for free  #
# to third party, or used as a part of any internet services 	 #
# such as webdesign etc.                                         #
##################################################################
*/

require_once ("config.inc.php");
require_once ("includes/userlogincheck.inc.php");
require_once ("includes/mysql.inc.php");
require_once ("includes/arrays.inc.php");
require_once ("classes/settings.class.php");
require_once ("classes/userside.class.php");
require_once ("classes/misc.class.php");

$id			= $_SESSION['user_id'];
$pid		= isset($_REQUEST['pid'])	?	trim($_REQUEST['pid'])	:	"0";


$message	= "";
$messages	= "";
$script		= "";

$arrImages	= array();
$objC		= new check();
if (!$objDB) {
    $message	= "<span style='color:red;'>Unable to Locate Database Server.</span>";
} else {
    $objU		= new userside($objDB);
    $objSU2		= new settings($objDB);
    $objM		= new misc($objDB);

    if ($_POST['RP']) {
        $message	= $objU->delete_user_image($id, $pid);
        $pid		= 0;
    }

    if (isset($_POST['SaveNow'])) {
        $objU->set_user_image(array_merge($_POST, $_FILES));

        //create allowed image type array
        $allowdImgTypes=$objSU2->select();
        $allowdImgTypes=explode(",",$allowdImgTypes['allowedimagetypes']);
        //checking uploaded image is is allowed type and also checking uploaded file is executable
        $typeChkMsg = $objSU2->CheckUploadFileType($allowdImgTypes,$_FILES['file']['type']);
       
        if(trim($typeChkMsg)=='') {            
            list($width, $height) = getimagesize($_FILES['file']['tmp_name']);
            if($width <300 || $height <300) {
                $chkMsg = "<span style='color:red;'>Upload image size should be atleast 300x300 pixels</span>";
            }
            if($chkMsg=="")
                $message	= $objU->save_user_image($id, $pid);
            else 
                $message=$chkMsg;
                
        }//end if
        else {
          $message="<span style='color:red;'>".$typeChkMsg."</span>";
        }//end else

    } else {
        $array	= $objU->get_user_image($id, $pid);
        $objU->set_user_image($array);
    }

    $arrImages	= $objU->get_user_images($id);
    if (empty($arrImages)) {
       // $message	.= "<span style='color:red;'>You haven't uploaded any photos yet.</span>";
    }

    $script		= $objU->get_script($message);
    $message	= $objU->remove_script($message);
}

                                                                
include_once ("title.inc.php");
include_once ("tophtml.inc.php");

if ($objDB) {
    //total count of images uploaded by the user
    $condition="where nUser_Id='".$_SESSION['user_id']."'";
    $totalImgCount = $objST->fetchSingleValue($objST->select_rows(TABLEPREFIX.'photos','count(nPhoto_Id) as cnt',$condition),'cnt');
} //echo '<pre>'; print_r($totalImgCount); echo '</pre>';

?>
<link href="js/block.css" rel="stylesheet" type="text/css">
<link href="js/facebox.css" media="screen" rel="stylesheet" type="text/css"/>
<script type="text/javascript"  src="js/googlefix.js"></script>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.blockUI.js"></script>
<script src="js/facebox.js" type="text/javascript"></script>
<script type="text/javascript"> 
    $(document).ready(function() {


        $('.change').click(function(){
            var answer= confirm("Do you want to delete this image?");
            if (answer== true)
            {
                $('#pid').val($(this).attr('id'));
                $('#RP').val('RP');
                $('#frm1').submit();
            }else{
                return false;
            }
        });


        $('#AP').click(function() {
            var frm	= document.frmUser;
            if (frm.vTitle.value != "")
            {
                $.extend($.blockUI.defaults.overlayCSS, { backgroundColor: 'none' });
                $.extend($.blockUI.defaults.pageMessageCSS, { width:'520px', margin:'-50px 0 0 -125px', top:'70%', left:'40%',textAlign:'left' });
                $.blockUI('<h1><img src="images/loading.gif" /> Cybermatch is processing your request.  Please be patient...</h1>');
                test();}
        });
        $('#UB').click(function() { 
            $.unblockUI();
        }); 
        function test() {
            if (validate1()) {
                $("#frmUser").submit();
                //$.unblockUI();
            }
        }
    });
    function changePic(pIdVal){
        $('#pid').val(pIdVal);
        $('#frm1').submit();
    }
</script> 
<script type="text/javascript">
    jQuery(document).ready(function($) {
        $('a[rel*=facebox]').facebox()
    })
</script>
<script language="javascript">
    function validate1()
    {
        var frm	= document.frmUser;
        if (frm.vTitle.value == "") {
            frm.vTitle.focus();
            frm.vTitle.className = 'errorinput';
            $.unblockUI();
            return false;
        } else {
            return true;
        }

    }

    function validate()
    {
        var frm	= document.frmUser;
        if (frm.vTitle.value == "") {
            alert("Please enter title of the image.");
            frm.vTitle.focus();
            frm.vTitle.className = 'errorinput';
            $.unblockUI();
            return false;
        } else {
            return true;
        }

    }
</script>

<div class="row">
	<div class="eight columns">
		<div class="search-rslts">
			<div class="row"><div class="inenr-hd"><h2>My Photos</h2></div></div>
			<div class="row">
				<h2 class="headings3">Profile Images</h2>
			</div>
			<div class="row">
				<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post" enctype="multipart/form-data" name="frmUser" id="frmUser" onSubmit="return validate();">
					<div class="newdesignforinput maintext1">
						<?php if(isset($message) && trim($message)!='') 
						{
						?>
						<div class="full_row">						
							<div class="maintext1 success"><?php echo $message;?></div>
						</div>
						 <?php }//end if?>
						<?php 
						if($totalImgCount<$siteSettings['maximgupload'] || ($pid > 0)) {
						?>
						
						<div class="full_row">
							<div class="three columns">Photo Title <span style="color: red;">*</span></div>
							<?php if ($pid > 0) { ?>
							<div class="five columns margin_R_200">
								<input name="vTitle" type="text" class="textbox txt-bx01"  value="<?php echo $objU->vTitle?>" size="30" maxlength="200">
							</div>
							<?php } else {?>
							<div class="five columns margin_R_200">
								<input name="vTitle" type="text" class="textbox txt-bx01" size="30" maxlength="200">
							</div>
							<?php }?>
						</div>
						<?php if ($pid > 0) { ?>
						
						<div class="full_row">
							<div class="three columns">Current Photo</div>
							<div class="five columns margin_R_200">
								<img src="<?php echo PROFILE_IMAGE_URL."/sthumb_".$objU->vUrl?>" width="75" height="75">
							</div>
						</div>
						<?php }//end  if ?>
						
						<div class="full_row">
							<div class="three columns">Browse Photos <span style="color: red;">*</span></div>
							<div class="five columns margin_R_200">
								<input name="file" type="file" class="textbox txt-bx01" style="width: 222px !important;">
							</div>
						</div>
						
						
						<div class="full_row">
							<div class="three columns">&nbsp;</div>
							<div class="five columns margin_R_200 gray_txt">
								<span style="color:red;">*</span>&nbsp;File extensions allowed: gif, jpg, jpeg, png<br>
								<span style="color:red;">* </span>File size limit:(
									<?php
	
									ECHO $maximagesizestringinPHP = ini_get("upload_max_filesize")."B";
									//echo $maximagesizeinPHP = $maximagesizestringinPHP * (1024 * 1024);
									?> )<br>
								<span style="color:red;">*</span> Best Size 300px X 300px (Larger size will automatically resized to 300x300 pixels)<br>
							</div>
						</div>
						
						<div class="full_row">
							<div class="three columns">&nbsp;</div>
							<div class="five columns margin_R_200">
								<input name="SaveNow" type="submit" class="loginbutton" id="AP" value="Upload Photo"><input type="hidden" name="pid" value="<?php echo $pid?>">
								<input type="hidden" name="vUrl" value="<?php echo $objU->vUrl?>">
								<input type="hidden" name="SaveNow">
							</div>
						</div>
						<?php
							}//end maximage count check if
						?>
					</div>
				</form>
				
				<?php if($totalImgCount<$siteSettings['maximgupload']) { //if ($pid > 0) {?>
				<form name="formNew" method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
					<div class="newdesignforinput maintext1">
						<div class="full_row">
							<div class="five columns margin_R_200">
								<input name="Submit" type="submit" class="loginbutton" value="Click Here to Add New Photo">
								<input type="hidden" name="pid" value="0">
							</div>
						</div>
					</div>
				</form>
						
				<?php } ?>
				
				<div class="clear"></div>
				<div class="row">
				<?php if(!empty($arrImages)) { ?>
					<form id="frm1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
					<div class="display_table">
						<div class="display_row my_photo_head">
							<div class="display_cell photo_cell_1">#</div>
							<div class="display_cell photo_cell_2">Image</div>
							<div class="display_cell photo_cell_3">Title</div>
							<div class="display_cell photo_cell_4">Action</div>
						</div>
						<?php foreach ($arrImages as $key => $value) { ?>
						<div class="display_row my_photo_cont">
							<div class="display_cell photo_cell_1"><?php echo $key+1?></div>
							<div class="display_cell photo_cell_2"><a href="<?php echo PROFILE_IMAGE_URL."/".$value['vUrl']?>" rel="facebox"><img src="<?php echo PROFILE_IMAGE_URL."/sthumb_".$value['vUrl']?>" border="0"></a></div>
							<div class="display_cell photo_cell_3"><?php echo stripslashes($value['vTitle'])?></div>
							<div class="display_cell photo_cell_4">
								<input name="CP" type="submit" class="loginbutton" value="Change" onclick="changePic(<?php echo $value['nPhoto_Id'];?>);">&nbsp;&nbsp;
								<input id="<?php echo $value['nPhoto_Id']?>" name="RPl" type="button" class="loginbutton change" value="Remove">
							</div>
						</div>
						<?php }//end for loop  ?>
												
							<input id="pid" type="hidden" name="pid" value="">
                            <input id="RP" type="hidden" name="RP" value="">
                      
						
					</div>
					</form>
					<?php }  ?>
				<div id="hide"><?php echo $script?></div>     
				</div>
				                                                    
			</div>
		</div>
	</div>
	<div class="four columns right search_result_R">
		<?php include_once ("left.inc.php");?>
	</div>
</div>

<?php include_once('bottomhtml.inc.php');?>
