<?php
require_once (PATH_TABLES . "campaign/CampaignProfileTable.php") ;
require_once (PATH_MODELS . "base/MasterBase.php") ;

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

	public function getExistingRecords($comp_code, $comp_id=0) {
        $sql  = "SELECT * FROM " . $this->tbl .
            " WHERE " . $this->fldcode . " = '" . $comp_code . "' ";

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

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

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

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

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

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

        return $rows;
    }

    function getActiveCampaignProfileList($orderby = ''){
        $sql = "SELECT * FROM " . $this->tbl .
               " WHERE " . CampaignProfileTable::C_STATUS . " = 1 ";

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

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

        return $rows;
    }
}
