<?
require("../clases/blog.class.php");
require("../clases/interesblog.class.php");
require("../clases/blog_datos.class.php"); $objbd = new blog_datos();
$obji = new interesblog();
$obj = new blog();
$t = $_REQUEST["text"];
if($t=="R"){	
        echo $id = $obj->Correlativo();
		 $idp = $_REQUEST['idpersona'];	
		 $a = $_REQUEST["titulo"];	
		 $d = $_REQUEST["detalle"];		
		 $e = $_REQUEST["estado"];	
		 $f = date("Y-m-d");	
		if($obj->Crear($id,$idp,$a,$d,$e,$f)){		
					echo "<script languaje=javascript>\n"; 
	 				echo "alert('Entrada Registrada!!!');location.href ='../listablog.php?id=$idp';";					
	 				echo "</script>"; 
							
		}else{
		       echo "no pasa nada";
		     }
}

if($t=="M"){
         $idp = $_REQUEST['idpersona'];	/////para redireccionar	
         $id = $_REQUEST['idblog'];	
		 $a = $_REQUEST["titulo"];	
		 $d = $_REQUEST["detalle"];		
		 $e = $_REQUEST["estado"];
		if($obj->Actualizar($id,$a,$d,$e)){		
					echo "<script languaje=javascript>\n"; 
	 				echo "alert('Entrada Modificada Correctamente!!!');location.href ='../listablog.php?id=$idp';";					
	 				echo "</script>"; 
							
		}else{
		       echo "no pasa nada";
		     }
}

if($t=="V")
{
   $idp = $_REQUEST['idpersona'];
   $id = $_REQUEST['idblog'];
   if($obj->BuscarPorCodigo($id))
   {
     $visitas = $obj->getVisitas();
	 $cont = $visitas + 1;
		if($obj->ActualizarVisitas($id,$cont))
		{
		  if($objbd->Crear($id,$idp,1))
		  {
		    echo "<script languaje=javascript>\n"; 
	 		echo "location.href ='../frmblogver.php?idblog=$id&idpersona=$idp';";				
	 		echo "</script>";
		  }
		}else{
		      echo "visita no actualizó";
		     }
   }
}


if($t=="L")
{ 
   $idp = $_REQUEST['idpersona'];
   $id = $_REQUEST['idblog'];
   
   if($obji->Verificar($id,$idp))
   {
     if($obji->Eliminar($id,$idp)) 
	 {
	   if($obj->BuscarPorCodigo($id))
	   {
	      $interes=$obj->getInteres();
		  $con = $interes-1;
		  if($obj->ActualizarInteres($id,$con))
		  {
		     echo "<script languaje=javascript>\n"; 
			 echo "location.href ='../frmblogver.php?idblog=$id&idpersona=$idp';";				
			 echo "</script>";
		  }
	   }
	 }     
   }else{
           if($obji->Crear($id,$idp,1))
			{
			   $lista = $obji->ListarPorIdblog($id);	
			   $cont = count($lista);
			   if($obj->ActualizarInteres($id,$cont))
			    {
				   echo "<script languaje=javascript>\n"; 
				   echo "location.href ='../frmblogver.php?idblog=$id&idpersona=$idp';";				
				   echo "</script>";
				}
			}
		}
}


if($t=="E"){
 $idp = $_REQUEST["idpersona"];
 $cod = $_REQUEST["id"];
   if($obj->Eliminar($cod)){
   
       echo "<script languaje=javascript>\n"; 
	 	echo "alert('Entrada Eliminada !!!');location.href ='../listablog.php?id=$idp';";				
	 	echo "</script>";		
   }
   else
   {
    echo "no pasa nada";
	}

}
?>

