<?php
//die();
require_once('core.php');


if(isset($_REQUEST['action'])=== false || $user->ID != 767) access_error();


$filehandler = fopen('export2.csv', 'r');

if($filehandler) {
    while(!feof($filehandler)) {
        $buffer = fgets($filehandler, 4096);
	//echo $buffer."\r\n";
        // zuerst Volk, dann Profession
	$count = strpos($buffer, ';');
	$profession = substr($buffer, 0, $count);
	$buffer = substr($buffer, $count+1);
	// im folgenden dann Herstellugnsid, dann Menge
	echo "INSERT INTO vorgefertigte_chars VALUES ($profession, ";
	//echo $buffer."\r\n";
	$a = 0;
	while(strlen($buffer)>0) {
		$count = strpos($buffer, ';');
		$wert = substr($buffer,0, $count); 
		$buffer = substr($buffer, $count+1);
		echo "$wert, ";
	}echo ", NOW(), 767)\r\n";
    } 
}
fclose($filehandler);

/*
echo "Starte Umwandlung<br />";

echo "INSERT INTO startitem_pakete VALUES ";

$filehandler = fopen('export.csv', 'r');

if($filehandler) {
    while(!feof($filehandler)) {
        $buffer = fgets($filehandler, 4096);
	//echo $buffer."\r\n";
        // zuerst Volk, dann Profession
	$count = strpos($buffer, ';');
	$volk = substr($buffer,0, $count);
	$buffer = substr($buffer, $count+1);
	$count = strpos($buffer, ';');
	$profession = substr($buffer, 0, $count);
	$buffer = substr($buffer, $count+1);
	// im folgenden dann Herstellugnsid, dann Menge
	//echo $buffer."\r\n";
	$a = 0;
	while(strlen($buffer)>0) {
		$count = strpos($buffer, ';');
		$herstid = substr($buffer,0, $count); 
		$buffer = substr($buffer, $count+1);
		$count = strpos($buffer, ';');
		$anzahl = substr($buffer, 0, $count); 
		$buffer = substr($buffer, $count+1);
		$a += $herstid+$anzahl;
		//if($anzahl > 0) echo "($volk, $profession, $herstid, $anzahl, NOW(), 767), \r\n";
	}echo $a."\r\n";
    } 
}
fclose($filehandler);
*/

/* if($_REQUEST['action'] != 'superpushing') die("f");

error_reporting(E_ALL);
echo "MM";
set_time_limit(0);
$MySQL->query("TRUNCATE TABLE server.chars_rezepte");
$chars = $MySQL->fetch_complete("SELECT charid FROM server.chars WHERE aktiviert != 9");
$rezepte = $MySQL->fetch_complete("SELECT rezeptid FROM server.rezepte WHERE rezeptid IN (7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 25, 27, 29, 30, 31, 33, 34, 35, 36, 37, 38, 42, 43, 44, 45, 46, 49, 409, 433, 436, 56, 58, 59, 60, 61, 122, 147, 153, 154, 254, 257, 287, 288, 289, 297, 298, 306, 374, 375, 393, 399, 400, 410, 49, 55, 57, 58, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 76, 77, 80, 81, 82, 83, 84, 85, 86, 87, 88, 90, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 104, 105, 106, 107, 109, 110, 111, 112, 113, 115, 118, 119, 120, 121, 129, 146, 255, 256, 254, 257, 259, 260, 262, 434, 123, 124, 132, 371, 372, 373, 377, 378, 390, 401, 408, 150, 151, 152, 349, 350, 351, 352, 370, 379, 380, 381, 376, 391, 392, 395, 398, 156, 157, 158, 165, 177, 243, 244, 245, 246, 247, 248, 283, 284, 285, 286, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 329, 330, 335, 342, 347, 373, 397, 435, 353, 354, 358, 359, 360, 361, 362, 363, 364, 365, 366, 369, 384, 387, 388, 389)");
$i=0;
foreach($chars as $citem) {
	$sql = "INSERT INTO server.chars_rezepte VALUES ";
	foreach($rezepte as $ritem) {
		$sql.= "(".$ritem['rezeptid'].",".$citem['charid'].", 0, NULL ), ";
	}
	$sql = substr($sql, 0,  strlen($sql)-2);
	
	$MySQL->query($sql);
	echo ".$i<br />"; flush();	
	$i++;
}

*/
/*
$MySQL->query("START TRANSACTION");
//$MySQL->query("DELETE FROM bb2.wbb2_access;");

$result = $MySQL->fetch_complete("SELECT * FROM server.accounts WHERE bb_userid > 0 AND `group` >= 2 AND (rank = 6 OR rank = 7 OR rank = 8)");


foreach($result as $item) {
	$access = array();
	switch( $item['group'] )
            {
            	default:
                case 0:
                	break;
                case 2:
                // HP/Grafik
                	array_push( $access, 61, 62, 125, 66, 67, 116, 117 ); break;
                case 3:
                //Weltenbau
                	array_push( $access, 58, 103, 104, 120, 121, 65, 105, 106 ); break;
                case 4:
                // Support
                	array_push( $access, 129, 132 ); break;
                case 5:
                // Quest
                	array_push( $access, 63, 127, 133, 134 ); break;
                case 6:
                // Technik
                	array_push( $access, 59, 60, 123 ); break;
                case 7:
                // Spielsystem
                	array_push( $access, 71 ); break;
                case 8:
                // Testteam
                	array_push( $access, 128 ); break;
            }
        $access = array_unique( $access );
        $i = 0;
        foreach( $access as $board )
        {
            if( $board != 0 )
            {
            	//echo "<br>".$item['name'].$item['group'].sprintf("INSERT INTO wbb2.bb2_access (boardid,userid,can_view_board,can_enter_board,can_read_thread,can_use_search) VALUES (%d,%d,1,1,1,1)", $board, $item['bb_userid'] );
            	$MySQL->query( sprintf("INSERT INTO wbb2.bb2_access (boardid,userid,can_view_board,can_enter_board,can_read_thread,can_use_search) VALUES (%d,%d,1,1,1,1)", $board, $item['bb_userid'] ));
        		$i++;
            }
        }

       	$MySQL->query( sprintf("UPDATE wbb2.bb2_users SET useuseraccess = ".( ( $i > 0 ) ? '1' : '0' )." WHERE userid = %d", $item['bb_userid'] ));
}


echo "FINITO";
*/
// ASKAIANS UNTERBROCHENE HERSTELLUNGSKETTEN
/*
$result = $MySQL->fetch_complete("SELECT her_herstellungsid, ressourcen, name_interface FROM item_interface.herstellung WHERE freigeschalten = 1");
echo "MM";
$length = count($result);
for($i=0;$i<$length;$i++) {
	$result1[$result[$i]['her_herstellungsid']] = $result[$i];
}
unset($result);

$result = $MySQL->fetch_complete("SELECT her_herstellungsid, ressourcen, name_interface FROM item_interface.herstellung");
$length = count($result);
for($i=0;$i<$length;$i++) {
	$result0[$result[$i]['her_herstellungsid']] = $result[$i];
}
unset($result);

$result2 = $result1;

foreach($result2 as $key => $item) {
	$length = strlen($item['ressourcen']);
	if($length > 0) {
		$result2[$key]['ressourcen'] = explode(",", substr(ereg_replace("\([0-9]+\)",",",$result2[$key]['ressourcen']),0,-1));
	}
}
unset($result1);

//Print_R($result2);

$missing = array();
foreach($result2 as $key => $item) {
	if(is_array($item['ressourcen']) && count($item['ressourcen'])>0) {
		foreach($item['ressourcen'] as $subitem) {
			if(isset($result2[$subitem])===false) {
				if(isset($missing[$subitem])===true) {
					// ist schon als vermisst festgestellt worden
					$missing[$subitem][1].= ",".$key."(".$item['name_interface'].") ";
				} else {
					$missing[$subitem] = array(0=>$result0[$subitem]['name_interface'], 1 => $key."(".$item['name_interface'].") ");
				}
			}
		}
	}
}

Print_R($missing);

echo "finito";
*/
echo "finito!";
?>