<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('groups_list'); ?></div>
    <div class="content">
        <a href="<?= base_url() ?>authorization/admin_groups/create" class="button sub inlineBlock rnd3 lightTextShadow">
            <span><?php echo "أضف مجموعة جديدة"; ?><img src="<?= base_url() ?>global/modules/admin/images/plus-small.gif" width="12" height="9" alt="New new" /></span>
        </a>

        <!-- Notification boxes -->
        <?php echo $this->template->flash_msg(); ?>
        <?php if ($groups == 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() ?>authorization/admin_groups/operation/" id="form">                
                <table class="dataGrid tableSorter boxStyle" cellspacing="0" cellpadding="0" border="0">
                    <thead>
                        <tr>
                            <th width="5%"><input type="checkbox" name="check_nf2" id="selectall"/></th>
                            <th width="10%">مسلسل</th>
                            <th ><?php echo lang('group_name'); ?></th>
                            <th ><?php echo lang('operation'); ?></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $counter = 1;
                        foreach ($groups as $v) :
                            ?>
                            <tr <?php
                            if ($counter % 2 == 1) {
                                echo "class='odd'";
                            }
                            ?> >
                                <td><input type="checkbox" name="check_nf[]" value="<?= $v['gr_id'] ?>" id="group" /></td>
                                <td class="align-center"><?php echo $counter; ?></td>

                                <td><?php echo $v['gr_name'] ?></td>
                                <td><?php echo $v['gr_notice'] ?></td>

                                <td class="align-center">
                                    <?php if ($v['gr_id'] != 1) { ?>
                                        <a href="<?= base_url() ?>authorization/admin_groups/remove/<?= $v['gr_id']; ?>" onclick="return confirm('هل تريد حذف هذا العنصر؟');">
                                            <img src="<?= base_url() ?>global/modules/admin/images/del.gif" width="16" height="16" title="<?php echo lang('delete'); ?>" alt="حذف"  />
                                        </a>
                                        &nbsp;&nbsp; | &nbsp;&nbsp;
                                    <?php } ?>

                                        <a href="<?= base_url() ?>authorization/admin_groups/edit/<?= $v['gr_id']; ?>" >
                                            <img src="<?= base_url() ?>global/modules/admin/images/pencil.gif" width="16" height="16" title="<?php echo lang('edit'); ?>" 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 -->
