All pastes #605217 Raw Edit

Untitled

public text v1 · immutable
·published 2007-07-06 01:07 UTC
rendered paste body
<?php
	//////////////////////////////////////////////////////////
	// XL service_check function, it will be the service 		//
	// checkpoints, service_check(thefilename,thesvcnumber	//
	// return 1 if the service not found, 0 if found and 2	//
	// if error occurr.																			//
	//////////////////////////////////////////////////////////
	function service_check_xl($file,$svcnum,$getme)
	{
		
		// make sure to rewind the file
		rewind($file);
		$chkok = 0;
		$errsvc = 0;
					
			//get all the service name from xlservicelist.txt
			$xllist = fopen("./xlservicelist.txt","r");
			//echo "The svcnum is $svcnum \n";
			// how many times we have to skip to get the serive name
			for($i = 0;$i < $svcnum;$i++)
			{
				$buflist = fgets($xllist,256);
				//echo "The buflist is $buflist \n";
				$point = $svcnum -1;
				if($i == $point)
				{
					
					// check if the string has '\n'
					$szbuflist = strlen($buflist);
					for($x=0 ; $x < $szbuflist; $x++)
					{
						// check 0A or 0D
						$chkchr = ord($buflist[$x]);
						if ($chkchr == 13 or $chkchr == 10)
						{
							$breakline = 1;
						}
					}
				}
			}
			fclose($xllist);
			//echo "Service name before substr $svcname \n";
			
			// if we have breakline = 1 then use substr, else goes on with the buf
			if($breakline == 1)
			{
				$svcname = substr($buflist,0,$szbuflist-2);
				
			}
						
			if($breakline == 0)
			{
				$svcname = $buflist;
				
			}
					
			// we have the service name by service number
			// check if it is in the push file
			while(!feof($file) and $errsvc != 1)
			{
				
				$len = strlen($svcname);
				//echo 'The $svcname is '."$svcname \n";
				//echo 'The $len is '."$len \n";
				
				
				$buf = fgets($file,256);
				//echo 'The $buf is '."$buf \n";
				
				if($chkok == 0)
				{
					$chkbuf = substr($buf,0,$len);
					//echo 'The chkbuf is '."$chkbuf \n";
					
					$chkbuflen = strlen($chkbuf);
					//echo 'The len of chkbuf is '."$chkbuflen \n";
					
					$res = strcmp($svcname,$chkbuf);
					//echo 'The result of strcmp is '."$res \n";
					
					if( $res == 0)
					{
						// we have the service in the push list
						// return 0
						// echo "We have the service in the push list. \n";
						
						$chkok = 1;
						if ($getme == 5)
						{
							return $buf;
						}
					}
			  }
			}
			
		if ( $chkok == 1)
			{
				return 0;
			}
			
			else
			{
				return 1;
			}	 
		
	}
	
	//////////////////////////////////////////////////////////
	//XL  service_name function, it returns service name		//
	// by service number																		//
	//////////////////////////////////////////////////////////
	function service_name_xl($id)
	{
		// first check if it is the valid number
		$xlnum = fopen("./xlconf.txt","r");
		$xlsource = fopen("./xlservicelist.txt","r");
		$thenumber = fgets($xlnum,256);
		fclose($xlnum);
		
		if($id > $thenumber)
		{
			echo "Error service number. in service_name_xl \n";
			return '';
		}
		else
		{
					
			for($i=0; $i < $id;$i++)
			{
				$bufservice = fgets($xlsource,256);
				$point = $id-1;
				$lensize = strlen($bufservice);
				
				if($i == $point)
				{
					for($i=0 ; $i < $lensize ; $i++)
					{
						$chk = ord($bufservice[$i]);
						
						if($chk == 13)
						{
							// substr me!
							echo "the bufservice is contain 13 \n";
							$newbuf = substr($bufservice,0,$lensize-2);
							return $newbuf;
						}
					}
					
					return $bufservice;
				}
			}
		}
		fclose($xlsource);	
	}
	

	
	function service_check_isat($file,$svcnum,$getme)
	{
		
		// make sure to rewind the file
		rewind($file);
		$chkok = 0;
		$errsvc = 0;
		
			
			//get all the service name from isatservicelist.txt
			$isatlist = fopen("./isatservicelist.txt","r");
			//echo "The svcnum is $svcnum \n";
			// how many times we have to skip to get the serive name
			for($i = 0;$i < $svcnum;$i++)
			{
				$buflist = fgets($isatlist,256);
				//echo "The buflist is $buflist \n";
				$point = $svcnum -1;
				if($i == $point)
				{
					
					// check if the string has '\n'
					$szbuflist = strlen($buflist);
					for($x=0 ; $x < $szbuflist; $x++)
					{
						// check 0A or 0D
						$chkchr = ord($buflist[$x]);
						if ($chkchr == 13 or $chkchr == 10)
						{
							$breakline = 1;
						}
					}
				}
			}
			fclose($isatlist);
			//echo "Service name before substr $svcname \n";
			
			// if we have breakline = 1 then use substr, else goes on with the buf
			if($breakline == 1)
			{
				$svcname = substr($buflist,0,$szbuflist-2);
				
			}
						
			if($breakline == 0)
			{
				$svcname = $buflist;
				
			}
					
			// we have the service name by service number
			// check if it is in the push file
			while(!feof($file) and $errsvc != 1)
			{
				
				$len = strlen($svcname);
				//echo 'The $svcname is '."$svcname \n";
				//echo 'The $len is '."$len \n";
				
				
				$buf = fgets($file,256);
				//echo 'The $buf is '."$buf \n";
				
				if($chkok == 0)
				{
					$chkbuf = substr($buf,0,$len);
					//echo 'The chkbuf is '."$chkbuf \n";
					$chkbuflen = strlen($chkbuf);
					//echo 'The len of chkbuf is '."$chkbuflen \n";
					
					$res = strcmp($svcname,$chkbuf);
					//echo 'The result of strcmp is '."$res \n";
					
					if( $res == 0)
					{
						// we have the service in the push list
						// return 0
						// echo "We have the service in the push list. \n";
						
						$chkok = 1;
						if ($getme == 5)
						{
							return $buf;
						}
					}
			  }
			}
			
		if ( $chkok == 1)
			{
				return 0;
			}
			
			else
			{
				return 1;
			}	 
		
	}
	
	//////////////////////////////////////////////////////////
	//isat  service_name function, it returns service name		//
	// by service number																		//
	//////////////////////////////////////////////////////////
	function service_name_isat($id)
	{
		// first check if it is the valid number
		$isatnum = fopen("./isatconf.txt","r");
		$isatsource = fopen("./isatservicelist.txt","r");
		$thenumber = fgets($isatnum,256);
		fclose($isatnum);
		
		if($id > $thenumber)
		{
			echo "Error service number. in service_name_isat \n";
			return '';
		}
		else
		{
					
			for($i=0; $i < $id;$i++)
			{
				$bufservice = fgets($isatsource,256);
				$point = $id-1;
				$lensize = strlen($bufservice);
				
				if($i == $point)
				{
					for($i=0 ; $i < $lensize ; $i++)
					{
						$chk = ord($bufservice[$i]);
						
						if($chk == 13)
						{
							// substr me!
							echo "the bufservice is contain 13 \n";
							$newbuf = substr($bufservice,0,$lensize-2);
							return $newbuf;
						}
					}
					
					return $bufservice;
				}
			}
		}
		fclose($isatsource);	
	}
	
	function service_check_tsel($file,$svcnum,$getme)
	{
		
		// make sure to rewind the file
		rewind($file);
		$chkok = 0;
		$errsvc = 0;
		
			
			//get all the service name from tselservicelist.txt
			$tsellist = fopen("./tselservicelist.txt","r");
			//echo "The svcnum is $svcnum \n";
			// how many times we have to skip to get the serive name
			for($i = 0;$i < $svcnum;$i++)
			{
				$buflist = fgets($tsellist,256);
				//echo "The buflist is $buflist \n";
				$point = $svcnum -1;
				if($i == $point)
				{
					
					// check if the string has '\n'
					$szbuflist = strlen($buflist);
					for($x=0 ; $x < $szbuflist; $x++)
					{
						// check 0A or 0D
						$chkchr = ord($buflist[$x]);
						if ($chkchr == 13 or $chkchr == 10)
						{
							$breakline = 1;
						}
					}
				}
			}
			fclose($tsellist);
			//echo "Service name before substr $svcname \n";
			
			// if we have breakline = 1 then use substr, else goes on with the buf
			if($breakline == 1)
			{
				$svcname = substr($buflist,0,$szbuflist-2);
				
			}
						
			if($breakline == 0)
			{
				$svcname = $buflist;
				
			}
					
			// we have the service name by service number
			// check if it is in the push file
			while(!feof($file) and $errsvc != 1)
			{
				
				$len = strlen($svcname);
				//echo 'The $svcname is '."$svcname \n";
				//echo 'The $len is '."$len \n";
				
				
				$buf = fgets($file,256);
				//echo 'The $buf is '."$buf \n";
				
				if($chkok == 0)
				{
					$chkbuf = substr($buf,0,$len);
					//echo 'The chkbuf is '."$chkbuf \n";
					$chkbuflen = strlen($chkbuf);
					//echo 'The len of chkbuf is '."$chkbuflen \n";
					
					$res = strcmp($svcname,$chkbuf);
					//echo 'The result of strcmp is '."$res \n";
					
					if( $res == 0)
					{
						// we have the service in the push list
						// return 0
						// echo "We have the service in the push list. \n";
						
						$chkok = 1;
						if ($getme == 5)
						{
							return $buf;
						}
					}
			  }
			}
			
		if ( $chkok == 1)
			{
				return 0;
			}
			
			else
			{
				return 1;
			}	 
		
	}
	
	//////////////////////////////////////////////////////////
	//tsel  service_name function, it returns service name		//
	// by service number																		//
	//////////////////////////////////////////////////////////
	function service_name_tsel($id)
	{
		// first check if it is the valid number
		$tselnum = fopen("./tselconf.txt","r");
		$tselsource = fopen("./tselservicelist.txt","r");
		$thenumber = fgets($tselnum,256);
		fclose($tselnum);
		
		if($id > $thenumber)
		{
			echo "Error service number. in service_name_tsel \n";
			return '';
		}
		else
		{
					
			for($i=0; $i < $id;$i++)
			{
				$bufservice = fgets($tselsource,256);
				$point = $id-1;
				$lensize = strlen($bufservice);
				
				if($i == $point)
				{
					for($i=0 ; $i < $lensize ; $i++)
					{
						$chk = ord($bufservice[$i]);
						
						if($chk == 13)
						{
							// substr me!
							echo "the bufservice is contain 13 \n";
							$newbuf = substr($bufservice,0,$lensize-2);
							return $newbuf;
						}
					}
					
					return $bufservice;
				}
			}
		}
		fclose($tselsource);	
	}
	
	
	//////////////////////////////////////////////////////////
	// start of diff function																//
	//////////////////////////////////////////////////////////
	
	
	// check the telco name, why? to make it simple and more readable
	function check_telco_name($buf)
	{
		$chk = substr($buf,0,4);
		echo 'chk telco result : '."$chl \n";
		
		// change all of this, use switch just like app check
		switch ($chk){
			
			case "INDO":
				echo 'Check telco was in INDO.'." \n";
				return 1;
				
			case "TELK":
				return 2;
				
			case "XL25":
				return 3;
				
			default:
				echo "Check telco error undefine. \n";
				return 0;
			}
			
		
	}
	
	
	function check_blank_line($buf)
	{
		$size = strlen($buf);
		
		if($size== 2 or $size < 1)
		{
			for ($i=0;$i<2;$i++)
			{
				$ch = ord($buf[$i]);
				if($ch==13 or $ch == 10 or $size == 0)
				{
					return 1;
				}
			}
		}
		else
		{
			return 0;
		}
	}
	
	
	function check_app_line($buf)
	{
		$chk = substr($buf,0,4);
		if($chk == "app_")
		{
			return 1;
		}
		else
		{
			return 0;
		}
		
	}
	
	
	function add_telco_name($buf, $tn)
	{
		switch($tn){
			case 1:
				$name = "ISAT";
				break;
			
			case 2:
				$name = "TSEL";
				break;
				
			case 3:
				$name = "XL25";
				break;
				
			default:
				echo " error in add_telco_name input undefine. \n";
				break;
			}
		$size = strlen($buf)+4;
		for ($i=0;$i<4;$i++)
		{
			$nb[$i] = $name[$i];
		}
			
		for ($x=4;$x<$size;$x++)
		{
			$nb[$x] = $buf[$x-4];
		}
		//$nb = str_pad($name,$size,$buf,STR_PAD_LEFT);
		echo '$nb is '."$nb \n";
		return $nb;
	}
	//////////////////////////////////////////////////////////
	// End of diff functions																//
	//////////////////////////////////////////////////////////
	
	/*****************************************************************************************/
	//////////////////////////////////////////////////////////
	// Start of uploader functions													//
	//////////////////////////////////////////////////////////
	// do_size(thestringname, thestringsize(len))
	// a function that will filter the actual size. ( neglect 13 or 0Dh and 10 or 0Ah , char)
	// return the actual size of string.
	function do_size($string, $sz)
	{
		$x = 0;
		$i = 0;
		$ch =' ';
		while($x != 13 and $i < $sz)
		{
			$ch =$string[$i];
			//echo $ch;
			$x = ord($ch);
			//echo "$x ";
			if( $x != 13)
			 $i++;
		}
		//echo "\n";
		return $i;
	}
	
	// scanstrpos_whitespace(thestringname,thestringsize,thescanchar)
	// a function will return the last occurrence of a char
	function scanstrpos_whitespace($b,$actsz,$scanstr)
	{
		
		$i = 0;
		$x = 0;
		
		while($x<$actsz)
		{
			$res = ord($b[$i]);
			//echo "$res ";
			if($res == $scanstr)
			{
				$x=$actsz+1;
				//echo "got here. \n";
			}
			else
			{
				$i++;
				$x++;
			}
		}
		//echo ' end of $res. ' ."\n";
		return $i;
	}
		
	// scanstrpos_after_n(thestringname,previouspos,thestringsize,thescanchar)
	// this is a function that continue the first scan string
	function scanstrpos_after_n($b,$pvpos,$sz,$char)	
	{
		$ab = substr($b,$pvpos);
		$i = 0;
		$x = 0;
		//echo '$ab is' ." $ab \n";
 		while($x<$sz )
		{
			$ch = ord($ab[$i]);
			if($ch == $char)
			{
				//echo 'In pos \n';
				$pos++;
			}
					
			//echo " $ch";
			$i++;
			$x++;
		}
		echo "\n";
		return $pvpos+$pos;
	}
	
	
	function do_check($testbuf)
	{
		$res1 = strlen($testbuf);
		//echo '$res do check is' ." $res1 \n";
		if($res1==0)
		{
			return 1;
		}
		
		return 0;
	}
	
	
	function insert_to_db($b1,$b2,$tco)
	{
		$today = date("Y-m-d");
		//$today = "2007-06-17";
		echo "$today \n";
		mysql_connect("localhost","root");
		mysql_select_db("test");
		
		switch ($tco){
			case 1:
				$telco = "indosatpush9965";
				break;
				
			case 2:
				$telco = "telkomselpush9965";
				break;
				
			case 3:
				$telco = "xlpush2588";
				break;
				
			default:
				echo "Undefine telco in insert_to_db. \n";
				break;
			}
		
		$query = mysql_query("INSERT INTO $telco (`appname`,`apppush`,`datein`) VALUES ('$b1','$b2','$today') ");
		if (!$query) 
						{
    					die('Invalid query: ' . mysql_error());
						}
		mysql_close();
		echo '$telco is '."$telco \n";
		echo '$b1 is: '."$b1 \n";
		echo '$b2 is: '."$b2 \n";
	}
	
	function get_telconm($buf)
	{
		$tmpbuf = substr($buf,0,4);
		
		switch($tmpbuf){
			case "ISAT":
				return 1;
				
			case "TSEL":
				return 2;
				
			case "XL25":
				return 3;
				
			default:
				return 0;
			}
	
	}
	
	//////////////////////////////////////////////////////////
	// end of uploader functions														//
	//////////////////////////////////////////////////////////
	
	
	//////////////////////////////////////////////////////////
	// Indosat section first.. 															//
	//////////////////////////////////////////////////////////
	
	// create the isatelbuf.txt
	$isatsource = fopen("http://dewiden.paysetter.co.id/tipush.txt","r");
	$isatdest = fopen("./isatbuf.txt","w");
	
	while(!feof($isatsource))
	{
		$tmp = fgets($isatsource,256);
		$new = strtoupper($tmp);
		fwrite($isatdest,$new);
		
	}
	fclose($isatsource);
	fclose($isatdest);
	
	// first move all indosat things into isatpush.txt
	$isatsource = fopen("./isatbuf.txt","r");
	$isatdest		= fopen("./isatpush.txt","w");
	
	// we read the source file line by line, if got isat telco 
	// identifier then get everything but if encounter tsel
	// telco identifier stop and continue with other proc
	
	while(!feof($isatsource))
	{
		$isatbuf = fgets($isatsource,256);
		$isatchk = substr($isatbuf,0,4);
		//echo "The isatchk is $isatchk. \n";
		if ($isatchk == "TELK")
		{
			//echo "Got telk identifier $isatbuf. \n";
			break ;
		}
		else
		{
			fwrite($isatdest,$isatbuf);
			//echo "The isat buf transfer is $isatbuf ";
		}
	}
	
	fclose($isatsource);
	fclose($isatdest);
	
	// Got separated, yeahhhh continue with other,
	// process if all service is good
	$isatsource = fopen("./isatpush.txt","r");
	$isatdest = fopen("./pushlist.txt","w");
	
	//write the the telco name as the header
	fwrite($isatdest,"INDOSAT9965 \x0D\x0A");
	
	$index = 1;
	$isatconf = fopen("./isatconf.txt","r");
	$numservice = fgets($isatconf,256);
	fclose($isatconf);
	
	for ($i = 0; $i < $numservice; $i++)
	{
		$servicechk = service_check_isat($isatsource,$index,0);
		$printme = service_name_isat($index);
		echo "$index . This $printme service check is $servicechk \n";
		
		// got the bad service
		if($servicechk == 1)
		{
			$thisbadservice = service_name_isat($index);
			fwrite($isatdest,$thisbadservice);
			echo "This bad service is $thisbadservice ";
			// add tab 
			echo "\t";
			
			fwrite($isatdest,"\t");
			fwrite($isatdest,"0");
			echo "0 \n";
			fwrite($isatdest,"\x0D\x0A");
		}
		
		if($servicechk == 0)
		{
			//write the service in the right order
			$serviceokay = service_check_isat($isatsource,$index,5);
			echo "This msg will be write in the push list. $serviceokay \n";
			fwrite($isatdest,$serviceokay);
			fwrite($isatdest,"\x0D\x0A");
			
		}
		
		$index++;
	}
	
	fclose($isatsource);
	fclose($isatdest);
	
	//////////////////////////////////////////////////////////
	//																											//
	// end of indosat input output section									//
	//																											//
	//////////////////////////////////////////////////////////
	
	//////////////////////////////////////////////////////////
	// Telkomsel9965 section start													//
	//////////////////////////////////////////////////////////
	
	// first move all tsel9965 things into tselpush.txt
	$tselsource = fopen("./isatbuf.txt","r");
	$tseldest		= fopen("./tselpush.txt","w");
	$writeme = 0;
	// we read the source file line by line, start from tsel 
	// identifier then get everything until feof
		
	while(!feof($tselsource))
	{
		$tselbuf = fgets($tselsource,256);
		$tselchk = substr($tselbuf,0,4);
		//echo "The tselchk is $tselchk. \n";
		
		if ($tselchk == "TELK")
		{
			echo "Got telk identifier $tselbuf. \n";
			$writeme = 1;
		}
		if($writeme == 1)
		{
			$new = strtoupper($tselbuf);
			fwrite($tseldest,$new);
			echo "The tsel buf transfer is $new ";
		}
	}
	
	fclose($tselsource);
	fclose($tseldest);
	
	// Got separated, yeahhhh continue with other,
	// process if all service is good
	$tselsource = fopen("./tselpush.txt","r");
	$tseldest = fopen("./pushlist.txt","a+");
	
	//write the the telco name as the header
	fwrite($tseldest,"TELKOMSEL9965 \x0D\x0A");
	
	$tselconf = fopen("./tselconf.txt","r");
	$numservice = fgets($tselconf,256);
	fclose($tselconf);
	
	$index = 1;
	for ($i = 0; $i < 11; $i++)
	{
		$servicechk = service_check_tsel($tselsource,$index,0);
		$printme = service_name_tsel($index);
		echo "$index . This $printme service check is $servicechk \n";
		
		// got the bad service
		if($servicechk == 1)
		{
			$thisbadservice = service_name_tsel($index);
			fwrite($tseldest,$thisbadservice);
			echo "This bad service is $thisbadservice ";
			// add tab 
			echo "\t";
			
			fwrite($tseldest,"\t");
			fwrite($tseldest,"0");
			echo "0 \n";
			fwrite($tseldest,"\x0D\x0A");
		}
		
		if($servicechk == 0)
		{
			//write the service in the right order
			$serviceokay = service_check_tsel($tselsource,$index,5);
			echo "This msg will be write in the push list. $serviceokay \n";
			fwrite($tseldest,$serviceokay);
			fwrite($tseldest,"\x0D\x0A");
			
		}
		
		$index++;
	}
	
	fclose($tselsource);
	fclose($tseldest);
	
	//////////////////////////////////////////////////////////
	// End of telkomsel9965 input output section						//
	//////////////////////////////////////////////////////////
	
	//////////////////////////////////////////////////////////
	//																											//
	// XL2588 file input output															//
	//																											//
	//////////////////////////////////////////////////////////
	
	
	// open the XL file, just for read and copy to xlbuf.txt
	$xlsource = fopen("http://panday.paysetter.co.id/xlpush.txt","r");
	$xldest = fopen("./xlbuf.txt","w");
	
	while(!feof($xlsource))
	{
		$tmp = fgets($xlsource,256);
		$chk = substr($tmp,0,4);
		$new = strtoupper($tmp);
		fwrite($xldest,$new);
				
	}
	
	fclose($xlsource);
	fclose($xldest);
	
	
	$xlsource = fopen("./xlbuf.txt","r");
	$xldest = fopen("./xlpushtemp.txt","w");
	
	$index = 1;
	// do the check
	// check if all service is good
	fwrite($xldest,"XL2588\x0D\x0A");
	echo "XL2588\n";
	
	//check how many services do we have
	$xlconf = fopen("./xlconf.txt","r");
	$bufconf = fgets($xlconf,256);
	fclose($xlconf);
	
	for ($i = 0; $i < $bufconf; $i++)
	{
		$servicechk = service_check_xl($xlsource,$index,0);
		//$printme = service_name($index);
		echo "$index . This $printme service check is $servicechk \n";
		
		// got the bad service
		if($servicechk == 1)
		{
			$thisbadservice = service_name_xl($index);
			fwrite($xldest,$thisbadservice);
			echo "This bad service is $thisbadservice ";
			// add tab 
			echo "\t";
			
			fwrite($xldest,"\t");
			fwrite($xldest,"0");
			echo "0 \n";
			fwrite($xldest,"\x0D\x0A");
		}
		
		if($servicechk == 0)
		{
			//write the service in the right order
			$serviceokay = service_check_xl($xlsource,$index,5);
			echo "This msg will be write in the push list. $serviceokay \n";
			fwrite($xldest,$serviceokay);
			fwrite($xldest,"\x0D\x0A");
			
		}
		
		$index++;
	}
		
	fclose($xlsource);
	fclose($xldest);
	
	// We all set ready to transfer all the data to the real push list
	$xlsource = fopen("./xlpushtemp.txt","r");
	$xldest = fopen("./pushlist.txt","a");
	
	while(!feof($xlsource))
	{
		$sbuf = fgets($xlsource,256);
		fwrite($xldest,$sbuf);
		echo 'Tranferring '."$sbuf ";
	}
	
	fclose($xlsource);
	fclose($xldest);
	
	//////////////////////////////////////////////////////////
	//																											//
	// End of XL2588 input output														//
	//																											//
	//////////////////////////////////////////////////////////
	
	
	//////////////////////////////////////////////////////////
	//																											//
	// The diff push section #2															//
	//																											//
	//////////////////////////////////////////////////////////
	
	// open the read file
	$file = fopen("./pushlist.txt","r");
	
	// open the temp write file, if it doesnt exist then create one
	$newfile = fopen("./tmpfile.txt","w");
	
	if((fflush($newfile))===false){
		echo "Failed to flush the newfile. \n";
	}
	
	global $prev;
	
	if($file)
	{
		while(!feof($file))
		{
			// read the line
			$buffer = fgets($file,256);
			echo "$buffer";
			
			// check if it's blank line, and skip 
			$blankline = check_blank_line($buffer);
			echo '$blank line is '."$blankline \n";
			
			$appline = check_app_line($buffer);
			
			if((!$blankline) && (!$appline))
			{
				// since this is the first, check if it's telco
				// check if there is telco label
				$telconame = check_telco_name($buffer);
				//echo 'The telconame is '."$telconame;
				if($telconame == 0)
					{
						$pvtelconame = $prev;
						// got the telconame now add the telco initial 
						$newbuf = add_telco_name($buffer,$pvtelconame);
						echo "The new buf is ";
						for($i=0;$i<(strlen($buffer)+4);$i++)
						{
							//echo "$newbuf[$i]";
							fwrite($newfile,$newbuf[$i]);
						}
						//echo "\n";
					}
				
				else
					{
						$pvtelconame = $telconame;
						$prev = $telconame;
						
					}
							
			
			}
			else
			{
				if($appline == 1)
				{
					echo "App line encounter SKIP.\n\n";
				}
				else
				{
					echo "Blank line encounter SKIP. \n\n";
				}
			}
			
			
		}
	}
	
	
	fclose($file);
	fclose($newfile);
				
	//////////////////////////////////////////////////////////
	//																											//
	// end of diff push section #2													//
	//																											//
	//////////////////////////////////////////////////////////
	
	
	
	//////////////////////////////////////////////////////////
	//																											//
	// start of uploader section #3													//
	//																											//
	//////////////////////////////////////////////////////////	
	$handle = @fopen("./tmpfile.txt", "r");
	if ($handle) 
	{
    while (!feof($handle)) 
    {
        // read per line
        $buffer = fgets($handle, 256);
        //echo "$buffer \n";
        $size = strlen($buffer);
        //echo "$size \n";
        
        				
				// get the actual size, DELETE the \n
				$actualsize = do_size($buffer,$size);
				//echo "actual size is $actualsize \n";
				
				// you have the size now inspect the string for whitespace
				$firststringpos = scanstrpos_whitespace($buffer,$actualsize,9);
				//echo "The first string pos is $firststringpos \n";
				
				// you have the first string pos, copy it to buf1
				$buf1 = substr($buffer,0,$firststringpos);
				//echo "$buf1 \n";
				
				// scearch the string pos, after the last occurrance of ..
				$secondstringpos = scanstrpos_after_n($buffer,$firststringpos,$actualsize,9);
				//echo "The second string would be $secondstringpos \n";
				
				// you have the second start string delete the previous.
				$buf2 = substr($buffer,$secondstringpos);
				//echo '$buf2 is' ." $buf2 \n";
				
				// check if buf1 is valid
				$valid = do_check($buf1);
				if ($valid)
				{
					echo "Error was occurr at buf1 : The value is invalid. \n";
					echo "Error was occurr at buf2 : The value of buf1 is invalid. \n";
				}
				
				// have them insert into the MYSQL one by one and ignore the error.
				// ..future log all error, it wwill include with the proccess position
				else
				{
					// addition: what is the telco to put the data intto the telco table application 
					// there will be a switch condition so the insertdb will insert into the table
					// directly, supply from the previous checked.
					
					$telco = get_telconm($buf1);
					
					insert_to_db($buf1,$buf2,$telco);
				}
    }
    fclose($handle);
   }
/*****************************************************************************************/	
	//////////////////////////////////////////////////////////
	//																											//
	// start of uploader section #3													//
	//																											//
	//////////////////////////////////////////////////////////	
?>