Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* Shelby Scates 02/23/2012 */
- /* MySQL Config */
- $username = "faithconsignment";
- $password = "Fai!Con12";
- $database = "faith";
- $host = "localhost";
- /* Debug Config */
- ini_set('max_execution_time', 1800);
- function updateStatus($status) {
- session_start();
- $_SESSION['status'] = $status;
- session_write_close();
- }
- if($_GET['a'] == "import_users") {
- if(file_exists($_FILES['user_file']['tmp_name'])) {
- $filename = $_FILES['user_file']['name'];
- move_uploaded_file($_FILES['user_file']['tmp_name'], "./if/" . $filename);
- updateStatus($filename . " Uploaded");
- sleep(2);
- }
- else { updateStatus("Error: No File Uploaded"); die(); }
- mysql_connect($host, $username, $password) or die("<h1>Failed to establish database connection</h1>");
- $crows = mysql_num_rows(mysql_query("SELECT * FROM faith.users"));
- updateStatus("Processing File...");
- $handle = file_get_contents("./if/$filename");
- $handle = explode("\n", $handle);
- $rows = count($handle);
- $errors = 0;
- $errorstring = "";
- $x = 0;
- $rows = $rows-1;
- while($x < $rows) {
- $handle[$x] = explode(",", $handle[$x]);
- $full_name = str_replace("\"", '', $handle[$x][1] . " " . $handle[$x][2]);
- $consigner_id = $handle[$x][0];
- $consigner_pass = hash('md5', str_replace("\"", '', $handle[$x][3]));
- $consigner_sc = str_replace("\"", '', $handle[$x][4]);
- /* Data consistency check */
- if($full_name && $consigner_id && $consigner_pass && $consigner_sc && is_numeric($consigner_id) && strlen($consigner_pass) == 32) {
- if(mysql_num_rows(mysql_query("SELECT * FROM faith.users WHERE cid = '$consigner_id'"))) {
- mysql_query("UPDATE faith.users SET name = '$full_name', pass = '$consigner_pass', security_key = '$consigner_sc' WHERE cid = '$consigner_id'");
- }
- else {
- mysql_query("INSERT INTO faith.users(`id`,`cid`,`name`,`pass`,`email`,`security_key`,`ip`,`dt`) VALUES (null, '$consigner_id', '$full_name', '$consigner_pass', '', '$consigner_sc', '', '')");
- }
- }
- else {
- $errors++;
- $en = $x+1;
- $errorstring .= "Line $en was skipped due to a data inconsistency. Please check manually.<br/>";
- }
- $percent_complete = round($x/$rows * 100, 1);
- updateStatus("Updating Tables..." . $percent_complete . "% Complete");
- $x++;
- }
- $rs = "<span style='cursor:pointer; color:#ff0000;' id='revealerrors'>" . $errors . " errors</span><p id='errors'>" . $errorstring . "</p>";
- updateStatus("User Import Complete - " . $rs);
- }
- elseif($_GET['a'] == "import_sold") {
- if(file_exists($_FILES['sold_file']['tmp_name'])) {
- $filename = $_FILES['sold_file']['name'];
- move_uploaded_file($_FILES['sold_file']['tmp_name'], "./if/" . $filename);
- updateStatus($filename . " Uploaded");
- sleep(2);
- }
- else { updateStatus("Error: No File Uploaded"); die(); }
- mysql_connect($host, $username, $password) or die("<h1>Failed to establish database connection</h1>");
- $crows = mysql_num_rows(mysql_query("SELECT * FROM faith.users"));
- updateStatus("Processing File...");
- $handle = file_get_contents("./if/$filename");
- $handle = explode("\n", $handle);
- $rows = count($handle);
- if($_POST['tts'] == "yes") {
- mysql_query("TRUNCATE TABLE faith.items_sold");
- }
- mysql_connect($host, $username, $password) or die("<h1>Failed to establish database connection</h1>");
- $errors = 0;
- $errorstring = "";
- $x = 0;
- $rows--;
- while($x < $rows) {
- $handle[$x] = str_replace("\"", '', explode(",", $handle[$x]));
- $username = $handle[$x][0];
- $name = $handle[$x][1] . " " . $handle[$x][3];
- $cid = $handle[$x][4];
- $itemnumber = $handle[$x][5];
- $itemdesc = $handle[$x][7];
- $size = $handle[$x][8];
- $price = $handle[$x][9];
- $consamt = $handle[$x][10];
- $sale = $handle[$x][11];
- $date_purchased = $handle[$x][12];
- /* Data consistency check */
- if($username && $name && $cid && $itemnumber && is_numeric($cid) && is_numeric($itemnumber)) {
- mysql_query("INSERT INTO faith.items_sold(`id`, `username`, `name`, `cid`, `item_number`, `bought_on`, `itemdesc`, `size`, `price`, `cons`, `od`) VALUES (null, '$username', '$name', '$cid', '$itemnumber', '$date_purchased', '$itemdesc', '$size', '$price', '$consamt', 'null')");
- }
- else {
- $errors++;
- $en = $x+1;
- $errorstring .= "Line $en was skipped due to a data inconsistency. Please check manually.<br/>";
- }
- $percent_complete = round($x/$rows * 100, 1);
- updateStatus("Updating Tables..." . $percent_complete . "% Complete");
- $x++;
- }
- $rs = "<span style='cursor:pointer; color:#ff0000;' id='revealerrors'>" . $errors . " errors</span><p id='errors'>" . $errorstring . "</p>";
- updateStatus("Sold Items Import Complete - " . $rs);
- }
- elseif($_GET['a'] == "not_sold") {
- if(file_exists($_FILES['not_sold_file']['tmp_name'])) {
- $filename = $_FILES['not_sold_file']['name'];
- move_uploaded_file($_FILES['not_sold_file']['tmp_name'], "./if/" . $filename);
- updateStatus($filename . " Uploaded");
- sleep(2);
- }
- else { updateStatus("Error: No File Uploaded"); die(); }
- mysql_connect($host, $username, $password) or die("<h1>Failed to establish database connection</h1>");
- $crows = mysql_num_rows(mysql_query("SELECT * FROM faith.users"));
- updateStatus("Processing File...");
- $handle = file_get_contents("./if/$filename");
- $handle = explode("\n", $handle);
- $rows = count($handle);
- mysql_connect($host, $username, $password) or die("<h1>Failed to establish database connection</h1>");
- if($_POST['tt'] == "yes") {
- mysql_query("TRUNCATE TABLE faith.items_not_sold");
- }
- $errors = 0;
- $errorstring = "";
- $x = 0;
- $rows--;
- while($x < $rows) {
- $handle[$x] = explode(",", $handle[$x]);
- $cid = $handle[$x][0];
- $pid = $handle[$x][1];
- $itemdesc = str_replace("\"", '', $handle[$x][2]);
- $size = str_replace("\"", '', $handle[$x][3]);
- $price = $handle[$x][4];
- $cons = $handle[$x][5];
- $date_consigned = $handle[$x][6];
- /* Data consistency check */
- if($cid && $pid && is_numeric($cid) && is_numeric($pid)) {
- if(!mysql_num_rows(mysql_query("SELECT * FROM faith.items_not_sold WHERE pid = $pid"))) {
- mysql_query("INSERT INTO faith.items_not_sold(`id`, `cid`, `pid`, `itemdesc`, `size`, `price`, `cons`, `date_consigned`, `e`, `e2`) VALUES (null, '$cid', '$pid', '$itemdesc', '$size', '$price', '$cons', '$date_consigned', 'null', 'null')");
- }
- }
- else {
- $errors++;
- $en = $x+1;
- $errorstring .= "Line $en was skipped due to a data inconsistency. Please check manually.<br/>";
- }
- $percent_complete = round($x/$rows * 100, 1);
- updateStatus("Updating Tables..." . $percent_complete . "% Complete");
- $x++;
- }
- $rs = "<span style='cursor:pointer; color:#ff0000;' id='revealerrors'>" . $errors . " errors</span><p id='errors'>" . $errorstring . "</p>";
- updateStatus("Not Sold Items Import Complete - " . $rs);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement