<?php

class gallery
	{
		var $obj1;
		var $con;
		// constructor
		function __construct()
		{
			$this->obj1 = new dboperations();
			$this->con = $this->obj1-> dbconnect();
			
		}
		
		function getgallery($galleryid='',$fields='*',$sql='')
		{
			if ($galleryid!='')
			{
				$sqltext = "Select $fields from mstgallery where galleryid='".$galleryid."'";
				//echo $sqltext;
			}
			else if($sql!='')
			{
				$sqltext = $sql;
			}
			else
			{
				$sqltext = "Select $fields from mstgallery";
			}

			$prodapps = $this->obj1->select_query($sqltext);
			
			if ($prodapps)
			{
				$numrows = $this->obj1->numRows($prodapps);
			}
			if ($numrows ==1)
			{
				while ($prodappslist = mysqli_fetch_assoc($prodapps))
				{
					$prodappstr[] = $prodappslist;
				}	
			}
			else if($numrows > 1)
			{
				while ($prodappslist = mysqli_fetch_assoc($prodapps))
				{
					$prodappstr[] = $prodappslist;
				}
			}
			return $prodappstr;
		}
		
		
		function addgallery($applicationdata)
		{
			if (is_array($applicationdata)== false)
			{
				return false;
			}
			else
			{
				$fieldnames =  "(";
				$fieldvalues = "(";
				foreach ($applicationdata as $k => $v) 
				{
					
					$fieldnames .=  ($fieldnames=="(")?"$k":",$k";
					$fieldvalues .= ($fieldvalues=="(")?"'$v'":",'$v'";
				}
				$sqltext = "insert into mstgallery ".$fieldnames.") values ".$fieldvalues.")";
				//echo $sqltext;
				$applications = $this->obj1->insert_query($sqltext);
				return ($applications == 1)?"true":"false";
				
			}
		}
		function editgallery($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 mstgallery ".$fieldnamesvalues." where ".$wherecondition ;
				///echo $sqltext;
				$applications = $this->obj1->update_query($sqltext);
				return ($applications == 1)?"true":"false";
				
			}
		}
	}


class galleryphoto
	{
		var $obj1;
		var $con;
		// constructor
		function __construct()
		{
			$this->obj1 = new dboperations();
			$this->con = $this->obj1-> dbconnect();
			
		}
		
		function getgalleryphoto($photoid='',$fields='*',$sql='')
		{
			if ($promotionid!='')
			{
				$sqltext = "Select $fields from mstgalleryphotos where photoid='".$photoid."'";
			}
			else if($sql!='')
			{
				$sqltext = $sql;
			}
			else
			{
				$sqltext = "Select $fields from mstgalleryphotos";
			}
				
			$prodapps = $this->obj1->select_query($sqltext);
			
			if ($prodapps)
			{
				$numrows = $this->obj1->numRows($prodapps);
			}
			if ($numrows ==1)
			{
				while ($prodappslist = mysqli_fetch_assoc($prodapps))
				{
					$prodappstr[] = $prodappslist;
				}	
			}
			else if($numrows > 1)
			{
				while ($prodappslist = mysqli_fetch_assoc($prodapps))
				{
					$prodappstr[] = $prodappslist;
				}
			}
			return $prodappstr;
		}
		
		// example for adding product data		//            $data['productname'] = 'product1';
		//            $data['proudctdesc'] = "product desc";
		//            $data['productimagebig'] = '/images/product1.jpg';
		//            $data = $obj->addproduct($data);
		
		function addgalleryphoto($applicationdata)
		{
			if (is_array($applicationdata)== false)
			{
				return false;
			}
			else
			{
				$fieldnames =  "(";
				$fieldvalues = "(";
				foreach ($applicationdata as $k => $v) 
				{
					$fieldnames .=  ($fieldnames=="(")?"$k":",$k";
					$fieldvalues .= ($fieldvalues=="(")?"'$v'":",'$v'";
				}
				$sqltext = "insert into mstgalleryphotos ".$fieldnames.") values ".$fieldvalues.")";
				//echo $sqltext;
				$applications = $this->obj1->insert_query($sqltext);
				return ($applications == 1)?"true":"false";
				
			}
		}
		function editgalleryphoto($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 mstgalleryphotos ".$fieldnamesvalues." where ".$wherecondition ;
				//echo $sqltext;
				$applications = $this->obj1->update_query($sqltext);
				return ($applications == 1)?"true":"false";
				
			}
		}
		function deletegalleryphoto($photoid)
		{
			if($photoid)
			{
				$sqltext = "delete from mstgalleryphotos where photoid='".$photoid."'";
				$staffs = $this->obj1->delete_query($sqltext);
				return ($staffs == 1)?"true":"false";
			}
		}
		
	}

?>