403Webshell
Server IP : 182.53.201.61  /  Your IP : 216.73.217.175
Web Server : Apache/2.2.15 (Fedora)
System : Linux km10.dyndns.org 2.6.31.5-127.fc12.i686.PAE #1 SMP Sat Nov 7 21:25:57 EST 2009 i686
User : apache ( 48)
PHP Version : 5.3.3
Disable Function : NONE
MySQL : ON  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/html/room/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/room/Report.php
<?php
$ebits = ini_get('error_reporting');
error_reporting($ebits ^ E_NOTICE);
session_start();
include("dbconfig.php");
mysql_select_db("KPI"); 
mysql_query("SET NAMES 'tis620'; ");
if (isset($_GET['logoff'])  &&  $_GET['logoff']=='yes') 	{
	$_SESSION["uDept"]='NA';
	$_SESSION["cUserName"] ='Guest';
	$usr='xxxx';
} else {
	if (!isset($_SESSION["cUserName"]))$_SESSION["cUserName"] ='Guest';
	if (!isset($_SESSION["uDept"]))$_SESSION["uDept"]='NA';
	if (!isset($_SESSION["cUserID"]))$usr='xxxx';
	else $usr=$_SESSION["cUserID"];
}
if (!isset($_SESSION["Done"])) $_SESSION["Done"] = 'Y';
/* ------------------------------------------------------------------------------------------------------------------------------------------
										Authentication
 ------------------------------------------------------------------------------------------------------------------------------------------*/
if (isset($_POST['username'])) {	     
	$_SESSION["uDept"]='NA';
	$usr = trim($_POST['username']);  
	/*
		เช็ค user ด้วย UDP ผ่านโปรแกรม watchdog.exe
		ให้บริการที่ 192.168.1.2 port 8500
		รูปแบบ 'ChkUsrXXXXX#password'
		ถ้าถูกต้อง  จะได้คำตอบเป็น คำนำหน้าชื่อ;ชื่อ นามสกุล
		ถ้าไม่ถูกจะได้คำตอบเป็น UnAuth
		
	*/
	//$sock=socket_connect_timeout($host, $port, $timeout=100)	

	if(($sock = socket_create(AF_INET, SOCK_DGRAM, 0)))
	{
		// lน่าจะเป็น System local เป็น UTF8  จึงไม่ต้อง iconv( 'UTF-8','TIS-620', $reply);
		$input = 'ChkUsr'.$usr.'#'.trim($_POST['password']);
		$Login ='Na';
		Socket_set_option ($sock, SOL_SOCKET, SO_RCVTIMEO, Array ("sec" => 5, "usec" => 100));//Receive
		Socket_set_option ($sock, SOL_SOCKET, SO_SNDTIMEO, Array ("sec" => 5, "usec" => 10));//Send   
		$server = '192.168.1.2';	//SERVER หลัก
		$port = 8500;
		if (socket_sendto($sock, $input , strlen($input) , 0 , $server , $port))
		if (socket_recv ( $sock , $reply , 2045 , MSG_WAITALL ) )$Login = $reply;  // iconv( 'UTF-8','TIS-620', $reply)
		echo $Login.'<br>';
		if ($Login == 'Na'){
			$Login ='UnAuth';
			$server = '192.168.1.14';   //SERVER สำรอง
			if (socket_sendto($sock, $input , strlen($input) , 0 , $server , $port))
			if (socket_recv ( $sock , $reply , 2045 , MSG_WAITALL ) )$Login = $reply; // iconv( 'UTF-8','TIS-620', $reply)
			echo $Login.'<br>';
		}
	} else $Login ='UnAuth';
	//---------------------------------------------------------------------------
	if ($Login <>'UnAuth') {
		$_SESSION["cUserName"] = substr($Login,10);
		$cName = substr($_SESSION["cUserName"],strpos($_SESSION["cUserName"],";")+1 );
		if (strpos($cName,' ')) $cName =substr($cName ,0,strpos($cName,' '));
		$_SESSION["cUserName"] =str_replace(";","",$_SESSION["cUserName"]);
		
		$sql= "select * from  indicators where name like '%".$usr."%' ";   //เช็คว่ามี usr (id) ใน  indicators ไหม
		$result=mysql_query($sql);
		while ($object = mysql_fetch_array($result)) {
		     $sql= 'ok' ;
			 break;
		}
		if ($sql=='ok'){	//พบ user ID ใน ตาราง indicator
			$sql='select * from  users  where password = "'.$usr.'"';
			$result=mysql_query($sql);
			while ($object = mysql_fetch_array($result)) {  //และพบใน ตาราง Users 
				if ($object['username']<>$cName || $object['name']<>$_SESSION["cUserName"]){  //ชื่อไม่ตรงให้ update
					$sql='update users  set  username = "'.$cName.'" ,name ="'.$_SESSION["cUserName"].'"  where password = "'.$usr.'"';
					$result2=mysql_query($sql);
				}
				if (trim($object['dept'])<>'')	$_SESSION["uDept"] = $object['dept'];
				$sql='ok';
				break;
			}
			if ($sql <> 'ok'){ 
				$sql='insert into  users  (username ,name,password) values ("'.$cName.'" ,"'.$_SESSION["cUserName"].'" , "'.$usr.'")';
				$result=mysql_query($sql);
			}
		}
		else {   //ไม่พบ user ID ใน ตาราง indicator อาจพบใน ตาราง Users
			$sql='select * from  users  where password = "'.$usr.'"';
			$result=mysql_query($sql);
			while ($object = mysql_fetch_array($result)) {
				$_SESSION["uDept"] = $object['dept'];
			}
		}	
	}
	if ($_SESSION["cUserName"] =='Guest'){
		echo '<script language="javascript">';
		echo 'alert("ไม่ถูกต้อง")';
		echo '</script>';
	}
}
$_SESSION["cUserID"]=$usr;
//-----------
if (!isset($_SESSION["DeptName"])){
	//เพื่อให้ให้ค้นครั้งเดียวพอ จะได้ไม่หน่วงหน้า web 
	$curID=0;
	$deptList='';
	$sql="select * from dept order by dept_id";
	$result=mysql_query($sql);
	while ($object = mysql_fetch_array($result)) {
		if (	$object['dept_id'] == $curID) {
			if ($deptList == '') $deptList='"'.$object['dept'].'"';
			else $deptList .=',"'.$object['dept'].'"';
			$curID +=1;
		} else {
			for ($i = $curID; $i <= $object['dept_id']; $i++) {
				if ($i == $object['dept_id']){
					if ($deptList == '') $deptList='"'.$object['dept'].'"';
					else $deptList .=',"'.$object['dept'].'"';
				} else {
				if ($deptList == '') $deptList='""';
				else $deptList .=',""';
				}
			}
			$curID = $object['dept_id']+1;
		}
	}	
	eval ('$_SESSION["DeptName"] = array('.$deptList.'); '); 
}
/*------------------------------------------------------------------------------------------------------------------------------------------
														Call from ADD_Report 
/*------------------------------------------------------------------------------------------------------------------------------------------*/
if ($_SESSION["Done"] <> 'Y'){				//ป้องกัน Refresh
	if (isset( $_POST['delete']) && $_POST['delete']=='ลบตัวชี้วัด'){						
			$sql="update indicators  set active ='N' where id_no=".$_POST['id_no']; 
			$result=mysql_query($sql);
			/*active ='N'  ลบ*/
	} else {
		if (isset($_POST['insert']) || isset( $_POST['append']) ) {	     
			if ($_POST['insert']=='บันทึกข้อมูล' || $_POST['append']=='เพิ่มตัวชี้วัด') {
				$_POST['amount']+=0;	//ปรับเป็นตัวเลข
				$_POST['total']+=0;
				$nCurID = $_POST['id_no']+0;
				/* กรณีที่ SAVE จาก "add_report "  

					1.ปรับปรุง หน่วยงานรับผิดชอบ dept ฐาน indicators 
					*************************************
				*/
				
				$Savedate = (substr($_POST['DateRegis'],6)-543).'-'.substr($_POST['DateRegis'],3,2).'-'.substr($_POST['DateRegis'],0,2);
				$deptList = '';
				foreach($_POST["framework"] as $row) {
					$deptList .= $row . ',';  //ต้องมี , ปิดท้ายเสมอ ไว้ค้นหา
				}
				$response =  str_replace(",",";",$_POST['response']);
				if(substr($response,0,1)<> ";") $response =";".$response ;
				if ( $_POST['append']=='เพิ่มตัวชี้วัด') {
						$sql="insert into indicators (indicators,dept,name,name1,name2,def,sd,st,sr,HA,PA,GA,goal,eva,compair) 
						values ('".$_POST['indicators']."','".$deptList."','".$_POST['name']."','".$_POST['name1']."','".$_POST['name2']."','"
						.$_POST['def']."','".$_POST['sd']."','".$_POST['st']."','".$_POST['sr']."','".$_POST['response2'].
						"','".$_POST['response3']."','".$_POST['response4']."',".$_POST['goal2'].",'".$_POST['goal3']."','".$_POST['goal1']."')";
						$result=mysql_query($sql);	
						$sql="select * from indicators where id_no=LAST_INSERT_ID()";
						$result=mysql_query($sql);	
						$nCurID = mysql_insert_id();
				}else{
					$sql="update indicators  set indicators='".$_POST['indicators']."',dept ='".$deptList."',name='".$_POST['name1']."',
					name1='".$_POST['name1']."',name2='".$_POST['name2']."',def='".$_POST['def']."' ,sd='".$_POST['sd']."',st='".$_POST['st']."',sr='".$_POST['sr']."',HA='"
					.$_POST['response2']."',PA='".$_POST['response3']."',GA='".$_POST['response4']."',name='".$_POST['name'].
					"',goal=".$_POST['goal2'].",eva='".$_POST['goal3']."',compair='".$_POST['goal1']."' where id_no=".$nCurID; 
					$result=mysql_query($sql);
					
				}
				
				//echo $_POST['insert'].'<br>' ;  //เอาไว้ตรวจสอบ $_POST['insert']
				//echo $_POST['append'].'<br>' ; 
				//echo $sql.'<br>';
				   // echo mysql_error();   //เอาไว้ตรวจสอบ error  
				//echo $Savedate;
				//echo  $sql; //ตรวจคำสั่ง update
				//------------------------------------------------------------------------------
		
				/*  2.บันทึกข้อมูล " รายวัน " ฐาน Result  
					*****************************
				*/
				$sql="delete from  result  where id_no=".$nCurID." and date = '".$Savedate."'";
				$result=mysql_query($sql);		//โดยลบข้อมูลวันเดิมออกก่อน (ป้องกันบันทึกซ้ำ )
				$sql="insert into result (id_no,date,amount,total) values (".$nCurID.",'".$Savedate."',".$_POST['amount'].",".$_POST['total'].")";
				$result=mysql_query($sql);	 	// แล้ว insert ใหม่ 

				/* 3.รวมข้อมูลเป็นรายเดือน
					 จาก Result เพื่อบันทึกในฐาน goal ช่องเดือน(m1-12 และ m1b-m12b)ของ reccord ตามปีงบปรมาณนั้น	*/
				//   3.1 กำหนดตัวแปร ปีงบประมาณ
				$ButgMonth = substr($Savedate,5,2);
				$ButgYear   = substr($Savedate,0,4);
				if ($ButgMonth >='10') {
					$firstButgDate =$ButgYear.'-10-01';
					$ButgMonth = $ButgMonth-9;    					//$ButgMonth 1,2,3  คือเดือนตุลาคม 10 - ธันวาคม 12
					$ButgYear = $ButgYear+1;
				} else {
					$firstButgDate = ($ButgYear-1).'-10-01';
					$ButgMonth = ($ButgMonth+3);  				//$ButgMonth 4 - 12  คือเดือนมกราคม 1 - กันยายน 9
				}	
				$nextm = date('Y-m-t',strtotime($Savedate)); 	//วันสุดท้ายของเดือน
				//   3.2  ตรวจสอบข้อมูลใน Goal เอาเป้าหมายสุดท้ายมา ใช้กรณีไม่สะสมเป้าหมาย ($nTotalb)
				$suma=0;	$sumt=0;	$nTotalb =0;	$txtData  ='';
				$sql="select * from goal where id_no=".$nCurID." and year = '".$ButgYear."' limit 1" ;
				$oGoal = mysql_query($sql);
				$gRows = mysql_num_rows($oGoal);
				if ($gRows > 0) {	//เคยมีบรรทัดปีนี้ 
					while ($object = mysql_fetch_array($oGoal)) {
						$txtData = trim($object['data']);
						$nTotalb = $object['totalb']+0;
					}
				}
				//   3.3  ผลงาน 
				if ( $_POST['sr'] =='Y'  ) { 	 	//   3.3.1  กรณีระบุว่าใช้ผลงาน สุดท้าย 
				 	$lSumm=false;
					$sql="select  *  from result where id_no=".$nCurID." and date >= '".substr($Savedate,0,8)."01' and 
					date <= '".$nextm."'  order by date DESC limit 1" ;
					$result=mysql_query($sql);
					while ($object = mysql_fetch_object($result)) {
						$suma = ($object ->amount)+0;		//ยอดสุดท้ายในเดือน
						break;
					}
				
				} else { 									//	3.3.2  กรณีระบุว่าใช้ผลงานสะสม
					$lSumm=true;
					$sql="select sum(amount) as suma  from result where id_no=".$nCurID." and date >= '".substr($Savedate,0,8)."01' and date <= '".$nextm."'" ;
					$result=mysql_query($sql);
					while ($object = mysql_fetch_object($result)) {
						$suma = ($object ->suma)+0;	   //ยอดรวมในเดือน
						break;
					}
				}
				//	3.4 เป้าหมาย
				if ( $_POST['st'] =='Y'  ) {  	// 3.4.1  กรณีระบุว่าไม่สะสม 
				
					$lSumY=false;
					$sql="select  *  from result where id_no=".$nCurID." and total > 0 and  
					date >= '".$firstButgDate."' and date <= '".$nextm."' order by date DESC limit 1" ;  
					$result=mysql_query($sql);
					while ($object = mysql_fetch_object($result)) {
						$sumt = ($object ->total)+0;  	//ยอดเป้าหมายที่ใส่ล่าสุดในปีถึงเดือนนี้
						break;
					}
					if ($sumt==0) $sumt =$nTotalb;		//ไม่มีบันทึกเป้าหมาย เอาค่าที่บันทึกไว้ครั้งสุดท้าย

				} else {								// 3.4.2  กรณีระบุว่าใช้เป้าหมายสะสม
				
					$lSumY=true;
					$sql="select  sum(total) as sumt from result where id_no=".$nCurID." and date >= '".substr($Savedate,0,8)."01' and date <= '".$nextm."'" ;
					$result=mysql_query($sql);
					while ($object = mysql_fetch_object($result)) {
						$sumt = ($object -> sumt)+0;		//เป้าหมายสะสมในเดือน
						break;
					}
				}
				
				// 4 บันทึก ผลรายเดือนที่ได้ ลงฐาน goal บรรทัด " ปีงบประมาณ "ที่ระบุ
				
				if ($gRows == 0) {	//ไม่เคยมีบรรทัดปีนี้ ให้ insert
					$txtData= ';'.substr('{reg000000000000}',0,$ButgMonth+3).'1'.substr('{reg000000000000}',$ButgMonth+4);
			
					$sql="insert into goal (id_no,year,compair,goal,eva,m".$ButgMonth.",m".$ButgMonth."b,data) 
					value (".$nCurID.",'".$ButgYear."','".$_POST['goal1']."',".$_POST['goal2'].",'".$_POST['goal3']."',".$suma.",".$sumt.",'".$txtData."')";
				} else {  					//เคยมีบรรทัดปี ให้Update
					$npos = strpos($txtData,'{reg');
					if ( $npos >= 1 ) 	$txtData = substr($txtData,0,$npos+$ButgMonth+3).'1'.substr($txtData,$npos+$ButgMonth+4);
					else $txtData .= ';'.substr('{reg000000000000}',0,$ButgMonth+3).'1'.substr('{reg000000000000}',$ButgMonth+4);
					
					$sql="update goal set  m".$ButgMonth."=".$suma.",m".$ButgMonth."b=".$sumt.
					",goal=".$_POST['goal2'].",eva='".$_POST['goal3']."',compair='".$_POST['goal1'].
					"',data='".$txtData."'  where id_no=".$nCurID." and year='".$ButgYear."'";
				}
				$result=mysql_query($sql);
				//echo $sql.'<br>';
				/*
					5.รวมข้อมูลรายปี goal ช่องเดือน 1 ถึง 12 
				*/
				$suma=0;
				$sumt=0;
				$sql="select * from goal  where id_no=".$nCurID." and year = '".$ButgYear."' limit 1" ;
				$result=mysql_query($sql);
				while ($object = mysql_fetch_array($result)) {
					$compair = trim($object['compair'] );
					$eva =$object['eva'] ;
					$goal =$object['goal'] ;
					for ($i = 1; $i <= 12; $i++) {
						if ($lSumm) $suma = $suma+$object["m".$i];
						else 	if ($object["m".$i] > 0)	$suma = $object["m".$i];	//  กรณีระบุว่าใช้ผลงาน สุดท้าย (ลงท้ายด้วย L)
						if ($lSumY)  $sumt = $sumt +$object["m".$i."b"]; //รวมทุกเดือน
						else 	if  ($object["m".$i."b"] > 0)   $sumt = $object["m".$i."b"];	//เดือนที่มีค่าล่าสุด
					}
				}
				$totalx=$suma;   // ผลประเมิน บันทึกไว้ใน $totalx
				switch (substr(trim($eva),0,1)) {
					case 'n':
						if ($suma==0) $totalx = 0.00;
						else {
							if ($sumt==0) $totalx = $suma;
							else $totalx = $suma /$sumt ; 
						}
						break;
					case ':':		
						if ($suma==0) $totalx = 0.00;
						else {
							if ($sumt==0) $totalx = 1.00;
							else	$totalx = $suma /$sumt ; 
						}
						break;
					case '%':		// ถ้าเป้าเป็น % ผลประเมินต้องเป็น %
						if ($suma==0) $totalx = 0.00;
						else {
							if ($sumt==0) $totalx = 100.00 ;
							else  $totalx = $suma *100/$sumt ;  
						}
						break;
					case 'T':		// ถ้าเป้าเป็น /1000 
						if ($suma==0) $totalx = 0.00;
						else {
							if ($sumt==0) $totalx = 1000.00 ;
							else	$totalx = $suma *1000/$sumt ;
						}
						break;
					
					case 'H':		// ถ้าเป้าเป็น /100,000 
						if ($suma==0) $totalx = 0.00;
						else {
							if ($sumt==0) $totalx = 100000.00 ;
							else	$totalx = $suma *100000/$sumt ;
						}
						break;
					
					case '/':			// ถ้าเป้าเป็นค่าเฉลี่ย
						if ($suma==0) $totalx = 0.00;
						else {
							if ($sumt==0) $totalx = $suma;
							else $totalx = $suma /$sumt ; 
						}
						break;
				}
				if ($compair =="=" || $compair=='') $compair ="==";
				$result='red';
				//พิจารณาตาม compair
				eval ('if ('.$totalx.$compair.$goal.') $result = "green"; '); 
				//บันทึกผลประเมิน ปี
				$sql="update goal set  total=".$suma.",totalb=".$sumt.",totalx=".$totalx.",result='".$result."' 
				where id_no=".$nCurID." and year='".$ButgYear."'";
				//echo $sql.'<br>';
				$result=mysql_query($sql);
			}
		}
	}
}
$_SESSION["Done"] = 'Y';
/* ------------------------------------------------------------------------------------------------------------------------------------------
										 onChange()  จะมีตัวแปร $_GET[ ] ส่งมาด้วย 
------------------------------------------------------------------------------------------------------------------------------------------*/
if (isset($_GET['Rdept'])) $_SESSION['deptRep'] = $_GET['Rdept'];
elseif (!isset($_SESSION['deptRep'])) $_SESSION['deptRep'] = 'All'; 
if (isset($_GET['resp'])) $_SESSION['resp'] = $_GET['resp'];
elseif (!isset($_SESSION['resp'])) $_SESSION['resp'] = 'All'; 
if (isset($_GET['work'])) $_SESSION['work'] = $_GET['work'];
elseif (!isset($_SESSION['work'])) $_SESSION['work'] = 'All'; 
if (isset($_GET['byear']))	$_SESSION['byear'] = $_GET['byear'];
if (!isset($_SESSION['byear'])){    				// -- เข้า page นี้ครั้งแรกให้ใช้ ปีปัจจุบัน
	$year =  date('Y');
	$mon = date('m');
	if ($mon >= 10)	$_SESSION['byear'] =$year+544;
	else $_SESSION['byear'] =$year+543;
} 
$year = $_SESSION['byear']-543;		// -- เข้า page ครั้งต่อๆไป จะมีปีเป็นตามที่ใช้อยู่
?>
<!DOCTYPE html>
<html>
<script type="text/javascript"> 
	function getValue(vname) 
	{ 
		var n = document.getElementById(vname).value
		return n;
	} 
	function changeFunc(cLOG) {
    	var URL;
		URL= "<?php echo $_SERVER['PHP_SELF'] ?>";
		URL+= "?&byear=";
		URL+= getValue('byear');
		URL+= "&Rdept=";
		URL+= getValue('dept_id');
		URL+= "&resp=";
		URL+= getValue('resp_id');
		URL+= "&work=";
		URL+= getValue('work');
		URL+= "&logoff=";
		URL+= cLOG;
		window.location= URL;
   	}
	function createDynamicURL(cIDNO,cYear,cName){
	var URL;
	URL="ControlChart.php?&id_no=";
	URL+= cIDNO;
	URL+= "&rYear=";
	URL+= cYear;
	URL+= "&RepName=";
	URL+= cName;
	return URL;
  }
  function RedirectURL(cIDNO,cYear,cName){
	//window.location= createDynamicURL(cIDNO,cYear,cName);
	window.open(createDynamicURL(cIDNO,cYear,cName), '_blank');
  }
</script>
<style>
.tooltip {
  position: relative;
  display: inline-block;
  border-bottom: 1px dotted black;
}

.tooltip .tooltiptext {
  visibility: hidden;
  width: 120px;
  background-color: #555;
  color: #fff;
  text-align: center;
  border-radius: 6px;
  padding: 5px 0;
  position: absolute;
  z-index: 1;
  bottom: 125%;
  left: 50%;
  margin-left: -60px;
  opacity: 0;
  transition: opacity 0.3s;
}

.tooltip .tooltiptext::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -5px;
  border-width: 5px;
  border-style: solid;
  border-color: #555 transparent transparent transparent;
}

.tooltip:hover .tooltiptext {
  visibility: visible;
  opacity: 1;
}
</style>
<head>
<title>รายงานตัวชี้วัด</title>
<script language="JavaScript" src="bak/date-picker.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
</head>
<body background="image/bg.JPG" >
<table width="1015" height="51" border="0" align="center" cellpadding="3">
  <tr>
    <td align="center"><table width="1200" border="0">
      <tr align="left" valign="top">
        <td width="180"><p><a href="image/คู่มือ KPI.pdf"><img src="image/major.gif" align="left" title="คู่มือการใช้งาน" ></p> 
        <p>คู่มือการใช้งาน</p></a></td>
      <td width="700" align="center"><img src="image/templatemo_logo.png" width="184" height="43" align="top"></a>
      <div align="center"><br>
    <span class="style3" > ตอบสนองวิสัยทัศน์ : บริการปลอดภัย ร่วมใจทุกภาคี เจ้าหน้าที่มีความสุข</span></td>
	<td width="306"> ชื่อผู้ใช้งาน : &nbsp;<?php echo $_SESSION["cUserName"].'<br>Department:'.$_SESSION["uDept"]; ?></td>
  </tr>
</table> 

<table width="1200" height="45" border="2" align="center" cellpadding="3" cellspacing="2" bordercolor="#000000" background="bak/image/bg.JPG">
  <tr>
    <td width="75"  align="center" ><span class="style4"><a href="about.php">เกี่ยวกับเรา</a></span></td>
	<td width="100"><p>ปี
	    <input type="text" name="byear" id="byear" size="10" value="<? echo $_SESSION['byear'];?>" onChange="changeFunc('')">
</td>
	<td width="264" bgcolor="#F0F0F0"><p>ฝ่ายงาน
		<select name="dept_id" id="dept_id" style="width:75%; height:24px" onChange="changeFunc('')" >
				<option value="All" <?php if($_SESSION['deptRep'] == 'All'){echo("selected");}?>>&nbsp;&nbsp;ทั้งหมด</option>
				<option value="Adm" <?php if($_SESSION['deptRep'] == 'Adm'){echo("selected");}?>>&nbsp;&nbsp;ที่รับผิดชอบ</option>
			<?php
				//mysql_select_db("KPI");
				//mysql_query("SET NAMES 'tis620'; ");
				$sql="select * from dept ";
				$result=mysql_query($sql);
				while ($rowResp = mysql_fetch_object($result)) {
    				if ($_SESSION['deptRep'] == $rowResp -> dept_id)
					echo '<option value="'.$rowResp -> dept_id .'" selected >'.$rowResp-> dept_id.
					"&nbsp;&nbsp;&nbsp;&nbsp;".$rowResp-> dept.'</option>';
					else 
					echo '<option value="'.$rowResp -> dept_id .'" >'.$rowResp-> dept_id.
					"&nbsp;&nbsp;&nbsp;&nbsp;".$rowResp-> dept.'</option>';
				}
				?>			
	</select></p></td>  
		<td width="228"><p>ภารกิจ
		    <select name="resp_id" id="resp_id" style="width:75%; height:26px" onChange="changeFunc('')" >
              <option value="All" <?php if($_SESSION['resp'] == 'All'){echo("selected");}?>>&nbsp;&nbsp;ทั้งหมด</option>
              <?php
				mysql_select_db("KPI");
				mysql_query("SET NAMES 'tis620'; ");
				$sql="select * from response order by resp_id";
				$result=mysql_query($sql);
				while ($rowresp = mysql_fetch_object($result)) {
    				if ($_SESSION['resp'] == $rowresp -> colum_name)
					echo '<option value="'.$rowresp -> colum_name .'" selected >'.$rowresp-> resp_id.
					"&nbsp;&nbsp;&nbsp;&nbsp;".$rowresp-> response.'</option>';
					else 
					echo '<option value="'.$rowresp ->colum_name.'" >'.$rowresp-> resp_id.
					"&nbsp;&nbsp;&nbsp;&nbsp;".$rowresp-> response.'</option>';
				}
				?>
            </select>
		</p></td>
		<td width="200">ประเมินผล
			<select name="work" id="work" style="width:50%; height:26px" onChange="changeFunc('')" > 
		 		<option value="All" <?php if ($_SESSION['work'] == 'All') echo 'selected'; ?>>ทั้งหมด</option>
		 		<option value="green" <?php if ($_SESSION['work'] == 'green') echo 'selected'; ?>>ผ่าน</option>
		 		<option value="red" <?php if ($_SESSION['work'] == 'red') echo 'selected'; ?>>ไม่ผ่าน</option>
				<option value="null" <?php if ($_SESSION['work'] == 'null') echo 'selected'; ?>>ไม่มีผลงาน</option>
			</select>    	</td>
		<td width="42" align="center" valign="top"><?php 
			if ($_SESSION["uDept"]=='NA') 
				echo '<a href="login.php"><img src="image/user.gif" 
				width="31" height="30" border="0"  title="ลงชื่อเข้าใช้งาน">Login</a>';
			else 
				echo '<img src="image/log_off.png" 
				width="31" height="30" border="0"  title="ออกจากระบบ" onclick="changeFunc(\'yes\')">Logout';
		?></td>
  </tr>
</table>
<?php
$sql="select b.id_no,b.dept,b.indicators,b.HA,b.PA,b.GA,b.name1,b.name2,b.name,b.def from  indicators b where b.active = 'Y'";
if ($_SESSION['deptRep'] <>'All' ) {
	if ($_SESSION['deptRep'] == 'Adm' ) $sql .=" AND instr(b.name,'".$usr."') " ;
	else $sql .=" AND instr(b.dept,'".$_SESSION['deptRep']."')" ;
}
if ($_SESSION['resp'] <> 'All' ) {
	$sql.= " AND b." .$_SESSION['resp']." is not null  AND b.".$_SESSION['resp']." <> '' order by b.".$_SESSION['resp'];
}
else  $sql .= " AND H<>'Y' order by id_no";
//else  $sql .= " order by id_no";
//echo $sql.'<br>';

//echo $sql;      // เอาไว้ อ่านทบทวน ค่ำสั่ง SQL
?>
<br>
<table width="1300" height="63" border="2" align="center" cellpadding="3"  bgcolor="#FFFFFF">
  <tr>
    <td width="75" align="center" bgcolor="#66FFFF"><strong>&nbsp;<?php 
		if ($_SESSION['resp'] <> 'All' ) echo $_SESSION['resp'];
		else echo 'ID_NO';
	?></strong>
	</td>
    <td width="320" align="center"  bgcolor="#66FFFF"><strong> ตัวชี้วัด  &nbsp; Indicators</strong></td>
    <td width="94" align="center"  bgcolor="#66FFFF"><strong> ค่าเป้าหมาย &nbsp;</strong></td>
    <td width="54" align="center" bgcolor="#CCCCCC"><strong> ปี <? echo $year+537;?></strong></td>
    <td width="54" align="center" bgcolor="#CCCCCC"><strong> ปี <? echo $year+538;?></strong></td>
   <td width="54" align="center"  bgcolor="#CCCCCC"><strong> ปี <? echo $year+539;?></strong></td>
    <td width="54" align="center"  bgcolor="#CCCCCC"><strong> ปี <? echo $year+540;?></strong></td>
    <td width="54" align="center" bgcolor="#CCCCCC"><strong> ปี <? echo $year+541;?></strong></td>
    <td width="54" align="center" bgcolor="#CCCCCC"><strong> ปี <? echo $year+542;?></strong></td>
    <td width="54" align="center"  bgcolor="#66FFFF"><strong> ปี <? echo $year+543;?></strong></td>
	<td width="120" align="center"  bgcolor="#66FFFF"><strong>กลุ่มงาน</strong></td>
	<td width="100" align="center"  bgcolor="#66FFFF"><strong>ผู้รับผิดชอบ</strong></td>
  </tr>
<?php
$nIndicators=0;
$nPass=0;
$nlIndicators=0;
$nlPass=0;
$nHpass=0;
$nHIndi=0;
$lastID='';
$result=mysql_query($sql);
while ($object = mysql_fetch_object($result)) {  // วน LOOP แต่ละ ID_NO ในตาราง indicators ที่ Active ='Y' (ไม่ได้ลบ)
    $deptList = $object -> dept;
    $id_no = $object -> id_no;
	$indicators=$object -> indicators;
	$name1=$object -> iname1;
	$name2=$object -> iname2;
	$def=$object -> def;
	if ($_SESSION['resp'] <> 'All' )	eval ('$showid = $object ->'.$_SESSION['resp'].';');
	else $showid = $id_no;
	if ( substr($showid,-2,2)=='00') { //กรณีหัวข้อกลุ่ม
		$lastID=$showid;
		$nIndicators +=$nHIndi;
		$nPass += $nHpass;
		if ($_SESSION['resp']=='HA'){
			if ( substr($showid,2,5)=='00000'){
				$color1='#880088';   //สีของหัวข้อหลัก <a>
				$color2='#0000ff';	  //สีของหัวข้อหลัก 
				$pb = '<br>';
				$pe='';
				$nHpass=0;
				$nHIndi=0;
				$colsp='10';
			} else {
				$color1='#0000ff';   //สีของหัวข้อรอง <a>
				$color2='#000000';	  //สีของหัวข้อรอง 
				$pb = '';
				$pe='';
				$nHpass=1;
				$nHIndi=1;
				$colsp='11';
			}
			echo '<tr height="24" >'; 
			if (InDept( $deptList,  $_SESSION['uDept'] ) || strpos($namecode,$usr ) ) {
					echo '<td >'.$pb.'<div align="center"><a href="add_report.php?&id_no='.$id_no.'&goal=&eva=&compair=" style="color:'.$color1.';">'.$showid.'</a></div>'.$pe.'</td>';
					echo '<td colspan="'.$colsp.'">'.$pb.'<div align="left"><a href="add_report.php?&id_no='.$id_no.'&goal=&eva=&compair=" style="color:'.$color1.';">'.$indicators.'</a></div>'.$pe.'</td>';
			} else {
				echo '<td >'.$pb.'<font color="'.$color2.'" ><div align="center">'.$showid.'</div></font>'.$pe.'</td>';
				echo '<td colspan="'.$colsp.'">'.$pb.'<font color="'.$color2.'" ><div align="left"  >'.$indicators.'</div></font>'.$pe.'</td>';
			}
			if ($colsp=='10'){
				echo '<td ><font color="'.$color2.'" ><div align="left"  >';
				if ($nIndicators > 0){
					echo  $nPass-$nlPass;
					echo ' / ';
					echo $nIndicators - $nlIndicators;
					
				}
				$nlIndicators=$nIndicators;
				$nlPass=$nPass;
				echo '</div></font></td>';
				
			}
			echo '</tr>';
		}
	 } else {
		//รายการย่อย
		$namecode =$object ->name ;
		$name ='';  							//ชื่อ user สำหรับแสดง
		while ($namecode <> ''){ 		//นำรหัสมาแปลงเป็นชื่อ ทีละคน
			if (strpos($namecode,',')){
				$i = strpos($namecode,',');
				$tcode = trim(substr($namecode,0,$i));
				$namecode =trim(substr($namecode,$i+1));
			}else{
				$tcode = trim($namecode);
				$namecode = '';
			}	
			$sql ="select username from users  where password='".$tcode."' limit 1";
			$resname=mysql_query($sql);
			while ($rec = mysql_fetch_object($resname)) {
				$sql = $rec-> username;
				if (strpos( $sql,' ')) $sql = substr($sql,0,strpos( $sql,' '));
				if ( $name =='') $name = $sql ;
				else $name.= ', '. $sql ;
			}
		} 
		$namecode =$object ->name ;
		$ntotalb =0;
		$cResult = '';
		$cReccord = '';
		$ntotalx = 0;
		$sql="select * from goal  where id_no=".$id_no." and  year <='".$year."'   order by year desc limit 3";  //ข้อมูล
		$rg=mysql_query($sql);
		while ($re = mysql_fetch_object($rg)) {
			if  ($re -> year == $year) {
				$ntotalb = $re -> totalb;
				$ntotalx = $re -> totalx;
				$cResult = $re -> result;
				$cReccord = $re -> data;
				$npos = strpos($cReccord,'{reg');
				if ( $npos >= 1 ) 	$cReccord = '0'.substr($cReccord,$npos+4);
				else $cReccord ='0';
				$no= $re -> no;
			}
			$compair = $re ->compair ; 	//การเทียบค่า
			$eva = $re ->eva ;    				//ค่า evaluation
			$goal = $re ->goal ;					//ค่าเป้าหมาย
			$cgoal = trim($compair).trim($goal).' '.trim($eva);
			if (!empty($goal) || !empty($eva)) break;
		}
		$cInlist = 'Y';
		if ($_SESSION['work'] <> 'All' ){   //ตรวจผลงาน เพื่อแสดงพื้นสี ประกอบด้วย
			if  ($_SESSION['work'] == 'null' ) {
				if ($ntotalb > 0) $cInlist = 'N';
			} else {
				if (trim($cResult)<>$_SESSION['work']) $cInlist='N';
			}
		}
		if ($cInlist=='Y') {
			$Ayear =array(array('green','-    '),array('green','    '),array('green','    '),array('green','    '),array('green','    ')
						,array('green','    '));
						
			$minYear = $year-6;
			$sql="select year,totalx,result,data from goal  where id_no=".$id_no." and  year >='".$minYear."' and year < '".$year."'";
			$resYear=mysql_query($sql);
			while ($rec = mysql_fetch_object($resYear)) {
				$nowY =$rec-> year;
				$nowY = 6-($year-$nowY );
				$Ayear[$nowY][1] = $rec-> totalx;
				$Ayear[$nowY][0] = ($rec-> result);
			}
			//<tr>
			if (substr($lastID,0,5) == substr($showid,0,5)) {   //เป็นข้อย่อย
				$lSub=true;
				$color1='#002255';   //สีของหัวข้อย่อย มี link
				$color2='#004499';	  //สีของหัวข้อย่อย 
			} else {																	//หัวข้อรายการปกติ		
				$lSub=false;
				$color1='#0000ff';   //สีของหัวข้อปกติ	 มี link
				$color2='#000000';	 
			}
			echo '<tr height="24" >'; 
			if (InDept( $deptList,  $_SESSION['uDept'] ) || strpos($namecode,$usr ) ) {
					echo '<td ><div align="center"><a href="add_report.php?&id_no='.$id_no.'&goal='.$goal.'&eva='.$eva.'&compair='.$compair.'" style="color:'.$color1.';">'.$showid.'</a></div></td>';
					echo '<td ><div align="left"><a href="add_report.php?&id_no='.$id_no.'&goal='.$goal.'&eva='.$eva.'&compair='.$compair.'" style="color:'.$color1.';">'.$indicators.'</a></div></td>';
			} else {
				echo '<td ><font color="'.$color2.'" ><div align="center">'.$showid.'</div></font></td>';
				echo '<td ><font color="'.$color2.'" ><div align="left"  >'.$indicators.'</div></font></td>';
			}
			echo '<td align="center"><div align="center" class="tooltip">'.$cgoal .'<span class="tooltiptext">'.$def.'</span></div></td>';
			for ($i = 0; $i <= 6; $i++) {   // ---   แสดง ข้อมูล ย้อนหลัง 6 ปี
				$show = '<td  align="right" ';
				if ($i==6 && $ntotalb == 0) {  //ปีล่าสุด
					if (strpos($cReccord,'1') > 0) $show.='bgcolor="#CCFFE5"';
					else $show.='bgcolor="#FFFF00"';
				}
				$show.=' bordercolor="#FFFFFF"><a href="#" onclick="RedirectURL(\''.$id_no.
				'\',\''.($year+(537+$i)).'\',\''.$indicators.'\');return false;" target="_parent" class="style14" 
				style="text-decoration: none;"><font color="';
				if ($i == 6){									//ปีเป้าหมาย
					$show .=$cResult.'">'.$ntotalx.'</font></a></td>';
					if ($lSub) {
						if ($cResult=='red') 	$nHpass =0;;
					} else  {
							$nIndicators += $nHIndi+1;
							$nHIndi =0;
							$nPass += $nHpass;
							if ($cResult=='green') 	$nPass += 1;		//ผลงานผ่านตัวชีวัด
							$nHpass =0;
					} 
				}	
				else $show .=$Ayear[$i][0].'">'.$Ayear[$i][1].'</font></a></td>';
				echo $show;
			}
			if (substr_count($deptList,',') > 1) echo '<td align="center"><div class="tooltip">'.$deptList.'<span class="tooltiptext">'. DeptName($deptList).'</span></div></td>';
			else echo '<td>'.DeptName($deptList).'</td>';
			echo '<td align="center">'. $name.'</td></tr>';
		//</tr>
		}
	}
 }
$nIndicators +=$nHIndi;
$nPass += $nHpass;
if ($nIndicators > 0){
	echo '<tr height="24" >'; 
	echo '<td colspan="11"></td><td><font color="#000000"><div align="left"  >';
	echo  $nPass-$nlPass;
	echo ' / ';
	echo $nIndicators - $nlIndicators;
	echo '</div></font></td></tr>';
}
?>
</table>
<table width="1300" height="63" border="2" align="center" cellpadding="3"  bgcolor="#FFFFFF">
  <tr>
    <td width="184" align="center"><strong>&nbsp;จำนวนตัวชี้วัดทั้งหมด</strong></td>
	<td><?php echo $nIndicators; ?></td>
	<td>ผ่านเป้าหมาย :<?php echo $nPass; ?></td>
	<td>ผ่านเป้าหมาย :<?php echo number_format($nPass*100/$nIndicators,2); ?> %</td> 
	</tr>	
</table>
<?php
 function InDept($i_Dept,$u_Dept){
	if ($u_Dept=='All,') return true;
	if (trim($i_Dept)=='' || $u_Dept=='NA') return false;
	while ($i_Dept<>''){
	 	$nAt = strpos($i_Dept,',');
		if ($nAt ) {
			$subc = substr($i_Dept,0,$nAt+1);
			if (substr_count($u_Dept,$subc) > 0) return true;
			$i_Dept = substr($i_Dept,$nAt+1);
		} else return false;
	}
	return false;
} 
function DeptName($cList){
	$cName='';
	while ($cList<>''){
	 	$nAt = strpos($cList,',');
		if ($nAt ) {
				$subc = substr($cList,0,$nAt);
				$cList = substr($cList,$nAt+1);
		} else {
				$subc = 'NA';
				$cList = '';
		}
		if ($subc <> 'NA'){
			if ($cName=='') $cName =$_SESSION['DeptName'][($subc+0)]; 
			else 	$cName .= ','.$_SESSION['DeptName'][($subc+0)]; 
		}
	}
	return $cName; //number_format($number, 2, '.', '');
}
?>
</body>
</html>
<?php
function socket_connect_timeout($host, $port, $timeout=100){

    $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

    /**
     * Set the send and receive timeouts super low so that socket_connect
     * will return to us quickly. We then loop and check the real timeout
     * and check the socket error to decide if its conected yet or not.
     */
    $connect_timeval = array(
        "sec"=>0,
        "usec" => 100
    );
    socket_set_option(
        $socket,
        SOL_SOCKET,
        SO_SNDTIMEO,
        $connect_timeval
    );
    socket_set_option(
        $socket,
        SOL_SOCKET,
        SO_RCVTIMEO,
        $connect_timeval
    );

    $now = microtime(true);

    /**
     * Loop calling socket_connect. As long as the error is 115 (in progress)
     * or 114 (already called) and our timeout has not been reached, keep
     * trying.
     */
    $err = null;
    $socket_connected = false;
    do{
        socket_clear_error($socket);
        $socket_connected = @socket_connect($socket, $host, $port);
        $err = socket_last_error($socket);
        $elapsed = (microtime(true) - $now) * 1000;
    }
    while (($err === 115 || $err === 114) && $elapsed < $timeout);

    /**
     * For some reason, socket_connect can return true even when it is
     * not connected. Make sure it returned true the last error is zero
     */
    $socket_connected = $socket_connected && $err === 0;

    if($socket_connected){

        /**
         * Set keep alive on so the other side does not drop us
         */
        socket_set_option($socket, SOL_SOCKET, SO_KEEPALIVE, 1);

        /**
         * set the real send/receive timeouts here now that we are connected
         */
        $timeval = array(
            "sec" => 0,
            "usec" => 0
        );
        if($timeout >= 1000){
            $ts_seconds = $timeout / 1000;
            $timeval["sec"] = floor($ts_seconds);
            $timeval["usec"] = ($ts_seconds - $timeval["sec"]) * 1000000;
        } else {
            $timeval["usec"] = $timeout * 1000;
        }
        socket_set_option(
            $socket,
            SOL_SOCKET,
            SO_SNDTIMEO,
            $timeval
        );
        socket_set_option(
            $socket,
            SOL_SOCKET,
            SO_RCVTIMEO,
            $timeval
        );

    } else {

        $elapsed = round($elapsed, 4);

        if(!is_null($err) && $err !== 0 && $err !== 114 && $err !== 115){
            $message = "Failed to connect to $host:$port. ($err: ".socket_strerror($err)."; after {$elapsed}ms)";
        } else {
            $message = "Failed to connect to $host:$port. (timed out after {$elapsed}ms)";
        }

        throw new Exception($message);

    }

    return $socket;

}
?>

Youez - 2016 - github.com/yon3zu
LinuXploit