<?php

$hour_begin = 7;
$hour_end = 13;
print "<h1>" . TimeFormatDay($time) . "</h1>";
print "\n<p class=\"menu_bar\">\n<a class=\"menu_tab\" href=\"index2.php?page=datebook_view_day&amp;time=" . ($time - 31536000) . "\"><< " . Date("Y", $time - 31536000) . "</a>\n<a class=\"menu_tab\" href=\"index2.php?page=datebook_view_day&amp;time=" . ($time - 604800) . "\"><< " . TimeFormat($time - 604800) . "</a>\n<a class=\"menu_tab\" href=\"index2.php?page=datebook_view_day&amp;time=" . ($time - 86400) . "\">< " . TimeFormat($time - 86400) . "</a>\n<a class=\"menu_tab\" href=\"index2.php?page=datebook_view_day&amp;time=" . time() . "\">Today</a>\n<a class=\"menu_tab\" href=\"index2.php?page=datebook_view_day&amp;time=" . ($time + 86400) . "\">" . TimeFormat($time + 86400) . " ></a>\n<a class=\"menu_tab\" href=\"index2.php?page=datebook_view_day&amp;time=" . ($time + 604800) . "\">" . TimeFormat($time + 604800) . " >></a>\n<a class=\"menu_tab\" href=\"index2.php?page=datebook_view_day&amp;time=" . ($time + 31536000) . "\">" . Date("Y", $time + 31536000) . " >></a>\n</p>";
$startday_day = date("j", $time);
$startday_month = date("n", $time);
$startday_year = date("Y", $time);
$startday = mktime($hour_begin, 0, 0, $startday_month, $startday_day, $startday_year);
$endday = $startday + 86400;
// Invoices issued today
$sql_invoices = "SELECT invoice_id, invoice_ref, invoice_paid, invoice_due, proj_name, proj_num, proj_id FROM intranet_timesheet_invoice, intranet_projects WHERE invoice_date BETWEEN '{$startday}' AND '{$endday}' AND invoice_project = proj_id ORDER BY invoice_ref";
$result_invoices = mysql_query($sql_invoices, $conn) or die(mysql_error());
if (mysql_num_rows($result_invoices) > 0 and $user_usertype_current > 2) {
    print "<h2>Invoices Issued Today</h2>";
    print "<table summary=\"Invoices due on " . TimeFormat($time) . "\">";
    while ($array_invoices = mysql_fetch_array($result_invoices)) {
        $invoice_id = $array_invoices['invoice_id'];
        $invoice_ref = $array_invoices['invoice_ref'];
        $invoice_paid = $array_invoices['invoice_paid'];
        $invoice_due = $array_invoices['invoice_due'];
        $proj_name = $array_invoices['proj_name'];
        $proj_num = $array_invoices['proj_num'];
        $proj_id = $array_invoices['proj_id'];
        if ($invoice_due < time() and $invoice_paid == 0) {
            $highlight = "background-color: #{$settings_alertcolor}";
        } else {
            $highlight = NULL;
        }
        print "<tr><td style=\"width: 100px; {$highlight}\"><a href=\"index2.php?page=timesheet_invoice_view&amp;invoice_id={$invoice_id}\">{$invoice_ref}</a>";
if ($techmessage != "" and $settings_showtech == "1" and $usertype_status == "admin") {
    $timesheetaction = $timesheetaction . "<div class=\"warning\"><p><strong>Support Messages</strong></p><p>{$techmessage}</p></div>";
}
// This includes the "outstanding" section, which alerts users to outstanding actions.
if ($alertmessage == NULL) {
    include "inc_files/inc_outstanding.php";
}
if ($useraction == "defineuser") {
    include "inc_files/inc_alertuser.php";
}
if ($timesheetaction && $_COOKIE[timesheethide] < time() && $hidealerts != "yes") {
    echo "<div>" . $timesheetaction . "</div>";
}
// Check for any upcoming holidays
if ($_GET[page] == NULL) {
    $today = TimeFormatDay(time());
    echo "<h1>{$today}</h1>";
    ListHolidays();
}
if ($useraction != "defineuser") {
    // Add the project title, if there is one either through POST or GET
    if ($proj_title) {
        echo $proj_title;
    }
    // Include the relevant page if the $_GET[page] variable is not blank, otherwise deliver the default page
    if ($page_redirect != NULL) {
        $inc_file = "inc_files/inc_" . $page_redirect . ".php";
    } elseif ($_GET[page] != NULL) {
        $inc_file = "inc_files/inc_" . $_GET[page] . ".php";
    } elseif ($_POST[page] != NULL) {
        $inc_file = "inc_files/inc_" . $_POST[page] . ".php";
function ListHolidays()
{
    global $conn;
    echo "<h2>Upcoming Holidays</h2>";
    $nowtime = time() - 43200;
    $sql5 = "SELECT user_id, user_name_first, user_name_second, holiday_date, holiday_timestamp, holiday_paid, holiday_length, holiday_approved FROM intranet_user_details, intranet_user_holidays WHERE holiday_user = user_id AND holiday_timestamp BETWEEN {$nowtime} AND " . ($nowtime + 2 * 604800) . " ORDER BY holiday_timestamp, user_name_second";
    $result5 = mysql_query($sql5, $conn) or die(mysql_error());
    if (mysql_num_rows($result5) > 0) {
        $current_date = 0;
        $holidaymessage = $holidaymessage . "<table>";
        while ($array5 = mysql_fetch_array($result5)) {
            if ($current_id != $user_id and $current_id > 0) {
                $holidaymessage = $holidaymessage . "</td></tr>";
            }
            $user_id = $array5['user_id'];
            $user_name_first = $array5['user_name_first'];
            $user_name_second = $array5['user_name_second'];
            $holiday_timestamp = $array5['holiday_timestamp'];
            $holiday_length = $array5['holiday_length'];
            $holiday_paid = $array5['holiday_paid'];
            $holiday_date = $array5['holiday_date'];
            $holiday_approved = $array5['holiday_approved'];
            $calendar_link = "index2.php?page=holiday_approval&amp;year=" . date("Y", $holiday_timestamp) . "#Week" . date("W", $holiday_timestamp);
            if ($holiday_approved == NULL) {
                $holiday_approved1 = "<span style=\"color: red;\">";
                $holiday_approved2 = "</span>";
            } else {
                unset($holiday_approved1);
                unset($holiday_approved2);
            }
            if ($current_date != $holiday_date) {
                $holidaymessage = $holidaymessage . "<tr><td>" . TimeFormatDay($holiday_timestamp) . "</td><td>";
            } else {
                $holidaymessage = $holidaymessage . ", ";
            }
            if ($holiday_length < 1) {
                $holiday_length = " (Half Day)";
            } else {
                unset($holiday_length);
            }
            $holidaymessage = $holidaymessage . "<a href=\"{$calendar_link}\">" . $holiday_approved1 . $user_name_first . " " . $user_name_second . $holiday_length . $holiday_approved2 . "</a>";
            $current_date = $holiday_date;
        }
        $holidaymessage = $holidaymessage . "</td></tr></table>";
    }
    echo $holidaymessage;
}