<?php echo $this->insertTimeForm ?>
<div class="section">
    <div class="row">
        <div class="small-12 medium-4 text-left columns">
            <h3><i class="fa fa-calendar"></i> <?php echo $this->timesheet->currentMonthText ?> <a href="#" data-reveal-id="yearForm"><?php echo $this->timesheet->currentYear ?></a></h3>
        </div>
        <div class="small-12 medium-8 text-right columns hide-for-print">
            <ul class="button-group round even-5 stack-for-small">
                <li><a class="button small secondary" href="<?php echo $this->link(array('timesheet',$this->timesheet->currentYear,$this->timesheet->previousMonth)) ?>"><i class="fa fa-caret-left"></i> Prev.</a></li>
                <li><a class="button small secondary" href="<?php echo $this->link(array('timesheet',$this->timesheet->currentYear,$this->timesheet->nextMonth)) ?>">Next <i class="fa fa-caret-right"></i></a></li>
                <li><a class="button small toggleTotals" href="#"><i class="fa fa-calculator"></i> Totals</a></li>
                <li><a class="button small" href="#"><i class="fa fa-print"></i> Print</a></li>
                <?php
                    if($this->needsValidation)
                    {
                        echo "<li><a class=\"button small success\" href=\"".$this->link(array('timesheet','validate',$this->timesheet->currentYear,$this->timesheet->currentMonth))."\"><i class=\"fa fa-check\"></i> Validate</a></li>";
                    }
                ?>
            </ul>
        </div>
    </div><!-- end row -->
<?php
    echo "
        <div class=\"row\">
            <div class=\"small-12 columns hide-for-print\">
                <ul class=\"inline-list right\">
                    <li><a id=\"hideAll\" href=\"#\"><i class=\"fa fa-eye-slash\"></i> Hide All</a></li>
                    <li><a id=\"showAll\" href=\"#\"><i class=\"fa fa-eye\"></i> Show All</a></li>
                </ul>
            </div>
        </div>
    ";

    if(count($this->timesheet->entries) > 0)
    {
        echo "
            <div class=\"row\" style=\"margin-bottom:10px;\">
                <div class=\"small-4 medium-2 columns\">
                   &nbsp;
                </div>
                <div class=\"small-4 medium-2 columns\">
                    <b>Time In</b> <small>(Adjusted)</small>
                </div>
                <div class=\"small-4 medium-2 columns\">
                    <b>Time Out</b> <small>(Adjusted)</small>
                </div>
                <div class=\"small-4 medium-2 columns\">
                    <b>Less Time</b>
                </div>
                <div class=\"small-4 medium-2 columns\">
                    <b>Total</b>
                </div>
                <div class=\"small-4 medium-2 columns\">
                    <b>Code</b>
                </div>
            </div><!-- end row -->
        ";

        $date = 0;

        foreach($this->timesheet->entries as $entry)
        {
            if($date != $entry->date)
            {
                if($this->timesheet->getBatch() != $entry->batchId)
                {
                    echo "
                    <div class=\"row marker\" style=\"border-bottom:1px #ccc solid; background-color:#eaeaea; padding-top:15px; padding-bottom:15px;\"> \n
                        <div class=\"small-12 columns timeTitle\" >
                            <b>".$entry->fullDate."</b><i class=\"right fa fa-chevron-up\"></i>\n
                        </div>
                    </div> <!-- end row --> \n
                    ";
                }
                else
                {
                    echo "
                    <div class=\"row marker\" style=\"border-bottom:1px #ccc solid; background-color:#FFF4A8; padding-top:15px; padding-bottom:15px;\"> \n
                        <div class=\"small-12 columns timeTitle\" >
                            <b>".$entry->fullDate."</b><i class=\"right fa fa-chevron-up\"></i>\n
                        </div>
                    </div> <!-- end row --> \n
                    ";
                }
            }

            echo "
            <div class=\"row\" style=\"border-bottom:1px #ccc solid; padding:10px;\"> \n
               <div class=\"small-4 medium-2 columns\"> \n";

               if($this->timesheet->getBatch() == $entry->batchId)
               {
                    echo "<a class=\"button radius tiny\" style=\"margin:0px; width:100%; left:-15px;\" href=\"".$this->link(array('timesheet','edit',$entry->id))."\"><i class=\"fa fa-edit\"></i> Edit</a> \n";
               }
               else
               {
                   echo "<i class=\"fa fa-lock\"></i> Validated \n";
               }

            echo "
                </div> \n
                <div class=\"small-4 medium-2 columns\"> \n
                    <span data-tooltip aria-haspopup=\"true\" class=\"has-tip\" title=\"Entered as: ".$entry->inTime."\">".$entry->roundedInTime."</span> \n
                </div> \n
                <div class=\"small-4 medium-2 columns\"> \n
                    <span data-tooltip aria-haspopup=\"true\" class=\"has-tip\" title=\"Entered as: ".$entry->outTime."\">".$entry->roundedOutTime."</span> \n
                </div> \n
                <div class=\"small-4 medium-2 columns\"> \n
                    ".$entry->lessTime." Min. \n
                </div> \n
                <div class=\"small-4 medium-2 columns\"> \n
                    ".$entry->timeWorked." Hours \n
                </div> \n
                <div class=\"small-4 medium-2 columns\"> \n
                    ".$entry->codeName." \n
                </div> \n
            </div> <!-- end row --> \n
            ";

            $date = $entry->date;
        }
    }
    else
    {
        echo "
            <div class=\"row\">
                <div class=\"small-12 columns text-center\">
                    No time submitted.
                </div>
            </div><!-- end row -->
        ";
    }
?>
</div><!-- end section -->

<div id="yearForm" class="reveal-modal small" data-reveal aria-labelledby="Change Year" aria-hidden="true" role="dialog">
    <h2 id="modalTitle">Select a Year</h2>
    <?php echo $this->changeYearForm ?>
    <a class="close-reveal-modal" aria-label="Close">&#215;</a>
</div>

<div id="totals" class="totalsPanel">
    <div class="row">
        <div class="small-10 columns">
            <h3 id="modalTitle"><i class="fa fa-calculator"></i> Totals for this month</h3>
        </div>
        <div class="small-2 columns text-right">
            <a class="button small radius toggleTotals" href="#"><i class="fa fa-chevron-up"></i></a>
        </div>
    </div> <!-- end row -->
    <div class="row">
        <?php

        foreach($this->timesheet->totals as $key=>$value)
        {
            if($value != '0')
            {
                echo "
                    <div class=\"small-6 medium-4 columns totals end\">
                    ".$key.": ".$value."
                    </div>
                ";
            }
        }

        ?>
    </div>
</div>

<script>
    $(function() {
        $(".toggleTotals").click(function() {

            if($("#totals").is(":visible"))
            {
                $('#entryForm').slideDown();
            }
            else
            {
                $('#entryForm').slideUp();
            }

            $("#totals").slideToggle();
        });

        $(".timeTitle").click(function() {
            $(this).parent().nextUntil(".marker").slideToggle("slow");
            $(this).find("i").toggleClass("fa-chevron-up fa-chevron-down")
            return false;
        });

        $("#hideAll").click(function() {
           $(".marker").nextUntil(".marker").slideUp();
            $(".marker").find("i").removeClass("fa-chevron-up")
            $(".marker").find("i").addClass("fa-chevron-down")
            return false;
        });

        $("#showAll").click(function() {
            $(".marker").nextUntil(".marker").slideDown();
            $(".marker").find("i").removeClass("fa-chevron-down")
            $(".marker").find("i").addClass("fa-chevron-up")
            return false;
        });

    });
</script>