<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts Multicart                     |
// +----------------------------------------------------------------------+
// | Authors: Programmer<programmer@armia.com>        		              |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems, Inc and iScripts.com ï¿½ 2005                |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------+
// | 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.                                                       |
// +----------------------------------------------------------------------+
?>
<?php
include "../includes/config.php";
include "../includes/session.php";
include "../includes/functions.php";
include_once('../includes/S3.php');
include('../includes/class.upload.php');
if (get_magic_quotes_gpc()) {
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}

if(isset( $_SESSION["sess_adminname"]) and $_SESSION["sess_adminname"]!= ""){
	$adminname = $_SESSION["sess_adminname"];
}else{
	header("Location:login.php");
	exit;
}

if (isset($_GET["artistid"]) and $_GET["artistid"] != "") {
    $artistid = $_GET["artistid"];
} else if (isset($_POST["artistid"]) and $_POST["artistid"] != "") {
    $artistid = $_POST["artistid"];
}

if(isset( $_POST["portfolioid"]) and $_POST["portfolioid"] != ""){
	$portfolioid = $_POST["portfolioid"];
}
$txtArtistDescription = trim($_POST["txtArtistDescription"]);


if(isset($_POST["btnSaveChanges"])){
	$message = "";
	if (!isNotNull($txtArtistDescription)) {
        $message .= SELLER_DESC_TEXT." <br>";
    }

	$portfoliodir = "../portfolios/";

	$chkDeleteArtistPhoto = $_POST["chkDeleteArtistPhoto"];
	$chkDeleteSampleWork1 = $_POST["chkDeleteSampleWork1"];
	$chkDeleteSampleWork2 = $_POST["chkDeleteSampleWork2"];
	$chkDeleteSampleWork3 = $_POST["chkDeleteSampleWork3"];
	$chkDeleteSampleWork4 = $_POST["chkDeleteSampleWork4"];
	$chkDeleteSampleWork5 = $_POST["chkDeleteSampleWork5"];
	$chkDeleteSampleWork6 = $_POST["chkDeleteSampleWork6"];

    $artistphoto = $_FILES['artistphoto'];
    $artistphotoname 	= $_FILES['artistphoto']['name'];
    $artistphototype 	= $_FILES['artistphoto']['type'];
	$artistfilename 	= $_FILES['artistphoto']['name'];
	$artisttempname		= $_FILES['artistphoto']['tmp_name'];

	$artistphotodest = $portfoliodir . $artistphotoname;

	$samplework1 = $_FILES['samplework1'];
    $samplework1name = $_FILES['samplework1']['name'];
    $samplework1type = $_FILES['samplework1']['type'];

	$samplework1filename = $_FILES['samplework1']['name'];
	$samplework1tempname = $_FILES['samplework1']['tmp_name'];
	$samplework1dest = $portfoliodir . $samplework1name;


	$samplework2 = $_FILES['samplework2'];
    $samplework2name = $_FILES['samplework2']['name'];
    $samplework2type = $_FILES['samplework2']['type'];

	$samplework2filename = $_FILES['samplework2']['name'];
	$samplework2tempname = $_FILES['samplework2']['tmp_name'];
	$samplework2dest = $portfoliodir . $samplework2name;

	$samplework3 = $_FILES['samplework3'];
    $samplework3name = $_FILES['samplework3']['name'];
    $samplework3type = $_FILES['samplework3']['type'];

	$samplework3filename = $_FILES['samplework3']['name'];
	$samplework3tempname = $_FILES['samplework3']['tmp_name'];
	$samplework3dest = $portfoliodir . $samplework3name;

	$samplework4 = $_FILES['samplework4'];
    $samplework4name = $_FILES['samplework4']['name'];
    $samplework4type = $_FILES['samplework4']['type'];

	$samplework4filename = $_FILES['samplework4']['name'];
	$samplework4tempname = $_FILES['samplework4']['tmp_name'];
	$samplework4dest = $portfoliodir . $samplework4name;

	$samplework5 = $_FILES['samplework5'];
    $samplework5name = $_FILES['samplework5']['name'];
    $samplework5type = $_FILES['samplework5']['type'];

	$samplework5filename = $_FILES['samplework5']['name'];
	$samplework5tempname = $_FILES['samplework5']['tmp_name'];
	$samplework5dest = $portfoliodir . $samplework5name;

	$samplework6 = $_FILES['samplework6'];
    $samplework6name = $_FILES['samplework6']['name'];
    $samplework6type = $_FILES['samplework6']['type'];

	$samplework6filename = $_FILES['samplework6']['name'];
	$samplework6tempname = $_FILES['samplework6']['tmp_name'];
	$samplework6dest = $portfoliodir . $samplework6name;

        
	if ($artistphotoname != "") {
        if (!isValidWebImageType($artistphototype,$artistfilename,$artisttempname)) {
            $message .= INVALID_PHOTO_TEXT . "<br>";
            $error = true;
        } else {
            if (file_exists($artistphotodest)) {
                $message .= RENAME_PHOTO_TEXT . "<br>";
                $error = true;
            }
        }
    }else{
		$txtArtistPhoto = $_POST["txtArtistPhoto"];
		if(!isNotNull($portfolioid)){
			if($artistphotoname == ""){
				$message .= PHOTO_REQ_TEXT . "<br>";
        		$error = true;
			}
		}

	}



	if (!is_readable($portfoliodir) || !is_writable($portfoliodir) || !is_executable($portfoliodir)) {
        $error = true;
        $message .= PERMISSION_CHANGE_TEXT."<br>";
    }


	if($message == ""){
		if($artistphotoname != ""){
                    
             $artistphotodest = $portfoliodir . $artistphotoname;
             $sellerProfilePhotoName = substr($artistphotoname, 0, strrpos($artistphotoname, '.'));

            $handle = new Upload($_FILES['artistphoto']);

            if ($handle->uploaded) {
                $handle->image_resize = true;
                $handle->image_x = 250;
                $handle->image_y = 240;
                $handle->file_new_name_body = $sellerProfilePhotoName;
                $handle->Process($portfoliodir);
                $artistphotoname = $handle->file_dst_name;
                $imagepath             = "../portfolios/".$artistphotoname;
                moveImageToCDN($imagepath,'portfolios/'.$artistphotoname);
            
                
            }
			
			
		}
		
		if(isset($portfolioid) and $portfolioid != ""){
			$sql = "SELECT ap.* FROM ".$tableprefix."artists a INNER JOIN ".$tableprefix."artist_portfolios ap ON a.artist_id = ap.artist_id  WHERE a.artist_id = '".addslashes($artistid)."' AND ap.artist_portfolio_id = '".addslashes($portfolioid)."' ";
			$res = mysql_query($sql);
			if(mysql_num_rows($res) > 0 ){
				$row= mysql_fetch_array($res);
				$txtArtistPhoto= $row["artist_photo"];
				$txtArtistSampleWork1= $row["artist_sample_work_1"];
				$txtArtistSampleWork2= $row["artist_sample_work_2"];
				$txtArtistSampleWork3= $row["artist_sample_work_3"];
				$txtArtistSampleWork4= $row["artist_sample_work_4"];
				$txtArtistSampleWork5= $row["artist_sample_work_5"];
				$txtArtistSampleWork6= $row["artist_sample_work_6"];
			}

			$sql = "UPDATE " . $tableprefix . "artist_portfolios SET
				artist_description = '".addslashes($txtArtistDescription)."'
				";
			if(($artistphotoname !="") || ($chkDeleteArtistPhoto == "on")){
				$sql .= " ,artist_photo = '".addslashes($artistphotoname)."' ";
				$artistphotoold = $portfoliodir . $txtArtistPhoto;
				@unlink($artistphotoold);
				deleteCDNImage($artistphotoold);
			}
			

			 $sql .=	" WHERE artist_portfolio_id= '".addslashes($portfolioid)."' AND artist_id = '".addslashes($artistid)."' ";
			mysql_query($sql);
			$success_message = SELLER_PORTFOLIO_UPDATE_TEXT;
		}else{
			$sql = "INSERT INTO " . $tableprefix . "artist_portfolios
					(
					artist_id,
					artist_description,
					artist_photo
					
					)VALUES(
					'".addslashes($artistid)."',
					'".addslashes($txtArtistDescription)."',
					'".addslashes($artistphotoname)."'
					
					)";
			mysql_query($sql);
			$portfolioid = mysql_insert_id();
			$success_message = SELLER_PORTFOLIO_CREATE_TEXT;
		}

		//mysql_query($sql);

	}else{
		$message = "<br>".MSG_CORRECT_THE_ERRORS."<br>" . $message;
	}
}


$sql = "SELECT ap.*,a.artist_name FROM ".$tableprefix."artists a INNER JOIN ".$tableprefix."artist_portfolios ap ON a.artist_id = ap.artist_id  WHERE a.artist_id = '".addslashes($artistid)."' ";
$res = mysql_query($sql);
if(mysql_num_rows($res) > 0 ){
	$row= mysql_fetch_array($res);
	$portfolioid = $row["artist_portfolio_id"];
	$txtArtistDescription = $row["artist_description"];
	$txtArtistPhoto= $row["artist_photo"];
	$txtArtistSampleWork1= $row["artist_sample_work_1"];
	$txtArtistSampleWork2= $row["artist_sample_work_2"];
	$txtArtistSampleWork3= $row["artist_sample_work_3"];
	$txtArtistSampleWork4= $row["artist_sample_work_4"];
	$txtArtistSampleWork5= $row["artist_sample_work_5"];
	$txtArtistSampleWork6= $row["artist_sample_work_6"];
        $txtUserName    =    $row["artist_name"];
}

include "../includes/htmltop.php";
?>
<script type="text/javascript" src="<?php echo SITE_URL?>/ckeditor/ckeditor.js"></script>
<script type="text/javascript">
    window.onload = function()
    {
       // CKEDITOR.replace( 'txtArtistDescription' );
        var editor =  CKEDITOR.replace( 'txtArtistDescription'
        , {
	filebrowserBrowseUrl : '<?php echo SITE_URL ?>/ckeditor/ckfinder/ckfinder.html',
	filebrowserImageBrowseUrl : '<?php echo SITE_URL ?>/ckeditor/ckfinder/ckfinder.html?type=Images',
	filebrowserFlashBrowseUrl : '<?php echo SITE_URL ?>/ckeditor/ckfinder/ckfinder.html?type=Flash',
	filebrowserUploadUrl : '<?php echo SITE_URL ?>/ckeditor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
	filebrowserImageUploadUrl : '<?php echo SITE_URL ?>/ckeditor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
	filebrowserFlashUploadUrl : '<?php echo SITE_URL ?>/ckeditor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
        });
            CKFinder.setupCKEditor( editor, '<?php echo SITE_URL ?>/ckeditor/ckfinder/' );
        
    };
</script>    
<body>
<center>

		<div align="left" id="layout">




				<!--header area start -->
<?php

	include_once("../includes/topheader_admin.php")

?>

				<!--header area end -->




				<div align="left" class="main_body">
				<!--main body start -->



<?php
		include_once("../includes/admintopmenu.php")
?>
		<form name="frmPortfolio" action="<?php echo $_SERVER["PHP_SELF"]?>" method="POST" enctype="multipart/form-data">
			<input type="hidden" name="artistid" value="<?php echo htmlentities($artistid);?>">
			<input type="hidden" name="portfolioid" value="<?php echo htmlentities($portfolioid);?>">
			<input type="hidden" name="txtArtistPhoto" value="<?php echo htmlentities($txtArtistPhoto);?>">

			<div align="left" class="content_area">
			<!--content area start -->
			<div align="left" class="page_title"><?php echo UPLOAD_PORTFOLIO_TEXT;?></div>
			<div align="center" class="text_information grey_tr"><?php echo $message?></div>
                        <div align="center" class="text_information_success grey_tr"><?php echo $success_message; ?></div>
                    <br>

			<div align="left">



			<table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_table">
			<tr>
				<td colspan="3" align="right"><span class="required">*</span><?php echo MANDATORY_FIELDS;?></td>
			</tr>

			<tr><td colspan="3">&nbsp;</td></tr>
			<tr><td align="left" valign=top width="28%"><?php echo SELLER_DESC;?>&nbsp;<span class="required">*</span></td><td >&nbsp;</td>
				<td valign=top align="left">
					<textarea name="txtArtistDescription" id="txtArtistDescription" class="textbox" rows="8" cols="80" ><?php echo  ($txtArtistDescription)?></textarea>
				</td>
			</tr>
			<tr><td colspan="3">&nbsp;</td></tr>
			<tr><td align="left" valign=top ><?php echo SELLER_PHOTO;?>&nbsp;<span class="required">*</span></td><td >&nbsp;</td>
				<td valign=top align="left" class="blackbartextCopy"><input type="file" name="artistphoto" id="artistphoto" size="40" class="textbox" >&nbsp;<?php echo BEST_SIZE_TEXT;?>
				<div align="left">
				<?php
				if(isNotNull($txtArtistPhoto)){?>
				<?php echo EXISTING_TEXT;?>  <font color='RED'><?php echo $txtArtistPhoto?></font>
				<br>
				<input type="checkbox" class="checkbox" name="chkDeleteArtistPhoto">&nbsp;<?php echo DELETE_EXISTING_TEXT;?>
				<br>
				<?php }?>

				</div>
				</td>
			</tr>
			<tr><td colspan="3">&nbsp;</td></tr>
			
			

			<?php
			if($portfolioid != ""){ 
                            
                              if ($enable_seller_friendly == "Y") {
                                    $sellerLink =  SITE_URL . "/" . $txtUserName;
                                } else {
                                        $sellerLink = SITE_URL . "/showportfolio.php?artistid=" .$artistid;
                                }
                            
                            ?>
                        
                        
				<tr><td colspan="3" align="left"><a class=links href="../showportfolio.php?artistid=<?php echo $artistid;?>" target="_blank" ><b><?php echo VIEW_PORT_TEXT;?></b></a></td></tr>
			<?php }
			?>
		<tr><td colspan="3">&nbsp;</td></tr>
			<tr><td colspan="3" align="center">
				<input type="submit" value="<?php echo BTN_SAVE_CHANGES;?>" name="btnSaveChanges" class="button" >
				&nbsp;&nbsp;<input type="button" value="<?php echo BTN_BACK_SELLER_DETAILS;?>" name="btnBack" class="button"  onClick="window.location.href='editartist.php?artistid=<?php echo $artistid;?>';" >
				</td>
			</tr>
		</table>
	</form>


                             														</div>


				<!--content area end-->

				</div>

				</form>

					<div align="left" class="clear_float"><img src="../images/clear.gif" alt="" width="1" height="1" /></div>
				<!--main body end -->
				</div>


<?php

	include "../includes/footer.php";
?>



