#!/Applications/MAMP/bin/php5/bin/php 1 ) { $currentUser = explode($fh_delim, $userLine); $usercount++; $reasonRejected = 'InactiveOnImport'; // Make sure all fields are present. Pad if necessary to account for no address for($i = count($currentUser); $i < 27; $i++) { $currentUser[] = ''; } $currentUser[] = 'United States'; //Append the country to the array. // Check for duplicate (conversion query may produce a few due to addresses) if ( $currentUserId == $currentUser[0] ) { $duplicateUserCount++; // Make inactive $currentUser[19] = 0; $reasonRejected = 'Duplicate'; } $currentUserId = $currentUser[0]; // Clean up spaces in emails and names. Some emails ending in comma $currentUser[1] = trim($currentUser[1]); $currentUser[2] = trim($currentUser[2]); $currentUser[3] = trim($currentUser[3]); if ( substr($currentUser[1], strlen($currentUser[1]) - 1, 1) == "," ) { $currentUser[1] = substr($currentUser[1], 0, strlen($currentUser[1]) - 1); } // See if the user is on the suppression list and add the flag. if ( array_key_exists($currentUser[1], $allUserSuppressions) ) { $currentUser[] = 1; } else { $currentUser[] = 0; } // Check the bounce count and make the user inactive if it is above 300 if ( $currentUser[18] > 300 && $currentUser[19] == 1 ) { $currentUser[19] = 0; $reasonRejected = 'HighBounceCount'; } // Check the email and make the user inactive if it is invalid if ( $currentUser[19] == 1 ) { if ( !is_valid_email_address($currentUser[1]) ) { $currentUser[19] = 0; $reasonRejected = 'BadEmail'; } } if ( $currentUser[19] == 1 ) { $activeUserCount++; $currentUser[] = ''; // Write the csv file for later review if needed. fputcsv($fh_activeUsers, $currentUser); // Insert the user into the database. $dbUserId = $currentUser[0] + 100; // Adding 100 to all the imported user id numbers db_query("INSERT INTO {users} (uid, name, pass, mail, created, status, init, login, theme, signature, language, picture) VALUES (%d, '%s', '%s', '%s', %d, %d, '%s', %d, '%s', '%s', '%s', '%s')", $dbUserId, $dbUserId, md5($currentUser[7]), $currentUser[1], strtotime($currentUser[10]), 1, $currentUser[1], strtotime($currentUser[8]), "", "", "", ""); // Insert all the profile field values db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", 1, $dbUserId, $currentUser[2]); db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", 2, $dbUserId, $currentUser[3]); db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", 25, $dbUserId, $currentUser[4]); db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", 5, $dbUserId, $currentUser[22]); db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", 6, $dbUserId, $currentUser[23]); db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", 7, $dbUserId, $currentUser[24]); db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", 23, $dbUserId, $currentUser[27]); db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", 9, $dbUserId, $currentUser[26]); db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", 10, $dbUserId, $currentUser[15]); db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", 11, $dbUserId, $currentUser[16]); db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", 13, $dbUserId, $currentUser[13]); db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", 14, $dbUserId, $currentUser[14]); db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", 17, $dbUserId, $currentUser[21]); db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", 19, $dbUserId, $currentUser[17]); db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", 20, $dbUserId, $currentUser[12]); //db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", 22, $dbUserId, $currentUser[]); // Province db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", 21, $dbUserId, $currentUser[5]); db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", 24, $dbUserId, $currentUser[25]); db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", 15, $dbUserId, $currentUser[28]); } else { // Write inactive records to a separate file. $currentUser[] = $reasonRejected; fputcsv($fh_inactiveUsers, $currentUser); } } } fclose($fh_usersIn) or die("Unable to close users: $php_errormsg\n"); fclose($fh_activeUsers) or die("Unable to close active users file: $php_errormsg\n"); fclose($fh_inactiveUsers) or die("Unable to close in-active users file: $php_errormsg\n"); // Write the sequence value for the user id last used. db_query("UPDATE {sequences} SET id = %d WHERE name = '%s'", $currentUserId + 100, "users_uid"); echo "\nUsers Processed: " . $usercount; echo "\nDuplicates Found: " . $duplicateUserCount; $inActiveUserCount = $usercount - $activeUserCount; echo "\nInActive Users: " . $inActiveUserCount; echo "\nActive Users: " . $activeUserCount; echo "\n\nDone\n"; function is_valid_email_address($email) { $qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]'; $dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]'; $atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'. '\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+'; $quoted_pair = '\\x5c[\\x00-\\x7f]'; $domain_literal = "\\x5b($dtext|$quoted_pair)*\\x5d"; $quoted_string = "\\x22($qtext|$quoted_pair)*\\x22"; $domain_ref = $atom; $sub_domain = "($domain_ref|$domain_literal)"; $word = "($atom|$quoted_string)"; $domain = "$sub_domain(\\x2e$sub_domain)*"; $local_part = "$word(\\x2e$word)*"; $addr_spec = "$local_part\\x40$domain"; return preg_match("!^$addr_spec$!", $email) ? 1 : 0; } ?>