Location: PHPKode > projects > EzyBiz > ezybiz/importitem.php
<? include('includes/main.php'); ?>
<? include('includes/arfunctions.php'); ?>
<? 
templatetop('Select Item File'); 
if ($file) {
  if ($file_size <= 0) die(texterrorend('Uploaded file can not be empty.'));

  $gfilename=IMAGE_UPLOAD_DIR."impitem".$file_size.".txt";
  copy($file, $gfilename);
  $fcontents = file ($gfilename);
  while (list ($line_num, $line) = each ($fcontents)) {
 
   $custarray=split(",",$line);
   $itemcode=$custarray[0];
   $categoryid=$custarray[1];
   $description=$custarray[2];
   $vendor=$custarray[3];
   $quantity=$custarray[4];
   $weight=$custarray[5];
   $householdprice=$custarray[6];
   $discount1=$custarray[7];
   $disqty1=$custarray[8];
   $discount2=$custarray[9];
   $disqty2=$custarray[10];
   $discount3=$custarray[11];
   $disqty3=$custarray[12];
   $cost1=$custarray[13];
   $costqty1=$custarray[14];
   $cost2=$custarray[15];
   $costqty2=$custarray[16];
   $cost3=$custarray[17];
   $costqty3=$custarray[18];
   $cost4=$custarray[19];
   $graphicurl=$custarray[20];
   $catalogsheeturl=$custarray[21];
   $catalogdescription=$custarray[22];
   $vendorid=$custarray[23];
   $inventorylocationid=$custarray[24];
   if ($itemcode) {

   $recordSet2=&$conn->Execute('select id from item where itemcode='.sqlprep($itemcode).'');
   $itemid=0;
   if (!$recordSet2->EOF) {
         $itemid=$recordSet2->fields[0];
		 echo "Item ".$itemcode." exists<br>";
   } 
   else {
		if ($conn->Execute('insert into item(itemcode, description, categoryid , stockunitnameid, priceunitnameid, lbsperpriceunit, priceunitsperstockunit,inventoryglacctid, salesglacctid, catalogdescription, catalogsheeturl, graphicurl, companyid, entrydate, products_quantity) values ('.sqlprep($itemcode).', '.sqlprep($description).', '.sqlprep($categoryid).', 1, 1, 1,1, 0, 0, '.sqlprep($catalogdescription).',  '.sqlprep($catalogsheeturl).', '.sqlprep($graphicurl).', '.sqlprep($active_company).', NOW(), '.sqlprep($quantity).')')) {
		
		$recordSet2=&$conn->Execute('select id from item where itemcode='.sqlprep($itemcode).'');
        if (!$recordSet2->EOF) {
         $itemid=$recordSet2->fields[0];
		
		$conn->Execute('insert into itemlocation (itemid, inventorylocationid, onhandqty, maxstocklevelseason1, minstocklevelseason1, orderqtyseason1, maxstocklevelseason2, minstocklevelseason2, orderqtyseason2, maxstocklevelseason3, minstocklevelseason3, orderqtyseason3, maxstocklevelseason4, minstocklevelseason4, orderqtyseason4, markupsetid, firstcost, midcost, lastcost, entrydate, entryuserid, lastchangeuserid) VALUES('.$itemid.', '.sqlprep($inventorylocationid).','.sqlprep($quantity).',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,NOW(),1,1 )');
		
		$conn->Execute("insert into itemvendor (vendorid,itemid,vordernumber, vitemcost1, vitemqty1, vitemcost2, vitemqty2, vitemcost3, vitemqty3, vitemcost4) values ('".$vendorid."', '".$itemid."', '".$itemcode."', '".$cost1."', '" .$costqty1."', '" .$cost2. "', '" .$costqty2."','" .$cost3. "', '" .$costqty3."', '".$cost4."')");

		$recordSet2=&$conn->Execute("select id from pricelevel where description='Household'");
        if (!$recordSet2->EOF) {
         $pricelevelid=$recordSet2->fields[0];

		$conn->Execute("insert into priceperpriceunit(itemid,itemlocationid ,pricelevelid, price, cancel, entrydate) Values ('".$itemid."' , '".$inventorylocationid."', '".$pricelevelid."' , '".$householdprice."' ,'0',NOW())");
	
			$counter = 0;
			while($counter<3){
				$counter=$counter+1;
				$conn->Execute("insert into pricediscount(itemid, itemlocationid, quantity, discount,cancel ,entrydate)values ('".$itemid."', '".$inventorylocationid."', '".${"disqty".$counter}."', '".${"discount".$counter}."','0' ,NOW())");
			}
			
		}
		
		}
  echo "\n";
  echo texttitle("Items have been imported").'<br><br>';
	}
	else{
  echo "\n";
  echo texttitle("Error importing data").'<br><br>';
    }

  };

  }
 }
} else {
    echo '<form name="mainform" method="post" action="importitem.php" enctype="multipart/form-data">';
    echo '<table><tr><td align="'.TABLE_LEFT_SIDE_ALIGN.'">URL/File for CSV Format Item File:</td><td><input name="file" type="file" '.INC_TEXTBOX.'></td></tr></table>';
    echo '<input type="submit" value="Select File"></form>';
};
templatebottom(3); 
?>
<? include('includes/footer.php'); ?>
Return current item: EzyBiz