<?php
require_once ("../config.inc.php");
require_once ("../includes/adminlogincheck.inc.php");
require_once ("../includes/mysql.inc.php");
require_once ("../includes/arrays.inc.php");
require_once ("../classes/users.class.php");
require_once ("../classes/settings.class.php");


$page		= isset($_REQUEST['page'])	?	trim($_REQUEST['page'])	:	"1";
$id			= isset($_REQUEST['id'])	?	trim($_REQUEST['id'])	:	"0";
$pid		= isset($_REQUEST['pid'])	?	trim($_REQUEST['pid'])	:	"0";
$message	= "";
$objC		= new check();
$objST	= new settings($objDB);
$siteTitle=$objST->select();
if (!$objDB) {
    $message	= "Unable to Locate Database Server.";
} else {
    $objU		= new users($objDB);
    $objSU2	= new settings($objDB);

    if (isset($_POST['SaveNow'])) {
        $objU->set_user_image(array_merge($_POST, $_FILES));

        //create allowed image type array
        $allowdImgTypes=$objSU2->select();
        $allowdImgTypes=explode(",",$allowdImgTypes['allowedimagetypes']);

        //checking uploaded image is is allowed type and also checking uploaded file is executable
        $chkMsg=$objSU2->CheckUploadFileType($allowdImgTypes,$_FILES['file']['type']);

        if(trim($chkMsg)=='') {
            $message	= $objU->save_user_image($id, $pid,1);
        }//end if
        else {
            $message=$chkMsg;
        }//end else

    } else {
        $array	= $objU->get_user_image($id, $pid);
        $objU->set_user_image($array);
    }
}
//include_once('title.inc.php');
?>
<script language="javascript" type="text/javascript">
    function validate()
    {
        var frm	= document.frmUser;
        if (frm.vTitle.value == "") {
            alert("Please enter title of the image.");
            frm.vTitle.focus();
            return false;
        }
        return true;

    }
    function closewindow()
    {
        window.opener.location.href = window.opener.location.href;
        if (window.opener.progressWindow)
        {
            window.opener.progressWindow.close()
        }
        window.close();
    }
</script>
<link href="../styles/<?php echo $siteTitle['styles'];?>" rel="stylesheet" type="text/css">
<table width="100%"  border="0" cellspacing="0" cellpadding="0" class="add-pic-table">
    <tr>
        <td valign="top" class="white"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td width="72%" valign="top"><?php //include_once('tophtml.php');?>
                        <table width="100%"  border="0" cellspacing="0" cellpadding="5">
                            <tr>
                                <td><table width="100%"  border="0" cellspacing="0" cellpadding="5">
                                        <tr>
                                            <td width="41%" colspan="2"><h5>Add Photo</h5></td>
                                        </tr>
                                    </table></td>
                            </tr>
                        </table>
                        <form action="" method="post" enctype="multipart/form-data" name="frmUser" onSubmit="return validate();">
                            <table width="100%"  border="0" cellspacing="0" cellpadding="5">
                                <tr>
                                    <td><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                                            <?php if ($objDB) {
                                                ?>
                                                <?php 	if(isset($message) && $message!='') {
                                                    ?>
                                            <tr align="left">

                                                <td colspan="2" class="maintext2 warning"><?php echo $message;?></td>
                                            </tr>
                                                    <?php  	}//end if?>
                                            <tr align="left">
                                                <td width="27%" class="maintext2">Photo Title <span style="color: red;">*</span></td>
                                                <td width="70%" class="maintext2"><input name="vTitle" type="text" size="40" maxlength="200" value="<?php echo $objU->vTitle?>" class="textbox add-pic-txt"></td>
                                            </tr>
                                                <?php if ($pid > 0) { ?>
                                            <tr align="left">
                                                <td class="maintext2">Current Photo</td>
                                                <td class="maintext2"><img src="<?php echo "../".PROFILE_IMAGE_URL."/sthumb_".$objU->vUrl?>"></td>
                                            </tr>
                                                    <?php } ?>
                                            <tr align="left">
                                                <td class="maintext2">Browse Photos <span style="color: red;">*</span></td>
                                                <td class="maintext2"><input type="file" name="file" class="textbox" style="width: 225px;"></td>
                                            </tr>
                                                <?php
                                            }//end first if
                                            ?>
                                        </table>
                                        <table width="100%"  border="0" cellspacing="0" cellpadding="0" style="margin-top: 10px;">
                                            <tr>
                                                <td align="right">
                                                    <?php if ($objDB) {
                                                        ?>
                                                    <table width="100%"  border="0" cellspacing="0" cellpadding="5">
                                                        <tr>
                                                            <td align="left"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                                                                    <tr>
                                                                        <td width="28%">&nbsp;</td>
                                                                        <td align="left" width="10%"><input name="SaveNow" type="submit" class="loginbutton" style="padding:6px 12px;" value="Upload Photos"><input type="hidden" name="page" value="<?php echo $page?>">
                                                                            <input type="hidden" name="id" value="<?php echo $id?>">
                                                                            <input type="hidden" name="pid" value="<?php echo $pid?>"></td>
                                                                        <td align="left">&nbsp;&nbsp;<input name="BackNow" type="button" class="close-win" style="padding:6px 12px;" value="Close Window" onClick="closewindow();"></td>
                                                                    </tr>
                                                                </table></td>
                                                        </tr>
                                                    </table>
                                                        <?php
                                                    }//end first if
                                                    ?></td>
                                            </tr>
                                        </table></td>
                                </tr>
                            </table></form></td>
                </tr>
            </table>
        </td>
    </tr>
</table>
<?php //include_once('bottomhtml.php');?>