@extends('layouts.master')

@section('navigation')
    @if($role==1)
        @include('local.managers.admins._navigation')
    @elseif($role==2)
        @include('local.managers.sCoords._navigation')
    @elseif($role==3)
        @include('local.managers.pCoords._navigation')
    @else
        @include('local.professors._navigation')
    @endif
@stop

@section('main')

<!-- New Activity Modal -->
<div class="modal fade" id="newActivityModal" tabindex="-1" role="dialog" aria-labelledby="newActivityModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="newActivityModalLabel">New Activity</h4>
            </div>
            <div class="modal-body">
                {{ Form::open(array('action' => array('ActivitiesController@create', $course->id))) }}
                    <div class="form-group">
                        {{ Form::label('name', 'Name') }}
                        {{ Form::text('name', Input::old('name'), array('class' => 'form-control')) }}
                    </div>
                    <div class="form-group">
                        {{ Form::label('description', 'Description') }}
                        {{ Form::textarea('description', Input::old('description'), array('class' => 'form-control', 'rows'=> 5, 'placeholder'=>'Minimum 10 characters')) }}
                    </div>
                    <div class="btn-group" role="group">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        <button type="submit" class="btn btn-default btn-primary">Submit</button>
                    </div>
                {{ Form::close() }}
            </div>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-12">
        <p>{{$course->name}}</p>

    </div>
</div>

<div id="dummy-graph-container" class="row">
    @if(is_array($outcomes_attempted))
    <div class="col-md-12" id="graph"></div>
    @else
    <div id="overlay"><h2>No Data</h2></div>
    <div class="col-md-12" id="dummy"></div>
    @endif
</div>


<div class="row">
    <div class="col-md-7">
        <h3>Activities</h3>

        @if(!$activities->isEmpty())

            @if (in_array($course->semester->id, $active_semesters))
                <button data-toggle="modal" data-target="#newActivityModal" class="btn btn-sm btn-default pull-right"> New Activity</button>
            @endif

            <table class="table table-striped table-condensed">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Date</th>
                        <th>Updated</th>
                        <th>Assessed</th>
                        <th>Published</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach ($activities as $activity)
                    <tr>
                        <td>{{ link_to_action('ActivitiesController@show', $activity->name, $parameters = array('id'=>$activity->id)) }}</td>
                        <td>{{ date('M d, Y', strtotime($activity->date)) }}</td>
                        <td>{{ date('M d, Y', strtotime($activity->updated_at)) }}</td>
                        <td>
                            @if($activity->outcomes_attempted!=NULL)
                                <span class="glyphicon glyphicon-ok"></span>
                            @endif
                        </td>
                        <td>
                            @if($activity->outcomes_attempted!=NULL && !$activity->draft)
                                <span class="glyphicon glyphicon-ok"></span>
                            @endif
                        </td>
                    </tr>
                    @endforeach

                    @if (!in_array($course->semester->id, $active_semesters))
                    <tr>
                        <td colspan="3"><div class="alert alert-info">The semester for this course is inactive. You cannot create any more activities.</div></td>
                    </tr>
                    @endif
                </tbody>
            </table>

            <p>Unplublished activity results are <strong>not considered</strong> in the graph above.</p>

        @else
            <div class="alert alert-info">
                @if(in_array($course->semester->id, $active_semesters))
                <p>
                    No activities.
                    <a data-toggle="modal" data-target="#newActivityModal">
                        Create one.
                    </a>
                </p>
                @else
                    <p>The semester for this course is inactive. You cannot create any activities.</p>
                @endif
            </div>
        @endif
    </div>
    <div class="col-md-5">
        <h3>Students</h3>
        @if(!$students->isEmpty())

            <!-- If any section is assessed -->
            @if($course->outcomes_attempted!=NULL)
                {{ HTML::linkAction('CoursesController@exportGrades', 'Export grades to CSV file', array('id'=>$course->id), array('class'=>'btn btn-default btn-sm pull-right')) }}
            @endif


            <table class="table table-striped table-condensed">
                <thead><tr>
                    <th></th>
                    <th>Name</th>
                    <th>Number</th>
                    <th>School</th>
                    <th>Major</th>
                </tr></thead>
                <tbody>
                @foreach ($students as $i => $student)
                    <?php $formatted_student_number = substr($student->number, 0, 3).'-'.substr($student->number, 3, -4).'-'.substr($student->number, 5, 8); ?>
                    <tr>
                        <td>{{$i+1}}</td>
                        <td><a href="{{ URL::action('StudentsController@show', array('semester'=>$course->semester_id, 'id'=>$course->code.$course->number.'-'.$course->section, 'number'=>$student->number)) }}">{{ $student->name }}</a></td>
                        <td>{{ $formatted_student_number }}</td>
                        <td>{{ $student->school_code }}</td>
                        <td>{{ $student->conc_code }}</td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        @else
            <div class="alert alert-info"><p>No students. <a href=""></a></p></div>
        @endif
    </div>
</div>
@stop

@section('included-js')

<!-- HighCharts -->
<script src="{{ asset('vendor/highcharts/highcharts.js') }}"></script>
<!--script src="http://code.highcharts.com/modules/exporting.js"></script -->

@stop

@section('javascript')
$(function () {
    $('#graph').highcharts({
        chart: {
            type: 'bar'
        },
        title: {
            text: 'Performance by Learning Outcome Criteria in {{ $title }}'
        },
        xAxis: {
            categories: [
                @foreach($outcomes as $outcome)
                    "{{{ $outcome->name }}}",
                @endforeach
            ],
            labels: {
                style: {
                    fontSize:'11px'
                },
                step:1,
                useHTML:true,
                formatter: function() {
                    return '<div style="width:200px; word-break:break; text-overflow:ellipsis; overflow:hidden;">'+this.value+'</div>';
                },
            }
        },
        yAxis: {
            min: 0,
            max: 100,
            title: {
                text: 'Percentage'
            }
        },
        tooltip: {
            headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
            pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
                '<td style="padding:0"><b>{point.y:.2f}</b></td></tr>',
            footerFormat: '</table>',
            shared: true,
            useHTML: true
        },
        plotOptions: {
            bar: {
                //grouping: false,
                shadow: false,
                borderWidth: 0,
            },
            series: {
            pointPadding: 0,
            groupPadding: 0.075
            },
        },
        series: [{
            name: 'Obtained Value',
            color: '#e70033',
            dataLabels: {
                enabled: true,
                fontSize: 8,
                color: '#fff',
                align: 'right',
                format: '{y:.1f}%',
                style: {
                    //fontWeight: 'bold'
                },
                y:-1
            },
            data:[
                @foreach($outcomes as $index => $outcome)
                    @if(
                        is_array($outcomes_attempted)
                        && array_key_exists($outcome->id, $outcomes_attempted)
                        && $outcomes_attempted[$outcome->id]!=0)
                        {{{ ($outcomes_achieved[$outcome->id]/$outcomes_attempted[$outcome->id])*100 }}},
                    @else
                        0,
                    @endif
                @endforeach

            ],
            pointPadding: 0,
        }, {
            name: 'Expected Value',
            color: '#555555',
            dataLabels: {
                enabled: true,
                fontSize: 8,
                color: '#fff',
                align: 'right',
                format: '{y:.1f}%',
                style: {
                    //fontWeight: 'bold'
                },
                y:-1
            },
            data: [
                @foreach($outcomes as $index => $outcome)
                    @if(
                        is_array($outcomes_attempted)
                        && array_key_exists($outcome->id, $outcomes_attempted)
                        && $outcomes_attempted[$outcome->id]!=0)
                        {{{ $outcome->expected_outcome }}},
                    @else
                        0,
                    @endif
                @endforeach
            ],
            pointPadding: 0,

        }]
    });

    // Include dummy graph for outcomes
    @include('global.dummy-outcomes')
});

@stop