<?php

    include "config.php";
    //$user = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '2106' LIMIT 1;"));
    //include "functions.php";
    //$komp_users = mysql_query("SELECT * FROM `users`,`online` WHERE `users`.`id`=`online`.`id` AND `online`.`date` >= ".(time()-60).";");
    $komp_users = mysql_query("SELECT * FROM `users`;");
    while($ku=mysql_fetch_array($komp_users))
    {
     $kompl_raw=mysql_query("SELECT * FROM inventory where owner=".$ku['id']." AND dressed=1");

        $items_on_user=array();
        $set_id_wear=array();
        $kompl_har=0;
        while ($kompl=mysql_fetch_array($kompl_raw))
        {
            $items_on_user[]=$kompl['prototype'];
        }
        $sets_raw=mysql_query("SELECT * FROM item_sets;");
        while ($set_items=mysql_fetch_array($sets_raw))
        {
            $kompl_full=1;
            $in_set=explode(',',$set_items['prot_id']);
            foreach($in_set as $tmp_set)
            if (!in_array($tmp_set,$items_on_user))
            {$kompl_full=0;}
            if ($kompl_full==1) $set_id_wear[]=$set_items['set_id'];
	}

        foreach($set_id_wear as $s)
        {
            $items_raw=mysql_fetch_array(mysql_query("SELECT * FROM item_sets where set_id='{$s}' limit 1;"));
                $kompl_har+=$items_raw['gsila'];
		$kompl_har+=$items_raw['glovk'];
		$kompl_har+=$items_raw['gintel'];
		$kompl_har+=$items_raw['ginta'];
        }
        if(!$kompl_har) $kompl_har=0;
		$explim=0;
	foreach(array_keys(EXPTABLE) as $k)
	{
	 if($k>=$ku['exp'])
	 {
	  $explim=$k;
	  break;
	 }
	}
	$sum_stat=15;
	foreach(array_keys(EXPTABLE) as $k)
	{
	 if($k==$explim)
	  break;
	 else
	 {
	  $sum_stat+=EXPTABLE[$k][0];
	  $sum_stat+=EXPTABLE[$k][2];
	 }
	}
        $res=mysql_fetch_array(
		mysql_query("SELECT IFNULL( (SUM( gsila ) + SUM( glovk ) + SUM( ginta ) + SUM( gintel )) , 0)+	{$kompl_har} + {$sum_stat}
FROM `inventory` WHERE `owner` = '{$ku['id']}' AND `dressed` = 1;"));

	  $res2=mysql_fetch_array(mysql_query("SELECT `sila`+`lovk`+`intel`+`inta`+`vinos`+`mudra`+`stats` FROM `users` WHERE `id`={$ku['id']};"));
	 

	 
if($res[0]!=$res2[0])
 echo("<br/>".$kompl_har." _ ID=".$ku['id']."[".$ku['exp']."] : All=".$res2[0]."/norm=".$res[0]);



}

