<?php
/**
 * This is a class file used for Employee 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 NewsFileMgmt.
 *
 * @category Employee Management System
 * @package  Employee Management System
 * @author   Aum Infosys <admin@auminfosys.com>
 * @license  Aum Infosys
 * @version  Release: 1.0.1
 * @link     http://auminfosys.com/
 *
 */

class NewsFileMgmt
{
    /**
     * @var public $file_id This is the News Id.
     */
    public $file_id;

    /**
     * @var public $news_id This is the News Display.
     */
    public $news_id;

    /**
     * @var public $file_title This is the News Title.
     */
    public $file_title;

    /**
     * @var public $file_name This is the News Short Description.
     */
    public $file_name;


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

    /**
     * This function is used to get a particular record.
     *
     * @param integer $file_id This is the database file_id.
     *
     * @return array
     */
    function getRecordById($file_id)
    {
        $qry = "select * from com_newsfile where 1=1 ";

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

        $out = dbQuery($qry);

        if (dbRows($out) > 0) {
            $this->employee_count = 1;

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

            $this->file_id = ($file_id);
            $this->news_id = ($news_id);
            $this->file_title = ($file_title);
            $this->file_name = ($file_name);


            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->employee_count = 0;

        $qry = "SELECT * 
				FROM com_newsfile
				WHERE 1=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";
        }

        //print $qry;
        $out = dbQuery($qry);

        if (dbRows($out) > 0) {
            return $out;
        }
        return $out;


    }


    /**
     * This is a function for adding new record for Employee.
     *
     * @return void The redirect file name and the message are passed.
     *
     */
    function add()
    {
        $qry = " INSERT INTO com_newsfile SET ";
        $qry .= "news_id = '" . Escape($this->news_id) . "', ";
        $qry .= "file_title = '" . Escape($this->file_title) . "' ";

        //echo $qry;

        if ($qry != "") {
            dbQuery($qry);
            $this->file_id = dbInsertedId();
        }
    }

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

        $qry .= "news_id = '" . Escape($this->news_id) . "', ";
        $qry .= "file_title = '" . Escape($this->file_title) . "' ";


        $qry .= " WHERE file_id = '" . $this->file_id . "' ";

        if ($qry1 != "") {
            dbQuery($qry);
        }
    }

    /**
     * This is a function for deleting the Employee record.
     *
     * @return void The redirect file name and the message are passed.
     *
     */
    function delete()
    {
        $qry = "DELETE FROM com_newsfile WHERE file_id IN (" . $this->file_id . ")";
        dbQuery($qry);
    }

    function updatefile()
    {
        $qry = "update com_newsfile 
				set file_name = '" . $this->file_name . "'
             	where news_id =   '" . $this->news_id . "' and file_id=" . $this->file_id;

        dbQuery($qry);
    }

}
?>