<?php
(@include ('../dt_page/lic.php')) or die("<p style='font-family:Arial, Helvetica, sans-serif; margin-top:80px; font-size:16px; line-height:180%; letter-spacing:2px;' align='center'><img src='https://primadesain.com/images/block.png' width='90' height='90' /></br></br>You not have a license to use this script on this domain,<br>Please contact us to purchase a license.<br><strong><a href='http://www.primadesain.com'>www.primadesain.com</a></strong></p><br><p style='font-family:Arial, Helvetica, sans-serif; margin-top:30px; font-size:12px; line-height:180%; letter-spacing:2px;' align='center'>&copy;2009 - ".date("Y")." www.primadesain.com</p>");
//$lic=$license;if(!$lic){echo "<p style='font-family:Arial, Helvetica, sans-serif; margin-top:80px; font-size:16px; line-height:180%; letter-spacing:2px;' align='center'><img src='https://primadesain.com/images/block.png' width='90' height='90' /></br></br>You not have a license to use this script on this domain,<br>Please contact us to purchase a license.<br><strong><a href='http://www.primadesain.com'>www.primadesain.com</a></strong></p><br><p style='font-family:Arial, Helvetica, sans-serif; margin-top:30px; font-size:12px; line-height:180%; letter-spacing:2px;' align='center'>&copy;2009 - ".date("Y")." www.primadesain.com</p>";}$svr=$_SERVER['SERVER_NAME'];$c=curl_init();curl_setopt($c,CURLOPT_URL,"http://www.primadesain.com/verifylicenses.php");curl_setopt($c,CURLOPT_TIMEOUT,30);curl_setopt($c,CURLOPT_POST,1);curl_setopt($c,CURLOPT_RETURNTRANSFER,1);$postfields='svr='.$svr.'&lic='.$lic;curl_setopt($c,CURLOPT_POSTFIELDS,$postfields);$result=curl_exec($c);if($result=="fail"){echo "<p style='font-family:Arial, Helvetica, sans-serif; margin-top:80px; font-size:16px; line-height:180%; letter-spacing:2px;' align='center'><img src='https://primadesain.com/images/block.png' width='90' height='90' /></br></br>You not have a license to use this script on this domain,<br>Please contact us to purchase a license.<br><strong><a href='http://www.primadesain.com'>www.primadesain.com</a></strong></p><br><p style='font-family:Arial, Helvetica, sans-serif; margin-top:30px; font-size:12px; line-height:180%; letter-spacing:2px;' align='center'>&copy;2009 - ".date("Y")." www.primadesain.com</p>";die();}
if (basename($_SERVER['SCRIPT_FILENAME']) == basename(__FILE__)){
echo "<p align=center><br><br><br><br><br><br><font size=\"6\" color=\"#FF0000\">ILLEGAL ACCESS !!";
echo "<meta http-equiv=\"refresh\" content=\"2; url=../index.php\">";
exit();} 
?>
 <div class="row">
            <div class="col-md-12">
                <h1 class="page-header">
                    <img src="../themes/img/settings.png" alt="register" class="header-icon" width="30">
                    Foto Profile
                </h1>
            </div>
        </div>

<?php
if($db->dataku("status", $user_session) == 0 || $db->dataku("blokir", $user_session) == 1) {
echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'></button>".$LANG["status0"]."</div>";
}else{
?>
<div class="row">
            	
                
                
                
                             <div class="col-md-9">
                
                
				  <div class="panel panel-inverse">
                        <div class="panel-heading bg-grey">
                            <h4 class="text-white">Foto Profile</h4>
                        </div>
                        <div class="panel-body">

<?php
	if(isset($_POST['uploadfotoprofil'])){
	
	
	
	$target_dir = "images/";
    $target_file = $target_dir . basename($_FILES["uploadfile"]["name"]);
    $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
	
	if(!empty($_FILES['uploadfile']['name']) && $imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" && $imageFileType != "PNG" && $imageFileType != "JPG") {
   header("location: ?go=ftprofile&result=type_error");
	exit;
  } else{
	
	
	$img = $_FILES['uploadfile'];
	$type = substr($img['name'], strrpos($img['name'], '.') + 1);
	if($img['size'] > 1000000) {
		header("location: ?go=ftprofile&result=size_error");
	exit;
	} else {
		
		
		$time = date("Ymd_His");
        $sess = md5(substr(str_shuffle(str_repeat("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz", 64)), 0, 24));
		if(!empty($_FILES['uploadfile']['name'])){
		$namex = substr($img['name'], 0, strrpos($img['name'], '.'));	
		$special = "iklan-".$userid."_a";
		$new_file_name = str_replace($namex,'',$special);
		$name  = $new_file_name.'_'.$sess.'_'.$time;
		$thumbName		= $name.'.'.$type;
		}
		if($type == "gif"){
			$imgObj = imagecreatefromgif($img['tmp_name']);
		} else if($type == "png"){
			$imgObj = imagecreatefrompng($img['tmp_name']);
		} else if($type == "jpeg"){
			$imgObj = imagecreatefromjpeg($img['tmp_name']);
		} else if($type == "JPG"){
			$imgObj = imagecreatefromjpeg($img['tmp_name']);
		} else if($type == "PNG"){

			$imgObj = imagecreatefrompng($img['tmp_name']);
		} else {
			$imgObj = imagecreatefromjpeg($img['tmp_name']);
		}
		$width = imageSX($imgObj);
		$height = imageSY($imgObj);
		
		if(!empty($_FILES['uploadfile']['name']) && !$width || !empty($_FILES['uploadfile']['name']) && !$height) {
    header("location: ?go=ftprofile&result=file_error");
	exit;
		}else{
		if($width > 1000) {
		 	$height = $height * (1000 / $width);
		 	$width = 1000;	
		}
		$thumbWidth = $width;
		$thumbHeight = $height;
		$newThumb = imagecreatetruecolor($thumbWidth, $thumbHeight);
		imagecopyresampled($newThumb, $imgObj, 0, 0, 0, 0, $thumbWidth, $thumbHeight, imageSX($imgObj), imageSY($imgObj));
		if($type == "gif") {
			imagegif($newThumb, 'images/'.$thumbName);
		} else if($type == "png") {
			imagejpeg($newThumb, 'images/'.$thumbName);
		} else {
			imagejpeg($newThumb, 'images/'.$thumbName);
		}    
		imagedestroy($imgObj);
		imagedestroy($newThumb);
		
		$fotolama = $_POST['fotolama'];
		if(!empty($thumbName)){ 
		$foto = $thumbName; 
		unlink("images/$fotolama");
		}else{
		$foto = $fotolama; 
		}
		$myquery=mysql_query("UPDATE member SET foto='$foto' WHERE username='$user_session'") or die(mysql_error());
		

	header("location: ?go=ftprofile&result=success");
	exit;
	}
}
  }
} else {
?>	

<?php
 if(isset($_GET['result'])&&$_GET['result']=="noupload"){
echo "<div class='alert alert-success alert-dismissable'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'></button>Photo profile not updated!</div>";
}
?>  
<?php
 if(isset($_GET['result'])&&$_GET['result']=="success"){
echo "<div class='alert alert-success alert-dismissable'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'></button>Photo profile has been updated!</div>";
}
?>  
<?php
 if(isset($_GET['result'])&&$_GET['result']=="size_error"){
echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'></button>Upload max size only 1 MB</div>";
}
?>  
<?php
 if(isset($_GET['result'])&&$_GET['result']=="type_error"){
echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'></button>Upload only file pdf, jpg, png, gif.</div>";
}
?>  
<?php
 if(isset($_GET['result'])&&$_GET['result']=="file_error"){
echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'></button>Upload only file pdf, jpg, png, gif.</div>";
}
?>  


<p><?php echo $LANG["fotoproinfo"]?></p>
<p><?php echo $LANG["fotoproinfo2"]?></p>
<ul style="margin-left:30px">
       <li><font style="font-size:10pt"><?php echo $LANG["fotoproinfo2a"]?></font></li>
        <li><font style="font-size:10pt"><?php echo $LANG["fotoproinfo2b"]?></font></li>
        <li><font style="font-size:10pt"><?php echo $LANG["fotoproinfo2c"]?></font></li>
      </ul>
<br />
<?php
	$adafoto = $db->dataku("foto", $user_session);
	$dirfoto = "./images/$adafoto";
	if (!empty($adafoto) && (file_exists($dirfoto))){
		$gambar = "<a href='./images/".$adafoto."' class='highslide' onclick='return hs.expand(this)'><img src='./images/$adafoto' width='100'></a>";
		}
	else
		{
		$gambar = "<img src='../images/no_image.png' width='100'>";
		} 	
		?>
        
        <?php echo $gambar;?><br /><br />
        
        
												
                                                <form action="" method="post"  enctype="multipart/form-data" name="form1x" id="form1x" onsubmit="return Validate(this);">
                                                <input name="fotolama" type="hidden" value="<?php echo $adafoto;?>">
													
                                                    
                                                      <div class="controls-row">

            <label>Select image</label>
<input name="uploadfile" type="file" id="uploadfile" required='required'>                                      

          </div>
                                                    
                                                    
                                                    
                                                    <div>

           &nbsp;

          </div>
          <div>
        
           <button type="submit" class="btn btn-primary" name="uploadfotoprofil"><i class="fa fa-upload"></i>&nbsp;Upload</button>
          </div>
														
												</form>


<br /><i>Upload only file jpg, png, gif. Max size upload 1 MB.</i>

<script type="text/javascript">
var _validFileExtensions = [".jpg", ".jpeg", ".gif", ".png"];

function Validate(oForm) {
    var arrInputs = oForm.getElementsByTagName("input");
    for (var i = 0; i < arrInputs.length; i++) {
        var oInput = arrInputs[i];
        if (oInput.type == "file") {
            var sFileName = oInput.value;
            if (sFileName.length > 0) {
                var blnValid = false;
                for (var j = 0; j < _validFileExtensions.length; j++) {
                    var sCurExtension = _validFileExtensions[j];
                    if (sFileName.substr(sFileName.length - sCurExtension.length, sCurExtension.length).toLowerCase() == sCurExtension.toLowerCase()) {
                        blnValid = true;
                        break;
                    }
                }

                if (!blnValid) {
                    alert("Maaf, " + sFileName + " <?php echo $LANG["fotoproinfo2d"]?> : " + _validFileExtensions.join(", "));
					window.location.reload();
                    return false;
                }
            }
        }
    }

    return true;
}
</script>	




<?php
}
} 
?>    
</div></div></div></div>