<?php
include_once("auth.php");
include "mod/grafico/grafico.class.php";
include_once ("base/lista.class.php");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//PT">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	<title>Graficos</title>
	<script type="text/javascript" src="js/jquery-1.2.3.pack.js"></script>
	<link rel="STYLESHEET" type="text/css" href="admin.css">
<? if ($_REQUEST['campo']) $_SESSION['campo']=$_REQUEST['campo']; echo $_REQUEST['campo']?>
<script type="text/javascript">





function escolhe(url){

	if(url != null) {
		
		var campo="<?=$_SESSION['campo']; ?>";
		
		$('#grafico1').load("insertgrafico.php?id=" + url, function() { 
		var myhtml= $('#grafico1').html();
		
		alert ("Por favor confirme o gráfico"); 
		
		
		//pai.value=myhtml;

		
		pai=eval("window.opener.document.dataform." + campo);
		alert(pai.value);
		
		pai.value=url;
		
		alert(pai.value);
		
		
		
		self.close();

		//alert (myhtml); 
		//var B = FCK.InsertHtml(decodeURI(myhtml));
		//self.close();
		});

	}
	
	
}


function muda(tipo, idCat){
	document.location.href="grafico.popup.php?campo="+campo+"&idCat=" + idCat;
}


function mudaOffset(offset){
document.location.href="main.php?campo="+campo+"&offset=" + offset;
}

function replace(string,text,by) {
var strLength = string.length, txtLength = text.length;
if ((strLength == 0) || (txtLength == 0)) return string;
var i = string.indexOf(text);
if ((!i) && (text != string.substring(0,txtLength))) return string;
if (i == -1) return string;
var newstr = string.substring(0,i) + by;
if (i+txtLength < strLength)
newstr += replace(string.substring(i+txtLength,strLength),text,by);
return newstr;
}
</script>
</head>

<body >

<form enctype="multipart/form-data" name="dataform" action="imagem.popup.php" method="POST">
<?
class listaGrafico extends lista{

	
    function tabela($setas=false, $caixas=true){
            $max= sizeof($this->dados);
			$i=0;
            foreach($this->dados as $t){
    			//$linkId='?idD=' . $t["id"] . '&id=' . $_REQUEST['idOld'] . '&idCatD='. $_REQUEST['idCatD']. "&tipoD=" . $_REQUEST["tipoD"];
                $linkId="javascript:escolhe('" . $t["id"] ."')";
            	$linkEditar='<a href='. $linkId ;
                //$linkApagar='<a href="void(null)"';
                $linha=($i % 2)?"1":"0";
                echo '<tr class="linha' . $linha . '">';            
                foreach ($t as $l=>$c){
					if ($l == "objecto") continue;
                	echo "<td>" .$linkEditar . ">$c</a></td>";
                }
				print '<td height="20" width=110 align="left">';
                echo "</td></tr>\n";        
				$i++;
    		}
    }
    
    function toolbars(){
                
        $toolbar= new toolbar(); 
		$toolbar->botao("Novo");
		$toolbar->ini();
		$toolbar->nav($this->req['offset'], $this->req['limit'], $this->req['total']);
		$toolbar->ini();
		$toolbar->categoria("grafico", "categoria", $this->req['idCat'], true);
		$toolbar->procurar($this->req['procurar']);   //mudar para campo
		$toolbar->botao("procurar", 90);
		$toolbar->fim();

    }	
	

   
    
}
///////////////////////////////////////////////////////////

class graficoPopup extends grafico{
	
	function graficoPopup(){
		$this->req=$_REQUEST;
		$this->req['limit']=50;
		
		$this->idCat=$this->req['idCat'];
		$this->tipo="grafico";
		
		if ($this->req['cmd']=="editar")$this->editar(); else $this->listar();

	}
		
	function listar(){
		$campos=array("Nr"=>"id","Titulo"=> "titulo" , "Largura"=>"largura", "Altura"=>"altura", "Objecto"=>"objecto");

		$db= new dbElemento;
		
		$dados=$db->getLista("grafico", $this->idCat, $campos , "id", 2 ,0, 50, $this->req['procurar']);

		$f= new listaGrafico($campos, $dados, $this->req);
		
		$f->titulo("Gráficos");
		$f->toolbars();
		$f->cabecaSimples();
		$f->tabela(true);
		$f->mostra();	
	}
	


}

$a=new graficoPopup;


?>
</form>
<div id="grafico1"></div>
</body>
