<?php $__env->startSection('page_title'); ?>
    OSAA - Forms
<?php $__env->stopSection(); ?>

<?php $__env->startSection('page_sub_title'); ?>    
	<?php echo $info['school_year']; ?>-<?php echo substr(intval($info['school_year']) + 1, 2, 2); ?> <?php echo $info['online_form']->name; ?> Forms
<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
    @parent

    <style type="text/css">
    	
        h2 {
            color: #1C43A6 !important;
        }

        h2.line {
            border-bottom: 1px solid #1C43A6;
            padding-bottom: 0.25em;
            margin-bottom: 0.25em;
        }

        h3 {
            color: #990000 !important;
        }
        
        .success_bar {
            position: fixed;
            top: 600px;
            left: 0;
            width: 100%;
            padding: 0.25em 0;
            line-height: 1.5em;
            background-color: rgba(176, 255, 190, 0.0);
            border-bottom: 2px solid rgba(13, 88, 27, 0.50);
            border-top: 2px solid rgba(13, 88, 27, 0.50);
            z-index: 500;
        }

        .success_bar .message {
            width: 1200px;
            margin: 0 auto;
            font-size: 14pt;
            color: #151515;
        }       

        .page_functions {
            width: auto !important;
        }  

        .odd {
            background-color: #dedede;
        }

        table.data_table {
            border-collapse: collapse;
            width: 100%;
            font-size: 10pt;
        }

        .data_table thead {
            background-color: #005FA9;
            color: #ffffff;
        }

        .data_table thead th {            
            padding: 4px 2px;
            text-align: left;
            vertical-align: bottom;
        }

        .data_table tbody tr {
            line-height: 2.5em;
        }
    
    </style>
	
<?php $__env->stopSection(); ?>

<?php $__env->startSection('jquery_init'); ?>
	
    if(!window.console)
    {
        window.console = { log: $.noop, group: $.noop, groupEnd: $.noop };            
    }

    $('[data-tabs]').tabs();

    // Success bar
    $('.success_bar').animate({ 'top' : 32, 'background-color' : 'rgba(176, 255, 190, 1.0)'}, 1600, 'easeOutQuad', function ()
    {       
        $(this).delay(6000).fadeOut(4000);  

        $(this).hover(function ()
        {
            $(this).stop(true).css('opacity', '1.0');
        },
        function ()
        {
            $(this).fadeOut(4000);
        })
    });   


    /* 
     * Custom tooltip items
     */
    $('[data-tooltip]').each(function ()
    {
        var item = $(this);

        var help = item.attr('data-tooltip');
        
        item.tooltip({'content' : help, 'items' : item});
    });


    /* Status Log
     *
     * Shows the status history when item is clicked.
     */
    $('[data-log]')
        .click(function(event)
        {
            var item = $(this);
            var log = $.parseJSON(item.attr('data-log'));
            var created = item.attr('data-created');
            var updated = item.attr('data-updated');
            var school = item.attr('data-school');
            var form_id = item.attr('data-form-id');

            var html = '<div style="font-size: 9pt;">';
            
            html += '<div style="float: right; width: 150px;">Form ID: ' + form_id + '<br />`school_forms`</div>';
            html += '<div style="display: inline-block; width: 125px;">Last Updated:</div>' + updated + '<br />';
            html += '<div style="display: inline-block; width: 125px;">Form Created:</div>' + created + '<br />';
            
            html += '<table style="width: 100%; border-collapse: collapse; margin-top: 1em;"><tbody>';

            $.each(log, function(index, value)
            {
                if ((index % 2) == 0)
                {
                    html += '<tr style="background-color: #dedede;">';
                }
                else
                {
                    html += '<tr>';
                }

                html += '<td style="padding-right: 15px;vertical-align: top;">' + value.timestamp + '</td>';
                html += '<td style="padding-right: 15px;vertical-align: top;">' + value.action + '</td>';
                html += '<td style="vertical-align: top;">' + value.user + '<br /><i>' + value.notes + '</i></td></tr>';
            });

            html += '</tbody></table></div>';

            $('<div></div>')
                .appendTo('body')
                .dialog(
                {                       
                    resizable: false,
                    height: 'auto',
                    width: 550,
                    modal: false,                    
                    title: school + ' Status Log',
                    open : function ()
                        {  
                            var dialog_object = $(this);                            

                            dialog_object.html(html);
                        },
                    close : function ()
                        {
                            var dialog_object = $(this);

                            $(dialog_object).remove();
                        }                
                });

        })
        .hover(function()
        {
            $(this).css({'cursor':'pointer'});
        },
        function()
        {
            $(this).css({'cursor':''});
        })
        .tooltip({'content':'Click to view detailed status history.','items':'[data-log]'});


    $('.download_report').each(function(index)
    {
        var item = $(this);

        var right = item.attr('data-right');

        item.button();
        item.css({'font-size' : '8pt',
                  'position' : 'absolute',
                  'top' : '9px',
                  'right' : right});
    });      

   
<?php $__env->stopSection(); ?>

<?php $__env->startSection('page_functions'); ?> 	

	

<?php $__env->stopSection(); ?>


<?php $__env->startSection('main_content'); ?>          

    <?php /*  Success Bar  */ ?>
    <?php if (Session::has('success')): ?>
        <div class="success_bar">
            <div class="message">               
                <?php echo Session::get('success'); ?>
            </div>          
        </div>
    <?php endif; ?>        

    <?php /*  Form Data by Season  */ ?>
    <div data-tabs="true" style="width: 100%; position: relative;">    

        <ul style="padding-left: 5px; font-size: 10pt;">
            <?php foreach ($info['seasons'] as $season_slug => $season_name): ?>
                <li><a href="#tabs-<?php echo $season_slug; ?>"><?php echo $season_name; ?></a></li>
            <?php endforeach; ?>
        </ul>

        <?php foreach ($info['seasons'] as $season_slug => $season_name): ?>

            <div id="tabs-<?php echo $season_slug; ?>" style="padding: 10px 2px 4px 2px;">

                <a href="<?php echo url('/forms/seasonal/' . strtolower($season_name) . '/participation'); ?>" target="_blank" class="download_report" data-right="16px" data-season="<?php echo strtolower($season_name); ?>">Participation Summary</a>

                <a href="<?php echo url('/forms/seasonal/' . strtolower($season_name) . '/preselection'); ?>" target="_blank" class="download_report" data-right="183px" data-season="<?php echo strtolower($season_name); ?>">Preselections</a>

                <table class="data_table" id="data_<?php echo $season_slug; ?>">
                    <thead>
                        <tr>
                            <th style="width: 215px;">School</th>
                            <th>Status</th>
                            <?php
                                $column_count = 0;
                            ?>
                            <?php foreach ($info['online_form']->data_format->activities as $activity_object): ?>
                                <?php
                                    // Only list activities in this season
                                    if (!Helpers::strEqual($activity_object->season, $season_slug))
                                    {
                                        continue;
                                    }

                                    $column_count++;
                                ?>
                                <th style="text-align: center;"><?php echo $activity_object->slug; ?></th>
                            <?php endforeach; ?>                            
                        </tr>
                    </thead>

                    <tbody>
                        <?php
                            $count = 0;
                        ?>
                        <?php foreach ($info['school_objects'] as $school_object): ?>

                            <tr <?php echo (($count++ % 2) == 1) ? ' class="odd"' : null; ?>>
                                <td style="padding-left: 5px;">
                                    <?php echo $school_object->school->short_name; ?>
                                </td>
                                <td>
                                    <img 
                                        <?php if ($school_object->{ $season_slug}->code == 2): ?>
                                            src="<?php echo asset('/images/icons/finished_16px.png'); ?>"
                                        <?php elseif ($school_object->{ $season_slug}->code == 1): ?>
                                            src="<?php echo asset('/images/icons/pending_16px.png'); ?>"
                                        <?php else: ?>
                                            src="<?php echo asset('/images/icons/never_started_16px.png'); ?>"
                                        <?php endif; ?>
                                        alt=""
                                        title=""
                                        style="vertical-align: middle;"
                                        <?php if (!is_null($school_object->{ $season_slug }->form)): ?>
                                            data-log="<?php echo htmlentities(json_encode($school_object->{ $season_slug }->form->data->status_history), ENT_QUOTES, 'UTF-8'); ?>"
                                            data-created="<?php echo date('n/j/Y g:ia', strtotime($school_object->{ $season_slug }->form->created_at)); ?>"
                                            data-updated="<?php echo date('n/j/Y g:ia', strtotime($school_object->{ $season_slug }->form->updated_at)); ?>"
                                            data-school="<?php echo $school_object->school->short_name; ?>"
                                            data-form-id="<?php echo $school_object->{ $season_slug }->form->id; ?>"
                                        <?php endif; ?>
                                    />

                                    <?php echo $school_object->{ $season_slug }->status; ?>

                                    <?php if ($school_object->{ $season_slug}->code != 2 and !Helpers::strIsEmpty($school_object->email_link)): ?>
                                        <a href="<?php echo $school_object->email_link; ?>"><img src="<?php echo asset('/images/icons/mail_16px.png'); ?>" alt="" title="" style="vertical-align: middle;" /></a>
                                    <?php /* 
                                    <?php elseif ($school_object->{ $season_slug}->code == 2): ?>
                                     */ ?>
                                    <?php endif; ?>
                                        <a href="<?php echo url('/forms/seasonal/' . strtolower($season_name) . '/' . $school_object->school->id); ?>"><img src="<?php echo asset('/images/icons/form_2_48px.png'); ?>" alt="" title="" style="vertical-align: middle; width: 16px;" /></a>
                                    <?php /*  <?php endif; ?>  */ ?>
                                </td>
                                <?php if ($school_object->{ $season_slug}->code == 2): ?>
                                    <?php foreach ($school_object->{ $season_slug }->form->data->activities as $activity_object): ?>
                                        
                                        <?php                                            
                                            if ($activity_object->preselect and !$activity_object->offered)
                                            {
                                                $additional_style = ' background-color: #b0ffbe;';
                                            }
                                            elseif ($activity_object->offered and !$activity_object->preselect)
                                            {
                                                $additional_style = ' background-color: #ffb0b0;';
                                            }
                                            else
                                            {
                                                $additional_style = null;
                                            }
                                        ?>

                                        <td style="font-size: 9pt; line-height: 1em; border-left: 1px solid <?php echo (($count % 2) == 1) ? '#dedede' : '#ffffff'; ?>; padding-left: 5px;<?php echo $additional_style; ?>">
                                            
                                            <div style="float: left; margin: 5px 10px 0 0;">
                                                <img 
                                                    <?php if ($activity_object->preselect): ?>
                                                        src="<?php echo asset('images/icons/checkbox_checked_16px.png'); ?>"
                                                        alt="[X]"
                                                        title=""
                                                        data-tooltip="Preselected for the next school year"
                                                    <?php else: ?>
                                                        src="<?php echo asset('images/icons/checkbox_empty_16px.png'); ?>"
                                                        alt="[&nbsp;&nbsp;]"
                                                        title=""
                                                        data-tooltip="Not preselected for the next school year"
                                                    <?php endif; ?>                                                    
                                                    style="vertical-align: middle;"
                                                />
                                            </div>

                                            <?php if ($activity_object->offered): ?>
                                                Boys: <?php echo $activity_object->boys; ?><br />
                                                Girls: <?php echo $activity_object->girls; ?>
                                            <?php else: ?>
                                                <div style="line-height: 2em;">Not Offered</div>
                                            <?php endif; ?>
                                            
                                        </td>

                                    <?php endforeach; ?>
                                <?php else: ?>

                                    <td colspan="<?php echo $column_count; ?>">Form has not been submitted.</td>

                                <?php endif; ?>                               
                            </tr>

                        <?php endforeach; ?>

                    </tbody>
                </table>



            </div>

        <?php endforeach; ?>

    </div>

<?php $__env->stopSection(); ?>

