public static function renderHeader($withMenu = true)
    {
        include '../resources/header.html';
        if ($withMenu) {
            $userManager = new UserManager();
            $loggedInUser = $userManager->getLoggedInUser();
            $auctionManager = new AuctionManager();
            $categories = $auctionManager->getAllCategories();
            $searchTerm = isset($_GET['searchTerm']) ? $_GET['searchTerm'] : "";
            $categoryID = isset($_GET['categoryID']) ? $_GET['categoryID'] : AuctionManager::DEFAULT_ALL_CATEGORIES;
            echo '
<nav class="navbar navbar-bidbucket" role="navigation">
    <div class="container-fluid">

        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="/auction/homepage"><img src="/assets/img/logo2.png" height="25" alt="logo"></a>
            <span class="navbar-brand"><a href="/auction/profile?id=' . $loggedInUser->userID . '">Hello ' . $loggedInUser->firstName . '!</a></span>
        </div>
        <div class="collapse navbar-collapse" id="myNavbar">
            <form class="navbar-form navbar-left" role="form" action="/auction/homepage" method="get">
              <div class="form-group">
                <input type="text" class="form-control" id="searchbox" name="searchTerm" placeholder="Search" value="' . $searchTerm . '">
                <select class="form-control" id="categoryDrop" name="categoryID" >
                  <option value="' . AuctionManager::DEFAULT_ALL_CATEGORIES . '">ALL</option>';
            foreach ($categories as $category) {
                $selected = $categoryID == $category->id ? "selected" : "";
                echo '<option ' . $selected . ' value="' . $category->id . '">' . $category->name . '</option>';
            }
            echo ' </select>
              </div>
              <button type="submit" class="btn btn-default">Submit</button>
            </form>
            <ul class="nav navbar-nav navbar-right">
                <li><a href="/auction/settings"><span class="glyphicon glyphicon-user"></span> My Bucket</a></li>

                ';
            if ($loggedInUser->roleID == 2) {
                echo '<li><a href="/auction/upload"><span class="glyphicon glyphicon-list-alt"></span> Start Auction</a></li>';
            }
            echo '
                <li><a href="/auction/logout"><span class="glyphicon glyphicon-log-out"></span> Log out</a></li>
            </ul>
        </div>
    </div>
</nav>


';
        }
    }
    public function render()
    {
        $auctionManager = new AuctionManager();
        $categories = $auctionManager->getAllCategories();
        Header::renderHeader(true);
        echo '
        <div id="upload" class="container">
            <div class="row-fluid">

                <div class="col-lg-10 col-lg-offset-1">
                    <form action="/auction/upload" style="" class="login-form" id="UserLoginForm" method="post" accept-charset="utf-8" enctype="multipart/form-data">
                    <fieldset class="form-group">
                        <label for="item_title">Product Name</label>
                        <input type="text" class="form-control" id="item_title" name="item_title" placeholder="Product Name" required="required">
                    </fieldset>
                    <div class="form-group">
                        <label for="item_description">Product Description</label>
                        <input type="text" class="form-control" id="item_description" name="description" placeholder="Product Description" required="required">
                    </div>
                    <fieldset class="form-group col-lg-4">
                        <label for="item_start_price">Start Price</label>
                        <div class="input-group">
                        <span class="input-group-addon"><i class="glyphicon glyphicon-gbp"></i>
                            </span>
                        <input type="number" min="0.01" step="0.01" class="form-control" id="item_start_price" name="start_price" placeholder="0.00" required="required">
                        </div>
                    </fieldset>
                    <fieldset class="form-group col-lg-4 col-lg-offset-2">

                        <label for="item_reserve_price">Reserve Price</label>
                        <div class="input-group">
                        <span class="input-group-addon"><i class="glyphicon glyphicon-gbp"></i>
                            </span>
                        <input type="number" min="0.01" step="0.01" class="form-control" id="item_reserve_price" name="reserve_price" placeholder="0.00" required="required">
                        </div>
                    </fieldset>
                    <fieldset class="form-group col-lg-4">
                        <label for="item_start_date">Start Date</label>
                        <div class="input-group">
                        <span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i>
                            </span>
                            <input type="date" class="form-control" id=item_start_date name="start_date"/>
                        </div>
                    </fieldset>
                    <fieldset class="form-group col-lg-4 col-lg-offset-2">
                        <label for="item_start_time">Start time</label>
                        <div class="input-group">
                        <span class="input-group-addon"><i class="glyphicon glyphicon-time"></i>
                            </span>
                            <input type="time" class="form-control" id=item_start_time name="start_time"/>
                        </div>
                    </fieldset>
                    <fieldset class="form-group col-lg-4">
                        <label for="item_start_date">End Date</label>
                        <div class="input-group">
                        <span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i>
                            </span>
                            <input type="date" class="form-control" id=item_end_date name="end_date" required="required" />
                        </div>
                    </fieldset>
                    <fieldset class="form-group col-lg-4 col-lg-offset-2">
                        <label for="item_start_time">End time</label>
                        <div class="input-group">
                        <span class="input-group-addon"><i class="glyphicon glyphicon-time"></i>
                            </span>
                            <input type="time" class="form-control" id=item_end_time name="end_time"/>
                        </div>
                    </fieldset>
                    <fieldset class=" form-group col-lg-4">
                           <label for="ItemCondition">Item Condition</label>
                          <select name="item_condition" class="form-control" id="ItemCondition" required="required">
                                    <option value="">Please choose</option>
                                    <option value="New - in box">New - in box</option>
                                    <option value="New">New</option>
                                    <option value="Used once">Used once</option>
                                    <option value="Used">Used</option>
                                    <option value="Small defect">Small defect</option>
                                    <option value="Needs fixing">Needs fixing</option>
                          </select>
                    </fieldset>
                    <fieldset class="form-group col-lg-4 col-lg-offset-2">
                        <label for="category">Category</label>
                    <select multiple="multiple" name="category[]" class="form-control" id="category" required="required">
                        ';
        foreach ($categories as $category) {
            echo "<option value=" . $category->id . ">" . $category->name . "</option>";
        }
        echo '
                    </select>
                    </fieldset>
                    <fieldset class="form-group">
                    <label for="fileToUpload">Select image to upload:</label>
                        <input type="file" class="form-control" name="userfile" id="userfile" required="required" accept="image/*" >
                    </fieldset>

                    <div class="form-group">
                                <button class="btn btn-primary btn-large btn-block" name="submit" type="submit" value="submit"> Submit </button>
                     </div>
                     </form>
                </div>
            </div> <!-- row-fluid -->
        </div> <!-- regisister container -->';
    }
<?php

/**
 * Created by PhpStorm.
 * User: BlackLinden
 * Date: 14/03/2016
 * Time: 17:43
 */
use Models\AuctionAwarderManager;
use Models\AuctionManager;
use Models\EmailManager;
use Models\UserManager;
require __DIR__ . '/../bootstrap.php';
$auctionManager = new AuctionManager();
$auctionAwarderManager = new AuctionAwarderManager();
$userManager = new UserManager();
$emailManager = new EmailManager();
$auctionIds = $auctionAwarderManager->getAuctionIdsToAward();
echo count($auctionIds) . " auctions to award\n";
foreach ($auctionIds as $auctionID) {
    echo "Awarding {$auctionID}...\n";
    $auctionDetail = $auctionManager->getAuctionDetail($auctionID);
    $seller = $userManager->getUser($auctionDetail->sellerID);
    // There have been bids
    echo "There have been " . $auctionDetail->numberOfBids . " bids\n";
    if ($auctionDetail->numberOfBids > 0) {
        $highestBidder = $userManager->getUser($auctionDetail->highestBidderID);
        $losingBuyers = $auctionAwarderManager->getLosingBuyers($auctionID, $auctionDetail->highestBidderID);
        foreach ($losingBuyers as $losingBuyer) {
            $emailManager->sendEmailUnsuccessfullBid($losingBuyer, $auctionDetail);
        }
    public function render()
    {
        //Echo the view
        //renders the header automatically
        Header::renderHeader();
        $auctionManager = new AuctionManager();
        $sortSelected = isset($_POST['sort']) ? $_POST['sort'] : "";
        echo '
        <div id="searchresults" class="container">

            <h1>BidBucket</h1>
            <h6 id="homeSubheader">Where cool items hang out</h6>

        <div class="surroundss">

        <div class="menu">
            <h3>Categories</h3>
            <ul>
            ';
        foreach ($auctionManager->getAllCategories() as $category) {
            echo '<a href ="/auction/homepage?searchTerm=&categoryID=' . $category->id . '"><li>' . $category->name . '</li></a>';
        }
        echo '
            </ul>
       </div>
        <div class="main">
            <p id="currentAuctionsHeader">Current Auctions</p>
            <form name="sortform" method="post" class="form-inline">
                <div class="form-group">
                    <label for="sort">Sort:</label>
                        <select class="form-control" name="sort" onchange="this.form.submit()">';
        foreach (AuctionManager::$sorts as $sort) {
            $selected = $sortSelected == $sort ? "selected" : "";
            echo '<option ' . $selected . ' value="' . $sort . '">' . $sort . '</option>';
        }
        echo '
                        </select>
                        <noscript><input type="submit" value="Submit"></noscript>
                </div>
            </form>
            <br>';
        foreach ($this->auctionDetails as $auction) {
            if (count($auction->imageIDs) > 0) {
                $url = "/auction/image?id=" . $auction->imageIDs[0];
            } else {
                $url = "/assets/img/logo.png";
            }
            $watching = "Not watching";
            if ($auction->isWatching == 1) {
                $watching = "Watching";
            }
            echo '
                <table>
                    <tr>
                      <td rowspan="8"><img src="' . $url . '" align="left" width="120" alt="logo"></td>
                      <td><a href="/auction/auction?id=' . $auction->auctionId . '"><h3>' . $auction->itemName . '</h3></a></td>
                    </tr>
                    <tr><td><b>Current price</b>: £ ' . $auction->maxBid . ' </td></tr>
                    <tr><td><b>Number of bids</b>: ' . $auction->numberOfBids . '</td></tr>
                    <tr><td><b>Condition</b>: ' . $auction->itemCondition . '</td></tr>
                    <tr><td><b>Starting price</b>: £ ' . $auction->startPrice . '</td></tr>
                    <tr><td><b>Start date</b>: ' . DateTimeUtils::formatDate($auction->startDate) . '</td></tr>
                    <tr><td><b>End date</b>: ' . DateTimeUtils::formatDate($auction->endDate) . '</td></tr>
                    <tr><td>' . $watching . '</td></tr>
                </table>
                <br><br>';
        }
        echo '</div>
  </div>
</div>';
    }
    public function render()
    {
        //Echo the view
        //renders the header automatically
        Header::renderHeader();
        $auctionSellerManager = new AuctionSellerManager();
        $auctionManager = new AuctionManager();
        $sortSelected = isset($_POST['sort']) ? $_POST['sort'] : "";
        echo '
        <div id="searchresults" class="container">
        <div class="surroundss">
        <div class="menu">
            <h3>Categories</h3>
            <ul>
            ';
        // change this to output the seller items
        foreach ($auctionManager->getAllCategories() as $category) {
            echo '<a href ="/auction/homepage?searchTerm=&categoryID=' . $category->id . '"><li>' . $category->name . '</li></a>';
        }
        echo '
            </ul>
       </div>
        <div class="main">
            <h1>Welcome to BidBucket</h1>
            <p>Here is a list of all of your auctions</p>
            <form name="sortform" method="post" class="form-inline">
                <div class="form-group">
                    <label for="sort">Sort:</label>
                        <select class="form-control" name="sort" onchange="this.form.submit()">';
        foreach (AuctionSellerManager::$sorts as $sort) {
            $selected = $sortSelected == $sort ? "selected" : "";
            echo '<option ' . $selected . ' value="' . $sort . '">' . $sort . '</option>';
        }
        echo '
                        </select>
                </div>
            </form>';
        foreach ($this->auctionReport as $auction) {
            if (count($auction->imageIDs) > 0) {
                $url = "/auction/image?id=" . $auction->imageIDs[0];
            } else {
                $url = "/assets/img/logo.png";
            }
            echo '
                <table>
                    <tr>
                      <td rowspan="7"><img src="' . $url . '" align="left" width="120" alt="logo"></td>
                      <td><a href="/auction/auctionseller?id=' . $auction->auctionId . '"><h3>' . $auction->itemName . '</h3></a></td>
                    </tr>
                    <tr><td><b>Current price</b>: £ ' . $auction->maxBid . ' </td></tr>
                    <tr><td><b>Number of bids</b>: ' . $auction->numberOfBids . '</td></tr>
                    <tr><td><b>No of unique bidders</b>: ' . $auction->numberOfBidders . '</td></tr>
                    <tr><td><b>No of watchers</b>: ' . $auction->watchers . '</td></tr>
                    <tr><td><b>No of views</b>: ' . $auction->views . '</td></tr>
                    <tr><td><b>End date</b>: ' . DateTimeUtils::formatDate($auction->endDate) . '</td></tr>
                </table>
                <br><br>';
        }
        echo '</div>
</div>
</div>';
    }
 /**
  * Increments the number of views by 1
  * @param $auctionID
  * @param $currentUser
  */
 public function incrementViews($auctionID, $currentUser)
 {
     // checks if the seller is looking at an item and if not increments views
     // http://stackoverflow.com/questions/2259155/increment-value-in-mysql-update-query
     $connection = ConnectionManager::getConnection();
     $auctionManager = new AuctionManager();
     $sellerId = $auctionManager->getAuctionDetail($auctionID)->sellerID;
     if ($sellerId != $currentUser) {
         if (!isset($_SESSION["hasVisited'{$auctionID}''"])) {
             $_SESSION["hasVisited'{$auctionID}''"] = "yes";
             $sql = "UPDATE auction SET views = views + 1 WHERE id = '" . $auctionID . "'";
             $connection->query($sql);
         }
     }
 }
 $description = $_POST['description'];
 $item_condition = $_POST['item_condition'];
 $start_price = $_POST['start_price'];
 $reserve_price = $_POST['reserve_price'];
 $start_date = $_POST['start_date'];
 $start_time = $_POST['start_time'];
 $end_date = $_POST['end_date'];
 $end_time = $_POST['end_time'];
 $fileName = $_FILES['userfile']['name'];
 //image name
 $tmpName = $_FILES['userfile']['tmp_name'];
 // data
 $fileSize = $_FILES['userfile']['size'];
 $fileType = $_FILES['userfile']['type'];
 $categories = $_POST['category'];
 $auctionManager = new AuctionManager();
 $imageManager = new ImageManager();
 $imageAuctionID = -1;
 if ($tmpName != null) {
     $imageID = $imageManager->uploadImage($tmpName, $fileType);
     \Models\Logger::log($imageID);
     if ($imageID > 0) {
         $auctionID = $auctionManager->createNewItem($title, $description, $item_condition, $start_price, $reserve_price, $start_date, $start_time, $end_date, $end_time, $categories);
         if ($auctionID > 0) {
             $imageAuctionID = $auctionManager->registerImage($auctionID, $imageID);
             \Models\Logger::log($imageAuctionID);
         }
     }
 }
 if ($imageAuctionID > 0) {
     $auctionDetail = $auctionManager->getAuctionDetail($auctionID);
/**
 * Created by PhpStorm.
 * User: BlackLinden
 * Date: 08/02/2016
 * Time: 11:33
 */
include_once '../bootstrap.php';
use Models\AuctionManager;
use Models\Bid;
use Models\BidManager;
use Models\LoginManager;
use Models\UserManager;
use Views\AuctionDetailView;
LoginManager::startSessionAndRedirectIfNotLoggedIn();
$auctionManager = new AuctionManager();
$userManager = new UserManager();
$currentUser = $userManager->getLoggedInUser()->userID;
// get the auction id
$auctionId = (int) $_REQUEST['id'];
if ($auctionId) {
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
        $id = $_POST['id'];
        $amount = $_POST['newBid'];
        $itemName = $_REQUEST['itemName'];
        $bidManager = new BidManager();
        $bid = new Bid($amount, new DateTime(), $id, $currentUser, $itemName);
        $bidManager->updateBid($bid);
        $auctionDetail = $auctionManager->getAuctionDetail($auctionId);
        $auctionDetailView = new AuctionDetailView($auctionDetail);
        $auctionDetailView->render();