<?php

function format_interval(DateInterval $interval) {
    $result = "";
    if ($interval->y) {
        $result .= $interval->format("%y years ");
    }
    if ($interval->m) {
        $result .= $interval->format("%m months ");
    }
    if ($interval->d) {
        $result .= $interval->format("%d days ");
    }
    if ($interval->h) {
        $result .= $interval->format("%h hours ");
    }
    if ($interval->i) {
        $result .= $interval->format("%i minutes ");
    }
    if ($interval->s) {
        $result .= $interval->format("%s seconds ");
    }

    return $result;
}
?>
<div class="col-sm-10">

    <div class="row ">

        <div class="col-sm-12 ">

            <div class="col-sm-12 gray_ttc">

                <div class="col-sm-12 ">
                    <div class="col-sm-12">
                        <h3>
                            Upcoming classes
                        </h3>
                        <hr>
                    </div>

                    <div class="col-sm-12" style="padding: 0">

                        <div class="col-sm-12 gray_ttc text-left" style="border-bottom: 2px solid #8CC73F;padding-top: 10px;padding-bottom: 10px;font-weight: bold">

                            <div class="col-sm-7">Class Details</div>
                            <div class="col-sm-5">Action</div>

                        </div>
                        <div class="col-sm-12"><br></div> 
                        <?php
                        if (!$classes) {
                            echo 'You do not have any ' . $this->session->userdata('active_sub_menu_item') . ' class';
                        }
                        $i = 1;
                        ?>
                        <?php foreach ($classes as $v_class) { ?>
                            <div id="actions_for<?php echo $v_class->classroom_id; ?>">
                                <div class="col-sm-12 <?php
                                if ($i % 2 == 0) {
                                    echo 'gray';
                                } else {
                                    echo 'white';
                                }
                                ?>" >
                                    <div class="col-sm-7 text-left" style="padding-top: 20px ">
                                        <address>
                                            <span class="row col-sm-12" >   
                                                <span class="col-sm-4" style="padding:0">Course Name</span>
                                                <span class="col-sm-1" style="padding:0">: </span>
                                                <span class="col-sm-6" style="padding:0">
                                                    <a href="<?php echo base_url() . $course_info[$v_class->classroom_id]->url; ?>" target="blank">
                                                        <?php echo $v_class->course_name; ?>
                                                    </a>
                                                </span>
                                            </span>
                                            <span class="row col-sm-12">   
                                                <span class="col-sm-4" style="padding:0">Classroom Title</span>
                                                <span class="col-sm-1" style="padding:0">: </span>
                                                <span class="col-sm-6" style="padding:0"><?php echo $v_class->classroom_title; ?></span>
                                            </span>
                                            <?php
                                            $offset = $this->session->userdata('time_offset');
                                            $required_time = (strtotime("$v_class->class_start_time") + $offset);

                                            $now = date('Y-M-d H:i:s', strtotime(gmdate('Y-M-d H:i:s')) - $offset);
                                            $now = new DateTime($now, new DateTimeZone($person_info->person_time_zone));

                                            $class_start_time = date('Y-M-d H:i:s', (strtotime($v_class->class_start_time)));
                                            $class_start_time = new DateTime($class_start_time, new DateTimeZone($person_info->person_time_zone));
                                            $interval = $class_start_time->diff($now);
                                            $class_start_time = date('Y-M-d H:i:s', (strtotime($v_class->class_start_time) + $offset));
                                            $now = date('Y-M-d H:i:s', (strtotime(gmdate('Y-M-d H:i:s'))));
                                            $total_duration = strtotime($v_class->class_end_time) - strtotime($v_class->class_start_time);
                                            ?>

                                            <span class="row col-sm-12" >
                                                <span class="col-sm-4" style="padding:0">Class Status</span>
                                                <span class="col-sm-1" style="padding:0">: </span>
                                                <span class="col-sm-6" style="padding:0">
                                                    <?php
                                                    $running = FALSE;
                                                    if ($v_class->classroom_status == 0) {
                                                        if ($class_start_time < $now) {
                                                            $running = TRUE;
                                                            echo 'Running';
                                                        } else {
                                                            echo 'Start In ' . format_interval($interval);
                                                        }
                                                    } else {
                                                        $classroom_status = array('', 'Running', 'Finished', 'Unexpected_End', 'Not Held', 'Canceled', 'Archived', 'Draft', 'Not Held');
                                                        echo $classroom_status[$v_class->classroom_status];
                                                    }
//                                                    echo '<pre>';
//                                                    print_r(format_interval($interval));
//                                                    exit();
                                                    ?>
                                                </span>
                                            </span>

                                            <span class="row col-sm-12" >
                                                <span class="col-sm-3" style="font-weight: bold;margin-right: 45px; padding: 0px;">Presented by</span>
                                                <span class="col-sm-1" style="padding:0">: </span>
                                                <span class="col-sm-6" style="padding:0">
                                                    <a href="<?php echo base_url() . $resource_person_info[$v_class->classroom_id]->url . '/profile'; ?>"><?php echo $v_class->person_first_name . ' ' . $v_class->person_last_name; ?></a>
                                                </span>
                                            </span>
                                            <br>

                                            <span class="row col-sm-12" >   
                                                <span class="col-sm-3" style="font-weight: bold;margin-right: 45px; padding:0">Duration</span>
                                                <span class="col-sm-1" style="padding:0">: </span>
                                                <span class="col-sm-6" style="padding:0"><?php echo $v_class->class_duration; ?> Minutes</span>
                                            </span>

                                        </address>
                                    </div>

                                    <div class="col-sm-5 text-left" style="padding: 20px 0 0 0">
                                        <a href="as_teacher_edit_schedule_class.html"><i class="fa fa-edit" title="Edit"></i></a>&nbsp;
                                        <span>&nbsp;&nbsp;</span>
                                        <a href="#"><i class="fa fa-trash-o" title="Delete"></i></a>&nbsp;
                                        <span>&nbsp;&nbsp;</span>
                                        <a href="#"><i class="fa fa-archive" title="Archive"></i></a>&nbsp;
                                        <span>&nbsp;&nbsp;</span>
                                        <a href="#"><i class="fa fa-user-plus" title="Active Class"></i></a>&nbsp;
                                        <span>&nbsp;&nbsp;</span>
                                        <a href="#"><i class="fa  fa-user-times" title="Inactive Class"></i></a>&nbsp;
                                        <span>&nbsp;&nbsp;</span>
                                        <a href="#"><i class="fa fa-laptop" title="Join Class"></i></a>&nbsp;
                                        <span>&nbsp;&nbsp;</span>
                                        <a href="#"><i class="fa  fa-remove" title="Cancel Class"></i></a>&nbsp;
                                        <span>&nbsp;&nbsp;</span>
                                        <a href="#"><i class="fa  fa-play-circle-o" title="Launch Class"></i></a>&nbsp;
                                    </div>
                                </div>

                                <div class="col-sm-12"><br></div> 
                            <?php }?>
                        </div>

                    </div>

                    <div class="col-sm-12"><br></div>


                    <div class="col-sm-12 " style="padding: 0">
                        <nav class="course-pagination">
                            <ul class="pagination">
                                <li>
                                    <a href="#" aria-label="Previous">
                                        <span aria-hidden="true" title="First Page">&laquo;&laquo;</span>
                                    </a>
                                </li>
                                <li>
                                    <a href="#" aria-label="Previous">
                                        <span aria-hidden="true" title="Previous Page">&laquo;</span>
                                    </a>
                                </li>
                                <li><a href="#">1</a></li>
                                <li><a href="#">2</a></li>
                                <li><a href="#">3</a></li>
                                <li><a href="#">4</a></li>
                                <li><a href="#">5</a></li>
                                <li>
                                    <a href="#" aria-label="Next">
                                        <span aria-hidden="true" title="Next Page">&raquo;</span>
                                    </a>
                                </li>
                                <li>
                                    <a href="#" aria-label="Next">
                                        <span aria-hidden="true" title="Last Page">&raquo;&raquo;</span>
                                    </a>
                                </li>
                            </ul>
                        </nav>

                    </div>

                </div>

            </div>

            <div class="col-sm-12"><br></div>
            <div class="col-sm-12 gray" >
                <div class="col-sm-12 " >
                    <label><a href="dashboard.html">Dashboard </a> ->> <a href="selected_user_details.html">Organization </a> ->> <a href="organization_upcoming_class.html"> Upcoming Class</a> </label>
                </div>
            </div>

        </div>

    </div>


</div>