@extends('layouts.master')


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

@section('main')
<a href="{{ action('SchoolsController@show', array($school->id)); }}" class="btn btn-primary pull-left" alt="print">Go to Performance by School Courses</a>

<a href="{{ action('ProgramsController@print_program', array($school->id)); }}" class="btn btn-primary pull-right" alt="print"><span class="glyphicon glyphicon-print"></span></a>
<br>
<br>
<div class="row">
    <ul id="resultsTabs" class="nav nav-tabs" role="tablist">
        <li role="presentation" class="active"><a href="#combined" aria-controls="combined" role="tab">Combined</a></li>
        <li role="presentation"><a href="#uncombined" aria-controls="uncombined" role="tab">Uncombined</a></li>
    </ul>
	<div>
<!-- 	<div class="tab-content"> -->

	<div role="tabpanel" class="tab-pane active" id="combined">
	<div class="row">
		<div class="col-md-12" id="graph2"></div>
	</div>

            <div class="row">
                <div class="col-md-12">
                    <h3>Performance of {{ $school->name }} Students by Combined Learning Outcome</h3>
                    @if($outcomes->count()>0)
                        <table class="table table-striped table-condensed datatable">
                            <thead>
                                <tr>
                                    <th>Learning Outcome</th>
                                    <th>Program</th>
                                    <th>Program Id</th>
                                    <th>Program Is Graduate</th>
                                    <th>Number Students</th>
                                    <th>Number Students that Achieved the Target</th>
                                    <th>Percentage of Students that Achieved the Target</th>
                                    <th>Semesters</th>
                                </tr>
                            </thead>
                            <tfoot>
                                <tr class="column-search">
                                    <th><input class="column-search-bar form-control" type="text" placeholder="Search"/></th>
                                    <th><select class="column-search-select form-control"><option value=""></option></select></th>
                                    <th><select class="column-search-select form-control"><option value=""></option></select></th>
                                    <th><select class="column-search-select form-control"><option value=""></option></select></th>
                                    <th><input class="column-search-bar form-control" type="text" placeholder="Search"/></th>
                                    <th><input class="column-search-bar form-control" type="text" placeholder="Search"/></th>
                                    <th><select class="column-search-select form-control"><option value=""></option></select></th>
                                    <th><input class="column-search-bar form-control" type="text" placeholder="Search"/></th>
                                </tr>
                            </tfoot>
                            <tbody>
                                @foreach($programs as $program)
                                  @foreach($outcomes_colap as $outcome)
                                	@if(isset($outcomes_attempted_colap[$program->id][$outcome->id]))
                                    <tr>
										<td>{{ link_to_action('OutcomesController@show', $outcome->name, array($outcome->id), $attributes = array()) }}</td>
										<td>{{{ $program->name }}}</td>
										<td>{{{ $program->id }}}</td>
										<td>{{{ $program->is_graduate }}}</td>
										<td>{{{ $outcomes_attempted_colap[$program->id][$outcome->id] }}}</td>
										<td>{{{ $outcomes_achieved_colap[$program->id][$outcome->id] }}}</td>
										<td>
											@if($outcomes_attempted_colap[$program->id][$outcome->id]!=0)
												{{{ round($outcomes_achieved_colap[$program->id][$outcome->id] / $outcomes_attempted_colap[$program->id][$outcome->id]*100, 2) }}}%
											@else
												N/M
											@endif
										</td>
										<td>
										@if(isset($outcomes_attempted_colap_semesters[$program->id][$outcome->id]))
											{{{ str_replace('"','',json_encode($outcomes_attempted_colap_semesters[$program->id][$outcome->id])) }}}
										@else
											N/M
										@endif
										
										</td>
                                    </tr>
                       				@endif
                                  @endforeach
                                @endforeach
                            </tbody>
                        </table>
                    @else
                        <p class="lead"> No courses assigned.</p>
                    @endif
                </div>
            </div>
            </div>
		<div role="tabpanel" class="tab-pane" id="uncombined">
	<div class="row">
		<div class="col-md-12" id="graph"></div>
	</div>

            <div class="row">
                <div class="col-md-12">
                    <h3>Performance of {{ $school->name }} Students by Uncombined Learning Outcome</h3>
                    @if($outcomes->count()>0)
                        <table class="table table-striped table-condensed datatable">
                            <thead>
                                <tr>
                                    <th>Learning Outcome</th>
                                    <th>Program</th>
                                    <th>Program Id</th>
                                    <th>Program Is Graduate</th>
                                    <th>Number Students</th>
                                    <th>Number Students that Achieved the Target</th>
                                    <th>Percentage of Students that Achieved the Target</th>
                                    <th>Semesters</th>
                                </tr>
                            </thead>
                            <tfoot>
                                <tr class="column-search">
                                    <th><input class="column-search-bar form-control" type="text" placeholder="Search"/></th>
                                    <th><select class="column-search-select form-control"><option value=""></option></select></th>
                                    <th><select class="column-search-select form-control"><option value=""></option></select></th>
                                    <th><select class="column-search-select form-control"><option value=""></option></select></th>
                                    <th><input class="column-search-bar form-control" type="text" placeholder="Search"/></th>
                                    <th><input class="column-search-bar form-control" type="text" placeholder="Search"/></th>
                                    <th><select class="column-search-select form-control"><option value=""></option></select></th>
                                    <th><input class="column-search-bar form-control" type="text" placeholder="Search"/></th>
                                </tr>
                            </tfoot>
                            <tbody>
                                @foreach($programs as $program)
                               	   @foreach($outcomes as $outcome)
  											@if(isset($outcomes_attempted[$program->id][$outcome->id]))
                                  <tr>
										<td>{{ link_to_action('OutcomesController@show', $outcome->name, array($outcome->id), $attributes = array()) }}</td>
										<td>{{{ $program->name }}}</td>
										<td>{{{ $program->id }}}</td>
										<td>{{{ $program->is_graduate }}}</td>
										<td>{{{ $outcomes_attempted[$program->id][$outcome->id] }}}</td>
										<td>{{{ $outcomes_achieved[$program->id][$outcome->id] }}}</td>
										<td>
											@if($outcomes_attempted[$program->id][$outcome->id]!=0)
												{{{ round($outcomes_achieved[$program->id][$outcome->id] / $outcomes_attempted[$program->id][$outcome->id]*100, 2) }}}%
											@else
												N/M
											@endif
										</td>
										<td>
											@if(isset($outcomes_attempted_semesters[$program->id][$outcome->id]))
												{{{ str_replace('"','',json_encode($outcomes_attempted_semesters[$program->id][$outcome->id])) }}}
											@else
												N/M
											@endif
										
										</td>
                                    </tr>
											@endif
                                   @endforeach
                                @endforeach
                            </tbody>
                        </table>
                    @else
                        <p class="lead"> No courses assigned.</p>
                    @endif
                </div>
            </div>
</div>
	</div>
</div>
 <!-- ===== tabs ===== -->
<div class="row">
    <!-- Nav tabs -->
   <!-- Tab panes -->
    <ul id="programTabs" class="nav nav-tabs" role="tablist">
        <li role="presentation" class="active"><a href="#courses" aria-controls="courses" role="tab">Courses</a></li>
        <li role="presentation"><a href="#contact" aria-controls="contact" role="tab">Contact Information</a></li>
    </ul>
    <div class="tab-content">

       <div role="tabpanel" class="tab-pane active" id="courses">
            <div class="row">
                <div class="col-md-12">
                    <h3>Courses in this program</h3>
                    @if(count($grouped_courses)>0)
                        <table class="table table-striped table-condensed datatable">
                            <thead>
                                <tr>
                                    <th>Identifier</th>
                                    <th>Name</th>
                                    <th>Course Program</th>
                                    <th>Number of Students</th>
                                </tr>
                            </thead>
                            <tfoot>
                                <tr class="column-search">
                                    <th><input class="column-search-bar form-control" type="text" placeholder="Search"/></th>
                                    <th><input class="column-search-bar form-control" type="text" placeholder="Search"/></th>
                                <th><select class="column-search-select form-control"><option value=""></option></select></th>
                                    <th><input class="column-search-bar form-control" type="text" placeholder="Search"/></th>
                                </tr>
                            </tfoot>
                            <tbody>
                                @foreach($grouped_courses as $grouped_course)
                                    <tr>
                                        <td class="col-md-2">{{ HTML::linkAction('CoursesController@showGrouped', $grouped_course->code.$grouped_course->number.' ('.$grouped_course->semester->code.')', array($grouped_course->code, $grouped_course->number, $grouped_course->semester->code)) }}</td>
                                        <td class="col-md-4">{{{ $grouped_course->name}}}</td>
                                        <td class="col-md-2">{{{ $grouped_course->program_code}}}</td>
                                        <td class="col-md-3">{{{ $grouped_course->quantity }}}</td>
                                    </tr>
                                @endforeach
                            </tbody>
                        </table>
                    @else
                        <p class="lead"> No courses assigned.</p>
                    @endif
                </div>
            </div>
        </div>
        <div role="tabpanel" class="tab-pane" id="contact">
            <div class="row">
                <div class="col-md-12">
                    <h3>Contact Information</h3>
                    <table class="table table-striped datatable">
                        <thead>
                            <tr>
                                <th>Name</th>
                                <th>Role</th>
                                <th>Program</th>
                                <th>Email</th>
                                <th>Office Phone</th>
                            </tr>
                        </thead>
                        <tfoot>
                            <tr class="column-search">
                                <th><input class="column-search-bar form-control" type="text" placeholder="Search"/></th>
                                <th><select class="column-search-select form-control"><option value=""></option></select></th>
                                <th><select class="column-search-select form-control"><option value=""></option></select></th>
                                <th><input class="column-search-bar form-control" type="text" placeholder="Search"/></th>
                                <th><input class="column-search-bar form-control" type="text" placeholder="Search"/></th>
                            </tr>
                        </tfoot>
                        <tbody>
                            @foreach($users as $user)
                                <tr>
                                    <td>{{ $user->surnames }}, {{ $user->first_name }}</td>

                                    @if($user->role == 1)
                                        <td>Administrator</td>
                                        <td>All</td>
                                    @elseif($user->role == 2)
                                        <td>School Coordinator</td>
                                        <td>All in {{ $program->school->name }}</td>
                                    @elseif($user->role == 3)
                                        <td>Program Coordinator</td>
                                        <td>
                                            @foreach ($user->programs as $program)
                                                {{ $program->name }}&nbsp;
                                            @endforeach
                                        </td>
                                    @else
                                        <td>Professor</td>
                                        <td>
                                            @foreach ($user->programs as $program)
                                                {{ $program->name }}&nbsp;
                                            @endforeach
                                        </td>
                                    @endif

                                    <td>
                                        <a href="mailto:{{ $user->email }}">{{ $user->email }}</a>
                                    </td>
                                    <td>
                                        @if($user->office_phone)
                                            {{{ $user->office_phone }}}

                                            @if($user->office_extension)
                                                <span>ext.</span> {{{ $user->office_extension }}}
                                            @endif
                                        @else
                                            Not set
                                        @endif
                                    </td>
                                </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- ===== end tabs ===== -->

@stop

@section('included-js')

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

<!-- Datatables -->
@include('global._datatables_js')

@stop

@section('javascript')

$('#programTabs a').click(function (e) {
    e.preventDefault()
    $(this).tab('show');
});


$('#graph').highcharts({
    chart: {
        type: 'bar'
    },
    title: {
        text: 'Performance of {{ $school->name }} Students by Uncombined Learning Outcome'
    },
    legend: {
                reversed: true,
            },
    xAxis: {
        categories: [
            @foreach($outcomes as $outcome)
            	@if(isset($outcomes_attempted_todo[$outcome->id]))
                 "{{{ $outcome->name }}}<br>(N = {{{ $outcomes_attempted_todo[$outcome->id] }}}, {{{ $outcomes_achieved_todo[$outcome->id] }}})",
            	@else
                    "{{{ $outcome->name }}}<br>(N = 0, 0)",         	
            	@endif
            @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:70,
		color: '#000',
		width:3,
		zIndex:4,
		label:{
			text: 'Goal (70%)',
			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: '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_todo)
                    && array_key_exists($outcome->id, $outcomes_attempted_todo)
                    && $outcomes_attempted_todo[$outcome->id]!=0)
                @else
                    0,
                @endif
            @endforeach
        ]

    },{
        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_todo)
                    && array_key_exists($outcome->id, $outcomes_attempted_todo)
                    && $outcomes_attempted_todo[$outcome->id]!=0)
                    {{{ ($outcomes_achieved_todo[$outcome->id]/$outcomes_attempted_todo[$outcome->id])*100 }}},
                @else
                    0,
                @endif
            @endforeach
        ]
    }]
});

$('#graph2').highcharts({
    chart: {
        type: 'bar'
    }, 
    title: {
        text: 'Performance of {{ $school->name }} Students by Combined Learning Outcome'
    },
    legend: {
                reversed: true,
            },
    xAxis: {
        categories: [
            @foreach($outcomes_colap as $outcome)
                "{{{ $outcome->name }}}<br>(N = {{{ $outcomes_attempted_colap_todo[$outcome->id] }}}, {{{ $outcomes_achieved_colap_todo[$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:70,
		color: '#000',
		width:3,
		zIndex:4,
		label:{
			text: 'Goal (70%)',
			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: 'Expected Value',
        color: '#555555',
        dataLabels: {
            enabled: true,
            fontSize: 8,
            color: '#fff',
            align: 'right',
            format: '{y:.1f}%',
            style: {
                //fontWeight: 'bold'
            },
            y:-1
        },
        data: [
            @foreach($outcomes_colap as $index => $outcome)
                @if(
                    is_array($outcomes_attempted_colap_todo)
                    && array_key_exists($outcome->id, $outcomes_attempted_colap_todo)
                    && $outcomes_attempted_colap_todo[$outcome->id]!=0)
                @else
                    0,
                @endif
            @endforeach
        ]

    },{
        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_colap as $index => $outcome)
                @if(
                    is_array($outcomes_attempted_colap_todo)
                    && array_key_exists($outcome->id, $outcomes_attempted_todo)
                    && $outcomes_attempted_colap_todo[$outcome->id]!=0)
                    {{{ ($outcomes_achieved_colap_todo[$outcome->id]/$outcomes_attempted_colap_todo[$outcome->id])*100 }}},
                @else
                    0,
                @endif
            @endforeach
        ]
    }]
});

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

@stop
