@extends('layouts.master')

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

@section('main')

	<div class="row">
		<div class="col-md-12">
			<p>{{$course->name}}</p>
		</div>
	</div>
    <div class="row">
        <div class="col-md-12" id="graph">
        </div>
    </div>
	<div class="row">
        <div class="col-md-5">
            <h4>Section Information</h4>
            <table class="table table-striped table-condensed">
                <tbody>
                    <tr>
                        <td>Professor</td>
                        <td>{{{ $course->user->surnames }}}, {{{ $course->user->first_name }}}</td>
                    </tr>
                    <tr>
                        <td>School</td>
                        <td>{{{ $course->program->school->name }}}</td>
                    </tr>
                    <tr>
                        <td>Program</td>
                        <td>{{{ $course->program->name }}}</td>
                    </tr>
                    <tr>
                        <td>Activities</td>
                        <td> {{{ $course->activities->count() }}}</td>
                    </tr>
                    <tr>
                        <td>Students</td>
                        <td>{{{ $course->students->count() }}}</td>
                    </tr>
                </tbody>
            </table>

            <h4>Students</h4>
            @if(!$students->isEmpty())
                <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>
                    <tbdody>
                    @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>{{ $student->name }}</td>
                            <td>{{ $formatted_student_number }}</td>
                            <td>{{ $student->school_code }}</td>
                            <td>{{ $student->conc_code }}</td>
                        </tr>
                    @endforeach
                    </tbdody>
                </table>
            @else
                <div class="alert alert-info"><p>No students. <a href=""></a></p></div>
            @endif
        </div>
        <div class="col-md-7">
            <h4>Activities</h4>
            @if($course->activities->count())
                <table class="table table-striped table-condensed">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Date</th>
                            <th>Rubric</th>
                            <th>Transformative Action</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($course->activities as $activity)
                        <tr>
                            <?php
                                Log::info($activity);
                                Log::info($activity->rubric);
                                $bool = empty($activity->rubric);
                                Log::info($bool);
                                
                                ?>
                            <td>{{{ $activity->name }}}</td>
                            <td>{{{ date('m/d/y', strtotime($activity->updated_at))  }}}</td>
                            <td>
                                @if(isset($activity->rubric[0]))
                                    {{ HTML::linkAction('RubricsController@show_limited', $activity->rubric[0]->name, array($activity->rubric[0]->id)) }}
                                @endif
                            </td>
                            @if(isset($activity->transforming_action))
                            <td><strong>{{ $activity->transforming_action->at_text }}: </strong>{{$activity->transforming_action->description}}</td>
                            @else
                            <td></td>
                            @endif
                        </tr>
                        @endforeach
                    </tbody>
                </table>
            @else
            None
            @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 }}}<br>(N = {{$outcomes_attempted[$outcome->id]}}, {{$outcomes_achieved[$outcome->id]}})",
                @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'
            }, 
            
                    plotLines:[{
                value:66.67,
                color: '#000',
                width:3,
                zIndex:4,
                label:{
                    text: 'Goal (66.67%)',
                    style: {
                        color: '#000',
                        fontSize: '14px',
                    }
        
                }
            }]
        },
        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

            ]
        }/*, {
            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
            ]

        }*/]
    });
});

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

@stop