<?php 
/********************************************************************************* 
 *  This file is part of Sentrifugo.
 *  Copyright (C) 2014 Sapplica
 *   
 *  Sentrifugo is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Sentrifugo is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Sentrifugo.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  Sentrifugo Support <support@sentrifugo.com>
 ********************************************************************************/
?>

<?php 
$employee_data = $this->employee_data;
$column_arr = $this->column_arr;
$sort_name = $this->sort_name;
$sort_type = $this->sort_type;
$per_page = $this->per_page;
$page_no = $this->page_no;
$page_cnt = $this->page_cnt;
$group_id = $this->group_id;
$role_id = $this->role_id;
?>
<input type="hidden" id="page_no"  value="<?php echo $page_no ;?>" />
<input type="hidden" id="per_page" value="<?php echo $per_page ;?>" />
<div id="reportgrid" class="newpop-div">
<div class="all-grid-control">
<div id="iddiv_table_content_popup" class="details_data_display_block newtablegrid">
<table width="50%"  id="idtable_content" class='grid' align='center'   cellspacing='0' cellpadding='4' border='0'>
    <thead>
        <tr>
<?php 
        $i = 1;
        foreach($column_arr as $column_key => $column_name)
        {
            if($sort_name == $column_key)
            {
                if($sort_type == "DESC")
                    $csort_type = "ASC";
                else 
                    $csort_type = "DESC";
            }
            else 
            {
                $csort_type = "DESC";
            }
?>
            <th class="<?php echo ($i == 1)?"cellDivHeader":"" ;?> sort" ><a class ="psort_columns" id ="<?php echo "idcol_".$column_key ;?>" href="javascript:void(0);" data-column="<?php echo $column_key ;?>" data-sort_type = "<?php echo $csort_type;?>"><?php echo $column_name ;?></a></th>
<?php             
            $i++;
        }
?>
        </tr>
    </thead>
    <tbody>
<?php 
    $i = 0;
   if(count($employee_data) > 0)
   {
   foreach($employee_data as $key => $emp_data)
   {
        if($i%2 == 0)
            $classColor = 'row1';
        else
            $classColor = 'row2';
?>
    <tr class="<?php echo $classColor;?>">
<?php        
       foreach($column_arr as $column_key => $column_name)
        {
?>
            
<?php 
            if($group_id != USERS_GROUP)
            {
                if($column_key == 'userfullname')
                {
                    $display =  isset($emp_data['userfullname'])?$emp_data['prefix_name'].". ".$emp_data['userfullname']:"<center>--</center>";
                    $display_title =  isset($emp_data['userfullname'])?$emp_data['prefix_name'].". ".$emp_data['userfullname']:"--";
                }
                elseif($column_key == 'date_of_joining')
                {
                    $display =  isset($emp_data['date_of_joining'])?  sapp_Global::change_date($emp_data['date_of_joining'],"view"):"<center>--</center>";
                    $display_title =  isset($emp_data['date_of_joining'])?  sapp_Global::change_date($emp_data['date_of_joining'],"view"):"--";
                }
                else 
                {
                    $display =  isset($emp_data[$column_key])?$emp_data[$column_key]:"<center>--</center>";
                    $display_title =  isset($emp_data[$column_key])?$emp_data[$column_key]:"--";
                }
            }
            else 
            {
                $display =  isset($emp_data[$column_key])?$emp_data[$column_key]:"<center>--</center>";
                $display_title =  isset($emp_data[$column_key])?$emp_data[$column_key]:"--";
            }
?>
        <td> <span title="<?php echo $display_title;?>"><?php echo $display ;?></span>  </td>
<?php             
        }?>
    </tr>
<?php         
       
       $i++;
   }
   }
   else 
   {
?>       
       <tr>
            <td class="no-data-td" colspan="3"><p class="no-data">No data found</p></td>
        </tr>
<?php                            
   }
?>
    </tbody>
</table>
</div>
<div class="table-btm">    
<?php if($page_cnt > 1) { ?>
    <div class="pagination_block">
        <div class="records_block">			
            <div class="page_txt">
                <span>Records per page</span>
                <div class="records_number-drop-down">					
                    <select id="sel_per_page" >
                        <option value="20" <?php echo ($per_page == 20)?"selected":"" ;?>>20</option>
                        <option value="50" <?php echo ($per_page == 50)?"selected":"" ;?>>50</option>
                        <option value="100" <?php echo ($per_page == 100)?"selected":"" ;?>>100</option>
                        <option value="150" <?php echo ($per_page == 150)?"selected":"" ;?>>150</option>
                        <option value="200" <?php echo ($per_page == 200)?"selected":"" ;?>>200</option>
                    </select>
                </div>				
            </div>
			
        </div>

        <div class="pagination_view">
        <?php sapp_Global::pagination_html(); ?>
        </div></div>
<?php } ?>
    
</div>
</div>
</div>
<input type="hidden" id="psort_name" value="<?php echo $sort_name ;?>" />
<input type="hidden" id="psort_type" value="<?php echo $sort_type ;?>" />
<script type="text/javascript" language="javascript">
$(document).ready(function(){

    <?php 
if($page_cnt >1)
{
?>
    $('#sel_per_page').change(function(){
    var val = $(this).val();
    $('#per_page').val(val);
    $('#page_no').val('1');
    var sort_name = $('#psort_name').val();
    var sort_type = $('#psort_type').val();                   
    var group_id = '<?php echo $group_id ;?>';
    var role_id = '<?php echo $role_id ;?>';
    var page_no = $('#page_no').val();        
    var dialog_id = "emprolesgroup_dialog";
    var per_page = $('#per_page').val();
    $('#'+dialog_id).dialog('close');
    emprolesgroup_popup(group_id,role_id,page_no,sort_name,sort_type,dialog_id,per_page);
});    
    $('.pagination').jqPagination({
        link_string	: '/?page={page_number}',
        current_page    : parseInt(<?php echo $page_no;?>),
        max_page	: parseInt(<?php echo $this->page_cnt?>),
        paged		: function(page) {
            $('#page_no').val(page);
            var sort_name = $('#psort_name').val();
            var sort_type = $('#psort_type').val();                   
            var group_id = '<?php echo $group_id ;?>';
            var role_id = '<?php echo $role_id ;?>';
            var page_no = $('#page_no').val();        
            var dialog_id = "emprolesgroup_dialog";
            var per_page = $('#per_page').val();
            $('#'+dialog_id).dialog('close');
            emprolesgroup_popup(group_id,role_id,page_no,sort_name,sort_type,dialog_id,per_page);
        }
    });
    <?php 
}
    ?> 
            
<?php 
if($sort_type == 'DESC')
{
?>
    $('#idcol_<?php echo $sort_name;?>').append('<span class="s-ico"><span class="ui-icon-asc  ui-icon ui-icon-triangle-1-s"></span></span>');
<?php         
}
else 
{
?>
    $('#idcol_<?php echo $sort_name;?>').append('<span class="s-ico"><span class="ui-icon-desc ui-icon ui-icon-triangle-1-n"></span></span>');
<?php         
}
?>
    $('.psort_columns').click(function(){
        var sort_name = $(this).attr('data-column');
        var sort_type = $(this).attr('data-sort_type');       
        $('#psort_name').val(sort_name);
        $('#psort_type').val(sort_type);
        var group_id = '<?php echo $group_id ;?>';
        var role_id = '<?php echo $role_id ;?>';
        var page_no = $('#page_no').val();        
        var dialog_id = "emprolesgroup_dialog";
        var per_page = $('#per_page').val();
        $('#'+dialog_id).dialog('close');
        emprolesgroup_popup(group_id,role_id,page_no,sort_name,sort_type,dialog_id,per_page);
    });       
    
    $('#iddiv_table_content_popup').slimScrollHorizontal({
		  alwaysVisible: false,
		  start: 'left',
		  position: 'bottom',
		}).css({ background: '#ccc', paddingBottom: '10px' }); 
});//end of ready function
</script>
