<?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 (c) 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/arrays.inc.php";
include "../includes/class.upload.php";


$maximagesizestringinPHP = ini_get("upload_max_filesize");
$maximagesizeinPHP = $maximagesizestringinPHP * (1024 * 1024);

$adminCurrency = GetAdminCurrency();

include('../includes/image.class.php');
$img = new Zubrag_image;
//getting styles from arrays.inc

if (function_exists('get_magic_quotes_gpc') && 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($_POST["btnSaveChanges"])) {
    $message = "";
    $logofile = $_FILES['userfile'][0];
    $logofilename = $_FILES['userfile']['name'][0];
    if (!empty($logofilename)) {
        $logofiletype = $_FILES['userfile']['type'][0];
        $logotempname = $_FILES['userfile']['tmp_name'][0];
        $logofilesize = $_FILES['userfile']['size'][0];
        $logoimagedest = "../banners/" . $logofilename;
        $logoimageTemp = "../banners/" . time() . $logofilename;
        if ($_FILES['userfile']['name'][0] != "") {
            if (!isValidWebImageType($logofiletype, $logofilename, $logotempname)) {
                $message .= " * Invalid Logo file ! Upload an image (jpg/gif/png)" . "<br>";
                $error = true;
            } else {
                if (file_exists($logoimagedest)) {
                    $message .= " * ".FILE_WITH_SAME_NAME. "<br>";
                    $error = true;
                } elseif ($logofilesize > $maximagesizeinPHP) {
                    $message.= "*".COULD_NOT_UPLOAD_LOGO.$maximagesizestringinPHP. "<br>";
                }
            }
        }
        //Logo upload modified by Sreehari

        if (move_uploaded_file($_FILES['userfile']['tmp_name'][0], $logoimageTemp)) {
            $dir_dest = "../banners/";
            $handle = new Upload($logoimageTemp);
            $logoNewfilename = substr($logofilename, 0, strrpos($logofilename, '.'));
            list($origWidth, $origHeight) = getimagesize($logoimageTemp);
            $maxResizeWidth = 203;
            $maxResizeHeight = 105;
            $resizedWidth = $origWidth;
            $resizedHeight = $origHeight;
            if ($resizedWidth > $maxResizeWidth) {
                $aspectRatio = $maxResizeWidth / $resizedWidth;
                $resizedWidth = round($aspectRatio * $resizedWidth);
                $resizedHeight = round($aspectRatio * $resizedHeight);
            }
            if ($resizedHeight > $maxResizeHeight) {
                $aspectRatio = $maxResizeHeight / $resizedHeight;
                $resizedWidth = round($aspectRatio * $resizedWidth);
                $resizedHeight = round($aspectRatio * $resizedHeight);
            }

            if ($handle->uploaded) {
                $handle->image_resize = true;
                $handle->image_x = $resizedWidth;
                $handle->image_y = $resizedHeight;
                $handle->file_new_name_body = $logoNewfilename;
                $handle->Process($dir_dest);
                $logofilename = $handle->file_dst_name;
            }
            unlink($logoimageTemp);
        }
        // no error so insert user details
        $sql = "UPDATE " . $tableprefix . "settings SET site_logo = " . GetSQLValueString($logofilename, "text");
        /* echo $sql;
          exit; */
        mysql_query($sql) or die(mysql_error());
        $message = LOGO_UPDATED."!";
    } else {
        $message = UPL_VALID_FILE;
    }
}

$sql = "SELECT site_logo FROM " . $tableprefix . "settings ";
$result = mysql_query($sql);
if (mysql_num_rows($result) != 0) {
    $row = mysql_fetch_array($result);
    $site_logo = $row["site_logo"];
}




include "../includes/htmltop.php";
?>
<style>
   /* .tooltip {
        display:none;
        background:transparent url(../images/tooltip/black_arrow.png);
        font-size:12px;
        height:70px;
        width:160px;
        padding:25px;
        color:#fff;	
    }*/


   .tooltip {
    background-color: black;;
filter: alpha(opacity=75)-moz-opacity:0.75;
opacity: 0.75;
    border: 2px solid #FFFFFF;

    border-radius:5px 5px 5px 5px;
    color: white;
    font-size: 1.2em;
    left: -12px;
    padding: 10px;
    position: relative;
    top: 21px;
    width: 200px;
}
.tooltip:after, .tooltip:before
{
    top: 100%;
    border: solid transparent;
    content: " ";
    height: 0;
    width: 0;
    position: absolute;
    pointer-events: none;
}
.tooltip:after
{
    border-color: rgba(10, 13, 15, 0);
    border-top-color: #0a0d0f;
    border-width: 10px;
    left: 50%;
    margin-left: -10px;
} .tooltip:before

{
    border-color: rgba(245, 245, 245, 0);
    border-top-color: #f5f5f5;
    border-width: 16px;
    left: 50%;
    margin-left: -16px;
}

</style>
<script language="JavaScript" type="text/JavaScript" src="../js/jquery.tools.min.js"></script>
<script language="JavaScript" type="text/JavaScript">

    $(document).ready(function(){
        $(".help a[title]").tooltip();
    })
	
	
</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="frmSettings" action="<?php echo $_SERVER["PHP_SELF"] ?>" method="POST"  enctype="multipart/form-data">				

                <div align="right" class="content_area">
                    <!--content area start -->




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

                    <div align="right">

                        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_table">

                            <tr class="grey_tr">                           
                                <td align="right" valign="middle"><?php echo SITE_LOGO;?></td>
                                 <td align="center" valign="middle"></td>                                
                                <td  align="left" valign="middle">                                   
                                   &nbsp;<input type="file" name="userfile[]"> <b>(<?php echo JPG_GIF_PNG;?>)</b> <?php echo SUITABLE_SIZE;?> (203 x 105)
                                    <span class="help"><a href="#" title="This is where you can insert your own logo into the website. "><img src="../images/question_mark.jpg" border="0" height="15"></a></span>
                                </td>
                                <td align="right">
                                    <img src="../banners/<?php echo $site_logo; ?>" border="0" align="absmiddle" /><br><?php echo $site_logo; ?>
                                </td>
                           </tr>
                            </table>

                    </div>
                    <div align="center"><input type="submit" value="<?php echo BTN_SAVE_CHANGES;?>" name="btnSaveChanges" class="button"></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";
        ?>