<?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";

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 ($samplework1name != "") {
        if (!isValidWebImageType($samplework1type,$samplework1filename,$samplework1tempname)) {
            $message .= SAMPLE_WORK1_INVALID . "<br>";
            $error = true;
        } else {
            if (file_exists($samplework1dest)) {
                $message .= SAMPLE_WORK1_EXISTS_RENAME . "<br>";
                $error = true;
            }
        }
    }

	if ($samplework2name != "") {
        if (!isValidWebImageType($samplework2type,$samplework2filename,$samplework2tempname)) {
            $message .= SAMPLE_WORK2_INVALID . "<br>";
            $error = true;
        } else {
            if (file_exists($samplework2dest)) {
                $message .= SAMPLE_WORK2_EXISTS_RENAME . "<br>";
                $error = true;
            }
        }
    }

	if ($samplework3name != "") {
        if (!isValidWebImageType($samplework3type,$samplework3filename,$samplework3tempname)) {
            $message .= SAMPLE_WORK3_INVALID . "<br>";
            $error = true;
        } else {
            if (file_exists($samplework3dest)) {
                $message .= SAMPLE_WORK3_EXISTS_RENAME . "<br>";
                $error = true;
            }
        }
    }
	if ($samplework4name != "") {
        if (!isValidWebImageType($samplework4type,$samplework4filename,$samplework4tempname)) {
            $message .= SAMPLE_WORK4_INVALID . "<br>";
            $error = true;
        } else {
            if (file_exists($samplework4dest)) {
                $message .= SAMPLE_WORK4_EXISTS_RENAME . "<br>";
                $error = true;
            }
        }
    }
	if ($samplework5name != "") {
        if (!isValidWebImageType($samplework5type,$samplework5filename,$samplework5tempname)) {
            $message .= SAMPLE_WORK5_INVALID . "<br>";
            $error = true;
        } else {
            if (file_exists($samplework5dest)) {
                $message .= SAMPLE_WORK5_EXISTS_RENAME . "<br>";
                $error = true;
            }
        }
    }
	if ($samplework6name != "") {
        if (!isValidWebImageType($samplework6type,$samplework6filename,$samplework6tempname)) {
            $message .= SAMPLE_WORK6_INVALID . "<br>";
            $error = true;
        } else {
            if (file_exists($samplework6dest)) {
                $message .= SAMPLE_WORK6_EXISTS_RENAME . "<br>";
                $error = true;
            }
        }
    }

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


	if($message == ""){
		if($artistphotoname != ""){
			move_uploaded_file($_FILES['artistphoto']['tmp_name'], $artistphotodest);
		}
		if($samplework1name != ""){
			move_uploaded_file($_FILES['samplework1']['tmp_name'], $samplework1dest);
		}
		if($samplework2name != ""){
			move_uploaded_file($_FILES['samplework2']['tmp_name'], $samplework2dest);
		}
		if($samplework3name != ""){
			move_uploaded_file($_FILES['samplework3']['tmp_name'], $samplework3dest);
		}
		if($samplework4name != ""){
			move_uploaded_file($_FILES['samplework4']['tmp_name'], $samplework4dest);
		}
		if($samplework5name != ""){
			move_uploaded_file($_FILES['samplework5']['tmp_name'], $samplework5dest);
		}
		if($samplework6name != ""){
			move_uploaded_file($_FILES['samplework6']['tmp_name'], $samplework6dest);
		}
		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);
			}
			if(($samplework1name !="")||($chkDeleteSampleWork1 == "on")){
				$sql .= " ,artist_sample_work_1 = '".addslashes($samplework1name)."' ";
				$samplephotoold1 = $portfoliodir . $txtArtistSampleWork1;
				@unlink($samplephotoold1);
			}
			if(($samplework2name !="")||($chkDeleteSampleWork2 == "on")){
				$sql .= " ,artist_sample_work_2 = '".addslashes($samplework2name)."' ";
				$samplephotoold2 = $portfoliodir . $txtArtistSampleWork2;
				@unlink($samplephotoold2);
			}
			if(($samplework3name !="")||($chkDeleteSampleWork3 == "on")){
				$sql .= " ,artist_sample_work_3 = '".addslashes($samplework3name)."' ";
				$samplephotoold3 = $portfoliodir . $txtArtistSampleWork3;
				@unlink($samplephotoold3);
			}
			if(($samplework4name !="")||($chkDeleteSampleWork4 == "on")){
				$sql .= " ,artist_sample_work_4 = '".addslashes($samplework4name)."' ";
				$samplephotoold4 = $portfoliodir . $txtArtistSampleWork4;
				@unlink($samplephotoold4);
			}
			if(($samplework5name !="")||($chkDeleteSampleWork5 == "on")){
				$sql .= " ,artist_sample_work_5 = '".addslashes($samplework5name)."' ";
				$samplephotoold5 = $portfoliodir . $txtArtistSampleWork5;
				@unlink($samplephotoold5);
			}
			if(($samplework6name !="")||($chkDeleteSampleWork6 == "on")){
				$sql .= " ,artist_sample_work_6 = '".addslashes($samplework6name)."' ";
				$samplephotoold6 = $portfoliodir . $txtArtistSampleWork6;
				@unlink($samplephotoold6);
			}

			$sql .=	" WHERE artist_portfolio_id= '".addslashes($portfolioid)."' AND artist_id = '".addslashes($artistid)."' ";
			mysql_query($sql);
			$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();
			$message = SELLER_PORTFOLIO_CREATE_TEXT;
		}

		//mysql_query($sql);

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


$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)."' ";
$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"];
}

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


<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>
            <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" 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>
			<!--<tr><td align="left" valign=top><?php echo SAMPLE_WORK1_TEXT;?>&nbsp;</td><td >&nbsp;</td>
				<td valign=top align="left" class="blackbartextCopy"><input type="file" name="samplework1" id="samplework1" size="40" class="textbox" >&nbsp;<?php echo BEST_SIZE_TEXT;?>
				<div align="left">
				<?php
				if(isNotNull($txtArtistSampleWork1)){?>
				<?php echo EXISTING_TEXT;?> <font color='RED'><?php echo $txtArtistSampleWork1?></font>
				<br>
				<input type="checkbox" class="checkbox" name="chkDeleteSampleWork1">&nbsp;<?php echo DELETE_EXISTING_TEXT;?>
				<br>
				<?php  }?>
				</div>
				</td>
			</tr>
			<tr><td colspan="3">&nbsp;</td></tr>
			<tr><td align="left" valign=top><?php echo SAMPLE_WORK2_TEXT;?>&nbsp;</td><td >&nbsp;</td>
				<td valign=top align="left" class="blackbartextCopy"><input type="file" name="samplework2" id="samplework2" size="40" class="textbox" >&nbsp;<?php echo BEST_SIZE_TEXT;?>
				<div align="left">
				<?php
				if(isNotNull($txtArtistSampleWork2)){?>
				<?php echo EXISTING_TEXT;?> <font color='RED'><?php echo $txtArtistSampleWork2?></font>
				<br>
				<input type="checkbox" class="checkbox" name="chkDeleteSampleWork2">&nbsp;<?php echo DELETE_EXISTING_TEXT;?>
				<br>
				<?php  }?>
				</div>
				</td>
			</tr>
			<tr><td colspan="3">&nbsp;</td></tr>
			<tr><td align="left" valign=top><?php echo SAMPLE_WORK3_TEXT;?>&nbsp;</td><td >&nbsp;</td>
				<td valign=top align="left" class="blackbartextCopy"><input type="file" name="samplework3" id="samplework34" size="40" class="textbox" >&nbsp;<?php echo BEST_SIZE_TEXT;?>
				<div align="left">
				<?php
				if(isNotNull($txtArtistSampleWork3)){?>
				<?php echo EXISTING_TEXT;?> <font color='RED'><?php echo $txtArtistSampleWork3?></font>
				<br>
				<input type="checkbox" class="checkbox" name="chkDeleteSampleWork3">&nbsp;<?php echo DELETE_EXISTING_TEXT;?>
				<br>
				<?php  }?>
				</div>
				</td>
			</tr>
			<tr><td colspan="3">&nbsp;</td></tr>
			<tr><td align="left" valign=top><?php echo SAMPLE_WORK4_TEXT;?>&nbsp;</td><td >&nbsp;</td>
				<td valign=top align="left" class="blackbartextCopy"><input type="file" name="samplework4" id="samplework4" size="40" class="textbox" >&nbsp;<?php echo BEST_SIZE_TEXT;?>
				<div align="left">
				<?php
				if(isNotNull($txtArtistSampleWork4)){?>
				<?php echo EXISTING_TEXT;?> <font color='RED'><?php echo $txtArtistSampleWork4?></font>
				<br>
				<input type="checkbox" class="checkbox" name="chkDeleteSampleWork4">&nbsp;<?php echo DELETE_EXISTING_TEXT;?>
				<br>
				<?php  }?>
				</div>
				</td>
			</tr>
			<tr><td colspan="3">&nbsp;</td></tr>
			<tr><td align="left" valign=top><?php echo SAMPLE_WORK5_TEXT;?>&nbsp;</td><td >&nbsp;</td>
				<td valign=top align="left" class="blackbartextCopy"><input type="file" name="samplework5" id="samplework5" size="40" class="textbox" >&nbsp;<?php echo BEST_SIZE_TEXT;?>
				<div align="left">
				<?php
				if(isNotNull($txtArtistSampleWork5)){?>
				<?php echo EXISTING_TEXT;?> <font color='RED'><?php echo $txtArtistSampleWork5?></font>
				<br>
				<input type="checkbox" class="checkbox" name="chkDeleteSampleWork5">&nbsp;<?php echo DELETE_EXISTING_TEXT;?>
				<br>
				<?php }?>
				</div>
				</td>
			</tr>
			<tr><td colspan="3">&nbsp;</td></tr>
			<tr><td align="left" valign=top><?php echo SAMPLE_WORK6_TEXT;?>&nbsp;</td><td >&nbsp;</td>
				<td valign=top align="left" class="blackbartextCopy"><input type="file" name="samplework6" id="samplework6" size="40" class="textbox" >&nbsp;<?php echo BEST_SIZE_TEXT;?>
				<div align="left">
				<?php
				if(isNotNull($txtArtistSampleWork6)){?>
				<?php echo EXISTING_TEXT;?> <font color='RED'><?php echo $txtArtistSampleWork6?></font>
				<br>
				<input type="checkbox" class="checkbox" name="chkDeleteSampleWork6">&nbsp;<?php echo DELETE_EXISTING_TEXT;?>
				<br>
				<?php }?>
				</div>
				</td>
			</tr>-->
			<tr><td colspan="3">&nbsp;</td></tr>

			<?php
			if($portfolioid != ""){ ?>
				<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";
?>



