Viewing file: clsDepartment.php (7.97 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
//--Class department--------------------------
//--PK of department ::
// 1. departmentId
class Department extends clsDB{
var $result;
var $deptId;
var $deptName;
var $deptDesc;
var $deptCode;
var $deptParent;
var $deptYear;
var $deptDate;
var $deptRef;
var $pbriId;
var $depttypeId;
var $deptParentId;
var $deptLevel;
var $deptGroup;
function Department(&$c){
$this->c=$c->c;
$this->DB=$c->db;
}
function Save(){
if ($this->status==1){
//uncomment a line below if your table use ID as running number
$this->departmentId=$this->GetNextCode();
$sql = "insert into Department values(
'$this->deptId',
'$this->deptName',
'$this->deptDesc',
'$this->deptCode',
'$this->deptParent',
'$this->deptYear',
'$this->deptDate',
'$this->deptRef',
'$this->pbriId',
'$this->depttypeId',
'$this->deptParentId',
'$this->deptLevel',
'$this->deptGroup')";
}else {
$sql = "update Department set
deptName='$this->deptName',
deptDesc='$this->deptDesc',
deptCode='$this->deptCode',
deptParent='$this->deptParent',
deptYear='$this->deptYear',
deptDate='$this->deptDate',
deptRef='$this->deptRef',
pbriId='$this->pbriId',
depttypeId='$this->depttypeId',
deptParentId='$this->deptParentId',
deptLevel='$this->deptLevel',
deptGroup='$this->deptGroup'
where deptId='$this->deptId'";
}
return $this->Dml($sql);
}
function Delete(){
return $this->Dml("delete from Department where deptId='$this->deptId'");
}
function GetNextCode(){
$this->SetQuery("select max(deptId) as num from Department");
if ($result=$this->GetResult()) {
return $result['num']+1;
}
}
function RSdepartment(){
$this->SetQuery("select * from Department order by deptId");
}
function GetRecord(){
$numFields = $this->NumField();
$row = $this->GetResult();
if ($row){
for ($i=0; $i<$numFields; $i++){
eval("\$this->".mysql_field_name($this->rs, $i)."=\$row['".mysql_field_name($this->rs, $i)."'];");
}
return true;
}else{ // clear value of Member;
for ($i=0; $i<$numFields; $i++){
eval("\$this->".mysql_field_name($this->rs, $i)."='';");
}
return false;
}
}
function SearchByKey($xKey){
if ($this->SetQuery("select * from Department where deptId= '$xKey'")){
return 1;
}else {
return 0;
}
}
//****************** You can add new functions below **********************//
function SearchByDeptRef($xKey){
if($this->SetQuery("select * from Department where deptRef = '$xKey'")){
return 1;
}else {
return 0;
}
}
function SearchBydeptParent(){ /////
$this->SetQuery("select * from Department where deptParent=0");
}
function RSDeptByMaxdeptDate(){
$maxdate = $this->MaxDate();
$this->SetQuery("select * from Department where deptDate = '$maxdate' and deptParent=1 order by deptId asc");
}
function RSDeptByMaxdeptDate2(){
$maxdate = $this->MaxDate();
$this->SetQuery("select * from Department where deptDate = '$maxdate' order by deptId asc");
}
function RSDeptBydeptParent1(){
$maxdate = $this->MaxDate();
$this->SetQuery("select * from Department where deptParent=1 order by deptId asc");
}
function MaxDate(){
$this->SetQuery("select max(deptDate) as num from Department");
if ($result=$this->GetResult()) {
return $result['num'];
}
}
function searchMaxDate($xKey){
if($this->SetQuery("select deptDate from Department where deptDate >'$xKey' order by deptDate asc limit 1")){
return 1;
}else {
return 0;
}
}
function SearchDeptByMaxdeptDate($xKey){
$maxdate = $this->MaxDate();
$this->SetQuery("select * from Department where deptId='$xKey' and deptDate = '$maxdate' and deptParent=1 order by deptId");
}
function SearchMaxDocGroup(){
$this->SetQuery("select max(docGroup) as num from Department");
if ($result=$this->GetResult()) {
return $result['num'];
}
}
function SearchBydeptDateDocGroup($xKey){
$this->SetQuery("select * from Department where docGroup='$xKey' order by deptId");
}
function SearchDeptParentByDeptRef($xKey){
$this->SetQuery("select * from Department where deptRef = '$xKey'");
}
function SearchByreceiveInMaxDocGroup($xKey){
$this->SetQuery("select * from Department where docGroup='$xKey' and deptParent=1 and receiveIn='Y' order by deptId asc");
}
function SearchBysendInMaxDocGroup($xKey){
$this->SetQuery("select * from Department where docGroup='$xKey' and deptParent=1 and sendIn='Y' order by deptId asc");
}
function SearchDeptName($xKey){
$this->SetQuery("select deptName as name from Department where deptId= '$xKey'");
if ($result=$this->GetResult()) {
return $result['name'];
}
}
function SearchBydeptDateDocGroupNoselectDept($xKey,$deptID){
$this->SetQuery("select * from Department where docGroup='$xKey' and deptParent=1 and deptId!='$deptID' order by deptId");
}
function SearchBydeptParentnot0($xKey){ /////
$this->SetQuery("select * from Department where deptParent!=0 and deptDate!='$xKey' order by deptDate desc ,deptId asc");
}
function RSmenuByDeptParent($dId){
$maxdate = $this->MaxDate();
$sql = "select * from Department where deptParentId=$dId and deptDate = '$maxdate' order by deptId";
$this->SetQuery($sql);
}
function RSmenuByDeptParent2($dId){
$maxdate = $this->MaxDate();
$sql = "select * from Department where deptParentId=$dId and deptDate = '$maxdate' order by deptId";
$this->SetQuery($sql);
}
function RSmenuByDeptParent2deptdate0($dId){
$sql = "select * from Department where deptParentId=$dId and deptDate = '0000-00-00' order by deptId";
$this->SetQuery($sql);
}
function RSMainDepartment(){
$maxdate = $this->MaxDate();
$sql = "select * from Department where deptParentId=0 and deptDate = '$maxdate' order by deptParentId";
$this->SetQuery($sql);
}
function SearchByName(){
//echo "cls 1".$xKey."<br>";
//echo "cls 2".$yKey."<br>";
///--ใช้เมธอดนี้เพื่อค้นหาข้อมูลตาม PK ต้องระบุพารามิเตอร์ด้วย
//--และต้องตามด้วยเมธอด GetRecord() เสมอ
$maxdate = $this->MaxDate();
$sql = "select * from Department where deptName = 'ผู้อำนวยการสถาบันพระบรมราชชนก' and deptDate = '$maxdate' ";
//echo $sql;
$this->SetQuery($sql);
}
function RSdeptSetgroupHead(){
$maxdate = $this->MaxDate();
$sql = "select * from Department where depttypeId < '3' and deptDate = '$maxdate'";
$this->SetQuery($sql);
}
function RSdepthavedeptParentId($xKey){
$sql = "select * from Department where deptParentId ='$xKey'";
$this->SetQuery($sql);
}
function RSdeptGroupBydeptDate($xKey){
$sql = "select * from Department group by deptDate order by deptDate desc";
$this->SetQuery($sql);
}
function searchdeptDate($xKey){
$this->SetQuery("select * from Department where deptDate='$xKey' order by deptId asc");
}
function searchdeptDate2($xKey){
$this->SetQuery("select * from Department where deptParentId=0 and deptDate='$xKey' order by deptParentId asc , deptId asc");
}
function RSMainDepartmentdeptDate0(){
$sql = "select * from Department where deptDate='0000-00-00' order by deptParentId";
$this->SetQuery($sql);
}
function RSMainDepartment2($xKey,$yKey){
$sql = "select * from Department where deptParentId=0 and deptDate='0000-00-00' order by deptParentId asc , deptId asc";
$this->SetQuery($sql);
}
function SearchNewdept($xKey){
$sql = "select * from Department where deptParent ='$xKey'";
$this->SetQuery($sql);
}
function SearchByNamedeptDate0(){
$sql = "select * from Department where deptName = 'ผู้อำนวยการสถาบันพระบรมราชชนก' and deptDate='0000-00-00'";
//echo $sql;
$this->SetQuery($sql);
}
function RSdeptSetgroupHeaddeptDate0(){
$sql = "select * from Department where depttypeId < '3' and deptDate='0000-00-00'";
$this->SetQuery($sql);
}
function searchpreMaxDate($xKey){
$sql = "select * from Department where deptDate <'$xKey' and deptDate!='0000-00-00' order by deptDate desc limit 1";
$this->SetQuery($sql);
}
function searchdeptDateorderdeptParentId($xKey){
$this->SetQuery("select * from Department where deptParentId='$xKey'");
}
} //--End class department--
?>
|