<?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('../includes/class.upload.php');
include_once('../includes/S3.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_artistid"]) and $_SESSION["sess_artistid"] != "") {
    $artistid = $_SESSION["sess_artistid"];
} else {
    header("Location:login.php");
    exit;
}

if(checkArtistExpired($artistid)){
    header("Location:seller_plan_upgrade.php?sellerid=".$artistid);
    exit;
}

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

$txtArtistDescription = trim($_POST["txtArtistDescription"]);
//$txtArtistContactDetails = trim($_POST["txtArtistContactDetails"]);


if (isset($_POST["btnSaveChanges"]) ) {
    $message = "";
    if (!isNotNull($txtArtistDescription)) {
        $message .= MSG_DESC_REQ;
    }
    /* if (!isNotNull($txtArtistContactDetails)) {
      $message .= "* seller Contact Details is required! <br>";
      } */
    $portfoliodir = "../portfolios/";

    $chkDeleteArtistPhoto = $_POST["chkDeleteArtistPhoto"];

    $artistphoto = $_FILES['artistphoto'];
    /*     * ******************************************************* */
    $size = getimagesize($_FILES["artistphoto"]["tmp_name"]);
    $ratio = $size[0] / $size[1];
    $req_width = 191;
    $height = $req_width / $ratio;

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

    $artistphotodest = $portfoliodir . $artistphotoname;
    if ($artistphotoname != "") {
        if (!isValidWebImageType($artistphototype, $artistfilename, $artisttempname)) {
            $message .= MSG_INVAL_IMG;
            $error = true;
        } else {
            if (file_exists($artistphotodest)) {
                $message .= MSG_SEL_IMG;
                $error = true;
            }
        }


        if (!is_readable($portfoliodir) || !is_writable($portfoliodir) || !is_executable($portfoliodir)) {
            $error = true;
            // $message .= " * Please request admin to change the permission of 'portfolios' folder in the root to 777 <br>";
        }
    }
    if ($message == "") {
        if ($artistphotoname != "") {
            //move_uploaded_file($_FILES['artistphoto']['tmp_name'], $artistphotodest);
            //$img->GenerateThumbFile($artistphotodest,$artistphotodest,120,150);

            $sellerProfilePhotoName = substr($artistphotoname, 0, strrpos($artistphotoname, '.'));

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

            if ($handle->uploaded) {
                $handle->image_resize = true;
                $handle->image_x = 191;
                $handle->image_y = $height;
                $handle->file_new_name_body = $sellerProfilePhotoName;
                $handle->Process($portfoliodir);
                $artistphotoname = $handle->file_dst_name;
                $imagepath             = "../portfolios/".$artistphotoname;
                moveImageToCDN($imagepath,'portfolios/'.$artistphotoname);
                
            }
        }
        $rs_qr = mysql_query("select * from " . $tableprefix . "artist_portfolios	where artist_id =" . $artistid);

        $resultrows = mysql_num_rows($rs_qr);
        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"];
            }
        } // end portfolio id Check 		

        if ($resultrows > 0) { // Update port folio page if data exitsts
            $sql = "UPDATE " . $tableprefix . "artist_portfolios SET 
				artist_description = '" . addslashes($txtArtistDescription) . "'";

            if (($artistphotoname != "") || ($chkDeleteArtistPhoto == "on")) {
                $sql .= " ,artist_photo = '" . addslashes($artistphotoname) . "' ";
                $artistphotoold = $portfoliodir . $txtArtistPhoto;
                @unlink($artistphotoold);
            }
            $sql .= " WHERE artist_portfolio_id= '" . addslashes($portfolioid) . "' AND artist_id = '" . addslashes($artistid) . "' ";
            mysql_query($sql);
            $message = MSG_PORT_SUC;
        } // end if 

        if ($resultrows == 0) { // Insert data to table
            $sql_insert = "INSERT INTO " . $tableprefix . "artist_portfolios (artist_description ,artist_id ,artist_photo)
						VALUES('" . addslashes($txtArtistDescription) . "','" . addslashes($artistid) . "','" . addslashes($artistphotoname) . "')";
            $rs_insert = mysql_query($sql_insert);
            $message = MSG_PORT_SUC;;
            $portfolioid = mysql_insert_id();
        } // end if 
    } // end if message empty check  	
    else {
        $message = VAL_MSG_PLS_CORRECT . $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"];
    //$txtArtistContactDetails= $row["artist_contact_details"];
    $txtArtistPhoto = $row["artist_photo"];
}
include "../includes/htmltop.php";
?>

<script type="text/javascript" src="<?php echo SITE_URL ?>/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="<?php echo SITE_URL ?>/ckfinder/ckfinder.js"></script>
<script type="text/javascript">
    window.onload = function()
    {
        var editor =  CKEDITOR.replace( 'editor1'
                                                        , {
                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_seller.php")
        ?>

        <!--header area end -->




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



            <?php
            include_once("../includes/artisttopmenu.php")
            ?>		


            <div align="left" class="content_area">

                <!--content area start -->

                <div align="left" class="page_title"><?php echo TEXT_UPLOAD_PORT; ?></div>
                <div align="center" class="text_information grey_tr"><?php echo $message ?> <?php $message = ''; ?></div>
                <br>

                <div align="left">																			

                    <form name="frmPortfolio" action="<?php echo $_SERVER["PHP_SELF"] ?>" method="POST" enctype="multipart/form-data">
                        <input type="hidden" name="portfolioid" value="<?php echo htmlentities($portfolioid); ?>">
                        <input type="hidden" name="txtArtistPhoto" value="<?php echo htmlentities($txtArtistPhoto); ?>">
                        <table cellpadding="0" cellspacing="0" align="center" class="manage_table" width="100%">
                            <tr><td colspan="3">&nbsp;</td></tr>
                            <tr><td colspan="3" align="right"><span class="required">*</span>&nbsp;<?php echo MSG_FIELD_MANDATORY; ?></td></tr>
                            <tr><td align="right" valign=top width="20%"><?php echo TEXT_SELLER_DESC;?>&nbsp;<span class="required">*</span></td>
                                <td width="1%" >&nbsp;</td>
                                <td width="79%" align="left" valign=top>
                                    <textarea id="editor1" name="txtArtistDescription" cols="70" rows="10"><?php echo stripslashes($txtArtistDescription); ?></textarea>
                                    <?php
                                    /* $sBasePath                      = "../FCKeditor/";
                                      $oFCKeditor 					= new FCKeditor('txtArtistDescription') ;
                                      $oFCKeditor->BasePath			= $sBasePath ;
                                      $oFCKeditor->Value				= nl2br(stripslashes($txtArtistDescription));
                                      $oFCKeditor->Width  = '100%' ;
                                      $oFCKeditor->Height = '330' ;
                                      $oFCKeditor->Create() ; */
                                    ?>
                                </td>
                            </tr>
                            <tr><td colspan="3">&nbsp;</td></tr>
                            <tr><td align="right" valign=top ><?php echo TEXT_SELLER_PHOTO;?>&nbsp;</td>
                                <td >&nbsp;</td>
                                <td valign=top align="left" class="blackbartextCopy"><input type="file" name="artistphoto" id="artistphoto" size="40" class="textbox" >&nbsp;<strong><?php echo TEXT_BEST_FIT; ?>- 190 x 185</strong>
                                    <div align="left">
                                        <?php if (isNotNull($txtArtistPhoto)) { ?>
                                           <?php echo TEXT_EXISTING;?>: <font color='RED'><?php echo $txtArtistPhoto ?></font>
                                            <br>

                                            <input type="checkbox" class="checkbox" name="chkDeleteArtistPhoto">&nbsp;<?php echo TEXT_DEL_EXISTING ;?>
                                            <br>
                                        <?php } ?>

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

                            <?php
                            if ($portfolioid != "") {

                                /* -----------Multicart 2.0 upgradation-------------- */

                                $artistname = getArtistName($artistid);

                                if ($enable_seller_friendly == "Y") {
                                    ?>								
                                    <tr><td colspan="3" align="left"><a href="<?php echo SITE_URL ?>/store/<?php echo $artistname; ?>"><b><?php echo LINK_VIEW_CUR_PORT; ?></b></a></td></tr>
                                    <?php
                                } else {
                                    ?>
                                    <tr><td colspan="3" align="left"><a href="../showportfolio.php?artistid=<?php echo $artistid; ?>" target="_blank" class="menu2"><b><?php echo LINK_VIEW_CUR_PORT; ?></b></a></td></tr>

                                    <?php
                                }



                                /* -----------Multicart 2.0 upgradation-------------- */
                            }
                            ?>
                            <tr><td colspan="3">&nbsp;</td></tr>
                            <tr><td colspan="3" align="center">
                                    <input type="button" value="<?php echo BTN_BACK;?>" name="btnBack" class="button"  onClick="window.location.href='artistmain.php';" >
                                    &nbsp;&nbsp;<input type="submit" value="<?php echo BTN_SAVE_CHANGE;?>" name="btnSaveChanges" class="button" >
                                </td>
                            </tr>
                        </table>
                    </form>

                </div>


                <!--content area end-->

            </div>


            <div align="left" class="clear_float"><img src="<?php echo $imagefolder; ?>/clear.gif" alt="" width="1" height="1" /></div>
            <!--main body end -->
        </div>


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