<?php

/**
 * This is a class file used for  Site operations.
 *
 * PHP version 5
 *
 * @category Admin_Tool
 * @package  Admin_Tool
 * @author   Aum Infosys <admin@auminfosys.com>
 * @license  Aum Infosys
 * @version  CVS:1.0.1
 * @link     http://auminfosys.com/
 * @filesource
 */

/**
 * This is a class named SubjectMgmt.
 *
 * @category School Management System
 * @package  School Management System
 * @author   Aum Infosys <admin@auminfosys.com>
 * @license  Aum Infosys
 * @version  Release: 1.0.1
 * @link     http://auminfosys.com/
 *
 */



class SiteConfigMgmt
{
    /**
     * @var public $config_id This is the configration Id feteched from the database(cms_siteconfigmaster).
     */

    public $config_id;

    /**
     * @var public $config key This is the key value of site configration.
     */

    public $config_key;

    /**
     * @var public $config_value This is the configration value feteched from the database(cms_siteconfigmaster).
     */

    public $config_value;

    /**
     * @var public $config_level This is the configration level.
     */
    public $config_level;


    function SiteConfigMgmt()
    {
        $this->bullet = "<font size='2'>&raquo;</font>";
        $this->bullet = htmlentities($this->bullet);
        $this->site_count = 0;
    }


    /**
     * This is a function for getting the all records with/without condition
     *
     * @param integer $limit This is the limit of number or records.
     * @param integer $start This is the starting location of records.
     * @param string  $condition This is the condition for fetching records.	 
     * @param string  $order_field This is the field for fetching records orderby.	 
     * @param string  $order_type This is the order direction to fetch records orderby.	 	 
     *
     * @return Mix Result Set
     */
    function getAllRecords($limit = 0, $start = 0, $condition = "", $order_field = "", $order_type = "")
    {
        $this->school_count = 0;

        $qry = "SELECT * FROM cms_siteconfigmaster where 1=1 ";

        if ($condition != "") {
            $qry .= $condition;
        }

        if ($order_field != "" && $order_type != "") {
            $qry .= "";
        }

        if (intval($limit) > 0 && intval($start) >= 0) {
            $qry .= " Limit $start , $limit";
        }

        $out = dbQuery($qry);

        if (dbRows($out) > 0) {
            $this->site_count = dbRows($out);
            return $out;
        }
        return $out;

    }

    /**
     * This is a function for getting the total no of records with/without condition
     *
     * @param integer $limit This is the limit of number or records.
     * @param integer $start This is the starting location of records.
     * @param string  $condition This is the condition for fetching records.	 
     * @param string  $order_field This is the field for fetching records orderby.	 
     * @param string  $order_type This is the order direction to fetch records orderby.	 	 
     *
     * @return Total Records Found
     */
    function getCountRecords($limit = 0, $start = 0, $condition = "", $order_field = "", $order_type = "")
    {
        $this->user_count = 0;

        $qry = "SELECT Count(*) AS Count FROM cms_siteconfigmaster where 1=1 ";

        if ($condition != "") {
            $qry .= $condition;
        }


        $out = dbQuery($qry);

        if (dbRows($out) > 0) {
            $row = dbArray($out);
            extract($row);
            $this->site_count = $Count;
            dbResult($out);
        }
        return $this->site_count;
    }

    /**
     * This is a function for getting the SiteConfigValue of records with/without condition
     *
     * @param string  $config_key .	 	 
     *
     * @return SiteConfigValue.
     */
    function getSiteConfigValue($key)
    {
        $ConfigValue = "";
        $condition = "";
        $sql = "SELECT * FROM cms_siteconfigmaster Where config_key='" . $key . "'";
        $out = dbQuery($sql);
        if (dbRows($out) > 0) {
            $row = dbArray($out);
            extract($row);
            if ($config_level == 1) {
                $objsiteConfigDetailMgmt = new siteConfigDetailMgmt();
                $objsiteConfigDetailMgmt->getRecordById($config_id);
                $ConfigValue = $objsiteConfigDetailMgmt->config_value;
                if ($ConfigValue == "")
                    $ConfigValue = $config_value;

            } else {
                $ConfigValue = $config_value;
            }
            dbResult($out);
        }
        return $ConfigValue;
    }


    /**
     * This is a function for adding new record for Site configration.
     *
     * @return void The redirect file name and the message are passed.
     *
     */
    function add()
    {
        $Qry1 = "";

        $Qry1 .= "config_key='" . Escape($this->config_key) . "',";
        $Qry1 .= "config_value='" . Escape($this->config_value) . "',";
        $Qry1 .= "config_level='" . Escape($this->config_level) . "',";

        if ($Qry1 != "") {
            $Qry1 = substr($Qry1, 0, strlen($Qry1) - 1);
            $qry = "insert into cms_siteconfigmaster set " . $Qry1 . " ";
            dbQuery($qry);

        }
    }

    /**
     * This is a function for editing a site config record.
     *
     * @return void The redirect file name and the message are passed.
     *
     */
    function edit()
    {
        $Qry1 = "";
        $Qry1 .= "config_value='" . Escape($this->config_value) . "',";
        if ($Qry1 != "") {
            $Qry1 = substr($Qry1, 0, strlen($Qry1) - 1);
            $qry = "update cms_siteconfigmaster set " . $Qry1 . " where config_key='" . $this->config_key . "'";

            dbQuery($qry);
        }
    }
    /**
     * This is a function for deleting the site configration  record.
     *
     * @return void The redirect file name and the message are passed.
     *
     */
    function delete()
    {
        $qry = "delete from  cms_siteconfigmaster where config_id in (" . $this->deleteConfig_Id . ")";

        dbQuery($qry);
    }

}
?>