<?php

$siteId = 20;
$prefix = 'svjf';
$navArray = array(13 => array('A SGM Mähringen/Jungingen/Lehr', 'B SGM Jungingen/Lehr/Mähringen', 'C SGM Lehr/Jungingen/Mähringen', 'D1/2 SVJ Jg. 2001/2002', 'E1/2 SVJ Jg. 2003', 'E3/4 SVJ Jg. 2004', 'F1 SVJ Jg. 2005', 'F2/3 SVJ Jg. 2006', 'Bambini SG Lehr/Mähringen ab 2007', 'Bambini SV Jungingen ab 2007'), 14 => array('B SV Jungingen Jg. 1997/1998', 'D SV Jungingen Jg. 2001/02', 'E SV Jungingen bis Jg. 2003'));
define('PATH_ROOT', '../');
include_once(PATH_ROOT . '.config/config_global.php');
$db = new mysqli (DB_HOST, DB_USER, DB_PASS, DB_NAME);
$db->set_charset('utf8');

$i = 1;
foreach ($navArray as $navStart => $navArray)
{
	foreach ($navArray as $navName)
	{
		$navLink = createLinkFromName($navName);
		$insert = $db->query('INSERT INTO ' . $prefix . '_navi VALUES ( NULL , "' . $navStart . '" , "' . $navName . '" , "" , "' . $navLink . '" , "Y" , "' . $i . '" , "N" , NULL );');
		$navId = $db->insert_id;
		$update = $db->query('UPDATE svjf_navi SET svjf_navTarget = "index.php?siteId=' . $siteId . '&navId=' . $navId . '" WHERE svjf_navId = "' . $navId . '";');

		++$i;
	}
}

function createLinkFromName($name)
{
	$search = array('ä', 'ö', 'ü', '.', ' ');
	$replace = array('ae', 'oe', 'ue', '', '_');

	$newName = mb_strtolower($name, 'UTF-8');
	$link = str_replace($search, $replace, $newName);

	return $link;
}