<?  
	session_start(); 
?>
<!DOCTYPE >
<html >
<head>
<meta charset=utf-8>
<title>Untitled Document</title>
<script>
$(document).ready(function() {
    $('#usertb').DataTable({
		
		"columnDefs": [
            	/*{
                	"targets": [ 1 ],
                	"visible": false,
                	"searchable": false
            	},
				{
					"targets": [ 6 ],
                	"visible": false,
                	"searchable": false
				},
				{
					"targets": [ 10 ],
					"orderable": false
				},
				{
					"targets": [ 11 ],
					"orderable": false
				}*/
            
        	],
			"createdRow": function ( row, data, index ) { //กำหนดเงือนไขเปลี่ยน style ของคอลัมน์หรือแถว
				if ( data[5]=='Admin' ) {
					$('td', row).eq(5).addClass('highlight'); //กำหนดสีของ คอลัมน์ที่ 5 ตาม style class ขื่อ highlight
				}
			},
			"dom": '<"toolbar">lBfrtip', //กำหนดส่วนหัวเอง
			buttons: [
            	//'copy', 'excel', 'print', 'colvis' //'csv','pdf',
				/*{
                	extend: 'print',
					text: '<i class="ti-printer"></i> Print',
					exportOptions: {
						columns: [ 0, 2, 3, 4, 5 ]
                    	//modifier: {
                        	//selected: true
                    	//}
					}
                },
                {
                    extend: 'excel',
					text: '<i class="ti-export"></i> Export to Excel',
					exportOptions: {
                    	columns: [ 0, 2, 3, 4, 5 ]
                	}
                },
				{
					extend: 'colvis',
					text: '<i class="ti-layout"></i> Show/Hide Column',
					exportOptions: {
                    	columns: [ 0, 2, 3, 4, 5 ]
                	}
				}*/
			],
			//select: true,
			order: [[ 0, "asc" ]], //กำหนดการจัดเรียง เริ่มต้น defale
			lengthMenu: [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]]   //กำหนดจำนวนแสดงรายการแต่ละหน้า	
	});
	
	$("div.toolbar").html('<b>รายการผู้ใช้งานระบบ (User Detail) </b>'); //กำหนดชื่อตารางด้านบน
	
	//กำหนดส่วน footer ให้มีช่องพิมพ์ textbox สำหรับค้นหา
		$('#usertb tfoot th').each( function () {
			var title = $(this).text();
			if((title != 'แก้ไข') && (title !='ลบ') && (title !='ลายเซนต์') && (title !='รูปภาพ') ){
				$(this).html( '<input type="text" placeholder=" '+title+'" style="width:90%;"  />' );
			}else{
				$(this).html(' ');	
			}
		} );
		
		// Apply the search ค้นหาจาก footer ------------------------
		$('#usertb').DataTable().columns().every( function () {
			var that = this;
			//ค้นหาจาก footer	
			$( 'input', this.footer() ).on( 'keyup change', function () {
				if ( that.search() !== this.value ) {
					that
						.search( this.value )
						.draw();
				}
			} );
		} );
});
</script>
<style>
	td.highlight {
        font-weight: bold;
        color: blue;
    }
	.toolbar {
		text-align:center;
    	/*float:left;*/
	}
</style>
</head>

<body>
<div>
<table id="usertb" class="display cell-border compact row-border table table-striped table-bordered" cellspacing="0" width="100%">
	<thead>
      <tr>	
          <th style="text-align:center;">ลำดับที่</th>
          <th>รหัส</th>
          <th>ชื่อ</th>
          <th>นามสกุล</th>
          <th>Name</th>
          <th>lastname</th>
          <th>บริษัท</th>
          <th>สาขา</th> 
          <th>แผนก</th> 
          <th>ตำแหน่ง</th>
          <th>รูปภาพ</th>  
          <th style="text-align:center;">แก้ไข</th>
          <th style="text-align:center;">ลบ</th>
      </tr>
  </thead>
   <tfoot>
          <tr>	
              <th style="text-align:center;">ลำดับที่</th>
              <th>รหัส</th>
              <th>ชื่อ</th>
              <th>นามสกุล</th>
              <th>Name</th>
              <th>lastname</th>
              <th>บริษัท</th>
              <th>สาขา</th> 
              <th>แผนก</th> 
              <th>ตำแหน่ง</th> 
              <th>รูปภาพ</th> 
              <th style="text-align:center;">แก้ไข</th>
              <th style="text-align:center;">ลบ</th>
          </tr>
      </tfoot>
      <tbody>
  	  <?
	include "../../Connections/connect_mysql.php";
	$sql=" select * from user_tb order by userid desc; ";
	$result = mysql_query($sql) or die(mysql_error());
	$rowint = 1;
	while($record=mysql_fetch_array($result)){
		//$emp_id = $record['emp_id'];
		//$emp_begin_name = iconv('tis-620','utf-8',$record['emp_begin_name']);
		$userid = $record['userid'];
		$usercode = $record['usercode'];
		$usernameth = $record['usernameth'];
		$userlnameth = $record['userlnameth'];
		$usernameen = $record['usernameen'];
		$userlnameen = $record['userlnameen'];
		$usersex = $record['usersex'];
		$userposition = $record['userposition'];
		$userdepartment = $record['userdepartment'];
		$usercompany = $record['usercompany'];
		$userbranch = $record['userbranch'];
		$userloginname = $record['userloginname'];
		$userpassword = $record['userpassword'];
		$userpin = $record['userpin'];
		$userpicpath = $record['userpicpath'];
		$createby = $record['createby'];
		$createtime = $record['createtime'];
		$updateby = $record['updateby'];
		$updatetime = $record['updatetime'];
		$statustrans = $record['statustrans'];
		$statonline = $record['statonline'];
		$lasttimeonline = $record['lasttimeonline'];
		$remark = $record['remark'];
		
		$sqlps= " select * from position_tb where posid={$userposition} ";
		$resultps = mysql_query($sqlps) or die(mysql_error());
		$recordps=mysql_fetch_array($resultps);
		$poscode = $recordps['poscode'];
		$posname = $recordps['posname'];
		
		$sqlds = " select * from department_tb where dpmid={$userdepartment} ";
		$resultds = mysql_query($sqlds) or die(mysql_error());
		$recordds=mysql_fetch_array($resultds);
		$dpmcode = $recordds['dpmcode']; 
		$dpmname = $recordds['dpmname'];
		
		$sqlcs = " select * from company_tb where compid={$usercompany}";
		$resultcs = mysql_query($sqlcs) or die(mysql_error());
		$recordcs=mysql_fetch_array($resultcs);
		$compcode = $recordcs['compcode']; 
		$compnameth = $recordcs['compnameth'];
		
		$sqlbs = " select * from branch_tb where branid={$userbranch}";
		$resultbs = mysql_query($sqlbs) or die(mysql_error());
		$recordbs=mysql_fetch_array($resultbs);
		$brancode = $recordbs['brancode'];
		$branname = $recordbs['branname'];
		
			
?>
  <tr style="cursor:pointer;">
      <td style="text-align:center;"><?=$rowint?></td>
      <td><?=$usercode?></td>
      <td><?=$usernameth?></td>
      <td><?=$userlnameth?></td>
      <td><?=$usernameen?></td>
      <td><?=$userlnameen?></td>
      <td>(<?=$compcode?>) <?=$compnameth?></td>
      <td>(<?=$brancode?>) <?=$branname?></td>
      <td>(<?=$dpmcode?>) <?=$dpmname?></td>
      <td>(<?=$poscode?>) <?=$posname?></td>
      <td><? if($userpicpath=="" || $userpicpath=="-" ){ ?><button type="button" class="btn btn-primary" onClick="javascript:uploaduserpic('<?=$usercode?>','<?=$usernameth?>','<?=$userlnameth?>');"><i class="fa fa-file-image-o"></i> Upload file </button> <? }else{ ?><button type="button" class="btn btn-info" onClick="showuserpic(<?=$userid?>,'<?=$usernameth?>','<?=$userlnameth?>');"><i class="fa fa-picture-o"></i> Show file </button><? } ?></td>
	  <td><button type="button" class="btn btn-info" onClick="javascript:edituser(<?=$userid?>);" ><i class="fa fa-pencil-square-o"></i> แก้ไข</button></td>
      <td><button type="button" class="btn btn-danger" onClick="javascript:deluser(<?=$userid?>);"><i class="fa fa-trash"></i> ลบ</button></td>	
  </tr>
<?
		$rowint = $rowint + 1;
		
   }//while
		
?>	    
  
      </tbody>
</table>


</div>
</body>
</html>
<?
	mysql_close($c);
?>