<?php
class support{	
	function generate_value_digit($MaxDigit,$Value,$DefaultEmptyValue,$Align){
		$Char = "";
		$StrLenValue = strlen($Value);
		if($Align == "left"){			
			for($a=1;$a<=$MaxDigit;$a++){
				if($a<=$StrLenValue) $Char .= substr($Value,$a-1,1);
				else $Char .=  $DefaultEmptyValue;
			}
		}
		else{
			for($a=1;$a<=$MaxDigit;$a++){
				if(($MaxDigit - $StrLenValue)< $a) $Char .= substr($Value,$a - ($MaxDigit - $StrLenValue) - 1 ,1);
				else $Char .=  $DefaultEmptyValue;
			}
		}
		return $Char;		
	}
	function generate_no_surat_cuti($type,$date_now){
		if($type == 'rooster') $add = "-R"; else $add = "-T";
		$dn_array = explode("-",$date_now);		
		$gen_surat_cuti = "YBB-".$dn_array[2].$dn_array[1].$dn_array[0].$dn_array[3].$dn_array[4].$dn_array[5].$add;
		return $gen_surat_cuti;		
	}
	function generate_no_medical($date_now){
		$dn_array = explode("-",$date_now);		
		$gen_medical = "YBB-".$dn_array[2].$dn_array[1].$dn_array[0].$dn_array[3].$dn_array[4].$dn_array[5]."-M";
		return $gen_medical;		
	}
	function convert_date($date){//ybb
		if(trim($date) == "") return "";
		else if(trim($date) == "- -") return "";
		else if(trim($date) == "--") return "";
		$a = explode("-",$date);
		$newdate =  $a[1]."-".$a[0]."-".$a[2];
		return $newdate;
	}
	function cek_valid_date($date){//ybb
		$a = explode("-",$date);
		if(count($a) < 3) return false;
		else if((trim($a[0])=="")||(trim($a[1])=="")||(trim($a[2])=="")) return false;
		else if((!ereg("^[0-9]+$",trim($a[0])))||(!ereg("^[0-9]+$",trim($a[1]))) ||(!ereg("^[0-9]+$",trim($a[2]))))  return false;
		else return true;		
	}
	function cek_numerik($num){
		if(!ereg("^[0-9]+$",$num))   return false;
		else return true;
	} 
	function convert_date2($date){
		$a = explode(" ",$date);
		$newdate = $a[2];
		return $newdate;
	}
	function get_toprange_month($month,$year){
		if(substr($month,0,1) == "0") $month = substr($month,1,1);
		switch($month){
			case "1" : return "31";break;
			case "2" : {if (($year%4) == 0) return "29"; else return "28";};break;
			case "3" : return "31";break;
			case "4" : return "30";break;
			case "5" : return "31";break;
			case "6" : return "30";break;
			case "7" : return "31";break;
			case "8" : return "31";break;
			case "9" : return "30";break;
			case "10" : return "31";break;
			case "11" : return "30";break;
			case "12" : return "31";break;
		}
	}	
//	function convert_date3($date){ //ybb
//		$str = explode(" ",$date);
//		switch ($str[0]){
//			case "Jan" : $str[0] = "1";break;
//			case "Feb" : $str[0] = "2";break;
//			case "Mar" : $str[0] = "3";break;
//			case "Apr" : $str[0] = "4";break;
//			case "May" : $str[0] = "5";break;
//			case "Jun" : $str[0] = "6";break;
//			case "Jul" : $str[0] = "7";break;
//			case "Aug" : $str[0] = "8";break;
//			case "Sep" : $str[0] = "9";break;
//			case "Oct" : $str[0] = "10";break;
//			case "Nov" : $str[0] = "11";break;
//			case "Dec" : $str[0] = "12";break;
//		}
//		$newdate =  $str[1]."-".$str[0]."-".$str[2];
//		if(trim($str[2]) == "1900") return "--";
//		return $newdate;
//	}
        function convert_date3($date){
		$str1 = substr($date,0,10);
		$str = explode("-",$str1);
		$newdate =  $str[2]."-".$str[1]."-".$str[0];
		if(trim($str[0]) == "1900") return "--";	
		return $newdate;	
	}
	function convert_date4($date){//ybb
		if(trim($date) == "/ /") return $newdate;
		$a = explode("/",$date);
		$newdate =  $a[1]."-".$a[0]."-".$a[2];
		return $newdate;
	}
	function convert_date5($date){//ybb
		if(trim($date) == "") return "";
		else if(trim($date) == "- -") return "";
		else if(trim($date) == "--") return "";
		$a = explode("-",$date);
                if($a[0]=='1900')return "";
		$newdate =  $a[2]."-".$a[1]."-".$a[0];
		return $newdate;
	}
	function cek_image($str){
		$string = substr($str,0,5);
		if ($string != "image") return false;
		else return true;
	}
	function change_default_password($pass){
		$fp = fopen("def_password.txt","w"); 
		$tulis_data = fwrite($fp, $pass, 80000); 
		if (!$tulis_data) die ("tidak bisa rubah password");
		fclose($fp); 
	}
	function get_default_password(){
		$fp = fopen("def_password.txt","r"); 
		$data= fread($fp, 80000); 
		fclose($fp); 
		return trim($data);
	}
	function make_picture($foto_txt,$file_foto){
		$fp = fopen($file_foto,"w"); 
		$tulis_data = fwrite($fp, $foto_txt, 80000); 
		if (!$tulis_data) die ("gak bisa nulis text");
		fclose( $fp ); 
	}
	function make_txt_file($data_txt,$path_file){
		$fp = fopen($path_file,"w"); 
		$tulis_data = fwrite($fp, $data_txt, 10000000); 
		if (!$tulis_data) die ("gak bisa nulis text");
		fclose( $fp ); 
	}
	function encode($foto){
		return  base64_encode(fread(fopen($foto, "rb"),filesize($foto)));
	}
	function ambil_foto($nip){
		if ($this->get_data_karyawan_from_nip($nip,'PathPhoto') == "Null") return "";
		else {
			return $this->get_data_karyawan_from_nip($nip,'PathPhoto'); 
		}
	}
	function read_picture($nip){
		$data_foto = $this->get_data_karyawan_from_nip($nip,'PathPhoto');
		$fp = fopen($data_foto,"r"); 
		$data= fread($fp, 80000); 
		fclose( $fp ); 
		return base64_decode($data);
	}
	function generate_search($prev,$end,$keyword,$kat_search,$cek_not_found){
		if(ereg("[\"]",$keyword))
			$keywords = preg_split("[\"]", $keyword);	
		else 
			$keywords = preg_split("/[\s,]+/", $keyword);
				
		$jumlah_array = count($keywords);
		if($cek_not_found == 1)		$not_found = "iouioasabbbfuuu6667778837999288772200995nnnlklkjlvjjj0099vnn";		
		else $not_found = "";
			
		/*
		$last_str = substr($akses,strlen($akses)-1,strlen($akses));
		if($last_str == ",") $akses = substr($akses,0,strlen($akses)-1);
		*/
		
		$sql = $prev." and (";
			  
		for ($i=1;$i<=$jumlah_array;$i++){
			if(ereg("[\\]",$keywords[$i-1])) $keywords[$i-1] = substr($keywords[$i-1],0,strlen($keywords[$i-1])-1);
			if(trim($keywords[$i-1]) == "") $keywords[$i-1] = $not_found;
			if ($i == $jumlah_array) $sql .= $kat_search." like '%".$keywords[$i-1]."%' ) ";
			else  $sql .= $kat_search." like '%".$keywords[$i-1]."%'  or ";
		}
		$sql .= " ".$end;
		return $sql;		
	}
	function check_valid_page($Akses,$checkpage){
		$arr_akses = explode(",",$Akses);
		if(in_array($checkpage,$arr_akses)) return true;
		else return false;
	}
	function convert_to_money($numerik,$kurs){
		if($kurs == "Rp"){
			$numerik = ceil($numerik);
			$longtext = strlen($numerik);
			$money = "";
			$b = 1;
			for($a=$longtext;$a>=0;$a--){	
				$temp[$b] .= substr($numerik,$a,1);	
				$b++;
			} 
			for($a=1;$a<=$b;$a++){
				$money .= $temp[$a];
				if(($a-1) % 3 == 0 )$money .= ".";				
			}
			for($a=strlen($money);$a>=1;$a--)	{
				 $money2 .= substr($money,$a,1);		
			}
			if(substr($money2,0,1) == ".")	return $kurs."$money2".",-";
			else return"$kurs $money2".",-";
		}
		else{
			$money = $this->round_out($numerik,2);

			return "$kurs $money";
			  //return "$kurs $numerik";
		}
	}
	function convert_to_money2($numerik,$kurs){
		if($kurs == "Rp"){
			$numerik = ceil($numerik);
			$longtext = strlen($numerik);
			$money = "";
			$b = 1;
			for($a=$longtext;$a>=0;$a--){	
				$temp[$b] .= substr($numerik,$a,1);	
				$b++;
			} 
			for($a=1;$a<=$b;$a++){
				$money .= $temp[$a];
				if(($a-1) % 3 == 0 )$money .= ".";				
			}
			for($a=strlen($money);$a>=1;$a--)	{
				 $money2 .= substr($money,$a,1);		
			}
			if(substr($money2,0,1) == ".")	return substr($money2,1,strlen($money2));
			else return "$money2";
		}
		else{
			//$money = $this->round_out($numerik,2);
			$arr_numerik = explode(".",$numerik);
			$money = $arr_numerik[0].$arr_numerik[1].$arr_numerik[2].$arr_numerik[3];
			return "$money";
			  //return "$kurs $numerik";
		}
	}
	function convert_format_po($NoPO){
		$NoPO_arr = explode("/",$NoPO);
		$bulan = $NoPO_arr[2] * 1;
		$tahun = strtoupper($NoPO_arr[3]);
		if(ereg("REV",$tahun)){
			$tahun_arr = explode("REV",$tahun);
			$tahun_a = $tahun_arr[0] + 2000;
			$tahun = $tahun_a."REV".$tahun_arr[1];
		}
		else{
			$tahun = $tahun + 2000;			
		}	
		$new_NoPO = $NoPO_arr[0]."/".$NoPO_arr[1]."/".$bulan."/".$tahun;
		return $new_NoPO;
	}
	function round_out($value, $places=0) {
		  if ($places < 0) { $places = 0; }
		  $mult = pow(10, $places);
		 //  return ($value >= 0 ? ceil($value * $mult):floor($value * $mult)) / $mult;
		   return floor($value * $mult) / $mult;
	}
	 
}

$cek_exist_class_support = "on";
?>
