<?php
/*************************************************************************      
* 文件说明：         
*    功能说明:MAP状态显示页面服务器端，
*
*    调用关系：        
*
*
* 作者：Cui Ticun    2005-10-31     
*      
*修改注释：      
*NO.1      
*Name：            
*Time：
*Modify description：      
*************************************************************************/
require("../../inc/lib.inc");

$tmpSql = "SELECT existFlag From elementExistConf WHERE elementName='BSS'";
global $pubConn;
if($DEBUG)
	echo "<br>tmpSql=$tmpSql";
$tmpResult=mysqli_query($pubConn,$tmpSql);
echo mysqli_error($pubConn);
$tmpRows=mysqli_fetch_array($tmpResult);

$bssExistFlag=$tmpRows['existFlag'];

$dbName='OMC_PUB';
$ledConfTable='sysLedConf';
$ledStatTable='sysLedStat';

$nLedNoUsed	='00';
$nLedOk		='01';
$nLedWarn	='02';
$nLedError	='03';
$nLedAlarm  ='04';
$NotShowLED ='15';
$shapeArr=array("circle","square","rectangle","triangle","rectangle_v","star");
$suffixArr=array(".gif","_f.gif");
$divideNumber='20489';

function getLedStatus($status_str,$led_num){
	global $NotShowLED,$divideNumber;
	$status_num = $NotShowLED;

	$offset = 0;
	if($led_num < $divideNumber){
		$offset = ($led_num % 16)*2;
	}else{
		$offset = 0;
	}
	if($DEBUG) 
	echo "<br>led_num=$led_num,status_str=$status_str,offset=$offset";
	$status_num = substr($status_str,$offset,2);
	if($DEBUG) 
	echo "<br>status_num=$status_num";

	if($status_num >=0 && $status_num <=$NotShowLED){
		return($status_num&0x07);
	}else{
		return($NotShowLED);
	}
}

$pageIndex=$typeOffset+$pageNum;
if($bssExistFlag==1)
	$selSql = "SELECT T1.key_led_num,T2.key_status,T1.point_x,T1.point_y,T1.shape,T1.remark,T1.dst_page_type,T1.dst_page_num 
						FROM $ledConfTable AS T1,$ledStatTable AS T2  
						WHERE (
						if(T1.sync_from_led < 0 && T2.key_led_num < $divideNumber,floor(T1.key_led_num/16) = T2.key_led_num,T1.key_led_num = T2.key_led_num) 
						OR 
						if(T1.sync_from_led >= 0 && T2.key_led_num < $divideNumber,floor(T1.sync_from_led/16) = T2.key_led_num,T1.sync_from_led = T2.key_led_num) 
						)
						AND T1.key_src_page_type ='$showingPageType' 
						AND T1.key_src_page_num = '$pageIndex' 
						AND T2.key_status != '15151515151515151515151515151515'
						";
else	
	$selSql = "SELECT T1.key_led_num,T2.key_status,T1.point_x,T1.point_y,T1.shape,T1.remark,T1.dst_page_type,T1.dst_page_num 
						FROM $ledConfTable AS T1,$ledStatTable AS T2  
						WHERE (
						if(T1.sync_from_led < 0 && T2.key_led_num < $divideNumber,floor(T1.key_led_num/16) = T2.key_led_num,T1.key_led_num = T2.key_led_num) 
						OR 
						if(T1.sync_from_led >= 0 && T2.key_led_num < $divideNumber,floor(T1.sync_from_led/16) = T2.key_led_num,T1.sync_from_led = T2.key_led_num) 
						)
						AND T1.key_src_page_type ='$showingPageType' 
						AND T1.key_src_page_num = '$pageIndex' 
						AND T2.key_status != '15151515151515151515151515151515'
						AND (T1.key_led_num <='20576'	OR T1.key_led_num >='20589')
						";
if($DEBUG)
	echo "<br>selSql=$selSql";
$selResult=mysqli_query($pubConn,$selSql);
echo mysqli_error($pubConn);
$selRows=mysqli_fetch_array($selResult);
do{

	//echo "<br>selRows[key_status]";
	$tmpStatus=getLedStatus($selRows['key_status'],$selRows['key_led_num']);
	switch($tmpStatus){
	case $nLedOk:
		$tmpImage="./images/".$shapeArr[$selRows['shape']]."_green";
		break;
	case $nLedWarn:
		$tmpImage="./images/".$shapeArr[$selRows['shape']]."_yellow";
		break;
	case $nLedError:
		$tmpImage="./images/".$shapeArr[$selRows['shape']]."_red";
		break;
	case $nLedNoUsed:
		$tmpImage="./images/".$shapeArr[$selRows['shape']]."_gray";
		break;
	default :
		$continueFlag=1;
		//$tmpImage="./images/".$shapeArr[$shape[$j]]."_gray";
		break;
	}

	if($continueFlag==1){
		$continueFlag=0;
		continue;
	}
	
	$tmpImage = $tmpImage.$suffixArr[0];
		
	echo "$tmpImage";
	echo "@@@";
}while($selRows=mysqli_fetch_array($selResult));
?>

	


