<?php
$id=0;

$chars = getCharacterList($users['id']);
if($chars != 'empty' && getCharacterGM($users['id'])>0){
		  if ($accounttype == '1'){
	echo getPanel("warning","Error","Crystal Warrior Accounts Cannot Use Auction House");
		  }else{

if(isset($_POST['name'])){
	$_POST['name']=$_POST['name'];
	$_POST['name']=str_replace(" ","_",$_POST['name']);
}

if (!isset($_POST['name'])) 
{	

}
elseif(strlen($_POST['name'])<='3')
{
	
	echo getPanel("warning","Error","You Must enter more than 3 characters");
} 
elseif(getItemList($_POST['name'])=='empty')
{
	echo getPanel("warning","Error","No Items Found");
}
else
{
$name = $_POST['name'];
$item = getItemList($name);
echo '<table class="table table-hover">';
	foreach ($item as $items) 
	{
            echo '<tr><td><a href="?p=auction&id='.$items['itemid'].'">
            '.ucwords(str_replace('_',' ',$items['sortname'])).'</a>
            </td></tr>';
    }
 echo '</table>';

}



if(!isset($_GET['id'])){

    echo '
    
    <form action="" method="post"><input type="text" name="name" placeholder="Enter a Item"></input>  <input type="submit" value="Search"></input></form>

<br>
    
    Last 100 Items Listed<table class="table table-hover">
    <tr class="table-primary">
    <td>Item</td>
    <td>Stack</td>
    <td>Gil</td>
    </tr>';

    $ah=getAH();
    foreach($ah as $list){
        echo '<tr>
        <td>
        <a href="?p=auction&id='.$list['itemid'].'">
        <img src=http://static.ffxiah.com/images/icon/'.$list['itemid'].'.png alt='.getItemName($list['itemid']).' height=32 width=32>
        '.getItemName($list['itemid']).'</a></td>';
        
        if($list['stack']==1){
            echo '<td>Yes</td>';
        }
        else{
            echo '<td>No</td>';
        }
        
        echo'
        <td>'.$list['price'].'</td>
        </tr>';
    }

}
else{
    
    
$id=$_GET['id'];
        echo '<table class="table table-hover">
    <tr class="table-primary">
    <td>Item</td>
    <td>Stack</td>
    <td>Gil</td>
    </tr>';

    $ah=getAHItemUnsold($id);
    if($ah=='empty' || $ah=='error'){
    }
    else{
        foreach($ah as $list){
            echo '<tr>
            <td>
            <a href="?p=items&id='.$list['itemid'].'">
            <img src=http://static.ffxiah.com/images/icon/'.$list['itemid'].'.png alt='.getItemName($list['itemid']).' height=32 width=32>
            '.getItemName($list['itemid']).'</a></td>';
            
            if($list['stack']==1){
                echo '<td>Yes</td>';
            }
            else{
                echo '<td>No</td>';
            }
            
            echo'
            <td>'.$list['price'].'</td>
            </tr>';
        }
    }
 
} 
echo '</table>';
}
}

?>
