<?php
class Person{
var $dbms;
var $result;
var $status;
var $per_id;
var $per_name;
var $per_lasname;
var $per_address;
var $per_phone;
var $positon_id;
var $per_user;
var $per_passwd;
var $per_status;
function Person(){
$this->dbms=new dbase;
}
function Delete(){
$this->status = 0;
}
function AddNew(){
$this->status=1;
}
function Edit(){
$this->status=2;
}
function Save(){
if($this->status=='1'){
$sql="insert into person values('$this->per_id','$this->per_name','$this->per_lasname','$this->per_address','$this->per_phone','$this->position_id','$this->per_user','$this->per_passwd','$this->per_status')";
}
else if($this->status == '0')
{
$sql = "delete from person where per_id = '$this->per_id'";
// echo $sql;
}else if($this->status=='2'){
if($this->per_image == ""){ // แก้ไขข้อมูล
$sql="update person set per_id='$this->per_id',
per_name='$this->per_name'
per_lasname='$this->per_lasname'
per_address='$this->per_address'
per_phone='$this->per_phone'
position_id='$this->position_id'
per_iser'$this->per_user'
per_password'$this->per_passwd'
per_status'$this->per_status'
where per_id='$this->per_id'";
}
else{ // แก้ไขข้อมูล
$sql="update per set per_id='$this->per_id',
per_name='$this->per_name'
per_lasname='$this->per_lasname'
per_address='$this->per_address'
per_phone='$this->per_phone'
position_id='$this->position_id'
per_iser'$this->per_user'
per_password'$this->per_passwd'
per_status'$this->per_status')
where per_id='$this->per_id'";
}
}
$this->dbms->SetQuery($sql);
}
function GetNextCode() {
//GetMaxIDเป็นฟังก์ชั่นที่รีเทิร์นค่าสูงสุดของตารางให้
$this->dbms->SetQuery("Select Max(per_id) as per_id from person ");
$this->GetRecord();
$code=substr("$this->per_id",1)+1;
return "E" .substr("000$code",-4,4);
}
function RSlogin($per_id,$per_passwd){
//$this->dbms->SetQuery("select * from person where per_id='$per_id' and per_passwd='$per_passwd'");
}
function RSper($per_id){
$this->dbms->SetQuery("select * from person where per_id='$per_id' ");
}
function RSloginper($login,$password){
$this->dbms->SetQuery("select * from person where per_id='$login' and per_passwd='$password'");
}
function RSstus($c_id){
$this->dbms->SetQuery("select * from person where per_id='$c_id'");
}
function PassGetRecord(){
//PassGetRecord เป็นฟังก์ชั่นนำค่าที่ได้จากการเอ็กซีคิวมากำหนดค่าให้กับตัวแปรของคลาส
if($this->result=$this->dbms->GetResult()){
$this->per_passwd=$this->result['per_passwd'];
return 1;
}else{
return 0;
}
}
function ChangPass($per_id,$per_passwd) {
$sql = "update person set per_passwd='$per_passwd' where per_id='$per_id' ";
$this->dbms->SetQuery($sql);
}
//**************************************************************************//
function RSstatus($s_id){
$this->dbms->SetQuery("select person.per_id , person.position_id , position.position_id , position.position_name from position left join person on position.position_id = person.position_id where per_id='$s_id'");
}
function SelectPerson(){
$this->dbms->SetQuery("select * from person order by per_id asc");
}
function NumRow(){
return $this->dbms->GetRow();
}
function SPerson($s_id){
// รีเทิร์นข้อมูลให้เป็นกลุ่มข้อมูลจากการเอ็กซีคิวคำสั่ง
$this->dbms->SetQuery("select * from person where per_id ='$s_id' ");
}
function GetRecord(){
if($this->result=$this->dbms->GetResult()){
$this->per_id=$this->result['per_id'];
$this->per_name= $this->result['per_name'];
$this->per_lasname= $this->result['per_lasname'];
$this->per_address= $this->result['per_address'];
$this->per_phone= $this->result['per_phone'];
$this->position_id=$this->result['position_id'];
$this->per_user= $this->result['per_user'];
$this->per_passwd=$this->result['per_passwd'];
$this->per_status=$this->result['per_status'];
return 1;
}
else{
return 0;
}
}
// ค้นหาข้อมูล
function Search1($per_name){
if($this->dbms->SetQuery("select * from person where per_name='$per_name'")){
return 1;
}
else{
return 0;
}
}
function Search($per_id){
if($this->dbms->SetQuery("select * from person where per_id='$per_id'")){
return 1;
}else{
return 0;
}
}
function SearchByID($per_search,$txtsearch){
// RStteacherinfoเป็นฟังก์ชั่นที่รีเทิร์นข้อมูลให้เป็นกลุ่มข้อมูลจากการเอ็กซีคิวคำสั่ง
$this->dbms->SetQuery("select * from person where $per_search like '%$txtsearch%' order by per_id ");
}
function SearchName($txtsearch){
$this->dbms->SetQuery("select * from person where per_name LIKE '%$txtsearch%'");
}
function GetNumRow(){
//GetCountIDเป็นฟังก์ชั่นที่รีเทิร์นค่าสูงสุดของตารางให้
$this->dbms->SetQuery("select count(per_id) as per_id from person ");
if($result = $this->dbms->GetResult()) {
return $result['per_id'];
}
}
function RSPerson2($PageSt,$PerPg){
// RStteacherinfoเป็นฟังก์ชั่นที่รีเทิร์นข้อมูลให้เป็นกลุ่มข้อมูลจากการเอ็กซีคิวคำสั่ง
$this->dbms->SetQuery("select * from person order by per_id limit $PageSt,$PerPg");
}
function PSPgSearch($type_search,$txtsearch,$PageSt,$PerPg){
$this->dbms->SetQuery("select * from person where $type_search like '%$txtsearch%' order by per_id limit $PageSt,$PerPg");
}
function PSPg($PageSt,$PerPg){
$this->dbms->SetQuery("select * from person order by per_id limit $PageSt,$PerPg");
}
//จบการคำนวณเรคคอร์ด
function RSBYPerson($per_search,$txtsearch){
$this->dbms->SetQuery("select * from person where $per_search like '%$txtsearch%' ");
}
function Query($con, $where){
$r= $this->dbms->SetQuery("$con $where");
}
function DisConnect(){
return $this->dbms->DisConnect();
}
}
?>