<?php
require_once (PATH_TABLES . "corporate_gift/CorporateGiftTable.php") ;
require_once (PATH_MODELS . "base/MasterBase.php") ;

class CorporateGiftClass extends MasterBase {
	function __construct($db) {
		$this->db 		= $db ;
		$this->tbl 		= CorporateGiftTable::C_TABLE;
		$this->fldid 	= CorporateGiftTable::C_ID;
		$this->flddesc 	= CorporateGiftTable::C_NAME;
	}
	function __destruct() {
	}

	function getCorporateGiftList($orderby = ''){
        $sql = "SELECT * FROM " . $this->tbl . " ";

        if($orderby != "")
            $sql .= " ORDER BY " . $orderby;

        $rows = $this->db->getTable($sql);

        return $rows;
    }

    public function getExistingRecords($gift_name, $gift_id=0) {
        $sql  = "SELECT * FROM " . $this->tbl .
            " WHERE " . $this->flddesc . " = '" . $gift_name . "' ";

        if($gift_id != 0) {
            $sql  .= " AND " . $this->fldid . " <> " . $gift_id . " ";
        }

        $rows = $this->db->getTable($sql);

        if (is_null($rows) || count($rows) == 0) {
            return null;
        } else {
            return $rows;
        }
    }

    public function getCorporateGiftActive(){
        $sql =" SELECT * FROM " . CorporateGiftTable::C_TABLE . " WHERE " . CorporateGiftTable::C_STATUS . " = 1 ";
        $rows = $this->db->getTable($sql);

        if (is_null($rows) || count($rows) == 0) {
            return null;
        } else {
            return $rows;
        }
    }
}
