<?php
session_start();

   include_once("../scripts/connect.php");
   $conexion=conecta_default();
   
   include_once("../scripts/session.php");
   //Validar Session

    $sesion=new Sesion("","","");/*Se crea un objeto nuevo con el privilegio necesario para la pag. actual*/

    if(!$sesion->isValida("4")){ /*Sesion invalida*/

	 header("Location: ../index.php?err=NoSesion");

    }/*no hay sesion*/

    else{

       $dato=explode("|",$_SESSION['usuario']);
       $sesion->setDatos($dato[0],$dato[1],$dato[2]);
       $sesion->setSesion();

    }
    //fin validar session
extract($_POST);
   $id_cd=$sesion->id;



if($continua==2){
 	$qPP = "SELECT idreg, inversionista.nombre as elnombre, appat, apmat, apagar, cd, observaciones, status FROM `regs2` join inversionista on 
    inversionista.id_inver=regs2.id_inver WHERE `status`=7 ORDER BY $listacd DESC";


}
    else{
  	$qPP = "SELECT idreg, inversionista.nombre as elnombre, appat, apmat, apagar, cd, observaciones, status FROM `regs2` join inversionista on 
    inversionista.id_inver=regs2.id_inver WHERE `status`=7";
    
    
    }
	

 $totalin = 0;
  $totalin2 = 0;

$rPP = mysqli_query($conexion, $qPP) or die ('ErrPP: '. mysqli_error($conexion));

 echo"<br><form name=\"Agrega3\" action=\"retenidas.php\" method=\"post\">
  Ordenar por:<select name = \"listacd\">
   
<option value=\"apagar\">Cantidad</option>
<option value=\"appat\">Apellido P.</option>
<option value=\"idreg\">ID Regalia</option>
  <option value=\"cd\">Centro Dist</option>

 </select>

  <input type=hidden name=continua value=\"2\" />

  <input type=\"submit\" name=\"lista2\"  value=\"Continuar\" />
  
  
  
  </form>";


   
if(!mysqli_affected_rows($conexion))
{
	echo "<center>No hay Regalias Retenidas por el momento.</center><br>";
    exit;
}




echo "<html>
			<body>
			
			
			<center><b>REGALIAS RETENIDAS</b>
			
			<br>

	        <table border=\"1\" align=\"center\">
	 ";
	
	
echo " <th>ID</th><th>Nombre</th><th>Retenido</th><th>CD</th><th>Motivo</th><th>Regresar a</th>";

while (($objetoPP=mysqli_fetch_object($rPP)) )
{$totalin+=$objetoPP->apagar;  
	echo "<tr>
			 <td>$objetoPP->idreg</td><td>$objetoPP->elnombre $objetoPP->appat $objetoPP->apmat</td><td>$objetoPP->apagar</td><td>$objetoPP->cd</td>
             <td>$objetoPP->observaciones</td>
             
             <td><form name=\"pagar\" action=\"regresaregalia.php\" method=\"post\"><input type=hidden name=id_regalia value=$objetoPP->idreg><input type=\"submit\" value=\"POR PAGAR\" name=\"pago\"></form></td>
             ";
             
		
            
		
                 
	echo"
		  </tr> 
		 ";
   
}
echo "</table>
El total de regalias retenidas es $ $totalin<br>"; 
   

?>