<?php
function smarty_function_create_match($creatematch)
{
	$sql = "SELECT im.navisionid,im.id,im.vertreiber,im.bestellcode,i.attribute_7,i.number,i.krempl_id FROM krempl_passendwie im INNER JOIN items i ON i.attribute_7 = im.navisionid WHERE im.navisionid = ".$this->id;
	$result = $this->db->query($sql);
	while ($row = $result->fetch_object()) {
		$obj->match[] = $row;
	}

	if ($obj->krempl_id) {
	$sql = "SELECT im.navisionid,im.id,im.vertreiber,im.bestellcode,i.attribute_7,i.number,i.krempl_id FROM krempl_passendwie im INNER JOIN items i ON i.attribute_7 = im.navisionid WHERE im.id = ".$this->db->real_escape_string($obj->krempl_id);
		$result = $this->db->query($sql);
	}
}


function smarty_function_load_match($html2, &$smarty)
{
	$result = smarty_function_create_match($html2['creatematch']);
	$smarty->assign($html2['assign'], $result);
}

$html2 = "";
foreach ($obj->match as $m) {
	$html2 .= '<div id="itemMatch"><strong>'.$m->vertreiber.'</strong><br>'.$m->bestellcode.'</div>';
}

/*var_dump($html2);
$obj->geraetematch = $html2; */

/*$table_data = array();
foreach ($obj->geraetematch as $geraet) {
	$nr1 = str_replace('#', '', $geraet->nr);
	$nr1 = str_replace('_', ' ', $nr1);
	$nr2 = str_replace('#', '', $geraet->vertreiber);
	$nr2 = str_replace('_', ' ', $nr2);
	$nr3 = str_replace('#', '', $geraet->bestellcode);
	$nr3 = str_replace('_', ' ', $nr3);

	//$table_data[$einkaufsmoeglichkeitencached][$bezeichnungoriginal][] = array($nr1, $nr2,$nr3);
}
//$html = '<table border="0" cellpadding="2" cellspacing="0">';
foreach ($table_data as $key => $marken) {
	$y = 0;
	$html .= '<tr class="intelectra_item_table_header"><td colspan="3"><h4><b>'.$obj->name.' passend zu '.$key.' '.$parent_warengruppe.'</b></h4></tr>';
	$html .= '<tr class="intelectra_item_table_header"><td>Ger&auml;te-/Modellbezeichnung</td><td>E-, Service-, Produktions- oder Hauptnummer</td><td>Zusatz-, F- oder Seriennummer oder Fertigungsdatum</td></tr>';
	foreach ($marken as $geraet => $nummern) {
		$color = 'intelectra_table_row1';
		if ($y % 2 == 1) {
			$color = 'intelectra_table_row2';
		}
		$z = 0;
		foreach ($nummern as $nummer) {
			if ($z == 0) {
				$html .= '<tr class="'.$color.'"><td>'.$geraet.'</td><td>'.$nummer[0].'</td><td>'.$nummer[1].''.$nummer[2].'</td></tr>';
			} else {
				$html .= '<tr class="'.$color.'"><td>&nbsp;</td><td>'.$nummer[0].'</td><td>'.$nummer[1].''.$nummer[2].'</td></tr>';
			}
			$z++;
		}
		$y++;
	}
}*/
//$html .= '</table>';
