<?php $__env->startSection('page_title'); ?>
    OSAA - Cheerleading Sanctioned Competition Calendar
<?php $__env->stopSection(); ?>

<?php $__env->startSection('page_sub_title'); ?>    
   OSAA <?php echo Session::get('year'); ?>-<?php echo intval(substr(Session::get('year'), 2, 2)) + 1; ?> Cheerleading Sanctioned Competition Calendar
<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
    @parent
    
    <style type="text/css">        
        
        table {
            border-collapse: collapse;
            width: 100%;
            font-size: 12pt;
        }

        table thead th {
            text-align: left;
            line-height: 1.5em;
            padding-left: 0.5em;
        }

        table tbody td {
            line-height: 2em;
            padding-left: 0.5em;
        }

        tbody tr.odd {
            background-color: #dddddd;            
        }

    </style>

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

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

  	$('.page_functions').css('width', 'auto');

    $('.button').button();
    $('.return_to_cheer')
        .button({'icons' : { 'primary' : ' ui-icon-arrowthick-1-w'}})
        .css('font-size', '9pt');

  	$('.tabs').tabs();

    function colorRows ()
    {   
      $('table').each(function ()
      {
        var i = 0;

        $('tbody tr:visible', $(this)).each(function ()
        {
          if (i % 2 == 1)
          {
            $(this).addClass('odd');
          }
          else
          {
            $(this).removeClass('odd');
          }
          i = i + 1;
        });   


      });   
    }

    colorRows();


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

<?php $__env->startSection('page_functions'); ?>
    <a href="<?php echo url('/activities/che'); ?>" class="return_to_cheer">Cheerleading</a>
<?php $__env->stopSection(); ?>


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

    <?php
        $activity_events = activityevent::where('school_year', '=', Session::get('year'))
                                        ->where('activity', '=', 'CHE')
                                        ->where('activity_event_type', '=', 'SCMP')
                                        ->get();

        $events = array();
        
        $activity_events = $activity_events->each(function ($ae) use(&$events)
        {
            $event_object = new stdClass();

            $event = event::findOrFail($ae->event);

            if (Helpers::strEqual($event->event_status, array('PND', 'DEL', 'CXL')))
            {
                return;
            }

            $event_object->id = $event->id;

            $event_object->date = date('n/j/Y', strtotime($event->start_at));

            $event_object->location = 'TBD';
            $event_object->map_link = null;

            $location = location::find($event->location);

            if (!is_null($location))
            {
                $event_object->location = $location->name;
                
                $address = address::find($location->address);

                if (!is_null($address))
                {
                    $event_object->map_link = $address->getMapLink();
                }
            }

            $event_object->name = $event->name;

            $contact_data = json_decode($ae->contact_info);

            $event_object->contact_name = $contact_data->name;
            $event_object->contact_email = Helpers::obfuscateEmailAddress($contact_data->email);

            $events[] = $event_object;
        });

        usort($events, function($a, $b)
        {
            $a1 = strtotime($a->date);
            $b1 = strtotime($b->date);

            if ($a1 < $b1)
            {
                return -1;
            }
            elseif ($a1 > $b1)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        })
    ?>

    <?php if (file_exists(public_path() . '/docs/che/' . substr(Session::get('year'), 2, 2) . '-' . substr(intval(Session::get('year')) + 1, 2, 2) . 'SanctionedCalendar.pdf')): ?>
        <div class="float_right" style="margin-top: -0.5em;">
            <a href="<?php echo asset('/docs/che/' . substr(Session::get('year'), 2, 2) . '-' . substr(intval(Session::get('year')) + 1, 2, 2) . 'SanctionedCalendar.pdf'); ?>" target="_blank">
                <img src="<?php echo asset('/images/icons/pdf_2_24px.png'); ?>" style="vertical-align: middle;" />
                Download <?php echo Session::get('year'); ?>-<?php echo substr(intval(Session::get('year')) + 1, 2, 2); ?> Calendar as PDF
            </a>
        </div>    
    <?php endif; ?>

    <h2>Calendar</h2>

    <?php if (count($events) > 0): ?>

        <table>
            <thead class="ui-widget-header">
                <tr>
                    <th>Date</th>
                    <th>Event</th>
                    <th>Location</th>
                    <th>Contact</th>
                </tr>
            </thead>

            <tbody>
                
                <?php foreach ($events as $event): ?>

                    <tr data-event-id="<?php echo $event->id; ?>">
                        <td><?php echo $event->date; ?></td>
                        <td><?php echo $event->name; ?></td>
                        <td>
                            <?php if (!is_null($event->map_link)): ?>
                                <a href="<?php echo $event->map_link; ?>" target="_blank"><?php echo $event->location; ?></a>
                            <?php else: ?>
                                <?php echo $event->location; ?>
                            <?php endif; ?>
                        </td> 
                        <td><a href="mailto:<?php echo $event->contact_email; ?>"><?php echo $event->contact_name; ?></a></td>                        
                    </tr>


                <?php endforeach; ?>

            </tbody>

        </table>


    <?php else: ?>

        <h3>No Events Scheduled</h3>

        <p>
            There are currently no sanctioned competitions scheduled for this school year.  Please check back later.
        </p>

    <?php endif; ?>

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