<?php

$siteId = 20;
$prefix = 'svjf';
$navArray = array(7, 8, 10, 11);
$newArray = array('Spielberichte', 'Tabelle', 'Mannschaft', 'Aktuelles', 'Training');

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');

foreach ($navArray as $navStart)
{
	$i = 1;
	foreach ($newArray 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;
}