<script>
    jQuery(document).ready(function() {
        jQuery("#operation").change(function() {

            var len = jQuery("#group:checked").length;
            if (len < 1) {
                alert("لم تقم باختيار أى عنصر");
                jQuery(".defaultOpt").attr("selected", "selected");
                return false;
            } else {
                if (jQuery("option.delete").is(":selected")) {
                    var answer = confirm('هل أنت متأكد من حذف هذه العناصر؟');
                    if (answer == false) {
                        jQuery(".defaultOpt").attr("selected", "selected");
                        return false;
                    }
                }
                jQuery("#form").submit();
            }
        });
    });
</script>
<!-- Data Grid Start -->
<div class="block">
    <div class="title lightTextShadow"><?php echo $this->lang->line('files_list'); ?></div>
    <div class="content">
        <a href="<?= base_url() ?>charge/admin_files/create" class="button sub inlineBlock rnd3 lightTextShadow">
            <span><?php echo $this->lang->line('button_file'); ?><img src="<?= base_url() ?>global/modules/admin/images/plus-small.gif" width="12" height="9" alt="New category" /></span>
        </a>

        <!-- Notification boxes -->
        <?php echo $this->template->flash_msg(); ?>
        <?php if ($files == FALSE) : ?>
            <br/>            
            <p class="block boxStyle notice attention"><a href="javascript:void(0)" class="close"></a><b>تنبيه!</b>لا توجد بيانات مضافة<p>
            <?php else : ?>
            <form method="post" action="<?= base_url() ?>charge/admin_files/operation/" id="form">                        
                <table class="dataGrid tableSorter boxStyle" cellspacing="0" cellpadding="0" border="0">
                    <thead>
                        <tr>
                            <th><input type="checkbox" name="check_nf2" id="selectall" /></th>
                            <th>مسلسل</th>
                            <th><?php echo $this->lang->line('files_name'); ?></th>
                            <th><?php echo $this->lang->line('created'); ?></th>
                            <th><?php echo $this->lang->line('order'); ?></th>
                            <th><?php echo $this->lang->line('operation'); ?></th>


                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $counter = 1;
                        foreach ($files as $ph) :
                            ?>
                            <tr <?php
                            if ($counter % 2 == 1) {
                                echo "class='odd'";
                            }
                            ?>>
                                <td><input type="checkbox" name="check_nf[]" value="<?= $ph['fl_id'] ?>" id="group" /></td>
                                <td class="align-center"><?php echo $counter; ?></td>
                                <td>
                                    <a href="<?= base_url() ?>charge/admin_files/edit/<?= $ph['fl_id']; ?>">

                                        <?php if ($ph['fl_url'] != "" && file_exists(PUBPATH . "global/uploads/" . $ph['fl_url'])) { ?>
                                            <a href="<?= base_url(); ?>global/uploads/<?php echo $ph['fl_url']; ?>"  /><?php echo $ph['fl_name'] ?>
                                        <?php } ?>

                                    </a>
                                </td>
                                <td><?php echo date('Y-m-d', $ph['fl_created']); ?></td>                            

                                <td class="align-center">
                                    <a href="<?= base_url() ?>charge/admin_files/sort/up/<?= $ph['fl_id'] ?>"  ><img src="<?= base_url() ?>global/modules/admin/images/up.png" title="أعلى" alt="up"/></a>
                                    <a href="<?= base_url() ?>charge/admin_files/sort/down/<?= $ph['fl_id'] ?>" ><img src="<?= base_url() ?>global/modules/admin/images/down.png" title="أسفل" alt="down"/></a>
                                </td>

                                <td class="align-center">                                
                                    <a href="<?= base_url() ?>charge/admin_files/edit/<?= $ph['fl_id']; ?>"><img src="<?= base_url() ?>global/modules/admin/images/edit2.png" width="16" height="16" title="<?php echo $this->lang->line('edit'); ?>" alt="تعديل" /></a>&nbsp;&nbsp; | &nbsp;&nbsp;
                                    <a href="<?= base_url() ?>charge/admin_files/remove/<?= $ph['fl_id']; ?>" onclick="return confirm('هل تريد حذف هذا العنصر؟');"><img src="<?= base_url() ?>global/modules/admin/images/del.png" width="16" height="16" title="<?php echo $this->lang->line('delete'); ?>" alt="حذف"  /></a>
                                </td>
                            </tr>
                            <?php
                            $counter++;
                        endforeach;
                        ?>
                    </tbody>
                </table>
                <div class="pager">
                    <div class="resultsCount"><b><?php echo $row + 1 ?></b> - <b><?php echo $row + 10 ?></b> / <em><?php echo $total_rows; ?></em></div>
                    <?php echo $links; ?>
                    <fieldset class="formList inlineBlock">
                        <p align="center"><?php echo $this->lang->line('choose_operation'); ?>:
                            <select class="select rnd5" id="operation" name="operation" onchange="" >
                                <option class="defaultOpt" value=""  >--<?php echo $this->lang->line('choose'); ?>--</option>
                                <option class="oButton delete" value="delete" ><?php echo $this->lang->line('delete'); ?></option>
                            </select>
                        </p>
                    </fieldset>  
                </div>
            </form>
        <?php endif; ?>
    </div>
</div><!-- Data Grid End -->