<?php




echo '<table class="table table-sm">';
ini_set('display_errors', 0);
    
$id=$_GET['id'];
$link=getLinkshell($id);
$haslink=0;
$owner=0;
$shell=0;

if($link!='empty'){
 foreach ($chars as $char) {
  if($char!='empty'){
   $ls=getLinkshellbyChar($char['charid']);
   if($ls!='empty'){
    foreach ($ls as $lss){
     if(ucwords($lss['signature'])==ucwords($link['name'])){
      $haslink=1;
      if($lss['itemId']==513){
       $owner=1;
      }
      if($lss['itemId']==514){
       $sack=1;
      }
     }
    }
   }
  }
 }

 if($haslink==1){


if(isset($_POST['kick'])){
$slot=$_POST['slot'];
$location=$_POST['location'];
$charid=$_POST['charid'];
$itemid=$_POST['itemid'];
$sig=$link['name'];
 if(($owner==1 || $sack==1) && ($itemid==515)){
  kickLs($charid,$slot,$location,$itemid,$sig);
 }
}

if(isset($_POST['promote'])){
$slot=$_POST['slot'];
$location=$_POST['location'];
$charid=$_POST['charid'];
$itemid=$_POST['itemid'];
$sig=$link['name'];
 if(($owner==1 || $sack==1) && ($itemid==515)){
  promoteLS($charid,$slot,$location,$itemid,$sig);
 }
}

if(isset($_POST['demote'])){
$slot=$_POST['slot'];
$location=$_POST['location'];
$charid=$_POST['charid'];
$itemid=$_POST['itemid'];
$sig=$link['name'];
 if(($owner==1) && ($itemid==514)){
  demoteLS($charid,$slot,$location,$itemid,$sig);
 }
}

$color=dechex($link['color']);
$rgb = hex2rgb($color);
//echo '<tr><td><a data-toggle="collapse" href="#collapseChat" role="button" aria-expanded="false" aria-controls="collapseChat">Chat</a></td></tr>';
//echo '</table><div class="collapse" id="collapseChat"><table class="table table-sm">';
	//require_once("chat.php");
//echo '</table></div>';

echo '<table class="table table-sm" id="myTable2">';

echo '<tr><th></th><th>Name</th><th>Online</th><th onclick="sortTable(3)">Last Online</th><td></td></tr>';

  if($owner==1){
  }
  elseif($sack==1){
  }
  else{
  }
$holders=getLinkHolders($link['name']);
   foreach($holders as $holder){
if($holder['itemId']==513){
$image='shell';
}
elseif($holder['itemId']==514){
$image='sack';
}
else{
$image='pearl';
}

 $accid=getCharacterAccid($holder['charid']);
 $gm=getCharacter($holder['charid']);
 $gm=$gm[0];
 
	if(($gm['gmlevel'])>0){
		$online="gm";
	}
	elseif(isCharOnline($holder['charid'])==true)
	{
		$online="online";
	}
	else
	{
		$online="offline";
	}
	if($_GET['status']==$online){
    echo '<tr><td width=10%><div style="width: 25px; height: 25px; background-color:rgba('.$rgb[0].','.$rgb[1].','.$rgb[2].',1)"><img src="theme/'.$theme.'/images/'.$image.'.png" height="25" width="25" alt="'.$link['name'].'" title="'.$link['name'].'"></div></td><td><a href=?p=characters&id='.$holder['charid'].'>'.getCharacterName($holder['charid']).'</a></td><td align=right><img src="theme/'.$theme.'/images/'.$online.'.png" height="25" width="25" alt="'.$online.'" title="'.$online.'"></td><td>'.getLastOnline($holder['charid'])[0].'</td>';
if(($owner==1 || $sack==1) && ($holder['itemId']==515)){
echo '<td>
<form action="" method="post">
<input type="hidden" name="promote" value="promote"></input>
<input type="hidden" name="slot" value="'.$holder['slot'].'"></input>
<input type="hidden" name="location" value="'.$holder['location'].'"></input>
<input type="hidden" name="charid" value="'.$holder['charid'].'"></input>
<input type="hidden" name="itemid" value="'.$holder['itemId'].'"></input>
<input type="submit" value="Promote"></input>
</form>
</td><td>
<form action="" method="post">
<input type="hidden" name="kick" value="kick"></input>
<input type="hidden" name="slot" value="'.$holder['slot'].'"></input>
<input type="hidden" name="location" value="'.$holder['location'].'"></input>
<input type="hidden" name="charid" value="'.$holder['charid'].'"></input>
<input type="hidden" name="itemid" value="'.$holder['itemId'].'"></input>
<input type="submit" value="Kick"></input>
</form>

</td>';
}
elseif(($owner==1) && ($holder['itemId']==514)){
echo '<td>
<form action="" method="post">
<input type="hidden" name="demote" value="demote"></input>
<input type="hidden" name="slot" value="'.$holder['slot'].'"></input>
<input type="hidden" name="location" value="'.$holder['location'].'"></input>
<input type="hidden" name="charid" value="'.$holder['charid'].'"></input>
<input type="hidden" name="itemid" value="'.$holder['itemId'].'"></input>
<input type="submit" value="Demote"></input>
</form>
</td><td>
</td>';
}
else{
echo '<td></td><td></td>';
}
echo '</tr>';
 }
   }
}

 else{
 echo getPanel("danger","Get out!","Stop trying to look at other linkshells...");	
}


}

ini_set('display_errors', 1);
echo '</table>';
?>