<?php
	class Currencies
	{
		function __construct()
		{
			$this->obj1 = new dbopenconn();
			$this->con = $this->obj1-> dbconnect();
		}
		
		// get list of or single compani(es) from database
		function getCurrencies($CurrencyID='',$sql='',$debugquery='',$fields='*')
		{
			if ($CurrencyID!="")
			{
				$sqltext = "Select $fields from mstcurrencies where currencyid='".$CurrencyID."'";
			}
			else if ($sql!="")
			{
				$sqltext = $sql;
			}
			else
			{
				$sqltext = "Select $fields from mstcurrencies";
			}
				
			$companies = $this->obj1->select_query($sqltext);
			
			if ($companies)
			{
				$numrows = $this->obj1->numRows($companies);
			}
			if ($numrows ==1)
			{
				while ($companylist = mysqli_fetch_assoc($companies))
				{
					$compstr[] = $companylist;
				}	
			}
			else if($numrows > 1)
			{
				while ($companylist = mysqli_fetch_assoc($companies))
				{
					$compstr[] = $companylist;
				}
			}
			return $compstr;
		
		}
		function getCurrencyValue($CurrencyID='',$sql='',$debugquery='',$fields='*',$date='')
		{
			if ($date !="")
			{
				$subsql = " and dateofentry = '".$date."'";
			}
			if ($CurrencyID!="")
			{
				$sqltext = "Select $fields from mstcurrencies a,trncurrencyvalues b where a.currencyid=b.currencyid and a.currencyid='".$CurrencyID."'".$subsql;
			}
			else if ($sql!="")
			{
				$sqltext = $sql;
			}
			else
			{
				//$sqltext = "Select $fields from mstcurrencies";
				$sqltext = "Select $fields from mstcurrencies a,trncurrencyvalues b where a.currencyid=b.currencyid ".$subsql;
			}
				
			$companies = $this->obj1->select_query($sqltext);
			
			if ($companies)
			{
				$numrows = $this->obj1->numRows($companies);
			}
			else if ($subsql !="")
			{
				$sqltext = "Select $fields from mstcurrencies a,trncurrencyvalues b where a.currencyid=b.currencyid order by currencyvalueid desc";
				$companies = $this->obj1->select_query($sqltext);
				if ($companies)
				{
					$numrows = $this->obj1->numRows($companies);
				}
			}
			if ($numrows ==1)
			{
				while ($companylist = mysqli_fetch_assoc($companies))
				{
					$compstr[] = $companylist;
				}	
			}
			else if($numrows > 1)
			{
				while ($companylist = mysqli_fetch_assoc($companies))
				{
					$compstr[] = $companylist;
				}
			}
			return $compstr;
		
		}
		// add company to database
		
		function AddCurrency($CompanyData)
		{
		if (is_array($CompanyData)== false)
			{
				return false;
			}
			else
			{
				$fieldnames =  "(";
				$fieldvalues = "(";
				foreach ($CompanyData as $k => $v) 
				{
					
					$fieldnames .=  ($fieldnames=="(")?"$k":",$k";
					$fieldvalues .= ($fieldvalues=="(")?"'$v'":",'$v'";
				}
				$sqltext = "insert into mstcurrencies ".$fieldnames.") values ".$fieldvalues.")";
				//echo $sqltext;
				$applications = $this->obj1->insert_query($sqltext);
				
				return ($applications == 1)?"true":"false";
			}
		
		}
		
		function EditCurrency($applicationdata,$wherecondition)
		{
			if (is_array($applicationdata)== false)
			{
				return false;
			}
			else
			{
				$fieldnamesvalues =  "set ";
				
				foreach ($applicationdata as $k => $v) 
				{
					$fieldnamesvalues .=  ($fieldnamesvalues =="set ")?"$k='$v'":",$k='$v'";
				}
				$sqltext = "update mstcurrencies ".$fieldnamesvalues." where ".$wherecondition ;
				//echo $sqltext;
				$applications = $this->obj1->update_query($sqltext);
				return ($applications == 1)?"true":"false";
				
			}
		}
		
		function DeleteCurrency($applicationdata)
		{
			if($applicationdata)
			{
				$sqltext = "delete from mstcurrencies where currencyid='".$applicationdata."'";
				$applications = $this->obj1->delete_query($sqltext);
				return ($applications == 1)?"true":"false";
			}
		
		}
	}
	
	class CurrenciesValues
	{
		function __construct()
		{
			$this->obj1 = new dbopenconn();
			$this->con = $this->obj1-> dbconnect();
		}
		
		// get list of or single compani(es) from database
		function getCurrencyValues($CurrencyID='',$sql='',$debugquery='',$fields='*')
		{
			if ($CurrencyID!="")
			{
				$sqltext = "Select $fields from trncurrencyvalues where currencyvalueid='".$CurrencyID."'";
			}
			else if ($sql!="")
			{
				$sqltext = $sql;
			}
			else
			{
				$sqltext = "Select $fields from trncurrencyvalues";
			}
				
			$companies = $this->obj1->select_query($sqltext);
			
			if ($companies)
			{
				$numrows = $this->obj1->numRows($companies);
			}
			if ($numrows ==1)
			{
				while ($companylist = mysqli_fetch_assoc($companies))
				{
					$compstr[] = $companylist;
				}	
			}
			else if($numrows > 1)
			{
				while ($companylist = mysqli_fetch_assoc($companies))
				{
					$compstr[] = $companylist;
				}
			}
			return $compstr;
		
		}
		// add company to database
		function AddCurrencyValue($CompanyData)
		{
		if (is_array($CompanyData)== false)
			{
				return false;
			}
			else
			{
				$fieldnames =  "(";
				$fieldvalues = "(";
				foreach ($CompanyData as $k => $v) 
				{
					
					$fieldnames .=  ($fieldnames=="(")?"$k":",$k";
					$fieldvalues .= ($fieldvalues=="(")?"'$v'":",'$v'";
				}
				$sqltext = "insert into trncurrencyvalue ".$fieldnames.") values ".$fieldvalues.")";
				//echo $sqltext;
				$applications = $this->obj1->insert_query($sqltext);
				
				return ($applications == 1)?"true":"false";
			}
		
		}
		
		function EditCurrencyValue($applicationdata,$wherecondition)
		{
			if (is_array($applicationdata)== false)
			{
				return false;
			}
			else
			{
				$fieldnamesvalues =  "set ";
				
				foreach ($applicationdata as $k => $v) 
				{
					$fieldnamesvalues .=  ($fieldnamesvalues =="set ")?"$k='$v'":",$k='$v'";
				}
				$sqltext = "update trncurrencyvalues ".$fieldnamesvalues." where ".$wherecondition ;
				//echo $sqltext;
				$applications = $this->obj1->update_query($sqltext);
				return ($applications == 1)?"true":"false";
				
			}
		}
		
		function DeleteCurrencyValue($applicationdata)
		{
			if($applicationdata)
			{
				$sqltext = "delete from trncurrencyvalues where currencyvalueid='".$applicationdata."'";
				$applications = $this->obj1->delete_query($sqltext);
				return ($applications == 1)?"true":"false";
			}
		
		}
	}





?>