<?php
$ti=time();
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=Log_details_report".$ti.".xls");
header("Pragma: no-cache");
header("Expires: 0");

#echo "<pre>";print_r($filters);echo "<br>";
#echo "<pre>";print_r($data_type);echo "<br>";print_r($results);echo "</pre>";
#echo "</br> : ".count($item);
#echo "HERE"

$field = count($filters);
?>
<table width="1000" border="1" cellpadding="3" cellspacing="0" class="filterTable" id="filterTable">
    <thead>
        <tr>
            <th style="padding:1%;">S.No</th>
            <?php
                foreach($filters as $value){                    
                    echo '<th style="padding:1%;">'.$value.'</th>';                  
                }
            ?>            
        </tr>
    </thead>
    <tbody>
        <?php if(count($results) > 0) { ?>
            <?php foreach($results as $key=>$value) {?>
                <?php if($value->menu_type != 8) {
                    $service = $this->log_details_report_model->get_service_name($value->menu_type,$value->service_menu_id)->service_name;
                } else {
                    $service = 'Sync Process';
                }
                
                if($value->menu_type == 1) {
                    $menu = 'Master';
                } elseif($value->menu_type == 3) {
                    $menu = 'Inventory';
                } elseif($value->menu_type == 4){
                    $menu = 'Billing Information';
                } elseif($value->menu_type == 8) {
                    $menu = '';
                }
                ?>
                <tr>
                    <td align="center" style="padding:1%;"><?php echo ++$key;?></td>
                    <?php if (in_array("Name", $filters)) {?><td style="padding:1%;"><?php echo text($value->name); ?></td><?php } ?>
                    <?php if (in_array("IP Address", $filters)) {?><td style="padding:1%;"><?php echo text($value->ip_address);?></td><?php } ?>
                    <?php if (in_array("Login Date & Time ", $filters)) {?><td style="padding:1%;"><?php echo text(date('d-m-Y h:i:s A',strtotime($value->log_date_time)));?></td><?php } ?>
                    <?php if (in_array("Service Name", $filters)) {?><td style="padding:1%;"><?php echo ((!empty($menu)) ? $menu . ' - ' : '') . $service;?></td><?php } ?>
                    <?php if (in_array("Page Type", $filters)) {?><td style="padding:1%;"><?php echo text($value->page_type);?></td><?php } ?>
                    <?php if (in_array("Description", $filters)) {?><td style="padding:1%;"><?php echo text($value->desc);?></td><?php } ?>
                </tr>
            <?php } ?>
           
        <?php } else {?>
            <tr>
                <td colspan="<?php echo $field+1; ?>" style="color: #0B6CCB;"><center>No Records Found!</center></td>
            </tr>
        <?php } ?>
    </tbody>
</table>