<script type="text/javascript">
$(document).ready(function() {   
   	$('select').select2();

	$.each($(".select2-container"), function (i, n) {
        $(n).next().show().fadeTo(0,0).height("0px").css("left", "auto"); // make the original select visible for validation engine and hidden for us
        $(n).prepend($(n).next());
        $(n).delay(500).queue(function () {
            $(this).removeClass("validate[required]"); //remove the class name from select2 container(div), so that validation engine dose not validate it
            $(this).dequeue();
        });
    });

   //Datepicker
   jQuery('.datepicker2').datepicker({
			dateFormat : 'dd-mm-yy',
			changeMonth : true,
			changeYear : true
			});
   
   //Data table configurations
   var oTable = $("#test").dataTable({
	   	"iDisplayLength": 10,
		"aLengthMenu": [5,10,25,50,100],
		"sPaginationType": "full_numbers",
		"aoColumns": [	{"bSortable": false },
						{"bSortable": false },
					<?php foreach($tbHdr as $v): ?>
						null,
					<?php endforeach; ?>
					] 
	});
	oTable.fnSort( [ [0,'asc'] ] );
   
	
	
	//on change
	$('#userID,#queryType').live('change',function(){
		console.log('hello');
		//changeList();
	});
}); 

function changeList(){
	console.log('hello');
	var datefrom = $('#dateForm').val();
	var dateto = $('#dateTo').val();
	var userID = $('#userID').val();
	var queryType = $('#queryType').val();
	var search = $('#search').val();
	
	var urls = "<?php echo base_url();?>logreport/index/"+userID+"/"+datefrom+"/"+dateto+"/"+queryType+"/"+search;
		window.location = urls;
} 

 
</script>

<div id="content">                        
<div class="wrap">
<div class="head">
	<div class="info">
        <!--<h1><?php echo element('compName', $this->session->userdata('logged_in')) ?> [ 
            <?php echo element('compNo', $this->session->userdata('logged_in')) ?> ]</h1>-->
        <ul class="breadcrumb">
            <li><a href='<?php echo base_url(); ?>'><?php echo $this->lang->line('dashboard') ?></a> <span class="divider">-</span></li>
            <li><a href="<?php echo base_url(); ?>/locationtransfer"><?php echo $this->lang->line('module') ?></a> <span class="divider">-</span></li>
            <li class="active"><?php echo $this->lang->line('title') ?></li>
        </ul>
	</div>
	<div class="search">
		<form action="<?php echo base_url() ?>admin/search" method="post">
			<input name="search_text" type="text" placeholder="search..."/>                                
            <button type="submit"><span class="i-magnifier"></span></button>
		</form>
	</div>                        
</div><!-- head --> 
<div class="content">
    
	<div class="wrap">        
        <div class="content">
            <div class="wrap">   
                
                <div class="row-fluid">
                    <div class="span12">
                       	<div class="block">
                        	<div class="head">
                            	<h2><?php echo $this->lang->line('selectDate') ?></h2>
                            </div>
                            <div class="content np">
                				<div class="controls-row"><!-- Row 4-->
                					<div class="span6 tac">
	                                    <div class="span4 tal"><?php echo form_label($this->lang->line('user')); ?></div>
		                                <div class="span8 fr">
		                                    <?php
		                                    	$preselcat = !empty($user)?$user:'';
												$options['all'] = 'Please select';
		                                        foreach($users as $row){
		                                            $options[$row->fldid] = $row->username."(".$row->userid.")";
		                                        }
		                                        $js='ID="userID" class="span10"';
		                                        echo form_dropdown('userID', $options, $preselcat, $js);
		                                    ?>
		                                </div>
		                            </div>
	                            </div>
                				<div class="controls-row"><!-- Row 4-->
									<div class="span6 tac">
				                    	<div class="span4 tal"><?php echo form_label($this->lang->line('dateFrom'));?></div>
				                        <div class="input-prepend span8">
					                        <span class="add-on span2"><i class="i-calendar"></i></span>
											<?php
												$data = array(
												'name' => 'dateFrom',
												'id' => 'dateForm',
												'type' => 'text',
												'class' => 'span8 datepicker2 financhk',);
												$js='onChange=""';
												echo form_input($data, date("d-m-Y", strtotime($dateFrom)), $js);
											?>       
				                        </div>
			                        </div>
			                        <div class="span6 tac">
				                    	<div class="span4 tal"><?php echo form_label($this->lang->line('dateTo'));?></div>
				                        <div class="input-prepend span8">
					                        <span class="add-on span2"><i class="i-calendar"></i></span>
											<?php
												$data = array(
												'name' => 'dateTo',
												'id' => 'dateTo',
												'type' => 'text',
												'class' => 'span8 datepicker2 financhk',);
												$js='onChange=""';
												echo form_input($data, date("d-m-Y", strtotime($dateTo)), $js);
											?>       
				                        </div>
			                        </div>                                    
                                </div><!-- End Row 4-->
                                <div class="controls-row"><!-- Row 4-->
									<div class="span6 tac">
				                    	<div class="span4 tal"><?php echo form_label($this->lang->line('search'));?></div>
				                        <div class="span8 fr">
											<?php
												$txt = $search == 'all'?'':urldecode($search);
												$data = array(
												'name' => 'search',
												'id' => 'search',
												'type' => 'text',
												'class' => 'span10',
												'placeholder' => 'Keywords'
												);
												$js='onChange="changeList()"';
												echo form_input($data, $txt, $js);
											?>       
				                        </div>
			                        </div>
			                        <div class="span6 tac">
				                    	<div class="span4 tal"><?php echo form_label($this->lang->line('typeOfQuery'));?></div>
				                        <div class="span8 fr">
		                                    <?php
		                                    	$preselcat = !empty($type)?$type:'';
                                        		$options = array();
												$options['all'] = 'Select query type';
												$options['insert'] = 'Insert';
												$options['update'] = 'Update';

		                                        $js='ID="queryType" class="span10"';
		                                        echo form_dropdown('queryType', $options, $preselcat, $js);
		                                    ?>
		                                </div>
			                        </div>                                    
                                </div><!-- End Row 4-->
                            </div>
                            <div class="footer">
                            	<div class="side fr">
	                            	<div class="btn-group">
	                                    <!-- <button id="calcul" onclick="getTotal()" class="btn btn-warning" type="button"> 
	                                        <i class="i-checkmark-3"></i>Calculate Total</button> -->
										<button id="search" onclick="changeList()" class="btn-icon btn-info-form" style="margin-left:5px;" type="button"> 
	                                        <i class="i-info"></i>Search</button>
	                                </div>
                                </div>
                            </div>
                        </div>
                        <div class="block">                            
                            <div class="head">
                                <h2><?php echo $this->lang->line('title') ?></h2>
                                <div class="side fr">
            				 		<a href="<?php echo base_url();?>logreport/logReportListPrint/<?php echo $user.'/'.$dateFrom.'/'.$dateTo.'/'.$type.'/'.$search; ?>" class="btn-form btn-success-form" target="_blank">Print</a>
                        		</div>
                            </div><!-- head -->
                            <div class="content np table-sorting">
                                <table cellpadding="0" cellspacing="0" width="100%" id="test" class="editable itemTbl">
                                    <thead>
                                    <tr>
                                    	<th style="display:none;">&nbsp;</th>
                                    	<th class="tac">#</th>
                                    <?php foreach($tbHdr as $row): ?>
                                        <th class="tac"><?php echo $this->lang->line($row); ?></th>
                                    <?php endforeach; ?>                       		
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <?php $bil = 0; 
                                    if(isset($datatbls) && !empty($datatbls)):
                                        foreach($datatbls as $item):
                                        $bil++?>
                                        <tr class="itemList">
                                        	<td class="ID" style="display:none"><?php echo $item->ID; ?></td>
                                            <td class="tac"><?php echo $bil; ?></td>
										<?php foreach($tbHdr as $row): ?>
                                            <td class="tac span2">
												<?php
													echo $item->$row; 
												?>                                            	        
                                            </td>
                                        <?php endforeach; ?>
                                        </tr>
                                        <?php 
                                        endforeach;
                                    endif;?>
                                    </tbody>         
                                </table>
                            </div><!-- content -->                              
                        </div><!-- block -->
                    </div><!-- span12 -->
                </div><!-- row-fluid -->	
            </div><!-- wrap -->
        </div><!-- content -->
	</div>
</div>
</div>
</div>
