function importSBAtableData() { global $db, $resultMmessage, $failed; require DIR_WS_CLASSES . 'products_with_attributes_stock.php'; $stock = new products_with_attributes_stock(); //new object from class $separater = ','; //set the list separation character ',' to whatever is needed. $separater2 = ';'; //set the list separation character ';' to whatever is needed. $SBAtableReport = DIR_FS_BACKUP . 'tableSBAdata.csv'; //path 'backups/' and filename 'tableSBAdata' for export $stockResult = null; $qtyResult = null; $ReportFile = null; $customid = null; //Use these settings only if needed. //ini_set('memory_limit','96M'); //Increase only if you are having a memory low issue, then change back when done //ini_set('max_execution_time','0'); //If set to zero, no time limit is imposed, remove when done //ini_set('max_input_time','0'); //If set to zero, no time limit is imposed, remove when done if (checkSBAtable(TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK)) { $ReportFile = file($SBAtableReport); //get file data } else { array_push($resultMmessage, 'FAILED table products_with_attributes_stock not found!'); $failed = true; } /* Only update the QTY and Custom ID fields * checks input file data prior to loading to database, only numeric is allowed for QTY */ if ($ReportFile) { $i = -1; //Count; adjust for skipping first line in file foreach ($ReportFile as $line_num => $line) { //skip line 0 as it is the header row if ($line_num > 0) { //decide what separater was used i.e., a comma or a semicolon //some programs save the CSV with a comma, others use a semicolon if (count(explode($separater, $line)) == 10) { $line = explode($separater, $line); } elseif (count(explode($separater2, $line)) == 10) { $line = explode($separater2, $line); } else { $line = null; } //checks done on the input data prior to loading to database $stockResult = doubleval(trim($line[0])); $qtyResult = doubleval(trim($line[7])); $customid = trim($line[9]); $customid = str_replace('"', '', $customid); } $i++; //increment count if (!empty($stockResult) && $qtyResult >= 0) { $saveResult = $stock->updateAttribQty($stockResult, $qtyResult); if ($saveResult != 1 && $line_num > 0 || !is_numeric($line[0]) && $line_num > 0 || !is_numeric($line[7]) && $line_num > 0) { $failed = true; array_push($resultMmessage, 'FAILURE during save Qty process! stock_id: ' . $i . ' Bad Quantity value, error:' . $saveResult); //report any line error } } if (!empty($stockResult) && !empty($customid)) { $saveResult = $stock->updateCustomIDAttrib($stockResult, $customid); //echo "Stock ID: $stockResult Custom ID: $customid <br />";//Debug Line, comment this out to remove from displaying on web page if ($saveResult != 1 && $line_num > 0 || !is_numeric($line[0]) && $line_num > 0) { $failed = true; array_push($resultMmessage, 'FAILURE during save Custom ID process! Record: ' . $i . ' error:' . $saveResult); //report any line error } } } array_push($resultMmessage, 'Updated ' . $i . ' Quantities from: ' . $SBAtableReport); } else { array_push($resultMmessage, 'Update FAILED no file found!'); $failed = true; } return; }