<?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');
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;
}

$txtColor   = trim($_POST['txtColor']);
$txtNumRows = trim($_POST['txtNumRows']);
$txtNumCols = trim($_POST['txtNumCols']);
if (isset($_POST["btnSaveChanges"])) {
    $message = "" ;
	if (!isNotNull($txtColor)) {
        $message .= COLOR_EMPTY_MSG." <br>";
    }
    if (!isNotNull($txtNumRows)) {
        $message .= NUMROWS_EMPTY_TEXT." <br>";
    }
    else {
            if($txtNumRows==0)
                {
                $message .= NUMROWS_ZERO_TEXT." <br>";
            }
    }
    if (!isNotNull($txtNumCols)) {
        $message .= NUMCOLS_EMPTY_TEXT." <br>";
    }
    else {
            if($txtNumCols==0)
                {
                    $message .= NUMCOLS_ZERO_TEXT." <br>";
                }
            if($txtNumCols>4)
                {
                    $message .= NUMCOLS_MAX_TEXT." <br>";
                }
    }

    $sellerbannerdir = "../sellerbanners/";
    $chkDeleteBanner = $_POST["chkDeleteThemeBanner"];

    $themeBannerImg = $_FILES['themeBanner'];
    /*     * ******************************************************* */
    $size = getimagesize($_FILES["themeBanner"]["tmp_name"]);
    $ratio = $size[0] / $size[1];
    $req_width = 970;
   // $height = $req_width / $ratio;
    $height = 100;
    /*     * ****************************************************** */
    $themeBannerImgname = $_FILES['themeBanner']['name'];
    $themeBannerImgtype = $_FILES['themeBanner']['type'];
    $themeBannerfilename = $_FILES['themeBanner']['name'];
    $themeBannerImgtempname = $_FILES['themeBanner']['tmp_name'];

    $themeBannerphotodest = $sellerbannerdir . $themeBannerImgname;
    if ($themeBannerImgname != "") {
        if (!isValidWebImageType($themeBannerImgtype, $themeBannerfilename, $themeBannerImgtempname)) {
            $message .= MSG_INVAL_IMG;
            $error = true;
        } else {
            if (file_exists($themeBannerphotodest)) {
                $message .= MSG_SEL_BANIMG;
                $error = true;
            }
        }


        if (!is_readable($themeBannerphotodest) || !is_writable($themeBannerphotodest) || !is_executable($themeBannerphotodest)) {
            $error = true;
            // $message .= " * Please request admin to change the permission of 'portfolios' folder in the root to 777 <br>";
        }
    }




    if ($message == "") {

         if ($themeBannerImgname != "") {
  
            $sellerBannerName = substr($themeBannerImgname, 0, strrpos($themeBannerImgname, '.'));

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

            if ($handle->uploaded) {
                $handle->image_resize = true;
                $handle->image_x = 970;
                $handle->image_y = $height;
                $handle->file_new_name_body = $sellerBannerName;
                $handle->Process($sellerbannerdir);
                $themeBannerImgname = $handle->file_dst_name;
            }
        }

        $sql ="UPDATE ".$tableprefix."artists SET
			theme_color = '".addslashes($txtColor)."',
			theme_numrows = '".addslashes($txtNumRows)."',
			theme_numcols = '".addslashes($txtNumCols)."'";
        $themeOldImg = $_POST['txtThemeBanner'];
        if (($themeBannerImgname != "") || ($chkDeleteBanner == "on")) {
                $sql .= " ,theme_banner = '" . addslashes($themeBannerImgname) . "' ";
                $themephotoold = $sellerbannerdir . $themeOldImg;
                @unlink($themephotoold);
            }
       $sql .="	WHERE artist_id =  '".addslashes($artistid)."'";
		mysql_query($sql) or die(mysql_error());
                $message = MSG_THEME_SUC;
    }
    else {
            $message = VAL_MSG_PLS_CORRECT . $message;
    }

}
$sql = "SELECT theme_color,theme_banner,theme_numrows,theme_numcols FROM " . $tableprefix . "artists   WHERE artist_id = '" . addslashes($artistid) . "' ";
$res = mysql_query($sql);
if (mysql_num_rows($res) > 0) {
    $row = mysql_fetch_array($res);
    $themeColor = $row["theme_color"];
    $themeNumRows = $row["theme_numrows"];
    $themeNumCols = $row["theme_numcols"];
    $themeBanner = $row["theme_banner"];
    
}
else
    {
    $themeColor='#ffffff';
}
include "../includes/htmltop.php";
?>
<link rel="stylesheet" href="<?php echo SITE_URL ?>/style/colorpicker.css" type="text/css" />
<script type="text/javascript" src="<?php echo SITE_URL ?>/js/colorpicker.js"></script>
<script type="text/javascript">
    function showPicker(){
        $('#colorpickerField1').ColorPicker({
            onSubmit: function(hsb, hex, rgb, el) {
		//$(el).val(hex);
		$(el).ColorPickerHide();
                $("#colorpickerField1").css('backgroundColor', '#' + hex);
                $("#txtColor").val('#' +hex);
            },
            onBeforeShow: function () {
		$(this).ColorPickerSetColor(this.value);
            }
        })
        .bind('keyup', function(){
             $(this).ColorPickerSetColor(this.value);

        });
    }


        </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_THEMES_PORT; ?></div>
                <div align="center" class="text_information grey_tr"><?php echo $message ?> <?php $message = ''; ?></div>
                <br>

                <div align="left">																			

                    <form name="frmThemes" action="<?php echo $_SERVER["PHP_SELF"] ?>" method="POST" enctype="multipart/form-data">
                       <input type="hidden" name="txtThemeBanner" value="<?php echo htmlentities($themeBanner); ?>">
                        <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_CHANGE_COLOR;?>&nbsp;<span class="required">*</span></td>
                                <td width="1%" >&nbsp;</td>
                                <td width="79%" align="left" valign=top>
                                    <input name="txtColor" type="text" class="textarea" id="txtColor" value="<?php echo $themeColor?>"  maxlength="20">
                                    <input type="text" id="colorpickerField1" value="" onclick="showPicker()" ondblclick="showPicker()" size="6" style="background-color: <?php echo $themeColor?>">
                                </td>
                            </tr>
                            <tr><td colspan="3">&nbsp;</td></tr>
                            <tr><td align="right" valign=top ><?php echo TEXT_CHANGE_BANNER;?>&nbsp;<span class="required">*</span></td>
                                <td >&nbsp;</td>
                                <td valign=top align="left" class="blackbartextCopy"><input type="file" name="themeBanner" id="themeBanner" size="40" class="textbox" >
                                   &nbsp;<strong><?php echo TEXT_BEST_FIT; ?>- 970 x 100</strong>
                                    <div align="left">
                                        <?php if (isNotNull($themeBanner)) { ?>
                                           <?php echo TEXT_EXISTING;?>: <font color='RED'><?php echo $themeBanner ?></font>
                                            <br>
                                            <input type="checkbox" class="checkbox" name="chkDeleteThemeBanner">&nbsp;<?php echo TEXT_DEL_EXISTING ;?>
                                            <br>
                                        <?php } ?>
                                    </div>
                                </td>
                            </tr>
                            <tr><td colspan="3">&nbsp;</td></tr>
                            <tr>
                                <td align="left" valign=top colspan="3"><strong><?php echo TEXT_ITEM_LISTING;?></strong></td>
                               
                            </tr>
                            <tr><td colspan="3">&nbsp;</td></tr>
                            <tr>
                                <td align="right" valign=top width="20%"><?php echo TEXT_NUM_ROWS;?>&nbsp;<span class="required">*</span></td>
                                <td width="1%" >&nbsp;</td>
                                <td width="79%" align="left" valign=top>
                                    <input name="txtNumRows" type="text" class="textarea" id="txtNumRows" value="<?php echo $themeNumRows?>"  maxlength="20">
                                    
                                </td>
                            </tr>
                            <tr><td colspan="3">&nbsp;</td></tr>
                            <tr><td align="right" valign=top width="20%"><?php echo TEXT_NUM_COLS;?>&nbsp;<span class="required">*</span></td>
                                <td width="1%" >&nbsp;</td>
                                <td width="79%" align="left" valign=top>
                                    <input name="txtNumCols" type="text" class="textarea" id="txtNumCols" value="<?php echo $themeNumCols?>"  maxlength="20">
                                    <?php echo TEXT_COLS_LIMIT?>
                                </td>
                            </tr>
                            <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";
        ?>
