Mister Spy Say ="Hello Kids ... :D" ___ ____ _ _____ | \/ (_) | | / ___| | . . |_ ___| |_ ___ _ __ \ `--. _ __ _ _ | |\/| | / __| __/ _ \ '__| `--. \ '_ \| | | | | | | | \__ \ || __/ | /\__/ / |_) | |_| | \_| |_/_|___/\__\___|_| \____/| .__/ \__, | | | __/ | |_| |___/ Bot Mister Spy V3
Mister Spy

Mister Spy

Current Path : /home/caballoscriollos/public_html/espanol/actualizador/
Upload File :
Current File : /home/caballoscriollos/public_html/espanol/actualizador/extr.php

<?php

class DB 
{
	static public function String($string)
	{		
		//return "'".addslashes(toHTML($string))."'";
		return "'".addslashes($string)."'";
	}
	
	static public function StringUnquoted($string)
	{
		return addslashes($string);
	}
	
	static public function Number($sNumber)
	{
		return (is_numeric($sNumber) ? $sNumber : 'NULL');
	}
	
	static public function ObtenerFecha($Date)
	{
		$Anio = substr($Date, 0, 4);
		$Mes = substr($Date, 4, 2);
		$Dia = substr($Date, 6, 2);
		return $Dia . '-' .$Mes. '-' .$Anio;
	}
	
	static public function Date($date)
	{/*
        if (($ret = DB::parseDate($date, '%Y-%m-%d %H:%M:%s')) != false)
                return "'$ret'";

        if (($ret = DB::parseDate($date, '%d/%m/%Y %H:%M:%s')) != false)
                return "'$ret'";

        if (($ret = DB::parseDate($date, '%d/%m/%Y %H:%M')) != false)
                return "'$ret'";

        if (($ret = DB::parseDate($date, '%d/%m/%Y %H')) != false)
                return "'$ret'";
*/
        if (($ret = DB::parseDate($date, '%d/%m/%Y')) != false)
                return "'$ret'";
/*
        if (($ret = DB::parseDate($date, '%Y-%m-%d %H:%M:%s')) != false)
                return "'$ret'";

        if (($ret = DB::parseDate($date, '%d-%m-%Y %H:%M:%s')) != false)
                return "'$ret'";

        if (($ret = DB::parseDate($date, '%d-%m-%Y %H:%M')) != false)
                return "'$ret'";

        if (($ret = DB::parseDate($date, '%d-%m-%Y %H')) != false)
                return "'$ret'";
*/
        if (($ret = DB::parseDate($date, '%d-%m-%Y')) != false)
                return "'$ret'";
/*
        if (($ret = DB::parseDate($date, '%Y-%m-%d %H:%M')) != false)
                return "'$ret'";

        if (($ret = DB::parseDate($date, '%Y-%m-%d %H')) != false)
                return "'$ret'";

        if (($ret = DB::parseDate($date, '%Y-%m-%d')) != false)
                return "'$ret'";
*/
        return 'NULL';
	}

	
	static public function Bool($sBool)
	{
		if ($sBool == true || $sBool == 1)
			return '1';
		return '0';
	}

	static private function parseDate( $date, $format ) 
	{
		// Builds up date pattern from the given $format, keeping delimiters in place.
		if( !preg_match_all( "/%([YmdHMsu])([^%])*/", $format, $formatTokens, PREG_SET_ORDER ) ) 
			return false;
	
		foreach( $formatTokens as $formatToken ) 
		{
			$delimiter = preg_quote( $formatToken[2], "/" );
			if($formatToken[1] == 'Y') 
			{
				$datePattern .= '(.{1,4})'.$delimiter;
			} 
			elseif($formatToken[1] == 'u') 
			{
				$datePattern .= '(.{1,5})'.$delimiter;
			} 
			else 
			{
				$datePattern .= '(.{1,2})'.$delimiter;
			}
		}
		
		// Splits up the given $date
		if( !preg_match( "/^".$datePattern."/", $date, $dateTokens) ) 
		{
			return false;
		}
	  
		$dateSegments = array();
		for($i = 0; $i < count($formatTokens); $i++) 
		{
			$dateSegments[$formatTokens[$i][1]] = $dateTokens[$i+1];
		}
	
		// Reformats the given $date into rfc3339
		if( $dateSegments["Y"] && $dateSegments["m"] && $dateSegments["d"] ) 
		{
			if( ! checkdate ( $dateSegments["m"], $dateSegments["d"], $dateSegments["Y"] )) 
			{ 
				return false; 
			}
			
			$dateReformated =
			str_pad($dateSegments["Y"], 4, '0', STR_PAD_LEFT)
			."-".str_pad($dateSegments["m"], 2, '0', STR_PAD_LEFT)
			."-".str_pad($dateSegments["d"], 2, '0', STR_PAD_LEFT);
		} 
		else 
		{
			return false;
		}
	  
		if( $dateSegments["H"] && $dateSegments["M"] ) 
		{
			$dateReformated .=
			" ".str_pad($dateSegments["H"], 2, '0', STR_PAD_LEFT)
			.':'.str_pad($dateSegments["M"], 2, '0', STR_PAD_LEFT);
	
			if( $dateSegments["s"] ) 
			{
				$dateReformated .=
				":".str_pad($dateSegments["s"], 2, '0', STR_PAD_LEFT);
				if( $dateSegments["u"] ) 
				{
					$dateReformated .=
					'.'.str_pad($dateSegments["u"], 5, '0', STR_PAD_RIGHT);
				}
			}
		}
	
		return $dateReformated;
	}
}


set_time_limit(99999999999);




$hostname_cnx = "localhost";
$Animalbase_cnx = "caballos_bd";
$username_cnx = "caballos_usuario";
$password_cnx = "V4kadl8xLdDR";
$cnx = mysql_pconnect($hostname_cnx, $username_cnx, $password_cnx) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($Animalbase_cnx, $cnx);




$Handle = fopen('accc/EXTR_2.txt', "r");
$Header = 1;
$Row	= 1;
$Id		= 1;
$Error	= "";



while (($Animal = fgetcsv($Handle, 1000,  ";")) !== FALSE)
{
	if ($Header != 0)
	{				
		if((trim($Animal[8]) != ""))
		{	
			#Obtengo los datos para agregarlos en la base de datos
			$RAZA = $Animal[0];//
			$REGI = $Animal[1];//
			$VARI = $Animal[2];//
			$ASOC = $Animal[3];//
			$HBAE = $Animal[4];//
			$CDPX = $Animal[5];//
			$RPEX = $Animal[6];//
			$SEXO = $Animal[7];//
			$NOMB = $Animal[8];//
			$PROP = $Animal[9];//
			$CRIA = $Animal[10];//
			$ANLS = $Animal[11];//
			$RANA = $Animal[12];//
			$APRB = $Animal[13];//
			$COLO = $Animal[14];
			$FNAC = DB::ObtenerFecha($Animal[15]);//
			$FBAJ = DB::ObtenerFecha($Animal[16]);
			$CPEL = $Animal[17];//
			$CCUE = $Animal[18];//
			$CCAB = $Animal[19];//
			$CMIE = $Animal[20];//
			$RPNU = $Animal[21];//
			$NROC = $Animal[22];//
			$PURE = $Animal[23];//
			$TANA = $Animal[24];//
			$IdPr = $Animal[25];//
			$IdPa = $Animal[26];//
			$IdMa = $Animal[27];//
			
			/* verificamos si esxiste el registro, entonces utilizamos el Id existente */
			$queryAnimal = "SELECT * FROM tblExtr";
			$queryAnimal.= " WHERE HBAE = " . DB::Number($HBAE);
			$queryAnimal.= " AND RPEX = " . DB::String($RPEX);
			$queryAnimal.= " AND SEXO = " . DB::String($SEXO);
			$queryAnimal.= " AND REGI = " . DB::String($REGI);
			$sqlAnimal	= mysql_query($queryAnimal) or die(mysql_error());
			$oAnimal = mysql_fetch_array($sqlAnimal);

			if ($oAnimal)
			{
				$queryUpdate = "";
				$queryUpdate.= "UPDATE tblExtr SET";
				$queryUpdate.= " REGI = " . DB::Number($REGI) . ", ";
				$queryUpdate.= " VARI = " . DB::String($VARI) . ", ";
				$queryUpdate.= " ASOX = " . DB::String($ASOC) . ", ";
				$queryUpdate.= " HBAE = " . DB::Number($HBAE) . ", ";
				$queryUpdate.= " CDPX = " . DB::String($CDPX) . ", ";
				$queryUpdate.= " RPEX = " . DB::String($RPEX) . ", ";
				$queryUpdate.= " SEXO = " . DB::String($SEXO) . ", ";
				$queryUpdate.= " NOMB = " . DB::String($NOMB) . ", ";
				$queryUpdate.= " PROP = " . DB::String($PROP) . ", ";
				$queryUpdate.= " CRIA = " . DB::String($CRIA) . ", ";
				$queryUpdate.= " ANLS = " . DB::String($ANLS) . ", ";
				$queryUpdate.= " RANA = " . DB::String($RANA) . ", ";
				$queryUpdate.= " APRB = " . DB::String($APRB) . ", ";
				$queryUpdate.= " COLO = " . DB::String($COLO) . ", ";
				if ($FNAC != "" && $FNAC != "NULL") 
					$queryUpdate.= " FNAC = " . DB::Date($FNAC) . ", ";
				$queryUpdate.= " FBAJ = " . DB::Date($FBAJ) . ", ";
				$queryUpdate.= " CPEL = " . DB::String($CPEL) . ", ";
				$queryUpdate.= " CCUE = " . DB::String($CCUE) . ", ";
				$queryUpdate.= " CCAB = " . DB::String($CCAB) . ", ";
				$queryUpdate.= " CMIE = " . DB::String($CMIE) . ", ";
				$queryUpdate.= " RPNU = " . DB::String($RPNU) . ", ";
				$queryUpdate.= " NROC = " . DB::String($NROC) . ", ";
				$queryUpdate.= " PURE = " . DB::String($PURE) . ", ";
				$queryUpdate.= " TANA = " . DB::String($TANA) . ", ";
				$queryUpdate.= " IdProd = " . DB::Number($IdPr) . ", ";
				$queryUpdate.= " IdPa = " . DB::Number($IdPa) . ", ";
				$queryUpdate.= " IdMa = " . DB::Number($IdMa);
				$queryUpdate.= " WHERE IdExtr = " . DB::Number($IdExtr);
				
				$sqlUpdate = mysql_query($queryUpdate, $cnx) or die(mysql_error());	
										
			}
			else
			{
				$queryInsert = "";
				$queryInsert.= "INSERT INTO tblExtr";
				$queryInsert.= "(";
				$queryInsert.= " RAZA,";
				$queryInsert.= " REGI,";
				$queryInsert.= " VARI,";
				$queryInsert.= " ASOX,";
				$queryInsert.= " HBAE,";
				$queryInsert.= " CDPX,";
				$queryInsert.= " RPEX,";
				$queryInsert.= " SEXO,";
				$queryInsert.= " NOMB,";
				$queryInsert.= " PROP,";
				$queryInsert.= " CRIA,";
				$queryInsert.= " ANLS,";
				$queryInsert.= " RANA,";
				$queryInsert.= " APRB,";
				$queryInsert.= " COLO,";
				if ($FNAC != "" && $FNAC != "NULL") $queryInsert.= " FNAC,";
				$queryInsert.= " FBAJ,";
				$queryInsert.= " CPEL,";
				$queryInsert.= " CCUE,";
				$queryInsert.= " CCAB,";
				$queryInsert.= " CMIE,";
				$queryInsert.= " RPNU,";
				$queryInsert.= " NROC,";
				$queryInsert.= " PURE,";
				$queryInsert.= " TANA,";
				$queryInsert.= " IdProd,";
				$queryInsert.= " IdPa,";
				$queryInsert.= " IdMa";
				$queryInsert.= ")";
				$queryInsert.= " VALUES ";
				$queryInsert.= "(";
				$queryInsert.= DB::Number($RAZA) . ", ";
				$queryInsert.= DB::String($REGI) . ", ";
				$queryInsert.= DB::String($VARI) . ", ";
				$queryInsert.= DB::String($ASOC) . ", ";
				$queryInsert.= DB::Number($HBAE) . ", ";
				$queryInsert.= DB::String($CDPX) . ", ";
				$queryInsert.= DB::String($RPEX) . ", ";
				$queryInsert.= DB::String($SEXO) . ", ";
				$queryInsert.= DB::String($NOMB) . ", ";
				$queryInsert.= DB::String($PROP) . ", ";
				$queryInsert.= DB::String($CRIA) . ", ";
				$queryInsert.= DB::String($ANLS) . ", ";
				$queryInsert.= DB::String($RANA) . ", ";
				$queryInsert.= DB::String($APRB) . ", ";
				$queryInsert.= DB::String($COLO) . ", ";
				if ($FNAC != "" && $FNAC != "NULL") $queryInsert.= DB::Date($FNAC) . ", ";
				$queryInsert.= DB::Date($FBAJ) . ", ";
				$queryInsert.= DB::String($CPEL) . ", ";
				$queryInsert.= DB::String($CCUE) . ", ";
				$queryInsert.= DB::String($CCAB) . ", ";
				$queryInsert.= DB::String($CMIE) . ", ";
				$queryInsert.= DB::String($RPNU) . ", ";
				$queryInsert.= DB::String($NROC) . ", ";
				$queryInsert.= DB::String($PURE) . ", ";
				$queryInsert.= DB::String($TANA) . ", ";
				$queryInsert.= DB::Number($IdPr) . ", ";
				$queryInsert.= DB::Number($IdPa) . ", ";
				$queryInsert.= DB::Number($IdMa);
				$queryInsert.= ")";
				//print_r($queryInsert);exit;
				$sqlInsert = mysql_query($queryInsert, $cnx) or die(mysql_error());			
			}
			
			/* verificamos si esxiste el registro, entonces utilizamos el Id existente */
			$queryAnimal = "SELECT * FROM tblAnimales";
			$queryAnimal.= " WHERE IdProd = " . DB::Number($IdPr);
			$sqlAnimal	= mysql_query($queryAnimal) or die(mysql_error());
			$oAnimal = mysql_fetch_array($sqlAnimal);
			
			$queryAnimal2 = "SELECT * FROM tblExtr";
			$queryAnimal2.= " WHERE HBAE = " . DB::Number($HBAE);
			$queryAnimal2.= " AND RPEX = " . DB::String($RPEX);
			$queryAnimal.= " AND SEXO = " . DB::String($SEXO);
			$queryAnimal2.= " AND REGI = " . DB::String($REGI);
			$sqlAnimal2	= mysql_query($queryAnimal2) or die(mysql_error());
			$oAnimal2 = mysql_fetch_array($sqlAnimal2);
			
			if ($oAnimal)
			{
				$queryUpdate = "";
				$queryUpdate.= "UPDATE tblAnimales SET";
				$queryUpdate.= " IdProd = " . DB::Number($IdPr) . ", ";
				$queryUpdate.= " IdPa = " . DB::Number($IdPa) . ", ";
				$queryUpdate.= " IdMa = " . DB::Number($IdMa) . ", ";
				$queryUpdate.= " IdExis = NULL, ";
				$queryUpdate.= " IdPdre = NULL, ";
				$queryUpdate.= " IdExtr = " . DB::Number($oAnimal2['IdExtr']);
				$queryUpdate.= " WHERE IdProd = " . DB::Number($IdPr);
	
				$sqlUpdate = mysql_query($queryUpdate, $cnx) or die(mysql_error());		
			}
			else
			{
				$queryInsert = "";
				$queryInsert.= "INSERT INTO tblAnimales";
				$queryInsert.= "(";
				$queryInsert.= " IdProd,";
				$queryInsert.= " IdPa,";
				$queryInsert.= " IdMa,";
				$queryInsert.= " IdExtr";
				$queryInsert.= ")";
				$queryInsert.= " VALUES ";
				$queryInsert.= "(";
				$queryInsert.= DB::Number($IdPr) . ", ";
				$queryInsert.= DB::Number($IdPa) . ", ";
				$queryInsert.= DB::Number($IdMa) . ", ";
				$queryInsert.= DB::Number($oAnimal2['IdExtr']);
				$queryInsert.= ")";
				
				$sqlInsert = mysql_query($queryInsert, $cnx) or die(mysql_error());	
			}			
		}
		else
		{
			$registro = $row++;
			$mensaje .= "<br> El registro " . $row . " no se ha podido agregar.";
		}
	}

	print_r($Row . ': ' . $NOMB);
	print_r('<br>');

	$Row++;
	$Header++;
}

print_r("Fin 1");
print_r("<br>");

?>

Mr. DellatioNx196 GaLers xh3LL Backd00r 1.0, Coded By Mr. DellatioNx196 - Bogor BlackHat