|
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 : |
<?
#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 "savenode.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_raw.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;
}
*/
$xweight = 1;
//@16/8/2550
if ($pro_id == 31 && $mm==6 && $siteid == 0){
$mm = 3;
}
$kpi_array = array(); // clear array
$node_array = array(); // clear array
if ($yy == 2550 && $mm == 3 && $siteid == 0){ //cache เฉพาะรอบ 6 เดือน ของกรม
// save
if ($_GET[save]){
//list($total_si, $total_wi, $total_wisi) = GetNodeValue_raw($parentid,$yy,$mm,0,0);
list($total_si, $total_wi, $total_wisi) = GetNodeValue_raw(0,$yy,$mm,0,0);
SaveKPIArray();
SaveNodeArray();
}else{
LoadKPIArray();
LoadNodeArray();
list($total_si, $total_wi, $total_wisi) = $node_array[0];
}
}else{
//คำนวณสด
list($total_si, $total_wi, $total_wisi) = GetNodeValue_raw(0,$yy,$mm,0,0);
}
$reposition = 1;
if ($reposition){
//list($total_wix, $total_six, $total_wisix) = Repositioning($pro_id,$psiteid,0);
//$total_si = $total_wisix/$total_wix;
list($wi,$sum_si,$wisi) = Repositioning($pro_id,$psiteid,0);
$total_si = $wisi / $wi;
$total_wi = $wi;
$total_wisi = $wisi;
$node_array[0] = array($total_si, $total_wi, $total_wisi);
}
//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 ) ){ //หมวด
if ($rs[node_type] == 1 ){ //หมวด
/*
$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];
*/
// check node type
$sql = "select node_type from kpi_tree where node_id='$rs[source_node_id]' and siteid='$rs[source_siteid]';";
$kpi_type= Query1($sql);
if ($kpi_type == 1){ // A/B/C
$compute = 0;
$goal1 = $wi1 = $si1 = $wisi1 = 0;
$sql = "select t1.*,t2.goal,t2.wi from kpi_tree_member t1 inner join $kpitable t2 on t1.kpi_id=t2.id where t1.node_id='$rs[source_node_id]';";
//echo $sql;
$kresult = mysql_query($sql);
while ($krs=mysql_fetch_assoc($kresult)){
list($ksi,$kwi,$kwisi,$kval) = $kpi_array[$krs[kpi_id]];
if ($kwi > 0 ){ //ไม่เอาอันที่ weight 0 มาคิด
$compute += $kval;
$si1 += $ksi;
$wisi1 += $kwisi;
//echo "$krs[kpi_id] = $ksi,$kwi,$kwisi,$kval<BR>";
$goal1 += $krs[goal];
$wi1 += $krs[wi];
}
} //while
if ($si1 < 1){
$si1 = 1;
}
$wisi1 = $si1 * $wi1; //คำนวณ weight ของตัวแม่ ใหม่อีกที
$compute = $si1; // ผลงานที่ทำได้ ของตัวแม่ จะเท่ากับค่าคะแนน
$grade = $si1;
$xscore = $si1;
$tscore = 5;
}else{ // node ปกติ
list($si1, $wi1, $wisi1) = $node_array[$rs[source_node_id]];
$grade = $si1;
$xscore = $si1t;
$tscore = 5;
}
$critical = Query1("select gainalert from kpi_tree where siteid='$rs[source_siteid]' and node_id='$rs[source_node_id]';");
if ($critical == "") $critical = 0;
$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($grade) < floatval($critical)){
$alink = "../../application/management/sarlist.php?pro_id=$pro_id&psiteid=$rs[siteid]&nodeid=$rs[node_id]&yy=$yy&mm=$mm&alert=1&nodesi=$grade";
}
//หาตัวลูกที่ค่าน้อยกว่า gain alert
if ($alink == ""){
$sql = "SELECT * from $provisiontreetable where pro_id='$pro_id' and parent_id='$rs[node_id]' and siteid='$rs[siteid]';";
$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&nodesi=$xvalue";
break;
}
} // while
} //if
$rs[node_name_cp] = str_replace("[ส่วนกลาง]","",$rs[node_name_cp]);
$wi1 = floatval($wi1);
$critical = number_format($critical,2);
$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 = 0;
$grade = $ksi;
$xscore = $kval;
$link1 = "$cpd_path&id=$pro_id&psiteid=$psiteid&nodeid=" . $rs[node_id] . "&yy=$yy&mm=$mm";
if (floatval($grade) < floatval($critical)){
$alink = "../../application/management/sarlist.php?pro_id=$pro_id&nodeid=$rs[node_id]&psiteid=$rs[siteid]&yy=$yy&mm=$mm&alert=1&nodesi=$grade";
}
$kwi = floatval($kwi);
$kpi_link = "../../application/management/kpitotal.php?id=$rs[kpi_id]&yy=$yy&mm=$mm";
$rs[node_name_cp] = str_replace("[ส่วนกลาง]","",$rs[node_name_cp]);
$critical = number_format($critical,2);
$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 ;
$gain6 = $gain9 = 3;
//@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';");
//$gain6 = Query1("select gain6 from $kpitreetable where siteid='$xsiteid' and node_id='$xid';");
$xgainalert = Query1("select gainalert from $kpitreetable where siteid='$psiteid' and node_id='$xid';");
$gain6 = Query1("select gain6 from $kpitreetable where siteid='$psiteid' and node_id='$xid';");
}else{
$totalgain = $totalgain6 = 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]';");
$xgainalert6 = Query1("select gain6 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;
$totalgain6 += $xgainalert6 * $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;
if ($xkval . "" != ""){ //ถ้าไม่เป็น N/A
$totalgain6 += $xgainalert * $xwi1;
}
$totalgain_weight += $xkwi;
}
} //while
$xgainalert = round($totalgain / $totalgain_weight,2);
$gain6 = round($totalgain6 / $totalgain_weight,2);
} // if
$main_xscore = $total_si * 20 ; //เต็ม 100
$main_grade = $total_si ;
//@16/8/2550
if ($pro_id == 31 && $mm==3 && $siteid == 0){
$mm = 6;
}
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='" . number_format($xgainalert,4) . "' actualgoal='" . number_format($gain6,4) . "' >";
$s1 = str_replace("&","&",$s1);
$s2 = str_replace("&","&",$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);
?>