<?php 

include("_dirinfo.php");

include (PATH_TO_ROOT."init.php");
include_once PATH_TO_ROOT.'_class/class.Extjs_grid.php';


class SimpleGrid extends MakeGrid 
{
	
	public function __construct()
	{
		$this->table = $table;
		$this->database = $database;
		parent::__construct();
	}
	
	public function createGridTable($table,$database)
	{
		
		$this->table = $table;
		$this->database = $database;
		//if we haven't manually added any columns it adds columns for each field in the table
		if(count($this->columns) == 0 )
		{ 
			global $MySQL_User,$MySQL_Pass;
			$db = new db();
			$db->SetDatabaseConnection($MySQL_User,$MySQL_Pass,$this->database);
			$rsp = $db->SQLexecute("SELECT * FROM $this->table LIMIT 1");
			
			$rsp = $db->fetchAssoc($rsp);
			
			foreach ($rsp as $col => $nvm) {
				$this->addColumn($col,$col);
			}
			$tmp =  parent::createStore();
			$tmp.= parent::createGrid();
			return $tmp;
		}
	}
	/**
	 * Creates a grid from an array
	 * If only one array is passed it asumes the first row contains the columns
	 *
	 * @param unknown_type $array
	 * @param unknown_type $arrayData
	 * @return unknown
	 */
	public function createGridArray($array,$arrayData=null)
	{
		if (!isset($arrayData))
		{
			$colArray = $array[0];
			for ($i = 1;$i<count($array);$i++)
			{
				$dataArray[] = $array[$i];
			}
		}
		else
		{
			$colArray = $array;
			$dataArray = $arrayData;
		}
		foreach ($colArray as $col) 
		{
			$this->addColumn($col,$col);
		}
		
	
		$this->dataArray = $dataArray;
		
		$tmp .=$this->createStore();
	//	$tmp .= 'Store'.$this->rndID.'.loadData(myData);';
		$tmp.= $this->createGrid();
		
		
		return $tmp;
		
		
	}
	
}

?>