<?php

/**
 * This is a class file used for Site Configuration 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 SiteConfigurationdetailMgmt.
 *
 * @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 siteConfigDetailMgmt
{

    /**
     * @var public $college_id This is the school code.
     */

    public $college_id;

    /**
     * @var public $config_id This is the config id feteched from the database(cms_siteconfigdetail).
     */

    public $config_id;

    /**
     * @var public $config_value This is the config value.
     */
    public $config_value;


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

    /**
     * This function is used to get a particular record.
     *
     * @param integer $college_id This is the database college_id.
     *
     * @return array
     */
    function getRecordById($config_id)
    {
        $qry = "SELECT * FROM cms_siteconfigdetail 
				 WHERE cms_siteconfigdetail.college_id= '" . $_SESSION["VedantnrSchoolId"] . "' ";

        if ($config_id != "") {
            $qry .= " and config_id='$config_id' ";
        }

        $out = dbQuery($qry);

        if (dbRows($out) > 0) {

            $row = dbArray($out);
            extract($row);

            $this->config_value = ($config_value);
            $this->config_id = ($config_id);
            $this->college_id = ($college_id);

            dbResult($out);
        }
    }


    /**
     * 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->config_count = 0;

        $qry = "SELECT 
					ssm.config_id,ssm.config_key,ssd.config_value
				FROM 
					sms_siteconfigmaster ssm left join cms_siteconfigdetail ssd
					ON ssm.config_id=ssd.config_id AND ssd.college_id= '" . $_SESSION["VedantnrSchoolId"] . "'
				WHERE ssm.config_level = '1'";

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

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

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

        $out = dbQuery($qry);

        if (dbRows($out) > 0) {
            $this->config_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->config_count = 0;

        $qry = "SELECT 
					ssm.config_id,ssm.config_key,ssd.config_value
				FROM 
					sms_siteconfigmaster ssm left join cms_siteconfigdetail ssd
					ON ssm.config_id=ssd.config_id AND ssd.college_id= '" . $_SESSION["VedantnrSchoolId"] . "'
				WHERE ssm.config_level = '1'";

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

        $out = dbQuery($qry);

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




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

        $Qry1 .= "config_id='" . Escape($this->config_id) . "',";
        $Qry1 .= "config_value='" . Escape($this->config_value) . "',";
        $Qry1 .= "college_id='" . Escape($_SESSION['aSchoolId']) . "',";
        $Qry1 .= "blnBackup = '0',";

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

        }
    }

    /**
     * This is a function for editing a Configuration record.
     *
     * @return void The redirect file name and the message are passed.
     *
     */
    function edit()
    {
        $Qry1 = "";

        $Qry1 .= "college_id='" . Escape($_SESSION['aSchoolId']) . "',";
        $Qry1 .= "config_id='" . Escape($this->config_id) . "',";
        $Qry1 .= "config_value='" . Escape($this->config_value) . "',";
        $Qry1 .= "blnBackup = '0',";

        if ($Qry1 != "") {
            $Qry1 = substr($Qry1, 0, strlen($Qry1) - 1);
            $qry = "update cms_siteconfigdetail set " . $Qry1 . " where college_id = '" . $_SESSION['aSchoolId'] . "' and config_id=" . $this->config_id;

            dbQuery($qry);
        }
    }
    /**
     * This is a function for deleting the subject record.
     *
     * @return void The redirect file name and the message are passed.
     *
     */
    function delete()
    {
        $qry = "delete from  cms_siteconfigdetail
             	where config_id in (" . $this->deleteConfig_Id . ")" . " AND college_id = '" . $_SESSION['aSchoolId'] . "'";
        dbQuery($qry);
    }

    function getMasterRecords($limit = 0, $start = 0, $condition = "", $order_field = "", $order_type = "")
    {
        $this->school_count = 0;

        $qry = "SELECT sms_siteconfigmaster.`config_key`,
				cms_siteconfigdetail.`config_id`,
				cms_siteconfigdetail.`config_value`,
				cms_siteconfigdetail.`college_id` 
				FROM sms_siteconfigmaster ,
				cms_siteconfigdetail 
				where sms_siteconfigmaster.config_id = cms_siteconfigdetail.config_id 
				and cms_siteconfigdetail.college_id= '" . $_SESSION["VedantnrSchoolId"] . "'";

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

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

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

        $out = dbQuery($qry);

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