#!/php/php
<?php
//header( "Content-Type: text/html" );
//header( "Content-Type: text/plain" );
set_time_limit( 300 );
require( "config.php" );
require( "php-lib.inc" );
//$indir = "C:\\Download\\Data";
$indir = ".";
// default infile
//$infile = "goodrecs.txt";
$infile = "Ahlan2_3.txt";
$level = 33;
PrintHtmlTop( "Alosh Update Script" );
echo "<p> input file=\"$indir/$infile\" </p>\n";
//echo "#input file=\"$indir/$infile\" \n\n";
if ( !$infile ) {
echo "<p>usage: php parse-records.php infile=filename.ext </p>\n";
// echo "usage: php parse-records.php infile=filename.ext \n";
die( "<p>Error: missing command line argument </p>\n" );
// die( "Error: missing command line argument \n" );
}
//PrintArray( $HTTP_GET_VARS );
//PrintArray( $argv );
//PrintFile( "$indir/$infile" );
//echo "<p>The Output </p>\n";
$infp = fopen( "$indir/$infile", "r" );
if ( !$infp ) {
die( "<p> Error: Unable to open file for read access. </p>\n" );
}
//$link = mysql_connect( $hostname, $user, $password ) or die( "Connect Failed: " . mysql_error() );
//mysql_select_db( $dbname );
//mysql_set_charset('utf8');
?>
<div align="left">
<pre>
<?php
$count = 0;
$i = 1;
//($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
//$mon++;
//printf "%02d-%02d-%02d", $mday, $mon, $year;
//echo " \n";
//while ( !feof( $infp ) && $i <= 10 ) {
//while ( !feof( $infp ) && $i <= 400 ) {
while ( !feof( $infp ) && $i <= 1000000 ) {
$line = fgets( $infp, 1024 );
// echo "$i: ";
// echo "\\count $count\n";
// $line = ereg_replace( "To", "Tooo" , $line );
$line = trim( $line );
$line = ereg_replace( "\r\n$", "", $line );
$line = ereg_replace( "\n$", "", $line );
// echo "\\line $line\n";
// echo $line;
// echo "$i: \"$line\"\n";
// echo "\n";
// echo "$i: \n";
$temp = substr( $line, 0, 99 );
$wd = rtrim( $temp );
$temp = substr( $line, 100, 199 );
$mn = rtrim( $temp );
$mn = ltrim( $mn );
$mn = str_replace( "'", "\\'", $mn );
// $temp = substr( $line, 28, 24 );
// $fn = rtrim( $temp );
// $fn = ltrim( $fn );
// $fn = str_replace( "'", "\\'", $fn );
// $temp = substr( $line, 52, 32 );
// $add = rtrim( $temp );
// $temp = substr( $line, 84, 20 );
// $ct = rtrim( $temp );
// $temp = substr( $line, 104, 2 );
// $st = rtrim( $temp );
// $temp = substr( $line, 106, 10 );
// $zip = rtrim( $temp );
// $temp = substr( $line, 116, 1 );
// $fl = rtrim( $temp );
//echo( "word = \"$wd\"\n" );
//echo( "meaning = \"$mn\"\n" );
// echo( "firstname = \"$fn\"\n" );
// echo( "address = \"$add\"\n" );
// echo( "city = \"$ct\"\n" );
// echo( "state = \"$st\"\n" );
// echo( "zipcode = \"$zip\"\n" );
// echo( "status = \"$fl\"\n" );
if ( 0 ) {
$sql = "SELECT * FROM $tablename WHERE ( contactid = '$id' AND lastname = '$ln' )";
$result = mysql_query( $sql )
or die( "Select Failed, sql = '$sql'" . mysql_error() );
$numrecs = mysql_numrows( $result );
$recs = $numrecs;
echo "SQL: \"$sql\"\n";
if ( !($numrecs) ) {
echo( "No Matches Found \n" );
}
else {
echo( "$numrecs Record(s) Found \n" );
}
$counter = 0;
while ( $counter < $recs ) {
$row = mysql_fetch_array( $result );
echo( "wid = \"" );
echo( $row['wid'] );
echo( "\"\n" );
echo( "meaning = \"" );
echo( $row['meaning'] );
echo( "\"\n" );
echo( "firstname = \"" );
echo( $row['firstname'] );
echo( "\"\n" );
echo( "address = \"" );
echo( $row['address'] );
echo( "\"\n" );
echo( "city = \"" );
echo( $row['city'] );
echo( "\"\n" );
echo( "state = \"" );
echo( $row['state'] );
echo( "\"\n" );
echo( "zipcode = \"" );
echo( $row['zipcode'] );
echo( "\"\n" );
echo( "status = \"" );
echo( $row['flag'] );
echo( "\"\n" );
$counter++;
}
}
// $sql = "UPDATE $tablename SET firstname='$fn', address = '$add', city = '$ct', state = '$st', zipcode = '$zip' WHERE ( contactid = '$id' AND lastname LIKE '$ln%' )";
$sql = "INSERT $tablename ( word, written, meaning, language, level ) VALUES ( '$wd', '$wd', '$mn', 'arabic', $level );";
// $result = mysql_query( $sql )
// or die( "Update Failed, sql = '$sql'" . mysql_error() );
// echo "SQL: \"$sql\"\n";
echo "$sql\r\n";
$count += 1;
if ( 0 ) {
if ( $result ) {
$numrows = mysql_affected_rows();
printf( "Updated records: %d\n", $numrows );
if ( $numrows > 0 ) {
$count += $numrows;
}
}
else {
echo( "Update Failed: " . mysql_error() );
}
}
if ( feof( $infp ) ) {
break;
}
$i++;
}
//echo "\n\n";
?>
</pre>
</div>
<?php
print "\n";
printf( "<p>Total updated records: %d </p>\n", $count );
//mysql_close( $link );
fclose( $infp );
PrintHtmlBottom();
?>