MINI SHELL

Server : Apache/2.2.2 (Fedora)
System : Linux App1.pathumtani.go.th 2.6.20-1.2320.fc5smp #1 SMP Tue Jun 12 19:40:16 EDT 2007 i686
User : apache ( 48)
PHP Version : 5.2.9
Disable Function : NONE
Directory :  /var/www/html/pathumthani_vc/report/sar/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/html/pathumthani_vc/report/sar/cpd.php
<?
if ($pagebypass !="ON"){
	if($yy!=""){ $str_yy="&yy=$yy";}else{ $str_yy =""; }
	if($mm!=""){ $str_mm="&mm=$mm";}else{ $str_mm =""; }
	header ("Location: cpd_raw.php?nodesi=$nodesi&id=$id&nodeid=$nodeid&psiteid=$psiteid$str_yy$str_mm");    
	exit;
}

#START
###### This Program is copyright Sapphire Research and Development co.,ltd ########
#########################################################
$ApplicationName= "KPI Builder";
$module_code = "KPI_PROV";
$process_id="CPD";

$VERSION = "2.41";
$BypassAPP= false; // true = ไม่ต้องเช็ค , false = เช็คสิทธิ
#########################################################
#Developer::Poramin
#DateCreate::29/03/2007
#LastUpdate::29/03/2007
#DatabaseTable::
#END
#########################################################		
session_start();
if($_SESSION[secid]==""){
	$dbname = "obec";
	$siteid = 0;
}
include_once "db.inc.php";
//include_once ("../../inc/authority.inc.php") ;
$time_start = getmicrotime();

set_time_limit(900);

include "kpi_tree.inc.php";
include "kpi_calculate.inc.php";

header("Content-Type: Text/xml");
echo '<?xml version=\'1.0\' encoding=\'windows-874\' ?>';

/*
$xid = explode("_",$id); //id = xxx_yyy (proid_nodeid)
$pro_id = intval($xid[0]);
$id = intval($xid[1]);

*/

$pro_id = $id;
$id = intval($nodeid); 


if ($yy==""){
	$yy = Query1("select max(yy) from vardata;");
}

if ($mm==""){
	$mm = Query1("select max(mm) from vardata where yy='$yy';");
}


$cpd_path = "../../application/management/cpd.php";
$result = mysql_query("SELECT * from $protable where  pro_id='$pro_id' and siteid='$psiteid';");
$rs = mysql_fetch_assoc($result);
$threshold_value = intval($rs[threshold]); //กำหนดค่า Threshold
$title = $rs[provision_name];
if ($rs[pro_caption_cp] > ""){
	$title=$rs[pro_caption_cp];
}

$psiteid = $rs[siteid];   //เอา siteid จาก DB
$xproid = intval($pro_id);


if (strstr($title,"ศึกษาสงเคราะห์")){
	$xweight = 0.89; //ศึกษาสงเคราะห์
}else if (strstr($title,"ศรีสังวาลย์")){
	$xweight = 0.84; 
}else if (strstr($title,"ริมใต้")){
	$xweight = 0.76; 
}else{
	$xweight = 1;
}



$kpi_array = array(); // clear array
$node_array = array(); // clear array
//list($total_si, $total_wi, $total_wisi) = GetNodeValue($id,$yy,$mm,0,0);
list($total_si, $total_wi, $total_wisi) = GetNodeValue(0,$yy,$mm,0,0);

//echo "<pre>"; print_r($kpi_array); exit;

$n=0;
$sql 	= "SELECT * from $provisiontreetable where  pro_id='$pro_id' and parent_id='$id'  and siteid='$psiteid';";
$result	= mysql_query($sql)or die("Query line " . __LINE__ . " error<hr>".mysql_error());
while ($rs=mysql_fetch_array($result,MYSQL_ASSOC)){	
	$menuitem++;

	$alink="";
	$xscore= 0.00;
	$tscore = 0.00;
	$grade = 0.00;

	if ($rs[node_type] == 1 && (Query1("SELECT count(*) from $provisiontreetable where  pro_id='$pro_id' and parent_id='$rs[node_id]'; ") > 0 ) ){  //หมวด

/*
		$sql = "select * from $nodedata where mm='$mm' and yy='$yy' and siteid='$rs[siteid]' and node_id='$rs[source_node_id]';"; 
		$kresult = mysql_query($sql);
		$krs = mysql_fetch_assoc($kresult);
		$grade = $krs[si];
		$xscore = $krs[compute];
*/
		list($si1, $wi1, $wisi1) = $node_array[$rs[source_node_id]];
		$grade = $si1*$xweight;
		$xscore = $si1*$xweight;
		$tscore = 5;
		$critical = Query1("select gainalert from kpi_tree where siteid='$rs[source_siteid]' and node_id='$rs[source_node_id]';");
		if ($critical == "") $critical = 3;

		$link1 = "$cpd_path&id=$pro_id&psiteid=$psiteid&nodeid=$rs[node_id]&yy=$yy&mm=$mm";
/*
		//check ว่ามีลูกที่ต่ำกว่าเกณฑ์หรือไม่
		$found = false;
		$cresult = mysql_query("SELECT * from $provisiontreetable where  pro_id='$pro_id' and parent_id='$rs[node_id]'; ");
		while ($crs = mysql_fetch_assoc($cresult)){
			if ($crs[node_type] == 1 ){
				list($si2, $wi2, $wisi2) = $node_array[$crs[source_node_id]];
				if ($si2*$xweight < 3){
					$found = true;
					break;
				}
			}else{
				list($ksi,$kwi,$kwisi,$kval) = $kpi_array[$crs[kpi_id]];
				$critical = Query1("select gainalert from $kpitable where siteid='$rs[source_siteid]' and id='$rs[kpi_id]';");
				if ($critical . "" == "") $critical = 3;
				if (floatval($ksi*$xweight) < floatval($critical)){
					$found = true;
					break;
				}
			} //if
		} // while

		if ($found){
			$alink = "../../application/management/sarlist.php?pro_id=$pro_id&psiteid=$rs[siteid]&yy=$yy&mm=$mm&alert=1";
		}
		*/
//		$link1 = urlencode($link1);

		if (floatval($xscore) < floatval($critical)){
			$alink = "../../application/management/sarlist.php?pro_id=$pro_id&psiteid=$rs[siteid]&nodeid=$rs[node_id]&yy=$yy&mm=$mm&alert=1";
		}

		//หาตัวลูกที่ค่าน้อยกว่า gain alert
		if ($alink == ""){
			$sql 	= "SELECT * from $provisiontreetable where  pro_id='$pro_id' and parent_id='$rs[node_id]'  and siteid='$psiteid';";
			$xresult	= mysql_query($sql)or die("Query line " . __LINE__ . " error<hr>".mysql_error());
			while ($xrs=mysql_fetch_array($xresult,MYSQL_ASSOC)){	
				if ($xrs[node_type] == 1 && (Query1("SELECT count(*) from $provisiontreetable where  pro_id='$pro_id' and parent_id='$xrs[node_id]'; ") > 0 ) ){
					//node
					$xgainalert = Query1("select gainalert from $kpitreetable where siteid='$xrs[source_siteid]' and node_id='$xrs[source_node_id]';");
					list($xsi1, $xwi1, $xwisi1) = $node_array[$xrs[source_node_id]];
					$xvalue = $xsi1;
				}else{
					//kpi
					$xgainalert = Query1("select gainalert from $kpitable where siteid='$xrs[source_siteid]' and id='$xrs[kpi_id]';");
					list($xksi,$xkwi,$kxwisi,$xkval) = $kpi_array[$xrs[kpi_id]];
					$xvalue = $xksi;
				}

				if ($xvalue < $xgainalert){
					$alink = "../../application/management/sarlist.php?pro_id=$pro_id&psiteid=$rs[siteid]&nodeid=$rs[node_id]&yy=$yy&mm=$mm&alert=1";
					break;
				}

			} //while
		} //if


		$rs[node_name_cp] = str_replace("[ส่วนกลาง]","",$rs[node_name_cp]);
		$wi1 = floatval($wi1);

		$x = "<port pName='$rs[node_name_cp]' dataType='cockpit' dataScr='' pHeight='' linkName='main.php?cpfile=$link1' linkWindows='_self' exportName='' exportWindows='' alertLink='$alink' alertWindow='_blank'><score actualScore='" . number_format($xscore,4) . "' totalScore='$wi1' actualGrade='" . number_format($grade,4)  . "' totalGrade='5' upDate=''  critical='$critical' /></port>";

	
	
	}else{ //KPI

/*
		$kresult = mysql_query("select * from $kpidata where mm='$mm' and yy='$yy' and siteid='$siteid' and kpi_id='$rs[kpi_id]';");
		$krs = mysql_fetch_assoc($kresult);
		$grade = $krs[si];
		$xscore = $krs[compute];
*/
		list($ksi,$kwi,$kwisi,$kval) = $kpi_array[$rs[kpi_id]];
		$tscore = Query1("select goal from $kpitable where siteid='$rs[source_siteid]' and id='$rs[kpi_id]';");
		$critical = Query1("select gainalert from $kpitable where siteid='$rs[source_siteid]' and id='$rs[kpi_id]';");
		if ($critical . "" == "") $critical = 3;
		$grade = $ksi*$xweight;
		$xscore = $kval*$xweight;

		$link1 = "$cpd_path&id=$pro_id&psiteid=$psiteid&nodeid=" . $rs[node_id] . "&yy=$yy&mm=$mm";
		if (floatval($xscore) < floatval($critical)){
			$alink = "../../application/management/sarlist.php?pro_id=$pro_id&nodeid=$rs[node_id]&psiteid=$rs[siteid]&yy=$yy&mm=$mm&alert=1";
		}

		$kpi_link = "../../application/management/kpitotal.php?id=$rs[kpi_id]&yy=$yy&mm=$mm";

		$rs[node_name_cp] = str_replace("[ส่วนกลาง]","",$rs[node_name_cp]);
		$kwi = floatval($kwi);

		$x = "<port pName='$rs[node_name_cp]' dataType='cockpit' dataScr='' pHeight='' linkName='$kpi_link' linkWindows='_blank' exportName='' exportWindows='' alertLink='$alink' alertWindow='_blank' linkgis='../../application/thematic/theme.php?command=areaid:66|year:$yy|mm:$mm|kpiid:$rs[kpi_id]' linkgisWindows='_blank'> <score actualScore='" . number_format($xscore,4) . "' totalScore='$kwi' actualGrade='" . number_format($grade,4)  . "' totalGrade='5' upDate='' critical='$critical'  /></port>";
	}

	$n++;
	if ($n % 2){
		$s1 .= $x;
	}else{
		$s2 .= $x;
	}

} // while

$main_xscore = 0.00;
$main_grade = 0.00;
$mmx = ($mm + 3) % 12 ;

//@23/6/2550 ถ้าเป็น node หลัก ไม่น่าจะมี source_node_id
//$snode = Query1("select source_node_id from $provisiontreetable where  pro_id='$pro_id' and node_id='$id'; ");
//list($si1, $wi1, $wisi1) = $node_array[intval($snode)];
//$main_xscore = $si1 * 20 *$xweight; //เต็ม 100
//$main_grade = $si1 *$xweight;

if ($id > 0){
	$sql 	= "SELECT source_node_id from $provisiontreetable where  pro_id='$pro_id' and node_id='$id'  and siteid='$psiteid';";
	$xid = Query1($sql);
	$sql 	= "SELECT source_site_id from $provisiontreetable where  pro_id='$pro_id' and node_id='$id'  and siteid='$psiteid';";
	$xsiteid = Query1($sql);
	list($total_si, $total_wi, $total_wisi) = $node_array[$xid];
	$xgainalert = Query1("select gainalert from $kpitreetable where siteid='$xsiteid' and node_id='$xid';");
}else{
	$totalgain = 0;
	$totalgain_weight = 0;

	$sql 	= "SELECT * from $provisiontreetable where  pro_id='$pro_id' and parent_id='0'  and siteid='$psiteid';";
	$xresult	= mysql_query($sql)or die("Query line " . __LINE__ . " error<hr>".mysql_error());
	while ($xrs=mysql_fetch_array($xresult,MYSQL_ASSOC)){	
		if ($xrs[node_type] == 1 && (Query1("SELECT count(*) from $provisiontreetable where  pro_id='$pro_id' and parent_id='$xrs[node_id]'; ") > 0 ) ){
			//node
			$xgainalert = Query1("select gainalert from $kpitreetable where siteid='$xrs[source_siteid]' and node_id='$xrs[source_node_id]';");
			list($xsi1, $xwi1, $xwisi1) = $node_array[$xrs[source_node_id]];
			$totalgain += $xgainalert* $xwi1;
			$totalgain_weight += $xwi1;
		}else{
			//kpi
			$xgainalert = Query1("select gainalert from $kpitable where siteid='$xrs[source_siteid]' and id='$xrs[kpi_id]';");
			list($xksi,$xkwi,$kxwisi,$xkval) = $kpi_array[$xrs[kpi_id]];
			$totalgain += $xgainalert* $xwi1;
			$totalgain_weight += $xkwi;
		}

	} //while

	$xgainalert = round($totalgain / $totalgain_weight,2);
} // if


$main_xscore = $total_si * 20 * $xweight; //เต็ม 100
$main_grade = $total_si *$xweight;

echo "<detail hName='$title' yy='$yy' mm='$mm' gNumber='2' textBackGround='VISUAL CONTROL' imgBG='xx.jpg' actualScore='" . number_format($main_xscore,4) . "' totalScore='100' actualGrade='" . number_format($main_grade,4) . "' totalGrade='5' upDate='' goal='$xgainalert'>";

$s1 = str_replace("&","&amp;",$s1);
$s2 = str_replace("&","&amp;",$s2);
?>
<groupDetail gName='leftPort' pNumber='' xPos='0' yPos='0'>
<?=$s1?>
</groupDetail>

<groupDetail gName='rightPort' pNumber='' xPos='293.3' yPos='0'>
<?=$s2?>
</groupDetail>
<?


echo "</detail>";
$time_end = getmicrotime(); writetime2db($time_start,$time_end);
?>

Anon7 - 2021