";
  if(!$log){
    print "
	$tblstart$tccell1>You must be logged in to access the Item Shop.
".
	redirect('index.php','return to the main page',0).
	$tblend;
  }else{
    $user=mysql_fetch_array(mysql_query("SELECT posts,regdate,users_rpg.* FROM users,users_rpg WHERE id=$loguserid AND uid=id"));
    $p=$user[posts];
    $d=(ctime()-$user[regdate])/86400;
    $st=getstats($user);
    $GP=$st[GP];
    switch($action){
	case '':
	  $shops=mysql_query('SELECT * FROM itemcateg ORDER BY corder');
	  $eq=mysql_fetch_array(mysql_query("SELECT * FROM users_rpg WHERE uid=$loguserid"));
	  $eqitems=mysql_query("SELECT * FROM items WHERE id=$eq[eq1] OR id=$eq[eq2] OR id=$eq[eq3] OR id=$eq[eq4] OR id=$eq[eq5] OR id=$eq[eq6]");
	  while($item=mysql_fetch_array($eqitems)) $items[$item[id]]=$item;
	  while($shop=mysql_fetch_array($shops))
	    $shoplist.="
		
		$tccell1>$shop[name]
		$tccell2s>$shop[description]
		$tccell1s>".$items[$eq['eq'.$shop[id]]][name]."
	    ";
	  print "
		
		  
		 | 
		$tblstart
		 $tccellh colspan=3>Shop list | 
		 $tccellc>Shop$tccellc>Description$tccellc>Item equipped
		 $shoplist
		$tblend
		
	  ";
	break;
	case 'items':
	  $uu=mysql_query("SELECT id FROM users");
	  while($u=mysql_fetch_array($uu)) mysql_query("INSERT INTO users_rpg (uid) VALUES ($u[id])");
	  $eq=mysql_fetch_array(mysql_query("SELECT eq$cat AS e FROM users_rpg WHERE uid=$loguserid"));
	  $eqitem=mysql_fetch_array(mysql_query("SELECT * FROM items WHERE id=$eq[e]"));
        print "
		
		
		$tblstart
		  $tccell1>Return to shop list
		$tblend
		
		
		
	  ";
	  $atrlist='';
	  for($i=0;$i<9;$i++) $atrlist.="$tccellh width=6%>$stat[$i]";
	  $items=mysql_query("SELECT * FROM items WHERE cat=$cat OR cat=0 ORDER BY type,coins");
	  print "
		$tblstart
		$tccellh width=110 colspan=2>Commands$tccellct width=1 rowspan=10000> 
		$tccellh colspan=1>Item
		$atrlist
		$tccellh width=6%>
		$tccellh width=5%>
	  ";
	  while($item=mysql_fetch_array($items)){
	    $preview="Preview";
	    if($item[id]==$eq[e] && $item[id]){
		$comm="width=80 colspan=2>Sell";
	    }elseif($item[id] && $item[coins]<=$GP){
		$comm="width=30>Buy$tccell1s width=50>$preview";
	    }elseif(!$eq[e] && !$item[id]){
		$comm="width=80 colspan=2>-";
	    }else{
		$comm="width=80 colspan=2>$preview";
	    }
	    if($item[id]==$eqitem[id]) $color=' class=equal';
	    elseif($item[coins]>$GP) $color=' class=disabled';
	    else $color='';
	    $atrlist='';
	    for($i=0;$i<9;$i++){
		$st=$item["s$stat[$i]"];
		if(substr($item[stype],$i,1)=='m'){
		  $st=vsprintf('x%1.2f',$st/100);
		  if($st==100) $st=' ';
		}else{
		  if($st>0) $st="+$st";
		  if(!$st) $st=' ';
		}
		$itst=$item["s$stat[$i]"];
		$eqst=$eqitem["s$stat[$i]"];
		if(!$color && substr($item[stype],$i,1)==substr($eqitem[stype],$i,1)){
		  if($itst> $eqst) $st="$st";
		  if($itst==$eqst) $st="$st";
		  if($itst< $eqst) $st="$st";
		}
		$atrlist.="
		  $tccell1s>$st
		";
	    }
	    print "
		
		$tccell1s $comm
		$tccell2ls>$item[name]
		$atrlist
		$tccell2rs>$item[coins]
		$tccell2rs>0
	    ";
	  }
	  print $tblend;
	break;
	case 'buy':
	  $item=mysql_fetch_array(mysql_query("SELECT * FROM items WHERE id=$id"));
	  if($item[coins]<=$GP){
	    $pitem=mysql_fetch_array(mysql_query("SELECT coins FROM items WHERE id=".$user['eq'.$item[cat]]));
	    $whatever = $pitem[coins]*0.6-$item[coins];
	    mysql_query("UPDATE users_rpg SET `eq". $item[cat] ."`='". $id ."',`spent`=spent-". $whatever ." WHERE uid=$loguserid") or print mysql_error();
	    print "
		$tblstart
		  $tccell1>The $item[name] has been bought and equipped.
		  ".redirect('shop.php','return to the shop',0)."
		$tblend
	    ";
	  }
	break;
	case 'sell':
	  $pitem=mysql_fetch_array(mysql_query("SELECT coins FROM items WHERE id=".$user['eq'.$cat]));
	  mysql_query("UPDATE users_rpg SET eq$cat=0,spent=spent-$pitem[coins]*0.6 WHERE uid=$loguserid") or print mysql_error();
	  print "
	    $tblstart
		$tccell1>The $item[name] has been unequipped and sold.
		".redirect('shop.php','return to the shop',0)."
	    $tblend
	  ";
	break;
	default:
    }
  }
  print $footer;
  printtimedif($startingtime);
?>