<?php

/* 
 * Author       : Jai K
 * Purpose      : The listing page for Form Download
 * Created On   : 2016-12-28 18:15
 */

?>
<style>

</style>
<aside class="right-side">
    <section class="content-header">
        <div class="title_bar">
            <h1 class="major_txt_color"><?php echo $title; ?> List</h1>
            <div class="breadcrumb_container"><?php echo breadcrumb_links();?></div>
        </div>
    </section>
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <!-- /.box -->
                <div class="box box-primary">
                    <div class="box-body table-responsive">
                    <?php if(!empty($success)) {?>
                        <div class="alert alert-success alert-dismissable">
                            <i class="fa fa-thumbs-o-up"></i>
                            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                            <h4><?php echo $success;?></h4>
                        </div>
                    <?php }
                    else if(!empty($error)) {?>
                        <div class="alert alert-danger alert-dismissable">
                            <i class="fa fa-thumbs-o-down"></i>
                            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                            <h4><?php echo $error;?></h4>
                        </div>
                    <?php }?>
                        <div class="row">
                            <div class="left-col action-left-col">
                                <?php if (in_array(2, $permission)) {?>
                                    <a href="<?php echo $add_link?>">
                                        <input type="button" class="btn btn-success btn-sm" value="<?php echo $add_btn?>" />
                                    </a>
                                <?php }?>
                            </div>
                        </div>      
                    </div>
                    <div class="box-body table-responsive">
                        <table id="dt_basic" class="table table-striped table-bordered table-hover" width="100%">
                            <thead>			                
                                <tr>
                                    <th data-class="expand">S.No</th>
                                    <th >Name</th>
                                    <th data-hide="phone" style="text-align: center;" >Uploaded Date</th>
                                    <th data-hide="phone,tablet" style="text-align: center;" width="20%">Preview/Download</th>
                                    <th data-hide="phone,tablet">Status</th>
                                    <th data-hide="phone" style="text-align: center; min-width: 225px;" width="15%" >Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php 
                                    foreach( $results as $k => $row ) :
                                        $prv_html = ' - ';
                                        if( !empty( $row['frm_file'] ) ) :
                                            $prv_html = get_file_preview( DIR_FORM_DOWNLOAD . $row['frm_file'], '', FALSE );
                                            $prv_html = file_exists( DIR_FORM_DOWNLOAD . $row['frm_file'] ) ? '<a target="_blank" title="Click to download" href="'. BASE_URL .DIR_FORM_DOWNLOAD . $row['frm_file'] .'">'.$prv_html.'</a>' : $prv_html;
                                        endif;
                                ?>
                                    <tr>
                                        <td><?php echo ++$k;?></td>
                                        <td><a href="<?php echo BASE_URL . DIR_FORM_DOWNLOAD . $row['frm_file']; ?>" target="_blank"><?php echo $row['frm_name']; ?></a></td>
                                        <td align="center"><?php echo date("d M, Y", strtotime( $row['created_on'] ) );?></td>
                                        <td align="center"><?php echo $prv_html; ?></td>
                                        <td><?php echo $row['status'] == "1" ? 'Active' : 'Inactive'; ?></td>
                                        
                                        <td class="td_action">
                                            <?php if( in_array(1, $permission) ):?>
                                                <a class="label btn btn-warning view" href="<?php echo $view_link . $row['id'] . '/'; ?>">
                                                    <span>View</span>
                                                </a>
                                            <?php endif; if( in_array(3, $permission) ) :?>
                                                <a class="label btn btn-primary edit" href="<?php echo $edit_link . $row['id'] . '/'; ?>">
                                                    <span>Edit</span>
                                                </a>
                                            <?php endif; if (in_array(4, $permission)) :?>
                                                <a class="label btn btn-danger pop_up_confirm delete" data-confirm="Do you want to delete this form (<b><?php echo $row['frm_name'];?></b>)?" data-href="<?php echo $delete_link . $row['id'] . '/'; ?>" >
                                                    <span>Delete</span>
                                                </a>
                                            <?php endif; ?>
                                        </td>
                                    </tr>
                                <?php endforeach; ?>
                            </tbody>
                        </table>
                    </div>
                </div><!-- /.box -->
            </div>
        </div>
        
    </section><!-- /.content -->
</aside><!-- /.right-side -->
<!-- ./wrapper -->
<script type="text/javascript" src="<?php echo js_url();?>library/datatables.responsive.min.js"></script>
<script src="<?php echo base_url();?>assets/js/library/jquery.dataTables.min.js"></script>
<script>
    $(document).ready(function() {
        /* BASIC ;*/
        var responsiveHelper_dt_basic = undefined;
        
        var breakpointDefinition = {
            tablet : 1024,
            phone : 480
        };

        $('#dt_basic').dataTable({
            "autoWidth" : true,
            "preDrawCallback" : function() {
                // Initialize the responsive datatables helper once.
                if (!responsiveHelper_dt_basic) {
                    responsiveHelper_dt_basic = new ResponsiveDatatablesHelper($('#dt_basic'), breakpointDefinition);
                }
            },
            "rowCallback" : function(nRow) {
                responsiveHelper_dt_basic.createExpandIcon(nRow);
            },
            "drawCallback" : function(oSettings) {
                responsiveHelper_dt_basic.respond();
            }
        });
        $('select[name="dt_basic_length"], input[type="search"]').removeClass();
        $('input[type="search"]').css('-webkit-appearance','textfield');      
	    /* END BASIC */
    });
</script>
