<?php
session_start();
require_once "main.php";
Logger::configure('log4php.xml');
$log = Logger::getLogger('acinfo');
global $db;
if ($_GET['submitType']=='cust') {
    $result = bill_get_customer($_SESSION['comnum'], $_GET['id']);
    if (count($result)>0) {
        $masterid = $result[0]['masterid'];
        $result = bill_get_docs($masterid);
?>
        <script>
            function setType(type)
            {
                //formName is the name of your form
                document.accinform.submitType.value = type;
            }
        </script>
        Please click the document to download it.
        <button type="button" value="aAccount" onClick="dynamic_Select('includes/docinfo.php', '#accinfo','add',<?php echo $masterid;?>)">Add a Document</button>
<?php
        for ( $i = 0, $cnt = count ( $result ); $i < $cnt; $i++ ) {
            echo "<br/><button type=\"button\" value=\"aAccount\" style=\"font-size:10px\" onClick=\"dynamic_Select('includes/docinfo.php', '#accinfo','delete',".$result[$i]['id'].")\">Delete</button>";
			
            echo "&nbsp&nbsp<a style=\"font-size:15px\" href=\"includes/uploads".$_SESSION['comnum']."/".$result[$i]['filename']."\" target=\"_blank\"><font color=\"blue\">". $result[$i]['filename'] . "</font></a>";
        }
    } else {
        echo '<script>alert("Account was not found");</script>';
    }
} else if ($_GET['submitType']=='add') {
    $zid = $_GET['id'];
    $comz = (!empty($_GET['comnum']) ? $_GET['comnum'] : null);
?>
    <script>
        function setType(type)
        {
            //formName is the name of your form
            document.accinform.submitType.value = type;
        }
    </script>
    <form action="includes/uploaddoc.php" method="post" target="_blank" enctype="multipart/form-data">
        <input type="hidden" name="masterid" value="<?php echo $zid;?>">
        <input type="hidden" name="comnum" value=" <?php echo $_SESSION['comnum']?>">
        <input type="hidden" name="MAX_FILE_SIZE" value="2000000">
        <!-- Name of input element determines name in $_FILES array -->
        <input name="userfile" type="file" id="userfile">
        <input name="upload" type="submit" id="upload" value="Upload File">
    </form>           
<?php
} else if ($_GET['submitType']=='delete') {
    $log->info($_GET['submitType'].' - user = '.$_SESSION['user'].' - '.$_SESSION['comnum'].' = '.$_GET['id']);
    $result = bill_get_doc($_GET['id']);
    $tesx = 'uploads'.trim($_SESSION['comnum']).'/'.$result[0]['filename'];
    unlink($tesx);    
	$result = bill_delete_doc($_GET['id']);	
    echo '<br>File was Deleted';
}
?>