<?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 NewsMgmt.
 *
 * @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 NewsMgmt
{
    /**
     * @var public $news_id This is the News Id.
     */
    public $news_id;

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

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

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

    /**
     * @var public $news_longdesc This is the News Long Description.
     */
    public $news_longdesc;

    /**
     * @var public $news_date This is the News Date.
     */
    public $news_date;

    /**
     * @var public $news_active This is the News Active.
     */
    public $news_active;

    /**
     * Constructor to inialize employee_count to zero
     *
     */
    function NewsMgmt()
    {
        $this->bullet = "<font size='2'>&raquo;</font>";
        $this->bullet = htmlentities($this->bullet);
    }

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

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

        //$qry.=$condition;

        $out = dbQuery($qry);

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

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

            $this->news_id = ($news_id);
            $this->news_display = ($news_display);
            $this->news_title = ($news_title);
            $this->news_shortdesc = ($news_shortdesc);
            $this->news_longdesc = ($news_longdesc);
            $this->news_date = ($news_date);
            $this->news_active = ($news_active);

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


        $qry = "SELECT * 
				FROM com_news
				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 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 getDownloadById($news_id)
    {
        $qry = "SELECT * 
				FROM  com_newsfile 
				WHERE news_id=$news_id ";

        $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()
    {
        global $SQLDateFormat;
        $qry = " INSERT INTO com_news SET ";

        $qry .= "news_display = '" . Escape($this->news_display) . "', ";
        $qry .= "news_title = '" . Escape($this->news_title) . "', ";
        $qry .= "news_shortdesc = '" . replaceHtmlEditor(Escape($this->news_shortdesc)) . "', ";
        $qry .= "news_longdesc = '" . replaceHtmlEditor(Escape($this->news_longdesc)) . "', ";
        $qry .= "news_date = STR_TO_DATE('" . Escape($this->news_date) . "','$SQLDateFormat'), ";
        $qry .= "news_active = '" . Escape($this->news_active) . "' ";

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

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

        $qry .= "news_display = '" . Escape($this->news_display) . "', ";
        $qry .= "news_title = '" . Escape($this->news_title) . "', ";
        $qry .= "news_shortdesc = '" . replaceHtmlEditor(Escape($this->news_shortdesc)) . "', ";
        $qry .= "news_longdesc = '" . replaceHtmlEditor(Escape($this->news_longdesc)) . "', ";
        $qry .= "news_date = STR_TO_DATE('" . Escape($this->news_date) . "','$SQLDateFormat'),";
        $qry .= "blnBackup = '0',";
        $qry .= "news_active = '" . Escape($this->news_active) . "' ";


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

        if ($qry != "") {
            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_news WHERE news_id IN (" . $this->news_id . ")";
        dbQuery($qry);
    }
}
?>