<?php
$target='pagina';
include("funciones/funciones_backup.php");
include("conexion/conexion.php");
include("Menu/menu_inicio.php");
include("Ordenes/ordenes.php");
include("logos.php");

$str_orden = $_GET['pord'];
$str_mens = $_GET['pmsn'];
$str_pregunta = " where g.orden='".$str_orden."' and g.id_mensajero='".$str_mens."'";
$cnx_mysql= new conexion();
$cnx_mysql->conectarse();

if (!empty($str_mens)){		
		$retor=$cnx_mysql->consultar("select nombre from mensajeros where id_mensajero='".$str_mens."'")	;
		$fila=mysql_fetch_row($retor);
		$n_mensajero=$fila[0];		
	}


$nombrepagina = "DETALLE ".$n_mensajero;
encabezado2($target);
$tamano_pagina=20;
$_SESSION['tam']=$tamano_pagina;
$pagina = $_GET["pagina"];
if(!$pagina){
	$inicio=0;
	$_SESSION['inicio']=$inicio;
	$pagina=1;
}else{
	$inicio=($pagina-1)*$tamano_pagina;
	$_SESSION['inicio']=$inicio;
}

echo"</td>";
	echo"<td width=79% background=\"imagenes/bg3.jpg\" valign=top>";
	$tabla=$_SESSION['tabla_guia'];

	if (!empty($str_pregunta)){		
		$perfil=$_SESSION['perfil'];

		$sql_consulta="SELECT g.guia FROM guias_proceso as g  inner join rastreo_guias as b on g.guia=b.guia
				".$str_pregunta."";	
		//echo $sql_consulta;	
		class filas{
			var $rowsobj;
			function cantidad($sql_consulta){
				$this->userObj=new select_zonas();
				$cant=$this->userObj->get_filas($sql_consulta);
				return $cant;
			}
		}
		$filasobj=new filas();
		$cant=$filasobj->cantidad($sql_consulta);
		$total_paginas= ceil($cant/$tamano_pagina);
	}
?>
	<style type="text/css">
	td.comment{
  	padding:0pt;
  	padding-bottom:0pt;
  	margin:0pt;  
}

.comment{
	
	margin:0pt;	
	
	width:700px;
	height:auto !important;
  	overflow:scroll !important;

}

	</style>
<CENTER>
<table width="100%" border="1" class="primaria">
<tr>
<td width="100%" colspan="12" align="center">
<!--<? echo "<FONT color='#F3250A'>".$nombrepagina." : </FONT><FONT color='#308DC7'></FONT>";?></td>-->
</tr>
<tr class=miTable_tr>
<td colspan="12" class=miTable_th1><div align="center">..::Consulta de Envios <?echo $n_mensajero; ?> ::..</div></td>
</tr>
<tr class=miTable_tr>
<td colspan="12" class=miTable_th1>Cantidad de registros encontrados <? print $cant;?></td>
</tr>
</table>
<table border="0" width="100%" class="primaria">
<tr class="miTable_tr">
<td valign=top class=miTable_th1 width="40"><? echo $Tguia ?></td>
<td valign=top class=miTable_th1 width="40"><? echo $Torden ?></td>
<td valign=top class=miTable_th1 width='200'><? echo $Testado ?></td>
<td valign=top class=miTable_th1 width="180"><? echo $Tempresa ?></td>
<td valign=top class=miTable_th1 width="180"><? echo $Tdestinatario ?></td>
<td valign=top class=miTable_th1 width="180"><? echo $Tdireccion ?></td>
<td valign=top class=miTable_th1 width="60"><? echo $Tespecial5 ?></td>
<td valign=top class=miTable_th1 width="60"><? echo $Ttelefono ?></td>
<td valign=top class=miTable_th1 width="80"><? echo $Tciudad ?></td>
<td valign=top class=miTable_th1 width="100"><? echo $Tidentificacion ?></td>
<?
if(!empty($Tespecial1)){
	echo "<td valign=top class=miTable_th1 width='65'>".$Tespecial1."</td>";
}
if(!empty($Tespecial2)){
	echo "<td valign=top class=miTable_th1 width='65'>".$Tespecial2."</td>";
}
if(!empty($Tespecial3)){
	echo "<td valign=top class=miTable_th1 width='65'>".$Tespecial3."</td>";
}
if(!empty($Tespecial4)){
	echo "<td valign=top class=miTable_th1 width='65'>".$Tespecial4."</td>";
}
//if(!empty($Tespecial5)){
//	echo "<td valign=top class=miTable_th1 width='65'>".$Tespecial5."</td>";
//}
echo "<td valign=top class=miTable_th1 width='80'>".$Trastreo."</td>";
echo "</tr>";
$cnx_mysql= new conexion();
$cnx_mysql->conectarse();
$fields_consulta="g.guia, g.empresa, g.destinatario, g.direccion, g.telefono, g.ciudad,g.identificacion,g.especial1,
			   g.especial2,g.especial3,g.especial4,g.especial5,g.orden,e.nombre";

$rst_select_lotes=$cnx_mysql->consultar("SELECT ".$fields_consulta."  FROM guias_proceso as g 
			  join estados_gestion as e on g.id_estado=e.id_estado where g.orden='".$str_orden."' 
			  and g.id_mensajero='".$str_mens."' order by guia LIMIT $inicio,$tamano_pagina"); 		

 		while($row_select_lotes=mysql_fetch_array($rst_select_lotes)){
 			echo "<tr class=miTable_tr>";
 			echo "<td valign=top class=miTable_td>";
					?>
					<A HREF='accion_guia.php?tipo=1', onClick='window.open("accion_guia.php?guia=<? echo $row_select_lotes[0];?>&tabla=<? echo $tabla;?>","window","width=650,height=600,toolbars=no,scrollbars=yes,resizable=no"); return false'><? echo $row_select_lotes[0];?></a>
					<? echo "</td>";

					$f_entrega='00-00-0000';
					if(!empty($row_select_lotes[11])){
						$f_entrega=date("d-m-Y",strtotime($row_select_lotes[11]));
					}
					echo "<td valign=top class=miTable_td>".$row_select_lotes[12]."</td>";##Orden
					echo "<td valign=top class=miTable_td>".$row_select_lotes[13]."</td>";##Estado
					echo "<td valign=top class=miTable_td>".$row_select_lotes[1]."</td>";##EMPRESA
					echo "<td valign=top class=miTable_td>".$row_select_lotes[2]."</td>";##DESTINATARIO
					echo "<td valign=top class=miTable_td>".$row_select_lotes[3]."</td>";##DIRECCION
					echo "<td valign=top class=miTable_td>".$f_entrega."</td>";##ESPECIAL 5
					echo "<td valign=middle class=miTable_td><div align=center>".$row_select_lotes[4]."</div>";##TELEFONO
					echo "</td>";
					echo "<td valign=top class=miTable_td>".$row_select_lotes[5]."</td>";##CIUDAD
					echo "<td valign=top class=miTable_td>".$row_select_lotes[6]."</td>";##IDENTIFICACION
					if(!empty($Tespecial1)){
						echo "<td valign=top class=miTable_td>".$row_select_lotes[7]."</td>";##Especial1
					}
					if(!empty($Tespecial2)){
						echo "<td valign=top class=miTable_td>".$row_select_lotes[8]."</td>";##Especial2
					}
					if(!empty($Tespecial3)){
						echo "<td valign=top class=miTable_td>".$row_select_lotes[9]."</td>";##Especial3
					}
					if(!empty($Tespecial4)){
						echo "<td valign=top class=miTable_td>".$row_select_lotes[10]."</td>";##Especial4
					}
					echo "<td valign=top class=miTable_td>";
					if ($perfil!=5){
					?>
					<A HREF='accion_rastreo.php?tipo=1', onClick='window.open("accion_rastreo.php?guia=<? echo $row_select_lotes[0];?>&tipo=1&tabla=<? echo $tabla;?>&id_suc=<? echo $suc;?>","window","width=550,height=650,resizable=yes,scrollbars=yes"); return false'>Ver Rastreo</a>
					<? }
					echo "</td>";
 		}
?>
</tr>
<tr class=miTable_tr>
<td class=miTable_td colspan="12">
<div align="center">
<?
$id_user=$_GET['id_user'];
$id_sucursal=$_GET['suc'];
if($total_paginas>1)
{   echo "Paginas:";
//echo "&nbsp;&nbsp;";
$start = ( $pagina-5 > 0 ? $pagina-5  : 1 );
if ($start > 1 ){
	print "&nbsp;<a href='ver_detalle_nomina_orden.php?pagina=".($start-1)."&pord=$str_orden&pmsn=$str_mens&fec1=$str_f1&fec2=$str_f2&id_user=$id_user&suc=$idsuc'> << </A>";
}
for($i = 0; $i < 10 && $total_paginas >= $start+$i; $i++){
	if($pagina == $start+$i){
		print "&nbsp;&nbsp;".($start+$i);
	}else{
		print "&nbsp;&nbsp;<a href='ver_detalle_nomina_orden.php?pagina=".($start+$i)."&pord=$str_orden&pmsn=$str_mens&fec1=$str_f1&fec2=$str_f2&id_user=$id_user&suc=$idsuc'>". ($start+$i)." </A>";
	}
}
if($start+$i < $total_paginas){
	print "&nbsp;&nbsp;<a href='ver_detalle_nomina_orden.php?pagina=".($start+$i)."&pord=$str_orden&pmsn=$str_mens&fec1=$str_f1&fec2=$str_f2&id_user=$id_user&suc=$idsuc'> >> </A>";

}
print "&nbsp;&nbsp;<a href='ver_detalle_nomina_orden.php?pagina=1&pord=$str_orden&pmsn=$str_mens&fec1=$str_f1&fec2=$str_f2&id_user=$id_user&suc=$idsuc'>Primera P&aacute;gina</A>";
print "&nbsp;&nbsp;<a href='ver_detalle_nomina_orden.php?pagina=".($total_paginas)."&pord=$str_orden&pmsn=$str_mens&fec1=$str_f1&fec2=$str_f2&id_user=$id_user&suc=$idsuc'>&Uacute;ltima P&aacute;gina</A>";
}
?></td>
</tr>
<tr class=miTable_tr>
<td class=miTable_th1 colspan="12">
<DIV align="center">
Ir a la pagina
<input type='text' name='pagina' value='' size="5" class="inputbox">
<input type='hidden' name='id_user' value='<? echo $id_user?>'>
<input type='hidden' name='suc' value='<? echo $id_sucursal?>'>
<input type='hidden' name='tabla' value='<? echo $tabla?>'>
<?
if (!empty($id_cli)){
	echo "<input type='hidden' name='id_cli' value='$id_cli'>";
}
?>

<input type='submit' name='' value='Ir' class="inputbox">
</DIV></td>
</tr>
</table>
</CENTER>
<CENTER>
 <?
	 mostrar_pie();
echo"</center>";
echo"</td>";
echo"</tr>";
echo"</table>";
echo"<table width=603 border=0 align=center cellpadding=0 cellspacing=0>";
echo"<tbody><tr>";
echo"<td></td>";
echo"</tr>";
echo"<tr>";
echo"<td height=7 background=imagenes/lineas_pie.jpg><img src=index2_files/spacer.html width=1 height=15></td>";
echo"</tr>";
echo"<tr>";
	?>
	 <td>
	  <center>
	  <? pie_de_pagina();?>
	  </center>
	 </td>
	<?php
	echo"</tr>";
	echo"</tbody></table>";

	echo"</center>";
	echo"</body>";
	echo"</html>";
$cnx_mysql->cerrar();
?>
</center>
</form>