<?php

class allform
	{
		var $obj1;
		var $con;
		// constructor
		function __construct()
		{
			$this->obj1 = new dboperations();
			$this->con = $this->obj1-> dbconnect();
			
		}
		
		function getallform($allformid='',$fields='*',$sql='')
		{
			if ($allformid!='')
			{
				$sqltext = "Select $fields from ".ALLFORM_TABLE." where formid='".$allformid."'";
			}
			else if($sql!='')
			{
				$sqltext = $sql;
			}
			else
			{
				$sqltext = "Select $fields from ".ALLFORM_TABLE."";
			}
			//echo $sqltext;
			$prodapps = $this->obj1->select_query_mainconnection($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 addallform($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 ".ALLFORM_TABLE." ".$fieldnames.") values ".$fieldvalues.")";
			//	echo $sqltext;
			//	die();
				$applications = $this->obj1->insert_query_mainconnection($sqltext);
				return ($applications == 1)?"true":"false";
				
			}
		}
		function editallform($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 ".ALLFORM_TABLE." ".$fieldnamesvalues." where ".$wherecondition ;
				//echo $sqltext;
				$applications = $this->obj1->update_query_mainconnection($sqltext);
				return ($applications == 1)?"true":"false";
				
			}
		}
	}
