<?php
session_start();
require_once "main.php";
Logger::configure('log4php.xml');
$log = Logger::getLogger('logouploaddoc');
global $db;
if ($_SESSION['access']<3){
    $comz = $_SESSION['comnum'];
    $fileName = $_FILES['userfile']['name'];
    $tmpName = $_FILES['userfile']['tmp_name'];
    $target_path = 'uploads/';
    if(!is_dir($target_path)) {
        mkdir($target_path);
    }

    $target_path = $target_path . $comz . '.png';
        if(!file_exists($target_path))  {
        if(move_uploaded_file($_FILES['userfile']['tmp_name'], $target_path)) {
            echo "The logo has been uploaded";
            $log->info( (!empty($_GET['submitType']) ? $_GET['submitType'] : null).' - user = '.$_SESSION['user'].' - '.$_SESSION['comnum'].' = '.(!empty($_GET['id']) ? $_GET['id'] : null));

        }
        } else {
        unlink($target_path);
        if(move_uploaded_file($_FILES['userfile']['tmp_name'], $target_path)) {
            echo "The logo has been replaced";
            $log->info( (!empty($_GET['submitType']) ? $_GET['submitType'] : null).' - user = '.$_SESSION['user'].' - '.$_SESSION['comnum'].' = '.(!empty($_GET['id']) ? $_GET['id'] : null));

        }

        }
} else {
?>
    <script>alert('You do not have a high enough access level to post payments\n\
                   or charges!\n\
                   Please see your administrator.');
    </script>
<?php
}
////echo 'File: <b>' . $fileName . '</b> was uploaded succesfully.<br>';
?>
