<?php

// LIMITS ENTFERNEN!!!
@set_time_limit(0);

include './core.php';

$accounts = $MySQL->query( "SELECT accountid FROM accounts" );

while( $row = $MySQL->fetch_array( $accounts ) )
{
	$cAcc = new Account( (int)$row['accountid'] );
    $cAcc->refresh_wbb_access();
}

/*$RMySQL = new MySQL( '', '', '', '' );

$accounts_res = $RMySQL->query( "SELECT * FROM accounts" );

while( $row = $RMySQL->fetch_array( $accounts_res ) )
{
    switch( $row['group'] )
    {
    	default:
        	$group = 0; break;
        case 'Servertechnik':
        	$group = 1; break;
        case 'Homepage':
        	$group = 2; break;
        case 'Grafik':
        	$group = 3; break;
        case 'Bau':
        	$group = 4; break;
        case 'Map':
        	$group = 5; break;
        case 'Script':
        	$group = 6; break;
        case 'Quest':
        	$group = 7; break;
        case 'Support':
        	$group = 8; break;
    }

    switch( $row['level'] )
	{
    	default:
        case 'user': $rank = 1; break;
        case 'player': $rank = 2; break;
        case 'moderator': $rank = 3; break;
        case 'superModerator': $rank = 4; break;
        case 'mitarbeiter': $rank = 1; break;
        case 'ehrenMitglied': $rank = 5; break;
        case 'counselor1': $rank = 6; break;
        case 'counselor2': $rank = 7; break;
        case 'gmCounselor': $rank = 8; break;
        case 'gameMaster': $rank = 9; break;
        case 'elderGameMaster': $rank = 10; break;
        case 'developer': $rank = 12; break;
        case 'administrator': $rank = 14; break;
    }

    $flags = 0;
    set_flag( $flags, 0, ( $row['showEmail'] == 1 ) );
    set_flag( $flags, 1, ( $row['getNewsletter'] == 1 ) );
    set_flag( $flags, 2, ( $row['block'] == 1 ) );
    set_flag( $flags, 3, ( $row['activation'] == 1 ) );

    $access_flags = 0;
    $wa = explode( ',', $row['webAccess'] );
    set_flag( $access_flags, 0, ( $row['techAdmin'] == 1 ) );
    set_flag( $access_flags, 1, ( $row['downloadAccess'] == 1 ) );
    set_flag( $access_flags, 2, in_array( 'templates', $wa ) );
    set_flag( $access_flags, 3, in_array( 'screenshots', $wa ) );
    set_flag( $access_flags, 4, in_array( 'faq', $wa ) );
    set_flag( $access_flags, 5, in_array( 'lib', $wa ) );

    $away_msg = empty( $row['abwesenheit'] ) ? 'NULL' : "'".$row['abwesenheit']."'";
    $intern_email = empty( $row['staffMail'] ) ? 'NULL' : "'".$row['staffMail']."'";
    $intern_icq = empty( $row['staffICQ'] ) ? 'NULL' : $row['staffICQ'];
    $row['lastBoardLinkChange'] = empty( $row['lastBoardLinkChange'] ) ? 'NULL' : $row['lastBoardLinkChange'];

    //$MySQL->query( "INSERT INTO accounts VALUES (".$row['accountid'].",'".$row['accountName']."','".$row['password']."',".$row['bb_userid'].",'".$row['eMail']."',NULL,".$flags.",".$access_flags.",".$row['styleID'].",".$row['registerTime'].",'".$row['lastIP']."',NULL,".$row['lastBoardLinkChange'].",".$rank.",".$group.",".$row['maxChars'].",".$away_msg.",".$intern_email.",".$intern_icq.",NULL)" );

    if( $row['bb_userid'] > 0 && !empty( $row['bb_userid'] ) )
    {
        $board_access = array();

	    if( $rank == 7 || $rank == 8 )
	    {
	        switch( $group )
	        {
	            default:
	            case 0:
	            case 1:
	                break;
	            case 2:
	                array_push( $board_access, 61, 62, 13, 14 ); break;
	            case 3:
	                array_push( $board_access, 66, 67, 28 ); break;
	            case 4:
	                array_push( $board_access, 58, 10 ); break;
	            case 5:
	                array_push( $board_access, 65, 29 ); break;
	            case 6:
	                array_push( $board_access, 59, 60, 11, 12 ); break;
	            case 7:
	                array_push( $board_access, 63, 16 ); break;
	            case 8:
	                array_push( $board_access, 71 ); break;
	        }
	    }

	    foreach( $board_access as $board )
	    {
	        $MySQL->query( "INSERT INTO wbb2.bb2_access (boardid,userid,can_view_board,can_enter_board,can_read_thread,can_use_search) VALUES (".$board.",".$row['bb_userid'].",1,1,1,1)" );
	    }
    }

    if( $row['activation'] != 1 )
    {
    	$MySQL->query( "INSERT INTO account_activation_codes VALUES (".$row['accountid'].",".$row['activation'].")" );
    }

    if( !empty( $row['pic'] ) )
    {
        $extension = substr( strrchr( $row['pic'], "." ), 1 );
        $MySQL->query( "INSERT INTO user_pictures VALUES (".$row['accountid'].",".$row['picActivated'].",'".$extension."',NULL)" );
    }

    if( !empty( $row['loc'] ) )
    {
    	$locinfo = explode( ',', $row['loc'] );
        $town = empty( $locinfo[3] ) ? 'NULL' : "'".$locinfo[3]."'";
        $plz = empty( $locinfo[4] ) ? 'NULL' : "'".$locinfo[4]."'";

        $MySQL->query( "INSERT INTO user_locations VALUES (".$row['accountid'].",'".$locinfo[0]."',".$locinfo[1].",".$locinfo[2].",".$town.",".$plz.")" );
    }
}


$betastatus_res = $RMySQL->query( "SELECT * FROM beta_status" );

while( $row = $RMySQL->fetch_array( $betastatus_res ) )
{
	$MySQL->query( "INSERT INTO betastatus VALUES ('','".$row['bereich']."',".$row['prozent'].",'".$row['kommentar']."')" );
}

$faqcat_res = $RMySQL->query( "SELECT * FROM faqcat" );

while( $row = $RMySQL->fetch_array( $faqcat_res ) )
{
	$MySQL->query( "INSERT INTO faq_categories VALUES (".$row['ID'].",'".$row['title']."',".$row['ordnen'].")" );
}

$faq_res = $RMySQL->query( "SELECT * FROM faq" );
$i = 0;

while( $row = $RMySQL->fetch_array( $faq_res ) )
{
	$MySQL->query( "INSERT INTO faqs VALUES (".$row['ID'].",".$row['cID'].",'".addslashes( $row['question'] )."','".addslashes( $row['answer'] )."',".$i.")" );
	$i++;
}

$wep_res = $RMySQL->query( "SELECT * FROM weekendPics" );

while( $row = $RMySQL->fetch_array( $wep_res ) )
{
	$MySQL->query( "INSERT INTO weekend_pictures VALUES (".$row['picID'].",'".$row['name']."','".$row['description']."',".$row['startTime'].")" );
}

$screen_res = $RMySQL->query( "SELECT * FROM screenshots" );

while( $row = $RMySQL->fetch_array( $wep_res ) )
{
	$MySQL->query( "INSERT INTO weekend_pictures VALUES (".$row['picID'].",'".$row['name']."','".$row['description']."',".$row['startTime'].")" );
}

function set_flag( &$field, $index, $value )
{
    if ( $value )
        $field |= ( 1 << $index );
    else
        $field &= ~( 1 << $index );
}*/

?>