<?php
if (getCharacterGM($users['id']) >= 3)
{

 if(!isset($_GET['id'])){		
 echo '<form action="" method="post"><input type="text" name="name" placeholder="Enter a Character"></input>  <input type="submit" value="Search"></input></form>';


	if (!isset($_POST['name'])) 
	{	
	}
	elseif(strlen($_POST['name'])<'3')
	{
	echo getPanel("warning","Error","You Must enter more than 2 characters");
	} 
	elseif(getNamesList($_POST['name'])=='empty')
	{
	echo getPanel("warning","Error","No Characters Found");
	}
	else
	{
	$charname = $_POST['name'];
	$char = getNamesList($charname);
	echo '<table class="table table-striped">';
		foreach ($char as $chars) 
		{
		echo '<tr><td><a href="?p=gm&tool=charvar&id='.$chars['charid'].'">'.$chars['charname'].'</a></td></tr>';
		}
	echo '</table>';
	}
 }
 else{
 $id=$_GET['id'];
	echo '<table class="table table-sm">';
	$char=getCharacter($id);
	$char=$char[0];
	if($char!='empty'){
		echo '<tr class=table-active>
		<td><a href=?p=characters&id='.$char['charid'].'>'.$char['charname'].'</a></td>
		<td><form method="POST" action=?p=gm&tool=charvarupdate&id='.$id.'>Varname<input type="text" name="varname"></input>Value<input type="text" name="value"></input><button class="btn btn-primary" type="submit">Update Charvar</button></form></td>
		</tr>';

		if(isset($_POST['varname'])){
			$varname=$_POST['varname'];
			$value=$_POST['value'];
				if($value==0){
					deletePlayerVariable($char['charid'],$varname);
				}else{
					setPlayerVariable($char['charid'],$varname,$value);
				}
				echo getPanel("success","Success","Charvar Inserted");
			}
		else{
		}
	}
 }
 echo '</table>';
 
 
 }


?>