<?
include_once "db/dbElemento.class.php";

class dbProduto extends dbElemento{


function setInsert($table, $idCat, $data){
      
		$strip=get_magic_quotes_gpc();
	  
		$camposBD=$this->getCampos($table) ;
		//if (empty($data['id'])) array_shift($camposBD);
		$data['id']=$data['codigo'];

		$sep="";
        foreach ($camposBD as $c){
			if ($strip) stripslashes($data[$c]);
			$data[$c]=mysql_real_escape_string($data[$c]);			
			$cam.="$sep $c ";
			$val.="$sep '".$data[$c]."'";			
			if ($sep=="") $sep=",";
        }
            
        $sql="insert into $table (".$cam.") values (".$val.") ";

        $this->set($sql);
        $id= $data['id'];
        $this->setOrder($table, $idCat, $id);
		
		return $id;
	}	

	
	function setUpdate($table, $idcat, $data, $id){
        
		$strip=get_magic_quotes_gpc();
		
		$camposBD=$this->getCampos($table) ;
		//array_shift($camposBD);
		$data['id']=$data['codigo'];

		$sql="update $table set ";
		$sep="";
        foreach ($camposBD as $c){
			if ($strip) stripslashes($data[$c]);
			$data[$c]=mysql_real_escape_string($data[$c]);
			
			$sql.="$sep $c = '".$data[$c]."'";
			if ($sep=="") $sep=",";
        }
        $sql.=" where id=$id";
		
        $this->set($sql);

	}
	

}