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 :  /home/pathumthani_integration/integration/inc/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //home/pathumthani_integration/integration/inc/function.php
<?
	# FUNCTION ##############################################
	/* ฟังก์ชั่นการตรวจสอบสิทธิ์การ เพิ่ม ลบ แก้ไข Modified By : Aussy [2552-10-10 15:12] */
	function cmdObj ( $app_id, $cmd_type, $url="#", $target="_self", $obj_text="", $attrib="", $alt="" ) {
		if ( $_SESSION['SS_PERMISSION'] && $app_id && $cmd_type ) {
			if ( $cmd_type == "VIEW" ) $ico = ""; elseif ( $cmd_type == "ADD" ) $ico = "b_add"; elseif ( $cmd_type == "EDIT" ) $ico = "b_edit"; elseif ( $cmd_type == "DELETE" ) $ico = "b_drop";
			
			if ( $_SESSION['SS_PERMISSION'][$app_id][$cmd_type] == "Y" ) {
				echo "<a href=\"".$url."\" target=\"".$target."\">";
				#if ( $obj_text ) echo "<label alt=\"".$alt."\" ".$attrib." onMouseOver=\"this.style.cursor='hand';\">".$obj_text."</label>";
				if ( $obj_text ) echo $obj_text;
				else echo "<img src=\"../../images/obj_icon/".$ico.".png\" width=\"16\" height=\"16\" border=\"0\" align=\"absmiddle\" alt=\"".$alt."\" ".$attrib.">";
				echo "</a>";
			} elseif ( $_SESSION['SS_PERMISSION'][$app_id][$cmd_type] == "N" ) {
				#if ( $obj_text ) echo "<label alt=\"".$alt."\" ".$attrib." onMouseOver=\"this.style.cursor='hand';\">".$obj_text."</label>";
				if ( $obj_text ) echo $obj_text;
				else echo "<img src=\"../../images/obj_icon/".$ico."_disabled.png\" width=\"16\" height=\"16\" border=\"0\" align=\"absmiddle\" alt=\"".$alt."\">";
			}
		}
	}
	################################################
	# ฟังก์ชั่นกำหนดสิทธิ แบบ Tag คำสั่ง By:Jeng [2009-10-13 10:41]
	# $app_id : รหัส application
	# $cmd_type : ประเภทการเข้าถึง VIEW, ADD, EDIT, DELETE
	# $tagYes : แท็กที่ต้องการแสดง เมื่อถูกเงื่อนไข
	# $tagNo : แท็กที่ต้องการแสดง เมื่อไม่ถูกเงื่อนไข
	################################################
	function cmdObj_tag( $app_id="", $cmd_type="", $tagYes="", $tagNo=""){
		if( !empty($app_id) && !empty($_SESSION['SS_PERMISSION'][$app_id][$cmd_type]) ){
			if($_SESSION['SS_PERMISSION'][$app_id][$cmd_type] == "Y"){
				echo $tagYes;
			}else 
			if($_SESSION['SS_PERMISSION'][$app_id][$cmd_type] == "N"){
				echo $tagNo;
			}
		}else{
			echo $tagNo;
		}
	}
	##############################################
	# ฟัังก์ชั่งแสดงข้อมูล ๊ Usernamemanager VIEW
	# $app_id : รหัส application
	# $itstaffid : รหัสผู้ใช้งาน
	#  ประเภทการเข้าถึง ALL, SELF, GROUP
	##############################################
	
	function getUserViewID($app_id = ""){
		$itstaffid = array();
		if( !empty($app_id) && !empty($_SESSION['SS_PERMISSION'][$app_id]['VIEW']) && $_SESSION['SS_PERMISSION'][$app_id]['VIEW'] == "Y" ){
			if( !empty($app_id) && !empty($_SESSION['SS_PERMISSION'][$app_id]['SUB_VIEW']) ){
				if($_SESSION['SS_PERMISSION'][$app_id]['SUB_VIEW'] == "SELF"){
					$itstaffid[] = $_SESSION["session_staffid"]; 
				}else
				if($_SESSION['SS_PERMISSION'][$app_id]['SUB_VIEW'] == "GROUP"){
					$sql = "SELECT epm_staffgroup.org_id FROM epm_staffgroup Inner Join epm_groupmember ON epm_staffgroup.gid = epm_groupmember.gid 
								WHERE epm_groupmember.staffid ='".$_SESSION["session_staffid"]."' ";
					$RESULT = mysql_query($sql);	
					$rowG = mysql_fetch_assoc($RESULT);
					$arrGID = implode("','",$rowG);	
					$sql_staffid = "SELECT epm_groupmember.staffid FROM epm_staffgroup Inner Join epm_groupmember ON epm_staffgroup.gid = epm_groupmember.gid 
								WHERE epm_staffgroup.org_id IN('".$arrGID."') ";
					$RESULT_staffid = mysql_query($sql_staffid);	
					while($rowS = mysql_fetch_assoc($RESULT_staffid)){
						$itstaffid[] = $rowS["staffid"]; 
					}
				}else 
				if($_SESSION['SS_PERMISSION'][$app_id]['SUB_VIEW'] == "ALL"){
					$itstaffid[] = "";
				}else{
					$itstaffid[] = "NO_STAFFID";
				}
			}
			
		}else{
			$itstaffid[] = "NO_APPID";
		}
		return $itstaffid;
	}
	
	
	
	
	function redirect_url($url){
		echo "<script language=\"JavaScript\">\n";
		echo "window.location='".$url."';\n";
		echo "</script>\n";
	}
	
	function swap_date($date){
		if ( $date && $date != "0000-00-00" ) {
			list($d, $m, $y) = split("-", $date);
			return sprintf("%s-%s-%s", $y, $m, $d);
		}
	}
	
	/* ฟังก์ชั่นการคำนวณอายุ Modified By : Aussy [2552-10-10 15:12] */
	function birthday($birthday) {
		if ( $birthday ) {
			list($year,$month,$day) = explode("-",$birthday);
			$year_diff = date("Y") - $year;
			$month_diff = date("m") - $month;
			$day_diff = date("d") - $day;
			if ($month_diff < 0) $year_diff--;
			elseif (($month_diff==0) && ($day_diff < 0)) $year_diff--;
			
			return $year_diff;
		}
	}
	
	/* ฟังก์ชั่นการคำนวณอายุ (เฉพาะปีเท่านั้น) Modified By : Aussy [2553-08-24 23:38] */
	function birthday_year($birthday) {
		if ( $birthday && $birthday != "0000-00-00" ) {
			list($year,$month,$day) = explode("-",$birthday);
			$year_diff = date("Y") - $year;
			$month_diff = date("m") - $month;
			$day_diff = date("d") - $day;
			
			if ($month_diff < 0) $year_diff--;
			elseif (($month_diff==0) && ($day_diff < 0)) $year_diff--;
			
			if ($month_diff < 0) $month_diff = (12+ (date("m") - $month));
			else $month_diff = date("m") - $month;
			
			return $year_diff;
		}
	}
	
	function getPageNum($row, $row_per_page) {
		$page = ceil($row / $row_per_page);
		//$page += (is_int($page))?1:0;
		return ($page<=0)?1:$page;
	}
	
	function getDMY( $xDate, $xType="D" ) {
		$arrThaiMonth = array('','มกราคม','กุมภาพันธ์','มีนาคม','เมษายน','พฤษภาคม','มิถุนายน','กรกฏาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม');
		
		if ( $xDate && $xDate != "0000-00-00" ) {
			if ( $xType == "D" ) return substr($xDate, 8, 2);
			if ( $xType == "M" ) return $arrThaiMonth[intval(substr($xDate,5,2))];
			if ( $xType == "Y" ) return substr($xDate, 0, 4)+543;
		}
	}
	
	function shwArray( $strData ) {
		if ( is_array($strData) ) {
			echo "<pre>";
			print_r($strData);
			echo "</pre>";
		} else {
			echo $strData;
		}
	}
	
	function CharLimit( $strData, $intLimit = 0 ) {
		if ( $strData ) {
			$strResult = substr($strData, 0, $intLimit);
			if ( strlen($strData) > $intLimit ) $strResult = $strResult . "...";
			return $strResult;
		}
	}
	
	function STRING_RANDOM($len){
		$code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
		srand((double)microtime() *1000000);
		for($i=0 ; $i < $len ; $i++) {
			$strRandom .= $code[rand()%strlen($code)];
		}
		return $strRandom;
	}
	
	
	
	
	function EnCrypt($strNormal){
		empty($strEncrypted);
		for($intA = 0;$intA < strlen($strNormal);$intA++){
			if(substr($strNormal, $intA, 1) == "A"){
				$strEncrypted = $strEncrypted . "9";
			}elseif(substr($strNormal, $intA, 1) == "B"){
				$strEncrypted = $strEncrypted . "8";
			}elseif(substr($strNormal, $intA, 1) == "C"){
				$strEncrypted = $strEncrypted . "7";
			}elseif(substr($strNormal, $intA, 1) == "D"){
				$strEncrypted = $strEncrypted . "6";
			}elseif(substr($strNormal, $intA, 1) == "E"){
				$strEncrypted = $strEncrypted . "5";
			}elseif(substr($strNormal, $intA, 1) == "F"){
				$strEncrypted = $strEncrypted . "4";
			}elseif(substr($strNormal, $intA, 1) == "G"){
				$strEncrypted = $strEncrypted . "3";
			}elseif(substr($strNormal, $intA, 1) == "H"){
				$strEncrypted = $strEncrypted . "2";
			}elseif(substr($strNormal, $intA, 1) == "I"){
				$strEncrypted = $strEncrypted . "1";
			}elseif(substr($strNormal, $intA, 1) == "J"){
				$strEncrypted = $strEncrypted . "0";
			}elseif(substr($strNormal, $intA, 1) == "K"){
				$strEncrypted = $strEncrypted . "z";
			}elseif(substr($strNormal, $intA, 1) == "L"){
				$strEncrypted = $strEncrypted . "y";
			}elseif(substr($strNormal, $intA, 1) == "M"){
				$strEncrypted = $strEncrypted . "x";
			}elseif(substr($strNormal, $intA, 1) == "N"){
				$strEncrypted = $strEncrypted . "w";
			}elseif(substr($strNormal, $intA, 1) == "O"){
				$strEncrypted = $strEncrypted . "v";
			}elseif(substr($strNormal, $intA, 1) == "P"){
				$strEncrypted = $strEncrypted . "u";
			}elseif(substr($strNormal, $intA, 1) == "Q"){
				$strEncrypted = $strEncrypted . "t";
			}elseif(substr($strNormal, $intA, 1) == "R"){
				$strEncrypted = $strEncrypted . "s";
			}elseif(substr($strNormal, $intA, 1) == "S"){
				$strEncrypted = $strEncrypted . "r";
			}elseif(substr($strNormal, $intA, 1) == "T"){
				$strEncrypted = $strEncrypted . "q";
			}elseif(substr($strNormal, $intA, 1) == "U"){
				$strEncrypted = $strEncrypted . "p";
			}elseif(substr($strNormal, $intA, 1) == "V"){
				$strEncrypted = $strEncrypted . "o";
			}elseif(substr($strNormal, $intA, 1) == "W"){
				$strEncrypted = $strEncrypted . "n";
			}elseif(substr($strNormal, $intA, 1) == "X"){
				$strEncrypted = $strEncrypted . "m";
			}elseif(substr($strNormal, $intA, 1) == "Y"){
				$strEncrypted = $strEncrypted . "l";
			}elseif(substr($strNormal, $intA, 1) == "Z"){
				$strEncrypted = $strEncrypted . "k";
			}elseif(substr($strNormal, $intA, 1) == "a"){
				$strEncrypted = $strEncrypted . "j";
			}elseif(substr($strNormal, $intA, 1) == "b"){
				$strEncrypted = $strEncrypted . "i";
			}elseif(substr($strNormal, $intA, 1) == "c"){
				$strEncrypted = $strEncrypted . "h";
			}elseif(substr($strNormal, $intA, 1) == "d"){
				$strEncrypted = $strEncrypted . "g";
			}elseif(substr($strNormal, $intA, 1) == "e"){
				$strEncrypted = $strEncrypted . "f";
			}elseif(substr($strNormal, $intA, 1) == "f"){
				$strEncrypted = $strEncrypted . "e";
			}elseif(substr($strNormal, $intA, 1) == "g"){
				$strEncrypted = $strEncrypted . "d";
			}elseif(substr($strNormal, $intA, 1) == "h"){
				$strEncrypted = $strEncrypted . "c";
			}elseif(substr($strNormal, $intA, 1) == "i"){
				$strEncrypted = $strEncrypted . "b";
			}elseif(substr($strNormal, $intA, 1) == "j"){
				$strEncrypted = $strEncrypted . "a";
			}elseif(substr($strNormal, $intA, 1) == "k"){
				$strEncrypted = $strEncrypted . "Z";
			}elseif(substr($strNormal, $intA, 1) == "l"){
				$strEncrypted = $strEncrypted . "Y";
			}elseif(substr($strNormal, $intA, 1) == "m"){
				$strEncrypted = $strEncrypted . "X";
			}elseif(substr($strNormal, $intA, 1) == "n"){
				$strEncrypted = $strEncrypted . "W";
			}elseif(substr($strNormal, $intA, 1) == "o"){
				$strEncrypted = $strEncrypted . "V";
			}elseif(substr($strNormal, $intA, 1) == "p"){
				$strEncrypted = $strEncrypted . "U";
			}elseif(substr($strNormal, $intA, 1) == "q"){
				$strEncrypted = $strEncrypted . "T";
			}elseif(substr($strNormal, $intA, 1) == "r"){
				$strEncrypted = $strEncrypted . "S";
			}elseif(substr($strNormal, $intA, 1) == "s"){
				$strEncrypted = $strEncrypted . "R";
			}elseif(substr($strNormal, $intA, 1) == "t"){
				$strEncrypted = $strEncrypted . "Q";
			}elseif(substr($strNormal, $intA, 1) == "u"){
				$strEncrypted = $strEncrypted . "P";
			}elseif(substr($strNormal, $intA, 1) == "v"){
				$strEncrypted = $strEncrypted . "O";
			}elseif(substr($strNormal, $intA, 1) == "w"){
				$strEncrypted = $strEncrypted . "N";
			}elseif(substr($strNormal, $intA, 1) == "x"){
				$strEncrypted = $strEncrypted . "M";
			}elseif(substr($strNormal, $intA, 1) == "y"){
				$strEncrypted = $strEncrypted . "L";
			}elseif(substr($strNormal, $intA, 1) == "z"){
				$strEncrypted = $strEncrypted . "K";
			}elseif(substr($strNormal, $intA, 1) == "0"){
				$strEncrypted = $strEncrypted . "J";
			}elseif(substr($strNormal, $intA, 1) == "1"){
				$strEncrypted = $strEncrypted . "I";
			}elseif(substr($strNormal, $intA, 1) == "2"){
				$strEncrypted = $strEncrypted . "H";
			}elseif(substr($strNormal, $intA, 1) == "3"){
				$strEncrypted = $strEncrypted . "G";
			}elseif(substr($strNormal, $intA, 1) == "4"){
				$strEncrypted = $strEncrypted . "F";
			}elseif(substr($strNormal, $intA, 1) == "5"){
				$strEncrypted = $strEncrypted . "E";
			}elseif(substr($strNormal, $intA, 1) == "6"){
				$strEncrypted = $strEncrypted . "D";
			}elseif(substr($strNormal, $intA, 1) == "7"){
				$strEncrypted = $strEncrypted . "C";
			}elseif(substr($strNormal, $intA, 1) == "8"){
				$strEncrypted = $strEncrypted . "B";
			}elseif(substr($strNormal, $intA, 1) == "9"){
				$strEncrypted = $strEncrypted . "A";
			}elseif(substr($strNormal, $intA, 1) == "~"){
				$strEncrypted = $strEncrypted . " ";
			}elseif(substr($strNormal, $intA, 1) == "!"){
				$strEncrypted = $strEncrypted . "/";
			}elseif(substr($strNormal, $intA, 1) == "@"){
				$strEncrypted = $strEncrypted . "?";
			}elseif(substr($strNormal, $intA, 1) == "#"){
				$strEncrypted = $strEncrypted . ".";
			}elseif(substr($strNormal, $intA, 1) == "$"){
				$strEncrypted = $strEncrypted . ">";
			}elseif(substr($strNormal, $intA, 1) == "%"){
				$strEncrypted = $strEncrypted . ",";
			}elseif(substr($strNormal, $intA, 1) == "^"){
				$strEncrypted = $strEncrypted . "<";
			}elseif(substr($strNormal, $intA, 1) == "&"){
				$strEncrypted = $strEncrypted . "'";
			}elseif(substr($strNormal, $intA, 1) == "*"){
				$strEncrypted = $strEncrypted . "\"";
			}elseif(substr($strNormal, $intA, 1) == "("){
				$strEncrypted = $strEncrypted . ";";
			}elseif(substr($strNormal, $intA, 1) == ")"){
				$strEncrypted = $strEncrypted . ":";
			}elseif(substr($strNormal, $intA, 1) == "_"){
				$strEncrypted = $strEncrypted . "\\";
			}elseif(substr($strNormal, $intA, 1) == "-"){
				$strEncrypted = $strEncrypted . "|";
			}elseif(substr($strNormal, $intA, 1) == "+"){
				$strEncrypted = $strEncrypted . "]";
			}elseif(substr($strNormal, $intA, 1) == "="){
				$strEncrypted = $strEncrypted . "}";
			}elseif(substr($strNormal, $intA, 1) == "{"){
				$strEncrypted = $strEncrypted . "[";
			}elseif(substr($strNormal, $intA, 1) == "["){
				$strEncrypted = $strEncrypted . "{";
			}elseif(substr($strNormal, $intA, 1) == "}"){
				$strEncrypted = $strEncrypted . "=";
			}elseif(substr($strNormal, $intA, 1) == "]"){
				$strEncrypted = $strEncrypted . "+";
			}elseif(substr($strNormal, $intA, 1) == "|"){
				$strEncrypted = $strEncrypted . "-";
			}elseif(substr($strNormal, $intA, 1) == "\\"){
				$strEncrypted = $strEncrypted . "_";
			}elseif(substr($strNormal, $intA, 1) == ":"){
				$strEncrypted = $strEncrypted . ")";
			}elseif(substr($strNormal, $intA, 1) == ";"){
				$strEncrypted = $strEncrypted . "(";
			}elseif(substr($strNormal, $intA, 1) == "\""){
				$strEncrypted = $strEncrypted . "*";
			}elseif(substr($strNormal, $intA, 1) == "'"){
				$strEncrypted = $strEncrypted . "&";
			}elseif(substr($strNormal, $intA, 1) == "<"){
				$strEncrypted = $strEncrypted . "^";
			}elseif(substr($strNormal, $intA, 1) == ","){
				$strEncrypted = $strEncrypted . "%";
			}elseif(substr($strNormal, $intA, 1) == ">"){
				$strEncrypted = $strEncrypted . "$";
			}elseif(substr($strNormal, $intA, 1) == "."){
				$strEncrypted = $strEncrypted . "#";
			}elseif(substr($strNormal, $intA, 1) == "?"){
				$strEncrypted = $strEncrypted . "@";
			}elseif(substr($strNormal, $intA, 1) == "/"){
				$strEncrypted = $strEncrypted . "!";
			}elseif(substr($strNormal, $intA, 1) == " "){
				$strEncrypted = $strEncrypted . "~";
			}
		}
		$ENCODE_BIT = 64;  //64 bit
		$strRandVal = STRING_RANDOM($ENCODE_BIT);
		$strEncrypted = str_replace(substr($strRandVal, 4, strlen($strNormal)), $strEncrypted, $strRandVal);
		$strEncrypted = str_replace(substr($strEncrypted, $ENCODE_BIT - 3, 2), getNO(strlen($strNormal), 2, 0), $strEncrypted);
		return($strEncrypted);
	}

	function getNO($NO, $GetCharTotal, $Increasement){
		$NO = ($NO * 1) + $Increasement;
		$NO = "000000000".$NO;
		$NO = substr($NO,strlen($NO) - $GetCharTotal,$GetCharTotal);
		return($NO);
	}
	
	function getPersonalID($strPersonalID) {
		if ( $strPersonalID && strlen($strPersonalID)==13 ) {
			$PID = substr($strPersonalID,0,1);
			$PID .= "-" . substr($strPersonalID,1,4);
			$PID .= "-" . substr($strPersonalID,5,5);
			$PID .= "-" . substr($strPersonalID,10,2);
			$PID .= "-" . substr($strPersonalID,12,1);
			return $PID;
		}else{
			return $strPersonalID;
		}
	}
	
	function get_date($birthdate){
		$date_edit=explode('-',$birthdate);
		$date_edit[0]+=543;
		$change_date=implode("-",array_reverse($date_edit));
		return $change_date;
	}
	
	function SmallThaiDate( $vDate ) {
		# Set $vDate Format to "d-m-Y" First...
		$Month = array("", "ม.ค.", "ก.พ.", "มี.ค.", "เม.ย.", "พ.ค.", "มิ.ย.", "ก.ค.", "ส.ค.", "ก.ย.", "ต.ค.", "พ.ย.", "ธ.ค.");
		if ( $vDate ) {
			$arrDate = explode("-", $vDate);
			$arrDate[0] = ( $arrDate[0] == "00" ) ? "-" : intval($arrDate[0]);
			$arrDate[1] = ( $arrDate[1] == "00" ) ? "-" : $Month[intval($arrDate[1])];
			$strDate = $arrDate[0]." ".$arrDate[1]." ".($arrDate[2] + 543);
			return $strDate;
		}
	}
	
	function date2THA($x){
		$exdateexplode=explode("-",$x);
		if($exdateexplode[0]<=2300){ $exdateexplode[0]=$exdateexplode[0]+543;}
		if($exdateexplode[0]>2900){ $exdateexplode[0]=$exdateexplode[0]-543;}			
		$x=$exdateexplode[0]."-".$exdateexplode[1]."-".$exdateexplode[2];	
		return $x;
	}

	function date2ENG($x){
		$exdateexplode=explode("-",$x);
		if($exdateexplode[0]<=1900){ $exdateexplode[0]=$exdateexplode[0]+543;}
		if($exdateexplode[0]>2300){ $exdateexplode[0]=$exdateexplode[0]-543;}			
		$x=$exdateexplode[0]."-".$exdateexplode[1]."-".$exdateexplode[2];	
		return $x;
	}
	
	/* จำแนกกลุ่มอายุ */
	function ageGrp($intAge) {
		if ( $intAge < 19 ) $Grp = "A";
		elseif ( $intAge < 60 ) $Grp =  "B";
		elseif ( $intAge < 120 ) $Grp = "C";
		return $Grp;
	}
	
	function GetCellProperty($id,$sec1,$cellno){
			$result = mysql_query("select * from cellinfo where node_id='$id' and sec='$sec1' and cellno='$cellno';");
			if ($result){
				$rs=mysql_fetch_array($result,MYSQL_ASSOC);
				$prop = "";
				if ($rs[alignment]){
					$prop .= " align='$rs[alignment]' ";
				}
	
				if ($rs[valign]){
					$prop .= " valign='$rs[valign]' ";
				}
	
				if ($rs[bgcolor]){
					$prop .= " bgcolor='$rs[bgcolor]' ";
				}
	
				if ($rs[width]){
					$prop .= " width='$rs[width]' ";
				}
	
				return $prop;
	
			}else{
				return "";
			}
	}
	
	function GetCellValue($id,$sec1,$cellno){
			$result = mysql_query("select * from cellinfo where node_id='$id' and sec='$sec1' and cellno='$cellno';");
			if ($result){
				$rs=mysql_fetch_array($result,MYSQL_ASSOC);
				$val1 = $rs[caption];
	
				if ($rs[celltype] == 1){
					$val1 .= " [obj] ";
				}else if ($rs[celltype] == 2){
					$val1 .= " [fld] ";
				}else if ($rs[celltype] == 3){
					$val1 .= " [fn] ";
				}else if ($rs[celltype] == 4){
					$val1 .= " [cal] ";
				}
	
				if ($rs[font]){
					$val1 = "<span style='$rs[font]'>$val1</span>";
				}
	
				if ($rs[url]){
					$val1 = "<a href='$rs[url]' target='_blank'>$val1</a>";
				}
				
				return $val1;
	
			}else{
				return "&nbsp;";
			}
	}
	
	function DB2Array($arrayname,$sql){
		$s = "\$$arrayname  = array(";
		$result = mysql_query($sql);
		$i = 0;
		$firstrow = true;
		while ($rs = mysql_fetch_assoc($result)){
			if ($firstrow){
				$firstrow = false;
			}else{
				$s .= ",";
			}
	
			$firstcol = true;
			$s .= "$i => array(";
			foreach($rs as $key => $value){
				if ($firstcol){
					$firstcol = false;
				}else{
					$s .= ", ";
				}
				$s .= "\"$key\"=>\"" . $value . "\"";
			}
			$s .= ")";
	
			$i++;
		}
	
		$s .= ");";
	
		return $s;
	}
		
	function canSetWidth(){ // ตรวจสอบว่า ฐานข้อมูลรองรับการแก้ไข Column Width หรือไม่
		$result = @mysql_query("SELECT cwidth1,cwidth2,cwidth3,cwidth4 FROM eq_kpi_tree_member LIMIT 1");
		if ($result && mysql_errno() == 0){
			return true; // can set width
		}else{
			return false; //cannot set width
		}
	}
	
	function GetColumnWidth($rid,$sec,$cellno){
		$x = explode(".",$cellno);
		$col = $x[1];
	
		// H,E,I,F
		if ($sec == "H"){
			$sql = "select cwidth1 from eq_kpi_tree_member where node_id='$rid';";
		}else if ($sec == "E"){
			$sql = "select cwidth2 from eq_kpi_tree_member where node_id='$rid';";
		}else if ($sec == "I"){
			$sql = "select cwidth3 from eq_kpi_tree_member where node_id='$rid';";
		}else {
			$sql = "select cwidth4 from eq_kpi_tree_member where node_id='$rid';";
		}
	
		$cwidth = "";
	
		$result = @mysql_query($sql);
		if ($result){
			$rs = mysql_fetch_array($result);
			$x=explode("|",$rs[0]); //แต่ละ column คั่นด้วย |
			$cwidth = $x[$col - 1]; // เอาเฉพาะตัวที่กำหนดจากค่าตัวหลังของ cellno
		}
	
		return htmlspecialchars($cwidth);
	}
	
	function SetColumnWidth($rid,$sec,$cellno,$cwidth){
	global $uname;
		$x = explode(".",$cellno);
		$col = $x[1];
		
		$cwidth = str_replace("|","",$cwidth);  //กำจัดเครื่องหมาย | (ถ้ามี)
		
		// H,E,I,F
		if ($sec == "H"){
			$sql = "select cwidth1 from eq_kpi_tree_member where node_id='$rid';";
		}else if ($sec == "E"){
			$sql = "select cwidth2 from eq_kpi_tree_member where node_id='$rid';";
		}else if ($sec == "I"){
			$sql = "select cwidth3 from eq_kpi_tree_member where node_id='$rid';";
		}else {
			$sql = "select cwidth4 from eq_kpi_tree_member where node_id='$rid';";
		}
	
		$result = @mysql_query($sql);
		if ($result){
			$rs = mysql_fetch_array($result);
			$x=explode("|",$rs[0]); //แต่ละ column คั่นด้วย |
	
			//สำหรับอันที่ไม่เคยได้ทำถึงอันนี้
			for ($i=0;$i<$col-1;$i++){
				if (!isset($x[$i])){
					$x[$i] = "";
				}
			}
	
			$x[$col - 1] = $cwidth;  
			$columnwidth = implode("|",$x); //จับมารวมกัน
		}else{ // ยังไม่มีการกำหนดค่า
			$columnwidth = "";
			for ($i=0;$i<$col-1;$i++){
				$columnwidth .= "|";
			}
			$columnwidth .= "$cwidth|";
		}
	
		
		// H,E,I,F
		if ($sec == "H"){
			$sql = "update eq_kpi_tree_member set cwidth1='$columnwidth' where node_id='$rid';";
		}else if ($sec == "E"){
			$sql = "update eq_kpi_tree_member set cwidth2='$columnwidth' where node_id='$rid';";
		}else if ($sec == "I"){
			$sql = "update eq_kpi_tree_member set cwidth3='$columnwidth' where node_id='$rid';";
		}else {
			$sql = "update eq_kpi_tree_member set cwidth4='$columnwidth' where node_id='$rid';";
		}
	
		@mysql_query($sql);
	
	}
	
	/* ฟังก์ชั่นคำนวณร้อยละ Modified By : Aussy [2552-10-02 19:04] */
	function percentage ( $arrVal, $intDec=2, $intPercent=100 ) {
		if ( $arrVal && is_array($arrVal) ) {
			#shwArray($arrVal);

			$SumOfVal = array_sum($arrVal); #echo "Total of Value is : ".$SumOfVal."<br>";
			
			foreach ( $arrVal as $Key => $Val ) {
				$arrVal[$Key] = number_format((($Val * $intPercent) / $SumOfVal), $intDec + 1); // จำนวนร้อยละ ทศนิยม +1

				// ชุดตัวแปร Array ร้อยละ จำนวนหลักทศนิยม
				if ( substr($arrVal[$Key], -1, 1) < 5 ) { # A2
					$arrA2Ori[$Key] = $arrVal[$Key];
					$arrA2[$Key] = number_format($arrVal[$Key], $intDec);
					$Ref = explode(".", $arrA2[$Key]);
					$arrA2LastChar[$Key] = substr($arrA2Ori[$Key], -1, 1);
				} else { # A1
					$arrA1Ori[$Key] = $arrVal[$Key];
					$arrA1[$Key] = number_format($arrVal[$Key], $intDec);
					$Ref = explode(".", $arrA1[$Key]);
					$arrA1LastChar[$Key] = substr($arrA1Ori[$Key], -1, 1);
				}
				
				$arrVInt[$Key] = $Ref[0]; // ชุดตัวแปรจำนวนเต็ม (ตัดทศนิยมทิ้ง)
				$arrVDec[$Key] = $Ref[1]; // ชุดตัวแปรจำนวนทศนิยม
			}
			
			#shwArray($arrVal);
			
			$x0 = array_sum($arrVInt);			#echo "x0 = ".$x0."<br>";
			$x1 = $intPercent - $x0;				#echo "x1 = ".$x1."<br>";
			$x2 = ($x1 * pow(10, $intDec));	#echo "x2 = ".$x2."<br>";
			$x3 = array_sum($arrVDec);			#echo "x3 = ".$x3."<br>";
			$x4 = $x3 - $x2;							#echo "x4 = ".$x4."<br>";
			
			#shwArray($arrA1Ori);
			#shwArray($arrA2Ori);
			
			arsort($arrA1LastChar);
			arsort($arrA2LastChar);
			#shwArray($arrA1LastChar);
			#shwArray($arrA2LastChar);
			
			#shwArray($arrA1);
			#shwArray($arrA2);
			
			if ( $x4 == 0 ) {
				foreach ( $arrA1 as $Key => $Val ) $arrResult[$Key] = $arrA1[$Key];
				foreach ( $arrA2 as $Key => $Val ) $arrResult[$Key] = $arrA2[$Key];
			} elseif ( $x4 > 0 ) {
				$intA = 1;
				foreach ( $arrA1LastChar as $Key => $Val ) {
					if ( $intA <= (count($arrA1Ori) - $x4) ) $arrResult[$Key] = $arrA1[$Key]; else $arrResult[$Key] = substr($arrA1Ori[$Key], 0, strlen($arrA1Ori[$Key]) - 1);
					$intA++;
				}
				
				foreach ( $arrA2 as $Key => $Val ) $arrResult[$Key] = $arrA2[$Key];
			} elseif ( $x4 < 0 ) {
				$intA = 1;
				foreach ( $arrA2LastChar as $Key => $Val ) {
					if ( $intA <= abs($x4) ) $arrResult[$Key] = $arrA2[$Key] + 1/(pow(10, $intDec)); else $arrResult[$Key] = $arrA2[$Key];
					$intA++;
				}
				
				foreach ( $arrA1 as $Key => $Val ) $arrResult[$Key] = $arrA1[$Key];
			}
			
			#shwArray($arrResult);
			#echo "Total of Percent is : ".number_format(array_sum($arrResult), 2)."<br>";
			
			return $arrResult;
		}
	}
	
	/* ฟังก์ชั่นคำนวณร้อยละ Modified By : Aussy [2552-10-05 10:00] */
	function percentage_2d ( $arrVal, $intDec=2, $intPercent=100 ) {
		if ( $arrVal && is_array($arrVal) ) {
#			echo "arrVal ______________ "; shwArray($arrVal);
			$SumOfVal = multimension_array_sum($arrVal); #echo "Total of Value is : ".$SumOfVal."<br>";
			
			$Key = 0;
			foreach ( $arrVal as $i => $arrValX ) { # แกน X
				foreach ( $arrValX as $j => $arrValY ) { # แกน Y
#					$SumOfX[$j] += $arrValY;
#					$SumOfY[$i] += $arrValY;
					
					if ( $SumOfVal > 0 ) $arrPer[$i][$j] = number_format((($arrValY * $intPercent) / $SumOfVal), $intDec + 1); // จำนวนร้อยละ ทศนิยม+1
#					$SumOfarrX[$j] += number_format((($arrValY * $intPercent) / $SumOfVal), $intDec + 1); // จำนวนร้อยละ ในแกน X ทศนิยม+1
#					$SumOfarrY[$i] += number_format((($arrValY * $intPercent) / $SumOfVal), $intDec + 1); // จำนวนร้อยละ ในแกน Y ทศนิยม+1
					
					// ชุดตัวแปร Array ร้อยละ จำนวนหลักทศนิยม
					
					if ( substr($arrPer[$i][$j], -1, 1) < 5 ) { # A2
						$arrA2Ori[$Key] = $arrPer[$i][$j];
						$arrA2[$Key] = number_format($arrPer[$i][$j], $intDec);
						$Ref = explode(".", $arrA2[$Key]);
						$arrA2LastChar[$Key] = substr($arrA2Ori[$Key], -1, 1);
					} else { # A1
						$arrA1Ori[$Key] = $arrPer[$i][$j];
						$arrA1[$Key] = number_format($arrPer[$i][$j], $intDec);
						$Ref = explode(".", $arrA1[$Key]);
						$arrA1LastChar[$Key] = substr($arrA1Ori[$Key], -1, 1);
					}
					
					$arrVInt[$Key] = $Ref[0]; // ชุดตัวแปรจำนวนเต็ม (ตัดทศนิยมทิ้ง)
					$arrVDec[$Key] = $Ref[1]; // ชุดตัวแปรจำนวนทศนิยม
					
					$arrKey[$Key] = $i."#".$j;
					$Key++;
				}
			}
			
#			shwArray($arrKey);
			
#			echo "SumOfX ______________ "; shwArray($SumOfX);
#			echo "SumOfY ______________ "; shwArray($SumOfY);
			
#			echo "arrPer ______________ "; shwArray($arrPer);
#			echo multimension_array_sum($arrPer);
			$SumOfArrPer = multimension_array_sum($arrPer); #echo "Total of Value is : ".$SumOfArrPer."<br>";
			
			$x0 = array_sum($arrVInt);			#echo "x0 = ".$x0."<br>";
			$x1 = $intPercent - $x0;				#echo "x1 = ".$x1."<br>";
			$x2 = ($x1 * pow(10, $intDec));	#echo "x2 = ".$x2."<br>";
			$x3 = array_sum($arrVDec);			#echo "x3 = ".$x3."<br>";
			$x4 = $x3 - $x2;							#echo "x4 = ".$x4."<br>";
			
#			echo "arrA1Ori ______________ "; shwArray($arrA1Ori);
#			echo "arrA2Ori ______________ "; shwArray($arrA2Ori);
			
			@arsort($arrA1LastChar);
			@arsort($arrA2LastChar);
#			shwArray($arrA1LastChar);
#			shwArray($arrA2LastChar);
			
#			shwArray($arrA1);
#			shwArray($arrA2);
			
#			echo "SumOfarrX ______________ "; shwArray($SumOfarrX);
#			echo "SumOfarrY ______________ "; shwArray($SumOfarrY);

			if ( $x4 == 0 ) {
				if ( is_array($arrA1) ) {
					foreach ( $arrA1 as $Key => $Val ) {
						$Index = explode("#", $arrKey[$Key]);
						$arrResult[$Index[0]][$Index[1]] = $arrA1[$Key];
					}
				}
				
				foreach ( $arrA2 as $Key => $Val ) {
					$Index = explode("#", $arrKey[$Key]);
					$arrResult[$Index[0]][$Index[1]] = $arrA2[$Key];
				}
			} elseif ( $x4 > 0 ) {
				$intA = 1;
				foreach ( $arrA1LastChar as $Key => $Val ) {
					$Index = explode("#", $arrKey[$Key]);
					if ( $intA <= (count($arrA1Ori) - $x4) ) $arrResult[$Index[0]][$Index[1]] = $arrA1[$Key];
					else $arrResult[$Index[0]][$Index[1]] = substr($arrA1Ori[$Key], 0, strlen($arrA1Ori[$Key]) - 1);
					$intA++;
				}
				
				if($arrA2)
				foreach ( $arrA2 as $Key => $Val ) {
					$Index = explode("#", $arrKey[$Key]);
					$arrResult[$Index[0]][$Index[1]] = $arrA2[$Key];
				}
			} elseif ( $x4 < 0 ) {
				$intA = 1;
				foreach ( $arrA2LastChar as $Key => $Val ) {
					$Index = explode("#", $arrKey[$Key]);
					if ( $intA <= abs($x4) ) $arrResult[$Index[0]][$Index[1]] = $arrA2[$Key] + 1/(pow(10, $intDec));
					else $arrResult[$Index[0]][$Index[1]] = $arrA2[$Key];
					$intA++;
				}
				
				if ( is_array($arrA1) ) {
					foreach ( $arrA1 as $Key => $Val ) {
						$Index = explode("#", $arrKey[$Key]);
						$arrResult[$Index[0]][$Index[1]] = $arrA1[$Key];
					}
				}
			}
			
#			shwArray($arrResult);
#			echo "Total of Percent is : ".number_format(multimension_array_sum($arrResult), 2)."<br>";
			
			return $arrResult;
		}
	}
	
	/* ฟังก์ชั่นคำนวณหาผลรวมของ Array หลายมิติ Modified By : Aussy [2552-10-05 10:00] */
	function multimension_array_sum ( $a ) {
		if ( !is_array($a) ) return $a;
		foreach ( $a as $key => $value ) $totale += multimension_array_sum($value);
		return $totale;
	}
		
	/* ฟังก์ชั่นสำหรับตัดช่องว่างทั้งหมดในประโยค Modified By : Aussy [2552-10-15 10:53] */
	function trimall($str, $charlist = " \t\n\r\0\x0B") {
		return str_replace(str_split($charlist), '', $str);
	}
	
	/* ฟังก์ชั่นสำหรับการแสดงผลตัวเลขในรูปแบบเลขบัตรประจำตัวประชาชน Modified By : Aussy [2553-10-17 01:40] */
	function pinFormat ( $strPin ) {
		if ( $strPin && strlen($strPin) == 13 ) {
			return substr($strPin, 0, 1)."-".substr($strPin, 1, 4)."-".substr($strPin, 5, 5)."-".substr($strPin, 10, 2)."-".substr($strPin, 12, 1);
		}
	}
	
	/* ฟังก์ชั่นสำหรับการแสดงผลตัวเลขในรูปแบบเลขบัตรประจำตัวประชาชน X-X-X Modified By : Kidsana[2010-10-26 01:40] */
	function pinFormatX ( $strPin ) {
		if ( $strPin && strlen($strPin) == 13 ) {
			return substr($strPin, 0, 1)."-".substr($strPin, 1, 4)."-".substr($strPin, 5, 5)."-XX-X";
		}
	}
	# END FUNCTION ###########################################
?>

Anon7 - 2021