<?php

/**
 * This is a class file used for School 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 companyMgmt.
 *
 * @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 companyMgmt
{
    /**
     * @var public $company_id This is the School Id feteched from the database(lms_companymaster).
     */
    public $company_id;
	
	/**
     * @var public $company_name This is the School Name feteched from the database(lms_companymaster).
     */
    public $company_name;
    
	/**
     * @var public $company_address This is the school address.
     */
    public $company_address;
	
	/**
     * @var public $company_phone This is the School phone.
     */
    public $company_phone;
	
	/**
     * @var public $company_fax This is the School fax.
     */
	public $company_fax;
	
	/**
     * @var public $company_email This is the School email id.
     */
	public $company_email;
	
	/**
     * @var public $company_website This is the School URL.
     */
	public $company_website;
	/**
     * @var public $company_website This is the School URL.
     */
	public $company_regno;
	/**
     * @var public $company_website This is the School URL.
     */
	public $company_slogan;
	public $company_tinno;   	
	public $company_cstno; 	
	public $company_servicetaxno; 	
	public $company_panno;
	
	
	public $createdby;
	
	/**
     * @var public $createdon This is the School createdon.
     */
	public $createdon;
	
	//this below function is common
	
	/**
     * @var public $company_description This is the message.
     */
    public $company_description;
    /**
     * @var public $company_count This is a counter.
     */
    public $company_count;
    /**
     * @var public $school_redirectfile This is file name to be redirected on after the operation.
     */
  
	public $company_logo;

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

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

        if ($company_id!="") {
            $qry.=" and company_id='".$_SESSION['cCompany_id']."' ";
        }

        $out=dbQuery($qry);

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

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

            $this->company_id				= ($company_id);
			$this->company_name				= ($company_name);
			$this->company_address			= ($company_address);
			$this->company_phone				= ($company_phone);
			$this->company_fax				= ($company_fax);
			$this->company_email			= ($company_email);
			$this->company_website				= ($company_website);
			
			$this->company_regno	= ($company_regno);
			$this->company_slogan	= ($company_slogan);
										
			dbFreeResult($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->company_count=0;
		
		$qry = "SELECT  count(*) FROM lms_companymaster 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";
        }
        $out=dbQuery($qry);

        if (dbRows($out)>0) {
            $this->company_count=dbRows($out);            
			dbFreeResult($out);
        }
		return $this->company_count;
    }
	
	/**
     * 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->company_count=0;
				
		$qry = "SELECT * FROM lms_companymaster 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";
        }
        // echo $qry;exit;
        $out=dbQuery($qry);

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

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

            $Qry1 .= "company_name='"	      .Escape($this->company_name)."',";			
            $Qry1 .= "company_address='"	  .replaceHtmlEditor(Escape($this->company_address))."',";
			$Qry1 .= "company_phone='"	      .Escape($this->company_phone)."',";
		    $Qry1 .= "company_fax='"	      .Escape($this->company_fax)."',";
            $Qry1 .= "company_email='"	      .Escape($this->company_email)."',";			
            $Qry1 .= "company_website='"	  .Escape($this->company_website)."',";
    	    $Qry1 .= "company_regno='"	      .Escape($this->company_regno)."',";
			$Qry1 .= "company_description='"   .replaceHtmlEditor(Escape($this->company_description))."',";
			
			
			 $Qry1 .= "company_tinno='"	      .Escape($this->company_tinno)."',";
            $Qry1 .= "company_cstno='"	      .Escape($this->company_cstno)."',";			
            $Qry1 .= "company_servicetaxno='"	  .Escape($this->company_servicetaxno)."',";
    	    $Qry1 .= "company_panno='"	      .Escape($this->company_panno)."',";
			    	
 	
 	

		    $Qry1 .= "company_slogan='"	       .Escape($this->company_slogan)."',";
		    $Qry1 .= "createdby='"	           .Escape($_SESSION['cUserId'])."',";			
            $Qry1 .= "createdon='"	           .Escape(date('Y-m-d h:i:s'))."',";
						
						
            if ($Qry1 != "") {
                $Qry1 = substr($Qry1, 0, strlen($Qry1)-1);
                $qry = "insert into lms_companymaster set " . $Qry1 . " ";
                dbQuery($qry);
                $this->company_id=dbInsertedId();
				
				if ($this->company_id > 0) {
					$this->CreateCompanyFolder($this->company_id);
				}
            }
    }

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

          $Qry1 = "";

            $Qry1 .= "company_name='"	      .Escape($this->company_name)."',";			
            $Qry1 .= "company_address='"	  .replaceHtmlEditor(Escape($this->company_address))."',";
			$Qry1 .= "company_phone='"	      .Escape($this->company_phone)."',";
		    $Qry1 .= "company_fax='"	      .Escape($this->company_fax)."',";
            $Qry1 .= "company_email='"	      .Escape($this->company_email)."',";			
            $Qry1 .= "company_website='"	  .Escape($this->company_website)."',";
    	    $Qry1 .= "company_regno='"	      .Escape($this->company_regno)."',";
			$Qry1 .= "company_description='"   .replaceHtmlEditor(Escape($this->company_description))."',";
			
			
			 $Qry1 .= "company_tinno='"	      .Escape($this->company_tinno)."',";
            $Qry1 .= "company_cstno='"	      .Escape($this->company_cstno)."',";			
            $Qry1 .= "company_servicetaxno='"	  .Escape($this->company_servicetaxno)."',";
    	    $Qry1 .= "company_panno='"	      .Escape($this->company_panno)."',";
			    	
 	
 	

		    $Qry1 .= "company_slogan='"	       .Escape($this->company_slogan)."',";
		    $Qry1 .= "createdby='"	           .Escape($_SESSION['cUserId'])."',";			
            $Qry1 .= "createdon='"	           .Escape(date('Y-m-d h:i:s'))."',";
						
            if ($Qry1 != "") {
                $Qry1 = substr($Qry1, 0, strlen($Qry1)-1);
                 $qry = "update lms_companymaster set " . $Qry1 . " where company_id='".$this->company_id."'";
                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  lms_companymaster 
             	where company_id in (".$this->deleteId.") ";
        dbQuery($qry);
   	}

  
  function CreateCompanyFolder($company_id) 
  {
  
   global $SiteDefaultImage;
   global $SiteImagePath ;
   global $SiteImageHeight;
   global $EmployeeImagePath ;
   global $CompanyImagePath;
   global $ProductImagePath;
	    
		
  	 if(!is_dir(str_replace("/".$_SESSION["cCompany_id"]."/","/".$company_id."/",$CompanyImagePath))) {
	  
	    $schimpath=(str_replace("/".$_SESSION["cCompany_id"]."/","/".$company_id."/",$CompanyImagePath));
	  
		mkdir($schimpath, 0777);
		chmod($schimpath, 0777);
		
		copy($SiteImagePath.$SiteDefaultImage,$schimpath.$SiteDefaultImage);
		$file_path=realpath($schimpath);
		chmod($file_path, 0755);
	 }
	 if(!is_dir(str_replace("/".$_SESSION["cCompany_id"]."/","/".$company_id."/",$EmployeeImagePath))) {
		
		$Emppath=(str_replace("/".$_SESSION["cCompany_id"]."/","/".$company_id."/",$EmployeeImagePath));
		
		mkdir($Emppath, 0777);
		chmod($Emppath, 0777);
		
		//copy($SiteImagePath.$SiteDefaultImage, $Emppath.$SiteDefaultImage);
		$file_path=realpath($Emppath);
		chmod($file_path, 0755);
	 }
	 if (!is_dir(str_replace("/".$_SESSION["cCompany_id"]."/","/".$company_id."/",$ProductImagePath))) {
		
		$pudpath=(str_replace("/".$_SESSION["cCompany_id"]."/","/".$company_id."/",$ProductImagePath));
		mkdir($pudpath, 0777);
		chmod($pudpath, 0777);
		
		//copy($SiteImagePath.$SiteDefaultImage, $pudpath.$SiteDefaultImage);
		$file_path=realpath($pudpath);
		chmod($file_path, 0755);
	 }
  }
  
/**
 * This is a function for updating the Student Photo.
 *
 * @return void The redirect file name and the message are passed.
 *
 */
    function updatePhoto()
    {			
		$qry = "update lms_companymaster 
				set company_logo = '".$this->company_logo."'
             	where company_id ='".$this->company_id."'";
      
	    dbQuery($qry);
   	}
}
?>