<?php
class ADMIN{

  var $id, $name, $pass, $level;

  function __construct(){
	  $this->id = 0;
	  $this->name = "";
	  $this->pass = "";
	  $this->level = "";
  }
  
  function setAdmin($pfield,$pval){
    global $conn;
	$query = "SELECT * FROM tb_admin WHERE $pfield='$pval'";
	$result = mysqli_query($conn,$query);
	$num = mysqli_num_rows($result);
	if($num>0){
	while($myrow = mysqli_fetch_array($result)){
	  $this->id = $myrow["id"];
	  $this->name = $myrow["name"];
	  $this->pass = $myrow["pass"];
	  $this->level = $myrow["level"];
	}
	}

  }
  

  function updateAdmin(){
    global $conn;
	$query = "UPDATE tb_admin SET name='".$this->name."', pass='".$this->pass."' WHERE id='".$this->id."'";
	mysqli_query($conn,$query);
  }
  
  
  function getAdminList($pval){
    global $conn;
	$query = "SELECT * FROM tb_admin $pval";
	$result = mysqli_query($conn,$query);
	$num = mysqli_num_rows($result);
	if($num>0){
	while($myrow = mysqli_fetch_array($result)){
	  $tid = $myrow["id"];
	  $output[$tid]["name"] = $myrow["name"];
	  $output[$tid]["pass"] = $myrow["pass"];
	  $output[$tid]["level"] = $myrow["level"];
	}
	}
	return $output;
  }
}
?>