<div class="col-sm-12 gray_ttc text-center" style="border-bottom: 2px solid #8CC73F;padding-top: 10px;padding-bottom: 10px;font-weight: bold">
    <div class="col-sm-4" style="padding:10px 0">Topic Name</div>
    <div class="col-sm-3" style="padding:10px 0">By</div>
    <div class="col-sm-5" style="padding:10px 0">Action</div>
</div>
<div class="col-sm-12"><br></div> 
<?php
if ($all_topic) {
    foreach ($all_topic as $v_topic) {
        $topic_id = $v_topic->quiz_topic_id;
        $status = $v_topic->topic_status;
    
        $topic_creator_role = $topic_creator[$v_topic->quiz_topic_id]->person_role;
        $topic_viewer_role = $this->session->userdata('person_role');
        ?>
        <div id="actions<?php echo $topic_id; ?>">
            <div class="col-sm-12 gray text-center" >
                <div class="col-sm-4" style="padding:10px 0">
                    <?php
                    $replace_data = '<span style=color:green>' . $search_value . '</span>';
                    $topic_name = str_replace("$search_value", "$replace_data", $v_topic->topic_name);
                    echo $v_topic->topic_name;
                    ?>
                </div>

                <div class="col-sm-3" style="padding:10px 0">
                    <?php
                    if ($topic_creator_role == 6) {
                        echo 'TalhaTraining';
                    } else if ($topic_creator_role == 1) {
                        echo 'TalhaTraining';
                    } else if ($topic_creator_role == 3) {
                        ?>
                        <a href="<?php echo base_url() . $topic_creator[$topic_id]->url . '/profile'; ?>" target="_blank">
                            <?php echo $topic_creator[$topic_id]->person_first_name . ' ' . $topic_creator[$topic_id]->person_last_name;
                            ?>
                        </a>
                        <?php
                    } else if ($topic_creator_role == 4) {
                        ?>
                        <a href="<?php echo base_url() . $topic_creator[$quiz_id]->url . '/profile'; ?>" target="_blank">
                            <?php echo $org_info[$topic_id]->organization_name; ?>
                        </a>
                        <?php
                    }
                    ?>
                </div>

                <div class="col-sm-4" style="padding:10px 0">

                    <a href="<?php echo base_url() . 'super-admin/edit-topic/' .  $topic_id ; ?>">
                        <i class="fa fa-edit" title="Edit topic"></i>
                    </a>&nbsp;&nbsp;

                    <?php
                    switch ($topic_viewer_role) {
                        case 1:
                            ?>
                            <?php
                            switch ($status) {
                                case 0:
                                    ?>
                                    <a href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'super-admin/change-status/' .  $topic_id  . '/1'; ?>', 'Publish', '<?php echo $topic_id; ?>')">
                                        <i class="fa  fa-user-plus" title="Publish"></i>
                                    </a>&nbsp;&nbsp;

                                    <a href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'super-admin/change-status/' .  $topic_id  . '/3'; ?>', 'Pending', '<?php echo $topic_id; ?>')">
                                        <i class="fa fa-refresh fa-spin" title="Pending topic"></i>
                                    </a>&nbsp;&nbsp;

                                    <?php
                                    break;
                                case 1:
                                    if (!$topic_quizes[$topic_id]) {
                                        ?>
                                        <a href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'super-admin/change-status/' .  $topic_id  . '/0'; ?>', 'Unpublish', '<?php echo $topic_id; ?>')">
                                            <i class="fa  fa-user-times" title="Unpublish"></i>
                                        </a>&nbsp;&nbsp;

                                        <a href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'super-admin/change-status/' .  $topic_id  . '/3'; ?>', 'Pending', '<?php echo $topic_id; ?>')">
                                            <i class="fa fa-refresh fa-spin" title="Pending topic"></i>
                                        </a>&nbsp;&nbsp;
                                    <?php } ?>
                                    <?php
                                    break;
                                case 2:
                                    ?>
                                    <a href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'super-admin/change-status/' .  $topic_id  . '/1'; ?>', 'Publish', '<?php echo $topic_id; ?>')">
                                        <i class="fa  fa-user-plus" title="Publish"></i>
                                    </a>&nbsp;&nbsp;
                                    <a href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'super-admin/change-status/' .  $topic_id  . '/0'; ?>', 'Unpublish', '<?php echo $topic_id; ?>')">
                                        <i class="fa  fa-user-times" title="Unpublish"></i>
                                    </a>&nbsp;&nbsp;
                                    <a href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'super-admin/change-status/' .  $topic_id  . '/4'; ?>', 'Approve', '<?php echo $topic_id; ?>')">
                                        <i class="glyphicon glyphicon-ok" title="Approve topic"></i>
                                    </a>&nbsp;&nbsp;
                                    <?php
                                    break;
                                case 3:
                                    ?>
                                    <a href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'super-admin/change-status/' .  $topic_id  . '/4'; ?>', 'Approve', '<?php echo $topic_id; ?>')">
                                        <i class="glyphicon glyphicon-ok" title="Approve topic"></i>
                                    </a>&nbsp;&nbsp;
                                    <?php
                                    break;
                                case 4:
                                    ?>
                                    <a href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'super-admin/change-status/' .  $topic_id  . '/1'; ?>', 'Publish', '<?php echo $topic_id; ?>')">
                                        <i class="fa  fa-user-plus" title="Publish"></i>
                                    </a>&nbsp;&nbsp;
                                    <a href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'super-admin/change-status/' .  $topic_id  . '/3'; ?>', 'Pending', '<?php echo $topic_id; ?>')">
                                        <i class="fa fa-refresh fa-spin" title="Pending topic"></i>
                                    </a>&nbsp;&nbsp;
                                    <?php
                                    break;
                                default:
                                    break;
                            }
                            ?>
                            <?php if (!$topic_quizes[$topic_id]) { ?>
                                <a  href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'super-admin/delete-topic/' .  $topic_id ; ?>', 'Delete', '<?php echo $topic_id; ?>')">
                                    <i class="fa fa-trash-o" title="Delete"></i>
                                </a>&nbsp;&nbsp;
                            <?php } ?>
                            <?php
                            break;
                        case 6:
                            ?>
                            <?php
                            switch ($status) {
                                case 0:
                                    ?>
                                    <a href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'super-admin/change-status/' .  $topic_id  . '/1'; ?>', 'Publish', '<?php echo $topic_id; ?>')">
                                        <i class="fa  fa-user-plus" title="Publish"></i>
                                    </a>&nbsp;&nbsp;

                                    <a href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'super-admin/change-status/' .  $topic_id  . '/3'; ?>', 'Pending', '<?php echo $topic_id; ?>')">
                                        <i class="fa fa-refresh fa-spin" title="Pending topic"></i>
                                    </a>&nbsp;&nbsp;

                                    <?php
                                    break;
                                case 1:
                                    ?>
                                    <a href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'super-admin/change-status/' .  $topic_id  . '/0'; ?>', 'Unpublish', '<?php echo $topic_id; ?>')">
                                        <i class="fa  fa-user-times" title="Unpublish"></i>
                                    </a>&nbsp;&nbsp;

                                    <a href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'super-admin/change-status/' .  $topic_id  . '/3'; ?>', 'Pending', '<?php echo $topic_id; ?>')">
                                        <i class="fa fa-refresh fa-spin" title="Pending topic"></i>
                                    </a>&nbsp;&nbsp;
                                    <?php
                                    break;
                                case 2:
                                    ?>
                                    <a href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'super-admin/change-status/' .  $topic_id  . '/1'; ?>', 'Publish', '<?php echo $topic_id; ?>')">
                                        <i class="fa  fa-user-plus" title="Publish"></i>
                                    </a>&nbsp;&nbsp;
                                    <a href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'super-admin/change-status/' .  $topic_id  . '/0'; ?>', 'Unpublish', '<?php echo $topic_id; ?>')">
                                        <i class="fa  fa-user-times" title="Unpublish"></i>
                                    </a>&nbsp;&nbsp;
                                    <a href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'super-admin/change-status/' .  $topic_id  . '/4'; ?>', 'Approve', '<?php echo $topic_id; ?>')">
                                        <i class="glyphicon glyphicon-ok" title="Approve topic"></i>
                                    </a>&nbsp;&nbsp;
                                    <?php
                                    break;
                                case 3:
                                    ?>
                                    <a href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'super-admin/change-status/' .  $topic_id  . '/4'; ?>', 'Approve', '<?php echo $topic_id; ?>')">
                                        <i class="glyphicon glyphicon-ok" title="Approve topic"></i>
                                    </a>&nbsp;&nbsp;
                                    <?php
                                    break;
                                case 4:
                                    ?>
                                    <a href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'super-admin/change-status/' .  $topic_id  . '/1'; ?>', 'Publish', '<?php echo $topic_id; ?>')">
                                        <i class="fa  fa-user-plus" title="Publish"></i>
                                    </a>&nbsp;&nbsp;
                                    <a href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'super-admin/change-status/' .  $topic_id  . '/3'; ?>', 'Pending', '<?php echo $topic_id; ?>')">
                                        <i class="fa fa-refresh fa-spin" title="Pending topic"></i>
                                    </a>&nbsp;&nbsp;
                                    <?php
                                    break;
                                default:
                                    break;
                            }
                            ?>

                            <a  href="javascript:void(0)" onclick="return checkForAction('<?php echo base_url() . 'super-admin/delete-topic/' .  $topic_id ; ?>', 'Delete', '<?php echo $topic_id; ?>')">
                                <i class="fa fa-trash-o" title="Delete"></i>
                            </a>&nbsp;&nbsp;
                            <?php
                            break;
                    }
                    ?>
                    <a  href="<?php echo base_url() . 'super-admin/view-topic-quiz/' .  $topic_id ; ?>" >
                        <i class="fa fa-th" title="View quiz"></i>
                    </a>&nbsp;&nbsp;
                </div>
            </div>
            <div class="col-sm-12"><br></div> 
        </div>
        <?php
    }
} else {
    echo 'You do not have any topic.';
}
?>

<!--------------------start Pagination---------------------------->
<div class="col-sm-12">
    <?php $total_page = ceil($total_data / $per_page_view); ?>
    <div class="col-sm-12 form-group">
        <?php
        if ($total_page > 1) {
            ?>
            <nav class="course-pagination">
                <ul class="pagination">
                    <?php
                    if ($page > 2) {
                        ?>
                        <li>
                            <a href='javascript:;' onclick="pagination('<?php echo base_url() . 'super-admin/manage-topic/1'; ?>', 'topic')"
                               aria-label="Previous">
                                <span aria-hidden="true" title="First Page">&laquo;&laquo;</span>
                            </a>
                        </li>
                        <li>
                            <a href='javascript:;' onclick="pagination('<?php echo base_url() . 'super-admin/manage-topic/' . ($page - 1); ?>', 'topic')"
                               aria-label="Previous">
                                <span aria-hidden="true" title="Previous Page">&laquo;</span>
                            </a>
                        </li>
                    <?php } elseif ($page > 1) { ?>
                        <li>
                            <a href='javascript:;' onclick="pagination('<?php echo base_url() . 'super-admin/manage-topic/' . ($page - 1); ?>', 'topic')"
                               aria-label="Previous">
                                <span aria-hidden="true" title="Previous Page">&laquo;</span>
                            </a>
                        </li>
                        <?php
                    }
                    $count_page = 0;
                    if ($total_page < 10) {
                        for ($i = $page; $total_page >= $i; $i++) {
                            ?>
                            <li>
                                <a <?php
                                if ($page == $i) {
                                    echo 'style="background-color:#80c12c; color:#fff;"';
                                }
                                ?>
                                    href='javascript:;' onclick="pagination('<?php echo base_url() . 'super-admin/manage-topic/' . $i; ?>', 'topic')">
                                        <?php echo $i ?>
                                </a>
                            </li>
                            <?php
                        }
                    } else if ($page + 10 <= $total_page) {
                        $count_page = $page + 10;
                        for ($i = $page; $count_page > $i; $i++) {
                            ?>
                            <li>
                                <a <?php
                                if ($page == $i) {
                                    echo 'style="background-color:#80c12c; color:#fff;"';
                                }
                                ?>
                                    href='javascript:;' onclick="pagination('<?php echo base_url() . 'super-admin/manage-topic/' . $i; ?>', 'topic')">
                                        <?php echo $i ?>
                                </a>
                            </li>
                            <?php
                        }
                    } else {
                        for ($i = $total_page - 10; $total_page > $i; $i++) {
                            ?>
                            <li>
                                <a <?php
                                if ($page == $i + 1) {
                                    echo 'style="background-color:#80c12c; color:#fff;"';
                                }
                                ?>
                                    href="javascript:;" onclick="pagination('<?php echo base_url() . 'super-admin/manage-topic/' . ($i + 1); ?>', 'topic')"> 
                                        <?php echo ($i + 1) ?>
                                </a>
                            </li>
                            <?php
                        }
                    }

                    if ($total_page > $page + 10) {
                        ?>
                        <li>
                            <a href="javascript:;" onclick="pagination('<?php echo base_url() . 'super-admin/manage-topic/' . ($page + 1); ?>', 'topic')"
                               aria-label="Next">
                                <span aria-hidden="true" title="Next Page">&raquo;</span>
                            </a>
                        </li>
                        <li>
                            <a href="javascript:;" onclick="pagination('<?php echo base_url() . 'super-admin/manage-topic/' . ($page + 1); ?>', 'topic')" 
                               aria-label="Next">
                                <span aria-hidden="true" title="Last Page">&raquo;&raquo;</span>
                            </a>
                        </li>
                    <?php } ?>
                </ul>
            </nav>
        <?php } ?>
    </div>
</div>