<?php echo $this->insertTimeForm ?>
<div class="section">
    <div class="row">
        <div class="small-6 text-left columns">
            <h2><i class="fa fa-calendar"></i> <?php echo $this->timesheet->currentMonthText ?> <?php echo $this->timesheet->currentYear ?></h2>
        </div>
        <div class="small-6 text-right columns">
            <?php
            if($this->needsValidation)
            {
                echo "<a class=\"button round success\" href=\"".$this->link(array('timesheet','validate',$this->timesheet->currentYear,$this->timesheet->currentMonth))."\"><i class=\"fa fa-check\"></i> Validate</a>";
            }
            ?>
        </div>
        <div class="small-12 text-center columns hide-for-print">
            <ul class="button-group radius even-7">
                <?php

                $year = $this->year;

                if($this->month == 12)
                {
                    $year = $this->nextYear;
                }

                if($this->momth == 1)
                {
                    $year = $this->previousYear;
                }
                ?>

                <li><a class="button small secondary" href="
                    <?php
                    switch ($this->month)
                    {
                        case 01:
                            echo $this->link(array('timesheet',$this->previousYear, $this->previousMonth));
                            break;
                        default:
                            echo $this->link(array('timesheet',$this->year, $this->previousMonth));
                    }
                    ?>
                    "><i class="fa fa-caret-left"></i> Previous</a></li>
                <li><a class="button small secondary" href="<?php echo $this->link(array('timesheet',$this->currentYear,$this->currentMonth))?>"><i class="fa fa-flag"></i> Current</a></li>
                <li><a class="button small secondary" href="
                    <?php
                    switch ($this->month)
                    {
                        case 12:
                            echo $this->link(array('timesheet',$this->nextYear, $this->nextMonth));
                            break;
                        default:
                            echo $this->link(array('timesheet',$this->year, $this->nextMonth));
                    }
                    ?>
                    ">Next <i class="fa fa-caret-right"></i></a></li>
                <li><a class="button small secondary" id="hideAll" href="#"><i class="fa fa-eye-slash"></i> Hide All</a></li>
                <li><a class="button small secondary" id="showAll" href="#"><i class="fa fa-eye"></i> Show All</a></li>
                <li><a class="button small toggleTotals" href="#"><i class="fa fa-calculator"></i> Totals</a></li>
                <li><a class="button small" target="_blank" href="<?php echo $this->link(array('timesheet','printpreview',$this->timesheet->userId,$this->timesheet->currentYear,$this->timesheet->currentMonth)) ?>"><i class="fa fa-print"></i> Print</a></li>
            </ul>
        </div>
    </div><!-- end row -->
<?php
    if(count($this->timesheet->entries) > 0)
    {
        echo "
            <div class=\"row\" style=\"padding-top:20px; padding-bottom:10px; background-color:#ccc;\">
                <div class=\"small-4 medium-2 columns\">
                    <b>Status</b>
                </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=\"padding-top:5px;\"> \n
               <div class=\"small-4 medium-2 columns\"> \n";
               if($entry->batchId == "ADMIN ADD")
               {
                   echo "<i class=\"fa fa-warning\"></i> Admin. Add";
               }
               else
               {
                   if($this->timesheet->getBatch() == $entry->batchId)
                   {
                       echo "<a class=\"\" style=\"margin:0px; width:100%; left:-15px;\" href=\"".$this->link(array('timesheet','edit',$entry->id))."\"><i class=\"fa fa-edit\"></i> Edit Entry</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>
            <div class=\"row\" style='border-bottom:1px #a7a7a7 solid; '>
                <div class=\"small-12 medium-10 medium-push-2 columns\"> \n
                   ".$entry->note."
                </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="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>