<?php
if ($no_results == FALSE) {
    ?>
    <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">قائمة معاينات المرضى</div>
        <div class="content">
            <a href="<?= base_url() ?>patient/admin_patient/create" class="button sub inlineBlock rnd3 lightTextShadow">
                <span>تسجيل استمارة طبية<img src="<?= base_url() ?>global/modules/admin/images/plus-small.gif" width="12" height="9" alt="New new" /></span>
            </a>
            <a href="<?= base_url() ?>patient/admin_patient/patient_search" class="button sub inlineBlock rnd3 lightTextShadow">
                <span>بحث متقدم</span>
            </a>
            <!-- Notification boxes -->
            <?php echo $this->template->flash_msg(); ?>
            <?php if ($result1 == 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() ?>patient/admin_patient/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>رقم الحالة</th>
                                <th>تاريخ التسجيل</th>
                                <th>اسم المريض</th>
                                <th>تاريخ الميلاد</th>
                                <th>الفرع</th>
                                <th>الجنس</th>
                                <th>تاريخ الانشاء</th>
                                <th>خيارات</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $counter = $row + 1;
                            foreach ($result1 as $n) :
                                ?>
                                <tr <?php
                                if ($counter % 2 == 1) {
                                    echo "class='odd'";
                                }
                                ?> >
                                    <td><input type="checkbox" name="check_nf[]" value="<?= $n['pi_id'] ?>" id="group" /></td>
                                    <td class="align-center"><?php echo $counter; ?></td>
                                    <td><?= $n['pi_num'] ?></td>                                    
                                    <td><?= $n['pi_date_reg'] ?></td> 
                                    <td><?= $n['pi_name'] . '' . $n['pi_father'] . '' . $n['pi_family'] ?></td>   
                                    <td><?= $n['pi_borndate'] ?></td>   
                                    <td><?= $n['branch_name'] ?></td>   
                                    <td><?= $n['pi_gender'] ?></td>   
                                    <td><?= date('Y-m-d', $n['pi_created']) ?></td>

                                    <td class="align-center">
                                        <a href="<?= base_url() ?>patient/admin_photos/overview/<?= $n['pi_id'] ?>" ><img src="<?= base_url() ?>global/modules/admin/images/add_images.png" title="رفع المستندات" alt="up"/></a>&nbsp;&nbsp; | &nbsp;&nbsp;
                                        <a href="<?= base_url() ?>patient/admin_patient/edit/<?= $n['pi_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() ?>patient/admin_patient/export_patient_reprt/<?= $n['pi_id']; ?>" ><img src="<?= base_url() ?>global/modules/admin/images/pdf_document.png" width="16" height="16" title="<?php echo $this->lang->line('export'); ?>" alt="'استخراج"  /></a>| &nbsp;&nbsp;
                                        <a href="<?= base_url() ?>patient/admin_patient/remove/<?= $n['pi_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 -->
<?php } else {
    ?>

    <div class="block">
        <div class="title lightTextShadow">نتائج البحث</div>
        <div class="content">
            <p class = "block boxStyle notice attention"><a href = "javascript:void(0)" class = "close"></a><b>تنبيه!</b>عفوا لا يوجد نتائج لكلمة البحث التى قمت بإختيارها ، حاول البحث بكلمة أخرى<p>
                <?php } ?>
    </div></div>
<!-- Data Grid Block End -->
<!-- Main Block End -->
