Advertisement
Guest User

Untitled

a guest
Jun 8th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.91 KB | None | 0 0
  1. <?php
  2. /* Shelby Scates 02/23/2012 */
  3.  
  4.  
  5. /* MySQL Config */
  6. $username = "faithconsignment";
  7. $password = "Fai!Con12";
  8. $database = "faith";
  9. $host = "localhost";
  10.  
  11. /* Debug Config */
  12. ini_set('max_execution_time', 1800);
  13.  
  14.  
  15.  
  16. function updateStatus($status) {
  17. session_start();
  18. $_SESSION['status'] = $status;
  19. session_write_close();
  20. }
  21.  
  22. if($_GET['a'] == "import_users") {
  23. if(file_exists($_FILES['user_file']['tmp_name'])) {
  24. $filename = $_FILES['user_file']['name'];
  25. move_uploaded_file($_FILES['user_file']['tmp_name'], "./if/" . $filename);
  26. updateStatus($filename . " Uploaded");
  27. sleep(2);
  28. }
  29. else { updateStatus("Error: No File Uploaded"); die(); }
  30.  
  31. mysql_connect($host, $username, $password) or die("<h1>Failed to establish database connection</h1>");
  32. $crows = mysql_num_rows(mysql_query("SELECT * FROM faith.users"));
  33.  
  34. updateStatus("Processing File...");
  35. $handle = file_get_contents("./if/$filename");
  36. $handle = explode("\n", $handle);
  37. $rows = count($handle);
  38.  
  39. $errors = 0;
  40. $errorstring = "";
  41. $x = 0;
  42. $rows = $rows-1;
  43. while($x < $rows) {
  44. $handle[$x] = explode(",", $handle[$x]);
  45. $full_name = str_replace("\"", '', $handle[$x][1] . " " . $handle[$x][2]);
  46. $consigner_id = $handle[$x][0];
  47. $consigner_pass = hash('md5', str_replace("\"", '', $handle[$x][3]));
  48. $consigner_sc = str_replace("\"", '', $handle[$x][4]);
  49.  
  50. /* Data consistency check */
  51. if($full_name && $consigner_id && $consigner_pass && $consigner_sc && is_numeric($consigner_id) && strlen($consigner_pass) == 32) {
  52. if(mysql_num_rows(mysql_query("SELECT * FROM faith.users WHERE cid = '$consigner_id'"))) {
  53. mysql_query("UPDATE faith.users SET name = '$full_name', pass = '$consigner_pass', security_key = '$consigner_sc' WHERE cid = '$consigner_id'");
  54. }
  55. else {
  56. 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', '', '')");
  57. }
  58. }
  59. else {
  60. $errors++;
  61. $en = $x+1;
  62. $errorstring .= "Line $en was skipped due to a data inconsistency. Please check manually.<br/>";
  63.  
  64. }
  65. $percent_complete = round($x/$rows * 100, 1);
  66. updateStatus("Updating Tables..." . $percent_complete . "% Complete");
  67. $x++;
  68. }
  69. $rs = "<span style='cursor:pointer; color:#ff0000;' id='revealerrors'>" . $errors . " errors</span><p id='errors'>" . $errorstring . "</p>";
  70. updateStatus("User Import Complete - " . $rs);
  71.  
  72. }
  73.  
  74. elseif($_GET['a'] == "import_sold") {
  75. if(file_exists($_FILES['sold_file']['tmp_name'])) {
  76. $filename = $_FILES['sold_file']['name'];
  77. move_uploaded_file($_FILES['sold_file']['tmp_name'], "./if/" . $filename);
  78. updateStatus($filename . " Uploaded");
  79. sleep(2);
  80. }
  81. else { updateStatus("Error: No File Uploaded"); die(); }
  82. mysql_connect($host, $username, $password) or die("<h1>Failed to establish database connection</h1>");
  83. $crows = mysql_num_rows(mysql_query("SELECT * FROM faith.users"));
  84.  
  85. updateStatus("Processing File...");
  86. $handle = file_get_contents("./if/$filename");
  87. $handle = explode("\n", $handle);
  88. $rows = count($handle);
  89. if($_POST['tts'] == "yes") {
  90. mysql_query("TRUNCATE TABLE faith.items_sold");
  91. }
  92. mysql_connect($host, $username, $password) or die("<h1>Failed to establish database connection</h1>");
  93. $errors = 0;
  94. $errorstring = "";
  95. $x = 0;
  96. $rows--;
  97. while($x < $rows) {
  98. $handle[$x] = str_replace("\"", '', explode(",", $handle[$x]));
  99. $username = $handle[$x][0];
  100. $name = $handle[$x][1] . " " . $handle[$x][3];
  101. $cid = $handle[$x][4];
  102. $itemnumber = $handle[$x][5];
  103. $itemdesc = $handle[$x][7];
  104. $size = $handle[$x][8];
  105. $price = $handle[$x][9];
  106. $consamt = $handle[$x][10];
  107. $sale = $handle[$x][11];
  108. $date_purchased = $handle[$x][12];
  109.  
  110. /* Data consistency check */
  111. if($username && $name && $cid && $itemnumber && is_numeric($cid) && is_numeric($itemnumber)) {
  112. 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')");
  113. }
  114.  
  115.  
  116. else {
  117. $errors++;
  118. $en = $x+1;
  119. $errorstring .= "Line $en was skipped due to a data inconsistency. Please check manually.<br/>";
  120.  
  121. }
  122. $percent_complete = round($x/$rows * 100, 1);
  123. updateStatus("Updating Tables..." . $percent_complete . "% Complete");
  124. $x++;
  125. }
  126. $rs = "<span style='cursor:pointer; color:#ff0000;' id='revealerrors'>" . $errors . " errors</span><p id='errors'>" . $errorstring . "</p>";
  127. updateStatus("Sold Items Import Complete - " . $rs);
  128. }
  129.  
  130.  
  131.  
  132. elseif($_GET['a'] == "not_sold") {
  133. if(file_exists($_FILES['not_sold_file']['tmp_name'])) {
  134. $filename = $_FILES['not_sold_file']['name'];
  135. move_uploaded_file($_FILES['not_sold_file']['tmp_name'], "./if/" . $filename);
  136. updateStatus($filename . " Uploaded");
  137. sleep(2);
  138. }
  139. else { updateStatus("Error: No File Uploaded"); die(); }
  140. mysql_connect($host, $username, $password) or die("<h1>Failed to establish database connection</h1>");
  141. $crows = mysql_num_rows(mysql_query("SELECT * FROM faith.users"));
  142.  
  143. updateStatus("Processing File...");
  144. $handle = file_get_contents("./if/$filename");
  145. $handle = explode("\n", $handle);
  146. $rows = count($handle);
  147. mysql_connect($host, $username, $password) or die("<h1>Failed to establish database connection</h1>");
  148. if($_POST['tt'] == "yes") {
  149. mysql_query("TRUNCATE TABLE faith.items_not_sold");
  150. }
  151.  
  152. $errors = 0;
  153. $errorstring = "";
  154. $x = 0;
  155. $rows--;
  156. while($x < $rows) {
  157. $handle[$x] = explode(",", $handle[$x]);
  158. $cid = $handle[$x][0];
  159. $pid = $handle[$x][1];
  160. $itemdesc = str_replace("\"", '', $handle[$x][2]);
  161. $size = str_replace("\"", '', $handle[$x][3]);
  162. $price = $handle[$x][4];
  163. $cons = $handle[$x][5];
  164. $date_consigned = $handle[$x][6];
  165.  
  166. /* Data consistency check */
  167. if($cid && $pid && is_numeric($cid) && is_numeric($pid)) {
  168. if(!mysql_num_rows(mysql_query("SELECT * FROM faith.items_not_sold WHERE pid = $pid"))) {
  169. 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')");
  170. }
  171. }
  172.  
  173. else {
  174. $errors++;
  175. $en = $x+1;
  176. $errorstring .= "Line $en was skipped due to a data inconsistency. Please check manually.<br/>";
  177.  
  178. }
  179. $percent_complete = round($x/$rows * 100, 1);
  180. updateStatus("Updating Tables..." . $percent_complete . "% Complete");
  181. $x++;
  182. }
  183. $rs = "<span style='cursor:pointer; color:#ff0000;' id='revealerrors'>" . $errors . " errors</span><p id='errors'>" . $errorstring . "</p>";
  184. updateStatus("Not Sold Items Import Complete - " . $rs);
  185. }
  186.  
  187. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement