<?php

$saison = array('start' => 2011, 'end' => 2012);
$bereich = 'Frauen';
$nummer = '1';
$newNavStart = '277';
$siteId = '20';


$startDate = $saison['start'] . '-08-01';
$endDate = $saison['end'] . '-07-31';

define('PATH_ROOT', '../');
include_once(PATH_ROOT . '.config/config_global.php');
include_once(PATH_FNC . 'fnc_portal.php');

$db = new mysqli (DB_HOST, DB_USER, DB_PASS, DB_NAME);
$db->set_charset('utf8');

$berichte = $db->query('SELECT * FROM berichte WHERE Datum >= "' . $startDate . '" AND Datum <= "' . $endDate . '" AND Bereich = "' . $bereich . '" AND Nummer = "' . $nummer . '" ORDER BY Datum DESC;');
$count = $berichte->num_rows;
$i = 0;

while ($bericht = $berichte->fetch_assoc())
{
	foreach ($bericht as $key => $value)
	{
		$bericht[$key] = $db->real_escape_string($value);
	}
	$insert = $db->query('INSERT INTO svjf_navi VALUES ( NULL , "' . $newNavStart . '" , "' . ($count - $i) . '. Spieltag" , "" , "spieltag_' . ($count - $i) . '" , "Y" , "' . ($i + 1) . '" , "Y" , "spielbericht" );');
	$navId = $db->insert_id;
	$update = $db->query('UPDATE svjf_navi SET svjf_navTarget = "index.php?siteId=' . $siteId . '&navId=' . $navId . '" WHERE svjf_navId = "' . $navId . '";');
	$insert = $db->query('INSERT INTO svjf_spielbericht VALUES ( "' . $navId . '" , "' . $bericht['Head'] . '" , "' . $bericht['Heim'] . '" , "' . $bericht['ErgH'] . '" , "' . $bericht['ErgG'] . '" , "' . $bericht['HalbH'] . '" , "' . $bericht['HalbG'] . '" , "' . $bericht['Gegner'] . '" , "' . $bericht['Text'] . '" , "' . $bericht['Bild'] . '" , "' . $bericht['Spieler'] . '" , "' . $bericht['Tore'] . '" , "' . $bericht['Besonderes'] . '" , "' . $bericht['Vorschau'] . '" , "' . $bericht['Datum'] . '" );');

	$i++;
}