<?php
class Mdb extends Model
{
	function Mdb()
	{
		parent::Model();
		//$this->db->simple_query('SET NAMES utf8');
	}
	
	function get_field_names($tablaneve)
	{
		return $this->db->list_fields($tablaneve);
	}
	
	function set_empty_array($tablaneve)
	{
		$t = array();
		$arr = $this->get_field_names($tablaneve);
		foreach ($arr as $elem)
		{
			$t[$elem] = "";
		}
		
		
		return $t;
	}

	function set_empty_object($tablaneve)
	{
		$obj = new UresObj();
		
		$arr = $this->get_field_names($tablaneve);
		
				
		foreach ($arr as $elem)
		{
			$obj->add($elem,"");
		}
		
		return $obj;
		
	}


	function set_post_array($tablaneve)
	{
		$t = array();
		$arr = $this->get_field_names($tablaneve);
		foreach ($arr as $elem)
		{
			$t[$elem] = $this->input->post($elem);
		}
		
		return $t;
		
	}
	
	
	function set_post_object($tablaneve)
	{
		$t = new UresObj();
		$arr = $this->get_field_names($tablaneve);
		foreach ($arr as $elem)
		{
			$t->$elem = $this->input->post($elem);
		}
		return $t;
	}


	function insert_ignore($array,$table)
	{
		$query = "INSERT IGNORE INTO ".$table." SET ";
		$count = count($array);
		$i = 0;
	
		if ($count == 0){return false;}
		
		foreach($array as $key => $value)
		{
			$i++;
			if (!is_numeric($value))
			{
				$value = mysql_real_escape_string($value);
			}
			$query.=$key."='".$value."'";
			if ($i != $count)
			{
				$query.=", ";
			}
		}
		$this->db->simple_query($query);
	}



	
	function fetch_map($tabla,$mezo,$where_mezo,$where_ertek,$orderby,$orderby_irany="ASC",$limit=999)
	{
		$mezok = $this->query("select $mezo from $tabla where $where_mezo=$where_ertek oder by $orderby $orderbyidany limit $limit",-1)->rows;
		//$e = $this->ldb->select($mezo)->from($tabla)->where($where_mezo,$where_ertek)->orderby($orderby,$orderby_irany)->limit($limit)->get();
		$ret = array();
		
		foreach ($mezok as $m)
		{
			$ret[]=$m->$mezo;
		}
		
		return $ret;
	}
}


class UresObj
{
	function add($nev, $ertek)
	{
		$this->$nev = $ertek;
	}
}


		
?>