<?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
$reports_view_helper = $this->Reports();
$requisition_arr = $this->requisition_arr;
$page_no = $this->page_no;
$per_page = $this->per_page;
$page_cnt = $this->page_cnt;
$cols_param_arr = $this->cols_param_arr;
$sort_name = $this->sort_name;
$sort_type = $this->sort_type;
$user_data = 0;
$columns_array = $this->columns_array;
$mandatory_array = $this->mandatory_array;

?>

	<div class="table-header">
	    <div class="config-choose config-up" onclick="displayreqtabs();" id="selectfields"></div>
		<span>Candidate Details</span>
        <div id='idcols_arr' class="columnsdiv" style='display:none;' ><i>Columns :</i>
	<?php 
	    $selectedColumn = implode(',',array_keys($cols_param_arr));
	    foreach($columns_array as $column_key => $column_name)
	    {
	        $checked = in_array($column_key, array_keys($cols_param_arr))?"checked = 'checked'":"";
	?>
	    	<p><input type="checkbox" class="cls_clmchk" id="cls_<?php echo $column_key ;?>" name="cols_arr[<?php echo $column_key ;?>]" value="<?php echo $column_name ;?>" <?php echo $checked;?> /><b><?php echo $column_name;?></b></p>
	<?php         
	    }
	?>
				<div class="new-form-ui-submit mrgetop10">
					<input type="button" id ="btncols" value ="Apply" />
				 	<button onclick="displayreqtabs()" type="button" id="Cancel" name="Cancel">Cancel</button>
				</div>	
		</div><input type="hidden" value="<?php echo $selectedColumn;?>" id="selectedColumns"/>
	</div>
	<div id="reportgrid" class="details_data_display_block newtablegrid">
	    <table id="idtable_content" class='grid' align='center'  width='100%' cellspacing='0' cellpadding='4' border='0'>
	        <thead>
	        <tr>
           
<?php 
        $i = 1;
        foreach($cols_param_arr as $column_key => $column_name)
        {
        	if($sort_name == $column_key)
            {
                if($sort_type == "ASC")
                    $csort_type = "DESC";
                else 
                    $csort_type = "ASC";
            }
            else 
            {
                $csort_type = "ASC";
            }        
?>
            	<th class="<?php echo ($i == 1)?"cellDivHeader":"" ;?> sort" ><a class="sort_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>
<?php 
    if(count($requisition_arr) > 0)
    {
?>
        	<tbody>
<?php         
        $i = 0;
        foreach($requisition_arr as $emp_data)
        {
            if($i%2 == 0)
                $classColor = 'row1';
            else
                $classColor = 'row2';	
?>
        		<tr class="<?php echo $classColor;?>">
<?php 
        foreach($cols_param_arr as $column_key => $column_name)
        {
?>
            		<td><span title="<?php $reports_view_helper->displayCandidatesData($emp_data, $column_key, true);?>"><?php $reports_view_helper->displayCandidatesData($emp_data, $column_key);?></span></td>
<?php             
        }
?>
        		</tr>
<?php    
            $i++;
        }
?>
        
<?php         
    }
    else 
    {
?>
	        <tr>
	            <td class="no-data-td" colspan="<?php echo sizeof($cols_param_arr);?>"><p class="no-data">No data found</p></td>
	        </tr>
<?php        
    }
?>
        </tbody>
    </table>
</div>

    <div class="table-btm">
		<div class="pagination_block">
				<?php 
					if(count($requisition_arr) > 0)
					{
					?>
					<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>
					<?php 
					}
					if($page_cnt >1)
					{
					?>
					<div class="pagination_view">
						<?php sapp_Global::pagination_html(); ?>
					</div>
					<?php 
					}
					?>
		</div>
    </div>

<script type="text/javascript" language="javascript">
$(document).ready(function(){
	$('#reportgrid').slimScrollHorizontal({
		alwaysVisible: false,
		start: 'left',
		position: 'bottom',
	}).css({ background: '#ccc', paddingBottom: '10px' });
        
        
$('#btncols').click(function(){
    	$('#idsubmitbutton').trigger('click');
    });
<?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         
}
?>    
<?php 
    if(count($requisition_arr) > 0)
    {
  ?>$('#export_excel,#pdf').show();
<?php          
    }
    else 
    {
?>$('#export_excel,#pdf').hide();
<?php        
    }
?> 
<?php 
if($page_cnt >1)
{
?>
    $('.pagination').jqPagination({
        link_string	: '/?page={page_number}',
        current_page    : parseInt(<?php echo $this->page_no;?>),
        max_page	: parseInt(<?php echo $this->page_cnt?>),
        paged		: function(page) {
               $('#page_no').val(page);
               candidatesreport_ajax();
        }
    });
<?php 
}
?>

	$('#sel_per_page').change(function(){
        var val = $(this).val();
        $('#per_page').val(val);
        candidatesreport_ajax();
    });
    
    $('.sort_columns').click(function(){
        var sort_name = $(this).attr('data-column');
        var sort_type = $(this).attr('data-sort_type');
        $('#sort_name').val(sort_name);
        $('#sort_type').val(sort_type);
        candidatesreport_ajax();    
	});
});
</script>