<?php
/**
 * This is a class file used for Subject 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 YearMgmt
{
    /**
     * @var public $subject_id This is the Subject Id feteched from the database(sms_subjectmaster).
     */

    public $year_id;

    /**
     * @var public $subject_order This is the subject code.
     */

    public $year_name;

    public $year_active;

    /**
     * @var public $subject_name This is the Subject Name feteched from the database(sms_subjectmaster).
     */

    public $transfer_student;

    /**
     * @var public $subject_order This is the Subject order.
     */
    public $transfer_fees;



    /**
     * 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 = "")
    {

        $qry = "SELECT * FROM cms_yearmaster 
				WHERE cms_yearmaster.year_name in (" . $this->year_name . ")";

        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);

        return $out;
    }


    function add()
    {
        $Qry1 = "";

        $Qry1 .= "year_name='" . Escape($this->year_name) . "',";
        $Qry1 .= "year_active='1',";
        $Qry1 .= "transfer_student = '0',";
        $Qry1 .= "transfer_fees = '0',";

        if ($Qry1 != "") {
            $Qry1 = substr($Qry1, 0, strlen($Qry1) - 1);
            $qry = "insert into cms_yearmaster set " . $Qry1 . " ";
            dbQuery($qry);
            $this->year_id = dbInsertedId();
        }
    }

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

        if ($Qry1 != "") {
            $Qry1 = substr($Qry1, 0, strlen($Qry1) - 1);
            $qry = "update cms_yearmaster set " . $Qry1;

            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_yearmaster
             	where year_id in (" . $this->year_id . ")";

        dbQuery($qry);
    }

    /**
     * This is a function for getting currenr year id.
     *
     * @return year_id
     *
     */
    function get_year_id()
    {
        $local_year_id = 0;

        $qry = "select year_id from  cms_yearmaster
             	  where year_active = 1";
        dbQuery($qry);

        $out = dbQuery($qry);

        $total = dbRows($out);

        if ($total > 0) {
            $row = dbArray($out);
            $local_year_id = $row["year_id"];
            return $local_year_id;
        }
    }
    function getyear($year_id)
    {

        $qry = "SELECT year_name FROM cms_yearmaster WHERE year_id = $year_id";
    
        $out = dbQuery($qry);

        return $out;
    }
}
?>