@extends('admin.admin-master') 
@section('content')
<div>&nbsp; </div>
@if (Session::has('message'))
<span class="alert {{Session::get('class')}}">
    {{Session::get('message')}}
</span>
@endif
<div>&nbsp; </div>

<h3><i class="fa fa-dashboard"></i> Dashboard </h3>
<div>&nbsp; </div>
<!--- Main Panel ----->
<div class="col-md-12">
    <div class="row">
        <!--- 1st box --->
        <div class="col-sm-3 animated slideInDown">
            <div class="hero-widget well well-sm ">
                <div class="icon text-info">
                    <i class="fa fa-users"></i>
                </div>
                <div class="text">
                    <var>{{$dashboard_data['user_count']}}</var>
                    <label class="text-muted">Invited users by fb share</label>
                </div>
            </div>
        </div>
        <!--- 2nd box --->
        <div class="col-sm-3 animated slideInDown">
            <div class="hero-widget well well-sm">
                <div class="icon text-info">
                    <i class="fa fa-meh-o"></i>
                </div>
                <div class="text">
                    <var>{{$dashboard_data['last_week_user']}}</var>
                    <label class="text-muted">Users of last 10 days</label>
                </div>
            </div>
        </div>
        <!--- 3rd box --->
        <div class="col-sm-3 animated slideInDown">
            <div class="hero-widget well well-sm">
                <div class="icon text-info">
                    <i class="fa fa-facebook"></i>
                </div>
                <div class="text">
                    <var>{{$dashboard_data['is_shared']}}</var>
                    <label class="text-muted">Total fb share of the Quiz</label>
                </div>
            </div>
        </div>
        <!--- 4th box --->
        <div class="col-sm-3 animated slideInDown">
            <div class="hero-widget well well-sm">
                <div class="icon text-info">
                    <i class="fa fa-certificate"></i>
                </div>
                <div class="text">
                    <var>{{$dashboard_data['quiz_complete']}}</var>
                    <label class="text-muted">Number of completed quiz</label>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="col-md-12">
    <div class="row">
        <div class="col-md-6">
            <h3>User activity graph ({{$graph_date}}) </h3>
        </div>
        <div class="col-md-3 text-right">
            <h5>Select a day</h5>
        </div>
        <div class="col-md-3">
            <?php
            $date = array(
                Util::getDate(date('Y-m-d'), 'Y-m-d') => 'Today' ,
                Util::getPreviousDayDate(date('Y-m-d')) => 'Yesterday',
                Util::getPreviousDayDate(Util::getPreviousDayDate(date('Y-m-d'))) => '2 Days ago',  );
            ?>
            {{ Form::select('graph_date',$date,Input::get('graph_date'),array('class'=>'form-control','id'=>'graph_date')) }}
        </div>
        <script>
            $('#graph_date').change(function(){
            date = $(this).val();
                    window.location = '?graph_date=' + date;
            });</script>
    </div>
    <!-- Graph chart -->
    <div class="row">
        <div>
            <canvas id="canvas" height="30%" width="100%"></canvas>
        </div>
    </div>
    <!-- // Graph chart -->

    <script>
                var randomScalingFactor = function() {
                return Math.round(Math.random() * 100)
                };
                var lineChartData = {
                labels:  {{$hours}},
                        datasets: [
                        {
                        label: "User Quiz Graph",
                                fillColor: "rgba(220,220,220,0.2)",
                                strokeColor: "#192f42",
                                pointColor: "rgba(220,220,220,1)",
                                pointStrokeColor: "#192f42",
                                pointHighlightFill: "#fff",
                                pointHighlightStroke: "rgba(220,220,220,1)",
                                data:  {{$count}}
                        }
                        ]
                }
    </script>
    <script>
        window.onload = function() {
        var ctx = document.getElementById("canvas").getContext("2d");
                window.myLine = new Chart(ctx).Line(lineChartData, {
        responsive: true
        });
        }
    </script>

</div>
<!-- Recent Activity -->
<div class="col-md-12">
    <h3> Recent Activity </h3>
    <div class="row">
        {{Form::open(array('url'=>'/admin','method'=>'GET'))}}
        <form action="/admin" method="GET">
            <div class="col-md-3">
                <?php $listOfValue = array();
                $listOfValue[0] = 'Select group';
                ?>

                @foreach($group_list as $g)
                <?php

                $listOfValue[$g->group_id] = $g->group_name;
                ?>
                @endforeach
                <div class="form-group">
                    {{ Form::select('group',$listOfValue,Input::get('group'),array('class'=>'form-control')) }}
                </div>
            </div>
            <div class="col-md-3">
            </div>
            <div class="col-md-3">
            </div>
            <div class="col-md-3">
                {{Form::button('<i class="fa fa-search"></i> Search ',array('class'=>'btn btn-default btn-sm btn-block' , 'type'=>'submit'))}}
            </div>
            {{Form::close()}}
    </div>
    <table class="table table-condensed">
        <tr>
            <th> Name </th>
            <th class="hidden-xs">Quiz date</th>
            <th class="hidden-xs">Group name</th>
            <th>True ans</th>
            <th>False ans</th>
            <th> % </th>
            <th>Status</th>
            <th class="hidden-xs">Total</th>
        </tr>
        @foreach($recent_data as $rd)
        <tr>
            <td> <img src="https://graph.facebook.com/{{$rd->fbid}}/picture" class="img-circle" style="width: 20px">
                {{--<img src="{{url()}}/public/images/{{rand(1,10)}}.jpg" class="img-circle" style="width: 20px"> --}}
                <a href="https://facebook.com/2"> {{$rd->name}}</a>
            </td>
            <td class="hidden-xs">{{Util::getdate($rd->quiz_date,'Y-m-d h:i A')}}</td>
            <td class="hidden-xs">{{$rd->group_name}}</td>
            <td>{{$rd->true_ans}}</td>
            <td>{{$rd->false_ans}}</td>
            <td>{{$rd->avg_grade}}%</td>
            <td>{{($rd->false_ans>0)?'<span class="text-danger"><i class="fa fa-times"></i></span>':'<span class="text-success"><i class="fa fa-check"></i></span>'}}</td>
            <td class="hidden-xs">{{$rd->total}}</td>
        </tr>
        @endforeach
    </table>
    <center>
        {{$recent_data->appends(array('group'=>Input::get('group')))->links()}}
    </center>
</div>
<!-- Recent Activity -->
<!-- Main Panel End -->
<!-- By Arifur Rahman -->
@stop
