<?php

// get items
$sql = "SELECT id, number FROM items";
$result = $this->db->query($sql);
$items = array();
while ($obj = $result->fetch_object()) {
	$items[$obj->number] = $obj->id;
}

$row = 0;
if (($handle = fopen(ROOT_DIR.'tmp/import/'.basename($_FILES['Filedata']['name']), "r")) !== FALSE) {
	while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
		$row++;
		if ($row != 1) {
			if (strlen($data[0]) == 5) {
				$data[0] = '0'.$data[0];
			} else if (strlen($data[0]) == 4) {
				$data[0] = '00'.$data[0];
			} else if (strlen($data[0]) == 3) {
				$data[0] = '000'.$data[0];
			} else if (strlen($data[0]) == 2) {
				$data[0] = '0000'.$data[0];
			}

			if (isset($items[$data[0]])) {
				$item_id = $items[$data[0]];

				// endkunde
				$sql1 = "UPDATE item_prices SET price_1='".str_replace(',','.',$data[4])."' WHERE customergroup_id=1 AND item_id=".$item_id;
				$this->db->query($sql1);
				if ($this->db->error) {
					$log_object->info('Error in /core/import_class', $this->db->error.', sql:'.$sql1);
				}

				// haendler
				$sql2 = "UPDATE item_prices SET price_1='".str_replace(',','.',$data[1])."', quantity_2=3, price_2='".str_replace(',','.',$data[2])."', quantity_3=100, price_3='".str_replace(',','.',$data[3])."' WHERE customergroup_id=101 AND item_id=".$item_id;
				$this->db->query($sql2);
				if ($this->db->error) {
					$log_object->info('Error in /core/import_class', $this->db->error.', sql:'.$sql2);
				}
			} else {
				$log_object->info('Import prices','Item with number '.$data[0].' not found!');
			}
		}
	}
	fclose($handle);
}

?>